@tailor-platform/sdk 2.0.0-next.8 → 2.0.0

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 (180) hide show
  1. package/CHANGELOG.md +631 -0
  2. package/dist/{application-GzW98_Xr.mjs → application-CM6hKnSK.mjs} +489 -118
  3. package/dist/application-CM6hKnSK.mjs.map +1 -0
  4. package/dist/application-CXNaUNhv.mjs +3 -0
  5. package/dist/cli/commands/deploy/aigateway.d.mts +2 -2
  6. package/dist/cli/commands/deploy/application.d.mts +2 -2
  7. package/dist/cli/commands/deploy/auth.d.mts +2 -2
  8. package/dist/cli/commands/deploy/deploy.d.mts +1 -0
  9. package/dist/cli/commands/deploy/executor.d.mts +2 -2
  10. package/dist/cli/commands/deploy/function-registry.d.mts +1 -2
  11. package/dist/cli/commands/deploy/idp.d.mts +2 -2
  12. package/dist/cli/commands/deploy/label.d.mts +2 -0
  13. package/dist/cli/commands/deploy/resolver.d.mts +2 -2
  14. package/dist/cli/commands/deploy/secret-manager.d.mts +1 -1
  15. package/dist/cli/commands/deploy/staticwebsite.d.mts +2 -2
  16. package/dist/cli/commands/deploy/tailordb/index.d.mts +4 -2
  17. package/dist/cli/commands/deploy/types.d.mts +2 -1
  18. package/dist/cli/commands/deploy/workflow-execution-policy.d.mts +1 -2
  19. package/dist/cli/commands/deploy/workflow.d.mts +2 -2
  20. package/dist/cli/commands/executor/get.d.mts +1 -10
  21. package/dist/cli/commands/executor/jobs.d.mts +1 -38
  22. package/dist/cli/commands/executor/trigger.d.mts +1 -11
  23. package/dist/cli/commands/generate/seed/bundler.d.mts +2 -1
  24. package/dist/cli/commands/tailordb/migrate/bundler.d.mts +3 -2
  25. package/dist/cli/commands/tailordb/migrate/diff-calculator.d.mts +11 -1
  26. package/dist/cli/commands/tailordb/migrate/schema-checks.d.mts +5 -0
  27. package/dist/cli/commands/tailordb/migrate/snapshot.d.mts +1 -1
  28. package/dist/cli/commands/workflow/executions.d.mts +1 -13
  29. package/dist/cli/commands/workflow/get.d.mts +1 -10
  30. package/dist/cli/commands/workflow/start.d.mts +2 -14
  31. package/dist/cli/index.mjs +12 -6552
  32. package/dist/cli/lib.d.mts +14 -15
  33. package/dist/cli/lib.mjs +203 -46
  34. package/dist/cli/lib.mjs.map +1 -1
  35. package/dist/cli/{index.d.mts → main.d.mts} +1 -1
  36. package/dist/cli/main.mjs +6777 -0
  37. package/dist/cli/main.mjs.map +1 -0
  38. package/dist/cli/services/http-adapter/bundler.d.mts +1 -0
  39. package/dist/cli/services/workflow/bundler.d.mts +2 -1
  40. package/dist/cli/shared/client.d.mts +28 -3
  41. package/dist/cli/shared/config-loader.d.mts +11 -4
  42. package/dist/cli/shared/error-json.d.mts +23 -0
  43. package/dist/cli/shared/script-executor.d.mts +6 -3
  44. package/dist/cli/shared/seed-chunker.d.mts +2 -7
  45. package/dist/cli/shared/seed-context.d.mts +49 -0
  46. package/dist/cli/shared/tailordb-namespaces.d.mts +7 -4
  47. package/dist/cli/shared/tsconfig-paths-plugin.d.mts +2 -0
  48. package/dist/cli/shared/type-generator.d.mts +4 -3
  49. package/dist/completion/zsh-worker.zsh +85 -22
  50. package/dist/configure/config/types.d.mts +29 -4
  51. package/dist/configure/index.d.mts +4 -3
  52. package/dist/configure/index.mjs +183 -6
  53. package/dist/configure/index.mjs.map +1 -1
  54. package/dist/configure/services/executor/index.d.mts +2 -2
  55. package/dist/configure/services/executor/trigger/event.d.mts +245 -2
  56. package/dist/configure/services/executor/trigger/index.d.mts +3 -3
  57. package/dist/configure/services/idp/index.d.mts +2 -2
  58. package/dist/configure/services/idp/permission.d.mts +1 -16
  59. package/dist/configure/services/idp/types.d.mts +5 -1
  60. package/dist/configure/services/index.d.mts +4 -3
  61. package/dist/configure/services/resolver/index.d.mts +2 -1
  62. package/dist/configure/services/resolver/permission.d.mts +64 -0
  63. package/dist/configure/services/resolver/resolver.d.mts +14 -2
  64. package/dist/configure/services/tailordb/index.d.mts +0 -1
  65. package/dist/configure/services/tailordb/permission.d.mts +1 -16
  66. package/dist/configure/services/workflow/execution-policy.d.mts +3 -3
  67. package/dist/configure/services/workflow/execution-policy.types.d.mts +1 -1
  68. package/dist/configure/services/workflow/job.d.mts +11 -2
  69. package/dist/configure/services/workflow/workflow.d.mts +10 -0
  70. package/dist/configure/types/permission-operand.types.d.mts +20 -0
  71. package/dist/{crashreport-CxHne11E.mjs → crashreport-B5LqCTfF.mjs} +2 -2
  72. package/dist/{crashreport-CxHne11E.mjs.map → crashreport-B5LqCTfF.mjs.map} +1 -1
  73. package/dist/{crashreport-0ioNRZ4K.mjs → crashreport-eI7ty7ok.mjs} +1 -1
  74. package/dist/{errors-DfnF4ibq.mjs → errors-D7583Zz7.mjs} +2 -44
  75. package/dist/errors-D7583Zz7.mjs.map +1 -0
  76. package/dist/{globals-CBZ0egXT.mjs → globals-TfAVItuK.mjs} +21 -5
  77. package/dist/globals-TfAVItuK.mjs.map +1 -0
  78. package/dist/logger-BtX0suGY.mjs +48 -0
  79. package/dist/logger-BtX0suGY.mjs.map +1 -0
  80. package/dist/{logger-BwS4ppwO.mjs → logger-CXQq9YIp.mjs} +110 -13
  81. package/dist/logger-CXQq9YIp.mjs.map +1 -0
  82. package/dist/node-builtins-CmaL2Cbq.mjs +36 -0
  83. package/dist/node-builtins-CmaL2Cbq.mjs.map +1 -0
  84. package/dist/plugin/builtin/enum-constants/index.mjs +115 -2
  85. package/dist/plugin/builtin/enum-constants/index.mjs.map +1 -0
  86. package/dist/plugin/builtin/file-utils/index.mjs +149 -2
  87. package/dist/plugin/builtin/file-utils/index.mjs.map +1 -0
  88. package/dist/plugin/builtin/kysely-type/index.mjs +274 -2
  89. package/dist/plugin/builtin/kysely-type/index.mjs.map +1 -0
  90. package/dist/plugin/builtin/seed/index.d.mts +3 -2
  91. package/dist/plugin/builtin/seed/index.mjs +1 -1
  92. package/dist/plugin/builtin/seed/seed-type-processor.d.mts +21 -0
  93. package/dist/plugin/builtin/seed/types.d.mts +2 -0
  94. package/dist/{register-ts-hook-DvEs6YsL.mjs → register-ts-hook-LYV7zH-e.mjs} +2953 -996
  95. package/dist/register-ts-hook-LYV7zH-e.mjs.map +1 -0
  96. package/dist/{registry-i7EdJ-D5.mjs → registry-BIGVUrMB.mjs} +3 -3
  97. package/dist/registry-BIGVUrMB.mjs.map +1 -0
  98. package/dist/runtime/globals.d.mts +7 -0
  99. package/dist/runtime/index.d.mts +3 -1
  100. package/dist/runtime/index.mjs +3 -2
  101. package/dist/runtime/logger.d.mts +98 -0
  102. package/dist/runtime/logger.mjs +3 -0
  103. package/dist/runtime/workflow.d.mts +15 -7
  104. package/dist/runtime/workflow.mjs +1 -1
  105. package/dist/seed-B-yckgQY.mjs +483 -0
  106. package/dist/seed-B-yckgQY.mjs.map +1 -0
  107. package/dist/{service-DaeJlBoH.mjs → service-B5WynBHQ.mjs} +3 -3
  108. package/dist/{service-DaeJlBoH.mjs.map → service-B5WynBHQ.mjs.map} +1 -1
  109. package/dist/service-M7OYziQP.mjs +3 -0
  110. package/dist/{service-Dmxa2I4i.mjs → service-k1xy_A5G.mjs} +30 -4
  111. package/dist/service-k1xy_A5G.mjs.map +1 -0
  112. package/dist/{service_pb-BoLM0X4K.mjs → service_pb-D5--My_M.mjs} +5 -5
  113. package/dist/service_pb-D5--My_M.mjs.map +1 -0
  114. package/dist/{service_pb-r1T7kpJc.mjs → service_pb-i8CmnQP4.mjs} +1 -1
  115. package/dist/tailor-proto/src/tailor/v1/application_pb.d.mts +106 -1
  116. package/dist/tailor-proto/src/tailor/v1/auth_resource_pb.d.mts +6 -1
  117. package/dist/tailor-proto/src/tailor/v1/executor_resource_pb.d.mts +24 -1
  118. package/dist/tailor-proto/src/tailor/v1/function_pb.d.mts +49 -1
  119. package/dist/tailor-proto/src/tailor/v1/service_pb.d.mts +89 -6
  120. package/dist/tailor-proto/src/tailor/v1/telemetryrouter_resource_pb.d.mts +26 -1
  121. package/dist/tailor-proto/src/tailor/v1/workflow_pb.d.mts +101 -1
  122. package/dist/tailor-proto/src/tailor/v1/workflow_resource_pb.d.mts +22 -1
  123. package/dist/types/auth.generated.d.mts +14 -2
  124. package/dist/types/executor.generated.d.mts +45 -3
  125. package/dist/types/http-adapter.generated.d.mts +5 -0
  126. package/dist/types/idp.generated.d.mts +31 -1
  127. package/dist/types/resolver.generated.d.mts +30 -2
  128. package/dist/types/tailordb.generated.d.mts +15 -3
  129. package/dist/utils/test/index.d.mts +1 -2
  130. package/dist/utils/test/index.mjs +1 -169
  131. package/dist/utils/test/index.mjs.map +1 -1
  132. package/dist/vitest/environment.mjs +1 -1
  133. package/dist/vitest/index.d.mts +6 -4
  134. package/dist/vitest/index.mjs +112 -62
  135. package/dist/vitest/index.mjs.map +1 -1
  136. package/dist/vitest/mock.d.mts +2 -1
  137. package/dist/vitest/mocks/logger.d.mts +45 -0
  138. package/dist/vitest/mocks/workflow.d.mts +8 -8
  139. package/dist/vitest/setup.mjs +1 -1
  140. package/dist/{workflow-CsBvRE3g.mjs → workflow-Bamae_Yc.mjs} +5 -5
  141. package/dist/workflow-Bamae_Yc.mjs.map +1 -0
  142. package/dist/{workspace_resource_pb-Db3fv68L.mjs → workspace_resource_pb-DXnO2AT-.mjs} +13 -8
  143. package/dist/workspace_resource_pb-DXnO2AT-.mjs.map +1 -0
  144. package/docs/cli/application.md +5 -1
  145. package/docs/cli/tailordb.md +47 -13
  146. package/docs/cli-reference.md +38 -30
  147. package/docs/configuration.md +54 -2
  148. package/docs/github-actions.md +2 -2
  149. package/docs/migration/v2.md +408 -5
  150. package/docs/runtime.md +5 -1
  151. package/docs/services/executor.md +83 -3
  152. package/docs/services/idp.md +8 -6
  153. package/docs/services/resolver.md +60 -4
  154. package/docs/services/tailordb-migration.md +31 -7
  155. package/docs/services/tailordb.md +7 -5
  156. package/docs/services/workflow.md +33 -3
  157. package/docs/testing.md +34 -7
  158. package/package.json +31 -24
  159. package/dist/application-GzW98_Xr.mjs.map +0 -1
  160. package/dist/application-OM0taSPn.mjs +0 -3
  161. package/dist/cli/index.mjs.map +0 -1
  162. package/dist/enum-constants-j9QBF0cB.mjs +0 -116
  163. package/dist/enum-constants-j9QBF0cB.mjs.map +0 -1
  164. package/dist/errors-DfnF4ibq.mjs.map +0 -1
  165. package/dist/file-utils-yEiIS4nJ.mjs +0 -150
  166. package/dist/file-utils-yEiIS4nJ.mjs.map +0 -1
  167. package/dist/globals-CBZ0egXT.mjs.map +0 -1
  168. package/dist/kysely-type-DqIRgDYR.mjs +0 -275
  169. package/dist/kysely-type-DqIRgDYR.mjs.map +0 -1
  170. package/dist/logger-BwS4ppwO.mjs.map +0 -1
  171. package/dist/register-ts-hook-DvEs6YsL.mjs.map +0 -1
  172. package/dist/registry-i7EdJ-D5.mjs.map +0 -1
  173. package/dist/seed-CRSQJI_z.mjs +0 -1170
  174. package/dist/seed-CRSQJI_z.mjs.map +0 -1
  175. package/dist/service-BJAQ70e5.mjs +0 -3
  176. package/dist/service-Dmxa2I4i.mjs.map +0 -1
  177. package/dist/service_pb-BoLM0X4K.mjs.map +0 -1
  178. package/dist/utils/test/mock.d.mts +0 -86
  179. package/dist/workflow-CsBvRE3g.mjs.map +0 -1
  180. package/dist/workspace_resource_pb-Db3fv68L.mjs.map +0 -1
@@ -13,12 +13,19 @@ type IdPGqlOperationsInput = "query" | {
13
13
  unenrollMfa?: boolean | undefined;
14
14
  };
15
15
  type IdPGqlOperations = {
16
+ /** Enable _createUser mutation (default: true) */
16
17
  create?: boolean | undefined;
18
+ /** Enable _updateUser mutation (default: true) */
17
19
  update?: boolean | undefined;
20
+ /** Enable _deleteUser mutation (default: true) */
18
21
  delete?: boolean | undefined;
22
+ /** Enable _users and _user queries (default: true) */
19
23
  read?: boolean | undefined;
24
+ /** Enable _sendPasswordResetEmail mutation (default: true) */
20
25
  sendPasswordResetEmail?: boolean | undefined;
26
+ /** Enable _requestMfaSettingsUrl query (default: true) */
21
27
  requestMfaSettingsUrl?: boolean | undefined;
28
+ /** Enable _unenrollMfa mutation (default: true) */
22
29
  unenrollMfa?: boolean | undefined;
23
30
  };
24
31
  /**
@@ -558,33 +565,56 @@ type IdPInput = {
558
565
  lang?: "en" | "ja" | undefined;
559
566
  /** User authentication policy configuration */
560
567
  userAuthPolicy?: {
568
+ /** Use non-email identifier for usernames */
561
569
  useNonEmailIdentifier?: boolean | undefined;
570
+ /** Allow users to reset their own passwords */
562
571
  allowSelfPasswordReset?: boolean | undefined;
572
+ /** Require uppercase letters in passwords */
563
573
  passwordRequireUppercase?: boolean | undefined;
574
+ /** Require lowercase letters in passwords */
564
575
  passwordRequireLowercase?: boolean | undefined;
576
+ /** Require non-alphanumeric characters in passwords */
565
577
  passwordRequireNonAlphanumeric?: boolean | undefined;
578
+ /** Require numeric characters in passwords */
566
579
  passwordRequireNumeric?: boolean | undefined;
580
+ /** Minimum password length (6-30) */
567
581
  passwordMinLength?: number | undefined;
582
+ /** Maximum password length (6-4096) */
568
583
  passwordMaxLength?: number | undefined;
584
+ /** Restrict registration to these email domains */
569
585
  allowedEmailDomains?: string[] | undefined;
586
+ /** Enable Google OAuth login */
570
587
  allowGoogleOauth?: boolean | undefined;
588
+ /** Enable Microsoft OAuth login */
571
589
  allowMicrosoftOauth?: boolean | undefined;
590
+ /** Disable password-based authentication */
572
591
  disablePasswordAuth?: boolean | undefined;
592
+ /** Make TOTP MFA available for users in this namespace */
573
593
  enableMfa?: boolean | undefined;
594
+ /** Require TOTP MFA enrollment and challenge for password-authenticated users (requires enableMfa) */
574
595
  requireMfa?: boolean | undefined;
596
+ /** Application origins (scheme + host + optional port) allowed as MFA self-service return targets */
575
597
  allowedReturnOrigins?: string[] | undefined;
598
+ /** Label shown next to the user account in authenticator apps */
576
599
  mfaIssuer?: string | undefined;
577
600
  } | undefined;
578
601
  /** Enable publishing user lifecycle events */
579
- publishUserEvents?: boolean | undefined;
602
+ publishEvents?: boolean | undefined;
580
603
  /** Configure which GraphQL operations are enabled */
581
604
  gqlOperations?: "query" | {
605
+ /** Enable _createUser mutation (default: true) */
582
606
  create?: boolean | undefined;
607
+ /** Enable _updateUser mutation (default: true) */
583
608
  update?: boolean | undefined;
609
+ /** Enable _deleteUser mutation (default: true) */
584
610
  delete?: boolean | undefined;
611
+ /** Enable _users and _user queries (default: true) */
585
612
  read?: boolean | undefined;
613
+ /** Enable _sendPasswordResetEmail mutation (default: true) */
586
614
  sendPasswordResetEmail?: boolean | undefined;
615
+ /** Enable _requestMfaSettingsUrl query (default: true) */
587
616
  requestMfaSettingsUrl?: boolean | undefined;
617
+ /** Enable _unenrollMfa mutation (default: true) */
588
618
  unenrollMfa?: boolean | undefined;
589
619
  } | undefined;
590
620
  /** Namespace-level email configuration defaults */
@@ -12,23 +12,35 @@ type Resolver = {
12
12
  body: Function;
13
13
  /** Output field definition */
14
14
  output: {
15
+ /** Field data type */
15
16
  type: "string" | "boolean" | "date" | "enum" | "uuid" | "integer" | "float" | "decimal" | "datetime" | "time" | "nested";
17
+ /** Field metadata configuration */
16
18
  metadata: {
19
+ /** Whether the field is required */
17
20
  required?: boolean | undefined;
21
+ /** Whether the field is an array */
18
22
  array?: boolean | undefined;
19
- /** Resolver description */
23
+ /** Field description */
20
24
  description?: string | undefined;
25
+ /** Allowed values for enum fields */
21
26
  allowedValues?: {
27
+ /** The allowed value */
22
28
  value: string;
23
- /** Resolver description */
29
+ /** Description of the allowed value */
24
30
  description?: string | undefined;
25
31
  }[] | undefined;
32
+ /** Lifecycle hooks */
26
33
  hooks?: {
34
+ /** Hook function called on creation */
27
35
  create?: Function | undefined;
36
+ /** Hook function called on update */
28
37
  update?: Function | undefined;
29
38
  } | undefined;
39
+ /** Validation functions for the field */
30
40
  validate?: Function[] | undefined;
41
+ /** Type name for nested or enum fields */
31
42
  typeName?: string | undefined;
43
+ /** Default value for the field on create */
32
44
  default?: unknown;
33
45
  };
34
46
  fields: {
@@ -45,9 +57,25 @@ type Resolver = {
45
57
  publishEvents?: boolean | undefined;
46
58
  /** Machine user to execute this resolver as */
47
59
  invoker?: string | {
60
+ /** Auth namespace */
48
61
  namespace: string;
62
+ /** Machine user name for authentication */
49
63
  machineUserName: string;
50
64
  } | undefined;
65
+ permission?: "allowAnonymous" | readonly {
66
+ conditions: readonly [(string | boolean | {
67
+ user: string;
68
+ }), "=" | "!=", (string | boolean | {
69
+ user: string;
70
+ })] | readonly (readonly [(string | boolean | {
71
+ user: string;
72
+ }), "=" | "!=", (string | boolean | {
73
+ user: string;
74
+ })])[];
75
+ permit: boolean;
76
+ /** Reason recorded for this policy, used in the access-denied error message */
77
+ description?: string | undefined;
78
+ }[] | undefined;
51
79
  };
52
80
  type ResolverInput = Resolver;
53
81
  //#endregion
@@ -10,9 +10,13 @@ type GqlOperationsInput = "query" | {
10
10
  read?: boolean | undefined;
11
11
  };
12
12
  type GqlOperations = {
13
+ /** Enable create mutation (default: true) */
13
14
  create?: boolean | undefined;
15
+ /** Enable update mutation (default: true) */
14
16
  update?: boolean | undefined;
17
+ /** Enable delete mutation (default: true) */
15
18
  delete?: boolean | undefined;
19
+ /** Enable read queries - get, list, aggregation (default: true) */
16
20
  read?: boolean | undefined;
17
21
  };
18
22
  type DBFieldMetadata = {
@@ -27,7 +31,6 @@ type DBFieldMetadata = {
27
31
  /** Allowed values for enum fields */
28
32
  allowedValues?: {
29
33
  value: string;
30
- /** Field description */
31
34
  description?: string | undefined;
32
35
  }[] | undefined;
33
36
  /** Whether the field is indexed for faster queries */
@@ -44,15 +47,20 @@ type DBFieldMetadata = {
44
47
  foreignKeyField?: string | undefined;
45
48
  /** Lifecycle hooks for the field */
46
49
  hooks?: {
50
+ /** Hook function called on record creation */
47
51
  create?: Function | undefined;
52
+ /** Hook function called on record update */
48
53
  update?: Function | undefined;
49
54
  } | undefined;
50
55
  /** Validation functions for the field */
51
56
  validate?: Function[] | undefined;
52
57
  /** Serial (auto-increment) configuration */
53
58
  serial?: {
59
+ /** Starting value for the serial sequence */
54
60
  start: number;
61
+ /** Maximum value for the serial sequence */
55
62
  maxValue?: number | undefined;
63
+ /** Format string for serial value (string type only) */
56
64
  format?: string | undefined;
57
65
  } | undefined;
58
66
  /** Decimal scale (number of digits after decimal point, 0-12) */
@@ -437,18 +445,22 @@ type TailorDBServiceConfigInput = {
437
445
  files: string[];
438
446
  /** Glob patterns to exclude from type discovery */
439
447
  ignores?: string[] | undefined;
440
- /** URL for the ERD (Entity Relationship Diagram) site */
441
- erdSite?: string | undefined;
442
448
  /** Migration configuration */
443
449
  migration?: {
450
+ /** Directory containing migration files */
444
451
  directory: string;
452
+ /** Machine user name for migration execution */
445
453
  machineUser?: string | undefined;
446
454
  } | undefined;
447
455
  /** Default GraphQL operations for all types in this service */
448
456
  gqlOperations?: "query" | {
457
+ /** Enable create mutation (default: true) */
449
458
  create?: boolean | undefined;
459
+ /** Enable update mutation (default: true) */
450
460
  update?: boolean | undefined;
461
+ /** Enable delete mutation (default: true) */
451
462
  delete?: boolean | undefined;
463
+ /** Enable read queries - get, list, aggregation (default: true) */
452
464
  read?: boolean | undefined;
453
465
  } | undefined;
454
466
  };
@@ -1,7 +1,6 @@
1
1
  import { TailorDBType } from "../../configure/services/tailordb/schema.mjs";
2
2
  import { TailorField } from "../../configure/types/type.mjs";
3
3
  import { output } from "../../configure/index.mjs";
4
- import { createImportMain, setupInvokerMock, setupTailorErrorsMock, setupTailordbMock, setupWaitPointMock, setupWorkflowMock } from "./mock.mjs";
5
4
  import { StandardSchemaV1 } from "@standard-schema/spec";
6
5
  //#region src/utils/test/index.d.ts
7
6
  /**
@@ -32,4 +31,4 @@ declare function createStandardSchema<T = Record<string, unknown>>(schemaType: T
32
31
  };
33
32
  };
34
33
  //#endregion
35
- export { createImportMain, createStandardSchema, createTailorDBHook, setupInvokerMock, setupTailorErrorsMock, setupTailordbMock, setupWaitPointMock, setupWorkflowMock };
34
+ export { createStandardSchema, createTailorDBHook };
@@ -1,171 +1,3 @@
1
- import { pathToFileURL } from "node:url";
2
- import * as path from "node:path";
3
-
4
- //#region src/utils/test/mock.ts
5
- const GlobalThis = globalThis;
6
- /**
7
- * Sets up a mock for `globalThis.tailordb.Client` used in bundled resolver/executor tests.
8
- * @deprecated Use `mockTailordb` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.
9
- * @param resolver - Optional function to resolve query results. Defaults to returning empty arrays.
10
- * @returns Object containing arrays of executed queries and created clients for assertions.
11
- */
12
- function setupTailordbMock(resolver = () => []) {
13
- const executedQueries = [];
14
- const createdClients = [];
15
- class MockTailordbClient {
16
- record;
17
- constructor({ namespace }) {
18
- this.record = {
19
- namespace,
20
- ended: false
21
- };
22
- createdClients.push(this.record);
23
- }
24
- async connect() {}
25
- async end() {
26
- this.record.ended = true;
27
- }
28
- async queryObject(query, params = []) {
29
- executedQueries.push({
30
- query,
31
- params
32
- });
33
- return { rows: resolver(query, params) };
34
- }
35
- }
36
- GlobalThis.tailordb = { Client: MockTailordbClient };
37
- return {
38
- executedQueries,
39
- createdClients
40
- };
41
- }
42
- /**
43
- * Sets up a mock for `globalThis.tailor.workflow.startJobFunction` used in bundled workflow tests.
44
- * `wait`/`resolve` are stubbed to throw a helpful error directing to `mockWorkflow`,
45
- * so mistakenly calling wait without wait-point mocks produces a clear message instead of a TypeError.
46
- * @deprecated Use `mockWorkflow` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.
47
- * @param handler - Function that handles started job calls and returns results.
48
- * @returns Object containing an array of started jobs for assertions.
49
- */
50
- function setupWorkflowMock(handler) {
51
- const startedJobs = [];
52
- GlobalThis.tailor = {
53
- ...GlobalThis.tailor,
54
- workflow: {
55
- wait: () => {
56
- throw new Error("tailor.workflow.wait is not mocked. Use mockWorkflow from @tailor-platform/sdk/vitest in tests.");
57
- },
58
- resolve: async () => {
59
- throw new Error("tailor.workflow.resolve is not mocked. Use mockWorkflow from @tailor-platform/sdk/vitest in tests.");
60
- },
61
- ...GlobalThis.tailor?.workflow,
62
- startJobFunction: (jobName, args) => {
63
- startedJobs.push({
64
- jobName,
65
- args
66
- });
67
- return handler(jobName, args);
68
- }
69
- }
70
- };
71
- return { startedJobs };
72
- }
73
- /**
74
- * Sets up a mock for `globalThis.tailor.context.getInvoker` used in bundled
75
- * resolver/executor/workflow tests.
76
- * @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.
77
- * @param invoker - The `TailorPrincipal` value to return, or `null` for anonymous.
78
- */
79
- function setupInvokerMock(invoker) {
80
- const raw = invoker ? {
81
- id: invoker.id,
82
- type: invoker.type,
83
- workspaceId: invoker.workspaceId,
84
- attributes: invoker.attributeList,
85
- attributeMap: invoker.attributes
86
- } : null;
87
- GlobalThis.tailor = {
88
- ...GlobalThis.tailor,
89
- context: { getInvoker: () => raw }
90
- };
91
- }
92
- /**
93
- * Sets up a mock for `globalThis.TailorErrors` used in bundled resolver tests.
94
- * Mimics the PF runtime's TailorErrors class that serializes errors with the `TailorErrors: ` prefix.
95
- * @deprecated Use the `tailor-runtime` environment from `@tailor-platform/sdk/vitest` which auto-injects TailorErrors.
96
- */
97
- function setupTailorErrorsMock() {
98
- GlobalThis.TailorErrors = class TailorErrors extends Error {
99
- errors;
100
- constructor(errors) {
101
- super(`TailorErrors: ${JSON.stringify({ errors })}`);
102
- this.name = "TailorErrors";
103
- this.errors = errors;
104
- }
105
- };
106
- }
107
- /**
108
- * Sets up mocks for `globalThis.tailor.workflow.wait` and `.resolve` used in bundled workflow tests.
109
- * `startJobFunction` is stubbed to throw a helpful error directing to `setupWorkflowMock()`,
110
- * so mistakenly starting a job without job mocks produces a clear message instead of silently returning undefined.
111
- * @deprecated Use `mockWorkflow` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.
112
- * `setWaitHandler` / `setResolveHandler` cover wait/resolve, and `waitCalls` / `resolveCalls` give the same assertion shape.
113
- * @param config - Optional handlers for wait and resolve calls.
114
- * @param config.onWait - Handler called when wait is invoked.
115
- * @param config.onResolve - Handler called when resolve is invoked.
116
- * @returns Object containing arrays of wait and resolve calls for assertions.
117
- */
118
- function setupWaitPointMock(config) {
119
- const waitCalls = [];
120
- const resolveCalls = [];
121
- GlobalThis.tailor = {
122
- ...GlobalThis.tailor,
123
- workflow: {
124
- startJobFunction: () => {
125
- throw new Error("tailor.workflow.startJobFunction is not mocked. Use setupWorkflowMock() in tests.");
126
- },
127
- ...GlobalThis.tailor?.workflow,
128
- wait: (key, payload) => {
129
- waitCalls.push({
130
- key,
131
- payload
132
- });
133
- return config?.onWait?.(key, payload);
134
- },
135
- resolve: async (executionId, key, callback) => {
136
- resolveCalls.push({
137
- executionId,
138
- key
139
- });
140
- await config?.onResolve?.(executionId, key, callback);
141
- }
142
- }
143
- };
144
- return {
145
- waitCalls,
146
- resolveCalls
147
- };
148
- }
149
- /**
150
- * Creates a function that imports a bundled JS file and returns its `main` export.
151
- * Used to test bundled output from `apply --buildOnly`.
152
- * @param baseDir - Base directory where bundled files are located.
153
- * @returns An async function that takes a relative path and returns the `main` function.
154
- * @deprecated This is an SDK-internal testing helper. Bundling integrity is the SDK's responsibility,
155
- * not the application's — verify your code through unit tests against the TypeScript source and
156
- * E2E tests against a deployed application instead. This export will be removed in a future release.
157
- */
158
- function createImportMain(baseDir) {
159
- return async (relativePath) => {
160
- const fileUrl = pathToFileURL(path.join(baseDir, relativePath));
161
- fileUrl.searchParams.set("v", `${Date.now()}-${Math.random()}`);
162
- const main = (await import(fileUrl.href)).main;
163
- if (typeof main !== "function") throw new Error(`Expected "main" to be a function in ${relativePath}, got ${typeof main}`);
164
- return main;
165
- };
166
- }
167
-
168
- //#endregion
169
1
  //#region src/utils/test/index.ts
170
2
  /**
171
3
  * Creates a hook function that processes TailorDB type fields
@@ -250,5 +82,5 @@ function createStandardSchema(schemaType, hook) {
250
82
  }
251
83
 
252
84
  //#endregion
253
- export { createImportMain, createStandardSchema, createTailorDBHook, setupInvokerMock, setupTailorErrorsMock, setupTailordbMock, setupWaitPointMock, setupWorkflowMock };
85
+ export { createStandardSchema, createTailorDBHook };
254
86
  //# sourceMappingURL=index.mjs.map
@@ -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 { 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,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A,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/index.ts"],"sourcesContent":["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\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":";;;;;;;;;;AAeA,SAAgB,mBAAqD,MAAS;CAC5E,QAAQ,MAAe,sBAAY,IAAI,KAAK,MAAM;EAChD,MAAM,MAAM,QAAQ,OAAO,SAAS,WAAY,OAAmC;EACnF,MAAM,SAAS,OAAO,QAAQ,KAAK,MAAM,CAAC,CAAC,QACxC,QAAQ,CAAC,KAAK,WAAW;GAExB,MAAM,QAAQ;GACd,IAAI,QAAQ,MACV,OAAO,OAAO,MAAM,QAAQ,OAAO,WAAW;QACzC,IAAI,MAAM,SAAS,UAAU;IAElC,MAAM,aAAa,mBAAmB,EAAE,QAAQ,MAAM,OAAO,CAAQ;IACrE,IAAI,MAAM,SAAS,OAAO;KACxB,MAAM,cAAc,MAAM;KAC1B,OAAO,OAAO,MAAM,QAAQ,WAAW,IACnC,YAAY,KAAK,SAAS,WAAW,MAAM,GAAG,CAAC,IAC/C;IACN,OACE,OAAO,OAAO,WAAW,MAAM,MAAM,GAAG;GAE5C,OAAO,IAAI,MAAM,SAAS,OAAO,QAAQ;IACvC,OAAO,OAAO,MAAM,SAAS,MAAM,OAAO;KACxC,OAAO,MAAM;KACb,SAAS;KACT;IACF,CAAC;IACD,IAAI,OAAO,gBAAgB,MACzB,OAAO,OAAO,OAAO,IAAI,CAAC,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,4 +1,4 @@
1
- import { n as cleanupPlatformGlobals, r as installPlatformGlobals, t as RUNTIME_FLAG_KEY } from "../globals-CBZ0egXT.mjs";
1
+ import { n as cleanupPlatformGlobals, r as installPlatformGlobals, t as RUNTIME_FLAG_KEY } from "../globals-TfAVItuK.mjs";
2
2
  import * as globals from "globals";
3
3
 
4
4
  //#region src/vitest/environment.ts
@@ -3,6 +3,7 @@ import { MockAuthconnectionOptions, mockAuthconnection } from "./mocks/authconne
3
3
  import { MockFileOptions, mockFile } from "./mocks/file.mjs";
4
4
  import { MockIconvOptions, mockIconv } from "./mocks/iconv.mjs";
5
5
  import { MockIdpOptions, mockIdp } from "./mocks/idp.mjs";
6
+ import { MockLoggerOptions, mockLogger } from "./mocks/logger.mjs";
6
7
  import { MockSecretmanagerOptions, mockSecretmanager } from "./mocks/secretmanager.mjs";
7
8
  import { MockTailordbOptions, QueryBehavior, QueryMatch, QueryMatcher, mockTailordb } from "./mocks/tailordb.mjs";
8
9
  import { mockWorkflow } from "./mocks/workflow.mjs";
@@ -32,7 +33,8 @@ import { Plugin } from "vitest/config";
32
33
  *
33
34
  * 3. **Platform API mocks** (environment) — All platform APIs are auto-injected with
34
35
  * control objects: `mockTailordb`, `mockWorkflow`, `mockSecretmanager`,
35
- * `mockAuthconnection`, `mockIdp`, `mockFile`, `mockIconv`, `mockAigateway`. Each
36
+ * `mockAuthconnection`, `mockIdp`, `mockFile`, `mockIconv`, `mockAigateway`,
37
+ * `mockLogger`. Each
36
38
  * provides response configuration, call recording, and reset.
37
39
  *
38
40
  * 4. **Environment resolution** — Rewrites `environment: "tailor-runtime"` to the
@@ -42,8 +44,8 @@ import { Plugin } from "vitest/config";
42
44
  *
43
45
  * - **`process`** and **`require`** are NOT removed or blocked. Vitest's internal
44
46
  * runner depends on them. On the real Tailor Platform runtime, they do not exist.
45
- * - **Dynamic `import()`** of bundled files (via `createImportMain()`) bypasses
46
- * the transform hook since those files are loaded through Node.js native loader.
47
+ * - **Dynamic `import()`** of bundled files bypasses the transform hook since
48
+ * those files are loaded through Node.js native loader.
47
49
  * ## Options
48
50
  *
49
51
  * - **`config`** — Path to `tailor.config.ts`. Loads `defineSecretManager()` values
@@ -69,4 +71,4 @@ declare function tailorRuntime(options?: {
69
71
  config?: string;
70
72
  }): Plugin[];
71
73
  //#endregion
72
- export { type ExecutedQuery, type KyselyMock, type MockAigatewayOptions, type MockAuthconnectionOptions, type MockFileOptions, type MockIconvOptions, type MockIdpOptions, type MockSecretmanagerOptions, type MockTailordbOptions, type QueryBehavior, type QueryMatch, type QueryMatcher, type RunWorkflowLocallyOptions, createKyselyMock, mockAigateway, mockAuthconnection, mockFile, mockIconv, mockIdp, mockSecretmanager, mockTailordb, mockWorkflow, runWorkflowLocally, tailorRuntime };
74
+ export { type ExecutedQuery, type KyselyMock, type MockAigatewayOptions, type MockAuthconnectionOptions, type MockFileOptions, type MockIconvOptions, type MockIdpOptions, type MockLoggerOptions, type MockSecretmanagerOptions, type MockTailordbOptions, type QueryBehavior, type QueryMatch, type QueryMatcher, type RunWorkflowLocallyOptions, createKyselyMock, mockAigateway, mockAuthconnection, mockFile, mockIconv, mockIdp, mockLogger, mockSecretmanager, mockTailordb, mockWorkflow, runWorkflowLocally, tailorRuntime };