@tailor-platform/sdk 2.0.0-next.0 → 2.0.0-next.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +972 -0
- package/README.md +9 -9
- package/agent-skills/{tailor-sdk → tailor}/SKILL.md +3 -1
- package/dist/aigateway-DR4Kwuik.mjs +9 -0
- package/dist/aigateway-DR4Kwuik.mjs.map +1 -0
- package/dist/application-DArFTTJ9.mjs +3 -0
- package/dist/{application-76hhIhnJ.mjs → application-miwiXtB4.mjs} +1963 -1953
- package/dist/application-miwiXtB4.mjs.map +1 -0
- package/dist/{assert-CKfwrmCV.mjs → assert-DBxo8jPo.mjs} +1 -2
- package/dist/{assert-CKfwrmCV.mjs.map → assert-DBxo8jPo.mjs.map} +1 -1
- package/dist/authconnection-CZvi9ANm.mjs +9 -0
- package/dist/authconnection-CZvi9ANm.mjs.map +1 -0
- package/dist/{brand-DlnJ375c.mjs → brand-Eo4pLXPJ.mjs} +1 -2
- package/dist/brand-Eo4pLXPJ.mjs.map +1 -0
- package/dist/cli/cache/bundle-cache.d.mts +2 -0
- package/dist/cli/cache/store.d.mts +1 -0
- package/dist/cli/cache/types.d.mts +1 -0
- package/dist/cli/commands/api/api-call.d.mts +19 -0
- package/dist/cli/commands/api/index.d.mts +4 -0
- package/dist/cli/commands/deploy/aigateway.d.mts +5 -0
- package/dist/cli/commands/deploy/application.d.mts +7 -0
- package/dist/cli/commands/deploy/apply-phases.d.mts +14 -0
- package/dist/cli/commands/deploy/auth.d.mts +5 -0
- package/dist/cli/commands/deploy/deploy.d.mts +34 -0
- package/dist/cli/commands/deploy/executor.d.mts +7 -0
- package/dist/cli/commands/deploy/function-registry-types.d.mts +12 -0
- package/dist/cli/commands/deploy/function-registry.d.mts +7 -0
- package/dist/cli/commands/deploy/idp.d.mts +5 -0
- package/dist/cli/commands/deploy/resolver.d.mts +5 -0
- package/dist/cli/commands/deploy/secret-manager.d.mts +5 -0
- package/dist/cli/commands/deploy/staticwebsite.d.mts +5 -0
- package/dist/cli/commands/deploy/tailordb/index.d.mts +9 -0
- package/dist/cli/commands/deploy/types.d.mts +3 -0
- package/dist/cli/commands/deploy/workflow-execution-policy.d.mts +3 -0
- package/dist/cli/commands/deploy/workflow.d.mts +4 -0
- package/dist/cli/commands/executor/get.d.mts +28 -0
- package/dist/cli/commands/executor/jobs.d.mts +122 -0
- package/dist/cli/commands/executor/list.d.mts +18 -0
- package/dist/cli/commands/executor/transform.d.mts +42 -0
- package/dist/cli/commands/executor/trigger.d.mts +40 -0
- package/dist/cli/commands/executor/webhook.d.mts +21 -0
- package/dist/cli/commands/function/get.d.mts +17 -0
- package/dist/cli/commands/function/list.d.mts +21 -0
- package/dist/cli/commands/function/transform.d.mts +12 -0
- package/dist/cli/commands/generate/options.d.mts +6 -0
- package/dist/cli/commands/generate/seed/bundler.d.mts +26 -0
- package/dist/cli/commands/generate/service.d.mts +15 -0
- package/dist/cli/commands/machineuser/list.d.mts +26 -0
- package/dist/cli/commands/machineuser/token.d.mts +21 -0
- package/dist/cli/commands/oauth2client/get.d.mts +17 -0
- package/dist/cli/commands/oauth2client/list.d.mts +19 -0
- package/dist/cli/commands/oauth2client/transform.d.mts +21 -0
- package/dist/cli/commands/organization/folder/create.d.mts +17 -0
- package/dist/cli/commands/organization/folder/delete.d.mts +15 -0
- package/dist/cli/commands/organization/folder/get.d.mts +16 -0
- package/dist/cli/commands/organization/folder/list.d.mts +21 -0
- package/dist/cli/commands/organization/folder/update.d.mts +17 -0
- package/dist/cli/commands/organization/get.d.mts +15 -0
- package/dist/cli/commands/organization/list.d.mts +14 -0
- package/dist/cli/commands/organization/transform.d.mts +29 -0
- package/dist/cli/commands/organization/tree.d.mts +24 -0
- package/dist/cli/commands/organization/update.d.mts +16 -0
- package/dist/cli/commands/remove.d.mts +15 -0
- package/dist/cli/commands/show.d.mts +39 -0
- package/dist/cli/commands/staticwebsite/deploy.d.mts +19 -0
- package/dist/cli/commands/tailordb/migrate/bundler.d.mts +29 -0
- package/dist/cli/commands/tailordb/migrate/config.d.mts +18 -0
- package/dist/cli/commands/tailordb/migrate/diff-calculator.d.mts +246 -0
- package/dist/cli/commands/tailordb/migrate/generate.d.mts +16 -0
- package/dist/cli/commands/tailordb/migrate/snapshot-types.d.mts +208 -0
- package/dist/cli/commands/tailordb/migrate/snapshot.d.mts +98 -0
- package/dist/cli/commands/tailordb/migrate/types.d.mts +7 -0
- package/dist/cli/commands/tailordb/truncate.d.mts +18 -0
- package/dist/cli/commands/workflow/executions.d.mts +74 -0
- package/dist/cli/commands/workflow/get.d.mts +30 -0
- package/dist/cli/commands/workflow/list.d.mts +18 -0
- package/dist/cli/commands/workflow/resume.d.mts +22 -0
- package/dist/cli/commands/workflow/start.d.mts +60 -0
- package/dist/cli/commands/workflow/status.d.mts +6 -0
- package/dist/cli/commands/workflow/transform.d.mts +34 -0
- package/dist/cli/commands/workflow/wait.d.mts +15 -0
- package/dist/cli/commands/workflow/waiter.d.mts +23 -0
- package/dist/cli/commands/workspace/app/health.d.mts +17 -0
- package/dist/cli/commands/workspace/app/list.d.mts +21 -0
- package/dist/cli/commands/workspace/app/transform.d.mts +20 -0
- package/dist/cli/commands/workspace/create.d.mts +27 -0
- package/dist/cli/commands/workspace/delete.d.mts +14 -0
- package/dist/cli/commands/workspace/get.d.mts +16 -0
- package/dist/cli/commands/workspace/list.d.mts +17 -0
- package/dist/cli/commands/workspace/restore.d.mts +14 -0
- package/dist/cli/commands/workspace/transform.d.mts +20 -0
- package/dist/cli/commands/workspace/user/invite.d.mts +21 -0
- package/dist/cli/commands/workspace/user/list.d.mts +21 -0
- package/dist/cli/commands/workspace/user/remove.d.mts +16 -0
- package/dist/cli/commands/workspace/user/transform.d.mts +9 -0
- package/dist/cli/commands/workspace/user/update.d.mts +21 -0
- package/dist/cli/index.mjs +12 -5534
- package/dist/cli/lib.d.mts +90 -21180
- package/dist/cli/lib.mjs +157 -16
- package/dist/cli/lib.mjs.map +1 -1
- package/dist/cli/main.d.mts +23 -0
- package/dist/cli/main.mjs +6583 -0
- package/dist/cli/main.mjs.map +1 -0
- package/dist/cli/query/index.d.mts +38 -0
- package/dist/cli/services/application.d.mts +12 -0
- package/dist/cli/services/auth/service.d.mts +3 -0
- package/dist/cli/services/executor/service.d.mts +1 -0
- package/dist/cli/services/http-adapter/bundler.d.mts +3 -0
- package/dist/cli/services/http-adapter/service.d.mts +2 -0
- package/dist/cli/services/resolver/service.d.mts +1 -0
- package/dist/cli/services/tailordb/service.d.mts +3 -0
- package/dist/cli/services/workflow/bundler.d.mts +2 -0
- package/dist/cli/services/workflow/service.d.mts +1 -0
- package/dist/cli/shared/args.d.mts +13 -0
- package/dist/cli/shared/client.d.mts +1273 -0
- package/dist/cli/shared/config-loader.d.mts +25 -0
- package/dist/cli/shared/context.d.mts +29 -0
- package/dist/cli/shared/error-json.d.mts +23 -0
- package/dist/cli/shared/readonly-guard.d.mts +25 -0
- package/dist/cli/shared/script-executor.d.mts +77 -0
- package/dist/cli/shared/seed-chunker.d.mts +45 -0
- package/dist/cli/shared/seed-context.d.mts +49 -0
- package/dist/cli/shared/tailordb-namespaces.d.mts +40 -0
- package/dist/cli/shared/type-generator.d.mts +19 -0
- package/dist/cli/shared/workspace-name.d.mts +1 -0
- package/dist/cli/ts-hook.d.mts +4 -0
- package/dist/cli/ts-hook.mjs +333 -0
- package/dist/completion/zsh-worker.zsh +4223 -0
- package/dist/configure/config/index.d.mts +20 -0
- package/dist/configure/config/types.d.mts +111 -0
- package/dist/configure/index.d.mts +135 -7
- package/dist/configure/index.mjs +409 -56
- package/dist/configure/index.mjs.map +1 -1
- package/dist/configure/services/aigateway/index.d.mts +16 -0
- package/dist/configure/services/aigateway/types.d.mts +10 -0
- package/dist/configure/services/auth/index.d.mts +33 -0
- package/dist/configure/services/auth/types.d.mts +168 -0
- package/dist/configure/services/executor/executor.d.mts +70 -0
- package/dist/configure/services/executor/index.d.mts +9 -0
- package/dist/configure/services/executor/operation.d.mts +50 -0
- package/dist/configure/services/executor/trigger/event.d.mts +271 -0
- package/dist/configure/services/executor/trigger/index.d.mts +7 -0
- package/dist/configure/services/executor/trigger/schedule.d.mts +24 -0
- package/dist/configure/services/executor/trigger/webhook.d.mts +43 -0
- package/dist/configure/services/executor/types.d.mts +2 -0
- package/dist/configure/services/http-adapter/http-adapter.d.mts +124 -0
- package/dist/configure/services/http-adapter/index.d.mts +2 -0
- package/dist/configure/services/idp/index.d.mts +60 -0
- package/dist/configure/services/idp/permission.d.mts +64 -0
- package/dist/configure/services/idp/types.d.mts +23 -0
- package/dist/configure/services/index.d.mts +40 -0
- package/dist/configure/services/resolver/index.d.mts +6 -0
- package/dist/configure/services/resolver/permission.d.mts +64 -0
- package/dist/configure/services/resolver/resolver.d.mts +88 -0
- package/dist/configure/services/resolver/types.d.mts +5 -0
- package/dist/configure/services/secrets/index.d.mts +37 -0
- package/dist/configure/services/secrets/types.d.mts +10 -0
- package/dist/configure/services/staticwebsite/index.d.mts +18 -0
- package/dist/configure/services/staticwebsite/types.d.mts +10 -0
- package/dist/configure/services/tailordb/index.d.mts +4 -0
- package/dist/configure/services/tailordb/permission.d.mts +103 -0
- package/dist/configure/services/tailordb/schema.d.mts +486 -0
- package/dist/configure/services/tailordb/types.d.mts +198 -0
- package/dist/configure/services/workflow/execution-policy.d.mts +70 -0
- package/dist/configure/services/workflow/execution-policy.types.d.mts +103 -0
- package/dist/configure/services/workflow/index.d.mts +9 -0
- package/dist/configure/services/workflow/job.d.mts +83 -0
- package/dist/configure/services/workflow/types.d.mts +2 -0
- package/dist/configure/services/workflow/wait-point.d.mts +72 -0
- package/dist/configure/services/workflow/workflow.d.mts +56 -0
- package/dist/configure/types/aigateway-name.d.mts +12 -0
- package/dist/configure/types/connection-name.d.mts +12 -0
- package/dist/configure/types/field.d.mts +8 -0
- package/dist/configure/types/field.types.d.mts +70 -0
- package/dist/configure/types/idp-name.d.mts +12 -0
- package/dist/configure/types/index.d.mts +5 -0
- package/dist/configure/types/machine-user.d.mts +2 -0
- package/dist/configure/types/permission-operand.types.d.mts +20 -0
- package/dist/configure/types/type.d.mts +73 -0
- package/dist/{context-s0lxhu8_.mjs → context-DYQVYWqZ.mjs} +4 -6
- package/dist/context-DYQVYWqZ.mjs.map +1 -0
- package/dist/{crashreport-BhD0y14F.mjs → crashreport-B5LqCTfF.mjs} +25 -17
- package/dist/{crashreport-BhD0y14F.mjs.map → crashreport-B5LqCTfF.mjs.map} +1 -1
- package/dist/{crashreport-D1wKBJ8N.mjs → crashreport-eI7ty7ok.mjs} +1 -2
- package/dist/{enum-constants-C7DaWeQo.mjs → enum-constants-j9QBF0cB.mjs} +1 -2
- package/dist/enum-constants-j9QBF0cB.mjs.map +1 -0
- package/dist/{errors-EsY4XO6O.mjs → errors-D7583Zz7.mjs} +18 -3
- package/dist/errors-D7583Zz7.mjs.map +1 -0
- package/dist/{file-B58Dm-2P.mjs → file-BUcmVIH2.mjs} +12 -23
- package/dist/file-BUcmVIH2.mjs.map +1 -0
- package/dist/{file-utils-BHPxPXmn.mjs → file-utils-yEiIS4nJ.mjs} +7 -8
- package/dist/file-utils-yEiIS4nJ.mjs.map +1 -0
- package/dist/{globals-ByrCoDip.mjs → globals-DQotNuwK.mjs} +32 -6
- package/dist/globals-DQotNuwK.mjs.map +1 -0
- package/dist/iconv-QWaZh0TT.mjs +38 -0
- package/dist/iconv-QWaZh0TT.mjs.map +1 -0
- package/dist/{idp-Ch95ag8h.mjs → idp-RA_swu-h.mjs} +12 -6
- package/dist/idp-RA_swu-h.mjs.map +1 -0
- package/dist/{interceptor-DOqRkCya.mjs → interceptor-e33JtsC-.mjs} +2 -3
- package/dist/interceptor-e33JtsC-.mjs.map +1 -0
- package/dist/kysely/index.d.mts +5 -7
- package/dist/kysely/index.mjs +0 -1
- package/dist/kysely/index.mjs.map +1 -1
- package/dist/{kysely-type-D1e0Vwkd.mjs → kysely-type-DqIRgDYR.mjs} +6 -6
- package/dist/kysely-type-DqIRgDYR.mjs.map +1 -0
- package/dist/logger-BtX0suGY.mjs +48 -0
- package/dist/logger-BtX0suGY.mjs.map +1 -0
- package/dist/logger-CXQq9YIp.mjs +317 -0
- package/dist/logger-CXQq9YIp.mjs.map +1 -0
- package/dist/{multiline-Cf9ODpr1.mjs → multiline-sfHpTZZK.mjs} +1 -2
- package/dist/{multiline-Cf9ODpr1.mjs.map → multiline-sfHpTZZK.mjs.map} +1 -1
- package/dist/{package-json-DcQApfPQ.mjs → package-json-8b0O9TlX.mjs} +1 -2
- package/dist/{package-json-DcQApfPQ.mjs.map → package-json-8b0O9TlX.mjs.map} +1 -1
- package/dist/package-json-Cv2Z-TqQ.mjs +3 -0
- package/dist/parser/service/auth/index.d.mts +1 -0
- package/dist/parser/service/auth/schema.d.mts +3 -0
- package/dist/parser/service/http-adapter/index.d.mts +1 -0
- package/dist/parser/service/http-adapter/schema.d.mts +1 -0
- package/dist/parser/service/idp/types.d.mts +5 -0
- package/dist/parser/service/tailordb/type-source.d.mts +10 -0
- package/dist/parser/service/tailordb/types.d.mts +131 -0
- package/dist/platform-serialize-RoRtBS0v.mjs +46 -0
- package/dist/platform-serialize-RoRtBS0v.mjs.map +1 -0
- package/dist/plugin/builtin/enum-constants/index.d.mts +15 -1
- package/dist/plugin/builtin/enum-constants/index.mjs +1 -2
- package/dist/plugin/builtin/file-utils/index.d.mts +15 -1
- package/dist/plugin/builtin/file-utils/index.mjs +1 -2
- package/dist/plugin/builtin/kysely-type/index.d.mts +15 -1
- package/dist/plugin/builtin/kysely-type/index.mjs +1 -2
- package/dist/plugin/builtin/seed/index.d.mts +46 -2
- package/dist/plugin/builtin/seed/index.mjs +1 -2
- package/dist/plugin/builtin/seed/seed-type-processor.d.mts +19 -0
- package/dist/plugin/builtin/seed/types.d.mts +2 -0
- package/dist/plugin/get-generated-type.d.mts +16 -0
- package/dist/plugin/index.d.mts +3 -119
- package/dist/plugin/index.mjs +1 -2
- package/dist/plugin/index.mjs.map +1 -1
- package/dist/plugin/manager.d.mts +2 -0
- package/dist/plugin/types.d.mts +242 -0
- package/dist/plugin/with-context.d.mts +101 -0
- package/dist/{runtime-C7qTBDD2.mjs → register-ts-hook-BAHMwxfG.mjs} +12374 -8672
- package/dist/register-ts-hook-BAHMwxfG.mjs.map +1 -0
- package/dist/registry-BIGVUrMB.mjs +54 -0
- package/dist/registry-BIGVUrMB.mjs.map +1 -0
- package/dist/{repl-editor-CJG3sz7A.mjs → repl-editor-BCozyiNq.mjs} +7 -7
- package/dist/{repl-editor-CJG3sz7A.mjs.map → repl-editor-BCozyiNq.mjs.map} +1 -1
- package/dist/runtime/aigateway.d.mts +25 -0
- package/dist/runtime/aigateway.mjs +3 -0
- package/dist/runtime/authconnection.d.mts +21 -2
- package/dist/runtime/authconnection.mjs +2 -3
- package/dist/runtime/context.d.mts +54 -2
- package/dist/runtime/context.mjs +2 -3
- package/dist/runtime/field-parse.d.mts +10 -0
- package/dist/runtime/file.d.mts +170 -2
- package/dist/runtime/file.mjs +2 -3
- package/dist/runtime/globals.d.mts +38 -53
- package/dist/runtime/globals.mjs +0 -1
- package/dist/runtime/iconv.d.mts +73 -2
- package/dist/runtime/iconv.mjs +2 -3
- package/dist/runtime/idp.d.mts +129 -2
- package/dist/runtime/idp.mjs +2 -3
- package/dist/runtime/index.d.mts +48 -9
- package/dist/runtime/index.mjs +10 -9
- package/dist/runtime/logger.d.mts +98 -0
- package/dist/runtime/logger.mjs +3 -0
- package/dist/runtime/secretmanager.d.mts +41 -2
- package/dist/runtime/secretmanager.mjs +2 -3
- package/dist/runtime/types.d.mts +25 -0
- package/dist/runtime/workflow.d.mts +124 -2
- package/dist/runtime/workflow.mjs +2 -3
- package/dist/{schema-1msIhXwA.mjs → schema--xYWRGfe.mjs} +289 -231
- package/dist/schema--xYWRGfe.mjs.map +1 -0
- package/dist/{secret-file-CWzF8rry.mjs → secret-file-C3J4Gy8r.mjs} +2 -3
- package/dist/{secret-file-CWzF8rry.mjs.map → secret-file-C3J4Gy8r.mjs.map} +1 -1
- package/dist/secretmanager-CYlpffsz.mjs +13 -0
- package/dist/secretmanager-CYlpffsz.mjs.map +1 -0
- package/dist/secretmanager-IY4UvinW.mjs +131 -0
- package/dist/secretmanager-IY4UvinW.mjs.map +1 -0
- package/dist/seed/index.d.mts +4 -4
- package/dist/seed/index.mjs +0 -1
- package/dist/seed/index.mjs.map +1 -1
- package/dist/seed-LUVr7jHL.mjs +444 -0
- package/dist/seed-LUVr7jHL.mjs.map +1 -0
- package/dist/{service-DMohAx8a2.mjs → service-B5WynBHQ.mjs} +3 -4
- package/dist/service-B5WynBHQ.mjs.map +1 -0
- package/dist/service-BNtPsK9Q.mjs +837 -0
- package/dist/service-BNtPsK9Q.mjs.map +1 -0
- package/dist/service-D5jn05ZI.mjs +3 -0
- package/dist/service_pb-BwZRiNug.mjs +167 -0
- package/dist/service_pb-BwZRiNug.mjs.map +1 -0
- package/dist/service_pb-wRkxUta6.mjs +3 -0
- package/dist/tailor-proto/src/tailor/v1/aigateway_pb.d.mts +203 -0
- package/dist/tailor-proto/src/tailor/v1/aigateway_resource_pb.d.mts +57 -0
- package/dist/tailor-proto/src/tailor/v1/application_pb.d.mts +315 -0
- package/dist/tailor-proto/src/tailor/v1/application_resource_pb.d.mts +160 -0
- package/dist/tailor-proto/src/tailor/v1/auth_pb.d.mts +2069 -0
- package/dist/tailor-proto/src/tailor/v1/auth_resource_pb.d.mts +865 -0
- package/dist/tailor-proto/src/tailor/v1/events_pb.d.mts +111 -0
- package/dist/tailor-proto/src/tailor/v1/events_resource_pb.d.mts +68 -0
- package/dist/tailor-proto/src/tailor/v1/executor_pb.d.mts +438 -0
- package/dist/tailor-proto/src/tailor/v1/executor_resource_pb.d.mts +563 -0
- package/dist/tailor-proto/src/tailor/v1/function_pb.d.mts +144 -0
- package/dist/tailor-proto/src/tailor/v1/function_registry_pb.d.mts +450 -0
- package/dist/tailor-proto/src/tailor/v1/function_resource_pb.d.mts +191 -0
- package/dist/tailor-proto/src/tailor/v1/http_adapter_resource_pb.d.mts +49 -0
- package/dist/tailor-proto/src/tailor/v1/idp_pb.d.mts +406 -0
- package/dist/tailor-proto/src/tailor/v1/idp_resource_pb.d.mts +429 -0
- package/dist/tailor-proto/src/tailor/v1/metadata_pb.d.mts +72 -0
- package/dist/tailor-proto/src/tailor/v1/metadata_resource_pb.d.mts +16 -0
- package/dist/tailor-proto/src/tailor/v1/meter_pb.d.mts +308 -0
- package/dist/tailor-proto/src/tailor/v1/pipeline_pb.d.mts +590 -0
- package/dist/tailor-proto/src/tailor/v1/pipeline_resource_pb.d.mts +329 -0
- package/dist/tailor-proto/src/tailor/v1/resource_pb.d.mts +112 -0
- package/dist/tailor-proto/src/tailor/v1/secret_manager_pb.d.mts +345 -0
- package/dist/tailor-proto/src/tailor/v1/secret_manager_resource_pb.d.mts +53 -0
- package/dist/tailor-proto/src/tailor/v1/service_pb.d.mts +3575 -0
- package/dist/tailor-proto/src/tailor/v1/stateflow_pb.d.mts +186 -0
- package/dist/tailor-proto/src/tailor/v1/stateflow_resource_pb.d.mts +28 -0
- package/dist/tailor-proto/src/tailor/v1/staticwebsite_pb.d.mts +428 -0
- package/dist/tailor-proto/src/tailor/v1/staticwebsite_resource_pb.d.mts +89 -0
- package/dist/tailor-proto/src/tailor/v1/tailordb_pb.d.mts +683 -0
- package/dist/tailor-proto/src/tailor/v1/tailordb_resource_pb.d.mts +796 -0
- package/dist/tailor-proto/src/tailor/v1/telemetryrouter_pb.d.mts +329 -0
- package/dist/tailor-proto/src/tailor/v1/telemetryrouter_resource_pb.d.mts +182 -0
- package/dist/tailor-proto/src/tailor/v1/workflow_pb.d.mts +861 -0
- package/dist/tailor-proto/src/tailor/v1/workflow_resource_pb.d.mts +309 -0
- package/dist/tailor-proto/src/tailor/v1/workspace_pb.d.mts +2014 -0
- package/dist/tailor-proto/src/tailor/v1/workspace_resource_pb.d.mts +482 -0
- package/dist/{telemetry-BQbbVo2t.mjs → telemetry-BRVdwh14.mjs} +4 -5
- package/dist/telemetry-BRVdwh14.mjs.map +1 -0
- package/dist/telemetry-CkbkeJxl.mjs +3 -0
- package/dist/test-env-key-D7UkZp99.mjs +75 -0
- package/dist/test-env-key-D7UkZp99.mjs.map +1 -0
- package/dist/type-source-DH_LH20p.mjs +13 -0
- package/dist/type-source-DH_LH20p.mjs.map +1 -0
- package/dist/types/aigateway.generated.d.mts +12 -0
- package/dist/types/app-config.generated.d.mts +4 -0
- package/dist/types/auth-connection.generated.d.mts +33 -0
- package/dist/types/auth.generated.d.mts +188 -0
- package/dist/types/executor.generated.d.mts +209 -0
- package/dist/types/helpers.d.mts +40 -0
- package/dist/types/http-adapter.generated.d.mts +28 -0
- package/dist/types/idp.generated.d.mts +626 -0
- package/dist/types/resolver.generated.d.mts +82 -0
- package/dist/types/secrets.generated.d.mts +14 -0
- package/dist/types/staticwebsite.generated.d.mts +14 -0
- package/dist/types/tailordb.generated.d.mts +468 -0
- package/dist/types/workflow.generated.d.mts +17 -0
- package/dist/user-agent-Bgsszb5I.mjs +28 -0
- package/dist/user-agent-Bgsszb5I.mjs.map +1 -0
- package/dist/utils/test/index.d.mts +6 -99
- package/dist/utils/test/index.mjs +60 -40
- package/dist/utils/test/index.mjs.map +1 -1
- package/dist/utils/test/mock.d.mts +86 -0
- package/dist/vitest/environment.d.mts +1 -2
- package/dist/vitest/environment.mjs +2 -3
- package/dist/vitest/environment.mjs.map +1 -1
- package/dist/vitest/index.d.mts +15 -392
- package/dist/vitest/index.mjs +1347 -9
- package/dist/vitest/index.mjs.map +1 -1
- package/dist/vitest/mock-kysely.d.mts +61 -0
- package/dist/vitest/mock.d.mts +10 -0
- package/dist/vitest/mocks/aigateway.d.mts +40 -0
- package/dist/vitest/mocks/authconnection.d.mts +38 -0
- package/dist/vitest/mocks/file.d.mts +58 -0
- package/dist/vitest/mocks/iconv.d.mts +51 -0
- package/dist/vitest/mocks/idp.d.mts +60 -0
- package/dist/vitest/mocks/logger.d.mts +45 -0
- package/dist/vitest/mocks/secretmanager.d.mts +44 -0
- package/dist/vitest/mocks/tailordb.d.mts +115 -0
- package/dist/vitest/mocks/workflow.d.mts +157 -0
- package/dist/vitest/setup.d.mts +1 -2
- package/dist/vitest/setup.mjs +2 -3
- package/dist/vitest/setup.mjs.map +1 -1
- package/dist/vitest/workflow-local.d.mts +41 -0
- package/dist/workflow-CsaQ9qK-.mjs +42 -0
- package/dist/workflow-CsaQ9qK-.mjs.map +1 -0
- package/dist/{client-CobIRHl-.mjs → workspace_resource_pb-UGK1SSn_.mjs} +55 -616
- package/dist/workspace_resource_pb-UGK1SSn_.mjs.map +1 -0
- package/docs/cli/application.md +150 -252
- package/docs/cli/auth.md +51 -295
- package/docs/cli/completion.md +4 -25
- package/docs/cli/crashreport.md +3 -63
- package/docs/cli/executor.md +72 -183
- package/docs/cli/function.md +17 -133
- package/docs/cli/organization.md +11 -221
- package/docs/cli/plugin.md +29 -0
- package/docs/cli/query.md +2 -22
- package/docs/cli/secret.md +71 -251
- package/docs/cli/setup.md +138 -40
- package/docs/cli/skills.md +50 -39
- package/docs/cli/staticwebsite.md +32 -180
- package/docs/cli/tailordb.md +71 -427
- package/docs/cli/upgrade.md +2 -22
- package/docs/cli/user.md +78 -247
- package/docs/cli/workflow.md +150 -172
- package/docs/cli/workspace.md +167 -538
- package/docs/cli-reference.md +213 -96
- package/docs/configuration.md +40 -8
- package/docs/github-actions.md +72 -24
- package/docs/migration/v2.md +1316 -0
- package/docs/multi-environment.md +29 -7
- package/docs/plugin/custom.md +6 -6
- package/docs/plugin/index.md +9 -9
- package/docs/quickstart.md +8 -7
- package/docs/runtime.md +21 -12
- package/docs/services/aigateway.md +115 -0
- package/docs/services/auth.md +70 -61
- package/docs/services/executor.md +8 -5
- package/docs/services/http-adapter.md +16 -1
- package/docs/services/idp.md +55 -2
- package/docs/services/resolver.md +63 -11
- package/docs/services/secret.md +11 -11
- package/docs/services/staticwebsite.md +8 -2
- package/docs/services/tailordb-migration.md +43 -28
- package/docs/services/tailordb.md +200 -99
- package/docs/services/workflow.md +135 -59
- package/docs/testing.md +253 -145
- package/package.json +61 -47
- package/postinstall.mjs +4 -6
- package/dist/actor-J2gJ0eK5.d.mts +0 -24
- package/dist/application-76hhIhnJ.mjs.map +0 -1
- package/dist/application-av2raLs6.mjs +0 -4
- package/dist/authconnection-BIYzEh2p.d.mts +0 -39
- package/dist/authconnection-D8SJGMpj.mjs +0 -16
- package/dist/authconnection-D8SJGMpj.mjs.map +0 -1
- package/dist/brand-DlnJ375c.mjs.map +0 -1
- package/dist/chunk-BkoGK1jX.mjs +0 -21
- package/dist/cli/erd-viewer-assets/app.js +0 -1181
- package/dist/cli/erd-viewer-assets/index.html +0 -73
- package/dist/cli/erd-viewer-assets/serve.json +0 -13
- package/dist/cli/erd-viewer-assets/styles.css +0 -789
- package/dist/cli/index.d.mts +0 -5
- package/dist/cli/index.mjs.map +0 -1
- package/dist/cli/skills.d.mts +0 -1
- package/dist/cli/skills.mjs +0 -22
- package/dist/cli/skills.mjs.map +0 -1
- package/dist/client-C68VWo4g.mjs +0 -4
- package/dist/client-CobIRHl-.mjs.map +0 -1
- package/dist/context-CUBwSBq4.d.mts +0 -68
- package/dist/context-s0lxhu8_.mjs.map +0 -1
- package/dist/enum-constants-C7DaWeQo.mjs.map +0 -1
- package/dist/env-B-g-qgE4.d.mts +0 -7
- package/dist/errors-EsY4XO6O.mjs.map +0 -1
- package/dist/field-C4zdJLW5.mjs +0 -23
- package/dist/field-C4zdJLW5.mjs.map +0 -1
- package/dist/file-B58Dm-2P.mjs.map +0 -1
- package/dist/file-BzK8z3X-.d.mts +0 -250
- package/dist/file-utils-BHPxPXmn.mjs.map +0 -1
- package/dist/globals-ByrCoDip.mjs.map +0 -1
- package/dist/iconv-DreIffeM.mjs +0 -64
- package/dist/iconv-DreIffeM.mjs.map +0 -1
- package/dist/iconv-kwrmd1U_.d.mts +0 -122
- package/dist/idp-BlBPtXJ-.d.mts +0 -160
- package/dist/idp-Ch95ag8h.mjs.map +0 -1
- package/dist/index-CLxubakC.d.mts +0 -1225
- package/dist/index-CPRnOjjt.d.mts +0 -18
- package/dist/index-CQZVJ5SX.d.mts +0 -18
- package/dist/index-CfRFkXIO.d.mts +0 -47
- package/dist/index-DRhMpdnA.d.mts +0 -46
- package/dist/index-DUupuPhZ.d.mts +0 -18
- package/dist/interceptor-DOqRkCya.mjs.map +0 -1
- package/dist/job-BpsFXPbi.mjs +0 -54
- package/dist/job-BpsFXPbi.mjs.map +0 -1
- package/dist/kysely-type-D1e0Vwkd.mjs.map +0 -1
- package/dist/logger-DpJyJvNz.mjs +0 -221
- package/dist/logger-DpJyJvNz.mjs.map +0 -1
- package/dist/mock-DMgIygjE.mjs +0 -806
- package/dist/mock-DMgIygjE.mjs.map +0 -1
- package/dist/package-json-wzO6nV9O.mjs +0 -4
- package/dist/plugin-C_FyVSdl.d.mts +0 -634
- package/dist/registry-D0uB0OrK.mjs +0 -178
- package/dist/registry-D0uB0OrK.mjs.map +0 -1
- package/dist/runtime-C7qTBDD2.mjs.map +0 -1
- package/dist/schema-1msIhXwA.mjs.map +0 -1
- package/dist/secretmanager-B9h-U_8U.mjs +0 -25
- package/dist/secretmanager-B9h-U_8U.mjs.map +0 -1
- package/dist/secretmanager-CKLB3wAQ.d.mts +0 -55
- package/dist/seed-BH2FbrPV.mjs +0 -1171
- package/dist/seed-BH2FbrPV.mjs.map +0 -1
- package/dist/service-BHQIerYh.mjs +0 -4
- package/dist/service-DMohAx8a2.mjs.map +0 -1
- package/dist/service-wI3Hvrgx.mjs +0 -460
- package/dist/service-wI3Hvrgx.mjs.map +0 -1
- package/dist/tailordb-BlBGmQK-.d.mts +0 -863
- package/dist/telemetry-BQbbVo2t.mjs.map +0 -1
- package/dist/telemetry-w92bvGdC.mjs +0 -4
- package/dist/types-2Be3wSMc.mjs +0 -5
- package/dist/types-CmzfQP_m.mjs +0 -372
- package/dist/types-CmzfQP_m.mjs.map +0 -1
- package/dist/workflow--aPbA8Uq.mjs +0 -39
- package/dist/workflow--aPbA8Uq.mjs.map +0 -1
- package/dist/workflow-CMamswkK.d.mts +0 -96
- package/dist/workflow.generated-Bf1tWylx.d.mts +0 -1416
- package/docs/generator/builtin.md +0 -257
- package/docs/generator/custom.md +0 -147
- package/docs/generator/index.md +0 -66
package/dist/vitest/index.mjs
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import { t as
|
|
3
|
-
import {
|
|
1
|
+
import { i as getRegisteredJob, t as START_DEFAULT } from "../registry-BIGVUrMB.mjs";
|
|
2
|
+
import { a as writeWorkflowTestEnv, n as clearWorkflowTestEnv, r as readWorkflowTestEnv, t as buildJobContext } from "../test-env-key-D7UkZp99.mjs";
|
|
3
|
+
import { t as assertDefined } from "../assert-DBxo8jPo.mjs";
|
|
4
|
+
import { t as platformSerialize } from "../platform-serialize-RoRtBS0v.mjs";
|
|
5
|
+
import { i as withDispose, n as tailorRoot, r as tailordbRoot, t as mockSecretmanager } from "../secretmanager-IY4UvinW.mjs";
|
|
4
6
|
import { builtinModules } from "node:module";
|
|
7
|
+
import { isEqual } from "es-toolkit";
|
|
5
8
|
import { fileURLToPath } from "node:url";
|
|
6
9
|
import { dirname, isAbsolute, matchesGlob, relative, resolve } from "node:path";
|
|
7
10
|
import { ColumnNode, InsertQueryNode, Kysely, PostgresAdapter, PostgresIntrospector, PostgresQueryCompiler, PrimitiveValueListNode, ReferenceNode, UpdateQueryNode, ValueListNode, ValueNode, ValuesNode } from "kysely";
|
|
11
|
+
import { vi } from "vitest";
|
|
8
12
|
|
|
9
13
|
//#region src/vitest/blocked-modules.ts
|
|
10
14
|
/**
|
|
@@ -50,7 +54,8 @@ function isBlockedModule(specifier) {
|
|
|
50
54
|
* @returns Error message with optional suggestion for the Web Standard API alternative
|
|
51
55
|
*/
|
|
52
56
|
function getBlockedMessage(specifier) {
|
|
53
|
-
const
|
|
57
|
+
const bare = specifier.startsWith("node:") ? specifier.slice(5) : specifier;
|
|
58
|
+
const suggestion = SUGGESTIONS[bare];
|
|
54
59
|
const base = `"${specifier}" is not available in the Tailor Platform runtime.`;
|
|
55
60
|
return suggestion ? `${base} ${suggestion}` : base;
|
|
56
61
|
}
|
|
@@ -58,12 +63,12 @@ function getBlockedMessage(specifier) {
|
|
|
58
63
|
//#endregion
|
|
59
64
|
//#region src/vitest/plugin.ts
|
|
60
65
|
const DEFAULT_TEST_INCLUDE = ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"];
|
|
61
|
-
const IMPORT_LIKE_TYPES = new Set([
|
|
66
|
+
const IMPORT_LIKE_TYPES = /* @__PURE__ */ new Set([
|
|
62
67
|
"ImportDeclaration",
|
|
63
68
|
"ExportNamedDeclaration",
|
|
64
69
|
"ExportAllDeclaration"
|
|
65
70
|
]);
|
|
66
|
-
const UNSAFE_BINDING_NAMES = new Set([
|
|
71
|
+
const UNSAFE_BINDING_NAMES = /* @__PURE__ */ new Set([
|
|
67
72
|
"break",
|
|
68
73
|
"case",
|
|
69
74
|
"catch",
|
|
@@ -183,7 +188,7 @@ function createBlockPlugin() {
|
|
|
183
188
|
const testConfig = config.test;
|
|
184
189
|
const root = testConfig?.root ?? config.root;
|
|
185
190
|
const toAbsolutePaths = (value, baseRoot) => (Array.isArray(value) ? value : value ? [value] : []).map((f) => resolve(baseRoot, f));
|
|
186
|
-
const exemptHostFiles = new Set([...toAbsolutePaths(testConfig?.setupFiles, root), ...toAbsolutePaths(testConfig?.globalSetup, root)]);
|
|
191
|
+
const exemptHostFiles = /* @__PURE__ */ new Set([...toAbsolutePaths(testConfig?.setupFiles, root), ...toAbsolutePaths(testConfig?.globalSetup, root)]);
|
|
187
192
|
const includePairs = [{
|
|
188
193
|
root,
|
|
189
194
|
patterns: testConfig?.include ?? DEFAULT_TEST_INCLUDE
|
|
@@ -289,6 +294,1338 @@ function createEnvironmentPlugin(options) {
|
|
|
289
294
|
};
|
|
290
295
|
}
|
|
291
296
|
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region src/vitest/mocks/aigateway.ts
|
|
299
|
+
/**
|
|
300
|
+
* Acquire a disposable mock for `tailor.aigateway`. Restored on dispose.
|
|
301
|
+
* @param options - Initial AI Gateway URL fixtures
|
|
302
|
+
* @returns Disposable AI Gateway mock control object
|
|
303
|
+
* @example
|
|
304
|
+
* ```typescript
|
|
305
|
+
* import { mockAigateway } from "@tailor-platform/sdk/vitest";
|
|
306
|
+
*
|
|
307
|
+
* test("resolves an AI Gateway URL", async () => {
|
|
308
|
+
* using aigateway = mockAigateway({
|
|
309
|
+
* urls: { "my-aigateway": "https://my-aigateway.example.com" },
|
|
310
|
+
* });
|
|
311
|
+
* aigateway.setUrl("my-aigateway", "https://replacement.example.com");
|
|
312
|
+
* // …
|
|
313
|
+
* });
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
function mockAigateway(options = {}) {
|
|
317
|
+
const root = tailorRoot();
|
|
318
|
+
const prev = root.aigateway;
|
|
319
|
+
let urls = { ...options.urls };
|
|
320
|
+
async function defaultGet(name) {
|
|
321
|
+
const url = urls[name];
|
|
322
|
+
if (url === void 0) throw new Error(`No AI Gateway registered for "${name}". Acquire mockAigateway() and call setUrls(...).`);
|
|
323
|
+
return { url };
|
|
324
|
+
}
|
|
325
|
+
const get = vi.fn(defaultGet);
|
|
326
|
+
root.aigateway = { get };
|
|
327
|
+
return withDispose({
|
|
328
|
+
/** The `get` `vi.fn`. */
|
|
329
|
+
get,
|
|
330
|
+
setUrls(value) {
|
|
331
|
+
urls = value;
|
|
332
|
+
},
|
|
333
|
+
setUrl(name, url) {
|
|
334
|
+
urls = {
|
|
335
|
+
...urls,
|
|
336
|
+
[name]: url
|
|
337
|
+
};
|
|
338
|
+
},
|
|
339
|
+
get calls() {
|
|
340
|
+
return get.mock.calls.map(([name]) => ({ name }));
|
|
341
|
+
},
|
|
342
|
+
clear() {
|
|
343
|
+
get.mockClear();
|
|
344
|
+
},
|
|
345
|
+
reset() {
|
|
346
|
+
urls = {};
|
|
347
|
+
get.mockReset();
|
|
348
|
+
get.mockImplementation(defaultGet);
|
|
349
|
+
}
|
|
350
|
+
}, () => {
|
|
351
|
+
root.aigateway = prev;
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
//#endregion
|
|
356
|
+
//#region src/vitest/mocks/authconnection.ts
|
|
357
|
+
/**
|
|
358
|
+
* Acquire a disposable mock for `tailor.authconnection`. Restored on dispose.
|
|
359
|
+
* @param options - Initial token fixtures and fallback behavior
|
|
360
|
+
* @returns Disposable AuthConnection mock control object
|
|
361
|
+
* @example
|
|
362
|
+
* ```typescript
|
|
363
|
+
* import { mockAuthconnection } from "@tailor-platform/sdk/vitest";
|
|
364
|
+
*
|
|
365
|
+
* test("returns configured token", async () => {
|
|
366
|
+
* using ac = mockAuthconnection({ tokens: { google: { access_token: "ya29.xxx" } } });
|
|
367
|
+
* ac.setToken("google", { access_token: "replacement" });
|
|
368
|
+
* // …
|
|
369
|
+
* });
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
function mockAuthconnection(options = {}) {
|
|
373
|
+
const root = tailorRoot();
|
|
374
|
+
const prev = root.authconnection;
|
|
375
|
+
let tokens = { ...options.tokens };
|
|
376
|
+
async function defaultGetConnectionToken(connectionName) {
|
|
377
|
+
const token = tokens[connectionName];
|
|
378
|
+
if (token) return token;
|
|
379
|
+
if (options.onUnhandled === "error") throw new Error(`No AuthConnection token configured for "${connectionName}"`);
|
|
380
|
+
return { access_token: "mock-token" };
|
|
381
|
+
}
|
|
382
|
+
const getConnectionToken = vi.fn(defaultGetConnectionToken);
|
|
383
|
+
root.authconnection = { getConnectionToken };
|
|
384
|
+
return withDispose({
|
|
385
|
+
/** The `getConnectionToken` `vi.fn`. */
|
|
386
|
+
getConnectionToken,
|
|
387
|
+
setTokens(value) {
|
|
388
|
+
tokens = value;
|
|
389
|
+
},
|
|
390
|
+
setToken(connectionName, token) {
|
|
391
|
+
tokens = {
|
|
392
|
+
...tokens,
|
|
393
|
+
[connectionName]: token
|
|
394
|
+
};
|
|
395
|
+
},
|
|
396
|
+
get calls() {
|
|
397
|
+
return getConnectionToken.mock.calls.map(([connectionName]) => ({ connectionName }));
|
|
398
|
+
},
|
|
399
|
+
clear() {
|
|
400
|
+
getConnectionToken.mockClear();
|
|
401
|
+
},
|
|
402
|
+
reset() {
|
|
403
|
+
tokens = {};
|
|
404
|
+
getConnectionToken.mockReset();
|
|
405
|
+
getConnectionToken.mockImplementation(defaultGetConnectionToken);
|
|
406
|
+
}
|
|
407
|
+
}, () => {
|
|
408
|
+
root.authconnection = prev;
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
//#endregion
|
|
413
|
+
//#region src/vitest/mocks/file.ts
|
|
414
|
+
const FILE_METHODS = [
|
|
415
|
+
"upload",
|
|
416
|
+
"download",
|
|
417
|
+
"downloadAsBase64",
|
|
418
|
+
"delete",
|
|
419
|
+
"getMetadata",
|
|
420
|
+
"downloadStream",
|
|
421
|
+
"uploadStream"
|
|
422
|
+
];
|
|
423
|
+
const FILE_DEFAULTS = {
|
|
424
|
+
upload: { metadata: {
|
|
425
|
+
fileSize: 0,
|
|
426
|
+
sha256sum: ""
|
|
427
|
+
} },
|
|
428
|
+
download: {
|
|
429
|
+
data: /* @__PURE__ */ new Uint8Array(),
|
|
430
|
+
metadata: {
|
|
431
|
+
contentType: "",
|
|
432
|
+
fileSize: 0,
|
|
433
|
+
sha256sum: "",
|
|
434
|
+
lastUploadedAt: ""
|
|
435
|
+
}
|
|
436
|
+
},
|
|
437
|
+
downloadAsBase64: {
|
|
438
|
+
data: "",
|
|
439
|
+
metadata: {
|
|
440
|
+
contentType: "",
|
|
441
|
+
fileSize: 0,
|
|
442
|
+
sha256sum: "",
|
|
443
|
+
lastUploadedAt: ""
|
|
444
|
+
}
|
|
445
|
+
},
|
|
446
|
+
getMetadata: {
|
|
447
|
+
contentType: "",
|
|
448
|
+
fileSize: 0,
|
|
449
|
+
sha256sum: "",
|
|
450
|
+
urlPath: ""
|
|
451
|
+
},
|
|
452
|
+
downloadStream: null,
|
|
453
|
+
uploadStream: { metadata: {
|
|
454
|
+
fileSize: 0,
|
|
455
|
+
sha256sum: ""
|
|
456
|
+
} }
|
|
457
|
+
};
|
|
458
|
+
/**
|
|
459
|
+
* Acquire a disposable mock for `tailordb.file`. Restored on dispose.
|
|
460
|
+
* @param options - Controls behavior for calls without a configured result
|
|
461
|
+
* @returns Disposable File mock control object
|
|
462
|
+
* @example
|
|
463
|
+
* ```typescript
|
|
464
|
+
* import { mockFile } from "@tailor-platform/sdk/vitest";
|
|
465
|
+
*
|
|
466
|
+
* test("mock file download", async () => {
|
|
467
|
+
* using file = mockFile();
|
|
468
|
+
* file.download.mockResolvedValue({ data: new Uint8Array(), metadata: { ... } });
|
|
469
|
+
* // …
|
|
470
|
+
* });
|
|
471
|
+
* ```
|
|
472
|
+
*/
|
|
473
|
+
function mockFile(options = {}) {
|
|
474
|
+
const root = tailordbRoot();
|
|
475
|
+
const prev = root.file;
|
|
476
|
+
const { onUnhandled = "fallback" } = options;
|
|
477
|
+
const queue = [];
|
|
478
|
+
const calls = [];
|
|
479
|
+
let resolver = () => null;
|
|
480
|
+
function handle(method, namespace, typeName, fieldName, recordId) {
|
|
481
|
+
if (queue.length > 0) return queue.shift();
|
|
482
|
+
const resolved = resolver(method, {
|
|
483
|
+
method,
|
|
484
|
+
namespace,
|
|
485
|
+
typeName,
|
|
486
|
+
fieldName,
|
|
487
|
+
recordId
|
|
488
|
+
});
|
|
489
|
+
if (resolved != null) return resolved;
|
|
490
|
+
if (onUnhandled === "error") throw new Error(`No File mock configured for "${method}"`);
|
|
491
|
+
const fallback = FILE_DEFAULTS[method];
|
|
492
|
+
return fallback === void 0 ? void 0 : structuredClone(fallback);
|
|
493
|
+
}
|
|
494
|
+
const upload = vi.fn(async (...args) => {
|
|
495
|
+
const [namespace, typeName, fieldName, recordId] = args;
|
|
496
|
+
return handle("upload", namespace, typeName, fieldName, recordId);
|
|
497
|
+
});
|
|
498
|
+
const download = vi.fn(async (...args) => handle("download", ...args));
|
|
499
|
+
const downloadAsBase64 = vi.fn(async (...args) => handle("downloadAsBase64", ...args));
|
|
500
|
+
const deleteFile = vi.fn(async (...args) => {
|
|
501
|
+
handle("delete", ...args);
|
|
502
|
+
});
|
|
503
|
+
const getMetadata = vi.fn(async (...args) => handle("getMetadata", ...args));
|
|
504
|
+
const downloadStream = vi.fn(async (...args) => {
|
|
505
|
+
const resolved = handle("downloadStream", ...args);
|
|
506
|
+
if (resolved != null) return resolved;
|
|
507
|
+
return {
|
|
508
|
+
body: new ReadableStream({ start(controller) {
|
|
509
|
+
controller.close();
|
|
510
|
+
} }),
|
|
511
|
+
metadata: {
|
|
512
|
+
contentType: "",
|
|
513
|
+
fileSize: 0,
|
|
514
|
+
sha256sum: "",
|
|
515
|
+
lastUploadedAt: ""
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
});
|
|
519
|
+
const uploadStream = vi.fn(async (...args) => {
|
|
520
|
+
const [namespace, typeName, fieldName, recordId] = args;
|
|
521
|
+
return handle("uploadStream", namespace, typeName, fieldName, recordId);
|
|
522
|
+
});
|
|
523
|
+
const mocks = {
|
|
524
|
+
upload,
|
|
525
|
+
download,
|
|
526
|
+
downloadAsBase64,
|
|
527
|
+
delete: deleteFile,
|
|
528
|
+
getMetadata,
|
|
529
|
+
downloadStream,
|
|
530
|
+
uploadStream
|
|
531
|
+
};
|
|
532
|
+
function track(method, operation) {
|
|
533
|
+
return function(...args) {
|
|
534
|
+
calls.push({
|
|
535
|
+
method,
|
|
536
|
+
namespace: args[0],
|
|
537
|
+
typeName: args[1],
|
|
538
|
+
fieldName: args[2],
|
|
539
|
+
recordId: args[3]
|
|
540
|
+
});
|
|
541
|
+
return operation.apply(this, args);
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
root.file = {
|
|
545
|
+
upload: track("upload", upload),
|
|
546
|
+
download: track("download", download),
|
|
547
|
+
downloadAsBase64: track("downloadAsBase64", downloadAsBase64),
|
|
548
|
+
delete: track("delete", deleteFile),
|
|
549
|
+
getMetadata: track("getMetadata", getMetadata),
|
|
550
|
+
downloadStream: track("downloadStream", downloadStream),
|
|
551
|
+
uploadStream: track("uploadStream", uploadStream)
|
|
552
|
+
};
|
|
553
|
+
function allMocks() {
|
|
554
|
+
return FILE_METHODS.map((method) => mocks[method]);
|
|
555
|
+
}
|
|
556
|
+
return withDispose({
|
|
557
|
+
...mocks,
|
|
558
|
+
setResolver(value) {
|
|
559
|
+
resolver = value;
|
|
560
|
+
},
|
|
561
|
+
/**
|
|
562
|
+
* Enqueue a single result for the next `tailordb.file` call.
|
|
563
|
+
* The queue is shared across all methods and namespaces.
|
|
564
|
+
* @param result - Result to return from the next file call
|
|
565
|
+
*/
|
|
566
|
+
enqueueResult(result) {
|
|
567
|
+
queue.push(result);
|
|
568
|
+
},
|
|
569
|
+
/**
|
|
570
|
+
* Enqueue results for multiple subsequent `tailordb.file` calls.
|
|
571
|
+
* The queue is shared across all methods and namespaces.
|
|
572
|
+
* @param results - Results to enqueue, one per upcoming call
|
|
573
|
+
*/
|
|
574
|
+
enqueueResults(...results) {
|
|
575
|
+
queue.push(...results);
|
|
576
|
+
},
|
|
577
|
+
get calls() {
|
|
578
|
+
return calls;
|
|
579
|
+
},
|
|
580
|
+
clear() {
|
|
581
|
+
calls.length = 0;
|
|
582
|
+
for (const mock of allMocks()) mock.mockClear();
|
|
583
|
+
},
|
|
584
|
+
reset() {
|
|
585
|
+
queue.length = 0;
|
|
586
|
+
calls.length = 0;
|
|
587
|
+
resolver = () => null;
|
|
588
|
+
for (const mock of allMocks()) mock.mockReset();
|
|
589
|
+
}
|
|
590
|
+
}, () => {
|
|
591
|
+
root.file = prev;
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
//#endregion
|
|
596
|
+
//#region src/vitest/mocks/iconv.ts
|
|
597
|
+
function isUtf8(encoding) {
|
|
598
|
+
return encoding === "UTF8" || encoding === "UTF-8";
|
|
599
|
+
}
|
|
600
|
+
function defaultIconvResult(method, args) {
|
|
601
|
+
switch (method) {
|
|
602
|
+
case "convert":
|
|
603
|
+
case "convertBuffer": return isUtf8(args[2]) ? "" : /* @__PURE__ */ new Uint8Array();
|
|
604
|
+
case "decode": return "";
|
|
605
|
+
case "encode": return isUtf8(args[1]) ? "" : /* @__PURE__ */ new Uint8Array();
|
|
606
|
+
case "encodings": return [];
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
/**
|
|
610
|
+
* Acquire a disposable mock for `tailor.iconv`. Restored on dispose.
|
|
611
|
+
* @param options - Fallback behavior for unconfigured operations
|
|
612
|
+
* @returns Disposable Iconv mock control object
|
|
613
|
+
* @example
|
|
614
|
+
* ```typescript
|
|
615
|
+
* import { mockIconv } from "@tailor-platform/sdk/vitest";
|
|
616
|
+
*
|
|
617
|
+
* test("mock encoding conversion", () => {
|
|
618
|
+
* using iconv = mockIconv();
|
|
619
|
+
* iconv.decode.mockReturnValue("decoded-text");
|
|
620
|
+
* // …
|
|
621
|
+
* });
|
|
622
|
+
* ```
|
|
623
|
+
*/
|
|
624
|
+
function mockIconv(options = {}) {
|
|
625
|
+
const root = tailorRoot();
|
|
626
|
+
const prev = root.iconv;
|
|
627
|
+
let resolver = null;
|
|
628
|
+
const calls = [];
|
|
629
|
+
function resolve(method, args) {
|
|
630
|
+
if (resolver) {
|
|
631
|
+
const result = resolver(method, args);
|
|
632
|
+
if (result != null) return result;
|
|
633
|
+
}
|
|
634
|
+
if (options.onUnhandled === "error") throw new Error(`No Iconv mock behavior configured for "${method}"`);
|
|
635
|
+
return defaultIconvResult(method, args);
|
|
636
|
+
}
|
|
637
|
+
function defaultConvert(input, fromEncoding, toEncoding) {
|
|
638
|
+
return resolve("convert", [
|
|
639
|
+
input,
|
|
640
|
+
fromEncoding,
|
|
641
|
+
toEncoding
|
|
642
|
+
]);
|
|
643
|
+
}
|
|
644
|
+
function defaultConvertBuffer(input, fromEncoding, toEncoding) {
|
|
645
|
+
return resolve("convertBuffer", [
|
|
646
|
+
input,
|
|
647
|
+
fromEncoding,
|
|
648
|
+
toEncoding
|
|
649
|
+
]);
|
|
650
|
+
}
|
|
651
|
+
function defaultDecode(input, encoding) {
|
|
652
|
+
return resolve("decode", [input, encoding]);
|
|
653
|
+
}
|
|
654
|
+
function defaultEncode(input, encoding) {
|
|
655
|
+
return resolve("encode", [input, encoding]);
|
|
656
|
+
}
|
|
657
|
+
function defaultEncodings() {
|
|
658
|
+
return resolve("encodings", []);
|
|
659
|
+
}
|
|
660
|
+
const convert = vi.fn(defaultConvert);
|
|
661
|
+
const convertBuffer = vi.fn(defaultConvertBuffer);
|
|
662
|
+
const decode = vi.fn(defaultDecode);
|
|
663
|
+
const encode = vi.fn(defaultEncode);
|
|
664
|
+
const encodings = vi.fn(defaultEncodings);
|
|
665
|
+
function track(method, operation) {
|
|
666
|
+
return function(...args) {
|
|
667
|
+
calls.push({
|
|
668
|
+
method,
|
|
669
|
+
args: [...args]
|
|
670
|
+
});
|
|
671
|
+
return operation.apply(this, args);
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
const trackedConvert = track("convert", convert);
|
|
675
|
+
const trackedConvertBuffer = track("convertBuffer", convertBuffer);
|
|
676
|
+
const trackedDecode = track("decode", decode);
|
|
677
|
+
const trackedEncode = track("encode", encode);
|
|
678
|
+
const trackedEncodings = track("encodings", encodings);
|
|
679
|
+
class MockIconv {
|
|
680
|
+
#fromEncoding;
|
|
681
|
+
#toEncoding;
|
|
682
|
+
constructor(fromEncoding, toEncoding) {
|
|
683
|
+
this.#fromEncoding = fromEncoding;
|
|
684
|
+
this.#toEncoding = toEncoding;
|
|
685
|
+
}
|
|
686
|
+
convert(input) {
|
|
687
|
+
return trackedConvert.call(this, input, this.#fromEncoding, this.#toEncoding);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
root.iconv = {
|
|
691
|
+
convert: trackedConvert,
|
|
692
|
+
convertBuffer: trackedConvertBuffer,
|
|
693
|
+
decode: trackedDecode,
|
|
694
|
+
encode: trackedEncode,
|
|
695
|
+
encodings: trackedEncodings,
|
|
696
|
+
Iconv: MockIconv
|
|
697
|
+
};
|
|
698
|
+
function clear() {
|
|
699
|
+
calls.length = 0;
|
|
700
|
+
convert.mockClear();
|
|
701
|
+
convertBuffer.mockClear();
|
|
702
|
+
decode.mockClear();
|
|
703
|
+
encode.mockClear();
|
|
704
|
+
encodings.mockClear();
|
|
705
|
+
}
|
|
706
|
+
return withDispose({
|
|
707
|
+
/** The `convert` `vi.fn`. */
|
|
708
|
+
convert,
|
|
709
|
+
/** The `convertBuffer` `vi.fn`. */
|
|
710
|
+
convertBuffer,
|
|
711
|
+
/** The `decode` `vi.fn`. */
|
|
712
|
+
decode,
|
|
713
|
+
/** The `encode` `vi.fn`. */
|
|
714
|
+
encode,
|
|
715
|
+
/** The `encodings` `vi.fn`. */
|
|
716
|
+
encodings,
|
|
717
|
+
setResolver(value) {
|
|
718
|
+
resolver = value;
|
|
719
|
+
},
|
|
720
|
+
get calls() {
|
|
721
|
+
return calls;
|
|
722
|
+
},
|
|
723
|
+
clear,
|
|
724
|
+
reset() {
|
|
725
|
+
resolver = null;
|
|
726
|
+
calls.length = 0;
|
|
727
|
+
convert.mockReset();
|
|
728
|
+
convert.mockImplementation(defaultConvert);
|
|
729
|
+
convertBuffer.mockReset();
|
|
730
|
+
convertBuffer.mockImplementation(defaultConvertBuffer);
|
|
731
|
+
decode.mockReset();
|
|
732
|
+
decode.mockImplementation(defaultDecode);
|
|
733
|
+
encode.mockReset();
|
|
734
|
+
encode.mockImplementation(defaultEncode);
|
|
735
|
+
encodings.mockReset();
|
|
736
|
+
encodings.mockImplementation(defaultEncodings);
|
|
737
|
+
}
|
|
738
|
+
}, () => {
|
|
739
|
+
root.iconv = prev;
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
//#endregion
|
|
744
|
+
//#region src/vitest/mocks/idp.ts
|
|
745
|
+
const IDP_METHODS = [
|
|
746
|
+
"users",
|
|
747
|
+
"user",
|
|
748
|
+
"userByName",
|
|
749
|
+
"createUser",
|
|
750
|
+
"updateUser",
|
|
751
|
+
"deleteUser",
|
|
752
|
+
"sendPasswordResetEmail",
|
|
753
|
+
"unenrollMfa"
|
|
754
|
+
];
|
|
755
|
+
const IDP_USER_DEFAULT = {
|
|
756
|
+
id: "mock-id",
|
|
757
|
+
name: "mock-user",
|
|
758
|
+
disabled: false,
|
|
759
|
+
mfaEnrolled: false,
|
|
760
|
+
mfaFactorIds: []
|
|
761
|
+
};
|
|
762
|
+
const IDP_DEFAULTS = {
|
|
763
|
+
users: {
|
|
764
|
+
users: [],
|
|
765
|
+
nextPageToken: null,
|
|
766
|
+
totalCount: 0
|
|
767
|
+
},
|
|
768
|
+
user: IDP_USER_DEFAULT,
|
|
769
|
+
userByName: IDP_USER_DEFAULT,
|
|
770
|
+
createUser: IDP_USER_DEFAULT,
|
|
771
|
+
updateUser: IDP_USER_DEFAULT,
|
|
772
|
+
deleteUser: true,
|
|
773
|
+
sendPasswordResetEmail: true,
|
|
774
|
+
unenrollMfa: true
|
|
775
|
+
};
|
|
776
|
+
/**
|
|
777
|
+
* Acquire a disposable mock for `tailor.idp`. Restored on dispose.
|
|
778
|
+
* @param options - Controls behavior for calls without a configured result
|
|
779
|
+
* @returns Disposable IDP mock control object
|
|
780
|
+
* @example
|
|
781
|
+
* ```typescript
|
|
782
|
+
* import { mockIdp } from "@tailor-platform/sdk/vitest";
|
|
783
|
+
*
|
|
784
|
+
* test("returns a user", async () => {
|
|
785
|
+
* using idp = mockIdp();
|
|
786
|
+
* idp.namespace("my-idp").user.mockResolvedValue({
|
|
787
|
+
* id: "u-1",
|
|
788
|
+
* name: "alice",
|
|
789
|
+
* disabled: false,
|
|
790
|
+
* mfaEnrolled: false,
|
|
791
|
+
* mfaFactorIds: [],
|
|
792
|
+
* });
|
|
793
|
+
* // …
|
|
794
|
+
* });
|
|
795
|
+
* ```
|
|
796
|
+
*/
|
|
797
|
+
function mockIdp(options = {}) {
|
|
798
|
+
const root = tailorRoot();
|
|
799
|
+
const prev = root.idp;
|
|
800
|
+
const { onUnhandled = "fallback" } = options;
|
|
801
|
+
const queue = [];
|
|
802
|
+
const calls = [];
|
|
803
|
+
let resolver = () => null;
|
|
804
|
+
const namespaces = /* @__PURE__ */ new Map();
|
|
805
|
+
function compatibilityArgs(method, args) {
|
|
806
|
+
return method === "users" && args.length === 0 ? [void 0] : args;
|
|
807
|
+
}
|
|
808
|
+
function handle(method, args, namespace) {
|
|
809
|
+
if (queue.length > 0) return queue.shift();
|
|
810
|
+
const resolved = resolver(method, compatibilityArgs(method, args), namespace);
|
|
811
|
+
if (resolved != null) return resolved;
|
|
812
|
+
if (onUnhandled === "error") throw new Error(`No IdP mock configured for "${namespace}.${method}"`);
|
|
813
|
+
return structuredClone(IDP_DEFAULTS[method]);
|
|
814
|
+
}
|
|
815
|
+
function createNamespaceMocks(namespace) {
|
|
816
|
+
return {
|
|
817
|
+
users: vi.fn(async (...args) => handle("users", args, namespace)),
|
|
818
|
+
user: vi.fn(async (...args) => handle("user", args, namespace)),
|
|
819
|
+
userByName: vi.fn(async (...args) => handle("userByName", args, namespace)),
|
|
820
|
+
createUser: vi.fn(async (...args) => handle("createUser", args, namespace)),
|
|
821
|
+
updateUser: vi.fn(async (...args) => handle("updateUser", args, namespace)),
|
|
822
|
+
deleteUser: vi.fn(async (...args) => handle("deleteUser", args, namespace)),
|
|
823
|
+
sendPasswordResetEmail: vi.fn(async (...args) => handle("sendPasswordResetEmail", args, namespace)),
|
|
824
|
+
unenrollMfa: vi.fn(async (...args) => handle("unenrollMfa", args, namespace))
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
function namespace(name) {
|
|
828
|
+
const existing = namespaces.get(name);
|
|
829
|
+
if (existing) return existing;
|
|
830
|
+
const mocks = createNamespaceMocks(name);
|
|
831
|
+
namespaces.set(name, mocks);
|
|
832
|
+
return mocks;
|
|
833
|
+
}
|
|
834
|
+
function track(method, mock, namespaceName) {
|
|
835
|
+
return function(...args) {
|
|
836
|
+
calls.push({
|
|
837
|
+
method,
|
|
838
|
+
args: [...compatibilityArgs(method, args)],
|
|
839
|
+
namespace: namespaceName
|
|
840
|
+
});
|
|
841
|
+
return mock.apply(this, args);
|
|
842
|
+
};
|
|
843
|
+
}
|
|
844
|
+
const defaultClient = function(config) {
|
|
845
|
+
const mocks = namespace(config.namespace);
|
|
846
|
+
this.users = track("users", mocks.users, config.namespace);
|
|
847
|
+
this.user = track("user", mocks.user, config.namespace);
|
|
848
|
+
this.userByName = track("userByName", mocks.userByName, config.namespace);
|
|
849
|
+
this.createUser = track("createUser", mocks.createUser, config.namespace);
|
|
850
|
+
this.updateUser = track("updateUser", mocks.updateUser, config.namespace);
|
|
851
|
+
this.deleteUser = track("deleteUser", mocks.deleteUser, config.namespace);
|
|
852
|
+
this.sendPasswordResetEmail = track("sendPasswordResetEmail", mocks.sendPasswordResetEmail, config.namespace);
|
|
853
|
+
this.unenrollMfa = track("unenrollMfa", mocks.unenrollMfa, config.namespace);
|
|
854
|
+
};
|
|
855
|
+
const Client = vi.fn(defaultClient);
|
|
856
|
+
root.idp = { Client };
|
|
857
|
+
function allMocks() {
|
|
858
|
+
return [...namespaces.values()].flatMap((mocks) => IDP_METHODS.map((method) => mocks[method]));
|
|
859
|
+
}
|
|
860
|
+
return withDispose({
|
|
861
|
+
/** The mock IDP `Client` constructor (`vi.fn`). */
|
|
862
|
+
Client,
|
|
863
|
+
namespace,
|
|
864
|
+
setResolver(value) {
|
|
865
|
+
resolver = value;
|
|
866
|
+
},
|
|
867
|
+
/**
|
|
868
|
+
* Enqueue a single result for the next IDP call.
|
|
869
|
+
* The queue is shared across all methods and namespaces.
|
|
870
|
+
* @param result - Result to return from the next IDP call
|
|
871
|
+
*/
|
|
872
|
+
enqueueResult(result) {
|
|
873
|
+
queue.push(result);
|
|
874
|
+
},
|
|
875
|
+
/**
|
|
876
|
+
* Enqueue results for multiple subsequent IDP calls.
|
|
877
|
+
* The queue is shared across all methods and namespaces.
|
|
878
|
+
* @param results - Results to enqueue, one per upcoming call
|
|
879
|
+
*/
|
|
880
|
+
enqueueResults(...results) {
|
|
881
|
+
queue.push(...results);
|
|
882
|
+
},
|
|
883
|
+
get calls() {
|
|
884
|
+
return calls;
|
|
885
|
+
},
|
|
886
|
+
clear() {
|
|
887
|
+
calls.length = 0;
|
|
888
|
+
Client.mockClear();
|
|
889
|
+
for (const mock of allMocks()) mock.mockClear();
|
|
890
|
+
},
|
|
891
|
+
reset() {
|
|
892
|
+
queue.length = 0;
|
|
893
|
+
calls.length = 0;
|
|
894
|
+
resolver = () => null;
|
|
895
|
+
Client.mockReset();
|
|
896
|
+
Client.mockImplementation(defaultClient);
|
|
897
|
+
for (const mock of allMocks()) mock.mockReset();
|
|
898
|
+
}
|
|
899
|
+
}, () => {
|
|
900
|
+
root.idp = prev;
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
//#endregion
|
|
905
|
+
//#region src/vitest/mocks/logger.ts
|
|
906
|
+
/**
|
|
907
|
+
* Acquire a disposable mock for `tailor.logger`. Each method is a `vi.fn`, so
|
|
908
|
+
* calls can be asserted directly; `calls` returns the `debug`/`info`/`warn`/
|
|
909
|
+
* `error` entries in the order they were emitted. Restored on dispose.
|
|
910
|
+
* @param _options - Reserved for future initial fixtures
|
|
911
|
+
* @returns Disposable logger mock control object
|
|
912
|
+
* @example
|
|
913
|
+
* ```typescript
|
|
914
|
+
* import { mockLogger } from "@tailor-platform/sdk/vitest";
|
|
915
|
+
*
|
|
916
|
+
* test("logs the processed order", () => {
|
|
917
|
+
* using logger = mockLogger();
|
|
918
|
+
* // …run code that calls tailor.logger.info…
|
|
919
|
+
* expect(logger.info).toHaveBeenCalledWith("order processed", { orderId: "o-1" });
|
|
920
|
+
* });
|
|
921
|
+
* ```
|
|
922
|
+
*/
|
|
923
|
+
function mockLogger(_options = {}) {
|
|
924
|
+
const root = tailorRoot();
|
|
925
|
+
const prev = root.logger;
|
|
926
|
+
const debug = vi.fn((_message, _attributes) => {});
|
|
927
|
+
const info = vi.fn((_message, _attributes) => {});
|
|
928
|
+
const warn = vi.fn((_message, _attributes) => {});
|
|
929
|
+
const error = vi.fn((_message, _attributes) => {});
|
|
930
|
+
const setAttributes = vi.fn((_attributes) => {});
|
|
931
|
+
root.logger = {
|
|
932
|
+
debug,
|
|
933
|
+
info,
|
|
934
|
+
warn,
|
|
935
|
+
error,
|
|
936
|
+
setAttributes
|
|
937
|
+
};
|
|
938
|
+
const severityFns = {
|
|
939
|
+
debug,
|
|
940
|
+
info,
|
|
941
|
+
warn,
|
|
942
|
+
error
|
|
943
|
+
};
|
|
944
|
+
return withDispose({
|
|
945
|
+
/** The `debug` `vi.fn`. */
|
|
946
|
+
debug,
|
|
947
|
+
/** The `info` `vi.fn`. */
|
|
948
|
+
info,
|
|
949
|
+
/** The `warn` `vi.fn`. */
|
|
950
|
+
warn,
|
|
951
|
+
/** The `error` `vi.fn`. */
|
|
952
|
+
error,
|
|
953
|
+
/** The `setAttributes` `vi.fn`. */
|
|
954
|
+
setAttributes,
|
|
955
|
+
get calls() {
|
|
956
|
+
return Object.entries(severityFns).flatMap(([severity, fn]) => fn.mock.calls.map((args, i) => ({
|
|
957
|
+
order: fn.mock.invocationCallOrder[i] ?? 0,
|
|
958
|
+
call: {
|
|
959
|
+
severity,
|
|
960
|
+
message: args[0],
|
|
961
|
+
attributes: args[1]
|
|
962
|
+
}
|
|
963
|
+
}))).toSorted((a, b) => a.order - b.order).map((e) => e.call);
|
|
964
|
+
},
|
|
965
|
+
clear() {
|
|
966
|
+
debug.mockClear();
|
|
967
|
+
info.mockClear();
|
|
968
|
+
warn.mockClear();
|
|
969
|
+
error.mockClear();
|
|
970
|
+
setAttributes.mockClear();
|
|
971
|
+
},
|
|
972
|
+
reset() {
|
|
973
|
+
debug.mockReset();
|
|
974
|
+
info.mockReset();
|
|
975
|
+
warn.mockReset();
|
|
976
|
+
error.mockReset();
|
|
977
|
+
setAttributes.mockReset();
|
|
978
|
+
}
|
|
979
|
+
}, () => {
|
|
980
|
+
root.logger = prev;
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
//#endregion
|
|
985
|
+
//#region src/vitest/mocks/tailordb.ts
|
|
986
|
+
function testRegex(regex, value) {
|
|
987
|
+
const lastIndex = regex.lastIndex;
|
|
988
|
+
regex.lastIndex = 0;
|
|
989
|
+
try {
|
|
990
|
+
return regex.test(value);
|
|
991
|
+
} finally {
|
|
992
|
+
regex.lastIndex = lastIndex;
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
var MockQueryResult = class {
|
|
996
|
+
command;
|
|
997
|
+
rowCount;
|
|
998
|
+
rows;
|
|
999
|
+
constructor(rows) {
|
|
1000
|
+
this.command = "";
|
|
1001
|
+
this.rowCount = rows.length;
|
|
1002
|
+
this.rows = rows;
|
|
1003
|
+
}
|
|
1004
|
+
};
|
|
1005
|
+
/**
|
|
1006
|
+
* Acquire a disposable mock for TailorDB operations. Installs a mock
|
|
1007
|
+
* `tailordb.Client` whose `queryObject` is a shared `vi.fn()` (so query
|
|
1008
|
+
* responses can be staged before the client is constructed). Restored on
|
|
1009
|
+
* dispose.
|
|
1010
|
+
* @param options - Query fallback behavior
|
|
1011
|
+
* @returns Disposable TailorDB mock control object
|
|
1012
|
+
* @example
|
|
1013
|
+
* ```typescript
|
|
1014
|
+
* import { mockTailordb } from "@tailor-platform/sdk/vitest";
|
|
1015
|
+
*
|
|
1016
|
+
* test("query-based", async () => {
|
|
1017
|
+
* using db = mockTailordb();
|
|
1018
|
+
* db.onQuery({ sql: /FROM users/, params: ["u-1"] }).returnsRows([{ age: 30 }]);
|
|
1019
|
+
* // …
|
|
1020
|
+
* expect(db.queryObject).toHaveBeenCalled();
|
|
1021
|
+
* expect(db.Client).toHaveBeenCalledWith({ namespace: "tailordb" });
|
|
1022
|
+
* });
|
|
1023
|
+
* ```
|
|
1024
|
+
*/
|
|
1025
|
+
function mockTailordb(options = {}) {
|
|
1026
|
+
const root = tailordbRoot();
|
|
1027
|
+
const prevClient = root.Client;
|
|
1028
|
+
const rules = [];
|
|
1029
|
+
let queryResolver;
|
|
1030
|
+
function matchesQuery(matcher, query, params) {
|
|
1031
|
+
if (typeof matcher === "function") return matcher(query, params);
|
|
1032
|
+
if (typeof matcher === "string") return query === matcher;
|
|
1033
|
+
if (matcher instanceof RegExp) return testRegex(matcher, query);
|
|
1034
|
+
let sqlMatches;
|
|
1035
|
+
if (typeof matcher.sql === "string") sqlMatches = query === matcher.sql;
|
|
1036
|
+
else sqlMatches = testRegex(matcher.sql, query);
|
|
1037
|
+
if (!sqlMatches || matcher.params === void 0) return sqlMatches;
|
|
1038
|
+
if (typeof matcher.params === "function") return matcher.params(params);
|
|
1039
|
+
const expectedParams = matcher.params;
|
|
1040
|
+
return params.length === expectedParams.length && params.every((value, index) => isEqual(value, expectedParams[index]));
|
|
1041
|
+
}
|
|
1042
|
+
function queryResponse(response) {
|
|
1043
|
+
if (response.type === "error") throw response.error;
|
|
1044
|
+
return new MockQueryResult(response.rows);
|
|
1045
|
+
}
|
|
1046
|
+
async function defaultQuery(query, params = []) {
|
|
1047
|
+
for (let i = rules.length - 1; i >= 0; i -= 1) {
|
|
1048
|
+
const rule = rules[i];
|
|
1049
|
+
if (!rule || !matchesQuery(rule.matcher, query, params)) continue;
|
|
1050
|
+
const once = rule.once.shift();
|
|
1051
|
+
if (once) return queryResponse(once);
|
|
1052
|
+
if (rule.fallback) return queryResponse(rule.fallback);
|
|
1053
|
+
}
|
|
1054
|
+
if (queryResolver) return new MockQueryResult(queryResolver(query, params) ?? []);
|
|
1055
|
+
if (options.onUnhandled === "error") throw new Error(`No TailorDB query behavior matched: ${query}`);
|
|
1056
|
+
return new MockQueryResult([]);
|
|
1057
|
+
}
|
|
1058
|
+
const queryObject = vi.fn(defaultQuery);
|
|
1059
|
+
const defaultConnect = async () => {};
|
|
1060
|
+
const connect = vi.fn(defaultConnect);
|
|
1061
|
+
const createdClients = [];
|
|
1062
|
+
function enqueueRowsList(rowsList) {
|
|
1063
|
+
for (const rows of rowsList) queryObject.mockImplementationOnce(async () => new MockQueryResult(rows));
|
|
1064
|
+
}
|
|
1065
|
+
const defaultClient = function(config) {
|
|
1066
|
+
const record = {
|
|
1067
|
+
namespace: config?.namespace,
|
|
1068
|
+
ended: false
|
|
1069
|
+
};
|
|
1070
|
+
createdClients.push(record);
|
|
1071
|
+
this.connect = connect;
|
|
1072
|
+
this.end = vi.fn(async () => {
|
|
1073
|
+
record.ended = true;
|
|
1074
|
+
});
|
|
1075
|
+
this.queryObject = queryObject;
|
|
1076
|
+
this.createTransaction = (name) => {
|
|
1077
|
+
if (!name) throw new Error("Transaction name must be a non-empty string");
|
|
1078
|
+
return {
|
|
1079
|
+
begin: async () => {},
|
|
1080
|
+
commit: async () => {},
|
|
1081
|
+
rollback: async () => {},
|
|
1082
|
+
queryObject
|
|
1083
|
+
};
|
|
1084
|
+
};
|
|
1085
|
+
};
|
|
1086
|
+
const Client = vi.fn(defaultClient);
|
|
1087
|
+
root.Client = Client;
|
|
1088
|
+
return withDispose({
|
|
1089
|
+
/** The mock `tailordb.Client` constructor (`vi.fn`). */
|
|
1090
|
+
Client,
|
|
1091
|
+
/** The shared `queryObject` `vi.fn` used by every client and transaction. */
|
|
1092
|
+
queryObject,
|
|
1093
|
+
/**
|
|
1094
|
+
* Set a fallback query resolver. Called when the enqueue queue is empty.
|
|
1095
|
+
* @param resolver - Function that returns rows for a given query and params
|
|
1096
|
+
*/
|
|
1097
|
+
setQueryResolver(resolver) {
|
|
1098
|
+
queryResolver = resolver;
|
|
1099
|
+
queryObject.mockImplementation(defaultQuery);
|
|
1100
|
+
},
|
|
1101
|
+
/**
|
|
1102
|
+
* Configure responses for queries matching SQL text, parameters, or a predicate.
|
|
1103
|
+
* More recently registered matchers take precedence.
|
|
1104
|
+
* Do not combine matchers with a direct `queryObject.mockImplementation()` override.
|
|
1105
|
+
* @param matcher - Query matcher
|
|
1106
|
+
* @returns Chainable query behavior
|
|
1107
|
+
*/
|
|
1108
|
+
onQuery(matcher) {
|
|
1109
|
+
const rule = {
|
|
1110
|
+
matcher,
|
|
1111
|
+
once: []
|
|
1112
|
+
};
|
|
1113
|
+
rules.push(rule);
|
|
1114
|
+
const behavior = {
|
|
1115
|
+
returnsRows(rows) {
|
|
1116
|
+
rule.fallback = {
|
|
1117
|
+
type: "rows",
|
|
1118
|
+
rows
|
|
1119
|
+
};
|
|
1120
|
+
return behavior;
|
|
1121
|
+
},
|
|
1122
|
+
returnsRowsOnce(rows) {
|
|
1123
|
+
rule.once.push({
|
|
1124
|
+
type: "rows",
|
|
1125
|
+
rows
|
|
1126
|
+
});
|
|
1127
|
+
return behavior;
|
|
1128
|
+
},
|
|
1129
|
+
rejects(error) {
|
|
1130
|
+
rule.fallback = {
|
|
1131
|
+
type: "error",
|
|
1132
|
+
error
|
|
1133
|
+
};
|
|
1134
|
+
return behavior;
|
|
1135
|
+
},
|
|
1136
|
+
rejectsOnce(error) {
|
|
1137
|
+
rule.once.push({
|
|
1138
|
+
type: "error",
|
|
1139
|
+
error
|
|
1140
|
+
});
|
|
1141
|
+
return behavior;
|
|
1142
|
+
}
|
|
1143
|
+
};
|
|
1144
|
+
return behavior;
|
|
1145
|
+
},
|
|
1146
|
+
/**
|
|
1147
|
+
* Enqueue rows for the next `queryObject` call (FIFO; takes priority over
|
|
1148
|
+
* `setQueryResolver`). Call with no arguments for an empty result.
|
|
1149
|
+
* @param rows - Row objects to return from the next `queryObject` call
|
|
1150
|
+
*/
|
|
1151
|
+
enqueueResult(...rows) {
|
|
1152
|
+
enqueueRowsList([rows]);
|
|
1153
|
+
},
|
|
1154
|
+
/**
|
|
1155
|
+
* Enqueue rows for multiple subsequent `queryObject` calls (FIFO).
|
|
1156
|
+
* @param rowsList - Rows arrays, one per upcoming query
|
|
1157
|
+
*/
|
|
1158
|
+
enqueueResults(...rowsList) {
|
|
1159
|
+
enqueueRowsList(rowsList);
|
|
1160
|
+
},
|
|
1161
|
+
/**
|
|
1162
|
+
* Enqueue row arrays for subsequent queries whose exact order is under test.
|
|
1163
|
+
* @param rowsList - Rows arrays, one per upcoming query
|
|
1164
|
+
*/
|
|
1165
|
+
enqueueRows(...rowsList) {
|
|
1166
|
+
enqueueRowsList(rowsList);
|
|
1167
|
+
},
|
|
1168
|
+
/**
|
|
1169
|
+
* All queries executed via `queryObject`, in order, derived from the vi.fn
|
|
1170
|
+
* call records.
|
|
1171
|
+
* @returns Executed queries array
|
|
1172
|
+
*/
|
|
1173
|
+
get executedQueries() {
|
|
1174
|
+
return queryObject.mock.calls.map(([query, params]) => ({
|
|
1175
|
+
query,
|
|
1176
|
+
params: params ?? []
|
|
1177
|
+
}));
|
|
1178
|
+
},
|
|
1179
|
+
/**
|
|
1180
|
+
* All TailorDB clients created, with their namespace and end state.
|
|
1181
|
+
* @returns Created clients array
|
|
1182
|
+
*/
|
|
1183
|
+
get createdClients() {
|
|
1184
|
+
return createdClients;
|
|
1185
|
+
},
|
|
1186
|
+
/** Clear recorded calls while preserving configured query behavior. */
|
|
1187
|
+
clear() {
|
|
1188
|
+
queryObject.mockClear();
|
|
1189
|
+
connect.mockClear();
|
|
1190
|
+
Client.mockClear();
|
|
1191
|
+
createdClients.length = 0;
|
|
1192
|
+
},
|
|
1193
|
+
/** Reset query responses and recorded calls (keeps the mock installed). */
|
|
1194
|
+
reset() {
|
|
1195
|
+
queryObject.mockReset();
|
|
1196
|
+
queryObject.mockImplementation(defaultQuery);
|
|
1197
|
+
connect.mockReset();
|
|
1198
|
+
connect.mockImplementation(defaultConnect);
|
|
1199
|
+
Client.mockReset();
|
|
1200
|
+
Client.mockImplementation(defaultClient);
|
|
1201
|
+
createdClients.length = 0;
|
|
1202
|
+
rules.length = 0;
|
|
1203
|
+
queryResolver = void 0;
|
|
1204
|
+
}
|
|
1205
|
+
}, () => {
|
|
1206
|
+
root.Client = prevClient;
|
|
1207
|
+
});
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
//#endregion
|
|
1211
|
+
//#region src/vitest/mocks/workflow.ts
|
|
1212
|
+
const originalProcedures = /* @__PURE__ */ new WeakMap();
|
|
1213
|
+
function replaceProcedure(target, key, current) {
|
|
1214
|
+
const original = originalProcedures.get(current) ?? current;
|
|
1215
|
+
const defaultImplementation = function(...args) {
|
|
1216
|
+
return Reflect.apply(original, this, args);
|
|
1217
|
+
};
|
|
1218
|
+
const mock = vi.fn(defaultImplementation);
|
|
1219
|
+
originalProcedures.set(mock, original);
|
|
1220
|
+
const record = target;
|
|
1221
|
+
record[key] = mock;
|
|
1222
|
+
return {
|
|
1223
|
+
mock,
|
|
1224
|
+
scoped: {
|
|
1225
|
+
mockClear: () => mock.mockClear(),
|
|
1226
|
+
mockReset: () => mock.mockReset(),
|
|
1227
|
+
restore: () => {
|
|
1228
|
+
if (record[key] === mock) record[key] = current;
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
};
|
|
1232
|
+
}
|
|
1233
|
+
function replaceStart(definition) {
|
|
1234
|
+
return replaceProcedure(definition, "start", definition.start);
|
|
1235
|
+
}
|
|
1236
|
+
/**
|
|
1237
|
+
* Acquire a disposable mock for workflow operations (`tailor.workflow`).
|
|
1238
|
+
* Restored on dispose.
|
|
1239
|
+
*
|
|
1240
|
+
* The canonical `execJobFunction` and its `startJobFunction` alias share the
|
|
1241
|
+
* same underlying `vi.fn`, so calls through either name are recorded once and
|
|
1242
|
+
* handlers configured on either name apply to both.
|
|
1243
|
+
* @returns Disposable workflow mock control object
|
|
1244
|
+
* @example
|
|
1245
|
+
* ```typescript
|
|
1246
|
+
* import { mockWorkflow } from "@tailor-platform/sdk/vitest";
|
|
1247
|
+
*
|
|
1248
|
+
* test("job start", async () => {
|
|
1249
|
+
* using wf = mockWorkflow();
|
|
1250
|
+
* const job = wf.job(validateOrder);
|
|
1251
|
+
* job.mockResolvedValue({ valid: true });
|
|
1252
|
+
* await runWorkflowUnderTest();
|
|
1253
|
+
* expect(job).toHaveBeenCalled();
|
|
1254
|
+
* });
|
|
1255
|
+
* ```
|
|
1256
|
+
*/
|
|
1257
|
+
function mockWorkflow() {
|
|
1258
|
+
const root = tailorRoot();
|
|
1259
|
+
const prev = root.workflow;
|
|
1260
|
+
const prevEnv = readWorkflowTestEnv();
|
|
1261
|
+
const jobSpies = /* @__PURE__ */ new Map();
|
|
1262
|
+
const workflowSpies = /* @__PURE__ */ new Map();
|
|
1263
|
+
const waitPointMocks = /* @__PURE__ */ new Map();
|
|
1264
|
+
const scopedMocks = /* @__PURE__ */ new Set();
|
|
1265
|
+
const defaultExecJob = (jobName, _args, _options) => {
|
|
1266
|
+
throw new Error(`No workflow job mock for "${jobName}". Call mockWorkflow().setJobHandler(...) or enqueueResult(...), or use runWorkflowLocally() for local workflow execution.`);
|
|
1267
|
+
};
|
|
1268
|
+
const defaultStartWorkflow = async (_workflowName, _args, _options) => {
|
|
1269
|
+
return START_DEFAULT;
|
|
1270
|
+
};
|
|
1271
|
+
const defaultResumeWorkflowExecution = async (executionId) => executionId;
|
|
1272
|
+
const execJobFunction = vi.fn(defaultExecJob);
|
|
1273
|
+
const startWorkflow = vi.fn(defaultStartWorkflow);
|
|
1274
|
+
const resumeWorkflowExecution = vi.fn(defaultResumeWorkflowExecution);
|
|
1275
|
+
const wait = vi.fn((_key, _payload) => null);
|
|
1276
|
+
const resolve = vi.fn(async (_executionId, _key, _callback) => {});
|
|
1277
|
+
const jobFunctionShim = (...call) => {
|
|
1278
|
+
const out = call.length >= 3 ? execJobFunction(call[0], platformSerialize(call[1]), call[2]) : execJobFunction(call[0], platformSerialize(call[1]));
|
|
1279
|
+
return out instanceof Promise ? out.then((v) => platformSerialize(v)) : platformSerialize(out);
|
|
1280
|
+
};
|
|
1281
|
+
const workflowShim = (...call) => call.length >= 3 ? startWorkflow(call[0], platformSerialize(call[1]), call[2]) : startWorkflow(call[0], platformSerialize(call[1]));
|
|
1282
|
+
const resumeShim = (executionId) => resumeWorkflowExecution(executionId);
|
|
1283
|
+
root.workflow = {
|
|
1284
|
+
execJobFunction: jobFunctionShim,
|
|
1285
|
+
startJobFunction: jobFunctionShim,
|
|
1286
|
+
startWorkflow: workflowShim,
|
|
1287
|
+
resumeWorkflowExecution: resumeShim,
|
|
1288
|
+
wait: (key, payload) => wait(key, platformSerialize(payload)),
|
|
1289
|
+
resolve: (executionId, key, callback) => resolve(executionId, key, (payload) => {
|
|
1290
|
+
const out = callback(payload);
|
|
1291
|
+
return out instanceof Promise ? out.then((v) => platformSerialize(v)) : platformSerialize(out);
|
|
1292
|
+
})
|
|
1293
|
+
};
|
|
1294
|
+
return withDispose({
|
|
1295
|
+
/** The `execJobFunction` `vi.fn`. */
|
|
1296
|
+
execJobFunction,
|
|
1297
|
+
/**
|
|
1298
|
+
* Alias of `execJobFunction` (same `vi.fn` reference).
|
|
1299
|
+
* @deprecated Use `execJobFunction` instead.
|
|
1300
|
+
*/
|
|
1301
|
+
startJobFunction: execJobFunction,
|
|
1302
|
+
/** The `startWorkflow` `vi.fn`. */
|
|
1303
|
+
startWorkflow,
|
|
1304
|
+
/** The `resumeWorkflowExecution` `vi.fn`. */
|
|
1305
|
+
resumeWorkflowExecution,
|
|
1306
|
+
/** The `wait` `vi.fn`. */
|
|
1307
|
+
wait,
|
|
1308
|
+
/** The `resolve` `vi.fn`. */
|
|
1309
|
+
resolve,
|
|
1310
|
+
/**
|
|
1311
|
+
* Get a stable, typed mock for a workflow job's `start` method.
|
|
1312
|
+
* The real start behavior is used until an implementation or result is configured.
|
|
1313
|
+
* @param definition - Workflow job definition to mock
|
|
1314
|
+
* @returns Typed `start` mock for the definition
|
|
1315
|
+
*/
|
|
1316
|
+
job(definition) {
|
|
1317
|
+
const existing = jobSpies.get(definition);
|
|
1318
|
+
if (existing) return existing;
|
|
1319
|
+
const { mock, scoped } = replaceStart(definition);
|
|
1320
|
+
scopedMocks.add(scoped);
|
|
1321
|
+
jobSpies.set(definition, mock);
|
|
1322
|
+
return mock;
|
|
1323
|
+
},
|
|
1324
|
+
/**
|
|
1325
|
+
* Get a stable, typed mock for a workflow definition's `start` method.
|
|
1326
|
+
* The real start behavior is used until an implementation or result is configured.
|
|
1327
|
+
* @param definition - Workflow definition to mock
|
|
1328
|
+
* @returns Typed `start` mock for the definition
|
|
1329
|
+
*/
|
|
1330
|
+
workflow(definition) {
|
|
1331
|
+
const existing = workflowSpies.get(definition);
|
|
1332
|
+
if (existing) return existing;
|
|
1333
|
+
const { mock, scoped } = replaceStart(definition);
|
|
1334
|
+
workflowSpies.set(definition, mock);
|
|
1335
|
+
scopedMocks.add(scoped);
|
|
1336
|
+
return mock;
|
|
1337
|
+
},
|
|
1338
|
+
/**
|
|
1339
|
+
* Get stable, typed mocks for a wait point's `wait` and `resolve` methods.
|
|
1340
|
+
* @param definition - Wait point definition to mock
|
|
1341
|
+
* @returns Typed wait point mock control object
|
|
1342
|
+
*/
|
|
1343
|
+
waitPoint(definition) {
|
|
1344
|
+
const existing = waitPointMocks.get(definition);
|
|
1345
|
+
if (existing) return existing;
|
|
1346
|
+
const waitReplacement = replaceProcedure(definition, "wait", definition.wait);
|
|
1347
|
+
const resolveReplacement = replaceProcedure(definition, "resolve", definition.resolve);
|
|
1348
|
+
const waitSpy = waitReplacement.mock;
|
|
1349
|
+
const resolveSpy = resolveReplacement.mock;
|
|
1350
|
+
scopedMocks.add(waitReplacement.scoped);
|
|
1351
|
+
scopedMocks.add(resolveReplacement.scoped);
|
|
1352
|
+
const waitPointMock = {
|
|
1353
|
+
wait: waitSpy,
|
|
1354
|
+
resolve: resolveSpy,
|
|
1355
|
+
/**
|
|
1356
|
+
* Invoke the next and subsequent resolve callbacks with a wait payload.
|
|
1357
|
+
* @param payload - Payload originally supplied to the wait point
|
|
1358
|
+
*/
|
|
1359
|
+
setResolvePayload(payload) {
|
|
1360
|
+
resolveSpy.mockImplementation(async (_executionId, callback) => {
|
|
1361
|
+
platformSerialize(await callback(platformSerialize(payload)));
|
|
1362
|
+
});
|
|
1363
|
+
}
|
|
1364
|
+
};
|
|
1365
|
+
waitPointMocks.set(definition, waitPointMock);
|
|
1366
|
+
return waitPointMock;
|
|
1367
|
+
},
|
|
1368
|
+
/**
|
|
1369
|
+
* Set a fallback job handler. Called when the enqueue queue is empty.
|
|
1370
|
+
* @param handler - Function returning a result for a job name, args, and options
|
|
1371
|
+
*/
|
|
1372
|
+
setJobHandler(handler) {
|
|
1373
|
+
execJobFunction.mockImplementation((name, args, options) => handler(name, args, options));
|
|
1374
|
+
},
|
|
1375
|
+
/**
|
|
1376
|
+
* Enqueue a single result for the next `execJobFunction` call (FIFO;
|
|
1377
|
+
* takes priority over `setJobHandler`).
|
|
1378
|
+
* @param result - Result to return from the next call
|
|
1379
|
+
*/
|
|
1380
|
+
enqueueResult(result) {
|
|
1381
|
+
execJobFunction.mockImplementationOnce(() => result);
|
|
1382
|
+
},
|
|
1383
|
+
/**
|
|
1384
|
+
* Enqueue results for multiple subsequent `execJobFunction` calls (FIFO).
|
|
1385
|
+
* @param results - Results to enqueue, one per upcoming call
|
|
1386
|
+
*/
|
|
1387
|
+
enqueueResults(...results) {
|
|
1388
|
+
for (const result of results) execJobFunction.mockImplementationOnce(() => result);
|
|
1389
|
+
},
|
|
1390
|
+
/**
|
|
1391
|
+
* All jobs executed via `execJobFunction`, in order.
|
|
1392
|
+
* @returns Started jobs array
|
|
1393
|
+
*/
|
|
1394
|
+
get startedJobs() {
|
|
1395
|
+
return execJobFunction.mock.calls.map(([jobName, args, options]) => ({
|
|
1396
|
+
jobName,
|
|
1397
|
+
args,
|
|
1398
|
+
...options !== void 0 && { options }
|
|
1399
|
+
}));
|
|
1400
|
+
},
|
|
1401
|
+
/**
|
|
1402
|
+
* Configure what `startWorkflow` returns. Pass a string (same id every
|
|
1403
|
+
* call) or `(name, args, options) => string`. Default: a placeholder UUID.
|
|
1404
|
+
* @param handler - Static execution ID or a function returning one
|
|
1405
|
+
*/
|
|
1406
|
+
setStartHandler(handler) {
|
|
1407
|
+
startWorkflow.mockImplementation(typeof handler === "function" ? async (name, args, options) => handler(name, args, options) : async () => handler);
|
|
1408
|
+
},
|
|
1409
|
+
/**
|
|
1410
|
+
* Configure what `resumeWorkflowExecution` returns. Pass a string (same id
|
|
1411
|
+
* every call) or `(executionId) => string`. Default: echoes the input executionId.
|
|
1412
|
+
* @param handler - Static execution ID or a function returning one
|
|
1413
|
+
*/
|
|
1414
|
+
setResumeHandler(handler) {
|
|
1415
|
+
resumeWorkflowExecution.mockImplementation(typeof handler === "function" ? async (executionId) => handler(executionId) : async () => handler);
|
|
1416
|
+
},
|
|
1417
|
+
/**
|
|
1418
|
+
* Configure what `wait` returns. Pass `(key, payload) => unknown` or any
|
|
1419
|
+
* other value to return it for every call. Default: `null`.
|
|
1420
|
+
* @param handler - Static value or a function returning one
|
|
1421
|
+
*/
|
|
1422
|
+
setWaitHandler: ((handler) => {
|
|
1423
|
+
wait.mockImplementation(typeof handler === "function" ? (key, payload) => handler(key, payload) : () => handler);
|
|
1424
|
+
}),
|
|
1425
|
+
/**
|
|
1426
|
+
* Set the `env` passed to job bodies invoked via `createWorkflowJob().start()`.
|
|
1427
|
+
* Cleared on dispose / reset.
|
|
1428
|
+
* @param env - Env passed to job bodies.
|
|
1429
|
+
*/
|
|
1430
|
+
setEnv(env) {
|
|
1431
|
+
writeWorkflowTestEnv({ ...env });
|
|
1432
|
+
},
|
|
1433
|
+
/**
|
|
1434
|
+
* Configure how `resolve` runs the user-supplied callback. Default: callback
|
|
1435
|
+
* is not invoked (records the call only).
|
|
1436
|
+
* @param handler - Function invoked per `resolve` call
|
|
1437
|
+
*/
|
|
1438
|
+
setResolveHandler(handler) {
|
|
1439
|
+
resolve.mockImplementation(async (executionId, key, callback) => {
|
|
1440
|
+
await handler(executionId, key, callback);
|
|
1441
|
+
});
|
|
1442
|
+
},
|
|
1443
|
+
/**
|
|
1444
|
+
* `wait` calls reshaped as `{ key, payload }` for assertions.
|
|
1445
|
+
* @returns Wait call records
|
|
1446
|
+
*/
|
|
1447
|
+
get waitCalls() {
|
|
1448
|
+
return wait.mock.calls.map(([key, payload]) => ({
|
|
1449
|
+
key,
|
|
1450
|
+
payload
|
|
1451
|
+
}));
|
|
1452
|
+
},
|
|
1453
|
+
/**
|
|
1454
|
+
* `resolve` calls reshaped as `{ executionId, key }` for assertions.
|
|
1455
|
+
* @returns Resolve call records
|
|
1456
|
+
*/
|
|
1457
|
+
get resolveCalls() {
|
|
1458
|
+
return resolve.mock.calls.map(([executionId, key]) => ({
|
|
1459
|
+
executionId,
|
|
1460
|
+
key
|
|
1461
|
+
}));
|
|
1462
|
+
},
|
|
1463
|
+
/** Clear recorded calls while preserving configured responses. */
|
|
1464
|
+
clear() {
|
|
1465
|
+
execJobFunction.mockClear();
|
|
1466
|
+
startWorkflow.mockClear();
|
|
1467
|
+
resumeWorkflowExecution.mockClear();
|
|
1468
|
+
wait.mockClear();
|
|
1469
|
+
resolve.mockClear();
|
|
1470
|
+
for (const mock of scopedMocks) mock.mockClear();
|
|
1471
|
+
},
|
|
1472
|
+
/** Reset all workflow responses and recorded calls (keeps the mock installed). */
|
|
1473
|
+
reset() {
|
|
1474
|
+
execJobFunction.mockReset();
|
|
1475
|
+
execJobFunction.mockImplementation(defaultExecJob);
|
|
1476
|
+
startWorkflow.mockReset();
|
|
1477
|
+
startWorkflow.mockImplementation(defaultStartWorkflow);
|
|
1478
|
+
resumeWorkflowExecution.mockReset();
|
|
1479
|
+
resumeWorkflowExecution.mockImplementation(defaultResumeWorkflowExecution);
|
|
1480
|
+
wait.mockReset();
|
|
1481
|
+
wait.mockImplementation(() => null);
|
|
1482
|
+
resolve.mockReset();
|
|
1483
|
+
resolve.mockImplementation(async () => {});
|
|
1484
|
+
for (const mock of scopedMocks) mock.mockReset();
|
|
1485
|
+
clearWorkflowTestEnv();
|
|
1486
|
+
}
|
|
1487
|
+
}, () => {
|
|
1488
|
+
for (const mock of scopedMocks) mock.restore();
|
|
1489
|
+
root.workflow = prev;
|
|
1490
|
+
if (prevEnv !== void 0) writeWorkflowTestEnv(prevEnv);
|
|
1491
|
+
else clearWorkflowTestEnv();
|
|
1492
|
+
});
|
|
1493
|
+
}
|
|
1494
|
+
|
|
1495
|
+
//#endregion
|
|
1496
|
+
//#region src/vitest/workflow-local.ts
|
|
1497
|
+
var PendingStart = class {
|
|
1498
|
+
jobName;
|
|
1499
|
+
args;
|
|
1500
|
+
constructor(jobName, args) {
|
|
1501
|
+
this.jobName = jobName;
|
|
1502
|
+
this.args = args;
|
|
1503
|
+
}
|
|
1504
|
+
};
|
|
1505
|
+
async function runWorkflowLocally(workflow, args, options) {
|
|
1506
|
+
const root = globalThis;
|
|
1507
|
+
const previousTailor = root.tailor;
|
|
1508
|
+
const previousEnv = readWorkflowTestEnv();
|
|
1509
|
+
const hasPreviousEnv = previousEnv !== void 0;
|
|
1510
|
+
const runner = createLocalJobRunner();
|
|
1511
|
+
if (options?.env !== void 0) writeWorkflowTestEnv({ ...options.env });
|
|
1512
|
+
root.tailor = {
|
|
1513
|
+
...previousTailor,
|
|
1514
|
+
workflow: createLocalWorkflowRuntime(previousTailor?.workflow, runner.startJobFunction)
|
|
1515
|
+
};
|
|
1516
|
+
try {
|
|
1517
|
+
return await runner.runJob(workflow.mainJob.name, args);
|
|
1518
|
+
} finally {
|
|
1519
|
+
if (previousTailor) root.tailor = previousTailor;
|
|
1520
|
+
else delete root.tailor;
|
|
1521
|
+
if (options?.env !== void 0) if (hasPreviousEnv) writeWorkflowTestEnv(previousEnv);
|
|
1522
|
+
else clearWorkflowTestEnv();
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
function createLocalJobRunner() {
|
|
1526
|
+
let activeExecution;
|
|
1527
|
+
const startJobFunction = (jobName, args) => {
|
|
1528
|
+
if (!activeExecution) throw new Error(`Cannot start workflow job "${jobName}" outside runWorkflowLocally() job execution.`);
|
|
1529
|
+
if (activeExecution.pending) throw activeExecution.pending;
|
|
1530
|
+
const serializedArgs = platformSerialize(args);
|
|
1531
|
+
const index = activeExecution.cursor;
|
|
1532
|
+
activeExecution.cursor += 1;
|
|
1533
|
+
const cached = activeExecution.records[index];
|
|
1534
|
+
if (cached) {
|
|
1535
|
+
assertSameStart(cached, jobName, serializedArgs);
|
|
1536
|
+
if (cached.status === "rejected") throw cached.error;
|
|
1537
|
+
return platformSerialize(cached.result);
|
|
1538
|
+
}
|
|
1539
|
+
const pending = new PendingStart(jobName, serializedArgs);
|
|
1540
|
+
activeExecution.pending = pending;
|
|
1541
|
+
throw pending;
|
|
1542
|
+
};
|
|
1543
|
+
const runJob = async (name, args) => {
|
|
1544
|
+
const body = getRegisteredJob(name);
|
|
1545
|
+
if (!body) return null;
|
|
1546
|
+
const records = [];
|
|
1547
|
+
for (;;) {
|
|
1548
|
+
const execution = {
|
|
1549
|
+
records,
|
|
1550
|
+
cursor: 0
|
|
1551
|
+
};
|
|
1552
|
+
const previousExecution = activeExecution;
|
|
1553
|
+
activeExecution = execution;
|
|
1554
|
+
try {
|
|
1555
|
+
const out = await body(platformSerialize(args), buildJobContext());
|
|
1556
|
+
if (execution.pending) {
|
|
1557
|
+
await settlePendingStart(records, execution.pending, runJob);
|
|
1558
|
+
continue;
|
|
1559
|
+
}
|
|
1560
|
+
if (execution.cursor !== records.length) throw new Error(`Workflow job start sequence changed while replaying "${name}". Expected ${records.length} start(s), but replay reached ${execution.cursor}.`);
|
|
1561
|
+
return platformSerialize(out);
|
|
1562
|
+
} catch (cause) {
|
|
1563
|
+
const pending = cause instanceof PendingStart ? cause : execution.pending;
|
|
1564
|
+
if (pending) {
|
|
1565
|
+
await settlePendingStart(records, pending, runJob);
|
|
1566
|
+
continue;
|
|
1567
|
+
}
|
|
1568
|
+
throw cause;
|
|
1569
|
+
} finally {
|
|
1570
|
+
activeExecution = previousExecution;
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
};
|
|
1574
|
+
return {
|
|
1575
|
+
runJob,
|
|
1576
|
+
startJobFunction
|
|
1577
|
+
};
|
|
1578
|
+
}
|
|
1579
|
+
async function settlePendingStart(records, pending, runJob) {
|
|
1580
|
+
try {
|
|
1581
|
+
records.push({
|
|
1582
|
+
jobName: pending.jobName,
|
|
1583
|
+
args: pending.args,
|
|
1584
|
+
status: "fulfilled",
|
|
1585
|
+
result: await runJob(pending.jobName, pending.args)
|
|
1586
|
+
});
|
|
1587
|
+
} catch (error) {
|
|
1588
|
+
records.push({
|
|
1589
|
+
jobName: pending.jobName,
|
|
1590
|
+
args: pending.args,
|
|
1591
|
+
status: "rejected",
|
|
1592
|
+
error
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
function assertSameStart(record, jobName, args) {
|
|
1597
|
+
if (record.jobName === jobName && JSON.stringify(record.args) === JSON.stringify(args)) return;
|
|
1598
|
+
throw new Error(`Workflow job start sequence changed while replaying. Expected ${record.jobName}(${JSON.stringify(record.args)}), but got ${jobName}(${JSON.stringify(args)}).`);
|
|
1599
|
+
}
|
|
1600
|
+
function createLocalWorkflowRuntime(previous, execJobFunction) {
|
|
1601
|
+
const startWorkflow = async (name, args, options) => {
|
|
1602
|
+
if (previous) return await previous.startWorkflow(name, args, options);
|
|
1603
|
+
platformSerialize(args);
|
|
1604
|
+
return START_DEFAULT;
|
|
1605
|
+
};
|
|
1606
|
+
const resumeWorkflowExecution = async (executionId) => {
|
|
1607
|
+
if (previous) return await previous.resumeWorkflowExecution(executionId);
|
|
1608
|
+
return executionId;
|
|
1609
|
+
};
|
|
1610
|
+
return {
|
|
1611
|
+
execJobFunction,
|
|
1612
|
+
startJobFunction: execJobFunction,
|
|
1613
|
+
startWorkflow,
|
|
1614
|
+
resumeWorkflowExecution,
|
|
1615
|
+
wait: (key, payload) => {
|
|
1616
|
+
if (previous) return previous.wait(key, payload);
|
|
1617
|
+
throw new Error(`No wait handler for "${key}". Acquire mockWorkflow() and call setWaitHandler(...).`);
|
|
1618
|
+
},
|
|
1619
|
+
resolve: async (executionId, key, callback) => {
|
|
1620
|
+
if (previous) {
|
|
1621
|
+
await previous.resolve(executionId, key, callback);
|
|
1622
|
+
return;
|
|
1623
|
+
}
|
|
1624
|
+
throw new Error("No resolve handler. Acquire mockWorkflow() and call setResolveHandler(...).");
|
|
1625
|
+
}
|
|
1626
|
+
};
|
|
1627
|
+
}
|
|
1628
|
+
|
|
292
1629
|
//#endregion
|
|
293
1630
|
//#region src/vitest/mock-kysely.ts
|
|
294
1631
|
/**
|
|
@@ -479,7 +1816,8 @@ function createKyselyMock() {
|
|
|
479
1816
|
*
|
|
480
1817
|
* 3. **Platform API mocks** (environment) — All platform APIs are auto-injected with
|
|
481
1818
|
* control objects: `mockTailordb`, `mockWorkflow`, `mockSecretmanager`,
|
|
482
|
-
* `mockAuthconnection`, `mockIdp`, `mockFile`, `mockIconv
|
|
1819
|
+
* `mockAuthconnection`, `mockIdp`, `mockFile`, `mockIconv`, `mockAigateway`,
|
|
1820
|
+
* `mockLogger`. Each
|
|
483
1821
|
* provides response configuration, call recording, and reset.
|
|
484
1822
|
*
|
|
485
1823
|
* 4. **Environment resolution** — Rewrites `environment: "tailor-runtime"` to the
|
|
@@ -517,5 +1855,5 @@ function tailorRuntime(options) {
|
|
|
517
1855
|
}
|
|
518
1856
|
|
|
519
1857
|
//#endregion
|
|
520
|
-
export { createKyselyMock, mockAuthconnection, mockFile, mockIconv, mockIdp, mockSecretmanager, mockTailordb, mockWorkflow, tailorRuntime };
|
|
1858
|
+
export { createKyselyMock, mockAigateway, mockAuthconnection, mockFile, mockIconv, mockIdp, mockLogger, mockSecretmanager, mockTailordb, mockWorkflow, runWorkflowLocally, tailorRuntime };
|
|
521
1859
|
//# sourceMappingURL=index.mjs.map
|