@fncts/schema 0.0.6 → 0.0.8

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 (78) hide show
  1. package/Parser.d.ts +1 -0
  2. package/Schema/api/either.d.ts +19 -0
  3. package/Schema.d.ts +7 -0
  4. package/_cjs/AST.cjs +6 -5
  5. package/_cjs/AST.cjs.map +1 -1
  6. package/_cjs/ASTAnnotation.cjs.map +1 -1
  7. package/_cjs/ASTAnnotationMap.cjs.map +1 -1
  8. package/_cjs/Gen.cjs +4 -7
  9. package/_cjs/Gen.cjs.map +1 -1
  10. package/_cjs/InvalidInterpretationError.cjs.map +1 -1
  11. package/_cjs/ParseError.cjs +2 -1
  12. package/_cjs/ParseError.cjs.map +1 -1
  13. package/_cjs/ParseResult.cjs +4 -3
  14. package/_cjs/ParseResult.cjs.map +1 -1
  15. package/_cjs/Parser/api.cjs.map +1 -1
  16. package/_cjs/Parser/definition.cjs.map +1 -1
  17. package/_cjs/Parser/interpreter.cjs +2 -1
  18. package/_cjs/Parser/interpreter.cjs.map +1 -1
  19. package/_cjs/Parser.cjs +11 -0
  20. package/_cjs/Parser.cjs.map +1 -1
  21. package/_cjs/Schema/api/conc.cjs.map +1 -1
  22. package/_cjs/Schema/api/either.cjs +96 -0
  23. package/_cjs/Schema/api/either.cjs.map +1 -0
  24. package/_cjs/Schema/api/hashMap.cjs.map +1 -1
  25. package/_cjs/Schema/api/immutableArray.cjs.map +1 -1
  26. package/_cjs/Schema/api/list.cjs.map +1 -1
  27. package/_cjs/Schema/api/maybe.cjs +3 -2
  28. package/_cjs/Schema/api/maybe.cjs.map +1 -1
  29. package/_cjs/Schema/api.cjs +4 -3
  30. package/_cjs/Schema/api.cjs.map +1 -1
  31. package/_cjs/Schema/definition.cjs.map +1 -1
  32. package/_cjs/Schema/derivations.cjs.map +1 -1
  33. package/_cjs/Schema.cjs +77 -0
  34. package/_cjs/Schema.cjs.map +1 -1
  35. package/_cjs/global.cjs.map +1 -1
  36. package/_cjs/index.cjs.map +1 -1
  37. package/_cjs/utils.cjs.map +1 -1
  38. package/_mjs/AST.mjs +6 -5
  39. package/_mjs/AST.mjs.map +1 -1
  40. package/_mjs/ASTAnnotation.mjs.map +1 -1
  41. package/_mjs/ASTAnnotationMap.mjs.map +1 -1
  42. package/_mjs/Gen.mjs +4 -7
  43. package/_mjs/Gen.mjs.map +1 -1
  44. package/_mjs/InvalidInterpretationError.mjs.map +1 -1
  45. package/_mjs/ParseError.mjs +2 -1
  46. package/_mjs/ParseError.mjs.map +1 -1
  47. package/_mjs/ParseResult.mjs +4 -3
  48. package/_mjs/ParseResult.mjs.map +1 -1
  49. package/_mjs/Parser/api.mjs.map +1 -1
  50. package/_mjs/Parser/definition.mjs.map +1 -1
  51. package/_mjs/Parser/interpreter.mjs +2 -1
  52. package/_mjs/Parser/interpreter.mjs.map +1 -1
  53. package/_mjs/Parser.mjs +1 -0
  54. package/_mjs/Parser.mjs.map +1 -1
  55. package/_mjs/Schema/api/conc.mjs.map +1 -1
  56. package/_mjs/Schema/api/either.mjs +85 -0
  57. package/_mjs/Schema/api/either.mjs.map +1 -0
  58. package/_mjs/Schema/api/hashMap.mjs.map +1 -1
  59. package/_mjs/Schema/api/immutableArray.mjs.map +1 -1
  60. package/_mjs/Schema/api/list.mjs.map +1 -1
  61. package/_mjs/Schema/api/maybe.mjs +3 -2
  62. package/_mjs/Schema/api/maybe.mjs.map +1 -1
  63. package/_mjs/Schema/api.mjs +4 -3
  64. package/_mjs/Schema/api.mjs.map +1 -1
  65. package/_mjs/Schema/definition.mjs.map +1 -1
  66. package/_mjs/Schema/derivations.mjs.map +1 -1
  67. package/_mjs/Schema.mjs +9 -0
  68. package/_mjs/Schema.mjs.map +1 -1
  69. package/_mjs/global.mjs.map +1 -1
  70. package/_mjs/index.mjs.map +1 -1
  71. package/_mjs/utils.mjs.map +1 -1
  72. package/_src/Gen.ts +3 -6
  73. package/_src/Parser.ts +1 -0
  74. package/_src/Schema/api/either.ts +96 -0
  75. package/_src/Schema.ts +10 -0
  76. package/_src/global.ts +4 -0
  77. package/global.d.ts +4 -0
  78. package/package.json +2 -2
@@ -0,0 +1,96 @@
1
+ import type { EitherJson } from "@fncts/base/json/EitherJson";
2
+
3
+ import { EitherTypeId, EitherVariance } from "@fncts/base/data/Either";
4
+ import { IOTypeId } from "@fncts/io/IO";
5
+
6
+ /**
7
+ * @tsplus static fncts.schema.SchemaOps either
8
+ */
9
+ export function either<E, A>(left: Schema<E>, right: Schema<A>): Schema<Either<E, A>> {
10
+ return Schema.declaration(
11
+ Vector(left, right),
12
+ eitherInline(left, right),
13
+ eitherParser,
14
+ ASTAnnotationMap.empty.annotate(ASTAnnotation.Identifier, "Either"),
15
+ );
16
+ }
17
+
18
+ function eitherJson<E, A>(left: Schema<E>, right: Schema<A>): Schema<EitherJson<E, A>> {
19
+ return Schema.union(
20
+ Schema.struct({
21
+ _tag: Schema.literal("Left"),
22
+ left,
23
+ }),
24
+ Schema.struct({
25
+ _tag: Schema.literal("Right"),
26
+ right,
27
+ }),
28
+ );
29
+ }
30
+
31
+ /**
32
+ * @tsplus static fncts.schema.SchemaOps eitherFromJson
33
+ */
34
+ export function eitherFromJson<E, A>(left: Schema<E>, right: Schema<A>): Schema<Either<E, A>> {
35
+ return eitherJson(left, right).transform(
36
+ either(left, right),
37
+ (input) => {
38
+ if (input._tag === "Left") {
39
+ return Either.left(input.left);
40
+ } else {
41
+ return Either.right(input.right);
42
+ }
43
+ },
44
+ (input) => {
45
+ Either.concrete(input);
46
+ if (input.isLeft()) {
47
+ return {
48
+ _tag: "Left",
49
+ left: input.left,
50
+ } as const;
51
+ } else {
52
+ return {
53
+ _tag: "Right",
54
+ right: input.right,
55
+ } as const;
56
+ }
57
+ },
58
+ );
59
+ }
60
+
61
+ /**
62
+ * @tsplus derive fncts.schema.Schema[fncts.Either]<_> 10
63
+ */
64
+ export function deriveEither<A extends Either<any, any>>(
65
+ ...[left, right]: [A] extends [Either<infer _E, infer _A>]
66
+ ? Check<Check.IsEqual<A, Either<_E, _A>>> extends Check.True
67
+ ? [left: Schema<_E>, right: Schema<_A>]
68
+ : never
69
+ : never
70
+ ): Schema<A> {
71
+ return unsafeCoerce(eitherFromJson(left, right));
72
+ }
73
+
74
+ function eitherParser<E, A>(left: Schema<E>, right: Schema<A>): Parser<Either<E, A>> {
75
+ const schema = either(left, right);
76
+ return Parser.make((u, options) => {
77
+ if (!Either.isEither(u)) {
78
+ return ParseResult.fail(ParseError.TypeError(schema.ast, u));
79
+ }
80
+ Either.concrete(u);
81
+ if (u.isLeft()) {
82
+ return left.decode(u.left, options).map(Either.left);
83
+ } else {
84
+ return right.decode(u.right, options).map(Either.right);
85
+ }
86
+ });
87
+ }
88
+
89
+ function eitherInline<E, A>(_left: Schema<E>, _right: Schema<A>): Schema<Either<E, A>> {
90
+ return Schema.struct({
91
+ [EitherTypeId]: Schema.uniqueSymbol(EitherTypeId),
92
+ [EitherVariance]: Schema.any,
93
+ [IOTypeId]: Schema.uniqueSymbol(IOTypeId),
94
+ trace: Schema.undefined,
95
+ }) as unknown as Schema<Either<E, A>>;
96
+ }
package/_src/Schema.ts CHANGED
@@ -1,4 +1,14 @@
1
1
  // codegen:start { preset: barrel, include: ./Schema/*.ts }
2
2
  export * from "./Schema/api.js";
3
3
  export * from "./Schema/definition.js";
4
+ export * from "./Schema/derivations.js";
5
+ // codegen:end
6
+
7
+ // codegen:start { preset: barrel, include: ./Schema/api/*.ts }
8
+ export * from "./Schema/api/conc.js";
9
+ export * from "./Schema/api/either.js";
10
+ export * from "./Schema/api/hashMap.js";
11
+ export * from "./Schema/api/immutableArray.js";
12
+ export * from "./Schema/api/list.js";
13
+ export * from "./Schema/api/maybe.js";
4
14
  // codegen:end
package/_src/global.ts CHANGED
@@ -51,6 +51,10 @@ import { ParseResult } from "@fncts/schema/ParseResult";
51
51
  * @tsplus global
52
52
  */
53
53
  import { OptionalSchema, Schema } from "@fncts/schema/Schema/definition";
54
+ /**
55
+ * @tsplus global
56
+ */
57
+ import {} from "@fncts/schema/Schema"
54
58
  /**
55
59
  * @tsplus global
56
60
  */
package/global.d.ts CHANGED
@@ -50,6 +50,10 @@ import { ParseResult } from "@fncts/schema/ParseResult";
50
50
  * @tsplus global
51
51
  */
52
52
  import { OptionalSchema, Schema } from "@fncts/schema/Schema/definition";
53
+ /**
54
+ * @tsplus global
55
+ */
56
+ import {} from "@fncts/schema/Schema";
53
57
  /**
54
58
  * @tsplus global
55
59
  */
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@fncts/schema",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "dependencies": {
5
- "@fncts/base": "0.0.27",
5
+ "@fncts/base": "0.0.29",
6
6
  "@fncts/typelevel": "0.0.15"
7
7
  },
8
8
  "exports": {