@cbortech/cbor 0.24.0 → 0.25.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/README.ja.md +35 -37
- package/README.md +35 -37
- package/dist/ast/CborArray.d.ts +3 -3
- package/dist/ast/CborBignum.d.ts +5 -5
- package/dist/ast/CborByteString.d.ts +2 -2
- package/dist/ast/CborEllipsis.d.ts +2 -2
- package/dist/ast/CborEmbeddedCBOR.d.ts +3 -3
- package/dist/ast/CborFloat.d.ts +2 -2
- package/dist/ast/CborIndefiniteByteString.d.ts +3 -3
- package/dist/ast/CborIndefiniteTextString.d.ts +3 -3
- package/dist/ast/CborItem.d.ts +16 -10
- package/dist/ast/CborMap.d.ts +3 -3
- package/dist/ast/CborNint.d.ts +2 -2
- package/dist/ast/CborSimple.d.ts +2 -2
- package/dist/ast/CborTag.d.ts +3 -3
- package/dist/ast/CborTextString.d.ts +2 -2
- package/dist/ast/CborUint.d.ts +2 -2
- package/dist/ast/CborUnresolvedAppExt.d.ts +2 -2
- package/dist/ast/index.cjs +1 -1
- package/dist/ast/index.js +1 -1
- package/dist/cbor.d.ts +44 -26
- package/dist/cdn/parser.d.ts +7 -0
- package/dist/{edn → cdn}/serialize-utils.d.ts +4 -4
- package/dist/cdn/serializer.d.ts +7 -0
- package/dist/{edn → cdn}/tokenizer.d.ts +3 -3
- package/dist/extensions/cri.d.ts +7 -7
- package/dist/extensions/dt.d.ts +9 -9
- package/dist/extensions/ip.d.ts +8 -8
- package/dist/extensions/types.d.ts +4 -4
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +36 -18
- package/dist/index.js.map +1 -1
- package/dist/mapEntries-CNxwMt7o.cjs +31 -0
- package/dist/mapEntries-CNxwMt7o.cjs.map +1 -0
- package/dist/{mapEntries-D5MWtXqq.js → mapEntries-Da-2HMRf.js} +467 -461
- package/dist/mapEntries-Da-2HMRf.js.map +1 -0
- package/dist/simple.d.ts +2 -2
- package/dist/tag.d.ts +1 -1
- package/dist/types.d.ts +40 -24
- package/dist/utils/hexfloat.d.ts +2 -2
- package/package.json +9 -9
- package/dist/edn/parser.d.ts +0 -7
- package/dist/edn/serializer.d.ts +0 -7
- package/dist/mapEntries-D5MWtXqq.js.map +0 -1
- package/dist/mapEntries-bihZ3yks.cjs +0 -31
- package/dist/mapEntries-bihZ3yks.cjs.map +0 -1
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["#defaults","#merge"],"sources":["../src/cbor.ts"],"sourcesContent":["import type { CborItem } from './ast/CborItem';\nimport type {\n CBOROptions,\n FromCBOROptions,\n FromHexDumpOptions,\n FromEDNOptions,\n FromJSOptions,\n ToCBOROptions,\n ToEDNOptions,\n ToJSOptions,\n} from './types';\nimport { CBOR_OMIT } from './types';\nimport { decodeCBOR } from './cbor/decoder';\nimport { parseEDN } from './edn/parser';\nimport { dt_as_Date as _dt_as_Date } from './extensions/dt';\nimport { fromJS as _fromJS, _applyReplacer } from './js/fromJS';\nimport { MapEntries as _MapEntries } from './mapEntries';\nimport { Simple as _Simple } from './simple';\nimport { CBOR_TAG, Tag as _Tag } from './tag';\n\n/**\n * Main facade class.\n *\n * Provides factory methods for constructing AST nodes from the three\n * supported input formats, and shortcut methods that mirror the\n * `JSON.parse` / `JSON.stringify` API.\n *\n * @example\n * // CBOR binary → AST → CBOR binary\n * const ast = CBOR.fromCBOR(bytes);\n * const reencoded = ast.toCBOR();\n *\n * @example\n * // JS value → CBOR binary (shortcut)\n * const bytes = CBOR.encode({ hello: 'world' });\n *\n * @example\n * // CBOR binary → JS value (shortcut)\n * const value = CBOR.decode(bytes);\n */\nexport class CBOR {\n /**\n * Sentinel returned from a replacer or reviver to omit the key/element from\n * the output. Use this instead of `undefined` when `undefinedOmits` is\n * `false` (the default) and you need to drop a specific entry.\n */\n static readonly OMIT: typeof CBOR_OMIT = CBOR_OMIT;\n\n /** Unique symbol used to attach a CBOR tag number to a JS value. */\n static readonly TAG: typeof CBOR_TAG = CBOR_TAG;\n\n /** Namespace for CBOR tag annotation utilities. */\n static readonly Tag: typeof _Tag = _Tag;\n\n /** Wrapper for CBOR simple values other than false/true/null/undefined. */\n static readonly Simple: typeof _Simple = _Simple;\n\n /** Array subclass used to preserve CBOR map entries, including duplicates. */\n static readonly MapEntries: typeof _MapEntries = _MapEntries;\n\n /** Extension that maps CBOR-EDN dt/DT values to JavaScript Date objects. */\n static readonly dt_as_Date: typeof _dt_as_Date = _dt_as_Date;\n\n // ─── Instance API ───────────────────────────────────────────────────────────\n\n readonly #defaults: CBOROptions;\n\n /**\n * Create a reusable instance with default options applied to every method call.\n * Per-call options always override these defaults.\n *\n * @example\n * const cbor = new CBOR({ extensions: [CBOR.dt_as_Date] });\n * const obj = cbor.parse('{ \"dt\": DT\\'2024-01-01T00:00:00Z\\' }');\n * const text = cbor.stringify(obj);\n */\n constructor(defaults?: CBOROptions) {\n this.#defaults = defaults ?? {};\n }\n\n #merge<T extends object>(perCall?: T): CBOROptions & T {\n return { ...this.#defaults, ...(perCall ?? {}) } as CBOROptions & T;\n }\n\n fromCBOR(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions\n ): CborItem {\n const node = CBOR.fromCBOR(input, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n fromEDN(text: string, options?: FromEDNOptions): CborItem {\n const node = CBOR.fromEDN(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n fromJS(value: unknown, options?: FromJSOptions): CborItem {\n const node = CBOR.fromJS(value, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n fromHexDump(text: string, options?: FromHexDumpOptions): CborItem {\n const node = CBOR.fromHexDump(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.decode(input, this.#merge(options));\n }\n\n encode(value: unknown, options?: FromJSOptions & ToCBOROptions): Uint8Array {\n return CBOR.encode(value, this.#merge(options));\n }\n\n /**\n * @deprecated Use `fromCBOR(input, options).toEDN(options)` instead.\n */\n cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToEDNOptions\n ): string {\n return CBOR.cborToCborEdn(input, this.#merge(options));\n }\n\n /**\n * @deprecated Use `fromEDN(text, options).toCBOR(options)` instead.\n */\n cborEdnToCbor(\n text: string,\n options?: FromEDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.cborEdnToCbor(text, this.#merge(options));\n }\n\n parse(text: string): unknown;\n parse(\n text: string,\n reviver: (this: unknown, key: unknown, value: unknown) => unknown\n ): unknown;\n parse(text: string, options: FromEDNOptions & ToJSOptions): unknown;\n parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromEDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n const merged = this.#merge<ToJSOptions>({ reviver: arg2 });\n return CBOR.fromEDN(text, merged).toJS(merged);\n }\n const merged = this.#merge(arg2);\n return CBOR.fromEDN(text, merged).toJS(merged);\n }\n\n stringify(value: unknown): string;\n stringify(\n value: unknown,\n replacer:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null,\n space?: string | number\n ): string;\n stringify(value: unknown, options: FromJSOptions & ToEDNOptions): string;\n stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToEDNOptions),\n arg3?: string | number\n ): string {\n if (\n typeof arg2 === 'function' ||\n Array.isArray(arg2) ||\n arg2 === null ||\n (arg2 === undefined && arg3 !== undefined)\n ) {\n const opts: FromJSOptions & ToEDNOptions = {\n ...(this.#defaults as FromJSOptions & ToEDNOptions),\n };\n if (arg2 === null) {\n opts.replacer = undefined;\n } else if (typeof arg2 === 'function' || Array.isArray(arg2)) {\n opts.replacer = arg2;\n }\n if (arg3 !== undefined) opts.indent = resolveSpace(arg3);\n return CBOR.stringify(value, opts);\n }\n return CBOR.stringify(value, this.#merge(arg2 ?? undefined));\n }\n\n format(text: string, options?: FromEDNOptions & ToEDNOptions): string {\n return CBOR.format(text, this.#merge(options));\n }\n\n // ─── Factory methods ────────────────────────────────────────────────────────\n\n /** Decode CBOR binary data into an AST node. */\n static fromCBOR(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions\n ): CborItem {\n return decodeCBOR(input, options);\n }\n\n /** Parse a CBOR-EDN text string into an AST node. */\n static fromEDN(text: string, options?: FromEDNOptions): CborItem {\n return parseEDN(text, options);\n }\n\n /** Convert a JavaScript value into an AST node. */\n static fromJS(value: unknown, options?: FromJSOptions): CborItem {\n return _fromJS(value, options);\n }\n\n /**\n * Parse an annotated hex dump (as produced by {@link CborItem#toHexDump})\n * into an AST node.\n *\n * Each line is expected to have the form:\n * `[whitespace] HH [HH …] -- comment`\n * `[whitespace] HH [HH …] # comment`\n * `[whitespace] HH [HH …] // comment`\n * Block comments may also be written as `/ comment /` or `/* comment *\\/`.\n * Lines with no hex content before the comment marker are ignored.\n */\n static fromHexDump(text: string, options?: FromHexDumpOptions): CborItem {\n const bytes: number[] = [];\n const uncommented = stripHexDumpComments(text);\n const tokens = uncommented.trim().split(/\\s+/).filter(Boolean);\n for (const token of tokens) {\n if (!/^[0-9A-Fa-f]{2}$/.test(token))\n throw new SyntaxError(\n `Invalid hex token in dump: ${JSON.stringify(token)}`\n );\n bytes.push(parseInt(token, 16));\n }\n return decodeCBOR(new Uint8Array(bytes), options);\n }\n\n // ─── Shortcut API ───────────────────────────────────────────────────────────\n\n /** Decode CBOR binary data directly to a JavaScript value. */\n static decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.fromCBOR(input, options).toJS(options);\n }\n\n /** Encode a JavaScript value directly to CBOR binary data. */\n static encode(\n value: unknown,\n options?: FromJSOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromJS(value, options).toCBOR(options);\n }\n\n /**\n * Convert CBOR binary data directly to a CBOR-EDN text string.\n *\n * @deprecated Use `CBOR.fromCBOR(input, options).toEDN(options)` instead.\n */\n static cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToEDNOptions\n ): string {\n return CBOR.fromCBOR(input, options).toEDN(options);\n }\n\n /**\n * Convert a CBOR-EDN text string directly to CBOR binary data.\n *\n * @deprecated Use `CBOR.fromEDN(text, options).toCBOR(options)` instead.\n */\n static cborEdnToCbor(\n text: string,\n options?: FromEDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromEDN(text, options).toCBOR(options);\n }\n\n /**\n * Parse a CBOR-EDN text string directly to a JavaScript value.\n *\n * Accepts either a JSON-compatible `reviver` function as the second argument,\n * or a plain options object (existing API).\n *\n * When a `reviver` is supplied it is applied bottom-up after the EDN text has\n * been parsed and converted to a JS value, matching the semantics of\n * `JSON.parse(text, reviver)`.\n *\n * Note: CBOR-specific value types such as `bigint` are passed to the reviver\n * as-is; the reviver is responsible for handling them.\n */\n static parse(text: string): unknown;\n static parse(\n text: string,\n reviver: (this: unknown, key: unknown, value: unknown) => unknown\n ): unknown;\n static parse(text: string, options: FromEDNOptions & ToJSOptions): unknown;\n static parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromEDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n return CBOR.fromEDN(text).toJS({ reviver: arg2 });\n }\n return CBOR.fromEDN(text, arg2).toJS(arg2);\n }\n\n /**\n * Serialize a JavaScript value directly to a CBOR-EDN text string.\n *\n * Accepts either JSON-compatible `replacer` + `space` arguments, or a plain\n * options object (existing API).\n *\n * - `replacer` may be a function (transforms each key/value before encoding)\n * or an array of strings/numbers (allowlist of object keys to include).\n * Pass `null` to skip filtering.\n * - `space` controls indentation, mapping to `ToEDNOptions.indent`.\n * Numbers are clamped to `[0, 10]`; strings are truncated to 10 characters.\n */\n static stringify(value: unknown): string;\n static stringify(\n value: unknown,\n replacer:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null,\n space?: string | number\n ): string;\n static stringify(\n value: unknown,\n options: FromJSOptions & ToEDNOptions\n ): string;\n static stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToEDNOptions),\n arg3?: string | number\n ): string {\n if (\n typeof arg2 === 'function' ||\n Array.isArray(arg2) ||\n arg2 === null ||\n (arg2 === undefined && arg3 !== undefined)\n ) {\n const replacer =\n typeof arg2 === 'function' || Array.isArray(arg2) ? arg2 : undefined;\n const indent = resolveSpace(arg3);\n if (replacer) {\n // Mirror JSON.stringify: if the replacer drops the root, return undefined.\n const replaced = _applyReplacer(value, replacer);\n if (replaced === undefined || replaced === CBOR_OMIT)\n return undefined as unknown as string;\n return _fromJS(replaced).toEDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n return _fromJS(value).toEDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n // Options form: also mirror JSON.stringify root-drop semantics.\n const opts = arg2 as (FromJSOptions & ToEDNOptions) | undefined;\n if (opts?.replacer) {\n const replaced = _applyReplacer(\n value,\n opts.replacer,\n opts.extensions,\n opts.undefinedOmits\n );\n if (replaced === undefined || replaced === CBOR_OMIT)\n return undefined as unknown as string;\n const { replacer: _r, ...restFromJS } = opts;\n return _fromJS(\n replaced,\n Object.keys(restFromJS).length > 0\n ? (restFromJS as FromJSOptions)\n : undefined\n ).toEDN(opts);\n }\n return _fromJS(value, opts as FromJSOptions | undefined).toEDN(opts);\n }\n\n /** Normalize a CBOR-EDN text string by parsing and re-serializing it. */\n static format(text: string, options?: FromEDNOptions & ToEDNOptions): string {\n return CBOR.fromEDN(text, options).toEDN(options);\n }\n}\n\nfunction stripHexDumpComments(text: string): string {\n let out = '';\n let i = 0;\n\n while (i < text.length) {\n const ch = text[i];\n const next = text[i + 1] ?? '';\n\n if (ch === '-' && next === '-') {\n i = skipLineComment(text, i + 2);\n out += ' ';\n continue;\n }\n\n if (ch === '#') {\n i = skipLineComment(text, i + 1);\n out += ' ';\n continue;\n }\n\n if (ch === '/' && next === '/') {\n i = skipLineComment(text, i + 2);\n out += ' ';\n continue;\n }\n\n if (ch === '/' && next === '*') {\n const end = text.indexOf('*/', i + 2);\n if (end < 0) throw new SyntaxError('Unterminated comment in hex dump');\n out += whitespaceLike(text.slice(i, end + 2));\n i = end + 2;\n continue;\n }\n\n if (ch === '/') {\n const end = text.indexOf('/', i + 1);\n if (end < 0) throw new SyntaxError('Unterminated comment in hex dump');\n out += whitespaceLike(text.slice(i, end + 1));\n i = end + 1;\n continue;\n }\n\n out += ch;\n i++;\n }\n\n return out;\n}\n\nfunction skipLineComment(text: string, start: number): number {\n const end = text.indexOf('\\n', start);\n return end < 0 ? text.length : end;\n}\n\nfunction whitespaceLike(text: string): string {\n return text.replace(/[^\\r\\n]/g, ' ');\n}\n\n// ─── Module-scope helper ─────────────────────────────────────────────────────\n\n/** Map JSON.stringify `space` argument to ToEDNOptions.indent. */\nfunction resolveSpace(\n space: string | number | undefined\n): string | number | undefined {\n if (typeof space === 'number') {\n const n = Math.floor(Math.min(10, Math.max(0, space)));\n return n === 0 ? undefined : n;\n }\n if (typeof space === 'string') {\n const s = space.slice(0, 10);\n return s || undefined;\n }\n return undefined;\n}\n"],"mappings":"4IAwCA,IAAa,EAAb,MAAa,CAAK,CAMhB,OAAgB,KAAyB,EAAA,EAGzC,OAAgB,IAAuB,EAAA,EAGvC,OAAgB,IAAmB,EAAA,EAGnC,OAAgB,OAAyB,EAAA,EAGzC,OAAgB,WAAiC,EAAA,EAGjD,OAAgB,WAAiC,EAAA,EAIjD,GAWA,YAAY,EAAwB,CAClC,KAAKA,GAAY,GAAY,EAAE,CAGjC,GAAyB,EAA8B,CACrD,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{"version":3,"file":"index.cjs","names":["#defaults","#merge"],"sources":["../src/cbor.ts"],"sourcesContent":["import type { CborItem } from './ast/CborItem';\nimport type {\n CBOROptions,\n FromCBOROptions,\n FromCDNOptions,\n FromHexDumpOptions,\n FromJSOptions,\n ToCBOROptions,\n ToCDNOptions,\n ToJSOptions,\n} from './types';\nimport { CBOR_OMIT } from './types';\nimport { decodeCBOR } from './cbor/decoder';\nimport { parseCDN } from './cdn/parser';\nimport { dt_as_Date as _dt_as_Date } from './extensions/dt';\nimport { fromJS as _fromJS, _applyReplacer } from './js/fromJS';\nimport { MapEntries as _MapEntries } from './mapEntries';\nimport { Simple as _Simple } from './simple';\nimport { CBOR_TAG, Tag as _Tag } from './tag';\n\n/**\n * Main facade class.\n *\n * Provides factory methods for constructing AST nodes from the three\n * supported input formats, and shortcut methods that mirror the\n * `JSON.parse` / `JSON.stringify` API.\n *\n * @example\n * // CBOR binary → AST → CBOR binary\n * const ast = CBOR.fromCBOR(bytes);\n * const reencoded = ast.toCBOR();\n *\n * @example\n * // JS value → CBOR binary (shortcut)\n * const bytes = CBOR.encode({ hello: 'world' });\n *\n * @example\n * // CBOR binary → JS value (shortcut)\n * const value = CBOR.decode(bytes);\n */\nexport class CBOR {\n /**\n * Sentinel returned from a replacer or reviver to omit the key/element from\n * the output. Use this instead of `undefined` when `undefinedOmits` is\n * `false` (the default) and you need to drop a specific entry.\n */\n static readonly OMIT: typeof CBOR_OMIT = CBOR_OMIT;\n\n /** Unique symbol used to attach a CBOR tag number to a JS value. */\n static readonly TAG: typeof CBOR_TAG = CBOR_TAG;\n\n /** Namespace for CBOR tag annotation utilities. */\n static readonly Tag: typeof _Tag = _Tag;\n\n /** Wrapper for CBOR simple values other than false/true/null/undefined. */\n static readonly Simple: typeof _Simple = _Simple;\n\n /** Array subclass used to preserve CBOR map entries, including duplicates. */\n static readonly MapEntries: typeof _MapEntries = _MapEntries;\n\n /** Extension that maps CDN dt/DT values to JavaScript Date objects. */\n static readonly dt_as_Date: typeof _dt_as_Date = _dt_as_Date;\n\n // ─── Instance API ───────────────────────────────────────────────────────────\n\n readonly #defaults: CBOROptions;\n\n /**\n * Create a reusable instance with default options applied to every method call.\n * Per-call options always override these defaults.\n *\n * @example\n * const cbor = new CBOR({ extensions: [CBOR.dt_as_Date] });\n * const obj = cbor.parse('{ \"dt\": DT\\'2024-01-01T00:00:00Z\\' }');\n * const text = cbor.stringify(obj);\n */\n constructor(defaults?: CBOROptions) {\n this.#defaults = defaults ?? {};\n }\n\n #merge<T extends object>(perCall?: T): CBOROptions & T {\n return { ...this.#defaults, ...(perCall ?? {}) } as CBOROptions & T;\n }\n\n fromCBOR(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions\n ): CborItem {\n const node = CBOR.fromCBOR(input, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n fromCDN(text: string, options?: FromCDNOptions): CborItem {\n const node = CBOR.fromCDN(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n /** @deprecated Use `fromCDN()` instead. */\n fromEDN(text: string, options?: FromCDNOptions): CborItem {\n return this.fromCDN(text, options);\n }\n\n fromJS(value: unknown, options?: FromJSOptions): CborItem {\n const node = CBOR.fromJS(value, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n fromHexDump(text: string, options?: FromHexDumpOptions): CborItem {\n const node = CBOR.fromHexDump(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.decode(input, this.#merge(options));\n }\n\n encode(value: unknown, options?: FromJSOptions & ToCBOROptions): Uint8Array {\n return CBOR.encode(value, this.#merge(options));\n }\n\n /**\n * @deprecated Use `cborToCdn()` or `fromCBOR(input, options).toCDN(options)` instead.\n */\n cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return this.cborToCdn(input, options);\n }\n\n cborToCdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return CBOR.cborToCdn(input, this.#merge(options));\n }\n\n /**\n * @deprecated Use `cdnToCbor()` or `fromCDN(text, options).toCBOR(options)` instead.\n */\n cborEdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return this.cdnToCbor(text, options);\n }\n\n cdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.cdnToCbor(text, this.#merge(options));\n }\n\n parse(text: string): unknown;\n parse(\n text: string,\n reviver: (this: unknown, key: unknown, value: unknown) => unknown\n ): unknown;\n parse(text: string, options: FromCDNOptions & ToJSOptions): unknown;\n parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromCDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n const merged = this.#merge<ToJSOptions>({ reviver: arg2 });\n return CBOR.fromCDN(text, merged).toJS(merged);\n }\n const merged = this.#merge(arg2);\n return CBOR.fromCDN(text, merged).toJS(merged);\n }\n\n stringify(value: unknown): string;\n stringify(\n value: unknown,\n replacer:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null,\n space?: string | number\n ): string;\n stringify(value: unknown, options: FromJSOptions & ToCDNOptions): string;\n stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToCDNOptions),\n arg3?: string | number\n ): string {\n if (\n typeof arg2 === 'function' ||\n Array.isArray(arg2) ||\n arg2 === null ||\n (arg2 === undefined && arg3 !== undefined)\n ) {\n const opts: FromJSOptions & ToCDNOptions = {\n ...(this.#defaults as FromJSOptions & ToCDNOptions),\n };\n if (arg2 === null) {\n opts.replacer = undefined;\n } else if (typeof arg2 === 'function' || Array.isArray(arg2)) {\n opts.replacer = arg2;\n }\n if (arg3 !== undefined) opts.indent = resolveSpace(arg3);\n return CBOR.stringify(value, opts);\n }\n return CBOR.stringify(value, this.#merge(arg2 ?? undefined));\n }\n\n format(text: string, options?: FromCDNOptions & ToCDNOptions): string {\n return CBOR.format(text, this.#merge(options));\n }\n\n // ─── Factory methods ────────────────────────────────────────────────────────\n\n /** Decode CBOR binary data into an AST node. */\n static fromCBOR(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions\n ): CborItem {\n return decodeCBOR(input, options);\n }\n\n /** Parse a CDN text string into an AST node. */\n static fromCDN(text: string, options?: FromCDNOptions): CborItem {\n return parseCDN(text, options);\n }\n\n /**\n * Parse a CDN text string into an AST node.\n *\n * @deprecated Use `fromCDN()` instead.\n */\n static fromEDN(text: string, options?: FromCDNOptions): CborItem {\n return CBOR.fromCDN(text, options);\n }\n\n /** Convert a JavaScript value into an AST node. */\n static fromJS(value: unknown, options?: FromJSOptions): CborItem {\n return _fromJS(value, options);\n }\n\n /**\n * Parse an annotated hex dump (as produced by {@link CborItem#toHexDump})\n * into an AST node.\n *\n * Each line is expected to have the form:\n * `[whitespace] HH [HH …] -- comment`\n * `[whitespace] HH [HH …] # comment`\n * `[whitespace] HH [HH …] // comment`\n * Block comments may also be written as `/ comment /` or `/* comment *\\/`.\n * Lines with no hex content before the comment marker are ignored.\n */\n static fromHexDump(text: string, options?: FromHexDumpOptions): CborItem {\n const bytes: number[] = [];\n const uncommented = stripHexDumpComments(text);\n const tokens = uncommented.trim().split(/\\s+/).filter(Boolean);\n for (const token of tokens) {\n if (!/^[0-9A-Fa-f]{2}$/.test(token))\n throw new SyntaxError(\n `Invalid hex token in dump: ${JSON.stringify(token)}`\n );\n bytes.push(parseInt(token, 16));\n }\n return decodeCBOR(new Uint8Array(bytes), options);\n }\n\n // ─── Shortcut API ───────────────────────────────────────────────────────────\n\n /** Decode CBOR binary data directly to a JavaScript value. */\n static decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.fromCBOR(input, options).toJS(options);\n }\n\n /** Encode a JavaScript value directly to CBOR binary data. */\n static encode(\n value: unknown,\n options?: FromJSOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromJS(value, options).toCBOR(options);\n }\n\n /**\n * Convert CBOR binary data directly to a CDN text string.\n */\n static cborToCdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return CBOR.fromCBOR(input, options).toCDN(options);\n }\n\n /**\n * Convert CBOR binary data directly to a CDN text string.\n *\n * @deprecated Use `CBOR.cborToCdn()` or `CBOR.fromCBOR(input, options).toCDN(options)` instead.\n */\n static cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return CBOR.cborToCdn(input, options);\n }\n\n /**\n * Convert a CDN text string directly to CBOR binary data.\n */\n static cdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromCDN(text, options).toCBOR(options);\n }\n\n /**\n * Convert a CDN text string directly to CBOR binary data.\n *\n * @deprecated Use `CBOR.cdnToCbor()` or `CBOR.fromCDN(text, options).toCBOR(options)` instead.\n */\n static cborEdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.cdnToCbor(text, options);\n }\n\n /**\n * Parse a CDN text string directly to a JavaScript value.\n *\n * Accepts either a JSON-compatible `reviver` function as the second argument,\n * or a plain options object (existing API).\n *\n * When a `reviver` is supplied it is applied bottom-up after the CDN text has\n * been parsed and converted to a JS value, matching the semantics of\n * `JSON.parse(text, reviver)`.\n *\n * Note: CBOR-specific value types such as `bigint` are passed to the reviver\n * as-is; the reviver is responsible for handling them.\n */\n static parse(text: string): unknown;\n static parse(\n text: string,\n reviver: (this: unknown, key: unknown, value: unknown) => unknown\n ): unknown;\n static parse(text: string, options: FromCDNOptions & ToJSOptions): unknown;\n static parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromCDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n return CBOR.fromCDN(text).toJS({ reviver: arg2 });\n }\n return CBOR.fromCDN(text, arg2).toJS(arg2);\n }\n\n /**\n * Serialize a JavaScript value directly to a CDN text string.\n *\n * Accepts either JSON-compatible `replacer` + `space` arguments, or a plain\n * options object (existing API).\n *\n * - `replacer` may be a function (transforms each key/value before encoding)\n * or an array of strings/numbers (allowlist of object keys to include).\n * Pass `null` to skip filtering.\n * - `space` controls indentation, mapping to `ToCDNOptions.indent`.\n * Numbers are clamped to `[0, 10]`; strings are truncated to 10 characters.\n */\n static stringify(value: unknown): string;\n static stringify(\n value: unknown,\n replacer:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null,\n space?: string | number\n ): string;\n static stringify(\n value: unknown,\n options: FromJSOptions & ToCDNOptions\n ): string;\n static stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToCDNOptions),\n arg3?: string | number\n ): string {\n if (\n typeof arg2 === 'function' ||\n Array.isArray(arg2) ||\n arg2 === null ||\n (arg2 === undefined && arg3 !== undefined)\n ) {\n const replacer =\n typeof arg2 === 'function' || Array.isArray(arg2) ? arg2 : undefined;\n const indent = resolveSpace(arg3);\n if (replacer) {\n // Mirror JSON.stringify: if the replacer drops the root, return undefined.\n const replaced = _applyReplacer(value, replacer);\n if (replaced === undefined || replaced === CBOR_OMIT)\n return undefined as unknown as string;\n return _fromJS(replaced).toCDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n return _fromJS(value).toCDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n // Options form: also mirror JSON.stringify root-drop semantics.\n const opts = arg2 as (FromJSOptions & ToCDNOptions) | undefined;\n if (opts?.replacer) {\n const replaced = _applyReplacer(\n value,\n opts.replacer,\n opts.extensions,\n opts.undefinedOmits\n );\n if (replaced === undefined || replaced === CBOR_OMIT)\n return undefined as unknown as string;\n const { replacer: _r, ...restFromJS } = opts;\n return _fromJS(\n replaced,\n Object.keys(restFromJS).length > 0\n ? (restFromJS as FromJSOptions)\n : undefined\n ).toCDN(opts);\n }\n return _fromJS(value, opts as FromJSOptions | undefined).toCDN(opts);\n }\n\n /** Normalize a CDN text string by parsing and re-serializing it. */\n static format(text: string, options?: FromCDNOptions & ToCDNOptions): string {\n return CBOR.fromCDN(text, options).toCDN(options);\n }\n}\n\nfunction stripHexDumpComments(text: string): string {\n let out = '';\n let i = 0;\n\n while (i < text.length) {\n const ch = text[i];\n const next = text[i + 1] ?? '';\n\n if (ch === '-' && next === '-') {\n i = skipLineComment(text, i + 2);\n out += ' ';\n continue;\n }\n\n if (ch === '#') {\n i = skipLineComment(text, i + 1);\n out += ' ';\n continue;\n }\n\n if (ch === '/' && next === '/') {\n i = skipLineComment(text, i + 2);\n out += ' ';\n continue;\n }\n\n if (ch === '/' && next === '*') {\n const end = text.indexOf('*/', i + 2);\n if (end < 0) throw new SyntaxError('Unterminated comment in hex dump');\n out += whitespaceLike(text.slice(i, end + 2));\n i = end + 2;\n continue;\n }\n\n if (ch === '/') {\n const end = text.indexOf('/', i + 1);\n if (end < 0) throw new SyntaxError('Unterminated comment in hex dump');\n out += whitespaceLike(text.slice(i, end + 1));\n i = end + 1;\n continue;\n }\n\n out += ch;\n i++;\n }\n\n return out;\n}\n\nfunction skipLineComment(text: string, start: number): number {\n const end = text.indexOf('\\n', start);\n return end < 0 ? text.length : end;\n}\n\nfunction whitespaceLike(text: string): string {\n return text.replace(/[^\\r\\n]/g, ' ');\n}\n\n// ─── Module-scope helper ─────────────────────────────────────────────────────\n\n/** Map JSON.stringify `space` argument to ToCDNOptions.indent. */\nfunction resolveSpace(\n space: string | number | undefined\n): string | number | undefined {\n if (typeof space === 'number') {\n const n = Math.floor(Math.min(10, Math.max(0, space)));\n return n === 0 ? undefined : n;\n }\n if (typeof space === 'string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AC/B,GAAO,IACP,QACF,CAEA,GAAI,IAAO,KAAO,IAAS,IAAK,CAC9B,IAAM,EAAM,EAAK,QAAQ,KAAM,EAAI,CAAC,EACpC,GAAI,EAAM,EAAG,MAAU,YAAY,kCAAkC,EACrE,GAAO,EAAe,EAAK,MAAM,EAAG,EAAM,CAAC,CAAC,EAC5C,EAAI,EAAM,EACV,QACF,CAEA,GAAI,IAAO,IAAK,CACd,IAAM,EAAM,EAAK,QAAQ,IAAK,EAAI,CAAC,EACnC,GAAI,EAAM,EAAG,MAAU,YAAY,kCAAkC,EACrE,GAAO,EAAe,EAAK,MAAM,EAAG,EAAM,CAAC,CAAC,EAC5C,EAAI,EAAM,EACV,QACF,CAEA,GAAO,EACP,GACF,CAEA,OAAO,CACT,CAEA,SAAS,EAAgB,EAAc,EAAuB,CAC5D,IAAM,EAAM,EAAK,QAAQ;EAAM,CAAK,EACpC,OAAO,EAAM,EAAI,EAAK,OAAS,CACjC,CAEA,SAAS,EAAe,EAAsB,CAC5C,OAAO,EAAK,QAAQ,WAAY,GAAG,CACrC,CAKA,SAAS,EACP,EAC6B,CAC7B,GAAI,OAAO,GAAU,SAAU,CAC7B,IAAM,EAAI,KAAK,MAAM,KAAK,IAAI,GAAI,KAAK,IAAI,EAAG,CAAK,CAAC,CAAC,EACrD,OAAO,IAAM,EAAI,IAAA,GAAY,CAC/B,CACA,GAAI,OAAO,GAAU,SAEnB,OADU,EAAM,MAAM,EAAG,EAClB,GAAK,IAAA,EAGhB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { CBOROptions, CborExtension, FromCBOROptions, ToCBOROptions, FromEDNOptions, ToEDNOptions, FromJSOptions, ToJSOptions, FromHexDumpOptions, ToHexDumpOptions, } from './types';
|
|
1
|
+
export type { CBOROptions, CborExtension, FromCBOROptions, ToCBOROptions, FromCDNOptions, ToCDNOptions, FromEDNOptions, ToEDNOptions, FromJSOptions, ToJSOptions, FromHexDumpOptions, ToHexDumpOptions, } from './types';
|
|
2
2
|
export { CBOR_TAG, Null, Tag, Undefined } from './tag';
|
|
3
3
|
export { CBOR_OMIT } from './types';
|
|
4
4
|
export { Simple } from './simple';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as e, D as t, E as n, S as r, T as i, a, i as o, n as s, r as c, s as l, t as u, w as d } from "./mapEntries-
|
|
1
|
+
import { C as e, D as t, E as n, S as r, T as i, a, i as o, n as s, r as c, s as l, t as u, w as d } from "./mapEntries-Da-2HMRf.js";
|
|
2
2
|
//#region src/cbor.ts
|
|
3
3
|
var f = class t {
|
|
4
4
|
static OMIT = e;
|
|
@@ -21,10 +21,13 @@ var f = class t {
|
|
|
21
21
|
let r = t.fromCBOR(e, this.#t(n));
|
|
22
22
|
return r._defaults = this.#e, r;
|
|
23
23
|
}
|
|
24
|
-
|
|
25
|
-
let r = t.
|
|
24
|
+
fromCDN(e, n) {
|
|
25
|
+
let r = t.fromCDN(e, this.#t(n));
|
|
26
26
|
return r._defaults = this.#e, r;
|
|
27
27
|
}
|
|
28
|
+
fromEDN(e, t) {
|
|
29
|
+
return this.fromCDN(e, t);
|
|
30
|
+
}
|
|
28
31
|
fromJS(e, n) {
|
|
29
32
|
let r = t.fromJS(e, this.#t(n));
|
|
30
33
|
return r._defaults = this.#e, r;
|
|
@@ -39,19 +42,25 @@ var f = class t {
|
|
|
39
42
|
encode(e, n) {
|
|
40
43
|
return t.encode(e, this.#t(n));
|
|
41
44
|
}
|
|
42
|
-
cborToCborEdn(e,
|
|
43
|
-
return
|
|
45
|
+
cborToCborEdn(e, t) {
|
|
46
|
+
return this.cborToCdn(e, t);
|
|
47
|
+
}
|
|
48
|
+
cborToCdn(e, n) {
|
|
49
|
+
return t.cborToCdn(e, this.#t(n));
|
|
50
|
+
}
|
|
51
|
+
cborEdnToCbor(e, t) {
|
|
52
|
+
return this.cdnToCbor(e, t);
|
|
44
53
|
}
|
|
45
|
-
|
|
46
|
-
return t.
|
|
54
|
+
cdnToCbor(e, n) {
|
|
55
|
+
return t.cdnToCbor(e, this.#t(n));
|
|
47
56
|
}
|
|
48
57
|
parse(e, n) {
|
|
49
58
|
if (typeof n == "function") {
|
|
50
59
|
let r = this.#t({ reviver: n });
|
|
51
|
-
return t.
|
|
60
|
+
return t.fromCDN(e, r).toJS(r);
|
|
52
61
|
}
|
|
53
62
|
let r = this.#t(n);
|
|
54
|
-
return t.
|
|
63
|
+
return t.fromCDN(e, r).toJS(r);
|
|
55
64
|
}
|
|
56
65
|
stringify(e, n, r) {
|
|
57
66
|
if (typeof n == "function" || Array.isArray(n) || n === null || n === void 0 && r !== void 0) {
|
|
@@ -66,9 +75,12 @@ var f = class t {
|
|
|
66
75
|
static fromCBOR(e, t) {
|
|
67
76
|
return o(e, t);
|
|
68
77
|
}
|
|
69
|
-
static
|
|
78
|
+
static fromCDN(e, t) {
|
|
70
79
|
return l(e, t);
|
|
71
80
|
}
|
|
81
|
+
static fromEDN(e, n) {
|
|
82
|
+
return t.fromCDN(e, n);
|
|
83
|
+
}
|
|
72
84
|
static fromJS(e, t) {
|
|
73
85
|
return c(e, t);
|
|
74
86
|
}
|
|
@@ -86,35 +98,41 @@ var f = class t {
|
|
|
86
98
|
static encode(e, n) {
|
|
87
99
|
return t.fromJS(e, n).toCBOR(n);
|
|
88
100
|
}
|
|
101
|
+
static cborToCdn(e, n) {
|
|
102
|
+
return t.fromCBOR(e, n).toCDN(n);
|
|
103
|
+
}
|
|
89
104
|
static cborToCborEdn(e, n) {
|
|
90
|
-
return t.
|
|
105
|
+
return t.cborToCdn(e, n);
|
|
106
|
+
}
|
|
107
|
+
static cdnToCbor(e, n) {
|
|
108
|
+
return t.fromCDN(e, n).toCBOR(n);
|
|
91
109
|
}
|
|
92
110
|
static cborEdnToCbor(e, n) {
|
|
93
|
-
return t.
|
|
111
|
+
return t.cdnToCbor(e, n);
|
|
94
112
|
}
|
|
95
113
|
static parse(e, n) {
|
|
96
|
-
return typeof n == "function" ? t.
|
|
114
|
+
return typeof n == "function" ? t.fromCDN(e).toJS({ reviver: n }) : t.fromCDN(e, n).toJS(n);
|
|
97
115
|
}
|
|
98
116
|
static stringify(t, n, r) {
|
|
99
117
|
if (typeof n == "function" || Array.isArray(n) || n === null || n === void 0 && r !== void 0) {
|
|
100
118
|
let i = typeof n == "function" || Array.isArray(n) ? n : void 0, a = g(r);
|
|
101
119
|
if (i) {
|
|
102
120
|
let n = s(t, i);
|
|
103
|
-
return n === void 0 || n === e ? void 0 : c(n).
|
|
121
|
+
return n === void 0 || n === e ? void 0 : c(n).toCDN(a === void 0 ? void 0 : { indent: a });
|
|
104
122
|
}
|
|
105
|
-
return c(t).
|
|
123
|
+
return c(t).toCDN(a === void 0 ? void 0 : { indent: a });
|
|
106
124
|
}
|
|
107
125
|
let i = n;
|
|
108
126
|
if (i?.replacer) {
|
|
109
127
|
let n = s(t, i.replacer, i.extensions, i.undefinedOmits);
|
|
110
128
|
if (n === void 0 || n === e) return;
|
|
111
129
|
let { replacer: r, ...a } = i;
|
|
112
|
-
return c(n, Object.keys(a).length > 0 ? a : void 0).
|
|
130
|
+
return c(n, Object.keys(a).length > 0 ? a : void 0).toCDN(i);
|
|
113
131
|
}
|
|
114
|
-
return c(t, i).
|
|
132
|
+
return c(t, i).toCDN(i);
|
|
115
133
|
}
|
|
116
134
|
static format(e, n) {
|
|
117
|
-
return t.
|
|
135
|
+
return t.fromCDN(e, n).toCDN(n);
|
|
118
136
|
}
|
|
119
137
|
};
|
|
120
138
|
function p(e) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["#defaults","#merge"],"sources":["../src/cbor.ts"],"sourcesContent":["import type { CborItem } from './ast/CborItem';\nimport type {\n CBOROptions,\n FromCBOROptions,\n FromHexDumpOptions,\n FromEDNOptions,\n FromJSOptions,\n ToCBOROptions,\n ToEDNOptions,\n ToJSOptions,\n} from './types';\nimport { CBOR_OMIT } from './types';\nimport { decodeCBOR } from './cbor/decoder';\nimport { parseEDN } from './edn/parser';\nimport { dt_as_Date as _dt_as_Date } from './extensions/dt';\nimport { fromJS as _fromJS, _applyReplacer } from './js/fromJS';\nimport { MapEntries as _MapEntries } from './mapEntries';\nimport { Simple as _Simple } from './simple';\nimport { CBOR_TAG, Tag as _Tag } from './tag';\n\n/**\n * Main facade class.\n *\n * Provides factory methods for constructing AST nodes from the three\n * supported input formats, and shortcut methods that mirror the\n * `JSON.parse` / `JSON.stringify` API.\n *\n * @example\n * // CBOR binary → AST → CBOR binary\n * const ast = CBOR.fromCBOR(bytes);\n * const reencoded = ast.toCBOR();\n *\n * @example\n * // JS value → CBOR binary (shortcut)\n * const bytes = CBOR.encode({ hello: 'world' });\n *\n * @example\n * // CBOR binary → JS value (shortcut)\n * const value = CBOR.decode(bytes);\n */\nexport class CBOR {\n /**\n * Sentinel returned from a replacer or reviver to omit the key/element from\n * the output. Use this instead of `undefined` when `undefinedOmits` is\n * `false` (the default) and you need to drop a specific entry.\n */\n static readonly OMIT: typeof CBOR_OMIT = CBOR_OMIT;\n\n /** Unique symbol used to attach a CBOR tag number to a JS value. */\n static readonly TAG: typeof CBOR_TAG = CBOR_TAG;\n\n /** Namespace for CBOR tag annotation utilities. */\n static readonly Tag: typeof _Tag = _Tag;\n\n /** Wrapper for CBOR simple values other than false/true/null/undefined. */\n static readonly Simple: typeof _Simple = _Simple;\n\n /** Array subclass used to preserve CBOR map entries, including duplicates. */\n static readonly MapEntries: typeof _MapEntries = _MapEntries;\n\n /** Extension that maps CBOR-EDN dt/DT values to JavaScript Date objects. */\n static readonly dt_as_Date: typeof _dt_as_Date = _dt_as_Date;\n\n // ─── Instance API ───────────────────────────────────────────────────────────\n\n readonly #defaults: CBOROptions;\n\n /**\n * Create a reusable instance with default options applied to every method call.\n * Per-call options always override these defaults.\n *\n * @example\n * const cbor = new CBOR({ extensions: [CBOR.dt_as_Date] });\n * const obj = cbor.parse('{ \"dt\": DT\\'2024-01-01T00:00:00Z\\' }');\n * const text = cbor.stringify(obj);\n */\n constructor(defaults?: CBOROptions) {\n this.#defaults = defaults ?? {};\n }\n\n #merge<T extends object>(perCall?: T): CBOROptions & T {\n return { ...this.#defaults, ...(perCall ?? {}) } as CBOROptions & T;\n }\n\n fromCBOR(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions\n ): CborItem {\n const node = CBOR.fromCBOR(input, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n fromEDN(text: string, options?: FromEDNOptions): CborItem {\n const node = CBOR.fromEDN(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n fromJS(value: unknown, options?: FromJSOptions): CborItem {\n const node = CBOR.fromJS(value, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n fromHexDump(text: string, options?: FromHexDumpOptions): CborItem {\n const node = CBOR.fromHexDump(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.decode(input, this.#merge(options));\n }\n\n encode(value: unknown, options?: FromJSOptions & ToCBOROptions): Uint8Array {\n return CBOR.encode(value, this.#merge(options));\n }\n\n /**\n * @deprecated Use `fromCBOR(input, options).toEDN(options)` instead.\n */\n cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToEDNOptions\n ): string {\n return CBOR.cborToCborEdn(input, this.#merge(options));\n }\n\n /**\n * @deprecated Use `fromEDN(text, options).toCBOR(options)` instead.\n */\n cborEdnToCbor(\n text: string,\n options?: FromEDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.cborEdnToCbor(text, this.#merge(options));\n }\n\n parse(text: string): unknown;\n parse(\n text: string,\n reviver: (this: unknown, key: unknown, value: unknown) => unknown\n ): unknown;\n parse(text: string, options: FromEDNOptions & ToJSOptions): unknown;\n parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromEDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n const merged = this.#merge<ToJSOptions>({ reviver: arg2 });\n return CBOR.fromEDN(text, merged).toJS(merged);\n }\n const merged = this.#merge(arg2);\n return CBOR.fromEDN(text, merged).toJS(merged);\n }\n\n stringify(value: unknown): string;\n stringify(\n value: unknown,\n replacer:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null,\n space?: string | number\n ): string;\n stringify(value: unknown, options: FromJSOptions & ToEDNOptions): string;\n stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToEDNOptions),\n arg3?: string | number\n ): string {\n if (\n typeof arg2 === 'function' ||\n Array.isArray(arg2) ||\n arg2 === null ||\n (arg2 === undefined && arg3 !== undefined)\n ) {\n const opts: FromJSOptions & ToEDNOptions = {\n ...(this.#defaults as FromJSOptions & ToEDNOptions),\n };\n if (arg2 === null) {\n opts.replacer = undefined;\n } else if (typeof arg2 === 'function' || Array.isArray(arg2)) {\n opts.replacer = arg2;\n }\n if (arg3 !== undefined) opts.indent = resolveSpace(arg3);\n return CBOR.stringify(value, opts);\n }\n return CBOR.stringify(value, this.#merge(arg2 ?? undefined));\n }\n\n format(text: string, options?: FromEDNOptions & ToEDNOptions): string {\n return CBOR.format(text, this.#merge(options));\n }\n\n // ─── Factory methods ────────────────────────────────────────────────────────\n\n /** Decode CBOR binary data into an AST node. */\n static fromCBOR(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions\n ): CborItem {\n return decodeCBOR(input, options);\n }\n\n /** Parse a CBOR-EDN text string into an AST node. */\n static fromEDN(text: string, options?: FromEDNOptions): CborItem {\n return parseEDN(text, options);\n }\n\n /** Convert a JavaScript value into an AST node. */\n static fromJS(value: unknown, options?: FromJSOptions): CborItem {\n return _fromJS(value, options);\n }\n\n /**\n * Parse an annotated hex dump (as produced by {@link CborItem#toHexDump})\n * into an AST node.\n *\n * Each line is expected to have the form:\n * `[whitespace] HH [HH …] -- comment`\n * `[whitespace] HH [HH …] # comment`\n * `[whitespace] HH [HH …] // comment`\n * Block comments may also be written as `/ comment /` or `/* comment *\\/`.\n * Lines with no hex content before the comment marker are ignored.\n */\n static fromHexDump(text: string, options?: FromHexDumpOptions): CborItem {\n const bytes: number[] = [];\n const uncommented = stripHexDumpComments(text);\n const tokens = uncommented.trim().split(/\\s+/).filter(Boolean);\n for (const token of tokens) {\n if (!/^[0-9A-Fa-f]{2}$/.test(token))\n throw new SyntaxError(\n `Invalid hex token in dump: ${JSON.stringify(token)}`\n );\n bytes.push(parseInt(token, 16));\n }\n return decodeCBOR(new Uint8Array(bytes), options);\n }\n\n // ─── Shortcut API ───────────────────────────────────────────────────────────\n\n /** Decode CBOR binary data directly to a JavaScript value. */\n static decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.fromCBOR(input, options).toJS(options);\n }\n\n /** Encode a JavaScript value directly to CBOR binary data. */\n static encode(\n value: unknown,\n options?: FromJSOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromJS(value, options).toCBOR(options);\n }\n\n /**\n * Convert CBOR binary data directly to a CBOR-EDN text string.\n *\n * @deprecated Use `CBOR.fromCBOR(input, options).toEDN(options)` instead.\n */\n static cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToEDNOptions\n ): string {\n return CBOR.fromCBOR(input, options).toEDN(options);\n }\n\n /**\n * Convert a CBOR-EDN text string directly to CBOR binary data.\n *\n * @deprecated Use `CBOR.fromEDN(text, options).toCBOR(options)` instead.\n */\n static cborEdnToCbor(\n text: string,\n options?: FromEDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromEDN(text, options).toCBOR(options);\n }\n\n /**\n * Parse a CBOR-EDN text string directly to a JavaScript value.\n *\n * Accepts either a JSON-compatible `reviver` function as the second argument,\n * or a plain options object (existing API).\n *\n * When a `reviver` is supplied it is applied bottom-up after the EDN text has\n * been parsed and converted to a JS value, matching the semantics of\n * `JSON.parse(text, reviver)`.\n *\n * Note: CBOR-specific value types such as `bigint` are passed to the reviver\n * as-is; the reviver is responsible for handling them.\n */\n static parse(text: string): unknown;\n static parse(\n text: string,\n reviver: (this: unknown, key: unknown, value: unknown) => unknown\n ): unknown;\n static parse(text: string, options: FromEDNOptions & ToJSOptions): unknown;\n static parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromEDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n return CBOR.fromEDN(text).toJS({ reviver: arg2 });\n }\n return CBOR.fromEDN(text, arg2).toJS(arg2);\n }\n\n /**\n * Serialize a JavaScript value directly to a CBOR-EDN text string.\n *\n * Accepts either JSON-compatible `replacer` + `space` arguments, or a plain\n * options object (existing API).\n *\n * - `replacer` may be a function (transforms each key/value before encoding)\n * or an array of strings/numbers (allowlist of object keys to include).\n * Pass `null` to skip filtering.\n * - `space` controls indentation, mapping to `ToEDNOptions.indent`.\n * Numbers are clamped to `[0, 10]`; strings are truncated to 10 characters.\n */\n static stringify(value: unknown): string;\n static stringify(\n value: unknown,\n replacer:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null,\n space?: string | number\n ): string;\n static stringify(\n value: unknown,\n options: FromJSOptions & ToEDNOptions\n ): string;\n static stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToEDNOptions),\n arg3?: string | number\n ): string {\n if (\n typeof arg2 === 'function' ||\n Array.isArray(arg2) ||\n arg2 === null ||\n (arg2 === undefined && arg3 !== undefined)\n ) {\n const replacer =\n typeof arg2 === 'function' || Array.isArray(arg2) ? arg2 : undefined;\n const indent = resolveSpace(arg3);\n if (replacer) {\n // Mirror JSON.stringify: if the replacer drops the root, return undefined.\n const replaced = _applyReplacer(value, replacer);\n if (replaced === undefined || replaced === CBOR_OMIT)\n return undefined as unknown as string;\n return _fromJS(replaced).toEDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n return _fromJS(value).toEDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n // Options form: also mirror JSON.stringify root-drop semantics.\n const opts = arg2 as (FromJSOptions & ToEDNOptions) | undefined;\n if (opts?.replacer) {\n const replaced = _applyReplacer(\n value,\n opts.replacer,\n opts.extensions,\n opts.undefinedOmits\n );\n if (replaced === undefined || replaced === CBOR_OMIT)\n return undefined as unknown as string;\n const { replacer: _r, ...restFromJS } = opts;\n return _fromJS(\n replaced,\n Object.keys(restFromJS).length > 0\n ? (restFromJS as FromJSOptions)\n : undefined\n ).toEDN(opts);\n }\n return _fromJS(value, opts as FromJSOptions | undefined).toEDN(opts);\n }\n\n /** Normalize a CBOR-EDN text string by parsing and re-serializing it. */\n static format(text: string, options?: FromEDNOptions & ToEDNOptions): string {\n return CBOR.fromEDN(text, options).toEDN(options);\n }\n}\n\nfunction stripHexDumpComments(text: string): string {\n let out = '';\n let i = 0;\n\n while (i < text.length) {\n const ch = text[i];\n const next = text[i + 1] ?? '';\n\n if (ch === '-' && next === '-') {\n i = skipLineComment(text, i + 2);\n out += ' ';\n continue;\n }\n\n if (ch === '#') {\n i = skipLineComment(text, i + 1);\n out += ' ';\n continue;\n }\n\n if (ch === '/' && next === '/') {\n i = skipLineComment(text, i + 2);\n out += ' ';\n continue;\n }\n\n if (ch === '/' && next === '*') {\n const end = text.indexOf('*/', i + 2);\n if (end < 0) throw new SyntaxError('Unterminated comment in hex dump');\n out += whitespaceLike(text.slice(i, end + 2));\n i = end + 2;\n continue;\n }\n\n if (ch === '/') {\n const end = text.indexOf('/', i + 1);\n if (end < 0) throw new SyntaxError('Unterminated comment in hex dump');\n out += whitespaceLike(text.slice(i, end + 1));\n i = end + 1;\n continue;\n }\n\n out += ch;\n i++;\n }\n\n return out;\n}\n\nfunction skipLineComment(text: string, start: number): number {\n const end = text.indexOf('\\n', start);\n return end < 0 ? text.length : end;\n}\n\nfunction whitespaceLike(text: string): string {\n return text.replace(/[^\\r\\n]/g, ' ');\n}\n\n// ─── Module-scope helper ─────────────────────────────────────────────────────\n\n/** Map JSON.stringify `space` argument to ToEDNOptions.indent. */\nfunction resolveSpace(\n space: string | number | undefined\n): string | number | undefined {\n if (typeof space === 'number') {\n const n = Math.floor(Math.min(10, Math.max(0, space)));\n return n === 0 ? undefined : n;\n }\n if (typeof space === 'string') {\n const s = space.slice(0, 10);\n return s || undefined;\n }\n return undefined;\n}\n"],"mappings":";;AAwCA,IAAa,IAAb,MAAa,EAAK;CAMhB,OAAgB,OAAyB;CAGzC,OAAgB,MAAuB;CAGvC,OAAgB,MAAmB;CAGnC,OAAgB,SAAyB;CAGzC,OAAgB,aAAiC;CAGjD,OAAgB,aAAiC;CAIjD;CAWA,YAAY,GAAwB;EAClC,KAAKA,KAAY,KAAY,EAAE;;CAGjC,GAAyB,GAA8B;EACrD,OAAO;GAAE,GAAG,KAAKA;GAAW,GAAI,KAAW,EAAE;GAAG;;CAGlD,SACE,GACA,GACU;EACV,IAAM,IAAO,EAAK,SAAS,GAAO,KAAKC,GAAO,EAAQ,CAAC;EAEvD,OADA,EAAK,YAAY,KAAKD,IACf;;CAGT,QAAQ,GAAc,GAAoC;EACxD,IAAM,IAAO,EAAK,QAAQ,GAAM,KAAKC,GAAO,EAAQ,CAAC;EAErD,OADA,EAAK,YAAY,KAAKD,IACf;;CAGT,OAAO,GAAgB,GAAmC;EACxD,IAAM,IAAO,EAAK,OAAO,GAAO,KAAKC,GAAO,EAAQ,CAAC;EAErD,OADA,EAAK,YAAY,KAAKD,IACf;;CAGT,YAAY,GAAc,GAAwC;EAChE,IAAM,IAAO,EAAK,YAAY,GAAM,KAAKC,GAAO,EAAQ,CAAC;EAEzD,OADA,EAAK,YAAY,KAAKD,IACf;;CAGT,OACE,GACA,GACS;EACT,OAAO,EAAK,O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AM,EAAK,QAAQ,KAAK,IAAI,EAAE;GACpC,IAAI,IAAM,GAAG,MAAU,YAAY,mCAAmC;GAEtE,AADA,KAAO,EAAe,EAAK,MAAM,GAAG,IAAM,EAAE,CAAC,EAC7C,IAAI,IAAM;GACV;;EAIF,AADA,KAAO,GACP;;CAGF,OAAO;;AAGT,SAAS,EAAgB,GAAc,GAAuB;CAC5D,IAAM,IAAM,EAAK,QAAQ,MAAM,EAAM;CACrC,OAAO,IAAM,IAAI,EAAK,SAAS;;AAGjC,SAAS,EAAe,GAAsB;CAC5C,OAAO,EAAK,QAAQ,YAAY,IAAI;;AAMtC,SAAS,EACP,GAC6B;CAC7B,IAAI,OAAO,KAAU,UAAU;EAC7B,IAAM,IAAI,KAAK,MAAM,KAAK,IAAI,IAAI,KAAK,IAAI,GAAG,EAAM,CAAC,CAAC;EACtD,OAAO,MAAM,IAAI,KAAA,IAAY;;CAE/B,IAAI,OAAO,KAAU,UAEnB,OADU,EAAM,MAAM,GAAG,GAClB,IAAK,KAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["#defaults","#merge"],"sources":["../src/cbor.ts"],"sourcesContent":["import type { CborItem } from './ast/CborItem';\nimport type {\n CBOROptions,\n FromCBOROptions,\n FromCDNOptions,\n FromHexDumpOptions,\n FromJSOptions,\n ToCBOROptions,\n ToCDNOptions,\n ToJSOptions,\n} from './types';\nimport { CBOR_OMIT } from './types';\nimport { decodeCBOR } from './cbor/decoder';\nimport { parseCDN } from './cdn/parser';\nimport { dt_as_Date as _dt_as_Date } from './extensions/dt';\nimport { fromJS as _fromJS, _applyReplacer } from './js/fromJS';\nimport { MapEntries as _MapEntries } from './mapEntries';\nimport { Simple as _Simple } from './simple';\nimport { CBOR_TAG, Tag as _Tag } from './tag';\n\n/**\n * Main facade class.\n *\n * Provides factory methods for constructing AST nodes from the three\n * supported input formats, and shortcut methods that mirror the\n * `JSON.parse` / `JSON.stringify` API.\n *\n * @example\n * // CBOR binary → AST → CBOR binary\n * const ast = CBOR.fromCBOR(bytes);\n * const reencoded = ast.toCBOR();\n *\n * @example\n * // JS value → CBOR binary (shortcut)\n * const bytes = CBOR.encode({ hello: 'world' });\n *\n * @example\n * // CBOR binary → JS value (shortcut)\n * const value = CBOR.decode(bytes);\n */\nexport class CBOR {\n /**\n * Sentinel returned from a replacer or reviver to omit the key/element from\n * the output. Use this instead of `undefined` when `undefinedOmits` is\n * `false` (the default) and you need to drop a specific entry.\n */\n static readonly OMIT: typeof CBOR_OMIT = CBOR_OMIT;\n\n /** Unique symbol used to attach a CBOR tag number to a JS value. */\n static readonly TAG: typeof CBOR_TAG = CBOR_TAG;\n\n /** Namespace for CBOR tag annotation utilities. */\n static readonly Tag: typeof _Tag = _Tag;\n\n /** Wrapper for CBOR simple values other than false/true/null/undefined. */\n static readonly Simple: typeof _Simple = _Simple;\n\n /** Array subclass used to preserve CBOR map entries, including duplicates. */\n static readonly MapEntries: typeof _MapEntries = _MapEntries;\n\n /** Extension that maps CDN dt/DT values to JavaScript Date objects. */\n static readonly dt_as_Date: typeof _dt_as_Date = _dt_as_Date;\n\n // ─── Instance API ───────────────────────────────────────────────────────────\n\n readonly #defaults: CBOROptions;\n\n /**\n * Create a reusable instance with default options applied to every method call.\n * Per-call options always override these defaults.\n *\n * @example\n * const cbor = new CBOR({ extensions: [CBOR.dt_as_Date] });\n * const obj = cbor.parse('{ \"dt\": DT\\'2024-01-01T00:00:00Z\\' }');\n * const text = cbor.stringify(obj);\n */\n constructor(defaults?: CBOROptions) {\n this.#defaults = defaults ?? {};\n }\n\n #merge<T extends object>(perCall?: T): CBOROptions & T {\n return { ...this.#defaults, ...(perCall ?? {}) } as CBOROptions & T;\n }\n\n fromCBOR(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions\n ): CborItem {\n const node = CBOR.fromCBOR(input, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n fromCDN(text: string, options?: FromCDNOptions): CborItem {\n const node = CBOR.fromCDN(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n /** @deprecated Use `fromCDN()` instead. */\n fromEDN(text: string, options?: FromCDNOptions): CborItem {\n return this.fromCDN(text, options);\n }\n\n fromJS(value: unknown, options?: FromJSOptions): CborItem {\n const node = CBOR.fromJS(value, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n fromHexDump(text: string, options?: FromHexDumpOptions): CborItem {\n const node = CBOR.fromHexDump(text, this.#merge(options));\n node._defaults = this.#defaults;\n return node;\n }\n\n decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.decode(input, this.#merge(options));\n }\n\n encode(value: unknown, options?: FromJSOptions & ToCBOROptions): Uint8Array {\n return CBOR.encode(value, this.#merge(options));\n }\n\n /**\n * @deprecated Use `cborToCdn()` or `fromCBOR(input, options).toCDN(options)` instead.\n */\n cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return this.cborToCdn(input, options);\n }\n\n cborToCdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return CBOR.cborToCdn(input, this.#merge(options));\n }\n\n /**\n * @deprecated Use `cdnToCbor()` or `fromCDN(text, options).toCBOR(options)` instead.\n */\n cborEdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return this.cdnToCbor(text, options);\n }\n\n cdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.cdnToCbor(text, this.#merge(options));\n }\n\n parse(text: string): unknown;\n parse(\n text: string,\n reviver: (this: unknown, key: unknown, value: unknown) => unknown\n ): unknown;\n parse(text: string, options: FromCDNOptions & ToJSOptions): unknown;\n parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromCDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n const merged = this.#merge<ToJSOptions>({ reviver: arg2 });\n return CBOR.fromCDN(text, merged).toJS(merged);\n }\n const merged = this.#merge(arg2);\n return CBOR.fromCDN(text, merged).toJS(merged);\n }\n\n stringify(value: unknown): string;\n stringify(\n value: unknown,\n replacer:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null,\n space?: string | number\n ): string;\n stringify(value: unknown, options: FromJSOptions & ToCDNOptions): string;\n stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToCDNOptions),\n arg3?: string | number\n ): string {\n if (\n typeof arg2 === 'function' ||\n Array.isArray(arg2) ||\n arg2 === null ||\n (arg2 === undefined && arg3 !== undefined)\n ) {\n const opts: FromJSOptions & ToCDNOptions = {\n ...(this.#defaults as FromJSOptions & ToCDNOptions),\n };\n if (arg2 === null) {\n opts.replacer = undefined;\n } else if (typeof arg2 === 'function' || Array.isArray(arg2)) {\n opts.replacer = arg2;\n }\n if (arg3 !== undefined) opts.indent = resolveSpace(arg3);\n return CBOR.stringify(value, opts);\n }\n return CBOR.stringify(value, this.#merge(arg2 ?? undefined));\n }\n\n format(text: string, options?: FromCDNOptions & ToCDNOptions): string {\n return CBOR.format(text, this.#merge(options));\n }\n\n // ─── Factory methods ────────────────────────────────────────────────────────\n\n /** Decode CBOR binary data into an AST node. */\n static fromCBOR(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions\n ): CborItem {\n return decodeCBOR(input, options);\n }\n\n /** Parse a CDN text string into an AST node. */\n static fromCDN(text: string, options?: FromCDNOptions): CborItem {\n return parseCDN(text, options);\n }\n\n /**\n * Parse a CDN text string into an AST node.\n *\n * @deprecated Use `fromCDN()` instead.\n */\n static fromEDN(text: string, options?: FromCDNOptions): CborItem {\n return CBOR.fromCDN(text, options);\n }\n\n /** Convert a JavaScript value into an AST node. */\n static fromJS(value: unknown, options?: FromJSOptions): CborItem {\n return _fromJS(value, options);\n }\n\n /**\n * Parse an annotated hex dump (as produced by {@link CborItem#toHexDump})\n * into an AST node.\n *\n * Each line is expected to have the form:\n * `[whitespace] HH [HH …] -- comment`\n * `[whitespace] HH [HH …] # comment`\n * `[whitespace] HH [HH …] // comment`\n * Block comments may also be written as `/ comment /` or `/* comment *\\/`.\n * Lines with no hex content before the comment marker are ignored.\n */\n static fromHexDump(text: string, options?: FromHexDumpOptions): CborItem {\n const bytes: number[] = [];\n const uncommented = stripHexDumpComments(text);\n const tokens = uncommented.trim().split(/\\s+/).filter(Boolean);\n for (const token of tokens) {\n if (!/^[0-9A-Fa-f]{2}$/.test(token))\n throw new SyntaxError(\n `Invalid hex token in dump: ${JSON.stringify(token)}`\n );\n bytes.push(parseInt(token, 16));\n }\n return decodeCBOR(new Uint8Array(bytes), options);\n }\n\n // ─── Shortcut API ───────────────────────────────────────────────────────────\n\n /** Decode CBOR binary data directly to a JavaScript value. */\n static decode(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToJSOptions\n ): unknown {\n return CBOR.fromCBOR(input, options).toJS(options);\n }\n\n /** Encode a JavaScript value directly to CBOR binary data. */\n static encode(\n value: unknown,\n options?: FromJSOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromJS(value, options).toCBOR(options);\n }\n\n /**\n * Convert CBOR binary data directly to a CDN text string.\n */\n static cborToCdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return CBOR.fromCBOR(input, options).toCDN(options);\n }\n\n /**\n * Convert CBOR binary data directly to a CDN text string.\n *\n * @deprecated Use `CBOR.cborToCdn()` or `CBOR.fromCBOR(input, options).toCDN(options)` instead.\n */\n static cborToCborEdn(\n input: ArrayBufferView | ArrayBufferLike,\n options?: FromCBOROptions & ToCDNOptions\n ): string {\n return CBOR.cborToCdn(input, options);\n }\n\n /**\n * Convert a CDN text string directly to CBOR binary data.\n */\n static cdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.fromCDN(text, options).toCBOR(options);\n }\n\n /**\n * Convert a CDN text string directly to CBOR binary data.\n *\n * @deprecated Use `CBOR.cdnToCbor()` or `CBOR.fromCDN(text, options).toCBOR(options)` instead.\n */\n static cborEdnToCbor(\n text: string,\n options?: FromCDNOptions & ToCBOROptions\n ): Uint8Array {\n return CBOR.cdnToCbor(text, options);\n }\n\n /**\n * Parse a CDN text string directly to a JavaScript value.\n *\n * Accepts either a JSON-compatible `reviver` function as the second argument,\n * or a plain options object (existing API).\n *\n * When a `reviver` is supplied it is applied bottom-up after the CDN text has\n * been parsed and converted to a JS value, matching the semantics of\n * `JSON.parse(text, reviver)`.\n *\n * Note: CBOR-specific value types such as `bigint` are passed to the reviver\n * as-is; the reviver is responsible for handling them.\n */\n static parse(text: string): unknown;\n static parse(\n text: string,\n reviver: (this: unknown, key: unknown, value: unknown) => unknown\n ): unknown;\n static parse(text: string, options: FromCDNOptions & ToJSOptions): unknown;\n static parse(\n text: string,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (FromCDNOptions & ToJSOptions)\n ): unknown {\n if (typeof arg2 === 'function') {\n return CBOR.fromCDN(text).toJS({ reviver: arg2 });\n }\n return CBOR.fromCDN(text, arg2).toJS(arg2);\n }\n\n /**\n * Serialize a JavaScript value directly to a CDN text string.\n *\n * Accepts either JSON-compatible `replacer` + `space` arguments, or a plain\n * options object (existing API).\n *\n * - `replacer` may be a function (transforms each key/value before encoding)\n * or an array of strings/numbers (allowlist of object keys to include).\n * Pass `null` to skip filtering.\n * - `space` controls indentation, mapping to `ToCDNOptions.indent`.\n * Numbers are clamped to `[0, 10]`; strings are truncated to 10 characters.\n */\n static stringify(value: unknown): string;\n static stringify(\n value: unknown,\n replacer:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null,\n space?: string | number\n ): string;\n static stringify(\n value: unknown,\n options: FromJSOptions & ToCDNOptions\n ): string;\n static stringify(\n value: unknown,\n arg2?:\n | ((this: unknown, key: unknown, value: unknown) => unknown)\n | (string | number)[]\n | null\n | (FromJSOptions & ToCDNOptions),\n arg3?: string | number\n ): string {\n if (\n typeof arg2 === 'function' ||\n Array.isArray(arg2) ||\n arg2 === null ||\n (arg2 === undefined && arg3 !== undefined)\n ) {\n const replacer =\n typeof arg2 === 'function' || Array.isArray(arg2) ? arg2 : undefined;\n const indent = resolveSpace(arg3);\n if (replacer) {\n // Mirror JSON.stringify: if the replacer drops the root, return undefined.\n const replaced = _applyReplacer(value, replacer);\n if (replaced === undefined || replaced === CBOR_OMIT)\n return undefined as unknown as string;\n return _fromJS(replaced).toCDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n return _fromJS(value).toCDN(\n indent !== undefined ? { indent } : undefined\n );\n }\n // Options form: also mirror JSON.stringify root-drop semantics.\n const opts = arg2 as (FromJSOptions & ToCDNOptions) | undefined;\n if (opts?.replacer) {\n const replaced = _applyReplacer(\n value,\n opts.replacer,\n opts.extensions,\n opts.undefinedOmits\n );\n if (replaced === undefined || replaced === CBOR_OMIT)\n return undefined as unknown as string;\n const { replacer: _r, ...restFromJS } = opts;\n return _fromJS(\n replaced,\n Object.keys(restFromJS).length > 0\n ? (restFromJS as FromJSOptions)\n : undefined\n ).toCDN(opts);\n }\n return _fromJS(value, opts as FromJSOptions | undefined).toCDN(opts);\n }\n\n /** Normalize a CDN text string by parsing and re-serializing it. */\n static format(text: string, options?: FromCDNOptions & ToCDNOptions): string {\n return CBOR.fromCDN(text, options).toCDN(options);\n }\n}\n\nfunction stripHexDumpComments(text: string): string {\n let out = '';\n let i = 0;\n\n while (i < text.length) {\n const ch = text[i];\n const next = text[i + 1] ?? '';\n\n if (ch === '-' && next === '-') {\n i = skipLineComment(text, i + 2);\n out += ' ';\n continue;\n }\n\n if (ch === '#') {\n i = skipLineComment(text, i + 1);\n out += ' ';\n continue;\n }\n\n if (ch === '/' && next === '/') {\n i = skipLineComment(text, i + 2);\n out += ' ';\n continue;\n }\n\n if (ch === '/' && next === '*') {\n const end = text.indexOf('*/', i + 2);\n if (end < 0) throw new SyntaxError('Unterminated comment in hex dump');\n out += whitespaceLike(text.slice(i, end + 2));\n i = end + 2;\n continue;\n }\n\n if (ch === '/') {\n const end = text.indexOf('/', i + 1);\n if (end < 0) throw new SyntaxError('Unterminated comment in hex dump');\n out += whitespaceLike(text.slice(i, end + 1));\n i = end + 1;\n continue;\n }\n\n out += ch;\n i++;\n }\n\n return out;\n}\n\nfunction skipLineComment(text: string, start: number): number {\n const end = text.indexOf('\\n', start);\n return end < 0 ? text.length : end;\n}\n\nfunction whitespaceLike(text: string): string {\n return text.replace(/[^\\r\\n]/g, ' ');\n}\n\n// ─── Module-scope helper ─────────────────────────────────────────────────────\n\n/** Map JSON.stringify `space` argument to ToCDNOptions.indent. */\nfunction resolveSpace(\n space: string | number | undefined\n): string | number | undefined {\n if (typeof space === 'number') {\n const n = Math.floor(Math.min(10, Math.max(0, space)));\n return n === 0 ? undefined : n;\n }\n if (typeof space === 'string') {\n const s = space.slice(0, 10);\n return s || undefined;\n }\n return undefined;\n}\n"],"mappings":";;AAwCA,IAAa,IAAb,MAAa,EAAK;CAMhB,OAAgB,OAAyB;CAGzC,OAAgB,MAAuB;CAGvC,OAAgB,MAAmB;CAGnC,OAAgB,SAAyB;CAGzC,OAAgB,aAAiC;CAGjD,OAAgB,aAAiC;CAIjD;CAWA,YAAY,GAAwB;EAClC,KAAKA,KAAY,KAAY,CAAC;CAChC;CAEA,GAAyB,GAA8B;EACrD,OAAO;GAAE,GAAG,KAAKA;GAAW,GAAI,KAAW,CAAC;EAAG;CACjD;CAEA,SACE,GACA,GACU;EACV,IAAM,IAAO,EAAK,SAAS,GAAO,KAAKC,GAAO,CAAO,CAAC;EAEtD,OADA,EAAK,YAAY,KAAKD,IACf;CACT;CAEA,QAAQ,GAAc,GAAoC;EACxD,IAAM,IAAO,EAAK,QAAQ,GAAM,KAAKC,GAAO,CAAO,CAAC;EA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AKA,SAAS,EACP,GAC6B;CAC7B,IAAI,OAAO,KAAU,UAAU;EAC7B,IAAM,IAAI,KAAK,MAAM,KAAK,IAAI,IAAI,KAAK,IAAI,GAAG,CAAK,CAAC,CAAC;EACrD,OAAO,MAAM,IAAI,KAAA,IAAY;CAC/B;CACA,IAAI,OAAO,KAAU,UAEnB,OADU,EAAM,MAAM,GAAG,EAClB,KAAK,KAAA;AAGhB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var e=Symbol.for(`cbor.tag`),t=class{valueOf(){return null}toJSON(){return null}},n=class{valueOf(){}toJSON(){}};function r(t){if(!s(t))return;let n=t[e];return typeof n==`bigint`?n:void 0}function i(r,i){let a;switch(typeof r){case`number`:a=new Number(r);break;case`string`:a=new String(r);break;case`boolean`:a=new Boolean(r);break;case`bigint`:a=Object(r);break;case`undefined`:a=new n;break;case`object`:if(r===null){a=new t;break}a=r;break;default:throw TypeError(`setCborTag: cannot tag value of type ${typeof r}`)}return a[e]=i,a}function a(r){if(r instanceof Number||r instanceof String||r instanceof Boolean||Object.prototype.toString.call(r)===`[object BigInt]`)return r.valueOf();if(r instanceof t)return null;if(!(r instanceof n))return typeof r==`object`&&r&&delete r[e],r}function o(e){if(e instanceof Number||e instanceof String||e instanceof Boolean||Object.prototype.toString.call(e)===`[object BigInt]`)return e.valueOf();if(e instanceof t)return null;if(!(e instanceof n))return e}function s(e){return typeof e==`object`&&!!e}var c=class{constructor(){}static symbol=e;static Null=t;static Undefined=n;static get(e){return r(e)}static set(e,t){return i(e,t)}static remove(e){return a(e)}static getValue(e){return o(e)}},l=Symbol(`cbor.omit`),u=class e{value;constructor(e){if(!Number.isInteger(e)||e<0||e>255)throw RangeError(`Simple value must be an integer in 0–255`);this.value=e}valueOf(){return this.value}toJSON(){throw TypeError(`simple(${this.value}) cannot be serialized to JSON`)}static is(t){return t instanceof e}static get(t){return t instanceof e?t.value:void 0}},d=class{start;end;comments;_defaults;toCBOR(e){let t=this._defaults?{...this._defaults,...e}:e;return this._toCBOR(t)}toCDN(e){let t=this._defaults?{...this._defaults,...e}:e,n=this._toCDN(t,0);if(!t?.preserveComments)return n;let r=this.comments?.leading?.map(e=>e.text)??[],i=this.comments?.trailing??[],a=i.length===0?n:`${n} ${i.map(e=>e.text.trimEnd()).join(` `)}`;return[...r,a].join(`
|
|
2
|
+
`)}toEDN(e){return this.toCDN(e)}toJS(e){let t=this._defaults?{...this._defaults,...e}:e,n=this._toJS(t);if(!t?.reviver)return n;let r=t.reviver.call({"":n},``,n);return r===l?void 0:r}toHexDump(e){let t=this._defaults?{...this._defaults,...e}:e,n=t?.indent??3,r=typeof n==`string`?n:` `.repeat(n),i=(t?.commentStyle??`--`)+` `,a=this._toHexDump(0,t),o=Math.max(...a.map(e=>e.depth*r.length+e.hex.length))+2;return a.map(e=>(r.repeat(e.depth)+e.hex).padEnd(o)+i+e.comment).join(`
|
|
3
|
+
`)}_toHexDump(e,t){return[{depth:e,hex:Array.from(this._toCBOR(),e=>e.toString(16).toUpperCase().padStart(2,`0`)).join(` `),comment:this._toCDN(t,0)}]}},f=`getFloat16`in DataView.prototype&&`setFloat16`in DataView.prototype,p=new DataView(new ArrayBuffer(8));function ee(e){p.setFloat64(0,e,!1);let t=p.getUint32(0,!1),n=p.getUint32(4,!1),r=t>>>31&1,i=t>>>20&2047,a=t&1048575;if(i===2047){if(a===0&&n===0)return r<<15|31744;let e=a>>10|(n===0?0:1)||1;return r<<15|31744|e&1023}let o=i-1023+15;if(o>=31)return r<<15|31744;let s,c,l;if(o<=0){if(o<-10)return r<<15;let e=1<<20|a,t=11-o;t<=20?(s=e>>t&1023,c=e>>t-1&1,l=(e&(1<<t-1)-1)!=0||n!==0):(s=0,c=1,l=a!==0||n!==0)}else s=a>>10,c=a>>9&1,l=(a&511)!=0||n!==0;if(c!==0&&(l||s&1)&&s++,s>=1024){let e=o<=0?1:o+1;return e>=31?r<<15|31744:r<<15|e<<10}let u=o<=0?0:o;return r<<15|u<<10|s}function te(e){let t=e>>>15&1,n=e>>>10&31,r=e&1023;return n===31?r===0?t?-1/0:1/0:NaN:n===0?r===0?t?-0:0:(t?-1:1)*2**-14*(r/1024):(t?-1:1)*2**(n-15)*(1+r/1024)}var ne=f?(e,t,n,r)=>{e.setFloat16(t,n,r)}:(e,t,n,r)=>{e.setUint16(t,ee(n),r)};function m(e,t,n){if(n!==void 0){if(n===`i`){if(t>23n)throw RangeError(`value ${t} does not fit in immediate encoding _i (max 23)`);return new Uint8Array([e<<5|Number(t)])}let r=[255n,65535n,4294967295n,18446744073709551615n];if(t>r[n])throw RangeError(`value ${t} does not fit in encodingWidth _${n} (max ${r[n]})`);let i=24+n;if(i===24)return new Uint8Array([e<<5|24,Number(t)]);if(i===25){let n=new Uint8Array(3);return n[0]=e<<5|25,n[1]=Number(t>>8n),n[2]=Number(t&255n),n}if(i===26){let n=new Uint8Array(5);return n[0]=e<<5|26,new DataView(n.buffer).setUint32(1,Number(t),!1),n}let a=new Uint8Array(9);return a[0]=e<<5|27,new DataView(a.buffer).setBigUint64(1,t,!1),a}if(t<=23n)return new Uint8Array([e<<5|Number(t)]);if(t<=255n)return new Uint8Array([e<<5|24,Number(t)]);if(t<=65535n){let n=new Uint8Array(3);return n[0]=e<<5|25,n[1]=Number(t>>8n),n[2]=Number(t&255n),n}if(t<=4294967295n){let n=new Uint8Array(5);return n[0]=e<<5|26,new DataView(n.buffer).setUint32(1,Number(t),!1),n}let r=new Uint8Array(9);return r[0]=e<<5|27,new DataView(r.buffer).setBigUint64(1,t,!1),r}function h(e){let t=e.reduce((e,t)=>e+t.length,0),n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}var re=new DataView(new ArrayBuffer(4));function ie(e){return Object.is(te(ee(e)),e)}function ae(e){return re.setFloat32(0,e,!1),Object.is(re.getFloat32(0,!1),e)}function oe(e){return ie(e)?`half`:ae(e)?`single`:`double`}var g=class extends d{value;encodingWidth;constructor(e,t){if(super(),this.value=BigInt(e),this.value<0n)throw RangeError(`CborUint value must be non-negative`);if(this.value>18446744073709551615n)throw RangeError(`CborUint value exceeds maximum uint64`);this.encodingWidth=t?.encodingWidth}_toCBOR(e){return m(0,this.value,this.encodingWidth)}_toCDN(e,t){let n=this.encodingWidth===void 0?``:`_${this.encodingWidth}`,r=this.value;switch(e?.intFormat){case`hex`:return`0x${r.toString(16)}${n}`;case`octal`:return`0o${r.toString(8)}${n}`;case`binary`:return`0b${r.toString(2)}${n}`;default:return r.toString()+n}}_toJS(e){let t=e?.integerAs??`auto`;return t===`bigint`?this.value:t===`number`||this.value<=BigInt(2**53-1)?Number(this.value):this.value}},_=class extends d{argument;encodingWidth;constructor(e,t){super();let n=BigInt(e);if(n>=0n)throw RangeError(`CborNint value must be negative`);if(n<-18446744073709551616n)throw RangeError(`CborNint value exceeds minimum int64`);this.argument=-1n-n,this.encodingWidth=t?.encodingWidth}get value(){return-1n-this.argument}_toCBOR(e){return m(1,this.argument,this.encodingWidth)}_toCDN(e,t){let n=this.encodingWidth===void 0?``:`_${this.encodingWidth}`,r=this.argument+1n;switch(e?.intFormat){case`hex`:return`-0x${r.toString(16)}${n}`;case`octal`:return`-0o${r.toString(8)}${n}`;case`binary`:return`-0b${r.toString(2)}${n}`;default:return this.value.toString()+n}}_toJS(e){let t=this.value,n=e?.integerAs??`auto`;return n===`bigint`?t:n===`number`||t>=BigInt(-(2**53-1))?Number(t):t}};function v(e){let t=e?.indent;return t===void 0?null:typeof t==`number`?` `.repeat(t):t}function y(e,t){return e.repeat(t)}function se(e){return!!(e.comments?.leading?.length||e.comments?.trailing?.length||e.comments?.dangling?.length)}function ce(e){return!!(e.comments?.trailing?.length||e.comments?.dangling?.length)}function le(e,t){return(e.comments?.leading??[]).map(e=>t+e.text)}function ue(e){let t=e.comments?.trailing??[];return t.length===0?``:` `+t.map(e=>e.text).join(` `)}function de(e,t){return(e.comments?.dangling??[]).map(e=>t+e.text)}function fe(e,t=!1){let n=e?.commas??`comma`,r=n!==`none`;return{inlineSep:r?t?`,`:`, `:` `,multilineSep:r?`,`:``,trailSep:n===`trailing`?`,`:``,colSep:t?`:`:`: `}}function pe(e){return typeof e.toHex==`function`?e.toHex():Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``)}var me=typeof new Uint8Array().toBase64==`function`;function he(e){if(me)return e.toBase64({omitPadding:!0});let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/=/g,``)}function ge(e){if(me)return e.toBase64({alphabet:`base64url`,omitPadding:!0});let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=/g,``)}var _e=`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`,ve=`0123456789ABCDEFGHIJKLMNOPQRSTUV`;function ye(e,t){let n=``,r=0,i=0;for(let a of e)for(r=r<<8|a,i+=8;i>=5;)i-=5,n+=t[r>>i&31];return i>0&&(n+=t[r<<5-i&31]),n}function be(e){for(let t of e){let e=t.codePointAt(0);if(e<32||e===127)return!0}return!1}function xe(e,t,n){if(n===`string`){let t=Se(e);if(t!=null)return we(t)}if(n===`printable-string`||n===void 0){let t=Se(e);if(t!=null&&!be(t))return we(t)}switch(t){case`base64`:return`b64'${he(e)}'`;case`base64url`:return`b64'${ge(e)}'`;case`base32`:return`b32'${ye(e,_e)}'`;case`base32hex`:return`h32'${ye(e,ve)}'`;default:return`h'${pe(e)}'`}}function Se(e){try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{return null}}function Ce(e,t){let n=t.codePointAt(0),r=t;for(let i of e){let e=i.codePointAt(0);switch(e){case n:r+=`\\${t}`;break;case 92:r+=`\\\\`;break;case 10:r+=`\\n`;break;case 13:r+=`\\r`;break;case 9:r+=`\\t`;break;default:e<32||e===127||e===8232||e===8233||e===8203||e===8204||e===8205||e===65279?r+=`\\u${e.toString(16).padStart(4,`0`)}`:r+=i}}return r+t}function we(e){return Ce(e,`'`)}function Te(e){return Ce(e,`'`)}function b(e){return Ce(e,`"`)}function Ee(e){if(isNaN(e))return`NaN`;if(!isFinite(e))return e>0?`Infinity`:`-Infinity`;if(Object.is(e,-0))return`-0.0`;let t=e.toString();return t.includes(`.`)||t.includes(`e`)?t:t+`.0`}function De(e,t,n){return t===void 0||t===n?``:t===`half`?`_1`:t===`single`?`_2`:`_3`}var Oe=new DataView(new ArrayBuffer(8));function ke(e){let t=e.startsWith(`-`),n=e.slice(t?3:2),r=n.search(/[pP]/);if(r===-1)throw SyntaxError(`EDN parse error: hex float missing 'p' exponent: ${e}`);let i=n.slice(0,r),a=n.slice(r+1);if(!/^[+-]?\d+$/.test(a))throw SyntaxError(`EDN parse error: hex float has invalid or missing exponent: ${e}`);let o=parseInt(a,10),s=i.indexOf(`.`),c;if(s===-1){if(!/^[0-9a-fA-F]+$/.test(i))throw SyntaxError(`EDN parse error: hex float has no mantissa digits: ${e}`);c=parseInt(i,16)}else{let t=i.slice(0,s),n=i.slice(s+1);if(t===``&&n===``)throw SyntaxError(`EDN parse error: hex float has no mantissa digits: ${e}`);if(t!==``&&!/^[0-9a-fA-F]+$/.test(t)||n!==``&&!/^[0-9a-fA-F]+$/.test(n))throw SyntaxError(`EDN parse error: hex float has invalid mantissa: ${e}`);c=(t===``?0:parseInt(t,16))+(n===``?0:parseInt(n,16)/16**n.length)}let l=c*2**o;return t?-l:l}function Ae(e){if(isNaN(e))return`NaN`;if(!isFinite(e))return e>0?`Infinity`:`-Infinity`;let t=Object.is(e,-0)||e<0,n=Math.abs(e);if(n===0)return t?`-0x0p+0`:`0x0p+0`;Oe.setFloat64(0,n,!1);let r=Oe.getUint32(0,!1),i=Oe.getUint32(4,!1),a=r>>>20&2047,o=r&1048575,s=i,c=(o.toString(16).padStart(5,`0`)+s.toString(16).padStart(8,`0`)).replace(/0+$/,``),l=c===``?``:`.${c}`,u,d;a===0?(u=`0`,d=-1022):(u=`1`,d=a-1023);let f=d>=0?`+${d}`:`${d}`,p=`0x${u}${l}p${f}`;return t?`-${p}`:p}var x=class extends d{value;precision;constructor(e,t){super(),this.value=e,this.precision=t?.precision}_toCBOR(e){let t=this.precision??oe(this.value);if(t===`half`){let e=new Uint8Array(3);return e[0]=249,ne(new DataView(e.buffer),1,this.value,!1),e}if(t===`single`){let e=new Uint8Array(5);return e[0]=250,new DataView(e.buffer).setFloat32(1,this.value,!1),e}let n=new Uint8Array(9);return n[0]=251,new DataView(n.buffer).setFloat64(1,this.value,!1),n}_toCDN(e,t){let n=oe(this.value);return(e?.floatFormat===`hex`?Ae(this.value):Ee(this.value))+De(this.value,this.precision,n)}_toJS(e){return this.value}},S=class extends d{tag;content;encodingWidth;constructor(e,t,n){if(super(),this.tag=BigInt(e),this.tag<0n)throw RangeError(`CborTag tag number must be non-negative`);this.content=t,this.encodingWidth=n?.encodingWidth}_toCBOR(e){return h([m(6,this.tag,this.encodingWidth),this.content._toCBOR(e)])}_toCDN(e,t){let n=this.encodingWidth===void 0?``:`_${this.encodingWidth}`;return`${this.tag}${n}(${this.content._toCDN(e,t)})`}_toHexDump(e,t){let n=[{depth:e,hex:(e=>Array.from(e,e=>e.toString(16).toUpperCase().padStart(2,`0`)).join(` `))(m(6,this.tag,this.encodingWidth)),comment:`Tag ${this.tag}`}];return n.push(...this.content._toHexDump(e+1,t)),n}_toJS(e){let t=this.content._toJS(e);return e?.stripTags?t:c.set(t,this.tag)}};function je(e,t){let n=1,r=1;for(let i=0;i<t;i++)e[i]===`
|
|
4
|
+
`?(n++,r=1):r++;return{line:n,col:r}}var Me=class{input;pos;line;col;_peeked=null;_lastConsumedEndOffset;comments=[];constructor(e,t){this.input=e;let n=t?.offset??0;if(!Number.isInteger(n)||n<0||n>e.length)throw RangeError(`EDN parse offset must be an integer between 0 and ${e.length}`);let r=je(e,n);this.pos=n,this.line=r.line,this.col=r.col,this._lastConsumedEndOffset=n}peek(){return this._peeked===null&&(this._peeked=this._readNext()),this._peeked}consume(){let e=this._peeked===null?this._readNext():this._peeked;return this._peeked=null,this._lastConsumedEndOffset=e.endOffset,e}get lastEndOffset(){return this._lastConsumedEndOffset}_ch(){return this.input[this.pos]??``}_eof(){return this.pos>=this.input.length}_advance(){let e=this.input[this.pos++]??``;return e===`
|
|
5
|
+
`?(this.line++,this.col=1):this.col++,e}_fail(e,t=this.line,n=this.col){throw SyntaxError(`EDN parse error at line ${t}, column ${n}: ${e}`)}_skipWS(){for(;;){for(;!this._eof()&&/\s/.test(this._ch());)this._advance();if(this._eof())return;let e=this._ch();if(e===`#`){let e=this.pos,t=this.line,n=this.col;for(;!this._eof()&&this._ch()!==`
|
|
6
|
+
`;)this._advance();this.comments.push({kind:`line`,marker:`#`,text:this.input.slice(e,this.pos),start:e,end:this.pos,line:t,col:n});continue}if(e===`/`){let e=this.input[this.pos+1]??``;if(e===`/`){let e=this.pos,t=this.line,n=this.col;for(this._advance(),this._advance();!this._eof()&&this._ch()!==`
|
|
7
|
+
`;)this._advance();this.comments.push({kind:`line`,marker:`//`,text:this.input.slice(e,this.pos),start:e,end:this.pos,line:t,col:n});continue}if(e===`*`){let e=this.pos,t=this.line,n=this.col;this._advance(),this._advance(),this._skipBlockCommentStar(),this.comments.push({kind:`block`,marker:`/*`,text:this.input.slice(e,this.pos),start:e,end:this.pos,line:t,col:n});continue}let t=this.pos,n=this.line,r=this.col;this._advance(),this._skipBlockCommentSlash(),this.comments.push({kind:`block`,marker:`/`,text:this.input.slice(t,this.pos),start:t,end:this.pos,line:n,col:r});continue}return}}_skipByteStringComment(e){let t=this._ch();if(t===`/`){let t=this.input[this.pos+1]??``;if(t===`/`){for(this._advance(),this._advance();!this._eof()&&this._ch()!==`
|
|
8
|
+
`;){if(this._ch()===`\\`){this._advance(),!this._eof()&&this._ch()!==`
|
|
9
|
+
`&&this._advance();continue}if(this._ch()===e)break;this._advance()}return!0}return t===`*`?(this._advance(),this._advance(),this._skipBlockCommentStar(),!0):(this._advance(),this._skipBlockCommentSlash(),!0)}if(t===`#`){for(;!this._eof()&&this._ch()!==`
|
|
10
|
+
`;){if(this._ch()===`\\`){this._advance(),!this._eof()&&this._ch()!==`
|
|
11
|
+
`&&this._advance();continue}if(this._ch()===e)break;this._advance()}return!0}return!1}_skipRawComment(e,t,n,r,i){let a=e[t];if(a===`/`){if(t++,e[t]===`/`){for(t++;t<e.length&&e[t]!==`
|
|
12
|
+
`;)t++;return t}if(e[t]===`*`){for(t++;t<e.length;){if(e[t]===`*`&&e[t+1]===`/`)return t+2;t++}return t}for(;t<e.length&&e[t]!==`/`;)t++;if(t>=e.length)throw SyntaxError(`EDN parse error at line ${r}, column ${i}: unterminated block comment in ${n}`);return t+1}if(a===`#`){for(;t<e.length&&e[t]!==`
|
|
13
|
+
`;)t++;return t}return-1}_skipBlockCommentSlash(){let e=this.line,t=this.col;for(;!this._eof();){if(this._ch()===`\\`){this._advance(),this._eof()||this._advance();continue}if(this._ch()===`/`)break;this._advance()}this._eof()&&this._fail(`unterminated block comment`,e,t),this._advance()}_skipBlockCommentStar(){let e=this.line,t=this.col;for(;!this._eof();){if(this._ch()===`*`&&(this.input[this.pos+1]??``)===`/`){this._advance(),this._advance();return}this._advance()}this._fail(`unterminated block comment`,e,t)}_readStringContent(e){this._advance();let t=``;for(;!this._eof()&&this._ch()!==e;){let n=this._ch();if(n===`\r`){this._advance();continue}let r=n.codePointAt(0);if((r<32&&r!==10||r===127)&&this._fail(`unescaped control character U+${r.toString(16).padStart(4,`0`)} is not allowed in string literals`),n===`\\`){this._advance();let n=this.line,r=this.col,i=this._advance();switch(i){case`n`:t+=`
|
|
14
|
+
`;break;case`r`:t+=`\r`;break;case`t`:t+=` `;break;case`b`:t+=`\b`;break;case`f`:t+=`\f`;break;case`\\`:t+=`\\`;break;case`u`:t+=this._readUnicodeEscape(e);break;default:if(i===e){t+=i;break}if(i===`/`){t+=`/`;break}this._fail(`invalid escape sequence \\${i} in ${e===`"`?`double`:`single`}-quoted string`,n,r)}}else t+=this._advance()}return this._eof()&&this._fail(`unterminated string literal`),this._advance(),t}_readUnicodeEscape(e){let t=this.line,n=this.col,r=r=>{e===`'`&&r>=32&&r<=126&&r!==92&&r!==39&&this._fail(`\\u escape for printable ASCII U+${r.toString(16).padStart(4,`0`)} is not allowed in single-quoted strings; write the character literally`,t,n)};if(!this._eof()&&this._ch()===`{`){this._advance();let e=``;for(;!this._eof()&&this._ch()!==`}`;){let r=this._ch();/[0-9a-fA-F]/.test(r)||this._fail(`invalid character in \\u{} escape: ${JSON.stringify(r)}`,t,n),e+=this._advance()}this._eof()&&this._fail(`unterminated \\u{} escape`,t,n),this._advance(),e.length===0&&this._fail(`empty \\u{} escape`,t,n);let i=parseInt(e,16);return i>1114111&&this._fail(`\\u{${e}} exceeds maximum Unicode code point U+10FFFF`,t,n),i>=55296&&i<=57343&&this._fail(`\\u{${e}} is a surrogate code point, which is not a valid Unicode scalar value`,t,n),r(i),String.fromCodePoint(i)}let i=``;for(let e=0;e<4;e++){this._eof()&&this._fail(`truncated \\uXXXX escape`,t,n);let e=this._ch();/[0-9a-fA-F]/.test(e)||this._fail(`invalid hex digit in \\uXXXX escape: ${JSON.stringify(e)}`,t,n),i+=this._advance()}let a=parseInt(i,16);if(a>=55296&&a<=56319){(this._ch()!==`\\`||(this.input[this.pos+1]??``)!==`u`)&&this._fail(`lone high surrogate \\u${i} must be followed by \\uDC00–\\uDFFF`,t,n),this._advance(),this._advance();let e=this.line,r=this.col,o=``;for(let t=0;t<4;t++)this._eof()&&this._fail(`truncated low-surrogate escape`,e,r),o+=this._advance();let s=parseInt(o,16);return(s<56320||s>57343)&&this._fail(`\\u${i} (high surrogate) not followed by a valid low surrogate (got \\u${o})`,t,n),String.fromCodePoint(65536+(a-55296)*1024+(s-56320))}return a>=56320&&a<=57343&&this._fail(`lone low surrogate \\u${i} is not valid`,t,n),r(a),String.fromCharCode(a)}_readRawStringContent(){let e=this.line,t=this.col,n=0;for(;!this._eof()&&this._ch()==="`";)this._advance(),n++;!this._eof()&&this._ch()===`\r`&&this._advance(),!this._eof()&&this._ch()===`
|
|
15
|
+
`&&this._advance();let r=``;for(;!this._eof();){let i=this._ch();if(i===`\r`){this._advance();continue}if(i==="`"){let i=0;for(;!this._eof()&&this._ch()==="`";)this._advance(),i++;if(i>=n)return r+="`".repeat(i-n),r===``&&this._fail(`raw string must not be empty (§2.5.3)`,e,t),r;r+="`".repeat(i)}else{let e=i.codePointAt(0);e<32&&e!==10&&e!==13&&this._fail(`raw string content must not contain control character U+${e.toString(16).toUpperCase().padStart(4,`0`)} (§2.5.3)`,this.line,this.col),e===127&&this._fail(`raw string content must not contain DEL (U+007F) (§2.5.3)`,this.line,this.col),r+=this._advance()}}this._fail(`unterminated raw string literal`,e,t)}_processRawHexContent(e,t,n){let r=``,i=!1,a=0;for(;a<e.length;){let o=e[a];if(o===`
|
|
16
|
+
`||o===` `||o===`\r`){a++;continue}if(o===` `)throw SyntaxError(`EDN parse error at line ${t}, column ${n}: horizontal tab (HT) is not allowed inside h\`\` raw byte string literals (§5.3.3)`);let s=this._skipRawComment(e,a,"h`` raw byte string",t,n);if(s!==-1){a=s;continue}if(o===`.`&&e[a+1]===`.`&&e[a+2]===`.`){for(a+=3;a<e.length&&e[a]===`.`;)a++;r+=`...`,i=!0;continue}if(/[0-9a-fA-F]/.test(o)){r+=o,a++;continue}throw SyntaxError(`EDN parse error at line ${t}, column ${n}: unexpected character ${JSON.stringify(o)} in h\`\` raw byte string`)}return{value:r,elided:i}}_processRawB64Content(e,t,n){let r=``,i=0;for(;i<e.length;){let a=e[i];if(a===`
|
|
17
|
+
`||a===` `||a===`\r`){i++;continue}if(a===` `)throw SyntaxError(`EDN parse error at line ${t}, column ${n}: horizontal tab (HT) is not allowed inside b64\`\` raw byte string literals (§5.3.4)`);if(a===`#`){for(;i<e.length&&e[i]!==`
|
|
18
|
+
`;)i++;continue}r+=a,i++}return r}_processRawB32Content(e,t,n){let r=``,i=0;for(;i<e.length;){let a=e[i];if(a===`
|
|
19
|
+
`||a===` `||a===`\r`){i++;continue}if(a===` `)throw SyntaxError(`EDN parse error at line ${t}, column ${n}: horizontal tab (HT) is not allowed inside b32\`\`/h32\`\` raw byte string literals (§5.2)`);let o=this._skipRawComment(e,i,"b32``/h32`` raw byte string",t,n);if(o!==-1){i=o;continue}r+=a,i++}return r}_readByteContent(e){this._advance();let t=``;for(;!this._eof()&&this._ch()!==e;){let n=this._ch();if(n===`
|
|
20
|
+
`||n===` `){this._advance();continue}if(n===`\r`){this._advance();continue}if(n===` `&&this._fail(`horizontal tab (HT) is not allowed inside byte string literals (§5.2.2)`,this.line,this.col),n===`#`){for(;!this._eof()&&this._ch()!==`
|
|
21
|
+
`;){if(this._ch()===`\\`){this._advance(),!this._eof()&&this._ch()!==`
|
|
22
|
+
`&&this._advance();continue}if(this._ch()===e)break;this._advance()}continue}t+=this._advance()}return this._eof()&&this._fail(`unterminated byte string literal`),this._advance(),t}_readB32Content(e){this._advance();let t=``;for(;!this._eof()&&this._ch()!==e;){let n=this._ch();if(n===`
|
|
23
|
+
`||n===` `||n===`\r`){this._advance();continue}n===` `&&this._fail(`horizontal tab (HT) is not allowed inside byte string literals (§5.2)`,this.line,this.col),!this._skipByteStringComment(e)&&(t+=this._advance())}return this._eof()&&this._fail(`unterminated byte string literal`),this._advance(),t}_readHexByteContentElisionAware(e){this._advance();let t=``,n=!1;for(;!this._eof()&&this._ch()!==e;){let r=this._ch();if(r===`
|
|
24
|
+
`||r===` `||r===`\r`){this._advance();continue}if(r===` `&&this._fail(`horizontal tab (HT) is not allowed inside hex byte string literals (§5.2.1)`,this.line,this.col),!this._skipByteStringComment(e)){if(r===`.`&&(this.input[this.pos+1]??``)===`.`&&(this.input[this.pos+2]??``)===`.`){for(this._advance(),this._advance(),this._advance();!this._eof()&&this._ch()===`.`;)this._advance();t.endsWith(`...`)||(t+=`...`),n=!0;continue}if(/[0-9a-fA-F]/.test(r)){t+=this._advance();continue}this._fail(`unexpected character ${JSON.stringify(r)} in hex byte string`)}}return this._eof()&&this._fail(`unterminated hex byte string literal`),this._advance(),{value:t,elided:n}}_readNext(){this._skipWS();let e=this.pos;return{...this._readNextCore(),raw:this.input.slice(e,this.pos),offset:e,endOffset:this.pos}}_readNextCore(){let e=this.line,t=this.col;if(this._eof())return{type:`EOF`,value:``,line:e,col:t};let n=this._ch();switch(n){case`[`:return this._advance(),{type:`LBRACKET`,value:`[`,line:e,col:t};case`]`:return this._advance(),{type:`RBRACKET`,value:`]`,line:e,col:t};case`{`:return this._advance(),{type:`LBRACE`,value:`{`,line:e,col:t};case`}`:return this._advance(),{type:`RBRACE`,value:`}`,line:e,col:t};case`(`:return this._advance(),{type:`LPAREN`,value:`(`,line:e,col:t};case`)`:return this._advance(),{type:`RPAREN`,value:`)`,line:e,col:t};case`:`:return this._advance(),{type:`COLON`,value:`:`,line:e,col:t};case`,`:return this._advance(),{type:`COMMA`,value:`,`,line:e,col:t};case`<`:if((this.input[this.pos+1]??``)===`<`)return this._advance(),this._advance(),{type:`LT_LT`,value:`<<`,line:e,col:t};this._fail(`unexpected character '<'`,e,t);case`>`:if((this.input[this.pos+1]??``)===`>`)return this._advance(),this._advance(),{type:`GT_GT`,value:`>>`,line:e,col:t};this._fail(`unexpected character '>'`,e,t);case`+`:{let n=this.input.slice(this.pos+1);if(n.startsWith(`Infinity`)){let r=n[8]??``,i=r===`_`&&/[0-3i]/.test(n[9]??``)&&!/[a-zA-Z0-9_]/.test(n[10]??``);if(!/[a-zA-Z0-9_]/.test(r)||i){this._advance();for(let e=0;e<8;e++)this._advance();let n=`Infinity`;return i&&(n+=this._advance()+this._advance()),{type:`FLOAT`,value:n,line:e,col:t}}}let r=n[0]??``;return r>=`0`&&r<=`9`||r===`.`?(this._advance(),this._readNumber(e,t)):(this._advance(),{type:`PLUS`,value:`+`,line:e,col:t})}case"`":return{type:`RAWSTRING`,value:this._readRawStringContent(),line:e,col:t};case`"`:{let n=this._readStringContent(`"`);return n===``&&this._ch()===`_`?(this._advance(),{type:`EMPTY_INDEF_TEXT`,value:``,line:e,col:t}):{type:`TSTR`,value:n,line:e,col:t}}case`'`:{if((this.input[this.pos+1]??``)===`'`&&(this.input[this.pos+2]??``)===`_`)return this._advance(),this._advance(),this._advance(),{type:`EMPTY_INDEF_BYTES`,value:``,line:e,col:t};let n=this._readStringContent(`'`),r=new TextEncoder().encode(n);return{type:`SQSTR`,value:Array.from(r,e=>e.toString(16).padStart(2,`0`)).join(``),line:e,col:t}}}if(n===`-`){let n=this.input.slice(this.pos+1);if(n.startsWith(`Infinity`)){let r=n[8]??``,i=r===`_`&&/[0-3i]/.test(n[9]??``)&&!/[a-zA-Z0-9_]/.test(n[10]??``);if(!/[a-zA-Z0-9_]/.test(r)||i){this._advance();for(let e=0;e<8;e++)this._advance();let n=`-Infinity`;return i&&(n+=this._advance()+this._advance()),{type:`FLOAT`,value:n,line:e,col:t}}}return this._readNumber(e,t)}if(n===`+`){let n=this.input.slice(this.pos+1);if(n.startsWith(`Infinity`)){let r=n[8]??``,i=r===`_`&&/[0-3i]/.test(n[9]??``)&&!/[a-zA-Z0-9_]/.test(n[10]??``);if(!/[a-zA-Z0-9_]/.test(r)||i){this._advance();for(let e=0;e<8;e++)this._advance();let n=`Infinity`;return i&&(n+=this._advance()+this._advance()),{type:`FLOAT`,value:n,line:e,col:t}}}return this._advance(),this._readNumber(e,t)}if(n>=`0`&&n<=`9`||n===`.`&&/[0-9]/.test(this.input[this.pos+1]??``))return this._readNumber(e,t);if(/[a-zA-Z_]/.test(n))return this._readIdent(e,t);if(n===`.`){if((this.input[this.pos+1]??``)===`.`&&(this.input[this.pos+2]??``)===`.`){for(this._advance(),this._advance(),this._advance();!this._eof()&&this._ch()===`.`;)this._advance();return{type:`ELLIPSIS`,value:`...`,line:e,col:t}}this._fail(`unexpected character '.'`,e,t)}this._fail(`unexpected character ${JSON.stringify(n)}`,e,t)}_readNumber(e,t){let n=``;if(this._ch()===`-`&&(n+=this._advance()),this._ch()===`0`){let r=this.input[this.pos+1]??``;if(r===`x`||r===`X`){n+=this._advance()+this._advance();let r=n.length;for(;!this._eof()&&/[0-9a-fA-F]/.test(this._ch());)n+=this._advance();let i=n.length>r,a=!1,o=!1;if(!this._eof()&&this._ch()===`.`){a=!0,n+=this._advance();let e=n.length;for(;!this._eof()&&/[0-9a-fA-F]/.test(this._ch());)n+=this._advance();o=n.length>e}if(!this._eof()&&(this._ch()===`p`||this._ch()===`P`)){a=!0,!i&&!o&&this._fail(`hex float has no mantissa digits: ${n}`,e,t),n+=this._advance(),!this._eof()&&(this._ch()===`+`||this._ch()===`-`)&&(n+=this._advance());let r=n.length;for(;!this._eof()&&this._ch()>=`0`&&this._ch()<=`9`;)n+=this._advance();n.length===r&&this._fail(`hex float missing exponent digits: ${n}`,e,t)}else a&&this._fail(`hex float missing 'p' exponent: ${n}`,e,t);if(a){if(this._ch()===`_`){let e=this.input[this.pos+1]??``,t=this.input[this.pos+2]??``;(e===`0`||e===`1`||e===`2`||e===`3`||e===`i`)&&!/[0-9a-zA-Z_]/.test(t)&&(n+=this._advance()+this._advance())}return{type:`FLOAT`,value:n,line:e,col:t}}return{type:`INTEGER`,value:n,line:e,col:t}}if(r===`o`||r===`O`){for(n+=this._advance()+this._advance();!this._eof()&&this._ch()>=`0`&&this._ch()<=`7`;)n+=this._advance();return{type:`INTEGER`,value:n,line:e,col:t}}if(r===`b`||r===`B`){for(n+=this._advance()+this._advance();!this._eof()&&(this._ch()===`0`||this._ch()===`1`);)n+=this._advance();return{type:`INTEGER`,value:n,line:e,col:t}}}for(;!this._eof()&&this._ch()>=`0`&&this._ch()<=`9`;)n+=this._advance();let r=!1;if(!this._eof()&&this._ch()===`.`)for(r=!0,n+=this._advance();!this._eof()&&this._ch()>=`0`&&this._ch()<=`9`;)n+=this._advance();if(!this._eof()&&(this._ch()===`e`||this._ch()===`E`)){r=!0,n+=this._advance(),!this._eof()&&(this._ch()===`+`||this._ch()===`-`)&&(n+=this._advance());let i=n.length;for(;!this._eof()&&this._ch()>=`0`&&this._ch()<=`9`;)n+=this._advance();n.length===i&&this._fail(`float exponent has no digits: ${JSON.stringify(n)}`,e,t)}if(this._ch()===`_`){let e=this.input[this.pos+1]??``,t=this.input[this.pos+2]??``;(e===`0`||e===`1`||e===`2`||e===`3`||e===`i`)&&!/[0-9a-zA-Z_]/.test(t)&&(n+=this._advance()+this._advance())}return{type:r?`FLOAT`:`INTEGER`,value:n,line:e,col:t}}_readIdent(e,t){let n=``;for(;!this._eof()&&/[a-zA-Z0-9_]/.test(this._ch());)n+=this._advance();switch(n){case`true`:return{type:`TRUE`,value:n,line:e,col:t};case`false`:return{type:`FALSE`,value:n,line:e,col:t};case`null`:return{type:`NULL`,value:n,line:e,col:t};case`undefined`:return{type:`UNDEFINED`,value:n,line:e,col:t};case`NaN`:case`NaN_0`:case`NaN_1`:case`NaN_2`:case`NaN_3`:case`NaN_i`:case`Infinity`:case`Infinity_0`:case`Infinity_1`:case`Infinity_2`:case`Infinity_3`:case`Infinity_i`:return{type:`FLOAT`,value:n,line:e,col:t};case`simple`:return{type:`SIMPLE`,value:n,line:e,col:t};case`_`:return{type:`UNDERSCORE`,value:`_`,line:e,col:t};case`_0`:return{type:`ENCODING_INDICATOR`,value:`0`,line:e,col:t};case`_1`:return{type:`ENCODING_INDICATOR`,value:`1`,line:e,col:t};case`_2`:return{type:`ENCODING_INDICATOR`,value:`2`,line:e,col:t};case`_3`:return{type:`ENCODING_INDICATOR`,value:`3`,line:e,col:t};case`_i`:return{type:`ENCODING_INDICATOR`,value:`i`,line:e,col:t}}let r=n[0]??``,i=r>=`a`&&r<=`z`;if(i||r>=`A`&&r<=`Z`){let r=n.slice(1);if(i?/^[a-z0-9]*$/.test(r):/^[A-Z0-9]*$/.test(r)){for(;!this._eof();){let e=this._ch();if(!(i?e>=`a`&&e<=`z`||e>=`0`&&e<=`9`||e===`-`:e>=`A`&&e<=`Z`||e>=`0`&&e<=`9`||e===`-`))break;n+=this._advance()}let r=this._ch();if(r===`"`&&this._fail(`"${n}" prefix requires single quotes or backticks, not double quotes`,e,t),r===`'`)switch(n){case`h`:{let{value:n,elided:i}=this._readHexByteContentElisionAware(r);return{type:i?`BYTES_HEX_ELIDED`:`BYTES_HEX`,value:n,line:e,col:t}}case`b64`:return{type:`BYTES_B64`,value:this._readByteContent(r),line:e,col:t};case`b32`:return{type:`BYTES_B32`,value:this._readB32Content(r),line:e,col:t};case`h32`:return{type:`BYTES_H32`,value:this._readB32Content(r),line:e,col:t};default:return{type:`APP_STRING`,appPrefix:n,value:this._readStringContent(r),line:e,col:t}}if(r==="`"){let r=this._readRawStringContent();switch(n){case`h`:{let{value:n,elided:i}=this._processRawHexContent(r,e,t);return{type:i?`BYTES_HEX_ELIDED`:`BYTES_HEX`,value:n,line:e,col:t}}case`b64`:return{type:`BYTES_B64`,value:this._processRawB64Content(r,e,t),line:e,col:t};case`b32`:return{type:`BYTES_B32`,value:this._processRawB32Content(r,e,t),line:e,col:t};case`h32`:return{type:`BYTES_H32`,value:this._processRawB32Content(r,e,t),line:e,col:t};default:return{type:`APP_STRING`,appPrefix:n,value:r,line:e,col:t}}}if(r===`<`&&(this.input[this.pos+1]??``)===`<`)return this._advance(),this._advance(),{type:`APP_SEQUENCE`,appPrefix:n,value:``,line:e,col:t}}}this._fail(`unknown identifier ${JSON.stringify(n)}`,e,t)}},C=class extends d{indefiniteLength=!1;value;ednEncoding;encodingWidth;ednSource;constructor(e,t){super(),this.value=e,this.ednEncoding=t?.ednEncoding??`hex`,this.encodingWidth=t?.encodingWidth,this.ednSource=t?.ednSource}_toCBOR(e){return h([m(2,BigInt(this.value.length),this.encodingWidth),this.value])}_toCDN(e,t){let n=this.encodingWidth===void 0?``:`_${this.encodingWidth}`;if(e?.preserveByteString&&this.ednSource!==void 0)return this.ednSource+n;let r=e?.bstrEncoding??this.ednEncoding;return xe(this.value,r,e?.sqstr)+n}_toJS(e){return this.value}},w=class extends d{indefiniteLength=!0;chunks;constructor(e){super(),this.chunks=e}_toCBOR(e){let t=[new Uint8Array([95])];for(let n of this.chunks)t.push(n._toCBOR(e));return t.push(new Uint8Array([255])),h(t)}_toCDN(e,t){return this.chunks.length===0?`''_`:`(_ ${this.chunks.map(t=>t._toCDN(e,0)).join(`, `)})`}_toHexDump(e,t){let n=e=>e.toString(16).toUpperCase().padStart(2,`0`),r=[{depth:e,hex:n(95),comment:`Start indefinite-length byte string`}];for(let n of this.chunks)r.push(...n._toHexDump(e+1,t));return r.push({depth:e,hex:n(255),comment:`"break"`}),r}_toJS(e){let t=this.chunks.reduce((e,t)=>e+t.value.length,0),n=new Uint8Array(t),r=0;for(let e of this.chunks)n.set(e.value,r),r+=e.value.length;return n}},T=class extends d{indefiniteLength=!0;chunks;constructor(e){super(),this.chunks=e}_toCBOR(e){let t=[new Uint8Array([127])];for(let n of this.chunks)t.push(n._toCBOR(e));return t.push(new Uint8Array([255])),h(t)}_toCDN(e,t){return this.chunks.length===0?`""_`:`(_ ${this.chunks.map(t=>t._toCDN(e,0)).join(`, `)})`}_toHexDump(e,t){let n=e=>e.toString(16).toUpperCase().padStart(2,`0`),r=[{depth:e,hex:n(127),comment:`Start indefinite-length text string`}];for(let n of this.chunks)r.push(...n._toHexDump(e+1,t));return r.push({depth:e,hex:n(255),comment:`"break"`}),r}_toJS(e){return this.chunks.map(e=>e.value).join(``)}},E=class extends d{items;indefiniteLength;encodingWidth;constructor(e,t){super(),this.items=e,this.indefiniteLength=t?.indefiniteLength??!1,this.encodingWidth=t?.encodingWidth}_toCBOR(e){if(this.indefiniteLength){let t=[new Uint8Array([159])];for(let n of this.items)t.push(n._toCBOR(e));return t.push(new Uint8Array([255])),h(t)}let t=[m(4,BigInt(this.items.length),this.encodingWidth)];for(let n of this.items)t.push(n._toCBOR(e));return h(t)}_toCDN(e,t){let n=v(e),r=e?.preserveComments,i=r&&(ce(this)||this.items.some(se));n===null&&i&&(n=` `);let{inlineSep:a,multilineSep:o,trailSep:s}=fe(e,n===null),c=!this.indefiniteLength&&this.encodingWidth!==void 0?`_${this.encodingWidth} `:``;if(n===null||this.items.length===0&&!i){let n=this.items.map(n=>n._toCDN(e,t+1)).join(a);return this.indefiniteLength?this.items.length===0?`[_ ]`:`[_ ${n}]`:`[${c}${n}]`}let l=y(n,t+1),u=y(n,t),d=this.indefiniteLength?`[_ `:`[${c}`,f=[];for(let n=0;n<this.items.length;n++){let i=this.items[n];r&&f.push(...le(i,l));let a=n<this.items.length-1?o:s;f.push(`${l}${i._toCDN(e,t+1)}${a}${r?ue(i):``}`)}return r&&f.push(...de(this,l)),`${d}\n${f.join(`
|
|
25
|
+
`)}\n${u}]`}_toHexDump(e,t){let n=e=>e.toString(16).toUpperCase().padStart(2,`0`),r=e=>Array.from(e,e=>e.toString(16).toUpperCase().padStart(2,`0`)).join(` `);if(this.indefiniteLength){let r=[{depth:e,hex:n(159),comment:`Start indefinite-length array`}];for(let n of this.items)r.push(...n._toHexDump(e+1,t));return r.push({depth:e,hex:n(255),comment:`"break"`}),r}let i=[{depth:e,hex:r(m(4,BigInt(this.items.length),this.encodingWidth)),comment:`Array of length ${this.items.length}`}];for(let n of this.items)i.push(...n._toHexDump(e+1,t));return i}_toJS(e){let t=e?.reviver;if(!t)return this.items.map(t=>t._toJS(e));let n=e?{...e,reviver:void 0}:void 0,r=this.items.map(e=>e._toJS(n)),i=0;for(let n=0;n<this.items.length;n++){let a=n-i,o=this.items[n]._toJS(e),s=t.call(r,String(n),o);s===l||e?.undefinedOmits&&s===void 0?(r.splice(a,1),i++):r[a]=s}return r}},D=class extends d{entries;indefiniteLength;encodingWidth;constructor(e,t){super(),this.entries=e,this.indefiniteLength=t?.indefiniteLength??!1,this.encodingWidth=t?.encodingWidth}_toCBOR(e){if(this.indefiniteLength){let t=[new Uint8Array([191])];for(let[n,r]of this.entries)t.push(n._toCBOR(e),r._toCBOR(e));return t.push(new Uint8Array([255])),h(t)}let t=[m(5,BigInt(this.entries.length),this.encodingWidth)];for(let[n,r]of this.entries)t.push(n._toCBOR(e),r._toCBOR(e));return h(t)}_toCDN(e,t){let n=v(e),r=e?.preserveComments,i=r&&(ce(this)||this.entries.some(([e,t])=>se(e)||se(t)));n===null&&i&&(n=` `);let{inlineSep:a,multilineSep:o,trailSep:s,colSep:c}=fe(e,n===null),l=!this.indefiniteLength&&this.encodingWidth!==void 0?`_${this.encodingWidth} `:``,u=this.indefiniteLength?`{_ `:`{${l}`;if(n===null||this.entries.length===0&&!i){let n=this.entries.map(([n,r])=>`${n._toCDN(e,t+1)}${c}${r._toCDN(e,t+1)}`).join(a);return this.indefiniteLength?this.entries.length===0?`{_ }`:`{_ ${n}}`:`{${l}${n}}`}let d=y(n,t+1),f=y(n,t),p=[];for(let n=0;n<this.entries.length;n++){let[i,a]=this.entries[n];r&&p.push(...le(i,d));let l=n<this.entries.length-1?o:s,u=r?Ne([...i.comments?.trailing??[],...a.comments?.leading??[],...a.comments?.trailing??[]]):``;p.push(`${d}${i._toCDN(e,t+1)}${c}${a._toCDN(e,t+1)}${l}${u}`)}return r&&p.push(...de(this,d)),`${u}\n${p.join(`
|
|
26
|
+
`)}\n${f}}`}_toHexDump(e,t){let n=e=>e.toString(16).toUpperCase().padStart(2,`0`),r=e=>Array.from(e,e=>e.toString(16).toUpperCase().padStart(2,`0`)).join(` `);if(this.indefiniteLength){let r=[{depth:e,hex:n(191),comment:`Start indefinite-length map`}];for(let[n,i]of this.entries)r.push(...n._toHexDump(e+1,t)),r.push(...i._toHexDump(e+1,t));return r.push({depth:e,hex:n(255),comment:`"break"`}),r}let i=[{depth:e,hex:r(m(5,BigInt(this.entries.length),this.encodingWidth)),comment:`Map of length ${this.entries.length}`}];for(let[n,r]of this.entries)i.push(...n._toHexDump(e+1,t)),i.push(...r._toHexDump(e+1,t));return i}_toJS(e){let t=e?.reviver,n=()=>{let n=$.from(this.entries,([t,n])=>[t._toJS(e),n._toJS(e)]);if(!t)return n;let r=e?.undefinedOmits;for(let e=0;e<n.length;e++){let[i,a]=n[e],o=t.call(n,i,a);o===l||r&&o===void 0?n.splice(e--,1):n[e]=[i,o]}return n};return e?.mapAs===`entries`?n():e?.mapAs===`object`||this.entries.every(([e])=>e instanceof N)?(()=>{let n=e?{...e,reviver:void 0}:void 0,r={};for(let[e,t]of this.entries){let i=e instanceof N?e.value:e.toCDN(),a=t._toJS(n);i===`__proto__`?Object.defineProperty(r,i,{value:a,writable:!0,enumerable:!0,configurable:!0}):r[i]=a}if(!t)return r;let i=new Map;for(let e=0;e<this.entries.length;e++){let[t]=this.entries[e];i.set(t instanceof N?t.value:t.toCDN(),e)}for(let n=0;n<this.entries.length;n++){let[a,o]=this.entries[n],s=a instanceof N?a.value:a.toCDN();if(i.get(s)!==n)continue;let c=o._toJS(e),u=t.call(r,s,c);u===l||e?.undefinedOmits&&u===void 0?delete r[s]:s===`__proto__`?Object.defineProperty(r,s,{value:u,writable:!0,enumerable:!0,configurable:!0}):r[s]=u}return r})():n()}};function Ne(e){return e.length===0?``:` `+e.map(e=>e.text.trimEnd()).join(` `)}var O=class e extends d{value;constructor(e){if(super(),!Number.isInteger(e)||e<0||e>255)throw RangeError(`CborSimple value must be an integer in 0–255`);this.value=e}static FALSE=new e(20);static TRUE=new e(21);static NULL=new e(22);static UNDEFINED=new e(23);_toCBOR(e){return this.value<=23?new Uint8Array([224|this.value]):new Uint8Array([248,this.value])}_toCDN(e,t){switch(this.value){case 20:return`false`;case 21:return`true`;case 22:return`null`;case 23:return`undefined`;default:return`simple(${this.value})`}}_toJS(e){switch(this.value){case 20:return!1;case 21:return!0;case 22:return null;case 23:return;default:return new u(this.value)}}},k=class extends d{items;constructor(e){super(),this.items=e}_content(e){return h(this.items.map(t=>t._toCBOR(e)))}_toCBOR(e){let t=this._content(e);return h([m(2,BigInt(t.length)),t])}_toCDN(e,t){if(this.items.length===0)return`<<>>`;let n=v(e),{inlineSep:r,multilineSep:i,trailSep:a}=fe(e,n===null);if(n===null)return`<<${this.items.map(n=>n._toCDN(e,t+1)).join(r)}>>`;let o=y(n,t+1),s=y(n,t),c=this.items.map(n=>`${o}${n._toCDN(e,t+1)}`),l=c.length-1;return`<<\n${c.map((e,t)=>t<l?`${e}${i}`:`${e}${a}`).join(`
|
|
27
|
+
`)}\n${s}>>`}_toHexDump(e,t){let n=e=>Array.from(e,e=>e.toString(16).toUpperCase().padStart(2,`0`)).join(` `),r=this._content().length,i=[{depth:e,hex:n(m(2,BigInt(r))),comment:`Embedded CBOR sequence, ${r} byte${r===1?``:`s`}`}];for(let n of this.items)i.push(...n._toHexDump(e+1,t));return i}_toJS(e){return this._content()}},Pe=999n,Fe=class extends S{constructor(e,t){let n=t.length===1&&t[0]instanceof N?t[0]:new E(t);super(Pe,new E([new N(e),n]))}_toCDN(e,t){let n=this.content,r=n.items[0].value,i=n.items[1];return i instanceof N?`${r}${Te(i.value)}`:`${r}<<${i.items.map(n=>n._toCDN(e,t)).join(`, `)}>>`}},Ie=888n,A=class extends S{constructor(e){e===void 0?super(Ie,O.NULL):super(Ie,new E(e))}_toCDN(e,t){return this.content instanceof O?`...`:this.content instanceof E?this.content.items.map(n=>n._toCDN(e,t)).join(` + `):super._toCDN(e,t)}},Le=2n,Re=3n,ze=18446744073709551615n,Be=-(ze+1n);function Ve(e){if(e<0n)throw RangeError(`bigintToBytes requires a non-negative value`);if(e===0n)return new Uint8Array;let t=e.toString(16);t.length%2!=0&&(t=`0`+t);let n=new Uint8Array(t.length/2);for(let e=0;e<n.length;e++)n[e]=parseInt(t.slice(e*2,e*2+2),16);return n}function He(e){let t=0n;for(let n of e)t=t<<8n|BigInt(n);return t}var j=class extends S{bigValue;constructor(e){if(e<=ze)throw RangeError(`CborBigUint value ${e} fits in CborUint; use CborUint instead`);super(Le,new C(Ve(e))),this.bigValue=e}_toCDN(e,t){return this.bigValue.toString()}_toJS(e){return this.bigValue}},M=class extends S{bigValue;constructor(e){if(e>=Be)throw RangeError(`CborBigNint value ${e} fits in CborNint; use CborNint instead`);super(Re,new C(Ve(-1n-e))),this.bigValue=e}_toCDN(e,t){return this.bigValue.toString()}_toJS(e){return this.bigValue}};function Ue(e,t){let n=new Me(e,{offset:t?.offset}),r=new nt(n,t?.extensions,t?.unresolvedExtension,t?.allowInvalidUtf8,t?.allowTrailing).parse();return t?.preserveComments&&Qe(r,n.comments,e),r}function We(e){let t=e,n;if(/[_][0-3i]$/.test(e)){let r=e[e.length-1];n=r===`i`?`i`:Number(r),t=e.slice(0,-2)}return{numStr:t,encodingWidth:n}}function Ge(e){return e.startsWith(`-`)?-BigInt(e.slice(1)):BigInt(e)}function Ke(e){if(e===`NaN`)return{value:NaN,precision:void 0};if(e===`Infinity`)return{value:1/0,precision:void 0};if(e===`-Infinity`)return{value:-1/0,precision:void 0};if(e.endsWith(`_i`)||e.endsWith(`_0`))throw SyntaxError(`EDN parse error: _0 and _i encoding indicators are not valid for floating-point values`);let t=e,n;return e.endsWith(`_1`)?(n=`half`,t=e.slice(0,-2)):e.endsWith(`_2`)?(n=`single`,t=e.slice(0,-2)):e.endsWith(`_3`)&&(n=`double`,t=e.slice(0,-2)),/^-?0[xX]/.test(t)?{value:ke(t),precision:n}:{value:parseFloat(t),precision:n}}function qe(e){if(typeof Uint8Array.fromHex==`function`)return Uint8Array.fromHex(e);if(e.length%2!=0)throw SyntaxError(`hex string has odd length: ${e.length}`);let t=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)t[n/2]=parseInt(e.slice(n,n+2),16);return t}var Je=`ABCDEFGHIJKLMNOPQRSTUVWXYZ234567`,Ye=`0123456789ABCDEFGHIJKLMNOPQRSTUV`;function Xe(e,t){let n=e.replace(/=+$/,``).toUpperCase(),r=n.length%8;if(r===1||r===3||r===6)throw SyntaxError(`invalid base32 length: ${n.length} characters`);let i=new Uint8Array(128).fill(255);for(let e=0;e<t.length;e++)i[t.charCodeAt(e)]=e;let a=new Uint8Array(Math.floor(n.length*5/8)),o=0,s=0,c=0;for(let e of n){let t=e.charCodeAt(0),n=t<128?i[t]:255;if(n===255)throw SyntaxError(`invalid character in byte string: ${JSON.stringify(e)}`);o=o<<5|n,s+=5,s>=8&&(s-=8,a[c++]=o>>s&255)}if(s>0&&o&(1<<s)-1)throw SyntaxError(`non-zero trailing bits in base32 input`);return a}function Ze(e){if(typeof Uint8Array.fromBase64==`function`){let t=/[-_]/.test(e)?`base64url`:`base64`;return Uint8Array.fromBase64(e,{alphabet:t,lastChunkHandling:`loose`})}let t=e.replace(/-/g,`+`).replace(/_/g,`/`),n=t+`=`.repeat((4-t.length%4)%4),r=atob(n),i=new Uint8Array(r.length);for(let e=0;e<r.length;e++)i[e]=r.charCodeAt(e);return i}function Qe(e,t,n){if(t.length===0)return;let r=$e(e),i=tt(n);for(let a of t){let t={...a},o=[...r].filter(e=>e.end<=a.start).sort((e,t)=>t.end-e.end||t.start-e.start)[0],s=o?n.slice(o.end,a.start):``;if(o&&i(o.end)===a.line&&!s.includes(`:`)){et(o.node,`trailing`,t);continue}let c=[...r].filter(e=>e.start<a.start&&a.end<e.end).sort((e,t)=>t.start-e.start||e.end-t.end)[0],l=[...r].filter(e=>e.start>=a.end).sort((e,t)=>e.start-t.start||t.end-e.end)[0];if((!c||l&&l.end<=c.end)&&l){et(l.node,`leading`,t);continue}et(c?.node??e,`dangling`,t)}}function $e(e){let t=[],n=e=>{if(e.start!==void 0&&e.end!==void 0&&t.push({node:e,start:e.start,end:e.end}),e instanceof E||e instanceof k){for(let t of e.items)n(t);return}if(e instanceof D){for(let[t,r]of e.entries)n(t),n(r);return}if(e instanceof w||e instanceof T){for(let t of e.chunks)n(t);return}e instanceof S&&n(e.content)};return n(e),t}function et(e,t,n){e.comments??={},e.comments[t]??=[],e.comments[t].push(n)}function tt(e){let t=[0];for(let n=0;n<e.length;n++)e[n]===`
|
|
28
|
+
`&&t.push(n+1);return n=>{let r=Math.max(0,Math.min(e.length,n));r>0&&r===e.length&&r--;let i=0,a=t.length-1;for(;i<=a;){let e=i+a>>1;t[e]<=r?i=e+1:a=e-1}return a+1}}var nt=class{t;allowInvalidUtf8;allowTrailing;extByPrefix;extByTag;unresolvedExtension;constructor(e,t,n,r,i){this.t=e,this.allowInvalidUtf8=r,this.allowTrailing=i,this.extByPrefix=new Map,this.extByTag=new Map,this.unresolvedExtension=n??`cpa999`;for(let e of[...Z,...t??[]]){for(let t of e.appStringPrefixes??[])this.extByPrefix.set(t,e);for(let t of e.tagNumbers??[])this.extByTag.set(t,e)}}parse(){let e=this.parseValue();if(this.allowTrailing)return e;let t=this.t.peek();return t.type!==`EOF`&&this._fail(`unexpected token after value: ${JSON.stringify(t.value)}`,t),e}parseValue(){let e=this.t.peek().offset,t=this._parseValueNode();return t.start=e,t.end=this.t.lastEndOffset,t}_parseValueNode(){let e=this.t.peek();switch(e.type){case`INTEGER`:return this.parseIntegerOrTag();case`FLOAT`:return this.parseFloat();case`TSTR`:case`RAWSTRING`:return this.parseString();case`BYTES_HEX`:case`SQSTR`:case`BYTES_B64`:case`BYTES_B32`:case`BYTES_H32`:return this.t.consume(),this._parseBytesConcat(this._decodeBytesToken(e),e.type,e.raw);case`EMPTY_INDEF_BYTES`:return this.t.consume(),new w([]);case`EMPTY_INDEF_TEXT`:return this.t.consume(),new T([]);case`TRUE`:return this.t.consume(),O.TRUE;case`FALSE`:return this.t.consume(),O.FALSE;case`NULL`:return this.t.consume(),O.NULL;case`UNDEFINED`:return this.t.consume(),O.UNDEFINED;case`SIMPLE`:return this.parseSimple();case`LBRACKET`:return this.parseArray();case`LBRACE`:return this.parseMap();case`LPAREN`:return this.parseIndefGroup();case`LT_LT`:return this.parseEmbeddedCBOR();case`APP_STRING`:{this.t.consume();let t=this.extByPrefix.get(e.appPrefix);if(!t?.parseAppString){if(this.unresolvedExtension===`cpa999`)return new Fe(e.appPrefix,[new N(e.value)]);this._fail(`unknown app-string extension: ${JSON.stringify(e.appPrefix)}`,e)}return t.parseAppString(e.appPrefix,e.value)}case`APP_SEQUENCE`:{this.t.consume();let t=[];for(;this.t.peek().type!==`GT_GT`&&(this.t.peek().type===`EOF`&&this._fail(`unterminated ${e.appPrefix}<<...>>`,e),!(t.length>0&&this.t.peek().type===`COMMA`&&(this.t.consume(),this.t.peek().type===`GT_GT`)));)t.push(this.parseValue());this.expect(`GT_GT`);let n=this.extByPrefix.get(e.appPrefix);if(!n){if(this.unresolvedExtension===`cpa999`)return new Fe(e.appPrefix,t);this._fail(`unknown app-string extension: ${JSON.stringify(e.appPrefix)}`,e)}return n.parseAppSequence||this._fail(`app-string extension ${JSON.stringify(e.appPrefix)} does not support <<...>> form`,e),n.parseAppSequence(e.appPrefix,t)}case`ELLIPSIS`:{if(this.t.consume(),this.t.peek().type!==`PLUS`)return new A;let e=[new A];for(;this.t.peek().type===`PLUS`;)this.t.consume(),e.push(this.parseValue());return new A(e)}case`BYTES_HEX_ELIDED`:return this.t.consume(),this._parseHexElidedConcat(e);default:this._fail(`unexpected token: ${JSON.stringify(e.value)}`,e)}}parseIntegerOrTag(){let e=this.t.consume(),{numStr:t,encodingWidth:n}=We(e.value),r=n===void 0?this.consumeEncodingIndicator():n,i=Ge(t);if(i>18446744073709551615n)return this.t.peek().type===`LPAREN`&&this._fail(`tag number exceeds maximum uint64`,e),new j(i);if(i<-18446744073709551616n)return new M(i);let a=i>=0n?new g(i,r===void 0?void 0:{encodingWidth:r}):new _(i,r===void 0?void 0:{encodingWidth:r});if(this.t.peek().type===`LPAREN`){a instanceof g||this._fail(`tag number must be non-negative`,e),this.t.consume();let t=this.parseValue();this.expect(`RPAREN`);let n=a.value,i=this.extByTag.get(n);if(i?.parseTag){let e=i.parseTag(n,t);if(e!==void 0)return e}return new S(n,t,r===void 0?void 0:{encodingWidth:r})}return a}parseFloat(){let{value:e,precision:t}=Ke(this.t.consume().value);return new x(e,t===void 0?void 0:{precision:t})}parseString(){let e=this.t.consume();if(this.t.peek().type!==`PLUS`){let t=this.consumeEncodingIndicator();return new N(e.value,t===void 0?void 0:{encodingWidth:t})}let t=!1,n=[{text:e.value}];for(;this.t.peek().type===`PLUS`;){this.t.consume();let e=this.t.peek();e.type===`ELLIPSIS`?(this.t.consume(),n.push({ellipsis:!0}),t=!0):e.type===`TSTR`||e.type===`RAWSTRING`?(this.t.consume(),n.push({text:e.value})):this._isBytesToken(e.type)?(this.t.consume(),n.push({text:this._decodeUtf8(this._decodeBytesToken(e),e)})):this._fail(`expected string or byte string after +, got ${JSON.stringify(e.value)}`,e)}if(!t){let e=this.consumeEncodingIndicator();return new N(n.map(e=>`text`in e?e.text:``).join(``),e===void 0?void 0:{encodingWidth:e})}let r=[],i=``;for(let e of n)`ellipsis`in e?(i!==``&&(r.push(new N(i)),i=``),r.push(new A)):i+=e.text;return i!==``&&r.push(new N(i)),new A(r)}_isBytesToken(e){return e===`BYTES_HEX`||e===`SQSTR`||e===`BYTES_B64`||e===`BYTES_B32`||e===`BYTES_H32`}_decodeBytesToken(e){switch(e.type){case`BYTES_HEX`:case`SQSTR`:return qe(e.value);case`BYTES_B64`:return Ze(e.value);case`BYTES_B32`:return Xe(e.value,Je);case`BYTES_H32`:return Xe(e.value,Ye);default:this._fail(`expected byte string token`,e)}}_decodeUtf8(e,t){if(this.allowInvalidUtf8)return new TextDecoder(`utf-8`,{fatal:!1}).decode(e);try{return new TextDecoder(`utf-8`,{fatal:!0}).decode(e)}catch{this._fail(`byte string in text concatenation is not valid UTF-8`,t)}}_tokenTypeToCdnEncoding(e){switch(e){case`BYTES_B64`:return`base64`;case`BYTES_B32`:return`base32`;case`BYTES_H32`:return`base32hex`;default:return`hex`}}_parseBytesConcat(e,t,n){if(this.t.peek().type!==`PLUS`){let r=this.consumeEncodingIndicator();return new C(e,{ednEncoding:this._tokenTypeToCdnEncoding(t),ednSource:n,...r===void 0?{}:{encodingWidth:r}})}let r=!1,i=[{bytes:e}];for(;this.t.peek().type===`PLUS`;){this.t.consume();let e=this.t.peek();if(e.type===`ELLIPSIS`)this.t.consume(),i.push({ellipsis:!0}),r=!0;else if(e.type===`BYTES_HEX_ELIDED`){this.t.consume();let t=this._buildBytesElidedItems(e.value);for(let e of t)e instanceof A?(i.push({ellipsis:!0}),r=!0):e instanceof C&&i.push({bytes:e.value})}else this._isBytesToken(e.type)?(this.t.consume(),i.push({bytes:this._decodeBytesToken(e)})):e.type===`TSTR`||e.type===`RAWSTRING`?(this.t.consume(),i.push({bytes:new TextEncoder().encode(e.value)})):this._fail(`expected byte string after +, got ${JSON.stringify(e.value)}`,e)}if(!r){let e=this.consumeEncodingIndicator(),t=i.map(e=>`bytes`in e?e.bytes:new Uint8Array);return new C(this._concatBytes(t),e===void 0?void 0:{encodingWidth:e})}let a=[],o=[],s=()=>{o.length>0&&(a.push(new C(this._concatBytes([...o]))),o.length=0)};for(let e of i)`ellipsis`in e?(s(),a.push(new A)):o.push(e.bytes);return s(),new A(a)}_parseHexElidedConcat(e){let t=this._buildBytesElidedItems(e.value);for(;this.t.peek().type===`PLUS`;){this.t.consume();let e=this.t.peek();if(e.type===`ELLIPSIS`)this.t.consume(),t.push(new A);else if(e.type===`BYTES_HEX_ELIDED`){this.t.consume();let n=this._buildBytesElidedItems(e.value);this._mergeFirstBytesItem(t,n)}else if(this._isBytesToken(e.type)){this.t.consume();let n=this._decodeBytesToken(e),r=t[t.length-1];r instanceof C?t[t.length-1]=new C(this._concatBytes([r.value,n])):t.push(new C(n))}else this._fail(`expected byte string after +, got ${JSON.stringify(e.value)}`,e)}return new A(t)}_buildBytesElidedItems(e){let t=e.split(`...`),n=[];for(let e=0;e<t.length;e++)e>0&&n.push(new A),t[e].length>0&&n.push(new C(qe(t[e])));return n}_mergeFirstBytesItem(e,t){if(t.length===0)return;let n=e[e.length-1],r=t[0];n instanceof C&&r instanceof C?(e[e.length-1]=new C(this._concatBytes([n.value,r.value])),e.push(...t.slice(1))):e.push(...t)}_concatBytes(e){let t=e.reduce((e,t)=>e+t.byteLength,0),n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.byteLength;return n}parseSimple(){this.t.consume(),this.expect(`LPAREN`);let e=this.t.peek();e.type!==`INTEGER`&&this._fail(`expected integer inside simple(), got ${JSON.stringify(e.value)}`,e),this.t.consume();let{numStr:t}=We(e.value),n=Number(Ge(t));return this.expect(`RPAREN`),new O(n)}parseEmbeddedCBOR(){this.t.consume();let e=[];for(;this.t.peek().type!==`GT_GT`&&!(e.length>0&&this.t.peek().type===`COMMA`&&(this.t.consume(),this.t.peek().type===`GT_GT`));)e.push(this.parseValue());return this.expect(`GT_GT`),new k(e)}parseArray(){this.t.consume();let e=!1,t;if(this.t.peek().type===`UNDERSCORE`)this.t.consume(),e=!0;else if(this.t.peek().type===`ENCODING_INDICATOR`){let e=this.t.consume().value;t=e===`i`?`i`:Number(e)}let n=[];for(;this.t.peek().type!==`RBRACKET`&&!(n.length>0&&this.t.peek().type===`COMMA`&&(this.t.consume(),this.t.peek().type===`RBRACKET`));)n.push(this.parseValue());return this.expect(`RBRACKET`),new E(n,{indefiniteLength:e,encodingWidth:t})}parseMap(){this.t.consume();let e=!1,t;if(this.t.peek().type===`UNDERSCORE`)this.t.consume(),e=!0;else if(this.t.peek().type===`ENCODING_INDICATOR`){let e=this.t.consume().value;t=e===`i`?`i`:Number(e)}let n=[];for(;this.t.peek().type!==`RBRACE`&&!(n.length>0&&this.t.peek().type===`COMMA`&&(this.t.consume(),this.t.peek().type===`RBRACE`));){let e=this.parseValue();this.expect(`COLON`);let t=this.parseValue();n.push([e,t])}return this.expect(`RBRACE`),new D(n,{indefiniteLength:e,encodingWidth:t})}parseIndefGroup(){this.t.consume();let e=this.t.peek();e.type!==`UNDERSCORE`&&this._fail(`expected _ after (, got ${JSON.stringify(e.value)}`,e),this.t.consume();let t=[];for(;this.t.peek().type!==`RPAREN`&&!(t.length>0&&this.t.peek().type===`COMMA`&&(this.t.consume(),this.t.peek().type===`RPAREN`));)t.push(this.parseValue());this.expect(`RPAREN`),t.length===0&&this._fail(`empty indefinite group (_ ) is ambiguous; use ''_ for bytes or ""_ for text`);let n=t[0];if(n instanceof C)return new w(t.map((e,t)=>{if(e instanceof C)return e;this._fail(`indefinite byte string chunk ${t} must be a byte string, not a text string`)}));if(n instanceof N)return new T(t.map((e,t)=>{if(e instanceof N)return e;this._fail(`indefinite text string chunk ${t} must be a text string, not a byte string`)}));this._fail(`indefinite group chunks must be byte strings or text strings`)}consumeEncodingIndicator(){if(this.t.peek().type===`ENCODING_INDICATOR`){let e=this.t.consume().value;return e===`i`?`i`:Number(e)}}expect(e){let t=this.t.consume();return t.type!==e&&this._fail(`expected ${e}, got ${t.type} (${JSON.stringify(t.value)})`,t),t}_fail(e,t){let n=t?` at line ${t.line}, column ${t.col}`:``;throw SyntaxError(`EDN parse error${n}: ${e}`)}},rt=new TextEncoder,it=!1,N=class extends d{indefiniteLength=!1;value;encodingWidth;constructor(e,t){super(),this.value=e,this.encodingWidth=t?.encodingWidth}_toCBOR(e){let t=rt.encode(this.value);return h([m(3,BigInt(t.length),this.encodingWidth),t])}_toCDN(e,t){let n=this.encodingWidth===void 0?``:`_${this.encodingWidth}`;return at(this.value,n,e,t)}_toJS(e){return this.value}};function at(e,t,n,r){let i=ot(n?.textStringFormat??[]),a=v(n);if(i.length===0||a===null)return b(e)+t;let o=new Map,s=null;if(i.includes(`cdn`)&&(s=ct(e),s!==null))for(let{point:e,contentDepth:t}of s)o.set(e,t);if(i.includes(`newline`)){let t=s===null?st(e,0):lt(e);for(let{point:e,contentDepth:n}of t)o.has(e)||o.set(e,n)}let c=gt(e,o);if(c.length<=1)return b(e)+t;let l=c.map(({text:e},n)=>{let r=b(e);return n===c.length-1?r+t:r}),u=l[0];for(let e=1;e<l.length;e++){let t=y(a,r+1+c[e].contentDepth);u+=` +\n${t}${l[e]}`}return u}function ot(e){return e.map(e=>e===`cboredn`?(it||(it=!0,console.warn("`textStringFormat: ['cboredn']` is deprecated; use `textStringFormat: ['cdn']` instead.")),`cdn`):e)}function st(e,t){let n=[];for(let r=0;r<e.length;r++){let i=e[r];i===`\r`?e[r+1]===`
|
|
29
|
+
`?(n.push({point:r+2,contentDepth:t}),r++):n.push({point:r+1,contentDepth:t}):i===`
|
|
30
|
+
`&&n.push({point:r+1,contentDepth:t})}return n}function ct(e){try{Ue(e)}catch{return null}let t=[],n=new Me(e),r=0,i=null,a=!1,o=0;for(;;){let s=n.consume();if(s.type===`EOF`)break;let c=!1;if(a||(a=!0,s.offset>0&&mt(n.comments,0,s.offset)&&t.push({point:s.offset,contentDepth:r})),i!==null){if(i.kind===`opener`&&dt.has(s.type)){i.point=s.endOffset,o=s.endOffset;continue}else i.kind===`opener`&&pt.has(s.type)&&ht(e,i.point,s.offset)?c=!0:t.push({point:s.offset,contentDepth:i.contentDepth});i=null}ft.has(s.type)?(r++,i={point:s.endOffset,contentDepth:r,kind:`opener`}):pt.has(s.type)?(r=Math.max(0,r-1),c||t.push({point:s.offset,contentDepth:r})):s.type===`COMMA`&&(i={point:s.endOffset,contentDepth:r,kind:`comma`}),o=s.endOffset}let s=n.comments.find(e=>e.start>=o);return s!==void 0&&t.push({point:s.start,contentDepth:r}),t}function lt(e){let t=[],n=new Me(e),r=0;for(;;){let i=n.consume();if(i.type===`EOF`)break;if(ft.has(i.type))r++;else if(pt.has(i.type))r=Math.max(0,r-1);else if(i.type!==`COMMA`&&ut.has(i.type)){let n=e.slice(i.offset,i.endOffset);for(let{point:e}of st(n,0))t.push({point:i.offset+e,contentDepth:r+1})}}return t}var ut=new Set([`TSTR`,`RAWSTRING`]),dt=new Set([`ENCODING_INDICATOR`,`UNDERSCORE`]),ft=new Set([`LBRACKET`,`LBRACE`,`LPAREN`,`LT_LT`]),pt=new Set([`RBRACKET`,`RBRACE`,`RPAREN`,`GT_GT`]);function mt(e,t,n){return e.some(e=>e.start>=t&&e.end<=n)}function ht(e,t,n){return/^[\t\n\r ]*$/.test(e.slice(t,n))}function gt(e,t){let n=[...t].filter(([t])=>t>0&&t<e.length).sort(([e],[t])=>e-t);if(n.length===0)return[{text:e,contentDepth:0}];let r=[],i=0,a=0;for(let[t,o]of n)t!==i&&(r.push({text:e.slice(i,t),contentDepth:a}),i=t,a=o);return i<e.length&&r.push({text:e.slice(i),contentDepth:a}),r}function P(e){if(Number.isInteger(e))return new Date(e*1e3).toISOString().replace(/\.000Z$/,`Z`);let t=Math.round(e*1e3);if(t/1e3===e)return new Date(t).toISOString().replace(/\.000Z$/,`Z`);let n=Math.floor(e),r=e-n,i=new Date(n*1e3).toISOString().replace(/\.\d+Z$/,``),a=r.toString(),o=a.indexOf(`.`),s=o>=0?a.slice(o+1):`0`;for(;s.length<3;)s+=`0`;return`${i}.${s}Z`}function _t(e){if(e.length!==1)throw SyntaxError(`dt<<...>>: expected exactly one item`);let t=e[0];if(t instanceof N)return t.value;if(t instanceof C)return new TextDecoder(`utf-8`,{fatal:!0}).decode(t.value);throw SyntaxError(`dt<<...>>: expected a text string or byte string`)}function vt(e){let t=e.match(/^(.+T\d{2}:\d{2}:\d{2})(\.\d+)(Z|[+-]\d{2}:\d{2})$/i),n,r;t?(n=t[1]+t[3],r=parseFloat(`0`+t[2])):(n=e,r=void 0);let i=Date.parse(n);if(isNaN(i))throw SyntaxError(`dt: invalid RFC 3339 date-time: ${JSON.stringify(e)}`);if(r===void 0){let e=i/1e3;return e>=0?new bt(BigInt(e)):new xt(BigInt(e))}return new St(i/1e3+r)}var yt=1n,bt=class extends g{constructor(e,t){super(e,t)}_toCDN(e,t){return e?.appStrings===!1?super._toCDN(e,t):`dt'${P(Number(this.value))}'`}},xt=class extends _{constructor(e,t){super(e,t)}_toCDN(e,t){return e?.appStrings===!1?super._toCDN(e,t):`dt'${P(Number(this.value))}'`}},St=class extends x{constructor(e,t){super(e,t)}_toCDN(e,t){return e?.appStrings===!1?super._toCDN(e,t):`dt'${P(this.value)}'`}},Ct=class extends S{constructor(e,t){super(yt,vt(e),t)}_toCDN(e,t){if(e?.appStrings===!1)return super._toCDN(e,t);let n=this.content;return`DT'${P(n instanceof x?n.value:Number(n.value))}'`}},wt=class extends Ct{constructor(e,t){super(e,t)}_toJS(e){let t=this.content,n=t instanceof x?t.value*1e3:Number(t.value)*1e3;return new Date(n)}};function Tt(e){let t=e?.jsDate??!1;function n(e){return t?new wt(e):new Ct(e)}let r={appStringPrefixes:[`dt`,`DT`],tagNumbers:[yt],parseAppString(e,t){return e===`DT`?n(t):vt(t)},parseAppSequence(e,t){let r=_t(t);return e===`DT`?n(r):vt(r)},parseTag(e,t){if(e!==1n)return;let r;if(t instanceof g)r=Number(t.value);else if(t instanceof _)r=Number(t.value);else if(t instanceof x)r=t.value;else return;return n(P(r))}};return t&&(r.fromJS=(e,t)=>{if(e instanceof Date)return new wt(P(e.getTime()/1e3))},r.isJSType=e=>e instanceof Date),r}var Et=Tt(),Dt=Tt({jsDate:!0});function F(e){let t=e.split(`.`);if(t.length!==4)throw SyntaxError(`ip: invalid IPv4 address: ${JSON.stringify(e)}`);let n=new Uint8Array(4);for(let e=0;e<4;e++){let r=t[e];if(!/^\d+$/.test(r)||r.length>1&&r[0]===`0`)throw SyntaxError(`ip: invalid IPv4 octet: ${JSON.stringify(r)}`);let i=parseInt(r,10);if(i>255)throw SyntaxError(`ip: IPv4 octet out of range: ${i}`);n[e]=i}return n}function Ot(e){let t=new Uint8Array(16);if(e===`::`)return t;let n=e,r=null,i=e.match(/^(.*):(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/);i&&(n=i[1],n.endsWith(`:`)&&(n+=`:`),r=F(i[2]));let a=n.split(`::`);if(a.length>2)throw SyntaxError(`ip: invalid IPv6 address: ${JSON.stringify(e)}`);let o=a.length===2,s=a[0]?a[0].split(`:`):[],c=o&&a[1]?a[1].split(`:`):[],l=r?6:8;if(!o&&s.length!==l||o&&s.length+c.length>=l)throw SyntaxError(`ip: invalid IPv6 address: ${JSON.stringify(e)}`);let u=l-s.length-c.length,d=[...s,...Array(u).fill(`0`),...c],f=0;for(let e of d){if(!/^[0-9a-fA-F]{1,4}$/.test(e))throw SyntaxError(`ip: invalid IPv6 group: ${JSON.stringify(e)}`);let n=parseInt(e,16);t[f++]=n>>8&255,t[f++]=n&255}return r&&t.set(r,12),t}function I(e){return Array.from(e).join(`.`)}function kt(e){let t=e.slice(0,10).every(e=>e===0)&&e[10]===255&&e[11]===255?I(e.slice(12)):null,n=t?6:8,r=[];for(let t=0;t<n*2;t+=2)r.push(e[t]<<8|e[t+1]);let i=-1,a=0,o=0;for(;o<n;)if(r[o]===0){let e=o+1;for(;e<n&&r[e]===0;)e++;e-o>a&&(i=o,a=e-o),o=e}else o++;a<2&&(i=-1);let s=e=>e.toString(16),c;return c=i===-1?r.map(s).join(`:`):`${r.slice(0,i).map(s).join(`:`)}::${r.slice(i+a).map(s).join(`:`)}`,t?`${c}:${t}`:c}var L=`ip`,R=`IP`,z=52n,B=54n;function At(e){if(e.length!==1)throw SyntaxError(`ip<<...>>: expected exactly one item`);let t=e[0];if(t instanceof N)return t.value;if(t instanceof C)return new TextDecoder(`utf-8`,{fatal:!0}).decode(t.value);throw SyntaxError(`ip<<...>>: expected a text string or byte string`)}function jt(e){return/^\d/.test(e)&&e.includes(`.`)&&!e.includes(`:`)?{bytes:F(e),isV4:!0}:{bytes:Ot(e),isV4:!1}}function V(e){if(e.length===4)return I(e);if(e.length===16)return kt(e);throw SyntaxError(`ip: unexpected byte length: ${e.length}`)}function Mt(e,t){let n=new Uint8Array(e.length);n.set(e);let r=Math.floor(t/8),i=t%8;i>0&&r<e.length&&(n[r]&=255<<8-i&255);for(let t=r+ +(i>0);t<e.length;t++)n[t]=0;let a=Math.ceil(t/8);for(;a>0&&n[a-1]===0;)a--;return n.slice(0,a)}function Nt(e,t){let n=new Uint8Array(t);return n.set(e),n}var Pt=class extends C{_toCDN(e,t){return e?.appStrings===!1?super._toCDN(e,t):`${L}'${V(this.value)}'`}},Ft=class extends E{_isV4;constructor(e,t,n){super([new g(BigInt(e)),new C(t)]),this._isV4=n}_toCDN(e,t){if(e?.appStrings===!1)return super._toCDN(e,t);let n=Number(this.items[0].value),r=this.items[1].value;return`${L}'${V(Nt(r,this._isV4?4:16))}/${n}'`}},H=class extends S{constructor(e,t){super(e,t)}_toCDN(e,t){if(e?.appStrings===!1)return super._toCDN(e,t);let n=this.tag===z?4:16,r=this.content;if(r instanceof C)return`${R}'${V(r.value)}'`;if(r instanceof E&&r.items.length===2&&r.items[0]instanceof g&&r.items[1]instanceof C){let e=Number(r.items[0].value);return`${R}'${V(Nt(r.items[1].value,n))}/${e}'`}return super._toCDN(e,t)}};function It(e,t){let n=t.indexOf(`/`);if(n===-1){let{bytes:n,isV4:r}=jt(t);return e===R?new H(r?z:B,new C(n)):new Pt(n)}let r=t.slice(0,n),i=t.slice(n+1);if(!/^\d+$/.test(i))throw SyntaxError(`ip: invalid prefix length: ${JSON.stringify(i)}`);let a=parseInt(i,10),{bytes:o,isV4:s}=jt(r),c=s?32:128;if(a>c)throw SyntaxError(`ip: prefix length ${a} exceeds maximum ${c} for ${s?`IPv4`:`IPv6`}`);let l=Mt(o,a);return e===R?new H(s?z:B,new E([new g(BigInt(a)),new C(l)])):new Ft(a,l,s)}var Lt={appStringPrefixes:[L,R],tagNumbers:[z,B],parseAppString(e,t){return It(e,t)},parseAppSequence(e,t){return It(e,At(t))},parseTag(e,t){if(!(e!==z&&e!==B)&&(t instanceof C||t instanceof E))return new H(e,t)}},Rt=18446744073709551615n,zt=-(Rt+1n),Bt={tagNumbers:[Le,Re],parseTag(e,t){if(t instanceof C){if(e===2n){let e=He(t.value);return e>Rt?new j(e):void 0}if(e===3n){let e=-1n-He(t.value);return e<zt?new M(e):void 0}}}},Vt=`cri`,U=`CRI`,Ht=99n,Ut=new Map([[`coap`,-1n],[`coaps`,-2n],[`http`,-3n],[`https`,-4n],[`urn`,-5n],[`did`,-6n],[`coap+tcp`,-7n],[`coaps+tcp`,-8n],[`coap+ws`,-25n],[`coaps+ws`,-26n]]),Wt=new Map([...Ut.entries()].map(([e,t])=>[t,e]));function W(e){try{return decodeURIComponent(e)}catch{return e}}function Gt(e){return Array.from(new TextEncoder().encode(e),e=>`%${e.toString(16).toUpperCase().padStart(2,`0`)}`).join(``)}function G(e,t){let n=``;for(let r of e)n+=t(r)?r:Gt(r);return n}function Kt(e){return/[A-Za-z0-9\-._~]/.test(e)}function qt(e){return/[!$&'()*+,;=]/.test(e)}function Jt(e){return Kt(e)||qt(e)||e===`:`||e===`@`}function Yt(e){return(Jt(e)||e===`/`||e===`?`)&&e!==`&`}function Xt(e){return Jt(e)||e===`/`||e===`?`}function Zt(e){return Kt(e)||qt(e)||e===`:`}function Qt(e){return Kt(e)||qt(e)}function $t(e){let t=[],n=e,r=n.indexOf(`@`);r>=0&&(t.push(O.FALSE),t.push(new N(W(n.slice(0,r)))),n=n.slice(r+1));let i,a=null;if(n.startsWith(`[`)){let e=n.indexOf(`]`);if(e<0)throw SyntaxError(`cri: unterminated IPv6 bracket in authority`);i=n.slice(1,e);let r=n.slice(e+1);if(r.startsWith(`:`))a=r.slice(1);else if(r.length>0)throw SyntaxError(`cri: unexpected characters after ']' in authority`);t.push(new C(Ot(i)))}else{let e=n.lastIndexOf(`:`);if(e>=0?(i=n.slice(0,e),a=n.slice(e+1)):i=n,i!==``)if(/^\d{1,3}(\.\d{1,3}){3}$/.test(i))t.push(new C(F(i)));else for(let e of i.toLowerCase().split(`.`))t.push(new N(e))}if(a!==null&&a!==``){if(!/^\d+$/.test(a))throw SyntaxError(`cri: invalid port: ${JSON.stringify(a)}`);let e=parseInt(a,10);if(e>65535)throw SyntaxError(`cri: port ${e} out of range`);t.push(new g(BigInt(e)))}return new E(t)}function en(e){let t=e.items,n=0,r=``;if(n<t.length&&t[n]instanceof O&&t[n].value===20){n++;let e=t[n++];r+=G(e.value,Zt)+`@`}if(n>=t.length)return r;let i=t[n];if(i instanceof C){n++;let{length:e}=i.value;if(e===4)r+=I(i.value);else if(e===16)r+=`[`+kt(i.value)+`]`;else throw Error(`cri: unexpected host-ip byte length: ${e}`);n<t.length&&t[n]instanceof N&&(r+=`%25${G(t[n++].value,Qt)}`)}else{let e=[];for(;n<t.length&&t[n]instanceof N;)e.push(G(t[n++].value,Qt));r+=e.join(`.`)}return n<t.length&&t[n]instanceof g&&(r+=`:`+t[n].value.toString()),r}function tn(e){let t=e.slice(2),n=t.indexOf(`/`),r,i;return n>=0?(r=t.slice(0,n),i=t.slice(n+1).split(`/`).map(e=>new N(W(e)))):(r=t,i=[]),{authority:$t(r),pathSegments:i}}function nn(e){let t=e,n=null,r=t.indexOf(`#`);r>=0&&(n=W(t.slice(r+1)),t=t.slice(0,r));let i=null,a=t.indexOf(`?`);if(a>=0){let e=t.slice(a+1);t=t.slice(0,a),i=e.split(`&`).map(e=>new N(W(e)))}let o=[],s=/^([a-zA-Z][a-zA-Z0-9+.\-]*):([\s\S]*)$/.exec(t);if(s){let e=s[1].toLowerCase(),t=s[2],n=Ut.get(e);if(o.push(n===void 0?new N(e):new _(n)),t.startsWith(`//`)){let{authority:e,pathSegments:n}=tn(t);o.push(e,new E(n))}else if(t.startsWith(`/`)){let e=t.slice(1).split(`/`).map(e=>new N(W(e)));o.push(O.NULL,new E(e))}else{let e=t.split(`/`).map(e=>new N(W(e)));o.push(O.TRUE,new E(e))}}else if(t.startsWith(`//`)){let{authority:e,pathSegments:n}=tn(t);o.push(O.FALSE,e,new E(n))}else if(t.startsWith(`/`)){let e=t.slice(1).split(`/`).map(e=>new N(W(e)));o.push(O.TRUE,new E(e))}else if(t===``)o.push(new g(0n));else{let n=1n,r=t,i=!1;for(r.startsWith(`./`)&&(i=!0,r=r.slice(2));r.startsWith(`../`);)n++,r=r.slice(3);if(r===`..`?(n++,r=``):r===`.`&&(r=``),n===1n&&!i&&r!==``&&r.split(`/`)[0].includes(`:`))throw SyntaxError(`cri: invalid relative-path reference — first segment must not contain ':' without a './' prefix (RFC 3986 §3.3): ${JSON.stringify(e)}`);let a=r===``?[]:r.split(`/`).map(e=>new N(W(e)));o.push(new g(n),new E(a))}if(i!==null&&o.push(new E(i)),n!==null&&(i===null&&o.push(O.NULL),o.push(new N(n))),n!==null&&i===null&&o.splice(o.length-2,1),i===null&&n===null){let e=o[o.length-1];e instanceof E&&e.items.length===0&&o.pop()}return o.length===1&&o[0]instanceof g&&o[0].value===0n?[]:o}function K(e,t){let n=t,r=``;if(n<e.length){let t=e[n];if(t instanceof E){if(n++,t.items.length>0){let e=t.items.map(e=>{if(!(e instanceof N))throw Error(`cri: query item must be a text string`);return G(e.value,Yt)});r+=`?`+e.join(`&`)}}else t instanceof O&&t.value===22&&n++}return n<e.length&&e[n]instanceof N&&(r+=`#`+G(e[n].value,Xt)),r}function q(e){return e.items.map(e=>{if(!(e instanceof N))throw Error(`cri: path segment must be a text string`);return G(e.value,Jt)})}function rn(e){if(e.length===0)return``;let t=0,n=e[t++];if(n instanceof _||n instanceof N){let r;if(n instanceof _){let e=Wt.get(n.value);if(e===void 0)throw Error(`cri: unrecognised scheme-id ${n.value}`);r=e+`:`}else r=n.value+`:`;if(t>=e.length)return r;let i=e[t++],a=``,o=!1;if(i instanceof E)a=`//`+en(i),o=!0;else if(i instanceof O)if(i.value===22)o=!0;else if(i.value===21)o=!1;else throw Error(`cri: unexpected no-authority value: simple(${i.value})`);else throw Error(`cri: unexpected type for authority element`);let s=``;if(t<e.length&&e[t]instanceof E){let n=e[t++];n.items.length>0&&(s=(o?`/`:``)+q(n).join(`/`))}return r+a+s+K(e,t)}if(n instanceof O&&n.value===20){if(t>=e.length||!(e[t]instanceof E))throw Error(`cri: network-path reference requires an authority array`);let n=en(e[t++]),r=``;if(t<e.length&&e[t]instanceof E){let n=e[t++];n.items.length>0&&(r=`/`+q(n).join(`/`))}return`//`+n+r+K(e,t)}if(n instanceof O&&n.value===21){let n=`/`;if(t<e.length&&e[t]instanceof E){let r=e[t++];n=`/`+q(r).join(`/`)}return n+K(e,t)}if(n instanceof g){let r=n.value;if(r===0n)return K(e,t);let i=r===1n?``:`../`.repeat(Number(r)-1),a;if(t<e.length&&e[t]instanceof E){let n=e[t++];if(n.items.length>0){let e=q(n);a=(r===1n&&e[0].includes(`:`)?`./`:i)+e.join(`/`)}else a=i===``?`./`:i}else a=i===``?`./`:i;return a+K(e,t)}throw Error(`cri: unrecognised first element type in CRI array`)}var an=class extends E{_toCDN(e,t){if(e?.appStrings===!1)return super._toCDN(e,t);try{return`${Vt}'${rn(this.items)}'`}catch{return super._toCDN(e,t)}}},on=class extends S{constructor(e){super(Ht,e)}_toCDN(e,t){if(e?.appStrings===!1)return super._toCDN(e,t);try{return`${U}'${rn(this.content.items)}'`}catch{return super._toCDN(e,t)}}};function sn(e){if(e.length!==1)throw SyntaxError(`cri<<...>>: expected exactly one item`);let t=e[0];if(t instanceof N)return t.value;if(t instanceof C)return new TextDecoder(`utf-8`,{fatal:!0}).decode(t.value);throw SyntaxError(`cri<<...>>: expected a text string or byte string`)}function cn(e,t){let n=new an(nn(t));return e===U?new on(n):n}var ln={appStringPrefixes:[Vt,U],tagNumbers:[Ht],parseAppString(e,t){return cn(e,t)},parseAppSequence(e,t){return cn(e,sn(t))},parseTag(e,t){if(e===99n&&t instanceof E)return new on(new an(t.items,{indefiniteLength:t.indefiniteLength,encodingWidth:t.encodingWidth}))}},un=new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});function J(e){throw Error(`CBOR decode error: ${e}`)}function Y(e,t,n){if(n<=23)return{value:BigInt(n),nextOffset:t};switch(n){case 24:return t+1>e.byteLength&&J(`unexpected end of input`),{value:BigInt(e.getUint8(t)),nextOffset:t+1};case 25:return t+2>e.byteLength&&J(`unexpected end of input`),{value:BigInt(e.getUint16(t,!1)),nextOffset:t+2};case 26:return t+4>e.byteLength&&J(`unexpected end of input`),{value:BigInt(e.getUint32(t,!1)),nextOffset:t+4};case 27:return t+8>e.byteLength&&J(`unexpected end of input`),{value:e.getBigUint64(t,!1),nextOffset:t+8};default:J(`reserved additional info value: ${n}`)}}function X(e,t,n){let r=t,i=dn(e,t,n);return i.value.start=r,i.value.end=i.nextOffset,i}function dn(e,t,n){t>=e.byteLength&&J(`unexpected end of input`);let r=e.getUint8(t++),i=r>>5,a=r&31;switch(i){case 0:{let{value:n,nextOffset:r}=Y(e,t,a);return{value:new g(n),nextOffset:r}}case 1:{let{value:n,nextOffset:r}=Y(e,t,a);return{value:new _(-1n-n),nextOffset:r}}case 2:{if(a===31){let r=[],i=t;for(;;){if(i>=e.byteLength&&J(`unexpected end of indefinite byte string`),e.getUint8(i)===255){i++;break}let t=X(e,i,n);t.value instanceof C||J(`indefinite-length byte string chunk must be a definite byte string`),r.push(t.value),i=t.nextOffset}return{value:new w(r),nextOffset:i}}let{value:r,nextOffset:i}=Y(e,t,a),o=Number(r);return i+o>e.byteLength&&J(`byte string extends beyond input`),{value:new C(new Uint8Array(e.buffer,e.byteOffset+i,o).slice()),nextOffset:i+o}}case 3:{if(a===31){let r=[],i=t;for(;;){if(i>=e.byteLength&&J(`unexpected end of indefinite text string`),e.getUint8(i)===255){i++;break}let t=X(e,i,n);t.value instanceof N||J(`indefinite-length text string chunk must be a definite text string`),r.push(t.value),i=t.nextOffset}return{value:new T(r),nextOffset:i}}let{value:r,nextOffset:i}=Y(e,t,a),o=Number(r);i+o>e.byteLength&&J(`text string extends beyond input`);let s=new Uint8Array(e.buffer,e.byteOffset+i,o),c;try{c=un.decode(s)}catch{J(`invalid UTF-8 sequence in text string`)}return{value:new N(c),nextOffset:i+o}}case 4:{if(a===31){let r=[],i=t;for(;;){if(i>=e.byteLength&&J(`unexpected end of indefinite array`),e.getUint8(i)===255){i++;break}let t=X(e,i,n);r.push(t.value),i=t.nextOffset}return{value:new E(r,{indefiniteLength:!0}),nextOffset:i}}let{value:r,nextOffset:i}=Y(e,t,a),o=Number(r),s=[],c=i;for(let t=0;t<o;t++){let t=X(e,c,n);s.push(t.value),c=t.nextOffset}return{value:new E(s),nextOffset:c}}case 5:{if(a===31){let r=[],i=t;for(;;){if(i>=e.byteLength&&J(`unexpected end of indefinite map`),e.getUint8(i)===255){i++;break}let t=X(e,i,n);i=t.nextOffset;let a=X(e,i,n);i=a.nextOffset,r.push([t.value,a.value])}return{value:new D(r,{indefiniteLength:!0}),nextOffset:i}}let{value:r,nextOffset:i}=Y(e,t,a),o=Number(r),s=[],c=i;for(let t=0;t<o;t++){let t=X(e,c,n);c=t.nextOffset;let r=X(e,c,n);c=r.nextOffset,s.push([t.value,r.value])}return{value:new D(s),nextOffset:c}}case 6:{a===31&&J(`tags cannot use indefinite-length encoding`);let{value:r,nextOffset:i}=Y(e,t,a),o=X(e,i,n);for(let e of[...n?.extensions??[],...Z])if(e.parseTag){let t=e.parseTag(r,o.value);if(t!==void 0)return{value:t,nextOffset:o.nextOffset}}return{value:new S(r,o.value),nextOffset:o.nextOffset}}case 7:if(a<=19)return{value:new O(a),nextOffset:t};if(a===20)return{value:O.FALSE,nextOffset:t};if(a===21)return{value:O.TRUE,nextOffset:t};if(a===22)return{value:O.NULL,nextOffset:t};if(a===23)return{value:O.UNDEFINED,nextOffset:t};if(a===24){t+1>e.byteLength&&J(`unexpected end of input`);let n=e.getUint8(t);return n<32&&J(`simple value ${n} must be encoded in initial byte (0–31 reserved for extended encoding)`),{value:new O(n),nextOffset:t+1}}return a===25?(t+2>e.byteLength&&J(`unexpected end of input`),{value:new x(te(e.getUint16(t,!1)),{precision:`half`}),nextOffset:t+2}):a===26?(t+4>e.byteLength&&J(`unexpected end of input`),{value:new x(e.getFloat32(t,!1),{precision:`single`}),nextOffset:t+4}):a===27?(t+8>e.byteLength&&J(`unexpected end of input`),{value:new x(e.getFloat64(t,!1),{precision:`double`}),nextOffset:t+8}):(a<31&&J(`reserved additional info value in major type 7: ${a}`),J(`unexpected break code outside indefinite-length item`))}return J(`unknown major type: ${i}`)}function fn(e){if(e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw TypeError(`expected ArrayBufferView or ArrayBufferLike`)}function pn(e,t){let n=fn(e),r=new DataView(n.buffer,n.byteOffset,n.byteLength),i=t?.offset??0;if(!Number.isInteger(i)||i<0||i>r.byteLength)throw RangeError(`CBOR decode offset must be an integer between 0 and ${r.byteLength}`);let{value:a,nextOffset:o}=X(r,i,t);return!t?.allowTrailing&&o!==r.byteLength&&J(`${r.byteLength-o} trailing byte(s) after end of CBOR item`),a}var mn=24n,Z=[Et,Lt,Bt,ln,{tagNumbers:[mn],parseTag(e,t){if(e===24n&&t instanceof C)try{return new S(mn,new k([pn(t.value)]))}catch{return}}}];function Q(e,t){if(t?.replacer){let{replacer:n,...r}=t,i=_n(e,n,r.extensions,r.undefinedOmits);return i===l?O.UNDEFINED:Q(i,Object.keys(r).length>0?r:void 0)}return hn(e,t,!0)}function hn(e,t,n){for(let n of[...t?.extensions??[],...Z])if(n.fromJS){let r=n.fromJS(e,t??{});if(r!==void 0)return r}if(n&&typeof e==`object`&&e&&c.symbol in e){let n=e[c.symbol],r=hn(e,t,!1);for(let e of[...t?.extensions??[],...Z])if(e.parseTag){let t=e.parseTag(n,r);if(t!==void 0)return t}return new S(n,r)}if(e instanceof c.Null)return O.NULL;if(e instanceof c.Undefined)return O.UNDEFINED;if(e instanceof u)return new O(e.value);if(e===null)return O.NULL;if(e===void 0)return O.UNDEFINED;if(e===!0)return O.TRUE;if(e===!1)return O.FALSE;if(typeof e==`bigint`)return e>18446744073709551615n?new j(e):e<-18446744073709551616n?new M(e):e>=0n?new g(e):new _(e);if(typeof e==`number`)return(t?.encodeIntegerAs??`int`)===`int`&&Number.isInteger(e)&&!Object.is(e,-0)?e>=0?new g(BigInt(e)):new _(BigInt(e)):new x(e);if(typeof e==`string`)return new N(e);if(e instanceof Number||e instanceof Boolean||e instanceof String||Object.prototype.toString.call(e)===`[object BigInt]`)return hn(e.valueOf(),t,!1);if(e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer)return new C(new Uint8Array(e));if(ArrayBuffer.isView(e))return e instanceof Uint8Array&&t?.uint8ArrayAs===`array`?new E(Array.from(e,e=>new g(BigInt(e)))):new C(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));if(e instanceof $)return new D([...e].map(([e,n])=>[Q(e,t),Q(n,t)]));if(Array.isArray(e))return new E(e.map(e=>Q(e,t)));if(typeof e==`object`){let n=[];for(let[r,i]of Object.entries(e))n.push([new N(r),Q(i,t)]);return new D(n)}throw TypeError(`fromJS: unsupported value type: ${typeof e}`)}function gn(e){return ArrayBuffer.isView(e)||e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer||e instanceof Number||e instanceof Boolean||e instanceof String||Object.prototype.toString.call(e)===`[object BigInt]`||e instanceof c.Null||e instanceof c.Undefined||e instanceof u}function _n(e,t,n,r){let i=[...n??[],...Z];function a(e){return e===l||r===!0&&e===void 0}if(Array.isArray(t)){let n=t.map(String);function o(e){if(typeof e!=`object`||!e)return e;if(e instanceof $)return $.from(e,([e,t])=>[e,o(t)]);if(Array.isArray(e))return e.map(o);if(c.symbol in e||gn(e)||i.some(t=>t.isJSType?.(e)))return e;let t=Object.getPrototypeOf(e);if(t===Object.prototype||t===null){let t=e.toJSON;if(typeof t==`function`)return o(t.call(e))}let r={};for(let t of n)Object.prototype.hasOwnProperty.call(e,t)&&(r[t]=o(e[t]));return r}return o(e)}let s=t;function u(e,t,n){if(typeof e==`object`&&e&&!(e instanceof $)){let n=Object.getPrototypeOf(e);if(n===Object.prototype||n===null){let n=e.toJSON;typeof n==`function`&&(e=n.call(e,t))}}if(e=s.call(n,t,e),typeof e==`object`&&e){if(c.symbol in e)return e;if(e instanceof $){let t=new $;for(let[n,r]of e){let i=u(r,n,e);a(i)||t.push([n,i])}return t}if(Array.isArray(e))return e.map((t,n)=>{let r=u(t,String(n),e);return a(r)?null:r});if(gn(e)||i.some(t=>t.isJSType?.(e)))return e;let t={};for(let n of Object.keys(e)){let r=u(e[n],n,e);a(r)||(t[n]=r)}return t}return e}return u(e,``,{"":e})}var $=class extends Array{toJSON(){let e={};for(let[t,n]of this){let r=typeof t==`string`?t:Q(t).toCDN();r===`__proto__`?Object.defineProperty(e,r,{value:n,writable:!0,enumerable:!0,configurable:!0}):e[r]=n}return e}};Object.defineProperty(exports,`C`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`D`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`E`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`S`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`T`,{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return Dt}}),Object.defineProperty(exports,`b`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return pn}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return _n}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return Q}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return Ue}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return $}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`w`,{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,`x`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`y`,{enumerable:!0,get:function(){return _}});
|
|
31
|
+
//# sourceMappingURL=mapEntries-CNxwMt7o.cjs.map
|