mol_db 0.0.45

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,1003 @@
1
+ "use strict";
2
+ function require( path ){ return $node[ path ] };
3
+ "use strict";
4
+ var $;
5
+ (function ($) {
6
+ function $mol_fail(error) {
7
+ throw error;
8
+ }
9
+ $.$mol_fail = $mol_fail;
10
+ })($ || ($ = {}));
11
+ //fail.js.map
12
+ ;
13
+ "use strict";
14
+ var $;
15
+ (function ($) {
16
+ function $mol_fail_hidden(error) {
17
+ throw error;
18
+ }
19
+ $.$mol_fail_hidden = $mol_fail_hidden;
20
+ })($ || ($ = {}));
21
+ //hidden.js.map
22
+ ;
23
+ "use strict";
24
+ var $;
25
+ (function ($_1) {
26
+ function $mol_test(set) {
27
+ for (let name in set) {
28
+ const code = set[name];
29
+ const test = (typeof code === 'string') ? new Function('', code) : code;
30
+ $_1.$mol_test_all.push(test);
31
+ }
32
+ $mol_test_schedule();
33
+ }
34
+ $_1.$mol_test = $mol_test;
35
+ $_1.$mol_test_mocks = [];
36
+ $_1.$mol_test_all = [];
37
+ async function $mol_test_run() {
38
+ for (var test of $_1.$mol_test_all) {
39
+ let context = Object.create($_1.$$);
40
+ for (let mock of $_1.$mol_test_mocks)
41
+ await mock(context);
42
+ await test(context);
43
+ }
44
+ $_1.$$.$mol_log3_done({
45
+ place: '$mol_test',
46
+ message: 'All tests passed',
47
+ count: $_1.$mol_test_all.length,
48
+ });
49
+ }
50
+ $_1.$mol_test_run = $mol_test_run;
51
+ let scheduled = false;
52
+ function $mol_test_schedule() {
53
+ if (scheduled)
54
+ return;
55
+ scheduled = true;
56
+ setTimeout(async () => {
57
+ scheduled = false;
58
+ try {
59
+ await $mol_test_run();
60
+ }
61
+ finally {
62
+ $_1.$$.$mol_test_complete();
63
+ }
64
+ }, 0);
65
+ }
66
+ $_1.$mol_test_schedule = $mol_test_schedule;
67
+ $_1.$mol_test_mocks.push(context => {
68
+ let seed = 0;
69
+ context.Math = Object.create(Math);
70
+ context.Math.random = () => Math.sin(seed++);
71
+ const forbidden = ['XMLHttpRequest', 'fetch'];
72
+ for (let api of forbidden) {
73
+ context[api] = new Proxy(function () { }, {
74
+ get() {
75
+ $_1.$mol_fail_hidden(new Error(`${api} is forbidden in tests`));
76
+ },
77
+ apply() {
78
+ $_1.$mol_fail_hidden(new Error(`${api} is forbidden in tests`));
79
+ },
80
+ });
81
+ }
82
+ });
83
+ $mol_test({
84
+ 'mocked Math.random'($) {
85
+ console.assert($.Math.random() === 0);
86
+ console.assert($.Math.random() === Math.sin(1));
87
+ },
88
+ 'forbidden XMLHttpRequest'($) {
89
+ try {
90
+ console.assert(void new $.XMLHttpRequest);
91
+ }
92
+ catch (error) {
93
+ console.assert(error.message === 'XMLHttpRequest is forbidden in tests');
94
+ }
95
+ },
96
+ 'forbidden fetch'($) {
97
+ try {
98
+ console.assert(void $.fetch(''));
99
+ }
100
+ catch (error) {
101
+ console.assert(error.message === 'fetch is forbidden in tests');
102
+ }
103
+ },
104
+ });
105
+ })($ || ($ = {}));
106
+ //test.test.js.map
107
+ ;
108
+ "use strict";
109
+ var $;
110
+ (function ($) {
111
+ function $mol_test_complete() {
112
+ }
113
+ $.$mol_test_complete = $mol_test_complete;
114
+ })($ || ($ = {}));
115
+ //test.web.test.js.map
116
+ ;
117
+ "use strict";
118
+ var $;
119
+ (function ($) {
120
+ })($ || ($ = {}));
121
+ //context.js.map
122
+ ;
123
+ "use strict";
124
+ var $;
125
+ (function ($) {
126
+ $.$mol_dom_context = self;
127
+ })($ || ($ = {}));
128
+ //context.web.js.map
129
+ ;
130
+ "use strict";
131
+ var $;
132
+ (function ($) {
133
+ function $mol_dom_render_children(el, childNodes) {
134
+ const node_set = new Set(childNodes);
135
+ let nextNode = el.firstChild;
136
+ for (let view of childNodes) {
137
+ if (view == null)
138
+ continue;
139
+ if (view instanceof $.$mol_dom_context.Node) {
140
+ while (true) {
141
+ if (!nextNode) {
142
+ el.appendChild(view);
143
+ break;
144
+ }
145
+ if (nextNode == view) {
146
+ nextNode = nextNode.nextSibling;
147
+ break;
148
+ }
149
+ else {
150
+ if (node_set.has(nextNode)) {
151
+ el.insertBefore(view, nextNode);
152
+ break;
153
+ }
154
+ else {
155
+ const nn = nextNode.nextSibling;
156
+ el.removeChild(nextNode);
157
+ nextNode = nn;
158
+ }
159
+ }
160
+ }
161
+ }
162
+ else {
163
+ if (nextNode && nextNode.nodeName === '#text') {
164
+ const str = String(view);
165
+ if (nextNode.nodeValue !== str)
166
+ nextNode.nodeValue = str;
167
+ nextNode = nextNode.nextSibling;
168
+ }
169
+ else {
170
+ const textNode = $.$mol_dom_context.document.createTextNode(String(view));
171
+ el.insertBefore(textNode, nextNode);
172
+ }
173
+ }
174
+ }
175
+ while (nextNode) {
176
+ const currNode = nextNode;
177
+ nextNode = currNode.nextSibling;
178
+ el.removeChild(currNode);
179
+ }
180
+ }
181
+ $.$mol_dom_render_children = $mol_dom_render_children;
182
+ })($ || ($ = {}));
183
+ //children.js.map
184
+ ;
185
+ "use strict";
186
+ //error.js.map
187
+ ;
188
+ "use strict";
189
+ //assert.test.js.map
190
+ ;
191
+ "use strict";
192
+ //assert.js.map
193
+ ;
194
+ "use strict";
195
+ //deep.test.js.map
196
+ ;
197
+ "use strict";
198
+ //deep.js.map
199
+ ;
200
+ "use strict";
201
+ var $;
202
+ (function ($) {
203
+ $.$mol_test({
204
+ 'Make empty div'() {
205
+ $.$mol_assert_equal(($.$mol_jsx("div", null)).outerHTML, '<div></div>');
206
+ },
207
+ 'Define native field'() {
208
+ const dom = $.$mol_jsx("input", { value: '123' });
209
+ $.$mol_assert_equal(dom.outerHTML, '<input value="123">');
210
+ $.$mol_assert_equal(dom.value, '123');
211
+ },
212
+ 'Define classes'() {
213
+ const dom = $.$mol_jsx("div", { class: 'foo bar' });
214
+ $.$mol_assert_equal(dom.outerHTML, '<div class="foo bar"></div>');
215
+ },
216
+ 'Define styles'() {
217
+ const dom = $.$mol_jsx("div", { style: { color: 'red' } });
218
+ $.$mol_assert_equal(dom.outerHTML, '<div style="color: red;"></div>');
219
+ },
220
+ 'Define dataset'() {
221
+ const dom = $.$mol_jsx("div", { dataset: { foo: 'bar' } });
222
+ $.$mol_assert_equal(dom.outerHTML, '<div data-foo="bar"></div>');
223
+ },
224
+ 'Define attributes'() {
225
+ const dom = $.$mol_jsx("div", { lang: "ru", hidden: true });
226
+ $.$mol_assert_equal(dom.outerHTML, '<div lang="ru" hidden=""></div>');
227
+ },
228
+ 'Define child nodes'() {
229
+ const dom = $.$mol_jsx("div", null,
230
+ "hello",
231
+ $.$mol_jsx("strong", null, "world"),
232
+ "!");
233
+ $.$mol_assert_equal(dom.outerHTML, '<div>hello<strong>world</strong>!</div>');
234
+ },
235
+ 'Function as component'() {
236
+ const Button = ({ hint }, target) => {
237
+ return $.$mol_jsx("button", { title: hint }, target());
238
+ };
239
+ const dom = $.$mol_jsx(Button, { id: "/foo", hint: "click me" }, () => 'hey!');
240
+ $.$mol_assert_equal(dom.outerHTML, '<button title="click me" id="/foo">hey!</button>');
241
+ },
242
+ 'Nested guid generation'() {
243
+ const Foo = () => {
244
+ return $.$mol_jsx("div", null,
245
+ $.$mol_jsx(Bar, { id: "/bar" },
246
+ $.$mol_jsx("img", { id: "/icon" })));
247
+ };
248
+ const Bar = (props, icon) => {
249
+ return $.$mol_jsx("span", null, icon);
250
+ };
251
+ const dom = $.$mol_jsx(Foo, { id: "/foo" });
252
+ $.$mol_assert_equal(dom.outerHTML, '<div id="/foo"><span id="/foo/bar"><img id="/foo/icon"></span></div>');
253
+ },
254
+ 'Fail on non unique ids'() {
255
+ const App = () => {
256
+ return $.$mol_jsx("div", null,
257
+ $.$mol_jsx("span", { id: "/bar" }),
258
+ $.$mol_jsx("span", { id: "/bar" }));
259
+ };
260
+ $.$mol_assert_fail(() => $.$mol_jsx(App, { id: "/foo" }), 'JSX already has tag with id "/bar"');
261
+ },
262
+ });
263
+ })($ || ($ = {}));
264
+ //jsx.test.js.map
265
+ ;
266
+ "use strict";
267
+ var $;
268
+ (function ($) {
269
+ $.$mol_jsx_prefix = '';
270
+ $.$mol_jsx_booked = null;
271
+ $.$mol_jsx_document = {
272
+ getElementById: () => null,
273
+ createElementNS: (space, name) => $.$mol_dom_context.document.createElementNS(space, name),
274
+ createDocumentFragment: () => $.$mol_dom_context.document.createDocumentFragment(),
275
+ };
276
+ $.$mol_jsx_frag = '';
277
+ function $mol_jsx(Elem, props, ...childNodes) {
278
+ const id = props && props.id || '';
279
+ if (Elem && $.$mol_jsx_booked) {
280
+ if ($.$mol_jsx_booked.has(id)) {
281
+ $.$mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(id)}`));
282
+ }
283
+ else {
284
+ $.$mol_jsx_booked.add(id);
285
+ }
286
+ }
287
+ const guid = $.$mol_jsx_prefix + id;
288
+ let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
289
+ if (typeof Elem !== 'string') {
290
+ if ('prototype' in Elem) {
291
+ const view = node && node[Elem] || new Elem;
292
+ Object.assign(view, props);
293
+ view[Symbol.toStringTag] = guid;
294
+ view.childNodes = childNodes;
295
+ if (!view.ownerDocument)
296
+ view.ownerDocument = $.$mol_jsx_document;
297
+ node = view.valueOf();
298
+ node[Elem] = view;
299
+ return node;
300
+ }
301
+ else {
302
+ const prefix = $.$mol_jsx_prefix;
303
+ const booked = $.$mol_jsx_booked;
304
+ try {
305
+ $.$mol_jsx_prefix = guid;
306
+ $.$mol_jsx_booked = new Set;
307
+ return Elem(props, ...childNodes);
308
+ }
309
+ finally {
310
+ $.$mol_jsx_prefix = prefix;
311
+ $.$mol_jsx_booked = booked;
312
+ }
313
+ }
314
+ }
315
+ if (!node) {
316
+ node = Elem
317
+ ? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
318
+ : $.$mol_jsx_document.createDocumentFragment();
319
+ }
320
+ $.$mol_dom_render_children(node, [].concat(...childNodes));
321
+ if (!Elem)
322
+ return node;
323
+ for (const key in props) {
324
+ if (typeof props[key] === 'string') {
325
+ ;
326
+ node.setAttribute(key, props[key]);
327
+ }
328
+ else if (props[key] &&
329
+ typeof props[key] === 'object' &&
330
+ Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
331
+ if (typeof node[key] === 'object') {
332
+ Object.assign(node[key], props[key]);
333
+ continue;
334
+ }
335
+ }
336
+ else {
337
+ node[key] = props[key];
338
+ }
339
+ }
340
+ if (guid)
341
+ node.id = guid;
342
+ return node;
343
+ }
344
+ $.$mol_jsx = $mol_jsx;
345
+ })($ || ($ = {}));
346
+ //jsx.js.map
347
+ ;
348
+ "use strict";
349
+ var $;
350
+ (function ($) {
351
+ $.$mol_test({
352
+ 'nulls & undefineds'() {
353
+ $.$mol_assert_ok($.$mol_compare_deep(null, null));
354
+ $.$mol_assert_ok($.$mol_compare_deep(undefined, undefined));
355
+ $.$mol_assert_not($.$mol_compare_deep(undefined, null));
356
+ $.$mol_assert_not($.$mol_compare_deep({}, null));
357
+ },
358
+ 'number'() {
359
+ $.$mol_assert_ok($.$mol_compare_deep(1, 1));
360
+ $.$mol_assert_ok($.$mol_compare_deep(Number.NaN, Number.NaN));
361
+ $.$mol_assert_not($.$mol_compare_deep(1, 2));
362
+ },
363
+ 'Number'() {
364
+ $.$mol_assert_ok($.$mol_compare_deep(Object(1), Object(1)));
365
+ $.$mol_assert_ok($.$mol_compare_deep(Object(Number.NaN), Object(Number.NaN)));
366
+ $.$mol_assert_not($.$mol_compare_deep(Object(1), Object(2)));
367
+ },
368
+ 'empty POJOs'() {
369
+ $.$mol_assert_ok($.$mol_compare_deep({}, {}));
370
+ },
371
+ 'different POJOs'() {
372
+ $.$mol_assert_not($.$mol_compare_deep({ a: 1 }, { b: 2 }));
373
+ },
374
+ 'different POJOs with same keys but different values'() {
375
+ $.$mol_assert_not($.$mol_compare_deep({ a: 1 }, { a: 2 }));
376
+ },
377
+ 'different POJOs with different keys but same values'() {
378
+ $.$mol_assert_not($.$mol_compare_deep({}, { a: undefined }));
379
+ },
380
+ 'Array'() {
381
+ $.$mol_assert_ok($.$mol_compare_deep([], []));
382
+ $.$mol_assert_ok($.$mol_compare_deep([1, [2]], [1, [2]]));
383
+ $.$mol_assert_not($.$mol_compare_deep([1, 2], [1, 3]));
384
+ $.$mol_assert_not($.$mol_compare_deep([1, 2,], [1, 3, undefined]));
385
+ },
386
+ 'same POJO trees'() {
387
+ $.$mol_assert_ok($.$mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
388
+ },
389
+ 'different classes with same values'() {
390
+ class Obj {
391
+ foo = 1;
392
+ }
393
+ const a = new Obj;
394
+ const b = new class extends Obj {
395
+ };
396
+ $.$mol_assert_not($.$mol_compare_deep(a, b));
397
+ },
398
+ 'same POJOs with cyclic reference'() {
399
+ const a = { foo: {} };
400
+ a['self'] = a;
401
+ const b = { foo: {} };
402
+ b['self'] = b;
403
+ $.$mol_assert_ok($.$mol_compare_deep(a, b));
404
+ },
405
+ 'empty Element'() {
406
+ $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", null), $.$mol_jsx("div", null)));
407
+ $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null), $.$mol_jsx("span", null)));
408
+ },
409
+ 'Element with attributes'() {
410
+ $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", { dir: "rtl" })));
411
+ $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", null)));
412
+ $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", { dir: "ltr" })));
413
+ },
414
+ 'Element with styles'() {
415
+ $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: { color: 'red' } })));
416
+ $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: {} })));
417
+ $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: { color: 'blue' } })));
418
+ },
419
+ 'Element with content'() {
420
+ $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", null,
421
+ "foo",
422
+ $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
423
+ "foo",
424
+ $.$mol_jsx("br", null))));
425
+ $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null,
426
+ "foo",
427
+ $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
428
+ "bar",
429
+ $.$mol_jsx("br", null))));
430
+ $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null,
431
+ "foo",
432
+ $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
433
+ "foo",
434
+ $.$mol_jsx("hr", null))));
435
+ },
436
+ 'Element with handlers'() {
437
+ $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { onclick: () => 1 }), $.$mol_jsx("div", { onclick: () => 1 })));
438
+ $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { onclick: () => 1 }), $.$mol_jsx("div", { onclick: () => 2 })));
439
+ },
440
+ 'Date'() {
441
+ $.$mol_assert_ok($.$mol_compare_deep(new Date(12345), new Date(12345)));
442
+ $.$mol_assert_not($.$mol_compare_deep(new Date(12345), new Date(12346)));
443
+ },
444
+ 'RegExp'() {
445
+ $.$mol_assert_ok($.$mol_compare_deep(/\x22/mig, /\x22/mig));
446
+ $.$mol_assert_not($.$mol_compare_deep(/\x22/mig, /\x21/mig));
447
+ $.$mol_assert_not($.$mol_compare_deep(/\x22/mig, /\x22/mg));
448
+ },
449
+ 'Map'() {
450
+ $.$mol_assert_ok($.$mol_compare_deep(new Map, new Map));
451
+ $.$mol_assert_ok($.$mol_compare_deep(new Map([[[1], [2]]]), new Map([[[1], [2]]])));
452
+ $.$mol_assert_not($.$mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
453
+ },
454
+ 'Set'() {
455
+ $.$mol_assert_ok($.$mol_compare_deep(new Set, new Set));
456
+ $.$mol_assert_ok($.$mol_compare_deep(new Set([1, [2]]), new Set([1, [2]])));
457
+ $.$mol_assert_not($.$mol_compare_deep(new Set([1]), new Set([2])));
458
+ },
459
+ 'Uint8Array'() {
460
+ $.$mol_assert_ok($.$mol_compare_deep(new Uint8Array, new Uint8Array));
461
+ $.$mol_assert_ok($.$mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
462
+ $.$mol_assert_not($.$mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
463
+ },
464
+ });
465
+ })($ || ($ = {}));
466
+ //deep.test.js.map
467
+ ;
468
+ "use strict";
469
+ var $;
470
+ (function ($) {
471
+ const a_stack = [];
472
+ const b_stack = [];
473
+ let cache = null;
474
+ function $mol_compare_deep(a, b) {
475
+ if (Object.is(a, b))
476
+ return true;
477
+ const a_type = typeof a;
478
+ const b_type = typeof b;
479
+ if (a_type !== b_type)
480
+ return false;
481
+ if (a_type === 'function')
482
+ return a['toString']() === b['toString']();
483
+ if (a_type !== 'object')
484
+ return false;
485
+ if (!a || !b)
486
+ return false;
487
+ if (a instanceof Error)
488
+ return false;
489
+ if (a['constructor'] !== b['constructor'])
490
+ return false;
491
+ if (a instanceof RegExp)
492
+ return a.toString() === b['toString']();
493
+ const ref = a_stack.indexOf(a);
494
+ if (ref >= 0) {
495
+ return Object.is(b_stack[ref], b);
496
+ }
497
+ if (!cache)
498
+ cache = new WeakMap;
499
+ let a_cache = cache.get(a);
500
+ if (a_cache) {
501
+ const b_cache = a_cache.get(b);
502
+ if (typeof b_cache === 'boolean')
503
+ return b_cache;
504
+ }
505
+ else {
506
+ a_cache = new WeakMap();
507
+ cache.set(a, a_cache);
508
+ }
509
+ a_stack.push(a);
510
+ b_stack.push(b);
511
+ let result;
512
+ try {
513
+ if (Symbol.iterator in a) {
514
+ const a_iter = a[Symbol.iterator]();
515
+ const b_iter = b[Symbol.iterator]();
516
+ while (true) {
517
+ const a_next = a_iter.next();
518
+ const b_next = b_iter.next();
519
+ if (a_next.done !== b_next.done)
520
+ return result = false;
521
+ if (a_next.done)
522
+ break;
523
+ if (!$mol_compare_deep(a_next.value, b_next.value))
524
+ return result = false;
525
+ }
526
+ return result = true;
527
+ }
528
+ let count = 0;
529
+ for (let key in a) {
530
+ try {
531
+ if (!$mol_compare_deep(a[key], b[key]))
532
+ return result = false;
533
+ }
534
+ catch (error) {
535
+ $.$mol_fail_hidden(new $.$mol_error_mix(`Failed ${JSON.stringify(key)} fields comparison of ${a} and ${b}`, error));
536
+ }
537
+ ++count;
538
+ }
539
+ for (let key in b) {
540
+ --count;
541
+ if (count < 0)
542
+ return result = false;
543
+ }
544
+ if (a instanceof Number || a instanceof String || a instanceof Symbol || a instanceof Boolean || a instanceof Date) {
545
+ if (!Object.is(a['valueOf'](), b['valueOf']()))
546
+ return result = false;
547
+ }
548
+ return result = true;
549
+ }
550
+ finally {
551
+ a_stack.pop();
552
+ b_stack.pop();
553
+ if (a_stack.length === 0) {
554
+ cache = null;
555
+ }
556
+ else {
557
+ a_cache.set(b, result);
558
+ }
559
+ }
560
+ }
561
+ $.$mol_compare_deep = $mol_compare_deep;
562
+ })($ || ($ = {}));
563
+ //deep.js.map
564
+ ;
565
+ "use strict";
566
+ var $;
567
+ (function ($) {
568
+ $.$mol_test({
569
+ 'must be false'() {
570
+ $.$mol_assert_not(0);
571
+ },
572
+ 'must be true'() {
573
+ $.$mol_assert_ok(1);
574
+ },
575
+ 'two must be equal'() {
576
+ $.$mol_assert_equal(2, 2);
577
+ },
578
+ 'three must be equal'() {
579
+ $.$mol_assert_equal(2, 2, 2);
580
+ },
581
+ 'two must be unique'() {
582
+ $.$mol_assert_unique([3], [3]);
583
+ },
584
+ 'three must be unique'() {
585
+ $.$mol_assert_unique([3], [3], [3]);
586
+ },
587
+ 'two must be alike'() {
588
+ $.$mol_assert_like([3], [3]);
589
+ },
590
+ 'three must be alike'() {
591
+ $.$mol_assert_like([3], [3], [3]);
592
+ },
593
+ });
594
+ })($ || ($ = {}));
595
+ //assert.test.js.map
596
+ ;
597
+ "use strict";
598
+ var $;
599
+ (function ($) {
600
+ function $mol_assert_ok(value) {
601
+ if (value)
602
+ return;
603
+ $.$mol_fail(new Error(`${value} ≠ true`));
604
+ }
605
+ $.$mol_assert_ok = $mol_assert_ok;
606
+ function $mol_assert_not(value) {
607
+ if (!value)
608
+ return;
609
+ $.$mol_fail(new Error(`${value} ≠ false`));
610
+ }
611
+ $.$mol_assert_not = $mol_assert_not;
612
+ function $mol_assert_fail(handler, ErrorRight) {
613
+ const fail = $.$mol_fail;
614
+ try {
615
+ $.$mol_fail = $.$mol_fail_hidden;
616
+ handler();
617
+ }
618
+ catch (error) {
619
+ if (!ErrorRight)
620
+ return error;
621
+ $.$mol_fail = fail;
622
+ if (typeof ErrorRight === 'string') {
623
+ $mol_assert_equal(error.message, ErrorRight);
624
+ }
625
+ else {
626
+ $mol_assert_ok(error instanceof ErrorRight);
627
+ }
628
+ return error;
629
+ }
630
+ finally {
631
+ $.$mol_fail = fail;
632
+ }
633
+ $.$mol_fail(new Error('Not failed'));
634
+ }
635
+ $.$mol_assert_fail = $mol_assert_fail;
636
+ function $mol_assert_equal(...args) {
637
+ for (let i = 0; i < args.length; ++i) {
638
+ for (let j = 0; j < args.length; ++j) {
639
+ if (i === j)
640
+ continue;
641
+ if (Number.isNaN(args[i]) && Number.isNaN(args[j]))
642
+ continue;
643
+ if (args[i] !== args[j])
644
+ $.$mol_fail(new Error(`Not equal (${i + 1}:${j + 1})\n${args[i]}\n${args[j]}`));
645
+ }
646
+ }
647
+ }
648
+ $.$mol_assert_equal = $mol_assert_equal;
649
+ function $mol_assert_unique(...args) {
650
+ for (let i = 0; i < args.length; ++i) {
651
+ for (let j = 0; j < args.length; ++j) {
652
+ if (i === j)
653
+ continue;
654
+ if (args[i] === args[j] || (Number.isNaN(args[i]) && Number.isNaN(args[j]))) {
655
+ $.$mol_fail(new Error(`args[${i}] = args[${j}] = ${args[i]}`));
656
+ }
657
+ }
658
+ }
659
+ }
660
+ $.$mol_assert_unique = $mol_assert_unique;
661
+ function $mol_assert_like(head, ...tail) {
662
+ for (let [index, value] of Object.entries(tail)) {
663
+ if (!$.$mol_compare_deep(value, head)) {
664
+ const print = (val) => {
665
+ if (!val)
666
+ return val;
667
+ if (typeof val !== 'object')
668
+ return val;
669
+ if ('outerHTML' in val)
670
+ return val.outerHTML;
671
+ try {
672
+ return JSON.stringify(val);
673
+ }
674
+ catch (error) {
675
+ console.error(error);
676
+ return val;
677
+ }
678
+ };
679
+ return $.$mol_fail(new Error(`Not like (1:${+index + 2})\n${print(head)}\n---\n${print(value)}`));
680
+ }
681
+ }
682
+ }
683
+ $.$mol_assert_like = $mol_assert_like;
684
+ })($ || ($ = {}));
685
+ //assert.js.map
686
+ ;
687
+ "use strict";
688
+ var $;
689
+ (function ($) {
690
+ $.$mol_test({
691
+ async 'put, get, drop, count records and clear store'() {
692
+ const db = await $.$$.$mol_db('$mol_db_test', mig => mig.store_make('letters'));
693
+ const trans = db.change('letters');
694
+ try {
695
+ const { letters } = trans.stores;
696
+ $.$mol_assert_like(await letters.get(1), undefined);
697
+ $.$mol_assert_like(await letters.get(2), undefined);
698
+ $.$mol_assert_like(await letters.count(), 0);
699
+ await letters.put('a');
700
+ await letters.put('b', 1);
701
+ await letters.put('c', 2);
702
+ $.$mol_assert_like(await letters.get(1), 'b');
703
+ $.$mol_assert_like(await letters.get(2), 'c');
704
+ $.$mol_assert_like(await letters.count(), 2);
705
+ await letters.drop(1);
706
+ $.$mol_assert_like(await letters.get(1), undefined);
707
+ $.$mol_assert_like(await letters.count(), 1);
708
+ await letters.clear();
709
+ $.$mol_assert_like(await letters.count(), 0);
710
+ }
711
+ finally {
712
+ trans.abort();
713
+ db.kill();
714
+ }
715
+ },
716
+ async 'select by query'() {
717
+ const db = await $.$$.$mol_db('$mol_db_test', mig => mig.store_make('letters'));
718
+ const trans = db.change('letters');
719
+ try {
720
+ const { letters } = trans.stores;
721
+ await letters.put('a');
722
+ await letters.put('b');
723
+ await letters.put('c');
724
+ await letters.put('d');
725
+ $.$mol_assert_like(await letters.select(), ['a', 'b', 'c', 'd']);
726
+ $.$mol_assert_like(await letters.select(null, 2), ['a', 'b']);
727
+ $.$mol_assert_like(await letters.select(IDBKeyRange.bound(2, 3)), ['b', 'c']);
728
+ }
729
+ finally {
730
+ trans.abort();
731
+ db.kill();
732
+ }
733
+ },
734
+ });
735
+ })($ || ($ = {}));
736
+ //store.test.js.map
737
+ ;
738
+ "use strict";
739
+ var $;
740
+ (function ($) {
741
+ $.$mol_test({
742
+ async 'take and drop db'() {
743
+ const db = await $.$$.$mol_db('$mol_db_test');
744
+ await db.kill();
745
+ },
746
+ async 'make and drop store in separate migrations'() {
747
+ try {
748
+ const db1 = await $.$$.$mol_db('$mol_db_test', mig => mig.store_make('temp'));
749
+ db1.destructor();
750
+ $.$mol_assert_like(db1.stores, ['temp']);
751
+ $.$mol_assert_like(db1.version, 2);
752
+ const db2 = await $.$$.$mol_db('$mol_db_test', mig => mig.store_make('temp'), mig => mig.store_drop('temp'));
753
+ db2.destructor();
754
+ $.$mol_assert_like(db2.stores, []);
755
+ $.$mol_assert_like(db2.version, 3);
756
+ }
757
+ finally {
758
+ const db0 = await $.$$.$mol_db('$mol_db_test');
759
+ await db0.kill();
760
+ }
761
+ },
762
+ });
763
+ })($ || ($ = {}));
764
+ //db.test.js.map
765
+ ;
766
+ "use strict";
767
+ var $;
768
+ (function ($) {
769
+ function $mol_log3_area_lazy(event) {
770
+ const self = this;
771
+ const stack = self.$mol_log3_stack;
772
+ const deep = stack.length;
773
+ let logged = false;
774
+ stack.push(() => {
775
+ logged = true;
776
+ self.$mol_log3_area.call(self, event);
777
+ });
778
+ return () => {
779
+ if (logged)
780
+ self.console.groupEnd();
781
+ if (stack.length > deep)
782
+ stack.length = deep;
783
+ };
784
+ }
785
+ $.$mol_log3_area_lazy = $mol_log3_area_lazy;
786
+ $.$mol_log3_stack = [];
787
+ })($ || ($ = {}));
788
+ //log3.js.map
789
+ ;
790
+ "use strict";
791
+ //extract.test.js.map
792
+ ;
793
+ "use strict";
794
+ //extract.js.map
795
+ ;
796
+ "use strict";
797
+ var $;
798
+ (function ($_1) {
799
+ $_1.$mol_test_mocks.push($ => {
800
+ $.$mol_log3_come = () => { };
801
+ $.$mol_log3_done = () => { };
802
+ $.$mol_log3_fail = () => { };
803
+ $.$mol_log3_warn = () => { };
804
+ $.$mol_log3_rise = () => { };
805
+ $.$mol_log3_area = () => () => { };
806
+ });
807
+ })($ || ($ = {}));
808
+ //log3.test.js.map
809
+ ;
810
+ "use strict";
811
+ var $;
812
+ (function ($) {
813
+ function $mol_log3_web_make(level, color) {
814
+ return function $mol_log3_logger(event) {
815
+ const pending = this.$mol_log3_stack.pop();
816
+ if (pending)
817
+ pending();
818
+ let tpl = '%c';
819
+ const chunks = Object.values(event);
820
+ for (let i = 0; i < chunks.length; ++i) {
821
+ tpl += (typeof chunks[i] === 'string') ? ' ⦙ %s' : ' ⦙ %o';
822
+ }
823
+ const style = `color:${color};font-weight:bolder`;
824
+ this.console[level](tpl, style, ...chunks);
825
+ const self = this;
826
+ return () => self.console.groupEnd();
827
+ };
828
+ }
829
+ $.$mol_log3_web_make = $mol_log3_web_make;
830
+ $.$mol_log3_come = $mol_log3_web_make('info', 'royalblue');
831
+ $.$mol_log3_done = $mol_log3_web_make('info', 'forestgreen');
832
+ $.$mol_log3_fail = $mol_log3_web_make('error', 'orangered');
833
+ $.$mol_log3_warn = $mol_log3_web_make('warn', 'goldenrod');
834
+ $.$mol_log3_rise = $mol_log3_web_make('log', 'magenta');
835
+ $.$mol_log3_area = $mol_log3_web_make('group', 'cyan');
836
+ })($ || ($ = {}));
837
+ //log3.web.js.map
838
+ ;
839
+ "use strict";
840
+ //equals.test.js.map
841
+ ;
842
+ "use strict";
843
+ //equals.js.map
844
+ ;
845
+ "use strict";
846
+ var $;
847
+ (function ($) {
848
+ $.$mol_test({
849
+ 'equal paths'() {
850
+ const diff = $.$mol_diff_path([1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]);
851
+ $.$mol_assert_like(diff, {
852
+ prefix: [1, 2, 3, 4],
853
+ suffix: [[], [], []],
854
+ });
855
+ },
856
+ 'different suffix'() {
857
+ const diff = $.$mol_diff_path([1, 2, 3, 4], [1, 2, 3, 5], [1, 2, 5, 4]);
858
+ $.$mol_assert_like(diff, {
859
+ prefix: [1, 2],
860
+ suffix: [[3, 4], [3, 5], [5, 4]],
861
+ });
862
+ },
863
+ 'one contains other'() {
864
+ const diff = $.$mol_diff_path([1, 2, 3, 4], [1, 2], [1, 2, 3]);
865
+ $.$mol_assert_like(diff, {
866
+ prefix: [1, 2],
867
+ suffix: [[3, 4], [], [3]],
868
+ });
869
+ },
870
+ 'fully different'() {
871
+ const diff = $.$mol_diff_path([1, 2], [3, 4], [5, 6]);
872
+ $.$mol_assert_like(diff, {
873
+ prefix: [],
874
+ suffix: [[1, 2], [3, 4], [5, 6]],
875
+ });
876
+ },
877
+ });
878
+ })($ || ($ = {}));
879
+ //path.test.js.map
880
+ ;
881
+ "use strict";
882
+ var $;
883
+ (function ($) {
884
+ function $mol_diff_path(...paths) {
885
+ const limit = Math.min(...paths.map(path => path.length));
886
+ lookup: for (var i = 0; i < limit; ++i) {
887
+ const first = paths[0][i];
888
+ for (let j = 1; j < paths.length; ++j) {
889
+ if (paths[j][i] !== first)
890
+ break lookup;
891
+ }
892
+ }
893
+ return {
894
+ prefix: paths[0].slice(0, i),
895
+ suffix: paths.map(path => path.slice(i)),
896
+ };
897
+ }
898
+ $.$mol_diff_path = $mol_diff_path;
899
+ })($ || ($ = {}));
900
+ //path.js.map
901
+ ;
902
+ "use strict";
903
+ var $;
904
+ (function ($) {
905
+ class $mol_error_mix extends Error {
906
+ errors;
907
+ constructor(message, ...errors) {
908
+ super(message);
909
+ this.errors = errors;
910
+ if (errors.length) {
911
+ const stacks = [...errors.map(error => error.stack), this.stack];
912
+ const diff = $.$mol_diff_path(...stacks.map(stack => {
913
+ if (!stack)
914
+ return [];
915
+ return stack.split('\n').reverse();
916
+ }));
917
+ const head = diff.prefix.reverse().join('\n');
918
+ const tails = diff.suffix.map(path => path.reverse().map(line => line.replace(/^(?!\s+at)/, '\tat (.) ')).join('\n')).join('\n\tat (.) -----\n');
919
+ this.stack = `Error: ${this.constructor.name}\n\tat (.) /"""\\\n${tails}\n\tat (.) \\___/\n${head}`;
920
+ this.message += errors.map(error => '\n' + error.message).join('');
921
+ }
922
+ }
923
+ toJSON() {
924
+ return this.message;
925
+ }
926
+ }
927
+ $.$mol_error_mix = $mol_error_mix;
928
+ })($ || ($ = {}));
929
+ //mix.js.map
930
+ ;
931
+ "use strict";
932
+ var $;
933
+ (function ($) {
934
+ $.$mol_test({
935
+ async 'unique index'() {
936
+ const db = await $.$$.$mol_db('$mol_db_test', mig => mig.store_make('users'), mig => mig.stores.users.index_make('names', ['name'], !!'unique'));
937
+ const trans = db.change('users');
938
+ try {
939
+ const { users } = trans.stores;
940
+ await users.put({ name: 'Jin' }, 'jin');
941
+ await users.put({ name: 'John' }, 'john');
942
+ await users.put({ name: 'Bin' }, 'bin');
943
+ const { names } = users.indexes;
944
+ $.$mol_assert_like(await names.get(['Jin']), { name: 'Jin' });
945
+ $.$mol_assert_like(await names.get(['John']), { name: 'John' });
946
+ $.$mol_assert_like(await names.count(), 3);
947
+ $.$mol_assert_like(await names.select(IDBKeyRange.bound(['J'], ['J\uFFFF'])), [{ name: 'Jin' }, { name: 'John' }]);
948
+ try {
949
+ await users.put({ name: 'Jin' }, 'jin2');
950
+ $.$mol_fail(new Error('Exception expected'));
951
+ }
952
+ catch (error) {
953
+ $.$mol_assert_equal(error.message, `Unable to add key to index 'names': at least one key does not satisfy the uniqueness requirements.`);
954
+ }
955
+ }
956
+ finally {
957
+ trans.abort();
958
+ db.kill();
959
+ }
960
+ },
961
+ async 'multi path index'() {
962
+ const db = await $.$$.$mol_db('$mol_db_test', mig => mig.store_make('users'), mig => mig.stores.users.index_make('names', ['first', 'last']));
963
+ const trans = db.change('users');
964
+ try {
965
+ const { users } = trans.stores;
966
+ await users.put({ first: 'Jin', last: 'Johnson' }, 'jin');
967
+ await users.put({ first: 'John', last: 'Jinson' }, 'john');
968
+ await users.put({ first: 'Bond', last: 'James' }, '007');
969
+ const { names } = users.indexes;
970
+ $.$mol_assert_like(await names.get(['Jin', 'Johnson']), { first: 'Jin', last: 'Johnson' });
971
+ $.$mol_assert_like(await names.get(['John', 'Jinson']), { first: 'John', last: 'Jinson' });
972
+ $.$mol_assert_like(await names.count(), 3);
973
+ $.$mol_assert_like(await names.select(IDBKeyRange.bound(['Jin', 'Johnson'], ['John', 'Jinson'])), [{ first: 'Jin', last: 'Johnson' }, { first: 'John', last: 'Jinson' }]);
974
+ }
975
+ finally {
976
+ trans.abort();
977
+ db.kill();
978
+ }
979
+ },
980
+ async 'multiple indexes'() {
981
+ 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']));
982
+ const trans = db.change('users');
983
+ try {
984
+ const { users } = trans.stores;
985
+ await users.put({ name: 'Jin', age: 18 }, 'jin');
986
+ await users.put({ name: 'John', age: 18 }, 'john');
987
+ const { names, ages } = users.indexes;
988
+ $.$mol_assert_like(await names.select(['Jin']), [{ name: 'Jin', age: 18 }]);
989
+ $.$mol_assert_like(await names.select(['John']), [{ name: 'John', age: 18 }]);
990
+ $.$mol_assert_like(await names.count(), 2);
991
+ $.$mol_assert_like(await ages.select([18]), [{ name: 'Jin', age: 18 }, { name: 'John', age: 18 }]);
992
+ $.$mol_assert_like(await ages.count(), 2);
993
+ }
994
+ finally {
995
+ trans.abort();
996
+ db.kill();
997
+ }
998
+ },
999
+ });
1000
+ })($ || ($ = {}));
1001
+ //index.test.js.map
1002
+
1003
+ //# sourceMappingURL=web.test.js.map