@marcuspuchalla/nachos 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/LICENSE +674 -0
  3. package/README.md +345 -0
  4. package/dist/chunk-2FUTHZQQ.cjs +755 -0
  5. package/dist/chunk-2FUTHZQQ.cjs.map +1 -0
  6. package/dist/chunk-2HBCILJS.cjs +2034 -0
  7. package/dist/chunk-2HBCILJS.cjs.map +1 -0
  8. package/dist/chunk-7CFYWHS6.js +742 -0
  9. package/dist/chunk-7CFYWHS6.js.map +1 -0
  10. package/dist/chunk-PD72MVTX.cjs +160 -0
  11. package/dist/chunk-PD72MVTX.cjs.map +1 -0
  12. package/dist/chunk-ZDZ2B5PE.js +149 -0
  13. package/dist/chunk-ZDZ2B5PE.js.map +1 -0
  14. package/dist/chunk-ZRPJUEIZ.js +2020 -0
  15. package/dist/chunk-ZRPJUEIZ.js.map +1 -0
  16. package/dist/encoder/index.cjs +57 -0
  17. package/dist/encoder/index.cjs.map +1 -0
  18. package/dist/encoder/index.d.cts +72 -0
  19. package/dist/encoder/index.d.ts +72 -0
  20. package/dist/encoder/index.js +4 -0
  21. package/dist/encoder/index.js.map +1 -0
  22. package/dist/index.cjs +606 -0
  23. package/dist/index.cjs.map +1 -0
  24. package/dist/index.d.cts +494 -0
  25. package/dist/index.d.ts +494 -0
  26. package/dist/index.js +523 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/metafile-cjs.json +1 -0
  29. package/dist/metafile-esm.json +1 -0
  30. package/dist/parser/index.cjs +85 -0
  31. package/dist/parser/index.cjs.map +1 -0
  32. package/dist/parser/index.d.cts +72 -0
  33. package/dist/parser/index.d.ts +72 -0
  34. package/dist/parser/index.js +4 -0
  35. package/dist/parser/index.js.map +1 -0
  36. package/dist/types-DvNlfbKB.d.cts +301 -0
  37. package/dist/types-DvNlfbKB.d.ts +301 -0
  38. package/dist/useCborSimpleEncoder-ButVU988.d.cts +268 -0
  39. package/dist/useCborSimpleEncoder-TVxzNJ_9.d.ts +268 -0
  40. package/dist/useCborTag-B_iaShG6.d.ts +142 -0
  41. package/dist/useCborTag-BfTIV8HM.d.cts +142 -0
  42. package/package.json +102 -0
  43. package/src/__tests__/public-api.test.ts +326 -0
  44. package/src/encoder/__tests__/cbor-collection-encoder.test.ts +331 -0
  45. package/src/encoder/__tests__/cbor-integer-encoder.test.ts +283 -0
  46. package/src/encoder/__tests__/cbor-simple-encoder.test.ts +224 -0
  47. package/src/encoder/__tests__/cbor-string-encoder.test.ts +345 -0
  48. package/src/encoder/__tests__/cbor-tag-encoder.test.ts +565 -0
  49. package/src/encoder/composables/#useCborTagEncoder.ts# +158 -0
  50. package/src/encoder/composables/useCborCollectionEncoder.ts +424 -0
  51. package/src/encoder/composables/useCborEncoder.ts +203 -0
  52. package/src/encoder/composables/useCborIntegerEncoder.ts +188 -0
  53. package/src/encoder/composables/useCborSimpleEncoder.ts +266 -0
  54. package/src/encoder/composables/useCborStringEncoder.ts +266 -0
  55. package/src/encoder/composables/useCborTagEncoder.ts +158 -0
  56. package/src/encoder/index.ts +35 -0
  57. package/src/encoder/types.ts +88 -0
  58. package/src/encoder/utils.ts +80 -0
  59. package/src/index.ts +434 -0
  60. package/src/parser/__tests__/ast-tree-structure.test.ts +311 -0
  61. package/src/parser/__tests__/cbor-collection-errors.test.ts +296 -0
  62. package/src/parser/__tests__/cbor-collection.test.ts +369 -0
  63. package/src/parser/__tests__/cbor-deterministic-encoding.test.ts +432 -0
  64. package/src/parser/__tests__/cbor-diagnostic.test.ts +333 -0
  65. package/src/parser/__tests__/cbor-duplicate-keys.test.ts +235 -0
  66. package/src/parser/__tests__/cbor-float-errors.test.ts +222 -0
  67. package/src/parser/__tests__/cbor-float.test.ts +502 -0
  68. package/src/parser/__tests__/cbor-integer-errors.test.ts +139 -0
  69. package/src/parser/__tests__/cbor-integer.test.ts +200 -0
  70. package/src/parser/__tests__/cbor-map-duplicate-keys.test.ts +403 -0
  71. package/src/parser/__tests__/cbor-parser-errors.test.ts +126 -0
  72. package/src/parser/__tests__/cbor-security-dos-protection.test.ts +503 -0
  73. package/src/parser/__tests__/cbor-sequences.test.ts +150 -0
  74. package/src/parser/__tests__/cbor-source-map.test.ts +321 -0
  75. package/src/parser/__tests__/cbor-standard-tags.test.ts +340 -0
  76. package/src/parser/__tests__/cbor-string-errors.test.ts +227 -0
  77. package/src/parser/__tests__/cbor-string.test.ts +224 -0
  78. package/src/parser/__tests__/cbor-tag-advanced.test.ts +500 -0
  79. package/src/parser/__tests__/cbor-tag-errors.test.ts +447 -0
  80. package/src/parser/__tests__/cbor-tag-source-map.test.ts +360 -0
  81. package/src/parser/__tests__/cbor-tag.test.ts +684 -0
  82. package/src/parser/__tests__/extreme-edge-cases.test.ts +146 -0
  83. package/src/parser/__tests__/pathBuilder.test.ts +256 -0
  84. package/src/parser/__tests__/rfc-test-vectors.test.ts +607 -0
  85. package/src/parser/__tests__/security-limits.test.ts +248 -0
  86. package/src/parser/__tests__/utils-errors.test.ts +127 -0
  87. package/src/parser/composables/useCborCollection.ts +509 -0
  88. package/src/parser/composables/useCborDiagnostic.ts +381 -0
  89. package/src/parser/composables/useCborFloat.ts +256 -0
  90. package/src/parser/composables/useCborInteger.ts +114 -0
  91. package/src/parser/composables/useCborParser.ts +951 -0
  92. package/src/parser/composables/useCborString.ts +330 -0
  93. package/src/parser/composables/useCborStringTypes.ts +129 -0
  94. package/src/parser/composables/useCborTag.ts +739 -0
  95. package/src/parser/index.ts +56 -0
  96. package/src/parser/types.ts +371 -0
  97. package/src/parser/utils/pathBuilder.ts +259 -0
  98. package/src/parser/utils.ts +398 -0
  99. package/src/utils/__tests__/logger.test.ts +186 -0
  100. package/src/utils/logger.ts +96 -0
@@ -0,0 +1,72 @@
1
+ import { E as EncodableValue, b as EncodeResult, T as TaggedValue } from '../useCborSimpleEncoder-TVxzNJ_9.js';
2
+ export { D as DEFAULT_ENCODE_OPTIONS, g as EncodeContext, a as EncodeOptions, e as useCborCollectionEncoder, u as useCborEncoder, c as useCborIntegerEncoder, f as useCborSimpleEncoder, d as useCborStringEncoder } from '../useCborSimpleEncoder-TVxzNJ_9.js';
3
+ import '../types-DvNlfbKB.js';
4
+
5
+ /**
6
+ * CBOR Tag Encoder Composable
7
+ * Handles Major Type 6 (Semantic Tags)
8
+ * Following RFC 8949 specification
9
+ */
10
+
11
+ /**
12
+ * CBOR Tag Encoder Composable
13
+ *
14
+ * Provides functions to encode tagged values to CBOR format:
15
+ * - Major Type 6: Semantic tags (0 to 2^64-1)
16
+ *
17
+ * Tags provide semantic meaning to CBOR values:
18
+ * - Tag 0: Date/time string (RFC 3339)
19
+ * - Tag 1: Epoch timestamp
20
+ * - Tag 2: Positive bignum
21
+ * - Tag 3: Negative bignum
22
+ * - Tag 258: Cardano set (CIP-0005)
23
+ * - And many more...
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const { encodeTag } = useCborTagEncoder()
28
+ *
29
+ * // Encode date/time string (tag 0)
30
+ * const result1 = encodeTag(0, '2013-03-21T20:04:00Z', encode)
31
+ * // result1.hex: 'c074323031332d30332d32315432303a30343a30305a'
32
+ *
33
+ * // Encode positive bignum (tag 2)
34
+ * const result2 = encodeTag(2, new Uint8Array([0x01, 0xff]), encode)
35
+ * // result2.hex: 'c24201ff'
36
+ *
37
+ * // Encode Cardano set (tag 258)
38
+ * const result3 = encodeTag(258, [1, 2, 3], encode)
39
+ * // result3.hex: 'd9010283010203'
40
+ * ```
41
+ */
42
+ declare function useCborTagEncoder(): {
43
+ encodeTagNumber: (tagNumber: number | bigint) => Uint8Array;
44
+ encodeTag: (tagNumber: number | bigint, value: EncodableValue, encode: (value: EncodableValue) => EncodeResult) => EncodeResult;
45
+ encodeTaggedValue: (taggedValue: TaggedValue, encode: (value: EncodableValue) => EncodeResult) => EncodeResult;
46
+ };
47
+
48
+ /**
49
+ * CBOR Encoder Utility Functions
50
+ */
51
+ /**
52
+ * Convert Uint8Array to hex string
53
+ */
54
+ declare function bytesToHex(bytes: Uint8Array): string;
55
+ /**
56
+ * Concatenate multiple Uint8Arrays
57
+ */
58
+ declare function concatenateUint8Arrays(arrays: Uint8Array[]): Uint8Array;
59
+ /**
60
+ * Compare two Uint8Arrays bytewise (for canonical map sorting)
61
+ */
62
+ declare function compareBytes(a: Uint8Array, b: Uint8Array): number;
63
+ /**
64
+ * Write unsigned integer to bytes (big-endian)
65
+ */
66
+ declare function writeUint(value: number, bytes: number): Uint8Array;
67
+ /**
68
+ * Write BigInt to bytes (big-endian)
69
+ */
70
+ declare function writeBigUint(value: bigint, bytes: number): Uint8Array;
71
+
72
+ export { EncodableValue, EncodeResult, bytesToHex, compareBytes, concatenateUint8Arrays, useCborTagEncoder, writeBigUint, writeUint };
@@ -0,0 +1,4 @@
1
+ export { DEFAULT_ENCODE_OPTIONS, bytesToHex, compareBytes, concatenateUint8Arrays, useCborCollectionEncoder, useCborEncoder, useCborIntegerEncoder, useCborSimpleEncoder, useCborStringEncoder, useCborTagEncoder, writeBigUint, writeUint } from '../chunk-7CFYWHS6.js';
2
+ import '../chunk-ZDZ2B5PE.js';
3
+ //# sourceMappingURL=index.js.map
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
package/dist/index.cjs ADDED
@@ -0,0 +1,606 @@
1
+ 'use strict';
2
+
3
+ var chunk2HBCILJS_cjs = require('./chunk-2HBCILJS.cjs');
4
+ var chunk2FUTHZQQ_cjs = require('./chunk-2FUTHZQQ.cjs');
5
+ var chunkPD72MVTX_cjs = require('./chunk-PD72MVTX.cjs');
6
+
7
+ // src/parser/composables/useCborDiagnostic.ts
8
+ function isTaggedValue(value) {
9
+ return typeof value === "object" && value !== null && "tag" in value && "value" in value && typeof value.tag === "number";
10
+ }
11
+ function isPlainObject(value) {
12
+ return typeof value === "object" && value !== null && !Array.isArray(value) && !(value instanceof Uint8Array) && !(value instanceof Map) && !(value instanceof Set) && !isTaggedValue(value) && value.constructor === Object;
13
+ }
14
+ function escapeString(str) {
15
+ return str.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/\n/g, "\\n").replace(/\r/g, "\\r").replace(/\t/g, "\\t").replace(/[\x00-\x1f\x7f-\x9f]/g, (char) => {
16
+ const code = char.charCodeAt(0);
17
+ return `\\u${code.toString(16).padStart(4, "0")}`;
18
+ });
19
+ }
20
+ function bytesToHex(bytes) {
21
+ return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
22
+ }
23
+ function useCborDiagnostic() {
24
+ const toDiagnostic2 = (value, options = {}) => {
25
+ const {
26
+ pretty = false,
27
+ indent = " ",
28
+ maxDepth = 100,
29
+ indefinite = false
30
+ } = options;
31
+ return formatValue(value, 0, pretty, indent, maxDepth, indefinite);
32
+ };
33
+ const formatValue = (value, depth, pretty, indent, maxDepth, indefinite) => {
34
+ if (depth > maxDepth) {
35
+ return "...";
36
+ }
37
+ if (value === null) {
38
+ return "null";
39
+ }
40
+ if (value === void 0) {
41
+ return "undefined";
42
+ }
43
+ if (typeof value === "boolean") {
44
+ return value ? "true" : "false";
45
+ }
46
+ if (typeof value === "number") {
47
+ if (Number.isNaN(value)) {
48
+ return "NaN";
49
+ }
50
+ if (value === Infinity) {
51
+ return "Infinity";
52
+ }
53
+ if (value === -Infinity) {
54
+ return "-Infinity";
55
+ }
56
+ if (Object.is(value, -0)) {
57
+ return "-0.0";
58
+ }
59
+ if (Number.isInteger(value)) {
60
+ return value.toString();
61
+ }
62
+ return value.toString();
63
+ }
64
+ if (typeof value === "bigint") {
65
+ return value.toString();
66
+ }
67
+ if (typeof value === "string") {
68
+ return `"${escapeString(value)}"`;
69
+ }
70
+ if (value instanceof Uint8Array) {
71
+ return `h'${bytesToHex(value)}'`;
72
+ }
73
+ if (isTaggedValue(value)) {
74
+ const taggedContent = formatValue(
75
+ value.value,
76
+ depth + 1,
77
+ pretty,
78
+ indent,
79
+ maxDepth,
80
+ false
81
+ );
82
+ return `${value.tag}(${taggedContent})`;
83
+ }
84
+ if (Array.isArray(value)) {
85
+ if (value.length === 0) {
86
+ return indefinite ? "[_ ]" : "[]";
87
+ }
88
+ const items = value.map(
89
+ (item) => formatValue(item, depth + 1, pretty, indent, maxDepth, false)
90
+ );
91
+ if (pretty) {
92
+ const prefix = indefinite ? "[_ " : "[";
93
+ const lineIndent = indent.repeat(depth + 1);
94
+ const closeIndent = indent.repeat(depth);
95
+ return `${prefix}
96
+ ${lineIndent}${items.join(`,
97
+ ${lineIndent}`)}
98
+ ${closeIndent}]`;
99
+ } else {
100
+ const prefix = indefinite ? "[_ " : "[";
101
+ return `${prefix}${items.join(", ")}]`;
102
+ }
103
+ }
104
+ if (value instanceof Map) {
105
+ if (value.size === 0) {
106
+ return indefinite ? "{_ }" : "{}";
107
+ }
108
+ const entries = [];
109
+ for (const [k, v] of value) {
110
+ const keyStr = formatValue(k, depth + 1, pretty, indent, maxDepth, false);
111
+ const valueStr = formatValue(v, depth + 1, pretty, indent, maxDepth, false);
112
+ entries.push(`${keyStr}: ${valueStr}`);
113
+ }
114
+ if (pretty) {
115
+ const prefix = indefinite ? "{_ " : "{";
116
+ const lineIndent = indent.repeat(depth + 1);
117
+ const closeIndent = indent.repeat(depth);
118
+ return `${prefix}
119
+ ${lineIndent}${entries.join(`,
120
+ ${lineIndent}`)}
121
+ ${closeIndent}}`;
122
+ } else {
123
+ const prefix = indefinite ? "{_ " : "{";
124
+ return `${prefix}${entries.join(", ")}}`;
125
+ }
126
+ }
127
+ if (value instanceof Set) {
128
+ const items = Array.from(value).map(
129
+ (item) => formatValue(item, depth + 1, pretty, indent, maxDepth, false)
130
+ );
131
+ if (pretty) {
132
+ const lineIndent = indent.repeat(depth + 1);
133
+ const closeIndent = indent.repeat(depth);
134
+ return `[
135
+ ${lineIndent}${items.join(`,
136
+ ${lineIndent}`)}
137
+ ${closeIndent}]`;
138
+ } else {
139
+ return `[${items.join(", ")}]`;
140
+ }
141
+ }
142
+ if (isPlainObject(value)) {
143
+ const keys = Object.keys(value);
144
+ if (keys.length === 0) {
145
+ return indefinite ? "{_ }" : "{}";
146
+ }
147
+ const entries = keys.map((key) => {
148
+ const keyStr = `"${escapeString(key)}"`;
149
+ const valueStr = formatValue(
150
+ value[key],
151
+ depth + 1,
152
+ pretty,
153
+ indent,
154
+ maxDepth,
155
+ false
156
+ );
157
+ return `${keyStr}: ${valueStr}`;
158
+ });
159
+ if (pretty) {
160
+ const prefix = indefinite ? "{_ " : "{";
161
+ const lineIndent = indent.repeat(depth + 1);
162
+ const closeIndent = indent.repeat(depth);
163
+ return `${prefix}
164
+ ${lineIndent}${entries.join(`,
165
+ ${lineIndent}`)}
166
+ ${closeIndent}}`;
167
+ } else {
168
+ const prefix = indefinite ? "{_ " : "{";
169
+ return `${prefix}${entries.join(", ")}}`;
170
+ }
171
+ }
172
+ return String(value);
173
+ };
174
+ const fromDiagnostic = (diag) => {
175
+ const trimmed = diag.trim();
176
+ if (trimmed === "null") return null;
177
+ if (trimmed === "undefined") return void 0;
178
+ if (trimmed === "true") return true;
179
+ if (trimmed === "false") return false;
180
+ if (trimmed === "NaN") return NaN;
181
+ if (trimmed === "Infinity") return Infinity;
182
+ if (trimmed === "-Infinity") return -Infinity;
183
+ if (/^-?\d+(\.\d+)?$/.test(trimmed)) {
184
+ const num = Number(trimmed);
185
+ if (trimmed === "-0.0" || trimmed === "-0") {
186
+ return -0;
187
+ }
188
+ return num;
189
+ }
190
+ const hexMatch = trimmed.match(/^h'([0-9a-fA-F]*)'$/);
191
+ if (hexMatch && hexMatch[1] !== void 0) {
192
+ const hex = hexMatch[1];
193
+ const bytes = new Uint8Array(hex.length / 2);
194
+ for (let i = 0; i < hex.length; i += 2) {
195
+ bytes[i / 2] = parseInt(hex.substring(i, i + 2), 16);
196
+ }
197
+ return bytes;
198
+ }
199
+ if (trimmed.startsWith('"') && trimmed.endsWith('"')) {
200
+ return trimmed.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, "\\");
201
+ }
202
+ return trimmed;
203
+ };
204
+ const toDiagnosticWithType = (value, majorType, options = {}) => {
205
+ const typeNames = {
206
+ 0: "uint",
207
+ 1: "nint",
208
+ 2: "bstr",
209
+ 3: "tstr",
210
+ 4: "array",
211
+ 5: "map",
212
+ 6: "tag",
213
+ 7: "simple"
214
+ };
215
+ const typeName = typeNames[majorType] || "unknown";
216
+ const diag = toDiagnostic2(value, options);
217
+ return `${typeName}(${diag})`;
218
+ };
219
+ return {
220
+ toDiagnostic: toDiagnostic2,
221
+ fromDiagnostic,
222
+ toDiagnosticWithType
223
+ };
224
+ }
225
+
226
+ // src/parser/utils/pathBuilder.ts
227
+ var PathBuilder = {
228
+ /**
229
+ * Create root path (empty string)
230
+ */
231
+ root: () => "",
232
+ /**
233
+ * Create path for array index
234
+ * @param parent - Parent path
235
+ * @param index - Array index (0-based)
236
+ * @returns Path string like "[0]" or "[0][1]"
237
+ */
238
+ arrayIndex: (parent, index) => `${parent}[${index}]`,
239
+ /**
240
+ * Create path for map/object key
241
+ * @param parent - Parent path
242
+ * @param key - Key name (string or number)
243
+ * @returns Path string like ".key" or "[0].key"
244
+ */
245
+ mapKey: (parent, key) => {
246
+ const keyStr = String(key);
247
+ const escapedKey = keyStr.replace(/[.\[\]\\]/g, "\\$&");
248
+ return parent ? `${parent}.${escapedKey}` : `.${escapedKey}`;
249
+ },
250
+ /**
251
+ * Create path for map key by index (for non-string keys)
252
+ * @param parent - Parent path
253
+ * @param index - Key index in map
254
+ * @returns Path string like "[#key:0]"
255
+ */
256
+ mapKeyIndex: (parent, index) => `${parent}[#key:${index}]`,
257
+ /**
258
+ * Create path for header portion of a value
259
+ * Used for byte strings, text strings, arrays, maps, tags
260
+ * @param parent - Parent path
261
+ * @returns Path string like "[0][#header]"
262
+ */
263
+ header: (parent) => `${parent}[#header]`,
264
+ /**
265
+ * Create path for content portion of a value
266
+ * Used for byte strings and text strings
267
+ * @param parent - Parent path
268
+ * @returns Path string like "[0][#content]"
269
+ */
270
+ content: (parent) => `${parent}[#content]`,
271
+ /**
272
+ * Create path for tagged value
273
+ * @param parent - Parent path
274
+ * @returns Path string like "[0][#value]"
275
+ */
276
+ tagValue: (parent) => `${parent}[#value]`,
277
+ /**
278
+ * Normalize a path by removing special markers (#header, #content, #value)
279
+ * Used for matching paths across different representations
280
+ * @param path - Path to normalize
281
+ * @returns Normalized path without special markers
282
+ */
283
+ normalize: (path) => {
284
+ return path.replace(/\[#(header|content|value)\]$/, "");
285
+ },
286
+ /**
287
+ * Check if path is a header path
288
+ * @param path - Path to check
289
+ * @returns True if path ends with [#header]
290
+ */
291
+ isHeader: (path) => path.endsWith("[#header]"),
292
+ /**
293
+ * Check if path is a content path
294
+ * @param path - Path to check
295
+ * @returns True if path ends with [#content]
296
+ */
297
+ isContent: (path) => path.endsWith("[#content]"),
298
+ /**
299
+ * Check if path is a tag value path
300
+ * @param path - Path to check
301
+ * @returns True if path ends with [#value]
302
+ */
303
+ isTagValue: (path) => path.endsWith("[#value]"),
304
+ /**
305
+ * Check if path has any special marker
306
+ * @param path - Path to check
307
+ * @returns True if path ends with any special marker
308
+ */
309
+ hasMarker: (path) => /\[#(header|content|value)\]$/.test(path),
310
+ /**
311
+ * Get parent path (one level up)
312
+ * @param path - Path to get parent of
313
+ * @returns Parent path or null if already at root
314
+ */
315
+ getParent: (path) => {
316
+ const normalized = PathBuilder.normalize(path);
317
+ if (normalized === "") return null;
318
+ const arrayMatch = normalized.match(/^(.+)\[\d+\]$/);
319
+ if (arrayMatch && arrayMatch[1] !== void 0) return arrayMatch[1];
320
+ const keyMatch = normalized.match(/^(.+)\.[^.]+$/);
321
+ if (keyMatch && keyMatch[1] !== void 0) return keyMatch[1];
322
+ if (normalized.startsWith("[") || normalized.startsWith(".")) {
323
+ return "";
324
+ }
325
+ return null;
326
+ },
327
+ /**
328
+ * Get the depth (nesting level) of a path
329
+ * @param path - Path to measure
330
+ * @returns Number indicating nesting depth (0 for root)
331
+ */
332
+ getDepth: (path) => {
333
+ const normalized = PathBuilder.normalize(path);
334
+ if (normalized === "") return 0;
335
+ const arrayDepth = (normalized.match(/\[\d+\]/g) || []).length;
336
+ const keyDepth = (normalized.match(/\./g) || []).length;
337
+ return arrayDepth + keyDepth;
338
+ },
339
+ /**
340
+ * Parse a path into its components
341
+ * @param path - Path to parse
342
+ * @returns Array of path segments
343
+ */
344
+ parse: (path) => {
345
+ const normalized = PathBuilder.normalize(path);
346
+ const segments = [];
347
+ const markerMatch = path.match(/\[#(header|content|value)\]$/);
348
+ let remaining = normalized;
349
+ while (remaining) {
350
+ const indexMatch = remaining.match(/^\[(\d+)\]/);
351
+ if (indexMatch && indexMatch[1] !== void 0) {
352
+ segments.push({ type: "index", value: parseInt(indexMatch[1], 10) });
353
+ remaining = remaining.slice(indexMatch[0].length);
354
+ continue;
355
+ }
356
+ const keyMatch = remaining.match(/^\.([^.\[\]]+)/);
357
+ if (keyMatch && keyMatch[1] !== void 0) {
358
+ const key = keyMatch[1].replace(/\\(.)/g, "$1");
359
+ segments.push({ type: "key", value: key });
360
+ remaining = remaining.slice(keyMatch[0].length);
361
+ continue;
362
+ }
363
+ break;
364
+ }
365
+ if (markerMatch && markerMatch[1] !== void 0) {
366
+ segments.push({ type: "marker", value: markerMatch[1] });
367
+ }
368
+ return segments;
369
+ },
370
+ /**
371
+ * Build a path from segments
372
+ * @param segments - Array of path segments
373
+ * @returns Path string
374
+ */
375
+ build: (segments) => {
376
+ let path = "";
377
+ for (const segment of segments) {
378
+ if (segment.type === "index") {
379
+ path += `[${segment.value}]`;
380
+ } else if (segment.type === "key") {
381
+ const escapedKey = String(segment.value).replace(/[.\[\]\\]/g, "\\$&");
382
+ path += `.${escapedKey}`;
383
+ } else if (segment.type === "marker") {
384
+ path += `[#${segment.value}]`;
385
+ }
386
+ }
387
+ return path;
388
+ },
389
+ /**
390
+ * Join multiple path segments
391
+ * @param paths - Path segments to join
392
+ * @returns Combined path
393
+ */
394
+ join: (...paths) => {
395
+ return paths.filter((p) => p !== "").join("");
396
+ },
397
+ /**
398
+ * Check if a path is a descendant of another path
399
+ * @param path - Path to check
400
+ * @param ancestor - Potential ancestor path
401
+ * @returns True if path is a descendant of ancestor
402
+ */
403
+ isDescendantOf: (path, ancestor) => {
404
+ const normalizedPath = PathBuilder.normalize(path);
405
+ const normalizedAncestor = PathBuilder.normalize(ancestor);
406
+ if (normalizedAncestor === "") {
407
+ return normalizedPath !== "";
408
+ }
409
+ return normalizedPath.startsWith(normalizedAncestor) && normalizedPath.length > normalizedAncestor.length && (normalizedPath[normalizedAncestor.length] === "[" || normalizedPath[normalizedAncestor.length] === ".");
410
+ }
411
+ };
412
+
413
+ // src/index.ts
414
+ function decode(hexString, options) {
415
+ const { parse } = chunk2HBCILJS_cjs.useCborParser();
416
+ return parse(hexString, options);
417
+ }
418
+ function decodeWithSourceMap(hexString, options) {
419
+ const { parseWithSourceMap } = chunk2HBCILJS_cjs.useCborParser();
420
+ return parseWithSourceMap(hexString, options);
421
+ }
422
+ function encode(value, options) {
423
+ const { encode: encodeValue } = chunk2FUTHZQQ_cjs.useCborEncoder(options);
424
+ return encodeValue(value);
425
+ }
426
+ function encodeToHex(value, options) {
427
+ const { encodeToHex: encodeValueToHex } = chunk2FUTHZQQ_cjs.useCborEncoder(options);
428
+ return encodeValueToHex(value);
429
+ }
430
+ function encodeToBytes(value, options) {
431
+ const { encodeToBytes: encodeValueToBytes } = chunk2FUTHZQQ_cjs.useCborEncoder(options);
432
+ return encodeValueToBytes(value);
433
+ }
434
+ function encodeSequence(values, options) {
435
+ const { encodeSequence: encodeSeq } = chunk2FUTHZQQ_cjs.useCborEncoder(options);
436
+ return encodeSeq(values);
437
+ }
438
+ var CborDecoder = class {
439
+ /**
440
+ * Create a new CBOR decoder
441
+ *
442
+ * @param options - Parser configuration
443
+ */
444
+ constructor(options) {
445
+ this.options = options || {};
446
+ }
447
+ /**
448
+ * Decode CBOR hex string
449
+ *
450
+ * @param hexString - CBOR data as hex string
451
+ * @returns Decoded value and byte count
452
+ */
453
+ decode(hexString) {
454
+ return decode(hexString, this.options);
455
+ }
456
+ /**
457
+ * Decode CBOR hex string with source map
458
+ *
459
+ * @param hexString - CBOR data as hex string
460
+ * @returns Decoded value, byte count, and source map
461
+ */
462
+ decodeWithSourceMap(hexString) {
463
+ return decodeWithSourceMap(hexString, this.options);
464
+ }
465
+ };
466
+ var CborEncoder = class {
467
+ /**
468
+ * Create a new CBOR encoder
469
+ *
470
+ * @param options - Encoder configuration
471
+ */
472
+ constructor(options) {
473
+ this.options = options || {};
474
+ }
475
+ /**
476
+ * Encode value to CBOR
477
+ *
478
+ * @param value - JavaScript value to encode
479
+ * @returns CBOR bytes and hex string
480
+ */
481
+ encode(value) {
482
+ return encode(value, this.options);
483
+ }
484
+ /**
485
+ * Encode value to CBOR hex string
486
+ *
487
+ * @param value - JavaScript value to encode
488
+ * @returns CBOR hex string
489
+ */
490
+ encodeToHex(value) {
491
+ return encodeToHex(value, this.options);
492
+ }
493
+ /**
494
+ * Encode value to CBOR bytes
495
+ *
496
+ * @param value - JavaScript value to encode
497
+ * @returns CBOR bytes
498
+ */
499
+ encodeToBytes(value) {
500
+ return encodeToBytes(value, this.options);
501
+ }
502
+ /**
503
+ * Encode multiple values as CBOR sequence
504
+ *
505
+ * @param values - Array of values to encode
506
+ * @returns Concatenated CBOR encoding
507
+ */
508
+ encodeSequence(values) {
509
+ return encodeSequence(values, this.options);
510
+ }
511
+ };
512
+ function toDiagnostic(value, options) {
513
+ const { toDiagnostic: convert } = useCborDiagnostic();
514
+ return convert(value, options);
515
+ }
516
+ function decodeToDiagnostic(hexString, options) {
517
+ const { value } = decode(hexString);
518
+ return toDiagnostic(value, options);
519
+ }
520
+
521
+ Object.defineProperty(exports, "useCborCollection", {
522
+ enumerable: true,
523
+ get: function () { return chunk2HBCILJS_cjs.useCborCollection; }
524
+ });
525
+ Object.defineProperty(exports, "useCborFloat", {
526
+ enumerable: true,
527
+ get: function () { return chunk2HBCILJS_cjs.useCborFloat; }
528
+ });
529
+ Object.defineProperty(exports, "useCborInteger", {
530
+ enumerable: true,
531
+ get: function () { return chunk2HBCILJS_cjs.useCborInteger; }
532
+ });
533
+ Object.defineProperty(exports, "useCborParser", {
534
+ enumerable: true,
535
+ get: function () { return chunk2HBCILJS_cjs.useCborParser; }
536
+ });
537
+ Object.defineProperty(exports, "useCborString", {
538
+ enumerable: true,
539
+ get: function () { return chunk2HBCILJS_cjs.useCborString; }
540
+ });
541
+ Object.defineProperty(exports, "useCborTag", {
542
+ enumerable: true,
543
+ get: function () { return chunk2HBCILJS_cjs.useCborTag; }
544
+ });
545
+ Object.defineProperty(exports, "DEFAULT_ENCODE_OPTIONS", {
546
+ enumerable: true,
547
+ get: function () { return chunk2FUTHZQQ_cjs.DEFAULT_ENCODE_OPTIONS; }
548
+ });
549
+ Object.defineProperty(exports, "useCborCollectionEncoder", {
550
+ enumerable: true,
551
+ get: function () { return chunk2FUTHZQQ_cjs.useCborCollectionEncoder; }
552
+ });
553
+ Object.defineProperty(exports, "useCborEncoder", {
554
+ enumerable: true,
555
+ get: function () { return chunk2FUTHZQQ_cjs.useCborEncoder; }
556
+ });
557
+ Object.defineProperty(exports, "useCborIntegerEncoder", {
558
+ enumerable: true,
559
+ get: function () { return chunk2FUTHZQQ_cjs.useCborIntegerEncoder; }
560
+ });
561
+ Object.defineProperty(exports, "useCborSimpleEncoder", {
562
+ enumerable: true,
563
+ get: function () { return chunk2FUTHZQQ_cjs.useCborSimpleEncoder; }
564
+ });
565
+ Object.defineProperty(exports, "useCborStringEncoder", {
566
+ enumerable: true,
567
+ get: function () { return chunk2FUTHZQQ_cjs.useCborStringEncoder; }
568
+ });
569
+ Object.defineProperty(exports, "CborAdditionalInfo", {
570
+ enumerable: true,
571
+ get: function () { return chunkPD72MVTX_cjs.CborAdditionalInfo; }
572
+ });
573
+ Object.defineProperty(exports, "CborMajorType", {
574
+ enumerable: true,
575
+ get: function () { return chunkPD72MVTX_cjs.CborMajorType; }
576
+ });
577
+ Object.defineProperty(exports, "CborSimpleValue", {
578
+ enumerable: true,
579
+ get: function () { return chunkPD72MVTX_cjs.CborSimpleValue; }
580
+ });
581
+ Object.defineProperty(exports, "CborTag", {
582
+ enumerable: true,
583
+ get: function () { return chunkPD72MVTX_cjs.CborTag; }
584
+ });
585
+ Object.defineProperty(exports, "DEFAULT_LIMITS", {
586
+ enumerable: true,
587
+ get: function () { return chunkPD72MVTX_cjs.DEFAULT_LIMITS; }
588
+ });
589
+ Object.defineProperty(exports, "DEFAULT_OPTIONS", {
590
+ enumerable: true,
591
+ get: function () { return chunkPD72MVTX_cjs.DEFAULT_OPTIONS; }
592
+ });
593
+ exports.CborDecoder = CborDecoder;
594
+ exports.CborEncoder = CborEncoder;
595
+ exports.PathBuilder = PathBuilder;
596
+ exports.decode = decode;
597
+ exports.decodeToDiagnostic = decodeToDiagnostic;
598
+ exports.decodeWithSourceMap = decodeWithSourceMap;
599
+ exports.encode = encode;
600
+ exports.encodeSequence = encodeSequence;
601
+ exports.encodeToBytes = encodeToBytes;
602
+ exports.encodeToHex = encodeToHex;
603
+ exports.toDiagnostic = toDiagnostic;
604
+ exports.useCborDiagnostic = useCborDiagnostic;
605
+ //# sourceMappingURL=index.cjs.map
606
+ //# sourceMappingURL=index.cjs.map