@dappworks/kit 0.4.105 → 0.4.107

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/aiem.d.mts CHANGED
@@ -1,6 +1,20 @@
1
1
  import { Abi, Chain, GetContractReturnType, PublicClient, HttpTransport, WalletClient, AbiFunction } from 'viem';
2
2
  import TTLCache from '@isaacs/ttlcache';
3
3
 
4
+ type ClassType<T> = {
5
+ new (...args: any[]): T;
6
+ };
7
+
8
+ interface ReadParams {
9
+ foo?: string;
10
+ }
11
+ type ContractParams<T extends any = any, K extends keyof T = keyof T> = K;
12
+ declare class Fields {
13
+ static read(options?: ReadParams): (target: any, propertyKey: any, descriptor?: PropertyDescriptor) => void;
14
+ static custom(options?: ReadParams): (target: any, propertyKey: any, descriptor?: PropertyDescriptor) => void;
15
+ static contract<T = any, R = any>(entity: () => ClassType<R>, options: ContractParams<T>): (target: any, propertyKey: any, descriptor?: PropertyDescriptor) => void;
16
+ }
17
+
4
18
  declare class Cache {
5
19
  kv: TTLCache<string, any>;
6
20
  wrap<T>(key: string, fn: () => T | Promise<T>, config?: TTLCache.Options<any, any>): T | Promise<T>;
@@ -67,7 +81,14 @@ declare class AIem<Contracts extends Record<string, Abi>, Chains extends Record<
67
81
  }): any;
68
82
  static init(): AIem<any, any, any>;
69
83
  static Get<TAbi extends Abi = any>(abi: TAbi, chainId: any, address: any, wallet?: WalletClient): GetContractReturnType<TAbi, PublicClient<HttpTransport, Chain, any, any>>;
84
+ static Query: <E, S extends QuerySelect<E>>(entity: ClassType<E>, select: S) => ((entities: Partial<E>[]) => Promise<Array<Partial<QueryReturnType<E, S>>>>);
70
85
  }
71
86
  type ReadFunctionKeys<T extends Abi> = T[number] extends infer U ? U extends AbiFunction ? U['stateMutability'] extends 'view' | 'pure' ? U['name'] : never : never : never;
87
+ type QuerySelect<E> = {
88
+ [K in keyof E]?: E[K] extends (...args: any[]) => any ? boolean : E[K] extends object ? QuerySelect<E[K]> : boolean;
89
+ };
90
+ type QueryReturnType<E, S> = {
91
+ [K in keyof S]: S[K] extends true ? K extends keyof E ? E[K] : never : S[K] extends QuerySelect<infer T> ? QueryReturnType<E[K], T> : never;
92
+ };
72
93
 
73
- export { AIem, Cache, type ReadFunctionKeys };
94
+ export { AIem, Cache, Fields, type ReadFunctionKeys };
package/dist/aiem.mjs CHANGED
@@ -4,6 +4,810 @@ import md5 from 'md5';
4
4
  import { mainnet, iotex, bsc, polygon, iotexTestnet } from 'viem/chains';
5
5
  import TTLCache from '@isaacs/ttlcache';
6
6
 
7
+ // ../../node_modules/reflect-metadata/Reflect.js
8
+ var Reflect2;
9
+ (function(Reflect3) {
10
+ (function(factory) {
11
+ var root = typeof global === "object" ? global : typeof self === "object" ? self : typeof this === "object" ? this : Function("return this;")();
12
+ var exporter = makeExporter(Reflect3);
13
+ if (typeof root.Reflect === "undefined") {
14
+ root.Reflect = Reflect3;
15
+ } else {
16
+ exporter = makeExporter(root.Reflect, exporter);
17
+ }
18
+ factory(exporter);
19
+ function makeExporter(target, previous) {
20
+ return function(key, value) {
21
+ if (typeof target[key] !== "function") {
22
+ Object.defineProperty(target, key, { configurable: true, writable: true, value });
23
+ }
24
+ if (previous)
25
+ previous(key, value);
26
+ };
27
+ }
28
+ })(function(exporter) {
29
+ var hasOwn = Object.prototype.hasOwnProperty;
30
+ var supportsSymbol = typeof Symbol === "function";
31
+ var toPrimitiveSymbol = supportsSymbol && typeof Symbol.toPrimitive !== "undefined" ? Symbol.toPrimitive : "@@toPrimitive";
32
+ var iteratorSymbol = supportsSymbol && typeof Symbol.iterator !== "undefined" ? Symbol.iterator : "@@iterator";
33
+ var supportsCreate = typeof Object.create === "function";
34
+ var supportsProto = { __proto__: [] } instanceof Array;
35
+ var downLevel = !supportsCreate && !supportsProto;
36
+ var HashMap = {
37
+ // create an object in dictionary mode (a.k.a. "slow" mode in v8)
38
+ create: supportsCreate ? function() {
39
+ return MakeDictionary(/* @__PURE__ */ Object.create(null));
40
+ } : supportsProto ? function() {
41
+ return MakeDictionary({ __proto__: null });
42
+ } : function() {
43
+ return MakeDictionary({});
44
+ },
45
+ has: downLevel ? function(map, key) {
46
+ return hasOwn.call(map, key);
47
+ } : function(map, key) {
48
+ return key in map;
49
+ },
50
+ get: downLevel ? function(map, key) {
51
+ return hasOwn.call(map, key) ? map[key] : void 0;
52
+ } : function(map, key) {
53
+ return map[key];
54
+ }
55
+ };
56
+ var functionPrototype = Object.getPrototypeOf(Function);
57
+ var usePolyfill = typeof process === "object" && process.env && process.env["REFLECT_METADATA_USE_MAP_POLYFILL"] === "true";
58
+ var _Map = !usePolyfill && typeof Map === "function" && typeof Map.prototype.entries === "function" ? Map : CreateMapPolyfill();
59
+ var _Set = !usePolyfill && typeof Set === "function" && typeof Set.prototype.entries === "function" ? Set : CreateSetPolyfill();
60
+ var _WeakMap = !usePolyfill && typeof WeakMap === "function" ? WeakMap : CreateWeakMapPolyfill();
61
+ var Metadata = new _WeakMap();
62
+ function decorate(decorators, target, propertyKey, attributes) {
63
+ if (!IsUndefined(propertyKey)) {
64
+ if (!IsArray(decorators))
65
+ throw new TypeError();
66
+ if (!IsObject(target))
67
+ throw new TypeError();
68
+ if (!IsObject(attributes) && !IsUndefined(attributes) && !IsNull(attributes))
69
+ throw new TypeError();
70
+ if (IsNull(attributes))
71
+ attributes = void 0;
72
+ propertyKey = ToPropertyKey(propertyKey);
73
+ return DecorateProperty(decorators, target, propertyKey, attributes);
74
+ } else {
75
+ if (!IsArray(decorators))
76
+ throw new TypeError();
77
+ if (!IsConstructor(target))
78
+ throw new TypeError();
79
+ return DecorateConstructor(decorators, target);
80
+ }
81
+ }
82
+ exporter("decorate", decorate);
83
+ function metadata(metadataKey, metadataValue) {
84
+ function decorator(target, propertyKey) {
85
+ if (!IsObject(target))
86
+ throw new TypeError();
87
+ if (!IsUndefined(propertyKey) && !IsPropertyKey(propertyKey))
88
+ throw new TypeError();
89
+ OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
90
+ }
91
+ return decorator;
92
+ }
93
+ exporter("metadata", metadata);
94
+ function defineMetadata(metadataKey, metadataValue, target, propertyKey) {
95
+ if (!IsObject(target))
96
+ throw new TypeError();
97
+ if (!IsUndefined(propertyKey))
98
+ propertyKey = ToPropertyKey(propertyKey);
99
+ return OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);
100
+ }
101
+ exporter("defineMetadata", defineMetadata);
102
+ function hasMetadata(metadataKey, target, propertyKey) {
103
+ if (!IsObject(target))
104
+ throw new TypeError();
105
+ if (!IsUndefined(propertyKey))
106
+ propertyKey = ToPropertyKey(propertyKey);
107
+ return OrdinaryHasMetadata(metadataKey, target, propertyKey);
108
+ }
109
+ exporter("hasMetadata", hasMetadata);
110
+ function hasOwnMetadata(metadataKey, target, propertyKey) {
111
+ if (!IsObject(target))
112
+ throw new TypeError();
113
+ if (!IsUndefined(propertyKey))
114
+ propertyKey = ToPropertyKey(propertyKey);
115
+ return OrdinaryHasOwnMetadata(metadataKey, target, propertyKey);
116
+ }
117
+ exporter("hasOwnMetadata", hasOwnMetadata);
118
+ function getMetadata(metadataKey, target, propertyKey) {
119
+ if (!IsObject(target))
120
+ throw new TypeError();
121
+ if (!IsUndefined(propertyKey))
122
+ propertyKey = ToPropertyKey(propertyKey);
123
+ return OrdinaryGetMetadata(metadataKey, target, propertyKey);
124
+ }
125
+ exporter("getMetadata", getMetadata);
126
+ function getOwnMetadata(metadataKey, target, propertyKey) {
127
+ if (!IsObject(target))
128
+ throw new TypeError();
129
+ if (!IsUndefined(propertyKey))
130
+ propertyKey = ToPropertyKey(propertyKey);
131
+ return OrdinaryGetOwnMetadata(metadataKey, target, propertyKey);
132
+ }
133
+ exporter("getOwnMetadata", getOwnMetadata);
134
+ function getMetadataKeys(target, propertyKey) {
135
+ if (!IsObject(target))
136
+ throw new TypeError();
137
+ if (!IsUndefined(propertyKey))
138
+ propertyKey = ToPropertyKey(propertyKey);
139
+ return OrdinaryMetadataKeys(target, propertyKey);
140
+ }
141
+ exporter("getMetadataKeys", getMetadataKeys);
142
+ function getOwnMetadataKeys(target, propertyKey) {
143
+ if (!IsObject(target))
144
+ throw new TypeError();
145
+ if (!IsUndefined(propertyKey))
146
+ propertyKey = ToPropertyKey(propertyKey);
147
+ return OrdinaryOwnMetadataKeys(target, propertyKey);
148
+ }
149
+ exporter("getOwnMetadataKeys", getOwnMetadataKeys);
150
+ function deleteMetadata(metadataKey, target, propertyKey) {
151
+ if (!IsObject(target))
152
+ throw new TypeError();
153
+ if (!IsUndefined(propertyKey))
154
+ propertyKey = ToPropertyKey(propertyKey);
155
+ var metadataMap = GetOrCreateMetadataMap(
156
+ target,
157
+ propertyKey,
158
+ /*Create*/
159
+ false
160
+ );
161
+ if (IsUndefined(metadataMap))
162
+ return false;
163
+ if (!metadataMap.delete(metadataKey))
164
+ return false;
165
+ if (metadataMap.size > 0)
166
+ return true;
167
+ var targetMetadata = Metadata.get(target);
168
+ targetMetadata.delete(propertyKey);
169
+ if (targetMetadata.size > 0)
170
+ return true;
171
+ Metadata.delete(target);
172
+ return true;
173
+ }
174
+ exporter("deleteMetadata", deleteMetadata);
175
+ function DecorateConstructor(decorators, target) {
176
+ for (var i = decorators.length - 1; i >= 0; --i) {
177
+ var decorator = decorators[i];
178
+ var decorated = decorator(target);
179
+ if (!IsUndefined(decorated) && !IsNull(decorated)) {
180
+ if (!IsConstructor(decorated))
181
+ throw new TypeError();
182
+ target = decorated;
183
+ }
184
+ }
185
+ return target;
186
+ }
187
+ function DecorateProperty(decorators, target, propertyKey, descriptor) {
188
+ for (var i = decorators.length - 1; i >= 0; --i) {
189
+ var decorator = decorators[i];
190
+ var decorated = decorator(target, propertyKey, descriptor);
191
+ if (!IsUndefined(decorated) && !IsNull(decorated)) {
192
+ if (!IsObject(decorated))
193
+ throw new TypeError();
194
+ descriptor = decorated;
195
+ }
196
+ }
197
+ return descriptor;
198
+ }
199
+ function GetOrCreateMetadataMap(O, P, Create) {
200
+ var targetMetadata = Metadata.get(O);
201
+ if (IsUndefined(targetMetadata)) {
202
+ if (!Create)
203
+ return void 0;
204
+ targetMetadata = new _Map();
205
+ Metadata.set(O, targetMetadata);
206
+ }
207
+ var metadataMap = targetMetadata.get(P);
208
+ if (IsUndefined(metadataMap)) {
209
+ if (!Create)
210
+ return void 0;
211
+ metadataMap = new _Map();
212
+ targetMetadata.set(P, metadataMap);
213
+ }
214
+ return metadataMap;
215
+ }
216
+ function OrdinaryHasMetadata(MetadataKey, O, P) {
217
+ var hasOwn2 = OrdinaryHasOwnMetadata(MetadataKey, O, P);
218
+ if (hasOwn2)
219
+ return true;
220
+ var parent = OrdinaryGetPrototypeOf(O);
221
+ if (!IsNull(parent))
222
+ return OrdinaryHasMetadata(MetadataKey, parent, P);
223
+ return false;
224
+ }
225
+ function OrdinaryHasOwnMetadata(MetadataKey, O, P) {
226
+ var metadataMap = GetOrCreateMetadataMap(
227
+ O,
228
+ P,
229
+ /*Create*/
230
+ false
231
+ );
232
+ if (IsUndefined(metadataMap))
233
+ return false;
234
+ return ToBoolean(metadataMap.has(MetadataKey));
235
+ }
236
+ function OrdinaryGetMetadata(MetadataKey, O, P) {
237
+ var hasOwn2 = OrdinaryHasOwnMetadata(MetadataKey, O, P);
238
+ if (hasOwn2)
239
+ return OrdinaryGetOwnMetadata(MetadataKey, O, P);
240
+ var parent = OrdinaryGetPrototypeOf(O);
241
+ if (!IsNull(parent))
242
+ return OrdinaryGetMetadata(MetadataKey, parent, P);
243
+ return void 0;
244
+ }
245
+ function OrdinaryGetOwnMetadata(MetadataKey, O, P) {
246
+ var metadataMap = GetOrCreateMetadataMap(
247
+ O,
248
+ P,
249
+ /*Create*/
250
+ false
251
+ );
252
+ if (IsUndefined(metadataMap))
253
+ return void 0;
254
+ return metadataMap.get(MetadataKey);
255
+ }
256
+ function OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) {
257
+ var metadataMap = GetOrCreateMetadataMap(
258
+ O,
259
+ P,
260
+ /*Create*/
261
+ true
262
+ );
263
+ metadataMap.set(MetadataKey, MetadataValue);
264
+ }
265
+ function OrdinaryMetadataKeys(O, P) {
266
+ var ownKeys = OrdinaryOwnMetadataKeys(O, P);
267
+ var parent = OrdinaryGetPrototypeOf(O);
268
+ if (parent === null)
269
+ return ownKeys;
270
+ var parentKeys = OrdinaryMetadataKeys(parent, P);
271
+ if (parentKeys.length <= 0)
272
+ return ownKeys;
273
+ if (ownKeys.length <= 0)
274
+ return parentKeys;
275
+ var set = new _Set();
276
+ var keys = [];
277
+ for (var _i = 0, ownKeys_1 = ownKeys; _i < ownKeys_1.length; _i++) {
278
+ var key = ownKeys_1[_i];
279
+ var hasKey = set.has(key);
280
+ if (!hasKey) {
281
+ set.add(key);
282
+ keys.push(key);
283
+ }
284
+ }
285
+ for (var _a = 0, parentKeys_1 = parentKeys; _a < parentKeys_1.length; _a++) {
286
+ var key = parentKeys_1[_a];
287
+ var hasKey = set.has(key);
288
+ if (!hasKey) {
289
+ set.add(key);
290
+ keys.push(key);
291
+ }
292
+ }
293
+ return keys;
294
+ }
295
+ function OrdinaryOwnMetadataKeys(O, P) {
296
+ var keys = [];
297
+ var metadataMap = GetOrCreateMetadataMap(
298
+ O,
299
+ P,
300
+ /*Create*/
301
+ false
302
+ );
303
+ if (IsUndefined(metadataMap))
304
+ return keys;
305
+ var keysObj = metadataMap.keys();
306
+ var iterator = GetIterator(keysObj);
307
+ var k = 0;
308
+ while (true) {
309
+ var next = IteratorStep(iterator);
310
+ if (!next) {
311
+ keys.length = k;
312
+ return keys;
313
+ }
314
+ var nextValue = IteratorValue(next);
315
+ try {
316
+ keys[k] = nextValue;
317
+ } catch (e) {
318
+ try {
319
+ IteratorClose(iterator);
320
+ } finally {
321
+ throw e;
322
+ }
323
+ }
324
+ k++;
325
+ }
326
+ }
327
+ function Type(x) {
328
+ if (x === null)
329
+ return 1;
330
+ switch (typeof x) {
331
+ case "undefined":
332
+ return 0;
333
+ case "boolean":
334
+ return 2;
335
+ case "string":
336
+ return 3;
337
+ case "symbol":
338
+ return 4;
339
+ case "number":
340
+ return 5;
341
+ case "object":
342
+ return x === null ? 1 : 6;
343
+ default:
344
+ return 6;
345
+ }
346
+ }
347
+ function IsUndefined(x) {
348
+ return x === void 0;
349
+ }
350
+ function IsNull(x) {
351
+ return x === null;
352
+ }
353
+ function IsSymbol(x) {
354
+ return typeof x === "symbol";
355
+ }
356
+ function IsObject(x) {
357
+ return typeof x === "object" ? x !== null : typeof x === "function";
358
+ }
359
+ function ToPrimitive(input, PreferredType) {
360
+ switch (Type(input)) {
361
+ case 0:
362
+ return input;
363
+ case 1:
364
+ return input;
365
+ case 2:
366
+ return input;
367
+ case 3:
368
+ return input;
369
+ case 4:
370
+ return input;
371
+ case 5:
372
+ return input;
373
+ }
374
+ var hint = "string" ;
375
+ var exoticToPrim = GetMethod(input, toPrimitiveSymbol);
376
+ if (exoticToPrim !== void 0) {
377
+ var result = exoticToPrim.call(input, hint);
378
+ if (IsObject(result))
379
+ throw new TypeError();
380
+ return result;
381
+ }
382
+ return OrdinaryToPrimitive(input);
383
+ }
384
+ function OrdinaryToPrimitive(O, hint) {
385
+ var valueOf, result; {
386
+ var toString_1 = O.toString;
387
+ if (IsCallable(toString_1)) {
388
+ var result = toString_1.call(O);
389
+ if (!IsObject(result))
390
+ return result;
391
+ }
392
+ var valueOf = O.valueOf;
393
+ if (IsCallable(valueOf)) {
394
+ var result = valueOf.call(O);
395
+ if (!IsObject(result))
396
+ return result;
397
+ }
398
+ }
399
+ throw new TypeError();
400
+ }
401
+ function ToBoolean(argument) {
402
+ return !!argument;
403
+ }
404
+ function ToString(argument) {
405
+ return "" + argument;
406
+ }
407
+ function ToPropertyKey(argument) {
408
+ var key = ToPrimitive(
409
+ argument);
410
+ if (IsSymbol(key))
411
+ return key;
412
+ return ToString(key);
413
+ }
414
+ function IsArray(argument) {
415
+ return Array.isArray ? Array.isArray(argument) : argument instanceof Object ? argument instanceof Array : Object.prototype.toString.call(argument) === "[object Array]";
416
+ }
417
+ function IsCallable(argument) {
418
+ return typeof argument === "function";
419
+ }
420
+ function IsConstructor(argument) {
421
+ return typeof argument === "function";
422
+ }
423
+ function IsPropertyKey(argument) {
424
+ switch (Type(argument)) {
425
+ case 3:
426
+ return true;
427
+ case 4:
428
+ return true;
429
+ default:
430
+ return false;
431
+ }
432
+ }
433
+ function GetMethod(V, P) {
434
+ var func = V[P];
435
+ if (func === void 0 || func === null)
436
+ return void 0;
437
+ if (!IsCallable(func))
438
+ throw new TypeError();
439
+ return func;
440
+ }
441
+ function GetIterator(obj) {
442
+ var method = GetMethod(obj, iteratorSymbol);
443
+ if (!IsCallable(method))
444
+ throw new TypeError();
445
+ var iterator = method.call(obj);
446
+ if (!IsObject(iterator))
447
+ throw new TypeError();
448
+ return iterator;
449
+ }
450
+ function IteratorValue(iterResult) {
451
+ return iterResult.value;
452
+ }
453
+ function IteratorStep(iterator) {
454
+ var result = iterator.next();
455
+ return result.done ? false : result;
456
+ }
457
+ function IteratorClose(iterator) {
458
+ var f = iterator["return"];
459
+ if (f)
460
+ f.call(iterator);
461
+ }
462
+ function OrdinaryGetPrototypeOf(O) {
463
+ var proto = Object.getPrototypeOf(O);
464
+ if (typeof O !== "function" || O === functionPrototype)
465
+ return proto;
466
+ if (proto !== functionPrototype)
467
+ return proto;
468
+ var prototype = O.prototype;
469
+ var prototypeProto = prototype && Object.getPrototypeOf(prototype);
470
+ if (prototypeProto == null || prototypeProto === Object.prototype)
471
+ return proto;
472
+ var constructor = prototypeProto.constructor;
473
+ if (typeof constructor !== "function")
474
+ return proto;
475
+ if (constructor === O)
476
+ return proto;
477
+ return constructor;
478
+ }
479
+ function CreateMapPolyfill() {
480
+ var cacheSentinel = {};
481
+ var arraySentinel = [];
482
+ var MapIterator = (
483
+ /** @class */
484
+ function() {
485
+ function MapIterator2(keys, values, selector) {
486
+ this._index = 0;
487
+ this._keys = keys;
488
+ this._values = values;
489
+ this._selector = selector;
490
+ }
491
+ MapIterator2.prototype["@@iterator"] = function() {
492
+ return this;
493
+ };
494
+ MapIterator2.prototype[iteratorSymbol] = function() {
495
+ return this;
496
+ };
497
+ MapIterator2.prototype.next = function() {
498
+ var index = this._index;
499
+ if (index >= 0 && index < this._keys.length) {
500
+ var result = this._selector(this._keys[index], this._values[index]);
501
+ if (index + 1 >= this._keys.length) {
502
+ this._index = -1;
503
+ this._keys = arraySentinel;
504
+ this._values = arraySentinel;
505
+ } else {
506
+ this._index++;
507
+ }
508
+ return { value: result, done: false };
509
+ }
510
+ return { value: void 0, done: true };
511
+ };
512
+ MapIterator2.prototype.throw = function(error) {
513
+ if (this._index >= 0) {
514
+ this._index = -1;
515
+ this._keys = arraySentinel;
516
+ this._values = arraySentinel;
517
+ }
518
+ throw error;
519
+ };
520
+ MapIterator2.prototype.return = function(value) {
521
+ if (this._index >= 0) {
522
+ this._index = -1;
523
+ this._keys = arraySentinel;
524
+ this._values = arraySentinel;
525
+ }
526
+ return { value, done: true };
527
+ };
528
+ return MapIterator2;
529
+ }()
530
+ );
531
+ return (
532
+ /** @class */
533
+ function() {
534
+ function Map2() {
535
+ this._keys = [];
536
+ this._values = [];
537
+ this._cacheKey = cacheSentinel;
538
+ this._cacheIndex = -2;
539
+ }
540
+ Object.defineProperty(Map2.prototype, "size", {
541
+ get: function() {
542
+ return this._keys.length;
543
+ },
544
+ enumerable: true,
545
+ configurable: true
546
+ });
547
+ Map2.prototype.has = function(key) {
548
+ return this._find(
549
+ key,
550
+ /*insert*/
551
+ false
552
+ ) >= 0;
553
+ };
554
+ Map2.prototype.get = function(key) {
555
+ var index = this._find(
556
+ key,
557
+ /*insert*/
558
+ false
559
+ );
560
+ return index >= 0 ? this._values[index] : void 0;
561
+ };
562
+ Map2.prototype.set = function(key, value) {
563
+ var index = this._find(
564
+ key,
565
+ /*insert*/
566
+ true
567
+ );
568
+ this._values[index] = value;
569
+ return this;
570
+ };
571
+ Map2.prototype.delete = function(key) {
572
+ var index = this._find(
573
+ key,
574
+ /*insert*/
575
+ false
576
+ );
577
+ if (index >= 0) {
578
+ var size = this._keys.length;
579
+ for (var i = index + 1; i < size; i++) {
580
+ this._keys[i - 1] = this._keys[i];
581
+ this._values[i - 1] = this._values[i];
582
+ }
583
+ this._keys.length--;
584
+ this._values.length--;
585
+ if (key === this._cacheKey) {
586
+ this._cacheKey = cacheSentinel;
587
+ this._cacheIndex = -2;
588
+ }
589
+ return true;
590
+ }
591
+ return false;
592
+ };
593
+ Map2.prototype.clear = function() {
594
+ this._keys.length = 0;
595
+ this._values.length = 0;
596
+ this._cacheKey = cacheSentinel;
597
+ this._cacheIndex = -2;
598
+ };
599
+ Map2.prototype.keys = function() {
600
+ return new MapIterator(this._keys, this._values, getKey);
601
+ };
602
+ Map2.prototype.values = function() {
603
+ return new MapIterator(this._keys, this._values, getValue);
604
+ };
605
+ Map2.prototype.entries = function() {
606
+ return new MapIterator(this._keys, this._values, getEntry);
607
+ };
608
+ Map2.prototype["@@iterator"] = function() {
609
+ return this.entries();
610
+ };
611
+ Map2.prototype[iteratorSymbol] = function() {
612
+ return this.entries();
613
+ };
614
+ Map2.prototype._find = function(key, insert) {
615
+ if (this._cacheKey !== key) {
616
+ this._cacheIndex = this._keys.indexOf(this._cacheKey = key);
617
+ }
618
+ if (this._cacheIndex < 0 && insert) {
619
+ this._cacheIndex = this._keys.length;
620
+ this._keys.push(key);
621
+ this._values.push(void 0);
622
+ }
623
+ return this._cacheIndex;
624
+ };
625
+ return Map2;
626
+ }()
627
+ );
628
+ function getKey(key, _) {
629
+ return key;
630
+ }
631
+ function getValue(_, value) {
632
+ return value;
633
+ }
634
+ function getEntry(key, value) {
635
+ return [key, value];
636
+ }
637
+ }
638
+ function CreateSetPolyfill() {
639
+ return (
640
+ /** @class */
641
+ function() {
642
+ function Set2() {
643
+ this._map = new _Map();
644
+ }
645
+ Object.defineProperty(Set2.prototype, "size", {
646
+ get: function() {
647
+ return this._map.size;
648
+ },
649
+ enumerable: true,
650
+ configurable: true
651
+ });
652
+ Set2.prototype.has = function(value) {
653
+ return this._map.has(value);
654
+ };
655
+ Set2.prototype.add = function(value) {
656
+ return this._map.set(value, value), this;
657
+ };
658
+ Set2.prototype.delete = function(value) {
659
+ return this._map.delete(value);
660
+ };
661
+ Set2.prototype.clear = function() {
662
+ this._map.clear();
663
+ };
664
+ Set2.prototype.keys = function() {
665
+ return this._map.keys();
666
+ };
667
+ Set2.prototype.values = function() {
668
+ return this._map.values();
669
+ };
670
+ Set2.prototype.entries = function() {
671
+ return this._map.entries();
672
+ };
673
+ Set2.prototype["@@iterator"] = function() {
674
+ return this.keys();
675
+ };
676
+ Set2.prototype[iteratorSymbol] = function() {
677
+ return this.keys();
678
+ };
679
+ return Set2;
680
+ }()
681
+ );
682
+ }
683
+ function CreateWeakMapPolyfill() {
684
+ var UUID_SIZE = 16;
685
+ var keys = HashMap.create();
686
+ var rootKey = CreateUniqueKey();
687
+ return (
688
+ /** @class */
689
+ function() {
690
+ function WeakMap2() {
691
+ this._key = CreateUniqueKey();
692
+ }
693
+ WeakMap2.prototype.has = function(target) {
694
+ var table = GetOrCreateWeakMapTable(
695
+ target,
696
+ /*create*/
697
+ false
698
+ );
699
+ return table !== void 0 ? HashMap.has(table, this._key) : false;
700
+ };
701
+ WeakMap2.prototype.get = function(target) {
702
+ var table = GetOrCreateWeakMapTable(
703
+ target,
704
+ /*create*/
705
+ false
706
+ );
707
+ return table !== void 0 ? HashMap.get(table, this._key) : void 0;
708
+ };
709
+ WeakMap2.prototype.set = function(target, value) {
710
+ var table = GetOrCreateWeakMapTable(
711
+ target,
712
+ /*create*/
713
+ true
714
+ );
715
+ table[this._key] = value;
716
+ return this;
717
+ };
718
+ WeakMap2.prototype.delete = function(target) {
719
+ var table = GetOrCreateWeakMapTable(
720
+ target,
721
+ /*create*/
722
+ false
723
+ );
724
+ return table !== void 0 ? delete table[this._key] : false;
725
+ };
726
+ WeakMap2.prototype.clear = function() {
727
+ this._key = CreateUniqueKey();
728
+ };
729
+ return WeakMap2;
730
+ }()
731
+ );
732
+ function CreateUniqueKey() {
733
+ var key;
734
+ do
735
+ key = "@@WeakMap@@" + CreateUUID();
736
+ while (HashMap.has(keys, key));
737
+ keys[key] = true;
738
+ return key;
739
+ }
740
+ function GetOrCreateWeakMapTable(target, create) {
741
+ if (!hasOwn.call(target, rootKey)) {
742
+ if (!create)
743
+ return void 0;
744
+ Object.defineProperty(target, rootKey, { value: HashMap.create() });
745
+ }
746
+ return target[rootKey];
747
+ }
748
+ function FillRandomBytes(buffer, size) {
749
+ for (var i = 0; i < size; ++i)
750
+ buffer[i] = Math.random() * 255 | 0;
751
+ return buffer;
752
+ }
753
+ function GenRandomBytes(size) {
754
+ if (typeof Uint8Array === "function") {
755
+ if (typeof crypto !== "undefined")
756
+ return crypto.getRandomValues(new Uint8Array(size));
757
+ if (typeof msCrypto !== "undefined")
758
+ return msCrypto.getRandomValues(new Uint8Array(size));
759
+ return FillRandomBytes(new Uint8Array(size), size);
760
+ }
761
+ return FillRandomBytes(new Array(size), size);
762
+ }
763
+ function CreateUUID() {
764
+ var data = GenRandomBytes(UUID_SIZE);
765
+ data[6] = data[6] & 79 | 64;
766
+ data[8] = data[8] & 191 | 128;
767
+ var result = "";
768
+ for (var offset = 0; offset < UUID_SIZE; ++offset) {
769
+ var byte = data[offset];
770
+ if (offset === 4 || offset === 6 || offset === 8)
771
+ result += "-";
772
+ if (byte < 16)
773
+ result += "0";
774
+ result += byte.toString(16).toLowerCase();
775
+ }
776
+ return result;
777
+ }
778
+ }
779
+ function MakeDictionary(obj) {
780
+ obj.__ = void 0;
781
+ delete obj.__;
782
+ return obj;
783
+ }
784
+ });
785
+ })(Reflect2 || (Reflect2 = {}));
786
+
787
+ // lib/decorators.ts
788
+ var FIELD_KEY = Symbol("aiem_field");
789
+ var Fields = class {
790
+ static read(options = {}) {
791
+ return function(target, propertyKey, descriptor) {
792
+ Reflect.defineMetadata(FIELD_KEY, { type: "read", options }, target, propertyKey);
793
+ };
794
+ }
795
+ static custom(options = {}) {
796
+ return function(target, propertyKey, descriptor) {
797
+ Reflect.defineMetadata(FIELD_KEY, { type: "custom", options }, target, propertyKey);
798
+ };
799
+ }
800
+ static contract(entity, options) {
801
+ return function(target, propertyKey, descriptor) {
802
+ Reflect.defineMetadata(FIELD_KEY, { type: "contract", entity, targetKey: options }, target, propertyKey);
803
+ };
804
+ }
805
+ };
806
+ function getFieldMetadata(target, propertyKey) {
807
+ return Reflect.getMetadata(FIELD_KEY, target, propertyKey);
808
+ }
809
+
810
+ // aiem.ts
7
811
  mainnet.rpcUrls.default.http = ["https://rpc.ankr.com/eth"];
8
812
  mainnet.rpcUrls.default.webSocket = ["wss://ethereum-rpc.publicnode.com"];
9
813
  var Cache = class {
@@ -12,7 +816,6 @@ var Cache = class {
12
816
  }
13
817
  wrap(key, fn, config = {}) {
14
818
  if (this.kv.has(key)) {
15
- console.log(`load ${key} from cache`);
16
819
  return this.kv.get(key);
17
820
  }
18
821
  const result = fn();
@@ -185,8 +988,66 @@ _AIem.defaultFuncMap = {
185
988
  "decimals": { ttl: 60 * 1e3 },
186
989
  "balanceOf": { ttl: 5 * 1e3 }
187
990
  };
991
+ _AIem.Query = (entity, select) => {
992
+ return async (entities) => {
993
+ const results = [];
994
+ for (const entityData of entities) {
995
+ const instance = Object.assign(new entity(), entityData);
996
+ const result = {};
997
+ const fetchFields = async (obj, sel, res) => {
998
+ const promises = [];
999
+ for (const key in sel) {
1000
+ const fieldMetadata = getFieldMetadata(obj, key);
1001
+ if (fieldMetadata) {
1002
+ switch (fieldMetadata.type) {
1003
+ case "read":
1004
+ promises.push(_AIem.Get(instance.abi, instance.chainId, instance.address).read[key]().then((value) => res[key] = value));
1005
+ break;
1006
+ case "custom":
1007
+ promises.push(obj[key]().then((value) => res[key] = value));
1008
+ break;
1009
+ case "contract":
1010
+ if (fieldMetadata.targetKey) {
1011
+ promises.push(_AIem.Get(instance.abi, instance.chainId, instance.address).read[fieldMetadata.targetKey]().then((address) => {
1012
+ return _AIem.Query(fieldMetadata.entity(), sel[key])([{ address, chainId: instance.chainId }]).then((val) => {
1013
+ res[key] = val[0];
1014
+ });
1015
+ }));
1016
+ }
1017
+ break;
1018
+ }
1019
+ } else if (sel[key] === true) {
1020
+ res[key] = obj[key];
1021
+ }
1022
+ }
1023
+ await Promise.all(promises);
1024
+ };
1025
+ await fetchFields(instance, select, result);
1026
+ results.push(result);
1027
+ }
1028
+ return results;
1029
+ };
1030
+ };
188
1031
  var AIem = _AIem;
1032
+ /*! Bundled license information:
1033
+
1034
+ reflect-metadata/Reflect.js:
1035
+ (*! *****************************************************************************
1036
+ Copyright (C) Microsoft. All rights reserved.
1037
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
1038
+ this file except in compliance with the License. You may obtain a copy of the
1039
+ License at http://www.apache.org/licenses/LICENSE-2.0
1040
+
1041
+ THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1042
+ KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
1043
+ WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
1044
+ MERCHANTABLITY OR NON-INFRINGEMENT.
1045
+
1046
+ See the Apache Version 2.0 License for specific language governing permissions
1047
+ and limitations under the License.
1048
+ ***************************************************************************** *)
1049
+ */
189
1050
 
190
- export { AIem, Cache };
1051
+ export { AIem, Cache, Fields };
191
1052
  //# sourceMappingURL=out.js.map
192
1053
  //# sourceMappingURL=aiem.mjs.map
package/dist/aiem.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../aiem.ts"],"names":[],"mappings":";;;;;AAAA,SAAiD,oBAAoB,aAAa,YAA8E;AAChK,OAAO,SAAS;AAChB,SAAS,OAAO,SAAS,KAAK,SAAS,oBAAqB;AAC5D,OAAO,cAAc;AAGrB,QAAQ,QAAQ,QAAQ,OAAO,CAAC,0BAA0B;AAE1D,QAAQ,QAAQ,QAAQ,YAAY,CAAC,mCAAmC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AAGA,UAAM,WAAW,YAAY;AAAA;AAAA,MAE3B;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AACD,WAAO,IAAI,MAAM,UAAU,OAAO;AAAA,EACpC;AAAA,EAGA,OAAO,OAA4B;AACjC,QAAI,CAAC,WAAW,MAAM;AAEpB,iBAAW,OAAO,IAAI,MAAK;AAAA,IAC7B;AAEA,WAAO,WAAW;AAAA,EACpB;AAAA;AAAA,EAGA,OAAO,IAA4B,KAAW,SAAc,SAAc,QAAkG;AAC1K,UAAM,OAAO,KAAK,KAAK;AAEvB,UAAM,WAAW,YAAY,IAAI,KAAK,UAAU,GAAG,CAAC,CAAC,IAAI,OAAO,IAAI,OAAO,IAAI,SAAS,OAAO,QAAQ,UAAU,IAAI;AACrH,WAAO,KAAK,OAAO,KAAK,UAAU,MAAM;AAEtC,YAAM,YAAY,KAAK,UAAU,OAAO;AAGxC,aAAO,KAAK,YAAY;AAAA,QACtB,QAAQ;AAAA;AAAA,UAEN,QAAQ;AAAA;AAAA,UAER;AAAA,QACF;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;AAxNa,MACJ,QAAgB,IAAI,MAAM;AADtB,MAmBJ,iBAAiB;AAAA,EACtB,eAAe,EAAE,KAAK,KAAK,IAAK;AAAA,EAChC,UAAU,EAAE,KAAK,KAAK,IAAK;AAAA,EAC3B,QAAQ,EAAE,KAAK,KAAK,IAAK;AAAA,EACzB,YAAY,EAAE,KAAK,KAAK,IAAK;AAAA,EAC7B,aAAa,EAAE,KAAK,IAAI,IAAK;AAC/B;AAzBK,IAAM,OAAN","sourcesContent":["import { type Chain, type GetContractReturnType, createPublicClient, getContract, http, type Abi, PublicClient, HttpTransport, WalletClient, AbiFunction } from 'viem'\nimport md5 from \"md5\"\nimport { iotex, mainnet, bsc, polygon, iotexTestnet, } from 'viem/chains'\nimport TTLCache from '@isaacs/ttlcache'\n\n//@ts-ignore\nmainnet.rpcUrls.default.http = ['https://rpc.ankr.com/eth']\n//@ts-ignore\nmainnet.rpcUrls.default.webSocket = [\"wss://ethereum-rpc.publicnode.com\"]\n\n\n\n\nexport class Cache {\n kv = new TTLCache<string, any>({ max: 10000, ttl: 1000 * 60, });\n\n wrap<T>(key: string, fn: () => T | Promise<T>, config: TTLCache.Options<any, any> = {}): T | Promise<T> {\n if (this.kv.has(key)) {\n console.log(`load ${key} from cache`)\n return this.kv.get(key);\n }\n\n const result = fn();\n if (result instanceof Promise) {\n const promiseResult = result.then(res => {\n this.kv.set(key, res, config);\n return res;\n });\n this.kv.set(key, promiseResult, config);\n return promiseResult;\n } else {\n this.kv.set(key, result, config);\n return result;\n }\n }\n}\n\n\nexport class AIem<Contracts extends Record<string, Abi>, Chains extends Record<string, Chain>, Addrs extends { [K in keyof Contracts]?: { [key: string]: `${string}-0x${string}` } }> {\n static cache?: Cache = new Cache()\n cache?: Cache = new Cache()\n contractMap?: Contracts\n //@ts-ignore\n chainMap?: Chains = {\n [iotex.id]: iotex,\n [mainnet.id]: mainnet,\n [bsc.id]: bsc,\n [polygon.id]: polygon,\n [iotexTestnet.id]: iotexTestnet,\n }\n nameMap?: Addrs\n contracts: {\n [K in keyof Addrs & keyof Contracts]: {\n //@ts-ignore\n [KK in keyof Addrs[K]]: GetContractReturnType<Contracts[K], PublicClient<HttpTransport, Chain, any, any>, any, any>\n }\n }\n static defaultFuncMap = {\n \"totalSupply\": { ttl: 15 * 1000 },\n \"symbol\": { ttl: 60 * 1000 },\n \"name\": { ttl: 60 * 1000 },\n \"decimals\": { ttl: 60 * 1000 },\n \"balanceOf\": { ttl: 5 * 1000 }\n }\n funcMap?: { [key: string]: { ttl?: number } } = {}\n\n\n get _cache() {\n return AIem.cache\n }\n\n\n //@ts-ignore\n getWallet?: () => WalletClient\n\n static Set<Contracts extends Record<string, Abi>, Chains extends Record<string, Chain>, Addrs extends { [K in keyof Contracts]?: { [key: string]: `${string}-0x${string}` } }>(args: Pick<AIem<Contracts, Chains, Addrs>, \"contractMap\" | \"chainMap\" | \"nameMap\" | \"getWallet\" | \"cache\" | \"funcMap\">) {\n return this.init().Set(args)\n }\n\n Set<Contracts extends Record<string, Abi>, Chains extends Record<string, Chain>, Addrs extends { [K in keyof Contracts]?: { [key: string]: `${string}-0x${string}` } }>(args: Pick<AIem<Contracts, Chains, Addrs>, \"contractMap\" | \"chainMap\" | \"nameMap\" | \"getWallet\" | \"cache\" | \"funcMap\">): AIem<Contracts, Chains, Addrs> {\n const { chainMap = {}, contractMap = {}, funcMap, ...rest } = args || {}\n //@ts-ignore\n this.chainMap = Object.assign({}, this.chainMap || {}, chainMap)\n //@ts-ignore\n this.contractMap = Object.assign({}, this.contractMap || {}, contractMap)\n //@ts-ignore\n this.funcMap = Object.assign({}, this.funcMap || {}, funcMap)\n\n Object.assign(this, rest)\n return this as any\n }\n\n\n constructor(args: Pick<AIem<Contracts, Chains, Addrs>, \"contractMap\" | \"chainMap\" | \"nameMap\" | \"getWallet\" | \"cache\" | \"funcMap\"> = {}) {\n\n\n this.Set(args)\n\n this.contracts = new Proxy({}, {\n //@ts-ignore\n get: (target: any, contractName: keyof Addrs & keyof Contracts) => {\n if (target[contractName]) return target[contractName]\n\n if (!this.nameMap[contractName]) {\n throw new Error(`Contract ${String(contractName)} not found`);\n }\n\n target[contractName] = new Proxy({}, {\n //@ts-ignore\n get: (innerTarget: any, contractAlias: keyof Addrs[keyof Addrs]) => {\n const addressStr = this.nameMap[contractName]?.[contractAlias];\n if (!addressStr) {\n throw new Error(`Alias ${String(contractAlias)} for contract ${String(contractName)} not found`);\n }\n const [chainId, address] = addressStr.split('-');\n\n\n // Assuming getContractInstance is a function that retrieves a contract instance\n return this.Get(contractName, String(chainId), address as `0x${string}`);\n }\n });\n return target[contractName];\n }\n }) as any;\n\n }\n\n // WsClient<C extends keyof Chains>(chainId: C): PublicClient<WebSocketTransport, Chain, any, any> {\n // //@ts-ignore\n // return this.cache.wrap(`wsClient-${String(chainId)}`, () => {\n // // const wsUrl = this.chainMap[chainId]?.rpcUrls?.default?.webSocket?.[0]\n // // if (!wsUrl) throw new Error(`rpcUrls.default.webSocket[0] is not defined for chainId ${String(chainId)}`)\n // // //@ts-ignore\n // return createPublicClient({\n // //@ts-ignore\n // chain: this.chainMap[chainId],\n // transport: webSocket()\n // }) as PublicClient<WebSocketTransport, Chain, any, any>\n // })\n // }\n\n\n PubClient<C extends keyof Chains>(chainId: C): PublicClient<HttpTransport, Chain, any, any> {\n //@ts-ignore\n return this._cache.wrap(`publicClient-${String(chainId)}`, () => {\n //@ts-ignore\n return createPublicClient({\n //@ts-ignore\n chain: this.chainMap[chainId],\n transport: http()\n }) as PublicClient<HttpTransport, Chain, any, any>\n })\n }\n\n\n //@ts-ignore\n Get<K extends keyof Contracts, C extends keyof Chains, Addr extends `0x${string}`>(contractName: K, chainId: C, address: Addr): GetContractReturnType<Contracts[K], PublicClient<HttpTransport, Chain, any, any>> {\n const wallet = this.getWallet ? this.getWallet() : null\n //@ts-ignore\n const cacheKey = `contract: ${contractName}-${chainId}-${address}-${wallet ? wallet.account.address : wallet}`\n return this._cache.wrap(cacheKey, () => {\n //@ts-ignore\n const contract = this.contractMap[contractName];\n //@ts-ignore\n const pubClient = this.PubClient(chainId)\n\n //@ts-ignore\n return this.getContract({\n client: {\n //@ts-ignore\n public: pubClient,\n //@ts-ignore\n wallet\n },\n address,\n abi: contract\n })\n }) as any\n }\n\n getContract({\n client,\n address,\n abi\n }: {\n client: {\n public: PublicClient<HttpTransport, Chain, any, any>\n wallet?: WalletClient\n }\n address: `0x${string}`\n abi: any,\n }) {\n const handler = {\n get: (target: any, funcName: any) => {\n if (typeof target[funcName] === 'function') {\n return async (...args: any[]) => {\n const methodConfig = this.funcMap?.[funcName as string];\n const cacheKey = `method:${client.public.chain.id}-${address}-${String(funcName)}-${JSON.stringify(args)}`;\n\n if (methodConfig) {\n return this.cache.wrap(cacheKey, () => {\n return target[funcName](...args);\n }, methodConfig);\n }\n\n return target[funcName](...args);\n };\n }\n return new Proxy(target[funcName], handler)\n }\n }\n\n //@ts-ignore\n const contract = getContract({\n //@ts-ignore\n client,\n address,\n abi\n })\n return new Proxy(contract, handler) as any\n }\n\n\n static init(): AIem<any, any, any> {\n if (!globalThis.aiem) {\n //@ts-ignore\n globalThis.aiem = new AIem();\n }\n\n return globalThis.aiem;\n }\n\n //@ts-ignore\n static Get<TAbi extends Abi = any>(abi: TAbi, chainId: any, address: any, wallet?: WalletClient): GetContractReturnType<TAbi, PublicClient<HttpTransport, Chain, any, any>> {\n const aiem = this.init()\n\n const cacheKey = `contract ${md5(JSON.stringify(abi))}-${chainId}-${address}-${wallet ? wallet.account.address : null}`\n return aiem._cache.wrap(cacheKey, () => {\n //@ts-ignore\n const pubClient = aiem.PubClient(chainId)\n\n //@ts-ignore\n return aiem.getContract({\n client: {\n //@ts-ignore\n public: pubClient,\n //@ts-ignore\n wallet\n },\n address,\n abi\n })\n }) as any\n }\n}\n\n\nexport type ReadFunctionKeys<T extends Abi> = T[number] extends infer U\n ? U extends AbiFunction\n ? U['stateMutability'] extends 'view' | 'pure'\n ? U['name']\n : never\n : never\n : never;\n"]}
1
+ {"version":3,"sources":["../aiem.ts","../../../node_modules/reflect-metadata/Reflect.js","../lib/decorators.ts"],"names":["Reflect","hasOwn","MapIterator","Map","Set","WeakMap"],"mappings":";;;;;AAAA,SAAiD,oBAAoB,aAAa,YAA8E;AAChK,OAAO,SAAS;AAChB,SAAS,OAAO,SAAS,KAAK,SAAS,oBAAqB;AAC5D,OAAO,cAAc;;;ACWrB,IAAIA;AAAA,CACH,SAAUA,UAAS;AAGhB,GAAC,SAAU,SAAS;AAChB,QAAI,OAAO,OAAO,WAAW,WAAW,SACpC,OAAO,SAAS,WAAW,OACvB,OAAO,SAAS,WAAW,OACvB,SAAS,cAAc,EAAE;AACrC,QAAI,WAAW,aAAaA,QAAO;AACnC,QAAI,OAAO,KAAK,YAAY,aAAa;AACrC,WAAK,UAAUA;AAAA,IACnB,OACK;AACD,iBAAW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,QAAa;AAC1D,cAAM,WAAW,CAAC;AAClB,mBAAW,OAAO,KAAK;AAGrB,gBAAM,gBAAgB,iBAAiB,KAAK,GAAG;AAG/C,cAAI,eAAe;AACjB,oBAAQ,cAAc,MAAM;AAAA,cAC1B,KAAK;AAEH,yBAAS,KAAK,MAAK,IAAI,SAAS,KAAK,SAAS,SAAS,SAAS,OAAO,EAAE,KAAK,GAAG,EAAE,EAAE,KAAK,CAAC,UAAe,IAAI,GAAG,IAAI,KAAK,CAAC;AAC3H;AAAA,cACF,KAAK;AACH,yBAAS,KAAK,IAAI,GAAG,EAAE,EAAE,KAAK,CAAC,UAAe,IAAI,GAAG,IAAI,KAAK,CAAC;AAC/D;AAAA,cACF,KAAK;AAEH,oBAAI,cAAc,WAAW;AAE3B,2BAAS,KAAK,MAAK,IAAI,SAAS,KAAK,SAAS,SAAS,SAAS,OAAO,EAAE,KAAK,cAAc,SAAS,EAAE,EAAE,KAAK,CAAC,YAAiB;AAG9H,2BAAO,MAAK,MAAM,cAAc,OAAO,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC,EAAE,SAAS,SAAS,SAAS,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,QAAa;AAC/G,0BAAI,GAAG,IAAI,IAAI,CAAC;AAAA,oBAClB,CAAC;AAAA,kBACH,CAAC,CAAC;AAAA,gBACJ;AACA;AAAA,cACF;AACE;AAAA,YACJ;AAAA,UACF,WAAW,IAAI,GAAG,MAAM,MAAM;AAC5B,gBAAI,GAAG,IAAI,IAAI,GAAG;AAAA,UACpB;AAAA,QACF;AACA,cAAM,QAAQ,IAAI,QAAQ;AAAA,MAC5B;AAEA,YAAM,YAAY,UAAU,QAAQ,MAAM;AAC1C,cAAQ,KAAK,MAAM;AAAA,IACrB;AAEA,WAAO;AAAA,EACT;AACF;AAlRK,IAAM,OAAN","sourcesContent":["import { type Chain, type GetContractReturnType, createPublicClient, getContract, http, type Abi, PublicClient, HttpTransport, WalletClient, AbiFunction } from 'viem'\nimport md5 from \"md5\"\nimport { iotex, mainnet, bsc, polygon, iotexTestnet, } from 'viem/chains'\nimport TTLCache from '@isaacs/ttlcache'\nimport { ClassType } from \"./lib/interface\"\nimport { Fields, getFieldMetadata } from \"./lib/decorators\"\n\n//@ts-ignore\nmainnet.rpcUrls.default.http = ['https://rpc.ankr.com/eth']\n//@ts-ignore\nmainnet.rpcUrls.default.webSocket = [\"wss://ethereum-rpc.publicnode.com\"]\n\n\n\n\nexport { Fields } from \"./lib/decorators\"\n\nexport class Cache {\n kv = new TTLCache<string, any>({ max: 10000, ttl: 1000 * 60, });\n\n wrap<T>(key: string, fn: () => T | Promise<T>, config: TTLCache.Options<any, any> = {}): T | Promise<T> {\n if (this.kv.has(key)) {\n // console.log(`load ${key} from cache`)\n return this.kv.get(key);\n }\n\n const result = fn();\n if (result instanceof Promise) {\n const promiseResult = result.then(res => {\n this.kv.set(key, res, config);\n return res;\n });\n this.kv.set(key, promiseResult, config);\n return promiseResult;\n } else {\n this.kv.set(key, result, config);\n return result;\n }\n }\n}\n\n\nexport class AIem<Contracts extends Record<string, Abi>, Chains extends Record<string, Chain>, Addrs extends { [K in keyof Contracts]?: { [key: string]: `${string}-0x${string}` } }> {\n static cache?: Cache = new Cache()\n cache?: Cache = new Cache()\n contractMap?: Contracts\n //@ts-ignore\n chainMap?: Chains = {\n [iotex.id]: iotex,\n [mainnet.id]: mainnet,\n [bsc.id]: bsc,\n [polygon.id]: polygon,\n [iotexTestnet.id]: iotexTestnet,\n }\n nameMap?: Addrs\n contracts: {\n [K in keyof Addrs & keyof Contracts]: {\n //@ts-ignore\n [KK in keyof Addrs[K]]: GetContractReturnType<Contracts[K], PublicClient<HttpTransport, Chain, any, any>, any, any>\n }\n }\n static defaultFuncMap = {\n \"totalSupply\": { ttl: 15 * 1000 },\n \"symbol\": { ttl: 60 * 1000 },\n \"name\": { ttl: 60 * 1000 },\n \"decimals\": { ttl: 60 * 1000 },\n \"balanceOf\": { ttl: 5 * 1000 }\n }\n funcMap?: { [key: string]: { ttl?: number } } = {}\n\n\n get _cache() {\n return AIem.cache\n }\n\n\n //@ts-ignore\n getWallet?: () => WalletClient\n\n static Set<Contracts extends Record<string, Abi>, Chains extends Record<string, Chain>, Addrs extends { [K in keyof Contracts]?: { [key: string]: `${string}-0x${string}` } }>(args: Pick<AIem<Contracts, Chains, Addrs>, \"contractMap\" | \"chainMap\" | \"nameMap\" | \"getWallet\" | \"cache\" | \"funcMap\">) {\n return this.init().Set(args)\n }\n\n Set<Contracts extends Record<string, Abi>, Chains extends Record<string, Chain>, Addrs extends { [K in keyof Contracts]?: { [key: string]: `${string}-0x${string}` } }>(args: Pick<AIem<Contracts, Chains, Addrs>, \"contractMap\" | \"chainMap\" | \"nameMap\" | \"getWallet\" | \"cache\" | \"funcMap\">): AIem<Contracts, Chains, Addrs> {\n const { chainMap = {}, contractMap = {}, funcMap, ...rest } = args || {}\n //@ts-ignore\n this.chainMap = Object.assign({}, this.chainMap || {}, chainMap)\n //@ts-ignore\n this.contractMap = Object.assign({}, this.contractMap || {}, contractMap)\n //@ts-ignore\n this.funcMap = Object.assign({}, this.funcMap || {}, funcMap)\n\n Object.assign(this, rest)\n return this as any\n }\n\n\n constructor(args: Pick<AIem<Contracts, Chains, Addrs>, \"contractMap\" | \"chainMap\" | \"nameMap\" | \"getWallet\" | \"cache\" | \"funcMap\"> = {}) {\n\n\n this.Set(args)\n\n this.contracts = new Proxy({}, {\n //@ts-ignore\n get: (target: any, contractName: keyof Addrs & keyof Contracts) => {\n if (target[contractName]) return target[contractName]\n\n if (!this.nameMap[contractName]) {\n throw new Error(`Contract ${String(contractName)} not found`);\n }\n\n target[contractName] = new Proxy({}, {\n //@ts-ignore\n get: (innerTarget: any, contractAlias: keyof Addrs[keyof Addrs]) => {\n const addressStr = this.nameMap[contractName]?.[contractAlias];\n if (!addressStr) {\n throw new Error(`Alias ${String(contractAlias)} for contract ${String(contractName)} not found`);\n }\n const [chainId, address] = addressStr.split('-');\n\n\n // Assuming getContractInstance is a function that retrieves a contract instance\n return this.Get(contractName, String(chainId), address as `0x${string}`);\n }\n });\n return target[contractName];\n }\n }) as any;\n\n }\n\n // WsClient<C extends keyof Chains>(chainId: C): PublicClient<WebSocketTransport, Chain, any, any> {\n // //@ts-ignore\n // return this.cache.wrap(`wsClient-${String(chainId)}`, () => {\n // // const wsUrl = this.chainMap[chainId]?.rpcUrls?.default?.webSocket?.[0]\n // // if (!wsUrl) throw new Error(`rpcUrls.default.webSocket[0] is not defined for chainId ${String(chainId)}`)\n // // //@ts-ignore\n // return createPublicClient({\n // //@ts-ignore\n // chain: this.chainMap[chainId],\n // transport: webSocket()\n // }) as PublicClient<WebSocketTransport, Chain, any, any>\n // })\n // }\n\n\n PubClient<C extends keyof Chains>(chainId: C): PublicClient<HttpTransport, Chain, any, any> {\n //@ts-ignore\n return this._cache.wrap(`publicClient-${String(chainId)}`, () => {\n //@ts-ignore\n return createPublicClient({\n //@ts-ignore\n chain: this.chainMap[chainId],\n transport: http()\n }) as PublicClient<HttpTransport, Chain, any, any>\n })\n }\n\n\n //@ts-ignore\n Get<K extends keyof Contracts, C extends keyof Chains, Addr extends `0x${string}`>(contractName: K, chainId: C, address: Addr): GetContractReturnType<Contracts[K], PublicClient<HttpTransport, Chain, any, any>> {\n const wallet = this.getWallet ? this.getWallet() : null\n //@ts-ignore\n const cacheKey = `contract: ${contractName}-${chainId}-${address}-${wallet ? wallet.account.address : wallet}`\n return this._cache.wrap(cacheKey, () => {\n //@ts-ignore\n const contract = this.contractMap[contractName];\n //@ts-ignore\n const pubClient = this.PubClient(chainId)\n\n //@ts-ignore\n return this.getContract({\n client: {\n //@ts-ignore\n public: pubClient,\n //@ts-ignore\n wallet\n },\n address,\n abi: contract\n })\n }) as any\n }\n\n getContract({\n client,\n address,\n abi\n }: {\n client: {\n public: PublicClient<HttpTransport, Chain, any, any>\n wallet?: WalletClient\n }\n address: `0x${string}`\n abi: any,\n }) {\n const handler = {\n get: (target: any, funcName: any) => {\n if (typeof target[funcName] === 'function') {\n return async (...args: any[]) => {\n const methodConfig = this.funcMap?.[funcName as string];\n const cacheKey = `method:${client.public.chain.id}-${address}-${String(funcName)}-${JSON.stringify(args)}`;\n\n if (methodConfig) {\n return this.cache.wrap(cacheKey, () => {\n return target[funcName](...args);\n }, methodConfig);\n }\n\n return target[funcName](...args);\n };\n }\n return new Proxy(target[funcName], handler)\n }\n }\n\n //@ts-ignore\n const contract = getContract({\n //@ts-ignore\n client,\n address,\n abi\n })\n return new Proxy(contract, handler) as any\n }\n\n\n static init(): AIem<any, any, any> {\n if (!globalThis.aiem) {\n //@ts-ignore\n globalThis.aiem = new AIem();\n }\n\n return globalThis.aiem;\n }\n\n //@ts-ignore\n static Get<TAbi extends Abi = any>(abi: TAbi, chainId: any, address: any, wallet?: WalletClient): GetContractReturnType<TAbi, PublicClient<HttpTransport, Chain, any, any>> {\n const aiem = this.init()\n\n const cacheKey = `contract ${md5(JSON.stringify(abi))}-${chainId}-${address}-${wallet ? wallet.account.address : null}`\n return aiem._cache.wrap(cacheKey, () => {\n //@ts-ignore\n const pubClient = aiem.PubClient(chainId)\n\n //@ts-ignore\n return aiem.getContract({\n client: {\n //@ts-ignore\n public: pubClient,\n //@ts-ignore\n wallet\n },\n address,\n abi\n })\n }) as any\n }\n\n static Query = <E, S extends QuerySelect<E>>(\n entity: ClassType<E>,\n select: S\n ): ((entities: Partial<E>[]) => Promise<Array<Partial<QueryReturnType<E, S>>>>) => {\n return async (entities: Partial<E>[]): Promise<Array<Partial<QueryReturnType<E, S>>>> => {\n const results: Array<Partial<QueryReturnType<E, S>>> = [];\n\n for (const entityData of entities) {\n const instance = Object.assign(new entity(), entityData);\n const result: any = {};\n\n const fetchFields = async (obj: any, sel: any, res: any) => {\n const promises = [];\n for (const key in sel) {\n // return console.log(key, getFieldMetadata(obj, key))\n // Check if the property is annotated with @Fields.read(), @Fields.custom(), or @Fields.contract()\n const fieldMetadata = getFieldMetadata(obj, key);\n\n // console.log(key, fieldMetadata, instance)\n if (fieldMetadata) {\n switch (fieldMetadata.type) {\n case 'read':\n //@ts-ignore\n promises.push(this.Get(instance.abi, instance.chainId, instance.address).read[key]().then((value: any) => res[key] = value));\n break\n case 'custom':\n promises.push(obj[key]().then((value: any) => res[key] = value));\n break;\n case 'contract':\n // console.log(fieldMetadata)\n if (fieldMetadata.targetKey) {\n //@ts-ignore\n promises.push(this.Get(instance.abi, instance.chainId, instance.address).read[fieldMetadata.targetKey]().then((address: any) => {\n // console.log({ address, sel: sel[key] })\n //@ts-ignore\n return this.Query(fieldMetadata.entity(), sel[key])([{ address, chainId: instance.chainId }]).then((val: any) => {\n res[key] = val[0]\n })\n }))\n }\n break;\n default:\n break;\n }\n } else if (sel[key] === true) {\n res[key] = obj[key];\n }\n }\n await Promise.all(promises);\n };\n\n await fetchFields(instance, select, result);\n results.push(result);\n }\n\n return results;\n };\n };\n}\nexport type ReadFunctionKeys<T extends Abi> = T[number] extends infer U\n ? U extends AbiFunction\n ? U['stateMutability'] extends 'view' | 'pure'\n ? U['name']\n : never\n : never\n : never;\n\n\ntype QuerySelect<E> = {\n [K in keyof E]?: E[K] extends (...args: any[]) => any\n ? boolean\n : E[K] extends object\n ? QuerySelect<E[K]>\n : boolean;\n};\n\ntype QueryReturnType<E, S> = {\n [K in keyof S]: S[K] extends true\n ? K extends keyof E ? E[K] : never\n : S[K] extends QuerySelect<infer T>\n //@ts-ignore\n ? QueryReturnType<E[K], T>\n : never;\n};","/*! *****************************************************************************\nCopyright (C) Microsoft. All rights reserved.\nLicensed under the Apache License, Version 2.0 (the \"License\"); you may not use\nthis file except in compliance with the License. You may obtain a copy of the\nLicense at http://www.apache.org/licenses/LICENSE-2.0\n\nTHIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\nKIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED\nWARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,\nMERCHANTABLITY OR NON-INFRINGEMENT.\n\nSee the Apache Version 2.0 License for specific language governing permissions\nand limitations under the License.\n***************************************************************************** */\nvar Reflect;\n(function (Reflect) {\n // Metadata Proposal\n // https://rbuckton.github.io/reflect-metadata/\n (function (factory) {\n var root = typeof global === \"object\" ? global :\n typeof self === \"object\" ? self :\n typeof this === \"object\" ? this :\n Function(\"return this;\")();\n var exporter = makeExporter(Reflect);\n if (typeof root.Reflect === \"undefined\") {\n root.Reflect = Reflect;\n }\n else {\n exporter = makeExporter(root.Reflect, exporter);\n }\n factory(exporter);\n function makeExporter(target, previous) {\n return function (key, value) {\n if (typeof target[key] !== \"function\") {\n Object.defineProperty(target, key, { configurable: true, writable: true, value: value });\n }\n if (previous)\n previous(key, value);\n };\n }\n })(function (exporter) {\n var hasOwn = Object.prototype.hasOwnProperty;\n // feature test for Symbol support\n var supportsSymbol = typeof Symbol === \"function\";\n var toPrimitiveSymbol = supportsSymbol && typeof Symbol.toPrimitive !== \"undefined\" ? Symbol.toPrimitive : \"@@toPrimitive\";\n var iteratorSymbol = supportsSymbol && typeof Symbol.iterator !== \"undefined\" ? Symbol.iterator : \"@@iterator\";\n var supportsCreate = typeof Object.create === \"function\"; // feature test for Object.create support\n var supportsProto = { __proto__: [] } instanceof Array; // feature test for __proto__ support\n var downLevel = !supportsCreate && !supportsProto;\n var HashMap = {\n // create an object in dictionary mode (a.k.a. \"slow\" mode in v8)\n create: supportsCreate\n ? function () { return MakeDictionary(Object.create(null)); }\n : supportsProto\n ? function () { return MakeDictionary({ __proto__: null }); }\n : function () { return MakeDictionary({}); },\n has: downLevel\n ? function (map, key) { return hasOwn.call(map, key); }\n : function (map, key) { return key in map; },\n get: downLevel\n ? function (map, key) { return hasOwn.call(map, key) ? map[key] : undefined; }\n : function (map, key) { return map[key]; },\n };\n // Load global or shim versions of Map, Set, and WeakMap\n var functionPrototype = Object.getPrototypeOf(Function);\n var usePolyfill = typeof process === \"object\" && process.env && process.env[\"REFLECT_METADATA_USE_MAP_POLYFILL\"] === \"true\";\n var _Map = !usePolyfill && typeof Map === \"function\" && typeof Map.prototype.entries === \"function\" ? Map : CreateMapPolyfill();\n var _Set = !usePolyfill && typeof Set === \"function\" && typeof Set.prototype.entries === \"function\" ? Set : CreateSetPolyfill();\n var _WeakMap = !usePolyfill && typeof WeakMap === \"function\" ? WeakMap : CreateWeakMapPolyfill();\n // [[Metadata]] internal slot\n // https://rbuckton.github.io/reflect-metadata/#ordinary-object-internal-methods-and-internal-slots\n var Metadata = new _WeakMap();\n /**\n * Applies a set of decorators to a property of a target object.\n * @param decorators An array of decorators.\n * @param target The target object.\n * @param propertyKey (Optional) The property key to decorate.\n * @param attributes (Optional) The property descriptor for the target key.\n * @remarks Decorators are applied in reverse order.\n * @example\n *\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * constructor(p) { }\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * Example = Reflect.decorate(decoratorsArray, Example);\n *\n * // property (on constructor)\n * Reflect.decorate(decoratorsArray, Example, \"staticProperty\");\n *\n * // property (on prototype)\n * Reflect.decorate(decoratorsArray, Example.prototype, \"property\");\n *\n * // method (on constructor)\n * Object.defineProperty(Example, \"staticMethod\",\n * Reflect.decorate(decoratorsArray, Example, \"staticMethod\",\n * Object.getOwnPropertyDescriptor(Example, \"staticMethod\")));\n *\n * // method (on prototype)\n * Object.defineProperty(Example.prototype, \"method\",\n * Reflect.decorate(decoratorsArray, Example.prototype, \"method\",\n * Object.getOwnPropertyDescriptor(Example.prototype, \"method\")));\n *\n */\n function decorate(decorators, target, propertyKey, attributes) {\n if (!IsUndefined(propertyKey)) {\n if (!IsArray(decorators))\n throw new TypeError();\n if (!IsObject(target))\n throw new TypeError();\n if (!IsObject(attributes) && !IsUndefined(attributes) && !IsNull(attributes))\n throw new TypeError();\n if (IsNull(attributes))\n attributes = undefined;\n propertyKey = ToPropertyKey(propertyKey);\n return DecorateProperty(decorators, target, propertyKey, attributes);\n }\n else {\n if (!IsArray(decorators))\n throw new TypeError();\n if (!IsConstructor(target))\n throw new TypeError();\n return DecorateConstructor(decorators, target);\n }\n }\n exporter(\"decorate\", decorate);\n // 4.1.2 Reflect.metadata(metadataKey, metadataValue)\n // https://rbuckton.github.io/reflect-metadata/#reflect.metadata\n /**\n * A default metadata decorator factory that can be used on a class, class member, or parameter.\n * @param metadataKey The key for the metadata entry.\n * @param metadataValue The value for the metadata entry.\n * @returns A decorator function.\n * @remarks\n * If `metadataKey` is already defined for the target and target key, the\n * metadataValue for that key will be overwritten.\n * @example\n *\n * // constructor\n * @Reflect.metadata(key, value)\n * class Example {\n * }\n *\n * // property (on constructor, TypeScript only)\n * class Example {\n * @Reflect.metadata(key, value)\n * static staticProperty;\n * }\n *\n * // property (on prototype, TypeScript only)\n * class Example {\n * @Reflect.metadata(key, value)\n * property;\n * }\n *\n * // method (on constructor)\n * class Example {\n * @Reflect.metadata(key, value)\n * static staticMethod() { }\n * }\n *\n * // method (on prototype)\n * class Example {\n * @Reflect.metadata(key, value)\n * method() { }\n * }\n *\n */\n function metadata(metadataKey, metadataValue) {\n function decorator(target, propertyKey) {\n if (!IsObject(target))\n throw new TypeError();\n if (!IsUndefined(propertyKey) && !IsPropertyKey(propertyKey))\n throw new TypeError();\n OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);\n }\n return decorator;\n }\n exporter(\"metadata\", metadata);\n /**\n * Define a unique metadata entry on the target.\n * @param metadataKey A key used to store and retrieve metadata.\n * @param metadataValue A value that contains attached metadata.\n * @param target The target object on which to define metadata.\n * @param propertyKey (Optional) The property key for the target.\n * @example\n *\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * constructor(p) { }\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * Reflect.defineMetadata(\"custom:annotation\", options, Example);\n *\n * // property (on constructor)\n * Reflect.defineMetadata(\"custom:annotation\", options, Example, \"staticProperty\");\n *\n * // property (on prototype)\n * Reflect.defineMetadata(\"custom:annotation\", options, Example.prototype, \"property\");\n *\n * // method (on constructor)\n * Reflect.defineMetadata(\"custom:annotation\", options, Example, \"staticMethod\");\n *\n * // method (on prototype)\n * Reflect.defineMetadata(\"custom:annotation\", options, Example.prototype, \"method\");\n *\n * // decorator factory as metadata-producing annotation.\n * function MyAnnotation(options): Decorator {\n * return (target, key?) => Reflect.defineMetadata(\"custom:annotation\", options, target, key);\n * }\n *\n */\n function defineMetadata(metadataKey, metadataValue, target, propertyKey) {\n if (!IsObject(target))\n throw new TypeError();\n if (!IsUndefined(propertyKey))\n propertyKey = ToPropertyKey(propertyKey);\n return OrdinaryDefineOwnMetadata(metadataKey, metadataValue, target, propertyKey);\n }\n exporter(\"defineMetadata\", defineMetadata);\n /**\n * Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.\n * @param metadataKey A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey (Optional) The property key for the target.\n * @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.\n * @example\n *\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * constructor(p) { }\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Reflect.hasMetadata(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Reflect.hasMetadata(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Reflect.hasMetadata(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Reflect.hasMetadata(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Reflect.hasMetadata(\"custom:annotation\", Example.prototype, \"method\");\n *\n */\n function hasMetadata(metadataKey, target, propertyKey) {\n if (!IsObject(target))\n throw new TypeError();\n if (!IsUndefined(propertyKey))\n propertyKey = ToPropertyKey(propertyKey);\n return OrdinaryHasMetadata(metadataKey, target, propertyKey);\n }\n exporter(\"hasMetadata\", hasMetadata);\n /**\n * Gets a value indicating whether the target object has the provided metadata key defined.\n * @param metadataKey A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey (Optional) The property key for the target.\n * @returns `true` if the metadata key was defined on the target object; otherwise, `false`.\n * @example\n *\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * constructor(p) { }\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Reflect.hasOwnMetadata(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Reflect.hasOwnMetadata(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Reflect.hasOwnMetadata(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Reflect.hasOwnMetadata(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Reflect.hasOwnMetadata(\"custom:annotation\", Example.prototype, \"method\");\n *\n */\n function hasOwnMetadata(metadataKey, target, propertyKey) {\n if (!IsObject(target))\n throw new TypeError();\n if (!IsUndefined(propertyKey))\n propertyKey = ToPropertyKey(propertyKey);\n return OrdinaryHasOwnMetadata(metadataKey, target, propertyKey);\n }\n exporter(\"hasOwnMetadata\", hasOwnMetadata);\n /**\n * Gets the metadata value for the provided metadata key on the target object or its prototype chain.\n * @param metadataKey A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey (Optional) The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * constructor(p) { }\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Reflect.getMetadata(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Reflect.getMetadata(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Reflect.getMetadata(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Reflect.getMetadata(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Reflect.getMetadata(\"custom:annotation\", Example.prototype, \"method\");\n *\n */\n function getMetadata(metadataKey, target, propertyKey) {\n if (!IsObject(target))\n throw new TypeError();\n if (!IsUndefined(propertyKey))\n propertyKey = ToPropertyKey(propertyKey);\n return OrdinaryGetMetadata(metadataKey, target, propertyKey);\n }\n exporter(\"getMetadata\", getMetadata);\n /**\n * Gets the metadata value for the provided metadata key on the target object.\n * @param metadataKey A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey (Optional) The property key for the target.\n * @returns The metadata value for the metadata key if found; otherwise, `undefined`.\n * @example\n *\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * constructor(p) { }\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Reflect.getOwnMetadata(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Reflect.getOwnMetadata(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Reflect.getOwnMetadata(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Reflect.getOwnMetadata(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Reflect.getOwnMetadata(\"custom:annotation\", Example.prototype, \"method\");\n *\n */\n function getOwnMetadata(metadataKey, target, propertyKey) {\n if (!IsObject(target))\n throw new TypeError();\n if (!IsUndefined(propertyKey))\n propertyKey = ToPropertyKey(propertyKey);\n return OrdinaryGetOwnMetadata(metadataKey, target, propertyKey);\n }\n exporter(\"getOwnMetadata\", getOwnMetadata);\n /**\n * Gets the metadata keys defined on the target object or its prototype chain.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey (Optional) The property key for the target.\n * @returns An array of unique metadata keys.\n * @example\n *\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * constructor(p) { }\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Reflect.getMetadataKeys(Example);\n *\n * // property (on constructor)\n * result = Reflect.getMetadataKeys(Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Reflect.getMetadataKeys(Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Reflect.getMetadataKeys(Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Reflect.getMetadataKeys(Example.prototype, \"method\");\n *\n */\n function getMetadataKeys(target, propertyKey) {\n if (!IsObject(target))\n throw new TypeError();\n if (!IsUndefined(propertyKey))\n propertyKey = ToPropertyKey(propertyKey);\n return OrdinaryMetadataKeys(target, propertyKey);\n }\n exporter(\"getMetadataKeys\", getMetadataKeys);\n /**\n * Gets the unique metadata keys defined on the target object.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey (Optional) The property key for the target.\n * @returns An array of unique metadata keys.\n * @example\n *\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * constructor(p) { }\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Reflect.getOwnMetadataKeys(Example);\n *\n * // property (on constructor)\n * result = Reflect.getOwnMetadataKeys(Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Reflect.getOwnMetadataKeys(Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Reflect.getOwnMetadataKeys(Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Reflect.getOwnMetadataKeys(Example.prototype, \"method\");\n *\n */\n function getOwnMetadataKeys(target, propertyKey) {\n if (!IsObject(target))\n throw new TypeError();\n if (!IsUndefined(propertyKey))\n propertyKey = ToPropertyKey(propertyKey);\n return OrdinaryOwnMetadataKeys(target, propertyKey);\n }\n exporter(\"getOwnMetadataKeys\", getOwnMetadataKeys);\n /**\n * Deletes the metadata entry from the target object with the provided key.\n * @param metadataKey A key used to store and retrieve metadata.\n * @param target The target object on which the metadata is defined.\n * @param propertyKey (Optional) The property key for the target.\n * @returns `true` if the metadata entry was found and deleted; otherwise, false.\n * @example\n *\n * class Example {\n * // property declarations are not part of ES6, though they are valid in TypeScript:\n * // static staticProperty;\n * // property;\n *\n * constructor(p) { }\n * static staticMethod(p) { }\n * method(p) { }\n * }\n *\n * // constructor\n * result = Reflect.deleteMetadata(\"custom:annotation\", Example);\n *\n * // property (on constructor)\n * result = Reflect.deleteMetadata(\"custom:annotation\", Example, \"staticProperty\");\n *\n * // property (on prototype)\n * result = Reflect.deleteMetadata(\"custom:annotation\", Example.prototype, \"property\");\n *\n * // method (on constructor)\n * result = Reflect.deleteMetadata(\"custom:annotation\", Example, \"staticMethod\");\n *\n * // method (on prototype)\n * result = Reflect.deleteMetadata(\"custom:annotation\", Example.prototype, \"method\");\n *\n */\n function deleteMetadata(metadataKey, target, propertyKey) {\n if (!IsObject(target))\n throw new TypeError();\n if (!IsUndefined(propertyKey))\n propertyKey = ToPropertyKey(propertyKey);\n var metadataMap = GetOrCreateMetadataMap(target, propertyKey, /*Create*/ false);\n if (IsUndefined(metadataMap))\n return false;\n if (!metadataMap.delete(metadataKey))\n return false;\n if (metadataMap.size > 0)\n return true;\n var targetMetadata = Metadata.get(target);\n targetMetadata.delete(propertyKey);\n if (targetMetadata.size > 0)\n return true;\n Metadata.delete(target);\n return true;\n }\n exporter(\"deleteMetadata\", deleteMetadata);\n function DecorateConstructor(decorators, target) {\n for (var i = decorators.length - 1; i >= 0; --i) {\n var decorator = decorators[i];\n var decorated = decorator(target);\n if (!IsUndefined(decorated) && !IsNull(decorated)) {\n if (!IsConstructor(decorated))\n throw new TypeError();\n target = decorated;\n }\n }\n return target;\n }\n function DecorateProperty(decorators, target, propertyKey, descriptor) {\n for (var i = decorators.length - 1; i >= 0; --i) {\n var decorator = decorators[i];\n var decorated = decorator(target, propertyKey, descriptor);\n if (!IsUndefined(decorated) && !IsNull(decorated)) {\n if (!IsObject(decorated))\n throw new TypeError();\n descriptor = decorated;\n }\n }\n return descriptor;\n }\n function GetOrCreateMetadataMap(O, P, Create) {\n var targetMetadata = Metadata.get(O);\n if (IsUndefined(targetMetadata)) {\n if (!Create)\n return undefined;\n targetMetadata = new _Map();\n Metadata.set(O, targetMetadata);\n }\n var metadataMap = targetMetadata.get(P);\n if (IsUndefined(metadataMap)) {\n if (!Create)\n return undefined;\n metadataMap = new _Map();\n targetMetadata.set(P, metadataMap);\n }\n return metadataMap;\n }\n // 3.1.1.1 OrdinaryHasMetadata(MetadataKey, O, P)\n // https://rbuckton.github.io/reflect-metadata/#ordinaryhasmetadata\n function OrdinaryHasMetadata(MetadataKey, O, P) {\n var hasOwn = OrdinaryHasOwnMetadata(MetadataKey, O, P);\n if (hasOwn)\n return true;\n var parent = OrdinaryGetPrototypeOf(O);\n if (!IsNull(parent))\n return OrdinaryHasMetadata(MetadataKey, parent, P);\n return false;\n }\n // 3.1.2.1 OrdinaryHasOwnMetadata(MetadataKey, O, P)\n // https://rbuckton.github.io/reflect-metadata/#ordinaryhasownmetadata\n function OrdinaryHasOwnMetadata(MetadataKey, O, P) {\n var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);\n if (IsUndefined(metadataMap))\n return false;\n return ToBoolean(metadataMap.has(MetadataKey));\n }\n // 3.1.3.1 OrdinaryGetMetadata(MetadataKey, O, P)\n // https://rbuckton.github.io/reflect-metadata/#ordinarygetmetadata\n function OrdinaryGetMetadata(MetadataKey, O, P) {\n var hasOwn = OrdinaryHasOwnMetadata(MetadataKey, O, P);\n if (hasOwn)\n return OrdinaryGetOwnMetadata(MetadataKey, O, P);\n var parent = OrdinaryGetPrototypeOf(O);\n if (!IsNull(parent))\n return OrdinaryGetMetadata(MetadataKey, parent, P);\n return undefined;\n }\n // 3.1.4.1 OrdinaryGetOwnMetadata(MetadataKey, O, P)\n // https://rbuckton.github.io/reflect-metadata/#ordinarygetownmetadata\n function OrdinaryGetOwnMetadata(MetadataKey, O, P) {\n var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);\n if (IsUndefined(metadataMap))\n return undefined;\n return metadataMap.get(MetadataKey);\n }\n // 3.1.5.1 OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P)\n // https://rbuckton.github.io/reflect-metadata/#ordinarydefineownmetadata\n function OrdinaryDefineOwnMetadata(MetadataKey, MetadataValue, O, P) {\n var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ true);\n metadataMap.set(MetadataKey, MetadataValue);\n }\n // 3.1.6.1 OrdinaryMetadataKeys(O, P)\n // https://rbuckton.github.io/reflect-metadata/#ordinarymetadatakeys\n function OrdinaryMetadataKeys(O, P) {\n var ownKeys = OrdinaryOwnMetadataKeys(O, P);\n var parent = OrdinaryGetPrototypeOf(O);\n if (parent === null)\n return ownKeys;\n var parentKeys = OrdinaryMetadataKeys(parent, P);\n if (parentKeys.length <= 0)\n return ownKeys;\n if (ownKeys.length <= 0)\n return parentKeys;\n var set = new _Set();\n var keys = [];\n for (var _i = 0, ownKeys_1 = ownKeys; _i < ownKeys_1.length; _i++) {\n var key = ownKeys_1[_i];\n var hasKey = set.has(key);\n if (!hasKey) {\n set.add(key);\n keys.push(key);\n }\n }\n for (var _a = 0, parentKeys_1 = parentKeys; _a < parentKeys_1.length; _a++) {\n var key = parentKeys_1[_a];\n var hasKey = set.has(key);\n if (!hasKey) {\n set.add(key);\n keys.push(key);\n }\n }\n return keys;\n }\n // 3.1.7.1 OrdinaryOwnMetadataKeys(O, P)\n // https://rbuckton.github.io/reflect-metadata/#ordinaryownmetadatakeys\n function OrdinaryOwnMetadataKeys(O, P) {\n var keys = [];\n var metadataMap = GetOrCreateMetadataMap(O, P, /*Create*/ false);\n if (IsUndefined(metadataMap))\n return keys;\n var keysObj = metadataMap.keys();\n var iterator = GetIterator(keysObj);\n var k = 0;\n while (true) {\n var next = IteratorStep(iterator);\n if (!next) {\n keys.length = k;\n return keys;\n }\n var nextValue = IteratorValue(next);\n try {\n keys[k] = nextValue;\n }\n catch (e) {\n try {\n IteratorClose(iterator);\n }\n finally {\n throw e;\n }\n }\n k++;\n }\n }\n // 6 ECMAScript Data Typ0es and Values\n // https://tc39.github.io/ecma262/#sec-ecmascript-data-types-and-values\n function Type(x) {\n if (x === null)\n return 1 /* Null */;\n switch (typeof x) {\n case \"undefined\": return 0 /* Undefined */;\n case \"boolean\": return 2 /* Boolean */;\n case \"string\": return 3 /* String */;\n case \"symbol\": return 4 /* Symbol */;\n case \"number\": return 5 /* Number */;\n case \"object\": return x === null ? 1 /* Null */ : 6 /* Object */;\n default: return 6 /* Object */;\n }\n }\n // 6.1.1 The Undefined Type\n // https://tc39.github.io/ecma262/#sec-ecmascript-language-types-undefined-type\n function IsUndefined(x) {\n return x === undefined;\n }\n // 6.1.2 The Null Type\n // https://tc39.github.io/ecma262/#sec-ecmascript-language-types-null-type\n function IsNull(x) {\n return x === null;\n }\n // 6.1.5 The Symbol Type\n // https://tc39.github.io/ecma262/#sec-ecmascript-language-types-symbol-type\n function IsSymbol(x) {\n return typeof x === \"symbol\";\n }\n // 6.1.7 The Object Type\n // https://tc39.github.io/ecma262/#sec-object-type\n function IsObject(x) {\n return typeof x === \"object\" ? x !== null : typeof x === \"function\";\n }\n // 7.1 Type Conversion\n // https://tc39.github.io/ecma262/#sec-type-conversion\n // 7.1.1 ToPrimitive(input [, PreferredType])\n // https://tc39.github.io/ecma262/#sec-toprimitive\n function ToPrimitive(input, PreferredType) {\n switch (Type(input)) {\n case 0 /* Undefined */: return input;\n case 1 /* Null */: return input;\n case 2 /* Boolean */: return input;\n case 3 /* String */: return input;\n case 4 /* Symbol */: return input;\n case 5 /* Number */: return input;\n }\n var hint = PreferredType === 3 /* String */ ? \"string\" : PreferredType === 5 /* Number */ ? \"number\" : \"default\";\n var exoticToPrim = GetMethod(input, toPrimitiveSymbol);\n if (exoticToPrim !== undefined) {\n var result = exoticToPrim.call(input, hint);\n if (IsObject(result))\n throw new TypeError();\n return result;\n }\n return OrdinaryToPrimitive(input, hint === \"default\" ? \"number\" : hint);\n }\n // 7.1.1.1 OrdinaryToPrimitive(O, hint)\n // https://tc39.github.io/ecma262/#sec-ordinarytoprimitive\n function OrdinaryToPrimitive(O, hint) {\n if (hint === \"string\") {\n var toString_1 = O.toString;\n if (IsCallable(toString_1)) {\n var result = toString_1.call(O);\n if (!IsObject(result))\n return result;\n }\n var valueOf = O.valueOf;\n if (IsCallable(valueOf)) {\n var result = valueOf.call(O);\n if (!IsObject(result))\n return result;\n }\n }\n else {\n var valueOf = O.valueOf;\n if (IsCallable(valueOf)) {\n var result = valueOf.call(O);\n if (!IsObject(result))\n return result;\n }\n var toString_2 = O.toString;\n if (IsCallable(toString_2)) {\n var result = toString_2.call(O);\n if (!IsObject(result))\n return result;\n }\n }\n throw new TypeError();\n }\n // 7.1.2 ToBoolean(argument)\n // https://tc39.github.io/ecma262/2016/#sec-toboolean\n function ToBoolean(argument) {\n return !!argument;\n }\n // 7.1.12 ToString(argument)\n // https://tc39.github.io/ecma262/#sec-tostring\n function ToString(argument) {\n return \"\" + argument;\n }\n // 7.1.14 ToPropertyKey(argument)\n // https://tc39.github.io/ecma262/#sec-topropertykey\n function ToPropertyKey(argument) {\n var key = ToPrimitive(argument, 3 /* String */);\n if (IsSymbol(key))\n return key;\n return ToString(key);\n }\n // 7.2 Testing and Comparison Operations\n // https://tc39.github.io/ecma262/#sec-testing-and-comparison-operations\n // 7.2.2 IsArray(argument)\n // https://tc39.github.io/ecma262/#sec-isarray\n function IsArray(argument) {\n return Array.isArray\n ? Array.isArray(argument)\n : argument instanceof Object\n ? argument instanceof Array\n : Object.prototype.toString.call(argument) === \"[object Array]\";\n }\n // 7.2.3 IsCallable(argument)\n // https://tc39.github.io/ecma262/#sec-iscallable\n function IsCallable(argument) {\n // NOTE: This is an approximation as we cannot check for [[Call]] internal method.\n return typeof argument === \"function\";\n }\n // 7.2.4 IsConstructor(argument)\n // https://tc39.github.io/ecma262/#sec-isconstructor\n function IsConstructor(argument) {\n // NOTE: This is an approximation as we cannot check for [[Construct]] internal method.\n return typeof argument === \"function\";\n }\n // 7.2.7 IsPropertyKey(argument)\n // https://tc39.github.io/ecma262/#sec-ispropertykey\n function IsPropertyKey(argument) {\n switch (Type(argument)) {\n case 3 /* String */: return true;\n case 4 /* Symbol */: return true;\n default: return false;\n }\n }\n // 7.3 Operations on Objects\n // https://tc39.github.io/ecma262/#sec-operations-on-objects\n // 7.3.9 GetMethod(V, P)\n // https://tc39.github.io/ecma262/#sec-getmethod\n function GetMethod(V, P) {\n var func = V[P];\n if (func === undefined || func === null)\n return undefined;\n if (!IsCallable(func))\n throw new TypeError();\n return func;\n }\n // 7.4 Operations on Iterator Objects\n // https://tc39.github.io/ecma262/#sec-operations-on-iterator-objects\n function GetIterator(obj) {\n var method = GetMethod(obj, iteratorSymbol);\n if (!IsCallable(method))\n throw new TypeError(); // from Call\n var iterator = method.call(obj);\n if (!IsObject(iterator))\n throw new TypeError();\n return iterator;\n }\n // 7.4.4 IteratorValue(iterResult)\n // https://tc39.github.io/ecma262/2016/#sec-iteratorvalue\n function IteratorValue(iterResult) {\n return iterResult.value;\n }\n // 7.4.5 IteratorStep(iterator)\n // https://tc39.github.io/ecma262/#sec-iteratorstep\n function IteratorStep(iterator) {\n var result = iterator.next();\n return result.done ? false : result;\n }\n // 7.4.6 IteratorClose(iterator, completion)\n // https://tc39.github.io/ecma262/#sec-iteratorclose\n function IteratorClose(iterator) {\n var f = iterator[\"return\"];\n if (f)\n f.call(iterator);\n }\n // 9.1 Ordinary Object Internal Methods and Internal Slots\n // https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots\n // 9.1.1.1 OrdinaryGetPrototypeOf(O)\n // https://tc39.github.io/ecma262/#sec-ordinarygetprototypeof\n function OrdinaryGetPrototypeOf(O) {\n var proto = Object.getPrototypeOf(O);\n if (typeof O !== \"function\" || O === functionPrototype)\n return proto;\n // TypeScript doesn't set __proto__ in ES5, as it's non-standard.\n // Try to determine the superclass constructor. Compatible implementations\n // must either set __proto__ on a subclass constructor to the superclass constructor,\n // or ensure each class has a valid `constructor` property on its prototype that\n // points back to the constructor.\n // If this is not the same as Function.[[Prototype]], then this is definately inherited.\n // This is the case when in ES6 or when using __proto__ in a compatible browser.\n if (proto !== functionPrototype)\n return proto;\n // If the super prototype is Object.prototype, null, or undefined, then we cannot determine the heritage.\n var prototype = O.prototype;\n var prototypeProto = prototype && Object.getPrototypeOf(prototype);\n if (prototypeProto == null || prototypeProto === Object.prototype)\n return proto;\n // If the constructor was not a function, then we cannot determine the heritage.\n var constructor = prototypeProto.constructor;\n if (typeof constructor !== \"function\")\n return proto;\n // If we have some kind of self-reference, then we cannot determine the heritage.\n if (constructor === O)\n return proto;\n // we have a pretty good guess at the heritage.\n return constructor;\n }\n // naive Map shim\n function CreateMapPolyfill() {\n var cacheSentinel = {};\n var arraySentinel = [];\n var MapIterator = /** @class */ (function () {\n function MapIterator(keys, values, selector) {\n this._index = 0;\n this._keys = keys;\n this._values = values;\n this._selector = selector;\n }\n MapIterator.prototype[\"@@iterator\"] = function () { return this; };\n MapIterator.prototype[iteratorSymbol] = function () { return this; };\n MapIterator.prototype.next = function () {\n var index = this._index;\n if (index >= 0 && index < this._keys.length) {\n var result = this._selector(this._keys[index], this._values[index]);\n if (index + 1 >= this._keys.length) {\n this._index = -1;\n this._keys = arraySentinel;\n this._values = arraySentinel;\n }\n else {\n this._index++;\n }\n return { value: result, done: false };\n }\n return { value: undefined, done: true };\n };\n MapIterator.prototype.throw = function (error) {\n if (this._index >= 0) {\n this._index = -1;\n this._keys = arraySentinel;\n this._values = arraySentinel;\n }\n throw error;\n };\n MapIterator.prototype.return = function (value) {\n if (this._index >= 0) {\n this._index = -1;\n this._keys = arraySentinel;\n this._values = arraySentinel;\n }\n return { value: value, done: true };\n };\n return MapIterator;\n }());\n return /** @class */ (function () {\n function Map() {\n this._keys = [];\n this._values = [];\n this._cacheKey = cacheSentinel;\n this._cacheIndex = -2;\n }\n Object.defineProperty(Map.prototype, \"size\", {\n get: function () { return this._keys.length; },\n enumerable: true,\n configurable: true\n });\n Map.prototype.has = function (key) { return this._find(key, /*insert*/ false) >= 0; };\n Map.prototype.get = function (key) {\n var index = this._find(key, /*insert*/ false);\n return index >= 0 ? this._values[index] : undefined;\n };\n Map.prototype.set = function (key, value) {\n var index = this._find(key, /*insert*/ true);\n this._values[index] = value;\n return this;\n };\n Map.prototype.delete = function (key) {\n var index = this._find(key, /*insert*/ false);\n if (index >= 0) {\n var size = this._keys.length;\n for (var i = index + 1; i < size; i++) {\n this._keys[i - 1] = this._keys[i];\n this._values[i - 1] = this._values[i];\n }\n this._keys.length--;\n this._values.length--;\n if (key === this._cacheKey) {\n this._cacheKey = cacheSentinel;\n this._cacheIndex = -2;\n }\n return true;\n }\n return false;\n };\n Map.prototype.clear = function () {\n this._keys.length = 0;\n this._values.length = 0;\n this._cacheKey = cacheSentinel;\n this._cacheIndex = -2;\n };\n Map.prototype.keys = function () { return new MapIterator(this._keys, this._values, getKey); };\n Map.prototype.values = function () { return new MapIterator(this._keys, this._values, getValue); };\n Map.prototype.entries = function () { return new MapIterator(this._keys, this._values, getEntry); };\n Map.prototype[\"@@iterator\"] = function () { return this.entries(); };\n Map.prototype[iteratorSymbol] = function () { return this.entries(); };\n Map.prototype._find = function (key, insert) {\n if (this._cacheKey !== key) {\n this._cacheIndex = this._keys.indexOf(this._cacheKey = key);\n }\n if (this._cacheIndex < 0 && insert) {\n this._cacheIndex = this._keys.length;\n this._keys.push(key);\n this._values.push(undefined);\n }\n return this._cacheIndex;\n };\n return Map;\n }());\n function getKey(key, _) {\n return key;\n }\n function getValue(_, value) {\n return value;\n }\n function getEntry(key, value) {\n return [key, value];\n }\n }\n // naive Set shim\n function CreateSetPolyfill() {\n return /** @class */ (function () {\n function Set() {\n this._map = new _Map();\n }\n Object.defineProperty(Set.prototype, \"size\", {\n get: function () { return this._map.size; },\n enumerable: true,\n configurable: true\n });\n Set.prototype.has = function (value) { return this._map.has(value); };\n Set.prototype.add = function (value) { return this._map.set(value, value), this; };\n Set.prototype.delete = function (value) { return this._map.delete(value); };\n Set.prototype.clear = function () { this._map.clear(); };\n Set.prototype.keys = function () { return this._map.keys(); };\n Set.prototype.values = function () { return this._map.values(); };\n Set.prototype.entries = function () { return this._map.entries(); };\n Set.prototype[\"@@iterator\"] = function () { return this.keys(); };\n Set.prototype[iteratorSymbol] = function () { return this.keys(); };\n return Set;\n }());\n }\n // naive WeakMap shim\n function CreateWeakMapPolyfill() {\n var UUID_SIZE = 16;\n var keys = HashMap.create();\n var rootKey = CreateUniqueKey();\n return /** @class */ (function () {\n function WeakMap() {\n this._key = CreateUniqueKey();\n }\n WeakMap.prototype.has = function (target) {\n var table = GetOrCreateWeakMapTable(target, /*create*/ false);\n return table !== undefined ? HashMap.has(table, this._key) : false;\n };\n WeakMap.prototype.get = function (target) {\n var table = GetOrCreateWeakMapTable(target, /*create*/ false);\n return table !== undefined ? HashMap.get(table, this._key) : undefined;\n };\n WeakMap.prototype.set = function (target, value) {\n var table = GetOrCreateWeakMapTable(target, /*create*/ true);\n table[this._key] = value;\n return this;\n };\n WeakMap.prototype.delete = function (target) {\n var table = GetOrCreateWeakMapTable(target, /*create*/ false);\n return table !== undefined ? delete table[this._key] : false;\n };\n WeakMap.prototype.clear = function () {\n // NOTE: not a real clear, just makes the previous data unreachable\n this._key = CreateUniqueKey();\n };\n return WeakMap;\n }());\n function CreateUniqueKey() {\n var key;\n do\n key = \"@@WeakMap@@\" + CreateUUID();\n while (HashMap.has(keys, key));\n keys[key] = true;\n return key;\n }\n function GetOrCreateWeakMapTable(target, create) {\n if (!hasOwn.call(target, rootKey)) {\n if (!create)\n return undefined;\n Object.defineProperty(target, rootKey, { value: HashMap.create() });\n }\n return target[rootKey];\n }\n function FillRandomBytes(buffer, size) {\n for (var i = 0; i < size; ++i)\n buffer[i] = Math.random() * 0xff | 0;\n return buffer;\n }\n function GenRandomBytes(size) {\n if (typeof Uint8Array === \"function\") {\n if (typeof crypto !== \"undefined\")\n return crypto.getRandomValues(new Uint8Array(size));\n if (typeof msCrypto !== \"undefined\")\n return msCrypto.getRandomValues(new Uint8Array(size));\n return FillRandomBytes(new Uint8Array(size), size);\n }\n return FillRandomBytes(new Array(size), size);\n }\n function CreateUUID() {\n var data = GenRandomBytes(UUID_SIZE);\n // mark as random - RFC 4122 § 4.4\n data[6] = data[6] & 0x4f | 0x40;\n data[8] = data[8] & 0xbf | 0x80;\n var result = \"\";\n for (var offset = 0; offset < UUID_SIZE; ++offset) {\n var byte = data[offset];\n if (offset === 4 || offset === 6 || offset === 8)\n result += \"-\";\n if (byte < 16)\n result += \"0\";\n result += byte.toString(16).toLowerCase();\n }\n return result;\n }\n }\n // uses a heuristic used by v8 and chakra to force an object into dictionary mode.\n function MakeDictionary(obj) {\n obj.__ = undefined;\n delete obj.__;\n return obj;\n }\n });\n})(Reflect || (Reflect = {}));\n","import 'reflect-metadata';\nimport { ClassType } from './interface';\n\nexport const FIELD_KEY = Symbol('aiem_field');\n\n\n\nexport interface ReadParams {\n foo?: string\n}\n\n\nexport type ContractParams<T extends any = any, K extends keyof T = keyof T> = K\n\n\n\nexport class Fields {\n static read(options: ReadParams = {}) {\n return function (target: any, propertyKey: any, descriptor?: PropertyDescriptor) {\n Reflect.defineMetadata(FIELD_KEY, { type: 'read', options }, target, propertyKey);\n };\n }\n\n static custom(options: ReadParams = {}) {\n return function (target: any, propertyKey: any, descriptor?: PropertyDescriptor) {\n Reflect.defineMetadata(FIELD_KEY, { type: 'custom', options }, target, propertyKey);\n };\n }\n\n static contract<T = any, R = any>(entity: () => ClassType<R>, options: ContractParams<T>) {\n return function (target: any, propertyKey: any, descriptor?: PropertyDescriptor) {\n Reflect.defineMetadata(FIELD_KEY, { type: 'contract', entity, targetKey: options }, target, propertyKey);\n };\n }\n}\n\nexport function getFieldMetadata(target: any, propertyKey: string) {\n return Reflect.getMetadata(FIELD_KEY, target, propertyKey);\n}"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dappworks/kit",
3
- "version": "0.4.105",
3
+ "version": "0.4.107",
4
4
  "description": "",
5
5
  "main": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.mts",