@hyperscale0/udl 4.9.0 → 5.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 (44) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +4 -13
  3. package/dist/diagnostics.d.ts +1 -15
  4. package/dist/diagnostics.d.ts.map +1 -1
  5. package/dist/diagnostics.js +3 -12
  6. package/dist/diagnostics.js.map +1 -1
  7. package/dist/index.d.ts +1 -4
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +1 -4
  10. package/dist/index.js.map +1 -1
  11. package/dist/object-contract.d.ts +0 -52
  12. package/dist/object-contract.d.ts.map +1 -1
  13. package/dist/object-contract.js +0 -19
  14. package/dist/object-contract.js.map +1 -1
  15. package/dist/validation.d.ts.map +1 -1
  16. package/dist/validation.js +29 -0
  17. package/dist/validation.js.map +1 -1
  18. package/package.json +4 -8
  19. package/spec/README.md +6 -0
  20. package/src/diagnostics.ts +10 -18
  21. package/src/index.ts +1 -13
  22. package/src/object-contract.ts +0 -47
  23. package/src/validation.ts +57 -0
  24. package/dist/cli.d.ts +0 -3
  25. package/dist/cli.d.ts.map +0 -1
  26. package/dist/cli.js +0 -184
  27. package/dist/cli.js.map +0 -1
  28. package/dist/evolution.d.ts +0 -5
  29. package/dist/evolution.d.ts.map +0 -1
  30. package/dist/evolution.js +0 -27
  31. package/dist/evolution.js.map +0 -1
  32. package/dist/instrument-references.d.ts +0 -5
  33. package/dist/instrument-references.d.ts.map +0 -1
  34. package/dist/instrument-references.js +0 -90
  35. package/dist/instrument-references.js.map +0 -1
  36. package/dist/parser.d.ts +0 -4
  37. package/dist/parser.d.ts.map +0 -1
  38. package/dist/parser.js +0 -67
  39. package/dist/parser.js.map +0 -1
  40. package/docs/README.md +0 -294
  41. package/src/cli.ts +0 -196
  42. package/src/evolution.ts +0 -46
  43. package/src/instrument-references.ts +0 -123
  44. package/src/parser.ts +0 -80
package/src/parser.ts DELETED
@@ -1,80 +0,0 @@
1
- import { serializeUdl } from "./canonical.js";
2
- import { issue } from "./diagnostics.js";
3
- import { UDL_LIMITS } from "./limits.js";
4
- import type { UdlDocument } from "./schema.js";
5
- import { assertValidUdl, UdlError } from "./validation.js";
6
-
7
- const utf8Decoder = new TextDecoder("utf-8", { fatal: true });
8
-
9
- export function parseUdl(source: string | Uint8Array): UdlDocument {
10
- const sourceBytes =
11
- typeof source === "string"
12
- ? source.length > UDL_LIMITS.maxSourceBytes
13
- ? source.length
14
- : new TextEncoder().encode(source).byteLength
15
- : source.byteLength;
16
- if (sourceBytes > UDL_LIMITS.maxSourceBytes) {
17
- throw new UdlError([
18
- issue(
19
- "UDL1004",
20
- "$",
21
- `UDL source exceeds ${UDL_LIMITS.maxSourceBytes} bytes`,
22
- ),
23
- ]);
24
- }
25
- return parseUdlText(
26
- typeof source === "string" ? source : decodeUdlBytes(source),
27
- );
28
- }
29
-
30
- function parseUdlText(source: string): UdlDocument {
31
- let value: unknown;
32
- try {
33
- value = JSON.parse(source) as unknown;
34
- } catch (error) {
35
- throw new UdlError([
36
- issue(
37
- "UDL1002",
38
- "$",
39
- error instanceof Error ? error.message : "could not parse JSON",
40
- ),
41
- ]);
42
- }
43
- // JSON.parse has already checked syntax. Scan member names before its
44
- // last-value-wins behavior can erase an authored declaration.
45
- const members: (Set<string> | null)[] = [];
46
- let name = "";
47
- for (const token of source.matchAll(/"(?:[^"\\]|\\.)*"|[{}[\]:]/g)) {
48
- const text = token[0];
49
- if (text === "{") members.push(new Set());
50
- else if (text === "[") members.push(null);
51
- else if (text === "}" || text === "]") members.pop();
52
- else if (text === ":") {
53
- const keys = members[members.length - 1];
54
- if (keys?.has(name))
55
- throw new UdlError([
56
- issue(
57
- "UDL1002",
58
- "$",
59
- `duplicate JSON member ${name} at offset ${token.index}`,
60
- ),
61
- ]);
62
- keys?.add(name);
63
- } else name = JSON.parse(text) as string;
64
- }
65
- return assertValidUdl(value);
66
- }
67
-
68
- export function canonicalizeUdl(source: string | Uint8Array): string {
69
- return serializeUdl(parseUdl(source));
70
- }
71
-
72
- function decodeUdlBytes(source: Uint8Array): string {
73
- try {
74
- return utf8Decoder.decode(source);
75
- } catch {
76
- throw new UdlError([
77
- issue("UDL1001", "$", "UDL bytes must be valid UTF-8"),
78
- ]);
79
- }
80
- }