@randajan/jet-base
Advanced tools
Comparing version 1.1.1 to 1.2.0
// src/index.js | ||
import jet2 from "@randajan/jet-core"; | ||
import jet3 from "@randajan/jet-core"; | ||
// src/private.js | ||
import jet from "@randajan/jet-core"; | ||
// src/defs.js | ||
var LIST = /* @__PURE__ */ new Map(); | ||
@@ -10,14 +9,115 @@ var use = (base) => LIST.get(base); | ||
LIST.set(base, { | ||
paths: /* @__PURE__ */ new Set(), | ||
flat: {}, | ||
fit: {}, | ||
watch: {}, | ||
store: {} | ||
fits: {}, | ||
watches: {} | ||
}); | ||
}; | ||
var get = (base, path) => { | ||
// src/duty.js | ||
import jet2 from "@randajan/jet-core"; | ||
// src/vals.js | ||
import jet from "@randajan/jet-core"; | ||
var spread = (path) => { | ||
const x = path.lastIndexOf("."); | ||
if (x < 0) { | ||
return [path, "", path]; | ||
} | ||
return [path, path.slice(0, x), path.slice(x + 1)]; | ||
}; | ||
var forEach = (value, callback, path) => { | ||
const put2 = (v, p) => callback(v, p, false); | ||
const deep = (v, p) => { | ||
jet.forEach(v, put2, deep, p); | ||
return callback(v, p, true); | ||
}; | ||
return jet.forEach(value, put2, deep, path); | ||
}; | ||
var deflate = (paths, path, value) => { | ||
const flat = { [path]: value }; | ||
let p = path; | ||
do { | ||
if (paths.has(p)) { | ||
break; | ||
} | ||
paths.add(p); | ||
const x = p.lastIndexOf("."); | ||
if (x <= 0) { | ||
break; | ||
} | ||
p = p.slice(0, x); | ||
} while (true); | ||
forEach(value, (v, p2) => { | ||
paths.add(p2); | ||
flat[p2] = v; | ||
}, path); | ||
return flat; | ||
}; | ||
var prepareParent = (key, parent, img, copy = false) => { | ||
if (parent) { | ||
return parent; | ||
} | ||
if (!img) { | ||
return String.jet.isNumeric(key) ? [] : {}; | ||
} | ||
return copy ? jet.copy(img, true, false) : jet.create(jet(img, false)); | ||
}; | ||
var put = (path, value, parents, parentImgs, imgCopy = false) => { | ||
const [p, d, k] = spread(path); | ||
parents[d] = prepareParent(k, parents[d], parentImgs[d], imgCopy); | ||
if (p) { | ||
jet.set(parents[d], k, value); | ||
} | ||
parents[p] = value; | ||
}; | ||
var fit = (fits, path, to, from) => fits[path] && fits[path].fit ? fits[path].fit(to[path], from[path]) : to[path]; | ||
var set = (base, path, value) => { | ||
const _p = use(base), { input, flat, fits, paths, watches } = _p; | ||
path = String.jet.to(path, "."); | ||
return path ? use(base).flat[path] : use(base).output; | ||
const flatIn = deflate(paths, path, value); | ||
const rawPaths = [...paths].sort(); | ||
for (let i = rawPaths.length - 1; i >= 0; i--) { | ||
const p = rawPaths[i]; | ||
if (path === p) { | ||
put(p, fit(fits, p, flatIn, flat), flatIn, flat, true); | ||
} else if (path.startsWith(p)) { | ||
put(p, fit(fits, p, flatIn, flat), flatIn, flat, true); | ||
} else if (p.startsWith(path)) { | ||
put(p, fit(fits, p, flatIn, flat), flatIn, flatIn); | ||
} | ||
} | ||
_p.input = path ? jet.digIn(input, path, value, true) : value; | ||
const output = _p.output = flatIn[""]; | ||
const pathsOut = _p.paths = /* @__PURE__ */ new Set(); | ||
const flatOut = _p.flat = { "": output }; | ||
const cngs = _p.changes = []; | ||
forEach(output, (v, p, isMapable) => { | ||
if (!isMapable && v !== flat[p]) { | ||
cngs.push(p); | ||
} | ||
pathsOut.add(p); | ||
flatOut[p] = v; | ||
delete flat[p]; | ||
}); | ||
for (const p in flat) { | ||
if (!jet.isMapable(flat[p]) && flatOut[p] != flat[p]) { | ||
cngs.push(p); | ||
} | ||
} | ||
if (cngs.length) { | ||
const c = " ^" + cngs.join(" ^"); | ||
for (const p in watches) { | ||
if (c.includes(" ^" + p)) { | ||
watches[p].run(cngs); | ||
} | ||
} | ||
} | ||
return cngs; | ||
}; | ||
var get = (base, path) => use(base).flat[String.jet.to(path, ".")]; | ||
// src/duty.js | ||
var formatDutyArgs = (path, fce) => { | ||
if (fce === void 0 && jet.isRunnable(path)) { | ||
if (fce === void 0 && jet2.isRunnable(path)) { | ||
fce = path; | ||
@@ -30,3 +130,3 @@ path = ""; | ||
}; | ||
var addDuty = (priv, kind, path, fce) => (priv[kind][path] = priv[kind][path] || jet.create.RunPool()).add(fce); | ||
var addDuty = (priv, kind, path, fce) => (priv[kind][path] = priv[kind][path] || jet2.create.RunPool()).add(fce); | ||
var filterChanges = (path, changes) => { | ||
@@ -44,13 +144,13 @@ if (!path) { | ||
}; | ||
var watch = (base, path, fce) => { | ||
var addWatch = (base, path, fce) => { | ||
[path, fce] = formatDutyArgs(path, fce); | ||
return addDuty(use(base), "watch", path, (cngs) => { | ||
return addDuty(use(base), "watches", path, (cngs) => { | ||
fce((p) => base.get([path, p]), (_) => filterChanges(path, cngs)); | ||
}); | ||
}; | ||
var fit = (base, path, fce) => { | ||
var addFit = (base, path, fce) => { | ||
[path, fce] = formatDutyArgs(path, fce); | ||
const _p = use(base); | ||
const rem = addDuty(_p, "fit", path, fce); | ||
const refit = path ? (_) => set(base, path, jet.digOut(_p.input, path)) : (_) => set(base, path, _p.input); | ||
const rem = addDuty(_p, "fits", path, fce); | ||
const refit = path ? (_) => set(base, path, jet2.digOut(_p.input, path)) : (_) => set(base, path, _p.input); | ||
refit(); | ||
@@ -62,53 +162,2 @@ return (_) => { | ||
}; | ||
var set = (base, path, value) => { | ||
const _p = use(base), { input, output, flat, fit: fit2 } = _p; | ||
path = String.jet.to(path, "."); | ||
const put = (v, p) => p && fit2[p] && fit2[p].fit ? fit2[p].fit(v, flat[p]) : v; | ||
const deep = (v, p) => put(jet.map(v, put, deep, p), p); | ||
let dummy = jet.map(value, put, deep, path); | ||
if (!path) { | ||
_p.input = value; | ||
_p.output = dummy; | ||
} else { | ||
_p.input = jet.digIn(input, path, value, true); | ||
_p.output = jet.digIn(output, path, dummy, true, (next, parent, path2, dir) => put(next(parent ? jet.copy(parent) : parent), dir)); | ||
} | ||
if (fit2[""]) { | ||
_p.output = fit2[""].fit(_p.output, output); | ||
} | ||
return flatIt(base); | ||
}; | ||
var flatIt = (base) => { | ||
const _p = use(base), { output, flat, watch: watch2 } = _p; | ||
const newFlat = _p.flat = {}; | ||
const cngs = _p.changes = []; | ||
const put = (v, p) => { | ||
if (v !== flat[p]) { | ||
cngs.push(p); | ||
} | ||
newFlat[p] = v; | ||
delete flat[p]; | ||
}; | ||
const deep = (v, p) => { | ||
jet.forEach(v, put, deep, p); | ||
newFlat[p] = v; | ||
delete flat[p]; | ||
}; | ||
jet.forEach(output, put, deep); | ||
for (const p in flat) { | ||
if (!jet.isMapable(flat[p]) && newFlat[p] != flat[p]) { | ||
cngs.push(p); | ||
} | ||
} | ||
if (!cngs.length) { | ||
return cngs; | ||
} | ||
const c = " ^" + cngs.join(" ^"); | ||
for (const p in watch2) { | ||
if (c.includes(" ^" + p)) { | ||
watch2[p].run(cngs); | ||
} | ||
} | ||
return cngs; | ||
}; | ||
@@ -127,14 +176,14 @@ // src/index.js | ||
} | ||
isType(path, type, soft) { | ||
return jet2.is(type, get(this, path), soft); | ||
isType(path, type, strict = true) { | ||
return jet3.is(type, get(this, path), strict); | ||
} | ||
isFull(path) { | ||
return jet2.isFull(get(this, path)); | ||
return jet3.isFull(get(this, path)); | ||
} | ||
get(path, def) { | ||
const v = get(this, path); | ||
return v != null ? jet2.copy(v, true) : def; | ||
return v != null ? jet3.copy(v, true) : def; | ||
} | ||
getType(path, all = false) { | ||
return jet2(get(this, path), all); | ||
getType(path, strict = true) { | ||
return jet3(get(this, path), strict); | ||
} | ||
@@ -160,19 +209,25 @@ set(path, value) { | ||
watch(path, fce) { | ||
return watch(this, path, fce); | ||
return addWatch(this, path, fce); | ||
} | ||
fit(path, fce) { | ||
return fit(this, path, fce); | ||
return addFit(this, path, fce); | ||
} | ||
fitTo(path, type, ...args) { | ||
return this.fit(path, (next, v, f) => jet2.to(type, next(v, f), ...args)); | ||
return addFit(this, path, (next, v, f) => jet3.to(type, next(v, f), ...args)); | ||
} | ||
fitType(path, type, ...args) { | ||
return this.fit(path, (next, v, f) => jet2.tap(type, next(v, f), ...args)); | ||
fitType(path, type, strict = true) { | ||
return addFit(this, path, (next, v, f) => { | ||
v = next(v, f); | ||
return jet3.is(type, v, strict) ? v : jet3.create(type); | ||
}); | ||
} | ||
default(path, value, force = false) { | ||
const isFull = force ? jet2.isFull : (v) => v != null; | ||
return this.fit(path, (next, v, f) => isFull(next(v, f)) ? v : value); | ||
setDefault(path, value, fullDetect = true) { | ||
const isFull = fullDetect ? jet3.isFull : (v) => v != null; | ||
return addFit(this, path, (next, v, f) => isFull(next(v, f)) ? v : value); | ||
} | ||
lock(path, value) { | ||
return this.fit(path, value === void 0 ? (next, v, f) => f : (_) => value); | ||
setLock(path, value) { | ||
if (value === void 0) { | ||
value = get(this, path); | ||
} | ||
return addFit(this, path, (_) => value); | ||
} | ||
@@ -179,0 +234,0 @@ log(...msg) { |
{ | ||
"name": "@randajan/jet-base", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "Ecosystem of types and related usefull tools.", | ||
@@ -21,3 +21,3 @@ "repository": "randajan/jet-base", | ||
"peerDependencies": { | ||
"@randajan/jet-core": "^2.1.7" | ||
"@randajan/jet-core": "3.0.2" | ||
}, | ||
@@ -24,0 +24,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23697
233
1