@kanonak-protocol/sdk 3.78.0 → 4.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 (41) hide show
  1. package/dist/browser.js +1 -1
  2. package/dist/canonical/CanonicalHash.d.ts +8 -0
  3. package/dist/canonical/Datatypes.d.ts +98 -0
  4. package/dist/canonical/index.d.ts +2 -1
  5. package/dist/{chunk-RVOMWGIN.js → chunk-4OSNT57C.js} +1 -1
  6. package/dist/{chunk-KXVSGB6Q.js → chunk-6I4BYZVA.js} +1 -1
  7. package/dist/{chunk-Z5ELOT2C.js → chunk-NC3FSY3R.js} +1 -1
  8. package/dist/{chunk-XQS5LDSO.js → chunk-PBNVHBS3.js} +1 -1
  9. package/dist/chunk-T3JR2SV6.js +1 -0
  10. package/dist/{chunk-QXFO6X6V.js → chunk-V3YPCUA6.js} +1 -1
  11. package/dist/chunk-VNKX52D5.js +2 -0
  12. package/dist/chunk-WUAKDYY6.js +1 -0
  13. package/dist/{chunk-IOMNZBK4.js → chunk-XYEY6HUC.js} +1 -1
  14. package/dist/{chunk-LKBG2MK6.js → chunk-YCV4H6H5.js} +1 -1
  15. package/dist/{chunk-PJMOM5H7.js → chunk-YI5GLYMB.js} +1 -1
  16. package/dist/{chunk-ATH6636H.js → chunk-YWUKDEZA.js} +1 -1
  17. package/dist/{chunk-XWRVENU6.js → chunk-ZRMF5QLN.js} +1 -1
  18. package/dist/chunk-ZYAABYDS.js +1 -0
  19. package/dist/index.d.ts +2 -1
  20. package/dist/index.js +26 -26
  21. package/dist/kanonaks/LiteralKanonak.d.ts +4 -0
  22. package/dist/parsing/KanonakObjectParser.d.ts +13 -0
  23. package/dist/parsing/index.js +1 -1
  24. package/dist/reasoning/index.js +1 -1
  25. package/dist/repositories/browser.js +1 -1
  26. package/dist/repositories/index.js +1 -1
  27. package/dist/resolution/index.js +1 -1
  28. package/dist/search/index.js +1 -1
  29. package/dist/server/index.js +1 -1
  30. package/dist/statements/ScalarStatement.d.ts +14 -0
  31. package/dist/transformations/index.js +1 -1
  32. package/dist/uri-helpers/index.js +1 -1
  33. package/dist/validation/index.js +1 -1
  34. package/package.json +7 -3
  35. package/vectors/decode.mjs +115 -0
  36. package/vectors/full-form-vectors.json +254 -0
  37. package/vectors/lexical-vectors.json +81 -0
  38. package/dist/chunk-GIYURKX6.js +0 -2
  39. package/dist/chunk-IUZZDC2U.js +0 -1
  40. package/dist/chunk-TJPQETHV.js +0 -1
  41. package/dist/chunk-W6T7MOKY.js +0 -1
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Decoder for the canonical-form full-form vectors' typed-value INPUT model
3
+ * (issue #55, option 1). The input is language-neutral and carries datatype
4
+ * explicitly, so a port tests canonicalization in isolation (no parser needed):
5
+ *
6
+ * subject := { uri, statements: [ { predicate, value } ] }
7
+ * value := { lit, datatype } typed scalar — raw lexical token + datatype URI
8
+ * | { raw } untyped/open-world scalar (no carrier, raw token)
9
+ * | { ref } reference to an entity (full canonical URI)
10
+ * | { embed: { name?, statements } } embedded node
11
+ * | { list: [ value ] } ordered list
12
+ *
13
+ * It builds the SDK object model the same way the parser's range-directed
14
+ * typing does (carrier from the datatype URI via `carrierOf`), so
15
+ * `canonicalForm`/`canonicalHash` over the result is the authoritative output.
16
+ * This file is also the reference each `kanonak-canonical` port mirrors to map
17
+ * the input model into its own representation.
18
+ */
19
+ import {
20
+ SubjectKanonak,
21
+ ReferenceKanonak,
22
+ EmbeddedKanonak,
23
+ LiteralKanonak,
24
+ StringStatement,
25
+ ReferenceStatement,
26
+ EmbeddedStatement,
27
+ ListStatement,
28
+ carrierOf,
29
+ } from '@kanonak-protocol/sdk';
30
+
31
+ /** "publisher/package@ver/name" or "publisher/package/name" → { publisher, package_, name }. */
32
+ function entityUri(uriStr) {
33
+ const idx = uriStr.lastIndexOf('/');
34
+ const name = uriStr.slice(idx + 1);
35
+ const head = uriStr.slice(0, idx); // publisher/package@ver
36
+ const publisher = head.slice(0, head.indexOf('/'));
37
+ const pkg = head.slice(head.indexOf('/') + 1).split('@')[0];
38
+ return { publisher, package_: pkg, name };
39
+ }
40
+
41
+ /**
42
+ * A scalar statement. canonicalForm reads `(carrier, lexical)` off any
43
+ * ScalarStatement, so a single StringStatement faithfully represents every
44
+ * scalar carrier — the canonical output depends on the carrier+lexical, not the
45
+ * statement class.
46
+ */
47
+ function scalar(predicateUri, carrier, lexical) {
48
+ const s = new StringStatement();
49
+ s.predicate = ReferenceKanonak.parse(predicateUri);
50
+ s.object = lexical;
51
+ if (carrier) {
52
+ s.carrier = carrier;
53
+ s.lexical = lexical;
54
+ }
55
+ return s;
56
+ }
57
+
58
+ function buildEmbedded(e) {
59
+ const emb = new EmbeddedKanonak();
60
+ if (e.name) emb.name = e.name;
61
+ emb.statement = (e.statements ?? []).map((st) => buildStatement(st.predicate, st.value));
62
+ return emb;
63
+ }
64
+
65
+ function buildItem(v) {
66
+ if ('ref' in v) return ReferenceKanonak.parse(v.ref);
67
+ if ('embed' in v) return buildEmbedded(v.embed);
68
+ const lit = new LiteralKanonak();
69
+ if ('lit' in v) {
70
+ lit.value = v.lit;
71
+ lit.carrier = carrierOf(entityUri(v.datatype));
72
+ lit.lexical = v.lit;
73
+ } else if ('raw' in v) {
74
+ lit.value = v.raw;
75
+ } else {
76
+ throw new Error(`decode: unknown list item shape ${JSON.stringify(v)}`);
77
+ }
78
+ return lit;
79
+ }
80
+
81
+ export function buildStatement(predicateUri, v) {
82
+ if ('lit' in v) return scalar(predicateUri, carrierOf(entityUri(v.datatype)), v.lit);
83
+ if ('raw' in v) return scalar(predicateUri, undefined, v.raw);
84
+ if ('ref' in v) {
85
+ const s = new ReferenceStatement();
86
+ s.predicate = ReferenceKanonak.parse(predicateUri);
87
+ s.object = ReferenceKanonak.parse(v.ref);
88
+ return s;
89
+ }
90
+ if ('embed' in v) {
91
+ const s = new EmbeddedStatement();
92
+ s.predicate = ReferenceKanonak.parse(predicateUri);
93
+ s.object = buildEmbedded(v.embed);
94
+ return s;
95
+ }
96
+ if ('list' in v) {
97
+ const s = new ListStatement();
98
+ s.predicate = ReferenceKanonak.parse(predicateUri);
99
+ s.object = v.list.map(buildItem);
100
+ return s;
101
+ }
102
+ throw new Error(`decode: unknown value shape ${JSON.stringify(v)}`);
103
+ }
104
+
105
+ /** Build the SubjectKanonak[] the canonical form consumes from a vector's `input`. */
106
+ export function decodeSubjects(input) {
107
+ return input.subjects.map((s) => {
108
+ const subj = new SubjectKanonak();
109
+ const idx = s.uri.lastIndexOf('/');
110
+ subj.namespace = s.uri.slice(0, idx);
111
+ subj.name = s.uri.slice(idx + 1);
112
+ subj.statement = (s.statements ?? []).map((st) => buildStatement(st.predicate, st.value));
113
+ return subj;
114
+ });
115
+ }
@@ -0,0 +1,254 @@
1
+ {
2
+ "canonicalFormVersion": "1",
3
+ "hashAlgorithm": "sha256",
4
+ "description": "Golden conformance vectors for canonicalForm/canonicalHash over the typed-value input model (issue #55). input -> expectedCanonicalForm (exact UTF-8 JSON bytes) -> expectedHash. The same file drives every kanonak-canonical port. See decode.mjs for the input-model decoder. Expected values are authoritative.",
5
+ "vectors": [
6
+ {
7
+ "id": "typed-scalars-mixed",
8
+ "description": "One subject with integer/decimal/boolean/dateTime/string/anyURI properties — the typed blob in a full form; statements emitted in predicate UTF-8 byte order.",
9
+ "input": {
10
+ "subjects": [
11
+ {
12
+ "uri": "example.org/data@1.0.0/Tick",
13
+ "statements": [
14
+ {
15
+ "predicate": "example.org/data@1.0.0/qty",
16
+ "value": {
17
+ "lit": "0100",
18
+ "datatype": "kanonak.org/core-xsd/integer"
19
+ }
20
+ },
21
+ {
22
+ "predicate": "example.org/data@1.0.0/price",
23
+ "value": {
24
+ "lit": "1.230",
25
+ "datatype": "kanonak.org/core-xsd/decimal"
26
+ }
27
+ },
28
+ {
29
+ "predicate": "example.org/data@1.0.0/active",
30
+ "value": {
31
+ "lit": "1",
32
+ "datatype": "kanonak.org/core-xsd/boolean"
33
+ }
34
+ },
35
+ {
36
+ "predicate": "example.org/data@1.0.0/at",
37
+ "value": {
38
+ "lit": "2026-05-31T13:00:00+01:00",
39
+ "datatype": "kanonak.org/core-xsd/dateTime"
40
+ }
41
+ },
42
+ {
43
+ "predicate": "example.org/data@1.0.0/label",
44
+ "value": {
45
+ "lit": "hello",
46
+ "datatype": "kanonak.org/core-xsd/string"
47
+ }
48
+ }
49
+ ]
50
+ }
51
+ ]
52
+ },
53
+ "expectedCanonicalForm": "{\"subjects\":[{\"uri\":\"example.org/data@1.0.0/Tick\",\"statements\":[{\"predicate\":\"example.org/data@1.0.0/active\",\"type\":\"typed\",\"carrier\":\"boolean\",\"value\":\"true\"},{\"predicate\":\"example.org/data@1.0.0/at\",\"type\":\"typed\",\"carrier\":\"dateTime\",\"value\":\"2026-05-31T12:00:00Z\"},{\"predicate\":\"example.org/data@1.0.0/label\",\"type\":\"typed\",\"carrier\":\"string\",\"value\":\"hello\"},{\"predicate\":\"example.org/data@1.0.0/price\",\"type\":\"typed\",\"carrier\":\"decimal\",\"value\":\"1.23\"},{\"predicate\":\"example.org/data@1.0.0/qty\",\"type\":\"typed\",\"carrier\":\"integer\",\"value\":\"100\"}]}]}",
54
+ "expectedHash": "sha256:e55ab7be11235de58360a8c8b069c8c19f21bb5fcde7c4638abd2f731ea8b704"
55
+ },
56
+ {
57
+ "id": "decimal-five",
58
+ "description": "A decimal-valued 5.0 — distinct identity from the integer 5 below (carrier tag differs).",
59
+ "input": {
60
+ "subjects": [
61
+ {
62
+ "uri": "example.org/data@1.0.0/N",
63
+ "statements": [
64
+ {
65
+ "predicate": "example.org/data@1.0.0/v",
66
+ "value": {
67
+ "lit": "5.0",
68
+ "datatype": "kanonak.org/core-xsd/decimal"
69
+ }
70
+ }
71
+ ]
72
+ }
73
+ ]
74
+ },
75
+ "expectedCanonicalForm": "{\"subjects\":[{\"uri\":\"example.org/data@1.0.0/N\",\"statements\":[{\"predicate\":\"example.org/data@1.0.0/v\",\"type\":\"typed\",\"carrier\":\"decimal\",\"value\":\"5\"}]}]}",
76
+ "expectedHash": "sha256:705b20070647ddf964b713b5e68207c4c1767ba83be597ccfdf8d7e55a183c94"
77
+ },
78
+ {
79
+ "id": "integer-five",
80
+ "description": "An integer-valued 5 — same lexical \"5\" as decimal-five but a different carrier, so a different hash.",
81
+ "input": {
82
+ "subjects": [
83
+ {
84
+ "uri": "example.org/data@1.0.0/N",
85
+ "statements": [
86
+ {
87
+ "predicate": "example.org/data@1.0.0/v",
88
+ "value": {
89
+ "lit": "5",
90
+ "datatype": "kanonak.org/core-xsd/integer"
91
+ }
92
+ }
93
+ ]
94
+ }
95
+ ]
96
+ },
97
+ "expectedCanonicalForm": "{\"subjects\":[{\"uri\":\"example.org/data@1.0.0/N\",\"statements\":[{\"predicate\":\"example.org/data@1.0.0/v\",\"type\":\"typed\",\"carrier\":\"integer\",\"value\":\"5\"}]}]}",
98
+ "expectedHash": "sha256:f32b37ab13e5ccb84afc2a1c6ce3fd2ee13dcf53dda0dc17fa1d4a0bc798c7e3"
99
+ },
100
+ {
101
+ "id": "long-hundred",
102
+ "description": "xsd:long 0100 — collapses to the integer carrier, equal identity to integer-hundred.",
103
+ "input": {
104
+ "subjects": [
105
+ {
106
+ "uri": "example.org/data@1.0.0/N",
107
+ "statements": [
108
+ {
109
+ "predicate": "example.org/data@1.0.0/v",
110
+ "value": {
111
+ "lit": "0100",
112
+ "datatype": "kanonak.org/core-xsd/long"
113
+ }
114
+ }
115
+ ]
116
+ }
117
+ ]
118
+ },
119
+ "expectedCanonicalForm": "{\"subjects\":[{\"uri\":\"example.org/data@1.0.0/N\",\"statements\":[{\"predicate\":\"example.org/data@1.0.0/v\",\"type\":\"typed\",\"carrier\":\"integer\",\"value\":\"100\"}]}]}",
120
+ "expectedHash": "sha256:653ec69910e2f7022208305c0ff44915f6eddf0163771a38f4af26161476caa4"
121
+ },
122
+ {
123
+ "id": "integer-hundred",
124
+ "description": "xsd:integer 100 — same carrier+value as long-hundred, so an identical hash.",
125
+ "input": {
126
+ "subjects": [
127
+ {
128
+ "uri": "example.org/data@1.0.0/N",
129
+ "statements": [
130
+ {
131
+ "predicate": "example.org/data@1.0.0/v",
132
+ "value": {
133
+ "lit": "100",
134
+ "datatype": "kanonak.org/core-xsd/integer"
135
+ }
136
+ }
137
+ ]
138
+ }
139
+ ]
140
+ },
141
+ "expectedCanonicalForm": "{\"subjects\":[{\"uri\":\"example.org/data@1.0.0/N\",\"statements\":[{\"predicate\":\"example.org/data@1.0.0/v\",\"type\":\"typed\",\"carrier\":\"integer\",\"value\":\"100\"}]}]}",
142
+ "expectedHash": "sha256:653ec69910e2f7022208305c0ff44915f6eddf0163771a38f4af26161476caa4"
143
+ },
144
+ {
145
+ "id": "extra-untyped-raw-token",
146
+ "description": "An untyped/open-world scalar (no datatype): the raw token \"1.10\" is preserved verbatim, NOT decimal-collapsed to \"1.1\" — the open-world tier.",
147
+ "input": {
148
+ "subjects": [
149
+ {
150
+ "uri": "example.org/data@1.0.0/N",
151
+ "statements": [
152
+ {
153
+ "predicate": "example.org/data@1.0.0/x",
154
+ "value": {
155
+ "raw": "1.10"
156
+ }
157
+ }
158
+ ]
159
+ }
160
+ ]
161
+ },
162
+ "expectedCanonicalForm": "{\"subjects\":[{\"uri\":\"example.org/data@1.0.0/N\",\"statements\":[{\"predicate\":\"example.org/data@1.0.0/x\",\"type\":\"string\",\"value\":\"1.10\"}]}]}",
163
+ "expectedHash": "sha256:0b48e715952fb38d57d944b6bcbda77932f424b49868fce687728b3fa212e3e8"
164
+ },
165
+ {
166
+ "id": "list-order-preserved",
167
+ "description": "A list of references keeps source order [B, A] (lists carry semantic order).",
168
+ "input": {
169
+ "subjects": [
170
+ {
171
+ "uri": "example.org/data@1.0.0/L",
172
+ "statements": [
173
+ {
174
+ "predicate": "example.org/data@1.0.0/items",
175
+ "value": {
176
+ "list": [
177
+ {
178
+ "ref": "example.org/data@1.0.0/B"
179
+ },
180
+ {
181
+ "ref": "example.org/data@1.0.0/A"
182
+ }
183
+ ]
184
+ }
185
+ }
186
+ ]
187
+ }
188
+ ]
189
+ },
190
+ "expectedCanonicalForm": "{\"subjects\":[{\"uri\":\"example.org/data@1.0.0/L\",\"statements\":[{\"predicate\":\"example.org/data@1.0.0/items\",\"type\":\"list\",\"items\":[{\"type\":\"ref\",\"value\":\"example.org/data@1.0.0/B\"},{\"type\":\"ref\",\"value\":\"example.org/data@1.0.0/A\"}]}]}]}",
191
+ "expectedHash": "sha256:ea18909364cd74f16e1537d9796964508cc3821fbe530993a9f6784bf79afc0c"
192
+ },
193
+ {
194
+ "id": "ref-and-embedded",
195
+ "description": "A reference property and an embedded node property.",
196
+ "input": {
197
+ "subjects": [
198
+ {
199
+ "uri": "example.org/data@1.0.0/R",
200
+ "statements": [
201
+ {
202
+ "predicate": "example.org/data@1.0.0/owner",
203
+ "value": {
204
+ "ref": "example.org/data@1.0.0/Alice"
205
+ }
206
+ },
207
+ {
208
+ "predicate": "example.org/data@1.0.0/meta",
209
+ "value": {
210
+ "embed": {
211
+ "name": "m",
212
+ "statements": [
213
+ {
214
+ "predicate": "example.org/data@1.0.0/n",
215
+ "value": {
216
+ "lit": "7",
217
+ "datatype": "kanonak.org/core-xsd/integer"
218
+ }
219
+ }
220
+ ]
221
+ }
222
+ }
223
+ }
224
+ ]
225
+ }
226
+ ]
227
+ },
228
+ "expectedCanonicalForm": "{\"subjects\":[{\"uri\":\"example.org/data@1.0.0/R\",\"statements\":[{\"predicate\":\"example.org/data@1.0.0/meta\",\"type\":\"embedded\",\"name\":\"m\",\"statements\":[{\"predicate\":\"example.org/data@1.0.0/n\",\"type\":\"typed\",\"carrier\":\"integer\",\"value\":\"7\"}]},{\"predicate\":\"example.org/data@1.0.0/owner\",\"type\":\"ref\",\"value\":\"example.org/data@1.0.0/Alice\"}]}]}",
229
+ "expectedHash": "sha256:fd4700f77a5825ba362394c328c25b3eefd795926101aa18bf0af1804432908f"
230
+ },
231
+ {
232
+ "id": "nfc-normalization",
233
+ "description": "A string property whose value is authored as NFD (e + combining acute) canonicalizes to NFC.",
234
+ "input": {
235
+ "subjects": [
236
+ {
237
+ "uri": "example.org/data@1.0.0/N",
238
+ "statements": [
239
+ {
240
+ "predicate": "example.org/data@1.0.0/label",
241
+ "value": {
242
+ "lit": "é",
243
+ "datatype": "kanonak.org/core-xsd/string"
244
+ }
245
+ }
246
+ ]
247
+ }
248
+ ]
249
+ },
250
+ "expectedCanonicalForm": "{\"subjects\":[{\"uri\":\"example.org/data@1.0.0/N\",\"statements\":[{\"predicate\":\"example.org/data@1.0.0/label\",\"type\":\"typed\",\"carrier\":\"string\",\"value\":\"é\"}]}]}",
251
+ "expectedHash": "sha256:25b63ea3f42aa11307cbe4793caa56009be337707db7254fa64f7b6ae8b06cce"
252
+ }
253
+ ]
254
+ }
@@ -0,0 +1,81 @@
1
+ {
2
+ "canonicalFormVersion": "1",
3
+ "description": "Golden conformance vectors for per-carrier canonical lexical forms (issue #55). Language-neutral: each vector is (carrier, input raw token) -> expected canonical lexical string, OR (carrier, input) -> expectError for inputs that must fail loud. Every kanonak-canonical port asserts canonicalScalarLexical(carrier, input) === expected for these. Expected values are authoritative — they define the form.",
4
+ "vectors": [
5
+ { "id": "integer-plain", "carrier": "integer", "input": "100", "expected": "100" },
6
+ { "id": "integer-leading-zeros", "carrier": "integer", "input": "0100", "expected": "100" },
7
+ { "id": "integer-explicit-plus", "carrier": "integer", "input": "+100", "expected": "100" },
8
+ { "id": "integer-negative", "carrier": "integer", "input": "-42", "expected": "-42" },
9
+ { "id": "integer-negative-zero", "carrier": "integer", "input": "-0", "expected": "0" },
10
+ { "id": "integer-zero", "carrier": "integer", "input": "0", "expected": "0" },
11
+ { "id": "integer-epoch-nanos-beyond-2^53", "carrier": "integer", "input": "1770000000000000001", "expected": "1770000000000000001" },
12
+ { "id": "integer-rejects-decimal-point", "carrier": "integer", "input": "1.0", "expectError": true },
13
+ { "id": "integer-rejects-exponent", "carrier": "integer", "input": "1e3", "expectError": true },
14
+
15
+ { "id": "decimal-trailing-zero", "carrier": "decimal", "input": "1.10", "expected": "1.1" },
16
+ { "id": "decimal-all-fraction-zeros", "carrier": "decimal", "input": "1.00", "expected": "1" },
17
+ { "id": "decimal-leading-fraction-zero", "carrier": "decimal", "input": "0.10", "expected": "0.1" },
18
+ { "id": "decimal-integer-valued", "carrier": "decimal", "input": "100", "expected": "100" },
19
+ { "id": "decimal-integer-dot-zero", "carrier": "decimal", "input": "100.0", "expected": "100" },
20
+ { "id": "decimal-negative-zero", "carrier": "decimal", "input": "-0.00", "expected": "0" },
21
+ { "id": "decimal-bare-fraction", "carrier": "decimal", "input": ".5", "expected": "0.5" },
22
+ { "id": "decimal-negative-trailing", "carrier": "decimal", "input": "-0.250", "expected": "-0.25" },
23
+ { "id": "decimal-subpenny-exact", "carrier": "decimal", "input": "1.234500", "expected": "1.2345" },
24
+ { "id": "decimal-tenth-exact", "carrier": "decimal", "input": "0.1", "expected": "0.1" },
25
+ { "id": "decimal-rejects-exponent", "carrier": "decimal", "input": "1e3", "expectError": true },
26
+
27
+ { "id": "double-integer-valued", "carrier": "double", "input": "1000", "expected": "1000" },
28
+ { "id": "double-exponent-form", "carrier": "double", "input": "1e3", "expected": "1000" },
29
+ { "id": "double-fraction", "carrier": "double", "input": "1.5", "expected": "1.5" },
30
+ { "id": "double-negative-zero", "carrier": "double", "input": "-0", "expected": "0" },
31
+ { "id": "double-nan", "carrier": "double", "input": "NaN", "expected": "NaN" },
32
+ { "id": "double-inf", "carrier": "double", "input": "INF", "expected": "INF" },
33
+ { "id": "double-neg-inf", "carrier": "double", "input": "-INF", "expected": "-INF" },
34
+ { "id": "double-rejects-Infinity-spelling", "carrier": "double", "input": "Infinity", "expectError": true },
35
+
36
+ { "id": "float-fraction", "carrier": "float", "input": "1.5", "expected": "1.5" },
37
+ { "id": "float-nan", "carrier": "float", "input": "NaN", "expected": "NaN" },
38
+
39
+ { "id": "boolean-true", "carrier": "boolean", "input": "true", "expected": "true" },
40
+ { "id": "boolean-one", "carrier": "boolean", "input": "1", "expected": "true" },
41
+ { "id": "boolean-false", "carrier": "boolean", "input": "false", "expected": "false" },
42
+ { "id": "boolean-zero", "carrier": "boolean", "input": "0", "expected": "false" },
43
+ { "id": "boolean-rejects-uppercase", "carrier": "boolean", "input": "TRUE", "expectError": true },
44
+
45
+ { "id": "string-ascii-unchanged", "carrier": "string", "input": "hello", "expected": "hello" },
46
+ { "id": "string-nfd-to-nfc", "carrier": "string", "input": "é", "expected": "é" },
47
+ { "id": "string-nfc-stable", "carrier": "string", "input": "é", "expected": "é" },
48
+ { "id": "string-no-whitespace-collapse", "carrier": "string", "input": "a b\t", "expected": "a b\t" },
49
+
50
+ { "id": "anyURI-nfc", "carrier": "anyURI", "input": "https://example.org/é", "expected": "https://example.org/é" },
51
+
52
+ { "id": "hexBinary-lowercase-to-upper", "carrier": "hexBinary", "input": "0fb7", "expected": "0FB7" },
53
+ { "id": "hexBinary-already-upper", "carrier": "hexBinary", "input": "0FB7", "expected": "0FB7" },
54
+ { "id": "hexBinary-empty", "carrier": "hexBinary", "input": "", "expected": "" },
55
+ { "id": "hexBinary-rejects-odd-length", "carrier": "hexBinary", "input": "abc", "expectError": true },
56
+
57
+ { "id": "base64-canonical", "carrier": "base64Binary", "input": "aGVsbG8=", "expected": "aGVsbG8=" },
58
+ { "id": "base64-line-wrap-collapses", "carrier": "base64Binary", "input": "aGVs\nbG8=", "expected": "aGVsbG8=" },
59
+
60
+ { "id": "dateTime-offset-to-utc-z", "carrier": "dateTime", "input": "2026-05-31T13:00:00+01:00", "expected": "2026-05-31T12:00:00Z" },
61
+ { "id": "dateTime-z-stable", "carrier": "dateTime", "input": "2026-05-31T12:00:00Z", "expected": "2026-05-31T12:00:00Z" },
62
+ { "id": "dateTime-plus-zero-to-z", "carrier": "dateTime", "input": "2026-05-31T12:00:00+00:00", "expected": "2026-05-31T12:00:00Z" },
63
+ { "id": "dateTime-rolls-back-a-day", "carrier": "dateTime", "input": "2026-05-31T01:00:00+02:00", "expected": "2026-05-30T23:00:00Z" },
64
+ { "id": "dateTime-rolls-year", "carrier": "dateTime", "input": "2026-12-31T23:00:00-02:00", "expected": "2027-01-01T01:00:00Z" },
65
+ { "id": "dateTime-floating-no-z", "carrier": "dateTime", "input": "2026-05-31T12:00:00", "expected": "2026-05-31T12:00:00" },
66
+ { "id": "dateTime-nanos-preserved", "carrier": "dateTime", "input": "2026-01-01T00:00:00.123456789Z", "expected": "2026-01-01T00:00:00.123456789Z" },
67
+ { "id": "dateTime-frac-trailing-zeros-trimmed", "carrier": "dateTime", "input": "2026-01-01T00:00:00.1200Z", "expected": "2026-01-01T00:00:00.12Z" },
68
+ { "id": "dateTime-frac-all-zeros-dropped", "carrier": "dateTime", "input": "2026-01-01T00:00:00.000Z", "expected": "2026-01-01T00:00:00Z" },
69
+ { "id": "dateTime-frac-survives-shift", "carrier": "dateTime", "input": "2026-01-01T00:30:00.500+01:00", "expected": "2025-12-31T23:30:00.5Z" },
70
+
71
+ { "id": "date-no-shift", "carrier": "date", "input": "2026-05-31", "expected": "2026-05-31" },
72
+ { "id": "date-plus-zero-to-z", "carrier": "date", "input": "2026-05-31+00:00", "expected": "2026-05-31Z" },
73
+ { "id": "date-offset-preserved-not-shifted", "carrier": "date", "input": "2026-05-31-05:00", "expected": "2026-05-31-05:00" },
74
+
75
+ { "id": "time-no-shift", "carrier": "time", "input": "13:00:00-05:00", "expected": "13:00:00-05:00" },
76
+ { "id": "time-frac-trimmed", "carrier": "time", "input": "23:30:00.500Z", "expected": "23:30:00.5Z" },
77
+ { "id": "time-frac-all-zeros-dropped", "carrier": "time", "input": "00:00:00.000", "expected": "00:00:00" },
78
+ { "id": "time-24-to-00", "carrier": "time", "input": "24:00:00", "expected": "00:00:00" },
79
+ { "id": "time-plus-zero-to-z", "carrier": "time", "input": "12:00:00+00:00", "expected": "12:00:00Z" }
80
+ ]
81
+ }
@@ -1,2 +0,0 @@
1
- import{I as W,J as X}from"./chunk-QXFO6X6V.js";import{b as B,c as V,f as w}from"./chunk-IUZZDC2U.js";import{a as b,d as K,e as q,f as z}from"./chunk-Z5ELOT2C.js";import{a as D,f as E,h as F,j as N,k as Y,m as v}from"./chunk-XQS5LDSO.js";import{c as G,d as x}from"./chunk-W6T7MOKY.js";import{a as L}from"./chunk-FUUTGGJS.js";import{d as U}from"./chunk-2ACBWC7K.js";var Q=(t=>(t.Class="Class",t.DatatypeProperty="DatatypeProperty",t.ObjectProperty="ObjectProperty",t.AnnotationProperty="AnnotationProperty",t.Instance="Instance",t.Datatype="Datatype",t.Unknown="Unknown",t))(Q||{}),Z=(p=>(p.InstanceOf="instanceOf",p.SubClassOf="subClassOf",p.Domain="domain",p.Range="range",p.ObjectRelationship="objectRelationship",p.SubPropertyOf="subPropertyOf",p.PropertyValue="propertyValue",p.EmbeddedLink="embeddedLink",p))(Z||{}),I=class{static async buildFromRepository(e){let a=await new w().parseKanonaks(e),o=await e.getAllDocumentsAsync(),s=[],i=[],t=new Set,p=new Set,g=new Map;for(let u of a){let l=u;l.name&&(b.isClassType(l)&&t.add(l.name),(b.isObjectPropertyType(l)||b.isGenericPropertyType(l))&&p.add(l.name))}for(let u of o)for(let[l,f]of Object.entries(u.body))p.has(l)&&f?.range&&typeof f.range=="string"&&g.set(l,f.range);let y=new Map;for(let u of a){let l=u;l.name&&y.set(l.name,l)}for(let u of o){let l=u.metadata.namespace_,f=l?`${l.publisher}/${l.package_}`:"",c=l?.version?`${l.version.major}.${l.version.minor}.${l.version.patch}`:"",d=H(u);for(let[k,m]of Object.entries(u.body)){if(!m||typeof m!="object")continue;let P=y.get(k),h="Unknown";if(P){let T=P;b.isClassType(T)?h="Class":b.isObjectPropertyType(T)?h="ObjectProperty":b.isDatatypePropertyType(T)?h="DatatypeProperty":b.isAnnotationPropertyType(T)?h="AnnotationProperty":b.isDatatypeType(T)?h="Datatype":b.isGenericPropertyType(T)?h="ObjectProperty":b.isInstanceOfKnownClass(T,t)&&(h="Instance")}let j=f&&c?`${f}/${k}@${c}`:k,A={};for(let[T,$]of Object.entries(m))T!=="type"&&(typeof $!="object"||$===null)&&(A[T]=$);s.push({id:j,label:m.label??k,type:h,namespace:f,properties:A}),J(j,m,h,t,p,i,f,c,d),_(j,m,p,g,s,i,f,c,d),ue(j,P,i)}}return{nodes:s,edges:i}}static buildFromDocument(e){let r=[],a=[],o=e.metadata.namespace_,s=o?.version?`${o.version.major}.${o.version.minor}.${o.version.patch}`:"",i=o?`${o.publisher}/${o.package_}`:"",t=new Set,p=new Set,g=new Map,y=H(e);for(let[f,c]of Object.entries(e.body)){let d=c?.type;d&&(pe(d,y)&&t.add(f),ce(d,y)&&(p.add(f),c.range&&typeof c.range=="string"&&g.set(f,c.range)))}for(let[f,c]of Object.entries(e.body)){if(!c||typeof c!="object")continue;let d=c.type,k=le(d,f,t,y),m=i&&s?`${i}/${f}@${s}`:f,P={};for(let[h,j]of Object.entries(c))h!=="type"&&(typeof j!="object"||j===null)&&(P[h]=j);r.push({id:m,label:c.label??f,type:k,namespace:i,properties:P}),J(m,c,k,t,p,a,i,s,y),_(m,c,p,g,r,a,i,s,y)}let u=new Set(r.map(f=>f.id)),l=a.filter(f=>u.has(f.source)&&u.has(f.target));return{nodes:r,edges:l}}};function H(n,e){let r=new Map;if(n.metadata?.imports)for(let[a,o]of Object.entries(n.metadata.imports))for(let s of o){let i=s.alias??s.packageName,t=s.version,p=`${t.major}.${t.minor}.${t.patch}`;r.set(i,{publisher:a,package_:s.packageName,version:p})}return r}var ee={"kanonak.org/core-rdf/Class":"Class","kanonak.org/core-owl/Class":"Class","kanonak.org/core-rdfs/Class":"Class","kanonak.org/core-owl/ObjectProperty":"ObjectProperty","kanonak.org/core-owl/DatatypeProperty":"DatatypeProperty","kanonak.org/core-owl/AnnotationProperty":"AnnotationProperty","kanonak.org/core-rdf/Property":"ObjectProperty","kanonak.org/core-rdfs/Datatype":"Datatype"},ie=new Set(["kanonak.org/core-owl/ObjectProperty","kanonak.org/core-owl/DatatypeProperty","kanonak.org/core-owl/AnnotationProperty","kanonak.org/core-rdf/Property"]);function M(n,e){if(n.includes(".")){let r=n.indexOf("."),a=n.substring(0,r),o=n.substring(r+1),s=e.get(a);if(s)return`${s.publisher}/${s.package_}/${o}`}return null}function pe(n,e){let r=M(n,e);return r?ee[r]==="Class":!1}function ce(n,e){let r=M(n,e);return r?ie.has(r):!1}function le(n,e,r,a){if(!n||n==="Package")return"Unknown";let o=M(n,a);if(o){let i=ee[o];if(i)return i;let t=o.split("/").pop()?.split("@")[0]??"";return r.has(t)?"Instance":"Unknown"}let s=n.split(".").pop()??n;return r.has(s)?"Instance":"Unknown"}var ne=new Set(["type","label","comment","version","publisher","imports","license","match","alias","package"]);function J(n,e,r,a,o,s,i,t,p){let g=e.type,y=e.subClassOf;if(y){let c=Array.isArray(y)?y:[y];for(let d of c)typeof d=="string"&&s.push({source:n,target:O(d,i,t,p),type:"subClassOf",label:"subClassOf"})}let u=e.subPropertyOf;if(u){let c=Array.isArray(u)?u:[u];for(let d of c)typeof d=="string"&&s.push({source:n,target:O(d,i,t,p),type:"subPropertyOf",label:"subPropertyOf"})}if(r==="Instance"&&g){let c=g.split(".").pop()??g;s.push({source:n,target:O(c,i,t,p),type:"instanceOf",label:"type"})}if(r==="Instance")for(let[c,d]of Object.entries(e)){if(ne.has(c)||!o.has(c))continue;let k=Array.isArray(d)?d:[d];for(let m of k)typeof m=="string"&&fe(m)&&s.push({source:n,target:O(m,i,t,p),type:"propertyValue",label:c,propertyId:O(c,i,t,p)})}let l=r==="ObjectProperty"||r==="DatatypeProperty",f=e.domain&&e.range;if((l||f)&&e.domain&&e.range){let c=typeof e.domain=="string"?e.domain:null,d=typeof e.range=="string"?e.range:null;c&&d&&s.push({source:O(c,i,t,p),target:O(d,i,t,p),type:"objectRelationship",label:e.label??n.split("/").pop()??"",propertyId:n})}}function _(n,e,r,a,o,s,i,t,p){for(let[g,y]of Object.entries(e)){if(ne.has(g)||typeof y!="object"||y===null||Array.isArray(y))continue;let u=y,l=`${n}/${g}`,f=a.get(g),c=f?f.split(".").pop()??f:"Unknown",d={};for(let[m,P]of Object.entries(u))(typeof P!="object"||P===null)&&(d[m]=P);o.push({id:l,label:`${c} (embedded)`,type:"Instance",namespace:i,properties:d});let k=i&&t?`${i}/${g}@${t}`:g;s.push({source:n,target:l,type:"propertyValue",label:g,propertyId:r.has(g)?k:void 0}),f&&s.push({source:l,target:O(c,i,t,p),type:"instanceOf",label:"type (inferred)"}),_(l,u,r,a,o,s,i,t,p)}}function ue(n,e,r){let a=e?.statement;if(Array.isArray(a))for(let o of a){if(!(o instanceof V))continue;let s=o.predicate?.subject?.name??"";for(let i of o.links){let t=i.target?.subject;if(!t)continue;let p=t.version,g=p&&typeof p.major=="number"?`@${p.major}.${p.minor}.${p.patch}`:"";r.push({source:n,target:`${t.publisher}/${t.package_}/${t.name}${g}`,type:"embeddedLink",label:s})}}}function fe(n){return!(!n||n.includes(" ")||n.includes(`
2
- `)||n.startsWith("http://")||n.startsWith("https://")||/^\d{4}-\d{2}/.test(n)||/^\d+(\.\d+)?$/.test(n))}function O(n,e,r,a){if(n.includes("@")&&n.includes("/"))return n;if(n.includes(".")){let o=n.indexOf("."),s=n.substring(0,o),i=n.substring(o+1);if(a){let t=a.get(s);if(t)return`${t.publisher}/${t.package_}/${i}@${t.version}`}return e&&r?`${e}/${i}@${r}`:i}return e&&r?`${e}/${n}@${r}`:n}function de(n){if(!n.expiresAt)return!1;let e=new Date(n.expiresAt),r=300*1e3;return e.getTime()<=Date.now()+r}function Re(n){return!!n.accessToken&&!de(n)}function Se(n){let e=n.replace(/^https?:\/\//,"").replace(/^git:\/\//,"").replace(/\/+$/,"").trim();if(!e)throw new Error("Publisher host cannot be empty");return e}var C="kanonak.org",S="core-rdf",re="core-xsd",te={publisher:C,package_:S,name:"subClassOf"},oe={publisher:C,package_:S,name:"label"},ye={publisher:C,package_:S,name:"comment"},se={publisher:C,package_:"core-owl",name:"oneOf"},ae=n=>n;function ge(n){let e=Y(n,te);if(e)return[e];let r=[];for(let a of v(n,te))a instanceof x&&r.push(a.subject);return r}function me(n,e,r){if(e.publisher===C&&e.package_===S&&e.name==="Literal")return{kind:"datatype",uri:e};let o=E(n,e);if(o){let s=ae(o);if(b.isDatatypeType(s))return{kind:"datatype",uri:e};if(b.isClassType(s))return{kind:"class",uri:K(o)??e,localName:o.name}}return e.publisher===C&&e.package_===re?{kind:"datatype",uri:e}:r==="datatype"?{kind:"datatype",uri:e}:{kind:"class",uri:e,localName:e.name}}function be(n,e,r){if(!e.range)throw new Error(`Property ${e.uri.publisher}/${e.uri.package_}/${e.uri.name} has no rdfs.range; every property must declare a range. Validate the ontology before introspecting it.`);let a=me(n,e.range,e.kind),o=e.kind==="object"?"object":e.kind==="datatype"?"datatype":a.kind==="class"?"object":"datatype";return{uri:e.uri,localName:e.uri.name,kind:o,range:a,...e.label!==void 0?{label:e.label}:{},...e.comment!==void 0?{comment:e.comment}:{},...r??{}}}var R=n=>new L(C,re,n);function ke(n){return typeof n=="boolean"?R("boolean"):typeof n=="number"?Number.isInteger(n)?R("integer"):R("decimal"):R("string")}function he(n,e){let r=[];for(let a of v(e,se))if(a instanceof x){let o=E(n,a.subject),s=(o?K(o):void 0)??a.subject,i=o?N(o,oe):void 0;r.push({kind:"individual",uri:s,localName:s.name,...i!==void 0?{label:i}:{}})}else a instanceof B&&r.push({kind:"literal",value:a.value,datatype:ke(a.value)});return r}function Pe(n,e,r,a){let o=q(n,e),s=D(e);return z(n,e).filter(t=>r?!0:t.domains.some(p=>D(p)===s)).map(t=>be(n,t,X(a,o,t.uri)))}async function Te(n,e,r){let a=n.metadata?.namespace_;if(!a)throw new Error("buildOntologyModel: document has no namespace (publisher/package/version).");let o=r?.includeInherited??!1,s=await new w().parseKanonaks(e),i=W(s),t=[],p=[],g=new Set;for(let y of s){if(!(y instanceof G)||!b.isClassType(ae(y)))continue;let u=K(y);if(!u||u.publisher!==a.publisher||u.package_!==a.package_||u.version&&a.version&&!U(u.version,a.version))continue;let l=D(u);if(g.has(l))continue;g.add(l);let f=ge(y).map(k=>({uri:k,localName:k.name})),c=N(y,oe),d=N(y,ye);t.push({uri:u,localName:u.name,superClasses:f,properties:Pe(s,u,o,i),...c!==void 0?{label:c}:{},...d!==void 0?{comment:d}:{}}),F(y,se)&&p.push({uri:u,localName:u.name,members:he(s,y),...c!==void 0?{label:c}:{},...d!==void 0?{comment:d}:{}})}return{classes:t,enums:p}}export{Q as a,Z as b,I as c,de as d,Re as e,Se as f,Te as g};
@@ -1 +0,0 @@
1
- import{a as A}from"./chunk-TJPQETHV.js";import{b as N,c as _,i as M}from"./chunk-IOMNZBK4.js";import{a as $,b as L,c as j,d as k,g as S,h as D,i as O,j as P,k as K,l as R}from"./chunk-W6T7MOKY.js";var b=class extends L{name};var w=class extends ${value};var I=class extends S{links=[]};var U=/\[\[([^\[\]\n]+)\]\]/g,B=/\[\[/g,V=/```[\s\S]*?```|`[^`\n]*`/g;function z(f){let e=[];for(let t of f.matchAll(V))e.push([t.index,t.index+t[0].length]);return e}function Q(f){if(!f||!f.includes("[["))return[];let e=z(f),t=a=>e.some(([n,p])=>a>=n&&a<p),r=new Set(T(f).map(a=>a.startOffset)),o=[];for(let a of f.matchAll(B)){let n=a.index;if(t(n)||r.has(n))continue;let p=f.slice(n,n+48).replace(/\s+/g," ").trim();o.push({startOffset:n,snippet:p})}return o}function T(f){if(!f||!f.includes("[["))return[];let e=[];for(let o of f.matchAll(V))e.push([o.index,o.index+o[0].length]);let t=o=>e.some(([a,n])=>o>=a&&o<n),r=[];for(let o of f.matchAll(U)){let a=o.index;if(t(a))continue;let n=o[1],p=n.indexOf("|"),s=(p===-1?n:n.slice(0,p)).trim();if(s.length===0)continue;let m=p===-1?"":n.slice(p+1).trim(),y={reference:s,startOffset:a,endOffset:a+o[0].length};m.length>0&&(y.displayText=m),r.push(y)}return r}var C=class{constructor(e){}async parseKanonaks(e){let t=[],r=await e.getAllDocumentsAsync(),o=new N(e),a=new _(o);for(let i of r){let c=i.metadata.namespace_?.toString()??"";for(let[l,u]of Object.entries(i.body)){let d=new j,g=this.resolveCanonicalEntity(l,i,c);d.namespace=g.namespace,d.name=g.name,d.statement=[];let h=await this.parseStatements(u,i,o,a,e);d.statement.push(...h),t.push(d)}}let n=new Map,p=new Map,s=[];for(let i of t)if(i instanceof j){let c=`${i.namespace}/${i.name}`,l=n.get(c);if(l){let u=p.get(c);for(let d of i.statement){let g=E(d);u.has(g)||(u.add(g),l.statement.push(d))}}else{let u=new Set,d=[];for(let g of i.statement){let h=E(g);u.has(h)||(u.add(h),d.push(g))}i.statement=d,p.set(c,u),n.set(c,i),s.push(i)}}else s.push(i);let m=new Set;for(let i of s)if(i instanceof j){let c=i.namespace||"",l=c.indexOf("/"),u=l>=0?c.slice(0,l):"",d=l>=0?c.slice(l+1):"",g=d.indexOf("@"),h=g>=0?d.slice(0,g):d;m.add(`${u}/${h}/${i.name}`)}let y=i=>m.has(`${i.publisher}/${i.package_}/${i.name}`);for(let i of s)i instanceof j&&this.canonicalizeStatementBuiltins(i.statement,y);return s}canonicalizeStatementBuiltins(e,t){for(let r of e){let o=r.predicate?.subject;if(M(o,t),r instanceof P)r.object instanceof k&&M(r.object.subject,t);else if(r instanceof K)r.object&&this.canonicalizeStatementBuiltins(r.object.statement,t);else if(r instanceof R)for(let a of r.object??[])a instanceof k?M(a.subject,t):a instanceof b&&this.canonicalizeStatementBuiltins(a.statement,t)}}resolveCanonicalEntity(e,t,r){if(!e.includes(".")||!t.metadata?.imports)return{namespace:r,name:e};let o=e.indexOf("."),a=e.substring(0,o),n=e.substring(o+1);for(let[p,s]of Object.entries(t.metadata.imports))for(let m of s)if((m.alias??m.packageName)===a){let i=m.version;return{namespace:`${p}/${m.packageName}@${i.major}.${i.minor}.${i.patch}`,name:n}}return{namespace:r,name:e}}async parseStatements(e,t,r,o,a){let n=[];if(typeof e!="object"||e===null||Array.isArray(e))return n;for(let[p,s]of Object.entries(e))try{let m=await this.getPropertyMetadata(p,t,r,a,o);if(!m)continue;let y=await this.parsePropertyValue(p,s,m,t,r,o,a);y&&n.push(y)}catch(m){throw new Error(`Failed to parse property '${p}': ${m.message}`,{cause:m})}return n}async getPropertyMetadata(e,t,r,o,a){let n=await r.resolveEntityAsync(e,t);if(!n)return;let p=n.entity,s=p.type?.toString()??"",m=s.includes(".")?s.substring(s.lastIndexOf(".")+1):s;if(!new Set(["Property","DatatypeProperty","ObjectProperty","AnnotationProperty"]).has(m))return;let i=a.getPropertyTypeClassification(s),c=p.range?.toString(),l;if(i==="ObjectProperty")l="ObjectProperty";else if(i==="DatatypeProperty")l="DatatypeProperty";else{let g=c&&c.includes(".")?c.substring(c.lastIndexOf(".")+1):c??"";(c?a.isKnownXsdDatatypeName(c):!1)||g==="Literal"?l="DatatypeProperty":l="ObjectProperty"}let u;if(c){let g=t;if(n.isImported&&n.definedInNamespace){if(typeof o.getDocumentAsync!="function")throw new Error(`Cannot resolve the range of imported property '${e}': the parse repository cannot fetch defining document '${n.definedInNamespace}'. Thread the real repository through to embedded-object parsing \u2014 no stub, no fallback.`);let x=await o.getDocumentAsync(n.definedInNamespace);if(!x)throw new Error(`Cannot resolve the range of imported property '${e}': defining document '${n.definedInNamespace}' was not found in the repository.`);g=x}u=(await r.resolveEntityAsync(c,g))?.uri}return{propertyUri:n.uri.toString(),propertyType:l,range:c,rangeUri:u,isImported:n.isImported,definedInNamespace:n.definedInNamespace}}async parsePropertyValue(e,t,r,o,a,n,p){let s=r.propertyUri;if(t!=null){if(Array.isArray(t))return this.parseListValue(s,t,r,o,a,n,p);if(r.propertyType==="DatatypeProperty")return this.parseDatatypeValue(s,t,r,o,a,n);if(r.propertyType==="ObjectProperty")return this.parseObjectValue(s,t,r,o,a,n,p)}}async parseDatatypeValue(e,t,r,o,a,n){if(t instanceof Date)return S.parse(e,t.toISOString());if(typeof t=="string")return n.isSubstitutableDatatype(r.rangeUri)?await this.parseSubstitutableValue(e,t,o,a):S.parse(e,t);if(typeof t=="number")return D.parse(e,t);if(typeof t=="boolean"){let p=new O;return p.predicate=k.parse(e),p.object=t,p}}async parseSubstitutableValue(e,t,r,o){let a=new I;a.predicate=k.parse(e),a.object=t;for(let n of T(t)){let p=await o.resolveEntityAsync(n.reference,r),s;p&&(s=new k,s.subject=p.uri);let m={reference:n.reference,startOffset:n.startOffset,endOffset:n.endOffset};n.displayText!==void 0&&(m.displayText=n.displayText),s!==void 0&&(m.target=s),a.links.push(m)}return a}async parseObjectValue(e,t,r,o,a,n,p){if(typeof t=="string"){let s=await this.resolveReference(t,o,a);if(!s)return;let m=new P;return m.predicate=k.parse(e),m.object=s,m}if(typeof t=="object"&&!Array.isArray(t)){let s=new b;if(s.statement=await this.parseStatements(t,o,a,n,p),s.statement.length>0){let i=new K;return i.predicate=k.parse(e),i.object=s,i}let m=[];for(let[i,c]of Object.entries(t))if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let l=new b;l.name=i,l.statement=await this.parseStatements(c,o,a,n,p),m.push(l)}else if(typeof c=="string"){let l=await this.resolveReference(c,o,a);l&&m.push(l)}if(m.length>0){let i=new R;return i.predicate=k.parse(e),i.object=m,i}let y=new K;return y.predicate=k.parse(e),y.object=s,y}}async parseListValue(e,t,r,o,a,n,p){let s=[],m=r.propertyType==="DatatypeProperty",y=r.rangeUri?.publisher==="kanonak.org"&&r.rangeUri?.package_==="core-rdf"&&r.rangeUri?.name==="List"||!r.rangeUri&&(r.range?.includes(".")?r.range.substring(r.range.lastIndexOf(".")+1):r.range)==="List";for(let c of t){let l=typeof c=="string"||typeof c=="number"||typeof c=="boolean";if(m&&l){let u=new w;u.value=c,s.push(u);continue}if((m||y)&&c instanceof Date){let u=new w;u.value=c.toISOString(),s.push(u);continue}if(y&&l){if(typeof c=="string"){let u=await a.resolveEntityAsync(c,o);if(u){let d=new k;d.subject=u.uri,s.push(d)}else{let d=new w;d.value=c,s.push(d)}}else{let u=new w;u.value=c,s.push(u)}continue}if(typeof c=="string"){let u=await this.resolveReference(c,o,a);u&&s.push(u)}else if(typeof c=="object"&&c!==null&&!Array.isArray(c)){let u=new b;u.statement=await this.parseStatements(c,o,a,n,p),s.push(u)}}let i=new R;return i.predicate=k.parse(e),i.object=s,i}async resolveReference(e,t,r){let o=await r.resolveEntityAsync(e,t);if(o){let n=new k;return n.subject=o.uri,n}let a=t.metadata?.namespace_;if(a){let{KanonakUri:n}=await import("./KanonakUri-4VJGV3FN.js"),p=a.version??{major:0,minor:0,patch:0,toString:()=>"0.0.0",equals:()=>!1,getHashCode:()=>0,compareTo:()=>0};if(e.includes(".")){let m=e.indexOf("."),y=e.substring(0,m),i=e.substring(m+1);if(t.metadata?.imports){for(let[c,l]of Object.entries(t.metadata.imports))for(let u of l)if((u.alias??u.packageName)===y){let g=new k;return g.subject=new n(c,u.packageName,i,u.version),g}}}let s=new k;return s.subject=new n(a.publisher,a.package_,e,p),s}return null}async saveKanonaks(e,t){let r=new Map;for(let o of e)o instanceof j&&o.namespace&&(r.has(o.namespace)||r.set(o.namespace,[]),r.get(o.namespace).push(o));for(let[o,a]of r){let n=await this.convertKanonaksToDocument(o,a),p=`${o.split("@")[0]}.yml`;await t.saveDocumentAsync(n,p)}}async serializeToYaml(e,t){let r=e.filter(n=>n instanceof j&&n.namespace===t);if(r.length===0)throw new Error(`No kanonaks found with namespace '${t}'`);let o=await this.convertKanonaksToDocument(t,r);return new A().save(o)}async convertKanonaksToDocument(e,t){let o={metadata:{namespace_:e,get allImports(){if(!this.imports)return[];let n=[];for(let p of Object.values(this.imports))n.push(...p);return n}},body:{}},a=new Map;for(let n of t){let p={};for(let s of n.statement){let[m,y]=this.convertStatementToProperty(s);m&&y!==null&&y!==void 0&&(p[m]=y),this.collectImportsFromStatement(s,e,a)}o.body[n.name]=p}return o}convertStatementToProperty(e){if(e instanceof S)return[e.predicate.subject.name,e.object];if(e instanceof D)return[e.predicate.subject.name,e.object];if(e instanceof O)return[e.predicate.subject.name,e.object];if(e instanceof P)return[e.predicate.subject.name,e.object.subject.name];if(e instanceof R){let t=this.convertKanonakListToValue(e.object);return[e.predicate.subject.name,t]}else if(e instanceof K){let t=this.convertEmbeddedKanonakToValue(e.object);return[e.predicate.subject.name,t]}return[null,null]}convertKanonakListToValue(e){let t=[];for(let r of e)r instanceof k?t.push(r.subject.name):r instanceof b&&t.push(this.convertEmbeddedKanonakToValue(r));return t}convertEmbeddedKanonakToValue(e){let t={};for(let r of e.statement){let[o,a]=this.convertStatementToProperty(r);o&&a!==null&&a!==void 0&&(t[o]=a)}return t}collectImportsFromStatement(e,t,r){}};function E(f){let e=f.predicate?.subject;return(e?`${e.publisher}/${e.package_}/${e.name}`:"?")+"="+X(f)}function X(f){return f instanceof I?"m:"+String(f.object):f instanceof S?"s:"+String(f.object):f instanceof D?"n:"+String(f.object):f instanceof O?"b:"+String(f.object):f instanceof P?"r:"+v(f.object):f instanceof K?"e:"+v(f.object):f instanceof R?"l:["+(f.object??[]).map(v).join("|")+"]":"x"}function v(f){if(!f)return"";if(f instanceof k){let e=f.subject;return"R("+(e?`${e.publisher}/${e.package_}/${e.name}`:"")+")"}return f instanceof b?"E("+(f.statement??[]).map(E).join(";")+")":f instanceof w?"L("+String(f.value)+")":"N"}export{b as a,w as b,I as c,Q as d,T as e,C as f};
@@ -1 +0,0 @@
1
- import{a as k,b as f}from"./chunk-2ACBWC7K.js";import*as h from"js-yaml";var b=new Set(["Package","EphemeralPackage"]);function v(d){return typeof d=="string"&&b.has(d)}var $=class{parse(r){let t=this.parseWithErrors(r);if(!t.isValid){let a=t.errors[0];throw new Error(`YAML parse error at line ${a.line}, column ${a.column}: ${a.message}`)}return t.document}parseWithErrors(r){let t=[],a;try{r=r.replace(/^\uFEFF/,"");let s=h.load(r);if(!s||typeof s!="object")return a={metadata:this.createEmptyMetadata(),body:{},toString:()=>"KanonakDocument(empty)"},{document:a,errors:t,isValid:!0};let e=this.extractMetadata(s),n=this.extractBody(s,e);return a={metadata:e,body:n,toString:function(){return this.metadata.namespace_?`KanonakDocument(${this.metadata.namespace_.publisher}/${this.metadata.namespace_.package_})`:"KanonakDocument(no namespace)"}},{document:a,errors:t,isValid:!0}}catch(s){let e=s,n={message:e.message||"Unknown parse error",line:e.mark?.line??0,column:e.mark?.column??0,errorType:e.name==="YAMLException"?"SyntaxError":"Unknown",toString:()=>`${e.name==="YAMLException"?"SyntaxError":"Unknown"} at line ${e.mark?.line??0}: ${e.message||"Unknown parse error"}`};return t.push(n),{document:void 0,errors:t,isValid:!1}}}save(r){let t={};if(r.metadata.namespace_){let a=r.metadata.namespace_,s={type:"Package",publisher:a.publisher};a.version&&(s.version=`${a.version.major}.${a.version.minor}.${a.version.patch}`),r.metadata.imports&&(s.imports=this.serializeImports(r.metadata.imports)),t[a.package_]=s}return Object.assign(t,r.body),h.dump(t,{indent:2,noRefs:!0,sortKeys:!1})}createEmptyMetadata(){return{get allImports(){return[]}}}addAllImportsGetter(r){let t=r.imports;return Object.defineProperty(r,"allImports",{get:function(){if(!t)return[];let a=[];for(let s of Object.values(t))a.push(...s);return a},enumerable:!0,configurable:!0}),r}createVersion(r,t,a){return{major:r,minor:t,patch:a,toString:()=>`${r}.${t}.${a}`,equals:e=>!e||typeof e!="object"?!1:e.major===r&&e.minor===t&&e.patch===a,getHashCode:()=>r<<20|t<<10|a,compareTo:e=>r!==e.major?r-e.major:t!==e.minor?t-e.minor:a-e.patch}}extractMetadata(r){let t=this.createEmptyMetadata();for(let[a,s]of Object.entries(r))if(s&&typeof s=="object"&&v(s.type)){t.type_=s.type;let e=a,n=s.publisher,i=s.version?this.parseVersion(s.version):void 0;return n&&e&&(t.namespace_={publisher:n,package_:e,version:i,toString:function(){return this.version?`${this.publisher}/${this.package_}@${this.version.major}.${this.version.minor}.${this.version.patch}`:`${this.publisher}/${this.package_}`},equals:o=>!o||typeof o!="object"?!1:o.publisher===n&&o.package_===e&&(!i||!o.version||i.equals(o.version)),getHashCode:()=>{let o=0;for(let c=0;c<n.length;c++)o=(o<<5)-o+n.charCodeAt(c);for(let c=0;c<e.length;c++)o=(o<<5)-o+e.charCodeAt(c);return o|0}}),s.imports&&Array.isArray(s.imports)&&(t.imports=this.parseImportsV3(s.imports)),this.addAllImportsGetter(t)}if(r.kanonak&&typeof r.kanonak=="object"){let a=r.kanonak;return(a.publisher||a.package||a.version)&&(t.namespace_=this.parseNamespace(a)),a.imports&&typeof a.imports=="object"&&(t.imports=this.parseImportsLegacy(a.imports)),this.addAllImportsGetter(t)}return t}extractBody(r,t){let a={};for(let[s,e]of Object.entries(r))if(!(s==="kanonak"||s==="namespace"||s==="imports"))if(e&&typeof e=="object"&&v(e.type)){let n={};for(let[i,o]of Object.entries(e))i==="publisher"||i==="version"||i==="imports"||(n[i]=o);a[s]=n}else a[s]=e;return a}parseNamespace(r){if(typeof r=="string"){let e=r.match(/^([^/]+)\/([^@]+)(?:@(.+))?$/);if(e){let n=e[3]?this.parseVersion(e[3]):this.createVersion(1,0,0);return{publisher:e[1],package_:e[2],version:n,toString:()=>r,equals:i=>!i||typeof i!="object"?!1:i.publisher===e[1]&&i.package_===e[2]&&(!n||!i.version||n.equals(i.version)),getHashCode:()=>{let i=0;for(let o=0;o<e[1].length;o++)i=(i<<5)-i+e[1].charCodeAt(o);for(let o=0;o<e[2].length;o++)i=(i<<5)-i+e[2].charCodeAt(o);return i|0}}}}let t=r.publisher||"",a=r.package||"",s=r.version?this.parseVersion(r.version):this.createVersion(1,0,0);return{publisher:t,package_:a,version:s,toString:function(){return`${this.publisher}/${this.package_}@${this.version?.major??1}.${this.version?.minor??0}.${this.version?.patch??0}`},equals:e=>!e||typeof e!="object"?!1:e.publisher===t&&e.package_===a&&(!s||!e.version||s.equals(e.version)),getHashCode:()=>{let e=0;for(let n=0;n<t.length;n++)e=(e<<5)-e+t.charCodeAt(n);for(let n=0;n<a.length;n++)e=(e<<5)-e+a.charCodeAt(n);return e|0}}}parseVersion(r){if(typeof r=="string"){let t=r.split(".").map(Number);return this.createVersion(t[0]||0,t[1]||0,t[2]||0)}return this.createVersion(r.major||0,r.minor||0,r.patch||0)}parseImportsV3(r){let t={};for(let a of r)if(!(!a||typeof a!="object"))if(a.packages&&Array.isArray(a.packages)){let s=a.publisher;if(!s)throw new Error("PublisherImport requires 'publisher' property");t[s]||(t[s]=[]);for(let e of a.packages){if(!e||typeof e!="object")continue;let n=this.parseImportFromEmbeddedObject(e,s);t[s].push(n)}}else{let s=this.parseImportFromEmbeddedObject(a,a.publisher),e=s.publisher||"";t[e]||(t[e]=[]),t[e].push(s)}return t}parseImportsLegacy(r){let t={};for(let[a,s]of Object.entries(r))Array.isArray(s)&&(t[a]=s.map(e=>this.parseImport(e,a)));return t}parseImportFromEmbeddedObject(r,t){let a=r.package;if(!a)throw new Error("Import requires 'package' property");let s=r.match;if(!s)throw new Error("Import requires 'match' property");let e=r.version;if(!e)throw new Error("Import requires 'version' property");let n=this.parseVersion(e),i=this.parseVersionOperator(s),o=this.calculateMaxVersion(s,n),c=r.alias;return{package_:`${a} ${s} ${n.toString()}`,publisher:t,packageName:a,versionOperator:i,version:n,alias:c,minVersion:n,maxVersion:o,toEmbeddedObject:()=>{let m={package:a,match:s,version:n.toString()};return c&&(m.alias=c),m},toString:()=>c?`${a} ${s} ${n.toString()} as ${c}`:`${a} ${s} ${n.toString()}`}}buildImport(r,t,a,s){return this.parseImport({packageName:r,operator:t,version:a},s)}parseImport(r,t){if(typeof r=="string"){let o=r.match(/^(.+?)\s*([~^=*])\s*(\S+)\s+as\s+(\S+)$/);if(o){let m=o[1].trim(),u=o[2],p=this.parseVersion(o[3].trim()),l=o[4].trim(),g=this.parseVersionOperator(u),V=this.calculateMaxVersion(u,p);return{package_:r,publisher:t,packageName:m,versionOperator:g,version:p,alias:l,minVersion:p,maxVersion:V,toEmbeddedObject:()=>{let y={package:m,match:u,version:p.toString()};return l&&(y.alias=l),y},toString:()=>`${m} ${u} ${p.toString()} as ${l}`}}let c=r.match(/^(.+?)\s*([~^=*])\s*(.+)$/);if(c){let m=c[1].trim(),u=c[2],p=this.parseVersion(c[3].trim()),l=this.parseVersionOperator(u),g=this.calculateMaxVersion(u,p);return{package_:r,publisher:t,packageName:m,versionOperator:l,version:p,alias:void 0,minVersion:p,maxVersion:g,toEmbeddedObject:()=>({package:m,match:u,version:p.toString()}),toString:()=>`${m} ${u} ${p.toString()}`}}}let a=this.parseVersionOperator(r.operator||"~"),s=this.parseVersion(r.version||"1.0.0"),e=r.packageName||r.package||"",n=f(a),i=this.calculateMaxVersion(r.operator||"~",s);return{package_:r.package||"",publisher:t,packageName:e,versionOperator:a,version:s,alias:r.alias,minVersion:s,maxVersion:i,toEmbeddedObject:()=>{let o={package:e,match:n,version:s.toString()};return r.alias&&(o.alias=r.alias),o},toString:()=>`${e} ${n} ${s.toString()}`}}parseVersionOperator(r){return k(r)}calculateMaxVersion(r,t){switch(r){case"~":return this.createVersion(t.major,t.minor+1,0);case"^":return t.major===0?this.createVersion(0,t.minor+1,0):this.createVersion(t.major+1,0,0);default:return this.createVersion(999,999,999)}}serializeImports(r){let t=[];for(let[a,s]of Object.entries(r)){let e={publisher:a,packages:s.map(n=>{let i=f(n.versionOperator),o={package:n.packageName,match:i,version:`${n.version.major}.${n.version.minor}.${n.version.patch}`};return n.alias&&(o.alias=n.alias),o})};t.push(e)}return t}};export{$ as a};
@@ -1 +0,0 @@
1
- import{a as c}from"./chunk-FUUTGGJS.js";var m=class{};var p=class extends m{statement=[]};var i=class extends p{namespace;name;icon};var a=class e extends m{subject;static parse(o){let n=new e;return n.subject=c.parse(o),n}};var r=class{predicate;object};var s=class extends r{};var f=class e extends s{static parse(o,n){let t=new e;return t.predicate=a.parse(o),t.object=n,t}};var k=class e extends s{static parse(o,n){let t=new e;return t.predicate=a.parse(o),t.object=n,t}};var x=class extends s{};var d=class e extends r{static parse(o,n){let t=new e;return t.predicate=a.parse(o),t.object=a.parse(n),t}};var l=class extends r{};var b=class extends r{};export{m as a,p as b,i as c,a as d,r as e,s as f,f as g,k as h,x as i,d as j,l as k,b as l};