@tinyactors/sxml 0.0.0-stage → 0.3.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.
@@ -0,0 +1,679 @@
1
+ import { type ChunkSource, type OutputSink } from './stream.ts';
2
+ export { type ChunkSource, type NodeWritable, nodeStreamSink, type OutputSink, type OutputSinkObject, outputReadableStream, textSink, writableStreamSink, } from './stream.ts';
3
+ /** Where load() finds sxml.wasm: a URL or path, the bytes, a compiled
4
+ * module, or a fetch Response. */
5
+ export type WasmSource = string | URL | BufferSource | WebAssembly.Module | Response | PromiseLike<Response>;
6
+ export interface LoadOptions {
7
+ /** Default: sxml.wasm next to this file, which has every language and
8
+ * every optional feature (Sxml.features). */
9
+ wasm?: WasmSource;
10
+ /** The DUCET for the uca-collation feature (D213), the
11
+ * text of allkeys.txt of the Unicode Collation Algorithm 16.0.0: a URL
12
+ * or path, or the bytes. Default: allkeys.txt next to this file, which
13
+ * the package ships; when that cannot be read, UCA collation URIs use
14
+ * sxml's fallback (and fallback=no is FOCH0002). false: none. A
15
+ * resolver's own answer for 'collation-data' comes first. */
16
+ collationData?: string | URL | BufferSource | false;
17
+ }
18
+ /** What a resolver is asked for (include/sxml/processor.h, "Resource
19
+ * resolver"). */
20
+ export type ResourceKind = 'xml-document' | 'text' | 'binary' | 'collection' | 'uri-collection' | 'xquery-module' | 'xslt-module' | 'xslt-package' | 'schema-document' | 'external-entity'
21
+ /** A file of the IANA Time Zone Database for the
22
+ * timezone-database feature: absoluteUri is 'urn:sxml:timezone-data:'
23
+ * and a zoneinfo path, a zone name ('Europe/Paris', a TZif file) or
24
+ * 'zone1970.tab'. Answer with the file's bytes. */
25
+ | 'timezone-data'
26
+ /** The DUCET for the uca-collation feature: absoluteUri
27
+ * is 'http://www.unicode.org/Public/UCA/16.0.0/allkeys.txt'. Answer
28
+ * with the file's text, or leave it to LoadOptions.collationData. */
29
+ | 'collation-data'
30
+ /** A CLDR file for the localization feature: absoluteUri
31
+ * is 'urn:sxml:locale-data:' and a path below CLDR's common/
32
+ * directory ('main/de.xml', 'rbnf/de.xml',
33
+ * 'supplemental/supplementalData.xml', 'supplemental/ordinals.xml').
34
+ * Answer with the file's bytes; without them dates are English with
35
+ * '[Language: en]'. */
36
+ | 'locale-data';
37
+ export interface ResourceRequest {
38
+ kind: ResourceKind;
39
+ /** The URI as the expression wrote it, such as fn:doc's argument. */
40
+ uriReference: string;
41
+ /** uriReference resolved against the static base URI; '' when that is
42
+ * absent and uriReference is relative. */
43
+ absoluteUri: string;
44
+ }
45
+ /** Answers fn:doc, fn:unparsed-text and the other resource functions: the
46
+ * resource's bytes or text, or null/undefined when it is not available
47
+ * (FODC0002 for fn:doc). Called synchronously, during an evaluation; it
48
+ * must not use the processor. An exception it throws stops the evaluation
49
+ * and is rethrown by the call that started it. An XML document may also
50
+ * be a ChunkSource, read a chunk at a time as it is parsed (D294). */
51
+ export type Resolver = (request: ResourceRequest) => string | Uint8Array | ChunkSource | null | undefined;
52
+ export interface ProcessorOptions {
53
+ /** Default: nothing is available. */
54
+ resolver?: Resolver;
55
+ /** The optional features the processor may use, by name, each one of
56
+ * Sxml.features. Default: every feature of the module. Without a
57
+ * feature, sxml behaves as the specifications say a processor without
58
+ * it does. */
59
+ features?: string[];
60
+ /** tree-sitter languages for tree-sitter:parse beside the built-in ones,
61
+ * loaded with Sxml.loadCodeLanguage; one with a built-in language's
62
+ * name replaces it. Default: none. */
63
+ codeLanguages?: CodeLanguage[];
64
+ /** The size of the chunks an OutputSink receives, in bytes; default
65
+ * 65,536 (D294). */
66
+ outputChunkByteCount?: number;
67
+ /** The most evaluation steps one evaluation may take before it stops
68
+ * with an error (the C processor limit maximum_evaluation_step_count):
69
+ * a whole number up to 2^53; default, and 0, sxml's 100,000,000, a few
70
+ * seconds of work. A streamed document grants 500 steps more for each
71
+ * element it reads, so long streams run within it (D295). */
72
+ maximumEvaluationStepCount?: number;
73
+ /** Which documents keep the line and column of each node, for
74
+ * fn:location and for errors that name a node (the C processor setting
75
+ * source_location_policy; D313, D318): 'automatic', the default, keeps
76
+ * them for a document parsed before any program is compiled and for
77
+ * the documents of a program that can ask (it calls fn:location, can
78
+ * look up functions or validates); 'always'; 'never'. They cost 32
79
+ * bytes a node. */
80
+ locations?: 'automatic' | 'always' | 'never';
81
+ /** For tests: fail this allocation (counted from 1) with out of memory. */
82
+ failingAllocationNumber?: number;
83
+ }
84
+ /** A tree-sitter language file to load (Sxml.loadCodeLanguage). */
85
+ export interface CodeLanguageOptions {
86
+ /** The language file, as `tree-sitter build --wasm` writes it
87
+ * (tree-sitter-NAME.wasm): a URL or path, the bytes, a compiled
88
+ * module, or a fetch Response. */
89
+ wasm: WasmSource;
90
+ /** The language's name in tree-sitter:parse: ASCII letters, digits, '_',
91
+ * '-', '+' and '.'. Default: NAME of the file's tree_sitter_NAME
92
+ * function. */
93
+ name?: string;
94
+ /** The text of the grammar's queries/highlights.scm; default none, so
95
+ * no highlight attributes. */
96
+ highlights?: string;
97
+ /** The text of queries/locals.scm; default none. */
98
+ locals?: string;
99
+ /** The text of queries/injections.scm; default none. */
100
+ injections?: string;
101
+ /** tree-sitter.json's injection-regex, which other languages'
102
+ * injections match to mean this one; default: only its name. */
103
+ injectionRegex?: string;
104
+ }
105
+ /** JSON-like data, converted to XDM as fn:parse-json converts its JSON text
106
+ * (objects are maps, arrays are arrays, numbers xs:double, null the empty
107
+ * sequence); a string is an xs:string. */
108
+ export type JsonData = string | number | boolean | null | JsonData[] | {
109
+ [key: string]: JsonData;
110
+ };
111
+ /** A value to bind: one this processor made, or JSON-like data. */
112
+ export type Input = Value | JsonData;
113
+ export interface StaticOptions {
114
+ /** Namespace bindings, prefix to URI; the prefix '' sets the default
115
+ * element namespace. Added to the predeclared prefixes (xs, fn, map,
116
+ * array, math, err, ...) and to those of the processor's features (bin
117
+ * with expath-binary), which they may rebind. */
118
+ namespaces?: Record<string, string>;
119
+ /** The static base URI, against which fn:doc resolves relative URIs. */
120
+ baseUri?: string;
121
+ }
122
+ export interface CompileOptions extends StaticOptions {
123
+ /** The external variables, as NCNames or Q{uri}local, each item()*. */
124
+ variables?: string[];
125
+ }
126
+ export interface EvaluateOptions {
127
+ /** The context value; absent means no focus (XPDY0002 when used). */
128
+ context?: Input;
129
+ /** Values of the declared variables; a missing one raises XPDY0002. */
130
+ variables?: Record<string, Input>;
131
+ }
132
+ /** The serialization parameters of Serialization 4.0, as fn:serialize
133
+ * takes them: method ('xml', 'html', 'xhtml', 'text', 'json', 'adaptive',
134
+ * 'csv'), indent, omit-xml-declaration, item-separator, ... Keys may be
135
+ * written in camelCase (omitXmlDeclaration); yes/no parameters take
136
+ * booleans. Without options, a value is written by the adaptive method. */
137
+ export type SerializationOptions = Record<string, JsonData>;
138
+ /** Trace output (XSLT 4.0, 23.1 and 23.2; F&O 4.0, fn:trace and
139
+ * fn:message): an xsl:message or failed xsl:assert as the text method
140
+ * writes it, fn:trace and fn:message by the adaptive method. */
141
+ export interface Message {
142
+ text: string;
143
+ /** xsl:message: its error code's local name (XTMM9000 by default);
144
+ * fn:trace and fn:message: the label. */
145
+ code: string;
146
+ /** xsl:message terminate="yes" and xsl:assert: the call then throws. */
147
+ isTerminating: boolean;
148
+ sourceName: string;
149
+ lineNumber: number;
150
+ columnNumber: number;
151
+ }
152
+ export interface QueryCompileOptions extends StaticOptions {
153
+ }
154
+ /** A tree an updating query changed (XQuery Update Facility 3.0,
155
+ * upd:applyUpdates): trees never change in sxml, so the update makes a
156
+ * new tree; putting it where the original was is the host's. */
157
+ export interface UpdatedTree {
158
+ /** The root as the query read it: a document node you bound, or a
159
+ * parentless node. */
160
+ original: Value;
161
+ /** The root of the new tree with every change made. */
162
+ updated: Value;
163
+ }
164
+ /** A document fn:put stores (XQUF 3.0, 6.1): writing it at uri is the
165
+ * host's. */
166
+ export interface PutDocument {
167
+ /** fn:put's $uri resolved against the static base URI. */
168
+ uri: string;
169
+ node: Value;
170
+ /** fn:put's $params, or undefined. */
171
+ parameters: Value | undefined;
172
+ /** The node serialized with parameters (method xml without). */
173
+ serialize(): string;
174
+ /** The same, written to sink a chunk at a time (D294). */
175
+ serializeTo(sink: OutputSink): void;
176
+ }
177
+ /** Receives what an updating query changed, after the evaluation and in
178
+ * the order of each tree's first update; documents fn:put stores come
179
+ * last. Without putDocument, fn:put raises FOUP0002. */
180
+ export interface UpdateSink {
181
+ updatedTree?(tree: UpdatedTree): void;
182
+ putDocument?(document: PutDocument): void;
183
+ }
184
+ export interface QueryEvaluateOptions {
185
+ /** The initial context value; absent means none (XPDY0002 when the
186
+ * query needs it). */
187
+ context?: Input;
188
+ /** The external variables the prolog declares (XQuery 4.0, 5.16), by
189
+ * NCName or Q{uri}local; names it does not declare are ignored, and a
190
+ * declared one without a value takes its default. */
191
+ variables?: Record<string, Input>;
192
+ /** For an updating query: receives the changed trees. Without it, its
193
+ * values are disposed at once. */
194
+ updates?: UpdateSink;
195
+ /** Receives fn:trace and fn:message output, after the evaluation (also
196
+ * when it throws). */
197
+ messages?: (message: Message) => void;
198
+ }
199
+ export interface StylesheetCompileOptions {
200
+ /** The principal module's URI, against which xsl:include, xsl:import
201
+ * and fn:doc resolve. */
202
+ baseUri?: string;
203
+ /** Static parameters (XSLT 4.0, 9.6), by NCName or Q{uri}local. */
204
+ staticParameters?: Record<string, Input>;
205
+ }
206
+ /** How a result reaches you (XSLT 4.0, 2.4.6): 'serialized' as a string,
207
+ * 'raw' as the value the stylesheet made, 'tree' as one document node. */
208
+ export type ResultDelivery = 'serialized' | 'raw' | 'tree';
209
+ export interface TransformOptions {
210
+ /** The global context item (XSLT 4.0, 2.4.2): its document is the
211
+ * default initial match selection. */
212
+ source?: Input;
213
+ /** The initial match selection, when it is not the source. */
214
+ initialMatchSelection?: Input;
215
+ /** The initial mode, by NCName or Q{uri}local; '#unnamed' is the unnamed
216
+ * mode. Default: the stylesheet's default mode. */
217
+ initialMode?: string;
218
+ /** Calls this named template instead of applying templates (2.4.4).
219
+ * Without source and initialMatchSelection, xsl:initial-template is
220
+ * called. */
221
+ initialTemplate?: string;
222
+ /** Calls this stylesheet function with args instead (2.4.5). */
223
+ initialFunction?: string;
224
+ args?: Input[];
225
+ /** The stylesheet parameters. */
226
+ parameters?: Record<string, Input>;
227
+ /** Parameters of the initial template or of the template rules. */
228
+ templateParameters?: Record<string, Input>;
229
+ tunnelParameters?: Record<string, Input>;
230
+ /** Against which relative hrefs of xsl:result-document resolve. */
231
+ baseOutputUri?: string;
232
+ /** The principal result's delivery; default 'serialized', by the
233
+ * stylesheet's unnamed xsl:output. */
234
+ delivery?: ResultDelivery;
235
+ /** The result documents' delivery; default 'serialized'. */
236
+ resultDocumentDelivery?: ResultDelivery;
237
+ /** Serialization parameters replacing the unnamed xsl:output's, as
238
+ * fn:serialize takes them. */
239
+ serialization?: SerializationOptions;
240
+ /** Receives xsl:message and xsl:assert output, after the
241
+ * transformation (also when it throws). */
242
+ messages?: (message: Message) => void;
243
+ /** With delivery 'serialized': receives the principal result a chunk at
244
+ * a time as it is serialized, instead of TransformResult.output (D294). */
245
+ output?: OutputSink;
246
+ /** With resultDocumentDelivery 'serialized': chooses the sink of each
247
+ * result document by its URI, as it begins; undefined gathers it as
248
+ * ResultDocument.output. A document whose transformation fails while it
249
+ * is open is aborted. Documents with a sink are not in
250
+ * TransformResult.resultDocuments. */
251
+ resultDocumentOutput?: (uri: string) => OutputSink | undefined;
252
+ /** The absolute URI of a principal source to stream (XSLT 4.0, 2.4.3;
253
+ * D228): the resolver is asked for it (kind 'xml-document') and may
254
+ * answer with a ChunkSource. When the initial mode is streamable, its
255
+ * nodes are read as they are parsed and never held whole; otherwise it
256
+ * is built first. Applies templates; not with source or
257
+ * initialMatchSelection. */
258
+ streamedSource?: string;
259
+ }
260
+ /** A secondary result: what one xsl:result-document made (26.2). */
261
+ export interface ResultDocument {
262
+ /** Its href resolved against the base output URI. */
263
+ uri: string;
264
+ /** 'serialized': the text. */
265
+ output: string | undefined;
266
+ /** 'raw' and 'tree': the value. */
267
+ value: Value | undefined;
268
+ }
269
+ export interface TransformResult {
270
+ /** The principal result serialized ('serialized'). */
271
+ output: string | undefined;
272
+ /** The principal result as a value ('raw', 'tree'). */
273
+ value: Value | undefined;
274
+ /** In the order they completed. */
275
+ resultDocuments: ResultDocument[];
276
+ }
277
+ /** A schema document: its text, with its URI, or only a URI, which the
278
+ * resolver is asked for (kind 'schema-document'). */
279
+ export interface SchemaDocument {
280
+ text?: string | Uint8Array;
281
+ uri?: string;
282
+ }
283
+ export interface SchemaCompileOptions {
284
+ /** Against which relative URIs of documents given by URI resolve. */
285
+ baseUri?: string;
286
+ }
287
+ /** One error of a compilation or validation (XSD 1.1 Part 1, appendix
288
+ * C): code is the constraint name, such as 'cvc-complex-type.2.4'. */
289
+ export interface SchemaReport {
290
+ code: string;
291
+ description: string;
292
+ /** The schema document's URI, or the instance's. */
293
+ sourceName: string;
294
+ lineNumber: number;
295
+ columnNumber: number;
296
+ }
297
+ export interface ValidateOptions {
298
+ /** 'strict' (default): the root needs a global declaration; 'lax'. */
299
+ mode?: 'strict' | 'lax';
300
+ /** Validate the root against this type of the schema instead, by NCName
301
+ * or Q{uri}local. */
302
+ type?: string;
303
+ /** The document URI of text input. */
304
+ uri?: string;
305
+ }
306
+ /** The validity of the validation root (Part 1, 3.3.5.1). */
307
+ export type Validity = 'valid' | 'invalid' | 'not-known';
308
+ export interface ValidationResult {
309
+ validity: Validity;
310
+ /** Every error found, in order; empty when valid. */
311
+ reports: SchemaReport[];
312
+ /** Unless invalid: the validated copy, its elements and attributes
313
+ * annotated with their types (XDM 4.0, 3.3). */
314
+ document: Value | undefined;
315
+ }
316
+ export interface SchematronCompileOptions {
317
+ /** The phase: an id, '#ALL', '#ANY' (each validation takes the first
318
+ * phase whose when holds for the document) or '#DEFAULT' (the
319
+ * default: the schema's defaultPhase, else '#ALL'). */
320
+ phase?: string;
321
+ /** Against which a schema given by URI resolves. */
322
+ baseUri?: string;
323
+ /** Values of schema parameters by name: query fragments, each put in
324
+ * place of its param's value. */
325
+ parameters?: Record<string, string>;
326
+ }
327
+ export interface SchematronValidateOptions {
328
+ /** The document URI of text input. */
329
+ uri?: string;
330
+ /** Also list each rule that fires, as a finding of kind 'fired-rule'. */
331
+ firedRules?: boolean;
332
+ /** Also give the SVRL report (ISO/IEC 19757-3, annex D). */
333
+ svrl?: boolean;
334
+ }
335
+ /** A diagnostic an assertion names, evaluated for the finding. */
336
+ export interface SchematronDiagnostic {
337
+ id: string;
338
+ language: string;
339
+ text: string;
340
+ }
341
+ /** A property an assertion names, evaluated for the finding. */
342
+ export interface SchematronProperty {
343
+ id: string;
344
+ role: string;
345
+ scheme: string;
346
+ text: string;
347
+ }
348
+ /** A failed assert, a successful report, or (with firedRules) a rule that
349
+ * fired. Empty strings for attributes the assertion does not have. */
350
+ export interface SchematronFinding {
351
+ kind: 'failed-assert' | 'successful-report' | 'fired-rule';
352
+ id: string;
353
+ role: string;
354
+ flag: string;
355
+ severity: string;
356
+ /** An error finding: its severity is 'fatal' or 'error'; without one,
357
+ * its role or a flag is, or it has neither role nor flag. */
358
+ isError: boolean;
359
+ message: string;
360
+ diagnostics: SchematronDiagnostic[];
361
+ properties: SchematronProperty[];
362
+ patternId: string;
363
+ /** The test as compiled, placeholders replaced. */
364
+ test: string;
365
+ /** The subject node as fn:path gives it. */
366
+ path: string;
367
+ /** The node's place in the document (0 when the tree keeps none). */
368
+ sourceName: string;
369
+ /** The URI of the document the node is in: a subordinate document's for
370
+ * a pattern with documents, or one a rule read with doc(); else the
371
+ * validated document's (empty when it has none). lineNumber and
372
+ * columnNumber are of this document. */
373
+ document: string;
374
+ lineNumber: number;
375
+ columnNumber: number;
376
+ /** The assertion's place in the Schematron schema. */
377
+ schemaSourceName: string;
378
+ schemaLineNumber: number;
379
+ schemaColumnNumber: number;
380
+ }
381
+ export interface SchematronResult {
382
+ /** No error finding. */
383
+ valid: boolean;
384
+ /** The phase in force (under '#ANY', the one chosen). */
385
+ phase: string;
386
+ findings: SchematronFinding[];
387
+ /** With options.svrl. */
388
+ svrl?: string;
389
+ }
390
+ /** The EXI options of Processor.encodeExi and Processor.parseExi
391
+ * (Efficient XML Interchange 1.0, section 5.4). Every option left out has
392
+ * its EXI default: bit-packed, nothing preserved, not strict, a document,
393
+ * unbounded string tables, built-in grammars. In parseExi, a stream whose
394
+ * header carries its options is read with those instead. */
395
+ export interface ExiOptions {
396
+ /** How events and values are laid out (EXI 1.0, 5.4 and 9): 'bit-packed'
397
+ * (default), 'byte-alignment', 'pre-compression' (values in channels,
398
+ * not compressed) or 'compression' (the channels compressed with
399
+ * DEFLATE). */
400
+ alignment?: 'bit-packed' | 'byte-alignment' | 'pre-compression' | 'compression';
401
+ /** The fidelity options (EXI 1.0, 6.3): what the stream keeps besides
402
+ * elements, attributes and text. 'dtd' writes nothing from a tree,
403
+ * which has no document type declaration; without 'prefixes' a decoder
404
+ * names the prefixes ns0, ns1 and so on. */
405
+ preserve?: ('comments' | 'pis' | 'dtd' | 'prefixes' | 'lexical-values')[];
406
+ /** A fragment (EXI 1.0, 8.4.2): zero or more elements, comments and
407
+ * processing instructions, not a document. */
408
+ fragment?: boolean;
409
+ /** strict: schema-informed grammars without their undeclared
410
+ * productions; it means nothing with the built-in grammars. */
411
+ strict?: boolean;
412
+ /** selfContained: self-contained elements are allowed (EXI 1.0,
413
+ * 8.5.4.4.1). */
414
+ selfContained?: boolean;
415
+ /** blockSize: the values per compression block (default 1,000,000). */
416
+ blockSize?: number;
417
+ /** valueMaxLength: the longest value the string tables keep (default
418
+ * unbounded). */
419
+ valueMaxLength?: number;
420
+ /** valuePartitionCapacity: how many values the global string table
421
+ * keeps (default unbounded). */
422
+ valuePartitionCapacity?: number;
423
+ /** encodeExi: the header starts with the EXI cookie '$EXI' (EXI 1.0,
424
+ * 5.1). */
425
+ includeCookie?: boolean;
426
+ /** encodeExi: the header carries the options, so that a decoder need
427
+ * not know them. */
428
+ includeOptions?: boolean;
429
+ /** encodeExi: the stream is Canonical EXI (W3C Recommendation 7 June
430
+ * 2018). */
431
+ canonical?: boolean;
432
+ /** encodeExi: the header's options name the schemaId (EXI 1.0, 5.4). */
433
+ includeSchemaId?: boolean;
434
+ /** encodeExi, with canonical: the header leaves the options document
435
+ * out (Canonical EXI, omitOptionsDocument). */
436
+ omitOptionsDocument?: boolean;
437
+ /** encodeExi, with canonical: date-times are written in UTC (Canonical
438
+ * EXI, utcTime). */
439
+ utcTime?: boolean;
440
+ /** encodeExi, with selfContained: the elements written self-contained,
441
+ * so that each can be read on its own (EXI 1.0, 8.5.4.4.1), each an
442
+ * NCName in no namespace or Q{uri}local. */
443
+ selfContainedElements?: string[];
444
+ /** Schema-informed grammars from a compiled schema of this processor
445
+ * (Processor.compileSchema); without it the built-in grammars. */
446
+ schema?: Schema;
447
+ }
448
+ /** A failure in sxml: a static, dynamic or type error of the expression
449
+ * (with its error code), a document that is not well-formed, a limit, or
450
+ * out of memory. */
451
+ export declare class SxmlError extends Error {
452
+ /** The status, such as 'DYNAMIC_ERROR' or 'MALFORMED_INPUT'. */
453
+ readonly status: string;
454
+ /** The error code as prefix:local, such as 'err:FOAR0001'; '' when the
455
+ * status has none. */
456
+ readonly code: string;
457
+ readonly codeNamespaceUri: string;
458
+ readonly codeLocalName: string;
459
+ readonly description: string;
460
+ /** The module or document the location is in: 'expression', 'query',
461
+ * a module's URI; '' when unknown. */
462
+ readonly sourceName: string;
463
+ readonly lineNumber: number;
464
+ readonly columnNumber: number;
465
+ constructor(fields: {
466
+ status: string;
467
+ codeNamespaceUri: string;
468
+ codeLocalName: string;
469
+ codePrefix: string;
470
+ description: string;
471
+ sourceName?: string;
472
+ lineNumber: number;
473
+ columnNumber: number;
474
+ });
475
+ }
476
+ /** A schema that does not compile: every error, with the first as the
477
+ * SxmlError's own code, description and location. */
478
+ export declare class SchemaError extends SxmlError {
479
+ readonly reports: readonly SchemaReport[];
480
+ constructor(error: SxmlError, reports: SchemaReport[]);
481
+ }
482
+ /** The loaded module: makes processors. One per page or process is enough;
483
+ * processors made from it are independent. */
484
+ export declare class Sxml {
485
+ /** The library version, such as '0.2.0'. */
486
+ readonly version: string;
487
+ /** The optional features of the module: all of them (D272; 'test' adds
488
+ * nothing, it checks that the list reaches the processor). */
489
+ readonly features: readonly string[];
490
+ private readonly registry;
491
+ createProcessor(options?: ProcessorOptions): Processor;
492
+ /**
493
+ * Loads a tree-sitter language file (tree-sitter-NAME.wasm, as
494
+ * `tree-sitter build --wasm` writes it) into this module for
495
+ * tree-sitter:parse: links it into sxml.wasm (src/linker.ts) and checks
496
+ * its ABI and queries. Give it to processors with createProcessor({
497
+ * codeLanguages }). It stays loaded as long as this Sxml. Rejects with
498
+ * an Error that says what is wrong with the file, the name or a query.
499
+ */
500
+ loadCodeLanguage(options: CodeLanguageOptions): Promise<CodeLanguage>;
501
+ }
502
+ /** A tree-sitter language loaded by Sxml.loadCodeLanguage, for
503
+ * createProcessor({ codeLanguages }). */
504
+ export declare class CodeLanguage {
505
+ /** Its name in tree-sitter:parse. */
506
+ readonly name: string;
507
+ /** The grammar's tree-sitter language ABI, 13 to 15. */
508
+ readonly abiVersion: number;
509
+ }
510
+ /** Loads and instantiates sxml.wasm. */
511
+ export declare function load(options?: LoadOptions): Promise<Sxml>;
512
+ /** A processor (include/sxml/processor.h): its name pool, types and items.
513
+ * Values and expressions belong to the processor that made them. */
514
+ export declare class Processor {
515
+ private readonly state;
516
+ /** Parses an XML document and returns its document node. */
517
+ parse(xml: string | Uint8Array, options?: {
518
+ uri?: string;
519
+ }): Value;
520
+ /** Compiles an XPath 4.0 expression, for evaluating it many times. */
521
+ compile(expression: string, options?: CompileOptions): XPathExpression;
522
+ /** Compiles and evaluates an expression once; the variables are those
523
+ * options.variables names. */
524
+ evaluate(expression: string, options?: StaticOptions & EvaluateOptions): Value;
525
+ /** Compiles an XQuery 4.0 main module, with the library modules it
526
+ * imports (the resolver is asked for them, kind 'xquery-module'), for
527
+ * evaluating it many times. */
528
+ compileQuery(query: string, options?: QueryCompileOptions): XQuery;
529
+ /** Compiles an XSLT 4.0 stylesheet, with the modules it includes and
530
+ * imports (kind 'xslt-module') and the packages it uses (kind
531
+ * 'xslt-package'), for running it many times. A stylesheet with errors
532
+ * throws a SchemaError with every error as its reports (codes with
533
+ * their prefix, such as 'err:XPST0003'). */
534
+ compileStylesheet(stylesheet: string | Uint8Array, options?: StylesheetCompileOptions): Stylesheet;
535
+ /** Compiles an XSD 1.1 schema from one or more schema documents (a
536
+ * string is a document's text), with every document they include,
537
+ * import, redefine or override (the resolver is asked, kind
538
+ * 'schema-document'). Throws a SchemaError with every report when the
539
+ * schema has errors. */
540
+ compileSchema(documents: string | SchemaDocument | (string | SchemaDocument)[], options?: SchemaCompileOptions): Schema;
541
+ /** Compiles a Schematron schema (ISO/IEC 19757-3:2025) from its text or
542
+ * its URI (the resolver is asked, kind 'xml-document', for it and for
543
+ * the documents its include and extends href name), for the phase
544
+ * options.phase names (an id, '#ALL', '#ANY', or '#DEFAULT', the
545
+ * default) with the schema parameters options.parameters gives. Throws a
546
+ * SchemaError with every error when it does not compile (codes such as
547
+ * 'schematron:syntax', 'err:XPST0003'). */
548
+ compileSchematron(schema: string | SchemaDocument, options?: SchematronCompileOptions): Schematron;
549
+ /** Converts JSON-like data to a value (see JsonData). */
550
+ value(data: Input): Value;
551
+ /** Serializes a value: by the adaptive method without options, else as
552
+ * fn:serialize with them (method xml unless they name another). */
553
+ serialize(value: Value, options?: SerializationOptions): string;
554
+ /** Serializes a value as serialize() does, writing the output to sink a
555
+ * chunk at a time instead of returning it (D294). */
556
+ serializeTo(value: Value, sink: OutputSink, options?: SerializationOptions): void;
557
+ /** Encodes a document or element node as an EXI stream (Efficient XML
558
+ * Interchange 1.0) with options: by default bit-packed, with the
559
+ * built-in grammars, keeping elements, attributes and text only. Throws
560
+ * a TypeError or RangeError for options it does not take, and an
561
+ * SxmlError for a value that is not one document or element node or
562
+ * content the options cannot represent. */
563
+ encodeExi(node: Value, options?: ExiOptions): Uint8Array;
564
+ /** Decodes an EXI stream into a new document and returns its document
565
+ * node, as parse() does for XML text. options are those the stream was
566
+ * encoded with, needed when its header does not carry them;
567
+ * options.uri is the document URI. A stream that is not EXI throws an
568
+ * SxmlError with status 'MALFORMED_INPUT'. */
569
+ parseExi(stream: Uint8Array, options?: ExiOptions & {
570
+ uri?: string;
571
+ }): Value;
572
+ /** Releases the processor and every value and expression made with it. */
573
+ dispose(): void;
574
+ /** The allocations the processor holds, for leak checks in tests; after
575
+ * dispose(), those that were left when it was destroyed (0 unless the
576
+ * package or sxml leaked). */
577
+ liveAllocationCount(): number;
578
+ serializeWith(value: Value, options: Value | undefined, sink: OutputSink): void;
579
+ }
580
+ /** A compiled XPath 4.0 expression (include/sxml/xpath.h). */
581
+ export declare class XPathExpression {
582
+ readonly processor: Processor;
583
+ /** The external variables, in the order compile() was given them. */
584
+ readonly variables: readonly string[];
585
+ private handle;
586
+ /** Evaluates the expression; the result is a new value. */
587
+ evaluate(options?: EvaluateOptions): Value;
588
+ dispose(): void;
589
+ }
590
+ /** A compiled XQuery 4.0 main module (include/sxml/xquery.h).
591
+ * Processor.compileQuery makes it. */
592
+ export declare class XQuery {
593
+ readonly processor: Processor;
594
+ /** Whether its body is an updating expression (XQUF 3.0, 2.2): its
595
+ * result is then empty and its changes go to options.updates. */
596
+ readonly isUpdating: boolean;
597
+ private handle;
598
+ /** Evaluates the query; the result is a new value. */
599
+ evaluate(options?: QueryEvaluateOptions): Value;
600
+ /** Serializes a value with the serialization parameters the query's
601
+ * output declarations give (XQuery 4.0, 5.22: method xml unless they
602
+ * name another). Value.serialize(options) uses options instead. */
603
+ serialize(value: Value): string;
604
+ /** Serializes a value as serialize() does, writing the output to sink a
605
+ * chunk at a time instead of returning it (D294). */
606
+ serializeTo(value: Value, sink: OutputSink): void;
607
+ /** Evaluates the query and serializes its result as serialize() does. */
608
+ run(options?: QueryEvaluateOptions): string;
609
+ /** Evaluates the query and writes its serialized result to sink a chunk
610
+ * at a time, as serializeTo() does (D294). */
611
+ runTo(sink: OutputSink, options?: QueryEvaluateOptions): void;
612
+ private serializeOutput;
613
+ dispose(): void;
614
+ private address;
615
+ }
616
+ /** A compiled XSLT 4.0 stylesheet (include/sxml/xslt.h).
617
+ * Processor.compileStylesheet makes it. */
618
+ export declare class Stylesheet {
619
+ readonly processor: Processor;
620
+ private handle;
621
+ /** Runs one transformation (XSLT 4.0, 2.3): applies templates to the
622
+ * source, or calls options.initialTemplate or options.initialFunction. */
623
+ transform(options?: TransformOptions): TransformResult;
624
+ dispose(): void;
625
+ private address;
626
+ }
627
+ /** A compiled XSD 1.1 schema (include/sxml/schema.h).
628
+ * Processor.compileSchema makes it. */
629
+ export declare class Schema {
630
+ readonly processor: Processor;
631
+ private handle;
632
+ /** Validates a document (XSD 1.1 Part 1, 5.2): XML text, parsed and
633
+ * validated in one pass so that reports have its lines and columns, or
634
+ * a document or element node of this processor. An invalid document is
635
+ * not an exception: see the result's validity and reports. Text that
636
+ * is not well-formed throws, as Processor.parse does. */
637
+ validate(input: Value | string | Uint8Array, options?: ValidateOptions): ValidationResult;
638
+ dispose(): void;
639
+ }
640
+ /** A compiled Schematron schema (include/sxml/schematron.h).
641
+ * Processor.compileSchematron makes it. */
642
+ export declare class Schematron {
643
+ readonly processor: Processor;
644
+ private handle;
645
+ /** The schema's title, schemaVersion, schematronEdition (any value, as
646
+ * written) and queryBinding; empty when absent. */
647
+ title: string;
648
+ schemaVersion: string;
649
+ schematronEdition: string;
650
+ queryBinding: string;
651
+ /** The phase compiled ('#DEFAULT' resolved). */
652
+ phase: string;
653
+ /** The schema's warnings (code 'schematron:compatibility'): a parameter
654
+ * named twice in one pattern instance, a pattern's let read by another
655
+ * pattern, a rule's let after its assertions. Read as their authors
656
+ * mean them; each names the clause it deviates from. */
657
+ warnings: readonly SchemaReport[];
658
+ /** Validates a document: XML text, parsed with its locations, or a node
659
+ * of this processor. Findings are not exceptions: see the result. A
660
+ * dynamic error in the rules, or text that is not well-formed, throws. */
661
+ validate(input: Value | string | Uint8Array, options?: SchematronValidateOptions): SchematronResult;
662
+ dispose(): void;
663
+ private address;
664
+ }
665
+ /** An XDM value: a sequence of items in its processor (a parsed document,
666
+ * an evaluation's result). */
667
+ export declare class Value {
668
+ readonly processor: Processor;
669
+ private handle;
670
+ /** Serializes the value (Processor.serialize). */
671
+ serialize(options?: SerializationOptions): string;
672
+ /** Serializes the value to sink a chunk at a time
673
+ * (Processor.serializeTo). */
674
+ serializeTo(sink: OutputSink, options?: SerializationOptions): void;
675
+ /** The value by the adaptive method: items one per line, strings
676
+ * quoted, nodes as XML. */
677
+ toString(): string;
678
+ dispose(): void;
679
+ }