@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,225 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { encodeEntities, equalDeep, getOrSet, substitute, } from '@amazon/vinyl-util';
6
+ import { XmlSchemaError, xmlSchemaErrorLocale } from './XmlSchemaError';
7
+ /**
8
+ * @private
9
+ */
10
+ const locale = {
11
+ /**
12
+ * When a namespace binding is generated, if the prefix was not provided in the stringifier
13
+ * options, it will be generated from this template.
14
+ */
15
+ prefixTemplate: 'ns_{value}',
16
+ };
17
+ const defaultStringifyOptions = {
18
+ indent: ' ',
19
+ newline: '\n',
20
+ prefixMap: new Map(),
21
+ includeXmlDeclaration: true,
22
+ };
23
+ export class XmlWriter {
24
+ rules;
25
+ options;
26
+ usedPrefixes = new Map();
27
+ traversed = new Set();
28
+ constructor(rules, options) {
29
+ this.rules = rules;
30
+ this.options = {
31
+ ...defaultStringifyOptions,
32
+ ...options,
33
+ };
34
+ }
35
+ stringify(object) {
36
+ let str = this.options.includeXmlDeclaration
37
+ ? '<?xml version="1.0"?>' + this.options.newline
38
+ : '';
39
+ const state = new StringifyState();
40
+ str += this.stringifyChildren(object, this.rules.elements, state);
41
+ this.usedPrefixes.clear();
42
+ this.traversed.clear();
43
+ return str;
44
+ }
45
+ qName(localPart, namespaceUri) {
46
+ if (!namespaceUri)
47
+ return localPart;
48
+ const prefixMap = this.options.prefixMap;
49
+ const prefix = getOrSet(this.usedPrefixes, namespaceUri, () => {
50
+ if (prefixMap.has(namespaceUri)) {
51
+ return prefixMap.get(namespaceUri);
52
+ }
53
+ return substitute(locale.prefixTemplate, {
54
+ value: (this.usedPrefixes.size + 1).toString(36),
55
+ });
56
+ });
57
+ return `${prefix}:${localPart}`;
58
+ }
59
+ /**
60
+ * Stringifies an element.
61
+ *
62
+ * @param object
63
+ * @param rule
64
+ * @param state
65
+ */
66
+ stringifyElement(object, rule, state) {
67
+ if (this.traversed.has(object))
68
+ throw new XmlSchemaError(xmlSchemaErrorLocale.cyclicReferences);
69
+ this.traversed.add(object);
70
+ const nl = this.options.newline;
71
+ const isDocument = state.depth === 0;
72
+ let namespaces = '';
73
+ let xmlns = state.xmlns;
74
+ if (xmlns !== rule.namespaceUri &&
75
+ (xmlns == null || !rule.namespaceUri)) {
76
+ // The element's namespace is different from the parent.
77
+ // Change the default namespace if moving to or from a null namespace.
78
+ xmlns = rule.namespaceUri;
79
+ namespaces += ` xmlns="${rule.namespaceUri ?? ''}"`;
80
+ }
81
+ const childState = state.createChild(xmlns, this.options.indent);
82
+ const rules = rule.rules();
83
+ const attributes = this.stringifyAttributes(object, rules.attributes);
84
+ const children = this.stringifyChildren(object, rules.elements, childState);
85
+ const text = this.stringifyCharacters(object, rules.characters);
86
+ if (isDocument) {
87
+ this.usedPrefixes.forEach((prefix, uri) => {
88
+ namespaces += ` xmlns:${prefix}="${uri}"`;
89
+ });
90
+ }
91
+ const indent = state.indent;
92
+ const childIndent = childState.indent;
93
+ const qName = rule.namespaceUri === xmlns
94
+ ? rule.localPart
95
+ : this.qName(rule.localPart, rule.namespaceUri);
96
+ let str = `${indent}<${qName}${namespaces}${attributes}`;
97
+ if (children) {
98
+ str += `>`;
99
+ if (text)
100
+ str += `${nl}${childIndent}${text}`;
101
+ str += nl + children;
102
+ str += `${nl}${indent}</${qName}>`;
103
+ }
104
+ else if (text) {
105
+ str += `>${text}</${qName}>`;
106
+ }
107
+ else {
108
+ str += '/>';
109
+ }
110
+ return str;
111
+ }
112
+ /**
113
+ * Stringifies an element's attributes.
114
+ *
115
+ * @param object
116
+ * @param attributes
117
+ * @return Returns the attributes string. This will include a leading space if there are any
118
+ * found attributes.
119
+ */
120
+ stringifyAttributes(object, attributes) {
121
+ let str = '';
122
+ attributes.forEach((attributeRule) => {
123
+ const propertyValue = object[attributeRule.property];
124
+ if (propertyValue !== undefined) {
125
+ const attributeValue = attributeRule.stringify(propertyValue);
126
+ if (attributeRule.default === undefined ||
127
+ !equalDeep(propertyValue, attributeRule.default)) {
128
+ str += ` ${this.qName(attributeRule.localPart, attributeRule.namespaceUri)}="${encodeEntities(attributeValue)}"`;
129
+ }
130
+ }
131
+ else {
132
+ if (attributeRule.required) {
133
+ throw new XmlSchemaError(substitute(xmlSchemaErrorLocale.requiredAttribute, {
134
+ property: attributeRule.property,
135
+ }));
136
+ }
137
+ }
138
+ });
139
+ return str;
140
+ }
141
+ /**
142
+ * Stringifies a property as a CDATA node.
143
+ *
144
+ * @param object
145
+ * @param charactersRule
146
+ */
147
+ stringifyCharacters(object, charactersRule) {
148
+ if (!charactersRule)
149
+ return null;
150
+ const str = charactersRule.stringify(object[charactersRule.property]);
151
+ if (!str)
152
+ return '';
153
+ return `<![CDATA[${str}]]>`;
154
+ }
155
+ /**
156
+ * Stringifies an element's child elements.
157
+ *
158
+ * @param object
159
+ * @param elements
160
+ * @param state
161
+ */
162
+ stringifyChildren(object, elements, state) {
163
+ let str = '';
164
+ elements.forEach((elementsRule) => {
165
+ const child = object[elementsRule.property];
166
+ if (child) {
167
+ if (elementsRule.array) {
168
+ const arr = child;
169
+ if (elementsRule.minOccurs > arr.length) {
170
+ throw new XmlSchemaError(substitute(xmlSchemaErrorLocale.atLeastElements, {
171
+ property: elementsRule.property,
172
+ expected: elementsRule.minOccurs,
173
+ actual: arr.length,
174
+ }));
175
+ }
176
+ if (elementsRule.maxOccurs != null &&
177
+ elementsRule.maxOccurs < arr.length) {
178
+ throw new XmlSchemaError(substitute(xmlSchemaErrorLocale.atMostElements, {
179
+ property: elementsRule.property,
180
+ expected: elementsRule.maxOccurs,
181
+ actual: arr.length,
182
+ }));
183
+ }
184
+ for (const element of arr) {
185
+ if (str)
186
+ str += this.options.newline;
187
+ str += this.stringifyElement(element, elementsRule, state);
188
+ }
189
+ }
190
+ else {
191
+ if (str)
192
+ str += this.options.newline;
193
+ str += this.stringifyElement(child, elementsRule, state);
194
+ }
195
+ }
196
+ else {
197
+ if (elementsRule.minOccurs > 0) {
198
+ throw new XmlSchemaError(substitute(xmlSchemaErrorLocale.atLeastElements, {
199
+ property: elementsRule.property,
200
+ expected: elementsRule.minOccurs,
201
+ actual: 0,
202
+ }));
203
+ }
204
+ }
205
+ });
206
+ return str;
207
+ }
208
+ }
209
+ class StringifyState {
210
+ depth;
211
+ xmlns;
212
+ indent;
213
+ constructor(depth = 0, xmlns = null, indent = '') {
214
+ this.depth = depth;
215
+ this.xmlns = xmlns;
216
+ this.indent = indent;
217
+ }
218
+ createChild(xmlns, indent) {
219
+ return new StringifyState(this.depth + 1, xmlns, this.indent + indent);
220
+ }
221
+ }
222
+ export function stringifyXml(object, rules, options) {
223
+ const writer = new XmlWriter(rules, options);
224
+ return writer.stringify(object);
225
+ }
@@ -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 @@
1
+ {"version":3,"file":"xmlRules.d.ts","sourceRoot":"","sources":["../../../../src/xml/xmlRules.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AAEH,OAAO,EAKH,KAAK,SAAS,EACd,KAAK,KAAK,EACV,KAAK,YAAY,EACpB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAA;AAExD,oBAAY,WAAW;IACnB,UAAU,eAAe;IACzB,SAAS,cAAc;IACvB,OAAO,YAAY;IACnB,QAAQ,aAAa;CACxB;AAED;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAA;AAE/D;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI;IACrC,QAAQ,EAAE,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAChD,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GACb,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC1B,CAAA;AAED;;GAEG;AACH,MAAM,MAAM,OAAO,CAAC,CAAC,IACf,aAAa,CAAC,CAAC,CAAC,GAChB,cAAc,CAAC,CAAC,CAAC,GACjB,YAAY,CAAC,CAAC,GAAG,CAAC,SAAS,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC,GACjD,WAAW,CAAC,CAAC,GAAG,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,CAAA;AAE3C;;;GAGG;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,oBAAoB,CAAC,MAAM,CAAC,GACvC,aAAa,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;AAapC,wBAAgB,WAAW,CACvB,OAAO,EAAE,wBAAwB,CAAC,OAAO,CAAC,GAC3C,aAAa,CAAC,OAAO,CAAC,CAAA;AAEzB,wBAAgB,WAAW,CACvB,OAAO,CAAC,EAAE,oBAAoB,CAAC,OAAO,CAAC,GACxC,aAAa,CAAC,OAAO,GAAG,SAAS,CAAC,CAAA;AAarC,wBAAgB,YAAY,CACxB,OAAO,EAAE,wBAAwB,CAAC,IAAI,CAAC,GACxC,aAAa,CAAC,YAAY,CAAC,CAAA;AAE9B,wBAAgB,YAAY,CACxB,OAAO,CAAC,EAAE,oBAAoB,CAAC,YAAY,CAAC,GAC7C,aAAa,CAAC,YAAY,GAAG,SAAS,CAAC,CAAA"}
@@ -0,0 +1,134 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /**
6
+ * A set of utilities for easily writing schema-based rule definitions to be used with the
7
+ * `parseXml` parser.
8
+ *
9
+ * @module
10
+ */
11
+ import { parseDate, stringifyDate, parseBoolean, stringify, } from '@amazon/vinyl-util';
12
+ export var XmlRuleType;
13
+ (function (XmlRuleType) {
14
+ XmlRuleType["CHARACTERS"] = "characters";
15
+ XmlRuleType["ATTRIBUTE"] = "attribute";
16
+ XmlRuleType["ELEMENT"] = "element";
17
+ XmlRuleType["ELEMENTS"] = "elements";
18
+ })(XmlRuleType || (XmlRuleType = {}));
19
+ /**
20
+ * Returns a schema for a single object based on a map of rules.
21
+ *
22
+ * If more than one element is found with a matching name, a `ParseError` is thrown.
23
+ */
24
+ export function element(rules, options) {
25
+ return {
26
+ type: XmlRuleType.ELEMENT,
27
+ localPart: undefined,
28
+ namespaceUri: undefined,
29
+ required: false,
30
+ ...options,
31
+ rules,
32
+ };
33
+ }
34
+ /**
35
+ * Handles a list of child nodes where each matching child node is parsed into a corresponding
36
+ * object represented by the given rules.
37
+ *
38
+ * @param rules The parsing rules to use for each element.
39
+ * @param options
40
+ * @see parseChildNodes
41
+ */
42
+ export function elements(rules, options) {
43
+ return {
44
+ type: XmlRuleType.ELEMENTS,
45
+ localPart: undefined,
46
+ namespaceUri: undefined,
47
+ minOccurs: 0,
48
+ maxOccurs: null,
49
+ useEmptyArrays: false,
50
+ ...options,
51
+ rules,
52
+ };
53
+ }
54
+ /**
55
+ * Parses the text content of the current element via the given parse and stringify functions.
56
+ *
57
+ * Does not currently support mixing text and element nodes.
58
+ * E.g. the XML `<note>Dear <name>John</name>, I regret to inform you...</note>` could not be
59
+ * serialized or deserialized using xml rule mappings.
60
+ *
61
+ * @param parse The string passed to this parser is the processed text content of the current
62
+ * element.
63
+ * @param stringify Serializes the value.
64
+ *
65
+ * @see processCharacters
66
+ */
67
+ export function characters(parse, stringify) {
68
+ return { type: XmlRuleType.CHARACTERS, parse, stringify };
69
+ }
70
+ /**
71
+ * Handles the processed text content without any modification.
72
+ *
73
+ * @see characters
74
+ */
75
+ export const charactersString = characters((i) => i, stringify);
76
+ /**
77
+ * Handles an attribute using the given parse and stringify functions.
78
+ *
79
+ * @param parse
80
+ * @param stringify
81
+ * @param options
82
+ */
83
+ export function attr(parse, stringify, options) {
84
+ return {
85
+ type: XmlRuleType.ATTRIBUTE,
86
+ localPart: undefined,
87
+ namespaceUri: null,
88
+ required: false,
89
+ default: undefined,
90
+ ...options,
91
+ parse,
92
+ stringify,
93
+ };
94
+ }
95
+ /**
96
+ * Keeps an attribute's string value as is.
97
+ *
98
+ * @param options
99
+ */
100
+ export function attrString(options) {
101
+ return attr((i) => i, stringify, options);
102
+ }
103
+ /**
104
+ * Parses an attribute's value using `parseInt`
105
+ *
106
+ * @param options
107
+ */
108
+ export function attrInt(options) {
109
+ return attr(parseInt, stringify, options);
110
+ }
111
+ /**
112
+ * Parses an attribute using `parseFloat`
113
+ *
114
+ * @param options
115
+ */
116
+ export function attrFloat(options) {
117
+ return attr(parseFloat, stringify, options);
118
+ }
119
+ /**
120
+ * Parses an attribute's value `"true"` or `"1"` as `true`.
121
+ *
122
+ * @param options
123
+ */
124
+ export function attrBoolean(options) {
125
+ return attr(parseBoolean, stringify, options);
126
+ }
127
+ /**
128
+ * Parses an attribute using `Date.parse`
129
+ *
130
+ * @param options
131
+ */
132
+ export function attrDateTime(options) {
133
+ return attr(parseDate, stringifyDate, options);
134
+ }
@@ -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 @@
1
+ {"version":3,"file":"xlink.d.ts","sourceRoot":"","sources":["../../../../../../../src/xmlns/org/w3/1999/xlink.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AAEH,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAA"}
@@ -0,0 +1,5 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ export {};
@@ -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 @@
1
+ {"version":3,"file":"XmlSchema.d.ts","sourceRoot":"","sources":["../../../../../../../src/xmlns/org/w3/2001/XmlSchema.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,MAAM,GAAG,GAAG,MAAM,CAAA;AAExB,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,OAAO;IACpB,QAAQ,EAAE,GAAG,CAAA;CAChB"}
@@ -0,0 +1,5 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ export {};
@@ -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 { actuateType } from '../xmlns/org/w3/1999/xlink';
2
+ export declare function assertActuateEnum(str: string): actuateType;
3
+ //# sourceMappingURL=actuateValidator.d.ts.map