@haneullabs/bcs 2.0.2 → 2.1.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 CHANGED
@@ -1,5 +1,41 @@
1
1
  # Change Log
2
2
 
3
+ ## 2.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - bbf63cb: Updated dependencies
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [bbf63cb]
12
+ - @mysten/utils@0.4.0
13
+
14
+ ## 2.0.5
15
+
16
+ ### Patch Changes
17
+
18
+ - f7de3e5: Restore docs in published tarballs.
19
+ - Updated dependencies [f7de3e5]
20
+ - @mysten/utils@0.3.3
21
+
22
+ ## 2.0.4
23
+
24
+ ### Patch Changes
25
+
26
+ - 9e067cf: Validate the new per-package release flow end-to-end across every public @mysten package.
27
+ No functional changes — empty patch bump to force the orchestrator to dispatch every
28
+ release-<pkg>.yml workflow with `dry_run=false` so each package publishes via OIDC trusted
29
+ publishing.
30
+ - Updated dependencies [9e067cf]
31
+ - @mysten/utils@0.3.2
32
+
33
+ ## 2.0.3
34
+
35
+ ### Patch Changes
36
+
37
+ - 43e69f8: Add embedded LLM-friendly docs to published packages
38
+
3
39
  ## 2.0.2
4
40
 
5
41
  ### Patch Changes
package/README.md CHANGED
@@ -9,7 +9,7 @@ available in both Browser and NodeJS environments in a type-safe way.`
9
9
  To install, add the [`@haneullabs/bcs`](https://www.npmjs.com/package/@haneullabs/bcs) package to your
10
10
  project:
11
11
 
12
- ```sh npm2yarn
12
+ ```npm
13
13
  npm i @haneullabs/bcs
14
14
  ```
15
15
 
@@ -1 +1 @@
1
- {"version":3,"file":"bcs-type.d.mts","names":[],"sources":["../src/bcs-type.ts"],"sourcesContent":[],"mappings":";;;;;UAUiB,0BAA0B;EAA1B,IAAA,CAAA,EACT,IADS;EAA0B,QAAA,CAAA,EAAA,CAAA,KAAA,EAEvB,KAFuB,EAAA,GAAA,IAAA;;AAEvB,cAGP,O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W,OAAA,iBAAwB,CAAA,YAEtD,IAAA;;IAEc,MAAA;IAAQ,IAAA;IAAA,GAAS;EAAA,GAAW,eAAA,CAAgB,CAAA,EAAG,IAAA;AAAA"}
package/dist/bcs-type.mjs CHANGED
@@ -2,7 +2,6 @@ import { ulebEncode } from "./uleb.mjs";
2
2
  import { BcsReader } from "./reader.mjs";
3
3
  import { BcsWriter } from "./writer.mjs";
4
4
  import { fromBase58, fromBase64, fromHex, toBase58, toBase64, toHex } from "@haneullabs/utils";
5
-
6
5
  //#region src/bcs-type.ts
7
6
  var BcsType = class BcsType {
8
7
  #write;
@@ -12,10 +11,10 @@ var BcsType = class BcsType {
12
11
  this.read = options.read;
13
12
  this.serializedSize = options.serializedSize ?? (() => null);
14
13
  this.#write = options.write;
15
- this.#serialize = options.serialize ?? ((value, options$1) => {
14
+ this.#serialize = options.serialize ?? ((value, options) => {
16
15
  const writer = new BcsWriter({
17
16
  initialSize: this.serializedSize(value) ?? void 0,
18
- ...options$1
17
+ ...options
19
18
  });
20
19
  this.#write(value, writer);
21
20
  return writer.toBytes();
@@ -211,7 +210,7 @@ var BcsEnum = class extends BcsType {
211
210
  };
212
211
  },
213
212
  write: (value, writer) => {
214
- const [name, val] = Object.entries(value).filter(([name$1]) => Object.hasOwn(fields, name$1))[0];
213
+ const [name, val] = Object.entries(value).filter(([name]) => Object.hasOwn(fields, name))[0];
215
214
  for (let i = 0; i < canonicalOrder.length; i++) {
216
215
  const [optionName, optionType] = canonicalOrder[i];
217
216
  if (optionName === name) {
@@ -263,7 +262,7 @@ var BcsTuple = class extends BcsType {
263
262
  });
264
263
  }
265
264
  };
266
-
267
265
  //#endregion
268
266
  export { BcsEnum, BcsStruct, BcsTuple, BcsType, SerializedBcs, bigUIntBcsType, dynamicSizeBcsType, fixedSizeBcsType, isSerializedBcs, lazyBcsType, stringLikeBcsType, uIntBcsType };
267
+
269
268
  //# sourceMappingURL=bcs-type.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"bcs-type.mjs","names":["#write","#serialize","options","#schema","#bytes","name"],"sources":["../src/bcs-type.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase58, fromBase64, toBase58, toBase64, fromHex, toHex } from '@haneullabs/utils';\nimport { BcsReader } from './reader.js';\nimport { ulebEncode } from './uleb.js';\nimport type { BcsWriterOptions } from './writer.js';\nimport { BcsWriter } from './writer.js';\nimport type { EnumInputShape, EnumOutputShape, JoinString } from './types.js';\n\nexport interface BcsTypeOptions<T, Input = T, Name extends string = string> {\n\tname?: Name;\n\tvalidate?: (value: Input) => void;\n}\n\nexport class BcsType<T, Input = T, const Name extends string = string> {\n\t$inferType!: T;\n\t$inferInput!: Input;\n\tname: Name;\n\tread: (reader: BcsReader) => T;\n\tserializedSize: (value: Input, options?: BcsWriterOptions) => number | null;\n\tvalidate: (value: Input) => void;\n\t#write: (value: Input, writer: BcsWriter) => void;\n\t#serialize: (value: Input, options?: BcsWriterOptions) => Uint8Array<ArrayBuffer>;\n\n\tconstructor(\n\t\toptions: {\n\t\t\tname: Name;\n\t\t\tread: (reader: BcsReader) => T;\n\t\t\twrite: (value: Input, writer: BcsWriter) => void;\n\t\t\tserialize?: (value: Input, options?: BcsWriterOptions) => Uint8Array<ArrayBuffer>;\n\t\t\tserializedSize?: (value: Input) => number | null;\n\t\t\tvalidate?: (value: Input) => void;\n\t\t} & BcsTypeOptions<T, Input, Name>,\n\t) {\n\t\tthis.name = options.name;\n\t\tthis.read = options.read;\n\t\tthis.serializedSize = options.serializedSize ?? (() => null);\n\t\tthis.#write = options.write;\n\t\tthis.#serialize =\n\t\t\toptions.serialize ??\n\t\t\t((value, options) => {\n\t\t\t\tconst writer = new BcsWriter({\n\t\t\t\t\tinitialSize: this.serializedSize(value) ?? undefined,\n\t\t\t\t\t...options,\n\t\t\t\t});\n\t\t\t\tthis.#write(value, writer);\n\t\t\t\treturn writer.toBytes();\n\t\t\t});\n\n\t\tthis.validate = options.validate ?? (() => {});\n\t}\n\n\twrite(value: Input, writer: BcsWriter) {\n\t\tthis.validate(value);\n\t\tthis.#write(value, writer);\n\t}\n\n\tserialize(value: Input, options?: BcsWriterOptions) {\n\t\tthis.validate(value);\n\t\treturn new SerializedBcs(this, this.#serialize(value, options));\n\t}\n\n\tparse(bytes: Uint8Array): T {\n\t\tconst reader = new BcsReader(bytes);\n\t\treturn this.read(reader);\n\t}\n\n\tfromHex(hex: string) {\n\t\treturn this.parse(fromHex(hex));\n\t}\n\n\tfromBase58(b64: string) {\n\t\treturn this.parse(fromBase58(b64));\n\t}\n\n\tfromBase64(b64: string) {\n\t\treturn this.parse(fromBase64(b64));\n\t}\n\n\ttransform<T2 = T, Input2 = Input, NewName extends string = Name>({\n\t\tname,\n\t\tinput,\n\t\toutput,\n\t\tvalidate,\n\t}: {\n\t\tinput?: (val: Input2) => Input;\n\t\toutput?: (value: T) => T2;\n\t} & BcsTypeOptions<T2, Input2, NewName>) {\n\t\treturn new BcsType<T2, Input2, NewName>({\n\t\t\tname: (name ?? this.name) as NewName,\n\t\t\tread: (reader) => (output ? output(this.read(reader)) : (this.read(reader) as never)),\n\t\t\twrite: (value, writer) => this.#write(input ? input(value) : (value as never), writer),\n\t\t\tserializedSize: (value) => this.serializedSize(input ? input(value) : (value as never)),\n\t\t\tserialize: (value, options) =>\n\t\t\t\tthis.#serialize(input ? input(value) : (value as never), options),\n\t\t\tvalidate: (value) => {\n\t\t\t\tvalidate?.(value);\n\t\t\t\tthis.validate(input ? input(value) : (value as never));\n\t\t\t},\n\t\t});\n\t}\n}\n\nconst SERIALIZED_BCS_BRAND = Symbol.for('@haneullabs/serialized-bcs') as never;\nexport function isSerializedBcs(obj: unknown): obj is SerializedBcs<unknown> {\n\treturn !!obj && typeof obj === 'object' && (obj as any)[SERIALIZED_BCS_BRAND] === true;\n}\n\nexport class SerializedBcs<T, Input = T> {\n\t#schema: BcsType<T, Input>;\n\t#bytes: Uint8Array<ArrayBuffer>;\n\n\t// Used to brand SerializedBcs so that they can be identified, even between multiple copies\n\t// of the @haneullabs/bcs package are installed\n\tget [SERIALIZED_BCS_BRAND]() {\n\t\treturn true;\n\t}\n\n\tconstructor(schema: BcsType<T, Input>, bytes: Uint8Array<ArrayBuffer>) {\n\t\tthis.#schema = schema;\n\t\tthis.#bytes = bytes;\n\t}\n\n\ttoBytes() {\n\t\treturn this.#bytes;\n\t}\n\n\ttoHex() {\n\t\treturn toHex(this.#bytes);\n\t}\n\n\ttoBase64() {\n\t\treturn toBase64(this.#bytes);\n\t}\n\n\ttoBase58() {\n\t\treturn toBase58(this.#bytes);\n\t}\n\n\tparse() {\n\t\treturn this.#schema.parse(this.#bytes);\n\t}\n}\n\nexport function fixedSizeBcsType<T, Input = T, const Name extends string = string>({\n\tsize,\n\t...options\n}: {\n\tname: Name;\n\tsize: number;\n\tread: (reader: BcsReader) => T;\n\twrite: (value: Input, writer: BcsWriter) => void;\n} & BcsTypeOptions<T, Input, Name>) {\n\treturn new BcsType<T, Input, Name>({\n\t\t...options,\n\t\tserializedSize: () => size,\n\t});\n}\n\nexport function uIntBcsType<const Name extends string = string>({\n\treadMethod,\n\twriteMethod,\n\t...options\n}: {\n\tname: Name;\n\tsize: number;\n\treadMethod: `read${8 | 16 | 32}`;\n\twriteMethod: `write${8 | 16 | 32}`;\n\tmaxValue: number;\n} & BcsTypeOptions<number, number, Name>) {\n\treturn fixedSizeBcsType<number, number, Name>({\n\t\t...options,\n\t\tread: (reader) => reader[readMethod](),\n\t\twrite: (value, writer) => writer[writeMethod](value),\n\t\tvalidate: (value) => {\n\t\t\tif (value < 0 || value > options.maxValue) {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t`Invalid ${options.name} value: ${value}. Expected value in range 0-${options.maxValue}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\toptions.validate?.(value);\n\t\t},\n\t});\n}\n\nexport function bigUIntBcsType<const Name extends string = string>({\n\treadMethod,\n\twriteMethod,\n\t...options\n}: {\n\tname: Name;\n\tsize: number;\n\treadMethod: `read${64 | 128 | 256}`;\n\twriteMethod: `write${64 | 128 | 256}`;\n\tmaxValue: bigint;\n} & BcsTypeOptions<string, string | number | bigint>) {\n\treturn fixedSizeBcsType<string, string | number | bigint, Name>({\n\t\t...options,\n\t\tread: (reader) => reader[readMethod](),\n\t\twrite: (value, writer) => writer[writeMethod](BigInt(value)),\n\t\tvalidate: (val) => {\n\t\t\tconst value = BigInt(val);\n\t\t\tif (value < 0 || value > options.maxValue) {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t`Invalid ${options.name} value: ${value}. Expected value in range 0-${options.maxValue}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\toptions.validate?.(value);\n\t\t},\n\t});\n}\n\nexport function dynamicSizeBcsType<T, Input = T, const Name extends string = string>({\n\tserialize,\n\t...options\n}: {\n\tname: Name;\n\tread: (reader: BcsReader) => T;\n\tserialize: (value: Input, options?: BcsWriterOptions) => Uint8Array<ArrayBuffer>;\n} & BcsTypeOptions<T, Input>) {\n\tconst type = new BcsType<T, Input>({\n\t\t...options,\n\t\tserialize,\n\t\twrite: (value, writer) => {\n\t\t\tfor (const byte of type.serialize(value).toBytes()) {\n\t\t\t\twriter.write8(byte);\n\t\t\t}\n\t\t},\n\t});\n\n\treturn type;\n}\n\nexport function stringLikeBcsType<const Name extends string = string>({\n\ttoBytes,\n\tfromBytes,\n\t...options\n}: {\n\tname: Name;\n\ttoBytes: (value: string) => Uint8Array;\n\tfromBytes: (bytes: Uint8Array) => string;\n\tserializedSize?: (value: string) => number | null;\n} & BcsTypeOptions<string, string, Name>) {\n\treturn new BcsType<string, string, Name>({\n\t\t...options,\n\t\tread: (reader) => {\n\t\t\tconst length = reader.readULEB();\n\t\t\tconst bytes = reader.readBytes(length);\n\n\t\t\treturn fromBytes(bytes);\n\t\t},\n\t\twrite: (hex, writer) => {\n\t\t\tconst bytes = toBytes(hex);\n\t\t\twriter.writeULEB(bytes.length);\n\t\t\tfor (let i = 0; i < bytes.length; i++) {\n\t\t\t\twriter.write8(bytes[i]);\n\t\t\t}\n\t\t},\n\t\tserialize: (value) => {\n\t\t\tconst bytes = toBytes(value);\n\t\t\tconst size = ulebEncode(bytes.length);\n\t\t\tconst result = new Uint8Array(size.length + bytes.length);\n\t\t\tresult.set(size, 0);\n\t\t\tresult.set(bytes, size.length);\n\n\t\t\treturn result;\n\t\t},\n\t\tvalidate: (value) => {\n\t\t\tif (typeof value !== 'string') {\n\t\t\t\tthrow new TypeError(`Invalid ${options.name} value: ${value}. Expected string`);\n\t\t\t}\n\t\t\toptions.validate?.(value);\n\t\t},\n\t});\n}\n\nexport function lazyBcsType<T, Input>(cb: () => BcsType<T, Input>) {\n\tlet lazyType: BcsType<T, Input> | null = null;\n\tfunction getType() {\n\t\tif (!lazyType) {\n\t\t\tlazyType = cb();\n\t\t}\n\t\treturn lazyType;\n\t}\n\n\treturn new BcsType<T, Input>({\n\t\tname: 'lazy' as never,\n\t\tread: (data) => getType().read(data),\n\t\tserializedSize: (value) => getType().serializedSize(value),\n\t\twrite: (value, writer) => getType().write(value, writer),\n\t\tserialize: (value, options) => getType().serialize(value, options).toBytes(),\n\t});\n}\n\nexport interface BcsStructOptions<\n\tT extends Record<string, BcsType<any>>,\n\tName extends string = string,\n> extends Omit<\n\tBcsTypeOptions<\n\t\t{\n\t\t\t[K in keyof T]: T[K] extends BcsType<infer U, any> ? U : never;\n\t\t},\n\t\t{\n\t\t\t[K in keyof T]: T[K] extends BcsType<any, infer U> ? U : never;\n\t\t},\n\t\tName\n\t>,\n\t'name'\n> {\n\tname: Name;\n\tfields: T;\n}\n\nexport class BcsStruct<\n\tT extends Record<string, BcsType<any>>,\n\tconst Name extends string = string,\n> extends BcsType<\n\t{\n\t\t[K in keyof T]: T[K] extends BcsType<infer U, any> ? U : never;\n\t},\n\t{\n\t\t[K in keyof T]: T[K] extends BcsType<any, infer U> ? U : never;\n\t},\n\tName\n> {\n\tconstructor({ name, fields, ...options }: BcsStructOptions<T, Name>) {\n\t\tconst canonicalOrder = Object.entries(fields);\n\n\t\tsuper({\n\t\t\tname,\n\t\t\tserializedSize: (values) => {\n\t\t\t\tlet total = 0;\n\t\t\t\tfor (const [field, type] of canonicalOrder) {\n\t\t\t\t\tconst size = type.serializedSize(values[field]);\n\t\t\t\t\tif (size == null) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\n\t\t\t\t\ttotal += size;\n\t\t\t\t}\n\n\t\t\t\treturn total;\n\t\t\t},\n\t\t\tread: (reader) => {\n\t\t\t\tconst result: Record<string, unknown> = {};\n\t\t\t\tfor (const [field, type] of canonicalOrder) {\n\t\t\t\t\tresult[field] = type.read(reader);\n\t\t\t\t}\n\n\t\t\t\treturn result as never;\n\t\t\t},\n\t\t\twrite: (value, writer) => {\n\t\t\t\tfor (const [field, type] of canonicalOrder) {\n\t\t\t\t\ttype.write(value[field], writer);\n\t\t\t\t}\n\t\t\t},\n\t\t\t...options,\n\t\t\tvalidate: (value) => {\n\t\t\t\toptions?.validate?.(value);\n\t\t\t\tif (typeof value !== 'object' || value == null) {\n\t\t\t\t\tthrow new TypeError(`Expected object, found ${typeof value}`);\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\t}\n}\n\nexport interface BcsEnumOptions<\n\tT extends Record<string, BcsType<any> | null>,\n\tName extends string = string,\n> extends Omit<\n\tBcsTypeOptions<\n\t\tEnumOutputShape<{\n\t\t\t[K in keyof T]: T[K] extends BcsType<infer U, any, any> ? U : true;\n\t\t}>,\n\t\tEnumInputShape<{\n\t\t\t[K in keyof T]: T[K] extends BcsType<any, infer U, any> ? U : boolean | object | null;\n\t\t}>,\n\t\tName\n\t>,\n\t'name'\n> {\n\tname: Name;\n\tfields: T;\n}\n\nexport class BcsEnum<\n\tT extends Record<string, BcsType<any> | null>,\n\tconst Name extends string = string,\n> extends BcsType<\n\tEnumOutputShape<{\n\t\t[K in keyof T]: T[K] extends BcsType<infer U, any> ? U : true;\n\t}>,\n\tEnumInputShape<{\n\t\t[K in keyof T]: T[K] extends BcsType<any, infer U, any> ? U : boolean | object | null;\n\t}>,\n\tName\n> {\n\tconstructor({ fields, ...options }: BcsEnumOptions<T, Name>) {\n\t\tconst canonicalOrder = Object.entries(fields as object);\n\t\tsuper({\n\t\t\tread: (reader) => {\n\t\t\t\tconst index = reader.readULEB();\n\n\t\t\t\tconst enumEntry = canonicalOrder[index];\n\t\t\t\tif (!enumEntry) {\n\t\t\t\t\tthrow new TypeError(`Unknown value ${index} for enum ${options.name}`);\n\t\t\t\t}\n\n\t\t\t\tconst [kind, type] = enumEntry;\n\n\t\t\t\treturn {\n\t\t\t\t\t[kind]: type?.read(reader) ?? true,\n\t\t\t\t\t$kind: kind,\n\t\t\t\t} as never;\n\t\t\t},\n\t\t\twrite: (value, writer) => {\n\t\t\t\tconst [name, val] = Object.entries(value).filter(([name]) =>\n\t\t\t\t\tObject.hasOwn(fields, name),\n\t\t\t\t)[0];\n\n\t\t\t\tfor (let i = 0; i < canonicalOrder.length; i++) {\n\t\t\t\t\tconst [optionName, optionType] = canonicalOrder[i];\n\t\t\t\t\tif (optionName === name) {\n\t\t\t\t\t\twriter.writeULEB(i);\n\t\t\t\t\t\toptionType?.write(val, writer);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\t...options,\n\t\t\tvalidate: (value) => {\n\t\t\t\toptions?.validate?.(value);\n\t\t\t\tif (typeof value !== 'object' || value == null) {\n\t\t\t\t\tthrow new TypeError(`Expected object, found ${typeof value}`);\n\t\t\t\t}\n\n\t\t\t\tconst keys = Object.keys(value).filter(\n\t\t\t\t\t(k) => value[k] !== undefined && Object.hasOwn(fields, k),\n\t\t\t\t);\n\n\t\t\t\tif (keys.length !== 1) {\n\t\t\t\t\tthrow new TypeError(\n\t\t\t\t\t\t`Expected object with one key, but found ${keys.length} for type ${options.name}}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst [variant] = keys;\n\n\t\t\t\tif (!Object.hasOwn(fields, variant)) {\n\t\t\t\t\tthrow new TypeError(`Invalid enum variant ${variant}`);\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\t}\n}\n\nexport interface BcsTupleOptions<\n\tT extends readonly BcsType<any>[],\n\tName extends string,\n> extends Omit<\n\tBcsTypeOptions<\n\t\t{\n\t\t\t-readonly [K in keyof T]: T[K] extends BcsType<infer T, any> ? T : never;\n\t\t},\n\t\t{\n\t\t\t[K in keyof T]: T[K] extends BcsType<any, infer T> ? T : never;\n\t\t},\n\t\tName\n\t>,\n\t'name'\n> {\n\tname?: Name;\n\tfields: T;\n}\n\nexport class BcsTuple<\n\tconst T extends readonly BcsType<any>[],\n\tconst Name extends string =\n\t\t`(${JoinString<{ [K in keyof T]: T[K] extends BcsType<any, any, infer T> ? T : never }, ', '>})`,\n> extends BcsType<\n\t{\n\t\t-readonly [K in keyof T]: T[K] extends BcsType<infer T, any> ? T : never;\n\t},\n\t{\n\t\t[K in keyof T]: T[K] extends BcsType<any, infer T> ? T : never;\n\t},\n\tName\n> {\n\tconstructor({ fields, name, ...options }: BcsTupleOptions<T, Name>) {\n\t\tsuper({\n\t\t\tname: name ?? (`(${fields.map((t) => t.name).join(', ')})` as never),\n\t\t\tserializedSize: (values) => {\n\t\t\t\tlet total = 0;\n\t\t\t\tfor (let i = 0; i < fields.length; i++) {\n\t\t\t\t\tconst size = fields[i].serializedSize(values[i]);\n\t\t\t\t\tif (size == null) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\n\t\t\t\t\ttotal += size;\n\t\t\t\t}\n\n\t\t\t\treturn total;\n\t\t\t},\n\t\t\tread: (reader) => {\n\t\t\t\tconst result: unknown[] = [];\n\t\t\t\tfor (const field of fields) {\n\t\t\t\t\tresult.push(field.read(reader));\n\t\t\t\t}\n\t\t\t\treturn result as never;\n\t\t\t},\n\t\t\twrite: (value, writer) => {\n\t\t\t\tfor (let i = 0; i < fields.length; i++) {\n\t\t\t\t\tfields[i].write(value[i], writer);\n\t\t\t\t}\n\t\t\t},\n\t\t\t...options,\n\t\t\tvalidate: (value) => {\n\t\t\t\toptions?.validate?.(value);\n\t\t\t\tif (!Array.isArray(value)) {\n\t\t\t\t\tthrow new TypeError(`Expected array, found ${typeof value}`);\n\t\t\t\t}\n\t\t\t\tif (value.length !== fields.length) {\n\t\t\t\t\tthrow new TypeError(`Expected array of length ${fields.length}, found ${value.length}`);\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;AAeA,IAAa,UAAb,MAAa,QAA0D;CAOtE;CACA;CAEA,YACC,SAQC;AACD,OAAK,OAAO,QAAQ;AACpB,OAAK,OAAO,QAAQ;AACpB,OAAK,iBAAiB,QAAQ,yBAAyB;AACvD,QAAKA,QAAS,QAAQ;AACtB,QAAKC,YACJ,QAAQ,eACN,OAAO,cAAY;GACpB,MAAM,SAAS,IAAI,UAAU;IAC5B,aAAa,KAAK,eAAe,MAAM,IAAI;IAC3C,GAAGC;IACH,CAAC;AACF,SAAKF,MAAO,OAAO,OAAO;AAC1B,UAAO,OAAO,SAAS;;AAGzB,OAAK,WAAW,QAAQ,mBAAmB;;CAG5C,MAAM,OAAc,QAAmB;AACtC,OAAK,SAAS,MAAM;AACpB,QAAKA,MAAO,OAAO,OAAO;;CAG3B,UAAU,OAAc,SAA4B;AACnD,OAAK,SAAS,MAAM;AACpB,SAAO,IAAI,cAAc,MAAM,MAAKC,UAAW,OAAO,QAAQ,CAAC;;CAGhE,MAAM,OAAsB;EAC3B,MAAM,SAAS,IAAI,UAAU,MAAM;AACnC,SAAO,KAAK,KAAK,OAAO;;CAGzB,QAAQ,KAAa;AACpB,SAAO,KAAK,MAAM,QAAQ,IAAI,CAAC;;CAGhC,WAAW,KAAa;AACvB,SAAO,KAAK,MAAM,WAAW,IAAI,CAAC;;CAGnC,WAAW,KAAa;AACvB,SAAO,KAAK,MAAM,WAAW,IAAI,CAAC;;CAGnC,UAAiE,EAChE,MACA,OACA,QACA,YAIwC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,UAAU;;GAGxD,CAAC;;;AAuBJ,IAAa,WAAb,cAIU,QAQR;CACD,YAAY,EAAE,QAAQ,MAAM,GAAG,WAAqC;AACnE,QAAM;GACL,MAAM,QAAS,IAAI,OAAO,KAAK,MAAM,EAAE,KAAK,CAAC,KAAK,KAAK,CAAC;GACxD,iBAAiB,WAAW;IAC3B,IAAI,QAAQ;AACZ,SAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;KACvC,MAAM,OAAO,OAAO,GAAG,eAAe,OAAO,GAAG;AAChD,SAAI,QAAQ,KACX,QAAO;AAGR,cAAS;;AAGV,WAAO;;GAER,OAAO,WAAW;IACjB,MAAM,SAAoB,EAAE;AAC5B,SAAK,MAAM,SAAS,OACnB,QAAO,KAAK,MAAM,KAAK,OAAO,CAAC;AAEhC,WAAO;;GAER,QAAQ,OAAO,WAAW;AACzB,SAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,IAClC,QAAO,GAAG,MAAM,MAAM,IAAI,OAAO;;GAGnC,GAAG;GACH,WAAW,UAAU;AACpB,aAAS,WAAW,MAAM;AAC1B,QAAI,CAAC,MAAM,QAAQ,MAAM,CACxB,OAAM,IAAI,UAAU,yBAAyB,OAAO,QAAQ;AAE7D,QAAI,MAAM,WAAW,OAAO,OAC3B,OAAM,IAAI,UAAU,4BAA4B,OAAO,OAAO,UAAU,MAAM,SAAS;;GAGzF,CAAC"}
1
+ {"version":3,"file":"bcs-type.mjs","names":["#write","#serialize","#schema","#bytes"],"sources":["../src/bcs-type.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { fromBase58, fromBase64, toBase58, toBase64, fromHex, toHex } from '@haneullabs/utils';\nimport { BcsReader } from './reader.js';\nimport { ulebEncode } from './uleb.js';\nimport type { BcsWriterOptions } from './writer.js';\nimport { BcsWriter } from './writer.js';\nimport type { EnumInputShape, EnumOutputShape, JoinString } from './types.js';\n\nexport interface BcsTypeOptions<T, Input = T, Name extends string = string> {\n\tname?: Name;\n\tvalidate?: (value: Input) => void;\n}\n\nexport class BcsType<T, Input = T, const Name extends string = string> {\n\t$inferType!: T;\n\t$inferInput!: Input;\n\tname: Name;\n\tread: (reader: BcsReader) => T;\n\tserializedSize: (value: Input, options?: BcsWriterOptions) => number | null;\n\tvalidate: (value: Input) => void;\n\t#write: (value: Input, writer: BcsWriter) => void;\n\t#serialize: (value: Input, options?: BcsWriterOptions) => Uint8Array<ArrayBuffer>;\n\n\tconstructor(\n\t\toptions: {\n\t\t\tname: Name;\n\t\t\tread: (reader: BcsReader) => T;\n\t\t\twrite: (value: Input, writer: BcsWriter) => void;\n\t\t\tserialize?: (value: Input, options?: BcsWriterOptions) => Uint8Array<ArrayBuffer>;\n\t\t\tserializedSize?: (value: Input) => number | null;\n\t\t\tvalidate?: (value: Input) => void;\n\t\t} & BcsTypeOptions<T, Input, Name>,\n\t) {\n\t\tthis.name = options.name;\n\t\tthis.read = options.read;\n\t\tthis.serializedSize = options.serializedSize ?? (() => null);\n\t\tthis.#write = options.write;\n\t\tthis.#serialize =\n\t\t\toptions.serialize ??\n\t\t\t((value, options) => {\n\t\t\t\tconst writer = new BcsWriter({\n\t\t\t\t\tinitialSize: this.serializedSize(value) ?? undefined,\n\t\t\t\t\t...options,\n\t\t\t\t});\n\t\t\t\tthis.#write(value, writer);\n\t\t\t\treturn writer.toBytes();\n\t\t\t});\n\n\t\tthis.validate = options.validate ?? (() => {});\n\t}\n\n\twrite(value: Input, writer: BcsWriter) {\n\t\tthis.validate(value);\n\t\tthis.#write(value, writer);\n\t}\n\n\tserialize(value: Input, options?: BcsWriterOptions) {\n\t\tthis.validate(value);\n\t\treturn new SerializedBcs(this, this.#serialize(value, options));\n\t}\n\n\tparse(bytes: Uint8Array): T {\n\t\tconst reader = new BcsReader(bytes);\n\t\treturn this.read(reader);\n\t}\n\n\tfromHex(hex: string) {\n\t\treturn this.parse(fromHex(hex));\n\t}\n\n\tfromBase58(b64: string) {\n\t\treturn this.parse(fromBase58(b64));\n\t}\n\n\tfromBase64(b64: string) {\n\t\treturn this.parse(fromBase64(b64));\n\t}\n\n\ttransform<T2 = T, Input2 = Input, NewName extends string = Name>({\n\t\tname,\n\t\tinput,\n\t\toutput,\n\t\tvalidate,\n\t}: {\n\t\tinput?: (val: Input2) => Input;\n\t\toutput?: (value: T) => T2;\n\t} & BcsTypeOptions<T2, Input2, NewName>) {\n\t\treturn new BcsType<T2, Input2, NewName>({\n\t\t\tname: (name ?? this.name) as NewName,\n\t\t\tread: (reader) => (output ? output(this.read(reader)) : (this.read(reader) as never)),\n\t\t\twrite: (value, writer) => this.#write(input ? input(value) : (value as never), writer),\n\t\t\tserializedSize: (value) => this.serializedSize(input ? input(value) : (value as never)),\n\t\t\tserialize: (value, options) =>\n\t\t\t\tthis.#serialize(input ? input(value) : (value as never), options),\n\t\t\tvalidate: (value) => {\n\t\t\t\tvalidate?.(value);\n\t\t\t\tthis.validate(input ? input(value) : (value as never));\n\t\t\t},\n\t\t});\n\t}\n}\n\nconst SERIALIZED_BCS_BRAND = Symbol.for('@haneullabs/serialized-bcs') as never;\nexport function isSerializedBcs(obj: unknown): obj is SerializedBcs<unknown> {\n\treturn !!obj && typeof obj === 'object' && (obj as any)[SERIALIZED_BCS_BRAND] === true;\n}\n\nexport class SerializedBcs<T, Input = T> {\n\t#schema: BcsType<T, Input>;\n\t#bytes: Uint8Array<ArrayBuffer>;\n\n\t// Used to brand SerializedBcs so that they can be identified, even between multiple copies\n\t// of the @haneullabs/bcs package are installed\n\tget [SERIALIZED_BCS_BRAND]() {\n\t\treturn true;\n\t}\n\n\tconstructor(schema: BcsType<T, Input>, bytes: Uint8Array<ArrayBuffer>) {\n\t\tthis.#schema = schema;\n\t\tthis.#bytes = bytes;\n\t}\n\n\ttoBytes() {\n\t\treturn this.#bytes;\n\t}\n\n\ttoHex() {\n\t\treturn toHex(this.#bytes);\n\t}\n\n\ttoBase64() {\n\t\treturn toBase64(this.#bytes);\n\t}\n\n\ttoBase58() {\n\t\treturn toBase58(this.#bytes);\n\t}\n\n\tparse() {\n\t\treturn this.#schema.parse(this.#bytes);\n\t}\n}\n\nexport function fixedSizeBcsType<T, Input = T, const Name extends string = string>({\n\tsize,\n\t...options\n}: {\n\tname: Name;\n\tsize: number;\n\tread: (reader: BcsReader) => T;\n\twrite: (value: Input, writer: BcsWriter) => void;\n} & BcsTypeOptions<T, Input, Name>) {\n\treturn new BcsType<T, Input, Name>({\n\t\t...options,\n\t\tserializedSize: () => size,\n\t});\n}\n\nexport function uIntBcsType<const Name extends string = string>({\n\treadMethod,\n\twriteMethod,\n\t...options\n}: {\n\tname: Name;\n\tsize: number;\n\treadMethod: `read${8 | 16 | 32}`;\n\twriteMethod: `write${8 | 16 | 32}`;\n\tmaxValue: number;\n} & BcsTypeOptions<number, number, Name>) {\n\treturn fixedSizeBcsType<number, number, Name>({\n\t\t...options,\n\t\tread: (reader) => reader[readMethod](),\n\t\twrite: (value, writer) => writer[writeMethod](value),\n\t\tvalidate: (value) => {\n\t\t\tif (value < 0 || value > options.maxValue) {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t`Invalid ${options.name} value: ${value}. Expected value in range 0-${options.maxValue}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\toptions.validate?.(value);\n\t\t},\n\t});\n}\n\nexport function bigUIntBcsType<const Name extends string = string>({\n\treadMethod,\n\twriteMethod,\n\t...options\n}: {\n\tname: Name;\n\tsize: number;\n\treadMethod: `read${64 | 128 | 256}`;\n\twriteMethod: `write${64 | 128 | 256}`;\n\tmaxValue: bigint;\n} & BcsTypeOptions<string, string | number | bigint>) {\n\treturn fixedSizeBcsType<string, string | number | bigint, Name>({\n\t\t...options,\n\t\tread: (reader) => reader[readMethod](),\n\t\twrite: (value, writer) => writer[writeMethod](BigInt(value)),\n\t\tvalidate: (val) => {\n\t\t\tconst value = BigInt(val);\n\t\t\tif (value < 0 || value > options.maxValue) {\n\t\t\t\tthrow new TypeError(\n\t\t\t\t\t`Invalid ${options.name} value: ${value}. Expected value in range 0-${options.maxValue}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\toptions.validate?.(value);\n\t\t},\n\t});\n}\n\nexport function dynamicSizeBcsType<T, Input = T, const Name extends string = string>({\n\tserialize,\n\t...options\n}: {\n\tname: Name;\n\tread: (reader: BcsReader) => T;\n\tserialize: (value: Input, options?: BcsWriterOptions) => Uint8Array<ArrayBuffer>;\n} & BcsTypeOptions<T, Input>) {\n\tconst type = new BcsType<T, Input>({\n\t\t...options,\n\t\tserialize,\n\t\twrite: (value, writer) => {\n\t\t\tfor (const byte of type.serialize(value).toBytes()) {\n\t\t\t\twriter.write8(byte);\n\t\t\t}\n\t\t},\n\t});\n\n\treturn type;\n}\n\nexport function stringLikeBcsType<const Name extends string = string>({\n\ttoBytes,\n\tfromBytes,\n\t...options\n}: {\n\tname: Name;\n\ttoBytes: (value: string) => Uint8Array;\n\tfromBytes: (bytes: Uint8Array) => string;\n\tserializedSize?: (value: string) => number | null;\n} & BcsTypeOptions<string, string, Name>) {\n\treturn new BcsType<string, string, Name>({\n\t\t...options,\n\t\tread: (reader) => {\n\t\t\tconst length = reader.readULEB();\n\t\t\tconst bytes = reader.readBytes(length);\n\n\t\t\treturn fromBytes(bytes);\n\t\t},\n\t\twrite: (hex, writer) => {\n\t\t\tconst bytes = toBytes(hex);\n\t\t\twriter.writeULEB(bytes.length);\n\t\t\tfor (let i = 0; i < bytes.length; i++) {\n\t\t\t\twriter.write8(bytes[i]);\n\t\t\t}\n\t\t},\n\t\tserialize: (value) => {\n\t\t\tconst bytes = toBytes(value);\n\t\t\tconst size = ulebEncode(bytes.length);\n\t\t\tconst result = new Uint8Array(size.length + bytes.length);\n\t\t\tresult.set(size, 0);\n\t\t\tresult.set(bytes, size.length);\n\n\t\t\treturn result;\n\t\t},\n\t\tvalidate: (value) => {\n\t\t\tif (typeof value !== 'string') {\n\t\t\t\tthrow new TypeError(`Invalid ${options.name} value: ${value}. Expected string`);\n\t\t\t}\n\t\t\toptions.validate?.(value);\n\t\t},\n\t});\n}\n\nexport function lazyBcsType<T, Input>(cb: () => BcsType<T, Input>) {\n\tlet lazyType: BcsType<T, Input> | null = null;\n\tfunction getType() {\n\t\tif (!lazyType) {\n\t\t\tlazyType = cb();\n\t\t}\n\t\treturn lazyType;\n\t}\n\n\treturn new BcsType<T, Input>({\n\t\tname: 'lazy' as never,\n\t\tread: (data) => getType().read(data),\n\t\tserializedSize: (value) => getType().serializedSize(value),\n\t\twrite: (value, writer) => getType().write(value, writer),\n\t\tserialize: (value, options) => getType().serialize(value, options).toBytes(),\n\t});\n}\n\nexport interface BcsStructOptions<\n\tT extends Record<string, BcsType<any>>,\n\tName extends string = string,\n> extends Omit<\n\tBcsTypeOptions<\n\t\t{\n\t\t\t[K in keyof T]: T[K] extends BcsType<infer U, any> ? U : never;\n\t\t},\n\t\t{\n\t\t\t[K in keyof T]: T[K] extends BcsType<any, infer U> ? U : never;\n\t\t},\n\t\tName\n\t>,\n\t'name'\n> {\n\tname: Name;\n\tfields: T;\n}\n\nexport class BcsStruct<\n\tT extends Record<string, BcsType<any>>,\n\tconst Name extends string = string,\n> extends BcsType<\n\t{\n\t\t[K in keyof T]: T[K] extends BcsType<infer U, any> ? U : never;\n\t},\n\t{\n\t\t[K in keyof T]: T[K] extends BcsType<any, infer U> ? U : never;\n\t},\n\tName\n> {\n\tconstructor({ name, fields, ...options }: BcsStructOptions<T, Name>) {\n\t\tconst canonicalOrder = Object.entries(fields);\n\n\t\tsuper({\n\t\t\tname,\n\t\t\tserializedSize: (values) => {\n\t\t\t\tlet total = 0;\n\t\t\t\tfor (const [field, type] of canonicalOrder) {\n\t\t\t\t\tconst size = type.serializedSize(values[field]);\n\t\t\t\t\tif (size == null) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\n\t\t\t\t\ttotal += size;\n\t\t\t\t}\n\n\t\t\t\treturn total;\n\t\t\t},\n\t\t\tread: (reader) => {\n\t\t\t\tconst result: Record<string, unknown> = {};\n\t\t\t\tfor (const [field, type] of canonicalOrder) {\n\t\t\t\t\tresult[field] = type.read(reader);\n\t\t\t\t}\n\n\t\t\t\treturn result as never;\n\t\t\t},\n\t\t\twrite: (value, writer) => {\n\t\t\t\tfor (const [field, type] of canonicalOrder) {\n\t\t\t\t\ttype.write(value[field], writer);\n\t\t\t\t}\n\t\t\t},\n\t\t\t...options,\n\t\t\tvalidate: (value) => {\n\t\t\t\toptions?.validate?.(value);\n\t\t\t\tif (typeof value !== 'object' || value == null) {\n\t\t\t\t\tthrow new TypeError(`Expected object, found ${typeof value}`);\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\t}\n}\n\nexport interface BcsEnumOptions<\n\tT extends Record<string, BcsType<any> | null>,\n\tName extends string = string,\n> extends Omit<\n\tBcsTypeOptions<\n\t\tEnumOutputShape<{\n\t\t\t[K in keyof T]: T[K] extends BcsType<infer U, any, any> ? U : true;\n\t\t}>,\n\t\tEnumInputShape<{\n\t\t\t[K in keyof T]: T[K] extends BcsType<any, infer U, any> ? U : boolean | object | null;\n\t\t}>,\n\t\tName\n\t>,\n\t'name'\n> {\n\tname: Name;\n\tfields: T;\n}\n\nexport class BcsEnum<\n\tT extends Record<string, BcsType<any> | null>,\n\tconst Name extends string = string,\n> extends BcsType<\n\tEnumOutputShape<{\n\t\t[K in keyof T]: T[K] extends BcsType<infer U, any> ? U : true;\n\t}>,\n\tEnumInputShape<{\n\t\t[K in keyof T]: T[K] extends BcsType<any, infer U, any> ? U : boolean | object | null;\n\t}>,\n\tName\n> {\n\tconstructor({ fields, ...options }: BcsEnumOptions<T, Name>) {\n\t\tconst canonicalOrder = Object.entries(fields as object);\n\t\tsuper({\n\t\t\tread: (reader) => {\n\t\t\t\tconst index = reader.readULEB();\n\n\t\t\t\tconst enumEntry = canonicalOrder[index];\n\t\t\t\tif (!enumEntry) {\n\t\t\t\t\tthrow new TypeError(`Unknown value ${index} for enum ${options.name}`);\n\t\t\t\t}\n\n\t\t\t\tconst [kind, type] = enumEntry;\n\n\t\t\t\treturn {\n\t\t\t\t\t[kind]: type?.read(reader) ?? true,\n\t\t\t\t\t$kind: kind,\n\t\t\t\t} as never;\n\t\t\t},\n\t\t\twrite: (value, writer) => {\n\t\t\t\tconst [name, val] = Object.entries(value).filter(([name]) =>\n\t\t\t\t\tObject.hasOwn(fields, name),\n\t\t\t\t)[0];\n\n\t\t\t\tfor (let i = 0; i < canonicalOrder.length; i++) {\n\t\t\t\t\tconst [optionName, optionType] = canonicalOrder[i];\n\t\t\t\t\tif (optionName === name) {\n\t\t\t\t\t\twriter.writeULEB(i);\n\t\t\t\t\t\toptionType?.write(val, writer);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\t...options,\n\t\t\tvalidate: (value) => {\n\t\t\t\toptions?.validate?.(value);\n\t\t\t\tif (typeof value !== 'object' || value == null) {\n\t\t\t\t\tthrow new TypeError(`Expected object, found ${typeof value}`);\n\t\t\t\t}\n\n\t\t\t\tconst keys = Object.keys(value).filter(\n\t\t\t\t\t(k) => value[k] !== undefined && Object.hasOwn(fields, k),\n\t\t\t\t);\n\n\t\t\t\tif (keys.length !== 1) {\n\t\t\t\t\tthrow new TypeError(\n\t\t\t\t\t\t`Expected object with one key, but found ${keys.length} for type ${options.name}}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tconst [variant] = keys;\n\n\t\t\t\tif (!Object.hasOwn(fields, variant)) {\n\t\t\t\t\tthrow new TypeError(`Invalid enum variant ${variant}`);\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\t}\n}\n\nexport interface BcsTupleOptions<\n\tT extends readonly BcsType<any>[],\n\tName extends string,\n> extends Omit<\n\tBcsTypeOptions<\n\t\t{\n\t\t\t-readonly [K in keyof T]: T[K] extends BcsType<infer T, any> ? T : never;\n\t\t},\n\t\t{\n\t\t\t[K in keyof T]: T[K] extends BcsType<any, infer T> ? T : never;\n\t\t},\n\t\tName\n\t>,\n\t'name'\n> {\n\tname?: Name;\n\tfields: T;\n}\n\nexport class BcsTuple<\n\tconst T extends readonly BcsType<any>[],\n\tconst Name extends string =\n\t\t`(${JoinString<{ [K in keyof T]: T[K] extends BcsType<any, any, infer T> ? T : never }, ', '>})`,\n> extends BcsType<\n\t{\n\t\t-readonly [K in keyof T]: T[K] extends BcsType<infer T, any> ? T : never;\n\t},\n\t{\n\t\t[K in keyof T]: T[K] extends BcsType<any, infer T> ? T : never;\n\t},\n\tName\n> {\n\tconstructor({ fields, name, ...options }: BcsTupleOptions<T, Name>) {\n\t\tsuper({\n\t\t\tname: name ?? (`(${fields.map((t) => t.name).join(', ')})` as never),\n\t\t\tserializedSize: (values) => {\n\t\t\t\tlet total = 0;\n\t\t\t\tfor (let i = 0; i < fields.length; i++) {\n\t\t\t\t\tconst size = fields[i].serializedSize(values[i]);\n\t\t\t\t\tif (size == null) {\n\t\t\t\t\t\treturn null;\n\t\t\t\t\t}\n\n\t\t\t\t\ttotal += size;\n\t\t\t\t}\n\n\t\t\t\treturn total;\n\t\t\t},\n\t\t\tread: (reader) => {\n\t\t\t\tconst result: unknown[] = [];\n\t\t\t\tfor (const field of fields) {\n\t\t\t\t\tresult.push(field.read(reader));\n\t\t\t\t}\n\t\t\t\treturn result as never;\n\t\t\t},\n\t\t\twrite: (value, writer) => {\n\t\t\t\tfor (let i = 0; i < fields.length; i++) {\n\t\t\t\t\tfields[i].write(value[i], writer);\n\t\t\t\t}\n\t\t\t},\n\t\t\t...options,\n\t\t\tvalidate: (value) => {\n\t\t\t\toptions?.validate?.(value);\n\t\t\t\tif (!Array.isArray(value)) {\n\t\t\t\t\tthrow new TypeError(`Expected array, found ${typeof value}`);\n\t\t\t\t}\n\t\t\t\tif (value.length !== fields.length) {\n\t\t\t\t\tthrow new TypeError(`Expected array of length ${fields.length}, found ${value.length}`);\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\t}\n}\n"],"mappings":";;;;;AAeA,IAAa,UAAb,MAAa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,GAAG,WAAqC;EACnE,MAAM;GACL,MAAM,QAAS,IAAI,OAAO,KAAK,MAAM,EAAE,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE;GACxD,iBAAiB,WAAW;IAC3B,IAAI,QAAQ;IACZ,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;KACvC,MAAM,OAAO,OAAO,EAAE,CAAC,eAAe,OAAO,EAAE;KAC/C,IAAI,QAAQ,MACX,OAAO;KAGR,SAAS;IACV;IAEA,OAAO;GACR;GACA,OAAO,WAAW;IACjB,MAAM,SAAoB,CAAC;IAC3B,KAAK,MAAM,SAAS,QACnB,OAAO,KAAK,MAAM,KAAK,MAAM,CAAC;IAE/B,OAAO;GACR;GACA,QAAQ,OAAO,WAAW;IACzB,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAClC,OAAO,EAAE,CAAC,MAAM,MAAM,IAAI,MAAM;GAElC;GACA,GAAG;GACH,WAAW,UAAU;IACpB,SAAS,WAAW,KAAK;IACzB,IAAI,CAAC,MAAM,QAAQ,KAAK,GACvB,MAAM,IAAI,UAAU,yBAAyB,OAAO,OAAO;IAE5D,IAAI,MAAM,WAAW,OAAO,QAC3B,MAAM,IAAI,UAAU,4BAA4B,OAAO,OAAO,UAAU,MAAM,QAAQ;GAExF;EACD,CAAC;CACF;AACD"}
package/dist/bcs.d.mts CHANGED
@@ -30,8 +30,8 @@ declare function vector<T, Input, Name extends string = string>(type: BcsType<T,
30
30
  * Comparison is done byte-by-byte first, then by length if all compared bytes are equal.
31
31
  */
32
32
  declare function compareBcsBytes(a: Uint8Array, b: Uint8Array): number;
33
- declare function map<K$1 extends BcsType<any>, V extends BcsType<any>>(keyType: K$1, valueType: V): BcsType<Map<InferBcsType<K$1>, InferBcsType<V>>, Map<InferBcsInput<K$1>, InferBcsInput<V>>, `Map<${K$1['name']}, ${V['name']}>`>;
34
- declare function map<K$1, V, InputK = K$1, InputV = V>(keyType: BcsType<K$1, InputK>, valueType: BcsType<V, InputV>): BcsType<Map<K$1, V>, Map<InputK, InputV>, `Map<${string}, ${string}>`>;
33
+ declare function map<K extends BcsType<any>, V extends BcsType<any>>(keyType: K, valueType: V): BcsType<Map<InferBcsType<K>, InferBcsType<V>>, Map<InferBcsInput<K>, InferBcsInput<V>>, `Map<${K['name']}, ${V['name']}>`>;
34
+ declare function map<K, V, InputK = K, InputV = V>(keyType: BcsType<K, InputK>, valueType: BcsType<V, InputV>): BcsType<Map<K, V>, Map<InputK, InputV>, `Map<${string}, ${string}>`>;
35
35
  declare const bcs: {
36
36
  /**
37
37
  * Creates a BcsType that can be used to read and write an 8-bit unsigned integer.
@@ -1 +1 @@
1
- {"version":3,"file":"bcs.d.mts","names":[],"sources":["../src/bcs.ts"],"sourcesContent":[],"mappings":";;;;iBAyBS,qBAAqB,gEAEvB,UAFuB,GAGnB,eACT,aAAa,MACb,SAAS,cAAc;EALhB,MAAA,EAAA,MAAU;CAAW,EAM5B,IAN4B,CAAA,CAAA,EAQ3B,OAR2B,CAQnB,YARmB,CAQN,CARM,CAAA,EAAA,EAQA,QARA,CAQS,aART,CAQuB,CARvB,CAAA,CAAA,GAAA;EAEvB,MAAA,EAAA,MAAA;CAEQ,EAIgE,IAJhE,CAAA;iBAKN,UALP,CAAA,CAAA,EAAA,KAAA,EAAA,aAAA,MAAA,GAAA,MAAA,CAAA,CAAA,IAAA,EAAA,MAAA,EAAA,IAAA,EAOK,OAPL,CAOa,CAPb,EAOgB,KAPhB,CAAA,EAAA,OACS,CADT,EAQS,cART,CAQwB,CARxB,EAAA,EAQ6B,QAR7B,CAQsC,KARtC,CAAA,GAAA;EACuB,MAAA,EAAA,MAAA;CAAd,EAO0D,IAP1D,CAAA,CAAA,EAQR,OARQ,CAQA,CARA,EAAA,EAQK,QARL,CAQc,KARd,CAAA,GAAA;EAAT,MAAA,EAAA,MAAA;CACA,EAOoD,IAPpD,CAAA;iBA4CO,MA/CE,CAAA,UA+Ce,OA/Cf,CAAA,GAAA,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AE3D,IAAA,aAGD,OAAA,CAAA,CAAA,EAAA,IAAA;EAlbqC;;;;;;;;;EAIf;;;;iBAqcT,OAAA,OAAY,EAAA,QAAY,CAAA,GAAI,CAAA;AAAA"}
package/dist/bcs.mjs CHANGED
@@ -1,6 +1,5 @@
1
1
  import { ulebEncode } from "./uleb.mjs";
2
2
  import { BcsEnum, BcsStruct, BcsTuple, BcsType, bigUIntBcsType, dynamicSizeBcsType, fixedSizeBcsType, lazyBcsType, stringLikeBcsType, uIntBcsType } from "./bcs-type.mjs";
3
-
4
3
  //#region src/bcs.ts
5
4
  function fixedArray(size, type, options) {
6
5
  return new BcsType({
@@ -86,6 +85,11 @@ function map(keyType, valueType) {
86
85
  });
87
86
  }
88
87
  const bcs = {
88
+ /**
89
+ * Creates a BcsType that can be used to read and write an 8-bit unsigned integer.
90
+ * @example
91
+ * bcs.u8().serialize(255).toBytes() // Uint8Array [ 255 ]
92
+ */
89
93
  u8(options) {
90
94
  return uIntBcsType({
91
95
  readMethod: "read8",
@@ -96,6 +100,11 @@ const bcs = {
96
100
  name: options?.name ?? "u8"
97
101
  });
98
102
  },
103
+ /**
104
+ * Creates a BcsType that can be used to read and write a 16-bit unsigned integer.
105
+ * @example
106
+ * bcs.u16().serialize(65535).toBytes() // Uint8Array [ 255, 255 ]
107
+ */
99
108
  u16(options) {
100
109
  return uIntBcsType({
101
110
  readMethod: "read16",
@@ -106,6 +115,11 @@ const bcs = {
106
115
  name: options?.name ?? "u16"
107
116
  });
108
117
  },
118
+ /**
119
+ * Creates a BcsType that can be used to read and write a 32-bit unsigned integer.
120
+ * @example
121
+ * bcs.u32().serialize(4294967295).toBytes() // Uint8Array [ 255, 255, 255, 255 ]
122
+ */
109
123
  u32(options) {
110
124
  return uIntBcsType({
111
125
  readMethod: "read32",
@@ -116,6 +130,11 @@ const bcs = {
116
130
  name: options?.name ?? "u32"
117
131
  });
118
132
  },
133
+ /**
134
+ * Creates a BcsType that can be used to read and write a 64-bit unsigned integer.
135
+ * @example
136
+ * bcs.u64().serialize(1).toBytes() // Uint8Array [ 1, 0, 0, 0, 0, 0, 0, 0 ]
137
+ */
119
138
  u64(options) {
120
139
  return bigUIntBcsType({
121
140
  readMethod: "read64",
@@ -126,6 +145,11 @@ const bcs = {
126
145
  name: options?.name ?? "u64"
127
146
  });
128
147
  },
148
+ /**
149
+ * Creates a BcsType that can be used to read and write a 128-bit unsigned integer.
150
+ * @example
151
+ * bcs.u128().serialize(1).toBytes() // Uint8Array [ 1, ..., 0 ]
152
+ */
129
153
  u128(options) {
130
154
  return bigUIntBcsType({
131
155
  readMethod: "read128",
@@ -136,6 +160,11 @@ const bcs = {
136
160
  name: options?.name ?? "u128"
137
161
  });
138
162
  },
163
+ /**
164
+ * Creates a BcsType that can be used to read and write a 256-bit unsigned integer.
165
+ * @example
166
+ * bcs.u256().serialize(1).toBytes() // Uint8Array [ 1, ..., 0 ]
167
+ */
139
168
  u256(options) {
140
169
  return bigUIntBcsType({
141
170
  readMethod: "read256",
@@ -146,6 +175,11 @@ const bcs = {
146
175
  name: options?.name ?? "u256"
147
176
  });
148
177
  },
178
+ /**
179
+ * Creates a BcsType that can be used to read and write boolean values.
180
+ * @example
181
+ * bcs.bool().serialize(true).toBytes() // Uint8Array [ 1 ]
182
+ */
149
183
  bool(options) {
150
184
  return fixedSizeBcsType({
151
185
  size: 1,
@@ -159,6 +193,11 @@ const bcs = {
159
193
  }
160
194
  });
161
195
  },
196
+ /**
197
+ * Creates a BcsType that can be used to read and write unsigned LEB encoded integers
198
+ * @example
199
+ *
200
+ */
162
201
  uleb128(options) {
163
202
  return dynamicSizeBcsType({
164
203
  read: (reader) => reader.readULEB(),
@@ -169,6 +208,12 @@ const bcs = {
169
208
  name: options?.name ?? "uleb128"
170
209
  });
171
210
  },
211
+ /**
212
+ * Creates a BcsType representing a fixed length byte array
213
+ * @param size The number of bytes this types represents
214
+ * @example
215
+ * bcs.bytes(3).serialize(new Uint8Array([1, 2, 3])).toBytes() // Uint8Array [1, 2, 3]
216
+ */
172
217
  bytes(size, options) {
173
218
  return fixedSizeBcsType({
174
219
  size,
@@ -185,6 +230,12 @@ const bcs = {
185
230
  }
186
231
  });
187
232
  },
233
+ /**
234
+ * Creates a BcsType representing a variable length byte array
235
+ *
236
+ * @example
237
+ * bcs.byteVector().serialize([1, 2, 3]).toBytes() // Uint8Array [3, 1, 2, 3]
238
+ */
188
239
  byteVector(options) {
189
240
  return new BcsType({
190
241
  read: (reader) => {
@@ -208,6 +259,11 @@ const bcs = {
208
259
  }
209
260
  });
210
261
  },
262
+ /**
263
+ * Creates a BcsType that can ser/de string values. Strings will be UTF-8 encoded
264
+ * @example
265
+ * bcs.string().serialize('a').toBytes() // Uint8Array [ 1, 97 ]
266
+ */
211
267
  string(options) {
212
268
  return stringLikeBcsType({
213
269
  toBytes: (value) => new TextEncoder().encode(value),
@@ -216,15 +272,56 @@ const bcs = {
216
272
  name: options?.name ?? "string"
217
273
  });
218
274
  },
275
+ /**
276
+ * Creates a BcsType that represents a fixed length array of a given type
277
+ * @param size The number of elements in the array
278
+ * @param type The BcsType of each element in the array
279
+ * @example
280
+ * bcs.fixedArray(3, bcs.u8()).serialize([1, 2, 3]).toBytes() // Uint8Array [ 1, 2, 3 ]
281
+ */
219
282
  fixedArray,
283
+ /**
284
+ * Creates a BcsType representing an optional value
285
+ * @param type The BcsType of the optional value
286
+ * @example
287
+ * bcs.option(bcs.u8()).serialize(null).toBytes() // Uint8Array [ 0 ]
288
+ * bcs.option(bcs.u8()).serialize(1).toBytes() // Uint8Array [ 1, 1 ]
289
+ */
220
290
  option,
291
+ /**
292
+ * Creates a BcsType representing a variable length vector of a given type
293
+ * @param type The BcsType of each element in the vector
294
+ *
295
+ * @example
296
+ * bcs.vector(bcs.u8()).toBytes([1, 2, 3]) // Uint8Array [ 3, 1, 2, 3 ]
297
+ */
221
298
  vector,
299
+ /**
300
+ * Creates a BcsType representing a tuple of a given set of types
301
+ * @param types The BcsTypes for each element in the tuple
302
+ *
303
+ * @example
304
+ * const tuple = bcs.tuple([bcs.u8(), bcs.string(), bcs.bool()])
305
+ * tuple.serialize([1, 'a', true]).toBytes() // Uint8Array [ 1, 1, 97, 1 ]
306
+ */
222
307
  tuple(fields, options) {
223
308
  return new BcsTuple({
224
309
  fields,
225
310
  ...options
226
311
  });
227
312
  },
313
+ /**
314
+ * Creates a BcsType representing a struct of a given set of fields
315
+ * @param name The name of the struct
316
+ * @param fields The fields of the struct. The order of the fields affects how data is serialized and deserialized
317
+ *
318
+ * @example
319
+ * const struct = bcs.struct('MyStruct', {
320
+ * a: bcs.u8(),
321
+ * b: bcs.string(),
322
+ * })
323
+ * struct.serialize({ a: 1, b: 'a' }).toBytes() // Uint8Array [ 1, 1, 97 ]
324
+ */
228
325
  struct(name, fields, options) {
229
326
  return new BcsStruct({
230
327
  name,
@@ -232,6 +329,22 @@ const bcs = {
232
329
  ...options
233
330
  });
234
331
  },
332
+ /**
333
+ * Creates a BcsType representing an enum of a given set of options
334
+ * @param name The name of the enum
335
+ * @param values The values of the enum. The order of the values affects how data is serialized and deserialized.
336
+ * null can be used to represent a variant with no data.
337
+ *
338
+ * @example
339
+ * const enum = bcs.enum('MyEnum', {
340
+ * A: bcs.u8(),
341
+ * B: bcs.string(),
342
+ * C: null,
343
+ * })
344
+ * enum.serialize({ A: 1 }).toBytes() // Uint8Array [ 0, 1 ]
345
+ * enum.serialize({ B: 'a' }).toBytes() // Uint8Array [ 1, 1, 97 ]
346
+ * enum.serialize({ C: true }).toBytes() // Uint8Array [ 2 ]
347
+ */
235
348
  enum(name, fields, options) {
236
349
  return new BcsEnum({
237
350
  name,
@@ -239,12 +352,24 @@ const bcs = {
239
352
  ...options
240
353
  });
241
354
  },
355
+ /**
356
+ * Creates a BcsType representing a map of a given key and value type
357
+ * @param keyType The BcsType of the key
358
+ * @param valueType The BcsType of the value
359
+ * @example
360
+ * const map = bcs.map(bcs.u8(), bcs.string())
361
+ * map.serialize(new Map([[2, 'a']])).toBytes() // Uint8Array [ 1, 2, 1, 97 ]
362
+ */
242
363
  map,
364
+ /**
365
+ * Creates a BcsType that wraps another BcsType which is lazily evaluated. This is useful for creating recursive types.
366
+ * @param cb A callback that returns the BcsType
367
+ */
243
368
  lazy(cb) {
244
369
  return lazyBcsType(cb);
245
370
  }
246
371
  };
247
-
248
372
  //#endregion
249
373
  export { bcs, compareBcsBytes };
374
+
250
375
  //# sourceMappingURL=bcs.mjs.map