@bian-womp/spark-graph 0.1.23 → 0.1.25
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 +44 -29
- package/lib/cjs/index.cjs.map +1 -1
- package/lib/cjs/src/builder/Registry.d.ts.map +1 -1
- package/lib/cjs/src/misc/base.d.ts.map +1 -1
- package/lib/esm/index.js +44 -29
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/src/builder/Registry.d.ts.map +1 -1
- package/lib/esm/src/misc/base.d.ts.map +1 -1
- package/package.json +2 -2
package/lib/cjs/index.cjs
CHANGED
|
@@ -121,8 +121,8 @@ class Registry {
|
|
|
121
121
|
nonTransitive: !!opts?.nonTransitive,
|
|
122
122
|
});
|
|
123
123
|
// If both source and target have array variants, add derived array->array coercion
|
|
124
|
-
const fromArr = `${fromTypeId}[]`;
|
|
125
|
-
const toArr = `${toTypeId}[]`;
|
|
124
|
+
const fromArr = fromTypeId === "base.object" ? fromTypeId : `${fromTypeId}[]`;
|
|
125
|
+
const toArr = toTypeId === "base.object" ? toTypeId : `${toTypeId}[]`;
|
|
126
126
|
const arrKey = `${fromArr}->${toArr}`;
|
|
127
127
|
if (this.types.has(fromArr) && this.types.has(toArr)) {
|
|
128
128
|
if (!this.coercions.has(arrKey) && !this.asyncCoercions.has(arrKey)) {
|
|
@@ -147,8 +147,8 @@ class Registry {
|
|
|
147
147
|
nonTransitive: !!opts?.nonTransitive,
|
|
148
148
|
});
|
|
149
149
|
// If both source and target have array variants, add derived array->array async coercion
|
|
150
|
-
const fromArr = `${fromTypeId}[]`;
|
|
151
|
-
const toArr = `${toTypeId}[]`;
|
|
150
|
+
const fromArr = fromTypeId === "base.object" ? fromTypeId : `${fromTypeId}[]`;
|
|
151
|
+
const toArr = toTypeId === "base.object" ? toTypeId : `${toTypeId}[]`;
|
|
152
152
|
const arrKey = `${fromArr}->${toArr}`;
|
|
153
153
|
if (this.types.has(fromArr) && this.types.has(toArr)) {
|
|
154
154
|
if (!this.coercions.has(arrKey) && !this.asyncCoercions.has(arrKey)) {
|
|
@@ -1950,7 +1950,7 @@ function setupBasicGraphRegistry() {
|
|
|
1950
1950
|
return String(v);
|
|
1951
1951
|
}
|
|
1952
1952
|
});
|
|
1953
|
-
registry.registerCoercion("base.vec3", "base.
|
|
1953
|
+
registry.registerCoercion("base.vec3", "base.object", (v) => {
|
|
1954
1954
|
try {
|
|
1955
1955
|
return v ? JSON.stringify(v) : undefined;
|
|
1956
1956
|
}
|
|
@@ -1958,7 +1958,7 @@ function setupBasicGraphRegistry() {
|
|
|
1958
1958
|
return undefined;
|
|
1959
1959
|
}
|
|
1960
1960
|
});
|
|
1961
|
-
registry.registerCoercion("base.
|
|
1961
|
+
registry.registerCoercion("base.object", "base.vec3", (v) => {
|
|
1962
1962
|
try {
|
|
1963
1963
|
const result = JSON.parse(v);
|
|
1964
1964
|
if (result.length === 3 &&
|
|
@@ -1992,6 +1992,16 @@ function setupBasicGraphRegistry() {
|
|
|
1992
1992
|
{ value: 13, label: "Avg" },
|
|
1993
1993
|
{ value: 14, label: "MinAll" },
|
|
1994
1994
|
{ value: 15, label: "MaxAll" },
|
|
1995
|
+
// Trig and other unary functions on A
|
|
1996
|
+
{ value: 16, label: "Sin" },
|
|
1997
|
+
{ value: 17, label: "Cos" },
|
|
1998
|
+
{ value: 18, label: "Tan" },
|
|
1999
|
+
{ value: 19, label: "ASin" },
|
|
2000
|
+
{ value: 20, label: "ACos" },
|
|
2001
|
+
{ value: 21, label: "ATan" },
|
|
2002
|
+
{ value: 22, label: "Sqrt" },
|
|
2003
|
+
{ value: 23, label: "Exp" },
|
|
2004
|
+
{ value: 24, label: "Log" },
|
|
1995
2005
|
],
|
|
1996
2006
|
});
|
|
1997
2007
|
// Enums: Compare Operation
|
|
@@ -2134,30 +2144,35 @@ function setupBasicGraphRegistry() {
|
|
|
2134
2144
|
const b = ins.B === undefined ? [] : asArray(ins.B);
|
|
2135
2145
|
const op = Number(ins.Operation ?? 0) | 0;
|
|
2136
2146
|
// Unary ops on A
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2147
|
+
const unary = {
|
|
2148
|
+
8: (x) => Math.round(x),
|
|
2149
|
+
9: (x) => Math.floor(x),
|
|
2150
|
+
10: (x) => Math.ceil(x),
|
|
2151
|
+
11: (x) => Math.abs(x),
|
|
2152
|
+
16: (x) => Math.sin(x),
|
|
2153
|
+
17: (x) => Math.cos(x),
|
|
2154
|
+
18: (x) => Math.tan(x),
|
|
2155
|
+
19: (x) => Math.asin(x),
|
|
2156
|
+
20: (x) => Math.acos(x),
|
|
2157
|
+
21: (x) => Math.atan(x),
|
|
2158
|
+
22: (x) => Math.sqrt(x),
|
|
2159
|
+
23: (x) => Math.exp(x),
|
|
2160
|
+
24: (x) => Math.log(x),
|
|
2161
|
+
};
|
|
2162
|
+
if (op in unary)
|
|
2163
|
+
return { Result: a.map((x) => unary[op](Number(x))) };
|
|
2145
2164
|
// Aggregate ops on A -> single-element array
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
};
|
|
2157
|
-
if (op === 15)
|
|
2158
|
-
return {
|
|
2159
|
-
Result: [a.length ? Math.max(...a.map((x) => Number(x))) : 0],
|
|
2160
|
-
};
|
|
2165
|
+
const aggregates = {
|
|
2166
|
+
12: (arr) => arr.reduce((s, x) => s + Number(x || 0), 0),
|
|
2167
|
+
13: (arr) => {
|
|
2168
|
+
const sum = arr.reduce((s, x) => s + Number(x || 0), 0);
|
|
2169
|
+
return arr.length ? sum / arr.length : 0;
|
|
2170
|
+
},
|
|
2171
|
+
14: (arr) => (arr.length ? Math.min(...arr.map((x) => Number(x))) : 0),
|
|
2172
|
+
15: (arr) => (arr.length ? Math.max(...arr.map((x) => Number(x))) : 0),
|
|
2173
|
+
};
|
|
2174
|
+
if (op in aggregates)
|
|
2175
|
+
return { Result: [aggregates[op](a)] };
|
|
2161
2176
|
// Binary ops A (broadcast) B
|
|
2162
2177
|
const len = Math.max(a.length, b.length);
|
|
2163
2178
|
const ops = [
|