Comparing version 10.0.2 to 11.0.0
611
lib/main.js
(function() { | ||
'use strict'; | ||
var CND, Cupofjoe, Datom, MAIN, Multimix, assign, badge, debug, defaults, echo, help, info, isa, jr, letsfreezethat, letsfreezethat_nofreeze, p1, p2, rpr, type_of, urge, validate, warn, whisper, | ||
var Datom, GUY, MAIN, alert, assign, debug, echo, get_base_types, help, info, inspect, letsfreezethat, letsfreezethat_nofreeze, log, p1, p2, plain, praise, rpr, urge, warn, whisper, | ||
indexOf = [].indexOf; | ||
//########################################################################################################### | ||
CND = require('cnd'); | ||
GUY = require('guy'); | ||
rpr = CND.rpr; | ||
({alert, debug, help, info, plain, praise, urge, warn, whisper} = GUY.trm.get_loggers('DATOM')); | ||
badge = 'DATOM/MAIN'; | ||
({rpr, inspect, echo, log} = GUY.trm); | ||
debug = CND.get_logger('debug', badge); | ||
({assign} = Object); | ||
warn = CND.get_logger('warn', badge); | ||
//........................................................................................................... | ||
({get_base_types} = require('./types')); | ||
info = CND.get_logger('info', badge); | ||
letsfreezethat = require('letsfreezethat'); | ||
urge = CND.get_logger('urge', badge); | ||
letsfreezethat_nofreeze = require('letsfreezethat/nofreeze'); | ||
help = CND.get_logger('help', badge); | ||
//=========================================================================================================== | ||
// SELECT | ||
//----------------------------------------------------------------------------------------------------------- | ||
p1 = /^(?<skey>(?<sigil>[<^>\[~\]\x23])(?<key>[^<^>\[~\]\x23]*))$/u; // `\x23` used instead of `\#` which causes syntax error (???) | ||
whisper = CND.get_logger('whisper', badge); | ||
p2 = /^(?<skey>(?<sigil>[<^>\[~\]\x23])(?<key>[^<^>\[~\]\x23]*))\x23(?<attribute>[^<^>\[~\]\x23]+):(?<value>[^<^>\[~\]\x23]+)$/u; // `\x23` used instead of `\#` which causes syntax error (???) | ||
echo = CND.echo.bind(CND); | ||
//=========================================================================================================== | ||
// EXPORT | ||
//----------------------------------------------------------------------------------------------------------- | ||
MAIN = this; | ||
({assign, jr} = CND); | ||
Datom = class Datom { | ||
//--------------------------------------------------------------------------------------------------------- | ||
constructor(cfg = null) { | ||
//--------------------------------------------------------------------------------------------------------- | ||
this.lets = this.lets.bind(this); | ||
//--------------------------------------------------------------------------------------------------------- | ||
this.set = this.set.bind(this); | ||
//--------------------------------------------------------------------------------------------------------- | ||
this.unset = this.unset.bind(this); | ||
//--------------------------------------------------------------------------------------------------------- | ||
this.stamp = this.stamp.bind(this); | ||
//--------------------------------------------------------------------------------------------------------- | ||
this.unstamp = this.unstamp.bind(this); | ||
//--------------------------------------------------------------------------------------------------------- | ||
this.is_system = this.is_system.bind(this); | ||
//--------------------------------------------------------------------------------------------------------- | ||
this.is_stamped = this.is_stamped.bind(this); | ||
this.is_fresh = this.is_fresh.bind(this); | ||
this.is_dirty = this.is_dirty.bind(this); | ||
this.is_datom = this.is_datom.bind(this); | ||
//--------------------------------------------------------------------------------------------------------- | ||
this.new_datom = this.new_datom.bind(this); | ||
//--------------------------------------------------------------------------------------------------------- | ||
this._new_datom = this._new_datom.bind(this); | ||
//--------------------------------------------------------------------------------------------------------- | ||
this.fresh_datom = this.fresh_datom.bind(this); | ||
//--------------------------------------------------------------------------------------------------------- | ||
this.wrap_datom = this.wrap_datom.bind(this); | ||
//--------------------------------------------------------------------------------------------------------- | ||
this.new_single_datom = this.new_single_datom.bind(this); | ||
this.new_open_datom = this.new_open_datom.bind(this); | ||
this.new_close_datom = this.new_close_datom.bind(this); | ||
this.new_system_datom = this.new_system_datom.bind(this); | ||
this.new_text_datom = this.new_text_datom.bind(this); | ||
// @new_flush_datom = -> @new_system_datom 'flush' | ||
//........................................................................................................... | ||
Multimix = require('multimix'); | ||
//--------------------------------------------------------------------------------------------------------- | ||
this.new_warning = this.new_warning.bind(this); | ||
//========================================================================================================= | ||
this.types = require('./types'); | ||
//--------------------------------------------------------------------------------------------------------- | ||
/* TAINT likely to be removed */ | ||
this.new_xemitter = this.new_xemitter.bind(this); | ||
//========================================================================================================= | ||
({isa, validate, defaults, type_of} = this.types); | ||
//--------------------------------------------------------------------------------------------------------- | ||
this.select = this.select.bind(this); | ||
// super() | ||
this.types = get_base_types(); | ||
this.cfg = letsfreezethat.freeze(this.types.create.datom_constructor_cfg(cfg)); | ||
this.LFT = this.cfg.freeze ? letsfreezethat : letsfreezethat_nofreeze; | ||
this.freeze = this.LFT.freeze; | ||
this.thaw = this.LFT.thaw; | ||
return void 0; | ||
} | ||
({Cupofjoe} = require('cupofjoe')); | ||
letsfreezethat = require('letsfreezethat'); | ||
letsfreezethat_nofreeze = require('letsfreezethat/nofreeze'); | ||
//----------------------------------------------------------------------------------------------------------- | ||
this.lets = function(original, modifier) { | ||
var draft; | ||
draft = this.thaw(original); | ||
if (modifier != null) { | ||
modifier(draft); | ||
/* TAINT simplify logic by rewriting as single term without double negatives */ | ||
if (this.settings.dirty) { | ||
if (draft.$dirty === original.dirty) { | ||
draft.$dirty = true; | ||
lets(original, modifier) { | ||
var draft; | ||
draft = this.thaw(original); | ||
if (modifier != null) { | ||
modifier(draft); | ||
/* TAINT simplify logic by rewriting as single term without double negatives */ | ||
if (this.cfg.dirty) { | ||
if (draft.$dirty === original.dirty) { | ||
draft.$dirty = true; | ||
} | ||
} | ||
} | ||
return this.freeze(draft); | ||
} | ||
return this.freeze(draft); | ||
}; | ||
//----------------------------------------------------------------------------------------------------------- | ||
this.set = function(d, k, ...P) { | ||
var count; | ||
if (isa.text(k)) { | ||
if ((count = P.length) !== 1) { | ||
throw new Error(`µ67663 expected 1 value got ${count}`); | ||
set(d, k, ...P) { | ||
var count; | ||
if (this.types.isa.text(k)) { | ||
if ((count = P.length) !== 1) { | ||
throw new Error(`µ67663 expected 1 value got ${count}`); | ||
} | ||
return this.lets(d, function(d) { | ||
return d[k] = P[0]; | ||
}); | ||
} | ||
return this.lets(d, function(d) { | ||
return d[k] = P[0]; | ||
var ref1, results, v; | ||
ref1 = assign({}, k, ...P); | ||
results = []; | ||
for (k in ref1) { | ||
v = ref1[k]; | ||
results.push(d[k] = v); | ||
} | ||
return results; | ||
}); | ||
} | ||
return this.lets(d, function(d) { | ||
var ref1, results, v; | ||
ref1 = assign({}, k, ...P); | ||
results = []; | ||
for (k in ref1) { | ||
v = ref1[k]; | ||
results.push(d[k] = v); | ||
} | ||
return results; | ||
}); | ||
}; | ||
//----------------------------------------------------------------------------------------------------------- | ||
this.unset = function(d, k) { | ||
return this.lets(d, function(d) { | ||
return delete d[k]; | ||
}); | ||
}; | ||
unset(d, k) { | ||
return this.lets(d, function(d) { | ||
return delete d[k]; | ||
}); | ||
} | ||
//----------------------------------------------------------------------------------------------------------- | ||
this.stamp = function(d, ...P) { | ||
/* Set the `$stamped` attribute on datom to sigil it as processed. Stamped datoms will not be selected | ||
by the `select` method unless tag '#stamped' is used. */ | ||
return this.lets(d, function(d) { | ||
return assign(d, ...P, { | ||
$stamped: true | ||
stamp(d, ...P) { | ||
/* Set the `$stamped` attribute on datom to sigil it as processed. Stamped datoms will not be selected | ||
by the `select` method unless tag '#stamped' is used. */ | ||
return this.lets(d, function(d) { | ||
return assign(d, ...P, { | ||
$stamped: true | ||
}); | ||
}); | ||
}); | ||
}; | ||
} | ||
//----------------------------------------------------------------------------------------------------------- | ||
this.unstamp = function(d) { | ||
if (!d.$stamped) { | ||
return d; | ||
unstamp(d) { | ||
if (!d.$stamped) { | ||
return d; | ||
} | ||
return this.lets(d, function(d) { | ||
return delete d.$stamped; | ||
}); | ||
} | ||
return this.lets(d, function(d) { | ||
return delete d.$stamped; | ||
}); | ||
}; | ||
//----------------------------------------------------------------------------------------------------------- | ||
this.is_system = function(d) { | ||
/* Return whether datom is a system datom (i.e. whether its `sigil` equals `'~'`). */ | ||
return d.$key.match(/^[~\[\]]/); | ||
}; | ||
is_system(d) { | ||
/* Return whether datom is a system datom (i.e. whether its `sigil` equals `'~'`). */ | ||
return d.$key.match(/^[~\[\]]/); | ||
} | ||
//----------------------------------------------------------------------------------------------------------- | ||
this.is_stamped = function(d) { | ||
var ref1; | ||
return (ref1 = d.$stamped) != null ? ref1 : false/* i.e. already processed? */; | ||
}; | ||
is_stamped(d) { | ||
var ref1; | ||
return (ref1 = d.$stamped) != null ? ref1 : false/* i.e. already processed? */; | ||
} | ||
this.is_fresh = function(d) { | ||
var ref1; | ||
return (ref1 = d.$fresh) != null ? ref1 : false/* i.e. created within stream? */; | ||
}; | ||
is_fresh(d) { | ||
var ref1; | ||
return (ref1 = d.$fresh) != null ? ref1 : false/* i.e. created within stream? */; | ||
} | ||
this.is_dirty = function(d) { | ||
var ref1; | ||
return (ref1 = d.$dirty) != null ? ref1 : false/* i.e. modified? */; | ||
}; | ||
is_dirty(d) { | ||
var ref1; | ||
return (ref1 = d.$dirty) != null ? ref1 : false/* i.e. modified? */; | ||
} | ||
this.is_datom = function(x) { | ||
return isa.datom_datom(x); | ||
}; | ||
is_datom(x) { | ||
return this.types.isa.datom_datom(x); | ||
} | ||
//----------------------------------------------------------------------------------------------------------- | ||
this.new_datom = function($key, $value, ...other) { | ||
/* When `other` contains a key `$`, it is treated as a hint to copy | ||
system-level attributes; if the value of key `$` is a POD that has itself a | ||
key `$`, then a copy of that value is used. This allows to write `new_datom | ||
..., $: d` to copy system-level attributes such as source locations to a new | ||
datom. */ | ||
validate.datom_key($key); | ||
return this._new_datom($key, $value, ...other); | ||
}; | ||
new_datom($key, $value, ...other) { | ||
/* When `other` contains a key `$`, it is treated as a hint to copy | ||
system-level attributes; if the value of key `$` is a POD that has itself a | ||
key `$`, then a copy of that value is used. This allows to write `new_datom | ||
..., $: d` to copy system-level attributes such as source locations to a new | ||
datom. */ | ||
this.types.validate.datom_key($key); | ||
return this._new_datom($key, $value, ...other); | ||
} | ||
//----------------------------------------------------------------------------------------------------------- | ||
this._new_datom = function($key, $value, ...other) { | ||
var R; | ||
if ($value != null) { | ||
if ((!this.settings.merge_values) || (!isa.object($value))) { | ||
$value = {$value}; | ||
_new_datom($key, $value, ...other) { | ||
var R; | ||
if ($value != null) { | ||
if ((!this.cfg.merge_values) || (!this.types.isa.object($value))) { | ||
$value = {$value}; | ||
} | ||
if (indexOf.call(Object.keys($value), '$key') >= 0) { | ||
throw new Error("µ55632 value must not have attribute '$key'"); | ||
} | ||
R = assign({}, $value, ...other, {$key}); | ||
} else { | ||
R = assign({}, ...other, {$key}); | ||
} | ||
if (indexOf.call(Object.keys($value), '$key') >= 0) { | ||
throw new Error("µ55632 value must not have attribute '$key'"); | ||
while ((this.types.isa.object(R.$)) && (this.types.isa.object(R.$.$))) { | ||
R.$ = this.LFT._deep_copy(R.$.$); | ||
} | ||
R = assign({}, $value, ...other, {$key}); | ||
} else { | ||
R = assign({}, ...other, {$key}); | ||
return this.freeze(R); | ||
} | ||
while ((isa.object(R.$)) && (isa.object(R.$.$))) { | ||
R.$ = this.LFT._deep_copy(R.$.$); | ||
fresh_datom(...P) { | ||
return this.new_datom(...P, { | ||
$fresh: true | ||
}); | ||
} | ||
return this.freeze(R); | ||
}; | ||
//----------------------------------------------------------------------------------------------------------- | ||
this.fresh_datom = function(...P) { | ||
return this.new_datom(...P, { | ||
$fresh: true | ||
}); | ||
}; | ||
wrap_datom($key, $value) { | ||
this.types.validate.datom_key($key); | ||
this.types.validate.datom_datom($value); | ||
return this.freeze({$key, $value}); | ||
} | ||
//----------------------------------------------------------------------------------------------------------- | ||
this.wrap_datom = function($key, $value) { | ||
validate.datom_key($key); | ||
validate.datom_datom($value); | ||
return this.freeze({$key, $value}); | ||
}; | ||
new_single_datom(name, ...P) { | ||
this.types.validate.datom_name(name); | ||
return this._new_datom(`^${name}`, ...P); | ||
} | ||
//----------------------------------------------------------------------------------------------------------- | ||
this.new_single_datom = function(name, ...P) { | ||
validate.datom_name(name); | ||
return this._new_datom(`^${name}`, ...P); | ||
}; | ||
new_open_datom(name, ...P) { | ||
this.types.validate.datom_name(name); | ||
return this.new_datom(`<${name}`, ...P); | ||
} | ||
this.new_open_datom = function(name, ...P) { | ||
validate.datom_name(name); | ||
return this.new_datom(`<${name}`, ...P); | ||
}; | ||
new_close_datom(name, ...P) { | ||
this.types.validate.datom_name(name); | ||
return this.new_datom(`>${name}`, ...P); | ||
} | ||
this.new_close_datom = function(name, ...P) { | ||
validate.datom_name(name); | ||
return this.new_datom(`>${name}`, ...P); | ||
}; | ||
new_system_datom(name, ...P) { | ||
this.types.validate.datom_name(name); | ||
return this.new_datom(`~${name}`, ...P); | ||
} | ||
this.new_system_datom = function(name, ...P) { | ||
validate.datom_name(name); | ||
return this.new_datom(`~${name}`, ...P); | ||
}; | ||
new_text_datom(...P) { | ||
return this.new_single_datom('text', ...P); | ||
} | ||
this.new_text_datom = function(...P) { | ||
return this.new_single_datom('text', ...P); | ||
}; | ||
new_end_datom() { | ||
return this.new_system_datom('end'); | ||
} | ||
this.new_end_datom = function() { | ||
return this.new_system_datom('end'); | ||
}; | ||
new_warning(ref, message, d, ...other) { | ||
return this.new_system_datom('warning', d, {ref, message}, ...other); | ||
} | ||
// @new_flush_datom = -> @new_system_datom 'flush' | ||
//----------------------------------------------------------------------------------------------------------- | ||
this.new_warning = function(ref, message, d, ...other) { | ||
return this.new_system_datom('warning', d, {ref, message}, ...other); | ||
}; | ||
//=========================================================================================================== | ||
// SELECT | ||
//----------------------------------------------------------------------------------------------------------- | ||
p1 = /^(?<skey>(?<sigil>[<^>\[~\]\x23])(?<key>[^<^>\[~\]\x23]*))$/u; // `\x23` used instead of `\#` which causes syntax error (???) | ||
p2 = /^(?<skey>(?<sigil>[<^>\[~\]\x23])(?<key>[^<^>\[~\]\x23]*))\x23(?<attribute>[^<^>\[~\]\x23]+):(?<value>[^<^>\[~\]\x23]+)$/u; // `\x23` used instead of `\#` which causes syntax error (???) | ||
//----------------------------------------------------------------------------------------------------------- | ||
this.select = function(d, selector) { | ||
var g, k, match, ref1, ref2, ref3, ref4, stamped_values, v; | ||
if (selector == null) { | ||
throw new Error("µ86606 expected a selector, got none"); | ||
new_xemitter(...P) { | ||
return new (require('./xemitter')).Xemitter(...P); | ||
} | ||
if (!((isa.object(d)) && (d.$key != null))) { | ||
return false; | ||
} | ||
//......................................................................................................... | ||
if ((match = (ref1 = selector.match(p2)) != null ? ref1 : selector.match(p1)) == null) { | ||
throw new Error(`µ37799 illegal selector ${rpr(selector)}`); | ||
} | ||
g = {}; | ||
ref2 = match.groups; | ||
for (k in ref2) { | ||
v = ref2[k]; | ||
if (v !== '') { | ||
g[k] = v; | ||
} | ||
} | ||
if ((g.attribute != null) && (g.attribute !== 'stamped')) { | ||
throw new Error(`µ77764 unknown attribute name ${rpr(g.attribute)}`); | ||
} | ||
switch (g.value) { | ||
case void 0: | ||
stamped_values = [false]; | ||
break; | ||
case '*': | ||
stamped_values = [true, false]; | ||
break; | ||
case 'true': | ||
stamped_values = [true]; | ||
break; | ||
case 'false': | ||
stamped_values = [false]; | ||
break; | ||
default: | ||
throw new Error(`µ33366 illegal attribute or value in selector ${rpr(selector)}`); | ||
} | ||
if (ref3 = (ref4 = d.$stamped) != null ? ref4 : false, indexOf.call(stamped_values, ref3) < 0) { | ||
//......................................................................................................... | ||
return false; | ||
} | ||
if (g.key != null) { | ||
return d.$key === g.skey; | ||
} | ||
if (!d.$key.startsWith(g.sigil)) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
//=========================================================================================================== | ||
//----------------------------------------------------------------------------------------------------------- | ||
this.Cupofdatom = (function() { | ||
class Cupofdatom extends Cupofjoe { | ||
//--------------------------------------------------------------------------------------------------------- | ||
constructor(settings) { | ||
var base; | ||
super(settings); | ||
this.settings = Object.assign(this._defaults, this.settings); | ||
this.DATOM = (base = this.settings).DATOM != null ? base.DATOM : base.DATOM = module.exports; | ||
delete this.settings.DATOM; | ||
select(d, selector) { | ||
var g, k, match, ref1, ref2, ref3, ref4, stamped_values, v; | ||
if (selector == null) { | ||
throw new Error("µ86606 expected a selector, got none"); | ||
} | ||
//--------------------------------------------------------------------------------------------------------- | ||
_analyze(name, tail) { | ||
/* NOTE to be overriden by derivatives as seen necessary */ | ||
var attributes, content, i, idx, len, part, type; | ||
attributes = []; | ||
content = []; | ||
for (idx = i = 0, len = tail.length; i < len; idx = ++i) { | ||
part = tail[idx]; | ||
switch (type = type_of(part)) { | ||
case 'object': | ||
attributes.push(part); | ||
break; | ||
case 'function': | ||
content.push(part); | ||
break; | ||
case /* NOTE always leave as-is, expanded by Cupofjoe */'text': | ||
content.push(this.DATOM.new_single_datom('text', { | ||
text: part, | ||
$: '^ð1^' | ||
})); | ||
break; | ||
default: | ||
content.push(this.DATOM.new_single_datom('value', { | ||
$value: part, | ||
$: '^ð2^' | ||
})); | ||
} | ||
if (!((this.types.isa.object(d)) && (d.$key != null))) { | ||
return false; | ||
} | ||
//....................................................................................................... | ||
if ((match = (ref1 = selector.match(p2)) != null ? ref1 : selector.match(p1)) == null) { | ||
throw new Error(`µ37799 illegal selector ${rpr(selector)}`); | ||
} | ||
g = {}; | ||
ref2 = match.groups; | ||
for (k in ref2) { | ||
v = ref2[k]; | ||
if (v !== '') { | ||
g[k] = v; | ||
} | ||
return {name, attributes, content}; | ||
} | ||
//--------------------------------------------------------------------------------------------------------- | ||
_cram(...P) { | ||
return super.cram(...P); | ||
if ((g.attribute != null) && (g.attribute !== 'stamped')) { | ||
throw new Error(`µ77764 unknown attribute name ${rpr(g.attribute)}`); | ||
} | ||
//--------------------------------------------------------------------------------------------------------- | ||
cram(name, ...tail) { | ||
var attributes, content, d1, d2, has_attributes, v; | ||
// XXX_SUPER = @Cupofjoe. | ||
({name, attributes, content} = this._analyze(name, tail)); | ||
has_attributes = false; | ||
switch (g.value) { | ||
case void 0: | ||
stamped_values = [false]; | ||
break; | ||
case '*': | ||
stamped_values = [true, false]; | ||
break; | ||
case 'true': | ||
stamped_values = [true]; | ||
break; | ||
case 'false': | ||
stamped_values = [false]; | ||
break; | ||
default: | ||
throw new Error(`µ33366 illegal attribute or value in selector ${rpr(selector)}`); | ||
} | ||
if (ref3 = (ref4 = d.$stamped) != null ? ref4 : false, indexOf.call(stamped_values, ref3) < 0) { | ||
//....................................................................................................... | ||
if ((attributes != null) && attributes.length > 0) { | ||
has_attributes = true; | ||
attributes = Object.assign({}, ...attributes); | ||
} | ||
//....................................................................................................... | ||
if (has_attributes && name === null) { | ||
v = rpr({name, attributes, content}); | ||
throw new Error(`^datom/cupofjoe@3498^ cannot have attributes without name, got ${v}`); | ||
} | ||
//....................................................................................................... | ||
if ((content != null) && content.length > 0) { | ||
if (name === null) { | ||
return super.cram(...content); | ||
} | ||
if (has_attributes) { | ||
d1 = this.DATOM.new_open_datom(name, attributes, { | ||
$: '^ð3^' | ||
}); | ||
d2 = this.DATOM.new_close_datom(name, attributes, { | ||
$: '^ð4^' | ||
}); | ||
} else { | ||
d1 = this.DATOM.new_open_datom(name, { | ||
$: '^ð5^' | ||
}); | ||
d2 = this.DATOM.new_close_datom(name, { | ||
$: '^ð6^' | ||
}); | ||
} | ||
return super.cram(d1, ...content, d2); | ||
} | ||
//....................................................................................................... | ||
if (has_attributes) { | ||
return super.cram(this.DATOM.new_single_datom(name, attributes, { | ||
$: '^ð7^' | ||
})); | ||
} | ||
if (name !== null) { | ||
return super.cram(this.DATOM.new_single_datom(name, { | ||
$: '^ð8^' | ||
})); | ||
} | ||
return null; | ||
return false; | ||
} | ||
if (g.key != null) { | ||
return d.$key === g.skey; | ||
} | ||
if (!d.$key.startsWith(g.sigil)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
}; | ||
}; | ||
Cupofdatom.prototype._defaults = { | ||
flatten: true, | ||
DATOM: null | ||
}; | ||
return Cupofdatom; | ||
}).call(this); | ||
//=========================================================================================================== | ||
// EXPORT | ||
//----------------------------------------------------------------------------------------------------------- | ||
MAIN = this; | ||
module.exports = { | ||
Datom, | ||
DATOM: new Datom() | ||
}; | ||
Datom = (function() { | ||
class Datom extends Multimix { | ||
// @include ( require './cachewalker.mixin' ), { overwrite: false, } | ||
// @include ( require './_temp_svgttf' ), { overwrite: false, } ### !!!!!!!!!!!!!!!!!!!!!!!!!!! ### | ||
// @extend MAIN, { overwrite: false, } | ||
//--------------------------------------------------------------------------------------------------------- | ||
constructor(settings = null) { | ||
super(); | ||
validate.datom_settings(settings = {...defaults.settings, ...settings}); | ||
this.LFT = settings.freeze ? letsfreezethat : letsfreezethat_nofreeze; | ||
this.freeze = this.LFT.freeze; | ||
this.thaw = this.LFT.thaw; | ||
this.settings = this.freeze(settings); | ||
this.Datom = Datom; | ||
return this; | ||
} | ||
}; | ||
Datom.include(MAIN, { | ||
overwrite: false | ||
}); | ||
Datom.include(require('./xemitter.mixin'), { | ||
overwrite: false | ||
}); | ||
return Datom; | ||
}).call(this); | ||
module.exports = new Datom(); | ||
}).call(this); | ||
//# sourceMappingURL=main.js.map |
199
lib/types.js
(function() { | ||
'use strict'; | ||
var CND, Intertype, alert, badge, debug, help, info, intertype, jr, rpr, urge, warn, whisper, | ||
indexOf = [].indexOf; | ||
var GUY, Intertype, base_types, debug, echo, get_base_types, get_xemitter_types, inspect, log, misfit, rpr, xemitter_types; | ||
//########################################################################################################### | ||
CND = require('cnd'); | ||
GUY = require('guy'); | ||
rpr = CND.rpr; | ||
// { alert | ||
// debug | ||
// help | ||
// info | ||
// plain | ||
// praise | ||
// urge | ||
// warn | ||
// whisper } = GUY.trm.get_loggers 'DATOM/TYPES' | ||
({debug} = GUY.trm.get_loggers('DATOM/TYPES')); | ||
badge = 'DATOM/TYPES'; | ||
({rpr, inspect, echo, log} = GUY.trm); | ||
debug = CND.get_logger('debug', badge); | ||
({Intertype} = require('intertype')); | ||
alert = CND.get_logger('alert', badge); | ||
base_types = null; | ||
whisper = CND.get_logger('whisper', badge); | ||
xemitter_types = null; | ||
warn = CND.get_logger('warn', badge); | ||
misfit = Symbol('misfit'); | ||
help = CND.get_logger('help', badge); | ||
urge = CND.get_logger('urge', badge); | ||
info = CND.get_logger('info', badge); | ||
jr = JSON.stringify; | ||
Intertype = (require('intertype')).Intertype; | ||
intertype = new Intertype(module.exports); | ||
//----------------------------------------------------------------------------------------------------------- | ||
this.declare('datom_settings', { | ||
tests: { | ||
"x is a object": function(x) { | ||
return this.isa.object(x); | ||
get_base_types = function() { | ||
var declare; | ||
if (base_types != null) { | ||
return base_types; | ||
} | ||
//......................................................................................................... | ||
base_types = new Intertype(); | ||
({declare} = base_types); | ||
//......................................................................................................... | ||
declare.datom_constructor_cfg({ | ||
fields: { | ||
merge_values: 'boolean', | ||
freeze: 'boolean', | ||
dirty: 'boolean' | ||
}, | ||
"x.merge_values is a ?boolean": function(x) { | ||
return (x.merge_values == null) || this.isa.boolean(x.merge_values); | ||
}, | ||
"x.freeze is a ?boolean": function(x) { | ||
return (x.freeze == null) || this.isa.boolean(x.freeze); | ||
/* TAINT ??? to be removed ??? */default: { | ||
merge_values: true, | ||
freeze: true, | ||
dirty: false | ||
} | ||
} | ||
}); | ||
//----------------------------------------------------------------------------------------------------------- | ||
this.declare('datom_nonempty_list_of_positive_integers', function(x) { | ||
if (!this.isa.nonempty_list(x)) { | ||
return false; | ||
} | ||
return x.every((xx) => { | ||
return this.isa.positive_integer(xx); | ||
}); | ||
}); | ||
//----------------------------------------------------------------------------------------------------------- | ||
this.declare('datom_sigil', { | ||
tests: { | ||
"x is a chr": function(x) { | ||
return this.isa.chr(x); | ||
}, | ||
"x has sigil": function(x) { | ||
return indexOf.call('^<>~[]', x) >= 0; | ||
//......................................................................................................... | ||
/* TAINT ??? to be removed ??? */ declare.datom_sigil(function(x) { | ||
return x === '^' || x === '<' || x === '>' || x === '~' || x === '[' || x === ']'; | ||
}); | ||
//......................................................................................................... | ||
declare.datom_key(function(x) { | ||
if (!this.isa.text(x)) { | ||
return false; | ||
} | ||
} | ||
}); | ||
//----------------------------------------------------------------------------------------------------------- | ||
this.declare('datom_key', { | ||
tests: { | ||
"x is a text": function(x) { | ||
return this.isa.text(x); | ||
}, | ||
"x has at least 2 chrs": function(x) { | ||
return x.length > 1; | ||
}, | ||
"x has sigil": function(x) { | ||
return this.isa.datom_sigil(x[0]); | ||
if (!((Array.from(x)).length >= 2)) { | ||
return false; | ||
} | ||
} | ||
}); | ||
//----------------------------------------------------------------------------------------------------------- | ||
this.declare('datom_name', { | ||
tests: { | ||
"x is a nonempty text": function(x) { | ||
return this.isa.nonempty_text(x); | ||
return this.isa.datom_sigil(x[0]); | ||
}); | ||
//......................................................................................................... | ||
declare.datom_name('nonempty.text'); | ||
//......................................................................................................... | ||
declare.datom_vnr(function(x) { | ||
if (x == null) { | ||
return true; | ||
} | ||
} | ||
}); | ||
//----------------------------------------------------------------------------------------------------------- | ||
this.declare('datom_datom', { | ||
tests: { | ||
"x is a object": function(x) { | ||
return this.isa.object(x); | ||
if (!this.isa.list(x)) { | ||
return false; | ||
} | ||
if (!(x.length > 0)) { | ||
return false; | ||
} | ||
return x.every((n) => { | ||
return this.isa.positive0.integer(n); | ||
}); | ||
}); | ||
//......................................................................................................... | ||
declare.datom_datom({ | ||
fields: { | ||
$key: 'datom_key', | ||
$stamped: 'optional.boolean', | ||
$dirty: 'optional.boolean', | ||
$fresh: 'optional.boolean', | ||
$vnr: 'optional.datom_vnr' | ||
}, | ||
"x.$key is a datom_key": function(x) { | ||
return this.isa.datom_key(x.$key); | ||
}, | ||
"x.$stamped is an optional boolean": function(x) { | ||
return (x.$stamped == null) || (this.isa.boolean(x.$stamped)); | ||
}, | ||
"x.$dirty is an optional boolean": function(x) { | ||
return (x.$dirty == null) || (this.isa.boolean(x.$dirty)); | ||
}, | ||
"x.$fresh is an optional boolean": function(x) { | ||
return (x.$fresh == null) || (this.isa.boolean(x.$fresh)); | ||
}, | ||
//....................................................................................................... | ||
"x.$vnr is an optional nonempty list of positive integers": function(x) { | ||
return (x.$vnr == null) || this.isa.datom_nonempty_list_of_positive_integers(x.$vnr); | ||
default: { | ||
$key: null, | ||
$stamped: null, | ||
$dirty: null, | ||
$fresh: null | ||
} | ||
} | ||
}); | ||
}); | ||
//......................................................................................................... | ||
return base_types; | ||
}; | ||
//=========================================================================================================== | ||
// DEFAULTS, CASTS | ||
//----------------------------------------------------------------------------------------------------------- | ||
this.defaults = { | ||
settings: { | ||
merge_values: true, | ||
freeze: true, | ||
dirty: false | ||
get_xemitter_types = function() { | ||
var declare; | ||
if (xemitter_types != null) { | ||
return xemitter_types; | ||
} | ||
//......................................................................................................... | ||
xemitter_types = new Intertype(get_base_types()); | ||
({declare} = xemitter_types); | ||
//......................................................................................................... | ||
declare.callable('function'); | ||
//......................................................................................................... | ||
return xemitter_types; | ||
}; | ||
//----------------------------------------------------------------------------------------------------------- | ||
this.cast = {}; | ||
//=========================================================================================================== | ||
module.exports = {misfit, get_base_types, get_xemitter_types}; | ||
@@ -133,0 +120,0 @@ }).call(this); |
{ | ||
"name": "datom", | ||
"version": "10.0.2", | ||
"version": "11.0.0", | ||
"description": "standardized immutable objects in the spirit of datomic, especially suited for use in data pipelines", | ||
@@ -26,12 +26,10 @@ "main": "lib/main.js", | ||
"dependencies": { | ||
"cnd": "9.2.2", | ||
"cupofjoe": "0.2.1", | ||
"intertype": "7.7.0", | ||
"letsfreezethat": "^3.1.0", | ||
"multimix": "5.0.0" | ||
"guy": "^12.7.0", | ||
"intertype": "0.111.0", | ||
"letsfreezethat": "^3.1.0" | ||
}, | ||
"scripts": { | ||
"build": "coffee --map -o lib -c src", | ||
"test": "echo 'see https://github.com/loveencounterflow/hengist/tree/master/dev/datom'" | ||
"test": "echo 'see https://github.com/loveencounterflow/hengist/tree/main/dev/datom'" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
3
108727
822
+ Addedguy@^12.7.0
+ Addedacorn@8.14.0(transitive)
+ Addedacorn-loose@8.4.0(transitive)
+ Addedacorn-walk@8.3.4(transitive)
+ Addedansi-regex@5.0.1(transitive)
+ Addedastring@1.9.0(transitive)
+ Addeddayjs@1.11.13(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedguy@11.12.012.10.0(transitive)
+ Addedintertype@0.111.0(transitive)
+ Addedintertype-legacy@7.7.1(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedrfdc@1.4.1(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedtmp@0.2.3(transitive)
+ Addedto-width@1.2.0(transitive)
+ Addedvarsize-string@2.2.2(transitive)
+ Addedwcsize@1.0.0(transitive)
+ Addedwcstring@2.1.1(transitive)
- Removedcnd@9.2.2
- Removedcupofjoe@0.2.1
- Removedmultimix@5.0.0
- Removedcnd@9.2.19.2.2(transitive)
- Removedcupofjoe@0.2.1(transitive)
- Removedintertype@7.6.57.7.0(transitive)
- Removedjsx-number-format@0.1.5(transitive)
Updatedintertype@0.111.0