hyoo_sync_client 0.0.603 → 0.0.605
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/manifest.json +10 -0
- package/node.d.ts +541 -120
- package/node.d.ts.map +1 -1
- package/node.deps.json +1 -1
- package/node.js +1332 -470
- package/node.js.map +1 -1
- package/node.meta.tree +7 -3
- package/node.mjs +1332 -470
- package/node.test.js +1734 -623
- package/node.test.js.map +1 -1
- package/package.json +29 -23
- package/test.html +1 -1
- package/web.d.ts +439 -38
- package/web.d.ts.map +1 -1
- package/web.deps.json +1 -1
- package/web.js +965 -158
- package/web.js.map +1 -1
- package/web.meta.tree +7 -3
- package/web.mjs +965 -158
- package/web.test.js +297 -101
- package/web.test.js.map +1 -1
package/node.test.js
CHANGED
|
@@ -21,10 +21,9 @@ $.$$ = $
|
|
|
21
21
|
|
|
22
22
|
;
|
|
23
23
|
"use strict";
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
let $hyoo_sync_revision = "echo";
|
|
24
|
+
// namespace $ {
|
|
25
|
+
// $mol_report_bugsnag = '18acf016ed2a2a4cc4445daa9dd2dd3c'
|
|
26
|
+
// }
|
|
28
27
|
|
|
29
28
|
;
|
|
30
29
|
"use strict";
|
|
@@ -42,6 +41,11 @@ var $;
|
|
|
42
41
|
var $;
|
|
43
42
|
(function ($) {
|
|
44
43
|
const instances = new WeakSet();
|
|
44
|
+
/**
|
|
45
|
+
* Proxy that delegates all to lazy returned target.
|
|
46
|
+
*
|
|
47
|
+
* $mol_delegate( Array.prototype , ()=> fetch_array() )
|
|
48
|
+
*/
|
|
45
49
|
function $mol_delegate(proto, target) {
|
|
46
50
|
const proxy = new Proxy(proto, {
|
|
47
51
|
get: (_, field) => {
|
|
@@ -145,7 +149,7 @@ var $;
|
|
|
145
149
|
var $;
|
|
146
150
|
(function ($) {
|
|
147
151
|
function $mol_fail_hidden(error) {
|
|
148
|
-
throw error;
|
|
152
|
+
throw error; /// Use 'Never Pause Here' breakpoint in DevTools or simply blackbox this script
|
|
149
153
|
}
|
|
150
154
|
$.$mol_fail_hidden = $mol_fail_hidden;
|
|
151
155
|
})($ || ($ = {}));
|
|
@@ -189,6 +193,16 @@ var $;
|
|
|
189
193
|
"use strict";
|
|
190
194
|
var $;
|
|
191
195
|
(function ($) {
|
|
196
|
+
$.$mol_key_handle = Symbol.for('$mol_key_handle');
|
|
197
|
+
$.$mol_key_store = new WeakMap();
|
|
198
|
+
})($ || ($ = {}));
|
|
199
|
+
|
|
200
|
+
;
|
|
201
|
+
"use strict";
|
|
202
|
+
var $;
|
|
203
|
+
(function ($) {
|
|
204
|
+
if (!Symbol.dispose)
|
|
205
|
+
Symbol.dispose = Symbol('Symbol.dispose');
|
|
192
206
|
class $mol_object2 {
|
|
193
207
|
static $ = $;
|
|
194
208
|
[Symbol.toStringTag];
|
|
@@ -197,7 +211,7 @@ var $;
|
|
|
197
211
|
if (this[$mol_ambient_ref])
|
|
198
212
|
return this[$mol_ambient_ref];
|
|
199
213
|
const owner = $mol_owning_get(this);
|
|
200
|
-
return this[$mol_ambient_ref] = owner?.$ || $mol_object2.$;
|
|
214
|
+
return this[$mol_ambient_ref] = owner?.$ || this.constructor.$ || $mol_object2.$;
|
|
201
215
|
}
|
|
202
216
|
set $(next) {
|
|
203
217
|
if (this[$mol_ambient_ref])
|
|
@@ -219,8 +233,17 @@ var $;
|
|
|
219
233
|
static toJSON() {
|
|
220
234
|
return this.toString();
|
|
221
235
|
}
|
|
236
|
+
static [$mol_key_handle]() {
|
|
237
|
+
return this.toString();
|
|
238
|
+
}
|
|
222
239
|
destructor() { }
|
|
223
240
|
static destructor() { }
|
|
241
|
+
[Symbol.dispose]() {
|
|
242
|
+
this.destructor();
|
|
243
|
+
}
|
|
244
|
+
//[ Symbol.toPrimitive ]( hint: string ) {
|
|
245
|
+
// return hint === 'number' ? this.valueOf() : this.toString()
|
|
246
|
+
//}
|
|
224
247
|
toString() {
|
|
225
248
|
return this[Symbol.toStringTag] || this.constructor.name + '<>';
|
|
226
249
|
}
|
|
@@ -230,107 +253,158 @@ var $;
|
|
|
230
253
|
|
|
231
254
|
;
|
|
232
255
|
"use strict";
|
|
256
|
+
var $;
|
|
257
|
+
(function ($) {
|
|
258
|
+
let buf = new Uint8Array(2 ** 12); // 4KB Mem Page
|
|
259
|
+
/** Temporary buffer. Recursive usage isn't supported. */
|
|
260
|
+
function $mol_charset_buffer(size) {
|
|
261
|
+
if (buf.byteLength < size)
|
|
262
|
+
buf = new Uint8Array(size);
|
|
263
|
+
return buf;
|
|
264
|
+
}
|
|
265
|
+
$.$mol_charset_buffer = $mol_charset_buffer;
|
|
266
|
+
})($ || ($ = {}));
|
|
233
267
|
|
|
234
268
|
;
|
|
235
269
|
"use strict";
|
|
236
270
|
var $;
|
|
237
271
|
(function ($) {
|
|
238
|
-
function $
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
272
|
+
function $mol_charset_encode(str) {
|
|
273
|
+
const buf = $mol_charset_buffer(str.length * 3);
|
|
274
|
+
return buf.slice(0, $mol_charset_encode_to(str, buf));
|
|
275
|
+
}
|
|
276
|
+
$.$mol_charset_encode = $mol_charset_encode;
|
|
277
|
+
function $mol_charset_encode_to(str, buf, from = 0) {
|
|
278
|
+
let pos = from;
|
|
279
|
+
for (let i = 0; i < str.length; i++) {
|
|
280
|
+
let code = str.charCodeAt(i);
|
|
281
|
+
if (code < 0x80) { // ASCII - 1 octet
|
|
282
|
+
buf[pos++] = code;
|
|
283
|
+
}
|
|
284
|
+
else if (code < 0x800) { // 2 octet
|
|
285
|
+
buf[pos++] = 0xc0 | (code >> 6);
|
|
286
|
+
buf[pos++] = 0x80 | (code & 0x3f);
|
|
287
|
+
}
|
|
288
|
+
else if (code < 0xd800 || code >= 0xe000) { // 3 octet
|
|
289
|
+
buf[pos++] = 0xe0 | (code >> 12);
|
|
290
|
+
buf[pos++] = 0x80 | ((code >> 6) & 0x3f);
|
|
291
|
+
buf[pos++] = 0x80 | (code & 0x3f);
|
|
292
|
+
}
|
|
293
|
+
else { // surrogate pair
|
|
294
|
+
const point = ((code - 0xd800) << 10) + str.charCodeAt(++i) + 0x2400;
|
|
295
|
+
buf[pos++] = 0xf0 | (point >> 18);
|
|
296
|
+
buf[pos++] = 0x80 | ((point >> 12) & 0x3f);
|
|
297
|
+
buf[pos++] = 0x80 | ((point >> 6) & 0x3f);
|
|
298
|
+
buf[pos++] = 0x80 | (point & 0x3f);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return pos - from;
|
|
302
|
+
}
|
|
303
|
+
$.$mol_charset_encode_to = $mol_charset_encode_to;
|
|
304
|
+
function $mol_charset_encode_size(str) {
|
|
305
|
+
let size = 0;
|
|
306
|
+
for (let i = 0; i < str.length; i++) {
|
|
307
|
+
let code = str.charCodeAt(i);
|
|
308
|
+
if (code < 0x80)
|
|
309
|
+
size += 1;
|
|
310
|
+
else if (code < 0x800)
|
|
311
|
+
size += 2;
|
|
312
|
+
else if (code < 0xd800 || code >= 0xe000)
|
|
313
|
+
size += 3;
|
|
314
|
+
else
|
|
315
|
+
size += 4;
|
|
244
316
|
}
|
|
317
|
+
return size;
|
|
245
318
|
}
|
|
246
|
-
$.$
|
|
319
|
+
$.$mol_charset_encode_size = $mol_charset_encode_size;
|
|
247
320
|
})($ || ($ = {}));
|
|
248
321
|
|
|
249
322
|
;
|
|
250
323
|
"use strict";
|
|
251
324
|
var $;
|
|
252
325
|
(function ($) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
if ($mol_promise_like(error))
|
|
258
|
-
$mol_fail_hidden(error);
|
|
259
|
-
if (catched.get(error))
|
|
260
|
-
return false;
|
|
261
|
-
catched.set(error, true);
|
|
262
|
-
return true;
|
|
326
|
+
function $mol_int62_string_ensure(str) {
|
|
327
|
+
if (typeof str !== 'string')
|
|
328
|
+
return null;
|
|
329
|
+
return $mol_int62_from_string(str) && str;
|
|
263
330
|
}
|
|
264
|
-
$.$
|
|
331
|
+
$.$mol_int62_string_ensure = $mol_int62_string_ensure;
|
|
332
|
+
$.$mol_int62_max = (2 ** 30) - 1;
|
|
333
|
+
$.$mol_int62_min = -(2 ** 30);
|
|
334
|
+
$.$mol_int62_range = $.$mol_int62_max - $.$mol_int62_min + 1;
|
|
335
|
+
function $mol_int62_to_string({ lo, hi }) {
|
|
336
|
+
lo = (lo + $.$mol_int62_range) % $.$mol_int62_range;
|
|
337
|
+
hi = (hi + $.$mol_int62_range) % $.$mol_int62_range;
|
|
338
|
+
return lo.toString(36) + '_' + hi.toString(36);
|
|
339
|
+
}
|
|
340
|
+
$.$mol_int62_to_string = $mol_int62_to_string;
|
|
341
|
+
function $mol_int62_from_string(str) {
|
|
342
|
+
const [str_lo, str_hi] = str.split('_');
|
|
343
|
+
const int_lo = parseInt(str_lo, 36);
|
|
344
|
+
const int_hi = parseInt(str_hi, 36);
|
|
345
|
+
if (int_lo.toString(36) !== str_lo || int_hi.toString(36) !== str_hi) {
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
return {
|
|
349
|
+
lo: (int_lo - $.$mol_int62_min) % $.$mol_int62_range + $.$mol_int62_min,
|
|
350
|
+
hi: (int_hi - $.$mol_int62_min) % $.$mol_int62_range + $.$mol_int62_min,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
$.$mol_int62_from_string = $mol_int62_from_string;
|
|
354
|
+
function $mol_int62_compare(left_lo, left_hi, right_lo, right_hi) {
|
|
355
|
+
return (right_hi - left_hi) || (right_lo - left_lo);
|
|
356
|
+
}
|
|
357
|
+
$.$mol_int62_compare = $mol_int62_compare;
|
|
358
|
+
function $mol_int62_inc(lo, hi, max = $.$mol_int62_max) {
|
|
359
|
+
if (lo === max) {
|
|
360
|
+
return { lo: -max, hi: hi + 1 };
|
|
361
|
+
}
|
|
362
|
+
else {
|
|
363
|
+
return { lo: lo + 1, hi };
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
$.$mol_int62_inc = $mol_int62_inc;
|
|
367
|
+
function $mol_int62_random() {
|
|
368
|
+
return {
|
|
369
|
+
lo: Math.floor(Math.random() * $.$mol_int62_range + $.$mol_int62_min),
|
|
370
|
+
hi: Math.floor(Math.random() * $.$mol_int62_range + $.$mol_int62_min),
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
$.$mol_int62_random = $mol_int62_random;
|
|
374
|
+
function $mol_int62_hash_string(str) {
|
|
375
|
+
return $mol_int62_to_string($mol_int62_hash_buffer($mol_charset_encode(str)));
|
|
376
|
+
}
|
|
377
|
+
$.$mol_int62_hash_string = $mol_int62_hash_string;
|
|
378
|
+
function $mol_int62_hash_buffer(buf, seed = { lo: 0, hi: 0 }) {
|
|
379
|
+
let h1 = 0xdeadbeef ^ seed.lo;
|
|
380
|
+
let h2 = 0x41c6ce57 ^ seed.hi;
|
|
381
|
+
for (const byte of buf) {
|
|
382
|
+
h1 = Math.imul(h1 ^ byte, 2654435761);
|
|
383
|
+
h2 = Math.imul(h2 ^ byte, 1597334677);
|
|
384
|
+
}
|
|
385
|
+
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
|
386
|
+
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
|
387
|
+
return { lo: h1 << 1 >> 1, hi: h2 << 1 >> 1 };
|
|
388
|
+
}
|
|
389
|
+
$.$mol_int62_hash_buffer = $mol_int62_hash_buffer;
|
|
265
390
|
})($ || ($ = {}));
|
|
266
391
|
|
|
392
|
+
;
|
|
393
|
+
"use strict";
|
|
394
|
+
|
|
267
395
|
;
|
|
268
396
|
"use strict";
|
|
269
397
|
var $;
|
|
270
398
|
(function ($) {
|
|
271
|
-
function $
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
console.error(error);
|
|
277
|
-
return true;
|
|
399
|
+
function $mol_data_setup(value, config) {
|
|
400
|
+
return Object.assign(value, {
|
|
401
|
+
config,
|
|
402
|
+
Value: null
|
|
403
|
+
});
|
|
278
404
|
}
|
|
279
|
-
$.$
|
|
405
|
+
$.$mol_data_setup = $mol_data_setup;
|
|
280
406
|
})($ || ($ = {}));
|
|
281
407
|
|
|
282
|
-
;
|
|
283
|
-
"use strict";
|
|
284
|
-
var $node = new Proxy({ require }, {
|
|
285
|
-
get(target, name, wrapper) {
|
|
286
|
-
if (target[name])
|
|
287
|
-
return target[name];
|
|
288
|
-
if (name.startsWith('node:'))
|
|
289
|
-
return target.require(name);
|
|
290
|
-
if (name[0] === '.')
|
|
291
|
-
return target.require(name);
|
|
292
|
-
const mod = target.require('module');
|
|
293
|
-
if (mod.builtinModules.indexOf(name) >= 0)
|
|
294
|
-
return target.require(name);
|
|
295
|
-
try {
|
|
296
|
-
target.require.resolve(name);
|
|
297
|
-
}
|
|
298
|
-
catch {
|
|
299
|
-
const $$ = $;
|
|
300
|
-
$$.$mol_exec('.', 'npm', 'install', '--omit=dev', name);
|
|
301
|
-
try {
|
|
302
|
-
$$.$mol_exec('.', 'npm', 'install', '--omit=dev', '@types/' + name);
|
|
303
|
-
}
|
|
304
|
-
catch (e) {
|
|
305
|
-
if ($$.$mol_fail_catch(e)) {
|
|
306
|
-
$$.$mol_fail_log(e);
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
try {
|
|
311
|
-
return target.require(name);
|
|
312
|
-
}
|
|
313
|
-
catch (error) {
|
|
314
|
-
if ($.$mol_fail_catch(error) && error.code === 'ERR_REQUIRE_ESM') {
|
|
315
|
-
const module = cache.get(name);
|
|
316
|
-
if (module)
|
|
317
|
-
return module;
|
|
318
|
-
throw import(name).then(module => cache.set(name, module));
|
|
319
|
-
}
|
|
320
|
-
$.$mol_fail_log(error);
|
|
321
|
-
return null;
|
|
322
|
-
}
|
|
323
|
-
},
|
|
324
|
-
set(target, name, value) {
|
|
325
|
-
target[name] = value;
|
|
326
|
-
return true;
|
|
327
|
-
},
|
|
328
|
-
});
|
|
329
|
-
const cache = new Map();
|
|
330
|
-
require = (req => Object.assign(function require(name) {
|
|
331
|
-
return $node[name];
|
|
332
|
-
}, req))(require);
|
|
333
|
-
|
|
334
408
|
;
|
|
335
409
|
"use strict";
|
|
336
410
|
var $;
|
|
@@ -358,11 +432,12 @@ var $;
|
|
|
358
432
|
get: () => stack_get() + '\n' + [
|
|
359
433
|
this.cause ?? 'no cause',
|
|
360
434
|
...this.errors.flatMap(e => [
|
|
361
|
-
e.stack,
|
|
435
|
+
String(e.stack),
|
|
362
436
|
...e instanceof $mol_error_mix || !e.cause ? [] : [e.cause]
|
|
363
437
|
])
|
|
364
438
|
].map(frame_normalize).join('\n')
|
|
365
439
|
});
|
|
440
|
+
// в nodejs, что б не дублировалось cause в консоли
|
|
366
441
|
Object.defineProperty(this, 'cause', {
|
|
367
442
|
get: () => cause
|
|
368
443
|
});
|
|
@@ -380,6 +455,169 @@ var $;
|
|
|
380
455
|
$.$mol_error_mix = $mol_error_mix;
|
|
381
456
|
})($ || ($ = {}));
|
|
382
457
|
|
|
458
|
+
;
|
|
459
|
+
"use strict";
|
|
460
|
+
var $;
|
|
461
|
+
(function ($) {
|
|
462
|
+
class $mol_data_error extends $mol_error_mix {
|
|
463
|
+
}
|
|
464
|
+
$.$mol_data_error = $mol_data_error;
|
|
465
|
+
})($ || ($ = {}));
|
|
466
|
+
|
|
467
|
+
;
|
|
468
|
+
"use strict";
|
|
469
|
+
var $;
|
|
470
|
+
(function ($) {
|
|
471
|
+
/**
|
|
472
|
+
* Checks for value of given enum and returns expected type.
|
|
473
|
+
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_data_enum_demo
|
|
474
|
+
*/
|
|
475
|
+
function $mol_data_enum(name, dict) {
|
|
476
|
+
const index = {};
|
|
477
|
+
for (let key in dict) {
|
|
478
|
+
if (Number.isNaN(Number(key))) {
|
|
479
|
+
index[dict[key]] = key;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return $mol_data_setup((value) => {
|
|
483
|
+
if (typeof index[value] !== 'string') {
|
|
484
|
+
return $mol_fail(new $mol_data_error(`${value} is not value of ${name} enum`));
|
|
485
|
+
}
|
|
486
|
+
return value;
|
|
487
|
+
}, { name, dict });
|
|
488
|
+
}
|
|
489
|
+
$.$mol_data_enum = $mol_data_enum;
|
|
490
|
+
})($ || ($ = {}));
|
|
491
|
+
|
|
492
|
+
;
|
|
493
|
+
"use strict";
|
|
494
|
+
|
|
495
|
+
;
|
|
496
|
+
"use strict";
|
|
497
|
+
var $;
|
|
498
|
+
(function ($) {
|
|
499
|
+
const mod = require /****/('module');
|
|
500
|
+
const internals = mod.builtinModules;
|
|
501
|
+
function $node_internal_check(name) {
|
|
502
|
+
if (name.startsWith('node:'))
|
|
503
|
+
return true;
|
|
504
|
+
return internals.includes(name);
|
|
505
|
+
}
|
|
506
|
+
$.$node_internal_check = $node_internal_check;
|
|
507
|
+
})($ || ($ = {}));
|
|
508
|
+
|
|
509
|
+
;
|
|
510
|
+
"use strict";
|
|
511
|
+
var $;
|
|
512
|
+
(function ($) {
|
|
513
|
+
function $mol_promise_like(val) {
|
|
514
|
+
try {
|
|
515
|
+
return val && typeof val === 'object' && 'then' in val && typeof val.then === 'function';
|
|
516
|
+
}
|
|
517
|
+
catch {
|
|
518
|
+
return false;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
$.$mol_promise_like = $mol_promise_like;
|
|
522
|
+
})($ || ($ = {}));
|
|
523
|
+
|
|
524
|
+
;
|
|
525
|
+
"use strict";
|
|
526
|
+
var $;
|
|
527
|
+
(function ($) {
|
|
528
|
+
const catched = new WeakSet();
|
|
529
|
+
function $mol_fail_catch(error) {
|
|
530
|
+
if (typeof error !== 'object')
|
|
531
|
+
return false;
|
|
532
|
+
if ($mol_promise_like(error))
|
|
533
|
+
$mol_fail_hidden(error);
|
|
534
|
+
if (catched.has(error))
|
|
535
|
+
return false;
|
|
536
|
+
catched.add(error);
|
|
537
|
+
return true;
|
|
538
|
+
}
|
|
539
|
+
$.$mol_fail_catch = $mol_fail_catch;
|
|
540
|
+
})($ || ($ = {}));
|
|
541
|
+
|
|
542
|
+
;
|
|
543
|
+
"use strict";
|
|
544
|
+
var $;
|
|
545
|
+
(function ($) {
|
|
546
|
+
function $mol_try(handler) {
|
|
547
|
+
try {
|
|
548
|
+
return handler();
|
|
549
|
+
}
|
|
550
|
+
catch (error) {
|
|
551
|
+
console.error(error);
|
|
552
|
+
return error;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
$.$mol_try = $mol_try;
|
|
556
|
+
})($ || ($ = {}));
|
|
557
|
+
|
|
558
|
+
;
|
|
559
|
+
"use strict";
|
|
560
|
+
var $;
|
|
561
|
+
(function ($) {
|
|
562
|
+
function $mol_fail_log(error) {
|
|
563
|
+
if ($mol_promise_like(error))
|
|
564
|
+
return false;
|
|
565
|
+
if (!$mol_fail_catch(error))
|
|
566
|
+
return false;
|
|
567
|
+
$mol_try(() => { $mol_fail_hidden(error); });
|
|
568
|
+
return true;
|
|
569
|
+
}
|
|
570
|
+
$.$mol_fail_log = $mol_fail_log;
|
|
571
|
+
})($ || ($ = {}));
|
|
572
|
+
|
|
573
|
+
;
|
|
574
|
+
"use strict";
|
|
575
|
+
var $;
|
|
576
|
+
(function ($) {
|
|
577
|
+
const path = require /****/('path');
|
|
578
|
+
const mod = require /****/('module');
|
|
579
|
+
const localRequire = mod.createRequire(path.join(process.cwd(), 'package.json'));
|
|
580
|
+
function $node_autoinstall(name) {
|
|
581
|
+
try {
|
|
582
|
+
localRequire.resolve(name);
|
|
583
|
+
}
|
|
584
|
+
catch {
|
|
585
|
+
this.$mol_run.spawn({ command: ['npm', 'install', '--omit=dev', name], dir: '.' });
|
|
586
|
+
try {
|
|
587
|
+
this.$mol_run.spawn({ command: ['npm', 'install', '--omit=dev', '@types/' + name], dir: '.' });
|
|
588
|
+
}
|
|
589
|
+
catch (e) {
|
|
590
|
+
if (this.$mol_promise_like(e))
|
|
591
|
+
this.$mol_fail_hidden(e);
|
|
592
|
+
this.$mol_fail_log(e);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
$.$node_autoinstall = $node_autoinstall;
|
|
597
|
+
})($ || ($ = {}));
|
|
598
|
+
|
|
599
|
+
;
|
|
600
|
+
"use strict";
|
|
601
|
+
var $node = new Proxy({ require }, {
|
|
602
|
+
get(target, name, wrapper) {
|
|
603
|
+
if (target[name])
|
|
604
|
+
return target[name];
|
|
605
|
+
if ($.$node_internal_check(name))
|
|
606
|
+
return target.require(name);
|
|
607
|
+
if (name[0] === '.')
|
|
608
|
+
return target.require(name);
|
|
609
|
+
$.$node_autoinstall(name);
|
|
610
|
+
return target.require(name);
|
|
611
|
+
},
|
|
612
|
+
set(target, name, value) {
|
|
613
|
+
target[name] = value;
|
|
614
|
+
return true;
|
|
615
|
+
},
|
|
616
|
+
});
|
|
617
|
+
require = (req => Object.assign(function require(name) {
|
|
618
|
+
return $node[name];
|
|
619
|
+
}, req))(require);
|
|
620
|
+
|
|
383
621
|
;
|
|
384
622
|
"use strict";
|
|
385
623
|
var $;
|
|
@@ -423,11 +661,32 @@ var $;
|
|
|
423
661
|
"use strict";
|
|
424
662
|
var $;
|
|
425
663
|
(function ($) {
|
|
664
|
+
/** Generates unique identifier. */
|
|
665
|
+
function $mol_guid(length = 8, exists = () => false) {
|
|
666
|
+
for (;;) {
|
|
667
|
+
let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
|
|
668
|
+
if (exists(id))
|
|
669
|
+
continue;
|
|
670
|
+
return id;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
$.$mol_guid = $mol_guid;
|
|
674
|
+
})($ || ($ = {}));
|
|
675
|
+
|
|
676
|
+
;
|
|
677
|
+
"use strict";
|
|
678
|
+
var $;
|
|
679
|
+
(function ($) {
|
|
680
|
+
/** Special status statuses. */
|
|
426
681
|
let $mol_wire_cursor;
|
|
427
682
|
(function ($mol_wire_cursor) {
|
|
683
|
+
/** Update required. */
|
|
428
684
|
$mol_wire_cursor[$mol_wire_cursor["stale"] = -1] = "stale";
|
|
685
|
+
/** Some of (transitive) pub update required. */
|
|
429
686
|
$mol_wire_cursor[$mol_wire_cursor["doubt"] = -2] = "doubt";
|
|
687
|
+
/** Actual state but may be dropped. */
|
|
430
688
|
$mol_wire_cursor[$mol_wire_cursor["fresh"] = -3] = "fresh";
|
|
689
|
+
/** State will never be changed. */
|
|
431
690
|
$mol_wire_cursor[$mol_wire_cursor["final"] = -4] = "final";
|
|
432
691
|
})($mol_wire_cursor = $.$mol_wire_cursor || ($.$mol_wire_cursor = {}));
|
|
433
692
|
})($ || ($ = {}));
|
|
@@ -436,12 +695,27 @@ var $;
|
|
|
436
695
|
"use strict";
|
|
437
696
|
var $;
|
|
438
697
|
(function ($) {
|
|
698
|
+
/**
|
|
699
|
+
* Collects subscribers in compact array. 28B
|
|
700
|
+
*/
|
|
439
701
|
class $mol_wire_pub extends Object {
|
|
702
|
+
constructor(id = `$mol_wire_pub:${$mol_guid()}`) {
|
|
703
|
+
super();
|
|
704
|
+
this[Symbol.toStringTag] = id;
|
|
705
|
+
}
|
|
706
|
+
[Symbol.toStringTag];
|
|
440
707
|
data = [];
|
|
708
|
+
// Derived objects should be Arrays.
|
|
441
709
|
static get [Symbol.species]() {
|
|
442
710
|
return Array;
|
|
443
711
|
}
|
|
444
|
-
|
|
712
|
+
/**
|
|
713
|
+
* Index of first subscriber.
|
|
714
|
+
*/
|
|
715
|
+
sub_from = 0; // 4B
|
|
716
|
+
/**
|
|
717
|
+
* All current subscribers.
|
|
718
|
+
*/
|
|
445
719
|
get sub_list() {
|
|
446
720
|
const res = [];
|
|
447
721
|
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
@@ -449,14 +723,23 @@ var $;
|
|
|
449
723
|
}
|
|
450
724
|
return res;
|
|
451
725
|
}
|
|
726
|
+
/**
|
|
727
|
+
* Has any subscribers or not.
|
|
728
|
+
*/
|
|
452
729
|
get sub_empty() {
|
|
453
730
|
return this.sub_from === this.data.length;
|
|
454
731
|
}
|
|
732
|
+
/**
|
|
733
|
+
* Subscribe subscriber to this publisher events and return position of subscriber that required to unsubscribe.
|
|
734
|
+
*/
|
|
455
735
|
sub_on(sub, pub_pos) {
|
|
456
736
|
const pos = this.data.length;
|
|
457
737
|
this.data.push(sub, pub_pos);
|
|
458
738
|
return pos;
|
|
459
739
|
}
|
|
740
|
+
/**
|
|
741
|
+
* Unsubscribe subscriber from this publisher events by subscriber position provided by `on(pub)`.
|
|
742
|
+
*/
|
|
460
743
|
sub_off(sub_pos) {
|
|
461
744
|
if (!(sub_pos < this.data.length)) {
|
|
462
745
|
$mol_fail(new Error(`Wrong pos ${sub_pos}`));
|
|
@@ -469,21 +752,39 @@ var $;
|
|
|
469
752
|
if (end === this.sub_from)
|
|
470
753
|
this.reap();
|
|
471
754
|
}
|
|
755
|
+
/**
|
|
756
|
+
* Called when last sub was unsubscribed.
|
|
757
|
+
**/
|
|
472
758
|
reap() { }
|
|
759
|
+
/**
|
|
760
|
+
* Autowire this publisher with current subscriber.
|
|
761
|
+
**/
|
|
473
762
|
promote() {
|
|
474
763
|
$mol_wire_auto()?.track_next(this);
|
|
475
764
|
}
|
|
765
|
+
/**
|
|
766
|
+
* Enforce actualization. Should not throw errors.
|
|
767
|
+
*/
|
|
476
768
|
fresh() { }
|
|
769
|
+
/**
|
|
770
|
+
* Allow to put data to caches in the subtree.
|
|
771
|
+
*/
|
|
477
772
|
complete() { }
|
|
478
773
|
get incompleted() {
|
|
479
774
|
return false;
|
|
480
775
|
}
|
|
776
|
+
/**
|
|
777
|
+
* Notify subscribers about self changes.
|
|
778
|
+
*/
|
|
481
779
|
emit(quant = $mol_wire_cursor.stale) {
|
|
482
780
|
for (let i = this.sub_from; i < this.data.length; i += 2) {
|
|
483
781
|
;
|
|
484
|
-
this.data[i].absorb(quant);
|
|
782
|
+
this.data[i].absorb(quant, this.data[i + 1]);
|
|
485
783
|
}
|
|
486
784
|
}
|
|
785
|
+
/**
|
|
786
|
+
* Moves peer from one position to another. Doesn't clear data at old position!
|
|
787
|
+
*/
|
|
487
788
|
peer_move(from_pos, to_pos) {
|
|
488
789
|
const peer = this.data[from_pos];
|
|
489
790
|
const self_pos = this.data[from_pos + 1];
|
|
@@ -491,6 +792,9 @@ var $;
|
|
|
491
792
|
this.data[to_pos + 1] = self_pos;
|
|
492
793
|
peer.peer_repos(self_pos, to_pos);
|
|
493
794
|
}
|
|
795
|
+
/**
|
|
796
|
+
* Updates self position in the peer.
|
|
797
|
+
*/
|
|
494
798
|
peer_repos(peer_pos, self_pos) {
|
|
495
799
|
this.data[peer_pos + 1] = self_pos;
|
|
496
800
|
}
|
|
@@ -506,10 +810,16 @@ var $;
|
|
|
506
810
|
var $;
|
|
507
811
|
(function ($) {
|
|
508
812
|
$.$mol_wire_auto_sub = null;
|
|
813
|
+
/**
|
|
814
|
+
* When fulfilled, all publishers are promoted to this subscriber on access to its.
|
|
815
|
+
*/
|
|
509
816
|
function $mol_wire_auto(next = $.$mol_wire_auto_sub) {
|
|
510
817
|
return $.$mol_wire_auto_sub = next;
|
|
511
818
|
}
|
|
512
819
|
$.$mol_wire_auto = $mol_wire_auto;
|
|
820
|
+
/**
|
|
821
|
+
* Affection queue. Used to prevent accidental stack overflow on emit.
|
|
822
|
+
*/
|
|
513
823
|
$.$mol_wire_affected = [];
|
|
514
824
|
})($ || ($ = {}));
|
|
515
825
|
|
|
@@ -517,6 +827,7 @@ var $;
|
|
|
517
827
|
"use strict";
|
|
518
828
|
var $;
|
|
519
829
|
(function ($) {
|
|
830
|
+
// https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview#
|
|
520
831
|
$['devtoolsFormatters'] ||= [];
|
|
521
832
|
function $mol_dev_format_register(config) {
|
|
522
833
|
$['devtoolsFormatters'].push(config);
|
|
@@ -524,6 +835,17 @@ var $;
|
|
|
524
835
|
$.$mol_dev_format_register = $mol_dev_format_register;
|
|
525
836
|
$.$mol_dev_format_head = Symbol('$mol_dev_format_head');
|
|
526
837
|
$.$mol_dev_format_body = Symbol('$mol_dev_format_body');
|
|
838
|
+
function $mol_dev_format_button(label, click) {
|
|
839
|
+
return $mol_dev_format_auto({
|
|
840
|
+
[$.$mol_dev_format_head]() {
|
|
841
|
+
return $.$mol_dev_format_span({ color: 'cornflowerblue' }, label);
|
|
842
|
+
},
|
|
843
|
+
[$.$mol_dev_format_body]() {
|
|
844
|
+
Promise.resolve().then(click);
|
|
845
|
+
return $.$mol_dev_format_span({});
|
|
846
|
+
}
|
|
847
|
+
});
|
|
848
|
+
}
|
|
527
849
|
$mol_dev_format_register({
|
|
528
850
|
header: (val, config = false) => {
|
|
529
851
|
if (config)
|
|
@@ -532,26 +854,59 @@ var $;
|
|
|
532
854
|
return null;
|
|
533
855
|
if ($.$mol_dev_format_head in val) {
|
|
534
856
|
try {
|
|
535
|
-
return val[$.$mol_dev_format_head]();
|
|
857
|
+
return val[$.$mol_dev_format_head]();
|
|
858
|
+
}
|
|
859
|
+
catch (error) {
|
|
860
|
+
return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
if (typeof val === 'function') {
|
|
864
|
+
return $mol_dev_format_native(val);
|
|
865
|
+
}
|
|
866
|
+
if (val instanceof Error) {
|
|
867
|
+
return $.$mol_dev_format_span({}, $mol_dev_format_native(val), ' ', $mol_dev_format_button('throw', () => $mol_fail_hidden(val)));
|
|
868
|
+
}
|
|
869
|
+
if (val instanceof Promise) {
|
|
870
|
+
return $.$mol_dev_format_shade($mol_dev_format_native(val), ' ', val[Symbol.toStringTag] ?? '');
|
|
871
|
+
}
|
|
872
|
+
if (Symbol.toStringTag in val) {
|
|
873
|
+
return $mol_dev_format_native(val);
|
|
874
|
+
}
|
|
875
|
+
return null;
|
|
876
|
+
},
|
|
877
|
+
hasBody: (val, config = false) => {
|
|
878
|
+
if (config)
|
|
879
|
+
return false;
|
|
880
|
+
if (!val)
|
|
881
|
+
return false;
|
|
882
|
+
// if( Error.isError( val ) ) true
|
|
883
|
+
if (val[$.$mol_dev_format_body])
|
|
884
|
+
return true;
|
|
885
|
+
return false;
|
|
886
|
+
},
|
|
887
|
+
body: (val, config = false) => {
|
|
888
|
+
if (config)
|
|
889
|
+
return null;
|
|
890
|
+
if (!val)
|
|
891
|
+
return null;
|
|
892
|
+
if ($.$mol_dev_format_body in val) {
|
|
893
|
+
try {
|
|
894
|
+
return val[$.$mol_dev_format_body]();
|
|
536
895
|
}
|
|
537
896
|
catch (error) {
|
|
538
897
|
return $.$mol_dev_format_accent($mol_dev_format_native(val), '💨', $mol_dev_format_native(error), '');
|
|
539
898
|
}
|
|
540
899
|
}
|
|
541
|
-
if (
|
|
542
|
-
|
|
543
|
-
}
|
|
544
|
-
if (Symbol.toStringTag in val) {
|
|
545
|
-
return $mol_dev_format_native(val);
|
|
546
|
-
}
|
|
900
|
+
// if( Error.isError( val ) ) {
|
|
901
|
+
// return $mol_dev_format_native( val )
|
|
902
|
+
// }
|
|
547
903
|
return null;
|
|
548
904
|
},
|
|
549
|
-
hasBody: val => val[$.$mol_dev_format_body],
|
|
550
|
-
body: val => val[$.$mol_dev_format_body](),
|
|
551
905
|
});
|
|
552
906
|
function $mol_dev_format_native(obj) {
|
|
553
907
|
if (typeof obj === 'undefined')
|
|
554
908
|
return $.$mol_dev_format_shade('undefined');
|
|
909
|
+
// if( ![ 'object', 'function', 'symbol' ].includes( typeof obj ) ) return obj
|
|
555
910
|
return [
|
|
556
911
|
'object',
|
|
557
912
|
{
|
|
@@ -586,42 +941,117 @@ var $;
|
|
|
586
941
|
];
|
|
587
942
|
}
|
|
588
943
|
$.$mol_dev_format_element = $mol_dev_format_element;
|
|
589
|
-
|
|
590
|
-
return $mol_dev_format_element('span', {
|
|
591
|
-
...style,
|
|
592
|
-
}, ...content);
|
|
593
|
-
}
|
|
594
|
-
$.$mol_dev_format_span = $mol_dev_format_span;
|
|
944
|
+
$.$mol_dev_format_span = $mol_dev_format_element.bind(null, 'span');
|
|
595
945
|
$.$mol_dev_format_div = $mol_dev_format_element.bind(null, 'div');
|
|
596
946
|
$.$mol_dev_format_ol = $mol_dev_format_element.bind(null, 'ol');
|
|
597
947
|
$.$mol_dev_format_li = $mol_dev_format_element.bind(null, 'li');
|
|
598
948
|
$.$mol_dev_format_table = $mol_dev_format_element.bind(null, 'table');
|
|
599
949
|
$.$mol_dev_format_tr = $mol_dev_format_element.bind(null, 'tr');
|
|
600
950
|
$.$mol_dev_format_td = $mol_dev_format_element.bind(null, 'td');
|
|
601
|
-
$.$mol_dev_format_accent =
|
|
951
|
+
$.$mol_dev_format_accent = $.$mol_dev_format_span.bind(null, {
|
|
602
952
|
'color': 'magenta',
|
|
603
953
|
});
|
|
604
|
-
$.$mol_dev_format_strong =
|
|
954
|
+
$.$mol_dev_format_strong = $.$mol_dev_format_span.bind(null, {
|
|
605
955
|
'font-weight': 'bold',
|
|
606
956
|
});
|
|
607
|
-
$.$mol_dev_format_string =
|
|
957
|
+
$.$mol_dev_format_string = $.$mol_dev_format_span.bind(null, {
|
|
608
958
|
'color': 'green',
|
|
609
959
|
});
|
|
610
|
-
$.$mol_dev_format_shade =
|
|
960
|
+
$.$mol_dev_format_shade = $.$mol_dev_format_span.bind(null, {
|
|
611
961
|
'color': 'gray',
|
|
612
962
|
});
|
|
613
963
|
$.$mol_dev_format_indent = $.$mol_dev_format_div.bind(null, {
|
|
614
|
-
'margin-
|
|
964
|
+
'margin-inline-start': '13px'
|
|
615
965
|
});
|
|
966
|
+
class Stack extends Array {
|
|
967
|
+
// [ Symbol.toPrimitive ]() {
|
|
968
|
+
// return this.toString()
|
|
969
|
+
// }
|
|
970
|
+
match(...args) {
|
|
971
|
+
return this.toString().match(...args);
|
|
972
|
+
}
|
|
973
|
+
split(...args) {
|
|
974
|
+
return this.toString().split(...args);
|
|
975
|
+
}
|
|
976
|
+
toString() {
|
|
977
|
+
return this.join('\n');
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
class Call extends Object {
|
|
981
|
+
type;
|
|
982
|
+
function;
|
|
983
|
+
method;
|
|
984
|
+
eval;
|
|
985
|
+
source;
|
|
986
|
+
offset;
|
|
987
|
+
pos;
|
|
988
|
+
object;
|
|
989
|
+
flags;
|
|
990
|
+
[Symbol.toStringTag];
|
|
991
|
+
constructor(call) {
|
|
992
|
+
super();
|
|
993
|
+
this.type = call.getTypeName() ?? '';
|
|
994
|
+
this.function = call.getFunctionName() ?? '';
|
|
995
|
+
this.method = call.getMethodName() ?? '';
|
|
996
|
+
if (this.method === this.function)
|
|
997
|
+
this.method = '';
|
|
998
|
+
// const func = c.getFunction()
|
|
999
|
+
this.pos = [call.getEnclosingLineNumber() ?? 0, call.getEnclosingColumnNumber() ?? 0];
|
|
1000
|
+
this.eval = call.getEvalOrigin() ?? '';
|
|
1001
|
+
this.source = call.getScriptNameOrSourceURL() ?? '';
|
|
1002
|
+
this.object = call.getThis();
|
|
1003
|
+
this.offset = call.getPosition();
|
|
1004
|
+
const flags = [];
|
|
1005
|
+
if (call.isAsync())
|
|
1006
|
+
flags.push('async');
|
|
1007
|
+
if (call.isConstructor())
|
|
1008
|
+
flags.push('constructor');
|
|
1009
|
+
if (call.isEval())
|
|
1010
|
+
flags.push('eval');
|
|
1011
|
+
if (call.isNative())
|
|
1012
|
+
flags.push('native');
|
|
1013
|
+
if (call.isPromiseAll())
|
|
1014
|
+
flags.push('PromiseAll');
|
|
1015
|
+
if (call.isToplevel())
|
|
1016
|
+
flags.push('top');
|
|
1017
|
+
this.flags = flags;
|
|
1018
|
+
const type = this.type ? this.type + '.' : '';
|
|
1019
|
+
const func = this.function || '<anon>';
|
|
1020
|
+
const method = this.method ? ' [' + this.method + '] ' : '';
|
|
1021
|
+
this[Symbol.toStringTag] = `${type}${func}${method}`;
|
|
1022
|
+
}
|
|
1023
|
+
[Symbol.toPrimitive]() {
|
|
1024
|
+
return this.toString();
|
|
1025
|
+
}
|
|
1026
|
+
toString() {
|
|
1027
|
+
const object = this.object || '';
|
|
1028
|
+
const label = this[Symbol.toStringTag];
|
|
1029
|
+
const source = `${this.source}:${this.pos.join(':')} #${this.offset}`;
|
|
1030
|
+
return `\tat ${object}${label} (${source})`;
|
|
1031
|
+
}
|
|
1032
|
+
[$.$mol_dev_format_head]() {
|
|
1033
|
+
return $.$mol_dev_format_div({}, $mol_dev_format_native(this), $.$mol_dev_format_shade(' '), ...this.object ? [
|
|
1034
|
+
$mol_dev_format_native(this.object),
|
|
1035
|
+
] : [], ...this.method ? [$.$mol_dev_format_shade(' ', ' [', this.method, ']')] : [], $.$mol_dev_format_shade(' ', this.flags.join(', ')));
|
|
1036
|
+
}
|
|
1037
|
+
}
|
|
1038
|
+
Error.prepareStackTrace ??= (error, stack) => new Stack(...stack.map(call => new Call(call)));
|
|
616
1039
|
})($ || ($ = {}));
|
|
617
1040
|
|
|
618
1041
|
;
|
|
619
1042
|
"use strict";
|
|
620
1043
|
var $;
|
|
621
1044
|
(function ($) {
|
|
1045
|
+
/**
|
|
1046
|
+
* Publisher that can auto collect other publishers. 32B
|
|
1047
|
+
*
|
|
1048
|
+
* P1 P2 P3 P4 S1 S2 S3
|
|
1049
|
+
* ^ ^
|
|
1050
|
+
* pubs_from subs_from
|
|
1051
|
+
*/
|
|
622
1052
|
class $mol_wire_pub_sub extends $mol_wire_pub {
|
|
623
|
-
pub_from = 0;
|
|
624
|
-
cursor = $mol_wire_cursor.stale;
|
|
1053
|
+
pub_from = 0; // 4B
|
|
1054
|
+
cursor = $mol_wire_cursor.stale; // 4B
|
|
625
1055
|
get temp() {
|
|
626
1056
|
return false;
|
|
627
1057
|
}
|
|
@@ -702,7 +1132,7 @@ var $;
|
|
|
702
1132
|
this.data.length = this.sub_from;
|
|
703
1133
|
this.cursor = this.pub_from;
|
|
704
1134
|
this.track_cut();
|
|
705
|
-
this.cursor = $mol_wire_cursor.
|
|
1135
|
+
this.cursor = $mol_wire_cursor.stale;
|
|
706
1136
|
}
|
|
707
1137
|
track_cut() {
|
|
708
1138
|
if (this.cursor < this.pub_from) {
|
|
@@ -732,17 +1162,34 @@ var $;
|
|
|
732
1162
|
pub?.complete();
|
|
733
1163
|
}
|
|
734
1164
|
}
|
|
735
|
-
absorb(quant = $mol_wire_cursor.stale) {
|
|
1165
|
+
absorb(quant = $mol_wire_cursor.stale, pos = -1) {
|
|
736
1166
|
if (this.cursor === $mol_wire_cursor.final)
|
|
737
1167
|
return;
|
|
738
1168
|
if (this.cursor >= quant)
|
|
739
1169
|
return;
|
|
740
1170
|
this.cursor = quant;
|
|
741
1171
|
this.emit($mol_wire_cursor.doubt);
|
|
1172
|
+
// if( pos >= 0 && pos < this.sub_from - 2 ) {
|
|
1173
|
+
// const pub = this.data[ pos ] as $mol_wire_pub
|
|
1174
|
+
// if( pub instanceof $mol_wire_task ) return
|
|
1175
|
+
// for(
|
|
1176
|
+
// let cursor = this.pub_from;
|
|
1177
|
+
// cursor < this.sub_from;
|
|
1178
|
+
// cursor += 2
|
|
1179
|
+
// ) {
|
|
1180
|
+
// const pub = this.data[ cursor ] as $mol_wire_pub
|
|
1181
|
+
// if( pub instanceof $mol_wire_task ) {
|
|
1182
|
+
// pub.destructor()
|
|
1183
|
+
// }
|
|
1184
|
+
// }
|
|
1185
|
+
// }
|
|
742
1186
|
}
|
|
743
1187
|
[$mol_dev_format_head]() {
|
|
744
1188
|
return $mol_dev_format_native(this);
|
|
745
1189
|
}
|
|
1190
|
+
/**
|
|
1191
|
+
* Is subscribed to any publisher or not.
|
|
1192
|
+
*/
|
|
746
1193
|
get pub_empty() {
|
|
747
1194
|
return this.sub_from === this.pub_from;
|
|
748
1195
|
}
|
|
@@ -783,6 +1230,13 @@ var $;
|
|
|
783
1230
|
var $;
|
|
784
1231
|
(function ($) {
|
|
785
1232
|
const wrappers = new WeakMap();
|
|
1233
|
+
/**
|
|
1234
|
+
* Suspendable task with support both sync/async api.
|
|
1235
|
+
*
|
|
1236
|
+
* A1 A2 A3 A4 P1 P2 P3 P4 S1 S2 S3
|
|
1237
|
+
* ^ ^ ^
|
|
1238
|
+
* args_from pubs_from subs_from
|
|
1239
|
+
**/
|
|
786
1240
|
class $mol_wire_fiber extends $mol_wire_pub_sub {
|
|
787
1241
|
task;
|
|
788
1242
|
host;
|
|
@@ -803,6 +1257,7 @@ var $;
|
|
|
803
1257
|
});
|
|
804
1258
|
}
|
|
805
1259
|
static sync() {
|
|
1260
|
+
// Sync whole fiber graph
|
|
806
1261
|
while (this.planning.size) {
|
|
807
1262
|
for (const fiber of this.planning) {
|
|
808
1263
|
this.planning.delete(fiber);
|
|
@@ -813,6 +1268,7 @@ var $;
|
|
|
813
1268
|
fiber.fresh();
|
|
814
1269
|
}
|
|
815
1270
|
}
|
|
1271
|
+
// Collect garbage
|
|
816
1272
|
while (this.reaping.size) {
|
|
817
1273
|
const fibers = this.reaping;
|
|
818
1274
|
this.reaping = new Set;
|
|
@@ -823,7 +1279,6 @@ var $;
|
|
|
823
1279
|
}
|
|
824
1280
|
}
|
|
825
1281
|
}
|
|
826
|
-
[Symbol.toStringTag];
|
|
827
1282
|
cache = undefined;
|
|
828
1283
|
get args() {
|
|
829
1284
|
return this.data.slice(0, this.pub_from);
|
|
@@ -839,16 +1294,15 @@ var $;
|
|
|
839
1294
|
return $mol_promise_like(this.cache);
|
|
840
1295
|
}
|
|
841
1296
|
field() {
|
|
842
|
-
return this.task.name + '
|
|
1297
|
+
return this.task.name + '()';
|
|
843
1298
|
}
|
|
844
1299
|
constructor(id, task, host, args) {
|
|
845
|
-
super();
|
|
1300
|
+
super(id);
|
|
846
1301
|
this.task = task;
|
|
847
1302
|
this.host = host;
|
|
848
1303
|
if (args)
|
|
849
1304
|
this.data.push(...args);
|
|
850
1305
|
this.pub_from = this.sub_from = args?.length ?? 0;
|
|
851
|
-
this[Symbol.toStringTag] = id;
|
|
852
1306
|
}
|
|
853
1307
|
plan() {
|
|
854
1308
|
$mol_wire_fiber.planning.add(this);
|
|
@@ -873,12 +1327,10 @@ var $;
|
|
|
873
1327
|
[$mol_wire_cursor.final]: '🔵',
|
|
874
1328
|
}[this.cursor] ?? this.cursor.toString();
|
|
875
1329
|
return $mol_dev_format_div({}, $mol_owning_check(this, this.cache)
|
|
876
|
-
? $
|
|
877
|
-
|
|
878
|
-
[$mol_dev_format_body]: () => $mol_dev_format_native(this),
|
|
879
|
-
})
|
|
880
|
-
: $mol_dev_format_shade($mol_dev_format_native(this), cursor), $mol_dev_format_auto(this.cache));
|
|
1330
|
+
? $mol_dev_format_shade(cursor)
|
|
1331
|
+
: $mol_dev_format_shade(this[Symbol.toStringTag], cursor), $mol_dev_format_auto(this.cache));
|
|
881
1332
|
}
|
|
1333
|
+
[$mol_dev_format_body]() { return null; }
|
|
882
1334
|
get $() {
|
|
883
1335
|
return (this.host ?? this.task)['$'];
|
|
884
1336
|
}
|
|
@@ -946,10 +1398,12 @@ var $;
|
|
|
946
1398
|
result = wrappers.get(result);
|
|
947
1399
|
}
|
|
948
1400
|
else {
|
|
949
|
-
|
|
1401
|
+
const put = (v) => {
|
|
950
1402
|
if (this.cache === result)
|
|
951
1403
|
this.absorb();
|
|
952
|
-
|
|
1404
|
+
return v;
|
|
1405
|
+
};
|
|
1406
|
+
wrappers.set(result, result = Object.assign(result.then(put, put), { destructor: result.destructor || (() => { }) }));
|
|
953
1407
|
const error = new Error(`Promise in ${this}`);
|
|
954
1408
|
Object.defineProperty(result, 'stack', { get: () => error.stack });
|
|
955
1409
|
}
|
|
@@ -966,6 +1420,10 @@ var $;
|
|
|
966
1420
|
this.cursor = $mol_wire_cursor.stale;
|
|
967
1421
|
this.fresh();
|
|
968
1422
|
}
|
|
1423
|
+
/**
|
|
1424
|
+
* Synchronous execution. Throws Promise when waits async task (SuspenseAPI provider).
|
|
1425
|
+
* Should be called inside SuspenseAPI consumer (ie fiber).
|
|
1426
|
+
*/
|
|
969
1427
|
sync() {
|
|
970
1428
|
if (!$mol_wire_fiber.warm) {
|
|
971
1429
|
return this.result();
|
|
@@ -980,6 +1438,10 @@ var $;
|
|
|
980
1438
|
}
|
|
981
1439
|
return this.cache;
|
|
982
1440
|
}
|
|
1441
|
+
/**
|
|
1442
|
+
* Asynchronous execution.
|
|
1443
|
+
* It's SuspenseAPI consumer. So SuspenseAPI providers can be called inside.
|
|
1444
|
+
*/
|
|
983
1445
|
async async_raw() {
|
|
984
1446
|
while (true) {
|
|
985
1447
|
this.fresh();
|
|
@@ -992,6 +1454,7 @@ var $;
|
|
|
992
1454
|
if (!$mol_promise_like(this.cache))
|
|
993
1455
|
return this.cache;
|
|
994
1456
|
if (this.cursor === $mol_wire_cursor.final) {
|
|
1457
|
+
// never ends on destructed fiber
|
|
995
1458
|
await new Promise(() => { });
|
|
996
1459
|
}
|
|
997
1460
|
}
|
|
@@ -1016,9 +1479,19 @@ var $;
|
|
|
1016
1479
|
}
|
|
1017
1480
|
destructor() {
|
|
1018
1481
|
super.destructor();
|
|
1019
|
-
|
|
1482
|
+
$mol_wire_fiber.planning.delete(this);
|
|
1483
|
+
if (!$mol_owning_check(this, this.cache))
|
|
1484
|
+
return;
|
|
1485
|
+
try {
|
|
1020
1486
|
this.cache.destructor();
|
|
1021
1487
|
}
|
|
1488
|
+
catch (result) {
|
|
1489
|
+
if ($mol_promise_like(result)) {
|
|
1490
|
+
const error = new Error(`Promise in ${this}.destructor()`);
|
|
1491
|
+
Object.defineProperty(result, 'stack', { get: () => error.stack });
|
|
1492
|
+
}
|
|
1493
|
+
$mol_fail_hidden(result);
|
|
1494
|
+
}
|
|
1022
1495
|
}
|
|
1023
1496
|
}
|
|
1024
1497
|
$.$mol_wire_fiber = $mol_wire_fiber;
|
|
@@ -1029,6 +1502,10 @@ var $;
|
|
|
1029
1502
|
var $;
|
|
1030
1503
|
(function ($) {
|
|
1031
1504
|
$.$mol_compare_deep_cache = new WeakMap();
|
|
1505
|
+
/**
|
|
1506
|
+
* Deeply compares two values. Returns true if equal.
|
|
1507
|
+
* Define `Symbol.toPrimitive` to customize.
|
|
1508
|
+
*/
|
|
1032
1509
|
function $mol_compare_deep(left, right) {
|
|
1033
1510
|
if (Object.is(left, right))
|
|
1034
1511
|
return true;
|
|
@@ -1055,7 +1532,7 @@ var $;
|
|
|
1055
1532
|
if (left instanceof RegExp)
|
|
1056
1533
|
return left.source === right.source && left.flags === right.flags;
|
|
1057
1534
|
if (left instanceof Error)
|
|
1058
|
-
return left.message === right.message && left.stack
|
|
1535
|
+
return left.message === right.message && $mol_compare_deep(left.stack, right.stack);
|
|
1059
1536
|
let left_cache = $.$mol_compare_deep_cache.get(left);
|
|
1060
1537
|
if (left_cache) {
|
|
1061
1538
|
const right_cache = left_cache.get(right);
|
|
@@ -1109,7 +1586,7 @@ var $;
|
|
|
1109
1586
|
if (len !== right.byteLength)
|
|
1110
1587
|
return false;
|
|
1111
1588
|
if (left instanceof DataView)
|
|
1112
|
-
return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer,
|
|
1589
|
+
return compare_buffer(new Uint8Array(left.buffer, left.byteOffset, left.byteLength), new Uint8Array(right.buffer, right.byteOffset, right.byteLength));
|
|
1113
1590
|
for (let i = 0; i < len; ++i) {
|
|
1114
1591
|
if (left[i] !== right[i])
|
|
1115
1592
|
return false;
|
|
@@ -1168,8 +1645,9 @@ var $;
|
|
|
1168
1645
|
"use strict";
|
|
1169
1646
|
var $;
|
|
1170
1647
|
(function ($) {
|
|
1648
|
+
/** Log begin of collapsed group only when some logged inside, returns func to close group */
|
|
1171
1649
|
function $mol_log3_area_lazy(event) {
|
|
1172
|
-
const self = this
|
|
1650
|
+
const self = this.$;
|
|
1173
1651
|
const stack = self.$mol_log3_stack;
|
|
1174
1652
|
const deep = stack.length;
|
|
1175
1653
|
let logged = false;
|
|
@@ -1192,6 +1670,7 @@ var $;
|
|
|
1192
1670
|
"use strict";
|
|
1193
1671
|
var $;
|
|
1194
1672
|
(function ($) {
|
|
1673
|
+
/** Position in any resource. */
|
|
1195
1674
|
class $mol_span extends $mol_object2 {
|
|
1196
1675
|
uri;
|
|
1197
1676
|
source;
|
|
@@ -1207,13 +1686,17 @@ var $;
|
|
|
1207
1686
|
this.length = length;
|
|
1208
1687
|
this[Symbol.toStringTag] = this.uri + ('#' + this.row + ':' + this.col + '/' + this.length);
|
|
1209
1688
|
}
|
|
1689
|
+
/** Span for begin of unknown resource */
|
|
1210
1690
|
static unknown = $mol_span.begin('?');
|
|
1691
|
+
/** Makes new span for begin of resource. */
|
|
1211
1692
|
static begin(uri, source = '') {
|
|
1212
1693
|
return new $mol_span(uri, source, 1, 1, 0);
|
|
1213
1694
|
}
|
|
1695
|
+
/** Makes new span for end of resource. */
|
|
1214
1696
|
static end(uri, source) {
|
|
1215
1697
|
return new $mol_span(uri, source, 1, source.length + 1, 0);
|
|
1216
1698
|
}
|
|
1699
|
+
/** Makes new span for entire resource. */
|
|
1217
1700
|
static entire(uri, source) {
|
|
1218
1701
|
return new $mol_span(uri, source, 1, 1, source.length);
|
|
1219
1702
|
}
|
|
@@ -1228,15 +1711,19 @@ var $;
|
|
|
1228
1711
|
length: this.length
|
|
1229
1712
|
};
|
|
1230
1713
|
}
|
|
1714
|
+
/** Makes new error for this span. */
|
|
1231
1715
|
error(message, Class = Error) {
|
|
1232
1716
|
return new Class(`${message} (${this})`);
|
|
1233
1717
|
}
|
|
1718
|
+
/** Makes new span for same uri. */
|
|
1234
1719
|
span(row, col, length) {
|
|
1235
1720
|
return new $mol_span(this.uri, this.source, row, col, length);
|
|
1236
1721
|
}
|
|
1722
|
+
/** Makes new span after end of this. */
|
|
1237
1723
|
after(length = 0) {
|
|
1238
1724
|
return new $mol_span(this.uri, this.source, this.row, this.col + this.length, length);
|
|
1239
1725
|
}
|
|
1726
|
+
/** Makes new span between begin and end. */
|
|
1240
1727
|
slice(begin, end = -1) {
|
|
1241
1728
|
let len = this.length;
|
|
1242
1729
|
if (begin < 0)
|
|
@@ -1259,6 +1746,7 @@ var $;
|
|
|
1259
1746
|
"use strict";
|
|
1260
1747
|
var $;
|
|
1261
1748
|
(function ($) {
|
|
1749
|
+
/** Serializes tree to string in tree format. */
|
|
1262
1750
|
function $mol_tree2_to_string(tree) {
|
|
1263
1751
|
let output = [];
|
|
1264
1752
|
function dump(tree, prefix = '') {
|
|
@@ -1292,12 +1780,35 @@ var $;
|
|
|
1292
1780
|
"use strict";
|
|
1293
1781
|
var $;
|
|
1294
1782
|
(function ($) {
|
|
1783
|
+
function $mol_maybe(value) {
|
|
1784
|
+
return (value == null) ? [] : [value];
|
|
1785
|
+
}
|
|
1786
|
+
$.$mol_maybe = $mol_maybe;
|
|
1787
|
+
})($ || ($ = {}));
|
|
1788
|
+
|
|
1789
|
+
;
|
|
1790
|
+
"use strict";
|
|
1791
|
+
var $;
|
|
1792
|
+
(function ($) {
|
|
1793
|
+
/**
|
|
1794
|
+
* Abstract Syntax Tree with human readable serialization.
|
|
1795
|
+
* Avoid direct instantiation. Use static factories instead.
|
|
1796
|
+
* @see https://github.com/nin-jin/tree.d
|
|
1797
|
+
*/
|
|
1295
1798
|
class $mol_tree2 extends Object {
|
|
1296
1799
|
type;
|
|
1297
1800
|
value;
|
|
1298
1801
|
kids;
|
|
1299
1802
|
span;
|
|
1300
|
-
constructor(
|
|
1803
|
+
constructor(
|
|
1804
|
+
/** Type of structural node, `value` should be empty */
|
|
1805
|
+
type,
|
|
1806
|
+
/** Content of data node, `type` should be empty */
|
|
1807
|
+
value,
|
|
1808
|
+
/** Child nodes */
|
|
1809
|
+
kids,
|
|
1810
|
+
/** Position in most far source resource */
|
|
1811
|
+
span) {
|
|
1301
1812
|
super();
|
|
1302
1813
|
this.type = type;
|
|
1303
1814
|
this.value = value;
|
|
@@ -1305,12 +1816,15 @@ var $;
|
|
|
1305
1816
|
this.span = span;
|
|
1306
1817
|
this[Symbol.toStringTag] = type || '\\' + value;
|
|
1307
1818
|
}
|
|
1819
|
+
/** Makes collection node. */
|
|
1308
1820
|
static list(kids, span = $mol_span.unknown) {
|
|
1309
1821
|
return new $mol_tree2('', '', kids, span);
|
|
1310
1822
|
}
|
|
1823
|
+
/** Makes new derived collection node. */
|
|
1311
1824
|
list(kids) {
|
|
1312
1825
|
return $mol_tree2.list(kids, this.span);
|
|
1313
1826
|
}
|
|
1827
|
+
/** Makes data node for any string. */
|
|
1314
1828
|
static data(value, kids = [], span = $mol_span.unknown) {
|
|
1315
1829
|
const chunks = value.split('\n');
|
|
1316
1830
|
if (chunks.length > 1) {
|
|
@@ -1324,21 +1838,26 @@ var $;
|
|
|
1324
1838
|
}
|
|
1325
1839
|
return new $mol_tree2('', value, kids, span);
|
|
1326
1840
|
}
|
|
1841
|
+
/** Makes new derived data node. */
|
|
1327
1842
|
data(value, kids = []) {
|
|
1328
1843
|
return $mol_tree2.data(value, kids, this.span);
|
|
1329
1844
|
}
|
|
1845
|
+
/** Makes struct node. */
|
|
1330
1846
|
static struct(type, kids = [], span = $mol_span.unknown) {
|
|
1331
1847
|
if (/[ \n\t\\]/.test(type)) {
|
|
1332
1848
|
$$.$mol_fail(span.error(`Wrong type ${JSON.stringify(type)}`));
|
|
1333
1849
|
}
|
|
1334
1850
|
return new $mol_tree2(type, '', kids, span);
|
|
1335
1851
|
}
|
|
1852
|
+
/** Makes new derived structural node. */
|
|
1336
1853
|
struct(type, kids = []) {
|
|
1337
1854
|
return $mol_tree2.struct(type, kids, this.span);
|
|
1338
1855
|
}
|
|
1856
|
+
/** Makes new derived node with different kids id defined. */
|
|
1339
1857
|
clone(kids, span = this.span) {
|
|
1340
1858
|
return new $mol_tree2(this.type, this.value, kids, span);
|
|
1341
1859
|
}
|
|
1860
|
+
/** Returns multiline text content. */
|
|
1342
1861
|
text() {
|
|
1343
1862
|
var values = [];
|
|
1344
1863
|
for (var kid of this.kids) {
|
|
@@ -1348,42 +1867,53 @@ var $;
|
|
|
1348
1867
|
}
|
|
1349
1868
|
return this.value + values.join('\n');
|
|
1350
1869
|
}
|
|
1870
|
+
/** Parses tree format. */
|
|
1871
|
+
/** @deprecated Use $mol_tree2_from_string */
|
|
1351
1872
|
static fromString(str, uri = 'unknown') {
|
|
1352
1873
|
return $$.$mol_tree2_from_string(str, uri);
|
|
1353
1874
|
}
|
|
1875
|
+
/** Serializes to tree format. */
|
|
1354
1876
|
toString() {
|
|
1355
1877
|
return $$.$mol_tree2_to_string(this);
|
|
1356
1878
|
}
|
|
1879
|
+
/** Makes new tree with node overrided by path. */
|
|
1357
1880
|
insert(value, ...path) {
|
|
1881
|
+
return this.update($mol_maybe(value), ...path)[0];
|
|
1882
|
+
}
|
|
1883
|
+
/** Makes new tree with node overrided by path. */
|
|
1884
|
+
update(value, ...path) {
|
|
1358
1885
|
if (path.length === 0)
|
|
1359
1886
|
return value;
|
|
1360
1887
|
const type = path[0];
|
|
1361
1888
|
if (typeof type === 'string') {
|
|
1362
1889
|
let replaced = false;
|
|
1363
|
-
const sub = this.kids.
|
|
1890
|
+
const sub = this.kids.flatMap((item, index) => {
|
|
1364
1891
|
if (item.type !== type)
|
|
1365
1892
|
return item;
|
|
1366
1893
|
replaced = true;
|
|
1367
|
-
return item.
|
|
1894
|
+
return item.update(value, ...path.slice(1));
|
|
1368
1895
|
}).filter(Boolean);
|
|
1369
1896
|
if (!replaced && value) {
|
|
1370
|
-
sub.push(this.struct(type, []).
|
|
1897
|
+
sub.push(...this.struct(type, []).update(value, ...path.slice(1)));
|
|
1371
1898
|
}
|
|
1372
|
-
return this.clone(sub);
|
|
1899
|
+
return [this.clone(sub)];
|
|
1373
1900
|
}
|
|
1374
1901
|
else if (typeof type === 'number') {
|
|
1375
|
-
const
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1902
|
+
const ins = (this.kids[type] || this.list([]))
|
|
1903
|
+
.update(value, ...path.slice(1));
|
|
1904
|
+
return [this.clone([
|
|
1905
|
+
...this.kids.slice(0, type),
|
|
1906
|
+
...ins,
|
|
1907
|
+
...this.kids.slice(type + 1),
|
|
1908
|
+
])];
|
|
1379
1909
|
}
|
|
1380
1910
|
else {
|
|
1381
1911
|
const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
|
|
1382
|
-
.
|
|
1383
|
-
|
|
1384
|
-
return this.clone(kids);
|
|
1912
|
+
.flatMap(item => item.update(value, ...path.slice(1)));
|
|
1913
|
+
return [this.clone(kids)];
|
|
1385
1914
|
}
|
|
1386
1915
|
}
|
|
1916
|
+
/** Query nodes by path. */
|
|
1387
1917
|
select(...path) {
|
|
1388
1918
|
let next = [this];
|
|
1389
1919
|
for (const type of path) {
|
|
@@ -1410,6 +1940,7 @@ var $;
|
|
|
1410
1940
|
}
|
|
1411
1941
|
return this.list(next);
|
|
1412
1942
|
}
|
|
1943
|
+
/** Filter kids by path or value. */
|
|
1413
1944
|
filter(path, value) {
|
|
1414
1945
|
const sub = this.kids.filter(item => {
|
|
1415
1946
|
var found = item.select(...path);
|
|
@@ -1437,9 +1968,11 @@ var $;
|
|
|
1437
1968
|
$mol_fail_hidden(error);
|
|
1438
1969
|
}
|
|
1439
1970
|
}
|
|
1971
|
+
/** Transform tree through context with transformers */
|
|
1440
1972
|
hack(belt, context = {}) {
|
|
1441
1973
|
return [].concat(...this.kids.map(child => child.hack_self(belt, context)));
|
|
1442
1974
|
}
|
|
1975
|
+
/** Makes Error with node coordinates. */
|
|
1443
1976
|
error(message, Class = Error) {
|
|
1444
1977
|
return this.span.error(`${message}\n${this.clone([])}`, Class);
|
|
1445
1978
|
}
|
|
@@ -1457,6 +1990,7 @@ var $;
|
|
|
1457
1990
|
"use strict";
|
|
1458
1991
|
var $;
|
|
1459
1992
|
(function ($) {
|
|
1993
|
+
/** Syntax error with cordinates and source line snippet. */
|
|
1460
1994
|
class $mol_error_syntax extends SyntaxError {
|
|
1461
1995
|
reason;
|
|
1462
1996
|
line;
|
|
@@ -1475,6 +2009,7 @@ var $;
|
|
|
1475
2009
|
"use strict";
|
|
1476
2010
|
var $;
|
|
1477
2011
|
(function ($) {
|
|
2012
|
+
/** Parses tree format from string. */
|
|
1478
2013
|
function $mol_tree2_from_string(str, uri = '?') {
|
|
1479
2014
|
const span = $mol_span.entire(uri, str);
|
|
1480
2015
|
var root = $mol_tree2.list([], span);
|
|
@@ -1484,6 +2019,7 @@ var $;
|
|
|
1484
2019
|
var indent = 0;
|
|
1485
2020
|
var line_start = pos;
|
|
1486
2021
|
row++;
|
|
2022
|
+
// read indent
|
|
1487
2023
|
while (str.length > pos && str[pos] == '\t') {
|
|
1488
2024
|
indent++;
|
|
1489
2025
|
pos++;
|
|
@@ -1492,8 +2028,10 @@ var $;
|
|
|
1492
2028
|
min_indent = indent;
|
|
1493
2029
|
}
|
|
1494
2030
|
indent -= min_indent;
|
|
2031
|
+
// invalid tab size
|
|
1495
2032
|
if (indent < 0 || indent >= stack.length) {
|
|
1496
2033
|
const sp = span.span(row, 1, pos - line_start);
|
|
2034
|
+
// skip error line
|
|
1497
2035
|
while (str.length > pos && str[pos] != '\n') {
|
|
1498
2036
|
pos++;
|
|
1499
2037
|
}
|
|
@@ -1508,7 +2046,9 @@ var $;
|
|
|
1508
2046
|
}
|
|
1509
2047
|
stack.length = indent + 1;
|
|
1510
2048
|
var parent = stack[indent];
|
|
2049
|
+
// parse types
|
|
1511
2050
|
while (str.length > pos && str[pos] != '\\' && str[pos] != '\n') {
|
|
2051
|
+
// type can not contain space and tab
|
|
1512
2052
|
var error_start = pos;
|
|
1513
2053
|
while (str.length > pos && (str[pos] == ' ' || str[pos] == '\t')) {
|
|
1514
2054
|
pos++;
|
|
@@ -1520,6 +2060,7 @@ var $;
|
|
|
1520
2060
|
const sp = span.span(row, error_start - line_start + 1, pos - error_start);
|
|
1521
2061
|
this.$mol_fail(new this.$mol_error_syntax(`Wrong nodes separator`, str.substring(line_start, line_end), sp));
|
|
1522
2062
|
}
|
|
2063
|
+
// read type
|
|
1523
2064
|
var type_start = pos;
|
|
1524
2065
|
while (str.length > pos &&
|
|
1525
2066
|
str[pos] != '\\' &&
|
|
@@ -1534,10 +2075,12 @@ var $;
|
|
|
1534
2075
|
parent_kids.push(next);
|
|
1535
2076
|
parent = next;
|
|
1536
2077
|
}
|
|
2078
|
+
// read one space if exists
|
|
1537
2079
|
if (str.length > pos && str[pos] == ' ') {
|
|
1538
2080
|
pos++;
|
|
1539
2081
|
}
|
|
1540
2082
|
}
|
|
2083
|
+
// read data
|
|
1541
2084
|
if (str.length > pos && str[pos] == '\\') {
|
|
1542
2085
|
var data_start = pos;
|
|
1543
2086
|
while (str.length > pos && str[pos] != '\n') {
|
|
@@ -1548,6 +2091,7 @@ var $;
|
|
|
1548
2091
|
parent_kids.push(next);
|
|
1549
2092
|
parent = next;
|
|
1550
2093
|
}
|
|
2094
|
+
// now must be end of text
|
|
1551
2095
|
if (str.length === pos && stack.length > 0) {
|
|
1552
2096
|
const sp = span.span(row, pos - line_start + 1, 1);
|
|
1553
2097
|
this.$mol_fail(new this.$mol_error_syntax(`Unexpected EOF, LF required`, str.substring(line_start, str.length), sp));
|
|
@@ -1560,6 +2104,30 @@ var $;
|
|
|
1560
2104
|
$.$mol_tree2_from_string = $mol_tree2_from_string;
|
|
1561
2105
|
})($ || ($ = {}));
|
|
1562
2106
|
|
|
2107
|
+
;
|
|
2108
|
+
"use strict";
|
|
2109
|
+
var $;
|
|
2110
|
+
(function ($) {
|
|
2111
|
+
function $mol_array_chunks(array, rule) {
|
|
2112
|
+
const br = typeof rule === 'number' ? (_, i) => i % rule === 0 : rule;
|
|
2113
|
+
let chunk = [];
|
|
2114
|
+
const chunks = [];
|
|
2115
|
+
for (let i = 0; i < array.length; ++i) {
|
|
2116
|
+
const item = array[i];
|
|
2117
|
+
if (br(item, i)) {
|
|
2118
|
+
if (chunk.length)
|
|
2119
|
+
chunks.push(chunk);
|
|
2120
|
+
chunk = [];
|
|
2121
|
+
}
|
|
2122
|
+
chunk.push(item);
|
|
2123
|
+
}
|
|
2124
|
+
if (chunk.length)
|
|
2125
|
+
chunks.push(chunk);
|
|
2126
|
+
return chunks;
|
|
2127
|
+
}
|
|
2128
|
+
$.$mol_array_chunks = $mol_array_chunks;
|
|
2129
|
+
})($ || ($ = {}));
|
|
2130
|
+
|
|
1563
2131
|
;
|
|
1564
2132
|
"use strict";
|
|
1565
2133
|
var $;
|
|
@@ -1580,7 +2148,9 @@ var $;
|
|
|
1580
2148
|
}
|
|
1581
2149
|
if (ArrayBuffer.isView(json)) {
|
|
1582
2150
|
const buf = new Uint8Array(json.buffer, json.byteOffset, json.byteLength);
|
|
1583
|
-
|
|
2151
|
+
const codes = [...buf].map(b => b.toString(16).toUpperCase().padStart(2, '0'));
|
|
2152
|
+
const str = $mol_array_chunks(codes, 8).map(c => c.join(' ')).join('\n');
|
|
2153
|
+
return $mol_tree2.data(str, [], span);
|
|
1584
2154
|
}
|
|
1585
2155
|
if (json instanceof Date) {
|
|
1586
2156
|
return new $mol_tree2('', json.toISOString(), [], span);
|
|
@@ -1614,6 +2184,7 @@ var $;
|
|
|
1614
2184
|
"use strict";
|
|
1615
2185
|
var $;
|
|
1616
2186
|
(function ($) {
|
|
2187
|
+
/** Module for working with terminal. Text coloring when output in terminal */
|
|
1617
2188
|
class $mol_term_color {
|
|
1618
2189
|
static reset = this.ansi(0, 0);
|
|
1619
2190
|
static bold = this.ansi(1, 22);
|
|
@@ -1663,7 +2234,7 @@ var $;
|
|
|
1663
2234
|
function $mol_log3_node_make(level, output, type, color) {
|
|
1664
2235
|
return function $mol_log3_logger(event) {
|
|
1665
2236
|
if (!event.time)
|
|
1666
|
-
event = { time: new Date().toISOString()
|
|
2237
|
+
event = { ...event, time: new Date().toISOString() };
|
|
1667
2238
|
let tree = this.$mol_tree2_from_json(event);
|
|
1668
2239
|
tree = tree.struct(type, tree.kids);
|
|
1669
2240
|
let str = color(tree.toString());
|
|
@@ -1685,32 +2256,41 @@ var $;
|
|
|
1685
2256
|
"use strict";
|
|
1686
2257
|
var $;
|
|
1687
2258
|
(function ($) {
|
|
2259
|
+
/** One-shot fiber */
|
|
1688
2260
|
class $mol_wire_task extends $mol_wire_fiber {
|
|
1689
2261
|
static getter(task) {
|
|
1690
2262
|
return function $mol_wire_task_get(host, args) {
|
|
1691
2263
|
const sub = $mol_wire_auto();
|
|
1692
2264
|
const existen = sub?.track_next();
|
|
2265
|
+
let cause = '';
|
|
1693
2266
|
reuse: if (existen) {
|
|
1694
2267
|
if (!existen.temp)
|
|
1695
2268
|
break reuse;
|
|
1696
|
-
if (existen.host !== host)
|
|
2269
|
+
if (existen.host !== host) {
|
|
2270
|
+
cause = 'host';
|
|
1697
2271
|
break reuse;
|
|
1698
|
-
|
|
2272
|
+
}
|
|
2273
|
+
if (existen.task !== task) {
|
|
2274
|
+
cause = 'task';
|
|
1699
2275
|
break reuse;
|
|
1700
|
-
|
|
2276
|
+
}
|
|
2277
|
+
if (!$mol_compare_deep(existen.args, args)) {
|
|
2278
|
+
cause = 'args';
|
|
1701
2279
|
break reuse;
|
|
2280
|
+
}
|
|
1702
2281
|
return existen;
|
|
1703
2282
|
}
|
|
1704
2283
|
const key = (host?.[Symbol.toStringTag] ?? host) + ('.' + task.name + '<#>');
|
|
1705
2284
|
const next = new $mol_wire_task(key, task, host, args);
|
|
2285
|
+
// Disabled because non-idempotency is required for try-catch
|
|
1706
2286
|
if (existen?.temp) {
|
|
1707
2287
|
$$.$mol_log3_warn({
|
|
1708
2288
|
place: '$mol_wire_task',
|
|
1709
|
-
message: `
|
|
2289
|
+
message: `Different ${cause} on restart`,
|
|
1710
2290
|
sub,
|
|
1711
|
-
|
|
2291
|
+
prev: existen,
|
|
1712
2292
|
next,
|
|
1713
|
-
hint: '
|
|
2293
|
+
hint: 'Maybe required additional memoization',
|
|
1714
2294
|
});
|
|
1715
2295
|
}
|
|
1716
2296
|
return next;
|
|
@@ -1735,7 +2315,7 @@ var $;
|
|
|
1735
2315
|
try {
|
|
1736
2316
|
next[Symbol.toStringTag] = this[Symbol.toStringTag];
|
|
1737
2317
|
}
|
|
1738
|
-
catch {
|
|
2318
|
+
catch { // Promises throw in strict mode
|
|
1739
2319
|
Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
|
|
1740
2320
|
}
|
|
1741
2321
|
}
|
|
@@ -1748,6 +2328,10 @@ var $;
|
|
|
1748
2328
|
this.emit();
|
|
1749
2329
|
return next;
|
|
1750
2330
|
}
|
|
2331
|
+
destructor() {
|
|
2332
|
+
super.destructor();
|
|
2333
|
+
this.cursor = $mol_wire_cursor.final;
|
|
2334
|
+
}
|
|
1751
2335
|
}
|
|
1752
2336
|
$.$mol_wire_task = $mol_wire_task;
|
|
1753
2337
|
})($ || ($ = {}));
|
|
@@ -1765,18 +2349,46 @@ var $;
|
|
|
1765
2349
|
factories.set(val, make);
|
|
1766
2350
|
return make;
|
|
1767
2351
|
}
|
|
2352
|
+
const getters = new WeakMap();
|
|
2353
|
+
function get_prop(host, field) {
|
|
2354
|
+
let props = getters.get(host);
|
|
2355
|
+
let get_val = props?.[field];
|
|
2356
|
+
if (get_val)
|
|
2357
|
+
return get_val;
|
|
2358
|
+
get_val = (next) => {
|
|
2359
|
+
if (next !== undefined)
|
|
2360
|
+
host[field] = next;
|
|
2361
|
+
return host[field];
|
|
2362
|
+
};
|
|
2363
|
+
Object.defineProperty(get_val, 'name', { value: field });
|
|
2364
|
+
if (!props) {
|
|
2365
|
+
props = {};
|
|
2366
|
+
getters.set(host, props);
|
|
2367
|
+
}
|
|
2368
|
+
props[field] = get_val;
|
|
2369
|
+
return get_val;
|
|
2370
|
+
}
|
|
2371
|
+
/**
|
|
2372
|
+
* Convert asynchronous (promise-based) API to synchronous by wrapping function and method calls in a fiber.
|
|
2373
|
+
* @see https://mol.hyoo.ru/#!section=docs/=1fcpsq_1wh0h2
|
|
2374
|
+
*/
|
|
1768
2375
|
function $mol_wire_sync(obj) {
|
|
1769
2376
|
return new Proxy(obj, {
|
|
1770
2377
|
get(obj, field) {
|
|
1771
2378
|
let val = obj[field];
|
|
2379
|
+
const temp = $mol_wire_task.getter(typeof val === 'function' ? val : get_prop(obj, field));
|
|
1772
2380
|
if (typeof val !== 'function')
|
|
1773
|
-
return
|
|
1774
|
-
const temp = $mol_wire_task.getter(val);
|
|
2381
|
+
return temp(obj, []).sync();
|
|
1775
2382
|
return function $mol_wire_sync(...args) {
|
|
1776
2383
|
const fiber = temp(obj, args);
|
|
1777
2384
|
return fiber.sync();
|
|
1778
2385
|
};
|
|
1779
2386
|
},
|
|
2387
|
+
set(obj, field, next) {
|
|
2388
|
+
const temp = $mol_wire_task.getter(get_prop(obj, field));
|
|
2389
|
+
temp(obj, [next]).sync();
|
|
2390
|
+
return true;
|
|
2391
|
+
},
|
|
1780
2392
|
construct(obj, args) {
|
|
1781
2393
|
const temp = $mol_wire_task.getter(factory(obj));
|
|
1782
2394
|
return temp(obj, args).sync();
|
|
@@ -1910,144 +2522,6 @@ var $;
|
|
|
1910
2522
|
$.$mol_run = $mol_run;
|
|
1911
2523
|
})($ || ($ = {}));
|
|
1912
2524
|
|
|
1913
|
-
;
|
|
1914
|
-
"use strict";
|
|
1915
|
-
var $;
|
|
1916
|
-
(function ($) {
|
|
1917
|
-
function $mol_exec(dir, command, ...args) {
|
|
1918
|
-
return this.$mol_run.spawn({ command: [command, ...args], dir });
|
|
1919
|
-
}
|
|
1920
|
-
$.$mol_exec = $mol_exec;
|
|
1921
|
-
})($ || ($ = {}));
|
|
1922
|
-
|
|
1923
|
-
;
|
|
1924
|
-
"use strict";
|
|
1925
|
-
var $;
|
|
1926
|
-
(function ($) {
|
|
1927
|
-
const TextEncoder = globalThis.TextEncoder ?? $node.util.TextEncoder;
|
|
1928
|
-
const encoder = new TextEncoder();
|
|
1929
|
-
function $mol_charset_encode(value) {
|
|
1930
|
-
return encoder.encode(value);
|
|
1931
|
-
}
|
|
1932
|
-
$.$mol_charset_encode = $mol_charset_encode;
|
|
1933
|
-
})($ || ($ = {}));
|
|
1934
|
-
|
|
1935
|
-
;
|
|
1936
|
-
"use strict";
|
|
1937
|
-
var $;
|
|
1938
|
-
(function ($) {
|
|
1939
|
-
function $mol_int62_string_ensure(str) {
|
|
1940
|
-
if (typeof str !== 'string')
|
|
1941
|
-
return null;
|
|
1942
|
-
return $mol_int62_from_string(str) && str;
|
|
1943
|
-
}
|
|
1944
|
-
$.$mol_int62_string_ensure = $mol_int62_string_ensure;
|
|
1945
|
-
$.$mol_int62_max = (2 ** 30) - 1;
|
|
1946
|
-
$.$mol_int62_min = -(2 ** 30);
|
|
1947
|
-
$.$mol_int62_range = $.$mol_int62_max - $.$mol_int62_min + 1;
|
|
1948
|
-
function $mol_int62_to_string({ lo, hi }) {
|
|
1949
|
-
lo = (lo + $.$mol_int62_range) % $.$mol_int62_range;
|
|
1950
|
-
hi = (hi + $.$mol_int62_range) % $.$mol_int62_range;
|
|
1951
|
-
return lo.toString(36) + '_' + hi.toString(36);
|
|
1952
|
-
}
|
|
1953
|
-
$.$mol_int62_to_string = $mol_int62_to_string;
|
|
1954
|
-
function $mol_int62_from_string(str) {
|
|
1955
|
-
const [str_lo, str_hi] = str.split('_');
|
|
1956
|
-
const int_lo = parseInt(str_lo, 36);
|
|
1957
|
-
const int_hi = parseInt(str_hi, 36);
|
|
1958
|
-
if (int_lo.toString(36) !== str_lo || int_hi.toString(36) !== str_hi) {
|
|
1959
|
-
return null;
|
|
1960
|
-
}
|
|
1961
|
-
return {
|
|
1962
|
-
lo: (int_lo - $.$mol_int62_min) % $.$mol_int62_range + $.$mol_int62_min,
|
|
1963
|
-
hi: (int_hi - $.$mol_int62_min) % $.$mol_int62_range + $.$mol_int62_min,
|
|
1964
|
-
};
|
|
1965
|
-
}
|
|
1966
|
-
$.$mol_int62_from_string = $mol_int62_from_string;
|
|
1967
|
-
function $mol_int62_compare(left_lo, left_hi, right_lo, right_hi) {
|
|
1968
|
-
return (right_hi - left_hi) || (right_lo - left_lo);
|
|
1969
|
-
}
|
|
1970
|
-
$.$mol_int62_compare = $mol_int62_compare;
|
|
1971
|
-
function $mol_int62_inc(lo, hi, max = $.$mol_int62_max) {
|
|
1972
|
-
if (lo === max) {
|
|
1973
|
-
return { lo: -max, hi: hi + 1 };
|
|
1974
|
-
}
|
|
1975
|
-
else {
|
|
1976
|
-
return { lo: lo + 1, hi };
|
|
1977
|
-
}
|
|
1978
|
-
}
|
|
1979
|
-
$.$mol_int62_inc = $mol_int62_inc;
|
|
1980
|
-
function $mol_int62_random() {
|
|
1981
|
-
return {
|
|
1982
|
-
lo: Math.floor(Math.random() * $.$mol_int62_range + $.$mol_int62_min),
|
|
1983
|
-
hi: Math.floor(Math.random() * $.$mol_int62_range + $.$mol_int62_min),
|
|
1984
|
-
};
|
|
1985
|
-
}
|
|
1986
|
-
$.$mol_int62_random = $mol_int62_random;
|
|
1987
|
-
function $mol_int62_hash_string(str) {
|
|
1988
|
-
return $mol_int62_to_string($mol_int62_hash_buffer($mol_charset_encode(str)));
|
|
1989
|
-
}
|
|
1990
|
-
$.$mol_int62_hash_string = $mol_int62_hash_string;
|
|
1991
|
-
function $mol_int62_hash_buffer(buf, seed = { lo: 0, hi: 0 }) {
|
|
1992
|
-
let h1 = 0xdeadbeef ^ seed.lo;
|
|
1993
|
-
let h2 = 0x41c6ce57 ^ seed.hi;
|
|
1994
|
-
for (const byte of buf) {
|
|
1995
|
-
h1 = Math.imul(h1 ^ byte, 2654435761);
|
|
1996
|
-
h2 = Math.imul(h2 ^ byte, 1597334677);
|
|
1997
|
-
}
|
|
1998
|
-
h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
|
|
1999
|
-
h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
|
|
2000
|
-
return { lo: h1 << 1 >> 1, hi: h2 << 1 >> 1 };
|
|
2001
|
-
}
|
|
2002
|
-
$.$mol_int62_hash_buffer = $mol_int62_hash_buffer;
|
|
2003
|
-
})($ || ($ = {}));
|
|
2004
|
-
|
|
2005
|
-
;
|
|
2006
|
-
"use strict";
|
|
2007
|
-
|
|
2008
|
-
;
|
|
2009
|
-
"use strict";
|
|
2010
|
-
var $;
|
|
2011
|
-
(function ($) {
|
|
2012
|
-
function $mol_data_setup(value, config) {
|
|
2013
|
-
return Object.assign(value, {
|
|
2014
|
-
config,
|
|
2015
|
-
Value: null
|
|
2016
|
-
});
|
|
2017
|
-
}
|
|
2018
|
-
$.$mol_data_setup = $mol_data_setup;
|
|
2019
|
-
})($ || ($ = {}));
|
|
2020
|
-
|
|
2021
|
-
;
|
|
2022
|
-
"use strict";
|
|
2023
|
-
var $;
|
|
2024
|
-
(function ($) {
|
|
2025
|
-
class $mol_data_error extends $mol_error_mix {
|
|
2026
|
-
}
|
|
2027
|
-
$.$mol_data_error = $mol_data_error;
|
|
2028
|
-
})($ || ($ = {}));
|
|
2029
|
-
|
|
2030
|
-
;
|
|
2031
|
-
"use strict";
|
|
2032
|
-
var $;
|
|
2033
|
-
(function ($) {
|
|
2034
|
-
function $mol_data_enum(name, dict) {
|
|
2035
|
-
const index = {};
|
|
2036
|
-
for (let key in dict) {
|
|
2037
|
-
if (Number.isNaN(Number(key))) {
|
|
2038
|
-
index[dict[key]] = key;
|
|
2039
|
-
}
|
|
2040
|
-
}
|
|
2041
|
-
return $mol_data_setup((value) => {
|
|
2042
|
-
if (typeof index[value] !== 'string') {
|
|
2043
|
-
return $mol_fail(new $mol_data_error(`${value} is not value of ${name} enum`));
|
|
2044
|
-
}
|
|
2045
|
-
return value;
|
|
2046
|
-
}, { name, dict });
|
|
2047
|
-
}
|
|
2048
|
-
$.$mol_data_enum = $mol_data_enum;
|
|
2049
|
-
})($ || ($ = {}));
|
|
2050
|
-
|
|
2051
2525
|
;
|
|
2052
2526
|
"use strict";
|
|
2053
2527
|
var $;
|
|
@@ -2059,73 +2533,52 @@ var $;
|
|
|
2059
2533
|
"use strict";
|
|
2060
2534
|
var $;
|
|
2061
2535
|
(function ($) {
|
|
2062
|
-
function $
|
|
2063
|
-
|
|
2536
|
+
function $mol_base64_url_encode(buffer) {
|
|
2537
|
+
return buffer.toBase64({ alphabet: 'base64url', omitPadding: true });
|
|
2064
2538
|
}
|
|
2065
|
-
$.$
|
|
2539
|
+
$.$mol_base64_url_encode = $mol_base64_url_encode;
|
|
2540
|
+
function $mol_base64_url_decode(str) {
|
|
2541
|
+
return Uint8Array.fromBase64(str, { alphabet: 'base64url' });
|
|
2542
|
+
}
|
|
2543
|
+
$.$mol_base64_url_decode = $mol_base64_url_decode;
|
|
2066
2544
|
})($ || ($ = {}));
|
|
2067
2545
|
|
|
2068
2546
|
;
|
|
2069
2547
|
"use strict";
|
|
2070
2548
|
var $;
|
|
2071
2549
|
(function ($) {
|
|
2072
|
-
function $
|
|
2550
|
+
function $mol_base64_url_encode_node(str) {
|
|
2073
2551
|
if (!str)
|
|
2074
2552
|
return '';
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
return Buffer.from(str).toString('base64');
|
|
2553
|
+
const buf = Buffer.isBuffer(str) ? str : Buffer.from(str);
|
|
2554
|
+
return buf.toString('base64url').replace(/=/g, '');
|
|
2078
2555
|
}
|
|
2079
|
-
$.$
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
;
|
|
2084
|
-
"use strict";
|
|
2085
|
-
var $;
|
|
2086
|
-
(function ($) {
|
|
2087
|
-
function $mol_base64_decode(base64) {
|
|
2088
|
-
throw new Error('Not implemented');
|
|
2556
|
+
$.$mol_base64_url_encode_node = $mol_base64_url_encode_node;
|
|
2557
|
+
if (!('toBase64' in Uint8Array.prototype)) {
|
|
2558
|
+
$.$mol_base64_url_encode = $mol_base64_url_encode_node;
|
|
2089
2559
|
}
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
;
|
|
2094
|
-
"use strict";
|
|
2095
|
-
var $;
|
|
2096
|
-
(function ($) {
|
|
2097
|
-
function $mol_base64_decode_node(base64Str) {
|
|
2098
|
-
base64Str = base64Str.replace(/-/g, '+').replace(/_/g, '/');
|
|
2099
|
-
const buffer = Buffer.from(base64Str, 'base64');
|
|
2560
|
+
function $mol_base64_url_decode_node(str) {
|
|
2561
|
+
// without Uint8Array breaks $mol_compare_deep
|
|
2562
|
+
const buffer = Buffer.from(str, 'base64url');
|
|
2100
2563
|
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
2101
2564
|
}
|
|
2102
|
-
$.$
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
;
|
|
2107
|
-
"use strict";
|
|
2108
|
-
var $;
|
|
2109
|
-
(function ($) {
|
|
2110
|
-
function $mol_base64_url_encode(buffer) {
|
|
2111
|
-
return $mol_base64_encode(buffer).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
2112
|
-
}
|
|
2113
|
-
$.$mol_base64_url_encode = $mol_base64_url_encode;
|
|
2114
|
-
function $mol_base64_url_decode(str) {
|
|
2115
|
-
return $mol_base64_decode(str.replace(/-/g, '+').replace(/_/g, '/'));
|
|
2565
|
+
$.$mol_base64_url_decode_node = $mol_base64_url_decode_node;
|
|
2566
|
+
if (!('fromBase64' in Uint8Array)) {
|
|
2567
|
+
$.$mol_base64_url_decode = $mol_base64_url_decode_node;
|
|
2116
2568
|
}
|
|
2117
|
-
$.$mol_base64_url_decode = $mol_base64_url_decode;
|
|
2118
2569
|
})($ || ($ = {}));
|
|
2119
2570
|
|
|
2120
2571
|
;
|
|
2121
2572
|
"use strict";
|
|
2122
2573
|
var $;
|
|
2123
2574
|
(function ($) {
|
|
2575
|
+
/** @FIXME Need polyfill for Safari and Node (https://github.com/microsoft/MSR-JavaScript-Crypto/) */
|
|
2124
2576
|
const algorithm = {
|
|
2125
2577
|
name: 'ECDSA',
|
|
2126
2578
|
hash: 'SHA-256',
|
|
2127
2579
|
namedCurve: "P-256",
|
|
2128
2580
|
};
|
|
2581
|
+
/** Asymmetric signing pair with shortest payload */
|
|
2129
2582
|
async function $mol_crypto_auditor_pair() {
|
|
2130
2583
|
const pair = await $mol_crypto_native.subtle.generateKey(algorithm, true, ['sign', 'verify']);
|
|
2131
2584
|
return {
|
|
@@ -2134,8 +2587,10 @@ var $;
|
|
|
2134
2587
|
};
|
|
2135
2588
|
}
|
|
2136
2589
|
$.$mol_crypto_auditor_pair = $mol_crypto_auditor_pair;
|
|
2590
|
+
/** Asymmetric signing public key wrapper with shortest payload */
|
|
2137
2591
|
class $mol_crypto_auditor_public extends Object {
|
|
2138
2592
|
native;
|
|
2593
|
+
/** Key size in bytes. */
|
|
2139
2594
|
static size_str = 86;
|
|
2140
2595
|
static size_bin = 64;
|
|
2141
2596
|
constructor(native) {
|
|
@@ -2156,10 +2611,12 @@ var $;
|
|
|
2156
2611
|
y: serial.slice(43, 86),
|
|
2157
2612
|
}, algorithm, true, ['verify']));
|
|
2158
2613
|
}
|
|
2614
|
+
/** 86 bytes */
|
|
2159
2615
|
async serial() {
|
|
2160
2616
|
const { x, y } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
|
|
2161
2617
|
return x + y;
|
|
2162
2618
|
}
|
|
2619
|
+
/** 64 bytes */
|
|
2163
2620
|
async toArray() {
|
|
2164
2621
|
const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
|
|
2165
2622
|
return new Uint8Array([
|
|
@@ -2172,8 +2629,10 @@ var $;
|
|
|
2172
2629
|
}
|
|
2173
2630
|
}
|
|
2174
2631
|
$.$mol_crypto_auditor_public = $mol_crypto_auditor_public;
|
|
2632
|
+
/** Asymmetric signing private key wrapper with shortest payload */
|
|
2175
2633
|
class $mol_crypto_auditor_private extends Object {
|
|
2176
2634
|
native;
|
|
2635
|
+
/** Key size in bytes. */
|
|
2177
2636
|
static size_str = 129;
|
|
2178
2637
|
static size_bin = 96;
|
|
2179
2638
|
constructor(native) {
|
|
@@ -2196,10 +2655,12 @@ var $;
|
|
|
2196
2655
|
d: serial.slice(86, 129),
|
|
2197
2656
|
}, algorithm, true, ['sign']));
|
|
2198
2657
|
}
|
|
2658
|
+
/** 129 bytes */
|
|
2199
2659
|
async serial() {
|
|
2200
2660
|
const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
|
|
2201
2661
|
return x + y + d;
|
|
2202
2662
|
}
|
|
2663
|
+
/** 96 bytes */
|
|
2203
2664
|
async toArray() {
|
|
2204
2665
|
const { x, y, d } = await $mol_crypto_native.subtle.exportKey('jwk', this.native);
|
|
2205
2666
|
return new Uint8Array([
|
|
@@ -2208,14 +2669,17 @@ var $;
|
|
|
2208
2669
|
...$mol_base64_url_decode(d),
|
|
2209
2670
|
]);
|
|
2210
2671
|
}
|
|
2672
|
+
/** 64 bytes */
|
|
2211
2673
|
async sign(data) {
|
|
2212
2674
|
return await $mol_crypto_native.subtle.sign(algorithm, this.native, data);
|
|
2213
2675
|
}
|
|
2676
|
+
/** Makes public key from private */
|
|
2214
2677
|
async public() {
|
|
2215
2678
|
return await $mol_crypto_auditor_public.from($mol_crypto_auditor_private_to_public(await this.serial()));
|
|
2216
2679
|
}
|
|
2217
2680
|
}
|
|
2218
2681
|
$.$mol_crypto_auditor_private = $mol_crypto_auditor_private;
|
|
2682
|
+
/** Sign size in bytes. */
|
|
2219
2683
|
$.$mol_crypto_auditor_sign_size = 64;
|
|
2220
2684
|
function $mol_crypto_auditor_private_to_public(serial) {
|
|
2221
2685
|
return serial.slice(0, 86);
|
|
@@ -2284,16 +2748,23 @@ var $;
|
|
|
2284
2748
|
const level = $mol_data_enum('level', $hyoo_crowd_peer_level);
|
|
2285
2749
|
let $hyoo_crowd_unit_kind;
|
|
2286
2750
|
(function ($hyoo_crowd_unit_kind) {
|
|
2751
|
+
/** Grab Land by King */
|
|
2287
2752
|
$hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["grab"] = 0] = "grab";
|
|
2753
|
+
/** Join Peer to Land */
|
|
2288
2754
|
$hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["join"] = 1] = "join";
|
|
2755
|
+
/* Give Level for Peer for Land */
|
|
2289
2756
|
$hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["give"] = 2] = "give";
|
|
2757
|
+
/** Add Data to Land by joined Peer with right Level */
|
|
2290
2758
|
$hyoo_crowd_unit_kind[$hyoo_crowd_unit_kind["data"] = 3] = "data";
|
|
2291
2759
|
})($hyoo_crowd_unit_kind = $.$hyoo_crowd_unit_kind || ($.$hyoo_crowd_unit_kind = {}));
|
|
2292
2760
|
let $hyoo_crowd_unit_group;
|
|
2293
2761
|
(function ($hyoo_crowd_unit_group) {
|
|
2762
|
+
/** Join and Give units */
|
|
2294
2763
|
$hyoo_crowd_unit_group[$hyoo_crowd_unit_group["auth"] = 0] = "auth";
|
|
2764
|
+
/** Data units */
|
|
2295
2765
|
$hyoo_crowd_unit_group[$hyoo_crowd_unit_group["data"] = 1] = "data";
|
|
2296
2766
|
})($hyoo_crowd_unit_group = $.$hyoo_crowd_unit_group || ($.$hyoo_crowd_unit_group = {}));
|
|
2767
|
+
/** Independent part of data. */
|
|
2297
2768
|
class $hyoo_crowd_unit extends Object {
|
|
2298
2769
|
land;
|
|
2299
2770
|
auth;
|
|
@@ -2304,7 +2775,24 @@ var $;
|
|
|
2304
2775
|
time;
|
|
2305
2776
|
data;
|
|
2306
2777
|
bin;
|
|
2307
|
-
constructor(
|
|
2778
|
+
constructor(
|
|
2779
|
+
/** Identifier of land. */
|
|
2780
|
+
land,
|
|
2781
|
+
/** Identifier of auth. */
|
|
2782
|
+
auth,
|
|
2783
|
+
/** Identifier of head node. */
|
|
2784
|
+
head,
|
|
2785
|
+
/** Self identifier inside head after prev before next. */
|
|
2786
|
+
self,
|
|
2787
|
+
/** Identifier of next node. */
|
|
2788
|
+
next,
|
|
2789
|
+
/** Identifier of prev node. */
|
|
2790
|
+
prev,
|
|
2791
|
+
/** Monotonic real clock. 4B / info = 31b */
|
|
2792
|
+
time,
|
|
2793
|
+
/** type-size = bin<0 | null=0 | json>0 */
|
|
2794
|
+
/** Associated atomic data. mem = 4B+ / bin = (0|8B)+ / type-size-info = 16b */
|
|
2795
|
+
data, bin) {
|
|
2308
2796
|
super();
|
|
2309
2797
|
this.land = land;
|
|
2310
2798
|
this.auth = auth;
|
|
@@ -2432,9 +2920,28 @@ var $;
|
|
|
2432
2920
|
buff.set(next);
|
|
2433
2921
|
return buff;
|
|
2434
2922
|
}
|
|
2923
|
+
// land( next?: $mol_int62_pair ) {
|
|
2924
|
+
// if( next ) {
|
|
2925
|
+
// this.setInt32( offset.land_lo, next.lo, true )
|
|
2926
|
+
// this.setInt32( offset.land_hi, next.hi, true )
|
|
2927
|
+
// return next
|
|
2928
|
+
// } else {
|
|
2929
|
+
// return {
|
|
2930
|
+
// lo: this.getInt32( offset.land_lo, true ),
|
|
2931
|
+
// hi: this.getInt32( offset.land_hi, true ),
|
|
2932
|
+
// }
|
|
2933
|
+
// }
|
|
2934
|
+
// }
|
|
2435
2935
|
size() {
|
|
2436
2936
|
return Math.ceil(Math.abs(this.getInt16(offset.size, true)) / 8) * 8 + offset.data + $mol_crypto_auditor_sign_size;
|
|
2437
2937
|
}
|
|
2938
|
+
// data() {
|
|
2939
|
+
// const info = this.getUint16( offset.data )
|
|
2940
|
+
// const size = Math.abs( info )
|
|
2941
|
+
// const buf = new Uint8Array( this.buffer, this.byteOffset + offset.sens, size )
|
|
2942
|
+
// const data = info > 0 ? JSON.parse( $mol_charset_decode( buf ) ) : info < 0 ? buf : null
|
|
2943
|
+
// return data
|
|
2944
|
+
// }
|
|
2438
2945
|
sens() {
|
|
2439
2946
|
return new Uint8Array(this.buffer, this.byteOffset, this.size() - $mol_crypto_auditor_sign_size);
|
|
2440
2947
|
}
|
|
@@ -2500,61 +3007,51 @@ var $;
|
|
|
2500
3007
|
"use strict";
|
|
2501
3008
|
var $;
|
|
2502
3009
|
(function ($) {
|
|
2503
|
-
function $mol_guid(length = 8, exists = () => false) {
|
|
2504
|
-
for (;;) {
|
|
2505
|
-
let id = Math.random().toString(36).substring(2, length + 2).toUpperCase();
|
|
2506
|
-
if (exists(id))
|
|
2507
|
-
continue;
|
|
2508
|
-
return id;
|
|
2509
|
-
}
|
|
2510
|
-
}
|
|
2511
|
-
$.$mol_guid = $mol_guid;
|
|
2512
|
-
})($ || ($ = {}));
|
|
2513
|
-
|
|
2514
|
-
;
|
|
2515
|
-
"use strict";
|
|
2516
|
-
var $;
|
|
2517
|
-
(function ($) {
|
|
2518
|
-
$.$mol_key_store = new WeakMap();
|
|
2519
3010
|
const TypedArray = Object.getPrototypeOf(Uint8Array);
|
|
3011
|
+
/** Returns string key for any value. */
|
|
2520
3012
|
function $mol_key(value) {
|
|
2521
|
-
|
|
2522
|
-
return value.toString() + 'n';
|
|
2523
|
-
if (typeof value === 'symbol')
|
|
2524
|
-
return value.description;
|
|
2525
|
-
if (!value)
|
|
2526
|
-
return JSON.stringify(value);
|
|
2527
|
-
if (typeof value !== 'object' && typeof value !== 'function')
|
|
2528
|
-
return JSON.stringify(value);
|
|
2529
|
-
return JSON.stringify(value, (field, value) => {
|
|
3013
|
+
primitives: {
|
|
2530
3014
|
if (typeof value === 'bigint')
|
|
2531
3015
|
return value.toString() + 'n';
|
|
2532
3016
|
if (typeof value === 'symbol')
|
|
2533
|
-
return value.description
|
|
3017
|
+
return `Symbol(${value.description})`;
|
|
2534
3018
|
if (!value)
|
|
2535
|
-
return value;
|
|
3019
|
+
return JSON.stringify(value); // 0, null, ""
|
|
2536
3020
|
if (typeof value !== 'object' && typeof value !== 'function')
|
|
2537
|
-
return value;
|
|
3021
|
+
return JSON.stringify(value); // boolean, number, string
|
|
3022
|
+
}
|
|
3023
|
+
caching: {
|
|
3024
|
+
let key = $mol_key_store.get(value);
|
|
3025
|
+
if (key)
|
|
3026
|
+
return key;
|
|
3027
|
+
}
|
|
3028
|
+
objects: {
|
|
3029
|
+
if (value instanceof TypedArray) {
|
|
3030
|
+
return `${value[Symbol.toStringTag]}([${[...value].map(v => $mol_key(v))}])`;
|
|
3031
|
+
}
|
|
2538
3032
|
if (Array.isArray(value))
|
|
2539
|
-
return value
|
|
2540
|
-
const proto = Reflect.getPrototypeOf(value);
|
|
2541
|
-
if (!proto)
|
|
2542
|
-
return value;
|
|
2543
|
-
if (Reflect.getPrototypeOf(proto) === null)
|
|
2544
|
-
return value;
|
|
2545
|
-
if ('toJSON' in value)
|
|
2546
|
-
return value;
|
|
3033
|
+
return `[${value.map(v => $mol_key(v))}]`;
|
|
2547
3034
|
if (value instanceof RegExp)
|
|
2548
3035
|
return value.toString();
|
|
2549
|
-
if (value instanceof
|
|
2550
|
-
return
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
3036
|
+
if (value instanceof Date)
|
|
3037
|
+
return `Date(${value.valueOf()})`;
|
|
3038
|
+
}
|
|
3039
|
+
structures: {
|
|
3040
|
+
const proto = Reflect.getPrototypeOf(value);
|
|
3041
|
+
if (!proto || !Reflect.getPrototypeOf(proto)) {
|
|
3042
|
+
return `{${Object.entries(value).map(([k, v]) => JSON.stringify(k) + ':' + $mol_key(v))}}`;
|
|
3043
|
+
}
|
|
3044
|
+
}
|
|
3045
|
+
handlers: {
|
|
3046
|
+
if ($mol_key_handle in value) {
|
|
3047
|
+
return value[$mol_key_handle]();
|
|
3048
|
+
}
|
|
3049
|
+
}
|
|
3050
|
+
containers: {
|
|
3051
|
+
const key = JSON.stringify('#' + $mol_guid());
|
|
3052
|
+
$mol_key_store.set(value, key);
|
|
2556
3053
|
return key;
|
|
2557
|
-
}
|
|
3054
|
+
}
|
|
2558
3055
|
}
|
|
2559
3056
|
$.$mol_key = $mol_key;
|
|
2560
3057
|
})($ || ($ = {}));
|
|
@@ -2598,6 +3095,9 @@ var $;
|
|
|
2598
3095
|
"use strict";
|
|
2599
3096
|
var $;
|
|
2600
3097
|
(function ($) {
|
|
3098
|
+
/**
|
|
3099
|
+
* Decorates method to fiber to ensure it is executed only once inside other fiber.
|
|
3100
|
+
*/
|
|
2601
3101
|
function $mol_wire_method(host, field, descr) {
|
|
2602
3102
|
if (!descr)
|
|
2603
3103
|
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
@@ -2630,20 +3130,21 @@ var $;
|
|
|
2630
3130
|
"use strict";
|
|
2631
3131
|
var $;
|
|
2632
3132
|
(function ($) {
|
|
3133
|
+
/** Long-living fiber. */
|
|
2633
3134
|
class $mol_wire_atom extends $mol_wire_fiber {
|
|
2634
3135
|
static solo(host, task) {
|
|
2635
|
-
const field = task.name + '
|
|
3136
|
+
const field = task.name + '()';
|
|
2636
3137
|
const existen = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
|
|
2637
3138
|
if (existen)
|
|
2638
3139
|
return existen;
|
|
2639
3140
|
const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
|
|
2640
|
-
const key = prefix + ('.' +
|
|
3141
|
+
const key = prefix + ('.' + task.name + '<>');
|
|
2641
3142
|
const fiber = new $mol_wire_atom(key, task, host, []);
|
|
2642
3143
|
(host ?? task)[field] = fiber;
|
|
2643
3144
|
return fiber;
|
|
2644
3145
|
}
|
|
2645
3146
|
static plex(host, task, key) {
|
|
2646
|
-
const field = task.name + '
|
|
3147
|
+
const field = task.name + '()';
|
|
2647
3148
|
let dict = Object.getOwnPropertyDescriptor(host ?? task, field)?.value;
|
|
2648
3149
|
const prefix = host?.[Symbol.toStringTag] ?? (host instanceof Function ? $$.$mol_func_name(host) : host);
|
|
2649
3150
|
const key_str = $mol_key(key);
|
|
@@ -2680,7 +3181,17 @@ var $;
|
|
|
2680
3181
|
}
|
|
2681
3182
|
$mol_wire_atom.watching.add(this);
|
|
2682
3183
|
}
|
|
3184
|
+
/**
|
|
3185
|
+
* Update atom value through another temp fiber.
|
|
3186
|
+
*/
|
|
2683
3187
|
resync(args) {
|
|
3188
|
+
// enforce pulling tasks abort
|
|
3189
|
+
for (let cursor = this.pub_from; cursor < this.sub_from; cursor += 2) {
|
|
3190
|
+
const pub = this.data[cursor];
|
|
3191
|
+
if (pub && pub instanceof $mol_wire_task) {
|
|
3192
|
+
pub.destructor();
|
|
3193
|
+
}
|
|
3194
|
+
}
|
|
2684
3195
|
return this.put(this.task.call(this.host, ...args));
|
|
2685
3196
|
}
|
|
2686
3197
|
once() {
|
|
@@ -2707,8 +3218,15 @@ var $;
|
|
|
2707
3218
|
(this.host ?? this.task)[this.field()] = null;
|
|
2708
3219
|
}
|
|
2709
3220
|
else {
|
|
2710
|
-
;
|
|
2711
|
-
(this.host ?? this.task)[this.field()]
|
|
3221
|
+
const key = $mol_key(this.args[0]);
|
|
3222
|
+
const map = (this.host ?? this.task)[this.field()];
|
|
3223
|
+
if (!map.has(key))
|
|
3224
|
+
this.$.$mol_log3_warn({
|
|
3225
|
+
place: this,
|
|
3226
|
+
message: 'Absent key on destruction',
|
|
3227
|
+
hint: 'Check for $mol_key(key) is not changed',
|
|
3228
|
+
});
|
|
3229
|
+
map.delete(key);
|
|
2712
3230
|
}
|
|
2713
3231
|
}
|
|
2714
3232
|
put(next) {
|
|
@@ -2728,7 +3246,7 @@ var $;
|
|
|
2728
3246
|
try {
|
|
2729
3247
|
next[Symbol.toStringTag] = this[Symbol.toStringTag];
|
|
2730
3248
|
}
|
|
2731
|
-
catch {
|
|
3249
|
+
catch { // Promises throw in strict mode
|
|
2732
3250
|
Object.defineProperty(next, Symbol.toStringTag, { value: this[Symbol.toStringTag] });
|
|
2733
3251
|
}
|
|
2734
3252
|
}
|
|
@@ -2756,6 +3274,7 @@ var $;
|
|
|
2756
3274
|
"use strict";
|
|
2757
3275
|
var $;
|
|
2758
3276
|
(function ($) {
|
|
3277
|
+
/** Decorates solo object channel to [mol_wire_atom](../atom/atom.ts). */
|
|
2759
3278
|
function $mol_wire_solo(host, field, descr) {
|
|
2760
3279
|
if (!descr)
|
|
2761
3280
|
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
@@ -2794,6 +3313,7 @@ var $;
|
|
|
2794
3313
|
"use strict";
|
|
2795
3314
|
var $;
|
|
2796
3315
|
(function ($) {
|
|
3316
|
+
/** Reactive memoizing multiplexed property decorator. */
|
|
2797
3317
|
function $mol_wire_plex(host, field, descr) {
|
|
2798
3318
|
if (!descr)
|
|
2799
3319
|
descr = Reflect.getOwnPropertyDescriptor(host, field);
|
|
@@ -2832,7 +3352,25 @@ var $;
|
|
|
2832
3352
|
"use strict";
|
|
2833
3353
|
var $;
|
|
2834
3354
|
(function ($) {
|
|
3355
|
+
/**
|
|
3356
|
+
* Reactive memoizing solo property decorator from [mol_wire](../wire/README.md)
|
|
3357
|
+
* @example
|
|
3358
|
+
* '@' $mol_mem
|
|
3359
|
+
* name(next?: string) {
|
|
3360
|
+
* return next ?? 'default'
|
|
3361
|
+
* }
|
|
3362
|
+
* @see https://mol.hyoo.ru/#!section=docs/=qxmh6t_sinbmb
|
|
3363
|
+
*/
|
|
2835
3364
|
$.$mol_mem = $mol_wire_solo;
|
|
3365
|
+
/**
|
|
3366
|
+
* Reactive memoizing multiplexed property decorator [mol_wire](../wire/README.md)
|
|
3367
|
+
* @example
|
|
3368
|
+
* '@' $mol_mem_key
|
|
3369
|
+
* name(id: number, next?: string) {
|
|
3370
|
+
* return next ?? 'default'
|
|
3371
|
+
* }
|
|
3372
|
+
* @see https://mol.hyoo.ru/#!section=docs/=qxmh6t_sinbmb
|
|
3373
|
+
*/
|
|
2836
3374
|
$.$mol_mem_key = $mol_wire_plex;
|
|
2837
3375
|
})($ || ($ = {}));
|
|
2838
3376
|
|
|
@@ -2846,104 +3384,115 @@ var $;
|
|
|
2846
3384
|
"use strict";
|
|
2847
3385
|
var $;
|
|
2848
3386
|
(function ($) {
|
|
2849
|
-
$.$mol_dom_context = new $node.jsdom.JSDOM('', { url: '
|
|
3387
|
+
$.$mol_dom_context = new $node.jsdom.JSDOM('', { url: `http://${process.env.DOMAIN || 'localhost'}/` }).window;
|
|
2850
3388
|
})($ || ($ = {}));
|
|
2851
3389
|
|
|
2852
3390
|
;
|
|
2853
3391
|
"use strict";
|
|
2854
3392
|
var $;
|
|
2855
3393
|
(function ($) {
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
3394
|
+
class $mol_storage extends $mol_object2 {
|
|
3395
|
+
/** Is storage a long term. */
|
|
3396
|
+
static persisted(next) {
|
|
3397
|
+
return false;
|
|
3398
|
+
}
|
|
3399
|
+
/** Total storage quota in bytes. */
|
|
3400
|
+
static total() {
|
|
3401
|
+
return 0;
|
|
3402
|
+
}
|
|
3403
|
+
/** Total storage usage in bytes. */
|
|
3404
|
+
static used() {
|
|
3405
|
+
return 0;
|
|
3406
|
+
}
|
|
3407
|
+
/** Minimum available free space in bytes. */
|
|
3408
|
+
static free() {
|
|
3409
|
+
return this.total() - this.used();
|
|
3410
|
+
}
|
|
3411
|
+
/** Fulfillness of storage. */
|
|
3412
|
+
static portion() {
|
|
3413
|
+
const total = this.total();
|
|
3414
|
+
if (!total)
|
|
3415
|
+
return 1;
|
|
3416
|
+
return this.used() / total;
|
|
3417
|
+
}
|
|
3418
|
+
/**
|
|
3419
|
+
* Fulfillness logarithmic level.
|
|
3420
|
+
* `0` - empty
|
|
3421
|
+
* `1` - half free
|
|
3422
|
+
* `2` - quart free
|
|
3423
|
+
* `Infinity` - fulfilled
|
|
3424
|
+
*/
|
|
3425
|
+
static level() {
|
|
3426
|
+
return Math.floor(-Math.log2(1 - this.portion()));
|
|
2862
3427
|
}
|
|
2863
|
-
current.reap = nothing;
|
|
2864
3428
|
}
|
|
2865
|
-
$.$
|
|
2866
|
-
const nothing = () => { };
|
|
2867
|
-
const sub = new $mol_wire_pub_sub;
|
|
2868
|
-
})($ || ($ = {}));
|
|
2869
|
-
|
|
2870
|
-
;
|
|
2871
|
-
"use strict";
|
|
2872
|
-
var $;
|
|
2873
|
-
(function ($) {
|
|
2874
|
-
$.$mol_mem_persist = $mol_wire_solid;
|
|
3429
|
+
$.$mol_storage = $mol_storage;
|
|
2875
3430
|
})($ || ($ = {}));
|
|
2876
3431
|
|
|
2877
3432
|
;
|
|
2878
3433
|
"use strict";
|
|
2879
3434
|
var $;
|
|
2880
3435
|
(function ($) {
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
3436
|
+
/** State of time moment */
|
|
3437
|
+
class $mol_state_time extends $mol_object {
|
|
3438
|
+
static task(precision, reset) {
|
|
3439
|
+
if (precision) {
|
|
3440
|
+
return new $mol_after_timeout(precision, () => this.task(precision, null));
|
|
3441
|
+
}
|
|
3442
|
+
else {
|
|
3443
|
+
return new $mol_after_frame(() => this.task(precision, null));
|
|
3444
|
+
}
|
|
2889
3445
|
}
|
|
2890
|
-
|
|
2891
|
-
|
|
3446
|
+
static now(precision) {
|
|
3447
|
+
this.task(precision);
|
|
3448
|
+
return Date.now();
|
|
2892
3449
|
}
|
|
2893
3450
|
}
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
$.$mol_mem_cached = $mol_wire_probe;
|
|
3451
|
+
__decorate([
|
|
3452
|
+
$mol_mem_key
|
|
3453
|
+
], $mol_state_time, "task", null);
|
|
3454
|
+
__decorate([
|
|
3455
|
+
$mol_mem_key
|
|
3456
|
+
], $mol_state_time, "now", null);
|
|
3457
|
+
$.$mol_state_time = $mol_state_time;
|
|
2902
3458
|
})($ || ($ = {}));
|
|
2903
3459
|
|
|
2904
3460
|
;
|
|
2905
3461
|
"use strict";
|
|
2906
3462
|
var $;
|
|
2907
3463
|
(function ($) {
|
|
2908
|
-
class $
|
|
2909
|
-
static
|
|
2910
|
-
return
|
|
2911
|
-
persisted: async () => false,
|
|
2912
|
-
persist: async () => false,
|
|
2913
|
-
estimate: async () => ({}),
|
|
2914
|
-
getDirectory: async () => null,
|
|
2915
|
-
};
|
|
3464
|
+
class $mol_storage_node extends $mol_storage {
|
|
3465
|
+
static persisted() {
|
|
3466
|
+
return true;
|
|
2916
3467
|
}
|
|
2917
|
-
static
|
|
2918
|
-
$
|
|
2919
|
-
|
|
2920
|
-
return Boolean(next);
|
|
2921
|
-
const native = this.native();
|
|
2922
|
-
if (next && !$mol_mem_cached(() => this.persisted())) {
|
|
2923
|
-
native.persist().then(actual => {
|
|
2924
|
-
setTimeout(() => this.persisted(actual, 'cache'), 5000);
|
|
2925
|
-
if (actual)
|
|
2926
|
-
this.$.$mol_log3_done({ place: `$mol_storage`, message: `Persist: Yes` });
|
|
2927
|
-
else
|
|
2928
|
-
this.$.$mol_log3_fail({ place: `$mol_storage`, message: `Persist: No` });
|
|
2929
|
-
});
|
|
2930
|
-
}
|
|
2931
|
-
return next ?? $mol_wire_sync(native).persisted();
|
|
3468
|
+
static stats() {
|
|
3469
|
+
$mol_state_time.now(1000);
|
|
3470
|
+
return $node.fs.statfsSync('.');
|
|
2932
3471
|
}
|
|
2933
|
-
static
|
|
2934
|
-
|
|
3472
|
+
static total() {
|
|
3473
|
+
const { blocks, bsize } = this.stats();
|
|
3474
|
+
return blocks * bsize;
|
|
2935
3475
|
}
|
|
2936
|
-
static
|
|
2937
|
-
|
|
3476
|
+
static used() {
|
|
3477
|
+
const { blocks, bfree, bsize } = this.stats();
|
|
3478
|
+
return (blocks - bfree) * bsize;
|
|
3479
|
+
}
|
|
3480
|
+
static free() {
|
|
3481
|
+
const { bfree, bsize } = this.stats();
|
|
3482
|
+
return bfree * bsize;
|
|
3483
|
+
}
|
|
3484
|
+
static portion() {
|
|
3485
|
+
const { blocks, bfree } = this.stats();
|
|
3486
|
+
if (!blocks)
|
|
3487
|
+
return 1;
|
|
3488
|
+
return (blocks - bfree) / blocks;
|
|
2938
3489
|
}
|
|
2939
3490
|
}
|
|
2940
3491
|
__decorate([
|
|
2941
3492
|
$mol_mem
|
|
2942
|
-
], $
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
], $mol_storage, "persisted", null);
|
|
2946
|
-
$.$mol_storage = $mol_storage;
|
|
3493
|
+
], $mol_storage_node, "stats", null);
|
|
3494
|
+
$.$mol_storage_node = $mol_storage_node;
|
|
3495
|
+
$.$mol_storage = $.$mol_storage_node;
|
|
2947
3496
|
})($ || ($ = {}));
|
|
2948
3497
|
|
|
2949
3498
|
;
|
|
@@ -3010,6 +3559,11 @@ var $;
|
|
|
3010
3559
|
"use strict";
|
|
3011
3560
|
var $;
|
|
3012
3561
|
(function ($) {
|
|
3562
|
+
/**
|
|
3563
|
+
* Returns closure that returns constant value.
|
|
3564
|
+
* @example
|
|
3565
|
+
* const rnd = $mol_const( Math.random() )
|
|
3566
|
+
*/
|
|
3013
3567
|
function $mol_const(value) {
|
|
3014
3568
|
const getter = (() => value);
|
|
3015
3569
|
getter['()'] = value;
|
|
@@ -3024,6 +3578,10 @@ var $;
|
|
|
3024
3578
|
"use strict";
|
|
3025
3579
|
var $;
|
|
3026
3580
|
(function ($) {
|
|
3581
|
+
/**
|
|
3582
|
+
* Decorates method to fiber to ensure it is executed only once inside other fiber from [mol_wire](../wire/README.md)
|
|
3583
|
+
* @see https://mol.hyoo.ru/#!section=docs/=1fcpsq_1wh0h2
|
|
3584
|
+
*/
|
|
3027
3585
|
$.$mol_action = $mol_wire_method;
|
|
3028
3586
|
})($ || ($ = {}));
|
|
3029
3587
|
|
|
@@ -3031,6 +3589,7 @@ var $;
|
|
|
3031
3589
|
"use strict";
|
|
3032
3590
|
var $;
|
|
3033
3591
|
(function ($) {
|
|
3592
|
+
/** Convert a pseudo-synchronous (Suspense API) API to an explicit asynchronous one (for integrating with external systems). */
|
|
3034
3593
|
function $mol_wire_async(obj) {
|
|
3035
3594
|
let fiber;
|
|
3036
3595
|
const temp = $mol_wire_task.getter(obj);
|
|
@@ -3057,6 +3616,27 @@ var $;
|
|
|
3057
3616
|
$.$mol_wire_async = $mol_wire_async;
|
|
3058
3617
|
})($ || ($ = {}));
|
|
3059
3618
|
|
|
3619
|
+
;
|
|
3620
|
+
"use strict";
|
|
3621
|
+
var $;
|
|
3622
|
+
(function ($) {
|
|
3623
|
+
/** Run code without state changes */
|
|
3624
|
+
function $mol_wire_probe(task, def) {
|
|
3625
|
+
const warm = $mol_wire_fiber.warm;
|
|
3626
|
+
try {
|
|
3627
|
+
$mol_wire_fiber.warm = false;
|
|
3628
|
+
const res = task();
|
|
3629
|
+
if (res === undefined)
|
|
3630
|
+
return def;
|
|
3631
|
+
return res;
|
|
3632
|
+
}
|
|
3633
|
+
finally {
|
|
3634
|
+
$mol_wire_fiber.warm = warm;
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3637
|
+
$.$mol_wire_probe = $mol_wire_probe;
|
|
3638
|
+
})($ || ($ = {}));
|
|
3639
|
+
|
|
3060
3640
|
;
|
|
3061
3641
|
"use strict";
|
|
3062
3642
|
var $;
|
|
@@ -3090,6 +3670,13 @@ var $;
|
|
|
3090
3670
|
$.$mol_lock = $mol_lock;
|
|
3091
3671
|
})($ || ($ = {}));
|
|
3092
3672
|
|
|
3673
|
+
;
|
|
3674
|
+
"use strict";
|
|
3675
|
+
var $;
|
|
3676
|
+
(function ($) {
|
|
3677
|
+
$.$mol_mem_cached = $mol_wire_probe;
|
|
3678
|
+
})($ || ($ = {}));
|
|
3679
|
+
|
|
3093
3680
|
;
|
|
3094
3681
|
"use strict";
|
|
3095
3682
|
var $;
|
|
@@ -3117,13 +3704,20 @@ var $;
|
|
|
3117
3704
|
path() { return ''; }
|
|
3118
3705
|
modes() { return []; }
|
|
3119
3706
|
write(options) {
|
|
3120
|
-
|
|
3707
|
+
throw new Error('Not implemented');
|
|
3121
3708
|
}
|
|
3122
3709
|
read() {
|
|
3123
|
-
|
|
3710
|
+
throw new Error('Not implemented');
|
|
3711
|
+
}
|
|
3712
|
+
truncate(size) {
|
|
3713
|
+
throw new Error('Not implemented');
|
|
3714
|
+
}
|
|
3715
|
+
flush() {
|
|
3716
|
+
throw new Error('Not implemented');
|
|
3717
|
+
}
|
|
3718
|
+
close() {
|
|
3719
|
+
throw new Error('Not implemented');
|
|
3124
3720
|
}
|
|
3125
|
-
truncate(size) { }
|
|
3126
|
-
close() { }
|
|
3127
3721
|
destructor() {
|
|
3128
3722
|
this.close();
|
|
3129
3723
|
}
|
|
@@ -3131,18 +3725,43 @@ var $;
|
|
|
3131
3725
|
$.$mol_file_transaction = $mol_file_transaction;
|
|
3132
3726
|
})($ || ($ = {}));
|
|
3133
3727
|
|
|
3728
|
+
;
|
|
3729
|
+
"use strict";
|
|
3730
|
+
var $;
|
|
3731
|
+
(function ($) {
|
|
3732
|
+
/**
|
|
3733
|
+
* Disable reaping of current subscriber
|
|
3734
|
+
*/
|
|
3735
|
+
function $mol_wire_solid() {
|
|
3736
|
+
let current = $mol_wire_auto();
|
|
3737
|
+
if (current.temp)
|
|
3738
|
+
current = current.host;
|
|
3739
|
+
if (current.reap !== nothing) {
|
|
3740
|
+
current?.sub_on(sub, sub.data.length);
|
|
3741
|
+
}
|
|
3742
|
+
current.reap = nothing;
|
|
3743
|
+
}
|
|
3744
|
+
$.$mol_wire_solid = $mol_wire_solid;
|
|
3745
|
+
const nothing = () => { };
|
|
3746
|
+
const sub = new $mol_wire_pub_sub;
|
|
3747
|
+
})($ || ($ = {}));
|
|
3748
|
+
|
|
3134
3749
|
;
|
|
3135
3750
|
"use strict";
|
|
3136
3751
|
var $;
|
|
3137
3752
|
(function ($) {
|
|
3138
3753
|
let file_modes;
|
|
3139
3754
|
(function (file_modes) {
|
|
3755
|
+
/** create if it doesn't already exist */
|
|
3140
3756
|
file_modes[file_modes["create"] = $node.fs.constants.O_CREAT] = "create";
|
|
3757
|
+
/** truncate to zero size if it already exists */
|
|
3141
3758
|
file_modes[file_modes["exists_truncate"] = $node.fs.constants.O_TRUNC] = "exists_truncate";
|
|
3759
|
+
/** throw exception if it already exists */
|
|
3142
3760
|
file_modes[file_modes["exists_fail"] = $node.fs.constants.O_EXCL] = "exists_fail";
|
|
3143
3761
|
file_modes[file_modes["read_only"] = $node.fs.constants.O_RDONLY] = "read_only";
|
|
3144
3762
|
file_modes[file_modes["write_only"] = $node.fs.constants.O_WRONLY] = "write_only";
|
|
3145
3763
|
file_modes[file_modes["read_write"] = $node.fs.constants.O_RDWR] = "read_write";
|
|
3764
|
+
/** data will be appended to the end */
|
|
3146
3765
|
file_modes[file_modes["append"] = $node.fs.constants.O_APPEND] = "append";
|
|
3147
3766
|
})(file_modes || (file_modes = {}));
|
|
3148
3767
|
function mode_mask(modes) {
|
|
@@ -3169,6 +3788,9 @@ var $;
|
|
|
3169
3788
|
read() {
|
|
3170
3789
|
return $mol_file_node_buffer_normalize($node.fs.readFileSync(this.descr()));
|
|
3171
3790
|
}
|
|
3791
|
+
flush() {
|
|
3792
|
+
$node.fs.fsyncSync(this.descr());
|
|
3793
|
+
}
|
|
3172
3794
|
close() {
|
|
3173
3795
|
$node.fs.closeSync(this.descr());
|
|
3174
3796
|
}
|
|
@@ -3204,12 +3826,24 @@ var $;
|
|
|
3204
3826
|
root() {
|
|
3205
3827
|
const path = this.path();
|
|
3206
3828
|
const base = this.constructor.base;
|
|
3829
|
+
// Если путь выше или равен base или если parent такойже как и this - считаем это корнем
|
|
3207
3830
|
return base.startsWith(path) || this == this.parent();
|
|
3208
3831
|
}
|
|
3209
3832
|
stat(next, virt) {
|
|
3210
3833
|
const path = this.path();
|
|
3211
3834
|
const parent = this.parent();
|
|
3835
|
+
// Отслеживать проверку наличия родительской папки не стоит до корня диска
|
|
3836
|
+
// Лучше ограничить mam-ом
|
|
3212
3837
|
if (!this.root()) {
|
|
3838
|
+
/*
|
|
3839
|
+
Если parent папка удалилась, надо ресетнуть все объекты в ней на любой глубине.
|
|
3840
|
+
Например, rm -rf с последующим git pull: parent папка может удалиться, потом создасться,
|
|
3841
|
+
а текущая папка успеет только удалиться до момента выполнения stat.
|
|
3842
|
+
Поэтому parent.exists() не запустит перевычисления, нужна именно parent.version()
|
|
3843
|
+
|
|
3844
|
+
Однако, parent.version() меняется не только при удалении, будет ложное срабатывание
|
|
3845
|
+
С этим придется мириться, красивого решения пока нет.
|
|
3846
|
+
*/
|
|
3213
3847
|
parent.version();
|
|
3214
3848
|
}
|
|
3215
3849
|
parent.watcher();
|
|
@@ -3223,9 +3857,19 @@ var $;
|
|
|
3223
3857
|
if (/([\/\\]\.|___$)/.test(path))
|
|
3224
3858
|
return;
|
|
3225
3859
|
const file = this.relative(path.at(-1) === '/' ? path.slice(0, -1) : path);
|
|
3860
|
+
// console.log(type, path)
|
|
3861
|
+
// add (change): добавился файл - у parent надо обновить список sub, если он был заюзан
|
|
3862
|
+
// change, unlink (rename): обновился или удалился файл - ресетим
|
|
3863
|
+
// addDir (change), добавилась папка, у parent обновляем список директорий в sub
|
|
3864
|
+
// дочерние ресетим
|
|
3865
|
+
// unlinkDir (rename), удалилась папка, ресетим ее
|
|
3866
|
+
// stat у всех дочерних обновится сам, т.к. связан с parent.version()
|
|
3226
3867
|
this.changed.add(file);
|
|
3227
3868
|
if (!this.watching)
|
|
3228
3869
|
return;
|
|
3870
|
+
// throttle, пока события поступают не сбрасываем.
|
|
3871
|
+
// аналог awaitWriteFinish из chokidar
|
|
3872
|
+
// интервалы между change-сообщениями модифицируемого файла должны быть меньше watch_debounce
|
|
3229
3873
|
this.frame?.destructor();
|
|
3230
3874
|
this.frame = new this.$.$mol_after_timeout(this.watch_debounce(), () => {
|
|
3231
3875
|
if (!this.watching)
|
|
@@ -3234,8 +3878,16 @@ var $;
|
|
|
3234
3878
|
$mol_wire_async(this).flush();
|
|
3235
3879
|
});
|
|
3236
3880
|
}
|
|
3881
|
+
/**
|
|
3882
|
+
* Должно быть больше, чем время между событиями от вотчера при записи внешним процессом.
|
|
3883
|
+
* Иначе запуск ресетов паралельно с изменением может привести к неконсистентности.
|
|
3884
|
+
*/
|
|
3237
3885
|
static watch_debounce() { return 500; }
|
|
3238
3886
|
static flush() {
|
|
3887
|
+
// Пока flush работает, вотчер сюда не заходит, но может добавлять новые изменения
|
|
3888
|
+
// на каждом перезапуске они применятся
|
|
3889
|
+
// Пока run выполняется, изменения накапливаются, в конце run вызывается flush
|
|
3890
|
+
// Пока применяются изменения, run должен ожидать конца flush
|
|
3239
3891
|
for (const file of this.changed) {
|
|
3240
3892
|
const parent = file.parent();
|
|
3241
3893
|
try {
|
|
@@ -3250,16 +3902,32 @@ var $;
|
|
|
3250
3902
|
}
|
|
3251
3903
|
this.changed.clear();
|
|
3252
3904
|
this.watching = true;
|
|
3905
|
+
// this.watch_wd?.destructor()
|
|
3906
|
+
// this.watch_wd = null
|
|
3253
3907
|
}
|
|
3254
3908
|
static watching = true;
|
|
3255
3909
|
static lock = new $mol_lock;
|
|
3256
3910
|
static watch_off(path) {
|
|
3257
3911
|
this.watching = false;
|
|
3912
|
+
// run должен ожидать конца flush
|
|
3258
3913
|
this.flush();
|
|
3259
3914
|
this.watching = false;
|
|
3915
|
+
/*
|
|
3916
|
+
watch запаздывает и событие может прилететь через 3 сек после окончания сайд эффекта
|
|
3917
|
+
поэтому добавляем папку, которую меняет side_effect
|
|
3918
|
+
Когда дойдет до выполнения flush, он ресетнет ее
|
|
3919
|
+
|
|
3920
|
+
Иначе будут лишние срабатывания
|
|
3921
|
+
Например, удалили hyoo/board, watch ресетит и exists начинает отдавать false, срабатывает git clone
|
|
3922
|
+
Сразу после него событие addDir еще не успело прийти,
|
|
3923
|
+
на следующем перезапуске вызывается git pull, т.к.
|
|
3924
|
+
с точки зрения реактивной системы hyoo/board еще не существует.
|
|
3925
|
+
*/
|
|
3260
3926
|
this.changed.add(this.absolute(path));
|
|
3261
3927
|
}
|
|
3928
|
+
// protected static watch_wd = null as null | $mol_after_timeout
|
|
3262
3929
|
static unwatched(side_effect, affected_dir) {
|
|
3930
|
+
// ждем, пока выполнится предыдущий unwatched
|
|
3263
3931
|
const unlock = this.lock.grab();
|
|
3264
3932
|
this.watch_off(affected_dir);
|
|
3265
3933
|
try {
|
|
@@ -3282,6 +3950,7 @@ var $;
|
|
|
3282
3950
|
modified() { return this.stat()?.mtime ?? null; }
|
|
3283
3951
|
version() {
|
|
3284
3952
|
const next = this.stat()?.mtime.getTime().toString(36).toUpperCase() ?? '';
|
|
3953
|
+
// console.log('version', next, this.path())
|
|
3285
3954
|
return next;
|
|
3286
3955
|
}
|
|
3287
3956
|
info(path) { return null; }
|
|
@@ -3299,15 +3968,19 @@ var $;
|
|
|
3299
3968
|
writable(opts) {
|
|
3300
3969
|
return new WritableStream;
|
|
3301
3970
|
}
|
|
3971
|
+
// open( ... modes: readonly $mol_file_mode[] ) { return 0 }
|
|
3302
3972
|
buffer(next) {
|
|
3973
|
+
// Если версия пустая - возвращаем пустой буфер
|
|
3303
3974
|
let readed = new Uint8Array();
|
|
3304
3975
|
if (next === undefined) {
|
|
3976
|
+
// Если меняется версия файла, буфер надо перечитать
|
|
3305
3977
|
if (this.version())
|
|
3306
3978
|
readed = this.read();
|
|
3307
3979
|
}
|
|
3308
3980
|
const prev = $mol_mem_cached(() => this.buffer());
|
|
3309
3981
|
const changed = prev === undefined || !$mol_compare_array(prev, next ?? readed);
|
|
3310
3982
|
if (prev !== undefined && changed) {
|
|
3983
|
+
// Логируем, если повторно читаем/пишем и буфер поменялся
|
|
3311
3984
|
this.$.$mol_log3_rise({
|
|
3312
3985
|
place: `$mol_file_node.buffer()`,
|
|
3313
3986
|
message: 'Changed',
|
|
@@ -3316,6 +3989,11 @@ var $;
|
|
|
3316
3989
|
}
|
|
3317
3990
|
if (next === undefined)
|
|
3318
3991
|
return changed ? readed : prev;
|
|
3992
|
+
// Если буфер при записи не поменялся и файл не удаляли перед этим - не записываем новую версию.
|
|
3993
|
+
// Если записывать, это приведет к смене mtime и вотчер снова триггернется, даже если содержимое файла не поменялось.
|
|
3994
|
+
// В этом алгоритме есть изъян.
|
|
3995
|
+
// Если файл записали, потом отключили вотчер, кто-то из вне его поменял, потом включили вотчер, снова записали тот же буфер,
|
|
3996
|
+
// то буфер не запишется на диск, т.к. кэш не консистентен с диском.
|
|
3319
3997
|
if (!changed && this.exists())
|
|
3320
3998
|
return prev;
|
|
3321
3999
|
this.parent().exists(true);
|
|
@@ -3351,13 +4029,21 @@ var $;
|
|
|
3351
4029
|
}
|
|
3352
4030
|
return null;
|
|
3353
4031
|
}
|
|
4032
|
+
// static watch_root = ''
|
|
4033
|
+
// static watcher_warned = false
|
|
3354
4034
|
watcher() {
|
|
4035
|
+
// const constructor = this.constructor as typeof $mol_file_base
|
|
4036
|
+
// if (! constructor.watcher_warned) {
|
|
4037
|
+
// console.warn(`${constructor}.watcher() not implemented`)
|
|
4038
|
+
// constructor.watcher_warned = true
|
|
4039
|
+
// }
|
|
3355
4040
|
return {
|
|
3356
4041
|
destructor() { }
|
|
3357
4042
|
};
|
|
3358
4043
|
}
|
|
3359
4044
|
exists(next) {
|
|
3360
4045
|
const exists = Boolean(this.stat());
|
|
4046
|
+
// console.log('exists current', exists, 'next', next, this.path())
|
|
3361
4047
|
if (next === undefined)
|
|
3362
4048
|
return exists;
|
|
3363
4049
|
if (next === exists)
|
|
@@ -3383,6 +4069,10 @@ var $;
|
|
|
3383
4069
|
return match ? match[1].substring(1) : '';
|
|
3384
4070
|
}
|
|
3385
4071
|
text(next, virt) {
|
|
4072
|
+
// Если записываем text, и вотчер ресетнул записанный файл,
|
|
4073
|
+
// то надо снова его обновить, вызвать логику, которая делала пуш в text.
|
|
4074
|
+
// Например файл удалили, потом снова создали, версия поменялась - перезаписываем
|
|
4075
|
+
// Если использовать version, то вновь созданный файл, через вотчер запустит свое пересоздание
|
|
3386
4076
|
if (next !== undefined)
|
|
3387
4077
|
this.exists();
|
|
3388
4078
|
return this.text_int(next, virt);
|
|
@@ -3407,6 +4097,7 @@ var $;
|
|
|
3407
4097
|
if (this.type() !== 'dir')
|
|
3408
4098
|
return [];
|
|
3409
4099
|
this.version();
|
|
4100
|
+
// Если дочерний file удалился, список надо обновить
|
|
3410
4101
|
return this.kids().filter(file => file.exists());
|
|
3411
4102
|
}
|
|
3412
4103
|
resolve(path) {
|
|
@@ -3551,10 +4242,15 @@ var $;
|
|
|
3551
4242
|
watcher(reset) {
|
|
3552
4243
|
const path = this.path();
|
|
3553
4244
|
const root = this.root();
|
|
4245
|
+
// Если папки/файла нет, watch упадет с ошибкой
|
|
4246
|
+
// exists обратится к parent.version и parent.watcher
|
|
4247
|
+
// Поэтому у root-папки и выше не надо вызывать exists, иначе поднимется выше base до корня диска
|
|
4248
|
+
// exists вызывать надо, что б пересоздавать вотчер при появлении папки или файла
|
|
3554
4249
|
if (!root && !this.exists())
|
|
3555
4250
|
return super.watcher();
|
|
3556
4251
|
let watcher;
|
|
3557
4252
|
try {
|
|
4253
|
+
// Между exists и watch файл может удалиться, в любом случае надо обрабатывать ENOENT
|
|
3558
4254
|
watcher = $node.fs.watch(path);
|
|
3559
4255
|
}
|
|
3560
4256
|
catch (error) {
|
|
@@ -3564,6 +4260,8 @@ var $;
|
|
|
3564
4260
|
if (root || error.code !== 'ENOENT') {
|
|
3565
4261
|
this.$.$mol_fail_log(error);
|
|
3566
4262
|
}
|
|
4263
|
+
// Если файла нет - вотчер не создается, создастся потом, когда exists поменяется на true.
|
|
4264
|
+
// Если создание упало с другой ошибкой - не ломаем работу mol_file, деградируем до не реактивной fs.
|
|
3567
4265
|
return super.watcher();
|
|
3568
4266
|
}
|
|
3569
4267
|
watcher.on('change', (type, name) => {
|
|
@@ -3575,6 +4273,7 @@ var $;
|
|
|
3575
4273
|
watcher.on('error', e => this.$.$mol_fail_log(e));
|
|
3576
4274
|
let destructed = false;
|
|
3577
4275
|
watcher.on('close', () => {
|
|
4276
|
+
// Если в процессе работы вотчер сам закрылся, надо его переоткрыть
|
|
3578
4277
|
if (!destructed)
|
|
3579
4278
|
setTimeout(() => $mol_wire_async(this).watcher(null), 500);
|
|
3580
4279
|
});
|
|
@@ -3593,6 +4292,8 @@ var $;
|
|
|
3593
4292
|
if (this.$.$mol_fail_catch(error)) {
|
|
3594
4293
|
if (error.code === 'ENOENT')
|
|
3595
4294
|
return null;
|
|
4295
|
+
if (error.code === 'EPERM')
|
|
4296
|
+
return null;
|
|
3596
4297
|
error.message += '\n' + path;
|
|
3597
4298
|
this.$.$mol_fail_hidden(error);
|
|
3598
4299
|
}
|
|
@@ -3796,13 +4497,13 @@ var $;
|
|
|
3796
4497
|
};
|
|
3797
4498
|
}
|
|
3798
4499
|
static get method() {
|
|
3799
|
-
return (obj, name, descr) => {
|
|
4500
|
+
return (obj, name, descr = Reflect.getOwnPropertyDescriptor(obj, name)) => {
|
|
3800
4501
|
descr.value = this.func(descr.value);
|
|
3801
4502
|
return descr;
|
|
3802
4503
|
};
|
|
3803
4504
|
}
|
|
3804
4505
|
static get field() {
|
|
3805
|
-
return (obj, name, descr) => {
|
|
4506
|
+
return (obj, name, descr = Reflect.getOwnPropertyDescriptor(obj, name)) => {
|
|
3806
4507
|
descr.get = descr.set = this.func(descr.get);
|
|
3807
4508
|
return descr;
|
|
3808
4509
|
};
|
|
@@ -3819,10 +4520,10 @@ var $;
|
|
|
3819
4520
|
static wrap(task) {
|
|
3820
4521
|
const store = new WeakMap();
|
|
3821
4522
|
const fun = function (next) {
|
|
3822
|
-
if (next === undefined && store.has(this))
|
|
3823
|
-
return store.get(this);
|
|
4523
|
+
if (next === undefined && store.has(this ?? fun))
|
|
4524
|
+
return store.get(this ?? fun);
|
|
3824
4525
|
const val = task.call(this, next) ?? next;
|
|
3825
|
-
store.set(this, val);
|
|
4526
|
+
store.set(this ?? fun, val);
|
|
3826
4527
|
return val;
|
|
3827
4528
|
};
|
|
3828
4529
|
Reflect.defineProperty(fun, 'name', { value: task.name + ' ' });
|
|
@@ -3836,10 +4537,12 @@ var $;
|
|
|
3836
4537
|
"use strict";
|
|
3837
4538
|
var $;
|
|
3838
4539
|
(function ($) {
|
|
4540
|
+
/** Internal int31 representation of current time. */
|
|
3839
4541
|
function $hyoo_crowd_time_now() {
|
|
3840
4542
|
return Math.floor(Date.now() / 100) - 1767e7;
|
|
3841
4543
|
}
|
|
3842
4544
|
$.$hyoo_crowd_time_now = $hyoo_crowd_time_now;
|
|
4545
|
+
/** Returns unix timestamp for internal time representation. */
|
|
3843
4546
|
function $hyoo_crowd_time_stamp(time) {
|
|
3844
4547
|
return 1767e9 + time * 100;
|
|
3845
4548
|
}
|
|
@@ -3850,8 +4553,10 @@ var $;
|
|
|
3850
4553
|
"use strict";
|
|
3851
4554
|
var $;
|
|
3852
4555
|
(function ($) {
|
|
4556
|
+
/** Vector clock. Stores real timestamps. */
|
|
3853
4557
|
class $hyoo_crowd_clock extends Map {
|
|
3854
4558
|
static begin = -1 * 2 ** 30;
|
|
4559
|
+
/** Maximum time for all peers. */
|
|
3855
4560
|
last_time = $hyoo_crowd_clock.begin;
|
|
3856
4561
|
constructor(entries) {
|
|
3857
4562
|
super(entries);
|
|
@@ -3861,16 +4566,19 @@ var $;
|
|
|
3861
4566
|
this.see_time(time);
|
|
3862
4567
|
}
|
|
3863
4568
|
}
|
|
4569
|
+
/** Synchronize this clock with another. */
|
|
3864
4570
|
sync(right) {
|
|
3865
4571
|
for (const [peer, time] of right) {
|
|
3866
4572
|
this.see_peer(peer, time);
|
|
3867
4573
|
}
|
|
3868
4574
|
}
|
|
4575
|
+
/** Increase `last` to latest. */
|
|
3869
4576
|
see_time(time) {
|
|
3870
4577
|
if (time < this.last_time)
|
|
3871
4578
|
return;
|
|
3872
4579
|
this.last_time = time;
|
|
3873
4580
|
}
|
|
4581
|
+
/** Add new `time` for `peer` and increase `last`. */
|
|
3874
4582
|
see_peer(peer, time) {
|
|
3875
4583
|
if (!this.fresh(peer, time))
|
|
3876
4584
|
return;
|
|
@@ -3885,9 +4593,11 @@ var $;
|
|
|
3885
4593
|
}), bin.getInt32(cursor + 8 + 4 * group, true));
|
|
3886
4594
|
}
|
|
3887
4595
|
}
|
|
4596
|
+
/** Checks if time from future. */
|
|
3888
4597
|
fresh(peer, time) {
|
|
3889
4598
|
return time > this.time(peer);
|
|
3890
4599
|
}
|
|
4600
|
+
/** Checks if this clock from future of another. */
|
|
3891
4601
|
ahead(clock) {
|
|
3892
4602
|
for (const [peer, time] of this) {
|
|
3893
4603
|
if (clock.fresh(peer, time))
|
|
@@ -3904,6 +4614,7 @@ var $;
|
|
|
3904
4614
|
last_stamp() {
|
|
3905
4615
|
return $hyoo_crowd_time_stamp(this.last_time);
|
|
3906
4616
|
}
|
|
4617
|
+
/** Gererates new time for peer that greater then other seen. */
|
|
3907
4618
|
tick(peer) {
|
|
3908
4619
|
let time = this.now();
|
|
3909
4620
|
if (time <= this.last_time) {
|
|
@@ -3960,6 +4671,7 @@ var $;
|
|
|
3960
4671
|
"use strict";
|
|
3961
4672
|
var $;
|
|
3962
4673
|
(function ($) {
|
|
4674
|
+
/** Stateless non-unique adapter to CROWD Tree for given Head. */
|
|
3963
4675
|
class $hyoo_crowd_node extends $mol_object2 {
|
|
3964
4676
|
land;
|
|
3965
4677
|
head;
|
|
@@ -3982,16 +4694,20 @@ var $;
|
|
|
3982
4694
|
world() {
|
|
3983
4695
|
return this.land.world();
|
|
3984
4696
|
}
|
|
4697
|
+
/** Returns another representation of this node. */
|
|
3985
4698
|
as(Node) {
|
|
3986
4699
|
return this.world()?.Fund(Node).Item(`${this.land.id()}!${this.head}`) ?? new Node(this.land, this.head);
|
|
3987
4700
|
}
|
|
4701
|
+
/** Ordered inner alive Units. */
|
|
3988
4702
|
units() {
|
|
3989
4703
|
return this.land.unit_alives(this.head);
|
|
3990
4704
|
}
|
|
4705
|
+
/** Ordered inner alive Node. */
|
|
3991
4706
|
nodes(Node) {
|
|
3992
4707
|
const fund = this.world()?.Fund(Node);
|
|
3993
4708
|
return this.units().map(unit => fund?.Item(`${this.land.id()}!${unit.self}`) ?? new Node(this.land, unit.self));
|
|
3994
4709
|
}
|
|
4710
|
+
/** Returns true when node value is never changed. */
|
|
3995
4711
|
virgin() {
|
|
3996
4712
|
return this.land.unit_list(this.head).length === 0;
|
|
3997
4713
|
}
|
|
@@ -4019,6 +4735,7 @@ var $;
|
|
|
4019
4735
|
var $;
|
|
4020
4736
|
(function ($) {
|
|
4021
4737
|
class $hyoo_crowd_reg extends $hyoo_crowd_node {
|
|
4738
|
+
/** Atomic value. */
|
|
4022
4739
|
value(next) {
|
|
4023
4740
|
const unit = this.units().at(-1);
|
|
4024
4741
|
if (next === undefined)
|
|
@@ -4028,12 +4745,15 @@ var $;
|
|
|
4028
4745
|
this.land.put(this.head, unit?.self ?? this.land.id_new(), '0_0', next);
|
|
4029
4746
|
return next;
|
|
4030
4747
|
}
|
|
4748
|
+
/** Atomic string. */
|
|
4031
4749
|
str(next) {
|
|
4032
4750
|
return String(this.value(next) ?? '');
|
|
4033
4751
|
}
|
|
4752
|
+
/** Atomic number. */
|
|
4034
4753
|
numb(next) {
|
|
4035
4754
|
return Number(this.value(next));
|
|
4036
4755
|
}
|
|
4756
|
+
/** Atomic boolean. */
|
|
4037
4757
|
bool(next) {
|
|
4038
4758
|
return Boolean(this.value(next));
|
|
4039
4759
|
}
|
|
@@ -4058,6 +4778,7 @@ var $;
|
|
|
4058
4778
|
var $;
|
|
4059
4779
|
(function ($) {
|
|
4060
4780
|
class $hyoo_crowd_struct extends $hyoo_crowd_node {
|
|
4781
|
+
/** Returns inner node for key. */
|
|
4061
4782
|
sub(key, Node) {
|
|
4062
4783
|
const head = $mol_int62_hash_string(key + '\n' + this.head);
|
|
4063
4784
|
return this.world()?.Fund(Node).Item(`${this.land.id()}!${head}`) ?? new Node(this.land, head);
|
|
@@ -4074,6 +4795,7 @@ var $;
|
|
|
4074
4795
|
"use strict";
|
|
4075
4796
|
var $;
|
|
4076
4797
|
(function ($) {
|
|
4798
|
+
/** Conflict-free Reinterpretable Ordered Washed Data Tree */
|
|
4077
4799
|
class $hyoo_crowd_land extends $mol_object {
|
|
4078
4800
|
id() {
|
|
4079
4801
|
return $mol_int62_to_string($mol_int62_random());
|
|
@@ -4107,21 +4829,26 @@ var $;
|
|
|
4107
4829
|
}
|
|
4108
4830
|
pub = new $mol_wire_pub;
|
|
4109
4831
|
_clocks = [new $hyoo_crowd_clock, new $hyoo_crowd_clock];
|
|
4832
|
+
/** unit by head + self */
|
|
4110
4833
|
_unit_all = new Map();
|
|
4111
4834
|
unit(head, self) {
|
|
4112
4835
|
return this._unit_all.get(`${head}!${self}`);
|
|
4113
4836
|
}
|
|
4837
|
+
/** units by head */
|
|
4114
4838
|
_unit_lists = new Map();
|
|
4839
|
+
/** Units by Head without tombstones */
|
|
4115
4840
|
_unit_alives = new Map();
|
|
4116
4841
|
size() {
|
|
4117
4842
|
return this._unit_all.size;
|
|
4118
4843
|
}
|
|
4844
|
+
/** Returns list of all Units for Node. */
|
|
4119
4845
|
unit_list(head) {
|
|
4120
4846
|
let kids = this._unit_lists.get(head);
|
|
4121
4847
|
if (!kids)
|
|
4122
4848
|
this._unit_lists.set(head, kids = Object.assign([], { dirty: false }));
|
|
4123
4849
|
return kids;
|
|
4124
4850
|
}
|
|
4851
|
+
/** Returns list of alive Units for Node. */
|
|
4125
4852
|
unit_alives(head) {
|
|
4126
4853
|
this.pub.promote();
|
|
4127
4854
|
let kids = this._unit_alives.get(head);
|
|
@@ -4134,23 +4861,27 @@ var $;
|
|
|
4134
4861
|
}
|
|
4135
4862
|
return kids;
|
|
4136
4863
|
}
|
|
4864
|
+
/** Node by id and type. */
|
|
4137
4865
|
node(head, Node) {
|
|
4138
4866
|
return new Node(this, head);
|
|
4139
4867
|
}
|
|
4868
|
+
/** Root Node. */
|
|
4140
4869
|
chief = this.node('0_0', $hyoo_crowd_struct);
|
|
4870
|
+
/** Generates new identifier. */
|
|
4141
4871
|
id_new() {
|
|
4142
4872
|
for (let i = 0; i < 1000; ++i) {
|
|
4143
4873
|
const id = $mol_int62_to_string($mol_int62_random());
|
|
4144
4874
|
if (id === '0_0')
|
|
4145
|
-
continue;
|
|
4875
|
+
continue; // zero reserved for empty
|
|
4146
4876
|
if (id === this.id())
|
|
4147
|
-
continue;
|
|
4877
|
+
continue; // reserved for rights
|
|
4148
4878
|
if (this._unit_lists.has(id))
|
|
4149
|
-
continue;
|
|
4879
|
+
continue; // skip already exists
|
|
4150
4880
|
return id;
|
|
4151
4881
|
}
|
|
4152
4882
|
throw new Error(`Can't generate ID after 1000 times`);
|
|
4153
4883
|
}
|
|
4884
|
+
/** Makes independent clone with defined peer. */
|
|
4154
4885
|
fork(auth) {
|
|
4155
4886
|
const fork = $hyoo_crowd_land.make({
|
|
4156
4887
|
id: $mol_const(this.id()),
|
|
@@ -4158,6 +4889,7 @@ var $;
|
|
|
4158
4889
|
});
|
|
4159
4890
|
return fork.apply(this.delta());
|
|
4160
4891
|
}
|
|
4892
|
+
/** Makes Delta bettween Clock and now. */
|
|
4161
4893
|
delta(clocks = [new $hyoo_crowd_clock, new $hyoo_crowd_clock]) {
|
|
4162
4894
|
this.pub.promote();
|
|
4163
4895
|
const delta = [];
|
|
@@ -4218,6 +4950,7 @@ var $;
|
|
|
4218
4950
|
kids.dirty = false;
|
|
4219
4951
|
return kids;
|
|
4220
4952
|
}
|
|
4953
|
+
/** Applies Delta to current state. */
|
|
4221
4954
|
apply(delta) {
|
|
4222
4955
|
for (const next of delta) {
|
|
4223
4956
|
this._clocks[next.group()].see_peer(next.auth, next.time);
|
|
@@ -4241,6 +4974,7 @@ var $;
|
|
|
4241
4974
|
return this;
|
|
4242
4975
|
}
|
|
4243
4976
|
_joined = false;
|
|
4977
|
+
/** Register public key of current peer **/
|
|
4244
4978
|
join() {
|
|
4245
4979
|
if (this._joined)
|
|
4246
4980
|
return;
|
|
@@ -4259,6 +4993,7 @@ var $;
|
|
|
4259
4993
|
this._joined = true;
|
|
4260
4994
|
this.pub.emit();
|
|
4261
4995
|
}
|
|
4996
|
+
/** Unregister public key of current peer **/
|
|
4262
4997
|
leave() {
|
|
4263
4998
|
const auth = this.peer();
|
|
4264
4999
|
if (!auth)
|
|
@@ -4287,6 +5022,7 @@ var $;
|
|
|
4287
5022
|
level_base(next) {
|
|
4288
5023
|
this.level('0_0', next);
|
|
4289
5024
|
}
|
|
5025
|
+
/** Access level for peer. Use empty string for current peer. **/
|
|
4290
5026
|
level(peer, next) {
|
|
4291
5027
|
if (next)
|
|
4292
5028
|
this.join();
|
|
@@ -4317,6 +5053,7 @@ var $;
|
|
|
4317
5053
|
this.pub.promote();
|
|
4318
5054
|
return this._unit_all.size > 0;
|
|
4319
5055
|
}
|
|
5056
|
+
/** All peers who have special rights to write o land. */
|
|
4320
5057
|
peers() {
|
|
4321
5058
|
this.pub.promote();
|
|
4322
5059
|
const lords = [];
|
|
@@ -4329,6 +5066,7 @@ var $;
|
|
|
4329
5066
|
}
|
|
4330
5067
|
return lords;
|
|
4331
5068
|
}
|
|
5069
|
+
/** All peers who joined to land except king. */
|
|
4332
5070
|
residents() {
|
|
4333
5071
|
this.pub.promote();
|
|
4334
5072
|
const lords = [];
|
|
@@ -4341,6 +5079,7 @@ var $;
|
|
|
4341
5079
|
}
|
|
4342
5080
|
return lords;
|
|
4343
5081
|
}
|
|
5082
|
+
/** All peers who have alive data inside land. */
|
|
4344
5083
|
authors() {
|
|
4345
5084
|
this.pub.promote();
|
|
4346
5085
|
const authors = new Set();
|
|
@@ -4372,6 +5111,7 @@ var $;
|
|
|
4372
5111
|
selection(peer) {
|
|
4373
5112
|
return this.world().land_sync(peer).chief.sub('$hyoo_crowd_land..selection', $hyoo_crowd_reg);
|
|
4374
5113
|
}
|
|
5114
|
+
/** Places data to tree. */
|
|
4375
5115
|
put(head, self, prev, data) {
|
|
4376
5116
|
this.join();
|
|
4377
5117
|
const old_id = `${head}!${self}`;
|
|
@@ -4389,18 +5129,25 @@ var $;
|
|
|
4389
5129
|
const unit_new = new $hyoo_crowd_unit(this.id(), auth, head, self, next, prev, time, data, null);
|
|
4390
5130
|
this._unit_all.set(old_id, unit_new);
|
|
4391
5131
|
unit_list.splice(seat, 0, unit_new);
|
|
5132
|
+
// unit_list.dirty = true
|
|
4392
5133
|
this._unit_alives.set(head, undefined);
|
|
5134
|
+
// this.apply([ unit_new ])
|
|
4393
5135
|
this.pub.emit();
|
|
4394
5136
|
return unit_new;
|
|
4395
5137
|
}
|
|
5138
|
+
/** Marks unit as deleted and wipes its data. */
|
|
4396
5139
|
wipe(unit) {
|
|
4397
5140
|
if (unit.data === null)
|
|
4398
5141
|
return unit;
|
|
5142
|
+
// for( const kid of this.unit_list( unit.self ) ) {
|
|
5143
|
+
// this.wipe( kid )
|
|
5144
|
+
// }
|
|
4399
5145
|
const unit_list = this.unit_list(unit.head);
|
|
4400
5146
|
const seat = unit_list.indexOf(unit);
|
|
4401
5147
|
const prev = seat > 0 ? unit_list[seat - 1].self : seat < 0 ? unit.prev : '0_0';
|
|
4402
5148
|
return this.put(unit.head, unit.self, prev, null);
|
|
4403
5149
|
}
|
|
5150
|
+
/** Moves Unit after another Prev inside some Head. */
|
|
4404
5151
|
move(unit, head, prev) {
|
|
4405
5152
|
const unit_list = this.unit_list(unit.head);
|
|
4406
5153
|
const seat = unit_list.indexOf(unit);
|
|
@@ -4410,6 +5157,7 @@ var $;
|
|
|
4410
5157
|
this.put(next.head, next.self, unit_list[unit_list.indexOf(next) - 2]?.self ?? '0_0', next.data);
|
|
4411
5158
|
this.put(head, unit.self, prev, unit.data);
|
|
4412
5159
|
}
|
|
5160
|
+
/** Moves Unit at given Seat inside given Head. */
|
|
4413
5161
|
insert(unit, head, seat) {
|
|
4414
5162
|
const list = this.unit_list(head);
|
|
4415
5163
|
const prev = seat ? list[seat - 1].self : '0_0';
|
|
@@ -4429,6 +5177,7 @@ var $;
|
|
|
4429
5177
|
"use strict";
|
|
4430
5178
|
var $;
|
|
4431
5179
|
(function ($) {
|
|
5180
|
+
/** Registry of nodes as domain entities. */
|
|
4432
5181
|
class $hyoo_crowd_fund extends $mol_object {
|
|
4433
5182
|
world;
|
|
4434
5183
|
node_class;
|
|
@@ -4461,7 +5210,11 @@ var $;
|
|
|
4461
5210
|
"use strict";
|
|
4462
5211
|
var $;
|
|
4463
5212
|
(function ($) {
|
|
5213
|
+
/** @deprecated */
|
|
4464
5214
|
$.$mol_dict_key = $mol_key;
|
|
5215
|
+
/**
|
|
5216
|
+
* Dictionary with extended keys support
|
|
5217
|
+
*/
|
|
4465
5218
|
class $mol_dict extends Map {
|
|
4466
5219
|
get(key) {
|
|
4467
5220
|
return super.get($mol_key(key));
|
|
@@ -4508,6 +5261,7 @@ var $;
|
|
|
4508
5261
|
if (iteration.done)
|
|
4509
5262
|
return iteration;
|
|
4510
5263
|
iteration.value = [JSON.parse(iteration.value[0]), iteration.value[1]];
|
|
5264
|
+
// iteration.value[0] = JSON.parse( iteration.value[0] as any as string )
|
|
4511
5265
|
return iteration;
|
|
4512
5266
|
}
|
|
4513
5267
|
};
|
|
@@ -4564,6 +5318,7 @@ var $;
|
|
|
4564
5318
|
_knights = new $mol_dict();
|
|
4565
5319
|
_signs = new WeakMap();
|
|
4566
5320
|
async grab(law = [''], mod = [], add = []) {
|
|
5321
|
+
// if( !law.length && !mod.length && !add.length ) $mol_fail( new Error( 'Grabbing dead land' ) )
|
|
4567
5322
|
const knight = await $hyoo_crowd_peer.generate();
|
|
4568
5323
|
this._knights.set(knight.id, knight);
|
|
4569
5324
|
const land_inner = this.land(knight.id);
|
|
@@ -4644,7 +5399,7 @@ var $;
|
|
|
4644
5399
|
}
|
|
4645
5400
|
async audit_delta(land, delta) {
|
|
4646
5401
|
const all = new Map();
|
|
4647
|
-
const desync = 60 * 60 * 10;
|
|
5402
|
+
const desync = 60 * 60 * 10; // 1 hour
|
|
4648
5403
|
const deadline = land.clock_data.now() + desync;
|
|
4649
5404
|
const get_unit = (id) => {
|
|
4650
5405
|
return all.get(id) ?? land._unit_all.get(id);
|
|
@@ -4783,6 +5538,7 @@ var $;
|
|
|
4783
5538
|
"use strict";
|
|
4784
5539
|
var $;
|
|
4785
5540
|
(function ($) {
|
|
5541
|
+
/** Starts subtasks concurrently instead of serial. */
|
|
4786
5542
|
function $mol_wire_race(...tasks) {
|
|
4787
5543
|
const results = tasks.map(task => {
|
|
4788
5544
|
try {
|
|
@@ -4809,7 +5565,7 @@ var $;
|
|
|
4809
5565
|
(function ($) {
|
|
4810
5566
|
$.$hyoo_sync_masters = [
|
|
4811
5567
|
`sync.hyoo.ru`,
|
|
4812
|
-
|
|
5568
|
+
//`sync-pmzz.onrender.com`,
|
|
4813
5569
|
];
|
|
4814
5570
|
})($ || ($ = {}));
|
|
4815
5571
|
|
|
@@ -4930,6 +5686,12 @@ var $;
|
|
|
4930
5686
|
$mol_wire_sync(this).db_land_save(land, units);
|
|
4931
5687
|
for (const unit of units)
|
|
4932
5688
|
this.db_unit_persisted.add(unit);
|
|
5689
|
+
// this.$.$mol_log3_rise({
|
|
5690
|
+
// place: this,
|
|
5691
|
+
// land: land.id(),
|
|
5692
|
+
// message: 'Base Save',
|
|
5693
|
+
// units: this.log_pack( units ),
|
|
5694
|
+
// })
|
|
4933
5695
|
}
|
|
4934
5696
|
db_land_init(land) {
|
|
4935
5697
|
try {
|
|
@@ -4949,6 +5711,12 @@ var $;
|
|
|
4949
5711
|
this.db_unit_persisted.add(unit);
|
|
4950
5712
|
units.sort($hyoo_crowd_unit_compare);
|
|
4951
5713
|
land.apply(units);
|
|
5714
|
+
// this.$.$mol_log3_rise({
|
|
5715
|
+
// place: this,
|
|
5716
|
+
// land: land.id(),
|
|
5717
|
+
// message: 'Base Load',
|
|
5718
|
+
// units: this.log_pack( units ),
|
|
5719
|
+
// })
|
|
4952
5720
|
}
|
|
4953
5721
|
async db_land_load(land) {
|
|
4954
5722
|
return [];
|
|
@@ -4981,6 +5749,11 @@ var $;
|
|
|
4981
5749
|
}
|
|
4982
5750
|
line_land_clocks({ line, land }, next) {
|
|
4983
5751
|
$mol_wire_solid();
|
|
5752
|
+
// try{
|
|
5753
|
+
// this.master()
|
|
5754
|
+
// } catch( error ) {
|
|
5755
|
+
// $mol_fail_log( error )
|
|
5756
|
+
// }
|
|
4984
5757
|
return next;
|
|
4985
5758
|
}
|
|
4986
5759
|
line_sync(line) {
|
|
@@ -4995,13 +5768,29 @@ var $;
|
|
|
4995
5768
|
if (!units.length)
|
|
4996
5769
|
return;
|
|
4997
5770
|
this.line_send_units(line, units);
|
|
5771
|
+
/*this.$.$mol_log3_rise({
|
|
5772
|
+
place: this,
|
|
5773
|
+
land: land.id(),
|
|
5774
|
+
message: 'Sync Sent',
|
|
5775
|
+
line: $mol_key( line ),
|
|
5776
|
+
units: this.log_pack( units ),
|
|
5777
|
+
})*/
|
|
4998
5778
|
for (const unit of units) {
|
|
4999
5779
|
clocks[unit.group()].see_peer(unit.auth, unit.time);
|
|
5000
5780
|
}
|
|
5001
5781
|
}
|
|
5002
5782
|
line_land_init({ line, land }) {
|
|
5003
5783
|
this.db_land_init(land);
|
|
5784
|
+
// const lands = this.line_land_clocks({ line, land })
|
|
5785
|
+
// if( lands ) return
|
|
5004
5786
|
this.line_send_clocks(line, land);
|
|
5787
|
+
// this.$.$mol_log3_come({
|
|
5788
|
+
// place: this,
|
|
5789
|
+
// land: land.id(),
|
|
5790
|
+
// message: 'Sync Open',
|
|
5791
|
+
// line: $mol_key( line ),
|
|
5792
|
+
// clocks: land._clocks,
|
|
5793
|
+
// })
|
|
5005
5794
|
}
|
|
5006
5795
|
line_land_neck({ line, land }, next = []) {
|
|
5007
5796
|
return next;
|
|
@@ -5045,6 +5834,13 @@ var $;
|
|
|
5045
5834
|
}
|
|
5046
5835
|
else {
|
|
5047
5836
|
this.line_lands(line, [...lands, land]);
|
|
5837
|
+
// this.$.$mol_log3_done({
|
|
5838
|
+
// place: this,
|
|
5839
|
+
// land: land.id(),
|
|
5840
|
+
// message: 'Sync Pair',
|
|
5841
|
+
// line: $mol_key( line ),
|
|
5842
|
+
// clocks,
|
|
5843
|
+
// })
|
|
5048
5844
|
}
|
|
5049
5845
|
return;
|
|
5050
5846
|
}
|
|
@@ -5149,6 +5945,7 @@ var $;
|
|
|
5149
5945
|
"use strict";
|
|
5150
5946
|
var $;
|
|
5151
5947
|
(function ($) {
|
|
5948
|
+
/** Converts IDBResult to Promise */
|
|
5152
5949
|
function $mol_db_response(request) {
|
|
5153
5950
|
return new Promise((done, fail) => {
|
|
5154
5951
|
request.onerror = () => fail(new Error(request.error.message));
|
|
@@ -5162,6 +5959,14 @@ var $;
|
|
|
5162
5959
|
"use strict";
|
|
5163
5960
|
var $;
|
|
5164
5961
|
(function ($) {
|
|
5962
|
+
/**
|
|
5963
|
+
* Creates new or returns existen database with automatic schema migration.
|
|
5964
|
+
* Schema version is based on migrations count.
|
|
5965
|
+
* Migrations code mustn't be changed after deploy.
|
|
5966
|
+
* Only adding migrations at the end is allowed.
|
|
5967
|
+
* Only new migrations will be applyed to existen DB.
|
|
5968
|
+
* Schema changes allowed only through migratios.
|
|
5969
|
+
*/
|
|
5165
5970
|
async function $mol_db(name, ...migrations) {
|
|
5166
5971
|
const request = this.$mol_dom_context.indexedDB.open(name, migrations.length ? migrations.length + 1 : undefined);
|
|
5167
5972
|
request.onupgradeneeded = event => {
|
|
@@ -5180,6 +5985,7 @@ var $;
|
|
|
5180
5985
|
"use strict";
|
|
5181
5986
|
var $;
|
|
5182
5987
|
(function ($) {
|
|
5988
|
+
/** IndexedDB ObjectStore wrapper. */
|
|
5183
5989
|
class $mol_db_store {
|
|
5184
5990
|
native;
|
|
5185
5991
|
constructor(native) {
|
|
@@ -5194,6 +6000,7 @@ var $;
|
|
|
5194
6000
|
get incremental() {
|
|
5195
6001
|
return this.native.autoIncrement;
|
|
5196
6002
|
}
|
|
6003
|
+
/** Returns dictionary of all existen Indexes. */
|
|
5197
6004
|
get indexes() {
|
|
5198
6005
|
return new Proxy({}, {
|
|
5199
6006
|
ownKeys: () => [...this.native.indexNames],
|
|
@@ -5201,9 +6008,11 @@ var $;
|
|
|
5201
6008
|
get: (_, name) => new $mol_db_index(this.native.index(name))
|
|
5202
6009
|
});
|
|
5203
6010
|
}
|
|
6011
|
+
/** Creates new Index */
|
|
5204
6012
|
index_make(name, path = [], unique = false, multiEntry = false) {
|
|
5205
6013
|
return this.native.createIndex(name, path, { multiEntry, unique });
|
|
5206
6014
|
}
|
|
6015
|
+
/** Drops existen Index */
|
|
5207
6016
|
index_drop(name) {
|
|
5208
6017
|
this.native.deleteIndex(name);
|
|
5209
6018
|
return this;
|
|
@@ -5214,21 +6023,27 @@ var $;
|
|
|
5214
6023
|
get db() {
|
|
5215
6024
|
return this.transaction.db;
|
|
5216
6025
|
}
|
|
6026
|
+
/** Deletes all stored Documents */
|
|
5217
6027
|
clear() {
|
|
5218
6028
|
return $mol_db_response(this.native.clear());
|
|
5219
6029
|
}
|
|
6030
|
+
/** Counts Documents by primary key(s) */
|
|
5220
6031
|
count(keys) {
|
|
5221
6032
|
return $mol_db_response(this.native.count(keys));
|
|
5222
6033
|
}
|
|
6034
|
+
/** Stores single Document by primary key. */
|
|
5223
6035
|
put(doc, key) {
|
|
5224
6036
|
return $mol_db_response(this.native.put(doc, key));
|
|
5225
6037
|
}
|
|
6038
|
+
/** Returns Document by primary key. */
|
|
5226
6039
|
get(key) {
|
|
5227
6040
|
return $mol_db_response(this.native.get(key));
|
|
5228
6041
|
}
|
|
6042
|
+
/** Selects Documents by primary keys. */
|
|
5229
6043
|
select(key, count) {
|
|
5230
6044
|
return $mol_db_response(this.native.getAll(key, count));
|
|
5231
6045
|
}
|
|
6046
|
+
/** Deletes Documents by primary key(s). */
|
|
5232
6047
|
drop(keys) {
|
|
5233
6048
|
return $mol_db_response(this.native.delete(keys));
|
|
5234
6049
|
}
|
|
@@ -5243,6 +6058,7 @@ var $;
|
|
|
5243
6058
|
"use strict";
|
|
5244
6059
|
var $;
|
|
5245
6060
|
(function ($) {
|
|
6061
|
+
/** IndexedDB Index wrapper. */
|
|
5246
6062
|
class $mol_db_index {
|
|
5247
6063
|
native;
|
|
5248
6064
|
constructor(native) {
|
|
@@ -5269,12 +6085,15 @@ var $;
|
|
|
5269
6085
|
get db() {
|
|
5270
6086
|
return this.store.db;
|
|
5271
6087
|
}
|
|
6088
|
+
/** Counts Documents by key(s) */
|
|
5272
6089
|
count(keys) {
|
|
5273
6090
|
return $mol_db_response(this.native.count(keys));
|
|
5274
6091
|
}
|
|
6092
|
+
/** Returns Document by primary key. */
|
|
5275
6093
|
get(key) {
|
|
5276
6094
|
return $mol_db_response(this.native.get(key));
|
|
5277
6095
|
}
|
|
6096
|
+
/** Selects Documents by primary keys. */
|
|
5278
6097
|
select(key, count) {
|
|
5279
6098
|
return $mol_db_response(this.native.getAll(key, count));
|
|
5280
6099
|
}
|
|
@@ -5310,32 +6129,46 @@ var $;
|
|
|
5310
6129
|
"use strict";
|
|
5311
6130
|
var $;
|
|
5312
6131
|
(function ($) {
|
|
6132
|
+
/** IndexedDB instance wrapper. */
|
|
5313
6133
|
class $mol_db_database {
|
|
5314
6134
|
native;
|
|
5315
6135
|
constructor(native) {
|
|
5316
6136
|
this.native = native;
|
|
5317
6137
|
}
|
|
6138
|
+
/** Returns database name. */
|
|
5318
6139
|
get name() {
|
|
5319
6140
|
return this.native.name;
|
|
5320
6141
|
}
|
|
6142
|
+
/** Returns database schema version. */
|
|
5321
6143
|
get version() {
|
|
5322
6144
|
return this.native.version;
|
|
5323
6145
|
}
|
|
6146
|
+
/** Returns all stores names. */
|
|
5324
6147
|
get stores() {
|
|
5325
6148
|
return [...this.native.objectStoreNames];
|
|
5326
6149
|
}
|
|
6150
|
+
/** Create read-only transaction. */
|
|
5327
6151
|
read(...names) {
|
|
5328
6152
|
return new $mol_db_transaction(this.native.transaction(names, 'readonly', { durability: 'relaxed' })).stores;
|
|
5329
6153
|
}
|
|
6154
|
+
/** Create read/write transaction. */
|
|
5330
6155
|
change(...names) {
|
|
5331
6156
|
return new $mol_db_transaction(this.native.transaction(names, 'readwrite', { durability: 'relaxed' }));
|
|
5332
6157
|
}
|
|
6158
|
+
/**
|
|
6159
|
+
* Deletes database.
|
|
6160
|
+
* DB can be deleted only after end of all transactions.
|
|
6161
|
+
*/
|
|
5333
6162
|
kill() {
|
|
5334
6163
|
this.native.close();
|
|
5335
6164
|
const request = $mol_dom_context.indexedDB.deleteDatabase(this.name);
|
|
5336
6165
|
request.onblocked = console.warn;
|
|
5337
6166
|
return $mol_db_response(request);
|
|
5338
6167
|
}
|
|
6168
|
+
/**
|
|
6169
|
+
* Closes DB connection.
|
|
6170
|
+
* Connection really be closed only after end of all transactions.
|
|
6171
|
+
*/
|
|
5339
6172
|
destructor() {
|
|
5340
6173
|
this.native.close();
|
|
5341
6174
|
}
|
|
@@ -5347,11 +6180,13 @@ var $;
|
|
|
5347
6180
|
"use strict";
|
|
5348
6181
|
var $;
|
|
5349
6182
|
(function ($) {
|
|
6183
|
+
/** IndexedDB Transaction wrapper. */
|
|
5350
6184
|
class $mol_db_transaction {
|
|
5351
6185
|
native;
|
|
5352
6186
|
constructor(native) {
|
|
5353
6187
|
this.native = native;
|
|
5354
6188
|
}
|
|
6189
|
+
/** Returns dictionary of all existen Stores. */
|
|
5355
6190
|
get stores() {
|
|
5356
6191
|
return new Proxy({}, {
|
|
5357
6192
|
ownKeys: () => [...this.native.objectStoreNames],
|
|
@@ -5361,18 +6196,22 @@ var $;
|
|
|
5361
6196
|
: undefined,
|
|
5362
6197
|
});
|
|
5363
6198
|
}
|
|
6199
|
+
/** Creates new Store */
|
|
5364
6200
|
store_make(name) {
|
|
5365
6201
|
return this.native.db.createObjectStore(name, { autoIncrement: true });
|
|
5366
6202
|
}
|
|
6203
|
+
/** Drops existen Store */
|
|
5367
6204
|
store_drop(name) {
|
|
5368
6205
|
this.native.db.deleteObjectStore(name);
|
|
5369
6206
|
return this;
|
|
5370
6207
|
}
|
|
6208
|
+
/** Instant abort transaction. Any errors aborts transactions automatically. */
|
|
5371
6209
|
abort() {
|
|
5372
6210
|
if (this.native.error)
|
|
5373
6211
|
return;
|
|
5374
6212
|
this.native.abort();
|
|
5375
6213
|
}
|
|
6214
|
+
/** Instant commits transaction. Without errors commit proceed automatically later. */
|
|
5376
6215
|
commit() {
|
|
5377
6216
|
this.native.commit?.();
|
|
5378
6217
|
return new Promise((done, fail) => {
|
|
@@ -5493,6 +6332,29 @@ var $;
|
|
|
5493
6332
|
};
|
|
5494
6333
|
});
|
|
5495
6334
|
}
|
|
6335
|
+
// @ $mol_mem
|
|
6336
|
+
// server() {
|
|
6337
|
+
// return new $mol_dom_listener(
|
|
6338
|
+
// $mol_dom_context,
|
|
6339
|
+
// 'message',
|
|
6340
|
+
// $mol_wire_async( ( event: MessageEvent<[ string, $mol_int62_string, readonly $hyoo_crowd_unit[] ]> )=> {
|
|
6341
|
+
// if( !event ) return
|
|
6342
|
+
// if( !Array.isArray( event.data ) ) return
|
|
6343
|
+
// switch( event.data[0] ) {
|
|
6344
|
+
// case 'hyoo_sync_units': {
|
|
6345
|
+
// const [, land_id, units ] = event.data
|
|
6346
|
+
// const line = event.source! as Window
|
|
6347
|
+
// const land = this.land( land_id )
|
|
6348
|
+
// land.apply( units )
|
|
6349
|
+
// this.slaves([ ... new Set([ ... this.slaves(), line ]) ])
|
|
6350
|
+
// this.line_lands( line, [ ... new Set([ ... this.line_lands( line ), land ]) ] )
|
|
6351
|
+
// this.line_land_clocks({ line, land })
|
|
6352
|
+
// line.postMessage([ 'hyoo_sync_units', land.id(), [] ])
|
|
6353
|
+
// }
|
|
6354
|
+
// }
|
|
6355
|
+
// } )
|
|
6356
|
+
// )
|
|
6357
|
+
// }
|
|
5496
6358
|
line_send_clocks(line, land) {
|
|
5497
6359
|
if (line instanceof WebSocket) {
|
|
5498
6360
|
line.send(land.clocks_bin);
|
|
@@ -5621,13 +6483,6 @@ var $;
|
|
|
5621
6483
|
$.$mol_test_complete = $mol_test_complete;
|
|
5622
6484
|
})($ || ($ = {}));
|
|
5623
6485
|
|
|
5624
|
-
;
|
|
5625
|
-
"use strict";
|
|
5626
|
-
var $;
|
|
5627
|
-
(function ($_1) {
|
|
5628
|
-
$mol_test_mocks.push($ => $.$mol_fail_log = () => false);
|
|
5629
|
-
})($ || ($ = {}));
|
|
5630
|
-
|
|
5631
6486
|
;
|
|
5632
6487
|
"use strict";
|
|
5633
6488
|
var $;
|
|
@@ -5742,6 +6597,12 @@ var $;
|
|
|
5742
6597
|
createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
|
|
5743
6598
|
};
|
|
5744
6599
|
$.$mol_jsx_frag = '';
|
|
6600
|
+
/**
|
|
6601
|
+
* JSX adapter that makes DOM tree.
|
|
6602
|
+
* Generates global unique ids for every DOM-element by components tree with ids.
|
|
6603
|
+
* Ensures all local ids are unique.
|
|
6604
|
+
* Can reuse an existing nodes by GUIDs when used inside [`mol_jsx_attach`](https://github.com/hyoo-ru/mam_mol/tree/master/jsx/attach).
|
|
6605
|
+
*/
|
|
5745
6606
|
function $mol_jsx(Elem, props, ...childNodes) {
|
|
5746
6607
|
const id = props && props.id || '';
|
|
5747
6608
|
const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
|
|
@@ -5852,6 +6713,8 @@ var $;
|
|
|
5852
6713
|
|
|
5853
6714
|
;
|
|
5854
6715
|
"use strict";
|
|
6716
|
+
/** @jsx $mol_jsx */
|
|
6717
|
+
/** @jsxFrag $mol_jsx_frag */
|
|
5855
6718
|
var $;
|
|
5856
6719
|
(function ($) {
|
|
5857
6720
|
$mol_test({
|
|
@@ -5957,6 +6820,7 @@ var $;
|
|
|
5957
6820
|
"use strict";
|
|
5958
6821
|
var $;
|
|
5959
6822
|
(function ($) {
|
|
6823
|
+
/** Lazy computed lists with native Array interface. $mol_range2_array is mutable but all derived ranges are immutable. */
|
|
5960
6824
|
function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
|
|
5961
6825
|
const source = typeof item === 'function' ? new $mol_range2_array() : item;
|
|
5962
6826
|
if (typeof item !== 'function') {
|
|
@@ -6005,6 +6869,7 @@ var $;
|
|
|
6005
6869
|
}
|
|
6006
6870
|
$.$mol_range2 = $mol_range2;
|
|
6007
6871
|
class $mol_range2_array extends Array {
|
|
6872
|
+
// Lazy
|
|
6008
6873
|
concat(...tail) {
|
|
6009
6874
|
if (tail.length === 0)
|
|
6010
6875
|
return this;
|
|
@@ -6016,6 +6881,7 @@ var $;
|
|
|
6016
6881
|
}
|
|
6017
6882
|
return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
|
|
6018
6883
|
}
|
|
6884
|
+
// Lazy
|
|
6019
6885
|
filter(check, context) {
|
|
6020
6886
|
const filtered = [];
|
|
6021
6887
|
let cursor = -1;
|
|
@@ -6028,13 +6894,16 @@ var $;
|
|
|
6028
6894
|
return filtered[index];
|
|
6029
6895
|
}, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
|
|
6030
6896
|
}
|
|
6897
|
+
// Diligent
|
|
6031
6898
|
forEach(proceed, context) {
|
|
6032
6899
|
for (let [key, value] of this.entries())
|
|
6033
6900
|
proceed.call(context, value, key, this);
|
|
6034
6901
|
}
|
|
6902
|
+
// Lazy
|
|
6035
6903
|
map(proceed, context) {
|
|
6036
6904
|
return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
|
|
6037
6905
|
}
|
|
6906
|
+
// Diligent
|
|
6038
6907
|
reduce(merge, result) {
|
|
6039
6908
|
let index = 0;
|
|
6040
6909
|
if (arguments.length === 1) {
|
|
@@ -6045,12 +6914,15 @@ var $;
|
|
|
6045
6914
|
}
|
|
6046
6915
|
return result;
|
|
6047
6916
|
}
|
|
6917
|
+
// Lazy
|
|
6048
6918
|
toReversed() {
|
|
6049
6919
|
return $mol_range2(index => this[this.length - 1 - index], () => this.length);
|
|
6050
6920
|
}
|
|
6921
|
+
// Lazy
|
|
6051
6922
|
slice(from = 0, to = this.length) {
|
|
6052
6923
|
return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
|
|
6053
6924
|
}
|
|
6925
|
+
// Lazy
|
|
6054
6926
|
some(check, context) {
|
|
6055
6927
|
for (let index = 0; index < this.length; ++index) {
|
|
6056
6928
|
if (check.call(context, this[index], index, this))
|
|
@@ -6071,6 +6943,9 @@ var $;
|
|
|
6071
6943
|
sort() {
|
|
6072
6944
|
return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
|
|
6073
6945
|
}
|
|
6946
|
+
indexOf(needle) {
|
|
6947
|
+
return this.findIndex(item => item === needle);
|
|
6948
|
+
}
|
|
6074
6949
|
[Symbol.toPrimitive]() {
|
|
6075
6950
|
return $mol_guid();
|
|
6076
6951
|
}
|
|
@@ -6240,6 +7115,7 @@ var $;
|
|
|
6240
7115
|
|
|
6241
7116
|
;
|
|
6242
7117
|
"use strict";
|
|
7118
|
+
/** @jsx $mol_jsx */
|
|
6243
7119
|
var $;
|
|
6244
7120
|
(function ($) {
|
|
6245
7121
|
$mol_test({
|
|
@@ -6301,6 +7177,7 @@ var $;
|
|
|
6301
7177
|
const obj3_copy = { test: 3, obj2: obj2_copy };
|
|
6302
7178
|
obj1.obj3 = obj3;
|
|
6303
7179
|
obj1_copy.obj3 = obj3_copy;
|
|
7180
|
+
// warmup cache
|
|
6304
7181
|
$mol_assert_not($mol_compare_deep(obj1, {}));
|
|
6305
7182
|
$mol_assert_not($mol_compare_deep(obj2, {}));
|
|
6306
7183
|
$mol_assert_not($mol_compare_deep(obj3, {}));
|
|
@@ -6370,18 +7247,34 @@ var $;
|
|
|
6370
7247
|
"use strict";
|
|
6371
7248
|
var $;
|
|
6372
7249
|
(function ($) {
|
|
7250
|
+
/**
|
|
7251
|
+
* Argument must be Truthy
|
|
7252
|
+
* @deprecated use $mol_assert_equal instead
|
|
7253
|
+
*/
|
|
6373
7254
|
function $mol_assert_ok(value) {
|
|
6374
7255
|
if (value)
|
|
6375
7256
|
return;
|
|
6376
7257
|
$mol_fail(new Error(`${value} ≠ true`));
|
|
6377
7258
|
}
|
|
6378
7259
|
$.$mol_assert_ok = $mol_assert_ok;
|
|
7260
|
+
/**
|
|
7261
|
+
* Argument must be Falsy
|
|
7262
|
+
* @deprecated use $mol_assert_equal instead
|
|
7263
|
+
*/
|
|
6379
7264
|
function $mol_assert_not(value) {
|
|
6380
7265
|
if (!value)
|
|
6381
7266
|
return;
|
|
6382
7267
|
$mol_fail(new Error(`${value} ≠ false`));
|
|
6383
7268
|
}
|
|
6384
7269
|
$.$mol_assert_not = $mol_assert_not;
|
|
7270
|
+
/**
|
|
7271
|
+
* Handler must throw an error.
|
|
7272
|
+
* @example
|
|
7273
|
+
* $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } ) // Passes because throws error
|
|
7274
|
+
* $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , 'Parse error' ) // Passes because throws right message
|
|
7275
|
+
* $mol_assert_fail( ()=>{ throw new Error( 'Parse error' ) } , Error ) // Passes because throws right class
|
|
7276
|
+
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
|
|
7277
|
+
*/
|
|
6385
7278
|
function $mol_assert_fail(handler, ErrorRight) {
|
|
6386
7279
|
const fail = $.$mol_fail;
|
|
6387
7280
|
try {
|
|
@@ -6391,7 +7284,7 @@ var $;
|
|
|
6391
7284
|
catch (error) {
|
|
6392
7285
|
$.$mol_fail = fail;
|
|
6393
7286
|
if (typeof ErrorRight === 'string') {
|
|
6394
|
-
$mol_assert_equal(error.message, ErrorRight);
|
|
7287
|
+
$mol_assert_equal(error.message ?? error, ErrorRight);
|
|
6395
7288
|
}
|
|
6396
7289
|
else {
|
|
6397
7290
|
$mol_assert_equal(error instanceof ErrorRight, true);
|
|
@@ -6401,13 +7294,21 @@ var $;
|
|
|
6401
7294
|
finally {
|
|
6402
7295
|
$.$mol_fail = fail;
|
|
6403
7296
|
}
|
|
6404
|
-
$mol_fail(new Error('Not failed'));
|
|
7297
|
+
$mol_fail(new Error('Not failed', { cause: { expect: ErrorRight } }));
|
|
6405
7298
|
}
|
|
6406
7299
|
$.$mol_assert_fail = $mol_assert_fail;
|
|
7300
|
+
/** @deprecated Use $mol_assert_equal */
|
|
6407
7301
|
function $mol_assert_like(...args) {
|
|
6408
7302
|
$mol_assert_equal(...args);
|
|
6409
7303
|
}
|
|
6410
7304
|
$.$mol_assert_like = $mol_assert_like;
|
|
7305
|
+
/**
|
|
7306
|
+
* All arguments must not be structural equal to each other.
|
|
7307
|
+
* @example
|
|
7308
|
+
* $mol_assert_unique( 1 , 2 , 3 ) // Passes
|
|
7309
|
+
* $mol_assert_unique( 1 , 1 , 2 ) // Fails because 1 === 1
|
|
7310
|
+
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
|
|
7311
|
+
*/
|
|
6411
7312
|
function $mol_assert_unique(...args) {
|
|
6412
7313
|
for (let i = 0; i < args.length; ++i) {
|
|
6413
7314
|
for (let j = 0; j < args.length; ++j) {
|
|
@@ -6415,40 +7316,26 @@ var $;
|
|
|
6415
7316
|
continue;
|
|
6416
7317
|
if (!$mol_compare_deep(args[i], args[j]))
|
|
6417
7318
|
continue;
|
|
6418
|
-
$mol_fail(new Error(`
|
|
7319
|
+
return $mol_fail(new Error(`Uniquesess assertion failure`, { cause: { [i]: args[i], [i]: args[i] } }));
|
|
6419
7320
|
}
|
|
6420
7321
|
}
|
|
6421
7322
|
}
|
|
6422
7323
|
$.$mol_assert_unique = $mol_assert_unique;
|
|
7324
|
+
/**
|
|
7325
|
+
* All arguments must be structural equal each other.
|
|
7326
|
+
* @example
|
|
7327
|
+
* $mol_assert_like( [1] , [1] , [1] ) // Passes
|
|
7328
|
+
* $mol_assert_like( [1] , [1] , [2] ) // Fails because 1 !== 2
|
|
7329
|
+
* @see https://mol.hyoo.ru/#!section=docs/=9q9dv3_fgxjsf
|
|
7330
|
+
*/
|
|
6423
7331
|
function $mol_assert_equal(...args) {
|
|
6424
7332
|
for (let i = 1; i < args.length; ++i) {
|
|
6425
7333
|
if ($mol_compare_deep(args[0], args[i]))
|
|
6426
7334
|
continue;
|
|
6427
|
-
|
|
6428
|
-
continue;
|
|
6429
|
-
return $mol_fail(new Error(`args[0] ≠ args[${i}]\n${print(args[0])}\n---\n${print(args[i])}`));
|
|
7335
|
+
return $mol_fail(new Error(`Equality assertion failure`, { cause: { 0: args[0], [i]: args[i] } }));
|
|
6430
7336
|
}
|
|
6431
7337
|
}
|
|
6432
7338
|
$.$mol_assert_equal = $mol_assert_equal;
|
|
6433
|
-
const print = (val) => {
|
|
6434
|
-
if (!val)
|
|
6435
|
-
return val;
|
|
6436
|
-
if (typeof val === 'bigint')
|
|
6437
|
-
return String(val) + 'n';
|
|
6438
|
-
if (typeof val === 'symbol')
|
|
6439
|
-
return `Symbol(${val.description})`;
|
|
6440
|
-
if (typeof val !== 'object')
|
|
6441
|
-
return val;
|
|
6442
|
-
if ('outerHTML' in val)
|
|
6443
|
-
return val.outerHTML;
|
|
6444
|
-
try {
|
|
6445
|
-
return JSON.stringify(val, (k, v) => typeof v === 'bigint' ? String(v) : v, '\t');
|
|
6446
|
-
}
|
|
6447
|
-
catch (error) {
|
|
6448
|
-
console.error(error);
|
|
6449
|
-
return val;
|
|
6450
|
-
}
|
|
6451
|
-
};
|
|
6452
7339
|
})($ || ($ = {}));
|
|
6453
7340
|
|
|
6454
7341
|
;
|
|
@@ -6475,16 +7362,16 @@ var $;
|
|
|
6475
7362
|
$mol_assert_unique([1], [2], [3]);
|
|
6476
7363
|
},
|
|
6477
7364
|
'two must be alike'() {
|
|
6478
|
-
$
|
|
7365
|
+
$mol_assert_equal([3], [3]);
|
|
6479
7366
|
},
|
|
6480
7367
|
'three must be alike'() {
|
|
6481
|
-
$
|
|
7368
|
+
$mol_assert_equal([3], [3], [3]);
|
|
6482
7369
|
},
|
|
6483
7370
|
'two object must be alike'() {
|
|
6484
|
-
$
|
|
7371
|
+
$mol_assert_equal({ a: 1 }, { a: 1 });
|
|
6485
7372
|
},
|
|
6486
7373
|
'three object must be alike'() {
|
|
6487
|
-
$
|
|
7374
|
+
$mol_assert_equal({ a: 1 }, { a: 1 }, { a: 1 });
|
|
6488
7375
|
},
|
|
6489
7376
|
});
|
|
6490
7377
|
})($ || ($ = {}));
|
|
@@ -6503,6 +7390,30 @@ var $;
|
|
|
6503
7390
|
});
|
|
6504
7391
|
})($ || ($ = {}));
|
|
6505
7392
|
|
|
7393
|
+
;
|
|
7394
|
+
"use strict";
|
|
7395
|
+
var $;
|
|
7396
|
+
(function ($) {
|
|
7397
|
+
$mol_test({
|
|
7398
|
+
'return result without errors'() {
|
|
7399
|
+
$mol_assert_equal($mol_try(() => false), false);
|
|
7400
|
+
},
|
|
7401
|
+
//'return error if thrown'() {
|
|
7402
|
+
//
|
|
7403
|
+
// const error = new Error( '$mol_try test error' )
|
|
7404
|
+
// $mol_assert_equal( $mol_try( ()=> { throw error } ) , error )
|
|
7405
|
+
//
|
|
7406
|
+
//} ,
|
|
7407
|
+
});
|
|
7408
|
+
})($ || ($ = {}));
|
|
7409
|
+
|
|
7410
|
+
;
|
|
7411
|
+
"use strict";
|
|
7412
|
+
var $;
|
|
7413
|
+
(function ($_1) {
|
|
7414
|
+
$mol_test_mocks.push($ => $.$mol_fail_log = () => false);
|
|
7415
|
+
})($ || ($ = {}));
|
|
7416
|
+
|
|
6506
7417
|
;
|
|
6507
7418
|
"use strict";
|
|
6508
7419
|
var $;
|
|
@@ -6574,10 +7485,23 @@ var $;
|
|
|
6574
7485
|
var $;
|
|
6575
7486
|
(function ($) {
|
|
6576
7487
|
$mol_test({
|
|
6577
|
-
'encode
|
|
6578
|
-
|
|
6579
|
-
|
|
6580
|
-
|
|
7488
|
+
'encode empty'() {
|
|
7489
|
+
$mol_assert_equal($mol_charset_encode(''), new Uint8Array([]));
|
|
7490
|
+
},
|
|
7491
|
+
'encode 1 octet'() {
|
|
7492
|
+
$mol_assert_equal($mol_charset_encode('F'), new Uint8Array([0x46]));
|
|
7493
|
+
},
|
|
7494
|
+
'encode 2 octet'() {
|
|
7495
|
+
$mol_assert_equal($mol_charset_encode('Б'), new Uint8Array([0xd0, 0x91]));
|
|
7496
|
+
},
|
|
7497
|
+
'encode 3 octet'() {
|
|
7498
|
+
$mol_assert_equal($mol_charset_encode('ह'), new Uint8Array([0xe0, 0xa4, 0xb9]));
|
|
7499
|
+
},
|
|
7500
|
+
'encode 4 octet'() {
|
|
7501
|
+
$mol_assert_equal($mol_charset_encode('𐍈'), new Uint8Array([0xf0, 0x90, 0x8d, 0x88]));
|
|
7502
|
+
},
|
|
7503
|
+
'encode surrogate pair'() {
|
|
7504
|
+
$mol_assert_equal($mol_charset_encode('😀'), new Uint8Array([0xf0, 0x9f, 0x98, 0x80]));
|
|
6581
7505
|
},
|
|
6582
7506
|
});
|
|
6583
7507
|
})($ || ($ = {}));
|
|
@@ -6641,6 +7565,9 @@ var $;
|
|
|
6641
7565
|
gender["bisexual"] = "bisexual";
|
|
6642
7566
|
gender["trans"] = "transgender";
|
|
6643
7567
|
})(gender || (gender = {}));
|
|
7568
|
+
// Test disabled due https://github.com/microsoft/TypeScript/issues/46112
|
|
7569
|
+
// const Sex = $mol_data_enum( 'sex' , sex )
|
|
7570
|
+
// type sex_value = $mol_type_assert< typeof Sex.Value , sex >
|
|
6644
7571
|
$mol_test({
|
|
6645
7572
|
'config of enum'() {
|
|
6646
7573
|
const Sex = $mol_data_enum('sex', sex);
|
|
@@ -6670,6 +7597,8 @@ var $;
|
|
|
6670
7597
|
$mol_assert_fail(() => Sex('__proto__'), `__proto__ is not value of sex enum`);
|
|
6671
7598
|
},
|
|
6672
7599
|
});
|
|
7600
|
+
// Test disabled due https://github.com/microsoft/TypeScript/issues/46112
|
|
7601
|
+
// type gender_value = $mol_type_assert< typeof Gender.Value , gender >
|
|
6673
7602
|
$mol_test({
|
|
6674
7603
|
'config of enum'() {
|
|
6675
7604
|
const Gender = $mol_data_enum('gender', gender);
|
|
@@ -6697,36 +7626,6 @@ var $;
|
|
|
6697
7626
|
});
|
|
6698
7627
|
})($ || ($ = {}));
|
|
6699
7628
|
|
|
6700
|
-
;
|
|
6701
|
-
"use strict";
|
|
6702
|
-
var $;
|
|
6703
|
-
(function ($) {
|
|
6704
|
-
const png = new Uint8Array([0x1a, 0x0a, 0x00, 0x49, 0x48, 0x78, 0xda]);
|
|
6705
|
-
$mol_test({
|
|
6706
|
-
'base64 encode string'() {
|
|
6707
|
-
$mol_assert_equal($mol_base64_encode('Hello, ΧΨΩЫ'), 'SGVsbG8sIM6nzqjOqdCr');
|
|
6708
|
-
},
|
|
6709
|
-
'base64 encode binary'() {
|
|
6710
|
-
$mol_assert_equal($mol_base64_encode(png), 'GgoASUh42g==');
|
|
6711
|
-
},
|
|
6712
|
-
});
|
|
6713
|
-
})($ || ($ = {}));
|
|
6714
|
-
|
|
6715
|
-
;
|
|
6716
|
-
"use strict";
|
|
6717
|
-
var $;
|
|
6718
|
-
(function ($) {
|
|
6719
|
-
const png = new Uint8Array([0x1a, 0x0a, 0x00, 0x49, 0x48, 0x78, 0xda]);
|
|
6720
|
-
$mol_test({
|
|
6721
|
-
'base64 decode string'() {
|
|
6722
|
-
$mol_assert_like($mol_base64_decode('SGVsbG8sIM6nzqjOqdCr'), new TextEncoder().encode('Hello, ΧΨΩЫ'));
|
|
6723
|
-
},
|
|
6724
|
-
'base64 decode binary'() {
|
|
6725
|
-
$mol_assert_like($mol_base64_decode('GgoASUh42g=='), png);
|
|
6726
|
-
},
|
|
6727
|
-
});
|
|
6728
|
-
})($ || ($ = {}));
|
|
6729
|
-
|
|
6730
7629
|
;
|
|
6731
7630
|
"use strict";
|
|
6732
7631
|
var $;
|
|
@@ -6751,30 +7650,30 @@ var $;
|
|
|
6751
7650
|
(function ($_1) {
|
|
6752
7651
|
const common = [
|
|
6753
7652
|
$mol_int62_to_string({
|
|
6754
|
-
lo: 12 << 0 | 13 << 8 | 14 << 16 | 15 << 24,
|
|
6755
|
-
hi: 13 << 0 | 14 << 8 | 15 << 16 | 16 << 24,
|
|
7653
|
+
lo: 12 << 0 | 13 << 8 | 14 << 16 | 15 << 24, // land_lo
|
|
7654
|
+
hi: 13 << 0 | 14 << 8 | 15 << 16 | 16 << 24, // land_hi
|
|
6756
7655
|
}),
|
|
6757
7656
|
$mol_int62_to_string({
|
|
6758
|
-
lo: 2 << 0 | 3 << 8 | 4 << 16 | 5 << 24,
|
|
6759
|
-
hi: 3 << 0 | 4 << 8 | 5 << 16 | 6 << 24,
|
|
7657
|
+
lo: 2 << 0 | 3 << 8 | 4 << 16 | 5 << 24, // auth_lo
|
|
7658
|
+
hi: 3 << 0 | 4 << 8 | 5 << 16 | 6 << 24, // auto_hi
|
|
6760
7659
|
}),
|
|
6761
7660
|
$mol_int62_to_string({
|
|
6762
|
-
lo: 4 << 0 | 5 << 8 | 6 << 16 | 7 << 24,
|
|
6763
|
-
hi: 5 << 0 | 6 << 8 | 7 << 16 | 8 << 24,
|
|
7661
|
+
lo: 4 << 0 | 5 << 8 | 6 << 16 | 7 << 24, // head_lo
|
|
7662
|
+
hi: 5 << 0 | 6 << 8 | 7 << 16 | 8 << 24, // head_hi
|
|
6764
7663
|
}),
|
|
6765
7664
|
$mol_int62_to_string({
|
|
6766
|
-
lo: 10 << 0 | 11 << 8 | 12 << 16 | 13 << 24,
|
|
6767
|
-
hi: 11 << 0 | 12 << 8 | 13 << 16 | 14 << 24,
|
|
7665
|
+
lo: 10 << 0 | 11 << 8 | 12 << 16 | 13 << 24, // self_lo
|
|
7666
|
+
hi: 11 << 0 | 12 << 8 | 13 << 16 | 14 << 24, // self_hi
|
|
6768
7667
|
}),
|
|
6769
7668
|
$mol_int62_to_string({
|
|
6770
|
-
lo: 6 << 0 | 7 << 8 | 8 << 16 | 9 << 24,
|
|
6771
|
-
hi: 7 << 0 | 8 << 8 | 9 << 16 | 10 << 24,
|
|
7669
|
+
lo: 6 << 0 | 7 << 8 | 8 << 16 | 9 << 24, // next_lo
|
|
7670
|
+
hi: 7 << 0 | 8 << 8 | 9 << 16 | 10 << 24, // next_hi
|
|
6772
7671
|
}),
|
|
6773
7672
|
$mol_int62_to_string({
|
|
6774
|
-
lo: 8 << 0 | 9 << 8 | 10 << 16 | 11 << 24,
|
|
6775
|
-
hi: 9 << 0 | 10 << 8 | 11 << 16 | 12 << 24,
|
|
7673
|
+
lo: 8 << 0 | 9 << 8 | 10 << 16 | 11 << 24, // prev_lo
|
|
7674
|
+
hi: 9 << 0 | 10 << 8 | 11 << 16 | 12 << 24, // prev_hi
|
|
6776
7675
|
}),
|
|
6777
|
-
1 << 0 | 2 << 8 | 3 << 16 | 4 << 24,
|
|
7676
|
+
1 << 0 | 2 << 8 | 3 << 16 | 4 << 24, // time
|
|
6778
7677
|
];
|
|
6779
7678
|
$mol_test({
|
|
6780
7679
|
'pack and unpack unit with null'($) {
|
|
@@ -6871,6 +7770,7 @@ var $;
|
|
|
6871
7770
|
"use strict";
|
|
6872
7771
|
var $;
|
|
6873
7772
|
(function ($) {
|
|
7773
|
+
/// @todo right orderinng
|
|
6874
7774
|
$.$mol_after_mock_queue = [];
|
|
6875
7775
|
function $mol_after_mock_warp() {
|
|
6876
7776
|
const queue = $.$mol_after_mock_queue.splice(0);
|
|
@@ -7108,7 +8008,7 @@ var $;
|
|
|
7108
8008
|
}
|
|
7109
8009
|
await $mol_wire_async(A).a();
|
|
7110
8010
|
$mol_assert_equal(A.instances.length, 2);
|
|
7111
|
-
$mol_assert_equal(A.instances[0] instanceof A);
|
|
8011
|
+
$mol_assert_equal(A.instances[0] instanceof A, true);
|
|
7112
8012
|
$mol_assert_equal(A.instances[0], A.instances[1]);
|
|
7113
8013
|
}
|
|
7114
8014
|
});
|
|
@@ -7194,6 +8094,7 @@ var $;
|
|
|
7194
8094
|
var $;
|
|
7195
8095
|
(function ($_1) {
|
|
7196
8096
|
$mol_test({
|
|
8097
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#component-states
|
|
7197
8098
|
'Cached channel'($) {
|
|
7198
8099
|
class App extends $mol_object2 {
|
|
7199
8100
|
static $ = $;
|
|
@@ -7251,6 +8152,7 @@ var $;
|
|
|
7251
8152
|
$mol_assert_equal(App.value(5), 21);
|
|
7252
8153
|
$mol_assert_equal(App.value(), 21);
|
|
7253
8154
|
},
|
|
8155
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#wish-consistency
|
|
7254
8156
|
'Auto recalculation of cached values'($) {
|
|
7255
8157
|
class App extends $mol_object2 {
|
|
7256
8158
|
static $ = $;
|
|
@@ -7278,6 +8180,7 @@ var $;
|
|
|
7278
8180
|
App.xxx(5);
|
|
7279
8181
|
$mol_assert_equal(App.zzz(), 7);
|
|
7280
8182
|
},
|
|
8183
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#wish-reasonability
|
|
7281
8184
|
'Skip recalculation when actually no dependency changes'($) {
|
|
7282
8185
|
const log = [];
|
|
7283
8186
|
class App extends $mol_object2 {
|
|
@@ -7311,6 +8214,7 @@ var $;
|
|
|
7311
8214
|
App.zzz();
|
|
7312
8215
|
$mol_assert_like(log, ['zzz', 'yyy', 'xxx', 'xxx', 'yyy']);
|
|
7313
8216
|
},
|
|
8217
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#flow-auto
|
|
7314
8218
|
'Flow: Auto'($) {
|
|
7315
8219
|
class App extends $mol_object2 {
|
|
7316
8220
|
static get $() { return $; }
|
|
@@ -7348,6 +8252,7 @@ var $;
|
|
|
7348
8252
|
$mol_assert_equal(App.result(), 23);
|
|
7349
8253
|
$mol_assert_equal(App.counter, 4);
|
|
7350
8254
|
},
|
|
8255
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#dupes-equality
|
|
7351
8256
|
'Dupes: Equality'($) {
|
|
7352
8257
|
let counter = 0;
|
|
7353
8258
|
class App extends $mol_object2 {
|
|
@@ -7371,6 +8276,7 @@ var $;
|
|
|
7371
8276
|
App.foo({ numbs: [2] });
|
|
7372
8277
|
$mol_assert_like(App.bar(), { numbs: [2], count: 2 });
|
|
7373
8278
|
},
|
|
8279
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#cycle-fail
|
|
7374
8280
|
'Cycle: Fail'($) {
|
|
7375
8281
|
class App extends $mol_object2 {
|
|
7376
8282
|
static $ = $;
|
|
@@ -7395,6 +8301,29 @@ var $;
|
|
|
7395
8301
|
], App, "test", null);
|
|
7396
8302
|
App.test();
|
|
7397
8303
|
},
|
|
8304
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
|
|
8305
|
+
// 'Update deps on push'( $ ) {
|
|
8306
|
+
// class App extends $mol_object2 {
|
|
8307
|
+
// static $ = $
|
|
8308
|
+
// @ $mol_wire_solo
|
|
8309
|
+
// static left( next = false ) {
|
|
8310
|
+
// return next
|
|
8311
|
+
// }
|
|
8312
|
+
// @ $mol_wire_solo
|
|
8313
|
+
// static right( next = false ) {
|
|
8314
|
+
// return next
|
|
8315
|
+
// }
|
|
8316
|
+
// @ $mol_wire_solo
|
|
8317
|
+
// static res( next?: boolean ) {
|
|
8318
|
+
// return this.left( next ) && this.right()
|
|
8319
|
+
// }
|
|
8320
|
+
// }
|
|
8321
|
+
// $mol_assert_equal( App.res(), false )
|
|
8322
|
+
// $mol_assert_equal( App.res( true ), false )
|
|
8323
|
+
// $mol_assert_equal( App.right( true ), true )
|
|
8324
|
+
// $mol_assert_equal( App.res(), true )
|
|
8325
|
+
// } ,
|
|
8326
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
|
|
7398
8327
|
'Different order of pull and push'($) {
|
|
7399
8328
|
class App extends $mol_object2 {
|
|
7400
8329
|
static $ = $;
|
|
@@ -7406,7 +8335,7 @@ var $;
|
|
|
7406
8335
|
}
|
|
7407
8336
|
static slow(next) {
|
|
7408
8337
|
if (next !== undefined)
|
|
7409
|
-
this.slow();
|
|
8338
|
+
this.slow(); // enforce pull before push
|
|
7410
8339
|
return this.store(next);
|
|
7411
8340
|
}
|
|
7412
8341
|
}
|
|
@@ -7425,6 +8354,7 @@ var $;
|
|
|
7425
8354
|
App.store(777);
|
|
7426
8355
|
$mol_assert_equal(App.fast(), App.slow(), 777);
|
|
7427
8356
|
},
|
|
8357
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
|
|
7428
8358
|
'Actions inside invariant'($) {
|
|
7429
8359
|
class App extends $mol_object2 {
|
|
7430
8360
|
static $ = $;
|
|
@@ -7464,6 +8394,7 @@ var $;
|
|
|
7464
8394
|
static toggle() {
|
|
7465
8395
|
const prev = this.checked();
|
|
7466
8396
|
$mol_assert_unique(this.checked(!prev), prev);
|
|
8397
|
+
// $mol_assert_equal( this.checked() , prev )
|
|
7467
8398
|
}
|
|
7468
8399
|
static res() {
|
|
7469
8400
|
return this.checked();
|
|
@@ -7488,6 +8419,39 @@ var $;
|
|
|
7488
8419
|
], App, "test", null);
|
|
7489
8420
|
await $mol_wire_async(App).test();
|
|
7490
8421
|
},
|
|
8422
|
+
// // https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
|
|
8423
|
+
// 'Stable order of multiple root'( $ ) {
|
|
8424
|
+
// class App extends $mol_object2 {
|
|
8425
|
+
// static $ = $
|
|
8426
|
+
// static counter = 0
|
|
8427
|
+
// @ $mol_wire_solo
|
|
8428
|
+
// static left_trigger( next = 0 ) {
|
|
8429
|
+
// return next
|
|
8430
|
+
// }
|
|
8431
|
+
// @ $mol_wire_solo
|
|
8432
|
+
// static left_root() {
|
|
8433
|
+
// this.left_trigger()
|
|
8434
|
+
// return ++ this.counter
|
|
8435
|
+
// }
|
|
8436
|
+
// @ $mol_wire_solo
|
|
8437
|
+
// static right_trigger( next = 0 ) {
|
|
8438
|
+
// return next
|
|
8439
|
+
// }
|
|
8440
|
+
// @ $mol_wire_solo
|
|
8441
|
+
// static right_root() {
|
|
8442
|
+
// this.right_trigger()
|
|
8443
|
+
// return ++ this.counter
|
|
8444
|
+
// }
|
|
8445
|
+
// }
|
|
8446
|
+
// $mol_assert_equal( App.left_root(), 1 )
|
|
8447
|
+
// $mol_assert_equal( App.right_root(), 2 )
|
|
8448
|
+
// App.right_trigger( 1 )
|
|
8449
|
+
// App.left_trigger( 1 )
|
|
8450
|
+
// $mol_wire_fiber.sync()
|
|
8451
|
+
// $mol_assert_equal( App.right_root(), 4 )
|
|
8452
|
+
// $mol_assert_equal( App.left_root(), 3 )
|
|
8453
|
+
// } ,
|
|
8454
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#error-store
|
|
7491
8455
|
'Restore after error'($) {
|
|
7492
8456
|
class App extends $mol_object2 {
|
|
7493
8457
|
static get $() { return $; }
|
|
@@ -7585,6 +8549,7 @@ var $;
|
|
|
7585
8549
|
App.showing(true);
|
|
7586
8550
|
$mol_assert_unique(App.render(), details);
|
|
7587
8551
|
},
|
|
8552
|
+
// https://github.com/nin-jin/slides/tree/master/reactivity#wish-stability
|
|
7588
8553
|
async 'Hold pubs while wait async task'($) {
|
|
7589
8554
|
class App extends $mol_object2 {
|
|
7590
8555
|
static $ = $;
|
|
@@ -7601,8 +8566,6 @@ var $;
|
|
|
7601
8566
|
$mol_wire_sync(this).wait();
|
|
7602
8567
|
return this.value();
|
|
7603
8568
|
}
|
|
7604
|
-
static test() {
|
|
7605
|
-
}
|
|
7606
8569
|
}
|
|
7607
8570
|
__decorate([
|
|
7608
8571
|
$mol_wire_solo
|
|
@@ -7613,9 +8576,6 @@ var $;
|
|
|
7613
8576
|
__decorate([
|
|
7614
8577
|
$mol_wire_solo
|
|
7615
8578
|
], App, "result", null);
|
|
7616
|
-
__decorate([
|
|
7617
|
-
$mol_wire_method
|
|
7618
|
-
], App, "test", null);
|
|
7619
8579
|
$mol_assert_equal(App.result(), 1);
|
|
7620
8580
|
App.resets(null);
|
|
7621
8581
|
$mol_wire_fiber.sync();
|
|
@@ -7806,7 +8766,7 @@ var $;
|
|
|
7806
8766
|
;
|
|
7807
8767
|
"use strict";
|
|
7808
8768
|
var $;
|
|
7809
|
-
(function ($) {
|
|
8769
|
+
(function ($_1) {
|
|
7810
8770
|
$mol_test({
|
|
7811
8771
|
'init with overload'() {
|
|
7812
8772
|
class X extends $mol_object {
|
|
@@ -7819,6 +8779,22 @@ var $;
|
|
|
7819
8779
|
});
|
|
7820
8780
|
$mol_assert_equal(x.foo(), 2);
|
|
7821
8781
|
},
|
|
8782
|
+
'Context in instance inherits from class'($) {
|
|
8783
|
+
const custom = $.$mol_ambient({});
|
|
8784
|
+
class X extends $.$mol_object {
|
|
8785
|
+
static $ = custom;
|
|
8786
|
+
}
|
|
8787
|
+
$mol_assert_equal(new X().$, custom);
|
|
8788
|
+
},
|
|
8789
|
+
});
|
|
8790
|
+
})($ || ($ = {}));
|
|
8791
|
+
|
|
8792
|
+
;
|
|
8793
|
+
"use strict";
|
|
8794
|
+
var $;
|
|
8795
|
+
(function ($_1) {
|
|
8796
|
+
$mol_test_mocks.push($ => {
|
|
8797
|
+
$.$mol_after_frame = $mol_after_mock_commmon;
|
|
7822
8798
|
});
|
|
7823
8799
|
})($ || ($ = {}));
|
|
7824
8800
|
|
|
@@ -8116,9 +9092,9 @@ var $;
|
|
|
8116
9092
|
if (!replace)
|
|
8117
9093
|
replace = (next, prev, lead) => insert(next, drop(prev, lead));
|
|
8118
9094
|
if (to > prev.length)
|
|
8119
|
-
to = prev.length;
|
|
9095
|
+
to = prev.length; // $mol_fail( new RangeError( `To(${ to }) greater then length(${ prev.length })` ) )
|
|
8120
9096
|
if (from > to)
|
|
8121
|
-
from = to;
|
|
9097
|
+
from = to; // $mol_fail( new RangeError( `From(${ to }) greater then to(${ to })` ) )
|
|
8122
9098
|
let p = from;
|
|
8123
9099
|
let n = 0;
|
|
8124
9100
|
let lead = p ? prev[p - 1] : null;
|
|
@@ -8148,6 +9124,8 @@ var $;
|
|
|
8148
9124
|
|
|
8149
9125
|
;
|
|
8150
9126
|
"use strict";
|
|
9127
|
+
/** @jsx $mol_jsx */
|
|
9128
|
+
/** @jsxFrag $mol_jsx_frag */
|
|
8151
9129
|
var $;
|
|
8152
9130
|
(function ($) {
|
|
8153
9131
|
$mol_test({
|
|
@@ -8170,10 +9148,10 @@ var $;
|
|
|
8170
9148
|
return prev;
|
|
8171
9149
|
},
|
|
8172
9150
|
});
|
|
8173
|
-
$mol_assert_equal(list, $mol_jsx("body", null,
|
|
9151
|
+
$mol_assert_equal(list.outerHTML, ($mol_jsx("body", null,
|
|
8174
9152
|
$mol_jsx("p", { "data-rev": "old" }, "a"),
|
|
8175
9153
|
$mol_jsx("p", { "data-rev": "old" }, "b"),
|
|
8176
|
-
$mol_jsx("p", { "data-rev": "old" }, "c")));
|
|
9154
|
+
$mol_jsx("p", { "data-rev": "old" }, "c"))).outerHTML);
|
|
8177
9155
|
},
|
|
8178
9156
|
'insert items'() {
|
|
8179
9157
|
const list = $mol_jsx("body", null,
|
|
@@ -8195,13 +9173,13 @@ var $;
|
|
|
8195
9173
|
return prev;
|
|
8196
9174
|
},
|
|
8197
9175
|
});
|
|
8198
|
-
$mol_assert_equal(list, $mol_jsx("body", null,
|
|
9176
|
+
$mol_assert_equal(list.outerHTML, ($mol_jsx("body", null,
|
|
8199
9177
|
$mol_jsx("p", { "data-rev": "old" }, "a"),
|
|
8200
9178
|
$mol_jsx("p", { "data-rev": "old" }, "b"),
|
|
8201
9179
|
$mol_jsx("p", { "data-rev": "new" }, "X"),
|
|
8202
9180
|
$mol_jsx("p", { "data-rev": "new" }, "Y"),
|
|
8203
9181
|
$mol_jsx("p", { "data-rev": "old" }, "c"),
|
|
8204
|
-
$mol_jsx("p", { "data-rev": "old" }, "d")));
|
|
9182
|
+
$mol_jsx("p", { "data-rev": "old" }, "d"))).outerHTML);
|
|
8205
9183
|
},
|
|
8206
9184
|
'append items'() {
|
|
8207
9185
|
const list = $mol_jsx("body", null,
|
|
@@ -8220,10 +9198,10 @@ var $;
|
|
|
8220
9198
|
return prev;
|
|
8221
9199
|
},
|
|
8222
9200
|
});
|
|
8223
|
-
$mol_assert_equal(list, $mol_jsx("body", null,
|
|
9201
|
+
$mol_assert_equal(list.outerHTML, ($mol_jsx("body", null,
|
|
8224
9202
|
$mol_jsx("p", { "data-rev": "old" }, "a"),
|
|
8225
9203
|
$mol_jsx("p", { "data-rev": "new" }, "b"),
|
|
8226
|
-
$mol_jsx("p", { "data-rev": "new" }, "c")));
|
|
9204
|
+
$mol_jsx("p", { "data-rev": "new" }, "c"))).outerHTML);
|
|
8227
9205
|
},
|
|
8228
9206
|
'split item'() {
|
|
8229
9207
|
const list = $mol_jsx("body", null,
|
|
@@ -8244,11 +9222,11 @@ var $;
|
|
|
8244
9222
|
return prev;
|
|
8245
9223
|
},
|
|
8246
9224
|
});
|
|
8247
|
-
$mol_assert_equal(list, $mol_jsx("body", null,
|
|
9225
|
+
$mol_assert_equal(list.outerHTML, ($mol_jsx("body", null,
|
|
8248
9226
|
$mol_jsx("p", { "data-rev": "old" }, "a"),
|
|
8249
9227
|
$mol_jsx("p", { "data-rev": "new" }, "b"),
|
|
8250
9228
|
$mol_jsx("p", { "data-rev": "up" }, "c"),
|
|
8251
|
-
$mol_jsx("p", { "data-rev": "old" }, "d")));
|
|
9229
|
+
$mol_jsx("p", { "data-rev": "old" }, "d"))).outerHTML);
|
|
8252
9230
|
},
|
|
8253
9231
|
'drop items'() {
|
|
8254
9232
|
const list = $mol_jsx("body", null,
|
|
@@ -8272,11 +9250,11 @@ var $;
|
|
|
8272
9250
|
return prev;
|
|
8273
9251
|
},
|
|
8274
9252
|
});
|
|
8275
|
-
$mol_assert_equal(list, $mol_jsx("body", null,
|
|
9253
|
+
$mol_assert_equal(list.outerHTML, ($mol_jsx("body", null,
|
|
8276
9254
|
$mol_jsx("p", { "data-rev": "old" }, "A"),
|
|
8277
9255
|
$mol_jsx("p", { "data-rev": "old" }, "B"),
|
|
8278
9256
|
$mol_jsx("p", { "data-rev": "old" }, "C"),
|
|
8279
|
-
$mol_jsx("p", { "data-rev": "old" }, "D")));
|
|
9257
|
+
$mol_jsx("p", { "data-rev": "old" }, "D"))).outerHTML);
|
|
8280
9258
|
},
|
|
8281
9259
|
'update items'() {
|
|
8282
9260
|
const list = $mol_jsx("body", null,
|
|
@@ -8298,11 +9276,11 @@ var $;
|
|
|
8298
9276
|
return prev;
|
|
8299
9277
|
},
|
|
8300
9278
|
});
|
|
8301
|
-
$mol_assert_equal(list, $mol_jsx("body", null,
|
|
9279
|
+
$mol_assert_equal(list.outerHTML, ($mol_jsx("body", null,
|
|
8302
9280
|
$mol_jsx("p", { "data-rev": "old" }, "a"),
|
|
8303
9281
|
$mol_jsx("p", { "data-rev": "up" }, "X"),
|
|
8304
9282
|
$mol_jsx("p", { "data-rev": "up" }, "Y"),
|
|
8305
|
-
$mol_jsx("p", { "data-rev": "old" }, "d")));
|
|
9283
|
+
$mol_jsx("p", { "data-rev": "old" }, "d"))).outerHTML);
|
|
8306
9284
|
},
|
|
8307
9285
|
});
|
|
8308
9286
|
})($ || ($ = {}));
|
|
@@ -8325,12 +9303,18 @@ var $;
|
|
|
8325
9303
|
;
|
|
8326
9304
|
"use strict";
|
|
8327
9305
|
|
|
9306
|
+
;
|
|
9307
|
+
"use strict";
|
|
9308
|
+
|
|
8328
9309
|
;
|
|
8329
9310
|
"use strict";
|
|
8330
9311
|
var $;
|
|
8331
9312
|
(function ($) {
|
|
9313
|
+
let x = /x/[Symbol.matchAll];
|
|
9314
|
+
/** Type safe reguar expression builder */
|
|
8332
9315
|
class $mol_regexp extends RegExp {
|
|
8333
9316
|
groups;
|
|
9317
|
+
/** Prefer to use $mol_regexp.from */
|
|
8334
9318
|
constructor(source, flags = 'gsu', groups = []) {
|
|
8335
9319
|
super(source, flags);
|
|
8336
9320
|
this.groups = groups;
|
|
@@ -8350,12 +9334,14 @@ var $;
|
|
|
8350
9334
|
this.lastIndex = index;
|
|
8351
9335
|
}
|
|
8352
9336
|
}
|
|
9337
|
+
/** Parses input and returns found capture groups or null */
|
|
8353
9338
|
[Symbol.match](str) {
|
|
8354
9339
|
const res = [...this[Symbol.matchAll](str)].filter(r => r.groups).map(r => r[0]);
|
|
8355
9340
|
if (!res.length)
|
|
8356
9341
|
return null;
|
|
8357
9342
|
return res;
|
|
8358
9343
|
}
|
|
9344
|
+
/** Splits string by regexp edges */
|
|
8359
9345
|
[Symbol.split](str) {
|
|
8360
9346
|
const res = [];
|
|
8361
9347
|
let token_last = null;
|
|
@@ -8410,6 +9396,14 @@ var $;
|
|
|
8410
9396
|
get native() {
|
|
8411
9397
|
return new RegExp(this.source, this.flags);
|
|
8412
9398
|
}
|
|
9399
|
+
/** Makes regexp that greedy repeats this pattern with delimiter */
|
|
9400
|
+
static separated(chunk, sep) {
|
|
9401
|
+
return $mol_regexp.from([
|
|
9402
|
+
$mol_regexp.repeat_greedy([[chunk], sep], 0),
|
|
9403
|
+
chunk,
|
|
9404
|
+
]);
|
|
9405
|
+
}
|
|
9406
|
+
/** Makes regexp that non-greedy repeats this pattern from min to max count */
|
|
8413
9407
|
static repeat(source, min = 0, max = Number.POSITIVE_INFINITY) {
|
|
8414
9408
|
const regexp = $mol_regexp.from(source);
|
|
8415
9409
|
const upper = Number.isFinite(max) ? max : '';
|
|
@@ -8425,6 +9419,7 @@ var $;
|
|
|
8425
9419
|
};
|
|
8426
9420
|
return regexp2;
|
|
8427
9421
|
}
|
|
9422
|
+
/** Makes regexp that greedy repeats this pattern from min to max count */
|
|
8428
9423
|
static repeat_greedy(source, min = 0, max = Number.POSITIVE_INFINITY) {
|
|
8429
9424
|
const regexp = $mol_regexp.from(source);
|
|
8430
9425
|
const upper = Number.isFinite(max) ? max : '';
|
|
@@ -8440,26 +9435,31 @@ var $;
|
|
|
8440
9435
|
};
|
|
8441
9436
|
return regexp2;
|
|
8442
9437
|
}
|
|
8443
|
-
|
|
9438
|
+
/** Makes regexp that match any of options */
|
|
9439
|
+
static vary(sources, flags = 'gsu') {
|
|
8444
9440
|
const groups = [];
|
|
8445
9441
|
const chunks = sources.map(source => {
|
|
8446
9442
|
const regexp = $mol_regexp.from(source);
|
|
8447
9443
|
groups.push(...regexp.groups);
|
|
8448
9444
|
return regexp.source;
|
|
8449
9445
|
});
|
|
8450
|
-
return new $mol_regexp(`(?:${chunks.join('|')})`,
|
|
9446
|
+
return new $mol_regexp(`(?:${chunks.join('|')})`, flags, groups);
|
|
8451
9447
|
}
|
|
9448
|
+
/** Makes regexp that allow absent of this pattern */
|
|
8452
9449
|
static optional(source) {
|
|
8453
9450
|
return $mol_regexp.repeat_greedy(source, 0, 1);
|
|
8454
9451
|
}
|
|
9452
|
+
/** Makes regexp that look ahead for pattern */
|
|
8455
9453
|
static force_after(source) {
|
|
8456
9454
|
const regexp = $mol_regexp.from(source);
|
|
8457
9455
|
return new $mol_regexp(`(?=${regexp.source})`, regexp.flags, regexp.groups);
|
|
8458
9456
|
}
|
|
9457
|
+
/** Makes regexp that look ahead for pattern */
|
|
8459
9458
|
static forbid_after(source) {
|
|
8460
9459
|
const regexp = $mol_regexp.from(source);
|
|
8461
9460
|
return new $mol_regexp(`(?!${regexp.source})`, regexp.flags, regexp.groups);
|
|
8462
9461
|
}
|
|
9462
|
+
/** Converts some js values to regexp */
|
|
8463
9463
|
static from(source, { ignoreCase, multiline } = {
|
|
8464
9464
|
ignoreCase: false,
|
|
8465
9465
|
multiline: false,
|
|
@@ -8560,9 +9560,11 @@ var $;
|
|
|
8560
9560
|
return regexp;
|
|
8561
9561
|
}
|
|
8562
9562
|
}
|
|
9563
|
+
/** Makes regexp which includes only unicode category */
|
|
8563
9564
|
static unicode_only(...category) {
|
|
8564
9565
|
return new $mol_regexp(`\\p{${category.join('=')}}`);
|
|
8565
9566
|
}
|
|
9567
|
+
/** Makes regexp which excludes unicode category */
|
|
8566
9568
|
static unicode_except(...category) {
|
|
8567
9569
|
return new $mol_regexp(`\\P{${category.join('=')}}`);
|
|
8568
9570
|
}
|
|
@@ -9003,6 +10005,7 @@ var $;
|
|
|
9003
10005
|
var $;
|
|
9004
10006
|
(function ($) {
|
|
9005
10007
|
class $hyoo_crowd_text extends $hyoo_crowd_node {
|
|
10008
|
+
/** Text representation. Based on list of strings. */
|
|
9006
10009
|
text(next) {
|
|
9007
10010
|
if (next === undefined) {
|
|
9008
10011
|
return this.str();
|
|
@@ -9034,6 +10037,7 @@ var $;
|
|
|
9034
10037
|
return next;
|
|
9035
10038
|
}
|
|
9036
10039
|
}
|
|
10040
|
+
/** Text representation. Based on list of strings. */
|
|
9037
10041
|
str(next) {
|
|
9038
10042
|
if (next === undefined) {
|
|
9039
10043
|
let str = '';
|
|
@@ -9125,7 +10129,7 @@ var $;
|
|
|
9125
10129
|
return next;
|
|
9126
10130
|
}
|
|
9127
10131
|
else {
|
|
9128
|
-
this.units();
|
|
10132
|
+
this.units(); // track text to recalc selection on its change
|
|
9129
10133
|
return reg.value()
|
|
9130
10134
|
?.map(point => this.offset_by_point(point)[1]) ?? [0, 0];
|
|
9131
10135
|
}
|
|
@@ -9632,6 +10636,7 @@ var $;
|
|
|
9632
10636
|
|
|
9633
10637
|
;
|
|
9634
10638
|
"use strict";
|
|
10639
|
+
/** @jsx $mol_jsx */
|
|
9635
10640
|
var $;
|
|
9636
10641
|
(function ($) {
|
|
9637
10642
|
$mol_test({
|
|
@@ -9649,9 +10654,9 @@ var $;
|
|
|
9649
10654
|
$mol_assert_equal($mol_key({ foo: [false] }), '{"foo":[false]}');
|
|
9650
10655
|
},
|
|
9651
10656
|
'Uint8Array'() {
|
|
9652
|
-
$mol_assert_equal($mol_key(new Uint8Array([1, 2])), '[1,2]');
|
|
9653
|
-
$mol_assert_equal($mol_key([new Uint8Array([1, 2])]), '[[1,2]]');
|
|
9654
|
-
$mol_assert_equal($mol_key({ foo: new Uint8Array([1, 2]) }), '{"foo":[1,2]}');
|
|
10657
|
+
$mol_assert_equal($mol_key(new Uint8Array([1, 2])), 'Uint8Array([1,2])');
|
|
10658
|
+
$mol_assert_equal($mol_key([new Uint8Array([1, 2])]), '[Uint8Array([1,2])]');
|
|
10659
|
+
$mol_assert_equal($mol_key({ foo: new Uint8Array([1, 2]) }), '{"foo":Uint8Array([1,2])}');
|
|
9655
10660
|
},
|
|
9656
10661
|
'Function'() {
|
|
9657
10662
|
const func = () => { };
|
|
@@ -9671,6 +10676,12 @@ var $;
|
|
|
9671
10676
|
$mol_assert_unique($mol_key(foo), $mol_key($mol_jsx("div", null, "bar")));
|
|
9672
10677
|
},
|
|
9673
10678
|
'Custom JSON representation'() {
|
|
10679
|
+
class User {
|
|
10680
|
+
toJSON() { return 'jin'; }
|
|
10681
|
+
}
|
|
10682
|
+
$mol_assert_unique([$mol_key(new User)], [$mol_key(new User)]);
|
|
10683
|
+
},
|
|
10684
|
+
'Custom key handler'() {
|
|
9674
10685
|
class User {
|
|
9675
10686
|
name;
|
|
9676
10687
|
age;
|
|
@@ -9678,21 +10689,22 @@ var $;
|
|
|
9678
10689
|
this.name = name;
|
|
9679
10690
|
this.age = age;
|
|
9680
10691
|
}
|
|
9681
|
-
|
|
10692
|
+
[$mol_key_handle]() { return `User(${JSON.stringify(this.name)})`; }
|
|
9682
10693
|
}
|
|
9683
|
-
$mol_assert_equal($mol_key(new User('jin', 18)), '
|
|
10694
|
+
$mol_assert_equal($mol_key([new User('jin', 16)]), $mol_key([new User('jin', 18)]), '[User("jin")]');
|
|
9684
10695
|
},
|
|
9685
10696
|
'Special native classes'() {
|
|
9686
|
-
$mol_assert_equal($mol_key(new Date('xyz')), '
|
|
9687
|
-
$mol_assert_equal($mol_key(new Date(
|
|
9688
|
-
$mol_assert_equal($mol_key(/./), '
|
|
9689
|
-
$mol_assert_equal($mol_key(/\./gimsu), '
|
|
10697
|
+
$mol_assert_equal($mol_key(new Date('xyz')), 'Date(NaN)');
|
|
10698
|
+
$mol_assert_equal($mol_key(new Date(12345)), 'Date(12345)');
|
|
10699
|
+
$mol_assert_equal($mol_key(/./), '/./');
|
|
10700
|
+
$mol_assert_equal($mol_key(/\./gimsu), '/\\./gimsu');
|
|
9690
10701
|
},
|
|
9691
10702
|
});
|
|
9692
10703
|
})($ || ($ = {}));
|
|
9693
10704
|
|
|
9694
10705
|
;
|
|
9695
10706
|
"use strict";
|
|
10707
|
+
/** @jsx $mol_jsx */
|
|
9696
10708
|
var $;
|
|
9697
10709
|
(function ($) {
|
|
9698
10710
|
$mol_test({
|
|
@@ -9779,6 +10791,7 @@ var $;
|
|
|
9779
10791
|
var $;
|
|
9780
10792
|
(function ($) {
|
|
9781
10793
|
class $hyoo_crowd_list extends $hyoo_crowd_node {
|
|
10794
|
+
/** Data list representation. */
|
|
9782
10795
|
list(next) {
|
|
9783
10796
|
const units = this.units();
|
|
9784
10797
|
if (next === undefined) {
|
|
@@ -9892,8 +10905,10 @@ var $;
|
|
|
9892
10905
|
const world2 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
|
|
9893
10906
|
const land1 = await world1.grab();
|
|
9894
10907
|
const land2 = await world1.grab();
|
|
10908
|
+
// do changes
|
|
9895
10909
|
land1.chief.as($hyoo_crowd_list).list([123, 456]);
|
|
9896
10910
|
land2.chief.as($hyoo_crowd_list).list([456, 789]);
|
|
10911
|
+
// apply changes
|
|
9897
10912
|
for await (const batch of world1.delta()) {
|
|
9898
10913
|
$mol_assert_like((await world2.apply(batch)).forbid, new Map);
|
|
9899
10914
|
}
|
|
@@ -9904,7 +10919,9 @@ var $;
|
|
|
9904
10919
|
const world1 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
|
|
9905
10920
|
const world2 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
|
|
9906
10921
|
const land = world1.land(world1.peer.id);
|
|
10922
|
+
// do changes
|
|
9907
10923
|
land.chief.as($hyoo_crowd_list).list([123, 456]);
|
|
10924
|
+
// apply changes
|
|
9908
10925
|
const batch = await world1.delta_batch(land);
|
|
9909
10926
|
$mol_assert_like((await world2.apply(batch)).forbid, new Map);
|
|
9910
10927
|
$mol_assert_like(world2.land(land.id()).chief.as($hyoo_crowd_list).list(), [123, 456]);
|
|
@@ -9913,38 +10930,50 @@ var $;
|
|
|
9913
10930
|
const world1 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
|
|
9914
10931
|
const world2 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
|
|
9915
10932
|
const land = await world1.grab();
|
|
10933
|
+
// go to future
|
|
9916
10934
|
const clock = land.clock_data;
|
|
9917
10935
|
clock.see_time(clock.now() + 60 * 60 * 24 * 10);
|
|
10936
|
+
// do changes
|
|
9918
10937
|
land.chief.as($hyoo_crowd_reg).numb(123);
|
|
10938
|
+
// 1 ignored units
|
|
9919
10939
|
const batch = await world1.delta_batch(land);
|
|
9920
10940
|
$mol_assert_like([...(await world2.apply(batch)).forbid.values()], ['Far future']);
|
|
10941
|
+
// only 3 grab units
|
|
9921
10942
|
$mol_assert_like(world2.land(land.id()).delta().length, 3);
|
|
9922
10943
|
},
|
|
9923
10944
|
async 'ignore auth as another peer'() {
|
|
9924
10945
|
const world1 = new $hyoo_crowd_world({ ...await $hyoo_crowd_peer.generate(), id: '1_1' });
|
|
9925
10946
|
const world2 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
|
|
9926
10947
|
const land = await world1.grab();
|
|
10948
|
+
// do changes
|
|
9927
10949
|
land.chief.as($hyoo_crowd_reg).numb(123);
|
|
10950
|
+
// 2 ignored units
|
|
9928
10951
|
const batch = await world1.delta_batch(land);
|
|
9929
10952
|
$mol_assert_like([...(await world2.apply(batch)).forbid.values()], ['Alien join key', 'No auth key']);
|
|
10953
|
+
// only 2 grab units
|
|
9930
10954
|
$mol_assert_like(world2.land(land.id()).delta().length, 2);
|
|
9931
10955
|
},
|
|
9932
10956
|
async 'ignore auth without key'() {
|
|
9933
10957
|
const world1 = new $hyoo_crowd_world({ ...await $hyoo_crowd_peer.generate(), key_public_serial: [] });
|
|
9934
10958
|
const world2 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
|
|
9935
10959
|
const land = world1.land('1_1');
|
|
10960
|
+
// do changes
|
|
9936
10961
|
land.chief.as($hyoo_crowd_reg).numb(123);
|
|
10962
|
+
// 2 ignored units
|
|
9937
10963
|
const batch = await world1.delta_batch(land);
|
|
9938
10964
|
$mol_assert_like([...(await world2.apply(batch)).forbid.values()], ['No join key', 'Level too low']);
|
|
10965
|
+
// only 2 grab units
|
|
9939
10966
|
$mol_assert_like(world2.land(land.id()).delta().length, 0);
|
|
9940
10967
|
},
|
|
9941
10968
|
async 'ignore changes with wrong signs'() {
|
|
9942
10969
|
const world1 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
|
|
9943
10970
|
const world2 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
|
|
9944
10971
|
const land = await world1.grab();
|
|
10972
|
+
// 2 ignored units
|
|
9945
10973
|
const batch = await world1.delta_batch(land);
|
|
9946
|
-
batch[152] = ~batch[152];
|
|
10974
|
+
batch[152] = ~batch[152]; // break sign
|
|
9947
10975
|
$mol_assert_like([...(await world2.apply(batch)).forbid.values()], ['Wrong join sign', 'Level too low']);
|
|
10976
|
+
// no applied units
|
|
9948
10977
|
$mol_assert_like(world2.land(land.id()).delta().length, 0);
|
|
9949
10978
|
},
|
|
9950
10979
|
async 'ignore update auth except auth removing'() {
|
|
@@ -9955,6 +10984,7 @@ var $;
|
|
|
9955
10984
|
const land2 = world2.land(land1.id());
|
|
9956
10985
|
land2.clock_auth.tick(peer.id);
|
|
9957
10986
|
land2.clock_data.tick(peer.id);
|
|
10987
|
+
// do changes
|
|
9958
10988
|
land1.chief.as($hyoo_crowd_reg).numb(123);
|
|
9959
10989
|
land2.chief.as($hyoo_crowd_reg).numb(234);
|
|
9960
10990
|
const batch = await world1.delta_batch(land1);
|
|
@@ -9970,15 +11000,16 @@ var $;
|
|
|
9970
11000
|
const world1 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
|
|
9971
11001
|
const world2 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
|
|
9972
11002
|
const peer = await $hyoo_crowd_peer.generate();
|
|
9973
|
-
const land1 = await world1.grab();
|
|
11003
|
+
const land1 = await world1.grab(); // +3 units
|
|
9974
11004
|
const land2 = world2.land(land1.id());
|
|
9975
|
-
|
|
11005
|
+
// do changes
|
|
11006
|
+
land1.chief.sub('foo', $hyoo_crowd_reg).numb(123); // +1 unit
|
|
9976
11007
|
for await (const batch of world1.delta()) {
|
|
9977
11008
|
$mol_assert_like([...(await world2.apply(batch)).forbid.values()], []);
|
|
9978
11009
|
}
|
|
9979
|
-
land2.chief.sub('foo', $hyoo_crowd_reg).numb(234);
|
|
9980
|
-
land2.chief.sub('bar', $hyoo_crowd_reg).numb(234);
|
|
9981
|
-
land2.level(peer.id, $hyoo_crowd_peer_level.law);
|
|
11010
|
+
land2.chief.sub('foo', $hyoo_crowd_reg).numb(234); // 1 unit update +1 unit
|
|
11011
|
+
land2.chief.sub('bar', $hyoo_crowd_reg).numb(234); // +1 unit
|
|
11012
|
+
land2.level(peer.id, $hyoo_crowd_peer_level.law); // ingnored
|
|
9982
11013
|
$mol_assert_like(land1.delta().length, 4);
|
|
9983
11014
|
level_get: {
|
|
9984
11015
|
const batch = await world2.delta_batch(land2);
|
|
@@ -9989,7 +11020,7 @@ var $;
|
|
|
9989
11020
|
$mol_assert_like(land1.level(peer.id), $hyoo_crowd_peer_level.get);
|
|
9990
11021
|
}
|
|
9991
11022
|
level_add: {
|
|
9992
|
-
land1.level(land2.peer().id, $hyoo_crowd_peer_level.add);
|
|
11023
|
+
land1.level(land2.peer().id, $hyoo_crowd_peer_level.add); // +1 unit
|
|
9993
11024
|
const batch = await world2.delta_batch(land2);
|
|
9994
11025
|
$mol_assert_like([...(await world1.apply(batch)).forbid.values()], ['Level too low']);
|
|
9995
11026
|
$mol_assert_like(land1.delta().length, 7);
|
|
@@ -10011,7 +11042,7 @@ var $;
|
|
|
10011
11042
|
for await (const batch of world1.delta()) {
|
|
10012
11043
|
$mol_assert_like([...(await world2.apply(batch)).forbid.values()], []);
|
|
10013
11044
|
}
|
|
10014
|
-
land2.level(peer.id, $hyoo_crowd_peer_level.law);
|
|
11045
|
+
land2.level(peer.id, $hyoo_crowd_peer_level.law); // +1 unit
|
|
10015
11046
|
const batch = await world2.delta_batch(land2);
|
|
10016
11047
|
$mol_assert_like([...(await world1.apply(batch)).forbid.values()], []);
|
|
10017
11048
|
$mol_assert_like(land1.delta().length, 8);
|
|
@@ -10026,6 +11057,7 @@ var $;
|
|
|
10026
11057
|
const peer = await $hyoo_crowd_peer.generate();
|
|
10027
11058
|
const land1 = await world1.grab();
|
|
10028
11059
|
const land2 = world2.land(land1.id());
|
|
11060
|
+
// do changes
|
|
10029
11061
|
land1.chief.sub('foo', $hyoo_crowd_reg).numb(123);
|
|
10030
11062
|
const batch = await world1.delta_batch(land1);
|
|
10031
11063
|
$mol_assert_like([...(await world2.apply(batch)).forbid.values()], []);
|
|
@@ -10056,7 +11088,7 @@ var $;
|
|
|
10056
11088
|
for await (const batch of world1.delta()) {
|
|
10057
11089
|
$mol_assert_like([...(await world2.apply(batch)).forbid.values()], []);
|
|
10058
11090
|
}
|
|
10059
|
-
land2.level(peer.id, $hyoo_crowd_peer_level.law);
|
|
11091
|
+
land2.level(peer.id, $hyoo_crowd_peer_level.law); //ingnored
|
|
10060
11092
|
const batch = await world2.delta_batch(land2);
|
|
10061
11093
|
$mol_assert_like([...(await world1.apply(batch)).forbid.values()], []);
|
|
10062
11094
|
$mol_assert_like(land1.delta().length, 7);
|
|
@@ -10130,41 +11162,105 @@ var $;
|
|
|
10130
11162
|
});
|
|
10131
11163
|
})($ || ($ = {}));
|
|
10132
11164
|
|
|
11165
|
+
;
|
|
11166
|
+
"use strict";
|
|
11167
|
+
var $;
|
|
11168
|
+
(function ($) {
|
|
11169
|
+
$mol_test({
|
|
11170
|
+
'all cases of using maybe'() {
|
|
11171
|
+
$mol_assert_equal($mol_maybe(0)[0], 0);
|
|
11172
|
+
$mol_assert_equal($mol_maybe(false)[0], false);
|
|
11173
|
+
$mol_assert_equal($mol_maybe(null)[0], void 0);
|
|
11174
|
+
$mol_assert_equal($mol_maybe(void 0)[0], void 0);
|
|
11175
|
+
$mol_assert_equal($mol_maybe(void 0).map(v => v.toString())[0], void 0);
|
|
11176
|
+
$mol_assert_equal($mol_maybe(0).map(v => v.toString())[0], '0');
|
|
11177
|
+
},
|
|
11178
|
+
});
|
|
11179
|
+
})($ || ($ = {}));
|
|
11180
|
+
|
|
10133
11181
|
;
|
|
10134
11182
|
"use strict";
|
|
10135
11183
|
var $;
|
|
10136
11184
|
(function ($_1) {
|
|
11185
|
+
function check(tree, ideal) {
|
|
11186
|
+
$mol_assert_equal(tree.toString(), $$.$mol_tree2_from_string(ideal).toString());
|
|
11187
|
+
}
|
|
10137
11188
|
$mol_test({
|
|
10138
11189
|
'inserting'($) {
|
|
10139
|
-
|
|
10140
|
-
|
|
10141
|
-
|
|
10142
|
-
|
|
10143
|
-
|
|
10144
|
-
|
|
10145
|
-
|
|
10146
|
-
|
|
10147
|
-
|
|
10148
|
-
|
|
10149
|
-
|
|
10150
|
-
|
|
10151
|
-
|
|
10152
|
-
.insert($mol_tree2.struct('x'),
|
|
10153
|
-
|
|
10154
|
-
|
|
10155
|
-
|
|
10156
|
-
|
|
11190
|
+
check($.$mol_tree2_from_string(`
|
|
11191
|
+
a b c d
|
|
11192
|
+
`).insert($mol_tree2.struct('x'), 'a', 'b', 'c'), `
|
|
11193
|
+
a b x
|
|
11194
|
+
`);
|
|
11195
|
+
check($.$mol_tree2_from_string(`
|
|
11196
|
+
a b
|
|
11197
|
+
`).insert($mol_tree2.struct('x'), 'a', 'b', 'c', 'd'), `
|
|
11198
|
+
a b c x
|
|
11199
|
+
`);
|
|
11200
|
+
check($.$mol_tree2_from_string(`
|
|
11201
|
+
a b c d
|
|
11202
|
+
`)
|
|
11203
|
+
.insert($mol_tree2.struct('x'), 0, 0, 0), `
|
|
11204
|
+
a b x
|
|
11205
|
+
`);
|
|
11206
|
+
check($.$mol_tree2_from_string(`
|
|
11207
|
+
a b
|
|
11208
|
+
`)
|
|
11209
|
+
.insert($mol_tree2.struct('x'), 0, 0, 0, 0), `
|
|
11210
|
+
a b \\
|
|
11211
|
+
x
|
|
11212
|
+
`);
|
|
11213
|
+
check($.$mol_tree2_from_string(`
|
|
11214
|
+
a b c d
|
|
11215
|
+
`)
|
|
11216
|
+
.insert($mol_tree2.struct('x'), null, null, null), `
|
|
11217
|
+
a b x
|
|
11218
|
+
`);
|
|
11219
|
+
check($.$mol_tree2_from_string(`
|
|
11220
|
+
a b
|
|
11221
|
+
`)
|
|
11222
|
+
.insert($mol_tree2.struct('x'), null, null, null, null), `
|
|
11223
|
+
a b \\
|
|
11224
|
+
x
|
|
11225
|
+
`);
|
|
11226
|
+
},
|
|
11227
|
+
'updating'($) {
|
|
11228
|
+
check($.$mol_tree2_from_string(`
|
|
11229
|
+
a b c d
|
|
11230
|
+
`).update([], 'a', 'b', 'c')[0], `
|
|
11231
|
+
a b
|
|
11232
|
+
`);
|
|
11233
|
+
check($.$mol_tree2_from_string(`
|
|
11234
|
+
a b c d
|
|
11235
|
+
`).update([$mol_tree2.struct('x')])[0], `
|
|
11236
|
+
x
|
|
11237
|
+
`);
|
|
11238
|
+
check($.$mol_tree2_from_string(`
|
|
11239
|
+
a b c d
|
|
11240
|
+
`).update([$mol_tree2.struct('x'), $mol_tree2.struct('y')], 'a', 'b', 'c')[0], `
|
|
11241
|
+
a b
|
|
11242
|
+
x
|
|
11243
|
+
y
|
|
11244
|
+
`);
|
|
10157
11245
|
},
|
|
10158
11246
|
'deleting'($) {
|
|
10159
|
-
|
|
10160
|
-
|
|
10161
|
-
|
|
10162
|
-
|
|
10163
|
-
|
|
10164
|
-
|
|
11247
|
+
const base = $.$mol_tree2_from_string(`
|
|
11248
|
+
a b c d
|
|
11249
|
+
`);
|
|
11250
|
+
check(base.insert(null, 'a', 'b', 'c'), `
|
|
11251
|
+
a b
|
|
11252
|
+
`);
|
|
11253
|
+
check(base.update(base.select('a', 'b', 'c', null).kids, 'a', 'b', 'c')[0], `
|
|
11254
|
+
a b d
|
|
11255
|
+
`);
|
|
11256
|
+
check(base.insert(null, 0, 0, 0), `
|
|
11257
|
+
a b
|
|
11258
|
+
`);
|
|
10165
11259
|
},
|
|
10166
11260
|
'hack'($) {
|
|
10167
|
-
const res = $.$mol_tree2_from_string(`
|
|
11261
|
+
const res = $.$mol_tree2_from_string(`
|
|
11262
|
+
foo bar xxx
|
|
11263
|
+
`)
|
|
10168
11264
|
.hack({
|
|
10169
11265
|
'bar': (input, belt) => [input.struct('777', input.hack(belt))],
|
|
10170
11266
|
});
|
|
@@ -10173,6 +11269,29 @@ var $;
|
|
|
10173
11269
|
});
|
|
10174
11270
|
})($ || ($ = {}));
|
|
10175
11271
|
|
|
11272
|
+
;
|
|
11273
|
+
"use strict";
|
|
11274
|
+
var $;
|
|
11275
|
+
(function ($) {
|
|
11276
|
+
$mol_test({
|
|
11277
|
+
'empty array'() {
|
|
11278
|
+
$mol_assert_equal($mol_array_chunks([], () => true), []);
|
|
11279
|
+
},
|
|
11280
|
+
'one chunk'() {
|
|
11281
|
+
$mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], () => false), [[1, 2, 3, 4, 5]]);
|
|
11282
|
+
},
|
|
11283
|
+
'fixed size chunk'() {
|
|
11284
|
+
$mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], 3), [[1, 2, 3], [4, 5]]);
|
|
11285
|
+
},
|
|
11286
|
+
'first empty chunk'() {
|
|
11287
|
+
$mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], (_, i) => i === 0), [[1, 2, 3, 4, 5]]);
|
|
11288
|
+
},
|
|
11289
|
+
'chunk for every item'() {
|
|
11290
|
+
$mol_assert_equal($mol_array_chunks([1, 2, 3, 4, 5], () => true), [[1], [2], [3], [4], [5]]);
|
|
11291
|
+
},
|
|
11292
|
+
});
|
|
11293
|
+
})($ || ($ = {}));
|
|
11294
|
+
|
|
10176
11295
|
;
|
|
10177
11296
|
"use strict";
|
|
10178
11297
|
var $;
|
|
@@ -10252,7 +11371,7 @@ var $;
|
|
|
10252
11371
|
$mol_assert_equal($mol_tree2_from_json([]).toString(), '/\n');
|
|
10253
11372
|
$mol_assert_equal($mol_tree2_from_json([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
|
|
10254
11373
|
$mol_assert_equal($mol_tree2_from_json([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
|
|
10255
|
-
$mol_assert_equal($mol_tree2_from_json(new Uint16Array([1, 10, 256])).toString(), '
|
|
11374
|
+
$mol_assert_equal($mol_tree2_from_json(new Uint16Array([1, 10, 255, 256, 65535])).toString(), '\\01 00 0A 00 FF 00 00 01\n\\FF FF\n');
|
|
10256
11375
|
$mol_assert_equal($mol_tree2_from_json(['', 'foo', 'bar\nbaz']).toString(), '/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n');
|
|
10257
11376
|
$mol_assert_equal($mol_tree2_from_json({ 'foo': false, 'bar\nbaz': 'lol' }).toString(), '*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n');
|
|
10258
11377
|
},
|
|
@@ -10313,15 +11432,6 @@ var $;
|
|
|
10313
11432
|
});
|
|
10314
11433
|
})($ || ($ = {}));
|
|
10315
11434
|
|
|
10316
|
-
;
|
|
10317
|
-
"use strict";
|
|
10318
|
-
var $;
|
|
10319
|
-
(function ($_1) {
|
|
10320
|
-
$mol_test_mocks.push($ => {
|
|
10321
|
-
$.$mol_after_frame = $mol_after_mock_commmon;
|
|
10322
|
-
});
|
|
10323
|
-
})($ || ($ = {}));
|
|
10324
|
-
|
|
10325
11435
|
;
|
|
10326
11436
|
"use strict";
|
|
10327
11437
|
|
|
@@ -10329,6 +11439,7 @@ var $;
|
|
|
10329
11439
|
"use strict";
|
|
10330
11440
|
var $;
|
|
10331
11441
|
(function ($) {
|
|
11442
|
+
/** Watch and logs reactive states. Logger automatically added to test bundle which is adding to `test.html`. */
|
|
10332
11443
|
class $mol_wire_log extends $mol_object2 {
|
|
10333
11444
|
static watch(task) {
|
|
10334
11445
|
return task;
|