pema 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/lib/private/ArrayType.d.ts +1 -1
  2. package/lib/private/ArrayType.js +11 -4
  3. package/lib/private/BuiltinType.d.ts +1 -1
  4. package/lib/private/BuiltinType.js +6 -2
  5. package/lib/private/ConstructorType.d.ts +1 -1
  6. package/lib/private/ConstructorType.js +3 -1
  7. package/lib/private/DefaultType.d.ts +1 -1
  8. package/lib/private/DefaultType.js +6 -5
  9. package/lib/private/EnumType.d.ts +1 -1
  10. package/lib/private/EnumType.js +5 -2
  11. package/lib/private/FunctionType.d.ts +1 -1
  12. package/lib/private/FunctionType.js +6 -3
  13. package/lib/private/IntType.d.ts +1 -1
  14. package/lib/private/IntType.js +2 -2
  15. package/lib/private/IsType.d.ts +1 -1
  16. package/lib/private/IsType.js +3 -1
  17. package/lib/private/JSONType.d.ts +3 -2
  18. package/lib/private/JSONType.js +3 -1
  19. package/lib/private/LiteralType.d.ts +1 -2
  20. package/lib/private/LiteralType.js +3 -4
  21. package/lib/private/Loose.d.ts +4 -0
  22. package/lib/private/Loose.js +3 -0
  23. package/lib/private/NormalizeSchema.d.ts +3 -3
  24. package/lib/private/NullType.d.ts +1 -1
  25. package/lib/private/NullType.js +5 -2
  26. package/lib/private/NumericType.d.ts +2 -1
  27. package/lib/private/ObjectType.d.ts +1 -1
  28. package/lib/private/ObjectType.js +18 -5
  29. package/lib/private/OmitType.d.ts +1 -1
  30. package/lib/private/OmitType.js +3 -1
  31. package/lib/private/OptionalType.d.ts +1 -1
  32. package/lib/private/OptionalType.js +6 -5
  33. package/lib/private/ParseError.d.ts +1 -1
  34. package/lib/private/ParseError.js +9 -8
  35. package/lib/private/ParseOptions.d.ts +2 -1
  36. package/lib/private/Parsed.d.ts +4 -3
  37. package/lib/private/Parsed.js +2 -3
  38. package/lib/private/PartialType.d.ts +1 -1
  39. package/lib/private/PartialType.js +3 -1
  40. package/lib/private/PrimitiveType.d.ts +1 -1
  41. package/lib/private/PrimitiveType.js +7 -4
  42. package/lib/private/PureType.d.ts +1 -1
  43. package/lib/private/PureType.js +2 -2
  44. package/lib/private/RecordType.d.ts +1 -1
  45. package/lib/private/RecordType.js +3 -1
  46. package/lib/private/Storable.d.ts +1 -0
  47. package/lib/private/Storable.js +4 -0
  48. package/lib/private/StoreType.d.ts +1 -1
  49. package/lib/private/StoreType.js +4 -2
  50. package/lib/private/TupleType.d.ts +1 -1
  51. package/lib/private/TupleType.js +11 -4
  52. package/lib/private/UUIDType.d.ts +1 -1
  53. package/lib/private/UUIDType.js +3 -1
  54. package/lib/private/UUIDV4Type.d.ts +1 -1
  55. package/lib/private/UUIDV4Type.js +3 -1
  56. package/lib/private/UUIDV7Type.d.ts +1 -1
  57. package/lib/private/UUIDV7Type.js +3 -1
  58. package/lib/private/UintType.d.ts +1 -1
  59. package/lib/private/UintType.js +2 -2
  60. package/lib/private/UnionType.d.ts +1 -1
  61. package/lib/private/UnionType.js +6 -4
  62. package/lib/private/VirtualType.js +2 -2
  63. package/lib/private/array.d.ts +6 -4
  64. package/lib/private/array.js +15 -2
  65. package/lib/private/blob.d.ts +6 -2
  66. package/lib/private/blob.js +8 -1
  67. package/lib/private/boolean.d.ts +6 -5
  68. package/lib/private/boolean.js +8 -4
  69. package/lib/private/coerce/date.js +3 -5
  70. package/lib/private/coerce/int.js +1 -1
  71. package/lib/private/constructor.d.ts +6 -5
  72. package/lib/private/constructor.js +16 -1
  73. package/lib/private/date.d.ts +6 -2
  74. package/lib/private/date.js +8 -1
  75. package/lib/private/dict.d.ts +12 -2
  76. package/lib/private/dict.js +10 -2
  77. package/lib/private/enum.d.ts +9 -1
  78. package/lib/private/enum.js +14 -1
  79. package/lib/private/errors.js +5 -6
  80. package/lib/private/f32.d.ts +6 -2
  81. package/lib/private/f32.js +8 -1
  82. package/lib/private/f64.d.ts +6 -2
  83. package/lib/private/f64.js +8 -1
  84. package/lib/private/file.d.ts +6 -2
  85. package/lib/private/file.js +8 -1
  86. package/lib/private/function.d.ts +6 -5
  87. package/lib/private/function.js +8 -1
  88. package/lib/private/i128.d.ts +6 -2
  89. package/lib/private/i128.js +8 -1
  90. package/lib/private/i16.d.ts +6 -2
  91. package/lib/private/i16.js +8 -1
  92. package/lib/private/i32.d.ts +6 -2
  93. package/lib/private/i32.js +8 -1
  94. package/lib/private/i64.d.ts +6 -2
  95. package/lib/private/i64.js +8 -1
  96. package/lib/private/i8.d.ts +6 -2
  97. package/lib/private/i8.js +8 -1
  98. package/lib/private/index.d.ts +33 -15
  99. package/lib/private/index.js +148 -41
  100. package/lib/private/is-parsed.d.ts +3 -0
  101. package/lib/private/is-parsed.js +7 -0
  102. package/lib/private/is.d.ts +6 -2
  103. package/lib/private/is.js +14 -1
  104. package/lib/private/json.d.ts +12 -2
  105. package/lib/private/json.js +14 -1
  106. package/lib/private/literal.d.ts +10 -2
  107. package/lib/private/literal.js +16 -1
  108. package/lib/private/normalize.js +4 -11
  109. package/lib/private/null.d.ts +6 -2
  110. package/lib/private/null.js +8 -1
  111. package/lib/private/object.d.ts +11 -4
  112. package/lib/private/object.js +22 -1
  113. package/lib/private/omit.d.ts +9 -1
  114. package/lib/private/omit.js +14 -1
  115. package/lib/private/partial.d.ts +9 -2
  116. package/lib/private/partial.js +16 -2
  117. package/lib/private/path/next.d.ts +1 -7
  118. package/lib/private/pure.d.ts +9 -1
  119. package/lib/private/pure.js +14 -1
  120. package/lib/private/record.d.ts +6 -5
  121. package/lib/private/record.js +14 -1
  122. package/lib/private/resolve.d.ts +2 -0
  123. package/lib/private/resolve.js +7 -0
  124. package/lib/private/spec/bigint.d.ts +4 -1
  125. package/lib/private/spec/bigint.js +27 -26
  126. package/lib/private/spec/biguint.d.ts +4 -1
  127. package/lib/private/spec/biguint.js +23 -22
  128. package/lib/private/spec/int.d.ts +4 -1
  129. package/lib/private/spec/int.js +24 -23
  130. package/lib/private/spec/uint.d.ts +4 -1
  131. package/lib/private/spec/uint.js +22 -21
  132. package/lib/private/string.d.ts +6 -5
  133. package/lib/private/string.js +8 -4
  134. package/lib/private/symbol.d.ts +6 -2
  135. package/lib/private/symbol.js +8 -1
  136. package/lib/private/test.d.ts +4 -21
  137. package/lib/private/test.js +0 -44
  138. package/lib/private/tuple.d.ts +9 -2
  139. package/lib/private/tuple.js +16 -1
  140. package/lib/private/u128.d.ts +6 -2
  141. package/lib/private/u128.js +8 -1
  142. package/lib/private/u16.d.ts +6 -2
  143. package/lib/private/u16.js +8 -1
  144. package/lib/private/u32.d.ts +6 -5
  145. package/lib/private/u32.js +8 -1
  146. package/lib/private/u64.d.ts +6 -2
  147. package/lib/private/u64.js +8 -1
  148. package/lib/private/u8.d.ts +6 -2
  149. package/lib/private/u8.js +8 -1
  150. package/lib/private/undefined.d.ts +6 -2
  151. package/lib/private/undefined.js +8 -1
  152. package/lib/private/union.d.ts +12 -3
  153. package/lib/private/union.js +14 -1
  154. package/lib/private/unknown.d.ts +6 -5
  155. package/lib/private/unknown.js +8 -1
  156. package/lib/private/url.d.ts +6 -2
  157. package/lib/private/url.js +8 -1
  158. package/lib/private/uuid.d.ts +6 -2
  159. package/lib/private/uuid.js +8 -1
  160. package/package.json +7 -6
  161. package/lib/private/is-parsed-type.d.ts +0 -3
  162. package/lib/private/is-parsed-type.js +0 -6
@@ -1,4 +1,5 @@
1
1
  import CoerceKey from "#CoerceKey";
2
+ import Loose from "#Loose";
2
3
  import ParsedKey from "#ParsedKey";
3
4
  import type ParseOptions from "#ParseOptions";
4
5
  import type Serialized from "#Serialized";
@@ -7,19 +8,19 @@ export default abstract class Parsed<StaticType> implements Serializable {
7
8
  get [ParsedKey](): "ParsedKey";
8
9
  get infer(): StaticType;
9
10
  get nullable(): boolean;
11
+ [Loose]: boolean | undefined;
10
12
  [CoerceKey](x: unknown): unknown;
11
13
  abstract get name(): string;
12
14
  /**
13
15
  * Parse the given value.
14
16
  *
15
- * @param x Value to parse.
17
+ * @param u Value to parse.
16
18
  *
17
19
  * @throws `ParseError` if the value could not be parsed.
18
20
  *
19
21
  * @returns The parsed value, if successfully parsed.
20
22
  */
21
- abstract parse(x: unknown, options?: ParseOptions): StaticType;
22
- coerce(x: unknown, options?: ParseOptions): StaticType;
23
+ abstract parse(u: unknown, options?: ParseOptions): StaticType;
23
24
  abstract toJSON(): Serialized;
24
25
  }
25
26
  //# sourceMappingURL=Parsed.d.ts.map
@@ -1,4 +1,5 @@
1
1
  import CoerceKey from "#CoerceKey";
2
+ import Loose from "#Loose";
2
3
  import ParsedKey from "#ParsedKey";
3
4
  export default class Parsed {
4
5
  get [ParsedKey]() {
@@ -10,11 +11,9 @@ export default class Parsed {
10
11
  get nullable() {
11
12
  return false;
12
13
  }
14
+ [Loose] = undefined;
13
15
  [CoerceKey](x) {
14
16
  return x;
15
17
  }
16
- coerce(x, options = {}) {
17
- return this.parse(x, { ...options, coerce: true });
18
- }
19
18
  }
20
19
  //# sourceMappingURL=Parsed.js.map
@@ -13,7 +13,7 @@ export default class PartialType<D extends Partialable> extends VirtualType<D, I
13
13
  get name(): "partial";
14
14
  get schema(): D;
15
15
  default(value: (() => InferPartial<D>) | InferPartial<D>): DefaultType<this, InferPartial<D>>;
16
- parse(x: unknown, options?: ParseOptions): InferPartial<D>;
16
+ parse(u: unknown, options?: ParseOptions): InferPartial<D>;
17
17
  toJSON(): {
18
18
  type: "partial";
19
19
  of: {
@@ -4,6 +4,7 @@ import ParsedKey from "#ParsedKey";
4
4
  import ParseError from "#ParseError";
5
5
  import join from "#path/join";
6
6
  import next from "#path/next";
7
+ import resolve from "#resolve";
7
8
  import VirtualType from "#VirtualType";
8
9
  import is from "@rcompat/is";
9
10
  export default class PartialType extends VirtualType {
@@ -21,7 +22,8 @@ export default class PartialType extends VirtualType {
21
22
  default(value) {
22
23
  return new DefaultType(this, value);
23
24
  }
24
- parse(x, options = {}) {
25
+ parse(u, options = {}) {
26
+ const x = resolve(u);
25
27
  if (!is.dict(x))
26
28
  throw E.invalid_type(x, "object", options);
27
29
  const input = x;
@@ -12,7 +12,7 @@ export default abstract class PrimitiveType<StaticType, Name extends string> ext
12
12
  get options(): ParseOptions<unknown>;
13
13
  get validators(): Validator<StaticType>[];
14
14
  derive(next: Next<StaticType>): this;
15
- parse(x: unknown, options?: ParseOptions<StaticType>): Infer<this>;
15
+ parse(u: unknown, options?: ParseOptions<StaticType>): Infer<this>;
16
16
  }
17
17
  export {};
18
18
  //# sourceMappingURL=PrimitiveType.d.ts.map
@@ -1,7 +1,9 @@
1
1
  import CoerceKey from "#CoerceKey";
2
2
  import E from "#errors";
3
+ import Loose from "#Loose";
3
4
  import ParsedKey from "#ParsedKey";
4
5
  import ParseError from "#ParseError";
6
+ import resolve from "#resolve";
5
7
  import Type from "#Type";
6
8
  export default class PrimitiveType extends Type {
7
9
  #validators;
@@ -21,10 +23,10 @@ export default class PrimitiveType extends Type {
21
23
  const Constructor = this.constructor;
22
24
  return new Constructor([...this.#validators, ...next.validators ?? []], { ...this.#options, ...next.options ?? {} });
23
25
  }
24
- parse(x, options = {}) {
26
+ parse(u, options = {}) {
27
+ const x = resolve(u);
25
28
  // hotpath: avoid object spread when possible
26
- const has_instance_options = this.#options.coerce !== undefined
27
- || this.#options[ParsedKey] !== undefined;
29
+ const has_instance_options = this.#options[ParsedKey] !== undefined;
28
30
  const $options = has_instance_options
29
31
  ? { ...this.#options, ...options }
30
32
  : options;
@@ -33,7 +35,8 @@ export default class PrimitiveType extends Type {
33
35
  const validators = option_validators && option_validators.length > 0
34
36
  ? option_validators.concat(this.#validators)
35
37
  : this.#validators;
36
- const $x = $options.coerce === true ? this[CoerceKey](x) : x;
38
+ const loose = this[Loose] ?? $options[Loose] ?? false;
39
+ const $x = loose ? this[CoerceKey](x) : x;
37
40
  if (typeof $x !== this.name)
38
41
  throw E.invalid_type($x, this.name, $options);
39
42
  const base = $options[ParsedKey] ?? "";
@@ -7,7 +7,7 @@ export default class PureType<Type, Name extends string = "PureType"> extends Pa
7
7
  get name(): string;
8
8
  get Name(): Name;
9
9
  optional(): OptionalType<this>;
10
- parse(x: unknown): Infer<this>;
10
+ parse(u: unknown): Infer<this>;
11
11
  toJSON(): {
12
12
  type: "pure";
13
13
  };
@@ -10,9 +10,9 @@ export default class PureType extends Parsed {
10
10
  optional() {
11
11
  return new OptionalType(this);
12
12
  }
13
- parse(x) {
13
+ parse(u) {
14
14
  // no parsing of static types
15
- return x;
15
+ return u;
16
16
  }
17
17
  toJSON() {
18
18
  return { type: "pure" };
@@ -10,7 +10,7 @@ export default class RecordType<Key extends RecordTypeKey, Value extends Parsed<
10
10
  constructor(k: Key, v: Value);
11
11
  optional(): OptionalType<this>;
12
12
  get name(): "record";
13
- parse(x: unknown, options?: ParseOptions): Infer<this>;
13
+ parse(u: unknown, options?: ParseOptions): Infer<this>;
14
14
  toJSON(): {
15
15
  type: "record";
16
16
  key: {
@@ -4,6 +4,7 @@ import OptionalType from "#OptionalType";
4
4
  import ParsedKey from "#ParsedKey";
5
5
  import join from "#path/join";
6
6
  import next from "#path/next";
7
+ import resolve from "#resolve";
7
8
  import is from "@rcompat/is";
8
9
  export default class RecordType extends GenericType {
9
10
  #key;
@@ -19,7 +20,8 @@ export default class RecordType extends GenericType {
19
20
  get name() {
20
21
  return "record";
21
22
  }
22
- parse(x, options = {}) {
23
+ parse(u, options = {}) {
24
+ const x = resolve(u);
23
25
  const path = options[ParsedKey] ?? "";
24
26
  if (!is.dict(x))
25
27
  throw E.invalid_type(x, "object", path);
@@ -11,5 +11,6 @@ export default abstract class Storable<TKey extends K = K, TValue = unknown> ext
11
11
  type: N;
12
12
  datatype: T;
13
13
  };
14
+ static is(x: unknown): x is Storable;
14
15
  }
15
16
  //# sourceMappingURL=Storable.d.ts.map
@@ -1,7 +1,11 @@
1
1
  import Parsed from "#Parsed";
2
+ import is from "@rcompat/is";
2
3
  export default class Storable extends Parsed {
3
4
  static serialize(s) {
4
5
  return { type: s.name, datatype: s.datatype };
5
6
  }
7
+ static is(x) {
8
+ return is.object(x) && "datatype" in x;
9
+ }
6
10
  }
7
11
  //# sourceMappingURL=Storable.js.map
@@ -7,7 +7,7 @@ export default class StoreType<S extends StoreSchema> extends ObjectType<S> {
7
7
  #private;
8
8
  constructor(properties: S, pk?: string | null);
9
9
  get name(): string;
10
- parse(x: unknown, options?: ParseOptions): Infer<this>;
10
+ parse(u: unknown, options?: ParseOptions): Infer<this>;
11
11
  partial(): PartialType<any>;
12
12
  }
13
13
  //# sourceMappingURL=StoreType.d.ts.map
@@ -2,6 +2,7 @@ import ObjectType from "#ObjectType";
2
2
  import PartialType from "#PartialType";
3
3
  import E from "#errors";
4
4
  import next from "#path/next";
5
+ import resolve from "#resolve";
5
6
  import is from "@rcompat/is";
6
7
  export default class StoreType extends ObjectType {
7
8
  #pk;
@@ -12,9 +13,10 @@ export default class StoreType extends ObjectType {
12
13
  get name() {
13
14
  return "store";
14
15
  }
15
- parse(x, options = {}) {
16
+ parse(u, options = {}) {
17
+ const x = resolve(u);
16
18
  const $options = { ...options };
17
- if (x !== undefined && !is.dict(x))
19
+ if (is.defined(x) && !is.dict(x))
18
20
  throw E.invalid_type(x, "object", $options);
19
21
  const input = x ?? {};
20
22
  const out = {};
@@ -14,7 +14,7 @@ export default class TupleType<T extends Parsed<unknown>[]> extends GenericType<
14
14
  constructor(items: T);
15
15
  get name(): "tuple";
16
16
  optional(): OptionalType<this>;
17
- parse(x: unknown, options?: ParseOptions): Infer<this>;
17
+ parse(u: unknown, options?: ParseOptions): Infer<this>;
18
18
  toJSON(): {
19
19
  type: "tuple";
20
20
  of: import("./Serialized.js").default[];
@@ -1,7 +1,10 @@
1
1
  import E from "#errors";
2
2
  import GenericType from "#GenericType";
3
+ import Loose from "#Loose";
3
4
  import OptionalType from "#OptionalType";
4
5
  import next from "#path/next";
6
+ import resolve from "#resolve";
7
+ import is from "@rcompat/is";
5
8
  export default class TupleType extends GenericType {
6
9
  #items;
7
10
  constructor(items) {
@@ -14,19 +17,23 @@ export default class TupleType extends GenericType {
14
17
  optional() {
15
18
  return new OptionalType(this);
16
19
  }
17
- parse(x, options = {}) {
18
- if (!Array.isArray(x))
20
+ parse(u, options = {}) {
21
+ const x = resolve(u);
22
+ if (!is.array(x))
19
23
  throw E.invalid_type(x, "array", options);
24
+ const $options = this[Loose] !== undefined
25
+ ? { ...options, [Loose]: this[Loose] }
26
+ : options;
20
27
  const items = this.#items;
21
28
  const n = items.length;
22
29
  const out = new Array(n);
23
30
  // validate each expected item
24
31
  for (let i = 0; i < n; i++) {
25
- out[i] = items[i].parse(x[i], next(i, options));
32
+ out[i] = items[i].parse(x[i], next(i, $options));
26
33
  }
27
34
  // reject extra items
28
35
  if (x.length > n)
29
- throw E.invalid_type(x[n], "undefined", next(n, options));
36
+ throw E.invalid_type(x[n], "undefined", next(n, $options));
30
37
  return out;
31
38
  }
32
39
  toJSON() {
@@ -6,7 +6,7 @@ import UUIDV7Type from "#UUIDV7Type";
6
6
  export default class UUIDType extends PrimitiveType<string, "UUIDType"> implements Storable<"uuid"> {
7
7
  get name(): "string";
8
8
  get datatype(): "uuid";
9
- parse(x: unknown): Infer<this>;
9
+ parse(u: unknown): Infer<this>;
10
10
  toJSON(): {
11
11
  type: "string";
12
12
  datatype: "uuid";
@@ -3,6 +3,7 @@ import Storable from "#Storable";
3
3
  import UUIDV4Type from "#UUIDV4Type";
4
4
  import UUIDV7Type from "#UUIDV7Type";
5
5
  import E from "#errors";
6
+ import resolve from "#resolve";
6
7
  import is from "@rcompat/is";
7
8
  const re = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/i;
8
9
  const v4 = new UUIDV4Type();
@@ -14,7 +15,8 @@ export default class UUIDType extends PrimitiveType {
14
15
  get datatype() {
15
16
  return "uuid";
16
17
  }
17
- parse(x) {
18
+ parse(u) {
19
+ const x = resolve(u);
18
20
  if (!is.string(x) || !re.test(x)) {
19
21
  throw E.invalid_format(x, `"${x}" is not a valid UUID`);
20
22
  }
@@ -4,7 +4,7 @@ import Storable from "#Storable";
4
4
  export default class UUIDV4Type extends PrimitiveType<string, "UUIDV4Type"> implements Storable<"uuid_v4"> {
5
5
  get name(): "string";
6
6
  get datatype(): "uuid_v4";
7
- parse(x: unknown): Infer<this>;
7
+ parse(u: unknown): Infer<this>;
8
8
  toJSON(): {
9
9
  type: "string";
10
10
  datatype: "uuid_v4";
@@ -1,6 +1,7 @@
1
1
  import PrimitiveType from "#PrimitiveType";
2
2
  import Storable from "#Storable";
3
3
  import E from "#errors";
4
+ import resolve from "#resolve";
4
5
  import is from "@rcompat/is";
5
6
  const re = /^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i;
6
7
  export default class UUIDV4Type extends PrimitiveType {
@@ -10,7 +11,8 @@ export default class UUIDV4Type extends PrimitiveType {
10
11
  get datatype() {
11
12
  return "uuid_v4";
12
13
  }
13
- parse(x) {
14
+ parse(u) {
15
+ const x = resolve(u);
14
16
  if (!is.string(x) || !re.test(x)) {
15
17
  throw E.invalid_format(x, `"${x}" is not a valid UUID v4`);
16
18
  }
@@ -4,7 +4,7 @@ import Storable from "#Storable";
4
4
  export default class UUIDV7Type extends PrimitiveType<string, "UUIDV7Type"> implements Storable<"uuid_v7"> {
5
5
  get name(): "string";
6
6
  get datatype(): "uuid_v7";
7
- parse(x: unknown): Infer<this>;
7
+ parse(u: unknown): Infer<this>;
8
8
  toJSON(): {
9
9
  type: "string";
10
10
  datatype: "uuid_v7";
@@ -1,6 +1,7 @@
1
1
  import PrimitiveType from "#PrimitiveType";
2
2
  import Storable from "#Storable";
3
3
  import E from "#errors";
4
+ import resolve from "#resolve";
4
5
  import is from "@rcompat/is";
5
6
  const re = /^[\da-f]{8}-[\da-f]{4}-7[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i;
6
7
  export default class UUIDV7Type extends PrimitiveType {
@@ -10,7 +11,8 @@ export default class UUIDV7Type extends PrimitiveType {
10
11
  get datatype() {
11
12
  return "uuid_v7";
12
13
  }
13
- parse(x) {
14
+ parse(u) {
15
+ const x = resolve(u);
14
16
  if (!is.string(x) || !re.test(x)) {
15
17
  throw E.invalid_format(x, `"${x}" is not a valid UUID v7`);
16
18
  }
@@ -11,6 +11,6 @@ export default class UintType<T extends UintDataType> extends NumericType<T, num
11
11
  * Value is a non-privileged port number (1000 - 65535).
12
12
  */
13
13
  port(): this;
14
- parse(x: unknown, options?: ParseOptions<number>): import("./Infer.js").default<this>;
14
+ parse(u: unknown, options?: ParseOptions<number>): import("./Infer.js").default<this>;
15
15
  }
16
16
  //# sourceMappingURL=UintType.d.ts.map
@@ -14,8 +14,8 @@ export default class UintType extends NumericType {
14
14
  port() {
15
15
  return this.derive({ validators: [port] });
16
16
  }
17
- parse(x, options = {}) {
18
- return super.parse(x, {
17
+ parse(u, options = {}) {
18
+ return super.parse(u, {
19
19
  ...options,
20
20
  validators: [integer],
21
21
  });
@@ -19,7 +19,7 @@ export default class UnionType<T extends Parsed<unknown>[]> extends GenericType<
19
19
  get schema(): T;
20
20
  optional(): OptionalType<this>;
21
21
  default(value: (() => InferUnion<T>) | InferUnion<T>): DefaultType<this, InferUnion<T>>;
22
- parse(x: unknown, options?: ParseOptions): Infer<this>;
22
+ parse(u: unknown, options?: ParseOptions): Infer<this>;
23
23
  toJSON(): {
24
24
  type: "union";
25
25
  of: import("./Serialized.js").default[];
@@ -1,13 +1,14 @@
1
1
  import DefaultType from "#DefaultType";
2
2
  import E from "#errors";
3
3
  import GenericType from "#GenericType";
4
- import isParsedType from "#is-parsed-type";
4
+ import is_parsed from "#is-parsed";
5
5
  import OptionalType from "#OptionalType";
6
6
  import ParseError from "#ParseError";
7
+ import resolve from "#resolve";
7
8
  import S from "#schema-errors";
8
9
  import assert from "@rcompat/assert";
9
10
  const print = (type) => {
10
- const parsed = isParsedType(type);
11
+ const parsed = is_parsed(type);
11
12
  if (parsed) {
12
13
  return type.name;
13
14
  }
@@ -25,7 +26,7 @@ const print = (type) => {
25
26
  }
26
27
  return type;
27
28
  };
28
- const union_error = (types) => `\`${types.map(t => isParsedType(t) ? t.name : print(t)).join(" | ")}\``;
29
+ const union_error = (types) => `\`${types.map(t => is_parsed(t) ? t.name : print(t)).join(" | ")}\``;
29
30
  export default class UnionType extends GenericType {
30
31
  #of;
31
32
  constructor(of) {
@@ -45,7 +46,8 @@ export default class UnionType extends GenericType {
45
46
  default(value) {
46
47
  return new DefaultType(this, value);
47
48
  }
48
- parse(x, options = {}) {
49
+ parse(u, options = {}) {
50
+ const x = resolve(u);
49
51
  for (const type of this.#of) {
50
52
  try {
51
53
  type.parse(x, options);
@@ -1,8 +1,8 @@
1
1
  import GenericType from "#GenericType";
2
- const storable = (x) => !!x && typeof x === "object" && "datatype" in x;
2
+ import Storable from "#Storable";
3
3
  export default class VirtualType extends GenericType {
4
4
  get datatype() {
5
- if (storable(this.schema))
5
+ if (Storable.is(this.schema))
6
6
  return this.schema.datatype;
7
7
  throw new Error("cannot be used in a store");
8
8
  }
@@ -1,8 +1,10 @@
1
1
  import ArrayType from "#ArrayType";
2
2
  import type NormalizeSchema from "#NormalizeSchema";
3
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>>;
4
+ declare const array: {
5
+ strict: <const S extends Schema>(of: S) => ArrayType<NormalizeSchema<S>>;
6
+ loose: <const S extends Schema>(of: S) => ArrayType<NormalizeSchema<S>>;
7
+ vanilla: <const S extends Schema>(of: S) => ArrayType<NormalizeSchema<S>>;
8
+ };
9
+ export default array;
8
10
  //# sourceMappingURL=array.d.ts.map
@@ -1,9 +1,22 @@
1
1
  import ArrayType from "#ArrayType";
2
+ import Loose from "#Loose";
2
3
  import normalize from "#normalize";
3
4
  /**
4
5
  * Value is an array of the given type.
5
6
  */
6
- export default function array(of) {
7
+ const vanilla = function array(of) {
7
8
  return new ArrayType(normalize(of));
8
- }
9
+ };
10
+ const loose = function array(of) {
11
+ const i = new ArrayType(normalize(of));
12
+ i[Loose] = true;
13
+ return i;
14
+ };
15
+ const strict = function array(of) {
16
+ const i = new ArrayType(normalize(of));
17
+ i[Loose] = false;
18
+ return i;
19
+ };
20
+ const array = { strict, loose, vanilla };
21
+ export default array;
9
22
  //# sourceMappingURL=array.js.map
@@ -1,4 +1,8 @@
1
1
  import BlobType from "#BlobType";
2
- declare const _default: BlobType;
3
- export default _default;
2
+ declare const blob: {
3
+ vanilla: BlobType;
4
+ loose: BlobType;
5
+ strict: BlobType;
6
+ };
7
+ export default blob;
4
8
  //# sourceMappingURL=blob.d.ts.map
@@ -1,3 +1,10 @@
1
1
  import BlobType from "#BlobType";
2
- export default new BlobType();
2
+ import Loose from "#Loose";
3
+ const vanilla = new BlobType();
4
+ const loose = new BlobType();
5
+ loose[Loose] = true;
6
+ const strict = new BlobType();
7
+ strict[Loose] = false;
8
+ const blob = { vanilla, loose, strict };
9
+ export default blob;
3
10
  //# sourceMappingURL=blob.js.map
@@ -1,7 +1,8 @@
1
1
  import BooleanType from "#BooleanType";
2
- /**
3
- * Value is a boolean.
4
- */
5
- declare const _default: BooleanType;
6
- export default _default;
2
+ declare const boolean: {
3
+ vanilla: BooleanType;
4
+ loose: BooleanType;
5
+ strict: BooleanType;
6
+ };
7
+ export default boolean;
7
8
  //# sourceMappingURL=boolean.d.ts.map
@@ -1,6 +1,10 @@
1
1
  import BooleanType from "#BooleanType";
2
- /**
3
- * Value is a boolean.
4
- */
5
- export default new BooleanType();
2
+ import Loose from "#Loose";
3
+ const vanilla = new BooleanType();
4
+ const loose = new BooleanType();
5
+ loose[Loose] = true;
6
+ const strict = new BooleanType();
7
+ strict[Loose] = false;
8
+ const boolean = { vanilla, loose, strict };
9
+ export default boolean;
6
10
  //# sourceMappingURL=boolean.js.map
@@ -1,3 +1,4 @@
1
+ import is from "@rcompat/is";
1
2
  const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
2
3
  // time with optional :ss and .ms, but TZ is REQUIRED (Z or ±HH:MM)
3
4
  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})$/;
@@ -44,13 +45,10 @@ export default function coerceDate(x) {
44
45
  if (x instanceof Date)
45
46
  return x;
46
47
  // numbers are treated as epochs
47
- if (typeof x === "number" && Number.isFinite(x)) {
48
+ if (is.finite(x))
48
49
  return fromNumber(x);
49
- }
50
- // strings
51
- if (typeof x === "string") {
50
+ if (is.string(x))
52
51
  return fromString(x);
53
- }
54
52
  return x;
55
53
  }
56
54
  //# sourceMappingURL=date.js.map
@@ -3,7 +3,7 @@ export default function coerce_int(x) {
3
3
  // normalize from string to number; other types unaffected
4
4
  const n = is.numeric(x) ? Number(x) : x;
5
5
  // if is integer, return it
6
- if (typeof n === "number" && is.int(n))
6
+ if (is.int(n))
7
7
  return n;
8
8
  return x;
9
9
  }
@@ -1,8 +1,9 @@
1
1
  import ConstructorType from "#ConstructorType";
2
2
  import type { AbstractNewable } from "@rcompat/type";
3
- /**
4
- * Value is a constructed instance of the given class.
5
- */
6
- declare const _default: <const C extends AbstractNewable>(constructor: C) => ConstructorType<C>;
7
- export default _default;
3
+ declare const constructor: {
4
+ vanilla: <const C extends AbstractNewable>(c: C) => ConstructorType<C>;
5
+ loose: <const C extends AbstractNewable>(c: C) => ConstructorType<C>;
6
+ strict: <const C extends AbstractNewable>(c: C) => ConstructorType<C>;
7
+ };
8
+ export default constructor;
8
9
  //# sourceMappingURL=constructor.d.ts.map
@@ -1,6 +1,21 @@
1
1
  import ConstructorType from "#ConstructorType";
2
+ import Loose from "#Loose";
2
3
  /**
3
4
  * Value is a constructed instance of the given class.
4
5
  */
5
- export default (constructor) => new ConstructorType(constructor);
6
+ const vanilla = function constructor(c) {
7
+ return new ConstructorType(c);
8
+ };
9
+ const loose = function constructor(c) {
10
+ const i = new ConstructorType(c);
11
+ i[Loose] = true;
12
+ return i;
13
+ };
14
+ const strict = function constructor(c) {
15
+ const i = new ConstructorType(c);
16
+ i[Loose] = false;
17
+ return i;
18
+ };
19
+ const constructor = { vanilla, loose, strict };
20
+ export default constructor;
6
21
  //# sourceMappingURL=constructor.js.map
@@ -1,4 +1,8 @@
1
1
  import DateType from "#DateType";
2
- declare const _default: DateType;
3
- export default _default;
2
+ declare const date: {
3
+ vanilla: DateType;
4
+ loose: DateType;
5
+ strict: DateType;
6
+ };
7
+ export default date;
4
8
  //# sourceMappingURL=date.d.ts.map
@@ -1,3 +1,10 @@
1
1
  import DateType from "#DateType";
2
- export default new DateType();
2
+ import Loose from "#Loose";
3
+ const vanilla = new DateType();
4
+ const loose = new DateType();
5
+ loose[Loose] = true;
6
+ const strict = new DateType();
7
+ strict[Loose] = false;
8
+ const date = { vanilla, loose, strict };
9
+ export default date;
3
10
  //# sourceMappingURL=date.js.map