@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.
Files changed (109) hide show
  1. package/dist/cjs/bridge/bridge-messages.d.ts +8 -8
  2. package/dist/cjs/bridge/bridge-messages.js +234 -244
  3. package/dist/cjs/bridge/bridge-messages.js.map +1 -1
  4. package/dist/cjs/bridge/isolated-vm-bridge.d.ts.map +1 -1
  5. package/dist/cjs/bridge/isolated-vm-bridge.js +644 -654
  6. package/dist/cjs/bridge/isolated-vm-bridge.js.map +1 -1
  7. package/dist/cjs/build.tsbuildinfo +1 -1
  8. package/dist/cjs/evaluator/error-classification.js +15 -25
  9. package/dist/cjs/evaluator/error-classification.js.map +1 -1
  10. package/dist/cjs/evaluator/expression-evaluator.d.ts.map +1 -1
  11. package/dist/cjs/evaluator/expression-evaluator.js +152 -162
  12. package/dist/cjs/evaluator/expression-evaluator.js.map +1 -1
  13. package/dist/cjs/evaluator/lru-cache.d.ts.map +1 -1
  14. package/dist/cjs/evaluator/lru-cache.js +35 -45
  15. package/dist/cjs/evaluator/lru-cache.js.map +1 -1
  16. package/dist/cjs/extensions/array-extensions.js +589 -599
  17. package/dist/cjs/extensions/array-extensions.js.map +1 -1
  18. package/dist/cjs/extensions/boolean-extensions.js +38 -48
  19. package/dist/cjs/extensions/boolean-extensions.js.map +1 -1
  20. package/dist/cjs/extensions/date-extensions.js +500 -510
  21. package/dist/cjs/extensions/date-extensions.js.map +1 -1
  22. package/dist/cjs/extensions/expression-extension-error.d.ts.map +1 -1
  23. package/dist/cjs/extensions/expression-extension-error.js +12 -22
  24. package/dist/cjs/extensions/expression-extension-error.js.map +1 -1
  25. package/dist/cjs/extensions/extend.js +162 -172
  26. package/dist/cjs/extensions/extend.js.map +1 -1
  27. package/dist/cjs/extensions/extensions.js +2 -12
  28. package/dist/cjs/extensions/function-extensions.d.ts +10 -18
  29. package/dist/cjs/extensions/function-extensions.d.ts.map +1 -1
  30. package/dist/cjs/extensions/function-extensions.js +78 -88
  31. package/dist/cjs/extensions/function-extensions.js.map +1 -1
  32. package/dist/cjs/extensions/number-extensions.js +225 -235
  33. package/dist/cjs/extensions/number-extensions.js.map +1 -1
  34. package/dist/cjs/extensions/object-extensions.js +286 -296
  35. package/dist/cjs/extensions/object-extensions.js.map +1 -1
  36. package/dist/cjs/extensions/string-extensions.d.ts +1 -1
  37. package/dist/cjs/extensions/string-extensions.d.ts.map +1 -1
  38. package/dist/cjs/extensions/string-extensions.js +758 -768
  39. package/dist/cjs/extensions/string-extensions.js.map +1 -1
  40. package/dist/cjs/extensions/utils.d.ts.map +1 -1
  41. package/dist/cjs/extensions/utils.js +28 -38
  42. package/dist/cjs/extensions/utils.js.map +1 -1
  43. package/dist/cjs/index.js +32 -42
  44. package/dist/cjs/index.js.map +1 -1
  45. package/dist/cjs/observability/metrics.d.ts +27 -27
  46. package/dist/cjs/observability/metrics.d.ts.map +1 -1
  47. package/dist/cjs/observability/metrics.js +59 -69
  48. package/dist/cjs/observability/metrics.js.map +1 -1
  49. package/dist/cjs/observability/noop-provider.js +28 -38
  50. package/dist/cjs/observability/noop-provider.js.map +1 -1
  51. package/dist/cjs/pool/idle-scaling-pool.d.ts.map +1 -1
  52. package/dist/cjs/pool/idle-scaling-pool.js +134 -144
  53. package/dist/cjs/pool/idle-scaling-pool.js.map +1 -1
  54. package/dist/cjs/pool/isolate-pool.d.ts.map +1 -1
  55. package/dist/cjs/pool/isolate-pool.js +101 -111
  56. package/dist/cjs/pool/isolate-pool.js.map +1 -1
  57. package/dist/cjs/runtime/context.js +418 -428
  58. package/dist/cjs/runtime/context.js.map +1 -1
  59. package/dist/cjs/runtime/index.js +26 -36
  60. package/dist/cjs/runtime/index.js.map +1 -1
  61. package/dist/cjs/runtime/jmespath.js +72 -82
  62. package/dist/cjs/runtime/jmespath.js.map +1 -1
  63. package/dist/cjs/runtime/lazy-proxy.js +238 -248
  64. package/dist/cjs/runtime/lazy-proxy.js.map +1 -1
  65. package/dist/cjs/runtime/safe-globals.d.ts.map +1 -1
  66. package/dist/cjs/runtime/safe-globals.js +134 -144
  67. package/dist/cjs/runtime/safe-globals.js.map +1 -1
  68. package/dist/cjs/runtime/serialize.js +54 -64
  69. package/dist/cjs/runtime/serialize.js.map +1 -1
  70. package/dist/cjs/runtime/utils.js +20 -30
  71. package/dist/cjs/runtime/utils.js.map +1 -1
  72. package/dist/cjs/types/bridge.js +15 -25
  73. package/dist/cjs/types/bridge.js.map +1 -1
  74. package/dist/cjs/types/evaluator.d.ts.map +1 -1
  75. package/dist/cjs/types/evaluator.js +35 -45
  76. package/dist/cjs/types/evaluator.js.map +1 -1
  77. package/dist/cjs/types/index.js +14 -24
  78. package/dist/cjs/types/index.js.map +1 -1
  79. package/dist/cjs/types/runtime.d.ts.map +1 -1
  80. package/dist/cjs/types/runtime.js +27 -37
  81. package/dist/cjs/types/runtime.js.map +1 -1
  82. package/dist/esm/bridge/bridge-messages.d.ts +8 -8
  83. package/dist/esm/bridge/isolated-vm-bridge.d.ts.map +1 -1
  84. package/dist/esm/bridge/isolated-vm-bridge.js.map +1 -1
  85. package/dist/esm/build.tsbuildinfo +1 -1
  86. package/dist/esm/evaluator/expression-evaluator.d.ts.map +1 -1
  87. package/dist/esm/evaluator/lru-cache.d.ts.map +1 -1
  88. package/dist/esm/evaluator/lru-cache.js.map +1 -1
  89. package/dist/esm/extensions/expression-extension-error.d.ts.map +1 -1
  90. package/dist/esm/extensions/function-extensions.d.ts +10 -18
  91. package/dist/esm/extensions/function-extensions.d.ts.map +1 -1
  92. package/dist/esm/extensions/number-extensions.js.map +1 -1
  93. package/dist/esm/extensions/string-extensions.d.ts +1 -1
  94. package/dist/esm/extensions/string-extensions.d.ts.map +1 -1
  95. package/dist/esm/extensions/string-extensions.js.map +1 -1
  96. package/dist/esm/extensions/utils.d.ts.map +1 -1
  97. package/dist/esm/observability/metrics.d.ts +27 -27
  98. package/dist/esm/observability/metrics.d.ts.map +1 -1
  99. package/dist/esm/pool/idle-scaling-pool.d.ts.map +1 -1
  100. package/dist/esm/pool/idle-scaling-pool.js.map +1 -1
  101. package/dist/esm/pool/isolate-pool.d.ts.map +1 -1
  102. package/dist/esm/pool/isolate-pool.js.map +1 -1
  103. package/dist/esm/runtime/lazy-proxy.js.map +1 -1
  104. package/dist/esm/runtime/safe-globals.d.ts.map +1 -1
  105. package/dist/esm/types/evaluator.d.ts.map +1 -1
  106. package/dist/esm/types/evaluator.js.map +1 -1
  107. package/dist/esm/types/runtime.d.ts.map +1 -1
  108. package/dist/esm/types/runtime.js.map +1 -1
  109. 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
- (function (factory) {
5
- if (typeof module === "object" && typeof module.exports === "object") {
6
- var v = factory(require, exports);
7
- if (v !== undefined) module.exports = v;
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
- else if (typeof define === "function" && define.amd) {
10
- define(["require", "exports", "lodash/isEqual", "lodash/random", "lodash/uniqWith", "./expression-extension-error", "./object-extensions"], factory);
41
+ if (!extraArgs || extraArgs.length === 0) {
42
+ return value;
11
43
  }
12
- })(function (require, exports) {
13
- "use strict";
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.arrayExtensions = void 0;
16
- exports.average = average;
17
- exports.toJsonString = toJsonString;
18
- exports.toInt = toInt;
19
- exports.toFloat = toFloat;
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
- if (p.length > 0) {
64
- pluckedFromObject.push(p.length === 1 ? p[0] : p);
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
- function sum(value) {
93
- ensureNumberArray(value, { fnName: 'sum' });
94
- return value.reduce((p, c) => {
95
- if (typeof c === 'string') {
96
- return p + parseFloat(c);
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
- function min(value) {
105
- ensureNumberArray(value, { fnName: 'min' });
106
- return Math.min(...value.map((v) => {
107
- if (typeof v === 'string') {
108
- return parseFloat(v);
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
- return sum(value) / value.length;
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
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-return
157
- return value.reduce((o, v) => {
158
- if (typeof v === 'object' && v !== null && keyField in v && valueField in v) {
159
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
160
- o[v[keyField]] = v[valueField];
161
- }
162
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
163
- return o;
164
- }, {});
165
- }
166
- function chunk(value, extraArgs) {
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
- const chunks = [];
172
- for (let i = 0; i < value.length; i += chunkSize) {
173
- chunks.push(value.slice(i, i + chunkSize));
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
- return chunks;
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
- function renameKeys(value, extraArgs) {
178
- if (extraArgs.length === 0 || extraArgs.length % 2 !== 0) {
179
- throw new expression_extension_error_1.ExpressionExtensionError('renameKeys(): expected an even amount of args: from1, to1 [, from2, to2, ...]. e.g. .renameKeys("name", "title")');
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 value.map((v) => {
182
- if (typeof v !== 'object' || v === null) {
183
- return v;
184
- }
185
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-explicit-any
186
- const newObj = { ...v };
187
- const chunkedArgs = chunk(extraArgs, [2]);
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
- function mergeObjects(value, extraArgs) {
201
- const [other] = extraArgs;
202
- if (!other) {
203
- return value;
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
- if (typeof other !== 'object') {
206
- throw new expression_extension_error_1.ExpressionExtensionError('merge(): expected object arg');
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
- const newObject = { ...value };
209
- for (const [key, val] of Object.entries(other)) {
210
- if (!(key in newObject)) {
211
- newObject[key] = val;
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 newObject;
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
- function merge(value, extraArgs) {
217
- const [others] = extraArgs;
218
- if (others === undefined) {
219
- // If there are no arguments passed, merge all objects within the array
220
- const merged = value.reduce((combined, current) => {
221
- if (current !== null && typeof current === 'object' && !Array.isArray(current)) {
222
- combined = mergeObjects(combined, [current]);
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
- const listLength = value.length > others.length ? value.length : others.length;
232
- let merged = {};
233
- for (let i = 0; i < listLength; i++) {
234
- if (value[i] !== undefined) {
235
- if (typeof value[i] === 'object' && typeof others[i] === 'object') {
236
- merged = Object.assign(merged, mergeObjects(value[i], [others[i]]));
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
- function union(value, extraArgs) {
243
- const [others] = extraArgs;
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
- function difference(value, extraArgs) {
256
- const [others] = extraArgs;
257
- if (!Array.isArray(others)) {
258
- throw new expression_extension_error_1.ExpressionExtensionError('difference(): expected array arg, e.g. .difference([1, 2, 3, 4])');
259
- }
260
- const newArr = [];
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
- function intersection(value, extraArgs) {
269
- const [others] = extraArgs;
270
- if (!Array.isArray(others)) {
271
- throw new expression_extension_error_1.ExpressionExtensionError('intersection(): expected array arg, e.g. .intersection([1, 2, 3, 4])');
272
- }
273
- const newArr = [];
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
- function append(value, extraArgs) {
287
- return value.concat(extraArgs);
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
- function toJsonString(value) {
290
- return JSON.stringify(value);
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
- function toInt() {
293
- return undefined;
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
- function toFloat() {
296
- return undefined;
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
- function toBoolean() {
299
- return undefined;
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
- function toDateTime() {
302
- return undefined;
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
- average.doc = {
305
- name: 'average',
306
- aliases: ['mean'],
307
- description: 'Returns the average of the numbers in the array. Throws an error if there are any non-numbers.',
308
- examples: [{ example: '[12, 1, 5].average()', evaluated: '6' }],
309
- returnType: 'number',
310
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-average',
311
- };
312
- compact.doc = {
313
- name: 'compact',
314
- aliases: ['removeEmpty'],
315
- description: 'Removes any empty values from the array. <code>null</code>, <code>""</code> and <code>undefined</code> count as empty.',
316
- examples: [{ example: '[2, null, 1, ""].compact()', evaluated: '[2, 1]' }],
317
- returnType: 'Array',
318
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-compact',
319
- };
320
- isEmpty.doc = {
321
- name: 'isEmpty',
322
- description: 'Returns <code>true</code> if the array has no elements or is <code>null</code>',
323
- examples: [
324
- { example: '[].isEmpty()', evaluated: 'true' },
325
- { example: "['quick', 'brown', 'fox'].isEmpty()", evaluated: 'false' },
326
- ],
327
- returnType: 'boolean',
328
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-isEmpty',
329
- };
330
- isNotEmpty.doc = {
331
- name: 'isNotEmpty',
332
- description: 'Returns <code>true</code> if the array has at least one element',
333
- examples: [
334
- { example: "['quick', 'brown', 'fox'].isNotEmpty()", evaluated: 'true' },
335
- { example: '[].isNotEmpty()', evaluated: 'false' },
336
- ],
337
- returnType: 'boolean',
338
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-isNotEmpty',
339
- };
340
- first.doc = {
341
- name: 'first',
342
- aliases: ['head'],
343
- description: 'Returns the first element of the array',
344
- examples: [{ example: "['quick', 'brown', 'fox'].first()", evaluated: "'quick'" }],
345
- returnType: 'any',
346
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-first',
347
- };
348
- last.doc = {
349
- name: 'last',
350
- aliases: ['tail'],
351
- description: 'Returns the last element of the array',
352
- examples: [{ example: "['quick', 'brown', 'fox'].last()", evaluated: "'fox'" }],
353
- returnType: 'any',
354
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-last',
355
- };
356
- max.doc = {
357
- name: 'max',
358
- description: 'Returns the largest number in the array. Throws an error if there are any non-numbers.',
359
- examples: [{ example: '[1, 12, 5].max()', evaluated: '12' }],
360
- returnType: 'number',
361
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-max',
362
- };
363
- min.doc = {
364
- name: 'min',
365
- description: 'Returns the smallest number in the array. Throws an error if there are any non-numbers.',
366
- examples: [{ example: '[12, 1, 5].min()', evaluated: '1' }],
367
- returnType: 'number',
368
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-min',
369
- };
370
- randomItem.doc = {
371
- name: 'randomItem',
372
- description: 'Returns a randomly-chosen element from the array',
373
- examples: [
374
- { example: "['quick', 'brown', 'fox'].randomItem()", evaluated: "'brown'" },
375
- { example: "['quick', 'brown', 'fox'].randomItem()", evaluated: "'quick'" },
376
- ],
377
- returnType: 'any',
378
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-randomItem',
379
- };
380
- sum.doc = {
381
- name: 'sum',
382
- description: 'Returns the total of all the numbers in the array. Throws an error if there are any non-numbers.',
383
- examples: [{ example: '[12, 1, 5].sum()', evaluated: '18' }],
384
- returnType: 'number',
385
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-sum',
386
- };
387
- chunk.doc = {
388
- name: 'chunk',
389
- description: 'Splits the array into an array of sub-arrays, each with the given length',
390
- examples: [{ example: '[1, 2, 3, 4, 5, 6].chunk(2)', evaluated: '[[1,2],[3,4],[5,6]]' }],
391
- returnType: 'Array',
392
- args: [
393
- {
394
- name: 'length',
395
- optional: false,
396
- description: 'The number of elements in each chunk',
397
- type: 'number',
398
- },
399
- ],
400
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-chunk',
401
- };
402
- difference.doc = {
403
- name: 'difference',
404
- description: "Compares two arrays. Returns all elements in the base array that aren't present\nin <code>otherArray</code>.",
405
- examples: [{ example: '[1, 2, 3].difference([2, 3])', evaluated: '[1]' }],
406
- returnType: 'Array',
407
- args: [
408
- {
409
- name: 'otherArray',
410
- optional: false,
411
- description: 'The array to compare to the base array',
412
- type: 'Array',
413
- },
414
- ],
415
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/arrays/#array-difference',
416
- };
417
- intersection.doc = {
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