Skip to content

feat: typescript SDK resolve value by reference. - #8824

Merged
TomChv merged 15 commits into
dagger:mainfrom
TomChv:feat/ts-sdk-resolve-value-by-reference
Nov 19, 2024
Merged

TomChv merged 15 commits into
dagger:mainfrom
TomChv:feat/ts-sdk-resolve-value-by-reference

Conversation

@TomChv

@TomChv TomChv commented Oct 30, 2024 •

Copy link
Copy Markdown
Member

Fixes #8676.

Refactor typedef resolution to be resolve by reference. The introspection starts from the entrypoint (which is the class named the same as the module) and recursively resolve every references.

Refactor the TS compiler API to be abstract with a AST that handle lookups, typedef resolutions and default value resolution.

Use imports to resolve default value that refers to an exported variable.

Add custom introspection error.

Improve error handling to point to the line that couldn't be introspected.

Add supports for native enum keyword and type native keyword.

Simplify overall code abstractions too minimal.
Avoid long abstractions functions.

💡 This is not a breaking change! I want to be compatible with the previous way, just adding new features.

Copy of the changelog

Add support for non-decorable keywords by resolving declarations by references.
Support native enum keyword to define enumeration without decorators.
Example

enum Example {
  A = "A",
  B = "B",
}

Support native type keyword to define type without decorators.
This can be use to define data object or primitive type.
Example

type Example = {
  a: string
  b: number
}
type Integer = number
type Foo = string

Note: If the type is a data object, all properties will be exposed
to API & CLI.
Support resolution of variable and enumerations as default values if they
are exported by the same module.
Example

export enum Example {
  A = "A",
  B = "B",
}
export const defaultValue = "foo"
@object()
class Test {
  @func()
  defaultEnumVar(value: Example = Example.A): Example {
    return value
  }
  @func
  defaultStringVar(value: string = defaultValue): string {
    return value
  }
}

@TomChv TomChv self-assigned this Oct 30, 2024
@TomChv
TomChv requested a review from a team as a code owner October 30, 2024 17:06
@TomChv TomChv added needs/changelog Pull requests that require a changelog entry needs/docs Pull requests that require a docs change labels Oct 30, 2024
@TomChv
TomChv force-pushed the feat/ts-sdk-resolve-value-by-reference branch from ba03494 to 00cb234 Compare November 7, 2024 12:29
@TomChv

TomChv commented Nov 7, 2024

Copy link
Copy Markdown
Member Author

@helderco helderco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me.

All the tests are in a single file. Wouldn't hurt to have a few using multiple files, including with conflicting exported names, which would also see if aliased imports are supported:

import { Foo as Bar } from './foobar'

Comment on lines 138 to +139
WithNewFile("/work/src/index.ts", `
import { dag, Container, object, func } from "@dagger.io/dagger"
import { dag, Container, object, func } from "@dagger.io/dagger"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand all these indentation changes 😄

If you use sdkSource instead of WithNewFile it already trims the indentation correctly (heredoc). Otherwise, I'd expect this code to not have any indentation. Right now it's in between those two options.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a global search for tab and replace them with space but it seems I didn't re updated the code after.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't mark feedback as resolved. It should be the reviewer upon confirming it. Otherwise it's more difficult to keep track of what we need to check for.

In this case the formatting is still all over the place. Doesn't mean I'm going to block because of it, but it's not resolved either.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I did a global cleanup of the tab, that's why there's that many changes on the formatting

@helderco helderco Nov 19, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not saying there's many formatting changes, I'm saying there's a lot that's misformatted even considering only changed lines. Basically the indentations aren't all right.

So when I said this:

I don't understand all these indentation changes

I didn't mean "why make the change at all", I meant "why change the indentation but not make it right".

@TomChv
TomChv requested a review from helderco November 13, 2024 17:15
@TomChv
TomChv force-pushed the feat/ts-sdk-resolve-value-by-reference branch 2 times, most recently from 9c8f1bf to e68305e Compare November 14, 2024 11:32
Tom Chauveau added 14 commits November 19, 2024 14:46
Fixes dagger#8676.

Refactor typedef resolution to be resolve by reference.
The introspection starts from the entrypoint (which is the class named
the same as the module) and recursively resolve every references.

Refactor the TS compiler API to be abstract with a AST that handle
lookups, typedef resolutions and default value resolution.

Use `imports` to resolve default value that refers to an exported variable.

Add custom introspection error.

Improve error handling to point to the line that couldn't be introspected.

Add supports for native `enum` keyword and `type` native keyword.

Simplify overall code abstractions too minimal.
Avoid long abstractions functions.

Signed-off-by: Tom Chauveau <[email protected]>
Fix primitive type usage error message.

Fix UnexportedSignature tests

Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
Signed-off-by: Tom Chauveau <[email protected]>
@TomChv
TomChv force-pushed the feat/ts-sdk-resolve-value-by-reference branch from f805f57 to c63373b Compare November 19, 2024 13:46
@helderco helderco removed needs/changelog Pull requests that require a changelog entry needs/docs Pull requests that require a docs change labels Nov 19, 2024

@helderco helderco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docs in:

@TomChv
TomChv merged commit 99981d9 into dagger:main Nov 19, 2024
TomChv added a commit to TomChv/dagger that referenced this pull request Nov 21, 2024
  Add support for non-decorable keywords by resolving declarations by references.

  Support native `enum` keyword to define enumeration without decorators.
  Example
  ```ts
  enum Example {
    A = "A",
    B = "B",
  }
  ```

  Support native `type` keyword to define type without decorators.
  This can be use to define data object or primitive type.
  Example
  ```ts
  type Example = {
    a: string
    b: number
  }
  type Integer = number
  type Foo = string
  ```
  Note: If the type is a data object, all properties will be exposed
  to API & CLI.

  Support resolution of variable and enumerations as default values if they
  are exported by the same module.
  Example
  ```ts
  export enum Example {
    A = "A",
    B = "B",
  }
  export const defaultValue = "foo"
  @object()
  class Test {
    @func()
    defaultEnumVar(value: Example = Example.A): Example {
      return value
    }
    @func
    defaultStringVar(value: string = defaultValue): string {
      return value
    }
  }
  ```

Signed-off-by: Tom Chauveau <[email protected]>
@TomChv TomChv added this to the v0.15.0 milestone Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✨ TypeScript SDK: resolve introspection by reference

2 participants