@altopelago/aeos-core 0.9.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/README.md +143 -0
- package/dist/bin/aeos-validator.d.ts +16 -0
- package/dist/bin/aeos-validator.d.ts.map +1 -0
- package/dist/bin/aeos-validator.js +77 -0
- package/dist/bin/aeos-validator.js.map +1 -0
- package/dist/diag/codes.d.ts +55 -0
- package/dist/diag/codes.d.ts.map +1 -0
- package/dist/diag/codes.js +69 -0
- package/dist/diag/codes.js.map +1 -0
- package/dist/diag/emit.d.ts +34 -0
- package/dist/diag/emit.d.ts.map +1 -0
- package/dist/diag/emit.js +45 -0
- package/dist/diag/emit.js.map +1 -0
- package/dist/diag/index.d.ts +6 -0
- package/dist/diag/index.d.ts.map +1 -0
- package/dist/diag/index.js +6 -0
- package/dist/diag/index.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/rules/index.d.ts +10 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +10 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/numericForm.d.ts +29 -0
- package/dist/rules/numericForm.d.ts.map +1 -0
- package/dist/rules/numericForm.js +74 -0
- package/dist/rules/numericForm.js.map +1 -0
- package/dist/rules/presence.d.ts +20 -0
- package/dist/rules/presence.d.ts.map +1 -0
- package/dist/rules/presence.js +29 -0
- package/dist/rules/presence.js.map +1 -0
- package/dist/rules/referenceForm.d.ts +17 -0
- package/dist/rules/referenceForm.d.ts.map +1 -0
- package/dist/rules/referenceForm.js +78 -0
- package/dist/rules/referenceForm.js.map +1 -0
- package/dist/rules/schemaIndex.d.ts +34 -0
- package/dist/rules/schemaIndex.d.ts.map +1 -0
- package/dist/rules/schemaIndex.js +167 -0
- package/dist/rules/schemaIndex.js.map +1 -0
- package/dist/rules/stringForm.d.ts +48 -0
- package/dist/rules/stringForm.d.ts.map +1 -0
- package/dist/rules/stringForm.js +96 -0
- package/dist/rules/stringForm.js.map +1 -0
- package/dist/rules/typeCheck.d.ts +29 -0
- package/dist/rules/typeCheck.d.ts.map +1 -0
- package/dist/rules/typeCheck.js +99 -0
- package/dist/rules/typeCheck.js.map +1 -0
- package/dist/types/aes.d.ts +14 -0
- package/dist/types/aes.d.ts.map +1 -0
- package/dist/types/aes.js +8 -0
- package/dist/types/aes.js.map +1 -0
- package/dist/types/envelope.d.ts +47 -0
- package/dist/types/envelope.d.ts.map +1 -0
- package/dist/types/envelope.js +29 -0
- package/dist/types/envelope.js.map +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +10 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/schema.d.ts +81 -0
- package/dist/types/schema.d.ts.map +1 -0
- package/dist/types/schema.js +41 -0
- package/dist/types/schema.js.map +1 -0
- package/dist/types/spans.d.ts +28 -0
- package/dist/types/spans.d.ts.map +1 -0
- package/dist/types/spans.js +16 -0
- package/dist/types/spans.js.map +1 -0
- package/dist/util/digits.d.ts +34 -0
- package/dist/util/digits.d.ts.map +1 -0
- package/dist/util/digits.js +66 -0
- package/dist/util/digits.js.map +1 -0
- package/dist/util/index.d.ts +5 -0
- package/dist/util/index.d.ts.map +1 -0
- package/dist/util/index.js +5 -0
- package/dist/util/index.js.map +1 -0
- package/dist/validate.d.ts +46 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +633 -0
- package/dist/validate.js.map +1 -0
- package/package.json +33 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @altopelago/aeos-core - Rules: Type Check
|
|
3
|
+
*
|
|
4
|
+
* Phase 5: Literal kind validation.
|
|
5
|
+
*/
|
|
6
|
+
import type { DiagContext } from '../diag/emit.js';
|
|
7
|
+
import type { Span } from '../types/spans.js';
|
|
8
|
+
import type { RuleIndex } from './schemaIndex.js';
|
|
9
|
+
/**
|
|
10
|
+
* Event value with type and span
|
|
11
|
+
*/
|
|
12
|
+
interface TypedValue {
|
|
13
|
+
type: string;
|
|
14
|
+
raw?: string;
|
|
15
|
+
span: Span;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Check type constraints for events matching schema rules.
|
|
19
|
+
*
|
|
20
|
+
* For each event whose path has a `type` constraint in the schema,
|
|
21
|
+
* verify the value's literal kind matches the constraint.
|
|
22
|
+
*
|
|
23
|
+
* @param ruleIndex - Schema rule index (path → rule)
|
|
24
|
+
* @param events - Map of path → event value info
|
|
25
|
+
* @param ctx - Diagnostic context
|
|
26
|
+
*/
|
|
27
|
+
export declare function checkTypes(ruleIndex: RuleIndex, events: ReadonlyMap<string, TypedValue>, ctx: DiagContext): void;
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=typeCheck.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeCheck.d.ts","sourceRoot":"","sources":["../../src/rules/typeCheck.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAGnD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAuBlD;;GAEG;AACH,UAAU,UAAU;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,IAAI,CAAC;CACd;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACtB,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,EACvC,GAAG,EAAE,WAAW,GACjB,IAAI,CA0CN"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @altopelago/aeos-core - Rules: Type Check
|
|
3
|
+
*
|
|
4
|
+
* Phase 5: Literal kind validation.
|
|
5
|
+
*/
|
|
6
|
+
import { createDiag, emitError } from '../diag/emit.js';
|
|
7
|
+
import { ErrorCodes } from '../diag/codes.js';
|
|
8
|
+
/**
|
|
9
|
+
* Mapping from AEON parser type to AEOS constraint type.
|
|
10
|
+
*
|
|
11
|
+
* The parser emits "NumberLiteral" for all numeric literals.
|
|
12
|
+
* AEOS schema uses "IntegerLiteral" / "FloatLiteral" for specificity.
|
|
13
|
+
* We refine those using the literal's raw lexical form.
|
|
14
|
+
*/
|
|
15
|
+
const TYPE_ALIASES = {
|
|
16
|
+
// Parser type → Constraint types it satisfies
|
|
17
|
+
'NumberLiteral': ['NumberLiteral'],
|
|
18
|
+
'StringLiteral': ['StringLiteral'],
|
|
19
|
+
'BooleanLiteral': ['BooleanLiteral'],
|
|
20
|
+
'NullLiteral': ['NullLiteral'],
|
|
21
|
+
'ObjectNode': ['ObjectNode'],
|
|
22
|
+
'ListNode': ['ListNode'],
|
|
23
|
+
'ListLiteral': ['ListNode', 'ListLiteral'],
|
|
24
|
+
'TupleLiteral': ['TupleLiteral'],
|
|
25
|
+
'CloneReference': ['CloneReference'],
|
|
26
|
+
'PointerReference': ['PointerReference'],
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Check type constraints for events matching schema rules.
|
|
30
|
+
*
|
|
31
|
+
* For each event whose path has a `type` constraint in the schema,
|
|
32
|
+
* verify the value's literal kind matches the constraint.
|
|
33
|
+
*
|
|
34
|
+
* @param ruleIndex - Schema rule index (path → rule)
|
|
35
|
+
* @param events - Map of path → event value info
|
|
36
|
+
* @param ctx - Diagnostic context
|
|
37
|
+
*/
|
|
38
|
+
export function checkTypes(ruleIndex, events, ctx) {
|
|
39
|
+
for (const [path, rule] of ruleIndex) {
|
|
40
|
+
const expectedType = rule.constraints.type;
|
|
41
|
+
const expectedContainer = rule.constraints.type_is;
|
|
42
|
+
if (expectedType === undefined && expectedContainer === undefined)
|
|
43
|
+
continue;
|
|
44
|
+
const event = events.get(path);
|
|
45
|
+
if (!event)
|
|
46
|
+
continue; // Missing path handled by presence check
|
|
47
|
+
const actualType = event.type;
|
|
48
|
+
if (expectedContainer !== undefined) {
|
|
49
|
+
const containerOk = expectedContainer === 'list'
|
|
50
|
+
? (actualType === 'ListLiteral' || actualType === 'ListNode')
|
|
51
|
+
: actualType === 'TupleLiteral';
|
|
52
|
+
if (!containerOk) {
|
|
53
|
+
emitError(ctx, createDiag(path, event.span, `Container kind mismatch: expected ${expectedContainer}, got ${actualType}`, ErrorCodes.WRONG_CONTAINER_KIND));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (expectedType === undefined)
|
|
57
|
+
continue;
|
|
58
|
+
// Check if actual type satisfies expected type
|
|
59
|
+
if (!typeMatches(actualType, expectedType, event.raw)) {
|
|
60
|
+
const parentPath = path.replace(/\[\d+\]$/, '');
|
|
61
|
+
const parentType = parentPath !== path ? events.get(parentPath)?.type : undefined;
|
|
62
|
+
emitError(ctx, createDiag(path, event.span, `Type mismatch: expected ${expectedType}, got ${actualType}`, /\[\d+\]$/.test(path) && parentType === 'TupleLiteral'
|
|
63
|
+
? ErrorCodes.TUPLE_ELEMENT_TYPE_MISMATCH
|
|
64
|
+
: ErrorCodes.TYPE_MISMATCH));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Check if an actual type satisfies an expected type constraint.
|
|
70
|
+
*/
|
|
71
|
+
function typeMatches(actualType, expectedType, raw) {
|
|
72
|
+
// Direct match
|
|
73
|
+
if (actualType === expectedType)
|
|
74
|
+
return true;
|
|
75
|
+
if (actualType === 'NumberLiteral') {
|
|
76
|
+
if (expectedType === 'IntegerLiteral') {
|
|
77
|
+
return isIntegerNumber(raw);
|
|
78
|
+
}
|
|
79
|
+
if (expectedType === 'FloatLiteral') {
|
|
80
|
+
return isFloatNumber(raw);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Check aliases (e.g., NumberLiteral satisfies IntegerLiteral)
|
|
84
|
+
const satisfies = TYPE_ALIASES[actualType];
|
|
85
|
+
if (satisfies && satisfies.includes(expectedType))
|
|
86
|
+
return true;
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
function isIntegerNumber(raw) {
|
|
90
|
+
if (typeof raw !== 'string')
|
|
91
|
+
return false;
|
|
92
|
+
return /^[+-]?\d[\d_]*$/.test(raw);
|
|
93
|
+
}
|
|
94
|
+
function isFloatNumber(raw) {
|
|
95
|
+
if (typeof raw !== 'string')
|
|
96
|
+
return false;
|
|
97
|
+
return /^[+-]?(?:\d[\d_]*\.\d[\d_]*|\d[\d_]*\.|\.\d[\d_]*|\d[\d_]*[eE][+-]?\d[\d_]*)$/.test(raw);
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=typeCheck.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeCheck.js","sourceRoot":"","sources":["../../src/rules/typeCheck.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAI9C;;;;;;GAMG;AACH,MAAM,YAAY,GAA6B;IAC3C,8CAA8C;IAC9C,eAAe,EAAE,CAAC,eAAe,CAAC;IAClC,eAAe,EAAE,CAAC,eAAe,CAAC;IAClC,gBAAgB,EAAE,CAAC,gBAAgB,CAAC;IACpC,aAAa,EAAE,CAAC,aAAa,CAAC;IAC9B,YAAY,EAAE,CAAC,YAAY,CAAC;IAC5B,UAAU,EAAE,CAAC,UAAU,CAAC;IACxB,aAAa,EAAE,CAAC,UAAU,EAAE,aAAa,CAAC;IAC1C,cAAc,EAAE,CAAC,cAAc,CAAC;IAChC,gBAAgB,EAAE,CAAC,gBAAgB,CAAC;IACpC,kBAAkB,EAAE,CAAC,kBAAkB,CAAC;CAC3C,CAAC;A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C,IAAI,CAAC,GAAG,CAAC,CAAC;AACrG,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @altopelago/aeos-core - Types: AES
|
|
3
|
+
*
|
|
4
|
+
* Re-exports AES types from @altopelago/aeon-aes.
|
|
5
|
+
* These are type-only imports to maintain zero runtime dependencies.
|
|
6
|
+
*/
|
|
7
|
+
import type { AssignmentEvent } from '@altopelago/aeon-aes';
|
|
8
|
+
import type { Span as AeonSpan } from '@altopelago/aeon-lexer';
|
|
9
|
+
export type { AssignmentEvent, AeonSpan };
|
|
10
|
+
/**
|
|
11
|
+
* Readonly AES array type for validation input
|
|
12
|
+
*/
|
|
13
|
+
export type AES = readonly AssignmentEvent[];
|
|
14
|
+
//# sourceMappingURL=aes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aes.d.ts","sourceRoot":"","sources":["../../src/types/aes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAG/D,YAAY,EAAE,eAAe,EAAE,QAAQ,EAAE,CAAC;AAE1C;;GAEG;AACH,MAAM,MAAM,GAAG,GAAG,SAAS,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aes.js","sourceRoot":"","sources":["../../src/types/aes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @altopelago/aeos-core - Types: Envelope
|
|
3
|
+
*
|
|
4
|
+
* Canonical Result Envelope for AEOS validation.
|
|
5
|
+
* This shape is normative and must match the CTS runner expectations.
|
|
6
|
+
*/
|
|
7
|
+
import type { Span } from './spans.js';
|
|
8
|
+
/**
|
|
9
|
+
* Diagnostic entry (error or warning)
|
|
10
|
+
*/
|
|
11
|
+
export interface Diag {
|
|
12
|
+
/** Canonical path where the issue occurred */
|
|
13
|
+
readonly path: string;
|
|
14
|
+
/** Source span, or null for missing paths */
|
|
15
|
+
readonly span: Span;
|
|
16
|
+
/** Human-readable message (non-normative) */
|
|
17
|
+
readonly message: string;
|
|
18
|
+
/** Phase that produced this diagnostic */
|
|
19
|
+
readonly phase: 'schema_validation';
|
|
20
|
+
/** Error code (standard or vendor:code) */
|
|
21
|
+
readonly code: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Canonical Result Envelope
|
|
25
|
+
*
|
|
26
|
+
* This is the only output shape AEOS produces.
|
|
27
|
+
* The envelope MUST NOT contain the input AES.
|
|
28
|
+
*/
|
|
29
|
+
export interface ResultEnvelope {
|
|
30
|
+
/** true if validation passed with no errors */
|
|
31
|
+
readonly ok: boolean;
|
|
32
|
+
/** All validation errors */
|
|
33
|
+
readonly errors: readonly Diag[];
|
|
34
|
+
/** All validation warnings */
|
|
35
|
+
readonly warnings: readonly Diag[];
|
|
36
|
+
/** Guarantees keyed by path → array of tags */
|
|
37
|
+
readonly guarantees: Readonly<Record<string, readonly string[]>>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Create an empty passing result envelope
|
|
41
|
+
*/
|
|
42
|
+
export declare function createPassingEnvelope(guarantees?: Record<string, readonly string[]>, warnings?: readonly Diag[]): ResultEnvelope;
|
|
43
|
+
/**
|
|
44
|
+
* Create a failing result envelope from errors
|
|
45
|
+
*/
|
|
46
|
+
export declare function createFailingEnvelope(errors: readonly Diag[], warnings?: readonly Diag[], guarantees?: Record<string, readonly string[]>): ResultEnvelope;
|
|
47
|
+
//# sourceMappingURL=envelope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.d.ts","sourceRoot":"","sources":["../../src/types/envelope.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAA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
|
+
* This shape is normative and must match the CTS runner expectations.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Create an empty passing result envelope
|
|
9
|
+
*/
|
|
10
|
+
export function createPassingEnvelope(guarantees = {}, warnings = []) {
|
|
11
|
+
return {
|
|
12
|
+
ok: true,
|
|
13
|
+
errors: [],
|
|
14
|
+
warnings,
|
|
15
|
+
guarantees,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Create a failing result envelope from errors
|
|
20
|
+
*/
|
|
21
|
+
export function createFailingEnvelope(errors, warnings = [], guarantees = {}) {
|
|
22
|
+
return {
|
|
23
|
+
ok: false,
|
|
24
|
+
errors,
|
|
25
|
+
warnings,
|
|
26
|
+
guarantees,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=envelope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"envelope.js","sourceRoot":"","sources":["../../src/types/envelope.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAqCH;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACjC,aAAgD,EAAE,EAClD,WAA4B,EAAE;IAE9B,OAAO;QACH,EAAE,EAAE,IAAI;QACR,MAAM,EAAE,EAAE;QACV,QAAQ;QACR,UAAU;KACb,CAAC;AACN,CAAC;AAGD;;GAEG;AACH,MAAM,UAAU,qBAAqB,CACjC,MAAuB,EACvB,WAA4B,EAAE,EAC9B,aAAgD,EAAE;IAElD,OAAO;QACH,EAAE,EAAE,KAAK;QACT,MAAM;QACN,QAAQ;QACR,UAAU;KACb,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @altopelago/aeos-core - Types: Schema
|
|
3
|
+
*
|
|
4
|
+
* AEOS Constraint Model v1 types.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Known constraint keys for v1
|
|
8
|
+
*/
|
|
9
|
+
export interface AttributeConstraintsV1 extends ConstraintsV1 {
|
|
10
|
+
}
|
|
11
|
+
export interface ConstraintsV1 {
|
|
12
|
+
/** Path must exist in AES */
|
|
13
|
+
readonly required?: boolean;
|
|
14
|
+
/** Expected literal kind (StringLiteral, IntegerLiteral, etc.) */
|
|
15
|
+
readonly type?: string;
|
|
16
|
+
/** Reference form policy for the path */
|
|
17
|
+
readonly reference?: 'allow' | 'forbid' | 'require';
|
|
18
|
+
/** Required reference kind when reference='require' */
|
|
19
|
+
readonly reference_kind?: 'clone' | 'pointer' | 'either';
|
|
20
|
+
/** Regex pattern matched against the canonicalized reference target path */
|
|
21
|
+
readonly reference_target_pattern?: string;
|
|
22
|
+
/** Resolve reference chains before applying form/type constraints on this path */
|
|
23
|
+
readonly resolve_reference_form?: boolean;
|
|
24
|
+
/** Core v1 container kind check: list | tuple */
|
|
25
|
+
readonly type_is?: 'list' | 'tuple';
|
|
26
|
+
/** Core v1 exact container arity constraint */
|
|
27
|
+
readonly length_exact?: number;
|
|
28
|
+
/** For integers: 'signed' or 'unsigned' syntax */
|
|
29
|
+
readonly sign?: 'signed' | 'unsigned';
|
|
30
|
+
/** Minimum ASCII digit count (excludes sign) */
|
|
31
|
+
readonly min_digits?: number;
|
|
32
|
+
/** Maximum ASCII digit count (excludes sign) */
|
|
33
|
+
readonly max_digits?: number;
|
|
34
|
+
/** Minimum integer value (inclusive), encoded as base-10 string for exactness */
|
|
35
|
+
readonly min_value?: string;
|
|
36
|
+
/** Maximum integer value (inclusive), encoded as base-10 string for exactness */
|
|
37
|
+
readonly max_value?: string;
|
|
38
|
+
/** Minimum string length in UTF-16 code units (JavaScript string.length) */
|
|
39
|
+
readonly min_length?: number;
|
|
40
|
+
/** Maximum string length in UTF-16 code units (JavaScript string.length) */
|
|
41
|
+
readonly max_length?: number;
|
|
42
|
+
/** Regex pattern for string matching */
|
|
43
|
+
readonly pattern?: string;
|
|
44
|
+
/** Datatype label (presence check only, no capacity) */
|
|
45
|
+
readonly datatype?: string;
|
|
46
|
+
/** Attribute entry constraints keyed by attribute name */
|
|
47
|
+
readonly attributes?: Readonly<Record<string, AttributeConstraintsV1>>;
|
|
48
|
+
/** Reject unknown attribute keys at this attribute-object level */
|
|
49
|
+
readonly closed_attributes?: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Schema rule for a canonical path
|
|
53
|
+
*/
|
|
54
|
+
export interface SchemaRule {
|
|
55
|
+
/** Canonical path this rule applies to */
|
|
56
|
+
readonly path: string;
|
|
57
|
+
/** Constraints to apply */
|
|
58
|
+
readonly constraints: ConstraintsV1;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* AEOS Schema v1
|
|
62
|
+
*/
|
|
63
|
+
export interface SchemaV1 {
|
|
64
|
+
/** Array of rules */
|
|
65
|
+
readonly rules: readonly SchemaRule[];
|
|
66
|
+
/** Open-world or closed-world validation policy */
|
|
67
|
+
readonly world?: 'open' | 'closed';
|
|
68
|
+
/** Optional schema-wide reference policy */
|
|
69
|
+
readonly reference_policy?: 'allow' | 'forbid';
|
|
70
|
+
/** Optional datatype-wide constraints keyed by datatype base label */
|
|
71
|
+
readonly datatype_rules?: Readonly<Record<string, ConstraintsV1>>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Known constraint keys for validation
|
|
75
|
+
*/
|
|
76
|
+
export declare const KNOWN_CONSTRAINT_KEYS: ReadonlySet<string>;
|
|
77
|
+
/**
|
|
78
|
+
* Check if a constraints object has any unknown keys
|
|
79
|
+
*/
|
|
80
|
+
export declare function hasUnknownConstraintKeys(constraints: Record<string, unknown>): boolean;
|
|
81
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/types/schema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,WAAW,sBAAuB,SAAQ,aAAa;CAAG;AAEhE,MAAM,WAAW,aAAa;IAC1B,6BAA6B;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAE5B,kEAAkE;IAClE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAEvB,yCAAyC;IACzC,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;IAEpD,uDAAuD;IACvD,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,QAAQ,CAAC;IAEzD,4EAA4E;IAC5E,QAAQ,CAAC,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAE3C,kFAAkF;IAClF,QAAQ,CAAC,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAE1C,iDAAiD;IACjD,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAEpC,+CAA+C;IAC/C,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAE/B,kDAAkD;IAClD,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAC;IAEtC,gDAAgD;IAChD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAE7B,gDAAgD;IAChD,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM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wBAAgB,wBAAwB,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAOtF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @altopelago/aeos-core - Types: Schema
|
|
3
|
+
*
|
|
4
|
+
* AEOS Constraint Model v1 types.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Known constraint keys for validation
|
|
8
|
+
*/
|
|
9
|
+
export const KNOWN_CONSTRAINT_KEYS = new Set([
|
|
10
|
+
'required',
|
|
11
|
+
'type',
|
|
12
|
+
'reference',
|
|
13
|
+
'reference_kind',
|
|
14
|
+
'reference_target_pattern',
|
|
15
|
+
'resolve_reference_form',
|
|
16
|
+
'type_is',
|
|
17
|
+
'length_exact',
|
|
18
|
+
'sign',
|
|
19
|
+
'min_digits',
|
|
20
|
+
'max_digits',
|
|
21
|
+
'min_value',
|
|
22
|
+
'max_value',
|
|
23
|
+
'min_length',
|
|
24
|
+
'max_length',
|
|
25
|
+
'pattern',
|
|
26
|
+
'datatype',
|
|
27
|
+
'attributes',
|
|
28
|
+
'closed_attributes',
|
|
29
|
+
]);
|
|
30
|
+
/**
|
|
31
|
+
* Check if a constraints object has any unknown keys
|
|
32
|
+
*/
|
|
33
|
+
export function hasUnknownConstraintKeys(constraints) {
|
|
34
|
+
for (const key of Object.keys(constraints)) {
|
|
35
|
+
if (!KNOWN_CONSTRAINT_KEYS.has(key)) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/types/schema.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA8FH;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAwB,IAAI,GAAG,CAAC;IAC9D,UAAU;IACV,MAAM;IACN,WAAW;IACX,gBAAgB;IAChB,0BAA0B;IAC1B,wBAAwB;IACxB,SAAS;IACT,cAAc;IACd,MAAM;IACN,YAAY;IACZ,YAAY;IACZ,WAAW;IACX,WAAW;IACX,YAAY;IACZ,YAAY;IACZ,SAAS;IACT,UAAU;IACV,YAAY;IACZ,mBAAmB;CACtB,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,WAAoC;IACzE,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;QACzC,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAClC,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @altopelago/aeos-core - Types: Span
|
|
3
|
+
*
|
|
4
|
+
* Span representation for AEOS diagnostics.
|
|
5
|
+
* This is a simplified tuple format for CTS compatibility.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Span as a tuple: [start_offset, end_offset] or null for missing paths.
|
|
9
|
+
*
|
|
10
|
+
* This is the CTS-compatible format. For full position info,
|
|
11
|
+
* the original AEON Span from @altopelago/aeon-aes can be converted.
|
|
12
|
+
*/
|
|
13
|
+
export type Span = [number, number] | null;
|
|
14
|
+
/**
|
|
15
|
+
* Convert an AEON Span to AEOS tuple format.
|
|
16
|
+
*
|
|
17
|
+
* @param span - AEON Span with start/end Position objects
|
|
18
|
+
* @returns Tuple [start_offset, end_offset]
|
|
19
|
+
*/
|
|
20
|
+
export declare function spanToTuple(span: {
|
|
21
|
+
start: {
|
|
22
|
+
offset: number;
|
|
23
|
+
};
|
|
24
|
+
end: {
|
|
25
|
+
offset: number;
|
|
26
|
+
};
|
|
27
|
+
}): [number, number];
|
|
28
|
+
//# sourceMappingURL=spans.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spans.d.ts","sourceRoot":"","sources":["../../src/types/spans.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;AAE3C;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE;IAAE,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAAC,GAAG,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAE1G"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @altopelago/aeos-core - Types: Span
|
|
3
|
+
*
|
|
4
|
+
* Span representation for AEOS diagnostics.
|
|
5
|
+
* This is a simplified tuple format for CTS compatibility.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Convert an AEON Span to AEOS tuple format.
|
|
9
|
+
*
|
|
10
|
+
* @param span - AEON Span with start/end Position objects
|
|
11
|
+
* @returns Tuple [start_offset, end_offset]
|
|
12
|
+
*/
|
|
13
|
+
export function spanToTuple(span) {
|
|
14
|
+
return [span.start.offset, span.end.offset];
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=spans.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spans.js","sourceRoot":"","sources":["../../src/types/spans.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,IAA4D;IACpF,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AAChD,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @altopelago/aeos-core - Util: Digits
|
|
3
|
+
*
|
|
4
|
+
* Helpers for counting ASCII digits in numeric literals.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Count ASCII digits in a numeric literal (excludes sign, decimal point, exponent).
|
|
8
|
+
*
|
|
9
|
+
* Examples:
|
|
10
|
+
* - "123" → 3
|
|
11
|
+
* - "-456" → 3
|
|
12
|
+
* - "+789" → 3
|
|
13
|
+
* - "1.5" → 2 (digits before and after decimal)
|
|
14
|
+
* - "1e10" → 3 (1 + 10)
|
|
15
|
+
*
|
|
16
|
+
* For v1, we count only the integer part (before decimal point) for integer constraints.
|
|
17
|
+
*/
|
|
18
|
+
export declare function countDigits(raw: string): number;
|
|
19
|
+
/**
|
|
20
|
+
* Count integer part digits only (before any decimal point).
|
|
21
|
+
*
|
|
22
|
+
* For integer literals, this is the total digit count (excluding sign).
|
|
23
|
+
* For float literals, this counts digits before the '.'.
|
|
24
|
+
*/
|
|
25
|
+
export declare function countIntegerDigits(raw: string): number;
|
|
26
|
+
/**
|
|
27
|
+
* Check if a numeric literal is signed (has leading - or +).
|
|
28
|
+
*/
|
|
29
|
+
export declare function isSigned(raw: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Check if a numeric literal is negative (has leading -).
|
|
32
|
+
*/
|
|
33
|
+
export declare function isNegative(raw: string): boolean;
|
|
34
|
+
//# sourceMappingURL=digits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"digits.d.ts","sourceRoot":"","sources":["../../src/util/digits.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAQ/C;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CA+BtD;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE7C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAE/C"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @altopelago/aeos-core - Util: Digits
|
|
3
|
+
*
|
|
4
|
+
* Helpers for counting ASCII digits in numeric literals.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Count ASCII digits in a numeric literal (excludes sign, decimal point, exponent).
|
|
8
|
+
*
|
|
9
|
+
* Examples:
|
|
10
|
+
* - "123" → 3
|
|
11
|
+
* - "-456" → 3
|
|
12
|
+
* - "+789" → 3
|
|
13
|
+
* - "1.5" → 2 (digits before and after decimal)
|
|
14
|
+
* - "1e10" → 3 (1 + 10)
|
|
15
|
+
*
|
|
16
|
+
* For v1, we count only the integer part (before decimal point) for integer constraints.
|
|
17
|
+
*/
|
|
18
|
+
export function countDigits(raw) {
|
|
19
|
+
let count = 0;
|
|
20
|
+
for (const char of raw) {
|
|
21
|
+
if (char >= '0' && char <= '9') {
|
|
22
|
+
count++;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return count;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Count integer part digits only (before any decimal point).
|
|
29
|
+
*
|
|
30
|
+
* For integer literals, this is the total digit count (excluding sign).
|
|
31
|
+
* For float literals, this counts digits before the '.'.
|
|
32
|
+
*/
|
|
33
|
+
export function countIntegerDigits(raw) {
|
|
34
|
+
// Remove leading sign
|
|
35
|
+
let s = raw;
|
|
36
|
+
if (s.startsWith('+') || s.startsWith('-')) {
|
|
37
|
+
s = s.slice(1);
|
|
38
|
+
}
|
|
39
|
+
// Find decimal point or exponent
|
|
40
|
+
const decimalIndex = s.indexOf('.');
|
|
41
|
+
const expIndex = Math.min(s.indexOf('e') !== -1 ? s.indexOf('e') : Infinity, s.indexOf('E') !== -1 ? s.indexOf('E') : Infinity);
|
|
42
|
+
// Determine end of integer part
|
|
43
|
+
const endIndex = Math.min(decimalIndex !== -1 ? decimalIndex : Infinity, expIndex !== Infinity ? expIndex : Infinity, s.length);
|
|
44
|
+
// Count digits in integer part
|
|
45
|
+
let count = 0;
|
|
46
|
+
for (let i = 0; i < endIndex; i++) {
|
|
47
|
+
const char = s[i];
|
|
48
|
+
if (char !== undefined && char >= '0' && char <= '9') {
|
|
49
|
+
count++;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return count;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Check if a numeric literal is signed (has leading - or +).
|
|
56
|
+
*/
|
|
57
|
+
export function isSigned(raw) {
|
|
58
|
+
return raw.startsWith('-') || raw.startsWith('+');
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Check if a numeric literal is negative (has leading -).
|
|
62
|
+
*/
|
|
63
|
+
export function isNegative(raw) {
|
|
64
|
+
return raw.startsWith('-');
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=digits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"digits.js","sourceRoot":"","sources":["../../src/util/digits.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CAAC,GAAW;IACnC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,IAAI,IAAI,GAAG,EAAE,CAAC;QACrB,IAAI,IAAI,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG,EAAE,CAAC;YAC7B,KAAK,EAAE,CAAC;QACZ,CAAC;IACL,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAAW;IAC1C,sBAAsB;IACtB,IAAI,CAAC,GAAG,GAAG,CAAC;IACZ,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACzC,CAAC,GAAG,CA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tD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW;IAClC,OAAO,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AAC/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,aAAa,CAAC"}
|