@randajan/jet-base
Advanced tools
Comparing version 2.0.1 to 2.0.2
@@ -1,6 +0,7 @@ | ||
// src/base.js | ||
import jet3 from "@randajan/jet-core"; | ||
// src/Base.js | ||
import jet4 from "@randajan/jet-core"; | ||
// src/defs.js | ||
var LIST = /* @__PURE__ */ new Map(); | ||
var states = ["error", "pending", "initializing", "ready"]; | ||
var use = (base) => LIST.get(base); | ||
@@ -13,24 +14,62 @@ var register = (base) => { | ||
watches: {}, | ||
state: "pending", | ||
stateCode: 1, | ||
debug: false | ||
}; | ||
Object.defineProperty(priv, "state", { get: (_) => states[priv.stateCode] }); | ||
LIST.set(base, priv); | ||
return priv; | ||
}; | ||
var config = (base, ...args) => { | ||
const priv = use(base); | ||
if (priv.state !== "pending") { | ||
base.throw("config", `state must be 'pending' insted of ${priv.state}`); | ||
var config = (base, options) => { | ||
const _p = use(base); | ||
if (_p.stateCode !== 1) { | ||
base.throw("config", `state must be '${states[1]}' insted of ${_p.state}`); | ||
} | ||
if (priv.config) { | ||
if (_p.optionsSet) { | ||
base.throw("config", "can be called just once"); | ||
} | ||
priv.config = args; | ||
_p.optionsSet = true; | ||
_p.options = options; | ||
return base; | ||
}; | ||
var init = (base, options) => { | ||
const _p = use(base); | ||
if (_p.stateCode !== 1) { | ||
base.throw("init", `state must be '${states[1]}' insted of '${_p.state}'`); | ||
} | ||
if (_p.optionsSet && options) { | ||
base.throw("init", "options was predefined with config()"); | ||
} | ||
_p.stateCode = 2; | ||
const closure = (isReady, error) => { | ||
if (isReady) { | ||
_p.stateCode = 3; | ||
} else { | ||
_p.stateCode = 0; | ||
_p.error = error || new Error("Unknown error"); | ||
base.throw("init", _p.error); | ||
} | ||
return base; | ||
}; | ||
return _p.initialization = _p.onInit(_p.options = options || _p.options, closure); | ||
}; | ||
var autoInit = (base) => { | ||
if (base.stateCode === 3) { | ||
return; | ||
} | ||
if (base.stateCode === 0) { | ||
base.throw("", use(base).error); | ||
} | ||
if (base.stateCode === 2) { | ||
return use(base).initialization; | ||
} | ||
if (base.stateCode === 1) { | ||
return init(base); | ||
} | ||
}; | ||
// src/duty.js | ||
import jet2 from "@randajan/jet-core"; | ||
import jet3 from "@randajan/jet-core"; | ||
// src/vals.js | ||
import jet from "@randajan/jet-core"; | ||
import jet2 from "@randajan/jet-core"; | ||
var spread = (path) => { | ||
@@ -46,6 +85,6 @@ const x = path.lastIndexOf("."); | ||
const deep = (v, p) => { | ||
jet.forEach(v, put2, deep, p); | ||
jet2.forEach(v, put2, deep, p); | ||
return callback(v, p, true); | ||
}; | ||
return jet.forEach(value, put2, deep, path); | ||
return jet2.forEach(value, put2, deep, path); | ||
}; | ||
@@ -76,6 +115,6 @@ var deflate = (paths, path, value) => { | ||
} | ||
if (!img || !jet.isMapable(img)) { | ||
if (!img || !jet2.isMapable(img)) { | ||
return String.jet.isNumeric(key) ? [] : {}; | ||
} | ||
return copy ? jet.copy(img, true, false) : jet.create(jet(img, false)); | ||
return copy ? jet2.copy(img, true, false) : jet2.create(jet2(img, false)); | ||
}; | ||
@@ -86,3 +125,3 @@ var put = (path, value, parents, parentImgs, imgCopy = false) => { | ||
if (p) { | ||
jet.set(parents[d], k, value); | ||
jet2.set(parents[d], k, value); | ||
} | ||
@@ -107,3 +146,3 @@ parents[p] = value; | ||
} | ||
_p.input = path ? jet.digIn(input, path, value, true) : value; | ||
_p.input = path ? jet2.digIn(input, path, value, true) : value; | ||
const output = _p.output = flatIn[""]; | ||
@@ -123,3 +162,3 @@ const pathsOut = _p.paths = /* @__PURE__ */ new Set(); | ||
for (const p in flat) { | ||
if (!jet.isMapable(flat[p]) && flatOut[p] != flat[p]) { | ||
if (!jet2.isMapable(flat[p]) && flatOut[p] != flat[p]) { | ||
cngs.push(p); | ||
@@ -142,3 +181,3 @@ } | ||
var formatDutyArgs = (path, fce) => { | ||
if (fce === void 0 && jet2.isRunnable(path)) { | ||
if (fce === void 0 && jet3.isRunnable(path)) { | ||
fce = path; | ||
@@ -151,3 +190,3 @@ path = ""; | ||
}; | ||
var addDuty = (priv, kind, path, fce) => (priv[kind][path] = priv[kind][path] || jet2.create.RunPool()).add(fce); | ||
var addDuty = (priv, kind, path, fce) => (priv[kind][path] = priv[kind][path] || jet3.create.RunPool()).add(fce); | ||
var filterChanges = (path, changes) => { | ||
@@ -179,3 +218,3 @@ if (!path) { | ||
const rem = addDuty(_p, "fits", path, fce); | ||
const refit = path ? (_) => set(base, path, jet2.digOut(_p.input, path)) : (_) => set(base, path, _p.input); | ||
const refit = path ? (_) => set(base, path, jet3.digOut(_p.input, path)) : (_) => set(base, path, _p.input); | ||
refit(); | ||
@@ -188,24 +227,22 @@ return (_) => { | ||
// src/base.js | ||
// src/Base.js | ||
var Base = class { | ||
constructor() { | ||
const priv = register(this); | ||
const init = this.init.bind(this); | ||
Object.defineProperties(this, { | ||
state: { enumerable: true, get: (_) => priv.state }, | ||
debug: { enumerable: true, get: (_) => priv.debug }, | ||
init: { value: (...args) => { | ||
if (priv.state !== "pending") { | ||
this.throw("init", `state must be 'pending' insted is '${priv.state}'`); | ||
constructor(onInit) { | ||
const _p = register(this); | ||
const props = { | ||
error: { enumerable: true, get: (_) => _p.error }, | ||
state: { enumerable: true, get: (_) => _p.state }, | ||
stateCode: { enumerable: true, get: (_) => _p.stateCode }, | ||
debug: { enumerable: true, get: (_) => _p.debug, set: (v) => _p.debug = Boolean.jet.to(debug) } | ||
}; | ||
Object.defineProperties(this, props); | ||
_p.onInit = (options, closure) => { | ||
const image = Object.defineProperties({}, props); | ||
for (const i in Object.getOwnPropertyDescriptors(Base.prototype)) { | ||
if (i !== "constructor") { | ||
image[i] = Base.prototype[i].bind(this); | ||
} | ||
priv.state = "initializing"; | ||
if (!priv.config) { | ||
return init(...args); | ||
} | ||
if (args.length) { | ||
this.throw("init", "arguments was predefined with config()"); | ||
} | ||
return init(...priv.config); | ||
} } | ||
}); | ||
} | ||
return onInit(image, options, closure); | ||
}; | ||
} | ||
@@ -220,17 +257,8 @@ log(...msg) { | ||
} | ||
config(...args) { | ||
config(this, ...args); | ||
return this; | ||
config(options) { | ||
return config(this, options); | ||
} | ||
init(debug = false) { | ||
const priv = use(this); | ||
priv.debug = Boolean.jet.to(debug); | ||
priv.state = "ready"; | ||
return this; | ||
init(options) { | ||
return init(this, options); | ||
} | ||
autoInit() { | ||
if (this.state === "pending") { | ||
return this.init(); | ||
} | ||
} | ||
is(path, value) { | ||
@@ -240,13 +268,13 @@ return get(this, path) === value; | ||
isType(path, type, strict = true) { | ||
return jet3.is(type, get(this, path), strict); | ||
return jet4.is(type, get(this, path), strict); | ||
} | ||
isFull(path) { | ||
return jet3.isFull(get(this, path)); | ||
return jet4.isFull(get(this, path)); | ||
} | ||
get(path, def) { | ||
const v = get(this, path); | ||
return v != null ? jet3.copy(v, true) : def; | ||
return v != null ? jet4.copy(v, true) : def; | ||
} | ||
getType(path, strict = true) { | ||
return jet3(get(this, path), strict); | ||
return jet4(get(this, path), strict); | ||
} | ||
@@ -268,3 +296,3 @@ set(path, value) { | ||
const value = this.get(path); | ||
this.remove(path); | ||
set(this, path); | ||
return value; | ||
@@ -279,3 +307,3 @@ } | ||
fitTo(path, type, ...args) { | ||
return addFit(this, path, (next, v, f) => jet3.to(type, next(v, f), ...args)); | ||
return addFit(this, path, (next, v, f) => jet4.to(type, next(v, f), ...args)); | ||
} | ||
@@ -285,7 +313,7 @@ fitType(path, type, strict = true) { | ||
v = next(v, f); | ||
return jet3.is(type, v, strict) ? v : jet3.create(type); | ||
return jet4.is(type, v, strict) ? v : jet4.create(type); | ||
}); | ||
} | ||
setDefault(path, value, fullDetect = true) { | ||
const isFull = fullDetect ? jet3.isFull : (v) => v != null; | ||
const isFull = fullDetect ? jet4.isFull : (v) => v != null; | ||
return addFit(this, path, (next, v, f) => isFull(next(v, f)) ? v : value); | ||
@@ -300,133 +328,159 @@ } | ||
}; | ||
var base_default = Base; | ||
var Base_default = Base; | ||
// src/sync.js | ||
var BaseSync = class extends base_default { | ||
// src/BaseSync.js | ||
var BaseSync = class extends Base_default { | ||
constructor(onInit) { | ||
super((base, options, closure) => { | ||
if (!jet.isRunnable(onInit)) { | ||
return closure(true); | ||
} | ||
try { | ||
onInit(base, options); | ||
} catch (e) { | ||
return closure(false, e); | ||
} | ||
return closure(true); | ||
}); | ||
} | ||
is(path, value) { | ||
this.autoInit(); | ||
autoInit(this); | ||
return super.is(path, value); | ||
} | ||
isType(path, type, strict = true) { | ||
this.autoInit(); | ||
autoInit(this); | ||
return super.isType(path, type, strict); | ||
} | ||
isFull(path) { | ||
this.autoInit(); | ||
autoInit(this); | ||
return super.isFull(path); | ||
} | ||
get(path, def) { | ||
this.autoInit(); | ||
autoInit(this, true); | ||
return super.get(path, def); | ||
} | ||
getType(path, strict = true) { | ||
this.autoInit(); | ||
autoInit(this); | ||
return super.getType(path, strict); | ||
} | ||
set(path, value) { | ||
this.autoInit(); | ||
autoInit(this); | ||
return super.set(path, value); | ||
} | ||
remove(path) { | ||
this.autoInit(); | ||
autoInit(this); | ||
return super.remove(path); | ||
} | ||
pull(path) { | ||
this.autoInit(); | ||
autoInit(this); | ||
return super.pull(path); | ||
} | ||
watch(path, fce, initRun = false) { | ||
this.autoInit(); | ||
autoInit(this, true); | ||
return super.watch(path, fce, initRun); | ||
} | ||
fit(path, fce) { | ||
this.autoInit(); | ||
autoInit(this); | ||
return super.fit(path, fce); | ||
} | ||
fitTo(path, type, ...args) { | ||
this.autoInit(); | ||
autoInit(this); | ||
return super.fitTo(path, type, ...args); | ||
} | ||
fitType(path, type, strict = true) { | ||
this.autoInit(); | ||
autoInit(this); | ||
return super.fitType(path, type, strict); | ||
} | ||
setDefault(path, value, fullDetect = true) { | ||
this.autoInit(); | ||
autoInit(this); | ||
return super.setDefault(path, value, fullDetect); | ||
} | ||
setLock(path, value) { | ||
this.autoInit(); | ||
autoInit(this); | ||
return super.setLock(path, value); | ||
} | ||
}; | ||
var sync_default = BaseSync; | ||
var BaseSync_default = BaseSync; | ||
// src/async.js | ||
var BaseAsync = class extends base_default { | ||
// src/BaseAsync.js | ||
var BaseAsync = class extends Base_default { | ||
constructor(onInit) { | ||
super(async (image, options, closure) => { | ||
if (!jet.isRunnable(onInit)) { | ||
return closure(true); | ||
} | ||
try { | ||
await onInit(image, options); | ||
} catch (e) { | ||
return closure(false, e); | ||
} | ||
return closure(true); | ||
}); | ||
} | ||
async is(path, value) { | ||
await this.autoInit(); | ||
await autoInit(this); | ||
return super.is(path, value); | ||
} | ||
async isType(path, type, strict = true) { | ||
await this.autoInit(); | ||
await autoInit(this, true); | ||
return super.isType(path, type, strict); | ||
} | ||
async isFull(path) { | ||
await this.autoInit(); | ||
await autoInit(this, true); | ||
return super.isFull(path); | ||
} | ||
async get(path, def) { | ||
await this.autoInit(); | ||
await autoInit(this, true); | ||
return super.get(path, def); | ||
} | ||
async getType(path, strict = true) { | ||
await this.autoInit(); | ||
await autoInit(this, true); | ||
return super.getType(path, strict); | ||
} | ||
async set(path, value) { | ||
await this.autoInit(); | ||
await autoInit(this); | ||
return super.set(path, value); | ||
} | ||
async remove(path) { | ||
await this.autoInit(); | ||
await autoInit(this); | ||
return super.remove(path); | ||
} | ||
async pull(path) { | ||
await this.autoInit(); | ||
await autoInit(this); | ||
return super.pull(path); | ||
} | ||
async watch(path, fce, initRun = false) { | ||
await this.autoInit(); | ||
await autoInit(this, true); | ||
return super.watch(path, fce, initRun); | ||
} | ||
async fit(path, fce) { | ||
await this.autoInit(); | ||
await autoInit(this); | ||
return super.fit(path, fce); | ||
} | ||
async fitTo(path, type, ...args) { | ||
await this.autoInit(); | ||
await autoInit(this); | ||
return super.fitTo(path, type, ...args); | ||
} | ||
async fitType(path, type, strict = true) { | ||
await this.autoInit(); | ||
await autoInit(this); | ||
return super.fitType(path, type, strict); | ||
} | ||
async setDefault(path, value, fullDetect = true) { | ||
await this.autoInit(); | ||
await autoInit(this); | ||
return super.setDefault(path, value, fullDetect); | ||
} | ||
async setLock(path, value) { | ||
await this.autoInit(); | ||
await autoInit(this); | ||
return super.setLock(path, value); | ||
} | ||
}; | ||
var async_default = BaseAsync; | ||
var BaseAsync_default = BaseAsync; | ||
// src/index.js | ||
var src_default = { BaseSync: sync_default, BaseAsync: async_default }; | ||
var src_default = { BaseSync: BaseSync_default, BaseAsync: BaseAsync_default }; | ||
export { | ||
async_default as BaseAsync, | ||
sync_default as BaseSync, | ||
BaseAsync_default as BaseAsync, | ||
BaseSync_default as BaseSync, | ||
src_default as default | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@randajan/jet-base", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Ecosystem of types and related usefull tools.", | ||
@@ -5,0 +5,0 @@ "repository": "randajan/jet-base", |
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
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
42414
462