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