@solana/codecs-data-structures 2.0.0-experimental.a7c0b6a → 2.0.0-experimental.a7c51e0

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.
@@ -16,7 +16,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
16
16
  }
17
17
  function assertFixedSizeCodec(data, message) {
18
18
  if (data.fixedSize === null) {
19
- throw new Error(message ?? "Expected a fixed-size codec, got a variable-size one.");
19
+ throw new Error(message != null ? message : "Expected a fixed-size codec, got a variable-size one.");
20
20
  }
21
21
  }
22
22
  var mergeBytes = (byteArrays) => {
@@ -62,7 +62,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
62
62
  }
63
63
  return {
64
64
  decode: decoder.decode,
65
- description: description ?? encoder.description,
65
+ description: description != null ? description : encoder.description,
66
66
  encode: encoder.encode,
67
67
  fixedSize: encoder.fixedSize,
68
68
  maxSize: encoder.maxSize
@@ -70,7 +70,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
70
70
  }
71
71
  function fixCodecHelper(data, fixedBytes, description) {
72
72
  return {
73
- description: description ?? `fixed(${fixedBytes}, ${data.description})`,
73
+ description: description != null ? description : `fixed(${fixedBytes}, ${data.description})`,
74
74
  fixedSize: fixedBytes,
75
75
  maxSize: fixedBytes
76
76
  };
@@ -107,6 +107,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
107
107
  }
108
108
  }
109
109
  function sharedNumberFactory(input) {
110
+ var _a;
110
111
  let littleEndian;
111
112
  let defaultDescription = input.name;
112
113
  if (input.size > 1) {
@@ -114,7 +115,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
114
115
  defaultDescription += littleEndian ? "(le)" : "(be)";
115
116
  }
116
117
  return {
117
- description: input.config.description ?? defaultDescription,
118
+ description: (_a = input.config.description) != null ? _a : defaultDescription,
118
119
  fixedSize: input.size,
119
120
  littleEndian,
120
121
  maxSize: input.size
@@ -151,8 +152,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
151
152
  };
152
153
  }
153
154
  function toArrayBuffer(bytes, offset, length) {
154
- const bytesOffset = bytes.byteOffset + (offset ?? 0);
155
- const bytesLength = length ?? bytes.byteLength;
155
+ const bytesOffset = bytes.byteOffset + (offset != null ? offset : 0);
156
+ const bytesLength = length != null ? length : bytes.byteLength;
156
157
  return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);
157
158
  }
158
159
  var getU32Encoder = (config = {}) => numberEncoderFactory({
@@ -244,13 +245,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
244
245
  throw new Error('Codecs of "remainder" size must have fixed-size items.');
245
246
  }
246
247
  return {
247
- description: description ?? `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
248
+ description: description != null ? description : `array(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
248
249
  fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
249
250
  maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
250
251
  };
251
252
  }
252
253
  function getArrayEncoder(item, config = {}) {
253
- const size = config.size ?? getU32Encoder();
254
+ var _a;
255
+ const size = (_a = config.size) != null ? _a : getU32Encoder();
254
256
  return {
255
257
  ...arrayCodecHelper(item, size, config.description),
256
258
  encode: (value) => {
@@ -262,7 +264,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
262
264
  };
263
265
  }
264
266
  function getArrayDecoder(item, config = {}) {
265
- const size = config.size ?? getU32Decoder();
267
+ var _a;
268
+ const size = (_a = config.size) != null ? _a : getU32Decoder();
266
269
  return {
267
270
  ...arrayCodecHelper(item, size, config.description),
268
271
  decode: (bytes, offset = 0) => {
@@ -287,17 +290,19 @@ this.globalThis.solanaWeb3 = (function (exports) {
287
290
 
288
291
  // src/bit-array.ts
289
292
  var getBitArrayEncoder = (size, config = {}) => {
293
+ var _a, _b;
290
294
  const parsedConfig = typeof config === "boolean" ? { backward: config } : config;
291
- const backward = parsedConfig.backward ?? false;
295
+ const backward = (_a = parsedConfig.backward) != null ? _a : false;
292
296
  const backwardSuffix = backward ? "; backward" : "";
293
297
  return {
294
- description: parsedConfig.description ?? `bitArray(${size}${backwardSuffix})`,
298
+ description: (_b = parsedConfig.description) != null ? _b : `bitArray(${size}${backwardSuffix})`,
295
299
  encode(value) {
300
+ var _a2;
296
301
  const bytes = [];
297
302
  for (let i = 0; i < size; i += 1) {
298
303
  let byte = 0;
299
304
  for (let j = 0; j < 8; j += 1) {
300
- const feature = Number(value[i * 8 + j] ?? 0);
305
+ const feature = Number((_a2 = value[i * 8 + j]) != null ? _a2 : 0);
301
306
  byte |= feature << (backward ? j : 7 - j);
302
307
  }
303
308
  if (backward) {
@@ -313,8 +318,9 @@ this.globalThis.solanaWeb3 = (function (exports) {
313
318
  };
314
319
  };
315
320
  var getBitArrayDecoder = (size, config = {}) => {
321
+ var _a, _b;
316
322
  const parsedConfig = typeof config === "boolean" ? { backward: config } : config;
317
- const backward = parsedConfig.backward ?? false;
323
+ const backward = (_a = parsedConfig.backward) != null ? _a : false;
318
324
  const backwardSuffix = backward ? "; backward" : "";
319
325
  return {
320
326
  decode(bytes, offset = 0) {
@@ -335,7 +341,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
335
341
  });
336
342
  return [booleans, offset + size];
337
343
  },
338
- description: parsedConfig.description ?? `bitArray(${size}${backwardSuffix})`,
344
+ description: (_b = parsedConfig.description) != null ? _b : `bitArray(${size}${backwardSuffix})`,
339
345
  fixedSize: size,
340
346
  maxSize: size
341
347
  };
@@ -344,17 +350,19 @@ this.globalThis.solanaWeb3 = (function (exports) {
344
350
 
345
351
  // src/boolean.ts
346
352
  function getBooleanEncoder(config = {}) {
347
- const size = config.size ?? getU8Encoder();
353
+ var _a, _b;
354
+ const size = (_a = config.size) != null ? _a : getU8Encoder();
348
355
  assertFixedSizeCodec(size, "Codec [bool] requires a fixed size.");
349
356
  return {
350
- description: config.description ?? `bool(${size.description})`,
357
+ description: (_b = config.description) != null ? _b : `bool(${size.description})`,
351
358
  encode: (value) => size.encode(value ? 1 : 0),
352
359
  fixedSize: size.fixedSize,
353
360
  maxSize: size.fixedSize
354
361
  };
355
362
  }
356
363
  function getBooleanDecoder(config = {}) {
357
- const size = config.size ?? getU8Decoder();
364
+ var _a, _b;
365
+ const size = (_a = config.size) != null ? _a : getU8Decoder();
358
366
  assertFixedSizeCodec(size, "Codec [bool] requires a fixed size.");
359
367
  return {
360
368
  decode: (bytes, offset = 0) => {
@@ -362,7 +370,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
362
370
  const [value, vOffset] = size.decode(bytes, offset);
363
371
  return [value === 1, vOffset];
364
372
  },
365
- description: config.description ?? `bool(${size.description})`,
373
+ description: (_b = config.description) != null ? _b : `bool(${size.description})`,
366
374
  fixedSize: size.fixedSize,
367
375
  maxSize: size.fixedSize
368
376
  };
@@ -373,9 +381,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
373
381
 
374
382
  // src/bytes.ts
375
383
  function getBytesEncoder(config = {}) {
376
- const size = config.size ?? "variable";
384
+ var _a, _b;
385
+ const size = (_a = config.size) != null ? _a : "variable";
377
386
  const sizeDescription = typeof size === "object" ? size.description : `${size}`;
378
- const description = config.description ?? `bytes(${sizeDescription})`;
387
+ const description = (_b = config.description) != null ? _b : `bytes(${sizeDescription})`;
379
388
  const byteEncoder = {
380
389
  description,
381
390
  encode: (value) => value,
@@ -398,9 +407,10 @@ this.globalThis.solanaWeb3 = (function (exports) {
398
407
  };
399
408
  }
400
409
  function getBytesDecoder(config = {}) {
401
- const size = config.size ?? "variable";
410
+ var _a, _b;
411
+ const size = (_a = config.size) != null ? _a : "variable";
402
412
  const sizeDescription = typeof size === "object" ? size.description : `${size}`;
403
- const description = config.description ?? `bytes(${sizeDescription})`;
413
+ const description = (_b = config.description) != null ? _b : `bytes(${sizeDescription})`;
404
414
  const byteDecoder = {
405
415
  decode: (bytes, offset = 0) => {
406
416
  const slice = bytes.slice(offset);
@@ -442,13 +452,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
442
452
  const fixedVariantSize = allVariantHaveTheSameFixedSize ? variants[0][1].fixedSize : null;
443
453
  const maxVariantSize = maxCodecSizes(variants.map(([, field]) => field.maxSize));
444
454
  return {
445
- description: description ?? `dataEnum(${fieldDescriptions}; ${prefix.description})`,
455
+ description: description != null ? description : `dataEnum(${fieldDescriptions}; ${prefix.description})`,
446
456
  fixedSize: variants.length === 0 ? prefix.fixedSize : sumCodecSizes([prefix.fixedSize, fixedVariantSize]),
447
457
  maxSize: variants.length === 0 ? prefix.maxSize : sumCodecSizes([prefix.maxSize, maxVariantSize])
448
458
  };
449
459
  }
450
460
  function getDataEnumEncoder(variants, config = {}) {
451
- const prefix = config.size ?? getU8Encoder();
461
+ var _a;
462
+ const prefix = (_a = config.size) != null ? _a : getU8Encoder();
452
463
  return {
453
464
  ...dataEnumCodecHelper(variants, prefix, config.description),
454
465
  encode: (variant) => {
@@ -466,14 +477,16 @@ this.globalThis.solanaWeb3 = (function (exports) {
466
477
  };
467
478
  }
468
479
  function getDataEnumDecoder(variants, config = {}) {
469
- const prefix = config.size ?? getU8Decoder();
480
+ var _a;
481
+ const prefix = (_a = config.size) != null ? _a : getU8Decoder();
470
482
  return {
471
483
  ...dataEnumCodecHelper(variants, prefix, config.description),
472
484
  decode: (bytes, offset = 0) => {
485
+ var _a2;
473
486
  assertByteArrayIsNotEmptyForCodec("dataEnum", bytes, offset);
474
487
  const [discriminator, dOffset] = prefix.decode(bytes, offset);
475
488
  offset = dOffset;
476
- const variantField = variants[Number(discriminator)] ?? null;
489
+ const variantField = (_a2 = variants[Number(discriminator)]) != null ? _a2 : null;
477
490
  if (!variantField) {
478
491
  throw new Error(
479
492
  `Enum discriminator out of range. Expected a number between 0 and ${variants.length - 1}, got ${discriminator}.`
@@ -481,7 +494,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
481
494
  }
482
495
  const [variant, vOffset] = variantField[1].decode(bytes, offset);
483
496
  offset = vOffset;
484
- return [{ __kind: variantField[0], ...variant ?? {} }, offset];
497
+ return [{ __kind: variantField[0], ...variant != null ? variant : {} }, offset];
485
498
  }
486
499
  };
487
500
  }
@@ -495,13 +508,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
495
508
  throw new Error('Codecs of "remainder" size must have fixed-size items.');
496
509
  }
497
510
  return {
498
- description: description ?? `map(${key.description}, ${value.description}; ${getArrayLikeCodecSizeDescription(size)})`,
511
+ description: description != null ? description : `map(${key.description}, ${value.description}; ${getArrayLikeCodecSizeDescription(size)})`,
499
512
  fixedSize: getArrayLikeCodecSizeFromChildren(size, [key.fixedSize, value.fixedSize]),
500
513
  maxSize: getArrayLikeCodecSizeFromChildren(size, [key.maxSize, value.maxSize])
501
514
  };
502
515
  }
503
516
  function getMapEncoder(key, value, config = {}) {
504
- const size = config.size ?? getU32Encoder();
517
+ var _a;
518
+ const size = (_a = config.size) != null ? _a : getU32Encoder();
505
519
  return {
506
520
  ...mapCodecHelper(key, value, size, config.description),
507
521
  encode: (map) => {
@@ -514,7 +528,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
514
528
  };
515
529
  }
516
530
  function getMapDecoder(key, value, config = {}) {
517
- const size = config.size ?? getU32Decoder();
531
+ var _a;
532
+ const size = (_a = config.size) != null ? _a : getU32Decoder();
518
533
  return {
519
534
  ...mapCodecHelper(key, value, size, config.description),
520
535
  decode: (bytes, offset = 0) => {
@@ -555,14 +570,15 @@ this.globalThis.solanaWeb3 = (function (exports) {
555
570
  fixedSize = prefix.fixedSize + item.fixedSize;
556
571
  }
557
572
  return {
558
- description: description ?? `nullable(${item.description + descriptionSuffix})`,
573
+ description: description != null ? description : `nullable(${item.description + descriptionSuffix})`,
559
574
  fixedSize,
560
575
  maxSize: sumCodecSizes([prefix.maxSize, item.maxSize])
561
576
  };
562
577
  }
563
578
  function getNullableEncoder(item, config = {}) {
564
- const prefix = config.prefix ?? getU8Encoder();
565
- const fixed = config.fixed ?? false;
579
+ var _a, _b;
580
+ const prefix = (_a = config.prefix) != null ? _a : getU8Encoder();
581
+ const fixed = (_b = config.fixed) != null ? _b : false;
566
582
  return {
567
583
  ...nullableCodecHelper(item, prefix, fixed, config.description),
568
584
  encode: (option) => {
@@ -574,15 +590,17 @@ this.globalThis.solanaWeb3 = (function (exports) {
574
590
  };
575
591
  }
576
592
  function getNullableDecoder(item, config = {}) {
577
- const prefix = config.prefix ?? getU8Decoder();
578
- const fixed = config.fixed ?? false;
593
+ var _a, _b;
594
+ const prefix = (_a = config.prefix) != null ? _a : getU8Decoder();
595
+ const fixed = (_b = config.fixed) != null ? _b : false;
579
596
  return {
580
597
  ...nullableCodecHelper(item, prefix, fixed, config.description),
581
598
  decode: (bytes, offset = 0) => {
599
+ var _a2, _b2;
582
600
  if (bytes.length - offset <= 0) {
583
601
  return [null, offset];
584
602
  }
585
- const fixedOffset = offset + (prefix.fixedSize ?? 0) + (item.fixedSize ?? 0);
603
+ const fixedOffset = offset + ((_a2 = prefix.fixedSize) != null ? _a2 : 0) + ((_b2 = item.fixedSize) != null ? _b2 : 0);
586
604
  const [isSome, prefixOffset] = prefix.decode(bytes, offset);
587
605
  offset = prefixOffset;
588
606
  if (isSome === 0) {
@@ -608,7 +626,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
608
626
  const maxRange = isNumericEnum ? enumValues.length / 2 - 1 : enumValues.length - 1;
609
627
  const stringValues = isNumericEnum ? [...enumKeys] : [.../* @__PURE__ */ new Set([...enumKeys, ...enumValues])];
610
628
  return {
611
- description: description ?? `enum(${valueDescriptions}; ${prefix.description})`,
629
+ description: description != null ? description : `enum(${valueDescriptions}; ${prefix.description})`,
612
630
  enumKeys,
613
631
  enumValues,
614
632
  fixedSize: prefix.fixedSize,
@@ -620,7 +638,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
620
638
  };
621
639
  }
622
640
  function getScalarEnumEncoder(constructor, config = {}) {
623
- const prefix = config.size ?? getU8Encoder();
641
+ var _a;
642
+ const prefix = (_a = config.size) != null ? _a : getU8Encoder();
624
643
  const { description, fixedSize, maxSize, minRange, maxRange, stringValues, enumKeys, enumValues } = scalarEnumCoderHelper(constructor, prefix, config.description);
625
644
  return {
626
645
  description,
@@ -644,7 +663,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
644
663
  };
645
664
  }
646
665
  function getScalarEnumDecoder(constructor, config = {}) {
647
- const prefix = config.size ?? getU8Decoder();
666
+ var _a;
667
+ const prefix = (_a = config.size) != null ? _a : getU8Decoder();
648
668
  const { description, fixedSize, maxSize, minRange, maxRange, isNumericEnum, enumValues } = scalarEnumCoderHelper(
649
669
  constructor,
650
670
  prefix,
@@ -678,13 +698,14 @@ this.globalThis.solanaWeb3 = (function (exports) {
678
698
  throw new Error('Codecs of "remainder" size must have fixed-size items.');
679
699
  }
680
700
  return {
681
- description: description ?? `set(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
701
+ description: description != null ? description : `set(${item.description}; ${getArrayLikeCodecSizeDescription(size)})`,
682
702
  fixedSize: getArrayLikeCodecSizeFromChildren(size, [item.fixedSize]),
683
703
  maxSize: getArrayLikeCodecSizeFromChildren(size, [item.maxSize])
684
704
  };
685
705
  }
686
706
  function getSetEncoder(item, config = {}) {
687
- const size = config.size ?? getU32Encoder();
707
+ var _a;
708
+ const size = (_a = config.size) != null ? _a : getU32Encoder();
688
709
  return {
689
710
  ...setCodecHelper(item, size, config.description),
690
711
  encode: (set) => {
@@ -697,7 +718,8 @@ this.globalThis.solanaWeb3 = (function (exports) {
697
718
  };
698
719
  }
699
720
  function getSetDecoder(item, config = {}) {
700
- const size = config.size ?? getU32Decoder();
721
+ var _a;
722
+ const size = (_a = config.size) != null ? _a : getU32Decoder();
701
723
  return {
702
724
  ...setCodecHelper(item, size, config.description),
703
725
  decode: (bytes, offset = 0) => {
@@ -724,7 +746,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
724
746
  function structCodecHelper(fields, description) {
725
747
  const fieldDescriptions = fields.map(([name, codec]) => `${String(name)}: ${codec.description}`).join(", ");
726
748
  return {
727
- description: description ?? `struct(${fieldDescriptions})`,
749
+ description: description != null ? description : `struct(${fieldDescriptions})`,
728
750
  fixedSize: sumCodecSizes(fields.map(([, field]) => field.fixedSize)),
729
751
  maxSize: sumCodecSizes(fields.map(([, field]) => field.maxSize))
730
752
  };
@@ -760,7 +782,7 @@ this.globalThis.solanaWeb3 = (function (exports) {
760
782
  function tupleCodecHelper(items, description) {
761
783
  const itemDescriptions = items.map((item) => item.description).join(", ");
762
784
  return {
763
- description: description ?? `tuple(${itemDescriptions})`,
785
+ description: description != null ? description : `tuple(${itemDescriptions})`,
764
786
  fixedSize: sumCodecSizes(items.map((item) => item.fixedSize)),
765
787
  maxSize: sumCodecSizes(items.map((item) => item.maxSize))
766
788
  };
@@ -797,17 +819,19 @@ this.globalThis.solanaWeb3 = (function (exports) {
797
819
 
798
820
  // src/unit.ts
799
821
  function getUnitEncoder(config = {}) {
822
+ var _a;
800
823
  return {
801
- description: config.description ?? "unit",
824
+ description: (_a = config.description) != null ? _a : "unit",
802
825
  encode: () => new Uint8Array(),
803
826
  fixedSize: 0,
804
827
  maxSize: 0
805
828
  };
806
829
  }
807
830
  function getUnitDecoder(config = {}) {
831
+ var _a;
808
832
  return {
809
833
  decode: (_bytes, offset = 0) => [void 0, offset],
810
- description: config.description ?? "unit",
834
+ description: (_a = config.description) != null ? _a : "unit",
811
835
  fixedSize: 0,
812
836
  maxSize: 0
813
837
  };