@canton-network/core-token-standard 1.1.0 → 1.2.0

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/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import createClient from 'openapi-fetch';
2
- import require$$1 from 'lodash';
2
+ import * as jsonTypeValidation from '@mojotech/json-type-validation';
3
+ import * as types from '@daml/types';
3
4
 
4
5
  // Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
5
6
  // SPDX-License-Identifier: Apache-2.0
@@ -68,8 +69,6 @@ const MERGE_DELEGATION_PROPOSAL_TEMPLATE_ID = '#splice-util-token-standard-walle
68
69
  const MERGE_DELEGATION_TEMPLATE_ID = '#splice-util-token-standard-wallet:Splice.Util.Token.Wallet.MergeDelegation:MergeDelegation';
69
70
  const MERGE_DELEGATION_BATCH_MERGE_UTILITY = '#splice-util-token-standard-wallet:Splice.Util.Token.Wallet.MergeDelegation:BatchMergeUtility';
70
71
 
71
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
72
-
73
72
  function getAugmentedNamespace(n) {
74
73
  if (Object.prototype.hasOwnProperty.call(n, '__esModule')) return n;
75
74
  var f = n.default;
@@ -111,3108 +110,9 @@ var AllocationInstructionV1$1 = {};
111
110
 
112
111
  var module$8 = {};
113
112
 
114
- var lodash_isequal = {exports: {}};
115
-
116
- /**
117
- * Lodash (Custom Build) <https://lodash.com/>
118
- * Build: `lodash modularize exports="npm" -o ./`
119
- * Copyright JS Foundation and other contributors <https://js.foundation/>
120
- * Released under MIT license <https://lodash.com/license>
121
- * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
122
- * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
123
- */
124
- lodash_isequal.exports;
125
-
126
- var hasRequiredLodash_isequal;
127
-
128
- function requireLodash_isequal () {
129
- if (hasRequiredLodash_isequal) return lodash_isequal.exports;
130
- hasRequiredLodash_isequal = 1;
131
- (function (module, exports$1) {
132
- /** Used as the size to enable large array optimizations. */
133
- var LARGE_ARRAY_SIZE = 200;
134
-
135
- /** Used to stand-in for `undefined` hash values. */
136
- var HASH_UNDEFINED = '__lodash_hash_undefined__';
137
-
138
- /** Used to compose bitmasks for value comparisons. */
139
- var COMPARE_PARTIAL_FLAG = 1,
140
- COMPARE_UNORDERED_FLAG = 2;
141
-
142
- /** Used as references for various `Number` constants. */
143
- var MAX_SAFE_INTEGER = 9007199254740991;
144
-
145
- /** `Object#toString` result references. */
146
- var argsTag = '[object Arguments]',
147
- arrayTag = '[object Array]',
148
- asyncTag = '[object AsyncFunction]',
149
- boolTag = '[object Boolean]',
150
- dateTag = '[object Date]',
151
- errorTag = '[object Error]',
152
- funcTag = '[object Function]',
153
- genTag = '[object GeneratorFunction]',
154
- mapTag = '[object Map]',
155
- numberTag = '[object Number]',
156
- nullTag = '[object Null]',
157
- objectTag = '[object Object]',
158
- promiseTag = '[object Promise]',
159
- proxyTag = '[object Proxy]',
160
- regexpTag = '[object RegExp]',
161
- setTag = '[object Set]',
162
- stringTag = '[object String]',
163
- symbolTag = '[object Symbol]',
164
- undefinedTag = '[object Undefined]',
165
- weakMapTag = '[object WeakMap]';
166
-
167
- var arrayBufferTag = '[object ArrayBuffer]',
168
- dataViewTag = '[object DataView]',
169
- float32Tag = '[object Float32Array]',
170
- float64Tag = '[object Float64Array]',
171
- int8Tag = '[object Int8Array]',
172
- int16Tag = '[object Int16Array]',
173
- int32Tag = '[object Int32Array]',
174
- uint8Tag = '[object Uint8Array]',
175
- uint8ClampedTag = '[object Uint8ClampedArray]',
176
- uint16Tag = '[object Uint16Array]',
177
- uint32Tag = '[object Uint32Array]';
178
-
179
- /**
180
- * Used to match `RegExp`
181
- * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
182
- */
183
- var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
184
-
185
- /** Used to detect host constructors (Safari). */
186
- var reIsHostCtor = /^\[object .+?Constructor\]$/;
187
-
188
- /** Used to detect unsigned integer values. */
189
- var reIsUint = /^(?:0|[1-9]\d*)$/;
190
-
191
- /** Used to identify `toStringTag` values of typed arrays. */
192
- var typedArrayTags = {};
193
- typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
194
- typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
195
- typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
196
- typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
197
- typedArrayTags[uint32Tag] = true;
198
- typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
199
- typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
200
- typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
201
- typedArrayTags[errorTag] = typedArrayTags[funcTag] =
202
- typedArrayTags[mapTag] = typedArrayTags[numberTag] =
203
- typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
204
- typedArrayTags[setTag] = typedArrayTags[stringTag] =
205
- typedArrayTags[weakMapTag] = false;
206
-
207
- /** Detect free variable `global` from Node.js. */
208
- var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
209
-
210
- /** Detect free variable `self`. */
211
- var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
212
-
213
- /** Used as a reference to the global object. */
214
- var root = freeGlobal || freeSelf || Function('return this')();
215
-
216
- /** Detect free variable `exports`. */
217
- var freeExports = exports$1 && !exports$1.nodeType && exports$1;
218
-
219
- /** Detect free variable `module`. */
220
- var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
221
-
222
- /** Detect the popular CommonJS extension `module.exports`. */
223
- var moduleExports = freeModule && freeModule.exports === freeExports;
224
-
225
- /** Detect free variable `process` from Node.js. */
226
- var freeProcess = moduleExports && freeGlobal.process;
227
-
228
- /** Used to access faster Node.js helpers. */
229
- var nodeUtil = (function() {
230
- try {
231
- return freeProcess && freeProcess.binding && freeProcess.binding('util');
232
- } catch (e) {}
233
- }());
234
-
235
- /* Node.js helper references. */
236
- var nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
237
-
238
- /**
239
- * A specialized version of `_.filter` for arrays without support for
240
- * iteratee shorthands.
241
- *
242
- * @private
243
- * @param {Array} [array] The array to iterate over.
244
- * @param {Function} predicate The function invoked per iteration.
245
- * @returns {Array} Returns the new filtered array.
246
- */
247
- function arrayFilter(array, predicate) {
248
- var index = -1,
249
- length = array == null ? 0 : array.length,
250
- resIndex = 0,
251
- result = [];
252
-
253
- while (++index < length) {
254
- var value = array[index];
255
- if (predicate(value, index, array)) {
256
- result[resIndex++] = value;
257
- }
258
- }
259
- return result;
260
- }
261
-
262
- /**
263
- * Appends the elements of `values` to `array`.
264
- *
265
- * @private
266
- * @param {Array} array The array to modify.
267
- * @param {Array} values The values to append.
268
- * @returns {Array} Returns `array`.
269
- */
270
- function arrayPush(array, values) {
271
- var index = -1,
272
- length = values.length,
273
- offset = array.length;
274
-
275
- while (++index < length) {
276
- array[offset + index] = values[index];
277
- }
278
- return array;
279
- }
280
-
281
- /**
282
- * A specialized version of `_.some` for arrays without support for iteratee
283
- * shorthands.
284
- *
285
- * @private
286
- * @param {Array} [array] The array to iterate over.
287
- * @param {Function} predicate The function invoked per iteration.
288
- * @returns {boolean} Returns `true` if any element passes the predicate check,
289
- * else `false`.
290
- */
291
- function arraySome(array, predicate) {
292
- var index = -1,
293
- length = array == null ? 0 : array.length;
294
-
295
- while (++index < length) {
296
- if (predicate(array[index], index, array)) {
297
- return true;
298
- }
299
- }
300
- return false;
301
- }
302
-
303
- /**
304
- * The base implementation of `_.times` without support for iteratee shorthands
305
- * or max array length checks.
306
- *
307
- * @private
308
- * @param {number} n The number of times to invoke `iteratee`.
309
- * @param {Function} iteratee The function invoked per iteration.
310
- * @returns {Array} Returns the array of results.
311
- */
312
- function baseTimes(n, iteratee) {
313
- var index = -1,
314
- result = Array(n);
315
-
316
- while (++index < n) {
317
- result[index] = iteratee(index);
318
- }
319
- return result;
320
- }
321
-
322
- /**
323
- * The base implementation of `_.unary` without support for storing metadata.
324
- *
325
- * @private
326
- * @param {Function} func The function to cap arguments for.
327
- * @returns {Function} Returns the new capped function.
328
- */
329
- function baseUnary(func) {
330
- return function(value) {
331
- return func(value);
332
- };
333
- }
334
-
335
- /**
336
- * Checks if a `cache` value for `key` exists.
337
- *
338
- * @private
339
- * @param {Object} cache The cache to query.
340
- * @param {string} key The key of the entry to check.
341
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
342
- */
343
- function cacheHas(cache, key) {
344
- return cache.has(key);
345
- }
346
-
347
- /**
348
- * Gets the value at `key` of `object`.
349
- *
350
- * @private
351
- * @param {Object} [object] The object to query.
352
- * @param {string} key The key of the property to get.
353
- * @returns {*} Returns the property value.
354
- */
355
- function getValue(object, key) {
356
- return object == null ? undefined : object[key];
357
- }
358
-
359
- /**
360
- * Converts `map` to its key-value pairs.
361
- *
362
- * @private
363
- * @param {Object} map The map to convert.
364
- * @returns {Array} Returns the key-value pairs.
365
- */
366
- function mapToArray(map) {
367
- var index = -1,
368
- result = Array(map.size);
369
-
370
- map.forEach(function(value, key) {
371
- result[++index] = [key, value];
372
- });
373
- return result;
374
- }
375
-
376
- /**
377
- * Creates a unary function that invokes `func` with its argument transformed.
378
- *
379
- * @private
380
- * @param {Function} func The function to wrap.
381
- * @param {Function} transform The argument transform.
382
- * @returns {Function} Returns the new function.
383
- */
384
- function overArg(func, transform) {
385
- return function(arg) {
386
- return func(transform(arg));
387
- };
388
- }
389
-
390
- /**
391
- * Converts `set` to an array of its values.
392
- *
393
- * @private
394
- * @param {Object} set The set to convert.
395
- * @returns {Array} Returns the values.
396
- */
397
- function setToArray(set) {
398
- var index = -1,
399
- result = Array(set.size);
400
-
401
- set.forEach(function(value) {
402
- result[++index] = value;
403
- });
404
- return result;
405
- }
406
-
407
- /** Used for built-in method references. */
408
- var arrayProto = Array.prototype,
409
- funcProto = Function.prototype,
410
- objectProto = Object.prototype;
411
-
412
- /** Used to detect overreaching core-js shims. */
413
- var coreJsData = root['__core-js_shared__'];
414
-
415
- /** Used to resolve the decompiled source of functions. */
416
- var funcToString = funcProto.toString;
417
-
418
- /** Used to check objects for own properties. */
419
- var hasOwnProperty = objectProto.hasOwnProperty;
420
-
421
- /** Used to detect methods masquerading as native. */
422
- var maskSrcKey = (function() {
423
- var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
424
- return uid ? ('Symbol(src)_1.' + uid) : '';
425
- }());
426
-
427
- /**
428
- * Used to resolve the
429
- * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
430
- * of values.
431
- */
432
- var nativeObjectToString = objectProto.toString;
433
-
434
- /** Used to detect if a method is native. */
435
- var reIsNative = RegExp('^' +
436
- funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
437
- .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
438
- );
439
-
440
- /** Built-in value references. */
441
- var Buffer = moduleExports ? root.Buffer : undefined,
442
- Symbol = root.Symbol,
443
- Uint8Array = root.Uint8Array,
444
- propertyIsEnumerable = objectProto.propertyIsEnumerable,
445
- splice = arrayProto.splice,
446
- symToStringTag = Symbol ? Symbol.toStringTag : undefined;
447
-
448
- /* Built-in method references for those with the same name as other `lodash` methods. */
449
- var nativeGetSymbols = Object.getOwnPropertySymbols,
450
- nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
451
- nativeKeys = overArg(Object.keys, Object);
452
-
453
- /* Built-in method references that are verified to be native. */
454
- var DataView = getNative(root, 'DataView'),
455
- Map = getNative(root, 'Map'),
456
- Promise = getNative(root, 'Promise'),
457
- Set = getNative(root, 'Set'),
458
- WeakMap = getNative(root, 'WeakMap'),
459
- nativeCreate = getNative(Object, 'create');
460
-
461
- /** Used to detect maps, sets, and weakmaps. */
462
- var dataViewCtorString = toSource(DataView),
463
- mapCtorString = toSource(Map),
464
- promiseCtorString = toSource(Promise),
465
- setCtorString = toSource(Set),
466
- weakMapCtorString = toSource(WeakMap);
467
-
468
- /** Used to convert symbols to primitives and strings. */
469
- var symbolProto = Symbol ? Symbol.prototype : undefined,
470
- symbolValueOf = symbolProto ? symbolProto.valueOf : undefined;
471
-
472
- /**
473
- * Creates a hash object.
474
- *
475
- * @private
476
- * @constructor
477
- * @param {Array} [entries] The key-value pairs to cache.
478
- */
479
- function Hash(entries) {
480
- var index = -1,
481
- length = entries == null ? 0 : entries.length;
482
-
483
- this.clear();
484
- while (++index < length) {
485
- var entry = entries[index];
486
- this.set(entry[0], entry[1]);
487
- }
488
- }
489
-
490
- /**
491
- * Removes all key-value entries from the hash.
492
- *
493
- * @private
494
- * @name clear
495
- * @memberOf Hash
496
- */
497
- function hashClear() {
498
- this.__data__ = nativeCreate ? nativeCreate(null) : {};
499
- this.size = 0;
500
- }
501
-
502
- /**
503
- * Removes `key` and its value from the hash.
504
- *
505
- * @private
506
- * @name delete
507
- * @memberOf Hash
508
- * @param {Object} hash The hash to modify.
509
- * @param {string} key The key of the value to remove.
510
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
511
- */
512
- function hashDelete(key) {
513
- var result = this.has(key) && delete this.__data__[key];
514
- this.size -= result ? 1 : 0;
515
- return result;
516
- }
517
-
518
- /**
519
- * Gets the hash value for `key`.
520
- *
521
- * @private
522
- * @name get
523
- * @memberOf Hash
524
- * @param {string} key The key of the value to get.
525
- * @returns {*} Returns the entry value.
526
- */
527
- function hashGet(key) {
528
- var data = this.__data__;
529
- if (nativeCreate) {
530
- var result = data[key];
531
- return result === HASH_UNDEFINED ? undefined : result;
532
- }
533
- return hasOwnProperty.call(data, key) ? data[key] : undefined;
534
- }
535
-
536
- /**
537
- * Checks if a hash value for `key` exists.
538
- *
539
- * @private
540
- * @name has
541
- * @memberOf Hash
542
- * @param {string} key The key of the entry to check.
543
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
544
- */
545
- function hashHas(key) {
546
- var data = this.__data__;
547
- return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
548
- }
549
-
550
- /**
551
- * Sets the hash `key` to `value`.
552
- *
553
- * @private
554
- * @name set
555
- * @memberOf Hash
556
- * @param {string} key The key of the value to set.
557
- * @param {*} value The value to set.
558
- * @returns {Object} Returns the hash instance.
559
- */
560
- function hashSet(key, value) {
561
- var data = this.__data__;
562
- this.size += this.has(key) ? 0 : 1;
563
- data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
564
- return this;
565
- }
566
-
567
- // Add methods to `Hash`.
568
- Hash.prototype.clear = hashClear;
569
- Hash.prototype['delete'] = hashDelete;
570
- Hash.prototype.get = hashGet;
571
- Hash.prototype.has = hashHas;
572
- Hash.prototype.set = hashSet;
573
-
574
- /**
575
- * Creates an list cache object.
576
- *
577
- * @private
578
- * @constructor
579
- * @param {Array} [entries] The key-value pairs to cache.
580
- */
581
- function ListCache(entries) {
582
- var index = -1,
583
- length = entries == null ? 0 : entries.length;
584
-
585
- this.clear();
586
- while (++index < length) {
587
- var entry = entries[index];
588
- this.set(entry[0], entry[1]);
589
- }
590
- }
591
-
592
- /**
593
- * Removes all key-value entries from the list cache.
594
- *
595
- * @private
596
- * @name clear
597
- * @memberOf ListCache
598
- */
599
- function listCacheClear() {
600
- this.__data__ = [];
601
- this.size = 0;
602
- }
603
-
604
- /**
605
- * Removes `key` and its value from the list cache.
606
- *
607
- * @private
608
- * @name delete
609
- * @memberOf ListCache
610
- * @param {string} key The key of the value to remove.
611
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
612
- */
613
- function listCacheDelete(key) {
614
- var data = this.__data__,
615
- index = assocIndexOf(data, key);
616
-
617
- if (index < 0) {
618
- return false;
619
- }
620
- var lastIndex = data.length - 1;
621
- if (index == lastIndex) {
622
- data.pop();
623
- } else {
624
- splice.call(data, index, 1);
625
- }
626
- --this.size;
627
- return true;
628
- }
629
-
630
- /**
631
- * Gets the list cache value for `key`.
632
- *
633
- * @private
634
- * @name get
635
- * @memberOf ListCache
636
- * @param {string} key The key of the value to get.
637
- * @returns {*} Returns the entry value.
638
- */
639
- function listCacheGet(key) {
640
- var data = this.__data__,
641
- index = assocIndexOf(data, key);
642
-
643
- return index < 0 ? undefined : data[index][1];
644
- }
645
-
646
- /**
647
- * Checks if a list cache value for `key` exists.
648
- *
649
- * @private
650
- * @name has
651
- * @memberOf ListCache
652
- * @param {string} key The key of the entry to check.
653
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
654
- */
655
- function listCacheHas(key) {
656
- return assocIndexOf(this.__data__, key) > -1;
657
- }
658
-
659
- /**
660
- * Sets the list cache `key` to `value`.
661
- *
662
- * @private
663
- * @name set
664
- * @memberOf ListCache
665
- * @param {string} key The key of the value to set.
666
- * @param {*} value The value to set.
667
- * @returns {Object} Returns the list cache instance.
668
- */
669
- function listCacheSet(key, value) {
670
- var data = this.__data__,
671
- index = assocIndexOf(data, key);
672
-
673
- if (index < 0) {
674
- ++this.size;
675
- data.push([key, value]);
676
- } else {
677
- data[index][1] = value;
678
- }
679
- return this;
680
- }
681
-
682
- // Add methods to `ListCache`.
683
- ListCache.prototype.clear = listCacheClear;
684
- ListCache.prototype['delete'] = listCacheDelete;
685
- ListCache.prototype.get = listCacheGet;
686
- ListCache.prototype.has = listCacheHas;
687
- ListCache.prototype.set = listCacheSet;
688
-
689
- /**
690
- * Creates a map cache object to store key-value pairs.
691
- *
692
- * @private
693
- * @constructor
694
- * @param {Array} [entries] The key-value pairs to cache.
695
- */
696
- function MapCache(entries) {
697
- var index = -1,
698
- length = entries == null ? 0 : entries.length;
699
-
700
- this.clear();
701
- while (++index < length) {
702
- var entry = entries[index];
703
- this.set(entry[0], entry[1]);
704
- }
705
- }
706
-
707
- /**
708
- * Removes all key-value entries from the map.
709
- *
710
- * @private
711
- * @name clear
712
- * @memberOf MapCache
713
- */
714
- function mapCacheClear() {
715
- this.size = 0;
716
- this.__data__ = {
717
- 'hash': new Hash,
718
- 'map': new (Map || ListCache),
719
- 'string': new Hash
720
- };
721
- }
722
-
723
- /**
724
- * Removes `key` and its value from the map.
725
- *
726
- * @private
727
- * @name delete
728
- * @memberOf MapCache
729
- * @param {string} key The key of the value to remove.
730
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
731
- */
732
- function mapCacheDelete(key) {
733
- var result = getMapData(this, key)['delete'](key);
734
- this.size -= result ? 1 : 0;
735
- return result;
736
- }
737
-
738
- /**
739
- * Gets the map value for `key`.
740
- *
741
- * @private
742
- * @name get
743
- * @memberOf MapCache
744
- * @param {string} key The key of the value to get.
745
- * @returns {*} Returns the entry value.
746
- */
747
- function mapCacheGet(key) {
748
- return getMapData(this, key).get(key);
749
- }
750
-
751
- /**
752
- * Checks if a map value for `key` exists.
753
- *
754
- * @private
755
- * @name has
756
- * @memberOf MapCache
757
- * @param {string} key The key of the entry to check.
758
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
759
- */
760
- function mapCacheHas(key) {
761
- return getMapData(this, key).has(key);
762
- }
763
-
764
- /**
765
- * Sets the map `key` to `value`.
766
- *
767
- * @private
768
- * @name set
769
- * @memberOf MapCache
770
- * @param {string} key The key of the value to set.
771
- * @param {*} value The value to set.
772
- * @returns {Object} Returns the map cache instance.
773
- */
774
- function mapCacheSet(key, value) {
775
- var data = getMapData(this, key),
776
- size = data.size;
777
-
778
- data.set(key, value);
779
- this.size += data.size == size ? 0 : 1;
780
- return this;
781
- }
782
-
783
- // Add methods to `MapCache`.
784
- MapCache.prototype.clear = mapCacheClear;
785
- MapCache.prototype['delete'] = mapCacheDelete;
786
- MapCache.prototype.get = mapCacheGet;
787
- MapCache.prototype.has = mapCacheHas;
788
- MapCache.prototype.set = mapCacheSet;
789
-
790
- /**
791
- *
792
- * Creates an array cache object to store unique values.
793
- *
794
- * @private
795
- * @constructor
796
- * @param {Array} [values] The values to cache.
797
- */
798
- function SetCache(values) {
799
- var index = -1,
800
- length = values == null ? 0 : values.length;
801
-
802
- this.__data__ = new MapCache;
803
- while (++index < length) {
804
- this.add(values[index]);
805
- }
806
- }
807
-
808
- /**
809
- * Adds `value` to the array cache.
810
- *
811
- * @private
812
- * @name add
813
- * @memberOf SetCache
814
- * @alias push
815
- * @param {*} value The value to cache.
816
- * @returns {Object} Returns the cache instance.
817
- */
818
- function setCacheAdd(value) {
819
- this.__data__.set(value, HASH_UNDEFINED);
820
- return this;
821
- }
822
-
823
- /**
824
- * Checks if `value` is in the array cache.
825
- *
826
- * @private
827
- * @name has
828
- * @memberOf SetCache
829
- * @param {*} value The value to search for.
830
- * @returns {number} Returns `true` if `value` is found, else `false`.
831
- */
832
- function setCacheHas(value) {
833
- return this.__data__.has(value);
834
- }
835
-
836
- // Add methods to `SetCache`.
837
- SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
838
- SetCache.prototype.has = setCacheHas;
839
-
840
- /**
841
- * Creates a stack cache object to store key-value pairs.
842
- *
843
- * @private
844
- * @constructor
845
- * @param {Array} [entries] The key-value pairs to cache.
846
- */
847
- function Stack(entries) {
848
- var data = this.__data__ = new ListCache(entries);
849
- this.size = data.size;
850
- }
851
-
852
- /**
853
- * Removes all key-value entries from the stack.
854
- *
855
- * @private
856
- * @name clear
857
- * @memberOf Stack
858
- */
859
- function stackClear() {
860
- this.__data__ = new ListCache;
861
- this.size = 0;
862
- }
863
-
864
- /**
865
- * Removes `key` and its value from the stack.
866
- *
867
- * @private
868
- * @name delete
869
- * @memberOf Stack
870
- * @param {string} key The key of the value to remove.
871
- * @returns {boolean} Returns `true` if the entry was removed, else `false`.
872
- */
873
- function stackDelete(key) {
874
- var data = this.__data__,
875
- result = data['delete'](key);
876
-
877
- this.size = data.size;
878
- return result;
879
- }
880
-
881
- /**
882
- * Gets the stack value for `key`.
883
- *
884
- * @private
885
- * @name get
886
- * @memberOf Stack
887
- * @param {string} key The key of the value to get.
888
- * @returns {*} Returns the entry value.
889
- */
890
- function stackGet(key) {
891
- return this.__data__.get(key);
892
- }
893
-
894
- /**
895
- * Checks if a stack value for `key` exists.
896
- *
897
- * @private
898
- * @name has
899
- * @memberOf Stack
900
- * @param {string} key The key of the entry to check.
901
- * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
902
- */
903
- function stackHas(key) {
904
- return this.__data__.has(key);
905
- }
906
-
907
- /**
908
- * Sets the stack `key` to `value`.
909
- *
910
- * @private
911
- * @name set
912
- * @memberOf Stack
913
- * @param {string} key The key of the value to set.
914
- * @param {*} value The value to set.
915
- * @returns {Object} Returns the stack cache instance.
916
- */
917
- function stackSet(key, value) {
918
- var data = this.__data__;
919
- if (data instanceof ListCache) {
920
- var pairs = data.__data__;
921
- if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
922
- pairs.push([key, value]);
923
- this.size = ++data.size;
924
- return this;
925
- }
926
- data = this.__data__ = new MapCache(pairs);
927
- }
928
- data.set(key, value);
929
- this.size = data.size;
930
- return this;
931
- }
932
-
933
- // Add methods to `Stack`.
934
- Stack.prototype.clear = stackClear;
935
- Stack.prototype['delete'] = stackDelete;
936
- Stack.prototype.get = stackGet;
937
- Stack.prototype.has = stackHas;
938
- Stack.prototype.set = stackSet;
939
-
940
- /**
941
- * Creates an array of the enumerable property names of the array-like `value`.
942
- *
943
- * @private
944
- * @param {*} value The value to query.
945
- * @param {boolean} inherited Specify returning inherited property names.
946
- * @returns {Array} Returns the array of property names.
947
- */
948
- function arrayLikeKeys(value, inherited) {
949
- var isArr = isArray(value),
950
- isArg = !isArr && isArguments(value),
951
- isBuff = !isArr && !isArg && isBuffer(value),
952
- isType = !isArr && !isArg && !isBuff && isTypedArray(value),
953
- skipIndexes = isArr || isArg || isBuff || isType,
954
- result = skipIndexes ? baseTimes(value.length, String) : [],
955
- length = result.length;
956
-
957
- for (var key in value) {
958
- if ((hasOwnProperty.call(value, key)) &&
959
- !(skipIndexes && (
960
- // Safari 9 has enumerable `arguments.length` in strict mode.
961
- key == 'length' ||
962
- // Node.js 0.10 has enumerable non-index properties on buffers.
963
- (isBuff && (key == 'offset' || key == 'parent')) ||
964
- // PhantomJS 2 has enumerable non-index properties on typed arrays.
965
- (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
966
- // Skip index properties.
967
- isIndex(key, length)
968
- ))) {
969
- result.push(key);
970
- }
971
- }
972
- return result;
973
- }
974
-
975
- /**
976
- * Gets the index at which the `key` is found in `array` of key-value pairs.
977
- *
978
- * @private
979
- * @param {Array} array The array to inspect.
980
- * @param {*} key The key to search for.
981
- * @returns {number} Returns the index of the matched value, else `-1`.
982
- */
983
- function assocIndexOf(array, key) {
984
- var length = array.length;
985
- while (length--) {
986
- if (eq(array[length][0], key)) {
987
- return length;
988
- }
989
- }
990
- return -1;
991
- }
992
-
993
- /**
994
- * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
995
- * `keysFunc` and `symbolsFunc` to get the enumerable property names and
996
- * symbols of `object`.
997
- *
998
- * @private
999
- * @param {Object} object The object to query.
1000
- * @param {Function} keysFunc The function to get the keys of `object`.
1001
- * @param {Function} symbolsFunc The function to get the symbols of `object`.
1002
- * @returns {Array} Returns the array of property names and symbols.
1003
- */
1004
- function baseGetAllKeys(object, keysFunc, symbolsFunc) {
1005
- var result = keysFunc(object);
1006
- return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
1007
- }
1008
-
1009
- /**
1010
- * The base implementation of `getTag` without fallbacks for buggy environments.
1011
- *
1012
- * @private
1013
- * @param {*} value The value to query.
1014
- * @returns {string} Returns the `toStringTag`.
1015
- */
1016
- function baseGetTag(value) {
1017
- if (value == null) {
1018
- return value === undefined ? undefinedTag : nullTag;
1019
- }
1020
- return (symToStringTag && symToStringTag in Object(value))
1021
- ? getRawTag(value)
1022
- : objectToString(value);
1023
- }
1024
-
1025
- /**
1026
- * The base implementation of `_.isArguments`.
1027
- *
1028
- * @private
1029
- * @param {*} value The value to check.
1030
- * @returns {boolean} Returns `true` if `value` is an `arguments` object,
1031
- */
1032
- function baseIsArguments(value) {
1033
- return isObjectLike(value) && baseGetTag(value) == argsTag;
1034
- }
1035
-
1036
- /**
1037
- * The base implementation of `_.isEqual` which supports partial comparisons
1038
- * and tracks traversed objects.
1039
- *
1040
- * @private
1041
- * @param {*} value The value to compare.
1042
- * @param {*} other The other value to compare.
1043
- * @param {boolean} bitmask The bitmask flags.
1044
- * 1 - Unordered comparison
1045
- * 2 - Partial comparison
1046
- * @param {Function} [customizer] The function to customize comparisons.
1047
- * @param {Object} [stack] Tracks traversed `value` and `other` objects.
1048
- * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
1049
- */
1050
- function baseIsEqual(value, other, bitmask, customizer, stack) {
1051
- if (value === other) {
1052
- return true;
1053
- }
1054
- if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
1055
- return value !== value && other !== other;
1056
- }
1057
- return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
1058
- }
1059
-
1060
- /**
1061
- * A specialized version of `baseIsEqual` for arrays and objects which performs
1062
- * deep comparisons and tracks traversed objects enabling objects with circular
1063
- * references to be compared.
1064
- *
1065
- * @private
1066
- * @param {Object} object The object to compare.
1067
- * @param {Object} other The other object to compare.
1068
- * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
1069
- * @param {Function} customizer The function to customize comparisons.
1070
- * @param {Function} equalFunc The function to determine equivalents of values.
1071
- * @param {Object} [stack] Tracks traversed `object` and `other` objects.
1072
- * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1073
- */
1074
- function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
1075
- var objIsArr = isArray(object),
1076
- othIsArr = isArray(other),
1077
- objTag = objIsArr ? arrayTag : getTag(object),
1078
- othTag = othIsArr ? arrayTag : getTag(other);
1079
-
1080
- objTag = objTag == argsTag ? objectTag : objTag;
1081
- othTag = othTag == argsTag ? objectTag : othTag;
1082
-
1083
- var objIsObj = objTag == objectTag,
1084
- othIsObj = othTag == objectTag,
1085
- isSameTag = objTag == othTag;
1086
-
1087
- if (isSameTag && isBuffer(object)) {
1088
- if (!isBuffer(other)) {
1089
- return false;
1090
- }
1091
- objIsArr = true;
1092
- objIsObj = false;
1093
- }
1094
- if (isSameTag && !objIsObj) {
1095
- stack || (stack = new Stack);
1096
- return (objIsArr || isTypedArray(object))
1097
- ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
1098
- : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
1099
- }
1100
- if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
1101
- var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
1102
- othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
1103
-
1104
- if (objIsWrapped || othIsWrapped) {
1105
- var objUnwrapped = objIsWrapped ? object.value() : object,
1106
- othUnwrapped = othIsWrapped ? other.value() : other;
1107
-
1108
- stack || (stack = new Stack);
1109
- return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
1110
- }
1111
- }
1112
- if (!isSameTag) {
1113
- return false;
1114
- }
1115
- stack || (stack = new Stack);
1116
- return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
1117
- }
1118
-
1119
- /**
1120
- * The base implementation of `_.isNative` without bad shim checks.
1121
- *
1122
- * @private
1123
- * @param {*} value The value to check.
1124
- * @returns {boolean} Returns `true` if `value` is a native function,
1125
- * else `false`.
1126
- */
1127
- function baseIsNative(value) {
1128
- if (!isObject(value) || isMasked(value)) {
1129
- return false;
1130
- }
1131
- var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
1132
- return pattern.test(toSource(value));
1133
- }
1134
-
1135
- /**
1136
- * The base implementation of `_.isTypedArray` without Node.js optimizations.
1137
- *
1138
- * @private
1139
- * @param {*} value The value to check.
1140
- * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
1141
- */
1142
- function baseIsTypedArray(value) {
1143
- return isObjectLike(value) &&
1144
- isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
1145
- }
1146
-
1147
- /**
1148
- * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
1149
- *
1150
- * @private
1151
- * @param {Object} object The object to query.
1152
- * @returns {Array} Returns the array of property names.
1153
- */
1154
- function baseKeys(object) {
1155
- if (!isPrototype(object)) {
1156
- return nativeKeys(object);
1157
- }
1158
- var result = [];
1159
- for (var key in Object(object)) {
1160
- if (hasOwnProperty.call(object, key) && key != 'constructor') {
1161
- result.push(key);
1162
- }
1163
- }
1164
- return result;
1165
- }
1166
-
1167
- /**
1168
- * A specialized version of `baseIsEqualDeep` for arrays with support for
1169
- * partial deep comparisons.
1170
- *
1171
- * @private
1172
- * @param {Array} array The array to compare.
1173
- * @param {Array} other The other array to compare.
1174
- * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
1175
- * @param {Function} customizer The function to customize comparisons.
1176
- * @param {Function} equalFunc The function to determine equivalents of values.
1177
- * @param {Object} stack Tracks traversed `array` and `other` objects.
1178
- * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
1179
- */
1180
- function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
1181
- var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
1182
- arrLength = array.length,
1183
- othLength = other.length;
1184
-
1185
- if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
1186
- return false;
1187
- }
1188
- // Assume cyclic values are equal.
1189
- var stacked = stack.get(array);
1190
- if (stacked && stack.get(other)) {
1191
- return stacked == other;
1192
- }
1193
- var index = -1,
1194
- result = true,
1195
- seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
1196
-
1197
- stack.set(array, other);
1198
- stack.set(other, array);
1199
-
1200
- // Ignore non-index properties.
1201
- while (++index < arrLength) {
1202
- var arrValue = array[index],
1203
- othValue = other[index];
1204
-
1205
- if (customizer) {
1206
- var compared = isPartial
1207
- ? customizer(othValue, arrValue, index, other, array, stack)
1208
- : customizer(arrValue, othValue, index, array, other, stack);
1209
- }
1210
- if (compared !== undefined) {
1211
- if (compared) {
1212
- continue;
1213
- }
1214
- result = false;
1215
- break;
1216
- }
1217
- // Recursively compare arrays (susceptible to call stack limits).
1218
- if (seen) {
1219
- if (!arraySome(other, function(othValue, othIndex) {
1220
- if (!cacheHas(seen, othIndex) &&
1221
- (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
1222
- return seen.push(othIndex);
1223
- }
1224
- })) {
1225
- result = false;
1226
- break;
1227
- }
1228
- } else if (!(
1229
- arrValue === othValue ||
1230
- equalFunc(arrValue, othValue, bitmask, customizer, stack)
1231
- )) {
1232
- result = false;
1233
- break;
1234
- }
1235
- }
1236
- stack['delete'](array);
1237
- stack['delete'](other);
1238
- return result;
1239
- }
1240
-
1241
- /**
1242
- * A specialized version of `baseIsEqualDeep` for comparing objects of
1243
- * the same `toStringTag`.
1244
- *
1245
- * **Note:** This function only supports comparing values with tags of
1246
- * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
1247
- *
1248
- * @private
1249
- * @param {Object} object The object to compare.
1250
- * @param {Object} other The other object to compare.
1251
- * @param {string} tag The `toStringTag` of the objects to compare.
1252
- * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
1253
- * @param {Function} customizer The function to customize comparisons.
1254
- * @param {Function} equalFunc The function to determine equivalents of values.
1255
- * @param {Object} stack Tracks traversed `object` and `other` objects.
1256
- * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1257
- */
1258
- function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
1259
- switch (tag) {
1260
- case dataViewTag:
1261
- if ((object.byteLength != other.byteLength) ||
1262
- (object.byteOffset != other.byteOffset)) {
1263
- return false;
1264
- }
1265
- object = object.buffer;
1266
- other = other.buffer;
1267
-
1268
- case arrayBufferTag:
1269
- if ((object.byteLength != other.byteLength) ||
1270
- !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
1271
- return false;
1272
- }
1273
- return true;
1274
-
1275
- case boolTag:
1276
- case dateTag:
1277
- case numberTag:
1278
- // Coerce booleans to `1` or `0` and dates to milliseconds.
1279
- // Invalid dates are coerced to `NaN`.
1280
- return eq(+object, +other);
1281
-
1282
- case errorTag:
1283
- return object.name == other.name && object.message == other.message;
1284
-
1285
- case regexpTag:
1286
- case stringTag:
1287
- // Coerce regexes to strings and treat strings, primitives and objects,
1288
- // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
1289
- // for more details.
1290
- return object == (other + '');
1291
-
1292
- case mapTag:
1293
- var convert = mapToArray;
1294
-
1295
- case setTag:
1296
- var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
1297
- convert || (convert = setToArray);
1298
-
1299
- if (object.size != other.size && !isPartial) {
1300
- return false;
1301
- }
1302
- // Assume cyclic values are equal.
1303
- var stacked = stack.get(object);
1304
- if (stacked) {
1305
- return stacked == other;
1306
- }
1307
- bitmask |= COMPARE_UNORDERED_FLAG;
1308
-
1309
- // Recursively compare objects (susceptible to call stack limits).
1310
- stack.set(object, other);
1311
- var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
1312
- stack['delete'](object);
1313
- return result;
1314
-
1315
- case symbolTag:
1316
- if (symbolValueOf) {
1317
- return symbolValueOf.call(object) == symbolValueOf.call(other);
1318
- }
1319
- }
1320
- return false;
1321
- }
1322
-
1323
- /**
1324
- * A specialized version of `baseIsEqualDeep` for objects with support for
1325
- * partial deep comparisons.
1326
- *
1327
- * @private
1328
- * @param {Object} object The object to compare.
1329
- * @param {Object} other The other object to compare.
1330
- * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
1331
- * @param {Function} customizer The function to customize comparisons.
1332
- * @param {Function} equalFunc The function to determine equivalents of values.
1333
- * @param {Object} stack Tracks traversed `object` and `other` objects.
1334
- * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
1335
- */
1336
- function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
1337
- var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
1338
- objProps = getAllKeys(object),
1339
- objLength = objProps.length,
1340
- othProps = getAllKeys(other),
1341
- othLength = othProps.length;
1342
-
1343
- if (objLength != othLength && !isPartial) {
1344
- return false;
1345
- }
1346
- var index = objLength;
1347
- while (index--) {
1348
- var key = objProps[index];
1349
- if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
1350
- return false;
1351
- }
1352
- }
1353
- // Assume cyclic values are equal.
1354
- var stacked = stack.get(object);
1355
- if (stacked && stack.get(other)) {
1356
- return stacked == other;
1357
- }
1358
- var result = true;
1359
- stack.set(object, other);
1360
- stack.set(other, object);
1361
-
1362
- var skipCtor = isPartial;
1363
- while (++index < objLength) {
1364
- key = objProps[index];
1365
- var objValue = object[key],
1366
- othValue = other[key];
1367
-
1368
- if (customizer) {
1369
- var compared = isPartial
1370
- ? customizer(othValue, objValue, key, other, object, stack)
1371
- : customizer(objValue, othValue, key, object, other, stack);
1372
- }
1373
- // Recursively compare objects (susceptible to call stack limits).
1374
- if (!(compared === undefined
1375
- ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
1376
- : compared
1377
- )) {
1378
- result = false;
1379
- break;
1380
- }
1381
- skipCtor || (skipCtor = key == 'constructor');
1382
- }
1383
- if (result && !skipCtor) {
1384
- var objCtor = object.constructor,
1385
- othCtor = other.constructor;
1386
-
1387
- // Non `Object` object instances with different constructors are not equal.
1388
- if (objCtor != othCtor &&
1389
- ('constructor' in object && 'constructor' in other) &&
1390
- !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
1391
- typeof othCtor == 'function' && othCtor instanceof othCtor)) {
1392
- result = false;
1393
- }
1394
- }
1395
- stack['delete'](object);
1396
- stack['delete'](other);
1397
- return result;
1398
- }
1399
-
1400
- /**
1401
- * Creates an array of own enumerable property names and symbols of `object`.
1402
- *
1403
- * @private
1404
- * @param {Object} object The object to query.
1405
- * @returns {Array} Returns the array of property names and symbols.
1406
- */
1407
- function getAllKeys(object) {
1408
- return baseGetAllKeys(object, keys, getSymbols);
1409
- }
1410
-
1411
- /**
1412
- * Gets the data for `map`.
1413
- *
1414
- * @private
1415
- * @param {Object} map The map to query.
1416
- * @param {string} key The reference key.
1417
- * @returns {*} Returns the map data.
1418
- */
1419
- function getMapData(map, key) {
1420
- var data = map.__data__;
1421
- return isKeyable(key)
1422
- ? data[typeof key == 'string' ? 'string' : 'hash']
1423
- : data.map;
1424
- }
1425
-
1426
- /**
1427
- * Gets the native function at `key` of `object`.
1428
- *
1429
- * @private
1430
- * @param {Object} object The object to query.
1431
- * @param {string} key The key of the method to get.
1432
- * @returns {*} Returns the function if it's native, else `undefined`.
1433
- */
1434
- function getNative(object, key) {
1435
- var value = getValue(object, key);
1436
- return baseIsNative(value) ? value : undefined;
1437
- }
1438
-
1439
- /**
1440
- * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
1441
- *
1442
- * @private
1443
- * @param {*} value The value to query.
1444
- * @returns {string} Returns the raw `toStringTag`.
1445
- */
1446
- function getRawTag(value) {
1447
- var isOwn = hasOwnProperty.call(value, symToStringTag),
1448
- tag = value[symToStringTag];
1449
-
1450
- try {
1451
- value[symToStringTag] = undefined;
1452
- var unmasked = true;
1453
- } catch (e) {}
1454
-
1455
- var result = nativeObjectToString.call(value);
1456
- if (unmasked) {
1457
- if (isOwn) {
1458
- value[symToStringTag] = tag;
1459
- } else {
1460
- delete value[symToStringTag];
1461
- }
1462
- }
1463
- return result;
1464
- }
1465
-
1466
- /**
1467
- * Creates an array of the own enumerable symbols of `object`.
1468
- *
1469
- * @private
1470
- * @param {Object} object The object to query.
1471
- * @returns {Array} Returns the array of symbols.
1472
- */
1473
- var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
1474
- if (object == null) {
1475
- return [];
1476
- }
1477
- object = Object(object);
1478
- return arrayFilter(nativeGetSymbols(object), function(symbol) {
1479
- return propertyIsEnumerable.call(object, symbol);
1480
- });
1481
- };
1482
-
1483
- /**
1484
- * Gets the `toStringTag` of `value`.
1485
- *
1486
- * @private
1487
- * @param {*} value The value to query.
1488
- * @returns {string} Returns the `toStringTag`.
1489
- */
1490
- var getTag = baseGetTag;
1491
-
1492
- // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
1493
- if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
1494
- (Map && getTag(new Map) != mapTag) ||
1495
- (Promise && getTag(Promise.resolve()) != promiseTag) ||
1496
- (Set && getTag(new Set) != setTag) ||
1497
- (WeakMap && getTag(new WeakMap) != weakMapTag)) {
1498
- getTag = function(value) {
1499
- var result = baseGetTag(value),
1500
- Ctor = result == objectTag ? value.constructor : undefined,
1501
- ctorString = Ctor ? toSource(Ctor) : '';
1502
-
1503
- if (ctorString) {
1504
- switch (ctorString) {
1505
- case dataViewCtorString: return dataViewTag;
1506
- case mapCtorString: return mapTag;
1507
- case promiseCtorString: return promiseTag;
1508
- case setCtorString: return setTag;
1509
- case weakMapCtorString: return weakMapTag;
1510
- }
1511
- }
1512
- return result;
1513
- };
1514
- }
1515
-
1516
- /**
1517
- * Checks if `value` is a valid array-like index.
1518
- *
1519
- * @private
1520
- * @param {*} value The value to check.
1521
- * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
1522
- * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
1523
- */
1524
- function isIndex(value, length) {
1525
- length = length == null ? MAX_SAFE_INTEGER : length;
1526
- return !!length &&
1527
- (typeof value == 'number' || reIsUint.test(value)) &&
1528
- (value > -1 && value % 1 == 0 && value < length);
1529
- }
1530
-
1531
- /**
1532
- * Checks if `value` is suitable for use as unique object key.
1533
- *
1534
- * @private
1535
- * @param {*} value The value to check.
1536
- * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
1537
- */
1538
- function isKeyable(value) {
1539
- var type = typeof value;
1540
- return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
1541
- ? (value !== '__proto__')
1542
- : (value === null);
1543
- }
1544
-
1545
- /**
1546
- * Checks if `func` has its source masked.
1547
- *
1548
- * @private
1549
- * @param {Function} func The function to check.
1550
- * @returns {boolean} Returns `true` if `func` is masked, else `false`.
1551
- */
1552
- function isMasked(func) {
1553
- return !!maskSrcKey && (maskSrcKey in func);
1554
- }
1555
-
1556
- /**
1557
- * Checks if `value` is likely a prototype object.
1558
- *
1559
- * @private
1560
- * @param {*} value The value to check.
1561
- * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
1562
- */
1563
- function isPrototype(value) {
1564
- var Ctor = value && value.constructor,
1565
- proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
1566
-
1567
- return value === proto;
1568
- }
1569
-
1570
- /**
1571
- * Converts `value` to a string using `Object.prototype.toString`.
1572
- *
1573
- * @private
1574
- * @param {*} value The value to convert.
1575
- * @returns {string} Returns the converted string.
1576
- */
1577
- function objectToString(value) {
1578
- return nativeObjectToString.call(value);
1579
- }
1580
-
1581
- /**
1582
- * Converts `func` to its source code.
1583
- *
1584
- * @private
1585
- * @param {Function} func The function to convert.
1586
- * @returns {string} Returns the source code.
1587
- */
1588
- function toSource(func) {
1589
- if (func != null) {
1590
- try {
1591
- return funcToString.call(func);
1592
- } catch (e) {}
1593
- try {
1594
- return (func + '');
1595
- } catch (e) {}
1596
- }
1597
- return '';
1598
- }
1599
-
1600
- /**
1601
- * Performs a
1602
- * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
1603
- * comparison between two values to determine if they are equivalent.
1604
- *
1605
- * @static
1606
- * @memberOf _
1607
- * @since 4.0.0
1608
- * @category Lang
1609
- * @param {*} value The value to compare.
1610
- * @param {*} other The other value to compare.
1611
- * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
1612
- * @example
1613
- *
1614
- * var object = { 'a': 1 };
1615
- * var other = { 'a': 1 };
1616
- *
1617
- * _.eq(object, object);
1618
- * // => true
1619
- *
1620
- * _.eq(object, other);
1621
- * // => false
1622
- *
1623
- * _.eq('a', 'a');
1624
- * // => true
1625
- *
1626
- * _.eq('a', Object('a'));
1627
- * // => false
1628
- *
1629
- * _.eq(NaN, NaN);
1630
- * // => true
1631
- */
1632
- function eq(value, other) {
1633
- return value === other || (value !== value && other !== other);
1634
- }
1635
-
1636
- /**
1637
- * Checks if `value` is likely an `arguments` object.
1638
- *
1639
- * @static
1640
- * @memberOf _
1641
- * @since 0.1.0
1642
- * @category Lang
1643
- * @param {*} value The value to check.
1644
- * @returns {boolean} Returns `true` if `value` is an `arguments` object,
1645
- * else `false`.
1646
- * @example
1647
- *
1648
- * _.isArguments(function() { return arguments; }());
1649
- * // => true
1650
- *
1651
- * _.isArguments([1, 2, 3]);
1652
- * // => false
1653
- */
1654
- var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
1655
- return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
1656
- !propertyIsEnumerable.call(value, 'callee');
1657
- };
1658
-
1659
- /**
1660
- * Checks if `value` is classified as an `Array` object.
1661
- *
1662
- * @static
1663
- * @memberOf _
1664
- * @since 0.1.0
1665
- * @category Lang
1666
- * @param {*} value The value to check.
1667
- * @returns {boolean} Returns `true` if `value` is an array, else `false`.
1668
- * @example
1669
- *
1670
- * _.isArray([1, 2, 3]);
1671
- * // => true
1672
- *
1673
- * _.isArray(document.body.children);
1674
- * // => false
1675
- *
1676
- * _.isArray('abc');
1677
- * // => false
1678
- *
1679
- * _.isArray(_.noop);
1680
- * // => false
1681
- */
1682
- var isArray = Array.isArray;
1683
-
1684
- /**
1685
- * Checks if `value` is array-like. A value is considered array-like if it's
1686
- * not a function and has a `value.length` that's an integer greater than or
1687
- * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
1688
- *
1689
- * @static
1690
- * @memberOf _
1691
- * @since 4.0.0
1692
- * @category Lang
1693
- * @param {*} value The value to check.
1694
- * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
1695
- * @example
1696
- *
1697
- * _.isArrayLike([1, 2, 3]);
1698
- * // => true
1699
- *
1700
- * _.isArrayLike(document.body.children);
1701
- * // => true
1702
- *
1703
- * _.isArrayLike('abc');
1704
- * // => true
1705
- *
1706
- * _.isArrayLike(_.noop);
1707
- * // => false
1708
- */
1709
- function isArrayLike(value) {
1710
- return value != null && isLength(value.length) && !isFunction(value);
1711
- }
1712
-
1713
- /**
1714
- * Checks if `value` is a buffer.
1715
- *
1716
- * @static
1717
- * @memberOf _
1718
- * @since 4.3.0
1719
- * @category Lang
1720
- * @param {*} value The value to check.
1721
- * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
1722
- * @example
1723
- *
1724
- * _.isBuffer(new Buffer(2));
1725
- * // => true
1726
- *
1727
- * _.isBuffer(new Uint8Array(2));
1728
- * // => false
1729
- */
1730
- var isBuffer = nativeIsBuffer || stubFalse;
1731
-
1732
- /**
1733
- * Performs a deep comparison between two values to determine if they are
1734
- * equivalent.
1735
- *
1736
- * **Note:** This method supports comparing arrays, array buffers, booleans,
1737
- * date objects, error objects, maps, numbers, `Object` objects, regexes,
1738
- * sets, strings, symbols, and typed arrays. `Object` objects are compared
1739
- * by their own, not inherited, enumerable properties. Functions and DOM
1740
- * nodes are compared by strict equality, i.e. `===`.
1741
- *
1742
- * @static
1743
- * @memberOf _
1744
- * @since 0.1.0
1745
- * @category Lang
1746
- * @param {*} value The value to compare.
1747
- * @param {*} other The other value to compare.
1748
- * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
1749
- * @example
1750
- *
1751
- * var object = { 'a': 1 };
1752
- * var other = { 'a': 1 };
1753
- *
1754
- * _.isEqual(object, other);
1755
- * // => true
1756
- *
1757
- * object === other;
1758
- * // => false
1759
- */
1760
- function isEqual(value, other) {
1761
- return baseIsEqual(value, other);
1762
- }
1763
-
1764
- /**
1765
- * Checks if `value` is classified as a `Function` object.
1766
- *
1767
- * @static
1768
- * @memberOf _
1769
- * @since 0.1.0
1770
- * @category Lang
1771
- * @param {*} value The value to check.
1772
- * @returns {boolean} Returns `true` if `value` is a function, else `false`.
1773
- * @example
1774
- *
1775
- * _.isFunction(_);
1776
- * // => true
1777
- *
1778
- * _.isFunction(/abc/);
1779
- * // => false
1780
- */
1781
- function isFunction(value) {
1782
- if (!isObject(value)) {
1783
- return false;
1784
- }
1785
- // The use of `Object#toString` avoids issues with the `typeof` operator
1786
- // in Safari 9 which returns 'object' for typed arrays and other constructors.
1787
- var tag = baseGetTag(value);
1788
- return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
1789
- }
1790
-
1791
- /**
1792
- * Checks if `value` is a valid array-like length.
1793
- *
1794
- * **Note:** This method is loosely based on
1795
- * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
1796
- *
1797
- * @static
1798
- * @memberOf _
1799
- * @since 4.0.0
1800
- * @category Lang
1801
- * @param {*} value The value to check.
1802
- * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
1803
- * @example
1804
- *
1805
- * _.isLength(3);
1806
- * // => true
1807
- *
1808
- * _.isLength(Number.MIN_VALUE);
1809
- * // => false
1810
- *
1811
- * _.isLength(Infinity);
1812
- * // => false
1813
- *
1814
- * _.isLength('3');
1815
- * // => false
1816
- */
1817
- function isLength(value) {
1818
- return typeof value == 'number' &&
1819
- value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
1820
- }
1821
-
1822
- /**
1823
- * Checks if `value` is the
1824
- * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
1825
- * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
1826
- *
1827
- * @static
1828
- * @memberOf _
1829
- * @since 0.1.0
1830
- * @category Lang
1831
- * @param {*} value The value to check.
1832
- * @returns {boolean} Returns `true` if `value` is an object, else `false`.
1833
- * @example
1834
- *
1835
- * _.isObject({});
1836
- * // => true
1837
- *
1838
- * _.isObject([1, 2, 3]);
1839
- * // => true
1840
- *
1841
- * _.isObject(_.noop);
1842
- * // => true
1843
- *
1844
- * _.isObject(null);
1845
- * // => false
1846
- */
1847
- function isObject(value) {
1848
- var type = typeof value;
1849
- return value != null && (type == 'object' || type == 'function');
1850
- }
1851
-
1852
- /**
1853
- * Checks if `value` is object-like. A value is object-like if it's not `null`
1854
- * and has a `typeof` result of "object".
1855
- *
1856
- * @static
1857
- * @memberOf _
1858
- * @since 4.0.0
1859
- * @category Lang
1860
- * @param {*} value The value to check.
1861
- * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
1862
- * @example
1863
- *
1864
- * _.isObjectLike({});
1865
- * // => true
1866
- *
1867
- * _.isObjectLike([1, 2, 3]);
1868
- * // => true
1869
- *
1870
- * _.isObjectLike(_.noop);
1871
- * // => false
1872
- *
1873
- * _.isObjectLike(null);
1874
- * // => false
1875
- */
1876
- function isObjectLike(value) {
1877
- return value != null && typeof value == 'object';
1878
- }
1879
-
1880
- /**
1881
- * Checks if `value` is classified as a typed array.
1882
- *
1883
- * @static
1884
- * @memberOf _
1885
- * @since 3.0.0
1886
- * @category Lang
1887
- * @param {*} value The value to check.
1888
- * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
1889
- * @example
1890
- *
1891
- * _.isTypedArray(new Uint8Array);
1892
- * // => true
1893
- *
1894
- * _.isTypedArray([]);
1895
- * // => false
1896
- */
1897
- var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
1898
-
1899
- /**
1900
- * Creates an array of the own enumerable property names of `object`.
1901
- *
1902
- * **Note:** Non-object values are coerced to objects. See the
1903
- * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
1904
- * for more details.
1905
- *
1906
- * @static
1907
- * @since 0.1.0
1908
- * @memberOf _
1909
- * @category Object
1910
- * @param {Object} object The object to query.
1911
- * @returns {Array} Returns the array of property names.
1912
- * @example
1913
- *
1914
- * function Foo() {
1915
- * this.a = 1;
1916
- * this.b = 2;
1917
- * }
1918
- *
1919
- * Foo.prototype.c = 3;
1920
- *
1921
- * _.keys(new Foo);
1922
- * // => ['a', 'b'] (iteration order is not guaranteed)
1923
- *
1924
- * _.keys('hi');
1925
- * // => ['0', '1']
1926
- */
1927
- function keys(object) {
1928
- return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
1929
- }
1930
-
1931
- /**
1932
- * This method returns a new empty array.
1933
- *
1934
- * @static
1935
- * @memberOf _
1936
- * @since 4.13.0
1937
- * @category Util
1938
- * @returns {Array} Returns the new empty array.
1939
- * @example
1940
- *
1941
- * var arrays = _.times(2, _.stubArray);
1942
- *
1943
- * console.log(arrays);
1944
- * // => [[], []]
1945
- *
1946
- * console.log(arrays[0] === arrays[1]);
1947
- * // => false
1948
- */
1949
- function stubArray() {
1950
- return [];
1951
- }
113
+ var require$$0 = /*@__PURE__*/getAugmentedNamespace(jsonTypeValidation);
1952
114
 
1953
- /**
1954
- * This method returns `false`.
1955
- *
1956
- * @static
1957
- * @memberOf _
1958
- * @since 4.13.0
1959
- * @category Util
1960
- * @returns {boolean} Returns `false`.
1961
- * @example
1962
- *
1963
- * _.times(2, _.stubFalse);
1964
- * // => [false, false]
1965
- */
1966
- function stubFalse() {
1967
- return false;
1968
- }
1969
-
1970
- module.exports = isEqual;
1971
- } (lodash_isequal, lodash_isequal.exports));
1972
- return lodash_isequal.exports;
1973
- }
1974
-
1975
- /**
1976
- * Wraps values in an `Ok` type.
1977
- *
1978
- * Example: `ok(5) // => {ok: true, result: 5}`
1979
- */
1980
-
1981
- var ok = function (result) { return ({ ok: true, result: result }); };
1982
- /**
1983
- * Typeguard for `Ok`.
1984
- */
1985
- var isOk = function (r) { return r.ok === true; };
1986
- /**
1987
- * Wraps errors in an `Err` type.
1988
- *
1989
- * Example: `err('on fire') // => {ok: false, error: 'on fire'}`
1990
- */
1991
- var err = function (error) { return ({ ok: false, error: error }); };
1992
- /**
1993
- * Typeguard for `Err`.
1994
- */
1995
- var isErr = function (r) { return r.ok === false; };
1996
- /**
1997
- * Create a `Promise` that either resolves with the result of `Ok` or rejects
1998
- * with the error of `Err`.
1999
- */
2000
- var asPromise = function (r) {
2001
- return r.ok === true ? Promise.resolve(r.result) : Promise.reject(r.error);
2002
- };
2003
- /**
2004
- * Unwraps a `Result` and returns either the result of an `Ok`, or
2005
- * `defaultValue`.
2006
- *
2007
- * Example:
2008
- * ```
2009
- * Result.withDefault(5, number().run(json))
2010
- * ```
2011
- *
2012
- * It would be nice if `Decoder` had an instance method that mirrored this
2013
- * function. Such a method would look something like this:
2014
- * ```
2015
- * class Decoder<A> {
2016
- * runWithDefault = (defaultValue: A, json: any): A =>
2017
- * Result.withDefault(defaultValue, this.run(json));
2018
- * }
2019
- *
2020
- * number().runWithDefault(5, json)
2021
- * ```
2022
- * Unfortunately, the type of `defaultValue: A` on the method causes issues
2023
- * with type inference on the `object` decoder in some situations. While these
2024
- * inference issues can be solved by providing the optional type argument for
2025
- * `object`s, the extra trouble and confusion doesn't seem worth it.
2026
- */
2027
- var withDefault = function (defaultValue, r) {
2028
- return r.ok === true ? r.result : defaultValue;
2029
- };
2030
- /**
2031
- * Return the successful result, or throw an error.
2032
- */
2033
- var withException = function (r) {
2034
- if (r.ok === true) {
2035
- return r.result;
2036
- }
2037
- else {
2038
- throw r.error;
2039
- }
2040
- };
2041
- /**
2042
- * Given an array of `Result`s, return the successful values.
2043
- */
2044
- var successes = function (results) {
2045
- return results.reduce(function (acc, r) { return (r.ok === true ? acc.concat(r.result) : acc); }, []);
2046
- };
2047
- /**
2048
- * Apply `f` to the result of an `Ok`, or pass the error through.
2049
- */
2050
- var map = function (f, r) {
2051
- return r.ok === true ? ok(f(r.result)) : r;
2052
- };
2053
- /**
2054
- * Apply `f` to the result of two `Ok`s, or pass an error through. If both
2055
- * `Result`s are errors then the first one is returned.
2056
- */
2057
- var map2 = function (f, ar, br) {
2058
- return ar.ok === false ? ar :
2059
- br.ok === false ? br :
2060
- ok(f(ar.result, br.result));
2061
- };
2062
- /**
2063
- * Apply `f` to the error of an `Err`, or pass the success through.
2064
- */
2065
- var mapError = function (f, r) {
2066
- return r.ok === true ? r : err(f(r.error));
2067
- };
2068
- /**
2069
- * Chain together a sequence of computations that may fail, similar to a
2070
- * `Promise`. If the first computation fails then the error will propagate
2071
- * through. If it succeeds, then `f` will be applied to the value, returning a
2072
- * new `Result`.
2073
- */
2074
- var andThen = function (f, r) {
2075
- return r.ok === true ? f(r.result) : r;
2076
- };
2077
-
2078
-
2079
- var result = Object.freeze({
2080
- ok: ok,
2081
- isOk: isOk,
2082
- err: err,
2083
- isErr: isErr,
2084
- asPromise: asPromise,
2085
- withDefault: withDefault,
2086
- withException: withException,
2087
- successes: successes,
2088
- map: map,
2089
- map2: map2,
2090
- mapError: mapError,
2091
- andThen: andThen
2092
- });
2093
-
2094
- /*! *****************************************************************************
2095
- Copyright (c) Microsoft Corporation. All rights reserved.
2096
- Licensed under the Apache License, Version 2.0 (the "License"); you may not use
2097
- this file except in compliance with the License. You may obtain a copy of the
2098
- License at http://www.apache.org/licenses/LICENSE-2.0
2099
-
2100
- THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
2101
- KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
2102
- WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
2103
- MERCHANTABLITY OR NON-INFRINGEMENT.
2104
-
2105
- See the Apache Version 2.0 License for specific language governing permissions
2106
- and limitations under the License.
2107
- ***************************************************************************** */
2108
- /* global Reflect, Promise */
2109
-
2110
-
2111
-
2112
- var __assign = function() {
2113
- __assign = Object.assign || function __assign(t) {
2114
- for (var s, i = 1, n = arguments.length; i < n; i++) {
2115
- s = arguments[i];
2116
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
2117
- }
2118
- return t;
2119
- };
2120
- return __assign.apply(this, arguments);
2121
- };
2122
-
2123
- function __rest(s, e) {
2124
- var t = {};
2125
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
2126
- t[p] = s[p];
2127
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
2128
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
2129
- t[p[i]] = s[p[i]];
2130
- return t;
2131
- }
2132
-
2133
- var isEqual = requireLodash_isequal(); // this syntax avoids TS1192
2134
- /**
2135
- * Type guard for `DecoderError`. One use case of the type guard is in the
2136
- * `catch` of a promise. Typescript types the error argument of `catch` as
2137
- * `any`, so when dealing with a decoder as a promise you may need to
2138
- * distinguish between a `DecoderError` and an error string.
2139
- */
2140
- var isDecoderError = function (a) {
2141
- return a.kind === 'DecoderError' && typeof a.at === 'string' && typeof a.message === 'string';
2142
- };
2143
- /*
2144
- * Helpers
2145
- */
2146
- var isJsonArray = function (json) { return Array.isArray(json); };
2147
- var isJsonObject = function (json) {
2148
- return typeof json === 'object' && json !== null && !isJsonArray(json);
2149
- };
2150
- var typeString = function (json) {
2151
- switch (typeof json) {
2152
- case 'string':
2153
- return 'a string';
2154
- case 'number':
2155
- return 'a number';
2156
- case 'boolean':
2157
- return 'a boolean';
2158
- case 'undefined':
2159
- return 'undefined';
2160
- case 'object':
2161
- if (json instanceof Array) {
2162
- return 'an array';
2163
- }
2164
- else if (json === null) {
2165
- return 'null';
2166
- }
2167
- else {
2168
- return 'an object';
2169
- }
2170
- default:
2171
- return JSON.stringify(json);
2172
- }
2173
- };
2174
- var expectedGot = function (expected, got) {
2175
- return "expected " + expected + ", got " + typeString(got);
2176
- };
2177
- var printPath = function (paths) {
2178
- return paths.map(function (path) { return (typeof path === 'string' ? "." + path : "[" + path + "]"); }).join('');
2179
- };
2180
- var prependAt = function (newAt, _a) {
2181
- var at = _a.at, rest = __rest(_a, ["at"]);
2182
- return (__assign({ at: newAt + (at || '') }, rest));
2183
- };
2184
- /**
2185
- * Decoders transform json objects with unknown structure into known and
2186
- * verified forms. You can create objects of type `Decoder<A>` with either the
2187
- * primitive decoder functions, such as `boolean()` and `string()`, or by
2188
- * applying higher-order decoders to the primitives, such as `array(boolean())`
2189
- * or `dict(string())`.
2190
- *
2191
- * Each of the decoder functions are available both as a static method on
2192
- * `Decoder` and as a function alias -- for example the string decoder is
2193
- * defined at `Decoder.string()`, but is also aliased to `string()`. Using the
2194
- * function aliases exported with the library is recommended.
2195
- *
2196
- * `Decoder` exposes a number of 'run' methods, which all decode json in the
2197
- * same way, but communicate success and failure in different ways. The `map`
2198
- * and `andThen` methods modify decoders without having to call a 'run' method.
2199
- *
2200
- * Alternatively, the main decoder `run()` method returns an object of type
2201
- * `Result<A, DecoderError>`. This library provides a number of helper
2202
- * functions for dealing with the `Result` type, so you can do all the same
2203
- * things with a `Result` as with the decoder methods.
2204
- */
2205
- var Decoder = /** @class */ (function () {
2206
- /**
2207
- * The Decoder class constructor is kept private to separate the internal
2208
- * `decode` function from the external `run` function. The distinction
2209
- * between the two functions is that `decode` returns a
2210
- * `Partial<DecoderError>` on failure, which contains an unfinished error
2211
- * report. When `run` is called on a decoder, the relevant series of `decode`
2212
- * calls is made, and then on failure the resulting `Partial<DecoderError>`
2213
- * is turned into a `DecoderError` by filling in the missing information.
2214
- *
2215
- * While hiding the constructor may seem restrictive, leveraging the
2216
- * provided decoder combinators and helper functions such as
2217
- * `andThen` and `map` should be enough to build specialized decoders as
2218
- * needed.
2219
- */
2220
- function Decoder(decode) {
2221
- var _this = this;
2222
- this.decode = decode;
2223
- /**
2224
- * Run the decoder and return a `Result` with either the decoded value or a
2225
- * `DecoderError` containing the json input, the location of the error, and
2226
- * the error message.
2227
- *
2228
- * Examples:
2229
- * ```
2230
- * number().run(12)
2231
- * // => {ok: true, result: 12}
2232
- *
2233
- * string().run(9001)
2234
- * // =>
2235
- * // {
2236
- * // ok: false,
2237
- * // error: {
2238
- * // kind: 'DecoderError',
2239
- * // input: 9001,
2240
- * // at: 'input',
2241
- * // message: 'expected a string, got 9001'
2242
- * // }
2243
- * // }
2244
- * ```
2245
- */
2246
- this.run = function (json) {
2247
- return mapError(function (error) { return ({
2248
- kind: 'DecoderError',
2249
- input: json,
2250
- at: 'input' + (error.at || ''),
2251
- message: error.message || ''
2252
- }); }, _this.decode(json));
2253
- };
2254
- /**
2255
- * Run the decoder as a `Promise`.
2256
- */
2257
- this.runPromise = function (json) { return asPromise(_this.run(json)); };
2258
- /**
2259
- * Run the decoder and return the value on success, or throw an exception
2260
- * with a formatted error string.
2261
- */
2262
- this.runWithException = function (json) { return withException(_this.run(json)); };
2263
- /**
2264
- * Construct a new decoder that applies a transformation to the decoded
2265
- * result. If the decoder succeeds then `f` will be applied to the value. If
2266
- * it fails the error will propagated through.
2267
- *
2268
- * Example:
2269
- * ```
2270
- * number().map(x => x * 5).run(10)
2271
- * // => {ok: true, result: 50}
2272
- * ```
2273
- */
2274
- this.map = function (f) {
2275
- return new Decoder(function (json) { return map(f, _this.decode(json)); });
2276
- };
2277
- /**
2278
- * Chain together a sequence of decoders. The first decoder will run, and
2279
- * then the function will determine what decoder to run second. If the result
2280
- * of the first decoder succeeds then `f` will be applied to the decoded
2281
- * value. If it fails the error will propagate through.
2282
- *
2283
- * This is a very powerful method -- it can act as both the `map` and `where`
2284
- * methods, can improve error messages for edge cases, and can be used to
2285
- * make a decoder for custom types.
2286
- *
2287
- * Example of adding an error message:
2288
- * ```
2289
- * const versionDecoder = valueAt(['version'], number());
2290
- * const infoDecoder3 = object({a: boolean()});
2291
- *
2292
- * const decoder = versionDecoder.andThen(version => {
2293
- * switch (version) {
2294
- * case 3:
2295
- * return infoDecoder3;
2296
- * default:
2297
- * return fail(`Unable to decode info, version ${version} is not supported.`);
2298
- * }
2299
- * });
2300
- *
2301
- * decoder.run({version: 3, a: true})
2302
- * // => {ok: true, result: {a: true}}
2303
- *
2304
- * decoder.run({version: 5, x: 'abc'})
2305
- * // =>
2306
- * // {
2307
- * // ok: false,
2308
- * // error: {... message: 'Unable to decode info, version 5 is not supported.'}
2309
- * // }
2310
- * ```
2311
- *
2312
- * Example of decoding a custom type:
2313
- * ```
2314
- * // nominal type for arrays with a length of at least one
2315
- * type NonEmptyArray<T> = T[] & { __nonEmptyArrayBrand__: void };
2316
- *
2317
- * const nonEmptyArrayDecoder = <T>(values: Decoder<T>): Decoder<NonEmptyArray<T>> =>
2318
- * array(values).andThen(arr =>
2319
- * arr.length > 0
2320
- * ? succeed(createNonEmptyArray(arr))
2321
- * : fail(`expected a non-empty array, got an empty array`)
2322
- * );
2323
- * ```
2324
- */
2325
- this.andThen = function (f) {
2326
- return new Decoder(function (json) {
2327
- return andThen(function (value) { return f(value).decode(json); }, _this.decode(json));
2328
- });
2329
- };
2330
- /**
2331
- * Add constraints to a decoder _without_ changing the resulting type. The
2332
- * `test` argument is a predicate function which returns true for valid
2333
- * inputs. When `test` fails on an input, the decoder fails with the given
2334
- * `errorMessage`.
2335
- *
2336
- * ```
2337
- * const chars = (length: number): Decoder<string> =>
2338
- * string().where(
2339
- * (s: string) => s.length === length,
2340
- * `expected a string of length ${length}`
2341
- * );
2342
- *
2343
- * chars(5).run('12345')
2344
- * // => {ok: true, result: '12345'}
2345
- *
2346
- * chars(2).run('HELLO')
2347
- * // => {ok: false, error: {... message: 'expected a string of length 2'}}
2348
- *
2349
- * chars(12).run(true)
2350
- * // => {ok: false, error: {... message: 'expected a string, got a boolean'}}
2351
- * ```
2352
- */
2353
- this.where = function (test, errorMessage) {
2354
- return _this.andThen(function (value) { return (test(value) ? Decoder.succeed(value) : Decoder.fail(errorMessage)); });
2355
- };
2356
- }
2357
- /**
2358
- * Decoder primitive that validates strings, and fails on all other input.
2359
- */
2360
- Decoder.string = function () {
2361
- return new Decoder(function (json) {
2362
- return typeof json === 'string'
2363
- ? ok(json)
2364
- : err({ message: expectedGot('a string', json) });
2365
- });
2366
- };
2367
- /**
2368
- * Decoder primitive that validates numbers, and fails on all other input.
2369
- */
2370
- Decoder.number = function () {
2371
- return new Decoder(function (json) {
2372
- return typeof json === 'number'
2373
- ? ok(json)
2374
- : err({ message: expectedGot('a number', json) });
2375
- });
2376
- };
2377
- /**
2378
- * Decoder primitive that validates booleans, and fails on all other input.
2379
- */
2380
- Decoder.boolean = function () {
2381
- return new Decoder(function (json) {
2382
- return typeof json === 'boolean'
2383
- ? ok(json)
2384
- : err({ message: expectedGot('a boolean', json) });
2385
- });
2386
- };
2387
- Decoder.constant = function (value) {
2388
- return new Decoder(function (json) {
2389
- return isEqual(json, value)
2390
- ? ok(value)
2391
- : err({ message: "expected " + JSON.stringify(value) + ", got " + JSON.stringify(json) });
2392
- });
2393
- };
2394
- Decoder.object = function (decoders) {
2395
- return new Decoder(function (json) {
2396
- if (isJsonObject(json) && decoders) {
2397
- var obj = {};
2398
- for (var key in decoders) {
2399
- if (decoders.hasOwnProperty(key)) {
2400
- var r = decoders[key].decode(json[key]);
2401
- if (r.ok === true) {
2402
- // tslint:disable-next-line:strict-type-predicates
2403
- if (r.result !== undefined) {
2404
- obj[key] = r.result;
2405
- }
2406
- }
2407
- else if (json[key] === undefined) {
2408
- return err({ message: "the key '" + key + "' is required but was not present" });
2409
- }
2410
- else {
2411
- return err(prependAt("." + key, r.error));
2412
- }
2413
- }
2414
- }
2415
- return ok(obj);
2416
- }
2417
- else if (isJsonObject(json)) {
2418
- return ok(json);
2419
- }
2420
- else {
2421
- return err({ message: expectedGot('an object', json) });
2422
- }
2423
- });
2424
- };
2425
- Decoder.array = function (decoder) {
2426
- return new Decoder(function (json) {
2427
- if (isJsonArray(json) && decoder) {
2428
- var decodeValue_1 = function (v, i) {
2429
- return mapError(function (err$$1) { return prependAt("[" + i + "]", err$$1); }, decoder.decode(v));
2430
- };
2431
- return json.reduce(function (acc, v, i) {
2432
- return map2(function (arr, result) { return arr.concat([result]); }, acc, decodeValue_1(v, i));
2433
- }, ok([]));
2434
- }
2435
- else if (isJsonArray(json)) {
2436
- return ok(json);
2437
- }
2438
- else {
2439
- return err({ message: expectedGot('an array', json) });
2440
- }
2441
- });
2442
- };
2443
- Decoder.tuple = function (decoders) {
2444
- return new Decoder(function (json) {
2445
- if (isJsonArray(json)) {
2446
- if (json.length !== decoders.length) {
2447
- return err({
2448
- message: "expected a tuple of length " + decoders.length + ", got one of length " + json.length
2449
- });
2450
- }
2451
- var result = [];
2452
- for (var i = 0; i < decoders.length; i++) {
2453
- var nth = decoders[i].decode(json[i]);
2454
- if (nth.ok) {
2455
- result[i] = nth.result;
2456
- }
2457
- else {
2458
- return err(prependAt("[" + i + "]", nth.error));
2459
- }
2460
- }
2461
- return ok(result);
2462
- }
2463
- else {
2464
- return err({ message: expectedGot("a tuple of length " + decoders.length, json) });
2465
- }
2466
- });
2467
- };
2468
- Decoder.union = function (ad, bd) {
2469
- var decoders = [];
2470
- for (var _i = 2; _i < arguments.length; _i++) {
2471
- decoders[_i - 2] = arguments[_i];
2472
- }
2473
- return Decoder.oneOf.apply(Decoder, [ad, bd].concat(decoders));
2474
- };
2475
- Decoder.intersection = function (ad, bd) {
2476
- var ds = [];
2477
- for (var _i = 2; _i < arguments.length; _i++) {
2478
- ds[_i - 2] = arguments[_i];
2479
- }
2480
- return new Decoder(function (json) {
2481
- return [ad, bd].concat(ds).reduce(function (acc, decoder) { return map2(Object.assign, acc, decoder.decode(json)); }, ok({}));
2482
- });
2483
- };
2484
- /**
2485
- * Escape hatch to bypass validation. Always succeeds and types the result as
2486
- * `any`. Useful for defining decoders incrementally, particularly for
2487
- * complex objects.
2488
- *
2489
- * Example:
2490
- * ```
2491
- * interface User {
2492
- * name: string;
2493
- * complexUserData: ComplexType;
2494
- * }
2495
- *
2496
- * const userDecoder: Decoder<User> = object({
2497
- * name: string(),
2498
- * complexUserData: anyJson()
2499
- * });
2500
- * ```
2501
- */
2502
- Decoder.anyJson = function () { return new Decoder(function (json) { return ok(json); }); };
2503
- /**
2504
- * Decoder identity function which always succeeds and types the result as
2505
- * `unknown`.
2506
- */
2507
- Decoder.unknownJson = function () {
2508
- return new Decoder(function (json) { return ok(json); });
2509
- };
2510
- /**
2511
- * Decoder for json objects where the keys are unknown strings, but the values
2512
- * should all be of the same type.
2513
- *
2514
- * Example:
2515
- * ```
2516
- * dict(number()).run({chocolate: 12, vanilla: 10, mint: 37});
2517
- * // => {ok: true, result: {chocolate: 12, vanilla: 10, mint: 37}}
2518
- * ```
2519
- */
2520
- Decoder.dict = function (decoder) {
2521
- return new Decoder(function (json) {
2522
- if (isJsonObject(json)) {
2523
- var obj = {};
2524
- for (var key in json) {
2525
- if (json.hasOwnProperty(key)) {
2526
- var r = decoder.decode(json[key]);
2527
- if (r.ok === true) {
2528
- obj[key] = r.result;
2529
- }
2530
- else {
2531
- return err(prependAt("." + key, r.error));
2532
- }
2533
- }
2534
- }
2535
- return ok(obj);
2536
- }
2537
- else {
2538
- return err({ message: expectedGot('an object', json) });
2539
- }
2540
- });
2541
- };
2542
- /**
2543
- * Decoder for values that may be `undefined`. This is primarily helpful for
2544
- * decoding interfaces with optional fields.
2545
- *
2546
- * Example:
2547
- * ```
2548
- * interface User {
2549
- * id: number;
2550
- * isOwner?: boolean;
2551
- * }
2552
- *
2553
- * const decoder: Decoder<User> = object({
2554
- * id: number(),
2555
- * isOwner: optional(boolean())
2556
- * });
2557
- * ```
2558
- */
2559
- Decoder.optional = function (decoder) {
2560
- return new Decoder(function (json) { return (json === undefined ? ok(undefined) : decoder.decode(json)); });
2561
- };
2562
- /**
2563
- * Decoder that attempts to run each decoder in `decoders` and either succeeds
2564
- * with the first successful decoder, or fails after all decoders have failed.
2565
- *
2566
- * Note that `oneOf` expects the decoders to all have the same return type,
2567
- * while `union` creates a decoder for the union type of all the input
2568
- * decoders.
2569
- *
2570
- * Examples:
2571
- * ```
2572
- * oneOf(string(), number().map(String))
2573
- * oneOf(constant('start'), constant('stop'), succeed('unknown'))
2574
- * ```
2575
- */
2576
- Decoder.oneOf = function () {
2577
- var decoders = [];
2578
- for (var _i = 0; _i < arguments.length; _i++) {
2579
- decoders[_i] = arguments[_i];
2580
- }
2581
- return new Decoder(function (json) {
2582
- var errors = [];
2583
- for (var i = 0; i < decoders.length; i++) {
2584
- var r = decoders[i].decode(json);
2585
- if (r.ok === true) {
2586
- return r;
2587
- }
2588
- else {
2589
- errors[i] = r.error;
2590
- }
2591
- }
2592
- var errorsList = errors
2593
- .map(function (error) { return "at error" + (error.at || '') + ": " + error.message; })
2594
- .join('", "');
2595
- return err({
2596
- message: "expected a value matching one of the decoders, got the errors [\"" + errorsList + "\"]"
2597
- });
2598
- });
2599
- };
2600
- /**
2601
- * Decoder that always succeeds with either the decoded value, or a fallback
2602
- * default value.
2603
- */
2604
- Decoder.withDefault = function (defaultValue, decoder) {
2605
- return new Decoder(function (json) {
2606
- return ok(withDefault(defaultValue, decoder.decode(json)));
2607
- });
2608
- };
2609
- /**
2610
- * Decoder that pulls a specific field out of a json structure, instead of
2611
- * decoding and returning the full structure. The `paths` array describes the
2612
- * object keys and array indices to traverse, so that values can be pulled out
2613
- * of a nested structure.
2614
- *
2615
- * Example:
2616
- * ```
2617
- * const decoder = valueAt(['a', 'b', 0], string());
2618
- *
2619
- * decoder.run({a: {b: ['surprise!']}})
2620
- * // => {ok: true, result: 'surprise!'}
2621
- *
2622
- * decoder.run({a: {x: 'cats'}})
2623
- * // => {ok: false, error: {... at: 'input.a.b[0]' message: 'path does not exist'}}
2624
- * ```
2625
- *
2626
- * Note that the `decoder` is ran on the value found at the last key in the
2627
- * path, even if the last key is not found. This allows the `optional`
2628
- * decoder to succeed when appropriate.
2629
- * ```
2630
- * const optionalDecoder = valueAt(['a', 'b', 'c'], optional(string()));
2631
- *
2632
- * optionalDecoder.run({a: {b: {c: 'surprise!'}}})
2633
- * // => {ok: true, result: 'surprise!'}
2634
- *
2635
- * optionalDecoder.run({a: {b: 'cats'}})
2636
- * // => {ok: false, error: {... at: 'input.a.b.c' message: 'expected an object, got "cats"'}
2637
- *
2638
- * optionalDecoder.run({a: {b: {z: 1}}})
2639
- * // => {ok: true, result: undefined}
2640
- * ```
2641
- */
2642
- Decoder.valueAt = function (paths, decoder) {
2643
- return new Decoder(function (json) {
2644
- var jsonAtPath = json;
2645
- for (var i = 0; i < paths.length; i++) {
2646
- if (jsonAtPath === undefined) {
2647
- return err({
2648
- at: printPath(paths.slice(0, i + 1)),
2649
- message: 'path does not exist'
2650
- });
2651
- }
2652
- else if (typeof paths[i] === 'string' && !isJsonObject(jsonAtPath)) {
2653
- return err({
2654
- at: printPath(paths.slice(0, i + 1)),
2655
- message: expectedGot('an object', jsonAtPath)
2656
- });
2657
- }
2658
- else if (typeof paths[i] === 'number' && !isJsonArray(jsonAtPath)) {
2659
- return err({
2660
- at: printPath(paths.slice(0, i + 1)),
2661
- message: expectedGot('an array', jsonAtPath)
2662
- });
2663
- }
2664
- else {
2665
- jsonAtPath = jsonAtPath[paths[i]];
2666
- }
2667
- }
2668
- return mapError(function (error) {
2669
- return jsonAtPath === undefined
2670
- ? { at: printPath(paths), message: 'path does not exist' }
2671
- : prependAt(printPath(paths), error);
2672
- }, decoder.decode(jsonAtPath));
2673
- });
2674
- };
2675
- /**
2676
- * Decoder that ignores the input json and always succeeds with `fixedValue`.
2677
- */
2678
- Decoder.succeed = function (fixedValue) {
2679
- return new Decoder(function (json) { return ok(fixedValue); });
2680
- };
2681
- /**
2682
- * Decoder that ignores the input json and always fails with `errorMessage`.
2683
- */
2684
- Decoder.fail = function (errorMessage) {
2685
- return new Decoder(function (json) { return err({ message: errorMessage }); });
2686
- };
2687
- /**
2688
- * Decoder that allows for validating recursive data structures. Unlike with
2689
- * functions, decoders assigned to variables can't reference themselves
2690
- * before they are fully defined. We can avoid prematurely referencing the
2691
- * decoder by wrapping it in a function that won't be called until use, at
2692
- * which point the decoder has been defined.
2693
- *
2694
- * Example:
2695
- * ```
2696
- * interface Comment {
2697
- * msg: string;
2698
- * replies: Comment[];
2699
- * }
2700
- *
2701
- * const decoder: Decoder<Comment> = object({
2702
- * msg: string(),
2703
- * replies: lazy(() => array(decoder))
2704
- * });
2705
- * ```
2706
- */
2707
- Decoder.lazy = function (mkDecoder) {
2708
- return new Decoder(function (json) { return mkDecoder().decode(json); });
2709
- };
2710
- return Decoder;
2711
- }());
2712
-
2713
- /* tslint:disable:variable-name */
2714
- /** See `Decoder.string` */
2715
- var string = Decoder.string;
2716
- /** See `Decoder.number` */
2717
- var number = Decoder.number;
2718
- /** See `Decoder.boolean` */
2719
- var boolean = Decoder.boolean;
2720
- /** See `Decoder.anyJson` */
2721
- var anyJson = Decoder.anyJson;
2722
- /** See `Decoder.unknownJson` */
2723
- var unknownJson = Decoder.unknownJson;
2724
- /** See `Decoder.constant` */
2725
- var constant = Decoder.constant;
2726
- /** See `Decoder.object` */
2727
- var object = Decoder.object;
2728
- /** See `Decoder.array` */
2729
- var array = Decoder.array;
2730
- /** See `Decoder.tuple` */
2731
- var tuple = Decoder.tuple;
2732
- /** See `Decoder.dict` */
2733
- var dict = Decoder.dict;
2734
- /** See `Decoder.optional` */
2735
- var optional = Decoder.optional;
2736
- /** See `Decoder.oneOf` */
2737
- var oneOf = Decoder.oneOf;
2738
- /** See `Decoder.union` */
2739
- var union = Decoder.union;
2740
- /** See `Decoder.intersection` */
2741
- var intersection = Decoder.intersection;
2742
- /** See `Decoder.withDefault` */
2743
- var withDefault$1 = Decoder.withDefault;
2744
- /** See `Decoder.valueAt` */
2745
- var valueAt = Decoder.valueAt;
2746
- /** See `Decoder.succeed` */
2747
- var succeed = Decoder.succeed;
2748
- /** See `Decoder.fail` */
2749
- var fail = Decoder.fail;
2750
- /** See `Decoder.lazy` */
2751
- var lazy = Decoder.lazy;
2752
-
2753
- var index_es5 = /*#__PURE__*/Object.freeze({
2754
- __proto__: null,
2755
- Decoder: Decoder,
2756
- Result: result,
2757
- anyJson: anyJson,
2758
- array: array,
2759
- boolean: boolean,
2760
- constant: constant,
2761
- dict: dict,
2762
- fail: fail,
2763
- intersection: intersection,
2764
- isDecoderError: isDecoderError,
2765
- lazy: lazy,
2766
- number: number,
2767
- object: object,
2768
- oneOf: oneOf,
2769
- optional: optional,
2770
- string: string,
2771
- succeed: succeed,
2772
- tuple: tuple,
2773
- union: union,
2774
- unknownJson: unknownJson,
2775
- valueAt: valueAt,
2776
- withDefault: withDefault$1
2777
- });
2778
-
2779
- var require$$0 = /*@__PURE__*/getAugmentedNamespace(index_es5);
2780
-
2781
- var types = {};
2782
-
2783
- var hasRequiredTypes$1;
2784
-
2785
- function requireTypes$1 () {
2786
- if (hasRequiredTypes$1) return types;
2787
- hasRequiredTypes$1 = 1;
2788
- (function (exports$1) {
2789
- var __assign = (types && types.__assign) || function () {
2790
- __assign = Object.assign || function(t) {
2791
- for (var s, i = 1, n = arguments.length; i < n; i++) {
2792
- s = arguments[i];
2793
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
2794
- t[p] = s[p];
2795
- }
2796
- return t;
2797
- };
2798
- return __assign.apply(this, arguments);
2799
- };
2800
- var __createBinding = (types && types.__createBinding) || (Object.create ? (function(o, m, k, k2) {
2801
- if (k2 === undefined) k2 = k;
2802
- var desc = Object.getOwnPropertyDescriptor(m, k);
2803
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
2804
- desc = { enumerable: true, get: function() { return m[k]; } };
2805
- }
2806
- Object.defineProperty(o, k2, desc);
2807
- }) : (function(o, m, k, k2) {
2808
- if (k2 === undefined) k2 = k;
2809
- o[k2] = m[k];
2810
- }));
2811
- var __setModuleDefault = (types && types.__setModuleDefault) || (Object.create ? (function(o, v) {
2812
- Object.defineProperty(o, "default", { enumerable: true, value: v });
2813
- }) : function(o, v) {
2814
- o["default"] = v;
2815
- });
2816
- var __importStar = (types && types.__importStar) || (function () {
2817
- var ownKeys = function(o) {
2818
- ownKeys = Object.getOwnPropertyNames || function (o) {
2819
- var ar = [];
2820
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
2821
- return ar;
2822
- };
2823
- return ownKeys(o);
2824
- };
2825
- return function (mod) {
2826
- if (mod && mod.__esModule) return mod;
2827
- var result = {};
2828
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
2829
- __setModuleDefault(result, mod);
2830
- return result;
2831
- };
2832
- })();
2833
- var __generator = (types && types.__generator) || function (thisArg, body) {
2834
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
2835
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
2836
- function verb(n) { return function (v) { return step([n, v]); }; }
2837
- function step(op) {
2838
- if (f) throw new TypeError("Generator is already executing.");
2839
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
2840
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
2841
- if (y = 0, t) op = [op[0] & 2, t.value];
2842
- switch (op[0]) {
2843
- case 0: case 1: t = op; break;
2844
- case 4: _.label++; return { value: op[1], done: false };
2845
- case 5: _.label++; y = op[1]; op = [0]; continue;
2846
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
2847
- default:
2848
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
2849
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
2850
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
2851
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
2852
- if (t[2]) _.ops.pop();
2853
- _.trys.pop(); continue;
2854
- }
2855
- op = body.call(thisArg, _);
2856
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
2857
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
2858
- }
2859
- };
2860
- var __importDefault = (types && types.__importDefault) || function (mod) {
2861
- return (mod && mod.__esModule) ? mod : { "default": mod };
2862
- };
2863
- Object.defineProperty(exports$1, "__esModule", { value: true });
2864
- exports$1.Map = exports$1.emptyMap = exports$1.TextMap = exports$1.Optional = exports$1.ContractId = exports$1.Date = exports$1.List = exports$1.Party = exports$1.Time = exports$1.Text = exports$1.Decimal = exports$1.Numeric = exports$1.Int = exports$1.Bool = exports$1.Unit = exports$1.lookupTemplate = exports$1.templateIdWithPackageId = exports$1.registerTemplate = void 0;
2865
- exports$1.assembleTemplate = assembleTemplate;
2866
- exports$1.assembleInterface = assembleInterface;
2867
- exports$1.memo = memo;
2868
- exports$1.lazyMemo = lazyMemo;
2869
- // Copyright (c) 2025 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2870
- // SPDX-License-Identifier: Apache-2.0
2871
- var jtv = __importStar(require$$0);
2872
- var lodash_1 = __importDefault(require$$1);
2873
- function toInterfaceMixin() {
2874
- return {
2875
- toInterface: function (_, cid) {
2876
- return cid;
2877
- },
2878
- unsafeFromInterface: function (_, cid) {
2879
- return cid;
2880
- },
2881
- };
2882
- }
2883
- /**
2884
- * @internal
2885
- */
2886
- function assembleTemplate(template) {
2887
- return __assign(__assign({}, toInterfaceMixin()), template);
2888
- }
2889
- /**
2890
- * @internal
2891
- */
2892
- function assembleInterface(templateId, decoderSource, choices) {
2893
- return __assign({ templateId: templateId, sdkVersion: "3.3.0-snapshot.20250528.13806.0.v3cd439fb",
2894
- // `Interface<I> &` is a phantom intersection
2895
- decoder: lazyMemo(function () { return decoderSource().decoder; }), keyDecoder: jtv.succeed(undefined) }, choices);
2896
- }
2897
- /**
2898
- * @internal
2899
- */
2900
- var registeredTemplates = {};
2901
- /**
2902
- * @internal
2903
- */
2904
- var registerTemplate = function (template, packageSpecifiers) {
2905
- if (packageSpecifiers === void 0) { packageSpecifiers = []; }
2906
- var aliases = packageSpecifiers.map((0, exports$1.templateIdWithPackageId)(template));
2907
- new Set([template.templateId].concat(aliases)).forEach(function (templateId) {
2908
- if (templateId in registeredTemplates) {
2909
- console.warn("Trying to re-register template ".concat(templateId, "."));
2910
- }
2911
- else {
2912
- registeredTemplates[templateId] = template;
2913
- console.debug("Registered template ".concat(templateId, "."));
2914
- }
2915
- });
2916
- };
2917
- exports$1.registerTemplate = registerTemplate;
2918
- /**
2919
- * @internal
2920
- */
2921
- var templateIdWithPackageId = function (t) {
2922
- return function (pkgId) {
2923
- return [pkgId].concat(t.templateId.split(":").slice(1)).join(":");
2924
- };
2925
- };
2926
- exports$1.templateIdWithPackageId = templateIdWithPackageId;
2927
- /**
2928
- * @internal
2929
- */
2930
- var lookupTemplate = function (templateId) {
2931
- var template = registeredTemplates[templateId];
2932
- if (template === undefined) {
2933
- throw Error("Failed to look up template ".concat(templateId, ". Make sure your @daml/types version agrees with the used Daml SDK version."));
2934
- }
2935
- return template;
2936
- };
2937
- exports$1.lookupTemplate = lookupTemplate;
2938
- /**
2939
- * @internal Turn a thunk into a memoized version of itself. The memoized thunk
2940
- * invokes the original thunk only on its first invocation and caches the result
2941
- * for later uses. We use this to implement a version of `jtv.lazy` with
2942
- * memoization.
2943
- */
2944
- function memo(thunk) {
2945
- var memoized = function () {
2946
- var cache = thunk();
2947
- memoized = function () { return cache; };
2948
- return cache;
2949
- };
2950
- // NOTE(MH): Since we change `memoized` when the resultung thunk is invoked
2951
- // for the first time, we need to return it "by reference". Thus, we return
2952
- // a closure which contains a reference to `memoized`.
2953
- return function () { return memoized(); };
2954
- }
2955
- /**
2956
- * @internal Variation of `jtv.lazy` which memoizes the computed decoder on its
2957
- * first invocation.
2958
- */
2959
- function lazyMemo(mkDecoder) {
2960
- return jtv.lazy(memo(mkDecoder));
2961
- }
2962
- /**
2963
- * Companion object of the [[Unit]] type.
2964
- */
2965
- exports$1.Unit = {
2966
- decoder: jtv.object({}),
2967
- encode: function (t) { return t; },
2968
- };
2969
- /**
2970
- * Companion object of the [[Bool]] type.
2971
- */
2972
- exports$1.Bool = {
2973
- decoder: jtv.boolean(),
2974
- encode: function (b) { return b; },
2975
- };
2976
- /**
2977
- * Companion object of the [[Int]] type.
2978
- */
2979
- exports$1.Int = {
2980
- decoder: jtv.string(),
2981
- encode: function (i) { return i; },
2982
- };
2983
- /**
2984
- * Companion function of the [[Numeric]] type.
2985
- */
2986
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
2987
- var Numeric = function (_) { return ({
2988
- decoder: jtv.string(),
2989
- encode: function (n) { return n; },
2990
- }); };
2991
- exports$1.Numeric = Numeric;
2992
- /**
2993
- * Companion object of the [[Decimal]] type.
2994
- */
2995
- exports$1.Decimal = (0, exports$1.Numeric)(10);
2996
- /**
2997
- * Companion object of the [[Text]] type.
2998
- */
2999
- exports$1.Text = {
3000
- decoder: jtv.string(),
3001
- encode: function (t) { return t; },
3002
- };
3003
- /**
3004
- * Companion object of the [[Time]] type.
3005
- */
3006
- exports$1.Time = {
3007
- decoder: jtv.string(),
3008
- encode: function (t) { return t; },
3009
- };
3010
- /**
3011
- * Companion object of the [[Party]] type.
3012
- */
3013
- exports$1.Party = {
3014
- decoder: jtv.string(),
3015
- encode: function (p) { return p; },
3016
- };
3017
- /**
3018
- * Companion object of the [[List]] type.
3019
- */
3020
- var List = function (t) { return ({
3021
- decoder: jtv.array(t.decoder),
3022
- encode: function (l) { return l.map(function (element) { return t.encode(element); }); },
3023
- }); };
3024
- exports$1.List = List;
3025
- /**
3026
- * Companion object of the [[Date]] type.
3027
- */
3028
- exports$1.Date = {
3029
- decoder: jtv.string(),
3030
- encode: function (d) { return d; },
3031
- };
3032
- /**
3033
- * Companion object of the [[ContractId]] type.
3034
- */
3035
- var ContractId = function (_t) { return ({
3036
- decoder: jtv.string(),
3037
- encode: function (c) { return c; },
3038
- }); };
3039
- exports$1.ContractId = ContractId;
3040
- /**
3041
- * This class does the actual work behind the [[Optional]] companion function. In addition to
3042
- * implementing the [[Serializable]] interface it also stores the [[Serializable]] instance of the
3043
- * payload of the [[Optional]] and uses it to provide a decoder for the [[OptionalInner]] type.
3044
- *
3045
- * @typeparam T The type of the optionally present value.
3046
- */
3047
- var OptionalWorker = /** @class */ (function () {
3048
- function OptionalWorker(payload) {
3049
- if (payload instanceof OptionalWorker) {
3050
- var payloadInnerDecoder = payload.innerDecoder;
3051
- this.innerDecoder = jtv.oneOf(jtv.constant([]), jtv.tuple([payloadInnerDecoder]));
3052
- this.encode = function (o) {
3053
- if (o === null) {
3054
- // Top-level enclosing Optional where the type argument is also
3055
- // Optional and we represent None.
3056
- return null;
3057
- }
3058
- else {
3059
- // The current type is Optional<Optional<...>> and the current value
3060
- // is Some x. Therefore the nested value is represented as [] for
3061
- // x = None or as [y] for x = Some y. In both cases mapping the
3062
- // encoder of the type parameter does the right thing.
3063
- return o.map(function (nested) { return payload.encode(nested); });
3064
- }
3065
- };
3066
- }
3067
- else {
3068
- // NOTE(MH): `T` is not of the form `Optional<U>` here and hence `null`
3069
- // does not extend `T`. Thus, `OptionalInner<T> = T`.
3070
- this.innerDecoder = payload.decoder;
3071
- this.encode = function (o) {
3072
- if (o === null) {
3073
- // This branch is only reached if we are at the top-level and the
3074
- // entire type is a non-nested Optional, i.e. Optional<U> where U is
3075
- // not Optional. Recursive calls from the other branch would stop
3076
- // before reaching this case, as nested None are empty lists and
3077
- // never null.
3078
- return null;
3079
- }
3080
- else {
3081
- return payload.encode(o);
3082
- }
3083
- };
3084
- }
3085
- this.decoder = jtv
3086
- .optional(jtv.oneOf(jtv.constant(null), this.innerDecoder))
3087
- .map(function (x) { return (x === undefined ? null : x); });
3088
- }
3089
- return OptionalWorker;
3090
- }());
3091
- /**
3092
- * Companion function of the [[Optional]] type.
3093
- */
3094
- var Optional = function (t) {
3095
- return new OptionalWorker(t);
3096
- };
3097
- exports$1.Optional = Optional;
3098
- /**
3099
- * Companion object of the [[TextMap]] type.
3100
- */
3101
- var TextMap = function (t) { return ({
3102
- decoder: jtv.dict(t.decoder),
3103
- encode: function (tm) {
3104
- var out = {};
3105
- Object.keys(tm).forEach(function (k) {
3106
- out[k] = t.encode(tm[k]);
3107
- });
3108
- return out;
3109
- },
3110
- }); };
3111
- exports$1.TextMap = TextMap;
3112
- function it(arr) {
3113
- var i;
3114
- return __generator(this, function (_a) {
3115
- switch (_a.label) {
3116
- case 0:
3117
- i = 0;
3118
- _a.label = 1;
3119
- case 1:
3120
- if (!(i < arr.length)) return [3 /*break*/, 4];
3121
- return [4 /*yield*/, lodash_1.default.cloneDeep(arr[i])];
3122
- case 2:
3123
- _a.sent();
3124
- _a.label = 3;
3125
- case 3:
3126
- i++;
3127
- return [3 /*break*/, 1];
3128
- case 4: return [2 /*return*/, undefined];
3129
- }
3130
- });
3131
- }
3132
- // This code assumes that the decoder is only ever used in decoding values
3133
- // straight from the API responses, and said raw responses are never reused
3134
- // afterwards. This should be enforced by this class not being exported and the
3135
- // daml-ledger module not letting raw JSON responses escape without going
3136
- // through this.
3137
- //
3138
- // Without that assumption, the constructor would need to deep-copy its kvs
3139
- // argument.
3140
- var MapImpl = /** @class */ (function () {
3141
- function MapImpl(kvs) {
3142
- // sorting done so that generic object deep comparison would find equal
3143
- // maps equal (as defined by jest's expect().toEqual())
3144
- this._kvs = lodash_1.default.sortBy(kvs, function (kv) { return JSON.stringify(kv[0]); });
3145
- this._keys = this._kvs.map(function (e) { return e[0]; });
3146
- this._values = this._kvs.map(function (e) { return e[1]; });
3147
- }
3148
- MapImpl.prototype._idx = function (k) {
3149
- return this._keys.findIndex(function (l) { return lodash_1.default.isEqual(k, l); });
3150
- };
3151
- MapImpl.prototype.has = function (k) {
3152
- return this._idx(k) !== -1;
3153
- };
3154
- MapImpl.prototype.get = function (k) {
3155
- return lodash_1.default.cloneDeep(this._values[this._idx(k)]);
3156
- };
3157
- MapImpl.prototype.set = function (k, v) {
3158
- if (this.has(k)) {
3159
- var cpy = this._kvs.slice();
3160
- cpy[this._idx(k)] = lodash_1.default.cloneDeep([k, v]);
3161
- return new MapImpl(cpy);
3162
- }
3163
- else {
3164
- var head = lodash_1.default.cloneDeep([[k, v]]);
3165
- return new MapImpl(head.concat(this._kvs));
3166
- }
3167
- };
3168
- MapImpl.prototype.delete = function (k) {
3169
- var i = this._idx(k);
3170
- if (i !== -1) {
3171
- return new MapImpl(this._kvs.slice(0, i).concat(this._kvs.slice(i + 1)));
3172
- }
3173
- else {
3174
- return this;
3175
- }
3176
- };
3177
- MapImpl.prototype.keys = function () {
3178
- return it(this._keys);
3179
- };
3180
- MapImpl.prototype.values = function () {
3181
- return it(this._values);
3182
- };
3183
- MapImpl.prototype.entries = function () {
3184
- return it(this._kvs);
3185
- };
3186
- MapImpl.prototype.entriesArray = function () {
3187
- return lodash_1.default.cloneDeep(this._kvs);
3188
- };
3189
- MapImpl.prototype.forEach = function (f, u) {
3190
- var g = u ? f.bind(u) : f;
3191
- for (var _i = 0, _a = this._kvs; _i < _a.length; _i++) {
3192
- var _b = _a[_i], k = _b[0], v = _b[1];
3193
- g(v, k, this);
3194
- }
3195
- };
3196
- return MapImpl;
3197
- }());
3198
- var emptyMap = function () { return new MapImpl([]); };
3199
- exports$1.emptyMap = emptyMap;
3200
- /**
3201
- * Companion function of the [[GenMap]] type.
3202
- */
3203
- var Map = function (kd, vd) { return ({
3204
- decoder: jtv
3205
- .array(jtv.tuple([kd.decoder, vd.decoder]))
3206
- .map(function (kvs) { return new MapImpl(kvs); }),
3207
- encode: function (m) {
3208
- return m.entriesArray().map(function (e) { return [kd.encode(e[0]), vd.encode(e[1])]; });
3209
- },
3210
- }); };
3211
- exports$1.Map = Map;
3212
-
3213
- } (types));
3214
- return types;
3215
- }
115
+ var require$$1 = /*@__PURE__*/getAugmentedNamespace(types);
3216
116
 
3217
117
  var lib$1 = {};
3218
118
 
@@ -3234,7 +134,7 @@ function requireModule$7 () {
3234
134
  /* eslint-disable-next-line no-unused-vars */
3235
135
  var jtv = require$$0;
3236
136
  /* eslint-disable-next-line no-unused-vars */
3237
- var damlTypes = requireTypes$1();
137
+ var damlTypes = require$$1;
3238
138
 
3239
139
  exports$1.Archive = {
3240
140
  decoder: damlTypes.lazyMemo(function () {
@@ -3330,7 +230,7 @@ function requireModule$6 () {
3330
230
  /* eslint-disable-next-line no-unused-vars */
3331
231
  var jtv = require$$0;
3332
232
  /* eslint-disable-next-line no-unused-vars */
3333
- var damlTypes = requireTypes$1();
233
+ var damlTypes = require$$1;
3334
234
 
3335
235
  exports$1.RelTime = {
3336
236
  decoder: damlTypes.lazyMemo(function () {
@@ -3416,7 +316,7 @@ function requireModule$5 () {
3416
316
  /* eslint-disable-next-line no-unused-vars */
3417
317
  var jtv = require$$0;
3418
318
  /* eslint-disable-next-line no-unused-vars */
3419
- var damlTypes = requireTypes$1();
319
+ var damlTypes = require$$1;
3420
320
 
3421
321
  var pkg9e70a8b3510d617f8a136213f33d6a903a10ca0eeec76bb06ba55d1ed9680f69 = requireLib$2();
3422
322
  var pkgb70db8369e1c461d5c70f1c86f526a29e9776c655e6ffc2560f95b05ccb8b946 = requireLib$1();
@@ -3651,7 +551,7 @@ function requireModule$4 () {
3651
551
  /* eslint-disable-next-line no-unused-vars */
3652
552
  var jtv = require$$0;
3653
553
  /* eslint-disable-next-line no-unused-vars */
3654
- var damlTypes = requireTypes$1();
554
+ var damlTypes = require$$1;
3655
555
 
3656
556
  var pkg9e70a8b3510d617f8a136213f33d6a903a10ca0eeec76bb06ba55d1ed9680f69 = requireLib$2();
3657
557
  var pkgb70db8369e1c461d5c70f1c86f526a29e9776c655e6ffc2560f95b05ccb8b946 = requireLib$1();
@@ -3781,7 +681,7 @@ function requireModule$3 () {
3781
681
  /* eslint-disable-next-line no-unused-vars */
3782
682
  var jtv = require$$0;
3783
683
  /* eslint-disable-next-line no-unused-vars */
3784
- var damlTypes = requireTypes$1();
684
+ var damlTypes = require$$1;
3785
685
 
3786
686
  var pkg9e70a8b3510d617f8a136213f33d6a903a10ca0eeec76bb06ba55d1ed9680f69 = requireLib$2();
3787
687
 
@@ -4110,7 +1010,7 @@ function requireModule$2 () {
4110
1010
  /* eslint-disable-next-line no-unused-vars */
4111
1011
  var jtv = require$$0;
4112
1012
  /* eslint-disable-next-line no-unused-vars */
4113
- var damlTypes = requireTypes$1();
1013
+ var damlTypes = require$$1;
4114
1014
 
4115
1015
  var pkg9e70a8b3510d617f8a136213f33d6a903a10ca0eeec76bb06ba55d1ed9680f69 = requireLib$2();
4116
1016
 
@@ -4527,7 +1427,7 @@ function requireModule$1 () {
4527
1427
  /* eslint-disable-next-line no-unused-vars */
4528
1428
  var jtv = require$$0;
4529
1429
  /* eslint-disable-next-line no-unused-vars */
4530
- var damlTypes = requireTypes$1();
1430
+ var damlTypes = require$$1;
4531
1431
 
4532
1432
  var pkg9e70a8b3510d617f8a136213f33d6a903a10ca0eeec76bb06ba55d1ed9680f69 = requireLib$2();
4533
1433
 
@@ -4753,7 +1653,7 @@ function requireModule () {
4753
1653
  /* eslint-disable-next-line no-unused-vars */
4754
1654
  var jtv = require$$0;
4755
1655
  /* eslint-disable-next-line no-unused-vars */
4756
- var damlTypes = requireTypes$1();
1656
+ var damlTypes = require$$1;
4757
1657
 
4758
1658
  var pkg9e70a8b3510d617f8a136213f33d6a903a10ca0eeec76bb06ba55d1ed9680f69 = requireLib$2();
4759
1659