@altopelago/sansa 0.10.0 → 0.10.1

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/src/index.d.ts CHANGED
@@ -262,11 +262,15 @@ export interface SansaMutateDiagnostic {
262
262
 
263
263
  export interface SansaResolveBinding {
264
264
  readonly address?: string;
265
+ /** Opaque structural occurrence identity supplied by the host namespace. */
266
+ readonly identity?: string;
265
267
  readonly name?: string;
266
268
  readonly key?: string;
267
269
  readonly index?: number;
268
270
  readonly semanticType?: string;
269
271
  readonly datatype?: string;
272
+ readonly generics?: readonly SansaDatatypeGenericComponent[];
273
+ readonly clarifiers?: readonly SansaDatatypeClarifierComponent[];
270
274
  readonly representationKind?: string;
271
275
  readonly kind?: string;
272
276
  readonly type?: string;
@@ -276,12 +280,33 @@ export interface SansaResolveBinding {
276
280
  readonly nullReason?: string;
277
281
  readonly value?: unknown;
278
282
  readonly scalar?: unknown;
283
+ readonly origin?: string;
284
+ readonly span?: string;
279
285
  readonly children?: readonly SansaResolveBinding[];
280
286
  readonly parent?: SansaResolveBinding | null;
281
287
  readonly attributeSpace?: SansaResolveBinding;
282
288
  readonly attributes?: SansaResolveBinding;
283
289
  }
284
290
 
291
+ export interface SansaDatatypeDescriptor {
292
+ readonly datatype: string;
293
+ readonly generics: readonly SansaDatatypeGenericComponent[];
294
+ readonly clarifiers: readonly SansaDatatypeClarifierComponent[];
295
+ }
296
+
297
+ export interface SansaDatatypeStringComponent {
298
+ readonly kind: 'StringLiteral';
299
+ readonly value: string;
300
+ }
301
+
302
+ export interface SansaDatatypeNumberComponent {
303
+ readonly kind: 'NumberLiteral';
304
+ readonly value: string;
305
+ }
306
+
307
+ export type SansaDatatypeGenericComponent = SansaDatatypeDescriptor | SansaDatatypeNumberComponent;
308
+ export type SansaDatatypeClarifierComponent = SansaDatatypeStringComponent | SansaDatatypeNumberComponent;
309
+
285
310
  export interface SansaResolveNamespace<TBinding extends object = SansaResolveBinding> {
286
311
  readonly root: TBinding | (() => TBinding | undefined);
287
312
  readonly contextualRoot?: TBinding;
@@ -630,6 +655,8 @@ export type SansaMutationTargetSurfaceInput<TBinding extends object = SansaResol
630
655
  | 'aeon'
631
656
  | 'json'
632
657
  | 'json-compatible'
658
+ | 'telex'
659
+ | 'telex.aes'
633
660
  | SansaMutationTargetSurface<TBinding>;
634
661
 
635
662
  export interface SansaMutationTargetSurface<TBinding extends object = SansaResolveBinding> {
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) {
@@ -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
- let defaultSource = '';
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 = defaultSource;
52
- sourceStatus.textContent = 'default aeon';
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
- defaultSource = await fetchText('/fixtures/query-inventory.aeon', [
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
- sourceInput.value = defaultSource;
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 ?? 'aeon';
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">AEON Source</label>
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>