@novasamatech/scale 0.8.0-1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/enum.d.ts CHANGED
@@ -1,7 +1,12 @@
1
1
  import type { Codec, StringRecord } from 'scale-ts';
2
2
  type FilterStringRecord<T extends Record<string, Codec<any>>> = T extends StringRecord<Codec<any>> ? T : never;
3
3
  export type EnumCodec<T extends Record<string, Codec<any>>> = ReturnType<typeof Enum<T>>;
4
- export declare const Enum: <T extends Record<string, Codec<any>>>(inner: T) => Codec<(FilterStringRecord<T> extends infer T_1 extends StringRecord<Codec<any>> ? { [K in keyof T_1]: {
4
+ /**
5
+ * Wraps scale-ts `Enum`. The optional `indexes` array pins each variant's
6
+ * serialization index positionally (i-th key gets `indexes[i]`), so the on-wire
7
+ * ABI no longer depends on declaration/iteration order.
8
+ */
9
+ export declare const Enum: <T extends Record<string, Codec<any>>>(inner: T, indexes?: number[]) => Codec<(FilterStringRecord<T> extends infer T_1 extends StringRecord<Codec<any>> ? { [K in keyof T_1]: {
5
10
  tag: K;
6
11
  value: import("scale-ts").CodecType<T_1[K]>;
7
12
  }; } : never)[keyof FilterStringRecord<T>]>;
package/dist/enum.js CHANGED
@@ -1,2 +1,7 @@
1
1
  import { Enum as ScaleEnum } from 'scale-ts';
2
- export const Enum = (inner) => ScaleEnum(inner);
2
+ /**
3
+ * Wraps scale-ts `Enum`. The optional `indexes` array pins each variant's
4
+ * serialization index positionally (i-th key gets `indexes[i]`), so the on-wire
5
+ * ABI no longer depends on declaration/iteration order.
6
+ */
7
+ export const Enum = (inner, indexes) => ScaleEnum(inner, indexes);
@@ -1,4 +1,7 @@
1
1
  /**
2
- * Optimized version of `Option(bool)`
2
+ * Optimized version of `Option(bool)`.
3
+ *
4
+ * Canonical SCALE encoding (matches `parity_scale_codec::OptionBool`):
5
+ * `undefined` → 0, `true` → 1, `false` → 2.
3
6
  */
4
7
  export declare const OptionBool: import("scale-ts").Codec<boolean | void>;
@@ -1,20 +1,23 @@
1
1
  import { enhanceCodec, u8 } from 'scale-ts';
2
2
  /**
3
- * Optimized version of `Option(bool)`
3
+ * Optimized version of `Option(bool)`.
4
+ *
5
+ * Canonical SCALE encoding (matches `parity_scale_codec::OptionBool`):
6
+ * `undefined` → 0, `true` → 1, `false` → 2.
4
7
  */
5
8
  export const OptionBool = enhanceCodec(u8, value => {
6
9
  if (value === undefined) {
7
10
  return 0;
8
11
  }
9
- return value ? 2 : 1;
12
+ return value ? 1 : 2;
10
13
  }, v => {
11
14
  switch (v) {
12
15
  case 0:
13
16
  return undefined;
14
17
  case 1:
15
- return false;
16
- case 2:
17
18
  return true;
19
+ case 2:
20
+ return false;
18
21
  default:
19
22
  throw new Error(`Unknown value for optionBool: ${v}. Should be ether 0, 1 or 2.`);
20
23
  }
@@ -3,11 +3,11 @@ import { OptionBool } from './optionBool.js';
3
3
  describe('OptionBool', () => {
4
4
  it('should correctly encode/decode OptionBool', () => {
5
5
  expect(OptionBool.enc(undefined)).toEqual(new Uint8Array([0]));
6
- expect(OptionBool.enc(false)).toEqual(new Uint8Array([1]));
7
- expect(OptionBool.enc(true)).toEqual(new Uint8Array([2]));
6
+ expect(OptionBool.enc(true)).toEqual(new Uint8Array([1]));
7
+ expect(OptionBool.enc(false)).toEqual(new Uint8Array([2]));
8
8
  expect(OptionBool.dec(new Uint8Array([0]))).toEqual(undefined);
9
- expect(OptionBool.dec(new Uint8Array([1]))).toEqual(false);
10
- expect(OptionBool.dec(new Uint8Array([2]))).toEqual(true);
9
+ expect(OptionBool.dec(new Uint8Array([1]))).toEqual(true);
10
+ expect(OptionBool.dec(new Uint8Array([2]))).toEqual(false);
11
11
  });
12
12
  it('should throw in bytes has incorrect value', () => {
13
13
  expect(() => OptionBool.dec(new Uint8Array([3]))).toThrowErrorMatchingInlineSnapshot(`[Error: Unknown value for optionBool: 3. Should be ether 0, 1 or 2.]`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@novasamatech/scale",
3
3
  "type": "module",
4
- "version": "0.8.0-1",
4
+ "version": "0.8.0",
5
5
  "description": "additional scale-ts bindings",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {