@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.
Files changed (85) hide show
  1. package/dist/index.cjs +976 -0
  2. package/dist/index.cjs.map +7 -0
  3. package/dist/index.js +986 -0
  4. package/dist/index.js.map +7 -0
  5. package/dist/types/current/index.d.ts +14 -0
  6. package/dist/types/current/index.d.ts.map +1 -0
  7. package/dist/types/current/index.js +13 -0
  8. package/dist/types/current/tsconfig.tsbuildinfo +1 -0
  9. package/dist/types/current/xlink/actuateValidator.d.ts +3 -0
  10. package/dist/types/current/xlink/actuateValidator.d.ts.map +1 -0
  11. package/dist/types/current/xlink/actuateValidator.js +11 -0
  12. package/dist/types/current/xml/ParseXmlHandler.d.ts +56 -0
  13. package/dist/types/current/xml/ParseXmlHandler.d.ts.map +1 -0
  14. package/dist/types/current/xml/ParseXmlHandler.js +5 -0
  15. package/dist/types/current/xml/ParseXmlHandlerImpl.d.ts +49 -0
  16. package/dist/types/current/xml/ParseXmlHandlerImpl.d.ts.map +1 -0
  17. package/dist/types/current/xml/ParseXmlHandlerImpl.js +198 -0
  18. package/dist/types/current/xml/QName.d.ts +33 -0
  19. package/dist/types/current/xml/QName.d.ts.map +1 -0
  20. package/dist/types/current/xml/QName.js +19 -0
  21. package/dist/types/current/xml/XmlSchemaError.d.ts +15 -0
  22. package/dist/types/current/xml/XmlSchemaError.d.ts.map +1 -0
  23. package/dist/types/current/xml/XmlSchemaError.js +23 -0
  24. package/dist/types/current/xml/mappedXmlRules.d.ts +118 -0
  25. package/dist/types/current/xml/mappedXmlRules.d.ts.map +1 -0
  26. package/dist/types/current/xml/mappedXmlRules.js +122 -0
  27. package/dist/types/current/xml/mergeXmlRules.d.ts +62 -0
  28. package/dist/types/current/xml/mergeXmlRules.d.ts.map +1 -0
  29. package/dist/types/current/xml/mergeXmlRules.js +89 -0
  30. package/dist/types/current/xml/parseXml.d.ts +76 -0
  31. package/dist/types/current/xml/parseXml.d.ts.map +1 -0
  32. package/dist/types/current/xml/parseXml.js +305 -0
  33. package/dist/types/current/xml/stringifyXml.d.ts +67 -0
  34. package/dist/types/current/xml/stringifyXml.d.ts.map +1 -0
  35. package/dist/types/current/xml/stringifyXml.js +225 -0
  36. package/dist/types/current/xml/xmlRules.d.ts +207 -0
  37. package/dist/types/current/xml/xmlRules.d.ts.map +1 -0
  38. package/dist/types/current/xml/xmlRules.js +134 -0
  39. package/dist/types/current/xmlns/org/w3/1999/xlink.d.ts +7 -0
  40. package/dist/types/current/xmlns/org/w3/1999/xlink.d.ts.map +1 -0
  41. package/dist/types/current/xmlns/org/w3/1999/xlink.js +5 -0
  42. package/dist/types/current/xmlns/org/w3/2001/XmlSchema.d.ts +17 -0
  43. package/dist/types/current/xmlns/org/w3/2001/XmlSchema.d.ts.map +1 -0
  44. package/dist/types/current/xmlns/org/w3/2001/XmlSchema.js +5 -0
  45. package/dist/types/ts3.7/index.d.ts +14 -0
  46. package/dist/types/ts3.7/xlink/actuateValidator.d.ts +3 -0
  47. package/dist/types/ts3.7/xml/ParseXmlHandler.d.ts +56 -0
  48. package/dist/types/ts3.7/xml/ParseXmlHandlerImpl.d.ts +49 -0
  49. package/dist/types/ts3.7/xml/QName.d.ts +33 -0
  50. package/dist/types/ts3.7/xml/XmlSchemaError.d.ts +15 -0
  51. package/dist/types/ts3.7/xml/mappedXmlRules.d.ts +118 -0
  52. package/dist/types/ts3.7/xml/mergeXmlRules.d.ts +118 -0
  53. package/dist/types/ts3.7/xml/parseXml.d.ts +76 -0
  54. package/dist/types/ts3.7/xml/stringifyXml.d.ts +67 -0
  55. package/dist/types/ts3.7/xml/xmlRules.d.ts +207 -0
  56. package/dist/types/ts3.7/xmlns/org/w3/1999/xlink.d.ts +7 -0
  57. package/dist/types/ts3.7/xmlns/org/w3/2001/XmlSchema.d.ts +17 -0
  58. package/dist/types/ts4.1/index.d.ts +14 -0
  59. package/dist/types/ts4.1/xlink/actuateValidator.d.ts +3 -0
  60. package/dist/types/ts4.1/xml/ParseXmlHandler.d.ts +56 -0
  61. package/dist/types/ts4.1/xml/ParseXmlHandlerImpl.d.ts +49 -0
  62. package/dist/types/ts4.1/xml/QName.d.ts +33 -0
  63. package/dist/types/ts4.1/xml/XmlSchemaError.d.ts +15 -0
  64. package/dist/types/ts4.1/xml/mappedXmlRules.d.ts +118 -0
  65. package/dist/types/ts4.1/xml/mergeXmlRules.d.ts +118 -0
  66. package/dist/types/ts4.1/xml/parseXml.d.ts +77 -0
  67. package/dist/types/ts4.1/xml/stringifyXml.d.ts +67 -0
  68. package/dist/types/ts4.1/xml/xmlRules.d.ts +207 -0
  69. package/dist/types/ts4.1/xmlns/org/w3/1999/xlink.d.ts +7 -0
  70. package/dist/types/ts4.1/xmlns/org/w3/2001/XmlSchema.d.ts +17 -0
  71. package/dist/types/ts4.7/index.d.ts +14 -0
  72. package/dist/types/ts4.7/xlink/actuateValidator.d.ts +3 -0
  73. package/dist/types/ts4.7/xml/ParseXmlHandler.d.ts +56 -0
  74. package/dist/types/ts4.7/xml/ParseXmlHandlerImpl.d.ts +49 -0
  75. package/dist/types/ts4.7/xml/QName.d.ts +33 -0
  76. package/dist/types/ts4.7/xml/XmlSchemaError.d.ts +15 -0
  77. package/dist/types/ts4.7/xml/mappedXmlRules.d.ts +118 -0
  78. package/dist/types/ts4.7/xml/mergeXmlRules.d.ts +118 -0
  79. package/dist/types/ts4.7/xml/parseXml.d.ts +76 -0
  80. package/dist/types/ts4.7/xml/stringifyXml.d.ts +67 -0
  81. package/dist/types/ts4.7/xml/xmlRules.d.ts +207 -0
  82. package/dist/types/ts4.7/xmlns/org/w3/1999/xlink.d.ts +7 -0
  83. package/dist/types/ts4.7/xmlns/org/w3/2001/XmlSchema.d.ts +17 -0
  84. package/docs/XML_PARSING.md +210 -0
  85. package/package.json +82 -0
@@ -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 { Invariant, Maybe, ReadonlyDate } from '@amazon/vinyl-util';
8
+ import { 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,7 @@
1
+ /**
2
+ * A subset of types defined in xlink xml schema needed for dash parsing.
3
+ * Source: https://www.w3.org/TR/xlink/
4
+ * @module
5
+ */
6
+ export type actuateType = 'onLoad' | 'onRequest';
7
+ //# sourceMappingURL=xlink.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
@@ -0,0 +1,14 @@
1
+ /** Auto-generated from build scripts */
2
+ export * from './xmlns/org/w3/2001/XmlSchema';
3
+ export * from './xmlns/org/w3/1999/xlink';
4
+ export * from './xml/xmlRules';
5
+ export * from './xml/stringifyXml';
6
+ export * from './xml/parseXml';
7
+ export * from './xml/mergeXmlRules';
8
+ export * from './xml/mappedXmlRules';
9
+ export * from './xml/XmlSchemaError';
10
+ export * from './xml/QName';
11
+ export * from './xml/ParseXmlHandlerImpl';
12
+ export * from './xml/ParseXmlHandler';
13
+ export * from './xlink/actuateValidator';
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,3 @@
1
+ import type { actuateType } from '../xmlns/org/w3/1999/xlink';
2
+ export declare function assertActuateEnum(str: string): actuateType;
3
+ //# sourceMappingURL=actuateValidator.d.ts.map
@@ -0,0 +1,56 @@
1
+ import type { QName } from './QName';
2
+ import type { XmlElement } from '../xml/ParseXmlHandlerImpl';
3
+ /**
4
+ * A handler for XML deserialization.
5
+ */
6
+ export interface ParseXmlHandler<T> {
7
+ /**
8
+ * A new document has begun.
9
+ */
10
+ startDocument(): void;
11
+ /**
12
+ * A document has completed parsing, the final object is ready.
13
+ */
14
+ endDocument(): T & XmlElement<T>;
15
+ /**
16
+ * Invoked when a new element has been started, after the element's attributes have been read.
17
+ *
18
+ * @param name An object representing the element's name and namespace.
19
+ * @param attributes The attributes associated with the currently opening element.
20
+ */
21
+ startElement(name: QName, attributes: Attributes): void;
22
+ /**
23
+ * Invoked after an element closing tag.
24
+ */
25
+ endElement(): void;
26
+ /**
27
+ * Provides a raw substring as a text node. The given text is expected to be decoded using
28
+ * `decodeEntities`.
29
+ *
30
+ * @param str
31
+ */
32
+ textNode(str: string): void;
33
+ /**
34
+ * Provides a raw substring as a cdata node. This text is _not_ expected to be decoded.
35
+ *
36
+ * @param str
37
+ */
38
+ cDataNode(str: string): void;
39
+ }
40
+ /**
41
+ * An attribute map, where the keys are the fully qualified attribute names.
42
+ */
43
+ export interface Attributes {
44
+ readonly [qName: string]: Attribute | undefined;
45
+ }
46
+ export interface Attribute {
47
+ /**
48
+ * This attribute's name.
49
+ */
50
+ readonly name: QName;
51
+ /**
52
+ * The unescaped attribute value.
53
+ */
54
+ readonly value: string;
55
+ }
56
+ //# sourceMappingURL=ParseXmlHandler.d.ts.map
@@ -0,0 +1,49 @@
1
+ import type { Cloneable } from '@amazon/vinyl-util';
2
+ import type { XmlRules } from './xmlRules';
3
+ import type { MappedXmlRules } from './mappedXmlRules';
4
+ import type { Attributes, ParseXmlHandler } from './ParseXmlHandler';
5
+ import type { QName } from './QName';
6
+ export interface ParseXmlHandlerOptions {
7
+ readonly validateRules: boolean;
8
+ }
9
+ /**
10
+ * A {@link ParseXmlHandler} implementation that follows {@link XmlRules}, building an object of
11
+ * the parameterized type.
12
+ */
13
+ export declare class ParseXmlHandlerImpl<T> implements ParseXmlHandler<T> {
14
+ private readonly rules;
15
+ private stack;
16
+ private options;
17
+ private busy;
18
+ constructor(rules: MappedXmlRules<T>, options?: Partial<ParseXmlHandlerOptions>);
19
+ startDocument(): void;
20
+ startElement(name: QName, attributes: Attributes): void;
21
+ textNode(str: string): void;
22
+ cDataNode(str: string): void;
23
+ endElement(): void;
24
+ endDocument(): T & XmlElement<T>;
25
+ private validate;
26
+ }
27
+ /**
28
+ * Creates an XML content handler for the given parsing rules.
29
+ *
30
+ * @param rules
31
+ * @param options
32
+ */
33
+ export declare function parseXmlHandler<T extends object>(rules: XmlRules<T>, options?: Partial<ParseXmlHandlerOptions>): ParseXmlHandlerImpl<T>;
34
+ declare const parentSymbol: unique symbol;
35
+ export interface XmlElement<T = any> extends Cloneable<T & XmlElement<T>> {
36
+ readonly parent: (XmlElement | null);
37
+ toJSON(): any;
38
+ }
39
+ export declare class XmlElementImpl<T> implements XmlElement<T> {
40
+ [prop: keyof any]: any;
41
+ private [parentSymbol];
42
+ constructor(parent?: XmlElement | null);
43
+ get parent(): XmlElement | null;
44
+ set parent(value: XmlElement | null);
45
+ clone(): T & XmlElementImpl<T>;
46
+ toJSON(): any;
47
+ }
48
+ export {};
49
+ //# sourceMappingURL=ParseXmlHandlerImpl.d.ts.map
@@ -0,0 +1,33 @@
1
+ import type { Uri } from '../xmlns/org/w3/2001/XmlSchema';
2
+ /**
3
+ * An XML name for an element or attribute.
4
+ */
5
+ export interface QName {
6
+ /**
7
+ * The fully qualified name.
8
+ * This will be the prefixed name or the unprefixed name if the prefix is empty.
9
+ * The prefixed name will be `prefix ':' localPart`
10
+ */
11
+ readonly qName: string;
12
+ /**
13
+ * The xmlns prefix.
14
+ */
15
+ readonly prefix: string | null;
16
+ /**
17
+ * The local part of this name.
18
+ */
19
+ readonly localPart: string;
20
+ /**
21
+ * The resolved xmlns uri for the associated prefix.
22
+ */
23
+ readonly namespaceUri: Uri | null;
24
+ }
25
+ /**
26
+ * Creates a new {@link QName} object.
27
+ *
28
+ * @param localPart
29
+ * @param prefix
30
+ * @param namespaceUri
31
+ */
32
+ export declare function qName(localPart: string, prefix?: string | null, namespaceUri?: Uri | null): QName;
33
+ //# sourceMappingURL=QName.d.ts.map
@@ -0,0 +1,15 @@
1
+ import { ReportableError } from '@amazon/vinyl-util';
2
+ /**
3
+ * @private
4
+ */
5
+ export declare const xmlSchemaErrorLocale: {
6
+ readonly atLeastElements: "Expected at least {expected} occurrences of {property} but was {actual}";
7
+ readonly atMostElements: "Expected at most {expected} occurrences of {property} but was {actual}";
8
+ readonly cyclicReferences: "Cyclic reference detected";
9
+ readonly requiredAttribute: "Attribute '{property}' is required";
10
+ };
11
+ export declare class XmlSchemaError extends ReportableError {
12
+ get [Symbol.toStringTag](): string;
13
+ constructor(message: string);
14
+ }
15
+ //# sourceMappingURL=XmlSchemaError.d.ts.map
@@ -0,0 +1,118 @@
1
+ import type { AnyRecord, Invariant } from '@amazon/vinyl-util';
2
+ import type { XmlRules } from './xmlRules';
3
+ import type { Uri } from '../xmlns/org/w3/2001/XmlSchema';
4
+ /**
5
+ * A machine-readable representation of parse rules for random access based on qualified namespace
6
+ * keys.
7
+ *
8
+ * Rule keys will either be `namespaceUri:localPart` or just `localPart` for wildcard rules if
9
+ * namespaceUri is not defined in the handler.
10
+ */
11
+ export interface MappedXmlRules<T> {
12
+ /**
13
+ * Enforces that this rule set can only be used to parse the expected type T.
14
+ */
15
+ readonly __type: Invariant<T>;
16
+ readonly attributes: ReadonlyMap<string, MappedAttributeRule>;
17
+ readonly elements: ReadonlyMap<string, MappedElementsRule>;
18
+ readonly characters: MappedCharactersRule | undefined;
19
+ }
20
+ export interface MappedAttributeRule {
21
+ /**
22
+ * The property name.
23
+ */
24
+ readonly property: keyof any;
25
+ /**
26
+ * If true, a parsing error will be thrown if the value is undefined.
27
+ */
28
+ readonly required: boolean;
29
+ /**
30
+ * If the current element has no matching attribute, default will be used.
31
+ */
32
+ readonly default: any;
33
+ /**
34
+ * Parses the attribute value.
35
+ */
36
+ readonly parse: (value: string) => any;
37
+ /**
38
+ * Converts the attribute value to a string.
39
+ */
40
+ readonly stringify: (value: any) => string;
41
+ /**
42
+ * The local part of the QName.
43
+ */
44
+ readonly localPart: string;
45
+ /**
46
+ * The namespace uri that must match.
47
+ */
48
+ readonly namespaceUri: Uri | null;
49
+ }
50
+ export interface MappedElementsRule {
51
+ /**
52
+ * The name of the property to set on the parent element.
53
+ */
54
+ readonly property: keyof any;
55
+ /**
56
+ * True if the parsed elements should populate into an array.
57
+ */
58
+ readonly array: boolean;
59
+ /**
60
+ * The minimum number of elements.
61
+ */
62
+ readonly minOccurs: number;
63
+ /**
64
+ * The maximum number of elements. Use null for unbounded.
65
+ */
66
+ readonly maxOccurs: number | null;
67
+ /**
68
+ * If true and there are 0 occurrences of the element, the parsed value will be an empty array
69
+ * instead of undefined.
70
+ */
71
+ readonly useEmptyArrays: boolean;
72
+ /**
73
+ * Returns the mappings for matched element(s).
74
+ */
75
+ readonly rules: () => MappedXmlRules<any>;
76
+ /**
77
+ * The local part of the QName.
78
+ */
79
+ readonly localPart: string;
80
+ /**
81
+ * The namespace uri that must match.
82
+ */
83
+ readonly namespaceUri: Uri | null;
84
+ }
85
+ export interface MappedCharactersRule {
86
+ readonly property: keyof any;
87
+ /**
88
+ * Parses the unescaped/processed characters.
89
+ * This will always be called, but characters may be an empty string if the element has no
90
+ * text content.
91
+ */
92
+ readonly parse: (characters: string) => any;
93
+ /**
94
+ * Converts the value to a string.
95
+ */
96
+ readonly stringify: (value: any) => string;
97
+ }
98
+ /**
99
+ * An empty rules map, used when there was no match for the started element.
100
+ * @private
101
+ */
102
+ export declare const EmptyRules: MappedXmlRules<AnyRecord>;
103
+ /**
104
+ * Creates machine-friendly content handler rules from the given {@link XmlRules}.
105
+ *
106
+ * @param rules The {@link XmlRules} to convert.
107
+ * @param parentNamespaceUri
108
+ */
109
+ export declare function mapXmlRules<T extends object>(rules: XmlRules<T>, parentNamespaceUri?: Uri | null): MappedXmlRules<T>;
110
+ /**
111
+ * Creates a rule key for mapped xml rules.
112
+ *
113
+ * @private
114
+ * @param localPart The {@link QName.localPart}
115
+ * @param namespaceUri The `namespaceUri` of the element.
116
+ */
117
+ export declare function xmlRuleKey(localPart: string, namespaceUri?: Uri | null): string;
118
+ //# sourceMappingURL=mappedXmlRules.d.ts.map
@@ -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