@cbortech/cbor 0.27.1 → 0.27.2
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 +27 -0
- package/README.md +28 -0
- package/dist/ast/CborItem.d.ts +17 -2
- package/dist/ast/CborTag.d.ts +22 -0
- package/dist/ast/CborUnresolvedAppExt.d.ts +9 -0
- package/dist/ast/index.cjs +1 -1
- package/dist/ast/index.js +2 -2
- package/dist/cbor/tagLabels.d.ts +26 -0
- package/dist/cddl/eRefScope.d.ts +241 -0
- package/dist/cddl/eref.d.ts +64 -0
- package/dist/cddl/implicitTags.d.ts +28 -0
- package/dist/cddl/index.cjs +2 -2
- package/dist/cddl/index.cjs.map +1 -1
- package/dist/cddl/index.d.ts +2 -0
- package/dist/cddl/index.js +26 -25
- package/dist/cddl/index.js.map +1 -1
- package/dist/cddl/validator.d.ts +98 -2
- package/dist/cdn/index.cjs +1 -1
- package/dist/cdn/index.js +1 -1
- package/dist/cdn/serialize-utils.d.ts +20 -13
- package/dist/extensions/eref.d.ts +135 -0
- package/dist/index.cjs +7 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +190 -81
- package/dist/index.js.map +1 -1
- package/dist/js/fromJS.d.ts +23 -1
- package/dist/mapEntries-8zshEr-t.js +7085 -0
- package/dist/mapEntries-8zshEr-t.js.map +1 -0
- package/dist/mapEntries-DwHPAzCN.cjs +68 -0
- package/dist/mapEntries-DwHPAzCN.cjs.map +1 -0
- package/dist/schema-7r2xjpMK.js +345 -0
- package/dist/schema-7r2xjpMK.js.map +1 -0
- package/dist/schema-YiigSWjR.cjs +8 -0
- package/dist/schema-YiigSWjR.cjs.map +1 -0
- package/dist/{serialize-utils-h-CVB9rg.js → serialize-utils-BQtutOo6.js} +14 -6
- package/dist/serialize-utils-BQtutOo6.js.map +1 -0
- package/dist/{serialize-utils-DhlW61ZX.cjs → serialize-utils-DQ8T3Mzw.cjs} +5 -5
- package/dist/serialize-utils-DQ8T3Mzw.cjs.map +1 -0
- package/dist/types.d.ts +153 -4
- package/package.json +8 -8
- package/dist/mapEntries-CCLaJSaJ.js +0 -4127
- package/dist/mapEntries-CCLaJSaJ.js.map +0 -1
- package/dist/mapEntries-CZZJScaj.cjs +0 -13
- package/dist/mapEntries-CZZJScaj.cjs.map +0 -1
- package/dist/schema-DN9inJny.js +0 -1977
- package/dist/schema-DN9inJny.js.map +0 -1
- package/dist/schema-zsg5yCPK.cjs +0 -63
- package/dist/schema-zsg5yCPK.cjs.map +0 -1
- package/dist/serialize-utils-DhlW61ZX.cjs.map +0 -1
- package/dist/serialize-utils-h-CVB9rg.js.map +0 -1
package/dist/cddl/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as e, Q as t, Z as n, d as r, f as i, m as a, p as o, u as s } from "../mapEntries-8zshEr-t.js";
|
|
2
|
+
import { n as c, t as l } from "../schema-7r2xjpMK.js";
|
|
2
3
|
//#region src/cddl/position.ts
|
|
3
|
-
function
|
|
4
|
+
function u(e, t) {
|
|
4
5
|
let n = Math.max(0, Math.min(t, e.length)), r = 1, i = 0;
|
|
5
6
|
for (let t = 0; t < n; t++) e.charCodeAt(t) === 10 && (r++, i = t + 1);
|
|
6
7
|
return {
|
|
@@ -10,13 +11,13 @@ function l(e, t) {
|
|
|
10
11
|
}
|
|
11
12
|
//#endregion
|
|
12
13
|
//#region src/cddl/index.ts
|
|
13
|
-
var
|
|
14
|
+
var d = class {
|
|
14
15
|
static compile(e, t) {
|
|
15
|
-
return
|
|
16
|
+
return c(e, t);
|
|
16
17
|
}
|
|
17
18
|
};
|
|
18
|
-
function
|
|
19
|
-
let t = new
|
|
19
|
+
function f(e) {
|
|
20
|
+
let t = new o(e), n = [];
|
|
20
21
|
for (;;) {
|
|
21
22
|
let e = t.consume();
|
|
22
23
|
if (e.type === "EOF") break;
|
|
@@ -27,41 +28,41 @@ function d(e) {
|
|
|
27
28
|
comments: t.comments
|
|
28
29
|
};
|
|
29
30
|
}
|
|
30
|
-
function
|
|
31
|
-
let
|
|
31
|
+
function p(t) {
|
|
32
|
+
let n = new o(t), r = [];
|
|
32
33
|
try {
|
|
33
34
|
for (;;) {
|
|
34
|
-
let e =
|
|
35
|
+
let e = n.consume();
|
|
35
36
|
if (e.type === "EOF") break;
|
|
36
|
-
|
|
37
|
+
r.push(e);
|
|
37
38
|
}
|
|
38
39
|
return {
|
|
39
|
-
tokens:
|
|
40
|
-
comments:
|
|
40
|
+
tokens: r,
|
|
41
|
+
comments: n.comments
|
|
41
42
|
};
|
|
42
43
|
} catch (i) {
|
|
43
|
-
let a = i instanceof
|
|
44
|
-
if (o <
|
|
45
|
-
let
|
|
46
|
-
for (let
|
|
47
|
-
|
|
44
|
+
let a = i instanceof e ? i : new e(i instanceof Error ? i.message : String(i)), o = n.lastEndOffset;
|
|
45
|
+
if (o < t.length) {
|
|
46
|
+
let e = 1, n = 1;
|
|
47
|
+
for (let r = 0; r < o; r++) t[r] === "\n" ? (e++, n = 1) : n++;
|
|
48
|
+
r.push({
|
|
48
49
|
type: "ERROR",
|
|
49
|
-
value:
|
|
50
|
-
raw:
|
|
51
|
-
line:
|
|
52
|
-
col:
|
|
50
|
+
value: t.slice(o),
|
|
51
|
+
raw: t.slice(o),
|
|
52
|
+
line: e,
|
|
53
|
+
col: n,
|
|
53
54
|
offset: o,
|
|
54
|
-
endOffset:
|
|
55
|
+
endOffset: t.length
|
|
55
56
|
});
|
|
56
57
|
}
|
|
57
58
|
return {
|
|
58
|
-
tokens:
|
|
59
|
-
comments:
|
|
59
|
+
tokens: r,
|
|
60
|
+
comments: n.comments,
|
|
60
61
|
error: a
|
|
61
62
|
};
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
//#endregion
|
|
65
|
-
export {
|
|
66
|
+
export { d as CDDL, d as default, n as CddlMismatchError, l as CddlSchema, t as CddlSemanticError, e as CddlSyntaxError, s as PRELUDE_CDDL, a as getERefTables, r as getPreludeRules, i as parseCDDL, u as positionAt, f as tokenize, p as tokenizeLenient };
|
|
66
67
|
|
|
67
68
|
//# sourceMappingURL=index.js.map
|
package/dist/cddl/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/cddl/position.ts","../../src/cddl/index.ts"],"sourcesContent":["/**\n * Convert a character offset (as carried by CDDL AST nodes, CddlWarning,\n * and CddlValidationError.schemaStart/schemaEnd or start/end for CDN input)\n * into a 1-based line/column position, for CLI-style `file:line:col`\n * reporting.\n *\n * Offsets are JS string indices (UTF-16 code units), matching everything\n * else in this library. Offsets past the end of the text clamp to its end.\n */\nexport function positionAt(\n text: string,\n offset: number\n): { line: number; column: number } {\n const end = Math.max(0, Math.min(offset, text.length));\n let line = 1;\n let lineStart = 0;\n for (let i = 0; i < end; i++) {\n if (text.charCodeAt(i) === 0x0a) {\n line++;\n lineStart = i + 1;\n }\n }\n return { line, column: end - lineStart + 1 };\n}\n","/**\n * Public CDDL API (`@cbortech/cbor/cddl`).\n *\n * Phase 1 covers the grammar layer of RFC 8610 + RFC 9682: compiling CDDL\n * text into a checked rule table (`CDDL.compile`), re-serializing it\n * (`schema.format()`), and the lower-level tokenization API used by tooling\n * such as syntax highlighters. Validating CBOR/CDN data against a schema is\n * a later phase.\n */\n\nimport { CddlTokenizer, type CddlComment, type CddlToken } from './tokenizer';\nimport { CddlSyntaxError } from './errors';\nimport { compile, CddlSchema, type CompileOptions } from './schema';\n\nexport type { CddlToken, CddlTokenType, CddlComment } from './tokenizer';\nexport {\n CddlSyntaxError,\n CddlSemanticError,\n CddlMismatchError,\n} from './errors';\nexport type {\n CddlWarning,\n CddlValidationError,\n CddlValidationWarning,\n ValidationResult,\n} from './errors';\nexport type { ValidateOptions } from './validator';\nexport { CddlSchema } from './schema';\nexport type { CompileOptions } from './schema';\nexport { parseCDDL } from './parser';\nexport type { ParseCddlResult } from './parser';\nexport { PRELUDE_CDDL, getPreludeRules } from './prelude';\nexport { positionAt } from './position';\nexport type { CddlFormatOptions } from './writer';\nexport type {\n CddlRule,\n CddlType,\n CddlType1,\n CddlType2,\n CddlValue,\n CddlRef,\n CddlParenType,\n CddlMapType,\n CddlArrayType,\n CddlUnwrap,\n CddlEnum,\n CddlTagged,\n CddlMajor,\n CddlAny,\n CddlGroup,\n CddlGroupEntry,\n CddlEntryValue,\n CddlEntryGroup,\n CddlOccur,\n CddlMemberKey,\n CddlNodeBase,\n} from './ast';\n\n/** Main CDDL facade — mirrors the shape of the `CBOR` facade. */\nexport class CDDL {\n /**\n * Parse and compile a CDDL data model.\n *\n * @example\n * const schema = CDDL.compile(`person = { name: tstr, ? age: uint }`);\n * schema.root.name; // 'person'\n */\n static compile(text: string, options?: CompileOptions): CddlSchema {\n return compile(text, options);\n }\n}\n\nexport default CDDL;\n\nexport interface TokenizeResult {\n /** Scanned tokens in source order, excluding the final EOF token. */\n tokens: CddlToken[];\n /** Comments encountered while scanning, in source order. */\n comments: CddlComment[];\n}\n\nexport interface TokenizeLenientResult extends TokenizeResult {\n /**\n * The scan failure, if any. When set, `tokens` ends with a synthetic\n * `ERROR` token covering the source from the last clean token to the end\n * of the input.\n */\n error?: CddlSyntaxError;\n}\n\n/**\n * Tokenize CDDL text. Throws {@link CddlSyntaxError} on invalid input.\n */\nexport function tokenize(text: string): TokenizeResult {\n const tokenizer = new CddlTokenizer(text);\n const tokens: CddlToken[] = [];\n for (;;) {\n const tok = tokenizer.consume();\n if (tok.type === 'EOF') break;\n tokens.push(tok);\n }\n return { tokens, comments: tokenizer.comments };\n}\n\n/**\n * Error-tolerant tokenization for editors and highlighters: never throws on\n * invalid input. Tokens before the failure are returned as scanned; the\n * remainder of the input is covered by a single synthetic `ERROR` token and\n * the failure is reported in `error`.\n */\nexport function tokenizeLenient(text: string): TokenizeLenientResult {\n const tokenizer = new CddlTokenizer(text);\n const tokens: CddlToken[] = [];\n try {\n for (;;) {\n const tok = tokenizer.consume();\n if (tok.type === 'EOF') break;\n tokens.push(tok);\n }\n return { tokens, comments: tokenizer.comments };\n } catch (e) {\n const error =\n e instanceof CddlSyntaxError\n ? e\n : new CddlSyntaxError(e instanceof Error ? e.message : String(e));\n const start = tokenizer.lastEndOffset;\n if (start < text.length) {\n let line = 1;\n let col = 1;\n for (let i = 0; i < start; i++) {\n if (text[i] === '\\n') {\n line++;\n col = 1;\n } else {\n col++;\n }\n }\n tokens.push({\n type: 'ERROR',\n value: text.slice(start),\n raw: text.slice(start),\n line,\n col,\n offset: start,\n endOffset: text.length,\n });\n }\n return { tokens, comments: tokenizer.comments, error };\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/cddl/position.ts","../../src/cddl/index.ts"],"sourcesContent":["/**\n * Convert a character offset (as carried by CDDL AST nodes, CddlWarning,\n * and CddlValidationError.schemaStart/schemaEnd or start/end for CDN input)\n * into a 1-based line/column position, for CLI-style `file:line:col`\n * reporting.\n *\n * Offsets are JS string indices (UTF-16 code units), matching everything\n * else in this library. Offsets past the end of the text clamp to its end.\n */\nexport function positionAt(\n text: string,\n offset: number\n): { line: number; column: number } {\n const end = Math.max(0, Math.min(offset, text.length));\n let line = 1;\n let lineStart = 0;\n for (let i = 0; i < end; i++) {\n if (text.charCodeAt(i) === 0x0a) {\n line++;\n lineStart = i + 1;\n }\n }\n return { line, column: end - lineStart + 1 };\n}\n","/**\n * Public CDDL API (`@cbortech/cbor/cddl`).\n *\n * Phase 1 covers the grammar layer of RFC 8610 + RFC 9682: compiling CDDL\n * text into a checked rule table (`CDDL.compile`), re-serializing it\n * (`schema.format()`), and the lower-level tokenization API used by tooling\n * such as syntax highlighters. Validating CBOR/CDN data against a schema is\n * a later phase.\n */\n\nimport { CddlTokenizer, type CddlComment, type CddlToken } from './tokenizer';\nimport { CddlSyntaxError } from './errors';\nimport { compile, CddlSchema, type CompileOptions } from './schema';\n\nexport type { CddlToken, CddlTokenType, CddlComment } from './tokenizer';\nexport {\n CddlSyntaxError,\n CddlSemanticError,\n CddlMismatchError,\n} from './errors';\nexport type {\n CddlWarning,\n CddlValidationError,\n CddlValidationWarning,\n ValidationResult,\n} from './errors';\nexport type { ValidateOptions } from './validator';\nexport { CddlSchema } from './schema';\nexport type { CompileOptions } from './schema';\nexport { parseCDDL } from './parser';\nexport type { ParseCddlResult } from './parser';\nexport { PRELUDE_CDDL, getPreludeRules } from './prelude';\nexport { getERefTables } from './eref';\nexport type { ERefTables } from './eref';\nexport { positionAt } from './position';\nexport type { CddlFormatOptions } from './writer';\nexport type {\n CddlRule,\n CddlType,\n CddlType1,\n CddlType2,\n CddlValue,\n CddlRef,\n CddlParenType,\n CddlMapType,\n CddlArrayType,\n CddlUnwrap,\n CddlEnum,\n CddlTagged,\n CddlMajor,\n CddlAny,\n CddlGroup,\n CddlGroupEntry,\n CddlEntryValue,\n CddlEntryGroup,\n CddlOccur,\n CddlMemberKey,\n CddlNodeBase,\n} from './ast';\n\n/** Main CDDL facade — mirrors the shape of the `CBOR` facade. */\nexport class CDDL {\n /**\n * Parse and compile a CDDL data model.\n *\n * @example\n * const schema = CDDL.compile(`person = { name: tstr, ? age: uint }`);\n * schema.root.name; // 'person'\n */\n static compile(text: string, options?: CompileOptions): CddlSchema {\n return compile(text, options);\n }\n}\n\nexport default CDDL;\n\nexport interface TokenizeResult {\n /** Scanned tokens in source order, excluding the final EOF token. */\n tokens: CddlToken[];\n /** Comments encountered while scanning, in source order. */\n comments: CddlComment[];\n}\n\nexport interface TokenizeLenientResult extends TokenizeResult {\n /**\n * The scan failure, if any. When set, `tokens` ends with a synthetic\n * `ERROR` token covering the source from the last clean token to the end\n * of the input.\n */\n error?: CddlSyntaxError;\n}\n\n/**\n * Tokenize CDDL text. Throws {@link CddlSyntaxError} on invalid input.\n */\nexport function tokenize(text: string): TokenizeResult {\n const tokenizer = new CddlTokenizer(text);\n const tokens: CddlToken[] = [];\n for (;;) {\n const tok = tokenizer.consume();\n if (tok.type === 'EOF') break;\n tokens.push(tok);\n }\n return { tokens, comments: tokenizer.comments };\n}\n\n/**\n * Error-tolerant tokenization for editors and highlighters: never throws on\n * invalid input. Tokens before the failure are returned as scanned; the\n * remainder of the input is covered by a single synthetic `ERROR` token and\n * the failure is reported in `error`.\n */\nexport function tokenizeLenient(text: string): TokenizeLenientResult {\n const tokenizer = new CddlTokenizer(text);\n const tokens: CddlToken[] = [];\n try {\n for (;;) {\n const tok = tokenizer.consume();\n if (tok.type === 'EOF') break;\n tokens.push(tok);\n }\n return { tokens, comments: tokenizer.comments };\n } catch (e) {\n const error =\n e instanceof CddlSyntaxError\n ? e\n : new CddlSyntaxError(e instanceof Error ? e.message : String(e));\n const start = tokenizer.lastEndOffset;\n if (start < text.length) {\n let line = 1;\n let col = 1;\n for (let i = 0; i < start; i++) {\n if (text[i] === '\\n') {\n line++;\n col = 1;\n } else {\n col++;\n }\n }\n tokens.push({\n type: 'ERROR',\n value: text.slice(start),\n raw: text.slice(start),\n line,\n col,\n offset: start,\n endOffset: text.length,\n });\n }\n return { tokens, comments: tokenizer.comments, error };\n }\n}\n"],"mappings":";;;AASA,SAAgB,EACd,GACA,GACkC;CAClC,IAAM,IAAM,KAAK,IAAI,GAAG,KAAK,IAAI,GAAQ,EAAK,MAAM,CAAC,GACjD,IAAO,GACP,IAAY;CAChB,KAAK,IAAI,IAAI,GAAG,IAAI,GAAK,KACvB,AAAI,EAAK,WAAW,CAAC,MAAM,OACzB,KACA,IAAY,IAAI;CAGpB,OAAO;EAAE;EAAM,QAAQ,IAAM,IAAY;CAAE;AAC7C;;;ACsCA,IAAa,IAAb,MAAkB;CAQhB,OAAO,QAAQ,GAAc,GAAsC;EACjE,OAAO,EAAQ,GAAM,CAAO;CAC9B;AACF;AAuBA,SAAgB,EAAS,GAA8B;CACrD,IAAM,IAAY,IAAI,EAAc,CAAI,GAClC,IAAsB,CAAC;CAC7B,SAAS;EACP,IAAM,IAAM,EAAU,QAAQ;EAC9B,IAAI,EAAI,SAAS,OAAO;EACxB,EAAO,KAAK,CAAG;CACjB;CACA,OAAO;EAAE;EAAQ,UAAU,EAAU;CAAS;AAChD;AAQA,SAAgB,EAAgB,GAAqC;CACnE,IAAM,IAAY,IAAI,EAAc,CAAI,GAClC,IAAsB,CAAC;CAC7B,IAAI;EACF,SAAS;GACP,IAAM,IAAM,EAAU,QAAQ;GAC9B,IAAI,EAAI,SAAS,OAAO;GACxB,EAAO,KAAK,CAAG;EACjB;EACA,OAAO;GAAE;GAAQ,UAAU,EAAU;EAAS;CAChD,SAAS,GAAG;EACV,IAAM,IACJ,aAAa,IACT,IACA,IAAI,EAAgB,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,CAAC,GAC9D,IAAQ,EAAU;EACxB,IAAI,IAAQ,EAAK,QAAQ;GACvB,IAAI,IAAO,GACP,IAAM;GACV,KAAK,IAAI,IAAI,GAAG,IAAI,GAAO,KACzB,AAAI,EAAK,OAAO,QACd,KACA,IAAM,KAEN;GAGJ,EAAO,KAAK;IACV,MAAM;IACN,OAAO,EAAK,MAAM,CAAK;IACvB,KAAK,EAAK,MAAM,CAAK;IACrB;IACA;IACA,QAAQ;IACR,WAAW,EAAK;GAClB,CAAC;EACH;EACA,OAAO;GAAE;GAAQ,UAAU,EAAU;GAAU;EAAM;CACvD;AACF"}
|
package/dist/cddl/validator.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { CddlSchema } from './schema';
|
|
2
2
|
import { CborItem } from '../ast/CborItem';
|
|
3
|
+
import { CborMap } from '../ast/CborMap';
|
|
4
|
+
import { CborTag } from '../ast/CborTag';
|
|
3
5
|
import { ValidationResult } from './errors';
|
|
4
|
-
import { CddlValue } from './ast';
|
|
6
|
+
import { CddlGroup, CddlMemberKey, CddlType, CddlType1, CddlValue } from './ast';
|
|
5
7
|
export interface ValidateOptions {
|
|
6
8
|
/** Recursion guard for rule references and nested groups (default 256). */
|
|
7
9
|
maxDepth?: number;
|
|
@@ -26,5 +28,99 @@ export interface ValidateOptions {
|
|
|
26
28
|
*/
|
|
27
29
|
rule?: string;
|
|
28
30
|
}
|
|
29
|
-
|
|
31
|
+
/**
|
|
32
|
+
* One tag on a successful match path: `item` is a `CborTag` matched by a
|
|
33
|
+
* `#6.N(type)` with literal tag number `tag`, or — `inferred` — an
|
|
34
|
+
* untagged item that matched only as the content of such a type (see
|
|
35
|
+
* `TagTracing.infer`).
|
|
36
|
+
*/
|
|
37
|
+
export interface TagRecord {
|
|
38
|
+
readonly item: CborItem;
|
|
39
|
+
readonly tag: bigint;
|
|
40
|
+
readonly inferred: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* For an inferred record, how many inferred tags enclose this one around
|
|
43
|
+
* the same item (0 = outermost): `#6.101(#6.100(int))` records 101 at
|
|
44
|
+
* layer 0 and 100 at layer 1. Re-checking one layer (`.and`, …) repeats
|
|
45
|
+
* its layer; a genuinely nested tag, even of the same number, doesn't.
|
|
46
|
+
* Always 0 for a matched tag.
|
|
47
|
+
*/
|
|
48
|
+
readonly layer: number;
|
|
49
|
+
}
|
|
50
|
+
/** Tag bookkeeping for {@link validateItem}'s internal callers. */
|
|
51
|
+
export interface TagTracing {
|
|
52
|
+
/**
|
|
53
|
+
* Let `#6.N(type)` (literal N) accept an untagged item matching `type`,
|
|
54
|
+
* recording it as inferred. Only a fallback: at every type, rule and
|
|
55
|
+
* map-group choice, alternatives are first tried without inference.
|
|
56
|
+
*/
|
|
57
|
+
readonly infer?: boolean;
|
|
58
|
+
/** Tags to match as if absent (their content in their place). */
|
|
59
|
+
readonly stripped?: ReadonlySet<CborTag>;
|
|
60
|
+
/** Receives the successful path's records (left empty on failure). */
|
|
61
|
+
readonly trail: TagRecord[];
|
|
62
|
+
}
|
|
63
|
+
/** Generic parameter bindings; each binding closes over its defining env. */
|
|
64
|
+
type Env = Map<string, {
|
|
65
|
+
type1: CddlType1;
|
|
66
|
+
env: Env;
|
|
67
|
+
}> | undefined;
|
|
68
|
+
export declare function validateItem(schema: CddlSchema, item: CborItem, options?: ValidateOptions, tags?: TagTracing): ValidationResult;
|
|
69
|
+
/**
|
|
70
|
+
* Whether `item` matches `type` on its own, exactly as validation would
|
|
71
|
+
* check it at a position of that type (no generic bindings). `undefined`
|
|
72
|
+
* when the step/depth budget runs out.
|
|
73
|
+
*/
|
|
74
|
+
export declare function itemMatchesType(schema: CddlSchema, item: CborItem, type: CddlType, options?: ValidateOptions): boolean | undefined;
|
|
75
|
+
/** Opaque generic-parameter bindings in force at some point of a match. */
|
|
76
|
+
export type CddlEnv = Env;
|
|
77
|
+
/**
|
|
78
|
+
* The group member that consumed one map entry on the validator's own
|
|
79
|
+
* successful path — its member key, value type, and the generic bindings
|
|
80
|
+
* in force there.
|
|
81
|
+
*/
|
|
82
|
+
export interface MapMember {
|
|
83
|
+
readonly memberKey: CddlMemberKey;
|
|
84
|
+
readonly type: CddlType;
|
|
85
|
+
readonly env: CddlEnv;
|
|
86
|
+
}
|
|
87
|
+
/** One map group a type can denote, with its generic bindings. */
|
|
88
|
+
export interface MapGroupTarget {
|
|
89
|
+
readonly group: CddlGroup;
|
|
90
|
+
readonly env: CddlEnv;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Every map group (`{...}`) `type` can denote, following references,
|
|
94
|
+
* parentheses, choices and generic bindings exactly as `matchType()` does.
|
|
95
|
+
* `undefined` when some alternative could still match a map some *other*
|
|
96
|
+
* way this can't see into — `any`/`#5`, a control operator, `~unwrap`, an
|
|
97
|
+
* `&(...)` type, an undefined name — so no single group's assignment is
|
|
98
|
+
* known to be the one validation used.
|
|
99
|
+
*/
|
|
100
|
+
export declare function mapGroupsOfType(schema: CddlSchema, type: CddlType, env: CddlEnv): MapGroupTarget[] | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* The literal text a member key requires, when it requires exactly one:
|
|
103
|
+
* `name:`, `"name":`, or `"name" =>` (a text-literal key type).
|
|
104
|
+
*/
|
|
105
|
+
export declare function plainTextSpelling(mk: CddlMemberKey): string | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* Every spelling used as a plain text member key anywhere in `target`'s
|
|
108
|
+
* group — `name:`, `"name":`, or a key type that accepts a text literal
|
|
109
|
+
* (`"name" =>`, a rule or `/` choice of such literals, or a generic
|
|
110
|
+
* parameter bound to one, e.g. `K => …` in `G<"name">`) — through inline
|
|
111
|
+
* sub-groups, bare group references and `~unwrap`ped groups, expanded
|
|
112
|
+
* exactly as matching expands them (`expandEntry()`), across every choice
|
|
113
|
+
* and every distinct generic instantiation. `undefined` when the expansion
|
|
114
|
+
* runs out of budget.
|
|
115
|
+
*/
|
|
116
|
+
export declare function plainTextMemberKeys(schema: CddlSchema, target: MapGroupTarget): ReadonlySet<string> | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Match `map` against one map group exactly as validation does
|
|
119
|
+
* (`matchMapGroup()`), returning which member consumed each of its entries
|
|
120
|
+
* on the successful path (`false` for one left unconsumed, e.g. an elided
|
|
121
|
+
* `...` entry). `null` when it doesn't match; `undefined` when the budget
|
|
122
|
+
* runs out.
|
|
123
|
+
*/
|
|
124
|
+
export declare function traceMapGroup(schema: CddlSchema, map: CborMap, target: MapGroupTarget, options?: ValidateOptions): readonly (MapMember | false)[] | null | undefined;
|
|
30
125
|
export declare function matchesLiteral(item: CborItem, v: CddlValue): boolean;
|
|
126
|
+
export {};
|
package/dist/cdn/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../serialize-utils-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../serialize-utils-DQ8T3Mzw.cjs");function t(t){let n=new e.A(t),r=[];for(;;){let e=n.consume();if(e.type===`EOF`)break;r.push(e)}return{tokens:r,comments:n.comments}}function n(t){let n=new e.A(t),r=[];try{for(;;){let e=n.consume();if(e.type===`EOF`)break;r.push(e)}return{tokens:r,comments:n.comments}}catch(i){let a=i instanceof e.I?i:new e.I(i instanceof Error?i.message:String(i)),o=n.lastEndOffset;if(o<t.length){let e=1,n=1;for(let r=0;r<o;r++)t[r]===`
|
|
2
2
|
`?(e++,n=1):n++;r.push({type:`ERROR`,value:t.slice(o),raw:t.slice(o),line:e,col:n,offset:o,endOffset:t.length})}return{tokens:r,comments:n.comments,error:a}}}exports.CdnSyntaxError=e.I,exports.adjustAppSeqIndicator=e.t,exports.adjustRawAppSeqSource=e.n,exports.canonicalEncodingWidth=e.r,exports.decideTaggedAppSeqRendering=e.o,exports.resolveEiSuffix=e.C,exports.tokenize=t,exports.tokenizeLenient=n;
|
|
3
3
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cdn/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as e, C as t, I as n, n as r, o as i, r as a, t as o } from "../serialize-utils-
|
|
1
|
+
import { A as e, C as t, I as n, n as r, o as i, r as a, t as o } from "../serialize-utils-BQtutOo6.js";
|
|
2
2
|
//#region src/cdn/index.ts
|
|
3
3
|
function s(t) {
|
|
4
4
|
let n = new e(t), r = [];
|
|
@@ -237,7 +237,8 @@ export declare function serializeContainer(p: {
|
|
|
237
237
|
* no nested array/map — a multi-word string reads better with a line of
|
|
238
238
|
* its own. This does *not* also cover a prefixed literal like `h'...'`
|
|
239
239
|
* (which has no word count to check at all, but still disqualifies under
|
|
240
|
-
* the strict rule)
|
|
240
|
+
* the strict rule) or an app-string like `dt'...'` (word-counted, strict
|
|
241
|
+
* rule only) — that's covered separately, generically, by
|
|
241
242
|
* `isPrefixedLiteralText` (checked against the rendered entry `s` below)
|
|
242
243
|
* or, for a `CborTag`, `isMultiWordRenderedLiteral`. Omitted = never
|
|
243
244
|
* disqualifies.
|
|
@@ -324,17 +325,18 @@ export declare function serializeBytes(bytes: Uint8Array, encoding?: 'hex' | 'ba
|
|
|
324
325
|
*/
|
|
325
326
|
export declare function isMultiWordByteString(bytes: Uint8Array, sqstr?: 'printable-string' | 'string' | 'none'): boolean;
|
|
326
327
|
/**
|
|
327
|
-
* True when `rendered` — a single entry's own CDN rendering —
|
|
328
|
-
*
|
|
329
|
-
* backtick (`h'...'`, `b64'...'`, `ip'...'`, `dt'...'`, or any other
|
|
330
|
-
* app-string extension's own spelling, built-in or user-defined). These
|
|
331
|
-
* have no natural word boundary to check, so — like a byte string's own
|
|
332
|
-
* prefixed-literal case in `isMultiWordByteString` — the strict
|
|
328
|
+
* True when `rendered` — a single entry's own CDN rendering — starts with
|
|
329
|
+
* a prefixed literal that disqualifies under the strict
|
|
333
330
|
* `inlineLeafContainers` rule (`CborArray`/`CborMap`, and the
|
|
334
|
-
* indefinite-length string groups)
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
331
|
+
* indefinite-length string groups): a byte-string literal (`h'...'`,
|
|
332
|
+
* `b64'...'`), which has no natural word boundary to check (like a byte
|
|
333
|
+
* string's own prefixed-literal case in `isMultiWordByteString`), or an
|
|
334
|
+
* app-string extension literal (`ip'...'`, `dt'...'`, `e'...'`, or any
|
|
335
|
+
* other, built-in or user-defined) whose own content has two or more
|
|
336
|
+
* words — the latter is word-counted like a text string, so `e'alg'`
|
|
337
|
+
* stays a leaf while `dt'1969-07-21T02:56:16Z'` doesn't. The loose rule
|
|
338
|
+
* (only `CborEmbeddedCBOR`/`<<...>>`) treats either as an ordinary leaf
|
|
339
|
+
* instead, never calling this.
|
|
338
340
|
*
|
|
339
341
|
* This is a generic, rendering-based catch-all — unlike `isMultiWordByteString`,
|
|
340
342
|
* it doesn't need per-extension-class support, so it also covers any
|
|
@@ -365,8 +367,11 @@ export declare function isPrefixedLiteralText(rendered: string): boolean;
|
|
|
365
367
|
* - A bare quoted literal (`"..."`, `` `...` ``, or a bare `'...'` sqstr):
|
|
366
368
|
* always counts if its *decoded* content has two or more words,
|
|
367
369
|
* regardless of `strict` — matching a text string's own word count.
|
|
368
|
-
* - A prefixed literal (`h'...'`, `b64'...'
|
|
369
|
-
*
|
|
370
|
+
* - A prefixed byte-string literal (`h'...'`, `b64'...'`): has no natural
|
|
371
|
+
* word boundary to check, so it counts only when `strict`.
|
|
372
|
+
* - An app-string extension literal (`ip'...'`, `dt'...'`, `e'...'`, ...):
|
|
373
|
+
* counts only when `strict` *and* its content has two or more words (see
|
|
374
|
+
* `isPrefixedLiteralText`).
|
|
370
375
|
* - A generic tag wrapper (`tagNum[_EI](...)`) spanning the *entire* input:
|
|
371
376
|
* peels off just that one layer and recurses on what's inside (handling
|
|
372
377
|
* nested tags one layer at a time) — this is what lets a plain `CborTag`
|
|
@@ -387,6 +392,8 @@ export declare function isPrefixedLiteralText(rendered: string): boolean;
|
|
|
387
392
|
* all) still always counts, while a prefixed-literal item
|
|
388
393
|
* (`ilbs<<h'00'>>`) — unlike the same literal bare or tag-wrapped —
|
|
389
394
|
* does not.
|
|
395
|
+
* - A rendered array/map counts under the strict rule, including one
|
|
396
|
+
* exposed by `appPrefix: false` inside otherwise leaf-like tag wrappers.
|
|
390
397
|
* - Anything else (a number, `true`/`false`, multiple top-level tokens that
|
|
391
398
|
* aren't one of the wrappers above, ...) never counts.
|
|
392
399
|
*
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { FromCBOROptions, ToCDNOptions, ToJSOptions } from '../types';
|
|
2
|
+
import { CborExtension } from './types';
|
|
3
|
+
import { CborItem } from '../ast/CborItem';
|
|
4
|
+
import { CborUint } from '../ast/CborUint';
|
|
5
|
+
import { CborNint } from '../ast/CborNint';
|
|
6
|
+
import { EncodingWidth } from '../cbor/encode';
|
|
7
|
+
import { CddlSchema } from '../cddl/schema';
|
|
8
|
+
import { ValidateOptions } from '../cddl/validator';
|
|
9
|
+
export declare const PREFIX_EREF = "e";
|
|
10
|
+
interface ERefNodeOptions {
|
|
11
|
+
encodingWidth?: EncodingWidth;
|
|
12
|
+
ednSource?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Whether `toJS()` may use `refName` as this key's JS property name —
|
|
15
|
+
* `false` when `fromJS()` would *not* convert that name back to this
|
|
16
|
+
* integer key at this position (its string-key conversion is stricter
|
|
17
|
+
* than annotation — see `cddl/eRefScope.ts`'s module doc), so a
|
|
18
|
+
* `toJS()` → `fromJS()` round trip would otherwise silently turn the key
|
|
19
|
+
* into literal text. The `e'name'` label is then display-only: `toCDN()`
|
|
20
|
+
* still emits it, while `toJS()` treats the key as the plain integer it
|
|
21
|
+
* is. Set by `annotateERefKeys()`; defaults to `true`.
|
|
22
|
+
*/
|
|
23
|
+
jsKey?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A non-negative integer whose value a CDDL model names — `_toCDN()` emits
|
|
27
|
+
* `e'name'` notation unless `appPrefix` is `false`.
|
|
28
|
+
*/
|
|
29
|
+
export declare class CborERefUint extends CborUint {
|
|
30
|
+
readonly refName: string;
|
|
31
|
+
/** See `ERefNodeOptions.jsKey`. */
|
|
32
|
+
readonly jsKey: boolean;
|
|
33
|
+
constructor(value: number | bigint, refName: string, options?: ERefNodeOptions);
|
|
34
|
+
_toCDN(options: ToCDNOptions | undefined, depth: number, path?: readonly unknown[]): string;
|
|
35
|
+
_jsObjectKey(options: ToJSOptions | undefined): string | undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A negative integer whose value a CDDL model names — `_toCDN()` emits
|
|
39
|
+
* `e'name'` notation unless `appPrefix` is `false`.
|
|
40
|
+
*/
|
|
41
|
+
export declare class CborERefNint extends CborNint {
|
|
42
|
+
readonly refName: string;
|
|
43
|
+
/** See `ERefNodeOptions.jsKey`. */
|
|
44
|
+
readonly jsKey: boolean;
|
|
45
|
+
constructor(value: number | bigint, refName: string, options?: ERefNodeOptions);
|
|
46
|
+
_toCDN(options: ToCDNOptions | undefined, depth: number, path?: readonly unknown[]): string;
|
|
47
|
+
_jsObjectKey(options: ToJSOptions | undefined): string | undefined;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Build the `e'...'` `CborExtension` for one compiled CDDL schema.
|
|
51
|
+
*
|
|
52
|
+
* `parseAppString('e', 'title', …)` resolves `title` via the schema's
|
|
53
|
+
* `getERefTables().byName` and returns the appropriately-signed
|
|
54
|
+
* `CborERefUint`/`CborERefNint`. A name the schema does not define (or
|
|
55
|
+
* defines ambiguously — bound to more than one value — or defines only as a
|
|
56
|
+
* non-integer constant; see the module doc's Scope note) is a hard parse
|
|
57
|
+
* error, always thrown regardless of `onError`: there is no best-effort
|
|
58
|
+
* value to fall back to.
|
|
59
|
+
*/
|
|
60
|
+
export declare function createERefExtension(schema: CddlSchema): CborExtension;
|
|
61
|
+
/**
|
|
62
|
+
* Walk a CDDL-validated item tree and, for every plain (not already
|
|
63
|
+
* annotated) `CborUint`/`CborNint` used as a `CborMap` key — or as a map
|
|
64
|
+
* *value* whose own type is a closed `&(name: value)` choice of named
|
|
65
|
+
* integer constants (see `eRefValueFor()`'s own doc) — replace that node
|
|
66
|
+
* in place with the corresponding `CborERefUint`/`CborERefNint` — so
|
|
67
|
+
* `toCDN()` naturally emits `e'name'` notation (and, for a key, `toJS()`
|
|
68
|
+
* naturally uses `name` as the plain-object key — both by default;
|
|
69
|
+
* `appPrefix: false` / `eRefKeys: false` opt back out), without the caller
|
|
70
|
+
* having to spell `e'...'` in the original CBOR/CDN/JS source at all.
|
|
71
|
+
*
|
|
72
|
+
* Position-aware, exactly like `FromJSOptions.eRefKeys`'s own reverse
|
|
73
|
+
* direction (`cddl/eRefScope.ts`): starting from the schema's root rule (or
|
|
74
|
+
* `ruleName`, matching `ValidateOptions.rule` — the same rule the item was
|
|
75
|
+
* actually validated against), a key is only annotated with a name bound at
|
|
76
|
+
* a member-key position within the CDDL type actually reachable at *that*
|
|
77
|
+
* key's own structural position, descending through nested maps the same
|
|
78
|
+
* way this walk itself does — never a name that merely exists *somewhere*
|
|
79
|
+
* in the schema. This is deliberate, not merely cosmetic: a name that
|
|
80
|
+
* exists elsewhere in the schema but isn't reachable from this position is
|
|
81
|
+
* exactly the kind of name `fromJS()`'s `eRefKeys` option (correctly)
|
|
82
|
+
* refuses to convert back, so annotating with it here would make
|
|
83
|
+
* `toJS()` → `fromJS()` silently turn the original integer key into a
|
|
84
|
+
* *different*, wrong one (a plain text key, if the name isn't reachable at
|
|
85
|
+
* all) instead of round-tripping it byte-for-byte. A name reachable at this
|
|
86
|
+
* position also always satisfies `resolvesGloballyTo()` — the same
|
|
87
|
+
* schema-wide-uniqueness check `fromJS()` applies before labeling — so
|
|
88
|
+
* `e'name'` here always parses back to the same value via `fromCDN()`
|
|
89
|
+
* against the same schema too. A value's own label doesn't carry this same
|
|
90
|
+
* round-trip risk at all (see `eRefValueFor()`'s own doc for why), but is
|
|
91
|
+
* still gated by `resolvesGloballyTo()` for the CDN-reparse property alone.
|
|
92
|
+
*
|
|
93
|
+
* Data-aware, too: a key takes a name only from the group entry that
|
|
94
|
+
* actually consumed it in validation — read back from the validator's own
|
|
95
|
+
* map matching (`traceMapGroup()`), so value types, occurrence limits,
|
|
96
|
+
* entries already consumed and sub-group backtracking all count exactly as
|
|
97
|
+
* they did there — and nested content is only
|
|
98
|
+
* resolved against the value types that really matched. `ruleOrOptions`
|
|
99
|
+
* takes the same `ValidateOptions` validation used (`rule`, `features`, …)
|
|
100
|
+
* so those checks agree with it.
|
|
101
|
+
*
|
|
102
|
+
* Only descends through `CborArray`/`CborMap`/`CborTag` — the structural
|
|
103
|
+
* containers a CDDL-validated data model is built from — plus embedded
|
|
104
|
+
* CBOR: an array element or map value whose type is `bstr .cbor T` (or
|
|
105
|
+
* `.cborseq`) — e.g. COSE's `protected: bstr .cbor header_map` — is
|
|
106
|
+
* replaced by a `<<…>>` `CborEmbeddedCBOR` of its decoded content (only
|
|
107
|
+
* when that re-encodes to exactly the same bytes, so `toCBOR()`/`toJS()`
|
|
108
|
+
* are unchanged), and it, or a `<<…>>` already in CDN source, is annotated
|
|
109
|
+
* against `T` in turn (see `expandEmbedded()`/`walkEmbedded()`). Other node
|
|
110
|
+
* types (e.g. an indefinite-length string chunk) are left untouched, and
|
|
111
|
+
* their contents are not searched for map keys of their own. A map key is itself
|
|
112
|
+
* walked too (after any replacement of its own) — CBOR permits a map or
|
|
113
|
+
* array as a key, and an integer key nested inside *that* still needs
|
|
114
|
+
* annotating, e.g. `{{-1: "a"}: "b"}` — but never with a *positional*
|
|
115
|
+
* scope, the same way `fromJS()`'s own reverse direction never resolves
|
|
116
|
+
* `eRefKeys` names for a map key either (only this module's Scope note
|
|
117
|
+
* applies: a key reached this way simply gets no eRefKeys-eligible names of
|
|
118
|
+
* its own).
|
|
119
|
+
*
|
|
120
|
+
* `decodeOptions` are the caller's own decode-time extension settings
|
|
121
|
+
* (`extensions`/`builtinExtensions`, as given to `fromCBOR()`/`fromCDN()`/
|
|
122
|
+
* …), forwarded to the decode of embedded content — like tag 24's own
|
|
123
|
+
* (`extensions/cbordata.ts`) — so e.g. a bundled extension disabled via
|
|
124
|
+
* `builtinExtensions: false` stays disabled inside `<<…>>` too. Any other
|
|
125
|
+
* field is ignored; the inner decode is always strict, and content that
|
|
126
|
+
* doesn't decode that way is simply left as its bytes.
|
|
127
|
+
*
|
|
128
|
+
* Mutates `item` (and its descendants) in place; call only on a tree the
|
|
129
|
+
* caller exclusively owns and has not yet handed to anyone else — this is
|
|
130
|
+
* exactly the state a freshly decoded/parsed/constructed item is in right
|
|
131
|
+
* after CDDL validation succeeds, which is the only place this is called
|
|
132
|
+
* from (see `cbor.ts`'s `assertCddl()`).
|
|
133
|
+
*/
|
|
134
|
+
export declare function annotateERefKeys(item: CborItem, schema: CddlSchema, ruleOrOptions?: string | ValidateOptions, decodeOptions?: Pick<FromCBOROptions, 'extensions' | 'builtinExtensions'>): void;
|
|
135
|
+
export {};
|
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./serialize-utils-
|
|
2
|
-
`)}static toHex(e,
|
|
3
|
-
`)}static fromHex(e,
|
|
4
|
-
`,t);return n<0?e.length:n}function
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./serialize-utils-DQ8T3Mzw.cjs"),t=require("./mapEntries-DwHPAzCN.cjs"),n=require("./schema-YiigSWjR.cjs");function r(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}var i={appStringPrefixes:[`same`],preserveAppSeqSource:!0,parseAppSequence(e,t,n){if(t.length===0)throw SyntaxError(`same<<...>> requires at least one item`);let i=t[0],a=i.toCBOR();for(let e=1;e<t.length;e++)if(!r(a,t[e].toCBOR())){let t=`same<<...>>: item ${e} produces different CBOR bytes than item 0`;if(n)n(t);else throw SyntaxError(t)}return i}},a=8;function o(e,n,r,i){if(t.l(e,n,r).valid)return n;let a=[];if(!t.l(e,n,r,{infer:!0,trail:a}).valid)return n;let o=u(a);return!o||o.size===0?n:h(n,o,i)}function s(e,t,n,r){p(t);let i=new Set;for(let e of r)!e.inferred&&d(e.item)&&i.add(e.item);for(let r=0;i.size>0&&r<a;r++){let r=c(e,t,n,i);if(!r)return;if(r.size===i.size){for(let e of i)e._implicit=!0;return}i=r}}function c(e,n,r,i){if(t.l(e,n,r,{stripped:i,trail:[]}).valid)return new Set;let a=[];if(!t.l(e,n,r,{infer:!0,stripped:i,trail:a}).valid)return new Set;let o=new Map;for(let e of i){let t=l(e,i),n=f(t[t.length-1].content);(o.get(n)?.length??0)<t.length&&o.set(n,t)}let s=u(a);if(!s)return;let c=new Set;for(let[e,t]of s){let n=o.get(e);if(!n)return;if(n.length===t.length&&n.every((e,n)=>e.tag===t[n]))for(let e of n)c.add(e)}return c}function l(e,n){let r=[],i=e;for(;i instanceof t.B&&n.has(i);)r.push(i),i=f(i.content);return r}function u(e){let t=new Map;for(let n of e){if(!n.inferred)continue;let e=t.get(n.item);e||t.set(n.item,e=[]);let r=e[n.layer];if(r===void 0)e[n.layer]=n.tag;else if(r!==n.tag)return}for(let e of t.values())for(let t=0;t<e.length;t++)if(e[t]===void 0)return;return t}function d(e){return e instanceof t.B&&e._toJS===t.B.prototype._toJS}function f(e){for(;e instanceof t.A;)e=e.inner;return e}function p(e){m(e,p),e instanceof t.B&&(e._implicit=!1)}function m(e,n){if(e instanceof t.I)e.items.forEach(n);else if(e instanceof t.F)for(let[t,r]of e.entries)n(t),n(r);else e instanceof t.B?n(e.content):e instanceof t.A&&n(e.inner)}function h(e,n,r){let i=e=>{if(e instanceof t.I){let{items:t}=e;for(let e=0;e<t.length;e++)t[e]=i(t[e])}else if(e instanceof t.F)for(let t of e.entries)t[0]=i(t[0]),t[1]=i(t[1]);else e instanceof t.B&&(e.content=i(e.content));let a=e,o=n.get(e)??[];for(let e=o.length-1;e>=0;e--)a=r(o[e],a);return a};return i(e)}var g=new Map,_=64;function v(e){if(typeof e!=`string`)return e;let t=g.get(e);return t||(t=n.n(e),g.size>=_&&g.delete(g.keys().next().value),g.set(e,t)),t}function y(e,n,r,i,a){if(n){a&&a.implicitTags!==!1&&(e=o(n,e,r,(e,n)=>t.i(e,n,a)));let c=[],l=t.l(n,e,r,{trail:c});if(!l.valid)throw new t.Z(l.errors,l.warnings);s(n,e,r,c),t.s(e,n,r,i)}return e}function b(e,n){return n?{...e,extensions:[t.c(n),...e?.extensions??[]]}:e}function x(e,t){return y(e,v(t?.cddl),t?.cddlValidationOptions,t)}var S=class n{static OMIT=t.K;static TAG=t.q;static Tag=t.Y;static Simple=t.G;static MapEntries=t.t;static dt_as_Date=t.T;#e;constructor(e){this.#e=e??{}}#t(e){return{...this.#e,...e??{}}}fromCBOR(e,t){let r=n.fromCBOR(e,this.#t(t));return r._defaults=this.#e,r}fromCDN(e,t){let r=n.fromCDN(e,this.#t(t));return r._defaults=this.#e,r}fromEDN(e,t){return this.fromCDN(e,t)}fromJS(e,t){let r=n.fromJS(e,this.#t(t));return r._defaults=this.#e,r}fromHexDump(e,t){let r=n.fromHexDump(e,this.#t(t));return r._defaults=this.#e,r}*fromCBORSeq(e,t){for(let r of n.fromCBORSeq(e,this.#t(t)))r._defaults=this.#e,yield r}*fromCDNSeq(e,t){for(let r of n.fromCDNSeq(e,this.#t(t)))r._defaults=this.#e,yield r}*fromHexDumpSeq(e,t){for(let r of n.fromHexDumpSeq(e,this.#t(t)))r._defaults=this.#e,yield r}decode(e,t){return n.decode(e,this.#t(t))}*decodeSeq(e,t){yield*n.decodeSeq(e,this.#t(t))}*parseSeq(e,t){yield*n.parseSeq(e,this.#t(t))}encode(e,t){return n.encode(e,this.#t(t))}compile(e,t){return n.compile(e,this.#t(t))}decompile(e,t){return n.decompile(e,this.#t(t))}toHex(e,t){return n.toHex(e,this.#t(t))}fromHex(e,t){return n.fromHex(e,this.#t(t))}validate(e,t){return n.validate(e,this.#t(t))}cborToCborEdn(e,t){return this.cborToCdn(e,t)}cborToCdn(e,t){let r=this.#t(t),i=n.fromCBOR(e,r);return i._defaults=this.#e,i.toCDN(r)}cborEdnToCbor(e,t){return this.cdnToCbor(e,t)}cdnToCbor(e,t){let r=this.#t(t);return n.fromCDN(e,r).toCBOR(r)}parse(e,t){if(typeof t==`function`){let r=this.#t({reviver:t});return n.fromCDN(e,r).toJS(r)}let r=this.#t(t);return n.fromCDN(e,r).toJS(r)}stringify(e,t,r){if(typeof t==`function`||Array.isArray(t)||t===null||t===void 0&&r!==void 0){let i={...this.#e};return t===null?i.replacer=void 0:(typeof t==`function`||Array.isArray(t))&&(i.replacer=t),r!==void 0&&(i.indent=k(r)),n.stringify(e,i)}return n.stringify(e,this.#t(t??void 0))}format(e,t){return n.format(e,this.#t(t))}static fromCBOR(e,n){return x(t.x(e,n),n)}static fromCDN(e,n){let r=v(n?.cddl);return y(t.D(e,b(n,r)),r,n?.cddlValidationOptions,n)}static fromEDN(e,t){return n.fromCDN(e,t)}static*fromHexDumpSeq(e,t){let r=[],i=C(e).trim().split(/\s+/).filter(Boolean);for(let e of i)if(/^[0-9A-Fa-f]{2}$/.test(e))r.push(parseInt(e,16));else if(/^[0-9A-Fa-f]+$/.test(e)&&e.length%2==0)for(let t=0;t<e.length;t+=2)r.push(parseInt(e.slice(t,t+2),16));else throw SyntaxError(`Invalid hex token in dump: ${JSON.stringify(e)}`);yield*n.fromCBORSeq(new Uint8Array(r),t)}static*fromCBORSeq(e,n){let r=v(n?.cddl),i=e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength),a=0;for(;a<i.byteLength;){let e=t.x(i,{...n,offset:a,allowTrailing:!0});yield y(e,r,n?.cddlValidationOptions,n),a=e.end}}static*fromCDNSeq(n,r){let i=v(r?.cddl),a=e.D(r)||!!r?.preserveAll,o=0,s=!0;for(;;){let{offset:c,hadSeparator:l,commaOffset:u}=O(n,o,r,a?s?`all`:`after-newline`:`none`);if(s&&u>=0){let e=`leading comma in CDN sequence`;if(r?.strict!==!1)throw SyntaxError(e);E(e,u,r)}if(c>=n.length||a&&D(n,c)&&O(n,c,r).offset>=n.length)break;if(!s&&!l){let e=`CDN sequence items must be separated by whitespace, comma, or comment`;if(r?.strict!==!1)throw SyntaxError(e);E(e,c,r)}o=c;let d;try{d=t.D(n,b({...r,offset:o,allowTrailing:!0,_skipRS:!0},i))}catch(t){if(r?.strict!==!1)throw t;E(t instanceof Error?t.message:String(t),o,r,!0,t instanceof e.I?t:void 0);break}yield y(d,i,r?.cddlValidationOptions,r),o=d.end,s=!1}}static fromJS(e,n){let r=v(n?.cddl);return y(t.r(e,n,r),r,n?.cddlValidationOptions,n,n??{})}static fromHexDump(e,n){let r=[],i=C(e).trim().split(/\s+/).filter(Boolean);for(let e of i)if(/^[0-9A-Fa-f]{2}$/.test(e))r.push(parseInt(e,16));else if(/^[0-9A-Fa-f]+$/.test(e)&&e.length%2==0)for(let t=0;t<e.length;t+=2)r.push(parseInt(e.slice(t,t+2),16));else throw SyntaxError(`Invalid hex token in dump: ${JSON.stringify(e)}`);return x(t.x(new Uint8Array(r),n),n)}static decode(e,t){return n.fromCBOR(e,t).toJS(t)}static*decodeSeq(e,t){for(let r of n.fromCBORSeq(e,t))yield r.toJS(t)}static*parseSeq(e,t){for(let r of n.fromCDNSeq(e,t))yield r.toJS(t)}static encode(e,t){return n.fromJS(e,t).toCBOR(t)}static compile(e,t){let r=[...n.fromCDNSeq(e,t)].map(e=>e.toCBOR(t)),i=r.reduce((e,t)=>e+t.length,0),a=new Uint8Array(i),o=0;for(let e of r)a.set(e,o),o+=e.length;return a}static decompile(e,t){return[...n.fromCBORSeq(e,t)].map(e=>e.toCDN(t)).join(`
|
|
2
|
+
`)}static toHex(e,t){return[...n.fromCBORSeq(e,t)].map(e=>e.toHexDump(t)).join(`
|
|
3
|
+
`)}static fromHex(e,t){let r=[...n.fromHexDumpSeq(e,t)].map(e=>e.toCBOR(t)),i=r.reduce((e,t)=>e+t.length,0),a=new Uint8Array(i),o=0;for(let e of r)a.set(e,o),o+=e.length;return a}static validate(r,i){let a=[],o=[],s,c=v(i?.cddl),l={strict:!1,extensions:c?[t.c(c),...i?.extensions??[]]:i?.extensions,builtinExtensions:i?.builtinExtensions,onWarning:e=>{if(`hint`in e&&e.hint){o.push(e);return}if(`fatal`in e&&e.fatal){s=e;return}a.push(e)}},u=[],d=[],f=e=>{if(!c)return;let t=c.validate(e,i?.cddlValidationOptions);u.push(...t.errors),t.warnings&&d.push(...t.warnings)},p=c?{cddlErrors:u,cddlWarnings:d}:{},m=0;try{let e=i?.type??`cbor`;if(e===`cdn`){let e={...l,unresolvedExtension:i?.unresolvedExtension};for(let t of n.fromCDNSeq(r,e))m++,f(t)}else if(e===`hex`)for(let e of n.fromHexDumpSeq(r,l))m++,f(e);else for(let e of n.fromCBORSeq(r,l))m++,f(e)}catch(e){return{valid:!1,count:m,warnings:a,hints:o,error:e instanceof Error?e:Error(String(e)),...p}}if(s){let t=s.cause instanceof Error?s.cause:new e.I(s.message,{offset:s.offset});return{valid:!1,count:m,warnings:a,hints:o,error:t,...p}}return{valid:a.length===0&&u.length===0,count:m,warnings:a,hints:o,...p}}static cborToCdn(e,t){return n.fromCBOR(e,t).toCDN(t)}static cborToCborEdn(e,t){return n.fromCBOR(e,t).toCDN(t)}static cdnToCbor(e,t){return n.fromCDN(e,t).toCBOR(t)}static cborEdnToCbor(e,t){return n.fromCDN(e,t).toCBOR(t)}static parse(e,t){return typeof t==`function`?n.fromCDN(e).toJS({reviver:t}):n.fromCDN(e,t).toJS(t)}static stringify(e,n,r){if(typeof n==`function`||Array.isArray(n)||n===null||n===void 0&&r!==void 0){let i=typeof n==`function`||Array.isArray(n)?n:void 0,a=k(r);if(i){let n=t.n(e,i);return n===void 0||n===t.K?void 0:t.r(n).toCDN(a===void 0?void 0:{indent:a})}return t.r(e).toCDN(a===void 0?void 0:{indent:a})}let i=n,a=v(i?.cddl);if(i?.replacer){let n=t.n(e,i.replacer,i.extensions,i.undefinedOmits,i.builtinExtensions);if(n===void 0||n===t.K)return;let{replacer:r,...o}=i;return y(t.r(n,Object.keys(o).length>0?o:void 0,a),a,i.cddlValidationOptions,i,o).toCDN(i)}return y(t.r(e,i,a),a,i?.cddlValidationOptions,i,i??{}).toCDN(i)}static format(e,t){return n.fromCDN(e,t).toCDN(t)}};function C(e){let t=``,n=0;for(;n<e.length;){let r=e[n],i=e[n+1]??``;if(r===`-`&&i===`-`){n=w(e,n+2),t+=` `;continue}if(r===`—`){n=w(e,n+1),t+=` `;continue}if(r===`#`){n=w(e,n+1),t+=` `;continue}if(r===`/`&&i===`/`){n=w(e,n+2),t+=` `;continue}if(r===`/`&&i===`*`){let r=e.indexOf(`*/`,n+2);if(r<0)throw SyntaxError(`Unterminated comment in hex dump`);t+=T(e.slice(n,r+2)),n=r+2;continue}if(r===`/`){let r=e.indexOf(`/`,n+1);if(r<0)throw SyntaxError(`Unterminated comment in hex dump`);t+=T(e.slice(n,r+1)),n=r+1;continue}t+=r,n++}return t}function w(e,t){let n=e.indexOf(`
|
|
4
|
+
`,t);return n<0?e.length:n}function T(e){return e.replace(/[^\r\n]/g,` `)}function E(e,t,n,r,i){let a=i?.offset??t,o={message:e,offset:a};r&&(o.fatal=!0),i&&(o.cause=i),i?.offset!==void 0&&(o.line=i.line,o.column=i.column,o.endOffset=i.endOffset),n?.onWarning?n.onWarning(o):n?.silent||console.warn(`CDN sequence warning at offset ${a}: ${e}`)}function D(e,t){let n=e[t];return n===`#`||n===`/`}function O(e,t,n,r=`none`){let i=t,a=!1,o=!1,s=!1,c=-1,l=()=>r===`all`||r===`after-newline`&&s;for(;i<e.length;){let t=e[i];if(t===` `||t===` `||t===`\r`||t===``){a=!0,i++;continue}if(t===`
|
|
5
5
|
`){a=!0,s=!0,i++;continue}if(t===`#`){if(a=!0,l())break;let t=e.indexOf(`
|
|
6
6
|
`,i+1);i=t<0?e.length:t+1,s=!0;continue}if(t===`/`&&e[i+1]===`/`){if(a=!0,l())break;let t=e.indexOf(`
|
|
7
|
-
`,i+2);i=t<0?e.length:t+1,s=!0;continue}if(t===`/`&&e[i+1]===`*`){if(a=!0,l())break;let t=e.indexOf(`*/`,i+2);if(t<0){let t=`unterminated /* comment in CDN sequence`;if(n?.strict!==!1)throw SyntaxError(t);
|
|
8
|
-
`)&&(s=!0),i=t+2;continue}if(t===`/`&&e[i+1]!==`/`){if(a=!0,l())break;let t=e.indexOf(`/`,i+1);if(t<0){let t=`unterminated / comment in CDN sequence`;if(n?.strict!==!1)throw SyntaxError(t);
|
|
9
|
-
`)&&(s=!0),i=t+1;continue}if(t===`,`&&!o){a=!0,o=!0,c=i,i++;continue}break}return{offset:i,hadSeparator:a,commaOffset:c}}function
|
|
7
|
+
`,i+2);i=t<0?e.length:t+1,s=!0;continue}if(t===`/`&&e[i+1]===`*`){if(a=!0,l())break;let t=e.indexOf(`*/`,i+2);if(t<0){let t=`unterminated /* comment in CDN sequence`;if(n?.strict!==!1)throw SyntaxError(t);E(t,i,n,!0),i=e.length}else e.slice(i,t).includes(`
|
|
8
|
+
`)&&(s=!0),i=t+2;continue}if(t===`/`&&e[i+1]!==`/`){if(a=!0,l())break;let t=e.indexOf(`/`,i+1);if(t<0){let t=`unterminated / comment in CDN sequence`;if(n?.strict!==!1)throw SyntaxError(t);E(t,i,n,!0),i=e.length}else e.slice(i,t).includes(`
|
|
9
|
+
`)&&(s=!0),i=t+1;continue}if(t===`,`&&!o){a=!0,o=!0,c=i,i++;continue}break}return{offset:i,hadSeparator:a,commaOffset:c}}function k(e){if(typeof e==`number`){let t=Math.floor(Math.min(10,Math.max(0,e)));return t===0?void 0:t}if(typeof e==`string`)return e.slice(0,10)||void 0}exports.BUILTIN_EXTENSIONS=t.h,exports.CBOR=S,exports.default=S,exports.CBOR_OMIT=t.K,exports.CBOR_TAG=t.q,exports.CborERefNint=t.a,exports.CborERefUint=t.o,exports.CddlMismatchError=t.Z,exports.CdnSyntaxError=e.I,exports.MapEntries=t.t,exports.Null=t.J,exports.Simple=t.G,exports.Tag=t.Y,exports.Undefined=t.X,exports.annotateERefKeys=t.s,exports.b1=t.y,exports.b32=t.j,exports.createERefExtension=t.c,exports.cri=t.S,exports.dt=t.w,exports.dt_as_Date=t.T,exports.float=t.g,exports.h32=t.M,exports.ilbs=t._,exports.ilts=t.v,exports.ip=t.C,exports.same=i,exports.t1=t.b;
|
|
10
10
|
//# sourceMappingURL=index.cjs.map
|