@fncts/schema 0.0.1

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/Decoder.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { DecoderF } from "@fncts/base/data/Decoder";
2
+ import type { Schemable as S } from "@fncts/schema/Schemable";
3
+ export declare const Schemable: S<DecoderF>;
package/Encoder.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import { Encoder } from "@fncts/base/data/Encoder/definition";
2
+ import type { EncoderF } from "@fncts/base/data/Encoder";
3
+ import type { Schemable as S } from "@fncts/schema/Schemable";
4
+ export declare const Schemable: S<EncoderF>;
package/Guard.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import type { GuardF } from "@fncts/base/data/Guard";
2
+ import type { Schemable as S } from "@fncts/schema/Schemable";
3
+ export declare const Schemable: S<GuardF>;
package/Schema.d.ts ADDED
@@ -0,0 +1,140 @@
1
+ import { HKT } from "@fncts/typelevel/HKT";
2
+ import type { Brand, Validation } from "@fncts/base/data/Branded";
3
+ import type { Schemable as S, SchemableKind } from "@fncts/schema/Schemable";
4
+ import type { Literal } from "@fncts/typelevel/Any";
5
+ export declare const SchemaTypeId: unique symbol;
6
+ export type SchemaTypeId = typeof SchemaTypeId;
7
+ export declare const enum SchemaTag {
8
+ Unknown = 0,
9
+ String = 1,
10
+ Number = 2,
11
+ Boolean = 3,
12
+ BigInt = 4,
13
+ Literal = 5,
14
+ Nullable = 6,
15
+ Struct = 7,
16
+ Partial = 8,
17
+ Array = 9,
18
+ Record = 10,
19
+ Tuple = 11,
20
+ Lazy = 12,
21
+ Validation = 13,
22
+ Union = 14
23
+ }
24
+ export interface SchemaF extends HKT {
25
+ readonly type: Schema<this["A"]>;
26
+ }
27
+ export declare abstract class Schema<in out A> {
28
+ readonly _typeId: SchemaTypeId;
29
+ _A: (_: A) => A;
30
+ }
31
+ export declare class UnknownSchema extends Schema<unknown> {
32
+ readonly _tag = SchemaTag.Unknown;
33
+ }
34
+ export declare class StringSchema extends Schema<string> {
35
+ readonly _tag = SchemaTag.String;
36
+ }
37
+ export declare class NumberSchema extends Schema<number> {
38
+ readonly _tag = SchemaTag.Number;
39
+ }
40
+ export declare class BooleanSchema extends Schema<boolean> {
41
+ readonly _tag = SchemaTag.Boolean;
42
+ }
43
+ export declare class BigIntSchema extends Schema<bigint> {
44
+ readonly _tag = SchemaTag.BigInt;
45
+ }
46
+ export declare class LiteralSchema<A extends Literal> extends Schema<A> {
47
+ readonly value: A;
48
+ readonly _tag = SchemaTag.Literal;
49
+ constructor(value: A);
50
+ }
51
+ export declare class NullableSchema<A> extends Schema<A | null | undefined> {
52
+ readonly base: Schema<A>;
53
+ readonly _tag = SchemaTag.Nullable;
54
+ constructor(base: Schema<A>);
55
+ }
56
+ export declare class StructSchema<A extends Record<string, any>> extends Schema<A> {
57
+ readonly fields: {
58
+ [K in keyof A]: Schema<A[K]>;
59
+ };
60
+ readonly _tag = SchemaTag.Struct;
61
+ constructor(fields: {
62
+ [K in keyof A]: Schema<A[K]>;
63
+ });
64
+ }
65
+ export declare class PartialSchema<A extends Record<string, any>> extends Schema<Partial<A>> {
66
+ readonly fields: {
67
+ [K in keyof A]: Schema<A[K]>;
68
+ };
69
+ readonly _tag = SchemaTag.Partial;
70
+ constructor(fields: {
71
+ [K in keyof A]: Schema<A[K]>;
72
+ });
73
+ }
74
+ export declare class ArraySchema<A> extends Schema<ReadonlyArray<A>> {
75
+ readonly base: Schema<A>;
76
+ readonly _tag = SchemaTag.Array;
77
+ constructor(base: Schema<A>);
78
+ }
79
+ export declare class RecordSchema<A> extends Schema<Record<string, A>> {
80
+ readonly base: Schema<A>;
81
+ readonly _tag = SchemaTag.Record;
82
+ constructor(base: Schema<A>);
83
+ }
84
+ export declare class TupleSchema<A extends ReadonlyArray<any>> extends Schema<A> {
85
+ readonly components: {
86
+ [K in keyof A]: Schema<A[K]>;
87
+ };
88
+ readonly _tag = SchemaTag.Tuple;
89
+ constructor(components: {
90
+ [K in keyof A]: Schema<A[K]>;
91
+ });
92
+ }
93
+ export declare class LazySchema<A> extends Schema<A> {
94
+ readonly make: () => Schema<A>;
95
+ readonly _tag = SchemaTag.Lazy;
96
+ constructor(make: () => Schema<A>);
97
+ }
98
+ export declare class ValidationSchema<A, B extends ReadonlyArray<Validation<A, any>>> extends Schema<A & {
99
+ [K in keyof B]: B[K] extends Validation<any, infer S> ? Brand.Valid<A, S> : never;
100
+ }[number]> {
101
+ readonly base: Schema<A>;
102
+ readonly validations: readonly [...B];
103
+ readonly _tag = SchemaTag.Validation;
104
+ constructor(base: Schema<A>, validations: readonly [...B]);
105
+ }
106
+ export declare class UnionSchema<A extends ReadonlyArray<any>> extends Schema<A[number]> {
107
+ readonly members: {
108
+ [K in keyof A]: Schema<A[K]>;
109
+ };
110
+ readonly _tag = SchemaTag.Union;
111
+ constructor(members: {
112
+ [K in keyof A]: Schema<A[K]>;
113
+ });
114
+ }
115
+ export declare const unknown: Schema<unknown>;
116
+ export declare const string: Schema<string>;
117
+ export declare const number: Schema<number>;
118
+ export declare const boolean: Schema<boolean>;
119
+ export declare const bigint: Schema<bigint>;
120
+ export declare function literal<A extends Literal>(value: A): Schema<A>;
121
+ export declare function nullable<A>(base: Schema<A>): Schema<A | null | undefined>;
122
+ export declare function struct<A extends Record<string, any>>(fields: {
123
+ [K in keyof A]: Schema<A[K]>;
124
+ }): Schema<A>;
125
+ export declare function partial<A extends Record<string, any>>(fields: {
126
+ [K in keyof A]: Schema<A[K]>;
127
+ }): Schema<Partial<A>>;
128
+ export declare function array<A>(base: Schema<A>): Schema<ReadonlyArray<A>>;
129
+ export declare function record<A>(base: Schema<A>): Schema<Record<string, A>>;
130
+ export declare function tuple<A extends ReadonlyArray<any>>(...components: {
131
+ [K in keyof A]: Schema<A[K]>;
132
+ }): Schema<A>;
133
+ export declare function lazy<A>(make: () => Schema<A>): Schema<A>;
134
+ export declare function validation<A, B extends ReadonlyArray<Validation<A, any>>>(...validations: B): (base: Schema<A>) => Schema<A & { [K in keyof B]: B[K] extends Validation<any, infer S_1 extends string> ? Brand.Valid<A, S_1> : never; }[number]>;
135
+ export declare function union<A extends ReadonlyArray<any>>(...members: {
136
+ [K in keyof A]: Schema<A[K]>;
137
+ }): Schema<A[number]>;
138
+ export type Concrete = UnknownSchema | StringSchema | NumberSchema | BooleanSchema | BigIntSchema | LiteralSchema<any> | NullableSchema<any> | StructSchema<Record<string, any>> | PartialSchema<Record<string, any>> | ArraySchema<any> | RecordSchema<any> | TupleSchema<ReadonlyArray<any>> | LazySchema<any> | ValidationSchema<any, ReadonlyArray<Validation<any, any>>> | UnionSchema<ReadonlyArray<any>>;
139
+ export declare function concrete(_: Schema<any>): asserts _ is Concrete;
140
+ export declare function interpret<F extends HKT>(S: S<F>): <A>(schema: Schema<A>) => SchemableKind<F, A>;
package/Schemable.d.ts ADDED
@@ -0,0 +1,39 @@
1
+ import { HKT } from "@fncts/typelevel/HKT";
2
+ import type { Brand, Validation } from "@fncts/base/data/Branded";
3
+ import type { UnionSchema } from "@fncts/schema/Schema";
4
+ import type { Literal } from "@fncts/typelevel/Any";
5
+ export type SchemableKind<F extends HKT, A> = F extends {
6
+ readonly type: unknown;
7
+ } ? (F & {
8
+ readonly A: A;
9
+ })["type"] : {
10
+ readonly _F: F;
11
+ readonly _A: A;
12
+ };
13
+ export interface Schemable<F extends HKT> {
14
+ readonly unknown: SchemableKind<F, unknown>;
15
+ readonly string: SchemableKind<F, string>;
16
+ readonly number: SchemableKind<F, number>;
17
+ readonly boolean: SchemableKind<F, boolean>;
18
+ readonly bigint: SchemableKind<F, bigint>;
19
+ readonly literal: <A extends Literal>(literal: A) => SchemableKind<F, A>;
20
+ readonly nullable: <A>(or: SchemableKind<F, A>) => SchemableKind<F, A | null | undefined>;
21
+ readonly struct: <P extends Record<string, any>>(properties: {
22
+ [K in keyof P]: SchemableKind<F, P[K]>;
23
+ }) => SchemableKind<F, P>;
24
+ readonly partial: <P extends Record<string, any>>(properties: {
25
+ [K in keyof P]: SchemableKind<F, P[K]>;
26
+ }) => SchemableKind<F, Partial<P>>;
27
+ readonly array: <A>(item: SchemableKind<F, A>) => SchemableKind<F, ReadonlyArray<A>>;
28
+ readonly record: <A>(codomain: SchemableKind<F, A>) => SchemableKind<F, Record<string, A>>;
29
+ readonly tuple: <C extends ReadonlyArray<any>>(...components: {
30
+ [K in keyof C]: SchemableKind<F, C[K]>;
31
+ }) => SchemableKind<F, C>;
32
+ readonly lazy: <A>(f: () => SchemableKind<F, A>) => SchemableKind<F, A>;
33
+ readonly validation: <A, B extends ReadonlyArray<Validation<A, any>>>(...validations: B) => (base: SchemableKind<F, A>) => SchemableKind<F, A & {
34
+ [K in keyof B]: B[K] extends Validation<any, infer S> ? Brand.Valid<A, S> : never;
35
+ }[number]>;
36
+ readonly union: <A extends ReadonlyArray<any>>(members: {
37
+ [K in keyof A]: SchemableKind<F, A[K]>;
38
+ }, schema: UnionSchema<A>) => SchemableKind<F, A[number]>;
39
+ }
@@ -0,0 +1,29 @@
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/Decoder/api"));
8
+ var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/data/function/api"));
9
+ 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); }
10
+ 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; }
11
+ const Schemable = {
12
+ unknown: tsplus_module_1.unknown,
13
+ string: tsplus_module_1.string,
14
+ number: tsplus_module_1.number,
15
+ boolean: tsplus_module_1.boolean,
16
+ bigint: tsplus_module_1.bigint,
17
+ literal: tsplus_module_1.literal,
18
+ nullable: tsplus_module_1.nullable,
19
+ struct: tsplus_module_1.struct,
20
+ partial: tsplus_module_1.partial,
21
+ array: tsplus_module_1.readonlyArray,
22
+ record: tsplus_module_1.record,
23
+ tuple: tsplus_module_1.tuple,
24
+ lazy: tsplus_module_1.deriveLazy,
25
+ validation: tsplus_module_1.validation,
26
+ union: members => tsplus_module_1.union(...members)
27
+ };
28
+ exports.Schemable = Schemable;
29
+ //# sourceMappingURL=Decoder.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Decoder.cjs","mappings":";;;;;;;;;;AAGO,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;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/Decoder.ts"],"sourcesContent":[null]}
@@ -0,0 +1,45 @@
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
@@ -0,0 +1 @@
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]}
package/_cjs/Guard.cjs ADDED
@@ -0,0 +1,29 @@
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/Guard/api"));
8
+ var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/data/function/api"));
9
+ 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); }
10
+ 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; }
11
+ const Schemable = {
12
+ unknown: tsplus_module_1.unknown,
13
+ string: tsplus_module_1.string,
14
+ number: tsplus_module_1.number,
15
+ boolean: tsplus_module_1.boolean,
16
+ bigint: tsplus_module_1.bigint,
17
+ literal: tsplus_module_1.literal,
18
+ nullable: tsplus_module_1.nullable,
19
+ struct: tsplus_module_1.struct,
20
+ partial: tsplus_module_1.partial,
21
+ array: tsplus_module_1.readonlyArray,
22
+ record: tsplus_module_1.record,
23
+ tuple: tsplus_module_1.tuple,
24
+ lazy: tsplus_module_1.deriveLazy,
25
+ validation: tsplus_module_1.validation,
26
+ union: members => tsplus_module_1.deriveUnion(...members)
27
+ };
28
+ exports.Schemable = Schemable;
29
+ //# sourceMappingURL=Guard.cjs.map
@@ -0,0 +1 @@
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]}
@@ -0,0 +1,241 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ValidationSchema = exports.UnknownSchema = exports.UnionSchema = exports.TupleSchema = exports.StructSchema = exports.StringSchema = exports.SchemaTypeId = exports.Schema = exports.RecordSchema = exports.PartialSchema = exports.NumberSchema = exports.NullableSchema = exports.LiteralSchema = exports.LazySchema = exports.BooleanSchema = exports.BigIntSchema = exports.ArraySchema = void 0;
7
+ exports.array = array;
8
+ exports.boolean = exports.bigint = void 0;
9
+ exports.concrete = concrete;
10
+ exports.interpret = interpret;
11
+ exports.lazy = lazy;
12
+ exports.literal = literal;
13
+ exports.nullable = nullable;
14
+ exports.number = void 0;
15
+ exports.partial = partial;
16
+ exports.record = record;
17
+ exports.string = void 0;
18
+ exports.struct = struct;
19
+ exports.tuple = tuple;
20
+ exports.union = union;
21
+ exports.unknown = void 0;
22
+ exports.validation = validation;
23
+ var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/collection/immutable/Dictionary/definition"));
24
+ var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@fncts/base/collection/immutable/Dictionary/api"));
25
+ 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); }
26
+ 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; }
27
+ const SchemaTypeId = /*#__PURE__*/Symbol.for("fncts.schema.Schema");
28
+ exports.SchemaTypeId = SchemaTypeId;
29
+ class Schema {
30
+ constructor() {
31
+ this._typeId = SchemaTypeId;
32
+ }
33
+ }
34
+ exports.Schema = Schema;
35
+ class UnknownSchema extends Schema {
36
+ constructor() {
37
+ super(...arguments);
38
+ this._tag = 0 /* SchemaTag.Unknown */;
39
+ }
40
+ }
41
+ exports.UnknownSchema = UnknownSchema;
42
+ class StringSchema extends Schema {
43
+ constructor() {
44
+ super(...arguments);
45
+ this._tag = 1 /* SchemaTag.String */;
46
+ }
47
+ }
48
+ exports.StringSchema = StringSchema;
49
+ class NumberSchema extends Schema {
50
+ constructor() {
51
+ super(...arguments);
52
+ this._tag = 2 /* SchemaTag.Number */;
53
+ }
54
+ }
55
+ exports.NumberSchema = NumberSchema;
56
+ class BooleanSchema extends Schema {
57
+ constructor() {
58
+ super(...arguments);
59
+ this._tag = 3 /* SchemaTag.Boolean */;
60
+ }
61
+ }
62
+ exports.BooleanSchema = BooleanSchema;
63
+ class BigIntSchema extends Schema {
64
+ constructor() {
65
+ super(...arguments);
66
+ this._tag = 4 /* SchemaTag.BigInt */;
67
+ }
68
+ }
69
+ exports.BigIntSchema = BigIntSchema;
70
+ class LiteralSchema extends Schema {
71
+ constructor(value) {
72
+ super();
73
+ this.value = value;
74
+ this._tag = 5 /* SchemaTag.Literal */;
75
+ }
76
+ }
77
+ exports.LiteralSchema = LiteralSchema;
78
+ class NullableSchema extends Schema {
79
+ constructor(base) {
80
+ super();
81
+ this.base = base;
82
+ this._tag = 6 /* SchemaTag.Nullable */;
83
+ }
84
+ }
85
+ exports.NullableSchema = NullableSchema;
86
+ class StructSchema extends Schema {
87
+ constructor(fields) {
88
+ super();
89
+ this.fields = fields;
90
+ this._tag = 7 /* SchemaTag.Struct */;
91
+ }
92
+ }
93
+ exports.StructSchema = StructSchema;
94
+ class PartialSchema extends Schema {
95
+ constructor(fields) {
96
+ super();
97
+ this.fields = fields;
98
+ this._tag = 8 /* SchemaTag.Partial */;
99
+ }
100
+ }
101
+ exports.PartialSchema = PartialSchema;
102
+ class ArraySchema extends Schema {
103
+ constructor(base) {
104
+ super();
105
+ this.base = base;
106
+ this._tag = 9 /* SchemaTag.Array */;
107
+ }
108
+ }
109
+ exports.ArraySchema = ArraySchema;
110
+ class RecordSchema extends Schema {
111
+ constructor(base) {
112
+ super();
113
+ this.base = base;
114
+ this._tag = 10 /* SchemaTag.Record */;
115
+ }
116
+ }
117
+ exports.RecordSchema = RecordSchema;
118
+ class TupleSchema extends Schema {
119
+ constructor(components) {
120
+ super();
121
+ this.components = components;
122
+ this._tag = 11 /* SchemaTag.Tuple */;
123
+ }
124
+ }
125
+ exports.TupleSchema = TupleSchema;
126
+ class LazySchema extends Schema {
127
+ constructor(make) {
128
+ super();
129
+ this.make = make;
130
+ this._tag = 12 /* SchemaTag.Lazy */;
131
+ }
132
+ }
133
+ exports.LazySchema = LazySchema;
134
+ class ValidationSchema extends Schema {
135
+ constructor(base, validations) {
136
+ super();
137
+ this.base = base;
138
+ this.validations = validations;
139
+ this._tag = 13 /* SchemaTag.Validation */;
140
+ }
141
+ }
142
+ exports.ValidationSchema = ValidationSchema;
143
+ class UnionSchema extends Schema {
144
+ constructor(members) {
145
+ super();
146
+ this.members = members;
147
+ this._tag = 14 /* SchemaTag.Union */;
148
+ }
149
+ }
150
+ exports.UnionSchema = UnionSchema;
151
+ const unknown = /*#__PURE__*/new UnknownSchema();
152
+ exports.unknown = unknown;
153
+ const string = /*#__PURE__*/new StringSchema();
154
+ exports.string = string;
155
+ const number = /*#__PURE__*/new NumberSchema();
156
+ exports.number = number;
157
+ const boolean = /*#__PURE__*/new BooleanSchema();
158
+ exports.boolean = boolean;
159
+ const bigint = /*#__PURE__*/new BigIntSchema();
160
+ exports.bigint = bigint;
161
+ function literal(value) {
162
+ return new LiteralSchema(value);
163
+ }
164
+ function nullable(base) {
165
+ return new NullableSchema(base);
166
+ }
167
+ function struct(fields) {
168
+ return new StructSchema(fields);
169
+ }
170
+ function partial(fields) {
171
+ return new PartialSchema(fields);
172
+ }
173
+ function array(base) {
174
+ return new ArraySchema(base);
175
+ }
176
+ function record(base) {
177
+ return new RecordSchema(base);
178
+ }
179
+ function tuple(...components) {
180
+ return new TupleSchema(components).unsafeCoerce();
181
+ }
182
+ function lazy(make) {
183
+ return new LazySchema(make);
184
+ }
185
+ function validation(...validations) {
186
+ return base => new ValidationSchema(base, validations).unsafeCoerce();
187
+ }
188
+ function union(...members) {
189
+ return new UnionSchema(members);
190
+ }
191
+ function concrete(_) {
192
+ //
193
+ }
194
+ function cacheThunk(f) {
195
+ let cached;
196
+ return () => {
197
+ if (!cached) {
198
+ cached = f();
199
+ }
200
+ return cached;
201
+ };
202
+ }
203
+ function interpret(S) {
204
+ return schema => {
205
+ concrete(schema);
206
+ switch (schema._tag) {
207
+ case 0 /* SchemaTag.Unknown */:
208
+ return S.unknown;
209
+ case 1 /* SchemaTag.String */:
210
+ return S.string;
211
+ case 2 /* SchemaTag.Number */:
212
+ return S.number;
213
+ case 3 /* SchemaTag.Boolean */:
214
+ return S.boolean;
215
+ case 4 /* SchemaTag.BigInt */:
216
+ return S.bigint;
217
+ case 5 /* SchemaTag.Literal */:
218
+ return S.literal(schema.value);
219
+ case 12 /* SchemaTag.Lazy */:
220
+ const cached = cacheThunk(schema.make);
221
+ return S.lazy(() => interpret(S)(cached()));
222
+ case 6 /* SchemaTag.Nullable */:
223
+ return S.nullable(interpret(S)(schema.base));
224
+ case 7 /* SchemaTag.Struct */:
225
+ return S.struct(tsplus_module_1.Dictionary.reverseGet(tsplus_module_2.map(interpret(S))(tsplus_module_1.Dictionary.get(schema.fields))));
226
+ case 8 /* SchemaTag.Partial */:
227
+ return S.partial(tsplus_module_1.Dictionary.reverseGet(tsplus_module_2.map(interpret(S))(tsplus_module_1.Dictionary.get(schema.fields))));
228
+ case 9 /* SchemaTag.Array */:
229
+ return S.array(interpret(S)(schema.base));
230
+ case 10 /* SchemaTag.Record */:
231
+ return S.record(interpret(S)(schema.base));
232
+ case 11 /* SchemaTag.Tuple */:
233
+ return S.tuple(...schema.components.map(interpret(S)));
234
+ case 13 /* SchemaTag.Validation */:
235
+ return S.validation(...schema.validations)(interpret(S)(schema.base));
236
+ case 14 /* SchemaTag.Union */:
237
+ return S.union(schema.members.map(interpret(S)), schema);
238
+ }
239
+ };
240
+ }
241
+ //# sourceMappingURL=Schema.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Schema.cjs","mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAIO,MAAMA,YAAY,gBAAGC,MAAM,CAACC,GAAG,CAAC,qBAAqB,CAAC;AAAC;AAyBxD,MAAgBC,MAAM;EAA5BC;IACW,YAAO,GAAiBJ,YAAY;EAE/C;;AAAC;AAEK,MAAOK,aAAc,SAAQF,MAAe;EAAlDC;;IACW,SAAI;EACf;;AAAC;AAEK,MAAOE,YAAa,SAAQH,MAAc;EAAhDC;;IACW,SAAI;EACf;;AAAC;AAEK,MAAOG,YAAa,SAAQJ,MAAc;EAAhDC;;IACW,SAAI;EACf;;AAAC;AAEK,MAAOI,aAAc,SAAQL,MAAe;EAAlDC;;IACW,SAAI;EACf;;AAAC;AAEK,MAAOK,YAAa,SAAQN,MAAc;EAAhDC;;IACW,SAAI;EACf;;AAAC;AAEK,MAAOM,aAAiC,SAAQP,MAAS;EAE7DC,YAAqBO,KAAQ;IAC3B,KAAK,EAAE;IADY,UAAK,GAALA,KAAK;IADjB,SAAI;EAGb;;AACD;AAEK,MAAOC,cAAkB,SAAQT,MAA4B;EAEjEC,YAAqBS,IAAe;IAClC,KAAK,EAAE;IADY,SAAI,GAAJA,IAAI;IADhB,SAAI;EAGb;;AACD;AAEK,MAAOC,YAA4C,SAAQX,MAAS;EAExEC,YAAqBW,MAAwC;IAC3D,KAAK,EAAE;IADY,WAAM,GAANA,MAAM;IADlB,SAAI;EAGb;;AACD;AAE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C,CAAC,CAAC;MACxD;QACE,OAAOA,CAAC,CAACR,UAAU,CAAC,GAAGS,MAAM,CAAC1B,WAAW,CAAC,CAACwB,SAAS,CAACC,CAAC,CAAC,CAACC,MAAM,CAACrC,IAAI,CAAC,CAAC;MACvE;QACE,OAAOoC,CAAC,CAACP,KAAK,CAACQ,MAAM,CAACxB,OAAO,CAAC8B,GAAG,CAACR,SAAS,CAACC,CAAC,CAAC,CAAC,EAAEC,MAAM,CAAC;IAAC;EAE/D,CAAC;AACH","names":["SchemaTypeId","Symbol","for","Schema","constructor","UnknownSchema","StringSchema","NumberSchema","BooleanSchema","BigIntSchema","LiteralSchema","value","NullableSchema","base","StructSchema","fields","PartialSchema","ArraySchema","RecordSchema","TupleSchema","components","LazySchema","make","ValidationSchema","validations","UnionSchema","members","unknown","string","number","boolean","bigint","literal","nullable","struct","partial","array","record","tuple","unsafeCoerce","lazy","validation","union","concrete","_","cacheThunk","f","cached","interpret","S","schema","_tag","tsplus_module_1","reverseGet","tsplus_module_2","get","map"],"sourceRoot":"","sources":["../_src/Schema.ts"],"sourcesContent":[null]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=Schemable.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Schemable.cjs","mappings":"","names":[],"sourceRoot":"","sources":[],"sourcesContent":[]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=global.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global.cjs","mappings":"","names":[],"sourceRoot":"","sources":[],"sourcesContent":[]}
package/_cjs/index.cjs ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","mappings":"","names":[],"sourceRoot":"","sources":[],"sourcesContent":[]}
@@ -0,0 +1,20 @@
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
@@ -0,0 +1 @@
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]}