@amazon/vinyl-xml 1.0.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/dist/index.cjs +976 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.js +986 -0
- package/dist/index.js.map +7 -0
- package/dist/types/current/index.d.ts +14 -0
- package/dist/types/current/index.d.ts.map +1 -0
- package/dist/types/current/index.js +13 -0
- package/dist/types/current/tsconfig.tsbuildinfo +1 -0
- package/dist/types/current/xlink/actuateValidator.d.ts +3 -0
- package/dist/types/current/xlink/actuateValidator.d.ts.map +1 -0
- package/dist/types/current/xlink/actuateValidator.js +11 -0
- package/dist/types/current/xml/ParseXmlHandler.d.ts +56 -0
- package/dist/types/current/xml/ParseXmlHandler.d.ts.map +1 -0
- package/dist/types/current/xml/ParseXmlHandler.js +5 -0
- package/dist/types/current/xml/ParseXmlHandlerImpl.d.ts +49 -0
- package/dist/types/current/xml/ParseXmlHandlerImpl.d.ts.map +1 -0
- package/dist/types/current/xml/ParseXmlHandlerImpl.js +198 -0
- package/dist/types/current/xml/QName.d.ts +33 -0
- package/dist/types/current/xml/QName.d.ts.map +1 -0
- package/dist/types/current/xml/QName.js +19 -0
- package/dist/types/current/xml/XmlSchemaError.d.ts +15 -0
- package/dist/types/current/xml/XmlSchemaError.d.ts.map +1 -0
- package/dist/types/current/xml/XmlSchemaError.js +23 -0
- package/dist/types/current/xml/mappedXmlRules.d.ts +118 -0
- package/dist/types/current/xml/mappedXmlRules.d.ts.map +1 -0
- package/dist/types/current/xml/mappedXmlRules.js +122 -0
- package/dist/types/current/xml/mergeXmlRules.d.ts +62 -0
- package/dist/types/current/xml/mergeXmlRules.d.ts.map +1 -0
- package/dist/types/current/xml/mergeXmlRules.js +89 -0
- package/dist/types/current/xml/parseXml.d.ts +76 -0
- package/dist/types/current/xml/parseXml.d.ts.map +1 -0
- package/dist/types/current/xml/parseXml.js +305 -0
- package/dist/types/current/xml/stringifyXml.d.ts +67 -0
- package/dist/types/current/xml/stringifyXml.d.ts.map +1 -0
- package/dist/types/current/xml/stringifyXml.js +225 -0
- package/dist/types/current/xml/xmlRules.d.ts +207 -0
- package/dist/types/current/xml/xmlRules.d.ts.map +1 -0
- package/dist/types/current/xml/xmlRules.js +134 -0
- package/dist/types/current/xmlns/org/w3/1999/xlink.d.ts +7 -0
- package/dist/types/current/xmlns/org/w3/1999/xlink.d.ts.map +1 -0
- package/dist/types/current/xmlns/org/w3/1999/xlink.js +5 -0
- package/dist/types/current/xmlns/org/w3/2001/XmlSchema.d.ts +17 -0
- package/dist/types/current/xmlns/org/w3/2001/XmlSchema.d.ts.map +1 -0
- package/dist/types/current/xmlns/org/w3/2001/XmlSchema.js +5 -0
- package/dist/types/ts3.7/index.d.ts +14 -0
- package/dist/types/ts3.7/xlink/actuateValidator.d.ts +3 -0
- package/dist/types/ts3.7/xml/ParseXmlHandler.d.ts +56 -0
- package/dist/types/ts3.7/xml/ParseXmlHandlerImpl.d.ts +49 -0
- package/dist/types/ts3.7/xml/QName.d.ts +33 -0
- package/dist/types/ts3.7/xml/XmlSchemaError.d.ts +15 -0
- package/dist/types/ts3.7/xml/mappedXmlRules.d.ts +118 -0
- package/dist/types/ts3.7/xml/mergeXmlRules.d.ts +118 -0
- package/dist/types/ts3.7/xml/parseXml.d.ts +76 -0
- package/dist/types/ts3.7/xml/stringifyXml.d.ts +67 -0
- package/dist/types/ts3.7/xml/xmlRules.d.ts +207 -0
- package/dist/types/ts3.7/xmlns/org/w3/1999/xlink.d.ts +7 -0
- package/dist/types/ts3.7/xmlns/org/w3/2001/XmlSchema.d.ts +17 -0
- package/dist/types/ts4.1/index.d.ts +14 -0
- package/dist/types/ts4.1/xlink/actuateValidator.d.ts +3 -0
- package/dist/types/ts4.1/xml/ParseXmlHandler.d.ts +56 -0
- package/dist/types/ts4.1/xml/ParseXmlHandlerImpl.d.ts +49 -0
- package/dist/types/ts4.1/xml/QName.d.ts +33 -0
- package/dist/types/ts4.1/xml/XmlSchemaError.d.ts +15 -0
- package/dist/types/ts4.1/xml/mappedXmlRules.d.ts +118 -0
- package/dist/types/ts4.1/xml/mergeXmlRules.d.ts +118 -0
- package/dist/types/ts4.1/xml/parseXml.d.ts +77 -0
- package/dist/types/ts4.1/xml/stringifyXml.d.ts +67 -0
- package/dist/types/ts4.1/xml/xmlRules.d.ts +207 -0
- package/dist/types/ts4.1/xmlns/org/w3/1999/xlink.d.ts +7 -0
- package/dist/types/ts4.1/xmlns/org/w3/2001/XmlSchema.d.ts +17 -0
- package/dist/types/ts4.7/index.d.ts +14 -0
- package/dist/types/ts4.7/xlink/actuateValidator.d.ts +3 -0
- package/dist/types/ts4.7/xml/ParseXmlHandler.d.ts +56 -0
- package/dist/types/ts4.7/xml/ParseXmlHandlerImpl.d.ts +49 -0
- package/dist/types/ts4.7/xml/QName.d.ts +33 -0
- package/dist/types/ts4.7/xml/XmlSchemaError.d.ts +15 -0
- package/dist/types/ts4.7/xml/mappedXmlRules.d.ts +118 -0
- package/dist/types/ts4.7/xml/mergeXmlRules.d.ts +118 -0
- package/dist/types/ts4.7/xml/parseXml.d.ts +76 -0
- package/dist/types/ts4.7/xml/stringifyXml.d.ts +67 -0
- package/dist/types/ts4.7/xml/xmlRules.d.ts +207 -0
- package/dist/types/ts4.7/xmlns/org/w3/1999/xlink.d.ts +7 -0
- package/dist/types/ts4.7/xmlns/org/w3/2001/XmlSchema.d.ts +17 -0
- package/docs/XML_PARSING.md +210 -0
- package/package.json +82 -0
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { type Fun } from '@amazon/vinyl-util';
|
|
2
|
+
import { type XmlRules } from '../xml/xmlRules';
|
|
3
|
+
/**
|
|
4
|
+
* Recursively merges array types so that S[] & T[] becomes (S & T)[]
|
|
5
|
+
* When two array elements parsing rules are merged, the result is an array with intersected
|
|
6
|
+
* element types.
|
|
7
|
+
*/
|
|
8
|
+
export type Merged<T> = T extends readonly any[] ? MergedTupleOrArray<T> : T extends Fun ? T : T extends object ? {
|
|
9
|
+
[P in keyof T]: Merged<T[P]>;
|
|
10
|
+
} : T;
|
|
11
|
+
/**
|
|
12
|
+
* `[S0, T0] & [S1, T1]` cannot be converted to `[S0 & S1, T0 & T1]`, but we can at least preserve
|
|
13
|
+
* the tuple when not intersected.
|
|
14
|
+
*
|
|
15
|
+
* Intersected tuples become arrays. E.g. `[S0, T0] & [S1, T1]` becomes `Array<S0 | S1 | T0 | T1>`
|
|
16
|
+
*/
|
|
17
|
+
export type MergedTupleOrArray<T extends readonly any[]> = T extends [
|
|
18
|
+
infer V0
|
|
19
|
+
] ? [
|
|
20
|
+
Merged<V0>
|
|
21
|
+
] : T extends [
|
|
22
|
+
infer V0,
|
|
23
|
+
infer V1
|
|
24
|
+
] ? [
|
|
25
|
+
Merged<V0>,
|
|
26
|
+
Merged<V1>
|
|
27
|
+
] : T extends [
|
|
28
|
+
infer V0,
|
|
29
|
+
infer V1,
|
|
30
|
+
infer V2
|
|
31
|
+
] ? [
|
|
32
|
+
Merged<V0>,
|
|
33
|
+
Merged<V1>,
|
|
34
|
+
Merged<V2>
|
|
35
|
+
] : T extends [
|
|
36
|
+
infer V0,
|
|
37
|
+
infer V1,
|
|
38
|
+
infer V2,
|
|
39
|
+
infer V3
|
|
40
|
+
] ? [
|
|
41
|
+
Merged<V0>,
|
|
42
|
+
Merged<V1>,
|
|
43
|
+
Merged<V2>,
|
|
44
|
+
Merged<V3>
|
|
45
|
+
] : T extends [
|
|
46
|
+
infer V0,
|
|
47
|
+
infer V1,
|
|
48
|
+
infer V2,
|
|
49
|
+
infer V3,
|
|
50
|
+
infer V4
|
|
51
|
+
] ? [
|
|
52
|
+
Merged<V0>,
|
|
53
|
+
Merged<V1>,
|
|
54
|
+
Merged<V2>,
|
|
55
|
+
Merged<V3>,
|
|
56
|
+
Merged<V4>
|
|
57
|
+
] : T extends any[] ? Array<Merged<T[number]>> : T extends readonly [
|
|
58
|
+
infer V0
|
|
59
|
+
] ? readonly [
|
|
60
|
+
Merged<V0>
|
|
61
|
+
] : T extends readonly [
|
|
62
|
+
infer V0,
|
|
63
|
+
infer V1
|
|
64
|
+
] ? readonly [
|
|
65
|
+
Merged<V0>,
|
|
66
|
+
Merged<V1>
|
|
67
|
+
] : T extends readonly [
|
|
68
|
+
infer V0,
|
|
69
|
+
infer V1,
|
|
70
|
+
infer V2
|
|
71
|
+
] ? readonly [
|
|
72
|
+
Merged<V0>,
|
|
73
|
+
Merged<V1>,
|
|
74
|
+
Merged<V2>
|
|
75
|
+
] : T extends readonly [
|
|
76
|
+
infer V0,
|
|
77
|
+
infer V1,
|
|
78
|
+
infer V2,
|
|
79
|
+
infer V3
|
|
80
|
+
] ? readonly [
|
|
81
|
+
Merged<V0>,
|
|
82
|
+
Merged<V1>,
|
|
83
|
+
Merged<V2>,
|
|
84
|
+
Merged<V3>
|
|
85
|
+
] : T extends readonly [
|
|
86
|
+
infer V0,
|
|
87
|
+
infer V1,
|
|
88
|
+
infer V2,
|
|
89
|
+
infer V3,
|
|
90
|
+
infer V4
|
|
91
|
+
] ? readonly [
|
|
92
|
+
Merged<V0>,
|
|
93
|
+
Merged<V1>,
|
|
94
|
+
Merged<V2>,
|
|
95
|
+
Merged<V3>,
|
|
96
|
+
Merged<V4>
|
|
97
|
+
] : ReadonlyArray<Merged<T[number]>>;
|
|
98
|
+
/**
|
|
99
|
+
* Merges the given two xml rule sets into one.
|
|
100
|
+
*/
|
|
101
|
+
export declare function mergeXmlRules<A extends object, B extends object>(a: XmlRules<A>, b: XmlRules<B>): XmlRules<Merged<A & B>>;
|
|
102
|
+
/**
|
|
103
|
+
* Merges the given three xml rule sets into one.
|
|
104
|
+
*/
|
|
105
|
+
export declare function mergeXmlRules<A extends object, B extends object, C extends object>(a: XmlRules<A>, b: XmlRules<B>, c: XmlRules<C>): XmlRules<Merged<A & B & C>>;
|
|
106
|
+
/**
|
|
107
|
+
* Merges the given four xml rule sets into one.
|
|
108
|
+
*/
|
|
109
|
+
export declare function mergeXmlRules<A extends object, B extends object, C extends object, D extends object>(a: XmlRules<A>, b: XmlRules<B>, c: XmlRules<C>, d: XmlRules<D>): XmlRules<Merged<A & B & C & D>>;
|
|
110
|
+
/**
|
|
111
|
+
* Merges the given five xml rule sets into one.
|
|
112
|
+
*/
|
|
113
|
+
export declare function mergeXmlRules<A extends object, B extends object, C extends object, D extends object, E extends object>(a: XmlRules<A>, b: XmlRules<B>, c: XmlRules<C>, d: XmlRules<D>, e: XmlRules<E>): XmlRules<Merged<A & B & C & D & E>>;
|
|
114
|
+
/**
|
|
115
|
+
* Merges the given six xml rule sets into one.
|
|
116
|
+
*/
|
|
117
|
+
export declare function mergeXmlRules<A extends object, B extends object, C extends object, D extends object, E extends object, F extends object>(a: XmlRules<A>, b: XmlRules<B>, c: XmlRules<C>, d: XmlRules<D>, e: XmlRules<E>, f: XmlRules<F>): XmlRules<Merged<A & B & C & D & E & F>>;
|
|
118
|
+
//# sourceMappingURL=mergeXmlRules.d.ts.map
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type MutableDeep, StringReader } from '@amazon/vinyl-util';
|
|
2
|
+
import type { Uri } from '../xmlns/org/w3/2001/XmlSchema';
|
|
3
|
+
import type { Attributes, ParseXmlHandler } from './ParseXmlHandler';
|
|
4
|
+
import type { QName } from './QName';
|
|
5
|
+
import type { XmlElement } from './ParseXmlHandlerImpl';
|
|
6
|
+
export declare const XMLNS = "http://www.w3.org/2000/xmlns/";
|
|
7
|
+
/**
|
|
8
|
+
* Nested xml elements push current namespace information onto a stack.
|
|
9
|
+
*
|
|
10
|
+
* @private
|
|
11
|
+
*/
|
|
12
|
+
export interface StackElement {
|
|
13
|
+
/**
|
|
14
|
+
* The qualified name of the current element on the stack. Used to validate expected closing
|
|
15
|
+
* element.
|
|
16
|
+
*/
|
|
17
|
+
readonly qName: string;
|
|
18
|
+
/**
|
|
19
|
+
* The (mutable) namespaces map for the current stack.
|
|
20
|
+
*/
|
|
21
|
+
readonly namespaceMap: Namespaces;
|
|
22
|
+
/**
|
|
23
|
+
* The default namespace.
|
|
24
|
+
*/
|
|
25
|
+
defaultNamespaceUri: Uri | null;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Parses an XML document using a partial sax-style content handler.
|
|
29
|
+
* This allows for parsing without the entire document being read into memory first.
|
|
30
|
+
*
|
|
31
|
+
* XML Documents are mapped to data structures through content handlers instead of needing an
|
|
32
|
+
* intermediate model.
|
|
33
|
+
*/
|
|
34
|
+
export declare function parseXml<T>(str: string, handler: ParseXmlHandler<T>): T & XmlElement<T>;
|
|
35
|
+
/**
|
|
36
|
+
* @private
|
|
37
|
+
*/
|
|
38
|
+
export type Namespaces = Map<string, Uri | null>;
|
|
39
|
+
/**
|
|
40
|
+
* Given that the cursor is at a ' or ", reads the sequence of characters until an end quote is
|
|
41
|
+
* reached.
|
|
42
|
+
* The returned unescaped string is the text within the quotes.
|
|
43
|
+
* @private
|
|
44
|
+
*/
|
|
45
|
+
export declare function readAttributeValue(c: StringReader): string;
|
|
46
|
+
/**
|
|
47
|
+
* Reads until the end of the tag >
|
|
48
|
+
* @private
|
|
49
|
+
*/
|
|
50
|
+
export declare function untilTagClose(c: StringReader): void;
|
|
51
|
+
/**
|
|
52
|
+
* Returns true if the char code is a valid xml name character.
|
|
53
|
+
* @see https://www.w3.org/TR/2008/REC-xml-20081126/#NT-NameChar
|
|
54
|
+
* @param charCode
|
|
55
|
+
* @private
|
|
56
|
+
*/
|
|
57
|
+
export declare function isNameChar(charCode: number): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Reads an xml {@link QName}.
|
|
60
|
+
* The {@link QName.namespaceUri} returned will be null; it must be separately looked up.
|
|
61
|
+
*
|
|
62
|
+
* @param reader The current string reader.
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
65
|
+
export declare function readQName(reader: StringReader): MutableDeep<QName>;
|
|
66
|
+
/**
|
|
67
|
+
* Reads a series of xml attributes, separated by whitespace.
|
|
68
|
+
* Example: `ns1:key1="value1" key2 key3='value3'`
|
|
69
|
+
* Note: consumes all whitespace before and after attributes series.
|
|
70
|
+
*
|
|
71
|
+
* @return Returns a map of attribute `qName:string` to `Attribute` objects.
|
|
72
|
+
*
|
|
73
|
+
* @private
|
|
74
|
+
*/
|
|
75
|
+
export declare function xmlAttributes(reader: StringReader, stackElement: StackElement): MutableDeep<Attributes>;
|
|
76
|
+
//# sourceMappingURL=parseXml.d.ts.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type OptionalDeep } from '@amazon/vinyl-util';
|
|
2
|
+
import type { Uri } from '../xmlns/org/w3/2001/XmlSchema';
|
|
3
|
+
import type { MappedXmlRules } from './mappedXmlRules';
|
|
4
|
+
import type { ReservedXmlRuleKeys } from '../xml/xmlRules';
|
|
5
|
+
export interface StringifyOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The indentation. Default: 4 spaces
|
|
8
|
+
*/
|
|
9
|
+
readonly indent: string;
|
|
10
|
+
/**
|
|
11
|
+
* The character(s) between lines. Default: \n
|
|
12
|
+
*/
|
|
13
|
+
readonly newline: string;
|
|
14
|
+
/**
|
|
15
|
+
* A map of namespace uri to prefix strings.
|
|
16
|
+
* If a namespace is not found, a prefix will be generated.
|
|
17
|
+
*/
|
|
18
|
+
readonly prefixMap: ReadonlyMap<Uri, string>;
|
|
19
|
+
/**
|
|
20
|
+
* If true, will include the XML declaration at the beginning of the stringified document.
|
|
21
|
+
* `<?xml version="1.0"?>`
|
|
22
|
+
*/
|
|
23
|
+
readonly includeXmlDeclaration: boolean;
|
|
24
|
+
}
|
|
25
|
+
export declare class XmlWriter<T> {
|
|
26
|
+
private readonly rules;
|
|
27
|
+
private readonly options;
|
|
28
|
+
private readonly usedPrefixes;
|
|
29
|
+
private readonly traversed;
|
|
30
|
+
constructor(rules: MappedXmlRules<T>, options?: Partial<StringifyOptions>);
|
|
31
|
+
stringify(object: OptionalDeep<T, ReservedXmlRuleKeys>): string;
|
|
32
|
+
private qName;
|
|
33
|
+
/**
|
|
34
|
+
* Stringifies an element.
|
|
35
|
+
*
|
|
36
|
+
* @param object
|
|
37
|
+
* @param rule
|
|
38
|
+
* @param state
|
|
39
|
+
*/
|
|
40
|
+
private stringifyElement;
|
|
41
|
+
/**
|
|
42
|
+
* Stringifies an element's attributes.
|
|
43
|
+
*
|
|
44
|
+
* @param object
|
|
45
|
+
* @param attributes
|
|
46
|
+
* @return Returns the attributes string. This will include a leading space if there are any
|
|
47
|
+
* found attributes.
|
|
48
|
+
*/
|
|
49
|
+
private stringifyAttributes;
|
|
50
|
+
/**
|
|
51
|
+
* Stringifies a property as a CDATA node.
|
|
52
|
+
*
|
|
53
|
+
* @param object
|
|
54
|
+
* @param charactersRule
|
|
55
|
+
*/
|
|
56
|
+
private stringifyCharacters;
|
|
57
|
+
/**
|
|
58
|
+
* Stringifies an element's child elements.
|
|
59
|
+
*
|
|
60
|
+
* @param object
|
|
61
|
+
* @param elements
|
|
62
|
+
* @param state
|
|
63
|
+
*/
|
|
64
|
+
private stringifyChildren;
|
|
65
|
+
}
|
|
66
|
+
export declare function stringifyXml<T>(object: OptionalDeep<T, ReservedXmlRuleKeys>, rules: MappedXmlRules<T>, options?: Partial<StringifyOptions>): string;
|
|
67
|
+
//# sourceMappingURL=stringifyXml.d.ts.map
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A set of utilities for easily writing schema-based rule definitions to be used with the
|
|
3
|
+
* `parseXml` parser.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { type Invariant, type Maybe, type ReadonlyDate } from '@amazon/vinyl-util';
|
|
8
|
+
import type { Uri } from '../xmlns/org/w3/2001/XmlSchema';
|
|
9
|
+
export declare enum XmlRuleType {
|
|
10
|
+
CHARACTERS = "characters",
|
|
11
|
+
ATTRIBUTE = "attribute",
|
|
12
|
+
ELEMENT = "element",
|
|
13
|
+
ELEMENTS = "elements"
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Reserved keys that may not be used in XmlRules.
|
|
17
|
+
*
|
|
18
|
+
* If a schema uses a reserved word, set `localPart` in the rule options to associate.
|
|
19
|
+
*/
|
|
20
|
+
export type ReservedXmlRuleKeys = 'parent' | 'clone' | 'toJSON';
|
|
21
|
+
/**
|
|
22
|
+
* A schema for XML serialization and deserialization.
|
|
23
|
+
*
|
|
24
|
+
* The parser values may be lazy, represented as a function that returns a property parser.
|
|
25
|
+
* @typeParam T The object type these parsing rules model.
|
|
26
|
+
*/
|
|
27
|
+
export type XmlRules<T extends object> = {
|
|
28
|
+
readonly [P in Exclude<keyof T, ReservedXmlRuleKeys>]-?: XmlRule<T[P]> | LazyXmlRule<T[P]>;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* A union of the supported parsing types.
|
|
32
|
+
*/
|
|
33
|
+
export type XmlRule<T> = AttributeRule<T> | CharactersRule<T> | ElementsRule<T & (readonly object[] | undefined)> | ElementRule<T & (object | undefined)>;
|
|
34
|
+
/**
|
|
35
|
+
* A function that returns a property handler.
|
|
36
|
+
* Useful when there are recursive rules.
|
|
37
|
+
*/
|
|
38
|
+
export type LazyXmlRule<T> = () => XmlRule<T>;
|
|
39
|
+
export interface NamespacedRuleOptions {
|
|
40
|
+
/**
|
|
41
|
+
* Matches the `QName.localPart` of the element. If undefined, this will match against
|
|
42
|
+
* the property name from {@link XmlRules}.
|
|
43
|
+
*/
|
|
44
|
+
readonly localPart?: string | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Matches the `namespaceUri` of the element or attribute.
|
|
47
|
+
*
|
|
48
|
+
* If null, this will only match against a null namespace.
|
|
49
|
+
* If undefined, this will default to the namespace of the parent element for elements, or
|
|
50
|
+
* null for attributes.
|
|
51
|
+
*
|
|
52
|
+
* Note that attributes do not inherit default namespaces as elements do.
|
|
53
|
+
*/
|
|
54
|
+
readonly namespaceUri?: Maybe<Uri>;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A rule definition for a list of elements.
|
|
58
|
+
*/
|
|
59
|
+
export interface ElementsRule<T extends readonly object[] | undefined> extends Required<ElementsRuleOptions> {
|
|
60
|
+
readonly type: XmlRuleType.ELEMENTS;
|
|
61
|
+
/**
|
|
62
|
+
* Prevents rule from losing nullable type information.
|
|
63
|
+
*/
|
|
64
|
+
readonly __invariant?: Invariant<T>;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the schema for matched elements.
|
|
67
|
+
* These rules will be applied per element, collecting into an array.
|
|
68
|
+
*/
|
|
69
|
+
readonly rules: XmlRules<NonNullable<T>[number]>;
|
|
70
|
+
}
|
|
71
|
+
export interface ElementsRuleOptions extends NamespacedRuleOptions {
|
|
72
|
+
/**
|
|
73
|
+
* The minimum number of elements.
|
|
74
|
+
*/
|
|
75
|
+
readonly minOccurs?: number;
|
|
76
|
+
/**
|
|
77
|
+
* The maximum number of elements. Use null for unbounded.
|
|
78
|
+
*/
|
|
79
|
+
readonly maxOccurs?: number | null;
|
|
80
|
+
/**
|
|
81
|
+
* If true and there are 0 occurrences of the element, the parsed value will be an empty array
|
|
82
|
+
* instead of undefined.
|
|
83
|
+
*/
|
|
84
|
+
readonly useEmptyArrays?: boolean;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* A rule definition for a single element.
|
|
88
|
+
*/
|
|
89
|
+
export interface ElementRule<T extends object | undefined> extends Required<ElementRuleOptions> {
|
|
90
|
+
/**
|
|
91
|
+
* Prevents rule from losing nullable type information.
|
|
92
|
+
*/
|
|
93
|
+
readonly __invariant?: Invariant<T>;
|
|
94
|
+
readonly type: XmlRuleType.ELEMENT;
|
|
95
|
+
/**
|
|
96
|
+
* Returns the schema for the matched element.
|
|
97
|
+
*/
|
|
98
|
+
readonly rules: XmlRules<NonNullable<T>>;
|
|
99
|
+
}
|
|
100
|
+
export interface ElementRuleOptions extends NamespacedRuleOptions {
|
|
101
|
+
/**
|
|
102
|
+
* If true, a parsing error will be thrown if the value is undefined.
|
|
103
|
+
*/
|
|
104
|
+
readonly required?: boolean;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A rule definition for an attribute.
|
|
108
|
+
*/
|
|
109
|
+
export interface AttributeRule<T> extends Required<AttributeRuleOptions<T>> {
|
|
110
|
+
readonly type: XmlRuleType.ATTRIBUTE;
|
|
111
|
+
/**
|
|
112
|
+
* Parses the attribute value.
|
|
113
|
+
*/
|
|
114
|
+
readonly parse: (value: string) => T;
|
|
115
|
+
/**
|
|
116
|
+
* Stringifies the value.
|
|
117
|
+
*/
|
|
118
|
+
readonly stringify: (value: NonNullable<T>) => string;
|
|
119
|
+
}
|
|
120
|
+
export interface AttributeRuleOptions<T> extends NamespacedRuleOptions {
|
|
121
|
+
/**
|
|
122
|
+
* If true, a parsing error will be thrown if the value is undefined.
|
|
123
|
+
*/
|
|
124
|
+
readonly required?: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* If the current element has no matching attribute, default will be used.
|
|
127
|
+
*/
|
|
128
|
+
readonly default?: T | undefined;
|
|
129
|
+
/**
|
|
130
|
+
* Matches the `namespaceUri` of the attribute.
|
|
131
|
+
*
|
|
132
|
+
* If null, this will only match against a null namespace.
|
|
133
|
+
*
|
|
134
|
+
* Note that attributes do not inherit default namespaces as elements do.
|
|
135
|
+
*/
|
|
136
|
+
readonly namespaceUri?: Uri | null;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* A rule definition for an element's text content.
|
|
140
|
+
*/
|
|
141
|
+
export interface CharactersRule<T> {
|
|
142
|
+
readonly type: XmlRuleType.CHARACTERS;
|
|
143
|
+
/**
|
|
144
|
+
* Parses the unescaped/processed characters.
|
|
145
|
+
* This will always be called, but characters may be an empty string if the element has no
|
|
146
|
+
* text content.
|
|
147
|
+
*/
|
|
148
|
+
readonly parse: (characters: string) => T;
|
|
149
|
+
/**
|
|
150
|
+
* Stringifies the value.
|
|
151
|
+
*/
|
|
152
|
+
readonly stringify: (value: NonNullable<T>) => string;
|
|
153
|
+
}
|
|
154
|
+
export interface RequiredElementRuleOptions extends ElementRuleOptions {
|
|
155
|
+
readonly required: true;
|
|
156
|
+
}
|
|
157
|
+
export declare function element<T extends object>(rules: XmlRules<T>, options: RequiredElementRuleOptions): ElementRule<T>;
|
|
158
|
+
export declare function element<T extends object | undefined>(rules: XmlRules<NonNullable<T>>, options?: ElementRuleOptions): ElementRule<T | undefined>;
|
|
159
|
+
/**
|
|
160
|
+
* Elements options that guarantee that there is a non-null array.
|
|
161
|
+
* For minOccurs types greater than 10, a type cast is required.
|
|
162
|
+
*/
|
|
163
|
+
export type RequiredElementsOptions = (ElementsRuleOptions & {
|
|
164
|
+
readonly useEmptyArrays: true;
|
|
165
|
+
}) | (ElementsRuleOptions & {
|
|
166
|
+
readonly minOccurs: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
|
|
167
|
+
});
|
|
168
|
+
export declare function elements<T extends object>(rules: XmlRules<T>, options: RequiredElementsOptions): ElementsRule<readonly T[]>;
|
|
169
|
+
export declare function elements<T extends object>(rules: XmlRules<T>, options?: ElementsRuleOptions): ElementsRule<readonly T[] | undefined>;
|
|
170
|
+
/**
|
|
171
|
+
* Parses the text content of the current element via the given parse and stringify functions.
|
|
172
|
+
*
|
|
173
|
+
* Does not currently support mixing text and element nodes.
|
|
174
|
+
* E.g. the XML `<note>Dear <name>John</name>, I regret to inform you...</note>` could not be
|
|
175
|
+
* serialized or deserialized using xml rule mappings.
|
|
176
|
+
*
|
|
177
|
+
* @param parse The string passed to this parser is the processed text content of the current
|
|
178
|
+
* element.
|
|
179
|
+
* @param stringify Serializes the value.
|
|
180
|
+
*
|
|
181
|
+
* @see processCharacters
|
|
182
|
+
*/
|
|
183
|
+
export declare function characters<T>(parse: (str: string) => T, stringify: (value: T) => string): CharactersRule<T>;
|
|
184
|
+
/**
|
|
185
|
+
* Handles the processed text content without any modification.
|
|
186
|
+
*
|
|
187
|
+
* @see characters
|
|
188
|
+
*/
|
|
189
|
+
export declare const charactersString: CharactersRule<string>;
|
|
190
|
+
export type RequiredAttributeOptions<T> = AttributeRuleOptions<T> & ({
|
|
191
|
+
required: true;
|
|
192
|
+
} | {
|
|
193
|
+
default: T;
|
|
194
|
+
});
|
|
195
|
+
export declare function attr<T>(parse: (value: string) => T, stringify: (value: T) => string, options: RequiredAttributeOptions<T>): AttributeRule<T>;
|
|
196
|
+
export declare function attr<T>(parse: (value: string) => T, stringify: (value: NonNullable<T>) => string, options?: AttributeRuleOptions<T>): AttributeRule<T | undefined>;
|
|
197
|
+
export declare function attrString(options: RequiredAttributeOptions<string>): AttributeRule<string>;
|
|
198
|
+
export declare function attrString(options?: AttributeRuleOptions<string>): AttributeRule<string | undefined>;
|
|
199
|
+
export declare function attrInt(options: RequiredAttributeOptions<number>): AttributeRule<number>;
|
|
200
|
+
export declare function attrInt(options?: AttributeRuleOptions<number>): AttributeRule<number | undefined>;
|
|
201
|
+
export declare function attrFloat(options: RequiredAttributeOptions<number>): AttributeRule<number>;
|
|
202
|
+
export declare function attrFloat(options?: AttributeRuleOptions<number>): AttributeRule<number | undefined>;
|
|
203
|
+
export declare function attrBoolean(options: RequiredAttributeOptions<boolean>): AttributeRule<boolean>;
|
|
204
|
+
export declare function attrBoolean(options?: AttributeRuleOptions<boolean>): AttributeRule<boolean | undefined>;
|
|
205
|
+
export declare function attrDateTime(options: RequiredAttributeOptions<Date>): AttributeRule<ReadonlyDate>;
|
|
206
|
+
export declare function attrDateTime(options?: AttributeRuleOptions<ReadonlyDate>): AttributeRule<ReadonlyDate | undefined>;
|
|
207
|
+
//# sourceMappingURL=xmlRules.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A subset of types defined in 2001 XmlSchema needed for dash parsing.
|
|
3
|
+
* Source: https://www.w3.org/2001/XmlSchema.xsd
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* A Uniform Resource Identifier Reference
|
|
9
|
+
*/
|
|
10
|
+
export type Uri = string;
|
|
11
|
+
export interface Base64BinaryType {
|
|
12
|
+
_content: string;
|
|
13
|
+
}
|
|
14
|
+
export interface UriType {
|
|
15
|
+
_content: Uri;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=XmlSchema.d.ts.map
|