@tailor-platform/sdk 2.0.0-next.10 → 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 +165 -0
- package/dist/{application-miwiXtB4.mjs → application-CM6hKnSK.mjs} +312 -89
- package/dist/application-CM6hKnSK.mjs.map +1 -0
- package/dist/application-CXNaUNhv.mjs +3 -0
- package/dist/cli/commands/deploy/aigateway.d.mts +1 -1
- package/dist/cli/commands/deploy/application.d.mts +1 -1
- package/dist/cli/commands/deploy/auth.d.mts +1 -1
- package/dist/cli/commands/deploy/deploy.d.mts +1 -0
- package/dist/cli/commands/deploy/executor.d.mts +1 -1
- package/dist/cli/commands/deploy/function-registry.d.mts +1 -2
- package/dist/cli/commands/deploy/idp.d.mts +1 -1
- package/dist/cli/commands/deploy/label.d.mts +2 -0
- package/dist/cli/commands/deploy/resolver.d.mts +1 -1
- package/dist/cli/commands/deploy/staticwebsite.d.mts +1 -1
- package/dist/cli/commands/deploy/tailordb/index.d.mts +2 -1
- package/dist/cli/commands/deploy/types.d.mts +2 -1
- package/dist/cli/commands/deploy/workflow-execution-policy.d.mts +1 -2
- package/dist/cli/commands/deploy/workflow.d.mts +1 -1
- package/dist/cli/commands/executor/get.d.mts +1 -10
- package/dist/cli/commands/executor/jobs.d.mts +1 -38
- package/dist/cli/commands/executor/trigger.d.mts +1 -11
- package/dist/cli/commands/generate/seed/bundler.d.mts +2 -1
- package/dist/cli/commands/tailordb/migrate/schema-checks.d.mts +5 -0
- package/dist/cli/commands/tailordb/migrate/snapshot.d.mts +1 -1
- package/dist/cli/commands/workflow/executions.d.mts +1 -13
- package/dist/cli/commands/workflow/get.d.mts +1 -10
- package/dist/cli/commands/workflow/start.d.mts +2 -14
- package/dist/cli/lib.d.mts +7 -11
- package/dist/cli/lib.mjs +99 -42
- package/dist/cli/lib.mjs.map +1 -1
- package/dist/cli/main.mjs +318 -124
- package/dist/cli/main.mjs.map +1 -1
- package/dist/cli/services/http-adapter/bundler.d.mts +1 -0
- package/dist/cli/services/workflow/bundler.d.mts +2 -1
- package/dist/cli/shared/client.d.mts +28 -3
- package/dist/cli/shared/config-loader.d.mts +11 -4
- package/dist/cli/shared/tsconfig-paths-plugin.d.mts +2 -0
- package/dist/cli/shared/type-generator.d.mts +4 -3
- package/dist/completion/zsh-worker.zsh +82 -22
- package/dist/configure/config/types.d.mts +26 -3
- package/dist/configure/index.d.mts +2 -2
- package/dist/configure/index.mjs +171 -3
- package/dist/configure/index.mjs.map +1 -1
- package/dist/configure/services/executor/index.d.mts +2 -2
- package/dist/configure/services/executor/trigger/event.d.mts +245 -2
- package/dist/configure/services/executor/trigger/index.d.mts +3 -3
- package/dist/configure/services/idp/index.d.mts +1 -1
- package/dist/configure/services/index.d.mts +2 -2
- package/dist/configure/services/tailordb/index.d.mts +0 -1
- package/dist/configure/services/workflow/execution-policy.d.mts +1 -1
- package/dist/configure/services/workflow/execution-policy.types.d.mts +1 -1
- package/dist/configure/services/workflow/job.d.mts +11 -2
- package/dist/configure/services/workflow/workflow.d.mts +10 -0
- package/dist/{globals-DQotNuwK.mjs → globals-TfAVItuK.mjs} +1 -2
- package/dist/globals-TfAVItuK.mjs.map +1 -0
- package/dist/node-builtins-CmaL2Cbq.mjs +36 -0
- package/dist/node-builtins-CmaL2Cbq.mjs.map +1 -0
- 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.mjs +149 -2
- package/dist/plugin/builtin/file-utils/index.mjs.map +1 -0
- 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.mjs +1 -1
- package/dist/plugin/builtin/seed/seed-type-processor.d.mts +2 -0
- package/dist/{register-ts-hook-BAHMwxfG.mjs → register-ts-hook-LYV7zH-e.mjs} +2252 -797
- package/dist/register-ts-hook-LYV7zH-e.mjs.map +1 -0
- package/dist/registry-BIGVUrMB.mjs.map +1 -1
- package/dist/runtime/index.mjs +1 -1
- package/dist/runtime/workflow.d.mts +2 -20
- package/dist/runtime/workflow.mjs +1 -1
- package/dist/{seed-LUVr7jHL.mjs → seed-B-yckgQY.mjs} +42 -3
- package/dist/seed-B-yckgQY.mjs.map +1 -0
- package/dist/service-M7OYziQP.mjs +3 -0
- package/dist/{service-BNtPsK9Q.mjs → service-k1xy_A5G.mjs} +29 -2
- package/dist/{service-BNtPsK9Q.mjs.map → service-k1xy_A5G.mjs.map} +1 -1
- package/dist/{service_pb-BwZRiNug.mjs → service_pb-D5--My_M.mjs} +5 -5
- package/dist/service_pb-D5--My_M.mjs.map +1 -0
- package/dist/{service_pb-wRkxUta6.mjs → service_pb-i8CmnQP4.mjs} +1 -1
- package/dist/tailor-proto/src/tailor/v1/application_pb.d.mts +106 -1
- package/dist/tailor-proto/src/tailor/v1/executor_resource_pb.d.mts +24 -1
- package/dist/tailor-proto/src/tailor/v1/function_pb.d.mts +49 -1
- package/dist/tailor-proto/src/tailor/v1/service_pb.d.mts +89 -6
- package/dist/tailor-proto/src/tailor/v1/telemetryrouter_resource_pb.d.mts +26 -1
- package/dist/tailor-proto/src/tailor/v1/workflow_pb.d.mts +101 -1
- package/dist/tailor-proto/src/tailor/v1/workflow_resource_pb.d.mts +22 -1
- package/dist/types/executor.generated.d.mts +23 -3
- package/dist/types/idp.generated.d.mts +1 -1
- package/dist/utils/test/index.d.mts +1 -2
- package/dist/utils/test/index.mjs +1 -173
- package/dist/utils/test/index.mjs.map +1 -1
- package/dist/vitest/environment.mjs +1 -1
- package/dist/vitest/index.d.mts +2 -2
- package/dist/vitest/index.mjs +10 -52
- package/dist/vitest/index.mjs.map +1 -1
- package/dist/vitest/mocks/workflow.d.mts +0 -9
- package/dist/vitest/setup.mjs +1 -1
- package/dist/{workflow-CsaQ9qK-.mjs → workflow-Bamae_Yc.mjs} +1 -9
- package/dist/workflow-Bamae_Yc.mjs.map +1 -0
- package/dist/{workspace_resource_pb-UGK1SSn_.mjs → workspace_resource_pb-DXnO2AT-.mjs} +7 -7
- package/dist/workspace_resource_pb-DXnO2AT-.mjs.map +1 -0
- package/docs/cli/tailordb.md +39 -7
- package/docs/cli-reference.md +11 -10
- package/docs/configuration.md +50 -0
- package/docs/migration/v2.md +306 -9
- package/docs/runtime.md +1 -1
- package/docs/services/executor.md +83 -3
- package/docs/services/idp.md +8 -6
- package/docs/services/resolver.md +6 -4
- package/docs/services/tailordb-migration.md +17 -6
- package/docs/services/tailordb.md +6 -4
- package/docs/services/workflow.md +33 -3
- package/package.json +19 -17
- package/dist/application-DArFTTJ9.mjs +0 -3
- package/dist/application-miwiXtB4.mjs.map +0 -1
- package/dist/enum-constants-j9QBF0cB.mjs +0 -116
- package/dist/enum-constants-j9QBF0cB.mjs.map +0 -1
- package/dist/file-utils-yEiIS4nJ.mjs +0 -150
- package/dist/file-utils-yEiIS4nJ.mjs.map +0 -1
- package/dist/globals-DQotNuwK.mjs.map +0 -1
- package/dist/kysely-type-DqIRgDYR.mjs +0 -275
- package/dist/kysely-type-DqIRgDYR.mjs.map +0 -1
- package/dist/register-ts-hook-BAHMwxfG.mjs.map +0 -1
- package/dist/seed-LUVr7jHL.mjs.map +0 -1
- package/dist/service-D5jn05ZI.mjs +0 -3
- package/dist/service_pb-BwZRiNug.mjs.map +0 -1
- package/dist/utils/test/mock.d.mts +0 -86
- package/dist/workflow-CsaQ9qK-.mjs.map +0 -1
- package/dist/workspace_resource_pb-UGK1SSn_.mjs.map +0 -1
|
@@ -1,175 +1,3 @@
|
|
|
1
|
-
import { pathToFileURL } from "node:url";
|
|
2
|
-
import * as path from "node:path";
|
|
3
|
-
|
|
4
|
-
//#region src/utils/test/mock.ts
|
|
5
|
-
const GlobalThis = globalThis;
|
|
6
|
-
/**
|
|
7
|
-
* Sets up a mock for `globalThis.tailordb.Client` used in bundled resolver/executor tests.
|
|
8
|
-
* @deprecated Use `mockTailordb` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.
|
|
9
|
-
* @param resolver - Optional function to resolve query results. Defaults to returning empty arrays.
|
|
10
|
-
* @returns Object containing arrays of executed queries and created clients for assertions.
|
|
11
|
-
*/
|
|
12
|
-
function setupTailordbMock(resolver = () => []) {
|
|
13
|
-
const executedQueries = [];
|
|
14
|
-
const createdClients = [];
|
|
15
|
-
class MockTailordbClient {
|
|
16
|
-
record;
|
|
17
|
-
constructor({ namespace }) {
|
|
18
|
-
this.record = {
|
|
19
|
-
namespace,
|
|
20
|
-
ended: false
|
|
21
|
-
};
|
|
22
|
-
createdClients.push(this.record);
|
|
23
|
-
}
|
|
24
|
-
async connect() {}
|
|
25
|
-
async end() {
|
|
26
|
-
this.record.ended = true;
|
|
27
|
-
}
|
|
28
|
-
async queryObject(query, params = []) {
|
|
29
|
-
executedQueries.push({
|
|
30
|
-
query,
|
|
31
|
-
params
|
|
32
|
-
});
|
|
33
|
-
return { rows: resolver(query, params) };
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
GlobalThis.tailordb = { Client: MockTailordbClient };
|
|
37
|
-
return {
|
|
38
|
-
executedQueries,
|
|
39
|
-
createdClients
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Sets up a mock for `globalThis.tailor.workflow.execJobFunction` used in bundled workflow tests.
|
|
44
|
-
* `wait`/`resolve` are stubbed to throw a helpful error directing to `mockWorkflow`,
|
|
45
|
-
* so mistakenly calling wait without wait-point mocks produces a clear message instead of a TypeError.
|
|
46
|
-
* @deprecated Use `mockWorkflow` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.
|
|
47
|
-
* @param handler - Function that handles started job calls and returns results.
|
|
48
|
-
* @returns Object containing an array of started jobs for assertions.
|
|
49
|
-
*/
|
|
50
|
-
function setupWorkflowMock(handler) {
|
|
51
|
-
const startedJobs = [];
|
|
52
|
-
const execJobFunction = (jobName, args) => {
|
|
53
|
-
startedJobs.push({
|
|
54
|
-
jobName,
|
|
55
|
-
args
|
|
56
|
-
});
|
|
57
|
-
return handler(jobName, args);
|
|
58
|
-
};
|
|
59
|
-
GlobalThis.tailor = {
|
|
60
|
-
...GlobalThis.tailor,
|
|
61
|
-
workflow: {
|
|
62
|
-
wait: () => {
|
|
63
|
-
throw new Error("tailor.workflow.wait is not mocked. Use mockWorkflow from @tailor-platform/sdk/vitest in tests.");
|
|
64
|
-
},
|
|
65
|
-
resolve: async () => {
|
|
66
|
-
throw new Error("tailor.workflow.resolve is not mocked. Use mockWorkflow from @tailor-platform/sdk/vitest in tests.");
|
|
67
|
-
},
|
|
68
|
-
...GlobalThis.tailor?.workflow,
|
|
69
|
-
execJobFunction,
|
|
70
|
-
startJobFunction: execJobFunction
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
return { startedJobs };
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Sets up a mock for `globalThis.tailor.context.getInvoker` used in bundled
|
|
77
|
-
* resolver/executor/workflow tests.
|
|
78
|
-
* @deprecated With the `tailor-runtime` environment from `@tailor-platform/sdk/vitest`, drive the invoker via `vi.spyOn(globalThis.tailor.context, "getInvoker").mockReturnValue(...)` for bundled tests, or pass `invoker` directly to `.body()` when unit-testing resolvers/executors/workflow jobs against the TypeScript source.
|
|
79
|
-
* @param invoker - The `TailorPrincipal` value to return, or `null` for anonymous.
|
|
80
|
-
*/
|
|
81
|
-
function setupInvokerMock(invoker) {
|
|
82
|
-
const raw = invoker ? {
|
|
83
|
-
id: invoker.id,
|
|
84
|
-
type: invoker.type,
|
|
85
|
-
workspaceId: invoker.workspaceId,
|
|
86
|
-
attributes: invoker.attributeList,
|
|
87
|
-
attributeMap: invoker.attributes
|
|
88
|
-
} : null;
|
|
89
|
-
GlobalThis.tailor = {
|
|
90
|
-
...GlobalThis.tailor,
|
|
91
|
-
context: { getInvoker: () => raw }
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Sets up a mock for `globalThis.TailorErrors` used in bundled resolver tests.
|
|
96
|
-
* Mimics the PF runtime's TailorErrors class that serializes errors with the `TailorErrors: ` prefix.
|
|
97
|
-
* @deprecated Use the `tailor-runtime` environment from `@tailor-platform/sdk/vitest` which auto-injects TailorErrors.
|
|
98
|
-
*/
|
|
99
|
-
function setupTailorErrorsMock() {
|
|
100
|
-
GlobalThis.TailorErrors = class TailorErrors extends Error {
|
|
101
|
-
errors;
|
|
102
|
-
constructor(errors) {
|
|
103
|
-
super(`TailorErrors: ${JSON.stringify({ errors })}`);
|
|
104
|
-
this.name = "TailorErrors";
|
|
105
|
-
this.errors = errors;
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Sets up mocks for `globalThis.tailor.workflow.wait` and `.resolve` used in bundled workflow tests.
|
|
111
|
-
* `execJobFunction` is stubbed to throw a helpful error directing to `setupWorkflowMock()`,
|
|
112
|
-
* so mistakenly starting a job without job mocks produces a clear message instead of silently returning undefined.
|
|
113
|
-
* @deprecated Use `mockWorkflow` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.
|
|
114
|
-
* `setWaitHandler` / `setResolveHandler` cover wait/resolve, and `waitCalls` / `resolveCalls` give the same assertion shape.
|
|
115
|
-
* @param config - Optional handlers for wait and resolve calls.
|
|
116
|
-
* @param config.onWait - Handler called when wait is invoked.
|
|
117
|
-
* @param config.onResolve - Handler called when resolve is invoked.
|
|
118
|
-
* @returns Object containing arrays of wait and resolve calls for assertions.
|
|
119
|
-
*/
|
|
120
|
-
function setupWaitPointMock(config) {
|
|
121
|
-
const waitCalls = [];
|
|
122
|
-
const resolveCalls = [];
|
|
123
|
-
const throwUnmocked = () => {
|
|
124
|
-
throw new Error("tailor.workflow.execJobFunction is not mocked. Use setupWorkflowMock() in tests.");
|
|
125
|
-
};
|
|
126
|
-
GlobalThis.tailor = {
|
|
127
|
-
...GlobalThis.tailor,
|
|
128
|
-
workflow: {
|
|
129
|
-
execJobFunction: throwUnmocked,
|
|
130
|
-
startJobFunction: throwUnmocked,
|
|
131
|
-
...GlobalThis.tailor?.workflow,
|
|
132
|
-
wait: (key, payload) => {
|
|
133
|
-
waitCalls.push({
|
|
134
|
-
key,
|
|
135
|
-
payload
|
|
136
|
-
});
|
|
137
|
-
return config?.onWait?.(key, payload);
|
|
138
|
-
},
|
|
139
|
-
resolve: async (executionId, key, callback) => {
|
|
140
|
-
resolveCalls.push({
|
|
141
|
-
executionId,
|
|
142
|
-
key
|
|
143
|
-
});
|
|
144
|
-
await config?.onResolve?.(executionId, key, callback);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
return {
|
|
149
|
-
waitCalls,
|
|
150
|
-
resolveCalls
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Creates a function that imports a bundled JS file and returns its `main` export.
|
|
155
|
-
* Used to test bundled output from `apply --buildOnly`.
|
|
156
|
-
* @param baseDir - Base directory where bundled files are located.
|
|
157
|
-
* @returns An async function that takes a relative path and returns the `main` function.
|
|
158
|
-
* @deprecated This is an SDK-internal testing helper. Bundling integrity is the SDK's responsibility,
|
|
159
|
-
* not the application's — verify your code through unit tests against the TypeScript source and
|
|
160
|
-
* E2E tests against a deployed application instead. This export will be removed in a future release.
|
|
161
|
-
*/
|
|
162
|
-
function createImportMain(baseDir) {
|
|
163
|
-
return async (relativePath) => {
|
|
164
|
-
const fileUrl = pathToFileURL(path.join(baseDir, relativePath));
|
|
165
|
-
fileUrl.searchParams.set("v", `${Date.now()}-${Math.random()}`);
|
|
166
|
-
const main = (await import(fileUrl.href)).main;
|
|
167
|
-
if (typeof main !== "function") throw new Error(`Expected "main" to be a function in ${relativePath}, got ${typeof main}`);
|
|
168
|
-
return main;
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
//#endregion
|
|
173
1
|
//#region src/utils/test/index.ts
|
|
174
2
|
/**
|
|
175
3
|
* Creates a hook function that processes TailorDB type fields
|
|
@@ -254,5 +82,5 @@ function createStandardSchema(schemaType, hook) {
|
|
|
254
82
|
}
|
|
255
83
|
|
|
256
84
|
//#endregion
|
|
257
|
-
export {
|
|
85
|
+
export { createStandardSchema, createTailorDBHook };
|
|
258
86
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/utils/test/mock.ts","../../../src/utils/test/index.ts"],"sourcesContent":["import * as path from \"node:path\";\nimport { pathToFileURL } from \"node:url\";\nimport type { ContextInvoker } from \"#/runtime/context\";\nimport type { TailorPrincipal } from \"#/runtime/types\";\nimport type { ExecJobFunctionOptions } from \"#/runtime/workflow\";\n\ntype MainFunction = (args: Record<string, unknown>) => unknown | Promise<unknown>;\ntype QueryResolver = (query: string, params: unknown[]) => unknown[];\ntype JobHandler = (jobName: string, args: unknown) => unknown;\ntype WaitHandler = (key: string, payload: unknown) => unknown;\ntype ResolveHandler = (\n executionId: string,\n key: string,\n callback: (payload: unknown) => unknown,\n) => Promise<void> | void;\n\ninterface TailordbGlobal {\n tailordb?: {\n Client: new (config: { namespace?: string }) => {\n connect(): Promise<void> | void;\n end(): Promise<void> | void;\n queryObject(\n query: string,\n params?: unknown[],\n ): Promise<{ rows: unknown[] }> | { rows: unknown[] };\n };\n };\n tailor?: {\n workflow: {\n execJobFunction: (\n jobName: string,\n args: unknown,\n options?: ExecJobFunctionOptions,\n ) => unknown;\n startJobFunction: (\n jobName: string,\n args: unknown,\n options?: ExecJobFunctionOptions,\n ) => unknown;\n wait?: (key: string, payload?: unknown) => unknown;\n resolve?: (\n executionId: string,\n key: string,\n callback: (payload: unknown) => unknown,\n ) => Promise<void>;\n };\n context: {\n getInvoker: () => ContextInvoker | null;\n };\n };\n}\n\ninterface TailorErrorItem {\n message: string;\n path: (string | number)[];\n}\n\ninterface TailorErrorsGlobal {\n TailorErrors?: new (errors: TailorErrorItem[]) => Error;\n}\n\nconst GlobalThis = globalThis as unknown as TailordbGlobal & TailorErrorsGlobal;\n\n/**\n * Sets up a mock for `globalThis.tailordb.Client` used in bundled resolver/executor tests.\n * @deprecated Use `mockTailordb` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.\n * @param resolver - Optional function to resolve query results. Defaults to returning empty arrays.\n * @returns Object containing arrays of executed queries and created clients for assertions.\n */\nexport function setupTailordbMock(resolver: QueryResolver = () => []): {\n executedQueries: { query: string; params: unknown[] }[];\n createdClients: { namespace?: string; ended: boolean }[];\n} {\n const executedQueries: { query: string; params: unknown[] }[] = [];\n const createdClients: { namespace?: string; ended: boolean }[] = [];\n\n class MockTailordbClient {\n private record: { namespace?: string; ended: boolean };\n\n constructor({ namespace }: { namespace?: string }) {\n this.record = { namespace, ended: false };\n createdClients.push(this.record);\n }\n\n async connect(): Promise<void> {\n /* noop */\n }\n\n async end(): Promise<void> {\n this.record.ended = true;\n }\n\n async queryObject(query: string, params: unknown[] = []): Promise<{ rows: unknown[] }> {\n executedQueries.push({ query, params });\n return { rows: resolver(query, params) };\n }\n }\n\n GlobalThis.tailordb = {\n Client: MockTailordbClient,\n } as typeof GlobalThis.tailordb;\n\n return { executedQueries, createdClients };\n}\n\n/**\n * Sets up a mock for `globalThis.tailor.workflow.execJobFunction` used in bundled workflow tests.\n * `wait`/`resolve` are stubbed to throw a helpful error directing to `mockWorkflow`,\n * so mistakenly calling wait without wait-point mocks produces a clear message instead of a TypeError.\n * @deprecated Use `mockWorkflow` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.\n * @param handler - Function that handles started job calls and returns results.\n * @returns Object containing an array of started jobs for assertions.\n */\nexport function setupWorkflowMock(handler: JobHandler): {\n startedJobs: { jobName: string; args: unknown }[];\n} {\n const startedJobs: { jobName: string; args: unknown }[] = [];\n\n const execJobFunction = (jobName: string, args: unknown): unknown => {\n startedJobs.push({ jobName, args });\n return handler(jobName, args);\n };\n\n GlobalThis.tailor = {\n ...GlobalThis.tailor,\n workflow: {\n wait: () => {\n throw new Error(\n \"tailor.workflow.wait is not mocked. Use mockWorkflow from @tailor-platform/sdk/vitest in tests.\",\n );\n },\n resolve: async () => {\n throw new Error(\n \"tailor.workflow.resolve is not mocked. Use mockWorkflow from @tailor-platform/sdk/vitest in tests.\",\n );\n },\n ...GlobalThis.tailor?.workflow,\n execJobFunction,\n startJobFunction: execJobFunction,\n },\n } as typeof GlobalThis.tailor;\n\n return { startedJobs };\n}\n\n/**\n * Sets up a mock for `globalThis.tailor.context.getInvoker` used in bundled\n * resolver/executor/workflow tests.\n * @deprecated With the `tailor-runtime` environment from `@tailor-platform/sdk/vitest`, drive the invoker via `vi.spyOn(globalThis.tailor.context, \"getInvoker\").mockReturnValue(...)` for bundled tests, or pass `invoker` directly to `.body()` when unit-testing resolvers/executors/workflow jobs against the TypeScript source.\n * @param invoker - The `TailorPrincipal` value to return, or `null` for anonymous.\n */\nexport function setupInvokerMock(invoker: TailorPrincipal | null): void {\n const raw: ContextInvoker | null = invoker\n ? {\n id: invoker.id,\n type: invoker.type,\n workspaceId: invoker.workspaceId,\n attributes: invoker.attributeList as string[],\n attributeMap: invoker.attributes as Record<string, unknown>,\n }\n : null;\n\n GlobalThis.tailor = {\n ...GlobalThis.tailor,\n context: {\n getInvoker: () => raw,\n },\n } as typeof GlobalThis.tailor;\n}\n\n/**\n * Sets up a mock for `globalThis.TailorErrors` used in bundled resolver tests.\n * Mimics the PF runtime's TailorErrors class that serializes errors with the `TailorErrors: ` prefix.\n * @deprecated Use the `tailor-runtime` environment from `@tailor-platform/sdk/vitest` which auto-injects TailorErrors.\n */\nexport function setupTailorErrorsMock(): void {\n GlobalThis.TailorErrors = class TailorErrors extends Error {\n errors: TailorErrorItem[];\n\n constructor(errors: TailorErrorItem[]) {\n super(`TailorErrors: ${JSON.stringify({ errors })}`);\n this.name = \"TailorErrors\";\n this.errors = errors;\n }\n };\n}\n\n/**\n * Sets up mocks for `globalThis.tailor.workflow.wait` and `.resolve` used in bundled workflow tests.\n * `execJobFunction` is stubbed to throw a helpful error directing to `setupWorkflowMock()`,\n * so mistakenly starting a job without job mocks produces a clear message instead of silently returning undefined.\n * @deprecated Use `mockWorkflow` from `@tailor-platform/sdk/vitest` with the `tailor-runtime` environment instead.\n * `setWaitHandler` / `setResolveHandler` cover wait/resolve, and `waitCalls` / `resolveCalls` give the same assertion shape.\n * @param config - Optional handlers for wait and resolve calls.\n * @param config.onWait - Handler called when wait is invoked.\n * @param config.onResolve - Handler called when resolve is invoked.\n * @returns Object containing arrays of wait and resolve calls for assertions.\n */\nexport function setupWaitPointMock(config?: { onWait?: WaitHandler; onResolve?: ResolveHandler }): {\n waitCalls: { key: string; payload: unknown }[];\n resolveCalls: { executionId: string; key: string }[];\n} {\n const waitCalls: { key: string; payload: unknown }[] = [];\n const resolveCalls: { executionId: string; key: string }[] = [];\n\n const throwUnmocked = (): never => {\n throw new Error(\n \"tailor.workflow.execJobFunction is not mocked. Use setupWorkflowMock() in tests.\",\n );\n };\n\n GlobalThis.tailor = {\n ...GlobalThis.tailor,\n workflow: {\n execJobFunction: throwUnmocked,\n startJobFunction: throwUnmocked,\n ...GlobalThis.tailor?.workflow,\n wait: (key: string, payload?: unknown) => {\n waitCalls.push({ key, payload });\n return config?.onWait?.(key, payload);\n },\n resolve: async (\n executionId: string,\n key: string,\n callback: (payload: unknown) => unknown,\n ) => {\n resolveCalls.push({ executionId, key });\n await config?.onResolve?.(executionId, key, callback);\n },\n },\n } as typeof GlobalThis.tailor;\n\n return { waitCalls, resolveCalls };\n}\n\n/**\n * Creates a function that imports a bundled JS file and returns its `main` export.\n * Used to test bundled output from `apply --buildOnly`.\n * @param baseDir - Base directory where bundled files are located.\n * @returns An async function that takes a relative path and returns the `main` function.\n * @deprecated This is an SDK-internal testing helper. Bundling integrity is the SDK's responsibility,\n * not the application's — verify your code through unit tests against the TypeScript source and\n * E2E tests against a deployed application instead. This export will be removed in a future release.\n */\nexport function createImportMain(baseDir: string): (relativePath: string) => Promise<MainFunction> {\n return async (relativePath: string): Promise<MainFunction> => {\n const fileUrl = pathToFileURL(path.join(baseDir, relativePath));\n fileUrl.searchParams.set(\"v\", `${Date.now()}-${Math.random()}`);\n const module = await import(fileUrl.href);\n const main = module.main;\n if (typeof main !== \"function\") {\n throw new Error(`Expected \"main\" to be a function in ${relativePath}, got ${typeof main}`);\n }\n return main;\n };\n}\n","import type { output } from \"#/configure/index\";\nimport type { TailorDBType } from \"#/configure/services/tailordb/schema\";\nimport type { TailorField } from \"#/configure/types/type\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\nexport {\n setupTailordbMock,\n setupTailorErrorsMock,\n setupWorkflowMock,\n setupInvokerMock,\n setupWaitPointMock,\n createImportMain,\n} from \"./mock\";\n\n/**\n * Creates a hook function that processes TailorDB type fields\n * - Uses existing id from data if provided, otherwise generates UUID for id fields\n * - Recursively processes nested types\n * - Executes hooks.create for fields with create hooks\n * @template T - The output type of the hook function\n * @param type - TailorDB type definition\n * @returns A function that transforms input data according to field hooks\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function createTailorDBHook<T extends TailorDBType<any, any>>(type: T) {\n return (data: unknown, now: Date = new Date()) => {\n const obj = data && typeof data === \"object\" ? (data as Record<string, unknown>) : undefined;\n const hooked = Object.entries(type.fields).reduce(\n (hooked, [key, value]) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const field = value as TailorField<any, any, any>;\n if (key === \"id\") {\n hooked[key] = obj?.[key] ?? crypto.randomUUID();\n } else if (field.type === \"nested\") {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const nestedHook = createTailorDBHook({ fields: field.fields } as any);\n if (field.metadata.array) {\n const nestedValue = obj?.[key];\n hooked[key] = Array.isArray(nestedValue)\n ? nestedValue.map((item) => nestedHook(item, now))\n : nestedValue;\n } else {\n hooked[key] = nestedHook(obj?.[key], now);\n }\n } else if (field.metadata.hooks?.create) {\n hooked[key] = field.metadata.hooks.create({\n input: obj?.[key],\n invoker: null,\n now,\n });\n if (hooked[key] instanceof Date) {\n hooked[key] = hooked[key].toISOString();\n }\n } else if (obj) {\n hooked[key] = obj[key];\n }\n if (hooked[key] == null && field.metadata.default !== undefined) {\n const isTimeType =\n field.type === \"datetime\" || field.type === \"date\" || field.type === \"time\";\n hooked[key] =\n field.metadata.default === \"now\" && isTimeType\n ? now.toISOString()\n : field.metadata.default;\n }\n return hooked;\n },\n {} as Record<string, unknown>,\n );\n\n // oxlint-disable-next-line typescript/no-unnecessary-condition -- metadata absent in recursive nested calls\n if (type.metadata?.typeHook?.create) {\n const { id: _id, ...typeHookInput } = hooked;\n // oxlint-disable-next-line typescript/no-unsafe-function-type\n const overrides = (type.metadata.typeHook.create as Function)({\n input: typeHookInput,\n invoker: null,\n now,\n });\n if (overrides && typeof overrides === \"object\") {\n for (const [key, value] of Object.entries(overrides as Record<string, unknown>)) {\n hooked[key] = value instanceof Date ? value.toISOString() : value;\n }\n }\n }\n\n // oxlint-disable-next-line typescript/no-unnecessary-condition -- metadata absent in recursive nested calls\n if (type.metadata?.typeValidate) {\n const { id: _id, ...newRecord } = hooked;\n // oxlint-disable-next-line typescript/no-unsafe-function-type\n (type.metadata.typeValidate as Function)(\n { newRecord, oldRecord: null, invoker: null },\n (field: string, message: string) => {\n throw new Error(`Validation failed on field '${field}': ${message}`);\n },\n );\n }\n\n return hooked as Partial<output<T>>;\n };\n}\n\n/**\n * Creates the standard schema definition for lines-db\n * This returns the first argument for defineSchema with the ~standard section\n * @template T - The output type after validation\n * @param schemaType - TailorDB field schema for validation\n * @param hook - Hook function to transform data before validation\n * @returns Schema object with ~standard section for defineSchema\n */\nexport function createStandardSchema<T = Record<string, unknown>>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schemaType: TailorField<any, T>,\n hook: (data: unknown) => Partial<T>,\n) {\n return {\n \"~standard\": {\n version: 1,\n vendor: \"@tailor-platform/sdk\",\n validate: (value: unknown) => {\n const hooked = hook(value);\n const result = schemaType.parse({\n value: hooked,\n data: hooked,\n invoker: null,\n });\n if (result.issues) {\n return result;\n }\n return { value: hooked as T };\n },\n },\n } as const satisfies StandardSchemaV1<T>;\n}\n"],"mappings":";;;;AA6DA,MAAM,aAAa;;;;;;;AAQnB,SAAgB,kBAAkB,iBAAgC,CAAC,GAGjE;CACA,MAAM,kBAA0D,CAAC;CACjE,MAAM,iBAA2D,CAAC;CAElE,MAAM,mBAAmB;EACvB,AAAQ;EAER,YAAY,EAAE,aAAqC;GACjD,KAAK,SAAS;IAAE;IAAW,OAAO;GAAM;GACxC,eAAe,KAAK,KAAK,MAAM;EACjC;EAEA,MAAM,UAAyB,CAE/B;EAEA,MAAM,MAAqB;GACzB,KAAK,OAAO,QAAQ;EACtB;EAEA,MAAM,YAAY,OAAe,SAAoB,CAAC,GAAiC;GACrF,gBAAgB,KAAK;IAAE;IAAO;GAAO,CAAC;GACtC,OAAO,EAAE,MAAM,SAAS,OAAO,MAAM,EAAE;EACzC;CACF;CAEA,WAAW,WAAW,EACpB,QAAQ,mBACV;CAEA,OAAO;EAAE;EAAiB;CAAe;AAC3C;;;;;;;;;AAUA,SAAgB,kBAAkB,SAEhC;CACA,MAAM,cAAoD,CAAC;CAE3D,MAAM,mBAAmB,SAAiB,SAA2B;EACnE,YAAY,KAAK;GAAE;GAAS;EAAK,CAAC;EAClC,OAAO,QAAQ,SAAS,IAAI;CAC9B;CAEA,WAAW,SAAS;EAClB,GAAG,WAAW;EACd,UAAU;GACR,YAAY;IACV,MAAM,IAAI,MACR,iGACF;GACF;GACA,SAAS,YAAY;IACnB,MAAM,IAAI,MACR,oGACF;GACF;GACA,GAAG,WAAW,QAAQ;GACtB;GACA,kBAAkB;EACpB;CACF;CAEA,OAAO,EAAE,YAAY;AACvB;;;;;;;AAQA,SAAgB,iBAAiB,SAAuC;CACtE,MAAM,MAA6B,UAC/B;EACE,IAAI,QAAQ;EACZ,MAAM,QAAQ;EACd,aAAa,QAAQ;EACrB,YAAY,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ACpC,KAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,SAAoC,GAC5E,OAAO,OAAO,iBAAiB,OAAO,MAAM,YAAY,IAAI;EAGlE;EAGA,IAAI,KAAK,UAAU,cAAc;GAC/B,MAAM,EAAE,IAAI,KAAK,GAAG,cAAc;GAElC,AAAC,KAAK,SAAS,aACb;IAAE;IAAW,WAAW;IAAM,SAAS;GAAK,IAC3C,OAAe,YAAoB;IAClC,MAAM,IAAI,MAAM,+BAA+B,MAAM,KAAK,SAAS;GACrE,CACF;EACF;EAEA,OAAO;CACT;AACF;;;;;;;;;AAUA,SAAgB,qBAEd,YACA,MACA;CACA,OAAO,EACL,aAAa;EACX,SAAS;EACT,QAAQ;EACR,WAAW,UAAmB;GAC5B,MAAM,SAAS,KAAK,KAAK;GACzB,MAAM,SAAS,WAAW,MAAM;IAC9B,OAAO;IACP,MAAM;IACN,SAAS;GACX,CAAC;GACD,IAAI,OAAO,QACT,OAAO;GAET,OAAO,EAAE,OAAO,OAAY;EAC9B;CACF,EACF;AACF"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/utils/test/index.ts"],"sourcesContent":["import type { output } from \"#/configure/index\";\nimport type { TailorDBType } from \"#/configure/services/tailordb/schema\";\nimport type { TailorField } from \"#/configure/types/type\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\n/**\n * Creates a hook function that processes TailorDB type fields\n * - Uses existing id from data if provided, otherwise generates UUID for id fields\n * - Recursively processes nested types\n * - Executes hooks.create for fields with create hooks\n * @template T - The output type of the hook function\n * @param type - TailorDB type definition\n * @returns A function that transforms input data according to field hooks\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function createTailorDBHook<T extends TailorDBType<any, any>>(type: T) {\n return (data: unknown, now: Date = new Date()) => {\n const obj = data && typeof data === \"object\" ? (data as Record<string, unknown>) : undefined;\n const hooked = Object.entries(type.fields).reduce(\n (hooked, [key, value]) => {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const field = value as TailorField<any, any, any>;\n if (key === \"id\") {\n hooked[key] = obj?.[key] ?? crypto.randomUUID();\n } else if (field.type === \"nested\") {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const nestedHook = createTailorDBHook({ fields: field.fields } as any);\n if (field.metadata.array) {\n const nestedValue = obj?.[key];\n hooked[key] = Array.isArray(nestedValue)\n ? nestedValue.map((item) => nestedHook(item, now))\n : nestedValue;\n } else {\n hooked[key] = nestedHook(obj?.[key], now);\n }\n } else if (field.metadata.hooks?.create) {\n hooked[key] = field.metadata.hooks.create({\n input: obj?.[key],\n invoker: null,\n now,\n });\n if (hooked[key] instanceof Date) {\n hooked[key] = hooked[key].toISOString();\n }\n } else if (obj) {\n hooked[key] = obj[key];\n }\n if (hooked[key] == null && field.metadata.default !== undefined) {\n const isTimeType =\n field.type === \"datetime\" || field.type === \"date\" || field.type === \"time\";\n hooked[key] =\n field.metadata.default === \"now\" && isTimeType\n ? now.toISOString()\n : field.metadata.default;\n }\n return hooked;\n },\n {} as Record<string, unknown>,\n );\n\n // oxlint-disable-next-line typescript/no-unnecessary-condition -- metadata absent in recursive nested calls\n if (type.metadata?.typeHook?.create) {\n const { id: _id, ...typeHookInput } = hooked;\n // oxlint-disable-next-line typescript/no-unsafe-function-type\n const overrides = (type.metadata.typeHook.create as Function)({\n input: typeHookInput,\n invoker: null,\n now,\n });\n if (overrides && typeof overrides === \"object\") {\n for (const [key, value] of Object.entries(overrides as Record<string, unknown>)) {\n hooked[key] = value instanceof Date ? value.toISOString() : value;\n }\n }\n }\n\n // oxlint-disable-next-line typescript/no-unnecessary-condition -- metadata absent in recursive nested calls\n if (type.metadata?.typeValidate) {\n const { id: _id, ...newRecord } = hooked;\n // oxlint-disable-next-line typescript/no-unsafe-function-type\n (type.metadata.typeValidate as Function)(\n { newRecord, oldRecord: null, invoker: null },\n (field: string, message: string) => {\n throw new Error(`Validation failed on field '${field}': ${message}`);\n },\n );\n }\n\n return hooked as Partial<output<T>>;\n };\n}\n\n/**\n * Creates the standard schema definition for lines-db\n * This returns the first argument for defineSchema with the ~standard section\n * @template T - The output type after validation\n * @param schemaType - TailorDB field schema for validation\n * @param hook - Hook function to transform data before validation\n * @returns Schema object with ~standard section for defineSchema\n */\nexport function createStandardSchema<T = Record<string, unknown>>(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n schemaType: TailorField<any, T>,\n hook: (data: unknown) => Partial<T>,\n) {\n return {\n \"~standard\": {\n version: 1,\n vendor: \"@tailor-platform/sdk\",\n validate: (value: unknown) => {\n const hooked = hook(value);\n const result = schemaType.parse({\n value: hooked,\n data: hooked,\n invoker: null,\n });\n if (result.issues) {\n return result;\n }\n return { value: hooked as T };\n },\n },\n } as const satisfies StandardSchemaV1<T>;\n}\n"],"mappings":";;;;;;;;;;AAeA,SAAgB,mBAAqD,MAAS;CAC5E,QAAQ,MAAe,sBAAY,IAAI,KAAK,MAAM;EAChD,MAAM,MAAM,QAAQ,OAAO,SAAS,WAAY,OAAmC;EACnF,MAAM,SAAS,OAAO,QAAQ,KAAK,MAAM,CAAC,CAAC,QACxC,QAAQ,CAAC,KAAK,WAAW;GAExB,MAAM,QAAQ;GACd,IAAI,QAAQ,MACV,OAAO,OAAO,MAAM,QAAQ,OAAO,WAAW;QACzC,IAAI,MAAM,SAAS,UAAU;IAElC,MAAM,aAAa,mBAAmB,EAAE,QAAQ,MAAM,OAAO,CAAQ;IACrE,IAAI,MAAM,SAAS,OAAO;KACxB,MAAM,cAAc,MAAM;KAC1B,OAAO,OAAO,MAAM,QAAQ,WAAW,IACnC,YAAY,KAAK,SAAS,WAAW,MAAM,GAAG,CAAC,IAC/C;IACN,OACE,OAAO,OAAO,WAAW,MAAM,MAAM,GAAG;GAE5C,OAAO,IAAI,MAAM,SAAS,OAAO,QAAQ;IACvC,OAAO,OAAO,MAAM,SAAS,MAAM,OAAO;KACxC,OAAO,MAAM;KACb,SAAS;KACT;IACF,CAAC;IACD,IAAI,OAAO,gBA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als, r as installPlatformGlobals, t as RUNTIME_FLAG_KEY } from "../globals-
|
|
1
|
+
import { n as cleanupPlatformGlobals, r as installPlatformGlobals, t as RUNTIME_FLAG_KEY } from "../globals-TfAVItuK.mjs";
|
|
2
2
|
import * as globals from "globals";
|
|
3
3
|
|
|
4
4
|
//#region src/vitest/environment.ts
|
package/dist/vitest/index.d.mts
CHANGED
|
@@ -44,8 +44,8 @@ import { Plugin } from "vitest/config";
|
|
|
44
44
|
*
|
|
45
45
|
* - **`process`** and **`require`** are NOT removed or blocked. Vitest's internal
|
|
46
46
|
* runner depends on them. On the real Tailor Platform runtime, they do not exist.
|
|
47
|
-
* - **Dynamic `import()`** of bundled files
|
|
48
|
-
*
|
|
47
|
+
* - **Dynamic `import()`** of bundled files bypasses the transform hook since
|
|
48
|
+
* those files are loaded through Node.js native loader.
|
|
49
49
|
* ## Options
|
|
50
50
|
*
|
|
51
51
|
* - **`config`** — Path to `tailor.config.ts`. Loads `defineSecretManager()` values
|
package/dist/vitest/index.mjs
CHANGED
|
@@ -1,52 +1,23 @@
|
|
|
1
1
|
import { i as getRegisteredJob, t as START_DEFAULT } from "../registry-BIGVUrMB.mjs";
|
|
2
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 { n as isNodeBuiltinImport, t as getNodeBuiltinMessage } from "../node-builtins-CmaL2Cbq.mjs";
|
|
4
5
|
import { t as platformSerialize } from "../platform-serialize-RoRtBS0v.mjs";
|
|
5
6
|
import { i as withDispose, n as tailorRoot, r as tailordbRoot, t as mockSecretmanager } from "../secretmanager-IY4UvinW.mjs";
|
|
6
|
-
import { builtinModules } from "node:module";
|
|
7
7
|
import { isEqual } from "es-toolkit";
|
|
8
8
|
import { fileURLToPath } from "node:url";
|
|
9
|
-
import { dirname, isAbsolute, matchesGlob, relative, resolve } from "node:path";
|
|
10
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
11
|
import { vi } from "vitest";
|
|
12
12
|
|
|
13
13
|
//#region src/vitest/blocked-modules.ts
|
|
14
14
|
/**
|
|
15
|
-
* Blocked Node.js built-in modules and their Web Standard API alternatives.
|
|
16
|
-
*
|
|
17
|
-
* The Tailor Platform runtime only provides Web Standard APIs.
|
|
18
|
-
* These Node.js modules are not available and should be replaced with
|
|
19
|
-
* the suggested alternatives.
|
|
20
|
-
*/
|
|
21
|
-
const SUGGESTIONS = {
|
|
22
|
-
crypto: "Use the Web Crypto API (globalThis.crypto) instead.",
|
|
23
|
-
buffer: "Use Uint8Array or ArrayBuffer instead.",
|
|
24
|
-
fs: "File system access is not available in the Tailor Platform runtime.",
|
|
25
|
-
"fs/promises": "File system access is not available in the Tailor Platform runtime.",
|
|
26
|
-
path: "Use URL or URLPattern for path manipulation.",
|
|
27
|
-
http: "Use the Fetch API (globalThis.fetch) for HTTP requests instead.",
|
|
28
|
-
https: "Use the Fetch API (globalThis.fetch) for HTTPS requests instead.",
|
|
29
|
-
url: "Use the URL and URLSearchParams Web APIs instead.",
|
|
30
|
-
util: "Use Web Standard APIs instead.",
|
|
31
|
-
stream: "Use Web Streams API (ReadableStream, WritableStream, TransformStream) instead.",
|
|
32
|
-
"stream/web": "Use Web Streams API (ReadableStream, WritableStream, TransformStream) instead.",
|
|
33
|
-
events: "Use EventTarget instead.",
|
|
34
|
-
zlib: "Use CompressionStream and DecompressionStream Web APIs instead.",
|
|
35
|
-
querystring: "Use URLSearchParams instead.",
|
|
36
|
-
string_decoder: "Use TextDecoder instead."
|
|
37
|
-
};
|
|
38
|
-
const BLOCKED_MODULES = /* @__PURE__ */ new Set();
|
|
39
|
-
for (const mod of builtinModules) {
|
|
40
|
-
BLOCKED_MODULES.add(mod);
|
|
41
|
-
BLOCKED_MODULES.add(`node:${mod}`);
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
15
|
* Check if a module specifier is a blocked Node.js built-in.
|
|
45
16
|
* @param specifier - Module specifier to check (e.g. "node:crypto", "fs")
|
|
46
17
|
* @returns Whether the specifier is blocked
|
|
47
18
|
*/
|
|
48
19
|
function isBlockedModule(specifier) {
|
|
49
|
-
return
|
|
20
|
+
return isNodeBuiltinImport(specifier);
|
|
50
21
|
}
|
|
51
22
|
/**
|
|
52
23
|
* Get the error message for a blocked module import.
|
|
@@ -54,10 +25,7 @@ function isBlockedModule(specifier) {
|
|
|
54
25
|
* @returns Error message with optional suggestion for the Web Standard API alternative
|
|
55
26
|
*/
|
|
56
27
|
function getBlockedMessage(specifier) {
|
|
57
|
-
|
|
58
|
-
const suggestion = SUGGESTIONS[bare];
|
|
59
|
-
const base = `"${specifier}" is not available in the Tailor Platform runtime.`;
|
|
60
|
-
return suggestion ? `${base} ${suggestion}` : base;
|
|
28
|
+
return getNodeBuiltinMessage(specifier);
|
|
61
29
|
}
|
|
62
30
|
|
|
63
31
|
//#endregion
|
|
@@ -1236,10 +1204,7 @@ function replaceStart(definition) {
|
|
|
1236
1204
|
/**
|
|
1237
1205
|
* Acquire a disposable mock for workflow operations (`tailor.workflow`).
|
|
1238
1206
|
* Restored on dispose.
|
|
1239
|
-
|
|
1240
|
-
* The canonical `execJobFunction` and its `startJobFunction` alias share the
|
|
1241
|
-
* same underlying `vi.fn`, so calls through either name are recorded once and
|
|
1242
|
-
* handlers configured on either name apply to both.
|
|
1207
|
+
|
|
1243
1208
|
* @returns Disposable workflow mock control object
|
|
1244
1209
|
* @example
|
|
1245
1210
|
* ```typescript
|
|
@@ -1282,7 +1247,6 @@ function mockWorkflow() {
|
|
|
1282
1247
|
const resumeShim = (executionId) => resumeWorkflowExecution(executionId);
|
|
1283
1248
|
root.workflow = {
|
|
1284
1249
|
execJobFunction: jobFunctionShim,
|
|
1285
|
-
startJobFunction: jobFunctionShim,
|
|
1286
1250
|
startWorkflow: workflowShim,
|
|
1287
1251
|
resumeWorkflowExecution: resumeShim,
|
|
1288
1252
|
wait: (key, payload) => wait(key, platformSerialize(payload)),
|
|
@@ -1294,11 +1258,6 @@ function mockWorkflow() {
|
|
|
1294
1258
|
return withDispose({
|
|
1295
1259
|
/** The `execJobFunction` `vi.fn`. */
|
|
1296
1260
|
execJobFunction,
|
|
1297
|
-
/**
|
|
1298
|
-
* Alias of `execJobFunction` (same `vi.fn` reference).
|
|
1299
|
-
* @deprecated Use `execJobFunction` instead.
|
|
1300
|
-
*/
|
|
1301
|
-
startJobFunction: execJobFunction,
|
|
1302
1261
|
/** The `startWorkflow` `vi.fn`. */
|
|
1303
1262
|
startWorkflow,
|
|
1304
1263
|
/** The `resumeWorkflowExecution` `vi.fn`. */
|
|
@@ -1511,7 +1470,7 @@ async function runWorkflowLocally(workflow, args, options) {
|
|
|
1511
1470
|
if (options?.env !== void 0) writeWorkflowTestEnv({ ...options.env });
|
|
1512
1471
|
root.tailor = {
|
|
1513
1472
|
...previousTailor,
|
|
1514
|
-
workflow: createLocalWorkflowRuntime(previousTailor?.workflow, runner.
|
|
1473
|
+
workflow: createLocalWorkflowRuntime(previousTailor?.workflow, runner.execJobFunction)
|
|
1515
1474
|
};
|
|
1516
1475
|
try {
|
|
1517
1476
|
return await runner.runJob(workflow.mainJob.name, args);
|
|
@@ -1524,7 +1483,7 @@ async function runWorkflowLocally(workflow, args, options) {
|
|
|
1524
1483
|
}
|
|
1525
1484
|
function createLocalJobRunner() {
|
|
1526
1485
|
let activeExecution;
|
|
1527
|
-
const
|
|
1486
|
+
const execJobFunction = (jobName, args) => {
|
|
1528
1487
|
if (!activeExecution) throw new Error(`Cannot start workflow job "${jobName}" outside runWorkflowLocally() job execution.`);
|
|
1529
1488
|
if (activeExecution.pending) throw activeExecution.pending;
|
|
1530
1489
|
const serializedArgs = platformSerialize(args);
|
|
@@ -1573,7 +1532,7 @@ function createLocalJobRunner() {
|
|
|
1573
1532
|
};
|
|
1574
1533
|
return {
|
|
1575
1534
|
runJob,
|
|
1576
|
-
|
|
1535
|
+
execJobFunction
|
|
1577
1536
|
};
|
|
1578
1537
|
}
|
|
1579
1538
|
async function settlePendingStart(records, pending, runJob) {
|
|
@@ -1609,7 +1568,6 @@ function createLocalWorkflowRuntime(previous, execJobFunction) {
|
|
|
1609
1568
|
};
|
|
1610
1569
|
return {
|
|
1611
1570
|
execJobFunction,
|
|
1612
|
-
startJobFunction: execJobFunction,
|
|
1613
1571
|
startWorkflow,
|
|
1614
1572
|
resumeWorkflowExecution,
|
|
1615
1573
|
wait: (key, payload) => {
|
|
@@ -1827,8 +1785,8 @@ function createKyselyMock() {
|
|
|
1827
1785
|
*
|
|
1828
1786
|
* - **`process`** and **`require`** are NOT removed or blocked. Vitest's internal
|
|
1829
1787
|
* runner depends on them. On the real Tailor Platform runtime, they do not exist.
|
|
1830
|
-
* - **Dynamic `import()`** of bundled files
|
|
1831
|
-
*
|
|
1788
|
+
* - **Dynamic `import()`** of bundled files bypasses the transform hook since
|
|
1789
|
+
* those files are loaded through Node.js native loader.
|
|
1832
1790
|
* ## Options
|
|
1833
1791
|
*
|
|
1834
1792
|
* - **`config`** — Path to `tailor.config.ts`. Loads `defineSecretManager()` values
|