@altopelago/sansa 0.9.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 +41 -0
- package/CODE_OF_CONDUCT.md +28 -0
- package/CONTRIBUTING.md +52 -0
- package/GOVERNANCE.md +35 -0
- package/LICENSE +21 -0
- package/README.md +146 -0
- package/SECURITY.md +38 -0
- package/docs/api-contract.md +788 -0
- package/docs/capabilities.json +80 -0
- package/docs/query-tool.md +228 -0
- package/docs/releasing.md +37 -0
- package/fixtures/address-v1.json +316 -0
- package/fixtures/query-inventory.aeon +69 -0
- package/fixtures/query-inventory.json +671 -0
- package/fixtures/query-params-single.json +10 -0
- package/package.json +70 -0
- package/scripts/cts-address.mjs +107 -0
- package/scripts/cts-query.mjs +271 -0
- package/scripts/cts-resolve.mjs +151 -0
- package/scripts/cts-value-semantics.mjs +83 -0
- package/scripts/query-web.mjs +145 -0
- package/scripts/query.mjs +579 -0
- package/scripts/stress-addresses.mjs +65 -0
- package/src/index.d.ts +575 -0
- package/src/index.js +3389 -0
- package/stress-tests/README.md +19 -0
- package/stress-tests/address/invalid.sansa-cases +60 -0
- package/stress-tests/address/valid.sansa-cases +76 -0
- package/tools/query-web/app.js +266 -0
- package/tools/query-web/examples.mjs +478 -0
- package/tools/query-web/index.html +117 -0
- package/tools/query-web/runtime.mjs +796 -0
- package/tools/query-web/styles.css +251 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# SANSA Stress Tests
|
|
2
|
+
|
|
3
|
+
Stress tests are implementation-owned hardening inputs. They are broader than CTS and can grow quickly as new parser combinations are discovered.
|
|
4
|
+
|
|
5
|
+
The initial address stress surface uses two `---`-separated case files:
|
|
6
|
+
|
|
7
|
+
- `address/valid.sansa-cases`
|
|
8
|
+
- `address/invalid.sansa-cases`
|
|
9
|
+
|
|
10
|
+
Each non-empty case is parsed as a single SANSA address expression. Comments may appear on their own lines with `//`.
|
|
11
|
+
|
|
12
|
+
Run:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npm run stress
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Valid cases must parse. Invalid cases must fail closed.
|
|
19
|
+
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
---
|
|
2
|
+
|
|
3
|
+
---
|
|
4
|
+
inventory
|
|
5
|
+
---
|
|
6
|
+
$.bad name
|
|
7
|
+
---
|
|
8
|
+
$.items[01]
|
|
9
|
+
---
|
|
10
|
+
$.items[]
|
|
11
|
+
---
|
|
12
|
+
$.items[..]
|
|
13
|
+
---
|
|
14
|
+
$.items[01..2]
|
|
15
|
+
---
|
|
16
|
+
$.items[1..02]
|
|
17
|
+
---
|
|
18
|
+
$.[""]
|
|
19
|
+
---
|
|
20
|
+
$.<"">
|
|
21
|
+
---
|
|
22
|
+
$.["bad\q"]
|
|
23
|
+
---
|
|
24
|
+
$.["bad\u{D800}"]
|
|
25
|
+
---
|
|
26
|
+
$.["unterminated]
|
|
27
|
+
---
|
|
28
|
+
$.inventory:
|
|
29
|
+
---
|
|
30
|
+
$.inventory:csv[,]
|
|
31
|
+
---
|
|
32
|
+
$.inventory:csv[]
|
|
33
|
+
---
|
|
34
|
+
$.value:list<string|number>
|
|
35
|
+
---
|
|
36
|
+
$.a@id
|
|
37
|
+
---
|
|
38
|
+
$.a@["id"]
|
|
39
|
+
---
|
|
40
|
+
$.a.@id
|
|
41
|
+
---
|
|
42
|
+
$.a.@["id"]
|
|
43
|
+
---
|
|
44
|
+
$.items/
|
|
45
|
+
---
|
|
46
|
+
$.items..name
|
|
47
|
+
---
|
|
48
|
+
$.:<objects>
|
|
49
|
+
---
|
|
50
|
+
$:<object>
|
|
51
|
+
---
|
|
52
|
+
$.["list"]["2"]
|
|
53
|
+
---
|
|
54
|
+
$.items[1000000]
|
|
55
|
+
---
|
|
56
|
+
$.items[0..1000000]
|
|
57
|
+
---
|
|
58
|
+
$.items[1000000..]
|
|
59
|
+
---
|
|
60
|
+
$.items[33848483399384847473939404038834748393948739393323848483937747483]
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
---
|
|
2
|
+
$
|
|
3
|
+
---
|
|
4
|
+
?
|
|
5
|
+
---
|
|
6
|
+
$.inventory
|
|
7
|
+
---
|
|
8
|
+
$.inventory[0]
|
|
9
|
+
---
|
|
10
|
+
$.inventory[0..2]
|
|
11
|
+
---
|
|
12
|
+
$.inventory[2..]
|
|
13
|
+
---
|
|
14
|
+
$.inventory[..2]
|
|
15
|
+
---
|
|
16
|
+
$.inventory[0].^
|
|
17
|
+
---
|
|
18
|
+
$.inventory[0].^.name
|
|
19
|
+
---
|
|
20
|
+
$.["^"]
|
|
21
|
+
---
|
|
22
|
+
$.inventory[0].name
|
|
23
|
+
---
|
|
24
|
+
$.inventory[0].["display.name"]
|
|
25
|
+
---
|
|
26
|
+
$.inventory[0].@.<"pdf">
|
|
27
|
+
---
|
|
28
|
+
?.<"request">.user_id
|
|
29
|
+
---
|
|
30
|
+
$.items.*
|
|
31
|
+
---
|
|
32
|
+
$.items.**
|
|
33
|
+
---
|
|
34
|
+
$.items.*#text
|
|
35
|
+
---
|
|
36
|
+
$.items.*%stringLiteral
|
|
37
|
+
---
|
|
38
|
+
$.items.*#text%stringLiteral.("item_*")
|
|
39
|
+
---
|
|
40
|
+
$.result:number|nan
|
|
41
|
+
---
|
|
42
|
+
$.inventory:list<string>
|
|
43
|
+
---
|
|
44
|
+
$.version:sep[.]
|
|
45
|
+
---
|
|
46
|
+
$.inventory:csv[","]
|
|
47
|
+
---
|
|
48
|
+
$.claim:type<type>[arg]
|
|
49
|
+
---
|
|
50
|
+
$#record%object
|
|
51
|
+
---
|
|
52
|
+
$.["line\nfeed"].["tab\tname"].["quote\"name"]
|
|
53
|
+
---
|
|
54
|
+
$.["emoji_\u{1F642}"]
|
|
55
|
+
---
|
|
56
|
+
$:object
|
|
57
|
+
---
|
|
58
|
+
$:number|nan
|
|
59
|
+
---
|
|
60
|
+
$:document<invoice>
|
|
61
|
+
---
|
|
62
|
+
$.["list"][2]:rule["+"]
|
|
63
|
+
---
|
|
64
|
+
$.key:string[","]["."]
|
|
65
|
+
---
|
|
66
|
+
$.["list"][2][2]
|
|
67
|
+
---
|
|
68
|
+
$.key:tuple<x><y>
|
|
69
|
+
---
|
|
70
|
+
$.key:string<int><int>
|
|
71
|
+
---
|
|
72
|
+
?.name
|
|
73
|
+
---
|
|
74
|
+
$.items[999999]
|
|
75
|
+
---
|
|
76
|
+
$.items[0..999999]
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { firstQueryExampleName, queryExampleGroups, queryExamples } from './examples.mjs';
|
|
2
|
+
|
|
3
|
+
const fixtureInput = document.querySelector('#fixtureInput');
|
|
4
|
+
const paramsInput = document.querySelector('#paramsInput');
|
|
5
|
+
const sourceLabel = document.querySelector('#sourceLabel');
|
|
6
|
+
const queryInput = document.querySelector('#queryInput');
|
|
7
|
+
const resultOutput = document.querySelector('#resultOutput');
|
|
8
|
+
const fixtureStatus = document.querySelector('#fixtureStatus');
|
|
9
|
+
const paramsStatus = document.querySelector('#paramsStatus');
|
|
10
|
+
const queryStatus = document.querySelector('#queryStatus');
|
|
11
|
+
const resultStatus = document.querySelector('#resultStatus');
|
|
12
|
+
const exampleSelect = document.querySelector('#exampleSelect');
|
|
13
|
+
const resetButton = document.querySelector('#resetButton');
|
|
14
|
+
const parseButton = document.querySelector('#parseButton');
|
|
15
|
+
const runButton = document.querySelector('#runButton');
|
|
16
|
+
const transformExtensionsInput = document.querySelector('#transformExtensions');
|
|
17
|
+
const budgetInputs = Array.from(document.querySelectorAll('.budget-row input'));
|
|
18
|
+
|
|
19
|
+
let defaultFixtureSource = '';
|
|
20
|
+
let defaultJsonSource = '';
|
|
21
|
+
let defaultAeonSource = '';
|
|
22
|
+
let defaultParamsSource = '';
|
|
23
|
+
let lastAction = 'evaluate';
|
|
24
|
+
|
|
25
|
+
await loadDefaultSources();
|
|
26
|
+
renderExampleSelect();
|
|
27
|
+
setExample(exampleSelect.value || firstQueryExampleName());
|
|
28
|
+
await runQuery();
|
|
29
|
+
|
|
30
|
+
exampleSelect.addEventListener('change', () => {
|
|
31
|
+
setExample(exampleSelect.value);
|
|
32
|
+
void runQuery();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
resetButton.addEventListener('click', () => {
|
|
36
|
+
fixtureInput.value = sourceKind() === 'json' ? defaultJsonSource : defaultAeonSource;
|
|
37
|
+
paramsInput.value = defaultParamsSource;
|
|
38
|
+
setExample(exampleSelect.value);
|
|
39
|
+
fixtureStatus.textContent = sourceKind() === 'json' ? 'default json' : 'default aeon';
|
|
40
|
+
paramsStatus.textContent = 'default params';
|
|
41
|
+
void runQuery();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
parseButton.addEventListener('click', () => {
|
|
45
|
+
void parseOnly();
|
|
46
|
+
});
|
|
47
|
+
runButton.addEventListener('click', () => {
|
|
48
|
+
void runQuery();
|
|
49
|
+
});
|
|
50
|
+
document.querySelectorAll('input[name="outputMode"]').forEach((input) => {
|
|
51
|
+
input.addEventListener('change', () => {
|
|
52
|
+
if (lastAction === 'parse') {
|
|
53
|
+
void parseOnly();
|
|
54
|
+
} else {
|
|
55
|
+
void runQuery();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
document.querySelectorAll('input[name="queryPolicy"]').forEach((input) => {
|
|
60
|
+
input.addEventListener('change', () => {
|
|
61
|
+
if (lastAction !== 'parse') void runQuery();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
transformExtensionsInput.addEventListener('change', () => {
|
|
65
|
+
if (lastAction !== 'parse') void runQuery();
|
|
66
|
+
});
|
|
67
|
+
budgetInputs.forEach((input) => {
|
|
68
|
+
input.addEventListener('input', () => {
|
|
69
|
+
if (lastAction !== 'parse') void runQuery();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
document.querySelectorAll('input[name="sourceKind"]').forEach((input) => {
|
|
73
|
+
input.addEventListener('change', () => {
|
|
74
|
+
fixtureInput.value = sourceKind() === 'json' ? defaultJsonSource : defaultAeonSource;
|
|
75
|
+
sourceLabel.textContent = sourceKind() === 'json' ? 'Fixture JSON' : 'AEON Source';
|
|
76
|
+
fixtureStatus.textContent = sourceKind() === 'json' ? 'default json' : 'default aeon';
|
|
77
|
+
void runQuery();
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
fixtureInput.addEventListener('input', () => {
|
|
82
|
+
fixtureStatus.textContent = 'edited fixture';
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
paramsInput.addEventListener('input', () => {
|
|
86
|
+
paramsStatus.textContent = paramsInput.value.trim().length === 0 ? 'not mounted' : 'edited params';
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
queryInput.addEventListener('keydown', (event) => {
|
|
90
|
+
if ((event.metaKey || event.ctrlKey) && event.key === 'Enter') {
|
|
91
|
+
event.preventDefault();
|
|
92
|
+
runQuery();
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
function setExample(name) {
|
|
97
|
+
queryInput.value = queryExamples[name]?.query ?? queryExamples[firstQueryExampleName()]?.query ?? '';
|
|
98
|
+
queryStatus.textContent = 'example loaded';
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function renderExampleSelect() {
|
|
102
|
+
exampleSelect.replaceChildren(...queryExampleGroups.map((group) => {
|
|
103
|
+
const optgroup = document.createElement('optgroup');
|
|
104
|
+
optgroup.label = group.label;
|
|
105
|
+
optgroup.append(...group.examples.map((example) => {
|
|
106
|
+
const option = document.createElement('option');
|
|
107
|
+
option.value = example.name;
|
|
108
|
+
option.textContent = example.label;
|
|
109
|
+
return option;
|
|
110
|
+
}));
|
|
111
|
+
return optgroup;
|
|
112
|
+
}));
|
|
113
|
+
exampleSelect.value = firstQueryExampleName();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async function loadDefaultSources() {
|
|
117
|
+
defaultAeonSource = await fetchText('/fixtures/query-inventory.aeon', [
|
|
118
|
+
'inventory = {',
|
|
119
|
+
' items:list<object> = []',
|
|
120
|
+
'}',
|
|
121
|
+
].join('\n'));
|
|
122
|
+
defaultJsonSource = await fetchText('/fixtures/query-inventory.json', '{\n "root": {\n "address": "$",\n "children": []\n }\n}');
|
|
123
|
+
defaultParamsSource = [
|
|
124
|
+
'source:sansa = $.inventory.items.*',
|
|
125
|
+
'field:sansa = ?.sku',
|
|
126
|
+
'statusField:sansa = ?.status',
|
|
127
|
+
'sortField:sansa = ?.qty',
|
|
128
|
+
'name:string = "Adapter"',
|
|
129
|
+
].join('\n');
|
|
130
|
+
defaultFixtureSource = defaultAeonSource;
|
|
131
|
+
fixtureInput.value = defaultFixtureSource;
|
|
132
|
+
paramsInput.value = defaultParamsSource;
|
|
133
|
+
fixtureStatus.textContent = 'default aeon';
|
|
134
|
+
paramsStatus.textContent = 'default params';
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function fetchText(path, fallback) {
|
|
138
|
+
try {
|
|
139
|
+
const response = await fetch(path);
|
|
140
|
+
if (!response.ok) throw new Error(`${response.status} ${response.statusText}`);
|
|
141
|
+
return await response.text();
|
|
142
|
+
} catch (error) {
|
|
143
|
+
fixtureStatus.textContent = 'source load failed';
|
|
144
|
+
renderError('SANSA_QUERY_WORKBENCH_FIXTURE_LOAD', error.message);
|
|
145
|
+
return fallback;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async function parseOnly() {
|
|
150
|
+
lastAction = 'parse';
|
|
151
|
+
queryStatus.textContent = 'parsing';
|
|
152
|
+
const payload = await queryApi({ action: 'parse', query: queryInput.value });
|
|
153
|
+
queryStatus.textContent = payload.ok ? 'parse ok' : 'parse failed';
|
|
154
|
+
resultStatus.textContent = payload.ok
|
|
155
|
+
? 'parse summary'
|
|
156
|
+
: `${payload.errors.length} error${payload.errors.length === 1 ? '' : 's'}`;
|
|
157
|
+
renderValue(formatPayloadOutput(payload));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async function runQuery() {
|
|
161
|
+
lastAction = 'evaluate';
|
|
162
|
+
queryStatus.textContent = 'running';
|
|
163
|
+
const payload = await queryApi({
|
|
164
|
+
action: 'evaluate',
|
|
165
|
+
sourceKind: sourceKind(),
|
|
166
|
+
source: fixtureInput.value,
|
|
167
|
+
paramsSource: paramsInput.value,
|
|
168
|
+
query: queryInput.value,
|
|
169
|
+
policy: queryPolicy(),
|
|
170
|
+
transformExtensions: transformExtensionsInput.checked,
|
|
171
|
+
budget: queryBudget(),
|
|
172
|
+
});
|
|
173
|
+
queryStatus.textContent = payload.ok ? 'run ok' : 'run failed';
|
|
174
|
+
resultStatus.textContent = payload.ok
|
|
175
|
+
? `${payload.count} result${payload.count === 1 ? '' : 's'}`
|
|
176
|
+
: `${payload.errors.length} error${payload.errors.length === 1 ? '' : 's'}`;
|
|
177
|
+
renderValue(formatPayloadOutput(payload));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
async function queryApi(payload) {
|
|
181
|
+
try {
|
|
182
|
+
const response = await fetch('/api/query', {
|
|
183
|
+
method: 'POST',
|
|
184
|
+
headers: { 'content-type': 'application/json' },
|
|
185
|
+
body: JSON.stringify(payload),
|
|
186
|
+
});
|
|
187
|
+
return await response.json();
|
|
188
|
+
} catch (error) {
|
|
189
|
+
return {
|
|
190
|
+
ok: false,
|
|
191
|
+
errors: [{ code: 'SANSA_QUERY_WORKBENCH_API_ERROR', message: error.message }],
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function renderError(code, message) {
|
|
197
|
+
renderValue({
|
|
198
|
+
ok: false,
|
|
199
|
+
errors: [{ code, message }],
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function renderValue(value) {
|
|
204
|
+
resultOutput.textContent = typeof value === 'string'
|
|
205
|
+
? value
|
|
206
|
+
: JSON.stringify(value, null, 2);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function formatPayloadText(payload) {
|
|
210
|
+
if (typeof payload.text === 'string') return payload.text;
|
|
211
|
+
if (Array.isArray(payload.errors)) return formatDiagnostics(payload.errors);
|
|
212
|
+
return JSON.stringify(payload, null, 2);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function formatPayloadOutput(payload) {
|
|
216
|
+
switch (formatOutputMode()) {
|
|
217
|
+
case 'json':
|
|
218
|
+
return payload;
|
|
219
|
+
case 'inspect':
|
|
220
|
+
return typeof payload.inspect === 'string' ? payload.inspect : formatPayloadText(payload);
|
|
221
|
+
default:
|
|
222
|
+
return formatPayloadText(payload);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function formatDiagnostics(errors) {
|
|
227
|
+
if (errors.length === 0) return '(no diagnostics)';
|
|
228
|
+
return errors.map((error) => {
|
|
229
|
+
const phase = typeof error.phase === 'string' ? ` [${error.phase}]` : '';
|
|
230
|
+
const candidate = typeof error.candidateAddress === 'string' ? ` at ${error.candidateAddress}` : '';
|
|
231
|
+
const location = Number.isInteger(error.index)
|
|
232
|
+
? ` index ${error.index}`
|
|
233
|
+
: Number.isInteger(error.selectorIndex)
|
|
234
|
+
? ` selector ${error.selectorIndex}`
|
|
235
|
+
: '';
|
|
236
|
+
return `${error.code}${phase}${candidate}${location}: ${error.message}`;
|
|
237
|
+
}).join('\n');
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function formatOutputMode() {
|
|
241
|
+
return document.querySelector('input[name="outputMode"]:checked')?.value ?? 'text';
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function sourceKind() {
|
|
245
|
+
return document.querySelector('input[name="sourceKind"]:checked')?.value ?? 'aeon';
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function queryPolicy() {
|
|
249
|
+
return document.querySelector('input[name="queryPolicy"]:checked')?.value ?? '';
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function queryBudget() {
|
|
253
|
+
const budget = {};
|
|
254
|
+
for (const input of budgetInputs) {
|
|
255
|
+
const value = parseBudgetInput(input.value);
|
|
256
|
+
if (value !== undefined) budget[input.id] = value;
|
|
257
|
+
}
|
|
258
|
+
return budget;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function parseBudgetInput(value) {
|
|
262
|
+
const trimmed = value.trim();
|
|
263
|
+
if (!/^(0|[1-9][0-9]*)$/.test(trimmed)) return undefined;
|
|
264
|
+
const parsed = Number(trimmed);
|
|
265
|
+
return Number.isSafeInteger(parsed) ? parsed : undefined;
|
|
266
|
+
}
|