@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
|
@@ -2,9 +2,10 @@ import { existsSync } from 'node:fs';
|
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
import { resolve as resolvePath } from 'node:path';
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
5
|
-
import { evaluateQuery, parseQuery } from '../../src/index.js';
|
|
5
|
+
import { evaluateQuery, parseAddress, parseQuery } from '../../src/index.js';
|
|
6
6
|
|
|
7
7
|
const devAeonCoreUrl = new URL('../../../aeon/implementations/typescript/packages/core/dist/index.js', import.meta.url);
|
|
8
|
+
const devAeonAesUrl = new URL('../../../aeon/implementations/typescript/packages/aes/dist/index.js', import.meta.url);
|
|
8
9
|
const requireFromCwd = createRequire(resolvePath(process.cwd(), 'package.json'));
|
|
9
10
|
const QUERY_VALUE_METADATA_PROPERTY = '__sansaQueryValueMetadata';
|
|
10
11
|
const QUERY_OBJECT_FIELD_METADATA_PROPERTY = '__sansaObjectFieldMetadata';
|
|
@@ -40,9 +41,16 @@ export async function evaluateQueryForWorkbench({
|
|
|
40
41
|
valueSemantics = '',
|
|
41
42
|
budget = {},
|
|
42
43
|
}) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
let namespaceResult;
|
|
45
|
+
if (sourceKind === 'json') {
|
|
46
|
+
namespaceResult = namespaceFromJsonSource(source);
|
|
47
|
+
} else if (sourceKind === 'telex') {
|
|
48
|
+
namespaceResult = await namespaceFromTelexSource(source);
|
|
49
|
+
} else if (sourceKind === 'film') {
|
|
50
|
+
namespaceResult = await namespaceFromFilmSource(source);
|
|
51
|
+
} else {
|
|
52
|
+
namespaceResult = await namespaceFromAeonSource(source);
|
|
53
|
+
}
|
|
46
54
|
|
|
47
55
|
if (!namespaceResult.ok) {
|
|
48
56
|
return namespaceResult;
|
|
@@ -172,6 +180,207 @@ export async function namespaceFromAeonSource(source) {
|
|
|
172
180
|
};
|
|
173
181
|
}
|
|
174
182
|
|
|
183
|
+
/**
|
|
184
|
+
* Build a SANSA namespace directly from a complete portable AES stream.
|
|
185
|
+
* The adapter retains portable paths and occurrence identities; it does not
|
|
186
|
+
* reconstruct the implementation-specific AEON parser AST.
|
|
187
|
+
*/
|
|
188
|
+
export async function namespaceFromTelexSource(source) {
|
|
189
|
+
const loaded = await loadAeonAesRuntime();
|
|
190
|
+
if (!loaded.ok) {
|
|
191
|
+
const errors = [{
|
|
192
|
+
code: 'SANSA_QUERY_WORKBENCH_TELEX_RUNTIME_UNAVAILABLE',
|
|
193
|
+
message: loaded.message,
|
|
194
|
+
}];
|
|
195
|
+
return {
|
|
196
|
+
ok: false,
|
|
197
|
+
mode: 'evaluate',
|
|
198
|
+
sourceKind: 'telex',
|
|
199
|
+
text: renderDiagnosticText(errors),
|
|
200
|
+
errors,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const aes = loaded.module;
|
|
205
|
+
let parsed;
|
|
206
|
+
try {
|
|
207
|
+
parsed = aes.parseTelex(source);
|
|
208
|
+
} catch (error) {
|
|
209
|
+
const errors = [{
|
|
210
|
+
code: error?.code ?? 'TELEX_SYNTAX_ERROR',
|
|
211
|
+
message: error instanceof Error ? error.message : String(error),
|
|
212
|
+
...(Number.isInteger(error?.line) ? { line: error.line } : {}),
|
|
213
|
+
}];
|
|
214
|
+
return {
|
|
215
|
+
ok: false,
|
|
216
|
+
mode: 'evaluate',
|
|
217
|
+
sourceKind: 'telex',
|
|
218
|
+
text: renderDiagnosticText(errors),
|
|
219
|
+
errors,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const validation = aes.validateTelex(parsed, {
|
|
224
|
+
profile: parsed.profile,
|
|
225
|
+
projection: parsed.projection,
|
|
226
|
+
});
|
|
227
|
+
if (!validation.valid) {
|
|
228
|
+
const errors = validation.diagnostics.map((diagnostic) => ({
|
|
229
|
+
code: diagnostic.code,
|
|
230
|
+
message: diagnostic.message,
|
|
231
|
+
...(typeof diagnostic.path === 'string' ? { path: diagnostic.path } : {}),
|
|
232
|
+
...(Number.isInteger(diagnostic.record) ? { record: diagnostic.record } : {}),
|
|
233
|
+
}));
|
|
234
|
+
return {
|
|
235
|
+
ok: false,
|
|
236
|
+
mode: 'evaluate',
|
|
237
|
+
sourceKind: 'telex',
|
|
238
|
+
text: renderDiagnosticText(errors),
|
|
239
|
+
errors,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (parsed.profile !== aes.COMPLETE_AES_PROFILE) {
|
|
244
|
+
const errors = [{
|
|
245
|
+
code: 'SANSA_QUERY_WORKBENCH_PARTIAL_AES_UNSUPPORTED',
|
|
246
|
+
message: `SANSA query navigation requires '${aes.COMPLETE_AES_PROFILE}' when no external namespace state is supplied.`,
|
|
247
|
+
}];
|
|
248
|
+
return {
|
|
249
|
+
ok: false,
|
|
250
|
+
mode: 'evaluate',
|
|
251
|
+
sourceKind: 'telex',
|
|
252
|
+
text: renderDiagnosticText(errors),
|
|
253
|
+
errors,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
try {
|
|
258
|
+
return {
|
|
259
|
+
ok: true,
|
|
260
|
+
namespace: buildNamespaceFromPortableRecords(parsed.records),
|
|
261
|
+
diagnostics: [],
|
|
262
|
+
telex: {
|
|
263
|
+
version: parsed.version,
|
|
264
|
+
profile: parsed.profile,
|
|
265
|
+
profileExplicit: parsed.profileExplicit,
|
|
266
|
+
projection: parsed.projection,
|
|
267
|
+
projectionExplicit: parsed.projectionExplicit,
|
|
268
|
+
canonical: parsed.canonical,
|
|
269
|
+
records: parsed.records,
|
|
270
|
+
},
|
|
271
|
+
};
|
|
272
|
+
} catch (error) {
|
|
273
|
+
const errors = [{
|
|
274
|
+
code: 'SANSA_QUERY_WORKBENCH_INVALID_PORTABLE_AES',
|
|
275
|
+
message: error instanceof Error ? error.message : String(error),
|
|
276
|
+
}];
|
|
277
|
+
return {
|
|
278
|
+
ok: false,
|
|
279
|
+
mode: 'evaluate',
|
|
280
|
+
sourceKind: 'telex',
|
|
281
|
+
text: renderDiagnosticText(errors),
|
|
282
|
+
errors,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Build a SANSA namespace from a completely validated Film v1 byte stream.
|
|
289
|
+
* Film and Telex share the same portable record adapter; only their physical
|
|
290
|
+
* reader differs. No Film mutation or writer surface is implied.
|
|
291
|
+
*/
|
|
292
|
+
export async function namespaceFromFilmSource(source) {
|
|
293
|
+
const loaded = await loadAeonAesRuntime();
|
|
294
|
+
if (!loaded.ok) {
|
|
295
|
+
const errors = [{
|
|
296
|
+
code: 'SANSA_QUERY_WORKBENCH_FILM_RUNTIME_UNAVAILABLE',
|
|
297
|
+
message: loaded.message,
|
|
298
|
+
}];
|
|
299
|
+
return {
|
|
300
|
+
ok: false,
|
|
301
|
+
mode: 'evaluate',
|
|
302
|
+
sourceKind: 'film',
|
|
303
|
+
text: renderDiagnosticText(errors),
|
|
304
|
+
errors,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const aes = loaded.module;
|
|
309
|
+
if (typeof aes.decodeFilm !== 'function') {
|
|
310
|
+
const errors = [{
|
|
311
|
+
code: 'SANSA_QUERY_WORKBENCH_FILM_RUNTIME_UNAVAILABLE',
|
|
312
|
+
message: 'The loaded @altopelago/aeon-aes runtime does not expose a Film v1 reader.',
|
|
313
|
+
}];
|
|
314
|
+
return {
|
|
315
|
+
ok: false,
|
|
316
|
+
mode: 'evaluate',
|
|
317
|
+
sourceKind: 'film',
|
|
318
|
+
text: renderDiagnosticText(errors),
|
|
319
|
+
errors,
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
let decoded;
|
|
323
|
+
try {
|
|
324
|
+
decoded = aes.decodeFilm(source);
|
|
325
|
+
} catch (error) {
|
|
326
|
+
const errors = [{
|
|
327
|
+
code: error?.code ?? 'FILM_DECODE_ERROR',
|
|
328
|
+
message: error instanceof Error ? error.message : String(error),
|
|
329
|
+
...(Number.isInteger(error?.offset) ? { offset: error.offset } : {}),
|
|
330
|
+
...(Number.isInteger(error?.record) ? { record: error.record } : {}),
|
|
331
|
+
}];
|
|
332
|
+
return {
|
|
333
|
+
ok: false,
|
|
334
|
+
mode: 'evaluate',
|
|
335
|
+
sourceKind: 'film',
|
|
336
|
+
text: renderDiagnosticText(errors),
|
|
337
|
+
errors,
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
if (decoded.profile !== aes.COMPLETE_AES_PROFILE) {
|
|
342
|
+
const errors = [{
|
|
343
|
+
code: 'SANSA_QUERY_WORKBENCH_PARTIAL_AES_UNSUPPORTED',
|
|
344
|
+
message: `SANSA query navigation requires '${aes.COMPLETE_AES_PROFILE}' when no external namespace state is supplied.`,
|
|
345
|
+
}];
|
|
346
|
+
return {
|
|
347
|
+
ok: false,
|
|
348
|
+
mode: 'evaluate',
|
|
349
|
+
sourceKind: 'film',
|
|
350
|
+
text: renderDiagnosticText(errors),
|
|
351
|
+
errors,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
try {
|
|
356
|
+
return {
|
|
357
|
+
ok: true,
|
|
358
|
+
namespace: buildNamespaceFromPortableRecords(decoded.records),
|
|
359
|
+
diagnostics: [],
|
|
360
|
+
film: {
|
|
361
|
+
version: aes.FILM_VERSION,
|
|
362
|
+
profile: decoded.profile,
|
|
363
|
+
profileExplicit: decoded.profileExplicit,
|
|
364
|
+
projection: decoded.projection,
|
|
365
|
+
projectionExplicit: decoded.projectionExplicit,
|
|
366
|
+
records: decoded.records,
|
|
367
|
+
},
|
|
368
|
+
};
|
|
369
|
+
} catch (error) {
|
|
370
|
+
const errors = [{
|
|
371
|
+
code: 'SANSA_QUERY_WORKBENCH_INVALID_PORTABLE_AES',
|
|
372
|
+
message: error instanceof Error ? error.message : String(error),
|
|
373
|
+
}];
|
|
374
|
+
return {
|
|
375
|
+
ok: false,
|
|
376
|
+
mode: 'evaluate',
|
|
377
|
+
sourceKind: 'film',
|
|
378
|
+
text: renderDiagnosticText(errors),
|
|
379
|
+
errors,
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
175
384
|
async function mountParamsLocalSpace(namespace, paramsSource) {
|
|
176
385
|
if (String(paramsSource).trim().length === 0) {
|
|
177
386
|
return { ok: true, namespace, diagnostics: [] };
|
|
@@ -256,7 +465,7 @@ async function loadAeonCore() {
|
|
|
256
465
|
try {
|
|
257
466
|
return { ok: true, module: await import(candidate.href) };
|
|
258
467
|
} catch (error) {
|
|
259
|
-
failures.push(`${candidate.label}: ${error
|
|
468
|
+
failures.push(`${candidate.label}: ${caughtErrorMessage(error)}`);
|
|
260
469
|
}
|
|
261
470
|
}
|
|
262
471
|
|
|
@@ -270,6 +479,27 @@ async function loadAeonCore() {
|
|
|
270
479
|
};
|
|
271
480
|
}
|
|
272
481
|
|
|
482
|
+
export async function loadAeonAesRuntime() {
|
|
483
|
+
const candidates = aeonAesCandidates();
|
|
484
|
+
const failures = [];
|
|
485
|
+
for (const candidate of candidates) {
|
|
486
|
+
try {
|
|
487
|
+
return { ok: true, module: await import(candidate.href) };
|
|
488
|
+
} catch (error) {
|
|
489
|
+
failures.push(`${candidate.label}: ${caughtErrorMessage(error)}`);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return {
|
|
494
|
+
ok: false,
|
|
495
|
+
message: [
|
|
496
|
+
'Could not load an AEON AES TypeScript runtime.',
|
|
497
|
+
'Install @altopelago/aeon-aes in the calling project, set SANSA_AEON_AES_MODULE to a module path or specifier, or run from the aeon-family development workspace.',
|
|
498
|
+
...(failures.length === 0 ? [] : [`Tried: ${failures.join('; ')}`]),
|
|
499
|
+
].join(' '),
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
|
|
273
503
|
function aeonCoreCandidates() {
|
|
274
504
|
const candidates = [];
|
|
275
505
|
if (process.env.SANSA_AEON_CORE_MODULE) {
|
|
@@ -299,6 +529,35 @@ function aeonCoreCandidates() {
|
|
|
299
529
|
return candidates;
|
|
300
530
|
}
|
|
301
531
|
|
|
532
|
+
function aeonAesCandidates() {
|
|
533
|
+
const candidates = [];
|
|
534
|
+
if (process.env.SANSA_AEON_AES_MODULE) {
|
|
535
|
+
candidates.push({
|
|
536
|
+
label: 'SANSA_AEON_AES_MODULE',
|
|
537
|
+
href: moduleHref(process.env.SANSA_AEON_AES_MODULE),
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
try {
|
|
542
|
+
candidates.push({
|
|
543
|
+
label: '@altopelago/aeon-aes',
|
|
544
|
+
href: pathToFileURL(requireFromCwd.resolve('@altopelago/aeon-aes')).href,
|
|
545
|
+
});
|
|
546
|
+
} catch {
|
|
547
|
+
// Optional integration. AEON and JSON sources do not need the AES codec.
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
const devPath = fileURLToPath(devAeonAesUrl);
|
|
551
|
+
if (existsSync(devPath)) {
|
|
552
|
+
candidates.push({
|
|
553
|
+
label: 'aeon-family development path',
|
|
554
|
+
href: devAeonAesUrl.href,
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
return candidates;
|
|
559
|
+
}
|
|
560
|
+
|
|
302
561
|
function moduleHref(specifier) {
|
|
303
562
|
if (specifier.startsWith('file:')) return specifier;
|
|
304
563
|
if (specifier.startsWith('.') || specifier.startsWith('/')) {
|
|
@@ -311,6 +570,15 @@ function moduleHref(specifier) {
|
|
|
311
570
|
}
|
|
312
571
|
}
|
|
313
572
|
|
|
573
|
+
function caughtErrorMessage(error) {
|
|
574
|
+
if (error instanceof Error) return error.message;
|
|
575
|
+
try {
|
|
576
|
+
return String(error);
|
|
577
|
+
} catch {
|
|
578
|
+
return 'Unknown module import failure';
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
314
582
|
function remapLocalSpaceBinding(binding, targetAddress) {
|
|
315
583
|
return remapBindingTree({
|
|
316
584
|
...binding,
|
|
@@ -392,6 +660,12 @@ function buildNamespaceFromEvents(events, formatPath) {
|
|
|
392
660
|
attributeSpace: (binding) => binding.attributeSpace,
|
|
393
661
|
localSpace: (binding, name) => binding.localSpaces?.[name],
|
|
394
662
|
parent: (binding) => parents.get(binding) ?? binding.parent,
|
|
663
|
+
representationKindMatches: (binding, expected) => {
|
|
664
|
+
const actual = binding.representationKind;
|
|
665
|
+
return actual === expected
|
|
666
|
+
|| lowerFirst(actual) === expected
|
|
667
|
+
|| portableRepresentationAlias(actual) === expected;
|
|
668
|
+
},
|
|
395
669
|
};
|
|
396
670
|
}
|
|
397
671
|
|
|
@@ -429,6 +703,234 @@ function buildAttributeSpace(ownerAddress, annotations, parents, parent) {
|
|
|
429
703
|
return attributeSpace;
|
|
430
704
|
}
|
|
431
705
|
|
|
706
|
+
function buildNamespaceFromPortableRecords(records) {
|
|
707
|
+
const root = {
|
|
708
|
+
address: '$',
|
|
709
|
+
representationKind: 'object',
|
|
710
|
+
children: [],
|
|
711
|
+
};
|
|
712
|
+
const bodyRecords = records.filter((record) => typeof record.path === 'string');
|
|
713
|
+
const byAddress = new Map([['$', root]]);
|
|
714
|
+
const parsedByAddress = new Map();
|
|
715
|
+
const parents = new Map([[root, null]]);
|
|
716
|
+
|
|
717
|
+
for (const record of bodyRecords) {
|
|
718
|
+
const parsed = parseAddress(record.path);
|
|
719
|
+
if (!parsed.ok || !parsed.address.isExact) {
|
|
720
|
+
const message = parsed.ok
|
|
721
|
+
? `Portable AES path is not exact: ${record.path}`
|
|
722
|
+
: parsed.errors[0]?.message ?? `Invalid portable AES path: ${record.path}`;
|
|
723
|
+
throw new Error(message);
|
|
724
|
+
}
|
|
725
|
+
const selectors = parsed.address.selectors;
|
|
726
|
+
const final = selectors[selectors.length - 1];
|
|
727
|
+
if (!final || !['member', 'position'].includes(final.type)) {
|
|
728
|
+
throw new Error(`Portable AES event path must end in a member or index: ${record.path}`);
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
byAddress.set(record.path, portableBinding(record, final));
|
|
732
|
+
parsedByAddress.set(record.path, parsed.address);
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
for (const record of bodyRecords) {
|
|
736
|
+
const binding = byAddress.get(record.path);
|
|
737
|
+
const address = parsedByAddress.get(record.path);
|
|
738
|
+
let currentAddress = '$';
|
|
739
|
+
let parent = root;
|
|
740
|
+
|
|
741
|
+
for (const selector of address.selectors.slice(0, -1)) {
|
|
742
|
+
if (selector.type === 'attributeSpace') {
|
|
743
|
+
const spaceAddress = `${currentAddress}.@`;
|
|
744
|
+
let space = byAddress.get(spaceAddress);
|
|
745
|
+
if (!space) {
|
|
746
|
+
space = {
|
|
747
|
+
address: spaceAddress,
|
|
748
|
+
representationKind: 'attributeSpace',
|
|
749
|
+
children: [],
|
|
750
|
+
};
|
|
751
|
+
byAddress.set(spaceAddress, space);
|
|
752
|
+
parents.set(space, parent);
|
|
753
|
+
parent.attributeSpace = space;
|
|
754
|
+
}
|
|
755
|
+
currentAddress = spaceAddress;
|
|
756
|
+
parent = space;
|
|
757
|
+
continue;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
currentAddress = selector.type === 'member'
|
|
761
|
+
? appendMember(currentAddress, selector.name)
|
|
762
|
+
: `${currentAddress}[${selector.index}]`;
|
|
763
|
+
const nextParent = byAddress.get(currentAddress);
|
|
764
|
+
if (!nextParent) {
|
|
765
|
+
throw new Error(`Portable AES path '${record.path}' has no parent binding '${currentAddress}'.`);
|
|
766
|
+
}
|
|
767
|
+
parent = nextParent;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
parent.children.push(binding);
|
|
771
|
+
parents.set(binding, parent);
|
|
772
|
+
if (binding.representationKind === 'NodeHead' && parent.representationKind === 'NodeLiteral') {
|
|
773
|
+
parent.nodeTag = binding.value;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
return {
|
|
778
|
+
root,
|
|
779
|
+
children: (binding) => binding.children ?? [],
|
|
780
|
+
attributeSpace: (binding) => binding.attributeSpace,
|
|
781
|
+
localSpace: (binding, name) => binding.localSpaces?.[name],
|
|
782
|
+
parent: (binding) => parents.get(binding) ?? binding.parent,
|
|
783
|
+
representationKindMatches: (binding, expected) => {
|
|
784
|
+
const actual = binding.representationKind;
|
|
785
|
+
return actual === expected
|
|
786
|
+
|| lowerFirst(actual) === expected
|
|
787
|
+
|| portableRepresentationAlias(actual) === expected;
|
|
788
|
+
},
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
function portableBinding(record, finalSelector) {
|
|
793
|
+
const semanticType = typeof record.datatype === 'string'
|
|
794
|
+
? record.datatype
|
|
795
|
+
: portableSemanticType(record.kind);
|
|
796
|
+
const binding = {
|
|
797
|
+
address: record.path,
|
|
798
|
+
children: [],
|
|
799
|
+
representationKind: record.kind,
|
|
800
|
+
...(finalSelector.type === 'member' ? { name: finalSelector.name } : { index: finalSelector.index }),
|
|
801
|
+
...(typeof record.identity === 'string' ? { identity: record.identity } : {}),
|
|
802
|
+
...(semanticType === undefined ? {} : { semanticType }),
|
|
803
|
+
...(typeof record.datatype === 'string' ? { datatype: record.datatype } : {}),
|
|
804
|
+
...(Array.isArray(record.generics) ? { generics: record.generics } : {}),
|
|
805
|
+
...(Array.isArray(record.clarifiers) ? { clarifiers: record.clarifiers } : {}),
|
|
806
|
+
...(typeof record.origin === 'string' ? { origin: record.origin } : {}),
|
|
807
|
+
...(typeof record.span === 'string' ? { span: record.span } : {}),
|
|
808
|
+
};
|
|
809
|
+
const scalarKind = portableScalarKind(record.kind);
|
|
810
|
+
if (scalarKind !== undefined) binding.scalarKind = scalarKind;
|
|
811
|
+
const scalar = scalarFromPortableRecord(record);
|
|
812
|
+
if (scalar.ok) binding.value = scalar.value;
|
|
813
|
+
if (record.kind === 'NullLiteral') binding.nullReason = record.value;
|
|
814
|
+
if (record.kind === 'NodeHead' && typeof record.value === 'string') binding.nodeTag = record.value;
|
|
815
|
+
return binding;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
function portableSemanticType(kind) {
|
|
819
|
+
switch (kind) {
|
|
820
|
+
case 'StringLiteral': return 'string';
|
|
821
|
+
case 'NumberLiteral': return 'number';
|
|
822
|
+
case 'InfinityLiteral': return 'infinity';
|
|
823
|
+
case 'NaNLiteral': return 'nan';
|
|
824
|
+
case 'NullLiteral': return 'null';
|
|
825
|
+
case 'BooleanLiteral': return 'boolean';
|
|
826
|
+
case 'ToggleLiteral': return 'toggle';
|
|
827
|
+
case 'HexLiteral': return 'hex';
|
|
828
|
+
case 'RadixLiteral': return 'radix';
|
|
829
|
+
case 'EncodingLiteral': return 'encoding';
|
|
830
|
+
case 'SeparatorLiteral': return 'sep';
|
|
831
|
+
case 'SansaAddressLiteral': return 'sansa';
|
|
832
|
+
case 'DateLiteral': return 'date';
|
|
833
|
+
case 'TimeLiteral': return 'time';
|
|
834
|
+
case 'DateTimeLiteral': return 'datetime';
|
|
835
|
+
case 'WTCDateTimeLiteral': return 'wtc';
|
|
836
|
+
default: return undefined;
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
function portableScalarKind(kind) {
|
|
841
|
+
switch (kind) {
|
|
842
|
+
case 'NullLiteral': return 'null';
|
|
843
|
+
case 'InfinityLiteral': return 'infinity';
|
|
844
|
+
case 'NaNLiteral': return 'nan';
|
|
845
|
+
case 'ToggleLiteral': return 'toggle';
|
|
846
|
+
case 'HexLiteral': return 'hex';
|
|
847
|
+
case 'RadixLiteral': return 'radix';
|
|
848
|
+
case 'EncodingLiteral': return 'encoding';
|
|
849
|
+
case 'SeparatorLiteral': return 'separator';
|
|
850
|
+
case 'SansaAddressLiteral': return 'sansaAddress';
|
|
851
|
+
case 'DateLiteral': return 'date';
|
|
852
|
+
case 'TimeLiteral': return 'time';
|
|
853
|
+
case 'DateTimeLiteral': return 'datetime';
|
|
854
|
+
case 'WTCDateTimeLiteral': return 'wtc';
|
|
855
|
+
case 'CloneReference':
|
|
856
|
+
case 'PointerReference':
|
|
857
|
+
return 'referenceForm';
|
|
858
|
+
default:
|
|
859
|
+
return undefined;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
function portableRepresentationAlias(kind) {
|
|
864
|
+
switch (kind) {
|
|
865
|
+
case 'StringLiteral': return 'string';
|
|
866
|
+
case 'NumberLiteral': return 'number';
|
|
867
|
+
case 'InfinityLiteral': return 'infinity';
|
|
868
|
+
case 'NaNLiteral': return 'nan';
|
|
869
|
+
case 'NullLiteral': return 'null';
|
|
870
|
+
case 'BooleanLiteral': return 'boolean';
|
|
871
|
+
case 'ToggleLiteral': return 'toggle';
|
|
872
|
+
case 'HexLiteral': return 'hex';
|
|
873
|
+
case 'RadixLiteral': return 'radix';
|
|
874
|
+
case 'EncodingLiteral': return 'encoding';
|
|
875
|
+
case 'SeparatorLiteral': return 'separator';
|
|
876
|
+
case 'SansaAddressLiteral': return 'sansa';
|
|
877
|
+
case 'DateLiteral': return 'date';
|
|
878
|
+
case 'TimeLiteral': return 'time';
|
|
879
|
+
case 'DateTimeLiteral': return 'datetime';
|
|
880
|
+
case 'WTCDateTimeLiteral': return 'wtc';
|
|
881
|
+
case 'ObjectNode': return 'object';
|
|
882
|
+
case 'ListNode': return 'list';
|
|
883
|
+
case 'TupleLiteral': return 'tuple';
|
|
884
|
+
case 'NodeLiteral': return 'node';
|
|
885
|
+
case 'CloneReference': return 'cloneReference';
|
|
886
|
+
case 'PointerReference': return 'pointerReference';
|
|
887
|
+
default: return undefined;
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
function scalarFromPortableRecord(record) {
|
|
892
|
+
switch (record.kind) {
|
|
893
|
+
case 'StringLiteral':
|
|
894
|
+
case 'HexLiteral':
|
|
895
|
+
case 'RadixLiteral':
|
|
896
|
+
case 'EncodingLiteral':
|
|
897
|
+
case 'SeparatorLiteral':
|
|
898
|
+
case 'DateLiteral':
|
|
899
|
+
case 'TimeLiteral':
|
|
900
|
+
case 'DateTimeLiteral':
|
|
901
|
+
case 'WTCDateTimeLiteral':
|
|
902
|
+
case 'NodeHead':
|
|
903
|
+
return { ok: true, value: record.value ?? '' };
|
|
904
|
+
case 'SansaAddressLiteral':
|
|
905
|
+
return {
|
|
906
|
+
ok: true,
|
|
907
|
+
value: {
|
|
908
|
+
type: 'SansaAddressLiteral',
|
|
909
|
+
address: record.value ?? '',
|
|
910
|
+
canonical: record.value ?? '',
|
|
911
|
+
},
|
|
912
|
+
};
|
|
913
|
+
case 'NumberLiteral':
|
|
914
|
+
return { ok: true, value: Number(record.value) };
|
|
915
|
+
case 'InfinityLiteral':
|
|
916
|
+
return { ok: true, value: record.value === '-Infinity' ? -Infinity : Infinity };
|
|
917
|
+
case 'NaNLiteral':
|
|
918
|
+
return { ok: true, value: Number.NaN };
|
|
919
|
+
case 'BooleanLiteral':
|
|
920
|
+
return { ok: true, value: record.value === 'true' };
|
|
921
|
+
case 'ToggleLiteral':
|
|
922
|
+
return { ok: true, value: record.value ?? '' };
|
|
923
|
+
case 'NullLiteral':
|
|
924
|
+
return { ok: true, value: null };
|
|
925
|
+
case 'CloneReference':
|
|
926
|
+
return { ok: true, value: referenceFormValue('CloneReference', record.value ?? '') };
|
|
927
|
+
case 'PointerReference':
|
|
928
|
+
return { ok: true, value: referenceFormValue('PointerReference', record.value ?? '') };
|
|
929
|
+
default:
|
|
930
|
+
return { ok: false };
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
|
|
432
934
|
function appendMember(base, name) {
|
|
433
935
|
return /^[A-Za-z_][A-Za-z0-9_]*$/.test(name)
|
|
434
936
|
? `${base}.${name}`
|
|
@@ -772,6 +1274,7 @@ function renderBindingInspectLines(binding, label) {
|
|
|
772
1274
|
return [
|
|
773
1275
|
...(summary.name === undefined ? [] : [`${label}.name: ${summary.name}`]),
|
|
774
1276
|
...(summary.index === undefined ? [] : [`${label}.index: ${summary.index}`]),
|
|
1277
|
+
...(summary.identity === undefined ? [] : [`${label}.identity: ${summary.identity}`]),
|
|
775
1278
|
...(summary.semanticType === undefined ? [] : [`${label}.semanticType: ${summary.semanticType}`]),
|
|
776
1279
|
...(summary.representationKind === undefined ? [] : [`${label}.representationKind: ${summary.representationKind}`]),
|
|
777
1280
|
...(summary.scalarKind === undefined ? [] : [`${label}.scalarKind: ${summary.scalarKind}`]),
|
|
@@ -825,6 +1328,7 @@ function summarizeBinding(binding) {
|
|
|
825
1328
|
...(binding.address === undefined ? {} : { address: binding.address }),
|
|
826
1329
|
...(binding.name === undefined ? {} : { name: binding.name }),
|
|
827
1330
|
...(binding.index === undefined ? {} : { index: binding.index }),
|
|
1331
|
+
...(binding.identity === undefined ? {} : { identity: binding.identity }),
|
|
828
1332
|
...(binding.semanticType === undefined ? {} : { semanticType: binding.semanticType }),
|
|
829
1333
|
...(binding.representationKind === undefined ? {} : { representationKind: binding.representationKind }),
|
|
830
1334
|
...(binding.scalarKind === undefined ? {} : { scalarKind: binding.scalarKind }),
|