pema 0.1.0 → 0.2.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.
- package/LICENSE +19 -0
- package/lib/private/ArrayType.d.ts +28 -5
- package/lib/private/ArrayType.js +82 -22
- package/lib/private/BigIntDataType.d.ts +3 -0
- package/lib/private/BigIntDataType.js +2 -0
- package/lib/private/BigIntType.d.ts +8 -3
- package/lib/private/BigIntType.js +7 -4
- package/lib/private/BigUintDataType.d.ts +3 -0
- package/lib/private/BigUintDataType.js +2 -0
- package/lib/private/BigUintType.d.ts +10 -0
- package/lib/private/BigUintType.js +10 -0
- package/lib/private/BlobType.d.ts +12 -2
- package/lib/private/BlobType.js +12 -2
- package/lib/private/BooleanType.d.ts +10 -2
- package/lib/private/BooleanType.js +14 -2
- package/lib/private/BuiltinType.d.ts +7 -5
- package/lib/private/BuiltinType.js +18 -17
- package/lib/private/CoerceKey.d.ts +4 -0
- package/lib/private/CoerceKey.js +3 -0
- package/lib/private/ConstructorType.d.ts +10 -4
- package/lib/private/ConstructorType.js +13 -11
- package/lib/private/DataKey.d.ts +4 -0
- package/lib/private/DataKey.js +2 -0
- package/lib/private/DataType.d.ts +23 -0
- package/lib/private/DataType.js +2 -0
- package/lib/private/DateType.d.ts +12 -2
- package/lib/private/DateType.js +15 -2
- package/lib/private/DecrementDepth.d.ts +3 -0
- package/lib/private/DecrementDepth.js +2 -0
- package/lib/private/DefaultType.d.ts +13 -6
- package/lib/private/DefaultType.js +19 -11
- package/lib/private/FileType.d.ts +12 -2
- package/lib/private/FileType.js +12 -2
- package/lib/private/FloatDataType.d.ts +3 -0
- package/lib/private/FloatDataType.js +2 -0
- package/lib/private/GenericType.d.ts +2 -2
- package/lib/private/GenericType.js +2 -2
- package/lib/private/Id.d.ts +3 -0
- package/lib/private/Id.js +2 -0
- package/lib/private/Infer.d.ts +2 -2
- package/lib/private/InferInputSchema.d.ts +26 -0
- package/lib/private/InferInputSchema.js +2 -0
- package/lib/private/InferSchema.d.ts +5 -5
- package/lib/private/InferStore.d.ts +9 -0
- package/lib/private/InferStore.js +2 -0
- package/lib/private/InferStoreOut.d.ts +8 -0
- package/lib/private/InferStoreOut.js +2 -0
- package/lib/private/IntDataType.d.ts +3 -0
- package/lib/private/IntDataType.js +2 -0
- package/lib/private/IntType.d.ts +10 -5
- package/lib/private/IntType.js +13 -12
- package/lib/private/Issue.d.ts +6 -0
- package/lib/private/Issue.js +2 -0
- package/lib/private/LiteralType.d.ts +9 -2
- package/lib/private/LiteralType.js +17 -9
- package/lib/private/NormalizeSchema.d.ts +12 -7
- package/lib/private/NullType.d.ts +6 -2
- package/lib/private/NullType.js +11 -11
- package/lib/private/NumberType.d.ts +7 -3
- package/lib/private/NumberType.js +7 -4
- package/lib/private/NumericType.d.ts +25 -0
- package/lib/private/NumericType.js +38 -0
- package/lib/private/ObjectType.d.ts +23 -0
- package/lib/private/ObjectType.js +53 -0
- package/lib/private/OptionalType.d.ts +12 -5
- package/lib/private/OptionalType.js +16 -4
- package/lib/private/ParseError.d.ts +10 -0
- package/lib/private/ParseError.js +51 -0
- package/lib/private/ParseIssue.d.ts +5 -0
- package/lib/private/ParseIssue.js +2 -0
- package/lib/private/ParseOptions.d.ts +10 -0
- package/lib/private/ParseOptions.js +3 -0
- package/lib/private/Parsed.d.ts +24 -0
- package/lib/private/Parsed.js +17 -0
- package/lib/private/ParsedKey.d.ts +4 -0
- package/lib/private/ParsedKey.js +3 -0
- package/lib/private/PartialType.d.ts +25 -0
- package/lib/private/PartialType.js +69 -0
- package/lib/private/Partialable.d.ts +5 -0
- package/lib/private/Partialable.js +2 -0
- package/lib/private/PrimaryType.d.ts +14 -0
- package/lib/private/PrimaryType.js +26 -0
- package/lib/private/PrimitiveType.d.ts +12 -4
- package/lib/private/PrimitiveType.js +50 -17
- package/lib/private/PureType.d.ts +15 -0
- package/lib/private/PureType.js +21 -0
- package/lib/private/RecordType.d.ts +19 -4
- package/lib/private/RecordType.js +43 -14
- package/lib/private/RecordTypeKey.d.ts +1 -1
- package/lib/private/Schema.d.ts +3 -3
- package/lib/private/SchemaError.d.ts +4 -0
- package/lib/private/SchemaError.js +8 -0
- package/lib/private/Serialized.d.ts +72 -0
- package/lib/private/Serialized.js +2 -0
- package/lib/private/StoreId.d.ts +6 -0
- package/lib/private/StoreId.js +2 -0
- package/lib/private/StoreSchema.d.ts +8 -0
- package/lib/private/StoreSchema.js +2 -0
- package/lib/private/StoreType.d.ts +21 -0
- package/lib/private/StoreType.js +45 -0
- package/lib/private/Storeable.d.ts +15 -0
- package/lib/private/Storeable.js +7 -0
- package/lib/private/StringType.d.ts +17 -5
- package/lib/private/StringType.js +47 -13
- package/lib/private/SymbolType.d.ts +4 -1
- package/lib/private/SymbolType.js +5 -2
- package/lib/private/TupleType.d.ts +11 -4
- package/lib/private/TupleType.js +16 -22
- package/lib/private/Type.d.ts +5 -3
- package/lib/private/Type.js +2 -2
- package/lib/private/URLType.d.ts +16 -2
- package/lib/private/URLType.js +12 -2
- package/lib/private/UintDataType.d.ts +3 -0
- package/lib/private/UintDataType.js +2 -0
- package/lib/private/UintType.d.ts +14 -7
- package/lib/private/UintType.js +20 -12
- package/lib/private/UndefinedType.d.ts +4 -1
- package/lib/private/UndefinedType.js +7 -2
- package/lib/private/UnionType.d.ts +15 -4
- package/lib/private/UnionType.js +32 -26
- package/lib/private/UnknownType.d.ts +5 -0
- package/lib/private/UnknownType.js +7 -0
- package/lib/private/Validator.d.ts +1 -1
- package/lib/private/VirtualType.d.ts +6 -0
- package/lib/private/VirtualType.js +11 -0
- package/lib/private/array.d.ts +6 -3
- package/lib/private/array.js +7 -1
- package/lib/private/bigint.d.ts +1 -3
- package/lib/private/bigint.js +1 -2
- package/lib/private/biguint.d.ts +2 -0
- package/lib/private/biguint.js +2 -0
- package/lib/private/boolean.d.ts +3 -0
- package/lib/private/boolean.js +3 -0
- package/lib/private/coerce/bigint.d.ts +2 -0
- package/lib/private/coerce/bigint.js +13 -0
- package/lib/private/coerce/date.d.ts +2 -0
- package/lib/private/coerce/date.js +56 -0
- package/lib/private/coerce/int.d.ts +2 -0
- package/lib/private/coerce/int.js +8 -0
- package/lib/private/constructor.d.ts +5 -2
- package/lib/private/constructor.js +3 -0
- package/lib/private/error/fail.d.ts +3 -0
- package/lib/private/error/fail.js +5 -0
- package/lib/private/error/schemafail.d.ts +3 -0
- package/lib/private/error/schemafail.js +5 -0
- package/lib/private/error.d.ts +3 -2
- package/lib/private/error.js +10 -3
- package/lib/private/expect.d.ts +12 -11
- package/lib/private/expect.js +22 -11
- package/lib/private/expected.js +10 -1
- package/lib/private/f32.d.ts +4 -0
- package/lib/private/f32.js +4 -0
- package/lib/private/f64.d.ts +4 -0
- package/lib/private/f64.js +3 -0
- package/lib/private/i128.d.ts +4 -0
- package/lib/private/i128.js +6 -0
- package/lib/private/i16.d.ts +4 -0
- package/lib/private/i16.js +6 -0
- package/lib/private/i32.d.ts +4 -0
- package/lib/private/i32.js +6 -0
- package/lib/private/i64.d.ts +4 -0
- package/lib/private/i64.js +6 -0
- package/lib/private/i8.d.ts +4 -0
- package/lib/private/i8.js +6 -0
- package/lib/private/index.d.ts +4 -2
- package/lib/private/index.js +5 -40
- package/lib/private/int.d.ts +1 -3
- package/lib/private/int.js +1 -2
- package/lib/private/is-parsed-type.d.ts +3 -0
- package/lib/private/is-parsed-type.js +6 -0
- package/lib/private/json/JSONIssue.d.ts +6 -0
- package/lib/private/json/JSONIssue.js +2 -0
- package/lib/private/json/JSONPayload.d.ts +5 -0
- package/lib/private/json/JSONPayload.js +2 -0
- package/lib/private/literal.d.ts +1 -2
- package/lib/private/literal.js +1 -1
- package/lib/private/normalize.d.ts +4 -0
- package/lib/private/normalize.js +42 -0
- package/lib/private/number.d.ts +1 -3
- package/lib/private/number.js +1 -2
- package/lib/private/object.d.ts +11 -0
- package/lib/private/object.js +10 -0
- package/lib/private/optional.d.ts +2 -2
- package/lib/private/partial.d.ts +9 -0
- package/lib/private/partial.js +8 -0
- package/lib/private/path/join.d.ts +3 -0
- package/lib/private/path/join.js +13 -0
- package/lib/private/path/next.d.ts +9 -0
- package/lib/private/path/next.js +9 -0
- package/lib/private/path/rebase.d.ts +3 -0
- package/lib/private/path/rebase.js +9 -0
- package/lib/private/primary.d.ts +4 -0
- package/lib/private/primary.js +3 -0
- package/lib/private/pure.d.ts +3 -0
- package/lib/private/pure.js +5 -0
- package/lib/private/record.d.ts +5 -2
- package/lib/private/record.js +3 -0
- package/lib/private/spec/bigint.d.ts +5 -0
- package/lib/private/spec/bigint.js +73 -0
- package/lib/private/spec/biguint.d.ts +5 -0
- package/lib/private/spec/biguint.js +73 -0
- package/lib/private/spec/int.d.ts +5 -0
- package/lib/private/spec/int.js +70 -0
- package/lib/private/spec/uint.d.ts +5 -0
- package/lib/private/spec/uint.js +73 -0
- package/lib/private/string.d.ts +3 -0
- package/lib/private/string.js +3 -0
- package/lib/private/test/messages-of.d.ts +3 -0
- package/lib/private/test/messages-of.js +4 -0
- package/lib/private/test/paths-of.d.ts +3 -0
- package/lib/private/test/paths-of.js +4 -0
- package/lib/private/test/throws-issues.d.ts +4 -0
- package/lib/private/test/throws-issues.js +13 -0
- package/lib/private/trait/Default.d.ts +9 -0
- package/lib/private/trait/Default.js +4 -0
- package/lib/private/trait/Optional.d.ts +11 -0
- package/lib/private/trait/Optional.js +4 -0
- package/lib/private/tuple.d.ts +6 -2
- package/lib/private/tuple.js +6 -1
- package/lib/private/u128.d.ts +4 -0
- package/lib/private/u128.js +6 -0
- package/lib/private/u16.d.ts +4 -0
- package/lib/private/u16.js +6 -0
- package/lib/private/u32.d.ts +7 -0
- package/lib/private/u32.js +9 -0
- package/lib/private/u64.d.ts +4 -0
- package/lib/private/u64.js +6 -0
- package/lib/private/u8.d.ts +4 -0
- package/lib/private/u8.js +6 -0
- package/lib/private/uint.d.ts +1 -3
- package/lib/private/uint.js +1 -2
- package/lib/private/union.d.ts +6 -5
- package/lib/private/union.js +4 -1
- package/lib/private/unknown.d.ts +7 -0
- package/lib/private/unknown.js +6 -0
- package/lib/private/validator/email.d.ts +3 -0
- package/lib/private/validator/email.js +4 -0
- package/lib/private/validator/ends-with.d.ts +4 -0
- package/lib/private/validator/ends-with.js +11 -0
- package/lib/private/validator/f32.d.ts +2 -0
- package/lib/private/validator/f32.js +11 -0
- package/lib/private/validator/integer.d.ts +3 -0
- package/lib/private/validator/integer.js +12 -0
- package/lib/private/validator/isotime.d.ts +2 -0
- package/lib/private/validator/isotime.js +30 -0
- package/lib/private/validator/length.d.ts +5 -0
- package/lib/private/validator/length.js +29 -0
- package/lib/private/validator/max.d.ts +6 -0
- package/lib/private/validator/max.js +37 -0
- package/lib/private/validator/min.d.ts +6 -0
- package/lib/private/validator/min.js +37 -0
- package/lib/private/validator/port.d.ts +3 -0
- package/lib/private/validator/port.js +15 -0
- package/lib/private/validator/range.d.ts +3 -0
- package/lib/private/validator/range.js +22 -0
- package/lib/private/validator/regex.d.ts +5 -0
- package/lib/private/validator/regex.js +15 -0
- package/lib/private/validator/starts-with.d.ts +4 -0
- package/lib/private/validator/starts-with.js +11 -0
- package/lib/private/validator/unique-by.d.ts +2 -0
- package/lib/private/validator/unique-by.js +23 -0
- package/lib/private/validator/unique-with.d.ts +2 -0
- package/lib/private/validator/unique-with.js +18 -0
- package/lib/private/validator/unique.d.ts +2 -0
- package/lib/private/validator/unique.js +19 -0
- package/lib/private/validator/uuid.d.ts +3 -0
- package/lib/private/validator/uuid.js +4 -0
- package/lib/private/validator/values.d.ts +4 -0
- package/lib/private/validator/values.js +14 -0
- package/lib/public/DataType.d.ts +2 -0
- package/lib/public/DataType.js +2 -0
- package/lib/public/Id.d.ts +2 -0
- package/lib/public/Id.js +2 -0
- package/lib/public/InferStore.d.ts +2 -0
- package/lib/public/InferStore.js +2 -0
- package/lib/public/InferStoreOut.d.ts +2 -0
- package/lib/public/InferStoreOut.js +2 -0
- package/lib/public/Issue.d.ts +2 -0
- package/lib/public/Issue.js +2 -0
- package/lib/public/JSONPayload.d.ts +2 -0
- package/lib/public/JSONPayload.js +2 -0
- package/lib/public/ParseError.d.ts +2 -0
- package/lib/public/ParseError.js +2 -0
- package/lib/public/Serialized.d.ts +2 -0
- package/lib/public/Serialized.js +2 -0
- package/lib/public/StoreId.d.ts +2 -0
- package/lib/public/StoreId.js +2 -0
- package/lib/public/StoreSchema.d.ts +2 -0
- package/lib/public/StoreSchema.js +2 -0
- package/lib/public/StoreType.d.ts +3 -0
- package/lib/public/StoreType.js +2 -0
- package/lib/public/array.d.ts +3 -0
- package/lib/public/array.js +3 -0
- package/lib/public/bigint.d.ts +2 -0
- package/lib/public/bigint.js +2 -0
- package/lib/public/biguint.d.ts +2 -0
- package/lib/public/biguint.js +2 -0
- package/lib/public/boolean.d.ts +1 -0
- package/lib/public/boolean.js +1 -0
- package/lib/public/constructor.d.ts +1 -0
- package/lib/public/constructor.js +1 -0
- package/lib/public/f32.d.ts +2 -0
- package/lib/public/f32.js +2 -0
- package/lib/public/f64.d.ts +2 -0
- package/lib/public/f64.js +2 -0
- package/lib/public/i128.d.ts +2 -0
- package/lib/public/i128.js +2 -0
- package/lib/public/i16.d.ts +2 -0
- package/lib/public/i16.js +2 -0
- package/lib/public/i32.d.ts +2 -0
- package/lib/public/i32.js +2 -0
- package/lib/public/i64.d.ts +2 -0
- package/lib/public/i64.js +2 -0
- package/lib/public/i8.d.ts +2 -0
- package/lib/public/i8.js +2 -0
- package/lib/public/index.d.ts +6 -0
- package/lib/public/index.js +6 -0
- package/lib/public/number.d.ts +1 -0
- package/lib/public/number.js +1 -0
- package/lib/public/primary.d.ts +2 -0
- package/lib/public/primary.js +2 -0
- package/lib/public/pure.d.ts +2 -0
- package/lib/public/pure.js +2 -0
- package/lib/public/record.d.ts +1 -0
- package/lib/public/record.js +1 -0
- package/lib/public/string.d.ts +1 -0
- package/lib/public/string.js +1 -0
- package/lib/public/u128.d.ts +2 -0
- package/lib/public/u128.js +2 -0
- package/lib/public/u16.d.ts +2 -0
- package/lib/public/u16.js +2 -0
- package/lib/public/u32.d.ts +2 -0
- package/lib/public/u32.js +2 -0
- package/lib/public/u64.d.ts +2 -0
- package/lib/public/u64.js +2 -0
- package/lib/public/u8.d.ts +2 -0
- package/lib/public/u8.js +2 -0
- package/lib/public/uint.d.ts +3 -0
- package/lib/public/uint.js +3 -0
- package/lib/public/union.d.ts +1 -0
- package/lib/public/union.js +1 -0
- package/lib/public/unknown.d.ts +3 -0
- package/lib/public/unknown.js +2 -0
- package/package.json +14 -11
- package/lib/private/AbstractConstructor.d.ts +0 -3
- package/lib/private/AbstractConstructor.js +0 -2
- package/lib/private/MaybeInt.d.ts +0 -3
- package/lib/private/MaybeInt.js +0 -2
- package/lib/private/SchemaType.d.ts +0 -13
- package/lib/private/SchemaType.js +0 -63
- package/lib/private/Validated.d.ts +0 -8
- package/lib/private/Validated.js +0 -10
- package/lib/private/ValidatedKey.d.ts +0 -4
- package/lib/private/ValidatedKey.js +0 -3
- package/lib/private/is-int.d.ts +0 -3
- package/lib/private/is-int.js +0 -5
- package/lib/private/is_validated_type.d.ts +0 -4
- package/lib/private/is_validated_type.js +0 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) Terrablue <terrablue@proton.me> and contributors.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
16
|
+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
|
@@ -1,12 +1,35 @@
|
|
|
1
1
|
import GenericType from "#GenericType";
|
|
2
2
|
import type Infer from "#Infer";
|
|
3
3
|
import OptionalType from "#OptionalType";
|
|
4
|
-
import type
|
|
5
|
-
|
|
4
|
+
import type Parsed from "#Parsed";
|
|
5
|
+
import type ParseOptions from "#ParseOptions";
|
|
6
|
+
import type OptionalTrait from "#trait/Optional";
|
|
7
|
+
import type Validator from "#Validator";
|
|
8
|
+
import type Primitive from "@rcompat/type/Primitive";
|
|
9
|
+
type Next<T> = {
|
|
10
|
+
validators?: Validator<T>[];
|
|
11
|
+
};
|
|
12
|
+
export default class ArrayType<T extends Parsed<unknown>> extends GenericType<T, Infer<T>[], "ArrayType"> implements OptionalTrait {
|
|
6
13
|
#private;
|
|
7
|
-
constructor(
|
|
14
|
+
constructor(item: T, validators?: Validator<Array<Infer<T>>>[]);
|
|
15
|
+
get name(): "array";
|
|
8
16
|
optional(): OptionalType<this>;
|
|
9
|
-
|
|
10
|
-
|
|
17
|
+
derive(_next: Next<Array<Infer<T>>>): this;
|
|
18
|
+
/**
|
|
19
|
+
* Member values are unique — only for primitive subtypes.
|
|
20
|
+
*
|
|
21
|
+
* @throws `SchemaError` if the subtype is not a primitive.
|
|
22
|
+
* @returns ArrayType<T>
|
|
23
|
+
*/
|
|
24
|
+
unique(this: Infer<T> extends Primitive ? ArrayType<T> : never): ArrayType<T>;
|
|
25
|
+
min(limit: number): this;
|
|
26
|
+
max(limit: number): this;
|
|
27
|
+
length(from: number, to: number): this;
|
|
28
|
+
parse(x: unknown, options?: ParseOptions): Infer<this>;
|
|
29
|
+
toJSON(): {
|
|
30
|
+
type: "array";
|
|
31
|
+
of: import("./Serialized.js").default;
|
|
32
|
+
};
|
|
11
33
|
}
|
|
34
|
+
export {};
|
|
12
35
|
//# sourceMappingURL=ArrayType.d.ts.map
|
package/lib/private/ArrayType.js
CHANGED
|
@@ -1,48 +1,108 @@
|
|
|
1
|
-
import
|
|
1
|
+
import error from "#error";
|
|
2
|
+
import schemafail from "#error/schemafail";
|
|
2
3
|
import GenericType from "#GenericType";
|
|
3
4
|
import OptionalType from "#OptionalType";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
import ParsedKey from "#ParsedKey";
|
|
6
|
+
import ParseError from "#ParseError";
|
|
7
|
+
import join from "#path/join";
|
|
8
|
+
import next from "#path/next";
|
|
9
|
+
import rebase from "#path/rebase";
|
|
10
|
+
import PrimitiveType from "#PrimitiveType";
|
|
11
|
+
import length from "#validator/length";
|
|
12
|
+
import max from "#validator/max";
|
|
13
|
+
import min from "#validator/min";
|
|
14
|
+
import unique from "#validator/unique";
|
|
15
|
+
function isPrimitive(x) {
|
|
16
|
+
return x instanceof PrimitiveType;
|
|
17
|
+
}
|
|
14
18
|
const is = (x, validator) => validator(x);
|
|
15
19
|
export default class ArrayType extends GenericType {
|
|
16
|
-
#
|
|
17
|
-
|
|
20
|
+
#item;
|
|
21
|
+
#validators;
|
|
22
|
+
constructor(item, validators = []) {
|
|
18
23
|
super();
|
|
19
|
-
this.#
|
|
24
|
+
this.#item = item;
|
|
25
|
+
this.#validators = validators;
|
|
26
|
+
}
|
|
27
|
+
get name() {
|
|
28
|
+
return "array";
|
|
20
29
|
}
|
|
21
30
|
optional() {
|
|
22
31
|
return new OptionalType(this);
|
|
23
32
|
}
|
|
24
|
-
|
|
25
|
-
|
|
33
|
+
derive(_next) {
|
|
34
|
+
const Constructor = this.constructor;
|
|
35
|
+
return new Constructor(this.#item, [...this.#validators, ..._next.validators ?? []]);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Member values are unique — only for primitive subtypes.
|
|
39
|
+
*
|
|
40
|
+
* @throws `SchemaError` if the subtype is not a primitive.
|
|
41
|
+
* @returns ArrayType<T>
|
|
42
|
+
*/
|
|
43
|
+
unique() {
|
|
44
|
+
if (!isPrimitive(this.#item)) {
|
|
45
|
+
throw schemafail("unique: subtype {0} must be primitive", this.#item.name);
|
|
46
|
+
}
|
|
47
|
+
return this.derive({ validators: [unique] });
|
|
26
48
|
}
|
|
27
|
-
|
|
49
|
+
min(limit) {
|
|
50
|
+
if (limit < 0) {
|
|
51
|
+
throw schemafail("min: {0} must be positive", limit);
|
|
52
|
+
}
|
|
53
|
+
return this.derive({ validators: [min(limit)] });
|
|
54
|
+
}
|
|
55
|
+
max(limit) {
|
|
56
|
+
if (limit < 0) {
|
|
57
|
+
throw schemafail("max: {0} must be positive", limit);
|
|
58
|
+
}
|
|
59
|
+
return this.derive({ validators: [max(limit)] });
|
|
60
|
+
}
|
|
61
|
+
length(from, to) {
|
|
62
|
+
return this.derive({ validators: [length(from, to)] });
|
|
63
|
+
}
|
|
64
|
+
parse(x, options = {}) {
|
|
28
65
|
if (!is(x, _ => !!x && Array.isArray(x))) {
|
|
29
|
-
throw new
|
|
66
|
+
throw new ParseError(error("array", x, options));
|
|
30
67
|
}
|
|
68
|
+
const base = options[ParsedKey] ?? "";
|
|
31
69
|
let last = 0;
|
|
32
70
|
x.forEach((v, i) => {
|
|
33
71
|
// sparse array check
|
|
34
72
|
if (i > last) {
|
|
35
|
-
throw new
|
|
73
|
+
throw new ParseError([{
|
|
74
|
+
...error(this.#item.name, undefined, options)[0],
|
|
75
|
+
path: join(base, last),
|
|
76
|
+
}]);
|
|
36
77
|
}
|
|
37
|
-
const validator = this.#
|
|
38
|
-
validator.
|
|
78
|
+
const validator = this.#item;
|
|
79
|
+
validator.parse(v, next(i, options));
|
|
39
80
|
last++;
|
|
40
81
|
});
|
|
41
82
|
// sparse array with end slots
|
|
42
83
|
if (x.length > last) {
|
|
43
|
-
throw new
|
|
84
|
+
throw new ParseError([{
|
|
85
|
+
...error(this.#item.name, undefined, options)[0],
|
|
86
|
+
path: join(base, last),
|
|
87
|
+
}]);
|
|
88
|
+
}
|
|
89
|
+
for (const v of this.#validators) {
|
|
90
|
+
try {
|
|
91
|
+
v(x);
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
if (e instanceof ParseError) {
|
|
95
|
+
const rebased = (e.issues ?? [])
|
|
96
|
+
.map(i => ({ ...i, path: rebase(base, i.path) }));
|
|
97
|
+
throw new ParseError(rebased);
|
|
98
|
+
}
|
|
99
|
+
throw e;
|
|
100
|
+
}
|
|
44
101
|
}
|
|
45
102
|
return x;
|
|
46
103
|
}
|
|
104
|
+
toJSON() {
|
|
105
|
+
return { type: this.name, of: this.#item.toJSON() };
|
|
106
|
+
}
|
|
47
107
|
}
|
|
48
108
|
//# sourceMappingURL=ArrayType.js.map
|
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type BigIntDataType from "#BigIntDataType";
|
|
2
|
+
import coerce from "#coerce/bigint";
|
|
3
|
+
import CoerceKey from "#CoerceKey";
|
|
4
|
+
import NumericType from "#NumericType";
|
|
5
|
+
import type Storeable from "#Storeable";
|
|
6
|
+
export default class BigIntType<T extends BigIntDataType = "i64"> extends NumericType<T, bigint, "BigIntType"> implements Storeable<T> {
|
|
7
|
+
[CoerceKey]: typeof coerce;
|
|
8
|
+
get name(): string;
|
|
4
9
|
}
|
|
5
10
|
//# sourceMappingURL=BigIntType.d.ts.map
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import coerce from "#coerce/bigint";
|
|
2
|
+
import CoerceKey from "#CoerceKey";
|
|
3
|
+
import NumericType from "#NumericType";
|
|
4
|
+
export default class BigIntType extends NumericType {
|
|
5
|
+
[CoerceKey] = coerce;
|
|
6
|
+
get name() {
|
|
7
|
+
return "bigint";
|
|
5
8
|
}
|
|
6
9
|
}
|
|
7
10
|
//# sourceMappingURL=BigIntType.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type BigUintDataType from "#BigUintDataType";
|
|
2
|
+
import coerce from "#coerce/bigint";
|
|
3
|
+
import CoerceKey from "#CoerceKey";
|
|
4
|
+
import NumericType from "#NumericType";
|
|
5
|
+
import type Storeable from "#Storeable";
|
|
6
|
+
export default class BigUintType<T extends BigUintDataType = "u64"> extends NumericType<T, bigint, "BigUintType"> implements Storeable<T> {
|
|
7
|
+
[CoerceKey]: typeof coerce;
|
|
8
|
+
get name(): string;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=BigUintType.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import coerce from "#coerce/bigint";
|
|
2
|
+
import CoerceKey from "#CoerceKey";
|
|
3
|
+
import NumericType from "#NumericType";
|
|
4
|
+
export default class BigUintType extends NumericType {
|
|
5
|
+
[CoerceKey] = coerce;
|
|
6
|
+
get name() {
|
|
7
|
+
return "bigint";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=BigUintType.js.map
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import BuiltinType from "#BuiltinType";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import Storeable from "#Storeable";
|
|
3
|
+
export default class BlobType extends BuiltinType<Blob, "BlobType"> implements Storeable<"blob"> {
|
|
4
|
+
get Type(): {
|
|
5
|
+
new (blobParts?: BlobPart[], options?: BlobPropertyBag): Blob;
|
|
6
|
+
prototype: Blob;
|
|
7
|
+
};
|
|
8
|
+
get name(): "blob";
|
|
9
|
+
get datatype(): "blob";
|
|
10
|
+
toJSON(): {
|
|
11
|
+
type: "blob";
|
|
12
|
+
datatype: "blob";
|
|
13
|
+
};
|
|
4
14
|
}
|
|
5
15
|
//# sourceMappingURL=BlobType.d.ts.map
|
package/lib/private/BlobType.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import BuiltinType from "#BuiltinType";
|
|
2
|
+
import Storeable from "#Storeable";
|
|
2
3
|
export default class BlobType extends BuiltinType {
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
get Type() {
|
|
5
|
+
return Blob;
|
|
6
|
+
}
|
|
7
|
+
get name() {
|
|
8
|
+
return "blob";
|
|
9
|
+
}
|
|
10
|
+
get datatype() {
|
|
11
|
+
return "blob";
|
|
12
|
+
}
|
|
13
|
+
toJSON() {
|
|
14
|
+
return Storeable.serialize(this);
|
|
5
15
|
}
|
|
6
16
|
}
|
|
7
17
|
//# sourceMappingURL=BlobType.js.map
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
import CoerceKey from "#CoerceKey";
|
|
1
2
|
import PrimitiveType from "#PrimitiveType";
|
|
2
|
-
|
|
3
|
-
|
|
3
|
+
import Storeable from "#Storeable";
|
|
4
|
+
export default class BooleanType extends PrimitiveType<boolean, "BooleanType"> implements Storeable<"boolean"> {
|
|
5
|
+
get name(): "boolean";
|
|
6
|
+
get datatype(): "boolean";
|
|
7
|
+
[CoerceKey](x: unknown): unknown;
|
|
8
|
+
toJSON(): {
|
|
9
|
+
type: "boolean";
|
|
10
|
+
datatype: "boolean";
|
|
11
|
+
};
|
|
4
12
|
}
|
|
5
13
|
//# sourceMappingURL=BooleanType.d.ts.map
|
|
@@ -1,7 +1,19 @@
|
|
|
1
|
+
import CoerceKey from "#CoerceKey";
|
|
1
2
|
import PrimitiveType from "#PrimitiveType";
|
|
3
|
+
import Storeable from "#Storeable";
|
|
4
|
+
import boolish from "@rcompat/is/boolish";
|
|
2
5
|
export default class BooleanType extends PrimitiveType {
|
|
3
|
-
|
|
4
|
-
|
|
6
|
+
get name() {
|
|
7
|
+
return "boolean";
|
|
8
|
+
}
|
|
9
|
+
get datatype() {
|
|
10
|
+
return "boolean";
|
|
11
|
+
}
|
|
12
|
+
[CoerceKey](x) {
|
|
13
|
+
return boolish(x) ? x === "true" : x;
|
|
14
|
+
}
|
|
15
|
+
toJSON() {
|
|
16
|
+
return Storeable.serialize(this);
|
|
5
17
|
}
|
|
6
18
|
}
|
|
7
19
|
//# sourceMappingURL=BooleanType.js.map
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type Infer from "#Infer";
|
|
2
|
+
import type ParseOptions from "#ParseOptions";
|
|
2
3
|
import Type from "#Type";
|
|
3
|
-
import type
|
|
4
|
-
export default class BuiltinType<StaticType, Name extends string> extends Type<StaticType, Name> {
|
|
4
|
+
import type AbstractNewable from "@rcompat/type/AbstractNewable";
|
|
5
|
+
export default abstract class BuiltinType<StaticType, Name extends string> extends Type<StaticType, Name> {
|
|
5
6
|
#private;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
abstract get Type(): AbstractNewable;
|
|
8
|
+
constructor(options?: ParseOptions);
|
|
9
|
+
get coerce(): this;
|
|
10
|
+
parse(x: unknown, options?: ParseOptions): Infer<this>;
|
|
9
11
|
}
|
|
10
12
|
//# sourceMappingURL=BuiltinType.d.ts.map
|
|
@@ -1,26 +1,27 @@
|
|
|
1
|
+
import CoerceKey from "#CoerceKey";
|
|
2
|
+
import error from "#error";
|
|
3
|
+
import ParseError from "#ParseError";
|
|
1
4
|
import Type from "#Type";
|
|
2
|
-
const error_message = (name, x, key) => {
|
|
3
|
-
const base = `expected ${name}, got \`${x}\` (${(typeof x)})`;
|
|
4
|
-
return key === undefined
|
|
5
|
-
? base
|
|
6
|
-
: `${key}: ${base}`;
|
|
7
|
-
};
|
|
8
5
|
export default class BuiltinType extends Type {
|
|
9
|
-
#
|
|
10
|
-
|
|
11
|
-
constructor(name, type) {
|
|
6
|
+
#options;
|
|
7
|
+
constructor(options = {}) {
|
|
12
8
|
super();
|
|
13
|
-
this.#
|
|
14
|
-
this.#type = type;
|
|
9
|
+
this.#options = options;
|
|
15
10
|
}
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
#derive(next) {
|
|
12
|
+
const Constructor = this.constructor;
|
|
13
|
+
return new Constructor({ ...this.#options, ...next });
|
|
18
14
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
get coerce() {
|
|
16
|
+
return this.#derive({ coerce: true });
|
|
17
|
+
}
|
|
18
|
+
parse(x, options = {}) {
|
|
19
|
+
const $options = { ...this.#options, ...options };
|
|
20
|
+
const $x = $options.coerce === true ? this[CoerceKey](x) : x;
|
|
21
|
+
if (!($x instanceof this.Type)) {
|
|
22
|
+
throw new ParseError(error(this.name, $x, $options));
|
|
22
23
|
}
|
|
23
|
-
return x;
|
|
24
|
+
return $x;
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
//# sourceMappingURL=BuiltinType.js.map
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import DefaultType from "#DefaultType";
|
|
2
2
|
import GenericType from "#GenericType";
|
|
3
3
|
import type Infer from "#Infer";
|
|
4
|
-
import type
|
|
5
|
-
|
|
4
|
+
import type ParseOptions from "#ParseOptions";
|
|
5
|
+
import type DefaultTrait from "#trait/Default";
|
|
6
|
+
import type AbstractNewable from "@rcompat/type/AbstractNewable";
|
|
7
|
+
export default class ConstructorType<C extends AbstractNewable> extends GenericType<C, InstanceType<C>, "InstanceType"> implements DefaultTrait<InstanceType<C>> {
|
|
6
8
|
#private;
|
|
7
9
|
constructor(t: C);
|
|
8
|
-
default(value: InstanceType<C> | (() => InstanceType<C>)): DefaultType<this, InstanceType<C>>;
|
|
9
10
|
get name(): string;
|
|
10
|
-
|
|
11
|
+
default(value: (() => InstanceType<C>) | InstanceType<C>): DefaultType<this, InstanceType<C>>;
|
|
12
|
+
parse(x: unknown, options?: ParseOptions): Infer<this>;
|
|
13
|
+
toJSON(): {
|
|
14
|
+
type: "newable";
|
|
15
|
+
of: string;
|
|
16
|
+
};
|
|
11
17
|
}
|
|
12
18
|
//# sourceMappingURL=ConstructorType.d.ts.map
|
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
import DefaultType from "#DefaultType";
|
|
2
|
+
import error from "#error";
|
|
2
3
|
import GenericType from "#GenericType";
|
|
3
|
-
|
|
4
|
-
const base = `expected ${name}, got \`${x}\` (${(typeof x)})`;
|
|
5
|
-
return key === undefined
|
|
6
|
-
? base
|
|
7
|
-
: `${key}: ${base}`;
|
|
8
|
-
};
|
|
4
|
+
import ParseError from "#ParseError";
|
|
9
5
|
export default class ConstructorType extends GenericType {
|
|
10
6
|
#type;
|
|
11
7
|
constructor(t) {
|
|
12
8
|
super();
|
|
13
9
|
this.#type = t;
|
|
14
10
|
}
|
|
15
|
-
default(value) {
|
|
16
|
-
return new DefaultType(this, value);
|
|
17
|
-
}
|
|
18
11
|
get name() {
|
|
19
12
|
return "constructor";
|
|
20
13
|
}
|
|
21
|
-
|
|
14
|
+
default(value) {
|
|
15
|
+
return new DefaultType(this, value);
|
|
16
|
+
}
|
|
17
|
+
parse(x, options = {}) {
|
|
22
18
|
if (!(x instanceof this.#type)) {
|
|
23
|
-
throw new
|
|
19
|
+
throw new ParseError(error(this.name, x, options));
|
|
24
20
|
}
|
|
25
21
|
return x;
|
|
26
22
|
}
|
|
23
|
+
toJSON() {
|
|
24
|
+
return {
|
|
25
|
+
type: "newable",
|
|
26
|
+
of: this.#type.name,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
27
29
|
}
|
|
28
30
|
//# sourceMappingURL=ConstructorType.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
type DataType = {
|
|
2
|
+
blob: Blob;
|
|
3
|
+
boolean: boolean;
|
|
4
|
+
datetime: Date;
|
|
5
|
+
f32: number;
|
|
6
|
+
f64: number;
|
|
7
|
+
i128: bigint;
|
|
8
|
+
i16: number;
|
|
9
|
+
i32: number;
|
|
10
|
+
i64: bigint;
|
|
11
|
+
i8: number;
|
|
12
|
+
primary: string;
|
|
13
|
+
string: string;
|
|
14
|
+
time: string;
|
|
15
|
+
u128: bigint;
|
|
16
|
+
u16: number;
|
|
17
|
+
u32: number;
|
|
18
|
+
u64: bigint;
|
|
19
|
+
u8: number;
|
|
20
|
+
url: URL;
|
|
21
|
+
};
|
|
22
|
+
export type { DataType as default };
|
|
23
|
+
//# sourceMappingURL=DataType.d.ts.map
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import BuiltinType from "#BuiltinType";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import coerce from "#coerce/date";
|
|
3
|
+
import CoerceKey from "#CoerceKey";
|
|
4
|
+
import Storeable from "#Storeable";
|
|
5
|
+
export default class DateType extends BuiltinType<Date, "DateType"> implements Storeable<"datetime"> {
|
|
6
|
+
[CoerceKey]: typeof coerce;
|
|
7
|
+
get Type(): DateConstructor;
|
|
8
|
+
get name(): "date";
|
|
9
|
+
get datatype(): "datetime";
|
|
10
|
+
toJSON(): {
|
|
11
|
+
type: "date";
|
|
12
|
+
datatype: "datetime";
|
|
13
|
+
};
|
|
4
14
|
}
|
|
5
15
|
//# sourceMappingURL=DateType.d.ts.map
|
package/lib/private/DateType.js
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import BuiltinType from "#BuiltinType";
|
|
2
|
+
import coerce from "#coerce/date";
|
|
3
|
+
import CoerceKey from "#CoerceKey";
|
|
4
|
+
import Storeable from "#Storeable";
|
|
2
5
|
export default class DateType extends BuiltinType {
|
|
3
|
-
|
|
4
|
-
|
|
6
|
+
[CoerceKey] = coerce;
|
|
7
|
+
get Type() {
|
|
8
|
+
return Date;
|
|
9
|
+
}
|
|
10
|
+
get name() {
|
|
11
|
+
return "date";
|
|
12
|
+
}
|
|
13
|
+
get datatype() {
|
|
14
|
+
return "datetime";
|
|
15
|
+
}
|
|
16
|
+
toJSON() {
|
|
17
|
+
return Storeable.serialize(this);
|
|
5
18
|
}
|
|
6
19
|
}
|
|
7
20
|
//# sourceMappingURL=DateType.js.map
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import GenericType from "#GenericType";
|
|
2
1
|
import type Infer from "#Infer";
|
|
3
|
-
import type
|
|
4
|
-
|
|
2
|
+
import type Parsed from "#Parsed";
|
|
3
|
+
import type ParseOptions from "#ParseOptions";
|
|
4
|
+
import VirtualType from "#VirtualType";
|
|
5
|
+
export default class DefaultType<S extends Parsed<unknown>, D extends Infer<S>> extends VirtualType<S, Infer<S>, "DefaultType"> {
|
|
5
6
|
#private;
|
|
6
|
-
constructor(s: S, d:
|
|
7
|
-
get name():
|
|
8
|
-
|
|
7
|
+
constructor(s: S, d: (() => D) | D);
|
|
8
|
+
get name(): "default";
|
|
9
|
+
get schema(): S;
|
|
10
|
+
get input(): Infer<S> | undefined;
|
|
11
|
+
parse(x: unknown, options?: ParseOptions): Infer<this>;
|
|
12
|
+
toJSON(): {
|
|
13
|
+
type: "default";
|
|
14
|
+
of: import("./Serialized.js").default;
|
|
15
|
+
};
|
|
9
16
|
}
|
|
10
17
|
//# sourceMappingURL=DefaultType.d.ts.map
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import VirtualType from "#VirtualType";
|
|
2
|
+
function isDefaultFunction(x) {
|
|
3
3
|
return typeof x === "function";
|
|
4
|
-
}
|
|
5
|
-
|
|
4
|
+
}
|
|
5
|
+
;
|
|
6
|
+
export default class DefaultType extends VirtualType {
|
|
6
7
|
#schema;
|
|
7
8
|
#default;
|
|
8
9
|
constructor(s, d) {
|
|
@@ -13,15 +14,22 @@ export default class DefaultType extends GenericType {
|
|
|
13
14
|
get name() {
|
|
14
15
|
return "default";
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
+
get schema() {
|
|
18
|
+
return this.#schema;
|
|
19
|
+
}
|
|
20
|
+
get input() {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
parse(x, options = {}) {
|
|
24
|
+
let $x = x;
|
|
17
25
|
// default fallback
|
|
18
|
-
if (x === undefined) {
|
|
19
|
-
|
|
20
|
-
return this.#default();
|
|
21
|
-
}
|
|
22
|
-
return this.#default;
|
|
26
|
+
if ($x === undefined) {
|
|
27
|
+
$x = isDefaultFunction(this.#default) ? this.#default() : this.#default;
|
|
23
28
|
}
|
|
24
|
-
return this.#schema.
|
|
29
|
+
return this.#schema.parse($x, options);
|
|
30
|
+
}
|
|
31
|
+
toJSON() {
|
|
32
|
+
return { type: this.name, of: this.#schema.toJSON() };
|
|
25
33
|
}
|
|
26
34
|
}
|
|
27
35
|
//# sourceMappingURL=DefaultType.js.map
|