@altopelago/sansa 0.11.1 → 0.13.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@altopelago/sansa",
3
- "version": "0.11.1",
3
+ "version": "0.13.0",
4
4
  "description": "Semantic Address NameSpace Abstraction parser, resolver, and query toolkit.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -65,7 +65,8 @@
65
65
  "version:check": "node scripts/version.mjs check",
66
66
  "version:recover": "node scripts/version.mjs recover",
67
67
  "validate:cts-claims": "node scripts/validate-cts-claims.mjs",
68
- "test": "node --test test/*.test.js"
68
+ "test": "node --test test/*.test.js",
69
+ "test:rust": "cargo fmt --all --check --manifest-path implementations/rust/Cargo.toml && cargo clippy --locked --workspace --all-features --all-targets --manifest-path implementations/rust/Cargo.toml -- -D warnings && cargo test --locked --workspace --all-features --all-targets --manifest-path implementations/rust/Cargo.toml"
69
70
  },
70
71
  "keywords": [
71
72
  "sansa",
@@ -9,7 +9,7 @@ const root = resolve(here, '..');
9
9
  const ctsRoot = process.env.AEONITE_CTS_ROOT
10
10
  ? resolve(process.env.AEONITE_CTS_ROOT)
11
11
  : resolve(root, '..', '..', 'aeonite-org', 'aeonite-cts', 'cts');
12
- const manifestPath = readArg('--cts') ?? resolve(ctsRoot, 'value-semantics', 'v1', 'value-semantics-cts.v1.json');
12
+ const manifestPath = readArg('--cts') ?? resolve(ctsRoot, 'value-semantics', 'v1', 'value-semantics-cts.v1.next.json');
13
13
 
14
14
  const manifest = readJson(manifestPath);
15
15
  let pass = 0;
package/scripts/query.mjs CHANGED
@@ -479,8 +479,10 @@ function renderAeonValue(value, metadata, fieldMetadata) {
479
479
  if (value === null) return 'null';
480
480
  if (metadata?.kind === 'hex') return `#${value}`;
481
481
  if (metadata?.kind === 'radix') return `%${value}`;
482
+ if (metadata?.kind === 'number') return metadata.numericLexeme ?? String(value);
482
483
  if (metadata?.kind === 'encoding') return `&${value}`;
483
484
  if (metadata?.kind === 'separator') return `^${value}`;
485
+ if (metadata?.kind === 'symbol') return renderSymbolLiteral(value);
484
486
  if (['date', 'time', 'datetime', 'wtc'].includes(metadata?.kind)) return String(value);
485
487
  if (metadata?.kind === 'sansaAddress' || metadata?.kind === 'sansa') {
486
488
  return value?.canonical ?? value?.address?.canonical ?? value?.address ?? String(value);
@@ -504,6 +506,9 @@ function scalarMetadataFromBinding(binding) {
504
506
  const kind = binding.scalarKind ?? binding.valueKind ?? binding.literalKind ?? binding.representationKind ?? binding.kind ?? binding.type;
505
507
  if (typeof kind === 'string') metadata.kind = lowerFirst(kind);
506
508
  if (binding.nullReason !== undefined) metadata.nullReason = binding.nullReason;
509
+ if (binding.numericLexeme !== undefined) metadata.numericLexeme = binding.numericLexeme;
510
+ if (binding.radixBase !== undefined) metadata.radixBase = binding.radixBase;
511
+ if (binding.radixScale !== undefined) metadata.radixScale = binding.radixScale;
507
512
  return Object.keys(metadata).length > 0 ? metadata : undefined;
508
513
  }
509
514
 
@@ -511,6 +516,18 @@ function lowerFirst(value) {
511
516
  return value ? value[0].toLowerCase() + value.slice(1) : value;
512
517
  }
513
518
 
519
+ function renderSymbolLiteral(value) {
520
+ const text = String(value ?? '')
521
+ .replace(/\\/g, '\\\\')
522
+ .replace(/\|/g, '\\|')
523
+ .replace(/\n/g, '\\n')
524
+ .replace(/\r/g, '\\r')
525
+ .replace(/\t/g, '\\t')
526
+ .replace(/\u0008/g, '\\b')
527
+ .replace(/\f/g, '\\f');
528
+ return `|${text}|`;
529
+ }
530
+
514
531
  function summarizeQueryValue(value) {
515
532
  switch (value.type) {
516
533
  case 'bindingSet':
@@ -23,6 +23,7 @@ const repositoryRoot = path.resolve(
23
23
  const expectedPackageName = '@altopelago/sansa';
24
24
  const packagePath = path.join(repositoryRoot, 'package.json');
25
25
  const capabilitiesPath = path.join(repositoryRoot, 'docs', 'capabilities.json');
26
+ const cargoManifestPath = path.join(repositoryRoot, 'implementations', 'rust', 'Cargo.toml');
26
27
  const changelogPath = path.join(repositoryRoot, 'CHANGELOG.md');
27
28
  const transactionPath = path.join(repositoryRoot, '.sansa-version-transaction');
28
29
  const journalPath = path.join(transactionPath, 'journal.json');
@@ -45,6 +46,13 @@ const transactionTargets = [
45
46
  backup: path.join(transactionPath, 'capabilities.backup'),
46
47
  restore: path.join(transactionPath, 'capabilities.restore'),
47
48
  },
49
+ {
50
+ label: 'implementations/rust/Cargo.toml',
51
+ path: cargoManifestPath,
52
+ next: path.join(transactionPath, 'cargo.next'),
53
+ backup: path.join(transactionPath, 'cargo.backup'),
54
+ restore: path.join(transactionPath, 'cargo.restore'),
55
+ },
48
56
  ];
49
57
 
50
58
  function fail(message) {
@@ -294,6 +302,30 @@ async function jsonWithReplacedVersion(file, label, currentVersion, nextVersion)
294
302
  );
295
303
  }
296
304
 
305
+ function cargoVersionFromSource(source) {
306
+ const matches = [...source.matchAll(/^version\s*=\s*"([^"]+)"\s*$/gm)];
307
+ if (matches.length !== 1) {
308
+ throw new Error(
309
+ 'implementations/rust/Cargo.toml must contain exactly one workspace package version',
310
+ );
311
+ }
312
+ return matches[0][1];
313
+ }
314
+
315
+ async function cargoWithReplacedVersion(currentVersion, nextVersion) {
316
+ const source = await readFile(cargoManifestPath, 'utf8');
317
+ const actualVersion = cargoVersionFromSource(source);
318
+ if (actualVersion !== currentVersion) {
319
+ throw new Error(
320
+ `implementations/rust/Cargo.toml version ${JSON.stringify(actualVersion)} does not match package version ${JSON.stringify(currentVersion)}`,
321
+ );
322
+ }
323
+ return source.replace(
324
+ new RegExp(`^(version\\s*=\\s*)"${escapeRegExp(currentVersion)}"[ \\t]*$`, 'm'),
325
+ `$1${JSON.stringify(nextVersion)}`,
326
+ );
327
+ }
328
+
297
329
  function releaseHeadingProblem(changelog, version) {
298
330
  const releaseHeading = new RegExp(
299
331
  `^## ${escapeRegExp(version)} - \\d{4}-\\d{2}-\\d{2}$`,
@@ -305,7 +337,7 @@ function releaseHeadingProblem(changelog, version) {
305
337
  : `CHANGELOG.md must have exactly one dated release heading for ${version}`;
306
338
  }
307
339
 
308
- function metadataProblems(packageManifest, capabilities, changelog = null) {
340
+ function metadataProblems(packageManifest, capabilities, cargoVersion, changelog = null) {
309
341
  const problems = [];
310
342
  const version = packageManifest.version;
311
343
  if (packageManifest.name !== expectedPackageName) {
@@ -324,6 +356,11 @@ function metadataProblems(packageManifest, capabilities, changelog = null) {
324
356
  `docs/capabilities.json version ${JSON.stringify(capabilities.version)} does not match package version ${JSON.stringify(version)}`,
325
357
  );
326
358
  }
359
+ if (cargoVersion !== version) {
360
+ problems.push(
361
+ `implementations/rust/Cargo.toml version ${JSON.stringify(cargoVersion)} does not match package version ${JSON.stringify(version)}`,
362
+ );
363
+ }
327
364
  if (changelog !== null && typeof version === 'string') {
328
365
  const problem = releaseHeadingProblem(changelog, version);
329
366
  if (problem !== null) problems.push(problem);
@@ -332,14 +369,21 @@ function metadataProblems(packageManifest, capabilities, changelog = null) {
332
369
  }
333
370
 
334
371
  async function loadMetadata({ includeChangelog }) {
335
- const [packageManifest, capabilities, changelog] = await Promise.all([
372
+ const [packageManifest, capabilities, cargoManifest, changelog] = await Promise.all([
336
373
  readJson(packagePath, 'package.json'),
337
374
  readJson(capabilitiesPath, 'docs/capabilities.json'),
375
+ assertRegularFile(cargoManifestPath, 'implementations/rust/Cargo.toml')
376
+ .then(() => readFile(cargoManifestPath, 'utf8')),
338
377
  includeChangelog
339
378
  ? assertRegularFile(changelogPath, 'CHANGELOG.md').then(() => readFile(changelogPath, 'utf8'))
340
379
  : Promise.resolve(null),
341
380
  ]);
342
- return { packageManifest, capabilities, changelog };
381
+ return {
382
+ packageManifest,
383
+ capabilities,
384
+ cargoVersion: cargoVersionFromSource(cargoManifest),
385
+ changelog,
386
+ };
343
387
  }
344
388
 
345
389
  async function checkVersion() {
@@ -348,6 +392,7 @@ async function checkVersion() {
348
392
  const problems = metadataProblems(
349
393
  metadata.packageManifest,
350
394
  metadata.capabilities,
395
+ metadata.cargoVersion,
351
396
  metadata.changelog,
352
397
  );
353
398
  await Promise.all([
@@ -363,6 +408,10 @@ async function checkVersion() {
363
408
  metadata.capabilities.version,
364
409
  metadata.capabilities.version,
365
410
  ),
411
+ cargoWithReplacedVersion(
412
+ metadata.packageManifest.version,
413
+ metadata.packageManifest.version,
414
+ ),
366
415
  ]).catch((error) => problems.push(errorMessage(error)));
367
416
  if (problems.length > 0) throw new Error(problems.join('; '));
368
417
  console.log(
@@ -421,6 +470,7 @@ async function setVersion(version) {
421
470
  const problems = metadataProblems(
422
471
  metadata.packageManifest,
423
472
  metadata.capabilities,
473
+ metadata.cargoVersion,
424
474
  metadata.changelog,
425
475
  );
426
476
  if (problems.length > 0) {
@@ -449,6 +499,7 @@ async function setVersion(version) {
449
499
  metadata.capabilities.version,
450
500
  version,
451
501
  ),
502
+ cargoWithReplacedVersion(metadata.packageManifest.version, version),
452
503
  ]);
453
504
  await writeVersionTransaction(updates);
454
505
  console.log(`Set ${expectedPackageName} release metadata to ${version}.`);
package/src/index.d.ts CHANGED
@@ -47,6 +47,7 @@ export type SansaParseErrorCode =
47
47
  | 'SANSA_QUERY_INVALID_RADIX_LITERAL'
48
48
  | 'SANSA_QUERY_INVALID_ENCODING_LITERAL'
49
49
  | 'SANSA_QUERY_INVALID_SEPARATOR_LITERAL'
50
+ | 'SANSA_QUERY_INVALID_SYMBOL_LITERAL'
50
51
  | 'SANSA_QUERY_INVALID_NULL_LITERAL'
51
52
  | 'SANSA_QUERY_INVALID_TEMPORAL_LITERAL'
52
53
  | 'SANSA_QUERY_INVALID_RESOLUTION_EXPRESSION'
@@ -278,6 +279,12 @@ export interface SansaResolveBinding {
278
279
  readonly valueKind?: string;
279
280
  readonly literalKind?: string;
280
281
  readonly nullReason?: string;
282
+ /** Canonical finite AEON numeric text used for lossless comparison. */
283
+ readonly numericLexeme?: string;
284
+ /** Resolved base for an AEON radix-family value. */
285
+ readonly radixBase?: number;
286
+ /** Count of represented fractional radix digits, excluding visual separators. */
287
+ readonly radixScale?: number;
281
288
  readonly value?: unknown;
282
289
  readonly scalar?: unknown;
283
290
  readonly origin?: string;
@@ -311,7 +318,7 @@ export interface SansaResolveNamespace<TBinding extends object = SansaResolveBin
311
318
  readonly root: TBinding | (() => TBinding | undefined);
312
319
  readonly contextualRoot?: TBinding;
313
320
  readonly children?: (binding: TBinding) => Iterable<TBinding> | readonly TBinding[] | undefined;
314
- readonly parent?: (binding: TBinding) => TBinding | undefined;
321
+ readonly parent?: (binding: TBinding) => TBinding | null | undefined;
315
322
  readonly member?: (binding: TBinding, name: string) => TBinding | undefined;
316
323
  readonly position?: (binding: TBinding, index: number) => TBinding | undefined;
317
324
  readonly attributeSpace?: (binding: TBinding) => TBinding | undefined;
@@ -322,14 +329,35 @@ export interface SansaResolveNamespace<TBinding extends object = SansaResolveBin
322
329
  readonly representationKind?: (binding: TBinding) => string | undefined;
323
330
  readonly value?: (binding: TBinding) => unknown;
324
331
  readonly nullReason?: (binding: TBinding) => string | undefined;
332
+ /** Return canonical finite numeric text without host-number coercion. */
333
+ readonly numericLexeme?: (binding: TBinding) => string | undefined;
334
+ /** Return the resolved base for a radix-family binding. */
335
+ readonly radixBase?: (binding: TBinding) => number | undefined;
336
+ /** Return the represented fractional radix digit count. */
337
+ readonly radixScale?: (binding: TBinding) => number | undefined;
325
338
  readonly semanticTypeMatches?: (binding: TBinding, expected: string) => boolean;
326
339
  readonly representationKindMatches?: (binding: TBinding, expected: string) => boolean;
340
+ /**
341
+ * Optionally compare two same-kind container bindings without materializing them.
342
+ * The result must implement the active value-semantics profile. Return
343
+ * undefined to decline and use SANSA's generic structural comparison.
344
+ */
345
+ readonly structurallyEqual?: (
346
+ left: TBinding,
347
+ right: TBinding,
348
+ context: SansaStructuralEqualityContext,
349
+ ) => boolean | undefined;
327
350
  readonly bindingHandle?: (binding: TBinding) => unknown;
328
351
  readonly observedState?: (binding: TBinding) => unknown;
329
352
  readonly namespaceState?: (() => unknown) | unknown;
330
353
  readonly mutate?: SansaMutationAdapter<TBinding>;
331
354
  }
332
355
 
356
+ export interface SansaStructuralEqualityContext {
357
+ readonly operator: '==' | '!=';
358
+ readonly valueSemantics: AeonValueSemanticsProfile;
359
+ }
360
+
333
361
  export interface SansaGraphRelationshipDeclaration {
334
362
  readonly id: string;
335
363
  readonly direction: 'directed';
@@ -912,7 +940,13 @@ export interface SansaQueryObjectValue {
912
940
  readonly value: Record<string, unknown>;
913
941
  }
914
942
 
915
- export type AeonValueSemanticsOperation = 'equal' | 'notEqual' | 'compare' | 'isValue';
943
+ export type AeonValueSemanticsOperation =
944
+ | 'equal'
945
+ | 'notEqual'
946
+ | 'compare'
947
+ | 'isValue'
948
+ | 'radixScale'
949
+ | 'temporalRelation';
916
950
 
917
951
  export type AeonValueSemanticsCategory =
918
952
  | 'finiteNumber'
@@ -926,6 +960,7 @@ export type AeonValueSemanticsCategory =
926
960
  | 'radix'
927
961
  | 'encoding'
928
962
  | 'separator'
963
+ | 'symbol'
929
964
  | 'sansaAddress'
930
965
  | 'referenceForm'
931
966
  | 'temporal'
@@ -942,8 +977,10 @@ export interface AeonValueSemanticsProfile {
942
977
  readonly stringOrder?: string;
943
978
  readonly temporalOrder?: string;
944
979
  readonly caseMapping?: string;
980
+ readonly radixComparison?: string;
945
981
  readonly compareStrings: (left: string, right: string) => number;
946
982
  readonly compareTemporal: (left: AeonTemporalSemanticValue, right: AeonTemporalSemanticValue) => number;
983
+ readonly compareRadix?: (left: AeonRadixSemanticValue, right: AeonRadixSemanticValue) => number | null;
947
984
  readonly lowerString: (value: string) => string;
948
985
  readonly upperString: (value: string) => string;
949
986
  }
@@ -953,6 +990,21 @@ export interface AeonTemporalSemanticValue {
953
990
  readonly semanticType?: string;
954
991
  }
955
992
 
993
+ export type AeonTemporalClaimRelation =
994
+ | 'equal'
995
+ | 'before'
996
+ | 'after'
997
+ | 'contains'
998
+ | 'containedBy'
999
+ | 'overlaps'
1000
+ | 'incomparable';
1001
+
1002
+ export interface AeonRadixSemanticValue {
1003
+ readonly payload: string;
1004
+ readonly base: number;
1005
+ readonly semanticType?: string;
1006
+ }
1007
+
956
1008
  export interface AeonValueSemanticsProfileOptions {
957
1009
  readonly id?: string;
958
1010
  readonly locale?: string | readonly string[];
@@ -962,6 +1014,7 @@ export interface AeonValueSemanticsProfileOptions {
962
1014
  readonly numeric?: boolean;
963
1015
  readonly caseFirst?: 'upper' | 'lower' | 'false';
964
1016
  readonly compareTemporal?: (left: AeonTemporalSemanticValue, right: AeonTemporalSemanticValue) => number;
1017
+ readonly compareRadix?: (left: AeonRadixSemanticValue, right: AeonRadixSemanticValue) => number | null;
965
1018
  }
966
1019
 
967
1020
  export type AeonValueSemanticsProfileInput =
@@ -976,6 +1029,8 @@ export interface AeonValueSemanticsValueDescriptor {
976
1029
  readonly value?: unknown;
977
1030
  readonly reason?: string;
978
1031
  readonly semanticType?: string;
1032
+ readonly radixBase?: number;
1033
+ readonly radixScale?: number;
979
1034
  readonly containerKind?: string;
980
1035
  readonly count?: number;
981
1036
  }
@@ -1001,8 +1056,8 @@ export type AeonValueSemanticsResult =
1001
1056
  | {
1002
1057
  readonly ok: true;
1003
1058
  readonly outcome: 'value';
1004
- readonly value?: boolean;
1005
- readonly relation?: 'less' | 'equal' | 'greater';
1059
+ readonly value?: boolean | number;
1060
+ readonly relation?: 'less' | 'equal' | 'greater' | AeonTemporalClaimRelation;
1006
1061
  }
1007
1062
  | {
1008
1063
  readonly ok: false;
@@ -1027,6 +1082,25 @@ export function createFrenchValueSemanticsProfile(
1027
1082
  options?: Omit<AeonValueSemanticsProfileOptions, 'locale'> & { readonly locale?: 'fr' | 'fr-FR' },
1028
1083
  ): AeonValueSemanticsProfile;
1029
1084
  export function createNaturalAsciiValueSemanticsProfile(options?: Omit<AeonValueSemanticsProfileOptions, 'locale'>): AeonValueSemanticsProfile;
1085
+ export function createRadixNumericValueSemanticsProfile(
1086
+ options?: { readonly id?: string },
1087
+ ): AeonValueSemanticsProfile;
1088
+ export function createCrossBaseRadixNumericValueSemanticsProfile(
1089
+ options?: { readonly id?: string },
1090
+ ): AeonValueSemanticsProfile;
1091
+ export function compareExactRadixValues(left: string, right: string, base: number): -1 | 0 | 1 | null;
1092
+ export function compareExactCrossBaseRadixValues(
1093
+ left: string,
1094
+ leftBase: number,
1095
+ right: string,
1096
+ rightBase: number,
1097
+ ): -1 | 0 | 1 | null;
1098
+ export function compareTemporalClaims(
1099
+ left: AeonTemporalSemanticValue,
1100
+ right: AeonTemporalSemanticValue,
1101
+ ): AeonTemporalClaimRelation;
1102
+ /** Return represented fractional radix digits, excluding `_`, or `null` for an invalid payload. */
1103
+ export function radixScaleOf(value: string, base?: number): number | null;
1030
1104
 
1031
1105
  export interface SansaAddress {
1032
1106
  readonly type: 'SansaAddress';
@@ -1112,6 +1186,7 @@ export interface SansaQueryLiteralExpression {
1112
1186
  | 'radix'
1113
1187
  | 'encoding'
1114
1188
  | 'separator'
1189
+ | 'symbol'
1115
1190
  | 'date'
1116
1191
  | 'time'
1117
1192
  | 'datetime'