@voxgig/struct-js 0.1.5 → 0.1.7
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/package.json +1 -1
- package/src/struct.js +14 -17
package/package.json
CHANGED
package/src/struct.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* Copyright (c) 2025-2026 Voxgig Ltd. MIT LICENSE. */
|
|
2
|
-
// VERSION: @voxgig/struct-js 0.1.
|
|
2
|
+
// VERSION: @voxgig/struct-js 0.1.7
|
|
3
3
|
/* Voxgig Struct
|
|
4
4
|
* =============
|
|
5
5
|
*
|
|
@@ -846,7 +846,7 @@ function walk(
|
|
|
846
846
|
// Merge a list of values into each other. Later values have
|
|
847
847
|
// precedence. Nodes override scalars. Node kinds (list or map)
|
|
848
848
|
// override each other, and do *not* merge. The first element is
|
|
849
|
-
// modified.
|
|
849
|
+
// modified; the others are not.
|
|
850
850
|
function merge(val, maxdepth) {
|
|
851
851
|
// const md: number = null == maxdepth ? MAXDEPTH : maxdepth < 0 ? 0 : maxdepth
|
|
852
852
|
const md = slice(maxdepth ?? MAXDEPTH, 0)
|
|
@@ -889,34 +889,32 @@ function merge(val, maxdepth) {
|
|
|
889
889
|
dst[pI] = 0 < pI ? getprop(dst[pI - 1], key) : dst[pI]
|
|
890
890
|
const tval = dst[pI]
|
|
891
891
|
const vtype = typify(val)
|
|
892
|
-
// Destination empty, so create node (unless override is class instance).
|
|
893
|
-
if (NONE === tval && 0 === (T_instance & vtype)) {
|
|
894
|
-
cur[pI] = islist(val) ? [] : {}
|
|
895
|
-
}
|
|
896
892
|
// Matching override and destination so continue with their values.
|
|
897
|
-
|
|
893
|
+
if (vtype === typify(tval)) {
|
|
898
894
|
cur[pI] = tval
|
|
899
895
|
}
|
|
900
|
-
//
|
|
896
|
+
// Otherwise the override wins: a plain node is copied, taking
|
|
897
|
+
// nothing from the destination, so no later merge writes into it.
|
|
898
|
+
else if (0 === (T_instance & vtype)) {
|
|
899
|
+
cur[pI] = islist(val) ? [] : {}
|
|
900
|
+
dst[pI] = NONE
|
|
901
|
+
}
|
|
902
|
+
// A class instance is kept as is, so there is nothing to descend.
|
|
901
903
|
else {
|
|
902
904
|
cur[pI] = val
|
|
903
|
-
// No need to descend when override wins (destination is discarded).
|
|
904
905
|
val = NONE
|
|
905
906
|
}
|
|
906
907
|
}
|
|
907
|
-
// console.log('BEFORE-END', pathify(path), '@', pI, key,
|
|
908
|
-
// stringify(val, -1, 1), stringify(parent, -1, 1),
|
|
909
|
-
// 'CUR=', stringify(cur, -1, 1), 'DST=', stringify(dst, -1, 1))
|
|
910
908
|
return val
|
|
911
909
|
}
|
|
912
|
-
function after(key, _val,
|
|
910
|
+
function after(key, _val, parent, path) {
|
|
913
911
|
const cI = size(path)
|
|
914
912
|
const target = cur[cI - 1]
|
|
915
913
|
const value = cur[cI]
|
|
916
|
-
// console.log('AFTER-PREP', pathify(path), '@', cI, cur, '|',
|
|
917
|
-
// stringify(key, -1, 1), stringify(value, -1, 1), 'T=', stringify(target, -1, 1))
|
|
918
914
|
setprop(target, key, value)
|
|
919
|
-
|
|
915
|
+
// walk writes this back into the override, so below the root it is
|
|
916
|
+
// the override's own child (_lookup keeps a null, getprop would not).
|
|
917
|
+
return 0 === cI ? value : _lookup(parent, key)
|
|
920
918
|
}
|
|
921
919
|
// Walk overriding node, creating paths in output as needed.
|
|
922
920
|
out = walk(obj, before, after, maxdepth)
|
|
@@ -1711,7 +1709,6 @@ const validate_ONE = (inj, _val, _ref, store) => {
|
|
|
1711
1709
|
// Clean up structure, replacing [$ONE, ...] with current
|
|
1712
1710
|
inj.setval(inj.dparent, 2)
|
|
1713
1711
|
inj.path = slice(inj.path, -1)
|
|
1714
|
-
inj.key = getelem(inj.path, -1)
|
|
1715
1712
|
let tvals = slice(parent, 1)
|
|
1716
1713
|
if (0 === size(tvals)) {
|
|
1717
1714
|
inj.errs.push(
|