@tailor-platform/sdk 2.0.0-next.1 → 2.0.0-next.11
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 +1056 -24
- 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-DqS1yBg3.mjs → application-CM6hKnSK.mjs} +2155 -2008
- package/dist/application-CM6hKnSK.mjs.map +1 -0
- package/dist/application-CXNaUNhv.mjs +3 -0
- package/dist/authconnection-CZvi9ANm.mjs +9 -0
- package/dist/authconnection-CZvi9ANm.mjs.map +1 -0
- package/dist/brand-Eo4pLXPJ.mjs.map +1 -1
- 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 +35 -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 +6 -0
- package/dist/cli/commands/deploy/idp.d.mts +5 -0
- package/dist/cli/commands/deploy/label.d.mts +2 -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 +10 -0
- package/dist/cli/commands/deploy/types.d.mts +4 -0
- package/dist/cli/commands/deploy/workflow-execution-policy.d.mts +2 -0
- package/dist/cli/commands/deploy/workflow.d.mts +4 -0
- package/dist/cli/commands/executor/get.d.mts +19 -0
- package/dist/cli/commands/executor/jobs.d.mts +85 -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 +30 -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 +27 -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/schema-checks.d.mts +5 -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 +62 -0
- package/dist/cli/commands/workflow/get.d.mts +21 -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 +48 -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 -5481
- package/dist/cli/lib.d.mts +86 -21048
- package/dist/cli/lib.mjs +245 -46
- package/dist/cli/lib.mjs.map +1 -1
- package/dist/cli/main.d.mts +23 -0
- package/dist/cli/main.mjs +6777 -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 +4 -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 +3 -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 +1298 -0
- package/dist/cli/shared/config-loader.d.mts +32 -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/tsconfig-paths-plugin.d.mts +2 -0
- package/dist/cli/shared/type-generator.d.mts +20 -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 +1471 -1217
- package/dist/configure/config/index.d.mts +20 -0
- package/dist/configure/config/types.d.mts +134 -0
- package/dist/configure/index.d.mts +135 -8
- package/dist/configure/index.mjs +558 -36
- 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 +514 -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 +3 -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 +92 -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 +66 -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-Bd266-ru.mjs → context-DYQVYWqZ.mjs} +4 -5
- package/dist/context-DYQVYWqZ.mjs.map +1 -0
- package/dist/{crashreport-BsjAkFWw.mjs → crashreport-B5LqCTfF.mjs} +10 -11
- package/dist/{crashreport-BsjAkFWw.mjs.map → crashreport-B5LqCTfF.mjs.map} +1 -1
- package/dist/{crashreport-pr6Rhvza.mjs → crashreport-eI7ty7ok.mjs} +1 -1
- package/dist/{errors-Dtf2WPaW.mjs → errors-D7583Zz7.mjs} +18 -2
- package/dist/errors-D7583Zz7.mjs.map +1 -0
- package/dist/{file-_oUZo76X.mjs → file-BUcmVIH2.mjs} +12 -22
- package/dist/file-BUcmVIH2.mjs.map +1 -0
- package/dist/{globals-Crz8o65k.mjs → globals-TfAVItuK.mjs} +32 -55
- package/dist/globals-TfAVItuK.mjs.map +1 -0
- package/dist/iconv-QWaZh0TT.mjs +38 -0
- package/dist/iconv-QWaZh0TT.mjs.map +1 -0
- package/dist/{idp-BDbK5gjm.mjs → idp-RA_swu-h.mjs} +12 -5
- package/dist/idp-RA_swu-h.mjs.map +1 -0
- package/dist/{interceptor-D-q1rvRl.mjs → interceptor-e33JtsC-.mjs} +2 -2
- package/dist/interceptor-e33JtsC-.mjs.map +1 -0
- package/dist/kysely/index.d.mts +5 -7
- 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/node-builtins-CmaL2Cbq.mjs +36 -0
- package/dist/node-builtins-CmaL2Cbq.mjs.map +1 -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 +115 -2
- package/dist/plugin/builtin/enum-constants/index.mjs.map +1 -0
- package/dist/plugin/builtin/file-utils/index.d.mts +15 -1
- package/dist/plugin/builtin/file-utils/index.mjs +149 -2
- package/dist/plugin/builtin/file-utils/index.mjs.map +1 -0
- package/dist/plugin/builtin/kysely-type/index.d.mts +15 -1
- package/dist/plugin/builtin/kysely-type/index.mjs +274 -2
- package/dist/plugin/builtin/kysely-type/index.mjs.map +1 -0
- package/dist/plugin/builtin/seed/index.d.mts +46 -2
- package/dist/plugin/builtin/seed/index.mjs +1 -1
- package/dist/plugin/builtin/seed/seed-type-processor.d.mts +21 -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 -117
- package/dist/plugin/index.mjs +1 -1
- 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-n9NCkjee.mjs → register-ts-hook-LYV7zH-e.mjs} +9652 -4479
- package/dist/register-ts-hook-LYV7zH-e.mjs.map +1 -0
- package/dist/{registry-DdsYlL_P.mjs → registry-BIGVUrMB.mjs} +12 -9
- package/dist/registry-BIGVUrMB.mjs.map +1 -0
- package/dist/{repl-editor-DmGr9zMw.mjs → repl-editor-BCozyiNq.mjs} +6 -5
- package/dist/{repl-editor-DmGr9zMw.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 -2
- package/dist/runtime/context.d.mts +54 -2
- package/dist/runtime/context.mjs +2 -2
- package/dist/runtime/field-parse.d.mts +10 -0
- package/dist/runtime/file.d.mts +170 -2
- package/dist/runtime/file.mjs +2 -2
- package/dist/runtime/globals.d.mts +38 -20
- package/dist/runtime/iconv.d.mts +73 -2
- package/dist/runtime/iconv.mjs +2 -2
- package/dist/runtime/idp.d.mts +129 -2
- package/dist/runtime/idp.mjs +2 -2
- package/dist/runtime/index.d.mts +48 -9
- package/dist/runtime/index.mjs +10 -8
- 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 -2
- package/dist/runtime/types.d.mts +25 -0
- package/dist/runtime/workflow.d.mts +106 -2
- package/dist/runtime/workflow.mjs +2 -2
- package/dist/{schema-BhkpP5Hw.mjs → schema--xYWRGfe.mjs} +288 -229
- package/dist/schema--xYWRGfe.mjs.map +1 -0
- package/dist/{secret-file-DBqZhjFQ.mjs → secret-file-C3J4Gy8r.mjs} +2 -2
- package/dist/{secret-file-DBqZhjFQ.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-B-yckgQY.mjs +483 -0
- package/dist/seed-B-yckgQY.mjs.map +1 -0
- package/dist/{service-DU1mVzri.mjs → service-B5WynBHQ.mjs} +3 -3
- package/dist/{service-DU1mVzri.mjs.map → service-B5WynBHQ.mjs.map} +1 -1
- package/dist/service-M7OYziQP.mjs +3 -0
- package/dist/service-k1xy_A5G.mjs +864 -0
- package/dist/service-k1xy_A5G.mjs.map +1 -0
- package/dist/service_pb-D5--My_M.mjs +167 -0
- package/dist/service_pb-D5--My_M.mjs.map +1 -0
- package/dist/service_pb-i8CmnQP4.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 +420 -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 +586 -0
- package/dist/tailor-proto/src/tailor/v1/function_pb.d.mts +192 -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 +3658 -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 +207 -0
- package/dist/tailor-proto/src/tailor/v1/workflow_pb.d.mts +961 -0
- package/dist/tailor-proto/src/tailor/v1/workflow_resource_pb.d.mts +330 -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-CdqJEzkj.mjs → telemetry-BRVdwh14.mjs} +3 -3
- 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/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 +229 -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 +5 -100
- package/dist/utils/test/index.mjs +38 -189
- package/dist/utils/test/index.mjs.map +1 -1
- package/dist/vitest/environment.d.mts +1 -2
- package/dist/vitest/environment.mjs +2 -2
- package/dist/vitest/environment.mjs.map +1 -1
- package/dist/vitest/index.d.mts +17 -431
- package/dist/vitest/index.mjs +1234 -67
- 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 +148 -0
- package/dist/vitest/setup.d.mts +1 -2
- package/dist/vitest/setup.mjs +2 -2
- package/dist/vitest/workflow-local.d.mts +41 -0
- package/dist/workflow-Bamae_Yc.mjs +34 -0
- package/dist/workflow-Bamae_Yc.mjs.map +1 -0
- package/dist/{client-z_oHGVNy.mjs → workspace_resource_pb-DXnO2AT-.mjs} +57 -621
- package/dist/workspace_resource_pb-DXnO2AT-.mjs.map +1 -0
- package/docs/cli/application.md +150 -250
- package/docs/cli/auth.md +51 -295
- package/docs/cli/completion.md +1 -25
- package/docs/cli/crashreport.md +3 -61
- package/docs/cli/executor.md +72 -183
- package/docs/cli/function.md +16 -132
- 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 +89 -413
- 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 +214 -96
- package/docs/configuration.md +90 -6
- package/docs/github-actions.md +72 -24
- package/docs/migration/v2.md +1613 -0
- package/docs/multi-environment.md +29 -7
- package/docs/plugin/custom.md +4 -4
- package/docs/plugin/index.md +8 -8
- package/docs/quickstart.md +8 -7
- package/docs/runtime.md +18 -9
- package/docs/services/aigateway.md +20 -2
- package/docs/services/auth.md +51 -59
- package/docs/services/executor.md +91 -6
- package/docs/services/http-adapter.md +16 -1
- package/docs/services/idp.md +62 -7
- package/docs/services/resolver.md +67 -11
- package/docs/services/secret.md +11 -11
- package/docs/services/staticwebsite.md +8 -2
- package/docs/services/tailordb-migration.md +55 -29
- package/docs/services/tailordb.md +205 -102
- package/docs/services/workflow.md +163 -55
- package/docs/testing.md +244 -143
- package/package.json +61 -46
- package/postinstall.mjs +4 -6
- package/dist/application-DB2r36Et.mjs +0 -3
- package/dist/application-DqS1yBg3.mjs.map +0 -1
- package/dist/authconnection-D2MhtTN5.mjs +0 -15
- package/dist/authconnection-D2MhtTN5.mjs.map +0 -1
- package/dist/authconnection-DvUQAjQS.d.mts +0 -39
- 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/client-Dbohmtkv.mjs +0 -3
- package/dist/client-z_oHGVNy.mjs.map +0 -1
- package/dist/context-Bd266-ru.mjs.map +0 -1
- package/dist/context-BuuIb8CC.d.mts +0 -68
- package/dist/enum-constants-j9QBF0cB.mjs +0 -116
- package/dist/enum-constants-j9QBF0cB.mjs.map +0 -1
- package/dist/errors-Dtf2WPaW.mjs.map +0 -1
- package/dist/field-DOsJCPFa.mjs +0 -22
- package/dist/field-DOsJCPFa.mjs.map +0 -1
- package/dist/file-BB8Vs9O_.d.mts +0 -250
- package/dist/file-_oUZo76X.mjs.map +0 -1
- package/dist/file-utils-DcyIPFQh.mjs +0 -150
- package/dist/file-utils-DcyIPFQh.mjs.map +0 -1
- package/dist/globals-Crz8o65k.mjs.map +0 -1
- package/dist/http-adapter.generated-WgMnb7Sb.d.mts +0 -580
- package/dist/iconv-Co-TOPuH.d.mts +0 -122
- package/dist/iconv-D2vi8G36.mjs +0 -63
- package/dist/iconv-D2vi8G36.mjs.map +0 -1
- package/dist/idp-BDbK5gjm.mjs.map +0 -1
- package/dist/idp-DrhVrLmV.d.mts +0 -160
- package/dist/index-5vPyRu1y.d.mts +0 -18
- package/dist/index-B7AKc18V.d.mts +0 -47
- package/dist/index-BlpzXncY.d.mts +0 -1016
- package/dist/index-CK7u9isy.d.mts +0 -46
- package/dist/index-CNYe5lnW.d.mts +0 -18
- package/dist/index-DjUdWlzf.d.mts +0 -18
- package/dist/index-ZePLwxw7.d.mts +0 -208
- package/dist/interceptor-D-q1rvRl.mjs.map +0 -1
- package/dist/job-fuc3j1Ma.mjs +0 -53
- package/dist/job-fuc3j1Ma.mjs.map +0 -1
- package/dist/kysely-type-DR8uzZTA.mjs +0 -274
- package/dist/kysely-type-DR8uzZTA.mjs.map +0 -1
- package/dist/logger-CxF-Ex5d.mjs +0 -220
- package/dist/logger-CxF-Ex5d.mjs.map +0 -1
- package/dist/mock-BjFj5o1I.mjs +0 -804
- package/dist/mock-BjFj5o1I.mjs.map +0 -1
- package/dist/registry-DdsYlL_P.mjs.map +0 -1
- package/dist/rolldown-runtime-DXywRVcq.mjs +0 -20
- package/dist/runtime-n9NCkjee.mjs.map +0 -1
- package/dist/schema-BhkpP5Hw.mjs.map +0 -1
- package/dist/secretmanager-B3n4KHfm.d.mts +0 -55
- package/dist/secretmanager-BVxw3ih_.mjs +0 -24
- package/dist/secretmanager-BVxw3ih_.mjs.map +0 -1
- package/dist/seed-jf3008-h.mjs +0 -1160
- package/dist/seed-jf3008-h.mjs.map +0 -1
- package/dist/service-CCL8ruDf.mjs +0 -459
- package/dist/service-CCL8ruDf.mjs.map +0 -1
- package/dist/service-D6yonf2I.mjs +0 -3
- package/dist/telemetry-CdqJEzkj.mjs.map +0 -1
- package/dist/telemetry-ClwW5ohF.mjs +0 -3
- package/dist/test-env-key-D9kM6ETE.mjs +0 -49
- package/dist/test-env-key-D9kM6ETE.mjs.map +0 -1
- package/dist/types-B2RpYyA_.mjs +0 -371
- package/dist/types-B2RpYyA_.mjs.map +0 -1
- package/dist/types-ClhIrW_C.mjs +0 -4
- package/dist/types-DCUhgpyI.d.mts +0 -784
- package/dist/types-DhO_VEZd.d.mts +0 -574
- package/dist/types-DwDgacni.d.mts +0 -338
- package/dist/workflow-BbKvGLQg.d.mts +0 -96
- package/dist/workflow-DgemCAz3.mjs +0 -38
- package/dist/workflow-DgemCAz3.mjs.map +0 -1
- package/dist/workflow.generated-DtQwEo-x.d.mts +0 -671
package/dist/vitest/index.mjs
CHANGED
|
@@ -1,50 +1,23 @@
|
|
|
1
|
-
import { i as getRegisteredJob, t as
|
|
2
|
-
import { a as writeWorkflowTestEnv,
|
|
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
3
|
import { t as assertDefined } from "../assert-DBxo8jPo.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { n as isNodeBuiltinImport, t as getNodeBuiltinMessage } from "../node-builtins-CmaL2Cbq.mjs";
|
|
5
|
+
import { t as platformSerialize } from "../platform-serialize-RoRtBS0v.mjs";
|
|
6
|
+
import { i as withDispose, n as tailorRoot, r as tailordbRoot, t as mockSecretmanager } from "../secretmanager-IY4UvinW.mjs";
|
|
7
|
+
import { isEqual } from "es-toolkit";
|
|
7
8
|
import { fileURLToPath } from "node:url";
|
|
8
|
-
import { dirname, isAbsolute, matchesGlob, relative, resolve } from "node:path";
|
|
9
9
|
import { ColumnNode, InsertQueryNode, Kysely, PostgresAdapter, PostgresIntrospector, PostgresQueryCompiler, PrimitiveValueListNode, ReferenceNode, UpdateQueryNode, ValueListNode, ValueNode, ValuesNode } from "kysely";
|
|
10
|
+
import { dirname, isAbsolute, matchesGlob, relative, resolve } from "node:path";
|
|
11
|
+
import { vi } from "vitest";
|
|
10
12
|
|
|
11
13
|
//#region src/vitest/blocked-modules.ts
|
|
12
14
|
/**
|
|
13
|
-
* Blocked Node.js built-in modules and their Web Standard API alternatives.
|
|
14
|
-
*
|
|
15
|
-
* The Tailor Platform runtime only provides Web Standard APIs.
|
|
16
|
-
* These Node.js modules are not available and should be replaced with
|
|
17
|
-
* the suggested alternatives.
|
|
18
|
-
*/
|
|
19
|
-
const SUGGESTIONS = {
|
|
20
|
-
crypto: "Use the Web Crypto API (globalThis.crypto) instead.",
|
|
21
|
-
buffer: "Use Uint8Array or ArrayBuffer instead.",
|
|
22
|
-
fs: "File system access is not available in the Tailor Platform runtime.",
|
|
23
|
-
"fs/promises": "File system access is not available in the Tailor Platform runtime.",
|
|
24
|
-
path: "Use URL or URLPattern for path manipulation.",
|
|
25
|
-
http: "Use the Fetch API (globalThis.fetch) for HTTP requests instead.",
|
|
26
|
-
https: "Use the Fetch API (globalThis.fetch) for HTTPS requests instead.",
|
|
27
|
-
url: "Use the URL and URLSearchParams Web APIs instead.",
|
|
28
|
-
util: "Use Web Standard APIs instead.",
|
|
29
|
-
stream: "Use Web Streams API (ReadableStream, WritableStream, TransformStream) instead.",
|
|
30
|
-
"stream/web": "Use Web Streams API (ReadableStream, WritableStream, TransformStream) instead.",
|
|
31
|
-
events: "Use EventTarget instead.",
|
|
32
|
-
zlib: "Use CompressionStream and DecompressionStream Web APIs instead.",
|
|
33
|
-
querystring: "Use URLSearchParams instead.",
|
|
34
|
-
string_decoder: "Use TextDecoder instead."
|
|
35
|
-
};
|
|
36
|
-
const BLOCKED_MODULES = /* @__PURE__ */ new Set();
|
|
37
|
-
for (const mod of builtinModules) {
|
|
38
|
-
BLOCKED_MODULES.add(mod);
|
|
39
|
-
BLOCKED_MODULES.add(`node:${mod}`);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
15
|
* Check if a module specifier is a blocked Node.js built-in.
|
|
43
16
|
* @param specifier - Module specifier to check (e.g. "node:crypto", "fs")
|
|
44
17
|
* @returns Whether the specifier is blocked
|
|
45
18
|
*/
|
|
46
19
|
function isBlockedModule(specifier) {
|
|
47
|
-
return
|
|
20
|
+
return isNodeBuiltinImport(specifier);
|
|
48
21
|
}
|
|
49
22
|
/**
|
|
50
23
|
* Get the error message for a blocked module import.
|
|
@@ -52,20 +25,18 @@ function isBlockedModule(specifier) {
|
|
|
52
25
|
* @returns Error message with optional suggestion for the Web Standard API alternative
|
|
53
26
|
*/
|
|
54
27
|
function getBlockedMessage(specifier) {
|
|
55
|
-
|
|
56
|
-
const base = `"${specifier}" is not available in the Tailor Platform runtime.`;
|
|
57
|
-
return suggestion ? `${base} ${suggestion}` : base;
|
|
28
|
+
return getNodeBuiltinMessage(specifier);
|
|
58
29
|
}
|
|
59
30
|
|
|
60
31
|
//#endregion
|
|
61
32
|
//#region src/vitest/plugin.ts
|
|
62
33
|
const DEFAULT_TEST_INCLUDE = ["**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"];
|
|
63
|
-
const IMPORT_LIKE_TYPES = new Set([
|
|
34
|
+
const IMPORT_LIKE_TYPES = /* @__PURE__ */ new Set([
|
|
64
35
|
"ImportDeclaration",
|
|
65
36
|
"ExportNamedDeclaration",
|
|
66
37
|
"ExportAllDeclaration"
|
|
67
38
|
]);
|
|
68
|
-
const UNSAFE_BINDING_NAMES = new Set([
|
|
39
|
+
const UNSAFE_BINDING_NAMES = /* @__PURE__ */ new Set([
|
|
69
40
|
"break",
|
|
70
41
|
"case",
|
|
71
42
|
"catch",
|
|
@@ -185,7 +156,7 @@ function createBlockPlugin() {
|
|
|
185
156
|
const testConfig = config.test;
|
|
186
157
|
const root = testConfig?.root ?? config.root;
|
|
187
158
|
const toAbsolutePaths = (value, baseRoot) => (Array.isArray(value) ? value : value ? [value] : []).map((f) => resolve(baseRoot, f));
|
|
188
|
-
const exemptHostFiles = new Set([...toAbsolutePaths(testConfig?.setupFiles, root), ...toAbsolutePaths(testConfig?.globalSetup, root)]);
|
|
159
|
+
const exemptHostFiles = /* @__PURE__ */ new Set([...toAbsolutePaths(testConfig?.setupFiles, root), ...toAbsolutePaths(testConfig?.globalSetup, root)]);
|
|
189
160
|
const includePairs = [{
|
|
190
161
|
root,
|
|
191
162
|
patterns: testConfig?.include ?? DEFAULT_TEST_INCLUDE
|
|
@@ -291,9 +262,1198 @@ function createEnvironmentPlugin(options) {
|
|
|
291
262
|
};
|
|
292
263
|
}
|
|
293
264
|
|
|
265
|
+
//#endregion
|
|
266
|
+
//#region src/vitest/mocks/aigateway.ts
|
|
267
|
+
/**
|
|
268
|
+
* Acquire a disposable mock for `tailor.aigateway`. Restored on dispose.
|
|
269
|
+
* @param options - Initial AI Gateway URL fixtures
|
|
270
|
+
* @returns Disposable AI Gateway mock control object
|
|
271
|
+
* @example
|
|
272
|
+
* ```typescript
|
|
273
|
+
* import { mockAigateway } from "@tailor-platform/sdk/vitest";
|
|
274
|
+
*
|
|
275
|
+
* test("resolves an AI Gateway URL", async () => {
|
|
276
|
+
* using aigateway = mockAigateway({
|
|
277
|
+
* urls: { "my-aigateway": "https://my-aigateway.example.com" },
|
|
278
|
+
* });
|
|
279
|
+
* aigateway.setUrl("my-aigateway", "https://replacement.example.com");
|
|
280
|
+
* // …
|
|
281
|
+
* });
|
|
282
|
+
* ```
|
|
283
|
+
*/
|
|
284
|
+
function mockAigateway(options = {}) {
|
|
285
|
+
const root = tailorRoot();
|
|
286
|
+
const prev = root.aigateway;
|
|
287
|
+
let urls = { ...options.urls };
|
|
288
|
+
async function defaultGet(name) {
|
|
289
|
+
const url = urls[name];
|
|
290
|
+
if (url === void 0) throw new Error(`No AI Gateway registered for "${name}". Acquire mockAigateway() and call setUrls(...).`);
|
|
291
|
+
return { url };
|
|
292
|
+
}
|
|
293
|
+
const get = vi.fn(defaultGet);
|
|
294
|
+
root.aigateway = { get };
|
|
295
|
+
return withDispose({
|
|
296
|
+
/** The `get` `vi.fn`. */
|
|
297
|
+
get,
|
|
298
|
+
setUrls(value) {
|
|
299
|
+
urls = value;
|
|
300
|
+
},
|
|
301
|
+
setUrl(name, url) {
|
|
302
|
+
urls = {
|
|
303
|
+
...urls,
|
|
304
|
+
[name]: url
|
|
305
|
+
};
|
|
306
|
+
},
|
|
307
|
+
get calls() {
|
|
308
|
+
return get.mock.calls.map(([name]) => ({ name }));
|
|
309
|
+
},
|
|
310
|
+
clear() {
|
|
311
|
+
get.mockClear();
|
|
312
|
+
},
|
|
313
|
+
reset() {
|
|
314
|
+
urls = {};
|
|
315
|
+
get.mockReset();
|
|
316
|
+
get.mockImplementation(defaultGet);
|
|
317
|
+
}
|
|
318
|
+
}, () => {
|
|
319
|
+
root.aigateway = prev;
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
//#endregion
|
|
324
|
+
//#region src/vitest/mocks/authconnection.ts
|
|
325
|
+
/**
|
|
326
|
+
* Acquire a disposable mock for `tailor.authconnection`. Restored on dispose.
|
|
327
|
+
* @param options - Initial token fixtures and fallback behavior
|
|
328
|
+
* @returns Disposable AuthConnection mock control object
|
|
329
|
+
* @example
|
|
330
|
+
* ```typescript
|
|
331
|
+
* import { mockAuthconnection } from "@tailor-platform/sdk/vitest";
|
|
332
|
+
*
|
|
333
|
+
* test("returns configured token", async () => {
|
|
334
|
+
* using ac = mockAuthconnection({ tokens: { google: { access_token: "ya29.xxx" } } });
|
|
335
|
+
* ac.setToken("google", { access_token: "replacement" });
|
|
336
|
+
* // …
|
|
337
|
+
* });
|
|
338
|
+
* ```
|
|
339
|
+
*/
|
|
340
|
+
function mockAuthconnection(options = {}) {
|
|
341
|
+
const root = tailorRoot();
|
|
342
|
+
const prev = root.authconnection;
|
|
343
|
+
let tokens = { ...options.tokens };
|
|
344
|
+
async function defaultGetConnectionToken(connectionName) {
|
|
345
|
+
const token = tokens[connectionName];
|
|
346
|
+
if (token) return token;
|
|
347
|
+
if (options.onUnhandled === "error") throw new Error(`No AuthConnection token configured for "${connectionName}"`);
|
|
348
|
+
return { access_token: "mock-token" };
|
|
349
|
+
}
|
|
350
|
+
const getConnectionToken = vi.fn(defaultGetConnectionToken);
|
|
351
|
+
root.authconnection = { getConnectionToken };
|
|
352
|
+
return withDispose({
|
|
353
|
+
/** The `getConnectionToken` `vi.fn`. */
|
|
354
|
+
getConnectionToken,
|
|
355
|
+
setTokens(value) {
|
|
356
|
+
tokens = value;
|
|
357
|
+
},
|
|
358
|
+
setToken(connectionName, token) {
|
|
359
|
+
tokens = {
|
|
360
|
+
...tokens,
|
|
361
|
+
[connectionName]: token
|
|
362
|
+
};
|
|
363
|
+
},
|
|
364
|
+
get calls() {
|
|
365
|
+
return getConnectionToken.mock.calls.map(([connectionName]) => ({ connectionName }));
|
|
366
|
+
},
|
|
367
|
+
clear() {
|
|
368
|
+
getConnectionToken.mockClear();
|
|
369
|
+
},
|
|
370
|
+
reset() {
|
|
371
|
+
tokens = {};
|
|
372
|
+
getConnectionToken.mockReset();
|
|
373
|
+
getConnectionToken.mockImplementation(defaultGetConnectionToken);
|
|
374
|
+
}
|
|
375
|
+
}, () => {
|
|
376
|
+
root.authconnection = prev;
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region src/vitest/mocks/file.ts
|
|
382
|
+
const FILE_METHODS = [
|
|
383
|
+
"upload",
|
|
384
|
+
"download",
|
|
385
|
+
"downloadAsBase64",
|
|
386
|
+
"delete",
|
|
387
|
+
"getMetadata",
|
|
388
|
+
"downloadStream",
|
|
389
|
+
"uploadStream"
|
|
390
|
+
];
|
|
391
|
+
const FILE_DEFAULTS = {
|
|
392
|
+
upload: { metadata: {
|
|
393
|
+
fileSize: 0,
|
|
394
|
+
sha256sum: ""
|
|
395
|
+
} },
|
|
396
|
+
download: {
|
|
397
|
+
data: /* @__PURE__ */ new Uint8Array(),
|
|
398
|
+
metadata: {
|
|
399
|
+
contentType: "",
|
|
400
|
+
fileSize: 0,
|
|
401
|
+
sha256sum: "",
|
|
402
|
+
lastUploadedAt: ""
|
|
403
|
+
}
|
|
404
|
+
},
|
|
405
|
+
downloadAsBase64: {
|
|
406
|
+
data: "",
|
|
407
|
+
metadata: {
|
|
408
|
+
contentType: "",
|
|
409
|
+
fileSize: 0,
|
|
410
|
+
sha256sum: "",
|
|
411
|
+
lastUploadedAt: ""
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
getMetadata: {
|
|
415
|
+
contentType: "",
|
|
416
|
+
fileSize: 0,
|
|
417
|
+
sha256sum: "",
|
|
418
|
+
urlPath: ""
|
|
419
|
+
},
|
|
420
|
+
downloadStream: null,
|
|
421
|
+
uploadStream: { metadata: {
|
|
422
|
+
fileSize: 0,
|
|
423
|
+
sha256sum: ""
|
|
424
|
+
} }
|
|
425
|
+
};
|
|
426
|
+
/**
|
|
427
|
+
* Acquire a disposable mock for `tailordb.file`. Restored on dispose.
|
|
428
|
+
* @param options - Controls behavior for calls without a configured result
|
|
429
|
+
* @returns Disposable File mock control object
|
|
430
|
+
* @example
|
|
431
|
+
* ```typescript
|
|
432
|
+
* import { mockFile } from "@tailor-platform/sdk/vitest";
|
|
433
|
+
*
|
|
434
|
+
* test("mock file download", async () => {
|
|
435
|
+
* using file = mockFile();
|
|
436
|
+
* file.download.mockResolvedValue({ data: new Uint8Array(), metadata: { ... } });
|
|
437
|
+
* // …
|
|
438
|
+
* });
|
|
439
|
+
* ```
|
|
440
|
+
*/
|
|
441
|
+
function mockFile(options = {}) {
|
|
442
|
+
const root = tailordbRoot();
|
|
443
|
+
const prev = root.file;
|
|
444
|
+
const { onUnhandled = "fallback" } = options;
|
|
445
|
+
const queue = [];
|
|
446
|
+
const calls = [];
|
|
447
|
+
let resolver = () => null;
|
|
448
|
+
function handle(method, namespace, typeName, fieldName, recordId) {
|
|
449
|
+
if (queue.length > 0) return queue.shift();
|
|
450
|
+
const resolved = resolver(method, {
|
|
451
|
+
method,
|
|
452
|
+
namespace,
|
|
453
|
+
typeName,
|
|
454
|
+
fieldName,
|
|
455
|
+
recordId
|
|
456
|
+
});
|
|
457
|
+
if (resolved != null) return resolved;
|
|
458
|
+
if (onUnhandled === "error") throw new Error(`No File mock configured for "${method}"`);
|
|
459
|
+
const fallback = FILE_DEFAULTS[method];
|
|
460
|
+
return fallback === void 0 ? void 0 : structuredClone(fallback);
|
|
461
|
+
}
|
|
462
|
+
const upload = vi.fn(async (...args) => {
|
|
463
|
+
const [namespace, typeName, fieldName, recordId] = args;
|
|
464
|
+
return handle("upload", namespace, typeName, fieldName, recordId);
|
|
465
|
+
});
|
|
466
|
+
const download = vi.fn(async (...args) => handle("download", ...args));
|
|
467
|
+
const downloadAsBase64 = vi.fn(async (...args) => handle("downloadAsBase64", ...args));
|
|
468
|
+
const deleteFile = vi.fn(async (...args) => {
|
|
469
|
+
handle("delete", ...args);
|
|
470
|
+
});
|
|
471
|
+
const getMetadata = vi.fn(async (...args) => handle("getMetadata", ...args));
|
|
472
|
+
const downloadStream = vi.fn(async (...args) => {
|
|
473
|
+
const resolved = handle("downloadStream", ...args);
|
|
474
|
+
if (resolved != null) return resolved;
|
|
475
|
+
return {
|
|
476
|
+
body: new ReadableStream({ start(controller) {
|
|
477
|
+
controller.close();
|
|
478
|
+
} }),
|
|
479
|
+
metadata: {
|
|
480
|
+
contentType: "",
|
|
481
|
+
fileSize: 0,
|
|
482
|
+
sha256sum: "",
|
|
483
|
+
lastUploadedAt: ""
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
});
|
|
487
|
+
const uploadStream = vi.fn(async (...args) => {
|
|
488
|
+
const [namespace, typeName, fieldName, recordId] = args;
|
|
489
|
+
return handle("uploadStream", namespace, typeName, fieldName, recordId);
|
|
490
|
+
});
|
|
491
|
+
const mocks = {
|
|
492
|
+
upload,
|
|
493
|
+
download,
|
|
494
|
+
downloadAsBase64,
|
|
495
|
+
delete: deleteFile,
|
|
496
|
+
getMetadata,
|
|
497
|
+
downloadStream,
|
|
498
|
+
uploadStream
|
|
499
|
+
};
|
|
500
|
+
function track(method, operation) {
|
|
501
|
+
return function(...args) {
|
|
502
|
+
calls.push({
|
|
503
|
+
method,
|
|
504
|
+
namespace: args[0],
|
|
505
|
+
typeName: args[1],
|
|
506
|
+
fieldName: args[2],
|
|
507
|
+
recordId: args[3]
|
|
508
|
+
});
|
|
509
|
+
return operation.apply(this, args);
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
root.file = {
|
|
513
|
+
upload: track("upload", upload),
|
|
514
|
+
download: track("download", download),
|
|
515
|
+
downloadAsBase64: track("downloadAsBase64", downloadAsBase64),
|
|
516
|
+
delete: track("delete", deleteFile),
|
|
517
|
+
getMetadata: track("getMetadata", getMetadata),
|
|
518
|
+
downloadStream: track("downloadStream", downloadStream),
|
|
519
|
+
uploadStream: track("uploadStream", uploadStream)
|
|
520
|
+
};
|
|
521
|
+
function allMocks() {
|
|
522
|
+
return FILE_METHODS.map((method) => mocks[method]);
|
|
523
|
+
}
|
|
524
|
+
return withDispose({
|
|
525
|
+
...mocks,
|
|
526
|
+
setResolver(value) {
|
|
527
|
+
resolver = value;
|
|
528
|
+
},
|
|
529
|
+
/**
|
|
530
|
+
* Enqueue a single result for the next `tailordb.file` call.
|
|
531
|
+
* The queue is shared across all methods and namespaces.
|
|
532
|
+
* @param result - Result to return from the next file call
|
|
533
|
+
*/
|
|
534
|
+
enqueueResult(result) {
|
|
535
|
+
queue.push(result);
|
|
536
|
+
},
|
|
537
|
+
/**
|
|
538
|
+
* Enqueue results for multiple subsequent `tailordb.file` calls.
|
|
539
|
+
* The queue is shared across all methods and namespaces.
|
|
540
|
+
* @param results - Results to enqueue, one per upcoming call
|
|
541
|
+
*/
|
|
542
|
+
enqueueResults(...results) {
|
|
543
|
+
queue.push(...results);
|
|
544
|
+
},
|
|
545
|
+
get calls() {
|
|
546
|
+
return calls;
|
|
547
|
+
},
|
|
548
|
+
clear() {
|
|
549
|
+
calls.length = 0;
|
|
550
|
+
for (const mock of allMocks()) mock.mockClear();
|
|
551
|
+
},
|
|
552
|
+
reset() {
|
|
553
|
+
queue.length = 0;
|
|
554
|
+
calls.length = 0;
|
|
555
|
+
resolver = () => null;
|
|
556
|
+
for (const mock of allMocks()) mock.mockReset();
|
|
557
|
+
}
|
|
558
|
+
}, () => {
|
|
559
|
+
root.file = prev;
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
//#endregion
|
|
564
|
+
//#region src/vitest/mocks/iconv.ts
|
|
565
|
+
function isUtf8(encoding) {
|
|
566
|
+
return encoding === "UTF8" || encoding === "UTF-8";
|
|
567
|
+
}
|
|
568
|
+
function defaultIconvResult(method, args) {
|
|
569
|
+
switch (method) {
|
|
570
|
+
case "convert":
|
|
571
|
+
case "convertBuffer": return isUtf8(args[2]) ? "" : /* @__PURE__ */ new Uint8Array();
|
|
572
|
+
case "decode": return "";
|
|
573
|
+
case "encode": return isUtf8(args[1]) ? "" : /* @__PURE__ */ new Uint8Array();
|
|
574
|
+
case "encodings": return [];
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Acquire a disposable mock for `tailor.iconv`. Restored on dispose.
|
|
579
|
+
* @param options - Fallback behavior for unconfigured operations
|
|
580
|
+
* @returns Disposable Iconv mock control object
|
|
581
|
+
* @example
|
|
582
|
+
* ```typescript
|
|
583
|
+
* import { mockIconv } from "@tailor-platform/sdk/vitest";
|
|
584
|
+
*
|
|
585
|
+
* test("mock encoding conversion", () => {
|
|
586
|
+
* using iconv = mockIconv();
|
|
587
|
+
* iconv.decode.mockReturnValue("decoded-text");
|
|
588
|
+
* // …
|
|
589
|
+
* });
|
|
590
|
+
* ```
|
|
591
|
+
*/
|
|
592
|
+
function mockIconv(options = {}) {
|
|
593
|
+
const root = tailorRoot();
|
|
594
|
+
const prev = root.iconv;
|
|
595
|
+
let resolver = null;
|
|
596
|
+
const calls = [];
|
|
597
|
+
function resolve(method, args) {
|
|
598
|
+
if (resolver) {
|
|
599
|
+
const result = resolver(method, args);
|
|
600
|
+
if (result != null) return result;
|
|
601
|
+
}
|
|
602
|
+
if (options.onUnhandled === "error") throw new Error(`No Iconv mock behavior configured for "${method}"`);
|
|
603
|
+
return defaultIconvResult(method, args);
|
|
604
|
+
}
|
|
605
|
+
function defaultConvert(input, fromEncoding, toEncoding) {
|
|
606
|
+
return resolve("convert", [
|
|
607
|
+
input,
|
|
608
|
+
fromEncoding,
|
|
609
|
+
toEncoding
|
|
610
|
+
]);
|
|
611
|
+
}
|
|
612
|
+
function defaultConvertBuffer(input, fromEncoding, toEncoding) {
|
|
613
|
+
return resolve("convertBuffer", [
|
|
614
|
+
input,
|
|
615
|
+
fromEncoding,
|
|
616
|
+
toEncoding
|
|
617
|
+
]);
|
|
618
|
+
}
|
|
619
|
+
function defaultDecode(input, encoding) {
|
|
620
|
+
return resolve("decode", [input, encoding]);
|
|
621
|
+
}
|
|
622
|
+
function defaultEncode(input, encoding) {
|
|
623
|
+
return resolve("encode", [input, encoding]);
|
|
624
|
+
}
|
|
625
|
+
function defaultEncodings() {
|
|
626
|
+
return resolve("encodings", []);
|
|
627
|
+
}
|
|
628
|
+
const convert = vi.fn(defaultConvert);
|
|
629
|
+
const convertBuffer = vi.fn(defaultConvertBuffer);
|
|
630
|
+
const decode = vi.fn(defaultDecode);
|
|
631
|
+
const encode = vi.fn(defaultEncode);
|
|
632
|
+
const encodings = vi.fn(defaultEncodings);
|
|
633
|
+
function track(method, operation) {
|
|
634
|
+
return function(...args) {
|
|
635
|
+
calls.push({
|
|
636
|
+
method,
|
|
637
|
+
args: [...args]
|
|
638
|
+
});
|
|
639
|
+
return operation.apply(this, args);
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
const trackedConvert = track("convert", convert);
|
|
643
|
+
const trackedConvertBuffer = track("convertBuffer", convertBuffer);
|
|
644
|
+
const trackedDecode = track("decode", decode);
|
|
645
|
+
const trackedEncode = track("encode", encode);
|
|
646
|
+
const trackedEncodings = track("encodings", encodings);
|
|
647
|
+
class MockIconv {
|
|
648
|
+
#fromEncoding;
|
|
649
|
+
#toEncoding;
|
|
650
|
+
constructor(fromEncoding, toEncoding) {
|
|
651
|
+
this.#fromEncoding = fromEncoding;
|
|
652
|
+
this.#toEncoding = toEncoding;
|
|
653
|
+
}
|
|
654
|
+
convert(input) {
|
|
655
|
+
return trackedConvert.call(this, input, this.#fromEncoding, this.#toEncoding);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
root.iconv = {
|
|
659
|
+
convert: trackedConvert,
|
|
660
|
+
convertBuffer: trackedConvertBuffer,
|
|
661
|
+
decode: trackedDecode,
|
|
662
|
+
encode: trackedEncode,
|
|
663
|
+
encodings: trackedEncodings,
|
|
664
|
+
Iconv: MockIconv
|
|
665
|
+
};
|
|
666
|
+
function clear() {
|
|
667
|
+
calls.length = 0;
|
|
668
|
+
convert.mockClear();
|
|
669
|
+
convertBuffer.mockClear();
|
|
670
|
+
decode.mockClear();
|
|
671
|
+
encode.mockClear();
|
|
672
|
+
encodings.mockClear();
|
|
673
|
+
}
|
|
674
|
+
return withDispose({
|
|
675
|
+
/** The `convert` `vi.fn`. */
|
|
676
|
+
convert,
|
|
677
|
+
/** The `convertBuffer` `vi.fn`. */
|
|
678
|
+
convertBuffer,
|
|
679
|
+
/** The `decode` `vi.fn`. */
|
|
680
|
+
decode,
|
|
681
|
+
/** The `encode` `vi.fn`. */
|
|
682
|
+
encode,
|
|
683
|
+
/** The `encodings` `vi.fn`. */
|
|
684
|
+
encodings,
|
|
685
|
+
setResolver(value) {
|
|
686
|
+
resolver = value;
|
|
687
|
+
},
|
|
688
|
+
get calls() {
|
|
689
|
+
return calls;
|
|
690
|
+
},
|
|
691
|
+
clear,
|
|
692
|
+
reset() {
|
|
693
|
+
resolver = null;
|
|
694
|
+
calls.length = 0;
|
|
695
|
+
convert.mockReset();
|
|
696
|
+
convert.mockImplementation(defaultConvert);
|
|
697
|
+
convertBuffer.mockReset();
|
|
698
|
+
convertBuffer.mockImplementation(defaultConvertBuffer);
|
|
699
|
+
decode.mockReset();
|
|
700
|
+
decode.mockImplementation(defaultDecode);
|
|
701
|
+
encode.mockReset();
|
|
702
|
+
encode.mockImplementation(defaultEncode);
|
|
703
|
+
encodings.mockReset();
|
|
704
|
+
encodings.mockImplementation(defaultEncodings);
|
|
705
|
+
}
|
|
706
|
+
}, () => {
|
|
707
|
+
root.iconv = prev;
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
//#endregion
|
|
712
|
+
//#region src/vitest/mocks/idp.ts
|
|
713
|
+
const IDP_METHODS = [
|
|
714
|
+
"users",
|
|
715
|
+
"user",
|
|
716
|
+
"userByName",
|
|
717
|
+
"createUser",
|
|
718
|
+
"updateUser",
|
|
719
|
+
"deleteUser",
|
|
720
|
+
"sendPasswordResetEmail",
|
|
721
|
+
"unenrollMfa"
|
|
722
|
+
];
|
|
723
|
+
const IDP_USER_DEFAULT = {
|
|
724
|
+
id: "mock-id",
|
|
725
|
+
name: "mock-user",
|
|
726
|
+
disabled: false,
|
|
727
|
+
mfaEnrolled: false,
|
|
728
|
+
mfaFactorIds: []
|
|
729
|
+
};
|
|
730
|
+
const IDP_DEFAULTS = {
|
|
731
|
+
users: {
|
|
732
|
+
users: [],
|
|
733
|
+
nextPageToken: null,
|
|
734
|
+
totalCount: 0
|
|
735
|
+
},
|
|
736
|
+
user: IDP_USER_DEFAULT,
|
|
737
|
+
userByName: IDP_USER_DEFAULT,
|
|
738
|
+
createUser: IDP_USER_DEFAULT,
|
|
739
|
+
updateUser: IDP_USER_DEFAULT,
|
|
740
|
+
deleteUser: true,
|
|
741
|
+
sendPasswordResetEmail: true,
|
|
742
|
+
unenrollMfa: true
|
|
743
|
+
};
|
|
744
|
+
/**
|
|
745
|
+
* Acquire a disposable mock for `tailor.idp`. Restored on dispose.
|
|
746
|
+
* @param options - Controls behavior for calls without a configured result
|
|
747
|
+
* @returns Disposable IDP mock control object
|
|
748
|
+
* @example
|
|
749
|
+
* ```typescript
|
|
750
|
+
* import { mockIdp } from "@tailor-platform/sdk/vitest";
|
|
751
|
+
*
|
|
752
|
+
* test("returns a user", async () => {
|
|
753
|
+
* using idp = mockIdp();
|
|
754
|
+
* idp.namespace("my-idp").user.mockResolvedValue({
|
|
755
|
+
* id: "u-1",
|
|
756
|
+
* name: "alice",
|
|
757
|
+
* disabled: false,
|
|
758
|
+
* mfaEnrolled: false,
|
|
759
|
+
* mfaFactorIds: [],
|
|
760
|
+
* });
|
|
761
|
+
* // …
|
|
762
|
+
* });
|
|
763
|
+
* ```
|
|
764
|
+
*/
|
|
765
|
+
function mockIdp(options = {}) {
|
|
766
|
+
const root = tailorRoot();
|
|
767
|
+
const prev = root.idp;
|
|
768
|
+
const { onUnhandled = "fallback" } = options;
|
|
769
|
+
const queue = [];
|
|
770
|
+
const calls = [];
|
|
771
|
+
let resolver = () => null;
|
|
772
|
+
const namespaces = /* @__PURE__ */ new Map();
|
|
773
|
+
function compatibilityArgs(method, args) {
|
|
774
|
+
return method === "users" && args.length === 0 ? [void 0] : args;
|
|
775
|
+
}
|
|
776
|
+
function handle(method, args, namespace) {
|
|
777
|
+
if (queue.length > 0) return queue.shift();
|
|
778
|
+
const resolved = resolver(method, compatibilityArgs(method, args), namespace);
|
|
779
|
+
if (resolved != null) return resolved;
|
|
780
|
+
if (onUnhandled === "error") throw new Error(`No IdP mock configured for "${namespace}.${method}"`);
|
|
781
|
+
return structuredClone(IDP_DEFAULTS[method]);
|
|
782
|
+
}
|
|
783
|
+
function createNamespaceMocks(namespace) {
|
|
784
|
+
return {
|
|
785
|
+
users: vi.fn(async (...args) => handle("users", args, namespace)),
|
|
786
|
+
user: vi.fn(async (...args) => handle("user", args, namespace)),
|
|
787
|
+
userByName: vi.fn(async (...args) => handle("userByName", args, namespace)),
|
|
788
|
+
createUser: vi.fn(async (...args) => handle("createUser", args, namespace)),
|
|
789
|
+
updateUser: vi.fn(async (...args) => handle("updateUser", args, namespace)),
|
|
790
|
+
deleteUser: vi.fn(async (...args) => handle("deleteUser", args, namespace)),
|
|
791
|
+
sendPasswordResetEmail: vi.fn(async (...args) => handle("sendPasswordResetEmail", args, namespace)),
|
|
792
|
+
unenrollMfa: vi.fn(async (...args) => handle("unenrollMfa", args, namespace))
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
function namespace(name) {
|
|
796
|
+
const existing = namespaces.get(name);
|
|
797
|
+
if (existing) return existing;
|
|
798
|
+
const mocks = createNamespaceMocks(name);
|
|
799
|
+
namespaces.set(name, mocks);
|
|
800
|
+
return mocks;
|
|
801
|
+
}
|
|
802
|
+
function track(method, mock, namespaceName) {
|
|
803
|
+
return function(...args) {
|
|
804
|
+
calls.push({
|
|
805
|
+
method,
|
|
806
|
+
args: [...compatibilityArgs(method, args)],
|
|
807
|
+
namespace: namespaceName
|
|
808
|
+
});
|
|
809
|
+
return mock.apply(this, args);
|
|
810
|
+
};
|
|
811
|
+
}
|
|
812
|
+
const defaultClient = function(config) {
|
|
813
|
+
const mocks = namespace(config.namespace);
|
|
814
|
+
this.users = track("users", mocks.users, config.namespace);
|
|
815
|
+
this.user = track("user", mocks.user, config.namespace);
|
|
816
|
+
this.userByName = track("userByName", mocks.userByName, config.namespace);
|
|
817
|
+
this.createUser = track("createUser", mocks.createUser, config.namespace);
|
|
818
|
+
this.updateUser = track("updateUser", mocks.updateUser, config.namespace);
|
|
819
|
+
this.deleteUser = track("deleteUser", mocks.deleteUser, config.namespace);
|
|
820
|
+
this.sendPasswordResetEmail = track("sendPasswordResetEmail", mocks.sendPasswordResetEmail, config.namespace);
|
|
821
|
+
this.unenrollMfa = track("unenrollMfa", mocks.unenrollMfa, config.namespace);
|
|
822
|
+
};
|
|
823
|
+
const Client = vi.fn(defaultClient);
|
|
824
|
+
root.idp = { Client };
|
|
825
|
+
function allMocks() {
|
|
826
|
+
return [...namespaces.values()].flatMap((mocks) => IDP_METHODS.map((method) => mocks[method]));
|
|
827
|
+
}
|
|
828
|
+
return withDispose({
|
|
829
|
+
/** The mock IDP `Client` constructor (`vi.fn`). */
|
|
830
|
+
Client,
|
|
831
|
+
namespace,
|
|
832
|
+
setResolver(value) {
|
|
833
|
+
resolver = value;
|
|
834
|
+
},
|
|
835
|
+
/**
|
|
836
|
+
* Enqueue a single result for the next IDP call.
|
|
837
|
+
* The queue is shared across all methods and namespaces.
|
|
838
|
+
* @param result - Result to return from the next IDP call
|
|
839
|
+
*/
|
|
840
|
+
enqueueResult(result) {
|
|
841
|
+
queue.push(result);
|
|
842
|
+
},
|
|
843
|
+
/**
|
|
844
|
+
* Enqueue results for multiple subsequent IDP calls.
|
|
845
|
+
* The queue is shared across all methods and namespaces.
|
|
846
|
+
* @param results - Results to enqueue, one per upcoming call
|
|
847
|
+
*/
|
|
848
|
+
enqueueResults(...results) {
|
|
849
|
+
queue.push(...results);
|
|
850
|
+
},
|
|
851
|
+
get calls() {
|
|
852
|
+
return calls;
|
|
853
|
+
},
|
|
854
|
+
clear() {
|
|
855
|
+
calls.length = 0;
|
|
856
|
+
Client.mockClear();
|
|
857
|
+
for (const mock of allMocks()) mock.mockClear();
|
|
858
|
+
},
|
|
859
|
+
reset() {
|
|
860
|
+
queue.length = 0;
|
|
861
|
+
calls.length = 0;
|
|
862
|
+
resolver = () => null;
|
|
863
|
+
Client.mockReset();
|
|
864
|
+
Client.mockImplementation(defaultClient);
|
|
865
|
+
for (const mock of allMocks()) mock.mockReset();
|
|
866
|
+
}
|
|
867
|
+
}, () => {
|
|
868
|
+
root.idp = prev;
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
//#endregion
|
|
873
|
+
//#region src/vitest/mocks/logger.ts
|
|
874
|
+
/**
|
|
875
|
+
* Acquire a disposable mock for `tailor.logger`. Each method is a `vi.fn`, so
|
|
876
|
+
* calls can be asserted directly; `calls` returns the `debug`/`info`/`warn`/
|
|
877
|
+
* `error` entries in the order they were emitted. Restored on dispose.
|
|
878
|
+
* @param _options - Reserved for future initial fixtures
|
|
879
|
+
* @returns Disposable logger mock control object
|
|
880
|
+
* @example
|
|
881
|
+
* ```typescript
|
|
882
|
+
* import { mockLogger } from "@tailor-platform/sdk/vitest";
|
|
883
|
+
*
|
|
884
|
+
* test("logs the processed order", () => {
|
|
885
|
+
* using logger = mockLogger();
|
|
886
|
+
* // …run code that calls tailor.logger.info…
|
|
887
|
+
* expect(logger.info).toHaveBeenCalledWith("order processed", { orderId: "o-1" });
|
|
888
|
+
* });
|
|
889
|
+
* ```
|
|
890
|
+
*/
|
|
891
|
+
function mockLogger(_options = {}) {
|
|
892
|
+
const root = tailorRoot();
|
|
893
|
+
const prev = root.logger;
|
|
894
|
+
const debug = vi.fn((_message, _attributes) => {});
|
|
895
|
+
const info = vi.fn((_message, _attributes) => {});
|
|
896
|
+
const warn = vi.fn((_message, _attributes) => {});
|
|
897
|
+
const error = vi.fn((_message, _attributes) => {});
|
|
898
|
+
const setAttributes = vi.fn((_attributes) => {});
|
|
899
|
+
root.logger = {
|
|
900
|
+
debug,
|
|
901
|
+
info,
|
|
902
|
+
warn,
|
|
903
|
+
error,
|
|
904
|
+
setAttributes
|
|
905
|
+
};
|
|
906
|
+
const severityFns = {
|
|
907
|
+
debug,
|
|
908
|
+
info,
|
|
909
|
+
warn,
|
|
910
|
+
error
|
|
911
|
+
};
|
|
912
|
+
return withDispose({
|
|
913
|
+
/** The `debug` `vi.fn`. */
|
|
914
|
+
debug,
|
|
915
|
+
/** The `info` `vi.fn`. */
|
|
916
|
+
info,
|
|
917
|
+
/** The `warn` `vi.fn`. */
|
|
918
|
+
warn,
|
|
919
|
+
/** The `error` `vi.fn`. */
|
|
920
|
+
error,
|
|
921
|
+
/** The `setAttributes` `vi.fn`. */
|
|
922
|
+
setAttributes,
|
|
923
|
+
get calls() {
|
|
924
|
+
return Object.entries(severityFns).flatMap(([severity, fn]) => fn.mock.calls.map((args, i) => ({
|
|
925
|
+
order: fn.mock.invocationCallOrder[i] ?? 0,
|
|
926
|
+
call: {
|
|
927
|
+
severity,
|
|
928
|
+
message: args[0],
|
|
929
|
+
attributes: args[1]
|
|
930
|
+
}
|
|
931
|
+
}))).toSorted((a, b) => a.order - b.order).map((e) => e.call);
|
|
932
|
+
},
|
|
933
|
+
clear() {
|
|
934
|
+
debug.mockClear();
|
|
935
|
+
info.mockClear();
|
|
936
|
+
warn.mockClear();
|
|
937
|
+
error.mockClear();
|
|
938
|
+
setAttributes.mockClear();
|
|
939
|
+
},
|
|
940
|
+
reset() {
|
|
941
|
+
debug.mockReset();
|
|
942
|
+
info.mockReset();
|
|
943
|
+
warn.mockReset();
|
|
944
|
+
error.mockReset();
|
|
945
|
+
setAttributes.mockReset();
|
|
946
|
+
}
|
|
947
|
+
}, () => {
|
|
948
|
+
root.logger = prev;
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
|
|
952
|
+
//#endregion
|
|
953
|
+
//#region src/vitest/mocks/tailordb.ts
|
|
954
|
+
function testRegex(regex, value) {
|
|
955
|
+
const lastIndex = regex.lastIndex;
|
|
956
|
+
regex.lastIndex = 0;
|
|
957
|
+
try {
|
|
958
|
+
return regex.test(value);
|
|
959
|
+
} finally {
|
|
960
|
+
regex.lastIndex = lastIndex;
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
var MockQueryResult = class {
|
|
964
|
+
command;
|
|
965
|
+
rowCount;
|
|
966
|
+
rows;
|
|
967
|
+
constructor(rows) {
|
|
968
|
+
this.command = "";
|
|
969
|
+
this.rowCount = rows.length;
|
|
970
|
+
this.rows = rows;
|
|
971
|
+
}
|
|
972
|
+
};
|
|
973
|
+
/**
|
|
974
|
+
* Acquire a disposable mock for TailorDB operations. Installs a mock
|
|
975
|
+
* `tailordb.Client` whose `queryObject` is a shared `vi.fn()` (so query
|
|
976
|
+
* responses can be staged before the client is constructed). Restored on
|
|
977
|
+
* dispose.
|
|
978
|
+
* @param options - Query fallback behavior
|
|
979
|
+
* @returns Disposable TailorDB mock control object
|
|
980
|
+
* @example
|
|
981
|
+
* ```typescript
|
|
982
|
+
* import { mockTailordb } from "@tailor-platform/sdk/vitest";
|
|
983
|
+
*
|
|
984
|
+
* test("query-based", async () => {
|
|
985
|
+
* using db = mockTailordb();
|
|
986
|
+
* db.onQuery({ sql: /FROM users/, params: ["u-1"] }).returnsRows([{ age: 30 }]);
|
|
987
|
+
* // …
|
|
988
|
+
* expect(db.queryObject).toHaveBeenCalled();
|
|
989
|
+
* expect(db.Client).toHaveBeenCalledWith({ namespace: "tailordb" });
|
|
990
|
+
* });
|
|
991
|
+
* ```
|
|
992
|
+
*/
|
|
993
|
+
function mockTailordb(options = {}) {
|
|
994
|
+
const root = tailordbRoot();
|
|
995
|
+
const prevClient = root.Client;
|
|
996
|
+
const rules = [];
|
|
997
|
+
let queryResolver;
|
|
998
|
+
function matchesQuery(matcher, query, params) {
|
|
999
|
+
if (typeof matcher === "function") return matcher(query, params);
|
|
1000
|
+
if (typeof matcher === "string") return query === matcher;
|
|
1001
|
+
if (matcher instanceof RegExp) return testRegex(matcher, query);
|
|
1002
|
+
let sqlMatches;
|
|
1003
|
+
if (typeof matcher.sql === "string") sqlMatches = query === matcher.sql;
|
|
1004
|
+
else sqlMatches = testRegex(matcher.sql, query);
|
|
1005
|
+
if (!sqlMatches || matcher.params === void 0) return sqlMatches;
|
|
1006
|
+
if (typeof matcher.params === "function") return matcher.params(params);
|
|
1007
|
+
const expectedParams = matcher.params;
|
|
1008
|
+
return params.length === expectedParams.length && params.every((value, index) => isEqual(value, expectedParams[index]));
|
|
1009
|
+
}
|
|
1010
|
+
function queryResponse(response) {
|
|
1011
|
+
if (response.type === "error") throw response.error;
|
|
1012
|
+
return new MockQueryResult(response.rows);
|
|
1013
|
+
}
|
|
1014
|
+
async function defaultQuery(query, params = []) {
|
|
1015
|
+
for (let i = rules.length - 1; i >= 0; i -= 1) {
|
|
1016
|
+
const rule = rules[i];
|
|
1017
|
+
if (!rule || !matchesQuery(rule.matcher, query, params)) continue;
|
|
1018
|
+
const once = rule.once.shift();
|
|
1019
|
+
if (once) return queryResponse(once);
|
|
1020
|
+
if (rule.fallback) return queryResponse(rule.fallback);
|
|
1021
|
+
}
|
|
1022
|
+
if (queryResolver) return new MockQueryResult(queryResolver(query, params) ?? []);
|
|
1023
|
+
if (options.onUnhandled === "error") throw new Error(`No TailorDB query behavior matched: ${query}`);
|
|
1024
|
+
return new MockQueryResult([]);
|
|
1025
|
+
}
|
|
1026
|
+
const queryObject = vi.fn(defaultQuery);
|
|
1027
|
+
const defaultConnect = async () => {};
|
|
1028
|
+
const connect = vi.fn(defaultConnect);
|
|
1029
|
+
const createdClients = [];
|
|
1030
|
+
function enqueueRowsList(rowsList) {
|
|
1031
|
+
for (const rows of rowsList) queryObject.mockImplementationOnce(async () => new MockQueryResult(rows));
|
|
1032
|
+
}
|
|
1033
|
+
const defaultClient = function(config) {
|
|
1034
|
+
const record = {
|
|
1035
|
+
namespace: config?.namespace,
|
|
1036
|
+
ended: false
|
|
1037
|
+
};
|
|
1038
|
+
createdClients.push(record);
|
|
1039
|
+
this.connect = connect;
|
|
1040
|
+
this.end = vi.fn(async () => {
|
|
1041
|
+
record.ended = true;
|
|
1042
|
+
});
|
|
1043
|
+
this.queryObject = queryObject;
|
|
1044
|
+
this.createTransaction = (name) => {
|
|
1045
|
+
if (!name) throw new Error("Transaction name must be a non-empty string");
|
|
1046
|
+
return {
|
|
1047
|
+
begin: async () => {},
|
|
1048
|
+
commit: async () => {},
|
|
1049
|
+
rollback: async () => {},
|
|
1050
|
+
queryObject
|
|
1051
|
+
};
|
|
1052
|
+
};
|
|
1053
|
+
};
|
|
1054
|
+
const Client = vi.fn(defaultClient);
|
|
1055
|
+
root.Client = Client;
|
|
1056
|
+
return withDispose({
|
|
1057
|
+
/** The mock `tailordb.Client` constructor (`vi.fn`). */
|
|
1058
|
+
Client,
|
|
1059
|
+
/** The shared `queryObject` `vi.fn` used by every client and transaction. */
|
|
1060
|
+
queryObject,
|
|
1061
|
+
/**
|
|
1062
|
+
* Set a fallback query resolver. Called when the enqueue queue is empty.
|
|
1063
|
+
* @param resolver - Function that returns rows for a given query and params
|
|
1064
|
+
*/
|
|
1065
|
+
setQueryResolver(resolver) {
|
|
1066
|
+
queryResolver = resolver;
|
|
1067
|
+
queryObject.mockImplementation(defaultQuery);
|
|
1068
|
+
},
|
|
1069
|
+
/**
|
|
1070
|
+
* Configure responses for queries matching SQL text, parameters, or a predicate.
|
|
1071
|
+
* More recently registered matchers take precedence.
|
|
1072
|
+
* Do not combine matchers with a direct `queryObject.mockImplementation()` override.
|
|
1073
|
+
* @param matcher - Query matcher
|
|
1074
|
+
* @returns Chainable query behavior
|
|
1075
|
+
*/
|
|
1076
|
+
onQuery(matcher) {
|
|
1077
|
+
const rule = {
|
|
1078
|
+
matcher,
|
|
1079
|
+
once: []
|
|
1080
|
+
};
|
|
1081
|
+
rules.push(rule);
|
|
1082
|
+
const behavior = {
|
|
1083
|
+
returnsRows(rows) {
|
|
1084
|
+
rule.fallback = {
|
|
1085
|
+
type: "rows",
|
|
1086
|
+
rows
|
|
1087
|
+
};
|
|
1088
|
+
return behavior;
|
|
1089
|
+
},
|
|
1090
|
+
returnsRowsOnce(rows) {
|
|
1091
|
+
rule.once.push({
|
|
1092
|
+
type: "rows",
|
|
1093
|
+
rows
|
|
1094
|
+
});
|
|
1095
|
+
return behavior;
|
|
1096
|
+
},
|
|
1097
|
+
rejects(error) {
|
|
1098
|
+
rule.fallback = {
|
|
1099
|
+
type: "error",
|
|
1100
|
+
error
|
|
1101
|
+
};
|
|
1102
|
+
return behavior;
|
|
1103
|
+
},
|
|
1104
|
+
rejectsOnce(error) {
|
|
1105
|
+
rule.once.push({
|
|
1106
|
+
type: "error",
|
|
1107
|
+
error
|
|
1108
|
+
});
|
|
1109
|
+
return behavior;
|
|
1110
|
+
}
|
|
1111
|
+
};
|
|
1112
|
+
return behavior;
|
|
1113
|
+
},
|
|
1114
|
+
/**
|
|
1115
|
+
* Enqueue rows for the next `queryObject` call (FIFO; takes priority over
|
|
1116
|
+
* `setQueryResolver`). Call with no arguments for an empty result.
|
|
1117
|
+
* @param rows - Row objects to return from the next `queryObject` call
|
|
1118
|
+
*/
|
|
1119
|
+
enqueueResult(...rows) {
|
|
1120
|
+
enqueueRowsList([rows]);
|
|
1121
|
+
},
|
|
1122
|
+
/**
|
|
1123
|
+
* Enqueue rows for multiple subsequent `queryObject` calls (FIFO).
|
|
1124
|
+
* @param rowsList - Rows arrays, one per upcoming query
|
|
1125
|
+
*/
|
|
1126
|
+
enqueueResults(...rowsList) {
|
|
1127
|
+
enqueueRowsList(rowsList);
|
|
1128
|
+
},
|
|
1129
|
+
/**
|
|
1130
|
+
* Enqueue row arrays for subsequent queries whose exact order is under test.
|
|
1131
|
+
* @param rowsList - Rows arrays, one per upcoming query
|
|
1132
|
+
*/
|
|
1133
|
+
enqueueRows(...rowsList) {
|
|
1134
|
+
enqueueRowsList(rowsList);
|
|
1135
|
+
},
|
|
1136
|
+
/**
|
|
1137
|
+
* All queries executed via `queryObject`, in order, derived from the vi.fn
|
|
1138
|
+
* call records.
|
|
1139
|
+
* @returns Executed queries array
|
|
1140
|
+
*/
|
|
1141
|
+
get executedQueries() {
|
|
1142
|
+
return queryObject.mock.calls.map(([query, params]) => ({
|
|
1143
|
+
query,
|
|
1144
|
+
params: params ?? []
|
|
1145
|
+
}));
|
|
1146
|
+
},
|
|
1147
|
+
/**
|
|
1148
|
+
* All TailorDB clients created, with their namespace and end state.
|
|
1149
|
+
* @returns Created clients array
|
|
1150
|
+
*/
|
|
1151
|
+
get createdClients() {
|
|
1152
|
+
return createdClients;
|
|
1153
|
+
},
|
|
1154
|
+
/** Clear recorded calls while preserving configured query behavior. */
|
|
1155
|
+
clear() {
|
|
1156
|
+
queryObject.mockClear();
|
|
1157
|
+
connect.mockClear();
|
|
1158
|
+
Client.mockClear();
|
|
1159
|
+
createdClients.length = 0;
|
|
1160
|
+
},
|
|
1161
|
+
/** Reset query responses and recorded calls (keeps the mock installed). */
|
|
1162
|
+
reset() {
|
|
1163
|
+
queryObject.mockReset();
|
|
1164
|
+
queryObject.mockImplementation(defaultQuery);
|
|
1165
|
+
connect.mockReset();
|
|
1166
|
+
connect.mockImplementation(defaultConnect);
|
|
1167
|
+
Client.mockReset();
|
|
1168
|
+
Client.mockImplementation(defaultClient);
|
|
1169
|
+
createdClients.length = 0;
|
|
1170
|
+
rules.length = 0;
|
|
1171
|
+
queryResolver = void 0;
|
|
1172
|
+
}
|
|
1173
|
+
}, () => {
|
|
1174
|
+
root.Client = prevClient;
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
//#endregion
|
|
1179
|
+
//#region src/vitest/mocks/workflow.ts
|
|
1180
|
+
const originalProcedures = /* @__PURE__ */ new WeakMap();
|
|
1181
|
+
function replaceProcedure(target, key, current) {
|
|
1182
|
+
const original = originalProcedures.get(current) ?? current;
|
|
1183
|
+
const defaultImplementation = function(...args) {
|
|
1184
|
+
return Reflect.apply(original, this, args);
|
|
1185
|
+
};
|
|
1186
|
+
const mock = vi.fn(defaultImplementation);
|
|
1187
|
+
originalProcedures.set(mock, original);
|
|
1188
|
+
const record = target;
|
|
1189
|
+
record[key] = mock;
|
|
1190
|
+
return {
|
|
1191
|
+
mock,
|
|
1192
|
+
scoped: {
|
|
1193
|
+
mockClear: () => mock.mockClear(),
|
|
1194
|
+
mockReset: () => mock.mockReset(),
|
|
1195
|
+
restore: () => {
|
|
1196
|
+
if (record[key] === mock) record[key] = current;
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
};
|
|
1200
|
+
}
|
|
1201
|
+
function replaceStart(definition) {
|
|
1202
|
+
return replaceProcedure(definition, "start", definition.start);
|
|
1203
|
+
}
|
|
1204
|
+
/**
|
|
1205
|
+
* Acquire a disposable mock for workflow operations (`tailor.workflow`).
|
|
1206
|
+
* Restored on dispose.
|
|
1207
|
+
|
|
1208
|
+
* @returns Disposable workflow mock control object
|
|
1209
|
+
* @example
|
|
1210
|
+
* ```typescript
|
|
1211
|
+
* import { mockWorkflow } from "@tailor-platform/sdk/vitest";
|
|
1212
|
+
*
|
|
1213
|
+
* test("job start", async () => {
|
|
1214
|
+
* using wf = mockWorkflow();
|
|
1215
|
+
* const job = wf.job(validateOrder);
|
|
1216
|
+
* job.mockResolvedValue({ valid: true });
|
|
1217
|
+
* await runWorkflowUnderTest();
|
|
1218
|
+
* expect(job).toHaveBeenCalled();
|
|
1219
|
+
* });
|
|
1220
|
+
* ```
|
|
1221
|
+
*/
|
|
1222
|
+
function mockWorkflow() {
|
|
1223
|
+
const root = tailorRoot();
|
|
1224
|
+
const prev = root.workflow;
|
|
1225
|
+
const prevEnv = readWorkflowTestEnv();
|
|
1226
|
+
const jobSpies = /* @__PURE__ */ new Map();
|
|
1227
|
+
const workflowSpies = /* @__PURE__ */ new Map();
|
|
1228
|
+
const waitPointMocks = /* @__PURE__ */ new Map();
|
|
1229
|
+
const scopedMocks = /* @__PURE__ */ new Set();
|
|
1230
|
+
const defaultExecJob = (jobName, _args, _options) => {
|
|
1231
|
+
throw new Error(`No workflow job mock for "${jobName}". Call mockWorkflow().setJobHandler(...) or enqueueResult(...), or use runWorkflowLocally() for local workflow execution.`);
|
|
1232
|
+
};
|
|
1233
|
+
const defaultStartWorkflow = async (_workflowName, _args, _options) => {
|
|
1234
|
+
return START_DEFAULT;
|
|
1235
|
+
};
|
|
1236
|
+
const defaultResumeWorkflowExecution = async (executionId) => executionId;
|
|
1237
|
+
const execJobFunction = vi.fn(defaultExecJob);
|
|
1238
|
+
const startWorkflow = vi.fn(defaultStartWorkflow);
|
|
1239
|
+
const resumeWorkflowExecution = vi.fn(defaultResumeWorkflowExecution);
|
|
1240
|
+
const wait = vi.fn((_key, _payload) => null);
|
|
1241
|
+
const resolve = vi.fn(async (_executionId, _key, _callback) => {});
|
|
1242
|
+
const jobFunctionShim = (...call) => {
|
|
1243
|
+
const out = call.length >= 3 ? execJobFunction(call[0], platformSerialize(call[1]), call[2]) : execJobFunction(call[0], platformSerialize(call[1]));
|
|
1244
|
+
return out instanceof Promise ? out.then((v) => platformSerialize(v)) : platformSerialize(out);
|
|
1245
|
+
};
|
|
1246
|
+
const workflowShim = (...call) => call.length >= 3 ? startWorkflow(call[0], platformSerialize(call[1]), call[2]) : startWorkflow(call[0], platformSerialize(call[1]));
|
|
1247
|
+
const resumeShim = (executionId) => resumeWorkflowExecution(executionId);
|
|
1248
|
+
root.workflow = {
|
|
1249
|
+
execJobFunction: jobFunctionShim,
|
|
1250
|
+
startWorkflow: workflowShim,
|
|
1251
|
+
resumeWorkflowExecution: resumeShim,
|
|
1252
|
+
wait: (key, payload) => wait(key, platformSerialize(payload)),
|
|
1253
|
+
resolve: (executionId, key, callback) => resolve(executionId, key, (payload) => {
|
|
1254
|
+
const out = callback(payload);
|
|
1255
|
+
return out instanceof Promise ? out.then((v) => platformSerialize(v)) : platformSerialize(out);
|
|
1256
|
+
})
|
|
1257
|
+
};
|
|
1258
|
+
return withDispose({
|
|
1259
|
+
/** The `execJobFunction` `vi.fn`. */
|
|
1260
|
+
execJobFunction,
|
|
1261
|
+
/** The `startWorkflow` `vi.fn`. */
|
|
1262
|
+
startWorkflow,
|
|
1263
|
+
/** The `resumeWorkflowExecution` `vi.fn`. */
|
|
1264
|
+
resumeWorkflowExecution,
|
|
1265
|
+
/** The `wait` `vi.fn`. */
|
|
1266
|
+
wait,
|
|
1267
|
+
/** The `resolve` `vi.fn`. */
|
|
1268
|
+
resolve,
|
|
1269
|
+
/**
|
|
1270
|
+
* Get a stable, typed mock for a workflow job's `start` method.
|
|
1271
|
+
* The real start behavior is used until an implementation or result is configured.
|
|
1272
|
+
* @param definition - Workflow job definition to mock
|
|
1273
|
+
* @returns Typed `start` mock for the definition
|
|
1274
|
+
*/
|
|
1275
|
+
job(definition) {
|
|
1276
|
+
const existing = jobSpies.get(definition);
|
|
1277
|
+
if (existing) return existing;
|
|
1278
|
+
const { mock, scoped } = replaceStart(definition);
|
|
1279
|
+
scopedMocks.add(scoped);
|
|
1280
|
+
jobSpies.set(definition, mock);
|
|
1281
|
+
return mock;
|
|
1282
|
+
},
|
|
1283
|
+
/**
|
|
1284
|
+
* Get a stable, typed mock for a workflow definition's `start` method.
|
|
1285
|
+
* The real start behavior is used until an implementation or result is configured.
|
|
1286
|
+
* @param definition - Workflow definition to mock
|
|
1287
|
+
* @returns Typed `start` mock for the definition
|
|
1288
|
+
*/
|
|
1289
|
+
workflow(definition) {
|
|
1290
|
+
const existing = workflowSpies.get(definition);
|
|
1291
|
+
if (existing) return existing;
|
|
1292
|
+
const { mock, scoped } = replaceStart(definition);
|
|
1293
|
+
workflowSpies.set(definition, mock);
|
|
1294
|
+
scopedMocks.add(scoped);
|
|
1295
|
+
return mock;
|
|
1296
|
+
},
|
|
1297
|
+
/**
|
|
1298
|
+
* Get stable, typed mocks for a wait point's `wait` and `resolve` methods.
|
|
1299
|
+
* @param definition - Wait point definition to mock
|
|
1300
|
+
* @returns Typed wait point mock control object
|
|
1301
|
+
*/
|
|
1302
|
+
waitPoint(definition) {
|
|
1303
|
+
const existing = waitPointMocks.get(definition);
|
|
1304
|
+
if (existing) return existing;
|
|
1305
|
+
const waitReplacement = replaceProcedure(definition, "wait", definition.wait);
|
|
1306
|
+
const resolveReplacement = replaceProcedure(definition, "resolve", definition.resolve);
|
|
1307
|
+
const waitSpy = waitReplacement.mock;
|
|
1308
|
+
const resolveSpy = resolveReplacement.mock;
|
|
1309
|
+
scopedMocks.add(waitReplacement.scoped);
|
|
1310
|
+
scopedMocks.add(resolveReplacement.scoped);
|
|
1311
|
+
const waitPointMock = {
|
|
1312
|
+
wait: waitSpy,
|
|
1313
|
+
resolve: resolveSpy,
|
|
1314
|
+
/**
|
|
1315
|
+
* Invoke the next and subsequent resolve callbacks with a wait payload.
|
|
1316
|
+
* @param payload - Payload originally supplied to the wait point
|
|
1317
|
+
*/
|
|
1318
|
+
setResolvePayload(payload) {
|
|
1319
|
+
resolveSpy.mockImplementation(async (_executionId, callback) => {
|
|
1320
|
+
platformSerialize(await callback(platformSerialize(payload)));
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
};
|
|
1324
|
+
waitPointMocks.set(definition, waitPointMock);
|
|
1325
|
+
return waitPointMock;
|
|
1326
|
+
},
|
|
1327
|
+
/**
|
|
1328
|
+
* Set a fallback job handler. Called when the enqueue queue is empty.
|
|
1329
|
+
* @param handler - Function returning a result for a job name, args, and options
|
|
1330
|
+
*/
|
|
1331
|
+
setJobHandler(handler) {
|
|
1332
|
+
execJobFunction.mockImplementation((name, args, options) => handler(name, args, options));
|
|
1333
|
+
},
|
|
1334
|
+
/**
|
|
1335
|
+
* Enqueue a single result for the next `execJobFunction` call (FIFO;
|
|
1336
|
+
* takes priority over `setJobHandler`).
|
|
1337
|
+
* @param result - Result to return from the next call
|
|
1338
|
+
*/
|
|
1339
|
+
enqueueResult(result) {
|
|
1340
|
+
execJobFunction.mockImplementationOnce(() => result);
|
|
1341
|
+
},
|
|
1342
|
+
/**
|
|
1343
|
+
* Enqueue results for multiple subsequent `execJobFunction` calls (FIFO).
|
|
1344
|
+
* @param results - Results to enqueue, one per upcoming call
|
|
1345
|
+
*/
|
|
1346
|
+
enqueueResults(...results) {
|
|
1347
|
+
for (const result of results) execJobFunction.mockImplementationOnce(() => result);
|
|
1348
|
+
},
|
|
1349
|
+
/**
|
|
1350
|
+
* All jobs executed via `execJobFunction`, in order.
|
|
1351
|
+
* @returns Started jobs array
|
|
1352
|
+
*/
|
|
1353
|
+
get startedJobs() {
|
|
1354
|
+
return execJobFunction.mock.calls.map(([jobName, args, options]) => ({
|
|
1355
|
+
jobName,
|
|
1356
|
+
args,
|
|
1357
|
+
...options !== void 0 && { options }
|
|
1358
|
+
}));
|
|
1359
|
+
},
|
|
1360
|
+
/**
|
|
1361
|
+
* Configure what `startWorkflow` returns. Pass a string (same id every
|
|
1362
|
+
* call) or `(name, args, options) => string`. Default: a placeholder UUID.
|
|
1363
|
+
* @param handler - Static execution ID or a function returning one
|
|
1364
|
+
*/
|
|
1365
|
+
setStartHandler(handler) {
|
|
1366
|
+
startWorkflow.mockImplementation(typeof handler === "function" ? async (name, args, options) => handler(name, args, options) : async () => handler);
|
|
1367
|
+
},
|
|
1368
|
+
/**
|
|
1369
|
+
* Configure what `resumeWorkflowExecution` returns. Pass a string (same id
|
|
1370
|
+
* every call) or `(executionId) => string`. Default: echoes the input executionId.
|
|
1371
|
+
* @param handler - Static execution ID or a function returning one
|
|
1372
|
+
*/
|
|
1373
|
+
setResumeHandler(handler) {
|
|
1374
|
+
resumeWorkflowExecution.mockImplementation(typeof handler === "function" ? async (executionId) => handler(executionId) : async () => handler);
|
|
1375
|
+
},
|
|
1376
|
+
/**
|
|
1377
|
+
* Configure what `wait` returns. Pass `(key, payload) => unknown` or any
|
|
1378
|
+
* other value to return it for every call. Default: `null`.
|
|
1379
|
+
* @param handler - Static value or a function returning one
|
|
1380
|
+
*/
|
|
1381
|
+
setWaitHandler: ((handler) => {
|
|
1382
|
+
wait.mockImplementation(typeof handler === "function" ? (key, payload) => handler(key, payload) : () => handler);
|
|
1383
|
+
}),
|
|
1384
|
+
/**
|
|
1385
|
+
* Set the `env` passed to job bodies invoked via `createWorkflowJob().start()`.
|
|
1386
|
+
* Cleared on dispose / reset.
|
|
1387
|
+
* @param env - Env passed to job bodies.
|
|
1388
|
+
*/
|
|
1389
|
+
setEnv(env) {
|
|
1390
|
+
writeWorkflowTestEnv({ ...env });
|
|
1391
|
+
},
|
|
1392
|
+
/**
|
|
1393
|
+
* Configure how `resolve` runs the user-supplied callback. Default: callback
|
|
1394
|
+
* is not invoked (records the call only).
|
|
1395
|
+
* @param handler - Function invoked per `resolve` call
|
|
1396
|
+
*/
|
|
1397
|
+
setResolveHandler(handler) {
|
|
1398
|
+
resolve.mockImplementation(async (executionId, key, callback) => {
|
|
1399
|
+
await handler(executionId, key, callback);
|
|
1400
|
+
});
|
|
1401
|
+
},
|
|
1402
|
+
/**
|
|
1403
|
+
* `wait` calls reshaped as `{ key, payload }` for assertions.
|
|
1404
|
+
* @returns Wait call records
|
|
1405
|
+
*/
|
|
1406
|
+
get waitCalls() {
|
|
1407
|
+
return wait.mock.calls.map(([key, payload]) => ({
|
|
1408
|
+
key,
|
|
1409
|
+
payload
|
|
1410
|
+
}));
|
|
1411
|
+
},
|
|
1412
|
+
/**
|
|
1413
|
+
* `resolve` calls reshaped as `{ executionId, key }` for assertions.
|
|
1414
|
+
* @returns Resolve call records
|
|
1415
|
+
*/
|
|
1416
|
+
get resolveCalls() {
|
|
1417
|
+
return resolve.mock.calls.map(([executionId, key]) => ({
|
|
1418
|
+
executionId,
|
|
1419
|
+
key
|
|
1420
|
+
}));
|
|
1421
|
+
},
|
|
1422
|
+
/** Clear recorded calls while preserving configured responses. */
|
|
1423
|
+
clear() {
|
|
1424
|
+
execJobFunction.mockClear();
|
|
1425
|
+
startWorkflow.mockClear();
|
|
1426
|
+
resumeWorkflowExecution.mockClear();
|
|
1427
|
+
wait.mockClear();
|
|
1428
|
+
resolve.mockClear();
|
|
1429
|
+
for (const mock of scopedMocks) mock.mockClear();
|
|
1430
|
+
},
|
|
1431
|
+
/** Reset all workflow responses and recorded calls (keeps the mock installed). */
|
|
1432
|
+
reset() {
|
|
1433
|
+
execJobFunction.mockReset();
|
|
1434
|
+
execJobFunction.mockImplementation(defaultExecJob);
|
|
1435
|
+
startWorkflow.mockReset();
|
|
1436
|
+
startWorkflow.mockImplementation(defaultStartWorkflow);
|
|
1437
|
+
resumeWorkflowExecution.mockReset();
|
|
1438
|
+
resumeWorkflowExecution.mockImplementation(defaultResumeWorkflowExecution);
|
|
1439
|
+
wait.mockReset();
|
|
1440
|
+
wait.mockImplementation(() => null);
|
|
1441
|
+
resolve.mockReset();
|
|
1442
|
+
resolve.mockImplementation(async () => {});
|
|
1443
|
+
for (const mock of scopedMocks) mock.mockReset();
|
|
1444
|
+
clearWorkflowTestEnv();
|
|
1445
|
+
}
|
|
1446
|
+
}, () => {
|
|
1447
|
+
for (const mock of scopedMocks) mock.restore();
|
|
1448
|
+
root.workflow = prev;
|
|
1449
|
+
if (prevEnv !== void 0) writeWorkflowTestEnv(prevEnv);
|
|
1450
|
+
else clearWorkflowTestEnv();
|
|
1451
|
+
});
|
|
1452
|
+
}
|
|
1453
|
+
|
|
294
1454
|
//#endregion
|
|
295
1455
|
//#region src/vitest/workflow-local.ts
|
|
296
|
-
var
|
|
1456
|
+
var PendingStart = class {
|
|
297
1457
|
jobName;
|
|
298
1458
|
args;
|
|
299
1459
|
constructor(jobName, args) {
|
|
@@ -310,7 +1470,7 @@ async function runWorkflowLocally(workflow, args, options) {
|
|
|
310
1470
|
if (options?.env !== void 0) writeWorkflowTestEnv({ ...options.env });
|
|
311
1471
|
root.tailor = {
|
|
312
1472
|
...previousTailor,
|
|
313
|
-
workflow: createLocalWorkflowRuntime(previousTailor?.workflow, runner.
|
|
1473
|
+
workflow: createLocalWorkflowRuntime(previousTailor?.workflow, runner.execJobFunction)
|
|
314
1474
|
};
|
|
315
1475
|
try {
|
|
316
1476
|
return await runner.runJob(workflow.mainJob.name, args);
|
|
@@ -323,19 +1483,19 @@ async function runWorkflowLocally(workflow, args, options) {
|
|
|
323
1483
|
}
|
|
324
1484
|
function createLocalJobRunner() {
|
|
325
1485
|
let activeExecution;
|
|
326
|
-
const
|
|
327
|
-
if (!activeExecution) throw new Error(`Cannot
|
|
1486
|
+
const execJobFunction = (jobName, args) => {
|
|
1487
|
+
if (!activeExecution) throw new Error(`Cannot start workflow job "${jobName}" outside runWorkflowLocally() job execution.`);
|
|
328
1488
|
if (activeExecution.pending) throw activeExecution.pending;
|
|
329
1489
|
const serializedArgs = platformSerialize(args);
|
|
330
1490
|
const index = activeExecution.cursor;
|
|
331
1491
|
activeExecution.cursor += 1;
|
|
332
1492
|
const cached = activeExecution.records[index];
|
|
333
1493
|
if (cached) {
|
|
334
|
-
|
|
1494
|
+
assertSameStart(cached, jobName, serializedArgs);
|
|
335
1495
|
if (cached.status === "rejected") throw cached.error;
|
|
336
1496
|
return platformSerialize(cached.result);
|
|
337
1497
|
}
|
|
338
|
-
const pending = new
|
|
1498
|
+
const pending = new PendingStart(jobName, serializedArgs);
|
|
339
1499
|
activeExecution.pending = pending;
|
|
340
1500
|
throw pending;
|
|
341
1501
|
};
|
|
@@ -353,15 +1513,15 @@ function createLocalJobRunner() {
|
|
|
353
1513
|
try {
|
|
354
1514
|
const out = await body(platformSerialize(args), buildJobContext());
|
|
355
1515
|
if (execution.pending) {
|
|
356
|
-
await
|
|
1516
|
+
await settlePendingStart(records, execution.pending, runJob);
|
|
357
1517
|
continue;
|
|
358
1518
|
}
|
|
359
|
-
if (execution.cursor !== records.length) throw new Error(`Workflow job
|
|
1519
|
+
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}.`);
|
|
360
1520
|
return platformSerialize(out);
|
|
361
1521
|
} catch (cause) {
|
|
362
|
-
const pending = cause instanceof
|
|
1522
|
+
const pending = cause instanceof PendingStart ? cause : execution.pending;
|
|
363
1523
|
if (pending) {
|
|
364
|
-
await
|
|
1524
|
+
await settlePendingStart(records, pending, runJob);
|
|
365
1525
|
continue;
|
|
366
1526
|
}
|
|
367
1527
|
throw cause;
|
|
@@ -372,10 +1532,10 @@ function createLocalJobRunner() {
|
|
|
372
1532
|
};
|
|
373
1533
|
return {
|
|
374
1534
|
runJob,
|
|
375
|
-
|
|
1535
|
+
execJobFunction
|
|
376
1536
|
};
|
|
377
1537
|
}
|
|
378
|
-
async function
|
|
1538
|
+
async function settlePendingStart(records, pending, runJob) {
|
|
379
1539
|
try {
|
|
380
1540
|
records.push({
|
|
381
1541
|
jobName: pending.jobName,
|
|
@@ -392,18 +1552,24 @@ async function settlePendingTrigger(records, pending, runJob) {
|
|
|
392
1552
|
});
|
|
393
1553
|
}
|
|
394
1554
|
}
|
|
395
|
-
function
|
|
1555
|
+
function assertSameStart(record, jobName, args) {
|
|
396
1556
|
if (record.jobName === jobName && JSON.stringify(record.args) === JSON.stringify(args)) return;
|
|
397
|
-
throw new Error(`Workflow job
|
|
1557
|
+
throw new Error(`Workflow job start sequence changed while replaying. Expected ${record.jobName}(${JSON.stringify(record.args)}), but got ${jobName}(${JSON.stringify(args)}).`);
|
|
398
1558
|
}
|
|
399
|
-
function createLocalWorkflowRuntime(previous,
|
|
1559
|
+
function createLocalWorkflowRuntime(previous, execJobFunction) {
|
|
1560
|
+
const startWorkflow = async (name, args, options) => {
|
|
1561
|
+
if (previous) return await previous.startWorkflow(name, args, options);
|
|
1562
|
+
platformSerialize(args);
|
|
1563
|
+
return START_DEFAULT;
|
|
1564
|
+
};
|
|
1565
|
+
const resumeWorkflowExecution = async (executionId) => {
|
|
1566
|
+
if (previous) return await previous.resumeWorkflowExecution(executionId);
|
|
1567
|
+
return executionId;
|
|
1568
|
+
};
|
|
400
1569
|
return {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
platformSerialize(args);
|
|
405
|
-
return TRIGGER_DEFAULT;
|
|
406
|
-
},
|
|
1570
|
+
execJobFunction,
|
|
1571
|
+
startWorkflow,
|
|
1572
|
+
resumeWorkflowExecution,
|
|
407
1573
|
wait: (key, payload) => {
|
|
408
1574
|
if (previous) return previous.wait(key, payload);
|
|
409
1575
|
throw new Error(`No wait handler for "${key}". Acquire mockWorkflow() and call setWaitHandler(...).`);
|
|
@@ -608,7 +1774,8 @@ function createKyselyMock() {
|
|
|
608
1774
|
*
|
|
609
1775
|
* 3. **Platform API mocks** (environment) — All platform APIs are auto-injected with
|
|
610
1776
|
* control objects: `mockTailordb`, `mockWorkflow`, `mockSecretmanager`,
|
|
611
|
-
* `mockAuthconnection`, `mockIdp`, `mockFile`, `mockIconv
|
|
1777
|
+
* `mockAuthconnection`, `mockIdp`, `mockFile`, `mockIconv`, `mockAigateway`,
|
|
1778
|
+
* `mockLogger`. Each
|
|
612
1779
|
* provides response configuration, call recording, and reset.
|
|
613
1780
|
*
|
|
614
1781
|
* 4. **Environment resolution** — Rewrites `environment: "tailor-runtime"` to the
|
|
@@ -618,8 +1785,8 @@ function createKyselyMock() {
|
|
|
618
1785
|
*
|
|
619
1786
|
* - **`process`** and **`require`** are NOT removed or blocked. Vitest's internal
|
|
620
1787
|
* runner depends on them. On the real Tailor Platform runtime, they do not exist.
|
|
621
|
-
* - **Dynamic `import()`** of bundled files
|
|
622
|
-
*
|
|
1788
|
+
* - **Dynamic `import()`** of bundled files bypasses the transform hook since
|
|
1789
|
+
* those files are loaded through Node.js native loader.
|
|
623
1790
|
* ## Options
|
|
624
1791
|
*
|
|
625
1792
|
* - **`config`** — Path to `tailor.config.ts`. Loads `defineSecretManager()` values
|
|
@@ -646,5 +1813,5 @@ function tailorRuntime(options) {
|
|
|
646
1813
|
}
|
|
647
1814
|
|
|
648
1815
|
//#endregion
|
|
649
|
-
export { createKyselyMock, mockAuthconnection, mockFile, mockIconv, mockIdp, mockSecretmanager, mockTailordb, mockWorkflow, runWorkflowLocally, tailorRuntime };
|
|
1816
|
+
export { createKyselyMock, mockAigateway, mockAuthconnection, mockFile, mockIconv, mockIdp, mockLogger, mockSecretmanager, mockTailordb, mockWorkflow, runWorkflowLocally, tailorRuntime };
|
|
650
1817
|
//# sourceMappingURL=index.mjs.map
|