Skip to content

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

Open
toiroakr wants to merge 40 commits into
mainfrom
feat/function-types
Open

feat(sdk): vendor function-types and add @tailor-platform/sdk/runtime#1131
toiroakr wants to merge 40 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: 10382b8

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@10382b8
pnpm dlx https://pkg.pr.new/@tailor-platform/sdk@10382b8 --help

@tailor-platform/create-sdk

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

commit: 10382b8

@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.

This comment was marked as outdated.

The wait-point module previously declared an inline shape for
globalThis.tailor.workflow that duplicated TailorWorkflowAPI. Import the
canonical type from @/runtime/workflow instead, and type the test file's
globalThis cast with TailorRuntime as well.

Configure module is allowed to import from @/runtime per the import
boundary rules.
@github-actions

This comment has been minimized.

This comment was marked as outdated.

toiroakr added 2 commits May 19, 2026 23:23
…es-dep

- v2/tailordb-namespace rewrites 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.
- v2/drop-function-types-dep removes `@tailor-platform/function-types`
  from `package.json` dependency maps (`dependencies` /
  `devDependencies` / `peerDependencies` / `optionalDependencies`)
  and from `tsconfig.json` `compilerOptions.types`, since the
  declarations are now vendored inside the SDK.

Also restore the capital-cased `Tailordb` ambient namespace as a
`@deprecated` alias of the new lowercase `tailordb.*` namespace so
existing code that uses `Tailordb.QueryResult` etc. continues to
type-check against the vendored declarations, and revert
`packages/sdk/src/cli/shared/mock.ts` to its main version which still
uses `Tailordb.QueryResult<O>`.
@toiroakr toiroakr requested a review from Copilot May 19, 2026 14:39

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
Copy link
Copy Markdown

Code Metrics Report (packages/sdk)

main (b2bd4aa) #1131 (c189cd7) +/-
Coverage 62.3% 62.6% +0.2%
Code to Test Ratio 1:0.4 1:0.4 +0.0
Details
  |                    | main (b2bd4aa) | #1131 (c189cd7) |  +/-  |
  |--------------------|----------------|-----------------|-------|
+ | Coverage           |          62.3% |           62.6% | +0.2% |
  |   Files            |            364 |             372 |    +8 |
  |   Lines            |          12773 |           12831 |   +58 |
+ |   Covered          |           7967 |            8033 |   +66 |
+ | Code to Test Ratio |          1:0.4 |           1:0.4 |  +0.0 |
  |   Code             |          83913 |           84811 |  +898 |
+ |   Test             |          35136 |           35570 |  +434 |

Code coverage of files in pull request scope (85.6% → 89.8%)

Files Coverage +/- Status
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 (b2bd4aa) #1131 (c189cd7) +/-
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 (b2bd4aa) #1131 (c189cd7) +/-
Generate Median 2,279ms 2,753ms 474ms
Generate Max 2,294ms 2,773ms 479ms
Apply Build Median 2,317ms 2,791ms 474ms
Apply Build Max 2,453ms 2,967ms 514ms

Type Performance (instantiations)

main (b2bd4aa) #1131 (c189cd7) +/-
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

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 52 out of 55 changed files in this pull request and generated 1 comment.

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

Comment on lines 133 to 141
/**
* Sets up a mock for `globalThis.tailor.context.getInvoker` used in bundled
* resolver/executor/workflow tests.
* @deprecated With the `tailor-runtime` environment from `@tailor-platform/sdk/vitest`, drive the invoker via `vi.spyOn(globalThis.tailor.context, "getInvoker").mockReturnValue(...)` for bundled tests, or pass `invoker` directly to `.body()` when unit-testing resolvers/executors/workflow jobs against the TypeScript source.
* @param invoker - The `TailorInvoker` value to return, or `null` for anonymous.
*/
export function setupInvokerMock(invoker: TailorInvoker): void {
const raw: tailor.context.Invoker | null = invoker
const raw: ContextInvoker | null = invoker
? {
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