@n8n/expression-runtime 0.22.1 → 0.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/bridge/bridge-messages.d.ts +8 -8
- package/dist/cjs/bridge/bridge-messages.js +234 -244
- package/dist/cjs/bridge/bridge-messages.js.map +1 -1
- package/dist/cjs/bridge/isolated-vm-bridge.d.ts.map +1 -1
- package/dist/cjs/bridge/isolated-vm-bridge.js +644 -654
- package/dist/cjs/bridge/isolated-vm-bridge.js.map +1 -1
- package/dist/cjs/build.tsbuildinfo +1 -1
- package/dist/cjs/evaluator/error-classification.js +15 -25
- package/dist/cjs/evaluator/error-classification.js.map +1 -1
- package/dist/cjs/evaluator/expression-evaluator.d.ts.map +1 -1
- package/dist/cjs/evaluator/expression-evaluator.js +152 -162
- package/dist/cjs/evaluator/expression-evaluator.js.map +1 -1
- package/dist/cjs/evaluator/lru-cache.d.ts.map +1 -1
- package/dist/cjs/evaluator/lru-cache.js +35 -45
- package/dist/cjs/evaluator/lru-cache.js.map +1 -1
- package/dist/cjs/extensions/array-extensions.js +589 -599
- package/dist/cjs/extensions/array-extensions.js.map +1 -1
- package/dist/cjs/extensions/boolean-extensions.js +38 -48
- package/dist/cjs/extensions/boolean-extensions.js.map +1 -1
- package/dist/cjs/extensions/date-extensions.js +500 -510
- package/dist/cjs/extensions/date-extensions.js.map +1 -1
- package/dist/cjs/extensions/expression-extension-error.d.ts.map +1 -1
- package/dist/cjs/extensions/expression-extension-error.js +12 -22
- package/dist/cjs/extensions/expression-extension-error.js.map +1 -1
- package/dist/cjs/extensions/extend.js +162 -172
- package/dist/cjs/extensions/extend.js.map +1 -1
- package/dist/cjs/extensions/extensions.js +2 -12
- package/dist/cjs/extensions/function-extensions.d.ts +10 -18
- package/dist/cjs/extensions/function-extensions.d.ts.map +1 -1
- package/dist/cjs/extensions/function-extensions.js +78 -88
- package/dist/cjs/extensions/function-extensions.js.map +1 -1
- package/dist/cjs/extensions/number-extensions.js +225 -235
- package/dist/cjs/extensions/number-extensions.js.map +1 -1
- package/dist/cjs/extensions/object-extensions.js +286 -296
- package/dist/cjs/extensions/object-extensions.js.map +1 -1
- package/dist/cjs/extensions/string-extensions.d.ts +1 -1
- package/dist/cjs/extensions/string-extensions.d.ts.map +1 -1
- package/dist/cjs/extensions/string-extensions.js +758 -768
- package/dist/cjs/extensions/string-extensions.js.map +1 -1
- package/dist/cjs/extensions/utils.d.ts.map +1 -1
- package/dist/cjs/extensions/utils.js +28 -38
- package/dist/cjs/extensions/utils.js.map +1 -1
- package/dist/cjs/index.js +32 -42
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/observability/metrics.d.ts +27 -27
- package/dist/cjs/observability/metrics.d.ts.map +1 -1
- package/dist/cjs/observability/metrics.js +59 -69
- package/dist/cjs/observability/metrics.js.map +1 -1
- package/dist/cjs/observability/noop-provider.js +28 -38
- package/dist/cjs/observability/noop-provider.js.map +1 -1
- package/dist/cjs/pool/idle-scaling-pool.d.ts.map +1 -1
- package/dist/cjs/pool/idle-scaling-pool.js +134 -144
- package/dist/cjs/pool/idle-scaling-pool.js.map +1 -1
- package/dist/cjs/pool/isolate-pool.d.ts.map +1 -1
- package/dist/cjs/pool/isolate-pool.js +101 -111
- package/dist/cjs/pool/isolate-pool.js.map +1 -1
- package/dist/cjs/runtime/context.js +418 -428
- package/dist/cjs/runtime/context.js.map +1 -1
- package/dist/cjs/runtime/index.js +26 -36
- package/dist/cjs/runtime/index.js.map +1 -1
- package/dist/cjs/runtime/jmespath.js +72 -82
- package/dist/cjs/runtime/jmespath.js.map +1 -1
- package/dist/cjs/runtime/lazy-proxy.js +238 -248
- package/dist/cjs/runtime/lazy-proxy.js.map +1 -1
- package/dist/cjs/runtime/safe-globals.d.ts.map +1 -1
- package/dist/cjs/runtime/safe-globals.js +134 -144
- package/dist/cjs/runtime/safe-globals.js.map +1 -1
- package/dist/cjs/runtime/serialize.js +54 -64
- package/dist/cjs/runtime/serialize.js.map +1 -1
- package/dist/cjs/runtime/utils.js +20 -30
- package/dist/cjs/runtime/utils.js.map +1 -1
- package/dist/cjs/types/bridge.js +15 -25
- package/dist/cjs/types/bridge.js.map +1 -1
- package/dist/cjs/types/evaluator.d.ts.map +1 -1
- package/dist/cjs/types/evaluator.js +35 -45
- package/dist/cjs/types/evaluator.js.map +1 -1
- package/dist/cjs/types/index.js +14 -24
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/runtime.d.ts.map +1 -1
- package/dist/cjs/types/runtime.js +27 -37
- package/dist/cjs/types/runtime.js.map +1 -1
- package/dist/esm/bridge/bridge-messages.d.ts +8 -8
- package/dist/esm/bridge/isolated-vm-bridge.d.ts.map +1 -1
- package/dist/esm/bridge/isolated-vm-bridge.js.map +1 -1
- package/dist/esm/build.tsbuildinfo +1 -1
- package/dist/esm/evaluator/expression-evaluator.d.ts.map +1 -1
- package/dist/esm/evaluator/lru-cache.d.ts.map +1 -1
- package/dist/esm/evaluator/lru-cache.js.map +1 -1
- package/dist/esm/extensions/expression-extension-error.d.ts.map +1 -1
- package/dist/esm/extensions/function-extensions.d.ts +10 -18
- package/dist/esm/extensions/function-extensions.d.ts.map +1 -1
- package/dist/esm/extensions/number-extensions.js.map +1 -1
- package/dist/esm/extensions/string-extensions.d.ts +1 -1
- package/dist/esm/extensions/string-extensions.d.ts.map +1 -1
- package/dist/esm/extensions/string-extensions.js.map +1 -1
- package/dist/esm/extensions/utils.d.ts.map +1 -1
- package/dist/esm/observability/metrics.d.ts +27 -27
- package/dist/esm/observability/metrics.d.ts.map +1 -1
- package/dist/esm/pool/idle-scaling-pool.d.ts.map +1 -1
- package/dist/esm/pool/idle-scaling-pool.js.map +1 -1
- package/dist/esm/pool/isolate-pool.d.ts.map +1 -1
- package/dist/esm/pool/isolate-pool.js.map +1 -1
- package/dist/esm/runtime/lazy-proxy.js.map +1 -1
- package/dist/esm/runtime/safe-globals.d.ts.map +1 -1
- package/dist/esm/types/evaluator.d.ts.map +1 -1
- package/dist/esm/types/evaluator.js.map +1 -1
- package/dist/esm/types/runtime.d.ts.map +1 -1
- package/dist/esm/types/runtime.js.map +1 -1
- package/package.json +7 -6
|
@@ -1,637 +1,627 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
2
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
3
4
|
};
|
|
4
|
-
(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.arrayExtensions = void 0;
|
|
7
|
+
exports.average = average;
|
|
8
|
+
exports.toJsonString = toJsonString;
|
|
9
|
+
exports.toInt = toInt;
|
|
10
|
+
exports.toFloat = toFloat;
|
|
11
|
+
exports.toBoolean = toBoolean;
|
|
12
|
+
exports.toDateTime = toDateTime;
|
|
13
|
+
const isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
14
|
+
const random_1 = __importDefault(require("lodash/random"));
|
|
15
|
+
const uniqWith_1 = __importDefault(require("lodash/uniqWith"));
|
|
16
|
+
const expression_extension_error_1 = require("./expression-extension-error");
|
|
17
|
+
const object_extensions_1 = require("./object-extensions");
|
|
18
|
+
// DIVERGENCE from packages/workflow/src/extensions/array-extensions.ts:
|
|
19
|
+
// The original uses crypto.getRandomValues() which is a Web API unavailable
|
|
20
|
+
// inside the V8 isolate. lodash/random (already bundled) is used instead — both
|
|
21
|
+
// are backed by Math.random() and randomItem() is non-security-critical.
|
|
22
|
+
function randomInt(max) {
|
|
23
|
+
return (0, random_1.default)(0, max - 1);
|
|
24
|
+
}
|
|
25
|
+
function first(value) {
|
|
26
|
+
return value[0];
|
|
27
|
+
}
|
|
28
|
+
function isEmpty(value) {
|
|
29
|
+
return value.length === 0;
|
|
30
|
+
}
|
|
31
|
+
function isNotEmpty(value) {
|
|
32
|
+
return value.length > 0;
|
|
33
|
+
}
|
|
34
|
+
function last(value) {
|
|
35
|
+
return value[value.length - 1];
|
|
36
|
+
}
|
|
37
|
+
function pluck(value, extraArgs) {
|
|
38
|
+
if (!Array.isArray(extraArgs)) {
|
|
39
|
+
throw new expression_extension_error_1.ExpressionExtensionError('arguments must be passed to pluck');
|
|
8
40
|
}
|
|
9
|
-
|
|
10
|
-
|
|
41
|
+
if (!extraArgs || extraArgs.length === 0) {
|
|
42
|
+
return value;
|
|
11
43
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
exports.toBoolean = toBoolean;
|
|
21
|
-
exports.toDateTime = toDateTime;
|
|
22
|
-
const isEqual_1 = __importDefault(require("lodash/isEqual"));
|
|
23
|
-
const random_1 = __importDefault(require("lodash/random"));
|
|
24
|
-
const uniqWith_1 = __importDefault(require("lodash/uniqWith"));
|
|
25
|
-
const expression_extension_error_1 = require("./expression-extension-error");
|
|
26
|
-
const object_extensions_1 = require("./object-extensions");
|
|
27
|
-
// DIVERGENCE from packages/workflow/src/extensions/array-extensions.ts:
|
|
28
|
-
// The original uses crypto.getRandomValues() which is a Web API unavailable
|
|
29
|
-
// inside the V8 isolate. lodash/random (already bundled) is used instead — both
|
|
30
|
-
// are backed by Math.random() and randomItem() is non-security-critical.
|
|
31
|
-
function randomInt(max) {
|
|
32
|
-
return (0, random_1.default)(0, max - 1);
|
|
33
|
-
}
|
|
34
|
-
function first(value) {
|
|
35
|
-
return value[0];
|
|
36
|
-
}
|
|
37
|
-
function isEmpty(value) {
|
|
38
|
-
return value.length === 0;
|
|
39
|
-
}
|
|
40
|
-
function isNotEmpty(value) {
|
|
41
|
-
return value.length > 0;
|
|
42
|
-
}
|
|
43
|
-
function last(value) {
|
|
44
|
-
return value[value.length - 1];
|
|
45
|
-
}
|
|
46
|
-
function pluck(value, extraArgs) {
|
|
47
|
-
if (!Array.isArray(extraArgs)) {
|
|
48
|
-
throw new expression_extension_error_1.ExpressionExtensionError('arguments must be passed to pluck');
|
|
49
|
-
}
|
|
50
|
-
if (!extraArgs || extraArgs.length === 0) {
|
|
51
|
-
return value;
|
|
52
|
-
}
|
|
53
|
-
const plucked = value.reduce((pluckedFromObject, current) => {
|
|
54
|
-
if (current && typeof current === 'object') {
|
|
55
|
-
const p = [];
|
|
56
|
-
Object.keys(current).forEach((k) => {
|
|
57
|
-
extraArgs.forEach((field) => {
|
|
58
|
-
if (current && field === k) {
|
|
59
|
-
p.push(current[k]);
|
|
60
|
-
}
|
|
61
|
-
});
|
|
44
|
+
const plucked = value.reduce((pluckedFromObject, current) => {
|
|
45
|
+
if (current && typeof current === 'object') {
|
|
46
|
+
const p = [];
|
|
47
|
+
Object.keys(current).forEach((k) => {
|
|
48
|
+
extraArgs.forEach((field) => {
|
|
49
|
+
if (current && field === k) {
|
|
50
|
+
p.push(current[k]);
|
|
51
|
+
}
|
|
62
52
|
});
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
return pluckedFromObject;
|
|
68
|
-
}, new Array());
|
|
69
|
-
return plucked;
|
|
70
|
-
}
|
|
71
|
-
function randomItem(value) {
|
|
72
|
-
const len = value === undefined ? 0 : value.length;
|
|
73
|
-
return len ? value[randomInt(len)] : undefined;
|
|
74
|
-
}
|
|
75
|
-
function unique(value, extraArgs) {
|
|
76
|
-
const mapForEqualityCheck = (item) => {
|
|
77
|
-
if (extraArgs.length > 0 && item && typeof item === 'object') {
|
|
78
|
-
return extraArgs.reduce((acc, key) => {
|
|
79
|
-
acc[key] = item[key];
|
|
80
|
-
return acc;
|
|
81
|
-
}, {});
|
|
53
|
+
});
|
|
54
|
+
if (p.length > 0) {
|
|
55
|
+
pluckedFromObject.push(p.length === 1 ? p[0] : p);
|
|
82
56
|
}
|
|
83
|
-
return item;
|
|
84
|
-
};
|
|
85
|
-
return (0, uniqWith_1.default)(value, (a, b) => (0, isEqual_1.default)(mapForEqualityCheck(a), mapForEqualityCheck(b)));
|
|
86
|
-
}
|
|
87
|
-
const ensureNumberArray = (arr, { fnName }) => {
|
|
88
|
-
if (arr.some((i) => typeof i !== 'number')) {
|
|
89
|
-
throw new expression_extension_error_1.ExpressionExtensionError(`${fnName}(): all array elements must be numbers`);
|
|
90
57
|
}
|
|
58
|
+
return pluckedFromObject;
|
|
59
|
+
}, new Array());
|
|
60
|
+
return plucked;
|
|
61
|
+
}
|
|
62
|
+
function randomItem(value) {
|
|
63
|
+
const len = value === undefined ? 0 : value.length;
|
|
64
|
+
return len ? value[randomInt(len)] : undefined;
|
|
65
|
+
}
|
|
66
|
+
function unique(value, extraArgs) {
|
|
67
|
+
const mapForEqualityCheck = (item) => {
|
|
68
|
+
if (extraArgs.length > 0 && item && typeof item === 'object') {
|
|
69
|
+
return extraArgs.reduce((acc, key) => {
|
|
70
|
+
acc[key] = item[key];
|
|
71
|
+
return acc;
|
|
72
|
+
}, {});
|
|
73
|
+
}
|
|
74
|
+
return item;
|
|
91
75
|
};
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
if (typeof c !== 'number') {
|
|
99
|
-
return NaN;
|
|
100
|
-
}
|
|
101
|
-
return p + c;
|
|
102
|
-
}, 0);
|
|
76
|
+
return (0, uniqWith_1.default)(value, (a, b) => (0, isEqual_1.default)(mapForEqualityCheck(a), mapForEqualityCheck(b)));
|
|
77
|
+
}
|
|
78
|
+
const ensureNumberArray = (arr, { fnName }) => {
|
|
79
|
+
if (arr.some((i) => typeof i !== 'number')) {
|
|
80
|
+
throw new expression_extension_error_1.ExpressionExtensionError(`${fnName}(): all array elements must be numbers`);
|
|
103
81
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (typeof v !== 'number') {
|
|
111
|
-
return NaN;
|
|
112
|
-
}
|
|
113
|
-
return v;
|
|
114
|
-
}));
|
|
115
|
-
}
|
|
116
|
-
function max(value) {
|
|
117
|
-
ensureNumberArray(value, { fnName: 'max' });
|
|
118
|
-
return Math.max(...value.map((v) => {
|
|
119
|
-
if (typeof v === 'string') {
|
|
120
|
-
return parseFloat(v);
|
|
121
|
-
}
|
|
122
|
-
if (typeof v !== 'number') {
|
|
123
|
-
return NaN;
|
|
124
|
-
}
|
|
125
|
-
return v;
|
|
126
|
-
}));
|
|
127
|
-
}
|
|
128
|
-
function average(value) {
|
|
129
|
-
ensureNumberArray(value, { fnName: 'average' });
|
|
130
|
-
// This would usually be NaN but I don't think users
|
|
131
|
-
// will expect that
|
|
132
|
-
if (value.length === 0) {
|
|
133
|
-
return 0;
|
|
82
|
+
};
|
|
83
|
+
function sum(value) {
|
|
84
|
+
ensureNumberArray(value, { fnName: 'sum' });
|
|
85
|
+
return value.reduce((p, c) => {
|
|
86
|
+
if (typeof c === 'string') {
|
|
87
|
+
return p + parseFloat(c);
|
|
134
88
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
function compact(value) {
|
|
138
|
-
return value
|
|
139
|
-
.filter((v) => {
|
|
140
|
-
if (v && typeof v === 'object' && Object.keys(v).length === 0)
|
|
141
|
-
return false;
|
|
142
|
-
return v !== null && v !== undefined && v !== 'nil' && v !== '';
|
|
143
|
-
})
|
|
144
|
-
.map((v) => {
|
|
145
|
-
if (typeof v === 'object' && v !== null) {
|
|
146
|
-
return (0, object_extensions_1.compact)(v);
|
|
147
|
-
}
|
|
148
|
-
return v;
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
function smartJoin(value, extraArgs) {
|
|
152
|
-
const [keyField, valueField] = extraArgs;
|
|
153
|
-
if (!keyField || !valueField || typeof keyField !== 'string' || typeof valueField !== 'string') {
|
|
154
|
-
throw new expression_extension_error_1.ExpressionExtensionError('smartJoin(): expected two string args, e.g. .smartJoin("name", "value")');
|
|
89
|
+
if (typeof c !== 'number') {
|
|
90
|
+
return NaN;
|
|
155
91
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
return
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const [chunkSize] = extraArgs;
|
|
168
|
-
if (typeof chunkSize !== 'number' || chunkSize === 0) {
|
|
169
|
-
throw new expression_extension_error_1.ExpressionExtensionError('chunk(): expected non-zero numeric arg, e.g. .chunk(5)');
|
|
92
|
+
return p + c;
|
|
93
|
+
}, 0);
|
|
94
|
+
}
|
|
95
|
+
function min(value) {
|
|
96
|
+
ensureNumberArray(value, { fnName: 'min' });
|
|
97
|
+
return Math.min(...value.map((v) => {
|
|
98
|
+
if (typeof v === 'string') {
|
|
99
|
+
return parseFloat(v);
|
|
100
|
+
}
|
|
101
|
+
if (typeof v !== 'number') {
|
|
102
|
+
return NaN;
|
|
170
103
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
104
|
+
return v;
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
function max(value) {
|
|
108
|
+
ensureNumberArray(value, { fnName: 'max' });
|
|
109
|
+
return Math.max(...value.map((v) => {
|
|
110
|
+
if (typeof v === 'string') {
|
|
111
|
+
return parseFloat(v);
|
|
174
112
|
}
|
|
175
|
-
|
|
113
|
+
if (typeof v !== 'number') {
|
|
114
|
+
return NaN;
|
|
115
|
+
}
|
|
116
|
+
return v;
|
|
117
|
+
}));
|
|
118
|
+
}
|
|
119
|
+
function average(value) {
|
|
120
|
+
ensureNumberArray(value, { fnName: 'average' });
|
|
121
|
+
// This would usually be NaN but I don't think users
|
|
122
|
+
// will expect that
|
|
123
|
+
if (value.length === 0) {
|
|
124
|
+
return 0;
|
|
176
125
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
126
|
+
return sum(value) / value.length;
|
|
127
|
+
}
|
|
128
|
+
function compact(value) {
|
|
129
|
+
return value
|
|
130
|
+
.filter((v) => {
|
|
131
|
+
if (v && typeof v === 'object' && Object.keys(v).length === 0)
|
|
132
|
+
return false;
|
|
133
|
+
return v !== null && v !== undefined && v !== 'nil' && v !== '';
|
|
134
|
+
})
|
|
135
|
+
.map((v) => {
|
|
136
|
+
if (typeof v === 'object' && v !== null) {
|
|
137
|
+
return (0, object_extensions_1.compact)(v);
|
|
180
138
|
}
|
|
181
|
-
return
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
chunkedArgs.forEach(([from, to]) => {
|
|
189
|
-
if (from in newObj) {
|
|
190
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
191
|
-
newObj[to] = newObj[from];
|
|
192
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
193
|
-
delete newObj[from];
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
197
|
-
return newObj;
|
|
198
|
-
});
|
|
139
|
+
return v;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
function smartJoin(value, extraArgs) {
|
|
143
|
+
const [keyField, valueField] = extraArgs;
|
|
144
|
+
if (!keyField || !valueField || typeof keyField !== 'string' || typeof valueField !== 'string') {
|
|
145
|
+
throw new expression_extension_error_1.ExpressionExtensionError('smartJoin(): expected two string args, e.g. .smartJoin("name", "value")');
|
|
199
146
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
if (
|
|
203
|
-
|
|
147
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-return
|
|
148
|
+
return value.reduce((o, v) => {
|
|
149
|
+
if (typeof v === 'object' && v !== null && keyField in v && valueField in v) {
|
|
150
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
|
|
151
|
+
o[v[keyField]] = v[valueField];
|
|
204
152
|
}
|
|
205
|
-
|
|
206
|
-
|
|
153
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
154
|
+
return o;
|
|
155
|
+
}, {});
|
|
156
|
+
}
|
|
157
|
+
function chunk(value, extraArgs) {
|
|
158
|
+
const [chunkSize] = extraArgs;
|
|
159
|
+
if (typeof chunkSize !== 'number' || chunkSize === 0) {
|
|
160
|
+
throw new expression_extension_error_1.ExpressionExtensionError('chunk(): expected non-zero numeric arg, e.g. .chunk(5)');
|
|
161
|
+
}
|
|
162
|
+
const chunks = [];
|
|
163
|
+
for (let i = 0; i < value.length; i += chunkSize) {
|
|
164
|
+
chunks.push(value.slice(i, i + chunkSize));
|
|
165
|
+
}
|
|
166
|
+
return chunks;
|
|
167
|
+
}
|
|
168
|
+
function renameKeys(value, extraArgs) {
|
|
169
|
+
if (extraArgs.length === 0 || extraArgs.length % 2 !== 0) {
|
|
170
|
+
throw new expression_extension_error_1.ExpressionExtensionError('renameKeys(): expected an even amount of args: from1, to1 [, from2, to2, ...]. e.g. .renameKeys("name", "title")');
|
|
171
|
+
}
|
|
172
|
+
return value.map((v) => {
|
|
173
|
+
if (typeof v !== 'object' || v === null) {
|
|
174
|
+
return v;
|
|
207
175
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
176
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
|
|
177
|
+
const newObj = { ...v };
|
|
178
|
+
const chunkedArgs = chunk(extraArgs, [2]);
|
|
179
|
+
chunkedArgs.forEach(([from, to]) => {
|
|
180
|
+
if (from in newObj) {
|
|
181
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
|
|
182
|
+
newObj[to] = newObj[from];
|
|
183
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
184
|
+
delete newObj[from];
|
|
212
185
|
}
|
|
213
|
-
}
|
|
214
|
-
return
|
|
186
|
+
});
|
|
187
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
188
|
+
return newObj;
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
function mergeObjects(value, extraArgs) {
|
|
192
|
+
const [other] = extraArgs;
|
|
193
|
+
if (!other) {
|
|
194
|
+
return value;
|
|
215
195
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
return combined;
|
|
225
|
-
}, {});
|
|
226
|
-
return merged;
|
|
227
|
-
}
|
|
228
|
-
if (!Array.isArray(others)) {
|
|
229
|
-
throw new expression_extension_error_1.ExpressionExtensionError('merge(): expected array arg, e.g. .merge([{ id: 1, otherValue: 3 }])');
|
|
196
|
+
if (typeof other !== 'object') {
|
|
197
|
+
throw new expression_extension_error_1.ExpressionExtensionError('merge(): expected object arg');
|
|
198
|
+
}
|
|
199
|
+
const newObject = { ...value };
|
|
200
|
+
for (const [key, val] of Object.entries(other)) {
|
|
201
|
+
if (!(key in newObject)) {
|
|
202
|
+
newObject[key] = val;
|
|
230
203
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
204
|
+
}
|
|
205
|
+
return newObject;
|
|
206
|
+
}
|
|
207
|
+
function merge(value, extraArgs) {
|
|
208
|
+
const [others] = extraArgs;
|
|
209
|
+
if (others === undefined) {
|
|
210
|
+
// If there are no arguments passed, merge all objects within the array
|
|
211
|
+
const merged = value.reduce((combined, current) => {
|
|
212
|
+
if (current !== null && typeof current === 'object' && !Array.isArray(current)) {
|
|
213
|
+
combined = mergeObjects(combined, [current]);
|
|
238
214
|
}
|
|
239
|
-
|
|
215
|
+
return combined;
|
|
216
|
+
}, {});
|
|
240
217
|
return merged;
|
|
241
218
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
if (!Array.isArray(others)) {
|
|
245
|
-
throw new expression_extension_error_1.ExpressionExtensionError('union(): expected array arg, e.g. .union([1, 2, 3, 4])');
|
|
246
|
-
}
|
|
247
|
-
const newArr = Array.from(value);
|
|
248
|
-
for (const v of others) {
|
|
249
|
-
if (newArr.findIndex((w) => (0, isEqual_1.default)(w, v)) === -1) {
|
|
250
|
-
newArr.push(v);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
return unique(newArr, []);
|
|
219
|
+
if (!Array.isArray(others)) {
|
|
220
|
+
throw new expression_extension_error_1.ExpressionExtensionError('merge(): expected array arg, e.g. .merge([{ id: 1, otherValue: 3 }])');
|
|
254
221
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
for (const v of value) {
|
|
262
|
-
if (others.findIndex((w) => (0, isEqual_1.default)(w, v)) === -1) {
|
|
263
|
-
newArr.push(v);
|
|
222
|
+
const listLength = value.length > others.length ? value.length : others.length;
|
|
223
|
+
let merged = {};
|
|
224
|
+
for (let i = 0; i < listLength; i++) {
|
|
225
|
+
if (value[i] !== undefined) {
|
|
226
|
+
if (typeof value[i] === 'object' && typeof others[i] === 'object') {
|
|
227
|
+
merged = Object.assign(merged, mergeObjects(value[i], [others[i]]));
|
|
264
228
|
}
|
|
265
229
|
}
|
|
266
|
-
return unique(newArr, []);
|
|
267
230
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
for (const v of value) {
|
|
275
|
-
if (others.findIndex((w) => (0, isEqual_1.default)(w, v)) !== -1) {
|
|
276
|
-
newArr.push(v);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
for (const v of others) {
|
|
280
|
-
if (value.findIndex((w) => (0, isEqual_1.default)(w, v)) !== -1) {
|
|
281
|
-
newArr.push(v);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
return unique(newArr, []);
|
|
231
|
+
return merged;
|
|
232
|
+
}
|
|
233
|
+
function union(value, extraArgs) {
|
|
234
|
+
const [others] = extraArgs;
|
|
235
|
+
if (!Array.isArray(others)) {
|
|
236
|
+
throw new expression_extension_error_1.ExpressionExtensionError('union(): expected array arg, e.g. .union([1, 2, 3, 4])');
|
|
285
237
|
}
|
|
286
|
-
|
|
287
|
-
|
|
238
|
+
const newArr = Array.from(value);
|
|
239
|
+
for (const v of others) {
|
|
240
|
+
if (newArr.findIndex((w) => (0, isEqual_1.default)(w, v)) === -1) {
|
|
241
|
+
newArr.push(v);
|
|
242
|
+
}
|
|
288
243
|
}
|
|
289
|
-
|
|
290
|
-
|
|
244
|
+
return unique(newArr, []);
|
|
245
|
+
}
|
|
246
|
+
function difference(value, extraArgs) {
|
|
247
|
+
const [others] = extraArgs;
|
|
248
|
+
if (!Array.isArray(others)) {
|
|
249
|
+
throw new expression_extension_error_1.ExpressionExtensionError('difference(): expected array arg, e.g. .difference([1, 2, 3, 4])');
|
|
291
250
|
}
|
|
292
|
-
|
|
293
|
-
|
|
251
|
+
const newArr = [];
|
|
252
|
+
for (const v of value) {
|
|
253
|
+
if (others.findIndex((w) => (0, isEqual_1.default)(w, v)) === -1) {
|
|
254
|
+
newArr.push(v);
|
|
255
|
+
}
|
|
294
256
|
}
|
|
295
|
-
|
|
296
|
-
|
|
257
|
+
return unique(newArr, []);
|
|
258
|
+
}
|
|
259
|
+
function intersection(value, extraArgs) {
|
|
260
|
+
const [others] = extraArgs;
|
|
261
|
+
if (!Array.isArray(others)) {
|
|
262
|
+
throw new expression_extension_error_1.ExpressionExtensionError('intersection(): expected array arg, e.g. .intersection([1, 2, 3, 4])');
|
|
297
263
|
}
|
|
298
|
-
|
|
299
|
-
|
|
264
|
+
const newArr = [];
|
|
265
|
+
for (const v of value) {
|
|
266
|
+
if (others.findIndex((w) => (0, isEqual_1.default)(w, v)) !== -1) {
|
|
267
|
+
newArr.push(v);
|
|
268
|
+
}
|
|
300
269
|
}
|
|
301
|
-
|
|
302
|
-
|
|
270
|
+
for (const v of others) {
|
|
271
|
+
if (value.findIndex((w) => (0, isEqual_1.default)(w, v)) !== -1) {
|
|
272
|
+
newArr.push(v);
|
|
273
|
+
}
|
|
303
274
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
name: 'intersection',
|
|
419
|
-
description: 'Compares two arrays. Returns all elements in the base array that are also present in the other array.',
|
|
420
|
-
examples: [{ example: '[1, 2].intersection([2, 3])', evaluated: '[2]' }],
|
|
421
|
-
returnType: 'Array',
|
|
422
|
-
args: [
|
|
423
|
-
{
|
|
424
|
-
name: 'otherArray',
|
|
425
|
-
optional: false,
|
|
426
|
-
description: 'The array to compare to the base array',
|
|
427
|
-
type: 'Array',
|
|
428
|
-
},
|
|
429
|
-
],
|
|
430
|
-
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-intersection',
|
|
431
|
-
};
|
|
432
|
-
merge.doc = {
|
|
433
|
-
name: 'merge',
|
|
434
|
-
description: 'Merges two Object-arrays into one object by merging the key-value pairs of each element.',
|
|
435
|
-
examples: [
|
|
436
|
-
{
|
|
437
|
-
example: "[{ name: 'Nathan' }, { age: 42 }].merge([{ city: 'Berlin' }, { country: 'Germany' }])",
|
|
438
|
-
evaluated: "{ name: 'Nathan', age: 42, city: 'Berlin', country: 'Germany' }",
|
|
439
|
-
},
|
|
440
|
-
],
|
|
441
|
-
returnType: 'Object',
|
|
442
|
-
args: [
|
|
443
|
-
{
|
|
444
|
-
name: 'otherArray',
|
|
445
|
-
optional: false,
|
|
446
|
-
description: 'The array to merge into the base array',
|
|
447
|
-
type: 'Array',
|
|
448
|
-
},
|
|
449
|
-
],
|
|
450
|
-
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-merge',
|
|
451
|
-
};
|
|
452
|
-
pluck.doc = {
|
|
453
|
-
name: 'pluck',
|
|
454
|
-
description: "Returns an array containing the values of the given field(s) in each Object of the array. Ignores any array elements that aren't Objects or don't have a key matching the field name(s) provided.",
|
|
455
|
-
examples: [
|
|
456
|
-
{
|
|
457
|
-
example: "[{ name: 'Nathan', age: 42 },{ name: 'Jan', city: 'Berlin' }].pluck('name')",
|
|
458
|
-
evaluated: '["Nathan", "Jan"]',
|
|
459
|
-
},
|
|
460
|
-
{
|
|
461
|
-
example: "[{ name: 'Nathan', age: 42 },{ name: 'Jan', city: 'Berlin' }].pluck('age')",
|
|
462
|
-
evaluated: '[42]',
|
|
463
|
-
},
|
|
464
|
-
],
|
|
465
|
-
returnType: 'Array',
|
|
466
|
-
args: [
|
|
467
|
-
{
|
|
468
|
-
name: 'fieldNames',
|
|
469
|
-
optional: false,
|
|
470
|
-
variadic: true,
|
|
471
|
-
description: 'The keys to retrieve the value of',
|
|
472
|
-
type: 'string',
|
|
473
|
-
},
|
|
474
|
-
],
|
|
475
|
-
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-pluck',
|
|
476
|
-
};
|
|
477
|
-
renameKeys.doc = {
|
|
478
|
-
name: 'renameKeys',
|
|
479
|
-
description: 'Changes all matching keys (field names) of any Objects in the array. Rename more than one key by\nadding extra arguments, i.e. <code>from1, to1, from2, to2, ...</code>.',
|
|
480
|
-
examples: [
|
|
481
|
-
{
|
|
482
|
-
example: "[{ name: 'bob' }, { name: 'meg' }].renameKeys('name', 'x')",
|
|
483
|
-
evaluated: "[{ x: 'bob' }, { x: 'meg' }]",
|
|
484
|
-
},
|
|
485
|
-
],
|
|
486
|
-
returnType: 'Array',
|
|
487
|
-
args: [
|
|
488
|
-
{
|
|
489
|
-
name: 'from',
|
|
490
|
-
optional: false,
|
|
491
|
-
description: 'The key to rename',
|
|
492
|
-
type: 'string',
|
|
493
|
-
},
|
|
494
|
-
{ name: 'to', optional: false, description: 'The new key name', type: 'string' },
|
|
495
|
-
],
|
|
496
|
-
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-renameKeys',
|
|
497
|
-
};
|
|
498
|
-
smartJoin.doc = {
|
|
499
|
-
name: 'smartJoin',
|
|
500
|
-
description: 'Creates a single Object from an array of Objects. Each Object in the array provides one field for the returned Object. Each Object in the array must contain a field with the key name and a field with the value.',
|
|
501
|
-
examples: [
|
|
502
|
-
{
|
|
503
|
-
example: "[{ field: 'age', value: 2 }, { field: 'city', value: 'Berlin' }].smartJoin('field', 'value')",
|
|
504
|
-
evaluated: "{ age: 2, city: 'Berlin' }",
|
|
505
|
-
},
|
|
506
|
-
],
|
|
507
|
-
returnType: 'Object',
|
|
508
|
-
args: [
|
|
509
|
-
{
|
|
510
|
-
name: 'keyField',
|
|
511
|
-
optional: false,
|
|
512
|
-
description: 'The field in each Object containing the key name',
|
|
513
|
-
type: 'string',
|
|
514
|
-
},
|
|
515
|
-
{
|
|
516
|
-
name: 'nameField',
|
|
517
|
-
optional: false,
|
|
518
|
-
description: 'The field in each Object containing the value',
|
|
519
|
-
type: 'string',
|
|
520
|
-
},
|
|
521
|
-
],
|
|
522
|
-
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-smartJoin',
|
|
523
|
-
};
|
|
524
|
-
union.doc = {
|
|
525
|
-
name: 'union',
|
|
526
|
-
description: 'Concatenates two arrays and then removes any duplicates',
|
|
527
|
-
examples: [{ example: '[1, 2].union([2, 3])', evaluated: '[1, 2, 3]' }],
|
|
528
|
-
returnType: 'Array',
|
|
529
|
-
args: [
|
|
530
|
-
{
|
|
531
|
-
name: 'otherArray',
|
|
532
|
-
optional: false,
|
|
533
|
-
description: 'The array to union with the base array',
|
|
534
|
-
type: 'Array',
|
|
535
|
-
},
|
|
536
|
-
],
|
|
537
|
-
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-union',
|
|
538
|
-
};
|
|
539
|
-
unique.doc = {
|
|
540
|
-
name: 'unique',
|
|
541
|
-
description: 'Removes any duplicate elements from the array',
|
|
542
|
-
examples: [
|
|
543
|
-
{ example: "['quick', 'brown', 'quick'].unique()", evaluated: "['quick', 'brown']" },
|
|
544
|
-
{
|
|
545
|
-
example: "[{ name: 'Nathan', age: 42 }, { name: 'Nathan', age: 22 }].unique()",
|
|
546
|
-
evaluated: "[{ name: 'Nathan', age: 42 }, { name: 'Nathan', age: 22 }]",
|
|
547
|
-
},
|
|
548
|
-
{
|
|
549
|
-
example: "[{ name: 'Nathan', age: 42 }, { name: 'Nathan', age: 22 }].unique('name')",
|
|
550
|
-
evaluated: "[{ name: 'Nathan', age: 42 }]",
|
|
551
|
-
},
|
|
552
|
-
],
|
|
553
|
-
returnType: 'any',
|
|
554
|
-
aliases: ['removeDuplicates'],
|
|
555
|
-
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-unique',
|
|
556
|
-
args: [
|
|
557
|
-
{
|
|
558
|
-
name: 'fieldNames',
|
|
559
|
-
optional: false,
|
|
560
|
-
variadic: true,
|
|
561
|
-
description: 'The object keys to check for equality',
|
|
562
|
-
type: 'any',
|
|
563
|
-
},
|
|
564
|
-
],
|
|
565
|
-
};
|
|
566
|
-
toJsonString.doc = {
|
|
567
|
-
name: 'toJsonString',
|
|
568
|
-
description: "Converts the array to a JSON string. The same as JavaScript's <code>JSON.stringify()</code>.",
|
|
569
|
-
examples: [
|
|
570
|
-
{
|
|
571
|
-
example: "['quick', 'brown', 'fox'].toJsonString()",
|
|
572
|
-
evaluated: '\'["quick","brown","fox"]\'',
|
|
573
|
-
},
|
|
574
|
-
],
|
|
575
|
-
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-toJsonString',
|
|
576
|
-
returnType: 'string',
|
|
577
|
-
};
|
|
578
|
-
append.doc = {
|
|
579
|
-
name: 'append',
|
|
580
|
-
aliases: ['push'],
|
|
581
|
-
description: 'Adds new elements to the end of the array. Similar to <code>push()</code>, but returns the modified array. Consider using spread syntax instead (see examples).',
|
|
582
|
-
examples: [
|
|
583
|
-
{ example: "['forget', 'me'].append('not')", evaluated: "['forget', 'me', 'not']" },
|
|
584
|
-
{ example: '[9, 0, 2].append(1, 0)', evaluated: '[9, 0, 2, 1, 0]' },
|
|
585
|
-
{
|
|
586
|
-
example: '[...[9, 0, 2], 1, 0]',
|
|
587
|
-
evaluated: '[9, 0, 2, 1, 0]',
|
|
588
|
-
description: 'Consider using spread syntax instead',
|
|
589
|
-
},
|
|
590
|
-
],
|
|
591
|
-
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-append',
|
|
592
|
-
returnType: 'Array',
|
|
593
|
-
args: [
|
|
594
|
-
{
|
|
595
|
-
name: 'elements',
|
|
596
|
-
optional: false,
|
|
597
|
-
variadic: true,
|
|
598
|
-
description: 'The elements to append, in order',
|
|
599
|
-
type: 'any',
|
|
600
|
-
},
|
|
601
|
-
],
|
|
602
|
-
};
|
|
603
|
-
const removeDuplicates = unique.bind({});
|
|
604
|
-
removeDuplicates.doc = { ...unique.doc, hidden: true };
|
|
605
|
-
exports.arrayExtensions = {
|
|
606
|
-
typeName: 'Array',
|
|
607
|
-
functions: {
|
|
608
|
-
removeDuplicates,
|
|
609
|
-
unique,
|
|
610
|
-
first,
|
|
611
|
-
last,
|
|
612
|
-
pluck,
|
|
613
|
-
randomItem,
|
|
614
|
-
sum,
|
|
615
|
-
min,
|
|
616
|
-
max,
|
|
617
|
-
average,
|
|
618
|
-
isNotEmpty,
|
|
619
|
-
isEmpty,
|
|
620
|
-
compact,
|
|
621
|
-
smartJoin,
|
|
622
|
-
chunk,
|
|
623
|
-
renameKeys,
|
|
624
|
-
merge,
|
|
625
|
-
union,
|
|
626
|
-
difference,
|
|
627
|
-
intersection,
|
|
628
|
-
append,
|
|
629
|
-
toJsonString,
|
|
630
|
-
toInt,
|
|
631
|
-
toFloat,
|
|
632
|
-
toBoolean,
|
|
633
|
-
toDateTime,
|
|
275
|
+
return unique(newArr, []);
|
|
276
|
+
}
|
|
277
|
+
function append(value, extraArgs) {
|
|
278
|
+
return value.concat(extraArgs);
|
|
279
|
+
}
|
|
280
|
+
function toJsonString(value) {
|
|
281
|
+
return JSON.stringify(value);
|
|
282
|
+
}
|
|
283
|
+
function toInt() {
|
|
284
|
+
return undefined;
|
|
285
|
+
}
|
|
286
|
+
function toFloat() {
|
|
287
|
+
return undefined;
|
|
288
|
+
}
|
|
289
|
+
function toBoolean() {
|
|
290
|
+
return undefined;
|
|
291
|
+
}
|
|
292
|
+
function toDateTime() {
|
|
293
|
+
return undefined;
|
|
294
|
+
}
|
|
295
|
+
average.doc = {
|
|
296
|
+
name: 'average',
|
|
297
|
+
aliases: ['mean'],
|
|
298
|
+
description: 'Returns the average of the numbers in the array. Throws an error if there are any non-numbers.',
|
|
299
|
+
examples: [{ example: '[12, 1, 5].average()', evaluated: '6' }],
|
|
300
|
+
returnType: 'number',
|
|
301
|
+
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-average',
|
|
302
|
+
};
|
|
303
|
+
compact.doc = {
|
|
304
|
+
name: 'compact',
|
|
305
|
+
aliases: ['removeEmpty'],
|
|
306
|
+
description: 'Removes any empty values from the array. <code>null</code>, <code>""</code> and <code>undefined</code> count as empty.',
|
|
307
|
+
examples: [{ example: '[2, null, 1, ""].compact()', evaluated: '[2, 1]' }],
|
|
308
|
+
returnType: 'Array',
|
|
309
|
+
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-compact',
|
|
310
|
+
};
|
|
311
|
+
isEmpty.doc = {
|
|
312
|
+
name: 'isEmpty',
|
|
313
|
+
description: 'Returns <code>true</code> if the array has no elements or is <code>null</code>',
|
|
314
|
+
examples: [
|
|
315
|
+
{ example: '[].isEmpty()', evaluated: 'true' },
|
|
316
|
+
{ example: "['quick', 'brown', 'fox'].isEmpty()", evaluated: 'false' },
|
|
317
|
+
],
|
|
318
|
+
returnType: 'boolean',
|
|
319
|
+
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-isEmpty',
|
|
320
|
+
};
|
|
321
|
+
isNotEmpty.doc = {
|
|
322
|
+
name: 'isNotEmpty',
|
|
323
|
+
description: 'Returns <code>true</code> if the array has at least one element',
|
|
324
|
+
examples: [
|
|
325
|
+
{ example: "['quick', 'brown', 'fox'].isNotEmpty()", evaluated: 'true' },
|
|
326
|
+
{ example: '[].isNotEmpty()', evaluated: 'false' },
|
|
327
|
+
],
|
|
328
|
+
returnType: 'boolean',
|
|
329
|
+
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-isNotEmpty',
|
|
330
|
+
};
|
|
331
|
+
first.doc = {
|
|
332
|
+
name: 'first',
|
|
333
|
+
aliases: ['head'],
|
|
334
|
+
description: 'Returns the first element of the array',
|
|
335
|
+
examples: [{ example: "['quick', 'brown', 'fox'].first()", evaluated: "'quick'" }],
|
|
336
|
+
returnType: 'any',
|
|
337
|
+
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-first',
|
|
338
|
+
};
|
|
339
|
+
last.doc = {
|
|
340
|
+
name: 'last',
|
|
341
|
+
aliases: ['tail'],
|
|
342
|
+
description: 'Returns the last element of the array',
|
|
343
|
+
examples: [{ example: "['quick', 'brown', 'fox'].last()", evaluated: "'fox'" }],
|
|
344
|
+
returnType: 'any',
|
|
345
|
+
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-last',
|
|
346
|
+
};
|
|
347
|
+
max.doc = {
|
|
348
|
+
name: 'max',
|
|
349
|
+
description: 'Returns the largest number in the array. Throws an error if there are any non-numbers.',
|
|
350
|
+
examples: [{ example: '[1, 12, 5].max()', evaluated: '12' }],
|
|
351
|
+
returnType: 'number',
|
|
352
|
+
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-max',
|
|
353
|
+
};
|
|
354
|
+
min.doc = {
|
|
355
|
+
name: 'min',
|
|
356
|
+
description: 'Returns the smallest number in the array. Throws an error if there are any non-numbers.',
|
|
357
|
+
examples: [{ example: '[12, 1, 5].min()', evaluated: '1' }],
|
|
358
|
+
returnType: 'number',
|
|
359
|
+
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-min',
|
|
360
|
+
};
|
|
361
|
+
randomItem.doc = {
|
|
362
|
+
name: 'randomItem',
|
|
363
|
+
description: 'Returns a randomly-chosen element from the array',
|
|
364
|
+
examples: [
|
|
365
|
+
{ example: "['quick', 'brown', 'fox'].randomItem()", evaluated: "'brown'" },
|
|
366
|
+
{ example: "['quick', 'brown', 'fox'].randomItem()", evaluated: "'quick'" },
|
|
367
|
+
],
|
|
368
|
+
returnType: 'any',
|
|
369
|
+
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-randomItem',
|
|
370
|
+
};
|
|
371
|
+
sum.doc = {
|
|
372
|
+
name: 'sum',
|
|
373
|
+
description: 'Returns the total of all the numbers in the array. Throws an error if there are any non-numbers.',
|
|
374
|
+
examples: [{ example: '[12, 1, 5].sum()', evaluated: '18' }],
|
|
375
|
+
returnType: 'number',
|
|
376
|
+
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-sum',
|
|
377
|
+
};
|
|
378
|
+
chunk.doc = {
|
|
379
|
+
name: 'chunk',
|
|
380
|
+
description: 'Splits the array into an array of sub-arrays, each with the given length',
|
|
381
|
+
examples: [{ example: '[1, 2, 3, 4, 5, 6].chunk(2)', evaluated: '[[1,2],[3,4],[5,6]]' }],
|
|
382
|
+
returnType: 'Array',
|
|
383
|
+
args: [
|
|
384
|
+
{
|
|
385
|
+
name: 'length',
|
|
386
|
+
optional: false,
|
|
387
|
+
description: 'The number of elements in each chunk',
|
|
388
|
+
type: 'number',
|
|
634
389
|
},
|
|
635
|
-
|
|
636
|
-
|
|
390
|
+
],
|
|
391
|
+
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-chunk',
|
|
392
|
+
};
|
|
393
|
+
difference.doc = {
|
|
394
|
+
name: 'difference',
|
|
395
|
+
description: "Compares two arrays. Returns all elements in the base array that aren't present\nin <code>otherArray</code>.",
|
|
396
|
+
examples: [{ example: '[1, 2, 3].difference([2, 3])', evaluated: '[1]' }],
|
|
397
|
+
returnType: 'Array',
|
|
398
|
+
args: [
|
|
399
|
+
{
|
|
400
|
+
name: 'otherArray',
|
|
401
|
+
optional: false,
|
|
402
|
+
description: 'The array to compare to the base array',
|
|
403
|
+
type: 'Array',
|
|
404
|
+
},
|
|
405
|
+
],
|
|
406
|
+
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-difference',
|
|
407
|
+
};
|
|
408
|
+
intersection.doc = {
|
|
409
|
+
name: 'intersection',
|
|
410
|
+
description: 'Compares two arrays. Returns all elements in the base array that are also present in the other array.',
|
|
411
|
+
examples: [{ example: '[1, 2].intersection([2, 3])', evaluated: '[2]' }],
|
|
412
|
+
returnType: 'Array',
|
|
413
|
+
args: [
|
|
414
|
+
{
|
|
415
|
+
name: 'otherArray',
|
|
416
|
+
optional: false,
|
|
417
|
+
description: 'The array to compare to the base array',
|
|
418
|
+
type: 'Array',
|
|
419
|
+
},
|
|
420
|
+
],
|
|
421
|
+
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-intersection',
|
|
422
|
+
};
|
|
423
|
+
merge.doc = {
|
|
424
|
+
name: 'merge',
|
|
425
|
+
description: 'Merges two Object-arrays into one object by merging the key-value pairs of each element.',
|
|
426
|
+
examples: [
|
|
427
|
+
{
|
|
428
|
+
example: "[{ name: 'Nathan' }, { age: 42 }].merge([{ city: 'Berlin' }, { country: 'Germany' }])",
|
|
429
|
+
evaluated: "{ name: 'Nathan', age: 42, city: 'Berlin', country: 'Germany' }",
|
|
430
|
+
},
|
|
431
|
+
],
|
|
432
|
+
returnType: 'Object',
|
|
433
|
+
args: [
|
|
434
|
+
{
|
|
435
|
+
name: 'otherArray',
|
|
436
|
+
optional: false,
|
|
437
|
+
description: 'The array to merge into the base array',
|
|
438
|
+
type: 'Array',
|
|
439
|
+
},
|
|
440
|
+
],
|
|
441
|
+
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-merge',
|
|
442
|
+
};
|
|
443
|
+
pluck.doc = {
|
|
444
|
+
name: 'pluck',
|
|
445
|
+
description: "Returns an array containing the values of the given field(s) in each Object of the array. Ignores any array elements that aren't Objects or don't have a key matching the field name(s) provided.",
|
|
446
|
+
examples: [
|
|
447
|
+
{
|
|
448
|
+
example: "[{ name: 'Nathan', age: 42 },{ name: 'Jan', city: 'Berlin' }].pluck('name')",
|
|
449
|
+
evaluated: '["Nathan", "Jan"]',
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
example: "[{ name: 'Nathan', age: 42 },{ name: 'Jan', city: 'Berlin' }].pluck('age')",
|
|
453
|
+
evaluated: '[42]',
|
|
454
|
+
},
|
|
455
|
+
],
|
|
456
|
+
returnType: 'Array',
|
|
457
|
+
args: [
|
|
458
|
+
{
|
|
459
|
+
name: 'fieldNames',
|
|
460
|
+
optional: false,
|
|
461
|
+
variadic: true,
|
|
462
|
+
description: 'The keys to retrieve the value of',
|
|
463
|
+
type: 'string',
|
|
464
|
+
},
|
|
465
|
+
],
|
|
466
|
+
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-pluck',
|
|
467
|
+
};
|
|
468
|
+
renameKeys.doc = {
|
|
469
|
+
name: 'renameKeys',
|
|
470
|
+
description: 'Changes all matching keys (field names) of any Objects in the array. Rename more than one key by\nadding extra arguments, i.e. <code>from1, to1, from2, to2, ...</code>.',
|
|
471
|
+
examples: [
|
|
472
|
+
{
|
|
473
|
+
example: "[{ name: 'bob' }, { name: 'meg' }].renameKeys('name', 'x')",
|
|
474
|
+
evaluated: "[{ x: 'bob' }, { x: 'meg' }]",
|
|
475
|
+
},
|
|
476
|
+
],
|
|
477
|
+
returnType: 'Array',
|
|
478
|
+
args: [
|
|
479
|
+
{
|
|
480
|
+
name: 'from',
|
|
481
|
+
optional: false,
|
|
482
|
+
description: 'The key to rename',
|
|
483
|
+
type: 'string',
|
|
484
|
+
},
|
|
485
|
+
{ name: 'to', optional: false, description: 'The new key name', type: 'string' },
|
|
486
|
+
],
|
|
487
|
+
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-renameKeys',
|
|
488
|
+
};
|
|
489
|
+
smartJoin.doc = {
|
|
490
|
+
name: 'smartJoin',
|
|
491
|
+
description: 'Creates a single Object from an array of Objects. Each Object in the array provides one field for the returned Object. Each Object in the array must contain a field with the key name and a field with the value.',
|
|
492
|
+
examples: [
|
|
493
|
+
{
|
|
494
|
+
example: "[{ field: 'age', value: 2 }, { field: 'city', value: 'Berlin' }].smartJoin('field', 'value')",
|
|
495
|
+
evaluated: "{ age: 2, city: 'Berlin' }",
|
|
496
|
+
},
|
|
497
|
+
],
|
|
498
|
+
returnType: 'Object',
|
|
499
|
+
args: [
|
|
500
|
+
{
|
|
501
|
+
name: 'keyField',
|
|
502
|
+
optional: false,
|
|
503
|
+
description: 'The field in each Object containing the key name',
|
|
504
|
+
type: 'string',
|
|
505
|
+
},
|
|
506
|
+
{
|
|
507
|
+
name: 'nameField',
|
|
508
|
+
optional: false,
|
|
509
|
+
description: 'The field in each Object containing the value',
|
|
510
|
+
type: 'string',
|
|
511
|
+
},
|
|
512
|
+
],
|
|
513
|
+
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-smartJoin',
|
|
514
|
+
};
|
|
515
|
+
union.doc = {
|
|
516
|
+
name: 'union',
|
|
517
|
+
description: 'Concatenates two arrays and then removes any duplicates',
|
|
518
|
+
examples: [{ example: '[1, 2].union([2, 3])', evaluated: '[1, 2, 3]' }],
|
|
519
|
+
returnType: 'Array',
|
|
520
|
+
args: [
|
|
521
|
+
{
|
|
522
|
+
name: 'otherArray',
|
|
523
|
+
optional: false,
|
|
524
|
+
description: 'The array to union with the base array',
|
|
525
|
+
type: 'Array',
|
|
526
|
+
},
|
|
527
|
+
],
|
|
528
|
+
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-union',
|
|
529
|
+
};
|
|
530
|
+
unique.doc = {
|
|
531
|
+
name: 'unique',
|
|
532
|
+
description: 'Removes any duplicate elements from the array',
|
|
533
|
+
examples: [
|
|
534
|
+
{ example: "['quick', 'brown', 'quick'].unique()", evaluated: "['quick', 'brown']" },
|
|
535
|
+
{
|
|
536
|
+
example: "[{ name: 'Nathan', age: 42 }, { name: 'Nathan', age: 22 }].unique()",
|
|
537
|
+
evaluated: "[{ name: 'Nathan', age: 42 }, { name: 'Nathan', age: 22 }]",
|
|
538
|
+
},
|
|
539
|
+
{
|
|
540
|
+
example: "[{ name: 'Nathan', age: 42 }, { name: 'Nathan', age: 22 }].unique('name')",
|
|
541
|
+
evaluated: "[{ name: 'Nathan', age: 42 }]",
|
|
542
|
+
},
|
|
543
|
+
],
|
|
544
|
+
returnType: 'any',
|
|
545
|
+
aliases: ['removeDuplicates'],
|
|
546
|
+
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-unique',
|
|
547
|
+
args: [
|
|
548
|
+
{
|
|
549
|
+
name: 'fieldNames',
|
|
550
|
+
optional: false,
|
|
551
|
+
variadic: true,
|
|
552
|
+
description: 'The object keys to check for equality',
|
|
553
|
+
type: 'any',
|
|
554
|
+
},
|
|
555
|
+
],
|
|
556
|
+
};
|
|
557
|
+
toJsonString.doc = {
|
|
558
|
+
name: 'toJsonString',
|
|
559
|
+
description: "Converts the array to a JSON string. The same as JavaScript's <code>JSON.stringify()</code>.",
|
|
560
|
+
examples: [
|
|
561
|
+
{
|
|
562
|
+
example: "['quick', 'brown', 'fox'].toJsonString()",
|
|
563
|
+
evaluated: '\'["quick","brown","fox"]\'',
|
|
564
|
+
},
|
|
565
|
+
],
|
|
566
|
+
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-toJsonString',
|
|
567
|
+
returnType: 'string',
|
|
568
|
+
};
|
|
569
|
+
append.doc = {
|
|
570
|
+
name: 'append',
|
|
571
|
+
aliases: ['push'],
|
|
572
|
+
description: 'Adds new elements to the end of the array. Similar to <code>push()</code>, but returns the modified array. Consider using spread syntax instead (see examples).',
|
|
573
|
+
examples: [
|
|
574
|
+
{ example: "['forget', 'me'].append('not')", evaluated: "['forget', 'me', 'not']" },
|
|
575
|
+
{ example: '[9, 0, 2].append(1, 0)', evaluated: '[9, 0, 2, 1, 0]' },
|
|
576
|
+
{
|
|
577
|
+
example: '[...[9, 0, 2], 1, 0]',
|
|
578
|
+
evaluated: '[9, 0, 2, 1, 0]',
|
|
579
|
+
description: 'Consider using spread syntax instead',
|
|
580
|
+
},
|
|
581
|
+
],
|
|
582
|
+
docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-append',
|
|
583
|
+
returnType: 'Array',
|
|
584
|
+
args: [
|
|
585
|
+
{
|
|
586
|
+
name: 'elements',
|
|
587
|
+
optional: false,
|
|
588
|
+
variadic: true,
|
|
589
|
+
description: 'The elements to append, in order',
|
|
590
|
+
type: 'any',
|
|
591
|
+
},
|
|
592
|
+
],
|
|
593
|
+
};
|
|
594
|
+
const removeDuplicates = unique.bind({});
|
|
595
|
+
removeDuplicates.doc = { ...unique.doc, hidden: true };
|
|
596
|
+
exports.arrayExtensions = {
|
|
597
|
+
typeName: 'Array',
|
|
598
|
+
functions: {
|
|
599
|
+
removeDuplicates,
|
|
600
|
+
unique,
|
|
601
|
+
first,
|
|
602
|
+
last,
|
|
603
|
+
pluck,
|
|
604
|
+
randomItem,
|
|
605
|
+
sum,
|
|
606
|
+
min,
|
|
607
|
+
max,
|
|
608
|
+
average,
|
|
609
|
+
isNotEmpty,
|
|
610
|
+
isEmpty,
|
|
611
|
+
compact,
|
|
612
|
+
smartJoin,
|
|
613
|
+
chunk,
|
|
614
|
+
renameKeys,
|
|
615
|
+
merge,
|
|
616
|
+
union,
|
|
617
|
+
difference,
|
|
618
|
+
intersection,
|
|
619
|
+
append,
|
|
620
|
+
toJsonString,
|
|
621
|
+
toInt,
|
|
622
|
+
toFloat,
|
|
623
|
+
toBoolean,
|
|
624
|
+
toDateTime,
|
|
625
|
+
},
|
|
626
|
+
};
|
|
637
627
|
//# sourceMappingURL=array-extensions.js.map
|