pema 0.1.0

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 (155) hide show
  1. package/lib/private/AbstractConstructor.d.ts +3 -0
  2. package/lib/private/AbstractConstructor.js +2 -0
  3. package/lib/private/ArrayType.d.ts +12 -0
  4. package/lib/private/ArrayType.js +48 -0
  5. package/lib/private/BigIntType.d.ts +5 -0
  6. package/lib/private/BigIntType.js +7 -0
  7. package/lib/private/BlobType.d.ts +5 -0
  8. package/lib/private/BlobType.js +7 -0
  9. package/lib/private/BooleanType.d.ts +5 -0
  10. package/lib/private/BooleanType.js +7 -0
  11. package/lib/private/BuiltinType.d.ts +10 -0
  12. package/lib/private/BuiltinType.js +26 -0
  13. package/lib/private/ConstructorType.d.ts +12 -0
  14. package/lib/private/ConstructorType.js +28 -0
  15. package/lib/private/DateType.d.ts +5 -0
  16. package/lib/private/DateType.js +7 -0
  17. package/lib/private/DefaultType.d.ts +10 -0
  18. package/lib/private/DefaultType.js +27 -0
  19. package/lib/private/FileType.d.ts +5 -0
  20. package/lib/private/FileType.js +7 -0
  21. package/lib/private/GenericType.d.ts +7 -0
  22. package/lib/private/GenericType.js +10 -0
  23. package/lib/private/Infer.d.ts +4 -0
  24. package/lib/private/Infer.js +2 -0
  25. package/lib/private/InferSchema.d.ts +20 -0
  26. package/lib/private/InferSchema.js +2 -0
  27. package/lib/private/IntType.d.ts +7 -0
  28. package/lib/private/IntType.js +16 -0
  29. package/lib/private/LiteralType.d.ts +12 -0
  30. package/lib/private/LiteralType.js +24 -0
  31. package/lib/private/MaybeInt.d.ts +3 -0
  32. package/lib/private/MaybeInt.js +2 -0
  33. package/lib/private/NormalizeSchema.d.ts +16 -0
  34. package/lib/private/NormalizeSchema.js +2 -0
  35. package/lib/private/NullType.d.ts +7 -0
  36. package/lib/private/NullType.js +20 -0
  37. package/lib/private/NumberType.d.ts +5 -0
  38. package/lib/private/NumberType.js +7 -0
  39. package/lib/private/OptionalType.d.ts +10 -0
  40. package/lib/private/OptionalType.js +20 -0
  41. package/lib/private/PrimitiveType.d.ts +11 -0
  42. package/lib/private/PrimitiveType.js +31 -0
  43. package/lib/private/RecordType.d.ts +13 -0
  44. package/lib/private/RecordType.js +58 -0
  45. package/lib/private/RecordTypeKey.d.ts +6 -0
  46. package/lib/private/RecordTypeKey.js +2 -0
  47. package/lib/private/Schema.d.ts +7 -0
  48. package/lib/private/Schema.js +2 -0
  49. package/lib/private/SchemaType.d.ts +13 -0
  50. package/lib/private/SchemaType.js +63 -0
  51. package/lib/private/StringType.d.ts +8 -0
  52. package/lib/private/StringType.js +23 -0
  53. package/lib/private/SymbolType.d.ts +5 -0
  54. package/lib/private/SymbolType.js +7 -0
  55. package/lib/private/TupleType.d.ts +17 -0
  56. package/lib/private/TupleType.js +40 -0
  57. package/lib/private/Type.d.ts +10 -0
  58. package/lib/private/Type.js +15 -0
  59. package/lib/private/URLType.d.ts +5 -0
  60. package/lib/private/URLType.js +7 -0
  61. package/lib/private/UintType.d.ts +9 -0
  62. package/lib/private/UintType.js +16 -0
  63. package/lib/private/UndefinedType.d.ts +7 -0
  64. package/lib/private/UndefinedType.js +7 -0
  65. package/lib/private/UnionType.d.ts +18 -0
  66. package/lib/private/UnionType.js +63 -0
  67. package/lib/private/Validated.d.ts +8 -0
  68. package/lib/private/Validated.js +10 -0
  69. package/lib/private/ValidatedKey.d.ts +4 -0
  70. package/lib/private/ValidatedKey.js +3 -0
  71. package/lib/private/Validator.d.ts +3 -0
  72. package/lib/private/Validator.js +2 -0
  73. package/lib/private/array.d.ts +5 -0
  74. package/lib/private/array.js +3 -0
  75. package/lib/private/bigint.d.ts +4 -0
  76. package/lib/private/bigint.js +3 -0
  77. package/lib/private/blob.d.ts +4 -0
  78. package/lib/private/blob.js +3 -0
  79. package/lib/private/boolean.d.ts +4 -0
  80. package/lib/private/boolean.js +3 -0
  81. package/lib/private/constructor.d.ts +5 -0
  82. package/lib/private/constructor.js +3 -0
  83. package/lib/private/date.d.ts +4 -0
  84. package/lib/private/date.js +3 -0
  85. package/lib/private/error.d.ts +3 -0
  86. package/lib/private/error.js +4 -0
  87. package/lib/private/expect.d.ts +21 -0
  88. package/lib/private/expect.js +21 -0
  89. package/lib/private/expected.d.ts +3 -0
  90. package/lib/private/expected.js +2 -0
  91. package/lib/private/file.d.ts +4 -0
  92. package/lib/private/file.js +3 -0
  93. package/lib/private/index.d.ts +5 -0
  94. package/lib/private/index.js +43 -0
  95. package/lib/private/int.d.ts +4 -0
  96. package/lib/private/int.js +3 -0
  97. package/lib/private/is-int.d.ts +3 -0
  98. package/lib/private/is-int.js +5 -0
  99. package/lib/private/is_validated_type.d.ts +4 -0
  100. package/lib/private/is_validated_type.js +5 -0
  101. package/lib/private/literal.d.ts +5 -0
  102. package/lib/private/literal.js +3 -0
  103. package/lib/private/null.d.ts +4 -0
  104. package/lib/private/null.js +3 -0
  105. package/lib/private/number.d.ts +4 -0
  106. package/lib/private/number.js +3 -0
  107. package/lib/private/optional.d.ts +5 -0
  108. package/lib/private/optional.js +3 -0
  109. package/lib/private/record.d.ts +6 -0
  110. package/lib/private/record.js +3 -0
  111. package/lib/private/string.d.ts +4 -0
  112. package/lib/private/string.js +3 -0
  113. package/lib/private/symbol.d.ts +4 -0
  114. package/lib/private/symbol.js +3 -0
  115. package/lib/private/tuple.d.ts +5 -0
  116. package/lib/private/tuple.js +3 -0
  117. package/lib/private/uint.d.ts +4 -0
  118. package/lib/private/uint.js +3 -0
  119. package/lib/private/undefined.d.ts +4 -0
  120. package/lib/private/undefined.js +3 -0
  121. package/lib/private/union.d.ts +9 -0
  122. package/lib/private/union.js +3 -0
  123. package/lib/private/url.d.ts +4 -0
  124. package/lib/private/url.js +3 -0
  125. package/lib/public/Schema.d.ts +2 -0
  126. package/lib/public/Schema.js +2 -0
  127. package/lib/public/blob.d.ts +2 -0
  128. package/lib/public/blob.js +2 -0
  129. package/lib/public/boolean.d.ts +2 -0
  130. package/lib/public/boolean.js +2 -0
  131. package/lib/public/constructor.d.ts +2 -0
  132. package/lib/public/constructor.js +2 -0
  133. package/lib/public/date.d.ts +2 -0
  134. package/lib/public/date.js +2 -0
  135. package/lib/public/file.d.ts +2 -0
  136. package/lib/public/file.js +2 -0
  137. package/lib/public/index.d.ts +2 -0
  138. package/lib/public/index.js +2 -0
  139. package/lib/public/int.d.ts +2 -0
  140. package/lib/public/int.js +2 -0
  141. package/lib/public/number.d.ts +2 -0
  142. package/lib/public/number.js +2 -0
  143. package/lib/public/object.d.ts +2 -0
  144. package/lib/public/object.js +2 -0
  145. package/lib/public/optional.d.ts +2 -0
  146. package/lib/public/optional.js +2 -0
  147. package/lib/public/record.d.ts +2 -0
  148. package/lib/public/record.js +2 -0
  149. package/lib/public/string.d.ts +2 -0
  150. package/lib/public/string.js +2 -0
  151. package/lib/public/symbol.d.ts +2 -0
  152. package/lib/public/symbol.js +2 -0
  153. package/lib/public/union.d.ts +2 -0
  154. package/lib/public/union.js +2 -0
  155. package/package.json +45 -0
@@ -0,0 +1,13 @@
1
+ import GenericType from "#GenericType";
2
+ import type Infer from "#Infer";
3
+ import type InferSchema from "#InferSchema";
4
+ import OptionalType from "#OptionalType";
5
+ import type Schema from "#Schema";
6
+ export default class SchemaType<S extends Schema> extends GenericType<S, InferSchema<S>, "SchemaType"> {
7
+ #private;
8
+ constructor(s: S);
9
+ optional(): OptionalType<this>;
10
+ get name(): string;
11
+ validate(x: unknown, key?: string): Infer<this>;
12
+ }
13
+ //# sourceMappingURL=SchemaType.d.ts.map
@@ -0,0 +1,63 @@
1
+ import GenericType from "#GenericType";
2
+ import OptionalType from "#OptionalType";
3
+ import Validated from "#Validated";
4
+ import schema from "#index";
5
+ export default class SchemaType extends GenericType {
6
+ #schema;
7
+ constructor(s) {
8
+ super();
9
+ this.#schema = s;
10
+ }
11
+ optional() {
12
+ return new OptionalType(this);
13
+ }
14
+ get name() {
15
+ return "schema";
16
+ }
17
+ validate(x, key) {
18
+ const s = this.#schema;
19
+ if (s instanceof Validated) {
20
+ return s.validate(x, key);
21
+ }
22
+ if (Array.isArray(s)) {
23
+ if (s.length === 1) {
24
+ if (!Array.isArray(x))
25
+ throw new Error("Expected array");
26
+ return x.map((item) => schema(s[0]).validate(item, key));
27
+ }
28
+ else {
29
+ if (!Array.isArray(x))
30
+ throw new Error("Expected tuple");
31
+ if (x.length !== s.length)
32
+ throw new Error("Tuple length mismatch");
33
+ return s.map((sch, i) => schema(sch).validate(x[i], key));
34
+ }
35
+ }
36
+ if (typeof s === "object" && s !== null) {
37
+ if (typeof x !== "object" || x === null) {
38
+ throw new Error("Expected object");
39
+ }
40
+ const result = {};
41
+ for (const k in s) {
42
+ const r = schema(s[k]).validate(x[k], `.${k}`);
43
+ // exclude undefined (optionals)
44
+ if (r !== undefined) {
45
+ result[k] = r;
46
+ }
47
+ }
48
+ return result;
49
+ }
50
+ if (s === null) {
51
+ if (x !== null)
52
+ throw new Error("Expected null");
53
+ return null;
54
+ }
55
+ if (s === undefined) {
56
+ if (x !== undefined)
57
+ throw new Error("Expected undefined");
58
+ return undefined;
59
+ }
60
+ throw new Error("Invalid schema structure");
61
+ }
62
+ }
63
+ //# sourceMappingURL=SchemaType.js.map
@@ -0,0 +1,8 @@
1
+ import PrimitiveType from "#PrimitiveType";
2
+ import type Validator from "#Validator";
3
+ export default class StringType extends PrimitiveType<string, "StringType"> {
4
+ constructor(validators?: Validator<string>[]);
5
+ startsWith(prefix: string): StringType;
6
+ endsWith(suffix: string): StringType;
7
+ }
8
+ //# sourceMappingURL=StringType.d.ts.map
@@ -0,0 +1,23 @@
1
+ import PrimitiveType from "#PrimitiveType";
2
+ const starts_with_validator = (prefix) => (x) => {
3
+ if (!x.startsWith(prefix)) {
4
+ throw new Error(`"${x}" does not start with "${prefix}"`);
5
+ }
6
+ };
7
+ const ends_with_validator = (suffix) => (x) => {
8
+ if (!x.endsWith(suffix)) {
9
+ throw new Error(`"${x}" does not end with "${suffix}"`);
10
+ }
11
+ };
12
+ export default class StringType extends PrimitiveType {
13
+ constructor(validators) {
14
+ super("string", validators);
15
+ }
16
+ startsWith(prefix) {
17
+ return new StringType([...this.validators, starts_with_validator(prefix)]);
18
+ }
19
+ endsWith(suffix) {
20
+ return new StringType([...this.validators, ends_with_validator(suffix)]);
21
+ }
22
+ }
23
+ //# sourceMappingURL=StringType.js.map
@@ -0,0 +1,5 @@
1
+ import PrimitiveType from "#PrimitiveType";
2
+ export default class SymbolType extends PrimitiveType<symbol, "SymbolType"> {
3
+ constructor();
4
+ }
5
+ //# sourceMappingURL=SymbolType.d.ts.map
@@ -0,0 +1,7 @@
1
+ import PrimitiveType from "#PrimitiveType";
2
+ export default class SymbolType extends PrimitiveType {
3
+ constructor() {
4
+ super("symbol");
5
+ }
6
+ }
7
+ //# sourceMappingURL=SymbolType.js.map
@@ -0,0 +1,17 @@
1
+ import GenericType from "#GenericType";
2
+ import type Infer from "#Infer";
3
+ import type InferSchema from "#InferSchema";
4
+ import OptionalType from "#OptionalType";
5
+ import type Schema from "#Schema";
6
+ type InferTuple<T extends Schema[]> = {
7
+ [K in keyof T]: T[K] extends Schema ? InferSchema<T[K]> : "tuple-never";
8
+ };
9
+ export default class TupleType<T extends Schema[]> extends GenericType<T, InferTuple<T>, "TupleType"> {
10
+ #private;
11
+ constructor(members: T);
12
+ optional(): OptionalType<this>;
13
+ get name(): string;
14
+ validate(x: unknown, key?: string): Infer<this>;
15
+ }
16
+ export {};
17
+ //# sourceMappingURL=TupleType.d.ts.map
@@ -0,0 +1,40 @@
1
+ import error from "#error";
2
+ import expected from "#expected";
3
+ import GenericType from "#GenericType";
4
+ import schema from "#index";
5
+ import is_validated_type from "#is_validated_type";
6
+ import OptionalType from "#OptionalType";
7
+ const member_error = (i, key) => {
8
+ return key === undefined
9
+ ? `[${i}]`
10
+ : `${key}[${i}]`;
11
+ };
12
+ export default class TupleType extends GenericType {
13
+ #members;
14
+ constructor(members) {
15
+ super();
16
+ this.#members = members;
17
+ }
18
+ optional() {
19
+ return new OptionalType(this);
20
+ }
21
+ get name() {
22
+ return "tuple";
23
+ }
24
+ validate(x, key) {
25
+ if (!(!!x && Array.isArray(x))) {
26
+ throw new Error(error(expected("array", x), key));
27
+ }
28
+ this.#members.forEach((v, i) => {
29
+ const validator = is_validated_type(v) ? v : schema(v);
30
+ validator.validate(x[i], `${member_error(i, key)}`);
31
+ });
32
+ x.forEach((v, i) => {
33
+ const member = this.#members[i];
34
+ const validator = is_validated_type(member) ? member : schema(member);
35
+ validator.validate(v, `${member_error(i, key)}`);
36
+ });
37
+ return x;
38
+ }
39
+ }
40
+ //# sourceMappingURL=TupleType.js.map
@@ -0,0 +1,10 @@
1
+ import DefaultType from "#DefaultType";
2
+ import OptionalType from "#OptionalType";
3
+ import Validated from "#Validated";
4
+ import type Printable from "@rcompat/type/Printable";
5
+ export default abstract class Type<Type, Name extends string> extends Validated<Type> implements Printable {
6
+ optional(): OptionalType<this>;
7
+ default<const S extends Type>(value: S | (() => S)): DefaultType<this, S>;
8
+ get Name(): Name;
9
+ }
10
+ //# sourceMappingURL=Type.d.ts.map
@@ -0,0 +1,15 @@
1
+ import DefaultType from "#DefaultType";
2
+ import OptionalType from "#OptionalType";
3
+ import Validated from "#Validated";
4
+ export default class Type extends Validated {
5
+ optional() {
6
+ return new OptionalType(this);
7
+ }
8
+ default(value) {
9
+ return new DefaultType(this, value);
10
+ }
11
+ get Name() {
12
+ return undefined;
13
+ }
14
+ }
15
+ //# sourceMappingURL=Type.js.map
@@ -0,0 +1,5 @@
1
+ import BuiltinType from "#BuiltinType";
2
+ export default class URLType extends BuiltinType<URL, "URLType"> {
3
+ constructor();
4
+ }
5
+ //# sourceMappingURL=URLType.d.ts.map
@@ -0,0 +1,7 @@
1
+ import BuiltinType from "#BuiltinType";
2
+ export default class URLType extends BuiltinType {
3
+ constructor() {
4
+ super("url", URL);
5
+ }
6
+ }
7
+ //# sourceMappingURL=URLType.js.map
@@ -0,0 +1,9 @@
1
+ import type Infer from "#Infer";
2
+ import PrimitiveType from "#PrimitiveType";
3
+ type Name = "UintType";
4
+ export default class UintType extends PrimitiveType<number | bigint, Name> {
5
+ constructor();
6
+ validate(x: unknown, key?: string): Infer<this>;
7
+ }
8
+ export {};
9
+ //# sourceMappingURL=UintType.d.ts.map
@@ -0,0 +1,16 @@
1
+ import PrimitiveType from "#PrimitiveType";
2
+ import error from "#error";
3
+ import expected from "#expected";
4
+ import is_int from "#is-int";
5
+ export default class UintType extends PrimitiveType {
6
+ constructor() {
7
+ super("uint");
8
+ }
9
+ validate(x, key) {
10
+ if (!is_int(x) || x < 0) {
11
+ throw new Error(error(expected("uint", x), key));
12
+ }
13
+ return x;
14
+ }
15
+ }
16
+ //# sourceMappingURL=UintType.js.map
@@ -0,0 +1,7 @@
1
+ import PrimitiveType from "#PrimitiveType";
2
+ type Name = "UndefinedType";
3
+ export default class UndefinedType extends PrimitiveType<undefined, Name> {
4
+ constructor();
5
+ }
6
+ export {};
7
+ //# sourceMappingURL=UndefinedType.d.ts.map
@@ -0,0 +1,7 @@
1
+ import PrimitiveType from "#PrimitiveType";
2
+ export default class UndefinedType extends PrimitiveType {
3
+ constructor() {
4
+ super("undefined");
5
+ }
6
+ }
7
+ //# sourceMappingURL=UndefinedType.js.map
@@ -0,0 +1,18 @@
1
+ import GenericType from "#GenericType";
2
+ import type Infer from "#Infer";
3
+ import type InferSchema from "#InferSchema";
4
+ import OptionalType from "#OptionalType";
5
+ import type Schema from "#Schema";
6
+ import type TupleToUnion from "@rcompat/type/TupleToUnion";
7
+ type InferUnion<T extends Schema[]> = TupleToUnion<{
8
+ [K in keyof T]: T[K] extends Schema ? InferSchema<T[K]> : "union-never";
9
+ }>;
10
+ export default class UnionType<T extends Schema[]> extends GenericType<T, InferUnion<T>, "UnionType"> {
11
+ #private;
12
+ constructor(types: T);
13
+ optional(): OptionalType<this>;
14
+ get name(): string;
15
+ validate(x: unknown, key?: string): Infer<this>;
16
+ }
17
+ export {};
18
+ //# sourceMappingURL=UnionType.d.ts.map
@@ -0,0 +1,63 @@
1
+ import expected from "#expected";
2
+ import GenericType from "#GenericType";
3
+ import schema from "#index";
4
+ import is_validated_type from "#is_validated_type";
5
+ import OptionalType from "#OptionalType";
6
+ import assert from "@rcompat/invariant/assert";
7
+ const error = (message, key) => {
8
+ return key === undefined
9
+ ? message
10
+ : `${key}: ${message}`;
11
+ };
12
+ const print = (type) => {
13
+ const validated = is_validated_type(type);
14
+ if (validated) {
15
+ return type.name;
16
+ }
17
+ const type_of = typeof type;
18
+ if (type_of === "string") {
19
+ return `"${type}"`;
20
+ }
21
+ if (type_of === "bigint") {
22
+ return `${type}n`;
23
+ }
24
+ if (type_of === "object") {
25
+ return `{ ${Object.entries(type)
26
+ .map(([name, subtype]) => `${name}: ${print(subtype)}`)
27
+ .join(", ")} }`;
28
+ }
29
+ return type;
30
+ };
31
+ const to_union_string = (types) => `\`${types.map(t => is_validated_type(t) ? t.name : print(t)).join(" | ")}\``;
32
+ export default class UnionType extends GenericType {
33
+ #types;
34
+ constructor(types) {
35
+ assert(types.length > 1, "union type must have at least two members");
36
+ super();
37
+ this.#types = types;
38
+ }
39
+ optional() {
40
+ return new OptionalType(this);
41
+ }
42
+ get name() {
43
+ return "union";
44
+ }
45
+ validate(x, key) {
46
+ // union validates when any of its members validates
47
+ const validated = this.#types.some(type => {
48
+ const validator = is_validated_type(type) ? type : schema(type);
49
+ try {
50
+ validator.validate(x, key);
51
+ return true;
52
+ }
53
+ catch {
54
+ return false;
55
+ }
56
+ });
57
+ if (!validated) {
58
+ throw new Error(error(expected(to_union_string(this.#types), x), key));
59
+ }
60
+ return x;
61
+ }
62
+ }
63
+ //# sourceMappingURL=UnionType.js.map
@@ -0,0 +1,8 @@
1
+ import ValidatedKey from "#ValidatedKey";
2
+ export default abstract class Validated<StaticType> {
3
+ get [ValidatedKey](): "ValidatedKey";
4
+ get infer(): StaticType;
5
+ abstract get name(): string;
6
+ abstract validate(x: unknown, key?: string): StaticType;
7
+ }
8
+ //# sourceMappingURL=Validated.d.ts.map
@@ -0,0 +1,10 @@
1
+ import ValidatedKey from "#ValidatedKey";
2
+ export default class Validated {
3
+ get [ValidatedKey]() {
4
+ return "ValidatedKey";
5
+ }
6
+ get infer() {
7
+ return undefined;
8
+ }
9
+ }
10
+ //# sourceMappingURL=Validated.js.map
@@ -0,0 +1,4 @@
1
+ declare const ValidatedKey: unique symbol;
2
+ type ValidatedKey = typeof ValidatedKey;
3
+ export { ValidatedKey as default };
4
+ //# sourceMappingURL=ValidatedKey.d.ts.map
@@ -0,0 +1,3 @@
1
+ const ValidatedKey = Symbol("ValidatedKey");
2
+ export { ValidatedKey as default };
3
+ //# sourceMappingURL=ValidatedKey.js.map
@@ -0,0 +1,3 @@
1
+ type Validator<T = unknown> = (x: T) => void;
2
+ export type { Validator as default };
3
+ //# sourceMappingURL=Validator.d.ts.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Validator.js.map
@@ -0,0 +1,5 @@
1
+ import ArrayType from "#ArrayType";
2
+ import type Validated from "#Validated";
3
+ declare const _default: <const T extends Validated<unknown>>(t: T) => ArrayType<T>;
4
+ export default _default;
5
+ //# sourceMappingURL=array.d.ts.map
@@ -0,0 +1,3 @@
1
+ import ArrayType from "#ArrayType";
2
+ export default (t) => new ArrayType(t);
3
+ //# sourceMappingURL=array.js.map
@@ -0,0 +1,4 @@
1
+ import BigIntType from "#BigIntType";
2
+ declare const _default: BigIntType;
3
+ export default _default;
4
+ //# sourceMappingURL=bigint.d.ts.map
@@ -0,0 +1,3 @@
1
+ import BigIntType from "#BigIntType";
2
+ export default new BigIntType();
3
+ //# sourceMappingURL=bigint.js.map
@@ -0,0 +1,4 @@
1
+ import BlobType from "#BlobType";
2
+ declare const _default: BlobType;
3
+ export default _default;
4
+ //# sourceMappingURL=blob.d.ts.map
@@ -0,0 +1,3 @@
1
+ import BlobType from "#BlobType";
2
+ export default new BlobType();
3
+ //# sourceMappingURL=blob.js.map
@@ -0,0 +1,4 @@
1
+ import BooleanType from "#BooleanType";
2
+ declare const _default: BooleanType;
3
+ export default _default;
4
+ //# sourceMappingURL=boolean.d.ts.map
@@ -0,0 +1,3 @@
1
+ import BooleanType from "#BooleanType";
2
+ export default new BooleanType();
3
+ //# sourceMappingURL=boolean.js.map
@@ -0,0 +1,5 @@
1
+ import ConstructorType from "#ConstructorType";
2
+ import type AbstractConstructor from "@rcompat/type/AbstractConstructor";
3
+ declare const _default: <const C extends AbstractConstructor>(constructor: C) => ConstructorType<C>;
4
+ export default _default;
5
+ //# sourceMappingURL=constructor.d.ts.map
@@ -0,0 +1,3 @@
1
+ import ConstructorType from "#ConstructorType";
2
+ export default (constructor) => new ConstructorType(constructor);
3
+ //# sourceMappingURL=constructor.js.map
@@ -0,0 +1,4 @@
1
+ import DateType from "#DateType";
2
+ declare const _default: DateType;
3
+ export default _default;
4
+ //# sourceMappingURL=date.d.ts.map
@@ -0,0 +1,3 @@
1
+ import DateType from "#DateType";
2
+ export default new DateType();
3
+ //# sourceMappingURL=date.js.map
@@ -0,0 +1,3 @@
1
+ declare const _default: (message: string, key?: string) => string;
2
+ export default _default;
3
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1,4 @@
1
+ export default (message, key) => key === undefined
2
+ ? message
3
+ : `${key}: ${message}`;
4
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1,21 @@
1
+ declare const types: {
2
+ a: string;
3
+ b: string;
4
+ d: string;
5
+ n: string;
6
+ s: string;
7
+ u: string;
8
+ bt: string;
9
+ f: string;
10
+ bb: string;
11
+ o: string;
12
+ nl: string;
13
+ sy: string;
14
+ ur: string;
15
+ i: string;
16
+ ui: string;
17
+ co: string;
18
+ };
19
+ declare const _default: (type: keyof typeof types, got: unknown, at?: string) => string;
20
+ export default _default;
21
+ //# sourceMappingURL=expect.d.ts.map
@@ -0,0 +1,21 @@
1
+ const types = {
2
+ a: "array",
3
+ b: "boolean",
4
+ d: "date",
5
+ n: "number",
6
+ s: "string",
7
+ u: "undefined",
8
+ bt: "bigint",
9
+ f: "file",
10
+ bb: "blob",
11
+ o: "object",
12
+ nl: "null",
13
+ sy: "symbol",
14
+ ur: "url",
15
+ i: "int",
16
+ ui: "uint",
17
+ co: "constructor",
18
+ };
19
+ const prefix = (at) => at ? `${at}: ` : "";
20
+ export default (type, got, at = "") => `${prefix(at)}expected ${types[type]}, got \`${got}\` (${typeof got})`;
21
+ //# sourceMappingURL=expect.js.map
@@ -0,0 +1,3 @@
1
+ declare const _default: (type: string, x: unknown) => string;
2
+ export default _default;
3
+ //# sourceMappingURL=expected.d.ts.map
@@ -0,0 +1,2 @@
1
+ export default (type, x) => `expected ${type}, got \`${x?.toString() ?? x}\` (${(typeof x)})`;
2
+ //# sourceMappingURL=expected.js.map
@@ -0,0 +1,4 @@
1
+ import FileType from "#FileType";
2
+ declare const _default: FileType;
3
+ export default _default;
4
+ //# sourceMappingURL=file.d.ts.map
@@ -0,0 +1,3 @@
1
+ import FileType from "#FileType";
2
+ export default new FileType();
3
+ //# sourceMappingURL=file.js.map
@@ -0,0 +1,5 @@
1
+ import type NormalizeSchema from "#NormalizeSchema";
2
+ import type Schema from "#Schema";
3
+ import SchemaType from "#SchemaType";
4
+ export default function schema<const S extends Schema>(s: S): SchemaType<NormalizeSchema<S>>;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,43 @@
1
+ import array from "#array";
2
+ import constructor from "#constructor";
3
+ import is_validated_type from "#is_validated_type";
4
+ import literal from "#literal";
5
+ import null_type from "#null";
6
+ import SchemaType from "#SchemaType";
7
+ import tuple from "#tuple";
8
+ import undefined_type from "#undefined";
9
+ const is_constructor = (value) => {
10
+ try {
11
+ if (typeof value !== "function")
12
+ return false;
13
+ new value();
14
+ return true;
15
+ }
16
+ catch {
17
+ return false;
18
+ }
19
+ };
20
+ export default function schema(s) {
21
+ if (s === null) {
22
+ return new SchemaType(null_type);
23
+ }
24
+ if (s === undefined) {
25
+ return new SchemaType(undefined_type);
26
+ }
27
+ if (typeof s === "string") {
28
+ return new SchemaType(literal(s));
29
+ }
30
+ if (is_constructor(s)) {
31
+ return new SchemaType(constructor(s));
32
+ }
33
+ if (Array.isArray(s)) {
34
+ if (s.length === 1 && is_validated_type(s[0])) {
35
+ return new SchemaType(array(s[0]));
36
+ }
37
+ else {
38
+ return new SchemaType(tuple(...s));
39
+ }
40
+ }
41
+ return new SchemaType(s);
42
+ }
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,4 @@
1
+ import IntType from "#IntType";
2
+ declare const _default: IntType;
3
+ export default _default;
4
+ //# sourceMappingURL=int.d.ts.map
@@ -0,0 +1,3 @@
1
+ import IntType from "#IntType";
2
+ export default new IntType();
3
+ //# sourceMappingURL=int.js.map
@@ -0,0 +1,3 @@
1
+ declare const _default: (n: unknown) => n is number | bigint;
2
+ export default _default;
3
+ //# sourceMappingURL=is-int.d.ts.map
@@ -0,0 +1,5 @@
1
+ export default (n) => {
2
+ const type = typeof n;
3
+ return type === "number" && Number.isInteger(n) || type === "bigint";
4
+ };
5
+ //# sourceMappingURL=is-int.js.map
@@ -0,0 +1,4 @@
1
+ import type Validated from "#Validated";
2
+ declare const _default: (x: unknown) => x is Validated<unknown>;
3
+ export default _default;
4
+ //# sourceMappingURL=is_validated_type.d.ts.map
@@ -0,0 +1,5 @@
1
+ import ValidatedKey from "#ValidatedKey";
2
+ export default (x) => {
3
+ return !!x && typeof x === "object" && ValidatedKey in x;
4
+ };
5
+ //# sourceMappingURL=is_validated_type.js.map
@@ -0,0 +1,5 @@
1
+ import LiteralType from "#LiteralType";
2
+ type Literal = string;
3
+ declare const _default: <T extends Literal>(t: T) => LiteralType<T>;
4
+ export default _default;
5
+ //# sourceMappingURL=literal.d.ts.map
@@ -0,0 +1,3 @@
1
+ import LiteralType from "#LiteralType";
2
+ export default (t) => new LiteralType(t);
3
+ //# sourceMappingURL=literal.js.map