@almadar/std 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +72 -0
- package/dist/behaviors/action-affinity.d.ts +88 -0
- package/dist/behaviors/action-affinity.js +290 -0
- package/dist/behaviors/action-affinity.js.map +1 -0
- package/dist/behaviors/async.d.ts +20 -0
- package/dist/behaviors/async.js +542 -0
- package/dist/behaviors/async.js.map +1 -0
- package/dist/behaviors/data-management.d.ts +40 -0
- package/dist/behaviors/data-management.js +495 -0
- package/dist/behaviors/data-management.js.map +1 -0
- package/dist/behaviors/feedback.d.ts +18 -0
- package/dist/behaviors/feedback.js +307 -0
- package/dist/behaviors/feedback.js.map +1 -0
- package/dist/behaviors/game-core.d.ts +40 -0
- package/dist/behaviors/game-core.js +443 -0
- package/dist/behaviors/game-core.js.map +1 -0
- package/dist/behaviors/game-entity.d.ts +39 -0
- package/dist/behaviors/game-entity.js +643 -0
- package/dist/behaviors/game-entity.js.map +1 -0
- package/dist/behaviors/game-ui.d.ts +29 -0
- package/dist/behaviors/game-ui.js +493 -0
- package/dist/behaviors/game-ui.js.map +1 -0
- package/dist/behaviors/index.d.ts +11 -0
- package/dist/behaviors/index.js +4539 -0
- package/dist/behaviors/index.js.map +1 -0
- package/dist/behaviors/registry.d.ts +103 -0
- package/dist/behaviors/registry.js +4166 -0
- package/dist/behaviors/registry.js.map +1 -0
- package/dist/behaviors/types.d.ts +179 -0
- package/dist/behaviors/types.js +111 -0
- package/dist/behaviors/types.js.map +1 -0
- package/dist/behaviors/ui-interaction.d.ts +36 -0
- package/dist/behaviors/ui-interaction.js +1104 -0
- package/dist/behaviors/ui-interaction.js.map +1 -0
- package/dist/index.d.ts +195 -0
- package/dist/index.js +8209 -0
- package/dist/index.js.map +1 -0
- package/dist/modules/array.d.ts +28 -0
- package/dist/modules/array.js +556 -0
- package/dist/modules/array.js.map +1 -0
- package/dist/modules/async.d.ts +22 -0
- package/dist/modules/async.js +112 -0
- package/dist/modules/async.js.map +1 -0
- package/dist/modules/format.d.ts +21 -0
- package/dist/modules/format.js +129 -0
- package/dist/modules/format.js.map +1 -0
- package/dist/modules/index.d.ts +12 -0
- package/dist/modules/index.js +3131 -0
- package/dist/modules/index.js.map +1 -0
- package/dist/modules/math.d.ts +22 -0
- package/dist/modules/math.js +215 -0
- package/dist/modules/math.js.map +1 -0
- package/dist/modules/nn.d.ts +23 -0
- package/dist/modules/nn.js +189 -0
- package/dist/modules/nn.js.map +1 -0
- package/dist/modules/object.d.ts +22 -0
- package/dist/modules/object.js +257 -0
- package/dist/modules/object.js.map +1 -0
- package/dist/modules/str.d.ts +21 -0
- package/dist/modules/str.js +344 -0
- package/dist/modules/str.js.map +1 -0
- package/dist/modules/tensor.d.ts +23 -0
- package/dist/modules/tensor.js +427 -0
- package/dist/modules/tensor.js.map +1 -0
- package/dist/modules/time.d.ts +24 -0
- package/dist/modules/time.js +323 -0
- package/dist/modules/time.js.map +1 -0
- package/dist/modules/train.d.ts +23 -0
- package/dist/modules/train.js +308 -0
- package/dist/modules/train.js.map +1 -0
- package/dist/modules/validate.d.ts +23 -0
- package/dist/modules/validate.js +301 -0
- package/dist/modules/validate.js.map +1 -0
- package/dist/registry.d.ts +140 -0
- package/dist/registry.js +3240 -0
- package/dist/registry.js.map +1 -0
- package/dist/types-I95R8_FN.d.ts +91 -0
- package/package.json +59 -0
|
@@ -0,0 +1,3131 @@
|
|
|
1
|
+
// modules/math.ts
|
|
2
|
+
var MATH_OPERATORS = {
|
|
3
|
+
"math/abs": {
|
|
4
|
+
module: "math",
|
|
5
|
+
category: "std-math",
|
|
6
|
+
minArity: 1,
|
|
7
|
+
maxArity: 1,
|
|
8
|
+
description: "Absolute value",
|
|
9
|
+
hasSideEffects: false,
|
|
10
|
+
returnType: "number",
|
|
11
|
+
params: [{ name: "n", type: "number", description: "The number" }],
|
|
12
|
+
example: '["math/abs", -5] // => 5'
|
|
13
|
+
},
|
|
14
|
+
"math/min": {
|
|
15
|
+
module: "math",
|
|
16
|
+
category: "std-math",
|
|
17
|
+
minArity: 2,
|
|
18
|
+
maxArity: null,
|
|
19
|
+
description: "Minimum of values",
|
|
20
|
+
hasSideEffects: false,
|
|
21
|
+
returnType: "number",
|
|
22
|
+
params: [{ name: "...nums", type: "number[]", description: "Numbers to compare" }],
|
|
23
|
+
example: '["math/min", 3, 1, 4] // => 1'
|
|
24
|
+
},
|
|
25
|
+
"math/max": {
|
|
26
|
+
module: "math",
|
|
27
|
+
category: "std-math",
|
|
28
|
+
minArity: 2,
|
|
29
|
+
maxArity: null,
|
|
30
|
+
description: "Maximum of values",
|
|
31
|
+
hasSideEffects: false,
|
|
32
|
+
returnType: "number",
|
|
33
|
+
params: [{ name: "...nums", type: "number[]", description: "Numbers to compare" }],
|
|
34
|
+
example: '["math/max", 3, 1, 4] // => 4'
|
|
35
|
+
},
|
|
36
|
+
"math/clamp": {
|
|
37
|
+
module: "math",
|
|
38
|
+
category: "std-math",
|
|
39
|
+
minArity: 3,
|
|
40
|
+
maxArity: 3,
|
|
41
|
+
description: "Constrain value to range [min, max]",
|
|
42
|
+
hasSideEffects: false,
|
|
43
|
+
returnType: "number",
|
|
44
|
+
params: [
|
|
45
|
+
{ name: "n", type: "number", description: "The value to clamp" },
|
|
46
|
+
{ name: "min", type: "number", description: "Minimum bound" },
|
|
47
|
+
{ name: "max", type: "number", description: "Maximum bound" }
|
|
48
|
+
],
|
|
49
|
+
example: '["math/clamp", 150, 0, 100] // => 100'
|
|
50
|
+
},
|
|
51
|
+
"math/floor": {
|
|
52
|
+
module: "math",
|
|
53
|
+
category: "std-math",
|
|
54
|
+
minArity: 1,
|
|
55
|
+
maxArity: 1,
|
|
56
|
+
description: "Round down to integer",
|
|
57
|
+
hasSideEffects: false,
|
|
58
|
+
returnType: "number",
|
|
59
|
+
params: [{ name: "n", type: "number", description: "The number" }],
|
|
60
|
+
example: '["math/floor", 3.7] // => 3'
|
|
61
|
+
},
|
|
62
|
+
"math/ceil": {
|
|
63
|
+
module: "math",
|
|
64
|
+
category: "std-math",
|
|
65
|
+
minArity: 1,
|
|
66
|
+
maxArity: 1,
|
|
67
|
+
description: "Round up to integer",
|
|
68
|
+
hasSideEffects: false,
|
|
69
|
+
returnType: "number",
|
|
70
|
+
params: [{ name: "n", type: "number", description: "The number" }],
|
|
71
|
+
example: '["math/ceil", 3.2] // => 4'
|
|
72
|
+
},
|
|
73
|
+
"math/round": {
|
|
74
|
+
module: "math",
|
|
75
|
+
category: "std-math",
|
|
76
|
+
minArity: 1,
|
|
77
|
+
maxArity: 2,
|
|
78
|
+
description: "Round to nearest integer or specified decimals",
|
|
79
|
+
hasSideEffects: false,
|
|
80
|
+
returnType: "number",
|
|
81
|
+
params: [
|
|
82
|
+
{ name: "n", type: "number", description: "The number" },
|
|
83
|
+
{ name: "decimals", type: "number", description: "Decimal places", optional: true, defaultValue: 0 }
|
|
84
|
+
],
|
|
85
|
+
example: '["math/round", 3.456, 2] // => 3.46'
|
|
86
|
+
},
|
|
87
|
+
"math/pow": {
|
|
88
|
+
module: "math",
|
|
89
|
+
category: "std-math",
|
|
90
|
+
minArity: 2,
|
|
91
|
+
maxArity: 2,
|
|
92
|
+
description: "Exponentiation (base^exp)",
|
|
93
|
+
hasSideEffects: false,
|
|
94
|
+
returnType: "number",
|
|
95
|
+
params: [
|
|
96
|
+
{ name: "base", type: "number", description: "The base" },
|
|
97
|
+
{ name: "exp", type: "number", description: "The exponent" }
|
|
98
|
+
],
|
|
99
|
+
example: '["math/pow", 2, 8] // => 256'
|
|
100
|
+
},
|
|
101
|
+
"math/sqrt": {
|
|
102
|
+
module: "math",
|
|
103
|
+
category: "std-math",
|
|
104
|
+
minArity: 1,
|
|
105
|
+
maxArity: 1,
|
|
106
|
+
description: "Square root",
|
|
107
|
+
hasSideEffects: false,
|
|
108
|
+
returnType: "number",
|
|
109
|
+
params: [{ name: "n", type: "number", description: "The number" }],
|
|
110
|
+
example: '["math/sqrt", 16] // => 4'
|
|
111
|
+
},
|
|
112
|
+
"math/mod": {
|
|
113
|
+
module: "math",
|
|
114
|
+
category: "std-math",
|
|
115
|
+
minArity: 2,
|
|
116
|
+
maxArity: 2,
|
|
117
|
+
description: "Modulo (remainder)",
|
|
118
|
+
hasSideEffects: false,
|
|
119
|
+
returnType: "number",
|
|
120
|
+
params: [
|
|
121
|
+
{ name: "a", type: "number", description: "Dividend" },
|
|
122
|
+
{ name: "b", type: "number", description: "Divisor" }
|
|
123
|
+
],
|
|
124
|
+
example: '["math/mod", 7, 3] // => 1'
|
|
125
|
+
},
|
|
126
|
+
"math/sign": {
|
|
127
|
+
module: "math",
|
|
128
|
+
category: "std-math",
|
|
129
|
+
minArity: 1,
|
|
130
|
+
maxArity: 1,
|
|
131
|
+
description: "Returns -1, 0, or 1 indicating sign",
|
|
132
|
+
hasSideEffects: false,
|
|
133
|
+
returnType: "number",
|
|
134
|
+
params: [{ name: "n", type: "number", description: "The number" }],
|
|
135
|
+
example: '["math/sign", -42] // => -1'
|
|
136
|
+
},
|
|
137
|
+
"math/lerp": {
|
|
138
|
+
module: "math",
|
|
139
|
+
category: "std-math",
|
|
140
|
+
minArity: 3,
|
|
141
|
+
maxArity: 3,
|
|
142
|
+
description: "Linear interpolation between a and b by factor t",
|
|
143
|
+
hasSideEffects: false,
|
|
144
|
+
returnType: "number",
|
|
145
|
+
params: [
|
|
146
|
+
{ name: "a", type: "number", description: "Start value" },
|
|
147
|
+
{ name: "b", type: "number", description: "End value" },
|
|
148
|
+
{ name: "t", type: "number", description: "Interpolation factor (0-1)" }
|
|
149
|
+
],
|
|
150
|
+
example: '["math/lerp", 0, 100, 0.5] // => 50'
|
|
151
|
+
},
|
|
152
|
+
"math/map": {
|
|
153
|
+
module: "math",
|
|
154
|
+
category: "std-math",
|
|
155
|
+
minArity: 5,
|
|
156
|
+
maxArity: 5,
|
|
157
|
+
description: "Map value from one range to another",
|
|
158
|
+
hasSideEffects: false,
|
|
159
|
+
returnType: "number",
|
|
160
|
+
params: [
|
|
161
|
+
{ name: "n", type: "number", description: "The value" },
|
|
162
|
+
{ name: "inMin", type: "number", description: "Input range minimum" },
|
|
163
|
+
{ name: "inMax", type: "number", description: "Input range maximum" },
|
|
164
|
+
{ name: "outMin", type: "number", description: "Output range minimum" },
|
|
165
|
+
{ name: "outMax", type: "number", description: "Output range maximum" }
|
|
166
|
+
],
|
|
167
|
+
example: '["math/map", 5, 0, 10, 0, 100] // => 50'
|
|
168
|
+
},
|
|
169
|
+
"math/random": {
|
|
170
|
+
module: "math",
|
|
171
|
+
category: "std-math",
|
|
172
|
+
minArity: 0,
|
|
173
|
+
maxArity: 0,
|
|
174
|
+
description: "Random number between 0 (inclusive) and 1 (exclusive)",
|
|
175
|
+
hasSideEffects: false,
|
|
176
|
+
returnType: "number",
|
|
177
|
+
params: [],
|
|
178
|
+
example: '["math/random"] // => 0.7234...'
|
|
179
|
+
},
|
|
180
|
+
"math/randomInt": {
|
|
181
|
+
module: "math",
|
|
182
|
+
category: "std-math",
|
|
183
|
+
minArity: 2,
|
|
184
|
+
maxArity: 2,
|
|
185
|
+
description: "Random integer in range [min, max] (inclusive)",
|
|
186
|
+
hasSideEffects: false,
|
|
187
|
+
returnType: "number",
|
|
188
|
+
params: [
|
|
189
|
+
{ name: "min", type: "number", description: "Minimum (inclusive)" },
|
|
190
|
+
{ name: "max", type: "number", description: "Maximum (inclusive)" }
|
|
191
|
+
],
|
|
192
|
+
example: '["math/randomInt", 1, 6] // => 4'
|
|
193
|
+
},
|
|
194
|
+
"math/default": {
|
|
195
|
+
module: "math",
|
|
196
|
+
category: "std-math",
|
|
197
|
+
minArity: 2,
|
|
198
|
+
maxArity: 2,
|
|
199
|
+
description: "Return default if value is null, undefined, or NaN",
|
|
200
|
+
hasSideEffects: false,
|
|
201
|
+
returnType: "number",
|
|
202
|
+
params: [
|
|
203
|
+
{ name: "n", type: "number | null", description: "The value" },
|
|
204
|
+
{ name: "default", type: "number", description: "Default value" }
|
|
205
|
+
],
|
|
206
|
+
example: '["math/default", null, 0] // => 0'
|
|
207
|
+
}
|
|
208
|
+
};
|
|
209
|
+
function getMathOperators() {
|
|
210
|
+
return Object.keys(MATH_OPERATORS);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// modules/str.ts
|
|
214
|
+
var STR_OPERATORS = {
|
|
215
|
+
"str/len": {
|
|
216
|
+
module: "str",
|
|
217
|
+
category: "std-str",
|
|
218
|
+
minArity: 1,
|
|
219
|
+
maxArity: 1,
|
|
220
|
+
description: "String length",
|
|
221
|
+
hasSideEffects: false,
|
|
222
|
+
returnType: "number",
|
|
223
|
+
params: [{ name: "s", type: "string", description: "The string" }],
|
|
224
|
+
example: '["str/len", "hello"] // => 5'
|
|
225
|
+
},
|
|
226
|
+
"str/upper": {
|
|
227
|
+
module: "str",
|
|
228
|
+
category: "std-str",
|
|
229
|
+
minArity: 1,
|
|
230
|
+
maxArity: 1,
|
|
231
|
+
description: "Convert to uppercase",
|
|
232
|
+
hasSideEffects: false,
|
|
233
|
+
returnType: "string",
|
|
234
|
+
params: [{ name: "s", type: "string", description: "The string" }],
|
|
235
|
+
example: '["str/upper", "hello"] // => "HELLO"'
|
|
236
|
+
},
|
|
237
|
+
"str/lower": {
|
|
238
|
+
module: "str",
|
|
239
|
+
category: "std-str",
|
|
240
|
+
minArity: 1,
|
|
241
|
+
maxArity: 1,
|
|
242
|
+
description: "Convert to lowercase",
|
|
243
|
+
hasSideEffects: false,
|
|
244
|
+
returnType: "string",
|
|
245
|
+
params: [{ name: "s", type: "string", description: "The string" }],
|
|
246
|
+
example: '["str/lower", "HELLO"] // => "hello"'
|
|
247
|
+
},
|
|
248
|
+
"str/trim": {
|
|
249
|
+
module: "str",
|
|
250
|
+
category: "std-str",
|
|
251
|
+
minArity: 1,
|
|
252
|
+
maxArity: 1,
|
|
253
|
+
description: "Remove leading and trailing whitespace",
|
|
254
|
+
hasSideEffects: false,
|
|
255
|
+
returnType: "string",
|
|
256
|
+
params: [{ name: "s", type: "string", description: "The string" }],
|
|
257
|
+
example: '["str/trim", " hello "] // => "hello"'
|
|
258
|
+
},
|
|
259
|
+
"str/trimStart": {
|
|
260
|
+
module: "str",
|
|
261
|
+
category: "std-str",
|
|
262
|
+
minArity: 1,
|
|
263
|
+
maxArity: 1,
|
|
264
|
+
description: "Remove leading whitespace",
|
|
265
|
+
hasSideEffects: false,
|
|
266
|
+
returnType: "string",
|
|
267
|
+
params: [{ name: "s", type: "string", description: "The string" }],
|
|
268
|
+
example: '["str/trimStart", " hello"] // => "hello"'
|
|
269
|
+
},
|
|
270
|
+
"str/trimEnd": {
|
|
271
|
+
module: "str",
|
|
272
|
+
category: "std-str",
|
|
273
|
+
minArity: 1,
|
|
274
|
+
maxArity: 1,
|
|
275
|
+
description: "Remove trailing whitespace",
|
|
276
|
+
hasSideEffects: false,
|
|
277
|
+
returnType: "string",
|
|
278
|
+
params: [{ name: "s", type: "string", description: "The string" }],
|
|
279
|
+
example: '["str/trimEnd", "hello "] // => "hello"'
|
|
280
|
+
},
|
|
281
|
+
"str/split": {
|
|
282
|
+
module: "str",
|
|
283
|
+
category: "std-str",
|
|
284
|
+
minArity: 2,
|
|
285
|
+
maxArity: 2,
|
|
286
|
+
description: "Split string into array by delimiter",
|
|
287
|
+
hasSideEffects: false,
|
|
288
|
+
returnType: "array",
|
|
289
|
+
params: [
|
|
290
|
+
{ name: "s", type: "string", description: "The string" },
|
|
291
|
+
{ name: "delim", type: "string", description: "Delimiter" }
|
|
292
|
+
],
|
|
293
|
+
example: '["str/split", "a,b,c", ","] // => ["a", "b", "c"]'
|
|
294
|
+
},
|
|
295
|
+
"str/join": {
|
|
296
|
+
module: "str",
|
|
297
|
+
category: "std-str",
|
|
298
|
+
minArity: 2,
|
|
299
|
+
maxArity: 2,
|
|
300
|
+
description: "Join array elements into string",
|
|
301
|
+
hasSideEffects: false,
|
|
302
|
+
returnType: "string",
|
|
303
|
+
params: [
|
|
304
|
+
{ name: "arr", type: "array", description: "Array to join" },
|
|
305
|
+
{ name: "delim", type: "string", description: "Delimiter" }
|
|
306
|
+
],
|
|
307
|
+
example: '["str/join", ["a", "b", "c"], ", "] // => "a, b, c"'
|
|
308
|
+
},
|
|
309
|
+
"str/slice": {
|
|
310
|
+
module: "str",
|
|
311
|
+
category: "std-str",
|
|
312
|
+
minArity: 2,
|
|
313
|
+
maxArity: 3,
|
|
314
|
+
description: "Extract substring",
|
|
315
|
+
hasSideEffects: false,
|
|
316
|
+
returnType: "string",
|
|
317
|
+
params: [
|
|
318
|
+
{ name: "s", type: "string", description: "The string" },
|
|
319
|
+
{ name: "start", type: "number", description: "Start index" },
|
|
320
|
+
{ name: "end", type: "number", description: "End index (exclusive)", optional: true }
|
|
321
|
+
],
|
|
322
|
+
example: '["str/slice", "hello", 1, 4] // => "ell"'
|
|
323
|
+
},
|
|
324
|
+
"str/replace": {
|
|
325
|
+
module: "str",
|
|
326
|
+
category: "std-str",
|
|
327
|
+
minArity: 3,
|
|
328
|
+
maxArity: 3,
|
|
329
|
+
description: "Replace first occurrence",
|
|
330
|
+
hasSideEffects: false,
|
|
331
|
+
returnType: "string",
|
|
332
|
+
params: [
|
|
333
|
+
{ name: "s", type: "string", description: "The string" },
|
|
334
|
+
{ name: "find", type: "string", description: "String to find" },
|
|
335
|
+
{ name: "replace", type: "string", description: "Replacement" }
|
|
336
|
+
],
|
|
337
|
+
example: '["str/replace", "hello world", "world", "there"] // => "hello there"'
|
|
338
|
+
},
|
|
339
|
+
"str/replaceAll": {
|
|
340
|
+
module: "str",
|
|
341
|
+
category: "std-str",
|
|
342
|
+
minArity: 3,
|
|
343
|
+
maxArity: 3,
|
|
344
|
+
description: "Replace all occurrences",
|
|
345
|
+
hasSideEffects: false,
|
|
346
|
+
returnType: "string",
|
|
347
|
+
params: [
|
|
348
|
+
{ name: "s", type: "string", description: "The string" },
|
|
349
|
+
{ name: "find", type: "string", description: "String to find" },
|
|
350
|
+
{ name: "replace", type: "string", description: "Replacement" }
|
|
351
|
+
],
|
|
352
|
+
example: '["str/replaceAll", "a-b-c", "-", "_"] // => "a_b_c"'
|
|
353
|
+
},
|
|
354
|
+
"str/includes": {
|
|
355
|
+
module: "str",
|
|
356
|
+
category: "std-str",
|
|
357
|
+
minArity: 2,
|
|
358
|
+
maxArity: 2,
|
|
359
|
+
description: "Check if string contains substring",
|
|
360
|
+
hasSideEffects: false,
|
|
361
|
+
returnType: "boolean",
|
|
362
|
+
params: [
|
|
363
|
+
{ name: "s", type: "string", description: "The string" },
|
|
364
|
+
{ name: "search", type: "string", description: "Substring to find" }
|
|
365
|
+
],
|
|
366
|
+
example: '["str/includes", "hello world", "world"] // => true'
|
|
367
|
+
},
|
|
368
|
+
"str/startsWith": {
|
|
369
|
+
module: "str",
|
|
370
|
+
category: "std-str",
|
|
371
|
+
minArity: 2,
|
|
372
|
+
maxArity: 2,
|
|
373
|
+
description: "Check if string starts with prefix",
|
|
374
|
+
hasSideEffects: false,
|
|
375
|
+
returnType: "boolean",
|
|
376
|
+
params: [
|
|
377
|
+
{ name: "s", type: "string", description: "The string" },
|
|
378
|
+
{ name: "prefix", type: "string", description: "Prefix to check" }
|
|
379
|
+
],
|
|
380
|
+
example: '["str/startsWith", "hello", "hel"] // => true'
|
|
381
|
+
},
|
|
382
|
+
"str/endsWith": {
|
|
383
|
+
module: "str",
|
|
384
|
+
category: "std-str",
|
|
385
|
+
minArity: 2,
|
|
386
|
+
maxArity: 2,
|
|
387
|
+
description: "Check if string ends with suffix",
|
|
388
|
+
hasSideEffects: false,
|
|
389
|
+
returnType: "boolean",
|
|
390
|
+
params: [
|
|
391
|
+
{ name: "s", type: "string", description: "The string" },
|
|
392
|
+
{ name: "suffix", type: "string", description: "Suffix to check" }
|
|
393
|
+
],
|
|
394
|
+
example: '["str/endsWith", "hello", "lo"] // => true'
|
|
395
|
+
},
|
|
396
|
+
"str/padStart": {
|
|
397
|
+
module: "str",
|
|
398
|
+
category: "std-str",
|
|
399
|
+
minArity: 2,
|
|
400
|
+
maxArity: 3,
|
|
401
|
+
description: "Pad string from start to target length",
|
|
402
|
+
hasSideEffects: false,
|
|
403
|
+
returnType: "string",
|
|
404
|
+
params: [
|
|
405
|
+
{ name: "s", type: "string", description: "The string" },
|
|
406
|
+
{ name: "len", type: "number", description: "Target length" },
|
|
407
|
+
{ name: "char", type: "string", description: "Padding character", optional: true, defaultValue: " " }
|
|
408
|
+
],
|
|
409
|
+
example: '["str/padStart", "5", 3, "0"] // => "005"'
|
|
410
|
+
},
|
|
411
|
+
"str/padEnd": {
|
|
412
|
+
module: "str",
|
|
413
|
+
category: "std-str",
|
|
414
|
+
minArity: 2,
|
|
415
|
+
maxArity: 3,
|
|
416
|
+
description: "Pad string from end to target length",
|
|
417
|
+
hasSideEffects: false,
|
|
418
|
+
returnType: "string",
|
|
419
|
+
params: [
|
|
420
|
+
{ name: "s", type: "string", description: "The string" },
|
|
421
|
+
{ name: "len", type: "number", description: "Target length" },
|
|
422
|
+
{ name: "char", type: "string", description: "Padding character", optional: true, defaultValue: " " }
|
|
423
|
+
],
|
|
424
|
+
example: '["str/padEnd", "5", 3, "0"] // => "500"'
|
|
425
|
+
},
|
|
426
|
+
"str/repeat": {
|
|
427
|
+
module: "str",
|
|
428
|
+
category: "std-str",
|
|
429
|
+
minArity: 2,
|
|
430
|
+
maxArity: 2,
|
|
431
|
+
description: "Repeat string n times",
|
|
432
|
+
hasSideEffects: false,
|
|
433
|
+
returnType: "string",
|
|
434
|
+
params: [
|
|
435
|
+
{ name: "s", type: "string", description: "The string" },
|
|
436
|
+
{ name: "count", type: "number", description: "Repeat count" }
|
|
437
|
+
],
|
|
438
|
+
example: '["str/repeat", "ab", 3] // => "ababab"'
|
|
439
|
+
},
|
|
440
|
+
"str/reverse": {
|
|
441
|
+
module: "str",
|
|
442
|
+
category: "std-str",
|
|
443
|
+
minArity: 1,
|
|
444
|
+
maxArity: 1,
|
|
445
|
+
description: "Reverse string",
|
|
446
|
+
hasSideEffects: false,
|
|
447
|
+
returnType: "string",
|
|
448
|
+
params: [{ name: "s", type: "string", description: "The string" }],
|
|
449
|
+
example: '["str/reverse", "hello"] // => "olleh"'
|
|
450
|
+
},
|
|
451
|
+
"str/capitalize": {
|
|
452
|
+
module: "str",
|
|
453
|
+
category: "std-str",
|
|
454
|
+
minArity: 1,
|
|
455
|
+
maxArity: 1,
|
|
456
|
+
description: "Capitalize first character",
|
|
457
|
+
hasSideEffects: false,
|
|
458
|
+
returnType: "string",
|
|
459
|
+
params: [{ name: "s", type: "string", description: "The string" }],
|
|
460
|
+
example: '["str/capitalize", "hello"] // => "Hello"'
|
|
461
|
+
},
|
|
462
|
+
"str/titleCase": {
|
|
463
|
+
module: "str",
|
|
464
|
+
category: "std-str",
|
|
465
|
+
minArity: 1,
|
|
466
|
+
maxArity: 1,
|
|
467
|
+
description: "Convert to Title Case",
|
|
468
|
+
hasSideEffects: false,
|
|
469
|
+
returnType: "string",
|
|
470
|
+
params: [{ name: "s", type: "string", description: "The string" }],
|
|
471
|
+
example: '["str/titleCase", "hello world"] // => "Hello World"'
|
|
472
|
+
},
|
|
473
|
+
"str/camelCase": {
|
|
474
|
+
module: "str",
|
|
475
|
+
category: "std-str",
|
|
476
|
+
minArity: 1,
|
|
477
|
+
maxArity: 1,
|
|
478
|
+
description: "Convert to camelCase",
|
|
479
|
+
hasSideEffects: false,
|
|
480
|
+
returnType: "string",
|
|
481
|
+
params: [{ name: "s", type: "string", description: "The string" }],
|
|
482
|
+
example: '["str/camelCase", "hello world"] // => "helloWorld"'
|
|
483
|
+
},
|
|
484
|
+
"str/kebabCase": {
|
|
485
|
+
module: "str",
|
|
486
|
+
category: "std-str",
|
|
487
|
+
minArity: 1,
|
|
488
|
+
maxArity: 1,
|
|
489
|
+
description: "Convert to kebab-case",
|
|
490
|
+
hasSideEffects: false,
|
|
491
|
+
returnType: "string",
|
|
492
|
+
params: [{ name: "s", type: "string", description: "The string" }],
|
|
493
|
+
example: '["str/kebabCase", "Hello World"] // => "hello-world"'
|
|
494
|
+
},
|
|
495
|
+
"str/snakeCase": {
|
|
496
|
+
module: "str",
|
|
497
|
+
category: "std-str",
|
|
498
|
+
minArity: 1,
|
|
499
|
+
maxArity: 1,
|
|
500
|
+
description: "Convert to snake_case",
|
|
501
|
+
hasSideEffects: false,
|
|
502
|
+
returnType: "string",
|
|
503
|
+
params: [{ name: "s", type: "string", description: "The string" }],
|
|
504
|
+
example: '["str/snakeCase", "Hello World"] // => "hello_world"'
|
|
505
|
+
},
|
|
506
|
+
"str/default": {
|
|
507
|
+
module: "str",
|
|
508
|
+
category: "std-str",
|
|
509
|
+
minArity: 2,
|
|
510
|
+
maxArity: 2,
|
|
511
|
+
description: "Return default if value is null/undefined/empty",
|
|
512
|
+
hasSideEffects: false,
|
|
513
|
+
returnType: "string",
|
|
514
|
+
params: [
|
|
515
|
+
{ name: "s", type: "string | null", description: "The value" },
|
|
516
|
+
{ name: "default", type: "string", description: "Default value" }
|
|
517
|
+
],
|
|
518
|
+
example: '["str/default", null, "N/A"] // => "N/A"'
|
|
519
|
+
},
|
|
520
|
+
"str/template": {
|
|
521
|
+
module: "str",
|
|
522
|
+
category: "std-str",
|
|
523
|
+
minArity: 2,
|
|
524
|
+
maxArity: 2,
|
|
525
|
+
description: "Variable substitution in template string",
|
|
526
|
+
hasSideEffects: false,
|
|
527
|
+
returnType: "string",
|
|
528
|
+
params: [
|
|
529
|
+
{ name: "template", type: "string", description: "Template with {placeholders}" },
|
|
530
|
+
{ name: "vars", type: "object", description: "Variables to substitute" }
|
|
531
|
+
],
|
|
532
|
+
example: '["str/template", "Hello, {name}!", {"name": "World"}] // => "Hello, World!"'
|
|
533
|
+
},
|
|
534
|
+
"str/truncate": {
|
|
535
|
+
module: "str",
|
|
536
|
+
category: "std-str",
|
|
537
|
+
minArity: 2,
|
|
538
|
+
maxArity: 3,
|
|
539
|
+
description: "Truncate string with optional suffix",
|
|
540
|
+
hasSideEffects: false,
|
|
541
|
+
returnType: "string",
|
|
542
|
+
params: [
|
|
543
|
+
{ name: "s", type: "string", description: "The string" },
|
|
544
|
+
{ name: "len", type: "number", description: "Maximum length" },
|
|
545
|
+
{ name: "suffix", type: "string", description: "Suffix for truncated strings", optional: true, defaultValue: "..." }
|
|
546
|
+
],
|
|
547
|
+
example: '["str/truncate", "Hello World", 8, "..."] // => "Hello..."'
|
|
548
|
+
}
|
|
549
|
+
};
|
|
550
|
+
function getStrOperators() {
|
|
551
|
+
return Object.keys(STR_OPERATORS);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// modules/array.ts
|
|
555
|
+
var ARRAY_OPERATORS = {
|
|
556
|
+
"array/len": {
|
|
557
|
+
module: "array",
|
|
558
|
+
category: "std-array",
|
|
559
|
+
minArity: 1,
|
|
560
|
+
maxArity: 1,
|
|
561
|
+
description: "Array length",
|
|
562
|
+
hasSideEffects: false,
|
|
563
|
+
returnType: "number",
|
|
564
|
+
params: [{ name: "arr", type: "array", description: "The array" }],
|
|
565
|
+
example: '["array/len", [1, 2, 3]] // => 3'
|
|
566
|
+
},
|
|
567
|
+
"array/empty?": {
|
|
568
|
+
module: "array",
|
|
569
|
+
category: "std-array",
|
|
570
|
+
minArity: 1,
|
|
571
|
+
maxArity: 1,
|
|
572
|
+
description: "Check if array is empty",
|
|
573
|
+
hasSideEffects: false,
|
|
574
|
+
returnType: "boolean",
|
|
575
|
+
params: [{ name: "arr", type: "array", description: "The array" }],
|
|
576
|
+
example: '["array/empty?", []] // => true'
|
|
577
|
+
},
|
|
578
|
+
"array/first": {
|
|
579
|
+
module: "array",
|
|
580
|
+
category: "std-array",
|
|
581
|
+
minArity: 1,
|
|
582
|
+
maxArity: 1,
|
|
583
|
+
description: "Get first element",
|
|
584
|
+
hasSideEffects: false,
|
|
585
|
+
returnType: "any",
|
|
586
|
+
params: [{ name: "arr", type: "array", description: "The array" }],
|
|
587
|
+
example: '["array/first", [1, 2, 3]] // => 1'
|
|
588
|
+
},
|
|
589
|
+
"array/last": {
|
|
590
|
+
module: "array",
|
|
591
|
+
category: "std-array",
|
|
592
|
+
minArity: 1,
|
|
593
|
+
maxArity: 1,
|
|
594
|
+
description: "Get last element",
|
|
595
|
+
hasSideEffects: false,
|
|
596
|
+
returnType: "any",
|
|
597
|
+
params: [{ name: "arr", type: "array", description: "The array" }],
|
|
598
|
+
example: '["array/last", [1, 2, 3]] // => 3'
|
|
599
|
+
},
|
|
600
|
+
"array/nth": {
|
|
601
|
+
module: "array",
|
|
602
|
+
category: "std-array",
|
|
603
|
+
minArity: 2,
|
|
604
|
+
maxArity: 2,
|
|
605
|
+
description: "Get element at index",
|
|
606
|
+
hasSideEffects: false,
|
|
607
|
+
returnType: "any",
|
|
608
|
+
params: [
|
|
609
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
610
|
+
{ name: "index", type: "number", description: "Index (0-based)" }
|
|
611
|
+
],
|
|
612
|
+
example: '["array/nth", [1, 2, 3], 1] // => 2'
|
|
613
|
+
},
|
|
614
|
+
"array/slice": {
|
|
615
|
+
module: "array",
|
|
616
|
+
category: "std-array",
|
|
617
|
+
minArity: 2,
|
|
618
|
+
maxArity: 3,
|
|
619
|
+
description: "Extract subarray",
|
|
620
|
+
hasSideEffects: false,
|
|
621
|
+
returnType: "array",
|
|
622
|
+
params: [
|
|
623
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
624
|
+
{ name: "start", type: "number", description: "Start index" },
|
|
625
|
+
{ name: "end", type: "number", description: "End index (exclusive)", optional: true }
|
|
626
|
+
],
|
|
627
|
+
example: '["array/slice", [1, 2, 3, 4], 1, 3] // => [2, 3]'
|
|
628
|
+
},
|
|
629
|
+
"array/concat": {
|
|
630
|
+
module: "array",
|
|
631
|
+
category: "std-array",
|
|
632
|
+
minArity: 2,
|
|
633
|
+
maxArity: null,
|
|
634
|
+
description: "Concatenate arrays",
|
|
635
|
+
hasSideEffects: false,
|
|
636
|
+
returnType: "array",
|
|
637
|
+
params: [{ name: "...arrs", type: "array[]", description: "Arrays to concatenate" }],
|
|
638
|
+
example: '["array/concat", [1, 2], [3, 4]] // => [1, 2, 3, 4]'
|
|
639
|
+
},
|
|
640
|
+
"array/append": {
|
|
641
|
+
module: "array",
|
|
642
|
+
category: "std-array",
|
|
643
|
+
minArity: 2,
|
|
644
|
+
maxArity: 2,
|
|
645
|
+
description: "Add item to end (returns new array)",
|
|
646
|
+
hasSideEffects: false,
|
|
647
|
+
returnType: "array",
|
|
648
|
+
params: [
|
|
649
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
650
|
+
{ name: "item", type: "any", description: "Item to add" }
|
|
651
|
+
],
|
|
652
|
+
example: '["array/append", [1, 2], 3] // => [1, 2, 3]'
|
|
653
|
+
},
|
|
654
|
+
"array/prepend": {
|
|
655
|
+
module: "array",
|
|
656
|
+
category: "std-array",
|
|
657
|
+
minArity: 2,
|
|
658
|
+
maxArity: 2,
|
|
659
|
+
description: "Add item to start (returns new array)",
|
|
660
|
+
hasSideEffects: false,
|
|
661
|
+
returnType: "array",
|
|
662
|
+
params: [
|
|
663
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
664
|
+
{ name: "item", type: "any", description: "Item to add" }
|
|
665
|
+
],
|
|
666
|
+
example: '["array/prepend", [2, 3], 1] // => [1, 2, 3]'
|
|
667
|
+
},
|
|
668
|
+
"array/insert": {
|
|
669
|
+
module: "array",
|
|
670
|
+
category: "std-array",
|
|
671
|
+
minArity: 3,
|
|
672
|
+
maxArity: 3,
|
|
673
|
+
description: "Insert item at index (returns new array)",
|
|
674
|
+
hasSideEffects: false,
|
|
675
|
+
returnType: "array",
|
|
676
|
+
params: [
|
|
677
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
678
|
+
{ name: "index", type: "number", description: "Index to insert at" },
|
|
679
|
+
{ name: "item", type: "any", description: "Item to insert" }
|
|
680
|
+
],
|
|
681
|
+
example: '["array/insert", [1, 3], 1, 2] // => [1, 2, 3]'
|
|
682
|
+
},
|
|
683
|
+
"array/remove": {
|
|
684
|
+
module: "array",
|
|
685
|
+
category: "std-array",
|
|
686
|
+
minArity: 2,
|
|
687
|
+
maxArity: 2,
|
|
688
|
+
description: "Remove item at index (returns new array)",
|
|
689
|
+
hasSideEffects: false,
|
|
690
|
+
returnType: "array",
|
|
691
|
+
params: [
|
|
692
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
693
|
+
{ name: "index", type: "number", description: "Index to remove" }
|
|
694
|
+
],
|
|
695
|
+
example: '["array/remove", [1, 2, 3], 1] // => [1, 3]'
|
|
696
|
+
},
|
|
697
|
+
"array/removeItem": {
|
|
698
|
+
module: "array",
|
|
699
|
+
category: "std-array",
|
|
700
|
+
minArity: 2,
|
|
701
|
+
maxArity: 2,
|
|
702
|
+
description: "Remove first matching item (returns new array)",
|
|
703
|
+
hasSideEffects: false,
|
|
704
|
+
returnType: "array",
|
|
705
|
+
params: [
|
|
706
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
707
|
+
{ name: "item", type: "any", description: "Item to remove" }
|
|
708
|
+
],
|
|
709
|
+
example: '["array/removeItem", [1, 2, 3, 2], 2] // => [1, 3, 2]'
|
|
710
|
+
},
|
|
711
|
+
"array/reverse": {
|
|
712
|
+
module: "array",
|
|
713
|
+
category: "std-array",
|
|
714
|
+
minArity: 1,
|
|
715
|
+
maxArity: 1,
|
|
716
|
+
description: "Reverse array order (returns new array)",
|
|
717
|
+
hasSideEffects: false,
|
|
718
|
+
returnType: "array",
|
|
719
|
+
params: [{ name: "arr", type: "array", description: "The array" }],
|
|
720
|
+
example: '["array/reverse", [1, 2, 3]] // => [3, 2, 1]'
|
|
721
|
+
},
|
|
722
|
+
"array/sort": {
|
|
723
|
+
module: "array",
|
|
724
|
+
category: "std-array",
|
|
725
|
+
minArity: 1,
|
|
726
|
+
maxArity: 3,
|
|
727
|
+
description: "Sort array (returns new array)",
|
|
728
|
+
hasSideEffects: false,
|
|
729
|
+
returnType: "array",
|
|
730
|
+
params: [
|
|
731
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
732
|
+
{ name: "key", type: "string", description: "Field to sort by (for objects)", optional: true },
|
|
733
|
+
{ name: "dir", type: "string", description: '"asc" or "desc"', optional: true, defaultValue: "asc" }
|
|
734
|
+
],
|
|
735
|
+
example: '["array/sort", "@items", "price", "desc"]'
|
|
736
|
+
},
|
|
737
|
+
"array/shuffle": {
|
|
738
|
+
module: "array",
|
|
739
|
+
category: "std-array",
|
|
740
|
+
minArity: 1,
|
|
741
|
+
maxArity: 1,
|
|
742
|
+
description: "Randomly shuffle array (returns new array)",
|
|
743
|
+
hasSideEffects: false,
|
|
744
|
+
returnType: "array",
|
|
745
|
+
params: [{ name: "arr", type: "array", description: "The array" }],
|
|
746
|
+
example: '["array/shuffle", [1, 2, 3, 4, 5]]'
|
|
747
|
+
},
|
|
748
|
+
"array/unique": {
|
|
749
|
+
module: "array",
|
|
750
|
+
category: "std-array",
|
|
751
|
+
minArity: 1,
|
|
752
|
+
maxArity: 1,
|
|
753
|
+
description: "Remove duplicates (returns new array)",
|
|
754
|
+
hasSideEffects: false,
|
|
755
|
+
returnType: "array",
|
|
756
|
+
params: [{ name: "arr", type: "array", description: "The array" }],
|
|
757
|
+
example: '["array/unique", [1, 2, 2, 3, 1]] // => [1, 2, 3]'
|
|
758
|
+
},
|
|
759
|
+
"array/flatten": {
|
|
760
|
+
module: "array",
|
|
761
|
+
category: "std-array",
|
|
762
|
+
minArity: 1,
|
|
763
|
+
maxArity: 1,
|
|
764
|
+
description: "Flatten nested arrays one level",
|
|
765
|
+
hasSideEffects: false,
|
|
766
|
+
returnType: "array",
|
|
767
|
+
params: [{ name: "arr", type: "array", description: "The array" }],
|
|
768
|
+
example: '["array/flatten", [[1, 2], [3, 4]]] // => [1, 2, 3, 4]'
|
|
769
|
+
},
|
|
770
|
+
"array/zip": {
|
|
771
|
+
module: "array",
|
|
772
|
+
category: "std-array",
|
|
773
|
+
minArity: 2,
|
|
774
|
+
maxArity: 2,
|
|
775
|
+
description: "Pair elements from two arrays",
|
|
776
|
+
hasSideEffects: false,
|
|
777
|
+
returnType: "array",
|
|
778
|
+
params: [
|
|
779
|
+
{ name: "arr1", type: "array", description: "First array" },
|
|
780
|
+
{ name: "arr2", type: "array", description: "Second array" }
|
|
781
|
+
],
|
|
782
|
+
example: '["array/zip", [1, 2], ["a", "b"]] // => [[1, "a"], [2, "b"]]'
|
|
783
|
+
},
|
|
784
|
+
"array/includes": {
|
|
785
|
+
module: "array",
|
|
786
|
+
category: "std-array",
|
|
787
|
+
minArity: 2,
|
|
788
|
+
maxArity: 2,
|
|
789
|
+
description: "Check if array contains item",
|
|
790
|
+
hasSideEffects: false,
|
|
791
|
+
returnType: "boolean",
|
|
792
|
+
params: [
|
|
793
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
794
|
+
{ name: "item", type: "any", description: "Item to find" }
|
|
795
|
+
],
|
|
796
|
+
example: '["array/includes", [1, 2, 3], 2] // => true'
|
|
797
|
+
},
|
|
798
|
+
"array/indexOf": {
|
|
799
|
+
module: "array",
|
|
800
|
+
category: "std-array",
|
|
801
|
+
minArity: 2,
|
|
802
|
+
maxArity: 2,
|
|
803
|
+
description: "Find index of item (-1 if not found)",
|
|
804
|
+
hasSideEffects: false,
|
|
805
|
+
returnType: "number",
|
|
806
|
+
params: [
|
|
807
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
808
|
+
{ name: "item", type: "any", description: "Item to find" }
|
|
809
|
+
],
|
|
810
|
+
example: '["array/indexOf", [1, 2, 3], 2] // => 1'
|
|
811
|
+
},
|
|
812
|
+
"array/find": {
|
|
813
|
+
module: "array",
|
|
814
|
+
category: "std-array",
|
|
815
|
+
minArity: 2,
|
|
816
|
+
maxArity: 2,
|
|
817
|
+
description: "Find first element matching predicate",
|
|
818
|
+
hasSideEffects: false,
|
|
819
|
+
returnType: "any",
|
|
820
|
+
acceptsLambda: true,
|
|
821
|
+
lambdaArgPosition: 1,
|
|
822
|
+
params: [
|
|
823
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
824
|
+
{ name: "pred", type: "lambda", description: "Predicate function" }
|
|
825
|
+
],
|
|
826
|
+
example: '["array/find", "@items", ["fn", "x", ["=", "@x.status", "active"]]]'
|
|
827
|
+
},
|
|
828
|
+
"array/findIndex": {
|
|
829
|
+
module: "array",
|
|
830
|
+
category: "std-array",
|
|
831
|
+
minArity: 2,
|
|
832
|
+
maxArity: 2,
|
|
833
|
+
description: "Find index of first element matching predicate (-1 if none)",
|
|
834
|
+
hasSideEffects: false,
|
|
835
|
+
returnType: "number",
|
|
836
|
+
acceptsLambda: true,
|
|
837
|
+
lambdaArgPosition: 1,
|
|
838
|
+
params: [
|
|
839
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
840
|
+
{ name: "pred", type: "lambda", description: "Predicate function" }
|
|
841
|
+
],
|
|
842
|
+
example: '["array/findIndex", "@items", ["fn", "x", ["=", "@x.status", "active"]]]'
|
|
843
|
+
},
|
|
844
|
+
"array/filter": {
|
|
845
|
+
module: "array",
|
|
846
|
+
category: "std-array",
|
|
847
|
+
minArity: 2,
|
|
848
|
+
maxArity: 2,
|
|
849
|
+
description: "Keep elements matching predicate",
|
|
850
|
+
hasSideEffects: false,
|
|
851
|
+
returnType: "array",
|
|
852
|
+
acceptsLambda: true,
|
|
853
|
+
lambdaArgPosition: 1,
|
|
854
|
+
params: [
|
|
855
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
856
|
+
{ name: "pred", type: "lambda", description: "Predicate function" }
|
|
857
|
+
],
|
|
858
|
+
example: '["array/filter", "@items", ["fn", "x", [">", "@x.price", 100]]]'
|
|
859
|
+
},
|
|
860
|
+
"array/reject": {
|
|
861
|
+
module: "array",
|
|
862
|
+
category: "std-array",
|
|
863
|
+
minArity: 2,
|
|
864
|
+
maxArity: 2,
|
|
865
|
+
description: "Remove elements matching predicate",
|
|
866
|
+
hasSideEffects: false,
|
|
867
|
+
returnType: "array",
|
|
868
|
+
acceptsLambda: true,
|
|
869
|
+
lambdaArgPosition: 1,
|
|
870
|
+
params: [
|
|
871
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
872
|
+
{ name: "pred", type: "lambda", description: "Predicate function" }
|
|
873
|
+
],
|
|
874
|
+
example: '["array/reject", "@items", ["fn", "x", ["=", "@x.status", "deleted"]]]'
|
|
875
|
+
},
|
|
876
|
+
"array/map": {
|
|
877
|
+
module: "array",
|
|
878
|
+
category: "std-array",
|
|
879
|
+
minArity: 2,
|
|
880
|
+
maxArity: 2,
|
|
881
|
+
description: "Transform each element",
|
|
882
|
+
hasSideEffects: false,
|
|
883
|
+
returnType: "array",
|
|
884
|
+
acceptsLambda: true,
|
|
885
|
+
lambdaArgPosition: 1,
|
|
886
|
+
params: [
|
|
887
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
888
|
+
{ name: "fn", type: "lambda", description: "Transform function" }
|
|
889
|
+
],
|
|
890
|
+
example: '["array/map", "@items", ["fn", "x", ["*", "@x.price", 1.1]]]'
|
|
891
|
+
},
|
|
892
|
+
"array/reduce": {
|
|
893
|
+
module: "array",
|
|
894
|
+
category: "std-array",
|
|
895
|
+
minArity: 3,
|
|
896
|
+
maxArity: 3,
|
|
897
|
+
description: "Reduce array to single value",
|
|
898
|
+
hasSideEffects: false,
|
|
899
|
+
returnType: "any",
|
|
900
|
+
acceptsLambda: true,
|
|
901
|
+
lambdaArgPosition: 1,
|
|
902
|
+
params: [
|
|
903
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
904
|
+
{ name: "fn", type: "lambda", description: "Reducer function (acc, item) => newAcc" },
|
|
905
|
+
{ name: "init", type: "any", description: "Initial accumulator value" }
|
|
906
|
+
],
|
|
907
|
+
example: '["array/reduce", "@items", ["fn", ["acc", "x"], ["+", "@acc", "@x.price"]], 0]'
|
|
908
|
+
},
|
|
909
|
+
"array/every": {
|
|
910
|
+
module: "array",
|
|
911
|
+
category: "std-array",
|
|
912
|
+
minArity: 2,
|
|
913
|
+
maxArity: 2,
|
|
914
|
+
description: "Check if all elements match predicate",
|
|
915
|
+
hasSideEffects: false,
|
|
916
|
+
returnType: "boolean",
|
|
917
|
+
acceptsLambda: true,
|
|
918
|
+
lambdaArgPosition: 1,
|
|
919
|
+
params: [
|
|
920
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
921
|
+
{ name: "pred", type: "lambda", description: "Predicate function" }
|
|
922
|
+
],
|
|
923
|
+
example: '["array/every", "@items", ["fn", "x", [">", "@x.price", 0]]]'
|
|
924
|
+
},
|
|
925
|
+
"array/some": {
|
|
926
|
+
module: "array",
|
|
927
|
+
category: "std-array",
|
|
928
|
+
minArity: 2,
|
|
929
|
+
maxArity: 2,
|
|
930
|
+
description: "Check if any element matches predicate",
|
|
931
|
+
hasSideEffects: false,
|
|
932
|
+
returnType: "boolean",
|
|
933
|
+
acceptsLambda: true,
|
|
934
|
+
lambdaArgPosition: 1,
|
|
935
|
+
params: [
|
|
936
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
937
|
+
{ name: "pred", type: "lambda", description: "Predicate function" }
|
|
938
|
+
],
|
|
939
|
+
example: '["array/some", "@items", ["fn", "x", ["=", "@x.status", "active"]]]'
|
|
940
|
+
},
|
|
941
|
+
"array/count": {
|
|
942
|
+
module: "array",
|
|
943
|
+
category: "std-array",
|
|
944
|
+
minArity: 1,
|
|
945
|
+
maxArity: 2,
|
|
946
|
+
description: "Count elements (optionally matching predicate)",
|
|
947
|
+
hasSideEffects: false,
|
|
948
|
+
returnType: "number",
|
|
949
|
+
acceptsLambda: true,
|
|
950
|
+
lambdaArgPosition: 1,
|
|
951
|
+
params: [
|
|
952
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
953
|
+
{ name: "pred", type: "lambda", description: "Predicate function", optional: true }
|
|
954
|
+
],
|
|
955
|
+
example: '["array/count", "@tasks", ["fn", "t", ["=", "@t.status", "done"]]]'
|
|
956
|
+
},
|
|
957
|
+
"array/sum": {
|
|
958
|
+
module: "array",
|
|
959
|
+
category: "std-array",
|
|
960
|
+
minArity: 1,
|
|
961
|
+
maxArity: 2,
|
|
962
|
+
description: "Sum values (optionally by field)",
|
|
963
|
+
hasSideEffects: false,
|
|
964
|
+
returnType: "number",
|
|
965
|
+
params: [
|
|
966
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
967
|
+
{ name: "key", type: "string", description: "Field to sum", optional: true }
|
|
968
|
+
],
|
|
969
|
+
example: '["array/sum", "@cart.items", "price"]'
|
|
970
|
+
},
|
|
971
|
+
"array/avg": {
|
|
972
|
+
module: "array",
|
|
973
|
+
category: "std-array",
|
|
974
|
+
minArity: 1,
|
|
975
|
+
maxArity: 2,
|
|
976
|
+
description: "Average of values (optionally by field)",
|
|
977
|
+
hasSideEffects: false,
|
|
978
|
+
returnType: "number",
|
|
979
|
+
params: [
|
|
980
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
981
|
+
{ name: "key", type: "string", description: "Field to average", optional: true }
|
|
982
|
+
],
|
|
983
|
+
example: '["array/avg", "@ratings", "score"]'
|
|
984
|
+
},
|
|
985
|
+
"array/min": {
|
|
986
|
+
module: "array",
|
|
987
|
+
category: "std-array",
|
|
988
|
+
minArity: 1,
|
|
989
|
+
maxArity: 2,
|
|
990
|
+
description: "Minimum value (optionally by field)",
|
|
991
|
+
hasSideEffects: false,
|
|
992
|
+
returnType: "number",
|
|
993
|
+
params: [
|
|
994
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
995
|
+
{ name: "key", type: "string", description: "Field to compare", optional: true }
|
|
996
|
+
],
|
|
997
|
+
example: '["array/min", "@products", "price"]'
|
|
998
|
+
},
|
|
999
|
+
"array/max": {
|
|
1000
|
+
module: "array",
|
|
1001
|
+
category: "std-array",
|
|
1002
|
+
minArity: 1,
|
|
1003
|
+
maxArity: 2,
|
|
1004
|
+
description: "Maximum value (optionally by field)",
|
|
1005
|
+
hasSideEffects: false,
|
|
1006
|
+
returnType: "number",
|
|
1007
|
+
params: [
|
|
1008
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
1009
|
+
{ name: "key", type: "string", description: "Field to compare", optional: true }
|
|
1010
|
+
],
|
|
1011
|
+
example: '["array/max", "@products", "price"]'
|
|
1012
|
+
},
|
|
1013
|
+
"array/groupBy": {
|
|
1014
|
+
module: "array",
|
|
1015
|
+
category: "std-array",
|
|
1016
|
+
minArity: 2,
|
|
1017
|
+
maxArity: 2,
|
|
1018
|
+
description: "Group elements by field value",
|
|
1019
|
+
hasSideEffects: false,
|
|
1020
|
+
returnType: "any",
|
|
1021
|
+
params: [
|
|
1022
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
1023
|
+
{ name: "key", type: "string", description: "Field to group by" }
|
|
1024
|
+
],
|
|
1025
|
+
example: '["array/groupBy", "@orders", "status"]'
|
|
1026
|
+
},
|
|
1027
|
+
"array/partition": {
|
|
1028
|
+
module: "array",
|
|
1029
|
+
category: "std-array",
|
|
1030
|
+
minArity: 2,
|
|
1031
|
+
maxArity: 2,
|
|
1032
|
+
description: "Split array by predicate into [matches, nonMatches]",
|
|
1033
|
+
hasSideEffects: false,
|
|
1034
|
+
returnType: "array",
|
|
1035
|
+
acceptsLambda: true,
|
|
1036
|
+
lambdaArgPosition: 1,
|
|
1037
|
+
params: [
|
|
1038
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
1039
|
+
{ name: "pred", type: "lambda", description: "Predicate function" }
|
|
1040
|
+
],
|
|
1041
|
+
example: '["array/partition", "@items", ["fn", "x", [">", "@x.price", 50]]]'
|
|
1042
|
+
},
|
|
1043
|
+
"array/take": {
|
|
1044
|
+
module: "array",
|
|
1045
|
+
category: "std-array",
|
|
1046
|
+
minArity: 2,
|
|
1047
|
+
maxArity: 2,
|
|
1048
|
+
description: "Take first n elements",
|
|
1049
|
+
hasSideEffects: false,
|
|
1050
|
+
returnType: "array",
|
|
1051
|
+
params: [
|
|
1052
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
1053
|
+
{ name: "n", type: "number", description: "Number of elements" }
|
|
1054
|
+
],
|
|
1055
|
+
example: '["array/take", "@items", 5]'
|
|
1056
|
+
},
|
|
1057
|
+
"array/drop": {
|
|
1058
|
+
module: "array",
|
|
1059
|
+
category: "std-array",
|
|
1060
|
+
minArity: 2,
|
|
1061
|
+
maxArity: 2,
|
|
1062
|
+
description: "Skip first n elements",
|
|
1063
|
+
hasSideEffects: false,
|
|
1064
|
+
returnType: "array",
|
|
1065
|
+
params: [
|
|
1066
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
1067
|
+
{ name: "n", type: "number", description: "Number of elements to skip" }
|
|
1068
|
+
],
|
|
1069
|
+
example: '["array/drop", "@items", 5]'
|
|
1070
|
+
},
|
|
1071
|
+
"array/takeLast": {
|
|
1072
|
+
module: "array",
|
|
1073
|
+
category: "std-array",
|
|
1074
|
+
minArity: 2,
|
|
1075
|
+
maxArity: 2,
|
|
1076
|
+
description: "Take last n elements",
|
|
1077
|
+
hasSideEffects: false,
|
|
1078
|
+
returnType: "array",
|
|
1079
|
+
params: [
|
|
1080
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
1081
|
+
{ name: "n", type: "number", description: "Number of elements" }
|
|
1082
|
+
],
|
|
1083
|
+
example: '["array/takeLast", "@items", 3]'
|
|
1084
|
+
},
|
|
1085
|
+
"array/dropLast": {
|
|
1086
|
+
module: "array",
|
|
1087
|
+
category: "std-array",
|
|
1088
|
+
minArity: 2,
|
|
1089
|
+
maxArity: 2,
|
|
1090
|
+
description: "Skip last n elements",
|
|
1091
|
+
hasSideEffects: false,
|
|
1092
|
+
returnType: "array",
|
|
1093
|
+
params: [
|
|
1094
|
+
{ name: "arr", type: "array", description: "The array" },
|
|
1095
|
+
{ name: "n", type: "number", description: "Number of elements to skip" }
|
|
1096
|
+
],
|
|
1097
|
+
example: '["array/dropLast", "@items", 2]'
|
|
1098
|
+
}
|
|
1099
|
+
};
|
|
1100
|
+
function getArrayOperators() {
|
|
1101
|
+
return Object.keys(ARRAY_OPERATORS);
|
|
1102
|
+
}
|
|
1103
|
+
function getLambdaArrayOperators() {
|
|
1104
|
+
return Object.entries(ARRAY_OPERATORS).filter(([, meta]) => meta.acceptsLambda).map(([name]) => name);
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
// modules/object.ts
|
|
1108
|
+
var OBJECT_OPERATORS = {
|
|
1109
|
+
"object/keys": {
|
|
1110
|
+
module: "object",
|
|
1111
|
+
category: "std-object",
|
|
1112
|
+
minArity: 1,
|
|
1113
|
+
maxArity: 1,
|
|
1114
|
+
description: "Get object keys as array",
|
|
1115
|
+
hasSideEffects: false,
|
|
1116
|
+
returnType: "array",
|
|
1117
|
+
params: [{ name: "obj", type: "object", description: "The object" }],
|
|
1118
|
+
example: '["object/keys", {"a": 1, "b": 2}] // => ["a", "b"]'
|
|
1119
|
+
},
|
|
1120
|
+
"object/values": {
|
|
1121
|
+
module: "object",
|
|
1122
|
+
category: "std-object",
|
|
1123
|
+
minArity: 1,
|
|
1124
|
+
maxArity: 1,
|
|
1125
|
+
description: "Get object values as array",
|
|
1126
|
+
hasSideEffects: false,
|
|
1127
|
+
returnType: "array",
|
|
1128
|
+
params: [{ name: "obj", type: "object", description: "The object" }],
|
|
1129
|
+
example: '["object/values", {"a": 1, "b": 2}] // => [1, 2]'
|
|
1130
|
+
},
|
|
1131
|
+
"object/entries": {
|
|
1132
|
+
module: "object",
|
|
1133
|
+
category: "std-object",
|
|
1134
|
+
minArity: 1,
|
|
1135
|
+
maxArity: 1,
|
|
1136
|
+
description: "Get [key, value] pairs as array",
|
|
1137
|
+
hasSideEffects: false,
|
|
1138
|
+
returnType: "array",
|
|
1139
|
+
params: [{ name: "obj", type: "object", description: "The object" }],
|
|
1140
|
+
example: '["object/entries", {"a": 1}] // => [["a", 1]]'
|
|
1141
|
+
},
|
|
1142
|
+
"object/fromEntries": {
|
|
1143
|
+
module: "object",
|
|
1144
|
+
category: "std-object",
|
|
1145
|
+
minArity: 1,
|
|
1146
|
+
maxArity: 1,
|
|
1147
|
+
description: "Create object from [key, value] pairs",
|
|
1148
|
+
hasSideEffects: false,
|
|
1149
|
+
returnType: "any",
|
|
1150
|
+
params: [{ name: "entries", type: "array", description: "Array of [key, value] pairs" }],
|
|
1151
|
+
example: '["object/fromEntries", [["a", 1], ["b", 2]]] // => {"a": 1, "b": 2}'
|
|
1152
|
+
},
|
|
1153
|
+
"object/get": {
|
|
1154
|
+
module: "object",
|
|
1155
|
+
category: "std-object",
|
|
1156
|
+
minArity: 2,
|
|
1157
|
+
maxArity: 3,
|
|
1158
|
+
description: "Get nested value by path",
|
|
1159
|
+
hasSideEffects: false,
|
|
1160
|
+
returnType: "any",
|
|
1161
|
+
params: [
|
|
1162
|
+
{ name: "obj", type: "object", description: "The object" },
|
|
1163
|
+
{ name: "path", type: "string", description: 'Dot-separated path (e.g., "user.name")' },
|
|
1164
|
+
{ name: "default", type: "any", description: "Default if path not found", optional: true }
|
|
1165
|
+
],
|
|
1166
|
+
example: '["object/get", "@user", "profile.name", "Anonymous"]'
|
|
1167
|
+
},
|
|
1168
|
+
"object/set": {
|
|
1169
|
+
module: "object",
|
|
1170
|
+
category: "std-object",
|
|
1171
|
+
minArity: 3,
|
|
1172
|
+
maxArity: 3,
|
|
1173
|
+
description: "Set nested value by path (returns new object)",
|
|
1174
|
+
hasSideEffects: false,
|
|
1175
|
+
returnType: "any",
|
|
1176
|
+
params: [
|
|
1177
|
+
{ name: "obj", type: "object", description: "The object" },
|
|
1178
|
+
{ name: "path", type: "string", description: "Dot-separated path" },
|
|
1179
|
+
{ name: "value", type: "any", description: "Value to set" }
|
|
1180
|
+
],
|
|
1181
|
+
example: '["object/set", "@user", "profile.name", "John"]'
|
|
1182
|
+
},
|
|
1183
|
+
"object/has": {
|
|
1184
|
+
module: "object",
|
|
1185
|
+
category: "std-object",
|
|
1186
|
+
minArity: 2,
|
|
1187
|
+
maxArity: 2,
|
|
1188
|
+
description: "Check if path exists",
|
|
1189
|
+
hasSideEffects: false,
|
|
1190
|
+
returnType: "boolean",
|
|
1191
|
+
params: [
|
|
1192
|
+
{ name: "obj", type: "object", description: "The object" },
|
|
1193
|
+
{ name: "path", type: "string", description: "Dot-separated path" }
|
|
1194
|
+
],
|
|
1195
|
+
example: '["object/has", "@user", "profile.name"]'
|
|
1196
|
+
},
|
|
1197
|
+
"object/merge": {
|
|
1198
|
+
module: "object",
|
|
1199
|
+
category: "std-object",
|
|
1200
|
+
minArity: 2,
|
|
1201
|
+
maxArity: null,
|
|
1202
|
+
description: "Shallow merge objects (later wins)",
|
|
1203
|
+
hasSideEffects: false,
|
|
1204
|
+
returnType: "any",
|
|
1205
|
+
params: [{ name: "...objs", type: "object[]", description: "Objects to merge" }],
|
|
1206
|
+
example: '["object/merge", {"a": 1}, {"b": 2}] // => {"a": 1, "b": 2}'
|
|
1207
|
+
},
|
|
1208
|
+
"object/deepMerge": {
|
|
1209
|
+
module: "object",
|
|
1210
|
+
category: "std-object",
|
|
1211
|
+
minArity: 2,
|
|
1212
|
+
maxArity: null,
|
|
1213
|
+
description: "Deep merge objects (later wins)",
|
|
1214
|
+
hasSideEffects: false,
|
|
1215
|
+
returnType: "any",
|
|
1216
|
+
params: [{ name: "...objs", type: "object[]", description: "Objects to merge" }],
|
|
1217
|
+
example: '["object/deepMerge", {"a": {"b": 1}}, {"a": {"c": 2}}]'
|
|
1218
|
+
},
|
|
1219
|
+
"object/pick": {
|
|
1220
|
+
module: "object",
|
|
1221
|
+
category: "std-object",
|
|
1222
|
+
minArity: 2,
|
|
1223
|
+
maxArity: 2,
|
|
1224
|
+
description: "Select only specified keys",
|
|
1225
|
+
hasSideEffects: false,
|
|
1226
|
+
returnType: "any",
|
|
1227
|
+
params: [
|
|
1228
|
+
{ name: "obj", type: "object", description: "The object" },
|
|
1229
|
+
{ name: "keys", type: "array", description: "Keys to keep" }
|
|
1230
|
+
],
|
|
1231
|
+
example: '["object/pick", "@entity", ["name", "email"]]'
|
|
1232
|
+
},
|
|
1233
|
+
"object/omit": {
|
|
1234
|
+
module: "object",
|
|
1235
|
+
category: "std-object",
|
|
1236
|
+
minArity: 2,
|
|
1237
|
+
maxArity: 2,
|
|
1238
|
+
description: "Exclude specified keys",
|
|
1239
|
+
hasSideEffects: false,
|
|
1240
|
+
returnType: "any",
|
|
1241
|
+
params: [
|
|
1242
|
+
{ name: "obj", type: "object", description: "The object" },
|
|
1243
|
+
{ name: "keys", type: "array", description: "Keys to exclude" }
|
|
1244
|
+
],
|
|
1245
|
+
example: '["object/omit", "@entity", ["password", "secret"]]'
|
|
1246
|
+
},
|
|
1247
|
+
"object/mapValues": {
|
|
1248
|
+
module: "object",
|
|
1249
|
+
category: "std-object",
|
|
1250
|
+
minArity: 2,
|
|
1251
|
+
maxArity: 2,
|
|
1252
|
+
description: "Transform all values",
|
|
1253
|
+
hasSideEffects: false,
|
|
1254
|
+
returnType: "any",
|
|
1255
|
+
acceptsLambda: true,
|
|
1256
|
+
lambdaArgPosition: 1,
|
|
1257
|
+
params: [
|
|
1258
|
+
{ name: "obj", type: "object", description: "The object" },
|
|
1259
|
+
{ name: "fn", type: "lambda", description: "Transform function" }
|
|
1260
|
+
],
|
|
1261
|
+
example: '["object/mapValues", "@stats", ["fn", "v", ["*", "@v", 100]]]'
|
|
1262
|
+
},
|
|
1263
|
+
"object/mapKeys": {
|
|
1264
|
+
module: "object",
|
|
1265
|
+
category: "std-object",
|
|
1266
|
+
minArity: 2,
|
|
1267
|
+
maxArity: 2,
|
|
1268
|
+
description: "Transform all keys",
|
|
1269
|
+
hasSideEffects: false,
|
|
1270
|
+
returnType: "any",
|
|
1271
|
+
acceptsLambda: true,
|
|
1272
|
+
lambdaArgPosition: 1,
|
|
1273
|
+
params: [
|
|
1274
|
+
{ name: "obj", type: "object", description: "The object" },
|
|
1275
|
+
{ name: "fn", type: "lambda", description: "Transform function" }
|
|
1276
|
+
],
|
|
1277
|
+
example: '["object/mapKeys", "@data", ["fn", "k", ["str/upper", "@k"]]]'
|
|
1278
|
+
},
|
|
1279
|
+
"object/filter": {
|
|
1280
|
+
module: "object",
|
|
1281
|
+
category: "std-object",
|
|
1282
|
+
minArity: 2,
|
|
1283
|
+
maxArity: 2,
|
|
1284
|
+
description: "Filter entries by predicate",
|
|
1285
|
+
hasSideEffects: false,
|
|
1286
|
+
returnType: "any",
|
|
1287
|
+
acceptsLambda: true,
|
|
1288
|
+
lambdaArgPosition: 1,
|
|
1289
|
+
params: [
|
|
1290
|
+
{ name: "obj", type: "object", description: "The object" },
|
|
1291
|
+
{ name: "pred", type: "lambda", description: "Predicate (key, value) => boolean" }
|
|
1292
|
+
],
|
|
1293
|
+
example: '["object/filter", "@data", ["fn", ["k", "v"], ["!=", "@v", null]]]'
|
|
1294
|
+
},
|
|
1295
|
+
"object/empty?": {
|
|
1296
|
+
module: "object",
|
|
1297
|
+
category: "std-object",
|
|
1298
|
+
minArity: 1,
|
|
1299
|
+
maxArity: 1,
|
|
1300
|
+
description: "Check if object has no keys",
|
|
1301
|
+
hasSideEffects: false,
|
|
1302
|
+
returnType: "boolean",
|
|
1303
|
+
params: [{ name: "obj", type: "object", description: "The object" }],
|
|
1304
|
+
example: '["object/empty?", {}] // => true'
|
|
1305
|
+
},
|
|
1306
|
+
"object/equals": {
|
|
1307
|
+
module: "object",
|
|
1308
|
+
category: "std-object",
|
|
1309
|
+
minArity: 2,
|
|
1310
|
+
maxArity: 2,
|
|
1311
|
+
description: "Deep equality check",
|
|
1312
|
+
hasSideEffects: false,
|
|
1313
|
+
returnType: "boolean",
|
|
1314
|
+
params: [
|
|
1315
|
+
{ name: "a", type: "object", description: "First object" },
|
|
1316
|
+
{ name: "b", type: "object", description: "Second object" }
|
|
1317
|
+
],
|
|
1318
|
+
example: '["object/equals", {"a": 1}, {"a": 1}] // => true'
|
|
1319
|
+
},
|
|
1320
|
+
"object/clone": {
|
|
1321
|
+
module: "object",
|
|
1322
|
+
category: "std-object",
|
|
1323
|
+
minArity: 1,
|
|
1324
|
+
maxArity: 1,
|
|
1325
|
+
description: "Shallow clone object",
|
|
1326
|
+
hasSideEffects: false,
|
|
1327
|
+
returnType: "any",
|
|
1328
|
+
params: [{ name: "obj", type: "object", description: "The object" }],
|
|
1329
|
+
example: '["object/clone", "@entity"]'
|
|
1330
|
+
},
|
|
1331
|
+
"object/deepClone": {
|
|
1332
|
+
module: "object",
|
|
1333
|
+
category: "std-object",
|
|
1334
|
+
minArity: 1,
|
|
1335
|
+
maxArity: 1,
|
|
1336
|
+
description: "Deep clone object",
|
|
1337
|
+
hasSideEffects: false,
|
|
1338
|
+
returnType: "any",
|
|
1339
|
+
params: [{ name: "obj", type: "object", description: "The object" }],
|
|
1340
|
+
example: '["object/deepClone", "@entity"]'
|
|
1341
|
+
},
|
|
1342
|
+
"path": {
|
|
1343
|
+
module: "object",
|
|
1344
|
+
category: "std-object",
|
|
1345
|
+
minArity: 1,
|
|
1346
|
+
maxArity: null,
|
|
1347
|
+
// variadic
|
|
1348
|
+
description: "Build a dot-separated path string from segments. Used with set effect for dynamic field paths.",
|
|
1349
|
+
hasSideEffects: false,
|
|
1350
|
+
returnType: "string",
|
|
1351
|
+
params: [
|
|
1352
|
+
{ name: "...segments", type: "string[]", description: "Path segments to join with dots" }
|
|
1353
|
+
],
|
|
1354
|
+
example: '["path", "formValues", "@payload.fieldId"] // => "formValues.customerName"'
|
|
1355
|
+
}
|
|
1356
|
+
};
|
|
1357
|
+
function getObjectOperators() {
|
|
1358
|
+
return Object.keys(OBJECT_OPERATORS);
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
// modules/time.ts
|
|
1362
|
+
var TIME_OPERATORS = {
|
|
1363
|
+
"time/now": {
|
|
1364
|
+
module: "time",
|
|
1365
|
+
category: "std-time",
|
|
1366
|
+
minArity: 0,
|
|
1367
|
+
maxArity: 0,
|
|
1368
|
+
description: "Current timestamp",
|
|
1369
|
+
hasSideEffects: false,
|
|
1370
|
+
returnType: "number",
|
|
1371
|
+
params: [],
|
|
1372
|
+
example: '["time/now"] // => 1705593600000'
|
|
1373
|
+
},
|
|
1374
|
+
"time/today": {
|
|
1375
|
+
module: "time",
|
|
1376
|
+
category: "std-time",
|
|
1377
|
+
minArity: 0,
|
|
1378
|
+
maxArity: 0,
|
|
1379
|
+
description: "Today at midnight (local time)",
|
|
1380
|
+
hasSideEffects: false,
|
|
1381
|
+
returnType: "number",
|
|
1382
|
+
params: [],
|
|
1383
|
+
example: '["time/today"]'
|
|
1384
|
+
},
|
|
1385
|
+
"time/parse": {
|
|
1386
|
+
module: "time",
|
|
1387
|
+
category: "std-time",
|
|
1388
|
+
minArity: 1,
|
|
1389
|
+
maxArity: 2,
|
|
1390
|
+
description: "Parse string to timestamp",
|
|
1391
|
+
hasSideEffects: false,
|
|
1392
|
+
returnType: "number",
|
|
1393
|
+
params: [
|
|
1394
|
+
{ name: "str", type: "string", description: "Date string" },
|
|
1395
|
+
{ name: "format", type: "string", description: "Format pattern", optional: true }
|
|
1396
|
+
],
|
|
1397
|
+
example: '["time/parse", "2024-01-18", "YYYY-MM-DD"]'
|
|
1398
|
+
},
|
|
1399
|
+
"time/format": {
|
|
1400
|
+
module: "time",
|
|
1401
|
+
category: "std-time",
|
|
1402
|
+
minArity: 2,
|
|
1403
|
+
maxArity: 2,
|
|
1404
|
+
description: "Format timestamp to string",
|
|
1405
|
+
hasSideEffects: false,
|
|
1406
|
+
returnType: "string",
|
|
1407
|
+
params: [
|
|
1408
|
+
{ name: "date", type: "number", description: "Timestamp" },
|
|
1409
|
+
{ name: "format", type: "string", description: "Format pattern" }
|
|
1410
|
+
],
|
|
1411
|
+
example: '["time/format", "@entity.createdAt", "MMM DD, YYYY"]'
|
|
1412
|
+
},
|
|
1413
|
+
"time/year": {
|
|
1414
|
+
module: "time",
|
|
1415
|
+
category: "std-time",
|
|
1416
|
+
minArity: 1,
|
|
1417
|
+
maxArity: 1,
|
|
1418
|
+
description: "Get year from timestamp",
|
|
1419
|
+
hasSideEffects: false,
|
|
1420
|
+
returnType: "number",
|
|
1421
|
+
params: [{ name: "date", type: "number", description: "Timestamp" }],
|
|
1422
|
+
example: '["time/year", "@entity.createdAt"] // => 2024'
|
|
1423
|
+
},
|
|
1424
|
+
"time/month": {
|
|
1425
|
+
module: "time",
|
|
1426
|
+
category: "std-time",
|
|
1427
|
+
minArity: 1,
|
|
1428
|
+
maxArity: 1,
|
|
1429
|
+
description: "Get month from timestamp (1-12)",
|
|
1430
|
+
hasSideEffects: false,
|
|
1431
|
+
returnType: "number",
|
|
1432
|
+
params: [{ name: "date", type: "number", description: "Timestamp" }],
|
|
1433
|
+
example: '["time/month", "@entity.createdAt"] // => 1'
|
|
1434
|
+
},
|
|
1435
|
+
"time/day": {
|
|
1436
|
+
module: "time",
|
|
1437
|
+
category: "std-time",
|
|
1438
|
+
minArity: 1,
|
|
1439
|
+
maxArity: 1,
|
|
1440
|
+
description: "Get day of month from timestamp (1-31)",
|
|
1441
|
+
hasSideEffects: false,
|
|
1442
|
+
returnType: "number",
|
|
1443
|
+
params: [{ name: "date", type: "number", description: "Timestamp" }],
|
|
1444
|
+
example: '["time/day", "@entity.createdAt"] // => 18'
|
|
1445
|
+
},
|
|
1446
|
+
"time/weekday": {
|
|
1447
|
+
module: "time",
|
|
1448
|
+
category: "std-time",
|
|
1449
|
+
minArity: 1,
|
|
1450
|
+
maxArity: 1,
|
|
1451
|
+
description: "Get day of week (0=Sunday, 6=Saturday)",
|
|
1452
|
+
hasSideEffects: false,
|
|
1453
|
+
returnType: "number",
|
|
1454
|
+
params: [{ name: "date", type: "number", description: "Timestamp" }],
|
|
1455
|
+
example: '["time/weekday", "@entity.createdAt"] // => 4 (Thursday)'
|
|
1456
|
+
},
|
|
1457
|
+
"time/hour": {
|
|
1458
|
+
module: "time",
|
|
1459
|
+
category: "std-time",
|
|
1460
|
+
minArity: 1,
|
|
1461
|
+
maxArity: 1,
|
|
1462
|
+
description: "Get hour from timestamp (0-23)",
|
|
1463
|
+
hasSideEffects: false,
|
|
1464
|
+
returnType: "number",
|
|
1465
|
+
params: [{ name: "date", type: "number", description: "Timestamp" }],
|
|
1466
|
+
example: '["time/hour", "@entity.createdAt"] // => 14'
|
|
1467
|
+
},
|
|
1468
|
+
"time/minute": {
|
|
1469
|
+
module: "time",
|
|
1470
|
+
category: "std-time",
|
|
1471
|
+
minArity: 1,
|
|
1472
|
+
maxArity: 1,
|
|
1473
|
+
description: "Get minute from timestamp (0-59)",
|
|
1474
|
+
hasSideEffects: false,
|
|
1475
|
+
returnType: "number",
|
|
1476
|
+
params: [{ name: "date", type: "number", description: "Timestamp" }],
|
|
1477
|
+
example: '["time/minute", "@entity.createdAt"] // => 30'
|
|
1478
|
+
},
|
|
1479
|
+
"time/second": {
|
|
1480
|
+
module: "time",
|
|
1481
|
+
category: "std-time",
|
|
1482
|
+
minArity: 1,
|
|
1483
|
+
maxArity: 1,
|
|
1484
|
+
description: "Get second from timestamp (0-59)",
|
|
1485
|
+
hasSideEffects: false,
|
|
1486
|
+
returnType: "number",
|
|
1487
|
+
params: [{ name: "date", type: "number", description: "Timestamp" }],
|
|
1488
|
+
example: '["time/second", "@entity.createdAt"] // => 45'
|
|
1489
|
+
},
|
|
1490
|
+
"time/add": {
|
|
1491
|
+
module: "time",
|
|
1492
|
+
category: "std-time",
|
|
1493
|
+
minArity: 3,
|
|
1494
|
+
maxArity: 3,
|
|
1495
|
+
description: "Add time to timestamp",
|
|
1496
|
+
hasSideEffects: false,
|
|
1497
|
+
returnType: "number",
|
|
1498
|
+
params: [
|
|
1499
|
+
{ name: "date", type: "number", description: "Timestamp" },
|
|
1500
|
+
{ name: "amount", type: "number", description: "Amount to add" },
|
|
1501
|
+
{ name: "unit", type: "string", description: "Time unit (year/month/week/day/hour/minute/second/ms)" }
|
|
1502
|
+
],
|
|
1503
|
+
example: '["time/add", ["time/now"], 7, "day"]'
|
|
1504
|
+
},
|
|
1505
|
+
"time/subtract": {
|
|
1506
|
+
module: "time",
|
|
1507
|
+
category: "std-time",
|
|
1508
|
+
minArity: 3,
|
|
1509
|
+
maxArity: 3,
|
|
1510
|
+
description: "Subtract time from timestamp",
|
|
1511
|
+
hasSideEffects: false,
|
|
1512
|
+
returnType: "number",
|
|
1513
|
+
params: [
|
|
1514
|
+
{ name: "date", type: "number", description: "Timestamp" },
|
|
1515
|
+
{ name: "amount", type: "number", description: "Amount to subtract" },
|
|
1516
|
+
{ name: "unit", type: "string", description: "Time unit" }
|
|
1517
|
+
],
|
|
1518
|
+
example: '["time/subtract", ["time/now"], 1, "hour"]'
|
|
1519
|
+
},
|
|
1520
|
+
"time/diff": {
|
|
1521
|
+
module: "time",
|
|
1522
|
+
category: "std-time",
|
|
1523
|
+
minArity: 2,
|
|
1524
|
+
maxArity: 3,
|
|
1525
|
+
description: "Difference between timestamps",
|
|
1526
|
+
hasSideEffects: false,
|
|
1527
|
+
returnType: "number",
|
|
1528
|
+
params: [
|
|
1529
|
+
{ name: "a", type: "number", description: "First timestamp" },
|
|
1530
|
+
{ name: "b", type: "number", description: "Second timestamp" },
|
|
1531
|
+
{ name: "unit", type: "string", description: "Result unit", optional: true, defaultValue: "ms" }
|
|
1532
|
+
],
|
|
1533
|
+
example: '["time/diff", "@entity.birthDate", ["time/now"], "year"]'
|
|
1534
|
+
},
|
|
1535
|
+
"time/startOf": {
|
|
1536
|
+
module: "time",
|
|
1537
|
+
category: "std-time",
|
|
1538
|
+
minArity: 2,
|
|
1539
|
+
maxArity: 2,
|
|
1540
|
+
description: "Get start of time period",
|
|
1541
|
+
hasSideEffects: false,
|
|
1542
|
+
returnType: "number",
|
|
1543
|
+
params: [
|
|
1544
|
+
{ name: "date", type: "number", description: "Timestamp" },
|
|
1545
|
+
{ name: "unit", type: "string", description: "Time unit (year/month/week/day/hour/minute)" }
|
|
1546
|
+
],
|
|
1547
|
+
example: '["time/startOf", ["time/now"], "month"]'
|
|
1548
|
+
},
|
|
1549
|
+
"time/endOf": {
|
|
1550
|
+
module: "time",
|
|
1551
|
+
category: "std-time",
|
|
1552
|
+
minArity: 2,
|
|
1553
|
+
maxArity: 2,
|
|
1554
|
+
description: "Get end of time period",
|
|
1555
|
+
hasSideEffects: false,
|
|
1556
|
+
returnType: "number",
|
|
1557
|
+
params: [
|
|
1558
|
+
{ name: "date", type: "number", description: "Timestamp" },
|
|
1559
|
+
{ name: "unit", type: "string", description: "Time unit" }
|
|
1560
|
+
],
|
|
1561
|
+
example: '["time/endOf", ["time/now"], "month"]'
|
|
1562
|
+
},
|
|
1563
|
+
"time/isBefore": {
|
|
1564
|
+
module: "time",
|
|
1565
|
+
category: "std-time",
|
|
1566
|
+
minArity: 2,
|
|
1567
|
+
maxArity: 2,
|
|
1568
|
+
description: "Check if a is before b",
|
|
1569
|
+
hasSideEffects: false,
|
|
1570
|
+
returnType: "boolean",
|
|
1571
|
+
params: [
|
|
1572
|
+
{ name: "a", type: "number", description: "First timestamp" },
|
|
1573
|
+
{ name: "b", type: "number", description: "Second timestamp" }
|
|
1574
|
+
],
|
|
1575
|
+
example: '["time/isBefore", "@entity.startDate", "@entity.endDate"]'
|
|
1576
|
+
},
|
|
1577
|
+
"time/isAfter": {
|
|
1578
|
+
module: "time",
|
|
1579
|
+
category: "std-time",
|
|
1580
|
+
minArity: 2,
|
|
1581
|
+
maxArity: 2,
|
|
1582
|
+
description: "Check if a is after b",
|
|
1583
|
+
hasSideEffects: false,
|
|
1584
|
+
returnType: "boolean",
|
|
1585
|
+
params: [
|
|
1586
|
+
{ name: "a", type: "number", description: "First timestamp" },
|
|
1587
|
+
{ name: "b", type: "number", description: "Second timestamp" }
|
|
1588
|
+
],
|
|
1589
|
+
example: '["time/isAfter", ["time/now"], "@entity.deadline"]'
|
|
1590
|
+
},
|
|
1591
|
+
"time/isBetween": {
|
|
1592
|
+
module: "time",
|
|
1593
|
+
category: "std-time",
|
|
1594
|
+
minArity: 3,
|
|
1595
|
+
maxArity: 3,
|
|
1596
|
+
description: "Check if date is between start and end",
|
|
1597
|
+
hasSideEffects: false,
|
|
1598
|
+
returnType: "boolean",
|
|
1599
|
+
params: [
|
|
1600
|
+
{ name: "date", type: "number", description: "Timestamp to check" },
|
|
1601
|
+
{ name: "start", type: "number", description: "Range start" },
|
|
1602
|
+
{ name: "end", type: "number", description: "Range end" }
|
|
1603
|
+
],
|
|
1604
|
+
example: '["time/isBetween", ["time/now"], "@entity.startDate", "@entity.endDate"]'
|
|
1605
|
+
},
|
|
1606
|
+
"time/isSame": {
|
|
1607
|
+
module: "time",
|
|
1608
|
+
category: "std-time",
|
|
1609
|
+
minArity: 2,
|
|
1610
|
+
maxArity: 3,
|
|
1611
|
+
description: "Check if timestamps are same (optionally by unit)",
|
|
1612
|
+
hasSideEffects: false,
|
|
1613
|
+
returnType: "boolean",
|
|
1614
|
+
params: [
|
|
1615
|
+
{ name: "a", type: "number", description: "First timestamp" },
|
|
1616
|
+
{ name: "b", type: "number", description: "Second timestamp" },
|
|
1617
|
+
{ name: "unit", type: "string", description: "Comparison unit", optional: true }
|
|
1618
|
+
],
|
|
1619
|
+
example: '["time/isSame", "@a", "@b", "day"]'
|
|
1620
|
+
},
|
|
1621
|
+
"time/isPast": {
|
|
1622
|
+
module: "time",
|
|
1623
|
+
category: "std-time",
|
|
1624
|
+
minArity: 1,
|
|
1625
|
+
maxArity: 1,
|
|
1626
|
+
description: "Check if timestamp is in the past",
|
|
1627
|
+
hasSideEffects: false,
|
|
1628
|
+
returnType: "boolean",
|
|
1629
|
+
params: [{ name: "date", type: "number", description: "Timestamp" }],
|
|
1630
|
+
example: '["time/isPast", "@entity.expiresAt"]'
|
|
1631
|
+
},
|
|
1632
|
+
"time/isFuture": {
|
|
1633
|
+
module: "time",
|
|
1634
|
+
category: "std-time",
|
|
1635
|
+
minArity: 1,
|
|
1636
|
+
maxArity: 1,
|
|
1637
|
+
description: "Check if timestamp is in the future",
|
|
1638
|
+
hasSideEffects: false,
|
|
1639
|
+
returnType: "boolean",
|
|
1640
|
+
params: [{ name: "date", type: "number", description: "Timestamp" }],
|
|
1641
|
+
example: '["time/isFuture", "@entity.scheduledAt"]'
|
|
1642
|
+
},
|
|
1643
|
+
"time/isToday": {
|
|
1644
|
+
module: "time",
|
|
1645
|
+
category: "std-time",
|
|
1646
|
+
minArity: 1,
|
|
1647
|
+
maxArity: 1,
|
|
1648
|
+
description: "Check if timestamp is today",
|
|
1649
|
+
hasSideEffects: false,
|
|
1650
|
+
returnType: "boolean",
|
|
1651
|
+
params: [{ name: "date", type: "number", description: "Timestamp" }],
|
|
1652
|
+
example: '["time/isToday", "@entity.createdAt"]'
|
|
1653
|
+
},
|
|
1654
|
+
"time/relative": {
|
|
1655
|
+
module: "time",
|
|
1656
|
+
category: "std-time",
|
|
1657
|
+
minArity: 1,
|
|
1658
|
+
maxArity: 1,
|
|
1659
|
+
description: 'Format as relative time ("2 hours ago", "in 3 days")',
|
|
1660
|
+
hasSideEffects: false,
|
|
1661
|
+
returnType: "string",
|
|
1662
|
+
params: [{ name: "date", type: "number", description: "Timestamp" }],
|
|
1663
|
+
example: '["time/relative", "@entity.lastActivityAt"] // => "2 hours ago"'
|
|
1664
|
+
},
|
|
1665
|
+
"time/duration": {
|
|
1666
|
+
module: "time",
|
|
1667
|
+
category: "std-time",
|
|
1668
|
+
minArity: 1,
|
|
1669
|
+
maxArity: 1,
|
|
1670
|
+
description: 'Format milliseconds as duration ("2h 30m")',
|
|
1671
|
+
hasSideEffects: false,
|
|
1672
|
+
returnType: "string",
|
|
1673
|
+
params: [{ name: "ms", type: "number", description: "Duration in milliseconds" }],
|
|
1674
|
+
example: '["time/duration", 9000000] // => "2h 30m"'
|
|
1675
|
+
}
|
|
1676
|
+
};
|
|
1677
|
+
function getTimeOperators() {
|
|
1678
|
+
return Object.keys(TIME_OPERATORS);
|
|
1679
|
+
}
|
|
1680
|
+
|
|
1681
|
+
// modules/validate.ts
|
|
1682
|
+
var VALIDATE_OPERATORS = {
|
|
1683
|
+
"validate/required": {
|
|
1684
|
+
module: "validate",
|
|
1685
|
+
category: "std-validate",
|
|
1686
|
+
minArity: 1,
|
|
1687
|
+
maxArity: 1,
|
|
1688
|
+
description: "Check if value is not null, undefined, or empty string",
|
|
1689
|
+
hasSideEffects: false,
|
|
1690
|
+
returnType: "boolean",
|
|
1691
|
+
params: [{ name: "value", type: "any", description: "Value to check" }],
|
|
1692
|
+
example: '["validate/required", "@payload.name"]'
|
|
1693
|
+
},
|
|
1694
|
+
"validate/string": {
|
|
1695
|
+
module: "validate",
|
|
1696
|
+
category: "std-validate",
|
|
1697
|
+
minArity: 1,
|
|
1698
|
+
maxArity: 1,
|
|
1699
|
+
description: "Check if value is a string",
|
|
1700
|
+
hasSideEffects: false,
|
|
1701
|
+
returnType: "boolean",
|
|
1702
|
+
params: [{ name: "value", type: "any", description: "Value to check" }],
|
|
1703
|
+
example: '["validate/string", "@payload.name"]'
|
|
1704
|
+
},
|
|
1705
|
+
"validate/number": {
|
|
1706
|
+
module: "validate",
|
|
1707
|
+
category: "std-validate",
|
|
1708
|
+
minArity: 1,
|
|
1709
|
+
maxArity: 1,
|
|
1710
|
+
description: "Check if value is a number",
|
|
1711
|
+
hasSideEffects: false,
|
|
1712
|
+
returnType: "boolean",
|
|
1713
|
+
params: [{ name: "value", type: "any", description: "Value to check" }],
|
|
1714
|
+
example: '["validate/number", "@payload.age"]'
|
|
1715
|
+
},
|
|
1716
|
+
"validate/boolean": {
|
|
1717
|
+
module: "validate",
|
|
1718
|
+
category: "std-validate",
|
|
1719
|
+
minArity: 1,
|
|
1720
|
+
maxArity: 1,
|
|
1721
|
+
description: "Check if value is a boolean",
|
|
1722
|
+
hasSideEffects: false,
|
|
1723
|
+
returnType: "boolean",
|
|
1724
|
+
params: [{ name: "value", type: "any", description: "Value to check" }],
|
|
1725
|
+
example: '["validate/boolean", "@payload.active"]'
|
|
1726
|
+
},
|
|
1727
|
+
"validate/array": {
|
|
1728
|
+
module: "validate",
|
|
1729
|
+
category: "std-validate",
|
|
1730
|
+
minArity: 1,
|
|
1731
|
+
maxArity: 1,
|
|
1732
|
+
description: "Check if value is an array",
|
|
1733
|
+
hasSideEffects: false,
|
|
1734
|
+
returnType: "boolean",
|
|
1735
|
+
params: [{ name: "value", type: "any", description: "Value to check" }],
|
|
1736
|
+
example: '["validate/array", "@payload.items"]'
|
|
1737
|
+
},
|
|
1738
|
+
"validate/object": {
|
|
1739
|
+
module: "validate",
|
|
1740
|
+
category: "std-validate",
|
|
1741
|
+
minArity: 1,
|
|
1742
|
+
maxArity: 1,
|
|
1743
|
+
description: "Check if value is an object",
|
|
1744
|
+
hasSideEffects: false,
|
|
1745
|
+
returnType: "boolean",
|
|
1746
|
+
params: [{ name: "value", type: "any", description: "Value to check" }],
|
|
1747
|
+
example: '["validate/object", "@payload.data"]'
|
|
1748
|
+
},
|
|
1749
|
+
"validate/email": {
|
|
1750
|
+
module: "validate",
|
|
1751
|
+
category: "std-validate",
|
|
1752
|
+
minArity: 1,
|
|
1753
|
+
maxArity: 1,
|
|
1754
|
+
description: "Check if value is a valid email format",
|
|
1755
|
+
hasSideEffects: false,
|
|
1756
|
+
returnType: "boolean",
|
|
1757
|
+
params: [{ name: "value", type: "string", description: "Email to validate" }],
|
|
1758
|
+
example: '["validate/email", "@payload.email"]'
|
|
1759
|
+
},
|
|
1760
|
+
"validate/url": {
|
|
1761
|
+
module: "validate",
|
|
1762
|
+
category: "std-validate",
|
|
1763
|
+
minArity: 1,
|
|
1764
|
+
maxArity: 1,
|
|
1765
|
+
description: "Check if value is a valid URL format",
|
|
1766
|
+
hasSideEffects: false,
|
|
1767
|
+
returnType: "boolean",
|
|
1768
|
+
params: [{ name: "value", type: "string", description: "URL to validate" }],
|
|
1769
|
+
example: '["validate/url", "@payload.website"]'
|
|
1770
|
+
},
|
|
1771
|
+
"validate/uuid": {
|
|
1772
|
+
module: "validate",
|
|
1773
|
+
category: "std-validate",
|
|
1774
|
+
minArity: 1,
|
|
1775
|
+
maxArity: 1,
|
|
1776
|
+
description: "Check if value is a valid UUID",
|
|
1777
|
+
hasSideEffects: false,
|
|
1778
|
+
returnType: "boolean",
|
|
1779
|
+
params: [{ name: "value", type: "string", description: "UUID to validate" }],
|
|
1780
|
+
example: '["validate/uuid", "@payload.id"]'
|
|
1781
|
+
},
|
|
1782
|
+
"validate/phone": {
|
|
1783
|
+
module: "validate",
|
|
1784
|
+
category: "std-validate",
|
|
1785
|
+
minArity: 1,
|
|
1786
|
+
maxArity: 1,
|
|
1787
|
+
description: "Check if value is a valid phone number",
|
|
1788
|
+
hasSideEffects: false,
|
|
1789
|
+
returnType: "boolean",
|
|
1790
|
+
params: [{ name: "value", type: "string", description: "Phone number to validate" }],
|
|
1791
|
+
example: '["validate/phone", "@payload.phone"]'
|
|
1792
|
+
},
|
|
1793
|
+
"validate/creditCard": {
|
|
1794
|
+
module: "validate",
|
|
1795
|
+
category: "std-validate",
|
|
1796
|
+
minArity: 1,
|
|
1797
|
+
maxArity: 1,
|
|
1798
|
+
description: "Check if value is a valid credit card number (Luhn algorithm)",
|
|
1799
|
+
hasSideEffects: false,
|
|
1800
|
+
returnType: "boolean",
|
|
1801
|
+
params: [{ name: "value", type: "string", description: "Card number to validate" }],
|
|
1802
|
+
example: '["validate/creditCard", "@payload.cardNumber"]'
|
|
1803
|
+
},
|
|
1804
|
+
"validate/date": {
|
|
1805
|
+
module: "validate",
|
|
1806
|
+
category: "std-validate",
|
|
1807
|
+
minArity: 1,
|
|
1808
|
+
maxArity: 1,
|
|
1809
|
+
description: "Check if value is a valid date",
|
|
1810
|
+
hasSideEffects: false,
|
|
1811
|
+
returnType: "boolean",
|
|
1812
|
+
params: [{ name: "value", type: "any", description: "Value to check" }],
|
|
1813
|
+
example: '["validate/date", "@payload.birthDate"]'
|
|
1814
|
+
},
|
|
1815
|
+
"validate/minLength": {
|
|
1816
|
+
module: "validate",
|
|
1817
|
+
category: "std-validate",
|
|
1818
|
+
minArity: 2,
|
|
1819
|
+
maxArity: 2,
|
|
1820
|
+
description: "Check if string/array has minimum length",
|
|
1821
|
+
hasSideEffects: false,
|
|
1822
|
+
returnType: "boolean",
|
|
1823
|
+
params: [
|
|
1824
|
+
{ name: "value", type: "string | array", description: "Value to check" },
|
|
1825
|
+
{ name: "min", type: "number", description: "Minimum length" }
|
|
1826
|
+
],
|
|
1827
|
+
example: '["validate/minLength", "@payload.password", 8]'
|
|
1828
|
+
},
|
|
1829
|
+
"validate/maxLength": {
|
|
1830
|
+
module: "validate",
|
|
1831
|
+
category: "std-validate",
|
|
1832
|
+
minArity: 2,
|
|
1833
|
+
maxArity: 2,
|
|
1834
|
+
description: "Check if string/array has maximum length",
|
|
1835
|
+
hasSideEffects: false,
|
|
1836
|
+
returnType: "boolean",
|
|
1837
|
+
params: [
|
|
1838
|
+
{ name: "value", type: "string | array", description: "Value to check" },
|
|
1839
|
+
{ name: "max", type: "number", description: "Maximum length" }
|
|
1840
|
+
],
|
|
1841
|
+
example: '["validate/maxLength", "@payload.name", 50]'
|
|
1842
|
+
},
|
|
1843
|
+
"validate/length": {
|
|
1844
|
+
module: "validate",
|
|
1845
|
+
category: "std-validate",
|
|
1846
|
+
minArity: 2,
|
|
1847
|
+
maxArity: 2,
|
|
1848
|
+
description: "Check if string/array has exact length",
|
|
1849
|
+
hasSideEffects: false,
|
|
1850
|
+
returnType: "boolean",
|
|
1851
|
+
params: [
|
|
1852
|
+
{ name: "value", type: "string | array", description: "Value to check" },
|
|
1853
|
+
{ name: "exact", type: "number", description: "Required length" }
|
|
1854
|
+
],
|
|
1855
|
+
example: '["validate/length", "@payload.code", 6]'
|
|
1856
|
+
},
|
|
1857
|
+
"validate/min": {
|
|
1858
|
+
module: "validate",
|
|
1859
|
+
category: "std-validate",
|
|
1860
|
+
minArity: 2,
|
|
1861
|
+
maxArity: 2,
|
|
1862
|
+
description: "Check if number is >= minimum",
|
|
1863
|
+
hasSideEffects: false,
|
|
1864
|
+
returnType: "boolean",
|
|
1865
|
+
params: [
|
|
1866
|
+
{ name: "value", type: "number", description: "Number to check" },
|
|
1867
|
+
{ name: "min", type: "number", description: "Minimum value" }
|
|
1868
|
+
],
|
|
1869
|
+
example: '["validate/min", "@payload.age", 18]'
|
|
1870
|
+
},
|
|
1871
|
+
"validate/max": {
|
|
1872
|
+
module: "validate",
|
|
1873
|
+
category: "std-validate",
|
|
1874
|
+
minArity: 2,
|
|
1875
|
+
maxArity: 2,
|
|
1876
|
+
description: "Check if number is <= maximum",
|
|
1877
|
+
hasSideEffects: false,
|
|
1878
|
+
returnType: "boolean",
|
|
1879
|
+
params: [
|
|
1880
|
+
{ name: "value", type: "number", description: "Number to check" },
|
|
1881
|
+
{ name: "max", type: "number", description: "Maximum value" }
|
|
1882
|
+
],
|
|
1883
|
+
example: '["validate/max", "@payload.quantity", 100]'
|
|
1884
|
+
},
|
|
1885
|
+
"validate/range": {
|
|
1886
|
+
module: "validate",
|
|
1887
|
+
category: "std-validate",
|
|
1888
|
+
minArity: 3,
|
|
1889
|
+
maxArity: 3,
|
|
1890
|
+
description: "Check if number is within range [min, max]",
|
|
1891
|
+
hasSideEffects: false,
|
|
1892
|
+
returnType: "boolean",
|
|
1893
|
+
params: [
|
|
1894
|
+
{ name: "value", type: "number", description: "Number to check" },
|
|
1895
|
+
{ name: "min", type: "number", description: "Minimum value" },
|
|
1896
|
+
{ name: "max", type: "number", description: "Maximum value" }
|
|
1897
|
+
],
|
|
1898
|
+
example: '["validate/range", "@payload.rating", 1, 5]'
|
|
1899
|
+
},
|
|
1900
|
+
"validate/pattern": {
|
|
1901
|
+
module: "validate",
|
|
1902
|
+
category: "std-validate",
|
|
1903
|
+
minArity: 2,
|
|
1904
|
+
maxArity: 2,
|
|
1905
|
+
description: "Check if string matches regex pattern",
|
|
1906
|
+
hasSideEffects: false,
|
|
1907
|
+
returnType: "boolean",
|
|
1908
|
+
params: [
|
|
1909
|
+
{ name: "value", type: "string", description: "String to check" },
|
|
1910
|
+
{ name: "regex", type: "string", description: "Regex pattern" }
|
|
1911
|
+
],
|
|
1912
|
+
example: '["validate/pattern", "@payload.code", "^[A-Z]{3}[0-9]{3}$"]'
|
|
1913
|
+
},
|
|
1914
|
+
"validate/oneOf": {
|
|
1915
|
+
module: "validate",
|
|
1916
|
+
category: "std-validate",
|
|
1917
|
+
minArity: 2,
|
|
1918
|
+
maxArity: 2,
|
|
1919
|
+
description: "Check if value is in list of allowed values",
|
|
1920
|
+
hasSideEffects: false,
|
|
1921
|
+
returnType: "boolean",
|
|
1922
|
+
params: [
|
|
1923
|
+
{ name: "value", type: "any", description: "Value to check" },
|
|
1924
|
+
{ name: "options", type: "array", description: "Allowed values" }
|
|
1925
|
+
],
|
|
1926
|
+
example: '["validate/oneOf", "@payload.role", ["admin", "user", "guest"]]'
|
|
1927
|
+
},
|
|
1928
|
+
"validate/noneOf": {
|
|
1929
|
+
module: "validate",
|
|
1930
|
+
category: "std-validate",
|
|
1931
|
+
minArity: 2,
|
|
1932
|
+
maxArity: 2,
|
|
1933
|
+
description: "Check if value is not in list of disallowed values",
|
|
1934
|
+
hasSideEffects: false,
|
|
1935
|
+
returnType: "boolean",
|
|
1936
|
+
params: [
|
|
1937
|
+
{ name: "value", type: "any", description: "Value to check" },
|
|
1938
|
+
{ name: "options", type: "array", description: "Disallowed values" }
|
|
1939
|
+
],
|
|
1940
|
+
example: '["validate/noneOf", "@payload.username", ["admin", "root", "system"]]'
|
|
1941
|
+
},
|
|
1942
|
+
"validate/equals": {
|
|
1943
|
+
module: "validate",
|
|
1944
|
+
category: "std-validate",
|
|
1945
|
+
minArity: 2,
|
|
1946
|
+
maxArity: 2,
|
|
1947
|
+
description: "Deep equality check",
|
|
1948
|
+
hasSideEffects: false,
|
|
1949
|
+
returnType: "boolean",
|
|
1950
|
+
params: [
|
|
1951
|
+
{ name: "a", type: "any", description: "First value" },
|
|
1952
|
+
{ name: "b", type: "any", description: "Second value" }
|
|
1953
|
+
],
|
|
1954
|
+
example: '["validate/equals", "@payload.password", "@payload.confirmPassword"]'
|
|
1955
|
+
},
|
|
1956
|
+
"validate/check": {
|
|
1957
|
+
module: "validate",
|
|
1958
|
+
category: "std-validate",
|
|
1959
|
+
minArity: 2,
|
|
1960
|
+
maxArity: 2,
|
|
1961
|
+
description: "Run multiple validation rules, return { valid, errors }",
|
|
1962
|
+
hasSideEffects: false,
|
|
1963
|
+
returnType: "any",
|
|
1964
|
+
params: [
|
|
1965
|
+
{ name: "value", type: "any", description: "Value or object to validate" },
|
|
1966
|
+
{ name: "rules", type: "object", description: "Validation rules by field" }
|
|
1967
|
+
],
|
|
1968
|
+
example: `["validate/check", "@payload.data", {
|
|
1969
|
+
"name": [["required"], ["minLength", 2], ["maxLength", 50]],
|
|
1970
|
+
"email": [["required"], ["email"]],
|
|
1971
|
+
"age": [["number"], ["min", 18]]
|
|
1972
|
+
}]`
|
|
1973
|
+
}
|
|
1974
|
+
};
|
|
1975
|
+
function getValidateOperators() {
|
|
1976
|
+
return Object.keys(VALIDATE_OPERATORS);
|
|
1977
|
+
}
|
|
1978
|
+
|
|
1979
|
+
// modules/format.ts
|
|
1980
|
+
var FORMAT_OPERATORS = {
|
|
1981
|
+
"format/number": {
|
|
1982
|
+
module: "format",
|
|
1983
|
+
category: "std-format",
|
|
1984
|
+
minArity: 1,
|
|
1985
|
+
maxArity: 2,
|
|
1986
|
+
description: "Format number with locale-aware separators",
|
|
1987
|
+
hasSideEffects: false,
|
|
1988
|
+
returnType: "string",
|
|
1989
|
+
params: [
|
|
1990
|
+
{ name: "n", type: "number", description: "Number to format" },
|
|
1991
|
+
{ name: "opts", type: "object", description: "Format options (decimals, locale)", optional: true }
|
|
1992
|
+
],
|
|
1993
|
+
example: '["format/number", 1234567.89] // => "1,234,567.89"'
|
|
1994
|
+
},
|
|
1995
|
+
"format/currency": {
|
|
1996
|
+
module: "format",
|
|
1997
|
+
category: "std-format",
|
|
1998
|
+
minArity: 2,
|
|
1999
|
+
maxArity: 3,
|
|
2000
|
+
description: "Format as currency",
|
|
2001
|
+
hasSideEffects: false,
|
|
2002
|
+
returnType: "string",
|
|
2003
|
+
params: [
|
|
2004
|
+
{ name: "n", type: "number", description: "Amount" },
|
|
2005
|
+
{ name: "currency", type: "string", description: "Currency code (USD, EUR, etc.)" },
|
|
2006
|
+
{ name: "locale", type: "string", description: "Locale", optional: true, defaultValue: "en-US" }
|
|
2007
|
+
],
|
|
2008
|
+
example: '["format/currency", 1234.56, "USD"] // => "$1,234.56"'
|
|
2009
|
+
},
|
|
2010
|
+
"format/percent": {
|
|
2011
|
+
module: "format",
|
|
2012
|
+
category: "std-format",
|
|
2013
|
+
minArity: 1,
|
|
2014
|
+
maxArity: 2,
|
|
2015
|
+
description: "Format as percentage",
|
|
2016
|
+
hasSideEffects: false,
|
|
2017
|
+
returnType: "string",
|
|
2018
|
+
params: [
|
|
2019
|
+
{ name: "n", type: "number", description: "Number (0.5 = 50%)" },
|
|
2020
|
+
{ name: "decimals", type: "number", description: "Decimal places", optional: true, defaultValue: 0 }
|
|
2021
|
+
],
|
|
2022
|
+
example: '["format/percent", 0.856, 1] // => "85.6%"'
|
|
2023
|
+
},
|
|
2024
|
+
"format/bytes": {
|
|
2025
|
+
module: "format",
|
|
2026
|
+
category: "std-format",
|
|
2027
|
+
minArity: 1,
|
|
2028
|
+
maxArity: 1,
|
|
2029
|
+
description: "Format bytes as human-readable size",
|
|
2030
|
+
hasSideEffects: false,
|
|
2031
|
+
returnType: "string",
|
|
2032
|
+
params: [{ name: "n", type: "number", description: "Bytes" }],
|
|
2033
|
+
example: '["format/bytes", 2500000] // => "2.4 MB"'
|
|
2034
|
+
},
|
|
2035
|
+
"format/ordinal": {
|
|
2036
|
+
module: "format",
|
|
2037
|
+
category: "std-format",
|
|
2038
|
+
minArity: 1,
|
|
2039
|
+
maxArity: 1,
|
|
2040
|
+
description: "Format number as ordinal (1st, 2nd, 3rd)",
|
|
2041
|
+
hasSideEffects: false,
|
|
2042
|
+
returnType: "string",
|
|
2043
|
+
params: [{ name: "n", type: "number", description: "Number" }],
|
|
2044
|
+
example: '["format/ordinal", 42] // => "42nd"'
|
|
2045
|
+
},
|
|
2046
|
+
"format/plural": {
|
|
2047
|
+
module: "format",
|
|
2048
|
+
category: "std-format",
|
|
2049
|
+
minArity: 3,
|
|
2050
|
+
maxArity: 3,
|
|
2051
|
+
description: "Format count with singular/plural word",
|
|
2052
|
+
hasSideEffects: false,
|
|
2053
|
+
returnType: "string",
|
|
2054
|
+
params: [
|
|
2055
|
+
{ name: "n", type: "number", description: "Count" },
|
|
2056
|
+
{ name: "singular", type: "string", description: "Singular form" },
|
|
2057
|
+
{ name: "plural", type: "string", description: "Plural form" }
|
|
2058
|
+
],
|
|
2059
|
+
example: '["format/plural", 5, "item", "items"] // => "5 items"'
|
|
2060
|
+
},
|
|
2061
|
+
"format/list": {
|
|
2062
|
+
module: "format",
|
|
2063
|
+
category: "std-format",
|
|
2064
|
+
minArity: 1,
|
|
2065
|
+
maxArity: 2,
|
|
2066
|
+
description: "Format array as natural language list",
|
|
2067
|
+
hasSideEffects: false,
|
|
2068
|
+
returnType: "string",
|
|
2069
|
+
params: [
|
|
2070
|
+
{ name: "arr", type: "array", description: "Array of strings" },
|
|
2071
|
+
{ name: "style", type: "string", description: '"and" or "or"', optional: true, defaultValue: "and" }
|
|
2072
|
+
],
|
|
2073
|
+
example: '["format/list", ["Alice", "Bob", "Charlie"], "and"] // => "Alice, Bob, and Charlie"'
|
|
2074
|
+
},
|
|
2075
|
+
"format/phone": {
|
|
2076
|
+
module: "format",
|
|
2077
|
+
category: "std-format",
|
|
2078
|
+
minArity: 1,
|
|
2079
|
+
maxArity: 2,
|
|
2080
|
+
description: "Format phone number",
|
|
2081
|
+
hasSideEffects: false,
|
|
2082
|
+
returnType: "string",
|
|
2083
|
+
params: [
|
|
2084
|
+
{ name: "str", type: "string", description: "Phone number digits" },
|
|
2085
|
+
{ name: "format", type: "string", description: "Format pattern", optional: true, defaultValue: "US" }
|
|
2086
|
+
],
|
|
2087
|
+
example: '["format/phone", "5551234567"] // => "(555) 123-4567"'
|
|
2088
|
+
},
|
|
2089
|
+
"format/creditCard": {
|
|
2090
|
+
module: "format",
|
|
2091
|
+
category: "std-format",
|
|
2092
|
+
minArity: 1,
|
|
2093
|
+
maxArity: 1,
|
|
2094
|
+
description: "Format credit card with masked digits",
|
|
2095
|
+
hasSideEffects: false,
|
|
2096
|
+
returnType: "string",
|
|
2097
|
+
params: [{ name: "str", type: "string", description: "Card number" }],
|
|
2098
|
+
example: '["format/creditCard", "4111111111111234"] // => "\u2022\u2022\u2022\u2022 \u2022\u2022\u2022\u2022 \u2022\u2022\u2022\u2022 1234"'
|
|
2099
|
+
}
|
|
2100
|
+
};
|
|
2101
|
+
function getFormatOperators() {
|
|
2102
|
+
return Object.keys(FORMAT_OPERATORS);
|
|
2103
|
+
}
|
|
2104
|
+
|
|
2105
|
+
// modules/async.ts
|
|
2106
|
+
var ASYNC_OPERATORS = {
|
|
2107
|
+
"async/delay": {
|
|
2108
|
+
module: "async",
|
|
2109
|
+
category: "std-async",
|
|
2110
|
+
minArity: 1,
|
|
2111
|
+
maxArity: 1,
|
|
2112
|
+
description: "Wait for specified milliseconds",
|
|
2113
|
+
hasSideEffects: true,
|
|
2114
|
+
returnType: "void",
|
|
2115
|
+
params: [{ name: "ms", type: "number", description: "Milliseconds to wait" }],
|
|
2116
|
+
example: '["async/delay", 2000] // Wait 2 seconds'
|
|
2117
|
+
},
|
|
2118
|
+
"async/timeout": {
|
|
2119
|
+
module: "async",
|
|
2120
|
+
category: "std-async",
|
|
2121
|
+
minArity: 2,
|
|
2122
|
+
maxArity: 2,
|
|
2123
|
+
description: "Add timeout to an effect",
|
|
2124
|
+
hasSideEffects: true,
|
|
2125
|
+
returnType: "any",
|
|
2126
|
+
params: [
|
|
2127
|
+
{ name: "effect", type: "expression", description: "Effect to execute" },
|
|
2128
|
+
{ name: "ms", type: "number", description: "Timeout in milliseconds" }
|
|
2129
|
+
],
|
|
2130
|
+
example: '["async/timeout", ["call", "api", "fetchData"], 5000]'
|
|
2131
|
+
},
|
|
2132
|
+
"async/debounce": {
|
|
2133
|
+
module: "async",
|
|
2134
|
+
category: "std-async",
|
|
2135
|
+
minArity: 2,
|
|
2136
|
+
maxArity: 2,
|
|
2137
|
+
description: "Debounce an event (wait for pause in events)",
|
|
2138
|
+
hasSideEffects: true,
|
|
2139
|
+
returnType: "void",
|
|
2140
|
+
params: [
|
|
2141
|
+
{ name: "event", type: "string", description: "Event name to emit" },
|
|
2142
|
+
{ name: "ms", type: "number", description: "Debounce delay in milliseconds" }
|
|
2143
|
+
],
|
|
2144
|
+
example: '["async/debounce", "SEARCH", 300]'
|
|
2145
|
+
},
|
|
2146
|
+
"async/throttle": {
|
|
2147
|
+
module: "async",
|
|
2148
|
+
category: "std-async",
|
|
2149
|
+
minArity: 2,
|
|
2150
|
+
maxArity: 2,
|
|
2151
|
+
description: "Throttle an event (emit at most once per interval)",
|
|
2152
|
+
hasSideEffects: true,
|
|
2153
|
+
returnType: "void",
|
|
2154
|
+
params: [
|
|
2155
|
+
{ name: "event", type: "string", description: "Event name to emit" },
|
|
2156
|
+
{ name: "ms", type: "number", description: "Throttle interval in milliseconds" }
|
|
2157
|
+
],
|
|
2158
|
+
example: '["async/throttle", "SCROLL", 100]'
|
|
2159
|
+
},
|
|
2160
|
+
"async/retry": {
|
|
2161
|
+
module: "async",
|
|
2162
|
+
category: "std-async",
|
|
2163
|
+
minArity: 2,
|
|
2164
|
+
maxArity: 2,
|
|
2165
|
+
description: "Retry an effect with configurable backoff",
|
|
2166
|
+
hasSideEffects: true,
|
|
2167
|
+
returnType: "any",
|
|
2168
|
+
params: [
|
|
2169
|
+
{ name: "effect", type: "expression", description: "Effect to retry" },
|
|
2170
|
+
{ name: "opts", type: "object", description: "{ attempts, backoff, baseDelay }" }
|
|
2171
|
+
],
|
|
2172
|
+
example: `["async/retry",
|
|
2173
|
+
["call", "api", "fetchData", { "id": "@entity.id" }],
|
|
2174
|
+
{ "attempts": 3, "backoff": "exponential", "baseDelay": 1000 }]`
|
|
2175
|
+
},
|
|
2176
|
+
"async/race": {
|
|
2177
|
+
module: "async",
|
|
2178
|
+
category: "std-async",
|
|
2179
|
+
minArity: 2,
|
|
2180
|
+
maxArity: null,
|
|
2181
|
+
description: "Execute effects in parallel, return first to complete",
|
|
2182
|
+
hasSideEffects: true,
|
|
2183
|
+
returnType: "any",
|
|
2184
|
+
params: [{ name: "...effects", type: "expression[]", description: "Effects to race" }],
|
|
2185
|
+
example: '["async/race", ["call", "api1"], ["call", "api2"]]'
|
|
2186
|
+
},
|
|
2187
|
+
"async/all": {
|
|
2188
|
+
module: "async",
|
|
2189
|
+
category: "std-async",
|
|
2190
|
+
minArity: 2,
|
|
2191
|
+
maxArity: null,
|
|
2192
|
+
description: "Execute effects in parallel, wait for all to complete",
|
|
2193
|
+
hasSideEffects: true,
|
|
2194
|
+
returnType: "array",
|
|
2195
|
+
params: [{ name: "...effects", type: "expression[]", description: "Effects to execute" }],
|
|
2196
|
+
example: '["async/all", ["call", "api1"], ["call", "api2"]]'
|
|
2197
|
+
},
|
|
2198
|
+
"async/sequence": {
|
|
2199
|
+
module: "async",
|
|
2200
|
+
category: "std-async",
|
|
2201
|
+
minArity: 2,
|
|
2202
|
+
maxArity: null,
|
|
2203
|
+
description: "Execute effects in sequence (one after another)",
|
|
2204
|
+
hasSideEffects: true,
|
|
2205
|
+
returnType: "array",
|
|
2206
|
+
params: [{ name: "...effects", type: "expression[]", description: "Effects to execute in order" }],
|
|
2207
|
+
example: '["async/sequence", ["call", "validate"], ["call", "save"]]'
|
|
2208
|
+
}
|
|
2209
|
+
};
|
|
2210
|
+
function getAsyncOperators() {
|
|
2211
|
+
return Object.keys(ASYNC_OPERATORS);
|
|
2212
|
+
}
|
|
2213
|
+
|
|
2214
|
+
// modules/nn.ts
|
|
2215
|
+
var NN_OPERATORS = {
|
|
2216
|
+
"nn/sequential": {
|
|
2217
|
+
module: "nn",
|
|
2218
|
+
category: "std-nn",
|
|
2219
|
+
minArity: 1,
|
|
2220
|
+
maxArity: null,
|
|
2221
|
+
description: "Create a sequential neural network from layers",
|
|
2222
|
+
hasSideEffects: false,
|
|
2223
|
+
returnType: "nn/module",
|
|
2224
|
+
params: [
|
|
2225
|
+
{ name: "...layers", type: "nn/layer[]", description: "Layers to stack sequentially" }
|
|
2226
|
+
],
|
|
2227
|
+
example: '["nn/sequential", ["nn/linear", 16, 64], ["nn/relu"], ["nn/linear", 64, 4]]'
|
|
2228
|
+
},
|
|
2229
|
+
"nn/linear": {
|
|
2230
|
+
module: "nn",
|
|
2231
|
+
category: "std-nn",
|
|
2232
|
+
minArity: 2,
|
|
2233
|
+
maxArity: 2,
|
|
2234
|
+
description: "Fully connected linear layer (output = input * weights + bias)",
|
|
2235
|
+
hasSideEffects: false,
|
|
2236
|
+
returnType: "nn/layer",
|
|
2237
|
+
params: [
|
|
2238
|
+
{ name: "inFeatures", type: "number", description: "Input dimension" },
|
|
2239
|
+
{ name: "outFeatures", type: "number", description: "Output dimension" }
|
|
2240
|
+
],
|
|
2241
|
+
example: '["nn/linear", 16, 64] // 16 inputs -> 64 outputs'
|
|
2242
|
+
},
|
|
2243
|
+
"nn/relu": {
|
|
2244
|
+
module: "nn",
|
|
2245
|
+
category: "std-nn",
|
|
2246
|
+
minArity: 0,
|
|
2247
|
+
maxArity: 0,
|
|
2248
|
+
description: "ReLU activation function: max(0, x)",
|
|
2249
|
+
hasSideEffects: false,
|
|
2250
|
+
returnType: "nn/layer",
|
|
2251
|
+
params: [],
|
|
2252
|
+
example: '["nn/relu"]'
|
|
2253
|
+
},
|
|
2254
|
+
"nn/tanh": {
|
|
2255
|
+
module: "nn",
|
|
2256
|
+
category: "std-nn",
|
|
2257
|
+
minArity: 0,
|
|
2258
|
+
maxArity: 0,
|
|
2259
|
+
description: "Tanh activation function: (e^x - e^-x) / (e^x + e^-x)",
|
|
2260
|
+
hasSideEffects: false,
|
|
2261
|
+
returnType: "nn/layer",
|
|
2262
|
+
params: [],
|
|
2263
|
+
example: '["nn/tanh"]'
|
|
2264
|
+
},
|
|
2265
|
+
"nn/sigmoid": {
|
|
2266
|
+
module: "nn",
|
|
2267
|
+
category: "std-nn",
|
|
2268
|
+
minArity: 0,
|
|
2269
|
+
maxArity: 0,
|
|
2270
|
+
description: "Sigmoid activation function: 1 / (1 + e^-x)",
|
|
2271
|
+
hasSideEffects: false,
|
|
2272
|
+
returnType: "nn/layer",
|
|
2273
|
+
params: [],
|
|
2274
|
+
example: '["nn/sigmoid"]'
|
|
2275
|
+
},
|
|
2276
|
+
"nn/softmax": {
|
|
2277
|
+
module: "nn",
|
|
2278
|
+
category: "std-nn",
|
|
2279
|
+
minArity: 0,
|
|
2280
|
+
maxArity: 1,
|
|
2281
|
+
description: "Softmax activation function (normalizes to probability distribution)",
|
|
2282
|
+
hasSideEffects: false,
|
|
2283
|
+
returnType: "nn/layer",
|
|
2284
|
+
params: [
|
|
2285
|
+
{ name: "dim", type: "number", description: "Dimension to apply softmax", optional: true, defaultValue: -1 }
|
|
2286
|
+
],
|
|
2287
|
+
example: '["nn/softmax"]'
|
|
2288
|
+
},
|
|
2289
|
+
"nn/dropout": {
|
|
2290
|
+
module: "nn",
|
|
2291
|
+
category: "std-nn",
|
|
2292
|
+
minArity: 0,
|
|
2293
|
+
maxArity: 1,
|
|
2294
|
+
description: "Dropout layer for regularization (randomly zeros elements during training)",
|
|
2295
|
+
hasSideEffects: false,
|
|
2296
|
+
returnType: "nn/layer",
|
|
2297
|
+
params: [
|
|
2298
|
+
{ name: "p", type: "number", description: "Dropout probability", optional: true, defaultValue: 0.5 }
|
|
2299
|
+
],
|
|
2300
|
+
example: '["nn/dropout", 0.3] // 30% dropout'
|
|
2301
|
+
},
|
|
2302
|
+
"nn/batchnorm": {
|
|
2303
|
+
module: "nn",
|
|
2304
|
+
category: "std-nn",
|
|
2305
|
+
minArity: 1,
|
|
2306
|
+
maxArity: 1,
|
|
2307
|
+
description: "Batch normalization layer",
|
|
2308
|
+
hasSideEffects: false,
|
|
2309
|
+
returnType: "nn/layer",
|
|
2310
|
+
params: [
|
|
2311
|
+
{ name: "numFeatures", type: "number", description: "Number of features to normalize" }
|
|
2312
|
+
],
|
|
2313
|
+
example: '["nn/batchnorm", 64]'
|
|
2314
|
+
},
|
|
2315
|
+
"nn/layernorm": {
|
|
2316
|
+
module: "nn",
|
|
2317
|
+
category: "std-nn",
|
|
2318
|
+
minArity: 1,
|
|
2319
|
+
maxArity: 1,
|
|
2320
|
+
description: "Layer normalization",
|
|
2321
|
+
hasSideEffects: false,
|
|
2322
|
+
returnType: "nn/layer",
|
|
2323
|
+
params: [
|
|
2324
|
+
{ name: "normalizedShape", type: "number | number[]", description: "Shape to normalize over" }
|
|
2325
|
+
],
|
|
2326
|
+
example: '["nn/layernorm", 64]'
|
|
2327
|
+
},
|
|
2328
|
+
"nn/forward": {
|
|
2329
|
+
module: "nn",
|
|
2330
|
+
category: "std-nn",
|
|
2331
|
+
minArity: 2,
|
|
2332
|
+
maxArity: 2,
|
|
2333
|
+
description: "Execute forward pass through network",
|
|
2334
|
+
hasSideEffects: false,
|
|
2335
|
+
returnType: "tensor",
|
|
2336
|
+
params: [
|
|
2337
|
+
{ name: "module", type: "nn/module", description: "The neural network module" },
|
|
2338
|
+
{ name: "input", type: "tensor", description: "Input tensor" }
|
|
2339
|
+
],
|
|
2340
|
+
example: '["nn/forward", "@entity.architecture", "@entity.sensors"]'
|
|
2341
|
+
},
|
|
2342
|
+
"nn/getWeights": {
|
|
2343
|
+
module: "nn",
|
|
2344
|
+
category: "std-nn",
|
|
2345
|
+
minArity: 1,
|
|
2346
|
+
maxArity: 1,
|
|
2347
|
+
description: "Get network weights as a flat tensor",
|
|
2348
|
+
hasSideEffects: false,
|
|
2349
|
+
returnType: "tensor",
|
|
2350
|
+
params: [
|
|
2351
|
+
{ name: "module", type: "nn/module", description: "The neural network module" }
|
|
2352
|
+
],
|
|
2353
|
+
example: '["nn/getWeights", "@entity.architecture"]'
|
|
2354
|
+
},
|
|
2355
|
+
"nn/setWeights": {
|
|
2356
|
+
module: "nn",
|
|
2357
|
+
category: "std-nn",
|
|
2358
|
+
minArity: 2,
|
|
2359
|
+
maxArity: 2,
|
|
2360
|
+
description: "Set network weights from a flat tensor",
|
|
2361
|
+
hasSideEffects: true,
|
|
2362
|
+
returnType: "nn/module",
|
|
2363
|
+
params: [
|
|
2364
|
+
{ name: "module", type: "nn/module", description: "The neural network module" },
|
|
2365
|
+
{ name: "weights", type: "tensor", description: "New weights as flat tensor" }
|
|
2366
|
+
],
|
|
2367
|
+
example: '["nn/setWeights", "@entity.architecture", "@payload.newWeights"]'
|
|
2368
|
+
},
|
|
2369
|
+
"nn/paramCount": {
|
|
2370
|
+
module: "nn",
|
|
2371
|
+
category: "std-nn",
|
|
2372
|
+
minArity: 1,
|
|
2373
|
+
maxArity: 1,
|
|
2374
|
+
description: "Get total number of trainable parameters",
|
|
2375
|
+
hasSideEffects: false,
|
|
2376
|
+
returnType: "number",
|
|
2377
|
+
params: [
|
|
2378
|
+
{ name: "module", type: "nn/module", description: "The neural network module" }
|
|
2379
|
+
],
|
|
2380
|
+
example: '["nn/paramCount", "@entity.architecture"] // => 3300'
|
|
2381
|
+
},
|
|
2382
|
+
"nn/clone": {
|
|
2383
|
+
module: "nn",
|
|
2384
|
+
category: "std-nn",
|
|
2385
|
+
minArity: 1,
|
|
2386
|
+
maxArity: 1,
|
|
2387
|
+
description: "Create a deep copy of the network with same weights",
|
|
2388
|
+
hasSideEffects: false,
|
|
2389
|
+
returnType: "nn/module",
|
|
2390
|
+
params: [
|
|
2391
|
+
{ name: "module", type: "nn/module", description: "The neural network module to clone" }
|
|
2392
|
+
],
|
|
2393
|
+
example: '["nn/clone", "@entity.architecture"]'
|
|
2394
|
+
}
|
|
2395
|
+
};
|
|
2396
|
+
function getNnOperators() {
|
|
2397
|
+
return Object.keys(NN_OPERATORS);
|
|
2398
|
+
}
|
|
2399
|
+
|
|
2400
|
+
// modules/tensor.ts
|
|
2401
|
+
var TENSOR_OPERATORS = {
|
|
2402
|
+
// ============================================================================
|
|
2403
|
+
// Creation
|
|
2404
|
+
// ============================================================================
|
|
2405
|
+
"tensor/from": {
|
|
2406
|
+
module: "tensor",
|
|
2407
|
+
category: "std-tensor",
|
|
2408
|
+
minArity: 1,
|
|
2409
|
+
maxArity: 1,
|
|
2410
|
+
description: "Create tensor from array",
|
|
2411
|
+
hasSideEffects: false,
|
|
2412
|
+
returnType: "tensor",
|
|
2413
|
+
params: [
|
|
2414
|
+
{ name: "data", type: "array", description: "Array of numbers (can be nested for multi-dimensional)" }
|
|
2415
|
+
],
|
|
2416
|
+
example: '["tensor/from", [1.0, 2.0, 3.0]]'
|
|
2417
|
+
},
|
|
2418
|
+
"tensor/zeros": {
|
|
2419
|
+
module: "tensor",
|
|
2420
|
+
category: "std-tensor",
|
|
2421
|
+
minArity: 1,
|
|
2422
|
+
maxArity: 1,
|
|
2423
|
+
description: "Create tensor filled with zeros",
|
|
2424
|
+
hasSideEffects: false,
|
|
2425
|
+
returnType: "tensor",
|
|
2426
|
+
params: [
|
|
2427
|
+
{ name: "shape", type: "number[]", description: "Shape of the tensor" }
|
|
2428
|
+
],
|
|
2429
|
+
example: '["tensor/zeros", [3, 4]] // 3x4 tensor of zeros'
|
|
2430
|
+
},
|
|
2431
|
+
"tensor/ones": {
|
|
2432
|
+
module: "tensor",
|
|
2433
|
+
category: "std-tensor",
|
|
2434
|
+
minArity: 1,
|
|
2435
|
+
maxArity: 1,
|
|
2436
|
+
description: "Create tensor filled with ones",
|
|
2437
|
+
hasSideEffects: false,
|
|
2438
|
+
returnType: "tensor",
|
|
2439
|
+
params: [
|
|
2440
|
+
{ name: "shape", type: "number[]", description: "Shape of the tensor" }
|
|
2441
|
+
],
|
|
2442
|
+
example: '["tensor/ones", [3, 4]] // 3x4 tensor of ones'
|
|
2443
|
+
},
|
|
2444
|
+
"tensor/rand": {
|
|
2445
|
+
module: "tensor",
|
|
2446
|
+
category: "std-tensor",
|
|
2447
|
+
minArity: 1,
|
|
2448
|
+
maxArity: 1,
|
|
2449
|
+
description: "Create tensor with random values in [0, 1)",
|
|
2450
|
+
hasSideEffects: false,
|
|
2451
|
+
returnType: "tensor",
|
|
2452
|
+
params: [
|
|
2453
|
+
{ name: "shape", type: "number[]", description: "Shape of the tensor" }
|
|
2454
|
+
],
|
|
2455
|
+
example: '["tensor/rand", [16]] // Random 16-element vector'
|
|
2456
|
+
},
|
|
2457
|
+
"tensor/randn": {
|
|
2458
|
+
module: "tensor",
|
|
2459
|
+
category: "std-tensor",
|
|
2460
|
+
minArity: 1,
|
|
2461
|
+
maxArity: 1,
|
|
2462
|
+
description: "Create tensor with random values from standard normal distribution",
|
|
2463
|
+
hasSideEffects: false,
|
|
2464
|
+
returnType: "tensor",
|
|
2465
|
+
params: [
|
|
2466
|
+
{ name: "shape", type: "number[]", description: "Shape of the tensor" }
|
|
2467
|
+
],
|
|
2468
|
+
example: '["tensor/randn", [16]] // Random normal 16-element vector'
|
|
2469
|
+
},
|
|
2470
|
+
// ============================================================================
|
|
2471
|
+
// Shape & Indexing
|
|
2472
|
+
// ============================================================================
|
|
2473
|
+
"tensor/shape": {
|
|
2474
|
+
module: "tensor",
|
|
2475
|
+
category: "std-tensor",
|
|
2476
|
+
minArity: 1,
|
|
2477
|
+
maxArity: 1,
|
|
2478
|
+
description: "Get tensor shape as array",
|
|
2479
|
+
hasSideEffects: false,
|
|
2480
|
+
returnType: "number[]",
|
|
2481
|
+
params: [
|
|
2482
|
+
{ name: "tensor", type: "tensor", description: "The tensor" }
|
|
2483
|
+
],
|
|
2484
|
+
example: '["tensor/shape", "@entity.sensors"] // => [16]'
|
|
2485
|
+
},
|
|
2486
|
+
"tensor/get": {
|
|
2487
|
+
module: "tensor",
|
|
2488
|
+
category: "std-tensor",
|
|
2489
|
+
minArity: 2,
|
|
2490
|
+
maxArity: 2,
|
|
2491
|
+
description: "Get element at index",
|
|
2492
|
+
hasSideEffects: false,
|
|
2493
|
+
returnType: "number",
|
|
2494
|
+
params: [
|
|
2495
|
+
{ name: "tensor", type: "tensor", description: "The tensor" },
|
|
2496
|
+
{ name: "index", type: "number | number[]", description: "Index (single for 1D, array for multi-D)" }
|
|
2497
|
+
],
|
|
2498
|
+
example: '["tensor/get", "@entity.output", 3] // Get 4th element'
|
|
2499
|
+
},
|
|
2500
|
+
"tensor/slice": {
|
|
2501
|
+
module: "tensor",
|
|
2502
|
+
category: "std-tensor",
|
|
2503
|
+
minArity: 3,
|
|
2504
|
+
maxArity: 3,
|
|
2505
|
+
description: "Get slice of tensor",
|
|
2506
|
+
hasSideEffects: false,
|
|
2507
|
+
returnType: "tensor",
|
|
2508
|
+
params: [
|
|
2509
|
+
{ name: "tensor", type: "tensor", description: "The tensor" },
|
|
2510
|
+
{ name: "start", type: "number", description: "Start index" },
|
|
2511
|
+
{ name: "end", type: "number", description: "End index (exclusive)" }
|
|
2512
|
+
],
|
|
2513
|
+
example: '["tensor/slice", "@entity.output", 0, 3] // First 3 elements'
|
|
2514
|
+
},
|
|
2515
|
+
"tensor/reshape": {
|
|
2516
|
+
module: "tensor",
|
|
2517
|
+
category: "std-tensor",
|
|
2518
|
+
minArity: 2,
|
|
2519
|
+
maxArity: 2,
|
|
2520
|
+
description: "Reshape tensor to new shape (total elements must match)",
|
|
2521
|
+
hasSideEffects: false,
|
|
2522
|
+
returnType: "tensor",
|
|
2523
|
+
params: [
|
|
2524
|
+
{ name: "tensor", type: "tensor", description: "The tensor" },
|
|
2525
|
+
{ name: "shape", type: "number[]", description: "New shape" }
|
|
2526
|
+
],
|
|
2527
|
+
example: '["tensor/reshape", "@entity.data", [4, 4]] // Reshape to 4x4'
|
|
2528
|
+
},
|
|
2529
|
+
"tensor/flatten": {
|
|
2530
|
+
module: "tensor",
|
|
2531
|
+
category: "std-tensor",
|
|
2532
|
+
minArity: 1,
|
|
2533
|
+
maxArity: 1,
|
|
2534
|
+
description: "Flatten tensor to 1D",
|
|
2535
|
+
hasSideEffects: false,
|
|
2536
|
+
returnType: "tensor",
|
|
2537
|
+
params: [
|
|
2538
|
+
{ name: "tensor", type: "tensor", description: "The tensor" }
|
|
2539
|
+
],
|
|
2540
|
+
example: '["tensor/flatten", "@entity.data"]'
|
|
2541
|
+
},
|
|
2542
|
+
// ============================================================================
|
|
2543
|
+
// Math Operations
|
|
2544
|
+
// ============================================================================
|
|
2545
|
+
"tensor/add": {
|
|
2546
|
+
module: "tensor",
|
|
2547
|
+
category: "std-tensor",
|
|
2548
|
+
minArity: 2,
|
|
2549
|
+
maxArity: 2,
|
|
2550
|
+
description: "Element-wise addition",
|
|
2551
|
+
hasSideEffects: false,
|
|
2552
|
+
returnType: "tensor",
|
|
2553
|
+
params: [
|
|
2554
|
+
{ name: "a", type: "tensor", description: "First tensor" },
|
|
2555
|
+
{ name: "b", type: "tensor | number", description: "Second tensor or scalar" }
|
|
2556
|
+
],
|
|
2557
|
+
example: '["tensor/add", "@entity.a", "@entity.b"]'
|
|
2558
|
+
},
|
|
2559
|
+
"tensor/sub": {
|
|
2560
|
+
module: "tensor",
|
|
2561
|
+
category: "std-tensor",
|
|
2562
|
+
minArity: 2,
|
|
2563
|
+
maxArity: 2,
|
|
2564
|
+
description: "Element-wise subtraction",
|
|
2565
|
+
hasSideEffects: false,
|
|
2566
|
+
returnType: "tensor",
|
|
2567
|
+
params: [
|
|
2568
|
+
{ name: "a", type: "tensor", description: "First tensor" },
|
|
2569
|
+
{ name: "b", type: "tensor | number", description: "Second tensor or scalar" }
|
|
2570
|
+
],
|
|
2571
|
+
example: '["tensor/sub", "@entity.a", "@entity.b"]'
|
|
2572
|
+
},
|
|
2573
|
+
"tensor/mul": {
|
|
2574
|
+
module: "tensor",
|
|
2575
|
+
category: "std-tensor",
|
|
2576
|
+
minArity: 2,
|
|
2577
|
+
maxArity: 2,
|
|
2578
|
+
description: "Element-wise multiplication",
|
|
2579
|
+
hasSideEffects: false,
|
|
2580
|
+
returnType: "tensor",
|
|
2581
|
+
params: [
|
|
2582
|
+
{ name: "a", type: "tensor", description: "First tensor" },
|
|
2583
|
+
{ name: "b", type: "tensor | number", description: "Second tensor or scalar" }
|
|
2584
|
+
],
|
|
2585
|
+
example: '["tensor/mul", "@entity.weights", 0.99] // Decay weights'
|
|
2586
|
+
},
|
|
2587
|
+
"tensor/div": {
|
|
2588
|
+
module: "tensor",
|
|
2589
|
+
category: "std-tensor",
|
|
2590
|
+
minArity: 2,
|
|
2591
|
+
maxArity: 2,
|
|
2592
|
+
description: "Element-wise division",
|
|
2593
|
+
hasSideEffects: false,
|
|
2594
|
+
returnType: "tensor",
|
|
2595
|
+
params: [
|
|
2596
|
+
{ name: "a", type: "tensor", description: "First tensor" },
|
|
2597
|
+
{ name: "b", type: "tensor | number", description: "Second tensor or scalar" }
|
|
2598
|
+
],
|
|
2599
|
+
example: '["tensor/div", "@entity.gradient", "@entity.batchSize"]'
|
|
2600
|
+
},
|
|
2601
|
+
"tensor/matmul": {
|
|
2602
|
+
module: "tensor",
|
|
2603
|
+
category: "std-tensor",
|
|
2604
|
+
minArity: 2,
|
|
2605
|
+
maxArity: 2,
|
|
2606
|
+
description: "Matrix multiplication",
|
|
2607
|
+
hasSideEffects: false,
|
|
2608
|
+
returnType: "tensor",
|
|
2609
|
+
params: [
|
|
2610
|
+
{ name: "a", type: "tensor", description: "First tensor (NxM)" },
|
|
2611
|
+
{ name: "b", type: "tensor", description: "Second tensor (MxK)" }
|
|
2612
|
+
],
|
|
2613
|
+
example: '["tensor/matmul", "@entity.input", "@entity.weights"]'
|
|
2614
|
+
},
|
|
2615
|
+
"tensor/dot": {
|
|
2616
|
+
module: "tensor",
|
|
2617
|
+
category: "std-tensor",
|
|
2618
|
+
minArity: 2,
|
|
2619
|
+
maxArity: 2,
|
|
2620
|
+
description: "Dot product of two 1D tensors",
|
|
2621
|
+
hasSideEffects: false,
|
|
2622
|
+
returnType: "number",
|
|
2623
|
+
params: [
|
|
2624
|
+
{ name: "a", type: "tensor", description: "First vector" },
|
|
2625
|
+
{ name: "b", type: "tensor", description: "Second vector" }
|
|
2626
|
+
],
|
|
2627
|
+
example: '["tensor/dot", "@entity.a", "@entity.b"]'
|
|
2628
|
+
},
|
|
2629
|
+
// ============================================================================
|
|
2630
|
+
// Reductions
|
|
2631
|
+
// ============================================================================
|
|
2632
|
+
"tensor/sum": {
|
|
2633
|
+
module: "tensor",
|
|
2634
|
+
category: "std-tensor",
|
|
2635
|
+
minArity: 1,
|
|
2636
|
+
maxArity: 2,
|
|
2637
|
+
description: "Sum of tensor elements",
|
|
2638
|
+
hasSideEffects: false,
|
|
2639
|
+
returnType: "number | tensor",
|
|
2640
|
+
params: [
|
|
2641
|
+
{ name: "tensor", type: "tensor", description: "The tensor" },
|
|
2642
|
+
{ name: "dim", type: "number", description: "Dimension to reduce", optional: true }
|
|
2643
|
+
],
|
|
2644
|
+
example: '["tensor/sum", "@entity.rewards"] // Total reward'
|
|
2645
|
+
},
|
|
2646
|
+
"tensor/mean": {
|
|
2647
|
+
module: "tensor",
|
|
2648
|
+
category: "std-tensor",
|
|
2649
|
+
minArity: 1,
|
|
2650
|
+
maxArity: 2,
|
|
2651
|
+
description: "Mean of tensor elements",
|
|
2652
|
+
hasSideEffects: false,
|
|
2653
|
+
returnType: "number | tensor",
|
|
2654
|
+
params: [
|
|
2655
|
+
{ name: "tensor", type: "tensor", description: "The tensor" },
|
|
2656
|
+
{ name: "dim", type: "number", description: "Dimension to reduce", optional: true }
|
|
2657
|
+
],
|
|
2658
|
+
example: '["tensor/mean", "@entity.losses"]'
|
|
2659
|
+
},
|
|
2660
|
+
"tensor/max": {
|
|
2661
|
+
module: "tensor",
|
|
2662
|
+
category: "std-tensor",
|
|
2663
|
+
minArity: 1,
|
|
2664
|
+
maxArity: 2,
|
|
2665
|
+
description: "Maximum value in tensor",
|
|
2666
|
+
hasSideEffects: false,
|
|
2667
|
+
returnType: "number | tensor",
|
|
2668
|
+
params: [
|
|
2669
|
+
{ name: "tensor", type: "tensor", description: "The tensor" },
|
|
2670
|
+
{ name: "dim", type: "number", description: "Dimension to reduce", optional: true }
|
|
2671
|
+
],
|
|
2672
|
+
example: '["tensor/max", "@entity.qValues"]'
|
|
2673
|
+
},
|
|
2674
|
+
"tensor/min": {
|
|
2675
|
+
module: "tensor",
|
|
2676
|
+
category: "std-tensor",
|
|
2677
|
+
minArity: 1,
|
|
2678
|
+
maxArity: 2,
|
|
2679
|
+
description: "Minimum value in tensor",
|
|
2680
|
+
hasSideEffects: false,
|
|
2681
|
+
returnType: "number | tensor",
|
|
2682
|
+
params: [
|
|
2683
|
+
{ name: "tensor", type: "tensor", description: "The tensor" },
|
|
2684
|
+
{ name: "dim", type: "number", description: "Dimension to reduce", optional: true }
|
|
2685
|
+
],
|
|
2686
|
+
example: '["tensor/min", "@entity.distances"]'
|
|
2687
|
+
},
|
|
2688
|
+
"tensor/argmax": {
|
|
2689
|
+
module: "tensor",
|
|
2690
|
+
category: "std-tensor",
|
|
2691
|
+
minArity: 1,
|
|
2692
|
+
maxArity: 2,
|
|
2693
|
+
description: "Index of maximum value",
|
|
2694
|
+
hasSideEffects: false,
|
|
2695
|
+
returnType: "number | tensor",
|
|
2696
|
+
params: [
|
|
2697
|
+
{ name: "tensor", type: "tensor", description: "The tensor" },
|
|
2698
|
+
{ name: "dim", type: "number", description: "Dimension to reduce", optional: true }
|
|
2699
|
+
],
|
|
2700
|
+
example: '["tensor/argmax", "@entity.qValues"] // Best action index'
|
|
2701
|
+
},
|
|
2702
|
+
"tensor/norm": {
|
|
2703
|
+
module: "tensor",
|
|
2704
|
+
category: "std-tensor",
|
|
2705
|
+
minArity: 1,
|
|
2706
|
+
maxArity: 2,
|
|
2707
|
+
description: "L2 norm of tensor",
|
|
2708
|
+
hasSideEffects: false,
|
|
2709
|
+
returnType: "number",
|
|
2710
|
+
params: [
|
|
2711
|
+
{ name: "tensor", type: "tensor", description: "The tensor" },
|
|
2712
|
+
{ name: "p", type: "number", description: "Norm order (default 2)", optional: true, defaultValue: 2 }
|
|
2713
|
+
],
|
|
2714
|
+
example: '["tensor/norm", "@entity.gradient"]'
|
|
2715
|
+
},
|
|
2716
|
+
// ============================================================================
|
|
2717
|
+
// Range Validation (for contracts)
|
|
2718
|
+
// ============================================================================
|
|
2719
|
+
"tensor/allInRange": {
|
|
2720
|
+
module: "tensor",
|
|
2721
|
+
category: "std-tensor",
|
|
2722
|
+
minArity: 2,
|
|
2723
|
+
maxArity: 2,
|
|
2724
|
+
description: "Check if all elements are within range [min, max]",
|
|
2725
|
+
hasSideEffects: false,
|
|
2726
|
+
returnType: "boolean",
|
|
2727
|
+
params: [
|
|
2728
|
+
{ name: "tensor", type: "tensor", description: "The tensor" },
|
|
2729
|
+
{ name: "range", type: "[number, number]", description: "Range as [min, max]" }
|
|
2730
|
+
],
|
|
2731
|
+
example: '["tensor/allInRange", "@payload.input", [-1.0, 1.0]]'
|
|
2732
|
+
},
|
|
2733
|
+
"tensor/outOfRangeIndices": {
|
|
2734
|
+
module: "tensor",
|
|
2735
|
+
category: "std-tensor",
|
|
2736
|
+
minArity: 2,
|
|
2737
|
+
maxArity: 2,
|
|
2738
|
+
description: "Get indices of elements outside range",
|
|
2739
|
+
hasSideEffects: false,
|
|
2740
|
+
returnType: "number[]",
|
|
2741
|
+
params: [
|
|
2742
|
+
{ name: "tensor", type: "tensor", description: "The tensor" },
|
|
2743
|
+
{ name: "range", type: "[number, number]", description: "Range as [min, max]" }
|
|
2744
|
+
],
|
|
2745
|
+
example: '["tensor/outOfRangeIndices", "@payload.input", [-1.0, 1.0]]'
|
|
2746
|
+
},
|
|
2747
|
+
"tensor/clamp": {
|
|
2748
|
+
module: "tensor",
|
|
2749
|
+
category: "std-tensor",
|
|
2750
|
+
minArity: 3,
|
|
2751
|
+
maxArity: 3,
|
|
2752
|
+
description: "Clamp all elements to range [min, max]",
|
|
2753
|
+
hasSideEffects: false,
|
|
2754
|
+
returnType: "tensor",
|
|
2755
|
+
params: [
|
|
2756
|
+
{ name: "tensor", type: "tensor", description: "The tensor" },
|
|
2757
|
+
{ name: "min", type: "number", description: "Minimum value" },
|
|
2758
|
+
{ name: "max", type: "number", description: "Maximum value" }
|
|
2759
|
+
],
|
|
2760
|
+
example: '["tensor/clamp", "@entity.output", -10.0, 10.0]'
|
|
2761
|
+
},
|
|
2762
|
+
"tensor/clampPerDim": {
|
|
2763
|
+
module: "tensor",
|
|
2764
|
+
category: "std-tensor",
|
|
2765
|
+
minArity: 2,
|
|
2766
|
+
maxArity: 2,
|
|
2767
|
+
description: "Clamp each dimension to its specified range",
|
|
2768
|
+
hasSideEffects: false,
|
|
2769
|
+
returnType: "tensor",
|
|
2770
|
+
params: [
|
|
2771
|
+
{ name: "tensor", type: "tensor", description: "The tensor" },
|
|
2772
|
+
{ name: "ranges", type: "object", description: 'Per-dimension ranges { "0": {min, max}, ... }' }
|
|
2773
|
+
],
|
|
2774
|
+
example: '["tensor/clampPerDim", "@entity.rawOutput", "@entity.outputContract.ranges"]'
|
|
2775
|
+
},
|
|
2776
|
+
"tensor/outOfRangeDims": {
|
|
2777
|
+
module: "tensor",
|
|
2778
|
+
category: "std-tensor",
|
|
2779
|
+
minArity: 2,
|
|
2780
|
+
maxArity: 2,
|
|
2781
|
+
description: "Get dimensions that exceed their specified ranges",
|
|
2782
|
+
hasSideEffects: false,
|
|
2783
|
+
returnType: "array",
|
|
2784
|
+
params: [
|
|
2785
|
+
{ name: "tensor", type: "tensor", description: "The tensor" },
|
|
2786
|
+
{ name: "ranges", type: "object", description: 'Per-dimension ranges { "0": {min, max}, ... }' }
|
|
2787
|
+
],
|
|
2788
|
+
example: '["tensor/outOfRangeDims", "@entity.rawOutput", "@entity.outputContract.ranges"]'
|
|
2789
|
+
},
|
|
2790
|
+
// ============================================================================
|
|
2791
|
+
// Conversion
|
|
2792
|
+
// ============================================================================
|
|
2793
|
+
"tensor/toArray": {
|
|
2794
|
+
module: "tensor",
|
|
2795
|
+
category: "std-tensor",
|
|
2796
|
+
minArity: 1,
|
|
2797
|
+
maxArity: 1,
|
|
2798
|
+
description: "Convert tensor to nested array",
|
|
2799
|
+
hasSideEffects: false,
|
|
2800
|
+
returnType: "array",
|
|
2801
|
+
params: [
|
|
2802
|
+
{ name: "tensor", type: "tensor", description: "The tensor" }
|
|
2803
|
+
],
|
|
2804
|
+
example: '["tensor/toArray", "@entity.output"]'
|
|
2805
|
+
},
|
|
2806
|
+
"tensor/toList": {
|
|
2807
|
+
module: "tensor",
|
|
2808
|
+
category: "std-tensor",
|
|
2809
|
+
minArity: 1,
|
|
2810
|
+
maxArity: 1,
|
|
2811
|
+
description: "Convert 1D tensor to flat array",
|
|
2812
|
+
hasSideEffects: false,
|
|
2813
|
+
returnType: "number[]",
|
|
2814
|
+
params: [
|
|
2815
|
+
{ name: "tensor", type: "tensor", description: "The tensor (must be 1D)" }
|
|
2816
|
+
],
|
|
2817
|
+
example: '["tensor/toList", "@entity.output"]'
|
|
2818
|
+
}
|
|
2819
|
+
};
|
|
2820
|
+
function getTensorOperators() {
|
|
2821
|
+
return Object.keys(TENSOR_OPERATORS);
|
|
2822
|
+
}
|
|
2823
|
+
|
|
2824
|
+
// modules/train.ts
|
|
2825
|
+
var TRAIN_OPERATORS = {
|
|
2826
|
+
// ============================================================================
|
|
2827
|
+
// Training Loop
|
|
2828
|
+
// ============================================================================
|
|
2829
|
+
"train/loop": {
|
|
2830
|
+
module: "train",
|
|
2831
|
+
category: "std-train",
|
|
2832
|
+
minArity: 3,
|
|
2833
|
+
maxArity: 3,
|
|
2834
|
+
description: "Execute training loop with constraints",
|
|
2835
|
+
hasSideEffects: true,
|
|
2836
|
+
returnType: "train/result",
|
|
2837
|
+
params: [
|
|
2838
|
+
{ name: "module", type: "nn/module", description: "The neural network to train" },
|
|
2839
|
+
{ name: "data", type: "array", description: "Training data (array of {input, target} or experiences)" },
|
|
2840
|
+
{ name: "config", type: "train/config", description: "Training configuration with constraints" }
|
|
2841
|
+
],
|
|
2842
|
+
example: '["train/loop", "@entity.architecture", "@entity.buffer", "@entity.trainingConfig"]'
|
|
2843
|
+
},
|
|
2844
|
+
"train/step": {
|
|
2845
|
+
module: "train",
|
|
2846
|
+
category: "std-train",
|
|
2847
|
+
minArity: 4,
|
|
2848
|
+
maxArity: 4,
|
|
2849
|
+
description: "Execute single training step (forward, loss, backward, update)",
|
|
2850
|
+
hasSideEffects: true,
|
|
2851
|
+
returnType: "train/stepResult",
|
|
2852
|
+
params: [
|
|
2853
|
+
{ name: "module", type: "nn/module", description: "The neural network" },
|
|
2854
|
+
{ name: "input", type: "tensor", description: "Input tensor" },
|
|
2855
|
+
{ name: "target", type: "tensor", description: "Target tensor" },
|
|
2856
|
+
{ name: "config", type: "train/config", description: "Training configuration" }
|
|
2857
|
+
],
|
|
2858
|
+
example: '["train/step", "@entity.architecture", "@batch.input", "@batch.target", "@entity.config"]'
|
|
2859
|
+
},
|
|
2860
|
+
// ============================================================================
|
|
2861
|
+
// Validation
|
|
2862
|
+
// ============================================================================
|
|
2863
|
+
"train/validate": {
|
|
2864
|
+
module: "train",
|
|
2865
|
+
category: "std-train",
|
|
2866
|
+
minArity: 2,
|
|
2867
|
+
maxArity: 2,
|
|
2868
|
+
description: "Validate model on test cases, returns pass/fail metrics",
|
|
2869
|
+
hasSideEffects: false,
|
|
2870
|
+
returnType: "train/validationResult",
|
|
2871
|
+
params: [
|
|
2872
|
+
{ name: "module", type: "nn/module", description: "The neural network" },
|
|
2873
|
+
{ name: "testCases", type: "array", description: "Array of {input, expected, tolerance?}" }
|
|
2874
|
+
],
|
|
2875
|
+
example: '["train/validate", "@entity.architecture", "@entity.validationSet"]'
|
|
2876
|
+
},
|
|
2877
|
+
"train/checkRegression": {
|
|
2878
|
+
module: "train",
|
|
2879
|
+
category: "std-train",
|
|
2880
|
+
minArity: 3,
|
|
2881
|
+
maxArity: 3,
|
|
2882
|
+
description: "Check if new model regresses on required invariants",
|
|
2883
|
+
hasSideEffects: false,
|
|
2884
|
+
returnType: "train/regressionResult",
|
|
2885
|
+
params: [
|
|
2886
|
+
{ name: "newModule", type: "nn/module", description: "Newly trained network" },
|
|
2887
|
+
{ name: "oldModule", type: "nn/module", description: "Previous network" },
|
|
2888
|
+
{ name: "invariants", type: "array", description: "Test cases that must not regress" }
|
|
2889
|
+
],
|
|
2890
|
+
example: '["train/checkRegression", "@payload.newWeights", "@entity.architecture", "@entity.requiredInvariants"]'
|
|
2891
|
+
},
|
|
2892
|
+
// ============================================================================
|
|
2893
|
+
// Constraint Checking
|
|
2894
|
+
// ============================================================================
|
|
2895
|
+
"train/checkConstraints": {
|
|
2896
|
+
module: "train",
|
|
2897
|
+
category: "std-train",
|
|
2898
|
+
minArity: 2,
|
|
2899
|
+
maxArity: 2,
|
|
2900
|
+
description: "Check if network weights satisfy all constraints",
|
|
2901
|
+
hasSideEffects: false,
|
|
2902
|
+
returnType: "train/constraintResult",
|
|
2903
|
+
params: [
|
|
2904
|
+
{ name: "module", type: "nn/module", description: "The neural network" },
|
|
2905
|
+
{ name: "constraints", type: "train/constraints", description: "Constraint specification" }
|
|
2906
|
+
],
|
|
2907
|
+
example: '["train/checkConstraints", "@payload.newWeights", "@entity.constraints"]'
|
|
2908
|
+
},
|
|
2909
|
+
"train/checkWeightMagnitude": {
|
|
2910
|
+
module: "train",
|
|
2911
|
+
category: "std-train",
|
|
2912
|
+
minArity: 2,
|
|
2913
|
+
maxArity: 2,
|
|
2914
|
+
description: "Check if all weights are within magnitude limit",
|
|
2915
|
+
hasSideEffects: false,
|
|
2916
|
+
returnType: "boolean",
|
|
2917
|
+
params: [
|
|
2918
|
+
{ name: "module", type: "nn/module", description: "The neural network" },
|
|
2919
|
+
{ name: "maxMagnitude", type: "number", description: "Maximum allowed weight magnitude" }
|
|
2920
|
+
],
|
|
2921
|
+
example: '["train/checkWeightMagnitude", "@entity.architecture", 10.0]'
|
|
2922
|
+
},
|
|
2923
|
+
"train/checkForbiddenOutputs": {
|
|
2924
|
+
module: "train",
|
|
2925
|
+
category: "std-train",
|
|
2926
|
+
minArity: 3,
|
|
2927
|
+
maxArity: 3,
|
|
2928
|
+
description: "Check if model produces outputs in forbidden regions",
|
|
2929
|
+
hasSideEffects: false,
|
|
2930
|
+
returnType: "train/forbiddenResult",
|
|
2931
|
+
params: [
|
|
2932
|
+
{ name: "module", type: "nn/module", description: "The neural network" },
|
|
2933
|
+
{ name: "testInputs", type: "array", description: "Inputs to test" },
|
|
2934
|
+
{ name: "forbiddenRegions", type: "array", description: "Forbidden output regions" }
|
|
2935
|
+
],
|
|
2936
|
+
example: '["train/checkForbiddenOutputs", "@entity.architecture", "@entity.testInputs", "@entity.forbiddenOutputRegions"]'
|
|
2937
|
+
},
|
|
2938
|
+
// ============================================================================
|
|
2939
|
+
// Gradient Operations
|
|
2940
|
+
// ============================================================================
|
|
2941
|
+
"train/clipGradients": {
|
|
2942
|
+
module: "train",
|
|
2943
|
+
category: "std-train",
|
|
2944
|
+
minArity: 2,
|
|
2945
|
+
maxArity: 2,
|
|
2946
|
+
description: "Clip gradients to max norm (modifies in place)",
|
|
2947
|
+
hasSideEffects: true,
|
|
2948
|
+
returnType: "number",
|
|
2949
|
+
params: [
|
|
2950
|
+
{ name: "module", type: "nn/module", description: "The neural network" },
|
|
2951
|
+
{ name: "maxNorm", type: "number", description: "Maximum gradient norm" }
|
|
2952
|
+
],
|
|
2953
|
+
example: '["train/clipGradients", "@entity.architecture", 1.0]'
|
|
2954
|
+
},
|
|
2955
|
+
"train/getGradientNorm": {
|
|
2956
|
+
module: "train",
|
|
2957
|
+
category: "std-train",
|
|
2958
|
+
minArity: 1,
|
|
2959
|
+
maxArity: 1,
|
|
2960
|
+
description: "Get current gradient norm",
|
|
2961
|
+
hasSideEffects: false,
|
|
2962
|
+
returnType: "number",
|
|
2963
|
+
params: [
|
|
2964
|
+
{ name: "module", type: "nn/module", description: "The neural network" }
|
|
2965
|
+
],
|
|
2966
|
+
example: '["train/getGradientNorm", "@entity.architecture"]'
|
|
2967
|
+
},
|
|
2968
|
+
// ============================================================================
|
|
2969
|
+
// Weight Operations
|
|
2970
|
+
// ============================================================================
|
|
2971
|
+
"train/clipWeights": {
|
|
2972
|
+
module: "train",
|
|
2973
|
+
category: "std-train",
|
|
2974
|
+
minArity: 2,
|
|
2975
|
+
maxArity: 2,
|
|
2976
|
+
description: "Clip weights to max magnitude (modifies in place)",
|
|
2977
|
+
hasSideEffects: true,
|
|
2978
|
+
returnType: "void",
|
|
2979
|
+
params: [
|
|
2980
|
+
{ name: "module", type: "nn/module", description: "The neural network" },
|
|
2981
|
+
{ name: "maxMagnitude", type: "number", description: "Maximum weight magnitude" }
|
|
2982
|
+
],
|
|
2983
|
+
example: '["train/clipWeights", "@entity.architecture", 10.0]'
|
|
2984
|
+
},
|
|
2985
|
+
"train/getMaxWeightMagnitude": {
|
|
2986
|
+
module: "train",
|
|
2987
|
+
category: "std-train",
|
|
2988
|
+
minArity: 1,
|
|
2989
|
+
maxArity: 1,
|
|
2990
|
+
description: "Get maximum weight magnitude in network",
|
|
2991
|
+
hasSideEffects: false,
|
|
2992
|
+
returnType: "number",
|
|
2993
|
+
params: [
|
|
2994
|
+
{ name: "module", type: "nn/module", description: "The neural network" }
|
|
2995
|
+
],
|
|
2996
|
+
example: '["train/getMaxWeightMagnitude", "@entity.architecture"]'
|
|
2997
|
+
},
|
|
2998
|
+
// ============================================================================
|
|
2999
|
+
// Loss Functions
|
|
3000
|
+
// ============================================================================
|
|
3001
|
+
"train/mse": {
|
|
3002
|
+
module: "train",
|
|
3003
|
+
category: "std-train",
|
|
3004
|
+
minArity: 2,
|
|
3005
|
+
maxArity: 2,
|
|
3006
|
+
description: "Mean squared error loss",
|
|
3007
|
+
hasSideEffects: false,
|
|
3008
|
+
returnType: "number",
|
|
3009
|
+
params: [
|
|
3010
|
+
{ name: "predicted", type: "tensor", description: "Predicted values" },
|
|
3011
|
+
{ name: "target", type: "tensor", description: "Target values" }
|
|
3012
|
+
],
|
|
3013
|
+
example: '["train/mse", "@entity.output", "@batch.target"]'
|
|
3014
|
+
},
|
|
3015
|
+
"train/crossEntropy": {
|
|
3016
|
+
module: "train",
|
|
3017
|
+
category: "std-train",
|
|
3018
|
+
minArity: 2,
|
|
3019
|
+
maxArity: 2,
|
|
3020
|
+
description: "Cross-entropy loss for classification",
|
|
3021
|
+
hasSideEffects: false,
|
|
3022
|
+
returnType: "number",
|
|
3023
|
+
params: [
|
|
3024
|
+
{ name: "logits", type: "tensor", description: "Raw model outputs (logits)" },
|
|
3025
|
+
{ name: "labels", type: "tensor", description: "Target class labels" }
|
|
3026
|
+
],
|
|
3027
|
+
example: '["train/crossEntropy", "@entity.logits", "@batch.labels"]'
|
|
3028
|
+
},
|
|
3029
|
+
"train/huber": {
|
|
3030
|
+
module: "train",
|
|
3031
|
+
category: "std-train",
|
|
3032
|
+
minArity: 2,
|
|
3033
|
+
maxArity: 3,
|
|
3034
|
+
description: "Huber loss (smooth L1, robust to outliers)",
|
|
3035
|
+
hasSideEffects: false,
|
|
3036
|
+
returnType: "number",
|
|
3037
|
+
params: [
|
|
3038
|
+
{ name: "predicted", type: "tensor", description: "Predicted values" },
|
|
3039
|
+
{ name: "target", type: "tensor", description: "Target values" },
|
|
3040
|
+
{ name: "delta", type: "number", description: "Threshold for quadratic vs linear", optional: true, defaultValue: 1 }
|
|
3041
|
+
],
|
|
3042
|
+
example: '["train/huber", "@entity.qValues", "@batch.targets", 1.0]'
|
|
3043
|
+
},
|
|
3044
|
+
// ============================================================================
|
|
3045
|
+
// Optimizers
|
|
3046
|
+
// ============================================================================
|
|
3047
|
+
"train/sgd": {
|
|
3048
|
+
module: "train",
|
|
3049
|
+
category: "std-train",
|
|
3050
|
+
minArity: 2,
|
|
3051
|
+
maxArity: 3,
|
|
3052
|
+
description: "Stochastic gradient descent optimizer step",
|
|
3053
|
+
hasSideEffects: true,
|
|
3054
|
+
returnType: "void",
|
|
3055
|
+
params: [
|
|
3056
|
+
{ name: "module", type: "nn/module", description: "The neural network" },
|
|
3057
|
+
{ name: "lr", type: "number", description: "Learning rate" },
|
|
3058
|
+
{ name: "momentum", type: "number", description: "Momentum factor", optional: true, defaultValue: 0 }
|
|
3059
|
+
],
|
|
3060
|
+
example: '["train/sgd", "@entity.architecture", 0.01, 0.9]'
|
|
3061
|
+
},
|
|
3062
|
+
"train/adam": {
|
|
3063
|
+
module: "train",
|
|
3064
|
+
category: "std-train",
|
|
3065
|
+
minArity: 2,
|
|
3066
|
+
maxArity: 4,
|
|
3067
|
+
description: "Adam optimizer step",
|
|
3068
|
+
hasSideEffects: true,
|
|
3069
|
+
returnType: "void",
|
|
3070
|
+
params: [
|
|
3071
|
+
{ name: "module", type: "nn/module", description: "The neural network" },
|
|
3072
|
+
{ name: "lr", type: "number", description: "Learning rate" },
|
|
3073
|
+
{ name: "beta1", type: "number", description: "First moment decay", optional: true, defaultValue: 0.9 },
|
|
3074
|
+
{ name: "beta2", type: "number", description: "Second moment decay", optional: true, defaultValue: 0.999 }
|
|
3075
|
+
],
|
|
3076
|
+
example: '["train/adam", "@entity.architecture", 0.001]'
|
|
3077
|
+
},
|
|
3078
|
+
// ============================================================================
|
|
3079
|
+
// Experience Replay (for RL)
|
|
3080
|
+
// ============================================================================
|
|
3081
|
+
"train/sampleBatch": {
|
|
3082
|
+
module: "train",
|
|
3083
|
+
category: "std-train",
|
|
3084
|
+
minArity: 2,
|
|
3085
|
+
maxArity: 2,
|
|
3086
|
+
description: "Sample random batch from experience buffer",
|
|
3087
|
+
hasSideEffects: false,
|
|
3088
|
+
returnType: "array",
|
|
3089
|
+
params: [
|
|
3090
|
+
{ name: "buffer", type: "array", description: "Experience buffer" },
|
|
3091
|
+
{ name: "batchSize", type: "number", description: "Number of samples" }
|
|
3092
|
+
],
|
|
3093
|
+
example: '["train/sampleBatch", "@entity.experienceBuffer", 32]'
|
|
3094
|
+
},
|
|
3095
|
+
"train/computeReturns": {
|
|
3096
|
+
module: "train",
|
|
3097
|
+
category: "std-train",
|
|
3098
|
+
minArity: 2,
|
|
3099
|
+
maxArity: 2,
|
|
3100
|
+
description: "Compute discounted returns from rewards",
|
|
3101
|
+
hasSideEffects: false,
|
|
3102
|
+
returnType: "tensor",
|
|
3103
|
+
params: [
|
|
3104
|
+
{ name: "rewards", type: "array", description: "Array of rewards" },
|
|
3105
|
+
{ name: "gamma", type: "number", description: "Discount factor" }
|
|
3106
|
+
],
|
|
3107
|
+
example: '["train/computeReturns", "@episode.rewards", 0.99]'
|
|
3108
|
+
},
|
|
3109
|
+
"train/computeAdvantages": {
|
|
3110
|
+
module: "train",
|
|
3111
|
+
category: "std-train",
|
|
3112
|
+
minArity: 3,
|
|
3113
|
+
maxArity: 3,
|
|
3114
|
+
description: "Compute GAE advantages for policy gradient",
|
|
3115
|
+
hasSideEffects: false,
|
|
3116
|
+
returnType: "tensor",
|
|
3117
|
+
params: [
|
|
3118
|
+
{ name: "rewards", type: "array", description: "Array of rewards" },
|
|
3119
|
+
{ name: "values", type: "tensor", description: "Value estimates" },
|
|
3120
|
+
{ name: "config", type: "object", description: "Config with gamma, lambda" }
|
|
3121
|
+
],
|
|
3122
|
+
example: '["train/computeAdvantages", "@episode.rewards", "@episode.values", { "gamma": 0.99, "lambda": 0.95 }]'
|
|
3123
|
+
}
|
|
3124
|
+
};
|
|
3125
|
+
function getTrainOperators() {
|
|
3126
|
+
return Object.keys(TRAIN_OPERATORS);
|
|
3127
|
+
}
|
|
3128
|
+
|
|
3129
|
+
export { ARRAY_OPERATORS, ASYNC_OPERATORS, FORMAT_OPERATORS, MATH_OPERATORS, NN_OPERATORS, OBJECT_OPERATORS, STR_OPERATORS, TENSOR_OPERATORS, TIME_OPERATORS, TRAIN_OPERATORS, VALIDATE_OPERATORS, getArrayOperators, getAsyncOperators, getFormatOperators, getLambdaArrayOperators, getMathOperators, getNnOperators, getObjectOperators, getStrOperators, getTensorOperators, getTimeOperators, getTrainOperators, getValidateOperators };
|
|
3130
|
+
//# sourceMappingURL=index.js.map
|
|
3131
|
+
//# sourceMappingURL=index.js.map
|