Skip to content

feat(sdk): vendor function-types and add @tailor-platform/sdk/runtime#1131

Merged
toiroakr merged 42 commits into
mainfrom
feat/function-types
May 27, 2026
Merged

feat(sdk): vendor function-types and add @tailor-platform/sdk/runtime#1131
toiroakr merged 42 commits into
mainfrom
feat/function-types

Conversation

@toiroakr
Copy link
Copy Markdown
Contributor

@toiroakr toiroakr commented May 7, 2026

Summary

  • Internalize @tailor-platform/function-types (vendored as src/runtime/globals.ts) and remove the external dependency.
  • Add new @tailor-platform/sdk/runtime entry exposing typed wrappers for the runtime APIs: iconv, secretmanager, authconnection, idp, workflow, context, file. Wrappers and their associated types are self-contained — they work without activating any ambient globals.
  • 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).
  • Preserve the capital-cased Tailordb ambient namespace (Tailordb.QueryResult, Tailordb.CommandType, Tailordb.Client) as a @deprecated alias of the new lowercase tailordb.* namespace, so source-level callers of the old function-types names keep type-checking. Scheduled for removal in v2.0.
  • Ship the v2/tailordb-namespace codemod in @tailor-platform/sdk-codemod to rewrite Tailordb.QueryResult / Tailordb.CommandType / Tailordb.Client / typeof Tailordb.Client to the lowercase tailordb.* form. Removing @tailor-platform/function-types from package.json (and tsconfig.json compilerOptions.types if listed) can be done manually once you've upgraded — no codemod is needed because the replacement declarations are activated automatically.
  • Supersedes feat: add iconv runtime wrapper #1069 — the iconv runtime wrapper is folded into the new @/runtime/iconv namespace.

toiroakr and others added 2 commits May 7, 2026 10:18
Internalize the external @tailor-platform/function-types package into the SDK
and expose it as a new `@tailor-platform/sdk/runtime` entry. The runtime entry
provides typed wrappers (iconv, secretmanager, authconnection, idp, workflow,
context, file) for the platform's `tailor.*` and `tailordb.*` globals, and
importing it activates the corresponding ambient global types as a side
effect. Importing from `@tailor-platform/sdk` also activates those globals
automatically — existing projects do not need to add anything to tsconfig.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@toiroakr toiroakr requested a review from remiposo as a code owner May 7, 2026 06:10
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 7, 2026

🦋 Changeset detected

Latest commit: 12a206d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@tailor-platform/sdk Minor
@tailor-platform/sdk-codemod Patch
@tailor-platform/create-sdk Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

toiroakr and others added 2 commits May 7, 2026 15:57
Restructure src/runtime/globals.ts so every shape (interfaces, response
types, error class) is defined as a top-level exported type. The
`declare global` block now aliases those module-scope types into the
`tailor.*` / `Tailordb` namespaces. As a result, the bundled
`dist/runtime/*.d.mts` and `dist/vitest/index.d.mts` no longer reference
`tailor.*` types — consumers can import and use the runtime wrappers
without activating any ambient globals.

Importing `@tailor-platform/sdk/runtime` no longer auto-activates the
ambient declarations either. Users who still want unqualified
`tailor.iconv.convert(...)` calls can opt in via a side-effect import of
`@tailor-platform/sdk/runtime/globals` or by listing it in tsconfig
`compilerOptions.types`.

Also introduce `contextMock` so tests can configure invokers without
spying on `globalThis.tailor.context.getInvoker`.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
…function-types

# Conflicts:
#	pnpm-lock.yaml
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

⚡ pkg.pr.new

@tailor-platform/sdk

pnpm add https://pkg.pr.new/@tailor-platform/sdk@12a206d
pnpm dlx https://pkg.pr.new/@tailor-platform/sdk@12a206d --help

@tailor-platform/create-sdk

pnpm add https://pkg.pr.new/@tailor-platform/create-sdk@12a206d
pnpm dlx https://pkg.pr.new/@tailor-platform/create-sdk@12a206d my-app

commit: 12a206d

@toiroakr toiroakr marked this pull request as draft May 8, 2026 01:40
@toiroakr toiroakr mentioned this pull request May 8, 2026
6 tasks
Base automatically changed from feat/runtime-emulate to main May 13, 2026 00:46
toiroakr added 2 commits May 13, 2026 09:48
Rename setWorkflowExecutionId -> setTriggerHandler and setWaitResult ->
setWaitHandler in src/runtime/__tests__/workflow.test.ts. The previous
identifiers do not exist on workflowMock and broke typecheck:go and unit
tests on Node 22/24, Coverage, and SDK E2E.
@github-actions

This comment has been minimized.

Split the runtime data types and the typed globalThis accessor into a
private _runtime.ts module so that the wrappers under
@tailor-platform/sdk/runtime/{iconv,secretmanager,authconnection,idp,
workflow,context,file} no longer side-effect import ./globals.

Previously, importing any wrapper transitively activated the declare
global block in ./globals, which contradicted the documented opt-in
contract (the user was supposed to explicitly import
@tailor-platform/sdk/runtime/globals to get ambient tailor.* / tailordb
types). After this change, only the explicit globals entry activates
those declarations; the wrappers reach the runtime via a typed lazy
runtime accessor that reads globalThis.tailor / globalThis.tailordb
without polluting the consumer scope. Test files are updated to follow
the same rule.
@github-actions

This comment has been minimized.

This comment was marked as outdated.

@toiroakr toiroakr requested a review from Copilot May 13, 2026 05:45
@github-actions

This comment has been minimized.

This comment was marked as outdated.

@github-actions

This comment has been minimized.

This comment was marked as outdated.

@github-actions

This comment has been minimized.

The vitest test colocation will be handled in a separate PR. This
restores the `__tests__/` layout and the corresponding
`vitest.config.ts` include / exclude patterns and `knip.json`
ignore list so this PR no longer mixes the colocation refactor with
the function-types vendoring work.
@github-actions

This comment has been minimized.

The replacement types are vendored inside the SDK and activated automatically,
so users can simply remove @tailor-platform/function-types from their
package.json without a dedicated codemod. Drop the codemod, its fixtures,
the registry entry, the test registration, and the build target. Update the
related changeset entries accordingly.

This comment was marked as outdated.

@github-actions

This comment has been minimized.

# Conflicts:
#	packages/sdk/eslint.config.js
#	pnpm-lock.yaml
@github-actions

This comment has been minimized.

The v2/tailordb-namespace codemod rewrites Tailordb.Client references to tailordb.Client in both value and type positions, but the new lowercase namespace tailordb only declared QueryResult and CommandType. Add a Client type alias (= TailordbClientInstance) so codemod output like `const c: tailordb.Client = ...` type-checks via namespace+var merging.
@github-actions

This comment has been minimized.

This comment was marked as outdated.

Comment thread packages/sdk/src/runtime/globals.ts
Comment thread packages/sdk/src/runtime/globals.ts
@remiposo remiposo removed their assignment May 25, 2026
- Add Iconv / Client type aliases to ambient namespace tailor.iconv / tailor.idp so they remain usable in type position, matching the original @tailor-platform/function-types declarations (which declared these as classes inside the namespace).
- Switch internal CLI tailordb stub to use lowercase tailordb.QueryResult instead of the deprecated capital-cased Tailordb.QueryResult.
- Harden stripBannerExceptConfigureEntry regex to tolerate CRLF line endings so the strip works regardless of how tsdown formats banners.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 53 out of 56 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

@github-actions
Copy link
Copy Markdown

Code Metrics Report (packages/sdk)

main (a0658d0) #1131 (af250cf) +/-
Coverage 63.6% 63.8% +0.2%
Code to Test Ratio 1:0.4 1:0.4 +0.0
Details
  |                    | main (a0658d0) | #1131 (af250cf) |  +/-  |
  |--------------------|----------------|-----------------|-------|
+ | Coverage           |          63.6% |           63.8% | +0.2% |
  |   Files            |            367 |             375 |    +8 |
  |   Lines            |          12949 |           13007 |   +58 |
+ |   Covered          |           8244 |            8310 |   +66 |
+ | Code to Test Ratio |          1:0.4 |           1:0.4 |  +0.0 |
  |   Code             |          85698 |           86602 |  +904 |
+ |   Test             |          36485 |           36919 |  +434 |

Code coverage of files in pull request scope (85.4% → 89.6%)

Files Coverage +/- Status
packages/sdk/src/cli/shared/mock.ts 50.0% 0.0% modified
packages/sdk/src/configure/index.ts 100.0% 0.0% modified
packages/sdk/src/configure/services/workflow/wait-point.ts 100.0% 0.0% modified
packages/sdk/src/plugin/builtin/file-utils/generate-file-utils.ts 100.0% 0.0% modified
packages/sdk/src/runtime/authconnection.ts 100.0% +100.0% added
packages/sdk/src/runtime/context.ts 100.0% +100.0% added
packages/sdk/src/runtime/file.ts 100.0% +100.0% added
packages/sdk/src/runtime/globals.ts 0.0% 0.0% added
packages/sdk/src/runtime/iconv.ts 100.0% +100.0% added
packages/sdk/src/runtime/idp.ts 100.0% +100.0% added
packages/sdk/src/runtime/secretmanager.ts 100.0% +100.0% added
packages/sdk/src/runtime/workflow.ts 100.0% +100.0% added
packages/sdk/src/utils/test/mock.ts 57.1% 0.0% modified
packages/sdk/src/vitest/index.ts 100.0% 0.0% modified
packages/sdk/src/vitest/mock.ts 91.4% +3.6% modified

SDK Configure Bundle Size

main (a0658d0) #1131 (af250cf) +/-
configure-index-size 18KB 18KB 0KB
dependency-chunks-size 33.52KB 33.52KB 0KB
total-bundle-size 51.51KB 51.51KB 0KB

Runtime Performance

main (a0658d0) #1131 (af250cf) +/-
Generate Median 2,800ms 2,781ms -19ms
Generate Max 2,815ms 2,874ms 59ms
Apply Build Median 2,817ms 2,796ms -21ms
Apply Build Max 2,985ms 2,833ms -152ms

Type Performance (instantiations)

main (a0658d0) #1131 (af250cf) +/-
tailordb-basic 35,130 35,133 3
tailordb-optional 3,841 3,841 0
tailordb-relation 7,428 7,428 0
tailordb-validate 2,566 2,566 0
tailordb-hooks 5,767 5,767 0
tailordb-object 12,136 12,136 0
tailordb-enum 2,462 2,462 0
resolver-basic 9,424 9,424 0
resolver-nested 26,111 26,111 0
resolver-array 18,187 18,187 0
executor-schedule 4,234 4,234 0
executor-webhook 873 873 0
executor-record 8,166 8,166 0
executor-resolver 4,369 4,369 0
executor-operation-function 869 868 -1
executor-operation-gql 869 869 0
executor-operation-webhook 888 888 0
executor-operation-workflow 1,714 1,714 0

Reported by octocov

Copy link
Copy Markdown
Contributor

@remiposo remiposo left a comment

Choose a reason for hiding this comment

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

LGTM

@toiroakr toiroakr merged commit ae23669 into main May 27, 2026
56 checks passed
@toiroakr toiroakr deleted the feat/function-types branch May 27, 2026 09:27
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.

3 participants