@altopelago/sansa 0.9.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/conformance/cts-claims.json +4 -4
- package/docs/api-contract.md +7 -6
- package/docs/capabilities.json +39 -2
- package/docs/query-tool.md +1 -1
- package/fixtures/address-v1.json +9 -9
- package/fixtures/query-inventory.aeon +2 -2
- package/fixtures/query-inventory.json +4 -4
- package/package.json +1 -1
- package/scripts/query.mjs +1 -1
- package/scripts/validate-cts-claims.mjs +22 -11
- package/src/index.d.ts +144 -2
- package/src/index.js +359 -20
- package/stress-tests/address/valid.sansa-cases +3 -3
- package/tools/mutate-web/runtime.mjs +4 -4
- package/tools/query-web/runtime.mjs +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,39 @@ versions may still include breaking changes when the SANSA specifications move.
|
|
|
9
9
|
|
|
10
10
|
No notable changes yet.
|
|
11
11
|
|
|
12
|
+
## 0.10.0 - 2026-09-01
|
|
13
|
+
|
|
14
|
+
### Breaking
|
|
15
|
+
|
|
16
|
+
- Renamed the AEON temporal literal family from `zrut` to `wtc` across query,
|
|
17
|
+
instruction, mutation, workbench, fixture, declaration, and documentation
|
|
18
|
+
surfaces.
|
|
19
|
+
- Changed qualifier datatype clarifiers to one bracketed list. String
|
|
20
|
+
clarifiers must now be quoted, multiple values use comma separation inside
|
|
21
|
+
the same brackets, and numeric clarifiers such as `radix[16]` are represented
|
|
22
|
+
as numbers. Repeated clarifier lists and unquoted string clarifiers are
|
|
23
|
+
rejected.
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- Added experimental `traverseGraph(...)` and `traverseGraphSequence(...)`
|
|
28
|
+
APIs for declared, directed relationship traversal with ordered path
|
|
29
|
+
provenance.
|
|
30
|
+
- Added experimental graph capability metadata covering schema-version
|
|
31
|
+
applicability, semantic-type constraints, edge cardinality, cycle policy,
|
|
32
|
+
authorization hooks, and explicit traversal budgets.
|
|
33
|
+
|
|
34
|
+
### Changed
|
|
35
|
+
|
|
36
|
+
- Updated address, instruction, mutation, query, fixture, stress, and API
|
|
37
|
+
contract surfaces to use the unified AEON datatype clarifier grammar.
|
|
38
|
+
|
|
39
|
+
### Security
|
|
40
|
+
|
|
41
|
+
- Graph traversal requires explicit budgets and applies an independent
|
|
42
|
+
authorization decision to every traversal step without granting authority to
|
|
43
|
+
composed Query reads.
|
|
44
|
+
|
|
12
45
|
## 0.9.1 - 2026-08-02
|
|
13
46
|
|
|
14
47
|
### Added
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"claim_format": "aeonite.cts-claims.v1",
|
|
3
3
|
"repository": "AltoPelago/sansa",
|
|
4
4
|
"implementation": "@altopelago/sansa",
|
|
5
|
-
"implementation_version": "0.
|
|
5
|
+
"implementation_version": "0.10.0",
|
|
6
6
|
"cts_repository": "aeonite-org/aeonite-cts",
|
|
7
7
|
"cts_protocol": "cts.protocol.v1",
|
|
8
8
|
"claims": [
|
|
@@ -26,20 +26,20 @@
|
|
|
26
26
|
},
|
|
27
27
|
{
|
|
28
28
|
"surface": "sansa-query-parser",
|
|
29
|
-
"snapshot_id": "sansa-query-parser-cts-v1-snapshot-0.
|
|
29
|
+
"snapshot_id": "sansa-query-parser-cts-v1-snapshot-0.2",
|
|
30
30
|
"status": "claimed",
|
|
31
31
|
"command": "npm run cts:query",
|
|
32
32
|
"notes": "The default command excludes experimental extension cases."
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
35
|
"surface": "sansa-query-experimental",
|
|
36
|
-
"snapshot_id": "sansa-query-parser-cts-v1-snapshot-0.
|
|
36
|
+
"snapshot_id": "sansa-query-parser-cts-v1-snapshot-0.2",
|
|
37
37
|
"status": "experimental",
|
|
38
38
|
"command": "npm run cts:query:experimental"
|
|
39
39
|
},
|
|
40
40
|
{
|
|
41
41
|
"surface": "sansa-instruction",
|
|
42
|
-
"snapshot_id": "sansa-instruction-cts-v1-snapshot-0.
|
|
42
|
+
"snapshot_id": "sansa-instruction-cts-v1-snapshot-0.2",
|
|
43
43
|
"status": "experimental",
|
|
44
44
|
"command": "npm run cts:instruction"
|
|
45
45
|
},
|
package/docs/api-contract.md
CHANGED
|
@@ -408,7 +408,7 @@ If mutation targets parse successfully but produce SANSA portability warnings, s
|
|
|
408
408
|
|
|
409
409
|
Mutation plans are current-process execution artifacts, not portable serialized plan documents. A plan retains live binding objects supplied by the resolver, along with local adapter artifacts such as `bindingHandle` and `observedState`. These fields are for same-process continuity checks and diagnostics. Do not `JSON.stringify` a plan and replay it later or in another implementation; cloned or serialized plans cannot prove live binding continuity and should fail apply-time stale-target checks. A portable mutation-plan serialization format may be defined by a later profile.
|
|
410
410
|
|
|
411
|
-
For scalar values, the workbench adapter treats `kind` as the AEON literal family when one is provided. Known scalar families include `string`, `number`, `boolean`, `toggle`, `hex`, `radix`, `encoding`, `separator`/`sep`, `sansa`, `date`, `time`, `datetime`, `
|
|
411
|
+
For scalar values, the workbench adapter treats `kind` as the AEON literal family when one is provided. Known scalar families include `string`, `number`, `boolean`, `toggle`, `hex`, `radix`, `encoding`, `separator`/`sep`, `sansa`, `date`, `time`, `datetime`, `wtc`, `null`, `nan`, `infinity`, `cloneReference`, and `pointerReference`. JSON payloads omit AEON sigils: `kind: "hex"` with `"ff00aa"` renders `#ff00aa`; `kind: "sep"` with `"0.11.0"` renders `^0.11.0`; `kind: "null"` with `"notApplicable"` renders `!notApplicable`; and `kind: "cloneReference"` with `"target"` renders `~target`. The adapter rejects payloads that cannot be rendered as the requested known AEON literal family. Unknown custom `kind` values remain adapter-visible metadata and are not interpreted by the core planner.
|
|
412
412
|
|
|
413
413
|
Experimental Mutate budgets are optional and fail closed:
|
|
414
414
|
|
|
@@ -1020,7 +1020,7 @@ Current comparison policy:
|
|
|
1020
1020
|
| radix and radix | allowed | error | preserved payload and radix-family metadata identity only |
|
|
1021
1021
|
| hex and radix | error | error | no implicit numeric or base-16 coercion |
|
|
1022
1022
|
| encoding and encoding | allowed | allowed | naïve payload order over preserved encoded payload characters |
|
|
1023
|
-
| separator and separator | allowed | allowed | naïve whole-payload order; no splitting on
|
|
1023
|
+
| separator and separator | allowed | allowed | naïve whole-payload order; no splitting on datatype clarifiers |
|
|
1024
1024
|
| SANSA address and SANSA address | allowed | allowed | canonical address-expression identity and naïve address-expression order |
|
|
1025
1025
|
| temporal and temporal | allowed within same family | allowed within same family | default profile uses canonical temporal payload order; cross-family comparison fails without explicit compatibility |
|
|
1026
1026
|
| reference form and reference form | allowed | error | reference-kind and canonical target-path identity; no implicit follow |
|
|
@@ -1198,22 +1198,23 @@ The evaluator does not execute host-supplied functions. Function support is limi
|
|
|
1198
1198
|
}
|
|
1199
1199
|
```
|
|
1200
1200
|
|
|
1201
|
-
Arguments are
|
|
1201
|
+
Arguments are one of:
|
|
1202
1202
|
|
|
1203
1203
|
```js
|
|
1204
1204
|
{ kind: "token", value }
|
|
1205
1205
|
{ kind: "quoted", value }
|
|
1206
|
+
{ kind: "number", value }
|
|
1206
1207
|
```
|
|
1207
1208
|
|
|
1208
1209
|
Top-level qualifier unions are represented by multiple `terms`. Nested qualifier unions inside generic parameters are rejected.
|
|
1209
1210
|
|
|
1210
|
-
Qualifier terms may contain zero or more parameter groups and zero or
|
|
1211
|
+
Qualifier terms may contain zero or more parameter groups and zero or one clarifier value list:
|
|
1211
1212
|
|
|
1212
1213
|
```text
|
|
1213
|
-
name<parameter,parameter><parameter>[argument
|
|
1214
|
+
name<parameter,parameter><parameter>[argument,argument]
|
|
1214
1215
|
```
|
|
1215
1216
|
|
|
1216
|
-
`parameters` is a flattened convenience view. `parameterGroups` preserves how the term should render.
|
|
1217
|
+
`parameters` is a flattened convenience view. `parameterGroups` preserves how the term should render. Clarifier values preserve AEON's single-list datatype clarifier grammar.
|
|
1217
1218
|
|
|
1218
1219
|
## Canonical Rendering
|
|
1219
1220
|
|
package/docs/capabilities.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"implementation": "@altopelago/sansa",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"profiles": [
|
|
5
5
|
"value-semantics-minimum-consumer",
|
|
6
6
|
"aeon.value.default.v1",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"SANSA.Query",
|
|
20
20
|
"SANSA.Instruction",
|
|
21
21
|
"SANSA.Mutate",
|
|
22
|
-
"SANSA.Transform"
|
|
22
|
+
"SANSA.Transform",
|
|
23
|
+
"SANSA.Graph"
|
|
23
24
|
],
|
|
24
25
|
"core": {
|
|
25
26
|
"valueSemanticsMinimumConsumer": true,
|
|
@@ -30,6 +31,42 @@
|
|
|
30
31
|
"mutate": false
|
|
31
32
|
},
|
|
32
33
|
"experimentalCapabilities": [
|
|
34
|
+
{
|
|
35
|
+
"id": "sansa.graph.structured.one-hop.v1",
|
|
36
|
+
"capability": "SANSA.Graph",
|
|
37
|
+
"category": "declared-relationship-traversal",
|
|
38
|
+
"maturity": "experimental",
|
|
39
|
+
"entryPoints": ["traverseGraph", "traverseGraphSequence"],
|
|
40
|
+
"semantics": [
|
|
41
|
+
"structured declarations only",
|
|
42
|
+
"one-hop directed traversal",
|
|
43
|
+
"explicit bounded multi-hop declaration sequences",
|
|
44
|
+
"complete ordered multi-hop path provenance",
|
|
45
|
+
"index-neutral traversal through optional namespace lookup acceleration",
|
|
46
|
+
"explicit omit-or-error cycle policy",
|
|
47
|
+
"explicit schema-version applicability",
|
|
48
|
+
"source and target semantic-type constraints",
|
|
49
|
+
"per-source edge cardinality constraints",
|
|
50
|
+
"same-namespace traversal only",
|
|
51
|
+
"absolute address reference targets",
|
|
52
|
+
"address-valued relationship edges",
|
|
53
|
+
"deterministic Binding Set and Path Set",
|
|
54
|
+
"explicit Query-before and contextual Query/Transform-after composition",
|
|
55
|
+
"mandatory explicit budgets",
|
|
56
|
+
"aggregate depth, node, edge, and result budgets across hops",
|
|
57
|
+
"independent authorization callback per traversal step",
|
|
58
|
+
"read-only"
|
|
59
|
+
],
|
|
60
|
+
"boundaries": [
|
|
61
|
+
"relationship declaration authority remains external to SANSA",
|
|
62
|
+
"AEOS or an AEOS-adjacent profile owns relationship meaning",
|
|
63
|
+
"target adapters own index health, rebuild, and scan fallback",
|
|
64
|
+
"traversal conveys location, never authorization",
|
|
65
|
+
"Graph authorization does not authorize composed Query reads",
|
|
66
|
+
"relationship mutation remains SANSA.Mutate responsibility",
|
|
67
|
+
"no graph storage, indexing, query language, or implicit recursive traversal claim"
|
|
68
|
+
]
|
|
69
|
+
},
|
|
33
70
|
{
|
|
34
71
|
"id": "sansa.instruction.prototype.v1",
|
|
35
72
|
"capability": "SANSA.Instruction",
|
package/docs/query-tool.md
CHANGED
|
@@ -147,7 +147,7 @@ example `#ff00aa`, `%ff00aa`,
|
|
|
147
147
|
`2026-07-25`, `09:30:00Z`, `2026-07-25T09:30:00Z`, and
|
|
148
148
|
`2026-07-25T09:30:00Z&Australia/Melbourne`. Same-family temporal values compare
|
|
149
149
|
through the active temporal value-semantics profile; the default profile uses
|
|
150
|
-
canonical payload order for `date`, `time`, `datetime`, and `
|
|
150
|
+
canonical payload order for `date`, `time`, `datetime`, and `wtc` families. It rejects mixed-type
|
|
151
151
|
comparisons, toggle-to-Boolean coercion, hex-to-radix coercion, cross-family
|
|
152
152
|
temporal comparison, Boolean ordering, container ordering, explicit null
|
|
153
153
|
comparison, and NaN comparison.
|
package/fixtures/address-v1.json
CHANGED
|
@@ -163,10 +163,10 @@
|
|
|
163
163
|
"qualifierTerms": ["tuple"]
|
|
164
164
|
},
|
|
165
165
|
{
|
|
166
|
-
"id": "qualified-
|
|
167
|
-
"source": "$.version:sep[
|
|
166
|
+
"id": "qualified-string-clarifier",
|
|
167
|
+
"source": "$.version:sep[\".\"]",
|
|
168
168
|
"valid": true,
|
|
169
|
-
"canonical": "$.version:sep[
|
|
169
|
+
"canonical": "$.version:sep[\".\"]",
|
|
170
170
|
"exact": true,
|
|
171
171
|
"qualifierTerms": ["sep"]
|
|
172
172
|
},
|
|
@@ -179,18 +179,18 @@
|
|
|
179
179
|
"qualifierTerms": ["csv"]
|
|
180
180
|
},
|
|
181
181
|
{
|
|
182
|
-
"id": "qualified-
|
|
183
|
-
"source": "$.key:string[\",\"
|
|
182
|
+
"id": "qualified-multiple-clarifier-values",
|
|
183
|
+
"source": "$.key:string[\",\",\".\"]",
|
|
184
184
|
"valid": true,
|
|
185
|
-
"canonical": "$.key:string[\",\"
|
|
185
|
+
"canonical": "$.key:string[\",\",\".\"]",
|
|
186
186
|
"exact": true,
|
|
187
187
|
"qualifierTerms": ["string"]
|
|
188
188
|
},
|
|
189
189
|
{
|
|
190
190
|
"id": "qualified-rich-host-surface",
|
|
191
|
-
"source": "$.claim:type<type>[arg]",
|
|
191
|
+
"source": "$.claim:type<type>[\"arg\"]",
|
|
192
192
|
"valid": true,
|
|
193
|
-
"canonical": "$.claim:type<type>[arg]",
|
|
193
|
+
"canonical": "$.claim:type<type>[\"arg\"]",
|
|
194
194
|
"exact": true,
|
|
195
195
|
"qualifierTerms": ["type"]
|
|
196
196
|
},
|
|
@@ -198,7 +198,7 @@
|
|
|
198
198
|
"id": "reject-raw-comma-argument",
|
|
199
199
|
"source": "$.inventory:csv[,]",
|
|
200
200
|
"valid": false,
|
|
201
|
-
"error": "
|
|
201
|
+
"error": "SANSA_EXPECTED_QUALIFIER_ARGUMENT"
|
|
202
202
|
},
|
|
203
203
|
{
|
|
204
204
|
"id": "reject-empty-qualifier-argument",
|
|
@@ -10,11 +10,11 @@ types:object = {
|
|
|
10
10
|
mask:radix[16] = %ff00aa
|
|
11
11
|
octal:radix8 = %70
|
|
12
12
|
payload:encoding = &QmFzZTY0IQ==
|
|
13
|
-
version:sep[.] = ^0.11.0
|
|
13
|
+
version:sep["."] = ^0.11.0
|
|
14
14
|
released:date = 2026-07-25
|
|
15
15
|
window:time = 09:30:00Z
|
|
16
16
|
stamp:datetime = 2026-07-25T09:30:00Z
|
|
17
|
-
zone:
|
|
17
|
+
zone:wtc = 2026-07-25T09:30:00Z&Australia/Melbourne
|
|
18
18
|
count:int32 = 2
|
|
19
19
|
capacity:uint64 = 8
|
|
20
20
|
ratio:float64 = 2.5
|
|
@@ -180,7 +180,7 @@
|
|
|
180
180
|
{
|
|
181
181
|
"name": "version",
|
|
182
182
|
"address": "$.types.version",
|
|
183
|
-
"semanticType": "sep[
|
|
183
|
+
"semanticType": "sep[\".\"]",
|
|
184
184
|
"representationKind": "separator",
|
|
185
185
|
"scalarKind": "separator",
|
|
186
186
|
"value": "0.11.0"
|
|
@@ -212,9 +212,9 @@
|
|
|
212
212
|
{
|
|
213
213
|
"name": "zone",
|
|
214
214
|
"address": "$.types.zone",
|
|
215
|
-
"semanticType": "
|
|
216
|
-
"representationKind": "
|
|
217
|
-
"scalarKind": "
|
|
215
|
+
"semanticType": "wtc",
|
|
216
|
+
"representationKind": "wtc",
|
|
217
|
+
"scalarKind": "wtc",
|
|
218
218
|
"value": "2026-07-25T09:30:00Z&Australia/Melbourne"
|
|
219
219
|
},
|
|
220
220
|
{
|
package/package.json
CHANGED
package/scripts/query.mjs
CHANGED
|
@@ -466,7 +466,7 @@ function renderAeonValue(value, metadata, fieldMetadata) {
|
|
|
466
466
|
if (metadata?.kind === 'radix') return `%${value}`;
|
|
467
467
|
if (metadata?.kind === 'encoding') return `&${value}`;
|
|
468
468
|
if (metadata?.kind === 'separator') return `^${value}`;
|
|
469
|
-
if (['date', 'time', 'datetime', '
|
|
469
|
+
if (['date', 'time', 'datetime', 'wtc'].includes(metadata?.kind)) return String(value);
|
|
470
470
|
if (metadata?.kind === 'sansaAddress' || metadata?.kind === 'sansa') {
|
|
471
471
|
return value?.canonical ?? value?.address?.canonical ?? value?.address ?? String(value);
|
|
472
472
|
}
|
|
@@ -28,7 +28,7 @@ if (typeof claimsDocument.cts_protocol !== 'string' || claimsDocument.cts_protoc
|
|
|
28
28
|
errors.push('cts_protocol must be a non-empty string');
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
claims.forEach((claim
|
|
31
|
+
claims.forEach((claim) => validateClaim(claim, snapshotIds, errors));
|
|
32
32
|
|
|
33
33
|
if (errors.length > 0) {
|
|
34
34
|
console.error(`CTS claim validation failed: ${errors.length} issue(s)`);
|
|
@@ -41,7 +41,9 @@ console.log(`CTS claim validation passed: claims=${claims.length} cts_snapshots=
|
|
|
41
41
|
function readArg(name) {
|
|
42
42
|
const index = process.argv.indexOf(name);
|
|
43
43
|
if (index < 0) return null;
|
|
44
|
-
|
|
44
|
+
const value = process.argv[index + 1];
|
|
45
|
+
if (value === undefined || value.startsWith('--')) return null;
|
|
46
|
+
return value;
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
function readJson(file, label) {
|
|
@@ -53,7 +55,12 @@ function readJson(file, label) {
|
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
function collectClaims(document) {
|
|
56
|
-
if (Array.isArray(document.claims))
|
|
58
|
+
if (Array.isArray(document.claims)) {
|
|
59
|
+
return document.claims.map((claim, claimIndex) => ({
|
|
60
|
+
claim,
|
|
61
|
+
path: `claims[${claimIndex}]`,
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
57
64
|
if (!Array.isArray(document.claim_sets)) {
|
|
58
65
|
errors.push('claims document must contain claims or claim_sets');
|
|
59
66
|
return [];
|
|
@@ -70,28 +77,32 @@ function collectClaims(document) {
|
|
|
70
77
|
errors.push(`claim_sets[${claimSetIndex}].claims must be a list`);
|
|
71
78
|
return [];
|
|
72
79
|
}
|
|
73
|
-
return claimSet.claims.map((claim) => ({
|
|
80
|
+
return claimSet.claims.map((claim, claimIndex) => ({
|
|
81
|
+
claim,
|
|
82
|
+
path: `claim_sets[${claimSetIndex}].claims[${claimIndex}]`,
|
|
83
|
+
}));
|
|
74
84
|
});
|
|
75
85
|
}
|
|
76
86
|
|
|
77
|
-
function validateClaim(
|
|
87
|
+
function validateClaim(entry, knownSnapshotIds, output) {
|
|
88
|
+
const { claim, path } = entry;
|
|
78
89
|
if (!claim || typeof claim !== 'object') {
|
|
79
|
-
output.push(
|
|
90
|
+
output.push(`${path} must be an object`);
|
|
80
91
|
return;
|
|
81
92
|
}
|
|
82
93
|
if (typeof claim.surface !== 'string' || claim.surface.length === 0) {
|
|
83
|
-
output.push(
|
|
94
|
+
output.push(`${path}.surface must be a non-empty string`);
|
|
84
95
|
}
|
|
85
96
|
if (typeof claim.snapshot_id !== 'string' || claim.snapshot_id.length === 0) {
|
|
86
|
-
output.push(
|
|
97
|
+
output.push(`${path}.snapshot_id must be a non-empty string`);
|
|
87
98
|
} else if (!knownSnapshotIds.has(claim.snapshot_id)) {
|
|
88
|
-
output.push(
|
|
99
|
+
output.push(`${path}.snapshot_id is not present in CTS manifests: ${claim.snapshot_id}`);
|
|
89
100
|
}
|
|
90
101
|
if (!['claimed', 'experimental', 'advisory'].includes(claim.status)) {
|
|
91
|
-
output.push(
|
|
102
|
+
output.push(`${path}.status must be one of claimed, experimental, advisory`);
|
|
92
103
|
}
|
|
93
104
|
if (claim.command !== undefined && (typeof claim.command !== 'string' || claim.command.length === 0)) {
|
|
94
|
-
output.push(
|
|
105
|
+
output.push(`${path}.command must be a non-empty string when present`);
|
|
95
106
|
}
|
|
96
107
|
}
|
|
97
108
|
|
package/src/index.d.ts
CHANGED
|
@@ -141,6 +141,26 @@ export type SansaResolveErrorCode =
|
|
|
141
141
|
| 'SANSA_RESOLVE_EXACT_MULTIPLICITY_VIOLATION'
|
|
142
142
|
| 'SANSA_RESOLVE_UNSUPPORTED_SELECTOR';
|
|
143
143
|
|
|
144
|
+
export type SansaGraphErrorCode =
|
|
145
|
+
| 'SANSA_GRAPH_INVALID_INPUT'
|
|
146
|
+
| 'SANSA_GRAPH_BUDGET_REQUIRED'
|
|
147
|
+
| 'SANSA_GRAPH_INVALID_BUDGET'
|
|
148
|
+
| 'SANSA_GRAPH_BUDGET_EXCEEDED'
|
|
149
|
+
| 'SANSA_GRAPH_CYCLE_DETECTED'
|
|
150
|
+
| 'SANSA_GRAPH_INVALID_DECLARATION'
|
|
151
|
+
| 'SANSA_GRAPH_DUPLICATE_DECLARATION'
|
|
152
|
+
| 'SANSA_GRAPH_SCHEMA_VERSION_UNSUPPORTED'
|
|
153
|
+
| 'SANSA_GRAPH_START_ADDRESS_MISSING'
|
|
154
|
+
| 'SANSA_GRAPH_SOURCE_TYPE_MISMATCH'
|
|
155
|
+
| 'SANSA_GRAPH_EDGE_MISSING'
|
|
156
|
+
| 'SANSA_GRAPH_EDGE_CARDINALITY_MISMATCH'
|
|
157
|
+
| 'SANSA_GRAPH_EDGE_ADDRESS_MISSING'
|
|
158
|
+
| 'SANSA_GRAPH_END_ADDRESS_MISSING'
|
|
159
|
+
| 'SANSA_GRAPH_TARGET_TYPE_MISMATCH'
|
|
160
|
+
| 'SANSA_GRAPH_INVALID_REFERENCE_TARGET'
|
|
161
|
+
| 'SANSA_GRAPH_DANGLING_TARGET'
|
|
162
|
+
| 'SANSA_GRAPH_STEP_UNAUTHORIZED';
|
|
163
|
+
|
|
144
164
|
export type SansaQueryEvaluateErrorCode =
|
|
145
165
|
| 'SANSA_QUERY_POLICY_VIOLATION'
|
|
146
166
|
| 'SANSA_QUERY_BUDGET_EXCEEDED'
|
|
@@ -285,6 +305,111 @@ export interface SansaResolveNamespace<TBinding extends object = SansaResolveBin
|
|
|
285
305
|
readonly mutate?: SansaMutationAdapter<TBinding>;
|
|
286
306
|
}
|
|
287
307
|
|
|
308
|
+
export interface SansaGraphRelationshipDeclaration {
|
|
309
|
+
readonly id: string;
|
|
310
|
+
readonly direction: 'directed';
|
|
311
|
+
readonly schemaVersions: readonly string[];
|
|
312
|
+
readonly namespaceTransition: 'same-namespace';
|
|
313
|
+
readonly referenceForm: 'absolute-address-reference';
|
|
314
|
+
readonly sourceSemanticTypes: readonly string[];
|
|
315
|
+
readonly targetSemanticTypes: readonly string[];
|
|
316
|
+
readonly edgeAddress: string;
|
|
317
|
+
readonly edgeCardinality: 'zero-or-one' | 'exactly-one' | 'zero-or-more' | 'one-or-more';
|
|
318
|
+
readonly missingEdge: 'omit' | 'error';
|
|
319
|
+
readonly danglingTarget: 'omit' | 'error';
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export interface SansaGraphBudget {
|
|
323
|
+
readonly maxDepth: number;
|
|
324
|
+
readonly maxStartBindings: number;
|
|
325
|
+
readonly maxVisitedNodes: number;
|
|
326
|
+
readonly maxVisitedEdges: number;
|
|
327
|
+
readonly maxResults: number;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export interface SansaGraphTraversalMetrics {
|
|
331
|
+
readonly visitedNodes: number;
|
|
332
|
+
readonly visitedEdges: number;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export interface SansaGraphTraversalStep<TBinding extends object = SansaResolveBinding> {
|
|
336
|
+
readonly start: TBinding;
|
|
337
|
+
readonly edge: TBinding;
|
|
338
|
+
readonly end: TBinding;
|
|
339
|
+
readonly declaration: SansaGraphRelationshipDeclaration;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
export interface SansaGraphTraversalOptions<TBinding extends object = SansaResolveBinding> {
|
|
343
|
+
readonly budget: SansaGraphBudget;
|
|
344
|
+
readonly schemaVersion: string;
|
|
345
|
+
readonly authorizeStep?: (step: SansaGraphTraversalStep<TBinding>) => boolean;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export interface SansaGraphPath<TBinding extends object = SansaResolveBinding> {
|
|
349
|
+
readonly declarationId: string;
|
|
350
|
+
readonly start: TBinding;
|
|
351
|
+
readonly startAddress: string;
|
|
352
|
+
readonly edge: TBinding;
|
|
353
|
+
readonly edgeAddress: string;
|
|
354
|
+
readonly end: TBinding;
|
|
355
|
+
readonly endAddress: string;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export interface SansaGraphDiagnostic {
|
|
359
|
+
readonly code: SansaGraphErrorCode | SansaResolveErrorCode | SansaParseErrorCode;
|
|
360
|
+
readonly message: string;
|
|
361
|
+
readonly declarationId?: string;
|
|
362
|
+
readonly startAddress?: string;
|
|
363
|
+
readonly edgeAddress?: string;
|
|
364
|
+
readonly targetAddress?: string;
|
|
365
|
+
readonly budget?: string;
|
|
366
|
+
readonly limit?: number;
|
|
367
|
+
readonly observed?: number;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export type SansaGraphTraversalResult<TBinding extends object = SansaResolveBinding> =
|
|
371
|
+
| {
|
|
372
|
+
readonly ok: true;
|
|
373
|
+
readonly bindings: readonly TBinding[];
|
|
374
|
+
readonly paths: readonly SansaGraphPath<TBinding>[];
|
|
375
|
+
readonly metrics: SansaGraphTraversalMetrics;
|
|
376
|
+
readonly diagnostics: readonly SansaGraphDiagnostic[];
|
|
377
|
+
}
|
|
378
|
+
| {
|
|
379
|
+
readonly ok: false;
|
|
380
|
+
readonly bindings: readonly [];
|
|
381
|
+
readonly paths: readonly [];
|
|
382
|
+
readonly errors: readonly SansaGraphDiagnostic[];
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
export interface SansaGraphSequencePath<TBinding extends object = SansaResolveBinding> {
|
|
386
|
+
readonly start: TBinding;
|
|
387
|
+
readonly startAddress: string;
|
|
388
|
+
readonly end: TBinding;
|
|
389
|
+
readonly endAddress: string;
|
|
390
|
+
readonly steps: readonly SansaGraphPath<TBinding>[];
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
export interface SansaGraphSequenceOptions<TBinding extends object = SansaResolveBinding>
|
|
394
|
+
extends SansaGraphTraversalOptions<TBinding> {
|
|
395
|
+
readonly cyclePolicy: 'omit' | 'error';
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export type SansaGraphSequenceResult<TBinding extends object = SansaResolveBinding> =
|
|
399
|
+
| {
|
|
400
|
+
readonly ok: true;
|
|
401
|
+
readonly bindings: readonly TBinding[];
|
|
402
|
+
readonly paths: readonly SansaGraphSequencePath<TBinding>[];
|
|
403
|
+
readonly metrics: SansaGraphTraversalMetrics;
|
|
404
|
+
readonly diagnostics: readonly SansaGraphDiagnostic[];
|
|
405
|
+
}
|
|
406
|
+
| {
|
|
407
|
+
readonly ok: false;
|
|
408
|
+
readonly bindings: readonly [];
|
|
409
|
+
readonly paths: readonly [];
|
|
410
|
+
readonly errors: readonly SansaGraphDiagnostic[];
|
|
411
|
+
};
|
|
412
|
+
|
|
288
413
|
export interface SansaResolveOptions<TBinding extends object = SansaResolveBinding> {
|
|
289
414
|
readonly parse?: SansaParseOptions;
|
|
290
415
|
readonly contextualRoot?: TBinding;
|
|
@@ -963,7 +1088,7 @@ export interface SansaQueryLiteralExpression {
|
|
|
963
1088
|
| 'date'
|
|
964
1089
|
| 'time'
|
|
965
1090
|
| 'datetime'
|
|
966
|
-
| '
|
|
1091
|
+
| 'wtc'
|
|
967
1092
|
| 'null';
|
|
968
1093
|
readonly value: string | number | boolean | null;
|
|
969
1094
|
readonly nullReason?: string;
|
|
@@ -1313,7 +1438,7 @@ export interface QualifierTerm {
|
|
|
1313
1438
|
readonly arguments: readonly QualifierArgument[];
|
|
1314
1439
|
}
|
|
1315
1440
|
|
|
1316
|
-
export type QualifierArgument = QualifierTokenArgument | QualifierQuotedArgument;
|
|
1441
|
+
export type QualifierArgument = QualifierTokenArgument | QualifierQuotedArgument | QualifierNumberArgument;
|
|
1317
1442
|
|
|
1318
1443
|
export interface QualifierTokenArgument {
|
|
1319
1444
|
readonly kind: 'token';
|
|
@@ -1325,6 +1450,11 @@ export interface QualifierQuotedArgument {
|
|
|
1325
1450
|
readonly value: string;
|
|
1326
1451
|
}
|
|
1327
1452
|
|
|
1453
|
+
export interface QualifierNumberArgument {
|
|
1454
|
+
readonly kind: 'number';
|
|
1455
|
+
readonly value: number;
|
|
1456
|
+
}
|
|
1457
|
+
|
|
1328
1458
|
export class SansaParseError extends Error {
|
|
1329
1459
|
readonly code: SansaParseErrorCode;
|
|
1330
1460
|
readonly index: number;
|
|
@@ -1377,6 +1507,18 @@ export function resolveAddress<TBinding extends object = SansaResolveBinding>(
|
|
|
1377
1507
|
namespace: SansaResolveNamespace<TBinding>,
|
|
1378
1508
|
options?: SansaResolveOptions<TBinding>,
|
|
1379
1509
|
): SansaResolveResult<TBinding>;
|
|
1510
|
+
export function traverseGraph<TBinding extends object = SansaResolveBinding>(
|
|
1511
|
+
starts: readonly TBinding[],
|
|
1512
|
+
namespace: SansaResolveNamespace<TBinding>,
|
|
1513
|
+
declarations: readonly SansaGraphRelationshipDeclaration[],
|
|
1514
|
+
options: SansaGraphTraversalOptions<TBinding>,
|
|
1515
|
+
): SansaGraphTraversalResult<TBinding>;
|
|
1516
|
+
export function traverseGraphSequence<TBinding extends object = SansaResolveBinding>(
|
|
1517
|
+
starts: readonly TBinding[],
|
|
1518
|
+
namespace: SansaResolveNamespace<TBinding>,
|
|
1519
|
+
hops: readonly (readonly SansaGraphRelationshipDeclaration[])[],
|
|
1520
|
+
options: SansaGraphSequenceOptions<TBinding>,
|
|
1521
|
+
): SansaGraphSequenceResult<TBinding>;
|
|
1380
1522
|
export function renderAddress(address: SansaAddress): string;
|
|
1381
1523
|
export function renderQuery(query: SansaQuery): string;
|
|
1382
1524
|
export function renderQueryExpression(expression: SansaQueryExpression): string;
|
package/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const IDENTIFIER_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
2
|
-
const
|
|
2
|
+
const QUALIFIER_NUMBER_RE = /^[+-]?(?:(?:0|[1-9][0-9]*)(?:\.[0-9]+)?|\.[0-9]+)$/;
|
|
3
3
|
export const SANSA_MAX_POSITION_INDEX = 999_999;
|
|
4
4
|
export const SANSA_MAX_QUERY_INTEGER = Number.MAX_SAFE_INTEGER;
|
|
5
5
|
|
|
@@ -36,7 +36,7 @@ const VALUE_SEMANTICS_METADATA_CATEGORIES = [
|
|
|
36
36
|
'date',
|
|
37
37
|
'time',
|
|
38
38
|
'datetime',
|
|
39
|
-
'
|
|
39
|
+
'wtc',
|
|
40
40
|
'temporal',
|
|
41
41
|
'lexicalStructuredScalar',
|
|
42
42
|
'container',
|
|
@@ -1925,7 +1925,7 @@ function validateAeonTargetScalarValue(value, representation, path, operationInd
|
|
|
1925
1925
|
case 'date':
|
|
1926
1926
|
case 'time':
|
|
1927
1927
|
case 'datetime':
|
|
1928
|
-
case '
|
|
1928
|
+
case 'wtc':
|
|
1929
1929
|
return typeof value === 'string' && isQueryTemporalLiteral(value, representation)
|
|
1930
1930
|
? { ok: true }
|
|
1931
1931
|
: invalidAeonTargetValue(`${representation} literals must use valid AEON temporal text`, path, operationIndex);
|
|
@@ -2021,7 +2021,7 @@ function validateAeonSeparatorDatatypeSurface(datatype, base, operationIndex) {
|
|
|
2021
2021
|
),
|
|
2022
2022
|
};
|
|
2023
2023
|
}
|
|
2024
|
-
if (!/^(?:sep|separator)
|
|
2024
|
+
if (!/^(?:sep|separator)\[\s*"[A-Za-z0-9!#$%&*+\-.:;=?@^_|~<>]"\s*(?:,\s*"[A-Za-z0-9!#$%&*+\-.:;=?@^_|~<>]"\s*)*\]$/i.test(source)) {
|
|
2025
2025
|
return {
|
|
2026
2026
|
ok: false,
|
|
2027
2027
|
error: mutationTargetSurfaceError(
|
|
@@ -2115,7 +2115,7 @@ function isReservedAeonDatatypeBase(base) {
|
|
|
2115
2115
|
'date',
|
|
2116
2116
|
'time',
|
|
2117
2117
|
'datetime',
|
|
2118
|
-
'
|
|
2118
|
+
'wtc',
|
|
2119
2119
|
'sep',
|
|
2120
2120
|
'separator',
|
|
2121
2121
|
'kadot',
|
|
@@ -2334,7 +2334,7 @@ function representationKindFromMutationName(name, { allowUnknown = false } = {})
|
|
|
2334
2334
|
if (base === 'sep' || base === 'separator' || base === 'kadot') return 'separator';
|
|
2335
2335
|
if (base === 'sansa') return 'sansa';
|
|
2336
2336
|
if (base === 'encoding' || ['base64', 'embed', 'inline'].includes(base)) return 'encoding';
|
|
2337
|
-
if (['date', 'time', 'datetime', '
|
|
2337
|
+
if (['date', 'time', 'datetime', 'wtc'].includes(base)) return base;
|
|
2338
2338
|
if (['cloneReference', 'pointerReference', 'referenceForm'].includes(base)) return base;
|
|
2339
2339
|
return allowUnknown ? base : undefined;
|
|
2340
2340
|
}
|
|
@@ -2515,6 +2515,342 @@ export function resolveAddress(input, namespace, options = {}) {
|
|
|
2515
2515
|
return { ok: true, bindings: current, diagnostics: [] };
|
|
2516
2516
|
}
|
|
2517
2517
|
|
|
2518
|
+
export function traverseGraph(starts, namespace, declarations, options = {}) {
|
|
2519
|
+
const invalid = validateGraphInput(starts, namespace, declarations, options);
|
|
2520
|
+
if (invalid) return { ok: false, bindings: [], paths: [], errors: [invalid] };
|
|
2521
|
+
|
|
2522
|
+
const paths = [];
|
|
2523
|
+
const bindings = [];
|
|
2524
|
+
const bindingAddresses = new Set();
|
|
2525
|
+
let visitedEdges = 0;
|
|
2526
|
+
|
|
2527
|
+
for (const start of starts) {
|
|
2528
|
+
const startAddress = graphBindingAddress(start, namespace);
|
|
2529
|
+
if (!startAddress) {
|
|
2530
|
+
return graphFailure('SANSA_GRAPH_START_ADDRESS_MISSING', 'Graph start binding has no canonical address');
|
|
2531
|
+
}
|
|
2532
|
+
for (const declaration of declarations) {
|
|
2533
|
+
if (!declaration.schemaVersions.includes(options.schemaVersion)) {
|
|
2534
|
+
return graphFailure('SANSA_GRAPH_SCHEMA_VERSION_UNSUPPORTED', `Relationship '${declaration.id}' does not apply to schema version '${options.schemaVersion}'`, {
|
|
2535
|
+
declarationId: declaration.id,
|
|
2536
|
+
startAddress,
|
|
2537
|
+
});
|
|
2538
|
+
}
|
|
2539
|
+
const sourceSemanticType = graphBindingSemanticType(start, namespace);
|
|
2540
|
+
if (!declaration.sourceSemanticTypes.includes(sourceSemanticType)) {
|
|
2541
|
+
return graphFailure('SANSA_GRAPH_SOURCE_TYPE_MISMATCH', `Relationship '${declaration.id}' does not admit source semantic type '${sourceSemanticType || '<unknown>'}'`, {
|
|
2542
|
+
declarationId: declaration.id,
|
|
2543
|
+
startAddress,
|
|
2544
|
+
});
|
|
2545
|
+
}
|
|
2546
|
+
const edges = resolveAddress(declaration.edgeAddress, namespace, {
|
|
2547
|
+
contextualRoot: start,
|
|
2548
|
+
maxBindings: options.budget.maxVisitedEdges,
|
|
2549
|
+
});
|
|
2550
|
+
if (!edges.ok) return { ok: false, bindings: [], paths: [], errors: edges.errors };
|
|
2551
|
+
if (edges.bindings.length === 0 && declaration.missingEdge === 'error') {
|
|
2552
|
+
return graphFailure('SANSA_GRAPH_EDGE_MISSING', `Relationship '${declaration.id}' has no edge at '${declaration.edgeAddress}'`, {
|
|
2553
|
+
declarationId: declaration.id,
|
|
2554
|
+
startAddress,
|
|
2555
|
+
});
|
|
2556
|
+
}
|
|
2557
|
+
if (!graphCardinalityMatches(declaration.edgeCardinality, edges.bindings.length)) {
|
|
2558
|
+
return graphFailure('SANSA_GRAPH_EDGE_CARDINALITY_MISMATCH', `Relationship '${declaration.id}' edge cardinality '${declaration.edgeCardinality}' rejected ${edges.bindings.length} resolved edges`, {
|
|
2559
|
+
declarationId: declaration.id,
|
|
2560
|
+
startAddress,
|
|
2561
|
+
observed: edges.bindings.length,
|
|
2562
|
+
});
|
|
2563
|
+
}
|
|
2564
|
+
for (const edge of edges.bindings) {
|
|
2565
|
+
visitedEdges += 1;
|
|
2566
|
+
if (visitedEdges > options.budget.maxVisitedEdges) {
|
|
2567
|
+
return graphBudgetFailure('maxVisitedEdges', options.budget.maxVisitedEdges, visitedEdges);
|
|
2568
|
+
}
|
|
2569
|
+
const edgeAddress = graphBindingAddress(edge, namespace);
|
|
2570
|
+
if (!edgeAddress) {
|
|
2571
|
+
return graphFailure('SANSA_GRAPH_EDGE_ADDRESS_MISSING', 'Graph relationship edge has no canonical address', {
|
|
2572
|
+
declarationId: declaration.id,
|
|
2573
|
+
startAddress,
|
|
2574
|
+
});
|
|
2575
|
+
}
|
|
2576
|
+
const targetAddress = graphReferenceTarget(graphBindingValue(edge, namespace));
|
|
2577
|
+
if (!targetAddress) {
|
|
2578
|
+
return graphFailure('SANSA_GRAPH_INVALID_REFERENCE_TARGET', `Relationship edge '${edgeAddress}' does not contain an absolute SANSA address reference`, {
|
|
2579
|
+
declarationId: declaration.id,
|
|
2580
|
+
startAddress,
|
|
2581
|
+
edgeAddress,
|
|
2582
|
+
});
|
|
2583
|
+
}
|
|
2584
|
+
const target = resolveAddress(targetAddress, namespace, { maxBindings: 2 });
|
|
2585
|
+
if (!target.ok) return { ok: false, bindings: [], paths: [], errors: target.errors };
|
|
2586
|
+
if (target.bindings.length === 0) {
|
|
2587
|
+
if (declaration.danglingTarget === 'error') {
|
|
2588
|
+
return graphFailure('SANSA_GRAPH_DANGLING_TARGET', `Relationship edge '${edgeAddress}' targets missing binding '${targetAddress}'`, {
|
|
2589
|
+
declarationId: declaration.id,
|
|
2590
|
+
startAddress,
|
|
2591
|
+
edgeAddress,
|
|
2592
|
+
targetAddress,
|
|
2593
|
+
});
|
|
2594
|
+
}
|
|
2595
|
+
continue;
|
|
2596
|
+
}
|
|
2597
|
+
const end = target.bindings[0];
|
|
2598
|
+
const endAddress = graphBindingAddress(end, namespace);
|
|
2599
|
+
if (!endAddress) {
|
|
2600
|
+
return graphFailure('SANSA_GRAPH_END_ADDRESS_MISSING', 'Graph relationship target has no canonical address', {
|
|
2601
|
+
declarationId: declaration.id,
|
|
2602
|
+
startAddress,
|
|
2603
|
+
edgeAddress,
|
|
2604
|
+
targetAddress,
|
|
2605
|
+
});
|
|
2606
|
+
}
|
|
2607
|
+
const targetSemanticType = graphBindingSemanticType(end, namespace);
|
|
2608
|
+
if (!declaration.targetSemanticTypes.includes(targetSemanticType)) {
|
|
2609
|
+
return graphFailure('SANSA_GRAPH_TARGET_TYPE_MISMATCH', `Relationship '${declaration.id}' does not admit target semantic type '${targetSemanticType || '<unknown>'}'`, {
|
|
2610
|
+
declarationId: declaration.id,
|
|
2611
|
+
startAddress,
|
|
2612
|
+
edgeAddress,
|
|
2613
|
+
targetAddress,
|
|
2614
|
+
});
|
|
2615
|
+
}
|
|
2616
|
+
if (options.authorizeStep && options.authorizeStep({ start, edge, end, declaration }) !== true) {
|
|
2617
|
+
return graphFailure('SANSA_GRAPH_STEP_UNAUTHORIZED', `Traversal step through relationship '${declaration.id}' was not authorized`, {
|
|
2618
|
+
declarationId: declaration.id,
|
|
2619
|
+
startAddress,
|
|
2620
|
+
edgeAddress,
|
|
2621
|
+
targetAddress,
|
|
2622
|
+
});
|
|
2623
|
+
}
|
|
2624
|
+
paths.push({
|
|
2625
|
+
declarationId: declaration.id,
|
|
2626
|
+
start,
|
|
2627
|
+
startAddress,
|
|
2628
|
+
edge,
|
|
2629
|
+
edgeAddress,
|
|
2630
|
+
end,
|
|
2631
|
+
endAddress,
|
|
2632
|
+
});
|
|
2633
|
+
if (paths.length > options.budget.maxResults) {
|
|
2634
|
+
return graphBudgetFailure('maxResults', options.budget.maxResults, paths.length);
|
|
2635
|
+
}
|
|
2636
|
+
if (!bindingAddresses.has(endAddress)) {
|
|
2637
|
+
bindingAddresses.add(endAddress);
|
|
2638
|
+
bindings.push(end);
|
|
2639
|
+
if (bindings.length > options.budget.maxVisitedNodes) {
|
|
2640
|
+
return graphBudgetFailure('maxVisitedNodes', options.budget.maxVisitedNodes, bindings.length);
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
}
|
|
2646
|
+
|
|
2647
|
+
return {
|
|
2648
|
+
ok: true,
|
|
2649
|
+
bindings,
|
|
2650
|
+
paths,
|
|
2651
|
+
metrics: { visitedNodes: bindings.length, visitedEdges },
|
|
2652
|
+
diagnostics: [],
|
|
2653
|
+
};
|
|
2654
|
+
}
|
|
2655
|
+
|
|
2656
|
+
export function traverseGraphSequence(starts, namespace, hops, options = {}) {
|
|
2657
|
+
if (!Array.isArray(hops) || hops.length === 0 || !['omit', 'error'].includes(options.cyclePolicy)) {
|
|
2658
|
+
return graphFailure('SANSA_GRAPH_INVALID_INPUT', 'Graph sequence traversal requires one or more declaration hops and an explicit cycle policy');
|
|
2659
|
+
}
|
|
2660
|
+
if (!options.budget || !Number.isSafeInteger(options.budget.maxDepth) || options.budget.maxDepth < hops.length) {
|
|
2661
|
+
return graphBudgetFailure('maxDepth', options.budget?.maxDepth, hops.length);
|
|
2662
|
+
}
|
|
2663
|
+
if (!Array.isArray(starts) || starts.length > options.budget.maxStartBindings) {
|
|
2664
|
+
return graphBudgetFailure('maxStartBindings', options.budget.maxStartBindings, Array.isArray(starts) ? starts.length : undefined);
|
|
2665
|
+
}
|
|
2666
|
+
for (const declarations of hops) {
|
|
2667
|
+
const invalid = validateGraphInput(starts, namespace, declarations, options);
|
|
2668
|
+
if (invalid) return { ok: false, bindings: [], paths: [], errors: [invalid] };
|
|
2669
|
+
}
|
|
2670
|
+
|
|
2671
|
+
let frontier = [];
|
|
2672
|
+
for (const start of starts) {
|
|
2673
|
+
const startAddress = graphBindingAddress(start, namespace);
|
|
2674
|
+
if (!startAddress) return graphFailure('SANSA_GRAPH_START_ADDRESS_MISSING', 'Graph start binding has no canonical address');
|
|
2675
|
+
frontier.push({ start, startAddress, current: start, steps: [], seen: new Set([startAddress]) });
|
|
2676
|
+
}
|
|
2677
|
+
|
|
2678
|
+
const visitedNodeAddresses = new Set();
|
|
2679
|
+
let visitedEdges = 0;
|
|
2680
|
+
for (const declarations of hops) {
|
|
2681
|
+
const next = [];
|
|
2682
|
+
for (const path of frontier) {
|
|
2683
|
+
const traversed = traverseGraph([path.current], namespace, declarations, options);
|
|
2684
|
+
if (!traversed.ok) return traversed;
|
|
2685
|
+
visitedEdges += traversed.metrics.visitedEdges;
|
|
2686
|
+
if (visitedEdges > options.budget.maxVisitedEdges) {
|
|
2687
|
+
return graphBudgetFailure('maxVisitedEdges', options.budget.maxVisitedEdges, visitedEdges);
|
|
2688
|
+
}
|
|
2689
|
+
for (const step of traversed.paths) {
|
|
2690
|
+
if (path.seen.has(step.endAddress)) {
|
|
2691
|
+
if (options.cyclePolicy === 'error') {
|
|
2692
|
+
return graphFailure('SANSA_GRAPH_CYCLE_DETECTED', `Graph sequence revisited binding '${step.endAddress}'`, {
|
|
2693
|
+
declarationId: step.declarationId,
|
|
2694
|
+
startAddress: path.startAddress,
|
|
2695
|
+
edgeAddress: step.edgeAddress,
|
|
2696
|
+
targetAddress: step.endAddress,
|
|
2697
|
+
});
|
|
2698
|
+
}
|
|
2699
|
+
continue;
|
|
2700
|
+
}
|
|
2701
|
+
visitedNodeAddresses.add(step.endAddress);
|
|
2702
|
+
if (visitedNodeAddresses.size > options.budget.maxVisitedNodes) {
|
|
2703
|
+
return graphBudgetFailure('maxVisitedNodes', options.budget.maxVisitedNodes, visitedNodeAddresses.size);
|
|
2704
|
+
}
|
|
2705
|
+
next.push({
|
|
2706
|
+
...path,
|
|
2707
|
+
current: step.end,
|
|
2708
|
+
steps: [...path.steps, step],
|
|
2709
|
+
seen: new Set([...path.seen, step.endAddress]),
|
|
2710
|
+
});
|
|
2711
|
+
if (next.length > options.budget.maxResults) {
|
|
2712
|
+
return graphBudgetFailure('maxResults', options.budget.maxResults, next.length);
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2715
|
+
}
|
|
2716
|
+
frontier = next;
|
|
2717
|
+
if (frontier.length === 0) break;
|
|
2718
|
+
}
|
|
2719
|
+
|
|
2720
|
+
const bindings = [];
|
|
2721
|
+
const finalAddresses = new Set();
|
|
2722
|
+
const paths = frontier.map((path) => {
|
|
2723
|
+
const endAddress = graphBindingAddress(path.current, namespace);
|
|
2724
|
+
if (!finalAddresses.has(endAddress)) {
|
|
2725
|
+
finalAddresses.add(endAddress);
|
|
2726
|
+
bindings.push(path.current);
|
|
2727
|
+
}
|
|
2728
|
+
return {
|
|
2729
|
+
start: path.start,
|
|
2730
|
+
startAddress: path.startAddress,
|
|
2731
|
+
end: path.current,
|
|
2732
|
+
endAddress,
|
|
2733
|
+
steps: path.steps,
|
|
2734
|
+
};
|
|
2735
|
+
});
|
|
2736
|
+
return {
|
|
2737
|
+
ok: true,
|
|
2738
|
+
bindings,
|
|
2739
|
+
paths,
|
|
2740
|
+
metrics: { visitedNodes: visitedNodeAddresses.size, visitedEdges },
|
|
2741
|
+
diagnostics: [],
|
|
2742
|
+
};
|
|
2743
|
+
}
|
|
2744
|
+
|
|
2745
|
+
function validateGraphInput(starts, namespace, declarations, options) {
|
|
2746
|
+
if (!Array.isArray(starts) || !namespace || typeof namespace !== 'object' || !Array.isArray(declarations)) {
|
|
2747
|
+
return graphError('SANSA_GRAPH_INVALID_INPUT', 'Graph traversal requires start bindings, a namespace, and relationship declarations');
|
|
2748
|
+
}
|
|
2749
|
+
if (!options.budget || typeof options.budget !== 'object') {
|
|
2750
|
+
return graphError('SANSA_GRAPH_BUDGET_REQUIRED', 'Graph traversal requires an explicit budget');
|
|
2751
|
+
}
|
|
2752
|
+
if (typeof options.schemaVersion !== 'string' || options.schemaVersion.length === 0) {
|
|
2753
|
+
return graphError('SANSA_GRAPH_INVALID_INPUT', 'Graph traversal requires an explicit schema version');
|
|
2754
|
+
}
|
|
2755
|
+
for (const field of ['maxDepth', 'maxStartBindings', 'maxVisitedNodes', 'maxVisitedEdges', 'maxResults']) {
|
|
2756
|
+
const value = options.budget[field];
|
|
2757
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
2758
|
+
return graphError('SANSA_GRAPH_INVALID_BUDGET', `Graph budget '${field}' must be a non-negative safe integer`, { budget: field });
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
if (declarations.length > 0 && options.budget.maxDepth < 1) {
|
|
2762
|
+
return graphError('SANSA_GRAPH_BUDGET_EXCEEDED', 'Graph depth budget exceeded', {
|
|
2763
|
+
budget: 'maxDepth',
|
|
2764
|
+
limit: options.budget.maxDepth,
|
|
2765
|
+
observed: 1,
|
|
2766
|
+
});
|
|
2767
|
+
}
|
|
2768
|
+
if (starts.length > options.budget.maxStartBindings) {
|
|
2769
|
+
return graphError('SANSA_GRAPH_BUDGET_EXCEEDED', 'Graph start binding budget exceeded', {
|
|
2770
|
+
budget: 'maxStartBindings',
|
|
2771
|
+
limit: options.budget.maxStartBindings,
|
|
2772
|
+
observed: starts.length,
|
|
2773
|
+
});
|
|
2774
|
+
}
|
|
2775
|
+
const ids = new Set();
|
|
2776
|
+
for (const declaration of declarations) {
|
|
2777
|
+
if (!declaration || typeof declaration !== 'object'
|
|
2778
|
+
|| typeof declaration.id !== 'string' || declaration.id.length === 0
|
|
2779
|
+
|| declaration.direction !== 'directed'
|
|
2780
|
+
|| !isNonEmptyUniqueStringArray(declaration.schemaVersions)
|
|
2781
|
+
|| declaration.namespaceTransition !== 'same-namespace'
|
|
2782
|
+
|| declaration.referenceForm !== 'absolute-address-reference'
|
|
2783
|
+
|| !isNonEmptyUniqueStringArray(declaration.sourceSemanticTypes)
|
|
2784
|
+
|| !isNonEmptyUniqueStringArray(declaration.targetSemanticTypes)
|
|
2785
|
+
|| typeof declaration.edgeAddress !== 'string' || !declaration.edgeAddress.startsWith('?')
|
|
2786
|
+
|| !['zero-or-one', 'exactly-one', 'zero-or-more', 'one-or-more'].includes(declaration.edgeCardinality)
|
|
2787
|
+
|| (declaration.missingEdge !== 'omit' && declaration.missingEdge !== 'error')
|
|
2788
|
+
|| (declaration.danglingTarget !== 'omit' && declaration.danglingTarget !== 'error')) {
|
|
2789
|
+
return graphError('SANSA_GRAPH_INVALID_DECLARATION', 'Graph relationship declaration is invalid');
|
|
2790
|
+
}
|
|
2791
|
+
if (ids.has(declaration.id)) {
|
|
2792
|
+
return graphError('SANSA_GRAPH_DUPLICATE_DECLARATION', `Graph relationship declaration '${declaration.id}' is duplicated`, {
|
|
2793
|
+
declarationId: declaration.id,
|
|
2794
|
+
});
|
|
2795
|
+
}
|
|
2796
|
+
ids.add(declaration.id);
|
|
2797
|
+
}
|
|
2798
|
+
return null;
|
|
2799
|
+
}
|
|
2800
|
+
|
|
2801
|
+
function graphBindingAddress(binding, namespace) {
|
|
2802
|
+
if (typeof binding?.address === 'string') return binding.address;
|
|
2803
|
+
const handle = namespace.bindingHandle?.(binding);
|
|
2804
|
+
return typeof handle === 'string' ? handle : undefined;
|
|
2805
|
+
}
|
|
2806
|
+
|
|
2807
|
+
function graphBindingValue(binding, namespace) {
|
|
2808
|
+
return namespace.value ? namespace.value(binding) : binding?.value;
|
|
2809
|
+
}
|
|
2810
|
+
|
|
2811
|
+
function graphBindingSemanticType(binding, namespace) {
|
|
2812
|
+
const value = typeof namespace.semanticType === 'function'
|
|
2813
|
+
? namespace.semanticType(binding)
|
|
2814
|
+
: binding?.semanticType ?? binding?.datatype;
|
|
2815
|
+
return typeof value === 'string' ? value : '';
|
|
2816
|
+
}
|
|
2817
|
+
|
|
2818
|
+
function graphCardinalityMatches(cardinality, observed) {
|
|
2819
|
+
if (cardinality === 'zero-or-one') return observed <= 1;
|
|
2820
|
+
if (cardinality === 'exactly-one') return observed === 1;
|
|
2821
|
+
if (cardinality === 'one-or-more') return observed >= 1;
|
|
2822
|
+
return true;
|
|
2823
|
+
}
|
|
2824
|
+
|
|
2825
|
+
function isNonEmptyUniqueStringArray(value) {
|
|
2826
|
+
return Array.isArray(value)
|
|
2827
|
+
&& value.length > 0
|
|
2828
|
+
&& value.every((item) => typeof item === 'string' && item.length > 0)
|
|
2829
|
+
&& new Set(value).size === value.length;
|
|
2830
|
+
}
|
|
2831
|
+
|
|
2832
|
+
function graphReferenceTarget(value) {
|
|
2833
|
+
if (typeof value === 'string' && value.startsWith('$')) return value;
|
|
2834
|
+
if (!value || typeof value !== 'object') return undefined;
|
|
2835
|
+
if ((value.type === 'PointerReference' || value.type === 'CloneReference') && typeof value.target === 'string' && value.target.startsWith('$')) {
|
|
2836
|
+
return value.target;
|
|
2837
|
+
}
|
|
2838
|
+
if (value.type === 'StringLiteral' && typeof value.value === 'string' && value.value.startsWith('$')) return value.value;
|
|
2839
|
+
return undefined;
|
|
2840
|
+
}
|
|
2841
|
+
|
|
2842
|
+
function graphBudgetFailure(budget, limit, observed) {
|
|
2843
|
+
return graphFailure('SANSA_GRAPH_BUDGET_EXCEEDED', `Graph budget '${budget}' exceeded`, { budget, limit, observed });
|
|
2844
|
+
}
|
|
2845
|
+
|
|
2846
|
+
function graphFailure(code, message, details = {}) {
|
|
2847
|
+
return { ok: false, bindings: [], paths: [], errors: [graphError(code, message, details)] };
|
|
2848
|
+
}
|
|
2849
|
+
|
|
2850
|
+
function graphError(code, message, details = {}) {
|
|
2851
|
+
return { code, message, ...details };
|
|
2852
|
+
}
|
|
2853
|
+
|
|
2518
2854
|
export function renderAddress(address) {
|
|
2519
2855
|
let output = address.root.kind === 'absolute' ? '$' : '?';
|
|
2520
2856
|
|
|
@@ -4135,7 +4471,7 @@ function queryLiteralMetadata(expression) {
|
|
|
4135
4471
|
case 'date':
|
|
4136
4472
|
case 'time':
|
|
4137
4473
|
case 'datetime':
|
|
4138
|
-
case '
|
|
4474
|
+
case 'wtc':
|
|
4139
4475
|
return { kind: expression.kind, category: 'temporal', semanticType: expression.kind };
|
|
4140
4476
|
case 'null':
|
|
4141
4477
|
return { kind: 'null', category: 'explicitNull', nullReason: expression.nullReason };
|
|
@@ -4867,7 +5203,7 @@ function compareMinimumOrdering(left, right, profile) {
|
|
|
4867
5203
|
function normalizeValueSemanticsCategory(category) {
|
|
4868
5204
|
if (category === 'sansa') return 'sansaAddress';
|
|
4869
5205
|
if (category === 'cloneReference' || category === 'pointerReference') return 'referenceForm';
|
|
4870
|
-
if (['date', 'time', 'datetime', '
|
|
5206
|
+
if (['date', 'time', 'datetime', 'wtc'].includes(category)) return 'temporal';
|
|
4871
5207
|
return category;
|
|
4872
5208
|
}
|
|
4873
5209
|
|
|
@@ -5526,14 +5862,15 @@ export function renderQualifierTerm(term) {
|
|
|
5526
5862
|
for (const group of parameterGroups) {
|
|
5527
5863
|
output += `<${group.map(renderQualifierTerm).join(',')}>`;
|
|
5528
5864
|
}
|
|
5529
|
-
|
|
5530
|
-
output += `[${renderQualifierArgument(
|
|
5865
|
+
if (term.arguments.length > 0) {
|
|
5866
|
+
output += `[${term.arguments.map(renderQualifierArgument).join(',')}]`;
|
|
5531
5867
|
}
|
|
5532
5868
|
return output;
|
|
5533
5869
|
}
|
|
5534
5870
|
|
|
5535
5871
|
function renderQualifierArgument(argument) {
|
|
5536
5872
|
if (argument.kind === 'token') return argument.value;
|
|
5873
|
+
if (argument.kind === 'number') return String(argument.value);
|
|
5537
5874
|
return quotePayload(argument.value);
|
|
5538
5875
|
}
|
|
5539
5876
|
|
|
@@ -5712,9 +6049,15 @@ class AddressParser {
|
|
|
5712
6049
|
parameters.push(...group);
|
|
5713
6050
|
}
|
|
5714
6051
|
|
|
5715
|
-
|
|
6052
|
+
if (this.match('[')) {
|
|
5716
6053
|
args.push(this.parseQualifierArgument());
|
|
6054
|
+
while (this.match(',')) {
|
|
6055
|
+
args.push(this.parseQualifierArgument());
|
|
6056
|
+
}
|
|
5717
6057
|
this.consume(']');
|
|
6058
|
+
if (this.peek() === '[') {
|
|
6059
|
+
this.fail('Qualifier clarifiers must use a single bracketed list', 'SANSA_INVALID_QUALIFIER');
|
|
6060
|
+
}
|
|
5718
6061
|
}
|
|
5719
6062
|
|
|
5720
6063
|
const next = this.peek();
|
|
@@ -5731,17 +6074,13 @@ class AddressParser {
|
|
|
5731
6074
|
}
|
|
5732
6075
|
|
|
5733
6076
|
const start = this.index;
|
|
5734
|
-
while (!this.atEnd() && this.peek() !== ']') {
|
|
5735
|
-
const char = this.peek();
|
|
5736
|
-
if (!isQualifierArgumentChar(char)) {
|
|
5737
|
-
this.fail(`Invalid unquoted qualifier argument character '${char}'`, 'SANSA_INVALID_QUALIFIER_ARGUMENT_CHAR');
|
|
5738
|
-
}
|
|
6077
|
+
while (!this.atEnd() && this.peek() !== ']' && this.peek() !== ',') {
|
|
5739
6078
|
this.index += 1;
|
|
5740
6079
|
}
|
|
5741
6080
|
if (this.index === start) this.fail('Expected qualifier argument', 'SANSA_EXPECTED_QUALIFIER_ARGUMENT');
|
|
5742
6081
|
const value = this.input.slice(start, this.index);
|
|
5743
|
-
if (!
|
|
5744
|
-
return { kind: '
|
|
6082
|
+
if (!QUALIFIER_NUMBER_RE.test(value)) this.fail('Invalid qualifier argument', 'SANSA_INVALID_QUALIFIER_ARGUMENT');
|
|
6083
|
+
return { kind: 'number', value: Number(value) };
|
|
5745
6084
|
}
|
|
5746
6085
|
|
|
5747
6086
|
parseIdentifier(context) {
|
|
@@ -6840,7 +7179,7 @@ class QueryExpressionParser {
|
|
|
6840
7179
|
const source = this.readSimpleLiteralPayload();
|
|
6841
7180
|
const kind = source.includes('T')
|
|
6842
7181
|
? source.includes('&')
|
|
6843
|
-
? '
|
|
7182
|
+
? 'wtc'
|
|
6844
7183
|
: 'datetime'
|
|
6845
7184
|
: source.includes(':')
|
|
6846
7185
|
? 'time'
|
|
@@ -7721,7 +8060,7 @@ function isQueryTemporalLiteral(source, kind) {
|
|
|
7721
8060
|
&& isValidDateParts(match[1], match[2], match[3])
|
|
7722
8061
|
&& isValidTimeMatch(match, 4);
|
|
7723
8062
|
}
|
|
7724
|
-
if (kind === '
|
|
8063
|
+
if (kind === 'wtc') {
|
|
7725
8064
|
const match = new RegExp(`^${date}T${datetimeTime}&(${zone})$`).exec(source);
|
|
7726
8065
|
return Boolean(match)
|
|
7727
8066
|
&& isValidDateParts(match[1], match[2], match[3])
|
|
@@ -41,11 +41,11 @@ $.result:number|nan
|
|
|
41
41
|
---
|
|
42
42
|
$.inventory:list<string>
|
|
43
43
|
---
|
|
44
|
-
$.version:sep[.]
|
|
44
|
+
$.version:sep["."]
|
|
45
45
|
---
|
|
46
46
|
$.inventory:csv[","]
|
|
47
47
|
---
|
|
48
|
-
$.claim:type<type>[arg]
|
|
48
|
+
$.claim:type<type>["arg"]
|
|
49
49
|
---
|
|
50
50
|
$#record%object
|
|
51
51
|
---
|
|
@@ -61,7 +61,7 @@ $:document<invoice>
|
|
|
61
61
|
---
|
|
62
62
|
$.["list"][2]:rule["+"]
|
|
63
63
|
---
|
|
64
|
-
$.key:string[","
|
|
64
|
+
$.key:string[",","."]
|
|
65
65
|
---
|
|
66
66
|
$.["list"][2][2]
|
|
67
67
|
---
|
|
@@ -666,7 +666,7 @@ function validateAeonWorkbenchScalarValue(value, representation, path) {
|
|
|
666
666
|
case 'date':
|
|
667
667
|
case 'time':
|
|
668
668
|
case 'datetime':
|
|
669
|
-
case '
|
|
669
|
+
case 'wtc':
|
|
670
670
|
return typeof value === 'string' && value.length > 0
|
|
671
671
|
? { ok: true }
|
|
672
672
|
: invalidAeonWorkbenchValue(`${representation} literals must be non-empty text`, path);
|
|
@@ -1110,7 +1110,7 @@ function renderScalarValue(binding) {
|
|
|
1110
1110
|
if (kind === 'radix') return `%${value}`;
|
|
1111
1111
|
if (kind === 'encoding') return `&${value}`;
|
|
1112
1112
|
if (kind === 'separator') return `^${value}`;
|
|
1113
|
-
if (['date', 'time', 'datetime', '
|
|
1113
|
+
if (['date', 'time', 'datetime', 'wtc'].includes(kind)) return String(value);
|
|
1114
1114
|
if (kind === 'sansaAddress' || kind === 'sansa') {
|
|
1115
1115
|
return value?.canonical ?? value?.address?.canonical ?? value?.address ?? String(value);
|
|
1116
1116
|
}
|
|
@@ -1240,7 +1240,7 @@ function semanticTypeFromRepresentationKind(kind) {
|
|
|
1240
1240
|
case 'date':
|
|
1241
1241
|
case 'time':
|
|
1242
1242
|
case 'datetime':
|
|
1243
|
-
case '
|
|
1243
|
+
case 'wtc':
|
|
1244
1244
|
case 'null':
|
|
1245
1245
|
case 'nan':
|
|
1246
1246
|
case 'infinity':
|
|
@@ -1278,7 +1278,7 @@ function representationKindFromName(name, { allowUnknown = false } = {}) {
|
|
|
1278
1278
|
if (base === 'sep' || base === 'separator' || base === 'kadot') return 'separator';
|
|
1279
1279
|
if (base === 'sansa') return 'sansa';
|
|
1280
1280
|
if (base === 'encoding' || ['base64', 'embed', 'inline'].includes(base)) return 'encoding';
|
|
1281
|
-
if (['date', 'time', 'datetime', '
|
|
1281
|
+
if (['date', 'time', 'datetime', 'wtc'].includes(base)) return base;
|
|
1282
1282
|
if (['cloneReference', 'pointerReference', 'referenceForm'].includes(base)) return base;
|
|
1283
1283
|
return allowUnknown ? base : undefined;
|
|
1284
1284
|
}
|
|
@@ -604,7 +604,7 @@ function scalarKindFromValue(value, semanticType) {
|
|
|
604
604
|
|
|
605
605
|
function temporalKindFromSemanticType(semanticType) {
|
|
606
606
|
const base = typeof semanticType === 'string' ? semanticType.split(/[<\[]/, 1)[0] : undefined;
|
|
607
|
-
return ['date', 'time', 'datetime', '
|
|
607
|
+
return ['date', 'time', 'datetime', 'wtc'].includes(base) ? base : 'datetime';
|
|
608
608
|
}
|
|
609
609
|
|
|
610
610
|
function referenceFormValue(type, path) {
|
|
@@ -714,7 +714,7 @@ function renderAeonValue(value, metadata, fieldMetadata) {
|
|
|
714
714
|
if (metadata?.kind === 'radix') return `%${value}`;
|
|
715
715
|
if (metadata?.kind === 'encoding') return `&${value}`;
|
|
716
716
|
if (metadata?.kind === 'separator') return `^${value}`;
|
|
717
|
-
if (['date', 'time', 'datetime', '
|
|
717
|
+
if (['date', 'time', 'datetime', 'wtc'].includes(metadata?.kind)) return String(value);
|
|
718
718
|
if (metadata?.kind === 'sansaAddress' || metadata?.kind === 'sansa') {
|
|
719
719
|
return value?.canonical ?? value?.address?.canonical ?? value?.address ?? String(value);
|
|
720
720
|
}
|