@endevops/effect-codec-xml 0.0.1 → 0.1.0-beta.2
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/README.md +81 -62
- package/dist/codec.d.ts +17 -9
- package/dist/codec.d.ts.map +1 -1
- package/dist/codec.js +29 -18
- package/dist/codec.js.map +1 -1
- package/dist/conventions.d.ts +4 -4
- package/dist/conventions.js +7 -7
- package/dist/conventions.js.map +1 -1
- package/dist/entities/entity-decoder.d.ts +33 -33
- package/dist/entities/entity-decoder.d.ts.map +1 -1
- package/dist/entities/entity-decoder.js +63 -64
- package/dist/entities/entity-decoder.js.map +1 -1
- package/dist/errors.d.ts +2 -2
- package/dist/errors.js +2 -2
- package/dist/errors.js.map +1 -1
- package/dist/namespaces.js +40 -13
- package/dist/namespaces.js.map +1 -1
- package/dist/naming.d.ts +6 -6
- package/dist/naming.d.ts.map +1 -1
- package/dist/naming.js +3 -3
- package/dist/naming.js.map +1 -1
- package/dist/parse.d.ts +5 -5
- package/dist/parse.js +14 -14
- package/dist/parse.js.map +1 -1
- package/dist/plain-value.js +242 -0
- package/dist/plain-value.js.map +1 -0
- package/dist/render.d.ts +1 -1
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +28 -28
- package/dist/render.js.map +1 -1
- package/dist/xml-error.d.ts +9 -9
- package/dist/xml-error.js +18 -18
- package/dist/xml-error.js.map +1 -1
- package/dist/xml-value.d.ts +7 -7
- package/dist/xml-value.d.ts.map +1 -1
- package/dist/xml-value.js +6 -7
- package/dist/xml-value.js.map +1 -1
- package/package.json +1 -1
- package/src/codec.ts +98 -71
- package/src/conventions.ts +7 -7
- package/src/entities/entity-decoder.ts +98 -99
- package/src/errors.ts +3 -3
- package/src/index.ts +3 -3
- package/src/namespaces.ts +62 -36
- package/src/naming.ts +34 -35
- package/src/parse.ts +26 -26
- package/src/plain-value.ts +312 -0
- package/src/render.ts +44 -44
- package/src/xml-error.ts +18 -18
- package/src/xml-value.ts +10 -11
package/src/xml-value.ts
CHANGED
|
@@ -11,10 +11,10 @@ export interface XmlRecord {
|
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* @description One value in an XML document: nothing at all, character data, a repeated run of children, or a record of attributes, text and child elements.
|
|
14
|
-
* `undefined` is a value of its own rather than an omission, because that is how an absent optional field survives a round trip
|
|
15
|
-
* value stays distinguishable from a field whose value is the empty string, and the renderer writes neither of them. The shape is
|
|
16
|
-
*
|
|
17
|
-
* re-implementing the derivation.
|
|
14
|
+
* `undefined` is a value of its own rather than an omission, because that is how an absent optional field survives a round trip. A field with no
|
|
15
|
+
* value stays distinguishable from a field whose value is the empty string, and the renderer writes neither of them. The shape is the same one
|
|
16
|
+
* `Schema.toCodecStringTree` derives, and sharing that shape is what lets every schema feature Effect supports round-trip through this package
|
|
17
|
+
* without re-implementing the derivation.
|
|
18
18
|
*/
|
|
19
19
|
export type XmlValue = string | undefined | ReadonlyArray<XmlValue> | XmlRecord;
|
|
20
20
|
|
|
@@ -34,10 +34,9 @@ const MAX_GUARD_DEPTH = 512;
|
|
|
34
34
|
export const isXmlValue = (input: unknown): input is XmlValue => check(input, 0);
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
* @description One level of {@link isXmlValue}, with the depth it was reached at. The depth is the whole defence against a value built to be hostile
|
|
38
|
-
* self-referential object would otherwise recurse until the stack gave out, and a value nested thousands deep would take it with it.
|
|
39
|
-
*
|
|
40
|
-
* it.
|
|
37
|
+
* @description One level of {@link isXmlValue}, with the depth it was reached at. The depth is the whole defence against a value built to be hostile. A
|
|
38
|
+
* self-referential object would otherwise recurse until the stack gave out, and a value nested thousands deep would take it with it. This rejects
|
|
39
|
+
* both, so it is a bounded recursion rather than a loop. The model is a tree, and walking a tree means walking it.
|
|
41
40
|
*
|
|
42
41
|
* @param input - The candidate value.
|
|
43
42
|
* @param depth - How many levels down this value sits.
|
|
@@ -90,13 +89,13 @@ const everyFieldIs = (input: object, depth: number): boolean => {
|
|
|
90
89
|
};
|
|
91
90
|
|
|
92
91
|
/**
|
|
93
|
-
* @description A schema for {@link XmlValue}, so a value can be validated on its own
|
|
94
|
-
* and the schema it belongs to is not in hand.
|
|
92
|
+
* @description A schema for {@link XmlValue}, so a value can be validated on its own. This helps when it arrives from a store or a queue rather than from
|
|
93
|
+
* {@link parseXml}, and the schema it belongs to is not in hand.
|
|
95
94
|
*
|
|
96
95
|
* @example
|
|
97
96
|
* ```typescript
|
|
98
97
|
* import { Schema } from 'effect';
|
|
99
|
-
* import { XmlValue } from '@endevops/effect-xml
|
|
98
|
+
* import { XmlValue } from '@endevops/effect-codec-xml';
|
|
100
99
|
*
|
|
101
100
|
* Schema.decodeUnknownSync(XmlValue)({ book: { '@id': '1', title: 'Dune' } }); // => { book: { '@id': '1', title: 'Dune' } }
|
|
102
101
|
* Schema.decodeUnknownSync(XmlValue)({ book: { title: 42 } }); // => throws XmlValue
|