@tailor-platform/sdk 2.0.0-next.6 → 2.0.0-next.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/dist/{application-BJXRpQj5.mjs → application-GzW98_Xr.mjs} +199 -172
  3. package/dist/application-GzW98_Xr.mjs.map +1 -0
  4. package/dist/application-OM0taSPn.mjs +3 -0
  5. package/dist/cli/index.mjs +12 -9
  6. package/dist/cli/index.mjs.map +1 -1
  7. package/dist/cli/lib.mjs +2 -2
  8. package/dist/completion/zsh-worker.zsh +1 -1
  9. package/dist/configure/config/types.d.mts +5 -1
  10. package/dist/configure/index.mjs +16 -16
  11. package/dist/configure/index.mjs.map +1 -1
  12. package/dist/configure/services/auth/types.d.mts +18 -23
  13. package/dist/configure/services/executor/operation.d.mts +1 -1
  14. package/dist/configure/services/workflow/job.d.mts +10 -10
  15. package/dist/configure/services/workflow/workflow.d.mts +6 -4
  16. package/dist/{globals-D-YbJKW-.mjs → globals-CBZ0egXT.mjs} +3 -6
  17. package/dist/globals-CBZ0egXT.mjs.map +1 -0
  18. package/dist/{register-ts-hook-DL31O2W9.mjs → register-ts-hook-DvEs6YsL.mjs} +35 -78
  19. package/dist/register-ts-hook-DvEs6YsL.mjs.map +1 -0
  20. package/dist/{registry-CC3CbQiF.mjs → registry-i7EdJ-D5.mjs} +10 -10
  21. package/dist/registry-i7EdJ-D5.mjs.map +1 -0
  22. package/dist/runtime/globals.d.mts +1 -4
  23. package/dist/runtime/index.mjs +1 -1
  24. package/dist/runtime/workflow.d.mts +1 -76
  25. package/dist/runtime/workflow.mjs +1 -1
  26. package/dist/service-BJAQ70e5.mjs +3 -0
  27. package/dist/{service-CnHz9rwz.mjs → service-Dmxa2I4i.mjs} +31 -17
  28. package/dist/service-Dmxa2I4i.mjs.map +1 -0
  29. package/dist/utils/test/index.mjs +11 -11
  30. package/dist/utils/test/index.mjs.map +1 -1
  31. package/dist/utils/test/mock.d.mts +6 -6
  32. package/dist/vitest/environment.mjs +1 -1
  33. package/dist/vitest/index.mjs +67 -99
  34. package/dist/vitest/index.mjs.map +1 -1
  35. package/dist/vitest/mocks/workflow.d.mts +21 -41
  36. package/dist/vitest/setup.mjs +1 -1
  37. package/dist/vitest/workflow-local.d.mts +2 -2
  38. package/dist/workflow-CsBvRE3g.mjs +34 -0
  39. package/dist/workflow-CsBvRE3g.mjs.map +1 -0
  40. package/docs/cli/application.md +2 -0
  41. package/docs/cli/function.md +2 -2
  42. package/docs/cli/tailordb.md +2 -2
  43. package/docs/cli-reference.md +1 -1
  44. package/docs/configuration.md +2 -0
  45. package/docs/github-actions.md +2 -2
  46. package/docs/migration/v2.md +128 -11
  47. package/docs/runtime.md +1 -1
  48. package/docs/services/auth.md +7 -7
  49. package/docs/services/workflow.md +43 -43
  50. package/docs/testing.md +9 -9
  51. package/package.json +2 -2
  52. package/dist/application-BJXRpQj5.mjs.map +0 -1
  53. package/dist/application-BV-AXawv.mjs +0 -3
  54. package/dist/globals-D-YbJKW-.mjs.map +0 -1
  55. package/dist/register-ts-hook-DL31O2W9.mjs.map +0 -1
  56. package/dist/registry-CC3CbQiF.mjs.map +0 -1
  57. package/dist/service-CnHz9rwz.mjs.map +0 -1
  58. package/dist/service-nU6ITOHL.mjs +0 -3
  59. package/dist/workflow-9kHGKxF2.mjs +0 -64
  60. package/dist/workflow-9kHGKxF2.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/utils/test/mock.ts","../../../src/utils/test/index.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { ContextInvoker } from \"#/runtime/context\";\nimport type { TailorPrincipal } from \"#/runtime/types\";\nimport type { TriggerJobFunctionOptions } from \"#/runtime/workflow\";\n\ntype MainFunction = (args: Record<string, unknown>) => unknown | Promise<unknown>;\ntype QueryResolver = (query: string, params: unknown[]) => unknown[];\ntype JobHandler = (jobName: string, args: unknown) => unknown;\ntype WaitHandler = (key: string, payload: unknown) => unknown;\ntype ResolveHandler = (\n executionId: string,\n key: string,\n callback: (payload: unknown) => unknown,\n) => Promise<void> | void;\n\ninterface TailordbGlobal {\n tailordb?: {\n Client: new (config: { namespace?: string }) => {\n connect(): Promise<void> | void;\n end(): Promise<void> | void;\n queryObject(\n query: string,\n params?: unknown[],\n ): Promise<{ rows: unknown[] }> | { rows: unknown[] };\n };\n };\n tailor?: {\n workflow: {\n triggerJobFunction: (\n jobName: string,\n args: unknown,\n options?: TriggerJobFunctionOptions,\n ) => unknown;\n wait?: (key: string, payload?: unknown) => unknown;\n resolve?: (\n executionId: string,\n key: string,\n callback: (payload: unknown) => unknown,\n ) => Promise<void>;\n };\n context: {\n getInvoker: () => ContextInvoker | null;\n };\n };\n}\n\ninterface TailorErrorItem {\n message: string;\n path: (string | number)[];\n}\n\ninterface TailorErrorsGlobal {\n TailorErrors?: new (errors: TailorErrorItem[]) => Error;\n}\n\nconst GlobalThis = globalThis as TailordbGlobal & TailorErrorsGlobal;\n\n/**\n * Sets up a mock for `globalThis.tailordb.Client` used in bundled resolver/executor tests.\n * @deprecated Use `mockTailordb` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.\n * @param resolver - Optional function to resolve query results. Defaults to returning empty arrays.\n * @returns Object containing arrays of executed queries and created clients for assertions.\n */\nexport function setupTailordbMock(resolver: QueryResolver = () => []): {\n executedQueries: { query: string; params: unknown[] }[];\n createdClients: { namespace?: string; ended: boolean }[];\n} {\n const executedQueries: { query: string; params: unknown[] }[] = [];\n const createdClients: { namespace?: string; ended: boolean }[] = [];\n\n class MockTailordbClient {\n private record: { namespace?: string; ended: boolean };\n\n constructor({ namespace }: { namespace?: string }) {\n this.record = { namespace, ended: false };\n createdClients.push(this.record);\n }\n\n async connect(): Promise<void> {\n /* noop */\n }\n\n async end(): Promise<void> {\n this.record.ended = true;\n }\n\n async queryObject(query: string, params: unknown[] = []): Promise<{ rows: unknown[] }> {\n executedQueries.push({ query, params });\n return { rows: resolver(query, params) };\n }\n }\n\n GlobalThis.tailordb = {\n Client: MockTailordbClient,\n } as typeof GlobalThis.tailordb;\n\n return { executedQueries, createdClients };\n}\n\n/**\n * Sets up a mock for `globalThis.tailor.workflow.triggerJobFunction` used in bundled workflow tests.\n * `wait`/`resolve` are stubbed to throw a helpful error directing to `mockWorkflow`,\n * so mistakenly calling wait without wait-point mocks produces a clear message instead of a TypeError.\n * @deprecated Use `mockWorkflow` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.\n * @param handler - Function that handles triggered job calls and returns results.\n * @returns Object containing an array of triggered jobs for assertions.\n */\nexport function setupWorkflowMock(handler: JobHandler): {\n triggeredJobs: { jobName: string; args: unknown }[];\n} {\n const triggeredJobs: { jobName: string; args: unknown }[] = [];\n\n GlobalThis.tailor = {\n ...GlobalThis.tailor,\n workflow: {\n wait: () => {\n throw new Error(\n \"tailor.workflow.wait is not mocked. Use mockWorkflow from @tailor-platform/sdk/vitest in tests.\",\n );\n },\n resolve: async () => {\n throw new Error(\n \"tailor.workflow.resolve is not mocked. Use mockWorkflow from @tailor-platform/sdk/vitest in tests.\",\n );\n },\n ...GlobalThis.tailor?.workflow,\n triggerJobFunction: (jobName: string, args: unknown) => {\n triggeredJobs.push({ jobName, args });\n return handler(jobName, args);\n },\n },\n } as typeof GlobalThis.tailor;\n\n return { triggeredJobs };\n}\n\n/**\n * Sets up a mock for `globalThis.tailor.context.getInvoker` used in bundled\n * resolver/executor/workflow tests.\n * @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.\n * @param invoker - The `TailorPrincipal` value to return, or `null` for anonymous.\n */\nexport function setupInvokerMock(invoker: TailorPrincipal | null): void {\n const raw: ContextInvoker | null = invoker\n ? {\n id: invoker.id,\n type: invoker.type,\n workspaceId: invoker.workspaceId,\n attributes: invoker.attributeList as string[],\n attributeMap: invoker.attributes as Record<string, unknown>,\n }\n : null;\n\n GlobalThis.tailor = {\n ...GlobalThis.tailor,\n context: {\n getInvoker: () => raw,\n },\n } as typeof GlobalThis.tailor;\n}\n\n/**\n * Sets up a mock for `globalThis.TailorErrors` used in bundled resolver tests.\n * Mimics the PF runtime's TailorErrors class that serializes errors with the `TailorErrors: ` prefix.\n * @deprecated Use the `tailor-runtime` environment from `@tailor-platform/sdk/vitest` which auto-injects TailorErrors.\n */\nexport function setupTailorErrorsMock(): void {\n GlobalThis.TailorErrors = class TailorErrors extends Error {\n errors: TailorErrorItem[];\n\n constructor(errors: TailorErrorItem[]) {\n super(`TailorErrors: ${JSON.stringify({ errors })}`);\n this.name = \"TailorErrors\";\n this.errors = errors;\n }\n };\n}\n\n/**\n * Sets up mocks for `globalThis.tailor.workflow.wait` and `.resolve` used in bundled workflow tests.\n * `triggerJobFunction` is stubbed to throw a helpful error directing to `setupWorkflowMock()`,\n * so mistakenly triggering a job without job mocks produces a clear message instead of silently returning undefined.\n * @deprecated Use `mockWorkflow` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.\n * `setWaitHandler` / `setResolveHandler` cover wait/resolve, and `waitCalls` / `resolveCalls` give the same assertion shape.\n * @param config - Optional handlers for wait and resolve calls.\n * @param config.onWait - Handler called when wait is invoked.\n * @param config.onResolve - Handler called when resolve is invoked.\n * @returns Object containing arrays of wait and resolve calls for assertions.\n */\nexport function setupWaitPointMock(config?: { onWait?: WaitHandler; onResolve?: ResolveHandler }): {\n waitCalls: { key: string; payload: unknown }[];\n resolveCalls: { executionId: string; key: string }[];\n} {\n const waitCalls: { key: string; payload: unknown }[] = [];\n const resolveCalls: { executionId: string; key: string }[] = [];\n\n GlobalThis.tailor = {\n ...GlobalThis.tailor,\n workflow: {\n triggerJobFunction: () => {\n throw new Error(\n \"tailor.workflow.triggerJobFunction is not mocked. Use setupWorkflowMock() in tests.\",\n );\n },\n ...GlobalThis.tailor?.workflow,\n wait: (key: string, payload?: unknown) => {\n waitCalls.push({ key, payload });\n return config?.onWait?.(key, payload);\n },\n resolve: async (\n executionId: string,\n key: string,\n callback: (payload: unknown) => unknown,\n ) => {\n resolveCalls.push({ executionId, key });\n await config?.onResolve?.(executionId, key, callback);\n },\n },\n } as typeof GlobalThis.tailor;\n\n return { waitCalls, resolveCalls };\n}\n\n/**\n * Creates a function that imports a bundled JS file and returns its `main` export.\n * Used to test bundled output from `apply --buildOnly`.\n * @param baseDir - Base directory where bundled files are located.\n * @returns An async function that takes a relative path and returns the `main` function.\n * @deprecated This is an SDK-internal testing helper. Bundling integrity is the SDK's responsibility,\n * not the application's — verify your code through unit tests against the TypeScript source and\n * E2E tests against a deployed application instead. This export will be removed in a future release.\n */\nexport function createImportMain(baseDir: string): (relativePath: string) => Promise<MainFunction> {\n return async (relativePath: string): Promise<MainFunction> => {\n const fileUrl = pathToFileURL(path.join(baseDir, relativePath));\n fileUrl.searchParams.set(\"v\", `${Date.now()}-${Math.random()}`);\n const module = await import(fileUrl.href);\n const main = module.main;\n if (typeof main !== \"function\") {\n throw new Error(`Expected \"main\" to be a function in ${relativePath}, got ${typeof main}`);\n }\n return main;\n };\n}\n","import type { output } from \"#/configure/index\";\nimport type { TailorDBType } from \"#/configure/services/tailordb/schema\";\nimport type { TailorField } from \"#/configure/types/type\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\nexport {\n setupTailordbMock,\n setupTailorErrorsMock,\n setupWorkflowMock,\n setupInvokerMock,\n setupWaitPointMock,\n createImportMain,\n} from \"./mock\";\n\n/**\n * Creates a hook function that processes TailorDB type fields\n * - Uses existing id from data if provided, otherwise generates UUID for id fields\n * - Recursively processes nested types\n * - Executes hooks.create for fields with create hooks\n * @template T - The output type of the hook function\n * @param type - TailorDB type definition\n * @returns A function that transforms input data according to field hooks\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function createTailorDBHook<T extends TailorDBType<any, any>>(type: T) {\n return (data: unknown, now: Date = new Date()) => {\n const obj = data && typeof data === \"object\" ? (data as Record<string, unknown>) : undefined;\n const hooked = Object.entries(type.fields).reduce(\n (hooked, [key, value]) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const field = value as TailorField<any, any, any>;\n if (key === \"id\") {\n hooked[key] = obj?.[key] ?? crypto.randomUUID();\n } else if (field.type === \"nested\") {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const nestedHook = createTailorDBHook({ fields: field.fields } as any);\n if (field.metadata.array) {\n const nestedValue = obj?.[key];\n hooked[key] = Array.isArray(nestedValue)\n ? nestedValue.map((item) => nestedHook(item, now))\n : nestedValue;\n } else {\n hooked[key] = nestedHook(obj?.[key], now);\n }\n } else if (field.metadata.hooks?.create) {\n hooked[key] = field.metadata.hooks.create({\n input: obj?.[key],\n invoker: null,\n now,\n });\n if (hooked[key] instanceof Date) {\n hooked[key] = hooked[key].toISOString();\n }\n } else if (obj) {\n hooked[key] = obj[key];\n }\n if (hooked[key] == null && field.metadata.default !== undefined) {\n const isTimeType =\n field.type === \"datetime\" || field.type === \"date\" || field.type === \"time\";\n hooked[key] =\n field.metadata.default === \"now\" && isTimeType\n ? now.toISOString()\n : field.metadata.default;\n }\n return hooked;\n },\n {} as Record<string, unknown>,\n );\n\n // oxlint-disable-next-line typescript/no-unnecessary-condition -- metadata absent in recursive nested calls\n if (type.metadata?.typeHook?.create) {\n const { id: _id, ...typeHookInput } = hooked;\n // oxlint-disable-next-line typescript/no-unsafe-function-type\n const overrides = (type.metadata.typeHook.create as Function)({\n input: typeHookInput,\n invoker: null,\n now,\n });\n if (overrides && typeof overrides === \"object\") {\n for (const [key, value] of Object.entries(overrides as Record<string, unknown>)) {\n hooked[key] = value instanceof Date ? value.toISOString() : value;\n }\n }\n }\n\n // oxlint-disable-next-line typescript/no-unnecessary-condition -- metadata absent in recursive nested calls\n if (type.metadata?.typeValidate) {\n const { id: _id, ...newRecord } = hooked;\n // oxlint-disable-next-line typescript/no-unsafe-function-type\n (type.metadata.typeValidate as Function)(\n { newRecord, oldRecord: null, invoker: null },\n (field: string, message: string) => {\n throw new Error(`Validation failed on field '${field}': ${message}`);\n },\n );\n }\n\n return hooked as Partial<output<T>>;\n };\n}\n\n/**\n * Creates the standard schema definition for lines-db\n * This returns the first argument for defineSchema with the ~standard section\n * @template T - The output type after validation\n * @param schemaType - TailorDB field schema for validation\n * @param hook - Hook function to transform data before validation\n * @returns Schema object with ~standard section for defineSchema\n */\nexport function createStandardSchema<T = Record<string, unknown>>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schemaType: TailorField<any, T>,\n hook: (data: unknown) => Partial<T>,\n) {\n return {\n \"~standard\": {\n version: 1,\n vendor: \"@tailor-platform/sdk\",\n validate: (value: unknown) => {\n const hooked = hook(value);\n const result = schemaType.parse({\n value: hooked,\n data: hooked,\n invoker: null,\n });\n if (result.issues) {\n return result;\n }\n return { value: hooked as T };\n },\n },\n } as const satisfies StandardSchemaV1<T>;\n}\n"],"mappings":";;;;AAwDA,MAAM,aAAa;;;;;;;AAQnB,SAAgB,kBAAkB,iBAAgC,CAAC,GAGjE;CACA,MAAM,kBAA0D,CAAC;CACjE,MAAM,iBAA2D,CAAC;CAElE,MAAM,mBAAmB;EACvB,AAAQ;EAER,YAAY,EAAE,aAAqC;GACjD,KAAK,SAAS;IAAE;IAAW,OAAO;GAAM;GACxC,eAAe,KAAK,KAAK,MAAM;EACjC;EAEA,MAAM,UAAyB,CAE/B;EAEA,MAAM,MAAqB;GACzB,KAAK,OAAO,QAAQ;EACtB;EAEA,MAAM,YAAY,OAAe,SAAoB,CAAC,GAAiC;GACrF,gBAAgB,KAAK;IAAE;IAAO;GAAO,CAAC;GACtC,OAAO,EAAE,MAAM,SAAS,OAAO,MAAM,EAAE;EACzC;CACF;CAEA,WAAW,WAAW,EACpB,QAAQ,mBACV;CAEA,OAAO;EAAE;EAAiB;CA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YAAY;GAE1C,OAAO,IAAI,KACT,OAAO,OAAO,IAAI;GAEpB,IAAI,OAAO,QAAQ,QAAQ,MAAM,SAAS,YAAY,QAAW;IAC/D,MAAM,aACJ,MAAM,SAAS,cAAc,MAAM,SAAS,UAAU,MAAM,SAAS;IACvE,OAAO,OACL,MAAM,SAAS,YAAY,SAAS,aAChC,IAAI,YAAY,IAChB,MAAM,SAAS;GACvB;GACA,OAAO;EACT,GACA,CAAC,CACH;EAGA,IAAI,KAAK,UAAU,UAAU,QAAQ;GACnC,MAAM,EAAE,IAAI,KAAK,GAAG,kBAAkB;GAEtC,MAAM,YAAa,KAAK,SAAS,SAAS,OAAoB;IAC5D,OAAO;IACP,SAAS;IACT;GACF,CAAC;GACD,IAAI,aAAa,OAAO,cAAc,UACpC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,SAAoC,GAC5E,OAAO,OAAO,iBAAiB,OAAO,MAAM,YAAY,IAAI;EAGlE;EAGA,IAAI,KAAK,UAAU,cAAc;GAC/B,MAAM,EAAE,IAAI,KAAK,GAAG,cAAc;GAElC,AAAC,KAAK,SAAS,aACb;IAAE;IAAW,WAAW;IAAM,SAAS;GAAK,IAC3C,OAAe,YAAoB;IAClC,MAAM,IAAI,MAAM,+BAA+B,MAAM,KAAK,SAAS;GACrE,CACF;EACF;EAEA,OAAO;CACT;AACF;;;;;;;;;AAUA,SAAgB,qBAEd,YACA,MACA;CACA,OAAO,EACL,aAAa;EACX,SAAS;EACT,QAAQ;EACR,WAAW,UAAmB;GAC5B,MAAM,SAAS,KAAK,KAAK;GACzB,MAAM,SAAS,WAAW,MAAM;IAC9B,OAAO;IACP,MAAM;IACN,SAAS;GACX,CAAC;GACD,IAAI,OAAO,QACT,OAAO;GAET,OAAO,EAAE,OAAO,OAAY;EAC9B;CACF,EACF;AACF"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/utils/test/mock.ts","../../../src/utils/test/index.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { ContextInvoker } from \"#/runtime/context\";\nimport type { TailorPrincipal } from \"#/runtime/types\";\nimport type { StartJobFunctionOptions } from \"#/runtime/workflow\";\n\ntype MainFunction = (args: Record<string, unknown>) => unknown | Promise<unknown>;\ntype QueryResolver = (query: string, params: unknown[]) => unknown[];\ntype JobHandler = (jobName: string, args: unknown) => unknown;\ntype WaitHandler = (key: string, payload: unknown) => unknown;\ntype ResolveHandler = (\n executionId: string,\n key: string,\n callback: (payload: unknown) => unknown,\n) => Promise<void> | void;\n\ninterface TailordbGlobal {\n tailordb?: {\n Client: new (config: { namespace?: string }) => {\n connect(): Promise<void> | void;\n end(): Promise<void> | void;\n queryObject(\n query: string,\n params?: unknown[],\n ): Promise<{ rows: unknown[] }> | { rows: unknown[] };\n };\n };\n tailor?: {\n workflow: {\n startJobFunction: (\n jobName: string,\n args: unknown,\n options?: StartJobFunctionOptions,\n ) => unknown;\n wait?: (key: string, payload?: unknown) => unknown;\n resolve?: (\n executionId: string,\n key: string,\n callback: (payload: unknown) => unknown,\n ) => Promise<void>;\n };\n context: {\n getInvoker: () => ContextInvoker | null;\n };\n };\n}\n\ninterface TailorErrorItem {\n message: string;\n path: (string | number)[];\n}\n\ninterface TailorErrorsGlobal {\n TailorErrors?: new (errors: TailorErrorItem[]) => Error;\n}\n\nconst GlobalThis = globalThis as unknown as TailordbGlobal & TailorErrorsGlobal;\n\n/**\n * Sets up a mock for `globalThis.tailordb.Client` used in bundled resolver/executor tests.\n * @deprecated Use `mockTailordb` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.\n * @param resolver - Optional function to resolve query results. Defaults to returning empty arrays.\n * @returns Object containing arrays of executed queries and created clients for assertions.\n */\nexport function setupTailordbMock(resolver: QueryResolver = () => []): {\n executedQueries: { query: string; params: unknown[] }[];\n createdClients: { namespace?: string; ended: boolean }[];\n} {\n const executedQueries: { query: string; params: unknown[] }[] = [];\n const createdClients: { namespace?: string; ended: boolean }[] = [];\n\n class MockTailordbClient {\n private record: { namespace?: string; ended: boolean };\n\n constructor({ namespace }: { namespace?: string }) {\n this.record = { namespace, ended: false };\n createdClients.push(this.record);\n }\n\n async connect(): Promise<void> {\n /* noop */\n }\n\n async end(): Promise<void> {\n this.record.ended = true;\n }\n\n async queryObject(query: string, params: unknown[] = []): Promise<{ rows: unknown[] }> {\n executedQueries.push({ query, params });\n return { rows: resolver(query, params) };\n }\n }\n\n GlobalThis.tailordb = {\n Client: MockTailordbClient,\n } as typeof GlobalThis.tailordb;\n\n return { executedQueries, createdClients };\n}\n\n/**\n * Sets up a mock for `globalThis.tailor.workflow.startJobFunction` used in bundled workflow tests.\n * `wait`/`resolve` are stubbed to throw a helpful error directing to `mockWorkflow`,\n * so mistakenly calling wait without wait-point mocks produces a clear message instead of a TypeError.\n * @deprecated Use `mockWorkflow` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.\n * @param handler - Function that handles started job calls and returns results.\n * @returns Object containing an array of started jobs for assertions.\n */\nexport function setupWorkflowMock(handler: JobHandler): {\n startedJobs: { jobName: string; args: unknown }[];\n} {\n const startedJobs: { jobName: string; args: unknown }[] = [];\n\n GlobalThis.tailor = {\n ...GlobalThis.tailor,\n workflow: {\n wait: () => {\n throw new Error(\n \"tailor.workflow.wait is not mocked. Use mockWorkflow from @tailor-platform/sdk/vitest in tests.\",\n );\n },\n resolve: async () => {\n throw new Error(\n \"tailor.workflow.resolve is not mocked. Use mockWorkflow from @tailor-platform/sdk/vitest in tests.\",\n );\n },\n ...GlobalThis.tailor?.workflow,\n startJobFunction: (jobName: string, args: unknown) => {\n startedJobs.push({ jobName, args });\n return handler(jobName, args);\n },\n },\n } as typeof GlobalThis.tailor;\n\n return { startedJobs };\n}\n\n/**\n * Sets up a mock for `globalThis.tailor.context.getInvoker` used in bundled\n * resolver/executor/workflow tests.\n * @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.\n * @param invoker - The `TailorPrincipal` value to return, or `null` for anonymous.\n */\nexport function setupInvokerMock(invoker: TailorPrincipal | null): void {\n const raw: ContextInvoker | null = invoker\n ? {\n id: invoker.id,\n type: invoker.type,\n workspaceId: invoker.workspaceId,\n attributes: invoker.attributeList as string[],\n attributeMap: invoker.attributes as Record<string, unknown>,\n }\n : null;\n\n GlobalThis.tailor = {\n ...GlobalThis.tailor,\n context: {\n getInvoker: () => raw,\n },\n } as typeof GlobalThis.tailor;\n}\n\n/**\n * Sets up a mock for `globalThis.TailorErrors` used in bundled resolver tests.\n * Mimics the PF runtime's TailorErrors class that serializes errors with the `TailorErrors: ` prefix.\n * @deprecated Use the `tailor-runtime` environment from `@tailor-platform/sdk/vitest` which auto-injects TailorErrors.\n */\nexport function setupTailorErrorsMock(): void {\n GlobalThis.TailorErrors = class TailorErrors extends Error {\n errors: TailorErrorItem[];\n\n constructor(errors: TailorErrorItem[]) {\n super(`TailorErrors: ${JSON.stringify({ errors })}`);\n this.name = \"TailorErrors\";\n this.errors = errors;\n }\n };\n}\n\n/**\n * Sets up mocks for `globalThis.tailor.workflow.wait` and `.resolve` used in bundled workflow tests.\n * `startJobFunction` is stubbed to throw a helpful error directing to `setupWorkflowMock()`,\n * so mistakenly starting a job without job mocks produces a clear message instead of silently returning undefined.\n * @deprecated Use `mockWorkflow` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.\n * `setWaitHandler` / `setResolveHandler` cover wait/resolve, and `waitCalls` / `resolveCalls` give the same assertion shape.\n * @param config - Optional handlers for wait and resolve calls.\n * @param config.onWait - Handler called when wait is invoked.\n * @param config.onResolve - Handler called when resolve is invoked.\n * @returns Object containing arrays of wait and resolve calls for assertions.\n */\nexport function setupWaitPointMock(config?: { onWait?: WaitHandler; onResolve?: ResolveHandler }): {\n waitCalls: { key: string; payload: unknown }[];\n resolveCalls: { executionId: string; key: string }[];\n} {\n const waitCalls: { key: string; payload: unknown }[] = [];\n const resolveCalls: { executionId: string; key: string }[] = [];\n\n GlobalThis.tailor = {\n ...GlobalThis.tailor,\n workflow: {\n startJobFunction: () => {\n throw new Error(\n \"tailor.workflow.startJobFunction is not mocked. Use setupWorkflowMock() in tests.\",\n );\n },\n ...GlobalThis.tailor?.workflow,\n wait: (key: string, payload?: unknown) => {\n waitCalls.push({ key, payload });\n return config?.onWait?.(key, payload);\n },\n resolve: async (\n executionId: string,\n key: string,\n callback: (payload: unknown) => unknown,\n ) => {\n resolveCalls.push({ executionId, key });\n await config?.onResolve?.(executionId, key, callback);\n },\n },\n } as typeof GlobalThis.tailor;\n\n return { waitCalls, resolveCalls };\n}\n\n/**\n * Creates a function that imports a bundled JS file and returns its `main` export.\n * Used to test bundled output from `apply --buildOnly`.\n * @param baseDir - Base directory where bundled files are located.\n * @returns An async function that takes a relative path and returns the `main` function.\n * @deprecated This is an SDK-internal testing helper. Bundling integrity is the SDK's responsibility,\n * not the application's — verify your code through unit tests against the TypeScript source and\n * E2E tests against a deployed application instead. This export will be removed in a future release.\n */\nexport function createImportMain(baseDir: string): (relativePath: string) => Promise<MainFunction> {\n return async (relativePath: string): Promise<MainFunction> => {\n const fileUrl = pathToFileURL(path.join(baseDir, relativePath));\n fileUrl.searchParams.set(\"v\", `${Date.now()}-${Math.random()}`);\n const module = await import(fileUrl.href);\n const main = module.main;\n if (typeof main !== \"function\") {\n throw new Error(`Expected \"main\" to be a function in ${relativePath}, got ${typeof main}`);\n }\n return main;\n };\n}\n","import type { output } from \"#/configure/index\";\nimport type { TailorDBType } from \"#/configure/services/tailordb/schema\";\nimport type { TailorField } from \"#/configure/types/type\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\nexport {\n setupTailordbMock,\n setupTailorErrorsMock,\n setupWorkflowMock,\n setupInvokerMock,\n setupWaitPointMock,\n createImportMain,\n} from \"./mock\";\n\n/**\n * Creates a hook function that processes TailorDB type fields\n * - Uses existing id from data if provided, otherwise generates UUID for id fields\n * - Recursively processes nested types\n * - Executes hooks.create for fields with create hooks\n * @template T - The output type of the hook function\n * @param type - TailorDB type definition\n * @returns A function that transforms input data according to field hooks\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function createTailorDBHook<T extends TailorDBType<any, any>>(type: T) {\n return (data: unknown, now: Date = new Date()) => {\n const obj = data && typeof data === \"object\" ? (data as Record<string, unknown>) : undefined;\n const hooked = Object.entries(type.fields).reduce(\n (hooked, [key, value]) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const field = value as TailorField<any, any, any>;\n if (key === \"id\") {\n hooked[key] = obj?.[key] ?? crypto.randomUUID();\n } else if (field.type === \"nested\") {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const nestedHook = createTailorDBHook({ fields: field.fields } as any);\n if (field.metadata.array) {\n const nestedValue = obj?.[key];\n hooked[key] = Array.isArray(nestedValue)\n ? nestedValue.map((item) => nestedHook(item, now))\n : nestedValue;\n } else {\n hooked[key] = nestedHook(obj?.[key], now);\n }\n } else if (field.metadata.hooks?.create) {\n hooked[key] = field.metadata.hooks.create({\n input: obj?.[key],\n invoker: null,\n now,\n });\n if (hooked[key] instanceof Date) {\n hooked[key] = hooked[key].toISOString();\n }\n } else if (obj) {\n hooked[key] = obj[key];\n }\n if (hooked[key] == null && field.metadata.default !== undefined) {\n const isTimeType =\n field.type === \"datetime\" || field.type === \"date\" || field.type === \"time\";\n hooked[key] =\n field.metadata.default === \"now\" && isTimeType\n ? now.toISOString()\n : field.metadata.default;\n }\n return hooked;\n },\n {} as Record<string, unknown>,\n );\n\n // oxlint-disable-next-line typescript/no-unnecessary-condition -- metadata absent in recursive nested calls\n if (type.metadata?.typeHook?.create) {\n const { id: _id, ...typeHookInput } = hooked;\n // oxlint-disable-next-line typescript/no-unsafe-function-type\n const overrides = (type.metadata.typeHook.create as Function)({\n input: typeHookInput,\n invoker: null,\n now,\n });\n if (overrides && typeof overrides === \"object\") {\n for (const [key, value] of Object.entries(overrides as Record<string, unknown>)) {\n hooked[key] = value instanceof Date ? value.toISOString() : value;\n }\n }\n }\n\n // oxlint-disable-next-line typescript/no-unnecessary-condition -- metadata absent in recursive nested calls\n if (type.metadata?.typeValidate) {\n const { id: _id, ...newRecord } = hooked;\n // oxlint-disable-next-line typescript/no-unsafe-function-type\n (type.metadata.typeValidate as Function)(\n { newRecord, oldRecord: null, invoker: null },\n (field: string, message: string) => {\n throw new Error(`Validation failed on field '${field}': ${message}`);\n },\n );\n }\n\n return hooked as Partial<output<T>>;\n };\n}\n\n/**\n * Creates the standard schema definition for lines-db\n * This returns the first argument for defineSchema with the ~standard section\n * @template T - The output type after validation\n * @param schemaType - TailorDB field schema for validation\n * @param hook - Hook function to transform data before validation\n * @returns Schema object with ~standard section for defineSchema\n */\nexport function createStandardSchema<T = Record<string, unknown>>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schemaType: TailorField<any, T>,\n hook: (data: unknown) => Partial<T>,\n) {\n return {\n \"~standard\": {\n version: 1,\n vendor: \"@tailor-platform/sdk\",\n validate: (value: unknown) => {\n const hooked = hook(value);\n const result = schemaType.parse({\n value: hooked,\n data: hooked,\n invoker: null,\n });\n if (result.issues) {\n return result;\n }\n return { value: hooked as T };\n },\n },\n } as const satisfies StandardSchemaV1<T>;\n}\n"],"mappings":";;;;AAwDA,MAAM,aAAa;;;;;;;AAQnB,SAAgB,kBAAkB,iBAAgC,CAAC,GAGjE;CACA,MAAM,kBAA0D,CAAC;CACjE,MAAM,iBAA2D,CAAC;CAElE,MAAM,mBAAmB;EACvB,AAAQ;EAER,YAAY,EAAE,aAAqC;GACjD,KAAK,SAAS;IAAE;IAAW,OAAO;GAAM;GACxC,eAAe,KAAK,KAAK,MAAM;EACjC;EAEA,MAAM,UAAyB,CAE/B;EAEA,MAAM,MAAqB;GACzB,KAAK,OAAO,QAAQ;EACtB;EAEA,MAAM,YAAY,OAAe,SA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,CAAC;GACD,IAAI,OAAO,QACT,OAAO;GAET,OAAO,EAAE,OAAO,OAAY;EAC9B;CACF,EACF;AACF"}
@@ -22,15 +22,15 @@ declare function setupTailordbMock(resolver?: QueryResolver): {
22
22
  }[];
23
23
  };
24
24
  /**
25
- * Sets up a mock for `globalThis.tailor.workflow.triggerJobFunction` used in bundled workflow tests.
25
+ * Sets up a mock for `globalThis.tailor.workflow.startJobFunction` used in bundled workflow tests.
26
26
  * `wait`/`resolve` are stubbed to throw a helpful error directing to `mockWorkflow`,
27
27
  * so mistakenly calling wait without wait-point mocks produces a clear message instead of a TypeError.
28
28
  * @deprecated Use `mockWorkflow` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.
29
- * @param handler - Function that handles triggered job calls and returns results.
30
- * @returns Object containing an array of triggered jobs for assertions.
29
+ * @param handler - Function that handles started job calls and returns results.
30
+ * @returns Object containing an array of started jobs for assertions.
31
31
  */
32
32
  declare function setupWorkflowMock(handler: JobHandler): {
33
- triggeredJobs: {
33
+ startedJobs: {
34
34
  jobName: string;
35
35
  args: unknown;
36
36
  }[];
@@ -50,8 +50,8 @@ declare function setupInvokerMock(invoker: TailorPrincipal | null): void;
50
50
  declare function setupTailorErrorsMock(): void;
51
51
  /**
52
52
  * Sets up mocks for `globalThis.tailor.workflow.wait` and `.resolve` used in bundled workflow tests.
53
- * `triggerJobFunction` is stubbed to throw a helpful error directing to `setupWorkflowMock()`,
54
- * so mistakenly triggering a job without job mocks produces a clear message instead of silently returning undefined.
53
+ * `startJobFunction` is stubbed to throw a helpful error directing to `setupWorkflowMock()`,
54
+ * so mistakenly starting a job without job mocks produces a clear message instead of silently returning undefined.
55
55
  * @deprecated Use `mockWorkflow` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.
56
56
  * `setWaitHandler` / `setResolveHandler` cover wait/resolve, and `waitCalls` / `resolveCalls` give the same assertion shape.
57
57
  * @param config - Optional handlers for wait and resolve calls.
@@ -1,4 +1,4 @@
1
- import { n as cleanupPlatformGlobals, r as installPlatformGlobals, t as RUNTIME_FLAG_KEY } from "../globals-D-YbJKW-.mjs";
1
+ import { n as cleanupPlatformGlobals, r as installPlatformGlobals, t as RUNTIME_FLAG_KEY } from "../globals-CBZ0egXT.mjs";
2
2
  import * as globals from "globals";
3
3
 
4
4
  //#region src/vitest/environment.ts
@@ -1,4 +1,4 @@
1
- import { i as getRegisteredJob, t as TRIGGER_DEFAULT } from "../registry-CC3CbQiF.mjs";
1
+ import { i as getRegisteredJob, t as START_DEFAULT } from "../registry-i7EdJ-D5.mjs";
2
2
  import { a as writeWorkflowTestEnv, n as clearWorkflowTestEnv, r as readWorkflowTestEnv, t as buildJobContext } from "../test-env-key-D7UkZp99.mjs";
3
3
  import { t as assertDefined } from "../assert-DBxo8jPo.mjs";
4
4
  import { t as platformSerialize } from "../platform-serialize-RoRtBS0v.mjs";
@@ -1150,23 +1150,18 @@ function replaceProcedure(target, key, current) {
1150
1150
  }
1151
1151
  };
1152
1152
  }
1153
- function replaceTrigger(definition) {
1154
- return replaceProcedure(definition, "trigger", definition.trigger);
1153
+ function replaceStart(definition) {
1154
+ return replaceProcedure(definition, "start", definition.start);
1155
1155
  }
1156
1156
  /**
1157
1157
  * Acquire a disposable mock for workflow operations (`tailor.workflow`).
1158
1158
  * Restored on dispose.
1159
- *
1160
- * Canonical names (`startWorkflow`, `startJobFunction`, `resumeWorkflowExecution`)
1161
- * and their frozen aliases (`triggerWorkflow`, `triggerJobFunction`, `resumeWorkflow`)
1162
- * share the same underlying `vi.fn`, so calls through either name are recorded
1163
- * once and handlers configured on either name apply to both.
1164
1159
  * @returns Disposable workflow mock control object
1165
1160
  * @example
1166
1161
  * ```typescript
1167
1162
  * import { mockWorkflow } from "@tailor-platform/sdk/vitest";
1168
1163
  *
1169
- * test("job trigger", async () => {
1164
+ * test("job start", async () => {
1170
1165
  * using wf = mockWorkflow();
1171
1166
  * const job = wf.job(validateOrder);
1172
1167
  * job.mockResolvedValue({ valid: true });
@@ -1183,31 +1178,28 @@ function mockWorkflow() {
1183
1178
  const workflowSpies = /* @__PURE__ */ new Map();
1184
1179
  const waitPointMocks = /* @__PURE__ */ new Map();
1185
1180
  const scopedMocks = /* @__PURE__ */ new Set();
1186
- const defaultTriggerJob = (jobName, _args, _options) => {
1181
+ const defaultStartJob = (jobName, _args, _options) => {
1187
1182
  throw new Error(`No workflow job mock for "${jobName}". Call mockWorkflow().setJobHandler(...) or enqueueResult(...), or use runWorkflowLocally() for local workflow execution.`);
1188
1183
  };
1189
- const defaultTriggerWorkflow = async (_workflowName, _args, _options) => {
1190
- return TRIGGER_DEFAULT;
1184
+ const defaultStartWorkflow = async (_workflowName, _args, _options) => {
1185
+ return START_DEFAULT;
1191
1186
  };
1192
- const defaultResumeWorkflow = async (executionId) => executionId;
1193
- const triggerJobFunction = vi.fn(defaultTriggerJob);
1194
- const triggerWorkflow = vi.fn(defaultTriggerWorkflow);
1195
- const resumeWorkflow = vi.fn(defaultResumeWorkflow);
1187
+ const defaultResumeWorkflowExecution = async (executionId) => executionId;
1188
+ const startJobFunction = vi.fn(defaultStartJob);
1189
+ const startWorkflow = vi.fn(defaultStartWorkflow);
1190
+ const resumeWorkflowExecution = vi.fn(defaultResumeWorkflowExecution);
1196
1191
  const wait = vi.fn((_key, _payload) => null);
1197
1192
  const resolve = vi.fn(async (_executionId, _key, _callback) => {});
1198
1193
  const jobFunctionShim = (...call) => {
1199
- const out = call.length >= 3 ? triggerJobFunction(call[0], platformSerialize(call[1]), call[2]) : triggerJobFunction(call[0], platformSerialize(call[1]));
1194
+ const out = call.length >= 3 ? startJobFunction(call[0], platformSerialize(call[1]), call[2]) : startJobFunction(call[0], platformSerialize(call[1]));
1200
1195
  return out instanceof Promise ? out.then((v) => platformSerialize(v)) : platformSerialize(out);
1201
1196
  };
1202
- const workflowShim = (...call) => call.length >= 3 ? triggerWorkflow(call[0], platformSerialize(call[1]), call[2]) : triggerWorkflow(call[0], platformSerialize(call[1]));
1203
- const resumeShim = (executionId) => resumeWorkflow(executionId);
1197
+ const workflowShim = (...call) => call.length >= 3 ? startWorkflow(call[0], platformSerialize(call[1]), call[2]) : startWorkflow(call[0], platformSerialize(call[1]));
1198
+ const resumeShim = (executionId) => resumeWorkflowExecution(executionId);
1204
1199
  root.workflow = {
1205
1200
  startJobFunction: jobFunctionShim,
1206
- triggerJobFunction: jobFunctionShim,
1207
1201
  startWorkflow: workflowShim,
1208
- triggerWorkflow: workflowShim,
1209
1202
  resumeWorkflowExecution: resumeShim,
1210
- resumeWorkflow: resumeShim,
1211
1203
  wait: (key, payload) => wait(key, platformSerialize(payload)),
1212
1204
  resolve: (executionId, key, callback) => resolve(executionId, key, (payload) => {
1213
1205
  const out = callback(payload);
@@ -1216,54 +1208,39 @@ function mockWorkflow() {
1216
1208
  };
1217
1209
  return withDispose({
1218
1210
  /** The `startJobFunction` `vi.fn`. */
1219
- startJobFunction: triggerJobFunction,
1220
- /**
1221
- * Frozen alias of `startJobFunction` (same `vi.fn` reference).
1222
- * @deprecated Use `startJobFunction` instead.
1223
- */
1224
- triggerJobFunction,
1211
+ startJobFunction,
1225
1212
  /** The `startWorkflow` `vi.fn`. */
1226
- startWorkflow: triggerWorkflow,
1227
- /**
1228
- * Frozen alias of `startWorkflow` (same `vi.fn` reference).
1229
- * @deprecated Use `startWorkflow` instead.
1230
- */
1231
- triggerWorkflow,
1213
+ startWorkflow,
1232
1214
  /** The `resumeWorkflowExecution` `vi.fn`. */
1233
- resumeWorkflowExecution: resumeWorkflow,
1234
- /**
1235
- * Frozen alias of `resumeWorkflowExecution` (same `vi.fn` reference).
1236
- * @deprecated Use `resumeWorkflowExecution` instead.
1237
- */
1238
- resumeWorkflow,
1215
+ resumeWorkflowExecution,
1239
1216
  /** The `wait` `vi.fn`. */
1240
1217
  wait,
1241
1218
  /** The `resolve` `vi.fn`. */
1242
1219
  resolve,
1243
1220
  /**
1244
- * Get a stable, typed mock for a workflow job's `trigger` method.
1245
- * The real trigger behavior is used until an implementation or result is configured.
1221
+ * Get a stable, typed mock for a workflow job's `start` method.
1222
+ * The real start behavior is used until an implementation or result is configured.
1246
1223
  * @param definition - Workflow job definition to mock
1247
- * @returns Typed `trigger` mock for the definition
1224
+ * @returns Typed `start` mock for the definition
1248
1225
  */
1249
1226
  job(definition) {
1250
1227
  const existing = jobSpies.get(definition);
1251
1228
  if (existing) return existing;
1252
- const { mock, scoped } = replaceTrigger(definition);
1229
+ const { mock, scoped } = replaceStart(definition);
1253
1230
  scopedMocks.add(scoped);
1254
1231
  jobSpies.set(definition, mock);
1255
1232
  return mock;
1256
1233
  },
1257
1234
  /**
1258
- * Get a stable, typed mock for a workflow definition's `trigger` method.
1259
- * The real trigger behavior is used until an implementation or result is configured.
1235
+ * Get a stable, typed mock for a workflow definition's `start` method.
1236
+ * The real start behavior is used until an implementation or result is configured.
1260
1237
  * @param definition - Workflow definition to mock
1261
- * @returns Typed `trigger` mock for the definition
1238
+ * @returns Typed `start` mock for the definition
1262
1239
  */
1263
1240
  workflow(definition) {
1264
1241
  const existing = workflowSpies.get(definition);
1265
1242
  if (existing) return existing;
1266
- const { mock, scoped } = replaceTrigger(definition);
1243
+ const { mock, scoped } = replaceStart(definition);
1267
1244
  workflowSpies.set(definition, mock);
1268
1245
  scopedMocks.add(scoped);
1269
1246
  return mock;
@@ -1303,49 +1280,49 @@ function mockWorkflow() {
1303
1280
  * @param handler - Function returning a result for a job name, args, and options
1304
1281
  */
1305
1282
  setJobHandler(handler) {
1306
- triggerJobFunction.mockImplementation((name, args, options) => handler(name, args, options));
1283
+ startJobFunction.mockImplementation((name, args, options) => handler(name, args, options));
1307
1284
  },
1308
1285
  /**
1309
- * Enqueue a single result for the next `triggerJobFunction` call (FIFO;
1286
+ * Enqueue a single result for the next `startJobFunction` call (FIFO;
1310
1287
  * takes priority over `setJobHandler`).
1311
1288
  * @param result - Result to return from the next call
1312
1289
  */
1313
1290
  enqueueResult(result) {
1314
- triggerJobFunction.mockImplementationOnce(() => result);
1291
+ startJobFunction.mockImplementationOnce(() => result);
1315
1292
  },
1316
1293
  /**
1317
- * Enqueue results for multiple subsequent `triggerJobFunction` calls (FIFO).
1294
+ * Enqueue results for multiple subsequent `startJobFunction` calls (FIFO).
1318
1295
  * @param results - Results to enqueue, one per upcoming call
1319
1296
  */
1320
1297
  enqueueResults(...results) {
1321
- for (const result of results) triggerJobFunction.mockImplementationOnce(() => result);
1298
+ for (const result of results) startJobFunction.mockImplementationOnce(() => result);
1322
1299
  },
1323
1300
  /**
1324
- * All jobs triggered via `triggerJobFunction`, in order.
1325
- * @returns Triggered jobs array
1301
+ * All jobs started via `startJobFunction`, in order.
1302
+ * @returns Started jobs array
1326
1303
  */
1327
- get triggeredJobs() {
1328
- return triggerJobFunction.mock.calls.map(([jobName, args, options]) => ({
1304
+ get startedJobs() {
1305
+ return startJobFunction.mock.calls.map(([jobName, args, options]) => ({
1329
1306
  jobName,
1330
1307
  args,
1331
1308
  ...options !== void 0 && { options }
1332
1309
  }));
1333
1310
  },
1334
1311
  /**
1335
- * Configure what `triggerWorkflow` returns. Pass a string (same id every
1312
+ * Configure what `startWorkflow` returns. Pass a string (same id every
1336
1313
  * call) or `(name, args, options) => string`. Default: a placeholder UUID.
1337
1314
  * @param handler - Static execution ID or a function returning one
1338
1315
  */
1339
- setTriggerHandler(handler) {
1340
- triggerWorkflow.mockImplementation(typeof handler === "function" ? async (name, args, options) => handler(name, args, options) : async () => handler);
1316
+ setStartHandler(handler) {
1317
+ startWorkflow.mockImplementation(typeof handler === "function" ? async (name, args, options) => handler(name, args, options) : async () => handler);
1341
1318
  },
1342
1319
  /**
1343
- * Configure what `resumeWorkflow` returns. Pass a string (same id every
1344
- * call) or `(executionId) => string`. Default: echoes the input executionId.
1320
+ * Configure what `resumeWorkflowExecution` returns. Pass a string (same id
1321
+ * every call) or `(executionId) => string`. Default: echoes the input executionId.
1345
1322
  * @param handler - Static execution ID or a function returning one
1346
1323
  */
1347
1324
  setResumeHandler(handler) {
1348
- resumeWorkflow.mockImplementation(typeof handler === "function" ? async (executionId) => handler(executionId) : async () => handler);
1325
+ resumeWorkflowExecution.mockImplementation(typeof handler === "function" ? async (executionId) => handler(executionId) : async () => handler);
1349
1326
  },
1350
1327
  /**
1351
1328
  * Configure what `wait` returns. Pass `(key, payload) => unknown` or any
@@ -1356,7 +1333,7 @@ function mockWorkflow() {
1356
1333
  wait.mockImplementation(typeof handler === "function" ? (key, payload) => handler(key, payload) : () => handler);
1357
1334
  }),
1358
1335
  /**
1359
- * Set the `env` passed to job bodies invoked via `createWorkflowJob().trigger()`.
1336
+ * Set the `env` passed to job bodies invoked via `createWorkflowJob().start()`.
1360
1337
  * Cleared on dispose / reset.
1361
1338
  * @param env - Env passed to job bodies.
1362
1339
  */
@@ -1395,21 +1372,21 @@ function mockWorkflow() {
1395
1372
  },
1396
1373
  /** Clear recorded calls while preserving configured responses. */
1397
1374
  clear() {
1398
- triggerJobFunction.mockClear();
1399
- triggerWorkflow.mockClear();
1400
- resumeWorkflow.mockClear();
1375
+ startJobFunction.mockClear();
1376
+ startWorkflow.mockClear();
1377
+ resumeWorkflowExecution.mockClear();
1401
1378
  wait.mockClear();
1402
1379
  resolve.mockClear();
1403
1380
  for (const mock of scopedMocks) mock.mockClear();
1404
1381
  },
1405
1382
  /** Reset all workflow responses and recorded calls (keeps the mock installed). */
1406
1383
  reset() {
1407
- triggerJobFunction.mockReset();
1408
- triggerJobFunction.mockImplementation(defaultTriggerJob);
1409
- triggerWorkflow.mockReset();
1410
- triggerWorkflow.mockImplementation(defaultTriggerWorkflow);
1411
- resumeWorkflow.mockReset();
1412
- resumeWorkflow.mockImplementation(defaultResumeWorkflow);
1384
+ startJobFunction.mockReset();
1385
+ startJobFunction.mockImplementation(defaultStartJob);
1386
+ startWorkflow.mockReset();
1387
+ startWorkflow.mockImplementation(defaultStartWorkflow);
1388
+ resumeWorkflowExecution.mockReset();
1389
+ resumeWorkflowExecution.mockImplementation(defaultResumeWorkflowExecution);
1413
1390
  wait.mockReset();
1414
1391
  wait.mockImplementation(() => null);
1415
1392
  resolve.mockReset();
@@ -1427,7 +1404,7 @@ function mockWorkflow() {
1427
1404
 
1428
1405
  //#endregion
1429
1406
  //#region src/vitest/workflow-local.ts
1430
- var PendingTrigger = class {
1407
+ var PendingStart = class {
1431
1408
  jobName;
1432
1409
  args;
1433
1410
  constructor(jobName, args) {
@@ -1444,7 +1421,7 @@ async function runWorkflowLocally(workflow, args, options) {
1444
1421
  if (options?.env !== void 0) writeWorkflowTestEnv({ ...options.env });
1445
1422
  root.tailor = {
1446
1423
  ...previousTailor,
1447
- workflow: createLocalWorkflowRuntime(previousTailor?.workflow, runner.triggerJobFunction)
1424
+ workflow: createLocalWorkflowRuntime(previousTailor?.workflow, runner.startJobFunction)
1448
1425
  };
1449
1426
  try {
1450
1427
  return await runner.runJob(workflow.mainJob.name, args);
@@ -1457,19 +1434,19 @@ async function runWorkflowLocally(workflow, args, options) {
1457
1434
  }
1458
1435
  function createLocalJobRunner() {
1459
1436
  let activeExecution;
1460
- const triggerJobFunction = (jobName, args) => {
1461
- if (!activeExecution) throw new Error(`Cannot trigger workflow job "${jobName}" outside runWorkflowLocally() job execution.`);
1437
+ const startJobFunction = (jobName, args) => {
1438
+ if (!activeExecution) throw new Error(`Cannot start workflow job "${jobName}" outside runWorkflowLocally() job execution.`);
1462
1439
  if (activeExecution.pending) throw activeExecution.pending;
1463
1440
  const serializedArgs = platformSerialize(args);
1464
1441
  const index = activeExecution.cursor;
1465
1442
  activeExecution.cursor += 1;
1466
1443
  const cached = activeExecution.records[index];
1467
1444
  if (cached) {
1468
- assertSameTrigger(cached, jobName, serializedArgs);
1445
+ assertSameStart(cached, jobName, serializedArgs);
1469
1446
  if (cached.status === "rejected") throw cached.error;
1470
1447
  return platformSerialize(cached.result);
1471
1448
  }
1472
- const pending = new PendingTrigger(jobName, serializedArgs);
1449
+ const pending = new PendingStart(jobName, serializedArgs);
1473
1450
  activeExecution.pending = pending;
1474
1451
  throw pending;
1475
1452
  };
@@ -1487,15 +1464,15 @@ function createLocalJobRunner() {
1487
1464
  try {
1488
1465
  const out = await body(platformSerialize(args), buildJobContext());
1489
1466
  if (execution.pending) {
1490
- await settlePendingTrigger(records, execution.pending, runJob);
1467
+ await settlePendingStart(records, execution.pending, runJob);
1491
1468
  continue;
1492
1469
  }
1493
- if (execution.cursor !== records.length) throw new Error(`Workflow job trigger sequence changed while replaying "${name}". Expected ${records.length} trigger(s), but replay reached ${execution.cursor}.`);
1470
+ if (execution.cursor !== records.length) throw new Error(`Workflow job start sequence changed while replaying "${name}". Expected ${records.length} start(s), but replay reached ${execution.cursor}.`);
1494
1471
  return platformSerialize(out);
1495
1472
  } catch (cause) {
1496
- const pending = cause instanceof PendingTrigger ? cause : execution.pending;
1473
+ const pending = cause instanceof PendingStart ? cause : execution.pending;
1497
1474
  if (pending) {
1498
- await settlePendingTrigger(records, pending, runJob);
1475
+ await settlePendingStart(records, pending, runJob);
1499
1476
  continue;
1500
1477
  }
1501
1478
  throw cause;
@@ -1506,10 +1483,10 @@ function createLocalJobRunner() {
1506
1483
  };
1507
1484
  return {
1508
1485
  runJob,
1509
- triggerJobFunction
1486
+ startJobFunction
1510
1487
  };
1511
1488
  }
1512
- async function settlePendingTrigger(records, pending, runJob) {
1489
+ async function settlePendingStart(records, pending, runJob) {
1513
1490
  try {
1514
1491
  records.push({
1515
1492
  jobName: pending.jobName,
@@ -1526,33 +1503,24 @@ async function settlePendingTrigger(records, pending, runJob) {
1526
1503
  });
1527
1504
  }
1528
1505
  }
1529
- function assertSameTrigger(record, jobName, args) {
1506
+ function assertSameStart(record, jobName, args) {
1530
1507
  if (record.jobName === jobName && JSON.stringify(record.args) === JSON.stringify(args)) return;
1531
- throw new Error(`Workflow job trigger sequence changed while replaying. Expected ${record.jobName}(${JSON.stringify(record.args)}), but got ${jobName}(${JSON.stringify(args)}).`);
1508
+ throw new Error(`Workflow job start sequence changed while replaying. Expected ${record.jobName}(${JSON.stringify(record.args)}), but got ${jobName}(${JSON.stringify(args)}).`);
1532
1509
  }
1533
- function createLocalWorkflowRuntime(previous, triggerJobFunction) {
1510
+ function createLocalWorkflowRuntime(previous, startJobFunction) {
1534
1511
  const startWorkflow = async (name, args, options) => {
1535
1512
  if (previous) return await previous.startWorkflow(name, args, options);
1536
1513
  platformSerialize(args);
1537
- return TRIGGER_DEFAULT;
1514
+ return START_DEFAULT;
1538
1515
  };
1539
1516
  const resumeWorkflowExecution = async (executionId) => {
1540
1517
  if (previous) return await previous.resumeWorkflowExecution(executionId);
1541
1518
  return executionId;
1542
1519
  };
1543
1520
  return {
1544
- triggerJobFunction,
1545
- startJobFunction: triggerJobFunction,
1521
+ startJobFunction,
1546
1522
  startWorkflow,
1547
- triggerWorkflow: async (name, args, options) => {
1548
- if (previous) return await previous.triggerWorkflow(name, args, options);
1549
- return await startWorkflow(name, args);
1550
- },
1551
1523
  resumeWorkflowExecution,
1552
- resumeWorkflow: async (executionId) => {
1553
- if (previous) return await previous.resumeWorkflow(executionId);
1554
- return await resumeWorkflowExecution(executionId);
1555
- },
1556
1524
  wait: (key, payload) => {
1557
1525
  if (previous) return previous.wait(key, payload);
1558
1526
  throw new Error(`No wait handler for "${key}". Acquire mockWorkflow() and call setWaitHandler(...).`);