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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import OptionalType from "#OptionalType";
|
|
2
|
-
import type
|
|
3
|
-
declare const _default: <const T extends
|
|
2
|
+
import type Parsed from "#Parsed";
|
|
3
|
+
declare const _default: <const T extends Parsed<unknown>>(type: T) => OptionalType<T>;
|
|
4
4
|
export default _default;
|
|
5
5
|
//# sourceMappingURL=optional.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import ObjectType from "#ObjectType";
|
|
2
|
+
import type Partialable from "#Partialable";
|
|
3
|
+
import PartialType from "#PartialType";
|
|
4
|
+
type StripReadonly<T> = {
|
|
5
|
+
-readonly [K in keyof T]: T[K];
|
|
6
|
+
};
|
|
7
|
+
export default function partial<const D extends Partialable>(input: D | ObjectType<D>): PartialType<StripReadonly<D>>;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=partial.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// partial.ts
|
|
2
|
+
import ObjectType from "#ObjectType";
|
|
3
|
+
import PartialType from "#PartialType";
|
|
4
|
+
export default function partial(input) {
|
|
5
|
+
const dict = input instanceof ObjectType ? input.properties : input;
|
|
6
|
+
return new PartialType(dict);
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=partial.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// RFC 6901 escaping
|
|
2
|
+
function escapeToken(token) {
|
|
3
|
+
return token.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
4
|
+
}
|
|
5
|
+
export default function join(base, ...tokens) {
|
|
6
|
+
if (tokens.length === 0)
|
|
7
|
+
return base;
|
|
8
|
+
const tail = tokens.map(t => escapeToken(String(t))).join("/");
|
|
9
|
+
if (base === "")
|
|
10
|
+
return ("/" + tail);
|
|
11
|
+
return (base + "/" + tail);
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=join.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import ParsedKey from "#ParsedKey";
|
|
2
|
+
import type ParseOptions from "#ParseOptions";
|
|
3
|
+
export default function next(s: number | string, options?: ParseOptions): {
|
|
4
|
+
[ParsedKey]: import("@rcompat/type/JSONPointer").default;
|
|
5
|
+
coerce?: boolean;
|
|
6
|
+
partial?: boolean;
|
|
7
|
+
validators?: import("../Validator.js").default<unknown>[] | undefined;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=next.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import ParsedKey from "#ParsedKey";
|
|
2
|
+
import join from "#path/join";
|
|
3
|
+
export default function next(s, options) {
|
|
4
|
+
const base = options?.[ParsedKey] ?? "";
|
|
5
|
+
return options === undefined
|
|
6
|
+
? { [ParsedKey]: join("", String(s)) }
|
|
7
|
+
: { ...options, [ParsedKey]: join(base, String(s)) };
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=next.js.map
|
package/lib/private/record.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import type Parsed from "#Parsed";
|
|
1
2
|
import RecordType from "#RecordType";
|
|
2
3
|
import type RecordTypeKey from "#RecordTypeKey";
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Value is a record of the given key and value types.
|
|
6
|
+
*/
|
|
7
|
+
declare const _default: <const Key extends RecordTypeKey, const Value extends Parsed<unknown>>(k: Key, v: Value) => RecordType<Key, Value>;
|
|
5
8
|
export default _default;
|
|
6
9
|
//# sourceMappingURL=record.d.ts.map
|
package/lib/private/record.js
CHANGED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import expect from "#expect";
|
|
2
|
+
import test from "@rcompat/test";
|
|
3
|
+
export default (i, min, max) => {
|
|
4
|
+
test.case("fail", assert => {
|
|
5
|
+
assert(() => i.parse("1")).throws(expect("bi", "1"));
|
|
6
|
+
assert(() => i.parse(1.1)).throws(expect("bi", 1.1));
|
|
7
|
+
assert(() => i.parse(-1.1)).throws(expect("bi", -1.1));
|
|
8
|
+
assert(() => i.parse(0)).throws(expect("bi", 0));
|
|
9
|
+
assert(() => i.parse(1)).throws(expect("bi", 1));
|
|
10
|
+
});
|
|
11
|
+
test.case("pass", assert => {
|
|
12
|
+
assert(i).type();
|
|
13
|
+
assert(i.parse(0n)).equals(0n).type();
|
|
14
|
+
assert(i.parse(1n)).equals(1n).type();
|
|
15
|
+
});
|
|
16
|
+
test.case("range", assert => {
|
|
17
|
+
assert(i.parse(min)).equals(min).type();
|
|
18
|
+
assert(i.parse(max)).equals(max).type();
|
|
19
|
+
assert(() => i.parse(min - 1n)).throws(`${min - 1n} is out of range`);
|
|
20
|
+
assert(() => i.parse(max + 1n)).throws(`${max + 1n} is out of range`);
|
|
21
|
+
});
|
|
22
|
+
test.case("coerced", assert => {
|
|
23
|
+
const coerced = i.coerce;
|
|
24
|
+
assert(coerced.parse(0n)).equals(0n).type();
|
|
25
|
+
assert(coerced.parse(1n)).equals(1n).type();
|
|
26
|
+
assert(coerced.parse(0)).equals(0n).type();
|
|
27
|
+
assert(coerced.parse(1)).equals(1n).type();
|
|
28
|
+
assert(coerced.parse("1")).equals(1n).type();
|
|
29
|
+
assert(coerced.parse("1.0")).equals(1n).type();
|
|
30
|
+
assert(coerced.parse("1.")).equals(1n).type();
|
|
31
|
+
assert(() => coerced.parse("0.1")).throws(expect("bi", "0.1"));
|
|
32
|
+
assert(() => coerced.parse(".1")).throws(expect("bi", ".1"));
|
|
33
|
+
assert(coerced.parse(-1)).equals(-1n).type();
|
|
34
|
+
assert(coerced.parse("-1")).equals(-1n).type();
|
|
35
|
+
assert(coerced.parse("-1.0")).equals(-1n).type();
|
|
36
|
+
assert(coerced.parse("-1.")).equals(-1n).type();
|
|
37
|
+
assert(() => coerced.parse("-0.1")).throws(expect("bi", "-0.1"));
|
|
38
|
+
assert(() => coerced.parse("-.1")).throws(expect("bi", "-.1"));
|
|
39
|
+
});
|
|
40
|
+
test.case("default", assert => {
|
|
41
|
+
[i.default(1n), i.default(() => 1n)].forEach(d => {
|
|
42
|
+
assert(d).type();
|
|
43
|
+
assert(d.parse(undefined)).equals(1n).type();
|
|
44
|
+
assert(d.parse(1n)).equals(1n).type();
|
|
45
|
+
assert(d.parse(0n)).equals(0n).type();
|
|
46
|
+
assert(() => d.parse(1.2)).throws(expect("bi", 1.2));
|
|
47
|
+
assert(() => d.parse(-1.2)).throws(expect("bi", -1.2));
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
test.case("validator - range", assert => {
|
|
51
|
+
const r = i.range(-10n, 10n);
|
|
52
|
+
assert(r.parse(-10n)).equals(-10n).type();
|
|
53
|
+
assert(r.parse(0n)).equals(0n).type();
|
|
54
|
+
assert(r.parse(10n)).equals(10n).type();
|
|
55
|
+
assert(() => r.parse(-11n)).throws("-11 is out of range");
|
|
56
|
+
assert(() => r.parse(11n)).throws("11 is out of range");
|
|
57
|
+
});
|
|
58
|
+
test.case("validator - min", assert => {
|
|
59
|
+
const r = i.min(-10n);
|
|
60
|
+
assert(r.parse(-10n)).equals(-10n).type();
|
|
61
|
+
assert(r.parse(0n)).equals(0n).type();
|
|
62
|
+
assert(r.parse(10n)).equals(10n).type();
|
|
63
|
+
assert(() => r.parse(-11n)).throws("-11 is lower than min (-10)");
|
|
64
|
+
});
|
|
65
|
+
test.case("validator - max", assert => {
|
|
66
|
+
const r = i.max(10n);
|
|
67
|
+
assert(r.parse(-10n)).equals(-10n).type();
|
|
68
|
+
assert(r.parse(0n)).equals(0n).type();
|
|
69
|
+
assert(r.parse(10n)).equals(10n).type();
|
|
70
|
+
assert(() => r.parse(11n)).throws("11 is greater than max (10)");
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=bigint.js.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type BigUintDataType from "#BigUintDataType";
|
|
2
|
+
import type BigUintType from "#BigUintType";
|
|
3
|
+
declare const _default: <T extends BigUintDataType>(i: BigUintType<T>, min: bigint, max: bigint) => void;
|
|
4
|
+
export default _default;
|
|
5
|
+
//# sourceMappingURL=biguint.d.ts.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import expect from "#expect";
|
|
2
|
+
import test from "@rcompat/test";
|
|
3
|
+
export default (i, min, max) => {
|
|
4
|
+
test.case("fail", assert => {
|
|
5
|
+
assert(() => i.parse("1")).throws(expect("bi", "1"));
|
|
6
|
+
assert(() => i.parse(1.1)).throws(expect("bi", 1.1));
|
|
7
|
+
assert(() => i.parse(-1.1)).throws(expect("bi", -1.1));
|
|
8
|
+
assert(() => i.parse(-1n)).throws("-1 is out of range");
|
|
9
|
+
assert(() => i.parse(0)).throws(expect("bi", 0));
|
|
10
|
+
assert(() => i.parse(1)).throws(expect("bi", 1));
|
|
11
|
+
});
|
|
12
|
+
test.case("pass", assert => {
|
|
13
|
+
assert(i).type();
|
|
14
|
+
assert(i.parse(0n)).equals(0n).type();
|
|
15
|
+
assert(i.parse(1n)).equals(1n).type();
|
|
16
|
+
});
|
|
17
|
+
test.case("range", assert => {
|
|
18
|
+
assert(i.parse(min)).equals(min).type();
|
|
19
|
+
assert(i.parse(max)).equals(max).type();
|
|
20
|
+
assert(() => i.parse(min - 1n)).throws(`${min - 1n} is out of range`);
|
|
21
|
+
assert(() => i.parse(max + 1n)).throws(`${max + 1n} is out of range`);
|
|
22
|
+
});
|
|
23
|
+
test.case("coerced", assert => {
|
|
24
|
+
const coerced = i.coerce;
|
|
25
|
+
assert(coerced.parse(0n)).equals(0n).type();
|
|
26
|
+
assert(coerced.parse(1n)).equals(1n).type();
|
|
27
|
+
assert(coerced.parse(0)).equals(0n).type();
|
|
28
|
+
assert(coerced.parse(1)).equals(1n).type();
|
|
29
|
+
assert(coerced.parse("1")).equals(1n).type();
|
|
30
|
+
assert(coerced.parse("1.0")).equals(1n).type();
|
|
31
|
+
assert(coerced.parse("1.")).equals(1n).type();
|
|
32
|
+
assert(() => coerced.parse("0.1")).throws(expect("bi", "0.1"));
|
|
33
|
+
assert(() => coerced.parse(".1")).throws(expect("bi", ".1"));
|
|
34
|
+
assert(() => coerced.parse(-1)).throws("-1 is out of range");
|
|
35
|
+
assert(() => coerced.parse("-1")).throws("-1 is out of range");
|
|
36
|
+
assert(() => coerced.parse("-1.0")).throws("-1 is out of range");
|
|
37
|
+
assert(() => coerced.parse("-1.")).throws("-1 is out of range");
|
|
38
|
+
assert(() => coerced.parse("-0.1")).throws(expect("bi", "-0.1"));
|
|
39
|
+
assert(() => coerced.parse("-.1")).throws(expect("bi", "-.1"));
|
|
40
|
+
});
|
|
41
|
+
test.case("default", assert => {
|
|
42
|
+
[i.default(1n), i.default(() => 1n)].forEach(d => {
|
|
43
|
+
assert(d).type();
|
|
44
|
+
assert(d.parse(undefined)).equals(1n).type();
|
|
45
|
+
assert(d.parse(1n)).equals(1n).type();
|
|
46
|
+
assert(d.parse(0n)).equals(0n).type();
|
|
47
|
+
assert(() => d.parse(1.2)).throws(expect("bi", 1.2));
|
|
48
|
+
assert(() => d.parse(-1.2)).throws(expect("bi", -1.2));
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
test.case("validator - range", assert => {
|
|
52
|
+
const r = i.range(0n, 10n);
|
|
53
|
+
assert(r.parse(0n)).equals(0n).type();
|
|
54
|
+
assert(r.parse(10n)).equals(10n).type();
|
|
55
|
+
assert(() => r.parse(-1n)).throws("-1 is out of range");
|
|
56
|
+
assert(() => r.parse(-11n)).throws("-11 is out of range");
|
|
57
|
+
assert(() => r.parse(11n)).throws("11 is out of range");
|
|
58
|
+
});
|
|
59
|
+
test.case("validator - min", assert => {
|
|
60
|
+
const r = i.min(0n);
|
|
61
|
+
assert(r.parse(0n)).equals(0n).type();
|
|
62
|
+
assert(r.parse(10n)).equals(10n).type();
|
|
63
|
+
assert(() => r.parse(-1n)).throws("-1 is out of range");
|
|
64
|
+
});
|
|
65
|
+
test.case("validator - max", assert => {
|
|
66
|
+
const r = i.max(10n);
|
|
67
|
+
assert(r.parse(0n)).equals(0n).type();
|
|
68
|
+
assert(r.parse(10n)).equals(10n).type();
|
|
69
|
+
assert(() => r.parse(-1n)).throws("-1 is out of range");
|
|
70
|
+
assert(() => r.parse(11n)).throws("11 is greater than max (10)");
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=biguint.js.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import expect from "#expect";
|
|
2
|
+
import test from "@rcompat/test";
|
|
3
|
+
export default (i, min, max) => {
|
|
4
|
+
test.case("fail", assert => {
|
|
5
|
+
assert(() => i.parse("1")).throws(expect("n", "1"));
|
|
6
|
+
assert(() => i.parse(1.1)).throws("1.1 is not an integer");
|
|
7
|
+
assert(() => i.parse(-1.1)).throws("-1.1 is not an integer");
|
|
8
|
+
assert(() => i.parse(0n)).throws(expect("n", 0n));
|
|
9
|
+
assert(() => i.parse(1n)).throws(expect("n", 1n));
|
|
10
|
+
});
|
|
11
|
+
test.case("pass", assert => {
|
|
12
|
+
assert(i).type();
|
|
13
|
+
assert(i.parse(0)).equals(0).type();
|
|
14
|
+
assert(i.parse(1)).equals(1).type();
|
|
15
|
+
});
|
|
16
|
+
test.case("range", assert => {
|
|
17
|
+
assert(i.parse(min)).equals(min).type();
|
|
18
|
+
assert(i.parse(max)).equals(max).type();
|
|
19
|
+
assert(() => i.parse(min - 1)).throws(`${min - 1} is out of range`);
|
|
20
|
+
assert(() => i.parse(max + 1)).throws(`${max + 1} is out of range`);
|
|
21
|
+
});
|
|
22
|
+
test.case("coerced", assert => {
|
|
23
|
+
const coerced = i.coerce;
|
|
24
|
+
assert(coerced.parse(0)).equals(0).type();
|
|
25
|
+
assert(coerced.parse(1)).equals(1).type();
|
|
26
|
+
assert(coerced.parse("1")).equals(1).type();
|
|
27
|
+
assert(coerced.parse("1.0")).equals(1).type();
|
|
28
|
+
assert(coerced.parse("1.")).equals(1).type();
|
|
29
|
+
assert(() => coerced.parse("0.1")).throws("0.1 is not an integer");
|
|
30
|
+
assert(() => coerced.parse(".1")).throws("0.1 is not an integer");
|
|
31
|
+
assert(coerced.parse("-1")).equals(-1).type();
|
|
32
|
+
assert(coerced.parse("-1.0")).equals(-1).type();
|
|
33
|
+
assert(coerced.parse("-1.")).equals(-1).type();
|
|
34
|
+
assert(() => coerced.parse("-0.1")).throws("-0.1 is not an integer");
|
|
35
|
+
assert(() => coerced.parse("-.1")).throws("-0.1 is not an integer");
|
|
36
|
+
});
|
|
37
|
+
test.case("default", assert => {
|
|
38
|
+
[i.default(1), i.default(() => 1)].forEach(d => {
|
|
39
|
+
assert(d).type();
|
|
40
|
+
assert(d.parse(undefined)).equals(1).type();
|
|
41
|
+
assert(d.parse(1)).equals(1).type();
|
|
42
|
+
assert(d.parse(0)).equals(0).type();
|
|
43
|
+
assert(() => d.parse(1.2)).throws("1.2 is not an integer");
|
|
44
|
+
assert(() => d.parse(-1.2)).throws("-1.2 is not an integer");
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
test.case("validator - range", assert => {
|
|
48
|
+
const r = i.range(-10, 10);
|
|
49
|
+
assert(r.parse(-10)).equals(-10).type();
|
|
50
|
+
assert(r.parse(0)).equals(0).type();
|
|
51
|
+
assert(r.parse(10)).equals(10).type();
|
|
52
|
+
assert(() => r.parse(-11)).throws("-11 is out of range");
|
|
53
|
+
assert(() => r.parse(11)).throws("11 is out of range");
|
|
54
|
+
});
|
|
55
|
+
test.case("validator - min", assert => {
|
|
56
|
+
const r = i.min(-10);
|
|
57
|
+
assert(r.parse(-10)).equals(-10).type();
|
|
58
|
+
assert(r.parse(0)).equals(0).type();
|
|
59
|
+
assert(r.parse(10)).equals(10).type();
|
|
60
|
+
assert(() => r.parse(-11)).throws("-11 is lower than min (-10)");
|
|
61
|
+
});
|
|
62
|
+
test.case("validator - max", assert => {
|
|
63
|
+
const r = i.max(10);
|
|
64
|
+
assert(r.parse(-10)).equals(-10).type();
|
|
65
|
+
assert(r.parse(0)).equals(0).type();
|
|
66
|
+
assert(r.parse(10)).equals(10).type();
|
|
67
|
+
assert(() => r.parse(11)).throws("11 is greater than max (10)");
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=int.js.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import expect from "#expect";
|
|
2
|
+
import test from "@rcompat/test";
|
|
3
|
+
export default (i, min, max) => {
|
|
4
|
+
test.case("fail", assert => {
|
|
5
|
+
assert(() => i.parse("1")).throws(expect("n", "1"));
|
|
6
|
+
assert(() => i.parse(1.1)).throws("1.1 is not an integer");
|
|
7
|
+
assert(() => i.parse(-1.1)).throws("-1.1 is not an integer");
|
|
8
|
+
assert(() => i.parse(-1)).throws("-1 is out of range");
|
|
9
|
+
assert(() => i.parse(1n)).throws(expect("n", 1n));
|
|
10
|
+
});
|
|
11
|
+
test.case("pass", assert => {
|
|
12
|
+
assert(i).type();
|
|
13
|
+
assert(i.parse(1)).equals(1).type();
|
|
14
|
+
});
|
|
15
|
+
test.case("range", assert => {
|
|
16
|
+
assert(i.parse(0)).equals(0).type();
|
|
17
|
+
assert(i.parse(min)).equals(min).type();
|
|
18
|
+
assert(i.parse(max)).equals(max).type();
|
|
19
|
+
assert(() => i.parse(min - 1)).throws(`${min - 1} is out of range`);
|
|
20
|
+
assert(() => i.parse(max + 1)).throws(`${max + 1} is out of range`);
|
|
21
|
+
});
|
|
22
|
+
test.case("coerced", assert => {
|
|
23
|
+
const coerced = i.coerce;
|
|
24
|
+
assert(coerced.parse(0)).equals(0).type();
|
|
25
|
+
assert(coerced.parse(1)).equals(1).type();
|
|
26
|
+
assert(coerced.parse("1")).equals(1).type();
|
|
27
|
+
assert(coerced.parse("1.0")).equals(1).type();
|
|
28
|
+
assert(coerced.parse("1.")).equals(1).type();
|
|
29
|
+
assert(() => coerced.parse("0.1")).throws("0.1 is not an integer");
|
|
30
|
+
assert(() => coerced.parse(".1")).throws("0.1 is not an integer");
|
|
31
|
+
assert(() => coerced.parse("-1")).throws("-1 is out of range");
|
|
32
|
+
assert(() => coerced.parse("-1.0")).throws("-1 is out of range");
|
|
33
|
+
assert(() => coerced.parse("-1.")).throws("-1 is out of range");
|
|
34
|
+
});
|
|
35
|
+
test.case("default", assert => {
|
|
36
|
+
[i.default(1), i.default(() => 1)].forEach(d => {
|
|
37
|
+
assert(d).type();
|
|
38
|
+
assert(d.parse(undefined)).equals(1).type();
|
|
39
|
+
assert(d.parse(1)).equals(1).type();
|
|
40
|
+
assert(d.parse(0)).equals(0).type();
|
|
41
|
+
assert(() => d.parse(1.2)).throws("1.2 is not an integer");
|
|
42
|
+
assert(() => d.parse(-1.2)).throws("-1.2 is not an integer");
|
|
43
|
+
});
|
|
44
|
+
[i.default(-1), i.default(() => -1)].forEach(d => {
|
|
45
|
+
assert(d).type();
|
|
46
|
+
assert(() => d.parse(undefined)).throws("-1 is out of range");
|
|
47
|
+
assert(d.parse(1)).equals(1).type();
|
|
48
|
+
assert(d.parse(0)).equals(0).type();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
test.case("validator - range", assert => {
|
|
52
|
+
const r = i.range(0, 10);
|
|
53
|
+
assert(r.parse(0)).equals(0).type();
|
|
54
|
+
assert(r.parse(10)).equals(10).type();
|
|
55
|
+
assert(() => r.parse(-1)).throws("-1 is out of range");
|
|
56
|
+
assert(() => r.parse(-11)).throws("-11 is out of range");
|
|
57
|
+
assert(() => r.parse(11)).throws("11 is out of range");
|
|
58
|
+
});
|
|
59
|
+
test.case("validator - min", assert => {
|
|
60
|
+
const r = i.min(0);
|
|
61
|
+
assert(r.parse(0)).equals(0).type();
|
|
62
|
+
assert(r.parse(10)).equals(10).type();
|
|
63
|
+
assert(() => r.parse(-1)).throws("-1 is out of range");
|
|
64
|
+
});
|
|
65
|
+
test.case("validator - max", assert => {
|
|
66
|
+
const r = i.max(10);
|
|
67
|
+
assert(r.parse(0)).equals(0).type();
|
|
68
|
+
assert(r.parse(10)).equals(10).type();
|
|
69
|
+
assert(() => r.parse(-1)).throws("-1 is out of range");
|
|
70
|
+
assert(() => r.parse(11)).throws("11 is greater than max (10)");
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=uint.js.map
|
package/lib/private/string.d.ts
CHANGED
package/lib/private/string.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export default function throwsIssues(assert, fn) {
|
|
2
|
+
try {
|
|
3
|
+
fn();
|
|
4
|
+
// fail if nothing was thrown
|
|
5
|
+
assert().fail();
|
|
6
|
+
return []; // unreachable
|
|
7
|
+
}
|
|
8
|
+
catch (error) {
|
|
9
|
+
const e = error;
|
|
10
|
+
return e.issues ?? [];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=throws-issues.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type DefaultType from "#DefaultType";
|
|
2
|
+
import Parsed from "#Parsed";
|
|
3
|
+
export default abstract class DefaultTrait<T> extends Parsed<unknown> {
|
|
4
|
+
/**
|
|
5
|
+
* Use the given default if value is missing.
|
|
6
|
+
*/
|
|
7
|
+
abstract default(value: (() => T) | T): DefaultType<this, T>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=Default.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type OptionalType from "#OptionalType";
|
|
2
|
+
import Parsed from "#Parsed";
|
|
3
|
+
export default abstract class OptionalTrait extends Parsed<unknown> {
|
|
4
|
+
/**
|
|
5
|
+
* Value is optional.
|
|
6
|
+
*
|
|
7
|
+
* @returns OptionalType<T>
|
|
8
|
+
*/
|
|
9
|
+
abstract optional(): OptionalType<this>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=Optional.d.ts.map
|
package/lib/private/tuple.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import type NormalizeSchema from "#NormalizeSchema";
|
|
1
2
|
import type Schema from "#Schema";
|
|
2
3
|
import TupleType from "#TupleType";
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
type NormalizeSchemaArray<T extends Schema[]> = {
|
|
5
|
+
[K in keyof T]: NormalizeSchema<T[K]>;
|
|
6
|
+
};
|
|
7
|
+
export default function tuple<const T extends Schema[]>(...items: T): TupleType<NormalizeSchemaArray<T>>;
|
|
8
|
+
export {};
|
|
5
9
|
//# sourceMappingURL=tuple.d.ts.map
|
package/lib/private/tuple.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import TupleType from "#TupleType";
|
|
2
|
-
|
|
2
|
+
import normalize from "#normalize";
|
|
3
|
+
export default function tuple(...items) {
|
|
4
|
+
// normalize each item so the class only sees Parsed
|
|
5
|
+
const parsed = items.map(normalize);
|
|
6
|
+
return new TupleType(parsed);
|
|
7
|
+
}
|
|
3
8
|
//# sourceMappingURL=tuple.js.map
|