@bian-womp/spark-graph 0.1.22 → 0.1.23
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/lib/cjs/index.cjs +166 -15
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/cjs/src/misc/base.d.ts.map +1 -1
- package/lib/esm/index.js +166 -15
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/src/misc/base.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/misc/base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,KAAK,EAEV,eAAe,EAEhB,MAAM,eAAe,CAAC;AA2HvB,wBAAgB,uBAAuB,IAAI,QAAQ,
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/misc/base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,KAAK,EAEV,eAAe,EAEhB,MAAM,eAAe,CAAC;AA2HvB,wBAAgB,uBAAuB,IAAI,QAAQ,CA+zBlD;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,QA+BnD;AAqBD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,QA6BvD;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,eAAe,6BAUrE"}
|
package/lib/esm/index.js
CHANGED
|
@@ -1971,7 +1971,7 @@ function setupBasicGraphRegistry() {
|
|
|
1971
1971
|
});
|
|
1972
1972
|
// Enums: Math Operation
|
|
1973
1973
|
registry.registerEnum({
|
|
1974
|
-
id: "base.
|
|
1974
|
+
id: "enum:base.math.operation",
|
|
1975
1975
|
options: [
|
|
1976
1976
|
{ value: 0, label: "Add" },
|
|
1977
1977
|
{ value: 1, label: "Subtract" },
|
|
@@ -1981,11 +1981,20 @@ function setupBasicGraphRegistry() {
|
|
|
1981
1981
|
{ value: 5, label: "Max" },
|
|
1982
1982
|
{ value: 6, label: "Modulo" },
|
|
1983
1983
|
{ value: 7, label: "Power" },
|
|
1984
|
+
// Unary / aggregate operations on A only
|
|
1985
|
+
{ value: 8, label: "Round" },
|
|
1986
|
+
{ value: 9, label: "Floor" },
|
|
1987
|
+
{ value: 10, label: "Ceil" },
|
|
1988
|
+
{ value: 11, label: "Abs" },
|
|
1989
|
+
{ value: 12, label: "Sum" },
|
|
1990
|
+
{ value: 13, label: "Avg" },
|
|
1991
|
+
{ value: 14, label: "MinAll" },
|
|
1992
|
+
{ value: 15, label: "MaxAll" },
|
|
1984
1993
|
],
|
|
1985
1994
|
});
|
|
1986
1995
|
// Enums: Compare Operation
|
|
1987
1996
|
registry.registerEnum({
|
|
1988
|
-
id: "base.
|
|
1997
|
+
id: "enum:base.compare.operation",
|
|
1989
1998
|
options: [
|
|
1990
1999
|
{ value: 0, label: "LessThan" },
|
|
1991
2000
|
{ value: 1, label: "LessThanOrEqual" },
|
|
@@ -2110,7 +2119,7 @@ function setupBasicGraphRegistry() {
|
|
|
2110
2119
|
id: "base.math",
|
|
2111
2120
|
categoryId: "compute",
|
|
2112
2121
|
inputs: {
|
|
2113
|
-
Operation: "base.
|
|
2122
|
+
Operation: "enum:base.math.operation",
|
|
2114
2123
|
A: "base.float[]",
|
|
2115
2124
|
B: "base.float[]",
|
|
2116
2125
|
},
|
|
@@ -2121,8 +2130,34 @@ function setupBasicGraphRegistry() {
|
|
|
2121
2130
|
// Gracefully handle missing inputs by treating them as zeros
|
|
2122
2131
|
const a = ins.A === undefined ? [] : asArray(ins.A);
|
|
2123
2132
|
const b = ins.B === undefined ? [] : asArray(ins.B);
|
|
2124
|
-
const len = Math.max(a.length, b.length);
|
|
2125
2133
|
const op = Number(ins.Operation ?? 0) | 0;
|
|
2134
|
+
// Unary ops on A
|
|
2135
|
+
if (op === 8)
|
|
2136
|
+
return { Result: a.map((x) => Math.round(Number(x))) };
|
|
2137
|
+
if (op === 9)
|
|
2138
|
+
return { Result: a.map((x) => Math.floor(Number(x))) };
|
|
2139
|
+
if (op === 10)
|
|
2140
|
+
return { Result: a.map((x) => Math.ceil(Number(x))) };
|
|
2141
|
+
if (op === 11)
|
|
2142
|
+
return { Result: a.map((x) => Math.abs(Number(x))) };
|
|
2143
|
+
// Aggregate ops on A -> single-element array
|
|
2144
|
+
if (op === 12)
|
|
2145
|
+
return { Result: [a.reduce((s, x) => s + Number(x || 0), 0)] };
|
|
2146
|
+
if (op === 13) {
|
|
2147
|
+
const sum = a.reduce((s, x) => s + Number(x || 0), 0);
|
|
2148
|
+
const avg = a.length ? sum / a.length : 0;
|
|
2149
|
+
return { Result: [avg] };
|
|
2150
|
+
}
|
|
2151
|
+
if (op === 14)
|
|
2152
|
+
return {
|
|
2153
|
+
Result: [a.length ? Math.min(...a.map((x) => Number(x))) : 0],
|
|
2154
|
+
};
|
|
2155
|
+
if (op === 15)
|
|
2156
|
+
return {
|
|
2157
|
+
Result: [a.length ? Math.max(...a.map((x) => Number(x))) : 0],
|
|
2158
|
+
};
|
|
2159
|
+
// Binary ops A (broadcast) B
|
|
2160
|
+
const len = Math.max(a.length, b.length);
|
|
2126
2161
|
const ops = [
|
|
2127
2162
|
(x, y) => x + y,
|
|
2128
2163
|
(x, y) => x - y,
|
|
@@ -2147,7 +2182,7 @@ function setupBasicGraphRegistry() {
|
|
|
2147
2182
|
id: "base.compare",
|
|
2148
2183
|
categoryId: "compute",
|
|
2149
2184
|
inputs: {
|
|
2150
|
-
Operation: "base.
|
|
2185
|
+
Operation: "enum:base.compare.operation",
|
|
2151
2186
|
A: "base.float[]",
|
|
2152
2187
|
B: "base.float[]",
|
|
2153
2188
|
},
|
|
@@ -2167,6 +2202,122 @@ function setupBasicGraphRegistry() {
|
|
|
2167
2202
|
return { Result: a.map((x, i) => fn(Number(x), Number(b[i] ?? 0))) };
|
|
2168
2203
|
},
|
|
2169
2204
|
});
|
|
2205
|
+
// Logic
|
|
2206
|
+
registry.registerNode({
|
|
2207
|
+
id: "base.logic",
|
|
2208
|
+
categoryId: "compute",
|
|
2209
|
+
inputs: { Operation: "base.string", A: "base.bool", B: "base.bool" },
|
|
2210
|
+
outputs: { Result: "base.bool" },
|
|
2211
|
+
impl: (ins) => {
|
|
2212
|
+
const op = String(ins.Operation || "not").toLowerCase();
|
|
2213
|
+
const a = !!ins.A;
|
|
2214
|
+
const b = !!ins.B;
|
|
2215
|
+
if (op === "not")
|
|
2216
|
+
return { Result: !a };
|
|
2217
|
+
if (op === "and")
|
|
2218
|
+
return { Result: a && b };
|
|
2219
|
+
if (op === "or")
|
|
2220
|
+
return { Result: a || b };
|
|
2221
|
+
return { Result: false };
|
|
2222
|
+
},
|
|
2223
|
+
});
|
|
2224
|
+
// Strings
|
|
2225
|
+
registry.registerNode({
|
|
2226
|
+
id: "base.string.length",
|
|
2227
|
+
categoryId: "compute",
|
|
2228
|
+
inputs: { Text: "base.string" },
|
|
2229
|
+
outputs: { Length: "base.float" },
|
|
2230
|
+
impl: (ins) => ({
|
|
2231
|
+
Length: String(ins.Text || "").length,
|
|
2232
|
+
}),
|
|
2233
|
+
});
|
|
2234
|
+
registry.registerNode({
|
|
2235
|
+
id: "base.string.op",
|
|
2236
|
+
categoryId: "compute",
|
|
2237
|
+
inputs: { Op: "base.string", Text: "base.string" },
|
|
2238
|
+
outputs: { Text: "base.string" },
|
|
2239
|
+
impl: (ins) => {
|
|
2240
|
+
const op = String(ins.Op || "trim").toLowerCase();
|
|
2241
|
+
const t = String(ins.Text || "");
|
|
2242
|
+
if (op === "lower")
|
|
2243
|
+
return { Text: t.toLowerCase() };
|
|
2244
|
+
if (op === "upper")
|
|
2245
|
+
return { Text: t.toUpperCase() };
|
|
2246
|
+
return { Text: t.trim() };
|
|
2247
|
+
},
|
|
2248
|
+
});
|
|
2249
|
+
registry.registerNode({
|
|
2250
|
+
id: "base.string.split",
|
|
2251
|
+
categoryId: "compute",
|
|
2252
|
+
inputs: { Text: "base.string", Sep: "base.string" },
|
|
2253
|
+
outputs: { Parts: "base.string[]" },
|
|
2254
|
+
impl: (ins) => {
|
|
2255
|
+
const t = String(ins.Text || "");
|
|
2256
|
+
const sep = String(ins.Sep || ",");
|
|
2257
|
+
return { Parts: t.split(sep) };
|
|
2258
|
+
},
|
|
2259
|
+
});
|
|
2260
|
+
registry.registerNode({
|
|
2261
|
+
id: "base.string.join",
|
|
2262
|
+
categoryId: "compute",
|
|
2263
|
+
inputs: { Parts: "base.string[]", Sep: "base.string" },
|
|
2264
|
+
outputs: { Text: "base.string" },
|
|
2265
|
+
impl: (ins) => {
|
|
2266
|
+
const parts = Array.isArray(ins.Parts) ? ins.Parts.map(String) : [];
|
|
2267
|
+
const sep = String(ins.Sep || "");
|
|
2268
|
+
return { Text: parts.join(sep) };
|
|
2269
|
+
},
|
|
2270
|
+
});
|
|
2271
|
+
registry.registerNode({
|
|
2272
|
+
id: "base.string.replace",
|
|
2273
|
+
categoryId: "compute",
|
|
2274
|
+
inputs: {
|
|
2275
|
+
Text: "base.string",
|
|
2276
|
+
Search: "base.string",
|
|
2277
|
+
Replace: "base.string",
|
|
2278
|
+
},
|
|
2279
|
+
outputs: { Text: "base.string" },
|
|
2280
|
+
impl: (ins) => {
|
|
2281
|
+
const t = String(ins.Text || "");
|
|
2282
|
+
const s = String(ins.Search || "");
|
|
2283
|
+
const r = String(ins.Replace || "");
|
|
2284
|
+
return { Text: t.split(s).join(r) };
|
|
2285
|
+
},
|
|
2286
|
+
});
|
|
2287
|
+
// Arrays (carried as base.object)
|
|
2288
|
+
registry.registerNode({
|
|
2289
|
+
id: "base.array.length",
|
|
2290
|
+
categoryId: "compute",
|
|
2291
|
+
inputs: { Items: "base.object" },
|
|
2292
|
+
outputs: { Length: "base.float" },
|
|
2293
|
+
impl: (ins) => ({
|
|
2294
|
+
Length: Array.isArray(ins.Items) ? ins.Items.length : 0,
|
|
2295
|
+
}),
|
|
2296
|
+
});
|
|
2297
|
+
registry.registerNode({
|
|
2298
|
+
id: "base.array.slice",
|
|
2299
|
+
categoryId: "compute",
|
|
2300
|
+
inputs: { Items: "base.object", Start: "base.float", End: "base.float" },
|
|
2301
|
+
outputs: { Result: "base.object" },
|
|
2302
|
+
impl: (ins) => {
|
|
2303
|
+
const arr = Array.isArray(ins.Items) ? ins.Items : [];
|
|
2304
|
+
const s = Math.trunc(Number(ins.Start ?? 0));
|
|
2305
|
+
const e = Number.isFinite(Number(ins.End))
|
|
2306
|
+
? Math.trunc(Number(ins.End))
|
|
2307
|
+
: undefined;
|
|
2308
|
+
return { Result: arr.slice(s, e) };
|
|
2309
|
+
},
|
|
2310
|
+
});
|
|
2311
|
+
// Select
|
|
2312
|
+
registry.registerNode({
|
|
2313
|
+
id: "base.select",
|
|
2314
|
+
categoryId: "compute",
|
|
2315
|
+
inputs: { Cond: "base.bool", Then: "base.object", Else: "base.object" },
|
|
2316
|
+
outputs: { Result: "base.object" },
|
|
2317
|
+
impl: (ins) => ({
|
|
2318
|
+
Result: ins.Cond ? ins.Then : ins.Else,
|
|
2319
|
+
}),
|
|
2320
|
+
});
|
|
2170
2321
|
// Combine XYZ
|
|
2171
2322
|
registry.registerNode({
|
|
2172
2323
|
id: "base.compareXYZ",
|
|
@@ -2307,7 +2458,7 @@ function setupBasicGraphRegistry() {
|
|
|
2307
2458
|
});
|
|
2308
2459
|
// ------------------------- JSON/object utilities -------------------------
|
|
2309
2460
|
registry.registerNode({
|
|
2310
|
-
id: "base.
|
|
2461
|
+
id: "base.object.get",
|
|
2311
2462
|
categoryId: "compute",
|
|
2312
2463
|
inputs: { Object: "base.object", Pointers: "base.string[]" },
|
|
2313
2464
|
outputs: { Values: "base.object" },
|
|
@@ -2321,7 +2472,7 @@ function setupBasicGraphRegistry() {
|
|
|
2321
2472
|
},
|
|
2322
2473
|
});
|
|
2323
2474
|
registry.registerNode({
|
|
2324
|
-
id: "base.
|
|
2475
|
+
id: "base.object.set",
|
|
2325
2476
|
categoryId: "compute",
|
|
2326
2477
|
inputs: {
|
|
2327
2478
|
Object: "base.object",
|
|
@@ -2351,7 +2502,7 @@ function setupBasicGraphRegistry() {
|
|
|
2351
2502
|
},
|
|
2352
2503
|
});
|
|
2353
2504
|
registry.registerNode({
|
|
2354
|
-
id: "base.
|
|
2505
|
+
id: "base.object.remove",
|
|
2355
2506
|
categoryId: "compute",
|
|
2356
2507
|
inputs: { Object: "base.object", Pointers: "base.string[]" },
|
|
2357
2508
|
outputs: { Result: "base.object" },
|
|
@@ -2364,7 +2515,7 @@ function setupBasicGraphRegistry() {
|
|
|
2364
2515
|
},
|
|
2365
2516
|
});
|
|
2366
2517
|
registry.registerNode({
|
|
2367
|
-
id: "base.
|
|
2518
|
+
id: "base.object.merge",
|
|
2368
2519
|
categoryId: "compute",
|
|
2369
2520
|
inputs: { A: "base.object", B: "base.object" },
|
|
2370
2521
|
outputs: { Result: "base.object" },
|
|
@@ -2373,7 +2524,7 @@ function setupBasicGraphRegistry() {
|
|
|
2373
2524
|
}),
|
|
2374
2525
|
});
|
|
2375
2526
|
registry.registerNode({
|
|
2376
|
-
id: "base.
|
|
2527
|
+
id: "base.object.keys",
|
|
2377
2528
|
categoryId: "compute",
|
|
2378
2529
|
inputs: { Object: "base.object" },
|
|
2379
2530
|
outputs: { Keys: "base.string[]" },
|
|
@@ -2388,7 +2539,7 @@ function setupBasicGraphRegistry() {
|
|
|
2388
2539
|
},
|
|
2389
2540
|
});
|
|
2390
2541
|
registry.registerNode({
|
|
2391
|
-
id: "base.
|
|
2542
|
+
id: "base.object.values",
|
|
2392
2543
|
categoryId: "compute",
|
|
2393
2544
|
inputs: { Object: "base.object" },
|
|
2394
2545
|
outputs: { Values: "base.object" },
|
|
@@ -2403,7 +2554,7 @@ function setupBasicGraphRegistry() {
|
|
|
2403
2554
|
},
|
|
2404
2555
|
});
|
|
2405
2556
|
registry.registerNode({
|
|
2406
|
-
id: "base.
|
|
2557
|
+
id: "base.object.patch",
|
|
2407
2558
|
categoryId: "compute",
|
|
2408
2559
|
inputs: { Object: "base.object", Ops: "base.object" },
|
|
2409
2560
|
outputs: { Result: "base.object" },
|
|
@@ -2439,7 +2590,7 @@ function setupBasicGraphRegistry() {
|
|
|
2439
2590
|
},
|
|
2440
2591
|
});
|
|
2441
2592
|
registry.registerNode({
|
|
2442
|
-
id: "base.
|
|
2593
|
+
id: "base.array.concat",
|
|
2443
2594
|
categoryId: "compute",
|
|
2444
2595
|
inputs: { A: "base.object", B: "base.object" },
|
|
2445
2596
|
outputs: { Result: "base.object" },
|
|
@@ -2450,7 +2601,7 @@ function setupBasicGraphRegistry() {
|
|
|
2450
2601
|
},
|
|
2451
2602
|
});
|
|
2452
2603
|
registry.registerNode({
|
|
2453
|
-
id: "base.
|
|
2604
|
+
id: "base.array.flatten",
|
|
2454
2605
|
categoryId: "compute",
|
|
2455
2606
|
inputs: { Objects: "base.object" },
|
|
2456
2607
|
outputs: { Result: "base.object" },
|
|
@@ -2467,7 +2618,7 @@ function setupBasicGraphRegistry() {
|
|
|
2467
2618
|
},
|
|
2468
2619
|
});
|
|
2469
2620
|
registry.registerNode({
|
|
2470
|
-
id: "base.
|
|
2621
|
+
id: "base.array.sortBy",
|
|
2471
2622
|
categoryId: "compute",
|
|
2472
2623
|
inputs: { Objects: "base.object", Pointers: "base.string[]" },
|
|
2473
2624
|
outputs: { Result: "base.object" },
|