@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,1565 @@
|
|
|
1
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
2
|
+
const shell = document.querySelector("[data-sansa-playground]");
|
|
3
|
+
if (!shell) return;
|
|
4
|
+
|
|
5
|
+
const source = shell.querySelector("[data-sansa-source]");
|
|
6
|
+
const address = shell.querySelector("[data-sansa-address]");
|
|
7
|
+
const query = shell.querySelector("[data-sansa-query]");
|
|
8
|
+
const result = shell.querySelector("[data-sansa-result]");
|
|
9
|
+
const inputTitle = shell.querySelector("[data-sansa-input-title]");
|
|
10
|
+
const resultTitle = shell.querySelector("[data-sansa-result-title]");
|
|
11
|
+
const diagnostics = shell.querySelector("[data-sansa-diagnostics]");
|
|
12
|
+
const loading = shell.querySelector("[data-sansa-loading]");
|
|
13
|
+
const modeButtons = shell.querySelectorAll("[data-sansa-mode]");
|
|
14
|
+
const viewButtons = shell.querySelectorAll("[data-sansa-view]");
|
|
15
|
+
const composerOpen = shell.querySelectorAll("[data-sansa-composer-open]");
|
|
16
|
+
const composerModal = shell.querySelector("[data-sansa-composer-modal]");
|
|
17
|
+
const composerClose = shell.querySelectorAll("[data-sansa-composer-close]");
|
|
18
|
+
const composerTitle = shell.querySelector("[data-sansa-composer-title]");
|
|
19
|
+
const resolveComposer = shell.querySelector("[data-sansa-resolve-composer]");
|
|
20
|
+
const queryComposer = shell.querySelector("[data-sansa-query-composer]");
|
|
21
|
+
const composerInput = shell.querySelector("[data-sansa-composer-input]");
|
|
22
|
+
const composerOptions = shell.querySelector("[data-sansa-composer-options]");
|
|
23
|
+
const composerApply = shell.querySelector("[data-sansa-composer-apply]");
|
|
24
|
+
const composerApplyLabel = shell.querySelector("[data-sansa-composer-apply-label]");
|
|
25
|
+
const queryClauseButtons = shell.querySelectorAll("[data-sansa-query-clause]");
|
|
26
|
+
const queryClauseTitle = shell.querySelector("[data-sansa-query-clause-title]");
|
|
27
|
+
const queryClauseHelp = shell.querySelector("[data-sansa-query-clause-help]");
|
|
28
|
+
const queryClauseRequirement = shell.querySelector("[data-sansa-query-clause-requirement]");
|
|
29
|
+
const queryClauseLabel = shell.querySelector("[data-sansa-query-clause-label]");
|
|
30
|
+
const queryClauseInput = shell.querySelector("[data-sansa-query-clause-input]");
|
|
31
|
+
const queryClauseOptions = shell.querySelector("[data-sansa-query-clause-options]");
|
|
32
|
+
const queryPreview = shell.querySelector("[data-sansa-query-preview]");
|
|
33
|
+
const queryValidation = shell.querySelector("[data-sansa-query-validation]");
|
|
34
|
+
const examplesOpen = shell.querySelector("[data-sansa-examples-open]");
|
|
35
|
+
const examplesModal = shell.querySelector("[data-sansa-examples-modal]");
|
|
36
|
+
const examplesClose = shell.querySelectorAll("[data-sansa-examples-close]");
|
|
37
|
+
const exampleTabs = shell.querySelectorAll("[data-sansa-example-key]");
|
|
38
|
+
const exampleSource = shell.querySelector("[data-sansa-example-source]");
|
|
39
|
+
const exampleExpression = shell.querySelector("[data-sansa-example-expression]");
|
|
40
|
+
const exampleLoad = shell.querySelector("[data-sansa-example-load]");
|
|
41
|
+
|
|
42
|
+
if (!source || !address || !query || !result || !diagnostics || !loading) return;
|
|
43
|
+
|
|
44
|
+
const runtimeReady = Promise.all([
|
|
45
|
+
import("@aeon/runtime"),
|
|
46
|
+
import("../../src/index.js"),
|
|
47
|
+
import("@altopelago/aeon-sdk/sansa"),
|
|
48
|
+
import("./namespace.mjs")
|
|
49
|
+
]).then(([runtime, sansa, sdk, projection]) => ({
|
|
50
|
+
runRuntime: runtime.runRuntime,
|
|
51
|
+
parseAddress: sansa.parseAddress,
|
|
52
|
+
renderAddress: sansa.renderAddress,
|
|
53
|
+
parseQuery: sansa.parseQuery,
|
|
54
|
+
evaluateQuery: sansa.evaluateQuery,
|
|
55
|
+
resolveAddress: sansa.resolveAddress,
|
|
56
|
+
createAeonNamespace: sdk.createAeonNamespace,
|
|
57
|
+
...projection
|
|
58
|
+
}));
|
|
59
|
+
|
|
60
|
+
const examples = window.SansaPlaygroundExamples || {};
|
|
61
|
+
const state = {
|
|
62
|
+
mode: "transport",
|
|
63
|
+
view: "resolve",
|
|
64
|
+
requestId: 0,
|
|
65
|
+
rows: [],
|
|
66
|
+
namespace: null,
|
|
67
|
+
diagnosticLines: [],
|
|
68
|
+
hasDiagnosticErrors: false,
|
|
69
|
+
diagnosticLineOffset: 0,
|
|
70
|
+
caretBindingPath: null,
|
|
71
|
+
queryComposerClause: "from",
|
|
72
|
+
queryDraft: {
|
|
73
|
+
from: "$",
|
|
74
|
+
where: "",
|
|
75
|
+
order: "",
|
|
76
|
+
offset: "",
|
|
77
|
+
limit: "",
|
|
78
|
+
select: "."
|
|
79
|
+
},
|
|
80
|
+
whereBuilder: {
|
|
81
|
+
step: "root",
|
|
82
|
+
field: null,
|
|
83
|
+
operator: null,
|
|
84
|
+
functionName: null,
|
|
85
|
+
temporalTarget: null
|
|
86
|
+
},
|
|
87
|
+
queryRenderedOptions: [],
|
|
88
|
+
example: Object.keys(examples)[0] || "",
|
|
89
|
+
parseAddress: null,
|
|
90
|
+
resolveAddress: null,
|
|
91
|
+
selectionRows: null,
|
|
92
|
+
parseQuery: null
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const sourceComposer = window.AeonSourceComposer?.mount({
|
|
96
|
+
shell,
|
|
97
|
+
source,
|
|
98
|
+
runtimeReady,
|
|
99
|
+
getMode: () => state.mode,
|
|
100
|
+
runtimeConfig: (text, mode, relaxed = false) => {
|
|
101
|
+
if (relaxed) {
|
|
102
|
+
return {
|
|
103
|
+
text: sourceForBuilderSeed(text),
|
|
104
|
+
options: { mode: "loose", datatypePolicy: "reserved_only", includeAnnotations: true, output: "map" }
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
const mapping = mapMode(mode);
|
|
108
|
+
return {
|
|
109
|
+
text: sourceForMode(text, mode),
|
|
110
|
+
options: { mode: mapping.runtimeMode, datatypePolicy: mapping.datatypePolicy, includeAnnotations: true, output: "map" }
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
onApply: () => scheduleResolve(),
|
|
114
|
+
onError: (error) => {
|
|
115
|
+
diagnostics.textContent = error instanceof Error ? error.message : String(error);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
function escapeHtml(value) {
|
|
120
|
+
return String(value ?? "")
|
|
121
|
+
.replace(/&/g, "&")
|
|
122
|
+
.replace(/</g, "<")
|
|
123
|
+
.replace(/>/g, ">")
|
|
124
|
+
.replace(/"/g, """);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function mapMode(mode) {
|
|
128
|
+
if (mode === "strict") return { runtimeMode: "strict", datatypePolicy: "reserved_only" };
|
|
129
|
+
if (mode === "custom") return { runtimeMode: "strict", datatypePolicy: "allow_custom" };
|
|
130
|
+
return { runtimeMode: "transport", datatypePolicy: "reserved_only" };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function sourceForMode(text, mode) {
|
|
134
|
+
const sourceText = String(text ?? "");
|
|
135
|
+
if (mode === "transport" || /^\s*aeon\s*:\s*header\s*=/im.test(sourceText)) return sourceText;
|
|
136
|
+
const headerMode = mode === "custom" ? "custom" : "strict";
|
|
137
|
+
const withoutModeHeader = sourceText.replace(/^\s*aeon:mode\s*=\s*["'](?:transport|custom|strict)["']\s*(?:\r?\n)?/i, "");
|
|
138
|
+
return `aeon:mode = "${headerMode}"\n${withoutModeHeader}`;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function sourceDiagnosticLineOffset(text, mode) {
|
|
142
|
+
const sourceText = String(text ?? "");
|
|
143
|
+
if (mode === "transport"
|
|
144
|
+
|| /^\s*aeon\s*:\s*header\s*=/im.test(sourceText)
|
|
145
|
+
|| /^\s*aeon:mode\s*=\s*["'](?:transport|custom|strict)["']/i.test(sourceText)) {
|
|
146
|
+
return 0;
|
|
147
|
+
}
|
|
148
|
+
return 1;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function visibleDiagnosticLine(item, lineOffset = 0) {
|
|
152
|
+
const line = item?.span?.start?.line;
|
|
153
|
+
if (!Number.isInteger(line)) return null;
|
|
154
|
+
const visibleLine = line - lineOffset;
|
|
155
|
+
return visibleLine > 0 ? visibleLine : null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function showFirstSourceError(items, lineOffset = 0) {
|
|
159
|
+
const first = items?.find((item) => visibleDiagnosticLine(item, lineOffset) !== null);
|
|
160
|
+
window.AeonWebHighlight?.setEditorDiagnosticLine?.(
|
|
161
|
+
source,
|
|
162
|
+
first ? visibleDiagnosticLine(first, lineOffset) : null,
|
|
163
|
+
first?.span?.start?.column
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function sourceForBuilderSeed(text) {
|
|
168
|
+
return String(text ?? "").replace(/^\s*aeon:mode\s*=\s*["'](?:transport|custom|strict)["']\s*(?:\r?\n)?/i, "");
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function formatAttributePath(key) {
|
|
172
|
+
const text = String(key || "attr");
|
|
173
|
+
return /^[A-Za-z_][A-Za-z0-9_]*$/.test(text) ? `.@.${text}` : `.@.[${JSON.stringify(text)}]`;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function memberPath(key) {
|
|
177
|
+
const text = String(key || "field");
|
|
178
|
+
return /^[A-Za-z_][A-Za-z0-9_]*$/.test(text) ? `.${text}` : `.[${JSON.stringify(text)}]`;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function formatPath(path) {
|
|
182
|
+
if (typeof path === "string") return path;
|
|
183
|
+
if (path && typeof path === "object" && typeof window.AeonFormatPath === "function") {
|
|
184
|
+
return window.AeonFormatPath(path);
|
|
185
|
+
}
|
|
186
|
+
if (!path?.segments) return "$";
|
|
187
|
+
let output = "";
|
|
188
|
+
for (const segment of path.segments) {
|
|
189
|
+
if (segment.type === "root") output = "$";
|
|
190
|
+
if (segment.type === "member") output += memberPath(segment.key);
|
|
191
|
+
if (segment.type === "index") output += `[${segment.index}]`;
|
|
192
|
+
if (segment.type === "attribute") output += formatAttributePath(segment.key);
|
|
193
|
+
}
|
|
194
|
+
return output || "$";
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function valueFromEvent(event) {
|
|
198
|
+
if (event.raw !== null && event.raw !== undefined) return event.raw;
|
|
199
|
+
const value = event.value;
|
|
200
|
+
if (value && typeof value === "object") return value.raw ?? value.value ?? undefined;
|
|
201
|
+
return value;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function renderValue(value) {
|
|
205
|
+
if (value === undefined) return "{...}";
|
|
206
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
207
|
+
return JSON.stringify(value);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function eventType(event) {
|
|
211
|
+
return event.valueType ?? event.type ?? event.value?.type ?? "";
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function attributeEntries(attributes) {
|
|
215
|
+
if (attributes instanceof Map) return Array.from(attributes.entries());
|
|
216
|
+
if (attributes && !Array.isArray(attributes) && typeof attributes === "object") return Object.entries(attributes);
|
|
217
|
+
return [];
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function pushRows(rows, event, path) {
|
|
221
|
+
rows.push({
|
|
222
|
+
path,
|
|
223
|
+
type: eventType(event),
|
|
224
|
+
datatype: event.datatype ?? "",
|
|
225
|
+
value: valueFromEvent(event),
|
|
226
|
+
event
|
|
227
|
+
});
|
|
228
|
+
for (const [key, entry] of attributeEntries(event?.annotations ?? event?.attributes)) {
|
|
229
|
+
pushRows(rows, entry, `${path}${formatAttributePath(key)}`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function rowsFromEvents(events) {
|
|
234
|
+
const rows = [];
|
|
235
|
+
for (const event of events ?? []) pushRows(rows, event, formatPath(event.path));
|
|
236
|
+
return rows;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function temporalKind(datatype) {
|
|
240
|
+
const base = String(datatype ?? "").split(/[<\[]/, 1)[0].toLowerCase();
|
|
241
|
+
return ["date", "time", "datetime", "wtc"].includes(base) ? base : "datetime";
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function scalarKind(row) {
|
|
245
|
+
const type = String(row.type ?? "");
|
|
246
|
+
if (["DateLiteral", "TimeLiteral", "DateTimeLiteral", "WTCDateTimeLiteral"].includes(type)) {
|
|
247
|
+
return temporalKind(row.datatype);
|
|
248
|
+
}
|
|
249
|
+
const kinds = {
|
|
250
|
+
StringLiteral: "string",
|
|
251
|
+
NumberLiteral: "number",
|
|
252
|
+
InfinityLiteral: "infinity",
|
|
253
|
+
NaNLiteral: "nan",
|
|
254
|
+
BooleanLiteral: "boolean",
|
|
255
|
+
NullLiteral: "null",
|
|
256
|
+
ToggleLiteral: "toggle",
|
|
257
|
+
HexLiteral: "hex",
|
|
258
|
+
RadixLiteral: "radix",
|
|
259
|
+
EncodingLiteral: "encoding",
|
|
260
|
+
SeparatorLiteral: "separator",
|
|
261
|
+
SymbolicLiteral: "symbol",
|
|
262
|
+
SansaAddressLiteral: "sansaAddress",
|
|
263
|
+
CloneReference: "referenceForm",
|
|
264
|
+
PointerReference: "referenceForm"
|
|
265
|
+
};
|
|
266
|
+
return kinds[type];
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function representationKind(row) {
|
|
270
|
+
const type = String(row.type ?? "");
|
|
271
|
+
const kinds = {
|
|
272
|
+
ObjectNode: "object",
|
|
273
|
+
ListNode: "list",
|
|
274
|
+
TupleLiteral: "tuple",
|
|
275
|
+
NodeLiteral: "node",
|
|
276
|
+
StringLiteral: "string",
|
|
277
|
+
NumberLiteral: "number",
|
|
278
|
+
InfinityLiteral: "infinity",
|
|
279
|
+
NaNLiteral: "nan",
|
|
280
|
+
BooleanLiteral: "boolean",
|
|
281
|
+
NullLiteral: "null",
|
|
282
|
+
ToggleLiteral: "toggle",
|
|
283
|
+
HexLiteral: "hex",
|
|
284
|
+
RadixLiteral: "radix",
|
|
285
|
+
EncodingLiteral: "encoding",
|
|
286
|
+
SeparatorLiteral: "separator",
|
|
287
|
+
SymbolicLiteral: "symbol",
|
|
288
|
+
SansaAddressLiteral: "sansa",
|
|
289
|
+
CloneReference: "cloneReference",
|
|
290
|
+
PointerReference: "pointerReference"
|
|
291
|
+
};
|
|
292
|
+
if (["DateLiteral", "TimeLiteral", "DateTimeLiteral", "WTCDateTimeLiteral"].includes(type)) {
|
|
293
|
+
return temporalKind(row.datatype);
|
|
294
|
+
}
|
|
295
|
+
return kinds[type] ?? type;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function queryBinding(row, selector) {
|
|
299
|
+
const binding = {
|
|
300
|
+
address: row.path,
|
|
301
|
+
children: [],
|
|
302
|
+
semanticType: row.datatype || undefined,
|
|
303
|
+
representationKind: representationKind(row),
|
|
304
|
+
scalarKind: scalarKind(row)
|
|
305
|
+
};
|
|
306
|
+
if (selector?.type === "member") binding.name = selector.name;
|
|
307
|
+
if (selector?.type === "position") binding.index = selector.index;
|
|
308
|
+
if (row.value !== undefined) binding.value = row.value;
|
|
309
|
+
if (row.type === "NumberLiteral") binding.numericLexeme = String(row.value);
|
|
310
|
+
if (row.type === "NullLiteral") binding.nullReason = row.value;
|
|
311
|
+
return binding;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function appendSelector(base, selector) {
|
|
315
|
+
if (selector.type === "member") return `${base}${memberPath(selector.name)}`;
|
|
316
|
+
if (selector.type === "position") return `${base}[${selector.index}]`;
|
|
317
|
+
return base;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
function parsePath(path) {
|
|
322
|
+
if (!state.parseAddress) return null;
|
|
323
|
+
const parsed = state.parseAddress(path);
|
|
324
|
+
return parsed.ok ? parsed.address : null;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function globToRegExp(pattern) {
|
|
328
|
+
let output = "^";
|
|
329
|
+
for (const char of String(pattern ?? "")) {
|
|
330
|
+
if (char === "*") output += ".*";
|
|
331
|
+
else if (char === "?") output += ".";
|
|
332
|
+
else output += char.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
333
|
+
}
|
|
334
|
+
return new RegExp(`${output}$`);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function selectorsEqual(left, right) {
|
|
338
|
+
if (!left || !right) return false;
|
|
339
|
+
if (left.type === "member") return right.type === "member" && right.name === left.name;
|
|
340
|
+
if (left.type === "position") return right.type === "position" && right.index === left.index;
|
|
341
|
+
if (left.type === "attributeSpace") return right.type === "attributeSpace";
|
|
342
|
+
if (left.type === "localSpace") return right.type === "localSpace" && right.name === left.name;
|
|
343
|
+
if (left.type === "namePattern") return right.type === "member" && globToRegExp(left.pattern).test(right.name);
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function selectorMatches(pattern, target) {
|
|
348
|
+
if (!pattern || !target) return false;
|
|
349
|
+
if (pattern.type === "positionRange") {
|
|
350
|
+
if (target.type !== "position") return false;
|
|
351
|
+
const start = pattern.start ?? 0;
|
|
352
|
+
const end = pattern.end ?? Number.POSITIVE_INFINITY;
|
|
353
|
+
return target.index >= start && target.index <= end;
|
|
354
|
+
}
|
|
355
|
+
return selectorsEqual(pattern, target);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function normalizeParentSelectors(selectors) {
|
|
359
|
+
const normalized = [];
|
|
360
|
+
for (const selector of selectors) {
|
|
361
|
+
if (selector.type !== "parent") {
|
|
362
|
+
normalized.push(selector);
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
365
|
+
if (normalized.length === 0) return null;
|
|
366
|
+
normalized.pop();
|
|
367
|
+
}
|
|
368
|
+
return normalized;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function isMetadataFilter(selector) {
|
|
372
|
+
return selector?.type === "semanticTypeFilter" || selector?.type === "representationKindFilter";
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function normalizeFilterValue(value) {
|
|
376
|
+
const normalized = String(value ?? "")
|
|
377
|
+
.trim()
|
|
378
|
+
.replace(/Literal$|Node$/i, "")
|
|
379
|
+
.toLowerCase();
|
|
380
|
+
return normalized === "symbolic" ? "symbol" : normalized;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function representationKindCandidates(row) {
|
|
384
|
+
const candidates = new Set();
|
|
385
|
+
for (const value of [row.type, row.event?.valueType, row.event?.type, row.event?.value?.type]) {
|
|
386
|
+
const normalized = normalizeFilterValue(value);
|
|
387
|
+
if (normalized) candidates.add(normalized);
|
|
388
|
+
}
|
|
389
|
+
if (candidates.has("integer") || candidates.has("float")) candidates.add("number");
|
|
390
|
+
if (candidates.has("boolean")) candidates.add("bool");
|
|
391
|
+
return candidates;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function semanticTypeCandidates(row) {
|
|
395
|
+
const candidates = new Set();
|
|
396
|
+
for (const value of [row.datatype, row.event?.datatype]) {
|
|
397
|
+
const normalized = normalizeFilterValue(value);
|
|
398
|
+
if (normalized) candidates.add(normalized);
|
|
399
|
+
}
|
|
400
|
+
return candidates;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function metadataFiltersMatch(selectors, row) {
|
|
404
|
+
for (const selector of selectors) {
|
|
405
|
+
if (selector.type === "representationKindFilter" && !representationKindCandidates(row).has(normalizeFilterValue(selector.name))) {
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
408
|
+
if (selector.type === "semanticTypeFilter" && !semanticTypeCandidates(row).has(normalizeFilterValue(selector.name))) {
|
|
409
|
+
return false;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
return true;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function matchSelectors(pattern, target, patternIndex = 0, targetIndex = 0) {
|
|
416
|
+
if (patternIndex >= pattern.length) return targetIndex >= target.length;
|
|
417
|
+
const selector = pattern[patternIndex];
|
|
418
|
+
if (isMetadataFilter(selector)) return matchSelectors(pattern, target, patternIndex + 1, targetIndex);
|
|
419
|
+
if (selector.type === "descendantExpansion") {
|
|
420
|
+
return matchSelectors(pattern, target, patternIndex + 1, targetIndex)
|
|
421
|
+
|| (targetIndex < target.length && matchSelectors(pattern, target, patternIndex, targetIndex + 1));
|
|
422
|
+
}
|
|
423
|
+
if (targetIndex >= target.length) return false;
|
|
424
|
+
if (selector.type === "directExpansion") return matchSelectors(pattern, target, patternIndex + 1, targetIndex + 1);
|
|
425
|
+
return selectorMatches(selector, target[targetIndex]) && matchSelectors(pattern, target, patternIndex + 1, targetIndex + 1);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
function hasSelectorSurface(parsedAddress) {
|
|
430
|
+
return parsedAddress.selectors.some((selector) => [
|
|
431
|
+
"childIdentity",
|
|
432
|
+
"directExpansion",
|
|
433
|
+
"descendantExpansion",
|
|
434
|
+
"positionRange",
|
|
435
|
+
"parent",
|
|
436
|
+
"namePattern",
|
|
437
|
+
"semanticTypeFilter",
|
|
438
|
+
"representationKindFilter"
|
|
439
|
+
].includes(selector.type));
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function addressWarnings(parsedAddress) {
|
|
443
|
+
const warnings = [];
|
|
444
|
+
if (parsedAddress.root.kind === "contextual") {
|
|
445
|
+
warnings.push("Contextual root uses the selected scope root.");
|
|
446
|
+
}
|
|
447
|
+
if (parsedAddress.qualifierExpression) {
|
|
448
|
+
warnings.push("Qualifier syntax parses, but extraction ignores qualifier semantics.");
|
|
449
|
+
}
|
|
450
|
+
return warnings;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
function resultLine(row) {
|
|
454
|
+
return `${row.path} [${row.type || "binding"}]${row.identity ? ` (identity: ${row.identity})` : ""} = ${renderValue(row.value)}`;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function renderMatches(matches, parsedAddress, warnings) {
|
|
458
|
+
result.classList.add("is-valid");
|
|
459
|
+
result.classList.remove("is-invalid");
|
|
460
|
+
const lines = matches.map(resultLine);
|
|
461
|
+
result.innerHTML = `
|
|
462
|
+
<div class="sansa-status">${matches.length} match${matches.length === 1 ? "" : "es"}</div>
|
|
463
|
+
<div class="sansa-result-grid">
|
|
464
|
+
<span>${parsedAddress.isExact && !hasSelectorSurface(parsedAddress) ? "path" : "selector"}</span>
|
|
465
|
+
<span>${parsedAddress.isExact ? "exact" : "non-exact"}</span>
|
|
466
|
+
<span>${state.rows.length} bindings</span>
|
|
467
|
+
</div>
|
|
468
|
+
${warnings.length > 0 ? `<p class="sansa-warning">${escapeHtml(warnings.join(" "))}</p>` : ""}
|
|
469
|
+
<pre class="sansa-selection-output">${escapeHtml(lines.join("\n") || "No matching paths.")}</pre>
|
|
470
|
+
`;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function queryValueText(value) {
|
|
474
|
+
if (value?.type === "bindingSet") {
|
|
475
|
+
if (value.bindings.length === 0) return "(empty Binding Set)";
|
|
476
|
+
return value.bindings.map((binding) => `${binding.address} = ${renderValue(binding.value)}`).join("\n");
|
|
477
|
+
}
|
|
478
|
+
if (value?.type === "object") return JSON.stringify(value.value);
|
|
479
|
+
if (value?.type === "scalar") return renderValue(value.value);
|
|
480
|
+
return String(value ?? "");
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
function renderQueryResults(evaluation) {
|
|
484
|
+
if (!evaluation.ok) {
|
|
485
|
+
const first = evaluation.errors?.[0];
|
|
486
|
+
result.classList.remove("is-valid");
|
|
487
|
+
result.classList.add("is-invalid");
|
|
488
|
+
result.innerHTML = `
|
|
489
|
+
<div class="sansa-status">Invalid query</div>
|
|
490
|
+
<p class="sansa-warning">${escapeHtml(first?.message ?? "Unable to evaluate SANSA query.")}</p>
|
|
491
|
+
`;
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
result.classList.add("is-valid");
|
|
496
|
+
result.classList.remove("is-invalid");
|
|
497
|
+
const lines = evaluation.results.map((entry) => {
|
|
498
|
+
const prefix = entry.candidateAddress ? `${entry.candidateAddress} => ` : "";
|
|
499
|
+
return `${prefix}${queryValueText(entry.value)}`;
|
|
500
|
+
});
|
|
501
|
+
result.innerHTML = `
|
|
502
|
+
<div class="sansa-status">${evaluation.results.length} result${evaluation.results.length === 1 ? "" : "s"}</div>
|
|
503
|
+
<div class="sansa-result-grid">
|
|
504
|
+
<span>query</span>
|
|
505
|
+
<span>evaluated</span>
|
|
506
|
+
<span>${state.rows.length} bindings</span>
|
|
507
|
+
</div>
|
|
508
|
+
<pre class="sansa-selection-output">${escapeHtml(lines.join("\n") || "No query results.")}</pre>
|
|
509
|
+
`;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
function sourceCaretPosition() {
|
|
513
|
+
const offset = source.selectionStart;
|
|
514
|
+
if (!Number.isInteger(offset)) return null;
|
|
515
|
+
const beforeCaret = source.value.slice(0, offset);
|
|
516
|
+
const lines = beforeCaret.split("\n");
|
|
517
|
+
return {
|
|
518
|
+
line: lines.length,
|
|
519
|
+
column: (lines[lines.length - 1]?.length ?? 0) + 1
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
function compareSourcePositions(left, right) {
|
|
524
|
+
if (left.line !== right.line) return left.line - right.line;
|
|
525
|
+
return left.column - right.column;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
function caretBindingPath() {
|
|
529
|
+
const caret = sourceCaretPosition();
|
|
530
|
+
if (!caret) return null;
|
|
531
|
+
let match = null;
|
|
532
|
+
let matchWidth = Number.POSITIVE_INFINITY;
|
|
533
|
+
|
|
534
|
+
for (const row of state.rows) {
|
|
535
|
+
const span = row.event?.span;
|
|
536
|
+
if (!span?.start || !span?.end) continue;
|
|
537
|
+
const start = {
|
|
538
|
+
line: span.start.line - state.diagnosticLineOffset,
|
|
539
|
+
column: span.start.column
|
|
540
|
+
};
|
|
541
|
+
const end = {
|
|
542
|
+
line: span.end.line - state.diagnosticLineOffset,
|
|
543
|
+
column: span.end.column
|
|
544
|
+
};
|
|
545
|
+
if (start.line < 1 || end.line < 1) continue;
|
|
546
|
+
if (compareSourcePositions(caret, start) < 0 || compareSourcePositions(caret, end) > 0) continue;
|
|
547
|
+
|
|
548
|
+
const width = Number.isInteger(span.end.offset) && Number.isInteger(span.start.offset)
|
|
549
|
+
? span.end.offset - span.start.offset
|
|
550
|
+
: Number.POSITIVE_INFINITY;
|
|
551
|
+
if (width <= matchWidth) {
|
|
552
|
+
match = row.path;
|
|
553
|
+
matchWidth = width;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
return match;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
function updateDiagnosticsForCaret() {
|
|
561
|
+
if (state.hasDiagnosticErrors) {
|
|
562
|
+
diagnostics.textContent = state.diagnosticLines.join("\n");
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
const lines = [...state.diagnosticLines];
|
|
566
|
+
if (document.activeElement === source) {
|
|
567
|
+
state.caretBindingPath = caretBindingPath();
|
|
568
|
+
}
|
|
569
|
+
if (state.caretBindingPath) lines.push(`SANSA address: ${state.caretBindingPath}`);
|
|
570
|
+
diagnostics.textContent = lines.length > 0 ? lines.join("\n") : "No diagnostics.";
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
function diagnosticDetails(error) {
|
|
574
|
+
return ["selectorIndex", "identity", "property", "budget", "limitKind", "limit", "observed"]
|
|
575
|
+
.filter(key => error[key] !== undefined).map(key => `${key}=${error[key]}`).join(", ");
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function renderDiagnostics(meta, warnings = [], lineOffset = 0, queryErrors = []) {
|
|
579
|
+
const lines = [];
|
|
580
|
+
let hasErrors = false;
|
|
581
|
+
for (const warning of warnings) lines.push(`[warning] ${warning}`);
|
|
582
|
+
for (const warning of meta?.warnings ?? []) {
|
|
583
|
+
lines.push(`[warning] ${warning.code ? `${warning.code}: ` : ""}${warning.message ?? String(warning)}`);
|
|
584
|
+
}
|
|
585
|
+
for (const error of meta?.errors ?? []) {
|
|
586
|
+
hasErrors = true;
|
|
587
|
+
const line = visibleDiagnosticLine(error, lineOffset);
|
|
588
|
+
const column = error?.span?.start?.column;
|
|
589
|
+
const location = line === null
|
|
590
|
+
? ""
|
|
591
|
+
: Number.isInteger(column) ? `[line ${line}, column ${column}] ` : `[line ${line}] `;
|
|
592
|
+
lines.push(`[error] ${location}${error.code ? `${error.code}: ` : ""}${error.message ?? String(error)}`);
|
|
593
|
+
}
|
|
594
|
+
for (const error of queryErrors) {
|
|
595
|
+
hasErrors = true;
|
|
596
|
+
const phase = error.phase ? `[${error.phase}] ` : "";
|
|
597
|
+
const context = diagnosticDetails(error);
|
|
598
|
+
lines.push(`[error] ${phase}${error.code ? `${error.code}: ` : ""}${error.message ?? String(error)}${context ? ` (${context})` : ""}`);
|
|
599
|
+
}
|
|
600
|
+
state.diagnosticLines = lines;
|
|
601
|
+
state.hasDiagnosticErrors = hasErrors;
|
|
602
|
+
state.diagnosticLineOffset = lineOffset;
|
|
603
|
+
updateDiagnosticsForCaret();
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
function renderParseError(parsed) {
|
|
607
|
+
const first = parsed.errors?.[0];
|
|
608
|
+
result.classList.remove("is-valid");
|
|
609
|
+
result.classList.add("is-invalid");
|
|
610
|
+
result.innerHTML = `
|
|
611
|
+
<div class="sansa-status">Invalid address</div>
|
|
612
|
+
<p class="sansa-warning">${escapeHtml(first?.message ?? "Unable to parse SANSA address.")}</p>
|
|
613
|
+
`;
|
|
614
|
+
const context = diagnosticDetails(first ?? {});
|
|
615
|
+
state.diagnosticLines = [`[error] ${first?.code ?? "SANSA_PARSE_ERROR"}: ${first?.message ?? "Invalid SANSA address."}${context ? ` (${context})` : ""}`];
|
|
616
|
+
state.hasDiagnosticErrors = true;
|
|
617
|
+
updateDiagnosticsForCaret();
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
async function resolveNow() {
|
|
621
|
+
const requestId = ++state.requestId;
|
|
622
|
+
loading.hidden = false;
|
|
623
|
+
try {
|
|
624
|
+
const { runRuntime, parseAddress, renderAddress, parseQuery, evaluateQuery, resolveAddress, createAeonNamespace, scopedNamespace, rowsFromNamespace, selectionRows } = await runtimeReady;
|
|
625
|
+
state.parseAddress = parseAddress;
|
|
626
|
+
state.resolveAddress = resolveAddress;
|
|
627
|
+
state.selectionRows = selectionRows;
|
|
628
|
+
state.parseQuery = parseQuery;
|
|
629
|
+
if (requestId !== state.requestId) return;
|
|
630
|
+
|
|
631
|
+
const mapping = mapMode(state.mode);
|
|
632
|
+
const lineOffset = sourceDiagnosticLineOffset(source.value, state.mode);
|
|
633
|
+
const runtimeResult = runRuntime(sourceForMode(source.value, state.mode), {
|
|
634
|
+
mode: mapping.runtimeMode,
|
|
635
|
+
datatypePolicy: mapping.datatypePolicy,
|
|
636
|
+
includeAnnotations: true,
|
|
637
|
+
output: "map"
|
|
638
|
+
});
|
|
639
|
+
showFirstSourceError(runtimeResult.meta?.errors, lineOffset);
|
|
640
|
+
if ((runtimeResult.meta?.errors?.length ?? 0) > 0) {
|
|
641
|
+
state.rows = [];
|
|
642
|
+
state.namespace = null;
|
|
643
|
+
result.classList.remove("is-valid");
|
|
644
|
+
result.classList.add("is-invalid");
|
|
645
|
+
result.innerHTML = '<div class="sansa-status">Invalid AEON source</div>';
|
|
646
|
+
renderDiagnostics(runtimeResult.meta, [], lineOffset);
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
const eventRows = new Map(rowsFromEvents(runtimeResult.aes ?? []).map(row => [row.path, row]));
|
|
650
|
+
const documentNamespace = createAeonNamespace(runtimeResult.aes ?? []);
|
|
651
|
+
state.rows = rowsFromNamespace(documentNamespace).map(row => ({...row, event: eventRows.get(row.path)?.event}));
|
|
652
|
+
state.namespace = null;
|
|
653
|
+
state.namespace = scopedNamespace(documentNamespace, shell.querySelector("[data-sansa-scope]").value);
|
|
654
|
+
renderComposerOptions();
|
|
655
|
+
|
|
656
|
+
if (state.view === "query") {
|
|
657
|
+
const evaluation = evaluateQuery(query.value.trim(), state.namespace, { addressActivation: "trusted", resolve: resolveOptions() });
|
|
658
|
+
renderQueryResults(evaluation);
|
|
659
|
+
renderDiagnostics(runtimeResult.meta, [], lineOffset, evaluation.ok ? [] : evaluation.errors);
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
const parsed = parseAddress(address.value.trim());
|
|
664
|
+
if (!parsed.ok) {
|
|
665
|
+
renderParseError(parsed);
|
|
666
|
+
return;
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
const canonical = renderAddress(parsed.address);
|
|
670
|
+
if (address.value.trim() !== canonical) address.dataset.canonical = canonical;
|
|
671
|
+
else delete address.dataset.canonical;
|
|
672
|
+
|
|
673
|
+
const warnings = addressWarnings(parsed.address);
|
|
674
|
+
const selection = resolveAddress(parsed.address, state.namespace, resolveOptions());
|
|
675
|
+
if (!selection.ok) {
|
|
676
|
+
result.classList.remove("is-valid");
|
|
677
|
+
result.classList.add("is-invalid");
|
|
678
|
+
result.innerHTML = '<div class="sansa-status">Resolution failed</div>';
|
|
679
|
+
renderDiagnostics(runtimeResult.meta, warnings, lineOffset, selection.errors);
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
const matches = selectionRows(selection, state.rows);
|
|
683
|
+
renderMatches(matches, parsed.address, warnings);
|
|
684
|
+
renderDiagnostics(runtimeResult.meta, warnings, lineOffset);
|
|
685
|
+
} catch (error) {
|
|
686
|
+
showFirstSourceError(null);
|
|
687
|
+
result.classList.remove("is-valid");
|
|
688
|
+
result.classList.add("is-invalid");
|
|
689
|
+
result.innerHTML = "<div class=\"sansa-status\">Runtime error</div>";
|
|
690
|
+
state.diagnosticLines = [error instanceof Error ? error.message : String(error)];
|
|
691
|
+
state.hasDiagnosticErrors = true;
|
|
692
|
+
updateDiagnosticsForCaret();
|
|
693
|
+
} finally {
|
|
694
|
+
if (requestId === state.requestId) loading.hidden = true;
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
function scheduleResolve() {
|
|
699
|
+
window.clearTimeout(scheduleResolve.timer);
|
|
700
|
+
scheduleResolve.timer = window.setTimeout(resolveNow, 120);
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
function selectorAppend(selector) {
|
|
704
|
+
if (selector.type === "member") return memberPath(selector.name);
|
|
705
|
+
if (selector.type === "position") return `[${selector.index}]`;
|
|
706
|
+
if (selector.type === "attributeSpace") return ".@";
|
|
707
|
+
return "";
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
function optionLabel(option) {
|
|
711
|
+
if (option.kind === "directExpansion") return "*";
|
|
712
|
+
if (option.kind === "descendantExpansion") return "**";
|
|
713
|
+
if (option.kind === "attributeSpace") return "@";
|
|
714
|
+
if (option.kind === "childIdentity") return option.label;
|
|
715
|
+
if (option.kind === "representationKindFilter") return `%${option.label}`;
|
|
716
|
+
if (option.kind === "semanticTypeFilter") return `#${option.label}`;
|
|
717
|
+
return option.label;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
function optionDescription(option) {
|
|
721
|
+
if (option.kind === "directExpansion") return "direct children";
|
|
722
|
+
if (option.kind === "descendantExpansion") return "descendants";
|
|
723
|
+
if (option.kind === "attributeSpace") return "attribute space";
|
|
724
|
+
if (option.kind === "childIdentity") return "child identity";
|
|
725
|
+
if (option.kind === "member") return "member";
|
|
726
|
+
if (option.kind === "position") return "position";
|
|
727
|
+
if (option.kind === "representationKindFilter") return "kind filter";
|
|
728
|
+
if (option.kind === "semanticTypeFilter") return "type filter";
|
|
729
|
+
return "segment";
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
function optionValue(base, option) {
|
|
733
|
+
const normalizedBase = base.trim() || "$";
|
|
734
|
+
if (option.kind === "directExpansion") return `${normalizedBase}.*`;
|
|
735
|
+
if (option.kind === "descendantExpansion") return `${normalizedBase}.**`;
|
|
736
|
+
if (option.kind === "attributeSpace") return `${normalizedBase}.@`;
|
|
737
|
+
if (option.kind === "representationKindFilter") return `${normalizedBase}%${option.label}`;
|
|
738
|
+
if (option.kind === "semanticTypeFilter") return `${normalizedBase}#${option.label}`;
|
|
739
|
+
return `${normalizedBase}${option.append}`;
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
function hasFilter(addressText, type) {
|
|
743
|
+
const parsed = parsePath(addressText);
|
|
744
|
+
return parsed?.selectors.some((selector) => selector.type === type) === true;
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
function resolveOptions() {
|
|
748
|
+
const value = shell.querySelector("[data-sansa-inspections]").value;
|
|
749
|
+
const maxIdentityInspections = Number(value);
|
|
750
|
+
if (!value.trim() || !Number.isSafeInteger(maxIdentityInspections) || maxIdentityInspections < 0) {
|
|
751
|
+
throw new Error("Identity inspections must be a non-negative safe integer.");
|
|
752
|
+
}
|
|
753
|
+
const propertyValue = shell.querySelector("[data-sansa-property-inspections]").value;
|
|
754
|
+
const maxPropertyInspections = Number(propertyValue);
|
|
755
|
+
if (!propertyValue.trim() || !Number.isInteger(maxPropertyInspections) || maxPropertyInspections < 0 || maxPropertyInspections > 1000000) {
|
|
756
|
+
throw new Error("Property inspections must be an integer from 0 through 1000000.");
|
|
757
|
+
}
|
|
758
|
+
return {maxIdentityInspections, maxPropertyInspections, maxBindings: 1000};
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
function rowsMatchingAddress(addressText) {
|
|
762
|
+
if (!state.namespace || !state.resolveAddress) return [];
|
|
763
|
+
const selection = state.resolveAddress(addressText, state.namespace, resolveOptions());
|
|
764
|
+
return selection.ok ? state.selectionRows(selection, state.rows) : [];
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
function exactPrefixMatch(prefix, target) {
|
|
768
|
+
if (target.length <= prefix.length) return false;
|
|
769
|
+
for (let index = 0; index < prefix.length; index += 1) {
|
|
770
|
+
if (!selectorsEqual(prefix[index], target[index])) return false;
|
|
771
|
+
}
|
|
772
|
+
return true;
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
function representationFilterOptions(base) {
|
|
776
|
+
if (hasFilter(base, "representationKindFilter")) return [];
|
|
777
|
+
const matches = rowsMatchingAddress(base);
|
|
778
|
+
const values = new Set();
|
|
779
|
+
for (const row of matches) {
|
|
780
|
+
for (const value of representationKindCandidates(row)) {
|
|
781
|
+
if (/^[a-z_][a-z0-9_]*$/.test(value)) values.add(value);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
return Array.from(values)
|
|
785
|
+
.sort((left, right) => left.localeCompare(right))
|
|
786
|
+
.map((label) => ({ kind: "representationKindFilter", label }));
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
function semanticFilterOptions(base) {
|
|
790
|
+
if (hasFilter(base, "semanticTypeFilter")) return [];
|
|
791
|
+
const matches = rowsMatchingAddress(base);
|
|
792
|
+
const values = new Set();
|
|
793
|
+
for (const row of matches) {
|
|
794
|
+
for (const value of semanticTypeCandidates(row)) {
|
|
795
|
+
if (/^[a-z_][a-z0-9_]*$/.test(value)) values.add(value);
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
return Array.from(values)
|
|
799
|
+
.sort((left, right) => left.localeCompare(right))
|
|
800
|
+
.map((label) => ({ kind: "semanticTypeFilter", label }));
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
function childOptions(base) {
|
|
804
|
+
const options = new Map([
|
|
805
|
+
["directExpansion:*", {kind: "directExpansion", label: "Direct children"}],
|
|
806
|
+
["descendantExpansion:**", {kind: "descendantExpansion", label: "Descendants"}]
|
|
807
|
+
]);
|
|
808
|
+
for (const parent of rowsMatchingAddress(base)) {
|
|
809
|
+
for (const child of parent.binding.children ?? []) {
|
|
810
|
+
const append = child.name !== undefined ? memberPath(child.name) : `[${child.index}]`;
|
|
811
|
+
options.set(append, {kind: child.name !== undefined ? "member" : "position", label: append.replace(/^\./, ""), append});
|
|
812
|
+
if (child.identity) {
|
|
813
|
+
const label = String.fromCharCode(92) + child.identity + String.fromCharCode(92);
|
|
814
|
+
options.set(label, {kind: "childIdentity", label, append: "." + label});
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
if (parent.binding.attributeSpace) options.set("@", {kind: "attributeSpace", label: "@", append: ".@"});
|
|
818
|
+
}
|
|
819
|
+
return Array.from(options.values());
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
function renderComposerOptions() {
|
|
823
|
+
if (!composerInput || !composerOptions) return;
|
|
824
|
+
const base = composerInput.value.trim() || "$";
|
|
825
|
+
const options = [...childOptions(base), ...representationFilterOptions(base), ...semanticFilterOptions(base)];
|
|
826
|
+
composerOptions.innerHTML = options.map((option) => `
|
|
827
|
+
<button class="sansa-composer-option" type="button" data-sansa-option="${escapeHtml(optionValue(base, option))}">
|
|
828
|
+
<span>${escapeHtml(optionLabel(option))}</span>
|
|
829
|
+
<small>${escapeHtml(optionDescription(option))}</small>
|
|
830
|
+
</button>
|
|
831
|
+
`).join("");
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
const queryClauseDetails = {
|
|
835
|
+
from: {
|
|
836
|
+
title: "From",
|
|
837
|
+
label: "Source address",
|
|
838
|
+
help: "Choose the source bindings evaluated by the query.",
|
|
839
|
+
requirement: "Required",
|
|
840
|
+
placeholder: "$.inventory.items.*"
|
|
841
|
+
},
|
|
842
|
+
where: {
|
|
843
|
+
title: "Where",
|
|
844
|
+
label: "Predicate",
|
|
845
|
+
help: "Keep only candidates for which this Boolean expression is true.",
|
|
846
|
+
requirement: "Optional",
|
|
847
|
+
placeholder: ".qty >= 4"
|
|
848
|
+
},
|
|
849
|
+
order: {
|
|
850
|
+
title: "Order by",
|
|
851
|
+
label: "Sort keys",
|
|
852
|
+
help: "Order candidates using one or more expressions and directions.",
|
|
853
|
+
requirement: "Optional",
|
|
854
|
+
placeholder: ".name asc"
|
|
855
|
+
},
|
|
856
|
+
offset: {
|
|
857
|
+
title: "Offset",
|
|
858
|
+
label: "Rows to skip",
|
|
859
|
+
help: "Skip a non-negative number of ordered candidates.",
|
|
860
|
+
requirement: "Optional",
|
|
861
|
+
placeholder: "0"
|
|
862
|
+
},
|
|
863
|
+
limit: {
|
|
864
|
+
title: "Limit",
|
|
865
|
+
label: "Maximum rows",
|
|
866
|
+
help: "Cap the number of candidates projected by select.",
|
|
867
|
+
requirement: "Optional",
|
|
868
|
+
placeholder: "10"
|
|
869
|
+
},
|
|
870
|
+
select: {
|
|
871
|
+
title: "Select",
|
|
872
|
+
label: "Projection",
|
|
873
|
+
help: "Choose the value or object returned for each candidate.",
|
|
874
|
+
requirement: "Required",
|
|
875
|
+
placeholder: "{ sku = .sku name = .name }"
|
|
876
|
+
}
|
|
877
|
+
};
|
|
878
|
+
|
|
879
|
+
function buildQueryDraft() {
|
|
880
|
+
const draft = state.queryDraft;
|
|
881
|
+
const lines = [`from ${draft.from.trim() || "$"}`];
|
|
882
|
+
if (draft.where.trim()) lines.push(`where ${draft.where.trim()}`);
|
|
883
|
+
if (draft.order.trim()) lines.push(`order by ${draft.order.trim()}`);
|
|
884
|
+
if (draft.offset.trim()) lines.push(`offset ${draft.offset.trim()}`);
|
|
885
|
+
if (draft.limit.trim()) lines.push(`limit ${draft.limit.trim()}`);
|
|
886
|
+
lines.push(`select ${draft.select.trim() || "."}`);
|
|
887
|
+
return lines.join("\n");
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
function resetWhereBuilder() {
|
|
891
|
+
state.whereBuilder = {
|
|
892
|
+
step: "root",
|
|
893
|
+
field: null,
|
|
894
|
+
operator: null,
|
|
895
|
+
functionName: null,
|
|
896
|
+
temporalTarget: null
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
function seedQueryDraft(parseQuery) {
|
|
901
|
+
resetWhereBuilder();
|
|
902
|
+
const parsed = parseQuery(query.value.trim());
|
|
903
|
+
if (!parsed.ok) {
|
|
904
|
+
state.queryDraft = { from: "$", where: "", order: "", offset: "", limit: "", select: "." };
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
const model = parsed.query;
|
|
908
|
+
state.queryDraft = {
|
|
909
|
+
from: model.from.source === "address" ? model.from.address.canonical : model.from.expression,
|
|
910
|
+
where: model.where?.expression ?? "",
|
|
911
|
+
order: model.orderBy?.keys.map((key) => `${key.expression} ${key.direction}`).join(", ") ?? "",
|
|
912
|
+
offset: model.offset ? String(model.offset.value) : "",
|
|
913
|
+
limit: model.limit ? String(model.limit.value) : "",
|
|
914
|
+
select: model.select.expression
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
function querySourceOptions() {
|
|
919
|
+
const base = state.queryDraft.from.trim() || "$";
|
|
920
|
+
const parsed = parsePath(base);
|
|
921
|
+
const options = [];
|
|
922
|
+
if (base !== "$") {
|
|
923
|
+
options.push({ value: "$", label: "$", description: "restart from the document root" });
|
|
924
|
+
}
|
|
925
|
+
if (!parsed) return options;
|
|
926
|
+
return [
|
|
927
|
+
...options,
|
|
928
|
+
...[
|
|
929
|
+
...childOptions(base),
|
|
930
|
+
...representationFilterOptions(base),
|
|
931
|
+
...semanticFilterOptions(base)
|
|
932
|
+
].map((option) => ({
|
|
933
|
+
value: optionValue(base, option),
|
|
934
|
+
label: optionLabel(option),
|
|
935
|
+
description: optionDescription(option)
|
|
936
|
+
}))
|
|
937
|
+
];
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
function queryRelativeFields() {
|
|
941
|
+
const sourceText = state.queryDraft.from.trim() || "$";
|
|
942
|
+
const parsedSource = parsePath(sourceText);
|
|
943
|
+
if (!parsedSource || parsedSource.root.kind !== "absolute") return [];
|
|
944
|
+
const parents = hasSelectorSurface(parsedSource)
|
|
945
|
+
? rowsMatchingAddress(sourceText).map((row) => parsePath(row.path)).filter(Boolean)
|
|
946
|
+
: [parsedSource];
|
|
947
|
+
const fields = new Map();
|
|
948
|
+
|
|
949
|
+
for (const row of state.rows) {
|
|
950
|
+
const rowAddress = parsePath(row.path);
|
|
951
|
+
if (!rowAddress) continue;
|
|
952
|
+
for (const parent of parents) {
|
|
953
|
+
if (!exactPrefixMatch(parent.selectors, rowAddress.selectors)) continue;
|
|
954
|
+
if (rowAddress.selectors.length !== parent.selectors.length + 1) continue;
|
|
955
|
+
const selector = rowAddress.selectors[parent.selectors.length];
|
|
956
|
+
if (!selector || !["member", "position"].includes(selector.type)) continue;
|
|
957
|
+
const append = selectorAppend(selector);
|
|
958
|
+
const expression = append.startsWith("[") ? `.${append}` : append;
|
|
959
|
+
const existing = fields.get(expression);
|
|
960
|
+
if (existing) {
|
|
961
|
+
existing.rows.push(row);
|
|
962
|
+
} else {
|
|
963
|
+
fields.set(expression, {
|
|
964
|
+
expression,
|
|
965
|
+
label: selector.type === "member" ? selector.name : `[${selector.index}]`,
|
|
966
|
+
row,
|
|
967
|
+
rows: [row]
|
|
968
|
+
});
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
return Array.from(fields.values()).slice(0, 16);
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
function queryComparisonLiteral(row) {
|
|
976
|
+
const kind = scalarKind(row);
|
|
977
|
+
if (["number", "radix", "hex"].includes(kind)) return "0";
|
|
978
|
+
if (kind === "boolean") return "true";
|
|
979
|
+
if (kind === "toggle") return "yes";
|
|
980
|
+
if (["date", "time", "datetime", "wtc"].includes(kind) && row.value !== undefined) return String(row.value);
|
|
981
|
+
return '"value"';
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
function queryAuthoredLiteral(row) {
|
|
985
|
+
if (row.value === undefined) return queryComparisonLiteral(row);
|
|
986
|
+
const kind = scalarKind(row);
|
|
987
|
+
if (kind === "string") return JSON.stringify(String(row.value));
|
|
988
|
+
if (kind === "boolean") return row.value ? "true" : "false";
|
|
989
|
+
if (kind === "null") return "null";
|
|
990
|
+
return String(row.value);
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
function whereClauseOptionValues(fields) {
|
|
994
|
+
const builder = state.whereBuilder;
|
|
995
|
+
if (builder.step === "operator" && builder.field) {
|
|
996
|
+
const kind = scalarKind(builder.field.row);
|
|
997
|
+
const ordered = !["boolean", "null", "toggle", "referenceForm"].includes(kind);
|
|
998
|
+
const temporal = ["date", "time", "datetime", "wtc"].includes(kind);
|
|
999
|
+
return [
|
|
1000
|
+
{ action: "where-back-root", value: "", label: "Back", description: "choose another field or predicate" },
|
|
1001
|
+
...(temporal ? [{
|
|
1002
|
+
action: "where-temporal",
|
|
1003
|
+
value: "",
|
|
1004
|
+
label: "Temporal relation",
|
|
1005
|
+
description: "compare completion sets"
|
|
1006
|
+
}] : []),
|
|
1007
|
+
{ action: "where-operator", operator: "==", value: "", label: "Equals", description: "==" },
|
|
1008
|
+
{ action: "where-operator", operator: "!=", value: "", label: "Does not equal", description: "!=" },
|
|
1009
|
+
...(ordered ? [
|
|
1010
|
+
{ action: "where-operator", operator: ">", value: "", label: "Greater than", description: ">" },
|
|
1011
|
+
{ action: "where-operator", operator: ">=", value: "", label: "Greater than or equal", description: ">=" },
|
|
1012
|
+
{ action: "where-operator", operator: "<", value: "", label: "Less than", description: "<" },
|
|
1013
|
+
{ action: "where-operator", operator: "<=", value: "", label: "Less than or equal", description: "<=" }
|
|
1014
|
+
] : [])
|
|
1015
|
+
];
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
if (builder.step === "temporal-target" && builder.field) {
|
|
1019
|
+
const options = [
|
|
1020
|
+
{ action: "where-back-operator", value: "", label: "Back", description: "choose another operator" }
|
|
1021
|
+
];
|
|
1022
|
+
const temporalFields = fields.filter((field) =>
|
|
1023
|
+
["date", "time", "datetime", "wtc"].includes(scalarKind(field.row))
|
|
1024
|
+
&& field.expression !== builder.field.expression
|
|
1025
|
+
);
|
|
1026
|
+
for (const field of temporalFields) {
|
|
1027
|
+
options.push({
|
|
1028
|
+
action: "where-temporal-target",
|
|
1029
|
+
temporalTarget: { expression: field.expression, label: field.label },
|
|
1030
|
+
value: "",
|
|
1031
|
+
label: field.label,
|
|
1032
|
+
description: `${field.expression} · ${scalarKind(field.row)}`
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
const literals = new Map();
|
|
1036
|
+
for (const field of fields) {
|
|
1037
|
+
const kind = scalarKind(field.row);
|
|
1038
|
+
if (!["date", "time", "datetime", "wtc"].includes(kind)) continue;
|
|
1039
|
+
for (const row of field.rows ?? [field.row]) {
|
|
1040
|
+
const literal = queryAuthoredLiteral(row);
|
|
1041
|
+
if (literals.has(`${kind}:${literal}`)) continue;
|
|
1042
|
+
literals.set(`${kind}:${literal}`, {
|
|
1043
|
+
action: "where-temporal-target",
|
|
1044
|
+
temporalTarget: { expression: literal, label: literal },
|
|
1045
|
+
value: "",
|
|
1046
|
+
label: literal,
|
|
1047
|
+
description: `${kind} value from the AEON source`
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
return [...options, ...Array.from(literals.values()).slice(0, 12)];
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
if (builder.step === "temporal-relation" && builder.field && builder.temporalTarget) {
|
|
1055
|
+
const relations = [
|
|
1056
|
+
["equal", "Equal"],
|
|
1057
|
+
["before", "Before"],
|
|
1058
|
+
["after", "After"],
|
|
1059
|
+
["contains", "Contains"],
|
|
1060
|
+
["containedBy", "Contained by"],
|
|
1061
|
+
["overlaps", "Overlaps"],
|
|
1062
|
+
["incomparable", "Incomparable"]
|
|
1063
|
+
];
|
|
1064
|
+
return [
|
|
1065
|
+
{ action: "where-back-temporal-target", value: "", label: "Back", description: "choose another temporal binding" },
|
|
1066
|
+
...relations.map(([relation, label]) => ({
|
|
1067
|
+
action: "where-temporal-relation",
|
|
1068
|
+
relation,
|
|
1069
|
+
value: "",
|
|
1070
|
+
label,
|
|
1071
|
+
description: relation
|
|
1072
|
+
}))
|
|
1073
|
+
];
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
if (builder.step === "value" && builder.field && builder.operator) {
|
|
1077
|
+
const values = new Map();
|
|
1078
|
+
for (const row of builder.field.rows ?? [builder.field.row]) {
|
|
1079
|
+
const literal = queryAuthoredLiteral(row);
|
|
1080
|
+
if (!values.has(literal)) values.set(literal, {
|
|
1081
|
+
action: "where-value",
|
|
1082
|
+
literal,
|
|
1083
|
+
value: "",
|
|
1084
|
+
label: literal,
|
|
1085
|
+
description: "value from the AEON source"
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
1088
|
+
const example = queryComparisonLiteral(builder.field.row);
|
|
1089
|
+
if (!values.has(example)) values.set(example, {
|
|
1090
|
+
action: "where-value",
|
|
1091
|
+
literal: example,
|
|
1092
|
+
value: "",
|
|
1093
|
+
label: example,
|
|
1094
|
+
description: "example value"
|
|
1095
|
+
});
|
|
1096
|
+
return [
|
|
1097
|
+
{ action: "where-back-operator", value: "", label: "Back", description: "choose another operator" },
|
|
1098
|
+
...Array.from(values.values()).slice(0, 16)
|
|
1099
|
+
];
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
if (builder.step === "function-field" && builder.functionName) {
|
|
1103
|
+
const options = [
|
|
1104
|
+
{ action: "where-back-root", value: "", label: "Back", description: "choose another field or predicate" }
|
|
1105
|
+
];
|
|
1106
|
+
if (builder.functionName === "isValue") {
|
|
1107
|
+
options.push({
|
|
1108
|
+
action: "where-function-field",
|
|
1109
|
+
fieldExpression: ".",
|
|
1110
|
+
value: "",
|
|
1111
|
+
label: "Current binding",
|
|
1112
|
+
description: "."
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
1115
|
+
for (const field of fields) {
|
|
1116
|
+
options.push({
|
|
1117
|
+
action: "where-function-field",
|
|
1118
|
+
fieldExpression: field.expression,
|
|
1119
|
+
value: "",
|
|
1120
|
+
label: field.label,
|
|
1121
|
+
description: field.expression
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
1124
|
+
return options;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
return [
|
|
1128
|
+
{ action: "where-remove", value: "", label: "Remove clause", description: "omit this optional clause" },
|
|
1129
|
+
...fields.map((field) => ({
|
|
1130
|
+
action: "where-field",
|
|
1131
|
+
fieldExpression: field.expression,
|
|
1132
|
+
value: "",
|
|
1133
|
+
label: field.label,
|
|
1134
|
+
description: field.expression,
|
|
1135
|
+
field
|
|
1136
|
+
})),
|
|
1137
|
+
{ action: "where-function", functionName: "isValue", value: "", label: "isValue", description: "require a concrete value" },
|
|
1138
|
+
{ action: "where-function", functionName: "exists", value: "", label: "exists", description: "require a binding to exist" }
|
|
1139
|
+
];
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
function queryClauseOptionValues(clause) {
|
|
1143
|
+
const fields = queryRelativeFields();
|
|
1144
|
+
const optional = !["from", "select"].includes(clause)
|
|
1145
|
+
? [{ value: "", label: "Remove clause", description: "omit this optional clause" }]
|
|
1146
|
+
: [];
|
|
1147
|
+
if (clause === "from") return querySourceOptions();
|
|
1148
|
+
if (clause === "where") return whereClauseOptionValues(fields);
|
|
1149
|
+
if (clause === "select") {
|
|
1150
|
+
const options = [{ value: ".", label: ".", description: "current binding" }];
|
|
1151
|
+
for (const field of fields) {
|
|
1152
|
+
options.push({ value: field.expression, label: field.label, description: "project this field" });
|
|
1153
|
+
}
|
|
1154
|
+
if (fields.length > 0) {
|
|
1155
|
+
const projection = fields.slice(0, 6)
|
|
1156
|
+
.map((field) => `${String(field.label).replace(/[^A-Za-z0-9_]/g, "_")} = ${field.expression}`)
|
|
1157
|
+
.join(" ");
|
|
1158
|
+
options.push({ value: `{ ${projection} }`, label: "Object projection", description: "project the visible fields" });
|
|
1159
|
+
}
|
|
1160
|
+
const temporal = fields.filter((field) => ["date", "time", "datetime", "wtc"].includes(scalarKind(field.row)));
|
|
1161
|
+
if (temporal.length >= 2) {
|
|
1162
|
+
options.push({
|
|
1163
|
+
value: `{ relation = temporalRelation(${temporal[0].expression}, ${temporal[1].expression}) }`,
|
|
1164
|
+
label: "Temporal relation",
|
|
1165
|
+
description: "return a completion-set relation"
|
|
1166
|
+
});
|
|
1167
|
+
}
|
|
1168
|
+
return options;
|
|
1169
|
+
}
|
|
1170
|
+
if (clause === "order") {
|
|
1171
|
+
return [
|
|
1172
|
+
...optional,
|
|
1173
|
+
...fields.flatMap((field) => [
|
|
1174
|
+
{ value: `${field.expression} asc`, label: `${field.label} ascending`, description: "lowest first" },
|
|
1175
|
+
{ value: `${field.expression} desc`, label: `${field.label} descending`, description: "highest first" }
|
|
1176
|
+
])
|
|
1177
|
+
];
|
|
1178
|
+
}
|
|
1179
|
+
if (clause === "offset") {
|
|
1180
|
+
return [...optional, ...[0, 1, 10, 25].map((value) => ({ value: String(value), label: String(value), description: "rows to skip" }))];
|
|
1181
|
+
}
|
|
1182
|
+
if (clause === "limit") {
|
|
1183
|
+
return [...optional, ...[1, 10, 25, 100].map((value) => ({ value: String(value), label: String(value), description: "maximum results" }))];
|
|
1184
|
+
}
|
|
1185
|
+
return optional;
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
function renderQueryPreview() {
|
|
1189
|
+
if (!queryPreview || !queryValidation) return;
|
|
1190
|
+
const text = buildQueryDraft();
|
|
1191
|
+
queryPreview.textContent = text;
|
|
1192
|
+
const parsed = state.parseQuery?.(text);
|
|
1193
|
+
const valid = parsed?.ok === true;
|
|
1194
|
+
queryValidation.classList.toggle("is-invalid", !valid);
|
|
1195
|
+
queryValidation.textContent = valid
|
|
1196
|
+
? "Valid SANSA query."
|
|
1197
|
+
: parsed?.errors?.[0]?.message ?? "Complete the required clauses.";
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
function syncQueryClauseButtons() {
|
|
1201
|
+
queryClauseButtons.forEach((button) => {
|
|
1202
|
+
const clause = button.dataset.sansaQueryClause;
|
|
1203
|
+
const active = clause === state.queryComposerClause;
|
|
1204
|
+
const hasValue = Boolean(state.queryDraft[clause]?.trim());
|
|
1205
|
+
button.classList.toggle("is-active", active);
|
|
1206
|
+
button.classList.toggle("has-value", hasValue);
|
|
1207
|
+
button.setAttribute("aria-pressed", active ? "true" : "false");
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
function whereBuilderHelp() {
|
|
1212
|
+
const builder = state.whereBuilder;
|
|
1213
|
+
if (builder.step === "operator" && builder.field) {
|
|
1214
|
+
return `Choose how to compare ${builder.field.label}.`;
|
|
1215
|
+
}
|
|
1216
|
+
if (builder.step === "value" && builder.field) {
|
|
1217
|
+
return `Choose a value for ${builder.field.label}, or edit the predicate directly.`;
|
|
1218
|
+
}
|
|
1219
|
+
if (builder.step === "temporal-target" && builder.field) {
|
|
1220
|
+
return `Choose the temporal binding compared with ${builder.field.label}.`;
|
|
1221
|
+
}
|
|
1222
|
+
if (builder.step === "temporal-relation" && builder.field && builder.temporalTarget) {
|
|
1223
|
+
return `Choose how ${builder.field.label} relates to ${builder.temporalTarget.label}.`;
|
|
1224
|
+
}
|
|
1225
|
+
if (builder.step === "function-field" && builder.functionName) {
|
|
1226
|
+
return `Choose the binding passed to ${builder.functionName}().`;
|
|
1227
|
+
}
|
|
1228
|
+
return queryClauseDetails.where.help;
|
|
1229
|
+
}
|
|
1230
|
+
|
|
1231
|
+
function renderQueryClauseOptions() {
|
|
1232
|
+
if (!queryClauseOptions) return;
|
|
1233
|
+
const options = queryClauseOptionValues(state.queryComposerClause);
|
|
1234
|
+
state.queryRenderedOptions = options;
|
|
1235
|
+
queryClauseOptions.innerHTML = options.map((option, index) => `
|
|
1236
|
+
<button class="sansa-composer-option" type="button" data-sansa-query-option-index="${index}">
|
|
1237
|
+
<span>${escapeHtml(option.label)}</span>
|
|
1238
|
+
<small>${escapeHtml(option.description)}</small>
|
|
1239
|
+
</button>
|
|
1240
|
+
`).join("");
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
function renderQueryComposer() {
|
|
1244
|
+
const clause = state.queryComposerClause;
|
|
1245
|
+
const details = queryClauseDetails[clause];
|
|
1246
|
+
if (!details || !queryClauseInput) return;
|
|
1247
|
+
if (queryClauseTitle) queryClauseTitle.textContent = details.title;
|
|
1248
|
+
if (queryClauseHelp) queryClauseHelp.textContent = clause === "where" ? whereBuilderHelp() : details.help;
|
|
1249
|
+
if (queryClauseRequirement) queryClauseRequirement.textContent = details.requirement;
|
|
1250
|
+
if (queryClauseLabel) queryClauseLabel.textContent = details.label;
|
|
1251
|
+
queryClauseInput.placeholder = details.placeholder;
|
|
1252
|
+
queryClauseInput.value = state.queryDraft[clause] ?? "";
|
|
1253
|
+
queryClauseInput.inputMode = ["offset", "limit"].includes(clause) ? "numeric" : "text";
|
|
1254
|
+
syncQueryClauseButtons();
|
|
1255
|
+
renderQueryClauseOptions();
|
|
1256
|
+
renderQueryPreview();
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
function applyQueryClauseOption(option) {
|
|
1260
|
+
const clause = state.queryComposerClause;
|
|
1261
|
+
if (clause !== "where" || !option.action) {
|
|
1262
|
+
state.queryDraft[clause] = option.value ?? "";
|
|
1263
|
+
if (clause === "from") resetWhereBuilder();
|
|
1264
|
+
return;
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
if (option.action === "where-remove") {
|
|
1268
|
+
state.queryDraft.where = "";
|
|
1269
|
+
resetWhereBuilder();
|
|
1270
|
+
return;
|
|
1271
|
+
}
|
|
1272
|
+
if (option.action === "where-field") {
|
|
1273
|
+
state.whereBuilder = { step: "operator", field: option.field, operator: null, functionName: null, temporalTarget: null };
|
|
1274
|
+
state.queryDraft.where = option.field.expression;
|
|
1275
|
+
return;
|
|
1276
|
+
}
|
|
1277
|
+
if (option.action === "where-operator") {
|
|
1278
|
+
state.whereBuilder.step = "value";
|
|
1279
|
+
state.whereBuilder.operator = option.operator;
|
|
1280
|
+
state.queryDraft.where = `${state.whereBuilder.field.expression} ${option.operator}`;
|
|
1281
|
+
return;
|
|
1282
|
+
}
|
|
1283
|
+
if (option.action === "where-value") {
|
|
1284
|
+
const { field, operator } = state.whereBuilder;
|
|
1285
|
+
state.queryDraft.where = `${field.expression} ${operator} ${option.literal}`;
|
|
1286
|
+
resetWhereBuilder();
|
|
1287
|
+
return;
|
|
1288
|
+
}
|
|
1289
|
+
if (option.action === "where-temporal") {
|
|
1290
|
+
state.whereBuilder.step = "temporal-target";
|
|
1291
|
+
state.whereBuilder.temporalTarget = null;
|
|
1292
|
+
state.queryDraft.where = `temporalRelation(${state.whereBuilder.field.expression}, )`;
|
|
1293
|
+
return;
|
|
1294
|
+
}
|
|
1295
|
+
if (option.action === "where-temporal-target") {
|
|
1296
|
+
state.whereBuilder.step = "temporal-relation";
|
|
1297
|
+
state.whereBuilder.temporalTarget = option.temporalTarget;
|
|
1298
|
+
state.queryDraft.where = `temporalRelation(${state.whereBuilder.field.expression}, ${option.temporalTarget.expression})`;
|
|
1299
|
+
return;
|
|
1300
|
+
}
|
|
1301
|
+
if (option.action === "where-temporal-relation") {
|
|
1302
|
+
const { field, temporalTarget } = state.whereBuilder;
|
|
1303
|
+
state.queryDraft.where = `temporalRelation(${field.expression}, ${temporalTarget.expression}) == ${JSON.stringify(option.relation)}`;
|
|
1304
|
+
resetWhereBuilder();
|
|
1305
|
+
return;
|
|
1306
|
+
}
|
|
1307
|
+
if (option.action === "where-function") {
|
|
1308
|
+
state.whereBuilder = { step: "function-field", field: null, operator: null, functionName: option.functionName, temporalTarget: null };
|
|
1309
|
+
state.queryDraft.where = `${option.functionName}()`;
|
|
1310
|
+
return;
|
|
1311
|
+
}
|
|
1312
|
+
if (option.action === "where-function-field") {
|
|
1313
|
+
state.queryDraft.where = `${state.whereBuilder.functionName}(${option.fieldExpression})`;
|
|
1314
|
+
resetWhereBuilder();
|
|
1315
|
+
return;
|
|
1316
|
+
}
|
|
1317
|
+
if (option.action === "where-back-root") {
|
|
1318
|
+
state.queryDraft.where = "";
|
|
1319
|
+
resetWhereBuilder();
|
|
1320
|
+
return;
|
|
1321
|
+
}
|
|
1322
|
+
if (option.action === "where-back-operator") {
|
|
1323
|
+
state.whereBuilder.step = "operator";
|
|
1324
|
+
state.whereBuilder.operator = null;
|
|
1325
|
+
state.whereBuilder.temporalTarget = null;
|
|
1326
|
+
state.queryDraft.where = state.whereBuilder.field.expression;
|
|
1327
|
+
return;
|
|
1328
|
+
}
|
|
1329
|
+
if (option.action === "where-back-temporal-target") {
|
|
1330
|
+
state.whereBuilder.step = "temporal-target";
|
|
1331
|
+
state.whereBuilder.temporalTarget = null;
|
|
1332
|
+
state.queryDraft.where = `temporalRelation(${state.whereBuilder.field.expression}, )`;
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
async function openComposer() {
|
|
1337
|
+
if (!composerModal || !composerInput) return;
|
|
1338
|
+
const opener = document.activeElement;
|
|
1339
|
+
if (state.view === "query") {
|
|
1340
|
+
const { parseQuery } = await runtimeReady;
|
|
1341
|
+
state.parseQuery = parseQuery;
|
|
1342
|
+
seedQueryDraft(parseQuery);
|
|
1343
|
+
state.queryComposerClause = "from";
|
|
1344
|
+
if (composerTitle) composerTitle.textContent = "SANSA Query Composer";
|
|
1345
|
+
if (composerApplyLabel) composerApplyLabel.textContent = "Apply query";
|
|
1346
|
+
resolveComposer.hidden = true;
|
|
1347
|
+
queryComposer.hidden = false;
|
|
1348
|
+
renderQueryComposer();
|
|
1349
|
+
window.AeonAccessibility?.openModal(composerModal, opener, queryClauseInput);
|
|
1350
|
+
window.requestAnimationFrame(() => queryClauseInput?.select());
|
|
1351
|
+
return;
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
if (composerTitle) composerTitle.textContent = "SANSA Resolve Composer";
|
|
1355
|
+
if (composerApplyLabel) composerApplyLabel.textContent = "Apply address";
|
|
1356
|
+
resolveComposer.hidden = false;
|
|
1357
|
+
queryComposer.hidden = true;
|
|
1358
|
+
composerInput.value = address.value.trim() || "$";
|
|
1359
|
+
renderComposerOptions();
|
|
1360
|
+
window.AeonAccessibility?.openModal(composerModal, opener, composerInput);
|
|
1361
|
+
window.requestAnimationFrame(() => composerInput.select());
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
function closeComposer() {
|
|
1365
|
+
if (composerModal) window.AeonAccessibility?.closeModal(composerModal);
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
function setEditorValue(field, value) {
|
|
1369
|
+
field.value = value;
|
|
1370
|
+
field.dispatchEvent(new Event("input", { bubbles: true }));
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1373
|
+
function applyComposer() {
|
|
1374
|
+
if (state.view === "query") {
|
|
1375
|
+
const queryText = buildQueryDraft();
|
|
1376
|
+
const parsed = state.parseQuery?.(queryText);
|
|
1377
|
+
if (!parsed?.ok) {
|
|
1378
|
+
renderQueryPreview();
|
|
1379
|
+
queryClauseInput?.focus();
|
|
1380
|
+
return;
|
|
1381
|
+
}
|
|
1382
|
+
setEditorValue(query, parsed.query.canonical);
|
|
1383
|
+
closeComposer();
|
|
1384
|
+
return;
|
|
1385
|
+
}
|
|
1386
|
+
if (!composerInput) return;
|
|
1387
|
+
setEditorValue(address, composerInput.value.trim() || "$");
|
|
1388
|
+
closeComposer();
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
function syncModeButtons() {
|
|
1392
|
+
modeButtons.forEach((button) => {
|
|
1393
|
+
const active = button.dataset.sansaMode === state.mode;
|
|
1394
|
+
button.classList.toggle("is-active", active);
|
|
1395
|
+
button.setAttribute("aria-pressed", active ? "true" : "false");
|
|
1396
|
+
});
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
function syncView() {
|
|
1400
|
+
const queryView = state.view === "query";
|
|
1401
|
+
address.hidden = queryView;
|
|
1402
|
+
query.hidden = !queryView;
|
|
1403
|
+
if (inputTitle) inputTitle.textContent = queryView ? "SANSA query" : "SANSA address";
|
|
1404
|
+
if (resultTitle) resultTitle.textContent = queryView ? "Query result" : "Resolve result";
|
|
1405
|
+
viewButtons.forEach((button) => {
|
|
1406
|
+
const active = button.dataset.sansaView === state.view;
|
|
1407
|
+
button.classList.toggle("is-active", active);
|
|
1408
|
+
button.setAttribute("aria-pressed", active ? "true" : "false");
|
|
1409
|
+
});
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
function showExamplePreview() {
|
|
1413
|
+
const example = examples[state.example];
|
|
1414
|
+
if (!example) return;
|
|
1415
|
+
exampleSource.textContent = example.source || "";
|
|
1416
|
+
if (exampleExpression) {
|
|
1417
|
+
exampleExpression.textContent = example.view === "query"
|
|
1418
|
+
? example.query || ""
|
|
1419
|
+
: `${example.addressKind || "selector"}: ${example.address || "$"}`;
|
|
1420
|
+
}
|
|
1421
|
+
exampleTabs.forEach((tab) => {
|
|
1422
|
+
const active = tab.dataset.sansaExampleKey === state.example;
|
|
1423
|
+
tab.classList.toggle("is-active", active);
|
|
1424
|
+
tab.setAttribute("aria-pressed", active ? "true" : "false");
|
|
1425
|
+
});
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
function openExamples() {
|
|
1429
|
+
showExamplePreview();
|
|
1430
|
+
window.AeonAccessibility?.openModal(examplesModal, examplesOpen);
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
function closeExamples() {
|
|
1434
|
+
window.AeonAccessibility?.closeModal(examplesModal);
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
source.addEventListener("input", () => {
|
|
1438
|
+
if (document.activeElement !== source) state.caretBindingPath = null;
|
|
1439
|
+
scheduleResolve();
|
|
1440
|
+
});
|
|
1441
|
+
source.addEventListener("focus", updateDiagnosticsForCaret);
|
|
1442
|
+
source.addEventListener("blur", updateDiagnosticsForCaret);
|
|
1443
|
+
source.addEventListener("click", updateDiagnosticsForCaret);
|
|
1444
|
+
source.addEventListener("keyup", updateDiagnosticsForCaret);
|
|
1445
|
+
source.addEventListener("select", updateDiagnosticsForCaret);
|
|
1446
|
+
address.addEventListener("input", scheduleResolve);
|
|
1447
|
+
query.addEventListener("input", scheduleResolve);
|
|
1448
|
+
composerOpen.forEach((button) => button.addEventListener("click", openComposer));
|
|
1449
|
+
composerClose.forEach((button) => button.addEventListener("click", closeComposer));
|
|
1450
|
+
composerInput?.addEventListener("input", renderComposerOptions);
|
|
1451
|
+
composerInput?.addEventListener("keydown", (event) => {
|
|
1452
|
+
if (event.key === "Enter") {
|
|
1453
|
+
event.preventDefault();
|
|
1454
|
+
applyComposer();
|
|
1455
|
+
}
|
|
1456
|
+
});
|
|
1457
|
+
composerOptions?.addEventListener("click", (event) => {
|
|
1458
|
+
const option = event.target.closest("[data-sansa-option]");
|
|
1459
|
+
if (!option || !composerInput) return;
|
|
1460
|
+
composerInput.value = option.dataset.sansaOption || "$";
|
|
1461
|
+
renderComposerOptions();
|
|
1462
|
+
composerInput.focus();
|
|
1463
|
+
});
|
|
1464
|
+
queryClauseButtons.forEach((button) => {
|
|
1465
|
+
button.addEventListener("click", () => {
|
|
1466
|
+
const clause = button.dataset.sansaQueryClause;
|
|
1467
|
+
if (!queryClauseDetails[clause]) return;
|
|
1468
|
+
state.queryComposerClause = clause;
|
|
1469
|
+
renderQueryComposer();
|
|
1470
|
+
queryClauseInput?.focus();
|
|
1471
|
+
queryClauseInput?.select();
|
|
1472
|
+
});
|
|
1473
|
+
});
|
|
1474
|
+
queryClauseInput?.addEventListener("input", () => {
|
|
1475
|
+
state.queryDraft[state.queryComposerClause] = queryClauseInput.value;
|
|
1476
|
+
if (state.queryComposerClause === "where") resetWhereBuilder();
|
|
1477
|
+
if (state.queryComposerClause === "from") resetWhereBuilder();
|
|
1478
|
+
syncQueryClauseButtons();
|
|
1479
|
+
if (["from", "where"].includes(state.queryComposerClause)) renderQueryClauseOptions();
|
|
1480
|
+
renderQueryPreview();
|
|
1481
|
+
});
|
|
1482
|
+
queryClauseOptions?.addEventListener("click", (event) => {
|
|
1483
|
+
const target = event.target.closest("[data-sansa-query-option-index]");
|
|
1484
|
+
if (!target || !queryClauseInput) return;
|
|
1485
|
+
const index = Number.parseInt(target.dataset.sansaQueryOptionIndex ?? "", 10);
|
|
1486
|
+
const option = state.queryRenderedOptions[index];
|
|
1487
|
+
if (!option) return;
|
|
1488
|
+
applyQueryClauseOption(option);
|
|
1489
|
+
renderQueryComposer();
|
|
1490
|
+
queryClauseInput.focus();
|
|
1491
|
+
queryClauseInput.select();
|
|
1492
|
+
});
|
|
1493
|
+
composerApply?.addEventListener("click", applyComposer);
|
|
1494
|
+
|
|
1495
|
+
modeButtons.forEach((button) => {
|
|
1496
|
+
button.addEventListener("click", () => {
|
|
1497
|
+
state.mode = button.dataset.sansaMode || "transport";
|
|
1498
|
+
syncModeButtons();
|
|
1499
|
+
sourceComposer?.setMode?.(state.mode);
|
|
1500
|
+
scheduleResolve();
|
|
1501
|
+
});
|
|
1502
|
+
});
|
|
1503
|
+
|
|
1504
|
+
viewButtons.forEach((button) => {
|
|
1505
|
+
button.addEventListener("click", () => {
|
|
1506
|
+
state.view = button.dataset.sansaView === "query" ? "query" : "resolve";
|
|
1507
|
+
syncView();
|
|
1508
|
+
scheduleResolve();
|
|
1509
|
+
});
|
|
1510
|
+
});
|
|
1511
|
+
|
|
1512
|
+
examplesOpen?.addEventListener("click", openExamples);
|
|
1513
|
+
examplesClose.forEach((button) => button.addEventListener("click", closeExamples));
|
|
1514
|
+
exampleTabs.forEach((button) => {
|
|
1515
|
+
button.addEventListener("click", () => {
|
|
1516
|
+
state.example = button.dataset.sansaExampleKey || state.example;
|
|
1517
|
+
showExamplePreview();
|
|
1518
|
+
});
|
|
1519
|
+
});
|
|
1520
|
+
exampleLoad?.addEventListener("click", () => {
|
|
1521
|
+
const example = examples[state.example];
|
|
1522
|
+
if (!example) return;
|
|
1523
|
+
setEditorValue(source, example.source || "");
|
|
1524
|
+
setEditorValue(address, example.address || "$");
|
|
1525
|
+
if (example.query) setEditorValue(query, example.query);
|
|
1526
|
+
state.view = example.view === "query" ? "query" : "resolve";
|
|
1527
|
+
state.mode = example.mode || "transport";
|
|
1528
|
+
shell.querySelector("[data-sansa-scope]").value = example.scope ?? "$";
|
|
1529
|
+
shell.querySelector("[data-sansa-inspections]").value = example.inspections ?? 10000;
|
|
1530
|
+
shell.querySelector("[data-sansa-property-inspections]").value = example.propertyInspections ?? 10000;
|
|
1531
|
+
syncView();
|
|
1532
|
+
syncModeButtons();
|
|
1533
|
+
sourceComposer?.setMode?.(state.mode);
|
|
1534
|
+
closeExamples();
|
|
1535
|
+
scheduleResolve();
|
|
1536
|
+
});
|
|
1537
|
+
|
|
1538
|
+
document.addEventListener("keydown", (event) => {
|
|
1539
|
+
if (event.key === "Escape" && examplesModal && !examplesModal.hidden) {
|
|
1540
|
+
closeExamples();
|
|
1541
|
+
}
|
|
1542
|
+
if (event.key === "Escape" && composerModal && !composerModal.hidden) {
|
|
1543
|
+
closeComposer();
|
|
1544
|
+
}
|
|
1545
|
+
});
|
|
1546
|
+
|
|
1547
|
+
syncModeButtons();
|
|
1548
|
+
syncView();
|
|
1549
|
+
showExamplePreview();
|
|
1550
|
+
const initialExample = examples.identity;
|
|
1551
|
+
if (initialExample) {
|
|
1552
|
+
setEditorValue(source, initialExample.source);
|
|
1553
|
+
setEditorValue(address, initialExample.address);
|
|
1554
|
+
query.value = "from $.inventory.items.*\nselect .name";
|
|
1555
|
+
window.AeonWebHighlight?.refreshEditor?.(source);
|
|
1556
|
+
}
|
|
1557
|
+
for (const control of shell.querySelectorAll("[data-sansa-scope], [data-sansa-inspections], [data-sansa-property-inspections]")) {
|
|
1558
|
+
control.addEventListener("input", scheduleResolve);
|
|
1559
|
+
}
|
|
1560
|
+
shell.querySelector("[data-sansa-run]").addEventListener("click", resolveNow);
|
|
1561
|
+
for (const input of [source, address, query]) input.addEventListener("keydown", event => {
|
|
1562
|
+
if ((event.metaKey || event.ctrlKey) && event.key === "Enter") { event.preventDefault(); void resolveNow(); }
|
|
1563
|
+
});
|
|
1564
|
+
scheduleResolve();
|
|
1565
|
+
});
|