@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,2 +1,46 @@
1
- import { n as seedPlugin, t as SeedGeneratorID } from "../../../index-B7AKc18V.mjs";
2
- export { SeedGeneratorID, seedPlugin };
1
+ import { Plugin } from "../../types.mjs";
2
+ //#region src/plugin/builtin/seed/index.d.ts
3
+ /** Unique identifier for the seed generator plugin. */
4
+ declare const SeedGeneratorID = "@tailor-platform/seed";
5
+ type DisableIdpUserSyncDirections = {
6
+ /**
7
+ * Skip emitting the foreign key from `<userProfile>.<usernameField>` to
8
+ * `_User.name`. Defaults to `false` (FK emitted).
9
+ *
10
+ * Set to `true` to seed pre-registration states such as
11
+ * invited-but-not-registered users.
12
+ */
13
+ userToIdp?: boolean;
14
+ /**
15
+ * Skip emitting the foreign key from `_User.name` to
16
+ * `<userProfile>.<usernameField>`. Defaults to `false` (FK emitted).
17
+ *
18
+ * Set to `true` to seed `_User` rows that do not yet have a corresponding
19
+ * userProfile row.
20
+ */
21
+ idpToUser?: boolean;
22
+ };
23
+ type SeedPluginOptions = {
24
+ distPath: string;
25
+ machineUserName?: string;
26
+ /**
27
+ * Disable individual `_User <-> userProfile` foreign keys emitted into
28
+ * the generated seed schema. Both directions are emitted by default.
29
+ *
30
+ * Set a direction to `true` to relax it — for example to seed invited
31
+ * users that do not yet have an IdP credential.
32
+ */
33
+ disableIdpUserSync?: DisableIdpUserSyncDirections;
34
+ };
35
+ /**
36
+ * Plugin that generates seed data and schema files consumed by the
37
+ * `tailor seed` commands (@tailor-platform/sdk-plugin-seed).
38
+ * @param options - Plugin options
39
+ * @param options.distPath - Output directory path for generated seed files
40
+ * @param options.machineUserName - Default machine user name for authentication
41
+ * @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.
42
+ * @returns Plugin instance with onTailorDBReady hook
43
+ */
44
+ declare function seedPlugin(options: SeedPluginOptions): Plugin<unknown, SeedPluginOptions>;
45
+ //#endregion
46
+ export { SeedGeneratorID, SeedPluginOptions, seedPlugin };
@@ -1,3 +1,3 @@
1
- import { n as seedPlugin, t as SeedGeneratorID } from "../../../seed-jf3008-h.mjs";
1
+ import { n as seedPlugin, t as SeedGeneratorID } from "../../../seed-LUVr7jHL.mjs";
2
2
 
3
3
  export { SeedGeneratorID, seedPlugin };
@@ -0,0 +1,19 @@
1
+ import "../../../parser/service/tailordb/types.mjs";
2
+ import "../../types.mjs";
3
+ import "./types.mjs";
4
+ //#region src/plugin/builtin/seed/seed-type-processor.d.ts
5
+ /**
6
+ * Seed ordering information for a TailorDB namespace.
7
+ */
8
+ interface SeedNamespaceConfig {
9
+ /** TailorDB namespace name. */
10
+ namespace: string;
11
+ /** Type names in the namespace, in definition order. */
12
+ types: string[];
13
+ /** Seed dependencies (referenced type names) per type. */
14
+ dependencies: Record<string, string[]>;
15
+ /** Types with self-referencing fields, seeded in two passes. */
16
+ selfRefTypes: string[];
17
+ }
18
+ //#endregion
19
+ export { SeedNamespaceConfig };
@@ -0,0 +1,2 @@
1
+ import "../../../parser/service/tailordb/types.mjs";
2
+ import "@toiroakr/lines-db";
@@ -0,0 +1,16 @@
1
+ import { TailorAnyDBType } from "../configure/services/tailordb/types.mjs";
2
+ //#region src/plugin/get-generated-type.d.ts
3
+ /**
4
+ * Get a generated type from a plugin by loading the config and resolving everything automatically.
5
+ * For type-attached plugins, calls onTypeLoaded() with the sourceType.
6
+ * For namespace plugins, calls onNamespaceLoaded() with auto-resolved namespace.
7
+ * Results are cached per config path, plugin, namespace, and pluginConfig to avoid redundant processing.
8
+ * @param configPath - Path to tailor.config.ts (absolute or relative to cwd)
9
+ * @param pluginId - The plugin's unique identifier
10
+ * @param sourceType - The source TailorDB type (null for namespace plugins)
11
+ * @param kind - The generated type kind (e.g., "request", "step")
12
+ * @returns The generated TailorDB type
13
+ */
14
+ declare function getGeneratedType(configPath: string, pluginId: string, sourceType: TailorAnyDBType | null, kind: string): Promise<TailorAnyDBType>;
15
+ //#endregion
16
+ export { getGeneratedType };
@@ -1,117 +1,3 @@
1
- import { B as TailorActor, V as TailorEnv, f as TailorAnyDBType } from "../types-DCUhgpyI.mjs";
2
-
3
- //#region src/plugin/with-context.d.ts
4
- /**
5
- * Plugin executor factory function type.
6
- * Takes context and returns an executor configuration.
7
- * Returns unknown since the exact return type depends on createExecutor's generic params.
8
- */
9
- type PluginExecutorFactory<Ctx> = (ctx: Ctx) => unknown;
10
- /**
11
- * Base args for plugin executor function operations.
12
- * Provides typed access to runtime context without requiring specific record types.
13
- */
14
- interface PluginFunctionArgs {
15
- /** Workspace ID where the executor runs */
16
- workspaceId: string;
17
- /** Application namespace */
18
- appNamespace: string;
19
- /** Environment variables */
20
- env: TailorEnv;
21
- /** Actor (user) who triggered the event, null for system events */
22
- actor: TailorActor | null;
23
- /** Name of the TailorDB type */
24
- typeName: string;
25
- /** TailorDB connections by namespace */
26
- tailordb: Record<string, unknown>;
27
- }
28
- /**
29
- * Args for plugin executors triggered on record creation.
30
- */
31
- interface PluginRecordCreatedArgs extends PluginFunctionArgs {
32
- /** The newly created record */
33
- newRecord: Record<string, unknown>;
34
- }
35
- /**
36
- * Args for plugin executors triggered on record update.
37
- */
38
- interface PluginRecordUpdatedArgs extends PluginFunctionArgs {
39
- /** The record after update */
40
- newRecord: Record<string, unknown>;
41
- /** The record before update */
42
- oldRecord: Record<string, unknown>;
43
- }
44
- /**
45
- * Args for plugin executors triggered on record deletion.
46
- */
47
- interface PluginRecordDeletedArgs extends PluginFunctionArgs {
48
- /** The deleted record */
49
- oldRecord: Record<string, unknown>;
50
- }
51
- /**
52
- * Database schema type for plugins.
53
- * Since plugins work with dynamic types, the schema uses Record types.
54
- */
55
- type PluginDBSchema = Record<string, Record<string, unknown>>;
56
- /**
57
- * Base record type for TailorDB records.
58
- * All records have an id field.
59
- */
60
- type PluginRecord = {
61
- id: string;
62
- } & Record<string, unknown>;
63
- /**
64
- * Define a plugin executor that receives context at runtime.
65
- * This allows executor definitions to be in separate files while
66
- * still receiving dynamic values like typeName, generated types, and namespace.
67
- * @param factory - Function that takes context and returns executor configuration
68
- * @returns The same factory function (for type inference)
69
- * @example
70
- * ```typescript
71
- * // executors/on-create.ts
72
- * import { withPluginContext } from "@tailor-platform/sdk/plugin";
73
- * import { createExecutor, recordCreatedTrigger } from "@tailor-platform/sdk";
74
- * import { getDB } from "@tailor-platform/function-kysely-tailordb";
75
- *
76
- * interface MyContext {
77
- * sourceType: TailorAnyDBType;
78
- * historyType: TailorAnyDBType;
79
- * namespace: string;
80
- * }
81
- *
82
- * export default withPluginContext<MyContext>((ctx) =>
83
- * createExecutor({
84
- * name: `${ctx.sourceType.name.toLowerCase()}-on-create`,
85
- * trigger: recordCreatedTrigger({ type: ctx.sourceType }),
86
- * operation: {
87
- * kind: "function",
88
- * body: async (args) => {
89
- * const db = getDB(ctx.namespace);
90
- * await db.insertInto(ctx.historyType.name).values({
91
- * recordId: args.newRecord.id,
92
- * // ...
93
- * }).execute();
94
- * },
95
- * },
96
- * })
97
- * );
98
- * ```
99
- */
100
- declare function withPluginContext<Ctx>(factory: PluginExecutorFactory<Ctx>): PluginExecutorFactory<Ctx>;
101
- //#endregion
102
- //#region src/plugin/get-generated-type.d.ts
103
- /**
104
- * Get a generated type from a plugin by loading the config and resolving everything automatically.
105
- * For type-attached plugins, calls onTypeLoaded() with the sourceType.
106
- * For namespace plugins, calls onNamespaceLoaded() with auto-resolved namespace.
107
- * Results are cached per config path, plugin, namespace, and pluginConfig to avoid redundant processing.
108
- * @param configPath - Path to tailor.config.ts (absolute or relative to cwd)
109
- * @param pluginId - The plugin's unique identifier
110
- * @param sourceType - The source TailorDB type (null for namespace plugins)
111
- * @param kind - The generated type kind (e.g., "request", "step")
112
- * @returns The generated TailorDB type
113
- */
114
- declare function getGeneratedType(configPath: string, pluginId: string, sourceType: TailorAnyDBType | null, kind: string): Promise<TailorAnyDBType>;
115
- //#endregion
116
- export { type PluginDBSchema, type PluginExecutorFactory, type PluginFunctionArgs, type PluginRecord, type PluginRecordCreatedArgs, type PluginRecordDeletedArgs, type PluginRecordUpdatedArgs, getGeneratedType, withPluginContext };
117
- //# sourceMappingURL=index.d.mts.map
1
+ import { PluginDBSchema, PluginExecutorFactory, PluginFunctionArgs, PluginRecord, PluginRecordCreatedArgs, PluginRecordDeletedArgs, PluginRecordUpdatedArgs, withPluginContext } from "./with-context.mjs";
2
+ import { getGeneratedType } from "./get-generated-type.mjs";
3
+ export { type PluginDBSchema, type PluginExecutorFactory, type PluginFunctionArgs, type PluginRecord, type PluginRecordCreatedArgs, type PluginRecordDeletedArgs, type PluginRecordUpdatedArgs, getGeneratedType, withPluginContext };
@@ -1,5 +1,5 @@
1
- import * as fs from "node:fs";
2
1
  import * as path from "pathe";
2
+ import * as fs from "node:fs";
3
3
  import { pathToFileURL } from "node:url";
4
4
 
5
5
  //#region src/plugin/with-context.ts
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/plugin/with-context.ts","../../src/plugin/get-generated-type.ts"],"sourcesContent":["/**\n * Plugin executor context support for defining plugin executors in separate files.\n * This module provides utilities for creating type-safe plugin executors that receive\n * context (like type references and namespace) at runtime.\n */\n\nimport type { TailorActor, TailorEnv } from \"@/runtime/types\";\n\n/**\n * Plugin executor factory function type.\n * Takes context and returns an executor configuration.\n * Returns unknown since the exact return type depends on createExecutor's generic params.\n */\nexport type PluginExecutorFactory<Ctx> = (ctx: Ctx) => unknown;\n\n// ============================================================================\n// Plugin Executor Args Types\n// ============================================================================\n\n/**\n * Base args for plugin executor function operations.\n * Provides typed access to runtime context without requiring specific record types.\n */\nexport interface PluginFunctionArgs {\n /** Workspace ID where the executor runs */\n workspaceId: string;\n /** Application namespace */\n appNamespace: string;\n /** Environment variables */\n env: TailorEnv;\n /** Actor (user) who triggered the event, null for system events */\n actor: TailorActor | null;\n /** Name of the TailorDB type */\n typeName: string;\n /** TailorDB connections by namespace */\n tailordb: Record<string, unknown>;\n}\n\n/**\n * Args for plugin executors triggered on record creation.\n */\nexport interface PluginRecordCreatedArgs extends PluginFunctionArgs {\n /** The newly created record */\n newRecord: Record<string, unknown>;\n}\n\n/**\n * Args for plugin executors triggered on record update.\n */\nexport interface PluginRecordUpdatedArgs extends PluginFunctionArgs {\n /** The record after update */\n newRecord: Record<string, unknown>;\n /** The record before update */\n oldRecord: Record<string, unknown>;\n}\n\n/**\n * Args for plugin executors triggered on record deletion.\n */\nexport interface PluginRecordDeletedArgs extends PluginFunctionArgs {\n /** The deleted record */\n oldRecord: Record<string, unknown>;\n}\n\n/**\n * Database schema type for plugins.\n * Since plugins work with dynamic types, the schema uses Record types.\n */\nexport type PluginDBSchema = Record<string, Record<string, unknown>>;\n\n/**\n * Base record type for TailorDB records.\n * All records have an id field.\n */\nexport type PluginRecord = { id: string } & Record<string, unknown>;\n\n/**\n * Define a plugin executor that receives context at runtime.\n * This allows executor definitions to be in separate files while\n * still receiving dynamic values like typeName, generated types, and namespace.\n * @param factory - Function that takes context and returns executor configuration\n * @returns The same factory function (for type inference)\n * @example\n * ```typescript\n * // executors/on-create.ts\n * import { withPluginContext } from \"@tailor-platform/sdk/plugin\";\n * import { createExecutor, recordCreatedTrigger } from \"@tailor-platform/sdk\";\n * import { getDB } from \"@tailor-platform/function-kysely-tailordb\";\n *\n * interface MyContext {\n * sourceType: TailorAnyDBType;\n * historyType: TailorAnyDBType;\n * namespace: string;\n * }\n *\n * export default withPluginContext<MyContext>((ctx) =>\n * createExecutor({\n * name: `${ctx.sourceType.name.toLowerCase()}-on-create`,\n * trigger: recordCreatedTrigger({ type: ctx.sourceType }),\n * operation: {\n * kind: \"function\",\n * body: async (args) => {\n * const db = getDB(ctx.namespace);\n * await db.insertInto(ctx.historyType.name).values({\n * recordId: args.newRecord.id,\n * // ...\n * }).execute();\n * },\n * },\n * })\n * );\n * ```\n */\nexport function withPluginContext<Ctx>(\n factory: PluginExecutorFactory<Ctx>,\n): PluginExecutorFactory<Ctx> {\n return factory;\n}\n","import * as fs from \"node:fs\";\nimport { pathToFileURL } from \"node:url\";\nimport * as path from \"pathe\";\nimport type { TailorAnyDBType } from \"@/configure/services/tailordb/types\";\nimport type { Plugin, PluginOutput, TypePluginOutput } from \"@/plugin/types\";\n\n// ========================================\n// Config loading and caching\n// ========================================\n\ninterface PluginEntry {\n plugin: Plugin;\n pluginConfig: unknown;\n}\n\ninterface ConfigCache {\n config: { db?: Record<string, unknown> };\n plugins: Map<string, PluginEntry>;\n configDir: string;\n}\n\n/** Cache: resolved config path -> loaded config data */\nconst configCacheMap = new Map<string, ConfigCache>();\n\n/**\n * Check if a value is a Plugin instance.\n * @param value - Value to check\n * @returns True if value has the shape of Plugin\n */\nfunction isPlugin(value: unknown): value is Plugin {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as Record<string, unknown>).id === \"string\" &&\n typeof (value as Record<string, unknown>).description === \"string\"\n );\n}\n\n/**\n * Load and cache config module from the given path.\n * Extracts plugins from all array exports using definePlugins() format.\n * Returns null if the config file does not exist (e.g., in bundled executor on platform server).\n * @param configPath - Absolute or relative path to tailor.config.ts\n * @returns Cached config data with plugins map, or null if config file is not available\n */\nasync function loadAndCacheConfig(configPath: string): Promise<ConfigCache | null> {\n const resolvedPath = path.resolve(configPath);\n\n const cached = configCacheMap.get(resolvedPath);\n if (cached) return cached;\n\n // Config file may not exist in bundled environments (e.g., platform server)\n if (!fs.existsSync(resolvedPath)) {\n return null;\n }\n\n const configModule = await import(pathToFileURL(resolvedPath).href);\n if (!configModule?.default) {\n throw new Error(`Invalid config module at \"${resolvedPath}\": default export not found`);\n }\n\n const config = configModule.default as { db?: Record<string, unknown> };\n const configDir = path.dirname(resolvedPath);\n const plugins = new Map<string, PluginEntry>();\n\n // Find plugin arrays from exports (definePlugins returns PluginConfig[])\n for (const value of Object.values(configModule)) {\n if (!Array.isArray(value)) continue;\n\n for (const item of value) {\n if (isPlugin(item)) {\n plugins.set(item.id, { plugin: item, pluginConfig: item.pluginConfig });\n }\n }\n }\n\n const result: ConfigCache = { config, plugins, configDir };\n configCacheMap.set(resolvedPath, result);\n return result;\n}\n\n// ========================================\n// Namespace resolution\n// ========================================\n\ninterface DbNamespaceConfig {\n files?: string[];\n external?: boolean;\n}\n\n/**\n * Resolve the namespace for a type-attached sourceType by checking config.db file patterns.\n * Uses ESM module cache identity: same file path yields same object references.\n * @param config - App config with db namespace definitions\n * @param config.db - DB namespace definitions\n * @param configDir - Directory containing the config file\n * @param sourceType - The TailorDB type to look up\n * @returns The namespace name\n */\nasync function resolveNamespaceForType(\n config: { db?: Record<string, unknown> },\n configDir: string,\n sourceType: TailorAnyDBType,\n): Promise<string> {\n if (!config.db) {\n throw new Error(`No db configuration found in config`);\n }\n\n for (const [namespace, nsConfig] of Object.entries(config.db)) {\n const dbConfig = nsConfig as DbNamespaceConfig;\n // Skip external namespaces (no files to resolve)\n if (dbConfig.external || !dbConfig.files) continue;\n\n for (const pattern of dbConfig.files) {\n const absolutePattern = path.resolve(configDir, pattern);\n let matchedFiles: string[];\n try {\n matchedFiles = fs.globSync(absolutePattern);\n } catch {\n continue;\n }\n\n for (const file of matchedFiles) {\n const mod = await import(pathToFileURL(file).href);\n for (const exported of Object.values(mod)) {\n if (exported === sourceType) {\n return namespace;\n }\n }\n }\n }\n }\n\n throw new Error(\n `Could not resolve namespace for type \"${sourceType.name}\". ` +\n `Ensure the type file is included in a db namespace's files pattern.`,\n );\n}\n\n/**\n * Resolve the namespace for a namespace plugin by trying each namespace.\n * Calls onNamespaceLoaded() for each and returns the first whose output contains the requested kind.\n * @param config - App config with db namespace definitions\n * @param config.db - DB namespace definitions\n * @param plugin - Plugin instance\n * @param kind - The generated type kind to look for\n * @param pluginConfig - Plugin-level configuration\n * @returns The namespace name\n */\nasync function resolveNamespaceForNamespacePlugin(\n config: { db?: Record<string, unknown> },\n plugin: Plugin,\n kind: string,\n pluginConfig: unknown,\n): Promise<{ namespace: string; output: PluginOutput }> {\n if (!config.db) {\n throw new Error(`No db configuration found in config`);\n }\n\n if (!plugin.onNamespaceLoaded) {\n throw new Error(`Plugin \"${plugin.id}\" does not have a onNamespaceLoaded() method`);\n }\n\n for (const namespace of Object.keys(config.db)) {\n const dbConfig = config.db[namespace] as DbNamespaceConfig;\n if (dbConfig.external) continue;\n\n const output = await plugin.onNamespaceLoaded({\n pluginConfig,\n namespace,\n });\n\n if (output.types?.[kind]) {\n return { namespace, output };\n }\n }\n\n throw new Error(\n `Could not resolve namespace for plugin \"${plugin.id}\" with kind \"${kind}\". ` +\n `No namespace produced a type with that kind.`,\n );\n}\n\n// ========================================\n// Process caching\n// ========================================\n\n// Cache: plugin -> cacheKey -> TypePluginOutput\nconst processCache = new WeakMap<Plugin, Map<string, TypePluginOutput>>();\n\n// Cache for namespace plugins: plugin -> cacheKey -> PluginOutput\nconst namespaceProcessCache = new WeakMap<Plugin, Map<string, PluginOutput>>();\n\n/**\n * Generate a cache key that includes pluginConfig.\n * @param baseKey - Base key for the cache\n * @param pluginConfig - Plugin configuration to include in the key\n * @returns Cache key string\n */\nfunction getCacheKey(baseKey: string, pluginConfig: unknown): string {\n if (pluginConfig === undefined) {\n return baseKey;\n }\n try {\n return `${baseKey}:${JSON.stringify(pluginConfig)}`;\n } catch {\n throw new Error(\n `pluginConfig must be JSON-serializable for caching. Received non-serializable value.`,\n );\n }\n}\n\n// ========================================\n// Main API\n// ========================================\n\n/**\n * Get a generated type from a plugin by loading the config and resolving everything automatically.\n * For type-attached plugins, calls onTypeLoaded() with the sourceType.\n * For namespace plugins, calls onNamespaceLoaded() with auto-resolved namespace.\n * Results are cached per config path, plugin, namespace, and pluginConfig to avoid redundant processing.\n * @param configPath - Path to tailor.config.ts (absolute or relative to cwd)\n * @param pluginId - The plugin's unique identifier\n * @param sourceType - The source TailorDB type (null for namespace plugins)\n * @param kind - The generated type kind (e.g., \"request\", \"step\")\n * @returns The generated TailorDB type\n */\nexport async function getGeneratedType(\n configPath: string,\n pluginId: string,\n sourceType: TailorAnyDBType | null,\n kind: string,\n): Promise<TailorAnyDBType> {\n const cache = await loadAndCacheConfig(configPath);\n\n if (!cache) {\n // Config not available (e.g., running in bundled executor on platform server).\n // Return a placeholder. The actual type is resolved at generate/apply time.\n return { name: `__placeholder_${kind}__`, fields: {} } as TailorAnyDBType;\n }\n\n const { config, configDir, plugins } = cache;\n\n const pluginEntry = plugins.get(pluginId);\n if (!pluginEntry) {\n throw new Error(\n `Plugin \"${pluginId}\" not found in config at \"${configPath}\". ` +\n `Ensure the plugin is registered via definePlugins().`,\n );\n }\n\n const { plugin, pluginConfig } = pluginEntry;\n\n if (sourceType === null) {\n return getGeneratedTypeForNamespacePlugin(config, plugin, kind, pluginConfig);\n }\n\n const namespace = await resolveNamespaceForType(config, configDir, sourceType);\n return getGeneratedTypeForTypeAttachedPlugin(plugin, sourceType, kind, pluginConfig, namespace);\n}\n\n/**\n * Get a generated type from a type-attached plugin.\n * @param plugin - The plugin instance (must have onTypeLoaded() method)\n * @param sourceType - The source TailorDB type\n * @param kind - The generated type kind\n * @param pluginConfig - Plugin-level configuration\n * @param namespace - Resolved namespace\n * @returns The generated TailorDB type\n */\nasync function getGeneratedTypeForTypeAttachedPlugin(\n plugin: Plugin,\n sourceType: TailorAnyDBType,\n kind: string,\n pluginConfig: unknown,\n namespace: string,\n): Promise<TailorAnyDBType> {\n if (!plugin.onTypeLoaded) {\n throw new Error(`Plugin \"${plugin.id}\" does not have a onTypeLoaded() method`);\n }\n\n // Check cache first\n let pluginCache = processCache.get(plugin);\n if (!pluginCache) {\n pluginCache = new Map();\n processCache.set(plugin, pluginCache);\n }\n\n const cacheKey = getCacheKey(`${sourceType.name}:ns=${namespace}`, pluginConfig);\n let output = pluginCache.get(cacheKey);\n\n if (!output) {\n const typeConfig = sourceType.plugins.find((p) => p.pluginId === plugin.id)?.config;\n output = await plugin.onTypeLoaded({\n type: sourceType,\n typeConfig: typeConfig ?? {},\n pluginConfig,\n namespace,\n });\n pluginCache.set(cacheKey, output);\n }\n\n const generatedType = output.types?.[kind];\n if (!generatedType) {\n throw new Error(\n `Generated type not found: plugin=${plugin.id}, sourceType=${sourceType.name}, kind=${kind}`,\n );\n }\n\n return generatedType as TailorAnyDBType;\n}\n\n/**\n * Get a generated type from a namespace plugin.\n * Auto-resolves the namespace by trying each one.\n * @param config - App config with db namespace definitions\n * @param config.db - DB namespace definitions\n * @param plugin - The plugin instance (must have onNamespaceLoaded() method)\n * @param kind - The generated type kind\n * @param pluginConfig - Plugin-level configuration\n * @returns The generated TailorDB type\n */\nasync function getGeneratedTypeForNamespacePlugin(\n config: { db?: Record<string, unknown> },\n plugin: Plugin,\n kind: string,\n pluginConfig: unknown,\n): Promise<TailorAnyDBType> {\n if (!plugin.onNamespaceLoaded) {\n throw new Error(`Plugin \"${plugin.id}\" does not have a onNamespaceLoaded() method`);\n }\n\n // Check cache first - try all namespaces\n let pluginCache = namespaceProcessCache.get(plugin);\n if (!pluginCache) {\n pluginCache = new Map();\n namespaceProcessCache.set(plugin, pluginCache);\n }\n\n // Try cached results first\n if (config.db) {\n for (const namespace of Object.keys(config.db)) {\n const dbConfig = config.db[namespace] as DbNamespaceConfig;\n if (dbConfig.external) continue;\n\n const cacheKey = getCacheKey(`namespace:ns=${namespace}`, pluginConfig);\n const cached = pluginCache.get(cacheKey);\n if (cached?.types?.[kind]) {\n return cached.types[kind] as TailorAnyDBType;\n }\n }\n }\n\n // Not in cache - resolve namespace and process\n const { namespace, output } = await resolveNamespaceForNamespacePlugin(\n config,\n plugin,\n kind,\n pluginConfig,\n );\n\n const cacheKey = getCacheKey(`namespace:ns=${namespace}`, pluginConfig);\n pluginCache.set(cacheKey, output);\n\n const generatedType = output.types?.[kind];\n if (!generatedType) {\n throw new Error(`Generated type not found: plugin=${plugin.id}, kind=${kind}`);\n }\n\n return generatedType as TailorAnyDBType;\n}\n\n/**\n * Clear all internal caches. For testing only.\n */\nexport function _clearCacheForTesting(): void {\n configCacheMap.clear();\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/plugin/with-context.ts","../../src/plugin/get-generated-type.ts"],"sourcesContent":["/**\n * Plugin executor context support for defining plugin executors in separate files.\n * This module provides utilities for creating type-safe plugin executors that receive\n * context (like type references and namespace) at runtime.\n */\n\nimport type { TailorEnv, TailorPrincipal } from \"#/runtime/types\";\n\n/**\n * Plugin executor factory function type.\n * Takes context and returns an executor configuration.\n * Returns unknown since the exact return type depends on createExecutor's generic params.\n */\nexport type PluginExecutorFactory<Ctx> = (ctx: Ctx) => unknown;\n\n// ============================================================================\n// Plugin Executor Args Types\n// ============================================================================\n\n/**\n * Base args for plugin executor function operations.\n * Provides typed access to runtime context without requiring specific record types.\n */\nexport interface PluginFunctionArgs {\n /** Workspace ID where the executor runs */\n workspaceId: string;\n /** Application namespace */\n appNamespace: string;\n /** Environment variables */\n env: TailorEnv;\n /** Principal that triggered the event, null for system events */\n actor: TailorPrincipal | null;\n /** Name of the TailorDB type */\n typeName: string;\n /** TailorDB connections by namespace */\n tailordb: Record<string, unknown>;\n}\n\n/**\n * Args for plugin executors triggered on record creation.\n */\nexport interface PluginRecordCreatedArgs extends PluginFunctionArgs {\n /** The newly created record */\n newRecord: Record<string, unknown>;\n}\n\n/**\n * Args for plugin executors triggered on record update.\n */\nexport interface PluginRecordUpdatedArgs extends PluginFunctionArgs {\n /** The record after update */\n newRecord: Record<string, unknown>;\n /** The record before update */\n oldRecord: Record<string, unknown>;\n}\n\n/**\n * Args for plugin executors triggered on record deletion.\n */\nexport interface PluginRecordDeletedArgs extends PluginFunctionArgs {\n /** The deleted record */\n oldRecord: Record<string, unknown>;\n}\n\n/**\n * Database schema type for plugins.\n * Since plugins work with dynamic types, the schema uses Record types.\n */\nexport type PluginDBSchema = Record<string, Record<string, unknown>>;\n\n/**\n * Base record type for TailorDB records.\n * All records have an id field.\n */\nexport type PluginRecord = { id: string } & Record<string, unknown>;\n\n/**\n * Define a plugin executor that receives context at runtime.\n * This allows executor definitions to be in separate files while\n * still receiving dynamic values like typeName, generated types, and namespace.\n * @param factory - Function that takes context and returns executor configuration\n * @returns The same factory function (for type inference)\n * @example\n * ```typescript\n * // executors/on-create.ts\n * import { withPluginContext } from \"@tailor-platform/sdk/plugin\";\n * import { createExecutor, recordCreatedTrigger } from \"@tailor-platform/sdk\";\n * import { getDB } from \"@tailor-platform/function-kysely-tailordb\";\n *\n * interface MyContext {\n * sourceType: TailorAnyDBType;\n * historyType: TailorAnyDBType;\n * namespace: string;\n * }\n *\n * export default withPluginContext<MyContext>((ctx) =>\n * createExecutor({\n * name: `${ctx.sourceType.name.toLowerCase()}-on-create`,\n * trigger: recordCreatedTrigger({ type: ctx.sourceType }),\n * operation: {\n * kind: \"function\",\n * body: async (args) => {\n * const db = getDB(ctx.namespace);\n * await db.insertInto(ctx.historyType.name).values({\n * recordId: args.newRecord.id,\n * // ...\n * }).execute();\n * },\n * },\n * })\n * );\n * ```\n */\nexport function withPluginContext<Ctx>(\n factory: PluginExecutorFactory<Ctx>,\n): PluginExecutorFactory<Ctx> {\n return factory;\n}\n","import * as fs from \"node:fs\";\nimport { pathToFileURL } from \"node:url\";\nimport * as path from \"pathe\";\nimport type { TailorAnyDBType } from \"#/configure/services/tailordb/types\";\nimport type { Plugin, PluginOutput, TypePluginOutput } from \"#/plugin/types\";\n\n// ========================================\n// Config loading and caching\n// ========================================\n\ninterface PluginEntry {\n plugin: Plugin;\n pluginConfig: unknown;\n}\n\ninterface ConfigCache {\n config: { db?: Record<string, unknown> };\n plugins: Map<string, PluginEntry>;\n configDir: string;\n}\n\n/** Cache: resolved config path -> loaded config data */\nconst configCacheMap = new Map<string, ConfigCache>();\n\n/**\n * Check if a value is a Plugin instance.\n * @param value - Value to check\n * @returns True if value has the shape of Plugin\n */\nfunction isPlugin(value: unknown): value is Plugin {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as Record<string, unknown>).id === \"string\" &&\n typeof (value as Record<string, unknown>).description === \"string\"\n );\n}\n\n/**\n * Load and cache config module from the given path.\n * Extracts plugins from all array exports using definePlugins() format.\n * Returns null if the config file does not exist (e.g., in bundled executor on platform server).\n * @param configPath - Absolute or relative path to tailor.config.ts\n * @returns Cached config data with plugins map, or null if config file is not available\n */\nasync function loadAndCacheConfig(configPath: string): Promise<ConfigCache | null> {\n const resolvedPath = path.resolve(configPath);\n\n const cached = configCacheMap.get(resolvedPath);\n if (cached) return cached;\n\n // Config file may not exist in bundled environments (e.g., platform server)\n if (!fs.existsSync(resolvedPath)) {\n return null;\n }\n\n const configModule = await import(pathToFileURL(resolvedPath).href);\n if (!configModule?.default) {\n throw new Error(`Invalid config module at \"${resolvedPath}\": default export not found`);\n }\n\n const config = configModule.default as { db?: Record<string, unknown> };\n const configDir = path.dirname(resolvedPath);\n const plugins = new Map<string, PluginEntry>();\n\n // Find plugin arrays from exports (definePlugins returns PluginConfig[])\n for (const value of Object.values(configModule)) {\n if (!Array.isArray(value)) continue;\n\n for (const item of value) {\n if (isPlugin(item)) {\n plugins.set(item.id, { plugin: item, pluginConfig: item.pluginConfig });\n }\n }\n }\n\n const result: ConfigCache = { config, plugins, configDir };\n configCacheMap.set(resolvedPath, result);\n return result;\n}\n\n// ========================================\n// Namespace resolution\n// ========================================\n\ninterface DbNamespaceConfig {\n files?: string[];\n external?: boolean;\n}\n\n/**\n * Resolve the namespace for a type-attached sourceType by checking config.db file patterns.\n * Uses ESM module cache identity: same file path yields same object references.\n * @param config - App config with db namespace definitions\n * @param config.db - DB namespace definitions\n * @param configDir - Directory containing the config file\n * @param sourceType - The TailorDB type to look up\n * @returns The namespace name\n */\nasync function resolveNamespaceForType(\n config: { db?: Record<string, unknown> },\n configDir: string,\n sourceType: TailorAnyDBType,\n): Promise<string> {\n if (!config.db) {\n throw new Error(`No db configuration found in config`);\n }\n\n for (const [namespace, nsConfig] of Object.entries(config.db)) {\n const dbConfig = nsConfig as DbNamespaceConfig;\n // Skip external namespaces (no files to resolve)\n if (dbConfig.external || !dbConfig.files) continue;\n\n for (const pattern of dbConfig.files) {\n const absolutePattern = path.resolve(configDir, pattern);\n let matchedFiles: string[];\n try {\n matchedFiles = fs.globSync(absolutePattern);\n } catch {\n continue;\n }\n\n for (const file of matchedFiles) {\n const mod = await import(pathToFileURL(file).href);\n for (const exported of Object.values(mod)) {\n if (exported === sourceType) {\n return namespace;\n }\n }\n }\n }\n }\n\n throw new Error(\n `Could not resolve namespace for type \"${sourceType.name}\". ` +\n `Ensure the type file is included in a db namespace's files pattern.`,\n );\n}\n\n/**\n * Resolve the namespace for a namespace plugin by trying each namespace.\n * Calls onNamespaceLoaded() for each and returns the first whose output contains the requested kind.\n * @param config - App config with db namespace definitions\n * @param config.db - DB namespace definitions\n * @param plugin - Plugin instance\n * @param kind - The generated type kind to look for\n * @param pluginConfig - Plugin-level configuration\n * @returns The namespace name\n */\nasync function resolveNamespaceForNamespacePlugin(\n config: { db?: Record<string, unknown> },\n plugin: Plugin,\n kind: string,\n pluginConfig: unknown,\n): Promise<{ namespace: string; output: PluginOutput }> {\n if (!config.db) {\n throw new Error(`No db configuration found in config`);\n }\n\n if (!plugin.onNamespaceLoaded) {\n throw new Error(`Plugin \"${plugin.id}\" does not have a onNamespaceLoaded() method`);\n }\n\n for (const namespace of Object.keys(config.db)) {\n const dbConfig = config.db[namespace] as DbNamespaceConfig;\n if (dbConfig.external) continue;\n\n const output = await plugin.onNamespaceLoaded({\n pluginConfig,\n namespace,\n });\n\n if (output.types?.[kind]) {\n return { namespace, output };\n }\n }\n\n throw new Error(\n `Could not resolve namespace for plugin \"${plugin.id}\" with kind \"${kind}\". ` +\n `No namespace produced a type with that kind.`,\n );\n}\n\n// ========================================\n// Process caching\n// ========================================\n\n// Cache: plugin -> cacheKey -> TypePluginOutput\nconst processCache = new WeakMap<Plugin, Map<string, TypePluginOutput>>();\n\n// Cache for namespace plugins: plugin -> cacheKey -> PluginOutput\nconst namespaceProcessCache = new WeakMap<Plugin, Map<string, PluginOutput>>();\n\n/**\n * Generate a cache key that includes pluginConfig.\n * @param baseKey - Base key for the cache\n * @param pluginConfig - Plugin configuration to include in the key\n * @returns Cache key string\n */\nfunction getCacheKey(baseKey: string, pluginConfig: unknown): string {\n if (pluginConfig === undefined) {\n return baseKey;\n }\n try {\n return `${baseKey}:${JSON.stringify(pluginConfig)}`;\n } catch {\n throw new Error(\n `pluginConfig must be JSON-serializable for caching. Received non-serializable value.`,\n );\n }\n}\n\n// ========================================\n// Main API\n// ========================================\n\n/**\n * Get a generated type from a plugin by loading the config and resolving everything automatically.\n * For type-attached plugins, calls onTypeLoaded() with the sourceType.\n * For namespace plugins, calls onNamespaceLoaded() with auto-resolved namespace.\n * Results are cached per config path, plugin, namespace, and pluginConfig to avoid redundant processing.\n * @param configPath - Path to tailor.config.ts (absolute or relative to cwd)\n * @param pluginId - The plugin's unique identifier\n * @param sourceType - The source TailorDB type (null for namespace plugins)\n * @param kind - The generated type kind (e.g., \"request\", \"step\")\n * @returns The generated TailorDB type\n */\nexport async function getGeneratedType(\n configPath: string,\n pluginId: string,\n sourceType: TailorAnyDBType | null,\n kind: string,\n): Promise<TailorAnyDBType> {\n const cache = await loadAndCacheConfig(configPath);\n\n if (!cache) {\n // Config not available (e.g., running in bundled executor on platform server).\n // Return a placeholder. The actual type is resolved at generate/apply time.\n return { name: `__placeholder_${kind}__`, fields: {} } as TailorAnyDBType;\n }\n\n const { config, configDir, plugins } = cache;\n\n const pluginEntry = plugins.get(pluginId);\n if (!pluginEntry) {\n throw new Error(\n `Plugin \"${pluginId}\" not found in config at \"${configPath}\". ` +\n `Ensure the plugin is registered via definePlugins().`,\n );\n }\n\n const { plugin, pluginConfig } = pluginEntry;\n\n if (sourceType === null) {\n return getGeneratedTypeForNamespacePlugin(config, plugin, kind, pluginConfig);\n }\n\n const namespace = await resolveNamespaceForType(config, configDir, sourceType);\n return getGeneratedTypeForTypeAttachedPlugin(plugin, sourceType, kind, pluginConfig, namespace);\n}\n\n/**\n * Get a generated type from a type-attached plugin.\n * @param plugin - The plugin instance (must have onTypeLoaded() method)\n * @param sourceType - The source TailorDB type\n * @param kind - The generated type kind\n * @param pluginConfig - Plugin-level configuration\n * @param namespace - Resolved namespace\n * @returns The generated TailorDB type\n */\nasync function getGeneratedTypeForTypeAttachedPlugin(\n plugin: Plugin,\n sourceType: TailorAnyDBType,\n kind: string,\n pluginConfig: unknown,\n namespace: string,\n): Promise<TailorAnyDBType> {\n if (!plugin.onTypeLoaded) {\n throw new Error(`Plugin \"${plugin.id}\" does not have a onTypeLoaded() method`);\n }\n\n // Check cache first\n let pluginCache = processCache.get(plugin);\n if (!pluginCache) {\n pluginCache = new Map();\n processCache.set(plugin, pluginCache);\n }\n\n const cacheKey = getCacheKey(`${sourceType.name}:ns=${namespace}`, pluginConfig);\n let output = pluginCache.get(cacheKey);\n\n if (!output) {\n const typeConfig = sourceType.plugins.find((p) => p.pluginId === plugin.id)?.config;\n output = await plugin.onTypeLoaded({\n type: sourceType,\n typeConfig: typeConfig ?? {},\n pluginConfig,\n namespace,\n });\n pluginCache.set(cacheKey, output);\n }\n\n const generatedType = output.types?.[kind];\n if (!generatedType) {\n throw new Error(\n `Generated type not found: plugin=${plugin.id}, sourceType=${sourceType.name}, kind=${kind}`,\n );\n }\n\n return generatedType as TailorAnyDBType;\n}\n\n/**\n * Get a generated type from a namespace plugin.\n * Auto-resolves the namespace by trying each one.\n * @param config - App config with db namespace definitions\n * @param config.db - DB namespace definitions\n * @param plugin - The plugin instance (must have onNamespaceLoaded() method)\n * @param kind - The generated type kind\n * @param pluginConfig - Plugin-level configuration\n * @returns The generated TailorDB type\n */\nasync function getGeneratedTypeForNamespacePlugin(\n config: { db?: Record<string, unknown> },\n plugin: Plugin,\n kind: string,\n pluginConfig: unknown,\n): Promise<TailorAnyDBType> {\n if (!plugin.onNamespaceLoaded) {\n throw new Error(`Plugin \"${plugin.id}\" does not have a onNamespaceLoaded() method`);\n }\n\n // Check cache first - try all namespaces\n let pluginCache = namespaceProcessCache.get(plugin);\n if (!pluginCache) {\n pluginCache = new Map();\n namespaceProcessCache.set(plugin, pluginCache);\n }\n\n // Try cached results first\n if (config.db) {\n for (const namespace of Object.keys(config.db)) {\n const dbConfig = config.db[namespace] as DbNamespaceConfig;\n if (dbConfig.external) continue;\n\n const cacheKey = getCacheKey(`namespace:ns=${namespace}`, pluginConfig);\n const cached = pluginCache.get(cacheKey);\n if (cached?.types?.[kind]) {\n return cached.types[kind] as TailorAnyDBType;\n }\n }\n }\n\n // Not in cache - resolve namespace and process\n const { namespace, output } = await resolveNamespaceForNamespacePlugin(\n config,\n plugin,\n kind,\n pluginConfig,\n );\n\n const cacheKey = getCacheKey(`namespace:ns=${namespace}`, pluginConfig);\n pluginCache.set(cacheKey, output);\n\n const generatedType = output.types?.[kind];\n if (!generatedType) {\n throw new Error(`Generated type not found: plugin=${plugin.id}, kind=${kind}`);\n }\n\n return generatedType as TailorAnyDBType;\n}\n\n/**\n * Clear all internal caches. For testing only.\n */\nexport function _clearCacheForTesting(): void {\n configCacheMap.clear();\n}\n"],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ import "./types.mjs";
2
+ import "../configure/services/tailordb/index.mjs";
@@ -0,0 +1,242 @@
1
+ import { PluginAttachment, TailorAnyDBField, TailorAnyDBType } from "../configure/services/tailordb/types.mjs";
2
+ import { IdProvider, OAuth2Client } from "../types/auth.generated.mjs";
3
+ import { TailorDBType, TypeSourceInfoEntry } from "../parser/service/tailordb/types.mjs";
4
+ import { Executor } from "../types/executor.generated.mjs";
5
+ import { Resolver } from "../types/resolver.generated.mjs";
6
+ //#region src/plugin/types.d.ts
7
+ /**
8
+ * A single generated file to write to disk.
9
+ */
10
+ interface GeneratedFile {
11
+ path: string;
12
+ content: string;
13
+ skipIfExists?: boolean;
14
+ executable?: boolean;
15
+ }
16
+ /**
17
+ * Result returned by generation-time hooks.
18
+ */
19
+ interface GeneratorResult {
20
+ files: GeneratedFile[];
21
+ errors?: string[];
22
+ }
23
+ /**
24
+ * Auth configuration available to generation-time hooks.
25
+ */
26
+ interface GeneratorAuthInput {
27
+ name: string;
28
+ userProfile?: {
29
+ typeName: string;
30
+ namespace: string;
31
+ usernameField: string;
32
+ };
33
+ machineUsers?: Record<string, {
34
+ attributes?: Record<string, unknown>;
35
+ }>;
36
+ oauth2Clients?: Record<string, OAuth2Client>;
37
+ idProvider?: IdProvider;
38
+ }
39
+ /**
40
+ * Namespace-level TailorDB data available to generation-time hooks.
41
+ */
42
+ interface TailorDBNamespaceData {
43
+ /** Namespace name */
44
+ namespace: string;
45
+ /** All TailorDB types in this namespace, keyed by type name */
46
+ types: Record<string, TailorDBType>;
47
+ /** Source info for each type (file path, export name, plugin info) */
48
+ sourceInfo: ReadonlyMap<string, TypeSourceInfoEntry>;
49
+ /** Plugin attachments configured on each type via .plugin() method */
50
+ pluginAttachments: ReadonlyMap<string, readonly PluginAttachment[]>;
51
+ }
52
+ /**
53
+ * Namespace-level resolver data available to generation-time hooks.
54
+ */
55
+ interface ResolverNamespaceData {
56
+ /** Namespace name */
57
+ namespace: string;
58
+ /** All resolvers in this namespace, keyed by resolver name */
59
+ resolvers: Record<string, Resolver>;
60
+ }
61
+ /**
62
+ * Context passed to plugin's onTailorDBReady hook.
63
+ * @template PluginConfig - Plugin-level configuration type
64
+ */
65
+ interface TailorDBReadyContext<PluginConfig = unknown> {
66
+ /** All TailorDB namespaces with their types and metadata */
67
+ tailordb: TailorDBNamespaceData[];
68
+ /** Auth configuration */
69
+ auth?: GeneratorAuthInput;
70
+ /** Base directory for generated files */
71
+ baseDir: string;
72
+ /** Path to tailor.config.ts */
73
+ configPath: string;
74
+ /** Plugin-level configuration passed via definePlugins() */
75
+ pluginConfig: PluginConfig;
76
+ }
77
+ /**
78
+ * Context passed to plugin's onResolverReady hook.
79
+ * @template PluginConfig - Plugin-level configuration type
80
+ */
81
+ interface ResolverReadyContext<PluginConfig = unknown> {
82
+ /** All TailorDB namespaces with their types and metadata */
83
+ tailordb: TailorDBNamespaceData[];
84
+ /** All resolver namespaces with their resolvers */
85
+ resolvers: ResolverNamespaceData[];
86
+ /** Auth configuration */
87
+ auth?: GeneratorAuthInput;
88
+ /** Base directory for generated files */
89
+ baseDir: string;
90
+ /** Path to tailor.config.ts */
91
+ configPath: string;
92
+ /** Plugin-level configuration passed via definePlugins() */
93
+ pluginConfig: PluginConfig;
94
+ }
95
+ /**
96
+ * Context passed to plugin's onExecutorReady hook.
97
+ * @template PluginConfig - Plugin-level configuration type
98
+ */
99
+ interface ExecutorReadyContext<PluginConfig = unknown> {
100
+ /** All TailorDB namespaces with their types and metadata */
101
+ tailordb: TailorDBNamespaceData[];
102
+ /** All resolver namespaces with their resolvers */
103
+ resolvers: ResolverNamespaceData[];
104
+ /** All executors, keyed by executor name */
105
+ executors: Record<string, Executor>;
106
+ /** Auth configuration */
107
+ auth?: GeneratorAuthInput;
108
+ /** Base directory for generated files */
109
+ baseDir: string;
110
+ /** Path to tailor.config.ts */
111
+ configPath: string;
112
+ /** Plugin-level configuration passed via definePlugins() */
113
+ pluginConfig: PluginConfig;
114
+ }
115
+ type TypeConfigRequired<PluginConfig = unknown> = boolean | ((pluginConfig: PluginConfig | undefined) => boolean);
116
+ /**
117
+ * Interface for plugin configuration mapping.
118
+ * Extend this interface via declaration merging to add typed plugin configs.
119
+ */
120
+ interface PluginConfigs<Fields extends string = string> {}
121
+ /**
122
+ * Context passed to plugin's process method
123
+ */
124
+ interface PluginProcessContext<TypeConfig = unknown, PluginConfig = unknown> {
125
+ type: TailorAnyDBType;
126
+ typeConfig: TypeConfig;
127
+ pluginConfig: PluginConfig;
128
+ namespace: string;
129
+ }
130
+ /**
131
+ * Context passed to plugin's onNamespaceLoaded hook.
132
+ */
133
+ interface PluginNamespaceProcessContext<PluginConfig = unknown> {
134
+ pluginConfig: PluginConfig;
135
+ namespace: string;
136
+ }
137
+ /**
138
+ * Interface representing a TailorDB type for plugin output.
139
+ */
140
+ interface TailorDBTypeForPlugin {
141
+ readonly name: string;
142
+ readonly fields: Record<string, unknown>;
143
+ }
144
+ type PluginGeneratedType = TailorDBTypeForPlugin;
145
+ type PluginGeneratedTypes = Record<string, PluginGeneratedType>;
146
+ interface PluginGeneratedResolver {
147
+ name: string;
148
+ operation: "query" | "mutation";
149
+ inputFields?: Record<string, unknown>;
150
+ outputFields: Record<string, unknown>;
151
+ body: string;
152
+ }
153
+ interface PluginRecordTriggerConfig {
154
+ kind: "tailordb";
155
+ events: ("tailordb.type_record.created" | "tailordb.type_record.updated" | "tailordb.type_record.deleted")[];
156
+ typeName: string;
157
+ }
158
+ interface PluginScheduleTriggerConfig {
159
+ kind: "schedule";
160
+ cron: string;
161
+ timezone?: string;
162
+ }
163
+ interface PluginIncomingWebhookTriggerConfig {
164
+ kind: "incomingWebhook";
165
+ }
166
+ type PluginTriggerConfig = PluginRecordTriggerConfig | PluginScheduleTriggerConfig | PluginIncomingWebhookTriggerConfig;
167
+ type PluginInjectValue = string | number | boolean | null;
168
+ type PluginInjectMap = Record<string, PluginInjectValue>;
169
+ interface PluginFunctionOperationConfig {
170
+ kind: "function";
171
+ body: string;
172
+ inject?: PluginInjectMap;
173
+ }
174
+ interface PluginGraphQLOperationConfig {
175
+ kind: "graphql";
176
+ query: string;
177
+ appName?: string;
178
+ variables?: string;
179
+ }
180
+ interface PluginWebhookOperationConfig {
181
+ kind: "webhook";
182
+ url: string;
183
+ }
184
+ interface PluginWorkflowOperationConfig {
185
+ kind: "workflow";
186
+ workflowName: string;
187
+ }
188
+ type PluginOperationConfig = PluginFunctionOperationConfig | PluginGraphQLOperationConfig | PluginWebhookOperationConfig | PluginWorkflowOperationConfig;
189
+ type PluginExecutorContextValue = TailorAnyDBType | string | number | boolean | null | undefined;
190
+ interface PluginExecutorContextBase {
191
+ sourceType: TailorAnyDBType | null;
192
+ namespace: string;
193
+ }
194
+ type PluginExecutorContext = PluginExecutorContextBase & {
195
+ [key: string]: PluginExecutorContextValue;
196
+ };
197
+ interface PluginExecutorModule {
198
+ default: unknown;
199
+ }
200
+ interface PluginGeneratedExecutorWithFile<Ctx = PluginExecutorContext> {
201
+ name: string;
202
+ resolve: () => Promise<PluginExecutorModule>;
203
+ context: Ctx;
204
+ }
205
+ interface PluginGeneratedExecutorLegacy {
206
+ name: string;
207
+ description?: string;
208
+ trigger: PluginTriggerConfig;
209
+ operation: PluginOperationConfig;
210
+ }
211
+ type PluginGeneratedExecutor = PluginGeneratedExecutorWithFile | PluginGeneratedExecutorLegacy;
212
+ interface PluginExtends {
213
+ fields?: Record<string, TailorAnyDBField>;
214
+ }
215
+ interface PluginOutput {
216
+ types?: PluginGeneratedTypes;
217
+ resolvers?: PluginGeneratedResolver[];
218
+ executors?: PluginGeneratedExecutor[];
219
+ }
220
+ interface TypePluginOutput extends PluginOutput {
221
+ extends?: PluginExtends;
222
+ }
223
+ type NamespacePluginOutput = PluginOutput;
224
+ /**
225
+ * Plugin interface that all plugins must implement.
226
+ * @template TypeConfig - Type for per-type configuration passed via .plugin() method
227
+ * @template PluginConfig - Type for plugin-level configuration passed via definePlugins()
228
+ */
229
+ interface Plugin<TypeConfig = unknown, PluginConfig = unknown> {
230
+ readonly id: string;
231
+ readonly description: string;
232
+ readonly importPath?: string;
233
+ readonly typeConfigRequired?: TypeConfigRequired<PluginConfig>;
234
+ readonly pluginConfig?: PluginConfig;
235
+ onTypeLoaded?(context: PluginProcessContext<TypeConfig, PluginConfig>): TypePluginOutput | Promise<TypePluginOutput>;
236
+ onNamespaceLoaded?(context: PluginNamespaceProcessContext<PluginConfig>): NamespacePluginOutput | Promise<NamespacePluginOutput>;
237
+ onTailorDBReady?(context: TailorDBReadyContext<PluginConfig>): GeneratorResult | Promise<GeneratorResult>;
238
+ onResolverReady?(context: ResolverReadyContext<PluginConfig>): GeneratorResult | Promise<GeneratorResult>;
239
+ onExecutorReady?(context: ExecutorReadyContext<PluginConfig>): GeneratorResult | Promise<GeneratorResult>;
240
+ }
241
+ //#endregion
242
+ export { ExecutorReadyContext, GeneratedFile, GeneratorAuthInput, GeneratorResult, NamespacePluginOutput, Plugin, type PluginAttachment, PluginConfigs, PluginExecutorContext, PluginExecutorContextBase, PluginExecutorContextValue, PluginExecutorModule, PluginExtends, PluginFunctionOperationConfig, PluginGeneratedExecutor, PluginGeneratedExecutorLegacy, PluginGeneratedExecutorWithFile, PluginGeneratedResolver, PluginGeneratedType, PluginGeneratedTypes, PluginGraphQLOperationConfig, PluginIncomingWebhookTriggerConfig, PluginInjectMap, PluginInjectValue, PluginNamespaceProcessContext, PluginOperationConfig, PluginOutput, PluginProcessContext, PluginRecordTriggerConfig, PluginScheduleTriggerConfig, PluginTriggerConfig, PluginWebhookOperationConfig, PluginWorkflowOperationConfig, ResolverNamespaceData, ResolverReadyContext, TailorDBNamespaceData, TailorDBReadyContext, TailorDBTypeForPlugin, TypeConfigRequired, TypePluginOutput };