@fncts/schema 0.0.11 → 0.0.12
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/ASTAnnotation.d.ts +9 -9
- package/Parser.d.ts +2 -2
- package/Schema/api.d.ts +2 -2
- package/Schema.d.ts +8 -8
- package/_cjs/AST.cjs +43 -102
- package/_cjs/AST.cjs.map +1 -1
- package/_cjs/ASTAnnotation.cjs +22 -42
- package/_cjs/ASTAnnotation.cjs.map +1 -1
- package/_cjs/ASTAnnotationMap.cjs +2 -2
- package/_cjs/ASTAnnotationMap.cjs.map +1 -1
- package/_cjs/Gen.cjs +2 -2
- package/_cjs/Gen.cjs.map +1 -1
- package/_cjs/InvalidInterpretationError.cjs +1 -2
- package/_cjs/InvalidInterpretationError.cjs.map +1 -1
- package/_cjs/ParseError.cjs +4 -5
- package/_cjs/ParseError.cjs.map +1 -1
- package/_cjs/ParseResult.cjs +2 -2
- package/_cjs/Parser/api.cjs +2 -2
- package/_cjs/Parser/api.cjs.map +1 -1
- package/_cjs/Parser/definition.cjs +2 -2
- package/_cjs/Parser/interpreter.cjs +2 -2
- package/_cjs/Parser/interpreter.cjs.map +1 -1
- package/_cjs/Parser.cjs +8 -8
- package/_cjs/Parser.cjs.map +1 -1
- package/_cjs/Schema/api/conc.cjs +4 -5
- package/_cjs/Schema/api/conc.cjs.map +1 -1
- package/_cjs/Schema/api/either.cjs +4 -6
- package/_cjs/Schema/api/either.cjs.map +1 -1
- package/_cjs/Schema/api/hashMap.cjs +4 -6
- package/_cjs/Schema/api/hashMap.cjs.map +1 -1
- package/_cjs/Schema/api/hashSet.cjs +7 -7
- package/_cjs/Schema/api/hashSet.cjs.map +1 -1
- package/_cjs/Schema/api/immutableArray.cjs +4 -6
- package/_cjs/Schema/api/immutableArray.cjs.map +1 -1
- package/_cjs/Schema/api/list.cjs +4 -6
- package/_cjs/Schema/api/list.cjs.map +1 -1
- package/_cjs/Schema/api/maybe.cjs +4 -6
- package/_cjs/Schema/api/maybe.cjs.map +1 -1
- package/_cjs/Schema/api.cjs +29 -56
- package/_cjs/Schema/api.cjs.map +1 -1
- package/_cjs/Schema/definition.cjs +5 -8
- package/_cjs/Schema/definition.cjs.map +1 -1
- package/_cjs/Schema/derivations.cjs +14 -6
- package/_cjs/Schema/derivations.cjs.map +1 -1
- package/_cjs/Schema.cjs +32 -32
- package/_cjs/Schema.cjs.map +1 -1
- package/_cjs/utils.cjs +2 -2
- package/_cjs/utils.cjs.map +1 -1
- package/_mjs/AST.mjs +5 -28
- package/_mjs/AST.mjs.map +1 -1
- package/_mjs/ASTAnnotation.mjs.map +1 -1
- package/_mjs/ASTAnnotationMap.mjs +1 -2
- package/_mjs/ASTAnnotationMap.mjs.map +1 -1
- package/_mjs/Gen.mjs.map +1 -1
- package/_mjs/ParseError.mjs +1 -1
- package/_mjs/ParseError.mjs.map +1 -1
- package/_mjs/Parser/interpreter.mjs.map +1 -1
- package/_mjs/Parser.mjs +3 -2
- package/_mjs/Parser.mjs.map +1 -1
- package/_mjs/Schema/api/conc.mjs +1 -1
- package/_mjs/Schema/api/conc.mjs.map +1 -1
- package/_mjs/Schema/api/either.mjs.map +1 -1
- package/_mjs/Schema/api/hashMap.mjs.map +1 -1
- package/_mjs/Schema/api/hashSet.mjs.map +1 -1
- package/_mjs/Schema/api/immutableArray.mjs.map +1 -1
- package/_mjs/Schema/api/list.mjs.map +1 -1
- package/_mjs/Schema/api/maybe.mjs.map +1 -1
- package/_mjs/Schema/api.mjs.map +1 -1
- package/_mjs/Schema/derivations.mjs +12 -4
- package/_mjs/Schema/derivations.mjs.map +1 -1
- package/_mjs/Schema.mjs +10 -8
- package/_mjs/Schema.mjs.map +1 -1
- package/_mjs/utils.mjs.map +1 -1
- package/_src/AST.ts +24 -6
- package/_src/ASTAnnotation.ts +5 -1
- package/_src/ParseError.ts +13 -3
- package/_src/Parser.ts +3 -2
- package/_src/Schema/api/conc.ts +1 -1
- package/_src/Schema/derivations.ts +4 -0
- package/_src/Schema.ts +10 -8
- package/_src/global.ts +2 -2
- package/global.d.ts +2 -2
- package/package.json +3 -3
package/_mjs/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","names":["memoize","f","cache","Map","a","has","b","set","get","ownKeys","o","tsplus_module_1","from","Reflect","empty","getTemplateLiteralRegex","ast","pattern","head","span","spans","tsplus_module_2","isStringKeyword","type","isNumberKeyword","literal","RegExp","getKeysForIndexSignature","input","parameter","_tag","Object","keys","getOwnPropertySymbols"],"sources":["../_src/utils.ts"],"sourcesContent":[null],"mappings":";;AAIA,OAAM,SAAUA,OAAOA,CAAOC,CAAc;EAC1C,MAAMC,KAAK,GAAG,IAAIC,GAAG,EAAE;EACvB,OAAQC,CAAC,IAAI;IACX,IAAI,CAACF,KAAK,CAACG,GAAG,CAACD,CAAC,CAAC,EAAE;MACjB,MAAME,CAAC,GAAGL,CAAC,CAACG,CAAC,CAAC;MACdF,KAAK,CAACK,GAAG,CAACH,CAAC,EAAEE,CAAC,CAAC;MACf,OAAOA,CAAC
|
|
1
|
+
{"version":3,"file":"utils.mjs","names":["memoize","f","cache","Map","a","has","b","set","get","ownKeys","o","tsplus_module_1","from","Reflect","empty","getTemplateLiteralRegex","ast","pattern","head","span","spans","tsplus_module_2","isStringKeyword","type","isNumberKeyword","literal","RegExp","getKeysForIndexSignature","input","parameter","_tag","Object","keys","getOwnPropertySymbols"],"sources":["../_src/utils.ts"],"sourcesContent":[null],"mappings":";;AAIA,OAAM,SAAUA,OAAOA,CAAOC,CAAc;EAC1C,MAAMC,KAAK,GAAG,IAAIC,GAAG,EAAE;EACvB,OAAQC,CAAC,IAAI;IACX,IAAI,CAACF,KAAK,CAACG,GAAG,CAACD,CAAC,CAAC,EAAE;MACjB,MAAME,CAAC,GAAGL,CAAC,CAACG,CAAC,CAAC;MACdF,KAAK,CAACK,GAAG,CAACH,CAAC,EAAEE,CAAC,CAAC;MACf,OAAOA,CAAC;IACV;IACA,OAAOJ,KAAK,CAACM,GAAG,CAACJ,CAAC,CAAC;EACrB,CAAC;AACH;AAEA,OAAM,SAAUK,OAAOA,CAACC,CAAqB;EAC3C,OAAOA,CAAC,GAAGC,eAAA,CAAAC,IAAA,CAAYC,OAAO,CAACJ,OAAO,CAACC,CAAC,CAAC,CAAC,GAAGC,eAAA,CAAAG,KAAA,EAAc;AAC7D;AAEA,OAAM,SAAUC,uBAAuBA,CAACC,GAAoB;EAC1D,IAAIC,OAAO,GAAG,IAAID,GAAG,CAACE,IAAI,EAAE;EAC5B,KAAK,MAAMC,IAAI,IAAIH,GAAG,CAACI,KAAK,EAAE;IAC5B,IAAIC,eAAA,CAAAC,eAAA,CAAAH,IAAI,CAACI,IAAI,CAAkB,EAAE;MAC/BN,OAAO,IAAI,IAAI;IACjB,CAAC,MAAM,IAAII,eAAA,CAAAG,eAAA,CAAAL,IAAI,CAACI,IAAI,CAAkB,EAAE;MACtCN,OAAO,IAAI,kBAAkB;IAC/B;IACAA,OAAO,IAAIE,IAAI,CAACM,OAAO;EACzB;EACAR,OAAO,IAAI,GAAG;EACd,OAAO,IAAIS,MAAM,CAACT,OAAO,CAAC;AAC5B;AAEA,OAAM,SAAUU,wBAAwBA,CACtCC,KAA6C,EAC7CC,SAAsC;EAEtC,QAAQA,SAAS,CAACC,IAAI;IACpB;IACA;MACE,OAAOnB,eAAA,CAAAC,IAAA,CAAYmB,MAAM,CAACC,IAAI,CAACJ,KAAK,CAAC,CAAC;IACxC;MACE,OAAOjB,eAAA,CAAAC,IAAA,CAAYmB,MAAM,CAACE,qBAAqB,CAACL,KAAK,CAAC,CAAC;IACzD;MACE,OAAOD,wBAAwB,CAACC,KAAK,EAAEC,SAAS,CAACjB,IAAW,CAAC;EACjE;AACF"}
|
package/_src/AST.ts
CHANGED
|
@@ -154,7 +154,10 @@ export type LiteralValue = string | number | boolean | null | bigint;
|
|
|
154
154
|
|
|
155
155
|
export class Literal extends AST {
|
|
156
156
|
readonly _tag = ASTTag.Literal;
|
|
157
|
-
constructor(
|
|
157
|
+
constructor(
|
|
158
|
+
readonly literal: LiteralValue,
|
|
159
|
+
readonly annotations: ASTAnnotationMap = ASTAnnotationMap.empty,
|
|
160
|
+
) {
|
|
158
161
|
super();
|
|
159
162
|
}
|
|
160
163
|
|
|
@@ -184,7 +187,10 @@ export function isLiteral(self: AST): self is Literal {
|
|
|
184
187
|
|
|
185
188
|
export class UniqueSymbol extends AST {
|
|
186
189
|
readonly _tag = ASTTag.UniqueSymbol;
|
|
187
|
-
constructor(
|
|
190
|
+
constructor(
|
|
191
|
+
readonly symbol: symbol,
|
|
192
|
+
readonly annotations: ASTAnnotationMap = ASTAnnotationMap.empty,
|
|
193
|
+
) {
|
|
188
194
|
super();
|
|
189
195
|
}
|
|
190
196
|
|
|
@@ -518,7 +524,10 @@ export function createEnum(
|
|
|
518
524
|
}
|
|
519
525
|
|
|
520
526
|
export class TemplateLiteralSpan {
|
|
521
|
-
constructor(
|
|
527
|
+
constructor(
|
|
528
|
+
readonly type: StringKeyword | NumberKeyword,
|
|
529
|
+
readonly literal: string,
|
|
530
|
+
) {}
|
|
522
531
|
}
|
|
523
532
|
|
|
524
533
|
/*
|
|
@@ -564,7 +573,10 @@ export function createTemplateLiteral(
|
|
|
564
573
|
*/
|
|
565
574
|
|
|
566
575
|
export class Element {
|
|
567
|
-
constructor(
|
|
576
|
+
constructor(
|
|
577
|
+
readonly type: AST,
|
|
578
|
+
readonly isOptional: boolean,
|
|
579
|
+
) {}
|
|
568
580
|
}
|
|
569
581
|
|
|
570
582
|
/**
|
|
@@ -726,7 +738,10 @@ export function createTypeLiteral(
|
|
|
726
738
|
|
|
727
739
|
export class Union extends AST {
|
|
728
740
|
readonly _tag = ASTTag.Union;
|
|
729
|
-
constructor(
|
|
741
|
+
constructor(
|
|
742
|
+
readonly types: Vector<AST>,
|
|
743
|
+
readonly annotations: ASTAnnotationMap = ASTAnnotationMap.empty,
|
|
744
|
+
) {
|
|
730
745
|
super();
|
|
731
746
|
}
|
|
732
747
|
|
|
@@ -764,7 +779,10 @@ export function createUnion(candidates: Vector<AST>, annotations: ASTAnnotationM
|
|
|
764
779
|
|
|
765
780
|
export class Lazy extends AST {
|
|
766
781
|
readonly _tag = ASTTag.Lazy;
|
|
767
|
-
constructor(
|
|
782
|
+
constructor(
|
|
783
|
+
readonly getAST: () => AST,
|
|
784
|
+
readonly annotations: ASTAnnotationMap = ASTAnnotationMap.empty,
|
|
785
|
+
) {
|
|
768
786
|
super();
|
|
769
787
|
}
|
|
770
788
|
|
package/_src/ASTAnnotation.ts
CHANGED
|
@@ -15,7 +15,11 @@ export class ASTAnnotation<V> implements Hashable, Equatable {
|
|
|
15
15
|
declare [ASTAnnotationVariance]: {
|
|
16
16
|
readonly _V: (_: never) => V;
|
|
17
17
|
};
|
|
18
|
-
constructor(
|
|
18
|
+
constructor(
|
|
19
|
+
readonly tag: Tag<V>,
|
|
20
|
+
readonly identifier: string,
|
|
21
|
+
readonly combine: (v1: V, v2: V) => V,
|
|
22
|
+
) {}
|
|
19
23
|
get [Symbol.hash]() {
|
|
20
24
|
return Hashable.combine(Hashable.string(this.identifier), Hashable.unknown(this.tag));
|
|
21
25
|
}
|
package/_src/ParseError.ts
CHANGED
|
@@ -32,7 +32,10 @@ export type ParseError =
|
|
|
32
32
|
*/
|
|
33
33
|
export class TypeError {
|
|
34
34
|
readonly _tag = ParseErrorTag.Type;
|
|
35
|
-
constructor(
|
|
35
|
+
constructor(
|
|
36
|
+
readonly expected: AST,
|
|
37
|
+
readonly actual: unknown,
|
|
38
|
+
) {}
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
/**
|
|
@@ -48,7 +51,10 @@ export function typeError(expected: AST, actual: unknown): ParseError {
|
|
|
48
51
|
*/
|
|
49
52
|
export class IndexError {
|
|
50
53
|
readonly _tag = ParseErrorTag.Index;
|
|
51
|
-
constructor(
|
|
54
|
+
constructor(
|
|
55
|
+
readonly index: number,
|
|
56
|
+
readonly errors: Vector<ParseError>,
|
|
57
|
+
) {}
|
|
52
58
|
}
|
|
53
59
|
|
|
54
60
|
/**
|
|
@@ -64,7 +70,11 @@ export function indexError(index: number, errors: Vector<ParseError>): ParseErro
|
|
|
64
70
|
*/
|
|
65
71
|
export class KeyError {
|
|
66
72
|
readonly _tag = ParseErrorTag.Key;
|
|
67
|
-
constructor(
|
|
73
|
+
constructor(
|
|
74
|
+
readonly keyAST: AST,
|
|
75
|
+
readonly key: any,
|
|
76
|
+
readonly errors: Vector<ParseError>,
|
|
77
|
+
) {}
|
|
68
78
|
}
|
|
69
79
|
|
|
70
80
|
/**
|
package/_src/Parser.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/* eslint-disable simple-import-sort/exports */
|
|
1
2
|
// codegen:start { preset: barrel, include: ./Parser/*.ts }
|
|
2
|
-
export * from "./Parser/api.js";
|
|
3
|
-
export * from "./Parser/definition.js";
|
|
4
3
|
export * from "./Parser/interpreter.js";
|
|
4
|
+
export * from "./Parser/definition.js";
|
|
5
|
+
export * from "./Parser/api.js";
|
|
5
6
|
// codegen:end
|
package/_src/Schema/api/conc.ts
CHANGED
|
@@ -46,7 +46,7 @@ export function concParser<A>(value: Schema<A>): Parser<Conc<A>> {
|
|
|
46
46
|
const out: Array<A> = [];
|
|
47
47
|
let i = 0;
|
|
48
48
|
for (const v of u) {
|
|
49
|
-
const t = value.decode(
|
|
49
|
+
const t = value.decode(v);
|
|
50
50
|
Either.concrete(t);
|
|
51
51
|
if (t.isLeft()) {
|
|
52
52
|
errors.push(ParseError.IndexError(i, t.left));
|
|
@@ -66,11 +66,13 @@ export function deriveStruct<A extends Record<string, any>>(
|
|
|
66
66
|
): Schema<A> {
|
|
67
67
|
const maybeFieldsKeys: Vector<PropertyKey> = ownKeys(maybeFields);
|
|
68
68
|
let propertySignatures = ownKeys(requiredFields).map((key) =>
|
|
69
|
+
// @ts-expect-error
|
|
69
70
|
AST.createPropertySignature(key, requiredFields[key]!.ast, false, true),
|
|
70
71
|
);
|
|
71
72
|
|
|
72
73
|
if (optionalFields) {
|
|
73
74
|
propertySignatures = propertySignatures.concat(
|
|
75
|
+
// @ts-expect-error
|
|
74
76
|
ownKeys(optionalFields).map((key) => AST.createPropertySignature(key, optionalFields[key]!.ast, true, true)),
|
|
75
77
|
);
|
|
76
78
|
}
|
|
@@ -89,6 +91,7 @@ export function deriveStruct<A extends Record<string, any>>(
|
|
|
89
91
|
maybeFieldsKeys.map((key) =>
|
|
90
92
|
AST.createPropertySignature(
|
|
91
93
|
key,
|
|
94
|
+
// @ts-expect-error
|
|
92
95
|
AST.createUnion(Vector(AST.undefinedKeyword, AST.createLiteral(null), maybeFields![key]!.ast)),
|
|
93
96
|
true,
|
|
94
97
|
true,
|
|
@@ -103,6 +106,7 @@ export function deriveStruct<A extends Record<string, any>>(
|
|
|
103
106
|
AST.createTypeLiteral(
|
|
104
107
|
propertySignatures.concat(
|
|
105
108
|
maybeFieldsKeys.map((key) =>
|
|
109
|
+
// @ts-expect-error
|
|
106
110
|
AST.createPropertySignature(key, Schema.maybe(maybeFields![key]!).ast, true, true),
|
|
107
111
|
),
|
|
108
112
|
),
|
package/_src/Schema.ts
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
|
+
/* eslint-disable simple-import-sort/exports */
|
|
1
2
|
// codegen:start { preset: barrel, include: ./Schema/*.ts }
|
|
2
|
-
export * from "./Schema/api.js";
|
|
3
|
-
export * from "./Schema/definition.js";
|
|
4
3
|
export * from "./Schema/derivations.js";
|
|
4
|
+
export * from "./Schema/definition.js";
|
|
5
|
+
export * from "./Schema/api.js";
|
|
5
6
|
// codegen:end
|
|
6
7
|
|
|
8
|
+
/* eslint-disable simple-import-sort/exports */
|
|
7
9
|
// 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/hashSet.js";
|
|
12
|
-
export * from "./Schema/api/immutableArray.js";
|
|
13
|
-
export * from "./Schema/api/list.js";
|
|
14
10
|
export * from "./Schema/api/maybe.js";
|
|
11
|
+
export * from "./Schema/api/list.js";
|
|
12
|
+
export * from "./Schema/api/immutableArray.js";
|
|
13
|
+
export * from "./Schema/api/hashSet.js";
|
|
14
|
+
export * from "./Schema/api/hashMap.js";
|
|
15
|
+
export * from "./Schema/api/either.js";
|
|
16
|
+
export * from "./Schema/api/conc.js";
|
|
15
17
|
// codegen:end
|
|
16
18
|
|
|
17
19
|
export type {} from "./Parser.js";
|
package/_src/global.ts
CHANGED
|
@@ -50,11 +50,11 @@ import { ParseResult } from "@fncts/schema/ParseResult";
|
|
|
50
50
|
/**
|
|
51
51
|
* @tsplus global
|
|
52
52
|
*/
|
|
53
|
-
import {
|
|
53
|
+
import {} from "@fncts/schema/Schema";
|
|
54
54
|
/**
|
|
55
55
|
* @tsplus global
|
|
56
56
|
*/
|
|
57
|
-
import {} from "@fncts/schema/Schema"
|
|
57
|
+
import { OptionalSchema, Schema } from "@fncts/schema/Schema/definition";
|
|
58
58
|
/**
|
|
59
59
|
* @tsplus global
|
|
60
60
|
*/
|
package/global.d.ts
CHANGED
|
@@ -49,11 +49,11 @@ import { ParseResult } from "@fncts/schema/ParseResult";
|
|
|
49
49
|
/**
|
|
50
50
|
* @tsplus global
|
|
51
51
|
*/
|
|
52
|
-
import {
|
|
52
|
+
import {} from "@fncts/schema/Schema";
|
|
53
53
|
/**
|
|
54
54
|
* @tsplus global
|
|
55
55
|
*/
|
|
56
|
-
import {} from "@fncts/schema/Schema";
|
|
56
|
+
import { OptionalSchema, Schema } from "@fncts/schema/Schema/definition";
|
|
57
57
|
/**
|
|
58
58
|
* @tsplus global
|
|
59
59
|
*/
|
package/package.json
CHANGED