hyoo_sync_client 0.0.179 → 0.0.181

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.mjs CHANGED
@@ -1476,6 +1476,8 @@ var $;
1476
1476
  result = compare_pojo(left, right);
1477
1477
  else if (!Reflect.getPrototypeOf(left_proto))
1478
1478
  result = compare_pojo(left, right);
1479
+ else if (Symbol.toPrimitive in left)
1480
+ result = compare_primitive(left, right);
1479
1481
  else if (Array.isArray(left))
1480
1482
  result = compare_array(left, right);
1481
1483
  else if (left instanceof Set)
@@ -1486,8 +1488,6 @@ var $;
1486
1488
  result = compare_buffer(left, right);
1487
1489
  else if (Symbol.iterator in left)
1488
1490
  result = compare_iterator(left[Symbol.iterator](), right[Symbol.iterator]());
1489
- else if (Symbol.toPrimitive in left)
1490
- result = compare_primitive(left, right);
1491
1491
  else
1492
1492
  result = false;
1493
1493
  }
package/web.test.js CHANGED
@@ -200,6 +200,283 @@ var $;
200
200
  ;
201
201
  "use strict";
202
202
  var $;
203
+ (function ($) {
204
+ function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
205
+ return new Proxy(new $mol_range2_array(), {
206
+ get(target, field) {
207
+ if (typeof field === 'string') {
208
+ if (field === 'length')
209
+ return size();
210
+ const index = Number(field);
211
+ if (index < 0)
212
+ return undefined;
213
+ if (index >= size())
214
+ return undefined;
215
+ if (index === Math.trunc(index))
216
+ return item(index);
217
+ }
218
+ return target[field];
219
+ },
220
+ set(target, field) {
221
+ return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
222
+ },
223
+ ownKeys(target) {
224
+ return [...Array(size())].map((v, i) => String(i)).concat('length');
225
+ },
226
+ getOwnPropertyDescriptor(target, field) {
227
+ if (field === "length")
228
+ return {
229
+ value: size(),
230
+ writable: true,
231
+ enumerable: false,
232
+ configurable: false,
233
+ };
234
+ const index = Number(field);
235
+ if (index === Math.trunc(index))
236
+ return {
237
+ get: () => this.get(target, field, this),
238
+ enumerable: true,
239
+ configurable: true,
240
+ };
241
+ return Object.getOwnPropertyDescriptor(target, field);
242
+ }
243
+ });
244
+ }
245
+ $.$mol_range2 = $mol_range2;
246
+ class $mol_range2_array extends Array {
247
+ concat(...tail) {
248
+ if (tail.length === 0)
249
+ return this;
250
+ if (tail.length > 1) {
251
+ let list = this;
252
+ for (let item of tail)
253
+ list = list.concat(item);
254
+ return list;
255
+ }
256
+ return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
257
+ }
258
+ filter(check, context) {
259
+ const filtered = new $mol_range2_array();
260
+ for (let index = 0; index < this.length; ++index) {
261
+ const item = this[index];
262
+ if (check.call(context, item, index, this))
263
+ filtered.push(item);
264
+ }
265
+ return filtered;
266
+ }
267
+ forEach(proceed, context) {
268
+ for (let [key, value] of this.entries())
269
+ proceed.call(context, value, key, this);
270
+ }
271
+ map(proceed, context) {
272
+ return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
273
+ }
274
+ reduce(merge, result) {
275
+ let index = 0;
276
+ if (arguments.length === 1) {
277
+ result = this[index++];
278
+ }
279
+ for (; index < this.length; ++index) {
280
+ result = merge(result, this[index], index, this);
281
+ }
282
+ return result;
283
+ }
284
+ toReversed() {
285
+ return $mol_range2(index => this[this.length - 1 - index], () => this.length);
286
+ }
287
+ slice(from = 0, to = this.length) {
288
+ return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
289
+ }
290
+ some(check, context) {
291
+ for (let index = 0; index < this.length; ++index) {
292
+ if (check.call(context, this[index], index, this))
293
+ return true;
294
+ }
295
+ return false;
296
+ }
297
+ every(check, context) {
298
+ for (let index = 0; index < this.length; ++index) {
299
+ if (!check.call(context, this[index], index, this))
300
+ return false;
301
+ }
302
+ return true;
303
+ }
304
+ reverse() {
305
+ return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
306
+ }
307
+ sort() {
308
+ return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
309
+ }
310
+ [Symbol.toPrimitive]() {
311
+ return $mol_guid();
312
+ }
313
+ }
314
+ $.$mol_range2_array = $mol_range2_array;
315
+ })($ || ($ = {}));
316
+ //mol/range2/range2.ts
317
+ ;
318
+ "use strict";
319
+ var $;
320
+ (function ($) {
321
+ $mol_test({
322
+ 'lazy calls'() {
323
+ let calls = 0;
324
+ const list = $mol_range2(index => (++calls, index), () => 10);
325
+ $mol_assert_ok(list instanceof Array);
326
+ $mol_assert_equal(list.length, 10);
327
+ $mol_assert_equal(list[-1], undefined);
328
+ $mol_assert_equal(list[0], 0);
329
+ $mol_assert_equal(list[9], 9);
330
+ $mol_assert_equal(list[9.5], undefined);
331
+ $mol_assert_equal(list[10], undefined);
332
+ $mol_assert_equal(calls, 2);
333
+ },
334
+ 'infinity list'() {
335
+ let calls = 0;
336
+ const list = $mol_range2(index => (++calls, index));
337
+ $mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
338
+ $mol_assert_equal(list[0], 0);
339
+ $mol_assert_equal(list[4], 4);
340
+ $mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
341
+ $mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
342
+ $mol_assert_equal(calls, 3);
343
+ },
344
+ 'stringify'() {
345
+ const list = $mol_range2(i => i, () => 5);
346
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
347
+ $mol_assert_equal(list.join(';'), '0;1;2;3;4');
348
+ },
349
+ 'for-of'() {
350
+ let log = '';
351
+ for (let i of $mol_range2(i => i + 1, () => 5)) {
352
+ log += i;
353
+ }
354
+ $mol_assert_equal(log, '12345');
355
+ },
356
+ 'for-in'() {
357
+ let log = '';
358
+ for (let i in $mol_range2(i => i, () => 5)) {
359
+ log += i;
360
+ }
361
+ $mol_assert_equal(log, '01234');
362
+ },
363
+ 'forEach'() {
364
+ let log = '';
365
+ $mol_range2(i => i, () => 5).forEach(i => log += i);
366
+ $mol_assert_equal(log, '01234');
367
+ },
368
+ 'lazy concat'() {
369
+ let calls1 = 0;
370
+ let calls2 = 0;
371
+ const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
372
+ $mol_assert_ok(list instanceof Array);
373
+ $mol_assert_equal(list.length, 15);
374
+ $mol_assert_equal(list[0], 0);
375
+ $mol_assert_equal(list[4], 4);
376
+ $mol_assert_equal(list[5], 0);
377
+ $mol_assert_equal(list[9], 4);
378
+ $mol_assert_equal(list[10], 0);
379
+ $mol_assert_equal(list[14], 4);
380
+ $mol_assert_equal(list[15], undefined);
381
+ $mol_assert_equal(calls1, 2);
382
+ $mol_assert_equal(calls2, 2);
383
+ },
384
+ 'filter'() {
385
+ let calls = 0;
386
+ const list = $mol_range2(index => (++calls, index), () => 10).filter(v => v % 2).slice(0, 3);
387
+ $mol_assert_ok(list instanceof Array);
388
+ $mol_assert_equal(list.length, 3);
389
+ $mol_assert_equal(list[0], 1);
390
+ $mol_assert_equal(list[2], 5);
391
+ $mol_assert_equal(list[3], undefined);
392
+ $mol_assert_equal(calls, 10);
393
+ },
394
+ 'reverse'() {
395
+ let calls = 0;
396
+ const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
397
+ $mol_assert_ok(list instanceof Array);
398
+ $mol_assert_equal(list.length, 3);
399
+ $mol_assert_equal(list[0], 9);
400
+ $mol_assert_equal(list[2], 7);
401
+ $mol_assert_equal(list[3], undefined);
402
+ $mol_assert_equal(calls, 2);
403
+ },
404
+ 'reduce'() {
405
+ let calls = 0;
406
+ const list = $mol_range2().slice(1, 6);
407
+ $mol_assert_equal(list.reduce((s, v) => s + v), 15);
408
+ $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
409
+ },
410
+ 'lazy map'() {
411
+ let calls1 = 0;
412
+ let calls2 = 0;
413
+ const source = $mol_range2(index => (++calls1, index), () => 5);
414
+ const target = source.map((item, index, self) => {
415
+ ++calls2;
416
+ $mol_assert_equal(source, self);
417
+ return index + 10;
418
+ }, () => 5);
419
+ $mol_assert_ok(target instanceof Array);
420
+ $mol_assert_equal(target.length, 5);
421
+ $mol_assert_equal(target[0], 10);
422
+ $mol_assert_equal(target[4], 14);
423
+ $mol_assert_equal(target[5], undefined);
424
+ $mol_assert_equal(calls1, 2);
425
+ $mol_assert_equal(calls2, 2);
426
+ },
427
+ 'lazy slice'() {
428
+ let calls = 0;
429
+ const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
430
+ $mol_assert_ok(list instanceof Array);
431
+ $mol_assert_equal(list.length, 4);
432
+ $mol_assert_equal(list[0], 3);
433
+ $mol_assert_equal(list[3], 6);
434
+ $mol_assert_equal(list[4], undefined);
435
+ $mol_assert_equal(calls, 2);
436
+ },
437
+ 'lazy some'() {
438
+ let calls = 0;
439
+ $mol_assert_ok($mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
440
+ $mol_assert_equal(calls, 3);
441
+ $mol_assert_not($mol_range2(i => i, () => 0).some(v => true));
442
+ $mol_assert_ok($mol_range2(i => i).some(v => v > 5));
443
+ },
444
+ 'lazy every'() {
445
+ let calls = 0;
446
+ $mol_assert_not($mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
447
+ $mol_assert_equal(calls, 3);
448
+ $mol_assert_ok($mol_range2(i => i, () => 0).every(v => false));
449
+ $mol_assert_not($mol_range2(i => i).every(v => v < 5));
450
+ },
451
+ 'lazyfy'() {
452
+ let calls = 0;
453
+ const list = new $mol_range2_array(...[0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
454
+ $mol_assert_ok(list instanceof Array);
455
+ $mol_assert_equal(list.length, 4);
456
+ $mol_assert_equal(calls, 0);
457
+ $mol_assert_equal(list[0], 12);
458
+ $mol_assert_equal(list[3], 15);
459
+ $mol_assert_equal(list[4], undefined);
460
+ $mol_assert_equal(calls, 2);
461
+ },
462
+ 'prevent modification'() {
463
+ const list = $mol_range2(i => i, () => 5);
464
+ $mol_assert_fail(() => list.push(4), TypeError);
465
+ $mol_assert_fail(() => list.pop(), TypeError);
466
+ $mol_assert_fail(() => list.unshift(4), TypeError);
467
+ $mol_assert_fail(() => list.shift(), TypeError);
468
+ $mol_assert_fail(() => list.splice(1, 2), TypeError);
469
+ $mol_assert_fail(() => list[1] = 2, TypeError);
470
+ $mol_assert_fail(() => list.reverse(), TypeError);
471
+ $mol_assert_fail(() => list.sort(), TypeError);
472
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
473
+ }
474
+ });
475
+ })($ || ($ = {}));
476
+ //mol/range2/range2.test.ts
477
+ ;
478
+ "use strict";
479
+ var $;
203
480
  (function ($) {
204
481
  $mol_test({
205
482
  'nulls & undefineds'() {
@@ -229,6 +506,8 @@ var $;
229
506
  $mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
230
507
  $mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
231
508
  $mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
509
+ $mol_assert_not($mol_compare_deep($mol_range2().slice(0, 0), new Array()));
510
+ $mol_assert_not($mol_compare_deep($mol_range2(), $mol_range2()));
232
511
  },
233
512
  'Non POJO are different'() {
234
513
  class Thing extends Object {