@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
package/src/index.js
CHANGED
|
@@ -1670,6 +1670,9 @@ function resolveMutationTargetSurface(targetSurface) {
|
|
|
1670
1670
|
if (targetSurface === 'json' || targetSurface === 'json-compatible') {
|
|
1671
1671
|
return { ok: true, surface: jsonMutationTargetSurface };
|
|
1672
1672
|
}
|
|
1673
|
+
if (targetSurface === 'telex' || targetSurface === 'telex.aes') {
|
|
1674
|
+
return { ok: true, surface: telexMutationTargetSurface };
|
|
1675
|
+
}
|
|
1673
1676
|
if (targetSurface && typeof targetSurface === 'object' && typeof targetSurface.validateOperation === 'function') {
|
|
1674
1677
|
return {
|
|
1675
1678
|
ok: true,
|
|
@@ -1683,7 +1686,7 @@ function resolveMutationTargetSurface(targetSurface) {
|
|
|
1683
1686
|
ok: false,
|
|
1684
1687
|
error: mutationTargetSurfaceError(
|
|
1685
1688
|
'SANSA_MUTATE_TARGET_UNSUPPORTED_FEATURE',
|
|
1686
|
-
'Mutation target surface must be "aeon", "json", or an object with validateOperation',
|
|
1689
|
+
'Mutation target surface must be "aeon", "json", "json-compatible", "telex", "telex.aes", or an object with validateOperation',
|
|
1687
1690
|
{ targetFormat: targetSurfaceId(targetSurface) },
|
|
1688
1691
|
),
|
|
1689
1692
|
};
|
|
@@ -1724,6 +1727,159 @@ const jsonMutationTargetSurface = Object.freeze({
|
|
|
1724
1727
|
},
|
|
1725
1728
|
});
|
|
1726
1729
|
|
|
1730
|
+
const TELEX_SCALAR_KINDS = new Set([
|
|
1731
|
+
'StringLiteral',
|
|
1732
|
+
'NumberLiteral',
|
|
1733
|
+
'InfinityLiteral',
|
|
1734
|
+
'NaNLiteral',
|
|
1735
|
+
'NullLiteral',
|
|
1736
|
+
'BooleanLiteral',
|
|
1737
|
+
'ToggleLiteral',
|
|
1738
|
+
'HexLiteral',
|
|
1739
|
+
'RadixLiteral',
|
|
1740
|
+
'EncodingLiteral',
|
|
1741
|
+
'SeparatorLiteral',
|
|
1742
|
+
'SansaAddressLiteral',
|
|
1743
|
+
'DateLiteral',
|
|
1744
|
+
'TimeLiteral',
|
|
1745
|
+
'DateTimeLiteral',
|
|
1746
|
+
'WTCDateTimeLiteral',
|
|
1747
|
+
]);
|
|
1748
|
+
|
|
1749
|
+
const TELEX_KIND_ALIASES = new Map([
|
|
1750
|
+
['string', 'StringLiteral'], ['trimtick', 'StringLiteral'], ['prose', 'StringLiteral'],
|
|
1751
|
+
['number', 'NumberLiteral'], ['n', 'NumberLiteral'], ['integer', 'NumberLiteral'],
|
|
1752
|
+
['boolean', 'BooleanLiteral'], ['bool', 'BooleanLiteral'], ['toggle', 'ToggleLiteral'],
|
|
1753
|
+
['null', 'NullLiteral'], ['nan', 'NaNLiteral'], ['infinity', 'InfinityLiteral'],
|
|
1754
|
+
['hex', 'HexLiteral'], ['radix', 'RadixLiteral'], ['encoding', 'EncodingLiteral'],
|
|
1755
|
+
['base64', 'EncodingLiteral'], ['embed', 'EncodingLiteral'], ['inline', 'EncodingLiteral'],
|
|
1756
|
+
['separator', 'SeparatorLiteral'], ['sep', 'SeparatorLiteral'], ['csv', 'SeparatorLiteral'],
|
|
1757
|
+
['sansa', 'SansaAddressLiteral'], ['sansaaddress', 'SansaAddressLiteral'],
|
|
1758
|
+
['date', 'DateLiteral'], ['time', 'TimeLiteral'], ['datetime', 'DateTimeLiteral'], ['wtc', 'WTCDateTimeLiteral'],
|
|
1759
|
+
]);
|
|
1760
|
+
|
|
1761
|
+
const telexMutationTargetSurface = Object.freeze({
|
|
1762
|
+
id: 'telex',
|
|
1763
|
+
validateOperation(operation, context) {
|
|
1764
|
+
if (operation.op !== 'replace') {
|
|
1765
|
+
return {
|
|
1766
|
+
ok: false,
|
|
1767
|
+
error: mutationTargetSurfaceError(
|
|
1768
|
+
'SANSA_MUTATE_TARGET_UNSUPPORTED_OPERATION',
|
|
1769
|
+
`Target 'telex' currently supports scalar replacement only; '${operation.op}' requires a portable path-rewrite contract`,
|
|
1770
|
+
{ operationIndex: context.operationIndex, targetFormat: 'telex' },
|
|
1771
|
+
),
|
|
1772
|
+
};
|
|
1773
|
+
}
|
|
1774
|
+
const exposedKind = operation.target?.binding?.representationKind;
|
|
1775
|
+
const kind = TELEX_SCALAR_KINDS.has(exposedKind)
|
|
1776
|
+
? exposedKind
|
|
1777
|
+
: TELEX_KIND_ALIASES.get(String(exposedKind ?? '').toLowerCase());
|
|
1778
|
+
if (!TELEX_SCALAR_KINDS.has(kind)) {
|
|
1779
|
+
return {
|
|
1780
|
+
ok: false,
|
|
1781
|
+
error: mutationTargetSurfaceError(
|
|
1782
|
+
'SANSA_MUTATE_TARGET_UNSUPPORTED_FEATURE',
|
|
1783
|
+
`Target 'telex' cannot replace '${exposedKind ?? 'unknown'}' bindings in the scalar-replacement profile`,
|
|
1784
|
+
{ operationIndex: context.operationIndex, targetFormat: 'telex' },
|
|
1785
|
+
),
|
|
1786
|
+
};
|
|
1787
|
+
}
|
|
1788
|
+
if (operation.value !== null && typeof operation.value === 'object') {
|
|
1789
|
+
return {
|
|
1790
|
+
ok: false,
|
|
1791
|
+
error: mutationTargetSurfaceError(
|
|
1792
|
+
'SANSA_MUTATE_TARGET_UNSUPPORTED_VALUE',
|
|
1793
|
+
"Target 'telex' scalar replacement requires a scalar mutation value",
|
|
1794
|
+
{ operationIndex: context.operationIndex, targetFormat: 'telex', valuePath: `operations[${context.operationIndex}].value` },
|
|
1795
|
+
),
|
|
1796
|
+
};
|
|
1797
|
+
}
|
|
1798
|
+
const proposedKind = telexProposedScalarKind(operation, kind);
|
|
1799
|
+
if (!proposedKind.ok) {
|
|
1800
|
+
return {
|
|
1801
|
+
ok: false,
|
|
1802
|
+
error: mutationTargetSurfaceError(
|
|
1803
|
+
proposedKind.code,
|
|
1804
|
+
proposedKind.message,
|
|
1805
|
+
{ operationIndex: context.operationIndex, targetFormat: 'telex', ...(operation.datatype === undefined ? {} : { datatype: operation.datatype }) },
|
|
1806
|
+
),
|
|
1807
|
+
};
|
|
1808
|
+
}
|
|
1809
|
+
const valueResult = validateTelexScalarMutationValue(proposedKind.kind, operation.value, kind);
|
|
1810
|
+
if (!valueResult.ok) {
|
|
1811
|
+
return {
|
|
1812
|
+
ok: false,
|
|
1813
|
+
error: mutationTargetSurfaceError(
|
|
1814
|
+
'SANSA_MUTATE_TARGET_UNSUPPORTED_VALUE',
|
|
1815
|
+
valueResult.message,
|
|
1816
|
+
{ operationIndex: context.operationIndex, targetFormat: 'telex', valuePath: `operations[${context.operationIndex}].value` },
|
|
1817
|
+
),
|
|
1818
|
+
};
|
|
1819
|
+
}
|
|
1820
|
+
return { ok: true };
|
|
1821
|
+
},
|
|
1822
|
+
});
|
|
1823
|
+
|
|
1824
|
+
function telexProposedScalarKind(operation, fallback) {
|
|
1825
|
+
if (operation.kind !== undefined) {
|
|
1826
|
+
if (TELEX_SCALAR_KINDS.has(operation.kind)) return { ok: true, kind: operation.kind };
|
|
1827
|
+
const alias = TELEX_KIND_ALIASES.get(String(operation.kind).toLowerCase());
|
|
1828
|
+
if (alias !== undefined) return { ok: true, kind: alias };
|
|
1829
|
+
return {
|
|
1830
|
+
ok: false,
|
|
1831
|
+
code: 'SANSA_MUTATE_TARGET_UNSUPPORTED_FEATURE',
|
|
1832
|
+
message: `Target 'telex' scalar replacement cannot represent kind '${operation.kind}'`,
|
|
1833
|
+
};
|
|
1834
|
+
}
|
|
1835
|
+
if (operation.datatype !== undefined) {
|
|
1836
|
+
const base = datatypeBaseName(operation.datatype)?.toLowerCase();
|
|
1837
|
+
const alias = TELEX_KIND_ALIASES.get(base);
|
|
1838
|
+
if (alias !== undefined) return { ok: true, kind: alias };
|
|
1839
|
+
if (/^(?:u?int|float|decimal)\d*$/u.test(base ?? '')) return { ok: true, kind: 'NumberLiteral' };
|
|
1840
|
+
if (/^radix\d+$/u.test(base ?? '')) return { ok: true, kind: 'RadixLiteral' };
|
|
1841
|
+
if (['object', 'list', 'tuple', 'node', 'clonereference', 'pointerreference'].includes(base)) {
|
|
1842
|
+
return {
|
|
1843
|
+
ok: false,
|
|
1844
|
+
code: 'SANSA_MUTATE_TARGET_UNSUPPORTED_DATATYPE',
|
|
1845
|
+
message: `Target 'telex' scalar replacement cannot represent datatype '${operation.datatype}'`,
|
|
1846
|
+
};
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
return { ok: true, kind: fallback };
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
function validateTelexScalarMutationValue(kind, value, currentKind) {
|
|
1853
|
+
if (kind === 'NumberLiteral') {
|
|
1854
|
+
return typeof value === 'number' && Number.isFinite(value)
|
|
1855
|
+
? { ok: true }
|
|
1856
|
+
: { ok: false, message: "Target 'telex' NumberLiteral replacement requires a finite JSON number" };
|
|
1857
|
+
}
|
|
1858
|
+
if (kind === 'BooleanLiteral') {
|
|
1859
|
+
return typeof value === 'boolean'
|
|
1860
|
+
? { ok: true }
|
|
1861
|
+
: { ok: false, message: "Target 'telex' BooleanLiteral replacement requires a JSON boolean" };
|
|
1862
|
+
}
|
|
1863
|
+
if (kind === 'NullLiteral') {
|
|
1864
|
+
return (typeof value === 'string' && value.length > 0) || (value === null && currentKind === 'NullLiteral')
|
|
1865
|
+
? { ok: true }
|
|
1866
|
+
: { ok: false, message: "Target 'telex' NullLiteral replacement requires a non-empty reason string, or null for an existing null event" };
|
|
1867
|
+
}
|
|
1868
|
+
if (kind === 'NaNLiteral') {
|
|
1869
|
+
return value === null || value === 'NaN'
|
|
1870
|
+
? { ok: true }
|
|
1871
|
+
: { ok: false, message: "Target 'telex' NaNLiteral replacement requires null or 'NaN'" };
|
|
1872
|
+
}
|
|
1873
|
+
if (kind === 'InfinityLiteral') {
|
|
1874
|
+
return value === Infinity || value === -Infinity || ['Infinity', '+Infinity', '-Infinity'].includes(value)
|
|
1875
|
+
? { ok: true }
|
|
1876
|
+
: { ok: false, message: "Target 'telex' InfinityLiteral replacement requires an infinity token" };
|
|
1877
|
+
}
|
|
1878
|
+
return typeof value === 'string'
|
|
1879
|
+
? { ok: true }
|
|
1880
|
+
: { ok: false, message: `Target 'telex' ${kind} replacement requires a JSON string` };
|
|
1881
|
+
}
|
|
1882
|
+
|
|
1727
1883
|
function normalizeMutationTargetSurfaceOperationResult(result, context) {
|
|
1728
1884
|
if (result === undefined || result === true || result?.ok === true) return { ok: true };
|
|
1729
1885
|
if (result === false) {
|
|
@@ -5815,7 +5971,7 @@ function matchesRepresentationKind(namespace, binding, expected) {
|
|
|
5815
5971
|
const actual = typeof namespace.representationKind === 'function'
|
|
5816
5972
|
? namespace.representationKind(binding)
|
|
5817
5973
|
: binding.representationKind ?? binding.kind ?? binding.type;
|
|
5818
|
-
return typeof actual === 'string' && lowerFirst(actual) === expected;
|
|
5974
|
+
return typeof actual === 'string' && (actual === expected || lowerFirst(actual) === expected);
|
|
5819
5975
|
}
|
|
5820
5976
|
|
|
5821
5977
|
function resolveBindingLimitError(limit, observed, selectorIndex) {
|
package/tools/mutate-web/app.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defaultPolicy, firstMutateExampleId, mutateExampleGroups, mutateExamples as examples } from './examples.mjs';
|
|
2
2
|
const sourceInput = document.querySelector('#sourceInput');
|
|
3
|
+
const sourceKindInput = document.querySelector('#sourceKind');
|
|
3
4
|
const sourceResultOutput = document.querySelector('#sourceResultOutput');
|
|
4
5
|
const requestInput = document.querySelector('#requestInput');
|
|
5
6
|
const requestInputLabel = document.querySelector('#requestInputLabel');
|
|
@@ -29,7 +30,7 @@ const sourceTabButtons = Array.from(document.querySelectorAll('[data-source-tab]
|
|
|
29
30
|
const detailTabButtons = Array.from(document.querySelectorAll('[data-detail-tab]'));
|
|
30
31
|
const requestKindInputs = Array.from(document.querySelectorAll('input[name="requestKind"]'));
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
const defaultSources = { aeon: '', telex: '' };
|
|
33
34
|
let lastPayload = null;
|
|
34
35
|
let activeSourceTab = 'input';
|
|
35
36
|
let activeDetailTab = 'diagnostics';
|
|
@@ -48,12 +49,20 @@ exampleSelect.addEventListener('change', () => {
|
|
|
48
49
|
});
|
|
49
50
|
|
|
50
51
|
resetButton.addEventListener('click', () => {
|
|
51
|
-
sourceInput.value =
|
|
52
|
-
sourceStatus.textContent =
|
|
52
|
+
sourceInput.value = defaultSources[sourceKind()];
|
|
53
|
+
sourceStatus.textContent = `default ${sourceKind()}`;
|
|
53
54
|
setExample(exampleSelect.value);
|
|
54
55
|
void runMutation('plan');
|
|
55
56
|
});
|
|
56
57
|
|
|
58
|
+
sourceKindInput.addEventListener('change', () => {
|
|
59
|
+
sourceInput.value = defaultSources[sourceKind()];
|
|
60
|
+
targetFormatInput.value = sourceKind();
|
|
61
|
+
sourceStatus.textContent = `default ${sourceKind()}`;
|
|
62
|
+
sourceResultOutput.textContent = 'Run Plan or Apply to render the current source result.';
|
|
63
|
+
void runMutation('plan');
|
|
64
|
+
});
|
|
65
|
+
|
|
57
66
|
planButton.addEventListener('click', () => {
|
|
58
67
|
void runMutation('plan');
|
|
59
68
|
});
|
|
@@ -121,7 +130,7 @@ requestInput.addEventListener('keydown', (event) => {
|
|
|
121
130
|
});
|
|
122
131
|
|
|
123
132
|
async function loadDefaults() {
|
|
124
|
-
|
|
133
|
+
defaultSources.aeon = await fetchText('/fixtures/query-inventory.aeon', [
|
|
125
134
|
'inventory = {',
|
|
126
135
|
' items:list<object> = [',
|
|
127
136
|
' { sku:string = "A-100" name:string = "Adapter" qty:int = 1 }',
|
|
@@ -129,7 +138,13 @@ async function loadDefaults() {
|
|
|
129
138
|
' ]',
|
|
130
139
|
'}',
|
|
131
140
|
].join('\n'));
|
|
132
|
-
|
|
141
|
+
defaultSources.telex = await fetchText('/fixtures/query-inventory.telex.aes', [
|
|
142
|
+
'telex.aes=1',
|
|
143
|
+
'',
|
|
144
|
+
'path=$.inventory',
|
|
145
|
+
'kind=ObjectNode',
|
|
146
|
+
].join('\n'));
|
|
147
|
+
sourceInput.value = defaultSources.aeon;
|
|
133
148
|
sourceStatus.textContent = 'default aeon';
|
|
134
149
|
}
|
|
135
150
|
|
|
@@ -171,6 +186,7 @@ async function runMutation(mode) {
|
|
|
171
186
|
resultStatus.textContent = mode === 'apply' ? 'applying' : 'planning';
|
|
172
187
|
resultStatus.dataset.phase = mode === 'apply' ? 'apply' : 'plan';
|
|
173
188
|
const payload = await mutateApi({
|
|
189
|
+
sourceKind: sourceKind(),
|
|
174
190
|
source: sourceInput.value,
|
|
175
191
|
requestSource: requestInput.value,
|
|
176
192
|
requestKind: requestKind(),
|
|
@@ -282,6 +298,10 @@ function requestKind() {
|
|
|
282
298
|
return document.querySelector('input[name="requestKind"]:checked')?.value ?? 'structured';
|
|
283
299
|
}
|
|
284
300
|
|
|
301
|
+
function sourceKind() {
|
|
302
|
+
return sourceKindInput.value === 'telex' ? 'telex' : 'aeon';
|
|
303
|
+
}
|
|
304
|
+
|
|
285
305
|
function currentExample() {
|
|
286
306
|
return examples.find((entry) => entry.id === exampleSelect.value) ?? examples[0];
|
|
287
307
|
}
|
|
@@ -334,7 +354,7 @@ function requestKindLabel() {
|
|
|
334
354
|
}
|
|
335
355
|
|
|
336
356
|
function setOptionInputs(options) {
|
|
337
|
-
targetFormatInput.value = options.targetFormat ??
|
|
357
|
+
targetFormatInput.value = options.targetFormat ?? sourceKind();
|
|
338
358
|
if (options.policySource !== undefined) {
|
|
339
359
|
enforcePolicyInput.checked = true;
|
|
340
360
|
policyInput.value = options.policySource;
|
|
@@ -23,7 +23,11 @@
|
|
|
23
23
|
<section class="workspace" aria-label="SANSA Mutate workspace">
|
|
24
24
|
<section class="panel source-panel">
|
|
25
25
|
<div class="panel-head">
|
|
26
|
-
<label for="sourceInput">
|
|
26
|
+
<label for="sourceInput">Source</label>
|
|
27
|
+
<select id="sourceKind" aria-label="Source format">
|
|
28
|
+
<option value="aeon" selected>AEON</option>
|
|
29
|
+
<option value="telex">Telex AES</option>
|
|
30
|
+
</select>
|
|
27
31
|
<span id="sourceStatus">default aeon</span>
|
|
28
32
|
</div>
|
|
29
33
|
<div class="source-tabs" role="tablist" aria-label="Source views">
|
|
@@ -68,6 +72,7 @@
|
|
|
68
72
|
<select id="targetFormat" aria-label="Target format">
|
|
69
73
|
<option value="aeon" selected>AEON</option>
|
|
70
74
|
<option value="json">JSON</option>
|
|
75
|
+
<option value="telex">Telex AES</option>
|
|
71
76
|
</select>
|
|
72
77
|
</label>
|
|
73
78
|
</div>
|