@n8n/workflow-sdk 0.14.0 → 0.15.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/dist/build.tsbuildinfo +1 -1
- package/dist/codegen/emit-instance-ai.d.ts +9 -0
- package/dist/codegen/emit-instance-ai.js +139 -0
- package/dist/codegen/emit-instance-ai.js.map +1 -0
- package/dist/codegen/index.d.ts +1 -0
- package/dist/codegen/index.js +3 -1
- package/dist/codegen/index.js.map +1 -1
- package/dist/examples-loader.d.ts +10 -0
- package/dist/examples-loader.js +108 -0
- package/dist/examples-loader.js.map +1 -0
- package/dist/examples-zip.d.ts +5 -0
- package/dist/examples-zip.js +99 -0
- package/dist/examples-zip.js.map +1 -0
- package/dist/generate-types/generate-types.d.ts +7 -0
- package/dist/generate-types/generate-types.js +70 -15
- package/dist/generate-types/generate-types.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -2
- package/dist/index.js.map +1 -1
- package/dist/prompts/best-practices/guides/triage.js +4 -4
- package/dist/prompts/node-selection/ai-nodes.d.ts +0 -1
- package/dist/prompts/node-selection/ai-nodes.js +1 -20
- package/dist/prompts/node-selection/ai-nodes.js.map +1 -1
- package/dist/prompts/node-selection/index.d.ts +2 -3
- package/dist/prompts/node-selection/index.js +1 -5
- package/dist/prompts/node-selection/index.js.map +1 -1
- package/dist/prompts/node-selection/use-case-patterns.d.ts +0 -1
- package/dist/prompts/node-selection/use-case-patterns.js +1 -9
- package/dist/prompts/node-selection/use-case-patterns.js.map +1 -1
- package/dist/prompts/sdk-reference/workflow-patterns.d.ts +1 -1
- package/dist/prompts/sdk-reference/workflow-patterns.js +5 -4
- package/dist/prompts/sdk-reference/workflow-patterns.js.map +1 -1
- package/dist/validation/index.d.ts +1 -1
- package/dist/validation/index.js +51 -0
- package/dist/validation/index.js.map +1 -1
- package/examples/manifest.json +3491 -0
- package/examples/templates.zip +0 -0
- package/package.json +19 -6
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { WorkflowJSON } from '../types/base';
|
|
2
|
+
export declare const SDK_FUNCTIONS: readonly ["workflow", "trigger", "node", "sticky", "placeholder", "merge", "ifElse", "switchCase", "newCredential", "languageModel", "memory", "tool", "outputParser", "embedding", "embeddings", "vectorStore", "retriever", "documentLoader", "textSplitter", "fromAi", "splitInBatches", "nextBatch", "expr"];
|
|
3
|
+
export interface EmitInstanceAiOptions {
|
|
4
|
+
jsdocHeader?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function emitInstanceAi(workflow: WorkflowJSON, opts?: EmitInstanceAiOptions): string;
|
|
7
|
+
export declare function buildImports(body: string): string;
|
|
8
|
+
export declare function hoistSharedCredentials(body: string): string;
|
|
9
|
+
export declare function uniqueConstName(credName: string, used: Set<string>): string;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SDK_FUNCTIONS = void 0;
|
|
4
|
+
exports.emitInstanceAi = emitInstanceAi;
|
|
5
|
+
exports.buildImports = buildImports;
|
|
6
|
+
exports.hoistSharedCredentials = hoistSharedCredentials;
|
|
7
|
+
exports.uniqueConstName = uniqueConstName;
|
|
8
|
+
const code_generator_1 = require("./code-generator");
|
|
9
|
+
const composite_builder_1 = require("./composite-builder");
|
|
10
|
+
const graph_annotator_1 = require("./graph-annotator");
|
|
11
|
+
const semantic_graph_1 = require("./semantic-graph");
|
|
12
|
+
function generateWorkflowCode(workflow) {
|
|
13
|
+
const graph = (0, semantic_graph_1.buildSemanticGraph)(workflow);
|
|
14
|
+
(0, graph_annotator_1.annotateGraph)(graph);
|
|
15
|
+
const tree = (0, composite_builder_1.buildCompositeTree)(graph);
|
|
16
|
+
return (0, code_generator_1.generateCode)(tree, workflow, graph, {});
|
|
17
|
+
}
|
|
18
|
+
exports.SDK_FUNCTIONS = [
|
|
19
|
+
'workflow',
|
|
20
|
+
'trigger',
|
|
21
|
+
'node',
|
|
22
|
+
'sticky',
|
|
23
|
+
'placeholder',
|
|
24
|
+
'merge',
|
|
25
|
+
'ifElse',
|
|
26
|
+
'switchCase',
|
|
27
|
+
'newCredential',
|
|
28
|
+
'languageModel',
|
|
29
|
+
'memory',
|
|
30
|
+
'tool',
|
|
31
|
+
'outputParser',
|
|
32
|
+
'embedding',
|
|
33
|
+
'embeddings',
|
|
34
|
+
'vectorStore',
|
|
35
|
+
'retriever',
|
|
36
|
+
'documentLoader',
|
|
37
|
+
'textSplitter',
|
|
38
|
+
'fromAi',
|
|
39
|
+
'splitInBatches',
|
|
40
|
+
'nextBatch',
|
|
41
|
+
'expr',
|
|
42
|
+
];
|
|
43
|
+
function emitInstanceAi(workflow, opts = {}) {
|
|
44
|
+
const body = generateWorkflowCode(workflow);
|
|
45
|
+
const dedupedBody = hoistSharedCredentials(body);
|
|
46
|
+
const importLine = buildImports(dedupedBody);
|
|
47
|
+
const sections = [];
|
|
48
|
+
if (opts.jsdocHeader)
|
|
49
|
+
sections.push(opts.jsdocHeader.trim());
|
|
50
|
+
if (importLine)
|
|
51
|
+
sections.push(importLine);
|
|
52
|
+
sections.push(dedupedBody);
|
|
53
|
+
return sections.join('\n\n') + '\n';
|
|
54
|
+
}
|
|
55
|
+
function buildImports(body) {
|
|
56
|
+
const used = [];
|
|
57
|
+
for (const fn of exports.SDK_FUNCTIONS) {
|
|
58
|
+
if (containsCall(body, fn))
|
|
59
|
+
used.push(fn);
|
|
60
|
+
}
|
|
61
|
+
if (used.length === 0)
|
|
62
|
+
return '';
|
|
63
|
+
return `import { ${used.join(', ')} } from '@n8n/workflow-sdk';`;
|
|
64
|
+
}
|
|
65
|
+
function containsCall(body, fnName) {
|
|
66
|
+
const pattern = new RegExp(`\\b${fnName}\\(`);
|
|
67
|
+
return pattern.test(body);
|
|
68
|
+
}
|
|
69
|
+
function hoistSharedCredentials(body) {
|
|
70
|
+
const callPattern = /newCredential\('([^'\\]*)',\s*'([^'\\]*)'\)/g;
|
|
71
|
+
const groups = new Map();
|
|
72
|
+
let m;
|
|
73
|
+
while ((m = callPattern.exec(body)) !== null) {
|
|
74
|
+
const [match, name, id] = m;
|
|
75
|
+
const key = `${name}::${id}`;
|
|
76
|
+
const existing = groups.get(key);
|
|
77
|
+
if (existing) {
|
|
78
|
+
existing.count++;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
groups.set(key, { match, name, id, count: 1 });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const usedNames = collectExistingIdentifiers(body);
|
|
85
|
+
const hoists = [];
|
|
86
|
+
let result = body;
|
|
87
|
+
const dedupable = Array.from(groups.values())
|
|
88
|
+
.filter((g) => g.count >= 2)
|
|
89
|
+
.sort((a, b) => body.indexOf(a.match) - body.indexOf(b.match));
|
|
90
|
+
for (const group of dedupable) {
|
|
91
|
+
const constName = uniqueConstName(group.name, usedNames);
|
|
92
|
+
hoists.push(`const ${constName} = ${group.match};`);
|
|
93
|
+
result = splitJoin(result, group.match, constName);
|
|
94
|
+
}
|
|
95
|
+
if (hoists.length === 0)
|
|
96
|
+
return body;
|
|
97
|
+
return `${hoists.join('\n')}\n\n${result}`;
|
|
98
|
+
}
|
|
99
|
+
function splitJoin(haystack, needle, replacement) {
|
|
100
|
+
return haystack.split(needle).join(replacement);
|
|
101
|
+
}
|
|
102
|
+
function uniqueConstName(credName, used) {
|
|
103
|
+
const sanitised = credName
|
|
104
|
+
.replace(/[^a-zA-Z0-9]+/g, ' ')
|
|
105
|
+
.trim()
|
|
106
|
+
.split(/\s+/)
|
|
107
|
+
.filter(Boolean);
|
|
108
|
+
let camel;
|
|
109
|
+
if (sanitised.length === 0) {
|
|
110
|
+
camel = 'shared';
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
camel =
|
|
114
|
+
sanitised[0].charAt(0).toLowerCase() +
|
|
115
|
+
sanitised[0].slice(1) +
|
|
116
|
+
sanitised
|
|
117
|
+
.slice(1)
|
|
118
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
|
119
|
+
.join('');
|
|
120
|
+
}
|
|
121
|
+
const base = `${camel}Cred`;
|
|
122
|
+
let candidate = base;
|
|
123
|
+
let i = 1;
|
|
124
|
+
while (used.has(candidate)) {
|
|
125
|
+
i++;
|
|
126
|
+
candidate = `${base}${i}`;
|
|
127
|
+
}
|
|
128
|
+
used.add(candidate);
|
|
129
|
+
return candidate;
|
|
130
|
+
}
|
|
131
|
+
function collectExistingIdentifiers(body) {
|
|
132
|
+
const ids = new Set();
|
|
133
|
+
const pattern = /\b([a-zA-Z_][a-zA-Z0-9_]*)\b/g;
|
|
134
|
+
let m;
|
|
135
|
+
while ((m = pattern.exec(body)) !== null)
|
|
136
|
+
ids.add(m[1]);
|
|
137
|
+
return ids;
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=emit-instance-ai.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit-instance-ai.js","sourceRoot":"","sources":["../../src/codegen/emit-instance-ai.ts"],"names":[],"mappings":";;;AA2EA,wCAWC;AAMD,oCAOC;AAgBD,wDAoCC;AAUD,0CA6BC;AAhLD,qDAAgD;AAChD,2DAAyD;AACzD,uDAAkD;AAClD,qDAAsD;AAGtD,SAAS,oBAAoB,CAAC,QAAsB;IACnD,MAAM,KAAK,GAAG,IAAA,mCAAkB,EAAC,QAAQ,CAAC,CAAC;IAC3C,IAAA,+BAAa,EAAC,KAAK,CAAC,CAAC;IACrB,MAAM,IAAI,GAAG,IAAA,sCAAkB,EAAC,KAAK,CAAC,CAAC;IACvC,OAAO,IAAA,6BAAY,EAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;AAChD,CAAC;AAUY,QAAA,aAAa,GAAG;IAC5B,UAAU;IACV,SAAS;IACT,MAAM;IACN,QAAQ;IACR,aAAa;IACb,OAAO;IACP,QAAQ;IACR,YAAY;IACZ,eAAe;IACf,eAAe;IACf,QAAQ;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AI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;qBACzE,IAAI,CAAC,EAAE,CAAC,CAAC;IACb,CAAC;IAED,MAAM,IAAI,GAAG,GAAG,KAAK,MAAM,CAAC;IAC5B,IAAI,SAAS,GAAG,IAAI,CAAC;IACrB,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,OAAO,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5B,CAAC,EAAE,CAAC;QACJ,SAAS,GAAG,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC;IAC3B,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACpB,OAAO,SAAS,CAAC;AAClB,CAAC;AAMD,SAAS,0BAA0B,CAAC,IAAY;IAC/C,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAC;IAC9B,MAAM,OAAO,GAAG,+BAA+B,CAAC;IAChD,IAAI,CAAyB,CAAC;IAC9B,OAAO,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI;QAAE,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACxD,OAAO,GAAG,CAAC;AACZ,CAAC"}
|
package/dist/codegen/index.d.ts
CHANGED
|
@@ -16,5 +16,6 @@ export { buildSemanticGraph } from './semantic-graph';
|
|
|
16
16
|
export { annotateGraph } from './graph-annotator';
|
|
17
17
|
export { buildCompositeTree } from './composite-builder';
|
|
18
18
|
export { generateCode } from './code-generator';
|
|
19
|
+
export { emitInstanceAi, type EmitInstanceAiOptions } from './emit-instance-ai';
|
|
19
20
|
export { getOutputName, getInputName, getCompositeType, getNodeSemantics, isCycleOutput, } from './semantic-registry';
|
|
20
21
|
export declare function generateWorkflowCode(input: WorkflowJSON | GenerateWorkflowCodeOptions): string;
|
package/dist/codegen/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isCycleOutput = exports.getNodeSemantics = exports.getCompositeType = exports.getInputName = exports.getOutputName = exports.generateCode = exports.buildCompositeTree = exports.annotateGraph = exports.buildSemanticGraph = void 0;
|
|
3
|
+
exports.isCycleOutput = exports.getNodeSemantics = exports.getCompositeType = exports.getInputName = exports.getOutputName = exports.emitInstanceAi = exports.generateCode = exports.buildCompositeTree = exports.annotateGraph = exports.buildSemanticGraph = void 0;
|
|
4
4
|
exports.generateWorkflowCode = generateWorkflowCode;
|
|
5
5
|
const code_generator_1 = require("./code-generator");
|
|
6
6
|
const composite_builder_1 = require("./composite-builder");
|
|
@@ -16,6 +16,8 @@ var composite_builder_2 = require("./composite-builder");
|
|
|
16
16
|
Object.defineProperty(exports, "buildCompositeTree", { enumerable: true, get: function () { return composite_builder_2.buildCompositeTree; } });
|
|
17
17
|
var code_generator_2 = require("./code-generator");
|
|
18
18
|
Object.defineProperty(exports, "generateCode", { enumerable: true, get: function () { return code_generator_2.generateCode; } });
|
|
19
|
+
var emit_instance_ai_1 = require("./emit-instance-ai");
|
|
20
|
+
Object.defineProperty(exports, "emitInstanceAi", { enumerable: true, get: function () { return emit_instance_ai_1.emitInstanceAi; } });
|
|
19
21
|
var semantic_registry_1 = require("./semantic-registry");
|
|
20
22
|
Object.defineProperty(exports, "getOutputName", { enumerable: true, get: function () { return semantic_registry_1.getOutputName; } });
|
|
21
23
|
Object.defineProperty(exports, "getInputName", { enumerable: true, get: function () { return semantic_registry_1.getInputName; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/codegen/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/codegen/index.ts"],"names":[],"mappings":";;;AAgGA,oDAqDC;AAvID,qDAAgD;AAChD,2DAAyD;AACzD,yDAA0F;AAC1F,iEAAoE;AACpE,u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EAAE,CAAC;QACrB,KAAK,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,eAAe,EAAE,CAAC;YACpD,WAAW,CAAC,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACnC,CAAC;IACF,CAAC;IAGD,MAAM,mBAAmB,GAAG,IAAA,6CAA0B,EAAC,aAAa,CAAC,CAAC;IAGtE,OAAO,IAAA,6BAAY,EAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE;QAC1C,qBAAqB,EAAE,qBAAqB,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,SAAS;QACzF,mBAAmB,EAAE,mBAAmB,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,SAAS;QACnF,WAAW,EAAE,WAAW,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS;QAC3D,mBAAmB,EAAE,mBAAmB,IAAI,SAAS;QACrD,cAAc;QACd,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS;KAC3D,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface ExampleFile {
|
|
2
|
+
filename: string;
|
|
3
|
+
content: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ExampleFilesBundle {
|
|
6
|
+
files: ExampleFile[];
|
|
7
|
+
indexTxt: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function getExampleFiles(): ExampleFilesBundle;
|
|
10
|
+
export declare function resetExampleFilesCache(): void;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getExampleFiles = getExampleFiles;
|
|
37
|
+
exports.resetExampleFilesCache = resetExampleFilesCache;
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
const emit_instance_ai_1 = require("./codegen/emit-instance-ai");
|
|
41
|
+
const examples_zip_1 = require("./examples-zip");
|
|
42
|
+
const EXAMPLES_DIR = path.resolve(__dirname, '..', 'examples');
|
|
43
|
+
const MANIFEST_PATH = path.join(EXAMPLES_DIR, 'manifest.json');
|
|
44
|
+
const NODES_INLINE_LIMIT = 5;
|
|
45
|
+
const INDEX_NODE_SEPARATOR = ',';
|
|
46
|
+
let cached = null;
|
|
47
|
+
function getExampleFiles() {
|
|
48
|
+
if (cached !== null)
|
|
49
|
+
return cached;
|
|
50
|
+
cached = loadFromDisk();
|
|
51
|
+
return cached;
|
|
52
|
+
}
|
|
53
|
+
function resetExampleFilesCache() {
|
|
54
|
+
cached = null;
|
|
55
|
+
}
|
|
56
|
+
function loadFromDisk() {
|
|
57
|
+
if (!fs.existsSync(MANIFEST_PATH))
|
|
58
|
+
return { files: [], indexTxt: '' };
|
|
59
|
+
(0, examples_zip_1.ensureExtracted)();
|
|
60
|
+
const manifest = JSON.parse(fs.readFileSync(MANIFEST_PATH, 'utf-8'));
|
|
61
|
+
const entries = (manifest.workflows ?? [])
|
|
62
|
+
.filter((e) => e.success && !e.skip)
|
|
63
|
+
.sort((a, b) => b.score - a.score);
|
|
64
|
+
const files = [];
|
|
65
|
+
const indexLines = [];
|
|
66
|
+
for (const entry of entries) {
|
|
67
|
+
const wfPath = path.join(examples_zip_1.WORKFLOWS_CACHE_DIR, `${entry.slug}.json`);
|
|
68
|
+
if (!fs.existsSync(wfPath))
|
|
69
|
+
continue;
|
|
70
|
+
const wf = JSON.parse(fs.readFileSync(wfPath, 'utf-8'));
|
|
71
|
+
const header = buildJsdocHeader(entry);
|
|
72
|
+
const code = (0, emit_instance_ai_1.emitInstanceAi)(wf, { jsdocHeader: header });
|
|
73
|
+
files.push({ filename: `${entry.slug}.ts`, content: code });
|
|
74
|
+
indexLines.push(buildIndexLine(entry));
|
|
75
|
+
}
|
|
76
|
+
const indexTxt = indexLines.join('\n') + (indexLines.length > 0 ? '\n' : '');
|
|
77
|
+
return { files, indexTxt };
|
|
78
|
+
}
|
|
79
|
+
function buildJsdocHeader(entry) {
|
|
80
|
+
return [
|
|
81
|
+
'/**',
|
|
82
|
+
' * @template',
|
|
83
|
+
` * @name ${entry.name}`,
|
|
84
|
+
` * @nodes ${entry.nodes.join(', ')}`,
|
|
85
|
+
` * @tags ${entry.tags.join(', ')}`,
|
|
86
|
+
` * @source ${entry.source}`,
|
|
87
|
+
` * @author ${entry.author}`,
|
|
88
|
+
' */',
|
|
89
|
+
].join('\n');
|
|
90
|
+
}
|
|
91
|
+
function buildIndexLine(entry) {
|
|
92
|
+
const truncatedNodes = truncateNodes(entry.nodes);
|
|
93
|
+
return [
|
|
94
|
+
`${entry.slug}.ts`,
|
|
95
|
+
entry.name,
|
|
96
|
+
truncatedNodes,
|
|
97
|
+
entry.tags.join(','),
|
|
98
|
+
`n8n:${entry.id}`,
|
|
99
|
+
].join(' | ');
|
|
100
|
+
}
|
|
101
|
+
function truncateNodes(nodes) {
|
|
102
|
+
if (nodes.length <= NODES_INLINE_LIMIT)
|
|
103
|
+
return nodes.join(INDEX_NODE_SEPARATOR);
|
|
104
|
+
const head = nodes.slice(0, NODES_INLINE_LIMIT).join(INDEX_NODE_SEPARATOR);
|
|
105
|
+
const remaining = nodes.length - NODES_INLINE_LIMIT;
|
|
106
|
+
return `${head} +${remaining} more`;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=examples-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"examples-loader.js","sourceRoot":"","sources":["../src/examples-loader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEA,0CAIC;AAGD,wDAEC;AAlED,uCAAyB;AACzB,2CAA6B;AAE7B,iEAA4D;AAC5D,iDAAsE;AAItE,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;AAC/D,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,eAAe,CAAC,CAAC;AAE/D,MAAM,kBA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AAG,CAAC;QACpB,OAAO,KAAK,CAAC,EAAE,EAAE;KACjB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACf,CAAC;AAED,SAAS,aAAa,CAAC,KAAe;IACrC,IAAI,KAAK,CAAC,MAAM,IAAI,kBAAkB;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAChF,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,kBAAkB,CAAC,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IAC3E,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,GAAG,kBAAkB,CAAC;IACpD,OAAO,GAAG,IAAI,KAAK,SAAS,OAAO,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.WORKFLOWS_CACHE_DIR = void 0;
|
|
40
|
+
exports.zipExists = zipExists;
|
|
41
|
+
exports.needsExtraction = needsExtraction;
|
|
42
|
+
exports.extractFromZip = extractFromZip;
|
|
43
|
+
exports.ensureExtracted = ensureExtracted;
|
|
44
|
+
const adm_zip_1 = __importDefault(require("adm-zip"));
|
|
45
|
+
const fs = __importStar(require("fs"));
|
|
46
|
+
const os = __importStar(require("os"));
|
|
47
|
+
const path = __importStar(require("path"));
|
|
48
|
+
const EXAMPLES_DIR = path.resolve(__dirname, '..', 'examples');
|
|
49
|
+
const ZIP_PATH = path.join(EXAMPLES_DIR, 'templates.zip');
|
|
50
|
+
const MANIFEST_PATH = path.join(EXAMPLES_DIR, 'manifest.json');
|
|
51
|
+
function sdkVersion() {
|
|
52
|
+
try {
|
|
53
|
+
const pkgPath = path.resolve(__dirname, '..', 'package.json');
|
|
54
|
+
return (JSON.parse(fs.readFileSync(pkgPath, 'utf-8')).version ??
|
|
55
|
+
'unversioned');
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return 'unversioned';
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.WORKFLOWS_CACHE_DIR = path.join(os.tmpdir(), 'n8n-workflow-sdk', sdkVersion(), 'workflows');
|
|
62
|
+
function zipExists() {
|
|
63
|
+
return fs.existsSync(ZIP_PATH);
|
|
64
|
+
}
|
|
65
|
+
function needsExtraction() {
|
|
66
|
+
if (!fs.existsSync(ZIP_PATH))
|
|
67
|
+
return false;
|
|
68
|
+
if (!fs.existsSync(MANIFEST_PATH))
|
|
69
|
+
return false;
|
|
70
|
+
const manifest = JSON.parse(fs.readFileSync(MANIFEST_PATH, 'utf-8'));
|
|
71
|
+
for (const entry of manifest.workflows ?? []) {
|
|
72
|
+
if (!entry.success || entry.skip)
|
|
73
|
+
continue;
|
|
74
|
+
const filePath = path.join(exports.WORKFLOWS_CACHE_DIR, `${entry.slug}.json`);
|
|
75
|
+
if (!fs.existsSync(filePath))
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
function extractFromZip() {
|
|
81
|
+
if (!fs.existsSync(ZIP_PATH)) {
|
|
82
|
+
throw new Error(`Examples zip not found: ${ZIP_PATH}`);
|
|
83
|
+
}
|
|
84
|
+
if (!fs.existsSync(exports.WORKFLOWS_CACHE_DIR)) {
|
|
85
|
+
fs.mkdirSync(exports.WORKFLOWS_CACHE_DIR, { recursive: true });
|
|
86
|
+
}
|
|
87
|
+
const zip = new adm_zip_1.default(ZIP_PATH);
|
|
88
|
+
for (const entry of zip.getEntries()) {
|
|
89
|
+
if (entry.isDirectory)
|
|
90
|
+
continue;
|
|
91
|
+
zip.extractEntryTo(entry, exports.WORKFLOWS_CACHE_DIR, false, true);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function ensureExtracted() {
|
|
95
|
+
if (needsExtraction()) {
|
|
96
|
+
extractFromZip();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=examples-zip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"examples-zip.js","sourceRoot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
3
|
+
displayOptions?: {
|
|
4
|
+
show?: Record<string, unknown[]>;
|
|
5
|
+
hide?: Record<string, unknown[]>;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
1
8
|
export interface ParameterBuilderHint {
|
|
2
9
|
propertyHint: string;
|
|
3
10
|
placeholderSupported?: boolean;
|
|
@@ -235,6 +235,63 @@ const AI_TYPE_TO_SUBNODE_FIELD = {
|
|
|
235
235
|
canBeMultiple: false,
|
|
236
236
|
},
|
|
237
237
|
};
|
|
238
|
+
function variationApplies(variation, combo) {
|
|
239
|
+
const opts = variation.displayOptions;
|
|
240
|
+
if (!combo)
|
|
241
|
+
return !opts;
|
|
242
|
+
if (!opts)
|
|
243
|
+
return false;
|
|
244
|
+
if (opts.show) {
|
|
245
|
+
for (const [key, conditions] of Object.entries(opts.show)) {
|
|
246
|
+
const value = combo[key];
|
|
247
|
+
if (value === undefined)
|
|
248
|
+
return false;
|
|
249
|
+
if (!(0, display_options_1.checkConditions)(conditions, [value]))
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
if (opts.hide) {
|
|
254
|
+
for (const [key, conditions] of Object.entries(opts.hide)) {
|
|
255
|
+
const value = combo[key];
|
|
256
|
+
if (value === undefined)
|
|
257
|
+
continue;
|
|
258
|
+
if ((0, display_options_1.checkConditions)(conditions, [value]))
|
|
259
|
+
return false;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return true;
|
|
263
|
+
}
|
|
264
|
+
function emitBuilderHint(lines, indent, hint, combo) {
|
|
265
|
+
if (hint.propertyHint) {
|
|
266
|
+
const safePropertyHint = hint.propertyHint
|
|
267
|
+
.replace(/\*\//g, '*\\/')
|
|
268
|
+
.replace(/</g, '<')
|
|
269
|
+
.replace(/>/g, '>');
|
|
270
|
+
lines.push(`${indent} * @builderHint ${safePropertyHint}`);
|
|
271
|
+
}
|
|
272
|
+
if (!hint.extraTypeDefContent)
|
|
273
|
+
return;
|
|
274
|
+
for (const variation of hint.extraTypeDefContent) {
|
|
275
|
+
if (!variationApplies(variation, combo))
|
|
276
|
+
continue;
|
|
277
|
+
const safe = variation.content.replace(/\*\//g, '*\\/');
|
|
278
|
+
for (const line of safe.split('\n')) {
|
|
279
|
+
lines.push(`${indent} * ${line}`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
function getNodeBuilderHint(node) {
|
|
284
|
+
return node.builderHint;
|
|
285
|
+
}
|
|
286
|
+
function emitNodeHintForCombo(lines, node, combo) {
|
|
287
|
+
const hint = getNodeBuilderHint(node);
|
|
288
|
+
if (!hint?.extraTypeDefContent?.some((v) => variationApplies(v, combo)))
|
|
289
|
+
return;
|
|
290
|
+
const hintLines = [`${INDENT}/**`];
|
|
291
|
+
emitBuilderHint(hintLines, INDENT, { extraTypeDefContent: hint.extraTypeDefContent }, combo);
|
|
292
|
+
hintLines.push(`${INDENT} */`);
|
|
293
|
+
lines.push(...hintLines);
|
|
294
|
+
}
|
|
238
295
|
const schemaCache = new Map();
|
|
239
296
|
function findNestedSchemaDir(dir, targetNames) {
|
|
240
297
|
let entries;
|
|
@@ -585,11 +642,7 @@ function generateNestedPropertyJSDoc(prop, indent, discriminatorContext) {
|
|
|
585
642
|
lines.push(`${indent} * @hint ${safeHint}`);
|
|
586
643
|
}
|
|
587
644
|
if (prop.builderHint) {
|
|
588
|
-
|
|
589
|
-
.replace(/\*\//g, '*\\/')
|
|
590
|
-
.replace(/</g, '<')
|
|
591
|
-
.replace(/>/g, '>');
|
|
592
|
-
lines.push(`${indent} * @builderHint ${safeBuilderHint}`);
|
|
645
|
+
emitBuilderHint(lines, indent, prop.builderHint);
|
|
593
646
|
}
|
|
594
647
|
if (prop.builderHint?.placeholderSupported === false) {
|
|
595
648
|
lines.push(`${indent} * @placeholderSupported false`);
|
|
@@ -711,14 +764,10 @@ function generateFixedCollectionType(prop, discriminatorContext) {
|
|
|
711
764
|
groupJsDocLines.push(`${INDENT.repeat(2)}/** ${desc}`);
|
|
712
765
|
}
|
|
713
766
|
if (group.builderHint) {
|
|
714
|
-
const safeBuilderHint = group.builderHint.propertyHint
|
|
715
|
-
.replace(/\*\//g, '*\\/')
|
|
716
|
-
.replace(/</g, '<')
|
|
717
|
-
.replace(/>/g, '>');
|
|
718
767
|
if (groupJsDocLines.length === 0) {
|
|
719
768
|
groupJsDocLines.push(`${INDENT.repeat(2)}/**`);
|
|
720
769
|
}
|
|
721
|
-
groupJsDocLines
|
|
770
|
+
emitBuilderHint(groupJsDocLines, INDENT.repeat(2), group.builderHint);
|
|
722
771
|
}
|
|
723
772
|
if (isMultipleValues && hasMinRequired) {
|
|
724
773
|
if (groupJsDocLines.length === 0) {
|
|
@@ -1213,6 +1262,7 @@ function generateDiscriminatedUnion(node) {
|
|
|
1213
1262
|
lines.push(`/** ${description} */`);
|
|
1214
1263
|
}
|
|
1215
1264
|
lines.push(`export type ${configName} = {`);
|
|
1265
|
+
emitNodeHintForCombo(lines, node, combo);
|
|
1216
1266
|
for (const [key, value] of Object.entries(combo)) {
|
|
1217
1267
|
if (value !== undefined) {
|
|
1218
1268
|
lines.push(`${INDENT}${key}: '${value}';`);
|
|
@@ -1243,11 +1293,7 @@ function generatePropertyJSDoc(prop, discriminatorContext) {
|
|
|
1243
1293
|
lines.push(` * @hint ${safeHint}`);
|
|
1244
1294
|
}
|
|
1245
1295
|
if (prop.builderHint) {
|
|
1246
|
-
|
|
1247
|
-
.replace(/\*\//g, '*\\/')
|
|
1248
|
-
.replace(/</g, '<')
|
|
1249
|
-
.replace(/>/g, '>');
|
|
1250
|
-
lines.push(` * @builderHint ${safeBuilderHint}`);
|
|
1296
|
+
emitBuilderHint(lines, '', prop.builderHint);
|
|
1251
1297
|
}
|
|
1252
1298
|
if (prop.builderHint?.placeholderSupported === false) {
|
|
1253
1299
|
lines.push(' * @placeholderSupported false');
|
|
@@ -1329,6 +1375,13 @@ function generateNodeJSDoc(node) {
|
|
|
1329
1375
|
if (subnodeType) {
|
|
1330
1376
|
lines.push(` * @subnodeType ${subnodeType}`);
|
|
1331
1377
|
}
|
|
1378
|
+
const nodeHint = getNodeBuilderHint(node);
|
|
1379
|
+
if (nodeHint && (nodeHint.searchHint || nodeHint.extraTypeDefContent?.length)) {
|
|
1380
|
+
emitBuilderHint(lines, '', {
|
|
1381
|
+
propertyHint: nodeHint.searchHint,
|
|
1382
|
+
extraTypeDefContent: nodeHint.extraTypeDefContent,
|
|
1383
|
+
});
|
|
1384
|
+
}
|
|
1332
1385
|
lines.push(' */');
|
|
1333
1386
|
return lines.join('\n');
|
|
1334
1387
|
}
|
|
@@ -1629,6 +1682,7 @@ function generateDiscriminatorFile(node, version, combo, props, schema, _importD
|
|
|
1629
1682
|
lines.push(`/** ${description} */`);
|
|
1630
1683
|
}
|
|
1631
1684
|
lines.push(`export type ${configName} = {`);
|
|
1685
|
+
emitNodeHintForCombo(lines, node, combo);
|
|
1632
1686
|
for (const [key, value] of Object.entries(combo)) {
|
|
1633
1687
|
if (value !== undefined) {
|
|
1634
1688
|
lines.push(`${INDENT}${key}: '${value}';`);
|
|
@@ -2177,6 +2231,7 @@ function generateDiscriminatedUnionForEntry(node, nodeName, versionSuffix) {
|
|
|
2177
2231
|
lines.push(`/** ${description} */`);
|
|
2178
2232
|
}
|
|
2179
2233
|
lines.push(`export type ${configName} = {`);
|
|
2234
|
+
emitNodeHintForCombo(lines, node, combo);
|
|
2180
2235
|
for (const [key, value] of Object.entries(combo)) {
|
|
2181
2236
|
if (value !== undefined) {
|
|
2182
2237
|
lines.push(`${INDENT}${key}: '${value}';`);
|