@xapi-js/core 1.2.0 → 1.4.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/LICENSE +21 -21
- package/README.md +21 -1
- package/dist/index.cjs +610 -218
- package/dist/index.d.cts +160 -26
- package/dist/index.d.ts +160 -26
- package/dist/index.js +599 -192
- package/package.json +2 -6
package/dist/index.d.cts
CHANGED
|
@@ -191,15 +191,15 @@ declare class XapiRoot {
|
|
|
191
191
|
*/
|
|
192
192
|
datasetSize(): number;
|
|
193
193
|
/**
|
|
194
|
-
*
|
|
195
|
-
* @returns An
|
|
194
|
+
* Returns all parameters as an array.
|
|
195
|
+
* @returns An array of parameters.
|
|
196
196
|
*/
|
|
197
|
-
|
|
197
|
+
getParameters(): Parameter[];
|
|
198
198
|
/**
|
|
199
|
-
*
|
|
200
|
-
* @returns An
|
|
199
|
+
* Returns all datasets as an array.
|
|
200
|
+
* @returns An array of datasets.
|
|
201
201
|
*/
|
|
202
|
-
|
|
202
|
+
getDatasets(): Dataset[];
|
|
203
203
|
}
|
|
204
204
|
/**
|
|
205
205
|
* Represents a dataset within an X-API XML structure.
|
|
@@ -283,20 +283,20 @@ declare class Dataset {
|
|
|
283
283
|
*/
|
|
284
284
|
setColumn(rowIdx: number, columnId: string, value: XapiValueType): void;
|
|
285
285
|
/**
|
|
286
|
-
*
|
|
287
|
-
* @returns An
|
|
286
|
+
* Returns all constant column definitions as an array.
|
|
287
|
+
* @returns An array of constant columns.
|
|
288
288
|
*/
|
|
289
|
-
|
|
289
|
+
getConstColumns(): ConstColumn[];
|
|
290
290
|
/**
|
|
291
|
-
*
|
|
292
|
-
* @returns An
|
|
291
|
+
* Returns all column definitions as an array.
|
|
292
|
+
* @returns An array of columns.
|
|
293
293
|
*/
|
|
294
|
-
|
|
294
|
+
getColumns(): Column[];
|
|
295
295
|
/**
|
|
296
|
-
*
|
|
297
|
-
* @returns An
|
|
296
|
+
* Returns all rows in the dataset as an array.
|
|
297
|
+
* @returns An array of rows.
|
|
298
298
|
*/
|
|
299
|
-
|
|
299
|
+
getRows(): Row[];
|
|
300
300
|
/**
|
|
301
301
|
* Returns the number of column definitions.
|
|
302
302
|
* @returns The count of columns.
|
|
@@ -322,31 +322,32 @@ declare class Dataset {
|
|
|
322
322
|
*/
|
|
323
323
|
declare function initXapi(options: XapiOptions): void;
|
|
324
324
|
/**
|
|
325
|
-
* Parses an XML string into an XapiRoot object using
|
|
325
|
+
* Parses an XML string into an XapiRoot object using custom parser.
|
|
326
326
|
* @param xml - The string containing the XML data.
|
|
327
|
-
* @returns
|
|
327
|
+
* @returns An XapiRoot object.
|
|
328
328
|
*/
|
|
329
329
|
declare function parse(xml: string): XapiRoot;
|
|
330
330
|
declare function write(root: XapiRoot): string;
|
|
331
331
|
//#endregion
|
|
332
332
|
//#region src/utils.d.ts
|
|
333
|
+
/**
|
|
334
|
+
* Represents an XML node in the parsed structure.
|
|
335
|
+
*/
|
|
336
|
+
type XmlNode = {
|
|
337
|
+
tagName: string;
|
|
338
|
+
attributes?: Record<string, string>;
|
|
339
|
+
children?: (XmlNode | string)[];
|
|
340
|
+
};
|
|
333
341
|
declare function arrayBufferToString(buffer: ArrayBuffer): string;
|
|
334
342
|
/**
|
|
335
343
|
* Creates an array of entities for parsing XML, including control characters.
|
|
344
|
+
* @deprecated Use PARSE_ENTITIES directly for better performance
|
|
336
345
|
* @returns An array of objects, each with an `entity` (e.g., "") and its `value` (e.g., "\x01").
|
|
337
346
|
*/
|
|
338
347
|
declare function makeParseEntities(): {
|
|
339
348
|
entity: string;
|
|
340
349
|
value: string;
|
|
341
350
|
}[];
|
|
342
|
-
/**
|
|
343
|
-
* Creates an array of entities for writing XML, including control characters.
|
|
344
|
-
* @returns An array of objects, each with an `entity` (e.g., "") and its `value` (e.g., "\x01").
|
|
345
|
-
*/
|
|
346
|
-
declare function makeWriterEntities(): {
|
|
347
|
-
entity: string;
|
|
348
|
-
value: string;
|
|
349
|
-
}[];
|
|
350
351
|
/**
|
|
351
352
|
* Converts a Base64 string to a Uint8Array.
|
|
352
353
|
* @param base64String - The Base64 string to convert.
|
|
@@ -408,5 +409,138 @@ declare function convertToColumnType(value: XapiValueType, type: ColumnType): Xa
|
|
|
408
409
|
declare function convertToString(value: XapiValueType, type: ColumnType): string;
|
|
409
410
|
declare function _unescapeXml(str?: string): string | undefined;
|
|
410
411
|
declare function isXapiRoot(value: unknown): value is XapiRoot;
|
|
412
|
+
/**
|
|
413
|
+
* Escapes XML special characters in a string.
|
|
414
|
+
* @param str - The string to escape.
|
|
415
|
+
* @returns The escaped string.
|
|
416
|
+
*/
|
|
417
|
+
declare function escapeXml(str: string): string;
|
|
418
|
+
/**
|
|
419
|
+
* Encodes control characters as XML entities, excluding standard whitespace.
|
|
420
|
+
* Encodes 0x01-0x08, 0x0B-0x0C, 0x0E-0x1F but NOT 0x09 (tab), 0x0A (LF), 0x0D (CR), 0x20 (space).
|
|
421
|
+
* @param str - The string to encode.
|
|
422
|
+
* @returns The encoded string.
|
|
423
|
+
*/
|
|
424
|
+
declare function encodeControlChars(str: string): string;
|
|
425
|
+
/**
|
|
426
|
+
* A string builder for generating formatted XML.
|
|
427
|
+
*/
|
|
428
|
+
declare class XmlStringBuilder {
|
|
429
|
+
private lines;
|
|
430
|
+
private indentLevel;
|
|
431
|
+
private readonly indentString;
|
|
432
|
+
/**
|
|
433
|
+
* Writes the XML declaration.
|
|
434
|
+
* @param version - The XML version (default: "1.0").
|
|
435
|
+
* @param encoding - The encoding (default: "UTF-8").
|
|
436
|
+
*/
|
|
437
|
+
writeDeclaration(version?: string, encoding?: string): void;
|
|
438
|
+
/**
|
|
439
|
+
* Writes a start element tag.
|
|
440
|
+
* @param name - The element name.
|
|
441
|
+
* @param attributes - Optional attributes object.
|
|
442
|
+
* @param selfClosing - Whether to create a self-closing tag.
|
|
443
|
+
*/
|
|
444
|
+
writeStartElement(name: string, attributes?: Record<string, string>, selfClosing?: boolean): void;
|
|
445
|
+
/**
|
|
446
|
+
* Writes an end element tag.
|
|
447
|
+
* @param name - The element name.
|
|
448
|
+
*/
|
|
449
|
+
writeEndElement(name: string): void;
|
|
450
|
+
/**
|
|
451
|
+
* Writes an element with text content.
|
|
452
|
+
* @param name - The element name.
|
|
453
|
+
* @param attributes - Optional attributes object.
|
|
454
|
+
* @param text - The text content.
|
|
455
|
+
*/
|
|
456
|
+
writeElementWithText(name: string, attributes: Record<string, string> | undefined, text: string): void;
|
|
457
|
+
/**
|
|
458
|
+
* Returns the generated XML string.
|
|
459
|
+
* @returns The complete XML string with line breaks.
|
|
460
|
+
*/
|
|
461
|
+
toString(): string;
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Parses XML string into an XML node structure.
|
|
465
|
+
* This is a lightweight parser optimized for X-API XML structure.
|
|
466
|
+
*
|
|
467
|
+
* @param xml - The XML string to parse.
|
|
468
|
+
* @returns An array of parsed XML nodes.
|
|
469
|
+
*/
|
|
470
|
+
declare function parseXml(xml: string): XmlNode[];
|
|
471
|
+
//#endregion
|
|
472
|
+
//#region src/schema.d.ts
|
|
473
|
+
type XapiTypeMap = {
|
|
474
|
+
STRING: string;
|
|
475
|
+
INT: number;
|
|
476
|
+
FLOAT: number;
|
|
477
|
+
DECIMAL: number;
|
|
478
|
+
BIGDECIMAL: number;
|
|
479
|
+
DATE: Date;
|
|
480
|
+
DATETIME: Date;
|
|
481
|
+
TIME: Date;
|
|
482
|
+
BLOB: Uint8Array;
|
|
483
|
+
};
|
|
484
|
+
interface XapiColumnSchema<T extends ColumnType = ColumnType, Optional extends boolean = boolean> {
|
|
485
|
+
readonly kind: "xapi-column";
|
|
486
|
+
readonly type: T;
|
|
487
|
+
readonly size: number;
|
|
488
|
+
readonly optional: Optional;
|
|
489
|
+
}
|
|
490
|
+
type XapiColumns = Record<string, XapiColumnSchema>;
|
|
491
|
+
interface XapiDatasetSchema<Columns extends XapiColumns = XapiColumns> {
|
|
492
|
+
readonly kind: "xapi-dataset";
|
|
493
|
+
readonly columns: Columns;
|
|
494
|
+
}
|
|
495
|
+
type XapiDatasets = Record<string, XapiDatasetSchema>;
|
|
496
|
+
interface XapiRootSchema<Datasets extends XapiDatasets = XapiDatasets, Parameters extends XapiColumns = XapiColumns> {
|
|
497
|
+
readonly kind: "xapi-root";
|
|
498
|
+
readonly datasets: Datasets;
|
|
499
|
+
readonly parameters: Parameters;
|
|
500
|
+
}
|
|
501
|
+
interface XapiOperation<Request extends XapiRootSchema = XapiRootSchema, Response extends XapiRootSchema = XapiRootSchema> {
|
|
502
|
+
readonly kind: "xapi-operation";
|
|
503
|
+
readonly request: Request;
|
|
504
|
+
readonly response: Response;
|
|
505
|
+
}
|
|
506
|
+
type RequiredColumnKeys<Columns extends XapiColumns> = { [Key in keyof Columns]-?: Columns[Key]["optional"] extends true ? never : Key; }[keyof Columns];
|
|
507
|
+
type OptionalColumnKeys<Columns extends XapiColumns> = { [Key in keyof Columns]-?: Columns[Key]["optional"] extends true ? Key : never; }[keyof Columns];
|
|
508
|
+
type InferColumns<Columns extends XapiColumns> = { [Key in RequiredColumnKeys<Columns>]: XapiTypeMap[Columns[Key]["type"]]; } & { [Key in OptionalColumnKeys<Columns>]?: XapiTypeMap[Columns[Key]["type"]]; };
|
|
509
|
+
type InferDataset<Schema extends XapiDatasetSchema> = InferColumns<Schema["columns"]>[];
|
|
510
|
+
type InferRoot<Schema extends XapiRootSchema> = {
|
|
511
|
+
parameters: InferColumns<Schema["parameters"]>;
|
|
512
|
+
datasets: { [Key in keyof Schema["datasets"]]: InferDataset<Schema["datasets"][Key]>; };
|
|
513
|
+
};
|
|
514
|
+
type RequestOf<Operation extends XapiOperation> = InferRoot<Operation["request"]>;
|
|
515
|
+
type ResponseOf<Operation extends XapiOperation> = InferRoot<Operation["response"]>;
|
|
516
|
+
type ColumnOptions<Optional extends boolean> = {
|
|
517
|
+
size?: number;
|
|
518
|
+
optional?: Optional;
|
|
519
|
+
};
|
|
520
|
+
declare function defineDataset<const Columns extends XapiColumns>(columns: Columns): XapiDatasetSchema<Columns>;
|
|
521
|
+
declare function defineRoot<const Datasets extends XapiDatasets, const Parameters extends XapiColumns = Record<never, never>>(definition: {
|
|
522
|
+
datasets: Datasets;
|
|
523
|
+
parameters?: Parameters;
|
|
524
|
+
}): XapiRootSchema<Datasets, Parameters>;
|
|
525
|
+
declare function defineOperation<const Request extends XapiRootSchema, const Response extends XapiRootSchema>(definition: {
|
|
526
|
+
request: Request;
|
|
527
|
+
response: Response;
|
|
528
|
+
}): XapiOperation<Request, Response>;
|
|
529
|
+
declare const xapi: {
|
|
530
|
+
readonly string: <const Optional extends boolean = false>(options?: ColumnOptions<Optional>) => XapiColumnSchema<"STRING", Optional>;
|
|
531
|
+
readonly int: <const Optional extends boolean = false>(options?: ColumnOptions<Optional>) => XapiColumnSchema<"INT", Optional>;
|
|
532
|
+
readonly float: <const Optional extends boolean = false>(options?: ColumnOptions<Optional>) => XapiColumnSchema<"FLOAT", Optional>;
|
|
533
|
+
readonly decimal: <const Optional extends boolean = false>(options?: ColumnOptions<Optional>) => XapiColumnSchema<"DECIMAL", Optional>;
|
|
534
|
+
readonly bigdecimal: <const Optional extends boolean = false>(options?: ColumnOptions<Optional>) => XapiColumnSchema<"BIGDECIMAL", Optional>;
|
|
535
|
+
readonly date: <const Optional extends boolean = false>(options?: ColumnOptions<Optional>) => XapiColumnSchema<"DATE", Optional>;
|
|
536
|
+
readonly datetime: <const Optional extends boolean = false>(options?: ColumnOptions<Optional>) => XapiColumnSchema<"DATETIME", Optional>;
|
|
537
|
+
readonly time: <const Optional extends boolean = false>(options?: ColumnOptions<Optional>) => XapiColumnSchema<"TIME", Optional>;
|
|
538
|
+
readonly blob: <const Optional extends boolean = false>(options?: ColumnOptions<Optional>) => XapiColumnSchema<"BLOB", Optional>;
|
|
539
|
+
readonly dataset: typeof defineDataset;
|
|
540
|
+
readonly root: typeof defineRoot;
|
|
541
|
+
readonly operation: typeof defineOperation;
|
|
542
|
+
};
|
|
543
|
+
declare function encodeRoot<Schema extends XapiRootSchema>(schema: Schema, value: InferRoot<Schema>): XapiRoot;
|
|
544
|
+
declare function decodeRoot<Schema extends XapiRootSchema>(schema: Schema, root: XapiRoot): InferRoot<Schema>;
|
|
411
545
|
//#endregion
|
|
412
|
-
export { Col, Column, ColumnInfo, ColumnType, ColumnTypeError, ConstColumn, Dataset, InvalidXmlError, NexaVersion, Parameter, Row, RowType, Rows, StringWritableStream, XapiOptions, XapiParameters, XapiRoot, XapiValueType, XapiVersion, XplatformVersion, _unescapeXml, arrayBufferToString, base64ToUint8Array, columnType, convertToColumnType, convertToString, dateToString, initXapi, isXapiRoot, makeParseEntities,
|
|
546
|
+
export { Col, Column, ColumnInfo, ColumnType, ColumnTypeError, ConstColumn, Dataset, InferColumns, InferDataset, InferRoot, InvalidXmlError, NexaVersion, Parameter, RequestOf, ResponseOf, Row, RowType, Rows, StringWritableStream, XapiColumnSchema, XapiColumns, XapiDatasetSchema, XapiDatasets, XapiOperation, XapiOptions, XapiParameters, XapiRoot, XapiRootSchema, XapiTypeMap, XapiValueType, XapiVersion, XmlNode, XmlStringBuilder, XplatformVersion, _unescapeXml, arrayBufferToString, base64ToUint8Array, columnType, convertToColumnType, convertToString, dateToString, decodeRoot, defineDataset, defineOperation, defineRoot, encodeControlChars, encodeRoot, escapeXml, initXapi, isXapiRoot, makeParseEntities, parse, parseXml, rowType, stringToDate, stringToReadableStream, uint8ArrayToBase64, write, xapi };
|
package/dist/index.d.ts
CHANGED
|
@@ -191,15 +191,15 @@ declare class XapiRoot {
|
|
|
191
191
|
*/
|
|
192
192
|
datasetSize(): number;
|
|
193
193
|
/**
|
|
194
|
-
*
|
|
195
|
-
* @returns An
|
|
194
|
+
* Returns all parameters as an array.
|
|
195
|
+
* @returns An array of parameters.
|
|
196
196
|
*/
|
|
197
|
-
|
|
197
|
+
getParameters(): Parameter[];
|
|
198
198
|
/**
|
|
199
|
-
*
|
|
200
|
-
* @returns An
|
|
199
|
+
* Returns all datasets as an array.
|
|
200
|
+
* @returns An array of datasets.
|
|
201
201
|
*/
|
|
202
|
-
|
|
202
|
+
getDatasets(): Dataset[];
|
|
203
203
|
}
|
|
204
204
|
/**
|
|
205
205
|
* Represents a dataset within an X-API XML structure.
|
|
@@ -283,20 +283,20 @@ declare class Dataset {
|
|
|
283
283
|
*/
|
|
284
284
|
setColumn(rowIdx: number, columnId: string, value: XapiValueType): void;
|
|
285
285
|
/**
|
|
286
|
-
*
|
|
287
|
-
* @returns An
|
|
286
|
+
* Returns all constant column definitions as an array.
|
|
287
|
+
* @returns An array of constant columns.
|
|
288
288
|
*/
|
|
289
|
-
|
|
289
|
+
getConstColumns(): ConstColumn[];
|
|
290
290
|
/**
|
|
291
|
-
*
|
|
292
|
-
* @returns An
|
|
291
|
+
* Returns all column definitions as an array.
|
|
292
|
+
* @returns An array of columns.
|
|
293
293
|
*/
|
|
294
|
-
|
|
294
|
+
getColumns(): Column[];
|
|
295
295
|
/**
|
|
296
|
-
*
|
|
297
|
-
* @returns An
|
|
296
|
+
* Returns all rows in the dataset as an array.
|
|
297
|
+
* @returns An array of rows.
|
|
298
298
|
*/
|
|
299
|
-
|
|
299
|
+
getRows(): Row[];
|
|
300
300
|
/**
|
|
301
301
|
* Returns the number of column definitions.
|
|
302
302
|
* @returns The count of columns.
|
|
@@ -322,31 +322,32 @@ declare class Dataset {
|
|
|
322
322
|
*/
|
|
323
323
|
declare function initXapi(options: XapiOptions): void;
|
|
324
324
|
/**
|
|
325
|
-
* Parses an XML string into an XapiRoot object using
|
|
325
|
+
* Parses an XML string into an XapiRoot object using custom parser.
|
|
326
326
|
* @param xml - The string containing the XML data.
|
|
327
|
-
* @returns
|
|
327
|
+
* @returns An XapiRoot object.
|
|
328
328
|
*/
|
|
329
329
|
declare function parse(xml: string): XapiRoot;
|
|
330
330
|
declare function write(root: XapiRoot): string;
|
|
331
331
|
//#endregion
|
|
332
332
|
//#region src/utils.d.ts
|
|
333
|
+
/**
|
|
334
|
+
* Represents an XML node in the parsed structure.
|
|
335
|
+
*/
|
|
336
|
+
type XmlNode = {
|
|
337
|
+
tagName: string;
|
|
338
|
+
attributes?: Record<string, string>;
|
|
339
|
+
children?: (XmlNode | string)[];
|
|
340
|
+
};
|
|
333
341
|
declare function arrayBufferToString(buffer: ArrayBuffer): string;
|
|
334
342
|
/**
|
|
335
343
|
* Creates an array of entities for parsing XML, including control characters.
|
|
344
|
+
* @deprecated Use PARSE_ENTITIES directly for better performance
|
|
336
345
|
* @returns An array of objects, each with an `entity` (e.g., "") and its `value` (e.g., "\x01").
|
|
337
346
|
*/
|
|
338
347
|
declare function makeParseEntities(): {
|
|
339
348
|
entity: string;
|
|
340
349
|
value: string;
|
|
341
350
|
}[];
|
|
342
|
-
/**
|
|
343
|
-
* Creates an array of entities for writing XML, including control characters.
|
|
344
|
-
* @returns An array of objects, each with an `entity` (e.g., "") and its `value` (e.g., "\x01").
|
|
345
|
-
*/
|
|
346
|
-
declare function makeWriterEntities(): {
|
|
347
|
-
entity: string;
|
|
348
|
-
value: string;
|
|
349
|
-
}[];
|
|
350
351
|
/**
|
|
351
352
|
* Converts a Base64 string to a Uint8Array.
|
|
352
353
|
* @param base64String - The Base64 string to convert.
|
|
@@ -408,5 +409,138 @@ declare function convertToColumnType(value: XapiValueType, type: ColumnType): Xa
|
|
|
408
409
|
declare function convertToString(value: XapiValueType, type: ColumnType): string;
|
|
409
410
|
declare function _unescapeXml(str?: string): string | undefined;
|
|
410
411
|
declare function isXapiRoot(value: unknown): value is XapiRoot;
|
|
412
|
+
/**
|
|
413
|
+
* Escapes XML special characters in a string.
|
|
414
|
+
* @param str - The string to escape.
|
|
415
|
+
* @returns The escaped string.
|
|
416
|
+
*/
|
|
417
|
+
declare function escapeXml(str: string): string;
|
|
418
|
+
/**
|
|
419
|
+
* Encodes control characters as XML entities, excluding standard whitespace.
|
|
420
|
+
* Encodes 0x01-0x08, 0x0B-0x0C, 0x0E-0x1F but NOT 0x09 (tab), 0x0A (LF), 0x0D (CR), 0x20 (space).
|
|
421
|
+
* @param str - The string to encode.
|
|
422
|
+
* @returns The encoded string.
|
|
423
|
+
*/
|
|
424
|
+
declare function encodeControlChars(str: string): string;
|
|
425
|
+
/**
|
|
426
|
+
* A string builder for generating formatted XML.
|
|
427
|
+
*/
|
|
428
|
+
declare class XmlStringBuilder {
|
|
429
|
+
private lines;
|
|
430
|
+
private indentLevel;
|
|
431
|
+
private readonly indentString;
|
|
432
|
+
/**
|
|
433
|
+
* Writes the XML declaration.
|
|
434
|
+
* @param version - The XML version (default: "1.0").
|
|
435
|
+
* @param encoding - The encoding (default: "UTF-8").
|
|
436
|
+
*/
|
|
437
|
+
writeDeclaration(version?: string, encoding?: string): void;
|
|
438
|
+
/**
|
|
439
|
+
* Writes a start element tag.
|
|
440
|
+
* @param name - The element name.
|
|
441
|
+
* @param attributes - Optional attributes object.
|
|
442
|
+
* @param selfClosing - Whether to create a self-closing tag.
|
|
443
|
+
*/
|
|
444
|
+
writeStartElement(name: string, attributes?: Record<string, string>, selfClosing?: boolean): void;
|
|
445
|
+
/**
|
|
446
|
+
* Writes an end element tag.
|
|
447
|
+
* @param name - The element name.
|
|
448
|
+
*/
|
|
449
|
+
writeEndElement(name: string): void;
|
|
450
|
+
/**
|
|
451
|
+
* Writes an element with text content.
|
|
452
|
+
* @param name - The element name.
|
|
453
|
+
* @param attributes - Optional attributes object.
|
|
454
|
+
* @param text - The text content.
|
|
455
|
+
*/
|
|
456
|
+
writeElementWithText(name: string, attributes: Record<string, string> | undefined, text: string): void;
|
|
457
|
+
/**
|
|
458
|
+
* Returns the generated XML string.
|
|
459
|
+
* @returns The complete XML string with line breaks.
|
|
460
|
+
*/
|
|
461
|
+
toString(): string;
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Parses XML string into an XML node structure.
|
|
465
|
+
* This is a lightweight parser optimized for X-API XML structure.
|
|
466
|
+
*
|
|
467
|
+
* @param xml - The XML string to parse.
|
|
468
|
+
* @returns An array of parsed XML nodes.
|
|
469
|
+
*/
|
|
470
|
+
declare function parseXml(xml: string): XmlNode[];
|
|
471
|
+
//#endregion
|
|
472
|
+
//#region src/schema.d.ts
|
|
473
|
+
type XapiTypeMap = {
|
|
474
|
+
STRING: string;
|
|
475
|
+
INT: number;
|
|
476
|
+
FLOAT: number;
|
|
477
|
+
DECIMAL: number;
|
|
478
|
+
BIGDECIMAL: number;
|
|
479
|
+
DATE: Date;
|
|
480
|
+
DATETIME: Date;
|
|
481
|
+
TIME: Date;
|
|
482
|
+
BLOB: Uint8Array;
|
|
483
|
+
};
|
|
484
|
+
interface XapiColumnSchema<T extends ColumnType = ColumnType, Optional extends boolean = boolean> {
|
|
485
|
+
readonly kind: "xapi-column";
|
|
486
|
+
readonly type: T;
|
|
487
|
+
readonly size: number;
|
|
488
|
+
readonly optional: Optional;
|
|
489
|
+
}
|
|
490
|
+
type XapiColumns = Record<string, XapiColumnSchema>;
|
|
491
|
+
interface XapiDatasetSchema<Columns extends XapiColumns = XapiColumns> {
|
|
492
|
+
readonly kind: "xapi-dataset";
|
|
493
|
+
readonly columns: Columns;
|
|
494
|
+
}
|
|
495
|
+
type XapiDatasets = Record<string, XapiDatasetSchema>;
|
|
496
|
+
interface XapiRootSchema<Datasets extends XapiDatasets = XapiDatasets, Parameters extends XapiColumns = XapiColumns> {
|
|
497
|
+
readonly kind: "xapi-root";
|
|
498
|
+
readonly datasets: Datasets;
|
|
499
|
+
readonly parameters: Parameters;
|
|
500
|
+
}
|
|
501
|
+
interface XapiOperation<Request extends XapiRootSchema = XapiRootSchema, Response extends XapiRootSchema = XapiRootSchema> {
|
|
502
|
+
readonly kind: "xapi-operation";
|
|
503
|
+
readonly request: Request;
|
|
504
|
+
readonly response: Response;
|
|
505
|
+
}
|
|
506
|
+
type RequiredColumnKeys<Columns extends XapiColumns> = { [Key in keyof Columns]-?: Columns[Key]["optional"] extends true ? never : Key; }[keyof Columns];
|
|
507
|
+
type OptionalColumnKeys<Columns extends XapiColumns> = { [Key in keyof Columns]-?: Columns[Key]["optional"] extends true ? Key : never; }[keyof Columns];
|
|
508
|
+
type InferColumns<Columns extends XapiColumns> = { [Key in RequiredColumnKeys<Columns>]: XapiTypeMap[Columns[Key]["type"]]; } & { [Key in OptionalColumnKeys<Columns>]?: XapiTypeMap[Columns[Key]["type"]]; };
|
|
509
|
+
type InferDataset<Schema extends XapiDatasetSchema> = InferColumns<Schema["columns"]>[];
|
|
510
|
+
type InferRoot<Schema extends XapiRootSchema> = {
|
|
511
|
+
parameters: InferColumns<Schema["parameters"]>;
|
|
512
|
+
datasets: { [Key in keyof Schema["datasets"]]: InferDataset<Schema["datasets"][Key]>; };
|
|
513
|
+
};
|
|
514
|
+
type RequestOf<Operation extends XapiOperation> = InferRoot<Operation["request"]>;
|
|
515
|
+
type ResponseOf<Operation extends XapiOperation> = InferRoot<Operation["response"]>;
|
|
516
|
+
type ColumnOptions<Optional extends boolean> = {
|
|
517
|
+
size?: number;
|
|
518
|
+
optional?: Optional;
|
|
519
|
+
};
|
|
520
|
+
declare function defineDataset<const Columns extends XapiColumns>(columns: Columns): XapiDatasetSchema<Columns>;
|
|
521
|
+
declare function defineRoot<const Datasets extends XapiDatasets, const Parameters extends XapiColumns = Record<never, never>>(definition: {
|
|
522
|
+
datasets: Datasets;
|
|
523
|
+
parameters?: Parameters;
|
|
524
|
+
}): XapiRootSchema<Datasets, Parameters>;
|
|
525
|
+
declare function defineOperation<const Request extends XapiRootSchema, const Response extends XapiRootSchema>(definition: {
|
|
526
|
+
request: Request;
|
|
527
|
+
response: Response;
|
|
528
|
+
}): XapiOperation<Request, Response>;
|
|
529
|
+
declare const xapi: {
|
|
530
|
+
readonly string: <const Optional extends boolean = false>(options?: ColumnOptions<Optional>) => XapiColumnSchema<"STRING", Optional>;
|
|
531
|
+
readonly int: <const Optional extends boolean = false>(options?: ColumnOptions<Optional>) => XapiColumnSchema<"INT", Optional>;
|
|
532
|
+
readonly float: <const Optional extends boolean = false>(options?: ColumnOptions<Optional>) => XapiColumnSchema<"FLOAT", Optional>;
|
|
533
|
+
readonly decimal: <const Optional extends boolean = false>(options?: ColumnOptions<Optional>) => XapiColumnSchema<"DECIMAL", Optional>;
|
|
534
|
+
readonly bigdecimal: <const Optional extends boolean = false>(options?: ColumnOptions<Optional>) => XapiColumnSchema<"BIGDECIMAL", Optional>;
|
|
535
|
+
readonly date: <const Optional extends boolean = false>(options?: ColumnOptions<Optional>) => XapiColumnSchema<"DATE", Optional>;
|
|
536
|
+
readonly datetime: <const Optional extends boolean = false>(options?: ColumnOptions<Optional>) => XapiColumnSchema<"DATETIME", Optional>;
|
|
537
|
+
readonly time: <const Optional extends boolean = false>(options?: ColumnOptions<Optional>) => XapiColumnSchema<"TIME", Optional>;
|
|
538
|
+
readonly blob: <const Optional extends boolean = false>(options?: ColumnOptions<Optional>) => XapiColumnSchema<"BLOB", Optional>;
|
|
539
|
+
readonly dataset: typeof defineDataset;
|
|
540
|
+
readonly root: typeof defineRoot;
|
|
541
|
+
readonly operation: typeof defineOperation;
|
|
542
|
+
};
|
|
543
|
+
declare function encodeRoot<Schema extends XapiRootSchema>(schema: Schema, value: InferRoot<Schema>): XapiRoot;
|
|
544
|
+
declare function decodeRoot<Schema extends XapiRootSchema>(schema: Schema, root: XapiRoot): InferRoot<Schema>;
|
|
411
545
|
//#endregion
|
|
412
|
-
export { Col, Column, ColumnInfo, ColumnType, ColumnTypeError, ConstColumn, Dataset, InvalidXmlError, NexaVersion, Parameter, Row, RowType, Rows, StringWritableStream, XapiOptions, XapiParameters, XapiRoot, XapiValueType, XapiVersion, XplatformVersion, _unescapeXml, arrayBufferToString, base64ToUint8Array, columnType, convertToColumnType, convertToString, dateToString, initXapi, isXapiRoot, makeParseEntities,
|
|
546
|
+
export { Col, Column, ColumnInfo, ColumnType, ColumnTypeError, ConstColumn, Dataset, InferColumns, InferDataset, InferRoot, InvalidXmlError, NexaVersion, Parameter, RequestOf, ResponseOf, Row, RowType, Rows, StringWritableStream, XapiColumnSchema, XapiColumns, XapiDatasetSchema, XapiDatasets, XapiOperation, XapiOptions, XapiParameters, XapiRoot, XapiRootSchema, XapiTypeMap, XapiValueType, XapiVersion, XmlNode, XmlStringBuilder, XplatformVersion, _unescapeXml, arrayBufferToString, base64ToUint8Array, columnType, convertToColumnType, convertToString, dateToString, decodeRoot, defineDataset, defineOperation, defineRoot, encodeControlChars, encodeRoot, escapeXml, initXapi, isXapiRoot, makeParseEntities, parse, parseXml, rowType, stringToDate, stringToReadableStream, uint8ArrayToBase64, write, xapi };
|