@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.
Files changed (50) hide show
  1. package/README.md +81 -62
  2. package/dist/codec.d.ts +17 -9
  3. package/dist/codec.d.ts.map +1 -1
  4. package/dist/codec.js +29 -18
  5. package/dist/codec.js.map +1 -1
  6. package/dist/conventions.d.ts +4 -4
  7. package/dist/conventions.js +7 -7
  8. package/dist/conventions.js.map +1 -1
  9. package/dist/entities/entity-decoder.d.ts +33 -33
  10. package/dist/entities/entity-decoder.d.ts.map +1 -1
  11. package/dist/entities/entity-decoder.js +63 -64
  12. package/dist/entities/entity-decoder.js.map +1 -1
  13. package/dist/errors.d.ts +2 -2
  14. package/dist/errors.js +2 -2
  15. package/dist/errors.js.map +1 -1
  16. package/dist/namespaces.js +40 -13
  17. package/dist/namespaces.js.map +1 -1
  18. package/dist/naming.d.ts +6 -6
  19. package/dist/naming.d.ts.map +1 -1
  20. package/dist/naming.js +3 -3
  21. package/dist/naming.js.map +1 -1
  22. package/dist/parse.d.ts +5 -5
  23. package/dist/parse.js +14 -14
  24. package/dist/parse.js.map +1 -1
  25. package/dist/plain-value.js +242 -0
  26. package/dist/plain-value.js.map +1 -0
  27. package/dist/render.d.ts +1 -1
  28. package/dist/render.d.ts.map +1 -1
  29. package/dist/render.js +28 -28
  30. package/dist/render.js.map +1 -1
  31. package/dist/xml-error.d.ts +9 -9
  32. package/dist/xml-error.js +18 -18
  33. package/dist/xml-error.js.map +1 -1
  34. package/dist/xml-value.d.ts +7 -7
  35. package/dist/xml-value.d.ts.map +1 -1
  36. package/dist/xml-value.js +6 -7
  37. package/dist/xml-value.js.map +1 -1
  38. package/package.json +1 -1
  39. package/src/codec.ts +98 -71
  40. package/src/conventions.ts +7 -7
  41. package/src/entities/entity-decoder.ts +98 -99
  42. package/src/errors.ts +3 -3
  43. package/src/index.ts +3 -3
  44. package/src/namespaces.ts +62 -36
  45. package/src/naming.ts +34 -35
  46. package/src/parse.ts +26 -26
  47. package/src/plain-value.ts +312 -0
  48. package/src/render.ts +44 -44
  49. package/src/xml-error.ts +18 -18
  50. 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: 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 deliberately the
16
- * same one `Schema.toCodecStringTree` derives, which is what lets every schema feature Effect supports round-trip through this package without
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: a
38
- * self-referential object would otherwise recurse until the stack gave out, and a value nested thousands deep would take it with it. Both are
39
- * rejected here instead, which is why this is a real recursion with a bound rather than a loop — the model is a tree, and a tree is walked by walking
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 — when it arrives from a store or a queue rather than from {@link parseXml},
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-codec';
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