hyoo_sync_client 0.0.1

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/web.test.js ADDED
@@ -0,0 +1,4087 @@
1
+ "use strict";
2
+ function require( path ){ return $node[ path ] };
3
+ "use strict";
4
+ var $;
5
+ (function ($_1) {
6
+ function $mol_test(set) {
7
+ for (let name in set) {
8
+ const code = set[name];
9
+ const test = (typeof code === 'string') ? new Function('', code) : code;
10
+ $_1.$mol_test_all.push(test);
11
+ }
12
+ $mol_test_schedule();
13
+ }
14
+ $_1.$mol_test = $mol_test;
15
+ $_1.$mol_test_mocks = [];
16
+ $_1.$mol_test_all = [];
17
+ async function $mol_test_run() {
18
+ for (var test of $_1.$mol_test_all) {
19
+ let context = Object.create($$);
20
+ for (let mock of $_1.$mol_test_mocks)
21
+ await mock(context);
22
+ const res = test(context);
23
+ if ($mol_promise_like(res)) {
24
+ await new Promise((done, fail) => {
25
+ res.then(done, fail);
26
+ setTimeout(() => fail(new Error('Test timeout: ' + test.name)), 1000);
27
+ });
28
+ }
29
+ }
30
+ $$.$mol_log3_done({
31
+ place: '$mol_test',
32
+ message: 'All tests passed',
33
+ count: $_1.$mol_test_all.length,
34
+ });
35
+ }
36
+ $_1.$mol_test_run = $mol_test_run;
37
+ let scheduled = false;
38
+ function $mol_test_schedule() {
39
+ if (scheduled)
40
+ return;
41
+ scheduled = true;
42
+ setTimeout(async () => {
43
+ scheduled = false;
44
+ await $mol_test_run();
45
+ $$.$mol_test_complete();
46
+ }, 1000);
47
+ }
48
+ $_1.$mol_test_schedule = $mol_test_schedule;
49
+ $_1.$mol_test_mocks.push(context => {
50
+ let seed = 0;
51
+ context.Math = Object.create(Math);
52
+ context.Math.random = () => Math.sin(seed++);
53
+ const forbidden = ['XMLHttpRequest', 'fetch'];
54
+ for (let api of forbidden) {
55
+ context[api] = new Proxy(function () { }, {
56
+ get() {
57
+ $mol_fail_hidden(new Error(`${api} is forbidden in tests`));
58
+ },
59
+ apply() {
60
+ $mol_fail_hidden(new Error(`${api} is forbidden in tests`));
61
+ },
62
+ });
63
+ }
64
+ });
65
+ $mol_test({
66
+ 'mocked Math.random'($) {
67
+ console.assert($.Math.random() === 0);
68
+ console.assert($.Math.random() === Math.sin(1));
69
+ },
70
+ 'forbidden XMLHttpRequest'($) {
71
+ try {
72
+ console.assert(void new $.XMLHttpRequest);
73
+ }
74
+ catch (error) {
75
+ console.assert(error.message === 'XMLHttpRequest is forbidden in tests');
76
+ }
77
+ },
78
+ 'forbidden fetch'($) {
79
+ try {
80
+ console.assert(void $.fetch(''));
81
+ }
82
+ catch (error) {
83
+ console.assert(error.message === 'fetch is forbidden in tests');
84
+ }
85
+ },
86
+ });
87
+ })($ || ($ = {}));
88
+ //mol/test/test.test.ts
89
+ ;
90
+ "use strict";
91
+ var $;
92
+ (function ($) {
93
+ function $mol_test_complete() {
94
+ }
95
+ $.$mol_test_complete = $mol_test_complete;
96
+ })($ || ($ = {}));
97
+ //mol/test/test.web.test.ts
98
+ ;
99
+ "use strict";
100
+ //mol/type/error/error.ts
101
+ ;
102
+ "use strict";
103
+ //mol/type/assert/assert.ts
104
+ ;
105
+ "use strict";
106
+ //mol/type/assert/assert.test.ts
107
+ ;
108
+ "use strict";
109
+ //mol/type/partial/deep/deep.test.ts
110
+ ;
111
+ "use strict";
112
+ var $;
113
+ (function ($) {
114
+ $mol_test({
115
+ 'Make empty div'() {
116
+ $mol_assert_equal(($mol_jsx("div", null)).outerHTML, '<div></div>');
117
+ },
118
+ 'Define native field'() {
119
+ const dom = $mol_jsx("input", { value: '123' });
120
+ $mol_assert_equal(dom.outerHTML, '<input value="123">');
121
+ $mol_assert_equal(dom.value, '123');
122
+ },
123
+ 'Define classes'() {
124
+ const dom = $mol_jsx("div", { class: 'foo bar' });
125
+ $mol_assert_equal(dom.outerHTML, '<div class="foo bar"></div>');
126
+ },
127
+ 'Define styles'() {
128
+ const dom = $mol_jsx("div", { style: { color: 'red' } });
129
+ $mol_assert_equal(dom.outerHTML, '<div style="color: red;"></div>');
130
+ },
131
+ 'Define dataset'() {
132
+ const dom = $mol_jsx("div", { dataset: { foo: 'bar' } });
133
+ $mol_assert_equal(dom.outerHTML, '<div data-foo="bar"></div>');
134
+ },
135
+ 'Define attributes'() {
136
+ const dom = $mol_jsx("div", { lang: "ru", hidden: true });
137
+ $mol_assert_equal(dom.outerHTML, '<div lang="ru" hidden=""></div>');
138
+ },
139
+ 'Define child nodes'() {
140
+ const dom = $mol_jsx("div", null,
141
+ "hello",
142
+ $mol_jsx("strong", null, "world"),
143
+ "!");
144
+ $mol_assert_equal(dom.outerHTML, '<div>hello<strong>world</strong>!</div>');
145
+ },
146
+ 'Function as component'() {
147
+ const Button = (props, target) => {
148
+ return $mol_jsx("button", { title: props.hint }, target());
149
+ };
150
+ const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
151
+ $mol_assert_equal(dom.outerHTML, '<button id="foo" title="click me" class="Button">hey!</button>');
152
+ },
153
+ 'Nested guid generation'() {
154
+ const Foo = () => {
155
+ return $mol_jsx("div", null,
156
+ $mol_jsx(Bar, { id: "bar" },
157
+ $mol_jsx("img", { id: "icon" })));
158
+ };
159
+ const Bar = (props, icon) => {
160
+ return $mol_jsx("span", null,
161
+ icon,
162
+ $mol_jsx("i", { id: "label" }));
163
+ };
164
+ const dom = $mol_jsx(Foo, { id: "foo" });
165
+ $mol_assert_equal(dom.outerHTML, '<div id="foo" class="Foo"><span id="foo/bar" class="Foo_bar Bar"><img id="foo/icon" class="Foo_icon"><i id="foo/bar/label" class="Foo_bar_label Bar_label"></i></span></div>');
166
+ },
167
+ 'Fail on non unique ids'() {
168
+ const App = () => {
169
+ return $mol_jsx("div", null,
170
+ $mol_jsx("span", { id: "bar" }),
171
+ $mol_jsx("span", { id: "bar" }));
172
+ };
173
+ $mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
174
+ },
175
+ 'Owner based guid generationn'() {
176
+ const Foo = () => {
177
+ return $mol_jsx("div", null,
178
+ $mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
179
+ };
180
+ const Bar = (props) => {
181
+ return $mol_jsx("span", null, props.icon());
182
+ };
183
+ const dom = $mol_jsx(Foo, { id: "app" });
184
+ $mol_assert_equal(dom.outerHTML, '<div id="app" class="Foo"><span id="app/middle" class="Foo_middle Bar"><img id="app/icon" class="Foo_icon"></span></div>');
185
+ },
186
+ 'Fail on same ids from different caller'() {
187
+ const Foo = () => {
188
+ return $mol_jsx("div", null,
189
+ $mol_jsx("img", { id: "icon" }),
190
+ $mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
191
+ };
192
+ const Bar = (props) => {
193
+ return $mol_jsx("span", null, props.icon());
194
+ };
195
+ $mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
196
+ },
197
+ });
198
+ })($ || ($ = {}));
199
+ //mol/jsx/jsx.test.tsx
200
+ ;
201
+ "use strict";
202
+ var $;
203
+ (function ($) {
204
+ $mol_test({
205
+ 'nulls & undefineds'() {
206
+ $mol_assert_ok($mol_compare_deep(null, null));
207
+ $mol_assert_ok($mol_compare_deep(undefined, undefined));
208
+ $mol_assert_not($mol_compare_deep(undefined, null));
209
+ $mol_assert_not($mol_compare_deep({}, null));
210
+ },
211
+ 'number'() {
212
+ $mol_assert_ok($mol_compare_deep(1, 1));
213
+ $mol_assert_ok($mol_compare_deep(Number.NaN, Number.NaN));
214
+ $mol_assert_not($mol_compare_deep(1, 2));
215
+ $mol_assert_ok($mol_compare_deep(Object(1), Object(1)));
216
+ $mol_assert_not($mol_compare_deep(Object(1), Object(2)));
217
+ },
218
+ 'POJO'() {
219
+ $mol_assert_ok($mol_compare_deep({}, {}));
220
+ $mol_assert_not($mol_compare_deep({ a: 1 }, { b: 2 }));
221
+ $mol_assert_not($mol_compare_deep({ a: 1 }, { a: 2 }));
222
+ $mol_assert_not($mol_compare_deep({}, { a: undefined }));
223
+ $mol_assert_not($mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
224
+ $mol_assert_ok($mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
225
+ $mol_assert_ok($mol_compare_deep(Object.create(null), Object.create(null)));
226
+ },
227
+ 'Array'() {
228
+ $mol_assert_ok($mol_compare_deep([], []));
229
+ $mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
230
+ $mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
231
+ $mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
232
+ },
233
+ 'Non POJO are different'() {
234
+ class Thing extends Object {
235
+ }
236
+ $mol_assert_not($mol_compare_deep(new Thing, new Thing));
237
+ $mol_assert_not($mol_compare_deep(() => 1, () => 1));
238
+ $mol_assert_not($mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
239
+ },
240
+ 'POJO with symbols'() {
241
+ const sym = Symbol();
242
+ $mol_assert_ok($mol_compare_deep({ [sym]: true }, { [sym]: true }));
243
+ $mol_assert_not($mol_compare_deep({ [Symbol()]: true }, { [Symbol()]: true }));
244
+ },
245
+ 'same POJOs with cyclic reference'() {
246
+ const a = { foo: {} };
247
+ a['self'] = a;
248
+ const b = { foo: {} };
249
+ b['self'] = b;
250
+ $mol_assert_ok($mol_compare_deep(a, b));
251
+ },
252
+ 'Date'() {
253
+ $mol_assert_ok($mol_compare_deep(new Date(12345), new Date(12345)));
254
+ $mol_assert_not($mol_compare_deep(new Date(12345), new Date(12346)));
255
+ },
256
+ 'RegExp'() {
257
+ $mol_assert_ok($mol_compare_deep(/\x22/mig, /\x22/mig));
258
+ $mol_assert_not($mol_compare_deep(/\x22/mig, /\x21/mig));
259
+ $mol_assert_not($mol_compare_deep(/\x22/mig, /\x22/mg));
260
+ },
261
+ 'Error'() {
262
+ $mol_assert_not($mol_compare_deep(new Error('xxx'), new Error('xxx')));
263
+ const fail = (message) => new Error(message);
264
+ $mol_assert_ok($mol_compare_deep(...['xxx', 'xxx'].map(msg => new Error(msg))));
265
+ $mol_assert_not($mol_compare_deep(...['xxx', 'yyy'].map(msg => new Error(msg))));
266
+ },
267
+ 'Map'() {
268
+ $mol_assert_ok($mol_compare_deep(new Map, new Map));
269
+ $mol_assert_ok($mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
270
+ $mol_assert_ok($mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
271
+ $mol_assert_not($mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
272
+ $mol_assert_not($mol_compare_deep(new Map([[[1], 2]]), new Map([[[3], 2]])));
273
+ },
274
+ 'Set'() {
275
+ $mol_assert_ok($mol_compare_deep(new Set, new Set));
276
+ $mol_assert_ok($mol_compare_deep(new Set([1, [2]]), new Set([1, [2]])));
277
+ $mol_assert_not($mol_compare_deep(new Set([1]), new Set([2])));
278
+ },
279
+ 'Uint8Array'() {
280
+ $mol_assert_ok($mol_compare_deep(new Uint8Array, new Uint8Array));
281
+ $mol_assert_ok($mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
282
+ $mol_assert_not($mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
283
+ },
284
+ 'Custom comparator'() {
285
+ class User {
286
+ name;
287
+ rand;
288
+ constructor(name, rand = Math.random()) {
289
+ this.name = name;
290
+ this.rand = rand;
291
+ }
292
+ [Symbol.toPrimitive](mode) {
293
+ return this.name;
294
+ }
295
+ }
296
+ $mol_assert_ok($mol_compare_deep(new User('Jin'), new User('Jin')));
297
+ $mol_assert_not($mol_compare_deep(new User('Jin'), new User('John')));
298
+ },
299
+ });
300
+ })($ || ($ = {}));
301
+ //mol/compare/deep/deep.test.tsx
302
+ ;
303
+ "use strict";
304
+ var $;
305
+ (function ($) {
306
+ function $mol_dom_serialize(node) {
307
+ const serializer = new $mol_dom_context.XMLSerializer;
308
+ return serializer.serializeToString(node);
309
+ }
310
+ $.$mol_dom_serialize = $mol_dom_serialize;
311
+ })($ || ($ = {}));
312
+ //mol/dom/serialize/serialize.ts
313
+ ;
314
+ "use strict";
315
+ var $;
316
+ (function ($) {
317
+ function $mol_assert_ok(value) {
318
+ if (value)
319
+ return;
320
+ $mol_fail(new Error(`${value} ≠ true`));
321
+ }
322
+ $.$mol_assert_ok = $mol_assert_ok;
323
+ function $mol_assert_not(value) {
324
+ if (!value)
325
+ return;
326
+ $mol_fail(new Error(`${value} ≠ false`));
327
+ }
328
+ $.$mol_assert_not = $mol_assert_not;
329
+ function $mol_assert_fail(handler, ErrorRight) {
330
+ const fail = $.$mol_fail;
331
+ try {
332
+ $.$mol_fail = $.$mol_fail_hidden;
333
+ handler();
334
+ }
335
+ catch (error) {
336
+ if (!ErrorRight)
337
+ return error;
338
+ $.$mol_fail = fail;
339
+ if (typeof ErrorRight === 'string') {
340
+ $mol_assert_equal(error.message, ErrorRight);
341
+ }
342
+ else {
343
+ $mol_assert_ok(error instanceof ErrorRight);
344
+ }
345
+ return error;
346
+ }
347
+ finally {
348
+ $.$mol_fail = fail;
349
+ }
350
+ $mol_fail(new Error('Not failed'));
351
+ }
352
+ $.$mol_assert_fail = $mol_assert_fail;
353
+ function $mol_assert_equal(...args) {
354
+ for (let i = 0; i < args.length; ++i) {
355
+ for (let j = 0; j < args.length; ++j) {
356
+ if (i === j)
357
+ continue;
358
+ if (Number.isNaN(args[i]) && Number.isNaN(args[j]))
359
+ continue;
360
+ if (args[i] !== args[j])
361
+ $mol_fail(new Error(`Not equal (${i + 1}:${j + 1})\n${args[i]}\n${args[j]}`));
362
+ }
363
+ }
364
+ }
365
+ $.$mol_assert_equal = $mol_assert_equal;
366
+ function $mol_assert_unique(...args) {
367
+ for (let i = 0; i < args.length; ++i) {
368
+ for (let j = 0; j < args.length; ++j) {
369
+ if (i === j)
370
+ continue;
371
+ if (args[i] === args[j] || (Number.isNaN(args[i]) && Number.isNaN(args[j]))) {
372
+ $mol_fail(new Error(`args[${i}] = args[${j}] = ${args[i]}`));
373
+ }
374
+ }
375
+ }
376
+ }
377
+ $.$mol_assert_unique = $mol_assert_unique;
378
+ function $mol_assert_like(head, ...tail) {
379
+ for (let [index, value] of Object.entries(tail)) {
380
+ if (!$mol_compare_deep(value, head)) {
381
+ const print = (val) => {
382
+ if (!val)
383
+ return val;
384
+ if (typeof val !== 'object')
385
+ return val;
386
+ if ('outerHTML' in val)
387
+ return val.outerHTML;
388
+ try {
389
+ return JSON.stringify(val);
390
+ }
391
+ catch (error) {
392
+ console.error(error);
393
+ return val;
394
+ }
395
+ };
396
+ return $mol_fail(new Error(`Not like (1:${+index + 2})\n${print(head)}\n---\n${print(value)}`));
397
+ }
398
+ }
399
+ }
400
+ $.$mol_assert_like = $mol_assert_like;
401
+ function $mol_assert_dom(left, right) {
402
+ $mol_assert_equal($mol_dom_serialize(left), $mol_dom_serialize(right));
403
+ }
404
+ $.$mol_assert_dom = $mol_assert_dom;
405
+ })($ || ($ = {}));
406
+ //mol/assert/assert.ts
407
+ ;
408
+ "use strict";
409
+ var $;
410
+ (function ($) {
411
+ $mol_test({
412
+ 'must be false'() {
413
+ $mol_assert_not(0);
414
+ },
415
+ 'must be true'() {
416
+ $mol_assert_ok(1);
417
+ },
418
+ 'two must be equal'() {
419
+ $mol_assert_equal(2, 2);
420
+ },
421
+ 'three must be equal'() {
422
+ $mol_assert_equal(2, 2, 2);
423
+ },
424
+ 'two must be unique'() {
425
+ $mol_assert_unique([3], [3]);
426
+ },
427
+ 'three must be unique'() {
428
+ $mol_assert_unique([3], [3], [3]);
429
+ },
430
+ 'two must be alike'() {
431
+ $mol_assert_like([3], [3]);
432
+ },
433
+ 'three must be alike'() {
434
+ $mol_assert_like([3], [3], [3]);
435
+ },
436
+ });
437
+ })($ || ($ = {}));
438
+ //mol/assert/assert.test.ts
439
+ ;
440
+ "use strict";
441
+ //mol/type/equals/equals.ts
442
+ ;
443
+ "use strict";
444
+ //mol/type/equals/equals.test.ts
445
+ ;
446
+ "use strict";
447
+ //mol/type/keys/extract/extract.test.ts
448
+ ;
449
+ "use strict";
450
+ var $;
451
+ (function ($_1) {
452
+ $mol_test_mocks.push($ => {
453
+ $.$mol_log3_come = () => { };
454
+ $.$mol_log3_done = () => { };
455
+ $.$mol_log3_fail = () => { };
456
+ $.$mol_log3_warn = () => { };
457
+ $.$mol_log3_rise = () => { };
458
+ $.$mol_log3_area = () => () => { };
459
+ });
460
+ })($ || ($ = {}));
461
+ //mol/log3/log3.test.ts
462
+ ;
463
+ "use strict";
464
+ var $;
465
+ (function ($_1) {
466
+ $mol_test({
467
+ 'FQN of anon function'($) {
468
+ const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
469
+ $mol_assert_equal($$.$mol_func_name_test.name, '');
470
+ $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
471
+ $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
472
+ },
473
+ });
474
+ })($ || ($ = {}));
475
+ //mol/func/name/name.test.ts
476
+ ;
477
+ "use strict";
478
+ var $;
479
+ (function ($) {
480
+ $mol_test({
481
+ 'get'() {
482
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
483
+ $mol_assert_equal(proxy.foo, 777);
484
+ },
485
+ 'has'() {
486
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
487
+ $mol_assert_equal('foo' in proxy, true);
488
+ },
489
+ 'set'() {
490
+ const target = { foo: 777 };
491
+ const proxy = $mol_delegate({}, () => target);
492
+ proxy.foo = 123;
493
+ $mol_assert_equal(target.foo, 123);
494
+ },
495
+ 'getOwnPropertyDescriptor'() {
496
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
497
+ $mol_assert_like(Object.getOwnPropertyDescriptor(proxy, 'foo'), {
498
+ value: 777,
499
+ writable: true,
500
+ enumerable: true,
501
+ configurable: true,
502
+ });
503
+ },
504
+ 'ownKeys'() {
505
+ const proxy = $mol_delegate({}, () => ({ foo: 777, [Symbol.toStringTag]: 'bar' }));
506
+ $mol_assert_like(Reflect.ownKeys(proxy), ['foo', Symbol.toStringTag]);
507
+ },
508
+ 'getPrototypeOf'() {
509
+ class Foo {
510
+ }
511
+ const proxy = $mol_delegate({}, () => new Foo);
512
+ $mol_assert_equal(Object.getPrototypeOf(proxy), Foo.prototype);
513
+ },
514
+ 'setPrototypeOf'() {
515
+ class Foo {
516
+ }
517
+ const target = {};
518
+ const proxy = $mol_delegate({}, () => target);
519
+ Object.setPrototypeOf(proxy, Foo.prototype);
520
+ $mol_assert_equal(Object.getPrototypeOf(target), Foo.prototype);
521
+ },
522
+ 'instanceof'() {
523
+ class Foo {
524
+ }
525
+ const proxy = $mol_delegate({}, () => new Foo);
526
+ $mol_assert_ok(proxy instanceof Foo);
527
+ $mol_assert_ok(proxy instanceof $mol_delegate);
528
+ },
529
+ 'autobind'() {
530
+ class Foo {
531
+ }
532
+ const proxy = $mol_delegate({}, () => new Foo);
533
+ $mol_assert_ok(proxy instanceof Foo);
534
+ $mol_assert_ok(proxy instanceof $mol_delegate);
535
+ },
536
+ });
537
+ })($ || ($ = {}));
538
+ //mol/delegate/delegate.test.ts
539
+ ;
540
+ "use strict";
541
+ //mol/type/writable/writable.test.ts
542
+ ;
543
+ "use strict";
544
+ var $;
545
+ (function ($_1) {
546
+ $mol_test({
547
+ 'Collect deps'() {
548
+ const pub1 = new $mol_wire_pub;
549
+ const pub2 = new $mol_wire_pub;
550
+ const sub = new $mol_wire_pub_sub;
551
+ const bu1 = sub.track_on();
552
+ try {
553
+ pub1.promote();
554
+ pub2.promote();
555
+ pub2.promote();
556
+ }
557
+ finally {
558
+ sub.track_cut();
559
+ sub.track_off(bu1);
560
+ }
561
+ pub1.emit();
562
+ pub2.emit();
563
+ $mol_assert_like(sub.pub_list, [pub1, pub2, pub2]);
564
+ const bu2 = sub.track_on();
565
+ try {
566
+ pub1.promote();
567
+ pub1.promote();
568
+ pub2.promote();
569
+ }
570
+ finally {
571
+ sub.track_cut();
572
+ sub.track_off(bu2);
573
+ }
574
+ pub1.emit();
575
+ pub2.emit();
576
+ $mol_assert_like(sub.pub_list, [pub1, pub1, pub2]);
577
+ },
578
+ 'cyclic detection'($) {
579
+ const sub1 = new $mol_wire_pub_sub;
580
+ const sub2 = new $mol_wire_pub_sub;
581
+ const bu1 = sub1.track_on();
582
+ try {
583
+ const bu2 = sub2.track_on();
584
+ try {
585
+ $mol_assert_fail(() => sub1.promote(), 'Circular subscription');
586
+ }
587
+ finally {
588
+ sub2.track_cut();
589
+ sub2.track_off(bu2);
590
+ }
591
+ }
592
+ finally {
593
+ sub1.track_cut();
594
+ sub1.track_off(bu1);
595
+ }
596
+ },
597
+ });
598
+ })($ || ($ = {}));
599
+ //mol/wire/pub/sub/sub.test.ts
600
+ ;
601
+ "use strict";
602
+ var $;
603
+ (function ($) {
604
+ $.$mol_after_mock_queue = [];
605
+ function $mol_after_mock_warp() {
606
+ const queue = $.$mol_after_mock_queue.splice(0);
607
+ for (const task of queue)
608
+ task();
609
+ }
610
+ $.$mol_after_mock_warp = $mol_after_mock_warp;
611
+ class $mol_after_mock_commmon extends $mol_object2 {
612
+ task;
613
+ promise = Promise.resolve();
614
+ cancelled = false;
615
+ id;
616
+ constructor(task) {
617
+ super();
618
+ this.task = task;
619
+ $.$mol_after_mock_queue.push(task);
620
+ }
621
+ destructor() {
622
+ const index = $.$mol_after_mock_queue.indexOf(this.task);
623
+ if (index >= 0)
624
+ $.$mol_after_mock_queue.splice(index, 1);
625
+ }
626
+ }
627
+ $.$mol_after_mock_commmon = $mol_after_mock_commmon;
628
+ class $mol_after_mock_timeout extends $mol_after_mock_commmon {
629
+ delay;
630
+ constructor(delay, task) {
631
+ super(task);
632
+ this.delay = delay;
633
+ }
634
+ }
635
+ $.$mol_after_mock_timeout = $mol_after_mock_timeout;
636
+ })($ || ($ = {}));
637
+ //mol/after/mock/mock.test.ts
638
+ ;
639
+ "use strict";
640
+ var $;
641
+ (function ($_1) {
642
+ $mol_test_mocks.push($ => {
643
+ $.$mol_after_frame = $mol_after_mock_commmon;
644
+ });
645
+ })($ || ($ = {}));
646
+ //mol/after/frame/frame.test.ts
647
+ ;
648
+ "use strict";
649
+ var $;
650
+ (function ($) {
651
+ $mol_test({
652
+ 'Sync execution'() {
653
+ class Sync extends $mol_object2 {
654
+ static calc(a, b) {
655
+ return a + b;
656
+ }
657
+ }
658
+ __decorate([
659
+ $mol_wire_method
660
+ ], Sync, "calc", null);
661
+ $mol_assert_equal(Sync.calc(1, 2), 3);
662
+ },
663
+ async 'async <=> sync'() {
664
+ class SyncAsync extends $mol_object2 {
665
+ static async val(a) {
666
+ return a;
667
+ }
668
+ static sum(a, b) {
669
+ const syn = $mol_wire_sync(this);
670
+ return syn.val(a) + syn.val(b);
671
+ }
672
+ static async calc(a, b) {
673
+ return 5 + await $mol_wire_async(this).sum(a, b);
674
+ }
675
+ }
676
+ $mol_assert_equal(await SyncAsync.calc(1, 2), 8);
677
+ },
678
+ async 'Idempotence control'() {
679
+ class Idempotence extends $mol_object2 {
680
+ static logs_idemp = 0;
681
+ static logs_unidemp = 0;
682
+ static log_idemp() {
683
+ this.logs_idemp += 1;
684
+ }
685
+ static log_unidemp() {
686
+ this.logs_unidemp += 1;
687
+ }
688
+ static async val(a) {
689
+ return a;
690
+ }
691
+ static sum(a, b) {
692
+ this.log_idemp();
693
+ this.log_unidemp();
694
+ const syn = $mol_wire_sync(this);
695
+ return syn.val(a) + syn.val(b);
696
+ }
697
+ static async calc(a, b) {
698
+ return 5 + await $mol_wire_async(this).sum(a, b);
699
+ }
700
+ }
701
+ __decorate([
702
+ $mol_wire_method
703
+ ], Idempotence, "log_idemp", null);
704
+ $mol_assert_equal(await Idempotence.calc(1, 2), 8);
705
+ $mol_assert_equal(Idempotence.logs_idemp, 1);
706
+ $mol_assert_equal(Idempotence.logs_unidemp, 3);
707
+ },
708
+ async 'Error handling'() {
709
+ class Handle extends $mol_object2 {
710
+ static async sum(a, b) {
711
+ $mol_fail(new Error('test error ' + (a + b)));
712
+ }
713
+ static check() {
714
+ try {
715
+ return $mol_wire_sync(Handle).sum(1, 2);
716
+ }
717
+ catch (error) {
718
+ if ($mol_promise_like(error))
719
+ $mol_fail_hidden(error);
720
+ $mol_assert_equal(error.message, 'test error 3');
721
+ }
722
+ }
723
+ }
724
+ await $mol_wire_async(Handle).check();
725
+ },
726
+ });
727
+ })($ || ($ = {}));
728
+ //mol/wire/fiber/fiber.test.ts
729
+ ;
730
+ "use strict";
731
+ //mol/type/tail/tail.test.ts
732
+ ;
733
+ "use strict";
734
+ var $;
735
+ (function ($_1) {
736
+ $mol_test_mocks.push($ => {
737
+ $.$mol_after_timeout = $mol_after_mock_timeout;
738
+ });
739
+ })($ || ($ = {}));
740
+ //mol/after/timeout/timeout.test.ts
741
+ ;
742
+ "use strict";
743
+ var $;
744
+ (function ($_1) {
745
+ $mol_test({
746
+ async 'Latest method calls wins'($) {
747
+ class NameLogger extends $mol_object2 {
748
+ static $ = $;
749
+ static first = [];
750
+ static last = [];
751
+ static send(next) {
752
+ $mol_wire_sync(this.first).push(next);
753
+ this.$.$mol_wait_timeout(0);
754
+ this.last.push(next);
755
+ }
756
+ }
757
+ const name = $mol_wire_async(NameLogger).send;
758
+ name('john');
759
+ const promise = name('jin');
760
+ $.$mol_after_mock_warp();
761
+ await promise;
762
+ $mol_assert_like(NameLogger.first, ['john', 'jin']);
763
+ $mol_assert_like(NameLogger.last, ['jin']);
764
+ },
765
+ async 'Latest function calls wins'($) {
766
+ const first = [];
767
+ const last = [];
768
+ function send_name(next) {
769
+ $mol_wire_sync(first).push(next);
770
+ $.$mol_wait_timeout(0);
771
+ last.push(next);
772
+ }
773
+ const name = $mol_wire_async(send_name);
774
+ name('john');
775
+ const promise = name('jin');
776
+ $.$mol_after_mock_warp();
777
+ await promise;
778
+ $mol_assert_like(first, ['john', 'jin']);
779
+ $mol_assert_like(last, ['jin']);
780
+ },
781
+ });
782
+ })($ || ($ = {}));
783
+ //mol/wire/async/async.test.ts
784
+ ;
785
+ "use strict";
786
+ var $;
787
+ (function ($_1) {
788
+ $mol_test({
789
+ 'Cached channel'($) {
790
+ class App extends $mol_object2 {
791
+ static $ = $;
792
+ static value(next = 1) {
793
+ return next + 1;
794
+ }
795
+ }
796
+ __decorate([
797
+ $mol_wire_solo
798
+ ], App, "value", null);
799
+ $mol_assert_equal(App.value(), 2);
800
+ App.value(2);
801
+ $mol_assert_equal(App.value(), 3);
802
+ },
803
+ 'Read Pushed'($) {
804
+ class App extends $mol_object2 {
805
+ static $ = $;
806
+ static value(next = 0) {
807
+ return next;
808
+ }
809
+ }
810
+ __decorate([
811
+ $mol_wire_solo
812
+ ], App, "value", null);
813
+ $mol_assert_equal(App.value(1), 1);
814
+ $mol_assert_equal(App.value(), 1);
815
+ },
816
+ 'Mem overrides mem'($) {
817
+ class Base extends $mol_object2 {
818
+ static $ = $;
819
+ static value(next = 1) {
820
+ return next + 1;
821
+ }
822
+ }
823
+ __decorate([
824
+ $mol_wire_solo
825
+ ], Base, "value", null);
826
+ class Middle extends Base {
827
+ static value(next) {
828
+ return super.value(next) + 1;
829
+ }
830
+ }
831
+ __decorate([
832
+ $mol_wire_solo
833
+ ], Middle, "value", null);
834
+ class App extends Middle {
835
+ static value(next) {
836
+ return super.value(next) * 3;
837
+ }
838
+ }
839
+ __decorate([
840
+ $mol_wire_solo
841
+ ], App, "value", null);
842
+ $mol_assert_equal(App.value(), 9);
843
+ $mol_assert_equal(App.value(5), 21);
844
+ $mol_assert_equal(App.value(), 21);
845
+ },
846
+ 'Auto recalculation of cached values'($) {
847
+ class App extends $mol_object2 {
848
+ static $ = $;
849
+ static xxx(next) {
850
+ return next || 1;
851
+ }
852
+ static yyy() {
853
+ return this.xxx() + 1;
854
+ }
855
+ static zzz() {
856
+ return this.yyy() + 1;
857
+ }
858
+ }
859
+ __decorate([
860
+ $mol_wire_solo
861
+ ], App, "xxx", null);
862
+ __decorate([
863
+ $mol_wire_solo
864
+ ], App, "yyy", null);
865
+ __decorate([
866
+ $mol_wire_solo
867
+ ], App, "zzz", null);
868
+ $mol_assert_equal(App.yyy(), 2);
869
+ $mol_assert_equal(App.zzz(), 3);
870
+ App.xxx(5);
871
+ $mol_assert_equal(App.zzz(), 7);
872
+ },
873
+ 'Skip recalculation when actually no dependency changes'($) {
874
+ const log = [];
875
+ class App extends $mol_object2 {
876
+ static $ = $;
877
+ static xxx(next) {
878
+ log.push('xxx');
879
+ return next || 1;
880
+ }
881
+ static yyy() {
882
+ log.push('yyy');
883
+ return [Math.sign(this.xxx())];
884
+ }
885
+ static zzz() {
886
+ log.push('zzz');
887
+ return this.yyy()[0] + 1;
888
+ }
889
+ }
890
+ __decorate([
891
+ $mol_wire_solo
892
+ ], App, "xxx", null);
893
+ __decorate([
894
+ $mol_wire_solo
895
+ ], App, "yyy", null);
896
+ __decorate([
897
+ $mol_wire_solo
898
+ ], App, "zzz", null);
899
+ App.zzz();
900
+ $mol_assert_like(log, ['zzz', 'yyy', 'xxx']);
901
+ App.xxx(5);
902
+ $mol_assert_like(log, ['zzz', 'yyy', 'xxx', 'xxx']);
903
+ App.zzz();
904
+ $mol_assert_like(log, ['zzz', 'yyy', 'xxx', 'xxx', 'yyy']);
905
+ },
906
+ 'Flow: Auto'($) {
907
+ class App extends $mol_object2 {
908
+ static get $() { return $; }
909
+ static source(next = 1) { return next; }
910
+ static condition(next = true) { return next; }
911
+ static counter = 0;
912
+ static result() {
913
+ const res = this.condition() ? this.source() : 0;
914
+ return res + this.counter++;
915
+ }
916
+ }
917
+ __decorate([
918
+ $mol_wire_solo
919
+ ], App, "source", null);
920
+ __decorate([
921
+ $mol_wire_solo
922
+ ], App, "condition", null);
923
+ __decorate([
924
+ $mol_wire_solo
925
+ ], App, "result", null);
926
+ $mol_assert_equal(App.result(), 1);
927
+ $mol_assert_equal(App.counter, 1);
928
+ App.source(10);
929
+ $mol_assert_equal(App.result(), 11);
930
+ $mol_assert_equal(App.counter, 2);
931
+ App.condition(false);
932
+ $mol_assert_equal(App.result(), 2);
933
+ $mol_assert_equal(App.counter, 3);
934
+ $mol_wire_fiber.sync();
935
+ $mol_assert_equal(App.source(), 1);
936
+ App.source(20);
937
+ $mol_assert_equal(App.result(), 2);
938
+ $mol_assert_equal(App.counter, 3);
939
+ App.condition(true);
940
+ $mol_assert_equal(App.result(), 23);
941
+ $mol_assert_equal(App.counter, 4);
942
+ },
943
+ 'Dupes: Equality'($) {
944
+ let counter = 0;
945
+ class App extends $mol_object2 {
946
+ static $ = $;
947
+ static foo(next) {
948
+ return next ?? { numbs: [1] };
949
+ }
950
+ static bar() {
951
+ return { ...this.foo(), count: ++counter };
952
+ }
953
+ }
954
+ __decorate([
955
+ $mol_wire_solo
956
+ ], App, "foo", null);
957
+ __decorate([
958
+ $mol_wire_solo
959
+ ], App, "bar", null);
960
+ $mol_assert_like(App.bar(), { numbs: [1], count: 1 });
961
+ App.foo({ numbs: [1] });
962
+ $mol_assert_like(App.bar(), { numbs: [1], count: 1 });
963
+ App.foo({ numbs: [2] });
964
+ $mol_assert_like(App.bar(), { numbs: [2], count: 2 });
965
+ },
966
+ 'Cycle: Fail'($) {
967
+ class App extends $mol_object2 {
968
+ static $ = $;
969
+ static foo() {
970
+ return this.bar() + 1;
971
+ }
972
+ static bar() {
973
+ return this.foo() + 1;
974
+ }
975
+ static test() {
976
+ $mol_assert_fail(() => App.foo(), 'Circular subscription');
977
+ }
978
+ }
979
+ __decorate([
980
+ $mol_wire_solo
981
+ ], App, "foo", null);
982
+ __decorate([
983
+ $mol_wire_solo
984
+ ], App, "bar", null);
985
+ __decorate([
986
+ $mol_wire_method
987
+ ], App, "test", null);
988
+ App.test();
989
+ },
990
+ 'Different order of pull and push'($) {
991
+ class App extends $mol_object2 {
992
+ static $ = $;
993
+ static store(next = 0) {
994
+ return next;
995
+ }
996
+ static fast(next) {
997
+ return this.store(next);
998
+ }
999
+ static slow(next) {
1000
+ if (next !== undefined)
1001
+ this.slow();
1002
+ return this.store(next);
1003
+ }
1004
+ }
1005
+ __decorate([
1006
+ $mol_wire_solo
1007
+ ], App, "store", null);
1008
+ __decorate([
1009
+ $mol_wire_solo
1010
+ ], App, "fast", null);
1011
+ __decorate([
1012
+ $mol_wire_solo
1013
+ ], App, "slow", null);
1014
+ App.fast();
1015
+ $mol_assert_equal(App.slow(666), 666);
1016
+ $mol_assert_equal(App.fast(), App.slow(), 666);
1017
+ App.store(777);
1018
+ $mol_assert_equal(App.fast(), App.slow(), 777);
1019
+ },
1020
+ 'Actions inside invariant'($) {
1021
+ class App extends $mol_object2 {
1022
+ static $ = $;
1023
+ static count(next = 0) {
1024
+ return next;
1025
+ }
1026
+ static count2() {
1027
+ return this.count();
1028
+ }
1029
+ static res() {
1030
+ const count = this.count2();
1031
+ if (!count)
1032
+ this.count(count + 1);
1033
+ return count + 1;
1034
+ }
1035
+ }
1036
+ __decorate([
1037
+ $mol_wire_solo
1038
+ ], App, "count", null);
1039
+ __decorate([
1040
+ $mol_wire_solo
1041
+ ], App, "count2", null);
1042
+ __decorate([
1043
+ $mol_wire_solo
1044
+ ], App, "res", null);
1045
+ $mol_assert_like(App.res(), 1);
1046
+ App.count(5);
1047
+ $mol_assert_like(App.res(), 6);
1048
+ },
1049
+ async 'Toggle with async'($) {
1050
+ class App extends $mol_object2 {
1051
+ static $ = $;
1052
+ static checked(next = false) {
1053
+ $$.$mol_wait_timeout(0);
1054
+ return next;
1055
+ }
1056
+ static toggle() {
1057
+ const prev = this.checked();
1058
+ $mol_assert_unique(this.checked(!prev), prev);
1059
+ }
1060
+ static res() {
1061
+ return this.checked();
1062
+ }
1063
+ static test() {
1064
+ $mol_assert_equal(App.res(), false);
1065
+ App.toggle();
1066
+ $mol_assert_equal(App.res(), true);
1067
+ }
1068
+ }
1069
+ __decorate([
1070
+ $mol_wire_solo
1071
+ ], App, "checked", null);
1072
+ __decorate([
1073
+ $mol_wire_method
1074
+ ], App, "toggle", null);
1075
+ __decorate([
1076
+ $mol_wire_solo
1077
+ ], App, "res", null);
1078
+ __decorate([
1079
+ $mol_wire_method
1080
+ ], App, "test", null);
1081
+ await $mol_wire_async(App).test();
1082
+ },
1083
+ 'Restore after error'($) {
1084
+ class App extends $mol_object2 {
1085
+ static get $() { return $; }
1086
+ static condition(next = false) { return next; }
1087
+ static broken() {
1088
+ if (this.condition()) {
1089
+ $mol_fail(new Error('test error'));
1090
+ }
1091
+ return 1;
1092
+ }
1093
+ static result() {
1094
+ return this.broken();
1095
+ }
1096
+ }
1097
+ __decorate([
1098
+ $mol_wire_solo
1099
+ ], App, "condition", null);
1100
+ __decorate([
1101
+ $mol_wire_solo
1102
+ ], App, "broken", null);
1103
+ __decorate([
1104
+ $mol_wire_solo
1105
+ ], App, "result", null);
1106
+ $mol_assert_equal(App.result(), 1);
1107
+ App.condition(true);
1108
+ $mol_assert_fail(() => App.result());
1109
+ App.condition(false);
1110
+ $mol_assert_equal(App.result(), 1);
1111
+ },
1112
+ async 'Wait for data'($) {
1113
+ class App extends $mol_object2 {
1114
+ static $ = $;
1115
+ static async source() {
1116
+ return 'Jin';
1117
+ }
1118
+ static middle() {
1119
+ return $mol_wire_sync(this).source();
1120
+ }
1121
+ static target() {
1122
+ return this.middle();
1123
+ }
1124
+ static test() {
1125
+ $mol_assert_equal(App.target(), 'Jin');
1126
+ }
1127
+ }
1128
+ __decorate([
1129
+ $mol_wire_solo
1130
+ ], App, "middle", null);
1131
+ __decorate([
1132
+ $mol_wire_solo
1133
+ ], App, "target", null);
1134
+ __decorate([
1135
+ $mol_wire_method
1136
+ ], App, "test", null);
1137
+ await $mol_wire_async(App).test();
1138
+ },
1139
+ 'Auto destroy on long alone'($) {
1140
+ let destroyed = false;
1141
+ class App extends $mol_object2 {
1142
+ static $ = $;
1143
+ static showing(next = true) {
1144
+ return next;
1145
+ }
1146
+ static details() {
1147
+ return {
1148
+ destructor() {
1149
+ destroyed = true;
1150
+ }
1151
+ };
1152
+ }
1153
+ static render() {
1154
+ return this.showing() ? this.details() : null;
1155
+ }
1156
+ }
1157
+ __decorate([
1158
+ $mol_wire_solo
1159
+ ], App, "showing", null);
1160
+ __decorate([
1161
+ $mol_wire_solo
1162
+ ], App, "details", null);
1163
+ __decorate([
1164
+ $mol_wire_solo
1165
+ ], App, "render", null);
1166
+ const details = App.render();
1167
+ $mol_assert_ok(details);
1168
+ App.showing(false);
1169
+ $mol_assert_not(App.render());
1170
+ App.showing(true);
1171
+ $mol_assert_equal(App.render(), details);
1172
+ $mol_wire_fiber.sync();
1173
+ $mol_assert_not(destroyed);
1174
+ App.showing(false);
1175
+ $mol_wire_fiber.sync();
1176
+ $mol_assert_ok(destroyed);
1177
+ App.showing(true);
1178
+ $mol_assert_unique(App.render(), details);
1179
+ },
1180
+ async 'Hold pubs while wait async task'($) {
1181
+ class App extends $mol_object2 {
1182
+ static $ = $;
1183
+ static counter = 0;
1184
+ static resets(next) {
1185
+ return ($mol_wire_probe(() => this.resets()) ?? -1) + 1;
1186
+ }
1187
+ static async wait() { }
1188
+ static value() {
1189
+ return ++this.counter;
1190
+ }
1191
+ static result() {
1192
+ if (this.resets())
1193
+ $mol_wire_sync(this).wait();
1194
+ return this.value();
1195
+ }
1196
+ static test() {
1197
+ }
1198
+ }
1199
+ __decorate([
1200
+ $mol_wire_solo
1201
+ ], App, "resets", null);
1202
+ __decorate([
1203
+ $mol_wire_solo
1204
+ ], App, "value", null);
1205
+ __decorate([
1206
+ $mol_wire_solo
1207
+ ], App, "result", null);
1208
+ __decorate([
1209
+ $mol_wire_method
1210
+ ], App, "test", null);
1211
+ $mol_assert_equal(App.result(), 1);
1212
+ App.resets(null);
1213
+ $mol_wire_fiber.sync();
1214
+ $mol_assert_equal(await $mol_wire_async(App).result(), 1);
1215
+ },
1216
+ 'Owned value has js-path name'() {
1217
+ class App extends $mol_object2 {
1218
+ static title() {
1219
+ return new $mol_object2;
1220
+ }
1221
+ }
1222
+ __decorate([
1223
+ $mol_wire_solo
1224
+ ], App, "title", null);
1225
+ $mol_assert_equal(`${App.title()}`, 'App.title()');
1226
+ },
1227
+ 'Unsubscribe from temp pubs on complete'($) {
1228
+ class Random extends $mol_object2 {
1229
+ static $ = $;
1230
+ static seed() {
1231
+ return Math.random();
1232
+ }
1233
+ static resets(next) {
1234
+ return Math.random();
1235
+ }
1236
+ static value() {
1237
+ this.resets();
1238
+ return this.seed();
1239
+ }
1240
+ }
1241
+ __decorate([
1242
+ $mol_wire_method
1243
+ ], Random, "seed", null);
1244
+ __decorate([
1245
+ $mol_wire_solo
1246
+ ], Random, "resets", null);
1247
+ __decorate([
1248
+ $mol_wire_solo
1249
+ ], Random, "value", null);
1250
+ const first = Random.value();
1251
+ Random.resets(null);
1252
+ $mol_assert_unique(Random.value(), first);
1253
+ },
1254
+ });
1255
+ })($ || ($ = {}));
1256
+ //mol/wire/solo/solo.test.ts
1257
+ ;
1258
+ "use strict";
1259
+ var $;
1260
+ (function ($_1) {
1261
+ $mol_test({
1262
+ 'Memoize by single simple key'($) {
1263
+ class Team extends $mol_object2 {
1264
+ static $ = $;
1265
+ static user_name(user, next) {
1266
+ return next ?? user;
1267
+ }
1268
+ static user_names() {
1269
+ return [
1270
+ this.user_name('jin'),
1271
+ this.user_name('john'),
1272
+ ];
1273
+ }
1274
+ }
1275
+ __decorate([
1276
+ $mol_wire_plex
1277
+ ], Team, "user_name", null);
1278
+ __decorate([
1279
+ $mol_wire_solo
1280
+ ], Team, "user_names", null);
1281
+ $mol_assert_like(Team.user_names(), ['jin', 'john']);
1282
+ Team.user_name('jin', 'JIN');
1283
+ $mol_assert_like(Team.user_names(), ['JIN', 'john']);
1284
+ },
1285
+ 'Memoize by single complex key'($) {
1286
+ class Map extends $mol_object2 {
1287
+ static $ = $;
1288
+ static tile(pos) {
1289
+ return new String(`/tile=${pos}`);
1290
+ }
1291
+ static test() {
1292
+ $mol_assert_like(this.tile([0, 1]), new String('/tile=0,1'));
1293
+ $mol_assert_equal(this.tile([0, 1]), this.tile([0, 1]));
1294
+ }
1295
+ }
1296
+ __decorate([
1297
+ $mol_wire_plex
1298
+ ], Map, "tile", null);
1299
+ __decorate([
1300
+ $mol_wire_method
1301
+ ], Map, "test", null);
1302
+ Map.test();
1303
+ },
1304
+ 'Owned value has js-path name'() {
1305
+ class App extends $mol_object2 {
1306
+ static like(friend) {
1307
+ return new $mol_object2;
1308
+ }
1309
+ static relation([friend, props]) {
1310
+ return new $mol_object2;
1311
+ }
1312
+ }
1313
+ __decorate([
1314
+ $mol_wire_plex
1315
+ ], App, "like", null);
1316
+ __decorate([
1317
+ $mol_wire_plex
1318
+ ], App, "relation", null);
1319
+ $mol_assert_equal(`${App.like(123)}`, 'App.like(123)');
1320
+ $mol_assert_equal(`${App.relation([123, [456]])}`, 'App.relation([123,[456]])');
1321
+ },
1322
+ 'Deep deps'($) {
1323
+ class Fib extends $mol_object2 {
1324
+ static $ = $;
1325
+ static sums = 0;
1326
+ static value(index, next) {
1327
+ if (next)
1328
+ return next;
1329
+ if (index < 2)
1330
+ return 1;
1331
+ ++this.sums;
1332
+ return this.value(index - 1) + this.value(index - 2);
1333
+ }
1334
+ }
1335
+ __decorate([
1336
+ $mol_wire_plex
1337
+ ], Fib, "value", null);
1338
+ $mol_assert_equal(Fib.value(4), 5);
1339
+ $mol_assert_equal(Fib.sums, 3);
1340
+ Fib.value(1, 2);
1341
+ $mol_assert_equal(Fib.value(4), 8);
1342
+ $mol_assert_equal(Fib.sums, 6);
1343
+ },
1344
+ });
1345
+ })($ || ($ = {}));
1346
+ //mol/wire/plex/plex.test.ts
1347
+ ;
1348
+ "use strict";
1349
+ var $;
1350
+ (function ($) {
1351
+ $mol_test({
1352
+ 'Previous value'() {
1353
+ class Cache extends $mol_object2 {
1354
+ static store(next) {
1355
+ if (!next)
1356
+ return {};
1357
+ return {
1358
+ ...$mol_wire_probe(() => this.store()) ?? {},
1359
+ ...next,
1360
+ };
1361
+ }
1362
+ }
1363
+ __decorate([
1364
+ $mol_wire_solo
1365
+ ], Cache, "store", null);
1366
+ $mol_assert_like(Cache.store(), {});
1367
+ $mol_assert_like(Cache.store({ foo: 666 }), { foo: 666 });
1368
+ $mol_assert_like(Cache.store({ bar: 777 }), { foo: 666, bar: 777 });
1369
+ },
1370
+ });
1371
+ })($ || ($ = {}));
1372
+ //mol/wire/probe/probe.test.ts
1373
+ ;
1374
+ "use strict";
1375
+ var $;
1376
+ (function ($) {
1377
+ $mol_test({
1378
+ 'init with overload'() {
1379
+ class X extends $mol_object {
1380
+ foo() {
1381
+ return 1;
1382
+ }
1383
+ }
1384
+ var x = X.make({
1385
+ foo: () => 2,
1386
+ });
1387
+ $mol_assert_equal(x.foo(), 2);
1388
+ },
1389
+ });
1390
+ })($ || ($ = {}));
1391
+ //mol/object/object.test.ts
1392
+ ;
1393
+ "use strict";
1394
+ var $;
1395
+ (function ($) {
1396
+ $mol_test({
1397
+ 'local get set delete'() {
1398
+ var key = '$mol_state_local_test:' + Math.random();
1399
+ $mol_assert_equal($mol_state_local.value(key), null);
1400
+ $mol_state_local.value(key, 123);
1401
+ $mol_assert_equal($mol_state_local.value(key), 123);
1402
+ $mol_state_local.value(key, null);
1403
+ $mol_assert_equal($mol_state_local.value(key), null);
1404
+ },
1405
+ });
1406
+ })($ || ($ = {}));
1407
+ //mol/state/local/local.test.ts
1408
+ ;
1409
+ "use strict";
1410
+ var $;
1411
+ (function ($) {
1412
+ $mol_test_mocks.push(context => {
1413
+ class $mol_state_local_mock extends $mol_state_local {
1414
+ static state = {};
1415
+ static value(key, next = this.state[key]) {
1416
+ return this.state[key] = (next || null);
1417
+ }
1418
+ }
1419
+ __decorate([
1420
+ $mol_mem_key
1421
+ ], $mol_state_local_mock, "value", null);
1422
+ context.$mol_state_local = $mol_state_local_mock;
1423
+ });
1424
+ })($ || ($ = {}));
1425
+ //mol/state/local/local.mock.test.ts
1426
+ ;
1427
+ "use strict";
1428
+ var $;
1429
+ (function ($) {
1430
+ $mol_test({
1431
+ 'encode utf8 string'() {
1432
+ const str = 'Hello, ΧΨΩЫ';
1433
+ const encoded = new Uint8Array([72, 101, 108, 108, 111, 44, 32, 206, 167, 206, 168, 206, 169, 208, 171]);
1434
+ $mol_assert_like($mol_charset_encode(str), encoded);
1435
+ },
1436
+ });
1437
+ })($ || ($ = {}));
1438
+ //mol/charset/encode/encode.test.ts
1439
+ ;
1440
+ "use strict";
1441
+ var $;
1442
+ (function ($) {
1443
+ $mol_test({
1444
+ async 'sizes'() {
1445
+ const pair = await $$.$mol_crypto_auditor_pair();
1446
+ const key_public = await pair.public.serial();
1447
+ $mol_assert_equal(key_public.length, $mol_crypto_auditor_public.size);
1448
+ const key_private = await pair.private.serial();
1449
+ $mol_assert_equal(key_private.length, $mol_crypto_auditor_private.size);
1450
+ const data = new Uint8Array([1, 2, 3]);
1451
+ const sign = await pair.private.sign(data);
1452
+ $mol_assert_equal(sign.byteLength, $mol_crypto_auditor_sign_size);
1453
+ },
1454
+ async 'verify self signed with auto generated key'() {
1455
+ const auditor = await $$.$mol_crypto_auditor_pair();
1456
+ const data = new Uint8Array([1, 2, 3]);
1457
+ const sign = await auditor.private.sign(data);
1458
+ $mol_assert_ok(await auditor.public.verify(data, sign));
1459
+ },
1460
+ async 'verify signed with exported auto generated key'() {
1461
+ const pair = await $$.$mol_crypto_auditor_pair();
1462
+ const data = new Uint8Array([1, 2, 3]);
1463
+ const Alice = await $mol_crypto_auditor_private.from(await pair.private.serial());
1464
+ const sign = await Alice.sign(data);
1465
+ const Bob = await $mol_crypto_auditor_public.from(await pair.public.serial());
1466
+ $mol_assert_ok(await Bob.verify(data, sign));
1467
+ },
1468
+ async 'take public key from private'() {
1469
+ const pair = await $$.$mol_crypto_auditor_pair();
1470
+ const data = new Uint8Array([1, 2, 3]);
1471
+ const Alice = pair.private;
1472
+ const sign = await Alice.sign(data);
1473
+ const Bob = await pair.private.public();
1474
+ const Carol = await $mol_crypto_auditor_public.from(await pair.private.serial());
1475
+ $mol_assert_ok(await Bob.verify(data, sign));
1476
+ $mol_assert_ok(await Carol.verify(data, sign));
1477
+ },
1478
+ });
1479
+ })($ || ($ = {}));
1480
+ //mol/crypto/auditor/auditor.web.test.ts
1481
+ ;
1482
+ "use strict";
1483
+ var $;
1484
+ (function ($) {
1485
+ $mol_test({
1486
+ 'run callback'() {
1487
+ class Plus1 extends $mol_wrapper {
1488
+ static wrap(task) {
1489
+ return function (...args) {
1490
+ return task.call(this, ...args) + 1;
1491
+ };
1492
+ }
1493
+ }
1494
+ $mol_assert_equal(Plus1.run(() => 2), 3);
1495
+ },
1496
+ 'wrap function'() {
1497
+ class Plus1 extends $mol_wrapper {
1498
+ static wrap(task) {
1499
+ return function (...args) {
1500
+ return task.call(this, ...args) + 1;
1501
+ };
1502
+ }
1503
+ }
1504
+ const obj = {
1505
+ level: 2,
1506
+ pow: Plus1.func(function (a) {
1507
+ return a ** this.level;
1508
+ })
1509
+ };
1510
+ $mol_assert_equal(obj.pow(2), 5);
1511
+ },
1512
+ 'decorate field getter'() {
1513
+ class Plus1 extends $mol_wrapper {
1514
+ static last = 0;
1515
+ static wrap(task) {
1516
+ return function (...args) {
1517
+ return Plus1.last = (task.call(this, ...args) || 0) + 1;
1518
+ };
1519
+ }
1520
+ }
1521
+ class Foo {
1522
+ static get two() {
1523
+ return 1;
1524
+ }
1525
+ static set two(next) { }
1526
+ }
1527
+ __decorate([
1528
+ Plus1.field
1529
+ ], Foo, "two", null);
1530
+ $mol_assert_equal(Foo.two, 2);
1531
+ Foo.two = 3;
1532
+ $mol_assert_equal(Plus1.last, 2);
1533
+ $mol_assert_equal(Foo.two, 2);
1534
+ },
1535
+ 'decorate instance method'() {
1536
+ class Plus1 extends $mol_wrapper {
1537
+ static wrap(task) {
1538
+ return function (...args) {
1539
+ return task.call(this, ...args) + 1;
1540
+ };
1541
+ }
1542
+ }
1543
+ class Foo1 {
1544
+ level = 2;
1545
+ pow(a) {
1546
+ return a ** this.level;
1547
+ }
1548
+ }
1549
+ __decorate([
1550
+ Plus1.method
1551
+ ], Foo1.prototype, "pow", null);
1552
+ const Foo2 = Foo1;
1553
+ const foo = new Foo2;
1554
+ $mol_assert_equal(foo.pow(2), 5);
1555
+ },
1556
+ 'decorate static method'() {
1557
+ class Plus1 extends $mol_wrapper {
1558
+ static wrap(task) {
1559
+ return function (...args) {
1560
+ return task.call(this, ...args) + 1;
1561
+ };
1562
+ }
1563
+ }
1564
+ class Foo {
1565
+ static level = 2;
1566
+ static pow(a) {
1567
+ return a ** this.level;
1568
+ }
1569
+ }
1570
+ __decorate([
1571
+ Plus1.method
1572
+ ], Foo, "pow", null);
1573
+ $mol_assert_equal(Foo.pow(2), 5);
1574
+ },
1575
+ 'decorate class'() {
1576
+ class BarInc extends $mol_wrapper {
1577
+ static wrap(task) {
1578
+ return function (...args) {
1579
+ const foo = task.call(this, ...args);
1580
+ foo.bar++;
1581
+ return foo;
1582
+ };
1583
+ }
1584
+ }
1585
+ let Foo = class Foo {
1586
+ bar;
1587
+ constructor(bar) {
1588
+ this.bar = bar;
1589
+ }
1590
+ };
1591
+ Foo = __decorate([
1592
+ BarInc.class
1593
+ ], Foo);
1594
+ $mol_assert_equal(new Foo(2).bar, 3);
1595
+ },
1596
+ });
1597
+ })($ || ($ = {}));
1598
+ //mol/wrapper/wrapper.test.ts
1599
+ ;
1600
+ "use strict";
1601
+ var $;
1602
+ (function ($) {
1603
+ $mol_test({
1604
+ 'memoize field'() {
1605
+ class Foo {
1606
+ static one = 1;
1607
+ static get two() {
1608
+ return ++this.one;
1609
+ }
1610
+ static set two(next) { }
1611
+ }
1612
+ __decorate([
1613
+ $mol_memo.field
1614
+ ], Foo, "two", null);
1615
+ $mol_assert_equal(Foo.two, 2);
1616
+ $mol_assert_equal(Foo.two, 2);
1617
+ Foo.two = 3;
1618
+ $mol_assert_equal(Foo.two, 3);
1619
+ $mol_assert_equal(Foo.two, 3);
1620
+ },
1621
+ });
1622
+ })($ || ($ = {}));
1623
+ //mol/memo/memo.test.ts
1624
+ ;
1625
+ "use strict";
1626
+ var $;
1627
+ (function ($) {
1628
+ $mol_test({
1629
+ 'config by value'() {
1630
+ const N = $mol_data_setup((a) => a, 5);
1631
+ $mol_assert_equal(N.config, 5);
1632
+ },
1633
+ });
1634
+ })($ || ($ = {}));
1635
+ //mol/data/setup/setup.test.ts
1636
+ ;
1637
+ "use strict";
1638
+ var $;
1639
+ (function ($) {
1640
+ $mol_test({
1641
+ 'equal paths'() {
1642
+ const diff = $mol_diff_path([1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]);
1643
+ $mol_assert_like(diff, {
1644
+ prefix: [1, 2, 3, 4],
1645
+ suffix: [[], [], []],
1646
+ });
1647
+ },
1648
+ 'different suffix'() {
1649
+ const diff = $mol_diff_path([1, 2, 3, 4], [1, 2, 3, 5], [1, 2, 5, 4]);
1650
+ $mol_assert_like(diff, {
1651
+ prefix: [1, 2],
1652
+ suffix: [[3, 4], [3, 5], [5, 4]],
1653
+ });
1654
+ },
1655
+ 'one contains other'() {
1656
+ const diff = $mol_diff_path([1, 2, 3, 4], [1, 2], [1, 2, 3]);
1657
+ $mol_assert_like(diff, {
1658
+ prefix: [1, 2],
1659
+ suffix: [[3, 4], [], [3]],
1660
+ });
1661
+ },
1662
+ 'fully different'() {
1663
+ const diff = $mol_diff_path([1, 2], [3, 4], [5, 6]);
1664
+ $mol_assert_like(diff, {
1665
+ prefix: [],
1666
+ suffix: [[1, 2], [3, 4], [5, 6]],
1667
+ });
1668
+ },
1669
+ });
1670
+ })($ || ($ = {}));
1671
+ //mol/diff/path/path.test.ts
1672
+ ;
1673
+ "use strict";
1674
+ var $;
1675
+ (function ($) {
1676
+ let sex;
1677
+ (function (sex) {
1678
+ sex[sex["male"] = 0] = "male";
1679
+ sex[sex["female"] = 1] = "female";
1680
+ })(sex || (sex = {}));
1681
+ let gender;
1682
+ (function (gender) {
1683
+ gender["bisexual"] = "bisexual";
1684
+ gender["trans"] = "transgender";
1685
+ })(gender || (gender = {}));
1686
+ $mol_test({
1687
+ 'config of enum'() {
1688
+ const Sex = $mol_data_enum('sex', sex);
1689
+ $mol_assert_like(Sex.config, {
1690
+ name: 'sex',
1691
+ dict: sex,
1692
+ });
1693
+ },
1694
+ 'name of enum'() {
1695
+ const Sex = $mol_data_enum('sex', sex);
1696
+ $mol_assert_equal(Sex.config.name, 'sex');
1697
+ },
1698
+ 'Is right value of enum'() {
1699
+ const Sex = $mol_data_enum('sex', sex);
1700
+ $mol_assert_equal(Sex(0), sex.male);
1701
+ },
1702
+ 'Is wrong value of enum'() {
1703
+ const Sex = $mol_data_enum('sex', sex);
1704
+ $mol_assert_fail(() => Sex(2), `2 is not value of sex enum`);
1705
+ },
1706
+ 'Is name instead of value'() {
1707
+ const Sex = $mol_data_enum('sex', sex);
1708
+ $mol_assert_fail(() => Sex('male'), `male is not value of sex enum`);
1709
+ },
1710
+ 'Is common object field'() {
1711
+ const Sex = $mol_data_enum('sex', sex);
1712
+ $mol_assert_fail(() => Sex('__proto__'), `__proto__ is not value of sex enum`);
1713
+ },
1714
+ });
1715
+ $mol_test({
1716
+ 'config of enum'() {
1717
+ const Gender = $mol_data_enum('gender', gender);
1718
+ $mol_assert_like(Gender.config, {
1719
+ name: 'gender',
1720
+ dict: gender,
1721
+ });
1722
+ },
1723
+ 'Is right value of enum'() {
1724
+ const Gender = $mol_data_enum('gender', gender);
1725
+ $mol_assert_equal(Gender('transgender'), gender.trans);
1726
+ },
1727
+ 'Is wrong value of enum'() {
1728
+ const Gender = $mol_data_enum('gender', gender);
1729
+ $mol_assert_fail(() => Gender('xxx'), `xxx is not value of gender enum`);
1730
+ },
1731
+ 'Is name instead of value'() {
1732
+ const Gender = $mol_data_enum('gender', gender);
1733
+ $mol_assert_fail(() => Gender('trans'), `trans is not value of gender enum`);
1734
+ },
1735
+ 'Is common object field'() {
1736
+ const Gender = $mol_data_enum('gender', gender);
1737
+ $mol_assert_fail(() => Gender('__proto__'), `__proto__ is not value of gender enum`);
1738
+ },
1739
+ });
1740
+ })($ || ($ = {}));
1741
+ //mol/data/enum/enum.test.ts
1742
+ ;
1743
+ "use strict";
1744
+ var $;
1745
+ (function ($) {
1746
+ $mol_test({
1747
+ 'decode utf8 string'() {
1748
+ const str = 'Hello, ΧΨΩЫ';
1749
+ const encoded = new Uint8Array([72, 101, 108, 108, 111, 44, 32, 206, 167, 206, 168, 206, 169, 208, 171]);
1750
+ $mol_assert_equal($mol_charset_decode(encoded), str);
1751
+ $mol_assert_equal($mol_charset_decode(encoded, 'utf8'), str);
1752
+ },
1753
+ 'decode empty string'() {
1754
+ const encoded = new Uint8Array([]);
1755
+ $mol_assert_equal($mol_charset_decode(encoded), '');
1756
+ },
1757
+ });
1758
+ })($ || ($ = {}));
1759
+ //mol/charset/decode/decode.test.ts
1760
+ ;
1761
+ "use strict";
1762
+ var $;
1763
+ (function ($_1) {
1764
+ const common = [
1765
+ $mol_int62_to_string({
1766
+ lo: 12 << 0 | 13 << 8 | 14 << 16 | 15 << 24,
1767
+ hi: 13 << 0 | 14 << 8 | 15 << 16 | 16 << 24,
1768
+ }),
1769
+ $mol_int62_to_string({
1770
+ lo: 2 << 0 | 3 << 8 | 4 << 16 | 5 << 24,
1771
+ hi: 3 << 0 | 4 << 8 | 5 << 16 | 6 << 24,
1772
+ }),
1773
+ $mol_int62_to_string({
1774
+ lo: 4 << 0 | 5 << 8 | 6 << 16 | 7 << 24,
1775
+ hi: 5 << 0 | 6 << 8 | 7 << 16 | 8 << 24,
1776
+ }),
1777
+ $mol_int62_to_string({
1778
+ lo: 10 << 0 | 11 << 8 | 12 << 16 | 13 << 24,
1779
+ hi: 11 << 0 | 12 << 8 | 13 << 16 | 14 << 24,
1780
+ }),
1781
+ $mol_int62_to_string({
1782
+ lo: 6 << 0 | 7 << 8 | 8 << 16 | 9 << 24,
1783
+ hi: 7 << 0 | 8 << 8 | 9 << 16 | 10 << 24,
1784
+ }),
1785
+ $mol_int62_to_string({
1786
+ lo: 8 << 0 | 9 << 8 | 10 << 16 | 11 << 24,
1787
+ hi: 9 << 0 | 10 << 8 | 11 << 16 | 12 << 24,
1788
+ }),
1789
+ 1 << 0 | 2 << 8 | 3 << 16 | 4 << 24,
1790
+ ];
1791
+ $mol_test({
1792
+ 'pack and unpack unit with null'($) {
1793
+ const source = new $hyoo_crowd_unit(...common, null, null);
1794
+ const packed = $hyoo_crowd_unit_bin.from_unit(source);
1795
+ const unpacked = packed.unit();
1796
+ source.bin = packed;
1797
+ $mol_assert_like(source, unpacked);
1798
+ },
1799
+ 'pack and unpack unit with json'($) {
1800
+ const source = new $hyoo_crowd_unit(...common, { a: [1] }, null);
1801
+ const packed = $hyoo_crowd_unit_bin.from_unit(source);
1802
+ const unpacked = packed.unit();
1803
+ source.bin = packed;
1804
+ $mol_assert_like(source, unpacked);
1805
+ },
1806
+ 'pack and unpack unit with bin'($) {
1807
+ const source = new $hyoo_crowd_unit(...common, new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]), null);
1808
+ const packed = $hyoo_crowd_unit_bin.from_unit(source);
1809
+ const unpacked = packed.unit();
1810
+ source.bin = packed;
1811
+ $mol_assert_like(source, unpacked);
1812
+ },
1813
+ async 'sign / verify'($) {
1814
+ const source = new $hyoo_crowd_unit(...common, { a: [1] }, null);
1815
+ const packed = $hyoo_crowd_unit_bin.from_unit(source);
1816
+ const key = await $.$mol_crypto_auditor_pair();
1817
+ packed.sign(new Uint8Array(await key.private.sign(packed.sens())));
1818
+ const sign = packed.sign();
1819
+ $mol_assert_ok(await key.public.verify(packed.sens(), sign));
1820
+ },
1821
+ });
1822
+ })($ || ($ = {}));
1823
+ //hyoo/crowd/unit/unit.test.ts
1824
+ ;
1825
+ "use strict";
1826
+ var $;
1827
+ (function ($) {
1828
+ $mol_test({
1829
+ 'fresh'() {
1830
+ const clock = new $hyoo_crowd_clock;
1831
+ clock.see_peer('b_33', 1);
1832
+ clock.see_peer('m_66', 2);
1833
+ $mol_assert_ok(clock.fresh('m_66', 3));
1834
+ $mol_assert_ok(clock.fresh('x_99', 1));
1835
+ $mol_assert_not(clock.fresh('m_66', 1));
1836
+ },
1837
+ 'fork'() {
1838
+ const left = new $hyoo_crowd_clock;
1839
+ left.see_peer('b_33', 1);
1840
+ left.see_peer('m_66', 2);
1841
+ const right = new $hyoo_crowd_clock(left);
1842
+ $mol_assert_equal(right.last_time, 2);
1843
+ $mol_assert_like([...right], [
1844
+ ['b_33', 1],
1845
+ ['m_66', 2],
1846
+ ]);
1847
+ },
1848
+ 'generate'() {
1849
+ const clock = new $hyoo_crowd_clock;
1850
+ clock.see_peer('b_33', $mol_int62_min + 1);
1851
+ clock.see_peer('m_66', $mol_int62_min + 2);
1852
+ const now = clock.now();
1853
+ const time1 = clock.tick('b_33');
1854
+ $mol_assert_like(time1, now);
1855
+ $mol_assert_like(clock.last_time, now);
1856
+ clock.see_peer('m_66', clock.now() + 10);
1857
+ const time2 = clock.tick('m_66');
1858
+ $mol_assert_like(time2, now + 11);
1859
+ $mol_assert_like(clock.last_time, now + 11);
1860
+ },
1861
+ 'ahead'() {
1862
+ const clock1 = new $hyoo_crowd_clock;
1863
+ clock1.see_peer('b_33', 1);
1864
+ clock1.see_peer('m_66', 2);
1865
+ const clock2 = new $hyoo_crowd_clock;
1866
+ clock2.see_peer('b_33', 1);
1867
+ clock2.see_peer('x_99', 2);
1868
+ const clock3 = new $hyoo_crowd_clock;
1869
+ clock3.see_peer('b_33', 1);
1870
+ clock3.see_peer('m_66', 2);
1871
+ clock3.see_peer('x_99', 2);
1872
+ $mol_assert_ok(clock1.ahead(clock2));
1873
+ $mol_assert_ok(clock2.ahead(clock1));
1874
+ $mol_assert_ok(clock3.ahead(clock1));
1875
+ $mol_assert_ok(clock3.ahead(clock2));
1876
+ $mol_assert_not(clock1.ahead(clock3));
1877
+ $mol_assert_not(clock2.ahead(clock3));
1878
+ },
1879
+ 'bin'() {
1880
+ const clocks1 = [new $hyoo_crowd_clock, new $hyoo_crowd_clock];
1881
+ clocks1[$hyoo_crowd_unit_group.auth].see_peer('b_33', 1);
1882
+ clocks1[$hyoo_crowd_unit_group.data].see_peer('b_33', 2);
1883
+ const bin = $hyoo_crowd_clock_bin.from('2_b', clocks1);
1884
+ $mol_assert_like(bin.land(), '2_b');
1885
+ const clocks2 = [new $hyoo_crowd_clock, new $hyoo_crowd_clock];
1886
+ clocks2[$hyoo_crowd_unit_group.auth].see_bin(bin, $hyoo_crowd_unit_group.auth);
1887
+ clocks2[$hyoo_crowd_unit_group.data].see_bin(bin, $hyoo_crowd_unit_group.data);
1888
+ $mol_assert_like(clocks2.map(clock => new Map(clock)), [
1889
+ new Map([
1890
+ ['b_33', 1],
1891
+ ]),
1892
+ new Map([
1893
+ ['b_33', 2],
1894
+ ]),
1895
+ ]);
1896
+ },
1897
+ });
1898
+ })($ || ($ = {}));
1899
+ //hyoo/crowd/clock/clock.test.ts
1900
+ ;
1901
+ "use strict";
1902
+ var $;
1903
+ (function ($) {
1904
+ $mol_test({
1905
+ 'const returns stored value'() {
1906
+ const foo = { bar: $mol_const(Math.random()) };
1907
+ $mol_assert_equal(foo.bar(), foo.bar());
1908
+ $mol_assert_equal(foo.bar(), foo.bar['()']);
1909
+ },
1910
+ });
1911
+ })($ || ($ = {}));
1912
+ //mol/const/const.test.ts
1913
+ ;
1914
+ "use strict";
1915
+ var $;
1916
+ (function ($) {
1917
+ function $mol_reconcile({ prev, from, to, next, equal, drop, insert, update, }) {
1918
+ if (!update)
1919
+ update = (next, prev, lead) => insert(next, drop(prev, lead));
1920
+ let p = from;
1921
+ let n = 0;
1922
+ let lead = p ? prev[p - 1] : null;
1923
+ if (to > prev.length)
1924
+ $mol_fail(new RangeError(`To(${to}) greater then length(${prev.length})`));
1925
+ if (from > to)
1926
+ $mol_fail(new RangeError(`From(${to}) greater then to(${to})`));
1927
+ while (p < to || n < next.length) {
1928
+ if (p < to && n < next.length && equal(next[n], prev[p])) {
1929
+ lead = prev[p];
1930
+ ++p;
1931
+ ++n;
1932
+ }
1933
+ else if (next.length - n > to - p) {
1934
+ lead = insert(next[n], lead);
1935
+ ++n;
1936
+ }
1937
+ else if (next.length - n < to - p) {
1938
+ lead = drop(prev[p], lead);
1939
+ ++p;
1940
+ }
1941
+ else {
1942
+ lead = update(next[n], prev[p], lead);
1943
+ ++p;
1944
+ ++n;
1945
+ }
1946
+ }
1947
+ }
1948
+ $.$mol_reconcile = $mol_reconcile;
1949
+ })($ || ($ = {}));
1950
+ //mol/reconcile/reconcile.ts
1951
+ ;
1952
+ "use strict";
1953
+ var $;
1954
+ (function ($) {
1955
+ $mol_test({
1956
+ 'same list'() {
1957
+ const list = $mol_jsx("body", null,
1958
+ $mol_jsx("p", { "data-rev": "old" }, "a"),
1959
+ $mol_jsx("p", { "data-rev": "old" }, "b"),
1960
+ $mol_jsx("p", { "data-rev": "old" }, "c"));
1961
+ $mol_reconcile({
1962
+ prev: [...list.children],
1963
+ from: 0,
1964
+ to: 3,
1965
+ next: 'abc',
1966
+ equal: (next, prev) => prev.textContent === next,
1967
+ drop: (prev, lead) => list.removeChild(prev),
1968
+ insert: (next, lead) => list.insertBefore($mol_jsx("p", { "data-rev": "new" }, next), lead ? lead.nextSibling : list.firstChild),
1969
+ update: (next, prev, lead) => {
1970
+ prev.textContent = next;
1971
+ prev.setAttribute('data-rev', 'up');
1972
+ return prev;
1973
+ },
1974
+ });
1975
+ $mol_assert_dom(list, $mol_jsx("body", null,
1976
+ $mol_jsx("p", { "data-rev": "old" }, "a"),
1977
+ $mol_jsx("p", { "data-rev": "old" }, "b"),
1978
+ $mol_jsx("p", { "data-rev": "old" }, "c")));
1979
+ },
1980
+ 'insert items'() {
1981
+ const list = $mol_jsx("body", null,
1982
+ $mol_jsx("p", { "data-rev": "old" }, "a"),
1983
+ $mol_jsx("p", { "data-rev": "old" }, "b"),
1984
+ $mol_jsx("p", { "data-rev": "old" }, "c"),
1985
+ $mol_jsx("p", { "data-rev": "old" }, "d"));
1986
+ $mol_reconcile({
1987
+ prev: [...list.children],
1988
+ from: 1,
1989
+ to: 3,
1990
+ next: 'bXYc',
1991
+ equal: (next, prev) => prev.textContent === next,
1992
+ drop: (prev, lead) => list.removeChild(prev),
1993
+ insert: (next, lead) => list.insertBefore($mol_jsx("p", { "data-rev": "new" }, next), lead ? lead.nextSibling : list.firstChild),
1994
+ update: (next, prev, lead) => {
1995
+ prev.textContent = next;
1996
+ prev.setAttribute('data-rev', 'up');
1997
+ return prev;
1998
+ },
1999
+ });
2000
+ $mol_assert_dom(list, $mol_jsx("body", null,
2001
+ $mol_jsx("p", { "data-rev": "old" }, "a"),
2002
+ $mol_jsx("p", { "data-rev": "old" }, "b"),
2003
+ $mol_jsx("p", { "data-rev": "new" }, "X"),
2004
+ $mol_jsx("p", { "data-rev": "new" }, "Y"),
2005
+ $mol_jsx("p", { "data-rev": "old" }, "c"),
2006
+ $mol_jsx("p", { "data-rev": "old" }, "d")));
2007
+ },
2008
+ 'split item'() {
2009
+ const list = $mol_jsx("body", null,
2010
+ $mol_jsx("p", { "data-rev": "old" }, "a"),
2011
+ $mol_jsx("p", { "data-rev": "old" }, "bc"),
2012
+ $mol_jsx("p", { "data-rev": "old" }, "d"));
2013
+ $mol_reconcile({
2014
+ prev: [...list.children],
2015
+ from: 0,
2016
+ to: 3,
2017
+ next: 'abcd',
2018
+ equal: (next, prev) => prev.textContent === next,
2019
+ drop: (prev, lead) => list.removeChild(prev),
2020
+ insert: (next, lead) => list.insertBefore($mol_jsx("p", { "data-rev": "new" }, next), lead ? lead.nextSibling : list.firstChild),
2021
+ update: (next, prev, lead) => {
2022
+ prev.textContent = next;
2023
+ prev.setAttribute('data-rev', 'up');
2024
+ return prev;
2025
+ },
2026
+ });
2027
+ $mol_assert_dom(list, $mol_jsx("body", null,
2028
+ $mol_jsx("p", { "data-rev": "old" }, "a"),
2029
+ $mol_jsx("p", { "data-rev": "new" }, "b"),
2030
+ $mol_jsx("p", { "data-rev": "up" }, "c"),
2031
+ $mol_jsx("p", { "data-rev": "old" }, "d")));
2032
+ },
2033
+ 'drop items'() {
2034
+ const list = $mol_jsx("body", null,
2035
+ $mol_jsx("p", { "data-rev": "old" }, "A"),
2036
+ $mol_jsx("p", { "data-rev": "old" }, "B"),
2037
+ $mol_jsx("p", { "data-rev": "old" }, "x"),
2038
+ $mol_jsx("p", { "data-rev": "old" }, "y"),
2039
+ $mol_jsx("p", { "data-rev": "old" }, "C"),
2040
+ $mol_jsx("p", { "data-rev": "old" }, "D"));
2041
+ $mol_reconcile({
2042
+ prev: [...list.children],
2043
+ from: 1,
2044
+ to: 5,
2045
+ next: 'BC',
2046
+ equal: (next, prev) => prev.textContent === next,
2047
+ drop: (prev, lead) => list.removeChild(prev),
2048
+ insert: (next, lead) => list.insertBefore($mol_jsx("p", { "data-rev": "new" }, next), lead ? lead.nextSibling : list.firstChild),
2049
+ update: (next, prev, lead) => {
2050
+ prev.textContent = next;
2051
+ prev.setAttribute('data-rev', 'up');
2052
+ return prev;
2053
+ },
2054
+ });
2055
+ $mol_assert_dom(list, $mol_jsx("body", null,
2056
+ $mol_jsx("p", { "data-rev": "old" }, "A"),
2057
+ $mol_jsx("p", { "data-rev": "old" }, "B"),
2058
+ $mol_jsx("p", { "data-rev": "old" }, "C"),
2059
+ $mol_jsx("p", { "data-rev": "old" }, "D")));
2060
+ },
2061
+ 'update items'() {
2062
+ const list = $mol_jsx("body", null,
2063
+ $mol_jsx("p", { "data-rev": "old" }, "a"),
2064
+ $mol_jsx("p", { "data-rev": "old" }, "B"),
2065
+ $mol_jsx("p", { "data-rev": "old" }, "C"),
2066
+ $mol_jsx("p", { "data-rev": "old" }, "d"));
2067
+ $mol_reconcile({
2068
+ prev: [...list.children],
2069
+ from: 1,
2070
+ to: 3,
2071
+ next: 'XY',
2072
+ equal: (next, prev) => prev.textContent === next,
2073
+ drop: (prev, lead) => list.removeChild(prev),
2074
+ insert: (next, lead) => list.insertBefore($mol_jsx("p", { "data-rev": "new" }, next), lead ? lead.nextSibling : list.firstChild),
2075
+ update: (next, prev, lead) => {
2076
+ prev.textContent = next;
2077
+ prev.setAttribute('data-rev', 'up');
2078
+ return prev;
2079
+ },
2080
+ });
2081
+ $mol_assert_dom(list, $mol_jsx("body", null,
2082
+ $mol_jsx("p", { "data-rev": "old" }, "a"),
2083
+ $mol_jsx("p", { "data-rev": "up" }, "X"),
2084
+ $mol_jsx("p", { "data-rev": "up" }, "Y"),
2085
+ $mol_jsx("p", { "data-rev": "old" }, "d")));
2086
+ },
2087
+ });
2088
+ })($ || ($ = {}));
2089
+ //mol/reconcile/reconcile.test.tsx
2090
+ ;
2091
+ "use strict";
2092
+ //mol/type/merge/merge.ts
2093
+ ;
2094
+ "use strict";
2095
+ //mol/type/merge/merge.test.ts
2096
+ ;
2097
+ "use strict";
2098
+ //mol/type/intersect/intersect.ts
2099
+ ;
2100
+ "use strict";
2101
+ //mol/type/intersect/intersect.test.ts
2102
+ ;
2103
+ "use strict";
2104
+ //mol/type/override/override.ts
2105
+ ;
2106
+ "use strict";
2107
+ //mol/unicode/unicode.ts
2108
+ ;
2109
+ "use strict";
2110
+ var $;
2111
+ (function ($) {
2112
+ class $mol_regexp extends RegExp {
2113
+ groups;
2114
+ constructor(source, flags = 'gsu', groups = []) {
2115
+ super(source, flags);
2116
+ this.groups = groups;
2117
+ }
2118
+ *[Symbol.matchAll](str) {
2119
+ const index = this.lastIndex;
2120
+ this.lastIndex = 0;
2121
+ try {
2122
+ while (this.lastIndex < str.length) {
2123
+ const found = this.exec(str);
2124
+ if (!found)
2125
+ break;
2126
+ yield found;
2127
+ }
2128
+ }
2129
+ finally {
2130
+ this.lastIndex = index;
2131
+ }
2132
+ }
2133
+ [Symbol.match](str) {
2134
+ const res = [...this[Symbol.matchAll](str)].filter(r => r.groups).map(r => r[0]);
2135
+ if (!res.length)
2136
+ return null;
2137
+ return res;
2138
+ }
2139
+ [Symbol.split](str) {
2140
+ const res = [];
2141
+ let token_last = null;
2142
+ for (let token of this[Symbol.matchAll](str)) {
2143
+ if (token.groups && (token_last ? token_last.groups : true))
2144
+ res.push('');
2145
+ res.push(token[0]);
2146
+ token_last = token;
2147
+ }
2148
+ if (!res.length)
2149
+ res.push('');
2150
+ return res;
2151
+ }
2152
+ test(str) {
2153
+ return Boolean(str.match(this));
2154
+ }
2155
+ exec(str) {
2156
+ const from = this.lastIndex;
2157
+ if (from >= str.length)
2158
+ return null;
2159
+ const res = super.exec(str);
2160
+ if (res === null) {
2161
+ this.lastIndex = str.length;
2162
+ if (!str)
2163
+ return null;
2164
+ return Object.assign([str.slice(from)], {
2165
+ index: from,
2166
+ input: str,
2167
+ });
2168
+ }
2169
+ if (from === this.lastIndex) {
2170
+ $mol_fail(new Error('Captured empty substring'));
2171
+ }
2172
+ const groups = {};
2173
+ const skipped = str.slice(from, this.lastIndex - res[0].length);
2174
+ if (skipped) {
2175
+ this.lastIndex = this.lastIndex - res[0].length;
2176
+ return Object.assign([skipped], {
2177
+ index: from,
2178
+ input: res.input,
2179
+ });
2180
+ }
2181
+ for (let i = 0; i < this.groups.length; ++i) {
2182
+ const group = this.groups[i];
2183
+ groups[group] = groups[group] || res[i + 1] || '';
2184
+ }
2185
+ return Object.assign(res, { groups });
2186
+ }
2187
+ generate(params) {
2188
+ return null;
2189
+ }
2190
+ get native() {
2191
+ return new RegExp(this.source, this.flags);
2192
+ }
2193
+ static repeat(source, min = 0, max = Number.POSITIVE_INFINITY) {
2194
+ const regexp = $mol_regexp.from(source);
2195
+ const upper = Number.isFinite(max) ? max : '';
2196
+ const str = `(?:${regexp.source}){${min},${upper}}?`;
2197
+ const regexp2 = new $mol_regexp(str, regexp.flags, regexp.groups);
2198
+ regexp2.generate = params => {
2199
+ const res = regexp.generate(params);
2200
+ if (res)
2201
+ return res;
2202
+ if (min > 0)
2203
+ return res;
2204
+ return '';
2205
+ };
2206
+ return regexp2;
2207
+ }
2208
+ static repeat_greedy(source, min = 0, max = Number.POSITIVE_INFINITY) {
2209
+ const regexp = $mol_regexp.from(source);
2210
+ const upper = Number.isFinite(max) ? max : '';
2211
+ const str = `(?:${regexp.source}){${min},${upper}}`;
2212
+ const regexp2 = new $mol_regexp(str, regexp.flags, regexp.groups);
2213
+ regexp2.generate = params => {
2214
+ const res = regexp.generate(params);
2215
+ if (res)
2216
+ return res;
2217
+ if (min > 0)
2218
+ return res;
2219
+ return '';
2220
+ };
2221
+ return regexp2;
2222
+ }
2223
+ static vary(sources) {
2224
+ const groups = [];
2225
+ const chunks = sources.map(source => {
2226
+ const regexp = $mol_regexp.from(source);
2227
+ groups.push(...regexp.groups);
2228
+ return regexp.source;
2229
+ });
2230
+ return new $mol_regexp(`(?:${chunks.join('|')})`, '', groups);
2231
+ }
2232
+ static optional(source) {
2233
+ return $mol_regexp.repeat_greedy(source, 0, 1);
2234
+ }
2235
+ static force_after(source) {
2236
+ const regexp = $mol_regexp.from(source);
2237
+ return new $mol_regexp(`(?=${regexp.source})`, regexp.flags, regexp.groups);
2238
+ }
2239
+ static forbid_after(source) {
2240
+ const regexp = $mol_regexp.from(source);
2241
+ return new $mol_regexp(`(?!${regexp.source})`, regexp.flags, regexp.groups);
2242
+ }
2243
+ static from(source, { ignoreCase, multiline } = {
2244
+ ignoreCase: false,
2245
+ multiline: false,
2246
+ }) {
2247
+ let flags = 'gsu';
2248
+ if (multiline)
2249
+ flags += 'm';
2250
+ if (ignoreCase)
2251
+ flags += 'i';
2252
+ if (typeof source === 'number') {
2253
+ const src = `\\u{${source.toString(16)}}`;
2254
+ const regexp = new $mol_regexp(src, flags);
2255
+ regexp.generate = () => src;
2256
+ return regexp;
2257
+ }
2258
+ if (typeof source === 'string') {
2259
+ const src = source.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
2260
+ const regexp = new $mol_regexp(src, flags);
2261
+ regexp.generate = () => source;
2262
+ return regexp;
2263
+ }
2264
+ else if (source instanceof $mol_regexp) {
2265
+ const regexp = new $mol_regexp(source.source, flags, source.groups);
2266
+ regexp.generate = params => source.generate(params);
2267
+ return regexp;
2268
+ }
2269
+ if (source instanceof RegExp) {
2270
+ const test = new RegExp('|' + source.source);
2271
+ const groups = Array.from({ length: test.exec('').length - 1 }, (_, i) => String(i + 1));
2272
+ const regexp = new $mol_regexp(source.source, source.flags, groups);
2273
+ regexp.generate = () => '';
2274
+ return regexp;
2275
+ }
2276
+ if (Array.isArray(source)) {
2277
+ const patterns = source.map(src => Array.isArray(src)
2278
+ ? $mol_regexp.optional(src)
2279
+ : $mol_regexp.from(src));
2280
+ const chunks = patterns.map(pattern => pattern.source);
2281
+ const groups = [];
2282
+ let index = 0;
2283
+ for (const pattern of patterns) {
2284
+ for (let group of pattern.groups) {
2285
+ if (Number(group) >= 0) {
2286
+ groups.push(String(index++));
2287
+ }
2288
+ else {
2289
+ groups.push(group);
2290
+ }
2291
+ }
2292
+ }
2293
+ const regexp = new $mol_regexp(chunks.join(''), flags, groups);
2294
+ regexp.generate = params => {
2295
+ let res = '';
2296
+ for (const pattern of patterns) {
2297
+ let sub = pattern.generate(params);
2298
+ if (sub === null)
2299
+ return '';
2300
+ res += sub;
2301
+ }
2302
+ return res;
2303
+ };
2304
+ return regexp;
2305
+ }
2306
+ else {
2307
+ const groups = [];
2308
+ const chunks = Object.keys(source).map(name => {
2309
+ groups.push(name);
2310
+ const regexp = $mol_regexp.from(source[name]);
2311
+ groups.push(...regexp.groups);
2312
+ return `(${regexp.source})`;
2313
+ });
2314
+ const regexp = new $mol_regexp(`(?:${chunks.join('|')})`, flags, groups);
2315
+ const validator = new RegExp('^' + regexp.source + '$', flags);
2316
+ regexp.generate = (params) => {
2317
+ for (let option in source) {
2318
+ if (option in params) {
2319
+ if (typeof params[option] === 'boolean') {
2320
+ if (!params[option])
2321
+ continue;
2322
+ }
2323
+ else {
2324
+ const str = String(params[option]);
2325
+ if (str.match(validator))
2326
+ return str;
2327
+ $mol_fail(new Error(`Wrong param: ${option}=${str}`));
2328
+ }
2329
+ }
2330
+ else {
2331
+ if (typeof source[option] !== 'object')
2332
+ continue;
2333
+ }
2334
+ const res = $mol_regexp.from(source[option]).generate(params);
2335
+ if (res)
2336
+ return res;
2337
+ }
2338
+ return null;
2339
+ };
2340
+ return regexp;
2341
+ }
2342
+ }
2343
+ static unicode_only(...category) {
2344
+ return new $mol_regexp(`\\p{${category.join('=')}}`);
2345
+ }
2346
+ static unicode_except(...category) {
2347
+ return new $mol_regexp(`\\P{${category.join('=')}}`);
2348
+ }
2349
+ static char_range(from, to) {
2350
+ return new $mol_regexp(`${$mol_regexp.from(from).source}-${$mol_regexp.from(to).source}`);
2351
+ }
2352
+ static char_only(...allowed) {
2353
+ const regexp = allowed.map(f => $mol_regexp.from(f).source).join('');
2354
+ return new $mol_regexp(`[${regexp}]`);
2355
+ }
2356
+ static char_except(...forbidden) {
2357
+ const regexp = forbidden.map(f => $mol_regexp.from(f).source).join('');
2358
+ return new $mol_regexp(`[^${regexp}]`);
2359
+ }
2360
+ static decimal_only = $mol_regexp.from(/\d/gsu);
2361
+ static decimal_except = $mol_regexp.from(/\D/gsu);
2362
+ static latin_only = $mol_regexp.from(/\w/gsu);
2363
+ static latin_except = $mol_regexp.from(/\W/gsu);
2364
+ static space_only = $mol_regexp.from(/\s/gsu);
2365
+ static space_except = $mol_regexp.from(/\S/gsu);
2366
+ static word_break_only = $mol_regexp.from(/\b/gsu);
2367
+ static word_break_except = $mol_regexp.from(/\B/gsu);
2368
+ static tab = $mol_regexp.from(/\t/gsu);
2369
+ static slash_back = $mol_regexp.from(/\\/gsu);
2370
+ static nul = $mol_regexp.from(/\0/gsu);
2371
+ static char_any = $mol_regexp.from(/./gsu);
2372
+ static begin = $mol_regexp.from(/^/gsu);
2373
+ static end = $mol_regexp.from(/$/gsu);
2374
+ static or = $mol_regexp.from(/|/gsu);
2375
+ static line_end = $mol_regexp.from({
2376
+ win_end: [['\r'], '\n'],
2377
+ mac_end: '\r',
2378
+ });
2379
+ }
2380
+ $.$mol_regexp = $mol_regexp;
2381
+ })($ || ($ = {}));
2382
+ //mol/regexp/regexp.ts
2383
+ ;
2384
+ "use strict";
2385
+ var $;
2386
+ (function ($) {
2387
+ $mol_test({
2388
+ 'escape'() {
2389
+ const specials = $mol_regexp.from('.*+?^${}()|[]\\');
2390
+ $mol_assert_equal(specials.source, '\\.\\*\\+\\?\\^\\$\\{\\}\\(\\)\\|\\[\\]\\\\');
2391
+ },
2392
+ 'char code'() {
2393
+ const space = $mol_regexp.from(32);
2394
+ $mol_assert_like(' '.match(space), [' ']);
2395
+ },
2396
+ 'repeat fixed'() {
2397
+ const { repeat, decimal_only: digit } = $mol_regexp;
2398
+ const year = repeat(digit, 4, 4);
2399
+ $mol_assert_like('#2020#'.match(year), ['2020']);
2400
+ },
2401
+ 'greedy repeat'() {
2402
+ const { repeat, repeat_greedy, latin_only: letter } = $mol_regexp;
2403
+ $mol_assert_like('abc'.match(repeat(letter, 1, 2)), ['a', 'b', 'c']);
2404
+ $mol_assert_like('abc'.match(repeat_greedy(letter, 1, 2)), ['ab', 'c']);
2405
+ },
2406
+ 'repeat range'() {
2407
+ const { repeat_greedy, decimal_only: digit } = $mol_regexp;
2408
+ const year = repeat_greedy(digit, 2, 4);
2409
+ $mol_assert_like('#2#'.match(year), null);
2410
+ $mol_assert_like('#20#'.match(year), ['20']);
2411
+ $mol_assert_like('#2020#'.match(year), ['2020']);
2412
+ $mol_assert_like('#20201#'.match(year), ['2020']);
2413
+ },
2414
+ 'repeat from'() {
2415
+ const { repeat_greedy, latin_only: letter } = $mol_regexp;
2416
+ const name = repeat_greedy(letter, 2);
2417
+ $mol_assert_like('##'.match(name), null);
2418
+ $mol_assert_like('#a#'.match(name), null);
2419
+ $mol_assert_like('#ab#'.match(name), ['ab']);
2420
+ $mol_assert_like('#abc#'.match(name), ['abc']);
2421
+ },
2422
+ 'from string'() {
2423
+ const regexp = $mol_regexp.from('[\\d]');
2424
+ $mol_assert_equal(regexp.source, '\\[\\\\d\\]');
2425
+ $mol_assert_equal(regexp.flags, 'gsu');
2426
+ },
2427
+ 'from regexp'() {
2428
+ const regexp = $mol_regexp.from(/[\d]/i);
2429
+ $mol_assert_equal(regexp.source, '[\\d]');
2430
+ $mol_assert_equal(regexp.flags, 'i');
2431
+ },
2432
+ 'split'() {
2433
+ const regexp = $mol_regexp.from(';');
2434
+ $mol_assert_like('aaa;bbb;ccc'.split(regexp), ['aaa', ';', 'bbb', ';', 'ccc']);
2435
+ $mol_assert_like('aaa;;ccc'.split(regexp), ['aaa', ';', '', ';', 'ccc']);
2436
+ $mol_assert_like('aaa'.split(regexp), ['aaa']);
2437
+ $mol_assert_like(''.split(regexp), ['']);
2438
+ },
2439
+ 'test for matching'() {
2440
+ const regexp = $mol_regexp.from('foo');
2441
+ $mol_assert_like(regexp.test(''), false);
2442
+ $mol_assert_like(regexp.test('fo'), false);
2443
+ $mol_assert_like(regexp.test('foo'), true);
2444
+ $mol_assert_like(regexp.test('foobar'), true);
2445
+ $mol_assert_like(regexp.test('barfoo'), true);
2446
+ },
2447
+ 'case ignoring'() {
2448
+ const xxx = $mol_regexp.from('x', { ignoreCase: true });
2449
+ $mol_assert_like(xxx.flags, 'gisu');
2450
+ $mol_assert_like(xxx.exec('xx')[0], 'x');
2451
+ $mol_assert_like(xxx.exec('XX')[0], 'X');
2452
+ },
2453
+ 'multiline mode'() {
2454
+ const { end, from } = $mol_regexp;
2455
+ const xxx = from(['x', end], { multiline: true });
2456
+ $mol_assert_like(xxx.exec('x\ny')[0], 'x');
2457
+ $mol_assert_like(xxx.flags, 'gmsu');
2458
+ },
2459
+ 'flags override'() {
2460
+ const triplet = $mol_regexp.from($mol_regexp.from(/.../, { ignoreCase: true }), { multiline: true });
2461
+ $mol_assert_like(triplet.toString(), '/.../gmsu');
2462
+ },
2463
+ 'sequence'() {
2464
+ const { begin, end, decimal_only: digit, repeat, from } = $mol_regexp;
2465
+ const year = repeat(digit, 4, 4);
2466
+ const dash = '-';
2467
+ const month = repeat(digit, 2, 2);
2468
+ const day = repeat(digit, 2, 2);
2469
+ const date = from([begin, year, dash, month, dash, day, end]);
2470
+ $mol_assert_like(date.exec('2020-01-02')[0], '2020-01-02');
2471
+ },
2472
+ 'optional'() {
2473
+ const name = $mol_regexp.from(['A', ['4']]);
2474
+ $mol_assert_equal('AB'.match(name)[0], 'A');
2475
+ $mol_assert_equal('A4'.match(name)[0], 'A4');
2476
+ },
2477
+ 'anon variants'() {
2478
+ const name = $mol_regexp.from(['A', $mol_regexp.vary(['4', '5'])]);
2479
+ $mol_assert_equal('AB'.match(name), null);
2480
+ $mol_assert_equal('A4'.match(name)[0], 'A4');
2481
+ $mol_assert_equal('A5'.match(name)[0], 'A5');
2482
+ },
2483
+ 'only groups'() {
2484
+ const regexp = $mol_regexp.from({ dog: '@' });
2485
+ $mol_assert_like([...'#'.matchAll(regexp)][0].groups, undefined);
2486
+ $mol_assert_like([...'@'.matchAll(regexp)][0].groups, { dog: '@' });
2487
+ },
2488
+ 'catch skipped'() {
2489
+ const regexp = $mol_regexp.from(/(@)(\d?)/g);
2490
+ $mol_assert_like([...'[[@]]'.matchAll(regexp)].map(f => [...f]), [
2491
+ ['[['],
2492
+ ['@', '@', ''],
2493
+ [']]'],
2494
+ ]);
2495
+ },
2496
+ 'enum variants'() {
2497
+ let Sex;
2498
+ (function (Sex) {
2499
+ Sex["male"] = "male";
2500
+ Sex["female"] = "female";
2501
+ })(Sex || (Sex = {}));
2502
+ const sexism = $mol_regexp.from(Sex);
2503
+ $mol_assert_like([...''.matchAll(sexism)].length, 0);
2504
+ $mol_assert_like([...'trans'.matchAll(sexism)][0].groups, undefined);
2505
+ $mol_assert_like([...'male'.matchAll(sexism)][0].groups, { male: 'male', female: '' });
2506
+ $mol_assert_like([...'female'.matchAll(sexism)][0].groups, { male: '', female: 'female' });
2507
+ },
2508
+ 'recursive only groups'() {
2509
+ let Sex;
2510
+ (function (Sex) {
2511
+ Sex["male"] = "male";
2512
+ Sex["female"] = "female";
2513
+ })(Sex || (Sex = {}));
2514
+ const sexism = $mol_regexp.from({ Sex });
2515
+ $mol_assert_like([...''.matchAll(sexism)].length, 0);
2516
+ $mol_assert_like([...'male'.matchAll(sexism)][0].groups, { Sex: 'male', male: 'male', female: '' });
2517
+ $mol_assert_like([...'female'.matchAll(sexism)][0].groups, { Sex: 'female', male: '', female: 'female' });
2518
+ },
2519
+ 'sequence with groups'() {
2520
+ const { begin, end, decimal_only: digit, repeat, from } = $mol_regexp;
2521
+ const year = repeat(digit, 4, 4);
2522
+ const dash = '-';
2523
+ const month = repeat(digit, 2, 2);
2524
+ const day = repeat(digit, 2, 2);
2525
+ const regexp = from([begin, { year }, dash, { month }, dash, { day }, end]);
2526
+ const found = [...'2020-01-02'.matchAll(regexp)];
2527
+ $mol_assert_like(found[0].groups, {
2528
+ year: '2020',
2529
+ month: '01',
2530
+ day: '02',
2531
+ });
2532
+ },
2533
+ 'sequence with groups of mixed type'() {
2534
+ const prefix = '/';
2535
+ const postfix = '/';
2536
+ const regexp = $mol_regexp.from([{ prefix }, /(\w+)/, { postfix }, /([gumi]*)/]);
2537
+ $mol_assert_like([...'/foo/mi'.matchAll(regexp)], [
2538
+ Object.assign(["/foo/mi", "/", "foo", "/", "mi"], {
2539
+ groups: {
2540
+ prefix: '/',
2541
+ postfix: '/',
2542
+ },
2543
+ index: 0,
2544
+ input: "/",
2545
+ }),
2546
+ ]);
2547
+ },
2548
+ 'recursive sequence with groups'() {
2549
+ const { begin, end, decimal_only: digit, repeat, from } = $mol_regexp;
2550
+ const year = repeat(digit, 4, 4);
2551
+ const dash = '-';
2552
+ const month = repeat(digit, 2, 2);
2553
+ const day = repeat(digit, 2, 2);
2554
+ const regexp = from([
2555
+ begin, { date: [{ year }, dash, { month }] }, dash, { day }, end
2556
+ ]);
2557
+ const found = [...'2020-01-02'.matchAll(regexp)];
2558
+ $mol_assert_like(found[0].groups, {
2559
+ date: '2020-01',
2560
+ year: '2020',
2561
+ month: '01',
2562
+ day: '02',
2563
+ });
2564
+ },
2565
+ 'parse multiple'() {
2566
+ const { decimal_only: digit, from } = $mol_regexp;
2567
+ const regexp = from({ digit });
2568
+ $mol_assert_like([...'123'.matchAll(regexp)].map(f => f.groups), [
2569
+ { digit: '1' },
2570
+ { digit: '2' },
2571
+ { digit: '3' },
2572
+ ]);
2573
+ },
2574
+ 'named variants'() {
2575
+ const { begin, or, end, from } = $mol_regexp;
2576
+ const sexism = from([
2577
+ begin, 'sex = ', { sex: ['male', or, 'female'] }, end
2578
+ ]);
2579
+ $mol_assert_like([...'sex = male'.matchAll(sexism)][0].groups, { sex: 'male' });
2580
+ $mol_assert_like([...'sex = female'.matchAll(sexism)][0].groups, { sex: 'female' });
2581
+ $mol_assert_like([...'sex = malefemale'.matchAll(sexism)][0].groups, undefined);
2582
+ },
2583
+ 'force after'() {
2584
+ const { latin_only: letter, force_after, from } = $mol_regexp;
2585
+ const regexp = from([letter, force_after('.')]);
2586
+ $mol_assert_like('x.'.match(regexp), ['x']);
2587
+ $mol_assert_like('x,'.match(regexp), null);
2588
+ },
2589
+ 'forbid after'() {
2590
+ const { latin_only: letter, forbid_after, from } = $mol_regexp;
2591
+ const regexp = from([letter, forbid_after('.')]);
2592
+ $mol_assert_like('x.'.match(regexp), null);
2593
+ $mol_assert_like('x,'.match(regexp), ['x']);
2594
+ },
2595
+ 'char except'() {
2596
+ const { char_except, latin_only, tab } = $mol_regexp;
2597
+ const name = char_except(latin_only, tab);
2598
+ $mol_assert_like('a'.match(name), null);
2599
+ $mol_assert_like('\t'.match(name), null);
2600
+ $mol_assert_like('('.match(name), ['(']);
2601
+ },
2602
+ 'unicode only'() {
2603
+ const { unicode_only, from } = $mol_regexp;
2604
+ const name = from([
2605
+ unicode_only('Script', 'Cyrillic'),
2606
+ unicode_only('Hex_Digit'),
2607
+ ]);
2608
+ $mol_assert_like('FF'.match(name), null);
2609
+ $mol_assert_like('ФG'.match(name), null);
2610
+ $mol_assert_like('ФF'.match(name), ['ФF']);
2611
+ },
2612
+ 'generate by optional with inner group'() {
2613
+ const { begin, end, from } = $mol_regexp;
2614
+ const animals = from([begin, '#', ['^', { dog: '@' }], end]);
2615
+ $mol_assert_equal(animals.generate({}), '#');
2616
+ $mol_assert_equal(animals.generate({ dog: false }), '#');
2617
+ $mol_assert_equal(animals.generate({ dog: true }), '#^@');
2618
+ $mol_assert_fail(() => animals.generate({ dog: '$' }), 'Wrong param: dog=$');
2619
+ },
2620
+ 'generate by optional with inner group with variants'() {
2621
+ const { begin, end, from } = $mol_regexp;
2622
+ const animals = from([begin, '#', ['^', { animal: { dog: '@', fox: '&' } }], end]);
2623
+ $mol_assert_equal(animals.generate({}), '#');
2624
+ $mol_assert_equal(animals.generate({ dog: true }), '#^@');
2625
+ $mol_assert_equal(animals.generate({ fox: true }), '#^&');
2626
+ $mol_assert_fail(() => animals.generate({ dog: '$' }), 'Wrong param: dog=$');
2627
+ },
2628
+ 'complex example'() {
2629
+ const { begin, end, char_only, char_range, latin_only, slash_back, repeat_greedy, from, } = $mol_regexp;
2630
+ const atom_char = char_only(latin_only, "!#$%&'*+/=?^`{|}~-");
2631
+ const atom = repeat_greedy(atom_char, 1);
2632
+ const dot_atom = from([atom, repeat_greedy(['.', atom])]);
2633
+ const name_letter = char_only(char_range(0x01, 0x08), 0x0b, 0x0c, char_range(0x0e, 0x1f), 0x21, char_range(0x23, 0x5b), char_range(0x5d, 0x7f));
2634
+ const quoted_pair = from([
2635
+ slash_back,
2636
+ char_only(char_range(0x01, 0x09), 0x0b, 0x0c, char_range(0x0e, 0x7f))
2637
+ ]);
2638
+ const name = repeat_greedy({ name_letter, quoted_pair });
2639
+ const quoted_name = from(['"', { name }, '"']);
2640
+ const local_part = from({ dot_atom, quoted_name });
2641
+ const domain = dot_atom;
2642
+ const mail = from([begin, local_part, '@', { domain }, end]);
2643
+ $mol_assert_equal('foo..bar@example.org'.match(mail), null);
2644
+ $mol_assert_equal('foo..bar"@example.org'.match(mail), null);
2645
+ $mol_assert_like([...'foo.bar@example.org'.matchAll(mail)][0].groups, {
2646
+ dot_atom: "foo.bar",
2647
+ quoted_name: "",
2648
+ name: "",
2649
+ name_letter: "",
2650
+ quoted_pair: "",
2651
+ domain: "example.org",
2652
+ });
2653
+ $mol_assert_like([...'"foo..bar"@example.org'.matchAll(mail)][0].groups, {
2654
+ dot_atom: "",
2655
+ quoted_name: '"foo..bar"',
2656
+ name: "foo..bar",
2657
+ name_letter: "r",
2658
+ quoted_pair: "",
2659
+ domain: "example.org",
2660
+ });
2661
+ $mol_assert_equal(mail.generate({ dot_atom: 'foo.bar', domain: 'example.org' }), 'foo.bar@example.org');
2662
+ $mol_assert_equal(mail.generate({ name: 'foo..bar', domain: 'example.org' }), '"foo..bar"@example.org');
2663
+ $mol_assert_fail(() => mail.generate({ dot_atom: 'foo..bar', domain: 'example.org' }), 'Wrong param: dot_atom=foo..bar');
2664
+ },
2665
+ });
2666
+ })($ || ($ = {}));
2667
+ //mol/regexp/regexp.test.ts
2668
+ ;
2669
+ "use strict";
2670
+ var $;
2671
+ (function ($) {
2672
+ const { unicode_only, line_end, tab, repeat_greedy, optional, forbid_after, force_after, char_only, char_except } = $mol_regexp;
2673
+ $.$hyoo_crowd_tokenizer = $mol_regexp.from({
2674
+ token: {
2675
+ 'line-break': line_end,
2676
+ 'indents': repeat_greedy(tab, 1),
2677
+ 'emoji': [
2678
+ unicode_only('Extended_Pictographic'),
2679
+ optional(unicode_only('Emoji_Modifier')),
2680
+ repeat_greedy([
2681
+ unicode_only('Emoji_Component'),
2682
+ unicode_only('Extended_Pictographic'),
2683
+ optional(unicode_only('Emoji_Modifier')),
2684
+ ]),
2685
+ ],
2686
+ 'link': /\b(https?:\/\/[^\s,.;:!?")]+(?:[,.;:!?")][^\s,.;:!?")]+)+)/,
2687
+ 'Word': [
2688
+ [
2689
+ forbid_after(line_end),
2690
+ unicode_only('White_Space'),
2691
+ ],
2692
+ repeat_greedy(char_only([
2693
+ unicode_only('General_Category', 'Uppercase_Letter'),
2694
+ unicode_only('Diacritic'),
2695
+ unicode_only('General_Category', 'Number'),
2696
+ ]), 1),
2697
+ repeat_greedy(char_only([
2698
+ unicode_only('General_Category', 'Lowercase_Letter'),
2699
+ unicode_only('Diacritic'),
2700
+ unicode_only('General_Category', 'Number'),
2701
+ ])),
2702
+ ],
2703
+ 'word': [
2704
+ [
2705
+ forbid_after(line_end),
2706
+ unicode_only('White_Space'),
2707
+ ],
2708
+ repeat_greedy(char_only([
2709
+ unicode_only('General_Category', 'Lowercase_Letter'),
2710
+ unicode_only('Diacritic'),
2711
+ unicode_only('General_Category', 'Number'),
2712
+ ]), 1),
2713
+ ],
2714
+ 'spaces': [
2715
+ forbid_after(line_end),
2716
+ repeat_greedy(unicode_only('White_Space'), 1),
2717
+ force_after(unicode_only('White_Space')),
2718
+ ],
2719
+ 'space': [
2720
+ forbid_after(line_end),
2721
+ unicode_only('White_Space'),
2722
+ forbid_after([
2723
+ unicode_only('White_Space'),
2724
+ unicode_only('General_Category', 'Uppercase_Letter'),
2725
+ unicode_only('General_Category', 'Lowercase_Letter'),
2726
+ unicode_only('Diacritic'),
2727
+ unicode_only('General_Category', 'Number'),
2728
+ ]),
2729
+ ],
2730
+ 'others': [
2731
+ repeat_greedy(char_except([
2732
+ unicode_only('General_Category', 'Uppercase_Letter'),
2733
+ unicode_only('General_Category', 'Lowercase_Letter'),
2734
+ unicode_only('Diacritic'),
2735
+ unicode_only('General_Category', 'Number'),
2736
+ unicode_only('White_Space'),
2737
+ ]), 1),
2738
+ ],
2739
+ },
2740
+ }).native;
2741
+ })($ || ($ = {}));
2742
+ //hyoo/crowd/tokenizer/tokenizer.ts
2743
+ ;
2744
+ "use strict";
2745
+ var $;
2746
+ (function ($) {
2747
+ $mol_test({
2748
+ 'empty string'() {
2749
+ $mol_assert_like(''.match($hyoo_crowd_tokenizer), null);
2750
+ },
2751
+ 'new lines'() {
2752
+ $mol_assert_like('\n\r\n'.match($hyoo_crowd_tokenizer), ['\n', '\r\n']);
2753
+ },
2754
+ 'numbers'() {
2755
+ $mol_assert_like('123'.match($hyoo_crowd_tokenizer), ['123']);
2756
+ },
2757
+ 'emoji'() {
2758
+ $mol_assert_like('😀😁'.match($hyoo_crowd_tokenizer), ['😀', '😁']);
2759
+ },
2760
+ 'emoji with modifier'() {
2761
+ $mol_assert_like('👩🏿👩🏿'.match($hyoo_crowd_tokenizer), ['👩🏿', '👩🏿']);
2762
+ },
2763
+ 'combo emoji with modifier'() {
2764
+ $mol_assert_like('👩🏿‍🤝‍🧑🏿👩🏿‍🤝‍🧑🏿'.match($hyoo_crowd_tokenizer), ['👩🏿‍🤝‍🧑🏿', '👩🏿‍🤝‍🧑🏿']);
2765
+ },
2766
+ 'word with spaces'() {
2767
+ $mol_assert_like('foo1 bar2'.match($hyoo_crowd_tokenizer), ['foo1', ' ', ' bar2']);
2768
+ },
2769
+ 'word with diactric'() {
2770
+ $mol_assert_like('Е́е́'.match($hyoo_crowd_tokenizer), ['Е́е́']);
2771
+ },
2772
+ 'word with punctuation'() {
2773
+ $mol_assert_like('foo--bar'.match($hyoo_crowd_tokenizer), ['foo', '--', 'bar']);
2774
+ },
2775
+ 'CamelCase'() {
2776
+ $mol_assert_like('Foo1BAR2'.match($hyoo_crowd_tokenizer), ['Foo1', 'BAR2']);
2777
+ },
2778
+ });
2779
+ })($ || ($ = {}));
2780
+ //hyoo/crowd/tokenizer/tokenizer.test.ts
2781
+ ;
2782
+ "use strict";
2783
+ var $;
2784
+ (function ($) {
2785
+ class $hyoo_crowd_text extends $hyoo_crowd_node {
2786
+ text(next) {
2787
+ if (next === undefined) {
2788
+ return this.str();
2789
+ }
2790
+ else {
2791
+ const prev = this.units();
2792
+ const lines = next.match(/.*\n|.+$/g) ?? [];
2793
+ $mol_reconcile({
2794
+ prev,
2795
+ from: 0,
2796
+ to: prev.length,
2797
+ next: lines,
2798
+ equal: (next, prev) => {
2799
+ if (typeof prev.data === 'string')
2800
+ return false;
2801
+ return this.land.node(prev.self, $hyoo_crowd_text).str() === next;
2802
+ },
2803
+ drop: (prev, lead) => this.land.wipe(prev),
2804
+ insert: (next, lead) => {
2805
+ const unit = this.land.put(this.head, this.land.id_new(), lead?.self ?? '0_0', []);
2806
+ this.land.node(unit.self, $hyoo_crowd_text).str(next);
2807
+ return unit;
2808
+ },
2809
+ update: (next, prev, lead) => {
2810
+ this.land.node(prev.self, $hyoo_crowd_text).str(next);
2811
+ return prev;
2812
+ },
2813
+ });
2814
+ return next;
2815
+ }
2816
+ }
2817
+ str(next) {
2818
+ if (next === undefined) {
2819
+ let str = '';
2820
+ for (const unit of this.units()) {
2821
+ if (typeof unit.data === 'string')
2822
+ str += unit.data;
2823
+ else
2824
+ str += this.land.node(unit.self, $hyoo_crowd_text).str();
2825
+ }
2826
+ return str;
2827
+ }
2828
+ else {
2829
+ this.write(next, 0, -1);
2830
+ return next;
2831
+ }
2832
+ }
2833
+ write(next, str_from = -1, str_to = str_from) {
2834
+ const list = this.units();
2835
+ let from = str_from < 0 ? list.length : 0;
2836
+ let word = '';
2837
+ while (from < list.length) {
2838
+ word = String(list[from].data);
2839
+ if (str_from <= word.length) {
2840
+ next = word.slice(0, str_from) + next;
2841
+ break;
2842
+ }
2843
+ str_from -= word.length;
2844
+ if (str_to > 0)
2845
+ str_to -= word.length;
2846
+ from++;
2847
+ }
2848
+ let to = str_to < 0 ? list.length : from;
2849
+ while (to < list.length) {
2850
+ word = String(list[to].data);
2851
+ to++;
2852
+ if (str_to < word.length) {
2853
+ next = next + word.slice(str_to);
2854
+ break;
2855
+ }
2856
+ str_to -= word.length;
2857
+ }
2858
+ if (from && from === list.length) {
2859
+ --from;
2860
+ next = String(list[from].data) + next;
2861
+ }
2862
+ const words = next.match($hyoo_crowd_tokenizer) ?? [];
2863
+ this.as($hyoo_crowd_list).insert(words, from, to);
2864
+ return this;
2865
+ }
2866
+ point_by_offset(offset) {
2867
+ let off = offset;
2868
+ for (const unit of this.units()) {
2869
+ if (typeof unit.data === 'string') {
2870
+ const len = String(unit.data).length;
2871
+ if (off <= len)
2872
+ return [unit.self, off];
2873
+ else
2874
+ off -= len;
2875
+ }
2876
+ else {
2877
+ const found = this.land.node(unit.self, $hyoo_crowd_text).point_by_offset(off);
2878
+ if (found[0] !== '0_0')
2879
+ return found;
2880
+ off = found[1];
2881
+ }
2882
+ }
2883
+ return ['0_0', off];
2884
+ }
2885
+ offset_by_point([self, offset]) {
2886
+ for (const unit of this.units()) {
2887
+ if (unit.self === self)
2888
+ return [self, offset];
2889
+ if (typeof unit.data === 'string') {
2890
+ offset += unit.data.length;
2891
+ }
2892
+ else {
2893
+ const found = this.land.node(unit.self, $hyoo_crowd_text).offset_by_point([self, offset]);
2894
+ if (found[0] !== '0_0')
2895
+ return [self, found[1]];
2896
+ offset = found[1];
2897
+ }
2898
+ }
2899
+ return ['0_0', offset];
2900
+ }
2901
+ selection(peer, next) {
2902
+ const reg = this.land.selection(peer);
2903
+ if (next) {
2904
+ reg.value(next.map(offset => this.point_by_offset(offset)));
2905
+ return next;
2906
+ }
2907
+ else {
2908
+ this.units();
2909
+ return reg.value()
2910
+ ?.map(point => this.offset_by_point(point)[1]) ?? [0, 0];
2911
+ }
2912
+ }
2913
+ }
2914
+ $.$hyoo_crowd_text = $hyoo_crowd_text;
2915
+ })($ || ($ = {}));
2916
+ //hyoo/crowd/text/text.ts
2917
+ ;
2918
+ "use strict";
2919
+ var $;
2920
+ (function ($) {
2921
+ $mol_test({
2922
+ async 'string: Offset <=> Point'() {
2923
+ const store = $hyoo_crowd_land.make({});
2924
+ store.chief.as($hyoo_crowd_text).str('fooBar');
2925
+ const [first, second] = store.chief.units();
2926
+ $mol_assert_like(store.chief.as($hyoo_crowd_text)
2927
+ .point_by_offset(0), [first.self, 0]);
2928
+ $mol_assert_like(store.chief.as($hyoo_crowd_text)
2929
+ .offset_by_point([first.self, 0]), [first.self, 0]);
2930
+ $mol_assert_like(store.chief.as($hyoo_crowd_text)
2931
+ .point_by_offset(3), [first.self, 3]);
2932
+ $mol_assert_like(store.chief.as($hyoo_crowd_text)
2933
+ .offset_by_point([first.self, 3]), [first.self, 3]);
2934
+ $mol_assert_like(store.chief.as($hyoo_crowd_text)
2935
+ .offset_by_point([first.self, 5]), [first.self, 5]);
2936
+ $mol_assert_like(store.chief.as($hyoo_crowd_text)
2937
+ .point_by_offset(5), [second.self, 2]);
2938
+ $mol_assert_like(store.chief.as($hyoo_crowd_text)
2939
+ .offset_by_point([second.self, 2]), [second.self, 5]);
2940
+ $mol_assert_like(store.chief.as($hyoo_crowd_text)
2941
+ .point_by_offset(6), [second.self, 3]);
2942
+ $mol_assert_like(store.chief.as($hyoo_crowd_text)
2943
+ .offset_by_point([second.self, 3]), [second.self, 6]);
2944
+ $mol_assert_like(store.chief.as($hyoo_crowd_text)
2945
+ .point_by_offset(7), ['0_0', 1]);
2946
+ $mol_assert_like(store.chief.as($hyoo_crowd_text)
2947
+ .offset_by_point(['0_0', 1]), ['0_0', 7]);
2948
+ },
2949
+ async 'text: Offset <=> Point'() {
2950
+ const store = $hyoo_crowd_land.make({});
2951
+ store.chief.as($hyoo_crowd_text).text('foo bar\n666 777');
2952
+ const [first, second] = store.chief.nodes($hyoo_crowd_text);
2953
+ $mol_assert_like(store.chief.as($hyoo_crowd_text).point_by_offset(0), [first.units()[0].self, 0]);
2954
+ $mol_assert_like(store.chief.as($hyoo_crowd_text).offset_by_point([first.units()[0].self, 0]), [first.units()[0].self, 0]);
2955
+ $mol_assert_like(store.chief.as($hyoo_crowd_text).point_by_offset(8), [first.units()[2].self, 1]);
2956
+ $mol_assert_like(store.chief.as($hyoo_crowd_text).offset_by_point([first.units()[2].self, 1]), [first.units()[2].self, 8]);
2957
+ },
2958
+ });
2959
+ })($ || ($ = {}));
2960
+ //hyoo/crowd/text/text.test.ts
2961
+ ;
2962
+ "use strict";
2963
+ var $;
2964
+ (function ($) {
2965
+ async function make_land() {
2966
+ const world = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
2967
+ return world.grab();
2968
+ }
2969
+ $mol_test({
2970
+ async 'Join & Leave'() {
2971
+ const store = await make_land();
2972
+ $mol_assert_like(store.peers(), [store.id(), store.peer_id()]);
2973
+ $mol_assert_like(store.residents(), []);
2974
+ const peer = await $hyoo_crowd_peer.generate();
2975
+ store.join();
2976
+ $mol_assert_like(store.peers(), [store.id(), store.peer_id()]);
2977
+ $mol_assert_like(store.residents(), [store.peer_id()]);
2978
+ store.level(peer.id, $hyoo_crowd_peer_level.add);
2979
+ $mol_assert_like(store.peers(), [store.id(), store.peer_id(), peer.id]);
2980
+ $mol_assert_like(store.residents(), [store.peer_id()]);
2981
+ store.leave();
2982
+ $mol_assert_like(store.peers(), [store.id(), store.peer_id(), peer.id]);
2983
+ $mol_assert_like(store.residents(), []);
2984
+ },
2985
+ async 'Default state'() {
2986
+ const store = await make_land();
2987
+ $mol_assert_like(store.chief.as($hyoo_crowd_reg).value(), null);
2988
+ $mol_assert_like(store.chief.as($hyoo_crowd_reg).bool(), false);
2989
+ $mol_assert_like(store.chief.as($hyoo_crowd_reg).numb(), 0);
2990
+ $mol_assert_like(store.chief.as($hyoo_crowd_reg).str(), '');
2991
+ $mol_assert_like(store.chief.as($hyoo_crowd_list).list(), []);
2992
+ $mol_assert_like(store.delta().length, 2);
2993
+ },
2994
+ async 'Return default state'() {
2995
+ const store = await make_land();
2996
+ const reg = store.chief.as($hyoo_crowd_reg);
2997
+ const list = store.chief.as($hyoo_crowd_list);
2998
+ const text = store.chief.as($hyoo_crowd_text);
2999
+ $mol_assert_like(reg.bool(false), false);
3000
+ $mol_assert_like(reg.str(''), '');
3001
+ $mol_assert_like(reg.numb(0), 0);
3002
+ $mol_assert_like(text.str(''), '');
3003
+ $mol_assert_like(reg.value(null), null);
3004
+ $mol_assert_like(list.list(), []);
3005
+ },
3006
+ async 'Serial changes'() {
3007
+ const store = await make_land();
3008
+ Object.assign(store.peer(), { key_public_serial: null });
3009
+ $mol_assert_like(store.chief.as($hyoo_crowd_reg).value(), null);
3010
+ $mol_assert_like(store.chief.as($hyoo_crowd_list).list(), []);
3011
+ $mol_assert_like(store.chief.as($hyoo_crowd_reg).bool(), false);
3012
+ store.chief.as($hyoo_crowd_reg).bool(true);
3013
+ $mol_assert_like(store.chief.as($hyoo_crowd_reg).value(), true);
3014
+ $mol_assert_like(store.chief.as($hyoo_crowd_list).list(), [true]);
3015
+ $mol_assert_like(store.chief.as($hyoo_crowd_reg).numb(), 1);
3016
+ store.chief.as($hyoo_crowd_reg).numb(1);
3017
+ $mol_assert_like(store.chief.as($hyoo_crowd_reg).value(), 1);
3018
+ $mol_assert_like(store.chief.as($hyoo_crowd_list).list(), [1]);
3019
+ $mol_assert_like(store.chief.as($hyoo_crowd_reg).str(), '1');
3020
+ store.chief.as($hyoo_crowd_reg).str('x');
3021
+ $mol_assert_like(store.chief.as($hyoo_crowd_reg).value(), 'x');
3022
+ $mol_assert_like(store.chief.as($hyoo_crowd_list).list(), ['x']);
3023
+ store.chief.as($hyoo_crowd_reg).value(null);
3024
+ $mol_assert_like(store.chief.as($hyoo_crowd_reg).value(), null);
3025
+ $mol_assert_like(store.chief.as($hyoo_crowd_list).list(), []);
3026
+ $mol_assert_like(store.delta().map(unit => unit.data).slice(1), [3, null]);
3027
+ },
3028
+ async 'Name spaces'() {
3029
+ const store = await make_land();
3030
+ store.chief.sub('foo', $hyoo_crowd_struct).sub('bar', $hyoo_crowd_reg).numb(111);
3031
+ store.chief.sub('foo', $hyoo_crowd_struct).sub('ton', $hyoo_crowd_reg).numb(222);
3032
+ $mol_assert_like(store.chief.as($hyoo_crowd_list).list(), []);
3033
+ $mol_assert_like(store.chief.sub('foo', $hyoo_crowd_list).list(), []);
3034
+ $mol_assert_like(store.chief.sub('foo', $hyoo_crowd_struct).sub('bar', $hyoo_crowd_list).list(), [111]);
3035
+ $mol_assert_like(store.chief.sub('foo', $hyoo_crowd_struct).sub('ton', $hyoo_crowd_list).list(), [222]);
3036
+ },
3037
+ async 'Name spaces merging'() {
3038
+ const left = await make_land();
3039
+ left.chief.sub('foo', $hyoo_crowd_list).list([111]);
3040
+ const right = await make_land();
3041
+ right.clock_data.tick(right.peer().id);
3042
+ right.chief.sub('foo', $hyoo_crowd_list).list([222]);
3043
+ const left_delta = left.delta();
3044
+ const right_delta = right.delta();
3045
+ left.apply(right_delta);
3046
+ right.apply(left_delta);
3047
+ $mol_assert_like(left.chief.sub('foo', $hyoo_crowd_list).list(), right.chief.sub('foo', $hyoo_crowd_list).list(), [222, 111]);
3048
+ },
3049
+ async 'Ignore same changes'() {
3050
+ const store = await make_land();
3051
+ store.chief.as($hyoo_crowd_reg).str('foo');
3052
+ const time = store.clock_data.last_time;
3053
+ store.chief.as($hyoo_crowd_reg).str('foo');
3054
+ store.chief.as($hyoo_crowd_list).list(['foo']);
3055
+ $mol_assert_like(store.delta().map(unit => unit.time).slice(2), [time + 2, time]);
3056
+ },
3057
+ async 'Serial insert values'() {
3058
+ const store = await make_land();
3059
+ store.chief.as($hyoo_crowd_list).insert(['foo']);
3060
+ store.chief.as($hyoo_crowd_list).insert(['bar']);
3061
+ $mol_assert_like(store.chief.as($hyoo_crowd_list).list(), ['foo', 'bar']);
3062
+ },
3063
+ async 'Concurent insert values'() {
3064
+ const store = await make_land();
3065
+ store.chief.as($hyoo_crowd_list).insert(['foo'], 0);
3066
+ store.chief.as($hyoo_crowd_list).insert(['bar'], 0);
3067
+ $mol_assert_like(store.chief.as($hyoo_crowd_list).list(), ['bar', 'foo']);
3068
+ },
3069
+ async 'Insert value between others'() {
3070
+ const store = await make_land();
3071
+ store.chief.as($hyoo_crowd_list).insert(['foo']);
3072
+ store.chief.as($hyoo_crowd_list).insert(['bar']);
3073
+ store.chief.as($hyoo_crowd_list).insert(['lol'], 1);
3074
+ $mol_assert_like(store.chief.as($hyoo_crowd_list).list(), ['foo', 'lol', 'bar']);
3075
+ },
3076
+ async 'Insert value inside other'() {
3077
+ const store = await make_land();
3078
+ store.chief.as($hyoo_crowd_list).insert(['foo']);
3079
+ store.chief.nodes($hyoo_crowd_list)[0].insert(['bar']);
3080
+ $mol_assert_like(store.chief.as($hyoo_crowd_list).list(), ['foo']);
3081
+ $mol_assert_like(store.chief.nodes($hyoo_crowd_list)[0].list(), ['bar']);
3082
+ },
3083
+ async 'Insert before removed before changed'() {
3084
+ const store = await make_land();
3085
+ const node = store.chief.as($hyoo_crowd_list);
3086
+ node.list(['foo', 'bar']);
3087
+ node.list(['xxx', 'foo', 'bar']);
3088
+ node.list(['xxx', 'bars']);
3089
+ $mol_assert_like(node.list(), ['xxx', 'bars']);
3090
+ },
3091
+ async 'Move existen Unit'() {
3092
+ const store = await make_land();
3093
+ store.chief.as($hyoo_crowd_text).str('FooBarLol');
3094
+ store.chief.as($hyoo_crowd_list).move(0, 2);
3095
+ $mol_assert_like(store.chief.as($hyoo_crowd_text).str(), 'BarFooLol');
3096
+ },
3097
+ async 'Many moves'() {
3098
+ const store = await make_land();
3099
+ const text = store.chief.as($hyoo_crowd_text);
3100
+ const list = store.chief.as($hyoo_crowd_list);
3101
+ text.str('FooBarLol');
3102
+ list.move(2, 1);
3103
+ list.move(2, 1);
3104
+ list.move(0, 3);
3105
+ list.move(2, 1);
3106
+ $mol_assert_like(text.str(), 'BarFooLol');
3107
+ },
3108
+ async 'Separated sublists'() {
3109
+ const store = await make_land();
3110
+ const text = store.chief.as($hyoo_crowd_text);
3111
+ const list = store.chief.as($hyoo_crowd_list);
3112
+ text.str('AaBbCcDdEeFf');
3113
+ list.move(3, 5);
3114
+ list.move(3, 5);
3115
+ list.move(5, 4);
3116
+ list.move(0, 2);
3117
+ list.move(0, 2);
3118
+ list.move(2, 1);
3119
+ $mol_assert_like(text.str(), 'AaCcBbDdFfEe');
3120
+ },
3121
+ async 'Deltas for different versions'() {
3122
+ const store = await make_land();
3123
+ Object.assign(store.peer(), { key_public_serial: null });
3124
+ store.clock_data.see_time(store.clock_data.now() + 60);
3125
+ store.chief.as($hyoo_crowd_list).list(['foo', 'bar', 'lol']);
3126
+ $mol_assert_like(store.delta([
3127
+ new $hyoo_crowd_clock,
3128
+ new $hyoo_crowd_clock([
3129
+ [store.peer().id, store.clock_data.last_time - 3],
3130
+ ])
3131
+ ]).map(unit => unit.data).slice(2), ['foo', 'bar', 'lol']);
3132
+ $mol_assert_like(store.delta([
3133
+ new $hyoo_crowd_clock,
3134
+ new $hyoo_crowd_clock([
3135
+ [store.peer().id, store.clock_data.last_time - 2],
3136
+ ])
3137
+ ]).map(unit => unit.data).slice(2), ['bar', 'lol']);
3138
+ $mol_assert_like(store.delta([
3139
+ new $hyoo_crowd_clock,
3140
+ new $hyoo_crowd_clock([
3141
+ [store.peer().id, store.clock_data.last_time - 1],
3142
+ ])
3143
+ ]).map(unit => unit.data).slice(2), ['lol']);
3144
+ $mol_assert_like(store.delta([
3145
+ new $hyoo_crowd_clock,
3146
+ new $hyoo_crowd_clock([
3147
+ [store.peer().id, store.clock_data.last_time],
3148
+ ])
3149
+ ]).slice(2), []);
3150
+ },
3151
+ async 'Delete without subtree and ignore inserted into deleted'() {
3152
+ const store = await make_land();
3153
+ store.chief.as($hyoo_crowd_text).str('foo');
3154
+ const b2 = store.chief.nodes($hyoo_crowd_text)[0];
3155
+ b2.str('bar');
3156
+ const b3 = b2.nodes($hyoo_crowd_text)[0];
3157
+ b3.str('lol');
3158
+ $mol_assert_like(store.chief.as($hyoo_crowd_reg).value(), 'foo');
3159
+ $mol_assert_like(b2.as($hyoo_crowd_reg).value(), 'bar');
3160
+ $mol_assert_like(b3.as($hyoo_crowd_reg).value(), 'lol');
3161
+ store.chief.as($hyoo_crowd_list).cut(0);
3162
+ $mol_assert_like(store.chief.as($hyoo_crowd_reg).value(), null);
3163
+ $mol_assert_like(b2.as($hyoo_crowd_reg).value(), 'bar');
3164
+ $mol_assert_like(b3.as($hyoo_crowd_reg).value(), 'lol');
3165
+ },
3166
+ async 'Put/get list'() {
3167
+ const store = await make_land();
3168
+ $mol_assert_like(store.chief.as($hyoo_crowd_list).list(), []);
3169
+ store.chief.as($hyoo_crowd_list).list(['foo', 'bar', 'foo']);
3170
+ const first = store.chief.nodes($hyoo_crowd_list)[0];
3171
+ first.list(['bar', 'foo', 'bar']);
3172
+ $mol_assert_like(store.chief.as($hyoo_crowd_list).list(), ['foo', 'bar', 'foo']);
3173
+ $mol_assert_like(first.list(), ['bar', 'foo', 'bar']);
3174
+ },
3175
+ async 'Put/get text'() {
3176
+ const store1 = await make_land();
3177
+ store1.chief.as($hyoo_crowd_text).str('foo bar foo');
3178
+ $mol_assert_like(store1.chief.as($hyoo_crowd_text).str(), 'foo bar foo');
3179
+ $mol_assert_like(store1.chief.as($hyoo_crowd_list).list(), ['foo', ' bar', ' foo']);
3180
+ const store2 = store1.fork(await $hyoo_crowd_peer.generate());
3181
+ store2.chief.as($hyoo_crowd_text).str('barFFFoo bar');
3182
+ $mol_assert_like(store2.chief.as($hyoo_crowd_text).str(), 'barFFFoo bar');
3183
+ $mol_assert_like(store2.chief.as($hyoo_crowd_list).list(), ['bar', 'FFFoo', ' ', ' bar']);
3184
+ },
3185
+ async 'Text modifications'() {
3186
+ const store1 = await make_land();
3187
+ store1.chief.as($hyoo_crowd_text).str('foo bar');
3188
+ const store2 = store1.fork(await $hyoo_crowd_peer.generate());
3189
+ store2.chief.as($hyoo_crowd_text).str('foo bar');
3190
+ $mol_assert_like(store1.chief.units().map(unit => unit.self), [
3191
+ store2.chief.units()[0].self,
3192
+ store2.chief.units()[2].self,
3193
+ ]);
3194
+ const store3 = store2.fork(await $hyoo_crowd_peer.generate());
3195
+ store3.chief.as($hyoo_crowd_text).str('foo ton bar');
3196
+ $mol_assert_like(store2.chief.units().map(unit => unit.self), [
3197
+ store3.chief.units()[0].self,
3198
+ store3.chief.units()[1].self,
3199
+ store3.chief.units()[2].self,
3200
+ ]);
3201
+ const store4 = store3.fork(await $hyoo_crowd_peer.generate());
3202
+ store4.chief.as($hyoo_crowd_text).str('foo bar');
3203
+ $mol_assert_like([
3204
+ store3.chief.units()[0].self,
3205
+ store3.chief.units()[2].self,
3206
+ ], store4.chief.units().map(unit => unit.self));
3207
+ const store5 = store3.fork(await $hyoo_crowd_peer.generate());
3208
+ store5.chief.as($hyoo_crowd_text).str('foo ');
3209
+ $mol_assert_like([
3210
+ store4.chief.units()[0].self,
3211
+ store4.chief.units()[1].self,
3212
+ ], store5.chief.units().map(unit => unit.self));
3213
+ },
3214
+ async 'Change sequences'() {
3215
+ const store = await make_land();
3216
+ $mol_assert_like(store.chief.as($hyoo_crowd_text).str(), '');
3217
+ store.chief.as($hyoo_crowd_text).str('foo');
3218
+ $mol_assert_like(store.chief.as($hyoo_crowd_text).str(), 'foo');
3219
+ store.chief.as($hyoo_crowd_text).str('foo bar');
3220
+ $mol_assert_like(store.chief.as($hyoo_crowd_text).str(), 'foo bar');
3221
+ store.chief.as($hyoo_crowd_text).str('foo lol bar');
3222
+ $mol_assert_like(store.chief.as($hyoo_crowd_text).str(), 'foo lol bar');
3223
+ store.chief.as($hyoo_crowd_text).str('lol bar');
3224
+ $mol_assert_like(store.chief.as($hyoo_crowd_text).str(), 'lol bar');
3225
+ store.chief.as($hyoo_crowd_text).str('foo bar');
3226
+ $mol_assert_like(store.chief.as($hyoo_crowd_text).str(), 'foo bar');
3227
+ },
3228
+ async 'Merge different sequences'() {
3229
+ const left = await make_land();
3230
+ left.chief.as($hyoo_crowd_text).str('foo bar.');
3231
+ const right = await make_land();
3232
+ right.clock_data.tick(right.peer().id);
3233
+ right.chief.as($hyoo_crowd_text).str('xxx yyy.');
3234
+ const left_delta = left.delta();
3235
+ const right_delta = right.delta();
3236
+ left.apply(right_delta);
3237
+ right.apply(left_delta);
3238
+ $mol_assert_like(left.chief.as($hyoo_crowd_text).str(), right.chief.as($hyoo_crowd_text).str(), 'xxx yyy.foo bar.');
3239
+ },
3240
+ async 'Merge different insertions to same place of same sequence'() {
3241
+ const base = await make_land();
3242
+ base.chief.as($hyoo_crowd_text).str('foo bar');
3243
+ const left = base.fork(await $hyoo_crowd_peer.generate());
3244
+ left.chief.as($hyoo_crowd_text).str('foo xxx bar');
3245
+ const right = base.fork(await $hyoo_crowd_peer.generate());
3246
+ right.clock_data.tick(right.peer().id);
3247
+ right.chief.as($hyoo_crowd_text).str('foo yyy bar');
3248
+ const left_delta = left.delta(base.clocks);
3249
+ const right_delta = right.delta(base.clocks);
3250
+ left.apply(right_delta);
3251
+ right.apply(left_delta);
3252
+ $mol_assert_like(left.chief.as($hyoo_crowd_text).str(), right.chief.as($hyoo_crowd_text).str(), 'foo yyy xxx bar');
3253
+ },
3254
+ async 'Insert after moved'() {
3255
+ const base = await make_land();
3256
+ base.chief.as($hyoo_crowd_text).str('FooBarZak');
3257
+ const left = base.fork(await $hyoo_crowd_peer.generate());
3258
+ left.chief.as($hyoo_crowd_text).str('FooXxxBarZak');
3259
+ const right = base.fork(await $hyoo_crowd_peer.generate());
3260
+ right.clock_data.tick(right.peer().id);
3261
+ right.insert(right.chief.units()[0], '0_0', 2);
3262
+ const left_delta = left.delta(base.clocks);
3263
+ const right_delta = right.delta(base.clocks);
3264
+ left.apply(right_delta);
3265
+ right.apply(left_delta);
3266
+ $mol_assert_like(left.chief.as($hyoo_crowd_text).str(), right.chief.as($hyoo_crowd_text).str(), 'BarFooXxxZak');
3267
+ },
3268
+ async 'Insert before moved left'() {
3269
+ const base = await make_land();
3270
+ base.chief.as($hyoo_crowd_text).str('fooBarZak');
3271
+ const left = base.fork(await $hyoo_crowd_peer.generate());
3272
+ left.chief.as($hyoo_crowd_text).str('FooXxxBarZak');
3273
+ const right = base.fork(await $hyoo_crowd_peer.generate());
3274
+ right.clock_data.tick(right.peer().id);
3275
+ right.insert(right.chief.units()[1], '0_0', 0);
3276
+ const left_delta = left.delta(base.clocks);
3277
+ const right_delta = right.delta(base.clocks);
3278
+ left.apply(right_delta);
3279
+ right.apply(left_delta);
3280
+ $mol_assert_like(left.chief.as($hyoo_crowd_text).str(), right.chief.as($hyoo_crowd_text).str(), 'BarFooXxxZak');
3281
+ },
3282
+ async 'Insert before moved right'() {
3283
+ const base = await make_land();
3284
+ base.chief.as($hyoo_crowd_text).str('FooBarZakPew');
3285
+ const left = base.fork(await $hyoo_crowd_peer.generate());
3286
+ left.chief.as($hyoo_crowd_text).str('FooXxxBarZakPew');
3287
+ const right = base.fork(await $hyoo_crowd_peer.generate());
3288
+ right.clock_data.tick(right.peer().id);
3289
+ right.insert(right.chief.units()[1], '0_0', 4);
3290
+ const left_delta = left.delta(base.clocks);
3291
+ const right_delta = right.delta(base.clocks);
3292
+ left.apply(right_delta);
3293
+ right.apply(left_delta);
3294
+ $mol_assert_like(left.chief.as($hyoo_crowd_text).str(), right.chief.as($hyoo_crowd_text).str(), 'FooZakXxxPewBar');
3295
+ },
3296
+ async 'Insert after removed'() {
3297
+ const base = await make_land();
3298
+ base.chief.as($hyoo_crowd_text).str('FooBar');
3299
+ const left = base.fork(await $hyoo_crowd_peer.generate());
3300
+ left.chief.as($hyoo_crowd_text).str('FooXxxBar');
3301
+ const right = base.fork(await $hyoo_crowd_peer.generate());
3302
+ right.clock_data.tick(right.peer().id);
3303
+ right.chief.as($hyoo_crowd_text).str('Bar');
3304
+ const left_delta = left.delta(base.clocks);
3305
+ const right_delta = right.delta(base.clocks);
3306
+ left.apply(right_delta);
3307
+ right.apply(left_delta);
3308
+ $mol_assert_like(left.chief.as($hyoo_crowd_text).str(), right.chief.as($hyoo_crowd_text).str(), 'XxxBar');
3309
+ },
3310
+ async 'Insert after removed out'() {
3311
+ const base = await make_land();
3312
+ base.node('1_1', $hyoo_crowd_text).str('FooBarZak');
3313
+ const left = base.fork(await $hyoo_crowd_peer.generate());
3314
+ left.node('1_1', $hyoo_crowd_text).str('FooBarXxxZak');
3315
+ const right = base.fork(await $hyoo_crowd_peer.generate());
3316
+ right.clock_data.tick(right.peer().id);
3317
+ right.insert(right.node('1_1', $hyoo_crowd_node).units()[1], '2_2', 0);
3318
+ const left_delta = left.delta(base.clocks);
3319
+ const right_delta = right.delta(base.clocks);
3320
+ left.apply(right_delta);
3321
+ right.apply(left_delta);
3322
+ $mol_assert_like(left.node('1_1', $hyoo_crowd_text).str(), right.node('1_1', $hyoo_crowd_text).str(), 'FooZakXxx');
3323
+ $mol_assert_like(left.node('2_2', $hyoo_crowd_text).str(), left.node('2_2', $hyoo_crowd_text).str(), 'Bar');
3324
+ },
3325
+ async 'Insert before changed'() {
3326
+ const base = await make_land();
3327
+ base.chief.as($hyoo_crowd_text).str('XxxYyyZzz');
3328
+ const left = base.fork(await $hyoo_crowd_peer.generate());
3329
+ left.chief.as($hyoo_crowd_text).str('XxxFooYyyZzz');
3330
+ const right = base.fork(await $hyoo_crowd_peer.generate());
3331
+ right.clock_data.tick(right.peer().id);
3332
+ right.chief.as($hyoo_crowd_text).str('XxxBarZzz');
3333
+ const left_delta = left.delta(base.clocks);
3334
+ const right_delta = right.delta(base.clocks);
3335
+ left.apply(right_delta);
3336
+ right.apply(left_delta);
3337
+ $mol_assert_like(left.chief.as($hyoo_crowd_text).str(), right.chief.as($hyoo_crowd_text).str(), 'XxxBarFooZzz');
3338
+ },
3339
+ async 'Insert between moved'() {
3340
+ const base = await make_land();
3341
+ base.chief.as($hyoo_crowd_list).list([111, 222, 333, 444, 555, 666]);
3342
+ const left = base.fork(await $hyoo_crowd_peer.generate());
3343
+ left.chief.as($hyoo_crowd_list).list([111, 222, 777, 333, 444, 555, 666]);
3344
+ const right = base.fork(await $hyoo_crowd_peer.generate());
3345
+ right.clock_data.tick(right.peer().id);
3346
+ right.insert(right.chief.units()[1], '0_0', 5);
3347
+ right.insert(right.chief.units()[1], '0_0', 5);
3348
+ const left_delta = left.delta(base.clocks);
3349
+ const right_delta = right.delta(base.clocks);
3350
+ left.apply(right_delta);
3351
+ right.apply(left_delta);
3352
+ $mol_assert_like(left.chief.as($hyoo_crowd_list).list(), right.chief.as($hyoo_crowd_list).list(), [111, 444, 555, 222, 333, 777, 666]);
3353
+ },
3354
+ async 'Merge text changes'() {
3355
+ const base = await make_land();
3356
+ base.chief.as($hyoo_crowd_text).str('Hello World and fun!');
3357
+ const left = base.fork(await $hyoo_crowd_peer.generate());
3358
+ const right = base.fork(await $hyoo_crowd_peer.generate());
3359
+ right.clock_data.tick(right.peer().id);
3360
+ left.chief.as($hyoo_crowd_text).str('Hello Alice and fun!');
3361
+ right.chief.as($hyoo_crowd_text).str('Bye World and fun!');
3362
+ const left_delta = left.delta();
3363
+ const right_delta = right.delta();
3364
+ left.apply(right_delta);
3365
+ right.apply(left_delta);
3366
+ $mol_assert_equal(left.chief.as($hyoo_crowd_text).str(), right.chief.as($hyoo_crowd_text).str(), 'Bye Alice and fun!');
3367
+ },
3368
+ async 'Write into token'() {
3369
+ const store = await make_land();
3370
+ store.chief.as($hyoo_crowd_text).str('foobar');
3371
+ store.chief.as($hyoo_crowd_text).write('xyz', 3);
3372
+ $mol_assert_like(store.chief.as($hyoo_crowd_list).list(), ['fooxyzbar']);
3373
+ },
3374
+ async 'Write into token with split'() {
3375
+ const store = await make_land();
3376
+ store.chief.as($hyoo_crowd_text).str('foobar');
3377
+ store.chief.as($hyoo_crowd_text).write('XYZ', 2, 4);
3378
+ $mol_assert_like(store.chief.as($hyoo_crowd_list).list(), ['fo', 'XYZar']);
3379
+ },
3380
+ async 'Write over few tokens'() {
3381
+ const store = await make_land();
3382
+ store.chief.as($hyoo_crowd_text).str('xxx foo bar yyy');
3383
+ store.chief.as($hyoo_crowd_text).write('X Y Z', 6, 9);
3384
+ $mol_assert_like(store.chief.as($hyoo_crowd_list).list(), ['xxx', ' fo', 'X', ' Y', ' Zar', ' yyy']);
3385
+ },
3386
+ async 'Write whole token'() {
3387
+ const store = await make_land();
3388
+ store.chief.as($hyoo_crowd_text).str('xxxFoo yyy');
3389
+ store.chief.as($hyoo_crowd_text).write('bar', 3, 7);
3390
+ $mol_assert_like(store.chief.as($hyoo_crowd_list).list(), ['xxxbaryyy']);
3391
+ },
3392
+ async 'Write whole text'() {
3393
+ const store = await make_land();
3394
+ store.chief.as($hyoo_crowd_text).str('foo bar');
3395
+ store.chief.as($hyoo_crowd_text).write('xxx', 0, 7);
3396
+ $mol_assert_like(store.chief.as($hyoo_crowd_list).list(), ['xxx']);
3397
+ },
3398
+ async 'Write at the end'() {
3399
+ const store = await make_land();
3400
+ store.chief.as($hyoo_crowd_text).str('foo');
3401
+ store.chief.as($hyoo_crowd_text).write('bar');
3402
+ $mol_assert_like(store.chief.as($hyoo_crowd_list).list(), ['foobar']);
3403
+ },
3404
+ async 'Write between tokens'() {
3405
+ const store = await make_land();
3406
+ store.chief.as($hyoo_crowd_text).str('foo bar');
3407
+ store.chief.as($hyoo_crowd_text).write('xxx', 4);
3408
+ $mol_assert_like(store.chief.as($hyoo_crowd_list).list(), ['foo', ' xxxbar']);
3409
+ },
3410
+ });
3411
+ })($ || ($ = {}));
3412
+ //hyoo/crowd/land/land.test.ts
3413
+ ;
3414
+ "use strict";
3415
+ var $;
3416
+ (function ($) {
3417
+ $mol_test({
3418
+ 'Primitives'() {
3419
+ $mol_assert_equal($mol_key(null), 'null');
3420
+ $mol_assert_equal($mol_key(false), 'false');
3421
+ $mol_assert_equal($mol_key(true), 'true');
3422
+ $mol_assert_equal($mol_key(0), '0');
3423
+ $mol_assert_equal($mol_key(''), '""');
3424
+ },
3425
+ 'Array & POJO'() {
3426
+ $mol_assert_equal($mol_key([null]), '[null]');
3427
+ $mol_assert_equal($mol_key({ foo: 0 }), '{"foo":0}');
3428
+ $mol_assert_equal($mol_key({ foo: [false] }), '{"foo":[false]}');
3429
+ },
3430
+ 'Function'() {
3431
+ const func = () => { };
3432
+ $mol_assert_equal($mol_key(func), $mol_key(func));
3433
+ $mol_assert_unique($mol_key(func), $mol_key(() => { }));
3434
+ },
3435
+ 'Objects'() {
3436
+ class User {
3437
+ }
3438
+ const jin = new User();
3439
+ $mol_assert_equal($mol_key(jin), $mol_key(jin));
3440
+ $mol_assert_unique($mol_key(jin), $mol_key(new User()));
3441
+ },
3442
+ 'Elements'() {
3443
+ const foo = $mol_jsx("div", null, "bar");
3444
+ $mol_assert_equal($mol_key(foo), $mol_key(foo));
3445
+ $mol_assert_unique($mol_key(foo), $mol_key($mol_jsx("div", null, "bar")));
3446
+ },
3447
+ 'Custom JSON representation'() {
3448
+ class User {
3449
+ name;
3450
+ age;
3451
+ constructor(name, age) {
3452
+ this.name = name;
3453
+ this.age = age;
3454
+ }
3455
+ toJSON() { return { name: this.name }; }
3456
+ }
3457
+ $mol_assert_equal($mol_key(new User('jin', 18)), '{"name":"jin"}');
3458
+ },
3459
+ 'Special native classes'() {
3460
+ $mol_assert_equal($mol_key(new Date('xyz')), 'null');
3461
+ $mol_assert_equal($mol_key(new Date('2001-01-02T03:04:05.678Z')), '"2001-01-02T03:04:05.678Z"');
3462
+ $mol_assert_equal($mol_key(/./), '"/./"');
3463
+ $mol_assert_equal($mol_key(/\./gimsu), '"/\\\\./gimsu"');
3464
+ },
3465
+ });
3466
+ })($ || ($ = {}));
3467
+ //mol/key/key.test.tsx
3468
+ ;
3469
+ "use strict";
3470
+ var $;
3471
+ (function ($) {
3472
+ $mol_test({
3473
+ 'number'() {
3474
+ const dict = new $mol_dict();
3475
+ $mol_assert_equal(dict.get(123), undefined);
3476
+ $mol_assert_equal(dict.has(123), false);
3477
+ dict.set(123, 321);
3478
+ $mol_assert_equal(dict.get(123), 321);
3479
+ $mol_assert_equal(dict.has(123), true);
3480
+ dict.delete(123);
3481
+ $mol_assert_equal(dict.get(123), undefined);
3482
+ $mol_assert_equal(dict.has(123), false);
3483
+ },
3484
+ 'pojo as key'() {
3485
+ const dict = new $mol_dict();
3486
+ $mol_assert_equal(dict.get({ foo: 123 }), undefined);
3487
+ $mol_assert_equal(dict.has({ foo: 123 }), false);
3488
+ dict.set({ foo: 123 }, 321);
3489
+ $mol_assert_equal(dict.get({ foo: 123 }), 321);
3490
+ $mol_assert_equal(dict.has({ foo: 123 }), true);
3491
+ dict.delete({ foo: 123 });
3492
+ $mol_assert_equal(dict.get({ foo: 123 }), undefined);
3493
+ $mol_assert_equal(dict.has({ foo: 123 }), false);
3494
+ },
3495
+ 'array as key'() {
3496
+ const dict = new $mol_dict();
3497
+ $mol_assert_equal(dict.get([123]), undefined);
3498
+ $mol_assert_equal(dict.has([123]), false);
3499
+ dict.set([123], 321);
3500
+ $mol_assert_equal(dict.get([123]), 321);
3501
+ $mol_assert_equal(dict.has([123]), true);
3502
+ dict.delete([123]);
3503
+ $mol_assert_equal(dict.get([123]), undefined);
3504
+ $mol_assert_equal(dict.has([123]), false);
3505
+ },
3506
+ 'html element as key'() {
3507
+ const el = $mol_jsx("div", null);
3508
+ const dict = new $mol_dict();
3509
+ $mol_assert_equal(dict.get(el), undefined);
3510
+ $mol_assert_equal(dict.has(el), false);
3511
+ dict.set(el, 321);
3512
+ $mol_assert_equal(dict.get(el), 321);
3513
+ $mol_assert_equal(dict.has(el), true);
3514
+ $mol_assert_equal(dict.get($mol_jsx("div", null)), undefined);
3515
+ $mol_assert_equal(dict.has($mol_jsx("div", null)), false);
3516
+ dict.delete(el);
3517
+ $mol_assert_equal(dict.get(el), undefined);
3518
+ $mol_assert_equal(dict.has(el), false);
3519
+ },
3520
+ 'for-of key restore'() {
3521
+ const dict = new $mol_dict([[[123], 321]]);
3522
+ const keys = [];
3523
+ const vals = [];
3524
+ for (const [key, val] of dict) {
3525
+ keys.push(key);
3526
+ vals.push(val);
3527
+ }
3528
+ $mol_assert_like(keys, [[123]]);
3529
+ $mol_assert_like(vals, [321]);
3530
+ },
3531
+ 'method iterators key restore'() {
3532
+ const dict = new $mol_dict([[[123], 321]]);
3533
+ $mol_assert_like([...dict.keys()], [[123]]);
3534
+ $mol_assert_like([...dict.values()], [321]);
3535
+ $mol_assert_like([...dict.entries()], [[[123], 321]]);
3536
+ },
3537
+ 'forEach key restore'() {
3538
+ const dict = new $mol_dict([[[123], 321]]);
3539
+ const keys = [];
3540
+ const vals = [];
3541
+ dict.forEach((val, key) => {
3542
+ keys.push(key);
3543
+ vals.push(val);
3544
+ });
3545
+ $mol_assert_like(keys, [[123]]);
3546
+ $mol_assert_like(vals, [321]);
3547
+ },
3548
+ });
3549
+ })($ || ($ = {}));
3550
+ //mol/dict/dict.test.tsx
3551
+ ;
3552
+ "use strict";
3553
+ var $;
3554
+ (function ($) {
3555
+ class $hyoo_crowd_list extends $hyoo_crowd_node {
3556
+ list(next) {
3557
+ const units = this.units();
3558
+ if (next === undefined) {
3559
+ return units.map(unit => unit.data);
3560
+ }
3561
+ else {
3562
+ this.insert(next, 0, units.length);
3563
+ return next;
3564
+ }
3565
+ }
3566
+ set(next) {
3567
+ return new Set(this.list(next && [...next]));
3568
+ }
3569
+ insert(next, from = this.units().length, to = from) {
3570
+ $mol_reconcile({
3571
+ prev: this.units(),
3572
+ from,
3573
+ to,
3574
+ next,
3575
+ equal: (next, prev) => $mol_compare_deep(prev.data, next),
3576
+ drop: (prev, lead) => this.land.wipe(prev),
3577
+ insert: (next, lead) => this.land.put(this.head, this.land.id_new(), lead?.self ?? '0_0', next),
3578
+ update: (next, prev, lead) => this.land.put(prev.head, prev.self, lead?.self ?? '0_0', next),
3579
+ });
3580
+ }
3581
+ move(from, to) {
3582
+ const units = this.units();
3583
+ const lead = to ? units[to - 1] : null;
3584
+ this.land.move(units[from], this.head, lead?.self ?? '0_0');
3585
+ }
3586
+ cut(seat) {
3587
+ return this.land.wipe(this.units()[seat]);
3588
+ }
3589
+ has(val) {
3590
+ for (const unit of this.units()) {
3591
+ if (unit.data === val)
3592
+ return true;
3593
+ }
3594
+ return false;
3595
+ }
3596
+ add(val) {
3597
+ if (this.has(val))
3598
+ return;
3599
+ this.insert([val]);
3600
+ }
3601
+ drop(val) {
3602
+ for (const unit of this.units()) {
3603
+ if (unit.data !== val)
3604
+ continue;
3605
+ this.land.wipe(unit);
3606
+ }
3607
+ }
3608
+ node_make(val, Node) {
3609
+ this.insert([val]);
3610
+ const unit = this.units().at(-1);
3611
+ return this.land.node(unit.self, Node);
3612
+ }
3613
+ }
3614
+ __decorate([
3615
+ $mol_mem
3616
+ ], $hyoo_crowd_list.prototype, "set", null);
3617
+ $.$hyoo_crowd_list = $hyoo_crowd_list;
3618
+ })($ || ($ = {}));
3619
+ //hyoo/crowd/list/list.ts
3620
+ ;
3621
+ "use strict";
3622
+ var $;
3623
+ (function ($) {
3624
+ async function make_land(id = '1_1') {
3625
+ return $hyoo_crowd_land.make({
3626
+ id: $mol_const(id),
3627
+ peer: $mol_const(await $hyoo_crowd_peer.generate()),
3628
+ });
3629
+ }
3630
+ $mol_test({
3631
+ async 'list add & insert & drop'() {
3632
+ const land = await make_land();
3633
+ const node = land.chief.as($hyoo_crowd_list);
3634
+ node.list([1, 2]);
3635
+ $mol_assert_like(node.list(), [1, 2]);
3636
+ node.add(3);
3637
+ $mol_assert_like(node.list(), [1, 2, 3]);
3638
+ node.add(3);
3639
+ $mol_assert_like(node.list(), [1, 2, 3]);
3640
+ node.insert([2]);
3641
+ $mol_assert_like(node.list(), [1, 2, 3, 2]);
3642
+ node.insert([2], 0);
3643
+ $mol_assert_like(node.list(), [2, 1, 2, 3, 2]);
3644
+ node.drop(2);
3645
+ $mol_assert_like(node.list(), [1, 3]);
3646
+ node.drop(2);
3647
+ $mol_assert_like(node.list(), [1, 3]);
3648
+ },
3649
+ });
3650
+ })($ || ($ = {}));
3651
+ //hyoo/crowd/list/list.test.ts
3652
+ ;
3653
+ "use strict";
3654
+ var $;
3655
+ (function ($) {
3656
+ $mol_test({
3657
+ async 'world delta & apply'() {
3658
+ const world1 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
3659
+ const world2 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
3660
+ const land1 = await world1.grab();
3661
+ const land2 = await world1.grab();
3662
+ land1.chief.as($hyoo_crowd_list).list([123, 456]);
3663
+ land2.chief.as($hyoo_crowd_list).list([456, 789]);
3664
+ for await (const batch of world1.delta()) {
3665
+ $mol_assert_like((await world2.apply(batch)).forbid, new Map);
3666
+ }
3667
+ $mol_assert_like(world2.land(land1.id()).chief.as($hyoo_crowd_list).list(), [123, 456]);
3668
+ $mol_assert_like(world2.land(land2.id()).chief.as($hyoo_crowd_list).list(), [456, 789]);
3669
+ },
3670
+ async 'land delta & apply'() {
3671
+ const world1 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
3672
+ const world2 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
3673
+ const land = world1.land(world1.peer.id);
3674
+ land.chief.as($hyoo_crowd_list).list([123, 456]);
3675
+ const batch = await world1.delta_batch(land);
3676
+ $mol_assert_like((await world2.apply(batch)).forbid, new Map);
3677
+ $mol_assert_like(world2.land(land.id()).chief.as($hyoo_crowd_list).list(), [123, 456]);
3678
+ },
3679
+ async 'ignore changes from far future'() {
3680
+ const world1 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
3681
+ const world2 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
3682
+ const land = await world1.grab();
3683
+ const clock = land.clock_data;
3684
+ clock.see_time(clock.now() + 60 * 60 * 24 * 10);
3685
+ land.chief.as($hyoo_crowd_reg).numb(123);
3686
+ const batch = await world1.delta_batch(land);
3687
+ $mol_assert_like([...(await world2.apply(batch)).forbid.values()], ['Far future']);
3688
+ $mol_assert_like(world2.land(land.id()).delta().length, 3);
3689
+ },
3690
+ async 'ignore auth as another peer'() {
3691
+ const world1 = new $hyoo_crowd_world({ ...await $hyoo_crowd_peer.generate(), id: '1_1' });
3692
+ const world2 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
3693
+ const land = await world1.grab();
3694
+ land.chief.as($hyoo_crowd_reg).numb(123);
3695
+ const batch = await world1.delta_batch(land);
3696
+ $mol_assert_like([...(await world2.apply(batch)).forbid.values()], ['Alien join key', 'No auth key']);
3697
+ $mol_assert_like(world2.land(land.id()).delta().length, 2);
3698
+ },
3699
+ async 'ignore auth without key'() {
3700
+ const world1 = new $hyoo_crowd_world({ ...await $hyoo_crowd_peer.generate(), key_public_serial: [] });
3701
+ const world2 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
3702
+ const land = world1.land('1_1');
3703
+ land.chief.as($hyoo_crowd_reg).numb(123);
3704
+ const batch = await world1.delta_batch(land);
3705
+ $mol_assert_like([...(await world2.apply(batch)).forbid.values()], ['No join key', 'Level too low']);
3706
+ $mol_assert_like(world2.land(land.id()).delta().length, 0);
3707
+ },
3708
+ async 'ignore changes with wrong signs'() {
3709
+ const world1 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
3710
+ const world2 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
3711
+ const land = await world1.grab();
3712
+ const batch = await world1.delta_batch(land);
3713
+ batch[152] = ~batch[152];
3714
+ $mol_assert_like([...(await world2.apply(batch)).forbid.values()], ['Wrong join sign', 'Level too low']);
3715
+ $mol_assert_like(world2.land(land.id()).delta().length, 0);
3716
+ },
3717
+ async 'ignore update auth except auth removing'() {
3718
+ const peer = await $hyoo_crowd_peer.generate();
3719
+ const world1 = new $hyoo_crowd_world(peer);
3720
+ const world2 = new $hyoo_crowd_world(peer);
3721
+ const land1 = await world1.grab();
3722
+ const land2 = world2.land(land1.id());
3723
+ land2.clock_auth.tick(peer.id);
3724
+ land2.clock_data.tick(peer.id);
3725
+ land1.chief.as($hyoo_crowd_reg).numb(123);
3726
+ land2.chief.as($hyoo_crowd_reg).numb(234);
3727
+ const batch = await world1.delta_batch(land1);
3728
+ $mol_assert_like([...(await world2.apply(batch)).forbid.values()], []);
3729
+ $mol_assert_like(land2.delta().length, 5);
3730
+ land1.chief.as($hyoo_crowd_reg).numb(345);
3731
+ land1.leave();
3732
+ const batch2 = await world1.delta_batch(land1);
3733
+ $mol_assert_like([...(await world2.apply(batch2)).forbid.values()], ['No auth key']);
3734
+ $mol_assert_like(land2.chief.as($hyoo_crowd_reg).numb(), 234);
3735
+ },
3736
+ async 'levels'() {
3737
+ const world1 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
3738
+ const world2 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
3739
+ const peer = await $hyoo_crowd_peer.generate();
3740
+ const land1 = await world1.grab();
3741
+ const land2 = world2.land(land1.id());
3742
+ land1.chief.sub('foo', $hyoo_crowd_reg).numb(123);
3743
+ for await (const batch of world1.delta()) {
3744
+ $mol_assert_like([...(await world2.apply(batch)).forbid.values()], []);
3745
+ }
3746
+ land2.chief.sub('foo', $hyoo_crowd_reg).numb(234);
3747
+ land2.chief.sub('bar', $hyoo_crowd_reg).numb(234);
3748
+ land2.level(peer.id, $hyoo_crowd_peer_level.law);
3749
+ $mol_assert_like(land1.delta().length, 4);
3750
+ level_get: {
3751
+ const batch = await world2.delta_batch(land2);
3752
+ $mol_assert_like([...(await world1.apply(batch)).forbid.values()], ['Level too low', 'Level too low']);
3753
+ $mol_assert_like(land1.delta().length, 5);
3754
+ $mol_assert_like(land1.chief.sub('foo', $hyoo_crowd_reg).numb(), 123);
3755
+ $mol_assert_like(land1.chief.sub('bar', $hyoo_crowd_reg).numb(), 0);
3756
+ $mol_assert_like(land1.level(peer.id), $hyoo_crowd_peer_level.get);
3757
+ }
3758
+ level_add: {
3759
+ land1.level(land2.peer().id, $hyoo_crowd_peer_level.add);
3760
+ const batch = await world2.delta_batch(land2);
3761
+ $mol_assert_like([...(await world1.apply(batch)).forbid.values()], ['Level too low']);
3762
+ $mol_assert_like(land1.delta().length, 7);
3763
+ $mol_assert_like(land1.chief.sub('foo', $hyoo_crowd_reg).numb(), 123);
3764
+ $mol_assert_like(land1.chief.sub('bar', $hyoo_crowd_reg).numb(), 234);
3765
+ $mol_assert_like(land1.level(peer.id), $hyoo_crowd_peer_level.get);
3766
+ }
3767
+ level_mod: {
3768
+ land1.level(land2.peer().id, $hyoo_crowd_peer_level.mod);
3769
+ const batch = await world2.delta_batch(land2);
3770
+ $mol_assert_like([...(await world1.apply(batch)).forbid.values()], []);
3771
+ $mol_assert_like(land1.delta().length, 7);
3772
+ $mol_assert_like(land1.chief.sub('foo', $hyoo_crowd_reg).numb(), 234);
3773
+ $mol_assert_like(land1.chief.sub('bar', $hyoo_crowd_reg).numb(), 234);
3774
+ $mol_assert_like(land1.level(peer.id), $hyoo_crowd_peer_level.get);
3775
+ }
3776
+ level_law: {
3777
+ land1.level(land2.peer().id, $hyoo_crowd_peer_level.law);
3778
+ for await (const batch of world1.delta()) {
3779
+ $mol_assert_like([...(await world2.apply(batch)).forbid.values()], []);
3780
+ }
3781
+ land2.level(peer.id, $hyoo_crowd_peer_level.law);
3782
+ const batch = await world2.delta_batch(land2);
3783
+ $mol_assert_like([...(await world1.apply(batch)).forbid.values()], []);
3784
+ $mol_assert_like(land1.delta().length, 8);
3785
+ $mol_assert_like(land1.chief.sub('foo', $hyoo_crowd_reg).numb(), 234);
3786
+ $mol_assert_like(land1.chief.sub('bar', $hyoo_crowd_reg).numb(), 234);
3787
+ $mol_assert_like(land1.level(peer.id), $hyoo_crowd_peer_level.law);
3788
+ }
3789
+ },
3790
+ async 'default level'() {
3791
+ const world1 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
3792
+ const world2 = new $hyoo_crowd_world(await $hyoo_crowd_peer.generate());
3793
+ const peer = await $hyoo_crowd_peer.generate();
3794
+ const land1 = await world1.grab();
3795
+ const land2 = world2.land(land1.id());
3796
+ land1.chief.sub('foo', $hyoo_crowd_reg).numb(123);
3797
+ const batch = await world1.delta_batch(land1);
3798
+ $mol_assert_like([...(await world2.apply(batch)).forbid.values()], []);
3799
+ land2.chief.sub('foo', $hyoo_crowd_reg).numb(234);
3800
+ land2.chief.sub('bar', $hyoo_crowd_reg).numb(234);
3801
+ land2.level(peer.id, $hyoo_crowd_peer_level.law);
3802
+ $mol_assert_like(land1.delta().length, 4);
3803
+ level_add: {
3804
+ land1.level_base($hyoo_crowd_peer_level.add);
3805
+ const batch = await world2.delta_batch(land2);
3806
+ $mol_assert_like([...(await world1.apply(batch)).forbid.values()], ['Level too low']);
3807
+ $mol_assert_like(land1.delta().length, 7);
3808
+ $mol_assert_like(land1.chief.sub('foo', $hyoo_crowd_reg).numb(), 123);
3809
+ $mol_assert_like(land1.chief.sub('bar', $hyoo_crowd_reg).numb(), 234);
3810
+ $mol_assert_like(land1.level(peer.id), $hyoo_crowd_peer_level.add);
3811
+ }
3812
+ level_mod: {
3813
+ land1.level_base($hyoo_crowd_peer_level.mod);
3814
+ const batch = await world2.delta_batch(land2);
3815
+ $mol_assert_like([...(await world1.apply(batch)).forbid.values()], []);
3816
+ $mol_assert_like(land1.delta().length, 7);
3817
+ $mol_assert_like(land1.chief.sub('foo', $hyoo_crowd_reg).numb(), 234);
3818
+ $mol_assert_like(land1.chief.sub('bar', $hyoo_crowd_reg).numb(), 234);
3819
+ $mol_assert_like(land1.level(peer.id), $hyoo_crowd_peer_level.mod);
3820
+ }
3821
+ level_law: {
3822
+ land1.level_base($hyoo_crowd_peer_level.law);
3823
+ for await (const batch of world1.delta()) {
3824
+ $mol_assert_like([...(await world2.apply(batch)).forbid.values()], []);
3825
+ }
3826
+ land2.level(peer.id, $hyoo_crowd_peer_level.law);
3827
+ const batch = await world2.delta_batch(land2);
3828
+ $mol_assert_like([...(await world1.apply(batch)).forbid.values()], []);
3829
+ $mol_assert_like(land1.delta().length, 7);
3830
+ $mol_assert_like(land1.chief.sub('foo', $hyoo_crowd_reg).numb(), 234);
3831
+ $mol_assert_like(land1.chief.sub('bar', $hyoo_crowd_reg).numb(), 234);
3832
+ $mol_assert_like(land1.level(peer.id), $hyoo_crowd_peer_level.law);
3833
+ }
3834
+ },
3835
+ });
3836
+ })($ || ($ = {}));
3837
+ //hyoo/crowd/world/world.test.ts
3838
+ ;
3839
+ "use strict";
3840
+ var $;
3841
+ (function ($) {
3842
+ $.$hyoo_sync_masters = [
3843
+ `localhost:9090`,
3844
+ $mol_dom_context.document.location.origin.replace(/^\w+:\/\//, ''),
3845
+ ];
3846
+ })($ || ($ = {}));
3847
+ //hyoo/sync/masters/masters.test.ts
3848
+ ;
3849
+ "use strict";
3850
+ //mol/type/foot/foot.test.ts
3851
+ ;
3852
+ "use strict";
3853
+ var $;
3854
+ (function ($) {
3855
+ class $mol_wire_log extends $mol_object2 {
3856
+ static watch(task) {
3857
+ return task;
3858
+ }
3859
+ static track(fiber) {
3860
+ const prev = $mol_wire_probe(() => this.track(fiber));
3861
+ let next;
3862
+ try {
3863
+ next = fiber.sync();
3864
+ }
3865
+ finally {
3866
+ for (const pub of fiber.pub_list) {
3867
+ if (pub instanceof $mol_wire_fiber) {
3868
+ this.track(pub);
3869
+ }
3870
+ }
3871
+ }
3872
+ if (fiber.host === this)
3873
+ return next;
3874
+ if ($mol_compare_deep(prev, next)) {
3875
+ this.$.$mol_log3_rise({
3876
+ message: '💧 Same',
3877
+ place: fiber,
3878
+ });
3879
+ }
3880
+ else if (prev !== undefined) {
3881
+ this.$.$mol_log3_rise({
3882
+ message: '🔥 Next',
3883
+ place: fiber,
3884
+ prev,
3885
+ });
3886
+ }
3887
+ return next;
3888
+ }
3889
+ static active() {
3890
+ try {
3891
+ this.watch()?.();
3892
+ }
3893
+ catch (error) {
3894
+ $mol_fail_log(error);
3895
+ }
3896
+ finally {
3897
+ for (const pub of $mol_wire_auto().pub_list) {
3898
+ if (pub instanceof $mol_wire_fiber) {
3899
+ this.track(pub);
3900
+ }
3901
+ }
3902
+ }
3903
+ }
3904
+ }
3905
+ __decorate([
3906
+ $mol_mem
3907
+ ], $mol_wire_log, "watch", null);
3908
+ __decorate([
3909
+ $mol_mem_key
3910
+ ], $mol_wire_log, "track", null);
3911
+ __decorate([
3912
+ $mol_mem
3913
+ ], $mol_wire_log, "active", null);
3914
+ $.$mol_wire_log = $mol_wire_log;
3915
+ })($ || ($ = {}));
3916
+ //mol/wire/log/log.ts
3917
+ ;
3918
+ "use strict";
3919
+ var $;
3920
+ (function ($) {
3921
+ $mol_wire_log.active();
3922
+ })($ || ($ = {}));
3923
+ //mol/wire/atom/atom.test.ts
3924
+ ;
3925
+ "use strict";
3926
+ var $;
3927
+ (function ($) {
3928
+ $mol_test({
3929
+ async 'put, get, drop, count records and clear store'() {
3930
+ const db = await $$.$mol_db('$mol_db_test', mig => mig.store_make('letters'));
3931
+ const trans = db.change('letters');
3932
+ try {
3933
+ const { letters } = trans.stores;
3934
+ $mol_assert_like(await letters.get(1), undefined);
3935
+ $mol_assert_like(await letters.get(2), undefined);
3936
+ $mol_assert_like(await letters.count(), 0);
3937
+ await letters.put('a');
3938
+ await letters.put('b', 1);
3939
+ await letters.put('c', 2);
3940
+ $mol_assert_like(await letters.get(1), 'b');
3941
+ $mol_assert_like(await letters.get(2), 'c');
3942
+ $mol_assert_like(await letters.count(), 2);
3943
+ await letters.drop(1);
3944
+ $mol_assert_like(await letters.get(1), undefined);
3945
+ $mol_assert_like(await letters.count(), 1);
3946
+ await letters.clear();
3947
+ $mol_assert_like(await letters.count(), 0);
3948
+ }
3949
+ finally {
3950
+ trans.abort();
3951
+ db.kill();
3952
+ }
3953
+ },
3954
+ async 'select by query'() {
3955
+ const db = await $$.$mol_db('$mol_db_test', mig => mig.store_make('letters'));
3956
+ const trans = db.change('letters');
3957
+ try {
3958
+ const { letters } = trans.stores;
3959
+ await letters.put('a');
3960
+ await letters.put('b');
3961
+ await letters.put('c');
3962
+ await letters.put('d');
3963
+ $mol_assert_like(await letters.select(), ['a', 'b', 'c', 'd']);
3964
+ $mol_assert_like(await letters.select(null, 2), ['a', 'b']);
3965
+ $mol_assert_like(await letters.select($mol_dom_context.IDBKeyRange.bound(2, 3)), ['b', 'c']);
3966
+ }
3967
+ finally {
3968
+ trans.abort();
3969
+ db.kill();
3970
+ }
3971
+ },
3972
+ });
3973
+ })($ || ($ = {}));
3974
+ //mol/db/store/store.test.ts
3975
+ ;
3976
+ "use strict";
3977
+ var $;
3978
+ (function ($) {
3979
+ $mol_test({
3980
+ async 'take and drop db'() {
3981
+ const db = await $$.$mol_db('$mol_db_test');
3982
+ await db.kill();
3983
+ },
3984
+ async 'make and drop store in separate migrations'() {
3985
+ try {
3986
+ const db1 = await $$.$mol_db('$mol_db_test', mig => mig.store_make('temp'));
3987
+ db1.destructor();
3988
+ $mol_assert_like(db1.stores, ['temp']);
3989
+ $mol_assert_like(db1.version, 2);
3990
+ const db2 = await $$.$mol_db('$mol_db_test', mig => mig.store_make('temp'), mig => mig.store_drop('temp'));
3991
+ db2.destructor();
3992
+ $mol_assert_like(db2.stores, []);
3993
+ $mol_assert_like(db2.version, 3);
3994
+ }
3995
+ finally {
3996
+ const db0 = await $$.$mol_db('$mol_db_test');
3997
+ await db0.kill();
3998
+ }
3999
+ },
4000
+ });
4001
+ })($ || ($ = {}));
4002
+ //mol/db/db.test.ts
4003
+ ;
4004
+ "use strict";
4005
+ var $;
4006
+ (function ($) {
4007
+ $mol_test({
4008
+ async 'unique index'() {
4009
+ const db = await $$.$mol_db('$mol_db_test', mig => mig.store_make('users'), mig => mig.stores.users.index_make('names', ['name'], !!'unique'));
4010
+ const trans = db.change('users');
4011
+ try {
4012
+ const { users } = trans.stores;
4013
+ await users.put({ name: 'Jin' }, 'jin');
4014
+ await users.put({ name: 'John' }, 'john');
4015
+ await users.put({ name: 'Bin' }, 'bin');
4016
+ const { names } = users.indexes;
4017
+ $mol_assert_like(await names.get(['Jin']), { name: 'Jin' });
4018
+ $mol_assert_like(await names.get(['John']), { name: 'John' });
4019
+ $mol_assert_like(await names.count(), 3);
4020
+ $mol_assert_like(await names.select($mol_dom_context.IDBKeyRange.bound(['J'], ['J\uFFFF'])), [{ name: 'Jin' }, { name: 'John' }]);
4021
+ try {
4022
+ await users.put({ name: 'Jin' }, 'jin2');
4023
+ $mol_fail(new Error('Exception expected'));
4024
+ }
4025
+ catch (error) {
4026
+ $mol_assert_unique(error.message, 'Exception expected');
4027
+ }
4028
+ }
4029
+ finally {
4030
+ trans.abort();
4031
+ await db.kill();
4032
+ }
4033
+ },
4034
+ async 'multi path index'() {
4035
+ const db = await $$.$mol_db('$mol_db_test', mig => mig.store_make('users'), mig => mig.stores.users.index_make('names', ['first', 'last']));
4036
+ const trans = db.change('users');
4037
+ try {
4038
+ const { users } = trans.stores;
4039
+ await users.put({ first: 'Jin', last: 'Johnson' }, 'jin');
4040
+ await users.put({ first: 'John', last: 'Jinson' }, 'john');
4041
+ await users.put({ first: 'Bond', last: 'James' }, '007');
4042
+ const { names } = users.indexes;
4043
+ $mol_assert_like(await names.get(['Jin', 'Johnson']), { first: 'Jin', last: 'Johnson' });
4044
+ $mol_assert_like(await names.get(['John', 'Jinson']), { first: 'John', last: 'Jinson' });
4045
+ $mol_assert_like(await names.count(), 3);
4046
+ $mol_assert_like(await names.select($mol_dom_context.IDBKeyRange.bound(['Jin', 'Johnson'], ['John', 'Jinson'])), [{ first: 'Jin', last: 'Johnson' }, { first: 'John', last: 'Jinson' }]);
4047
+ }
4048
+ finally {
4049
+ trans.abort();
4050
+ await db.kill();
4051
+ }
4052
+ },
4053
+ async 'multiple indexes'() {
4054
+ const db = await $$.$mol_db('$mol_db_test', mig => mig.store_make('users'), mig => mig.stores.users.index_make('names', ['name'], !!'unique'), mig => mig.stores.users.index_make('ages', ['age']));
4055
+ const trans = db.change('users');
4056
+ try {
4057
+ const { users } = trans.stores;
4058
+ await users.put({ name: 'Jin', age: 18 }, 'jin');
4059
+ await users.put({ name: 'John', age: 18 }, 'john');
4060
+ const { names, ages } = users.indexes;
4061
+ $mol_assert_like(await names.select(['Jin']), [{ name: 'Jin', age: 18 }]);
4062
+ $mol_assert_like(await names.select(['John']), [{ name: 'John', age: 18 }]);
4063
+ $mol_assert_like(await names.count(), 2);
4064
+ $mol_assert_like(await ages.select([18]), [{ name: 'Jin', age: 18 }, { name: 'John', age: 18 }]);
4065
+ $mol_assert_like(await ages.count(), 2);
4066
+ }
4067
+ finally {
4068
+ trans.abort();
4069
+ await db.kill();
4070
+ }
4071
+ },
4072
+ });
4073
+ })($ || ($ = {}));
4074
+ //mol/db/index/index.test.ts
4075
+ ;
4076
+ "use strict";
4077
+ var $;
4078
+ (function ($_1) {
4079
+ $mol_test_mocks.push($ => {
4080
+ $.$hyoo_sync_client = class extends $hyoo_sync_yard {
4081
+ land_init(land) { }
4082
+ };
4083
+ });
4084
+ })($ || ($ = {}));
4085
+ //hyoo/sync/client/client.test.ts
4086
+
4087
+ //# sourceMappingURL=web.test.js.map