@tailor-platform/sdk 2.3.0 → 2.5.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 (257) hide show
  1. package/CHANGELOG.md +171 -0
  2. package/README.md +1 -1
  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-DFOUovmN.mjs +1 -0
  6. package/dist/application-D_4vg1KR.mjs +192 -0
  7. package/dist/application-D_4vg1KR.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/deploy/deploy.d.mts +2 -2
  15. package/dist/cli/commands/deploy/deployment-target.d.mts +2 -0
  16. package/dist/cli/commands/deploy/event-subscriptions.d.mts +3 -0
  17. package/dist/cli/commands/deploy/tailordb/apply.d.mts +3 -0
  18. package/dist/cli/commands/deploy/tailordb/index.d.mts +3 -10
  19. package/dist/cli/commands/deploy/tailordb/migration-validation.d.mts +5 -0
  20. package/dist/cli/commands/deploy/tailordb/plan.d.mts +8 -0
  21. package/dist/cli/commands/executor/jobs.d.mts +1 -1
  22. package/dist/cli/commands/generate/seed/bundler.d.mts +2 -2
  23. package/dist/cli/commands/show.d.mts +1 -1
  24. package/dist/cli/commands/tailordb/migrate/diff-calculator.d.mts +15 -15
  25. package/dist/cli/commands/tailordb/migrate/generate.d.mts +7 -3
  26. package/dist/cli/commands/tailordb/migrate/rename-detection.d.mts +1 -1
  27. package/dist/cli/commands/tailordb/migrate/snapshot-comparison.d.mts +43 -0
  28. package/dist/cli/commands/tailordb/migrate/snapshot-files.d.mts +62 -0
  29. package/dist/cli/commands/tailordb/migrate/snapshot-local.d.mts +12 -0
  30. package/dist/cli/commands/tailordb/migrate/snapshot-migrations.d.mts +12 -0
  31. package/dist/cli/commands/tailordb/migrate/snapshot-remote.d.mts +1 -0
  32. package/dist/cli/commands/tailordb/migrate/snapshot-types.d.mts +3 -1
  33. package/dist/cli/commands/tailordb/migrate/snapshot.d.mts +5 -117
  34. package/dist/cli/commands/tailordb/truncate.d.mts +2 -2
  35. package/dist/cli/lib.d.mts +8 -4
  36. package/dist/cli/lib.mjs +1 -9
  37. package/dist/cli/lib.mjs.map +1 -1
  38. package/dist/cli/main.mjs +1170 -7686
  39. package/dist/cli/main.mjs.map +1 -1
  40. package/dist/cli/shared/seed-chunker.d.mts +5 -5
  41. package/dist/cli/ts-hook.mjs +3 -1
  42. package/dist/completion/zsh-worker.zsh +99 -18
  43. package/dist/configure/config/index.d.mts +2 -2
  44. package/dist/configure/config/types.d.mts +2 -2
  45. package/dist/configure/index.d.mts +49 -12
  46. package/dist/configure/index.mjs +1 -1267
  47. package/dist/configure/index.mjs.map +1 -1
  48. package/dist/configure/services/aigateway/index.d.mts +5 -4
  49. package/dist/configure/services/aigateway/types.d.mts +6 -1
  50. package/dist/configure/services/auth/types.d.mts +3 -3
  51. package/dist/configure/services/idp/types.d.mts +1 -1
  52. package/dist/configure/services/tailordb/permission.d.mts +1 -1
  53. package/dist/configure/services/tailordb/schema.d.mts +5 -9
  54. package/dist/configure/services/tailordb/types.d.mts +8 -5
  55. package/dist/configure/services/workflow/execution-policy.d.mts +3 -3
  56. package/dist/configure/services/workflow/job.d.mts +12 -2
  57. package/dist/configure/types/auth-namespace-name.d.mts +18 -0
  58. package/dist/configure/types/field.types.d.mts +1 -1
  59. package/dist/configure/types/permission-operand.types.d.mts +1 -1
  60. package/dist/context-D0QjfxzD.mjs +2 -0
  61. package/dist/{context-DYQVYWqZ.mjs.map → context-D0QjfxzD.mjs.map} +1 -1
  62. package/dist/crashreport-B-_HTKLr.mjs +42 -0
  63. package/dist/{crashreport-CIIfLnoO.mjs.map → crashreport-B-_HTKLr.mjs.map} +1 -1
  64. package/dist/crashreport-BmsRIdpy.mjs +1 -0
  65. package/dist/errors-DSEXKRVD.mjs +2 -0
  66. package/dist/errors-DSEXKRVD.mjs.map +1 -0
  67. package/dist/file-COPYfju_.mjs +2 -0
  68. package/dist/file-COPYfju_.mjs.map +1 -0
  69. package/dist/globals-CMHSnj4w.mjs +2 -0
  70. package/dist/{globals-B2nlxBrz.mjs.map → globals-CMHSnj4w.mjs.map} +1 -1
  71. package/dist/iconv-DlFMt2gW.mjs +2 -0
  72. package/dist/{iconv-QWaZh0TT.mjs.map → iconv-DlFMt2gW.mjs.map} +1 -1
  73. package/dist/idp-G_ojPBB5.mjs +2 -0
  74. package/dist/{idp-RA_swu-h.mjs.map → idp-G_ojPBB5.mjs.map} +1 -1
  75. package/dist/interceptor-DQg3cR_9.mjs +2 -0
  76. package/dist/{interceptor-e33JtsC-.mjs.map → interceptor-DQg3cR_9.mjs.map} +1 -1
  77. package/dist/kysely/index.mjs +1 -31
  78. package/dist/kysely/index.mjs.map +1 -1
  79. package/dist/kysely-type-BTi3BMtL.mjs +43 -0
  80. package/dist/kysely-type-BTi3BMtL.mjs.map +1 -0
  81. package/dist/logger-BcGy-u7G.mjs +9 -0
  82. package/dist/{logger-DSdExfor.mjs.map → logger-BcGy-u7G.mjs.map} +1 -1
  83. package/dist/logger-DP2BjQ93.mjs +2 -0
  84. package/dist/{logger-BtX0suGY.mjs.map → logger-DP2BjQ93.mjs.map} +1 -1
  85. package/dist/multiline-EyzjEwn9.mjs +3 -0
  86. package/dist/{multiline-sfHpTZZK.mjs.map → multiline-EyzjEwn9.mjs.map} +1 -1
  87. package/dist/node-builtins-oBl7EbyV.mjs +2 -0
  88. package/dist/{node-builtins-CmaL2Cbq.mjs.map → node-builtins-oBl7EbyV.mjs.map} +1 -1
  89. package/dist/package-json-C690ceex.mjs +2 -0
  90. package/dist/{package-json-8b0O9TlX.mjs.map → package-json-C690ceex.mjs.map} +1 -1
  91. package/dist/package-json-CmqhDJ__.mjs +1 -0
  92. package/dist/parser/service/tailordb/type-source.d.mts +5 -5
  93. package/dist/parser/service/tailordb/types.d.mts +4 -4
  94. package/dist/platform-serialize-DkiTdHOt.mjs +2 -0
  95. package/dist/{platform-serialize-RoRtBS0v.mjs.map → platform-serialize-DkiTdHOt.mjs.map} +1 -1
  96. package/dist/plugin/builtin/enum-constants/index.d.mts +1 -1
  97. package/dist/plugin/builtin/enum-constants/index.mjs +5 -114
  98. package/dist/plugin/builtin/enum-constants/index.mjs.map +1 -1
  99. package/dist/plugin/builtin/file-utils/index.d.mts +1 -1
  100. package/dist/plugin/builtin/file-utils/index.mjs +22 -101
  101. package/dist/plugin/builtin/file-utils/index.mjs.map +1 -1
  102. package/dist/plugin/builtin/kysely-type/index.d.mts +9 -2
  103. package/dist/plugin/builtin/kysely-type/index.mjs +1 -275
  104. package/dist/plugin/builtin/seed/index.d.mts +5 -0
  105. package/dist/plugin/builtin/seed/index.mjs +1 -3
  106. package/dist/plugin/builtin/seed/seed-type-processor.d.mts +4 -6
  107. package/dist/plugin/get-generated-table.d.mts +16 -0
  108. package/dist/plugin/index.d.mts +3 -2
  109. package/dist/plugin/index.mjs +1 -251
  110. package/dist/plugin/index.mjs.map +1 -1
  111. package/dist/plugin/types.d.mts +32 -25
  112. package/dist/plugin/with-context.d.mts +4 -4
  113. package/dist/register-ts-hook-Drnaproy.mjs +640 -0
  114. package/dist/register-ts-hook-Drnaproy.mjs.map +1 -0
  115. package/dist/registry-HlEaGvl5.mjs +2 -0
  116. package/dist/{registry-BIGVUrMB.mjs.map → registry-HlEaGvl5.mjs.map} +1 -1
  117. package/dist/repl-editor-BG1aDOfH.mjs +2 -0
  118. package/dist/{repl-editor-BCozyiNq.mjs.map → repl-editor-BG1aDOfH.mjs.map} +1 -1
  119. package/dist/runtime/aigateway.mjs +1 -3
  120. package/dist/runtime/authconnection.mjs +1 -3
  121. package/dist/runtime/context.mjs +1 -3
  122. package/dist/runtime/file.d.mts +28 -28
  123. package/dist/runtime/file.mjs +1 -3
  124. package/dist/runtime/globals.mjs +1 -1
  125. package/dist/runtime/iconv.mjs +1 -3
  126. package/dist/runtime/idp.mjs +1 -3
  127. package/dist/runtime/index.mjs +1 -11
  128. package/dist/runtime/logger.mjs +1 -3
  129. package/dist/runtime/secretmanager.mjs +1 -3
  130. package/dist/runtime/types.d.mts +1 -1
  131. package/dist/runtime/workflow.mjs +1 -3
  132. package/dist/schema-Ze_dI5VX.mjs +2 -0
  133. package/dist/schema-Ze_dI5VX.mjs.map +1 -0
  134. package/dist/secret-file-C9wp_FCX.mjs +2 -0
  135. package/dist/{secret-file-C3J4Gy8r.mjs.map → secret-file-C9wp_FCX.mjs.map} +1 -1
  136. package/dist/secretmanager-5olfnI1b.mjs +2 -0
  137. package/dist/{secretmanager-IY4UvinW.mjs.map → secretmanager-5olfnI1b.mjs.map} +1 -1
  138. package/dist/secretmanager-vHQoXdQz.mjs +2 -0
  139. package/dist/{secretmanager-CYlpffsz.mjs.map → secretmanager-vHQoXdQz.mjs.map} +1 -1
  140. package/dist/seed/index.d.mts +4 -4
  141. package/dist/seed/index.mjs +8 -244
  142. package/dist/seed/index.mjs.map +1 -1
  143. package/dist/seed-DwqRFdqP.mjs +207 -0
  144. package/dist/seed-DwqRFdqP.mjs.map +1 -0
  145. package/dist/service-BVe9u2Rt.mjs +7 -0
  146. package/dist/service-BVe9u2Rt.mjs.map +1 -0
  147. package/dist/service-CpZELSBa.mjs +1 -0
  148. package/dist/service-DlgaUO4V.mjs +2 -0
  149. package/dist/{service-hZskxZmg.mjs.map → service-DlgaUO4V.mjs.map} +1 -1
  150. package/dist/service_pb-DGKCLuAs.mjs +2 -0
  151. package/dist/{service_pb-BEWj1pOV.mjs.map → service_pb-DGKCLuAs.mjs.map} +1 -1
  152. package/dist/service_pb-_aeFE-Nv.mjs +1 -0
  153. package/dist/telemetry-Bklv9kQY.mjs +2 -0
  154. package/dist/{telemetry-BRVdwh14.mjs.map → telemetry-Bklv9kQY.mjs.map} +1 -1
  155. package/dist/telemetry-DXHP3VVi.mjs +1 -0
  156. package/dist/type-source--ZNcV8RJ.mjs +2 -0
  157. package/dist/type-source--ZNcV8RJ.mjs.map +1 -0
  158. package/dist/types/aigateway.generated.d.mts +2 -2
  159. package/dist/types/auth.generated.d.mts +3 -3
  160. package/dist/types/executor.generated.d.mts +2 -2
  161. package/dist/types/tailordb.generated.d.mts +12 -12
  162. package/dist/user-agent-vdHYF3QL.mjs +2 -0
  163. package/dist/{user-agent-Bgsszb5I.mjs.map → user-agent-vdHYF3QL.mjs.map} +1 -1
  164. package/dist/utils/test/index.d.mts +4 -4
  165. package/dist/utils/test/index.mjs +1 -109
  166. package/dist/utils/test/index.mjs.map +1 -1
  167. package/dist/vitest/environment.mjs +1 -41
  168. package/dist/vitest/environment.mjs.map +1 -1
  169. package/dist/vitest/index.mjs +1 -1980
  170. package/dist/vitest/index.mjs.map +1 -1
  171. package/dist/vitest/mocks/file.d.mts +8 -8
  172. package/dist/vitest/setup.mjs +1 -140
  173. package/dist/vitest/setup.mjs.map +1 -1
  174. package/dist/wait-point-invoker-eiP-IIux.mjs +2 -0
  175. package/dist/wait-point-invoker-eiP-IIux.mjs.map +1 -0
  176. package/dist/wait-point-registry-BrkwfyjS.mjs +2 -0
  177. package/dist/{wait-point-registry-TL99zotw.mjs.map → wait-point-registry-BrkwfyjS.mjs.map} +1 -1
  178. package/dist/workflow-Cs9ISw6j.mjs +2 -0
  179. package/dist/{workflow-Bamae_Yc.mjs.map → workflow-Cs9ISw6j.mjs.map} +1 -1
  180. package/dist/workspace_resource_pb--GeYQPXu.mjs +2 -0
  181. package/dist/{workspace_resource_pb-HNIL_Vfj.mjs.map → workspace_resource_pb--GeYQPXu.mjs.map} +1 -1
  182. package/docs/cli/application.md +3 -1
  183. package/docs/cli/function.md +77 -13
  184. package/docs/cli/setup.md +24 -14
  185. package/docs/cli/tailordb.md +32 -30
  186. package/docs/cli/workspace.md +2 -2
  187. package/docs/cli-reference.md +23 -22
  188. package/docs/configuration.md +2 -2
  189. package/docs/github-actions.md +10 -9
  190. package/docs/migration/v2.md +16 -4
  191. package/docs/migration/v3.md +123 -0
  192. package/docs/plugin/custom.md +130 -85
  193. package/docs/plugin/index.md +3 -3
  194. package/docs/quickstart.md +1 -1
  195. package/docs/services/aigateway.md +33 -9
  196. package/docs/services/executor.md +5 -1
  197. package/docs/services/tailordb-migration.md +68 -54
  198. package/docs/services/tailordb.md +7 -7
  199. package/docs/services/workflow.md +10 -9
  200. package/docs/testing.md +1 -1
  201. package/package.json +16 -16
  202. package/postinstall.mjs +1 -1
  203. package/dist/aigateway-DR4Kwuik.mjs +0 -9
  204. package/dist/application-BZfk4HKm.mjs +0 -3
  205. package/dist/application-F-nl107y.mjs +0 -6019
  206. package/dist/application-F-nl107y.mjs.map +0 -1
  207. package/dist/assert-DBxo8jPo.mjs +0 -9
  208. package/dist/authconnection-CZvi9ANm.mjs +0 -9
  209. package/dist/brand-Eo4pLXPJ.mjs +0 -36
  210. package/dist/context-DYQVYWqZ.mjs +0 -23
  211. package/dist/crashreport-CIIfLnoO.mjs +0 -423
  212. package/dist/crashreport-CINZ5dVN.mjs +0 -3
  213. package/dist/errors-BVb6vYGy.mjs +0 -89
  214. package/dist/errors-BVb6vYGy.mjs.map +0 -1
  215. package/dist/file-BUcmVIH2.mjs +0 -58
  216. package/dist/file-BUcmVIH2.mjs.map +0 -1
  217. package/dist/globals-B2nlxBrz.mjs +0 -126
  218. package/dist/iconv-QWaZh0TT.mjs +0 -38
  219. package/dist/idp-RA_swu-h.mjs +0 -82
  220. package/dist/interceptor-e33JtsC-.mjs +0 -33
  221. package/dist/logger-BtX0suGY.mjs +0 -48
  222. package/dist/logger-DSdExfor.mjs +0 -358
  223. package/dist/multiline-sfHpTZZK.mjs +0 -38
  224. package/dist/node-builtins-CmaL2Cbq.mjs +0 -36
  225. package/dist/package-json-8b0O9TlX.mjs +0 -17
  226. package/dist/package-json-Cv2Z-TqQ.mjs +0 -3
  227. package/dist/platform-serialize-RoRtBS0v.mjs +0 -46
  228. package/dist/plugin/builtin/kysely-type/index.mjs.map +0 -1
  229. package/dist/plugin/builtin/seed/types.d.mts +0 -2
  230. package/dist/plugin/get-generated-type.d.mts +0 -16
  231. package/dist/register-ts-hook-ClI226n2.mjs +0 -25543
  232. package/dist/register-ts-hook-ClI226n2.mjs.map +0 -1
  233. package/dist/registry-BIGVUrMB.mjs +0 -54
  234. package/dist/repl-editor-BCozyiNq.mjs +0 -251
  235. package/dist/schema--xYWRGfe.mjs +0 -639
  236. package/dist/schema--xYWRGfe.mjs.map +0 -1
  237. package/dist/secret-file-C3J4Gy8r.mjs +0 -64
  238. package/dist/secretmanager-CYlpffsz.mjs +0 -13
  239. package/dist/secretmanager-IY4UvinW.mjs +0 -131
  240. package/dist/seed-xqM9WIHP.mjs +0 -483
  241. package/dist/seed-xqM9WIHP.mjs.map +0 -1
  242. package/dist/service-C_WpbKHu.mjs +0 -898
  243. package/dist/service-C_WpbKHu.mjs.map +0 -1
  244. package/dist/service-D1RCdzIL.mjs +0 -3
  245. package/dist/service-hZskxZmg.mjs +0 -131
  246. package/dist/service_pb-BEWj1pOV.mjs +0 -167
  247. package/dist/service_pb-BjlhvK9E.mjs +0 -3
  248. package/dist/telemetry-BRVdwh14.mjs +0 -84
  249. package/dist/telemetry-CkbkeJxl.mjs +0 -3
  250. package/dist/type-source-DH_LH20p.mjs +0 -13
  251. package/dist/type-source-DH_LH20p.mjs.map +0 -1
  252. package/dist/user-agent-Bgsszb5I.mjs +0 -28
  253. package/dist/wait-point-invoker-__oE88_P.mjs +0 -148
  254. package/dist/wait-point-invoker-__oE88_P.mjs.map +0 -1
  255. package/dist/wait-point-registry-TL99zotw.mjs +0 -47
  256. package/dist/workflow-Bamae_Yc.mjs +0 -34
  257. package/dist/workspace_resource_pb-HNIL_Vfj.mjs +0 -860
@@ -1,275 +1 @@
1
- import { t as multiline } from "../../../multiline-sfHpTZZK.mjs";
2
-
3
- //#region src/plugin/builtin/kysely-type/type-processor.ts
4
- /**
5
- * Get the enum type definition.
6
- * @param fieldConfig - The field configuration
7
- * @returns The enum type as a string union
8
- */
9
- function getEnumType(fieldConfig) {
10
- const allowedValues = fieldConfig.allowedValues;
11
- if (allowedValues && Array.isArray(allowedValues)) return allowedValues.map((v) => {
12
- return `"${typeof v === "string" ? v : v.value}"`;
13
- }).join(" | ");
14
- return "string";
15
- }
16
- /**
17
- * Get the nested object type definition.
18
- * @param fieldConfig - The field configuration
19
- * @returns The nested type with used utility types
20
- */
21
- function getNestedType(fieldConfig) {
22
- const fields = fieldConfig.fields;
23
- if (!fields || typeof fields !== "object") return {
24
- type: "string",
25
- usedUtilityTypes: {
26
- Timestamp: false,
27
- Serial: false
28
- }
29
- };
30
- const fieldResults = Object.entries(fields).map(([fieldName, config]) => {
31
- const result = generateFieldType(config);
32
- return {
33
- fieldType: `${fieldName}${config.required !== true ? "?" : ""}: ${result.type}`,
34
- usedUtilityTypes: result.usedUtilityTypes
35
- };
36
- });
37
- const aggregatedUtilityTypes = fieldResults.reduce((acc, result) => ({
38
- Timestamp: acc.Timestamp || result.usedUtilityTypes.Timestamp,
39
- Serial: acc.Serial || result.usedUtilityTypes.Serial
40
- }), {
41
- Timestamp: false,
42
- Serial: false
43
- });
44
- const fieldTypes = fieldResults.map((r) => r.fieldType);
45
- const obj = `{\n ${fieldTypes.join(";\n ")}${fieldTypes.length > 0 ? ";" : ""}\n}`;
46
- const hasOptionalFields = Object.values(fields).some((config) => config.required !== true);
47
- const hasGeneratedFields = Object.values(fields).some((config) => config.hooks?.create || config.default !== void 0);
48
- if (aggregatedUtilityTypes.Timestamp || hasOptionalFields || hasGeneratedFields) return {
49
- type: `ObjectColumnType<${obj}>`,
50
- usedUtilityTypes: aggregatedUtilityTypes
51
- };
52
- return {
53
- type: obj,
54
- usedUtilityTypes: aggregatedUtilityTypes
55
- };
56
- }
57
- /**
58
- * Get the base Kysely type for a field (without array/null modifiers).
59
- * @param fieldConfig - The field configuration
60
- * @returns The base type with used utility types
61
- */
62
- function getBaseType(fieldConfig) {
63
- const fieldType = fieldConfig.type;
64
- const usedUtilityTypes = {
65
- Timestamp: false,
66
- Serial: false
67
- };
68
- let type;
69
- switch (fieldType) {
70
- case "uuid":
71
- case "string":
72
- case "decimal":
73
- type = "string";
74
- break;
75
- case "integer":
76
- case "float":
77
- type = "number";
78
- break;
79
- case "date":
80
- case "datetime":
81
- usedUtilityTypes.Timestamp = true;
82
- type = "Timestamp";
83
- break;
84
- case "bool":
85
- case "boolean":
86
- type = "boolean";
87
- break;
88
- case "enum":
89
- type = getEnumType(fieldConfig);
90
- break;
91
- case "nested": return getNestedType(fieldConfig);
92
- default:
93
- type = "string";
94
- break;
95
- }
96
- return {
97
- type,
98
- usedUtilityTypes
99
- };
100
- }
101
- /**
102
- * Generate the complete field type including array and null modifiers.
103
- * @param fieldConfig - The field configuration
104
- * @returns The complete field type with used utility types
105
- */
106
- function generateFieldType(fieldConfig) {
107
- const baseTypeResult = getBaseType(fieldConfig);
108
- const usedUtilityTypes = { ...baseTypeResult.usedUtilityTypes };
109
- const isArray = fieldConfig.array === true;
110
- const isNullable = fieldConfig.required !== true;
111
- const isColumnTypeBase = (/* @__PURE__ */ new Set(["Timestamp"])).has(baseTypeResult.type);
112
- let finalType = baseTypeResult.type;
113
- if (isArray) if (isColumnTypeBase || finalType.startsWith("ObjectColumnType<")) finalType = `ArrayColumnType<${baseTypeResult.type}>`;
114
- else finalType = fieldConfig.type === "enum" ? `(${baseTypeResult.type})[]` : `${baseTypeResult.type}[]`;
115
- if (isNullable) finalType = `${finalType} | null`;
116
- if (fieldConfig.serial) {
117
- usedUtilityTypes.Serial = true;
118
- finalType = `Serial<${finalType}>`;
119
- }
120
- if (fieldConfig.hooks?.create || fieldConfig.default !== void 0) finalType = `Generated<${finalType}>`;
121
- return {
122
- type: finalType,
123
- usedUtilityTypes
124
- };
125
- }
126
- /**
127
- * Generate the table interface.
128
- * @param type - The parsed TailorDB type
129
- * @returns The type definition and used utility types
130
- */
131
- function generateTableInterface(type) {
132
- const fieldResults = Object.entries(type.fields).filter(([fieldName]) => fieldName !== "id").map(([fieldName, parsedField]) => ({
133
- fieldName,
134
- ...generateFieldType(parsedField.config)
135
- }));
136
- const fields = ["id: Generated<string>;", ...fieldResults.map((result) => `${result.fieldName}: ${result.type};`)];
137
- const aggregatedUtilityTypes = fieldResults.reduce((acc, result) => ({
138
- Timestamp: acc.Timestamp || result.usedUtilityTypes.Timestamp,
139
- Serial: acc.Serial || result.usedUtilityTypes.Serial
140
- }), {
141
- Timestamp: false,
142
- Serial: false
143
- });
144
- return {
145
- typeDef: multiline`
146
- ${type.name}: {
147
- ${fields.join("\n")}
148
- }
149
- `,
150
- usedUtilityTypes: aggregatedUtilityTypes
151
- };
152
- }
153
- /**
154
- * Convert a TailorDBType into KyselyTypeMetadata.
155
- * @param type - Parsed TailorDB type
156
- * @returns Generated Kysely type metadata
157
- */
158
- async function processKyselyType(type) {
159
- const result = generateTableInterface(type);
160
- return {
161
- name: type.name,
162
- typeDef: result.typeDef,
163
- usedUtilityTypes: result.usedUtilityTypes
164
- };
165
- }
166
- /**
167
- * Generate unified types file from multiple namespaces.
168
- * @param namespaceData - Namespace metadata
169
- * @returns Generated types file contents
170
- */
171
- function generateUnifiedKyselyTypes(namespaceData) {
172
- if (namespaceData.length === 0) return "";
173
- const globalUsedUtilityTypes = namespaceData.reduce((acc, ns) => ({
174
- Timestamp: acc.Timestamp || ns.usedUtilityTypes.Timestamp,
175
- Serial: acc.Serial || ns.usedUtilityTypes.Serial
176
- }), {
177
- Timestamp: false,
178
- Serial: false
179
- });
180
- const utilityTypeImports = ["type Generated"];
181
- if (globalUsedUtilityTypes.Timestamp) utilityTypeImports.push("type Timestamp");
182
- if (namespaceData.some((ns) => ns.types.some((t) => t.typeDef.includes("ObjectColumnType<")))) utilityTypeImports.push("type ObjectColumnType");
183
- if (namespaceData.some((ns) => ns.types.some((t) => t.typeDef.includes("ArrayColumnType<")))) utilityTypeImports.push("type ArrayColumnType");
184
- if (globalUsedUtilityTypes.Serial) utilityTypeImports.push("type Serial");
185
- return [
186
- multiline`
187
- import {
188
- createGetDB,
189
- ${utilityTypeImports.join(",\n")},
190
- type NamespaceDB,
191
- type NamespaceInsertable,
192
- type NamespaceSelectable,
193
- type NamespaceTable,
194
- type NamespaceTableName,
195
- type NamespaceTransaction,
196
- type NamespaceUpdateable,
197
- } from "@tailor-platform/sdk/kysely";
198
- `,
199
- `export interface Namespace {\n${namespaceData.map(({ namespace, types }) => {
200
- return ` "${namespace}": {\n${types.map((type) => {
201
- return type.typeDef.split("\n").map((line) => line.trim() ? ` ${line}` : "").join("\n");
202
- }).join("\n\n")}\n }`;
203
- }).join(",\n")}\n}`,
204
- multiline`
205
- export const getDB = createGetDB<Namespace>();
206
-
207
- export type DB<N extends keyof Namespace = keyof Namespace> = NamespaceDB<Namespace, N>;
208
- `,
209
- multiline`
210
- export type Transaction<K extends keyof Namespace | DB = keyof Namespace> =
211
- NamespaceTransaction<Namespace, K>;
212
-
213
- type TableName = NamespaceTableName<Namespace>;
214
- export type Table<T extends TableName> = NamespaceTable<Namespace, T>;
215
-
216
- export type Insertable<T extends TableName> = NamespaceInsertable<Namespace, T>;
217
- export type Selectable<T extends TableName> = NamespaceSelectable<Namespace, T>;
218
- export type Updateable<T extends TableName> = NamespaceUpdateable<Namespace, T>;
219
- `
220
- ].join("\n\n") + "\n";
221
- }
222
-
223
- //#endregion
224
- //#region src/plugin/builtin/kysely-type/index.ts
225
- /** Unique identifier for the Kysely type generator plugin. */
226
- const KyselyGeneratorID = "@tailor-platform/kysely-type";
227
- /**
228
- * Plugin that generates Kysely type definitions for TailorDB types.
229
- * @param options - Plugin options
230
- * @param options.distPath - Output file path for generated types
231
- * @returns Plugin instance with onTailorDBReady hook
232
- */
233
- function kyselyTypePlugin(options) {
234
- return {
235
- id: KyselyGeneratorID,
236
- description: "Generates Kysely type definitions for TailorDB types",
237
- pluginConfig: options,
238
- async onTailorDBReady(ctx) {
239
- const allNamespaceData = [];
240
- for (const ns of ctx.tailordb) {
241
- const typeMetadataList = [];
242
- for (const type of Object.values(ns.types)) {
243
- const metadata = await processKyselyType(type);
244
- typeMetadataList.push(metadata);
245
- }
246
- if (typeMetadataList.length === 0) continue;
247
- const usedUtilityTypes = typeMetadataList.reduce((acc, type) => ({
248
- Timestamp: acc.Timestamp || type.usedUtilityTypes.Timestamp,
249
- Serial: acc.Serial || type.usedUtilityTypes.Serial
250
- }), {
251
- Timestamp: false,
252
- Serial: false
253
- });
254
- allNamespaceData.push({
255
- namespace: ns.namespace,
256
- types: typeMetadataList,
257
- usedUtilityTypes
258
- });
259
- }
260
- const files = [];
261
- if (allNamespaceData.length > 0) {
262
- const content = generateUnifiedKyselyTypes(allNamespaceData);
263
- files.push({
264
- path: ctx.pluginConfig.distPath,
265
- content
266
- });
267
- }
268
- return { files };
269
- }
270
- };
271
- }
272
-
273
- //#endregion
274
- export { KyselyGeneratorID, kyselyTypePlugin };
275
- //# sourceMappingURL=index.mjs.map
1
+ import{n as e,r as t,t as n}from"../../../kysely-type-BTi3BMtL.mjs";export{n as DEFAULT_KYSELY_TYPES_DIST_PATH,e as KyselyGeneratorID,t as kyselyTypePlugin};
@@ -32,6 +32,11 @@ type SeedPluginOptions = {
32
32
  */
33
33
  disableIdpUserSync?: DisableIdpUserSyncDirections;
34
34
  };
35
+ declare module "@tailor-platform/sdk/plugin" {
36
+ interface PluginConfigRegistry {
37
+ "@tailor-platform/seed": SeedPluginOptions;
38
+ }
39
+ }
35
40
  /**
36
41
  * Plugin that generates seed data and schema files consumed by the
37
42
  * `tailor seed` commands (@tailor-platform/sdk-plugin-seed).
@@ -1,3 +1 @@
1
- import { n as seedPlugin, t as SeedGeneratorID } from "../../../seed-xqM9WIHP.mjs";
2
-
3
- export { SeedGeneratorID, seedPlugin };
1
+ import{n as e,t}from"../../../seed-DwqRFdqP.mjs";export{t as SeedGeneratorID,e as seedPlugin};
@@ -1,6 +1,4 @@
1
- import "../../../parser/service/tailordb/types.mjs";
2
1
  import "../../types.mjs";
3
- import "./types.mjs";
4
2
  //#region src/plugin/builtin/seed/seed-type-processor.d.ts
5
3
  /**
6
4
  * Seed ordering information for a TailorDB namespace.
@@ -8,13 +6,13 @@ import "./types.mjs";
8
6
  interface SeedNamespaceConfig {
9
7
  /** TailorDB namespace name. */
10
8
  namespace: string;
11
- /** Type names in the namespace, in definition order. */
9
+ /** Table names in the namespace, in definition order. */
12
10
  types: string[];
13
- /** Seed dependencies (referenced type names) per type. */
11
+ /** Seed dependencies (referenced table names) per table. */
14
12
  dependencies: Record<string, string[]>;
15
- /** Types with self-referencing fields, seeded in two passes. */
13
+ /** Tables with self-referencing fields, seeded in two passes. */
16
14
  selfRefTypes: string[];
17
- /** Field names a seed row must supply per type, enforced with `--upsert`. */
15
+ /** Field names a seed row must supply per table, enforced with `--upsert`. */
18
16
  requiredFields: Record<string, string[]>;
19
17
  }
20
18
  //#endregion
@@ -0,0 +1,16 @@
1
+ import { TailorAnyDBType } from "../configure/services/tailordb/types.mjs";
2
+ //#region src/plugin/get-generated-table.d.ts
3
+ /**
4
+ * Get a generated table from a plugin by loading the config and resolving everything automatically.
5
+ * For table-attached plugins, calls onTableLoaded() with the source table.
6
+ * For namespace plugins, calls onNamespaceLoaded() with auto-resolved namespace.
7
+ * Results are cached per config path, plugin, namespace, and pluginConfig to avoid redundant processing.
8
+ * @param configPath - Path to tailor.config.ts (absolute or relative to cwd)
9
+ * @param pluginId - The plugin's unique identifier
10
+ * @param sourceTable - The source TailorDB table (null for namespace plugins)
11
+ * @param kind - The generated table kind (e.g., "request", "step")
12
+ * @returns The generated TailorDB table
13
+ */
14
+ declare function getGeneratedTable(configPath: string, pluginId: string, sourceTable: TailorAnyDBType | null, kind: string): Promise<TailorAnyDBType>;
15
+ //#endregion
16
+ export { getGeneratedTable };
@@ -1,3 +1,4 @@
1
+ import { PluginConfigRegistry } from "./types.mjs";
1
2
  import { PluginDBSchema, PluginExecutorFactory, PluginFunctionArgs, PluginRecord, PluginRecordCreatedArgs, PluginRecordDeletedArgs, PluginRecordUpdatedArgs, withPluginContext } from "./with-context.mjs";
2
- import { getGeneratedType } from "./get-generated-type.mjs";
3
- export { type PluginDBSchema, type PluginExecutorFactory, type PluginFunctionArgs, type PluginRecord, type PluginRecordCreatedArgs, type PluginRecordDeletedArgs, type PluginRecordUpdatedArgs, getGeneratedType, withPluginContext };
3
+ import { getGeneratedTable } from "./get-generated-table.mjs";
4
+ export { type PluginConfigRegistry, type PluginDBSchema, type PluginExecutorFactory, type PluginFunctionArgs, type PluginRecord, type PluginRecordCreatedArgs, type PluginRecordDeletedArgs, type PluginRecordUpdatedArgs, getGeneratedTable, withPluginContext };
@@ -1,252 +1,2 @@
1
- import * as path from "pathe";
2
- import * as fs from "node:fs";
3
- import { pathToFileURL } from "node:url";
4
-
5
- //#region src/plugin/with-context.ts
6
- /**
7
- * Define a plugin executor that receives context at runtime.
8
- * This allows executor definitions to be in separate files while
9
- * still receiving dynamic values like typeName, generated types, and namespace.
10
- * @param factory - Function that takes context and returns executor configuration
11
- * @returns The same factory function (for type inference)
12
- * @example
13
- * ```typescript
14
- * // executors/on-create.ts
15
- * import { withPluginContext } from "@tailor-platform/sdk/plugin";
16
- * import { createExecutor, recordCreatedTrigger } from "@tailor-platform/sdk";
17
- * import { getDB } from "@tailor-platform/function-kysely-tailordb";
18
- *
19
- * interface MyContext {
20
- * sourceType: TailorAnyDBType;
21
- * historyType: TailorAnyDBType;
22
- * namespace: string;
23
- * }
24
- *
25
- * export default withPluginContext<MyContext>((ctx) =>
26
- * createExecutor({
27
- * name: `${ctx.sourceType.name.toLowerCase()}-on-create`,
28
- * trigger: recordCreatedTrigger({ type: ctx.sourceType }),
29
- * operation: {
30
- * kind: "function",
31
- * body: async (args) => {
32
- * const db = getDB(ctx.namespace);
33
- * await db.insertInto(ctx.historyType.name).values({
34
- * recordId: args.newRecord.id,
35
- * // ...
36
- * }).execute();
37
- * },
38
- * },
39
- * })
40
- * );
41
- * ```
42
- */
43
- function withPluginContext(factory) {
44
- return factory;
45
- }
46
-
47
- //#endregion
48
- //#region src/plugin/get-generated-type.ts
49
- /** Cache: resolved config path -> loaded config data */
50
- const configCacheMap = /* @__PURE__ */ new Map();
51
- /**
52
- * Check if a value is a Plugin instance.
53
- * @param value - Value to check
54
- * @returns True if value has the shape of Plugin
55
- */
56
- function isPlugin(value) {
57
- return typeof value === "object" && value !== null && typeof value.id === "string" && typeof value.description === "string";
58
- }
59
- /**
60
- * Load and cache config module from the given path.
61
- * Extracts plugins from all array exports using definePlugins() format.
62
- * Returns null if the config file does not exist (e.g., in bundled executor on platform server).
63
- * @param configPath - Absolute or relative path to tailor.config.ts
64
- * @returns Cached config data with plugins map, or null if config file is not available
65
- */
66
- async function loadAndCacheConfig(configPath) {
67
- const resolvedPath = path.resolve(configPath);
68
- const cached = configCacheMap.get(resolvedPath);
69
- if (cached) return cached;
70
- if (!fs.existsSync(resolvedPath)) return null;
71
- const configModule = await import(pathToFileURL(resolvedPath).href);
72
- if (!configModule?.default) throw new Error(`Invalid config module at "${resolvedPath}": default export not found`);
73
- const config = configModule.default;
74
- const configDir = path.dirname(resolvedPath);
75
- const plugins = /* @__PURE__ */ new Map();
76
- for (const value of Object.values(configModule)) {
77
- if (!Array.isArray(value)) continue;
78
- for (const item of value) if (isPlugin(item)) plugins.set(item.id, {
79
- plugin: item,
80
- pluginConfig: item.pluginConfig
81
- });
82
- }
83
- const result = {
84
- config,
85
- plugins,
86
- configDir
87
- };
88
- configCacheMap.set(resolvedPath, result);
89
- return result;
90
- }
91
- /**
92
- * Resolve the namespace for a type-attached sourceType by checking config.db file patterns.
93
- * Uses ESM module cache identity: same file path yields same object references.
94
- * @param config - App config with db namespace definitions
95
- * @param config.db - DB namespace definitions
96
- * @param configDir - Directory containing the config file
97
- * @param sourceType - The TailorDB type to look up
98
- * @returns The namespace name
99
- */
100
- async function resolveNamespaceForType(config, configDir, sourceType) {
101
- if (!config.db) throw new Error(`No db configuration found in config`);
102
- for (const [namespace, nsConfig] of Object.entries(config.db)) {
103
- const dbConfig = nsConfig;
104
- if (dbConfig.external || !dbConfig.files) continue;
105
- for (const pattern of dbConfig.files) {
106
- const absolutePattern = path.resolve(configDir, pattern);
107
- let matchedFiles;
108
- try {
109
- matchedFiles = fs.globSync(absolutePattern);
110
- } catch {
111
- continue;
112
- }
113
- for (const file of matchedFiles) {
114
- const mod = await import(pathToFileURL(file).href);
115
- for (const exported of Object.values(mod)) if (exported === sourceType) return namespace;
116
- }
117
- }
118
- }
119
- throw new Error(`Could not resolve namespace for type "${sourceType.name}". Ensure the type file is included in a db namespace's files pattern.`);
120
- }
121
- /**
122
- * Resolve the namespace for a namespace plugin by trying each namespace.
123
- * Calls onNamespaceLoaded() for each and returns the first whose output contains the requested kind.
124
- * @param config - App config with db namespace definitions
125
- * @param config.db - DB namespace definitions
126
- * @param plugin - Plugin instance
127
- * @param kind - The generated type kind to look for
128
- * @param pluginConfig - Plugin-level configuration
129
- * @returns The namespace name
130
- */
131
- async function resolveNamespaceForNamespacePlugin(config, plugin, kind, pluginConfig) {
132
- if (!config.db) throw new Error(`No db configuration found in config`);
133
- if (!plugin.onNamespaceLoaded) throw new Error(`Plugin "${plugin.id}" does not have a onNamespaceLoaded() method`);
134
- for (const namespace of Object.keys(config.db)) {
135
- if (config.db[namespace].external) continue;
136
- const output = await plugin.onNamespaceLoaded({
137
- pluginConfig,
138
- namespace
139
- });
140
- if (output.types?.[kind]) return {
141
- namespace,
142
- output
143
- };
144
- }
145
- throw new Error(`Could not resolve namespace for plugin "${plugin.id}" with kind "${kind}". No namespace produced a type with that kind.`);
146
- }
147
- const processCache = /* @__PURE__ */ new WeakMap();
148
- const namespaceProcessCache = /* @__PURE__ */ new WeakMap();
149
- /**
150
- * Generate a cache key that includes pluginConfig.
151
- * @param baseKey - Base key for the cache
152
- * @param pluginConfig - Plugin configuration to include in the key
153
- * @returns Cache key string
154
- */
155
- function getCacheKey(baseKey, pluginConfig) {
156
- if (pluginConfig === void 0) return baseKey;
157
- try {
158
- return `${baseKey}:${JSON.stringify(pluginConfig)}`;
159
- } catch {
160
- throw new Error(`pluginConfig must be JSON-serializable for caching. Received non-serializable value.`);
161
- }
162
- }
163
- /**
164
- * Get a generated type from a plugin by loading the config and resolving everything automatically.
165
- * For type-attached plugins, calls onTypeLoaded() with the sourceType.
166
- * For namespace plugins, calls onNamespaceLoaded() with auto-resolved namespace.
167
- * Results are cached per config path, plugin, namespace, and pluginConfig to avoid redundant processing.
168
- * @param configPath - Path to tailor.config.ts (absolute or relative to cwd)
169
- * @param pluginId - The plugin's unique identifier
170
- * @param sourceType - The source TailorDB type (null for namespace plugins)
171
- * @param kind - The generated type kind (e.g., "request", "step")
172
- * @returns The generated TailorDB type
173
- */
174
- async function getGeneratedType(configPath, pluginId, sourceType, kind) {
175
- const cache = await loadAndCacheConfig(configPath);
176
- if (!cache) return {
177
- name: `__placeholder_${kind}__`,
178
- fields: {}
179
- };
180
- const { config, configDir, plugins } = cache;
181
- const pluginEntry = plugins.get(pluginId);
182
- if (!pluginEntry) throw new Error(`Plugin "${pluginId}" not found in config at "${configPath}". Ensure the plugin is registered via definePlugins().`);
183
- const { plugin, pluginConfig } = pluginEntry;
184
- if (sourceType === null) return getGeneratedTypeForNamespacePlugin(config, plugin, kind, pluginConfig);
185
- return getGeneratedTypeForTypeAttachedPlugin(plugin, sourceType, kind, pluginConfig, await resolveNamespaceForType(config, configDir, sourceType));
186
- }
187
- /**
188
- * Get a generated type from a type-attached plugin.
189
- * @param plugin - The plugin instance (must have onTypeLoaded() method)
190
- * @param sourceType - The source TailorDB type
191
- * @param kind - The generated type kind
192
- * @param pluginConfig - Plugin-level configuration
193
- * @param namespace - Resolved namespace
194
- * @returns The generated TailorDB type
195
- */
196
- async function getGeneratedTypeForTypeAttachedPlugin(plugin, sourceType, kind, pluginConfig, namespace) {
197
- if (!plugin.onTypeLoaded) throw new Error(`Plugin "${plugin.id}" does not have a onTypeLoaded() method`);
198
- let pluginCache = processCache.get(plugin);
199
- if (!pluginCache) {
200
- pluginCache = /* @__PURE__ */ new Map();
201
- processCache.set(plugin, pluginCache);
202
- }
203
- const cacheKey = getCacheKey(`${sourceType.name}:ns=${namespace}`, pluginConfig);
204
- let output = pluginCache.get(cacheKey);
205
- if (!output) {
206
- const typeConfig = sourceType.plugins.find((p) => p.pluginId === plugin.id)?.config;
207
- output = await plugin.onTypeLoaded({
208
- type: sourceType,
209
- typeConfig: typeConfig ?? {},
210
- pluginConfig,
211
- namespace
212
- });
213
- pluginCache.set(cacheKey, output);
214
- }
215
- const generatedType = output.types?.[kind];
216
- if (!generatedType) throw new Error(`Generated type not found: plugin=${plugin.id}, sourceType=${sourceType.name}, kind=${kind}`);
217
- return generatedType;
218
- }
219
- /**
220
- * Get a generated type from a namespace plugin.
221
- * Auto-resolves the namespace by trying each one.
222
- * @param config - App config with db namespace definitions
223
- * @param config.db - DB namespace definitions
224
- * @param plugin - The plugin instance (must have onNamespaceLoaded() method)
225
- * @param kind - The generated type kind
226
- * @param pluginConfig - Plugin-level configuration
227
- * @returns The generated TailorDB type
228
- */
229
- async function getGeneratedTypeForNamespacePlugin(config, plugin, kind, pluginConfig) {
230
- if (!plugin.onNamespaceLoaded) throw new Error(`Plugin "${plugin.id}" does not have a onNamespaceLoaded() method`);
231
- let pluginCache = namespaceProcessCache.get(plugin);
232
- if (!pluginCache) {
233
- pluginCache = /* @__PURE__ */ new Map();
234
- namespaceProcessCache.set(plugin, pluginCache);
235
- }
236
- if (config.db) for (const namespace of Object.keys(config.db)) {
237
- if (config.db[namespace].external) continue;
238
- const cacheKey = getCacheKey(`namespace:ns=${namespace}`, pluginConfig);
239
- const cached = pluginCache.get(cacheKey);
240
- if (cached?.types?.[kind]) return cached.types[kind];
241
- }
242
- const { namespace, output } = await resolveNamespaceForNamespacePlugin(config, plugin, kind, pluginConfig);
243
- const cacheKey = getCacheKey(`namespace:ns=${namespace}`, pluginConfig);
244
- pluginCache.set(cacheKey, output);
245
- const generatedType = output.types?.[kind];
246
- if (!generatedType) throw new Error(`Generated type not found: plugin=${plugin.id}, kind=${kind}`);
247
- return generatedType;
248
- }
249
-
250
- //#endregion
251
- export { getGeneratedType, withPluginContext };
1
+ import*as e from"pathe";import*as t from"node:fs";import{pathToFileURL as n}from"node:url";function withPluginContext(e){return e}const r=new Map;function isPlugin(e){return typeof e==`object`&&!!e&&typeof e.id==`string`&&typeof e.description==`string`}async function loadAndCacheConfig(i){let a=e.resolve(i),o=r.get(a);if(o)return o;if(!t.existsSync(a))return null;let s=await import(n(a).href);if(!s?.default)throw Error(`Invalid config module at "${a}": default export not found`);let c=s.default,l=e.dirname(a),u=new Map;for(let e of Object.values(s))if(Array.isArray(e))for(let t of e)isPlugin(t)&&u.set(t.id,{plugin:t,pluginConfig:t.pluginConfig});let d={config:c,plugins:u,configDir:l};return r.set(a,d),d}async function resolveNamespaceForTable(r,i,a){if(!r.db)throw Error(`No db configuration found in config`);for(let[o,s]of Object.entries(r.db)){let r=s;if(!(r.external||!r.files))for(let s of r.files){let r=e.resolve(i,s),c;try{c=t.globSync(r)}catch{continue}for(let e of c){let t=await import(n(e).href);for(let e of Object.values(t))if(e===a)return o}}}throw Error(`Could not resolve namespace for table "${a.name}". Ensure the table file is included in a db namespace's files pattern.`)}async function resolveNamespaceForNamespacePlugin(e,t,n,r){if(!e.db)throw Error(`No db configuration found in config`);if(!t.onNamespaceLoaded)throw Error(`Plugin "${t.id}" does not have a onNamespaceLoaded() method`);for(let i of Object.keys(e.db)){if(e.db[i].external)continue;let a=await t.onNamespaceLoaded({pluginConfig:r,namespace:i});if(a.tables?.[n])return{namespace:i,output:a}}throw Error(`Could not resolve namespace for plugin "${t.id}" with kind "${n}". No namespace produced a table with that kind.`)}const i=new WeakMap,a=new WeakMap;function getCacheKey(e,t){if(t===void 0)return e;try{return`${e}:${JSON.stringify(t)}`}catch{throw Error(`pluginConfig must be JSON-serializable for caching. Received non-serializable value.`)}}async function getGeneratedTable(e,t,n,r){let i=await loadAndCacheConfig(e);if(!i)return{name:`__placeholder_${r}__`,fields:{}};let{config:a,configDir:o,plugins:s}=i,c=s.get(t);if(!c)throw Error(`Plugin "${t}" not found in config at "${e}". Ensure the plugin is registered via definePlugins().`);let{plugin:l,pluginConfig:u}=c;return n===null?getGeneratedTableForNamespacePlugin(a,l,r,u):getGeneratedTableForTableAttachedPlugin(l,n,r,u,await resolveNamespaceForTable(a,o,n))}async function getGeneratedTableForTableAttachedPlugin(e,t,n,r,a){if(!e.onTableLoaded)throw Error(`Plugin "${e.id}" does not have an onTableLoaded() method`);let o=i.get(e);o||(o=new Map,i.set(e,o));let s=getCacheKey(`${t.name}:ns=${a}`,r),c=o.get(s);if(!c){let n=t.plugins.find(t=>t.pluginId===e.id)?.config;c=await e.onTableLoaded({table:t,tableConfig:n??{},pluginConfig:r,namespace:a}),o.set(s,c)}let l=c.tables?.[n];if(!l)throw Error(`Generated table not found: plugin=${e.id}, sourceTable=${t.name}, kind=${n}`);return l}async function getGeneratedTableForNamespacePlugin(e,t,n,r){if(!t.onNamespaceLoaded)throw Error(`Plugin "${t.id}" does not have a onNamespaceLoaded() method`);let i=a.get(t);if(i||(i=new Map,a.set(t,i)),e.db)for(let t of Object.keys(e.db)){if(e.db[t].external)continue;let a=getCacheKey(`namespace:ns=${t}`,r),o=i.get(a);if(o?.tables?.[n])return o.tables[n]}let{namespace:o,output:s}=await resolveNamespaceForNamespacePlugin(e,t,n,r),c=getCacheKey(`namespace:ns=${o}`,r);i.set(c,s);let l=s.tables?.[n];if(!l)throw Error(`Generated table not found: plugin=${t.id}, kind=${n}`);return l}export{getGeneratedTable,withPluginContext};
252
2
  //# sourceMappingURL=index.mjs.map