@tailor-platform/sdk 1.74.0 → 1.75.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 +26 -0
- package/dist/application-BJKNlv8c.mjs +3 -0
- package/dist/{application-DwmoI6ZQ.mjs → application-DYshsH-K.mjs} +61 -11
- package/dist/application-DYshsH-K.mjs.map +1 -0
- package/dist/brand-Eo4pLXPJ.mjs.map +1 -1
- package/dist/cli/commands/deploy/workflow-execution-policy.d.mts +1 -0
- package/dist/cli/commands/tailordb/migrate/snapshot.d.mts +1 -16
- package/dist/cli/index.mjs +23 -34
- package/dist/cli/index.mjs.map +1 -1
- package/dist/cli/lib.d.mts +2 -2
- package/dist/cli/lib.mjs +3 -3
- package/dist/cli/lib.mjs.map +1 -1
- package/dist/completion/zsh-worker.zsh +9 -9
- package/dist/configure/config/types.d.mts +3 -1
- package/dist/configure/index.d.mts +3 -1
- package/dist/configure/index.mjs +113 -5
- package/dist/configure/index.mjs.map +1 -1
- package/dist/configure/services/index.d.mts +3 -1
- package/dist/configure/services/tailordb/schema.d.mts +5 -19
- package/dist/configure/services/workflow/execution-policy.d.mts +71 -0
- package/dist/configure/services/workflow/execution-policy.types.d.mts +104 -0
- package/dist/configure/services/workflow/index.d.mts +3 -1
- package/dist/configure/services/workflow/job.d.mts +7 -3
- package/dist/configure/types/field-runtime.d.mts +17 -0
- package/dist/configure/types/type.d.mts +1 -18
- package/dist/field-runtime-9bfXBAOK.mjs +183 -0
- package/dist/field-runtime-9bfXBAOK.mjs.map +1 -0
- package/dist/{globals-B8XX5TRB.mjs → globals-CcU1ONiK.mjs} +2 -2
- package/dist/globals-CcU1ONiK.mjs.map +1 -0
- package/dist/{job-CtU73PGa.mjs → job-D-PbD1P3.mjs} +5 -3
- package/dist/job-D-PbD1P3.mjs.map +1 -0
- package/dist/plugin/builtin/seed/index.mjs +1 -1
- package/dist/{registry-BozuxbPp.mjs → registry-NfSW0BRo.mjs} +4 -3
- package/dist/registry-NfSW0BRo.mjs.map +1 -0
- package/dist/runtime/globals.d.mts +1 -1
- package/dist/runtime/index.d.mts +1 -1
- package/dist/runtime/workflow.d.mts +22 -3
- package/dist/{runtime-Zkg3SUwi.mjs → runtime-CJ5usBOu.mjs} +456 -397
- package/dist/runtime-CJ5usBOu.mjs.map +1 -0
- package/dist/{schema-DAdZSFOd.mjs → schema-Dl_y0m9e.mjs} +8 -167
- package/dist/schema-Dl_y0m9e.mjs.map +1 -0
- package/dist/secretmanager-Bd45j7an.mjs +98 -0
- package/dist/secretmanager-Bd45j7an.mjs.map +1 -0
- package/dist/{seed-DoMTMLcm.mjs → seed-fm0LeYP2.mjs} +14 -3
- package/dist/seed-fm0LeYP2.mjs.map +1 -0
- package/dist/{service_pb-CIrhGwHk.mjs → service_pb-4unFyubn.mjs} +16 -6
- package/dist/{service_pb-CIrhGwHk.mjs.map → service_pb-4unFyubn.mjs.map} +1 -1
- package/dist/{service_pb-DjwIn4jO.mjs → service_pb-D-PXRoMg.mjs} +1 -1
- package/dist/tailor-proto/src/tailor/v1/service_pb.d.mts +1 -1
- package/dist/tailor-proto/src/tailor/v1/workflow_pb.d.mts +29 -9
- package/dist/tailor-proto/src/tailor/v1/workflow_resource_pb.d.mts +35 -1
- package/dist/types-BwzB2okW.mjs +199 -0
- package/dist/types-BwzB2okW.mjs.map +1 -0
- package/dist/types-KlawuVKa.mjs +4 -0
- package/dist/utils/test/index.mjs +1 -1
- package/dist/utils/test/index.mjs.map +1 -1
- package/dist/vitest/environment.mjs +1 -1
- package/dist/vitest/index.d.mts +8 -1
- package/dist/vitest/index.mjs +779 -1
- package/dist/vitest/index.mjs.map +1 -1
- package/dist/vitest/mock.d.mts +8 -363
- package/dist/vitest/mocks/aigateway.d.mts +30 -0
- package/dist/vitest/mocks/authconnection.d.mts +28 -0
- package/dist/vitest/mocks/file.d.mts +41 -0
- package/dist/vitest/mocks/iconv.d.mts +27 -0
- package/dist/vitest/mocks/idp.d.mts +44 -0
- package/dist/vitest/mocks/secretmanager.d.mts +33 -0
- package/dist/vitest/mocks/tailordb.d.mts +71 -0
- package/dist/vitest/mocks/workflow.d.mts +117 -0
- package/dist/vitest/setup.mjs +2 -2
- package/dist/workflow-DSwnYPPP.mjs.map +1 -1
- package/docs/configuration.md +24 -0
- package/docs/services/workflow.md +78 -0
- package/package.json +8 -8
- package/dist/application-BndtMTFY.mjs +0 -3
- package/dist/application-DwmoI6ZQ.mjs.map +0 -1
- package/dist/field-DOsJCPFa.mjs +0 -22
- package/dist/field-DOsJCPFa.mjs.map +0 -1
- package/dist/globals-B8XX5TRB.mjs.map +0 -1
- package/dist/job-CtU73PGa.mjs.map +0 -1
- package/dist/mock-Ce1GCi4-.mjs +0 -871
- package/dist/mock-Ce1GCi4-.mjs.map +0 -1
- package/dist/registry-BozuxbPp.mjs.map +0 -1
- package/dist/runtime-Zkg3SUwi.mjs.map +0 -1
- package/dist/schema-DAdZSFOd.mjs.map +0 -1
- package/dist/seed-DoMTMLcm.mjs.map +0 -1
- package/dist/types-qhFZ8y9B.mjs +0 -4
- package/dist/types-ywCGpzDZ.mjs +0 -360
- package/dist/types-ywCGpzDZ.mjs.map +0 -1
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { i as file_tailor_v1_service, n as PingRequestSchema, r as PingResponseSchema, t as OperatorService } from "./service_pb-
|
|
1
|
+
import { i as file_tailor_v1_service, n as PingRequestSchema, r as PingResponseSchema, t as OperatorService } from "./service_pb-4unFyubn.mjs";
|
|
2
2
|
|
|
3
3
|
export { OperatorService, PingRequestSchema, PingResponseSchema, file_tailor_v1_service };
|
|
@@ -3238,7 +3238,7 @@ declare const OperatorService: GenService<{
|
|
|
3238
3238
|
output: typeof DeleteWorkflowJobFunctionExecutionPolicyResponseSchema;
|
|
3239
3239
|
};
|
|
3240
3240
|
/**
|
|
3241
|
-
* GetWorkflowJobFunctionExecutionPolicy returns a workflow job function execution policy.
|
|
3241
|
+
* GetWorkflowJobFunctionExecutionPolicy returns a workflow job function execution policy by name.
|
|
3242
3242
|
*
|
|
3243
3243
|
* [Errors]
|
|
3244
3244
|
* - Unauthenticated: token is missing, expired, or invalid
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Filter, PageDirection } from "./resource_pb.mjs";
|
|
2
2
|
import { AuthInvoker } from "./auth_resource_pb.mjs";
|
|
3
|
-
import { ConcurrencyPolicy, RetryPolicy, Workflow, WorkflowExecution, WorkflowJobFunction, WorkflowJobFunctionExecutionPolicy } from "./workflow_resource_pb.mjs";
|
|
3
|
+
import { ConcurrencyPolicy, RetryPolicy, Workflow, WorkflowExecution, WorkflowJobFunction, WorkflowJobFunctionExecutionPolicy, WorkflowJobFunctionSummary } from "./workflow_resource_pb.mjs";
|
|
4
4
|
import { GenMessage } from "@bufbuild/protobuf/codegenv2";
|
|
5
5
|
import { Message } from "@bufbuild/protobuf";
|
|
6
6
|
|
|
@@ -450,9 +450,16 @@ declare const ListWorkflowJobFunctionsRequestSchema: GenMessage<ListWorkflowJobF
|
|
|
450
450
|
*/
|
|
451
451
|
declare type ListWorkflowJobFunctionsResponse = Message<"tailor.v1.ListWorkflowJobFunctionsResponse"> & {
|
|
452
452
|
/**
|
|
453
|
-
*
|
|
453
|
+
* Returns the lightweight WorkflowJobFunctionSummary projection (no script /
|
|
454
|
+
* script_ref) so workspace-wide listings do not have to materialise multi-MB
|
|
455
|
+
* payloads. Field tags match WorkflowJobFunction, so the change is wire
|
|
456
|
+
* compatible for clients that only read id / name / version / created_at.
|
|
457
|
+
* Use GetWorkflowJobFunction / GetWorkflowJobFunctionByName to fetch the
|
|
458
|
+
* script body for a specific job function.
|
|
459
|
+
*
|
|
460
|
+
* @generated from field: repeated tailor.v1.WorkflowJobFunctionSummary job_functions = 1;
|
|
454
461
|
*/
|
|
455
|
-
jobFunctions:
|
|
462
|
+
jobFunctions: WorkflowJobFunctionSummary[];
|
|
456
463
|
/**
|
|
457
464
|
* @generated from field: string next_page_token = 2;
|
|
458
465
|
*/
|
|
@@ -636,6 +643,10 @@ declare type CreateWorkflowJobFunctionExecutionPolicyRequest = Message<"tailor.v
|
|
|
636
643
|
*/
|
|
637
644
|
workspaceId: string;
|
|
638
645
|
/**
|
|
646
|
+
* 2..64 chars, starts with [a-z0-9], middle from [a-z0-9_:.-], last char
|
|
647
|
+
* is [a-z0-9] or `*` (trailing-wildcard form). Platform does not assign
|
|
648
|
+
* meaning to the prefix's tail character; the caller decides.
|
|
649
|
+
*
|
|
639
650
|
* @generated from field: string execution_policy_key = 2;
|
|
640
651
|
*/
|
|
641
652
|
executionPolicyKey: string;
|
|
@@ -643,6 +654,10 @@ declare type CreateWorkflowJobFunctionExecutionPolicyRequest = Message<"tailor.v
|
|
|
643
654
|
* @generated from field: optional tailor.v1.ConcurrencyPolicy concurrency_policy = 3;
|
|
644
655
|
*/
|
|
645
656
|
concurrencyPolicy?: ConcurrencyPolicy;
|
|
657
|
+
/**
|
|
658
|
+
* @generated from field: string execution_policy_name = 4;
|
|
659
|
+
*/
|
|
660
|
+
executionPolicyName: string;
|
|
646
661
|
};
|
|
647
662
|
/**
|
|
648
663
|
* Describes the message tailor.v1.CreateWorkflowJobFunctionExecutionPolicyRequest.
|
|
@@ -672,9 +687,9 @@ declare type UpdateWorkflowJobFunctionExecutionPolicyRequest = Message<"tailor.v
|
|
|
672
687
|
*/
|
|
673
688
|
workspaceId: string;
|
|
674
689
|
/**
|
|
675
|
-
* @generated from field: string
|
|
690
|
+
* @generated from field: string execution_policy_name = 2;
|
|
676
691
|
*/
|
|
677
|
-
|
|
692
|
+
executionPolicyName: string;
|
|
678
693
|
/**
|
|
679
694
|
* @generated from field: optional tailor.v1.ConcurrencyPolicy concurrency_policy = 3;
|
|
680
695
|
*/
|
|
@@ -708,9 +723,9 @@ declare type DeleteWorkflowJobFunctionExecutionPolicyRequest = Message<"tailor.v
|
|
|
708
723
|
*/
|
|
709
724
|
workspaceId: string;
|
|
710
725
|
/**
|
|
711
|
-
* @generated from field: string
|
|
726
|
+
* @generated from field: string execution_policy_name = 2;
|
|
712
727
|
*/
|
|
713
|
-
|
|
728
|
+
executionPolicyName: string;
|
|
714
729
|
};
|
|
715
730
|
/**
|
|
716
731
|
* Describes the message tailor.v1.DeleteWorkflowJobFunctionExecutionPolicyRequest.
|
|
@@ -735,9 +750,9 @@ declare type GetWorkflowJobFunctionExecutionPolicyRequest = Message<"tailor.v1.G
|
|
|
735
750
|
*/
|
|
736
751
|
workspaceId: string;
|
|
737
752
|
/**
|
|
738
|
-
* @generated from field: string
|
|
753
|
+
* @generated from field: string execution_policy_name = 2;
|
|
739
754
|
*/
|
|
740
|
-
|
|
755
|
+
executionPolicyName: string;
|
|
741
756
|
};
|
|
742
757
|
/**
|
|
743
758
|
* Describes the message tailor.v1.GetWorkflowJobFunctionExecutionPolicyRequest.
|
|
@@ -767,6 +782,11 @@ declare type GetWorkflowJobFunctionExecutionPolicyByKeyRequest = Message<"tailor
|
|
|
767
782
|
*/
|
|
768
783
|
workspaceId: string;
|
|
769
784
|
/**
|
|
785
|
+
* Looks up a policy by its declared key (exact or wildcard form). Pass the
|
|
786
|
+
* wildcard pattern literal (e.g. `tenant-api*`) to fetch a wildcard
|
|
787
|
+
* policy; concrete keys do not resolve here, the dispatch path uses
|
|
788
|
+
* prefix resolution instead.
|
|
789
|
+
*
|
|
770
790
|
* @generated from field: string execution_policy_key = 2;
|
|
771
791
|
*/
|
|
772
792
|
executionPolicyKey: string;
|
|
@@ -34,6 +34,33 @@ declare type WorkflowJobFunction = Message<"tailor.v1.WorkflowJobFunction"> & {
|
|
|
34
34
|
*/
|
|
35
35
|
scriptRef?: string;
|
|
36
36
|
};
|
|
37
|
+
/**
|
|
38
|
+
* WorkflowJobFunctionSummary is the lightweight projection of WorkflowJobFunction
|
|
39
|
+
* returned by list endpoints. Field tags are intentionally aligned with
|
|
40
|
+
* WorkflowJobFunction so clients generated against either message can decode
|
|
41
|
+
* the other on the wire. The heavy `script` (tag 3) and `script_ref` (tag 6)
|
|
42
|
+
* fields are omitted; callers that need them must use the Get* endpoints.
|
|
43
|
+
*
|
|
44
|
+
* @generated from message tailor.v1.WorkflowJobFunctionSummary
|
|
45
|
+
*/
|
|
46
|
+
declare type WorkflowJobFunctionSummary = Message<"tailor.v1.WorkflowJobFunctionSummary"> & {
|
|
47
|
+
/**
|
|
48
|
+
* @generated from field: string id = 1;
|
|
49
|
+
*/
|
|
50
|
+
id: string;
|
|
51
|
+
/**
|
|
52
|
+
* @generated from field: string name = 2;
|
|
53
|
+
*/
|
|
54
|
+
name: string;
|
|
55
|
+
/**
|
|
56
|
+
* @generated from field: int64 version = 4;
|
|
57
|
+
*/
|
|
58
|
+
version: bigint;
|
|
59
|
+
/**
|
|
60
|
+
* @generated from field: google.protobuf.Timestamp created_at = 5;
|
|
61
|
+
*/
|
|
62
|
+
createdAt?: Timestamp;
|
|
63
|
+
};
|
|
37
64
|
/**
|
|
38
65
|
* @generated from message tailor.v1.ConcurrencyPolicy
|
|
39
66
|
*/
|
|
@@ -137,6 +164,13 @@ declare type WorkflowJobFunctionExecutionPolicy = Message<"tailor.v1.WorkflowJob
|
|
|
137
164
|
* @generated from field: optional tailor.v1.ConcurrencyPolicy concurrency_policy = 5;
|
|
138
165
|
*/
|
|
139
166
|
concurrencyPolicy?: ConcurrencyPolicy;
|
|
167
|
+
/**
|
|
168
|
+
* Distinct from execution_policy_key. Future policy shapes with
|
|
169
|
+
* wildcard-like keys can still expose a well-formed name here.
|
|
170
|
+
*
|
|
171
|
+
* @generated from field: string name = 6;
|
|
172
|
+
*/
|
|
173
|
+
name: string;
|
|
140
174
|
};
|
|
141
175
|
/**
|
|
142
176
|
* @generated from message tailor.v1.WorkflowJobExecution
|
|
@@ -273,4 +307,4 @@ declare enum WorkflowExecution_Status {
|
|
|
273
307
|
WAITING = 7
|
|
274
308
|
}
|
|
275
309
|
//#endregion
|
|
276
|
-
export { ConcurrencyPolicy, RetryPolicy, Workflow, WorkflowExecution, WorkflowExecution_Status, WorkflowJobExecution, WorkflowJobExecution_Status, WorkflowJobFunction, WorkflowJobFunctionExecutionPolicy };
|
|
310
|
+
export { ConcurrencyPolicy, RetryPolicy, Workflow, WorkflowExecution, WorkflowExecution_Status, WorkflowJobExecution, WorkflowJobExecution_Status, WorkflowJobFunction, WorkflowJobFunctionExecutionPolicy, WorkflowJobFunctionSummary };
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { n as mapAllowedValues, t as parseInternal } from "./field-runtime-9bfXBAOK.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/configure/types/type.ts
|
|
4
|
+
function createTailorField(type, options, fields, values, metadata) {
|
|
5
|
+
const _metadata = metadata ? {
|
|
6
|
+
...metadata,
|
|
7
|
+
...metadata.allowedValues && { allowedValues: metadata.allowedValues.map((v) => ({ ...v })) },
|
|
8
|
+
...metadata.validate && { validate: metadata.validate.map((v) => Array.isArray(v) ? [...v] : v) }
|
|
9
|
+
} : { required: true };
|
|
10
|
+
if (!metadata) {
|
|
11
|
+
if (options) {
|
|
12
|
+
if (options.optional === true) _metadata.required = false;
|
|
13
|
+
if (options.array === true) _metadata.array = true;
|
|
14
|
+
}
|
|
15
|
+
if (values) _metadata.allowedValues = mapAllowedValues(values);
|
|
16
|
+
}
|
|
17
|
+
function parseInternal$1(args) {
|
|
18
|
+
return parseInternal({
|
|
19
|
+
...args,
|
|
20
|
+
field
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Clone the field and apply metadata updates to the clone.
|
|
25
|
+
* The original instance is never mutated, so a field shared across places
|
|
26
|
+
* cannot leak metadata between them.
|
|
27
|
+
* @param metadataUpdates - Metadata properties to overwrite on the clone
|
|
28
|
+
* @returns A new field with the updated metadata
|
|
29
|
+
*/
|
|
30
|
+
function cloneWith(metadataUpdates) {
|
|
31
|
+
const cloned = field.clone();
|
|
32
|
+
Object.assign(cloned._metadata, metadataUpdates);
|
|
33
|
+
return cloned;
|
|
34
|
+
}
|
|
35
|
+
const field = {
|
|
36
|
+
type,
|
|
37
|
+
fields: fields ?? {},
|
|
38
|
+
_defined: void 0,
|
|
39
|
+
_output: void 0,
|
|
40
|
+
_metadata,
|
|
41
|
+
get metadata() {
|
|
42
|
+
return { ...this._metadata };
|
|
43
|
+
},
|
|
44
|
+
description(description) {
|
|
45
|
+
return cloneWith({ description });
|
|
46
|
+
},
|
|
47
|
+
typeName(typeName) {
|
|
48
|
+
return cloneWith({ typeName });
|
|
49
|
+
},
|
|
50
|
+
validate(...validateInputs) {
|
|
51
|
+
return cloneWith({ validate: validateInputs });
|
|
52
|
+
},
|
|
53
|
+
parse(args) {
|
|
54
|
+
return parseInternal$1({
|
|
55
|
+
value: args.value,
|
|
56
|
+
data: args.data,
|
|
57
|
+
user: args.user,
|
|
58
|
+
pathArray: []
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
_parseInternal: parseInternal$1,
|
|
62
|
+
clone() {
|
|
63
|
+
let clonedFields = fields;
|
|
64
|
+
if (fields) {
|
|
65
|
+
const cloned = {};
|
|
66
|
+
for (const [key, nestedField] of Object.entries(fields)) cloned[key] = nestedField.clone();
|
|
67
|
+
clonedFields = cloned;
|
|
68
|
+
}
|
|
69
|
+
return createTailorField(type, options, clonedFields, values, this._metadata);
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
return field;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Create a UUID field for resolver input/output.
|
|
76
|
+
* @param options - Field configuration options
|
|
77
|
+
* @returns A UUID field
|
|
78
|
+
* @example t.uuid()
|
|
79
|
+
*/
|
|
80
|
+
function uuid(options) {
|
|
81
|
+
return createTailorField("uuid", options);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Create a string field for resolver input/output.
|
|
85
|
+
* @param options - Field configuration options
|
|
86
|
+
* @returns A string field
|
|
87
|
+
* @example t.string()
|
|
88
|
+
* @example t.string({ optional: true })
|
|
89
|
+
* @example t.string({ array: true })
|
|
90
|
+
*/
|
|
91
|
+
function string(options) {
|
|
92
|
+
return createTailorField("string", options);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Create a boolean field for resolver input/output.
|
|
96
|
+
* @param options - Field configuration options
|
|
97
|
+
* @returns A boolean field
|
|
98
|
+
* @example t.bool()
|
|
99
|
+
*/
|
|
100
|
+
function bool(options) {
|
|
101
|
+
return createTailorField("boolean", options);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Create an integer field for resolver input/output.
|
|
105
|
+
* @param options - Field configuration options
|
|
106
|
+
* @returns An integer field
|
|
107
|
+
* @example t.int()
|
|
108
|
+
*/
|
|
109
|
+
function int(options) {
|
|
110
|
+
return createTailorField("integer", options);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Create a float field for resolver input/output.
|
|
114
|
+
* @param options - Field configuration options
|
|
115
|
+
* @returns A float field
|
|
116
|
+
* @example t.float()
|
|
117
|
+
*/
|
|
118
|
+
function float(options) {
|
|
119
|
+
return createTailorField("float", options);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Create a decimal field for resolver input/output (stored as string for precision).
|
|
123
|
+
* @param options - Field configuration options
|
|
124
|
+
* @returns A decimal field
|
|
125
|
+
* @example t.decimal()
|
|
126
|
+
* @example t.decimal({ optional: true })
|
|
127
|
+
*/
|
|
128
|
+
function decimal(options) {
|
|
129
|
+
return createTailorField("decimal", options);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Create a date field for resolver input/output.
|
|
133
|
+
* @param options - Field configuration options
|
|
134
|
+
* @returns A date field
|
|
135
|
+
* @example t.date()
|
|
136
|
+
*/
|
|
137
|
+
function date(options) {
|
|
138
|
+
return createTailorField("date", options);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Create a datetime field for resolver input/output.
|
|
142
|
+
* @param options - Field configuration options
|
|
143
|
+
* @returns A datetime field
|
|
144
|
+
* @example t.datetime()
|
|
145
|
+
*/
|
|
146
|
+
function datetime(options) {
|
|
147
|
+
return createTailorField("datetime", options);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Create a time field for resolver input/output.
|
|
151
|
+
* @param options - Field configuration options
|
|
152
|
+
* @returns A time field
|
|
153
|
+
* @example t.time()
|
|
154
|
+
*/
|
|
155
|
+
function time(options) {
|
|
156
|
+
return createTailorField("time", options);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Create an enum field for resolver input/output.
|
|
160
|
+
* @param values - Array of allowed string values
|
|
161
|
+
* @param options - Field configuration options
|
|
162
|
+
* @returns An enum field
|
|
163
|
+
* @example t.enum(["active", "inactive"])
|
|
164
|
+
*/
|
|
165
|
+
function _enum(values, options) {
|
|
166
|
+
return createTailorField("enum", options, void 0, values);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Create a nested object field for resolver input/output.
|
|
170
|
+
* @param fields - Record of field definitions
|
|
171
|
+
* @param options - Field options (optional, array)
|
|
172
|
+
* @returns A nested object field
|
|
173
|
+
* @example
|
|
174
|
+
* // Single object:
|
|
175
|
+
* output: t.object({ name: t.string(), email: t.string() })
|
|
176
|
+
* @example
|
|
177
|
+
* // Array of objects:
|
|
178
|
+
* items: t.object({ name: t.string() }, { array: true })
|
|
179
|
+
*/
|
|
180
|
+
function object(fields, options) {
|
|
181
|
+
return createTailorField("nested", options, fields);
|
|
182
|
+
}
|
|
183
|
+
const t = {
|
|
184
|
+
uuid,
|
|
185
|
+
string,
|
|
186
|
+
bool,
|
|
187
|
+
int,
|
|
188
|
+
float,
|
|
189
|
+
decimal,
|
|
190
|
+
date,
|
|
191
|
+
datetime,
|
|
192
|
+
time,
|
|
193
|
+
enum: _enum,
|
|
194
|
+
object
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
//#endregion
|
|
198
|
+
export { t };
|
|
199
|
+
//# sourceMappingURL=types-BwzB2okW.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-BwzB2okW.mjs","names":["parseInternal","parseFieldInternal"],"sources":["../src/configure/types/type.ts"],"sourcesContent":["import { type AllowedValues, type AllowedValuesOutput, mapAllowedValues } from \"./field\";\nimport {\n parseInternal as parseFieldInternal,\n type FieldParseArgs,\n type FieldParseInternalArgs,\n} from \"./field-runtime\";\nimport type {\n DefinedFieldMetadata,\n TailorFieldType,\n TailorToTs,\n FieldMetadata,\n FieldOptions,\n FieldOutput,\n TailorField as TailorFieldBase,\n FieldValidateInput,\n} from \"#/configure/types/field.types\";\nimport type { InferFieldsOutput, TypeLevelError } from \"#/types/helpers\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\n// Erased fields stay assignable across builder method-state changes.\n// oxlint-disable-next-line no-explicit-any\ntype AnyBuilderMethod = any;\n\nexport type TailorAnyField = Omit<\n TailorFieldBase<AnyBuilderMethod, AnyBuilderMethod, FieldMetadata, TailorFieldType>,\n \"fields\"\n> & {\n readonly fields: Record<string, AnyBuilderMethod>;\n _metadata: FieldMetadata;\n description: AnyBuilderMethod;\n typeName: AnyBuilderMethod;\n validate: AnyBuilderMethod;\n parse: AnyBuilderMethod;\n _parseInternal: AnyBuilderMethod;\n};\n\ntype IsAny<T> = 0 extends 1 & T ? true : false;\ntype WithFieldDescription<Defined> = Defined & { description: true };\ntype WithFieldTypeName<Defined> = Defined & { typeName: true };\ntype WithFieldValidate<Defined> = Defined & { validate: true };\ntype FieldDescriptionFn<Defined extends DefinedFieldMetadata, Output> = (\n description: string,\n) => TailorField<WithFieldDescription<Defined>, Output>;\ntype FieldTypeNameFn<Defined extends DefinedFieldMetadata, Output> = (\n typeName: string,\n) => TailorField<WithFieldTypeName<Defined>, Output>;\ntype FieldValidateFn<Defined extends DefinedFieldMetadata, Output> = (\n ...validate: FieldValidateInput<Output>[]\n) => TailorField<WithFieldValidate<Defined>, Output>;\ntype FieldDescriptionMethod<Defined extends DefinedFieldMetadata, Output> =\n IsAny<Defined> extends true\n ? FieldDescriptionFn<Defined, Output>\n : Defined extends { description: unknown }\n ? TypeLevelError<\".description() has already been set\">\n : FieldDescriptionFn<Defined, Output>;\ntype FieldTypeNameMethod<Defined extends DefinedFieldMetadata, Output> =\n IsAny<Defined> extends true\n ? TypeLevelError<string>\n : Defined extends { typeName: unknown }\n ? TypeLevelError<\".typeName() has already been set\">\n : Defined extends { type: \"enum\" | \"nested\" }\n ? FieldTypeNameFn<Defined, Output>\n : TypeLevelError<\"typeName can only be set on enum or object fields\">;\ntype FieldValidateMethod<Defined extends DefinedFieldMetadata, Output> =\n IsAny<Defined> extends true\n ? FieldValidateFn<Defined, Output>\n : Defined extends { validate: unknown }\n ? TypeLevelError<\".validate() has already been set\">\n : FieldValidateFn<Defined, Output>;\n\n/**\n * Full TailorField interface with builder methods.\n * Extends the minimal structural interface from types/ with fluent API methods.\n */\nexport interface TailorField<\n Defined extends DefinedFieldMetadata = DefinedFieldMetadata,\n // Generic default output type (kept loose on purpose for library ergonomics).\n // oxlint-disable-next-line no-explicit-any\n Output = any,\n M extends FieldMetadata = FieldMetadata,\n T extends TailorFieldType = TailorFieldType,\n> extends TailorFieldBase<Defined, Output, M, T> {\n readonly fields: Record<string, TailorAnyField>;\n _metadata: M;\n\n /**\n * Set a description for the field\n * @param description - The description text\n * @returns The field with updated metadata\n */\n description: FieldDescriptionMethod<Defined, Output>;\n\n /**\n * Set a custom type name for enum or nested types\n * @param typeName - The custom type name\n * @returns The field with updated metadata\n */\n typeName: FieldTypeNameMethod<Defined, Output>;\n\n /**\n * Add validation functions to the field\n * @param validate - One or more validation functions\n * @returns The field with updated metadata\n */\n validate: FieldValidateMethod<Defined, Output>;\n\n /**\n * Parse and validate a value against this field's validation rules\n * Returns StandardSchema Result type with success or failure\n * @param args - Value, context data, and user\n * @returns Validation result\n */\n parse(args: FieldParseArgs): StandardSchemaV1.Result<Output>;\n\n /**\n * Internal parse method that tracks field path for nested validation\n * @private\n * @param args - Parse arguments\n * @returns Validation result\n */\n _parseInternal(args: FieldParseInternalArgs): StandardSchemaV1.Result<Output>;\n}\n\n/**\n * Internal shape carried by every runtime field for clone-on-write support.\n *\n * `clone()` is intentionally kept off the public {@link TailorField} interface:\n * adding it there would force `TailorDBField` (which has a differently-typed\n * `clone`) to stop being assignable to `TailorField`, breaking the supported\n * `t.object({ field: db.string() })` usage. Every `t.*` and `db.*` field carries\n * a `clone()` at runtime, so the internal cast in `clone()` is safe.\n */\ntype CloneableField = { clone(): TailorAnyField };\n\ntype TailorFieldRuntime<\n Defined extends DefinedFieldMetadata,\n Output,\n M extends FieldMetadata = FieldMetadata,\n T extends TailorFieldType = TailorFieldType,\n> = TailorFieldBase<Defined, Output, M, T> & {\n readonly fields: Record<string, TailorAnyField>;\n _metadata: M;\n description(description: string): object;\n typeName(typeName: string): object;\n validate(...validate: FieldValidateInput<Output>[]): object;\n parse(args: FieldParseArgs): StandardSchemaV1.Result<Output>;\n _parseInternal(args: FieldParseInternalArgs): StandardSchemaV1.Result<Output>;\n clone(): TailorAnyField;\n};\n\n/**\n * Creates a new TailorField instance.\n * @param type - Field type\n * @param options - Field options\n * @param fields - Nested fields for object-like types\n * @param values - Allowed values for enum-like fields\n * @param metadata - Pre-built metadata to clone from (used by `clone()`); when\n * given, the mutable containers are deep-copied here and `options`/`values` are\n * ignored for metadata construction\n * @returns A new TailorField\n */\nfunction createTailorField<\n const T extends TailorFieldType,\n const TOptions extends FieldOptions,\n const OutputBase = TailorToTs[T],\n>(\n type: T,\n options?: TOptions,\n fields?: Record<string, TailorAnyField>,\n values?: AllowedValues,\n metadata?: FieldMetadata,\n): TailorField<\n { type: T; array: TOptions extends { array: true } ? true : false },\n FieldOutput<OutputBase, TOptions>\n>;\nfunction createTailorField<\n const T extends TailorFieldType,\n const TOptions extends FieldOptions,\n const OutputBase = TailorToTs[T],\n>(\n type: T,\n options?: TOptions,\n fields?: Record<string, TailorAnyField>,\n values?: AllowedValues,\n metadata?: FieldMetadata,\n): object {\n type FieldValue = FieldOutput<OutputBase, TOptions>;\n\n // When cloning, take ownership of the source metadata and deep-copy its mutable\n // containers (enum value objects and `[fn, message]` validator tuples; validator\n // functions are kept by reference) so no two instances share mutable state.\n const _metadata: FieldMetadata = metadata\n ? {\n ...metadata,\n ...(metadata.allowedValues && {\n allowedValues: metadata.allowedValues.map((v) => ({ ...v })),\n }),\n ...(metadata.validate && {\n validate: metadata.validate.map((v) => (Array.isArray(v) ? ([...v] as typeof v) : v)),\n }),\n }\n : { required: true };\n\n if (!metadata) {\n if (options) {\n if (options.optional === true) {\n _metadata.required = false;\n }\n if (options.array === true) {\n _metadata.array = true;\n }\n }\n if (values) {\n _metadata.allowedValues = mapAllowedValues(values);\n }\n }\n\n function parseInternal(\n args: FieldParseInternalArgs,\n ): StandardSchemaV1.Result<FieldOutput<OutputBase, TOptions>> {\n return parseFieldInternal<T, FieldOutput<OutputBase, TOptions>>({\n ...args,\n field,\n });\n }\n\n /**\n * Clone the field and apply metadata updates to the clone.\n * The original instance is never mutated, so a field shared across places\n * cannot leak metadata between them.\n * @param metadataUpdates - Metadata properties to overwrite on the clone\n * @returns A new field with the updated metadata\n */\n function cloneWith(metadataUpdates: Partial<FieldMetadata>) {\n const cloned = field.clone();\n Object.assign(cloned._metadata, metadataUpdates);\n return cloned;\n }\n\n const field: TailorFieldRuntime<\n { type: T; array: TOptions extends { array: true } ? true : false },\n FieldValue,\n FieldMetadata,\n T\n > = {\n type,\n fields: fields ?? {},\n _defined: undefined as unknown as {\n type: T;\n array: TOptions extends { array: true } ? true : false;\n },\n _output: undefined as FieldOutput<OutputBase, TOptions>,\n _metadata,\n\n get metadata() {\n return { ...this._metadata };\n },\n\n description(description: string) {\n // Clone-on-write so a shared field instance never leaks metadata.\n return cloneWith({ description });\n },\n\n typeName(typeName: string) {\n // Clone-on-write so a shared field instance never leaks metadata.\n return cloneWith({ typeName });\n },\n\n validate(...validateInputs: FieldValidateInput<FieldValue>[]) {\n // Clone-on-write so a shared field instance never leaks metadata.\n return cloneWith({ validate: validateInputs });\n },\n\n parse(args: FieldParseArgs): StandardSchemaV1.Result<FieldOutput<OutputBase, TOptions>> {\n return parseInternal({\n value: args.value,\n data: args.data,\n user: args.user,\n pathArray: [],\n });\n },\n\n _parseInternal: parseInternal,\n\n clone() {\n // Deep clone nested object fields so the new instance shares no mutable state.\n let clonedFields = fields;\n if (fields) {\n const cloned: Record<string, TailorAnyField> = {};\n for (const [key, nestedField] of Object.entries(fields)) {\n // Both t.* and db.* fields carry clone() at runtime (see CloneableField).\n cloned[key] = (nestedField as TailorAnyField & CloneableField).clone();\n }\n clonedFields = cloned;\n }\n\n // Rebuild via the factory, handing it this field's metadata so the new\n // parseInternal closure rebinds to the clone and the factory owns the metadata deep-copy.\n // oxlint-disable-next-line no-explicit-any\n return createTailorField(type, options, clonedFields, values, this._metadata) as any;\n },\n };\n\n return field;\n}\n\n/**\n * Create a UUID field for resolver input/output.\n * @param options - Field configuration options\n * @returns A UUID field\n * @example t.uuid()\n */\nfunction uuid<const Opt extends FieldOptions>(options?: Opt) {\n return createTailorField(\"uuid\", options);\n}\n\n/**\n * Create a string field for resolver input/output.\n * @param options - Field configuration options\n * @returns A string field\n * @example t.string()\n * @example t.string({ optional: true })\n * @example t.string({ array: true })\n */\nfunction string<const Opt extends FieldOptions>(options?: Opt) {\n return createTailorField(\"string\", options);\n}\n\n/**\n * Create a boolean field for resolver input/output.\n * @param options - Field configuration options\n * @returns A boolean field\n * @example t.bool()\n */\nfunction bool<const Opt extends FieldOptions>(options?: Opt) {\n return createTailorField(\"boolean\", options);\n}\n\n/**\n * Create an integer field for resolver input/output.\n * @param options - Field configuration options\n * @returns An integer field\n * @example t.int()\n */\nfunction int<const Opt extends FieldOptions>(options?: Opt) {\n return createTailorField(\"integer\", options);\n}\n\n/**\n * Create a float field for resolver input/output.\n * @param options - Field configuration options\n * @returns A float field\n * @example t.float()\n */\nfunction float<const Opt extends FieldOptions>(options?: Opt) {\n return createTailorField(\"float\", options);\n}\n\n/**\n * Create a decimal field for resolver input/output (stored as string for precision).\n * @param options - Field configuration options\n * @returns A decimal field\n * @example t.decimal()\n * @example t.decimal({ optional: true })\n */\nfunction decimal<const Opt extends FieldOptions>(options?: Opt) {\n return createTailorField(\"decimal\", options);\n}\n\n/**\n * Create a date field for resolver input/output.\n * @param options - Field configuration options\n * @returns A date field\n * @example t.date()\n */\nfunction date<const Opt extends FieldOptions>(options?: Opt) {\n return createTailorField(\"date\", options);\n}\n\n/**\n * Create a datetime field for resolver input/output.\n * @param options - Field configuration options\n * @returns A datetime field\n * @example t.datetime()\n */\nfunction datetime<const Opt extends FieldOptions>(options?: Opt) {\n return createTailorField(\"datetime\", options);\n}\n\n/**\n * Create a time field for resolver input/output.\n * @param options - Field configuration options\n * @returns A time field\n * @example t.time()\n */\nfunction time<const Opt extends FieldOptions>(options?: Opt) {\n return createTailorField(\"time\", options);\n}\n\n/**\n * Create an enum field for resolver input/output.\n * @param values - Array of allowed string values\n * @param options - Field configuration options\n * @returns An enum field\n * @example t.enum([\"active\", \"inactive\"])\n */\nfunction _enum<const V extends AllowedValues, const Opt extends FieldOptions>(\n values: V,\n options?: Opt,\n): TailorField<\n { type: \"enum\"; array: Opt extends { array: true } ? true : false },\n FieldOutput<AllowedValuesOutput<V>, Opt>\n> {\n return createTailorField<\"enum\", Opt, AllowedValuesOutput<V>>(\"enum\", options, undefined, values);\n}\n\n/**\n * Create a nested object field for resolver input/output.\n * @param fields - Record of field definitions\n * @param options - Field options (optional, array)\n * @returns A nested object field\n * @example\n * // Single object:\n * output: t.object({ name: t.string(), email: t.string() })\n * @example\n * // Array of objects:\n * items: t.object({ name: t.string() }, { array: true })\n */\nfunction object<const F extends Record<string, TailorAnyField>, const Opt extends FieldOptions>(\n fields: F,\n options?: Opt,\n) {\n const objectField = createTailorField(\"nested\", options, fields) as TailorField<\n { type: \"nested\"; array: Opt extends { array: true } ? true : false },\n FieldOutput<InferFieldsOutput<F>, Opt>\n >;\n return objectField;\n}\n\nexport const t = {\n uuid,\n string,\n bool,\n int,\n float,\n decimal,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
|
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 { TailorInvoker } from \"#/runtime/types\";\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 triggerJobFunction: (jobName: string, args: unknown) => 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 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.triggerJobFunction` 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 triggered job calls and returns results.\n * @returns Object containing an array of triggered jobs for assertions.\n */\nexport function setupWorkflowMock(handler: JobHandler): {\n triggeredJobs: { jobName: string; args: unknown }[];\n} {\n const triggeredJobs: { jobName: string; args: unknown }[] = [];\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 triggerJobFunction: (jobName: string, args: unknown) => {\n triggeredJobs.push({ jobName, args });\n return handler(jobName, args);\n },\n },\n } as typeof GlobalThis.tailor;\n\n return { triggeredJobs };\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 `TailorInvoker` value to return, or `null` for anonymous.\n */\nexport function setupInvokerMock(invoker: TailorInvoker): 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 * `triggerJobFunction` is stubbed to throw a helpful error directing to `setupWorkflowMock()`,\n * so mistakenly triggering 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 GlobalThis.tailor = {\n ...GlobalThis.tailor,\n workflow: {\n triggerJobFunction: () => {\n throw new Error(\n \"tailor.workflow.triggerJobFunction is not mocked. Use setupWorkflowMock() in tests.\",\n );\n },\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, TailorUser } 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 { WORKFLOW_TEST_ENV_KEY } from \"#/configure/services/workflow/job\";\nexport {\n setupTailordbMock,\n setupTailorErrorsMock,\n setupWorkflowMock,\n setupInvokerMock,\n setupWaitPointMock,\n createImportMain,\n} from \"./mock\";\n\n/** Represents an unauthenticated user in the Tailor platform. */\nexport const unauthenticatedTailorUser = {\n id: \"00000000-0000-0000-0000-000000000000\",\n type: \"\",\n workspaceId: \"00000000-0000-0000-0000-000000000000\",\n attributes: null,\n attributeList: [],\n} as const satisfies TailorUser;\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) => {\n return 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 // Use existing id from data if provided, otherwise generate new UUID\n const existingId =\n data && typeof data === \"object\" ? (data as Record<string, unknown>)[key] : undefined;\n hooked[key] = existingId ?? crypto.randomUUID();\n } else if (field.type === \"nested\") {\n const nestedValue =\n data && typeof data === \"object\" ? (data as Record<string, unknown>)[key] : undefined;\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 // For nested array fields, recurse per element and pass through non-array values\n // (e.g. null/undefined for optional fields) so validation sees the original value.\n hooked[key] = Array.isArray(nestedValue)\n ? nestedValue.map((item) => nestedHook(item))\n : nestedValue;\n } else {\n hooked[key] = nestedHook(nestedValue);\n }\n } else if (field.metadata.hooks?.create) {\n hooked[key] = field.metadata.hooks.create({\n value: (data as Record<string, unknown>)[key],\n data: data,\n user: unauthenticatedTailorUser,\n });\n if (hooked[key] instanceof Date) {\n hooked[key] = hooked[key].toISOString();\n }\n } else if (data && typeof data === \"object\") {\n hooked[key] = (data as Record<string, unknown>)[key];\n }\n return hooked;\n },\n {} as Record<string, unknown>,\n ) 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 user: unauthenticatedTailorUser,\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":";;;;;AAmDA,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,gBAAsD,CAAC;CAE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QAAQ,OAAO,SAAS,UACjC,OAAO,OAAQ,KAAiC;GAElD,OAAO;EACT,GACA,CAAC,CACH;CACF;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,MAAM;GACR,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/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 { TailorInvoker } from \"#/runtime/types\";\nimport type { TriggerJobFunctionOptions } 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 triggerJobFunction: (\n jobName: string,\n args: unknown,\n options?: TriggerJobFunctionOptions,\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 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.triggerJobFunction` 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 triggered job calls and returns results.\n * @returns Object containing an array of triggered jobs for assertions.\n */\nexport function setupWorkflowMock(handler: JobHandler): {\n triggeredJobs: { jobName: string; args: unknown }[];\n} {\n const triggeredJobs: { jobName: string; args: unknown }[] = [];\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 triggerJobFunction: (jobName: string, args: unknown) => {\n triggeredJobs.push({ jobName, args });\n return handler(jobName, args);\n },\n },\n } as typeof GlobalThis.tailor;\n\n return { triggeredJobs };\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 `TailorInvoker` value to return, or `null` for anonymous.\n */\nexport function setupInvokerMock(invoker: TailorInvoker): 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 * `triggerJobFunction` is stubbed to throw a helpful error directing to `setupWorkflowMock()`,\n * so mistakenly triggering 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 GlobalThis.tailor = {\n ...GlobalThis.tailor,\n workflow: {\n triggerJobFunction: () => {\n throw new Error(\n \"tailor.workflow.triggerJobFunction is not mocked. Use setupWorkflowMock() in tests.\",\n );\n },\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, TailorUser } 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 { WORKFLOW_TEST_ENV_KEY } from \"#/configure/services/workflow/job\";\nexport {\n setupTailordbMock,\n setupTailorErrorsMock,\n setupWorkflowMock,\n setupInvokerMock,\n setupWaitPointMock,\n createImportMain,\n} from \"./mock\";\n\n/** Represents an unauthenticated user in the Tailor platform. */\nexport const unauthenticatedTailorUser = {\n id: \"00000000-0000-0000-0000-000000000000\",\n type: \"\",\n workspaceId: \"00000000-0000-0000-0000-000000000000\",\n attributes: null,\n attributeList: [],\n} as const satisfies TailorUser;\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) => {\n return 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 // Use existing id from data if provided, otherwise generate new UUID\n const existingId =\n data && typeof data === \"object\" ? (data as Record<string, unknown>)[key] : undefined;\n hooked[key] = existingId ?? crypto.randomUUID();\n } else if (field.type === \"nested\") {\n const nestedValue =\n data && typeof data === \"object\" ? (data as Record<string, unknown>)[key] : undefined;\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 // For nested array fields, recurse per element and pass through non-array values\n // (e.g. null/undefined for optional fields) so validation sees the original value.\n hooked[key] = Array.isArray(nestedValue)\n ? nestedValue.map((item) => nestedHook(item))\n : nestedValue;\n } else {\n hooked[key] = nestedHook(nestedValue);\n }\n } else if (field.metadata.hooks?.create) {\n hooked[key] = field.metadata.hooks.create({\n value: (data as Record<string, unknown>)[key],\n data: data,\n user: unauthenticatedTailorUser,\n });\n if (hooked[key] instanceof Date) {\n hooked[key] = hooked[key].toISOString();\n }\n } else if (data && typeof data === \"object\") {\n hooked[key] = (data as Record<string, unknown>)[key];\n }\n return hooked;\n },\n {} as Record<string, unknown>,\n ) 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 user: unauthenticatedTailorUser,\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":";;;;;AAwDA,MAAM,aAAa;;;;;;;AAQnB,SAAgB,kBAAkB,iBAAgC,CAAC,GAGjE;CACA,MAAM,kBAA0D,CAAC;CACjE,MAAM,iBAA2D,CAAC;CAElE,MAAM,mBAAmB;EACvB,AAAQ;EAER,YAAY,EAAE,a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AO,SAAS,WAAY,KAAiC,OAAO;IAE9E,MAAM,aAAa,mBAAmB,EAAE,QAAQ,MAAM,OAAO,CAAQ;IACrE,IAAI,MAAM,SAAS,OAGjB,OAAO,OAAO,MAAM,QAAQ,WAAW,IACnC,YAAY,KAAK,SAAS,WAAW,IAAI,CAAC,IAC1C;SAEJ,OAAO,OAAO,WAAW,WAAW;GAExC,OAAO,IAAI,MAAM,SAAS,OAAO,QAAQ;IACvC,OAAO,OAAO,MAAM,SAAS,MAAM,OAAO;KACxC,OAAQ,KAAiC;KACnC;KACN,MAAM;IACR,CAAC;IACD,IAAI,OAAO,gBAAgB,MACzB,OAAO,OAAO,OAAO,IAAI,CAAC,YAAY;GAE1C,OAAO,IAAI,QAAQ,OAAO,SAAS,UACjC,OAAO,OAAQ,KAAiC;GAElD,OAAO;EACT,GACA,CAAC,CACH;CACF;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,MAAM;GACR,CAAC;GACD,IAAI,OAAO,QACT,OAAO;GAET,OAAO,EAAE,OAAO,OAAY;EAC9B;CACF,EACF;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as cleanupPlatformGlobals, 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-CcU1ONiK.mjs";
|
|
2
2
|
import * as globals from "globals";
|
|
3
3
|
|
|
4
4
|
//#region src/vitest/environment.ts
|
package/dist/vitest/index.d.mts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import { mockAigateway
|
|
1
|
+
import { mockAigateway } from "./mocks/aigateway.mjs";
|
|
2
|
+
import { mockAuthconnection } from "./mocks/authconnection.mjs";
|
|
3
|
+
import { mockFile } from "./mocks/file.mjs";
|
|
4
|
+
import { mockIconv } from "./mocks/iconv.mjs";
|
|
5
|
+
import { mockIdp } from "./mocks/idp.mjs";
|
|
6
|
+
import { mockSecretmanager } from "./mocks/secretmanager.mjs";
|
|
7
|
+
import { mockTailordb } from "./mocks/tailordb.mjs";
|
|
8
|
+
import { mockWorkflow } from "./mocks/workflow.mjs";
|
|
2
9
|
import { ExecutedQuery, KyselyMock, createKyselyMock } from "./mock-kysely.mjs";
|
|
3
10
|
import { Plugin } from "vitest/config";
|
|
4
11
|
|