@tailor-platform/sdk 2.0.0-next.5 → 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 (129) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/dist/{application-Bf8wxOi6.mjs → application-GzW98_Xr.mjs} +377 -1418
  3. package/dist/application-GzW98_Xr.mjs.map +1 -0
  4. package/dist/application-OM0taSPn.mjs +3 -0
  5. package/dist/cli/commands/deploy/deploy.d.mts +8 -3
  6. package/dist/cli/commands/generate/options.d.mts +0 -1
  7. package/dist/cli/commands/generate/service.d.mts +1 -1
  8. package/dist/cli/commands/staticwebsite/deploy.d.mts +19 -0
  9. package/dist/cli/commands/workspace/create.d.mts +3 -0
  10. package/dist/cli/commands/workspace/list.d.mts +1 -0
  11. package/dist/cli/commands/workspace/transform.d.mts +2 -0
  12. package/dist/cli/index.mjs +781 -1553
  13. package/dist/cli/index.mjs.map +1 -1
  14. package/dist/cli/lib.d.mts +7 -3
  15. package/dist/cli/lib.mjs +49 -3
  16. package/dist/cli/lib.mjs.map +1 -1
  17. package/dist/cli/shared/config-loader.d.mts +1 -1
  18. package/dist/cli/shared/readonly-guard.d.mts +25 -0
  19. package/dist/cli/shared/tailordb-namespaces.d.mts +37 -0
  20. package/dist/cli/shared/workspace-name.d.mts +1 -0
  21. package/dist/completion/zsh-worker.zsh +15 -303
  22. package/dist/configure/config/types.d.mts +5 -1
  23. package/dist/configure/index.mjs +20 -19
  24. package/dist/configure/index.mjs.map +1 -1
  25. package/dist/configure/services/auth/types.d.mts +18 -23
  26. package/dist/configure/services/executor/executor.d.mts +2 -13
  27. package/dist/configure/services/executor/operation.d.mts +8 -3
  28. package/dist/configure/services/tailordb/schema.d.mts +1 -7
  29. package/dist/configure/services/tailordb/types.d.mts +1 -1
  30. package/dist/configure/services/workflow/execution-policy.d.mts +2 -2
  31. package/dist/configure/services/workflow/job.d.mts +10 -10
  32. package/dist/configure/services/workflow/workflow.d.mts +6 -4
  33. package/dist/configure/types/type.d.mts +1 -9
  34. package/dist/{crashreport-D3RjuSYb.mjs → crashreport-0ioNRZ4K.mjs} +1 -1
  35. package/dist/{crashreport-Cg-pqRJV.mjs → crashreport-CxHne11E.mjs} +4 -3
  36. package/dist/{crashreport-Cg-pqRJV.mjs.map → crashreport-CxHne11E.mjs.map} +1 -1
  37. package/dist/errors-DfnF4ibq.mjs +100 -0
  38. package/dist/errors-DfnF4ibq.mjs.map +1 -0
  39. package/dist/{globals-BjhJJ2dN.mjs → globals-CBZ0egXT.mjs} +13 -10
  40. package/dist/globals-CBZ0egXT.mjs.map +1 -0
  41. package/dist/{logger-BEiZZ3qT.mjs → logger-BwS4ppwO.mjs} +3 -3
  42. package/dist/logger-BwS4ppwO.mjs.map +1 -0
  43. package/dist/parser/service/tailordb/type-source.d.mts +10 -0
  44. package/dist/{register-ts-hook-BhzVkej0.mjs → register-ts-hook-DvEs6YsL.mjs} +2571 -1636
  45. package/dist/register-ts-hook-DvEs6YsL.mjs.map +1 -0
  46. package/dist/{registry-BSbq6SPo.mjs → registry-i7EdJ-D5.mjs} +10 -10
  47. package/dist/registry-i7EdJ-D5.mjs.map +1 -0
  48. package/dist/runtime/field-parse.d.mts +10 -0
  49. package/dist/runtime/globals.d.mts +3 -3
  50. package/dist/runtime/index.mjs +1 -1
  51. package/dist/runtime/workflow.d.mts +18 -33
  52. package/dist/runtime/workflow.mjs +1 -1
  53. package/dist/{schema-iCd1ugGp.mjs → schema--xYWRGfe.mjs} +42 -24
  54. package/dist/schema--xYWRGfe.mjs.map +1 -0
  55. package/dist/{secret-file-aoNXJmKa.mjs → secret-file-C3J4Gy8r.mjs} +2 -27
  56. package/dist/secret-file-C3J4Gy8r.mjs.map +1 -0
  57. package/dist/{secretmanager-Bd45j7an.mjs → secretmanager-IY4UvinW.mjs} +42 -9
  58. package/dist/secretmanager-IY4UvinW.mjs.map +1 -0
  59. package/dist/service-BJAQ70e5.mjs +3 -0
  60. package/dist/{service-DeZeYa06.mjs → service-DaeJlBoH.mjs} +3 -3
  61. package/dist/{service-DeZeYa06.mjs.map → service-DaeJlBoH.mjs.map} +1 -1
  62. package/dist/{service-CzZEVrp9.mjs → service-Dmxa2I4i.mjs} +64 -28
  63. package/dist/service-Dmxa2I4i.mjs.map +1 -0
  64. package/dist/service_pb-BoLM0X4K.mjs +167 -0
  65. package/dist/service_pb-BoLM0X4K.mjs.map +1 -0
  66. package/dist/{service_pb-DZkfjB_6.mjs → service_pb-r1T7kpJc.mjs} +1 -1
  67. package/dist/types/executor.generated.d.mts +60 -42
  68. package/dist/user-agent-Bgsszb5I.mjs +28 -0
  69. package/dist/user-agent-Bgsszb5I.mjs.map +1 -0
  70. package/dist/utils/test/index.mjs +11 -11
  71. package/dist/utils/test/index.mjs.map +1 -1
  72. package/dist/utils/test/mock.d.mts +6 -6
  73. package/dist/vitest/environment.mjs +1 -1
  74. package/dist/vitest/index.d.mts +8 -8
  75. package/dist/vitest/index.mjs +613 -227
  76. package/dist/vitest/index.mjs.map +1 -1
  77. package/dist/vitest/mock.d.mts +8 -8
  78. package/dist/vitest/mocks/aigateway.d.mts +14 -4
  79. package/dist/vitest/mocks/authconnection.d.mts +14 -4
  80. package/dist/vitest/mocks/file.d.mts +23 -6
  81. package/dist/vitest/mocks/iconv.d.mts +28 -4
  82. package/dist/vitest/mocks/idp.d.mts +25 -9
  83. package/dist/vitest/mocks/secretmanager.d.mts +13 -4
  84. package/dist/vitest/mocks/tailordb.d.mts +48 -7
  85. package/dist/vitest/mocks/workflow.d.mts +59 -33
  86. package/dist/vitest/setup.mjs +2 -2
  87. package/dist/vitest/workflow-local.d.mts +2 -2
  88. package/dist/workflow-CsBvRE3g.mjs +34 -0
  89. package/dist/workflow-CsBvRE3g.mjs.map +1 -0
  90. package/dist/{service_pb-Bk7dL-yT.mjs → workspace_resource_pb-Db3fv68L.mjs} +47 -165
  91. package/dist/workspace_resource_pb-Db3fv68L.mjs.map +1 -0
  92. package/docs/cli/application.md +63 -15
  93. package/docs/cli/function.md +2 -2
  94. package/docs/cli/tailordb.md +8 -140
  95. package/docs/cli/workspace.md +6 -4
  96. package/docs/cli-reference.md +11 -8
  97. package/docs/configuration.md +2 -0
  98. package/docs/github-actions.md +8 -0
  99. package/docs/migration/v2.md +169 -11
  100. package/docs/runtime.md +5 -6
  101. package/docs/services/auth.md +7 -7
  102. package/docs/services/executor.md +5 -0
  103. package/docs/services/tailordb.md +44 -0
  104. package/docs/services/workflow.md +43 -43
  105. package/docs/testing.md +112 -96
  106. package/package.json +2 -5
  107. package/dist/application-Bf8wxOi6.mjs.map +0 -1
  108. package/dist/application-CUkjzfij.mjs +0 -3
  109. package/dist/cli/erd-viewer-assets/app.js +0 -1424
  110. package/dist/cli/erd-viewer-assets/index.html +0 -77
  111. package/dist/cli/erd-viewer-assets/serve.json +0 -13
  112. package/dist/cli/erd-viewer-assets/styles.css +0 -1036
  113. package/dist/configure/types/field-runtime.d.mts +0 -16
  114. package/dist/errors-118wUDRr.mjs +0 -42
  115. package/dist/errors-118wUDRr.mjs.map +0 -1
  116. package/dist/globals-BjhJJ2dN.mjs.map +0 -1
  117. package/dist/logger-BEiZZ3qT.mjs.map +0 -1
  118. package/dist/register-ts-hook-BhzVkej0.mjs.map +0 -1
  119. package/dist/registry-BSbq6SPo.mjs.map +0 -1
  120. package/dist/resource_pb-BRv7AMXK.mjs +0 -49
  121. package/dist/resource_pb-BRv7AMXK.mjs.map +0 -1
  122. package/dist/schema-iCd1ugGp.mjs.map +0 -1
  123. package/dist/secret-file-aoNXJmKa.mjs.map +0 -1
  124. package/dist/secretmanager-Bd45j7an.mjs.map +0 -1
  125. package/dist/service-BT0GPd01.mjs +0 -3
  126. package/dist/service-CzZEVrp9.mjs.map +0 -1
  127. package/dist/service_pb-Bk7dL-yT.mjs.map +0 -1
  128. package/dist/workflow-GNuSnsTx.mjs +0 -22
  129. package/dist/workflow-GNuSnsTx.mjs.map +0 -1
@@ -3,26 +3,36 @@ import { AuthConnectionTokenResult, ConnectionName } from "@tailor-platform/sdk"
3
3
  interface AuthConnectionCall {
4
4
  connectionName: ConnectionName;
5
5
  }
6
+ /** Initial fixtures and fallback behavior for an AuthConnection mock. */
7
+ interface MockAuthconnectionOptions {
8
+ /** Tokens available when the mock is acquired. */
9
+ tokens?: Partial<Record<ConnectionName, AuthConnectionTokenResult>>;
10
+ /** Return a placeholder token or throw when a connection has no configured token. */
11
+ onUnhandled?: "fallback" | "error";
12
+ }
6
13
  /**
7
14
  * Acquire a disposable mock for `tailor.authconnection`. Restored on dispose.
15
+ * @param options - Initial token fixtures and fallback behavior
8
16
  * @returns Disposable AuthConnection mock control object
9
17
  * @example
10
18
  * ```typescript
11
19
  * import { mockAuthconnection } from "@tailor-platform/sdk/vitest";
12
20
  *
13
21
  * test("returns configured token", async () => {
14
- * using ac = mockAuthconnection();
15
- * ac.setTokens({ google: { access_token: "ya29.xxx" } });
22
+ * using ac = mockAuthconnection({ tokens: { google: { access_token: "ya29.xxx" } } });
23
+ * ac.setToken("google", { access_token: "replacement" });
16
24
  * // …
17
25
  * });
18
26
  * ```
19
27
  */
20
- declare function mockAuthconnection(): {
28
+ declare function mockAuthconnection(options?: MockAuthconnectionOptions): {
21
29
  /** The `getConnectionToken` `vi.fn`. */
22
30
  getConnectionToken: import("vitest").Mock<(connectionName: ConnectionName) => Promise<AuthConnectionTokenResult>>;
23
31
  setTokens(value: Partial<Record<ConnectionName, AuthConnectionTokenResult>>): void;
32
+ setToken(connectionName: ConnectionName, token: AuthConnectionTokenResult): void;
24
33
  readonly calls: AuthConnectionCall[];
34
+ clear(): void;
25
35
  reset(): void;
26
36
  } & Disposable;
27
37
  //#endregion
28
- export { mockAuthconnection };
38
+ export { MockAuthconnectionOptions, mockAuthconnection };
@@ -1,3 +1,5 @@
1
+ import { FileDownloadAsBase64Response, FileDownloadResponse, FileDownloadStreamResponse, FileMetadata, FileUploadOptions, FileUploadResponse, FileUploadStreamOptions } from "../../runtime/file.mjs";
2
+ import { Mock } from "vitest";
1
3
  //#region src/vitest/mocks/file.d.ts
2
4
  type FileResolver = (method: string, call: FileCall) => unknown;
3
5
  interface FileCall {
@@ -7,8 +9,14 @@ interface FileCall {
7
9
  fieldName: string;
8
10
  recordId: string;
9
11
  }
12
+ /** Controls fallback behavior for File calls without a configured result. */
13
+ interface MockFileOptions {
14
+ /** Return a type-compatible fixture or throw when no behavior is configured. */
15
+ onUnhandled?: "fallback" | "error";
16
+ }
10
17
  /**
11
18
  * Acquire a disposable mock for `tailordb.file`. Restored on dispose.
19
+ * @param options - Controls behavior for calls without a configured result
12
20
  * @returns Disposable File mock control object
13
21
  * @example
14
22
  * ```typescript
@@ -16,26 +24,35 @@ interface FileCall {
16
24
  *
17
25
  * test("mock file download", async () => {
18
26
  * using file = mockFile();
19
- * file.enqueueResult({ data: new Uint8Array([1, 2, 3]), metadata: { ... } });
27
+ * file.download.mockResolvedValue({ data: new Uint8Array(), metadata: { ... } });
20
28
  * // …
21
29
  * });
22
30
  * ```
23
31
  */
24
- declare function mockFile(): {
32
+ declare function mockFile(options?: MockFileOptions): {
25
33
  setResolver(value: FileResolver): void;
26
34
  /**
27
- * Enqueue a single result for the next `tailordb.file` call (FIFO; falls
28
- * back to `setResolver` when exhausted).
35
+ * Enqueue a single result for the next `tailordb.file` call.
36
+ * The queue is shared across all methods and namespaces.
29
37
  * @param result - Result to return from the next file call
30
38
  */
31
39
  enqueueResult(result: unknown): void;
32
40
  /**
33
41
  * Enqueue results for multiple subsequent `tailordb.file` calls.
42
+ * The queue is shared across all methods and namespaces.
34
43
  * @param results - Results to enqueue, one per upcoming call
35
44
  */
36
45
  enqueueResults(...results: unknown[]): void;
37
- readonly calls: FileCall[];
46
+ calls: FileCall[];
47
+ clear(): void;
38
48
  reset(): void;
49
+ delete: Mock<(namespace: string, typeName: string, fieldName: string, recordId: string) => Promise<void>>;
50
+ upload: Mock<(namespace: string, typeName: string, fieldName: string, recordId: string, data: string | ArrayBuffer | Uint8Array | number[], options?: FileUploadOptions) => Promise<FileUploadResponse>>;
51
+ download: Mock<(namespace: string, typeName: string, fieldName: string, recordId: string) => Promise<FileDownloadResponse>>;
52
+ downloadAsBase64: Mock<(namespace: string, typeName: string, fieldName: string, recordId: string) => Promise<FileDownloadAsBase64Response>>;
53
+ getMetadata: Mock<(namespace: string, typeName: string, fieldName: string, recordId: string) => Promise<FileMetadata>>;
54
+ downloadStream: Mock<(namespace: string, typeName: string, fieldName: string, recordId: string) => Promise<FileDownloadStreamResponse>>;
55
+ uploadStream: Mock<(namespace: string, typeName: string, fieldName: string, recordId: string, readableStream: ReadableStream<Uint8Array | ArrayBuffer>, options?: FileUploadStreamOptions) => Promise<FileUploadResponse>>;
39
56
  } & Disposable;
40
57
  //#endregion
41
- export { mockFile };
58
+ export { MockFileOptions, mockFile };
@@ -1,11 +1,24 @@
1
+ import { MockInstance } from "vitest";
1
2
  //#region src/vitest/mocks/iconv.d.ts
2
3
  type IconvResolver = (method: string, args: unknown[]) => unknown;
4
+ type IconvMethod = "convert" | "convertBuffer" | "decode" | "encode" | "encodings";
3
5
  interface IconvCall {
4
- method: string;
6
+ method: IconvMethod;
5
7
  args: unknown[];
6
8
  }
9
+ type ConversionResult = string | Uint8Array;
10
+ type ConvertMockProcedure = (input: string | Uint8Array | ArrayBuffer, fromEncoding: string, toEncoding: string) => ConversionResult;
11
+ type ConvertBufferMockProcedure = (input: Uint8Array | ArrayBuffer, fromEncoding: string, toEncoding: string) => ConversionResult;
12
+ type EncodeMockProcedure = (input: string, encoding: string) => ConversionResult;
13
+ type TypedOperationMock<RuntimeProcedure, MockProcedure extends (...args: never[]) => unknown> = RuntimeProcedure & MockInstance<MockProcedure>;
14
+ /** Controls how unconfigured Iconv operations are handled. */
15
+ interface MockIconvOptions {
16
+ /** Return an empty type-compatible value or throw when no behavior is configured. */
17
+ onUnhandled?: "fallback" | "error";
18
+ }
7
19
  /**
8
20
  * Acquire a disposable mock for `tailor.iconv`. Restored on dispose.
21
+ * @param options - Fallback behavior for unconfigured operations
9
22
  * @returns Disposable Iconv mock control object
10
23
  * @example
11
24
  * ```typescript
@@ -13,15 +26,26 @@ interface IconvCall {
13
26
  *
14
27
  * test("mock encoding conversion", () => {
15
28
  * using iconv = mockIconv();
16
- * iconv.setResolver((method) => (method === "decode" ? "decoded-text" : null));
29
+ * iconv.decode.mockReturnValue("decoded-text");
17
30
  * // …
18
31
  * });
19
32
  * ```
20
33
  */
21
- declare function mockIconv(): {
34
+ declare function mockIconv(options?: MockIconvOptions): {
35
+ /** The `convert` `vi.fn`. */
36
+ convert: TypedOperationMock<(<T extends string>(str: string | Uint8Array | ArrayBuffer, fromEncoding: string, toEncoding: T) => T extends "UTF8" | "UTF-8" ? string : Uint8Array), ConvertMockProcedure>;
37
+ /** The `convertBuffer` `vi.fn`. */
38
+ convertBuffer: TypedOperationMock<(<T extends string>(buffer: Uint8Array | ArrayBuffer, fromEncoding: string, toEncoding: T) => T extends "UTF8" | "UTF-8" ? string : Uint8Array), ConvertBufferMockProcedure>;
39
+ /** The `decode` `vi.fn`. */
40
+ decode: import("vitest").Mock<(input: Uint8Array | ArrayBuffer, encoding: string) => string>;
41
+ /** The `encode` `vi.fn`. */
42
+ encode: TypedOperationMock<(<T extends string>(str: string, encoding: T) => T extends "UTF8" | "UTF-8" ? string : Uint8Array), EncodeMockProcedure>;
43
+ /** The `encodings` `vi.fn`. */
44
+ encodings: import("vitest").Mock<() => string[]>;
22
45
  setResolver(value: IconvResolver): void;
23
46
  readonly calls: IconvCall[];
47
+ clear: () => void;
24
48
  reset(): void;
25
49
  } & Disposable;
26
50
  //#endregion
27
- export { mockIconv };
51
+ export { MockIconvOptions, mockIconv };
@@ -1,44 +1,60 @@
1
+ import { IdpClientConstructor, IdpClientInstance } from "../../runtime/idp.mjs";
1
2
  import { Mock } from "vitest";
2
3
  //#region src/vitest/mocks/idp.d.ts
4
+ type IdpMethod = keyof IdpClientInstance;
3
5
  type IdpResolver = (method: string, args: unknown[], namespace: string) => unknown;
4
6
  interface IdpCall {
5
7
  method: string;
6
8
  args: unknown[];
7
9
  namespace: string;
8
10
  }
11
+ /** Controls fallback behavior for IdP calls without a configured result. */
12
+ interface MockIdpOptions {
13
+ /** Return a type-compatible fixture or throw when no behavior is configured. */
14
+ onUnhandled?: "fallback" | "error";
15
+ }
16
+ type IdpNamespaceMocks = { [Method in IdpMethod]: Mock<IdpClientInstance[Method]>; };
9
17
  /**
10
18
  * Acquire a disposable mock for `tailor.idp`. Restored on dispose.
19
+ * @param options - Controls behavior for calls without a configured result
11
20
  * @returns Disposable IDP mock control object
12
21
  * @example
13
22
  * ```typescript
14
23
  * import { mockIdp } from "@tailor-platform/sdk/vitest";
15
24
  *
16
- * test("resolver-based", async () => {
25
+ * test("returns a user", async () => {
17
26
  * using idp = mockIdp();
18
- * idp.setResolver((method) =>
19
- * method === "user" ? { id: "u-1", name: "alice", disabled: false } : null,
20
- * );
27
+ * idp.namespace("my-idp").user.mockResolvedValue({
28
+ * id: "u-1",
29
+ * name: "alice",
30
+ * disabled: false,
31
+ * mfaEnrolled: false,
32
+ * mfaFactorIds: [],
33
+ * });
21
34
  * // …
22
35
  * });
23
36
  * ```
24
37
  */
25
- declare function mockIdp(): {
38
+ declare function mockIdp(options?: MockIdpOptions): {
26
39
  /** The mock IDP `Client` constructor (`vi.fn`). */
27
- Client: Mock;
40
+ Client: Mock<IdpClientConstructor>;
41
+ namespace: (name: string) => IdpNamespaceMocks;
28
42
  setResolver(value: IdpResolver): void;
29
43
  /**
30
- * Enqueue a single result for the next IDP call (FIFO; falls back to
31
- * `setResolver` when exhausted).
44
+ * Enqueue a single result for the next IDP call.
45
+ * The queue is shared across all methods and namespaces.
32
46
  * @param result - Result to return from the next IDP call
33
47
  */
34
48
  enqueueResult(result: unknown): void;
35
49
  /**
36
50
  * Enqueue results for multiple subsequent IDP calls.
51
+ * The queue is shared across all methods and namespaces.
37
52
  * @param results - Results to enqueue, one per upcoming call
38
53
  */
39
54
  enqueueResults(...results: unknown[]): void;
40
55
  readonly calls: IdpCall[];
56
+ clear(): void;
41
57
  reset(): void;
42
58
  } & Disposable;
43
59
  //#endregion
44
- export { mockIdp };
60
+ export { MockIdpOptions, mockIdp };
@@ -5,31 +5,40 @@ interface SecretCall {
5
5
  name?: string;
6
6
  names?: readonly string[];
7
7
  }
8
+ /** Initial fixtures for a Secret Manager mock. */
9
+ interface MockSecretmanagerOptions {
10
+ /** Secrets to merge over fixtures inherited from the currently installed mock. */
11
+ secrets?: Record<string, Record<string, string>>;
12
+ }
8
13
  /**
9
14
  * Acquire a disposable mock for `tailor.secretmanager`. The secret store is
10
15
  * inherited (cloned) from the currently-installed mock on acquisition and
11
16
  * restored on dispose, so secrets seeded outside the test survive across
12
17
  * `using` scopes while per-test `setSecrets()` overrides stay isolated.
18
+ * @param options - Initial Secret Manager fixtures
13
19
  * @returns Disposable SecretManager mock control object
14
20
  * @example
15
21
  * ```typescript
16
22
  * import { mockSecretmanager } from "@tailor-platform/sdk/vitest";
17
23
  *
18
24
  * test("reads secrets from vault", async () => {
19
- * using sm = mockSecretmanager();
20
- * sm.setSecrets({ "my-vault": { API_KEY: "sk-123" } });
25
+ * using sm = mockSecretmanager({ secrets: { "my-vault": { API_KEY: "sk-123" } } });
26
+ * sm.setSecret("my-vault", "API_KEY", "replacement");
21
27
  * // …
22
28
  * });
23
29
  * ```
24
30
  */
25
- declare function mockSecretmanager(): {
31
+ declare function mockSecretmanager(options?: MockSecretmanagerOptions): {
26
32
  /** The `getSecret` `vi.fn`. */
27
33
  getSecret: import("vitest").Mock<(vault: string, name: string) => Promise<string | undefined>>;
28
34
  /** The `getSecrets` `vi.fn`. */
29
35
  getSecrets: import("vitest").Mock<(<const T extends readonly string[]>(vault: string, names: T) => Promise<Partial<Record<T[number], string>>>)>;
30
36
  setSecrets(secrets: Record<string, Record<string, string>>): void;
37
+ setSecret(vault: string, name: string, value: string): void;
38
+ mergeSecrets(vault: string, secrets: Record<string, string>): void;
31
39
  readonly calls: SecretCall[];
40
+ clear(): void;
32
41
  reset(): void;
33
42
  } & Disposable;
34
43
  //#endregion
35
- export { mockSecretmanager };
44
+ export { MockSecretmanagerOptions, mockSecretmanager };
@@ -1,5 +1,30 @@
1
1
  //#region src/vitest/mocks/tailordb.d.ts
2
- type QueryResolver = (query: string, params: unknown[]) => unknown[];
2
+ type QueryResolver = (query: string, params: unknown[]) => unknown[] | undefined;
3
+ /** Controls how unmatched TailorDB queries are handled. */
4
+ interface MockTailordbOptions {
5
+ /** Return an empty result or throw when no configured query behavior matches. */
6
+ onUnhandled?: "fallback" | "error";
7
+ }
8
+ /** Matches a TailorDB query by SQL text and optionally by parameters. */
9
+ interface QueryMatch {
10
+ /** Exact SQL text or regular expression to match. */
11
+ sql: string | RegExp;
12
+ /** Exact parameters or a predicate for parameter matching. */
13
+ params?: readonly unknown[] | ((params: unknown[]) => boolean);
14
+ }
15
+ /** Selects TailorDB queries that receive a configured response. */
16
+ type QueryMatcher = string | RegExp | QueryMatch | ((query: string, params: unknown[]) => boolean);
17
+ /** Configures persistent and one-time responses for matched queries. */
18
+ interface QueryBehavior<Row> {
19
+ /** Return these rows for every matching query after one-time responses are consumed. */
20
+ returnsRows(rows: Row[]): QueryBehavior<Row>;
21
+ /** Return these rows for the next matching query. */
22
+ returnsRowsOnce(rows: Row[]): QueryBehavior<Row>;
23
+ /** Reject every matching query after one-time responses are consumed. */
24
+ rejects(error: unknown): QueryBehavior<Row>;
25
+ /** Reject the next matching query. */
26
+ rejectsOnce(error: unknown): QueryBehavior<Row>;
27
+ }
3
28
  interface ExecutedQuery {
4
29
  query: string;
5
30
  params: unknown[];
@@ -19,32 +44,41 @@ declare class MockQueryResult {
19
44
  * `tailordb.Client` whose `queryObject` is a shared `vi.fn()` (so query
20
45
  * responses can be staged before the client is constructed). Restored on
21
46
  * dispose.
47
+ * @param options - Query fallback behavior
22
48
  * @returns Disposable TailorDB mock control object
23
49
  * @example
24
50
  * ```typescript
25
51
  * import { mockTailordb } from "@tailor-platform/sdk/vitest";
26
52
  *
27
- * test("order-based", async () => {
53
+ * test("query-based", async () => {
28
54
  * using db = mockTailordb();
29
- * db.enqueueResults([], [{ age: 30 }], []); // BEGIN / SELECT / COMMIT
55
+ * db.onQuery({ sql: /FROM users/, params: ["u-1"] }).returnsRows([{ age: 30 }]);
30
56
  * // …
31
- * expect(db.queryObject).toHaveBeenCalledTimes(3);
57
+ * expect(db.queryObject).toHaveBeenCalled();
32
58
  * expect(db.Client).toHaveBeenCalledWith({ namespace: "tailordb" });
33
59
  * });
34
60
  * ```
35
61
  */
36
- declare function mockTailordb(): {
62
+ declare function mockTailordb(options?: MockTailordbOptions): {
37
63
  /** The mock `tailordb.Client` constructor (`vi.fn`). */
38
64
  Client: import("vitest").Mock<(this: any, config?: {
39
65
  namespace?: string;
40
66
  }) => void>;
41
67
  /** The shared `queryObject` `vi.fn` used by every client and transaction. */
42
- queryObject: import("vitest").Mock<(_query: string, _params?: unknown[]) => Promise<MockQueryResult>>;
68
+ queryObject: import("vitest").Mock<(query: string, params?: unknown[]) => Promise<MockQueryResult>>;
43
69
  /**
44
70
  * Set a fallback query resolver. Called when the enqueue queue is empty.
45
71
  * @param resolver - Function that returns rows for a given query and params
46
72
  */
47
73
  setQueryResolver(resolver: QueryResolver): void;
74
+ /**
75
+ * Configure responses for queries matching SQL text, parameters, or a predicate.
76
+ * More recently registered matchers take precedence.
77
+ * Do not combine matchers with a direct `queryObject.mockImplementation()` override.
78
+ * @param matcher - Query matcher
79
+ * @returns Chainable query behavior
80
+ */
81
+ onQuery<Row = unknown>(matcher: QueryMatcher): QueryBehavior<Row>;
48
82
  /**
49
83
  * Enqueue rows for the next `queryObject` call (FIFO; takes priority over
50
84
  * `setQueryResolver`). Call with no arguments for an empty result.
@@ -56,6 +90,11 @@ declare function mockTailordb(): {
56
90
  * @param rowsList - Rows arrays, one per upcoming query
57
91
  */
58
92
  enqueueResults(...rowsList: unknown[][]): void;
93
+ /**
94
+ * Enqueue row arrays for subsequent queries whose exact order is under test.
95
+ * @param rowsList - Rows arrays, one per upcoming query
96
+ */
97
+ enqueueRows(...rowsList: unknown[][]): void;
59
98
  /**
60
99
  * All queries executed via `queryObject`, in order, derived from the vi.fn
61
100
  * call records.
@@ -67,8 +106,10 @@ declare function mockTailordb(): {
67
106
  * @returns Created clients array
68
107
  */
69
108
  readonly createdClients: CreatedClient[];
109
+ /** Clear recorded calls while preserving configured query behavior. */
110
+ clear(): void;
70
111
  /** Reset query responses and recorded calls (keeps the mock installed). */
71
112
  reset(): void;
72
113
  } & Disposable;
73
114
  //#endregion
74
- export { mockTailordb };
115
+ export { MockTailordbOptions, QueryBehavior, QueryMatch, QueryMatcher, mockTailordb };
@@ -1,14 +1,12 @@
1
1
  import { TailorEnv } from "../../runtime/types.mjs";
2
- import { TriggerJobFunctionOptions } from "../../runtime/workflow.mjs";
2
+ import { StartJobFunctionOptions, StartWorkflowOptions } from "../../runtime/workflow.mjs";
3
+ import { WorkflowJob } from "../../configure/services/workflow/job.mjs";
4
+ import { Workflow } from "../../configure/services/workflow/workflow.mjs";
5
+ import { WaitPointInstance } from "../../configure/services/workflow/wait-point.mjs";
6
+ import { Mock } from "vitest";
3
7
  //#region src/vitest/mocks/workflow.d.ts
4
- type JobHandler = (jobName: string, args: unknown, options?: TriggerJobFunctionOptions) => unknown;
5
- type TriggerWorkflowOptions = {
6
- authInvoker?: {
7
- namespace: string;
8
- machineUserName: string;
9
- };
10
- };
11
- type TriggerHandlerFn = (workflowName: string, args: unknown, options?: TriggerWorkflowOptions) => string;
8
+ type JobHandler = (jobName: string, args: unknown, options?: StartJobFunctionOptions) => unknown;
9
+ type StartHandlerFn = (workflowName: string, args: unknown, options?: StartWorkflowOptions) => string;
12
10
  type ResumeHandlerFn = (executionId: string) => string;
13
11
  type WaitHandlerFn = (key: string, payload: unknown) => unknown;
14
12
  type ResolveHandler = (executionId: string, key: string, callback: (payload: unknown) => unknown) => unknown | Promise<unknown>;
@@ -16,11 +14,12 @@ type SetWaitHandler = {
16
14
  (handler: WaitHandlerFn): void;
17
15
  (handler: unknown): void;
18
16
  };
19
- interface TriggeredJob {
17
+ interface StartedJob {
20
18
  jobName: string;
21
19
  args: unknown;
22
- options?: TriggerJobFunctionOptions;
20
+ options?: StartJobFunctionOptions;
23
21
  }
22
+ type WaitPayload<Payload> = [Payload] extends [undefined] ? undefined : Payload;
24
23
  /**
25
24
  * Acquire a disposable mock for workflow operations (`tailor.workflow`).
26
25
  * Restored on dispose.
@@ -29,55 +28,80 @@ interface TriggeredJob {
29
28
  * ```typescript
30
29
  * import { mockWorkflow } from "@tailor-platform/sdk/vitest";
31
30
  *
32
- * test("job handler", async () => {
31
+ * test("job start", async () => {
33
32
  * using wf = mockWorkflow();
34
- * wf.setJobHandler((name) => (name === "validate" ? { valid: true } : null));
35
- * await runWorkflowUnderTest(); // calls tailor.workflow.triggerJobFunction("validate", {})
36
- * expect(wf.triggerJobFunction).toHaveBeenCalledWith("validate", {});
33
+ * const job = wf.job(validateOrder);
34
+ * job.mockResolvedValue({ valid: true });
35
+ * await runWorkflowUnderTest();
36
+ * expect(job).toHaveBeenCalled();
37
37
  * });
38
38
  * ```
39
39
  */
40
40
  declare function mockWorkflow(): {
41
- /** The `triggerJobFunction` `vi.fn`. */
42
- triggerJobFunction: import("vitest").Mock<(jobName: string, _args?: unknown, _options?: TriggerJobFunctionOptions) => unknown>;
43
- /** The `triggerWorkflow` `vi.fn`. */
44
- triggerWorkflow: import("vitest").Mock<(_workflowName: string, _args?: unknown, _options?: TriggerWorkflowOptions) => Promise<string>>;
45
- /** The `resumeWorkflow` `vi.fn`. */
46
- resumeWorkflow: import("vitest").Mock<(executionId: string) => Promise<string>>;
41
+ /** The `startJobFunction` `vi.fn`. */
42
+ startJobFunction: Mock<(jobName: string, _args?: unknown, _options?: StartJobFunctionOptions) => unknown>;
43
+ /** The `startWorkflow` `vi.fn`. */
44
+ startWorkflow: Mock<(_workflowName: string, _args?: unknown, _options?: StartWorkflowOptions) => Promise<string>>;
45
+ /** The `resumeWorkflowExecution` `vi.fn`. */
46
+ resumeWorkflowExecution: Mock<(executionId: string) => Promise<string>>;
47
47
  /** The `wait` `vi.fn`. */
48
- wait: import("vitest").Mock<(_key: string, _payload?: unknown) => unknown>;
48
+ wait: Mock<(_key: string, _payload?: unknown) => unknown>;
49
49
  /** The `resolve` `vi.fn`. */
50
- resolve: import("vitest").Mock<(_executionId: string, _key: string, _callback: (payload: unknown) => unknown) => Promise<void>>;
50
+ resolve: Mock<(_executionId: string, _key: string, _callback: (payload: unknown) => unknown) => Promise<void>>;
51
+ /**
52
+ * Get a stable, typed mock for a workflow job's `start` method.
53
+ * The real start behavior is used until an implementation or result is configured.
54
+ * @param definition - Workflow job definition to mock
55
+ * @returns Typed `start` mock for the definition
56
+ */
57
+ job<Name extends string, Input, Output>(definition: WorkflowJob<Name, Input, Output>): Mock<WorkflowJob<Name, Input, Output>["start"]>;
58
+ /**
59
+ * Get a stable, typed mock for a workflow definition's `start` method.
60
+ * The real start behavior is used until an implementation or result is configured.
61
+ * @param definition - Workflow definition to mock
62
+ * @returns Typed `start` mock for the definition
63
+ */
64
+ workflow<Definition extends Workflow>(definition: Definition): Mock<Definition["start"]>;
65
+ /**
66
+ * Get stable, typed mocks for a wait point's `wait` and `resolve` methods.
67
+ * @param definition - Wait point definition to mock
68
+ * @returns Typed wait point mock control object
69
+ */
70
+ waitPoint<Payload, Result>(definition: WaitPointInstance<Payload, Result>): {
71
+ wait: Mock<WaitPointInstance<Payload, Result>["wait"]>;
72
+ resolve: Mock<WaitPointInstance<Payload, Result>["resolve"]>;
73
+ setResolvePayload(payload: WaitPayload<Payload>): void;
74
+ };
51
75
  /**
52
76
  * Set a fallback job handler. Called when the enqueue queue is empty.
53
77
  * @param handler - Function returning a result for a job name, args, and options
54
78
  */
55
79
  setJobHandler(handler: JobHandler): void;
56
80
  /**
57
- * Enqueue a single result for the next `triggerJobFunction` call (FIFO;
81
+ * Enqueue a single result for the next `startJobFunction` call (FIFO;
58
82
  * takes priority over `setJobHandler`).
59
83
  * @param result - Result to return from the next call
60
84
  */
61
85
  enqueueResult(result: unknown): void;
62
86
  /**
63
- * Enqueue results for multiple subsequent `triggerJobFunction` calls (FIFO).
87
+ * Enqueue results for multiple subsequent `startJobFunction` calls (FIFO).
64
88
  * @param results - Results to enqueue, one per upcoming call
65
89
  */
66
90
  enqueueResults(...results: unknown[]): void;
67
91
  /**
68
- * All jobs triggered via `triggerJobFunction`, in order.
69
- * @returns Triggered jobs array
92
+ * All jobs started via `startJobFunction`, in order.
93
+ * @returns Started jobs array
70
94
  */
71
- readonly triggeredJobs: TriggeredJob[];
95
+ readonly startedJobs: StartedJob[];
72
96
  /**
73
- * Configure what `triggerWorkflow` returns. Pass a string (same id every
97
+ * Configure what `startWorkflow` returns. Pass a string (same id every
74
98
  * call) or `(name, args, options) => string`. Default: a placeholder UUID.
75
99
  * @param handler - Static execution ID or a function returning one
76
100
  */
77
- setTriggerHandler(handler: string | TriggerHandlerFn): void;
101
+ setStartHandler(handler: string | StartHandlerFn): void;
78
102
  /**
79
- * Configure what `resumeWorkflow` returns. Pass a string (same id every
80
- * call) or `(executionId) => string`. Default: echoes the input executionId.
103
+ * Configure what `resumeWorkflowExecution` returns. Pass a string (same id
104
+ * every call) or `(executionId) => string`. Default: echoes the input executionId.
81
105
  * @param handler - Static execution ID or a function returning one
82
106
  */
83
107
  setResumeHandler(handler: string | ResumeHandlerFn): void;
@@ -88,7 +112,7 @@ declare function mockWorkflow(): {
88
112
  */
89
113
  setWaitHandler: SetWaitHandler;
90
114
  /**
91
- * Set the `env` passed to job bodies invoked via `createWorkflowJob().trigger()`.
115
+ * Set the `env` passed to job bodies invoked via `createWorkflowJob().start()`.
92
116
  * Cleared on dispose / reset.
93
117
  * @param env - Env passed to job bodies.
94
118
  */
@@ -115,6 +139,8 @@ declare function mockWorkflow(): {
115
139
  executionId: string;
116
140
  key: string;
117
141
  }[];
142
+ /** Clear recorded calls while preserving configured responses. */
143
+ clear(): void;
118
144
  /** Reset all workflow responses and recorded calls (keeps the mock installed). */
119
145
  reset(): void;
120
146
  } & Disposable;
@@ -1,5 +1,5 @@
1
- import { t as RUNTIME_FLAG_KEY } from "../globals-BjhJJ2dN.mjs";
2
- import { t as mockSecretmanager } from "../secretmanager-Bd45j7an.mjs";
1
+ import { t as RUNTIME_FLAG_KEY } from "../globals-CBZ0egXT.mjs";
2
+ import { t as mockSecretmanager } from "../secretmanager-IY4UvinW.mjs";
3
3
  import { pathToFileURL } from "node:url";
4
4
  import { afterEach, beforeAll, beforeEach } from "vitest";
5
5
 
@@ -12,9 +12,9 @@ interface RunWorkflowLocallyOptions {
12
12
  env?: TailorEnv;
13
13
  }
14
14
  /**
15
- * Run a workflow's main job and dependent job triggers locally with real job bodies.
15
+ * Run a workflow's main job and dependent job starts locally with real job bodies.
16
16
  *
17
- * Use this for local full-chain workflow tests. Regular `.trigger()` calls
17
+ * Use this for local full-chain workflow tests. Regular `.start()` calls
18
18
  * delegate to the platform workflow runtime and should be mocked with
19
19
  * `mockWorkflow()` when you are not intentionally running the local chain.
20
20
  * @param workflow - Workflow definition to run
@@ -0,0 +1,34 @@
1
+ //#region src/runtime/workflow.ts
2
+ const api = () => globalThis.tailor.workflow;
3
+ /**
4
+ * See {@link PlatformWorkflowAPI.startWorkflow}.
5
+ * @param args - Forwarded to {@link PlatformWorkflowAPI.startWorkflow}
6
+ * @returns The execution ID of the started workflow
7
+ */
8
+ const startWorkflow = (...args) => api().startWorkflow(...args);
9
+ /**
10
+ * See {@link PlatformWorkflowAPI.resumeWorkflowExecution}.
11
+ * @param args - Forwarded to {@link PlatformWorkflowAPI.resumeWorkflowExecution}
12
+ * @returns The execution ID of the resumed workflow
13
+ */
14
+ const resumeWorkflowExecution = (...args) => api().resumeWorkflowExecution(...args);
15
+ /**
16
+ * See {@link PlatformWorkflowAPI.startJobFunction}.
17
+ * @param args - Forwarded to {@link PlatformWorkflowAPI.startJobFunction}
18
+ * @returns The job's return value
19
+ */
20
+ const startJobFunction = (...args) => api().startJobFunction(...args);
21
+ const wait = (...args) => api().wait(...args);
22
+ const resolve = (...args) => api().resolve(...args);
23
+ /** Runtime wrapper namespace for `tailor.workflow`. */
24
+ const workflow = {
25
+ startWorkflow,
26
+ resumeWorkflowExecution,
27
+ startJobFunction,
28
+ wait,
29
+ resolve
30
+ };
31
+
32
+ //#endregion
33
+ export { workflow as t };
34
+ //# sourceMappingURL=workflow-CsBvRE3g.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-CsBvRE3g.mjs","names":[],"sources":["../src/runtime/workflow.ts"],"sourcesContent":["/**\n * Workflow utilities.\n *\n * Thin typed wrapper around the platform-provided `tailor.workflow` runtime API.\n * At runtime this delegates to `globalThis.tailor.workflow`. Use `mockWorkflow`\n * from `@tailor-platform/sdk/vitest` to mock these calls in unit tests.\n * @example\n * import { workflow } from \"@tailor-platform/sdk/runtime\";\n *\n * const executionId = await workflow.startWorkflow(\"myWorkflow\", { data: \"value\" });\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * Specifies the machine user that should be used to execute the workflow.\n * This allows workflows to run with specific authentication context.\n */\nexport interface Invoker {\n /** The namespace where the machine user is defined */\n namespace: string;\n /** The name of the machine user to use for workflow execution */\n machineUserName: string;\n}\n\n/** Options for {@link startWorkflow}. */\nexport interface StartWorkflowOptions {\n /** Optional authentication invoker to specify which machine user should execute the workflow */\n authInvoker?: Invoker;\n}\n\ndeclare const executionPolicyKeyBrand: unique symbol;\n\n/**\n * A concrete runtime key produced by an execution policy instance — either an\n * exact-match policy's `.key`, or a wildcard policy's `.keyFor(suffix)` (see\n * `defineWorkflowExecutionPolicies`). Branded so an arbitrary string that\n * wasn't derived from a declared policy can't be passed as `executionPolicyKey`.\n */\nexport type ExecutionPolicyKey = string & { readonly [executionPolicyKeyBrand]: never };\n\n/** Options for {@link startJobFunction}. */\nexport interface StartJobFunctionOptions {\n /**\n * Execution policy key matched by the platform against the policies\n * declared with `defineWorkflowExecutionPolicies` in `tailor.config.ts`.\n */\n executionPolicyKey?: ExecutionPolicyKey;\n}\n\n/**\n * Platform API surface for `tailor.workflow`. Describes the shape the platform\n * runtime injects on `globalThis.tailor.workflow`.\n */\nexport interface PlatformWorkflowAPI {\n /**\n * Starts a workflow and returns its execution ID.\n * @param workflowName - Workflow name as defined in tailor.config\n * @param args - Arguments forwarded to the workflow's main job\n * @param options - Optional start options (e.g. `authInvoker`)\n * @returns The execution ID of the started workflow\n */\n startWorkflow(workflowName: string, args?: any, options?: StartWorkflowOptions): Promise<string>;\n\n /**\n * Resumes a failed or pending-retry workflow execution and returns its execution ID.\n * @param executionId - The execution to resume\n * @returns The execution ID of the resumed workflow\n */\n resumeWorkflowExecution(executionId: string): Promise<string>;\n\n /**\n * Starts a job function and returns its result.\n * @param jobName - Job name as defined in the workflow\n * @param args - Arguments forwarded to the job\n * @param options - Optional start options (e.g. `executionPolicyKey`)\n * @returns The job's return value\n */\n startJobFunction(jobName: string, args?: any, options?: StartJobFunctionOptions): any;\n\n /**\n * Suspends the current workflow execution and waits for an external signal to resume.\n * @param key - Wait point key\n * @param payload - Optional payload to record with the wait point\n * @returns The payload supplied by the corresponding `resolve` call\n */\n wait(key: string, payload?: any): any;\n\n /**\n * Resolves a waiting workflow execution, causing it to resume.\n * @param executionId - The execution to resume\n * @param key - Wait point key to resolve\n * @param callback - Callback receiving the wait payload; its return value is forwarded to `wait`\n * @returns A promise that resolves once the resolve has been recorded\n */\n resolve(executionId: string, key: string, callback: (waitPayload: any) => any): Promise<void>;\n}\n\nconst api = (): PlatformWorkflowAPI =>\n (globalThis as unknown as { tailor: { workflow: PlatformWorkflowAPI } }).tailor.workflow;\n\n/**\n * See {@link PlatformWorkflowAPI.startWorkflow}.\n * @param args - Forwarded to {@link PlatformWorkflowAPI.startWorkflow}\n * @returns The execution ID of the started workflow\n */\nconst startWorkflow: PlatformWorkflowAPI[\"startWorkflow\"] = (...args) =>\n api().startWorkflow(...args);\n\n/**\n * See {@link PlatformWorkflowAPI.resumeWorkflowExecution}.\n * @param args - Forwarded to {@link PlatformWorkflowAPI.resumeWorkflowExecution}\n * @returns The execution ID of the resumed workflow\n */\nconst resumeWorkflowExecution: PlatformWorkflowAPI[\"resumeWorkflowExecution\"] = (...args) =>\n api().resumeWorkflowExecution(...args);\n\n/**\n * See {@link PlatformWorkflowAPI.startJobFunction}.\n * @param args - Forwarded to {@link PlatformWorkflowAPI.startJobFunction}\n * @returns The job's return value\n */\nconst startJobFunction: PlatformWorkflowAPI[\"startJobFunction\"] = (...args) =>\n api().startJobFunction(...args);\n\nconst wait: PlatformWorkflowAPI[\"wait\"] = (...args) => api().wait(...args);\n\nconst resolve: PlatformWorkflowAPI[\"resolve\"] = (...args) => api().resolve(...args);\n\n/** Runtime wrapper namespace for `tailor.workflow`. */\nexport const workflow = {\n startWorkflow,\n resumeWorkflowExecution,\n startJobFunction,\n wait,\n resolve,\n} as const satisfies PlatformWorkflowAPI;\n"],"mappings":";AAkGA,MAAM,YACH,WAAwE,OAAO;;;;;;AAOlF,MAAM,iBAAuD,GAAG,SAC9D,IAAI,CAAC,CAAC,cAAc,GAAG,IAAI;;;;;;AAO7B,MAAM,2BAA2E,GAAG,SAClF,IAAI,CAAC,CAAC,wBAAwB,GAAG,IAAI;;;;;;AAOvC,MAAM,oBAA6D,GAAG,SACpE,IAAI,CAAC,CAAC,iBAAiB,GAAG,IAAI;AAEhC,MAAM,QAAqC,GAAG,SAAS,IAAI,CAAC,CAAC,KAAK,GAAG,IAAI;AAEzE,MAAM,WAA2C,GAAG,SAAS,IAAI,CAAC,CAAC,QAAQ,GAAG,IAAI;;AAGlF,MAAa,WAAW;CACtB;CACA;CACA;CACA;CACA;AACF"}