@tailor-platform/sdk 1.76.1 → 1.78.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (301) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/dist/{application-BUfYmf0O.mjs → application-CUxVA7Fs.mjs} +378 -1679
  3. package/dist/application-CUxVA7Fs.mjs.map +1 -0
  4. package/dist/application-Dp_-ioiP.mjs +3 -0
  5. package/dist/cli/cache/bundle-cache.d.mts +2 -1
  6. package/dist/cli/cache/store.d.mts +1 -1
  7. package/dist/cli/commands/api/index.d.mts +1 -0
  8. package/dist/cli/commands/deploy/aigateway.d.mts +5 -1
  9. package/dist/cli/commands/deploy/application.d.mts +7 -1
  10. package/dist/cli/commands/deploy/apply-phases.d.mts +14 -1
  11. package/dist/cli/commands/deploy/auth.d.mts +5 -1
  12. package/dist/cli/commands/deploy/deploy.d.mts +13 -3
  13. package/dist/cli/commands/deploy/executor.d.mts +7 -1
  14. package/dist/cli/commands/deploy/function-registry.d.mts +5 -0
  15. package/dist/cli/commands/deploy/idp.d.mts +5 -1
  16. package/dist/cli/commands/deploy/resolver.d.mts +5 -1
  17. package/dist/cli/commands/deploy/secret-manager.d.mts +5 -1
  18. package/dist/cli/commands/deploy/staticwebsite.d.mts +5 -1
  19. package/dist/cli/commands/deploy/tailordb/index.d.mts +8 -1
  20. package/dist/cli/commands/deploy/types.d.mts +3 -1
  21. package/dist/cli/commands/deploy/workflow-execution-policy.d.mts +3 -1
  22. package/dist/cli/commands/deploy/workflow.d.mts +4 -1
  23. package/dist/cli/commands/executor/get.d.mts +0 -1
  24. package/dist/cli/commands/executor/jobs.d.mts +0 -1
  25. package/dist/cli/commands/executor/list.d.mts +0 -1
  26. package/dist/cli/commands/executor/transform.d.mts +1 -0
  27. package/dist/cli/commands/executor/trigger.d.mts +0 -1
  28. package/dist/cli/commands/executor/webhook.d.mts +0 -1
  29. package/dist/cli/commands/function/get.d.mts +0 -1
  30. package/dist/cli/commands/function/list.d.mts +0 -1
  31. package/dist/cli/commands/function/transform.d.mts +1 -0
  32. package/dist/cli/commands/generate/service.d.mts +5 -1
  33. package/dist/cli/commands/generate/types.d.mts +3 -1
  34. package/dist/cli/commands/machineuser/list.d.mts +0 -1
  35. package/dist/cli/commands/machineuser/token.d.mts +0 -1
  36. package/dist/cli/commands/oauth2client/get.d.mts +0 -1
  37. package/dist/cli/commands/oauth2client/list.d.mts +0 -1
  38. package/dist/cli/commands/oauth2client/transform.d.mts +1 -0
  39. package/dist/cli/commands/organization/folder/create.d.mts +0 -1
  40. package/dist/cli/commands/organization/folder/delete.d.mts +0 -1
  41. package/dist/cli/commands/organization/folder/get.d.mts +0 -1
  42. package/dist/cli/commands/organization/folder/list.d.mts +0 -1
  43. package/dist/cli/commands/organization/folder/update.d.mts +0 -1
  44. package/dist/cli/commands/organization/get.d.mts +0 -1
  45. package/dist/cli/commands/organization/list.d.mts +0 -1
  46. package/dist/cli/commands/organization/transform.d.mts +2 -0
  47. package/dist/cli/commands/organization/tree.d.mts +0 -1
  48. package/dist/cli/commands/organization/update.d.mts +0 -1
  49. package/dist/cli/commands/remove.d.mts +0 -1
  50. package/dist/cli/commands/show.d.mts +9 -4
  51. package/dist/cli/commands/tailordb/migrate/config.d.mts +0 -1
  52. package/dist/cli/commands/tailordb/migrate/diff-calculator.d.mts +0 -1
  53. package/dist/cli/commands/tailordb/migrate/generate.d.mts +0 -1
  54. package/dist/cli/commands/tailordb/migrate/snapshot.d.mts +1 -1
  55. package/dist/cli/commands/tailordb/truncate.d.mts +0 -1
  56. package/dist/cli/commands/workflow/executions.d.mts +0 -1
  57. package/dist/cli/commands/workflow/get.d.mts +2 -1
  58. package/dist/cli/commands/workflow/list.d.mts +0 -1
  59. package/dist/cli/commands/workflow/resume.d.mts +0 -1
  60. package/dist/cli/commands/workflow/start.d.mts +0 -1
  61. package/dist/cli/commands/workflow/status.d.mts +1 -0
  62. package/dist/cli/commands/workflow/transform.d.mts +1 -0
  63. package/dist/cli/commands/workflow/wait.d.mts +0 -1
  64. package/dist/cli/commands/workflow/waiter.d.mts +1 -1
  65. package/dist/cli/commands/workspace/app/health.d.mts +0 -1
  66. package/dist/cli/commands/workspace/app/list.d.mts +0 -1
  67. package/dist/cli/commands/workspace/app/transform.d.mts +2 -0
  68. package/dist/cli/commands/workspace/create.d.mts +3 -1
  69. package/dist/cli/commands/workspace/delete.d.mts +0 -1
  70. package/dist/cli/commands/workspace/get.d.mts +0 -1
  71. package/dist/cli/commands/workspace/list.d.mts +1 -1
  72. package/dist/cli/commands/workspace/restore.d.mts +0 -1
  73. package/dist/cli/commands/workspace/transform.d.mts +4 -0
  74. package/dist/cli/commands/workspace/user/invite.d.mts +0 -1
  75. package/dist/cli/commands/workspace/user/list.d.mts +0 -1
  76. package/dist/cli/commands/workspace/user/remove.d.mts +0 -1
  77. package/dist/cli/commands/workspace/user/transform.d.mts +1 -0
  78. package/dist/cli/commands/workspace/user/update.d.mts +0 -1
  79. package/dist/cli/index.d.mts +3 -1
  80. package/dist/cli/index.mjs +660 -56
  81. package/dist/cli/index.mjs.map +1 -1
  82. package/dist/cli/lib.d.mts +4 -2
  83. package/dist/cli/lib.mjs +3 -3
  84. package/dist/cli/lib.mjs.map +1 -1
  85. package/dist/cli/query/index.d.mts +0 -1
  86. package/dist/cli/services/application.d.mts +12 -1
  87. package/dist/cli/services/auth/service.d.mts +2 -0
  88. package/dist/cli/services/executor/service.d.mts +1 -1
  89. package/dist/cli/services/http-adapter/bundler.d.mts +3 -1
  90. package/dist/cli/services/http-adapter/service.d.mts +2 -1
  91. package/dist/cli/services/resolver/service.d.mts +1 -1
  92. package/dist/cli/services/tailordb/service.d.mts +3 -1
  93. package/dist/cli/services/workflow/bundler.d.mts +2 -1
  94. package/dist/cli/services/workflow/service.d.mts +1 -1
  95. package/dist/cli/shared/args.d.mts +1 -1
  96. package/dist/cli/shared/client.d.mts +1 -1
  97. package/dist/cli/shared/config-loader.d.mts +0 -1
  98. package/dist/cli/shared/context.d.mts +2 -1
  99. package/dist/cli/shared/script-executor.d.mts +0 -1
  100. package/dist/cli/shared/seed-chunker.d.mts +7 -3
  101. package/dist/cli/shared/type-generator.d.mts +0 -1
  102. package/dist/cli/shared/workspace-name.d.mts +1 -0
  103. package/dist/cli/skills.mjs +1 -1
  104. package/dist/completion/zsh-worker.zsh +18 -1
  105. package/dist/configure/config/index.d.mts +0 -1
  106. package/dist/configure/config/types.d.mts +2 -2
  107. package/dist/configure/index.d.mts +2 -1
  108. package/dist/configure/index.mjs +248 -4
  109. package/dist/configure/index.mjs.map +1 -1
  110. package/dist/configure/services/aigateway/index.d.mts +0 -1
  111. package/dist/configure/services/aigateway/types.d.mts +0 -1
  112. package/dist/configure/services/auth/index.d.mts +0 -1
  113. package/dist/configure/services/auth/types.d.mts +14 -13
  114. package/dist/configure/services/executor/executor.d.mts +0 -1
  115. package/dist/configure/services/executor/index.d.mts +1 -0
  116. package/dist/configure/services/executor/operation.d.mts +1 -2
  117. package/dist/configure/services/executor/trigger/event.d.mts +0 -1
  118. package/dist/configure/services/executor/trigger/index.d.mts +0 -1
  119. package/dist/configure/services/executor/trigger/schedule.d.mts +0 -1
  120. package/dist/configure/services/executor/trigger/webhook.d.mts +0 -1
  121. package/dist/configure/services/http-adapter/http-adapter.d.mts +1 -2
  122. package/dist/configure/services/idp/index.d.mts +1 -5
  123. package/dist/configure/services/idp/permission.d.mts +4 -5
  124. package/dist/configure/services/idp/types.d.mts +0 -1
  125. package/dist/configure/services/index.d.mts +5 -0
  126. package/dist/configure/services/resolver/resolver.d.mts +0 -1
  127. package/dist/configure/services/resolver/types.d.mts +0 -1
  128. package/dist/configure/services/secrets/index.d.mts +0 -1
  129. package/dist/configure/services/secrets/types.d.mts +0 -1
  130. package/dist/configure/services/staticwebsite/index.d.mts +0 -1
  131. package/dist/configure/services/staticwebsite/types.d.mts +0 -1
  132. package/dist/configure/services/tailordb/permission.d.mts +4 -5
  133. package/dist/configure/services/tailordb/schema.d.mts +21 -8
  134. package/dist/configure/services/tailordb/types.d.mts +4 -5
  135. package/dist/configure/services/workflow/execution-policy.d.mts +0 -1
  136. package/dist/configure/services/workflow/execution-policy.types.d.mts +0 -1
  137. package/dist/configure/services/workflow/index.d.mts +1 -0
  138. package/dist/configure/services/workflow/job.d.mts +0 -1
  139. package/dist/configure/services/workflow/wait-point.d.mts +0 -1
  140. package/dist/configure/services/workflow/workflow.d.mts +0 -1
  141. package/dist/configure/types/field-runtime.d.mts +1 -1
  142. package/dist/configure/types/field.d.mts +1 -2
  143. package/dist/configure/types/field.types.d.mts +1 -2
  144. package/dist/configure/types/type.d.mts +1 -1
  145. package/dist/configure/user.d.mts +0 -1
  146. package/dist/{crashreport-ayWANEZ6.mjs → crashreport-BNWUM6Kf.mjs} +4 -3
  147. package/dist/{crashreport-ayWANEZ6.mjs.map → crashreport-BNWUM6Kf.mjs.map} +1 -1
  148. package/dist/{crashreport-Dy4ZzSkd.mjs → crashreport-BafWvjjX.mjs} +1 -1
  149. package/dist/errors-DVFS0AZk.mjs +100 -0
  150. package/dist/errors-DVFS0AZk.mjs.map +1 -0
  151. package/dist/{globals-CcU1ONiK.mjs → globals-CvizbGLY.mjs} +2 -2
  152. package/dist/{globals-CcU1ONiK.mjs.map → globals-CvizbGLY.mjs.map} +1 -1
  153. package/dist/kysely/index.d.mts +3 -4
  154. package/dist/{logger-BEiZZ3qT.mjs → logger-BwS4ppwO.mjs} +3 -3
  155. package/dist/logger-BwS4ppwO.mjs.map +1 -0
  156. package/dist/parser/service/auth/index.d.mts +1 -1
  157. package/dist/parser/service/auth/schema.d.mts +1 -0
  158. package/dist/parser/service/http-adapter/index.d.mts +1 -1
  159. package/dist/parser/service/idp/types.d.mts +1 -0
  160. package/dist/parser/service/tailordb/types.d.mts +0 -1
  161. package/dist/plugin/builtin/enum-constants/index.d.mts +0 -1
  162. package/dist/plugin/builtin/file-utils/index.d.mts +0 -1
  163. package/dist/plugin/builtin/kysely-type/index.d.mts +0 -1
  164. package/dist/plugin/builtin/seed/index.d.mts +0 -1
  165. package/dist/plugin/builtin/seed/index.mjs +1 -1
  166. package/dist/plugin/get-generated-type.d.mts +0 -1
  167. package/dist/plugin/manager.d.mts +3 -1
  168. package/dist/plugin/types.d.mts +0 -1
  169. package/dist/plugin/with-context.d.mts +0 -1
  170. package/dist/{registry-NfSW0BRo.mjs → registry-CYBRvfaU.mjs} +4 -49
  171. package/dist/registry-CYBRvfaU.mjs.map +1 -0
  172. package/dist/runtime/aigateway.d.mts +0 -2
  173. package/dist/runtime/authconnection.d.mts +0 -2
  174. package/dist/runtime/globals.d.mts +0 -1
  175. package/dist/runtime/index.d.mts +0 -1
  176. package/dist/runtime/types.d.mts +16 -7
  177. package/dist/{runtime-_vUgjiqT.mjs → runtime-BD2vYJFT.mjs} +2382 -1167
  178. package/dist/runtime-BD2vYJFT.mjs.map +1 -0
  179. package/dist/{schema-DrVyN-LP.mjs → schema-U6DxoZ8D.mjs} +204 -3
  180. package/dist/schema-U6DxoZ8D.mjs.map +1 -0
  181. package/dist/{secret-file-VSVGy1V0.mjs → secret-file-DBqZhjFQ.mjs} +2 -27
  182. package/dist/{secret-file-VSVGy1V0.mjs.map → secret-file-DBqZhjFQ.mjs.map} +1 -1
  183. package/dist/{secretmanager-Bd45j7an.mjs → secretmanager-IY4UvinW.mjs} +42 -9
  184. package/dist/secretmanager-IY4UvinW.mjs.map +1 -0
  185. package/dist/seed/index.d.mts +3 -2
  186. package/dist/{seed-fm0LeYP2.mjs → seed-DFFigL8V.mjs} +3 -13
  187. package/dist/seed-DFFigL8V.mjs.map +1 -0
  188. package/dist/service-CghpdV-9.mjs +3 -0
  189. package/dist/{service-DBFZQloR.mjs → service-Cp0I7ZFe.mjs} +3 -3
  190. package/dist/{service-DBFZQloR.mjs.map → service-Cp0I7ZFe.mjs.map} +1 -1
  191. package/dist/{service-BCRJ-3NV.mjs → service-D12iQGcS.mjs} +2 -2
  192. package/dist/{service-BCRJ-3NV.mjs.map → service-D12iQGcS.mjs.map} +1 -1
  193. package/dist/service_pb-BoLM0X4K.mjs +167 -0
  194. package/dist/service_pb-BoLM0X4K.mjs.map +1 -0
  195. package/dist/{service_pb-B2FF59sP.mjs → service_pb-r1T7kpJc.mjs} +1 -1
  196. package/dist/tailor-proto/src/tailor/v1/aigateway_pb.d.mts +0 -1
  197. package/dist/tailor-proto/src/tailor/v1/aigateway_resource_pb.d.mts +0 -1
  198. package/dist/tailor-proto/src/tailor/v1/application_pb.d.mts +0 -1
  199. package/dist/tailor-proto/src/tailor/v1/application_resource_pb.d.mts +0 -1
  200. package/dist/tailor-proto/src/tailor/v1/auth_pb.d.mts +0 -1
  201. package/dist/tailor-proto/src/tailor/v1/auth_resource_pb.d.mts +0 -1
  202. package/dist/tailor-proto/src/tailor/v1/events_pb.d.mts +0 -1
  203. package/dist/tailor-proto/src/tailor/v1/events_resource_pb.d.mts +0 -1
  204. package/dist/tailor-proto/src/tailor/v1/executor_pb.d.mts +0 -1
  205. package/dist/tailor-proto/src/tailor/v1/executor_resource_pb.d.mts +0 -1
  206. package/dist/tailor-proto/src/tailor/v1/function_pb.d.mts +0 -1
  207. package/dist/tailor-proto/src/tailor/v1/function_registry_pb.d.mts +0 -1
  208. package/dist/tailor-proto/src/tailor/v1/function_resource_pb.d.mts +0 -1
  209. package/dist/tailor-proto/src/tailor/v1/http_adapter_resource_pb.d.mts +0 -1
  210. package/dist/tailor-proto/src/tailor/v1/idp_pb.d.mts +0 -1
  211. package/dist/tailor-proto/src/tailor/v1/idp_resource_pb.d.mts +0 -1
  212. package/dist/tailor-proto/src/tailor/v1/metadata_pb.d.mts +0 -1
  213. package/dist/tailor-proto/src/tailor/v1/metadata_resource_pb.d.mts +0 -1
  214. package/dist/tailor-proto/src/tailor/v1/meter_pb.d.mts +0 -1
  215. package/dist/tailor-proto/src/tailor/v1/pipeline_pb.d.mts +0 -1
  216. package/dist/tailor-proto/src/tailor/v1/pipeline_resource_pb.d.mts +0 -1
  217. package/dist/tailor-proto/src/tailor/v1/resource_pb.d.mts +0 -1
  218. package/dist/tailor-proto/src/tailor/v1/secret_manager_pb.d.mts +0 -1
  219. package/dist/tailor-proto/src/tailor/v1/secret_manager_resource_pb.d.mts +0 -1
  220. package/dist/tailor-proto/src/tailor/v1/service_pb.d.mts +0 -1
  221. package/dist/tailor-proto/src/tailor/v1/stateflow_pb.d.mts +0 -1
  222. package/dist/tailor-proto/src/tailor/v1/stateflow_resource_pb.d.mts +0 -1
  223. package/dist/tailor-proto/src/tailor/v1/staticwebsite_pb.d.mts +0 -1
  224. package/dist/tailor-proto/src/tailor/v1/staticwebsite_resource_pb.d.mts +0 -1
  225. package/dist/tailor-proto/src/tailor/v1/tailordb_pb.d.mts +0 -1
  226. package/dist/tailor-proto/src/tailor/v1/tailordb_resource_pb.d.mts +0 -1
  227. package/dist/tailor-proto/src/tailor/v1/telemetryrouter_pb.d.mts +0 -1
  228. package/dist/tailor-proto/src/tailor/v1/telemetryrouter_resource_pb.d.mts +0 -1
  229. package/dist/tailor-proto/src/tailor/v1/workflow_pb.d.mts +0 -1
  230. package/dist/tailor-proto/src/tailor/v1/workflow_resource_pb.d.mts +0 -1
  231. package/dist/tailor-proto/src/tailor/v1/workspace_pb.d.mts +0 -1
  232. package/dist/tailor-proto/src/tailor/v1/workspace_resource_pb.d.mts +0 -1
  233. package/dist/test-env-key-DuZycyWM.mjs +49 -0
  234. package/dist/test-env-key-DuZycyWM.mjs.map +1 -0
  235. package/dist/type-source-DH_LH20p.mjs +13 -0
  236. package/dist/type-source-DH_LH20p.mjs.map +1 -0
  237. package/dist/types/aigateway.generated.d.mts +5 -2
  238. package/dist/types/auth-connection.generated.d.mts +11 -5
  239. package/dist/types/auth.generated.d.mts +118 -85
  240. package/dist/types/executor.generated.d.mts +76 -84
  241. package/dist/types/helpers.d.mts +5 -5
  242. package/dist/types/http-adapter.generated.d.mts +11 -5
  243. package/dist/types/idp.generated.d.mts +536 -524
  244. package/dist/types/resolver.generated.d.mts +24 -10
  245. package/dist/types/staticwebsite.generated.d.mts +7 -3
  246. package/dist/types/tailordb.generated.d.mts +55 -29
  247. package/dist/types/workflow.generated.d.mts +9 -4
  248. package/dist/user-agent-DX2Jnw0-.mjs +28 -0
  249. package/dist/user-agent-DX2Jnw0-.mjs.map +1 -0
  250. package/dist/utils/test/index.d.mts +0 -1
  251. package/dist/utils/test/index.mjs +1 -1
  252. package/dist/utils/test/mock.d.mts +0 -1
  253. package/dist/vitest/environment.mjs +1 -1
  254. package/dist/vitest/index.d.mts +9 -9
  255. package/dist/vitest/index.mjs +600 -185
  256. package/dist/vitest/index.mjs.map +1 -1
  257. package/dist/vitest/mock-kysely.d.mts +0 -1
  258. package/dist/vitest/mock.d.mts +8 -8
  259. package/dist/vitest/mocks/aigateway.d.mts +16 -6
  260. package/dist/vitest/mocks/authconnection.d.mts +16 -6
  261. package/dist/vitest/mocks/file.d.mts +24 -6
  262. package/dist/vitest/mocks/iconv.d.mts +28 -4
  263. package/dist/vitest/mocks/idp.d.mts +26 -10
  264. package/dist/vitest/mocks/secretmanager.d.mts +16 -5
  265. package/dist/vitest/mocks/tailordb.d.mts +54 -10
  266. package/dist/vitest/mocks/workflow.d.mts +48 -11
  267. package/dist/vitest/setup.mjs +2 -2
  268. package/dist/{service_pb-B5w9rjPY.mjs → workspace_resource_pb-Db3fv68L.mjs} +57 -165
  269. package/dist/workspace_resource_pb-Db3fv68L.mjs.map +1 -0
  270. package/docs/cli/application.md +58 -11
  271. package/docs/cli/setup.md +1 -1
  272. package/docs/cli/workspace.md +6 -4
  273. package/docs/cli-reference.md +12 -8
  274. package/docs/runtime.md +3 -4
  275. package/docs/services/aigateway.md +2 -0
  276. package/docs/services/tailordb.md +52 -1
  277. package/docs/services/workflow.md +1 -1
  278. package/docs/testing.md +103 -89
  279. package/package.json +16 -16
  280. package/dist/application-BUfYmf0O.mjs.map +0 -1
  281. package/dist/application-DbvD5UUz.mjs +0 -3
  282. package/dist/cli/shared/trigger-context.d.mts +0 -1
  283. package/dist/errors-Dtf2WPaW.mjs +0 -42
  284. package/dist/errors-Dtf2WPaW.mjs.map +0 -1
  285. package/dist/field-runtime-9bfXBAOK.mjs +0 -183
  286. package/dist/field-runtime-9bfXBAOK.mjs.map +0 -1
  287. package/dist/job-D-PbD1P3.mjs +0 -55
  288. package/dist/job-D-PbD1P3.mjs.map +0 -1
  289. package/dist/logger-BEiZZ3qT.mjs.map +0 -1
  290. package/dist/registry-NfSW0BRo.mjs.map +0 -1
  291. package/dist/resource_pb-BRv7AMXK.mjs +0 -49
  292. package/dist/resource_pb-BRv7AMXK.mjs.map +0 -1
  293. package/dist/runtime-_vUgjiqT.mjs.map +0 -1
  294. package/dist/schema-DrVyN-LP.mjs.map +0 -1
  295. package/dist/secretmanager-Bd45j7an.mjs.map +0 -1
  296. package/dist/seed-fm0LeYP2.mjs.map +0 -1
  297. package/dist/service-CPMlIg3X.mjs +0 -3
  298. package/dist/service_pb-B5w9rjPY.mjs.map +0 -1
  299. package/dist/types-BwzB2okW.mjs +0 -199
  300. package/dist/types-BwzB2okW.mjs.map +0 -1
  301. package/dist/types-KlawuVKa.mjs +0 -4
@@ -1,7 +1,9 @@
1
- import { a as getRegisteredWorkflow, d as buildJobContext, f as clearWorkflowTestEnv, i as getRegisteredJob, m as platformSerialize, p as writeWorkflowTestEnv, t as TRIGGER_DEFAULT } from "../registry-NfSW0BRo.mjs";
1
+ import { a as getRegisteredWorkflow, i as getRegisteredJob, t as TRIGGER_DEFAULT, u as platformSerialize } from "../registry-CYBRvfaU.mjs";
2
+ import { a as writeWorkflowTestEnv, i as readWorkflowTestEnv, n as buildJobContext, r as clearWorkflowTestEnv } from "../test-env-key-DuZycyWM.mjs";
2
3
  import { t as assertDefined } from "../assert-DBxo8jPo.mjs";
3
- import { i as withDispose, n as tailorRoot, r as tailordbRoot, t as mockSecretmanager } from "../secretmanager-Bd45j7an.mjs";
4
+ import { i as withDispose, n as tailorRoot, r as tailordbRoot, t as mockSecretmanager } from "../secretmanager-IY4UvinW.mjs";
4
5
  import { builtinModules } from "node:module";
6
+ import { isEqual } from "es-toolkit";
5
7
  import { fileURLToPath } from "node:url";
6
8
  import { dirname, isAbsolute, matchesGlob, relative, resolve } from "node:path";
7
9
  import { ColumnNode, InsertQueryNode, Kysely, PostgresAdapter, PostgresIntrospector, PostgresQueryCompiler, PrimitiveValueListNode, ReferenceNode, UpdateQueryNode, ValueListNode, ValueNode, ValuesNode } from "kysely";
@@ -295,27 +297,31 @@ function createEnvironmentPlugin(options) {
295
297
  //#region src/vitest/mocks/aigateway.ts
296
298
  /**
297
299
  * Acquire a disposable mock for `tailor.aigateway`. Restored on dispose.
300
+ * @param options - Initial AI Gateway URL fixtures
298
301
  * @returns Disposable AI Gateway mock control object
299
302
  * @example
300
303
  * ```typescript
301
304
  * import { mockAigateway } from "@tailor-platform/sdk/vitest";
302
305
  *
303
306
  * test("resolves an AI Gateway URL", async () => {
304
- * using aigateway = mockAigateway();
305
- * aigateway.setUrls({ "my-aigateway": "https://my-aigateway.example.com" });
307
+ * using aigateway = mockAigateway({
308
+ * urls: { "my-aigateway": "https://my-aigateway.example.com" },
309
+ * });
310
+ * aigateway.setUrl("my-aigateway", "https://replacement.example.com");
306
311
  * // …
307
312
  * });
308
313
  * ```
309
314
  */
310
- function mockAigateway() {
315
+ function mockAigateway(options = {}) {
311
316
  const root = tailorRoot();
312
317
  const prev = root.aigateway;
313
- let urls = {};
314
- const get = vi.fn(async (name) => {
318
+ let urls = { ...options.urls };
319
+ async function defaultGet(name) {
315
320
  const url = urls[name];
316
321
  if (url === void 0) throw new Error(`No AI Gateway registered for "${name}". Acquire mockAigateway() and call setUrls(...).`);
317
322
  return { url };
318
- });
323
+ }
324
+ const get = vi.fn(defaultGet);
319
325
  root.aigateway = { get };
320
326
  return withDispose({
321
327
  /** The `get` `vi.fn`. */
@@ -323,12 +329,22 @@ function mockAigateway() {
323
329
  setUrls(value) {
324
330
  urls = value;
325
331
  },
332
+ setUrl(name, url) {
333
+ urls = {
334
+ ...urls,
335
+ [name]: url
336
+ };
337
+ },
326
338
  get calls() {
327
339
  return get.mock.calls.map(([name]) => ({ name }));
328
340
  },
341
+ clear() {
342
+ get.mockClear();
343
+ },
329
344
  reset() {
330
345
  urls = {};
331
- get.mockClear();
346
+ get.mockReset();
347
+ get.mockImplementation(defaultGet);
332
348
  }
333
349
  }, () => {
334
350
  root.aigateway = prev;
@@ -339,23 +355,30 @@ function mockAigateway() {
339
355
  //#region src/vitest/mocks/authconnection.ts
340
356
  /**
341
357
  * Acquire a disposable mock for `tailor.authconnection`. Restored on dispose.
358
+ * @param options - Initial token fixtures and fallback behavior
342
359
  * @returns Disposable AuthConnection mock control object
343
360
  * @example
344
361
  * ```typescript
345
362
  * import { mockAuthconnection } from "@tailor-platform/sdk/vitest";
346
363
  *
347
364
  * test("returns configured token", async () => {
348
- * using ac = mockAuthconnection();
349
- * ac.setTokens({ google: { access_token: "ya29.xxx" } });
365
+ * using ac = mockAuthconnection({ tokens: { google: { access_token: "ya29.xxx" } } });
366
+ * ac.setToken("google", { access_token: "replacement" });
350
367
  * // …
351
368
  * });
352
369
  * ```
353
370
  */
354
- function mockAuthconnection() {
371
+ function mockAuthconnection(options = {}) {
355
372
  const root = tailorRoot();
356
373
  const prev = root.authconnection;
357
- let tokens = {};
358
- const getConnectionToken = vi.fn(async (connectionName) => tokens[connectionName] ?? { access_token: "mock-token" });
374
+ let tokens = { ...options.tokens };
375
+ async function defaultGetConnectionToken(connectionName) {
376
+ const token = tokens[connectionName];
377
+ if (token) return token;
378
+ if (options.onUnhandled === "error") throw new Error(`No AuthConnection token configured for "${connectionName}"`);
379
+ return { access_token: "mock-token" };
380
+ }
381
+ const getConnectionToken = vi.fn(defaultGetConnectionToken);
359
382
  root.authconnection = { getConnectionToken };
360
383
  return withDispose({
361
384
  /** The `getConnectionToken` `vi.fn`. */
@@ -363,12 +386,22 @@ function mockAuthconnection() {
363
386
  setTokens(value) {
364
387
  tokens = value;
365
388
  },
389
+ setToken(connectionName, token) {
390
+ tokens = {
391
+ ...tokens,
392
+ [connectionName]: token
393
+ };
394
+ },
366
395
  get calls() {
367
396
  return getConnectionToken.mock.calls.map(([connectionName]) => ({ connectionName }));
368
397
  },
398
+ clear() {
399
+ getConnectionToken.mockClear();
400
+ },
369
401
  reset() {
370
402
  tokens = {};
371
- getConnectionToken.mockClear();
403
+ getConnectionToken.mockReset();
404
+ getConnectionToken.mockImplementation(defaultGetConnectionToken);
372
405
  }
373
406
  }, () => {
374
407
  root.authconnection = prev;
@@ -377,6 +410,16 @@ function mockAuthconnection() {
377
410
 
378
411
  //#endregion
379
412
  //#region src/vitest/mocks/file.ts
413
+ const FILE_METHODS = [
414
+ "upload",
415
+ "download",
416
+ "downloadAsBase64",
417
+ "delete",
418
+ "getMetadata",
419
+ "openDownloadStream",
420
+ "downloadStream",
421
+ "uploadStream"
422
+ ];
380
423
  const FILE_DEFAULTS = {
381
424
  upload: { metadata: {
382
425
  fileSize: 0,
@@ -400,7 +443,6 @@ const FILE_DEFAULTS = {
400
443
  lastUploadedAt: ""
401
444
  }
402
445
  },
403
- delete: void 0,
404
446
  getMetadata: {
405
447
  contentType: "",
406
448
  fileSize: 0,
@@ -413,27 +455,59 @@ const FILE_DEFAULTS = {
413
455
  sha256sum: ""
414
456
  } }
415
457
  };
458
+ function wrapFileIterator(inner, closeSource) {
459
+ let closePromise;
460
+ const closeSourceOnce = () => closePromise ??= Promise.resolve(closeSource());
461
+ const close = async () => {
462
+ try {
463
+ await inner.return?.();
464
+ } finally {
465
+ await closeSourceOnce();
466
+ }
467
+ };
468
+ const stream = {
469
+ async next() {
470
+ const result = await inner.next();
471
+ if (!result.done) assertStreamValue(result.value);
472
+ return result.done ? {
473
+ done: true,
474
+ value: void 0
475
+ } : result;
476
+ },
477
+ close,
478
+ async return(value) {
479
+ try {
480
+ return inner.return ? await inner.return(value) : {
481
+ done: true,
482
+ value
483
+ };
484
+ } finally {
485
+ await closeSourceOnce();
486
+ }
487
+ },
488
+ async throw(error) {
489
+ try {
490
+ if (inner.throw) return await inner.throw(error);
491
+ throw error;
492
+ } finally {
493
+ await closeSourceOnce();
494
+ }
495
+ },
496
+ [Symbol.asyncIterator]() {
497
+ return stream;
498
+ }
499
+ };
500
+ return stream;
501
+ }
416
502
  function toFileStream(value) {
417
- if (value !== null && typeof value === "object" && Symbol.asyncIterator in value && typeof value.close === "function") return value;
503
+ if (value !== null && typeof value === "object" && Symbol.asyncIterator in value && typeof value.close === "function") {
504
+ const source = value;
505
+ return wrapFileIterator(source[Symbol.asyncIterator](), () => source.close());
506
+ }
418
507
  if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) throw new TypeError("openDownloadStream expects an iterable of StreamValue items (e.g. [{ type: \"chunk\", data, position }, { type: \"complete\" }]); got raw bytes. Wrap the bytes in a structured chunk first.");
419
508
  if (value !== null && typeof value === "object" && (Symbol.iterator in value || Symbol.asyncIterator in value)) {
420
509
  const source = value;
421
- const inner = Symbol.asyncIterator in source ? source[Symbol.asyncIterator]() : source[Symbol.iterator]();
422
- const stream = {
423
- async next() {
424
- const r = await inner.next();
425
- if (!r.done) assertStreamValue(r.value);
426
- return r.done ? {
427
- done: true,
428
- value: void 0
429
- } : r;
430
- },
431
- async close() {},
432
- [Symbol.asyncIterator]() {
433
- return stream;
434
- }
435
- };
436
- return stream;
510
+ return wrapFileIterator(Symbol.asyncIterator in source ? source[Symbol.asyncIterator]() : source[Symbol.iterator](), () => {});
437
511
  }
438
512
  const empty = {
439
513
  async next() {
@@ -449,14 +523,15 @@ function toFileStream(value) {
449
523
  };
450
524
  return empty;
451
525
  }
452
- function assertStreamValue(v) {
453
- if (v === null || typeof v !== "object") throw new TypeError(`openDownloadStream expected a StreamValue item ({ type: "metadata" | "chunk" | "complete", ... }); got ${typeof v === "object" ? "null" : typeof v}.`);
454
- if (v instanceof ArrayBuffer || ArrayBuffer.isView(v)) throw new TypeError("openDownloadStream expected a StreamValue item, got raw bytes. Wrap the bytes in a structured chunk first (e.g. { type: \"chunk\", data, position }).");
455
- const type = v.type;
526
+ function assertStreamValue(value) {
527
+ if (value === null || typeof value !== "object") throw new TypeError(`openDownloadStream expected a StreamValue item ({ type: "metadata" | "chunk" | "complete", ... }); got ${typeof value === "object" ? "null" : typeof value}.`);
528
+ if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) throw new TypeError("openDownloadStream expected a StreamValue item, got raw bytes. Wrap the bytes in a structured chunk first (e.g. { type: \"chunk\", data, position }).");
529
+ const type = value.type;
456
530
  if (type !== "metadata" && type !== "chunk" && type !== "complete") throw new TypeError(`openDownloadStream expected a StreamValue item with type "metadata" | "chunk" | "complete"; got ${JSON.stringify(type)}.`);
457
531
  }
458
532
  /**
459
533
  * Acquire a disposable mock for `tailordb.file`. Restored on dispose.
534
+ * @param options - Controls behavior for calls without a configured result
460
535
  * @returns Disposable File mock control object
461
536
  * @example
462
537
  * ```typescript
@@ -464,77 +539,105 @@ function assertStreamValue(v) {
464
539
  *
465
540
  * test("mock file download", async () => {
466
541
  * using file = mockFile();
467
- * file.enqueueResult({ data: new Uint8Array([1, 2, 3]), metadata: { ... } });
542
+ * file.download.mockResolvedValue({ data: new Uint8Array(), metadata: { ... } });
468
543
  * // …
469
544
  * });
470
545
  * ```
471
546
  */
472
- function mockFile() {
547
+ function mockFile(options = {}) {
473
548
  const root = tailordbRoot();
474
549
  const prev = root.file;
550
+ const { onUnhandled = "fallback" } = options;
475
551
  const queue = [];
476
- let resolver = () => null;
477
552
  const calls = [];
553
+ let resolver = () => null;
478
554
  function handle(method, namespace, typeName, fieldName, recordId) {
479
- const call = {
555
+ if (queue.length > 0) return queue.shift();
556
+ const resolved = resolver(method, {
480
557
  method,
481
558
  namespace,
482
559
  typeName,
483
560
  fieldName,
484
561
  recordId
485
- };
486
- calls.push(call);
487
- if (queue.length > 0) return queue.shift();
488
- const resolved = resolver(method, call);
562
+ });
489
563
  if (resolved != null) return resolved;
564
+ if (onUnhandled === "error") throw new Error(`No File mock configured for "${method}"`);
490
565
  const fallback = FILE_DEFAULTS[method];
491
566
  return fallback === void 0 ? void 0 : structuredClone(fallback);
492
567
  }
568
+ const upload = vi.fn(async (...args) => {
569
+ const [namespace, typeName, fieldName, recordId] = args;
570
+ return handle("upload", namespace, typeName, fieldName, recordId);
571
+ });
572
+ const download = vi.fn(async (...args) => handle("download", ...args));
573
+ const downloadAsBase64 = vi.fn(async (...args) => handle("downloadAsBase64", ...args));
574
+ const deleteFile = vi.fn(async (...args) => {
575
+ handle("delete", ...args);
576
+ });
577
+ const getMetadata = vi.fn(async (...args) => handle("getMetadata", ...args));
578
+ const openDownloadStream = vi.fn(async (...args) => toFileStream(handle("openDownloadStream", ...args)));
579
+ const downloadStream = vi.fn(async (...args) => {
580
+ const resolved = handle("downloadStream", ...args);
581
+ if (resolved != null) return resolved;
582
+ return {
583
+ body: new ReadableStream({ start(controller) {
584
+ controller.close();
585
+ } }),
586
+ metadata: {
587
+ contentType: "",
588
+ fileSize: 0,
589
+ sha256sum: "",
590
+ lastUploadedAt: ""
591
+ }
592
+ };
593
+ });
594
+ const uploadStream = vi.fn(async (...args) => {
595
+ const [namespace, typeName, fieldName, recordId] = args;
596
+ return handle("uploadStream", namespace, typeName, fieldName, recordId);
597
+ });
598
+ const mocks = {
599
+ upload,
600
+ download,
601
+ downloadAsBase64,
602
+ delete: deleteFile,
603
+ getMetadata,
604
+ openDownloadStream,
605
+ downloadStream,
606
+ uploadStream
607
+ };
608
+ function track(method, operation) {
609
+ return function(...args) {
610
+ calls.push({
611
+ method,
612
+ namespace: args[0],
613
+ typeName: args[1],
614
+ fieldName: args[2],
615
+ recordId: args[3]
616
+ });
617
+ return operation.apply(this, args);
618
+ };
619
+ }
493
620
  root.file = {
494
- async upload(namespace, typeName, fieldName, recordId) {
495
- return handle("upload", namespace, typeName, fieldName, recordId);
496
- },
497
- async download(namespace, typeName, fieldName, recordId) {
498
- return handle("download", namespace, typeName, fieldName, recordId);
499
- },
500
- async downloadAsBase64(namespace, typeName, fieldName, recordId) {
501
- return handle("downloadAsBase64", namespace, typeName, fieldName, recordId);
502
- },
503
- async delete(namespace, typeName, fieldName, recordId) {
504
- handle("delete", namespace, typeName, fieldName, recordId);
505
- },
506
- async getMetadata(namespace, typeName, fieldName, recordId) {
507
- return handle("getMetadata", namespace, typeName, fieldName, recordId);
508
- },
509
- async openDownloadStream(namespace, typeName, fieldName, recordId) {
510
- return toFileStream(handle("openDownloadStream", namespace, typeName, fieldName, recordId));
511
- },
512
- async downloadStream(namespace, typeName, fieldName, recordId) {
513
- const resolved = handle("downloadStream", namespace, typeName, fieldName, recordId);
514
- if (resolved != null) return resolved;
515
- return {
516
- body: new ReadableStream({ start(c) {
517
- c.close();
518
- } }),
519
- metadata: {
520
- contentType: "",
521
- fileSize: 0,
522
- sha256sum: "",
523
- lastUploadedAt: ""
524
- }
525
- };
526
- },
527
- async uploadStream(namespace, typeName, fieldName, recordId) {
528
- return handle("uploadStream", namespace, typeName, fieldName, recordId);
529
- }
621
+ upload: track("upload", upload),
622
+ download: track("download", download),
623
+ downloadAsBase64: track("downloadAsBase64", downloadAsBase64),
624
+ delete: track("delete", deleteFile),
625
+ getMetadata: track("getMetadata", getMetadata),
626
+ openDownloadStream: track("openDownloadStream", openDownloadStream),
627
+ downloadStream: track("downloadStream", downloadStream),
628
+ uploadStream: track("uploadStream", uploadStream)
530
629
  };
630
+ function allMocks() {
631
+ return FILE_METHODS.map((method) => mocks[method]);
632
+ }
531
633
  return withDispose({
634
+ ...mocks,
532
635
  setResolver(value) {
533
636
  resolver = value;
534
637
  },
535
638
  /**
536
- * Enqueue a single result for the next `tailordb.file` call (FIFO; falls
537
- * back to `setResolver` when exhausted).
639
+ * Enqueue a single result for the next `tailordb.file` call.
640
+ * The queue is shared across all methods and namespaces.
538
641
  * @param result - Result to return from the next file call
539
642
  */
540
643
  enqueueResult(result) {
@@ -542,6 +645,7 @@ function mockFile() {
542
645
  },
543
646
  /**
544
647
  * Enqueue results for multiple subsequent `tailordb.file` calls.
648
+ * The queue is shared across all methods and namespaces.
545
649
  * @param results - Results to enqueue, one per upcoming call
546
650
  */
547
651
  enqueueResults(...results) {
@@ -550,10 +654,15 @@ function mockFile() {
550
654
  get calls() {
551
655
  return calls;
552
656
  },
657
+ clear() {
658
+ calls.length = 0;
659
+ for (const mock of allMocks()) mock.mockClear();
660
+ },
553
661
  reset() {
554
662
  queue.length = 0;
555
- resolver = () => null;
556
663
  calls.length = 0;
664
+ resolver = () => null;
665
+ for (const mock of allMocks()) mock.mockReset();
557
666
  }
558
667
  }, () => {
559
668
  root.file = prev;
@@ -572,11 +681,11 @@ function defaultIconvResult(method, args) {
572
681
  case "decode": return "";
573
682
  case "encode": return isUtf8(args[1]) ? "" : /* @__PURE__ */ new Uint8Array();
574
683
  case "encodings": return [];
575
- default: return;
576
684
  }
577
685
  }
578
686
  /**
579
687
  * Acquire a disposable mock for `tailor.iconv`. Restored on dispose.
688
+ * @param options - Fallback behavior for unconfigured operations
580
689
  * @returns Disposable Iconv mock control object
581
690
  * @example
582
691
  * ```typescript
@@ -584,27 +693,66 @@ function defaultIconvResult(method, args) {
584
693
  *
585
694
  * test("mock encoding conversion", () => {
586
695
  * using iconv = mockIconv();
587
- * iconv.setResolver((method) => (method === "decode" ? "decoded-text" : null));
696
+ * iconv.decode.mockReturnValue("decoded-text");
588
697
  * // …
589
698
  * });
590
699
  * ```
591
700
  */
592
- function mockIconv() {
701
+ function mockIconv(options = {}) {
593
702
  const root = tailorRoot();
594
703
  const prev = root.iconv;
595
704
  let resolver = null;
596
705
  const calls = [];
597
- function handle(method, args) {
598
- calls.push({
599
- method,
600
- args: [...args]
601
- });
706
+ function resolve(method, args) {
602
707
  if (resolver) {
603
708
  const result = resolver(method, args);
604
709
  if (result != null) return result;
605
710
  }
711
+ if (options.onUnhandled === "error") throw new Error(`No Iconv mock behavior configured for "${method}"`);
606
712
  return defaultIconvResult(method, args);
607
713
  }
714
+ function defaultConvert(input, fromEncoding, toEncoding) {
715
+ return resolve("convert", [
716
+ input,
717
+ fromEncoding,
718
+ toEncoding
719
+ ]);
720
+ }
721
+ function defaultConvertBuffer(input, fromEncoding, toEncoding) {
722
+ return resolve("convertBuffer", [
723
+ input,
724
+ fromEncoding,
725
+ toEncoding
726
+ ]);
727
+ }
728
+ function defaultDecode(input, encoding) {
729
+ return resolve("decode", [input, encoding]);
730
+ }
731
+ function defaultEncode(input, encoding) {
732
+ return resolve("encode", [input, encoding]);
733
+ }
734
+ function defaultEncodings() {
735
+ return resolve("encodings", []);
736
+ }
737
+ const convert = vi.fn(defaultConvert);
738
+ const convertBuffer = vi.fn(defaultConvertBuffer);
739
+ const decode = vi.fn(defaultDecode);
740
+ const encode = vi.fn(defaultEncode);
741
+ const encodings = vi.fn(defaultEncodings);
742
+ function track(method, operation) {
743
+ return function(...args) {
744
+ calls.push({
745
+ method,
746
+ args: [...args]
747
+ });
748
+ return operation.apply(this, args);
749
+ };
750
+ }
751
+ const trackedConvert = track("convert", convert);
752
+ const trackedConvertBuffer = track("convertBuffer", convertBuffer);
753
+ const trackedDecode = track("decode", decode);
754
+ const trackedEncode = track("encode", encode);
755
+ const trackedEncodings = track("encodings", encodings);
608
756
  class MockIconv {
609
757
  #fromEncoding;
610
758
  #toEncoding;
@@ -613,39 +761,56 @@ function mockIconv() {
613
761
  this.#toEncoding = toEncoding;
614
762
  }
615
763
  convert(input) {
616
- return handle("convert", [
617
- input,
618
- this.#fromEncoding,
619
- this.#toEncoding
620
- ]);
764
+ return trackedConvert.call(this, input, this.#fromEncoding, this.#toEncoding);
621
765
  }
622
766
  }
623
767
  root.iconv = {
624
- convert: (str, from, to) => handle("convert", [
625
- str,
626
- from,
627
- to
628
- ]),
629
- convertBuffer: (buf, from, to) => handle("convertBuffer", [
630
- buf,
631
- from,
632
- to
633
- ]),
634
- decode: (buf, encoding) => handle("decode", [buf, encoding]),
635
- encode: (str, encoding) => handle("encode", [str, encoding]),
636
- encodings: () => handle("encodings", []),
768
+ convert: trackedConvert,
769
+ convertBuffer: trackedConvertBuffer,
770
+ decode: trackedDecode,
771
+ encode: trackedEncode,
772
+ encodings: trackedEncodings,
637
773
  Iconv: MockIconv
638
774
  };
775
+ function clear() {
776
+ calls.length = 0;
777
+ convert.mockClear();
778
+ convertBuffer.mockClear();
779
+ decode.mockClear();
780
+ encode.mockClear();
781
+ encodings.mockClear();
782
+ }
639
783
  return withDispose({
784
+ /** The `convert` `vi.fn`. */
785
+ convert,
786
+ /** The `convertBuffer` `vi.fn`. */
787
+ convertBuffer,
788
+ /** The `decode` `vi.fn`. */
789
+ decode,
790
+ /** The `encode` `vi.fn`. */
791
+ encode,
792
+ /** The `encodings` `vi.fn`. */
793
+ encodings,
640
794
  setResolver(value) {
641
795
  resolver = value;
642
796
  },
643
797
  get calls() {
644
798
  return calls;
645
799
  },
800
+ clear,
646
801
  reset() {
647
802
  resolver = null;
648
803
  calls.length = 0;
804
+ convert.mockReset();
805
+ convert.mockImplementation(defaultConvert);
806
+ convertBuffer.mockReset();
807
+ convertBuffer.mockImplementation(defaultConvertBuffer);
808
+ decode.mockReset();
809
+ decode.mockImplementation(defaultDecode);
810
+ encode.mockReset();
811
+ encode.mockImplementation(defaultEncode);
812
+ encodings.mockReset();
813
+ encodings.mockImplementation(defaultEncodings);
649
814
  }
650
815
  }, () => {
651
816
  root.iconv = prev;
@@ -654,99 +819,131 @@ function mockIconv() {
654
819
 
655
820
  //#endregion
656
821
  //#region src/vitest/mocks/idp.ts
822
+ const IDP_METHODS = [
823
+ "users",
824
+ "user",
825
+ "userByName",
826
+ "createUser",
827
+ "updateUser",
828
+ "deleteUser",
829
+ "sendPasswordResetEmail",
830
+ "unenrollMfa"
831
+ ];
832
+ const IDP_USER_DEFAULT = {
833
+ id: "mock-id",
834
+ name: "mock-user",
835
+ disabled: false,
836
+ mfaEnrolled: false,
837
+ mfaFactorIds: []
838
+ };
657
839
  const IDP_DEFAULTS = {
658
840
  users: {
659
841
  users: [],
660
842
  nextPageToken: null,
661
843
  totalCount: 0
662
844
  },
663
- user: {
664
- id: "mock-id",
665
- name: "mock-user",
666
- disabled: false,
667
- mfaEnrolled: false,
668
- mfaFactorIds: []
669
- },
670
- userByName: {
671
- id: "mock-id",
672
- name: "mock-user",
673
- disabled: false,
674
- mfaEnrolled: false,
675
- mfaFactorIds: []
676
- },
677
- createUser: {
678
- id: "mock-id",
679
- name: "mock-user",
680
- disabled: false,
681
- mfaEnrolled: false,
682
- mfaFactorIds: []
683
- },
684
- updateUser: {
685
- id: "mock-id",
686
- name: "mock-user",
687
- disabled: false,
688
- mfaEnrolled: false,
689
- mfaFactorIds: []
690
- },
845
+ user: IDP_USER_DEFAULT,
846
+ userByName: IDP_USER_DEFAULT,
847
+ createUser: IDP_USER_DEFAULT,
848
+ updateUser: IDP_USER_DEFAULT,
691
849
  deleteUser: true,
692
850
  sendPasswordResetEmail: true,
693
851
  unenrollMfa: true
694
852
  };
695
853
  /**
696
854
  * Acquire a disposable mock for `tailor.idp`. Restored on dispose.
855
+ * @param options - Controls behavior for calls without a configured result
697
856
  * @returns Disposable IDP mock control object
698
857
  * @example
699
858
  * ```typescript
700
859
  * import { mockIdp } from "@tailor-platform/sdk/vitest";
701
860
  *
702
- * test("resolver-based", async () => {
861
+ * test("returns a user", async () => {
703
862
  * using idp = mockIdp();
704
- * idp.setResolver((method) =>
705
- * method === "user" ? { id: "u-1", name: "alice", disabled: false } : null,
706
- * );
863
+ * idp.namespace("my-idp").user.mockResolvedValue({
864
+ * id: "u-1",
865
+ * name: "alice",
866
+ * disabled: false,
867
+ * mfaEnrolled: false,
868
+ * mfaFactorIds: [],
869
+ * });
707
870
  * // …
708
871
  * });
709
872
  * ```
710
873
  */
711
- function mockIdp() {
874
+ function mockIdp(options = {}) {
712
875
  const root = tailorRoot();
713
876
  const prev = root.idp;
877
+ const { onUnhandled = "fallback" } = options;
714
878
  const queue = [];
715
- let resolver = () => null;
716
879
  const calls = [];
880
+ let resolver = () => null;
881
+ const namespaces = /* @__PURE__ */ new Map();
882
+ function compatibilityArgs(method, args) {
883
+ return method === "users" && args.length === 0 ? [void 0] : args;
884
+ }
717
885
  function handle(method, args, namespace) {
718
- calls.push({
719
- method,
720
- args,
721
- namespace
722
- });
723
886
  if (queue.length > 0) return queue.shift();
724
- const resolved = resolver(method, args, namespace);
887
+ const resolved = resolver(method, compatibilityArgs(method, args), namespace);
725
888
  if (resolved != null) return resolved;
726
- const fallback = IDP_DEFAULTS[method];
727
- return fallback === void 0 ? void 0 : structuredClone(fallback);
889
+ if (onUnhandled === "error") throw new Error(`No IdP mock configured for "${namespace}.${method}"`);
890
+ return structuredClone(IDP_DEFAULTS[method]);
728
891
  }
729
- const Client = vi.fn(function(config) {
730
- const namespace = config.namespace;
731
- this.users = async (options) => handle("users", [options], namespace);
732
- this.user = async (userId) => handle("user", [userId], namespace);
733
- this.userByName = async (name) => handle("userByName", [name], namespace);
734
- this.createUser = async (input) => handle("createUser", [input], namespace);
735
- this.updateUser = async (input) => handle("updateUser", [input], namespace);
736
- this.deleteUser = async (userId) => handle("deleteUser", [userId], namespace);
737
- this.sendPasswordResetEmail = async (input) => handle("sendPasswordResetEmail", [input], namespace);
738
- this.unenrollMfa = async (input) => handle("unenrollMfa", [input], namespace);
739
- });
892
+ function createNamespaceMocks(namespace) {
893
+ return {
894
+ users: vi.fn(async (...args) => handle("users", args, namespace)),
895
+ user: vi.fn(async (...args) => handle("user", args, namespace)),
896
+ userByName: vi.fn(async (...args) => handle("userByName", args, namespace)),
897
+ createUser: vi.fn(async (...args) => handle("createUser", args, namespace)),
898
+ updateUser: vi.fn(async (...args) => handle("updateUser", args, namespace)),
899
+ deleteUser: vi.fn(async (...args) => handle("deleteUser", args, namespace)),
900
+ sendPasswordResetEmail: vi.fn(async (...args) => handle("sendPasswordResetEmail", args, namespace)),
901
+ unenrollMfa: vi.fn(async (...args) => handle("unenrollMfa", args, namespace))
902
+ };
903
+ }
904
+ function namespace(name) {
905
+ const existing = namespaces.get(name);
906
+ if (existing) return existing;
907
+ const mocks = createNamespaceMocks(name);
908
+ namespaces.set(name, mocks);
909
+ return mocks;
910
+ }
911
+ function track(method, mock, namespaceName) {
912
+ return function(...args) {
913
+ calls.push({
914
+ method,
915
+ args: [...compatibilityArgs(method, args)],
916
+ namespace: namespaceName
917
+ });
918
+ return mock.apply(this, args);
919
+ };
920
+ }
921
+ const defaultClient = function(config) {
922
+ const mocks = namespace(config.namespace);
923
+ this.users = track("users", mocks.users, config.namespace);
924
+ this.user = track("user", mocks.user, config.namespace);
925
+ this.userByName = track("userByName", mocks.userByName, config.namespace);
926
+ this.createUser = track("createUser", mocks.createUser, config.namespace);
927
+ this.updateUser = track("updateUser", mocks.updateUser, config.namespace);
928
+ this.deleteUser = track("deleteUser", mocks.deleteUser, config.namespace);
929
+ this.sendPasswordResetEmail = track("sendPasswordResetEmail", mocks.sendPasswordResetEmail, config.namespace);
930
+ this.unenrollMfa = track("unenrollMfa", mocks.unenrollMfa, config.namespace);
931
+ };
932
+ const Client = vi.fn(defaultClient);
740
933
  root.idp = { Client };
934
+ function allMocks() {
935
+ return [...namespaces.values()].flatMap((mocks) => IDP_METHODS.map((method) => mocks[method]));
936
+ }
741
937
  return withDispose({
742
938
  /** The mock IDP `Client` constructor (`vi.fn`). */
743
939
  Client,
940
+ namespace,
744
941
  setResolver(value) {
745
942
  resolver = value;
746
943
  },
747
944
  /**
748
- * Enqueue a single result for the next IDP call (FIFO; falls back to
749
- * `setResolver` when exhausted).
945
+ * Enqueue a single result for the next IDP call.
946
+ * The queue is shared across all methods and namespaces.
750
947
  * @param result - Result to return from the next IDP call
751
948
  */
752
949
  enqueueResult(result) {
@@ -754,6 +951,7 @@ function mockIdp() {
754
951
  },
755
952
  /**
756
953
  * Enqueue results for multiple subsequent IDP calls.
954
+ * The queue is shared across all methods and namespaces.
757
955
  * @param results - Results to enqueue, one per upcoming call
758
956
  */
759
957
  enqueueResults(...results) {
@@ -762,10 +960,18 @@ function mockIdp() {
762
960
  get calls() {
763
961
  return calls;
764
962
  },
963
+ clear() {
964
+ calls.length = 0;
965
+ Client.mockClear();
966
+ for (const mock of allMocks()) mock.mockClear();
967
+ },
765
968
  reset() {
766
969
  queue.length = 0;
767
- resolver = () => null;
768
970
  calls.length = 0;
971
+ resolver = () => null;
972
+ Client.mockReset();
973
+ Client.mockImplementation(defaultClient);
974
+ for (const mock of allMocks()) mock.mockReset();
769
975
  }
770
976
  }, () => {
771
977
  root.idp = prev;
@@ -774,6 +980,15 @@ function mockIdp() {
774
980
 
775
981
  //#endregion
776
982
  //#region src/vitest/mocks/tailordb.ts
983
+ function testRegex(regex, value) {
984
+ const lastIndex = regex.lastIndex;
985
+ regex.lastIndex = 0;
986
+ try {
987
+ return regex.test(value);
988
+ } finally {
989
+ regex.lastIndex = lastIndex;
990
+ }
991
+ }
777
992
  var MockQueryResult = class {
778
993
  command;
779
994
  rowCount;
@@ -789,27 +1004,62 @@ var MockQueryResult = class {
789
1004
  * `tailordb.Client` whose `queryObject` is a shared `vi.fn()` (so query
790
1005
  * responses can be staged before the client is constructed). Restored on
791
1006
  * dispose.
1007
+ * @param options - Query fallback behavior
792
1008
  * @returns Disposable TailorDB mock control object
793
1009
  * @example
794
1010
  * ```typescript
795
1011
  * import { mockTailordb } from "@tailor-platform/sdk/vitest";
796
1012
  *
797
- * test("order-based", async () => {
1013
+ * test("query-based", async () => {
798
1014
  * using db = mockTailordb();
799
- * db.enqueueResults([], [{ age: 30 }], []); // BEGIN / SELECT / COMMIT
1015
+ * db.onQuery({ sql: /FROM users/, params: ["u-1"] }).returnsRows([{ age: 30 }]);
800
1016
  * // …
801
- * expect(db.queryObject).toHaveBeenCalledTimes(3);
1017
+ * expect(db.queryObject).toHaveBeenCalled();
802
1018
  * expect(db.Client).toHaveBeenCalledWith({ namespace: "tailordb" });
803
1019
  * });
804
1020
  * ```
805
1021
  */
806
- function mockTailordb() {
1022
+ function mockTailordb(options = {}) {
807
1023
  const root = tailordbRoot();
808
1024
  const prevClient = root.Client;
809
- const queryObject = vi.fn(async (_query, _params = []) => new MockQueryResult([]));
810
- const connect = vi.fn(async () => {});
1025
+ const rules = [];
1026
+ let queryResolver;
1027
+ function matchesQuery(matcher, query, params) {
1028
+ if (typeof matcher === "function") return matcher(query, params);
1029
+ if (typeof matcher === "string") return query === matcher;
1030
+ if (matcher instanceof RegExp) return testRegex(matcher, query);
1031
+ let sqlMatches;
1032
+ if (typeof matcher.sql === "string") sqlMatches = query === matcher.sql;
1033
+ else sqlMatches = testRegex(matcher.sql, query);
1034
+ if (!sqlMatches || matcher.params === void 0) return sqlMatches;
1035
+ if (typeof matcher.params === "function") return matcher.params(params);
1036
+ const expectedParams = matcher.params;
1037
+ return params.length === expectedParams.length && params.every((value, index) => isEqual(value, expectedParams[index]));
1038
+ }
1039
+ function queryResponse(response) {
1040
+ if (response.type === "error") throw response.error;
1041
+ return new MockQueryResult(response.rows);
1042
+ }
1043
+ async function defaultQuery(query, params = []) {
1044
+ for (let i = rules.length - 1; i >= 0; i -= 1) {
1045
+ const rule = rules[i];
1046
+ if (!rule || !matchesQuery(rule.matcher, query, params)) continue;
1047
+ const once = rule.once.shift();
1048
+ if (once) return queryResponse(once);
1049
+ if (rule.fallback) return queryResponse(rule.fallback);
1050
+ }
1051
+ if (queryResolver) return new MockQueryResult(queryResolver(query, params) ?? []);
1052
+ if (options.onUnhandled === "error") throw new Error(`No TailorDB query behavior matched: ${query}`);
1053
+ return new MockQueryResult([]);
1054
+ }
1055
+ const queryObject = vi.fn(defaultQuery);
1056
+ const defaultConnect = async () => {};
1057
+ const connect = vi.fn(defaultConnect);
811
1058
  const createdClients = [];
812
- const Client = vi.fn(function(config) {
1059
+ function enqueueRowsList(rowsList) {
1060
+ for (const rows of rowsList) queryObject.mockImplementationOnce(async () => new MockQueryResult(rows));
1061
+ }
1062
+ const defaultClient = function(config) {
813
1063
  const record = {
814
1064
  namespace: config?.namespace,
815
1065
  ended: false
@@ -829,7 +1079,8 @@ function mockTailordb() {
829
1079
  queryObject
830
1080
  };
831
1081
  };
832
- });
1082
+ };
1083
+ const Client = vi.fn(defaultClient);
833
1084
  root.Client = Client;
834
1085
  return withDispose({
835
1086
  /** The mock `tailordb.Client` constructor (`vi.fn`). */
@@ -841,7 +1092,53 @@ function mockTailordb() {
841
1092
  * @param resolver - Function that returns rows for a given query and params
842
1093
  */
843
1094
  setQueryResolver(resolver) {
844
- queryObject.mockImplementation(async (query, params = []) => new MockQueryResult(resolver(query, params) ?? []));
1095
+ queryResolver = resolver;
1096
+ queryObject.mockImplementation(defaultQuery);
1097
+ },
1098
+ /**
1099
+ * Configure responses for queries matching SQL text, parameters, or a predicate.
1100
+ * More recently registered matchers take precedence.
1101
+ * Do not combine matchers with a direct `queryObject.mockImplementation()` override.
1102
+ * @param matcher - Query matcher
1103
+ * @returns Chainable query behavior
1104
+ */
1105
+ onQuery(matcher) {
1106
+ const rule = {
1107
+ matcher,
1108
+ once: []
1109
+ };
1110
+ rules.push(rule);
1111
+ const behavior = {
1112
+ returnsRows(rows) {
1113
+ rule.fallback = {
1114
+ type: "rows",
1115
+ rows
1116
+ };
1117
+ return behavior;
1118
+ },
1119
+ returnsRowsOnce(rows) {
1120
+ rule.once.push({
1121
+ type: "rows",
1122
+ rows
1123
+ });
1124
+ return behavior;
1125
+ },
1126
+ rejects(error) {
1127
+ rule.fallback = {
1128
+ type: "error",
1129
+ error
1130
+ };
1131
+ return behavior;
1132
+ },
1133
+ rejectsOnce(error) {
1134
+ rule.once.push({
1135
+ type: "error",
1136
+ error
1137
+ });
1138
+ return behavior;
1139
+ }
1140
+ };
1141
+ return behavior;
845
1142
  },
846
1143
  /**
847
1144
  * Enqueue rows for the next `queryObject` call (FIFO; takes priority over
@@ -849,14 +1146,21 @@ function mockTailordb() {
849
1146
  * @param rows - Row objects to return from the next `queryObject` call
850
1147
  */
851
1148
  enqueueResult(...rows) {
852
- queryObject.mockImplementationOnce(async () => new MockQueryResult(rows));
1149
+ enqueueRowsList([rows]);
853
1150
  },
854
1151
  /**
855
1152
  * Enqueue rows for multiple subsequent `queryObject` calls (FIFO).
856
1153
  * @param rowsList - Rows arrays, one per upcoming query
857
1154
  */
858
1155
  enqueueResults(...rowsList) {
859
- for (const rows of rowsList) queryObject.mockImplementationOnce(async () => new MockQueryResult(rows));
1156
+ enqueueRowsList(rowsList);
1157
+ },
1158
+ /**
1159
+ * Enqueue row arrays for subsequent queries whose exact order is under test.
1160
+ * @param rowsList - Rows arrays, one per upcoming query
1161
+ */
1162
+ enqueueRows(...rowsList) {
1163
+ enqueueRowsList(rowsList);
860
1164
  },
861
1165
  /**
862
1166
  * All queries executed via `queryObject`, in order, derived from the vi.fn
@@ -876,13 +1180,24 @@ function mockTailordb() {
876
1180
  get createdClients() {
877
1181
  return createdClients;
878
1182
  },
1183
+ /** Clear recorded calls while preserving configured query behavior. */
1184
+ clear() {
1185
+ queryObject.mockClear();
1186
+ connect.mockClear();
1187
+ Client.mockClear();
1188
+ createdClients.length = 0;
1189
+ },
879
1190
  /** Reset query responses and recorded calls (keeps the mock installed). */
880
1191
  reset() {
881
1192
  queryObject.mockReset();
882
- queryObject.mockImplementation(async () => new MockQueryResult([]));
883
- connect.mockClear();
884
- Client.mockClear();
1193
+ queryObject.mockImplementation(defaultQuery);
1194
+ connect.mockReset();
1195
+ connect.mockImplementation(defaultConnect);
1196
+ Client.mockReset();
1197
+ Client.mockImplementation(defaultClient);
885
1198
  createdClients.length = 0;
1199
+ rules.length = 0;
1200
+ queryResolver = void 0;
886
1201
  }
887
1202
  }, () => {
888
1203
  root.Client = prevClient;
@@ -891,6 +1206,30 @@ function mockTailordb() {
891
1206
 
892
1207
  //#endregion
893
1208
  //#region src/vitest/mocks/workflow.ts
1209
+ const originalProcedures = /* @__PURE__ */ new WeakMap();
1210
+ function replaceProcedure(target, key, current) {
1211
+ const original = originalProcedures.get(current) ?? current;
1212
+ const defaultImplementation = function(...args) {
1213
+ return Reflect.apply(original, this, args);
1214
+ };
1215
+ const mock = vi.fn(defaultImplementation);
1216
+ originalProcedures.set(mock, original);
1217
+ const record = target;
1218
+ record[key] = mock;
1219
+ return {
1220
+ mock,
1221
+ scoped: {
1222
+ mockClear: () => mock.mockClear(),
1223
+ mockReset: () => mock.mockReset(),
1224
+ restore: () => {
1225
+ if (record[key] === mock) record[key] = current;
1226
+ }
1227
+ }
1228
+ };
1229
+ }
1230
+ function replaceTrigger(definition) {
1231
+ return replaceProcedure(definition, "trigger", definition.trigger);
1232
+ }
894
1233
  /**
895
1234
  * Acquire a disposable mock for workflow operations (`tailor.workflow`).
896
1235
  * Restored on dispose.
@@ -899,17 +1238,23 @@ function mockTailordb() {
899
1238
  * ```typescript
900
1239
  * import { mockWorkflow } from "@tailor-platform/sdk/vitest";
901
1240
  *
902
- * test("job handler", async () => {
1241
+ * test("job trigger", async () => {
903
1242
  * using wf = mockWorkflow();
904
- * wf.setJobHandler((name) => (name === "validate" ? { valid: true } : null));
905
- * await runWorkflowUnderTest(); // calls tailor.workflow.triggerJobFunction("validate", {})
906
- * expect(wf.triggerJobFunction).toHaveBeenCalledWith("validate", {});
1243
+ * const job = wf.job(validateOrder);
1244
+ * job.mockResolvedValue({ valid: true });
1245
+ * await runWorkflowUnderTest();
1246
+ * expect(job).toHaveBeenCalled();
907
1247
  * });
908
1248
  * ```
909
1249
  */
910
1250
  function mockWorkflow() {
911
1251
  const root = tailorRoot();
912
1252
  const prev = root.workflow;
1253
+ const prevEnv = readWorkflowTestEnv();
1254
+ const jobSpies = /* @__PURE__ */ new Map();
1255
+ const workflowSpies = /* @__PURE__ */ new Map();
1256
+ const waitPointMocks = /* @__PURE__ */ new Map();
1257
+ const scopedMocks = /* @__PURE__ */ new Set();
913
1258
  const defaultTriggerJob = (jobName, args, _options) => {
914
1259
  const body = getRegisteredJob(jobName);
915
1260
  return body ? body(args, buildJobContext()) : null;
@@ -953,6 +1298,64 @@ function mockWorkflow() {
953
1298
  /** The `resolve` `vi.fn`. */
954
1299
  resolve,
955
1300
  /**
1301
+ * Get a stable, typed mock for a workflow job's `trigger` method.
1302
+ * The real trigger behavior is used until an implementation or result is configured.
1303
+ * @param definition - Workflow job definition to mock
1304
+ * @returns Typed `trigger` mock for the definition
1305
+ */
1306
+ job(definition) {
1307
+ const existing = jobSpies.get(definition);
1308
+ if (existing) return existing;
1309
+ const { mock, scoped } = replaceTrigger(definition);
1310
+ scopedMocks.add(scoped);
1311
+ jobSpies.set(definition, mock);
1312
+ return mock;
1313
+ },
1314
+ /**
1315
+ * Get a stable, typed mock for a workflow definition's `trigger` method.
1316
+ * The real trigger behavior is used until an implementation or result is configured.
1317
+ * @param definition - Workflow definition to mock
1318
+ * @returns Typed `trigger` mock for the definition
1319
+ */
1320
+ workflow(definition) {
1321
+ const existing = workflowSpies.get(definition);
1322
+ if (existing) return existing;
1323
+ const { mock, scoped } = replaceTrigger(definition);
1324
+ workflowSpies.set(definition, mock);
1325
+ scopedMocks.add(scoped);
1326
+ return mock;
1327
+ },
1328
+ /**
1329
+ * Get stable, typed mocks for a wait point's `wait` and `resolve` methods.
1330
+ * @param definition - Wait point definition to mock
1331
+ * @returns Typed wait point mock control object
1332
+ */
1333
+ waitPoint(definition) {
1334
+ const existing = waitPointMocks.get(definition);
1335
+ if (existing) return existing;
1336
+ const waitReplacement = replaceProcedure(definition, "wait", definition.wait);
1337
+ const resolveReplacement = replaceProcedure(definition, "resolve", definition.resolve);
1338
+ const waitSpy = waitReplacement.mock;
1339
+ const resolveSpy = resolveReplacement.mock;
1340
+ scopedMocks.add(waitReplacement.scoped);
1341
+ scopedMocks.add(resolveReplacement.scoped);
1342
+ const waitPointMock = {
1343
+ wait: waitSpy,
1344
+ resolve: resolveSpy,
1345
+ /**
1346
+ * Invoke the next and subsequent resolve callbacks with a wait payload.
1347
+ * @param payload - Payload originally supplied to the wait point
1348
+ */
1349
+ setResolvePayload(payload) {
1350
+ resolveSpy.mockImplementation(async (_executionId, callback) => {
1351
+ platformSerialize(await callback(platformSerialize(payload)));
1352
+ });
1353
+ }
1354
+ };
1355
+ waitPointMocks.set(definition, waitPointMock);
1356
+ return waitPointMock;
1357
+ },
1358
+ /**
956
1359
  * Set a fallback job handler. Called when the enqueue queue is empty.
957
1360
  * @param handler - Function returning a result for a job name, args, and options
958
1361
  */
@@ -1047,6 +1450,15 @@ function mockWorkflow() {
1047
1450
  key
1048
1451
  }));
1049
1452
  },
1453
+ /** Clear recorded calls while preserving configured responses. */
1454
+ clear() {
1455
+ triggerJobFunction.mockClear();
1456
+ triggerWorkflow.mockClear();
1457
+ resumeWorkflow.mockClear();
1458
+ wait.mockClear();
1459
+ resolve.mockClear();
1460
+ for (const mock of scopedMocks) mock.mockClear();
1461
+ },
1050
1462
  /** Reset all workflow responses and recorded calls (keeps the mock installed). */
1051
1463
  reset() {
1052
1464
  triggerJobFunction.mockReset();
@@ -1059,11 +1471,14 @@ function mockWorkflow() {
1059
1471
  wait.mockImplementation(() => null);
1060
1472
  resolve.mockReset();
1061
1473
  resolve.mockImplementation(async () => {});
1474
+ for (const mock of scopedMocks) mock.mockReset();
1062
1475
  clearWorkflowTestEnv();
1063
1476
  }
1064
1477
  }, () => {
1478
+ for (const mock of scopedMocks) mock.restore();
1065
1479
  root.workflow = prev;
1066
- clearWorkflowTestEnv();
1480
+ if (prevEnv !== void 0) writeWorkflowTestEnv(prevEnv);
1481
+ else clearWorkflowTestEnv();
1067
1482
  });
1068
1483
  }
1069
1484