@n8n/workflow-sdk 0.2.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/LICENSE.md +88 -0
- package/README.md +30 -0
- package/dist/ast-interpreter/errors.d.ts +19 -0
- package/dist/ast-interpreter/errors.js +64 -0
- package/dist/ast-interpreter/errors.js.map +1 -0
- package/dist/ast-interpreter/index.d.ts +5 -0
- package/dist/ast-interpreter/index.js +18 -0
- package/dist/ast-interpreter/index.js.map +1 -0
- package/dist/ast-interpreter/interpreter.d.ts +2 -0
- package/dist/ast-interpreter/interpreter.js +471 -0
- package/dist/ast-interpreter/interpreter.js.map +1 -0
- package/dist/ast-interpreter/parser.d.ts +2 -0
- package/dist/ast-interpreter/parser.js +61 -0
- package/dist/ast-interpreter/parser.js.map +1 -0
- package/dist/ast-interpreter/validators.d.ts +13 -0
- package/dist/ast-interpreter/validators.js +243 -0
- package/dist/ast-interpreter/validators.js.map +1 -0
- package/dist/build.tsbuildinfo +1 -0
- package/dist/cli/code-to-json.d.ts +1 -0
- package/dist/cli/code-to-json.js +51 -0
- package/dist/cli/code-to-json.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +25 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/json-to-code.d.ts +1 -0
- package/dist/cli/json-to-code.js +60 -0
- package/dist/cli/json-to-code.js.map +1 -0
- package/dist/cli/utils.d.ts +1 -0
- package/dist/cli/utils.js +16 -0
- package/dist/cli/utils.js.map +1 -0
- package/dist/codegen/code-generator.d.ts +14 -0
- package/dist/codegen/code-generator.js +807 -0
- package/dist/codegen/code-generator.js.map +1 -0
- package/dist/codegen/composite-builder.d.ts +3 -0
- package/dist/codegen/composite-builder.js +718 -0
- package/dist/codegen/composite-builder.js.map +1 -0
- package/dist/codegen/composite-handlers/build-utils.d.ts +24 -0
- package/dist/codegen/composite-handlers/build-utils.js +79 -0
- package/dist/codegen/composite-handlers/build-utils.js.map +1 -0
- package/dist/codegen/composite-handlers/error-handler.d.ts +6 -0
- package/dist/codegen/composite-handlers/error-handler.js +51 -0
- package/dist/codegen/composite-handlers/error-handler.js.map +1 -0
- package/dist/codegen/composite-handlers/if-else-handler.d.ts +5 -0
- package/dist/codegen/composite-handlers/if-else-handler.js +57 -0
- package/dist/codegen/composite-handlers/if-else-handler.js.map +1 -0
- package/dist/codegen/composite-handlers/index.d.ts +1 -0
- package/dist/codegen/composite-handlers/index.js +17 -0
- package/dist/codegen/composite-handlers/index.js.map +1 -0
- package/dist/codegen/composite-handlers/merge-handler.d.ts +5 -0
- package/dist/codegen/composite-handlers/merge-handler.js +25 -0
- package/dist/codegen/composite-handlers/merge-handler.js.map +1 -0
- package/dist/codegen/composite-handlers/sib-handler.d.ts +5 -0
- package/dist/codegen/composite-handlers/sib-handler.js +57 -0
- package/dist/codegen/composite-handlers/sib-handler.js.map +1 -0
- package/dist/codegen/composite-handlers/switch-case-handler.d.ts +5 -0
- package/dist/codegen/composite-handlers/switch-case-handler.js +80 -0
- package/dist/codegen/composite-handlers/switch-case-handler.js.map +1 -0
- package/dist/codegen/composite-tree.d.ts +81 -0
- package/dist/codegen/composite-tree.js +3 -0
- package/dist/codegen/composite-tree.js.map +1 -0
- package/dist/codegen/config-builder.d.ts +7 -0
- package/dist/codegen/config-builder.js +22 -0
- package/dist/codegen/config-builder.js.map +1 -0
- package/dist/codegen/constants.d.ts +5 -0
- package/dist/codegen/constants.js +30 -0
- package/dist/codegen/constants.js.map +1 -0
- package/dist/codegen/deferred-connections.d.ts +20 -0
- package/dist/codegen/deferred-connections.js +46 -0
- package/dist/codegen/deferred-connections.js.map +1 -0
- package/dist/codegen/execution-schema-jsdoc.d.ts +3 -0
- package/dist/codegen/execution-schema-jsdoc.js +109 -0
- package/dist/codegen/execution-schema-jsdoc.js.map +1 -0
- package/dist/codegen/execution-status.d.ts +9 -0
- package/dist/codegen/execution-status.js +42 -0
- package/dist/codegen/execution-status.js.map +1 -0
- package/dist/codegen/expression-annotator.d.ts +2 -0
- package/dist/codegen/expression-annotator.js +38 -0
- package/dist/codegen/expression-annotator.js.map +1 -0
- package/dist/codegen/graph-annotator.d.ts +2 -0
- package/dist/codegen/graph-annotator.js +107 -0
- package/dist/codegen/graph-annotator.js.map +1 -0
- package/dist/codegen/index.d.ts +20 -0
- package/dist/codegen/index.js +60 -0
- package/dist/codegen/index.js.map +1 -0
- package/dist/codegen/merge-pattern.d.ts +12 -0
- package/dist/codegen/merge-pattern.js +119 -0
- package/dist/codegen/merge-pattern.js.map +1 -0
- package/dist/codegen/node-type-utils.d.ts +4 -0
- package/dist/codegen/node-type-utils.js +38 -0
- package/dist/codegen/node-type-utils.js.map +1 -0
- package/dist/codegen/output-utils.d.ts +9 -0
- package/dist/codegen/output-utils.js +68 -0
- package/dist/codegen/output-utils.js.map +1 -0
- package/dist/codegen/parse-workflow-code.d.ts +3 -0
- package/dist/codegen/parse-workflow-code.js +438 -0
- package/dist/codegen/parse-workflow-code.js.map +1 -0
- package/dist/codegen/semantic-graph.d.ts +3 -0
- package/dist/codegen/semantic-graph.js +216 -0
- package/dist/codegen/semantic-graph.js.map +1 -0
- package/dist/codegen/semantic-registry.d.ts +18 -0
- package/dist/codegen/semantic-registry.js +102 -0
- package/dist/codegen/semantic-registry.js.map +1 -0
- package/dist/codegen/sib-merge-handler.d.ts +20 -0
- package/dist/codegen/sib-merge-handler.js +92 -0
- package/dist/codegen/sib-merge-handler.js.map +1 -0
- package/dist/codegen/string-utils.d.ts +6 -0
- package/dist/codegen/string-utils.js +38 -0
- package/dist/codegen/string-utils.js.map +1 -0
- package/dist/codegen/subnode-generator.d.ts +17 -0
- package/dist/codegen/subnode-generator.js +219 -0
- package/dist/codegen/subnode-generator.js.map +1 -0
- package/dist/codegen/types.d.ts +40 -0
- package/dist/codegen/types.js +16 -0
- package/dist/codegen/types.js.map +1 -0
- package/dist/codegen/variable-names.d.ts +8 -0
- package/dist/codegen/variable-names.js +121 -0
- package/dist/codegen/variable-names.js.map +1 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +14 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/constants/node-types.d.ts +19 -0
- package/dist/constants/node-types.js +46 -0
- package/dist/constants/node-types.js.map +1 -0
- package/dist/expression/index.d.ts +6 -0
- package/dist/expression/index.js +181 -0
- package/dist/expression/index.js.map +1 -0
- package/dist/expression.d.ts +1 -0
- package/dist/expression.js +10 -0
- package/dist/expression.js.map +1 -0
- package/dist/generate-types/generate-node-defs-cli.d.ts +7 -0
- package/dist/generate-types/generate-node-defs-cli.js +99 -0
- package/dist/generate-types/generate-node-defs-cli.js.map +1 -0
- package/dist/generate-types/generate-types.d.ts +163 -0
- package/dist/generate-types/generate-types.js +2569 -0
- package/dist/generate-types/generate-types.js.map +1 -0
- package/dist/generate-types/generate-zod-schemas.d.ts +41 -0
- package/dist/generate-types/generate-zod-schemas.js +1129 -0
- package/dist/generate-types/generate-zod-schemas.js.map +1 -0
- package/dist/generate-types/index.d.ts +3 -0
- package/dist/generate-types/index.js +62 -0
- package/dist/generate-types/index.js.map +1 -0
- package/dist/generate-types/zod-helpers.d.ts +189 -0
- package/dist/generate-types/zod-helpers.js +76 -0
- package/dist/generate-types/zod-helpers.js.map +1 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +87 -0
- package/dist/index.js.map +1 -0
- package/dist/types/aliases.d.ts +5 -0
- package/dist/types/aliases.js +3 -0
- package/dist/types/aliases.js.map +1 -0
- package/dist/types/base.d.ts +395 -0
- package/dist/types/base.js +22 -0
- package/dist/types/base.js.map +1 -0
- package/dist/utils/code-helpers.d.ts +7 -0
- package/dist/utils/code-helpers.js +47 -0
- package/dist/utils/code-helpers.js.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +11 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/safe-access.d.ts +3 -0
- package/dist/utils/safe-access.js +21 -0
- package/dist/utils/safe-access.js.map +1 -0
- package/dist/utils/trigger-detection.d.ts +1 -0
- package/dist/utils/trigger-detection.js +17 -0
- package/dist/utils/trigger-detection.js.map +1 -0
- package/dist/validation/display-options.d.ts +18 -0
- package/dist/validation/display-options.js +194 -0
- package/dist/validation/display-options.js.map +1 -0
- package/dist/validation/index.d.ts +34 -0
- package/dist/validation/index.js +428 -0
- package/dist/validation/index.js.map +1 -0
- package/dist/validation/input-resolver.d.ts +2 -0
- package/dist/validation/input-resolver.js +23 -0
- package/dist/validation/input-resolver.js.map +1 -0
- package/dist/validation/resolve-schema.d.ts +14 -0
- package/dist/validation/resolve-schema.js +105 -0
- package/dist/validation/resolve-schema.js.map +1 -0
- package/dist/validation/schema-helpers.d.ts +164 -0
- package/dist/validation/schema-helpers.js +51 -0
- package/dist/validation/schema-helpers.js.map +1 -0
- package/dist/validation/schema-validator.d.ts +22 -0
- package/dist/validation/schema-validator.js +402 -0
- package/dist/validation/schema-validator.js.map +1 -0
- package/dist/validation/test-schema-setup.d.ts +2 -0
- package/dist/validation/test-schema-setup.js +108 -0
- package/dist/validation/test-schema-setup.js.map +1 -0
- package/dist/validation.d.ts +1 -0
- package/dist/validation.js +9 -0
- package/dist/validation.js.map +1 -0
- package/dist/workflow-builder/connection-utils.d.ts +4 -0
- package/dist/workflow-builder/connection-utils.js +42 -0
- package/dist/workflow-builder/connection-utils.js.map +1 -0
- package/dist/workflow-builder/constants.d.ts +3 -0
- package/dist/workflow-builder/constants.js +7 -0
- package/dist/workflow-builder/constants.js.map +1 -0
- package/dist/workflow-builder/control-flow-builders/if-else.d.ts +2 -0
- package/dist/workflow-builder/control-flow-builders/if-else.js +3 -0
- package/dist/workflow-builder/control-flow-builders/if-else.js.map +1 -0
- package/dist/workflow-builder/control-flow-builders/next-batch.d.ts +2 -0
- package/dist/workflow-builder/control-flow-builders/next-batch.js +7 -0
- package/dist/workflow-builder/control-flow-builders/next-batch.js.map +1 -0
- package/dist/workflow-builder/control-flow-builders/split-in-batches.d.ts +27 -0
- package/dist/workflow-builder/control-flow-builders/split-in-batches.js +268 -0
- package/dist/workflow-builder/control-flow-builders/split-in-batches.js.map +1 -0
- package/dist/workflow-builder/control-flow-builders/switch-case.d.ts +2 -0
- package/dist/workflow-builder/control-flow-builders/switch-case.js +3 -0
- package/dist/workflow-builder/control-flow-builders/switch-case.js.map +1 -0
- package/dist/workflow-builder/layout-utils.d.ts +2 -0
- package/dist/workflow-builder/layout-utils.js +54 -0
- package/dist/workflow-builder/layout-utils.js.map +1 -0
- package/dist/workflow-builder/node-builders/index.d.ts +2 -0
- package/dist/workflow-builder/node-builders/index.js +29 -0
- package/dist/workflow-builder/node-builders/index.js.map +1 -0
- package/dist/workflow-builder/node-builders/node-builder.d.ts +26 -0
- package/dist/workflow-builder/node-builders/node-builder.js +596 -0
- package/dist/workflow-builder/node-builders/node-builder.js.map +1 -0
- package/dist/workflow-builder/node-builders/subnode-builders.d.ts +25 -0
- package/dist/workflow-builder/node-builders/subnode-builders.js +110 -0
- package/dist/workflow-builder/node-builders/subnode-builders.js.map +1 -0
- package/dist/workflow-builder/pin-data-utils.d.ts +5 -0
- package/dist/workflow-builder/pin-data-utils.js +54 -0
- package/dist/workflow-builder/pin-data-utils.js.map +1 -0
- package/dist/workflow-builder/plugins/composite-handlers/branch-handler-utils.d.ts +9 -0
- package/dist/workflow-builder/plugins/composite-handlers/branch-handler-utils.js +162 -0
- package/dist/workflow-builder/plugins/composite-handlers/branch-handler-utils.js.map +1 -0
- package/dist/workflow-builder/plugins/composite-handlers/if-else-handler.d.ts +5 -0
- package/dist/workflow-builder/plugins/composite-handlers/if-else-handler.js +83 -0
- package/dist/workflow-builder/plugins/composite-handlers/if-else-handler.js.map +1 -0
- package/dist/workflow-builder/plugins/composite-handlers/index.d.ts +3 -0
- package/dist/workflow-builder/plugins/composite-handlers/index.js +10 -0
- package/dist/workflow-builder/plugins/composite-handlers/index.js.map +1 -0
- package/dist/workflow-builder/plugins/composite-handlers/split-in-batches-handler.d.ts +15 -0
- package/dist/workflow-builder/plugins/composite-handlers/split-in-batches-handler.js +216 -0
- package/dist/workflow-builder/plugins/composite-handlers/split-in-batches-handler.js.map +1 -0
- package/dist/workflow-builder/plugins/composite-handlers/switch-case-handler.d.ts +5 -0
- package/dist/workflow-builder/plugins/composite-handlers/switch-case-handler.js +91 -0
- package/dist/workflow-builder/plugins/composite-handlers/switch-case-handler.js.map +1 -0
- package/dist/workflow-builder/plugins/defaults.d.ts +2 -0
- package/dist/workflow-builder/plugins/defaults.js +53 -0
- package/dist/workflow-builder/plugins/defaults.js.map +1 -0
- package/dist/workflow-builder/plugins/index.d.ts +3 -0
- package/dist/workflow-builder/plugins/index.js +9 -0
- package/dist/workflow-builder/plugins/index.js.map +1 -0
- package/dist/workflow-builder/plugins/registry.d.ts +22 -0
- package/dist/workflow-builder/plugins/registry.js +98 -0
- package/dist/workflow-builder/plugins/registry.js.map +1 -0
- package/dist/workflow-builder/plugins/serializers/index.d.ts +1 -0
- package/dist/workflow-builder/plugins/serializers/index.js +6 -0
- package/dist/workflow-builder/plugins/serializers/index.js.map +1 -0
- package/dist/workflow-builder/plugins/serializers/json-serializer.d.ts +3 -0
- package/dist/workflow-builder/plugins/serializers/json-serializer.js +140 -0
- package/dist/workflow-builder/plugins/serializers/json-serializer.js.map +1 -0
- package/dist/workflow-builder/plugins/types.d.ts +76 -0
- package/dist/workflow-builder/plugins/types.js +29 -0
- package/dist/workflow-builder/plugins/types.js.map +1 -0
- package/dist/workflow-builder/plugins/validators/agent-validator.d.ts +2 -0
- package/dist/workflow-builder/plugins/validators/agent-validator.js +45 -0
- package/dist/workflow-builder/plugins/validators/agent-validator.js.map +1 -0
- package/dist/workflow-builder/plugins/validators/chain-llm-validator.d.ts +2 -0
- package/dist/workflow-builder/plugins/validators/chain-llm-validator.js +39 -0
- package/dist/workflow-builder/plugins/validators/chain-llm-validator.js.map +1 -0
- package/dist/workflow-builder/plugins/validators/date-method-validator.d.ts +2 -0
- package/dist/workflow-builder/plugins/validators/date-method-validator.js +28 -0
- package/dist/workflow-builder/plugins/validators/date-method-validator.js.map +1 -0
- package/dist/workflow-builder/plugins/validators/disconnected-node-validator.d.ts +2 -0
- package/dist/workflow-builder/plugins/validators/disconnected-node-validator.js +142 -0
- package/dist/workflow-builder/plugins/validators/disconnected-node-validator.js.map +1 -0
- package/dist/workflow-builder/plugins/validators/expression-path-validator.d.ts +2 -0
- package/dist/workflow-builder/plugins/validators/expression-path-validator.js +155 -0
- package/dist/workflow-builder/plugins/validators/expression-path-validator.js.map +1 -0
- package/dist/workflow-builder/plugins/validators/expression-prefix-validator.d.ts +2 -0
- package/dist/workflow-builder/plugins/validators/expression-prefix-validator.js +32 -0
- package/dist/workflow-builder/plugins/validators/expression-prefix-validator.js.map +1 -0
- package/dist/workflow-builder/plugins/validators/from-ai-validator.d.ts +2 -0
- package/dist/workflow-builder/plugins/validators/from-ai-validator.js +30 -0
- package/dist/workflow-builder/plugins/validators/from-ai-validator.js.map +1 -0
- package/dist/workflow-builder/plugins/validators/http-request-validator.d.ts +2 -0
- package/dist/workflow-builder/plugins/validators/http-request-validator.js +55 -0
- package/dist/workflow-builder/plugins/validators/http-request-validator.js.map +1 -0
- package/dist/workflow-builder/plugins/validators/index.d.ts +15 -0
- package/dist/workflow-builder/plugins/validators/index.js +34 -0
- package/dist/workflow-builder/plugins/validators/index.js.map +1 -0
- package/dist/workflow-builder/plugins/validators/max-nodes-validator.d.ts +2 -0
- package/dist/workflow-builder/plugins/validators/max-nodes-validator.js +40 -0
- package/dist/workflow-builder/plugins/validators/max-nodes-validator.js.map +1 -0
- package/dist/workflow-builder/plugins/validators/merge-node-validator.d.ts +2 -0
- package/dist/workflow-builder/plugins/validators/merge-node-validator.js +54 -0
- package/dist/workflow-builder/plugins/validators/merge-node-validator.js.map +1 -0
- package/dist/workflow-builder/plugins/validators/missing-trigger-validator.d.ts +2 -0
- package/dist/workflow-builder/plugins/validators/missing-trigger-validator.js +27 -0
- package/dist/workflow-builder/plugins/validators/missing-trigger-validator.js.map +1 -0
- package/dist/workflow-builder/plugins/validators/no-nodes-validator.d.ts +2 -0
- package/dist/workflow-builder/plugins/validators/no-nodes-validator.js +23 -0
- package/dist/workflow-builder/plugins/validators/no-nodes-validator.js.map +1 -0
- package/dist/workflow-builder/plugins/validators/set-node-validator.d.ts +2 -0
- package/dist/workflow-builder/plugins/validators/set-node-validator.js +41 -0
- package/dist/workflow-builder/plugins/validators/set-node-validator.js.map +1 -0
- package/dist/workflow-builder/plugins/validators/subnode-connection-validator.d.ts +2 -0
- package/dist/workflow-builder/plugins/validators/subnode-connection-validator.js +64 -0
- package/dist/workflow-builder/plugins/validators/subnode-connection-validator.js.map +1 -0
- package/dist/workflow-builder/plugins/validators/tool-node-validator.d.ts +2 -0
- package/dist/workflow-builder/plugins/validators/tool-node-validator.js +37 -0
- package/dist/workflow-builder/plugins/validators/tool-node-validator.js.map +1 -0
- package/dist/workflow-builder/string-utils.d.ts +9 -0
- package/dist/workflow-builder/string-utils.js +237 -0
- package/dist/workflow-builder/string-utils.js.map +1 -0
- package/dist/workflow-builder/subnode-utils.d.ts +2 -0
- package/dist/workflow-builder/subnode-utils.js +180 -0
- package/dist/workflow-builder/subnode-utils.js.map +1 -0
- package/dist/workflow-builder/type-guards.d.ts +15 -0
- package/dist/workflow-builder/type-guards.js +48 -0
- package/dist/workflow-builder/type-guards.js.map +1 -0
- package/dist/workflow-builder/validation-helpers.d.ts +27 -0
- package/dist/workflow-builder/validation-helpers.js +195 -0
- package/dist/workflow-builder/validation-helpers.js.map +1 -0
- package/dist/workflow-builder/workflow-import.d.ts +15 -0
- package/dist/workflow-builder/workflow-import.js +102 -0
- package/dist/workflow-builder/workflow-import.js.map +1 -0
- package/dist/workflow-builder.d.ts +2 -0
- package/dist/workflow-builder.js +636 -0
- package/dist/workflow-builder.js.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,1129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.extractDefaultsForDisplayOptions = extractDefaultsForDisplayOptions;
|
|
4
|
+
exports.mapPropertyToZodSchema = mapPropertyToZodSchema;
|
|
5
|
+
exports.generateSchemaPropertyLine = generateSchemaPropertyLine;
|
|
6
|
+
exports.stripDiscriminatorKeysFromDisplayOptions = stripDiscriminatorKeysFromDisplayOptions;
|
|
7
|
+
exports.mergeDisplayOptions = mergeDisplayOptions;
|
|
8
|
+
exports.mergePropertiesByName = mergePropertiesByName;
|
|
9
|
+
exports.generateConditionalSchemaLine = generateConditionalSchemaLine;
|
|
10
|
+
exports.generateSubnodeConfigSchemaCode = generateSubnodeConfigSchemaCode;
|
|
11
|
+
exports.getSubnodeSchemaImports = getSubnodeSchemaImports;
|
|
12
|
+
exports.generateSingleVersionSchemaFile = generateSingleVersionSchemaFile;
|
|
13
|
+
exports.generateSchemaIndexFile = generateSchemaIndexFile;
|
|
14
|
+
exports.generateDiscriminatorSchemaFile = generateDiscriminatorSchemaFile;
|
|
15
|
+
exports.generateResourceIndexSchemaFile = generateResourceIndexSchemaFile;
|
|
16
|
+
exports.generateSplitVersionIndexSchemaFile = generateSplitVersionIndexSchemaFile;
|
|
17
|
+
exports.planSplitVersionSchemaFiles = planSplitVersionSchemaFiles;
|
|
18
|
+
const generate_types_1 = require("./generate-types");
|
|
19
|
+
const INDENT = ' ';
|
|
20
|
+
const CUSTOM_API_CALL_KEY = '__CUSTOM_API_CALL__';
|
|
21
|
+
function isCustomApiCall(operation) {
|
|
22
|
+
return operation === CUSTOM_API_CALL_KEY;
|
|
23
|
+
}
|
|
24
|
+
const GENERIC_AUTH_TYPE_VALUES = [
|
|
25
|
+
'httpBasicAuth',
|
|
26
|
+
'httpBearerAuth',
|
|
27
|
+
'httpDigestAuth',
|
|
28
|
+
'httpHeaderAuth',
|
|
29
|
+
'httpQueryAuth',
|
|
30
|
+
'httpCustomAuth',
|
|
31
|
+
'oAuth1Api',
|
|
32
|
+
'oAuth2Api',
|
|
33
|
+
];
|
|
34
|
+
const RESERVED_WORDS = new Set([
|
|
35
|
+
'break',
|
|
36
|
+
'case',
|
|
37
|
+
'catch',
|
|
38
|
+
'class',
|
|
39
|
+
'const',
|
|
40
|
+
'continue',
|
|
41
|
+
'debugger',
|
|
42
|
+
'default',
|
|
43
|
+
'delete',
|
|
44
|
+
'do',
|
|
45
|
+
'else',
|
|
46
|
+
'enum',
|
|
47
|
+
'export',
|
|
48
|
+
'extends',
|
|
49
|
+
'false',
|
|
50
|
+
'finally',
|
|
51
|
+
'for',
|
|
52
|
+
'function',
|
|
53
|
+
'if',
|
|
54
|
+
'import',
|
|
55
|
+
'in',
|
|
56
|
+
'instanceof',
|
|
57
|
+
'new',
|
|
58
|
+
'null',
|
|
59
|
+
'return',
|
|
60
|
+
'super',
|
|
61
|
+
'switch',
|
|
62
|
+
'this',
|
|
63
|
+
'throw',
|
|
64
|
+
'true',
|
|
65
|
+
'try',
|
|
66
|
+
'typeof',
|
|
67
|
+
'var',
|
|
68
|
+
'void',
|
|
69
|
+
'while',
|
|
70
|
+
'with',
|
|
71
|
+
'yield',
|
|
72
|
+
]);
|
|
73
|
+
const AI_TYPE_TO_SCHEMA_FIELD = {
|
|
74
|
+
ai_languageModel: {
|
|
75
|
+
fieldName: 'model',
|
|
76
|
+
schemaName: 'languageModelInstanceSchema',
|
|
77
|
+
isArray: false,
|
|
78
|
+
canBeMultiple: true,
|
|
79
|
+
},
|
|
80
|
+
ai_memory: {
|
|
81
|
+
fieldName: 'memory',
|
|
82
|
+
schemaName: 'memoryInstanceSchema',
|
|
83
|
+
isArray: false,
|
|
84
|
+
canBeMultiple: false,
|
|
85
|
+
},
|
|
86
|
+
ai_tool: {
|
|
87
|
+
fieldName: 'tools',
|
|
88
|
+
schemaName: 'toolInstanceSchema',
|
|
89
|
+
isArray: true,
|
|
90
|
+
canBeMultiple: false,
|
|
91
|
+
},
|
|
92
|
+
ai_outputParser: {
|
|
93
|
+
fieldName: 'outputParser',
|
|
94
|
+
schemaName: 'outputParserInstanceSchema',
|
|
95
|
+
isArray: false,
|
|
96
|
+
canBeMultiple: false,
|
|
97
|
+
},
|
|
98
|
+
ai_embedding: {
|
|
99
|
+
fieldName: 'embedding',
|
|
100
|
+
schemaName: 'embeddingInstanceSchema',
|
|
101
|
+
isArray: false,
|
|
102
|
+
canBeMultiple: true,
|
|
103
|
+
},
|
|
104
|
+
ai_vectorStore: {
|
|
105
|
+
fieldName: 'vectorStore',
|
|
106
|
+
schemaName: 'vectorStoreInstanceSchema',
|
|
107
|
+
isArray: false,
|
|
108
|
+
canBeMultiple: false,
|
|
109
|
+
},
|
|
110
|
+
ai_retriever: {
|
|
111
|
+
fieldName: 'retriever',
|
|
112
|
+
schemaName: 'retrieverInstanceSchema',
|
|
113
|
+
isArray: false,
|
|
114
|
+
canBeMultiple: false,
|
|
115
|
+
},
|
|
116
|
+
ai_document: {
|
|
117
|
+
fieldName: 'documentLoader',
|
|
118
|
+
schemaName: 'documentLoaderInstanceSchema',
|
|
119
|
+
isArray: false,
|
|
120
|
+
canBeMultiple: true,
|
|
121
|
+
},
|
|
122
|
+
ai_textSplitter: {
|
|
123
|
+
fieldName: 'textSplitter',
|
|
124
|
+
schemaName: 'textSplitterInstanceSchema',
|
|
125
|
+
isArray: false,
|
|
126
|
+
canBeMultiple: false,
|
|
127
|
+
},
|
|
128
|
+
ai_reranker: {
|
|
129
|
+
fieldName: 'reranker',
|
|
130
|
+
schemaName: 'rerankerInstanceSchema',
|
|
131
|
+
isArray: false,
|
|
132
|
+
canBeMultiple: false,
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
function isPropertyOptional(prop) {
|
|
136
|
+
const hasDefault = 'default' in prop && prop.default !== undefined;
|
|
137
|
+
return !prop.required || hasDefault;
|
|
138
|
+
}
|
|
139
|
+
function hasRequiredSubnodeFields(aiInputTypes) {
|
|
140
|
+
return aiInputTypes.some((input) => input.required && !input.displayOptions);
|
|
141
|
+
}
|
|
142
|
+
function hasConditionalSubnodeFields(aiInputTypes) {
|
|
143
|
+
return aiInputTypes.some((input) => input.displayOptions);
|
|
144
|
+
}
|
|
145
|
+
function hasDisplayOptions(properties) {
|
|
146
|
+
return properties.some((prop) => {
|
|
147
|
+
if (!prop.displayOptions)
|
|
148
|
+
return false;
|
|
149
|
+
const stripped = stripDiscriminatorKeysFromDisplayOptions(prop.displayOptions, ['@version']);
|
|
150
|
+
return stripped !== undefined;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
function toPascalCase(str) {
|
|
154
|
+
return str
|
|
155
|
+
.replace(/[-_]+/g, ' ')
|
|
156
|
+
.replace(/\./g, ' ')
|
|
157
|
+
.split(' ')
|
|
158
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
159
|
+
.join('');
|
|
160
|
+
}
|
|
161
|
+
function toSnakeCase(str) {
|
|
162
|
+
return str
|
|
163
|
+
.replace(/([A-Z])/g, '_$1')
|
|
164
|
+
.toLowerCase()
|
|
165
|
+
.replace(/^_/, '')
|
|
166
|
+
.replace(/[-\s]+/g, '_');
|
|
167
|
+
}
|
|
168
|
+
function formatZodLiteral(value) {
|
|
169
|
+
if (typeof value === 'string') {
|
|
170
|
+
const escaped = value
|
|
171
|
+
.replace(/\\/g, '\\\\')
|
|
172
|
+
.replace(/'/g, "\\'")
|
|
173
|
+
.replace(/\n/g, '\\n')
|
|
174
|
+
.replace(/\r/g, '\\r')
|
|
175
|
+
.replace(/\t/g, '\\t');
|
|
176
|
+
return `'${escaped}'`;
|
|
177
|
+
}
|
|
178
|
+
if (typeof value === 'number' || typeof value === 'boolean') {
|
|
179
|
+
return String(value);
|
|
180
|
+
}
|
|
181
|
+
return JSON.stringify(value);
|
|
182
|
+
}
|
|
183
|
+
function quotePropertyName(name) {
|
|
184
|
+
const needsQuoting = RESERVED_WORDS.has(name) || !/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
185
|
+
if (needsQuoting) {
|
|
186
|
+
return `'${name.replace(/'/g, "\\'")}'`;
|
|
187
|
+
}
|
|
188
|
+
return name;
|
|
189
|
+
}
|
|
190
|
+
function extractDefaultsForDisplayOptions(displayOptions, allProperties) {
|
|
191
|
+
const defaults = {};
|
|
192
|
+
const referencedProps = new Set();
|
|
193
|
+
if (displayOptions.show) {
|
|
194
|
+
for (const key of Object.keys(displayOptions.show)) {
|
|
195
|
+
if (!key.startsWith('@') && !key.startsWith('/')) {
|
|
196
|
+
const baseProp = key.split('.')[0];
|
|
197
|
+
referencedProps.add(baseProp);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (displayOptions.hide) {
|
|
202
|
+
for (const key of Object.keys(displayOptions.hide)) {
|
|
203
|
+
if (!key.startsWith('@') && !key.startsWith('/')) {
|
|
204
|
+
const baseProp = key.split('.')[0];
|
|
205
|
+
referencedProps.add(baseProp);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
for (const propName of referencedProps) {
|
|
210
|
+
const prop = allProperties.find((p) => p.name === propName);
|
|
211
|
+
if (prop && prop.default !== undefined) {
|
|
212
|
+
defaults[propName] = prop.default;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return defaults;
|
|
216
|
+
}
|
|
217
|
+
function generateResourceLocatorZodSchema(prop) {
|
|
218
|
+
if (prop.modes && prop.modes.length > 0) {
|
|
219
|
+
const modeSchema = prop.modes.length === 1
|
|
220
|
+
? `z.literal('${prop.modes[0].name}')`
|
|
221
|
+
: `z.union([${prop.modes.map((m) => `z.literal('${m.name}')`).join(', ')}])`;
|
|
222
|
+
const objectSchema = `z.object({ __rl: z.literal(true), mode: ${modeSchema}, value: z.union([z.string(), z.number()]), cachedResultName: z.string().optional(), cachedResultUrl: z.string().optional() })`;
|
|
223
|
+
return `z.union([${objectSchema}, expressionSchema])`;
|
|
224
|
+
}
|
|
225
|
+
return 'resourceLocatorValueSchema';
|
|
226
|
+
}
|
|
227
|
+
function mapNestedPropertyToZodSchema(prop) {
|
|
228
|
+
const result = mapNestedPropertyToZodSchemaInner(prop);
|
|
229
|
+
if (prop.noDataExpression) {
|
|
230
|
+
return stripExpressionFromZodSchema(result);
|
|
231
|
+
}
|
|
232
|
+
return result;
|
|
233
|
+
}
|
|
234
|
+
function mapNestedPropertyToZodSchemaInner(prop) {
|
|
235
|
+
if (['notice', 'curlImport', 'credentials'].includes(prop.type)) {
|
|
236
|
+
return '';
|
|
237
|
+
}
|
|
238
|
+
if (prop.type === 'resourceLocator') {
|
|
239
|
+
return generateResourceLocatorZodSchema(prop);
|
|
240
|
+
}
|
|
241
|
+
if (prop.type === 'resourceMapper') {
|
|
242
|
+
return 'resourceMapperValueSchema';
|
|
243
|
+
}
|
|
244
|
+
if (prop.typeOptions?.loadOptionsMethod || prop.typeOptions?.loadOptionsDependsOn) {
|
|
245
|
+
if (prop.type === 'multiOptions') {
|
|
246
|
+
return 'z.array(z.string())';
|
|
247
|
+
}
|
|
248
|
+
return 'stringOrExpression';
|
|
249
|
+
}
|
|
250
|
+
switch (prop.type) {
|
|
251
|
+
case 'string':
|
|
252
|
+
case 'dateTime':
|
|
253
|
+
case 'color':
|
|
254
|
+
case 'credentialsSelect':
|
|
255
|
+
return 'stringOrExpression';
|
|
256
|
+
case 'number':
|
|
257
|
+
return 'numberOrExpression';
|
|
258
|
+
case 'boolean':
|
|
259
|
+
return 'booleanOrExpression';
|
|
260
|
+
case 'options':
|
|
261
|
+
if (prop.options && prop.options.length > 0) {
|
|
262
|
+
const literals = prop.options
|
|
263
|
+
.filter((opt) => opt.value !== undefined)
|
|
264
|
+
.map((opt) => `z.literal(${formatZodLiteral(opt.value)})`);
|
|
265
|
+
if (literals.length > 0) {
|
|
266
|
+
return `z.union([${literals.join(', ')}, expressionSchema])`;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return 'stringOrExpression';
|
|
270
|
+
case 'multiOptions':
|
|
271
|
+
if (prop.options && prop.options.length > 0) {
|
|
272
|
+
const literals = prop.options
|
|
273
|
+
.filter((opt) => opt.value !== undefined)
|
|
274
|
+
.map((opt) => `z.literal(${formatZodLiteral(opt.value)})`);
|
|
275
|
+
if (literals.length > 0) {
|
|
276
|
+
return `z.array(z.union([${literals.join(', ')}]))`;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return 'z.array(z.string())';
|
|
280
|
+
case 'json':
|
|
281
|
+
return 'z.union([iDataObjectSchema, z.string()])';
|
|
282
|
+
case 'filter':
|
|
283
|
+
return 'filterValueSchema';
|
|
284
|
+
case 'assignmentCollection':
|
|
285
|
+
return 'assignmentCollectionValueSchema';
|
|
286
|
+
case 'hidden':
|
|
287
|
+
return 'z.unknown()';
|
|
288
|
+
default:
|
|
289
|
+
return 'z.unknown()';
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
function generateFixedCollectionZodSchema(prop) {
|
|
293
|
+
if (!prop.options || prop.options.length === 0) {
|
|
294
|
+
return 'z.record(z.string(), z.unknown())';
|
|
295
|
+
}
|
|
296
|
+
const isMultipleValues = prop.typeOptions?.multipleValues === true;
|
|
297
|
+
const groups = [];
|
|
298
|
+
for (const group of prop.options) {
|
|
299
|
+
if (group.value !== undefined || !group.values) {
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
const groupName = quotePropertyName(group.name);
|
|
303
|
+
const nestedProps = [];
|
|
304
|
+
for (const nestedProp of group.values) {
|
|
305
|
+
if (['notice', 'curlImport', 'credentials'].includes(nestedProp.type)) {
|
|
306
|
+
continue;
|
|
307
|
+
}
|
|
308
|
+
const nestedSchema = mapNestedPropertyToZodSchema(nestedProp);
|
|
309
|
+
if (nestedSchema) {
|
|
310
|
+
const quotedName = quotePropertyName(nestedProp.name);
|
|
311
|
+
nestedProps.push(`${quotedName}: ${nestedSchema}.optional()`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
if (nestedProps.length > 0) {
|
|
315
|
+
const innerSchema = `z.object({ ${nestedProps.join(', ')} })`;
|
|
316
|
+
const groupSchema = isMultipleValues ? `z.array(${innerSchema})` : innerSchema;
|
|
317
|
+
groups.push(`${groupName}: ${groupSchema}.optional()`);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
if (groups.length === 0) {
|
|
321
|
+
return 'z.record(z.string(), z.unknown())';
|
|
322
|
+
}
|
|
323
|
+
return `z.object({ ${groups.join(', ')} })`;
|
|
324
|
+
}
|
|
325
|
+
function generateCollectionZodSchema(prop) {
|
|
326
|
+
if (!prop.options || prop.options.length === 0) {
|
|
327
|
+
return 'z.record(z.string(), z.unknown())';
|
|
328
|
+
}
|
|
329
|
+
const nestedProps = [];
|
|
330
|
+
for (const nestedProp of prop.options) {
|
|
331
|
+
if (nestedProp.values !== undefined) {
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
const asNodeProp = nestedProp;
|
|
335
|
+
if (['notice', 'curlImport', 'credentials'].includes(asNodeProp.type)) {
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
const nestedSchema = mapNestedPropertyToZodSchema(asNodeProp);
|
|
339
|
+
if (nestedSchema) {
|
|
340
|
+
const quotedName = quotePropertyName(nestedProp.name);
|
|
341
|
+
nestedProps.push(`${quotedName}: ${nestedSchema}.optional()`);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (nestedProps.length === 0) {
|
|
345
|
+
return 'z.record(z.string(), z.unknown())';
|
|
346
|
+
}
|
|
347
|
+
return `z.object({ ${nestedProps.join(', ')} })`;
|
|
348
|
+
}
|
|
349
|
+
function mapPropertyToZodSchema(prop) {
|
|
350
|
+
const result = mapPropertyToZodSchemaInner(prop);
|
|
351
|
+
if (prop.noDataExpression) {
|
|
352
|
+
return stripExpressionFromZodSchema(result);
|
|
353
|
+
}
|
|
354
|
+
return result;
|
|
355
|
+
}
|
|
356
|
+
function stripExpressionFromZodSchema(schema) {
|
|
357
|
+
if (schema === 'stringOrExpression')
|
|
358
|
+
return 'z.string()';
|
|
359
|
+
if (schema === 'numberOrExpression')
|
|
360
|
+
return 'z.number()';
|
|
361
|
+
if (schema === 'booleanOrExpression')
|
|
362
|
+
return 'z.boolean()';
|
|
363
|
+
return schema.replace(/,\s*expressionSchema/g, '');
|
|
364
|
+
}
|
|
365
|
+
function mapPropertyToZodSchemaInner(prop) {
|
|
366
|
+
if (prop.type === 'credentialsSelect' && prop.name === 'genericAuthType') {
|
|
367
|
+
const literals = GENERIC_AUTH_TYPE_VALUES.map((v) => `z.literal('${v}')`);
|
|
368
|
+
return `z.union([${literals.join(', ')}, expressionSchema])`;
|
|
369
|
+
}
|
|
370
|
+
if (prop.type === 'resourceLocator') {
|
|
371
|
+
return generateResourceLocatorZodSchema(prop);
|
|
372
|
+
}
|
|
373
|
+
if (prop.type === 'resourceMapper') {
|
|
374
|
+
return 'resourceMapperValueSchema';
|
|
375
|
+
}
|
|
376
|
+
if (prop.typeOptions?.loadOptionsMethod || prop.typeOptions?.loadOptionsDependsOn) {
|
|
377
|
+
switch (prop.type) {
|
|
378
|
+
case 'options':
|
|
379
|
+
return 'stringOrExpression';
|
|
380
|
+
case 'multiOptions':
|
|
381
|
+
return 'z.array(z.string())';
|
|
382
|
+
default:
|
|
383
|
+
return 'stringOrExpression';
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
switch (prop.type) {
|
|
387
|
+
case 'string':
|
|
388
|
+
return 'stringOrExpression';
|
|
389
|
+
case 'number':
|
|
390
|
+
return 'numberOrExpression';
|
|
391
|
+
case 'boolean':
|
|
392
|
+
return 'booleanOrExpression';
|
|
393
|
+
case 'options':
|
|
394
|
+
if (prop.options && prop.options.length > 0) {
|
|
395
|
+
const literals = prop.options
|
|
396
|
+
.filter((opt) => opt.value !== undefined)
|
|
397
|
+
.map((opt) => `z.literal(${formatZodLiteral(opt.value)})`);
|
|
398
|
+
if (literals.length > 0) {
|
|
399
|
+
return `z.union([${literals.join(', ')}, expressionSchema])`;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
return 'stringOrExpression';
|
|
403
|
+
case 'multiOptions':
|
|
404
|
+
if (prop.options && prop.options.length > 0) {
|
|
405
|
+
const literals = prop.options
|
|
406
|
+
.filter((opt) => opt.value !== undefined)
|
|
407
|
+
.map((opt) => `z.literal(${formatZodLiteral(opt.value)})`);
|
|
408
|
+
if (literals.length > 0) {
|
|
409
|
+
return `z.array(z.union([${literals.join(', ')}]))`;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return 'z.array(z.string())';
|
|
413
|
+
case 'json':
|
|
414
|
+
return 'z.union([iDataObjectSchema, z.string()])';
|
|
415
|
+
case 'filter':
|
|
416
|
+
return 'filterValueSchema';
|
|
417
|
+
case 'assignmentCollection':
|
|
418
|
+
return 'assignmentCollectionValueSchema';
|
|
419
|
+
case 'fixedCollection':
|
|
420
|
+
return generateFixedCollectionZodSchema(prop);
|
|
421
|
+
case 'collection':
|
|
422
|
+
return generateCollectionZodSchema(prop);
|
|
423
|
+
case 'dateTime':
|
|
424
|
+
case 'color':
|
|
425
|
+
return 'stringOrExpression';
|
|
426
|
+
case 'hidden':
|
|
427
|
+
return 'z.unknown()';
|
|
428
|
+
case 'notice':
|
|
429
|
+
case 'curlImport':
|
|
430
|
+
case 'credentials':
|
|
431
|
+
return '';
|
|
432
|
+
case 'credentialsSelect':
|
|
433
|
+
return 'stringOrExpression';
|
|
434
|
+
default:
|
|
435
|
+
return 'z.unknown()';
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
function generateSchemaPropertyLine(prop, optional) {
|
|
439
|
+
const zodSchema = mapPropertyToZodSchema(prop);
|
|
440
|
+
if (!zodSchema) {
|
|
441
|
+
return '';
|
|
442
|
+
}
|
|
443
|
+
const propName = quotePropertyName(prop.name);
|
|
444
|
+
const schema = optional ? `${zodSchema}.optional()` : zodSchema;
|
|
445
|
+
return `${INDENT}${propName}: ${schema},`;
|
|
446
|
+
}
|
|
447
|
+
function stripDiscriminatorKeysFromDisplayOptions(displayOptions, discriminatorKeys) {
|
|
448
|
+
const result = {};
|
|
449
|
+
if (displayOptions.show) {
|
|
450
|
+
const cleanedShow = {};
|
|
451
|
+
for (const [key, values] of Object.entries(displayOptions.show)) {
|
|
452
|
+
if (!discriminatorKeys.includes(key)) {
|
|
453
|
+
cleanedShow[key] = values;
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
if (Object.keys(cleanedShow).length > 0) {
|
|
457
|
+
result.show = cleanedShow;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
if (displayOptions.hide) {
|
|
461
|
+
const cleanedHide = {};
|
|
462
|
+
for (const [key, values] of Object.entries(displayOptions.hide)) {
|
|
463
|
+
if (!discriminatorKeys.includes(key)) {
|
|
464
|
+
cleanedHide[key] = values;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
if (Object.keys(cleanedHide).length > 0) {
|
|
468
|
+
result.hide = cleanedHide;
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
if (!result.show && !result.hide) {
|
|
472
|
+
return undefined;
|
|
473
|
+
}
|
|
474
|
+
return result;
|
|
475
|
+
}
|
|
476
|
+
function mergeDisplayOptions(existing, incoming) {
|
|
477
|
+
const merged = { ...existing };
|
|
478
|
+
if (incoming.show) {
|
|
479
|
+
merged.show = merged.show ?? {};
|
|
480
|
+
for (const [key, values] of Object.entries(incoming.show)) {
|
|
481
|
+
const existingValues = merged.show[key] ?? [];
|
|
482
|
+
const combined = [...existingValues];
|
|
483
|
+
for (const val of values) {
|
|
484
|
+
const isDuplicate = combined.some((existingVal) => JSON.stringify(existingVal) === JSON.stringify(val));
|
|
485
|
+
if (!isDuplicate) {
|
|
486
|
+
combined.push(val);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
merged.show[key] = combined;
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
if (incoming.hide) {
|
|
493
|
+
merged.hide = merged.hide ?? {};
|
|
494
|
+
for (const [key, values] of Object.entries(incoming.hide)) {
|
|
495
|
+
const existingValues = merged.hide[key] ?? [];
|
|
496
|
+
const combined = [...existingValues];
|
|
497
|
+
for (const val of values) {
|
|
498
|
+
const isDuplicate = combined.some((existingVal) => JSON.stringify(existingVal) === JSON.stringify(val));
|
|
499
|
+
if (!isDuplicate) {
|
|
500
|
+
combined.push(val);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
merged.hide[key] = combined;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
return merged;
|
|
507
|
+
}
|
|
508
|
+
function mergePropertiesByName(properties) {
|
|
509
|
+
const propsByName = new Map();
|
|
510
|
+
for (const prop of properties) {
|
|
511
|
+
if (['notice', 'curlImport', 'credentials'].includes(prop.type)) {
|
|
512
|
+
continue;
|
|
513
|
+
}
|
|
514
|
+
const existing = propsByName.get(prop.name);
|
|
515
|
+
if (existing) {
|
|
516
|
+
if (prop.displayOptions && existing.displayOptions) {
|
|
517
|
+
existing.displayOptions = mergeDisplayOptions(existing.displayOptions, prop.displayOptions);
|
|
518
|
+
}
|
|
519
|
+
else if (prop.displayOptions && !existing.displayOptions) {
|
|
520
|
+
}
|
|
521
|
+
if ((prop.type === 'collection' || prop.type === 'fixedCollection') &&
|
|
522
|
+
prop.options &&
|
|
523
|
+
existing.options) {
|
|
524
|
+
const existingOptionNames = new Set(existing.options.map((o) => o.name));
|
|
525
|
+
for (const opt of prop.options) {
|
|
526
|
+
if (!existingOptionNames.has(opt.name)) {
|
|
527
|
+
existing.options.push(opt);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
propsByName.set(prop.name, {
|
|
534
|
+
...prop,
|
|
535
|
+
options: prop.options ? [...prop.options] : undefined,
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
return propsByName;
|
|
540
|
+
}
|
|
541
|
+
function generateConditionalSchemaLine(prop, allProperties = []) {
|
|
542
|
+
const zodSchema = mapPropertyToZodSchema(prop);
|
|
543
|
+
if (!zodSchema) {
|
|
544
|
+
return '';
|
|
545
|
+
}
|
|
546
|
+
const propName = quotePropertyName(prop.name);
|
|
547
|
+
const required = !isPropertyOptional(prop);
|
|
548
|
+
const displayOptionsStr = JSON.stringify(prop.displayOptions);
|
|
549
|
+
const defaults = prop.displayOptions
|
|
550
|
+
? extractDefaultsForDisplayOptions(prop.displayOptions, allProperties)
|
|
551
|
+
: {};
|
|
552
|
+
const defaultsStr = Object.keys(defaults).length > 0 ? `, defaults: ${JSON.stringify(defaults)}` : '';
|
|
553
|
+
return `${INDENT}${propName}: resolveSchema({ parameters, schema: ${zodSchema}, required: ${required}, displayOptions: ${displayOptionsStr}${defaultsStr} }),`;
|
|
554
|
+
}
|
|
555
|
+
function generateSubnodeConfigSchemaCode(aiInputTypes, schemaName, allProperties) {
|
|
556
|
+
if (aiInputTypes.length === 0) {
|
|
557
|
+
return null;
|
|
558
|
+
}
|
|
559
|
+
const hasConditional = hasConditionalSubnodeFields(aiInputTypes);
|
|
560
|
+
const lines = [];
|
|
561
|
+
if (hasConditional) {
|
|
562
|
+
lines.push(`function get${schemaName}SubnodeConfigSchema({ parameters, resolveSchema }) {`);
|
|
563
|
+
lines.push(`${INDENT}return z.object({`);
|
|
564
|
+
}
|
|
565
|
+
else {
|
|
566
|
+
lines.push(`const ${schemaName}SubnodeConfigSchema = z.object({`);
|
|
567
|
+
}
|
|
568
|
+
for (const aiInput of aiInputTypes) {
|
|
569
|
+
const fieldInfo = AI_TYPE_TO_SCHEMA_FIELD[aiInput.type];
|
|
570
|
+
if (!fieldInfo) {
|
|
571
|
+
continue;
|
|
572
|
+
}
|
|
573
|
+
let schemaStr;
|
|
574
|
+
if (fieldInfo.isArray) {
|
|
575
|
+
schemaStr = `z.array(${fieldInfo.schemaName})`;
|
|
576
|
+
}
|
|
577
|
+
else if (fieldInfo.canBeMultiple) {
|
|
578
|
+
schemaStr = `z.union([${fieldInfo.schemaName}, z.array(${fieldInfo.schemaName})])`;
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
schemaStr = fieldInfo.schemaName;
|
|
582
|
+
}
|
|
583
|
+
if (aiInput.displayOptions) {
|
|
584
|
+
const displayOptionsStr = JSON.stringify(aiInput.displayOptions);
|
|
585
|
+
const indent = hasConditional ? INDENT.repeat(2) : INDENT;
|
|
586
|
+
let defaultsStr = '';
|
|
587
|
+
if (allProperties) {
|
|
588
|
+
const defaults = extractDefaultsForDisplayOptions(aiInput.displayOptions, allProperties);
|
|
589
|
+
if (Object.keys(defaults).length > 0) {
|
|
590
|
+
defaultsStr = `, defaults: ${JSON.stringify(defaults)}`;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
lines.push(`${indent}${fieldInfo.fieldName}: resolveSchema({ parameters, schema: ${schemaStr}, required: ${aiInput.required}, displayOptions: ${displayOptionsStr}${defaultsStr} }),`);
|
|
594
|
+
}
|
|
595
|
+
else if (!aiInput.required) {
|
|
596
|
+
const indent = hasConditional ? INDENT.repeat(2) : INDENT;
|
|
597
|
+
lines.push(`${indent}${fieldInfo.fieldName}: ${schemaStr}.optional(),`);
|
|
598
|
+
}
|
|
599
|
+
else {
|
|
600
|
+
const indent = hasConditional ? INDENT.repeat(2) : INDENT;
|
|
601
|
+
lines.push(`${indent}${fieldInfo.fieldName}: ${schemaStr},`);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
if (hasConditional) {
|
|
605
|
+
lines.push(`${INDENT}});`);
|
|
606
|
+
lines.push('}');
|
|
607
|
+
lines.push(`exports.get${schemaName}SubnodeConfigSchema = get${schemaName}SubnodeConfigSchema;`);
|
|
608
|
+
}
|
|
609
|
+
else {
|
|
610
|
+
lines.push('});');
|
|
611
|
+
lines.push(`exports.${schemaName}SubnodeConfigSchema = ${schemaName}SubnodeConfigSchema;`);
|
|
612
|
+
}
|
|
613
|
+
return lines.join('\n');
|
|
614
|
+
}
|
|
615
|
+
function getSubnodeSchemaImports(aiInputTypes) {
|
|
616
|
+
const imports = [];
|
|
617
|
+
for (const aiInput of aiInputTypes) {
|
|
618
|
+
const fieldInfo = AI_TYPE_TO_SCHEMA_FIELD[aiInput.type];
|
|
619
|
+
if (fieldInfo && !imports.includes(fieldInfo.schemaName)) {
|
|
620
|
+
imports.push(fieldInfo.schemaName);
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
return imports;
|
|
624
|
+
}
|
|
625
|
+
function generateSingleVersionSchemaFile(node, specificVersion) {
|
|
626
|
+
const filteredProperties = (0, generate_types_1.filterPropertiesForVersion)(node.properties, specificVersion);
|
|
627
|
+
const filteredNode = {
|
|
628
|
+
...node,
|
|
629
|
+
properties: filteredProperties,
|
|
630
|
+
version: specificVersion,
|
|
631
|
+
};
|
|
632
|
+
const aiInputTypes = (0, generate_types_1.extractAIInputTypesFromBuilderHint)(filteredNode);
|
|
633
|
+
const subnodeSchemaImports = getSubnodeSchemaImports(aiInputTypes);
|
|
634
|
+
const hasAiInputs = aiInputTypes.length > 0;
|
|
635
|
+
const needsResolveSchema = hasDisplayOptions(filteredProperties) ||
|
|
636
|
+
(hasAiInputs && hasConditionalSubnodeFields(aiInputTypes));
|
|
637
|
+
const lines = [];
|
|
638
|
+
const helpers = [
|
|
639
|
+
'z',
|
|
640
|
+
'expressionSchema',
|
|
641
|
+
'stringOrExpression',
|
|
642
|
+
'numberOrExpression',
|
|
643
|
+
'booleanOrExpression',
|
|
644
|
+
'resourceLocatorValueSchema',
|
|
645
|
+
'resourceMapperValueSchema',
|
|
646
|
+
'filterValueSchema',
|
|
647
|
+
'assignmentCollectionValueSchema',
|
|
648
|
+
'iDataObjectSchema',
|
|
649
|
+
];
|
|
650
|
+
if (needsResolveSchema) {
|
|
651
|
+
helpers.push('resolveSchema');
|
|
652
|
+
}
|
|
653
|
+
for (const schemaImport of subnodeSchemaImports) {
|
|
654
|
+
helpers.push(schemaImport);
|
|
655
|
+
}
|
|
656
|
+
lines.push('/**');
|
|
657
|
+
lines.push(` * ${node.displayName} Node - Version ${specificVersion} - Zod Validation Schemas`);
|
|
658
|
+
lines.push(' *');
|
|
659
|
+
lines.push(' * These schemas validate node configuration at runtime.');
|
|
660
|
+
lines.push(' * Use .parse() for strict validation or .safeParse() for error handling.');
|
|
661
|
+
lines.push(' *');
|
|
662
|
+
lines.push(' * Schema helpers (z, expressionSchema, etc.) are passed as parameters');
|
|
663
|
+
lines.push(' * by the schema-validator, not imported from external files.');
|
|
664
|
+
lines.push(' *');
|
|
665
|
+
lines.push(' * @generated - CommonJS JavaScript for runtime loading');
|
|
666
|
+
lines.push(' */');
|
|
667
|
+
lines.push('');
|
|
668
|
+
lines.push(`module.exports = function getSchema({ parameters, ${helpers.join(', ')} }) {`);
|
|
669
|
+
if (hasAiInputs && hasConditionalSubnodeFields(aiInputTypes)) {
|
|
670
|
+
lines.push('');
|
|
671
|
+
lines.push(`${INDENT}// Helper function for conditional subnode schema`);
|
|
672
|
+
lines.push(`${INDENT}function getSubnodesSchema() {`);
|
|
673
|
+
lines.push(`${INDENT.repeat(2)}return z.object({`);
|
|
674
|
+
for (const aiInput of aiInputTypes) {
|
|
675
|
+
const fieldInfo = AI_TYPE_TO_SCHEMA_FIELD[aiInput.type];
|
|
676
|
+
if (!fieldInfo)
|
|
677
|
+
continue;
|
|
678
|
+
let schemaStr;
|
|
679
|
+
if (fieldInfo.isArray) {
|
|
680
|
+
schemaStr = `z.array(${fieldInfo.schemaName})`;
|
|
681
|
+
}
|
|
682
|
+
else if (fieldInfo.canBeMultiple) {
|
|
683
|
+
schemaStr = `z.union([${fieldInfo.schemaName}, z.array(${fieldInfo.schemaName})])`;
|
|
684
|
+
}
|
|
685
|
+
else {
|
|
686
|
+
schemaStr = fieldInfo.schemaName;
|
|
687
|
+
}
|
|
688
|
+
if (aiInput.displayOptions) {
|
|
689
|
+
const displayOptionsStr = JSON.stringify(aiInput.displayOptions);
|
|
690
|
+
const defaults = extractDefaultsForDisplayOptions(aiInput.displayOptions, filteredProperties);
|
|
691
|
+
const defaultsStr = Object.keys(defaults).length > 0 ? `, defaults: ${JSON.stringify(defaults)}` : '';
|
|
692
|
+
lines.push(`${INDENT.repeat(3)}${fieldInfo.fieldName}: resolveSchema({ parameters, schema: ${schemaStr}, required: ${aiInput.required}, displayOptions: ${displayOptionsStr}${defaultsStr} }),`);
|
|
693
|
+
}
|
|
694
|
+
else if (!aiInput.required) {
|
|
695
|
+
lines.push(`${INDENT.repeat(3)}${fieldInfo.fieldName}: ${schemaStr}.optional(),`);
|
|
696
|
+
}
|
|
697
|
+
else {
|
|
698
|
+
lines.push(`${INDENT.repeat(3)}${fieldInfo.fieldName}: ${schemaStr},`);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
lines.push(`${INDENT.repeat(2)}}).strict();`);
|
|
702
|
+
lines.push(`${INDENT}}`);
|
|
703
|
+
}
|
|
704
|
+
if (hasAiInputs && !hasConditionalSubnodeFields(aiInputTypes)) {
|
|
705
|
+
lines.push('');
|
|
706
|
+
lines.push(`${INDENT}// Static subnode schema`);
|
|
707
|
+
lines.push(`${INDENT}const subnodesSchema = z.object({`);
|
|
708
|
+
for (const aiInput of aiInputTypes) {
|
|
709
|
+
const fieldInfo = AI_TYPE_TO_SCHEMA_FIELD[aiInput.type];
|
|
710
|
+
if (!fieldInfo)
|
|
711
|
+
continue;
|
|
712
|
+
let schemaStr;
|
|
713
|
+
if (fieldInfo.isArray) {
|
|
714
|
+
schemaStr = `z.array(${fieldInfo.schemaName})`;
|
|
715
|
+
}
|
|
716
|
+
else if (fieldInfo.canBeMultiple) {
|
|
717
|
+
schemaStr = `z.union([${fieldInfo.schemaName}, z.array(${fieldInfo.schemaName})])`;
|
|
718
|
+
}
|
|
719
|
+
else {
|
|
720
|
+
schemaStr = fieldInfo.schemaName;
|
|
721
|
+
}
|
|
722
|
+
if (!aiInput.required) {
|
|
723
|
+
lines.push(`${INDENT.repeat(2)}${fieldInfo.fieldName}: ${schemaStr}.optional(),`);
|
|
724
|
+
}
|
|
725
|
+
else {
|
|
726
|
+
lines.push(`${INDENT.repeat(2)}${fieldInfo.fieldName}: ${schemaStr},`);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
lines.push(`${INDENT}}).strict();`);
|
|
730
|
+
}
|
|
731
|
+
lines.push('');
|
|
732
|
+
lines.push(`${INDENT}// Parameters schema`);
|
|
733
|
+
lines.push(`${INDENT}const parametersSchema = z.object({`);
|
|
734
|
+
const propsByName = mergePropertiesByName(filteredProperties);
|
|
735
|
+
const allPropsArray = Array.from(propsByName.values());
|
|
736
|
+
for (const prop of allPropsArray) {
|
|
737
|
+
if (prop.displayOptions) {
|
|
738
|
+
const strippedDisplayOptions = stripDiscriminatorKeysFromDisplayOptions(prop.displayOptions, [
|
|
739
|
+
'@version',
|
|
740
|
+
]);
|
|
741
|
+
if (strippedDisplayOptions) {
|
|
742
|
+
const propWithStripped = {
|
|
743
|
+
...prop,
|
|
744
|
+
displayOptions: strippedDisplayOptions,
|
|
745
|
+
};
|
|
746
|
+
const propLine = generateConditionalSchemaLine(propWithStripped, allPropsArray);
|
|
747
|
+
if (propLine) {
|
|
748
|
+
lines.push(INDENT + propLine);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
else {
|
|
752
|
+
const propLine = generateSchemaPropertyLine(prop, isPropertyOptional(prop));
|
|
753
|
+
if (propLine) {
|
|
754
|
+
lines.push(INDENT + propLine);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
else {
|
|
759
|
+
const propLine = generateSchemaPropertyLine(prop, isPropertyOptional(prop));
|
|
760
|
+
if (propLine) {
|
|
761
|
+
lines.push(INDENT + propLine);
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
lines.push(`${INDENT}});`);
|
|
766
|
+
lines.push('');
|
|
767
|
+
lines.push(`${INDENT}// Return combined config schema`);
|
|
768
|
+
lines.push(`${INDENT}return z.object({`);
|
|
769
|
+
lines.push(`${INDENT.repeat(2)}parameters: parametersSchema.optional(),`);
|
|
770
|
+
if (hasAiInputs) {
|
|
771
|
+
const subnodesOptional = !hasRequiredSubnodeFields(aiInputTypes);
|
|
772
|
+
if (hasConditionalSubnodeFields(aiInputTypes)) {
|
|
773
|
+
lines.push(`${INDENT.repeat(2)}subnodes: getSubnodesSchema()${subnodesOptional ? '.optional()' : ''},`);
|
|
774
|
+
}
|
|
775
|
+
else {
|
|
776
|
+
lines.push(`${INDENT.repeat(2)}subnodes: subnodesSchema${subnodesOptional ? '.optional()' : ''},`);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
lines.push(`${INDENT}});`);
|
|
780
|
+
lines.push('};');
|
|
781
|
+
return lines.join('\n');
|
|
782
|
+
}
|
|
783
|
+
function generateSchemaIndexFile(node, versions) {
|
|
784
|
+
const sortedVersions = [...versions].sort((a, b) => b - a);
|
|
785
|
+
const lines = [];
|
|
786
|
+
lines.push('/**');
|
|
787
|
+
lines.push(` * ${node.displayName} Node Schemas`);
|
|
788
|
+
lines.push(' *');
|
|
789
|
+
lines.push(' * Re-exports all version-specific Zod validation schemas.');
|
|
790
|
+
lines.push(' */');
|
|
791
|
+
lines.push('');
|
|
792
|
+
for (const version of sortedVersions) {
|
|
793
|
+
const fileName = `v${String(version).replace('.', '')}`;
|
|
794
|
+
lines.push(`export * from './${fileName}.schema';`);
|
|
795
|
+
}
|
|
796
|
+
return lines.join('\n');
|
|
797
|
+
}
|
|
798
|
+
function generateDiscriminatorSchemaFile(node, version, combo, props, _importDepth, aiInputTypes = []) {
|
|
799
|
+
const hasAiInputs = aiInputTypes.length > 0;
|
|
800
|
+
const discriminatorKeys = [
|
|
801
|
+
...Object.keys(combo).filter((k) => combo[k] !== undefined),
|
|
802
|
+
'@version',
|
|
803
|
+
];
|
|
804
|
+
const hasRemainingDisplayOptions = props.some((prop) => {
|
|
805
|
+
if (!prop.displayOptions)
|
|
806
|
+
return false;
|
|
807
|
+
const stripped = stripDiscriminatorKeysFromDisplayOptions(prop.displayOptions, discriminatorKeys);
|
|
808
|
+
return stripped !== undefined;
|
|
809
|
+
});
|
|
810
|
+
const hasConditionalAiInputs = hasAiInputs && hasConditionalSubnodeFields(aiInputTypes);
|
|
811
|
+
const lines = [];
|
|
812
|
+
const comboDesc = Object.entries(combo)
|
|
813
|
+
.filter(([_, v]) => v !== undefined)
|
|
814
|
+
.map(([k, v]) => `${k}=${v}`)
|
|
815
|
+
.join(', ');
|
|
816
|
+
const helpers = [
|
|
817
|
+
'z',
|
|
818
|
+
'expressionSchema',
|
|
819
|
+
'stringOrExpression',
|
|
820
|
+
'numberOrExpression',
|
|
821
|
+
'booleanOrExpression',
|
|
822
|
+
'resourceLocatorValueSchema',
|
|
823
|
+
'resourceMapperValueSchema',
|
|
824
|
+
'filterValueSchema',
|
|
825
|
+
'assignmentCollectionValueSchema',
|
|
826
|
+
'iDataObjectSchema',
|
|
827
|
+
];
|
|
828
|
+
if (hasRemainingDisplayOptions || hasConditionalAiInputs) {
|
|
829
|
+
helpers.push('resolveSchema');
|
|
830
|
+
}
|
|
831
|
+
if (hasAiInputs) {
|
|
832
|
+
const subnodeImports = getSubnodeSchemaImports(aiInputTypes);
|
|
833
|
+
for (const schemaImport of subnodeImports) {
|
|
834
|
+
helpers.push(schemaImport);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
lines.push('/**');
|
|
838
|
+
lines.push(` * ${node.displayName} Node - Version ${version} - Zod Schema`);
|
|
839
|
+
lines.push(` * Discriminator: ${comboDesc}`);
|
|
840
|
+
lines.push(' *');
|
|
841
|
+
lines.push(' * Use .parse() for strict validation or .safeParse() for error handling.');
|
|
842
|
+
lines.push(' *');
|
|
843
|
+
lines.push(' * Schema helpers (z, expressionSchema, etc.) are passed as parameters');
|
|
844
|
+
lines.push(' * by the schema-validator, not imported from external files.');
|
|
845
|
+
lines.push(' *');
|
|
846
|
+
lines.push(' * @generated - CommonJS JavaScript for runtime loading');
|
|
847
|
+
lines.push(' */');
|
|
848
|
+
lines.push('');
|
|
849
|
+
lines.push(`module.exports = function getSchema({ parameters, ${helpers.join(', ')} }) {`);
|
|
850
|
+
if (hasConditionalAiInputs) {
|
|
851
|
+
lines.push('');
|
|
852
|
+
lines.push(`${INDENT}// Helper function for conditional subnode schema`);
|
|
853
|
+
lines.push(`${INDENT}function getSubnodesSchema() {`);
|
|
854
|
+
lines.push(`${INDENT.repeat(2)}return z.object({`);
|
|
855
|
+
for (const aiInput of aiInputTypes) {
|
|
856
|
+
const fieldInfo = AI_TYPE_TO_SCHEMA_FIELD[aiInput.type];
|
|
857
|
+
if (!fieldInfo)
|
|
858
|
+
continue;
|
|
859
|
+
let schemaStr;
|
|
860
|
+
if (fieldInfo.isArray) {
|
|
861
|
+
schemaStr = `z.array(${fieldInfo.schemaName})`;
|
|
862
|
+
}
|
|
863
|
+
else if (fieldInfo.canBeMultiple) {
|
|
864
|
+
schemaStr = `z.union([${fieldInfo.schemaName}, z.array(${fieldInfo.schemaName})])`;
|
|
865
|
+
}
|
|
866
|
+
else {
|
|
867
|
+
schemaStr = fieldInfo.schemaName;
|
|
868
|
+
}
|
|
869
|
+
if (aiInput.displayOptions) {
|
|
870
|
+
const displayOptionsStr = JSON.stringify(aiInput.displayOptions);
|
|
871
|
+
const defaults = extractDefaultsForDisplayOptions(aiInput.displayOptions, props);
|
|
872
|
+
const defaultsStr = Object.keys(defaults).length > 0 ? `, defaults: ${JSON.stringify(defaults)}` : '';
|
|
873
|
+
lines.push(`${INDENT.repeat(3)}${fieldInfo.fieldName}: resolveSchema({ parameters, schema: ${schemaStr}, required: ${aiInput.required}, displayOptions: ${displayOptionsStr}${defaultsStr} }),`);
|
|
874
|
+
}
|
|
875
|
+
else if (!aiInput.required) {
|
|
876
|
+
lines.push(`${INDENT.repeat(3)}${fieldInfo.fieldName}: ${schemaStr}.optional(),`);
|
|
877
|
+
}
|
|
878
|
+
else {
|
|
879
|
+
lines.push(`${INDENT.repeat(3)}${fieldInfo.fieldName}: ${schemaStr},`);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
lines.push(`${INDENT.repeat(2)}}).strict();`);
|
|
883
|
+
lines.push(`${INDENT}}`);
|
|
884
|
+
}
|
|
885
|
+
if (hasAiInputs && !hasConditionalAiInputs) {
|
|
886
|
+
lines.push('');
|
|
887
|
+
lines.push(`${INDENT}// Static subnode schema`);
|
|
888
|
+
lines.push(`${INDENT}const subnodesSchema = z.object({`);
|
|
889
|
+
for (const aiInput of aiInputTypes) {
|
|
890
|
+
const fieldInfo = AI_TYPE_TO_SCHEMA_FIELD[aiInput.type];
|
|
891
|
+
if (!fieldInfo)
|
|
892
|
+
continue;
|
|
893
|
+
let schemaStr;
|
|
894
|
+
if (fieldInfo.isArray) {
|
|
895
|
+
schemaStr = `z.array(${fieldInfo.schemaName})`;
|
|
896
|
+
}
|
|
897
|
+
else if (fieldInfo.canBeMultiple) {
|
|
898
|
+
schemaStr = `z.union([${fieldInfo.schemaName}, z.array(${fieldInfo.schemaName})])`;
|
|
899
|
+
}
|
|
900
|
+
else {
|
|
901
|
+
schemaStr = fieldInfo.schemaName;
|
|
902
|
+
}
|
|
903
|
+
if (!aiInput.required) {
|
|
904
|
+
lines.push(`${INDENT.repeat(2)}${fieldInfo.fieldName}: ${schemaStr}.optional(),`);
|
|
905
|
+
}
|
|
906
|
+
else {
|
|
907
|
+
lines.push(`${INDENT.repeat(2)}${fieldInfo.fieldName}: ${schemaStr},`);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
lines.push(`${INDENT}}).strict();`);
|
|
911
|
+
}
|
|
912
|
+
lines.push('');
|
|
913
|
+
lines.push(`${INDENT}return z.object({`);
|
|
914
|
+
lines.push(`${INDENT.repeat(2)}parameters: z.object({`);
|
|
915
|
+
for (const [key, value] of Object.entries(combo)) {
|
|
916
|
+
if (value !== undefined) {
|
|
917
|
+
const discProp = node.properties?.find((p) => p.name === key);
|
|
918
|
+
const hasMatchingDefault = discProp?.default === value;
|
|
919
|
+
if (hasMatchingDefault) {
|
|
920
|
+
lines.push(`${INDENT.repeat(3)}${key}: z.literal('${value}').default('${value}'),`);
|
|
921
|
+
}
|
|
922
|
+
else {
|
|
923
|
+
lines.push(`${INDENT.repeat(3)}${key}: z.literal('${value}'),`);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
const propsByName = mergePropertiesByName(props);
|
|
928
|
+
const allPropsArray = Array.from(propsByName.values());
|
|
929
|
+
for (const prop of allPropsArray) {
|
|
930
|
+
if (prop.displayOptions) {
|
|
931
|
+
const strippedDisplayOptions = stripDiscriminatorKeysFromDisplayOptions(prop.displayOptions, discriminatorKeys);
|
|
932
|
+
if (strippedDisplayOptions) {
|
|
933
|
+
const propWithStrippedOptions = {
|
|
934
|
+
...prop,
|
|
935
|
+
displayOptions: strippedDisplayOptions,
|
|
936
|
+
};
|
|
937
|
+
const propLine = generateConditionalSchemaLine(propWithStrippedOptions, allPropsArray);
|
|
938
|
+
if (propLine) {
|
|
939
|
+
lines.push(INDENT.repeat(2) + propLine);
|
|
940
|
+
}
|
|
941
|
+
}
|
|
942
|
+
else {
|
|
943
|
+
const propLine = generateSchemaPropertyLine(prop, isPropertyOptional(prop));
|
|
944
|
+
if (propLine) {
|
|
945
|
+
lines.push(INDENT.repeat(2) + propLine);
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
else {
|
|
950
|
+
const propLine = generateSchemaPropertyLine(prop, isPropertyOptional(prop));
|
|
951
|
+
if (propLine) {
|
|
952
|
+
lines.push(INDENT.repeat(2) + propLine);
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
lines.push(`${INDENT.repeat(2)}}).optional(),`);
|
|
957
|
+
if (hasAiInputs) {
|
|
958
|
+
const subnodesOptional = !hasRequiredSubnodeFields(aiInputTypes);
|
|
959
|
+
if (hasConditionalAiInputs) {
|
|
960
|
+
lines.push(`${INDENT.repeat(2)}subnodes: getSubnodesSchema()${subnodesOptional ? '.optional()' : ''},`);
|
|
961
|
+
}
|
|
962
|
+
else {
|
|
963
|
+
lines.push(`${INDENT.repeat(2)}subnodes: subnodesSchema${subnodesOptional ? '.optional()' : ''},`);
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
lines.push(`${INDENT}});`);
|
|
967
|
+
lines.push('};');
|
|
968
|
+
return lines.join('\n');
|
|
969
|
+
}
|
|
970
|
+
function generateResourceIndexSchemaFile(node, _version, resource, operations) {
|
|
971
|
+
const lines = [];
|
|
972
|
+
lines.push('/**');
|
|
973
|
+
lines.push(` * ${node.displayName} - ${toPascalCase(resource)} Resource - Zod Schema Factory`);
|
|
974
|
+
lines.push(' * Exports a factory that unions all operation schemas for this resource.');
|
|
975
|
+
lines.push(' *');
|
|
976
|
+
lines.push(' * Schema helpers (z, expressionSchema, etc.) are passed as parameters');
|
|
977
|
+
lines.push(' * by the schema-validator, not imported from external files.');
|
|
978
|
+
lines.push(' *');
|
|
979
|
+
lines.push(' * @generated - CommonJS JavaScript for runtime loading');
|
|
980
|
+
lines.push(' */');
|
|
981
|
+
lines.push('');
|
|
982
|
+
for (const op of operations.sort()) {
|
|
983
|
+
const fileName = `operation_${toSnakeCase(op)}.schema`;
|
|
984
|
+
const importName = `get${toPascalCase(op)}Schema`;
|
|
985
|
+
lines.push(`const ${importName} = require('./${fileName}');`);
|
|
986
|
+
}
|
|
987
|
+
lines.push('');
|
|
988
|
+
const operationProp = node.properties.find((p) => p.name === 'operation');
|
|
989
|
+
const operationDefault = operationProp?.default;
|
|
990
|
+
lines.push('module.exports = function getSchema(helpers) {');
|
|
991
|
+
lines.push(`${INDENT}const { parameters, z } = helpers;`);
|
|
992
|
+
if (operationDefault !== undefined) {
|
|
993
|
+
const defaultValueStr = typeof operationDefault === 'string'
|
|
994
|
+
? `'${operationDefault}'`
|
|
995
|
+
: JSON.stringify(operationDefault);
|
|
996
|
+
lines.push(`${INDENT}// Apply operation default if not set`);
|
|
997
|
+
lines.push(`${INDENT}const effectiveParams = parameters.operation === undefined ? { ...parameters, operation: ${defaultValueStr} } : parameters;`);
|
|
998
|
+
}
|
|
999
|
+
const paramsVar = operationDefault !== undefined ? 'effectiveParams' : 'parameters';
|
|
1000
|
+
const helpersArg = operationDefault !== undefined ? `{ ...helpers, parameters: ${paramsVar} }` : 'helpers';
|
|
1001
|
+
if (operations.length === 1) {
|
|
1002
|
+
const importName = `get${toPascalCase(operations[0])}Schema`;
|
|
1003
|
+
lines.push(`${INDENT}return ${importName}(${helpersArg});`);
|
|
1004
|
+
}
|
|
1005
|
+
else {
|
|
1006
|
+
lines.push(`${INDENT}return z.union([`);
|
|
1007
|
+
for (const op of operations.sort()) {
|
|
1008
|
+
const importName = `get${toPascalCase(op)}Schema`;
|
|
1009
|
+
lines.push(`${INDENT.repeat(2)}${importName}(${helpersArg}),`);
|
|
1010
|
+
}
|
|
1011
|
+
lines.push(`${INDENT}]);`);
|
|
1012
|
+
}
|
|
1013
|
+
lines.push('};');
|
|
1014
|
+
return lines.join('\n');
|
|
1015
|
+
}
|
|
1016
|
+
function generateSplitVersionIndexSchemaFile(node, version, tree) {
|
|
1017
|
+
const lines = [];
|
|
1018
|
+
lines.push('/**');
|
|
1019
|
+
lines.push(` * ${node.displayName} Node - Version ${version} - Zod Schema Factory`);
|
|
1020
|
+
lines.push(' * Exports a factory that unions all discriminator schemas.');
|
|
1021
|
+
lines.push(' *');
|
|
1022
|
+
lines.push(' * Schema helpers (z, expressionSchema, etc.) are passed as parameters');
|
|
1023
|
+
lines.push(' * by the schema-validator, not imported from external files.');
|
|
1024
|
+
lines.push(' *');
|
|
1025
|
+
lines.push(' * @generated - CommonJS JavaScript for runtime loading');
|
|
1026
|
+
lines.push(' */');
|
|
1027
|
+
lines.push('');
|
|
1028
|
+
const importNames = [];
|
|
1029
|
+
let discriminatorDefault;
|
|
1030
|
+
if (tree.type === 'resource_operation' && tree.resources) {
|
|
1031
|
+
for (const [resource] of tree.resources) {
|
|
1032
|
+
const resourceDir = `resource_${toSnakeCase(resource)}`;
|
|
1033
|
+
const importName = `get${toPascalCase(resource)}Schema`;
|
|
1034
|
+
importNames.push(importName);
|
|
1035
|
+
lines.push(`const ${importName} = require('./${resourceDir}/index.schema');`);
|
|
1036
|
+
}
|
|
1037
|
+
const resourceProp = node.properties.find((p) => p.name === 'resource');
|
|
1038
|
+
if (resourceProp?.default !== undefined) {
|
|
1039
|
+
discriminatorDefault = { name: 'resource', value: resourceProp.default };
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
else if (tree.type === 'single' && tree.discriminatorName && tree.discriminatorValues) {
|
|
1043
|
+
const discName = tree.discriminatorName;
|
|
1044
|
+
for (const value of tree.discriminatorValues.sort()) {
|
|
1045
|
+
const fileName = `${discName}_${toSnakeCase(value)}.schema`;
|
|
1046
|
+
const importName = `get${toPascalCase(value)}Schema`;
|
|
1047
|
+
importNames.push(importName);
|
|
1048
|
+
lines.push(`const ${importName} = require('./${fileName}');`);
|
|
1049
|
+
}
|
|
1050
|
+
const discProp = node.properties.find((p) => p.name === discName);
|
|
1051
|
+
if (discProp?.default !== undefined) {
|
|
1052
|
+
discriminatorDefault = { name: discName, value: discProp.default };
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
lines.push('');
|
|
1056
|
+
lines.push('module.exports = function getSchema(helpers) {');
|
|
1057
|
+
lines.push(`${INDENT}const { parameters, z } = helpers;`);
|
|
1058
|
+
if (discriminatorDefault) {
|
|
1059
|
+
const defaultValueStr = typeof discriminatorDefault.value === 'string'
|
|
1060
|
+
? `'${discriminatorDefault.value}'`
|
|
1061
|
+
: JSON.stringify(discriminatorDefault.value);
|
|
1062
|
+
lines.push(`${INDENT}// Apply discriminator default if not set`);
|
|
1063
|
+
lines.push(`${INDENT}const effectiveParams = parameters.${discriminatorDefault.name} === undefined ? { ...parameters, ${discriminatorDefault.name}: ${defaultValueStr} } : parameters;`);
|
|
1064
|
+
}
|
|
1065
|
+
const paramsVar = discriminatorDefault ? 'effectiveParams' : 'parameters';
|
|
1066
|
+
const helpersArg = discriminatorDefault ? `{ ...helpers, parameters: ${paramsVar} }` : 'helpers';
|
|
1067
|
+
if (importNames.length === 1) {
|
|
1068
|
+
lines.push(`${INDENT}return ${importNames[0]}(${helpersArg});`);
|
|
1069
|
+
}
|
|
1070
|
+
else if (importNames.length > 1) {
|
|
1071
|
+
lines.push(`${INDENT}return z.union([`);
|
|
1072
|
+
for (const importName of importNames) {
|
|
1073
|
+
lines.push(`${INDENT.repeat(2)}${importName}(${helpersArg}),`);
|
|
1074
|
+
}
|
|
1075
|
+
lines.push(`${INDENT}]);`);
|
|
1076
|
+
}
|
|
1077
|
+
else {
|
|
1078
|
+
lines.push(`${INDENT}return z.object({});`);
|
|
1079
|
+
}
|
|
1080
|
+
lines.push('};');
|
|
1081
|
+
return lines.join('\n');
|
|
1082
|
+
}
|
|
1083
|
+
function planSplitVersionSchemaFiles(node, version) {
|
|
1084
|
+
const files = new Map();
|
|
1085
|
+
const combinations = (0, generate_types_1.extractDiscriminatorCombinations)(node);
|
|
1086
|
+
const tree = (0, generate_types_1.buildDiscriminatorTree)(combinations);
|
|
1087
|
+
const versionFilteredNode = {
|
|
1088
|
+
...node,
|
|
1089
|
+
properties: (0, generate_types_1.filterPropertiesForVersion)(node.properties, version),
|
|
1090
|
+
version,
|
|
1091
|
+
};
|
|
1092
|
+
if (tree.type === 'resource_operation' && tree.resources) {
|
|
1093
|
+
for (const [resource, operations] of tree.resources) {
|
|
1094
|
+
const resourceDir = `resource_${toSnakeCase(resource)}`;
|
|
1095
|
+
for (const operation of operations) {
|
|
1096
|
+
if (isCustomApiCall(operation))
|
|
1097
|
+
continue;
|
|
1098
|
+
const combo = { resource, operation };
|
|
1099
|
+
const versionFilteredProps = (0, generate_types_1.filterPropertiesForVersion)(node.properties, version);
|
|
1100
|
+
const nodeForCombination = { ...node, properties: versionFilteredProps };
|
|
1101
|
+
const props = (0, generate_types_1.getPropertiesForCombination)(nodeForCombination, combo);
|
|
1102
|
+
const fileName = `operation_${toSnakeCase(operation)}.schema.js`;
|
|
1103
|
+
const filePath = `${resourceDir}/${fileName}`;
|
|
1104
|
+
const comboAiInputTypes = (0, generate_types_1.extractAIInputTypesFromBuilderHint)(versionFilteredNode, combo);
|
|
1105
|
+
const content = generateDiscriminatorSchemaFile(node, version, combo, props, 5, comboAiInputTypes);
|
|
1106
|
+
files.set(filePath, content);
|
|
1107
|
+
}
|
|
1108
|
+
const filteredOperations = operations.filter((op) => !isCustomApiCall(op));
|
|
1109
|
+
const resourceIndexContent = generateResourceIndexSchemaFile(node, version, resource, filteredOperations);
|
|
1110
|
+
files.set(`${resourceDir}/index.schema.js`, resourceIndexContent);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
else if (tree.type === 'single' && tree.discriminatorName && tree.discriminatorValues) {
|
|
1114
|
+
const discName = tree.discriminatorName;
|
|
1115
|
+
for (const value of tree.discriminatorValues) {
|
|
1116
|
+
const combo = { [discName]: value };
|
|
1117
|
+
const versionFilteredProps = (0, generate_types_1.filterPropertiesForVersion)(node.properties, version);
|
|
1118
|
+
const nodeForCombination = { ...node, properties: versionFilteredProps };
|
|
1119
|
+
const props = (0, generate_types_1.getPropertiesForCombination)(nodeForCombination, combo);
|
|
1120
|
+
const fileName = `${discName}_${toSnakeCase(value)}.schema.js`;
|
|
1121
|
+
const comboAiInputTypes = (0, generate_types_1.extractAIInputTypesFromBuilderHint)(versionFilteredNode, combo);
|
|
1122
|
+
const content = generateDiscriminatorSchemaFile(node, version, combo, props, 4, comboAiInputTypes);
|
|
1123
|
+
files.set(fileName, content);
|
|
1124
|
+
}
|
|
1125
|
+
}
|
|
1126
|
+
files.set('index.schema.js', generateSplitVersionIndexSchemaFile(node, version, tree));
|
|
1127
|
+
return files;
|
|
1128
|
+
}
|
|
1129
|
+
//# sourceMappingURL=generate-zod-schemas.js.map
|