@fleet-sdk/common 0.2.3 → 0.3.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/CHANGELOG.md +7 -0
- package/dist/index.cjs.js +47 -5
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.mts +373 -31
- package/dist/index.d.ts +373 -31
- package/dist/index.esm.js +45 -6
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
@@ -22,13 +22,13 @@ declare const ergoTreeHeaderFlags: {
|
|
22
22
|
};
|
23
23
|
type ErgoTreeHeaderFlag = (typeof ergoTreeHeaderFlags)[keyof typeof ergoTreeHeaderFlags];
|
24
24
|
|
25
|
-
type NonMandatoryRegisters = {
|
26
|
-
R4?:
|
27
|
-
R5?:
|
28
|
-
R6?:
|
29
|
-
R7?:
|
30
|
-
R8?:
|
31
|
-
R9?:
|
25
|
+
type NonMandatoryRegisters<T = HexString> = {
|
26
|
+
R4?: T;
|
27
|
+
R5?: T;
|
28
|
+
R6?: T;
|
29
|
+
R7?: T;
|
30
|
+
R8?: T;
|
31
|
+
R9?: T;
|
32
32
|
};
|
33
33
|
|
34
34
|
type TokenId = string;
|
@@ -49,15 +49,13 @@ type TokenTargetAmount<AmountType> = {
|
|
49
49
|
amount?: AmountType;
|
50
50
|
};
|
51
51
|
|
52
|
-
type ContextExtension = {
|
53
|
-
[key: number]:
|
52
|
+
type ContextExtension<T = HexString> = {
|
53
|
+
[key: number]: T | undefined;
|
54
54
|
};
|
55
|
-
|
56
55
|
type ProverResult = {
|
57
56
|
readonly proofBytes: HexString;
|
58
57
|
readonly extension: ContextExtension;
|
59
58
|
};
|
60
|
-
|
61
59
|
type SignedInput = {
|
62
60
|
readonly boxId: BoxId;
|
63
61
|
readonly spendingProof: ProverResult;
|
@@ -106,22 +104,21 @@ type SignedTransaction = {
|
|
106
104
|
readonly id: TransactionId;
|
107
105
|
readonly inputs: SignedInput[];
|
108
106
|
readonly dataInputs: DataInput[];
|
109
|
-
readonly outputs: Box<
|
107
|
+
readonly outputs: Box<string>[];
|
110
108
|
};
|
111
109
|
|
112
110
|
type BoxId = string;
|
113
|
-
type
|
114
|
-
type BoxBaseType<T extends AmountType, R extends NonMandatoryRegisters> = {
|
111
|
+
type BoxBaseType<T extends Amount, R extends NonMandatoryRegisters> = {
|
115
112
|
ergoTree: ErgoTreeHex;
|
116
113
|
creationHeight: number;
|
117
114
|
value: T;
|
118
115
|
assets: TokenAmount<T>[];
|
119
116
|
additionalRegisters: R;
|
120
117
|
};
|
121
|
-
type BoxCandidate<T extends
|
118
|
+
type BoxCandidate<T extends Amount, R extends NonMandatoryRegisters = NonMandatoryRegisters> = BoxBaseType<T, R> & {
|
122
119
|
boxId?: BoxId;
|
123
120
|
};
|
124
|
-
type Box<T extends
|
121
|
+
type Box<T extends Amount = Amount, R extends NonMandatoryRegisters = NonMandatoryRegisters> = BoxBaseType<T, R> & {
|
125
122
|
boxId: BoxId;
|
126
123
|
transactionId: TransactionId;
|
127
124
|
index: number;
|
@@ -152,10 +149,10 @@ type BlockHeader = {
|
|
152
149
|
difficulty: string;
|
153
150
|
parentId: BlockHeaderId;
|
154
151
|
votes: string;
|
155
|
-
size
|
156
|
-
extensionId
|
157
|
-
transactionsId
|
158
|
-
adProofsId
|
152
|
+
size?: number;
|
153
|
+
extensionId?: HexString;
|
154
|
+
transactionsId?: HexString;
|
155
|
+
adProofsId?: HexString;
|
159
156
|
};
|
160
157
|
type Block = {
|
161
158
|
header: BlockHeader;
|
@@ -166,10 +163,25 @@ type Block = {
|
|
166
163
|
};
|
167
164
|
|
168
165
|
type ObjectSelector<T> = (item: T) => T[keyof T];
|
166
|
+
/**
|
167
|
+
* Returns the first element of an array.
|
168
|
+
* @param array
|
169
|
+
* @throws an error if the array is empty.
|
170
|
+
*/
|
169
171
|
declare function first(array: undefined): undefined;
|
170
172
|
declare function first<T>(array: ArrayLike<T>): T;
|
173
|
+
/**
|
174
|
+
* Returns the last element of an array.
|
175
|
+
* @param array
|
176
|
+
* @throws an error if the array is empty.
|
177
|
+
*/
|
171
178
|
declare function last(array: undefined): undefined;
|
172
179
|
declare function last<T>(array: ArrayLike<T>): T;
|
180
|
+
/**
|
181
|
+
* Returns the element at the specified index. Negative indices are counted from the end of the array.
|
182
|
+
* @param array
|
183
|
+
* @param index
|
184
|
+
*/
|
173
185
|
declare function at(array: undefined, index: number): undefined;
|
174
186
|
declare function at<T>(array: ArrayLike<T>, index: number): T;
|
175
187
|
/**
|
@@ -180,14 +192,140 @@ declare function hasDuplicates<T>(array: T[]): boolean;
|
|
180
192
|
* Check for duplicate keys in complex elements
|
181
193
|
*/
|
182
194
|
declare function hasDuplicatesBy<T>(array: T[], selector: ObjectSelector<T>): boolean;
|
195
|
+
/**
|
196
|
+
* Turns an array into chunks of the specified size
|
197
|
+
* @param array
|
198
|
+
* @param size
|
199
|
+
*
|
200
|
+
* @example
|
201
|
+
* ```
|
202
|
+
* const array = [1, 2, 3, 4, 5];
|
203
|
+
* const chunks = chunk(array, 2);
|
204
|
+
* console.log(chunks);
|
205
|
+
* // [[1, 2], [3, 4], [5]]
|
206
|
+
* ```
|
207
|
+
*/
|
183
208
|
declare function chunk<T>(array: T[], size: number): T[][];
|
209
|
+
/**
|
210
|
+
* Sorts an array of objects by the specified property
|
211
|
+
* @param array
|
212
|
+
* @param iteratee
|
213
|
+
* @param order
|
214
|
+
*
|
215
|
+
* @example
|
216
|
+
* ```
|
217
|
+
* const array = [{ name: "John", age: 25 }, { name: "Jane", age: 30 }];
|
218
|
+
* const sorted = orderBy(array, (item) => item.age, "desc");
|
219
|
+
* console.log(sorted);
|
220
|
+
* // [{ name: "Jane", age: 30 }, { name: "John", age: 25 }]
|
221
|
+
* ```
|
222
|
+
*/
|
184
223
|
declare function orderBy<T>(array: T[], iteratee: SortingSelector<T>, order?: SortingDirection): T[];
|
224
|
+
/**
|
225
|
+
* Checks if arrays are equal
|
226
|
+
* @param array1
|
227
|
+
* @param array2
|
228
|
+
*
|
229
|
+
* @example
|
230
|
+
* ```
|
231
|
+
* const array1 = [1, 2, 3];
|
232
|
+
* const array2 = [1, 2, 3];
|
233
|
+
* const array3 = [1, 2, 4];
|
234
|
+
* const array4 = [1, 2, 3, 4];
|
235
|
+
* areEqual(array1, array2); // true
|
236
|
+
* areEqual(array1, array3); // false
|
237
|
+
* areEqual(array1, array4); // false
|
238
|
+
* ```
|
239
|
+
*/
|
185
240
|
declare function areEqual<T>(array1: ArrayLike<T>, array2: ArrayLike<T>): boolean;
|
241
|
+
/**
|
242
|
+
* Checks if arrays are equal by the specified property
|
243
|
+
* @param array1
|
244
|
+
* @param array2
|
245
|
+
* @param selector
|
246
|
+
*
|
247
|
+
* @example
|
248
|
+
* ```
|
249
|
+
* const array1 = [{ name: "John", age: 25 }, { name: "Jane", age: 30 }];
|
250
|
+
* const array2 = [{ name: "John", age: 25 }, { name: "Jane", age: 30 }];
|
251
|
+
* const array3 = [{ name: "John", age: 25 }, { name: "Jane", age: 31 }];
|
252
|
+
*
|
253
|
+
* areEqualBy(array1, array2, (item) => item.age); // true
|
254
|
+
* areEqualBy(array1, array3, (item) => item.age); // false
|
255
|
+
* ```
|
256
|
+
*/
|
186
257
|
declare function areEqualBy<T>(array1: ArrayLike<T>, array2: ArrayLike<T>, selector: ObjectSelector<T>): boolean;
|
258
|
+
/**
|
259
|
+
* Checks if the array starts with the specified target
|
260
|
+
* @param array
|
261
|
+
* @param target
|
262
|
+
*
|
263
|
+
* @example
|
264
|
+
* ```
|
265
|
+
* const array = [1, 2, 3, 4, 5];
|
266
|
+
* const target1 = [1, 2];
|
267
|
+
* const target2 = [1, 3];
|
268
|
+
*
|
269
|
+
* startsWith(array, target1); // true
|
270
|
+
* startsWith(array, target2); // false
|
271
|
+
* ```
|
272
|
+
*/
|
187
273
|
declare function startsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean;
|
274
|
+
/**
|
275
|
+
* Checks if the array ends with the specified target
|
276
|
+
* @param array
|
277
|
+
* @param target
|
278
|
+
*
|
279
|
+
* @example
|
280
|
+
* ```
|
281
|
+
* const array = [1, 2, 3, 4, 5];
|
282
|
+
* const target1 = [4, 5];
|
283
|
+
* const target2 = [3, 5];
|
284
|
+
*
|
285
|
+
* endsWith(array, target1); // true
|
286
|
+
* endsWith(array, target2); // false
|
287
|
+
* ```
|
288
|
+
*/
|
188
289
|
declare function endsWith<T>(array: ArrayLike<T>, target: ArrayLike<T>): boolean;
|
290
|
+
/**
|
291
|
+
* Makes an array unique by removing duplicate elements
|
292
|
+
* @param array
|
293
|
+
*
|
294
|
+
* @example
|
295
|
+
* ```
|
296
|
+
* const array = [1, 2, 3, 3, 4, 5, 5];
|
297
|
+
* const unique = uniq(array);
|
298
|
+
* console.log(unique);
|
299
|
+
* // [1, 2, 3, 4, 5]
|
300
|
+
* ```
|
301
|
+
*/
|
189
302
|
declare function uniq<T>(array: Array<T>): Array<T>;
|
303
|
+
/**
|
304
|
+
* Makes an array unique by removing duplicate elements using the specified property
|
305
|
+
* @param array
|
306
|
+
* @param selector
|
307
|
+
* @param selection
|
308
|
+
*
|
309
|
+
* @example
|
310
|
+
* ```
|
311
|
+
* const array = [{ name: "John", age: 25 }, { name: "Jane", age: 30 }, { name: "John", age: 30 }];
|
312
|
+
* const unique = uniqBy(array, (item) => item.name);
|
313
|
+
* console.log(unique);
|
314
|
+
* // [{ name: "John", age: 25 }, { name: "Jane", age: 30 }]
|
315
|
+
* ```
|
316
|
+
*/
|
190
317
|
declare function uniqBy<T>(array: Array<T>, selector: ObjectSelector<T>, selection?: "keep-first" | "keep-last"): Array<T>;
|
318
|
+
/**
|
319
|
+
* Returns the depth of an array
|
320
|
+
* @param array
|
321
|
+
*
|
322
|
+
* @example
|
323
|
+
* ```
|
324
|
+
* const array = [1, 2, 3, [4, 5, [6, 7]]];
|
325
|
+
* const depth = depthOf(array);
|
326
|
+
* console.log(depth);
|
327
|
+
* // 3
|
328
|
+
*/
|
191
329
|
declare function depthOf(array: unknown | unknown[]): number;
|
192
330
|
|
193
331
|
type NumberLike = string | number | bigint | boolean;
|
@@ -198,6 +336,10 @@ declare const _10n: bigint;
|
|
198
336
|
declare const _63n: bigint;
|
199
337
|
declare const _127n: bigint;
|
200
338
|
declare const _128n: bigint;
|
339
|
+
/**
|
340
|
+
* Ensure that the given value is a bigint
|
341
|
+
* @param number
|
342
|
+
*/
|
201
343
|
declare function ensureBigInt(number: NumberLike): bigint;
|
202
344
|
type ParsingOptions = {
|
203
345
|
/**
|
@@ -210,6 +352,16 @@ type ParsingOptions = {
|
|
210
352
|
*/
|
211
353
|
decimalMark?: string;
|
212
354
|
};
|
355
|
+
/**
|
356
|
+
* Parse a decimal string into a bigint with options
|
357
|
+
* @param decimalStr
|
358
|
+
* @param options
|
359
|
+
*
|
360
|
+
* @example
|
361
|
+
* undecimalize("129.8379183", { decimals: 9 }) // 129837918300n
|
362
|
+
* undecimalize("1", { decimals: 2 }) // 100n
|
363
|
+
* undecimalize("1", 2) // 100n
|
364
|
+
*/
|
213
365
|
declare function undecimalize(decimalStr: string, options?: ParsingOptions | number): bigint;
|
214
366
|
type FormattingOptions = {
|
215
367
|
/**
|
@@ -226,21 +378,135 @@ type FormattingOptions = {
|
|
226
378
|
*/
|
227
379
|
decimalMark?: string;
|
228
380
|
};
|
381
|
+
/**
|
382
|
+
* Format a bigint into a decimal string with options
|
383
|
+
* @param value
|
384
|
+
* @param options
|
385
|
+
*
|
386
|
+
* @example
|
387
|
+
* decimalize(129837918300n, { decimals: 9 }) // "129.8379183"
|
388
|
+
* decimalize(100n, { decimals: 2 }) // "1"
|
389
|
+
*/
|
229
390
|
declare function decimalize(value: Amount, options?: FormattingOptions | number): string;
|
391
|
+
/**
|
392
|
+
* Format a bigint percentage into a decimal string with options
|
393
|
+
* @param value
|
394
|
+
* @param percentage
|
395
|
+
* @param precision
|
396
|
+
*
|
397
|
+
* @example
|
398
|
+
* ```
|
399
|
+
* percent(3498n, 1n) // 34n(1%)
|
400
|
+
* percent(3498n, 2n) // 69n(2%)
|
401
|
+
* percent(3498n, 10n) // 349n(10%)
|
402
|
+
* ```
|
403
|
+
*
|
404
|
+
*/
|
230
405
|
declare function percent(value: bigint, percentage: bigint, precision?: bigint): bigint;
|
406
|
+
/**
|
407
|
+
* Sum a collection of numbers by a given iteratee
|
408
|
+
* @param collection
|
409
|
+
* @param iteratee
|
410
|
+
* @param condition
|
411
|
+
*
|
412
|
+
* @example
|
413
|
+
* ```
|
414
|
+
* const values = [
|
415
|
+
* { key: 1, value: 100n },
|
416
|
+
* { key: 2, value: 200n },
|
417
|
+
* { key: 3, value: 300n },
|
418
|
+
* { key: 4, value: 400n },
|
419
|
+
* ];
|
420
|
+
*
|
421
|
+
* sumBy(values, x => x.value) // 1000n
|
422
|
+
* sumBy(values, x => x.value, x => x.key < 0) // 0n
|
423
|
+
* sumBy(values, x => x.value, x => x.key % 2 === 0) // 600n
|
424
|
+
*/
|
231
425
|
declare function sumBy<T>(collection: readonly T[], iteratee: (value: T) => bigint, condition?: (value: T) => boolean): bigint;
|
426
|
+
/**
|
427
|
+
* Get the minimum value from a collection of numbers
|
428
|
+
* @param numbers
|
429
|
+
*/
|
232
430
|
declare function min<T extends bigint | number>(...numbers: T[]): T;
|
431
|
+
/**
|
432
|
+
* Get the maximum value from a collection of numbers
|
433
|
+
* @param numbers
|
434
|
+
*/
|
233
435
|
declare function max<T extends bigint | number>(...numbers: T[]): T;
|
234
436
|
|
235
|
-
|
236
|
-
|
437
|
+
/**
|
438
|
+
* Calculates the sum of all nanoErgs and tokens in the given boxes.
|
439
|
+
* @param boxes
|
440
|
+
*
|
441
|
+
* @example
|
442
|
+
* ```
|
443
|
+
* const boxes = [
|
444
|
+
* { value: "10", assets: [{ tokenId: "test", amount: "20" }] },
|
445
|
+
* { value: 20n, assets: [{ tokenId: "test", amount: 30n }] }
|
446
|
+
* ];
|
447
|
+
*
|
448
|
+
* const sum = utxoSum(boxes);
|
449
|
+
* console.log(sum);
|
450
|
+
* // { nanoErgs: 30n, tokens: [{ tokenId: "test", amount: 50n }] }
|
451
|
+
* ```
|
452
|
+
*/
|
453
|
+
declare function utxoSum(boxes: MinimalBoxAmountsArray): BoxSummary;
|
454
|
+
declare function utxoSum(boxes: MinimalBoxAmountsArray, tokenId: TokenId): bigint;
|
455
|
+
/**
|
456
|
+
* Calculates the difference between two utxos or utxo sets.
|
457
|
+
* @param minuend
|
458
|
+
* @param subtrahend
|
459
|
+
*
|
460
|
+
* @example
|
461
|
+
* ```
|
462
|
+
* const minuend = [{ nanoErgs: 30n, tokens: [{ tokenId: "test", amount: 50n }] }];
|
463
|
+
* const subtrahend = [{ nanoErgs: 10n, tokens: [{ tokenId: "test", amount: 20n }] }];
|
464
|
+
* const diff = utxoDiff(minuend, subtrahend);
|
465
|
+
* console.log(diff);
|
466
|
+
* // { nanoErgs: 20n, tokens: [{ tokenId: "test", amount: 30n }] }
|
467
|
+
* ```
|
468
|
+
*/
|
237
469
|
declare function utxoDiff(minuend: BoxSummary | Box<Amount>[], subtrahend: BoxSummary | Box<Amount>[]): BoxSummary;
|
470
|
+
/**
|
471
|
+
* Checks if the given registers are densely packed.
|
472
|
+
* @param registers
|
473
|
+
*
|
474
|
+
* @example
|
475
|
+
* ```
|
476
|
+
* const registers = {
|
477
|
+
* R4: "deadbeef",
|
478
|
+
* R6: "cafe",
|
479
|
+
* };
|
480
|
+
* const result = areRegistersDenselyPacked(registers);
|
481
|
+
* console.log(result);
|
482
|
+
* // false
|
483
|
+
*/
|
238
484
|
declare function areRegistersDenselyPacked(registers: NonMandatoryRegisters): boolean;
|
239
|
-
|
240
|
-
|
485
|
+
/**
|
486
|
+
* Filters the given utxos by the given filter parameters.
|
487
|
+
* @param utxos
|
488
|
+
* @param filterParams
|
489
|
+
*/
|
490
|
+
declare function utxoFilter<T extends Amount>(utxos: Box<T>[], filterParams: UTxOFilterParams<T>): Box<T>[];
|
491
|
+
/**
|
492
|
+
* Parameters for filtering unspent transaction outputs (UTxOs).
|
493
|
+
*/
|
494
|
+
type UTxOFilterParams<T extends Amount> = {
|
495
|
+
/**
|
496
|
+
* A function that returns a boolean indicating whether a given UTxO should be included in the filtered results.
|
497
|
+
*/
|
241
498
|
by?: (utxo: Box<T>) => boolean;
|
499
|
+
/**
|
500
|
+
* An object specifying the maximum number of UTxOs and distinct tokens to include in the filtered results.
|
501
|
+
*/
|
242
502
|
max?: {
|
503
|
+
/**
|
504
|
+
* The maximum number of UTxOs to include in the filtered results.
|
505
|
+
*/
|
243
506
|
count?: number;
|
507
|
+
/**
|
508
|
+
* The maximum number of distinct tokens to include in the filtered results.
|
509
|
+
*/
|
244
510
|
aggregatedDistinctTokens?: number;
|
245
511
|
};
|
246
512
|
};
|
@@ -248,15 +514,43 @@ type BoxSummary = {
|
|
248
514
|
nanoErgs: bigint;
|
249
515
|
tokens: TokenAmount<bigint>[];
|
250
516
|
};
|
251
|
-
type
|
517
|
+
type MinimalBoxAmountsArray = readonly {
|
252
518
|
value: Amount;
|
253
519
|
assets: TokenAmount<Amount>[];
|
254
520
|
}[];
|
521
|
+
/**
|
522
|
+
* Ensures that the value and asset amounts of a given box are represented as BigInts.
|
523
|
+
* @returns A new box object with BigInt representation for the value and asset amounts.
|
524
|
+
*/
|
255
525
|
declare function ensureUTxOBigInt(box: Box<Amount>): Box<bigint>;
|
256
526
|
declare function ensureUTxOBigInt(candidate: BoxCandidate<Amount>): BoxCandidate<bigint>;
|
257
527
|
|
528
|
+
/**
|
529
|
+
* Remove undefined values from an object
|
530
|
+
* @param value
|
531
|
+
*
|
532
|
+
* @example
|
533
|
+
* ```
|
534
|
+
* const obj = { a: 1, b: undefined };
|
535
|
+
* const result = clearUndefined(obj);
|
536
|
+
* console.log(result); // { a: 1 }
|
537
|
+
* ```
|
538
|
+
*/
|
258
539
|
declare function clearUndefined(value: Record<string, unknown>): Record<string, unknown>;
|
259
|
-
|
540
|
+
/**
|
541
|
+
* Ensure that the options object has all the default values
|
542
|
+
* @param options
|
543
|
+
* @param defaults
|
544
|
+
*
|
545
|
+
* @example
|
546
|
+
* ```
|
547
|
+
* const options = { a: 1 };
|
548
|
+
* const defaults = { a: 2, b: 3 };
|
549
|
+
* const result = ensureDefaults(options, defaults);
|
550
|
+
* console.log(result); // { a: 1, b: 3 }
|
551
|
+
* ```
|
552
|
+
*/
|
553
|
+
declare function ensureDefaults<T extends object, R extends object>(options: T | undefined, defaults: R): R & T;
|
260
554
|
|
261
555
|
type AssertErrorMessageInput = string | Error | (() => string);
|
262
556
|
type Constructable = Function;
|
@@ -264,10 +558,8 @@ type JSPrimitiveTypes = "string" | "number" | "bigint" | "boolean" | "symbol" |
|
|
264
558
|
declare function assert(condition: boolean, error: AssertErrorMessageInput): asserts condition;
|
265
559
|
declare function assertTypeOf<T>(obj: T, expected: JSPrimitiveTypes): asserts obj;
|
266
560
|
declare function assertInstanceOf<T>(obj: T, expected: Constructable): asserts obj;
|
267
|
-
declare function isEmpty<T
|
268
|
-
declare function
|
269
|
-
declare function some<T extends object>(obj?: T): obj is T;
|
270
|
-
declare function some<T>(array?: T[]): array is T[];
|
561
|
+
declare function isEmpty<T>(target: T | null | undefined): target is undefined | null;
|
562
|
+
declare function some<T>(target: T | null | undefined): target is T;
|
271
563
|
declare function isTruthy<T>(value?: T): value is NonNullable<T>;
|
272
564
|
declare function isFalsy<T>(value?: T): value is undefined;
|
273
565
|
declare function isUndefined(v: unknown): v is undefined;
|
@@ -286,21 +578,71 @@ declare function byteSizeOf(hex: string): number;
|
|
286
578
|
type CollectionAddOptions = {
|
287
579
|
index?: number;
|
288
580
|
};
|
581
|
+
/**
|
582
|
+
* Collection abstract model
|
583
|
+
*
|
584
|
+
* @example
|
585
|
+
* Define a new collection class with internal type `number` and external type `string`
|
586
|
+
* ```
|
587
|
+
* class TestCollection extends Collection<number, string> {
|
588
|
+
* protected _map(item: string | number): number {
|
589
|
+
* return Number(item);
|
590
|
+
* }
|
591
|
+
* // Some other methods
|
592
|
+
* }
|
593
|
+
* ```
|
594
|
+
*
|
595
|
+
*/
|
289
596
|
declare abstract class Collection<InternalType, ExternalType> implements Iterable<InternalType> {
|
290
597
|
protected readonly _items: InternalType[];
|
291
598
|
constructor();
|
292
599
|
protected _isIndexOutOfBounds(index: number): boolean;
|
293
600
|
[Symbol.iterator](): Iterator<InternalType>;
|
601
|
+
/**
|
602
|
+
* Number of items in the collection
|
603
|
+
*/
|
294
604
|
get length(): number;
|
605
|
+
/**
|
606
|
+
* True if the collection is empty
|
607
|
+
*/
|
295
608
|
get isEmpty(): boolean;
|
609
|
+
/**
|
610
|
+
* Get item at index
|
611
|
+
* @param index
|
612
|
+
* @throws RangeError if index is out of bounds
|
613
|
+
*/
|
296
614
|
at(index: number): InternalType;
|
615
|
+
/**
|
616
|
+
* Add item to the collection
|
617
|
+
* @param items
|
618
|
+
* @param options
|
619
|
+
* @returns The new length of the collection
|
620
|
+
*/
|
297
621
|
add(items: OneOrMore<ExternalType>, options?: CollectionAddOptions): number;
|
298
622
|
abstract remove(item: unknown): number;
|
623
|
+
/**
|
624
|
+
* Map external type to internal type
|
625
|
+
* @param item
|
626
|
+
* @protected
|
627
|
+
*/
|
299
628
|
protected abstract _map(item: ExternalType | InternalType): InternalType;
|
300
629
|
protected _addOne(item: InternalType | ExternalType, options?: CollectionAddOptions): number;
|
301
630
|
protected _addOneOrMore(items: OneOrMore<ExternalType>, options?: CollectionAddOptions): number;
|
631
|
+
/**
|
632
|
+
* Get the collection as an array
|
633
|
+
*/
|
302
634
|
toArray(): InternalType[];
|
303
635
|
reduce<U>(callbackFn: (accumulator: U, currentValue: InternalType, currentIndex: number, array: InternalType[]) => U, initialValue: U): U;
|
304
636
|
}
|
305
637
|
|
306
|
-
|
638
|
+
declare class FleetError extends Error {
|
639
|
+
constructor(message?: string, options?: ErrorOptions);
|
640
|
+
}
|
641
|
+
declare class NotSupportedError extends FleetError {
|
642
|
+
constructor(message?: string);
|
643
|
+
}
|
644
|
+
declare class BlockchainProviderError extends FleetError {
|
645
|
+
constructor(message?: string, options?: ErrorOptions);
|
646
|
+
}
|
647
|
+
|
648
|
+
export { AddressType, Amount, AssertErrorMessageInput, Base58String, Block, BlockHeader, BlockHeaderId, BlockTransactions, BlockchainProviderError, Box, BoxCandidate, BoxId, BoxSummary, BuildOutputType, Collection, CollectionAddOptions, ContextExtension, DataInput, EIP12UnsignedDataInput, EIP12UnsignedInput, EIP12UnsignedTransaction, ErgoTreeHeaderFlag, ErgoTreeHex, FilterPredicate, FleetError, HexString, MinimalBoxAmountsArray, Network, NewToken, NonMandatoryRegisters, NotSupportedError, OneOrMore, PoWSolution, ProverResult, SignedInput, SignedTransaction, SortingDirection, SortingSelector, TokenAmount, TokenId, TokenTargetAmount, TransactionId, UTxOFilterParams, UnsignedInput, UnsignedTransaction, _0n, _10n, _127n, _128n, _1n, _63n, _7n, areEqual, areEqualBy, areRegistersDenselyPacked, assert, assertInstanceOf, assertTypeOf, at, byteSizeOf, chunk, clearUndefined, concatBytes, decimalize, depthOf, endsWith, ensureBigInt, ensureDefaults, ensureUTxOBigInt, ergoTreeHeaderFlags, first, hasDuplicates, hasDuplicatesBy, hasKey, isDefined, isEmpty, isFalsy, isHex, isTruthy, isUndefined, last, max, min, orderBy, percent, some, startsWith, sumBy, undecimalize, uniq, uniqBy, utxoDiff, utxoFilter, utxoSum };
|
package/dist/index.esm.js
CHANGED
@@ -34,13 +34,13 @@ function assertInstanceOf(obj, expected) {
|
|
34
34
|
throw new Error(`Expected an instance of '${expected.name}', got '${getTypeName(obj)}'.`);
|
35
35
|
}
|
36
36
|
}
|
37
|
-
function isEmpty(
|
38
|
-
if (!
|
37
|
+
function isEmpty(target) {
|
38
|
+
if (!target)
|
39
39
|
return true;
|
40
|
-
return Array.isArray(
|
40
|
+
return Array.isArray(target) ? target.length === 0 : Object.keys(target).length === 0;
|
41
41
|
}
|
42
|
-
function some(
|
43
|
-
return !isEmpty(
|
42
|
+
function some(target) {
|
43
|
+
return !isEmpty(target);
|
44
44
|
}
|
45
45
|
function isTruthy(value) {
|
46
46
|
return !!value;
|
@@ -495,18 +495,35 @@ var Collection = class {
|
|
495
495
|
}
|
496
496
|
};
|
497
497
|
}
|
498
|
+
/**
|
499
|
+
* Number of items in the collection
|
500
|
+
*/
|
498
501
|
get length() {
|
499
502
|
return this._items.length;
|
500
503
|
}
|
504
|
+
/**
|
505
|
+
* True if the collection is empty
|
506
|
+
*/
|
501
507
|
get isEmpty() {
|
502
508
|
return this.length === 0;
|
503
509
|
}
|
510
|
+
/**
|
511
|
+
* Get item at index
|
512
|
+
* @param index
|
513
|
+
* @throws RangeError if index is out of bounds
|
514
|
+
*/
|
504
515
|
at(index) {
|
505
516
|
if (this._isIndexOutOfBounds(index)) {
|
506
517
|
throw new RangeError(`Index '${index}' is out of range.`);
|
507
518
|
}
|
508
519
|
return this._items[index];
|
509
520
|
}
|
521
|
+
/**
|
522
|
+
* Add item to the collection
|
523
|
+
* @param items
|
524
|
+
* @param options
|
525
|
+
* @returns The new length of the collection
|
526
|
+
*/
|
510
527
|
add(items, options) {
|
511
528
|
return this._addOneOrMore(items, options);
|
512
529
|
}
|
@@ -538,6 +555,9 @@ var Collection = class {
|
|
538
555
|
}
|
539
556
|
return this.length;
|
540
557
|
}
|
558
|
+
/**
|
559
|
+
* Get the collection as an array
|
560
|
+
*/
|
541
561
|
toArray() {
|
542
562
|
return [...this._items];
|
543
563
|
}
|
@@ -546,6 +566,25 @@ var Collection = class {
|
|
546
566
|
}
|
547
567
|
};
|
548
568
|
|
549
|
-
|
569
|
+
// src/error.ts
|
570
|
+
var FleetError = class extends Error {
|
571
|
+
constructor(message, options) {
|
572
|
+
super(message, options);
|
573
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
574
|
+
this.name = new.target.name;
|
575
|
+
}
|
576
|
+
};
|
577
|
+
var NotSupportedError = class extends FleetError {
|
578
|
+
constructor(message) {
|
579
|
+
super(message);
|
580
|
+
}
|
581
|
+
};
|
582
|
+
var BlockchainProviderError = class extends FleetError {
|
583
|
+
constructor(message, options) {
|
584
|
+
super(message, options);
|
585
|
+
}
|
586
|
+
};
|
587
|
+
|
588
|
+
export { AddressType, BlockchainProviderError, Collection, FleetError, Network, NotSupportedError, _0n, _10n, _127n, _128n, _1n, _63n, _7n, areEqual, areEqualBy, areRegistersDenselyPacked, assert, assertInstanceOf, assertTypeOf, at, byteSizeOf, chunk, clearUndefined, concatBytes, decimalize, depthOf, endsWith, ensureBigInt, ensureDefaults, ensureUTxOBigInt, ergoTreeHeaderFlags, first, hasDuplicates, hasDuplicatesBy, hasKey, isDefined, isEmpty, isFalsy, isHex, isTruthy, isUndefined, last, max, min, orderBy, percent, some, startsWith, sumBy, undecimalize, uniq, uniqBy, utxoDiff, utxoFilter, utxoSum };
|
550
589
|
//# sourceMappingURL=out.js.map
|
551
590
|
//# sourceMappingURL=index.esm.js.map
|