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,11 @@
|
|
|
1
|
+
import GenericType from "#GenericType";
|
|
2
|
+
const storeable = (x) => !!x && typeof x === "object" && "datatype" in x;
|
|
3
|
+
export default class VirtualType extends GenericType {
|
|
4
|
+
get datatype() {
|
|
5
|
+
if (storeable(this.schema)) {
|
|
6
|
+
return this.schema.datatype;
|
|
7
|
+
}
|
|
8
|
+
throw new Error("cannot be used in a store");
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=VirtualType.js.map
|
package/lib/private/array.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import ArrayType from "#ArrayType";
|
|
2
|
-
import type
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import type NormalizeSchema from "#NormalizeSchema";
|
|
3
|
+
import type Schema from "#Schema";
|
|
4
|
+
/**
|
|
5
|
+
* Value is an array of the given type.
|
|
6
|
+
*/
|
|
7
|
+
export default function array<const S extends Schema>(of: S): ArrayType<NormalizeSchema<S>>;
|
|
5
8
|
//# sourceMappingURL=array.d.ts.map
|
package/lib/private/array.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import ArrayType from "#ArrayType";
|
|
2
|
-
|
|
2
|
+
import normalize from "#normalize";
|
|
3
|
+
/**
|
|
4
|
+
* Value is an array of the given type.
|
|
5
|
+
*/
|
|
6
|
+
export default function array(of) {
|
|
7
|
+
return new ArrayType(normalize(of));
|
|
8
|
+
}
|
|
3
9
|
//# sourceMappingURL=array.js.map
|
package/lib/private/bigint.d.ts
CHANGED
package/lib/private/bigint.js
CHANGED
package/lib/private/boolean.d.ts
CHANGED
package/lib/private/boolean.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import integer from "@rcompat/is/integer";
|
|
2
|
+
import numeric from "@rcompat/is/numeric";
|
|
3
|
+
export default function coerceBigInt(x) {
|
|
4
|
+
// normalize from string to number; other types unaffected
|
|
5
|
+
const n = numeric(x) ? Number(x) : x;
|
|
6
|
+
// normalize from number to bigint; other types unaffected
|
|
7
|
+
if (integer(n)) {
|
|
8
|
+
return BigInt(n);
|
|
9
|
+
}
|
|
10
|
+
// bigint or invalid
|
|
11
|
+
return x;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=bigint.js.map
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
2
|
+
// time with optional :ss and .ms, but TZ is REQUIRED (Z or ±HH:MM)
|
|
3
|
+
const ISO_DATETIME_TZ = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,3})?)?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
4
|
+
// signed integer
|
|
5
|
+
const INT = /^[+-]?\d+$/;
|
|
6
|
+
function epoch(n, digits) {
|
|
7
|
+
// for strings we use digit-count to choose s vs ms.
|
|
8
|
+
// for numbers we ALWAYS treat as ms (no digits provided)
|
|
9
|
+
const ms = digits !== undefined
|
|
10
|
+
? (digits >= 13 ? n : n * 1000)
|
|
11
|
+
: n;
|
|
12
|
+
const date = new Date(ms);
|
|
13
|
+
return Number.isNaN(date.getTime()) ? undefined : date;
|
|
14
|
+
}
|
|
15
|
+
function fromNumber(n) {
|
|
16
|
+
const date = epoch(n);
|
|
17
|
+
return date !== undefined ? date : n;
|
|
18
|
+
}
|
|
19
|
+
function fromString(raw) {
|
|
20
|
+
const s = raw.trim();
|
|
21
|
+
if (s === "")
|
|
22
|
+
return raw;
|
|
23
|
+
// integer string -> epoch seconds or ms (based on digit count)
|
|
24
|
+
if (INT.test(s)) {
|
|
25
|
+
const digits = s[0] === "+" || s[0] === "-" ? s.length - 1 : s.length;
|
|
26
|
+
const n = Number(s);
|
|
27
|
+
const date = epoch(n, digits);
|
|
28
|
+
return date ?? raw;
|
|
29
|
+
}
|
|
30
|
+
// ISO date-only -> interpret as UTC midnight
|
|
31
|
+
if (ISO_DATE.test(s)) {
|
|
32
|
+
const date = new Date(`${s}T00:00:00.000Z`);
|
|
33
|
+
return Number.isNaN(date.getTime()) ? raw : date;
|
|
34
|
+
}
|
|
35
|
+
// ISO datetime *with* timezone
|
|
36
|
+
if (ISO_DATETIME_TZ.test(s)) {
|
|
37
|
+
const date = new Date(s);
|
|
38
|
+
return Number.isNaN(date.getTime()) ? raw : date;
|
|
39
|
+
}
|
|
40
|
+
return raw;
|
|
41
|
+
}
|
|
42
|
+
export default function coerceDate(x) {
|
|
43
|
+
// already a Date
|
|
44
|
+
if (x instanceof Date)
|
|
45
|
+
return x;
|
|
46
|
+
// numbers are treated as epochs
|
|
47
|
+
if (typeof x === "number" && Number.isFinite(x)) {
|
|
48
|
+
return fromNumber(x);
|
|
49
|
+
}
|
|
50
|
+
// strings
|
|
51
|
+
if (typeof x === "string") {
|
|
52
|
+
return fromString(x);
|
|
53
|
+
}
|
|
54
|
+
return x;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=date.js.map
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import ConstructorType from "#ConstructorType";
|
|
2
|
-
import type
|
|
3
|
-
|
|
2
|
+
import type AbstractNewable from "@rcompat/type/AbstractNewable";
|
|
3
|
+
/**
|
|
4
|
+
* Value is a constructed instance of the given class.
|
|
5
|
+
*/
|
|
6
|
+
declare const _default: <const C extends AbstractNewable>(constructor: C) => ConstructorType<C>;
|
|
4
7
|
export default _default;
|
|
5
8
|
//# sourceMappingURL=constructor.d.ts.map
|
package/lib/private/error.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type ParseIssue from "#ParseIssue";
|
|
2
|
+
import type ParseOptions from "#ParseOptions";
|
|
3
|
+
export default function error<T>(name: string, x: unknown, options?: ParseOptions<T>): [ParseIssue];
|
|
3
4
|
//# sourceMappingURL=error.d.ts.map
|
package/lib/private/error.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import expected from "#expected";
|
|
2
|
+
import ParsedKey from "#ParsedKey";
|
|
3
|
+
export default function error(name, x, options) {
|
|
4
|
+
return [{
|
|
5
|
+
input: x,
|
|
6
|
+
message: expected(name, x),
|
|
7
|
+
path: options?.[ParsedKey] ?? "",
|
|
8
|
+
}];
|
|
9
|
+
}
|
|
10
|
+
;
|
|
4
11
|
//# sourceMappingURL=error.js.map
|
package/lib/private/expect.d.ts
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
declare const types: {
|
|
2
2
|
a: string;
|
|
3
3
|
b: string;
|
|
4
|
+
bb: string;
|
|
5
|
+
bi: string;
|
|
6
|
+
co: string;
|
|
4
7
|
d: string;
|
|
5
|
-
n: string;
|
|
6
|
-
s: string;
|
|
7
|
-
u: string;
|
|
8
|
-
bt: string;
|
|
9
8
|
f: string;
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
i: string;
|
|
10
|
+
n: string;
|
|
12
11
|
nl: string;
|
|
12
|
+
o: string;
|
|
13
|
+
s: string;
|
|
13
14
|
sy: string;
|
|
14
|
-
|
|
15
|
-
i: string;
|
|
15
|
+
u: string;
|
|
16
16
|
ui: string;
|
|
17
|
-
|
|
17
|
+
ur: string;
|
|
18
18
|
};
|
|
19
|
-
|
|
20
|
-
export default
|
|
19
|
+
type At = number | string;
|
|
20
|
+
export default function expect(type: keyof typeof types, got: unknown, at?: At): string;
|
|
21
|
+
export {};
|
|
21
22
|
//# sourceMappingURL=expect.d.ts.map
|
package/lib/private/expect.js
CHANGED
|
@@ -1,21 +1,32 @@
|
|
|
1
1
|
const types = {
|
|
2
2
|
a: "array",
|
|
3
3
|
b: "boolean",
|
|
4
|
+
bb: "blob",
|
|
5
|
+
bi: "bigint",
|
|
6
|
+
co: "constructor",
|
|
4
7
|
d: "date",
|
|
5
|
-
n: "number",
|
|
6
|
-
s: "string",
|
|
7
|
-
u: "undefined",
|
|
8
|
-
bt: "bigint",
|
|
9
8
|
f: "file",
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
i: "int",
|
|
10
|
+
n: "number",
|
|
12
11
|
nl: "null",
|
|
12
|
+
o: "object",
|
|
13
|
+
s: "string",
|
|
13
14
|
sy: "symbol",
|
|
14
|
-
|
|
15
|
-
i: "int",
|
|
15
|
+
u: "undefined",
|
|
16
16
|
ui: "uint",
|
|
17
|
-
|
|
17
|
+
ur: "url",
|
|
18
18
|
};
|
|
19
|
-
const prefix = (at) => at ?
|
|
20
|
-
|
|
19
|
+
const prefix = (at) => at ? `.${at}: ` : "";
|
|
20
|
+
function print_got(got) {
|
|
21
|
+
if (got === undefined) {
|
|
22
|
+
return "undefined";
|
|
23
|
+
}
|
|
24
|
+
if (got === null) {
|
|
25
|
+
return "null";
|
|
26
|
+
}
|
|
27
|
+
return `\`${got}\` (${typeof got})`;
|
|
28
|
+
}
|
|
29
|
+
export default function expect(type, got, at = "") {
|
|
30
|
+
return `${prefix(`${at}`)}expected ${types[type]}, got ${print_got(got)}`;
|
|
31
|
+
}
|
|
21
32
|
//# sourceMappingURL=expect.js.map
|
package/lib/private/expected.js
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
function print_got(x) {
|
|
2
|
+
if (x === undefined) {
|
|
3
|
+
return "undefined";
|
|
4
|
+
}
|
|
5
|
+
if (x === null) {
|
|
6
|
+
return "null";
|
|
7
|
+
}
|
|
8
|
+
return `\`${x?.toString() ?? x}\` (${(typeof x)})`;
|
|
9
|
+
}
|
|
10
|
+
export default (type, x) => `expected ${type}, got ${print_got(x)}`;
|
|
2
11
|
//# sourceMappingURL=expected.js.map
|
package/lib/private/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type NormalizeSchema from "#NormalizeSchema";
|
|
2
2
|
import type Schema from "#Schema";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Create a schema.
|
|
5
|
+
*/
|
|
6
|
+
export default function schema<const S extends Schema>(s: S): NormalizeSchema<S>;
|
|
5
7
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/private/index.js
CHANGED
|
@@ -1,43 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import null_type from "#null";
|
|
6
|
-
import SchemaType from "#SchemaType";
|
|
7
|
-
import tuple from "#tuple";
|
|
8
|
-
import undefined_type from "#undefined";
|
|
9
|
-
const is_constructor = (value) => {
|
|
10
|
-
try {
|
|
11
|
-
if (typeof value !== "function")
|
|
12
|
-
return false;
|
|
13
|
-
new value();
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
};
|
|
1
|
+
import normalize from "#normalize";
|
|
2
|
+
/**
|
|
3
|
+
* Create a schema.
|
|
4
|
+
*/
|
|
20
5
|
export default function schema(s) {
|
|
21
|
-
|
|
22
|
-
return new SchemaType(null_type);
|
|
23
|
-
}
|
|
24
|
-
if (s === undefined) {
|
|
25
|
-
return new SchemaType(undefined_type);
|
|
26
|
-
}
|
|
27
|
-
if (typeof s === "string") {
|
|
28
|
-
return new SchemaType(literal(s));
|
|
29
|
-
}
|
|
30
|
-
if (is_constructor(s)) {
|
|
31
|
-
return new SchemaType(constructor(s));
|
|
32
|
-
}
|
|
33
|
-
if (Array.isArray(s)) {
|
|
34
|
-
if (s.length === 1 && is_validated_type(s[0])) {
|
|
35
|
-
return new SchemaType(array(s[0]));
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
return new SchemaType(tuple(...s));
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return new SchemaType(s);
|
|
6
|
+
return normalize(s);
|
|
42
7
|
}
|
|
43
8
|
//# sourceMappingURL=index.js.map
|
package/lib/private/int.d.ts
CHANGED
package/lib/private/int.js
CHANGED
package/lib/private/literal.d.ts
CHANGED
package/lib/private/literal.js
CHANGED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import ArrayType from "#ArrayType";
|
|
2
|
+
import ConstructorType from "#ConstructorType";
|
|
3
|
+
import LiteralType from "#LiteralType";
|
|
4
|
+
import NullType from "#NullType";
|
|
5
|
+
import ObjectType from "#ObjectType";
|
|
6
|
+
import ParsedKey from "#ParsedKey";
|
|
7
|
+
import TupleType from "#TupleType";
|
|
8
|
+
import UndefinedType from "#UndefinedType";
|
|
9
|
+
import newable from "@rcompat/is/newable";
|
|
10
|
+
function isParsed(x) {
|
|
11
|
+
return !!x && typeof x === "object" && ParsedKey in x;
|
|
12
|
+
}
|
|
13
|
+
function isPlain(x) {
|
|
14
|
+
return !!x && typeof x === "object" &&
|
|
15
|
+
Object.getPrototypeOf(x) === Object.prototype;
|
|
16
|
+
}
|
|
17
|
+
export default function normalize(x) {
|
|
18
|
+
if (isParsed(x))
|
|
19
|
+
return x;
|
|
20
|
+
if (x === null)
|
|
21
|
+
return new NullType();
|
|
22
|
+
if (x === undefined)
|
|
23
|
+
return new UndefinedType();
|
|
24
|
+
if (typeof x === "string" || typeof x === "number" || typeof x === "boolean")
|
|
25
|
+
return new LiteralType(x);
|
|
26
|
+
if (newable(x)) {
|
|
27
|
+
return new ConstructorType(x);
|
|
28
|
+
}
|
|
29
|
+
if (Array.isArray(x)) {
|
|
30
|
+
return x.length === 1
|
|
31
|
+
? new ArrayType(normalize(x[0]))
|
|
32
|
+
: new TupleType(x.map(normalize));
|
|
33
|
+
}
|
|
34
|
+
if (isPlain(x)) {
|
|
35
|
+
const props = {};
|
|
36
|
+
for (const [k, v] of Object.entries(x))
|
|
37
|
+
props[k] = normalize(v);
|
|
38
|
+
return new ObjectType(props);
|
|
39
|
+
}
|
|
40
|
+
throw new TypeError("Unsupported type-like value passed to asType");
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=normalize.js.map
|
package/lib/private/number.d.ts
CHANGED
package/lib/private/number.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type NormalizeSchema from "#NormalizeSchema";
|
|
2
|
+
import ObjectType from "#ObjectType";
|
|
3
|
+
import type Schema from "#Schema";
|
|
4
|
+
import type Dict from "@rcompat/type/Dict";
|
|
5
|
+
import type EO from "@rcompat/type/EO";
|
|
6
|
+
type NormalizeProps<S extends Dict<Schema>> = keyof S extends never ? EO : {
|
|
7
|
+
[K in keyof S]: NormalizeSchema<S[K]>;
|
|
8
|
+
};
|
|
9
|
+
export default function object<P extends Dict<Schema>>(properties: P): ObjectType<NormalizeProps<P>>;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=object.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import normalize from "#normalize";
|
|
2
|
+
import ObjectType from "#ObjectType";
|
|
3
|
+
export default function object(peries) {
|
|
4
|
+
const props = {};
|
|
5
|
+
for (const [k, v] of Object.entries(peries)) {
|
|
6
|
+
props[k] = normalize(v);
|
|
7
|
+
}
|
|
8
|
+
return new ObjectType(props);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=object.js.map
|