@tailor-platform/sdk 2.0.0-next.0 → 2.0.0-next.10

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 (497) hide show
  1. package/CHANGELOG.md +972 -0
  2. package/README.md +9 -9
  3. package/agent-skills/{tailor-sdk → tailor}/SKILL.md +3 -1
  4. package/dist/aigateway-DR4Kwuik.mjs +9 -0
  5. package/dist/aigateway-DR4Kwuik.mjs.map +1 -0
  6. package/dist/application-DArFTTJ9.mjs +3 -0
  7. package/dist/{application-76hhIhnJ.mjs → application-miwiXtB4.mjs} +1963 -1953
  8. package/dist/application-miwiXtB4.mjs.map +1 -0
  9. package/dist/{assert-CKfwrmCV.mjs → assert-DBxo8jPo.mjs} +1 -2
  10. package/dist/{assert-CKfwrmCV.mjs.map → assert-DBxo8jPo.mjs.map} +1 -1
  11. package/dist/authconnection-CZvi9ANm.mjs +9 -0
  12. package/dist/authconnection-CZvi9ANm.mjs.map +1 -0
  13. package/dist/{brand-DlnJ375c.mjs → brand-Eo4pLXPJ.mjs} +1 -2
  14. package/dist/brand-Eo4pLXPJ.mjs.map +1 -0
  15. package/dist/cli/cache/bundle-cache.d.mts +2 -0
  16. package/dist/cli/cache/store.d.mts +1 -0
  17. package/dist/cli/cache/types.d.mts +1 -0
  18. package/dist/cli/commands/api/api-call.d.mts +19 -0
  19. package/dist/cli/commands/api/index.d.mts +4 -0
  20. package/dist/cli/commands/deploy/aigateway.d.mts +5 -0
  21. package/dist/cli/commands/deploy/application.d.mts +7 -0
  22. package/dist/cli/commands/deploy/apply-phases.d.mts +14 -0
  23. package/dist/cli/commands/deploy/auth.d.mts +5 -0
  24. package/dist/cli/commands/deploy/deploy.d.mts +34 -0
  25. package/dist/cli/commands/deploy/executor.d.mts +7 -0
  26. package/dist/cli/commands/deploy/function-registry-types.d.mts +12 -0
  27. package/dist/cli/commands/deploy/function-registry.d.mts +7 -0
  28. package/dist/cli/commands/deploy/idp.d.mts +5 -0
  29. package/dist/cli/commands/deploy/resolver.d.mts +5 -0
  30. package/dist/cli/commands/deploy/secret-manager.d.mts +5 -0
  31. package/dist/cli/commands/deploy/staticwebsite.d.mts +5 -0
  32. package/dist/cli/commands/deploy/tailordb/index.d.mts +9 -0
  33. package/dist/cli/commands/deploy/types.d.mts +3 -0
  34. package/dist/cli/commands/deploy/workflow-execution-policy.d.mts +3 -0
  35. package/dist/cli/commands/deploy/workflow.d.mts +4 -0
  36. package/dist/cli/commands/executor/get.d.mts +28 -0
  37. package/dist/cli/commands/executor/jobs.d.mts +122 -0
  38. package/dist/cli/commands/executor/list.d.mts +18 -0
  39. package/dist/cli/commands/executor/transform.d.mts +42 -0
  40. package/dist/cli/commands/executor/trigger.d.mts +40 -0
  41. package/dist/cli/commands/executor/webhook.d.mts +21 -0
  42. package/dist/cli/commands/function/get.d.mts +17 -0
  43. package/dist/cli/commands/function/list.d.mts +21 -0
  44. package/dist/cli/commands/function/transform.d.mts +12 -0
  45. package/dist/cli/commands/generate/options.d.mts +6 -0
  46. package/dist/cli/commands/generate/seed/bundler.d.mts +26 -0
  47. package/dist/cli/commands/generate/service.d.mts +15 -0
  48. package/dist/cli/commands/machineuser/list.d.mts +26 -0
  49. package/dist/cli/commands/machineuser/token.d.mts +21 -0
  50. package/dist/cli/commands/oauth2client/get.d.mts +17 -0
  51. package/dist/cli/commands/oauth2client/list.d.mts +19 -0
  52. package/dist/cli/commands/oauth2client/transform.d.mts +21 -0
  53. package/dist/cli/commands/organization/folder/create.d.mts +17 -0
  54. package/dist/cli/commands/organization/folder/delete.d.mts +15 -0
  55. package/dist/cli/commands/organization/folder/get.d.mts +16 -0
  56. package/dist/cli/commands/organization/folder/list.d.mts +21 -0
  57. package/dist/cli/commands/organization/folder/update.d.mts +17 -0
  58. package/dist/cli/commands/organization/get.d.mts +15 -0
  59. package/dist/cli/commands/organization/list.d.mts +14 -0
  60. package/dist/cli/commands/organization/transform.d.mts +29 -0
  61. package/dist/cli/commands/organization/tree.d.mts +24 -0
  62. package/dist/cli/commands/organization/update.d.mts +16 -0
  63. package/dist/cli/commands/remove.d.mts +15 -0
  64. package/dist/cli/commands/show.d.mts +39 -0
  65. package/dist/cli/commands/staticwebsite/deploy.d.mts +19 -0
  66. package/dist/cli/commands/tailordb/migrate/bundler.d.mts +29 -0
  67. package/dist/cli/commands/tailordb/migrate/config.d.mts +18 -0
  68. package/dist/cli/commands/tailordb/migrate/diff-calculator.d.mts +246 -0
  69. package/dist/cli/commands/tailordb/migrate/generate.d.mts +16 -0
  70. package/dist/cli/commands/tailordb/migrate/snapshot-types.d.mts +208 -0
  71. package/dist/cli/commands/tailordb/migrate/snapshot.d.mts +98 -0
  72. package/dist/cli/commands/tailordb/migrate/types.d.mts +7 -0
  73. package/dist/cli/commands/tailordb/truncate.d.mts +18 -0
  74. package/dist/cli/commands/workflow/executions.d.mts +74 -0
  75. package/dist/cli/commands/workflow/get.d.mts +30 -0
  76. package/dist/cli/commands/workflow/list.d.mts +18 -0
  77. package/dist/cli/commands/workflow/resume.d.mts +22 -0
  78. package/dist/cli/commands/workflow/start.d.mts +60 -0
  79. package/dist/cli/commands/workflow/status.d.mts +6 -0
  80. package/dist/cli/commands/workflow/transform.d.mts +34 -0
  81. package/dist/cli/commands/workflow/wait.d.mts +15 -0
  82. package/dist/cli/commands/workflow/waiter.d.mts +23 -0
  83. package/dist/cli/commands/workspace/app/health.d.mts +17 -0
  84. package/dist/cli/commands/workspace/app/list.d.mts +21 -0
  85. package/dist/cli/commands/workspace/app/transform.d.mts +20 -0
  86. package/dist/cli/commands/workspace/create.d.mts +27 -0
  87. package/dist/cli/commands/workspace/delete.d.mts +14 -0
  88. package/dist/cli/commands/workspace/get.d.mts +16 -0
  89. package/dist/cli/commands/workspace/list.d.mts +17 -0
  90. package/dist/cli/commands/workspace/restore.d.mts +14 -0
  91. package/dist/cli/commands/workspace/transform.d.mts +20 -0
  92. package/dist/cli/commands/workspace/user/invite.d.mts +21 -0
  93. package/dist/cli/commands/workspace/user/list.d.mts +21 -0
  94. package/dist/cli/commands/workspace/user/remove.d.mts +16 -0
  95. package/dist/cli/commands/workspace/user/transform.d.mts +9 -0
  96. package/dist/cli/commands/workspace/user/update.d.mts +21 -0
  97. package/dist/cli/index.mjs +12 -5534
  98. package/dist/cli/lib.d.mts +90 -21180
  99. package/dist/cli/lib.mjs +157 -16
  100. package/dist/cli/lib.mjs.map +1 -1
  101. package/dist/cli/main.d.mts +23 -0
  102. package/dist/cli/main.mjs +6583 -0
  103. package/dist/cli/main.mjs.map +1 -0
  104. package/dist/cli/query/index.d.mts +38 -0
  105. package/dist/cli/services/application.d.mts +12 -0
  106. package/dist/cli/services/auth/service.d.mts +3 -0
  107. package/dist/cli/services/executor/service.d.mts +1 -0
  108. package/dist/cli/services/http-adapter/bundler.d.mts +3 -0
  109. package/dist/cli/services/http-adapter/service.d.mts +2 -0
  110. package/dist/cli/services/resolver/service.d.mts +1 -0
  111. package/dist/cli/services/tailordb/service.d.mts +3 -0
  112. package/dist/cli/services/workflow/bundler.d.mts +2 -0
  113. package/dist/cli/services/workflow/service.d.mts +1 -0
  114. package/dist/cli/shared/args.d.mts +13 -0
  115. package/dist/cli/shared/client.d.mts +1273 -0
  116. package/dist/cli/shared/config-loader.d.mts +25 -0
  117. package/dist/cli/shared/context.d.mts +29 -0
  118. package/dist/cli/shared/error-json.d.mts +23 -0
  119. package/dist/cli/shared/readonly-guard.d.mts +25 -0
  120. package/dist/cli/shared/script-executor.d.mts +77 -0
  121. package/dist/cli/shared/seed-chunker.d.mts +45 -0
  122. package/dist/cli/shared/seed-context.d.mts +49 -0
  123. package/dist/cli/shared/tailordb-namespaces.d.mts +40 -0
  124. package/dist/cli/shared/type-generator.d.mts +19 -0
  125. package/dist/cli/shared/workspace-name.d.mts +1 -0
  126. package/dist/cli/ts-hook.d.mts +4 -0
  127. package/dist/cli/ts-hook.mjs +333 -0
  128. package/dist/completion/zsh-worker.zsh +4223 -0
  129. package/dist/configure/config/index.d.mts +20 -0
  130. package/dist/configure/config/types.d.mts +111 -0
  131. package/dist/configure/index.d.mts +135 -7
  132. package/dist/configure/index.mjs +409 -56
  133. package/dist/configure/index.mjs.map +1 -1
  134. package/dist/configure/services/aigateway/index.d.mts +16 -0
  135. package/dist/configure/services/aigateway/types.d.mts +10 -0
  136. package/dist/configure/services/auth/index.d.mts +33 -0
  137. package/dist/configure/services/auth/types.d.mts +168 -0
  138. package/dist/configure/services/executor/executor.d.mts +70 -0
  139. package/dist/configure/services/executor/index.d.mts +9 -0
  140. package/dist/configure/services/executor/operation.d.mts +50 -0
  141. package/dist/configure/services/executor/trigger/event.d.mts +271 -0
  142. package/dist/configure/services/executor/trigger/index.d.mts +7 -0
  143. package/dist/configure/services/executor/trigger/schedule.d.mts +24 -0
  144. package/dist/configure/services/executor/trigger/webhook.d.mts +43 -0
  145. package/dist/configure/services/executor/types.d.mts +2 -0
  146. package/dist/configure/services/http-adapter/http-adapter.d.mts +124 -0
  147. package/dist/configure/services/http-adapter/index.d.mts +2 -0
  148. package/dist/configure/services/idp/index.d.mts +60 -0
  149. package/dist/configure/services/idp/permission.d.mts +64 -0
  150. package/dist/configure/services/idp/types.d.mts +23 -0
  151. package/dist/configure/services/index.d.mts +40 -0
  152. package/dist/configure/services/resolver/index.d.mts +6 -0
  153. package/dist/configure/services/resolver/permission.d.mts +64 -0
  154. package/dist/configure/services/resolver/resolver.d.mts +88 -0
  155. package/dist/configure/services/resolver/types.d.mts +5 -0
  156. package/dist/configure/services/secrets/index.d.mts +37 -0
  157. package/dist/configure/services/secrets/types.d.mts +10 -0
  158. package/dist/configure/services/staticwebsite/index.d.mts +18 -0
  159. package/dist/configure/services/staticwebsite/types.d.mts +10 -0
  160. package/dist/configure/services/tailordb/index.d.mts +4 -0
  161. package/dist/configure/services/tailordb/permission.d.mts +103 -0
  162. package/dist/configure/services/tailordb/schema.d.mts +486 -0
  163. package/dist/configure/services/tailordb/types.d.mts +198 -0
  164. package/dist/configure/services/workflow/execution-policy.d.mts +70 -0
  165. package/dist/configure/services/workflow/execution-policy.types.d.mts +103 -0
  166. package/dist/configure/services/workflow/index.d.mts +9 -0
  167. package/dist/configure/services/workflow/job.d.mts +83 -0
  168. package/dist/configure/services/workflow/types.d.mts +2 -0
  169. package/dist/configure/services/workflow/wait-point.d.mts +72 -0
  170. package/dist/configure/services/workflow/workflow.d.mts +56 -0
  171. package/dist/configure/types/aigateway-name.d.mts +12 -0
  172. package/dist/configure/types/connection-name.d.mts +12 -0
  173. package/dist/configure/types/field.d.mts +8 -0
  174. package/dist/configure/types/field.types.d.mts +70 -0
  175. package/dist/configure/types/idp-name.d.mts +12 -0
  176. package/dist/configure/types/index.d.mts +5 -0
  177. package/dist/configure/types/machine-user.d.mts +2 -0
  178. package/dist/configure/types/permission-operand.types.d.mts +20 -0
  179. package/dist/configure/types/type.d.mts +73 -0
  180. package/dist/{context-s0lxhu8_.mjs → context-DYQVYWqZ.mjs} +4 -6
  181. package/dist/context-DYQVYWqZ.mjs.map +1 -0
  182. package/dist/{crashreport-BhD0y14F.mjs → crashreport-B5LqCTfF.mjs} +25 -17
  183. package/dist/{crashreport-BhD0y14F.mjs.map → crashreport-B5LqCTfF.mjs.map} +1 -1
  184. package/dist/{crashreport-D1wKBJ8N.mjs → crashreport-eI7ty7ok.mjs} +1 -2
  185. package/dist/{enum-constants-C7DaWeQo.mjs → enum-constants-j9QBF0cB.mjs} +1 -2
  186. package/dist/enum-constants-j9QBF0cB.mjs.map +1 -0
  187. package/dist/{errors-EsY4XO6O.mjs → errors-D7583Zz7.mjs} +18 -3
  188. package/dist/errors-D7583Zz7.mjs.map +1 -0
  189. package/dist/{file-B58Dm-2P.mjs → file-BUcmVIH2.mjs} +12 -23
  190. package/dist/file-BUcmVIH2.mjs.map +1 -0
  191. package/dist/{file-utils-BHPxPXmn.mjs → file-utils-yEiIS4nJ.mjs} +7 -8
  192. package/dist/file-utils-yEiIS4nJ.mjs.map +1 -0
  193. package/dist/{globals-ByrCoDip.mjs → globals-DQotNuwK.mjs} +32 -6
  194. package/dist/globals-DQotNuwK.mjs.map +1 -0
  195. package/dist/iconv-QWaZh0TT.mjs +38 -0
  196. package/dist/iconv-QWaZh0TT.mjs.map +1 -0
  197. package/dist/{idp-Ch95ag8h.mjs → idp-RA_swu-h.mjs} +12 -6
  198. package/dist/idp-RA_swu-h.mjs.map +1 -0
  199. package/dist/{interceptor-DOqRkCya.mjs → interceptor-e33JtsC-.mjs} +2 -3
  200. package/dist/interceptor-e33JtsC-.mjs.map +1 -0
  201. package/dist/kysely/index.d.mts +5 -7
  202. package/dist/kysely/index.mjs +0 -1
  203. package/dist/kysely/index.mjs.map +1 -1
  204. package/dist/{kysely-type-D1e0Vwkd.mjs → kysely-type-DqIRgDYR.mjs} +6 -6
  205. package/dist/kysely-type-DqIRgDYR.mjs.map +1 -0
  206. package/dist/logger-BtX0suGY.mjs +48 -0
  207. package/dist/logger-BtX0suGY.mjs.map +1 -0
  208. package/dist/logger-CXQq9YIp.mjs +317 -0
  209. package/dist/logger-CXQq9YIp.mjs.map +1 -0
  210. package/dist/{multiline-Cf9ODpr1.mjs → multiline-sfHpTZZK.mjs} +1 -2
  211. package/dist/{multiline-Cf9ODpr1.mjs.map → multiline-sfHpTZZK.mjs.map} +1 -1
  212. package/dist/{package-json-DcQApfPQ.mjs → package-json-8b0O9TlX.mjs} +1 -2
  213. package/dist/{package-json-DcQApfPQ.mjs.map → package-json-8b0O9TlX.mjs.map} +1 -1
  214. package/dist/package-json-Cv2Z-TqQ.mjs +3 -0
  215. package/dist/parser/service/auth/index.d.mts +1 -0
  216. package/dist/parser/service/auth/schema.d.mts +3 -0
  217. package/dist/parser/service/http-adapter/index.d.mts +1 -0
  218. package/dist/parser/service/http-adapter/schema.d.mts +1 -0
  219. package/dist/parser/service/idp/types.d.mts +5 -0
  220. package/dist/parser/service/tailordb/type-source.d.mts +10 -0
  221. package/dist/parser/service/tailordb/types.d.mts +131 -0
  222. package/dist/platform-serialize-RoRtBS0v.mjs +46 -0
  223. package/dist/platform-serialize-RoRtBS0v.mjs.map +1 -0
  224. package/dist/plugin/builtin/enum-constants/index.d.mts +15 -1
  225. package/dist/plugin/builtin/enum-constants/index.mjs +1 -2
  226. package/dist/plugin/builtin/file-utils/index.d.mts +15 -1
  227. package/dist/plugin/builtin/file-utils/index.mjs +1 -2
  228. package/dist/plugin/builtin/kysely-type/index.d.mts +15 -1
  229. package/dist/plugin/builtin/kysely-type/index.mjs +1 -2
  230. package/dist/plugin/builtin/seed/index.d.mts +46 -2
  231. package/dist/plugin/builtin/seed/index.mjs +1 -2
  232. package/dist/plugin/builtin/seed/seed-type-processor.d.mts +19 -0
  233. package/dist/plugin/builtin/seed/types.d.mts +2 -0
  234. package/dist/plugin/get-generated-type.d.mts +16 -0
  235. package/dist/plugin/index.d.mts +3 -119
  236. package/dist/plugin/index.mjs +1 -2
  237. package/dist/plugin/index.mjs.map +1 -1
  238. package/dist/plugin/manager.d.mts +2 -0
  239. package/dist/plugin/types.d.mts +242 -0
  240. package/dist/plugin/with-context.d.mts +101 -0
  241. package/dist/{runtime-C7qTBDD2.mjs → register-ts-hook-BAHMwxfG.mjs} +12374 -8672
  242. package/dist/register-ts-hook-BAHMwxfG.mjs.map +1 -0
  243. package/dist/registry-BIGVUrMB.mjs +54 -0
  244. package/dist/registry-BIGVUrMB.mjs.map +1 -0
  245. package/dist/{repl-editor-CJG3sz7A.mjs → repl-editor-BCozyiNq.mjs} +7 -7
  246. package/dist/{repl-editor-CJG3sz7A.mjs.map → repl-editor-BCozyiNq.mjs.map} +1 -1
  247. package/dist/runtime/aigateway.d.mts +25 -0
  248. package/dist/runtime/aigateway.mjs +3 -0
  249. package/dist/runtime/authconnection.d.mts +21 -2
  250. package/dist/runtime/authconnection.mjs +2 -3
  251. package/dist/runtime/context.d.mts +54 -2
  252. package/dist/runtime/context.mjs +2 -3
  253. package/dist/runtime/field-parse.d.mts +10 -0
  254. package/dist/runtime/file.d.mts +170 -2
  255. package/dist/runtime/file.mjs +2 -3
  256. package/dist/runtime/globals.d.mts +38 -53
  257. package/dist/runtime/globals.mjs +0 -1
  258. package/dist/runtime/iconv.d.mts +73 -2
  259. package/dist/runtime/iconv.mjs +2 -3
  260. package/dist/runtime/idp.d.mts +129 -2
  261. package/dist/runtime/idp.mjs +2 -3
  262. package/dist/runtime/index.d.mts +48 -9
  263. package/dist/runtime/index.mjs +10 -9
  264. package/dist/runtime/logger.d.mts +98 -0
  265. package/dist/runtime/logger.mjs +3 -0
  266. package/dist/runtime/secretmanager.d.mts +41 -2
  267. package/dist/runtime/secretmanager.mjs +2 -3
  268. package/dist/runtime/types.d.mts +25 -0
  269. package/dist/runtime/workflow.d.mts +124 -2
  270. package/dist/runtime/workflow.mjs +2 -3
  271. package/dist/{schema-1msIhXwA.mjs → schema--xYWRGfe.mjs} +289 -231
  272. package/dist/schema--xYWRGfe.mjs.map +1 -0
  273. package/dist/{secret-file-CWzF8rry.mjs → secret-file-C3J4Gy8r.mjs} +2 -3
  274. package/dist/{secret-file-CWzF8rry.mjs.map → secret-file-C3J4Gy8r.mjs.map} +1 -1
  275. package/dist/secretmanager-CYlpffsz.mjs +13 -0
  276. package/dist/secretmanager-CYlpffsz.mjs.map +1 -0
  277. package/dist/secretmanager-IY4UvinW.mjs +131 -0
  278. package/dist/secretmanager-IY4UvinW.mjs.map +1 -0
  279. package/dist/seed/index.d.mts +4 -4
  280. package/dist/seed/index.mjs +0 -1
  281. package/dist/seed/index.mjs.map +1 -1
  282. package/dist/seed-LUVr7jHL.mjs +444 -0
  283. package/dist/seed-LUVr7jHL.mjs.map +1 -0
  284. package/dist/{service-DMohAx8a2.mjs → service-B5WynBHQ.mjs} +3 -4
  285. package/dist/service-B5WynBHQ.mjs.map +1 -0
  286. package/dist/service-BNtPsK9Q.mjs +837 -0
  287. package/dist/service-BNtPsK9Q.mjs.map +1 -0
  288. package/dist/service-D5jn05ZI.mjs +3 -0
  289. package/dist/service_pb-BwZRiNug.mjs +167 -0
  290. package/dist/service_pb-BwZRiNug.mjs.map +1 -0
  291. package/dist/service_pb-wRkxUta6.mjs +3 -0
  292. package/dist/tailor-proto/src/tailor/v1/aigateway_pb.d.mts +203 -0
  293. package/dist/tailor-proto/src/tailor/v1/aigateway_resource_pb.d.mts +57 -0
  294. package/dist/tailor-proto/src/tailor/v1/application_pb.d.mts +315 -0
  295. package/dist/tailor-proto/src/tailor/v1/application_resource_pb.d.mts +160 -0
  296. package/dist/tailor-proto/src/tailor/v1/auth_pb.d.mts +2069 -0
  297. package/dist/tailor-proto/src/tailor/v1/auth_resource_pb.d.mts +865 -0
  298. package/dist/tailor-proto/src/tailor/v1/events_pb.d.mts +111 -0
  299. package/dist/tailor-proto/src/tailor/v1/events_resource_pb.d.mts +68 -0
  300. package/dist/tailor-proto/src/tailor/v1/executor_pb.d.mts +438 -0
  301. package/dist/tailor-proto/src/tailor/v1/executor_resource_pb.d.mts +563 -0
  302. package/dist/tailor-proto/src/tailor/v1/function_pb.d.mts +144 -0
  303. package/dist/tailor-proto/src/tailor/v1/function_registry_pb.d.mts +450 -0
  304. package/dist/tailor-proto/src/tailor/v1/function_resource_pb.d.mts +191 -0
  305. package/dist/tailor-proto/src/tailor/v1/http_adapter_resource_pb.d.mts +49 -0
  306. package/dist/tailor-proto/src/tailor/v1/idp_pb.d.mts +406 -0
  307. package/dist/tailor-proto/src/tailor/v1/idp_resource_pb.d.mts +429 -0
  308. package/dist/tailor-proto/src/tailor/v1/metadata_pb.d.mts +72 -0
  309. package/dist/tailor-proto/src/tailor/v1/metadata_resource_pb.d.mts +16 -0
  310. package/dist/tailor-proto/src/tailor/v1/meter_pb.d.mts +308 -0
  311. package/dist/tailor-proto/src/tailor/v1/pipeline_pb.d.mts +590 -0
  312. package/dist/tailor-proto/src/tailor/v1/pipeline_resource_pb.d.mts +329 -0
  313. package/dist/tailor-proto/src/tailor/v1/resource_pb.d.mts +112 -0
  314. package/dist/tailor-proto/src/tailor/v1/secret_manager_pb.d.mts +345 -0
  315. package/dist/tailor-proto/src/tailor/v1/secret_manager_resource_pb.d.mts +53 -0
  316. package/dist/tailor-proto/src/tailor/v1/service_pb.d.mts +3575 -0
  317. package/dist/tailor-proto/src/tailor/v1/stateflow_pb.d.mts +186 -0
  318. package/dist/tailor-proto/src/tailor/v1/stateflow_resource_pb.d.mts +28 -0
  319. package/dist/tailor-proto/src/tailor/v1/staticwebsite_pb.d.mts +428 -0
  320. package/dist/tailor-proto/src/tailor/v1/staticwebsite_resource_pb.d.mts +89 -0
  321. package/dist/tailor-proto/src/tailor/v1/tailordb_pb.d.mts +683 -0
  322. package/dist/tailor-proto/src/tailor/v1/tailordb_resource_pb.d.mts +796 -0
  323. package/dist/tailor-proto/src/tailor/v1/telemetryrouter_pb.d.mts +329 -0
  324. package/dist/tailor-proto/src/tailor/v1/telemetryrouter_resource_pb.d.mts +182 -0
  325. package/dist/tailor-proto/src/tailor/v1/workflow_pb.d.mts +861 -0
  326. package/dist/tailor-proto/src/tailor/v1/workflow_resource_pb.d.mts +309 -0
  327. package/dist/tailor-proto/src/tailor/v1/workspace_pb.d.mts +2014 -0
  328. package/dist/tailor-proto/src/tailor/v1/workspace_resource_pb.d.mts +482 -0
  329. package/dist/{telemetry-BQbbVo2t.mjs → telemetry-BRVdwh14.mjs} +4 -5
  330. package/dist/telemetry-BRVdwh14.mjs.map +1 -0
  331. package/dist/telemetry-CkbkeJxl.mjs +3 -0
  332. package/dist/test-env-key-D7UkZp99.mjs +75 -0
  333. package/dist/test-env-key-D7UkZp99.mjs.map +1 -0
  334. package/dist/type-source-DH_LH20p.mjs +13 -0
  335. package/dist/type-source-DH_LH20p.mjs.map +1 -0
  336. package/dist/types/aigateway.generated.d.mts +12 -0
  337. package/dist/types/app-config.generated.d.mts +4 -0
  338. package/dist/types/auth-connection.generated.d.mts +33 -0
  339. package/dist/types/auth.generated.d.mts +188 -0
  340. package/dist/types/executor.generated.d.mts +209 -0
  341. package/dist/types/helpers.d.mts +40 -0
  342. package/dist/types/http-adapter.generated.d.mts +28 -0
  343. package/dist/types/idp.generated.d.mts +626 -0
  344. package/dist/types/resolver.generated.d.mts +82 -0
  345. package/dist/types/secrets.generated.d.mts +14 -0
  346. package/dist/types/staticwebsite.generated.d.mts +14 -0
  347. package/dist/types/tailordb.generated.d.mts +468 -0
  348. package/dist/types/workflow.generated.d.mts +17 -0
  349. package/dist/user-agent-Bgsszb5I.mjs +28 -0
  350. package/dist/user-agent-Bgsszb5I.mjs.map +1 -0
  351. package/dist/utils/test/index.d.mts +6 -99
  352. package/dist/utils/test/index.mjs +60 -40
  353. package/dist/utils/test/index.mjs.map +1 -1
  354. package/dist/utils/test/mock.d.mts +86 -0
  355. package/dist/vitest/environment.d.mts +1 -2
  356. package/dist/vitest/environment.mjs +2 -3
  357. package/dist/vitest/environment.mjs.map +1 -1
  358. package/dist/vitest/index.d.mts +15 -392
  359. package/dist/vitest/index.mjs +1347 -9
  360. package/dist/vitest/index.mjs.map +1 -1
  361. package/dist/vitest/mock-kysely.d.mts +61 -0
  362. package/dist/vitest/mock.d.mts +10 -0
  363. package/dist/vitest/mocks/aigateway.d.mts +40 -0
  364. package/dist/vitest/mocks/authconnection.d.mts +38 -0
  365. package/dist/vitest/mocks/file.d.mts +58 -0
  366. package/dist/vitest/mocks/iconv.d.mts +51 -0
  367. package/dist/vitest/mocks/idp.d.mts +60 -0
  368. package/dist/vitest/mocks/logger.d.mts +45 -0
  369. package/dist/vitest/mocks/secretmanager.d.mts +44 -0
  370. package/dist/vitest/mocks/tailordb.d.mts +115 -0
  371. package/dist/vitest/mocks/workflow.d.mts +157 -0
  372. package/dist/vitest/setup.d.mts +1 -2
  373. package/dist/vitest/setup.mjs +2 -3
  374. package/dist/vitest/setup.mjs.map +1 -1
  375. package/dist/vitest/workflow-local.d.mts +41 -0
  376. package/dist/workflow-CsaQ9qK-.mjs +42 -0
  377. package/dist/workflow-CsaQ9qK-.mjs.map +1 -0
  378. package/dist/{client-CobIRHl-.mjs → workspace_resource_pb-UGK1SSn_.mjs} +55 -616
  379. package/dist/workspace_resource_pb-UGK1SSn_.mjs.map +1 -0
  380. package/docs/cli/application.md +150 -252
  381. package/docs/cli/auth.md +51 -295
  382. package/docs/cli/completion.md +4 -25
  383. package/docs/cli/crashreport.md +3 -63
  384. package/docs/cli/executor.md +72 -183
  385. package/docs/cli/function.md +17 -133
  386. package/docs/cli/organization.md +11 -221
  387. package/docs/cli/plugin.md +29 -0
  388. package/docs/cli/query.md +2 -22
  389. package/docs/cli/secret.md +71 -251
  390. package/docs/cli/setup.md +138 -40
  391. package/docs/cli/skills.md +50 -39
  392. package/docs/cli/staticwebsite.md +32 -180
  393. package/docs/cli/tailordb.md +71 -427
  394. package/docs/cli/upgrade.md +2 -22
  395. package/docs/cli/user.md +78 -247
  396. package/docs/cli/workflow.md +150 -172
  397. package/docs/cli/workspace.md +167 -538
  398. package/docs/cli-reference.md +213 -96
  399. package/docs/configuration.md +40 -8
  400. package/docs/github-actions.md +72 -24
  401. package/docs/migration/v2.md +1316 -0
  402. package/docs/multi-environment.md +29 -7
  403. package/docs/plugin/custom.md +6 -6
  404. package/docs/plugin/index.md +9 -9
  405. package/docs/quickstart.md +8 -7
  406. package/docs/runtime.md +21 -12
  407. package/docs/services/aigateway.md +115 -0
  408. package/docs/services/auth.md +70 -61
  409. package/docs/services/executor.md +8 -5
  410. package/docs/services/http-adapter.md +16 -1
  411. package/docs/services/idp.md +55 -2
  412. package/docs/services/resolver.md +63 -11
  413. package/docs/services/secret.md +11 -11
  414. package/docs/services/staticwebsite.md +8 -2
  415. package/docs/services/tailordb-migration.md +43 -28
  416. package/docs/services/tailordb.md +200 -99
  417. package/docs/services/workflow.md +135 -59
  418. package/docs/testing.md +253 -145
  419. package/package.json +61 -47
  420. package/postinstall.mjs +4 -6
  421. package/dist/actor-J2gJ0eK5.d.mts +0 -24
  422. package/dist/application-76hhIhnJ.mjs.map +0 -1
  423. package/dist/application-av2raLs6.mjs +0 -4
  424. package/dist/authconnection-BIYzEh2p.d.mts +0 -39
  425. package/dist/authconnection-D8SJGMpj.mjs +0 -16
  426. package/dist/authconnection-D8SJGMpj.mjs.map +0 -1
  427. package/dist/brand-DlnJ375c.mjs.map +0 -1
  428. package/dist/chunk-BkoGK1jX.mjs +0 -21
  429. package/dist/cli/erd-viewer-assets/app.js +0 -1181
  430. package/dist/cli/erd-viewer-assets/index.html +0 -73
  431. package/dist/cli/erd-viewer-assets/serve.json +0 -13
  432. package/dist/cli/erd-viewer-assets/styles.css +0 -789
  433. package/dist/cli/index.d.mts +0 -5
  434. package/dist/cli/index.mjs.map +0 -1
  435. package/dist/cli/skills.d.mts +0 -1
  436. package/dist/cli/skills.mjs +0 -22
  437. package/dist/cli/skills.mjs.map +0 -1
  438. package/dist/client-C68VWo4g.mjs +0 -4
  439. package/dist/client-CobIRHl-.mjs.map +0 -1
  440. package/dist/context-CUBwSBq4.d.mts +0 -68
  441. package/dist/context-s0lxhu8_.mjs.map +0 -1
  442. package/dist/enum-constants-C7DaWeQo.mjs.map +0 -1
  443. package/dist/env-B-g-qgE4.d.mts +0 -7
  444. package/dist/errors-EsY4XO6O.mjs.map +0 -1
  445. package/dist/field-C4zdJLW5.mjs +0 -23
  446. package/dist/field-C4zdJLW5.mjs.map +0 -1
  447. package/dist/file-B58Dm-2P.mjs.map +0 -1
  448. package/dist/file-BzK8z3X-.d.mts +0 -250
  449. package/dist/file-utils-BHPxPXmn.mjs.map +0 -1
  450. package/dist/globals-ByrCoDip.mjs.map +0 -1
  451. package/dist/iconv-DreIffeM.mjs +0 -64
  452. package/dist/iconv-DreIffeM.mjs.map +0 -1
  453. package/dist/iconv-kwrmd1U_.d.mts +0 -122
  454. package/dist/idp-BlBPtXJ-.d.mts +0 -160
  455. package/dist/idp-Ch95ag8h.mjs.map +0 -1
  456. package/dist/index-CLxubakC.d.mts +0 -1225
  457. package/dist/index-CPRnOjjt.d.mts +0 -18
  458. package/dist/index-CQZVJ5SX.d.mts +0 -18
  459. package/dist/index-CfRFkXIO.d.mts +0 -47
  460. package/dist/index-DRhMpdnA.d.mts +0 -46
  461. package/dist/index-DUupuPhZ.d.mts +0 -18
  462. package/dist/interceptor-DOqRkCya.mjs.map +0 -1
  463. package/dist/job-BpsFXPbi.mjs +0 -54
  464. package/dist/job-BpsFXPbi.mjs.map +0 -1
  465. package/dist/kysely-type-D1e0Vwkd.mjs.map +0 -1
  466. package/dist/logger-DpJyJvNz.mjs +0 -221
  467. package/dist/logger-DpJyJvNz.mjs.map +0 -1
  468. package/dist/mock-DMgIygjE.mjs +0 -806
  469. package/dist/mock-DMgIygjE.mjs.map +0 -1
  470. package/dist/package-json-wzO6nV9O.mjs +0 -4
  471. package/dist/plugin-C_FyVSdl.d.mts +0 -634
  472. package/dist/registry-D0uB0OrK.mjs +0 -178
  473. package/dist/registry-D0uB0OrK.mjs.map +0 -1
  474. package/dist/runtime-C7qTBDD2.mjs.map +0 -1
  475. package/dist/schema-1msIhXwA.mjs.map +0 -1
  476. package/dist/secretmanager-B9h-U_8U.mjs +0 -25
  477. package/dist/secretmanager-B9h-U_8U.mjs.map +0 -1
  478. package/dist/secretmanager-CKLB3wAQ.d.mts +0 -55
  479. package/dist/seed-BH2FbrPV.mjs +0 -1171
  480. package/dist/seed-BH2FbrPV.mjs.map +0 -1
  481. package/dist/service-BHQIerYh.mjs +0 -4
  482. package/dist/service-DMohAx8a2.mjs.map +0 -1
  483. package/dist/service-wI3Hvrgx.mjs +0 -460
  484. package/dist/service-wI3Hvrgx.mjs.map +0 -1
  485. package/dist/tailordb-BlBGmQK-.d.mts +0 -863
  486. package/dist/telemetry-BQbbVo2t.mjs.map +0 -1
  487. package/dist/telemetry-w92bvGdC.mjs +0 -4
  488. package/dist/types-2Be3wSMc.mjs +0 -5
  489. package/dist/types-CmzfQP_m.mjs +0 -372
  490. package/dist/types-CmzfQP_m.mjs.map +0 -1
  491. package/dist/workflow--aPbA8Uq.mjs +0 -39
  492. package/dist/workflow--aPbA8Uq.mjs.map +0 -1
  493. package/dist/workflow-CMamswkK.d.mts +0 -96
  494. package/dist/workflow.generated-Bf1tWylx.d.mts +0 -1416
  495. package/docs/generator/builtin.md +0 -257
  496. package/docs/generator/custom.md +0 -147
  497. package/docs/generator/index.md +0 -66
@@ -1,1171 +0,0 @@
1
-
2
- import { t as assertDefined } from "./assert-CKfwrmCV.mjs";
3
- import { t as multiline } from "./multiline-Cf9ODpr1.mjs";
4
- import * as path from "pathe";
5
-
6
- //#region src/plugin/builtin/seed/idp-user-processor.ts
7
- /**
8
- * Processes auth configuration to generate IdP user seed metadata
9
- * @param auth - Auth configuration from generator
10
- * @returns IdP user metadata or undefined if not applicable
11
- */
12
- function processIdpUser(auth) {
13
- if (auth.idProvider?.kind !== "BuiltInIdP" || !auth.userProfile) return;
14
- const { typeName, usernameField } = auth.userProfile;
15
- return {
16
- name: "_User",
17
- dependencies: [typeName],
18
- dataFile: "data/_User.jsonl",
19
- idpNamespace: auth.idProvider.namespace,
20
- schema: {
21
- usernameField,
22
- userTypeName: typeName
23
- }
24
- };
25
- }
26
- /**
27
- * Generates the server-side IDP seed script code for testExecScript execution.
28
- * Uses the global tailor.idp.Client - no bundling required.
29
- * @param idpNamespace - The IDP namespace name
30
- * @returns Script code string
31
- */
32
- function generateIdpSeedScriptCode(idpNamespace) {
33
- return multiline`
34
- export async function main(input) {
35
- const client = new tailor.idp.Client({ namespace: "${idpNamespace}" });
36
- const errors = [];
37
- let processed = 0;
38
-
39
- for (let i = 0; i < input.users.length; i++) {
40
- try {
41
- await client.createUser(input.users[i]);
42
- processed++;
43
- console.log(\`[_User] \${i + 1}/\${input.users.length}: \${input.users[i].name}\`);
44
- } catch (error) {
45
- const message = error instanceof Error ? error.message : String(error);
46
- errors.push(\`Row \${i} (\${input.users[i].name}): \${message}\`);
47
- console.error(\`[_User] Row \${i} failed: \${message}\`);
48
- }
49
- }
50
-
51
- return {
52
- success: errors.length === 0,
53
- processed,
54
- errors,
55
- };
56
- }
57
- `;
58
- }
59
- /**
60
- * Generates the server-side IDP truncation script code for testExecScript execution.
61
- * Lists all users with pagination and deletes each one.
62
- * @param idpNamespace - The IDP namespace name
63
- * @returns Script code string
64
- */
65
- function generateIdpTruncateScriptCode(idpNamespace) {
66
- return multiline`
67
- export async function main() {
68
- const client = new tailor.idp.Client({ namespace: "${idpNamespace}" });
69
- const errors = [];
70
- let deleted = 0;
71
-
72
- // List all users with pagination
73
- let after = undefined;
74
- const allUsers = [];
75
- do {
76
- const response = await client.users(after ? { after } : undefined);
77
- allUsers.push(...(response.users || []));
78
- after = response.nextPageToken;
79
- } while (after);
80
-
81
- console.log(\`Found \${allUsers.length} IDP users to delete\`);
82
-
83
- for (const user of allUsers) {
84
- try {
85
- await client.deleteUser(user.id);
86
- deleted++;
87
- console.log(\`[_User] Deleted \${deleted}/\${allUsers.length}: \${user.name}\`);
88
- } catch (error) {
89
- const message = error instanceof Error ? error.message : String(error);
90
- errors.push(\`User \${user.id} (\${user.name}): \${message}\`);
91
- console.error(\`[_User] Delete failed for \${user.name}: \${message}\`);
92
- }
93
- }
94
-
95
- return {
96
- success: errors.length === 0,
97
- deleted,
98
- total: allUsers.length,
99
- errors,
100
- };
101
- }
102
- `;
103
- }
104
- /**
105
- * Generates the schema file content for IdP users. Emits the
106
- * `_User.name -> <userProfile>.<usernameField>` foreign key by default; pass
107
- * `includeUserProfileFK: false` to omit it (e.g. when seeding `_User` rows
108
- * that do not yet have a corresponding userProfile row).
109
- * @param options - Schema generation options
110
- * @param options.usernameField - Username field name
111
- * @param options.userTypeName - TailorDB user type name
112
- * @param options.includeUserProfileFK - Whether to emit the `_User -> userProfile` foreign key (default `true`)
113
- * @returns Schema file contents
114
- */
115
- function generateIdpUserSchemaFile(options) {
116
- const { usernameField, userTypeName, includeUserProfileFK = true } = options;
117
- return multiline`
118
- import { t } from "@tailor-platform/sdk";
119
- import { defineSchema } from "@tailor-platform/sdk/seed";
120
- import { createStandardSchema } from "@tailor-platform/sdk/test";
121
-
122
- const schemaType = t.object({
123
- name: t.string(),
124
- password: t.string(),
125
- });
126
-
127
- // Simple identity hook for _User (no TailorDB backing type)
128
- const hook = <T>(data: unknown) => data as T;
129
-
130
- export const schema = defineSchema(
131
- createStandardSchema(schemaType, hook),
132
- {
133
- ${includeUserProfileFK ? multiline`
134
- primaryKey: "name",
135
- indexes: [
136
- { name: "_user_name_unique_idx", columns: ["name"], unique: true },
137
- ],
138
- foreignKeys: [
139
- {
140
- column: "name",
141
- references: {
142
- table: "${userTypeName}",
143
- column: "${usernameField}",
144
- },
145
- },
146
- ],
147
- ` : multiline`
148
- primaryKey: "name",
149
- indexes: [
150
- { name: "_user_name_unique_idx", columns: ["name"], unique: true },
151
- ],
152
- `}
153
- }
154
- );
155
-
156
- `;
157
- }
158
-
159
- //#endregion
160
- //#region src/types/tailordb.ts
161
- /**
162
- * Checks if a type source is generated by a plugin.
163
- * @param source - The type source entry to check.
164
- * @returns True if the source was generated by a plugin.
165
- */
166
- function isPluginGeneratedType(source) {
167
- return source.pluginId !== void 0;
168
- }
169
-
170
- //#endregion
171
- //#region src/plugin/builtin/seed/lines-db-processor.ts
172
- /**
173
- * Processes TailorDB types to generate lines-db metadata
174
- * @param type - Parsed TailorDB type
175
- * @param source - Source file info
176
- * @returns Generated lines-db metadata
177
- */
178
- function processLinesDb(type, source) {
179
- if (isPluginGeneratedType(source)) return processLinesDbForPluginType(type, source);
180
- if (!source.filePath) throw new Error(`Missing source info for type ${type.name}`);
181
- if (!source.exportName) throw new Error(`Missing export name for type ${type.name}`);
182
- const { optionalFields, omitFields, indexes, foreignKeys } = extractFieldMetadata(type);
183
- return {
184
- typeName: type.name,
185
- exportName: source.exportName,
186
- importPath: source.filePath,
187
- optionalFields,
188
- omitFields,
189
- foreignKeys,
190
- indexes
191
- };
192
- }
193
- /**
194
- * Process lines-db metadata for plugin-generated types
195
- * @param type - Parsed TailorDB type
196
- * @param source - Plugin-generated type source info
197
- * @returns Generated lines-db metadata with plugin source
198
- */
199
- function processLinesDbForPluginType(type, source) {
200
- const { optionalFields, omitFields, indexes, foreignKeys } = extractFieldMetadata(type);
201
- return {
202
- typeName: type.name,
203
- exportName: source.exportName,
204
- importPath: "",
205
- optionalFields,
206
- omitFields,
207
- foreignKeys,
208
- indexes,
209
- pluginSource: source
210
- };
211
- }
212
- /**
213
- * Extract field metadata from TailorDB type
214
- * @param type - Parsed TailorDB type
215
- * @returns Field metadata including optional fields, omit fields, indexes, and foreign keys
216
- */
217
- function extractFieldMetadata(type) {
218
- const optionalFields = ["id"];
219
- const omitFields = [];
220
- const indexes = [];
221
- const foreignKeys = [];
222
- for (const [fieldName, field] of Object.entries(type.fields)) {
223
- if (field.config.hooks?.create) optionalFields.push(fieldName);
224
- if (field.config.serial) omitFields.push(fieldName);
225
- if (field.config.unique) indexes.push({
226
- name: `${type.name.toLowerCase()}_${fieldName}_unique_idx`,
227
- columns: [fieldName],
228
- unique: true
229
- });
230
- }
231
- if (type.indexes) for (const [indexName, indexDef] of Object.entries(type.indexes)) indexes.push({
232
- name: indexName,
233
- columns: indexDef.fields,
234
- unique: indexDef.unique
235
- });
236
- for (const [fieldName, field] of Object.entries(type.fields)) if (field.relation) foreignKeys.push({
237
- column: fieldName,
238
- references: {
239
- table: field.relation.targetType,
240
- column: field.relation.key
241
- }
242
- });
243
- return {
244
- optionalFields,
245
- omitFields,
246
- indexes,
247
- foreignKeys
248
- };
249
- }
250
- /**
251
- * Generate schema options code for lines-db
252
- * @param foreignKeys - Foreign key definitions
253
- * @param indexes - Index definitions
254
- * @returns Schema options code string
255
- */
256
- function generateSchemaOptions(foreignKeys, indexes) {
257
- const schemaOptions = [];
258
- if (foreignKeys.length > 0) {
259
- schemaOptions.push(`foreignKeys: [`);
260
- foreignKeys.forEach((fk) => {
261
- schemaOptions.push(` ${JSON.stringify(fk)},`);
262
- });
263
- schemaOptions.push(`],`);
264
- }
265
- if (indexes.length > 0) {
266
- schemaOptions.push(`indexes: [`);
267
- indexes.forEach((index) => {
268
- schemaOptions.push(` ${JSON.stringify(index)},`);
269
- });
270
- schemaOptions.push("],");
271
- }
272
- return schemaOptions.length > 0 ? [
273
- "\n {",
274
- ...schemaOptions.map((option) => ` ${option}`),
275
- " }"
276
- ].join("\n") : "";
277
- }
278
- /**
279
- * Generates the schema file content for lines-db (for user-defined types with import)
280
- * @param metadata - lines-db metadata
281
- * @param importPath - Import path for the TailorDB type
282
- * @returns Schema file contents
283
- */
284
- function generateLinesDbSchemaFile(metadata, importPath) {
285
- const { exportName, optionalFields, omitFields, foreignKeys, indexes } = metadata;
286
- return multiline`
287
- import { t } from "@tailor-platform/sdk";
288
- import { defineSchema } from "@tailor-platform/sdk/seed";
289
- import { createTailorDBHook, createStandardSchema } from "@tailor-platform/sdk/test";
290
- import { ${exportName} } from "${importPath}";
291
-
292
- ${multiline`
293
- const schemaType = t.object({
294
- ...${exportName}.pickFields(${JSON.stringify(optionalFields)}, { optional: true }),
295
- ...${exportName}.omitFields(${JSON.stringify([...optionalFields, ...omitFields])}),
296
- });
297
- `}
298
-
299
- const hook = createTailorDBHook(${exportName});
300
-
301
- export const schema = defineSchema(
302
- createStandardSchema(schemaType, hook),${generateSchemaOptions(foreignKeys, indexes)}
303
- );
304
-
305
- `;
306
- }
307
- /**
308
- * Generates the schema file content using getGeneratedType API
309
- * (for plugin-generated types)
310
- * @param metadata - lines-db metadata (must have pluginSource)
311
- * @param params - Plugin import paths
312
- * @returns Schema file contents
313
- */
314
- function generateLinesDbSchemaFileWithPluginAPI(metadata, params) {
315
- const { typeName, exportName, optionalFields, omitFields, foreignKeys, indexes, pluginSource } = metadata;
316
- if (!pluginSource) throw new Error(`pluginSource is required for plugin-generated type "${typeName}"`);
317
- const { configImportPath, originalImportPath } = params;
318
- const schemaTypeCode = multiline`
319
- const schemaType = t.object({
320
- ...${exportName}.pickFields(${JSON.stringify(optionalFields)}, { optional: true }),
321
- ...${exportName}.omitFields(${JSON.stringify([...optionalFields, ...omitFields])}),
322
- });
323
- `;
324
- const schemaOptionsCode = generateSchemaOptions(foreignKeys, indexes);
325
- if (pluginSource.originalExportName && originalImportPath && pluginSource.generatedTypeKind) return multiline`
326
- import { join } from "node:path";
327
- import { t } from "@tailor-platform/sdk";
328
- import { getGeneratedType } from "@tailor-platform/sdk/plugin";
329
- import { defineSchema } from "@tailor-platform/sdk/seed";
330
- import { createTailorDBHook, createStandardSchema } from "@tailor-platform/sdk/test";
331
- import { ${pluginSource.originalExportName} } from "${originalImportPath}";
332
-
333
- const configPath = join(import.meta.dirname, "${configImportPath}");
334
- const ${exportName} = await getGeneratedType(configPath, "${pluginSource.pluginId}", ${pluginSource.originalExportName}, "${pluginSource.generatedTypeKind}");
335
-
336
- ${schemaTypeCode}
337
-
338
- const hook = createTailorDBHook(${exportName});
339
-
340
- export const schema = defineSchema(
341
- createStandardSchema(schemaType, hook),${schemaOptionsCode}
342
- );
343
-
344
- `;
345
- if (!pluginSource.generatedTypeKind) throw new Error(`Namespace plugin "${pluginSource.pluginId}" must provide generatedTypeKind for type "${typeName}"`);
346
- return multiline`
347
- import { join } from "node:path";
348
- import { t } from "@tailor-platform/sdk";
349
- import { getGeneratedType } from "@tailor-platform/sdk/plugin";
350
- import { defineSchema } from "@tailor-platform/sdk/seed";
351
- import { createTailorDBHook, createStandardSchema } from "@tailor-platform/sdk/test";
352
-
353
- const configPath = join(import.meta.dirname, "${configImportPath}");
354
- const ${exportName} = await getGeneratedType(configPath, "${pluginSource.pluginId}", null, "${pluginSource.generatedTypeKind}");
355
-
356
- ${schemaTypeCode}
357
-
358
- const hook = createTailorDBHook(${exportName});
359
-
360
- export const schema = defineSchema(
361
- createStandardSchema(schemaType, hook),${schemaOptionsCode}
362
- );
363
-
364
- `;
365
- }
366
-
367
- //#endregion
368
- //#region src/plugin/builtin/seed/seed-type-processor.ts
369
- /**
370
- * Processes TailorDB types to extract seed type information
371
- * @param type - Parsed TailorDB type
372
- * @param namespace - Namespace of the type
373
- * @returns Seed type information
374
- */
375
- function processSeedTypeInfo(type, namespace) {
376
- const dependencies = /* @__PURE__ */ new Set();
377
- const selfRefFields = [];
378
- for (const [fieldName, field] of Object.entries(type.fields)) {
379
- const targetType = field.relation?.targetType ?? field.config.foreignKeyType;
380
- if (!targetType) continue;
381
- if (targetType === type.name) selfRefFields.push(fieldName);
382
- else dependencies.add(targetType);
383
- }
384
- return {
385
- name: type.name,
386
- namespace,
387
- dependencies: Array.from(dependencies),
388
- selfRefFields,
389
- dataFile: `data/${type.name}.jsonl`
390
- };
391
- }
392
-
393
- //#endregion
394
- //#region src/plugin/builtin/seed/index.ts
395
- /** Unique identifier for the seed generator plugin. */
396
- const SeedGeneratorID = "@tailor-platform/seed";
397
- function resolveIdpUserSyncFKs(option) {
398
- return {
399
- emitUserToIdpFK: !(option?.userToIdp ?? false),
400
- emitIdpToUserFK: !(option?.idpToUser ?? false)
401
- };
402
- }
403
- /**
404
- * Generate the IdP user seed function code using tailor.idp.Client via testExecScript
405
- * @param hasIdpUser - Whether IdP user is included
406
- * @param idpNamespace - The IDP namespace name
407
- * @returns JavaScript code for IdP user seeding function
408
- */
409
- function generateIdpUserSeedFunction(hasIdpUser, idpNamespace) {
410
- if (!hasIdpUser || !idpNamespace) return "";
411
- return multiline`
412
- // Seed _User via tailor.idp.Client (server-side)
413
- const seedIdpUser = async () => {
414
- console.log(styleText("cyan", " Seeding _User via tailor.idp.Client..."));
415
- const dataDir = join(configDir, "data");
416
- const data = loadSeedData(dataDir, ["_User"]);
417
- const rows = data["_User"] || [];
418
- if (rows.length === 0) {
419
- console.log(styleText("dim", " No _User data to seed"));
420
- return { success: true };
421
- }
422
- console.log(styleText("dim", \` Processing \${rows.length} _User records...\`));
423
-
424
- const idpSeedCode = \/* js *\/\`${generateIdpSeedScriptCode(idpNamespace).replace(/`/g, "\\`").replace(/\$/g, "\\$")}\`;
425
-
426
- const result = await executeScript({
427
- client: operatorClient,
428
- workspaceId,
429
- name: "seed-idp-user.ts",
430
- code: idpSeedCode,
431
- arg: JSON.stringify({ users: rows }),
432
- invoker: {
433
- namespace: authNamespace,
434
- machineUserName,
435
- },
436
- });
437
-
438
- if (result.logs) {
439
- for (const line of result.logs.split("\\n").filter(Boolean)) {
440
- console.log(styleText("dim", \` \${line}\`));
441
- }
442
- }
443
-
444
- if (result.success) {
445
- let parsed;
446
- try {
447
- parsed = JSON.parse(result.result || "{}");
448
- } catch (e) {
449
- console.error(styleText("red", \` ✗ Failed to parse seed result: \${e.message}\`));
450
- return { success: false };
451
- }
452
-
453
- if (parsed.processed) {
454
- console.log(styleText("green", \` ✓ _User: \${parsed.processed} rows processed\`));
455
- }
456
-
457
- if (!parsed.success) {
458
- const errors = Array.isArray(parsed.errors) ? parsed.errors : [];
459
- for (const err of errors) {
460
- console.error(styleText("red", \` ✗ \${err}\`));
461
- }
462
- return { success: false };
463
- }
464
-
465
- return { success: true };
466
- } else {
467
- console.error(styleText("red", \` ✗ Seed failed: \${result.error}\`));
468
- return { success: false };
469
- }
470
- };
471
- `;
472
- }
473
- /**
474
- * Generate the IdP user seed call code
475
- * @param hasIdpUser - Whether IdP user is included
476
- * @returns JavaScript code for calling IdP user seeding
477
- */
478
- function generateIdpUserSeedCall(hasIdpUser) {
479
- if (!hasIdpUser) return "";
480
- return multiline`
481
- // Seed _User if included and not skipped
482
- const shouldSeedUser = !skipIdp && (!entitiesToProcess || entitiesToProcess.includes("_User"));
483
- if (hasIdpUser && shouldSeedUser) {
484
- const result = await seedIdpUser();
485
- if (!result.success) {
486
- allSuccess = false;
487
- }
488
- }
489
- `;
490
- }
491
- /**
492
- * Generate the IdP user truncation function code using tailor.idp.Client via testExecScript
493
- * @param hasIdpUser - Whether IdP user is included
494
- * @param idpNamespace - The IDP namespace name
495
- * @returns JavaScript code for IdP user truncation function
496
- */
497
- function generateIdpUserTruncateFunction(hasIdpUser, idpNamespace) {
498
- if (!hasIdpUser || !idpNamespace) return "";
499
- return multiline`
500
- // Truncate _User via tailor.idp.Client (server-side)
501
- const truncateIdpUser = async () => {
502
- console.log(styleText("cyan", "Truncating _User via tailor.idp.Client..."));
503
-
504
- const idpTruncateCode = \/* js *\/\`${generateIdpTruncateScriptCode(idpNamespace).replace(/`/g, "\\`").replace(/\$/g, "\\$")}\`;
505
-
506
- const result = await executeScript({
507
- client: operatorClient,
508
- workspaceId,
509
- name: "truncate-idp-user.ts",
510
- code: idpTruncateCode,
511
- arg: JSON.stringify({}),
512
- invoker: {
513
- namespace: authNamespace,
514
- machineUserName,
515
- },
516
- });
517
-
518
- if (result.logs) {
519
- for (const line of result.logs.split("\\n").filter(Boolean)) {
520
- console.log(styleText("dim", \` \${line}\`));
521
- }
522
- }
523
-
524
- if (result.success) {
525
- let parsed;
526
- try {
527
- parsed = JSON.parse(result.result || "{}");
528
- } catch (e) {
529
- console.error(styleText("red", \` ✗ Failed to parse truncation result: \${e.message}\`));
530
- return { success: false };
531
- }
532
-
533
- if (parsed.deleted !== undefined) {
534
- console.log(styleText("green", \` ✓ _User: \${parsed.deleted} users deleted\`));
535
- }
536
-
537
- if (!parsed.success) {
538
- const errors = Array.isArray(parsed.errors) ? parsed.errors : [];
539
- for (const err of errors) {
540
- console.error(styleText("red", \` ✗ \${err}\`));
541
- }
542
- return { success: false };
543
- }
544
-
545
- return { success: true };
546
- } else {
547
- console.error(styleText("red", \` ✗ Truncation failed: \${result.error}\`));
548
- return { success: false };
549
- }
550
- };
551
- `;
552
- }
553
- /**
554
- * Generate the IdP user truncation call code within the truncate block
555
- * @param hasIdpUser - Whether IdP user is included
556
- * @returns JavaScript code for calling IdP user truncation
557
- */
558
- function generateIdpUserTruncateCall(hasIdpUser) {
559
- if (!hasIdpUser) return "";
560
- return multiline`
561
- // Truncate _User if applicable
562
- const shouldTruncateUser = !skipIdp && !hasNamespace && (!hasTypes || entitiesToProcess.includes("_User"));
563
- if (hasIdpUser && shouldTruncateUser) {
564
- const truncResult = await truncateIdpUser();
565
- if (!truncResult.success) {
566
- console.error(styleText("red", "IDP user truncation failed."));
567
- process.exit(1);
568
- }
569
- }
570
- `;
571
- }
572
- /**
573
- * Generates the exec.mjs script content using testExecScript API for TailorDB types
574
- * and tailor.idp.Client for _User (IdP managed)
575
- * @param defaultMachineUserName - Default machine user name from generator config (can be overridden at runtime)
576
- * @param relativeConfigPath - Config path relative to exec script
577
- * @param namespaceConfigs - Namespace configurations with types and dependencies
578
- * @param hasIdpUser - Whether _User is included
579
- * @param idpNamespace - The IDP namespace name, or null if not applicable
580
- * @returns exec.mjs file contents
581
- */
582
- function generateExecScript(defaultMachineUserName, relativeConfigPath, namespaceConfigs, hasIdpUser, idpNamespace) {
583
- const namespaceEntitiesEntries = namespaceConfigs.map(({ namespace, types }) => {
584
- return ` "${namespace}": [\n${types.map((e) => ` "${e}",`).join("\n")}\n ]`;
585
- }).join(",\n");
586
- const namespaceDepsEntries = namespaceConfigs.map(({ namespace, dependencies }) => {
587
- return ` "${namespace}": {\n${Object.entries(dependencies).map(([type, deps]) => ` "${type}": [${deps.map((d) => `"${d}"`).join(", ")}]`).join(",\n")}\n }`;
588
- }).join(",\n");
589
- const namespaceSelfRefEntries = namespaceConfigs.map(({ namespace, selfRefTypes }) => {
590
- return ` "${namespace}": [${selfRefTypes.map((t) => `"${t}"`).join(", ")}]`;
591
- }).join(",\n");
592
- return multiline`
593
- /**
594
- * @generated
595
- * This file is auto-generated by @tailor-platform/sdk's seedPlugin.
596
- * Do not edit by hand: changes will be overwritten on the next \`sdk generate\`.
597
- */
598
- import { readFileSync } from "node:fs";
599
- import { join, isAbsolute } from "node:path";
600
- import { parseArgs, styleText } from "node:util";
601
- import { createInterface } from "node:readline";
602
- import {
603
- show,
604
- truncate,
605
- bundleSeedScript,
606
- chunkSeedData,
607
- executeScript,
608
- initOperatorClient,
609
- loadAccessToken,
610
- loadWorkspaceId,
611
- } from "@tailor-platform/sdk/cli";
612
-
613
- // Handle "validate" subcommand before parseArgs
614
- const subcommand = process.argv[2];
615
- if (subcommand === "validate") {
616
- const { validateSeedData } = await import("@tailor-platform/sdk/seed");
617
- const validateArgs = parseArgs({
618
- args: process.argv.slice(3),
619
- options: {
620
- verbose: { type: "boolean", short: "v", default: false },
621
- help: { type: "boolean", short: "h", default: false },
622
- },
623
- allowPositionals: true,
624
- });
625
-
626
- if (validateArgs.values.help) {
627
- console.log(\`
628
- Usage: node exec.mjs validate [options] [path]
629
-
630
- Validate JSONL seed data against schema definitions.
631
-
632
- Arguments:
633
- path File or directory to validate (default: ./data)
634
-
635
- Options:
636
- -v, --verbose Show verbose error output
637
- -h, --help Show help
638
-
639
- Examples:
640
- node exec.mjs validate # Validate all seed data
641
- node exec.mjs validate ./data/User.jsonl # Validate specific file
642
- node exec.mjs validate -v # Verbose error output
643
- \`);
644
- process.exit(0);
645
- }
646
-
647
- const configDir = import.meta.dirname;
648
- const targetPath = validateArgs.positionals[0] || join(configDir, "data");
649
- const resolvedPath = isAbsolute(targetPath) ? targetPath : join(process.cwd(), targetPath);
650
-
651
- try {
652
- const result = await validateSeedData({ path: resolvedPath, verbose: validateArgs.values.verbose });
653
- if (result.output) console.log(result.output);
654
- if (!result.valid) {
655
- console.error(result.error);
656
- process.exit(1);
657
- }
658
- process.exit(0);
659
- } catch (error) {
660
- console.error(styleText("red", \`Error: \${error instanceof Error ? error.message : String(error)}\`));
661
- process.exit(1);
662
- }
663
- }
664
-
665
- // Parse command-line arguments
666
- const { values, positionals } = parseArgs({
667
- options: {
668
- "machine-user": { type: "string", short: "m" },
669
- namespace: { type: "string", short: "n" },
670
- "skip-idp": { type: "boolean", default: false },
671
- truncate: { type: "boolean", default: false },
672
- yes: { type: "boolean", default: false },
673
- profile: { type: "string", short: "p" },
674
- help: { type: "boolean", short: "h", default: false },
675
- },
676
- allowPositionals: true,
677
- });
678
-
679
- if (values.help) {
680
- console.log(\`
681
- Usage: node exec.mjs [command] [options] [types...]
682
-
683
- Commands:
684
- validate [path] Validate seed data against schema (default: ./data)
685
-
686
- Options:
687
- -m, --machine-user <name> Machine user name for authentication (required if not configured)
688
- -n, --namespace <ns> Process all types in specified namespace (excludes _User)
689
- --skip-idp Skip IdP user (_User) entity
690
- --truncate Truncate tables before seeding
691
- --yes Skip confirmation prompts (for truncate)
692
- -p, --profile <name> Workspace profile name
693
- -h, --help Show help
694
-
695
- Examples:
696
- node exec.mjs -m admin # Process all types with machine user
697
- node exec.mjs --namespace <namespace> # Process tailordb namespace only (no _User)
698
- node exec.mjs User Order # Process specific types only
699
- node exec.mjs --skip-idp # Process all except _User
700
- node exec.mjs --truncate # Truncate all tables, then seed all
701
- node exec.mjs --truncate --yes # Truncate all tables without confirmation, then seed all
702
- node exec.mjs --truncate --namespace <namespace> # Truncate tailordb, then seed tailordb
703
- node exec.mjs --truncate User Order # Truncate User and Order, then seed them
704
- node exec.mjs validate # Validate all seed data
705
- node exec.mjs validate ./data/User.jsonl # Validate specific file
706
- \`);
707
- process.exit(0);
708
- }
709
-
710
- // Helper function to prompt for y/n confirmation
711
- const promptConfirmation = (question) => {
712
- const rl = createInterface({
713
- input: process.stdin,
714
- output: process.stdout,
715
- });
716
-
717
- return new Promise((resolve) => {
718
- rl.question(styleText("yellow", question), (answer) => {
719
- rl.close();
720
- resolve(answer.toLowerCase().trim());
721
- });
722
- });
723
- };
724
-
725
- const configDir = import.meta.dirname;
726
- const configPath = join(configDir, "${relativeConfigPath}");
727
-
728
- // Determine machine user name (CLI argument takes precedence over config default)
729
- const defaultMachineUser = ${defaultMachineUserName ? `"${defaultMachineUserName}"` : "undefined"};
730
- const machineUserName = values["machine-user"] || defaultMachineUser;
731
-
732
- if (!machineUserName) {
733
- console.error(styleText("red", "Error: Machine user name is required."));
734
- console.error(styleText("yellow", "Specify --machine-user <name> or configure machineUserName in generator options."));
735
- process.exit(1);
736
- }
737
-
738
- // Entity configuration
739
- const namespaceEntities = {
740
- ${namespaceEntitiesEntries}
741
- };
742
- const namespaceDeps = {
743
- ${namespaceDepsEntries}
744
- };
745
- const namespaceSelfRefTypes = {
746
- ${namespaceSelfRefEntries}
747
- };
748
- const entities = Object.values(namespaceEntities).flat();
749
- const hasIdpUser = ${String(hasIdpUser)};
750
-
751
- // Determine which entities to process
752
- let entitiesToProcess = null;
753
-
754
- const hasNamespace = !!values.namespace;
755
- const hasTypes = positionals.length > 0;
756
- const skipIdp = values["skip-idp"];
757
-
758
- // Validate mutually exclusive options
759
- const optionCount = [hasNamespace, hasTypes].filter(Boolean).length;
760
- if (optionCount > 1) {
761
- console.error(styleText("red", "Error: Options --namespace and type names are mutually exclusive."));
762
- process.exit(1);
763
- }
764
-
765
- // --skip-idp and --namespace are redundant (namespace already excludes _User)
766
- if (skipIdp && hasNamespace) {
767
- console.warn(styleText("yellow", "Warning: --skip-idp is redundant with --namespace (namespace filtering already excludes _User)."));
768
- }
769
-
770
- // Filter by namespace (automatically excludes _User as it has no namespace)
771
- if (hasNamespace) {
772
- const namespace = values.namespace;
773
- entitiesToProcess = namespaceEntities[namespace];
774
-
775
- if (!entitiesToProcess || entitiesToProcess.length === 0) {
776
- console.error(styleText("red", \`Error: No entities found in namespace "\${namespace}"\`));
777
- console.error(styleText("yellow", \`Available namespaces: \${Object.keys(namespaceEntities).join(", ")}\`));
778
- process.exit(1);
779
- }
780
-
781
- console.log(styleText("cyan", \`Filtering by namespace: \${namespace}\`));
782
- console.log(styleText("dim", \`Entities: \${entitiesToProcess.join(", ")}\`));
783
- }
784
-
785
- // Filter by specific types
786
- if (hasTypes) {
787
- const requestedTypes = positionals;
788
- const notFoundTypes = [];
789
- const allTypes = hasIdpUser ? [...entities, "_User"] : entities;
790
-
791
- entitiesToProcess = requestedTypes.filter((type) => {
792
- if (!allTypes.includes(type)) {
793
- notFoundTypes.push(type);
794
- return false;
795
- }
796
- return true;
797
- });
798
-
799
- if (notFoundTypes.length > 0) {
800
- console.error(styleText("red", \`Error: The following types were not found: \${notFoundTypes.join(", ")}\`));
801
- console.error(styleText("yellow", \`Available types: \${allTypes.join(", ")}\`));
802
- process.exit(1);
803
- }
804
-
805
- console.log(styleText("cyan", \`Filtering by types: \${entitiesToProcess.join(", ")}\`));
806
- }
807
-
808
- // Apply --skip-idp filter
809
- if (skipIdp) {
810
- if (entitiesToProcess) {
811
- entitiesToProcess = entitiesToProcess.filter((entity) => entity !== "_User");
812
- } else {
813
- entitiesToProcess = entities.filter((entity) => entity !== "_User");
814
- }
815
- }
816
-
817
- // Get application info
818
- const appInfo = await show({ configPath, profile: values.profile });
819
- const authNamespace = appInfo.auth;
820
-
821
- // Initialize operator client (once for all namespaces)
822
- const accessToken = await loadAccessToken({ profile: values.profile });
823
- const workspaceId = await loadWorkspaceId({ profile: values.profile });
824
- const operatorClient = await initOperatorClient(accessToken);
825
-
826
- ${generateIdpUserTruncateFunction(hasIdpUser, idpNamespace)}
827
-
828
- // Truncate tables if requested
829
- if (values.truncate) {
830
- const answer = values.yes ? "y" : await promptConfirmation("Are you sure you want to truncate? (y/n): ");
831
- if (answer !== "y") {
832
- console.log(styleText("yellow", "Truncate cancelled."));
833
- process.exit(0);
834
- }
835
-
836
- console.log(styleText("cyan", "Truncating tables..."));
837
-
838
- try {
839
- if (hasNamespace) {
840
- await truncate({
841
- configPath,
842
- profile: values.profile,
843
- namespace: values.namespace,
844
- });
845
- } else if (hasTypes) {
846
- const typesToTruncate = entitiesToProcess.filter((t) => t !== "_User");
847
- if (typesToTruncate.length > 0) {
848
- await truncate({
849
- configPath,
850
- profile: values.profile,
851
- types: typesToTruncate,
852
- });
853
- } else {
854
- console.log(styleText("dim", "No TailorDB types to truncate (only _User was specified)."));
855
- }
856
- } else {
857
- await truncate({
858
- configPath,
859
- profile: values.profile,
860
- all: true,
861
- });
862
- }
863
- } catch (error) {
864
- console.error(styleText("red", \`Truncate failed: \${error.message}\`));
865
- process.exit(1);
866
- }
867
-
868
- ${generateIdpUserTruncateCall(hasIdpUser)}
869
-
870
- console.log(styleText("green", "Truncate completed."));
871
- }
872
-
873
- console.log(styleText("cyan", "\\nStarting seed data generation..."));
874
- if (skipIdp) {
875
- console.log(styleText("dim", \` Skipping IdP user (_User)\`));
876
- }
877
-
878
- // Load seed data from JSONL files
879
- const loadSeedData = (dataDir, typeNames) => {
880
- const data = {};
881
- for (const typeName of typeNames) {
882
- const jsonlPath = join(dataDir, \`\${typeName}.jsonl\`);
883
- try {
884
- const content = readFileSync(jsonlPath, "utf-8").trim();
885
- if (content) {
886
- data[typeName] = content.split("\\n").map((line) => JSON.parse(line));
887
- } else {
888
- data[typeName] = [];
889
- }
890
- } catch (error) {
891
- if (error.code === "ENOENT") {
892
- data[typeName] = [];
893
- } else {
894
- throw error;
895
- }
896
- }
897
- }
898
- return data;
899
- };
900
-
901
- // Topological sort for dependency order
902
- const topologicalSort = (types, deps) => {
903
- const visited = new Set();
904
- const result = [];
905
-
906
- const visit = (type) => {
907
- if (visited.has(type)) return;
908
- visited.add(type);
909
- const typeDeps = deps[type] || [];
910
- for (const dep of typeDeps) {
911
- if (types.includes(dep)) {
912
- visit(dep);
913
- }
914
- }
915
- result.push(type);
916
- };
917
-
918
- for (const type of types) {
919
- visit(type);
920
- }
921
- return result;
922
- };
923
-
924
- // Seed TailorDB types via testExecScript
925
- const seedViaTestExecScript = async (namespace, typesToSeed, deps, selfRefTypes) => {
926
- const dataDir = join(configDir, "data");
927
- const sortedTypes = topologicalSort(typesToSeed, deps);
928
- const data = loadSeedData(dataDir, sortedTypes);
929
-
930
- // Skip if no data
931
- const typesWithData = sortedTypes.filter((t) => data[t] && data[t].length > 0);
932
- if (typesWithData.length === 0) {
933
- console.log(styleText("dim", \` [\${namespace}] No data to seed\`));
934
- return { success: true, processed: {} };
935
- }
936
-
937
- console.log(styleText("cyan", \` [\${namespace}] Seeding \${typesWithData.length} types via Kysely batch insert...\`));
938
-
939
- // Bundle seed script
940
- const bundled = await bundleSeedScript(namespace, typesWithData);
941
-
942
- // Chunk seed data to fit within gRPC message size limits
943
- const chunks = chunkSeedData({
944
- data,
945
- order: sortedTypes,
946
- codeByteSize: new TextEncoder().encode(bundled.bundledCode).length,
947
- });
948
-
949
- if (chunks.length === 0) {
950
- console.log(styleText("dim", \` [\${namespace}] No data to seed\`));
951
- return { success: true, processed: {} };
952
- }
953
-
954
- if (chunks.length > 1) {
955
- console.log(styleText("dim", \` Split into \${chunks.length} chunks\`));
956
- }
957
-
958
- const allProcessed = {};
959
- let hasError = false;
960
- const allErrors = [];
961
-
962
- for (const chunk of chunks) {
963
- if (chunks.length > 1) {
964
- console.log(styleText("dim", \` Chunk \${chunk.index + 1}/\${chunk.total}: \${chunk.order.join(", ")}\`));
965
- }
966
-
967
- // Execute seed script for this chunk
968
- const result = await executeScript({
969
- client: operatorClient,
970
- workspaceId,
971
- name: \`seed-\${namespace}.ts\`,
972
- code: bundled.bundledCode,
973
- arg: JSON.stringify({ data: chunk.data, order: chunk.order, selfRefTypes }),
974
- invoker: {
975
- namespace: authNamespace,
976
- machineUserName,
977
- },
978
- });
979
-
980
- // Parse result and display logs
981
- if (result.logs) {
982
- for (const line of result.logs.split("\\n").filter(Boolean)) {
983
- console.log(styleText("dim", \` \${line}\`));
984
- }
985
- }
986
-
987
- if (result.success) {
988
- let parsed;
989
- try {
990
- const parsedResult = JSON.parse(result.result || "{}");
991
- parsed = parsedResult && typeof parsedResult === "object" ? parsedResult : {};
992
- } catch (error) {
993
- const message = error instanceof Error ? error.message : String(error);
994
- console.error(styleText("red", \` ✗ Failed to parse seed result: \${message}\`));
995
- hasError = true;
996
- allErrors.push(message);
997
- continue;
998
- }
999
-
1000
- const processed = parsed.processed || {};
1001
- for (const [type, count] of Object.entries(processed)) {
1002
- allProcessed[type] = (allProcessed[type] || 0) + count;
1003
- console.log(styleText("green", \` ✓ \${type}: \${count} rows inserted\`));
1004
- }
1005
-
1006
- if (!parsed.success) {
1007
- const errors = Array.isArray(parsed.errors) ? parsed.errors : [];
1008
- const errorMessage =
1009
- errors.length > 0 ? errors.join("\\n ") : "Seed script reported failure";
1010
- console.error(styleText("red", \` ✗ Seed failed:\\n \${errorMessage}\`));
1011
- hasError = true;
1012
- allErrors.push(errorMessage);
1013
- }
1014
- } else {
1015
- console.error(styleText("red", \` ✗ Seed failed: \${result.error}\`));
1016
- hasError = true;
1017
- allErrors.push(result.error);
1018
- }
1019
- }
1020
-
1021
- if (hasError) {
1022
- return { success: false, error: allErrors.join("\\n") };
1023
- }
1024
- return { success: true, processed: allProcessed };
1025
- };
1026
-
1027
- ${generateIdpUserSeedFunction(hasIdpUser, idpNamespace)}
1028
-
1029
- // Main execution
1030
- try {
1031
- let allSuccess = true;
1032
-
1033
- // Determine which namespaces and types to process
1034
- const namespacesToProcess = hasNamespace
1035
- ? [values.namespace]
1036
- : Object.keys(namespaceEntities);
1037
-
1038
- for (const namespace of namespacesToProcess) {
1039
- const nsTypes = namespaceEntities[namespace] || [];
1040
- const nsDeps = namespaceDeps[namespace] || {};
1041
- const nsSelfRefTypes = namespaceSelfRefTypes[namespace] || [];
1042
-
1043
- // Filter types if specific types requested
1044
- let typesToSeed = entitiesToProcess
1045
- ? nsTypes.filter((t) => entitiesToProcess.includes(t))
1046
- : nsTypes;
1047
-
1048
- if (typesToSeed.length === 0) continue;
1049
-
1050
- const result = await seedViaTestExecScript(namespace, typesToSeed, nsDeps, nsSelfRefTypes);
1051
- if (!result.success) {
1052
- allSuccess = false;
1053
- }
1054
- }
1055
-
1056
- ${generateIdpUserSeedCall(hasIdpUser)}
1057
-
1058
- if (allSuccess) {
1059
- console.log(styleText("green", "\\n✓ Seed data generation completed successfully"));
1060
- } else {
1061
- console.error(styleText("red", "\\n✗ Seed data generation completed with errors"));
1062
- process.exit(1);
1063
- }
1064
- } catch (error) {
1065
- console.error(styleText("red", \`\\n✗ Seed data generation failed: \${error.message}\`));
1066
- process.exit(1);
1067
- }
1068
-
1069
- `;
1070
- }
1071
- /**
1072
- * Plugin that generates seed data files with Kysely batch insert and tailor.idp.Client for _User.
1073
- * @param options - Plugin options
1074
- * @param options.distPath - Output directory path for generated seed files
1075
- * @param options.machineUserName - Default machine user name for authentication
1076
- * @param options.disableIdpUserSync - Skip emitting individual `_User <-> userProfile` foreign keys. Both directions are emitted by default; set a direction to `true` to relax that side.
1077
- * @returns Plugin instance with onTailorDBReady hook
1078
- */
1079
- function seedPlugin(options) {
1080
- return {
1081
- id: SeedGeneratorID,
1082
- description: "Generates seed data files (Kysely batch insert + tailor.idp.Client for _User)",
1083
- pluginConfig: options,
1084
- async onTailorDBReady(ctx) {
1085
- const files = [];
1086
- const namespaceConfigs = [];
1087
- const idpUser = ctx.auth ? processIdpUser(ctx.auth) ?? null : null;
1088
- const hasIdpUser = idpUser !== null;
1089
- const idpUserSyncFKs = resolveIdpUserSyncFKs(ctx.pluginConfig.disableIdpUserSync);
1090
- for (const ns of ctx.tailordb) {
1091
- const types = [];
1092
- const dependencies = {};
1093
- const selfRefTypes = [];
1094
- for (const [typeName, type] of Object.entries(ns.types)) {
1095
- const source = assertDefined(ns.sourceInfo.get(typeName), `source info missing for type: ${typeName}`);
1096
- const typeInfo = processSeedTypeInfo(type, ns.namespace);
1097
- const linesDb = processLinesDb(type, source);
1098
- if (idpUserSyncFKs.emitUserToIdpFK && idpUser && typeName === idpUser.schema.userTypeName) linesDb.foreignKeys.push({
1099
- column: idpUser.schema.usernameField,
1100
- references: {
1101
- table: "_User",
1102
- column: "name"
1103
- }
1104
- });
1105
- types.push(typeInfo.name);
1106
- dependencies[typeInfo.name] = typeInfo.dependencies;
1107
- if (typeInfo.selfRefFields.length > 0) selfRefTypes.push(typeInfo.name);
1108
- files.push({
1109
- path: path.join(ctx.pluginConfig.distPath, typeInfo.dataFile),
1110
- content: "",
1111
- skipIfExists: true
1112
- });
1113
- const schemaOutputPath = path.join(ctx.pluginConfig.distPath, "data", `${linesDb.typeName}.schema.ts`);
1114
- if (linesDb.pluginSource && linesDb.pluginSource.pluginImportPath) {
1115
- let originalImportPath;
1116
- if (linesDb.pluginSource.originalFilePath && linesDb.pluginSource.originalExportName) {
1117
- const relativePath = path.relative(path.dirname(schemaOutputPath), linesDb.pluginSource.originalFilePath);
1118
- originalImportPath = relativePath.replace(/\.ts$/, "").startsWith(".") ? relativePath.replace(/\.ts$/, "") : `./${relativePath.replace(/\.ts$/, "")}`;
1119
- }
1120
- const schemaContent = generateLinesDbSchemaFileWithPluginAPI(linesDb, {
1121
- configImportPath: path.relative(path.dirname(schemaOutputPath), ctx.configPath),
1122
- originalImportPath
1123
- });
1124
- files.push({
1125
- path: schemaOutputPath,
1126
- content: schemaContent
1127
- });
1128
- } else {
1129
- const relativePath = path.relative(path.dirname(schemaOutputPath), linesDb.importPath);
1130
- const schemaContent = generateLinesDbSchemaFile(linesDb, relativePath.replace(/\.ts$/, "").startsWith(".") ? relativePath.replace(/\.ts$/, "") : `./${relativePath.replace(/\.ts$/, "")}`);
1131
- files.push({
1132
- path: schemaOutputPath,
1133
- content: schemaContent
1134
- });
1135
- }
1136
- }
1137
- namespaceConfigs.push({
1138
- namespace: ns.namespace,
1139
- types,
1140
- dependencies,
1141
- selfRefTypes
1142
- });
1143
- }
1144
- if (idpUser) {
1145
- files.push({
1146
- path: path.join(ctx.pluginConfig.distPath, idpUser.dataFile),
1147
- content: "",
1148
- skipIfExists: true
1149
- });
1150
- files.push({
1151
- path: path.join(ctx.pluginConfig.distPath, "data", `${idpUser.name}.schema.ts`),
1152
- content: generateIdpUserSchemaFile({
1153
- usernameField: idpUser.schema.usernameField,
1154
- userTypeName: idpUser.schema.userTypeName,
1155
- includeUserProfileFK: idpUserSyncFKs.emitIdpToUserFK
1156
- })
1157
- });
1158
- }
1159
- const relativeConfigPath = path.relative(ctx.pluginConfig.distPath, ctx.configPath);
1160
- files.push({
1161
- path: path.join(ctx.pluginConfig.distPath, "exec.mjs"),
1162
- content: generateExecScript(ctx.pluginConfig.machineUserName, relativeConfigPath, namespaceConfigs, hasIdpUser, idpUser?.idpNamespace ?? null)
1163
- });
1164
- return { files };
1165
- }
1166
- };
1167
- }
1168
-
1169
- //#endregion
1170
- export { seedPlugin as n, isPluginGeneratedType as r, SeedGeneratorID as t };
1171
- //# sourceMappingURL=seed-BH2FbrPV.mjs.map