mol_db 0.0.67 → 0.0.71
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/node.d.ts +145 -1
- package/node.deps.json +1 -1
- package/node.esm.js +704 -14
- package/node.esm.js.map +1 -1
- package/node.js +704 -14
- package/node.js.map +1 -1
- package/node.test.js +1389 -1382
- package/node.test.js.map +1 -1
- package/package.json +2 -1
- package/web.d.ts +7 -0
- package/web.deps.json +1 -1
- package/web.esm.js +15 -2
- package/web.esm.js.map +1 -1
- package/web.js +15 -2
- package/web.js.map +1 -1
- package/web.test.js +0 -13
- package/web.test.js.map +1 -1
package/node.esm.js
CHANGED
|
@@ -31,6 +31,61 @@ $node[ "../mam" ] = $node[ "../mam.js" ] = module.exports }.call( {} , {} )
|
|
|
31
31
|
;
|
|
32
32
|
"use strict";
|
|
33
33
|
var $;
|
|
34
|
+
(function ($) {
|
|
35
|
+
})($ || ($ = {}));
|
|
36
|
+
//context.js.map
|
|
37
|
+
;
|
|
38
|
+
"use strict";
|
|
39
|
+
//node.js.map
|
|
40
|
+
;
|
|
41
|
+
"use strict";
|
|
42
|
+
var $node = new Proxy({ require }, {
|
|
43
|
+
get(target, name, wrapper) {
|
|
44
|
+
if (target[name])
|
|
45
|
+
return target[name];
|
|
46
|
+
const mod = target.require('module');
|
|
47
|
+
if (mod.builtinModules.indexOf(name) >= 0)
|
|
48
|
+
return target.require(name);
|
|
49
|
+
const path = target.require('path');
|
|
50
|
+
const fs = target.require('fs');
|
|
51
|
+
let dir = path.resolve('.');
|
|
52
|
+
const suffix = `./node_modules/${name}`;
|
|
53
|
+
const $$ = $;
|
|
54
|
+
while (!fs.existsSync(path.join(dir, suffix))) {
|
|
55
|
+
const parent = path.resolve(dir, '..');
|
|
56
|
+
if (parent === dir) {
|
|
57
|
+
$$.$mol_exec('.', 'npm', 'install', name);
|
|
58
|
+
try {
|
|
59
|
+
$$.$mol_exec('.', 'npm', 'install', '@types/' + name);
|
|
60
|
+
}
|
|
61
|
+
catch { }
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
dir = parent;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return target.require(name);
|
|
69
|
+
},
|
|
70
|
+
set(target, name, value) {
|
|
71
|
+
target[name] = value;
|
|
72
|
+
return true;
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
require = (req => Object.assign(function require(name) {
|
|
76
|
+
return $node[name];
|
|
77
|
+
}, req))(require);
|
|
78
|
+
//node.node.js.map
|
|
79
|
+
;
|
|
80
|
+
"use strict";
|
|
81
|
+
var $;
|
|
82
|
+
(function ($) {
|
|
83
|
+
$.$mol_dom_context = new $node.jsdom.JSDOM('', { url: 'https://localhost/' }).window;
|
|
84
|
+
})($ || ($ = {}));
|
|
85
|
+
//context.node.js.map
|
|
86
|
+
;
|
|
87
|
+
"use strict";
|
|
88
|
+
var $;
|
|
34
89
|
(function ($) {
|
|
35
90
|
function $mol_db_response(request) {
|
|
36
91
|
return new Promise((done, fail) => {
|
|
@@ -44,6 +99,24 @@ var $;
|
|
|
44
99
|
;
|
|
45
100
|
"use strict";
|
|
46
101
|
var $;
|
|
102
|
+
(function ($) {
|
|
103
|
+
async function $mol_db(name, ...migrations) {
|
|
104
|
+
const request = this.$mol_dom_context.indexedDB.open(name, migrations.length ? migrations.length + 1 : undefined);
|
|
105
|
+
request.onupgradeneeded = event => {
|
|
106
|
+
migrations.splice(0, event.oldVersion - 1);
|
|
107
|
+
const transaction = new $.$mol_db_transaction(request.transaction);
|
|
108
|
+
for (const migrate of migrations)
|
|
109
|
+
migrate(transaction);
|
|
110
|
+
};
|
|
111
|
+
const db = await $.$mol_db_response(request);
|
|
112
|
+
return new $.$mol_db_database(db);
|
|
113
|
+
}
|
|
114
|
+
$.$mol_db = $mol_db;
|
|
115
|
+
})($ || ($ = {}));
|
|
116
|
+
//db.js.map
|
|
117
|
+
;
|
|
118
|
+
"use strict";
|
|
119
|
+
var $;
|
|
47
120
|
(function ($) {
|
|
48
121
|
class $mol_db_store {
|
|
49
122
|
native;
|
|
@@ -108,20 +181,9 @@ var $;
|
|
|
108
181
|
"use strict";
|
|
109
182
|
var $;
|
|
110
183
|
(function ($) {
|
|
111
|
-
|
|
112
|
-
const request = this.indexedDB.open(name, migrations.length ? migrations.length + 1 : undefined);
|
|
113
|
-
request.onupgradeneeded = event => {
|
|
114
|
-
migrations.splice(0, event.oldVersion - 1);
|
|
115
|
-
const transaction = new $.$mol_db_transaction(request.transaction);
|
|
116
|
-
for (const migrate of migrations)
|
|
117
|
-
migrate(transaction);
|
|
118
|
-
};
|
|
119
|
-
const db = await $.$mol_db_response(request);
|
|
120
|
-
return new $.$mol_db_database(db);
|
|
121
|
-
}
|
|
122
|
-
$.$mol_db = $mol_db;
|
|
184
|
+
$.$mol_dom_context.indexedDB = $node['fake-indexeddb'];
|
|
123
185
|
})($ || ($ = {}));
|
|
124
|
-
//db.js.map
|
|
186
|
+
//db.node.js.map
|
|
125
187
|
;
|
|
126
188
|
"use strict";
|
|
127
189
|
//db_schema.js.map
|
|
@@ -151,7 +213,7 @@ var $;
|
|
|
151
213
|
}
|
|
152
214
|
kill() {
|
|
153
215
|
this.native.close();
|
|
154
|
-
const request = indexedDB.deleteDatabase(this.name);
|
|
216
|
+
const request = $.$mol_dom_context.indexedDB.deleteDatabase(this.name);
|
|
155
217
|
request.onblocked = console.error;
|
|
156
218
|
return $.$mol_db_response(request).then(() => { });
|
|
157
219
|
}
|
|
@@ -249,5 +311,633 @@ var $;
|
|
|
249
311
|
"use strict";
|
|
250
312
|
//index_schema.js.map
|
|
251
313
|
;
|
|
314
|
+
"use strict";
|
|
315
|
+
var $;
|
|
316
|
+
(function ($) {
|
|
317
|
+
function $mol_log3_area_lazy(event) {
|
|
318
|
+
const self = this;
|
|
319
|
+
const stack = self.$mol_log3_stack;
|
|
320
|
+
const deep = stack.length;
|
|
321
|
+
let logged = false;
|
|
322
|
+
stack.push(() => {
|
|
323
|
+
logged = true;
|
|
324
|
+
self.$mol_log3_area.call(self, event);
|
|
325
|
+
});
|
|
326
|
+
return () => {
|
|
327
|
+
if (logged)
|
|
328
|
+
self.console.groupEnd();
|
|
329
|
+
if (stack.length > deep)
|
|
330
|
+
stack.length = deep;
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
$.$mol_log3_area_lazy = $mol_log3_area_lazy;
|
|
334
|
+
$.$mol_log3_stack = [];
|
|
335
|
+
})($ || ($ = {}));
|
|
336
|
+
//log3.js.map
|
|
337
|
+
;
|
|
338
|
+
"use strict";
|
|
339
|
+
var $;
|
|
340
|
+
(function ($) {
|
|
341
|
+
$.$mol_ambient_ref = Symbol('$mol_ambient_ref');
|
|
342
|
+
function $mol_ambient(overrides) {
|
|
343
|
+
return Object.setPrototypeOf(overrides, this || $);
|
|
344
|
+
}
|
|
345
|
+
$.$mol_ambient = $mol_ambient;
|
|
346
|
+
})($ || ($ = {}));
|
|
347
|
+
//ambient.js.map
|
|
348
|
+
;
|
|
349
|
+
"use strict";
|
|
350
|
+
var $;
|
|
351
|
+
(function ($) {
|
|
352
|
+
const instances = new WeakSet();
|
|
353
|
+
function $mol_delegate(proto, target) {
|
|
354
|
+
const proxy = new Proxy(proto, {
|
|
355
|
+
get: (_, field) => {
|
|
356
|
+
const obj = target();
|
|
357
|
+
let val = Reflect.get(obj, field);
|
|
358
|
+
if (typeof val === 'function') {
|
|
359
|
+
val = val.bind(obj);
|
|
360
|
+
}
|
|
361
|
+
return val;
|
|
362
|
+
},
|
|
363
|
+
has: (_, field) => Reflect.has(target(), field),
|
|
364
|
+
set: (_, field, value) => Reflect.set(target(), field, value),
|
|
365
|
+
getOwnPropertyDescriptor: (_, field) => Reflect.getOwnPropertyDescriptor(target(), field),
|
|
366
|
+
ownKeys: () => Reflect.ownKeys(target()),
|
|
367
|
+
getPrototypeOf: () => Reflect.getPrototypeOf(target()),
|
|
368
|
+
setPrototypeOf: (_, donor) => Reflect.setPrototypeOf(target(), donor),
|
|
369
|
+
isExtensible: () => Reflect.isExtensible(target()),
|
|
370
|
+
preventExtensions: () => Reflect.preventExtensions(target()),
|
|
371
|
+
apply: (_, self, args) => Reflect.apply(target(), self, args),
|
|
372
|
+
construct: (_, args, retarget) => Reflect.construct(target(), args, retarget),
|
|
373
|
+
defineProperty: (_, field, descr) => Reflect.defineProperty(target(), field, descr),
|
|
374
|
+
deleteProperty: (_, field) => Reflect.deleteProperty(target(), field),
|
|
375
|
+
});
|
|
376
|
+
instances.add(proxy);
|
|
377
|
+
return proxy;
|
|
378
|
+
}
|
|
379
|
+
$.$mol_delegate = $mol_delegate;
|
|
380
|
+
Reflect.defineProperty($mol_delegate, Symbol.hasInstance, {
|
|
381
|
+
value: (obj) => instances.has(obj),
|
|
382
|
+
});
|
|
383
|
+
})($ || ($ = {}));
|
|
384
|
+
//delegate.js.map
|
|
385
|
+
;
|
|
386
|
+
"use strict";
|
|
387
|
+
var $;
|
|
388
|
+
(function ($) {
|
|
389
|
+
$.$mol_owning_map = new WeakMap();
|
|
390
|
+
function $mol_owning_allow(having) {
|
|
391
|
+
try {
|
|
392
|
+
if (!having)
|
|
393
|
+
return false;
|
|
394
|
+
if (typeof having !== 'object')
|
|
395
|
+
return false;
|
|
396
|
+
if (having instanceof $.$mol_delegate)
|
|
397
|
+
return false;
|
|
398
|
+
if (typeof having['destructor'] !== 'function')
|
|
399
|
+
return false;
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
catch {
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
$.$mol_owning_allow = $mol_owning_allow;
|
|
407
|
+
function $mol_owning_get(having, Owner) {
|
|
408
|
+
if (!$mol_owning_allow(having))
|
|
409
|
+
return null;
|
|
410
|
+
while (true) {
|
|
411
|
+
const owner = $.$mol_owning_map.get(having);
|
|
412
|
+
if (!owner)
|
|
413
|
+
return owner;
|
|
414
|
+
if (!Owner)
|
|
415
|
+
return owner;
|
|
416
|
+
if (owner instanceof Owner)
|
|
417
|
+
return owner;
|
|
418
|
+
having = owner;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
$.$mol_owning_get = $mol_owning_get;
|
|
422
|
+
function $mol_owning_check(owner, having) {
|
|
423
|
+
if (!$mol_owning_allow(having))
|
|
424
|
+
return false;
|
|
425
|
+
if ($.$mol_owning_map.get(having) !== owner)
|
|
426
|
+
return false;
|
|
427
|
+
return true;
|
|
428
|
+
}
|
|
429
|
+
$.$mol_owning_check = $mol_owning_check;
|
|
430
|
+
function $mol_owning_catch(owner, having) {
|
|
431
|
+
if (!$mol_owning_allow(having))
|
|
432
|
+
return false;
|
|
433
|
+
if ($.$mol_owning_map.get(having))
|
|
434
|
+
return false;
|
|
435
|
+
$.$mol_owning_map.set(having, owner);
|
|
436
|
+
return true;
|
|
437
|
+
}
|
|
438
|
+
$.$mol_owning_catch = $mol_owning_catch;
|
|
439
|
+
})($ || ($ = {}));
|
|
440
|
+
//owning.js.map
|
|
441
|
+
;
|
|
442
|
+
"use strict";
|
|
443
|
+
var $;
|
|
444
|
+
(function ($) {
|
|
445
|
+
function $mol_fail(error) {
|
|
446
|
+
throw error;
|
|
447
|
+
}
|
|
448
|
+
$.$mol_fail = $mol_fail;
|
|
449
|
+
})($ || ($ = {}));
|
|
450
|
+
//fail.js.map
|
|
451
|
+
;
|
|
452
|
+
"use strict";
|
|
453
|
+
var $;
|
|
454
|
+
(function ($) {
|
|
455
|
+
function $mol_fail_hidden(error) {
|
|
456
|
+
throw error;
|
|
457
|
+
}
|
|
458
|
+
$.$mol_fail_hidden = $mol_fail_hidden;
|
|
459
|
+
})($ || ($ = {}));
|
|
460
|
+
//hidden.js.map
|
|
461
|
+
;
|
|
462
|
+
"use strict";
|
|
463
|
+
//writable.js.map
|
|
464
|
+
;
|
|
465
|
+
"use strict";
|
|
466
|
+
var $;
|
|
467
|
+
(function ($) {
|
|
468
|
+
class $mol_object2 {
|
|
469
|
+
static $ = $;
|
|
470
|
+
[$.$mol_ambient_ref] = null;
|
|
471
|
+
get $() {
|
|
472
|
+
if (this[$.$mol_ambient_ref])
|
|
473
|
+
return this[$.$mol_ambient_ref];
|
|
474
|
+
const owner = $.$mol_owning_get(this);
|
|
475
|
+
return this[$.$mol_ambient_ref] = owner?.$ || $mol_object2.$;
|
|
476
|
+
}
|
|
477
|
+
set $(next) {
|
|
478
|
+
if (this[$.$mol_ambient_ref])
|
|
479
|
+
$.$mol_fail_hidden(new Error('Context already defined'));
|
|
480
|
+
this[$.$mol_ambient_ref] = next;
|
|
481
|
+
}
|
|
482
|
+
static create(init) {
|
|
483
|
+
const obj = new this;
|
|
484
|
+
if (init)
|
|
485
|
+
init(obj);
|
|
486
|
+
return obj;
|
|
487
|
+
}
|
|
488
|
+
static [Symbol.toPrimitive]() {
|
|
489
|
+
return this.toString();
|
|
490
|
+
}
|
|
491
|
+
static toString() {
|
|
492
|
+
if (Symbol.toStringTag in this)
|
|
493
|
+
return this[Symbol.toStringTag];
|
|
494
|
+
return this.name;
|
|
495
|
+
}
|
|
496
|
+
destructor() { }
|
|
497
|
+
[Symbol.toPrimitive](hint) {
|
|
498
|
+
return hint === 'number' ? this.valueOf() : this.toString();
|
|
499
|
+
}
|
|
500
|
+
toString() {
|
|
501
|
+
return this[Symbol.toStringTag] || this.constructor.name + '()';
|
|
502
|
+
}
|
|
503
|
+
toJSON() {
|
|
504
|
+
return this.toString();
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
$.$mol_object2 = $mol_object2;
|
|
508
|
+
})($ || ($ = {}));
|
|
509
|
+
//object2.js.map
|
|
510
|
+
;
|
|
511
|
+
"use strict";
|
|
512
|
+
var $;
|
|
513
|
+
(function ($) {
|
|
514
|
+
function $mol_deprecated(message) {
|
|
515
|
+
return (host, field, descr) => {
|
|
516
|
+
const value = descr.value;
|
|
517
|
+
let warned = false;
|
|
518
|
+
descr.value = function $mol_deprecated_wrapper(...args) {
|
|
519
|
+
if (!warned) {
|
|
520
|
+
$.$$.$mol_log3_warn({
|
|
521
|
+
place: `${host.constructor.name}::${field}`,
|
|
522
|
+
message: `Deprecated`,
|
|
523
|
+
hint: message,
|
|
524
|
+
});
|
|
525
|
+
warned = true;
|
|
526
|
+
}
|
|
527
|
+
return value.call(this, ...args);
|
|
528
|
+
};
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
$.$mol_deprecated = $mol_deprecated;
|
|
532
|
+
})($ || ($ = {}));
|
|
533
|
+
//deprecated.js.map
|
|
534
|
+
;
|
|
535
|
+
"use strict";
|
|
536
|
+
var $;
|
|
537
|
+
(function ($) {
|
|
538
|
+
$.$mol_tree_convert = Symbol('$mol_tree_convert');
|
|
539
|
+
class $mol_tree extends $.$mol_object2 {
|
|
540
|
+
type;
|
|
541
|
+
data;
|
|
542
|
+
sub;
|
|
543
|
+
baseUri;
|
|
544
|
+
row;
|
|
545
|
+
col;
|
|
546
|
+
length;
|
|
547
|
+
constructor(config = {}) {
|
|
548
|
+
super();
|
|
549
|
+
this.type = config.type || '';
|
|
550
|
+
if (config.value !== undefined) {
|
|
551
|
+
var sub = $mol_tree.values(config.value);
|
|
552
|
+
if (config.type || sub.length > 1) {
|
|
553
|
+
this.sub = [...sub, ...(config.sub || [])];
|
|
554
|
+
this.data = config.data || '';
|
|
555
|
+
}
|
|
556
|
+
else {
|
|
557
|
+
this.data = sub[0].data;
|
|
558
|
+
this.sub = config.sub || [];
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
else {
|
|
562
|
+
this.data = config.data || '';
|
|
563
|
+
this.sub = config.sub || [];
|
|
564
|
+
}
|
|
565
|
+
this.baseUri = config.baseUri || '';
|
|
566
|
+
this.row = config.row || 0;
|
|
567
|
+
this.col = config.col || 0;
|
|
568
|
+
this.length = config.length || 0;
|
|
569
|
+
}
|
|
570
|
+
static values(str, baseUri) {
|
|
571
|
+
return str.split('\n').map((data, index) => new $mol_tree({
|
|
572
|
+
data: data,
|
|
573
|
+
baseUri: baseUri,
|
|
574
|
+
row: index + 1,
|
|
575
|
+
length: data.length,
|
|
576
|
+
}));
|
|
577
|
+
}
|
|
578
|
+
clone(config = {}) {
|
|
579
|
+
return new $mol_tree({
|
|
580
|
+
type: ('type' in config) ? config.type : this.type,
|
|
581
|
+
data: ('data' in config) ? config.data : this.data,
|
|
582
|
+
sub: ('sub' in config) ? config.sub : this.sub,
|
|
583
|
+
baseUri: ('baseUri' in config) ? config.baseUri : this.baseUri,
|
|
584
|
+
row: ('row' in config) ? config.row : this.row,
|
|
585
|
+
col: ('col' in config) ? config.col : this.col,
|
|
586
|
+
length: ('length' in config) ? config.length : this.length,
|
|
587
|
+
value: config.value
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
make(config) {
|
|
591
|
+
return new $mol_tree({
|
|
592
|
+
baseUri: this.baseUri,
|
|
593
|
+
row: this.row,
|
|
594
|
+
col: this.col,
|
|
595
|
+
length: this.length,
|
|
596
|
+
...config,
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
make_data(value, sub) {
|
|
600
|
+
return this.make({ value, sub });
|
|
601
|
+
}
|
|
602
|
+
make_struct(type, sub) {
|
|
603
|
+
return this.make({ type, sub });
|
|
604
|
+
}
|
|
605
|
+
static fromString(str, baseUri) {
|
|
606
|
+
var root = new $mol_tree({ baseUri: baseUri });
|
|
607
|
+
var stack = [root];
|
|
608
|
+
var row = 0;
|
|
609
|
+
var prefix = str.replace(/^\n?(\t*)[\s\S]*/, '$1');
|
|
610
|
+
var lines = str.replace(new RegExp('^\\t{0,' + prefix.length + '}', 'mg'), '').split('\n');
|
|
611
|
+
lines.forEach(line => {
|
|
612
|
+
++row;
|
|
613
|
+
var chunks = /^(\t*)((?:[^\n\t\\ ]+ *)*)(\\[^\n]*)?(.*?)(?:$|\n)/m.exec(line);
|
|
614
|
+
if (!chunks || chunks[4])
|
|
615
|
+
return this.$.$mol_fail(new Error(`Syntax error at ${baseUri}:${row}\n${line}`));
|
|
616
|
+
var indent = chunks[1];
|
|
617
|
+
var path = chunks[2];
|
|
618
|
+
var data = chunks[3];
|
|
619
|
+
var deep = indent.length;
|
|
620
|
+
var types = path ? path.replace(/ $/, '').split(/ +/) : [];
|
|
621
|
+
if (stack.length <= deep)
|
|
622
|
+
return this.$.$mol_fail(new Error(`Too many tabs at ${baseUri}:${row}\n${line}`));
|
|
623
|
+
stack.length = deep + 1;
|
|
624
|
+
var parent = stack[deep];
|
|
625
|
+
let col = deep;
|
|
626
|
+
types.forEach(type => {
|
|
627
|
+
if (!type)
|
|
628
|
+
return this.$.$mol_fail(new Error(`Unexpected space symbol ${baseUri}:${row}\n${line}`));
|
|
629
|
+
var next = new $mol_tree({ type, baseUri, row, col, length: type.length });
|
|
630
|
+
const parent_sub = parent.sub;
|
|
631
|
+
parent_sub.push(next);
|
|
632
|
+
parent = next;
|
|
633
|
+
col += type.length + 1;
|
|
634
|
+
});
|
|
635
|
+
if (data) {
|
|
636
|
+
var next = new $mol_tree({ data: data.substring(1), baseUri, row, col, length: data.length });
|
|
637
|
+
const parent_sub = parent.sub;
|
|
638
|
+
parent_sub.push(next);
|
|
639
|
+
parent = next;
|
|
640
|
+
}
|
|
641
|
+
stack.push(parent);
|
|
642
|
+
});
|
|
643
|
+
return root;
|
|
644
|
+
}
|
|
645
|
+
static fromJSON(json, baseUri = '') {
|
|
646
|
+
switch (true) {
|
|
647
|
+
case typeof json === 'boolean':
|
|
648
|
+
case typeof json === 'number':
|
|
649
|
+
case json === null:
|
|
650
|
+
return new $mol_tree({
|
|
651
|
+
type: String(json),
|
|
652
|
+
baseUri: baseUri
|
|
653
|
+
});
|
|
654
|
+
case typeof json === 'string':
|
|
655
|
+
return new $mol_tree({
|
|
656
|
+
value: json,
|
|
657
|
+
baseUri: baseUri
|
|
658
|
+
});
|
|
659
|
+
case Array.isArray(json):
|
|
660
|
+
return new $mol_tree({
|
|
661
|
+
type: "/",
|
|
662
|
+
sub: json.map(json => $mol_tree.fromJSON(json, baseUri))
|
|
663
|
+
});
|
|
664
|
+
case json instanceof Date:
|
|
665
|
+
return new $mol_tree({
|
|
666
|
+
value: json.toISOString(),
|
|
667
|
+
baseUri: baseUri
|
|
668
|
+
});
|
|
669
|
+
default:
|
|
670
|
+
if (typeof json[$.$mol_tree_convert] === 'function') {
|
|
671
|
+
return json[$.$mol_tree_convert]();
|
|
672
|
+
}
|
|
673
|
+
if (typeof json.toJSON === 'function') {
|
|
674
|
+
return $mol_tree.fromJSON(json.toJSON());
|
|
675
|
+
}
|
|
676
|
+
if (json instanceof Error) {
|
|
677
|
+
const { name, message, stack } = json;
|
|
678
|
+
json = { ...json, name, message, stack };
|
|
679
|
+
}
|
|
680
|
+
var sub = [];
|
|
681
|
+
for (var key in json) {
|
|
682
|
+
if (json[key] === undefined)
|
|
683
|
+
continue;
|
|
684
|
+
const subsub = $mol_tree.fromJSON(json[key], baseUri);
|
|
685
|
+
if (/^[^\n\t\\ ]+$/.test(key)) {
|
|
686
|
+
var child = new $mol_tree({
|
|
687
|
+
type: key,
|
|
688
|
+
baseUri: baseUri,
|
|
689
|
+
sub: [subsub],
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
else {
|
|
693
|
+
var child = new $mol_tree({
|
|
694
|
+
value: key,
|
|
695
|
+
baseUri: baseUri,
|
|
696
|
+
sub: [subsub],
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
sub.push(child);
|
|
700
|
+
}
|
|
701
|
+
return new $mol_tree({
|
|
702
|
+
type: "*",
|
|
703
|
+
sub: sub,
|
|
704
|
+
baseUri: baseUri
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
get uri() {
|
|
709
|
+
return this.baseUri + '#' + this.row + ':' + this.col;
|
|
710
|
+
}
|
|
711
|
+
toString(prefix = '') {
|
|
712
|
+
var output = '';
|
|
713
|
+
if (this.type.length) {
|
|
714
|
+
if (!prefix.length) {
|
|
715
|
+
prefix = "\t";
|
|
716
|
+
}
|
|
717
|
+
output += this.type;
|
|
718
|
+
if (this.sub.length == 1) {
|
|
719
|
+
return output + ' ' + this.sub[0].toString(prefix);
|
|
720
|
+
}
|
|
721
|
+
output += "\n";
|
|
722
|
+
}
|
|
723
|
+
else if (this.data.length || prefix.length) {
|
|
724
|
+
output += "\\" + this.data + "\n";
|
|
725
|
+
}
|
|
726
|
+
for (var child of this.sub) {
|
|
727
|
+
output += prefix;
|
|
728
|
+
output += child.toString(prefix + "\t");
|
|
729
|
+
}
|
|
730
|
+
return output;
|
|
731
|
+
}
|
|
732
|
+
toJSON() {
|
|
733
|
+
if (!this.type)
|
|
734
|
+
return this.value;
|
|
735
|
+
if (this.type === 'true')
|
|
736
|
+
return true;
|
|
737
|
+
if (this.type === 'false')
|
|
738
|
+
return false;
|
|
739
|
+
if (this.type === 'null')
|
|
740
|
+
return null;
|
|
741
|
+
if (this.type === '*') {
|
|
742
|
+
var obj = {};
|
|
743
|
+
for (var child of this.sub) {
|
|
744
|
+
if (child.type === '-')
|
|
745
|
+
continue;
|
|
746
|
+
var key = child.type || child.clone({ sub: child.sub.slice(0, child.sub.length - 1) }).value;
|
|
747
|
+
var val = child.sub[child.sub.length - 1].toJSON();
|
|
748
|
+
if (val !== undefined)
|
|
749
|
+
obj[key] = val;
|
|
750
|
+
}
|
|
751
|
+
return obj;
|
|
752
|
+
}
|
|
753
|
+
if (this.type === '/') {
|
|
754
|
+
var res = [];
|
|
755
|
+
this.sub.forEach(child => {
|
|
756
|
+
if (child.type === '-')
|
|
757
|
+
return;
|
|
758
|
+
var val = child.toJSON();
|
|
759
|
+
if (val !== undefined)
|
|
760
|
+
res.push(val);
|
|
761
|
+
});
|
|
762
|
+
return res;
|
|
763
|
+
}
|
|
764
|
+
if (this.type === 'time') {
|
|
765
|
+
return new Date(this.value);
|
|
766
|
+
}
|
|
767
|
+
const numb = Number(this.type);
|
|
768
|
+
if (!Number.isNaN(numb) || this.type === 'NaN')
|
|
769
|
+
return numb;
|
|
770
|
+
throw new Error(`Unknown type (${this.type}) at ${this.uri}`);
|
|
771
|
+
}
|
|
772
|
+
get value() {
|
|
773
|
+
var values = [];
|
|
774
|
+
for (var child of this.sub) {
|
|
775
|
+
if (child.type)
|
|
776
|
+
continue;
|
|
777
|
+
values.push(child.value);
|
|
778
|
+
}
|
|
779
|
+
return this.data + values.join("\n");
|
|
780
|
+
}
|
|
781
|
+
insert(value, ...path) {
|
|
782
|
+
if (path.length === 0)
|
|
783
|
+
return value;
|
|
784
|
+
const type = path[0];
|
|
785
|
+
if (typeof type === 'string') {
|
|
786
|
+
let replaced = false;
|
|
787
|
+
const sub = this.sub.map((item, index) => {
|
|
788
|
+
if (item.type !== type)
|
|
789
|
+
return item;
|
|
790
|
+
replaced = true;
|
|
791
|
+
return item.insert(value, ...path.slice(1));
|
|
792
|
+
});
|
|
793
|
+
if (!replaced)
|
|
794
|
+
sub.push(new $mol_tree({ type }).insert(value, ...path.slice(1)));
|
|
795
|
+
return this.clone({ sub });
|
|
796
|
+
}
|
|
797
|
+
else if (typeof type === 'number') {
|
|
798
|
+
const sub = this.sub.slice();
|
|
799
|
+
sub[type] = (sub[type] || new $mol_tree).insert(value, ...path.slice(1));
|
|
800
|
+
return this.clone({ sub });
|
|
801
|
+
}
|
|
802
|
+
else {
|
|
803
|
+
return this.clone({ sub: ((this.sub.length === 0) ? [new $mol_tree()] : this.sub).map(item => item.insert(value, ...path.slice(1))) });
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
select(...path) {
|
|
807
|
+
var next = [this];
|
|
808
|
+
for (var type of path) {
|
|
809
|
+
if (!next.length)
|
|
810
|
+
break;
|
|
811
|
+
var prev = next;
|
|
812
|
+
next = [];
|
|
813
|
+
for (var item of prev) {
|
|
814
|
+
switch (typeof (type)) {
|
|
815
|
+
case 'string':
|
|
816
|
+
for (var child of item.sub) {
|
|
817
|
+
if (!type || (child.type == type)) {
|
|
818
|
+
next.push(child);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
break;
|
|
822
|
+
case 'number':
|
|
823
|
+
if (type < item.sub.length)
|
|
824
|
+
next.push(item.sub[type]);
|
|
825
|
+
break;
|
|
826
|
+
default: next.push(...item.sub);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
return new $mol_tree({ sub: next });
|
|
831
|
+
}
|
|
832
|
+
filter(path, value) {
|
|
833
|
+
var sub = this.sub.filter(function (item) {
|
|
834
|
+
var found = item.select(...path);
|
|
835
|
+
if (value == null) {
|
|
836
|
+
return Boolean(found.sub.length);
|
|
837
|
+
}
|
|
838
|
+
else {
|
|
839
|
+
return found.sub.some(child => child.value == value);
|
|
840
|
+
}
|
|
841
|
+
});
|
|
842
|
+
return new $mol_tree({ sub: sub });
|
|
843
|
+
}
|
|
844
|
+
transform(visit, stack = []) {
|
|
845
|
+
const sub_stack = [this, ...stack];
|
|
846
|
+
return visit(sub_stack, () => this.sub.map(node => node.transform(visit, sub_stack)).filter(n => n));
|
|
847
|
+
}
|
|
848
|
+
hack(context) {
|
|
849
|
+
const sub = [].concat(...this.sub.map(child => {
|
|
850
|
+
const handle = context[child.type] || context[''];
|
|
851
|
+
if (!handle)
|
|
852
|
+
$.$mol_fail(child.error('Handler not defined'));
|
|
853
|
+
return handle(child, context);
|
|
854
|
+
}));
|
|
855
|
+
return this.clone({ sub });
|
|
856
|
+
}
|
|
857
|
+
error(message) {
|
|
858
|
+
return new Error(`${message}:\n${this} ${this.baseUri}:${this.row}:${this.col}`);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
__decorate([
|
|
862
|
+
$.$mol_deprecated('Use $mol_tree:hack')
|
|
863
|
+
], $mol_tree.prototype, "transform", null);
|
|
864
|
+
$.$mol_tree = $mol_tree;
|
|
865
|
+
})($ || ($ = {}));
|
|
866
|
+
//tree.js.map
|
|
867
|
+
;
|
|
868
|
+
"use strict";
|
|
869
|
+
var $;
|
|
870
|
+
(function ($) {
|
|
871
|
+
function $mol_log3_node_make(level, output, type, color) {
|
|
872
|
+
return function $mol_log3_logger(event) {
|
|
873
|
+
if (!event.time)
|
|
874
|
+
event = { time: new Date().toISOString(), ...event };
|
|
875
|
+
const tree = this.$mol_tree.fromJSON(event).clone({ type });
|
|
876
|
+
let str = tree.toString();
|
|
877
|
+
if (process[output].isTTY) {
|
|
878
|
+
str = $node.colorette[color + 'Bright'](str);
|
|
879
|
+
}
|
|
880
|
+
;
|
|
881
|
+
this.console[level](str);
|
|
882
|
+
const self = this;
|
|
883
|
+
return () => self.console.groupEnd();
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
$.$mol_log3_node_make = $mol_log3_node_make;
|
|
887
|
+
$.$mol_log3_come = $mol_log3_node_make('info', 'stdout', 'come', 'blue');
|
|
888
|
+
$.$mol_log3_done = $mol_log3_node_make('info', 'stdout', 'done', 'green');
|
|
889
|
+
$.$mol_log3_fail = $mol_log3_node_make('error', 'stderr', 'fail', 'red');
|
|
890
|
+
$.$mol_log3_warn = $mol_log3_node_make('warn', 'stderr', 'warn', 'yellow');
|
|
891
|
+
$.$mol_log3_rise = $mol_log3_node_make('log', 'stdout', 'rise', 'magenta');
|
|
892
|
+
$.$mol_log3_area = $mol_log3_node_make('log', 'stdout', 'area', 'cyan');
|
|
893
|
+
})($ || ($ = {}));
|
|
894
|
+
//log3.node.js.map
|
|
895
|
+
;
|
|
896
|
+
"use strict";
|
|
897
|
+
var $;
|
|
898
|
+
(function ($) {
|
|
899
|
+
function $mol_env() {
|
|
900
|
+
return {};
|
|
901
|
+
}
|
|
902
|
+
$.$mol_env = $mol_env;
|
|
903
|
+
})($ || ($ = {}));
|
|
904
|
+
//env.js.map
|
|
905
|
+
;
|
|
906
|
+
"use strict";
|
|
907
|
+
var $;
|
|
908
|
+
(function ($) {
|
|
909
|
+
$.$mol_env = function $mol_env() {
|
|
910
|
+
return this.process.env;
|
|
911
|
+
};
|
|
912
|
+
})($ || ($ = {}));
|
|
913
|
+
//env.node.js.map
|
|
914
|
+
;
|
|
915
|
+
"use strict";
|
|
916
|
+
var $;
|
|
917
|
+
(function ($) {
|
|
918
|
+
function $mol_exec(dir, command, ...args) {
|
|
919
|
+
let [app, ...args0] = command.split(' ');
|
|
920
|
+
args = [...args0, ...args];
|
|
921
|
+
this.$mol_log3_come({
|
|
922
|
+
place: '$mol_exec',
|
|
923
|
+
dir: $node.path.relative('', dir),
|
|
924
|
+
message: 'Run',
|
|
925
|
+
command: `${app} ${args.join(' ')}`,
|
|
926
|
+
});
|
|
927
|
+
var res = $node['child_process'].spawnSync(app, args, {
|
|
928
|
+
cwd: $node.path.resolve(dir),
|
|
929
|
+
shell: true,
|
|
930
|
+
env: this.$mol_env(),
|
|
931
|
+
});
|
|
932
|
+
if (res.status || res.error)
|
|
933
|
+
return $.$mol_fail(res.error || new Error(res.stderr.toString()));
|
|
934
|
+
if (!res.stdout)
|
|
935
|
+
res.stdout = Buffer.from([]);
|
|
936
|
+
return res;
|
|
937
|
+
}
|
|
938
|
+
$.$mol_exec = $mol_exec;
|
|
939
|
+
})($ || ($ = {}));
|
|
940
|
+
//exec.node.js.map
|
|
941
|
+
;
|
|
252
942
|
export default $
|
|
253
943
|
//# sourceMappingURL=node.esm.js.map
|