@n8n/expression-runtime 0.21.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) 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 +633 -643
  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 +7 -1
  11. package/dist/cjs/evaluator/expression-evaluator.d.ts.map +1 -1
  12. package/dist/cjs/evaluator/expression-evaluator.js +152 -155
  13. package/dist/cjs/evaluator/expression-evaluator.js.map +1 -1
  14. package/dist/cjs/evaluator/lru-cache.d.ts.map +1 -1
  15. package/dist/cjs/evaluator/lru-cache.js +35 -45
  16. package/dist/cjs/evaluator/lru-cache.js.map +1 -1
  17. package/dist/cjs/extensions/array-extensions.js +589 -599
  18. package/dist/cjs/extensions/array-extensions.js.map +1 -1
  19. package/dist/cjs/extensions/boolean-extensions.js +38 -48
  20. package/dist/cjs/extensions/boolean-extensions.js.map +1 -1
  21. package/dist/cjs/extensions/date-extensions.js +500 -510
  22. package/dist/cjs/extensions/date-extensions.js.map +1 -1
  23. package/dist/cjs/extensions/expression-extension-error.d.ts.map +1 -1
  24. package/dist/cjs/extensions/expression-extension-error.js +12 -22
  25. package/dist/cjs/extensions/expression-extension-error.js.map +1 -1
  26. package/dist/cjs/extensions/extend.js +162 -172
  27. package/dist/cjs/extensions/extend.js.map +1 -1
  28. package/dist/cjs/extensions/extensions.js +2 -12
  29. package/dist/cjs/extensions/function-extensions.d.ts +10 -18
  30. package/dist/cjs/extensions/function-extensions.d.ts.map +1 -1
  31. package/dist/cjs/extensions/function-extensions.js +78 -88
  32. package/dist/cjs/extensions/function-extensions.js.map +1 -1
  33. package/dist/cjs/extensions/number-extensions.js +225 -235
  34. package/dist/cjs/extensions/number-extensions.js.map +1 -1
  35. package/dist/cjs/extensions/object-extensions.js +286 -296
  36. package/dist/cjs/extensions/object-extensions.js.map +1 -1
  37. package/dist/cjs/extensions/string-extensions.d.ts +1 -1
  38. package/dist/cjs/extensions/string-extensions.d.ts.map +1 -1
  39. package/dist/cjs/extensions/string-extensions.js +758 -768
  40. package/dist/cjs/extensions/string-extensions.js.map +1 -1
  41. package/dist/cjs/extensions/utils.d.ts.map +1 -1
  42. package/dist/cjs/extensions/utils.js +28 -38
  43. package/dist/cjs/extensions/utils.js.map +1 -1
  44. package/dist/cjs/index.js +32 -42
  45. package/dist/cjs/index.js.map +1 -1
  46. package/dist/cjs/observability/metrics.d.ts +27 -27
  47. package/dist/cjs/observability/metrics.d.ts.map +1 -1
  48. package/dist/cjs/observability/metrics.js +59 -69
  49. package/dist/cjs/observability/metrics.js.map +1 -1
  50. package/dist/cjs/observability/noop-provider.js +28 -38
  51. package/dist/cjs/observability/noop-provider.js.map +1 -1
  52. package/dist/cjs/pool/idle-scaling-pool.d.ts.map +1 -1
  53. package/dist/cjs/pool/idle-scaling-pool.js +134 -144
  54. package/dist/cjs/pool/idle-scaling-pool.js.map +1 -1
  55. package/dist/cjs/pool/isolate-pool.d.ts.map +1 -1
  56. package/dist/cjs/pool/isolate-pool.js +101 -111
  57. package/dist/cjs/pool/isolate-pool.js.map +1 -1
  58. package/dist/cjs/runtime/context.js +418 -428
  59. package/dist/cjs/runtime/context.js.map +1 -1
  60. package/dist/cjs/runtime/index.js +26 -36
  61. package/dist/cjs/runtime/index.js.map +1 -1
  62. package/dist/cjs/runtime/jmespath.js +72 -82
  63. package/dist/cjs/runtime/jmespath.js.map +1 -1
  64. package/dist/cjs/runtime/lazy-proxy.js +238 -248
  65. package/dist/cjs/runtime/lazy-proxy.js.map +1 -1
  66. package/dist/cjs/runtime/safe-globals.d.ts.map +1 -1
  67. package/dist/cjs/runtime/safe-globals.js +134 -144
  68. package/dist/cjs/runtime/safe-globals.js.map +1 -1
  69. package/dist/cjs/runtime/serialize.js +54 -64
  70. package/dist/cjs/runtime/serialize.js.map +1 -1
  71. package/dist/cjs/runtime/utils.js +20 -30
  72. package/dist/cjs/runtime/utils.js.map +1 -1
  73. package/dist/cjs/types/bridge.js +15 -25
  74. package/dist/cjs/types/bridge.js.map +1 -1
  75. package/dist/cjs/types/evaluator.d.ts +5 -1
  76. package/dist/cjs/types/evaluator.d.ts.map +1 -1
  77. package/dist/cjs/types/evaluator.js +35 -45
  78. package/dist/cjs/types/evaluator.js.map +1 -1
  79. package/dist/cjs/types/index.js +14 -24
  80. package/dist/cjs/types/index.js.map +1 -1
  81. package/dist/cjs/types/runtime.d.ts.map +1 -1
  82. package/dist/cjs/types/runtime.js +27 -37
  83. package/dist/cjs/types/runtime.js.map +1 -1
  84. package/dist/esm/bridge/bridge-messages.d.ts +8 -8
  85. package/dist/esm/bridge/isolated-vm-bridge.d.ts.map +1 -1
  86. package/dist/esm/bridge/isolated-vm-bridge.js.map +1 -1
  87. package/dist/esm/build.tsbuildinfo +1 -1
  88. package/dist/esm/evaluator/expression-evaluator.d.ts +7 -1
  89. package/dist/esm/evaluator/expression-evaluator.d.ts.map +1 -1
  90. package/dist/esm/evaluator/expression-evaluator.js +8 -1
  91. package/dist/esm/evaluator/expression-evaluator.js.map +1 -1
  92. package/dist/esm/evaluator/lru-cache.d.ts.map +1 -1
  93. package/dist/esm/evaluator/lru-cache.js.map +1 -1
  94. package/dist/esm/extensions/expression-extension-error.d.ts.map +1 -1
  95. package/dist/esm/extensions/function-extensions.d.ts +10 -18
  96. package/dist/esm/extensions/function-extensions.d.ts.map +1 -1
  97. package/dist/esm/extensions/number-extensions.js.map +1 -1
  98. package/dist/esm/extensions/string-extensions.d.ts +1 -1
  99. package/dist/esm/extensions/string-extensions.d.ts.map +1 -1
  100. package/dist/esm/extensions/string-extensions.js.map +1 -1
  101. package/dist/esm/extensions/utils.d.ts.map +1 -1
  102. package/dist/esm/observability/metrics.d.ts +27 -27
  103. package/dist/esm/observability/metrics.d.ts.map +1 -1
  104. package/dist/esm/pool/idle-scaling-pool.d.ts.map +1 -1
  105. package/dist/esm/pool/idle-scaling-pool.js.map +1 -1
  106. package/dist/esm/pool/isolate-pool.d.ts.map +1 -1
  107. package/dist/esm/pool/isolate-pool.js.map +1 -1
  108. package/dist/esm/runtime/lazy-proxy.js.map +1 -1
  109. package/dist/esm/runtime/safe-globals.d.ts.map +1 -1
  110. package/dist/esm/types/evaluator.d.ts +5 -1
  111. package/dist/esm/types/evaluator.d.ts.map +1 -1
  112. package/dist/esm/types/evaluator.js.map +1 -1
  113. package/dist/esm/types/runtime.d.ts.map +1 -1
  114. package/dist/esm/types/runtime.js.map +1 -1
  115. package/package.json +7 -6
@@ -1,309 +1,299 @@
1
- (function (factory) {
2
- if (typeof module === "object" && typeof module.exports === "object") {
3
- var v = factory(require, exports);
4
- if (v !== undefined) module.exports = v;
5
- }
6
- else if (typeof define === "function" && define.amd) {
7
- define(["require", "exports", "./expression-extension-error"], factory);
8
- }
9
- })(function (require, exports) {
10
- "use strict";
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.objectExtensions = void 0;
13
- exports.compact = compact;
14
- exports.urlEncode = urlEncode;
15
- exports.toJsonString = toJsonString;
16
- exports.toInt = toInt;
17
- exports.toFloat = toFloat;
18
- exports.toBoolean = toBoolean;
19
- exports.toDateTime = toDateTime;
20
- const expression_extension_error_1 = require("./expression-extension-error");
21
- function isEmpty(value) {
22
- return Object.keys(value).length === 0;
23
- }
24
- function isNotEmpty(value) {
25
- return !isEmpty(value);
26
- }
27
- function keys(value) {
28
- return Object.keys(value);
29
- }
30
- function values(value) {
31
- return Object.values(value);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.objectExtensions = void 0;
4
+ exports.compact = compact;
5
+ exports.urlEncode = urlEncode;
6
+ exports.toJsonString = toJsonString;
7
+ exports.toInt = toInt;
8
+ exports.toFloat = toFloat;
9
+ exports.toBoolean = toBoolean;
10
+ exports.toDateTime = toDateTime;
11
+ const expression_extension_error_1 = require("./expression-extension-error");
12
+ function isEmpty(value) {
13
+ return Object.keys(value).length === 0;
14
+ }
15
+ function isNotEmpty(value) {
16
+ return !isEmpty(value);
17
+ }
18
+ function keys(value) {
19
+ return Object.keys(value);
20
+ }
21
+ function values(value) {
22
+ return Object.values(value);
23
+ }
24
+ function hasField(value, extraArgs) {
25
+ const [name] = extraArgs;
26
+ return name in value;
27
+ }
28
+ function removeField(value, extraArgs) {
29
+ const [name] = extraArgs;
30
+ if (name in value) {
31
+ const newObject = { ...value };
32
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
33
+ delete newObject[name];
34
+ return newObject;
32
35
  }
33
- function hasField(value, extraArgs) {
34
- const [name] = extraArgs;
35
- return name in value;
36
+ return value;
37
+ }
38
+ function removeFieldsContaining(value, extraArgs) {
39
+ const [match] = extraArgs;
40
+ if (typeof match !== 'string' || match === '') {
41
+ throw new expression_extension_error_1.ExpressionExtensionError('removeFieldsContaining(): expected non-empty string arg');
36
42
  }
37
- function removeField(value, extraArgs) {
38
- const [name] = extraArgs;
39
- if (name in value) {
40
- const newObject = { ...value };
43
+ const newObject = { ...value };
44
+ for (const [key, val] of Object.entries(value)) {
45
+ if (typeof val === 'string' && val.includes(match)) {
41
46
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
42
- delete newObject[name];
43
- return newObject;
47
+ delete newObject[key];
44
48
  }
45
- return value;
46
49
  }
47
- function removeFieldsContaining(value, extraArgs) {
48
- const [match] = extraArgs;
49
- if (typeof match !== 'string' || match === '') {
50
- throw new expression_extension_error_1.ExpressionExtensionError('removeFieldsContaining(): expected non-empty string arg');
51
- }
52
- const newObject = { ...value };
53
- for (const [key, val] of Object.entries(value)) {
54
- if (typeof val === 'string' && val.includes(match)) {
55
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
56
- delete newObject[key];
57
- }
58
- }
59
- return newObject;
50
+ return newObject;
51
+ }
52
+ function keepFieldsContaining(value, extraArgs) {
53
+ const [match] = extraArgs;
54
+ if (typeof match !== 'string' || match === '') {
55
+ throw new expression_extension_error_1.ExpressionExtensionError('argument of keepFieldsContaining must be a non-empty string');
60
56
  }
61
- function keepFieldsContaining(value, extraArgs) {
62
- const [match] = extraArgs;
63
- if (typeof match !== 'string' || match === '') {
64
- throw new expression_extension_error_1.ExpressionExtensionError('argument of keepFieldsContaining must be a non-empty string');
65
- }
66
- const newObject = { ...value };
67
- for (const [key, val] of Object.entries(value)) {
68
- if (typeof val !== 'string' || (typeof val === 'string' && !val.includes(match))) {
69
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
70
- delete newObject[key];
71
- }
57
+ const newObject = { ...value };
58
+ for (const [key, val] of Object.entries(value)) {
59
+ if (typeof val !== 'string' || (typeof val === 'string' && !val.includes(match))) {
60
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
61
+ delete newObject[key];
72
62
  }
73
- return newObject;
74
63
  }
75
- function compact(value) {
76
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
77
- const newObj = {};
78
- for (const [key, val] of Object.entries(value)) {
79
- if (val !== null && val !== undefined && val !== 'nil' && val !== '') {
80
- if (typeof val === 'object') {
81
- if (Object.keys(val).length === 0)
82
- continue;
83
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument
84
- newObj[key] = compact(val);
85
- }
86
- else {
87
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
88
- newObj[key] = val;
89
- }
64
+ return newObject;
65
+ }
66
+ function compact(value) {
67
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
+ const newObj = {};
69
+ for (const [key, val] of Object.entries(value)) {
70
+ if (val !== null && val !== undefined && val !== 'nil' && val !== '') {
71
+ if (typeof val === 'object') {
72
+ if (Object.keys(val).length === 0)
73
+ continue;
74
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-argument
75
+ newObj[key] = compact(val);
76
+ }
77
+ else {
78
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
79
+ newObj[key] = val;
90
80
  }
91
81
  }
92
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
93
- return newObj;
94
- }
95
- // DIVERGENCE from packages/workflow/src/extensions/object-extensions.ts:
96
- // The original uses URLSearchParams which is a Web API unavailable inside the
97
- // V8 isolate. encodeURIComponent is an ECMAScript built-in available in all
98
- // V8 contexts, but it doesn't encode !'()~ which WHATWG requires. The extra
99
- // replace step covers those characters to match URLSearchParams output.
100
- function whatwgEncode(str) {
101
- return encodeURIComponent(str)
102
- .replace(/%20/g, '+')
103
- .replace(/[!'()~]/g, (c) => '%' + c.charCodeAt(0).toString(16).toUpperCase());
104
82
  }
105
- function urlEncode(value) {
106
- return Object.entries(value)
107
- .map(([k, v]) => whatwgEncode(k) + '=' + whatwgEncode(String(v)))
108
- .join('&');
109
- }
110
- function toJsonString(value) {
111
- return JSON.stringify(value);
112
- }
113
- function toInt() {
114
- return undefined;
115
- }
116
- function toFloat() {
117
- return undefined;
118
- }
119
- function toBoolean() {
120
- return undefined;
121
- }
122
- function toDateTime() {
123
- return undefined;
124
- }
125
- isEmpty.doc = {
126
- name: 'isEmpty',
127
- description: 'Returns <code>true</code> if the Object has no keys (fields) set or is <code>null</code>',
128
- examples: [
129
- { example: "({'name': 'Nathan'}).isEmpty()", evaluated: 'false' },
130
- { example: '({}).isEmpty()', evaluated: 'true' },
131
- ],
132
- returnType: 'boolean',
133
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/objects/#object-isEmpty',
134
- };
135
- isNotEmpty.doc = {
136
- name: 'isNotEmpty',
137
- description: 'Returns <code>true</code> if the Object has at least one key (field) set',
138
- examples: [
139
- { example: "({'name': 'Nathan'}).isNotEmpty()", evaluated: 'true' },
140
- { example: '({}).isNotEmpty()', evaluated: 'false' },
141
- ],
142
- returnType: 'boolean',
143
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/objects/#object-isNotEmpty',
144
- };
145
- compact.doc = {
146
- name: 'compact',
147
- description: 'Removes all fields that have empty values, i.e. are <code>null</code>, <code>undefined</code>, <code>"nil"</code> or <code>""</code>',
148
- examples: [{ example: "({ x: null, y: 2, z: '' }).compact()", evaluated: '{ y: 2 }' }],
149
- returnType: 'Object',
150
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/objects/#object-compact',
151
- };
152
- urlEncode.doc = {
153
- name: 'urlEncode',
154
- description: "Generates a URL parameter string from the Object's keys and values. Only top-level keys are supported.",
155
- examples: [
156
- {
157
- example: "({ name: 'Mr Nathan', city: 'hanoi' }).urlEncode()",
158
- evaluated: "'name=Mr+Nathan&city=hanoi'",
159
- },
160
- ],
161
- returnType: 'string',
162
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/objects/#object-urlEncode',
163
- };
164
- hasField.doc = {
165
- name: 'hasField',
166
- description: 'Returns <code>true</code> if there is a field called <code>name</code>. Only checks top-level keys. Comparison is case-sensitive.',
167
- examples: [
168
- { example: "({ name: 'Nathan', age: 42 }).hasField('name')", evaluated: 'true' },
169
- { example: "({ name: 'Nathan', age: 42 }).hasField('Name')", evaluated: 'false' },
170
- { example: "({ name: 'Nathan', age: 42 }).hasField('inventedField')", evaluated: 'false' },
171
- ],
172
- returnType: 'boolean',
173
- args: [
174
- {
175
- name: 'name',
176
- optional: false,
177
- description: 'The name of the key to search for',
178
- type: 'string',
179
- },
180
- ],
181
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/objects/#object-hasField',
182
- };
183
- removeField.doc = {
184
- name: 'removeField',
185
- aliases: ['delete'],
186
- description: "Removes a field from the Object. The same as JavaScript's <code>delete</code>.",
187
- examples: [
188
- {
189
- example: "({ name: 'Nathan', city: 'hanoi' }).removeField('name')",
190
- evaluated: "{ city: 'hanoi' }",
191
- },
192
- ],
193
- returnType: 'Object',
194
- args: [
195
- {
196
- name: 'key',
197
- optional: false,
198
- description: 'The name of the field to remove',
199
- type: 'string',
200
- },
201
- ],
202
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/objects/#object-removeField',
203
- };
204
- removeFieldsContaining.doc = {
205
- name: 'removeFieldsContaining',
206
- description: "Removes keys (fields) whose values at least partly match the given <code>value</code>. Comparison is case-sensitive. Fields that aren't strings are always kept.",
207
- examples: [
208
- {
209
- example: "({ name: 'Mr Nathan', city: 'hanoi', age: 42 }).removeFieldsContaining('Nathan')",
210
- evaluated: "{ city: 'hanoi', age: 42 }",
211
- },
212
- {
213
- example: "({ name: 'Mr Nathan', city: 'hanoi', age: 42 }).removeFieldsContaining('Han')",
214
- evaluated: '{ age: 42 }',
215
- },
216
- {
217
- example: "({ name: 'Mr Nathan', city: 'hanoi', age: 42 }).removeFieldsContaining('nathan')",
218
- evaluated: "{ name: 'Mr Nathan', city: 'hanoi', age: 42 }",
219
- },
220
- ],
221
- returnType: 'Object',
222
- args: [
223
- {
224
- name: 'value',
225
- optional: false,
226
- description: 'The text that a value must contain in order to be removed',
227
- type: 'string',
228
- },
229
- ],
230
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/objects/#object-removeFieldsContaining',
231
- };
232
- keepFieldsContaining.doc = {
233
- name: 'keepFieldsContaining',
234
- description: "Removes any fields whose values don't at least partly match the given <code>value</code>. Comparison is case-sensitive. Fields that aren't strings will always be removed.",
235
- examples: [
236
- {
237
- example: "({ name: 'Mr Nathan', city: 'hanoi', age: 42 }).keepFieldsContaining('Nathan')",
238
- evaluated: "{ name: 'Mr Nathan' }",
239
- },
240
- {
241
- example: "({ name: 'Mr Nathan', city: 'hanoi', age: 42 }).keepFieldsContaining('nathan')",
242
- evaluated: '{}',
243
- },
244
- {
245
- example: "({ name: 'Mr Nathan', city: 'hanoi', age: 42 }).keepFieldsContaining('han')",
246
- evaluated: "{ name: 'Mr Nathan', city: 'hanoi' }",
247
- },
248
- ],
249
- returnType: 'Object',
250
- args: [
251
- {
252
- name: 'value',
253
- optional: false,
254
- description: 'The text that a value must contain in order to be kept',
255
- type: 'string',
256
- },
257
- ],
258
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/objects/#object-keepFieldsContaining',
259
- };
260
- keys.doc = {
261
- name: 'keys',
262
- description: "Returns an array with all the field names (keys) the Object contains. The same as JavaScript's <code>Object.keys(obj)</code>.",
263
- examples: [{ example: "({ name: 'Mr Nathan', age: 42 }).keys()", evaluated: "['name', 'age']" }],
264
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/objects/#object-keys',
265
- returnType: 'Array',
266
- };
267
- values.doc = {
268
- name: 'values',
269
- description: "Returns an array with all the values of the fields the Object contains. The same as JavaScript's <code>Object.values(obj)</code>.",
270
- examples: [
271
- { example: "({ name: 'Mr Nathan', age: 42 }).values()", evaluated: "['Mr Nathan', 42]" },
272
- ],
273
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/objects/#object-values',
274
- returnType: 'Array',
275
- };
276
- toJsonString.doc = {
277
- name: 'toJsonString',
278
- description: "Converts the Object to a JSON string. Similar to JavaScript's <code>JSON.stringify()</code>.",
279
- examples: [
280
- {
281
- example: "({ name: 'Mr Nathan', age: 42 }).toJsonString()",
282
- evaluated: '\'{"name":"Nathan","age":42}\'',
283
- },
284
- ],
285
- docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/objects/#object-toJsonString',
286
- returnType: 'string',
287
- };
288
- exports.objectExtensions = {
289
- typeName: 'Object',
290
- functions: {
291
- isEmpty,
292
- isNotEmpty,
293
- hasField,
294
- removeField,
295
- removeFieldsContaining,
296
- keepFieldsContaining,
297
- compact,
298
- urlEncode,
299
- keys,
300
- values,
301
- toJsonString,
302
- toInt,
303
- toFloat,
304
- toBoolean,
305
- toDateTime,
83
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
84
+ return newObj;
85
+ }
86
+ // DIVERGENCE from packages/workflow/src/extensions/object-extensions.ts:
87
+ // The original uses URLSearchParams which is a Web API unavailable inside the
88
+ // V8 isolate. encodeURIComponent is an ECMAScript built-in available in all
89
+ // V8 contexts, but it doesn't encode !'()~ which WHATWG requires. The extra
90
+ // replace step covers those characters to match URLSearchParams output.
91
+ function whatwgEncode(str) {
92
+ return encodeURIComponent(str)
93
+ .replace(/%20/g, '+')
94
+ .replace(/[!'()~]/g, (c) => '%' + c.charCodeAt(0).toString(16).toUpperCase());
95
+ }
96
+ function urlEncode(value) {
97
+ return Object.entries(value)
98
+ .map(([k, v]) => whatwgEncode(k) + '=' + whatwgEncode(String(v)))
99
+ .join('&');
100
+ }
101
+ function toJsonString(value) {
102
+ return JSON.stringify(value);
103
+ }
104
+ function toInt() {
105
+ return undefined;
106
+ }
107
+ function toFloat() {
108
+ return undefined;
109
+ }
110
+ function toBoolean() {
111
+ return undefined;
112
+ }
113
+ function toDateTime() {
114
+ return undefined;
115
+ }
116
+ isEmpty.doc = {
117
+ name: 'isEmpty',
118
+ description: 'Returns <code>true</code> if the Object has no keys (fields) set or is <code>null</code>',
119
+ examples: [
120
+ { example: "({'name': 'Nathan'}).isEmpty()", evaluated: 'false' },
121
+ { example: '({}).isEmpty()', evaluated: 'true' },
122
+ ],
123
+ returnType: 'boolean',
124
+ docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/objects/#object-isEmpty',
125
+ };
126
+ isNotEmpty.doc = {
127
+ name: 'isNotEmpty',
128
+ description: 'Returns <code>true</code> if the Object has at least one key (field) set',
129
+ examples: [
130
+ { example: "({'name': 'Nathan'}).isNotEmpty()", evaluated: 'true' },
131
+ { example: '({}).isNotEmpty()', evaluated: 'false' },
132
+ ],
133
+ returnType: 'boolean',
134
+ docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/objects/#object-isNotEmpty',
135
+ };
136
+ compact.doc = {
137
+ name: 'compact',
138
+ description: 'Removes all fields that have empty values, i.e. are <code>null</code>, <code>undefined</code>, <code>"nil"</code> or <code>""</code>',
139
+ examples: [{ example: "({ x: null, y: 2, z: '' }).compact()", evaluated: '{ y: 2 }' }],
140
+ returnType: 'Object',
141
+ docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/objects/#object-compact',
142
+ };
143
+ urlEncode.doc = {
144
+ name: 'urlEncode',
145
+ description: "Generates a URL parameter string from the Object's keys and values. Only top-level keys are supported.",
146
+ examples: [
147
+ {
148
+ example: "({ name: 'Mr Nathan', city: 'hanoi' }).urlEncode()",
149
+ evaluated: "'name=Mr+Nathan&city=hanoi'",
150
+ },
151
+ ],
152
+ returnType: 'string',
153
+ docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/objects/#object-urlEncode',
154
+ };
155
+ hasField.doc = {
156
+ name: 'hasField',
157
+ description: 'Returns <code>true</code> if there is a field called <code>name</code>. Only checks top-level keys. Comparison is case-sensitive.',
158
+ examples: [
159
+ { example: "({ name: 'Nathan', age: 42 }).hasField('name')", evaluated: 'true' },
160
+ { example: "({ name: 'Nathan', age: 42 }).hasField('Name')", evaluated: 'false' },
161
+ { example: "({ name: 'Nathan', age: 42 }).hasField('inventedField')", evaluated: 'false' },
162
+ ],
163
+ returnType: 'boolean',
164
+ args: [
165
+ {
166
+ name: 'name',
167
+ optional: false,
168
+ description: 'The name of the key to search for',
169
+ type: 'string',
170
+ },
171
+ ],
172
+ docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/objects/#object-hasField',
173
+ };
174
+ removeField.doc = {
175
+ name: 'removeField',
176
+ aliases: ['delete'],
177
+ description: "Removes a field from the Object. The same as JavaScript's <code>delete</code>.",
178
+ examples: [
179
+ {
180
+ example: "({ name: 'Nathan', city: 'hanoi' }).removeField('name')",
181
+ evaluated: "{ city: 'hanoi' }",
182
+ },
183
+ ],
184
+ returnType: 'Object',
185
+ args: [
186
+ {
187
+ name: 'key',
188
+ optional: false,
189
+ description: 'The name of the field to remove',
190
+ type: 'string',
191
+ },
192
+ ],
193
+ docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/objects/#object-removeField',
194
+ };
195
+ removeFieldsContaining.doc = {
196
+ name: 'removeFieldsContaining',
197
+ description: "Removes keys (fields) whose values at least partly match the given <code>value</code>. Comparison is case-sensitive. Fields that aren't strings are always kept.",
198
+ examples: [
199
+ {
200
+ example: "({ name: 'Mr Nathan', city: 'hanoi', age: 42 }).removeFieldsContaining('Nathan')",
201
+ evaluated: "{ city: 'hanoi', age: 42 }",
202
+ },
203
+ {
204
+ example: "({ name: 'Mr Nathan', city: 'hanoi', age: 42 }).removeFieldsContaining('Han')",
205
+ evaluated: '{ age: 42 }',
206
+ },
207
+ {
208
+ example: "({ name: 'Mr Nathan', city: 'hanoi', age: 42 }).removeFieldsContaining('nathan')",
209
+ evaluated: "{ name: 'Mr Nathan', city: 'hanoi', age: 42 }",
210
+ },
211
+ ],
212
+ returnType: 'Object',
213
+ args: [
214
+ {
215
+ name: 'value',
216
+ optional: false,
217
+ description: 'The text that a value must contain in order to be removed',
218
+ type: 'string',
219
+ },
220
+ ],
221
+ docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/objects/#object-removeFieldsContaining',
222
+ };
223
+ keepFieldsContaining.doc = {
224
+ name: 'keepFieldsContaining',
225
+ description: "Removes any fields whose values don't at least partly match the given <code>value</code>. Comparison is case-sensitive. Fields that aren't strings will always be removed.",
226
+ examples: [
227
+ {
228
+ example: "({ name: 'Mr Nathan', city: 'hanoi', age: 42 }).keepFieldsContaining('Nathan')",
229
+ evaluated: "{ name: 'Mr Nathan' }",
230
+ },
231
+ {
232
+ example: "({ name: 'Mr Nathan', city: 'hanoi', age: 42 }).keepFieldsContaining('nathan')",
233
+ evaluated: '{}',
234
+ },
235
+ {
236
+ example: "({ name: 'Mr Nathan', city: 'hanoi', age: 42 }).keepFieldsContaining('han')",
237
+ evaluated: "{ name: 'Mr Nathan', city: 'hanoi' }",
238
+ },
239
+ ],
240
+ returnType: 'Object',
241
+ args: [
242
+ {
243
+ name: 'value',
244
+ optional: false,
245
+ description: 'The text that a value must contain in order to be kept',
246
+ type: 'string',
247
+ },
248
+ ],
249
+ docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/objects/#object-keepFieldsContaining',
250
+ };
251
+ keys.doc = {
252
+ name: 'keys',
253
+ description: "Returns an array with all the field names (keys) the Object contains. The same as JavaScript's <code>Object.keys(obj)</code>.",
254
+ examples: [{ example: "({ name: 'Mr Nathan', age: 42 }).keys()", evaluated: "['name', 'age']" }],
255
+ docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/objects/#object-keys',
256
+ returnType: 'Array',
257
+ };
258
+ values.doc = {
259
+ name: 'values',
260
+ description: "Returns an array with all the values of the fields the Object contains. The same as JavaScript's <code>Object.values(obj)</code>.",
261
+ examples: [
262
+ { example: "({ name: 'Mr Nathan', age: 42 }).values()", evaluated: "['Mr Nathan', 42]" },
263
+ ],
264
+ docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/objects/#object-values',
265
+ returnType: 'Array',
266
+ };
267
+ toJsonString.doc = {
268
+ name: 'toJsonString',
269
+ description: "Converts the Object to a JSON string. Similar to JavaScript's <code>JSON.stringify()</code>.",
270
+ examples: [
271
+ {
272
+ example: "({ name: 'Mr Nathan', age: 42 }).toJsonString()",
273
+ evaluated: '\'{"name":"Nathan","age":42}\'',
306
274
  },
307
- };
308
- });
275
+ ],
276
+ docURL: 'https://docs.n8n.io/code/builtin/data-transformation-functions/objects/#object-toJsonString',
277
+ returnType: 'string',
278
+ };
279
+ exports.objectExtensions = {
280
+ typeName: 'Object',
281
+ functions: {
282
+ isEmpty,
283
+ isNotEmpty,
284
+ hasField,
285
+ removeField,
286
+ removeFieldsContaining,
287
+ keepFieldsContaining,
288
+ compact,
289
+ urlEncode,
290
+ keys,
291
+ values,
292
+ toJsonString,
293
+ toInt,
294
+ toFloat,
295
+ toBoolean,
296
+ toDateTime,
297
+ },
298
+ };
309
299
  //# sourceMappingURL=object-extensions.js.map