@altopelago/sansa 0.10.0 → 0.11.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 +40 -1
- package/README.md +17 -5
- package/conformance/cts-claims.json +1 -1
- package/docs/api-contract.md +34 -16
- package/docs/capabilities.json +2 -1
- package/docs/instruction-tool.md +4 -0
- package/docs/query-tool.md +43 -7
- package/docs/releasing.md +23 -7
- package/fixtures/query-inventory.telex.aes +571 -0
- package/package.json +4 -1
- package/scripts/instruction.mjs +3 -3
- package/scripts/query-web.mjs +2 -1
- package/scripts/query.mjs +26 -9
- package/scripts/version.mjs +486 -0
- package/src/index.d.ts +27 -0
- package/src/index.js +158 -2
- package/tools/mutate-web/app.js +26 -6
- package/tools/mutate-web/index.html +6 -1
- package/tools/mutate-web/runtime.mjs +310 -12
- package/tools/query-web/app.js +24 -5
- package/tools/query-web/index.html +4 -0
- package/tools/query-web/runtime.mjs +509 -5
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { applyMutationPlan, planInstruction, planMutation, resolveAddress, validateMutationPlanTarget } from '../../src/index.js';
|
|
2
|
-
import { namespaceFromAeonSource } from '../query-web/runtime.mjs';
|
|
2
|
+
import { loadAeonAesRuntime, namespaceFromAeonSource, namespaceFromTelexSource } from '../query-web/runtime.mjs';
|
|
3
3
|
|
|
4
4
|
const HANDLE_PROPERTY = '__sansaMutateWorkbenchHandle';
|
|
5
5
|
const HANDLE_PREFIX = 'mutate-workbench';
|
|
@@ -26,23 +26,52 @@ const WORKBENCH_POLICY_RULE_FIELDS = new Set([
|
|
|
26
26
|
|
|
27
27
|
export async function runMutationForWorkbench({
|
|
28
28
|
source,
|
|
29
|
+
sourceKind = 'aeon',
|
|
29
30
|
requestSource,
|
|
30
31
|
requestKind = 'structured',
|
|
31
32
|
mode = 'plan',
|
|
32
33
|
options = {},
|
|
33
34
|
}) {
|
|
34
|
-
const
|
|
35
|
-
const
|
|
35
|
+
const normalizedSourceKind = sourceKind === 'telex' ? 'telex' : 'aeon';
|
|
36
|
+
const targetProfile = describeMutationTargetProfile(options.targetFormat ?? normalizedSourceKind);
|
|
37
|
+
const namespaceResult = normalizedSourceKind === 'telex'
|
|
38
|
+
? await namespaceFromTelexSource(source)
|
|
39
|
+
: await namespaceFromAeonSource(source);
|
|
36
40
|
if (!namespaceResult.ok) {
|
|
41
|
+
const errors = normalizeDiagnostics(namespaceResult.errors ?? []).map((error) => ({
|
|
42
|
+
...error,
|
|
43
|
+
code: String(error.code ?? 'SANSA_MUTATE_WORKBENCH_SOURCE_ERROR').replace(
|
|
44
|
+
'SANSA_QUERY_WORKBENCH_',
|
|
45
|
+
'SANSA_MUTATE_WORKBENCH_',
|
|
46
|
+
),
|
|
47
|
+
phase: 'parse',
|
|
48
|
+
}));
|
|
37
49
|
return {
|
|
38
|
-
|
|
50
|
+
ok: false,
|
|
39
51
|
mode,
|
|
52
|
+
sourceKind: normalizedSourceKind,
|
|
53
|
+
phase: 'parse',
|
|
54
|
+
text: renderDiagnosticText(errors),
|
|
55
|
+
errors,
|
|
40
56
|
};
|
|
41
57
|
}
|
|
42
58
|
|
|
43
59
|
const root = getRoot(namespaceResult.namespace);
|
|
44
60
|
assignStableHandles(root);
|
|
45
|
-
|
|
61
|
+
let telexState;
|
|
62
|
+
let namespace;
|
|
63
|
+
if (normalizedSourceKind === 'telex') {
|
|
64
|
+
const loaded = await loadAeonAesRuntime();
|
|
65
|
+
if (!loaded.ok) {
|
|
66
|
+
const errors = [{ code: 'SANSA_MUTATE_WORKBENCH_TELEX_RUNTIME_UNAVAILABLE', message: loaded.message, phase: 'parse' }];
|
|
67
|
+
return { ok: false, mode, sourceKind: normalizedSourceKind, phase: 'parse', text: renderDiagnosticText(errors), errors };
|
|
68
|
+
}
|
|
69
|
+
telexState = createTelexMutationState(namespaceResult.telex, loaded.module);
|
|
70
|
+
namespace = mutableTelexNamespace(namespaceResult.namespace, telexState);
|
|
71
|
+
} else {
|
|
72
|
+
namespace = mutableNamespace(namespaceResult.namespace);
|
|
73
|
+
}
|
|
74
|
+
const renderSource = () => telexState ? renderTelexMutationState(telexState) : renderBindingTree(root);
|
|
46
75
|
const planOptions = mutationPlanOptions(options);
|
|
47
76
|
const applyOptions = mutationApplyOptions(options);
|
|
48
77
|
const planResult = requestKind === 'instruction'
|
|
@@ -60,7 +89,8 @@ export async function runMutationForWorkbench({
|
|
|
60
89
|
text: renderDiagnosticText(planResult.errors, { fallbackPhase: planResult.phase ?? 'plan' }),
|
|
61
90
|
errors,
|
|
62
91
|
targetProfile,
|
|
63
|
-
|
|
92
|
+
sourceKind: normalizedSourceKind,
|
|
93
|
+
source: renderSource(),
|
|
64
94
|
};
|
|
65
95
|
}
|
|
66
96
|
|
|
@@ -76,7 +106,8 @@ export async function runMutationForWorkbench({
|
|
|
76
106
|
errors: normalizeDiagnostics(policyResult.errors),
|
|
77
107
|
plan: summarizePlan(planResult.plan),
|
|
78
108
|
targetProfile,
|
|
79
|
-
|
|
109
|
+
sourceKind: normalizedSourceKind,
|
|
110
|
+
source: renderSource(),
|
|
80
111
|
};
|
|
81
112
|
}
|
|
82
113
|
|
|
@@ -92,7 +123,8 @@ export async function runMutationForWorkbench({
|
|
|
92
123
|
errors: normalizeDiagnostics(targetResult.errors),
|
|
93
124
|
plan: summarizePlan(planResult.plan),
|
|
94
125
|
targetProfile,
|
|
95
|
-
|
|
126
|
+
sourceKind: normalizedSourceKind,
|
|
127
|
+
source: renderSource(),
|
|
96
128
|
};
|
|
97
129
|
}
|
|
98
130
|
|
|
@@ -106,7 +138,8 @@ export async function runMutationForWorkbench({
|
|
|
106
138
|
plan,
|
|
107
139
|
...(planResult.loweredRequest === undefined ? {} : { loweredRequest: planResult.loweredRequest }),
|
|
108
140
|
targetProfile,
|
|
109
|
-
|
|
141
|
+
sourceKind: normalizedSourceKind,
|
|
142
|
+
source: renderSource(),
|
|
110
143
|
diagnostics: normalizeDiagnostics(planResult.diagnostics ?? []),
|
|
111
144
|
};
|
|
112
145
|
}
|
|
@@ -121,7 +154,30 @@ export async function runMutationForWorkbench({
|
|
|
121
154
|
errors: normalizeDiagnostics(applied.errors),
|
|
122
155
|
operationResults: summarizeOperationResults(applied.operationResults ?? []),
|
|
123
156
|
targetProfile,
|
|
124
|
-
|
|
157
|
+
sourceKind: normalizedSourceKind,
|
|
158
|
+
source: renderSource(),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
let renderedSource;
|
|
163
|
+
try {
|
|
164
|
+
renderedSource = renderSource();
|
|
165
|
+
} catch (error) {
|
|
166
|
+
const errors = [{
|
|
167
|
+
code: 'SANSA_MUTATE_APPLY_FAILED',
|
|
168
|
+
message: error instanceof Error ? error.message : String(error),
|
|
169
|
+
phase: 'apply',
|
|
170
|
+
}];
|
|
171
|
+
return {
|
|
172
|
+
ok: false,
|
|
173
|
+
mode: 'apply',
|
|
174
|
+
sourceKind: normalizedSourceKind,
|
|
175
|
+
text: renderDiagnosticText(errors),
|
|
176
|
+
plan,
|
|
177
|
+
errors,
|
|
178
|
+
operationResults: summarizeOperationResults(applied.operationResults ?? []),
|
|
179
|
+
targetProfile,
|
|
180
|
+
source: String(source),
|
|
125
181
|
};
|
|
126
182
|
}
|
|
127
183
|
|
|
@@ -133,6 +189,7 @@ export async function runMutationForWorkbench({
|
|
|
133
189
|
plan,
|
|
134
190
|
...(planResult.loweredRequest === undefined ? {} : { loweredRequest: planResult.loweredRequest }),
|
|
135
191
|
targetProfile,
|
|
192
|
+
sourceKind: normalizedSourceKind,
|
|
136
193
|
result: {
|
|
137
194
|
planId: applied.planId,
|
|
138
195
|
stateBefore: sanitizeJsonValue(applied.stateBefore),
|
|
@@ -140,7 +197,7 @@ export async function runMutationForWorkbench({
|
|
|
140
197
|
operationResults: summarizeOperationResults(applied.operationResults),
|
|
141
198
|
diagnostics: normalizeDiagnostics(applied.diagnostics ?? []),
|
|
142
199
|
},
|
|
143
|
-
source:
|
|
200
|
+
source: renderedSource,
|
|
144
201
|
};
|
|
145
202
|
}
|
|
146
203
|
|
|
@@ -178,7 +235,11 @@ function enforceTargetSurfaceForWorkbench(plan, targetFormat) {
|
|
|
178
235
|
}
|
|
179
236
|
|
|
180
237
|
function describeMutationTargetProfile(targetFormat) {
|
|
181
|
-
const id = targetFormat === 'json' || targetFormat === 'json-compatible'
|
|
238
|
+
const id = targetFormat === 'json' || targetFormat === 'json-compatible'
|
|
239
|
+
? 'json'
|
|
240
|
+
: targetFormat === 'telex' || targetFormat === 'telex.aes'
|
|
241
|
+
? 'telex'
|
|
242
|
+
: 'aeon';
|
|
182
243
|
if (id === 'json') {
|
|
183
244
|
return {
|
|
184
245
|
id,
|
|
@@ -186,6 +247,13 @@ function describeMutationTargetProfile(targetFormat) {
|
|
|
186
247
|
summary: 'JSON-compatible target surface: accepts ordinary JSON-compatible values and rejects AEON-only representation features.',
|
|
187
248
|
};
|
|
188
249
|
}
|
|
250
|
+
if (id === 'telex') {
|
|
251
|
+
return {
|
|
252
|
+
id,
|
|
253
|
+
boundary: 'representability',
|
|
254
|
+
summary: 'Telex target surface: currently permits deterministic replacement of an existing portable scalar event.',
|
|
255
|
+
};
|
|
256
|
+
}
|
|
189
257
|
return {
|
|
190
258
|
id,
|
|
191
259
|
boundary: 'representability',
|
|
@@ -501,6 +569,230 @@ function mutableNamespace(namespace) {
|
|
|
501
569
|
};
|
|
502
570
|
}
|
|
503
571
|
|
|
572
|
+
function createTelexMutationState(telex, aes) {
|
|
573
|
+
return {
|
|
574
|
+
aes,
|
|
575
|
+
version: telex.version,
|
|
576
|
+
profile: telex.profile,
|
|
577
|
+
profileExplicit: telex.profileExplicit === true,
|
|
578
|
+
projection: telex.projection,
|
|
579
|
+
projectionExplicit: telex.projectionExplicit === true,
|
|
580
|
+
records: telex.records.map((record) => ({
|
|
581
|
+
...record,
|
|
582
|
+
...(Array.isArray(record.generics) ? { generics: structuredClone(record.generics) } : {}),
|
|
583
|
+
...(Array.isArray(record.clarifiers) ? { clarifiers: structuredClone(record.clarifiers) } : {}),
|
|
584
|
+
})),
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
function mutableTelexNamespace(namespace, state) {
|
|
589
|
+
const recordsByPath = new Map();
|
|
590
|
+
for (let index = 0; index < state.records.length; index += 1) {
|
|
591
|
+
const path = state.records[index].path;
|
|
592
|
+
if (typeof path === 'string') recordsByPath.set(path, index);
|
|
593
|
+
}
|
|
594
|
+
return {
|
|
595
|
+
...namespace,
|
|
596
|
+
root: getRoot(namespace),
|
|
597
|
+
mutate: {
|
|
598
|
+
supportsReplace: true,
|
|
599
|
+
supportsStableBindingIdentity: true,
|
|
600
|
+
supportsAtomicApply: true,
|
|
601
|
+
bindingHandle: (binding) => binding[HANDLE_PROPERTY],
|
|
602
|
+
observedState: (binding) => binding.revision ?? 0,
|
|
603
|
+
sameBinding: (left, right) => left === right || left?.[HANDLE_PROPERTY] === right?.[HANDLE_PROPERTY],
|
|
604
|
+
replace(target, value, operation) {
|
|
605
|
+
const recordIndex = recordsByPath.get(target.address);
|
|
606
|
+
if (recordIndex === undefined) {
|
|
607
|
+
return { ok: false, message: `Portable AES event '${target.address}' was not found.` };
|
|
608
|
+
}
|
|
609
|
+
const current = state.records[recordIndex];
|
|
610
|
+
const replacement = telexScalarReplacementRecord(current, value, operation, state.aes);
|
|
611
|
+
if (!replacement.ok) return replacement;
|
|
612
|
+
const candidateRecords = [...state.records];
|
|
613
|
+
candidateRecords[recordIndex] = replacement.record;
|
|
614
|
+
const validation = state.aes.validateTelexRecords(candidateRecords, {
|
|
615
|
+
profile: state.profile,
|
|
616
|
+
projection: state.projection,
|
|
617
|
+
});
|
|
618
|
+
if (!validation.valid) {
|
|
619
|
+
return {
|
|
620
|
+
ok: false,
|
|
621
|
+
message: validation.diagnostics.map((diagnostic) => `${diagnostic.code}: ${diagnostic.message}`).join('; '),
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
state.records = candidateRecords;
|
|
625
|
+
applyPortableScalarRecordToBinding(target, replacement.record);
|
|
626
|
+
bump(target);
|
|
627
|
+
return { binding: target, resultingAddress: target.address };
|
|
628
|
+
},
|
|
629
|
+
},
|
|
630
|
+
};
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
function telexScalarReplacementRecord(current, value, operation, aes) {
|
|
634
|
+
if (!current || typeof current.path !== 'string') {
|
|
635
|
+
return { ok: false, message: 'Telex scalar replacement requires a body event.' };
|
|
636
|
+
}
|
|
637
|
+
let descriptor;
|
|
638
|
+
if (operation.datatype !== undefined) {
|
|
639
|
+
try {
|
|
640
|
+
descriptor = aes.parseDatatypeDescriptor(operation.datatype);
|
|
641
|
+
} catch (error) {
|
|
642
|
+
return { ok: false, message: error instanceof Error ? error.message : String(error) };
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
const kind = portableKindForMutation(operation.kind, descriptor?.datatype, current.kind);
|
|
646
|
+
if (kind === undefined || !PORTABLE_MUTABLE_SCALAR_KINDS.has(kind)) {
|
|
647
|
+
return { ok: false, message: `Telex scalar replacement cannot represent kind '${kind ?? operation.kind ?? current.kind}'.` };
|
|
648
|
+
}
|
|
649
|
+
const payload = portableScalarPayload(kind, value, current);
|
|
650
|
+
if (!payload.ok) return payload;
|
|
651
|
+
const record = {
|
|
652
|
+
...current,
|
|
653
|
+
kind,
|
|
654
|
+
value: payload.value,
|
|
655
|
+
...(descriptor === undefined ? {} : {
|
|
656
|
+
datatype: descriptor.datatype,
|
|
657
|
+
generics: descriptor.generics,
|
|
658
|
+
clarifiers: descriptor.clarifiers,
|
|
659
|
+
}),
|
|
660
|
+
};
|
|
661
|
+
// Source coordinates describe the pre-mutation artifact and cannot be
|
|
662
|
+
// claimed by the newly produced value. Unchanged events retain theirs.
|
|
663
|
+
delete record.origin;
|
|
664
|
+
delete record.span;
|
|
665
|
+
return { ok: true, record };
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
const PORTABLE_MUTABLE_SCALAR_KINDS = new Set([
|
|
669
|
+
'StringLiteral', 'NumberLiteral', 'InfinityLiteral', 'NaNLiteral', 'NullLiteral',
|
|
670
|
+
'BooleanLiteral', 'ToggleLiteral', 'HexLiteral', 'RadixLiteral', 'EncodingLiteral',
|
|
671
|
+
'SeparatorLiteral', 'SansaAddressLiteral', 'DateLiteral', 'TimeLiteral',
|
|
672
|
+
'DateTimeLiteral', 'WTCDateTimeLiteral',
|
|
673
|
+
]);
|
|
674
|
+
|
|
675
|
+
const PORTABLE_KIND_ALIASES = new Map([
|
|
676
|
+
['string', 'StringLiteral'], ['trimtick', 'StringLiteral'], ['prose', 'StringLiteral'],
|
|
677
|
+
['number', 'NumberLiteral'], ['n', 'NumberLiteral'], ['integer', 'NumberLiteral'],
|
|
678
|
+
['boolean', 'BooleanLiteral'], ['bool', 'BooleanLiteral'], ['toggle', 'ToggleLiteral'],
|
|
679
|
+
['null', 'NullLiteral'], ['nan', 'NaNLiteral'], ['infinity', 'InfinityLiteral'],
|
|
680
|
+
['hex', 'HexLiteral'], ['radix', 'RadixLiteral'], ['encoding', 'EncodingLiteral'],
|
|
681
|
+
['base64', 'EncodingLiteral'], ['embed', 'EncodingLiteral'], ['inline', 'EncodingLiteral'],
|
|
682
|
+
['separator', 'SeparatorLiteral'], ['sep', 'SeparatorLiteral'], ['csv', 'SeparatorLiteral'],
|
|
683
|
+
['sansa', 'SansaAddressLiteral'], ['sansaaddress', 'SansaAddressLiteral'],
|
|
684
|
+
['date', 'DateLiteral'], ['time', 'TimeLiteral'], ['datetime', 'DateTimeLiteral'], ['wtc', 'WTCDateTimeLiteral'],
|
|
685
|
+
]);
|
|
686
|
+
|
|
687
|
+
function portableKindForMutation(kind, datatype, fallback) {
|
|
688
|
+
if (PORTABLE_MUTABLE_SCALAR_KINDS.has(kind)) return kind;
|
|
689
|
+
const kindAlias = typeof kind === 'string' ? PORTABLE_KIND_ALIASES.get(kind.toLowerCase()) : undefined;
|
|
690
|
+
if (kindAlias !== undefined) return kindAlias;
|
|
691
|
+
if (typeof datatype === 'string') {
|
|
692
|
+
const base = datatype.toLowerCase();
|
|
693
|
+
const datatypeAlias = PORTABLE_KIND_ALIASES.get(base);
|
|
694
|
+
if (datatypeAlias !== undefined) return datatypeAlias;
|
|
695
|
+
if (/^(?:u?int|float|decimal)\d*$/u.test(base)) return 'NumberLiteral';
|
|
696
|
+
if (/^radix\d+$/u.test(base)) return 'RadixLiteral';
|
|
697
|
+
}
|
|
698
|
+
return PORTABLE_MUTABLE_SCALAR_KINDS.has(fallback) ? fallback : undefined;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
function portableScalarPayload(kind, value, current) {
|
|
702
|
+
switch (kind) {
|
|
703
|
+
case 'NumberLiteral':
|
|
704
|
+
return typeof value === 'number' && Number.isFinite(value)
|
|
705
|
+
? { ok: true, value: String(value) }
|
|
706
|
+
: invalidPortableScalar(kind, 'a finite JSON number');
|
|
707
|
+
case 'BooleanLiteral':
|
|
708
|
+
return typeof value === 'boolean'
|
|
709
|
+
? { ok: true, value: String(value) }
|
|
710
|
+
: invalidPortableScalar(kind, 'a JSON boolean');
|
|
711
|
+
case 'NullLiteral':
|
|
712
|
+
if (typeof value === 'string' && value.length > 0) return { ok: true, value };
|
|
713
|
+
if (value === null && current.kind === 'NullLiteral' && typeof current.value === 'string') {
|
|
714
|
+
return { ok: true, value: current.value };
|
|
715
|
+
}
|
|
716
|
+
return invalidPortableScalar(kind, 'a non-empty null-reason string, or null when replacing an existing null event');
|
|
717
|
+
case 'NaNLiteral':
|
|
718
|
+
return value === null || value === 'NaN'
|
|
719
|
+
? { ok: true, value: 'NaN' }
|
|
720
|
+
: invalidPortableScalar(kind, 'null or "NaN"');
|
|
721
|
+
case 'InfinityLiteral':
|
|
722
|
+
if (value === Infinity || value === 'Infinity' || value === '+Infinity') return { ok: true, value: 'Infinity' };
|
|
723
|
+
if (value === -Infinity || value === '-Infinity') return { ok: true, value: '-Infinity' };
|
|
724
|
+
return invalidPortableScalar(kind, '"Infinity", "+Infinity", or "-Infinity"');
|
|
725
|
+
default:
|
|
726
|
+
return typeof value === 'string'
|
|
727
|
+
? { ok: true, value }
|
|
728
|
+
: invalidPortableScalar(kind, 'a JSON string');
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
function invalidPortableScalar(kind, expected) {
|
|
733
|
+
return { ok: false, message: `${kind} replacement requires ${expected}.` };
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
function applyPortableScalarRecordToBinding(binding, record) {
|
|
737
|
+
binding.representationKind = record.kind;
|
|
738
|
+
binding.datatype = record.datatype;
|
|
739
|
+
binding.semanticType = record.datatype ?? portableScalarSemanticTypeForWorkbench(record.kind);
|
|
740
|
+
binding.generics = record.generics;
|
|
741
|
+
binding.clarifiers = record.clarifiers;
|
|
742
|
+
binding.scalarKind = portableScalarKindForWorkbench(record.kind);
|
|
743
|
+
binding.value = portableScalarValueForWorkbench(record);
|
|
744
|
+
if (record.kind === 'NullLiteral') binding.nullReason = record.value;
|
|
745
|
+
else delete binding.nullReason;
|
|
746
|
+
delete binding.origin;
|
|
747
|
+
delete binding.span;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
function portableScalarSemanticTypeForWorkbench(kind) {
|
|
751
|
+
return {
|
|
752
|
+
StringLiteral: 'string', NumberLiteral: 'number', BooleanLiteral: 'boolean',
|
|
753
|
+
NullLiteral: 'null', InfinityLiteral: 'infinity', NaNLiteral: 'nan', ToggleLiteral: 'toggle',
|
|
754
|
+
HexLiteral: 'hex', RadixLiteral: 'radix', EncodingLiteral: 'encoding', SeparatorLiteral: 'sep',
|
|
755
|
+
SansaAddressLiteral: 'sansa', DateLiteral: 'date', TimeLiteral: 'time',
|
|
756
|
+
DateTimeLiteral: 'datetime', WTCDateTimeLiteral: 'wtc',
|
|
757
|
+
}[kind];
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
function portableScalarKindForWorkbench(kind) {
|
|
761
|
+
return {
|
|
762
|
+
StringLiteral: 'string', NumberLiteral: 'number', BooleanLiteral: 'boolean',
|
|
763
|
+
NullLiteral: 'null', InfinityLiteral: 'infinity', NaNLiteral: 'nan', ToggleLiteral: 'toggle',
|
|
764
|
+
HexLiteral: 'hex', RadixLiteral: 'radix', EncodingLiteral: 'encoding', SeparatorLiteral: 'separator',
|
|
765
|
+
SansaAddressLiteral: 'sansaAddress', DateLiteral: 'date', TimeLiteral: 'time',
|
|
766
|
+
DateTimeLiteral: 'datetime', WTCDateTimeLiteral: 'wtc',
|
|
767
|
+
}[kind];
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
function portableScalarValueForWorkbench(record) {
|
|
771
|
+
if (record.kind === 'NumberLiteral') return Number(record.value);
|
|
772
|
+
if (record.kind === 'BooleanLiteral') return record.value === 'true';
|
|
773
|
+
if (record.kind === 'NullLiteral') return null;
|
|
774
|
+
if (record.kind === 'NaNLiteral') return Number.NaN;
|
|
775
|
+
if (record.kind === 'InfinityLiteral') return record.value === '-Infinity' ? -Infinity : Infinity;
|
|
776
|
+
if (record.kind === 'SansaAddressLiteral') {
|
|
777
|
+
return { type: 'SansaAddressLiteral', address: record.value, canonical: record.value };
|
|
778
|
+
}
|
|
779
|
+
return record.value;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
function renderTelexMutationState(state) {
|
|
783
|
+
const validation = state.aes.validateTelexRecords(state.records, {
|
|
784
|
+
profile: state.profile,
|
|
785
|
+
projection: state.projection,
|
|
786
|
+
});
|
|
787
|
+
if (!validation.valid) {
|
|
788
|
+
throw new Error(validation.diagnostics.map((diagnostic) => `${diagnostic.code}: ${diagnostic.message}`).join('; '));
|
|
789
|
+
}
|
|
790
|
+
return state.aes.encodeTelex(state.records, {
|
|
791
|
+
...(state.profileExplicit ? { profile: state.profile } : {}),
|
|
792
|
+
...(state.projectionExplicit && state.projection !== null ? { projection: state.projection } : {}),
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
|
|
504
796
|
function getRoot(namespace) {
|
|
505
797
|
return typeof namespace.root === 'function' ? namespace.root() : namespace.root;
|
|
506
798
|
}
|
|
@@ -955,13 +1247,19 @@ function summarizeOperationResults(results) {
|
|
|
955
1247
|
function summarizeBinding(binding) {
|
|
956
1248
|
return {
|
|
957
1249
|
address: binding.address,
|
|
1250
|
+
identity: binding.identity,
|
|
958
1251
|
name: binding.name,
|
|
959
1252
|
index: binding.index,
|
|
960
1253
|
semanticType: binding.semanticType,
|
|
1254
|
+
datatype: binding.datatype,
|
|
1255
|
+
generics: sanitizeJsonValue(binding.generics),
|
|
1256
|
+
clarifiers: sanitizeJsonValue(binding.clarifiers),
|
|
961
1257
|
representationKind: binding.representationKind,
|
|
962
1258
|
scalarKind: binding.scalarKind,
|
|
963
1259
|
nullReason: binding.nullReason,
|
|
964
1260
|
nodeTag: binding.nodeTag,
|
|
1261
|
+
origin: binding.origin,
|
|
1262
|
+
span: binding.span,
|
|
965
1263
|
value: sanitizeJsonValue(binding.value),
|
|
966
1264
|
};
|
|
967
1265
|
}
|
package/tools/query-web/app.js
CHANGED
|
@@ -20,6 +20,7 @@ const budgetInputs = Array.from(document.querySelectorAll('.budget-row input'));
|
|
|
20
20
|
let defaultFixtureSource = '';
|
|
21
21
|
let defaultJsonSource = '';
|
|
22
22
|
let defaultAeonSource = '';
|
|
23
|
+
let defaultTelexSource = '';
|
|
23
24
|
let defaultParamsSource = '';
|
|
24
25
|
let lastAction = 'evaluate';
|
|
25
26
|
|
|
@@ -34,10 +35,10 @@ exampleSelect.addEventListener('change', () => {
|
|
|
34
35
|
});
|
|
35
36
|
|
|
36
37
|
resetButton.addEventListener('click', () => {
|
|
37
|
-
fixtureInput.value = sourceKind()
|
|
38
|
+
fixtureInput.value = defaultSourceForKind(sourceKind());
|
|
38
39
|
paramsInput.value = defaultParamsSource;
|
|
39
40
|
setExample(exampleSelect.value);
|
|
40
|
-
fixtureStatus.textContent = sourceKind()
|
|
41
|
+
fixtureStatus.textContent = `default ${sourceKind()}`;
|
|
41
42
|
paramsStatus.textContent = 'default params';
|
|
42
43
|
void runQuery();
|
|
43
44
|
});
|
|
@@ -75,9 +76,11 @@ budgetInputs.forEach((input) => {
|
|
|
75
76
|
});
|
|
76
77
|
document.querySelectorAll('input[name="sourceKind"]').forEach((input) => {
|
|
77
78
|
input.addEventListener('change', () => {
|
|
78
|
-
fixtureInput.value = sourceKind()
|
|
79
|
-
sourceLabel.textContent = sourceKind() === 'json'
|
|
80
|
-
|
|
79
|
+
fixtureInput.value = defaultSourceForKind(sourceKind());
|
|
80
|
+
sourceLabel.textContent = sourceKind() === 'json'
|
|
81
|
+
? 'Fixture JSON'
|
|
82
|
+
: sourceKind() === 'telex' ? 'Telex AES' : 'AEON Source';
|
|
83
|
+
fixtureStatus.textContent = `default ${sourceKind()}`;
|
|
81
84
|
void runQuery();
|
|
82
85
|
});
|
|
83
86
|
});
|
|
@@ -126,6 +129,16 @@ async function loadDefaultSources() {
|
|
|
126
129
|
'}',
|
|
127
130
|
].join('\n'));
|
|
128
131
|
defaultJsonSource = await fetchText('/fixtures/query-inventory.json', '{\n "root": {\n "address": "$",\n "children": []\n }\n}');
|
|
132
|
+
defaultTelexSource = await fetchText('/fixtures/query-inventory.telex.aes', [
|
|
133
|
+
'telex.aes=1',
|
|
134
|
+
'',
|
|
135
|
+
'path=$.inventory',
|
|
136
|
+
'kind=ObjectNode',
|
|
137
|
+
'',
|
|
138
|
+
'path=$.inventory.items',
|
|
139
|
+
'kind=ListNode',
|
|
140
|
+
'',
|
|
141
|
+
].join('\n'));
|
|
129
142
|
defaultParamsSource = [
|
|
130
143
|
'source:sansa = $.inventory.items.*',
|
|
131
144
|
'field:sansa = ?.sku',
|
|
@@ -140,6 +153,12 @@ async function loadDefaultSources() {
|
|
|
140
153
|
paramsStatus.textContent = 'default params';
|
|
141
154
|
}
|
|
142
155
|
|
|
156
|
+
function defaultSourceForKind(kind) {
|
|
157
|
+
if (kind === 'json') return defaultJsonSource;
|
|
158
|
+
if (kind === 'telex') return defaultTelexSource;
|
|
159
|
+
return defaultAeonSource;
|
|
160
|
+
}
|
|
161
|
+
|
|
143
162
|
async function fetchText(path, fallback) {
|
|
144
163
|
try {
|
|
145
164
|
const response = await fetch(path);
|
|
@@ -31,6 +31,10 @@
|
|
|
31
31
|
<input type="radio" name="sourceKind" value="aeon" checked>
|
|
32
32
|
AEON
|
|
33
33
|
</label>
|
|
34
|
+
<label>
|
|
35
|
+
<input type="radio" name="sourceKind" value="telex">
|
|
36
|
+
Telex AES
|
|
37
|
+
</label>
|
|
34
38
|
<label>
|
|
35
39
|
<input type="radio" name="sourceKind" value="json">
|
|
36
40
|
JSON fixture
|