@tailor-platform/sdk 2.3.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +171 -0
- package/README.md +1 -1
- package/dist/aigateway-DsWDjzk4.mjs +2 -0
- package/dist/{aigateway-DR4Kwuik.mjs.map → aigateway-DsWDjzk4.mjs.map} +1 -1
- package/dist/application-DFOUovmN.mjs +1 -0
- package/dist/application-D_4vg1KR.mjs +192 -0
- package/dist/application-D_4vg1KR.mjs.map +1 -0
- package/dist/assert-WeXvmG4j.mjs +2 -0
- package/dist/{assert-DBxo8jPo.mjs.map → assert-WeXvmG4j.mjs.map} +1 -1
- package/dist/authconnection-CynFBIv8.mjs +2 -0
- package/dist/{authconnection-CZvi9ANm.mjs.map → authconnection-CynFBIv8.mjs.map} +1 -1
- package/dist/brand-C8nMKhJC.mjs +2 -0
- package/dist/{brand-Eo4pLXPJ.mjs.map → brand-C8nMKhJC.mjs.map} +1 -1
- package/dist/cli/commands/deploy/deploy.d.mts +2 -2
- package/dist/cli/commands/deploy/deployment-target.d.mts +2 -0
- package/dist/cli/commands/deploy/event-subscriptions.d.mts +3 -0
- package/dist/cli/commands/deploy/tailordb/apply.d.mts +3 -0
- package/dist/cli/commands/deploy/tailordb/index.d.mts +3 -10
- package/dist/cli/commands/deploy/tailordb/migration-validation.d.mts +5 -0
- package/dist/cli/commands/deploy/tailordb/plan.d.mts +8 -0
- package/dist/cli/commands/executor/jobs.d.mts +1 -1
- package/dist/cli/commands/generate/seed/bundler.d.mts +2 -2
- package/dist/cli/commands/show.d.mts +1 -1
- package/dist/cli/commands/tailordb/migrate/diff-calculator.d.mts +15 -15
- package/dist/cli/commands/tailordb/migrate/generate.d.mts +7 -3
- package/dist/cli/commands/tailordb/migrate/rename-detection.d.mts +1 -1
- package/dist/cli/commands/tailordb/migrate/snapshot-comparison.d.mts +43 -0
- package/dist/cli/commands/tailordb/migrate/snapshot-files.d.mts +62 -0
- package/dist/cli/commands/tailordb/migrate/snapshot-local.d.mts +12 -0
- package/dist/cli/commands/tailordb/migrate/snapshot-migrations.d.mts +12 -0
- package/dist/cli/commands/tailordb/migrate/snapshot-remote.d.mts +1 -0
- package/dist/cli/commands/tailordb/migrate/snapshot-types.d.mts +3 -1
- package/dist/cli/commands/tailordb/migrate/snapshot.d.mts +5 -117
- package/dist/cli/commands/tailordb/truncate.d.mts +2 -2
- package/dist/cli/lib.d.mts +8 -4
- package/dist/cli/lib.mjs +1 -9
- package/dist/cli/lib.mjs.map +1 -1
- package/dist/cli/main.mjs +1170 -7686
- package/dist/cli/main.mjs.map +1 -1
- package/dist/cli/shared/seed-chunker.d.mts +5 -5
- package/dist/cli/ts-hook.mjs +3 -1
- package/dist/completion/zsh-worker.zsh +99 -18
- package/dist/configure/config/index.d.mts +2 -2
- package/dist/configure/config/types.d.mts +2 -2
- package/dist/configure/index.d.mts +49 -12
- package/dist/configure/index.mjs +1 -1267
- package/dist/configure/index.mjs.map +1 -1
- package/dist/configure/services/aigateway/index.d.mts +5 -4
- package/dist/configure/services/aigateway/types.d.mts +6 -1
- package/dist/configure/services/auth/types.d.mts +3 -3
- package/dist/configure/services/idp/types.d.mts +1 -1
- package/dist/configure/services/tailordb/permission.d.mts +1 -1
- package/dist/configure/services/tailordb/schema.d.mts +5 -9
- package/dist/configure/services/tailordb/types.d.mts +8 -5
- package/dist/configure/services/workflow/execution-policy.d.mts +3 -3
- package/dist/configure/services/workflow/job.d.mts +12 -2
- package/dist/configure/types/auth-namespace-name.d.mts +18 -0
- package/dist/configure/types/field.types.d.mts +1 -1
- package/dist/configure/types/permission-operand.types.d.mts +1 -1
- package/dist/context-D0QjfxzD.mjs +2 -0
- package/dist/{context-DYQVYWqZ.mjs.map → context-D0QjfxzD.mjs.map} +1 -1
- package/dist/crashreport-B-_HTKLr.mjs +42 -0
- package/dist/{crashreport-CIIfLnoO.mjs.map → crashreport-B-_HTKLr.mjs.map} +1 -1
- package/dist/crashreport-BmsRIdpy.mjs +1 -0
- package/dist/errors-DSEXKRVD.mjs +2 -0
- package/dist/errors-DSEXKRVD.mjs.map +1 -0
- package/dist/file-COPYfju_.mjs +2 -0
- package/dist/file-COPYfju_.mjs.map +1 -0
- package/dist/globals-CMHSnj4w.mjs +2 -0
- package/dist/{globals-B2nlxBrz.mjs.map → globals-CMHSnj4w.mjs.map} +1 -1
- package/dist/iconv-DlFMt2gW.mjs +2 -0
- package/dist/{iconv-QWaZh0TT.mjs.map → iconv-DlFMt2gW.mjs.map} +1 -1
- package/dist/idp-G_ojPBB5.mjs +2 -0
- package/dist/{idp-RA_swu-h.mjs.map → idp-G_ojPBB5.mjs.map} +1 -1
- package/dist/interceptor-DQg3cR_9.mjs +2 -0
- package/dist/{interceptor-e33JtsC-.mjs.map → interceptor-DQg3cR_9.mjs.map} +1 -1
- package/dist/kysely/index.mjs +1 -31
- package/dist/kysely/index.mjs.map +1 -1
- package/dist/kysely-type-BTi3BMtL.mjs +43 -0
- package/dist/kysely-type-BTi3BMtL.mjs.map +1 -0
- package/dist/logger-BcGy-u7G.mjs +9 -0
- package/dist/{logger-DSdExfor.mjs.map → logger-BcGy-u7G.mjs.map} +1 -1
- package/dist/logger-DP2BjQ93.mjs +2 -0
- package/dist/{logger-BtX0suGY.mjs.map → logger-DP2BjQ93.mjs.map} +1 -1
- package/dist/multiline-EyzjEwn9.mjs +3 -0
- package/dist/{multiline-sfHpTZZK.mjs.map → multiline-EyzjEwn9.mjs.map} +1 -1
- package/dist/node-builtins-oBl7EbyV.mjs +2 -0
- package/dist/{node-builtins-CmaL2Cbq.mjs.map → node-builtins-oBl7EbyV.mjs.map} +1 -1
- package/dist/package-json-C690ceex.mjs +2 -0
- package/dist/{package-json-8b0O9TlX.mjs.map → package-json-C690ceex.mjs.map} +1 -1
- package/dist/package-json-CmqhDJ__.mjs +1 -0
- package/dist/parser/service/tailordb/type-source.d.mts +5 -5
- package/dist/parser/service/tailordb/types.d.mts +4 -4
- package/dist/platform-serialize-DkiTdHOt.mjs +2 -0
- package/dist/{platform-serialize-RoRtBS0v.mjs.map → platform-serialize-DkiTdHOt.mjs.map} +1 -1
- package/dist/plugin/builtin/enum-constants/index.d.mts +1 -1
- package/dist/plugin/builtin/enum-constants/index.mjs +5 -114
- package/dist/plugin/builtin/enum-constants/index.mjs.map +1 -1
- package/dist/plugin/builtin/file-utils/index.d.mts +1 -1
- package/dist/plugin/builtin/file-utils/index.mjs +22 -101
- package/dist/plugin/builtin/file-utils/index.mjs.map +1 -1
- package/dist/plugin/builtin/kysely-type/index.d.mts +9 -2
- package/dist/plugin/builtin/kysely-type/index.mjs +1 -275
- package/dist/plugin/builtin/seed/index.d.mts +5 -0
- package/dist/plugin/builtin/seed/index.mjs +1 -3
- package/dist/plugin/builtin/seed/seed-type-processor.d.mts +4 -6
- package/dist/plugin/get-generated-table.d.mts +16 -0
- package/dist/plugin/index.d.mts +3 -2
- package/dist/plugin/index.mjs +1 -251
- package/dist/plugin/index.mjs.map +1 -1
- package/dist/plugin/types.d.mts +32 -25
- package/dist/plugin/with-context.d.mts +4 -4
- package/dist/register-ts-hook-Drnaproy.mjs +640 -0
- package/dist/register-ts-hook-Drnaproy.mjs.map +1 -0
- package/dist/registry-HlEaGvl5.mjs +2 -0
- package/dist/{registry-BIGVUrMB.mjs.map → registry-HlEaGvl5.mjs.map} +1 -1
- package/dist/repl-editor-BG1aDOfH.mjs +2 -0
- package/dist/{repl-editor-BCozyiNq.mjs.map → repl-editor-BG1aDOfH.mjs.map} +1 -1
- package/dist/runtime/aigateway.mjs +1 -3
- package/dist/runtime/authconnection.mjs +1 -3
- package/dist/runtime/context.mjs +1 -3
- package/dist/runtime/file.d.mts +28 -28
- package/dist/runtime/file.mjs +1 -3
- package/dist/runtime/globals.mjs +1 -1
- package/dist/runtime/iconv.mjs +1 -3
- package/dist/runtime/idp.mjs +1 -3
- package/dist/runtime/index.mjs +1 -11
- package/dist/runtime/logger.mjs +1 -3
- package/dist/runtime/secretmanager.mjs +1 -3
- package/dist/runtime/types.d.mts +1 -1
- package/dist/runtime/workflow.mjs +1 -3
- package/dist/schema-Ze_dI5VX.mjs +2 -0
- package/dist/schema-Ze_dI5VX.mjs.map +1 -0
- package/dist/secret-file-C9wp_FCX.mjs +2 -0
- package/dist/{secret-file-C3J4Gy8r.mjs.map → secret-file-C9wp_FCX.mjs.map} +1 -1
- package/dist/secretmanager-5olfnI1b.mjs +2 -0
- package/dist/{secretmanager-IY4UvinW.mjs.map → secretmanager-5olfnI1b.mjs.map} +1 -1
- package/dist/secretmanager-vHQoXdQz.mjs +2 -0
- package/dist/{secretmanager-CYlpffsz.mjs.map → secretmanager-vHQoXdQz.mjs.map} +1 -1
- package/dist/seed/index.d.mts +4 -4
- package/dist/seed/index.mjs +8 -244
- package/dist/seed/index.mjs.map +1 -1
- package/dist/seed-DwqRFdqP.mjs +207 -0
- package/dist/seed-DwqRFdqP.mjs.map +1 -0
- package/dist/service-BVe9u2Rt.mjs +7 -0
- package/dist/service-BVe9u2Rt.mjs.map +1 -0
- package/dist/service-CpZELSBa.mjs +1 -0
- package/dist/service-DlgaUO4V.mjs +2 -0
- package/dist/{service-hZskxZmg.mjs.map → service-DlgaUO4V.mjs.map} +1 -1
- package/dist/service_pb-DGKCLuAs.mjs +2 -0
- package/dist/{service_pb-BEWj1pOV.mjs.map → service_pb-DGKCLuAs.mjs.map} +1 -1
- package/dist/service_pb-_aeFE-Nv.mjs +1 -0
- package/dist/telemetry-Bklv9kQY.mjs +2 -0
- package/dist/{telemetry-BRVdwh14.mjs.map → telemetry-Bklv9kQY.mjs.map} +1 -1
- package/dist/telemetry-DXHP3VVi.mjs +1 -0
- package/dist/type-source--ZNcV8RJ.mjs +2 -0
- package/dist/type-source--ZNcV8RJ.mjs.map +1 -0
- package/dist/types/aigateway.generated.d.mts +2 -2
- package/dist/types/auth.generated.d.mts +3 -3
- package/dist/types/executor.generated.d.mts +2 -2
- package/dist/types/tailordb.generated.d.mts +12 -12
- package/dist/user-agent-vdHYF3QL.mjs +2 -0
- package/dist/{user-agent-Bgsszb5I.mjs.map → user-agent-vdHYF3QL.mjs.map} +1 -1
- package/dist/utils/test/index.d.mts +4 -4
- package/dist/utils/test/index.mjs +1 -109
- package/dist/utils/test/index.mjs.map +1 -1
- package/dist/vitest/environment.mjs +1 -41
- package/dist/vitest/environment.mjs.map +1 -1
- package/dist/vitest/index.mjs +1 -1980
- package/dist/vitest/index.mjs.map +1 -1
- package/dist/vitest/mocks/file.d.mts +8 -8
- package/dist/vitest/setup.mjs +1 -140
- package/dist/vitest/setup.mjs.map +1 -1
- package/dist/wait-point-invoker-eiP-IIux.mjs +2 -0
- package/dist/wait-point-invoker-eiP-IIux.mjs.map +1 -0
- package/dist/wait-point-registry-BrkwfyjS.mjs +2 -0
- package/dist/{wait-point-registry-TL99zotw.mjs.map → wait-point-registry-BrkwfyjS.mjs.map} +1 -1
- package/dist/workflow-Cs9ISw6j.mjs +2 -0
- package/dist/{workflow-Bamae_Yc.mjs.map → workflow-Cs9ISw6j.mjs.map} +1 -1
- package/dist/workspace_resource_pb--GeYQPXu.mjs +2 -0
- package/dist/{workspace_resource_pb-HNIL_Vfj.mjs.map → workspace_resource_pb--GeYQPXu.mjs.map} +1 -1
- package/docs/cli/application.md +3 -1
- package/docs/cli/function.md +77 -13
- package/docs/cli/setup.md +24 -14
- package/docs/cli/tailordb.md +32 -30
- package/docs/cli/workspace.md +2 -2
- package/docs/cli-reference.md +23 -22
- package/docs/configuration.md +2 -2
- package/docs/github-actions.md +10 -9
- package/docs/migration/v2.md +16 -4
- package/docs/migration/v3.md +123 -0
- package/docs/plugin/custom.md +130 -85
- package/docs/plugin/index.md +3 -3
- package/docs/quickstart.md +1 -1
- package/docs/services/aigateway.md +33 -9
- package/docs/services/executor.md +5 -1
- package/docs/services/tailordb-migration.md +68 -54
- package/docs/services/tailordb.md +7 -7
- package/docs/services/workflow.md +10 -9
- package/docs/testing.md +1 -1
- package/package.json +16 -16
- package/postinstall.mjs +1 -1
- package/dist/aigateway-DR4Kwuik.mjs +0 -9
- package/dist/application-BZfk4HKm.mjs +0 -3
- package/dist/application-F-nl107y.mjs +0 -6019
- package/dist/application-F-nl107y.mjs.map +0 -1
- package/dist/assert-DBxo8jPo.mjs +0 -9
- package/dist/authconnection-CZvi9ANm.mjs +0 -9
- package/dist/brand-Eo4pLXPJ.mjs +0 -36
- package/dist/context-DYQVYWqZ.mjs +0 -23
- package/dist/crashreport-CIIfLnoO.mjs +0 -423
- package/dist/crashreport-CINZ5dVN.mjs +0 -3
- package/dist/errors-BVb6vYGy.mjs +0 -89
- package/dist/errors-BVb6vYGy.mjs.map +0 -1
- package/dist/file-BUcmVIH2.mjs +0 -58
- package/dist/file-BUcmVIH2.mjs.map +0 -1
- package/dist/globals-B2nlxBrz.mjs +0 -126
- package/dist/iconv-QWaZh0TT.mjs +0 -38
- package/dist/idp-RA_swu-h.mjs +0 -82
- package/dist/interceptor-e33JtsC-.mjs +0 -33
- package/dist/logger-BtX0suGY.mjs +0 -48
- package/dist/logger-DSdExfor.mjs +0 -358
- package/dist/multiline-sfHpTZZK.mjs +0 -38
- package/dist/node-builtins-CmaL2Cbq.mjs +0 -36
- package/dist/package-json-8b0O9TlX.mjs +0 -17
- package/dist/package-json-Cv2Z-TqQ.mjs +0 -3
- package/dist/platform-serialize-RoRtBS0v.mjs +0 -46
- package/dist/plugin/builtin/kysely-type/index.mjs.map +0 -1
- package/dist/plugin/builtin/seed/types.d.mts +0 -2
- package/dist/plugin/get-generated-type.d.mts +0 -16
- package/dist/register-ts-hook-ClI226n2.mjs +0 -25543
- package/dist/register-ts-hook-ClI226n2.mjs.map +0 -1
- package/dist/registry-BIGVUrMB.mjs +0 -54
- package/dist/repl-editor-BCozyiNq.mjs +0 -251
- package/dist/schema--xYWRGfe.mjs +0 -639
- package/dist/schema--xYWRGfe.mjs.map +0 -1
- package/dist/secret-file-C3J4Gy8r.mjs +0 -64
- package/dist/secretmanager-CYlpffsz.mjs +0 -13
- package/dist/secretmanager-IY4UvinW.mjs +0 -131
- package/dist/seed-xqM9WIHP.mjs +0 -483
- package/dist/seed-xqM9WIHP.mjs.map +0 -1
- package/dist/service-C_WpbKHu.mjs +0 -898
- package/dist/service-C_WpbKHu.mjs.map +0 -1
- package/dist/service-D1RCdzIL.mjs +0 -3
- package/dist/service-hZskxZmg.mjs +0 -131
- package/dist/service_pb-BEWj1pOV.mjs +0 -167
- package/dist/service_pb-BjlhvK9E.mjs +0 -3
- package/dist/telemetry-BRVdwh14.mjs +0 -84
- package/dist/telemetry-CkbkeJxl.mjs +0 -3
- package/dist/type-source-DH_LH20p.mjs +0 -13
- package/dist/type-source-DH_LH20p.mjs.map +0 -1
- package/dist/user-agent-Bgsszb5I.mjs +0 -28
- package/dist/wait-point-invoker-__oE88_P.mjs +0 -148
- package/dist/wait-point-invoker-__oE88_P.mjs.map +0 -1
- package/dist/wait-point-registry-TL99zotw.mjs +0 -47
- package/dist/workflow-Bamae_Yc.mjs +0 -34
- package/dist/workspace_resource_pb-HNIL_Vfj.mjs +0 -860
|
@@ -5,7 +5,7 @@ type FileResolver = (method: string, call: FileCall) => unknown;
|
|
|
5
5
|
interface FileCall {
|
|
6
6
|
method: string;
|
|
7
7
|
namespace: string;
|
|
8
|
-
|
|
8
|
+
tableName: string;
|
|
9
9
|
fieldName: string;
|
|
10
10
|
recordId: string;
|
|
11
11
|
}
|
|
@@ -46,13 +46,13 @@ declare function mockFile(options?: MockFileOptions): {
|
|
|
46
46
|
calls: FileCall[];
|
|
47
47
|
clear(): void;
|
|
48
48
|
reset(): void;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
getMetadata: Mock<(namespace: string,
|
|
54
|
-
downloadStream: Mock<(namespace: string,
|
|
55
|
-
uploadStream: Mock<(namespace: string,
|
|
49
|
+
delete: Mock<(namespace: string, tableName: string, fieldName: string, recordId: string) => Promise<void>>;
|
|
50
|
+
upload: Mock<(namespace: string, tableName: string, fieldName: string, recordId: string, data: string | ArrayBuffer | Uint8Array | number[], options?: FileUploadOptions) => Promise<FileUploadResponse>>;
|
|
51
|
+
download: Mock<(namespace: string, tableName: string, fieldName: string, recordId: string) => Promise<FileDownloadResponse>>;
|
|
52
|
+
downloadAsBase64: Mock<(namespace: string, tableName: string, fieldName: string, recordId: string) => Promise<FileDownloadAsBase64Response>>;
|
|
53
|
+
getMetadata: Mock<(namespace: string, tableName: string, fieldName: string, recordId: string) => Promise<FileMetadata>>;
|
|
54
|
+
downloadStream: Mock<(namespace: string, tableName: string, fieldName: string, recordId: string) => Promise<FileDownloadStreamResponse>>;
|
|
55
|
+
uploadStream: Mock<(namespace: string, tableName: string, fieldName: string, recordId: string, readableStream: ReadableStream<Uint8Array | ArrayBuffer>, options?: FileUploadStreamOptions) => Promise<FileUploadResponse>>;
|
|
56
56
|
} & Disposable;
|
|
57
57
|
//#endregion
|
|
58
58
|
export { MockFileOptions, mockFile };
|
package/dist/vitest/setup.mjs
CHANGED
|
@@ -1,141 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { t as mockSecretmanager } from "../secretmanager-IY4UvinW.mjs";
|
|
3
|
-
import { pathToFileURL } from "node:url";
|
|
4
|
-
import { afterEach, beforeAll, beforeEach } from "vitest";
|
|
5
|
-
|
|
6
|
-
//#region src/vitest/setup.ts
|
|
7
|
-
/**
|
|
8
|
-
* Vitest setup file that removes Node.js globals which Vitest depends on
|
|
9
|
-
* but are not available in the Tailor Platform runtime.
|
|
10
|
-
*
|
|
11
|
-
* These globals cannot be removed in the environment's setup() because
|
|
12
|
-
* Vitest's runner needs them during initialization. By using beforeEach/afterEach,
|
|
13
|
-
* they are only removed during user test code execution.
|
|
14
|
-
*
|
|
15
|
-
* This file is auto-injected by tailorRuntime() but only activates when
|
|
16
|
-
* the tailor-runtime environment is active (detected via __tailorRuntimeActive,
|
|
17
|
-
* a flag set by injectMocks() during environment setup).
|
|
18
|
-
*/
|
|
19
|
-
const BLOCKED_GLOBALS = ["performance"];
|
|
20
|
-
/**
|
|
21
|
-
* Reference-counted lifecycle for blocked globals.
|
|
22
|
-
*
|
|
23
|
-
* Concurrent tests in the same Vitest worker (`test.concurrent`) interleave
|
|
24
|
-
* their beforeEach/afterEach hooks: a naive `let saved` shared across hooks
|
|
25
|
-
* would let one test's `afterEach` restore `performance` mid-execution of
|
|
26
|
-
* another test. Reference counting keeps the globals removed for the union
|
|
27
|
-
* of all overlapping test scopes — the property is removed on first entry
|
|
28
|
-
* and restored only when the last test exits.
|
|
29
|
-
* @returns Lifecycle hooks
|
|
30
|
-
*/
|
|
31
|
-
function createBlockedGlobalsLifecycle() {
|
|
32
|
-
let active = 0;
|
|
33
|
-
let saved = {};
|
|
34
|
-
return {
|
|
35
|
-
get active() {
|
|
36
|
-
return active;
|
|
37
|
-
},
|
|
38
|
-
enter(globalObj, keys) {
|
|
39
|
-
if (active === 0) saved = removeBlockedGlobals(globalObj, keys);
|
|
40
|
-
active++;
|
|
41
|
-
},
|
|
42
|
-
exit(globalObj) {
|
|
43
|
-
if (active === 0) return;
|
|
44
|
-
active--;
|
|
45
|
-
if (active === 0) {
|
|
46
|
-
restoreBlockedGlobals(globalObj, saved);
|
|
47
|
-
saved = {};
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
const lifecycle = createBlockedGlobalsLifecycle();
|
|
53
|
-
function isTailorRuntime() {
|
|
54
|
-
return RUNTIME_FLAG_KEY in globalThis;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Extract a vault store from a secrets-shaped value.
|
|
58
|
-
*
|
|
59
|
-
* `defineSecretManager()` returns `{ vaults, options, get, getAll }` (get/getAll
|
|
60
|
-
* are non-enumerable). When that shape is present, the actual vaults live
|
|
61
|
-
* under `.vaults`. Otherwise fall back to treating the object itself as the
|
|
62
|
-
* vault map (for plain object configs).
|
|
63
|
-
* @param secrets - Value from `appConfig.secrets` or `config.secrets`
|
|
64
|
-
* @returns Vault store, or null if the value is unusable
|
|
65
|
-
*/
|
|
66
|
-
function extractVaultStore(secrets) {
|
|
67
|
-
if (!secrets || typeof secrets !== "object") return null;
|
|
68
|
-
const source = "vaults" in secrets && typeof secrets.vaults === "object" && secrets.vaults !== null ? secrets.vaults : secrets;
|
|
69
|
-
const store = {};
|
|
70
|
-
for (const [vaultName, vaultData] of Object.entries(source)) if (typeof vaultData === "object" && vaultData !== null) store[vaultName] = { ...vaultData };
|
|
71
|
-
return Object.keys(store).length > 0 ? store : null;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Load and parse secrets from a tailor.config.ts file.
|
|
75
|
-
*
|
|
76
|
-
* Returns a vault store on success, or `null` on any failure (missing config,
|
|
77
|
-
* import failure, missing/invalid secrets shape). Errors are swallowed so a
|
|
78
|
-
* misconfigured project still boots — the user can set secrets manually via
|
|
79
|
-
* `mockSecretmanager().setSecrets()`.
|
|
80
|
-
* @param configPath - Absolute path to tailor.config.ts
|
|
81
|
-
* @returns Vault store keyed by vault name, or null if unavailable
|
|
82
|
-
*/
|
|
83
|
-
async function loadSecretsFromConfig(configPath) {
|
|
84
|
-
try {
|
|
85
|
-
const config = await import(pathToFileURL(configPath).href);
|
|
86
|
-
return extractVaultStore(config.default?.secrets ?? config.secrets);
|
|
87
|
-
} catch {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
beforeAll(async () => {
|
|
92
|
-
if (!isTailorRuntime()) return;
|
|
93
|
-
const configPath = process.env.__TAILOR_RUNTIME_CONFIG;
|
|
94
|
-
if (!configPath) return;
|
|
95
|
-
const store = await loadSecretsFromConfig(configPath);
|
|
96
|
-
if (store) mockSecretmanager().setSecrets(store);
|
|
97
|
-
});
|
|
98
|
-
/**
|
|
99
|
-
* Remove the given globals from `globalObj`, returning the descriptors that
|
|
100
|
-
* were actually deleted so `restoreBlockedGlobals` can put them back.
|
|
101
|
-
*
|
|
102
|
-
* Mirrors environment.ts: non-configurable properties are skipped instead of
|
|
103
|
-
* deleted, so `delete` never throws in strict-mode runtimes that lock them
|
|
104
|
-
* down. Only properties whose deletion actually happened are returned, so the
|
|
105
|
-
* caller restores nothing for the skipped case.
|
|
106
|
-
* @param globalObj - Target object (typically `globalThis`)
|
|
107
|
-
* @param keys - Property names to remove
|
|
108
|
-
* @returns Map of removed descriptors keyed by property name
|
|
109
|
-
*/
|
|
110
|
-
function removeBlockedGlobals(globalObj, keys) {
|
|
111
|
-
const removed = {};
|
|
112
|
-
for (const key of keys) {
|
|
113
|
-
const descriptor = Object.getOwnPropertyDescriptor(globalObj, key);
|
|
114
|
-
if (descriptor?.configurable) {
|
|
115
|
-
removed[key] = descriptor;
|
|
116
|
-
delete globalObj[key];
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return removed;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Restore previously-removed globals onto `globalObj` from a `SavedGlobals`
|
|
123
|
-
* map produced by `removeBlockedGlobals`.
|
|
124
|
-
* @param globalObj - Target object (typically `globalThis`)
|
|
125
|
-
* @param saved - Descriptors to re-define
|
|
126
|
-
*/
|
|
127
|
-
function restoreBlockedGlobals(globalObj, saved) {
|
|
128
|
-
for (const [key, descriptor] of Object.entries(saved)) if (descriptor) Object.defineProperty(globalObj, key, descriptor);
|
|
129
|
-
}
|
|
130
|
-
beforeEach(() => {
|
|
131
|
-
if (!isTailorRuntime()) return;
|
|
132
|
-
lifecycle.enter(globalThis, BLOCKED_GLOBALS);
|
|
133
|
-
});
|
|
134
|
-
afterEach(() => {
|
|
135
|
-
if (!isTailorRuntime()) return;
|
|
136
|
-
lifecycle.exit(globalThis);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
//#endregion
|
|
140
|
-
export { createBlockedGlobalsLifecycle, extractVaultStore, loadSecretsFromConfig, removeBlockedGlobals, restoreBlockedGlobals };
|
|
1
|
+
import{t as e}from"../globals-CMHSnj4w.mjs";import{t}from"../secretmanager-5olfnI1b.mjs";import{pathToFileURL as n}from"node:url";import{afterEach as r,beforeAll as i,beforeEach as a}from"vitest";const o=[`performance`];function createBlockedGlobalsLifecycle(){let e=0,t={};return{get active(){return e},enter(n,r){e===0&&(t=removeBlockedGlobals(n,r)),e++},exit(n){e!==0&&(e--,e===0&&(restoreBlockedGlobals(n,t),t={}))}}}const s=createBlockedGlobalsLifecycle();function isTailorRuntime(){return e in globalThis}function extractVaultStore(e){if(!e||typeof e!=`object`)return null;let t=`vaults`in e&&typeof e.vaults==`object`&&e.vaults!==null?e.vaults:e,n={};for(let[e,r]of Object.entries(t))typeof r==`object`&&r&&(n[e]={...r});return Object.keys(n).length>0?n:null}async function loadSecretsFromConfig(e){try{let t=await import(n(e).href);return extractVaultStore(t.default?.secrets??t.secrets)}catch{return null}}i(async()=>{if(!isTailorRuntime())return;let e=process.env.__TAILOR_RUNTIME_CONFIG;if(!e)return;let n=await loadSecretsFromConfig(e);n&&t().setSecrets(n)});function removeBlockedGlobals(e,t){let n={};for(let r of t){let t=Object.getOwnPropertyDescriptor(e,r);t?.configurable&&(n[r]=t,delete e[r])}return n}function restoreBlockedGlobals(e,t){for(let[n,r]of Object.entries(t))r&&Object.defineProperty(e,n,r)}a(()=>{isTailorRuntime()&&s.enter(globalThis,o)}),r(()=>{isTailorRuntime()&&s.exit(globalThis)});export{createBlockedGlobalsLifecycle,extractVaultStore,loadSecretsFromConfig,removeBlockedGlobals,restoreBlockedGlobals};
|
|
141
2
|
//# sourceMappingURL=setup.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup.mjs","names":[],"sources":["../../src/vitest/setup.ts"],"sourcesContent":["/**\n * Vitest setup file that removes Node.js globals which Vitest depends on\n * but are not available in the Tailor Platform runtime.\n *\n * These globals cannot be removed in the environment's setup() because\n * Vitest's runner needs them during initialization. By using beforeEach/afterEach,\n * they are only removed during user test code execution.\n *\n * This file is auto-injected by tailorRuntime() but only activates when\n * the tailor-runtime environment is active (detected via __tailorRuntimeActive,\n * a flag set by injectMocks() during environment setup).\n */\nimport { pathToFileURL } from \"node:url\";\nimport { afterEach, beforeAll, beforeEach } from \"vitest\";\nimport { RUNTIME_FLAG_KEY, mockSecretmanager } from \"./mock\";\n\n// Globals that Vitest internals depend on but don't exist in the platform runtime.\n// Removed before each test, restored after.\nconst BLOCKED_GLOBALS = [\"performance\"] as const;\n\ntype SavedGlobals = Record<string, PropertyDescriptor | undefined>;\n\n/**\n * Reference-counted lifecycle for blocked globals.\n *\n * Concurrent tests in the same Vitest worker (`test.concurrent`) interleave\n * their beforeEach/afterEach hooks: a naive `let saved` shared across hooks\n * would let one test's `afterEach` restore `performance` mid-execution of\n * another test. Reference counting keeps the globals removed for the union\n * of all overlapping test scopes — the property is removed on first entry\n * and restored only when the last test exits.\n * @returns Lifecycle hooks\n */\nexport function createBlockedGlobalsLifecycle(): {\n enter: (globalObj: Record<string, unknown>, keys: readonly string[]) => void;\n exit: (globalObj: Record<string, unknown>) => void;\n readonly active: number;\n} {\n let active = 0;\n let saved: SavedGlobals = {};\n return {\n get active() {\n return active;\n },\n enter(globalObj, keys) {\n if (active === 0) saved = removeBlockedGlobals(globalObj, keys);\n active++;\n },\n exit(globalObj) {\n // Defensive guard — in practice every `enter` is paired with `exit`,\n // but a hook crash could desync the counter.\n if (active === 0) return;\n active--;\n if (active === 0) {\n restoreBlockedGlobals(globalObj, saved);\n saved = {};\n }\n },\n };\n}\n\nconst lifecycle = createBlockedGlobalsLifecycle();\n\nfunction isTailorRuntime(): boolean {\n return RUNTIME_FLAG_KEY in globalThis;\n}\n\n/**\n * Extract a vault store from a secrets-shaped value.\n *\n * `defineSecretManager()` returns `{ vaults, options, get, getAll }` (get/getAll\n * are non-enumerable). When that shape is present, the actual vaults live\n * under `.vaults`. Otherwise fall back to treating the object itself as the\n * vault map (for plain object configs).\n * @param secrets - Value from `appConfig.secrets` or `config.secrets`\n * @returns Vault store, or null if the value is unusable\n */\nexport function extractVaultStore(secrets: unknown): Record<string, Record<string, string>> | null {\n if (!secrets || typeof secrets !== \"object\") return null;\n\n const source =\n \"vaults\" in secrets &&\n typeof (secrets as { vaults?: unknown }).vaults === \"object\" &&\n (secrets as { vaults?: unknown }).vaults !== null\n ? (
|
|
1
|
+
{"version":3,"file":"setup.mjs","names":[],"sources":["../../src/vitest/setup.ts"],"sourcesContent":["/**\n * Vitest setup file that removes Node.js globals which Vitest depends on\n * but are not available in the Tailor Platform runtime.\n *\n * These globals cannot be removed in the environment's setup() because\n * Vitest's runner needs them during initialization. By using beforeEach/afterEach,\n * they are only removed during user test code execution.\n *\n * This file is auto-injected by tailorRuntime() but only activates when\n * the tailor-runtime environment is active (detected via __tailorRuntimeActive,\n * a flag set by injectMocks() during environment setup).\n */\nimport { pathToFileURL } from \"node:url\";\nimport { afterEach, beforeAll, beforeEach } from \"vitest\";\nimport { RUNTIME_FLAG_KEY, mockSecretmanager } from \"./mock\";\n\n// Globals that Vitest internals depend on but don't exist in the platform runtime.\n// Removed before each test, restored after.\nconst BLOCKED_GLOBALS = [\"performance\"] as const;\n\ntype SavedGlobals = Record<string, PropertyDescriptor | undefined>;\n\n/**\n * Reference-counted lifecycle for blocked globals.\n *\n * Concurrent tests in the same Vitest worker (`test.concurrent`) interleave\n * their beforeEach/afterEach hooks: a naive `let saved` shared across hooks\n * would let one test's `afterEach` restore `performance` mid-execution of\n * another test. Reference counting keeps the globals removed for the union\n * of all overlapping test scopes — the property is removed on first entry\n * and restored only when the last test exits.\n * @returns Lifecycle hooks\n */\nexport function createBlockedGlobalsLifecycle(): {\n enter: (globalObj: Record<string, unknown>, keys: readonly string[]) => void;\n exit: (globalObj: Record<string, unknown>) => void;\n readonly active: number;\n} {\n let active = 0;\n let saved: SavedGlobals = {};\n return {\n get active() {\n return active;\n },\n enter(globalObj, keys) {\n if (active === 0) saved = removeBlockedGlobals(globalObj, keys);\n active++;\n },\n exit(globalObj) {\n // Defensive guard — in practice every `enter` is paired with `exit`,\n // but a hook crash could desync the counter.\n if (active === 0) return;\n active--;\n if (active === 0) {\n restoreBlockedGlobals(globalObj, saved);\n saved = {};\n }\n },\n };\n}\n\nconst lifecycle = createBlockedGlobalsLifecycle();\n\nfunction isTailorRuntime(): boolean {\n return RUNTIME_FLAG_KEY in globalThis;\n}\n\n/**\n * Extract a vault store from a secrets-shaped value.\n *\n * `defineSecretManager()` returns `{ vaults, options, get, getAll }` (get/getAll\n * are non-enumerable). When that shape is present, the actual vaults live\n * under `.vaults`. Otherwise fall back to treating the object itself as the\n * vault map (for plain object configs).\n * @param secrets - Value from `appConfig.secrets` or `config.secrets`\n * @returns Vault store, or null if the value is unusable\n */\nexport function extractVaultStore(secrets: unknown): Record<string, Record<string, string>> | null {\n if (!secrets || typeof secrets !== \"object\") return null;\n\n const source =\n \"vaults\" in secrets &&\n typeof (secrets as { vaults?: unknown }).vaults === \"object\" &&\n (secrets as { vaults?: unknown }).vaults !== null\n ? (secrets as { vaults: Record<string, unknown> }).vaults\n : (secrets as Record<string, unknown>);\n\n const store: Record<string, Record<string, string>> = {};\n for (const [vaultName, vaultData] of Object.entries(source)) {\n if (typeof vaultData === \"object\" && vaultData !== null) {\n store[vaultName] = { ...(vaultData as Record<string, string>) };\n }\n }\n return Object.keys(store).length > 0 ? store : null;\n}\n\n/**\n * Load and parse secrets from a tailor.config.ts file.\n *\n * Returns a vault store on success, or `null` on any failure (missing config,\n * import failure, missing/invalid secrets shape). Errors are swallowed so a\n * misconfigured project still boots — the user can set secrets manually via\n * `mockSecretmanager().setSecrets()`.\n * @param configPath - Absolute path to tailor.config.ts\n * @returns Vault store keyed by vault name, or null if unavailable\n */\nexport async function loadSecretsFromConfig(\n configPath: string,\n): Promise<Record<string, Record<string, string>> | null> {\n try {\n // Convert to file URL so absolute Windows paths (e.g. \"C:\\...\") parse as\n // valid ESM specifiers.\n const config = await import(pathToFileURL(configPath).href);\n const appConfig = config.default;\n const secrets = appConfig?.secrets ?? config.secrets;\n return extractVaultStore(secrets);\n } catch {\n return null;\n }\n}\n\n// Load secrets from tailor.config.ts if config path is provided via env var\nbeforeAll(async () => {\n if (!isTailorRuntime()) return;\n const configPath = process.env.__TAILOR_RUNTIME_CONFIG;\n if (!configPath) return;\n\n const store = await loadSecretsFromConfig(configPath);\n if (store) {\n // Acquire without `using`: this is a one-time global seed that must persist\n // across tests, so we deliberately do not dispose (which would reset it).\n mockSecretmanager().setSecrets(store);\n }\n});\n\n/**\n * Remove the given globals from `globalObj`, returning the descriptors that\n * were actually deleted so `restoreBlockedGlobals` can put them back.\n *\n * Mirrors environment.ts: non-configurable properties are skipped instead of\n * deleted, so `delete` never throws in strict-mode runtimes that lock them\n * down. Only properties whose deletion actually happened are returned, so the\n * caller restores nothing for the skipped case.\n * @param globalObj - Target object (typically `globalThis`)\n * @param keys - Property names to remove\n * @returns Map of removed descriptors keyed by property name\n */\nexport function removeBlockedGlobals(\n globalObj: Record<string, unknown>,\n keys: readonly string[],\n): SavedGlobals {\n const removed: SavedGlobals = {};\n for (const key of keys) {\n const descriptor = Object.getOwnPropertyDescriptor(globalObj, key);\n if (descriptor?.configurable) {\n removed[key] = descriptor;\n delete globalObj[key];\n }\n }\n return removed;\n}\n\n/**\n * Restore previously-removed globals onto `globalObj` from a `SavedGlobals`\n * map produced by `removeBlockedGlobals`.\n * @param globalObj - Target object (typically `globalThis`)\n * @param saved - Descriptors to re-define\n */\nexport function restoreBlockedGlobals(\n globalObj: Record<string, unknown>,\n saved: SavedGlobals,\n): void {\n for (const [key, descriptor] of Object.entries(saved)) {\n if (descriptor) {\n Object.defineProperty(globalObj, key, descriptor);\n }\n }\n}\n\nbeforeEach(() => {\n if (!isTailorRuntime()) return;\n lifecycle.enter(globalThis, BLOCKED_GLOBALS);\n});\n\nafterEach(() => {\n if (!isTailorRuntime()) return;\n lifecycle.exit(globalThis);\n});\n"],"mappings":"oMAkBA,MAAM,EAAkB,CAAC,aAAa,EAetC,SAAgB,+BAId,CACA,IAAI,EAAS,EACT,EAAsB,CAAC,EAC3B,MAAO,CACL,IAAI,QAAS,CACX,OAAO,CACT,EACA,MAAM,EAAW,EAAM,CACjB,IAAW,IAAG,EAAQ,qBAAqB,EAAW,CAAI,GAC9D,GACF,EACA,KAAK,EAAW,CAGV,IAAW,IACf,IACI,IAAW,IACb,sBAAsB,EAAW,CAAK,EACtC,EAAQ,CAAC,GAEb,CACF,CACF,CAEA,MAAM,EAAY,8BAA8B,EAEhD,SAAS,iBAA2B,CAClC,OAAO,KAAoB,UAC7B,CAYA,SAAgB,kBAAkB,EAAiE,CACjG,GAAI,CAAC,GAAW,OAAO,GAAY,SAAU,OAAO,KAEpD,IAAM,EACJ,WAAY,GACZ,OAAQ,EAAiC,QAAW,UACnD,EAAiC,SAAW,KACxC,EAAgD,OAChD,EAED,EAAgD,CAAC,EACvD,IAAK,GAAM,CAAC,EAAW,KAAc,OAAO,QAAQ,CAAM,EACpD,OAAO,GAAc,UAAY,IACnC,EAAM,GAAa,CAAE,GAAI,CAAqC,GAGlE,OAAO,OAAO,KAAK,CAAK,CAAC,CAAC,OAAS,EAAI,EAAQ,IACjD,CAYA,eAAsB,sBACpB,EACwD,CACxD,GAAI,CAGF,IAAM,EAAS,MAAM,OAAO,EAAc,CAAU,CAAC,CAAC,MAGtD,OAAO,kBAFW,EAAO,SACE,SAAW,EAAO,OACb,CAClC,MAAQ,CACN,OAAO,IACT,CACF,CAGA,EAAU,SAAY,CACpB,GAAI,CAAC,gBAAgB,EAAG,OACxB,IAAM,EAAa,QAAQ,IAAI,wBAC/B,GAAI,CAAC,EAAY,OAEjB,IAAM,EAAQ,MAAM,sBAAsB,CAAU,EAChD,GAGF,EAAkB,CAAC,CAAC,WAAW,CAAK,CAExC,CAAC,EAcD,SAAgB,qBACd,EACA,EACc,CACd,IAAM,EAAwB,CAAC,EAC/B,IAAK,IAAM,KAAO,EAAM,CACtB,IAAM,EAAa,OAAO,yBAAyB,EAAW,CAAG,EAC7D,GAAY,eACd,EAAQ,GAAO,EACf,OAAO,EAAU,GAErB,CACA,OAAO,CACT,CAQA,SAAgB,sBACd,EACA,EACM,CACN,IAAK,GAAM,CAAC,EAAK,KAAe,OAAO,QAAQ,CAAK,EAC9C,GACF,OAAO,eAAe,EAAW,EAAK,CAAU,CAGtD,CAEA,MAAiB,CACV,gBAAgB,GACrB,EAAU,MAAM,WAAY,CAAe,CAC7C,CAAC,EAED,MAAgB,CACT,gBAAgB,GACrB,EAAU,KAAK,UAAU,CAC3B,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{AsyncLocalStorage as e}from"node:async_hooks";const t=`__tailorWorkflowTestEnv`;let n;function workflowInvokerStorage(){return n||=new e,n}function readWorkflowTestEnv(){return globalThis[t]}function writeWorkflowTestEnv(e){globalThis[t]=e}function clearWorkflowTestEnv(){delete globalThis[t]}function withWorkflowTestInvoker(e,t){return workflowInvokerStorage().run(e,t)}function readRuntimeInvoker(){let e=globalThis.tailor?.context?.getInvoker,t=e?.();return t?{id:t.id,type:t.type,workspaceId:t.workspaceId,attributes:t.attributeMap??(Array.isArray(t.attributes)?{}:t.attributes??{}),attributeList:t.attributeList??(Array.isArray(t.attributes)?t.attributes:[])}:null}function buildJobContext(){let e=n?.getStore(),t=e===void 0?readRuntimeInvoker():e,r=readWorkflowTestEnv();return r===void 0?{env:{},invoker:t}:{env:{...r},invoker:t}}const r=Symbol.for(`tailor-platform/sdk:wait-point-invoker`),i=Symbol.for(`tailor-platform/sdk:wait-point-key`);function getPlatformWorkflow(){let e=globalThis.tailor?.workflow;if(!e)throw Error("tailor.workflow is not available. Run tests in the `tailor-runtime` Vitest environment, or acquire mockWorkflow() from @tailor-platform/sdk/vitest and set a wait/resolve handler.");return e}function createWaitPointInvoker(){return{wait(e,t){return getPlatformWorkflow().wait(e,t)},async resolve(e,t,n){await getPlatformWorkflow().resolve(t,e,n)}}}function attachWaitPointInvoker(e,t){return Object.defineProperty(e,r,{value:t,enumerable:!1,configurable:!1,writable:!1}),e}function getWaitPointInvoker(e){return e[r]}function attachWaitPointKey(e,t){return Object.defineProperty(e,i,{value:t,enumerable:!1,configurable:!1,writable:!1}),e}function getWaitPointKey(e){return e[i]}export{getWaitPointKey as a,readWorkflowTestEnv as c,getWaitPointInvoker as i,withWorkflowTestInvoker as l,attachWaitPointKey as n,buildJobContext as o,createWaitPointInvoker as r,clearWorkflowTestEnv as s,attachWaitPointInvoker as t,writeWorkflowTestEnv as u};
|
|
2
|
+
//# sourceMappingURL=wait-point-invoker-eiP-IIux.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wait-point-invoker-eiP-IIux.mjs","names":["platform"],"sources":["../src/configure/services/workflow/test-env-key.ts","../src/configure/services/workflow/wait-point-invoker.ts"],"sourcesContent":["/**\n * Typed accessors for the test-time globalThis slot used to pass `env` from\n * `mockWorkflow().setEnv()` (in `@tailor-platform/sdk/vitest`) to\n * `runWorkflowLocally()` job bodies. The slot key is private to this\n * module; callers go through the get/set/clear functions below so both sides\n * share the same access path.\n *\n * Lives in its own file (with no `@/` imports) so `vitest/mock.ts` can load\n * it from nested Vitest configs that do not resolve `@/` aliases.\n * @internal\n */\nimport { AsyncLocalStorage } from \"node:async_hooks\";\nimport type { TailorEnv, TailorPrincipal } from \"../../../runtime/types\";\n\nconst SLOT_KEY = \"__tailorWorkflowTestEnv\";\n\ntype AsyncLocalStorageLike<T> = {\n getStore(): T | undefined;\n run<R>(store: T, callback: () => R): R;\n};\n\nlet invokerStorage: AsyncLocalStorageLike<TailorPrincipal | null> | undefined;\n\nfunction workflowInvokerStorage(): AsyncLocalStorageLike<TailorPrincipal | null> {\n if (!invokerStorage) {\n invokerStorage = new AsyncLocalStorage<TailorPrincipal | null>();\n }\n return invokerStorage;\n}\n\n/**\n * Read the test-time env slot.\n * @returns Current env, or `undefined` when unset.\n * @internal\n */\nexport function readWorkflowTestEnv(): TailorEnv | undefined {\n return (globalThis as unknown as Record<string, TailorEnv | undefined>)[SLOT_KEY];\n}\n\n/**\n * Write the test-time env slot.\n * @param env - Env value to expose to `runWorkflowLocally()` job bodies.\n * @internal\n */\nexport function writeWorkflowTestEnv(env: TailorEnv): void {\n (globalThis as unknown as Record<string, TailorEnv>)[SLOT_KEY] = env;\n}\n\n/**\n * Clear the test-time env slot.\n * @internal\n */\nexport function clearWorkflowTestEnv(): void {\n delete (globalThis as unknown as Record<string, unknown>)[SLOT_KEY];\n}\n\nexport function withWorkflowTestInvoker<T>(invoker: TailorPrincipal | null, run: () => T): T {\n return workflowInvokerStorage().run(invoker, run);\n}\n\ntype RuntimeInvoker = {\n id: string;\n type: \"user\" | \"machine_user\";\n workspaceId: string;\n attributes?: string[] | TailorPrincipal[\"attributes\"];\n attributeMap?: TailorPrincipal[\"attributes\"];\n attributeList?: TailorPrincipal[\"attributeList\"];\n};\n\nfunction readRuntimeInvoker(): TailorPrincipal | null {\n const runtime = (\n globalThis as unknown as {\n tailor?: { context?: { getInvoker?: () => RuntimeInvoker | null } };\n }\n ).tailor?.context?.getInvoker;\n const raw = runtime?.();\n if (!raw) return null;\n return {\n id: raw.id,\n type: raw.type,\n workspaceId: raw.workspaceId,\n attributes: raw.attributeMap ?? (Array.isArray(raw.attributes) ? {} : (raw.attributes ?? {})),\n attributeList: (raw.attributeList ??\n (Array.isArray(raw.attributes) ? raw.attributes : [])) as TailorPrincipal[\"attributeList\"],\n };\n}\n\n// Shallow-copied to isolate against cross-trigger mutation.\nexport function buildJobContext(): { env: TailorEnv; invoker: TailorPrincipal | null } {\n const storedInvoker = invokerStorage?.getStore();\n const invoker = storedInvoker === undefined ? readRuntimeInvoker() : storedInvoker;\n const fromGlobal = readWorkflowTestEnv();\n if (fromGlobal !== undefined) return { env: { ...fromGlobal }, invoker };\n return { env: {}, invoker };\n}\n","import type { PlatformWorkflowAPI } from \"#/runtime/workflow\";\n\n// Not re-exported from the workflow barrel: the slot exists so the Vitest mock\n// can intercept parameterized wait points, whose `wait`/`resolve` live on\n// short-lived objects returned by `.with()` rather than on the definition.\nconst WAIT_POINT_INVOKER: unique symbol = Symbol.for(\"tailor-platform/sdk:wait-point-invoker\");\nconst WAIT_POINT_KEY: unique symbol = Symbol.for(\"tailor-platform/sdk:wait-point-key\");\n\n/** Indirection every wait point call routes through, keyed by resolved key. */\nexport interface WaitPointInvoker {\n wait(key: string, payload: unknown): unknown;\n resolve(\n key: string,\n executionId: string,\n callback: (payload: unknown) => unknown | Promise<unknown>,\n ): Promise<void>;\n}\n\nfunction getPlatformWorkflow(): PlatformWorkflowAPI {\n const platform = globalThis as { tailor?: { workflow?: PlatformWorkflowAPI } };\n const workflow = platform.tailor?.workflow;\n if (!workflow) {\n throw new Error(\n \"tailor.workflow is not available. Run tests in the `tailor-runtime` Vitest environment, \" +\n \"or acquire mockWorkflow() from @tailor-platform/sdk/vitest and set a wait/resolve handler.\",\n );\n }\n return workflow;\n}\n\n/**\n * Create the invoker a single wait point definition delegates to.\n * @returns An invoker bound to the platform runtime\n */\nexport function createWaitPointInvoker(): WaitPointInvoker {\n return {\n wait(key, payload) {\n return getPlatformWorkflow().wait(key, payload);\n },\n async resolve(key, executionId, callback) {\n await getPlatformWorkflow().resolve(executionId, key, callback);\n },\n };\n}\n\n/**\n * Attach an invoker to a wait point definition so test doubles can intercept it.\n *\n * The slot itself is fixed once attached; a double swaps the invoker's `wait` /\n * `resolve` methods rather than the invoker object.\n * @param target - Wait point definition to attach to\n * @param invoker - Invoker the definition delegates to\n * @returns The same definition\n */\nexport function attachWaitPointInvoker<T extends object>(target: T, invoker: WaitPointInvoker): T {\n Object.defineProperty(target, WAIT_POINT_INVOKER, {\n value: invoker,\n enumerable: false,\n configurable: false,\n writable: false,\n });\n return target;\n}\n\n/**\n * Read the invoker attached to a wait point definition.\n * @param target - Wait point definition to read from\n * @returns The attached invoker, or undefined when the value is not a wait point\n */\nexport function getWaitPointInvoker(target: object): WaitPointInvoker | undefined {\n return (target as Record<symbol, WaitPointInvoker | undefined>)[WAIT_POINT_INVOKER];\n}\n\n/**\n * Record the resolved key on a wait point bound by `.with()`.\n * @param target - Bound wait point to attach to\n * @param key - Resolved runtime key\n * @returns The same bound wait point\n */\nexport function attachWaitPointKey<T extends object>(target: T, key: string): T {\n Object.defineProperty(target, WAIT_POINT_KEY, {\n value: key,\n enumerable: false,\n configurable: false,\n writable: false,\n });\n return target;\n}\n\n/**\n * Read the resolved key recorded on a bound wait point.\n * @param target - Bound wait point to read from\n * @returns The resolved key, or undefined when the value is not a bound wait point\n */\nexport function getWaitPointKey(target: object): string | undefined {\n return (target as Record<symbol, string | undefined>)[WAIT_POINT_KEY];\n}\n"],"mappings":"qDAcA,MAAM,EAAW,0BAOjB,IAAI,EAEJ,SAAS,wBAAwE,CAI/E,MAHA,CACE,IAAiB,IAAI,EAEhB,CACT,CAOA,SAAgB,qBAA6C,CAC3D,OAAQ,WAAgE,EAC1E,CAOA,SAAgB,qBAAqB,EAAsB,CACzD,WAAqD,GAAY,CACnE,CAMA,SAAgB,sBAA6B,CAC3C,OAAQ,WAAkD,EAC5D,CAEA,SAAgB,wBAA2B,EAAiC,EAAiB,CAC3F,OAAO,uBAAuB,CAAC,CAAC,IAAI,EAAS,CAAG,CAClD,CAWA,SAAS,oBAA6C,CACpD,IAAM,EACJ,WAGA,QAAQ,SAAS,WACb,EAAM,IAAU,EAEtB,OADK,EACE,CACL,GAAI,EAAI,GACR,KAAM,EAAI,KACV,YAAa,EAAI,YACjB,WAAY,EAAI,eAAiB,MAAM,QAAQ,EAAI,UAAU,EAAI,CAAC,EAAK,EAAI,YAAc,CAAC,GAC1F,cAAgB,EAAI,gBACjB,MAAM,QAAQ,EAAI,UAAU,EAAI,EAAI,WAAa,CAAC,EACvD,EARiB,IASnB,CAGA,SAAgB,iBAAuE,CACrF,IAAM,EAAgB,GAAgB,SAAS,EACzC,EAAU,IAAkB,IAAA,GAAY,mBAAmB,EAAI,EAC/D,EAAa,oBAAoB,EAEvC,OADI,IAAe,IAAA,GACZ,CAAE,IAAK,CAAC,EAAG,SAAQ,EADW,CAAE,IAAK,CAAE,GAAG,CAAW,EAAG,SAAQ,CAEzE,CCzFA,MAAM,EAAoC,OAAO,IAAI,wCAAwC,EACvF,EAAgC,OAAO,IAAI,oCAAoC,EAYrF,SAAS,qBAA2C,CAElD,IAAM,EAAWA,WAAS,QAAQ,SAClC,GAAI,CAAC,EACH,MAAU,MACR,oLAEF,EAEF,OAAO,CACT,CAMA,SAAgB,wBAA2C,CACzD,MAAO,CACL,KAAK,EAAK,EAAS,CACjB,OAAO,oBAAoB,CAAC,CAAC,KAAK,EAAK,CAAO,CAChD,EACA,MAAM,QAAQ,EAAK,EAAa,EAAU,CACxC,MAAM,oBAAoB,CAAC,CAAC,QAAQ,EAAa,EAAK,CAAQ,CAChE,CACF,CACF,CAWA,SAAgB,uBAAyC,EAAW,EAA8B,CAOhG,OANA,OAAO,eAAe,EAAQ,EAAoB,CAChD,MAAO,EACP,WAAY,GACZ,aAAc,GACd,SAAU,EACZ,CAAC,EACM,CACT,CAOA,SAAgB,oBAAoB,EAA8C,CAChF,OAAQ,EAAwD,EAClE,CAQA,SAAgB,mBAAqC,EAAW,EAAgB,CAO9E,OANA,OAAO,eAAe,EAAQ,EAAgB,CAC5C,MAAO,EACP,WAAY,GACZ,aAAc,GACd,SAAU,EACZ,CAAC,EACM,CACT,CAOA,SAAgB,gBAAgB,EAAoC,CAClE,OAAQ,EAA8C,EACxD"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=Symbol.for(`tailor-platform/sdk:wait-point-registry`);function registry(){let t=globalThis,n=t[e];return n||(n={entries:[],scopeStart:0},t[e]=n),n}function registerWaitPoint(e){registry().entries.push(e)}function beginWaitPointScope(){let e=registry();e.scopeStart=e.entries.length}function getScopedWaitPoints(){let e=registry();return e.entries.slice(e.scopeStart)}export{getScopedWaitPoints as n,registerWaitPoint as r,beginWaitPointScope as t};
|
|
2
|
+
//# sourceMappingURL=wait-point-registry-BrkwfyjS.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wait-point-registry-
|
|
1
|
+
{"version":3,"file":"wait-point-registry-BrkwfyjS.mjs","names":[],"sources":["../src/utils/wait-point-registry.ts"],"sourcesContent":["/**\n * How a wait point key reached the SDK. The declaration decides what the key\n * may contain: only `define` sees the key as a literal type, so only it can\n * type the `$params` a key carries.\n */\nexport type WaitPointDeclaration = \"createWaitPoint\" | \"define\" | \"property\";\n\n/** A wait point key as declared, before the deploy-time key rules run. */\nexport interface RegisteredWaitPoint {\n key: string;\n declaredBy: WaitPointDeclaration;\n}\n\nconst WAIT_POINT_REGISTRY_KEY: unique symbol = Symbol.for(\n \"tailor-platform/sdk:wait-point-registry\",\n);\n\ninterface Registry {\n entries: RegisteredWaitPoint[];\n scopeStart: number;\n}\n\ntype GlobalWithRegistry = typeof globalThis & {\n [WAIT_POINT_REGISTRY_KEY]?: Registry;\n};\n\nfunction registry(): Registry {\n const g = globalThis as GlobalWithRegistry;\n let state = g[WAIT_POINT_REGISTRY_KEY];\n if (!state) {\n state = { entries: [], scopeStart: 0 };\n g[WAIT_POINT_REGISTRY_KEY] = state;\n }\n return state;\n}\n\n/**\n * Record a declared wait point key so the CLI can check it against the key\n * rules once the declaring module has loaded.\n * @param entry - The key and the declaration it came from\n */\nexport function registerWaitPoint(entry: RegisteredWaitPoint): void {\n registry().entries.push(entry);\n}\n\n/**\n * Read every wait point declared by the modules loaded so far.\n * @returns The registered wait points, in declaration order\n */\nexport function getRegisteredWaitPoints(): readonly RegisteredWaitPoint[] {\n return registry().entries;\n}\n\n/**\n * Start a scope here, so what a run declares can be told apart from what an\n * earlier one left behind.\n *\n * The registry is process-wide, and a run that fails partway still leaves its\n * keys in it. Without a scope, a second run in the same process would be judged\n * on the first run's keys as well as its own.\n */\nexport function beginWaitPointScope(): void {\n const state = registry();\n state.scopeStart = state.entries.length;\n}\n\n/**\n * Read the wait points declared since {@link beginWaitPointScope}, or every one\n * of them when no scope was started.\n * @returns The wait points registered in the current scope, in declaration order\n */\nexport function getScopedWaitPoints(): readonly RegisteredWaitPoint[] {\n const state = registry();\n return state.entries.slice(state.scopeStart);\n}\n\n/**\n * Drop everything registered after a mark, where the mark is the length\n * {@link getRegisteredWaitPoints} returned earlier.\n *\n * The registry is process-wide, so a test that declares a key `deploy` rejects\n * would otherwise leave it for the deploy-time check another test file runs.\n * Nothing outside a test needs this: a CLI run declares one project's keys and\n * checks all of them.\n * @param mark - The registry length to return to\n */\nexport function restoreWaitPointRegistry(mark: number): void {\n const state = registry();\n state.entries.length = mark;\n if (state.scopeStart > mark) state.scopeStart = mark;\n}\n"],"mappings":"AAaA,MAAM,EAAyC,OAAO,IACpD,yCACF,EAWA,SAAS,UAAqB,CAC5B,IAAM,EAAI,WACN,EAAQ,EAAE,GAKd,OAJK,IACH,EAAQ,CAAE,QAAS,CAAC,EAAG,WAAY,CAAE,EACrC,EAAE,GAA2B,GAExB,CACT,CAOA,SAAgB,kBAAkB,EAAkC,CAClE,SAAS,CAAC,CAAC,QAAQ,KAAK,CAAK,CAC/B,CAkBA,SAAgB,qBAA4B,CAC1C,IAAM,EAAQ,SAAS,EACvB,EAAM,WAAa,EAAM,QAAQ,MACnC,CAOA,SAAgB,qBAAsD,CACpE,IAAM,EAAQ,SAAS,EACvB,OAAO,EAAM,QAAQ,MAAM,EAAM,UAAU,CAC7C"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const api=()=>globalThis.tailor.workflow,e={startWorkflow:(...e)=>api().startWorkflow(...e),resumeWorkflowExecution:(...e)=>api().resumeWorkflowExecution(...e),execJobFunction:(...e)=>api().execJobFunction(...e),wait:(...e)=>api().wait(...e),resolve:(...e)=>api().resolve(...e)};export{e as t};
|
|
2
|
+
//# sourceMappingURL=workflow-Cs9ISw6j.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-
|
|
1
|
+
{"version":3,"file":"workflow-Cs9ISw6j.mjs","names":[],"sources":["../src/runtime/workflow.ts"],"sourcesContent":["/**\n * Workflow utilities.\n *\n * Thin typed wrapper around the platform-provided `tailor.workflow` runtime API.\n * At runtime this delegates to `globalThis.tailor.workflow`. Use `mockWorkflow`\n * from `@tailor-platform/sdk/vitest` to mock these calls in unit tests.\n *\n * `execJobFunction` blocks until the job finishes and returns its result, while\n * `startWorkflow` returns only an execution ID.\n * @example\n * import { workflow } from \"@tailor-platform/sdk/runtime\";\n *\n * const executionId = await workflow.startWorkflow(\"myWorkflow\", { data: \"value\" });\n */\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * Specifies the machine user that should be used to execute the workflow.\n * This allows workflows to run with specific authentication context.\n */\nexport interface Invoker {\n /** The namespace where the machine user is defined */\n namespace: string;\n /** The name of the machine user to use for workflow execution */\n machineUserName: string;\n}\n\n/** Options for {@link startWorkflow}. */\nexport interface StartWorkflowOptions {\n /** Optional authentication invoker to specify which machine user should execute the workflow */\n authInvoker?: Invoker;\n}\n\ndeclare const executionPolicyKeyBrand: unique symbol;\n\n/**\n * A concrete runtime key produced by an execution policy instance — either an\n * exact-match policy's `.key`, or a wildcard policy's `.keyFor(suffix)` (see\n * `defineWorkflowExecutionPolicies`). Branded so an arbitrary string that\n * wasn't derived from a declared policy can't be passed as `executionPolicyKey`.\n */\nexport type ExecutionPolicyKey = string & { readonly [executionPolicyKeyBrand]: never };\n\n/** Options for {@link execJobFunction}. */\nexport interface ExecJobFunctionOptions {\n /**\n * Execution policy key matched by the platform against the policies\n * declared with `defineWorkflowExecutionPolicies` in `tailor.config.ts`.\n */\n executionPolicyKey?: ExecutionPolicyKey;\n}\n\n/**\n * Platform API surface for `tailor.workflow`. Describes the shape the platform\n * runtime injects on `globalThis.tailor.workflow`.\n */\nexport interface PlatformWorkflowAPI {\n /**\n * Starts a workflow and returns its execution ID.\n * @param workflowName - Workflow name as defined in tailor.config\n * @param args - Arguments forwarded to the workflow's main job\n * @param options - Optional start options (e.g. `authInvoker`)\n * @returns The execution ID of the started workflow\n */\n startWorkflow(workflowName: string, args?: any, options?: StartWorkflowOptions): Promise<string>;\n\n /**\n * Resumes a failed or pending-retry workflow execution and returns its execution ID.\n * @param executionId - The execution to resume\n * @returns The execution ID of the resumed workflow\n */\n resumeWorkflowExecution(executionId: string): Promise<string>;\n\n /**\n * Executes a job function and returns its result via durable suspend/replay.\n * @param jobName - Job name as defined in the workflow\n * @param args - Arguments forwarded to the job\n * @param options - Optional execution options (e.g. `executionPolicyKey`)\n * @returns The job's return value\n */\n execJobFunction(jobName: string, args?: any, options?: ExecJobFunctionOptions): any;\n\n /**\n * Suspends the current workflow execution and waits for an external signal to resume.\n * @param key - Wait point key\n * @param payload - Optional payload to record with the wait point\n * @returns The payload supplied by the corresponding `resolve` call\n */\n wait(key: string, payload?: any): any;\n\n /**\n * Resolves a waiting workflow execution, causing it to resume.\n * @param executionId - The execution to resume\n * @param key - Wait point key to resolve\n * @param callback - Callback receiving the wait payload; its return value is forwarded to `wait`\n * @returns A promise that resolves once the resolve has been recorded\n */\n resolve(executionId: string, key: string, callback: (waitPayload: any) => any): Promise<void>;\n}\n\nconst api = (): PlatformWorkflowAPI =>\n (globalThis as unknown as { tailor: { workflow: PlatformWorkflowAPI } }).tailor.workflow;\n\n/**\n * See {@link PlatformWorkflowAPI.startWorkflow}.\n * @param args - Forwarded to {@link PlatformWorkflowAPI.startWorkflow}\n * @returns The execution ID of the started workflow\n */\nconst startWorkflow: PlatformWorkflowAPI[\"startWorkflow\"] = (...args) =>\n api().startWorkflow(...args);\n\n/**\n * See {@link PlatformWorkflowAPI.resumeWorkflowExecution}.\n * @param args - Forwarded to {@link PlatformWorkflowAPI.resumeWorkflowExecution}\n * @returns The execution ID of the resumed workflow\n */\nconst resumeWorkflowExecution: PlatformWorkflowAPI[\"resumeWorkflowExecution\"] = (...args) =>\n api().resumeWorkflowExecution(...args);\n\n/**\n * See {@link PlatformWorkflowAPI.execJobFunction}.\n *\n * @deprecated since 2.5.0 — call the target job's own `.start()` method\n * instead. codemod: v3/remove-workflow-exec-job-function\n * @param args - Forwarded to {@link PlatformWorkflowAPI.execJobFunction}\n * @returns The job's return value\n */\nconst execJobFunction: PlatformWorkflowAPI[\"execJobFunction\"] = (...args) =>\n api().execJobFunction(...args);\n\nconst wait: PlatformWorkflowAPI[\"wait\"] = (...args) => api().wait(...args);\n\nconst resolve: PlatformWorkflowAPI[\"resolve\"] = (...args) => api().resolve(...args);\n\n/** Runtime wrapper namespace for `tailor.workflow`. */\nexport const workflow = {\n startWorkflow,\n resumeWorkflowExecution,\n execJobFunction,\n wait,\n resolve,\n} as const satisfies PlatformWorkflowAPI;\n"],"mappings":"AAqGA,MAAM,QACH,WAAwE,OAAO,SAkCrE,EAAW,CACtB,eA5B2D,GAAG,IAC9D,IAAI,CAAC,CAAC,cAAc,GAAG,CAAI,EA4B3B,yBArB+E,GAAG,IAClF,IAAI,CAAC,CAAC,wBAAwB,GAAG,CAAI,EAqBrC,iBAX+D,GAAG,IAClE,IAAI,CAAC,CAAC,gBAAgB,GAAG,CAAI,EAW7B,MATyC,GAAG,IAAS,IAAI,CAAC,CAAC,KAAK,GAAG,CAAI,EAUvE,SAR+C,GAAG,IAAS,IAAI,CAAC,CAAC,QAAQ,GAAG,CAAI,CASlF"}
|