@n8n/workflow-sdk 0.13.1 → 0.14.1
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/dist/build.tsbuildinfo +1 -1
- package/dist/expression/index.js +0 -11
- package/dist/expression/index.js.map +1 -1
- package/dist/generate-types/generate-types.d.ts +1 -1
- package/dist/generate-types/generate-types.js +50 -21
- package/dist/generate-types/generate-types.js.map +1 -1
- package/dist/generate-types/generate-zod-schemas.d.ts +1 -5
- package/dist/generate-types/generate-zod-schemas.js +154 -207
- package/dist/generate-types/generate-zod-schemas.js.map +1 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/prompts/best-practices/guides/chatbot.js +2 -2
- package/dist/prompts/node-guidance/index.d.ts +0 -1
- package/dist/prompts/node-guidance/index.js +0 -1
- package/dist/prompts/node-guidance/index.js.map +1 -1
- package/dist/prompts/node-guidance/parameter-guides/set-node.js +14 -15
- package/dist/prompts/node-guidance/parameter-guides/set-node.js.map +1 -1
- package/dist/prompts/node-selection/ai-nodes.d.ts +2 -2
- package/dist/prompts/node-selection/ai-nodes.js +10 -10
- package/dist/prompts/node-selection/ai-nodes.js.map +1 -1
- package/dist/prompts/node-selection/connection-parameters.d.ts +1 -1
- package/dist/prompts/node-selection/connection-parameters.js +2 -2
- package/dist/prompts/sdk-reference/additional-functions.d.ts +1 -1
- package/dist/prompts/sdk-reference/additional-functions.js +2 -2
- package/dist/prompts/sdk-reference/expressions.d.ts +1 -1
- package/dist/prompts/sdk-reference/expressions.js +1 -1
- package/dist/prompts/sdk-reference/workflow-patterns-detailed.d.ts +1 -1
- package/dist/prompts/sdk-reference/workflow-patterns-detailed.js +9 -7
- package/dist/prompts/sdk-reference/workflow-patterns-detailed.js.map +1 -1
- package/dist/prompts/sdk-reference/workflow-patterns.d.ts +1 -1
- package/dist/prompts/sdk-reference/workflow-patterns.js +13 -11
- package/dist/prompts/sdk-reference/workflow-patterns.js.map +1 -1
- package/dist/prompts/sdk-reference/workflow-rules.d.ts +1 -1
- package/dist/prompts/sdk-reference/workflow-rules.js +11 -1
- package/dist/prompts/sdk-reference/workflow-rules.js.map +1 -1
- package/dist/types/base.d.ts +6 -8
- package/dist/types/base.js.map +1 -1
- package/dist/validation/index.d.ts +1 -1
- package/dist/validation/index.js +24 -1
- package/dist/validation/index.js.map +1 -1
- package/dist/validation/schema-helpers.d.ts +87 -9
- package/dist/validation/schema-helpers.js +18 -4
- package/dist/validation/schema-helpers.js.map +1 -1
- package/dist/validation.d.ts +1 -0
- package/dist/validation.js +3 -1
- package/dist/validation.js.map +1 -1
- package/dist/workflow-builder/layout-utils.d.ts +1 -2
- package/dist/workflow-builder/layout-utils.js +21 -58
- package/dist/workflow-builder/layout-utils.js.map +1 -1
- package/dist/workflow-builder/node-builders/node-builder.d.ts +2 -2
- package/dist/workflow-builder/node-builders/node-builder.js +34 -16
- package/dist/workflow-builder/node-builders/node-builder.js.map +1 -1
- package/dist/workflow-builder/pin-data-utils.js +2 -3
- package/dist/workflow-builder/pin-data-utils.js.map +1 -1
- package/dist/workflow-builder/plugins/composite-handlers/branch-handler-utils.js +23 -2
- package/dist/workflow-builder/plugins/composite-handlers/branch-handler-utils.js.map +1 -1
- package/dist/workflow-builder/plugins/serializers/json-serializer.js +7 -1
- package/dist/workflow-builder/plugins/serializers/json-serializer.js.map +1 -1
- package/dist/workflow-builder/plugins/validators/merge-node-validator.js +1 -1
- package/dist/workflow-builder/plugins/validators/merge-node-validator.js.map +1 -1
- package/dist/workflow-builder/string-utils.d.ts +2 -0
- package/dist/workflow-builder/string-utils.js +12 -0
- package/dist/workflow-builder/string-utils.js.map +1 -1
- package/dist/workflow-builder/validation-helpers.js +5 -6
- package/dist/workflow-builder/validation-helpers.js.map +1 -1
- package/dist/workflow-builder.js +14 -0
- package/dist/workflow-builder.js.map +1 -1
- package/package.json +5 -11
- package/dist/prompts/node-guidance/node-tips/index.d.ts +0 -3
- package/dist/prompts/node-guidance/node-tips/index.js +0 -8
- package/dist/prompts/node-guidance/node-tips/index.js.map +0 -1
- package/dist/prompts/node-guidance/node-tips/structured-output-parser.d.ts +0 -2
- package/dist/prompts/node-guidance/node-tips/structured-output-parser.js +0 -35
- package/dist/prompts/node-guidance/node-tips/structured-output-parser.js.map +0 -1
- package/dist/prompts/node-guidance/node-tips/types.d.ts +0 -7
- package/dist/prompts/node-guidance/node-tips/types.js +0 -3
- package/dist/prompts/node-guidance/node-tips/types.js.map +0 -1
- package/dist/prompts/node-guidance/node-tips/webhook.d.ts +0 -2
- package/dist/prompts/node-guidance/node-tips/webhook.js +0 -38
- package/dist/prompts/node-guidance/node-tips/webhook.js.map +0 -1
|
@@ -7,11 +7,7 @@ exports.generateSchemaPropertyLine = generateSchemaPropertyLine;
|
|
|
7
7
|
exports.stripDiscriminatorKeysFromDisplayOptions = stripDiscriminatorKeysFromDisplayOptions;
|
|
8
8
|
exports.mergeDisplayOptions = mergeDisplayOptions;
|
|
9
9
|
exports.mergePropertiesByName = mergePropertiesByName;
|
|
10
|
-
exports.hasMultiVariantEntries = hasMultiVariantEntries;
|
|
11
|
-
exports.needsResolveOneOfSchemas = needsResolveOneOfSchemas;
|
|
12
10
|
exports.generateConditionalSchemaLine = generateConditionalSchemaLine;
|
|
13
|
-
exports.generateOneOfSchemaLine = generateOneOfSchemaLine;
|
|
14
|
-
exports.generateParameterEntryLine = generateParameterEntryLine;
|
|
15
11
|
exports.generateSubnodeConfigSchemaCode = generateSubnodeConfigSchemaCode;
|
|
16
12
|
exports.getSubnodeSchemaImports = getSubnodeSchemaImports;
|
|
17
13
|
exports.generateSingleVersionSchemaFile = generateSingleVersionSchemaFile;
|
|
@@ -26,6 +22,9 @@ const CUSTOM_API_CALL_KEY = '__CUSTOM_API_CALL__';
|
|
|
26
22
|
function isCustomApiCall(operation) {
|
|
27
23
|
return operation === CUSTOM_API_CALL_KEY;
|
|
28
24
|
}
|
|
25
|
+
const DISPLAY_ONLY_PROPERTY_TYPES = new Set(['notice', 'curlImport', 'credentials', 'callout']);
|
|
26
|
+
const ICON_ZOD_SCHEMA = "z.object({ type: z.union([z.literal('icon'), z.literal('emoji')]), value: z.string() })";
|
|
27
|
+
const WORKFLOW_SELECTOR_ZOD_SCHEMA = "z.union([z.object({ __rl: z.literal(true), mode: z.union([z.literal('list'), z.literal('id')]), value: z.union([z.string(), z.number()]), cachedResultName: z.string().optional(), cachedResultUrl: z.string().optional() }), expressionSchema])";
|
|
29
28
|
const GENERIC_AUTH_TYPE_VALUES = [
|
|
30
29
|
'httpBasicAuth',
|
|
31
30
|
'httpBearerAuth',
|
|
@@ -36,9 +35,6 @@ const GENERIC_AUTH_TYPE_VALUES = [
|
|
|
36
35
|
'oAuth1Api',
|
|
37
36
|
'oAuth2Api',
|
|
38
37
|
];
|
|
39
|
-
const DISPLAY_ONLY_PROPERTY_TYPES = new Set(['notice', 'curlImport', 'credentials', 'callout']);
|
|
40
|
-
const ICON_ZOD_SCHEMA = "z.object({ type: z.union([z.literal('icon'), z.literal('emoji')]), value: z.string() })";
|
|
41
|
-
const WORKFLOW_SELECTOR_ZOD_SCHEMA = "z.union([z.object({ __rl: z.literal(true), mode: z.union([z.literal('list'), z.literal('id')]), value: z.union([z.string(), z.number()]), cachedResultName: z.string().optional(), cachedResultUrl: z.string().optional() }), expressionSchema])";
|
|
42
38
|
const RESERVED_WORDS = new Set([
|
|
43
39
|
'break',
|
|
44
40
|
'case',
|
|
@@ -252,14 +248,26 @@ function generateResourceLocatorZodSchema(prop) {
|
|
|
252
248
|
}
|
|
253
249
|
return 'resourceLocatorValueSchema';
|
|
254
250
|
}
|
|
251
|
+
function primitiveElement(base, allowExpression) {
|
|
252
|
+
if (base === 'string')
|
|
253
|
+
return allowExpression ? 'stringOrExpression' : 'z.string()';
|
|
254
|
+
if (base === 'number')
|
|
255
|
+
return allowExpression ? 'numberOrExpression' : 'z.number()';
|
|
256
|
+
return allowExpression ? 'booleanOrExpression' : 'z.boolean()';
|
|
257
|
+
}
|
|
258
|
+
function wrapMultipleValues(elementSchema, isMultipleValues, _allowExpression) {
|
|
259
|
+
if (!isMultipleValues)
|
|
260
|
+
return elementSchema;
|
|
261
|
+
return `z.array(${elementSchema})`;
|
|
262
|
+
}
|
|
263
|
+
function literalUnion(literals, allowExpression) {
|
|
264
|
+
const parts = allowExpression ? [...literals, 'expressionSchema'] : literals;
|
|
265
|
+
return `z.union([${parts.join(', ')}])`;
|
|
266
|
+
}
|
|
255
267
|
function mapNestedPropertyToZodSchema(prop) {
|
|
256
|
-
|
|
257
|
-
const expressionAwareResult = prop.noDataExpression
|
|
258
|
-
? stripExpressionFromZodSchema(result)
|
|
259
|
-
: result;
|
|
260
|
-
return wrapMultipleValuesZodSchema(prop, expressionAwareResult);
|
|
268
|
+
return mapNestedPropertyToZodSchemaInner(prop, !prop.noDataExpression);
|
|
261
269
|
}
|
|
262
|
-
function mapNestedPropertyToZodSchemaInner(prop) {
|
|
270
|
+
function mapNestedPropertyToZodSchemaInner(prop, allowExpression) {
|
|
263
271
|
if (DISPLAY_ONLY_PROPERTY_TYPES.has(prop.type)) {
|
|
264
272
|
return '';
|
|
265
273
|
}
|
|
@@ -269,42 +277,41 @@ function mapNestedPropertyToZodSchemaInner(prop) {
|
|
|
269
277
|
if (prop.type === 'resourceMapper') {
|
|
270
278
|
return 'resourceMapperValueSchema';
|
|
271
279
|
}
|
|
280
|
+
const isMultipleValues = prop.typeOptions?.multipleValues === true;
|
|
272
281
|
if (prop.typeOptions?.loadOptionsMethod || prop.typeOptions?.loadOptionsDependsOn) {
|
|
273
282
|
if (prop.type === 'multiOptions') {
|
|
274
283
|
return 'z.array(z.string())';
|
|
275
284
|
}
|
|
276
|
-
return '
|
|
285
|
+
return wrapMultipleValues(primitiveElement('string', allowExpression), isMultipleValues, allowExpression);
|
|
277
286
|
}
|
|
278
287
|
switch (prop.type) {
|
|
279
288
|
case 'string':
|
|
280
289
|
case 'dateTime':
|
|
281
290
|
case 'color':
|
|
282
291
|
case 'credentialsSelect':
|
|
283
|
-
return '
|
|
292
|
+
return wrapMultipleValues(primitiveElement('string', allowExpression), isMultipleValues, allowExpression);
|
|
284
293
|
case 'number':
|
|
285
|
-
return '
|
|
294
|
+
return wrapMultipleValues(primitiveElement('number', allowExpression), isMultipleValues, allowExpression);
|
|
286
295
|
case 'boolean':
|
|
287
|
-
return '
|
|
288
|
-
case 'options':
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
if (literals.length > 0) {
|
|
304
|
-
return `z.array(z.union([${literals.join(', ')}]))`;
|
|
305
|
-
}
|
|
296
|
+
return primitiveElement('boolean', allowExpression);
|
|
297
|
+
case 'options': {
|
|
298
|
+
const literals = (prop.options ?? [])
|
|
299
|
+
.filter((opt) => opt.value !== undefined)
|
|
300
|
+
.map((opt) => `z.literal(${formatZodLiteral(opt.value)})`);
|
|
301
|
+
const elementSchema = literals.length > 0
|
|
302
|
+
? literalUnion(literals, allowExpression)
|
|
303
|
+
: primitiveElement('string', allowExpression);
|
|
304
|
+
return wrapMultipleValues(elementSchema, isMultipleValues, allowExpression);
|
|
305
|
+
}
|
|
306
|
+
case 'multiOptions': {
|
|
307
|
+
const literals = (prop.options ?? [])
|
|
308
|
+
.filter((opt) => opt.value !== undefined)
|
|
309
|
+
.map((opt) => `z.literal(${formatZodLiteral(opt.value)})`);
|
|
310
|
+
if (literals.length > 0) {
|
|
311
|
+
return `z.array(z.union([${literals.join(', ')}]))`;
|
|
306
312
|
}
|
|
307
313
|
return 'z.array(z.string())';
|
|
314
|
+
}
|
|
308
315
|
case 'json':
|
|
309
316
|
return 'z.union([iDataObjectSchema, z.string()])';
|
|
310
317
|
case 'filter':
|
|
@@ -316,7 +323,7 @@ function mapNestedPropertyToZodSchemaInner(prop) {
|
|
|
316
323
|
case 'collection':
|
|
317
324
|
return generateCollectionZodSchema(prop);
|
|
318
325
|
case 'button':
|
|
319
|
-
return '
|
|
326
|
+
return primitiveElement('string', allowExpression);
|
|
320
327
|
case 'icon':
|
|
321
328
|
return ICON_ZOD_SCHEMA;
|
|
322
329
|
case 'workflowSelector':
|
|
@@ -402,20 +409,8 @@ function generateCollectionZodSchema(prop) {
|
|
|
402
409
|
return `z.object({ ${nestedProps.join(', ')} })`;
|
|
403
410
|
}
|
|
404
411
|
function mapPropertyToZodSchema(prop) {
|
|
405
|
-
const result = mapPropertyToZodSchemaInner(prop);
|
|
406
|
-
|
|
407
|
-
? stripExpressionFromZodSchema(result)
|
|
408
|
-
: result;
|
|
409
|
-
return wrapMultipleValuesZodSchema(prop, expressionAwareResult);
|
|
410
|
-
}
|
|
411
|
-
function stripExpressionFromZodSchema(schema) {
|
|
412
|
-
if (schema === 'stringOrExpression')
|
|
413
|
-
return 'z.string()';
|
|
414
|
-
if (schema === 'numberOrExpression')
|
|
415
|
-
return 'z.number()';
|
|
416
|
-
if (schema === 'booleanOrExpression')
|
|
417
|
-
return 'z.boolean()';
|
|
418
|
-
return schema.replace(/,\s*expressionSchema/g, '');
|
|
412
|
+
const result = mapPropertyToZodSchemaInner(prop, !prop.noDataExpression);
|
|
413
|
+
return wrapMultipleValuesZodSchema(prop, result);
|
|
419
414
|
}
|
|
420
415
|
function wrapMultipleValuesZodSchema(prop, schema) {
|
|
421
416
|
if (!schema || prop.type === 'fixedCollection' || prop.type === 'multiOptions') {
|
|
@@ -423,10 +418,13 @@ function wrapMultipleValuesZodSchema(prop, schema) {
|
|
|
423
418
|
}
|
|
424
419
|
return prop.typeOptions?.multipleValues === true ? `z.array(${schema})` : schema;
|
|
425
420
|
}
|
|
426
|
-
function mapPropertyToZodSchemaInner(prop) {
|
|
421
|
+
function mapPropertyToZodSchemaInner(prop, allowExpression) {
|
|
422
|
+
if (DISPLAY_ONLY_PROPERTY_TYPES.has(prop.type)) {
|
|
423
|
+
return '';
|
|
424
|
+
}
|
|
427
425
|
if (prop.type === 'credentialsSelect' && prop.name === 'genericAuthType') {
|
|
428
426
|
const literals = GENERIC_AUTH_TYPE_VALUES.map((v) => `z.literal('${v}')`);
|
|
429
|
-
return
|
|
427
|
+
return literalUnion(literals, allowExpression);
|
|
430
428
|
}
|
|
431
429
|
if (prop.type === 'resourceLocator') {
|
|
432
430
|
return generateResourceLocatorZodSchema(prop);
|
|
@@ -435,42 +433,37 @@ function mapPropertyToZodSchemaInner(prop) {
|
|
|
435
433
|
return 'resourceMapperValueSchema';
|
|
436
434
|
}
|
|
437
435
|
if (prop.typeOptions?.loadOptionsMethod || prop.typeOptions?.loadOptionsDependsOn) {
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
case 'multiOptions':
|
|
442
|
-
return 'z.array(z.string())';
|
|
443
|
-
default:
|
|
444
|
-
return 'stringOrExpression';
|
|
445
|
-
}
|
|
436
|
+
if (prop.type === 'multiOptions')
|
|
437
|
+
return 'z.array(z.string())';
|
|
438
|
+
return primitiveElement('string', allowExpression);
|
|
446
439
|
}
|
|
447
440
|
switch (prop.type) {
|
|
448
441
|
case 'string':
|
|
449
|
-
|
|
442
|
+
case 'dateTime':
|
|
443
|
+
case 'color':
|
|
444
|
+
case 'credentialsSelect':
|
|
445
|
+
return primitiveElement('string', allowExpression);
|
|
450
446
|
case 'number':
|
|
451
|
-
return '
|
|
447
|
+
return primitiveElement('number', allowExpression);
|
|
452
448
|
case 'boolean':
|
|
453
|
-
return '
|
|
454
|
-
case 'options':
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
.map((opt) => `z.literal(${formatZodLiteral(opt.value)})`);
|
|
469
|
-
if (literals.length > 0) {
|
|
470
|
-
return `z.array(z.union([${literals.join(', ')}]))`;
|
|
471
|
-
}
|
|
449
|
+
return primitiveElement('boolean', allowExpression);
|
|
450
|
+
case 'options': {
|
|
451
|
+
const literals = (prop.options ?? [])
|
|
452
|
+
.filter((opt) => opt.value !== undefined)
|
|
453
|
+
.map((opt) => `z.literal(${formatZodLiteral(opt.value)})`);
|
|
454
|
+
return literals.length > 0
|
|
455
|
+
? literalUnion(literals, allowExpression)
|
|
456
|
+
: primitiveElement('string', allowExpression);
|
|
457
|
+
}
|
|
458
|
+
case 'multiOptions': {
|
|
459
|
+
const literals = (prop.options ?? [])
|
|
460
|
+
.filter((opt) => opt.value !== undefined)
|
|
461
|
+
.map((opt) => `z.literal(${formatZodLiteral(opt.value)})`);
|
|
462
|
+
if (literals.length > 0) {
|
|
463
|
+
return `z.array(z.union([${literals.join(', ')}]))`;
|
|
472
464
|
}
|
|
473
465
|
return 'z.array(z.string())';
|
|
466
|
+
}
|
|
474
467
|
case 'json':
|
|
475
468
|
return 'z.union([iDataObjectSchema, z.string()])';
|
|
476
469
|
case 'filter':
|
|
@@ -481,9 +474,12 @@ function mapPropertyToZodSchemaInner(prop) {
|
|
|
481
474
|
return generateFixedCollectionZodSchema(prop);
|
|
482
475
|
case 'collection':
|
|
483
476
|
return generateCollectionZodSchema(prop);
|
|
484
|
-
case '
|
|
485
|
-
|
|
486
|
-
|
|
477
|
+
case 'button':
|
|
478
|
+
return primitiveElement('string', allowExpression);
|
|
479
|
+
case 'icon':
|
|
480
|
+
return ICON_ZOD_SCHEMA;
|
|
481
|
+
case 'workflowSelector':
|
|
482
|
+
return WORKFLOW_SELECTOR_ZOD_SCHEMA;
|
|
487
483
|
case 'hidden':
|
|
488
484
|
return 'z.unknown()';
|
|
489
485
|
case 'notice':
|
|
@@ -491,14 +487,6 @@ function mapPropertyToZodSchemaInner(prop) {
|
|
|
491
487
|
case 'credentials':
|
|
492
488
|
case 'callout':
|
|
493
489
|
return '';
|
|
494
|
-
case 'button':
|
|
495
|
-
return 'stringOrExpression';
|
|
496
|
-
case 'icon':
|
|
497
|
-
return ICON_ZOD_SCHEMA;
|
|
498
|
-
case 'workflowSelector':
|
|
499
|
-
return WORKFLOW_SELECTOR_ZOD_SCHEMA;
|
|
500
|
-
case 'credentialsSelect':
|
|
501
|
-
return 'stringOrExpression';
|
|
502
490
|
default:
|
|
503
491
|
return 'z.unknown()';
|
|
504
492
|
}
|
|
@@ -573,72 +561,38 @@ function mergeDisplayOptions(existing, incoming) {
|
|
|
573
561
|
}
|
|
574
562
|
return merged;
|
|
575
563
|
}
|
|
576
|
-
function isSameDisplayOptions(a, b) {
|
|
577
|
-
return JSON.stringify(a ?? null) === JSON.stringify(b ?? null);
|
|
578
|
-
}
|
|
579
564
|
function mergePropertiesByName(properties) {
|
|
580
|
-
const
|
|
565
|
+
const propsByName = new Map();
|
|
581
566
|
for (const prop of properties) {
|
|
582
567
|
if (DISPLAY_ONLY_PROPERTY_TYPES.has(prop.type)) {
|
|
583
568
|
continue;
|
|
584
569
|
}
|
|
585
|
-
const
|
|
586
|
-
if (
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
]);
|
|
598
|
-
continue;
|
|
599
|
-
}
|
|
600
|
-
const trueDuplicate = existingVariants.find((v) => isSameDisplayOptions(v.displayOptions, normalizedProp.displayOptions));
|
|
601
|
-
if (trueDuplicate) {
|
|
602
|
-
if ((normalizedProp.type === 'collection' || normalizedProp.type === 'fixedCollection') &&
|
|
603
|
-
normalizedProp.options &&
|
|
604
|
-
trueDuplicate.options) {
|
|
605
|
-
const existingOptionNames = new Set(trueDuplicate.options.map((o) => o.name));
|
|
606
|
-
for (const opt of normalizedProp.options) {
|
|
570
|
+
const existing = propsByName.get(prop.name);
|
|
571
|
+
if (existing) {
|
|
572
|
+
if (prop.displayOptions && existing.displayOptions) {
|
|
573
|
+
existing.displayOptions = mergeDisplayOptions(existing.displayOptions, prop.displayOptions);
|
|
574
|
+
}
|
|
575
|
+
else if (prop.displayOptions && !existing.displayOptions) {
|
|
576
|
+
}
|
|
577
|
+
if ((prop.type === 'collection' || prop.type === 'fixedCollection') &&
|
|
578
|
+
prop.options &&
|
|
579
|
+
existing.options) {
|
|
580
|
+
const existingOptionNames = new Set(existing.options.map((o) => o.name));
|
|
581
|
+
for (const opt of prop.options) {
|
|
607
582
|
if (!existingOptionNames.has(opt.name)) {
|
|
608
|
-
|
|
583
|
+
existing.options.push(opt);
|
|
609
584
|
}
|
|
610
585
|
}
|
|
611
586
|
}
|
|
612
587
|
}
|
|
613
588
|
else {
|
|
614
|
-
|
|
615
|
-
...
|
|
616
|
-
options:
|
|
589
|
+
propsByName.set(prop.name, {
|
|
590
|
+
...prop,
|
|
591
|
+
options: prop.options ? [...prop.options] : undefined,
|
|
617
592
|
});
|
|
618
593
|
}
|
|
619
594
|
}
|
|
620
|
-
return
|
|
621
|
-
}
|
|
622
|
-
function hasMultiVariantEntries(variantsByName) {
|
|
623
|
-
for (const variants of variantsByName.values()) {
|
|
624
|
-
if (variants.length > 1)
|
|
625
|
-
return true;
|
|
626
|
-
}
|
|
627
|
-
return false;
|
|
628
|
-
}
|
|
629
|
-
function needsResolveOneOfSchemas(variantsByName, discriminatorKeys) {
|
|
630
|
-
for (const variants of variantsByName.values()) {
|
|
631
|
-
if (variants.length < 2)
|
|
632
|
-
continue;
|
|
633
|
-
const allRemainConditional = variants.every((v) => {
|
|
634
|
-
if (!v.displayOptions)
|
|
635
|
-
return false;
|
|
636
|
-
return (stripDiscriminatorKeysFromDisplayOptions(v.displayOptions, discriminatorKeys) !== undefined);
|
|
637
|
-
});
|
|
638
|
-
if (allRemainConditional)
|
|
639
|
-
return true;
|
|
640
|
-
}
|
|
641
|
-
return false;
|
|
595
|
+
return propsByName;
|
|
642
596
|
}
|
|
643
597
|
function generateConditionalSchemaLine(prop, allProperties = []) {
|
|
644
598
|
const zodSchema = mapPropertyToZodSchema(prop);
|
|
@@ -654,49 +608,6 @@ function generateConditionalSchemaLine(prop, allProperties = []) {
|
|
|
654
608
|
const defaultsStr = Object.keys(defaults).length > 0 ? `, defaults: ${JSON.stringify(defaults)}` : '';
|
|
655
609
|
return `${INDENT}${propName}: resolveSchema({ parameters, schema: ${zodSchema}, required: ${required}, displayOptions: ${displayOptionsStr}${defaultsStr} }),`;
|
|
656
610
|
}
|
|
657
|
-
function generateOneOfSchemaLine(variants, allProperties = []) {
|
|
658
|
-
if (variants.length === 0)
|
|
659
|
-
return '';
|
|
660
|
-
const propName = quotePropertyName(variants[0].name);
|
|
661
|
-
const variantSpecs = [];
|
|
662
|
-
for (const variant of variants) {
|
|
663
|
-
const zodSchema = mapPropertyToZodSchema(variant);
|
|
664
|
-
if (!zodSchema) {
|
|
665
|
-
return '';
|
|
666
|
-
}
|
|
667
|
-
const required = !isPropertyOptional(variant);
|
|
668
|
-
const displayOptionsStr = JSON.stringify(variant.displayOptions ?? {});
|
|
669
|
-
const defaults = variant.displayOptions
|
|
670
|
-
? extractDefaultsForDisplayOptions(variant.displayOptions, allProperties)
|
|
671
|
-
: {};
|
|
672
|
-
const defaultsStr = Object.keys(defaults).length > 0 ? `, defaults: ${JSON.stringify(defaults)}` : '';
|
|
673
|
-
variantSpecs.push(`{ schema: ${zodSchema}, required: ${required}, displayOptions: ${displayOptionsStr}${defaultsStr} }`);
|
|
674
|
-
}
|
|
675
|
-
return `${INDENT}${propName}: resolveOneOfSchemas({ parameters, variants: [${variantSpecs.join(', ')}] }),`;
|
|
676
|
-
}
|
|
677
|
-
function generateParameterEntryLine(variants, allFlatProperties, discriminatorKeys) {
|
|
678
|
-
if (variants.length === 0)
|
|
679
|
-
return '';
|
|
680
|
-
const processed = variants.map((variant) => {
|
|
681
|
-
if (!variant.displayOptions) {
|
|
682
|
-
return { variant, conditional: false };
|
|
683
|
-
}
|
|
684
|
-
const stripped = stripDiscriminatorKeysFromDisplayOptions(variant.displayOptions, discriminatorKeys);
|
|
685
|
-
if (!stripped) {
|
|
686
|
-
return { variant: { ...variant, displayOptions: undefined }, conditional: false };
|
|
687
|
-
}
|
|
688
|
-
return { variant: { ...variant, displayOptions: stripped }, conditional: true };
|
|
689
|
-
});
|
|
690
|
-
const unconditional = processed.find((p) => !p.conditional);
|
|
691
|
-
if (unconditional) {
|
|
692
|
-
return generateSchemaPropertyLine(unconditional.variant, isPropertyOptional(unconditional.variant));
|
|
693
|
-
}
|
|
694
|
-
const conditionalVariants = processed.map((p) => p.variant);
|
|
695
|
-
if (conditionalVariants.length === 1) {
|
|
696
|
-
return generateConditionalSchemaLine(conditionalVariants[0], allFlatProperties);
|
|
697
|
-
}
|
|
698
|
-
return generateOneOfSchemaLine(conditionalVariants, allFlatProperties);
|
|
699
|
-
}
|
|
700
611
|
function generateSubnodeConfigSchemaCode(aiInputTypes, schemaName, allProperties) {
|
|
701
612
|
if (aiInputTypes.length === 0) {
|
|
702
613
|
return null;
|
|
@@ -777,10 +688,8 @@ function generateSingleVersionSchemaFile(node, specificVersion) {
|
|
|
777
688
|
const aiInputTypes = (0, generate_types_1.extractAIInputTypesFromBuilderHint)(filteredNode);
|
|
778
689
|
const subnodeSchemaImports = getSubnodeSchemaImports(aiInputTypes);
|
|
779
690
|
const hasAiInputs = aiInputTypes.length > 0;
|
|
780
|
-
const propsByName = mergePropertiesByName(filteredProperties);
|
|
781
691
|
const needsResolveSchema = hasDisplayOptions(filteredProperties) ||
|
|
782
692
|
(hasAiInputs && hasConditionalSubnodeFields(aiInputTypes));
|
|
783
|
-
const needsResolveOneOf = needsResolveOneOfSchemas(propsByName, ['@version']);
|
|
784
693
|
const lines = [];
|
|
785
694
|
const helpers = [
|
|
786
695
|
'z',
|
|
@@ -797,9 +706,6 @@ function generateSingleVersionSchemaFile(node, specificVersion) {
|
|
|
797
706
|
if (needsResolveSchema) {
|
|
798
707
|
helpers.push('resolveSchema');
|
|
799
708
|
}
|
|
800
|
-
if (needsResolveOneOf) {
|
|
801
|
-
helpers.push('resolveOneOfSchemas');
|
|
802
|
-
}
|
|
803
709
|
for (const schemaImport of subnodeSchemaImports) {
|
|
804
710
|
helpers.push(schemaImport);
|
|
805
711
|
}
|
|
@@ -881,11 +787,35 @@ function generateSingleVersionSchemaFile(node, specificVersion) {
|
|
|
881
787
|
lines.push('');
|
|
882
788
|
lines.push(`${INDENT}// Parameters schema`);
|
|
883
789
|
lines.push(`${INDENT}const parametersSchema = z.object({`);
|
|
884
|
-
const
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
if (
|
|
888
|
-
|
|
790
|
+
const propsByName = mergePropertiesByName(filteredProperties);
|
|
791
|
+
const allPropsArray = Array.from(propsByName.values());
|
|
792
|
+
for (const prop of allPropsArray) {
|
|
793
|
+
if (prop.displayOptions) {
|
|
794
|
+
const strippedDisplayOptions = stripDiscriminatorKeysFromDisplayOptions(prop.displayOptions, [
|
|
795
|
+
'@version',
|
|
796
|
+
]);
|
|
797
|
+
if (strippedDisplayOptions) {
|
|
798
|
+
const propWithStripped = {
|
|
799
|
+
...prop,
|
|
800
|
+
displayOptions: strippedDisplayOptions,
|
|
801
|
+
};
|
|
802
|
+
const propLine = generateConditionalSchemaLine(propWithStripped, allPropsArray);
|
|
803
|
+
if (propLine) {
|
|
804
|
+
lines.push(INDENT + propLine);
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
else {
|
|
808
|
+
const propLine = generateSchemaPropertyLine(prop, isPropertyOptional(prop));
|
|
809
|
+
if (propLine) {
|
|
810
|
+
lines.push(INDENT + propLine);
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
else {
|
|
815
|
+
const propLine = generateSchemaPropertyLine(prop, isPropertyOptional(prop));
|
|
816
|
+
if (propLine) {
|
|
817
|
+
lines.push(INDENT + propLine);
|
|
818
|
+
}
|
|
889
819
|
}
|
|
890
820
|
}
|
|
891
821
|
lines.push(`${INDENT}});`);
|
|
@@ -934,8 +864,6 @@ function generateDiscriminatorSchemaFile(node, version, combo, props, _importDep
|
|
|
934
864
|
return stripped !== undefined;
|
|
935
865
|
});
|
|
936
866
|
const hasConditionalAiInputs = hasAiInputs && hasConditionalSubnodeFields(aiInputTypes);
|
|
937
|
-
const propsByName = mergePropertiesByName(props);
|
|
938
|
-
const needsResolveOneOf = needsResolveOneOfSchemas(propsByName, discriminatorKeys);
|
|
939
867
|
const lines = [];
|
|
940
868
|
const comboDesc = Object.entries(combo)
|
|
941
869
|
.filter(([_, v]) => v !== undefined)
|
|
@@ -956,9 +884,6 @@ function generateDiscriminatorSchemaFile(node, version, combo, props, _importDep
|
|
|
956
884
|
if (hasRemainingDisplayOptions || hasConditionalAiInputs) {
|
|
957
885
|
helpers.push('resolveSchema');
|
|
958
886
|
}
|
|
959
|
-
if (needsResolveOneOf) {
|
|
960
|
-
helpers.push('resolveOneOfSchemas');
|
|
961
|
-
}
|
|
962
887
|
if (hasAiInputs) {
|
|
963
888
|
const subnodeImports = getSubnodeSchemaImports(aiInputTypes);
|
|
964
889
|
for (const schemaImport of subnodeImports) {
|
|
@@ -1055,11 +980,33 @@ function generateDiscriminatorSchemaFile(node, version, combo, props, _importDep
|
|
|
1055
980
|
}
|
|
1056
981
|
}
|
|
1057
982
|
}
|
|
1058
|
-
const
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
if (
|
|
1062
|
-
|
|
983
|
+
const propsByName = mergePropertiesByName(props);
|
|
984
|
+
const allPropsArray = Array.from(propsByName.values());
|
|
985
|
+
for (const prop of allPropsArray) {
|
|
986
|
+
if (prop.displayOptions) {
|
|
987
|
+
const strippedDisplayOptions = stripDiscriminatorKeysFromDisplayOptions(prop.displayOptions, discriminatorKeys);
|
|
988
|
+
if (strippedDisplayOptions) {
|
|
989
|
+
const propWithStrippedOptions = {
|
|
990
|
+
...prop,
|
|
991
|
+
displayOptions: strippedDisplayOptions,
|
|
992
|
+
};
|
|
993
|
+
const propLine = generateConditionalSchemaLine(propWithStrippedOptions, allPropsArray);
|
|
994
|
+
if (propLine) {
|
|
995
|
+
lines.push(INDENT.repeat(2) + propLine);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
else {
|
|
999
|
+
const propLine = generateSchemaPropertyLine(prop, isPropertyOptional(prop));
|
|
1000
|
+
if (propLine) {
|
|
1001
|
+
lines.push(INDENT.repeat(2) + propLine);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
else {
|
|
1006
|
+
const propLine = generateSchemaPropertyLine(prop, isPropertyOptional(prop));
|
|
1007
|
+
if (propLine) {
|
|
1008
|
+
lines.push(INDENT.repeat(2) + propLine);
|
|
1009
|
+
}
|
|
1063
1010
|
}
|
|
1064
1011
|
}
|
|
1065
1012
|
lines.push(`${INDENT.repeat(2)}}).optional(),`);
|