pema 0.1.0 → 0.2.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/LICENSE +19 -0
- package/lib/private/ArrayType.d.ts +31 -5
- package/lib/private/ArrayType.js +86 -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
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type Infer from "#Infer";
|
|
2
|
+
import type Parsed from "#Parsed";
|
|
3
|
+
import type StoreSchema from "#StoreSchema";
|
|
4
|
+
type StoreId<T extends StoreSchema> = T["id"] extends Parsed<unknown> ? NonNullable<Infer<T["id"]>> : never;
|
|
5
|
+
export type { StoreId as default };
|
|
6
|
+
//# sourceMappingURL=StoreId.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import GenericType from "#GenericType";
|
|
2
|
+
import type Infer from "#Infer";
|
|
3
|
+
import type InferStore from "#InferStore";
|
|
4
|
+
import type ParseOptions from "#ParseOptions";
|
|
5
|
+
import PartialType from "#PartialType";
|
|
6
|
+
import type Serialized from "#Serialized";
|
|
7
|
+
import type StoreSchema from "#StoreSchema";
|
|
8
|
+
import type Dict from "@rcompat/type/Dict";
|
|
9
|
+
export default class StoreType<T extends StoreSchema> extends GenericType<T, InferStore<T>, "StoreType"> {
|
|
10
|
+
#private;
|
|
11
|
+
constructor(spec: T);
|
|
12
|
+
get name(): string;
|
|
13
|
+
get schema(): T;
|
|
14
|
+
partial(): PartialType<T>;
|
|
15
|
+
parse(x: unknown, options?: ParseOptions): Infer<this>;
|
|
16
|
+
toJSON(): {
|
|
17
|
+
type: "object";
|
|
18
|
+
properties: Dict<Serialized>;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=StoreType.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import GenericType from "#GenericType";
|
|
2
|
+
import ParsedKey from "#ParsedKey";
|
|
3
|
+
import PartialType from "#PartialType";
|
|
4
|
+
import join from "#path/join";
|
|
5
|
+
export default class StoreType extends GenericType {
|
|
6
|
+
#properties;
|
|
7
|
+
constructor(spec) {
|
|
8
|
+
super();
|
|
9
|
+
this.#properties = spec;
|
|
10
|
+
}
|
|
11
|
+
get name() {
|
|
12
|
+
return "store";
|
|
13
|
+
}
|
|
14
|
+
get schema() {
|
|
15
|
+
return this.#properties;
|
|
16
|
+
}
|
|
17
|
+
partial() {
|
|
18
|
+
return new PartialType(this.#properties);
|
|
19
|
+
}
|
|
20
|
+
parse(x, options = {}) {
|
|
21
|
+
const spec = this.#properties;
|
|
22
|
+
if (typeof x !== "object" || x === null) {
|
|
23
|
+
throw new Error("Expected object");
|
|
24
|
+
}
|
|
25
|
+
const result = {};
|
|
26
|
+
for (const k in spec) {
|
|
27
|
+
const r = spec[k].parse(x[k], {
|
|
28
|
+
...options, [ParsedKey]: join(options[ParsedKey] ?? "", String(k)),
|
|
29
|
+
});
|
|
30
|
+
// exclude undefined (optionals)
|
|
31
|
+
if (r !== undefined) {
|
|
32
|
+
result[k] = r;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return x;
|
|
36
|
+
}
|
|
37
|
+
toJSON() {
|
|
38
|
+
const properties = {};
|
|
39
|
+
for (const [k, v] of Object.entries(this.#properties)) {
|
|
40
|
+
properties[k] = v.toJSON();
|
|
41
|
+
}
|
|
42
|
+
return { type: "object", properties };
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=StoreType.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type K from "#DataKey";
|
|
2
|
+
import Parsed from "#Parsed";
|
|
3
|
+
import type Serialized from "#Serialized";
|
|
4
|
+
export default abstract class Storeable<T extends K = K> extends Parsed<unknown> {
|
|
5
|
+
abstract get datatype(): T;
|
|
6
|
+
abstract toJSON(): Serialized;
|
|
7
|
+
static serialize<N extends string, T extends K>(s: {
|
|
8
|
+
name: N;
|
|
9
|
+
datatype: T;
|
|
10
|
+
}): {
|
|
11
|
+
type: N;
|
|
12
|
+
datatype: T;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=Storeable.d.ts.map
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import PrimitiveType from "#PrimitiveType";
|
|
2
|
-
import
|
|
3
|
-
export default class StringType extends PrimitiveType<string, "StringType"> {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import Storeable from "#Storeable";
|
|
3
|
+
export default class StringType extends PrimitiveType<string, "StringType"> implements Storeable<"string"> {
|
|
4
|
+
get name(): "string";
|
|
5
|
+
get datatype(): "string";
|
|
6
|
+
isotime(): this;
|
|
7
|
+
regex(pattern: RegExp): this;
|
|
8
|
+
email(): this;
|
|
9
|
+
uuid(): this;
|
|
10
|
+
startsWith(prefix: string): this;
|
|
11
|
+
endsWith(suffix: string): this;
|
|
12
|
+
min(limit: number): this;
|
|
13
|
+
max(limit: number): this;
|
|
14
|
+
length(from: number, to: number): this;
|
|
15
|
+
toJSON(): {
|
|
16
|
+
type: "string";
|
|
17
|
+
datatype: "string";
|
|
18
|
+
};
|
|
7
19
|
}
|
|
8
20
|
//# sourceMappingURL=StringType.d.ts.map
|
|
@@ -1,23 +1,57 @@
|
|
|
1
|
+
import schemafail from "#error/schemafail";
|
|
1
2
|
import PrimitiveType from "#PrimitiveType";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import Storeable from "#Storeable";
|
|
4
|
+
import email from "#validator/email";
|
|
5
|
+
import ends_with from "#validator/ends-with";
|
|
6
|
+
import isotime from "#validator/isotime";
|
|
7
|
+
import length from "#validator/length";
|
|
8
|
+
import max from "#validator/max";
|
|
9
|
+
import min from "#validator/min";
|
|
10
|
+
import regex from "#validator/regex";
|
|
11
|
+
import starts_with from "#validator/starts-with";
|
|
12
|
+
import uuid from "#validator/uuid";
|
|
13
|
+
export default class StringType extends PrimitiveType {
|
|
14
|
+
get name() {
|
|
15
|
+
return "string";
|
|
5
16
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (!x.endsWith(suffix)) {
|
|
9
|
-
throw new Error(`"${x}" does not end with "${suffix}"`);
|
|
17
|
+
get datatype() {
|
|
18
|
+
return "string";
|
|
10
19
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
20
|
+
isotime() {
|
|
21
|
+
return this.derive({ validators: [isotime] });
|
|
22
|
+
}
|
|
23
|
+
regex(pattern) {
|
|
24
|
+
return this.derive({ validators: [regex(pattern)] });
|
|
25
|
+
}
|
|
26
|
+
email() {
|
|
27
|
+
return this.derive({ validators: [email] });
|
|
28
|
+
}
|
|
29
|
+
uuid() {
|
|
30
|
+
return this.derive({ validators: [uuid] });
|
|
15
31
|
}
|
|
16
32
|
startsWith(prefix) {
|
|
17
|
-
return
|
|
33
|
+
return this.derive({ validators: [starts_with(prefix)] });
|
|
18
34
|
}
|
|
19
35
|
endsWith(suffix) {
|
|
20
|
-
return
|
|
36
|
+
return this.derive({ validators: [ends_with(suffix)] });
|
|
37
|
+
}
|
|
38
|
+
min(limit) {
|
|
39
|
+
if (limit < 0) {
|
|
40
|
+
throw schemafail("min: {0} must be positive", limit);
|
|
41
|
+
}
|
|
42
|
+
return this.derive({ validators: [min(limit)] });
|
|
43
|
+
}
|
|
44
|
+
max(limit) {
|
|
45
|
+
if (limit < 0) {
|
|
46
|
+
throw schemafail("max: {0} must be positive", limit);
|
|
47
|
+
}
|
|
48
|
+
return this.derive({ validators: [max(limit)] });
|
|
49
|
+
}
|
|
50
|
+
length(from, to) {
|
|
51
|
+
return this.derive({ validators: [length(from, to)] });
|
|
52
|
+
}
|
|
53
|
+
toJSON() {
|
|
54
|
+
return Storeable.serialize(this);
|
|
21
55
|
}
|
|
22
56
|
}
|
|
23
57
|
//# sourceMappingURL=StringType.js.map
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import PrimitiveType from "#PrimitiveType";
|
|
2
2
|
export default class SymbolType extends PrimitiveType {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
get name() {
|
|
4
|
+
return "symbol";
|
|
5
|
+
}
|
|
6
|
+
toJSON() {
|
|
7
|
+
return { type: this.name };
|
|
5
8
|
}
|
|
6
9
|
}
|
|
7
10
|
//# sourceMappingURL=SymbolType.js.map
|
|
@@ -2,16 +2,23 @@ import GenericType from "#GenericType";
|
|
|
2
2
|
import type Infer from "#Infer";
|
|
3
3
|
import type InferSchema from "#InferSchema";
|
|
4
4
|
import OptionalType from "#OptionalType";
|
|
5
|
+
import type Parsed from "#Parsed";
|
|
6
|
+
import type ParseOptions from "#ParseOptions";
|
|
5
7
|
import type Schema from "#Schema";
|
|
8
|
+
import type OptionalTrait from "#trait/Optional";
|
|
6
9
|
type InferTuple<T extends Schema[]> = {
|
|
7
10
|
[K in keyof T]: T[K] extends Schema ? InferSchema<T[K]> : "tuple-never";
|
|
8
11
|
};
|
|
9
|
-
export default class TupleType<T extends
|
|
12
|
+
export default class TupleType<T extends Parsed<unknown>[]> extends GenericType<T, InferTuple<T>, "TupleType"> implements OptionalTrait {
|
|
10
13
|
#private;
|
|
11
|
-
constructor(
|
|
14
|
+
constructor(items: T);
|
|
15
|
+
get name(): "tuple";
|
|
12
16
|
optional(): OptionalType<this>;
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
parse(x: unknown, options?: ParseOptions): Infer<this>;
|
|
18
|
+
toJSON(): {
|
|
19
|
+
type: "tuple";
|
|
20
|
+
of: import("./Serialized.js").default[];
|
|
21
|
+
};
|
|
15
22
|
}
|
|
16
23
|
export {};
|
|
17
24
|
//# sourceMappingURL=TupleType.d.ts.map
|
package/lib/private/TupleType.js
CHANGED
|
@@ -1,40 +1,34 @@
|
|
|
1
1
|
import error from "#error";
|
|
2
|
-
import expected from "#expected";
|
|
3
2
|
import GenericType from "#GenericType";
|
|
4
|
-
import schema from "#index";
|
|
5
|
-
import is_validated_type from "#is_validated_type";
|
|
6
3
|
import OptionalType from "#OptionalType";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
? `[${i}]`
|
|
10
|
-
: `${key}[${i}]`;
|
|
11
|
-
};
|
|
4
|
+
import ParseError from "#ParseError";
|
|
5
|
+
import next from "#path/next";
|
|
12
6
|
export default class TupleType extends GenericType {
|
|
13
|
-
#
|
|
14
|
-
constructor(
|
|
7
|
+
#items;
|
|
8
|
+
constructor(items) {
|
|
15
9
|
super();
|
|
16
|
-
this.#
|
|
17
|
-
}
|
|
18
|
-
optional() {
|
|
19
|
-
return new OptionalType(this);
|
|
10
|
+
this.#items = items;
|
|
20
11
|
}
|
|
21
12
|
get name() {
|
|
22
13
|
return "tuple";
|
|
23
14
|
}
|
|
24
|
-
|
|
15
|
+
optional() {
|
|
16
|
+
return new OptionalType(this);
|
|
17
|
+
}
|
|
18
|
+
parse(x, options = {}) {
|
|
25
19
|
if (!(!!x && Array.isArray(x))) {
|
|
26
|
-
throw new
|
|
20
|
+
throw new ParseError(error("array", x, options));
|
|
27
21
|
}
|
|
28
|
-
this.#
|
|
29
|
-
|
|
30
|
-
validator.validate(x[i], `${member_error(i, key)}`);
|
|
22
|
+
this.#items.forEach((v, i) => {
|
|
23
|
+
v.parse(x[i], next(i, options));
|
|
31
24
|
});
|
|
32
25
|
x.forEach((v, i) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
26
|
+
if (i >= this.#items.length) {
|
|
27
|
+
throw new ParseError(error("undefined", v, next(i, options)));
|
|
28
|
+
}
|
|
36
29
|
});
|
|
37
30
|
return x;
|
|
38
31
|
}
|
|
32
|
+
toJSON() { return { type: this.name, of: this.#items.map(i => i.toJSON()) }; }
|
|
39
33
|
}
|
|
40
34
|
//# sourceMappingURL=TupleType.js.map
|
package/lib/private/Type.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import DefaultType from "#DefaultType";
|
|
2
2
|
import OptionalType from "#OptionalType";
|
|
3
|
-
import
|
|
3
|
+
import Parsed from "#Parsed";
|
|
4
|
+
import type DefaultTrait from "#trait/Default";
|
|
5
|
+
import type OptionalTrait from "#trait/Optional";
|
|
4
6
|
import type Printable from "@rcompat/type/Printable";
|
|
5
|
-
export default abstract class Type<
|
|
7
|
+
export default abstract class Type<T, Name extends string> extends Parsed<T> implements Printable, DefaultTrait<T>, OptionalTrait {
|
|
6
8
|
optional(): OptionalType<this>;
|
|
7
|
-
default<
|
|
9
|
+
default<S extends T>(value: (() => S) | S): DefaultType<this, S>;
|
|
8
10
|
get Name(): Name;
|
|
9
11
|
}
|
|
10
12
|
//# sourceMappingURL=Type.d.ts.map
|
package/lib/private/Type.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import DefaultType from "#DefaultType";
|
|
2
2
|
import OptionalType from "#OptionalType";
|
|
3
|
-
import
|
|
4
|
-
export default class Type extends
|
|
3
|
+
import Parsed from "#Parsed";
|
|
4
|
+
export default class Type extends Parsed {
|
|
5
5
|
optional() {
|
|
6
6
|
return new OptionalType(this);
|
|
7
7
|
}
|
package/lib/private/URLType.d.ts
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import BuiltinType from "#BuiltinType";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import Storeable from "#Storeable";
|
|
3
|
+
export default class URLType extends BuiltinType<URL, "URLType"> implements Storeable<"url"> {
|
|
4
|
+
get Type(): {
|
|
5
|
+
new (url: string | URL, base?: string | URL): URL;
|
|
6
|
+
prototype: URL;
|
|
7
|
+
canParse(url: string | URL, base?: string | URL): boolean;
|
|
8
|
+
createObjectURL(obj: Blob | MediaSource): string;
|
|
9
|
+
parse(url: string | URL, base?: string | URL): URL | null;
|
|
10
|
+
revokeObjectURL(url: string): void;
|
|
11
|
+
};
|
|
12
|
+
get name(): "url";
|
|
13
|
+
get datatype(): "url";
|
|
14
|
+
toJSON(): {
|
|
15
|
+
type: "url";
|
|
16
|
+
datatype: "url";
|
|
17
|
+
};
|
|
4
18
|
}
|
|
5
19
|
//# sourceMappingURL=URLType.d.ts.map
|
package/lib/private/URLType.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import BuiltinType from "#BuiltinType";
|
|
2
|
+
import Storeable from "#Storeable";
|
|
2
3
|
export default class URLType extends BuiltinType {
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
get Type() {
|
|
5
|
+
return URL;
|
|
6
|
+
}
|
|
7
|
+
get name() {
|
|
8
|
+
return "url";
|
|
9
|
+
}
|
|
10
|
+
get datatype() {
|
|
11
|
+
return "url";
|
|
12
|
+
}
|
|
13
|
+
toJSON() {
|
|
14
|
+
return Storeable.serialize(this);
|
|
5
15
|
}
|
|
6
16
|
}
|
|
7
17
|
//# sourceMappingURL=URLType.js.map
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import coerce from "#coerce/int";
|
|
2
|
+
import CoerceKey from "#CoerceKey";
|
|
3
|
+
import NumericType from "#NumericType";
|
|
4
|
+
import type ParseOptions from "#ParseOptions";
|
|
5
|
+
import type Storeable from "#Storeable";
|
|
6
|
+
import type UintDataType from "#UintDataType";
|
|
7
|
+
export default class UintType<T extends UintDataType> extends NumericType<T, number, "UintType"> implements Storeable<T> {
|
|
8
|
+
[CoerceKey]: typeof coerce;
|
|
9
|
+
get name(): string;
|
|
10
|
+
/**
|
|
11
|
+
* Value is a non-privileged port number (1000 - 65535).
|
|
12
|
+
*/
|
|
13
|
+
port(): this;
|
|
14
|
+
parse(x: unknown, options?: ParseOptions<number>): import("./Infer.js").default<this>;
|
|
7
15
|
}
|
|
8
|
-
export {};
|
|
9
16
|
//# sourceMappingURL=UintType.d.ts.map
|
package/lib/private/UintType.js
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import coerce from "#coerce/int";
|
|
2
|
+
import CoerceKey from "#CoerceKey";
|
|
3
|
+
import NumericType from "#NumericType";
|
|
4
|
+
import integer from "#validator/integer";
|
|
5
|
+
import port from "#validator/port";
|
|
6
|
+
export default class UintType extends NumericType {
|
|
7
|
+
[CoerceKey] = coerce;
|
|
8
|
+
get name() {
|
|
9
|
+
return "number";
|
|
8
10
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return
|
|
11
|
+
/**
|
|
12
|
+
* Value is a non-privileged port number (1000 - 65535).
|
|
13
|
+
*/
|
|
14
|
+
port() {
|
|
15
|
+
return this.derive({ validators: [port] });
|
|
16
|
+
}
|
|
17
|
+
parse(x, options = {}) {
|
|
18
|
+
return super.parse(x, {
|
|
19
|
+
...options,
|
|
20
|
+
validators: [integer],
|
|
21
|
+
});
|
|
14
22
|
}
|
|
15
23
|
}
|
|
16
24
|
//# sourceMappingURL=UintType.js.map
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import PrimitiveType from "#PrimitiveType";
|
|
2
2
|
type Name = "UndefinedType";
|
|
3
3
|
export default class UndefinedType extends PrimitiveType<undefined, Name> {
|
|
4
|
-
|
|
4
|
+
get name(): "undefined";
|
|
5
|
+
toJSON(): {
|
|
6
|
+
type: "undefined";
|
|
7
|
+
};
|
|
5
8
|
}
|
|
6
9
|
export {};
|
|
7
10
|
//# sourceMappingURL=UndefinedType.d.ts.map
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import PrimitiveType from "#PrimitiveType";
|
|
2
2
|
export default class UndefinedType extends PrimitiveType {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
get name() {
|
|
4
|
+
return "undefined";
|
|
5
|
+
}
|
|
6
|
+
toJSON() {
|
|
7
|
+
return {
|
|
8
|
+
type: this.name,
|
|
9
|
+
};
|
|
5
10
|
}
|
|
6
11
|
}
|
|
7
12
|
//# sourceMappingURL=UndefinedType.js.map
|
|
@@ -1,18 +1,29 @@
|
|
|
1
|
+
import DefaultType from "#DefaultType";
|
|
1
2
|
import GenericType from "#GenericType";
|
|
2
3
|
import type Infer from "#Infer";
|
|
3
4
|
import type InferSchema from "#InferSchema";
|
|
4
5
|
import OptionalType from "#OptionalType";
|
|
6
|
+
import type Parsed from "#Parsed";
|
|
7
|
+
import type ParseOptions from "#ParseOptions";
|
|
5
8
|
import type Schema from "#Schema";
|
|
9
|
+
import type DefaultTrait from "#trait/Default";
|
|
10
|
+
import type OptionalTrait from "#trait/Optional";
|
|
6
11
|
import type TupleToUnion from "@rcompat/type/TupleToUnion";
|
|
7
12
|
type InferUnion<T extends Schema[]> = TupleToUnion<{
|
|
8
13
|
[K in keyof T]: T[K] extends Schema ? InferSchema<T[K]> : "union-never";
|
|
9
14
|
}>;
|
|
10
|
-
export default class UnionType<T extends
|
|
15
|
+
export default class UnionType<T extends Parsed<unknown>[]> extends GenericType<T, InferUnion<T>, "UnionType"> implements OptionalTrait, DefaultTrait<InferUnion<T>> {
|
|
11
16
|
#private;
|
|
12
|
-
constructor(
|
|
17
|
+
constructor(of: T);
|
|
18
|
+
get name(): "union";
|
|
19
|
+
get schema(): T;
|
|
13
20
|
optional(): OptionalType<this>;
|
|
14
|
-
|
|
15
|
-
|
|
21
|
+
default(value: (() => InferUnion<T>) | InferUnion<T>): DefaultType<this, InferUnion<T>>;
|
|
22
|
+
parse(x: unknown, options?: ParseOptions): Infer<this>;
|
|
23
|
+
toJSON(): {
|
|
24
|
+
type: "union";
|
|
25
|
+
of: import("./Serialized.js").default[];
|
|
26
|
+
};
|
|
16
27
|
}
|
|
17
28
|
export {};
|
|
18
29
|
//# sourceMappingURL=UnionType.d.ts.map
|
package/lib/private/UnionType.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import DefaultType from "#DefaultType";
|
|
2
|
+
import error from "#error";
|
|
2
3
|
import GenericType from "#GenericType";
|
|
3
4
|
import schema from "#index";
|
|
4
|
-
import
|
|
5
|
+
import isParsedType from "#is-parsed-type";
|
|
5
6
|
import OptionalType from "#OptionalType";
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
return key === undefined
|
|
9
|
-
? message
|
|
10
|
-
: `${key}: ${message}`;
|
|
11
|
-
};
|
|
7
|
+
import ParseError from "#ParseError";
|
|
8
|
+
import assert from "@rcompat/assert";
|
|
12
9
|
const print = (type) => {
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
10
|
+
const parsed = isParsedType(type);
|
|
11
|
+
if (parsed) {
|
|
15
12
|
return type.name;
|
|
16
13
|
}
|
|
17
14
|
const type_of = typeof type;
|
|
@@ -28,36 +25,45 @@ const print = (type) => {
|
|
|
28
25
|
}
|
|
29
26
|
return type;
|
|
30
27
|
};
|
|
31
|
-
const
|
|
28
|
+
const union_error = (types) => `\`${types.map(t => isParsedType(t) ? t.name : print(t)).join(" | ")}\``;
|
|
32
29
|
export default class UnionType extends GenericType {
|
|
33
|
-
#
|
|
34
|
-
constructor(
|
|
35
|
-
assert(
|
|
30
|
+
#of;
|
|
31
|
+
constructor(of) {
|
|
32
|
+
assert(of.length > 1, "union type must have at least two members");
|
|
36
33
|
super();
|
|
37
|
-
this.#
|
|
34
|
+
this.#of = of;
|
|
35
|
+
}
|
|
36
|
+
get name() {
|
|
37
|
+
return "union";
|
|
38
|
+
}
|
|
39
|
+
get schema() {
|
|
40
|
+
return this.#of;
|
|
38
41
|
}
|
|
39
42
|
optional() {
|
|
40
43
|
return new OptionalType(this);
|
|
41
44
|
}
|
|
42
|
-
|
|
43
|
-
return
|
|
45
|
+
default(value) {
|
|
46
|
+
return new DefaultType(this, value);
|
|
44
47
|
}
|
|
45
|
-
|
|
46
|
-
// union
|
|
47
|
-
const
|
|
48
|
-
const validator =
|
|
48
|
+
parse(x, options = {}) {
|
|
49
|
+
// union parses when any of its members parses
|
|
50
|
+
const parsed = this.#of.map(type => {
|
|
51
|
+
const validator = isParsedType(type) ? type : schema(type);
|
|
49
52
|
try {
|
|
50
|
-
validator.
|
|
53
|
+
validator.parse(x, options);
|
|
51
54
|
return true;
|
|
52
55
|
}
|
|
53
|
-
catch {
|
|
54
|
-
return
|
|
56
|
+
catch (e) {
|
|
57
|
+
return e;
|
|
55
58
|
}
|
|
56
59
|
});
|
|
57
|
-
if (!
|
|
58
|
-
throw new
|
|
60
|
+
if (!parsed.some(r => r === true)) {
|
|
61
|
+
throw new ParseError(error(union_error(this.#of), x, options));
|
|
59
62
|
}
|
|
60
63
|
return x;
|
|
61
64
|
}
|
|
65
|
+
toJSON() {
|
|
66
|
+
return { type: this.name, of: this.#of.map(t => t.toJSON()) };
|
|
67
|
+
}
|
|
62
68
|
}
|
|
63
69
|
//# sourceMappingURL=UnionType.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import GenericType from "#GenericType";
|
|
2
|
+
export default abstract class VirtualType<Type, Inferred, Name extends string> extends GenericType<Type, Inferred, Name> {
|
|
3
|
+
abstract get schema(): Type;
|
|
4
|
+
get datatype(): keyof import("./DataType.js").default;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=VirtualType.d.ts.map
|