@fncts/schema 0.0.4 → 0.0.6

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 (151) hide show
  1. package/AST.d.ts +528 -0
  2. package/ASTAnnotation.d.ts +82 -0
  3. package/ASTAnnotationMap.d.ts +14 -0
  4. package/Gen.d.ts +15 -0
  5. package/InvalidInterpretationError.d.ts +5 -0
  6. package/ParseError.d.ts +107 -0
  7. package/ParseResult.d.ts +24 -0
  8. package/Parser/api.d.ts +42 -0
  9. package/Parser/definition.d.ts +22 -0
  10. package/Parser/interpreter.d.ts +6 -0
  11. package/Parser.d.ts +2 -0
  12. package/Schema/api/conc.d.ts +18 -0
  13. package/Schema/api/hashMap.d.ts +21 -0
  14. package/Schema/api/immutableArray.d.ts +23 -0
  15. package/Schema/api/list.d.ts +23 -0
  16. package/Schema/api/maybe.d.ts +21 -0
  17. package/Schema/api.d.ts +243 -0
  18. package/Schema/definition.d.ts +29 -0
  19. package/Schema/derivations.d.ts +70 -0
  20. package/Schema.d.ts +2 -144
  21. package/_cjs/AST.cjs +1171 -0
  22. package/_cjs/AST.cjs.map +1 -0
  23. package/_cjs/ASTAnnotation.cjs +111 -0
  24. package/_cjs/ASTAnnotation.cjs.map +1 -0
  25. package/_cjs/ASTAnnotationMap.cjs +35 -0
  26. package/_cjs/ASTAnnotationMap.cjs.map +1 -0
  27. package/_cjs/Gen.cjs +185 -0
  28. package/_cjs/Gen.cjs.map +1 -0
  29. package/_cjs/InvalidInterpretationError.cjs +18 -0
  30. package/_cjs/InvalidInterpretationError.cjs.map +1 -0
  31. package/_cjs/ParseError.cjs +222 -0
  32. package/_cjs/ParseError.cjs.map +1 -0
  33. package/_cjs/{Decoder.cjs → ParseResult.cjs} +24 -22
  34. package/_cjs/ParseResult.cjs.map +1 -0
  35. package/_cjs/Parser/api.cjs +80 -0
  36. package/_cjs/Parser/api.cjs.map +1 -0
  37. package/_cjs/{Guard.cjs → Parser/definition.cjs} +17 -22
  38. package/_cjs/Parser/definition.cjs.map +1 -0
  39. package/_cjs/Parser/interpreter.cjs +409 -0
  40. package/_cjs/Parser/interpreter.cjs.map +1 -0
  41. package/_cjs/Parser.cjs +28 -0
  42. package/_cjs/Parser.cjs.map +1 -0
  43. package/_cjs/Schema/api/conc.cjs +84 -0
  44. package/_cjs/Schema/api/conc.cjs.map +1 -0
  45. package/_cjs/Schema/api/hashMap.cjs +161 -0
  46. package/_cjs/Schema/api/hashMap.cjs.map +1 -0
  47. package/_cjs/Schema/api/immutableArray.cjs +90 -0
  48. package/_cjs/Schema/api/immutableArray.cjs.map +1 -0
  49. package/_cjs/Schema/api/list.cjs +98 -0
  50. package/_cjs/Schema/api/list.cjs.map +1 -0
  51. package/_cjs/Schema/api/maybe.cjs +75 -0
  52. package/_cjs/Schema/api/maybe.cjs.map +1 -0
  53. package/_cjs/Schema/api.cjs +424 -0
  54. package/_cjs/Schema/api.cjs.map +1 -0
  55. package/_cjs/Schema/definition.cjs +26 -0
  56. package/_cjs/Schema/definition.cjs.map +1 -0
  57. package/_cjs/Schema/derivations.cjs +108 -0
  58. package/_cjs/Schema/derivations.cjs.map +1 -0
  59. package/_cjs/Schema.cjs +20 -237
  60. package/_cjs/Schema.cjs.map +1 -1
  61. package/_cjs/utils.cjs +52 -0
  62. package/_cjs/utils.cjs.map +1 -0
  63. package/_mjs/AST.mjs +1060 -0
  64. package/_mjs/AST.mjs.map +1 -0
  65. package/_mjs/ASTAnnotation.mjs +80 -0
  66. package/_mjs/ASTAnnotation.mjs.map +1 -0
  67. package/_mjs/ASTAnnotationMap.mjs +27 -0
  68. package/_mjs/ASTAnnotationMap.mjs.map +1 -0
  69. package/_mjs/Gen.mjs +176 -0
  70. package/_mjs/Gen.mjs.map +1 -0
  71. package/_mjs/InvalidInterpretationError.mjs +10 -0
  72. package/_mjs/InvalidInterpretationError.mjs.map +1 -0
  73. package/_mjs/ParseError.mjs +200 -0
  74. package/_mjs/ParseError.mjs.map +1 -0
  75. package/_mjs/ParseResult.mjs +21 -0
  76. package/_mjs/ParseResult.mjs.map +1 -0
  77. package/_mjs/Parser/api.mjs +67 -0
  78. package/_mjs/Parser/api.mjs.map +1 -0
  79. package/_mjs/Parser/definition.mjs +15 -0
  80. package/_mjs/Parser/definition.mjs.map +1 -0
  81. package/_mjs/Parser/interpreter.mjs +401 -0
  82. package/_mjs/Parser/interpreter.mjs.map +1 -0
  83. package/_mjs/Parser.mjs +4 -0
  84. package/_mjs/Parser.mjs.map +1 -0
  85. package/_mjs/Schema/api/conc.mjs +72 -0
  86. package/_mjs/Schema/api/conc.mjs.map +1 -0
  87. package/_mjs/Schema/api/hashMap.mjs +150 -0
  88. package/_mjs/Schema/api/hashMap.mjs.map +1 -0
  89. package/_mjs/Schema/api/immutableArray.mjs +79 -0
  90. package/_mjs/Schema/api/immutableArray.mjs.map +1 -0
  91. package/_mjs/Schema/api/list.mjs +87 -0
  92. package/_mjs/Schema/api/list.mjs.map +1 -0
  93. package/_mjs/Schema/api/maybe.mjs +64 -0
  94. package/_mjs/Schema/api/maybe.mjs.map +1 -0
  95. package/_mjs/Schema/api.mjs +367 -0
  96. package/_mjs/Schema/api.mjs.map +1 -0
  97. package/_mjs/Schema/definition.mjs +16 -0
  98. package/_mjs/Schema/definition.mjs.map +1 -0
  99. package/_mjs/Schema/derivations.mjs +94 -0
  100. package/_mjs/Schema/derivations.mjs.map +1 -0
  101. package/_mjs/Schema.mjs +3 -212
  102. package/_mjs/Schema.mjs.map +1 -1
  103. package/_mjs/utils.mjs +41 -0
  104. package/_mjs/utils.mjs.map +1 -0
  105. package/_src/AST.ts +1353 -0
  106. package/_src/ASTAnnotation.ts +98 -0
  107. package/_src/ASTAnnotationMap.ts +38 -0
  108. package/_src/Gen.ts +171 -0
  109. package/_src/InvalidInterpretationError.ts +6 -0
  110. package/_src/ParseError.ts +237 -0
  111. package/_src/ParseResult.ts +26 -0
  112. package/_src/Parser/api.ts +71 -0
  113. package/_src/Parser/definition.ts +24 -0
  114. package/_src/Parser/interpreter.ts +442 -0
  115. package/_src/Parser.ts +4 -0
  116. package/_src/Schema/api/conc.ts +78 -0
  117. package/_src/Schema/api/hashMap.ts +184 -0
  118. package/_src/Schema/api/immutableArray.ts +88 -0
  119. package/_src/Schema/api/list.ts +96 -0
  120. package/_src/Schema/api/maybe.ts +68 -0
  121. package/_src/Schema/api.ts +530 -0
  122. package/_src/Schema/definition.ts +32 -0
  123. package/_src/Schema/derivations.ts +185 -0
  124. package/_src/Schema.ts +4 -254
  125. package/_src/global.ts +53 -0
  126. package/_src/utils.ts +48 -0
  127. package/global.d.ts +52 -0
  128. package/package.json +2 -2
  129. package/utils.d.ts +8 -0
  130. package/Decoder.d.ts +0 -3
  131. package/Encoder.d.ts +0 -4
  132. package/Guard.d.ts +0 -3
  133. package/Schemable.d.ts +0 -39
  134. package/_cjs/Decoder.cjs.map +0 -1
  135. package/_cjs/Encoder.cjs +0 -45
  136. package/_cjs/Encoder.cjs.map +0 -1
  137. package/_cjs/Guard.cjs.map +0 -1
  138. package/_cjs/Schemable.cjs +0 -6
  139. package/_cjs/Schemable.cjs.map +0 -1
  140. package/_mjs/Decoder.mjs +0 -20
  141. package/_mjs/Decoder.mjs.map +0 -1
  142. package/_mjs/Encoder.mjs +0 -36
  143. package/_mjs/Encoder.mjs.map +0 -1
  144. package/_mjs/Guard.mjs +0 -20
  145. package/_mjs/Guard.mjs.map +0 -1
  146. package/_mjs/Schemable.mjs +0 -2
  147. package/_mjs/Schemable.mjs.map +0 -1
  148. package/_src/Decoder.ts +0 -20
  149. package/_src/Encoder.ts +0 -38
  150. package/_src/Guard.ts +0 -20
  151. package/_src/Schemable.ts +0 -46
package/_cjs/Encoder.cjs DELETED
@@ -1,45 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Schemable = void 0;
7
- var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/data/Encoder/api"));
8
- var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/data/function/api"));
9
- var _Schema = /*#__PURE__*/require("@fncts/schema/Schema");
10
- var G = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./Guard.cjs"));
11
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
- const Schemable = {
14
- unknown: tsplus_module_1.unknown,
15
- string: tsplus_module_1.string,
16
- number: tsplus_module_1.number,
17
- boolean: tsplus_module_1.boolean,
18
- bigint: tsplus_module_1.bigint,
19
- literal: tsplus_module_1.literal,
20
- nullable: tsplus_module_1.nullable,
21
- struct: tsplus_module_1.struct,
22
- partial: tsplus_module_1.partial,
23
- array: tsplus_module_1.readonlyArray,
24
- record: tsplus_module_1.record,
25
- tuple: tsplus_module_1.tuple,
26
- lazy: tsplus_module_1.deriveLazy,
27
- validation: tsplus_module_1.validation,
28
- union: (members, schema) => {
29
- const guards = schema.members.map((0, _Schema.interpret)(G.Schemable));
30
- return tsplus_module_1.makeEncoder(inp => {
31
- let encoder;
32
- for (let i = 0; i < guards.length; i++) {
33
- if (guards[i].is(inp)) {
34
- encoder = members[i];
35
- }
36
- }
37
- if (!encoder) {
38
- throw new Error("BUG: Encoder not found for union");
39
- }
40
- return encoder.encode(inp);
41
- });
42
- }
43
- };
44
- exports.Schemable = Schemable;
45
- //# sourceMappingURL=Encoder.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Encoder.cjs","mappings":";;;;;;;;AAGA;AAEA;AAAgC;AAAA;AAEzB,MAAMA,SAAS,GAAgB;EACpCC,OAAO,yBAAiB;EACxBC,MAAM,wBAAU;EAChBC,MAAM,wBAAU;EAChBC,OAAO,yBAAU;EACjBC,MAAM,wBAAU;EAChBC,OAAO,yBAAiB;EACxBC,QAAQ,0BAAkB;EAC1BC,MAAM,wBAAgB;EACtBC,OAAO,yBAAiB;EACxBC,KAAK,+BAAuB;EAC5BC,MAAM,wBAAgB;EACtBC,KAAK,uBAA6B;EAClCC,IAAI,4BAAc;EAClBC,UAAU,4BAAkC;EAC5CC,KAAK,EAAE,CAACC,OAAO,EAAEC,MAAM,KAAI;IACzB,MAAMC,MAAM,GAAGD,MAAM,CAACD,OAAO,CAACG,GAAG,CAAC,qBAAS,EAACC,CAAC,CAACpB,SAAS,CAAC,CAAC;IACzD,OAAOqB,4BAASC,GAAG,IAAI;MACrB,IAAIC,OAAiC;MACrC,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGN,MAAM,CAACO,MAAM,EAAED,CAAC,EAAE,EAAE;QACtC,IAAIN,MAAM,CAACM,CAAC,CAAE,CAACE,EAAE,CAACJ,GAAG,CAAC,EAAE;UACtBC,OAAO,GAAGP,OAAO,CAACQ,CAAC,CAAE;;;MAGzB,IAAI,CAACD,OAAO,EAAE;QACZ,MAAM,IAAII,KAAK,CAAC,kCAAkC,CAAC;;MAErD,OAAOJ,OAAO,CAACK,MAAM,CAACN,GAAG,CAAC;IAC5B,CAAC,CAAC;EACJ;CACD;AAAC","names":["Schemable","unknown","string","number","boolean","bigint","literal","nullable","struct","partial","array","record","tuple","lazy","validation","union","members","schema","guards","map","G","tsplus_module_1","inp","encoder","i","length","is","Error","encode"],"sourceRoot":"","sources":["../_src/Encoder.ts"],"sourcesContent":[null]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"Guard.cjs","mappings":";;;;;;;;;;AAGO,MAAMA,SAAS,GAAc;EAClCC,OAAO,yBAAe;EACtBC,MAAM,wBAAU;EAChBC,MAAM,wBAAU;EAChBC,OAAO,yBAAU;EACjBC,MAAM,wBAAU;EAChBC,OAAO,yBAAe;EACtBC,QAAQ,0BAAgB;EACxBC,MAAM,wBAAc;EACpBC,OAAO,yBAAe;EACtBC,KAAK,+BAAqB;EAC1BC,MAAM,wBAAc;EACpBC,KAAK,uBAA2B;EAChCC,IAAI,4BAAY;EAChBC,UAAU,4BAAgC;EAC1CC,KAAK,EAAGC,OAAO,IAAKC,4BAAY,GAAGD,OAAO;CAC3C;AAAC","names":["Schemable","unknown","string","number","boolean","bigint","literal","nullable","struct","partial","array","record","tuple","lazy","validation","union","members","tsplus_module_1"],"sourceRoot":"","sources":["../_src/Guard.ts"],"sourcesContent":[null]}
@@ -1,6 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- //# sourceMappingURL=Schemable.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Schemable.cjs","mappings":"","names":[],"sourceRoot":"","sources":[],"sourcesContent":[]}
package/_mjs/Decoder.mjs DELETED
@@ -1,20 +0,0 @@
1
- import * as tsplus_module_1 from "@fncts/base/data/Decoder/api";
2
- import * as tsplus_module_2 from "@fncts/base/data/function/api";
3
- export const Schemable = {
4
- unknown: tsplus_module_1.unknown,
5
- string: tsplus_module_1.string,
6
- number: tsplus_module_1.number,
7
- boolean: tsplus_module_1.boolean,
8
- bigint: tsplus_module_1.bigint,
9
- literal: tsplus_module_1.literal,
10
- nullable: tsplus_module_1.nullable,
11
- struct: tsplus_module_1.struct,
12
- partial: tsplus_module_1.partial,
13
- array: tsplus_module_1.readonlyArray,
14
- record: tsplus_module_1.record,
15
- tuple: tsplus_module_1.tuple,
16
- lazy: tsplus_module_1.deriveLazy,
17
- validation: tsplus_module_1.validation,
18
- union: members => tsplus_module_1.union(...members)
19
- };
20
- //# sourceMappingURL=Decoder.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Decoder.mjs","mappings":";;AAGA,OAAO,MAAMA,SAAS,GAAgB;EACpCC,OAAO,yBAAiB;EACxBC,MAAM,wBAAU;EAChBC,MAAM,wBAAU;EAChBC,OAAO,yBAAU;EACjBC,MAAM,wBAAU;EAChBC,OAAO,yBAAiB;EACxBC,QAAQ,0BAAkB;EAC1BC,MAAM,wBAAgB;EACtBC,OAAO,yBAAiB;EACxBC,KAAK,+BAAuB;EAC5BC,MAAM,wBAAgB;EACtBC,KAAK,uBAA6B;EAClCC,IAAI,4BAAc;EAClBC,UAAU,4BAAkC;EAC5CC,KAAK,EAAGC,OAAO,IAAKC,sBAAc,GAAGD,OAAO;CAC7C","names":["Schemable","unknown","string","number","boolean","bigint","literal","nullable","struct","partial","array","record","tuple","lazy","validation","union","members","tsplus_module_1"],"sourceRoot":"","sources":["../_src/Decoder.ts"],"sourcesContent":[null]}
package/_mjs/Encoder.mjs DELETED
@@ -1,36 +0,0 @@
1
- import * as tsplus_module_1 from "@fncts/base/data/Encoder/api";
2
- import * as tsplus_module_2 from "@fncts/base/data/function/api";
3
- import { interpret } from "@fncts/schema/Schema";
4
- import * as G from "./Guard.mjs";
5
- export const Schemable = {
6
- unknown: tsplus_module_1.unknown,
7
- string: tsplus_module_1.string,
8
- number: tsplus_module_1.number,
9
- boolean: tsplus_module_1.boolean,
10
- bigint: tsplus_module_1.bigint,
11
- literal: tsplus_module_1.literal,
12
- nullable: tsplus_module_1.nullable,
13
- struct: tsplus_module_1.struct,
14
- partial: tsplus_module_1.partial,
15
- array: tsplus_module_1.readonlyArray,
16
- record: tsplus_module_1.record,
17
- tuple: tsplus_module_1.tuple,
18
- lazy: tsplus_module_1.deriveLazy,
19
- validation: tsplus_module_1.validation,
20
- union: (members, schema) => {
21
- const guards = schema.members.map(interpret(G.Schemable));
22
- return tsplus_module_1.makeEncoder(inp => {
23
- let encoder;
24
- for (let i = 0; i < guards.length; i++) {
25
- if (guards[i].is(inp)) {
26
- encoder = members[i];
27
- }
28
- }
29
- if (!encoder) {
30
- throw new Error("BUG: Encoder not found for union");
31
- }
32
- return encoder.encode(inp);
33
- });
34
- }
35
- };
36
- //# sourceMappingURL=Encoder.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Encoder.mjs","mappings":";;AAGA,SAASA,SAAS,QAAQ,sBAAsB;AAEhD,OAAO,KAAKC,CAAC,MAAM,aAAY;AAE/B,OAAO,MAAMC,SAAS,GAAgB;EACpCC,OAAO,yBAAiB;EACxBC,MAAM,wBAAU;EAChBC,MAAM,wBAAU;EAChBC,OAAO,yBAAU;EACjBC,MAAM,wBAAU;EAChBC,OAAO,yBAAiB;EACxBC,QAAQ,0BAAkB;EAC1BC,MAAM,wBAAgB;EACtBC,OAAO,yBAAiB;EACxBC,KAAK,+BAAuB;EAC5BC,MAAM,wBAAgB;EACtBC,KAAK,uBAA6B;EAClCC,IAAI,4BAAc;EAClBC,UAAU,4BAAkC;EAC5CC,KAAK,EAAE,CAACC,OAAO,EAAEC,MAAM,KAAI;IACzB,MAAMC,MAAM,GAAGD,MAAM,CAACD,OAAO,CAACG,GAAG,CAACrB,SAAS,CAACC,CAAC,CAACC,SAAS,CAAC,CAAC;IACzD,OAAOoB,4BAASC,GAAG,IAAI;MACrB,IAAIC,OAAiC;MACrC,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGL,MAAM,CAACM,MAAM,EAAED,CAAC,EAAE,EAAE;QACtC,IAAIL,MAAM,CAACK,CAAC,CAAE,CAACE,EAAE,CAACJ,GAAG,CAAC,EAAE;UACtBC,OAAO,GAAGN,OAAO,CAACO,CAAC,CAAE;;;MAGzB,IAAI,CAACD,OAAO,EAAE;QACZ,MAAM,IAAII,KAAK,CAAC,kCAAkC,CAAC;;MAErD,OAAOJ,OAAO,CAACK,MAAM,CAACN,GAAG,CAAC;IAC5B,CAAC,CAAC;EACJ;CACD","names":["interpret","G","Schemable","unknown","string","number","boolean","bigint","literal","nullable","struct","partial","array","record","tuple","lazy","validation","union","members","schema","guards","map","tsplus_module_1","inp","encoder","i","length","is","Error","encode"],"sourceRoot":"","sources":["../_src/Encoder.ts"],"sourcesContent":[null]}
package/_mjs/Guard.mjs DELETED
@@ -1,20 +0,0 @@
1
- import * as tsplus_module_1 from "@fncts/base/data/Guard/api";
2
- import * as tsplus_module_2 from "@fncts/base/data/function/api";
3
- export const Schemable = {
4
- unknown: tsplus_module_1.unknown,
5
- string: tsplus_module_1.string,
6
- number: tsplus_module_1.number,
7
- boolean: tsplus_module_1.boolean,
8
- bigint: tsplus_module_1.bigint,
9
- literal: tsplus_module_1.literal,
10
- nullable: tsplus_module_1.nullable,
11
- struct: tsplus_module_1.struct,
12
- partial: tsplus_module_1.partial,
13
- array: tsplus_module_1.readonlyArray,
14
- record: tsplus_module_1.record,
15
- tuple: tsplus_module_1.tuple,
16
- lazy: tsplus_module_1.deriveLazy,
17
- validation: tsplus_module_1.validation,
18
- union: members => tsplus_module_1.deriveUnion(...members)
19
- };
20
- //# sourceMappingURL=Guard.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Guard.mjs","mappings":";;AAGA,OAAO,MAAMA,SAAS,GAAc;EAClCC,OAAO,yBAAe;EACtBC,MAAM,wBAAU;EAChBC,MAAM,wBAAU;EAChBC,OAAO,yBAAU;EACjBC,MAAM,wBAAU;EAChBC,OAAO,yBAAe;EACtBC,QAAQ,0BAAgB;EACxBC,MAAM,wBAAc;EACpBC,OAAO,yBAAe;EACtBC,KAAK,+BAAqB;EAC1BC,MAAM,wBAAc;EACpBC,KAAK,uBAA2B;EAChCC,IAAI,4BAAY;EAChBC,UAAU,4BAAgC;EAC1CC,KAAK,EAAGC,OAAO,IAAKC,4BAAY,GAAGD,OAAO;CAC3C","names":["Schemable","unknown","string","number","boolean","bigint","literal","nullable","struct","partial","array","record","tuple","lazy","validation","union","members","tsplus_module_1"],"sourceRoot":"","sources":["../_src/Guard.ts"],"sourcesContent":[null]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Schemable.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Schemable.mjs","mappings":"","names":[],"sourceRoot":"","sources":[],"sourcesContent":[]}
package/_src/Decoder.ts DELETED
@@ -1,20 +0,0 @@
1
- import type { DecoderF } from "@fncts/base/data/Decoder";
2
- import type { Schemable as S } from "@fncts/schema/Schemable";
3
-
4
- export const Schemable: S<DecoderF> = {
5
- unknown: Decoder.unknown,
6
- string: Derive(),
7
- number: Derive(),
8
- boolean: Derive(),
9
- bigint: Derive(),
10
- literal: Decoder.literal,
11
- nullable: Decoder.nullable,
12
- struct: Decoder.struct,
13
- partial: Decoder.partial,
14
- array: Decoder.readonlyArray,
15
- record: Decoder.record,
16
- tuple: unsafeCoerce(Decoder.tuple),
17
- lazy: Decoder.lazy,
18
- validation: unsafeCoerce(Decoder.validation),
19
- union: (members) => Decoder.union(...members),
20
- };
package/_src/Encoder.ts DELETED
@@ -1,38 +0,0 @@
1
- import type { EncoderF } from "@fncts/base/data/Encoder";
2
- import type { Schemable as S } from "@fncts/schema/Schemable";
3
-
4
- import { interpret } from "@fncts/schema/Schema";
5
-
6
- import * as G from "./Guard.js";
7
-
8
- export const Schemable: S<EncoderF> = {
9
- unknown: Encoder.unknown,
10
- string: Derive(),
11
- number: Derive(),
12
- boolean: Derive(),
13
- bigint: Derive(),
14
- literal: Encoder.literal,
15
- nullable: Encoder.nullable,
16
- struct: Encoder.struct,
17
- partial: Encoder.partial,
18
- array: Encoder.readonlyArray,
19
- record: Encoder.record,
20
- tuple: unsafeCoerce(Encoder.tuple),
21
- lazy: Encoder.lazy,
22
- validation: unsafeCoerce(Encoder.validation),
23
- union: (members, schema) => {
24
- const guards = schema.members.map(interpret(G.Schemable));
25
- return Encoder((inp) => {
26
- let encoder: Encoder<any> | undefined;
27
- for (let i = 0; i < guards.length; i++) {
28
- if (guards[i]!.is(inp)) {
29
- encoder = members[i]!;
30
- }
31
- }
32
- if (!encoder) {
33
- throw new Error("BUG: Encoder not found for union");
34
- }
35
- return encoder.encode(inp);
36
- });
37
- },
38
- };
package/_src/Guard.ts DELETED
@@ -1,20 +0,0 @@
1
- import type { GuardF } from "@fncts/base/data/Guard";
2
- import type { Schemable as S } from "@fncts/schema/Schemable";
3
-
4
- export const Schemable: S<GuardF> = {
5
- unknown: Guard.unknown,
6
- string: Derive(),
7
- number: Derive(),
8
- boolean: Derive(),
9
- bigint: Derive(),
10
- literal: Guard.literal,
11
- nullable: Guard.nullable,
12
- struct: Guard.struct,
13
- partial: Guard.partial,
14
- array: Guard.readonlyArray,
15
- record: Guard.record,
16
- tuple: unsafeCoerce(Guard.tuple),
17
- lazy: Guard.lazy,
18
- validation: unsafeCoerce(Guard.validation),
19
- union: (members) => Guard.union(...members),
20
- };
package/_src/Schemable.ts DELETED
@@ -1,46 +0,0 @@
1
- import type { Brand, Validation } from "@fncts/base/data/Branded";
2
- import type { UnionSchema } from "@fncts/schema/Schema";
3
- import type { Literal } from "@fncts/typelevel/Any";
4
-
5
- export type SchemableKind<F extends HKT, A> = F extends { readonly type: unknown }
6
- ? (F & { readonly A: A })["type"]
7
- : {
8
- readonly _F: F;
9
- readonly _A: A;
10
- };
11
-
12
- export interface Schemable<F extends HKT> {
13
- readonly unknown: SchemableKind<F, unknown>;
14
- readonly string: SchemableKind<F, string>;
15
- readonly number: SchemableKind<F, number>;
16
- readonly boolean: SchemableKind<F, boolean>;
17
- readonly bigint: SchemableKind<F, bigint>;
18
- readonly literal: <A extends Literal>(literal: A) => SchemableKind<F, A>;
19
- readonly nullable: <A>(or: SchemableKind<F, A>) => SchemableKind<F, A | null | undefined>;
20
- readonly struct: <P extends Record<string, any>>(properties: {
21
- [K in keyof P]: SchemableKind<F, P[K]>;
22
- }) => SchemableKind<F, P>;
23
- readonly partial: <P extends Record<string, any>>(properties: {
24
- [K in keyof P]: SchemableKind<F, P[K]>;
25
- }) => SchemableKind<F, Partial<P>>;
26
- readonly array: <A>(item: SchemableKind<F, A>) => SchemableKind<F, ReadonlyArray<A>>;
27
- readonly record: <A>(codomain: SchemableKind<F, A>) => SchemableKind<F, Record<string, A>>;
28
- readonly tuple: <C extends ReadonlyArray<any>>(
29
- ...components: {
30
- [K in keyof C]: SchemableKind<F, C[K]>;
31
- }
32
- ) => SchemableKind<F, C>;
33
- readonly lazy: <A>(f: () => SchemableKind<F, A>) => SchemableKind<F, A>;
34
- readonly validation: <A, B extends ReadonlyArray<Validation<A, any>>>(
35
- ...validations: B
36
- ) => (
37
- base: SchemableKind<F, A>,
38
- ) => SchemableKind<
39
- F,
40
- A & { [K in keyof B]: B[K] extends Validation<any, infer S> ? Brand.Valid<A, S> : never }[number]
41
- >;
42
- readonly union: <A extends ReadonlyArray<any>>(
43
- members: { [K in keyof A]: SchemableKind<F, A[K]> },
44
- schema: UnionSchema<A>,
45
- ) => SchemableKind<F, A[number]>;
46
- }