11---
22title : Node SDK
3- description : JavaScript and TypeScript bounded parsing, multi-diagnostics, native ACL generation, canonical digests, and builders in @a3s-lab/acl.
3+ description : JavaScript and TypeScript bounded parsing, schema admission, multi-diagnostics, native ACL generation, canonical digests, and builders in @a3s-lab/acl.
44---
55
66# Node SDK
@@ -47,6 +47,9 @@ const generated = generate(new DocumentBuilder().block(provider).build());
4747| ` collectDiagnostics(input, limits?) ` | Collect bounded diagnostics without constructing a partial AST. |
4848| ` DEFAULT_PARSE_LIMITS ` | Shared immutable defaults for document bytes, nesting, collection items, token bytes, and diagnostic count. |
4949| ` ParseError ` , ` DIAGNOSTIC_CODES ` , ` DiagnosticReport ` | Stable codes, complete spans, UTF-8 byte offsets, redacted messages, and explicit truncation state. |
50+ | ` validateDocument(document, schema, limits?) ` | Validate a parsed ` Document ` against a declarative schema with a bounded report. |
51+ | ` SCHEMA_DIAGNOSTIC_CODES ` , ` SchemaDiagnostic ` , ` SchemaReport ` | Stable schema codes, logical paths, redacted messages, and explicit truncation state. |
52+ | ` Schema ` , ` AttributeSchema ` , ` BlockSchema ` , ` ValueSchema ` | TypeScript definitions for closed-by-default document, block, and recursive value rules. |
5053| ` generate(doc) ` | Generate native ACL text with labels in block headers. |
5154| ` canonicalBytes(doc) ` , ` canonicalDigest(doc) ` | Produce stable cross-SDK bytes and an algorithm-prefixed SHA-256 digest. |
5255| ` CanonicalError ` | Report non-finite numbers, non-scalar strings, and non-portable identifiers without echoing values. |
@@ -99,6 +102,42 @@ Resource-limit diagnostics remain fatal. A report stores at most
99102` maxDiagnostics ` errors and sets ` truncated ` only after observing another error
100103beyond that budget.
101104
105+ ## Schema Admission
106+
107+ Parse untrusted text with explicit limits, then validate the resulting
108+ document before activating it:
109+
110+ ``` typescript
111+ import {parse , validateDocument , type Schema } from ' @a3s-lab/acl' ;
112+
113+ const limits = {maxDiagnostics: 20 };
114+ const document = parse (' version = 1' , limits );
115+ const schema: Schema = {
116+ attributes: {
117+ version: {required: true , value: {kind: ' Number' }},
118+ },
119+ };
120+ const report = validateDocument (document , schema , limits );
121+ ```
122+
123+ Schemas reject undeclared attributes, blocks, and object fields by default.
124+ They can declare required or optional attributes, block occurrence and label
125+ cardinalities, and recursive ` Any ` , ` String ` , ` Number ` , ` Bool ` , ` Null ` , ` List ` ,
126+ ` Object ` , ` Call ` , and ` OneOf ` rules. Extension points require the corresponding
127+ explicit allow flag.
128+
129+ Schema reports use stable ` acl.schema.* ` codes and logical paths such as
130+ ` $.blocks.provider[0].attributes.api_key ` . Messages and paths never include
131+ attribute values, call arguments, or block labels. Reports use
132+ ` maxDiagnostics ` and set ` truncated ` only after observing an additional schema
133+ error beyond that budget.
134+
135+ Malformed or cyclic programmatic documents, invalid cardinality ranges, empty
136+ unions, unknown schema fields, and schema cycles fail with ` TypeError ` before
137+ validation. Schema admission validates document shape; host components still
138+ own numeric ranges, secret resolution, provider credentials, and other product
139+ semantics.
140+
102141## Native And Canonical Output
103142
104143` generate ` has one native ACL output contract. Labels remain in block headers;
@@ -110,6 +149,6 @@ sorting semantically unordered attribute and object keys.
110149
111150## Boundary
112151
113- The SDK is a parser/generator and AST builder. It does not load environment
114- variables, fetch remote configuration, validate provider credentials, or execute
115- functions such as ` env(...) ` .
152+ The SDK parses, generates, builds, and validates declarative ACL document
153+ shapes. It does not load environment variables, fetch remote configuration,
154+ validate provider credentials, or execute functions such as ` env(...) ` .
0 commit comments