@tailor-platform/sdk 2.4.0 → 2.6.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 (252) hide show
  1. package/CHANGELOG.md +131 -0
  2. package/bin/tailor.mjs +3 -2
  3. package/dist/aigateway-DsWDjzk4.mjs +2 -0
  4. package/dist/{aigateway-DR4Kwuik.mjs.map → aigateway-DsWDjzk4.mjs.map} +1 -1
  5. package/dist/application-CNeOcaLc.mjs +1 -0
  6. package/dist/application-CmXOqTaK.mjs +192 -0
  7. package/dist/application-CmXOqTaK.mjs.map +1 -0
  8. package/dist/assert-WeXvmG4j.mjs +2 -0
  9. package/dist/{assert-DBxo8jPo.mjs.map → assert-WeXvmG4j.mjs.map} +1 -1
  10. package/dist/authconnection-CynFBIv8.mjs +2 -0
  11. package/dist/{authconnection-CZvi9ANm.mjs.map → authconnection-CynFBIv8.mjs.map} +1 -1
  12. package/dist/brand-C8nMKhJC.mjs +2 -0
  13. package/dist/{brand-Eo4pLXPJ.mjs.map → brand-C8nMKhJC.mjs.map} +1 -1
  14. package/dist/cli/commands/api/index.d.mts +1 -1
  15. package/dist/cli/commands/deploy/deploy.d.mts +2 -2
  16. package/dist/cli/commands/deploy/deployment-target.d.mts +2 -0
  17. package/dist/cli/commands/deploy/event-subscriptions.d.mts +3 -0
  18. package/dist/cli/commands/deploy/tailordb/apply.d.mts +3 -0
  19. package/dist/cli/commands/deploy/tailordb/index.d.mts +3 -10
  20. package/dist/cli/commands/deploy/tailordb/migration-validation.d.mts +5 -0
  21. package/dist/cli/commands/deploy/tailordb/plan.d.mts +8 -0
  22. package/dist/cli/commands/executor/jobs.d.mts +1 -1
  23. package/dist/cli/commands/executor/trigger.d.mts +1 -1
  24. package/dist/cli/commands/generate/seed/bundler.d.mts +2 -2
  25. package/dist/cli/commands/show.d.mts +1 -1
  26. package/dist/cli/commands/tailordb/migrate/diff-calculator.d.mts +11 -11
  27. package/dist/cli/commands/tailordb/migrate/generate.d.mts +4 -0
  28. package/dist/cli/commands/tailordb/migrate/rename-detection.d.mts +1 -1
  29. package/dist/cli/commands/tailordb/migrate/snapshot-comparison.d.mts +43 -0
  30. package/dist/cli/commands/tailordb/migrate/snapshot-files.d.mts +62 -0
  31. package/dist/cli/commands/tailordb/migrate/snapshot-local.d.mts +12 -0
  32. package/dist/cli/commands/tailordb/migrate/snapshot-migrations.d.mts +12 -0
  33. package/dist/cli/commands/tailordb/migrate/snapshot-remote.d.mts +1 -0
  34. package/dist/cli/commands/tailordb/migrate/snapshot-types.d.mts +3 -1
  35. package/dist/cli/commands/tailordb/migrate/snapshot.d.mts +5 -117
  36. package/dist/cli/commands/workflow/start.d.mts +1 -1
  37. package/dist/cli/commands/workspace/list.d.mts +1 -1
  38. package/dist/cli/lib.d.mts +12 -4
  39. package/dist/cli/lib.mjs +1 -9
  40. package/dist/cli/lib.mjs.map +1 -1
  41. package/dist/cli/main.d.mts +2 -0
  42. package/dist/cli/main.mjs +1170 -7754
  43. package/dist/cli/main.mjs.map +1 -1
  44. package/dist/cli/shared/args.d.mts +65 -1
  45. package/dist/cli/shared/command.d.mts +11 -0
  46. package/dist/cli/shared/context.d.mts +1 -1
  47. package/dist/cli/shared/logger.d.mts +64 -0
  48. package/dist/cli/shared/script-executor.d.mts +1 -1
  49. package/dist/cli/shared/seed-chunker.d.mts +5 -5
  50. package/dist/completion/zsh-worker.zsh +82 -9
  51. package/dist/configure/config/index.d.mts +1 -1
  52. package/dist/configure/config/types.d.mts +2 -2
  53. package/dist/configure/index.d.mts +48 -12
  54. package/dist/configure/index.mjs +1 -1267
  55. package/dist/configure/index.mjs.map +1 -1
  56. package/dist/configure/services/auth/types.d.mts +1 -1
  57. package/dist/configure/services/idp/types.d.mts +1 -1
  58. package/dist/configure/services/tailordb/schema.d.mts +22 -8
  59. package/dist/configure/services/tailordb/types.d.mts +2 -2
  60. package/dist/configure/services/workflow/execution-policy.d.mts +3 -3
  61. package/dist/configure/services/workflow/job.d.mts +12 -2
  62. package/dist/configure/types/field.types.d.mts +1 -1
  63. package/dist/configure/types/permission-operand.types.d.mts +1 -1
  64. package/dist/context-D0QjfxzD.mjs +2 -0
  65. package/dist/{context-DYQVYWqZ.mjs.map → context-D0QjfxzD.mjs.map} +1 -1
  66. package/dist/crashreport-BN28xp5B.mjs +42 -0
  67. package/dist/{crashreport-Q0pDAlrj.mjs.map → crashreport-BN28xp5B.mjs.map} +1 -1
  68. package/dist/crashreport-By23O2k-.mjs +1 -0
  69. package/dist/errors-DLsQ_-ol.mjs +2 -0
  70. package/dist/errors-DLsQ_-ol.mjs.map +1 -0
  71. package/dist/es-builtins-n3wBv4Sv.mjs +2 -0
  72. package/dist/es-builtins-n3wBv4Sv.mjs.map +1 -0
  73. package/dist/file-COPYfju_.mjs +2 -0
  74. package/dist/file-COPYfju_.mjs.map +1 -0
  75. package/dist/globals-CMHSnj4w.mjs +2 -0
  76. package/dist/{globals-B2nlxBrz.mjs.map → globals-CMHSnj4w.mjs.map} +1 -1
  77. package/dist/iconv-DlFMt2gW.mjs +2 -0
  78. package/dist/{iconv-QWaZh0TT.mjs.map → iconv-DlFMt2gW.mjs.map} +1 -1
  79. package/dist/idp-G_ojPBB5.mjs +2 -0
  80. package/dist/{idp-RA_swu-h.mjs.map → idp-G_ojPBB5.mjs.map} +1 -1
  81. package/dist/interceptor-DQg3cR_9.mjs +2 -0
  82. package/dist/{interceptor-e33JtsC-.mjs.map → interceptor-DQg3cR_9.mjs.map} +1 -1
  83. package/dist/kysely/index.mjs +1 -32
  84. package/dist/kysely/index.mjs.map +1 -1
  85. package/dist/kysely-type-BTi3BMtL.mjs +43 -0
  86. package/dist/kysely-type-BTi3BMtL.mjs.map +1 -0
  87. package/dist/logger-CCjs1DuH.mjs +9 -0
  88. package/dist/logger-CCjs1DuH.mjs.map +1 -0
  89. package/dist/logger-DP2BjQ93.mjs +2 -0
  90. package/dist/{logger-BtX0suGY.mjs.map → logger-DP2BjQ93.mjs.map} +1 -1
  91. package/dist/multiline-EyzjEwn9.mjs +3 -0
  92. package/dist/{multiline-sfHpTZZK.mjs.map → multiline-EyzjEwn9.mjs.map} +1 -1
  93. package/dist/node-builtins-oBl7EbyV.mjs +2 -0
  94. package/dist/{node-builtins-CmaL2Cbq.mjs.map → node-builtins-oBl7EbyV.mjs.map} +1 -1
  95. package/dist/package-json-C690ceex.mjs +2 -0
  96. package/dist/{package-json-8b0O9TlX.mjs.map → package-json-C690ceex.mjs.map} +1 -1
  97. package/dist/package-json-CmqhDJ__.mjs +1 -0
  98. package/dist/parser/service/tailordb/type-source.d.mts +5 -5
  99. package/dist/parser/service/tailordb/types.d.mts +4 -4
  100. package/dist/platform-serialize-DkiTdHOt.mjs +2 -0
  101. package/dist/{platform-serialize-RoRtBS0v.mjs.map → platform-serialize-DkiTdHOt.mjs.map} +1 -1
  102. package/dist/plugin/builtin/enum-constants/index.mjs +5 -114
  103. package/dist/plugin/builtin/enum-constants/index.mjs.map +1 -1
  104. package/dist/plugin/builtin/file-utils/index.mjs +22 -104
  105. package/dist/plugin/builtin/file-utils/index.mjs.map +1 -1
  106. package/dist/plugin/builtin/kysely-type/index.d.mts +8 -1
  107. package/dist/plugin/builtin/kysely-type/index.mjs +1 -275
  108. package/dist/plugin/builtin/seed/index.d.mts +5 -0
  109. package/dist/plugin/builtin/seed/index.mjs +1 -3
  110. package/dist/plugin/builtin/seed/seed-type-processor.d.mts +0 -2
  111. package/dist/plugin/{get-generated-type.d.mts → get-generated-table.d.mts} +5 -5
  112. package/dist/plugin/index.d.mts +3 -2
  113. package/dist/plugin/index.mjs +1 -251
  114. package/dist/plugin/index.mjs.map +1 -1
  115. package/dist/plugin/types.d.mts +30 -23
  116. package/dist/plugin/with-context.d.mts +3 -3
  117. package/dist/register-ts-hook-oDA2JLp2.mjs +640 -0
  118. package/dist/register-ts-hook-oDA2JLp2.mjs.map +1 -0
  119. package/dist/registry-HlEaGvl5.mjs +2 -0
  120. package/dist/{registry-BIGVUrMB.mjs.map → registry-HlEaGvl5.mjs.map} +1 -1
  121. package/dist/repl-editor-BG1aDOfH.mjs +2 -0
  122. package/dist/{repl-editor-F9LotMNx.mjs.map → repl-editor-BG1aDOfH.mjs.map} +1 -1
  123. package/dist/runtime/aigateway.mjs +1 -3
  124. package/dist/runtime/authconnection.mjs +1 -3
  125. package/dist/runtime/context.mjs +1 -3
  126. package/dist/runtime/file.d.mts +21 -21
  127. package/dist/runtime/file.mjs +1 -3
  128. package/dist/runtime/globals.mjs +1 -1
  129. package/dist/runtime/iconv.mjs +1 -3
  130. package/dist/runtime/idp.mjs +1 -3
  131. package/dist/runtime/index.mjs +1 -11
  132. package/dist/runtime/logger.mjs +1 -3
  133. package/dist/runtime/secretmanager.mjs +1 -3
  134. package/dist/runtime/types.d.mts +1 -1
  135. package/dist/runtime/workflow.mjs +1 -3
  136. package/dist/schema-AYG4OhXY.mjs +2 -0
  137. package/dist/schema-AYG4OhXY.mjs.map +1 -0
  138. package/dist/secret-file-C9wp_FCX.mjs +2 -0
  139. package/dist/{secret-file-C3J4Gy8r.mjs.map → secret-file-C9wp_FCX.mjs.map} +1 -1
  140. package/dist/secretmanager-5olfnI1b.mjs +2 -0
  141. package/dist/{secretmanager-IY4UvinW.mjs.map → secretmanager-5olfnI1b.mjs.map} +1 -1
  142. package/dist/secretmanager-vHQoXdQz.mjs +2 -0
  143. package/dist/{secretmanager-CYlpffsz.mjs.map → secretmanager-vHQoXdQz.mjs.map} +1 -1
  144. package/dist/seed/index.mjs +8 -244
  145. package/dist/seed/index.mjs.map +1 -1
  146. package/dist/seed-DwqRFdqP.mjs +207 -0
  147. package/dist/seed-DwqRFdqP.mjs.map +1 -0
  148. package/dist/service-CLPMoj9n.mjs +2 -0
  149. package/dist/{service-LTfp03ZZ.mjs.map → service-CLPMoj9n.mjs.map} +1 -1
  150. package/dist/service-D7iXk0BT.mjs +1 -0
  151. package/dist/service-YqDsHmlK.mjs +7 -0
  152. package/dist/service-YqDsHmlK.mjs.map +1 -0
  153. package/dist/service_pb-DGKCLuAs.mjs +2 -0
  154. package/dist/{service_pb-BEWj1pOV.mjs.map → service_pb-DGKCLuAs.mjs.map} +1 -1
  155. package/dist/service_pb-_aeFE-Nv.mjs +1 -0
  156. package/dist/shared/src/color.d.mts +5 -0
  157. package/dist/tailor-proto/src/tailor/v1/workspace_pb.d.mts +1 -1
  158. package/dist/telemetry-Bklv9kQY.mjs +2 -0
  159. package/dist/{telemetry-BRVdwh14.mjs.map → telemetry-Bklv9kQY.mjs.map} +1 -1
  160. package/dist/telemetry-DXHP3VVi.mjs +1 -0
  161. package/dist/type-source--ZNcV8RJ.mjs +2 -0
  162. package/dist/type-source--ZNcV8RJ.mjs.map +1 -0
  163. package/dist/types/executor.generated.d.mts +1 -1
  164. package/dist/user-agent-vdHYF3QL.mjs +2 -0
  165. package/dist/{user-agent-Bgsszb5I.mjs.map → user-agent-vdHYF3QL.mjs.map} +1 -1
  166. package/dist/utils/test/index.mjs +1 -109
  167. package/dist/utils/test/index.mjs.map +1 -1
  168. package/dist/vitest/environment.mjs +1 -41
  169. package/dist/vitest/environment.mjs.map +1 -1
  170. package/dist/vitest/index.mjs +1 -1986
  171. package/dist/vitest/index.mjs.map +1 -1
  172. package/dist/vitest/mocks/file.d.mts +8 -8
  173. package/dist/vitest/setup.mjs +1 -140
  174. package/dist/vitest/setup.mjs.map +1 -1
  175. package/dist/wait-point-invoker-eiP-IIux.mjs +2 -0
  176. package/dist/wait-point-invoker-eiP-IIux.mjs.map +1 -0
  177. package/dist/wait-point-registry-B-ESkTZX.mjs +2 -0
  178. package/dist/wait-point-registry-B-ESkTZX.mjs.map +1 -0
  179. package/dist/workflow-Cs9ISw6j.mjs +2 -0
  180. package/dist/{workflow-Bamae_Yc.mjs.map → workflow-Cs9ISw6j.mjs.map} +1 -1
  181. package/dist/workspace_resource_pb--GeYQPXu.mjs +2 -0
  182. package/dist/{workspace_resource_pb-HNIL_Vfj.mjs.map → workspace_resource_pb--GeYQPXu.mjs.map} +1 -1
  183. package/docs/cli/function.md +66 -6
  184. package/docs/cli/setup.md +24 -14
  185. package/docs/cli/tailordb.md +2 -0
  186. package/docs/cli-reference.md +9 -8
  187. package/docs/github-actions.md +14 -12
  188. package/docs/migration/v2.md +18 -2
  189. package/docs/migration/v3.md +121 -0
  190. package/docs/plugin/custom.md +130 -85
  191. package/docs/plugin/index.md +3 -3
  192. package/docs/services/tailordb-migration.md +21 -7
  193. package/docs/services/tailordb.md +9 -7
  194. package/docs/services/workflow.md +10 -9
  195. package/package.json +14 -13
  196. package/postinstall.mjs +1 -1
  197. package/dist/aigateway-DR4Kwuik.mjs +0 -9
  198. package/dist/application-C8a0UJ-z.mjs +0 -6071
  199. package/dist/application-C8a0UJ-z.mjs.map +0 -1
  200. package/dist/application-D4zOiLLa.mjs +0 -3
  201. package/dist/assert-DBxo8jPo.mjs +0 -9
  202. package/dist/authconnection-CZvi9ANm.mjs +0 -9
  203. package/dist/brand-Eo4pLXPJ.mjs +0 -36
  204. package/dist/context-DYQVYWqZ.mjs +0 -23
  205. package/dist/crashreport-Cd4TqfZq.mjs +0 -3
  206. package/dist/crashreport-Q0pDAlrj.mjs +0 -427
  207. package/dist/errors-Bxut5_Sy.mjs +0 -89
  208. package/dist/errors-Bxut5_Sy.mjs.map +0 -1
  209. package/dist/file-BUcmVIH2.mjs +0 -58
  210. package/dist/file-BUcmVIH2.mjs.map +0 -1
  211. package/dist/globals-B2nlxBrz.mjs +0 -126
  212. package/dist/iconv-QWaZh0TT.mjs +0 -38
  213. package/dist/idp-RA_swu-h.mjs +0 -82
  214. package/dist/interceptor-e33JtsC-.mjs +0 -33
  215. package/dist/logger-BtX0suGY.mjs +0 -48
  216. package/dist/logger-D0bEznPv.mjs +0 -362
  217. package/dist/logger-D0bEznPv.mjs.map +0 -1
  218. package/dist/multiline-sfHpTZZK.mjs +0 -38
  219. package/dist/node-builtins-CmaL2Cbq.mjs +0 -36
  220. package/dist/package-json-8b0O9TlX.mjs +0 -17
  221. package/dist/package-json-Cv2Z-TqQ.mjs +0 -3
  222. package/dist/platform-serialize-RoRtBS0v.mjs +0 -46
  223. package/dist/plugin/builtin/kysely-type/index.mjs.map +0 -1
  224. package/dist/plugin/builtin/seed/types.d.mts +0 -2
  225. package/dist/register-ts-hook-Vqjza10T.mjs +0 -25679
  226. package/dist/register-ts-hook-Vqjza10T.mjs.map +0 -1
  227. package/dist/registry-BIGVUrMB.mjs +0 -54
  228. package/dist/repl-editor-F9LotMNx.mjs +0 -252
  229. package/dist/schema-D4TC4BC3.mjs +0 -640
  230. package/dist/schema-D4TC4BC3.mjs.map +0 -1
  231. package/dist/secret-file-C3J4Gy8r.mjs +0 -64
  232. package/dist/secretmanager-CYlpffsz.mjs +0 -13
  233. package/dist/secretmanager-IY4UvinW.mjs +0 -131
  234. package/dist/seed-Cibjmtry.mjs +0 -489
  235. package/dist/seed-Cibjmtry.mjs.map +0 -1
  236. package/dist/service-2grcAOCJ.mjs +0 -898
  237. package/dist/service-2grcAOCJ.mjs.map +0 -1
  238. package/dist/service-CaBPNDIZ.mjs +0 -3
  239. package/dist/service-LTfp03ZZ.mjs +0 -133
  240. package/dist/service_pb-BEWj1pOV.mjs +0 -167
  241. package/dist/service_pb-BjlhvK9E.mjs +0 -3
  242. package/dist/telemetry-BRVdwh14.mjs +0 -84
  243. package/dist/telemetry-CkbkeJxl.mjs +0 -3
  244. package/dist/type-source-DH_LH20p.mjs +0 -13
  245. package/dist/type-source-DH_LH20p.mjs.map +0 -1
  246. package/dist/user-agent-Bgsszb5I.mjs +0 -28
  247. package/dist/wait-point-invoker-__oE88_P.mjs +0 -148
  248. package/dist/wait-point-invoker-__oE88_P.mjs.map +0 -1
  249. package/dist/wait-point-registry-TL99zotw.mjs +0 -47
  250. package/dist/wait-point-registry-TL99zotw.mjs.map +0 -1
  251. package/dist/workflow-Bamae_Yc.mjs +0 -34
  252. package/dist/workspace_resource_pb-HNIL_Vfj.mjs +0 -860
@@ -1,898 +0,0 @@
1
- import { n as isSdkBranded } from "./brand-Eo4pLXPJ.mjs";
2
- import { n as logger, r as styles } from "./logger-D0bEznPv.mjs";
3
- import * as path from "pathe";
4
- import { z } from "zod";
5
- import * as fs from "node:fs";
6
- import { pathToFileURL } from "node:url";
7
-
8
- //#region src/parser/service/common.ts
9
- const functionSchema = z.custom((val) => typeof val === "function");
10
-
11
- //#endregion
12
- //#region src/cli/shared/user-modules.ts
13
- const IMPORT_NONCE_PARAM = "tailorImportNonce";
14
- let runCounter = 0;
15
- /**
16
- * Start a fresh user-module run. Modules imported through
17
- * {@link importUserModule} after this call bypass the ESM cache entries of
18
- * earlier runs, so a repeated in-process run re-evaluates user code instead
19
- * of reusing stale modules.
20
- */
21
- function beginUserModuleRun() {
22
- runCounter += 1;
23
- }
24
- /**
25
- * Read the cache-busting nonce of the current user-module run.
26
- * @returns The nonce, or undefined when no run was started
27
- */
28
- function currentImportNonce() {
29
- return runCounter === 0 ? void 0 : String(runCounter);
30
- }
31
- /**
32
- * Import a user module (config, workflow, resolver, executor, ...) with the
33
- * current run's cache-busting nonce applied. Outside a run this is a plain
34
- * import.
35
- * @param filePath - Absolute path of the user module
36
- * @returns The imported module namespace
37
- */
38
- function importUserModule(filePath) {
39
- const url = pathToFileURL(filePath);
40
- const nonce = currentImportNonce();
41
- if (nonce) url.searchParams.set(IMPORT_NONCE_PARAM, nonce);
42
- return import(url.href);
43
- }
44
-
45
- //#endregion
46
- //#region src/cli/services/file-loader.ts
47
- const DEFAULT_IGNORE_PATTERNS = ["**/*.test.ts", "**/*.spec.ts"];
48
- const warnedFallbacks = /* @__PURE__ */ new Set();
49
- /**
50
- * Load files matching the given patterns, excluding files that match ignore patterns.
51
- * By default, test files (*.test.ts, *.spec.ts) are excluded unless ignores is explicitly specified.
52
- * @param config - Configuration with files patterns and optional ignores patterns
53
- * @param baseDir - Directory relative patterns are resolved against
54
- * @returns Array of absolute file paths
55
- */
56
- function loadFilesWithIgnores(config, baseDir) {
57
- if (config.files.length === 0) return [];
58
- const resolved = resolveFiles(config, baseDir);
59
- const allPatternsAbsolute = config.files.every((pattern) => path.isAbsolute(pattern));
60
- if (resolved.matchedAnyPattern || baseDir === process.cwd() || allPatternsAbsolute) return resolved.files;
61
- const fallbackKey = `${baseDir}\0${config.files.join("\0")}`;
62
- if (!warnedFallbacks.has(fallbackKey)) {
63
- warnedFallbacks.add(fallbackKey);
64
- logger.warn(`No files matched "${config.files.join(", ")}" relative to "${baseDir}"; falling back to process.cwd(). Update this config's file patterns to be relative to its own directory before v2, when this fallback will be removed.`);
65
- }
66
- return resolveFiles(config, process.cwd()).files;
67
- }
68
- function resolveFiles(config, baseDir) {
69
- const isDefaultIgnores = config.ignores === void 0;
70
- const ignorePatterns = config.ignores ?? DEFAULT_IGNORE_PATTERNS;
71
- const resolvedIgnorePatterns = isDefaultIgnores ? ignorePatterns : ignorePatterns.map((ignorePattern) => path.resolve(baseDir, ignorePattern));
72
- const files = [];
73
- let matchedAnyPattern = false;
74
- for (const pattern of config.files) {
75
- const absolutePattern = path.resolve(baseDir, pattern);
76
- try {
77
- const matchedFiles = fs.globSync(absolutePattern);
78
- if (matchedFiles.length > 0) matchedAnyPattern = true;
79
- const filteredFiles = matchedFiles.filter((file) => !resolvedIgnorePatterns.some((ignorePattern) => path.matchesGlob(file, ignorePattern)));
80
- files.push(...filteredFiles);
81
- } catch (error) {
82
- matchedAnyPattern = true;
83
- logger.warn(`Failed to glob pattern "${pattern}": ${String(error)}`);
84
- }
85
- }
86
- return {
87
- files,
88
- matchedAnyPattern
89
- };
90
- }
91
-
92
- //#endregion
93
- //#region src/parser/service/tailordb/relation.ts
94
- const relationTypes = {
95
- "1-1": "1-1",
96
- oneToOne: "1-1",
97
- "n-1": "n-1",
98
- manyToOne: "n-1",
99
- "N-1": "n-1",
100
- keyOnly: "keyOnly"
101
- };
102
- const relationTypesKeys = Object.keys(relationTypes);
103
- function fieldRef(context) {
104
- return `Field "${context.fieldName}" on table "${context.typeName}"`;
105
- }
106
- /**
107
- * Validate relation configuration.
108
- * @param rawRelation - Raw relation configuration from TailorDB table definition
109
- * @param context - Context information for the relation (table name, field name, all type names)
110
- */
111
- function validateRelationConfig(rawRelation, context) {
112
- if (!rawRelation.type) throw new Error(`${fieldRef(context)} has a relation but is missing the required 'type' property. Valid values: ${relationTypesKeys.join(", ")}.`);
113
- if (!(rawRelation.type in relationTypes)) throw new Error(`${fieldRef(context)} has invalid relation type '${rawRelation.type}'. Valid values: ${relationTypesKeys.join(", ")}.`);
114
- if (rawRelation.toward.type !== "self" && !context.allTypeNames.has(rawRelation.toward.type)) throw new Error(`${fieldRef(context)} references unknown table "${rawRelation.toward.type}".`);
115
- }
116
- /**
117
- * Process raw relation config and compute derived metadata values.
118
- * @param rawRelation - Raw relation configuration
119
- * @param context - Context information for the relation
120
- * @param isArrayField - Whether the target field is an array field
121
- * @returns Computed relation metadata to apply to field config
122
- */
123
- function processRelationMetadata(rawRelation, context, isArrayField = false) {
124
- const isUnique = relationTypes[rawRelation.type] === "1-1";
125
- const key = rawRelation.toward.key ?? "id";
126
- const targetTypeName = rawRelation.toward.type === "self" ? context.typeName : rawRelation.toward.type;
127
- const shouldSetIndex = !isArrayField;
128
- const shouldSetUnique = !isArrayField && isUnique;
129
- return {
130
- index: shouldSetIndex,
131
- foreignKey: true,
132
- relationType: rawRelation.type,
133
- unique: shouldSetUnique,
134
- foreignKeyType: targetTypeName,
135
- foreignKeyField: key
136
- };
137
- }
138
- /**
139
- * Build relation info for creating forward/backward relationships.
140
- * Returns undefined for keyOnly relations.
141
- * @param rawRelation - Raw relation configuration
142
- * @param context - Context information for the relation
143
- * @returns Relation information or undefined for keyOnly relations
144
- */
145
- function buildRelationInfo(rawRelation, context) {
146
- if (rawRelation.type === "keyOnly") return;
147
- const isUnique = relationTypes[rawRelation.type] === "1-1";
148
- const key = rawRelation.toward.key ?? "id";
149
- const targetTypeName = rawRelation.toward.type === "self" ? context.typeName : rawRelation.toward.type;
150
- let forwardName = rawRelation.toward.as;
151
- if (!forwardName) forwardName = context.fieldName.replace(/(ID|Id|id)$/u, "");
152
- return {
153
- targetType: targetTypeName,
154
- forwardName,
155
- backwardName: rawRelation.backward ?? "",
156
- key,
157
- unique: isUnique
158
- };
159
- }
160
- /**
161
- * Apply processed relation metadata to field config.
162
- * @param fieldConfig - Original operator field configuration
163
- * @param metadata - Processed relation metadata to apply
164
- * @returns Field config with relation metadata applied
165
- */
166
- function applyRelationMetadataToFieldConfig(fieldConfig, metadata) {
167
- return {
168
- ...fieldConfig,
169
- index: metadata.index,
170
- foreignKey: metadata.foreignKey,
171
- unique: metadata.unique,
172
- foreignKeyType: metadata.foreignKeyType,
173
- foreignKeyField: metadata.foreignKeyField
174
- };
175
- }
176
-
177
- //#endregion
178
- //#region src/parser/service/tailordb/schema.ts
179
- /**
180
- * Normalize GqlOperationsConfig (alias or object) to GqlOperations object.
181
- * "query" alias expands to read-only mode: { create: false, update: false, delete: false, read: true }
182
- * @param config - The config to normalize
183
- * @returns The normalized GqlOperations object
184
- */
185
- function normalizeGqlOperations(config) {
186
- if (config === "query") return {
187
- create: false,
188
- update: false,
189
- delete: false,
190
- read: true
191
- };
192
- return config;
193
- }
194
- /**
195
- * Zod schema for GqlOperations configuration with normalization transform.
196
- * Accepts "query" alias or detailed object, normalizes to GqlOperations object.
197
- */
198
- const GqlOperationsSchema = z.union([z.literal("query"), z.strictObject({
199
- create: z.boolean().optional().describe("Enable create mutation (default: true)"),
200
- update: z.boolean().optional().describe("Enable update mutation (default: true)"),
201
- delete: z.boolean().optional().describe("Enable delete mutation (default: true)"),
202
- read: z.boolean().optional().describe("Enable read queries - get, list, aggregation (default: true)")
203
- })]).describe("Configuration for GraphQL operations on a TailorDB table.\nAll operations are enabled by default (undefined or true = enabled, false = disabled).").transform((val) => normalizeGqlOperations(val));
204
- const TailorFieldTypeSchema$1 = z.enum([
205
- "uuid",
206
- "string",
207
- "boolean",
208
- "integer",
209
- "float",
210
- "decimal",
211
- "enum",
212
- "date",
213
- "datetime",
214
- "time",
215
- "nested"
216
- ]);
217
- const AllowedValueSchema$1 = z.strictObject({
218
- value: z.string(),
219
- description: z.string().optional()
220
- });
221
- const DBFieldMetadataSchema = z.strictObject({
222
- required: z.boolean().optional().describe("Whether the field is required"),
223
- array: z.boolean().optional().describe("Whether the field is an array"),
224
- description: z.string().optional().describe("Field description"),
225
- typeName: z.string().optional().describe("Type name for nested or enum fields"),
226
- allowedValues: z.array(AllowedValueSchema$1).optional().describe("Allowed values for enum fields"),
227
- index: z.boolean().optional().describe("Whether the field is indexed for faster queries"),
228
- unique: z.boolean().optional().describe("Whether the field value must be unique"),
229
- vector: z.boolean().optional().describe("Whether the field is a vector field for similarity search"),
230
- foreignKey: z.boolean().optional().describe("Whether the field is a foreign key"),
231
- foreignKeyType: z.string().optional().describe("Target table name for foreign key relations"),
232
- foreignKeyField: z.string().optional().describe("Target field name for foreign key relations"),
233
- hooks: z.strictObject({
234
- create: functionSchema.optional().describe("Hook function called on record creation"),
235
- update: functionSchema.optional().describe("Hook function called on record update")
236
- }).optional().describe("Lifecycle hooks for the field"),
237
- validate: z.array(functionSchema).optional().describe("Validation functions for the field"),
238
- serial: z.strictObject({
239
- start: z.number().describe("Starting value for the serial sequence"),
240
- maxValue: z.number().optional().describe("Maximum value for the serial sequence"),
241
- format: z.string().optional().describe("Format string for serial value (string type only)")
242
- }).optional().describe("Serial (auto-increment) configuration"),
243
- scale: z.number().int().min(0).max(12).optional().describe("Decimal scale (number of digits after decimal point, 0-12)"),
244
- default: z.unknown().optional().describe("Default value for the field on create")
245
- });
246
- const RelationTypeSchema = z.enum(relationTypesKeys);
247
- const RawRelationConfigSchema = z.strictObject({
248
- type: RelationTypeSchema.describe("Relation cardinality type"),
249
- toward: z.strictObject({
250
- type: z.string().describe("Target table name, or 'self' for self-relations"),
251
- as: z.string().optional().describe("Custom forward relation name"),
252
- key: z.string().optional().describe("Target field to join on (default: 'id')")
253
- }),
254
- backward: z.string().optional().describe("Backward relation name on the target table")
255
- });
256
- const TailorDBFieldSchema = z.lazy(() => z.object({
257
- type: TailorFieldTypeSchema$1,
258
- fields: z.record(z.string(), TailorDBFieldSchema).optional(),
259
- metadata: DBFieldMetadataSchema,
260
- rawRelation: RawRelationConfigSchema.optional()
261
- }));
262
- /**
263
- * Schema for TailorDB table settings.
264
- * Normalizes gqlOperations from alias ("query") to object format.
265
- */
266
- const TailorDBTypeSettingsSchema = z.strictObject({
267
- pluralForm: z.string().optional().describe("Custom plural form of the table name for GraphQL"),
268
- aggregation: z.boolean().optional().describe("Enable aggregation queries for this table"),
269
- bulkUpsert: z.boolean().optional().describe("Enable bulk upsert mutation for this table"),
270
- gqlOperations: GqlOperationsSchema.optional().describe("Configure GraphQL operations for this table. Use \"query\" for read-only mode, or an object for granular control."),
271
- publishEvents: z.boolean().optional().describe("Enable publishing events for this table.\nWhen enabled, record creation/update/deletion events are published.\nIf not specified, this is automatically set to true when an executor uses this table\nwith recordCreated/recordUpdated/recordDeleted triggers. If explicitly set to false\nwhile an executor uses this table, an error will be thrown during apply.")
272
- });
273
- const GQL_PERMISSION_INVALID_OPERAND_MESSAGE = "operand is not supported in gqlPermission. Use permission() for record-level conditions.";
274
- const GqlPermissionOperandSchema = z.union([
275
- z.strictObject({ user: z.string() }),
276
- z.string(),
277
- z.boolean(),
278
- z.array(z.string()),
279
- z.array(z.boolean())
280
- ], { error: (issue) => {
281
- if (typeof issue.input === "object" && issue.input !== null) {
282
- const keys = Object.keys(issue.input);
283
- if (keys.length === 1) return `"${keys[0]}" ${GQL_PERMISSION_INVALID_OPERAND_MESSAGE}`;
284
- return "Operand object must have exactly 1 key";
285
- }
286
- return "Invalid operand in gqlPermission";
287
- } });
288
- const RecordPermissionOperandSchema = z.union([
289
- GqlPermissionOperandSchema,
290
- z.strictObject({ record: z.string() }),
291
- z.strictObject({ oldRecord: z.string() }),
292
- z.strictObject({ newRecord: z.string() })
293
- ]);
294
- const PermissionOperatorSchema = z.enum([
295
- "=",
296
- "!=",
297
- "in",
298
- "not in",
299
- "hasAny",
300
- "not hasAny"
301
- ]);
302
- const RecordPermissionConditionSchema = z.tuple([
303
- RecordPermissionOperandSchema,
304
- PermissionOperatorSchema,
305
- RecordPermissionOperandSchema
306
- ]).readonly();
307
- const GqlPermissionConditionSchema = z.tuple([
308
- GqlPermissionOperandSchema,
309
- PermissionOperatorSchema,
310
- GqlPermissionOperandSchema
311
- ]).readonly();
312
- const ActionPermissionSchema = z.union([
313
- z.strictObject({
314
- conditions: z.union([RecordPermissionConditionSchema, z.array(RecordPermissionConditionSchema).readonly()]),
315
- description: z.string().optional(),
316
- permit: z.boolean().optional()
317
- }),
318
- z.tuple([
319
- RecordPermissionOperandSchema,
320
- PermissionOperatorSchema,
321
- RecordPermissionOperandSchema
322
- ]).readonly(),
323
- z.tuple([
324
- RecordPermissionOperandSchema,
325
- PermissionOperatorSchema,
326
- RecordPermissionOperandSchema,
327
- z.boolean()
328
- ]).readonly(),
329
- z.array(z.union([RecordPermissionConditionSchema, z.boolean()])).refine((arr) => {
330
- const boolIndex = arr.findIndex((item) => typeof item === "boolean");
331
- return boolIndex === -1 || boolIndex === arr.length - 1;
332
- }, { message: "Boolean permit flag must only appear at the end" }).readonly()
333
- ]);
334
- const GqlPermissionActionSchema = z.enum([
335
- "read",
336
- "create",
337
- "update",
338
- "delete",
339
- "aggregate",
340
- "bulkUpsert"
341
- ]);
342
- const GqlPermissionPolicySchema = z.strictObject({
343
- conditions: z.array(GqlPermissionConditionSchema).readonly(),
344
- actions: z.union([z.literal("all"), z.array(GqlPermissionActionSchema).readonly()]),
345
- permit: z.boolean().optional(),
346
- description: z.string().optional()
347
- });
348
- const RawPermissionsSchema = z.strictObject({
349
- record: z.strictObject({
350
- create: z.array(ActionPermissionSchema).readonly(),
351
- read: z.array(ActionPermissionSchema).readonly(),
352
- update: z.array(ActionPermissionSchema).readonly(),
353
- delete: z.array(ActionPermissionSchema).readonly()
354
- }).optional(),
355
- gql: z.array(GqlPermissionPolicySchema).readonly().optional()
356
- });
357
- const TailorDBTypeSchema = z.strictObject({
358
- name: z.string(),
359
- fields: z.record(z.string(), TailorDBFieldSchema),
360
- metadata: z.object({
361
- name: z.string(),
362
- description: z.string().optional(),
363
- settings: TailorDBTypeSettingsSchema.optional(),
364
- permissions: RawPermissionsSchema,
365
- files: z.record(z.string(), z.string()),
366
- indexes: z.record(z.string(), z.strictObject({
367
- fields: z.array(z.string()),
368
- unique: z.boolean().optional()
369
- })).optional(),
370
- typeHook: z.strictObject({
371
- create: functionSchema.optional(),
372
- update: functionSchema.optional()
373
- }).optional(),
374
- typeValidate: functionSchema.optional()
375
- }).strict()
376
- });
377
- const TailorDBMigrationConfigSchema = z.strictObject({
378
- directory: z.string().describe("Directory containing migration files"),
379
- machineUser: z.string().optional().describe("Machine user name for migration execution")
380
- });
381
- /**
382
- * Schema for TailorDB service configuration.
383
- * Normalizes gqlOperations from alias ("query") to object format.
384
- */
385
- const TailorDBServiceConfigSchema = z.strictObject({
386
- files: z.array(z.string()).describe("Glob patterns for TailorDB table definition files"),
387
- ignores: z.array(z.string()).optional().describe("Glob patterns to exclude from table discovery"),
388
- migration: TailorDBMigrationConfigSchema.optional().describe("Migration configuration"),
389
- gqlOperations: GqlOperationsSchema.optional().describe("Default GraphQL operations for all tables in this service")
390
- });
391
-
392
- //#endregion
393
- //#region src/parser/service/tailordb/builder-helpers.ts
394
- const TAILORDB_TYPE_SCHEMA_KEYS = TailorDBTypeSchema.keyof().options;
395
- function stripTailorDBTypeBuilderHelpers(type) {
396
- if (!isSdkBranded(type, "tailordb-type")) return type;
397
- const config = {};
398
- const input = type;
399
- for (const key of TAILORDB_TYPE_SCHEMA_KEYS) if (Object.prototype.hasOwnProperty.call(input, key)) config[key] = input[key];
400
- return config;
401
- }
402
-
403
- //#endregion
404
- //#region src/parser/service/auth-connection/schema.ts
405
- const AuthConnectionOAuth2ConfigSchema = z.strictObject({
406
- providerUrl: z.string().describe("OAuth2 provider URL"),
407
- issuerUrl: z.string().describe("OAuth2 issuer URL"),
408
- clientId: z.string().describe("OAuth2 client ID"),
409
- clientSecret: z.string().describe("OAuth2 client secret"),
410
- authUrl: z.string().optional().describe("OAuth2 authorization endpoint override"),
411
- tokenUrl: z.string().optional().describe("OAuth2 token endpoint override")
412
- });
413
- const AuthConnectionConfigSchema = AuthConnectionOAuth2ConfigSchema.extend({ type: z.literal("oauth2").describe("Connection type") });
414
-
415
- //#endregion
416
- //#region src/parser/service/field/schema.ts
417
- const TailorFieldTypeSchema = z.enum([
418
- "uuid",
419
- "string",
420
- "boolean",
421
- "integer",
422
- "float",
423
- "decimal",
424
- "enum",
425
- "date",
426
- "datetime",
427
- "time",
428
- "nested"
429
- ]);
430
- const AllowedValueSchema = z.strictObject({
431
- value: z.string().describe("The allowed value"),
432
- description: z.string().optional().describe("Description of the allowed value")
433
- });
434
- const FieldMetadataSchema = z.strictObject({
435
- required: z.boolean().optional().describe("Whether the field is required"),
436
- array: z.boolean().optional().describe("Whether the field is an array"),
437
- description: z.string().optional().describe("Field description"),
438
- allowedValues: z.array(AllowedValueSchema).optional().describe("Allowed values for enum fields"),
439
- hooks: z.strictObject({
440
- create: functionSchema.optional().describe("Hook function called on creation"),
441
- update: functionSchema.optional().describe("Hook function called on update")
442
- }).optional().describe("Lifecycle hooks"),
443
- validate: z.array(functionSchema).optional().describe("Validation functions for the field"),
444
- typeName: z.string().optional().describe("Type name for nested or enum fields"),
445
- default: z.unknown().optional().describe("Default value for the field on create")
446
- });
447
- const TailorFieldSchema = z.object({
448
- type: TailorFieldTypeSchema.describe("Field data type"),
449
- metadata: FieldMetadataSchema.describe("Field metadata configuration"),
450
- get fields() {
451
- return z.record(z.string(), TailorFieldSchema);
452
- }
453
- });
454
-
455
- //#endregion
456
- //#region src/parser/service/auth/schema.ts
457
- const AuthInvokerObjectSchema = z.strictObject({
458
- namespace: z.string().describe("Auth namespace"),
459
- machineUserName: z.string().describe("Machine user name for authentication")
460
- });
461
- const AuthInvokerSchema = z.union([z.string().describe("Machine user name (namespace auto-resolved from auth service)"), AuthInvokerObjectSchema]);
462
- const secretValueSchema = z.strictObject({
463
- vaultName: z.string().describe("Vault name containing the secret"),
464
- secretKey: z.string().describe("Key of the secret in the vault")
465
- });
466
- const OIDCSchema = z.strictObject({
467
- name: z.string().describe("Identity provider name"),
468
- kind: z.literal("OIDC"),
469
- clientID: z.string().describe("OAuth2 client ID"),
470
- clientSecret: secretValueSchema.describe("OAuth2 client secret"),
471
- providerURL: z.string().describe("OIDC provider URL"),
472
- issuerURL: z.string().optional().describe("OIDC issuer URL (defaults to providerURL)"),
473
- usernameClaim: z.string().optional().describe("JWT claim to use as username")
474
- });
475
- const SAMLSchema = z.strictObject({
476
- name: z.string().describe("Identity provider name"),
477
- kind: z.literal("SAML"),
478
- enableSignRequest: z.boolean().default(false).describe("Enable signing of SAML requests"),
479
- metadataURL: z.string().optional().describe("URL to fetch SAML metadata (mutually exclusive with rawMetadata)"),
480
- rawMetadata: z.string().optional().describe("Raw SAML metadata XML (mutually exclusive with metadataURL)"),
481
- defaultRedirectURL: z.string().optional().describe("URL to redirect to when SAML ACS receives a response with an empty RelayState.")
482
- }).refine((value) => {
483
- return value.metadataURL !== void 0 !== (value.rawMetadata !== void 0);
484
- }, "Provide either metadataURL or rawMetadata");
485
- const IDTokenSchema = z.strictObject({
486
- name: z.string().describe("Identity provider name"),
487
- kind: z.literal("IDToken"),
488
- providerURL: z.string().describe("ID token provider URL"),
489
- issuerURL: z.string().optional().describe("ID token issuer URL"),
490
- clientID: z.string().describe("Client ID for ID token validation"),
491
- usernameClaim: z.string().optional().describe("JWT claim to use as username")
492
- });
493
- const BuiltinIdPSchema = z.strictObject({
494
- name: z.string().describe("Identity provider name"),
495
- kind: z.literal("BuiltInIdP"),
496
- namespace: z.string().describe("IdP namespace"),
497
- clientName: z.string().describe("OAuth2 client name in the IdP")
498
- });
499
- const IdProviderSchema = z.discriminatedUnion("kind", [
500
- OIDCSchema,
501
- SAMLSchema,
502
- IDTokenSchema,
503
- BuiltinIdPSchema
504
- ]);
505
- const OAuth2ClientGrantTypeSchema = z.union([z.literal("authorization_code"), z.literal("refresh_token")]).describe("OAuth2 grant type");
506
- const OAuth2ClientSchema = z.strictObject({
507
- description: z.string().optional().describe("Client description"),
508
- grantTypes: z.array(OAuth2ClientGrantTypeSchema).default(["authorization_code", "refresh_token"]).describe("Allowed OAuth2 grant types"),
509
- redirectURIs: z.array(z.union([
510
- z.templateLiteral(["https://", z.string()]),
511
- z.templateLiteral(["http://", z.string()]),
512
- z.templateLiteral([z.string(), ":url"]),
513
- z.templateLiteral([
514
- z.string(),
515
- ":url/",
516
- z.string()
517
- ])
518
- ])).describe("Allowed redirect URIs"),
519
- clientType: z.union([
520
- z.literal("confidential"),
521
- z.literal("public"),
522
- z.literal("browser")
523
- ]).optional().describe("OAuth2 client type"),
524
- accessTokenLifetimeSeconds: z.number().int().min(60, "Minimum access token lifetime is 60 seconds").max(86400, "Maximum access token lifetime is 1 day (86400 seconds)").optional().describe("Access token lifetime in seconds (60-86400)").transform((val) => val ? {
525
- seconds: BigInt(val),
526
- nanos: 0
527
- } : void 0),
528
- refreshTokenLifetimeSeconds: z.number().int().min(60, "Minimum refresh token lifetime is 60 seconds").max(604800, "Maximum refresh token lifetime is 7 days (604800 seconds)").optional().describe("Refresh token lifetime in seconds (60-604800)").transform((val) => val ? {
529
- seconds: BigInt(val),
530
- nanos: 0
531
- } : void 0),
532
- requireDpop: z.boolean().optional().describe("Require DPoP (Demonstrating Proof-of-Possession) for token requests")
533
- }).refine((data) => !(data.clientType === "browser" && data.requireDpop === true), {
534
- message: "requireDpop cannot be set to true for browser clients as they don't support DPoP",
535
- path: ["requireDpop"]
536
- });
537
- const SCIMAuthorizationSchema = z.strictObject({
538
- type: z.union([z.literal("oauth2"), z.literal("bearer")]).describe("SCIM authorization type"),
539
- bearerSecret: secretValueSchema.optional().describe("Bearer token secret (required for bearer type)")
540
- });
541
- const SCIMAttributeTypeSchema = z.union([
542
- z.literal("string"),
543
- z.literal("number"),
544
- z.literal("boolean"),
545
- z.literal("datetime"),
546
- z.literal("complex")
547
- ]).describe("SCIM attribute data type");
548
- const SCIMAttributeSchema = z.strictObject({
549
- type: SCIMAttributeTypeSchema.describe("Attribute data type"),
550
- name: z.string().describe("Attribute name"),
551
- description: z.string().optional().describe("Attribute description"),
552
- mutability: z.union([
553
- z.literal("readOnly"),
554
- z.literal("readWrite"),
555
- z.literal("writeOnly")
556
- ]).optional().describe("Attribute mutability"),
557
- required: z.boolean().optional().describe("Whether the attribute is required"),
558
- multiValued: z.boolean().optional().describe("Whether the attribute can have multiple values"),
559
- uniqueness: z.union([
560
- z.literal("none"),
561
- z.literal("server"),
562
- z.literal("global")
563
- ]).optional().describe("Uniqueness constraint"),
564
- canonicalValues: z.array(z.string()).nullable().optional().describe("List of canonical values"),
565
- get subAttributes() {
566
- return z.array(SCIMAttributeSchema).nullable().optional();
567
- }
568
- });
569
- const SCIMSchemaSchema = z.strictObject({
570
- name: z.string().describe("SCIM schema name"),
571
- attributes: z.array(SCIMAttributeSchema).describe("Schema attributes")
572
- });
573
- const SCIMAttributeMappingSchema = z.strictObject({
574
- tailorDBField: z.string().describe("TailorDB field name to map to"),
575
- scimPath: z.string().describe("SCIM attribute path")
576
- });
577
- const SCIMResourceSchema = z.strictObject({
578
- name: z.string().describe("SCIM resource name"),
579
- tailorDBNamespace: z.string().describe("TailorDB namespace for the resource"),
580
- tailorDBType: z.string().describe("TailorDB table name for the resource"),
581
- coreSchema: SCIMSchemaSchema.describe("Core SCIM schema definition"),
582
- attributeMapping: z.array(SCIMAttributeMappingSchema).describe("Attribute mapping configuration")
583
- });
584
- const SCIMSchema = z.strictObject({
585
- machineUserName: z.string().describe("Machine user name for SCIM operations"),
586
- authorization: SCIMAuthorizationSchema.describe("SCIM authorization configuration"),
587
- resources: z.array(SCIMResourceSchema).describe("SCIM resource definitions")
588
- });
589
- const TenantProviderSchema = z.strictObject({
590
- namespace: z.string().describe("TailorDB namespace for the tenant table"),
591
- type: z.string().describe("TailorDB table name for tenants"),
592
- signatureField: z.string().describe("Field used as the tenant signature")
593
- });
594
- const UserProfileSchema = z.strictObject({
595
- namespace: z.string().optional().describe("TailorDB namespace where the user table is defined"),
596
- type: z.custom().transform(stripTailorDBTypeBuilderHelpers).pipe(TailorDBTypeSchema),
597
- usernameField: z.string(),
598
- attributes: z.record(z.string(), z.literal(true)).optional(),
599
- attributeList: z.array(z.string()).optional()
600
- });
601
- const ValueOperandSchema = z.union([
602
- z.string(),
603
- z.boolean(),
604
- z.array(z.string()),
605
- z.array(z.boolean())
606
- ]);
607
- const MachineUserSchema = z.strictObject({
608
- attributes: z.record(z.string(), ValueOperandSchema.nullish()).transform((attributes) => Object.fromEntries(Object.entries(attributes).filter((entry) => entry[1] != null))).optional(),
609
- attributeList: z.array(z.uuid()).optional()
610
- });
611
- const BeforeLoginHookSchema = z.strictObject({
612
- handler: z.function(),
613
- invoker: z.string()
614
- });
615
- const AuthConfigBaseSchema = z.strictObject({
616
- name: z.string().describe("Auth service name"),
617
- hooks: z.strictObject({ beforeLogin: BeforeLoginHookSchema.optional().describe("Before login auth hook") }).optional().describe("Auth hooks"),
618
- machineUsers: z.record(z.string(), MachineUserSchema).optional().describe("Machine user definitions"),
619
- oauth2Clients: z.record(z.string(), OAuth2ClientSchema).optional().describe("OAuth2 client definitions"),
620
- idProvider: IdProviderSchema.optional().describe("Identity provider configuration"),
621
- scim: SCIMSchema.optional().describe("SCIM provisioning configuration"),
622
- tenantProvider: TenantProviderSchema.optional().describe("Multi-tenant provider configuration"),
623
- connections: z.record(z.string(), AuthConnectionConfigSchema).optional().describe("Auth connection definitions for external OAuth2 providers"),
624
- publishSessionEvents: z.boolean().optional().describe("Enable publishing session events")
625
- });
626
- const AuthConfigSchema = z.xor([AuthConfigBaseSchema.extend({
627
- userProfile: UserProfileSchema.optional().describe("User profile configuration"),
628
- machineUserAttributes: z.undefined().optional()
629
- }), AuthConfigBaseSchema.extend({
630
- userProfile: z.undefined().optional(),
631
- machineUserAttributes: z.record(z.string(), TailorFieldSchema).describe("Machine user attribute fields")
632
- })], { error: (iss) => {
633
- if (iss.code !== "invalid_union") return void 0;
634
- if (iss.errors.length < 2) return void 0;
635
- if (iss.errors.every((variantErrors) => variantErrors.every((e) => e.path.length === 1 && (e.path[0] === "userProfile" || e.path[0] === "machineUserAttributes")))) return "Specify either `userProfile` or `machineUserAttributes`, not both.";
636
- } }).brand("AuthConfig");
637
-
638
- //#endregion
639
- //#region src/parser/service/executor/schema.ts
640
- const TailorDBTriggerSchema = z.strictObject({
641
- kind: z.literal("tailordb").describe("TailorDB record event trigger"),
642
- events: z.array(z.enum([
643
- "tailordb.type_record.created",
644
- "tailordb.type_record.updated",
645
- "tailordb.type_record.deleted"
646
- ])).min(1).transform((arr) => [...new Set(arr)]).describe("TailorDB event types to trigger on"),
647
- typeName: z.string().describe("TailorDB table name to watch for events"),
648
- condition: functionSchema.optional().describe("Condition function to filter events")
649
- });
650
- const ResolverExecutedTriggerSchema = z.strictObject({
651
- kind: z.literal("resolverExecuted"),
652
- resolverName: z.string().describe("Name of the resolver to trigger on"),
653
- condition: functionSchema.optional().describe("Condition function to filter events")
654
- });
655
- const ScheduleTriggerSchema = z.strictObject({
656
- kind: z.literal("schedule"),
657
- cron: z.string().describe("CRON expression for the schedule"),
658
- timezone: z.string().optional().default("UTC").describe("Timezone for the CRON schedule (default: UTC)")
659
- });
660
- const IncomingWebhookTriggerResponseSchema = z.strictObject({
661
- body: functionSchema.optional().describe("Function returning the response body"),
662
- statusCode: z.number().int().optional().describe("HTTP status code for the response")
663
- });
664
- const IncomingWebhookTriggerSchema = z.strictObject({
665
- kind: z.literal("incomingWebhook"),
666
- response: IncomingWebhookTriggerResponseSchema.optional().describe("Response configuration")
667
- });
668
- const IdpUserTriggerSchema = z.strictObject({
669
- kind: z.literal("idpUser").describe("IdP user event trigger"),
670
- events: z.array(z.enum([
671
- "idp.user.created",
672
- "idp.user.updated",
673
- "idp.user.deleted"
674
- ])).min(1).transform((arr) => [...new Set(arr)]).describe("IdP user event types to trigger on"),
675
- idp: z.string().optional().describe("IdP namespace name to subscribe to. If omitted, the project's only IdP is used; throws when multiple IdPs exist.")
676
- });
677
- const AuthAccessTokenTriggerSchema = z.strictObject({
678
- kind: z.literal("authAccessToken").describe("Auth access token event trigger"),
679
- events: z.array(z.enum([
680
- "auth.access_token.issued",
681
- "auth.access_token.refreshed",
682
- "auth.access_token.revoked"
683
- ])).min(1).transform((arr) => [...new Set(arr)]).describe("Auth access token event types to trigger on")
684
- });
685
- const workflowNameSchema = z.string().refine((value) => value.trim().length > 0, "Workflow name cannot be blank").describe("Workflow name to subscribe to.");
686
- const WorkflowExecutionTriggerSchema = z.strictObject({
687
- kind: z.literal("workflowExecution").describe("Workflow execution event trigger"),
688
- events: z.array(z.enum([
689
- "workflow.workflow_execution.started",
690
- "workflow.workflow_execution.completed",
691
- "workflow.workflow_execution.retried",
692
- "workflow.workflow_execution.resumed",
693
- "workflow.workflow_execution.wait_started",
694
- "workflow.workflow_execution.wait_resolved"
695
- ])).min(1).transform((arr) => [...new Set(arr)]).describe("Workflow execution event types to trigger on"),
696
- workflowName: workflowNameSchema,
697
- condition: functionSchema.optional().describe("Condition function to filter events")
698
- });
699
- const WorkflowJobExecutionTriggerSchema = z.strictObject({
700
- kind: z.literal("workflowJobExecution").describe("Workflow job execution event trigger"),
701
- events: z.array(z.enum([
702
- "workflow.workflow_execution.job_execution.started",
703
- "workflow.workflow_execution.job_execution.completed",
704
- "workflow.workflow_execution.job_execution.wait_started",
705
- "workflow.workflow_execution.job_execution.wait_resolved"
706
- ])).min(1).transform((arr) => [...new Set(arr)]).describe("Workflow job execution event types to trigger on"),
707
- workflowName: workflowNameSchema,
708
- condition: functionSchema.optional().describe("Condition function to filter events")
709
- });
710
- const TriggerSchema = z.discriminatedUnion("kind", [
711
- TailorDBTriggerSchema,
712
- ResolverExecutedTriggerSchema,
713
- ScheduleTriggerSchema,
714
- IncomingWebhookTriggerSchema,
715
- IdpUserTriggerSchema,
716
- AuthAccessTokenTriggerSchema,
717
- WorkflowExecutionTriggerSchema,
718
- WorkflowJobExecutionTriggerSchema
719
- ]);
720
- const FunctionOperationSchema = z.strictObject({
721
- kind: z.enum(["function", "jobFunction"]),
722
- body: functionSchema.describe("Function implementation"),
723
- invoker: AuthInvokerSchema.optional().describe("Invoker for the function execution")
724
- });
725
- const GqlOperationSchema = z.strictObject({
726
- kind: z.literal("graphql"),
727
- appName: z.string().optional().describe("Target application name for the GraphQL query"),
728
- query: z.preprocess((val) => String(val), z.string().describe("GraphQL query string")),
729
- variables: functionSchema.optional().describe("Function to compute GraphQL variables"),
730
- invoker: AuthInvokerSchema.optional().describe("Invoker for the GraphQL execution")
731
- });
732
- const WebhookOperationSchema = z.strictObject({
733
- kind: z.literal("webhook"),
734
- url: functionSchema.describe("Function returning the webhook URL"),
735
- requestBody: functionSchema.optional().describe("Function to compute the request body"),
736
- headers: z.record(z.string(), z.union([z.string(), z.strictObject({
737
- vault: z.string(),
738
- key: z.string()
739
- })])).optional().describe("HTTP headers for the webhook request")
740
- });
741
- const JsonValueSchema = z.lazy(() => z.union([
742
- z.string(),
743
- z.number(),
744
- z.boolean(),
745
- z.null(),
746
- z.array(JsonValueSchema),
747
- z.record(z.string(), JsonValueSchema)
748
- ]));
749
- const WorkflowInputSchema = z.union([
750
- z.string(),
751
- z.number(),
752
- z.boolean(),
753
- z.array(JsonValueSchema),
754
- z.record(z.string(), JsonValueSchema)
755
- ]);
756
- const WorkflowOperationArgsSchema = z.union([WorkflowInputSchema, functionSchema]).describe("Arguments to pass to the workflow");
757
- const workflowOperationShape = {
758
- kind: z.literal("workflow"),
759
- args: WorkflowOperationArgsSchema.optional(),
760
- invoker: AuthInvokerSchema.optional().describe("Invoker for the workflow execution")
761
- };
762
- const WorkflowOperationByNameSchema = z.strictObject({
763
- ...workflowOperationShape,
764
- workflowName: z.string().describe("Name of the workflow to execute"),
765
- workflow: z.never().optional()
766
- });
767
- const WorkflowOperationByReferenceSchema = z.strictObject({
768
- ...workflowOperationShape,
769
- workflow: z.looseObject({ name: z.string() }),
770
- workflowName: z.string().optional()
771
- }).transform(({ workflow, ...operation }) => ({
772
- ...operation,
773
- workflowName: workflow.name
774
- }));
775
- const WorkflowOperationSchema = z.union([WorkflowOperationByReferenceSchema, WorkflowOperationByNameSchema]);
776
- const OperationSchema = z.union([
777
- FunctionOperationSchema,
778
- GqlOperationSchema,
779
- WebhookOperationSchema,
780
- WorkflowOperationSchema
781
- ]);
782
- const ExecutorSchema = z.strictObject({
783
- name: z.string().describe("Executor name"),
784
- description: z.string().optional().describe("Executor description"),
785
- disabled: z.boolean().optional().default(false).describe("Whether the executor is disabled"),
786
- trigger: TriggerSchema.describe("Event trigger configuration"),
787
- operation: OperationSchema.describe("Operation to execute when triggered")
788
- });
789
-
790
- //#endregion
791
- //#region src/cli/services/executor/loader.ts
792
- function stripExecutorTriggerArgs(executor) {
793
- if (!isSdkBranded(executor, "executor")) return executor;
794
- const trigger = executor.trigger;
795
- if (trigger === null || typeof trigger !== "object" || !("__args" in trigger)) return executor;
796
- const { __args: _args, ...triggerConfig } = trigger;
797
- return {
798
- ...executor,
799
- trigger: triggerConfig
800
- };
801
- }
802
- /**
803
- * Load and validate an executor definition from a file.
804
- * @param executorFilePath - Path to the executor file
805
- * @returns Parsed executor or null if invalid
806
- */
807
- async function loadExecutor(executorFilePath) {
808
- const executor = (await importUserModule(executorFilePath)).default;
809
- const parseResult = ExecutorSchema.safeParse(stripExecutorTriggerArgs(executor));
810
- if (!parseResult.success) return null;
811
- return parseResult.data;
812
- }
813
-
814
- //#endregion
815
- //#region src/cli/services/executor/service.ts
816
- /**
817
- * Creates a new ExecutorService instance.
818
- * @param params - Parameters for creating the service
819
- * @returns A new ExecutorService instance
820
- */
821
- function createExecutorService(params) {
822
- const { config, baseDir } = params;
823
- const executors = {};
824
- const pluginExecutors = [];
825
- let loadPromise;
826
- const loadExecutorForFile = async (executorFile) => {
827
- try {
828
- const executorModule = await importUserModule(executorFile);
829
- const result = ExecutorSchema.safeParse(stripExecutorTriggerArgs(executorModule.default));
830
- if (result.success) {
831
- const relativePath = path.relative(process.cwd(), executorFile);
832
- logger.log(`Executor: ${styles.successBright(`"${result.data.name}"`)} loaded from ${styles.path(relativePath)}`);
833
- executors[executorFile] = result.data;
834
- return result.data;
835
- }
836
- if (isSdkBranded(executorModule.default, "executor")) throw result.error;
837
- } catch (error) {
838
- const relativePath = path.relative(process.cwd(), executorFile);
839
- logger.error(`Failed to load executor from ${styles.bold(relativePath)}`);
840
- logger.error(String(error));
841
- throw error;
842
- }
843
- };
844
- return {
845
- config,
846
- get executors() {
847
- return executors;
848
- },
849
- get pluginExecutors() {
850
- return pluginExecutors;
851
- },
852
- loadExecutors: async () => {
853
- if (!loadPromise) loadPromise = (async () => {
854
- if (config.files.length === 0) return;
855
- const executorFiles = loadFilesWithIgnores(config, baseDir);
856
- logger.newline();
857
- logger.log(`Found ${styles.highlight(executorFiles.length.toString())} executor files`);
858
- await Promise.all(executorFiles.map((executorFile) => loadExecutorForFile(executorFile)));
859
- assertUniqueExecutorNames(executors);
860
- return executors;
861
- })();
862
- return loadPromise;
863
- },
864
- loadPluginExecutorFiles: async (filePaths) => {
865
- if (filePaths.length === 0) return;
866
- logger.newline();
867
- logger.log(`Loading ${styles.highlight(filePaths.length.toString())} plugin-generated executor files`);
868
- for (const filePath of filePaths) {
869
- const executor = await loadExecutorForFile(filePath);
870
- if (executor) pluginExecutors.push({
871
- executor,
872
- pluginId: "plugin-generated",
873
- sourceTypeName: void 0
874
- });
875
- }
876
- assertUniqueExecutorNames(executors);
877
- }
878
- };
879
- }
880
- /**
881
- * Assert that every loaded executor has a unique name.
882
- * Executors are stored by source file, so two files declaring the same
883
- * `name` would otherwise silently share a single bundle cache entry.
884
- * @param executors - Loaded executors keyed by source file
885
- */
886
- function assertUniqueExecutorNames(executors) {
887
- const seenNames = /* @__PURE__ */ new Map();
888
- for (const [file, executor] of Object.entries(executors)) {
889
- const relativePath = path.relative(process.cwd(), file);
890
- const existing = seenNames.get(executor.name);
891
- if (existing) throw new Error(`Duplicate executor name "${executor.name}" found:\n - ${existing}\n - ${relativePath}\nEach executor must have a unique name.`);
892
- seenNames.set(executor.name, relativePath);
893
- }
894
- }
895
-
896
- //#endregion
897
- export { beginUserModuleRun as _, AuthConfigSchema as a, functionSchema as b, stripTailorDBTypeBuilderHelpers as c, applyRelationMetadataToFieldConfig as d, buildRelationInfo as f, IMPORT_NONCE_PARAM as g, loadFilesWithIgnores as h, ExecutorSchema as i, TailorDBServiceConfigSchema as l, validateRelationConfig as m, loadExecutor as n, AuthInvokerSchema as o, processRelationMetadata as p, stripExecutorTriggerArgs as r, TailorFieldSchema as s, createExecutorService as t, TailorDBTypeSchema as u, currentImportNonce as v, importUserModule as y };
898
- //# sourceMappingURL=service-2grcAOCJ.mjs.map