@solana/codecs-data-structures 2.0.0-experimental.eb5fd16 → 2.0.0-experimental.eeb355e

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.
@@ -110,11 +110,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
110
110
  let littleEndian;
111
111
  let defaultDescription = input.name;
112
112
  if (input.size > 1) {
113
- littleEndian = !("endian" in input.options) || input.options.endian === 0;
113
+ littleEndian = !("endian" in input.config) || input.config.endian === 0;
114
114
  defaultDescription += littleEndian ? "(le)" : "(be)";
115
115
  }
116
116
  return {
117
- description: input.options.description ?? defaultDescription,
117
+ description: input.config.description ?? defaultDescription,
118
118
  fixedSize: input.size,
119
119
  littleEndian,
120
120
  maxSize: input.size
@@ -155,30 +155,30 @@ this.globalThis.solanaWeb3 = (function (exports) {
155
155
  const bytesLength = length ?? bytes.byteLength;
156
156
  return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
157
157
  }
158
- var getU32Encoder = (options = {}) => numberEncoderFactory({
158
+ var getU32Encoder = (config = {}) => numberEncoderFactory({
159
+ config,
159
160
  name: "u32",
160
- options,
161
161
  range: [0, Number("0xffffffff")],
162
162
  set: (view, value, le) => view.setUint32(0, value, le),
163
163
  size: 4
164
164
  });
165
- var getU32Decoder = (options = {}) => numberDecoderFactory({
165
+ var getU32Decoder = (config = {}) => numberDecoderFactory({
166
+ config,
166
167
  get: (view, le) => view.getUint32(0, le),
167
168
  name: "u32",
168
- options,
169
169
  size: 4
170
170
  });
171
- var getU8Encoder = (options = {}) => numberEncoderFactory({
171
+ var getU8Encoder = (config = {}) => numberEncoderFactory({
172
+ config,
172
173
  name: "u8",
173
- options,
174
174
  range: [0, Number("0xff")],
175
175
  set: (view, value) => view.setUint8(0, value),
176
176
  size: 1
177
177
  });
178
- var getU8Decoder = (options = {}) => numberDecoderFactory({
178
+ var getU8Decoder = (config = {}) => numberDecoderFactory({
179
+ config,
179
180
  get: (view) => view.getUint8(0),
180
181
  name: "u8",
181
- options,
182
182
  size: 1
183
183
  });
184
184
 
@@ -249,10 +249,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
249
249
  maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
250
250
  };
251
251
  }
252
- function getArrayEncoder(item, options = {}) {
253
- const size = options.size ?? getU32Encoder();
252
+ function getArrayEncoder(item, config = {}) {
253
+ const size = config.size ?? getU32Encoder();
254
254
  return {
255
- ...arrayCodecHelper(item, size, options.description),
255
+ ...arrayCodecHelper(item, size, config.description),
256
256
  encode: (value) => {
257
257
  if (typeof size === "number") {
258
258
  assertValidNumberOfItemsForCodec("array", size, value.length);
@@ -261,10 +261,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
261
261
  }
262
262
  };
263
263
  }
264
- function getArrayDecoder(item, options = {}) {
265
- const size = options.size ?? getU32Decoder();
264
+ function getArrayDecoder(item, config = {}) {
265
+ const size = config.size ?? getU32Decoder();
266
266
  return {
267
- ...arrayCodecHelper(item, size, options.description),
267
+ ...arrayCodecHelper(item, size, config.description),
268
268
  decode: (bytes, offset = 0) => {
269
269
  if (typeof size === "object" && bytes.slice(offset).length === 0) {
270
270
  return [[], offset];
@@ -281,17 +281,17 @@ this.globalThis.solanaWeb3 = (function (exports) {
281
281
  }
282
282
  };
283
283
  }
284
- function getArrayCodec(item, options = {}) {
285
- return combineCodec(getArrayEncoder(item, options), getArrayDecoder(item, options));
284
+ function getArrayCodec(item, config = {}) {
285
+ return combineCodec(getArrayEncoder(item, config), getArrayDecoder(item, config));
286
286
  }
287
287
 
288
288
  // src/bit-array.ts
289
- var getBitArrayEncoder = (size, options = {}) => {
290
- const parsedOptions = typeof options === "boolean" ? { backward: options } : options;
291
- const backward = parsedOptions.backward ?? false;
289
+ var getBitArrayEncoder = (size, config = {}) => {
290
+ const parsedConfig = typeof config === "boolean" ? { backward: config } : config;
291
+ const backward = parsedConfig.backward ?? false;
292
292
  const backwardSuffix = backward ? "; backward" : "";
293
293
  return {
294
- description: parsedOptions.description ?? `bitArray(${size}${backwardSuffix})`,
294
+ description: parsedConfig.description ?? `bitArray(${size}${backwardSuffix})`,
295
295
  encode(value) {
296
296
  const bytes = [];
297
297
  for (let i = 0; i < size; i += 1) {
@@ -312,9 +312,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
312
312
  maxSize: size
313
313
  };
314
314
  };
315
- var getBitArrayDecoder = (size, options = {}) => {
316
- const parsedOptions = typeof options === "boolean" ? { backward: options } : options;
317
- const backward = parsedOptions.backward ?? false;
315
+ var getBitArrayDecoder = (size, config = {}) => {
316
+ const parsedConfig = typeof config === "boolean" ? { backward: config } : config;
317
+ const backward = parsedConfig.backward ?? false;
318
318
  const backwardSuffix = backward ? "; backward" : "";
319
319
  return {
320
320
  decode(bytes, offset = 0) {
@@ -335,26 +335,26 @@ this.globalThis.solanaWeb3 = (function (exports) {
335
335
  });
336
336
  return [booleans, offset + size];
337
337
  },
338
- description: parsedOptions.description ?? `bitArray(${size}${backwardSuffix})`,
338
+ description: parsedConfig.description ?? `bitArray(${size}${backwardSuffix})`,
339
339
  fixedSize: size,
340
340
  maxSize: size
341
341
  };
342
342
  };
343
- var getBitArrayCodec = (size, options = {}) => combineCodec(getBitArrayEncoder(size, options), getBitArrayDecoder(size, options));
343
+ var getBitArrayCodec = (size, config = {}) => combineCodec(getBitArrayEncoder(size, config), getBitArrayDecoder(size, config));
344
344
 
345
345
  // src/boolean.ts
346
- function getBooleanEncoder(options = {}) {
347
- const size = options.size ?? getU8Encoder();
346
+ function getBooleanEncoder(config = {}) {
347
+ const size = config.size ?? getU8Encoder();
348
348
  assertFixedSizeCodec(size, "Codec [bool] requires a fixed size.");
349
349
  return {
350
- description: options.description ?? `bool(${size.description})`,
350
+ description: config.description ?? `bool(${size.description})`,
351
351
  encode: (value) => size.encode(value ? 1 : 0),
352
352
  fixedSize: size.fixedSize,
353
353
  maxSize: size.fixedSize
354
354
  };
355
355
  }
356
- function getBooleanDecoder(options = {}) {
357
- const size = options.size ?? getU8Decoder();
356
+ function getBooleanDecoder(config = {}) {
357
+ const size = config.size ?? getU8Decoder();
358
358
  assertFixedSizeCodec(size, "Codec [bool] requires a fixed size.");
359
359
  return {
360
360
  decode: (bytes, offset = 0) => {
@@ -362,20 +362,20 @@ this.globalThis.solanaWeb3 = (function (exports) {
362
362
  const [value, vOffset] = size.decode(bytes, offset);
363
363
  return [value === 1, vOffset];
364
364
  },
365
- description: options.description ?? `bool(${size.description})`,
365
+ description: config.description ?? `bool(${size.description})`,
366
366
  fixedSize: size.fixedSize,
367
367
  maxSize: size.fixedSize
368
368
  };
369
369
  }
370
- function getBooleanCodec(options = {}) {
371
- return combineCodec(getBooleanEncoder(options), getBooleanDecoder(options));
370
+ function getBooleanCodec(config = {}) {
371
+ return combineCodec(getBooleanEncoder(config), getBooleanDecoder(config));
372
372
  }
373
373
 
374
374
  // src/bytes.ts
375
- function getBytesEncoder(options = {}) {
376
- const size = options.size ?? "variable";
375
+ function getBytesEncoder(config = {}) {
376
+ const size = config.size ?? "variable";
377
377
  const sizeDescription = typeof size === "object" ? size.description : `${size}`;
378
- const description = options.description ?? `bytes(${sizeDescription})`;
378
+ const description = config.description ?? `bytes(${sizeDescription})`;
379
379
  const byteEncoder = {
380
380
  description,
381
381
  encode: (value) => value,
@@ -397,10 +397,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
397
397
  }
398
398
  };
399
399
  }
400
- function getBytesDecoder(options = {}) {
401
- const size = options.size ?? "variable";
400
+ function getBytesDecoder(config = {}) {
401
+ const size = config.size ?? "variable";
402
402
  const sizeDescription = typeof size === "object" ? size.description : `${size}`;
403
- const description = options.description ?? `bytes(${sizeDescription})`;
403
+ const description = config.description ?? `bytes(${sizeDescription})`;
404
404
  const byteDecoder = {
405
405
  decode: (bytes, offset = 0) => {
406
406
  const slice = bytes.slice(offset);
@@ -431,8 +431,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
431
431
  }
432
432
  };
433
433
  }
434
- function getBytesCodec(options = {}) {
435
- return combineCodec(getBytesEncoder(options), getBytesDecoder(options));
434
+ function getBytesCodec(config = {}) {
435
+ return combineCodec(getBytesEncoder(config), getBytesDecoder(config));
436
436
  }
437
437
 
438
438
  // src/data-enum.ts
@@ -447,10 +447,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
447
447
  maxSize: variants.length === 0 ? prefix.maxSize : sumCodecSizes([prefix.maxSize, maxVariantSize])
448
448
  };
449
449
  }
450
- function getDataEnumEncoder(variants, options = {}) {
451
- const prefix = options.size ?? getU8Encoder();
450
+ function getDataEnumEncoder(variants, config = {}) {
451
+ const prefix = config.size ?? getU8Encoder();
452
452
  return {
453
- ...dataEnumCodecHelper(variants, prefix, options.description),
453
+ ...dataEnumCodecHelper(variants, prefix, config.description),
454
454
  encode: (variant) => {
455
455
  const discriminator = variants.findIndex(([key]) => variant.__kind === key);
456
456
  if (discriminator < 0) {
@@ -465,10 +465,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
465
465
  }
466
466
  };
467
467
  }
468
- function getDataEnumDecoder(variants, options = {}) {
469
- const prefix = options.size ?? getU8Decoder();
468
+ function getDataEnumDecoder(variants, config = {}) {
469
+ const prefix = config.size ?? getU8Decoder();
470
470
  return {
471
- ...dataEnumCodecHelper(variants, prefix, options.description),
471
+ ...dataEnumCodecHelper(variants, prefix, config.description),
472
472
  decode: (bytes, offset = 0) => {
473
473
  assertByteArrayIsNotEmptyForCodec("dataEnum", bytes, offset);
474
474
  const [discriminator, dOffset] = prefix.decode(bytes, offset);
@@ -485,8 +485,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
485
485
  }
486
486
  };
487
487
  }
488
- function getDataEnumCodec(variants, options = {}) {
489
- return combineCodec(getDataEnumEncoder(variants, options), getDataEnumDecoder(variants, options));
488
+ function getDataEnumCodec(variants, config = {}) {
489
+ return combineCodec(getDataEnumEncoder(variants, config), getDataEnumDecoder(variants, config));
490
490
  }
491
491
 
492
492
  // src/map.ts
@@ -500,10 +500,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
500
500
  maxSize: getArrayLikeCodecSizeFromChildren(size, [key.maxSize, value.maxSize])
501
501
  };
502
502
  }
503
- function getMapEncoder(key, value, options = {}) {
504
- const size = options.size ?? getU32Encoder();
503
+ function getMapEncoder(key, value, config = {}) {
504
+ const size = config.size ?? getU32Encoder();
505
505
  return {
506
- ...mapCodecHelper(key, value, size, options.description),
506
+ ...mapCodecHelper(key, value, size, config.description),
507
507
  encode: (map) => {
508
508
  if (typeof size === "number") {
509
509
  assertValidNumberOfItemsForCodec("map", size, map.size);
@@ -513,10 +513,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
513
513
  }
514
514
  };
515
515
  }
516
- function getMapDecoder(key, value, options = {}) {
517
- const size = options.size ?? getU32Decoder();
516
+ function getMapDecoder(key, value, config = {}) {
517
+ const size = config.size ?? getU32Decoder();
518
518
  return {
519
- ...mapCodecHelper(key, value, size, options.description),
519
+ ...mapCodecHelper(key, value, size, config.description),
520
520
  decode: (bytes, offset = 0) => {
521
521
  const map = /* @__PURE__ */ new Map();
522
522
  if (typeof size === "object" && bytes.slice(offset).length === 0) {
@@ -540,8 +540,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
540
540
  }
541
541
  };
542
542
  }
543
- function getMapCodec(key, value, options = {}) {
544
- return combineCodec(getMapEncoder(key, value, options), getMapDecoder(key, value, options));
543
+ function getMapCodec(key, value, config = {}) {
544
+ return combineCodec(getMapEncoder(key, value, config), getMapDecoder(key, value, config));
545
545
  }
546
546
 
547
547
  // src/nullable.ts
@@ -560,11 +560,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
560
560
  maxSize: sumCodecSizes([prefix.maxSize, item.maxSize])
561
561
  };
562
562
  }
563
- function getNullableEncoder(item, options = {}) {
564
- const prefix = options.prefix ?? getU8Encoder();
565
- const fixed = options.fixed ?? false;
563
+ function getNullableEncoder(item, config = {}) {
564
+ const prefix = config.prefix ?? getU8Encoder();
565
+ const fixed = config.fixed ?? false;
566
566
  return {
567
- ...nullableCodecHelper(item, prefix, fixed, options.description),
567
+ ...nullableCodecHelper(item, prefix, fixed, config.description),
568
568
  encode: (option) => {
569
569
  const prefixByte = prefix.encode(Number(option !== null));
570
570
  let itemBytes = option !== null ? item.encode(option) : new Uint8Array();
@@ -573,11 +573,11 @@ this.globalThis.solanaWeb3 = (function (exports) {
573
573
  }
574
574
  };
575
575
  }
576
- function getNullableDecoder(item, options = {}) {
577
- const prefix = options.prefix ?? getU8Decoder();
578
- const fixed = options.fixed ?? false;
576
+ function getNullableDecoder(item, config = {}) {
577
+ const prefix = config.prefix ?? getU8Decoder();
578
+ const fixed = config.fixed ?? false;
579
579
  return {
580
- ...nullableCodecHelper(item, prefix, fixed, options.description),
580
+ ...nullableCodecHelper(item, prefix, fixed, config.description),
581
581
  decode: (bytes, offset = 0) => {
582
582
  if (bytes.length - offset <= 0) {
583
583
  return [null, offset];
@@ -594,8 +594,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
594
594
  }
595
595
  };
596
596
  }
597
- function getNullableCodec(item, options = {}) {
598
- return combineCodec(getNullableEncoder(item, options), getNullableDecoder(item, options));
597
+ function getNullableCodec(item, config = {}) {
598
+ return combineCodec(getNullableEncoder(item, config), getNullableDecoder(item, config));
599
599
  }
600
600
 
601
601
  // src/scalar-enum.ts
@@ -619,9 +619,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
619
619
  stringValues
620
620
  };
621
621
  }
622
- function getScalarEnumEncoder(constructor, options = {}) {
623
- const prefix = options.size ?? getU8Encoder();
624
- const { description, fixedSize, maxSize, minRange, maxRange, stringValues, enumKeys, enumValues } = scalarEnumCoderHelper(constructor, prefix, options.description);
622
+ function getScalarEnumEncoder(constructor, config = {}) {
623
+ const prefix = config.size ?? getU8Encoder();
624
+ const { description, fixedSize, maxSize, minRange, maxRange, stringValues, enumKeys, enumValues } = scalarEnumCoderHelper(constructor, prefix, config.description);
625
625
  return {
626
626
  description,
627
627
  encode: (value) => {
@@ -643,12 +643,12 @@ this.globalThis.solanaWeb3 = (function (exports) {
643
643
  maxSize
644
644
  };
645
645
  }
646
- function getScalarEnumDecoder(constructor, options = {}) {
647
- const prefix = options.size ?? getU8Decoder();
646
+ function getScalarEnumDecoder(constructor, config = {}) {
647
+ const prefix = config.size ?? getU8Decoder();
648
648
  const { description, fixedSize, maxSize, minRange, maxRange, isNumericEnum, enumValues } = scalarEnumCoderHelper(
649
649
  constructor,
650
650
  prefix,
651
- options.description
651
+ config.description
652
652
  );
653
653
  return {
654
654
  decode: (bytes, offset = 0) => {
@@ -668,8 +668,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
668
668
  maxSize
669
669
  };
670
670
  }
671
- function getScalarEnumCodec(constructor, options = {}) {
672
- return combineCodec(getScalarEnumEncoder(constructor, options), getScalarEnumDecoder(constructor, options));
671
+ function getScalarEnumCodec(constructor, config = {}) {
672
+ return combineCodec(getScalarEnumEncoder(constructor, config), getScalarEnumDecoder(constructor, config));
673
673
  }
674
674
 
675
675
  // src/set.ts
@@ -683,10 +683,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
683
683
  maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
684
684
  };
685
685
  }
686
- function getSetEncoder(item, options = {}) {
687
- const size = options.size ?? getU32Encoder();
686
+ function getSetEncoder(item, config = {}) {
687
+ const size = config.size ?? getU32Encoder();
688
688
  return {
689
- ...setCodecHelper(item, size, options.description),
689
+ ...setCodecHelper(item, size, config.description),
690
690
  encode: (set) => {
691
691
  if (typeof size === "number" && set.size !== size) {
692
692
  assertValidNumberOfItemsForCodec("set", size, set.size);
@@ -696,10 +696,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
696
696
  }
697
697
  };
698
698
  }
699
- function getSetDecoder(item, options = {}) {
700
- const size = options.size ?? getU32Decoder();
699
+ function getSetDecoder(item, config = {}) {
700
+ const size = config.size ?? getU32Decoder();
701
701
  return {
702
- ...setCodecHelper(item, size, options.description),
702
+ ...setCodecHelper(item, size, config.description),
703
703
  decode: (bytes, offset = 0) => {
704
704
  const set = /* @__PURE__ */ new Set();
705
705
  if (typeof size === "object" && bytes.slice(offset).length === 0) {
@@ -716,8 +716,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
716
716
  }
717
717
  };
718
718
  }
719
- function getSetCodec(item, options = {}) {
720
- return combineCodec(getSetEncoder(item, options), getSetDecoder(item, options));
719
+ function getSetCodec(item, config = {}) {
720
+ return combineCodec(getSetEncoder(item, config), getSetDecoder(item, config));
721
721
  }
722
722
 
723
723
  // src/struct.ts
@@ -729,18 +729,18 @@ this.globalThis.solanaWeb3 = (function (exports) {
729
729
  maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
730
730
  };
731
731
  }
732
- function getStructEncoder(fields, options = {}) {
732
+ function getStructEncoder(fields, config = {}) {
733
733
  return {
734
- ...structCodecHelper(fields, options.description),
734
+ ...structCodecHelper(fields, config.description),
735
735
  encode: (struct) => {
736
736
  const fieldBytes = fields.map(([key, codec]) => codec.encode(struct[key]));
737
737
  return mergeBytes(fieldBytes);
738
738
  }
739
739
  };
740
740
  }
741
- function getStructDecoder(fields, options = {}) {
741
+ function getStructDecoder(fields, config = {}) {
742
742
  return {
743
- ...structCodecHelper(fields, options.description),
743
+ ...structCodecHelper(fields, config.description),
744
744
  decode: (bytes, offset = 0) => {
745
745
  const struct = {};
746
746
  fields.forEach(([key, codec]) => {
@@ -752,8 +752,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
752
752
  }
753
753
  };
754
754
  }
755
- function getStructCodec(fields, options = {}) {
756
- return combineCodec(getStructEncoder(fields, options), getStructDecoder(fields, options));
755
+ function getStructCodec(fields, config = {}) {
756
+ return combineCodec(getStructEncoder(fields, config), getStructDecoder(fields, config));
757
757
  }
758
758
 
759
759
  // src/tuple.ts
@@ -765,18 +765,18 @@ this.globalThis.solanaWeb3 = (function (exports) {
765
765
  maxSize: sumCodecSizes(items.map((item) => item.maxSize))
766
766
  };
767
767
  }
768
- function getTupleEncoder(items, options = {}) {
768
+ function getTupleEncoder(items, config = {}) {
769
769
  return {
770
- ...tupleCodecHelper(items, options.description),
770
+ ...tupleCodecHelper(items, config.description),
771
771
  encode: (value) => {
772
772
  assertValidNumberOfItemsForCodec("tuple", items.length, value.length);
773
773
  return mergeBytes(items.map((item, index) => item.encode(value[index])));
774
774
  }
775
775
  };
776
776
  }
777
- function getTupleDecoder(items, options = {}) {
777
+ function getTupleDecoder(items, config = {}) {
778
778
  return {
779
- ...tupleCodecHelper(items, options.description),
779
+ ...tupleCodecHelper(items, config.description),
780
780
  decode: (bytes, offset = 0) => {
781
781
  const values = [];
782
782
  items.forEach((codec) => {
@@ -788,32 +788,32 @@ this.globalThis.solanaWeb3 = (function (exports) {
788
788
  }
789
789
  };
790
790
  }
791
- function getTupleCodec(items, options = {}) {
791
+ function getTupleCodec(items, config = {}) {
792
792
  return combineCodec(
793
- getTupleEncoder(items, options),
794
- getTupleDecoder(items, options)
793
+ getTupleEncoder(items, config),
794
+ getTupleDecoder(items, config)
795
795
  );
796
796
  }
797
797
 
798
798
  // src/unit.ts
799
- function getUnitEncoder(options = {}) {
799
+ function getUnitEncoder(config = {}) {
800
800
  return {
801
- description: options.description ?? "unit",
801
+ description: config.description ?? "unit",
802
802
  encode: () => new Uint8Array(),
803
803
  fixedSize: 0,
804
804
  maxSize: 0
805
805
  };
806
806
  }
807
- function getUnitDecoder(options = {}) {
807
+ function getUnitDecoder(config = {}) {
808
808
  return {
809
809
  decode: (_bytes, offset = 0) => [void 0, offset],
810
- description: options.description ?? "unit",
810
+ description: config.description ?? "unit",
811
811
  fixedSize: 0,
812
812
  maxSize: 0
813
813
  };
814
814
  }
815
- function getUnitCodec(options = {}) {
816
- return combineCodec(getUnitEncoder(options), getUnitDecoder(options));
815
+ function getUnitCodec(config = {}) {
816
+ return combineCodec(getUnitEncoder(config), getUnitDecoder(config));
817
817
  }
818
818
 
819
819
  exports.assertValidNumberOfItemsForCodec = assertValidNumberOfItemsForCodec;