pema 0.8.2 → 0.9.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 (46) hide show
  1. package/lib/private/ArrayType.d.ts +1 -1
  2. package/lib/private/ArrayType.js +7 -7
  3. package/lib/private/AsyncType.d.ts +18 -0
  4. package/lib/private/AsyncType.js +28 -0
  5. package/lib/private/EnumType.d.ts +13 -10
  6. package/lib/private/EnumType.js +31 -13
  7. package/lib/private/InferInputSchema.d.ts +1 -1
  8. package/lib/private/JSONType.js +3 -4
  9. package/lib/private/LiteralType.d.ts +1 -1
  10. package/lib/private/NumericType.d.ts +1 -1
  11. package/lib/private/NumericType.js +5 -5
  12. package/lib/private/ObjectType.js +2 -2
  13. package/lib/private/OmitType.js +3 -4
  14. package/lib/private/Parsed.d.ts +1 -0
  15. package/lib/private/Parsed.js +21 -0
  16. package/lib/private/PartialType.js +2 -2
  17. package/lib/private/PrimitiveType.d.ts +1 -1
  18. package/lib/private/PrimitiveType.js +3 -2
  19. package/lib/private/Serialized.d.ts +2 -1
  20. package/lib/private/StoreType.js +1 -1
  21. package/lib/private/StringType.js +8 -8
  22. package/lib/private/TupleType.js +1 -1
  23. package/lib/private/UintType.js +1 -1
  24. package/lib/private/array.d.ts +9 -3
  25. package/lib/private/async.d.ts +8 -0
  26. package/lib/private/async.js +7 -0
  27. package/lib/private/coerce/date.js +3 -5
  28. package/lib/private/constructor.d.ts +9 -3
  29. package/lib/private/enum.d.ts +6 -5
  30. package/lib/private/enum.js +5 -4
  31. package/lib/private/index.d.ts +97 -250
  32. package/lib/private/index.js +2 -0
  33. package/lib/private/is.d.ts +6 -3
  34. package/lib/private/normalize.js +2 -2
  35. package/lib/private/optional.d.ts +1 -1
  36. package/lib/private/path/next.d.ts +2 -1
  37. package/lib/private/path/next.js +4 -2
  38. package/lib/private/record.d.ts +9 -3
  39. package/lib/private/schema-errors.d.ts +1 -0
  40. package/lib/private/schema-errors.js +1 -0
  41. package/lib/private/spec/bigint.d.ts +3 -3
  42. package/lib/private/spec/biguint.d.ts +3 -3
  43. package/lib/private/spec/int.d.ts +3 -3
  44. package/lib/private/spec/uint.d.ts +3 -3
  45. package/lib/private/test.js +4 -3
  46. package/package.json +8 -8
@@ -20,7 +20,7 @@ export default class ArrayType<T extends Parsed<unknown>, M extends Mode = undef
20
20
  get name(): "array";
21
21
  optional(): OptionalType<this>;
22
22
  default(value: (() => Infer<T>[]) | Infer<T>[]): DefaultType<this, Infer<T>[]>;
23
- derive(_next: Next<Array<Infer<T>>>): this;
23
+ with(_next: Next<Array<Infer<T>>>): this;
24
24
  /**
25
25
  * Member values are unique — only for primitive subtypes.
26
26
  *
@@ -40,7 +40,7 @@ export default class ArrayType extends GenericType {
40
40
  default(value) {
41
41
  return new DefaultType(this, value);
42
42
  }
43
- derive(_next) {
43
+ with(_next) {
44
44
  const Constructor = this.constructor;
45
45
  return new Constructor(this.#item, this[Loose], [...this.#validators, ..._next.validators ?? []]);
46
46
  }
@@ -54,27 +54,27 @@ export default class ArrayType extends GenericType {
54
54
  if (!isPrimitive(this.#item)) {
55
55
  throw S.unique_subtype_not_primitive(this.#item.name);
56
56
  }
57
- return this.derive({ validators: [unique] });
57
+ return this.with({ validators: [unique] });
58
58
  }
59
59
  uniqueBy(select) {
60
- return this.derive({ validators: [uniqueBy(select)] });
60
+ return this.with({ validators: [uniqueBy(select)] });
61
61
  }
62
62
  min(limit) {
63
63
  if (limit < 0)
64
64
  throw S.min_negative(limit);
65
- return this.derive({ validators: [min(limit)] });
65
+ return this.with({ validators: [min(limit)] });
66
66
  }
67
67
  max(limit) {
68
68
  if (limit < 0)
69
69
  throw S.max_negative(limit);
70
- return this.derive({ validators: [max(limit)] });
70
+ return this.with({ validators: [max(limit)] });
71
71
  }
72
72
  length(from, to) {
73
- return this.derive({ validators: [length(from, to)] });
73
+ return this.with({ validators: [length(from, to)] });
74
74
  }
75
75
  parse(u, options = {}) {
76
76
  const x = resolve(u);
77
- const $options = this[Loose] !== undefined
77
+ const $options = is.defined(this[Loose])
78
78
  ? { ...options, [Loose]: this[Loose] }
79
79
  : options;
80
80
  const path = $options[ParsedKey] ?? "";
@@ -0,0 +1,18 @@
1
+ import type Mode from "#Mode";
2
+ import type ObjectType from "#ObjectType";
3
+ import type Parsed from "#Parsed";
4
+ import type ParseOptions from "#ParseOptions";
5
+ import type { Dict, MaybePromise } from "@rcompat/type";
6
+ type Derive<Input, Output> = (value: Input) => MaybePromise<Output>;
7
+ export default class AsyncType<P extends Dict<Parsed<unknown>> = Dict<Parsed<unknown>>, M extends Mode = undefined, I = ObjectType<P, M>["infer"], Output = I> {
8
+ #private;
9
+ constructor(schema: ObjectType<P, M, I>, derive?: Derive<I, Output>);
10
+ get infer(): Output;
11
+ get input(): import("./InferInputSchema.js").default<P>;
12
+ get schema(): ObjectType<P, M, I>;
13
+ get properties(): P;
14
+ derive<Next>(derive: Derive<Output, Next>): AsyncType<P, M, I, Awaited<Next>>;
15
+ parse(u: unknown, options?: ParseOptions): Promise<Output>;
16
+ }
17
+ export {};
18
+ //# sourceMappingURL=AsyncType.d.ts.map
@@ -0,0 +1,28 @@
1
+ export default class AsyncType {
2
+ #schema;
3
+ #derive;
4
+ constructor(schema, derive = value => value) {
5
+ this.#schema = schema;
6
+ this.#derive = derive;
7
+ }
8
+ get infer() {
9
+ return undefined;
10
+ }
11
+ get input() {
12
+ return this.#schema.input;
13
+ }
14
+ get schema() {
15
+ return this.#schema;
16
+ }
17
+ get properties() {
18
+ return this.#schema.properties;
19
+ }
20
+ derive(derive) {
21
+ const next = async (value) => await derive(await this.#derive(value));
22
+ return new AsyncType(this.#schema, next);
23
+ }
24
+ async parse(u, options) {
25
+ return this.#derive(this.#schema.parse(u, options));
26
+ }
27
+ }
28
+ //# sourceMappingURL=AsyncType.js.map
@@ -1,21 +1,24 @@
1
1
  import DefaultType from "#DefaultType";
2
- import GenericType from "#GenericType";
3
- import type Infer from "#Infer";
4
2
  import OptionalType from "#OptionalType";
5
3
  import type ParseOptions from "#ParseOptions";
6
- import type OptionalTrait from "#trait/Optional";
7
- type Literal = string;
8
- export default class EnumType<T extends readonly Literal[]> extends GenericType<T, T[number], "EnumType"> implements OptionalTrait {
4
+ import Storable from "#Storable";
5
+ import type UintType from "#UintType";
6
+ import type { Dict } from "@rcompat/type";
7
+ export default class EnumType<V extends Dict<number>, L extends boolean | undefined = undefined> extends Storable<"u8", V[keyof V]> {
9
8
  #private;
10
- constructor(values: T);
9
+ constructor(values: V, inner: UintType<"u8", L>);
11
10
  get name(): string;
11
+ get datatype(): "u8";
12
+ get values(): V;
13
+ nameOf(value: V[keyof V]): keyof V;
12
14
  optional(): OptionalType<this>;
13
- default<D extends T[number]>(value: (() => D) | D): DefaultType<EnumType<T>, D>;
14
- parse(u: unknown, options?: ParseOptions): Infer<this>;
15
+ default<D extends V[keyof V]>(value: (() => D) | D): DefaultType<EnumType<V, L>, D>;
16
+ parse(u: unknown, options?: ParseOptions): V[keyof V];
15
17
  toJSON(): {
16
18
  type: "enum";
17
- values: T[number][];
19
+ datatype: "u8";
20
+ values: V;
18
21
  };
19
22
  }
20
- export {};
23
+ export type Enum<V extends Dict<number>, L extends boolean | undefined = undefined> = EnumType<V, L> & V;
21
24
  //# sourceMappingURL=EnumType.d.ts.map
@@ -1,17 +1,35 @@
1
1
  import DefaultType from "#DefaultType";
2
- import E from "#errors";
3
- import GenericType from "#GenericType";
4
2
  import OptionalType from "#OptionalType";
5
- import resolve from "#resolve";
6
- import is from "@rcompat/is";
7
- export default class EnumType extends GenericType {
3
+ import S from "#schema-errors";
4
+ import Storable from "#Storable";
5
+ const KEY = /^[A-Z][A-Z0-9_]*$/;
6
+ export default class EnumType extends Storable {
8
7
  #values;
9
- constructor(values) {
8
+ #reverse;
9
+ #inner;
10
+ constructor(values, inner) {
10
11
  super();
12
+ for (const key of Object.keys(values)) {
13
+ if (!KEY.test(key))
14
+ throw S.enum_invalid_key(key);
15
+ }
11
16
  this.#values = values;
17
+ this.#reverse = new Map(Object.entries(values).map(([k, v]) => [v, k]));
18
+ this.#inner = inner.values(values);
19
+ Object.assign(this, values);
20
+ Object.freeze(this);
12
21
  }
13
22
  get name() {
14
- return this.#values.map(v => `"${v}"`).join(" | ");
23
+ return Object.keys(this.#values).map(k => `"${k}"`).join(" | ");
24
+ }
25
+ get datatype() {
26
+ return "u8";
27
+ }
28
+ get values() {
29
+ return this.#values;
30
+ }
31
+ nameOf(value) {
32
+ return this.#reverse.get(value);
15
33
  }
16
34
  optional() {
17
35
  return new OptionalType(this);
@@ -20,14 +38,14 @@ export default class EnumType extends GenericType {
20
38
  return new DefaultType(this, value);
21
39
  }
22
40
  parse(u, options = {}) {
23
- const x = resolve(u);
24
- if (!is.string(x) || !this.#values.includes(x)) {
25
- throw E.invalid_type(x, this.name, options);
26
- }
27
- return x;
41
+ return this.#inner.parse(u, options);
28
42
  }
29
43
  toJSON() {
30
- return { type: "enum", values: [...this.#values] };
44
+ return {
45
+ type: "enum",
46
+ datatype: "u8",
47
+ values: { ...this.#values },
48
+ };
31
49
  }
32
50
  }
33
51
  //# sourceMappingURL=EnumType.js.map
@@ -5,7 +5,7 @@ import type OptionalType from "#OptionalType";
5
5
  import type Parsed from "#Parsed";
6
6
  import type Schema from "#Schema";
7
7
  import type { ImpliedOptional, UndefinedToOptional } from "@rcompat/type";
8
- type InferInputSchema<S> = S extends DefaultType<infer T, unknown> ? T["infer"] | undefined : S extends OptionalType<infer T> ? T["infer"] | undefined : S extends ObjectType<infer P> ? ImpliedOptional<UndefinedToOptional<{
8
+ type InferInputSchema<S> = S extends DefaultType<infer T, unknown> ? InferInputSchema<T> | undefined : S extends OptionalType<infer T> ? InferInputSchema<T> | undefined : S extends ObjectType<infer P> ? ImpliedOptional<UndefinedToOptional<{
9
9
  [K in keyof P]: InferInputSchema<P[K]>;
10
10
  }>> : S extends Parsed<unknown> ? S["infer"] : S extends {
11
11
  [key: string]: Schema;
@@ -24,10 +24,9 @@ export default class JSONType extends Storable {
24
24
  }
25
25
  parse(u, options = {}) {
26
26
  const x = resolve(u);
27
- if (this.#inner !== undefined) {
28
- // delegate to inner schema for typed validation
27
+ // delegate to inner schema for typed validation
28
+ if (is.defined(this.#inner))
29
29
  return this.#inner.parse(x, options);
30
- }
31
30
  if (!is.json(x))
32
31
  throw E.invalid_type(x, "json", options);
33
32
  return JSON.parse(JSON.stringify(x));
@@ -36,7 +35,7 @@ export default class JSONType extends Storable {
36
35
  return {
37
36
  type: "json",
38
37
  datatype: "json",
39
- ...(this.#inner !== undefined && { of: this.#inner.toJSON() }),
38
+ ...is.defined(this.#inner) && { of: this.#inner.toJSON() },
40
39
  };
41
40
  }
42
41
  }
@@ -2,9 +2,9 @@ import DefaultType from "#DefaultType";
2
2
  import GenericType from "#GenericType";
3
3
  import type Infer from "#Infer";
4
4
  import Loose from "#Loose";
5
+ import type Mode from "#Mode";
5
6
  import OptionalType from "#OptionalType";
6
7
  import type ParseOptions from "#ParseOptions";
7
- import type Mode from "#Mode";
8
8
  type Literal = string | boolean | number;
9
9
  export default class LiteralType<T extends Literal, M extends Mode = undefined> extends GenericType<T, T, "LiteralType"> {
10
10
  #private;
@@ -14,7 +14,7 @@ export default abstract class NumericType<Key extends DataKey, T extends bigint
14
14
  #private;
15
15
  [Loose]: M;
16
16
  constructor(datatype: Key, mode?: M, validators?: Validator<T>[], options?: ParseOptions);
17
- derive(next: Next<T>): this;
17
+ with(next: Next<T>): this;
18
18
  values(anyof: Dict<T>): this;
19
19
  range(from: T, to: T): this;
20
20
  min(from: T): this;
@@ -12,21 +12,21 @@ export default class NumericType extends PrimitiveType {
12
12
  this.#datatype = datatype;
13
13
  this[Loose] = mode;
14
14
  }
15
- derive(next) {
15
+ with(next) {
16
16
  const Constructor = this.constructor;
17
17
  return new Constructor(this.#datatype, this[Loose], [...this.validators, ...next.validators ?? []], { ...this.options, ...next.options ?? {} });
18
18
  }
19
19
  values(anyof) {
20
- return this.derive({ validators: [values(anyof)] });
20
+ return this.with({ validators: [values(anyof)] });
21
21
  }
22
22
  range(from, to) {
23
- return this.derive({ validators: [range(from, to)] });
23
+ return this.with({ validators: [range(from, to)] });
24
24
  }
25
25
  min(from) {
26
- return this.derive({ validators: [min(from)] });
26
+ return this.with({ validators: [min(from)] });
27
27
  }
28
28
  max(to) {
29
- return this.derive({ validators: [max(to)] });
29
+ return this.with({ validators: [max(to)] });
30
30
  }
31
31
  get datatype() {
32
32
  return this.#datatype;
@@ -52,7 +52,7 @@ export default class ObjectType extends GenericType {
52
52
  }
53
53
  parse(u, options = {}) {
54
54
  const x = resolve(u);
55
- const $options = this[Loose] !== undefined
55
+ const $options = is.defined(this[Loose])
56
56
  ? { ...this.#options, ...options, [Loose]: this[Loose] }
57
57
  : { ...this.#options, ...options };
58
58
  if (is.defined(x) && !is.dict(x))
@@ -61,7 +61,7 @@ export default class ObjectType extends GenericType {
61
61
  const out = {};
62
62
  for (const k in this.#properties) {
63
63
  const parsed = this.#properties[k].parse(input[k], next(k, $options));
64
- if (parsed !== undefined)
64
+ if (is.defined(parsed))
65
65
  out[k] = parsed;
66
66
  }
67
67
  return out;
@@ -28,12 +28,11 @@ export default class OmitType extends GenericType {
28
28
  const props = this.#properties;
29
29
  for (const k in props) {
30
30
  const field = props[k];
31
- const r = field.parse(x[k], {
31
+ const parsed = field.parse(x[k], {
32
32
  ...options, [ParsedKey]: join(options[ParsedKey] ?? "", String(k)),
33
33
  });
34
- if (r !== undefined) {
35
- out[k] = r;
36
- }
34
+ if (is.defined(parsed))
35
+ out[k] = parsed;
37
36
  }
38
37
  return out;
39
38
  }
@@ -11,6 +11,7 @@ export default abstract class Parsed<StaticType> implements Serializable {
11
11
  [Loose]: boolean | undefined;
12
12
  [CoerceKey](x: unknown): unknown;
13
13
  abstract get name(): string;
14
+ derive<Output>(derive: (value: StaticType) => Output): Parsed<Output>;
14
15
  /**
15
16
  * Parse the given value.
16
17
  *
@@ -15,5 +15,26 @@ export default class Parsed {
15
15
  [CoerceKey](x) {
16
16
  return x;
17
17
  }
18
+ derive(derive) {
19
+ return new DerivedType(this, derive);
20
+ }
21
+ }
22
+ class DerivedType extends Parsed {
23
+ #schema;
24
+ #derive;
25
+ constructor(schema, derive) {
26
+ super();
27
+ this.#schema = schema;
28
+ this.#derive = derive;
29
+ }
30
+ get name() {
31
+ return this.#schema.name;
32
+ }
33
+ parse(u, options) {
34
+ return this.#derive(this.#schema.parse(u, options));
35
+ }
36
+ toJSON() {
37
+ return this.#schema.toJSON();
38
+ }
18
39
  }
19
40
  //# sourceMappingURL=Parsed.js.map
@@ -34,11 +34,11 @@ export default class PartialType extends VirtualType {
34
34
  const issues = [];
35
35
  for (const key of Object.keys(this.#spec)) {
36
36
  // skip missing/undefined keys (partial semantics)
37
- if (!(key in input) || input[key] === undefined)
37
+ if (!(key in input) || is.undefined(input[key]))
38
38
  continue;
39
39
  try {
40
40
  const parsed = this.#spec[key].parse(input[key], next(key, options));
41
- if (parsed !== undefined)
41
+ if (is.defined(parsed))
42
42
  out[key] = parsed;
43
43
  }
44
44
  catch (e) {
@@ -11,7 +11,7 @@ export default abstract class PrimitiveType<StaticType, Name extends string> ext
11
11
  constructor(validators?: Validator<StaticType>[], options?: ParseOptions);
12
12
  get options(): ParseOptions<unknown>;
13
13
  get validators(): Validator<StaticType>[];
14
- derive(next: Next<StaticType>): this;
14
+ with(next: Next<StaticType>): this;
15
15
  parse(u: unknown, options?: ParseOptions<StaticType>): Infer<this>;
16
16
  }
17
17
  export {};
@@ -5,6 +5,7 @@ import ParsedKey from "#ParsedKey";
5
5
  import ParseError from "#ParseError";
6
6
  import resolve from "#resolve";
7
7
  import Type from "#Type";
8
+ import is from "@rcompat/is";
8
9
  export default class PrimitiveType extends Type {
9
10
  #validators;
10
11
  #options;
@@ -19,14 +20,14 @@ export default class PrimitiveType extends Type {
19
20
  get validators() {
20
21
  return this.#validators;
21
22
  }
22
- derive(next) {
23
+ with(next) {
23
24
  const Constructor = this.constructor;
24
25
  return new Constructor([...this.#validators, ...next.validators ?? []], { ...this.#options, ...next.options ?? {} });
25
26
  }
26
27
  parse(u, options = {}) {
27
28
  const x = resolve(u);
28
29
  // hotpath: avoid object spread when possible
29
- const has_instance_options = this.#options[ParsedKey] !== undefined;
30
+ const has_instance_options = is.defined(this.#options[ParsedKey]);
30
31
  const $options = has_instance_options
31
32
  ? { ...this.#options, ...options }
32
33
  : options;
@@ -78,7 +78,8 @@ type StructuralSerialized = {
78
78
  properties: Dict<Serialized>;
79
79
  } | {
80
80
  type: "enum";
81
- values: string[];
81
+ datatype: "u8";
82
+ values: Dict<number>;
82
83
  } | {
83
84
  type: "pure";
84
85
  } | {
@@ -24,7 +24,7 @@ export default class StoreType extends ObjectType {
24
24
  if (k === this.#pk && !(k in input))
25
25
  continue;
26
26
  const parsed = this.properties[k].parse(input[k], next(k, $options));
27
- if (parsed !== undefined)
27
+ if (is.defined(parsed))
28
28
  out[k] = parsed;
29
29
  }
30
30
  return out;
@@ -17,32 +17,32 @@ export default class StringType extends PrimitiveType {
17
17
  return "string";
18
18
  }
19
19
  isotime() {
20
- return this.derive({ validators: [isotime] });
20
+ return this.with({ validators: [isotime] });
21
21
  }
22
22
  regex(pattern) {
23
- return this.derive({ validators: [regex(pattern)] });
23
+ return this.with({ validators: [regex(pattern)] });
24
24
  }
25
25
  email() {
26
- return this.derive({ validators: [email] });
26
+ return this.with({ validators: [email] });
27
27
  }
28
28
  startsWith(prefix) {
29
- return this.derive({ validators: [starts_with(prefix)] });
29
+ return this.with({ validators: [starts_with(prefix)] });
30
30
  }
31
31
  endsWith(suffix) {
32
- return this.derive({ validators: [ends_with(suffix)] });
32
+ return this.with({ validators: [ends_with(suffix)] });
33
33
  }
34
34
  min(limit) {
35
35
  if (limit < 0)
36
36
  throw E.min_negative(limit);
37
- return this.derive({ validators: [min(limit)] });
37
+ return this.with({ validators: [min(limit)] });
38
38
  }
39
39
  max(limit) {
40
40
  if (limit < 0)
41
41
  throw E.max_negative(limit);
42
- return this.derive({ validators: [max(limit)] });
42
+ return this.with({ validators: [max(limit)] });
43
43
  }
44
44
  length(from, to) {
45
- return this.derive({ validators: [length(from, to)] });
45
+ return this.with({ validators: [length(from, to)] });
46
46
  }
47
47
  toJSON() {
48
48
  return Storable.serialize(this);
@@ -23,7 +23,7 @@ export default class TupleType extends GenericType {
23
23
  const x = resolve(u);
24
24
  if (!is.array(x))
25
25
  throw E.invalid_type(x, "array", options);
26
- const $options = this[Loose] !== undefined
26
+ const $options = is.defined(this[Loose])
27
27
  ? { ...options, [Loose]: this[Loose] }
28
28
  : options;
29
29
  const items = this.#items;
@@ -12,7 +12,7 @@ export default class UintType extends NumericType {
12
12
  * Value is a non-privileged port number (1000 - 65535).
13
13
  */
14
14
  port() {
15
- return this.derive({ validators: [port] });
15
+ return this.with({ validators: [port] });
16
16
  }
17
17
  parse(u, options = {}) {
18
18
  return super.parse(u, {
@@ -1,10 +1,16 @@
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
+ declare const vanilla: <const S extends Schema>(of: S) => ArrayType<NormalizeSchema<S>>;
8
+ declare const loose: <const S extends Schema>(of: S) => ArrayType<NormalizeSchema<S>, true>;
9
+ declare const strict: <const S extends Schema>(of: S) => ArrayType<NormalizeSchema<S>, false>;
4
10
  declare const array: {
5
- strict: <const S extends Schema>(of: S) => ArrayType<NormalizeSchema<S>, false>;
6
- loose: <const S extends Schema>(of: S) => ArrayType<NormalizeSchema<S>, true>;
7
- vanilla: <const S extends Schema>(of: S) => ArrayType<NormalizeSchema<S>>;
11
+ strict: typeof strict;
12
+ loose: typeof loose;
13
+ vanilla: typeof vanilla;
8
14
  };
9
15
  export default array;
10
16
  //# sourceMappingURL=array.d.ts.map
@@ -0,0 +1,8 @@
1
+ import AsyncType from "#AsyncType";
2
+ import type { NormalizeSchemaObject } from "#NormalizeSchema";
3
+ import type ObjectType from "#ObjectType";
4
+ import type Schema from "#Schema";
5
+ import type { Dict } from "@rcompat/type";
6
+ declare function async_schema<const S extends Dict<Schema>>(schema: S): AsyncType<NormalizeSchemaObject<S>, undefined, ObjectType<NormalizeSchemaObject<S>>["infer"]>;
7
+ export default async_schema;
8
+ //# sourceMappingURL=async.d.ts.map
@@ -0,0 +1,7 @@
1
+ import AsyncType from "#AsyncType";
2
+ import normalize from "#normalize";
3
+ function async_schema(schema) {
4
+ return new AsyncType(normalize(schema));
5
+ }
6
+ export default async_schema;
7
+ //# sourceMappingURL=async.js.map
@@ -6,16 +6,14 @@ const ISO_DATETIME_TZ = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,3})
6
6
  const INT = /^[+-]?\d+$/;
7
7
  function epoch(n, digits) {
8
8
  // for strings we use digit-count to choose s vs ms.
9
- // for numbers we ALWAYS treat as ms (no digits provided)
10
- const ms = digits !== undefined
11
- ? (digits >= 13 ? n : n * 1000)
12
- : n;
9
+ // for numbers we always treat as ms (no digits provided)
10
+ const ms = is.defined(digits) ? (digits >= 13 ? n : n * 1000) : n;
13
11
  const date = new Date(ms);
14
12
  return Number.isNaN(date.getTime()) ? undefined : date;
15
13
  }
16
14
  function fromNumber(n) {
17
15
  const date = epoch(n);
18
- return date !== undefined ? date : n;
16
+ return is.defined(date) ? date : n;
19
17
  }
20
18
  function fromString(raw) {
21
19
  const s = raw.trim();
@@ -1,9 +1,15 @@
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 vanilla: <const C extends AbstractNewable>(c: C) => ConstructorType<C>;
7
+ declare const loose: <const C extends AbstractNewable>(c: C) => ConstructorType<C>;
8
+ declare const strict: <const C extends AbstractNewable>(c: C) => ConstructorType<C>;
3
9
  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>;
10
+ vanilla: typeof vanilla;
11
+ loose: typeof loose;
12
+ strict: typeof strict;
7
13
  };
8
14
  export default constructor;
9
15
  //# sourceMappingURL=constructor.d.ts.map
@@ -1,11 +1,12 @@
1
- import EnumType from "#EnumType";
2
- declare function vanilla<T extends readonly string[]>(values: T): EnumType<T>;
3
- declare function loose<T extends readonly string[]>(values: T): EnumType<T>;
4
- declare function strict<T extends readonly string[]>(values: T): EnumType<T>;
1
+ import { type Enum } from "#EnumType";
2
+ import type { Dict } from "@rcompat/type";
3
+ declare function vanilla<const V extends Dict<number>>(values: V): Enum<V, undefined>;
4
+ declare function loose<const V extends Dict<number>>(values: V): Enum<V, true>;
5
+ declare function strict<const V extends Dict<number>>(values: V): Enum<V, false>;
5
6
  declare const _default: {
7
+ vanilla: typeof vanilla;
6
8
  loose: typeof loose;
7
9
  strict: typeof strict;
8
- vanilla: typeof vanilla;
9
10
  };
10
11
  export default _default;
11
12
  //# sourceMappingURL=enum.d.ts.map
@@ -1,12 +1,13 @@
1
1
  import EnumType from "#EnumType";
2
+ import u8 from "#u8";
2
3
  function vanilla(values) {
3
- return new EnumType(values);
4
+ return new EnumType(values, u8.vanilla);
4
5
  }
5
6
  function loose(values) {
6
- return new EnumType(values);
7
+ return new EnumType(values, u8.loose);
7
8
  }
8
9
  function strict(values) {
9
- return new EnumType(values);
10
+ return new EnumType(values, u8.strict);
10
11
  }
11
- export default { loose, strict, vanilla };
12
+ export default { vanilla, loose, strict };
12
13
  //# sourceMappingURL=enum.js.map