-
Notifications
You must be signed in to change notification settings - Fork 3
feat(sdk): vendor function-types and add @tailor-platform/sdk/runtime #1131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
toiroakr
wants to merge
40
commits into
main
Choose a base branch
from
feat/function-types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
c43dfe9
Merge remote-tracking branch 'origin/feat/runtime-emulate' into feat/…
toiroakr c62c3b0
feat(sdk): vendor function-types and add @tailor-platform/sdk/runtime
toiroakr e1aedd2
refactor(sdk): expose runtime types without ambient globals
toiroakr b546863
Merge remote-tracking branch 'origin/feat/runtime-emulate' into feat/…
toiroakr d5ad97e
chore: sync skills
tailor-platform-pr-trigger[bot] 6327a78
Merge branch 'main' into feat/function-types
toiroakr 0276343
fix(sdk): use existing workflowMock API names in runtime workflow test
toiroakr a84e861
refactor(sdk): make runtime wrappers opt-in to ambient globals
toiroakr 1ae8a02
docs(sdk): correct contextMock references and document it in testing …
toiroakr 4538886
refactor(sdk): unify runtime/context.Invoker with SDK-friendly attrib…
toiroakr 997e0b0
refactor(sdk): align runtime types and file stream mock with platform…
toiroakr b407fa2
docs(sdk): drop runtime sequencing detail from user-facing workflow docs
toiroakr 362c958
fix(sdk): broaden runtime globals and tighten file stream mock contract
toiroakr 8d6cebb
fix(sdk): keep ambient runtime globals active when importing @tailor-…
toiroakr e5e0872
chore(sdk): exclude __test_fixtures__ from tsconfig and consolidate l…
toiroakr 7cf3328
chore(sdk): address Copilot review feedback on runtime/vitest mocks
toiroakr f8a6781
docs(sdk): align openDownloadStream mock example with StreamValue type
toiroakr 0d8f55d
docs(sdk): drop wrapper-internal shape conversion from runtime docs
toiroakr ba1171f
chore(example): revert unrelated User.schema fixture drift
toiroakr c391cde
refactor(sdk): move runtime types into per-service wrappers
toiroakr 0749c01
fix(sdk): activate ambient runtime globals via tsdown banner
toiroakr 08abf15
docs(sdk): drop function-types lockstep note from runtime guide
toiroakr ed326a0
docs(sdk): drop globals opt-in note from testing guide
toiroakr 5349265
fix(sdk): scope ambient globals banner to the configure entry only
toiroakr d1a1215
fix(sdk): correct configure-entry banner scoping and download-mock note
toiroakr 2d53012
chore: merge main into feat/function-types
toiroakr cdbd260
refactor(sdk): address PR review feedback
toiroakr bbbd42d
refactor(sdk): consolidate runtime globals to var tailor + namespace …
toiroakr f9723e5
fix(sdk): avoid ambient Tailor namespace in @tailor-platform/sdk/test
toiroakr 4567e89
refactor(sdk): inline runtime aggregates into index.ts and drop inter…
toiroakr 9697f73
refactor(sdk): merge type-only namespaces into var tailor / var tailordb
toiroakr 5106842
fix(sdk): export deleteFile alongside delete alias for named imports
toiroakr ce83a92
refactor(sdk): consolidate runtime wrappers via indexed access types
toiroakr 90fc6ff
refactor(sdk): reuse TailorWorkflowAPI in configure wait-point
toiroakr 6e9b05a
Merge remote-tracking branch 'origin/main' into feat/function-types
toiroakr f5d3d38
feat(sdk-codemod): add v2/tailordb-namespace and v2/drop-function-typ…
toiroakr 429cdf7
revert(sdk): move vitest tests back under __tests__/
toiroakr 4416fed
chore(sdk-codemod): drop v2/drop-function-types-dep codemod
toiroakr 50f302a
Merge remote-tracking branch 'origin/main' into feat/function-types
toiroakr 10382b8
fix(sdk): add Client type alias to lowercase tailordb namespace
toiroakr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --- | ||
| "@tailor-platform/sdk": minor | ||
| --- | ||
|
|
||
| Add `@tailor-platform/sdk/runtime` — typed wrappers for the Tailor Platform Function runtime APIs (`tailor.iconv`, `tailor.secretmanager`, `tailor.authconnection`, `tailor.idp`, `tailor.workflow`, `tailor.context`, and `tailordb.file`). The wrappers and their types are fully self-contained, so you can use them without activating any ambient globals. | ||
|
|
||
| ```ts | ||
| import { iconv, secretmanager, idp, file } from "@tailor-platform/sdk/runtime"; | ||
|
|
||
| const utf8 = iconv.convert(sjisBuffer, "Shift_JIS", "UTF-8"); | ||
| const apiKey = await secretmanager.getSecret("my-vault", "API_KEY"); | ||
| const client = new idp.Client({ namespace: "my-namespace" }); | ||
| const { metadata } = await file.upload("ns", "Document", "attachment", recordId, bytes); | ||
| ``` | ||
|
|
||
| The SDK no longer depends on the external `@tailor-platform/function-types` package; its declarations are now vendored inside the SDK. For backwards compatibility the ambient `tailor.*` / `tailordb.*` types are still activated automatically when you import from `@tailor-platform/sdk`, so existing code keeps type-checking with no changes. This implicit activation will be removed in v2.0 — new code is encouraged to use the typed wrappers from `@tailor-platform/sdk/runtime`, or to opt into the globals explicitly via `import "@tailor-platform/sdk/runtime/globals"` (or by listing the entry in `tsconfig.json`'s `compilerOptions.types`). | ||
|
toiroakr marked this conversation as resolved.
|
||
|
|
||
| The capital-cased `Tailordb` ambient namespace (`Tailordb.QueryResult`, `Tailordb.CommandType`, `Tailordb.Client`) is preserved as a `@deprecated` alias of the new lowercase `tailordb.*` namespace for source-level compatibility with `@tailor-platform/function-types`. It will be removed in v2.0; run `pnpm dlx @tailor-platform/sdk-codemod v2/tailordb-namespace` to migrate. The `@tailor-platform/function-types` declarations are vendored inside the SDK and activated automatically, so you can simply remove `@tailor-platform/function-types` from your `package.json` (and from `tsconfig.json` `compilerOptions.types` if listed) once you've upgraded. | ||
|
|
||
| Other test-mock changes from `@tailor-platform/sdk/vitest`: | ||
|
|
||
| - Breaking: when an `openDownloadStream` (or `toFileStream()`) call consumes a queued mock result, raw `Uint8Array` / `ArrayBuffer` payloads are now rejected. Enqueue a structured iterable of `StreamValue` items (`{ type: "metadata" }`, `{ type: "chunk", data, position }`, `{ type: "complete" }`) so test streams stay aligned with the platform's structured stream contract. The shorthand `Uint8Array` enqueue is still accepted by `download` / `downloadAsBase64`. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@tailor-platform/sdk-codemod": patch | ||
| --- | ||
|
|
||
| Add `v2/tailordb-namespace` codemod for the `@tailor-platform/function-types` → `@tailor-platform/sdk` vendoring: rewrite references to the deprecated capital-cased `Tailordb` ambient namespace (`Tailordb.QueryResult`, `Tailordb.CommandType`, `Tailordb.Client`, `typeof Tailordb.Client`) to the new lowercase `tailordb.*` namespace re-published by the SDK. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
packages/sdk-codemod/codemods/v2/tailordb-namespace/codemod.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| name: "@tailor-platform/tailordb-namespace" | ||
| version: "1.0.0" | ||
| description: "Rename the deprecated capital-cased `Tailordb` ambient namespace to lowercase `tailordb` (e.g. `Tailordb.QueryResult` → `tailordb.QueryResult`)" | ||
| engine: jssg | ||
| language: typescript | ||
| since: "1.0.0" | ||
| until: "2.0.0" |
36 changes: 36 additions & 0 deletions
36
packages/sdk-codemod/codemods/v2/tailordb-namespace/scripts/transform.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // Members exposed by the deprecated `Tailordb` ambient namespace from | ||
| // `@tailor-platform/function-types`. Each was a type-only declaration that | ||
| // has been re-published under the new lowercase `tailordb` namespace by the | ||
| // SDK. Anything outside this list is left untouched so user-defined symbols | ||
| // that happen to share the `Tailordb.` prefix are not rewritten by accident. | ||
| const TAILORDB_MEMBERS = ["QueryResult", "CommandType", "Client"] as const; | ||
|
|
||
| const MEMBER_GROUP = TAILORDB_MEMBERS.join("|"); | ||
|
|
||
| // Match `Tailordb.<Member>` with word boundaries so neither prefix nor | ||
| // suffix collisions (e.g. `MyTailordb.X`, `Tailordb.QueryResultExtra`) are | ||
| // rewritten. Generic-argument lists and `typeof` qualifiers are not part of | ||
| // the match — they fall outside the boundary and are preserved verbatim. | ||
| const PATTERN = new RegExp(String.raw`\bTailordb\.(${MEMBER_GROUP})\b`, "g"); | ||
|
|
||
| /** | ||
| * Rewrite references to the deprecated capital-cased `Tailordb` ambient | ||
| * namespace to the new lowercase `tailordb` namespace. The capital-cased | ||
| * namespace was inherited from `@tailor-platform/function-types`; the SDK | ||
| * keeps it as a `@deprecated` alias in v1 and removes it in v2. | ||
| * | ||
| * Only the known type-only members (`QueryResult`, `CommandType`, `Client`) | ||
| * are rewritten so that unrelated user-defined symbols sharing the | ||
| * `Tailordb.` prefix remain untouched. Both type-position references | ||
| * (`Tailordb.QueryResult<T>`, `typeof Tailordb.Client`) and value-position | ||
| * references (`new Tailordb.Client(...)`) are handled by the same rule. | ||
| * @param source - File contents | ||
| * @param _filePath - Absolute path to the file (kept for the runner signature) | ||
| * @returns Transformed source or null when nothing matched. | ||
| */ | ||
| export default function transform(source: string, _filePath: string): string | null { | ||
| if (!source.includes("Tailordb.")) return null; | ||
| PATTERN.lastIndex = 0; | ||
| const updated = source.replace(PATTERN, (_match, member: string) => `tailordb.${member}`); | ||
| return updated === source ? null : updated; | ||
| } |
5 changes: 5 additions & 0 deletions
5
packages/sdk-codemod/codemods/v2/tailordb-namespace/tests/basic-query-result/expected.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| async function fetchRows<O>(): Promise<tailordb.QueryResult<O>> { | ||
| return {} as tailordb.QueryResult<O>; | ||
| } | ||
|
|
||
| const command: tailordb.CommandType = "SELECT"; |
5 changes: 5 additions & 0 deletions
5
packages/sdk-codemod/codemods/v2/tailordb-namespace/tests/basic-query-result/input.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| async function fetchRows<O>(): Promise<Tailordb.QueryResult<O>> { | ||
| return {} as Tailordb.QueryResult<O>; | ||
| } | ||
|
|
||
| const command: Tailordb.CommandType = "SELECT"; |
7 changes: 7 additions & 0 deletions
7
...s/sdk-codemod/codemods/v2/tailordb-namespace/tests/client-instance-and-typeof/expected.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| function takeClient(client: tailordb.Client): void { | ||
| void client; | ||
| } | ||
|
|
||
| function makeClient(Ctor: typeof tailordb.Client): tailordb.Client { | ||
| return new Ctor({ namespace: "demo" }); | ||
| } |
7 changes: 7 additions & 0 deletions
7
...ages/sdk-codemod/codemods/v2/tailordb-namespace/tests/client-instance-and-typeof/input.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| function takeClient(client: Tailordb.Client): void { | ||
| void client; | ||
| } | ||
|
|
||
| function makeClient(Ctor: typeof Tailordb.Client): Tailordb.Client { | ||
| return new Ctor({ namespace: "demo" }); | ||
| } |
9 changes: 9 additions & 0 deletions
9
packages/sdk-codemod/codemods/v2/tailordb-namespace/tests/generic-arg/expected.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| interface Row { | ||
| id: string; | ||
| } | ||
|
|
||
| type RowsResult = tailordb.QueryResult<Row>; | ||
|
|
||
| function describe(result: tailordb.QueryResult<{ id: number; tags: readonly string[] }>): number { | ||
| return result.rowCount; | ||
| } |
9 changes: 9 additions & 0 deletions
9
packages/sdk-codemod/codemods/v2/tailordb-namespace/tests/generic-arg/input.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| interface Row { | ||
| id: string; | ||
| } | ||
|
|
||
| type RowsResult = Tailordb.QueryResult<Row>; | ||
|
|
||
| function describe(result: Tailordb.QueryResult<{ id: number; tags: readonly string[] }>): number { | ||
| return result.rowCount; | ||
| } |
9 changes: 9 additions & 0 deletions
9
packages/sdk-codemod/codemods/v2/tailordb-namespace/tests/multiple-members/expected.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| async function run<O>(): Promise<tailordb.QueryResult<O>> { | ||
| const cmd: tailordb.CommandType = "SELECT"; | ||
| const client: tailordb.Client = new (tailordb.Client as typeof tailordb.Client)({ | ||
| namespace: "demo", | ||
| }); | ||
| void cmd; | ||
| void client; | ||
| return {} as tailordb.QueryResult<O>; | ||
| } |
9 changes: 9 additions & 0 deletions
9
packages/sdk-codemod/codemods/v2/tailordb-namespace/tests/multiple-members/input.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| async function run<O>(): Promise<Tailordb.QueryResult<O>> { | ||
| const cmd: Tailordb.CommandType = "SELECT"; | ||
| const client: Tailordb.Client = new (Tailordb.Client as typeof Tailordb.Client)({ | ||
| namespace: "demo", | ||
| }); | ||
| void cmd; | ||
| void client; | ||
| return {} as Tailordb.QueryResult<O>; | ||
| } |
8 changes: 8 additions & 0 deletions
8
packages/sdk-codemod/codemods/v2/tailordb-namespace/tests/no-match/input.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { createResolver, t } from "@tailor-platform/sdk"; | ||
|
|
||
| export default createResolver({ | ||
| name: "hello", | ||
| type: "Query", | ||
| output: t.string(), | ||
| body: () => "world", | ||
| }); |
15 changes: 15 additions & 0 deletions
15
packages/sdk-codemod/codemods/v2/tailordb-namespace/tests/unrelated-prefix/input.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Identifiers that merely *start* with `Tailordb` (or have an unknown | ||
| // member) must not be rewritten by the codemod. | ||
|
|
||
| namespace MyTailordb { | ||
| export type QueryResult<T> = { rows: T[] }; | ||
| } | ||
|
|
||
| type Mine = MyTailordb.QueryResult<{ id: string }>; | ||
|
|
||
| // Unknown member on the deprecated namespace stays untouched (best-effort | ||
| // safety net — there is no `Tailordb.NotAType` on the SDK side). | ||
| type Untouched = Tailordb.NotAType; | ||
|
|
||
| // A suffix-extended member name must also stay intact. | ||
| type Extra = Tailordb.QueryResultExtra; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.