@fncts/schema 0.0.16 → 0.0.18

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 (173) hide show
  1. package/AST.d.ts +19 -6
  2. package/ASTAnnotation.d.ts +10 -2
  3. package/ParseError/ParseError.d.ts +231 -0
  4. package/ParseError/ParseErrorFormatter.d.ts +2 -0
  5. package/ParseError/PathFormatter.d.ts +13 -0
  6. package/ParseError/TreeFormatter.d.ts +14 -0
  7. package/ParseError.d.ts +4 -144
  8. package/ParseResult.d.ts +1 -8
  9. package/Parser/interpreter.d.ts +0 -1
  10. package/Schema/api/conc.d.ts +0 -2
  11. package/Schema/api/hashMap.d.ts +0 -1
  12. package/Schema/api/hashSet.d.ts +0 -1
  13. package/Schema/api/immutableArray.d.ts +0 -1
  14. package/Schema/api/list.d.ts +1 -2
  15. package/Schema/api/map.d.ts +19 -0
  16. package/Schema/api/set.d.ts +19 -0
  17. package/Schema/api.d.ts +11 -1
  18. package/Schema.d.ts +2 -0
  19. package/Show.d.ts +7 -3
  20. package/_cjs/AST.cjs +181 -114
  21. package/_cjs/AST.cjs.map +1 -1
  22. package/_cjs/ASTAnnotation.cjs +7 -2
  23. package/_cjs/ASTAnnotation.cjs.map +1 -1
  24. package/_cjs/ASTAnnotationMap.cjs +1 -1
  25. package/_cjs/ASTAnnotationMap.cjs.map +1 -1
  26. package/_cjs/Gen.cjs +25 -25
  27. package/_cjs/Gen.cjs.map +1 -1
  28. package/_cjs/Guard.cjs +1 -1
  29. package/_cjs/Guard.cjs.map +1 -1
  30. package/_cjs/InvalidInterpretationError.cjs.map +1 -1
  31. package/_cjs/ParseError/ParseError.cjs +260 -0
  32. package/_cjs/ParseError/ParseError.cjs.map +1 -0
  33. package/_cjs/ParseError/ParseErrorFormatter.cjs +6 -0
  34. package/_cjs/ParseError/ParseErrorFormatter.cjs.map +1 -0
  35. package/_cjs/ParseError/PathFormatter.cjs +94 -0
  36. package/_cjs/ParseError/PathFormatter.cjs.map +1 -0
  37. package/_cjs/ParseError/TreeFormatter.cjs +123 -0
  38. package/_cjs/ParseError/TreeFormatter.cjs.map +1 -0
  39. package/_cjs/ParseError.cjs +43 -289
  40. package/_cjs/ParseError.cjs.map +1 -1
  41. package/_cjs/ParseResult.cjs +2 -11
  42. package/_cjs/ParseResult.cjs.map +1 -1
  43. package/_cjs/Parser/api.cjs +3 -3
  44. package/_cjs/Parser/api.cjs.map +1 -1
  45. package/_cjs/Parser/definition.cjs +2 -2
  46. package/_cjs/Parser/definition.cjs.map +1 -1
  47. package/_cjs/Parser/interpreter.cjs +122 -118
  48. package/_cjs/Parser/interpreter.cjs.map +1 -1
  49. package/_cjs/Parser.cjs.map +1 -1
  50. package/_cjs/Schema/api/conc.cjs +36 -46
  51. package/_cjs/Schema/api/conc.cjs.map +1 -1
  52. package/_cjs/Schema/api/either.cjs +25 -31
  53. package/_cjs/Schema/api/either.cjs.map +1 -1
  54. package/_cjs/Schema/api/hashMap.cjs +42 -102
  55. package/_cjs/Schema/api/hashMap.cjs.map +1 -1
  56. package/_cjs/Schema/api/hashSet.cjs +47 -107
  57. package/_cjs/Schema/api/hashSet.cjs.map +1 -1
  58. package/_cjs/Schema/api/immutableArray.cjs +23 -49
  59. package/_cjs/Schema/api/immutableArray.cjs.map +1 -1
  60. package/_cjs/Schema/api/list.cjs +36 -53
  61. package/_cjs/Schema/api/list.cjs.map +1 -1
  62. package/_cjs/Schema/api/map.cjs +97 -0
  63. package/_cjs/Schema/api/map.cjs.map +1 -0
  64. package/_cjs/Schema/api/maybe.cjs +25 -36
  65. package/_cjs/Schema/api/maybe.cjs.map +1 -1
  66. package/_cjs/Schema/api/set.cjs +76 -0
  67. package/_cjs/Schema/api/set.cjs.map +1 -0
  68. package/_cjs/Schema/api.cjs +21 -3
  69. package/_cjs/Schema/api.cjs.map +1 -1
  70. package/_cjs/Schema/definition.cjs +1 -1
  71. package/_cjs/Schema/definition.cjs.map +1 -1
  72. package/_cjs/Schema/derivations.cjs +1 -1
  73. package/_cjs/Schema/derivations.cjs.map +1 -1
  74. package/_cjs/Schema.cjs +22 -0
  75. package/_cjs/Schema.cjs.map +1 -1
  76. package/_cjs/Show.cjs +107 -90
  77. package/_cjs/Show.cjs.map +1 -1
  78. package/_cjs/global.cjs.map +1 -1
  79. package/_cjs/index.cjs.map +1 -1
  80. package/_cjs/utils.cjs +6 -1
  81. package/_cjs/utils.cjs.map +1 -1
  82. package/_mjs/AST.mjs +177 -112
  83. package/_mjs/AST.mjs.map +1 -1
  84. package/_mjs/ASTAnnotation.mjs +5 -0
  85. package/_mjs/ASTAnnotation.mjs.map +1 -1
  86. package/_mjs/ASTAnnotationMap.mjs.map +1 -1
  87. package/_mjs/Gen.mjs +24 -24
  88. package/_mjs/Gen.mjs.map +1 -1
  89. package/_mjs/Guard.mjs.map +1 -1
  90. package/_mjs/InvalidInterpretationError.mjs.map +1 -1
  91. package/_mjs/ParseError/ParseError.mjs +228 -0
  92. package/_mjs/ParseError/ParseError.mjs.map +1 -0
  93. package/_mjs/ParseError/ParseErrorFormatter.mjs +2 -0
  94. package/_mjs/ParseError/ParseErrorFormatter.mjs.map +1 -0
  95. package/_mjs/ParseError/PathFormatter.mjs +86 -0
  96. package/_mjs/ParseError/PathFormatter.mjs.map +1 -0
  97. package/_mjs/ParseError/TreeFormatter.mjs +113 -0
  98. package/_mjs/ParseError/TreeFormatter.mjs.map +1 -0
  99. package/_mjs/ParseError.mjs +6 -270
  100. package/_mjs/ParseError.mjs.map +1 -1
  101. package/_mjs/ParseResult.mjs +1 -9
  102. package/_mjs/ParseResult.mjs.map +1 -1
  103. package/_mjs/Parser/api.mjs +2 -2
  104. package/_mjs/Parser/api.mjs.map +1 -1
  105. package/_mjs/Parser/definition.mjs +1 -1
  106. package/_mjs/Parser/definition.mjs.map +1 -1
  107. package/_mjs/Parser/interpreter.mjs +121 -117
  108. package/_mjs/Parser/interpreter.mjs.map +1 -1
  109. package/_mjs/Parser.mjs.map +1 -1
  110. package/_mjs/Schema/api/conc.mjs +35 -44
  111. package/_mjs/Schema/api/conc.mjs.map +1 -1
  112. package/_mjs/Schema/api/either.mjs +24 -30
  113. package/_mjs/Schema/api/either.mjs.map +1 -1
  114. package/_mjs/Schema/api/hashMap.mjs +41 -101
  115. package/_mjs/Schema/api/hashMap.mjs.map +1 -1
  116. package/_mjs/Schema/api/hashSet.mjs +46 -106
  117. package/_mjs/Schema/api/hashSet.mjs.map +1 -1
  118. package/_mjs/Schema/api/immutableArray.mjs +23 -49
  119. package/_mjs/Schema/api/immutableArray.mjs.map +1 -1
  120. package/_mjs/Schema/api/list.mjs +35 -52
  121. package/_mjs/Schema/api/list.mjs.map +1 -1
  122. package/_mjs/Schema/api/map.mjs +88 -0
  123. package/_mjs/Schema/api/map.mjs.map +1 -0
  124. package/_mjs/Schema/api/maybe.mjs +24 -35
  125. package/_mjs/Schema/api/maybe.mjs.map +1 -1
  126. package/_mjs/Schema/api/set.mjs +67 -0
  127. package/_mjs/Schema/api/set.mjs.map +1 -0
  128. package/_mjs/Schema/api.mjs +18 -2
  129. package/_mjs/Schema/api.mjs.map +1 -1
  130. package/_mjs/Schema/definition.mjs.map +1 -1
  131. package/_mjs/Schema/derivations.mjs.map +1 -1
  132. package/_mjs/Schema.mjs +2 -0
  133. package/_mjs/Schema.mjs.map +1 -1
  134. package/_mjs/Show.mjs +106 -90
  135. package/_mjs/Show.mjs.map +1 -1
  136. package/_mjs/global.mjs.map +1 -1
  137. package/_mjs/index.mjs.map +1 -1
  138. package/_mjs/utils.mjs +4 -0
  139. package/_mjs/utils.mjs.map +1 -1
  140. package/_src/AST.ts +139 -38
  141. package/_src/ASTAnnotation.ts +8 -1
  142. package/_src/Gen.ts +4 -1
  143. package/_src/ParseError/ParseError.ts +304 -0
  144. package/_src/ParseError/ParseErrorFormatter.ts +1 -0
  145. package/_src/ParseError/PathFormatter.ts +117 -0
  146. package/_src/ParseError/TreeFormatter.ts +127 -0
  147. package/_src/ParseError.ts +7 -331
  148. package/_src/ParseResult.ts +2 -9
  149. package/_src/Parser/api.ts +1 -1
  150. package/_src/Parser/interpreter.ts +98 -75
  151. package/_src/Schema/api/conc.ts +33 -42
  152. package/_src/Schema/api/either.ts +20 -30
  153. package/_src/Schema/api/hashMap.ts +40 -124
  154. package/_src/Schema/api/hashSet.ts +31 -117
  155. package/_src/Schema/api/immutableArray.ts +15 -45
  156. package/_src/Schema/api/list.ts +32 -55
  157. package/_src/Schema/api/map.ts +93 -0
  158. package/_src/Schema/api/maybe.ts +19 -34
  159. package/_src/Schema/api/set.ts +74 -0
  160. package/_src/Schema/api.ts +20 -2
  161. package/_src/Schema.ts +2 -0
  162. package/_src/Show.ts +156 -128
  163. package/_src/global.ts +0 -4
  164. package/_src/utils.ts +6 -0
  165. package/global.d.ts +0 -4
  166. package/package.json +3 -3
  167. package/utils.d.ts +1 -0
  168. package/ParseFailure.d.ts +0 -18
  169. package/_cjs/ParseFailure.cjs +0 -28
  170. package/_cjs/ParseFailure.cjs.map +0 -1
  171. package/_mjs/ParseFailure.mjs +0 -20
  172. package/_mjs/ParseFailure.mjs.map +0 -1
  173. package/_src/ParseFailure.ts +0 -18
package/AST.d.ts CHANGED
@@ -17,6 +17,7 @@ export declare abstract class Annotated {
17
17
  export declare abstract class AST extends Annotated {
18
18
  readonly [ASTTypeId]: ASTTypeId;
19
19
  abstract clone(newProperties: Partial<this>): AST;
20
+ toString(verbose?: boolean): string;
20
21
  }
21
22
  export declare namespace AST {
22
23
  interface Compiler<A> {
@@ -61,20 +62,23 @@ export type Concrete = Declaration | Literal | UniqueSymbol | UndefinedKeyword |
61
62
  */
62
63
  export declare function concrete(_: AST): asserts _ is Concrete;
63
64
  export declare function getAnnotations<V>(key: ASTAnnotation<V>): (self: Annotated) => Maybe<V>;
65
+ /**
66
+ * @tsplus type fncts.schema.AST.Declaration
67
+ */
64
68
  export declare class Declaration extends AST {
65
69
  readonly typeParameters: Vector<AST>;
66
- readonly type: AST;
67
70
  readonly decode: (...typeParameters: ReadonlyArray<AST>) => (input: any, options?: ParseOptions) => ParseResult<any>;
71
+ readonly encode: (...typeParameters: ReadonlyArray<AST>) => (input: any, options?: ParseOptions) => ParseResult<any>;
68
72
  readonly annotations: ASTAnnotationMap;
69
73
  readonly _tag = ASTTag.Declaration;
70
- constructor(typeParameters: Vector<AST>, type: AST, decode: (...typeParameters: ReadonlyArray<AST>) => (input: any, options?: ParseOptions) => ParseResult<any>, annotations?: ASTAnnotationMap);
74
+ constructor(typeParameters: Vector<AST>, decode: (...typeParameters: ReadonlyArray<AST>) => (input: any, options?: ParseOptions) => ParseResult<any>, encode: (...typeParameters: ReadonlyArray<AST>) => (input: any, options?: ParseOptions) => ParseResult<any>, annotations?: ASTAnnotationMap);
71
75
  clone(newProperties: Partial<this>): AST;
72
76
  }
73
77
  /**
74
78
  * @tsplus static fncts.schema.ASTOps createDeclaration
75
79
  * @tsplus location "@fncts/schema/AST"
76
80
  */
77
- export declare function createDeclaration(typeParameters: Vector<AST>, type: AST, decode: (...typeParameters: ReadonlyArray<AST>) => (input: any, options?: ParseOptions) => ParseResult<any>, annotations?: ASTAnnotationMap): Declaration;
81
+ export declare function createDeclaration(typeParameters: Vector<AST>, decode: (...typeParameters: ReadonlyArray<AST>) => (input: any, options?: ParseOptions) => ParseResult<any>, encode: (...typeParameters: ReadonlyArray<AST>) => (input: any, options?: ParseOptions) => ParseResult<any>, annotations?: ASTAnnotationMap): Declaration;
78
82
  /**
79
83
  * @tsplus fluent fncts.schema.AST isDeclaration
80
84
  * @tsplus location "@fncts/schema/AST"
@@ -277,6 +281,7 @@ export declare class TemplateLiteralSpan {
277
281
  readonly type: StringKeyword | NumberKeyword;
278
282
  readonly literal: string;
279
283
  constructor(type: StringKeyword | NumberKeyword, literal: string);
284
+ toString(): "${string}" | "${number}";
280
285
  }
281
286
  export declare class TemplateLiteral extends AST {
282
287
  readonly head: string;
@@ -295,6 +300,7 @@ export declare class Element {
295
300
  readonly type: AST;
296
301
  readonly isOptional: boolean;
297
302
  constructor(type: AST, isOptional: boolean);
303
+ toString(): string;
298
304
  }
299
305
  /**
300
306
  * @tsplus static fncts.schema.ASTOps createElement
@@ -320,14 +326,14 @@ export declare function createTuple(elements: Vector<Element>, rest: Maybe<Vecto
320
326
  * @tsplus location "@fncts/schema/AST"
321
327
  */
322
328
  export declare const unknownArray: Tuple;
323
- export declare class PropertySignature extends AST {
329
+ export declare class PropertySignature {
324
330
  readonly name: PropertyKey;
325
331
  readonly type: AST;
326
332
  readonly isOptional: boolean;
327
333
  readonly isReadonly: boolean;
328
334
  readonly annotations: ASTAnnotationMap;
329
335
  constructor(name: PropertyKey, type: AST, isOptional: boolean, isReadonly: boolean, annotations?: ASTAnnotationMap);
330
- clone(newProperties: Partial<this>): AST;
336
+ clone(newProperties: Partial<this>): PropertySignature;
331
337
  }
332
338
  /**
333
339
  * @tsplus static fncts.schema.ASTOps createPropertySignature
@@ -454,7 +460,8 @@ export declare function createValidation(from: AST, validation: Vector<Validatio
454
460
  * @tsplus tailRec
455
461
  */
456
462
  export declare function getCardinality(ast: AST): number;
457
- export declare function getWeight(ast: AST): number;
463
+ export type Weight = readonly [number, number, number];
464
+ export declare function getWeight(ast: AST): Weight;
458
465
  /**
459
466
  * @tsplus pipeable fncts.schema.AST combineAnnotations
460
467
  * @tsplus location "@fncts/schema/AST"
@@ -538,8 +545,14 @@ export declare function getSearchTree(members: Vector<AST>, isDecoding: boolean)
538
545
  buckets: {
539
546
  [literal: string]: ReadonlyArray<AST>;
540
547
  };
548
+ literals: ReadonlyArray<Literal>;
541
549
  ast: AST;
542
550
  };
543
551
  };
544
552
  otherwise: ReadonlyArray<AST>;
545
553
  };
554
+ /**
555
+ * @tsplus pipeable fncts.schema.AST getFormattedExpected
556
+ * @tsplus location "@fncts/schema/AST"
557
+ */
558
+ export declare function getFormattedExpected(verbose?: boolean): (self: AST) => Maybe<string>;
@@ -1,7 +1,9 @@
1
1
  import { Hashable } from "@fncts/base/data/Hashable";
2
2
  import { Equatable } from "@fncts/base/data/Equatable";
3
3
  import { Tag } from "@fncts/base/data/Tag/definition";
4
+ import { ParseError } from "@fncts/schema/ParseError";
4
5
  import { Vector } from "@fncts/base/collection/immutable/Vector";
6
+ import { AST } from "@fncts/schema/AST";
5
7
  import type { Validation } from "@fncts/base/data/Branded";
6
8
  export declare const ASTAnnotationVariance: unique symbol;
7
9
  export type ASTAnnotationVariance = typeof ASTAnnotationVariance;
@@ -42,12 +44,12 @@ export declare const DescriptionTag: import("@fncts/base/data/Tag").Tag<string,
42
44
  * @tsplus location "@fncts/schema/ASTAnnotation"
43
45
  */
44
46
  export declare const Description: ASTAnnotation<string>;
45
- export declare const MessageTag: import("@fncts/base/data/Tag").Tag<(_: unknown) => string, (_: unknown) => string>;
47
+ export declare const MessageTag: import("@fncts/base/data/Tag").Tag<(error: ParseError) => string, (error: ParseError) => string>;
46
48
  /**
47
49
  * @tsplus static fncts.schema.ASTAnnotationOps Message
48
50
  * @tsplus location "@fncts/schema/ASTAnnotation"
49
51
  */
50
- export declare const Message: ASTAnnotation<(_: unknown) => string>;
52
+ export declare const Message: ASTAnnotation<(error: ParseError) => string>;
51
53
  export declare const BrandTag: import("@fncts/base/data/Tag").Tag<import("@fncts/base/collection/immutable/Vector").Vector<Validation<any, any>>, import("@fncts/base/collection/immutable/Vector").Vector<Validation<any, any>>>;
52
54
  /**
53
55
  * @tsplus static fncts.schema.ASTAnnotationOps Brand
@@ -66,6 +68,12 @@ export declare const ParseOptionalTag: import("@fncts/base/data/Tag").Tag<boolea
66
68
  * @tsplus location "@fncts/schema/ASTAnnotation"
67
69
  */
68
70
  export declare const ParseOptional: ASTAnnotation<boolean>;
71
+ export declare const SurrogateTag: import("@fncts/base/data/Tag").Tag<import("./AST").AST, import("./AST").AST>;
72
+ /**
73
+ * @tsplus static fncts.schema.ASTAnnotationOps Surrogate
74
+ * @tsplus location "@fncts/schema/ASTAnnotation"
75
+ */
76
+ export declare const Surrogate: ASTAnnotation<import("./AST").AST>;
69
77
  export type Hook<A> = (...typeParameters: ReadonlyArray<A>) => A;
70
78
  export declare function hook(handler: (...typeParameters: ReadonlyArray<any>) => any): Hook<any>;
71
79
  export declare const ParserHookTag: import("@fncts/base/data/Tag").Tag<Hook<any>, Hook<any>>;
@@ -0,0 +1,231 @@
1
+ import { AST } from "@fncts/schema/AST";
2
+ import { Vector } from "@fncts/base/collection/immutable/Vector";
3
+ import type { Declaration, Refinement, Transform, Tuple, TypeLiteral, Union } from "@fncts/schema/AST";
4
+ export declare const enum ParseErrorTag {
5
+ Declaration = 0,
6
+ Type = 1,
7
+ Index = 2,
8
+ Key = 3,
9
+ Missing = 4,
10
+ Unexpected = 5,
11
+ UnionMember = 6,
12
+ Refinement = 7,
13
+ Transformation = 8,
14
+ TypeLiteral = 9,
15
+ Tuple = 10,
16
+ Union = 11,
17
+ Iterable = 12
18
+ }
19
+ /**
20
+ * @tsplus type fncts.schema.ParseError
21
+ * @tsplus companion fncts.schema.ParseErrorOps
22
+ */
23
+ export type ParseError = DeclarationError | TypeError | RefinementError | TransformationError | TypeLiteralError | TupleError | UnionError | IterableError;
24
+ /**
25
+ * @tsplus companion fncts.schema.ParseError.DeclarationError
26
+ */
27
+ export declare class DeclarationError {
28
+ readonly ast: Declaration;
29
+ readonly actual: unknown;
30
+ readonly error: ParseError;
31
+ readonly _tag = ParseErrorTag.Declaration;
32
+ constructor(ast: Declaration, actual: unknown, error: ParseError);
33
+ }
34
+ /**
35
+ * @tsplus static fncts.schema.ParseError.DeclarationError __call
36
+ * @tsplus static fncts.schema.ParseErrorOps DeclarationError
37
+ * @tsplus location "@fncts/schema/ParseError/ParseError"
38
+ */
39
+ export declare function declarationError(ast: Declaration, actual: unknown, error: ParseError): DeclarationError;
40
+ /**
41
+ * @tsplus companion fncts.schema.ParseError.TypeError
42
+ */
43
+ export declare class TypeError {
44
+ readonly ast: AST;
45
+ readonly actual: unknown;
46
+ readonly _tag = ParseErrorTag.Type;
47
+ constructor(ast: AST, actual: unknown);
48
+ }
49
+ /**
50
+ * @tsplus static fncts.schema.ParseError.TypeError __call
51
+ * @tsplus static fncts.schema.ParseErrorOps TypeError
52
+ * @tsplus location "@fncts/schema/ParseError/ParseError"
53
+ */
54
+ export declare function typeError(expected: AST, actual: unknown): TypeError;
55
+ /**
56
+ * @tsplus companion fncts.schema.ParseError.TypeLiteralError
57
+ */
58
+ export declare class TypeLiteralError {
59
+ readonly ast: TypeLiteral;
60
+ readonly actual: unknown;
61
+ readonly errors: Vector<KeyError>;
62
+ readonly output: {
63
+ readonly [x: string]: unknown;
64
+ };
65
+ readonly _tag = ParseErrorTag.TypeLiteral;
66
+ constructor(ast: TypeLiteral, actual: unknown, errors: Vector<KeyError>, output?: {
67
+ readonly [x: string]: unknown;
68
+ });
69
+ }
70
+ /**
71
+ * @tsplus static fncts.schema.ParseError.TypeLiteralError __call
72
+ * @tsplus static fncts.schema.ParseErrorOps TypeLiteralError
73
+ * @tsplus location "@fncts/schema/ParseError/ParseError"
74
+ */
75
+ export declare function typeLiteralError(ast: TypeLiteral, actual: unknown, errors: Vector<KeyError>, output?: {
76
+ readonly [x: string]: unknown;
77
+ }): TypeLiteralError;
78
+ /**
79
+ * @tsplus companion fncts.schema.ParseError.TupleError
80
+ */
81
+ export declare class TupleError {
82
+ readonly ast: Tuple;
83
+ readonly actual: unknown;
84
+ readonly errors: Vector<IndexError>;
85
+ readonly output: ReadonlyArray<unknown>;
86
+ readonly _tag = ParseErrorTag.Tuple;
87
+ constructor(ast: Tuple, actual: unknown, errors: Vector<IndexError>, output?: ReadonlyArray<unknown>);
88
+ }
89
+ /**
90
+ * @tsplus static fncts.schema.ParseError.TupleError __call
91
+ * @tsplus static fncts.schema.ParseErrorOps TupleError
92
+ * @tsplus location "@fncts/schema/ParseError/ParseError"
93
+ */
94
+ export declare function tupleError(ast: Tuple, actual: unknown, errors: Vector<IndexError>, output?: ReadonlyArray<unknown>): TupleError;
95
+ /**
96
+ * @tsplus companion fncts.schema.ParseError.IndexError
97
+ */
98
+ export declare class IndexError {
99
+ readonly index: number;
100
+ readonly error: ParseError | MissingError | UnexpectedError;
101
+ readonly _tag = ParseErrorTag.Index;
102
+ constructor(index: number, error: ParseError | MissingError | UnexpectedError);
103
+ }
104
+ /**
105
+ * @tsplus static fncts.schema.ParseError.IndexError __call
106
+ * @tsplus static fncts.schema.ParseErrorOps IndexError
107
+ * @tsplus location "@fncts/schema/ParseError/ParseError"
108
+ */
109
+ export declare function indexError(index: number, error: ParseError | MissingError | UnexpectedError): IndexError;
110
+ /**
111
+ * @tsplus companion fncts.schema.ParseError.KeyError
112
+ */
113
+ export declare class KeyError {
114
+ readonly keyAST: AST;
115
+ readonly key: any;
116
+ readonly error: ParseError | MissingError | UnexpectedError;
117
+ readonly _tag = ParseErrorTag.Key;
118
+ constructor(keyAST: AST, key: any, error: ParseError | MissingError | UnexpectedError);
119
+ }
120
+ /**
121
+ * @tsplus static fncts.schema.ParseError.KeyError __call
122
+ * @tsplus static fncts.schema.ParseErrorOps KeyError
123
+ * @tsplus location "@fncts/schema/ParseError/ParseError"
124
+ */
125
+ export declare function keyError(keyAST: AST, key: any, error: ParseError | MissingError | UnexpectedError): KeyError;
126
+ /**
127
+ * @tsplus companion fncts.schema.ParseError.MissingError
128
+ */
129
+ export declare class MissingError {
130
+ readonly _tag = ParseErrorTag.Missing;
131
+ }
132
+ /**
133
+ * @tsplus static fncts.schema.ParseErrorOps MissingError
134
+ * @tsplus location "@fncts/schema/ParseError/ParseError"
135
+ */
136
+ export declare const missingError: MissingError;
137
+ /**
138
+ * @tsplus companion fncts.schema.ParseError.UnexpectedError
139
+ */
140
+ export declare class UnexpectedError {
141
+ readonly actual: unknown;
142
+ readonly _tag = ParseErrorTag.Unexpected;
143
+ constructor(actual: unknown);
144
+ }
145
+ /**
146
+ * @tsplus static fncts.schema.ParseError.UnexpectedError __call
147
+ * @tsplus static fncts.schema.ParseErrorOps UnexpectedError
148
+ * @tsplus location "@fncts/schema/ParseError/ParseError"
149
+ */
150
+ export declare function unexpectedError(actual: unknown): UnexpectedError;
151
+ /**
152
+ * @tsplus companion fncts.schema.ParseError.UnionError
153
+ */
154
+ export declare class UnionError {
155
+ readonly ast: Union;
156
+ readonly actual: unknown;
157
+ readonly errors: Vector<TypeError | TypeLiteralError | UnionMemberError>;
158
+ readonly _tag = ParseErrorTag.Union;
159
+ constructor(ast: Union, actual: unknown, errors: Vector<TypeError | TypeLiteralError | UnionMemberError>);
160
+ }
161
+ /**
162
+ * @tsplus static fncts.schema.ParseError.UnionError __call
163
+ * @tsplus static fncts.schema.ParseErrorOps UnionError
164
+ * @tsplus location "@fncts/schema/ParseError/ParseError"
165
+ */
166
+ export declare function unionError(ast: Union, actual: unknown, errors: Vector<TypeError | TypeLiteralError | UnionMemberError>): UnionError;
167
+ /**
168
+ * @tsplus companion fncts.schema.ParseError.UnionMemberError
169
+ */
170
+ export declare class UnionMemberError {
171
+ readonly ast: AST;
172
+ readonly error: ParseError;
173
+ readonly _tag = ParseErrorTag.UnionMember;
174
+ constructor(ast: AST, error: ParseError);
175
+ }
176
+ /**
177
+ * @tsplus static fncts.schema.ParseError.UnionMemberError __call
178
+ * @tsplus static fncts.schema.ParseErrorOps UnionMemberError
179
+ * @tsplus location "@fncts/schema/ParseError/ParseError"
180
+ */
181
+ export declare function unionMemberError(ast: AST, error: ParseError): UnionMemberError;
182
+ /**
183
+ * @tsplus companion fncts.schema.ParseError.RefinementError
184
+ */
185
+ export declare class RefinementError {
186
+ readonly ast: Refinement;
187
+ readonly actual: unknown;
188
+ readonly kind: "From" | "Predicate";
189
+ readonly error: ParseError;
190
+ readonly _tag = ParseErrorTag.Refinement;
191
+ constructor(ast: Refinement, actual: unknown, kind: "From" | "Predicate", error: ParseError);
192
+ }
193
+ /**
194
+ * @tsplus static fncts.schema.ParseError.RefinementError __call
195
+ * @tsplus static fncts.schema.ParseErrorOps RefinementError
196
+ * @tsplus location "@fncts/schema/ParseError/ParseError"
197
+ */
198
+ export declare function refinementError(ast: Refinement, actual: unknown, kind: "From" | "Predicate", error: ParseError): ParseError;
199
+ /**
200
+ * @tsplus companion fncts.schema.ParseError.TransformationError
201
+ */
202
+ export declare class TransformationError {
203
+ readonly ast: Transform;
204
+ readonly actual: unknown;
205
+ readonly kind: "Encoded" | "Transformation" | "Type";
206
+ readonly error: ParseError;
207
+ readonly _tag = ParseErrorTag.Transformation;
208
+ constructor(ast: Transform, actual: unknown, kind: "Encoded" | "Transformation" | "Type", error: ParseError);
209
+ }
210
+ /**
211
+ * @tsplus static fncts.schema.ParseError.TransformationError __call
212
+ * @tsplus static fncts.schema.ParseErrorOps TransformationError
213
+ * @tsplus location "@fncts/schema/ParseError/ParseError"
214
+ */
215
+ export declare function transformationError(ast: Transform, actual: unknown, kind: "Encoded" | "Transformation" | "Type", error: ParseError): ParseError;
216
+ /**
217
+ * @tsplus companion fncts.schema.ParseError.IterableError
218
+ */
219
+ export declare class IterableError {
220
+ readonly ast: AST;
221
+ readonly actual: unknown;
222
+ readonly errors: Vector<IndexError | KeyError>;
223
+ readonly _tag = ParseErrorTag.Iterable;
224
+ constructor(ast: AST, actual: unknown, errors: Vector<IndexError | KeyError>);
225
+ }
226
+ /**
227
+ * @tsplus static fncts.schema.ParseError.IterableError __call
228
+ * @tsplus static fncts.schema.ParseErrorOps IterableError
229
+ * @tsplus location "@fncts/schema/ParseError/ParseError"
230
+ */
231
+ export declare function iterableError(ast: AST, actual: unknown, errors: Vector<IndexError | KeyError>): IterableError;
@@ -0,0 +1,2 @@
1
+ import { ParseError } from "@fncts/schema/ParseError";
2
+ export type ParseErrorFormatter = (error: ParseError) => string;
@@ -0,0 +1,13 @@
1
+ import { ParseError } from "@fncts/schema/ParseError";
2
+ import { Lazy } from "@fncts/base/data/function/definition";
3
+ import { ParseErrorTag } from "./ParseError.js";
4
+ export interface ParseErrorFlat {
5
+ type: ParseErrorTag;
6
+ path: Array<string | number | symbol>;
7
+ message: string;
8
+ }
9
+ /**
10
+ * @tsplus getter fncts.schema.ParseError flatten
11
+ * @tsplus location "@fncts/schema/ParseError/PathFormatter"
12
+ */
13
+ export declare function flatten(error: ParseError): Array<ParseErrorFlat>;
@@ -0,0 +1,14 @@
1
+ import { ParseError } from "@fncts/schema/ParseError";
2
+ import { Maybe } from "@fncts/base/data/Maybe/definition";
3
+ import { Vector } from "@fncts/base/collection/immutable/Vector";
4
+ import { RoseTree } from "@fncts/base/collection/immutable/RoseTree";
5
+ import { Lazy } from "@fncts/base/data/function/definition";
6
+ import type { TypeError } from "./ParseError";
7
+ /**
8
+ * @tsplus static fncts.schema.ParseErrorOps drawTree
9
+ * @tsplus getter fncts.schema.ParseError drawTree
10
+ * @tsplus location "@fncts/schema/ParseError/TreeFormatter"
11
+ */
12
+ export declare function format(error: ParseError): string;
13
+ export declare function getMessage(error: ParseError): Maybe<string>;
14
+ export declare function formatTypeError(error: TypeError): string;
package/ParseError.d.ts CHANGED
@@ -1,144 +1,4 @@
1
- import { AST } from "@fncts/schema/AST";
2
- import { Vector } from "@fncts/base/collection/immutable/Vector";
3
- import { Maybe } from "@fncts/base/data/Maybe/definition";
4
- import { RoseTree } from "@fncts/base/collection/immutable/RoseTree";
5
- import type { Refinement, Transform } from "@fncts/schema/AST";
6
- export declare const enum ParseErrorTag {
7
- Type = 0,
8
- Index = 1,
9
- Key = 2,
10
- Missing = 3,
11
- Unexpected = 4,
12
- UnionMember = 5,
13
- Refinement = 6,
14
- Transformation = 7
15
- }
16
- /**
17
- * @tsplus type fncts.schema.ParseError
18
- * @tsplus companion fncts.schema.ParseErrorOps
19
- */
20
- export type ParseError = TypeError | IndexError | KeyError | MissingError | UnexpectedError | UnionMemberError | RefinementError | TransformationError;
21
- /**
22
- * @tsplus companion fncts.schema.ParseError.TypeError
23
- */
24
- export declare class TypeError {
25
- readonly expected: AST;
26
- readonly actual: unknown;
27
- readonly _tag = ParseErrorTag.Type;
28
- constructor(expected: AST, actual: unknown);
29
- }
30
- /**
31
- * @tsplus static fncts.schema.ParseError.TypeError __call
32
- * @tsplus static fncts.schema.ParseErrorOps TypeError
33
- * @tsplus location "@fncts/schema/ParseError"
34
- */
35
- export declare function typeError(expected: AST, actual: unknown): ParseError;
36
- /**
37
- * @tsplus companion fncts.schema.ParseError.IndexError
38
- */
39
- export declare class IndexError {
40
- readonly index: number;
41
- readonly errors: Vector<ParseError>;
42
- readonly _tag = ParseErrorTag.Index;
43
- constructor(index: number, errors: Vector<ParseError>);
44
- }
45
- /**
46
- * @tsplus static fncts.schema.ParseError.IndexError __call
47
- * @tsplus static fncts.schema.ParseErrorOps IndexError
48
- * @tsplus location "@fncts/schema/ParseError"
49
- */
50
- export declare function indexError(index: number, errors: Vector<ParseError>): ParseError;
51
- /**
52
- * @tsplus companion fncts.schema.ParseError.KeyError
53
- */
54
- export declare class KeyError {
55
- readonly keyAST: AST;
56
- readonly key: any;
57
- readonly errors: Vector<ParseError>;
58
- readonly _tag = ParseErrorTag.Key;
59
- constructor(keyAST: AST, key: any, errors: Vector<ParseError>);
60
- }
61
- /**
62
- * @tsplus static fncts.schema.ParseError.KeyError __call
63
- * @tsplus static fncts.schema.ParseErrorOps KeyError
64
- * @tsplus location "@fncts/schema/ParseError"
65
- */
66
- export declare function keyError(keyAST: AST, key: any, errors: Vector<ParseError>): ParseError;
67
- /**
68
- * @tsplus companion fncts.schema.ParseError.MissingError
69
- */
70
- export declare class MissingError {
71
- readonly _tag = ParseErrorTag.Missing;
72
- }
73
- /**
74
- * @tsplus static fncts.schema.ParseErrorOps MissingError
75
- * @tsplus location "@fncts/schema/ParseError"
76
- */
77
- export declare const missingError: MissingError;
78
- /**
79
- * @tsplus companion fncts.schema.ParseError.UnexpectedError
80
- */
81
- export declare class UnexpectedError {
82
- readonly actual: unknown;
83
- readonly _tag = ParseErrorTag.Unexpected;
84
- constructor(actual: unknown);
85
- }
86
- /**
87
- * @tsplus static fncts.schema.ParseError.UnexpectedError __call
88
- * @tsplus static fncts.schema.ParseErrorOps UnexpectedError
89
- * @tsplus location "@fncts/schema/ParseError"
90
- */
91
- export declare function unexpectedError(actual: unknown): ParseError;
92
- /**
93
- * @tsplus companion fncts.schema.ParseError.UnionMemberError
94
- */
95
- export declare class UnionMemberError {
96
- readonly errors: Vector<ParseError>;
97
- readonly _tag = ParseErrorTag.UnionMember;
98
- constructor(errors: Vector<ParseError>);
99
- }
100
- /**
101
- * @tsplus static fncts.schema.ParseError.UnionMemberError __call
102
- * @tsplus static fncts.schema.ParseErrorOps UnionMemberError
103
- * @tsplus location "@fncts/schema/ParseError"
104
- */
105
- export declare function unionMemberError(errors: Vector<ParseError>): ParseError;
106
- /**
107
- * @tsplus companion fncts.schema.ParseError.RefinementError
108
- */
109
- export declare class RefinementError {
110
- readonly ast: Refinement;
111
- readonly actual: unknown;
112
- readonly kind: "From" | "Predicate";
113
- readonly errors: Vector<ParseError>;
114
- readonly _tag = ParseErrorTag.Refinement;
115
- constructor(ast: Refinement, actual: unknown, kind: "From" | "Predicate", errors: Vector<ParseError>);
116
- }
117
- /**
118
- * @tsplus static fncts.schema.ParseError.RefinementError __call
119
- * @tsplus static fncts.schema.ParseErrorOps RefinementError
120
- * @tsplus location "@fncts/schema/ParseError"
121
- */
122
- export declare function refinementError(ast: Refinement, actual: unknown, kind: "From" | "Predicate", errors: Vector<ParseError>): ParseError;
123
- /**
124
- * @tsplus companion fncts.schema.ParseError.TransformationError
125
- */
126
- export declare class TransformationError {
127
- readonly ast: Transform;
128
- readonly actual: unknown;
129
- readonly kind: "Encoded" | "Transformation" | "Type";
130
- readonly errors: Vector<ParseError>;
131
- readonly _tag = ParseErrorTag.Transformation;
132
- constructor(ast: Transform, actual: unknown, kind: "Encoded" | "Transformation" | "Type", errors: Vector<ParseError>);
133
- }
134
- /**
135
- * @tsplus static fncts.schema.ParseError.TransformationError __call
136
- * @tsplus static fncts.schema.ParseErrorOps TransformationError
137
- * @tsplus location "@fncts/schema/ParseError"
138
- */
139
- export declare function transformationError(ast: Transform, actual: unknown, kind: "Encoded" | "Transformation" | "Type", errors: Vector<ParseError>): ParseError;
140
- /**
141
- * @tsplus static fncts.schema.ParseErrorOps format
142
- * @tsplus location "@fncts/schema/ParseError"
143
- */
144
- export declare function format(errors: Vector<ParseError>): string;
1
+ export * from "./ParseError/TreeFormatter.js";
2
+ export * from "./ParseError/PathFormatter.js";
3
+ export * from "./ParseError/ParseErrorFormatter.js";
4
+ export * from "./ParseError/ParseError.js";
package/ParseResult.d.ts CHANGED
@@ -1,23 +1,16 @@
1
1
  import { Either } from "@fncts/base/data/Either/definition";
2
- import { ParseFailure } from "@fncts/schema/ParseFailure";
3
- import { Vector } from "@fncts/base/collection/immutable/Vector";
4
2
  import { ParseError } from "@fncts/schema/ParseError";
5
3
  /**
6
4
  * @tsplus type fncts.schema.ParseResult
7
5
  * @tsplus companion fncts.schema.ParseResultOps
8
6
  */
9
- export interface ParseResult<A> extends Either<ParseFailure, A> {
7
+ export interface ParseResult<A> extends Either<ParseError, A> {
10
8
  }
11
9
  /**
12
10
  * @tsplus static fncts.schema.ParseResultOps succeed
13
11
  * @tsplus location "@fncts/schema/ParseResult"
14
12
  */
15
13
  export declare function succeed<A>(value: A): ParseResult<A>;
16
- /**
17
- * @tsplus static fncts.schema.ParseResultOps failures
18
- * @tsplus location "@fncts/schema/ParseResult"
19
- */
20
- export declare function failures<A = never>(value: Vector<ParseError>): ParseResult<A>;
21
14
  /**
22
15
  * @tsplus static fncts.schema.ParseResultOps fail
23
16
  * @tsplus location "@fncts/schema/ParseResult"
@@ -1,5 +1,4 @@
1
1
  import { AST } from "@fncts/schema/AST";
2
2
  import { Parser } from "@fncts/schema/Parser/definition";
3
- import { ParseError } from "@fncts/schema/ParseError";
4
3
  import { ParseResult } from "@fncts/schema/ParseResult";
5
4
  export declare function parserFor(ast: AST, isDecoding: boolean): Parser<any>;
@@ -2,7 +2,6 @@ import { Schema } from "@fncts/schema/Schema/definition";
2
2
  import { Conc } from "@fncts/base/collection/immutable/Conc";
3
3
  import { Check } from "@fncts/typelevel";
4
4
  import { Parser } from "@fncts/schema/Parser/definition";
5
- import { ParseError } from "@fncts/schema/ParseError";
6
5
  import { Gen } from "@fncts/test/control/Gen";
7
6
  export declare function conc<A>(value: Schema<A>): Schema<Conc<A>>;
8
7
  /**
@@ -15,4 +14,3 @@ export declare function concFromArray<A>(value: Schema<A>): Schema<Conc<A>>;
15
14
  * @tsplus location "@fncts/schema/Schema/api/conc"
16
15
  */
17
16
  export declare function deriveConc<A extends Conc<any>>(...[value]: [A] extends [Conc<infer _A>] ? Check<Check.IsEqual<A, Conc<_A>>> extends Check.True ? [value: Schema<_A>] : never : never): Schema<A>;
18
- export declare function concParser<A>(value: Schema<A>): Parser<Conc<A>>;
@@ -1,6 +1,5 @@
1
1
  import { Schema } from "@fncts/schema/Schema/definition";
2
2
  import { Parser } from "@fncts/schema/Parser/definition";
3
- import { ParseError } from "@fncts/schema/ParseError";
4
3
  import { Gen } from "@fncts/test/control/Gen";
5
4
  import type { Check } from "@fncts/typelevel";
6
5
  import { HashMap } from "@fncts/base/collection/immutable/HashMap";
@@ -2,7 +2,6 @@ import { Schema } from "@fncts/schema/Schema/definition";
2
2
  import { HashSet } from "@fncts/base/collection/immutable/HashSet/definition";
3
3
  import { Check } from "@fncts/typelevel";
4
4
  import { Parser } from "@fncts/schema/Parser/definition";
5
- import { ParseError } from "@fncts/schema/ParseError";
6
5
  import { Gen } from "@fncts/test/control/Gen";
7
6
  export declare function hashSet<A>(value: Schema<A>): Schema<HashSet<A>>;
8
7
  /**
@@ -1,7 +1,6 @@
1
1
  import { Schema } from "@fncts/schema/Schema/definition";
2
2
  import { Check } from "@fncts/typelevel";
3
3
  import { Parser } from "@fncts/schema/Parser/definition";
4
- import { ParseError } from "@fncts/schema/ParseError";
5
4
  import { Gen } from "@fncts/test/control/Gen";
6
5
  import { ImmutableArray } from "@fncts/base/collection/immutable/ImmutableArray";
7
6
  /**
@@ -1,8 +1,7 @@
1
1
  import { Schema } from "@fncts/schema/Schema/definition";
2
- import { List, Nil, Cons } from "@fncts/base/collection/immutable/List/definition";
2
+ import { List } from "@fncts/base/collection/immutable/List/definition";
3
3
  import { Check } from "@fncts/typelevel";
4
4
  import { Parser } from "@fncts/schema/Parser/definition";
5
- import { ParseError } from "@fncts/schema/ParseError";
6
5
  import { Gen } from "@fncts/test/control/Gen";
7
6
  /**
8
7
  * @tsplus static fncts.schema.SchemaOps list
@@ -0,0 +1,19 @@
1
+ import { Schema } from "@fncts/schema/Schema/definition";
2
+ import { Check } from "@fncts/typelevel";
3
+ import { Parser } from "@fncts/schema/Parser/definition";
4
+ import { Gen } from "@fncts/test/control/Gen";
5
+ /**
6
+ * @tsplus static fncts.schema.SchemaOps map
7
+ * @tsplus location "@fncts/schema/Schema/api/map"
8
+ */
9
+ export declare function map<K, V>(key: Schema<K>, value: Schema<V>): Schema<Map<K, V>>;
10
+ /**
11
+ * @tsplus static fncts.schema.SchemaOps mapFromRecord
12
+ * @tsplus location "@fncts/schema/Schema/api/map"
13
+ */
14
+ export declare function mapFromRecord<K extends string | symbol, V>(key: Schema<K>, value: Schema<V>): Schema<Map<K, V>>;
15
+ /**
16
+ * @tsplus derive fncts.schema.Schema[fncts.Map]<_> 10
17
+ * @tsplus location "@fncts/schema/Schema/api/map"
18
+ */
19
+ export declare function deriveMap<A extends Map<any, any>>(...[key, value]: [A] extends [Map<infer K, infer V>] ? Check<Check.IsEqual<A, Map<K, V>> & Check.Extends<K, string | symbol>> extends Check.True ? [key: Schema<K>, value: Schema<V>] : never : never): Schema<A>;