@altopelago/sansa 0.14.2 → 0.15.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +118 -1
- package/README.md +96 -1
- package/conformance/README.md +8 -0
- package/conformance/aeonic-anchor-claims.json +133 -0
- package/conformance/aeonic-arithmetic-claims.json +60 -0
- package/conformance/aeonic-clock-claims.json +123 -0
- package/conformance/aeonic-comparison-claims.json +37 -0
- package/conformance/aeonic-datetime-claims.json +110 -0
- package/conformance/aeonic-rational-arithmetic-claims.json +72 -0
- package/conformance/aeonic-temporal-claims.json +105 -0
- package/conformance/cts-claims.json +17 -3
- package/conformance/results/aeonic-anchor-capacity.json +452 -0
- package/conformance/results/aeonic-anchor-snapshot-0.1.json +39 -0
- package/conformance/results/aeonic-arithmetic-snapshot-0.1.json +28 -0
- package/conformance/results/aeonic-clock-all-snapshot-0.1.json +49 -0
- package/conformance/results/aeonic-clock-arithmetic-snapshot-0.1.json +48 -0
- package/conformance/results/aeonic-clock-capacity.json +326 -0
- package/conformance/results/aeonic-clock-relations-snapshot-0.1.json +48 -0
- package/conformance/results/aeonic-comparison-snapshot-0.1.json +19 -0
- package/conformance/results/aeonic-datetime-all-snapshot-0.1.json +47 -0
- package/conformance/results/aeonic-datetime-arithmetic-snapshot-0.1.json +46 -0
- package/conformance/results/aeonic-datetime-capacity.json +302 -0
- package/conformance/results/aeonic-datetime-relations-snapshot-0.1.json +46 -0
- package/conformance/results/aeonic-rational-arithmetic-capacity.json +100 -0
- package/conformance/results/aeonic-rational-arithmetic-snapshot-0.2.json +30 -0
- package/conformance/results/aeonic-temporal-all-property-addressing-2026-11-16.json +39 -0
- package/conformance/results/aeonic-temporal-all-snapshot-0.1.json +39 -0
- package/conformance/results/aeonic-temporal-calendar-property-addressing-2026-11-16.json +38 -0
- package/conformance/results/aeonic-temporal-calendar-snapshot-0.1.json +38 -0
- package/conformance/results/aeonic-temporal-capacity-property-addressing-2026-11-16.json +136 -0
- package/conformance/results/aeonic-temporal-capacity.json +136 -0
- package/conformance/results/aeonic-temporal-relations-property-addressing-2026-11-16.json +38 -0
- package/conformance/results/aeonic-temporal-relations-snapshot-0.1.json +38 -0
- package/docs/aeonic-arithmetic.md +126 -0
- package/docs/aeonic-comparison.md +123 -0
- package/docs/aeonic-rational-arithmetic.md +167 -0
- package/docs/aeonic-temporal-civil-anchor.md +89 -0
- package/docs/aeonic-temporal-civil-clock.md +100 -0
- package/docs/aeonic-temporal-civil-date.md +124 -0
- package/docs/aeonic-temporal-civil-datetime.md +122 -0
- package/docs/api-contract.md +130 -3
- package/docs/capabilities.json +106 -2
- package/docs/child-identity-activation.md +93 -0
- package/docs/child-identity-candidate.md +60 -0
- package/docs/child-identity-tooling.md +31 -0
- package/docs/child-identity-workflows.md +102 -0
- package/docs/empty-keys-candidate.md +29 -0
- package/docs/migration-0.15.0.md +75 -0
- package/docs/property-addressing-implementation.md +118 -0
- package/docs/property-resolve-implementation.md +105 -0
- package/docs/property-selector-support.md +65 -0
- package/docs/property-selectors-api.d.ts +43 -0
- package/docs/property-selectors-api.pyi +27 -0
- package/docs/property-selectors-api.rs +48 -0
- package/docs/property-selectors-contract.md +168 -0
- package/docs/query-tool.md +32 -1
- package/docs/selector-cursor.md +45 -0
- package/docs/unicode-hardening.md +41 -0
- package/fixtures/address-v1.json +4 -3
- package/fixtures/child-identity-workflows/README.md +9 -0
- package/fixtures/child-identity-workflows/moved.aeon +10 -0
- package/fixtures/child-identity-workflows/original.aeon +10 -0
- package/fixtures/child-identity-workflows/reordered.aeon +10 -0
- package/fixtures/child-identity-workflows/replacement.aeon +10 -0
- package/fixtures/child-identity-workflows/workflows.json +89 -0
- package/fixtures/property-namespace-candidate-v1.json +336 -0
- package/fixtures/property-parser-candidate-v1.json +705 -0
- package/fixtures/property-query-candidate-v1.json +398 -0
- package/fixtures/property-resolve-candidate-v1.json +2702 -0
- package/fixtures/unicode-hardening-v1.json +401 -0
- package/package.json +30 -3
- package/scripts/calibrate-aeonic-anchor-capacity.py +294 -0
- package/scripts/calibrate-aeonic-clock-capacity.py +62 -0
- package/scripts/calibrate-aeonic-datetime-capacity.py +76 -0
- package/scripts/calibrate-aeonic-rational-capacity.py +85 -0
- package/scripts/calibrate-aeonic-temporal-capacity.py +95 -0
- package/scripts/cts-address.mjs +6 -2
- package/scripts/cts-aeonic-anchor.mjs +21 -0
- package/scripts/cts-aeonic-arithmetic-adapter.mjs +25 -0
- package/scripts/cts-aeonic-arithmetic.mjs +24 -0
- package/scripts/cts-aeonic-clock.mjs +24 -0
- package/scripts/cts-aeonic-comparison-adapter.mjs +30 -0
- package/scripts/cts-aeonic-comparison.mjs +25 -0
- package/scripts/cts-aeonic-datetime.mjs +24 -0
- package/scripts/cts-aeonic-rational-arithmetic-adapter.mjs +25 -0
- package/scripts/cts-aeonic-rational-arithmetic.mjs +24 -0
- package/scripts/cts-aeonic-temporal-civil-anchor-adapter.mjs +26 -0
- package/scripts/cts-aeonic-temporal-civil-clock-adapter.mjs +28 -0
- package/scripts/cts-aeonic-temporal-civil-date-adapter.mjs +28 -0
- package/scripts/cts-aeonic-temporal-civil-datetime-adapter.mjs +28 -0
- package/scripts/cts-aeonic-temporal.mjs +24 -0
- package/scripts/cts-instruction.mjs +4 -2
- package/scripts/cts-mutate.mjs +3 -2
- package/scripts/cts-resolve.mjs +17 -2
- package/scripts/playground.mjs +110 -0
- package/src/aeonic-arithmetic-binding.js +61 -0
- package/src/aeonic-arithmetic.d.ts +84 -0
- package/src/aeonic-arithmetic.js +276 -0
- package/src/aeonic-comparison.d.ts +86 -0
- package/src/aeonic-comparison.js +274 -0
- package/src/aeonic-convenience.d.ts +30 -0
- package/src/aeonic-convenience.js +45 -0
- package/src/aeonic-exact-number.js +34 -0
- package/src/aeonic-json.js +45 -0
- package/src/aeonic-rational-arithmetic.d.ts +86 -0
- package/src/aeonic-rational-arithmetic.js +417 -0
- package/src/aeonic-rational-json.js +51 -0
- package/src/aeonic-temporal-civil-anchor.d.ts +54 -0
- package/src/aeonic-temporal-civil-anchor.js +316 -0
- package/src/aeonic-temporal-civil-clock.d.ts +124 -0
- package/src/aeonic-temporal-civil-clock.js +388 -0
- package/src/aeonic-temporal-civil-date.d.ts +123 -0
- package/src/aeonic-temporal-civil-date.js +310 -0
- package/src/aeonic-temporal-civil-datetime.d.ts +138 -0
- package/src/aeonic-temporal-civil-datetime.js +501 -0
- package/src/index.d.ts +84 -1
- package/src/index.js +828 -183
- package/src/property-address.js +196 -0
- package/src/property-resolve.js +132 -0
- package/src/query-metadata.d.ts +16 -0
- package/src/query-metadata.js +25 -0
- package/src/selector-cursor.d.ts +19 -0
- package/src/selector-cursor.js +79 -0
- package/stress-tests/address/invalid.sansa-cases +0 -2
- package/stress-tests/address/valid.sansa-cases +3 -0
- package/tools/mutate-web/examples.mjs +1 -1
- package/tools/mutate-web/runtime.mjs +0 -2
- package/tools/playground/README.md +165 -0
- package/tools/playground/accessibility.js +91 -0
- package/tools/playground/aeon-highlight.js +77 -0
- package/tools/playground/aeon-source-composer.js +1077 -0
- package/tools/playground/anchor-examples.mjs +16 -0
- package/tools/playground/arithmetic-evaluator.mjs +28 -0
- package/tools/playground/arithmetic-model.mjs +187 -0
- package/tools/playground/arithmetic-worker.mjs +14 -0
- package/tools/playground/arithmetic.css +1 -0
- package/tools/playground/arithmetic.html +29 -0
- package/tools/playground/arithmetic.mjs +110 -0
- package/tools/playground/clock-examples.mjs +16 -0
- package/tools/playground/datetime-examples.mjs +22 -0
- package/tools/playground/examples.mjs +46 -0
- package/tools/playground/index.html +174 -0
- package/tools/playground/local.css +25 -0
- package/tools/playground/namespace.mjs +39 -0
- package/tools/playground/sansa-playground.js +1565 -0
- package/tools/playground/site.css +3914 -0
- package/tools/playground/temporal-examples.mjs +20 -0
- package/tools/playground/walkthrough.js +90 -0
- package/tools/playground/website-origin.json +16 -0
- package/tools/query-web/IDENTITY_SELECTORS.md +44 -0
- package/tools/query-web/app.js +4 -0
- package/tools/query-web/index.html +4 -0
- package/tools/query-web/runtime.mjs +70 -19
- package/tools/workflows/property-playground-assertions.mjs +33 -0
- package/tools/workflows/verify-child-identities.mjs +137 -0
- package/tools/workflows/verify-property-playground.mjs +48 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// Internal preparation support. Recognition/rendering do not authorize execution.
|
|
2
|
+
const MAX_SELECTORS = 256;
|
|
3
|
+
const MAX_PAYLOAD = 4096;
|
|
4
|
+
const MAX_CANONICAL = 65536;
|
|
5
|
+
const IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
6
|
+
const IDENTITY = /^[A-Za-z0-9_-]+$/;
|
|
7
|
+
const NUMBER = /^[+-]?(?:(?:0|[1-9][0-9]*)(?:\.[0-9]+)?|\.[0-9]+)$/;
|
|
8
|
+
|
|
9
|
+
export class PropertyAddressError extends Error {
|
|
10
|
+
constructor(message, code = 'SANSA_RESOLVE_INVALID_ADDRESS', details = {}) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.code = code;
|
|
13
|
+
Object.assign(this, details);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export function propertyLimit(limitKind, limit) {
|
|
17
|
+
throw new PropertyAddressError('Property address preparation bound exceeded', 'SANSA_PROPERTY_LIMIT_EXCEEDED', {limitKind, limit, observed: limit + 1});
|
|
18
|
+
}
|
|
19
|
+
// Only unquoted suffix syntax before qualifiers is a property candidate.
|
|
20
|
+
export function hasPropertySyntax(source) {
|
|
21
|
+
if (!source.includes('&')) return false;
|
|
22
|
+
let quoted = false;
|
|
23
|
+
for (let i = 0; i < source.length; i++) {
|
|
24
|
+
const ch = source[i];
|
|
25
|
+
if (quoted && ch === '\\') { i++; continue; }
|
|
26
|
+
if (ch === '"') { quoted = !quoted; continue; }
|
|
27
|
+
if (!quoted && ch === ':') return false;
|
|
28
|
+
if (!quoted && ch === '&') return true;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
export function data(object, key, optional = false) {
|
|
33
|
+
if (!object || typeof object !== 'object') throw new PropertyAddressError('Expected plain address data');
|
|
34
|
+
const prototype = Object.getPrototypeOf(object);
|
|
35
|
+
if (prototype !== Object.prototype && prototype !== null && !Array.isArray(object)) throw new PropertyAddressError('Expected plain address data');
|
|
36
|
+
const descriptor = Object.getOwnPropertyDescriptor(object, key);
|
|
37
|
+
if (!descriptor && optional) return undefined;
|
|
38
|
+
if (!descriptor || !('value' in descriptor)) throw new PropertyAddressError('Address data must not contain accessors');
|
|
39
|
+
return descriptor.value;
|
|
40
|
+
}
|
|
41
|
+
function array(value) {
|
|
42
|
+
if (!Array.isArray(value)) throw new PropertyAddressError('Expected address array');
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
export function hasPropertyAst(address) {
|
|
46
|
+
const selectors = data(address, 'selectors', true);
|
|
47
|
+
if (!Array.isArray(selectors)) return false;
|
|
48
|
+
for (let i = 0; i < selectors.length; i++) {
|
|
49
|
+
const selector = data(selectors, String(i));
|
|
50
|
+
if (data(selector, 'type') === 'propertyFilter') return true;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
function scalarCount(value, limit, kind) {
|
|
55
|
+
if (typeof value !== 'string') throw new PropertyAddressError('Expected address string');
|
|
56
|
+
let count = 0;
|
|
57
|
+
for (const ch of value) {
|
|
58
|
+
const code = ch.codePointAt(0);
|
|
59
|
+
if (code >= 0xd800 && code <= 0xdfff) throw new PropertyAddressError('Invalid Unicode scalar', 'SANSA_INVALID_UNICODE_SCALAR');
|
|
60
|
+
if (++count > limit) propertyLimit(kind, limit);
|
|
61
|
+
}
|
|
62
|
+
return value;
|
|
63
|
+
}
|
|
64
|
+
// Bounded, iterative canonical rendering of plain caller data. Ignore caller flags.
|
|
65
|
+
export function renderPropertyAddress(address, quote, number) {
|
|
66
|
+
if (data(address, 'type') !== 'SansaAddress') throw new PropertyAddressError('Invalid address type');
|
|
67
|
+
const root = data(address, 'root');
|
|
68
|
+
if (data(root, 'type') !== 'root' || !['absolute', 'contextual'].includes(data(root, 'kind'))) throw new PropertyAddressError('Invalid root');
|
|
69
|
+
const selectors = array(data(address, 'selectors'));
|
|
70
|
+
if (selectors.length > MAX_SELECTORS) propertyLimit('selectors', MAX_SELECTORS);
|
|
71
|
+
let output = '';
|
|
72
|
+
let length = 0;
|
|
73
|
+
const emit = value => {
|
|
74
|
+
for (const ch of scalarCount(value, MAX_CANONICAL, 'canonicalScalars')) {
|
|
75
|
+
if (++length > MAX_CANONICAL) propertyLimit('canonicalScalars', MAX_CANONICAL);
|
|
76
|
+
output += ch;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const text = (object, field) => scalarCount(data(object, field), MAX_CANONICAL, 'canonicalScalars');
|
|
80
|
+
const identifier = value => { if (!IDENTIFIER.test(value)) throw new PropertyAddressError('Invalid identifier'); return value; };
|
|
81
|
+
const position = value => { if (!Number.isSafeInteger(value) || value < 0) throw new PropertyAddressError('Invalid position'); return String(value); };
|
|
82
|
+
const quoted = value => quote(scalarCount(value, MAX_CANONICAL, 'canonicalScalars'));
|
|
83
|
+
emit(data(root, 'kind') === 'absolute' ? '$' : '?');
|
|
84
|
+
for (let i = 0; i < selectors.length; i++) {
|
|
85
|
+
const s = data(selectors, String(i));
|
|
86
|
+
switch (data(s, 'type')) {
|
|
87
|
+
case 'member': {
|
|
88
|
+
const name = text(s, 'name');
|
|
89
|
+
emit(IDENTIFIER.test(name) ? '.' + name : '.[' + quoted(name) + ']'); break;
|
|
90
|
+
}
|
|
91
|
+
case 'childIdentity': {
|
|
92
|
+
const identity = text(s, 'identity');
|
|
93
|
+
if (!IDENTITY.test(identity)) throw new PropertyAddressError('Invalid identity');
|
|
94
|
+
emit('.\\' + identity + '\\'); break;
|
|
95
|
+
}
|
|
96
|
+
case 'position': emit('[' + position(data(s, 'index')) + ']'); break;
|
|
97
|
+
case 'positionRange': {
|
|
98
|
+
const start = data(s, 'start'), end = data(s, 'end');
|
|
99
|
+
if (start == null && end == null) throw new PropertyAddressError('Empty range');
|
|
100
|
+
emit('[' + (start == null ? '' : position(start)) + '..' + (end == null ? '' : position(end)) + ']'); break;
|
|
101
|
+
}
|
|
102
|
+
case 'parent': emit('.^'); break;
|
|
103
|
+
case 'attributeSpace': emit('.@'); break;
|
|
104
|
+
case 'directExpansion': emit('.*'); break;
|
|
105
|
+
case 'descendantExpansion': emit('.**'); break;
|
|
106
|
+
case 'localSpace': { const name = text(s, 'name'); if (!name) throw new PropertyAddressError('Empty local space'); emit('.<' + quoted(name) + '>'); break; }
|
|
107
|
+
case 'namePattern': emit('.(' + quoted(text(s, 'pattern')) + ')'); break;
|
|
108
|
+
case 'semanticTypeFilter': emit('#' + identifier(text(s, 'name'))); break;
|
|
109
|
+
case 'representationKindFilter': emit('%' + identifier(text(s, 'name'))); break;
|
|
110
|
+
case 'propertyFilter': {
|
|
111
|
+
const property = data(s, 'property');
|
|
112
|
+
if (!['key', 'tag', 'headTag'].includes(property)) throw new PropertyAddressError('Unknown property');
|
|
113
|
+
emit('&' + property + '(' + quoted(scalarCount(data(s, 'value'), MAX_PAYLOAD, 'payloadScalars')) + ')'); break;
|
|
114
|
+
}
|
|
115
|
+
default: throw new PropertyAddressError('Unknown selector');
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const qualifier = data(address, 'qualifierExpression', true);
|
|
119
|
+
if (qualifier) {
|
|
120
|
+
if (data(qualifier, 'type') !== 'QualifierExpression') throw new PropertyAddressError('Invalid qualifier type');
|
|
121
|
+
const terms = array(data(qualifier, 'terms'));
|
|
122
|
+
if (!terms.length) throw new PropertyAddressError('Empty qualifier');
|
|
123
|
+
emit(':');
|
|
124
|
+
const stack = [], ancestors = new Set();
|
|
125
|
+
const pushList = (items, separator, kind) => {
|
|
126
|
+
if (stack.length + items.length * 2 > MAX_CANONICAL) propertyLimit('canonicalScalars', MAX_CANONICAL);
|
|
127
|
+
for (let i = items.length - 1; i >= 0; i--) {
|
|
128
|
+
stack.push([kind, data(items, String(i))]);
|
|
129
|
+
if (i) stack.push(['text', separator]);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
pushList(terms, '|', 'term');
|
|
133
|
+
while (stack.length) {
|
|
134
|
+
if (stack.length > MAX_CANONICAL) propertyLimit('canonicalScalars', MAX_CANONICAL);
|
|
135
|
+
const [kind, item] = stack.pop();
|
|
136
|
+
if (kind === 'text') { emit(item); continue; }
|
|
137
|
+
if (kind === 'leave') { ancestors.delete(item); continue; }
|
|
138
|
+
if (kind === 'argument') {
|
|
139
|
+
const type = data(item, 'kind'), value = data(item, 'value');
|
|
140
|
+
if (type === 'quoted') emit(quoted(value));
|
|
141
|
+
else if (type === 'number' && typeof value === 'number' && Number.isFinite(value)) emit(number(value));
|
|
142
|
+
else if (type === 'token' && NUMBER.test(scalarCount(value, MAX_CANONICAL, 'canonicalScalars'))) emit(value);
|
|
143
|
+
else throw new PropertyAddressError('Invalid qualifier argument');
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (data(item, 'type') !== 'QualifierTerm') throw new PropertyAddressError('Invalid qualifier term');
|
|
147
|
+
if (ancestors.has(item)) throw new PropertyAddressError('Cyclic qualifier');
|
|
148
|
+
ancestors.add(item); stack.push(['leave', item]);
|
|
149
|
+
emit(identifier(text(item, 'name')));
|
|
150
|
+
const args = array(data(item, 'arguments'));
|
|
151
|
+
if (args.length) { stack.push(['text', ']']); pushList(args, ',', 'argument'); stack.push(['text', '[']); }
|
|
152
|
+
let groups = data(item, 'parameterGroups', true);
|
|
153
|
+
if (groups === undefined) { const parameters = array(data(item, 'parameters')); groups = parameters.length ? [parameters] : []; }
|
|
154
|
+
array(groups);
|
|
155
|
+
if (groups.length > MAX_CANONICAL) propertyLimit('canonicalScalars', MAX_CANONICAL);
|
|
156
|
+
for (let i = groups.length - 1; i >= 0; i--) {
|
|
157
|
+
const group = array(data(groups, String(i)));
|
|
158
|
+
if (!group.length) throw new PropertyAddressError('Empty qualifier group');
|
|
159
|
+
stack.push(['text', '>']); pushList(group, ',', 'term'); stack.push(['text', '<']);
|
|
160
|
+
if (stack.length > MAX_CANONICAL) propertyLimit('canonicalScalars', MAX_CANONICAL);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return output;
|
|
165
|
+
}
|
|
166
|
+
// The existing cursor decodes payloads. Only nested control flow changes here.
|
|
167
|
+
export function parsePropertyQualifiers(cursor) {
|
|
168
|
+
const terms = [];
|
|
169
|
+
const makeTerm = () => ({type:'QualifierTerm', name:cursor.parseIdentifier('qualifier type name'), parameters:[], parameterGroups:[], arguments:[]});
|
|
170
|
+
let term = makeTerm(); terms.push(term);
|
|
171
|
+
const stack = [{term, state:'parameters'}];
|
|
172
|
+
while (stack.length) {
|
|
173
|
+
const frame = stack.at(-1);
|
|
174
|
+
if (frame.state === 'parameters') {
|
|
175
|
+
if (cursor.match('<')) {
|
|
176
|
+
frame.group = []; frame.term.parameterGroups.push(frame.group); frame.state = 'group';
|
|
177
|
+
const child = makeTerm(); frame.group.push(child); stack.push({term:child,state:'parameters'}); continue;
|
|
178
|
+
}
|
|
179
|
+
if (cursor.match('[')) {
|
|
180
|
+
frame.term.arguments.push(cursor.parseQualifierArgument());
|
|
181
|
+
while (cursor.match(',')) frame.term.arguments.push(cursor.parseQualifierArgument());
|
|
182
|
+
cursor.consume(']');
|
|
183
|
+
if (cursor.peek() === '[') cursor.fail('Qualifier clarifiers must use a single bracketed list','SANSA_INVALID_QUALIFIER');
|
|
184
|
+
}
|
|
185
|
+
const next = cursor.peek();
|
|
186
|
+
if (next && !['|', ',', '>'].includes(next)) cursor.fail('Unexpected character in qualifier expression','SANSA_INVALID_QUALIFIER');
|
|
187
|
+
stack.pop();
|
|
188
|
+
if (!stack.length && cursor.match('|')) { term = makeTerm(); terms.push(term); stack.push({term,state:'parameters'}); }
|
|
189
|
+
} else {
|
|
190
|
+
if (cursor.peek() === '|') cursor.fail('Nested qualifier unions are not supported','SANSA_INVALID_QUALIFIER');
|
|
191
|
+
if (cursor.match(',')) { const child = makeTerm(); frame.group.push(child); stack.push({term:child,state:'parameters'}); continue; }
|
|
192
|
+
cursor.consume('>'); frame.term.parameters.push(...frame.group); frame.state = 'parameters';
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return {type:'QualifierExpression',terms};
|
|
196
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// Runtime-owned standalone Resolve property state. Never exposed in options,
|
|
2
|
+
// bindings or serialized results. Other consumers must explicitly deny admission.
|
|
3
|
+
export const DEFAULT_PROPERTY_INSPECTIONS = 10_000;
|
|
4
|
+
export const MAX_PROPERTY_INSPECTIONS = 1_000_000;
|
|
5
|
+
|
|
6
|
+
export function validPropertyLimit(value) {
|
|
7
|
+
return typeof value === 'number' && Number.isInteger(value) && value >= 0 && value <= MAX_PROPERTY_INSPECTIONS;
|
|
8
|
+
}
|
|
9
|
+
const internalFailures = new WeakSet();
|
|
10
|
+
class PropertyFailure {
|
|
11
|
+
constructor(code) { this.code = code; internalFailures.add(this); }
|
|
12
|
+
}
|
|
13
|
+
const invalid = () => { throw new PropertyFailure('SANSA_RESOLVE_INVALID_PROPERTY_METADATA'); };
|
|
14
|
+
const objectLike = value => value !== null && (typeof value === 'object' || typeof value === 'function');
|
|
15
|
+
function faultCode(error) {
|
|
16
|
+
if (internalFailures.has(error)) return error.code;
|
|
17
|
+
// Explicit checked faults are plain data; never evaluate fault accessors or
|
|
18
|
+
// copy host messages/foreign values into diagnostics.
|
|
19
|
+
try {
|
|
20
|
+
const type = Object.getOwnPropertyDescriptor(error, 'type');
|
|
21
|
+
const kind = Object.getOwnPropertyDescriptor(error, 'kind');
|
|
22
|
+
if (type?.value === 'SansaPropertyAccessFault') switch (kind?.value) {
|
|
23
|
+
case 'invalidMetadata': return 'SANSA_RESOLVE_INVALID_PROPERTY_METADATA';
|
|
24
|
+
case 'scopeViolation': return 'SANSA_RESOLVE_PROPERTY_SCOPE_VIOLATION';
|
|
25
|
+
case 'adapterFailure': return 'SANSA_RESOLVE_PROPERTY_ADAPTER_ERROR';
|
|
26
|
+
}
|
|
27
|
+
} catch { /* untyped host fault */ }
|
|
28
|
+
return 'SANSA_RESOLVE_PROPERTY_ADAPTER_ERROR';
|
|
29
|
+
}
|
|
30
|
+
function diagnostic(code, selector, selectorIndex, extra = {}) {
|
|
31
|
+
return {code, message: 'Property resolution failed', property: selector.property, selectorIndex, ...extra};
|
|
32
|
+
}
|
|
33
|
+
export function prepareProperties(namespace, selectors) {
|
|
34
|
+
let facet;
|
|
35
|
+
try {
|
|
36
|
+
facet = namespace.properties;
|
|
37
|
+
const methods = {};
|
|
38
|
+
const method = name => {
|
|
39
|
+
if (!Object.hasOwn(methods, name)) methods[name] = facet?.[name];
|
|
40
|
+
return methods[name];
|
|
41
|
+
};
|
|
42
|
+
for (let selectorIndex = 0; selectorIndex < selectors.length; selectorIndex++) {
|
|
43
|
+
const selector = selectors[selectorIndex];
|
|
44
|
+
if (selector.type !== 'propertyFilter') continue;
|
|
45
|
+
if (typeof method('scope') !== 'function') return {error: diagnostic('SANSA_RESOLVE_UNSUPPORTED_PROPERTY_SCOPE', selector, selectorIndex)};
|
|
46
|
+
const required = selector.property === 'key' ? ['key'] : ['nodeKind', 'nodeTag', 'nodeHeads'];
|
|
47
|
+
for (const name of required) if (typeof method(name) !== 'function') return {error: diagnostic(selector.property === 'key' ? 'SANSA_RESOLVE_UNSUPPORTED_KEY' : 'SANSA_RESOLVE_UNSUPPORTED_TAG', selector, selectorIndex)};
|
|
48
|
+
}
|
|
49
|
+
// Snapshot requested callback references once: capability checking performs
|
|
50
|
+
// no metadata reads and later callbacks cannot silently remove the contract.
|
|
51
|
+
return {facet, methods};
|
|
52
|
+
} catch (error) {
|
|
53
|
+
const index = selectors.findIndex(s => s.type === 'propertyFilter');
|
|
54
|
+
return {error: diagnostic(faultCode(error), selectors[index], index)};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function scalar(value) {
|
|
58
|
+
if (value === undefined) return undefined;
|
|
59
|
+
if (typeof value !== 'string') invalid();
|
|
60
|
+
for (const ch of value) {
|
|
61
|
+
const code = ch.codePointAt(0);
|
|
62
|
+
if (code >= 0xd800 && code <= 0xdfff) invalid();
|
|
63
|
+
}
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
export function propertyContext(scopeRoot, evaluationRoot, directHeadOf) {
|
|
67
|
+
return Object.freeze({scopeRoot, evaluationRoot, ...(directHeadOf === undefined ? {} : {directHeadOf})});
|
|
68
|
+
}
|
|
69
|
+
export function selectProperty(binding, context, prepared, selector, selectorIndex, budget) {
|
|
70
|
+
const {facet, methods} = prepared;
|
|
71
|
+
const call = (name, candidate, ctx) => methods[name].call(facet, candidate, ctx);
|
|
72
|
+
const charge = () => {
|
|
73
|
+
if (budget.inspected >= budget.limit) throw new PropertyFailure('SANSA_RESOLVE_PROPERTY_LIMIT_EXCEEDED');
|
|
74
|
+
budget.inspected++;
|
|
75
|
+
};
|
|
76
|
+
const authorize = (candidate, ctx) => {
|
|
77
|
+
const role = call('scope', candidate, ctx);
|
|
78
|
+
if (role === 'outside') throw new PropertyFailure('SANSA_RESOLVE_PROPERTY_SCOPE_VIOLATION');
|
|
79
|
+
if (!['root', 'inside'].includes(role) || (role === 'root') !== (candidate === ctx.scopeRoot)) invalid();
|
|
80
|
+
return role;
|
|
81
|
+
};
|
|
82
|
+
const kind = (candidate, ctx) => {
|
|
83
|
+
const value = call('nodeKind', candidate, ctx);
|
|
84
|
+
if (!['NodeLiteral', 'NodeHead', 'Other'].includes(value)) invalid();
|
|
85
|
+
return value;
|
|
86
|
+
};
|
|
87
|
+
try {
|
|
88
|
+
charge();
|
|
89
|
+
const role = authorize(binding, context);
|
|
90
|
+
if (selector.property === 'key') return {match: role === 'root' ? false : scalar(call('key', binding, context)) === selector.value};
|
|
91
|
+
const nodeKind = kind(binding, context);
|
|
92
|
+
if (selector.property === 'headTag') return {match: nodeKind === 'NodeHead' && scalar(call('nodeTag', binding, context)) === selector.value};
|
|
93
|
+
if (nodeKind !== 'NodeLiteral') return {match: false};
|
|
94
|
+
let iterator, finished = false, match = false;
|
|
95
|
+
try {
|
|
96
|
+
const iterable = call('nodeHeads', binding, context);
|
|
97
|
+
const create = iterable?.[Symbol.iterator];
|
|
98
|
+
if (typeof create !== 'function') invalid();
|
|
99
|
+
iterator = create.call(iterable);
|
|
100
|
+
if (!objectLike(iterator)) invalid();
|
|
101
|
+
const next = iterator.next;
|
|
102
|
+
if (typeof next !== 'function') invalid();
|
|
103
|
+
while (true) {
|
|
104
|
+
const step = next.call(iterator);
|
|
105
|
+
if (!objectLike(step)) invalid();
|
|
106
|
+
if (step.done) { finished = true; break; }
|
|
107
|
+
charge();
|
|
108
|
+
const head = step.value;
|
|
109
|
+
if (!objectLike(head)) invalid();
|
|
110
|
+
const headContext = propertyContext(context.scopeRoot, context.evaluationRoot, binding);
|
|
111
|
+
authorize(head, headContext);
|
|
112
|
+
if (kind(head, headContext) !== 'NodeHead') invalid();
|
|
113
|
+
if (scalar(call('nodeTag', head, headContext)) === selector.value) { match = true; break; }
|
|
114
|
+
}
|
|
115
|
+
} finally {
|
|
116
|
+
// Also close after next() faults. Standard for-of does not cover that
|
|
117
|
+
// case, while the checked property contract explicitly requires it.
|
|
118
|
+
if (iterator && !finished) {
|
|
119
|
+
const close = iterator.return;
|
|
120
|
+
if (close !== undefined) {
|
|
121
|
+
if (typeof close !== 'function') invalid();
|
|
122
|
+
const closed = close.call(iterator);
|
|
123
|
+
if (!objectLike(closed)) invalid();
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return {match};
|
|
128
|
+
} catch (error) {
|
|
129
|
+
const code = faultCode(error);
|
|
130
|
+
return {error: diagnostic(code, selector, selectorIndex, code === 'SANSA_RESOLVE_PROPERTY_LIMIT_EXCEEDED' ? {budget: 'maxPropertyInspections', limit: budget.limit, observed: budget.limit + 1} : {})};
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Native scalar information for presentation; optional fields are never inferred. */
|
|
2
|
+
export interface SansaQueryValueMetadata {
|
|
3
|
+
readonly kind?: string;
|
|
4
|
+
readonly category?: string;
|
|
5
|
+
readonly semanticType?: string;
|
|
6
|
+
readonly containerKind?: string;
|
|
7
|
+
readonly nullReason?: string;
|
|
8
|
+
readonly numericLexeme?: string;
|
|
9
|
+
readonly radixBase?: number;
|
|
10
|
+
readonly radixScale?: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** Returns a detached frozen descriptor for a live scalar query value, or undefined. */
|
|
14
|
+
export function getQueryValueMetadata(value: unknown): Readonly<SansaQueryValueMetadata> | undefined;
|
|
15
|
+
/** Pass the materialized object (queryValue.value), including nested projections. */
|
|
16
|
+
export function getQueryObjectFieldMetadata(value: unknown): Readonly<Record<string, Readonly<SansaQueryValueMetadata>>>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const QUERY_VALUE_METADATA_PROPERTY = '__sansaQueryValueMetadata';
|
|
2
|
+
const QUERY_OBJECT_FIELD_METADATA_PROPERTY = '__sansaObjectFieldMetadata';
|
|
3
|
+
|
|
4
|
+
// Public presentation accessors. Metadata storage is private; callers receive
|
|
5
|
+
// detached, frozen scalar descriptors and never need to know the property keys.
|
|
6
|
+
const QUERY_METADATA_FIELDS = ['kind', 'category', 'semanticType', 'containerKind',
|
|
7
|
+
'nullReason', 'numericLexeme', 'radixBase', 'radixScale'];
|
|
8
|
+
function copyQueryMetadata(metadata) {
|
|
9
|
+
if (!metadata || typeof metadata !== 'object') return undefined;
|
|
10
|
+
return Object.freeze(Object.fromEntries(QUERY_METADATA_FIELDS
|
|
11
|
+
.filter((name) => metadata[name] !== undefined)
|
|
12
|
+
.map((name) => [name, metadata[name]])));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getQueryValueMetadata(value) {
|
|
16
|
+
if (value?.type !== 'scalar') return undefined;
|
|
17
|
+
return copyQueryMetadata(Object.getOwnPropertyDescriptor(value, QUERY_VALUE_METADATA_PROPERTY)?.value);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function getQueryObjectFieldMetadata(value) {
|
|
21
|
+
if (!value || typeof value !== 'object') return Object.freeze({});
|
|
22
|
+
const fields = Object.getOwnPropertyDescriptor(value, QUERY_OBJECT_FIELD_METADATA_PROPERTY)?.value;
|
|
23
|
+
return Object.freeze(Object.fromEntries(Object.entries(fields ?? {})
|
|
24
|
+
.map(([name, metadata]) => [name, copyQueryMetadata(metadata)])));
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SansaSelector } from './index.js';
|
|
2
|
+
/** Supported synchronous host-cursor API. See docs/selector-cursor.md. */
|
|
3
|
+
export interface SansaSelectorCursor {
|
|
4
|
+
peekSyntax(): string;
|
|
5
|
+
readonly index: number;
|
|
6
|
+
consume(char: string): unknown;
|
|
7
|
+
match(char: string): boolean;
|
|
8
|
+
matchRangeSeparator(): boolean;
|
|
9
|
+
parseQuotedPayload(): string;
|
|
10
|
+
parseIdentifier(context: string): string;
|
|
11
|
+
/** Optional non-structural capability; reference hosts omit it. */
|
|
12
|
+
parseChildIdentity?(): { readonly type: 'childIdentity'; readonly identity: string };
|
|
13
|
+
parseOptionalPositionIndex(): number | null;
|
|
14
|
+
fail(message: string, code: string, index?: number): never;
|
|
15
|
+
}
|
|
16
|
+
export function parseDotSelectorFromCursor<T = SansaSelector>(cursor: SansaSelectorCursor, member?: (name: string, quoted: boolean) => T): SansaSelector | T;
|
|
17
|
+
export function parsePositionSelectorFromCursor<T = SansaSelector>(cursor: SansaSelectorCursor, position?: (index: number) => T): SansaSelector | T;
|
|
18
|
+
|
|
19
|
+
export function validatePositionIndex(raw: string, maxPositionIndex: number | undefined, fail: (message: string, code: string) => never): number;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/** Shared host-cursor grammar. Cursors own lexical decoding, limits and diagnostics. */
|
|
2
|
+
const memberSelector = (name, quoted) => ({ type: 'member', name, quoted });
|
|
3
|
+
const positionSelector = index => ({ type: 'position', index });
|
|
4
|
+
|
|
5
|
+
// Native SANSA and host cursors share this grammar dispatch.
|
|
6
|
+
function dotReader(char) {
|
|
7
|
+
switch (char) {
|
|
8
|
+
case '@': return attribute;
|
|
9
|
+
case '^': return parent;
|
|
10
|
+
case '*': return expansion;
|
|
11
|
+
case '[': return quotedMember;
|
|
12
|
+
case '<': return localSpace;
|
|
13
|
+
case '(': return namePattern;
|
|
14
|
+
case '\\': return childIdentity;
|
|
15
|
+
default: return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function parseDotSelectorFromCursor(cursor, member = memberSelector) {
|
|
19
|
+
cursor.consume('.');
|
|
20
|
+
const reader = dotReader(cursor.peekSyntax());
|
|
21
|
+
return reader ? reader(cursor, member) : member(cursor.parseIdentifier('member selector'), false);
|
|
22
|
+
}
|
|
23
|
+
function childIdentity(cursor, member) {
|
|
24
|
+
// Structural-reference hosts retain their existing identifier rejection.
|
|
25
|
+
return typeof cursor.parseChildIdentity === 'function'
|
|
26
|
+
? cursor.parseChildIdentity()
|
|
27
|
+
: member(cursor.parseIdentifier('member selector'), false);
|
|
28
|
+
}
|
|
29
|
+
function attribute(cursor) { cursor.consume('@'); return { type: 'attributeSpace' }; }
|
|
30
|
+
function parent(cursor) { cursor.consume('^'); return { type: 'parent' }; }
|
|
31
|
+
function expansion(cursor) {
|
|
32
|
+
cursor.consume('*');
|
|
33
|
+
return { type: cursor.match('*') ? 'descendantExpansion' : 'directExpansion' };
|
|
34
|
+
}
|
|
35
|
+
function quotedMember(cursor, member) {
|
|
36
|
+
cursor.consume('[');
|
|
37
|
+
const name = cursor.parseQuotedPayload();
|
|
38
|
+
cursor.consume(']');
|
|
39
|
+
return member(name, true);
|
|
40
|
+
}
|
|
41
|
+
function localSpace(cursor) {
|
|
42
|
+
cursor.consume('<');
|
|
43
|
+
const name = cursor.parseQuotedPayload();
|
|
44
|
+
if (!name.length) cursor.fail('Local address-space names must not be empty', 'SANSA_EMPTY_LOCAL_SPACE_NAME');
|
|
45
|
+
cursor.consume('>');
|
|
46
|
+
return { type: 'localSpace', name };
|
|
47
|
+
}
|
|
48
|
+
function namePattern(cursor) {
|
|
49
|
+
cursor.consume('('); const pattern = cursor.parseQuotedPayload(); cursor.consume(')');
|
|
50
|
+
return { type: 'namePattern', pattern };
|
|
51
|
+
}
|
|
52
|
+
export function parsePositionSelectorFromCursor(cursor, position = positionSelector) {
|
|
53
|
+
cursor.consume('[');
|
|
54
|
+
const selectorStart = cursor.index;
|
|
55
|
+
const start = cursor.parseOptionalPositionIndex();
|
|
56
|
+
if (cursor.matchRangeSeparator()) {
|
|
57
|
+
const end = cursor.parseOptionalPositionIndex();
|
|
58
|
+
if (start === null && end === null) cursor.fail('Position ranges must include a start or end index', 'SANSA_EMPTY_POSITION_RANGE', selectorStart);
|
|
59
|
+
cursor.consume(']');
|
|
60
|
+
return { type: 'positionRange', start, end };
|
|
61
|
+
}
|
|
62
|
+
if (start === null) cursor.fail('Expected positional index', 'SANSA_EXPECTED_INDEX');
|
|
63
|
+
cursor.consume(']');
|
|
64
|
+
return position(start);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Validate the original decimal spelling and bound before number conversion.
|
|
68
|
+
* Hosts provide native diagnostics; the default is SANSA's portable ceiling. */
|
|
69
|
+
export function validatePositionIndex(raw, maxPositionIndex = 999_999, fail) {
|
|
70
|
+
if (!/^[0-9]+$/.test(raw)) return fail('Expected unsigned decimal positional index', 'SANSA_EXPECTED_INDEX');
|
|
71
|
+
if (raw.length > 1 && raw[0] === '0') return fail('Positional indexes must not contain leading zeroes', 'SANSA_LEADING_ZERO_INDEX');
|
|
72
|
+
const bound = String(maxPositionIndex);
|
|
73
|
+
if (raw.length > bound.length || (raw.length === bound.length && raw > bound)) {
|
|
74
|
+
return fail(`Position indexes must be less than or equal to ${maxPositionIndex}`, 'SANSA_POSITION_INDEX_LIMIT_EXCEEDED');
|
|
75
|
+
}
|
|
76
|
+
const value = Number(raw);
|
|
77
|
+
if (!Number.isSafeInteger(value)) return fail(`Position indexes must be less than or equal to ${maxPositionIndex}`, 'SANSA_POSITION_INDEX_LIMIT_EXCEEDED');
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
@@ -853,7 +853,6 @@ function validateAeonWorkbenchValue(value, hints = {}, path = 'value') {
|
|
|
853
853
|
if (value && typeof value === 'object') {
|
|
854
854
|
for (const [key, entry] of Object.entries(value)) {
|
|
855
855
|
const entryPath = `${path}${renderWorkbenchValuePathSegment(key)}`;
|
|
856
|
-
if (key.length === 0) return invalidAeonWorkbenchValue('Keys must not be empty', entryPath);
|
|
857
856
|
const result = validateAeonWorkbenchValue(entry, {}, entryPath);
|
|
858
857
|
if (!result.ok) return result;
|
|
859
858
|
}
|
|
@@ -885,7 +884,6 @@ function validateAeonWorkbenchNodeValue(value, path) {
|
|
|
885
884
|
}
|
|
886
885
|
for (const [key, entry] of Object.entries(value.attributes)) {
|
|
887
886
|
const entryPath = `${path}.attributes${renderWorkbenchValuePathSegment(key)}`;
|
|
888
|
-
if (key.length === 0) return invalidAeonWorkbenchValue('Keys must not be empty', entryPath);
|
|
889
887
|
const result = validateAeonWorkbenchValue(entry, {}, entryPath);
|
|
890
888
|
if (!result.ok) return result;
|
|
891
889
|
}
|