@tailor-platform/sdk 1.36.0 → 1.38.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 +82 -0
- package/dist/application-C1ipG5Q6.mjs +4 -0
- package/dist/{application-BwboBFcU.mjs → application-DhQrXEld.mjs} +60 -22
- package/dist/application-DhQrXEld.mjs.map +1 -0
- package/dist/{brand-0SscafcY.mjs → brand-D-d15jx3.mjs} +1 -1
- package/dist/{brand-0SscafcY.mjs.map → brand-D-d15jx3.mjs.map} +1 -1
- package/dist/cli/index.mjs +369 -128
- package/dist/cli/index.mjs.map +1 -1
- package/dist/cli/lib.d.mts +6 -6
- package/dist/cli/lib.mjs +7 -7
- package/dist/{client-B6icVEv4.mjs → client-BWAbbA1C.mjs} +1 -1
- package/dist/{client-CN15WgW2.mjs → client-xzPXtc_e.mjs} +10 -4
- package/dist/{client-CN15WgW2.mjs.map → client-xzPXtc_e.mjs.map} +1 -1
- package/dist/configure/index.d.mts +4 -5
- package/dist/configure/index.mjs +8 -15
- package/dist/configure/index.mjs.map +1 -1
- package/dist/{crash-report-CB1UtT3O.mjs → crash-report-BEAiCSCl.mjs} +1 -1
- package/dist/{crash-report-CdxPj_SW.mjs → crash-report-DXhPL8Ue.mjs} +4 -4
- package/dist/{crash-report-CdxPj_SW.mjs.map → crash-report-DXhPL8Ue.mjs.map} +1 -1
- package/dist/{enum-constants-DI85-fPE.mjs → enum-constants-Dx82rSjf.mjs} +1 -1
- package/dist/{enum-constants-DI85-fPE.mjs.map → enum-constants-Dx82rSjf.mjs.map} +1 -1
- package/dist/errors-D9f2UJpT.mjs +43 -0
- package/dist/errors-D9f2UJpT.mjs.map +1 -0
- package/dist/{file-utils-C4rXlOVt.mjs → file-utils-DeWpvq3T.mjs} +1 -1
- package/dist/{file-utils-C4rXlOVt.mjs.map → file-utils-DeWpvq3T.mjs.map} +1 -1
- package/dist/{index-DZN1QFLM.d.mts → index-CHo73Aat.d.mts} +2 -2
- package/dist/{index-CxSLivW7.d.mts → index-CIIXsk3E.d.mts} +2 -2
- package/dist/{index-C7vIBAg8.d.mts → index-Cln_TTZn.d.mts} +2 -2
- package/dist/{index-CYaunQeL.d.mts → index-Cs3fwmLu.d.mts} +33 -13
- package/dist/{index-DDCyefuU.d.mts → index-D_W9-Lvk.d.mts} +2 -2
- package/dist/{interceptor-f7slMkCC.mjs → interceptor-CzaH2Ur6.mjs} +1 -1
- package/dist/{interceptor-f7slMkCC.mjs.map → interceptor-CzaH2Ur6.mjs.map} +1 -1
- package/dist/{job-CPKYCk_e.mjs → job-DkAklmE4.mjs} +2 -2
- package/dist/{job-CPKYCk_e.mjs.map → job-DkAklmE4.mjs.map} +1 -1
- package/dist/{kysely-type-DtnNdHn3.mjs → kysely-type-CwtvQuxh.mjs} +1 -1
- package/dist/{kysely-type-DtnNdHn3.mjs.map → kysely-type-CwtvQuxh.mjs.map} +1 -1
- package/dist/{logger-qz-Y4sBV.mjs → logger-5_JMzHmw.mjs} +42 -3
- package/dist/logger-5_JMzHmw.mjs.map +1 -0
- package/dist/package-json--6dmp6-h.mjs +4 -0
- package/dist/{package-json-CfUqjJaQ.mjs → package-json-BHViVisJ.mjs} +1 -1
- package/dist/{package-json-CfUqjJaQ.mjs.map → package-json-BHViVisJ.mjs.map} +1 -1
- package/dist/plugin/builtin/enum-constants/index.d.mts +1 -1
- package/dist/plugin/builtin/enum-constants/index.mjs +1 -1
- package/dist/plugin/builtin/file-utils/index.d.mts +1 -1
- package/dist/plugin/builtin/file-utils/index.mjs +1 -1
- package/dist/plugin/builtin/kysely-type/index.d.mts +1 -1
- package/dist/plugin/builtin/kysely-type/index.mjs +1 -1
- package/dist/plugin/builtin/seed/index.d.mts +1 -1
- package/dist/plugin/builtin/seed/index.mjs +1 -1
- package/dist/plugin/index.d.mts +1 -2
- package/dist/{plugin-CiPUxkyN.d.mts → plugin-D84blivd.d.mts} +67 -11
- package/dist/{runtime-C7RRDaB3.mjs → runtime-ChpwtPut.mjs} +587 -144
- package/dist/runtime-ChpwtPut.mjs.map +1 -0
- package/dist/{schema-D27cW0Ca.mjs → schema-CnwUqPyM.mjs} +4 -361
- package/dist/schema-CnwUqPyM.mjs.map +1 -0
- package/dist/{seed-BZIFDG27.mjs → seed-DrbB1VXd.mjs} +1 -1
- package/dist/{seed-BZIFDG27.mjs.map → seed-DrbB1VXd.mjs.map} +1 -1
- package/dist/service-Bcp6JB3w.mjs +132 -0
- package/dist/service-Bcp6JB3w.mjs.map +1 -0
- package/dist/telemetry-4IOPW6wE.mjs +4 -0
- package/dist/{telemetry-CREcGK8y.mjs → telemetry-DwHuiNiR.mjs} +2 -2
- package/dist/{telemetry-CREcGK8y.mjs.map → telemetry-DwHuiNiR.mjs.map} +1 -1
- package/dist/types-B9ZMosul.mjs +372 -0
- package/dist/types-B9ZMosul.mjs.map +1 -0
- package/dist/types-C45jRrCM.mjs +4 -0
- package/dist/utils/test/index.d.mts +2 -2
- package/dist/utils/test/index.mjs +7 -3
- package/dist/utils/test/index.mjs.map +1 -1
- package/dist/{workflow.generated-8BeGQsVU.d.mts → workflow.generated-BRdcCWfC.d.mts} +2 -2
- package/docs/cli/function.md +42 -16
- package/docs/cli/upgrade.md +51 -0
- package/docs/cli/user.md +1 -1
- package/docs/cli/workflow.md +10 -10
- package/docs/cli-reference.md +23 -14
- package/docs/configuration.md +9 -7
- package/docs/services/auth.md +6 -5
- package/docs/services/executor.md +44 -12
- package/docs/services/resolver.md +6 -13
- package/docs/services/tailordb.md +20 -0
- package/docs/services/workflow.md +4 -3
- package/package.json +10 -10
- package/dist/application-BB5TqXWY.mjs +0 -4
- package/dist/application-BwboBFcU.mjs.map +0 -1
- package/dist/env-_ce3IYbl.d.mts +0 -30
- package/dist/logger-qz-Y4sBV.mjs.map +0 -1
- package/dist/package-json-D5Km1jjt.mjs +0 -4
- package/dist/runtime-C7RRDaB3.mjs.map +0 -1
- package/dist/schema-D27cW0Ca.mjs.map +0 -1
- package/dist/telemetry-C508zIi1.mjs +0 -4
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/configure/types/field.ts
|
|
3
|
+
/**
|
|
4
|
+
* Normalize allowed values into EnumValue objects with descriptions.
|
|
5
|
+
* @param values - Allowed values as strings or EnumValue objects
|
|
6
|
+
* @returns Normalized allowed values
|
|
7
|
+
*/
|
|
8
|
+
function mapAllowedValues(values) {
|
|
9
|
+
return values.map((value) => {
|
|
10
|
+
if (typeof value === "string") return {
|
|
11
|
+
value,
|
|
12
|
+
description: ""
|
|
13
|
+
};
|
|
14
|
+
return {
|
|
15
|
+
...value,
|
|
16
|
+
description: value.description ?? ""
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/configure/types/type.ts
|
|
23
|
+
const regex = {
|
|
24
|
+
uuid: /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
|
|
25
|
+
date: /^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})$/,
|
|
26
|
+
time: /^(?<hour>\d{2}):(?<minute>\d{2})$/,
|
|
27
|
+
datetime: /^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})T(?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2})(.(?<millisec>\d{3}))?Z$/,
|
|
28
|
+
decimal: /^-?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new TailorField instance.
|
|
32
|
+
* @param type - Field type
|
|
33
|
+
* @param options - Field options
|
|
34
|
+
* @param fields - Nested fields for object-like types
|
|
35
|
+
* @param values - Allowed values for enum-like fields
|
|
36
|
+
* @returns A new TailorField
|
|
37
|
+
*/
|
|
38
|
+
function createTailorField(type, options, fields, values) {
|
|
39
|
+
const _metadata = { required: true };
|
|
40
|
+
if (options) {
|
|
41
|
+
if (options.optional === true) _metadata.required = false;
|
|
42
|
+
if (options.array === true) _metadata.array = true;
|
|
43
|
+
}
|
|
44
|
+
if (values) _metadata.allowedValues = mapAllowedValues(values);
|
|
45
|
+
/**
|
|
46
|
+
* Validate a single value (not an array element)
|
|
47
|
+
* Used internally for array element validation
|
|
48
|
+
* @param args - Value, context data, and user
|
|
49
|
+
* @returns Array of validation issues
|
|
50
|
+
*/
|
|
51
|
+
function validateValue(args) {
|
|
52
|
+
const { value, data, user, pathArray } = args;
|
|
53
|
+
const issues = [];
|
|
54
|
+
switch (type) {
|
|
55
|
+
case "string":
|
|
56
|
+
if (typeof value !== "string") issues.push({
|
|
57
|
+
message: `Expected a string: received ${String(value)}`,
|
|
58
|
+
path: pathArray.length > 0 ? pathArray : void 0
|
|
59
|
+
});
|
|
60
|
+
break;
|
|
61
|
+
case "integer":
|
|
62
|
+
if (typeof value !== "number" || !Number.isInteger(value)) issues.push({
|
|
63
|
+
message: `Expected an integer: received ${String(value)}`,
|
|
64
|
+
path: pathArray.length > 0 ? pathArray : void 0
|
|
65
|
+
});
|
|
66
|
+
break;
|
|
67
|
+
case "float":
|
|
68
|
+
if (typeof value !== "number" || !Number.isFinite(value)) issues.push({
|
|
69
|
+
message: `Expected a number: received ${String(value)}`,
|
|
70
|
+
path: pathArray.length > 0 ? pathArray : void 0
|
|
71
|
+
});
|
|
72
|
+
break;
|
|
73
|
+
case "boolean":
|
|
74
|
+
if (typeof value !== "boolean") issues.push({
|
|
75
|
+
message: `Expected a boolean: received ${String(value)}`,
|
|
76
|
+
path: pathArray.length > 0 ? pathArray : void 0
|
|
77
|
+
});
|
|
78
|
+
break;
|
|
79
|
+
case "uuid":
|
|
80
|
+
if (typeof value !== "string" || !regex.uuid.test(value)) issues.push({
|
|
81
|
+
message: `Expected a valid UUID: received ${String(value)}`,
|
|
82
|
+
path: pathArray.length > 0 ? pathArray : void 0
|
|
83
|
+
});
|
|
84
|
+
break;
|
|
85
|
+
case "date":
|
|
86
|
+
if (typeof value !== "string" || !regex.date.test(value)) issues.push({
|
|
87
|
+
message: `Expected to match "yyyy-MM-dd" format: received ${String(value)}`,
|
|
88
|
+
path: pathArray.length > 0 ? pathArray : void 0
|
|
89
|
+
});
|
|
90
|
+
break;
|
|
91
|
+
case "datetime":
|
|
92
|
+
if (typeof value !== "string" || !regex.datetime.test(value)) issues.push({
|
|
93
|
+
message: `Expected to match ISO format: received ${String(value)}`,
|
|
94
|
+
path: pathArray.length > 0 ? pathArray : void 0
|
|
95
|
+
});
|
|
96
|
+
break;
|
|
97
|
+
case "time":
|
|
98
|
+
if (typeof value !== "string" || !regex.time.test(value)) issues.push({
|
|
99
|
+
message: `Expected to match "HH:mm" format: received ${String(value)}`,
|
|
100
|
+
path: pathArray.length > 0 ? pathArray : void 0
|
|
101
|
+
});
|
|
102
|
+
break;
|
|
103
|
+
case "decimal":
|
|
104
|
+
if (typeof value !== "string" || !regex.decimal.test(value)) issues.push({
|
|
105
|
+
message: `Expected a decimal string: received ${String(value)}`,
|
|
106
|
+
path: pathArray.length > 0 ? pathArray : void 0
|
|
107
|
+
});
|
|
108
|
+
break;
|
|
109
|
+
case "enum":
|
|
110
|
+
if (field._metadata.allowedValues) {
|
|
111
|
+
const allowedValues = field._metadata.allowedValues.map((v) => v.value);
|
|
112
|
+
if (typeof value !== "string" || !allowedValues.includes(value)) issues.push({
|
|
113
|
+
message: `Must be one of [${allowedValues.join(", ")}]: received ${String(value)}`,
|
|
114
|
+
path: pathArray.length > 0 ? pathArray : void 0
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
break;
|
|
118
|
+
case "nested":
|
|
119
|
+
if (typeof value !== "object" || value === null || Array.isArray(value) || value instanceof Date) issues.push({
|
|
120
|
+
message: `Expected an object: received ${String(value)}`,
|
|
121
|
+
path: pathArray.length > 0 ? pathArray : void 0
|
|
122
|
+
});
|
|
123
|
+
else if (field.fields && Object.keys(field.fields).length > 0) for (const [fieldName, nestedField] of Object.entries(field.fields)) {
|
|
124
|
+
const fieldValue = value?.[fieldName];
|
|
125
|
+
const result = nestedField._parseInternal({
|
|
126
|
+
value: fieldValue,
|
|
127
|
+
data,
|
|
128
|
+
user,
|
|
129
|
+
pathArray: pathArray.concat(fieldName)
|
|
130
|
+
});
|
|
131
|
+
if (result.issues) issues.push(...result.issues);
|
|
132
|
+
}
|
|
133
|
+
break;
|
|
134
|
+
}
|
|
135
|
+
const validateFns = field._metadata.validate;
|
|
136
|
+
if (validateFns && validateFns.length > 0) for (const validateInput of validateFns) {
|
|
137
|
+
const { fn, message } = typeof validateInput === "function" ? {
|
|
138
|
+
fn: validateInput,
|
|
139
|
+
message: "Validation failed"
|
|
140
|
+
} : {
|
|
141
|
+
fn: validateInput[0],
|
|
142
|
+
message: validateInput[1]
|
|
143
|
+
};
|
|
144
|
+
if (!fn({
|
|
145
|
+
value,
|
|
146
|
+
data,
|
|
147
|
+
user
|
|
148
|
+
})) issues.push({
|
|
149
|
+
message,
|
|
150
|
+
path: pathArray.length > 0 ? pathArray : void 0
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return issues;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Internal parse method that tracks field path for nested validation
|
|
157
|
+
* @param args - Parse arguments
|
|
158
|
+
* @returns Parse result with value or issues
|
|
159
|
+
*/
|
|
160
|
+
function parseInternal(args) {
|
|
161
|
+
const { value, data, user, pathArray } = args;
|
|
162
|
+
const issues = [];
|
|
163
|
+
const isNullOrUndefined = value === null || value === void 0;
|
|
164
|
+
if (field._metadata.required && isNullOrUndefined) {
|
|
165
|
+
issues.push({
|
|
166
|
+
message: "Required field is missing",
|
|
167
|
+
path: pathArray.length > 0 ? pathArray : void 0
|
|
168
|
+
});
|
|
169
|
+
return { issues };
|
|
170
|
+
}
|
|
171
|
+
if (!field._metadata.required && isNullOrUndefined) return { value: value ?? null };
|
|
172
|
+
if (field._metadata.array) {
|
|
173
|
+
if (!Array.isArray(value)) {
|
|
174
|
+
issues.push({
|
|
175
|
+
message: "Expected an array",
|
|
176
|
+
path: pathArray.length > 0 ? pathArray : void 0
|
|
177
|
+
});
|
|
178
|
+
return { issues };
|
|
179
|
+
}
|
|
180
|
+
for (let i = 0; i < value.length; i++) {
|
|
181
|
+
const elementValue = value[i];
|
|
182
|
+
const elementIssues = validateValue({
|
|
183
|
+
value: elementValue,
|
|
184
|
+
data,
|
|
185
|
+
user,
|
|
186
|
+
pathArray: pathArray.concat(`[${i}]`)
|
|
187
|
+
});
|
|
188
|
+
if (elementIssues.length > 0) issues.push(...elementIssues);
|
|
189
|
+
}
|
|
190
|
+
if (issues.length > 0) return { issues };
|
|
191
|
+
return { value };
|
|
192
|
+
}
|
|
193
|
+
const valueIssues = validateValue({
|
|
194
|
+
value,
|
|
195
|
+
data,
|
|
196
|
+
user,
|
|
197
|
+
pathArray
|
|
198
|
+
});
|
|
199
|
+
issues.push(...valueIssues);
|
|
200
|
+
if (issues.length > 0) return { issues };
|
|
201
|
+
return { value };
|
|
202
|
+
}
|
|
203
|
+
const field = {
|
|
204
|
+
type,
|
|
205
|
+
fields: fields ?? {},
|
|
206
|
+
_defined: void 0,
|
|
207
|
+
_output: void 0,
|
|
208
|
+
_metadata,
|
|
209
|
+
get metadata() {
|
|
210
|
+
return { ...this._metadata };
|
|
211
|
+
},
|
|
212
|
+
description(description) {
|
|
213
|
+
this._metadata.description = description;
|
|
214
|
+
return this;
|
|
215
|
+
},
|
|
216
|
+
typeName(typeName) {
|
|
217
|
+
this._metadata.typeName = typeName;
|
|
218
|
+
return this;
|
|
219
|
+
},
|
|
220
|
+
validate(...validateInputs) {
|
|
221
|
+
this._metadata.validate = validateInputs;
|
|
222
|
+
return this;
|
|
223
|
+
},
|
|
224
|
+
parse(args) {
|
|
225
|
+
return parseInternal({
|
|
226
|
+
value: args.value,
|
|
227
|
+
data: args.data,
|
|
228
|
+
user: args.user,
|
|
229
|
+
pathArray: []
|
|
230
|
+
});
|
|
231
|
+
},
|
|
232
|
+
_parseInternal: parseInternal
|
|
233
|
+
};
|
|
234
|
+
return field;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Create a UUID field for resolver input/output.
|
|
238
|
+
* @param options - Field configuration options
|
|
239
|
+
* @returns A UUID field
|
|
240
|
+
* @example t.uuid()
|
|
241
|
+
*/
|
|
242
|
+
function uuid(options) {
|
|
243
|
+
return createTailorField("uuid", options);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Create a string field for resolver input/output.
|
|
247
|
+
* @param options - Field configuration options
|
|
248
|
+
* @returns A string field
|
|
249
|
+
* @example t.string()
|
|
250
|
+
* @example t.string({ optional: true })
|
|
251
|
+
* @example t.string({ array: true })
|
|
252
|
+
*/
|
|
253
|
+
function string(options) {
|
|
254
|
+
return createTailorField("string", options);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Create a boolean field for resolver input/output.
|
|
258
|
+
* @param options - Field configuration options
|
|
259
|
+
* @returns A boolean field
|
|
260
|
+
* @example t.bool()
|
|
261
|
+
*/
|
|
262
|
+
function bool(options) {
|
|
263
|
+
return createTailorField("boolean", options);
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Create an integer field for resolver input/output.
|
|
267
|
+
* @param options - Field configuration options
|
|
268
|
+
* @returns An integer field
|
|
269
|
+
* @example t.int()
|
|
270
|
+
*/
|
|
271
|
+
function int(options) {
|
|
272
|
+
return createTailorField("integer", options);
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Create a float field for resolver input/output.
|
|
276
|
+
* @param options - Field configuration options
|
|
277
|
+
* @returns A float field
|
|
278
|
+
* @example t.float()
|
|
279
|
+
*/
|
|
280
|
+
function float(options) {
|
|
281
|
+
return createTailorField("float", options);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Create a decimal field for resolver input/output (stored as string for precision).
|
|
285
|
+
* @param options - Field configuration options
|
|
286
|
+
* @returns A decimal field
|
|
287
|
+
* @example t.decimal()
|
|
288
|
+
* @example t.decimal({ optional: true })
|
|
289
|
+
*/
|
|
290
|
+
function decimal(options) {
|
|
291
|
+
return createTailorField("decimal", options);
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Create a date field for resolver input/output.
|
|
295
|
+
* @param options - Field configuration options
|
|
296
|
+
* @returns A date field
|
|
297
|
+
* @example t.date()
|
|
298
|
+
*/
|
|
299
|
+
function date(options) {
|
|
300
|
+
return createTailorField("date", options);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Create a datetime field for resolver input/output.
|
|
304
|
+
* @param options - Field configuration options
|
|
305
|
+
* @returns A datetime field
|
|
306
|
+
* @example t.datetime()
|
|
307
|
+
*/
|
|
308
|
+
function datetime(options) {
|
|
309
|
+
return createTailorField("datetime", options);
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Create a time field for resolver input/output.
|
|
313
|
+
* @param options - Field configuration options
|
|
314
|
+
* @returns A time field
|
|
315
|
+
* @example t.time()
|
|
316
|
+
*/
|
|
317
|
+
function time(options) {
|
|
318
|
+
return createTailorField("time", options);
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Create an enum field for resolver input/output.
|
|
322
|
+
* @param values - Array of allowed string values
|
|
323
|
+
* @param options - Field configuration options
|
|
324
|
+
* @returns An enum field
|
|
325
|
+
* @example t.enum(["active", "inactive"])
|
|
326
|
+
*/
|
|
327
|
+
function _enum(values, options) {
|
|
328
|
+
return createTailorField("enum", options, void 0, values);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Create a nested object field for resolver input/output.
|
|
332
|
+
* @param fields - Record of field definitions
|
|
333
|
+
* @param options - Field options (optional, array)
|
|
334
|
+
* @returns A nested object field
|
|
335
|
+
* @example
|
|
336
|
+
* // Single object:
|
|
337
|
+
* output: t.object({ name: t.string(), email: t.string() })
|
|
338
|
+
* @example
|
|
339
|
+
* // Array of objects:
|
|
340
|
+
* items: t.object({ name: t.string() }, { array: true })
|
|
341
|
+
*/
|
|
342
|
+
function object(fields, options) {
|
|
343
|
+
return createTailorField("nested", options, fields);
|
|
344
|
+
}
|
|
345
|
+
const t = {
|
|
346
|
+
uuid,
|
|
347
|
+
string,
|
|
348
|
+
bool,
|
|
349
|
+
int,
|
|
350
|
+
float,
|
|
351
|
+
decimal,
|
|
352
|
+
date,
|
|
353
|
+
datetime,
|
|
354
|
+
time,
|
|
355
|
+
enum: _enum,
|
|
356
|
+
object
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
//#endregion
|
|
360
|
+
//#region src/configure/types/user.ts
|
|
361
|
+
/** Represents an unauthenticated user in the Tailor platform. */
|
|
362
|
+
const unauthenticatedTailorUser = {
|
|
363
|
+
id: "00000000-0000-0000-0000-000000000000",
|
|
364
|
+
type: "",
|
|
365
|
+
workspaceId: "00000000-0000-0000-0000-000000000000",
|
|
366
|
+
attributes: null,
|
|
367
|
+
attributeList: []
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
//#endregion
|
|
371
|
+
export { t as n, mapAllowedValues as r, unauthenticatedTailorUser as t };
|
|
372
|
+
//# sourceMappingURL=types-B9ZMosul.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-B9ZMosul.mjs","names":[],"sources":["../src/configure/types/field.ts","../src/configure/types/type.ts","../src/configure/types/user.ts"],"sourcesContent":["import type { EnumValue } from \"@/types/tailordb\";\n\nexport type AllowedValue = EnumValue;\n\nexport type AllowedValues = readonly [string | EnumValue, ...(string | EnumValue)[]];\n\n/**\n * Normalize allowed values into EnumValue objects with descriptions.\n * @param values - Allowed values as strings or EnumValue objects\n * @returns Normalized allowed values\n */\nexport function mapAllowedValues(values: AllowedValues): AllowedValue[] {\n return values.map((value) => {\n if (typeof value === \"string\") {\n return { value, description: \"\" };\n }\n return { ...value, description: value.description ?? \"\" };\n });\n}\n\nexport type AllowedValuesOutput<V extends AllowedValues> = V[number] extends infer T\n ? T extends string\n ? T\n : T extends { value: infer K }\n ? K\n : never\n : never;\n","import { type AllowedValues, type AllowedValuesOutput, mapAllowedValues } from \"./field\";\nimport {\n type TailorFieldType,\n type TailorToTs,\n type FieldMetadata,\n type DefinedFieldMetadata,\n type FieldOptions,\n type FieldOutput,\n} from \"./types\";\nimport type { Prettify, InferFieldsOutput } from \"./helpers\";\nimport type { FieldValidateInput } from \"./validation\";\nimport type { TailorUser } from \"@/configure/types\";\nimport type { TailorFieldInput } from \"@/types/field.generated\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\n\nconst regex = {\n uuid: /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,\n date: /^(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})$/,\n time: /^(?<hour>\\d{2}):(?<minute>\\d{2})$/,\n datetime:\n /^(?<year>\\d{4})-(?<month>\\d{2})-(?<day>\\d{2})T(?<hour>\\d{2}):(?<minute>\\d{2}):(?<second>\\d{2})(.(?<millisec>\\d{3}))?Z$/,\n decimal: /^-?(\\d+\\.?\\d*|\\.\\d+)([eE][+-]?\\d+)?$/,\n} as const;\n\n// This helper type intentionally uses `any` as a placeholder for unknown field output.\n// oxlint-disable-next-line no-explicit-any\nexport type TailorAnyField = TailorField<any>;\n\ntype FieldParseArgs = {\n value: unknown;\n data: unknown;\n user: TailorUser;\n};\n\ntype FieldValidateValueArgs<T extends TailorFieldType> = {\n value: TailorToTs[T];\n data: unknown;\n user: TailorUser;\n pathArray: string[];\n};\n\ntype FieldParseInternalArgs = {\n // Runtime input is unknown/untyped; we validate and narrow it inside the parser.\n // oxlint-disable-next-line no-explicit-any\n value: any;\n data: unknown;\n user: TailorUser;\n pathArray: string[];\n};\n\n/**\n * TailorField interface representing a field with metadata, type information, and optional nested fields.\n * This is the base field type used by both resolver types and TailorDB types.\n * Using interface to allow self-referencing in the fields property.\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 TailorFieldInput {\n readonly type: T;\n readonly fields: Record<string, TailorAnyField>;\n readonly _defined: Defined;\n readonly _output: Output;\n _metadata: M;\n\n /** Returns a shallow copy of the metadata */\n readonly 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<CurrentDefined extends Defined>(\n this: CurrentDefined extends { description: unknown }\n ? never\n : TailorField<CurrentDefined, Output>,\n description: string,\n ): TailorField<Prettify<CurrentDefined & { description: true }>, 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<CurrentDefined extends Defined>(\n this: CurrentDefined extends { typeName: unknown }\n ? never\n : CurrentDefined extends { type: \"enum\" | \"nested\" }\n ? TailorField<CurrentDefined, Output>\n : never,\n typeName: string,\n ): TailorField<Prettify<CurrentDefined & { typeName: true }>, 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<CurrentDefined extends Defined>(\n this: CurrentDefined extends { validate: unknown }\n ? never\n : TailorField<CurrentDefined, Output>,\n ...validate: FieldValidateInput<Output>[]\n ): TailorField<Prettify<CurrentDefined & { validate: true }>, 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 * 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 * @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): TailorField<\n { type: T; array: TOptions extends { array: true } ? true : false },\n FieldOutput<OutputBase, TOptions>\n> {\n const _metadata: FieldMetadata = { required: true };\n\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 * Validate a single value (not an array element)\n * Used internally for array element validation\n * @param args - Value, context data, and user\n * @returns Array of validation issues\n */\n function validateValue(args: FieldValidateValueArgs<T>): StandardSchemaV1.Issue[] {\n const { value, data, user, pathArray } = args;\n const issues: StandardSchemaV1.Issue[] = [];\n\n // Type-specific validation\n switch (type) {\n case \"string\":\n if (typeof value !== \"string\") {\n issues.push({\n message: `Expected a string: received ${String(value)}`,\n path: pathArray.length > 0 ? pathArray : undefined,\n });\n }\n break;\n\n case \"integer\":\n if (typeof value !== \"number\" || !Number.isInteger(value)) {\n issues.push({\n message: `Expected an integer: received ${String(value)}`,\n path: pathArray.length > 0 ? pathArray : undefined,\n });\n }\n break;\n\n case \"float\":\n if (typeof value !== \"number\" || !Number.isFinite(value)) {\n issues.push({\n message: `Expected a number: received ${String(value)}`,\n path: pathArray.length > 0 ? pathArray : undefined,\n });\n }\n break;\n\n case \"boolean\":\n if (typeof value !== \"boolean\") {\n issues.push({\n message: `Expected a boolean: received ${String(value)}`,\n path: pathArray.length > 0 ? pathArray : undefined,\n });\n }\n break;\n\n case \"uuid\":\n if (typeof value !== \"string\" || !regex.uuid.test(value)) {\n issues.push({\n message: `Expected a valid UUID: received ${String(value)}`,\n path: pathArray.length > 0 ? pathArray : undefined,\n });\n }\n break;\n case \"date\":\n if (typeof value !== \"string\" || !regex.date.test(value)) {\n issues.push({\n message: `Expected to match \"yyyy-MM-dd\" format: received ${String(value)}`,\n path: pathArray.length > 0 ? pathArray : undefined,\n });\n }\n break;\n case \"datetime\":\n if (typeof value !== \"string\" || !regex.datetime.test(value)) {\n issues.push({\n message: `Expected to match ISO format: received ${String(value)}`,\n path: pathArray.length > 0 ? pathArray : undefined,\n });\n }\n break;\n case \"time\":\n if (typeof value !== \"string\" || !regex.time.test(value)) {\n issues.push({\n message: `Expected to match \"HH:mm\" format: received ${String(value)}`,\n path: pathArray.length > 0 ? pathArray : undefined,\n });\n }\n break;\n case \"decimal\":\n if (typeof value !== \"string\" || !regex.decimal.test(value)) {\n issues.push({\n message: `Expected a decimal string: received ${String(value)}`,\n path: pathArray.length > 0 ? pathArray : undefined,\n });\n }\n break;\n\n case \"enum\":\n if (field._metadata.allowedValues) {\n const allowedValues = field._metadata.allowedValues.map((v) => v.value);\n if (typeof value !== \"string\" || !allowedValues.includes(value)) {\n issues.push({\n message: `Must be one of [${allowedValues.join(\", \")}]: received ${String(value)}`,\n path: pathArray.length > 0 ? pathArray : undefined,\n });\n }\n }\n break;\n\n case \"nested\":\n // Validate nested object fields\n if (\n typeof value !== \"object\" ||\n value === null ||\n Array.isArray(value) ||\n value instanceof Date\n ) {\n issues.push({\n message: `Expected an object: received ${String(value)}`,\n path: pathArray.length > 0 ? pathArray : undefined,\n });\n } else if (field.fields && Object.keys(field.fields).length > 0) {\n for (const [fieldName, nestedField] of Object.entries(field.fields)) {\n const fieldValue = value?.[fieldName];\n const result = nestedField._parseInternal({\n value: fieldValue,\n data,\n user,\n pathArray: pathArray.concat(fieldName),\n });\n if (result.issues) {\n issues.push(...result.issues);\n }\n }\n }\n break;\n }\n\n // Custom validation functions\n const validateFns = field._metadata.validate;\n if (validateFns && validateFns.length > 0) {\n for (const validateInput of validateFns) {\n const { fn, message } =\n typeof validateInput === \"function\"\n ? { fn: validateInput, message: \"Validation failed\" }\n : { fn: validateInput[0], message: validateInput[1] };\n\n if (!fn({ value, data, user })) {\n issues.push({\n message,\n path: pathArray.length > 0 ? pathArray : undefined,\n });\n }\n }\n }\n\n return issues;\n }\n\n /**\n * Internal parse method that tracks field path for nested validation\n * @param args - Parse arguments\n * @returns Parse result with value or issues\n */\n function parseInternal(\n args: FieldParseInternalArgs,\n ): StandardSchemaV1.Result<FieldOutput<OutputBase, TOptions>> {\n const { value, data, user, pathArray } = args;\n const issues: StandardSchemaV1.Issue[] = [];\n\n // 1. Check required/optional\n const isNullOrUndefined = value === null || value === undefined;\n if (field._metadata.required && isNullOrUndefined) {\n issues.push({\n message: \"Required field is missing\",\n path: pathArray.length > 0 ? pathArray : undefined,\n });\n return { issues };\n }\n\n // If optional and null/undefined, skip further validation and normalize to null\n if (!field._metadata.required && isNullOrUndefined) {\n return { value: value ?? null };\n }\n\n // 2. Check array type\n if (field._metadata.array) {\n if (!Array.isArray(value)) {\n issues.push({\n message: \"Expected an array\",\n path: pathArray.length > 0 ? pathArray : undefined,\n });\n return { issues };\n }\n\n // Validate each array element (without array flag)\n for (let i = 0; i < value.length; i++) {\n const elementValue = value[i];\n const elementPath = pathArray.concat(`[${i}]`);\n\n // Validate element with same type but without array flag\n const elementIssues = validateValue({\n value: elementValue,\n data,\n user,\n pathArray: elementPath,\n });\n if (elementIssues.length > 0) {\n issues.push(...elementIssues);\n }\n }\n\n if (issues.length > 0) {\n return { issues };\n }\n return { value: value as FieldOutput<OutputBase, TOptions> };\n }\n\n // 3. Type-specific validation and custom validation\n const valueIssues = validateValue({ value, data, user, pathArray });\n issues.push(...valueIssues);\n\n if (issues.length > 0) {\n return { issues };\n }\n\n return { value };\n }\n\n const field: TailorField<\n { type: T; array: TOptions extends { array: true } ? true : false },\n FieldOutput<OutputBase, TOptions>\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 this._metadata.description = description;\n // Fluent API returns this with updated type\n // oxlint-disable-next-line no-explicit-any\n return this as any;\n },\n\n typeName(typeName: string) {\n this._metadata.typeName = typeName;\n // Fluent API returns this with updated type\n // oxlint-disable-next-line no-explicit-any\n return this as any;\n },\n\n validate(...validateInputs: FieldValidateInput<FieldOutput<OutputBase, TOptions>>[]) {\n this._metadata.validate = validateInputs;\n // Fluent API returns this with updated type\n // oxlint-disable-next-line no-explicit-any\n return this as any;\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\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,\n date,\n datetime,\n time,\n enum: _enum,\n object,\n};\n","// Interfaces for module augmentation\n// Users can extend these via: declare module \"@tailor-platform/sdk\" { interface AttributeMap { ... } }\n// eslint-disable-next-line @typescript-eslint/no-empty-object-type\nexport interface AttributeMap {}\nexport interface AttributeList {\n __tuple?: []; // Marker for tuple type\n}\n\nexport type InferredAttributeMap = keyof AttributeMap extends never\n ? Record<string, string | string[] | boolean | boolean[] | undefined>\n : AttributeMap;\n\nexport type InferredAttributeList = AttributeList[\"__tuple\"] extends []\n ? string[]\n : AttributeList[\"__tuple\"];\n\n/** Represents a user in the Tailor platform. */\nexport type TailorUser = {\n /**\n * The ID of the user.\n * For unauthenticated users, this will be a nil UUID.\n */\n id: string;\n /**\n * The type of the user.\n * For unauthenticated users, this will be an empty string.\n */\n type: \"user\" | \"machine_user\" | \"\";\n /** The ID of the workspace the user belongs to. */\n workspaceId: string;\n /**\n * A map of the user's attributes.\n * For unauthenticated users, this will be null.\n */\n attributes: InferredAttributeMap | null;\n /**\n * A list of the user's attributes.\n * For unauthenticated users, this will be an empty array.\n */\n attributeList: InferredAttributeList;\n};\n\n/** Represents an unauthenticated user in the Tailor platform. */\nexport const unauthenticatedTailorUser: TailorUser = {\n id: \"00000000-0000-0000-0000-000000000000\",\n type: \"\",\n workspaceId: \"00000000-0000-0000-0000-000000000000\",\n attributes: null,\n attributeList: [],\n};\n"],"mappings":";;;;;;;AAWA,SAAgB,iBAAiB,QAAuC;AACtE,QAAO,OAAO,KAAK,UAAU;AAC3B,MAAI,OAAO,UAAU,SACnB,QAAO;GAAE;GAAO,aAAa;GAAI;AAEnC,SAAO;GAAE,GAAG;GAAO,aAAa,MAAM,eAAe;GAAI;GACzD;;;;;ACFJ,MAAM,QAAQ;CACZ,MAAM;CACN,MAAM;CACN,MAAM;CACN,UACE;CACF,SAAS;CACV;;;;;;;;;AAiHD,SAAS,kBAKP,MACA,SACA,QACA,QAIA;CACA,MAAM,YAA2B,EAAE,UAAU,MAAM;AAEnD,KAAI,SAAS;AACX,MAAI,QAAQ,aAAa,KACvB,WAAU,WAAW;AAEvB,MAAI,QAAQ,UAAU,KACpB,WAAU,QAAQ;;AAGt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Q;;;;;;;;;AAU3C,SAAS,MACP,QACA,SAIA;AACA,QAAO,kBAAuD,QAAQ,SAAS,QAAW,OAAO;;;;;;;;;;;;;;AAenG,SAAS,OACP,QACA,SACA;AAKA,QAJoB,kBAAkB,UAAU,SAAS,OAAO;;AAOlE,MAAa,IAAI;CACf;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,MAAM;CACN;CACD;;;;;AC1hBD,MAAa,4BAAwC;CACnD,IAAI;CACJ,MAAM;CACN,aAAa;CACb,YAAY;CACZ,eAAe,EAAE;CAClB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="@tailor-platform/function-types" />
|
|
2
|
-
import { U as TailorDBType, rt as TailorField } from "../../plugin-
|
|
3
|
-
import { n as output,
|
|
2
|
+
import { U as TailorDBType, rt as TailorField } from "../../plugin-D84blivd.mjs";
|
|
3
|
+
import { n as output, ot as WORKFLOW_TEST_ENV_KEY } from "../../index-Cs3fwmLu.mjs";
|
|
4
4
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
5
5
|
|
|
6
6
|
//#region src/utils/test/mock.d.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { t as WORKFLOW_TEST_ENV_KEY } from "../../job-
|
|
2
|
+
import { t as WORKFLOW_TEST_ENV_KEY } from "../../job-DkAklmE4.mjs";
|
|
3
3
|
import { pathToFileURL } from "node:url";
|
|
4
4
|
import * as path from "node:path";
|
|
5
5
|
|
|
@@ -113,8 +113,12 @@ function createTailorDBHook(type) {
|
|
|
113
113
|
return Object.entries(type.fields).reduce((hooked, [key, value]) => {
|
|
114
114
|
const field = value;
|
|
115
115
|
if (key === "id") hooked[key] = (data && typeof data === "object" ? data[key] : void 0) ?? crypto.randomUUID();
|
|
116
|
-
else if (field.type === "nested")
|
|
117
|
-
|
|
116
|
+
else if (field.type === "nested") {
|
|
117
|
+
const nestedValue = data && typeof data === "object" ? data[key] : void 0;
|
|
118
|
+
const nestedHook = createTailorDBHook({ fields: field.fields });
|
|
119
|
+
if (field.metadata.array) hooked[key] = Array.isArray(nestedValue) ? nestedValue.map((item) => nestedHook(item)) : nestedValue;
|
|
120
|
+
else hooked[key] = nestedHook(nestedValue);
|
|
121
|
+
} else if (field.metadata.hooks?.create) {
|
|
118
122
|
hooked[key] = field.metadata.hooks.create({
|
|
119
123
|
value: data[key],
|
|
120
124
|
data,
|
|
@@ -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\";\n\ntype MainFunction = (args: Record<string, unknown>) => unknown | Promise<unknown>;\ntype QueryResolver = (query: string, params: unknown[]) => unknown[];\ntype JobHandler = (jobName: string, args: unknown) => unknown;\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 };\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 * @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 * @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 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.TailorErrors` used in bundled resolver tests.\n * Mimics the PF runtime's TailorErrors class that serializes errors with the `TailorErrors: ` prefix.\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 * 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 */\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\";\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 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 // eslint-disable-next-line @typescript-eslint/no-explicit-any\n hooked[key] = createTailorDBHook({ fields: field.fields } as any)(\n (data as Record<string, unknown>)[key],\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":";;;;;;AAkCA,MAAM,aAAa;;;;;;AAOnB,SAAgB,kBAAkB,iBAAgC,EAAE,EAGlE;CACA,MAAM,kBAA0D,EAAE;CAClE,MAAM,iBAA2D,EAAE;CAEnE,MAAM,mBAAmB;EACvB,AAAQ;EAER,YAAY,EAAE,aAAqC;AACjD,QAAK,SAAS;IAAE;IAAW,OAAO;IAAO;AACzC,kBAAe,KAAK,KAAK,OAAO;;EAGlC,MAAM,UAAyB;EAI/B,MAAM,MAAqB;AACzB,QAAK,OAAO,QAAQ;;EAGtB,MAAM,YAAY,OAAe,SAAoB,EAAE,EAAgC;AACrF,mBAAgB,KAAK;IAAE;IAAO;IAAQ,CAAC;AACvC,UAAO,EAAE,MAAM,SAAS,OAAO,OAAO,IAAI,EAAE,EAAE;;;AAIlD,YAAW,WAAW,EACpB,QAA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Q,CAAQ,CAC9D,KAAiC,KACnC;YACQ,MAAM,SAAS,OAAO,QAAQ;AACvC,WAAO,OAAO,MAAM,SAAS,MAAM,OAAO;KACxC,OAAQ,KAAiC;KACnC;KACN,MAAM;KACP,CAAC;AACF,QAAI,OAAO,gBAAgB,KACzB,QAAO,OAAO,OAAO,KAAK,aAAa;cAEhC,QAAQ,OAAO,SAAS,SACjC,QAAO,OAAQ,KAAiC;AAElD,UAAO;KAET,EAAE,CACH;;;;;;;;;;;AAYL,SAAgB,qBAEd,YACA,MACA;AACA,QAAO,EACL,aAAa;EACX,SAAS;EACT,QAAQ;EACR,WAAW,UAAmB;GAC5B,MAAM,SAAS,KAAK,MAAM;GAC1B,MAAM,SAAS,WAAW,MAAM;IAC9B,OAAO;IACP,MAAM;IACN,MAAM;IACP,CAAC;AACF,OAAI,OAAO,OACT,QAAO;AAET,UAAO,EAAE,OAAO,QAAa;;EAEhC,EACF"}
|
|
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\";\n\ntype MainFunction = (args: Record<string, unknown>) => unknown | Promise<unknown>;\ntype QueryResolver = (query: string, params: unknown[]) => unknown[];\ntype JobHandler = (jobName: string, args: unknown) => unknown;\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 };\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 * @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 * @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 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.TailorErrors` used in bundled resolver tests.\n * Mimics the PF runtime's TailorErrors class that serializes errors with the `TailorErrors: ` prefix.\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 * 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 */\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\";\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 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":";;;;;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ET,UAAO,EAAE,OAAO,QAAa;;EAEhC,EACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="@tailor-platform/function-types" />
|
|
2
|
-
import {
|
|
2
|
+
import { Rt as BuiltinIdP, S as TailorDBServiceInput, T as AuthConfig } from "./plugin-D84blivd.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/types/idp.generated.d.ts
|
|
5
5
|
/**
|
|
@@ -411,4 +411,4 @@ type RetryPolicy = {
|
|
|
411
411
|
};
|
|
412
412
|
//#endregion
|
|
413
413
|
export { IdpDefinitionBrand as _, ResolverExternalConfig as a, IdPGqlOperationsInput as b, WorkflowServiceConfig as c, defineStaticWebSite as d, SecretsConfig as f, IdPUserField as g, IdPExternalConfig as h, ExecutorServiceInput as i, WorkflowServiceInput as l, IdPConfig as m, AppConfig as n, ResolverServiceConfig as o, defineSecretManager as p, ExecutorServiceConfig as r, ResolverServiceInput as s, RetryPolicy as t, StaticWebsiteConfig as u, IdPEmailConfig as v, IdPInput as x, IdPGqlOperations as y };
|
|
414
|
-
//# sourceMappingURL=workflow.generated-
|
|
414
|
+
//# sourceMappingURL=workflow.generated-BRdcCWfC.d.mts.map
|
package/docs/cli/function.md
CHANGED
|
@@ -89,20 +89,46 @@ See [Global Options](../cli-reference.md#global-options) for options available t
|
|
|
89
89
|
|
|
90
90
|
<!-- politty:command:function logs:global-options-link:end -->
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
<!-- politty:command:function logs:examples:start -->
|
|
93
|
+
|
|
94
|
+
**Examples**
|
|
95
|
+
|
|
96
|
+
**List all function execution logs**
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
$ tailor-sdk function logs
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**Get execution details with logs**
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
$ tailor-sdk function logs <execution-id>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
**Output as JSON**
|
|
93
109
|
|
|
94
110
|
```bash
|
|
95
|
-
|
|
96
|
-
|
|
111
|
+
$ tailor-sdk function logs --json
|
|
112
|
+
```
|
|
97
113
|
|
|
98
|
-
|
|
99
|
-
tailor-sdk function logs <execution-id>
|
|
114
|
+
**Get execution details as JSON**
|
|
100
115
|
|
|
101
|
-
|
|
102
|
-
tailor-sdk function logs --json
|
|
103
|
-
tailor-sdk function logs <execution-id> --json
|
|
116
|
+
```bash
|
|
117
|
+
$ tailor-sdk function logs <execution-id> --json
|
|
104
118
|
```
|
|
105
119
|
|
|
120
|
+
<!-- politty:command:function logs:examples:end -->
|
|
121
|
+
|
|
122
|
+
<!-- politty:command:function logs:notes:start -->
|
|
123
|
+
|
|
124
|
+
**Notes**
|
|
125
|
+
|
|
126
|
+
When viewing a specific execution that failed, the command displays error details with the stack trace mapped back to original source files via the inline sourcemap (clickable file links and code snippets, matching `function test-run` output).
|
|
127
|
+
|
|
128
|
+
When the deployed script cannot be downloaded or the function has been redeployed since the execution, the command falls back to a plain-text error display to avoid showing misleading source locations.
|
|
129
|
+
|
|
130
|
+
<!-- politty:command:function logs:notes:end -->
|
|
131
|
+
|
|
106
132
|
<!-- politty:command:function test-run:heading:start -->
|
|
107
133
|
|
|
108
134
|
### function test-run
|
|
@@ -135,14 +161,14 @@ tailor-sdk function test-run [options] <file>
|
|
|
135
161
|
|
|
136
162
|
**Options**
|
|
137
163
|
|
|
138
|
-
| Option | Alias | Description | Required | Default | Env
|
|
139
|
-
| ------------------------------- | ----- | ------------------------------------------------------------------------ | -------- | -------------------- |
|
|
140
|
-
| `--workspace-id <WORKSPACE_ID>` | `-w` | Workspace ID | No | - | `TAILOR_PLATFORM_WORKSPACE_ID`
|
|
141
|
-
| `--profile <PROFILE>` | `-p` | Workspace profile | No | - | `TAILOR_PLATFORM_PROFILE`
|
|
142
|
-
| `--name <NAME>` | `-n` | Workflow job name to run (matches the `name` field of createWorkflowJob) | No | - | -
|
|
143
|
-
| `--arg <ARG>` | `-a` | JSON argument to pass to the function | No | - | -
|
|
144
|
-
| `--machine-user <MACHINE_USER>` | `-m` | Machine user name for authentication | No | - |
|
|
145
|
-
| `--config <CONFIG>` | `-c` | Path to SDK config file | No | `"tailor.config.ts"` | -
|
|
164
|
+
| Option | Alias | Description | Required | Default | Env |
|
|
165
|
+
| ------------------------------- | ----- | ------------------------------------------------------------------------ | -------- | -------------------- | ----------------------------------- |
|
|
166
|
+
| `--workspace-id <WORKSPACE_ID>` | `-w` | Workspace ID | No | - | `TAILOR_PLATFORM_WORKSPACE_ID` |
|
|
167
|
+
| `--profile <PROFILE>` | `-p` | Workspace profile | No | - | `TAILOR_PLATFORM_PROFILE` |
|
|
168
|
+
| `--name <NAME>` | `-n` | Workflow job name to run (matches the `name` field of createWorkflowJob) | No | - | - |
|
|
169
|
+
| `--arg <ARG>` | `-a` | JSON argument to pass to the function | No | - | - |
|
|
170
|
+
| `--machine-user <MACHINE_USER>` | `-m` | Machine user name for authentication | No | - | `TAILOR_PLATFORM_MACHINE_USER_NAME` |
|
|
171
|
+
| `--config <CONFIG>` | `-c` | Path to SDK config file | No | `"tailor.config.ts"` | - |
|
|
146
172
|
|
|
147
173
|
<!-- politty:command:function test-run:options:end -->
|
|
148
174
|
<!-- politty:command:function test-run:examples:start -->
|