pema 0.8.3 → 0.9.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.
Files changed (40) 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/JSONType.js +3 -4
  8. package/lib/private/LiteralType.d.ts +1 -1
  9. package/lib/private/NumericType.d.ts +1 -1
  10. package/lib/private/NumericType.js +5 -5
  11. package/lib/private/ObjectType.js +2 -2
  12. package/lib/private/OmitType.js +3 -4
  13. package/lib/private/Parsed.d.ts +1 -0
  14. package/lib/private/Parsed.js +21 -0
  15. package/lib/private/PartialType.js +2 -2
  16. package/lib/private/PrimitiveType.d.ts +1 -1
  17. package/lib/private/PrimitiveType.js +3 -2
  18. package/lib/private/Serialized.d.ts +2 -1
  19. package/lib/private/StoreType.js +1 -1
  20. package/lib/private/StringType.js +8 -8
  21. package/lib/private/TupleType.js +1 -1
  22. package/lib/private/UintType.js +1 -1
  23. package/lib/private/array.d.ts +9 -3
  24. package/lib/private/async.d.ts +8 -0
  25. package/lib/private/async.js +7 -0
  26. package/lib/private/coerce/date.js +3 -5
  27. package/lib/private/constructor.d.ts +9 -3
  28. package/lib/private/enum.d.ts +6 -5
  29. package/lib/private/enum.js +5 -4
  30. package/lib/private/index.d.ts +114 -5
  31. package/lib/private/index.js +94 -90
  32. package/lib/private/is.d.ts +6 -3
  33. package/lib/private/normalize.js +2 -2
  34. package/lib/private/path/next.d.ts +2 -1
  35. package/lib/private/path/next.js +4 -2
  36. package/lib/private/record.d.ts +9 -3
  37. package/lib/private/schema-errors.d.ts +1 -0
  38. package/lib/private/schema-errors.js +1 -0
  39. package/lib/private/test.js +4 -3
  40. 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
@@ -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
@@ -1,4 +1,5 @@
1
1
  export type { default as ArrayType } from "#ArrayType";
2
+ export type { default as AsyncType } from "#AsyncType";
2
3
  export type { default as BlobType } from "#BlobType";
3
4
  export type { default as BooleanType } from "#BooleanType";
4
5
  export type { default as ConstructorType } from "#ConstructorType";
@@ -6,7 +7,7 @@ export type { default as DataKey } from "#DataKey";
6
7
  export type { default as DataType } from "#DataType";
7
8
  export type { default as DateType } from "#DateType";
8
9
  export type { default as DefaultType } from "#DefaultType";
9
- export type { default as EnumType } from "#EnumType";
10
+ export type { Enum, default as EnumType } from "#EnumType";
10
11
  export type { default as FunctionType } from "#FunctionType";
11
12
  export type { default as Id } from "#Id";
12
13
  export type { default as InferStore } from "#InferStore";
@@ -16,7 +17,7 @@ export type { default as IsType } from "#IsType";
16
17
  export type { default as JSONPayload } from "#json/JSONPayload";
17
18
  export type { default as JSONType } from "#JSONType";
18
19
  export type { default as LiteralType } from "#LiteralType";
19
- export type { default as NormalizeSchema, NormalizeSchemaObject, } from "#NormalizeSchema";
20
+ export type { default as NormalizeSchema, NormalizeSchemaObject } from "#NormalizeSchema";
20
21
  export type { default as NullType } from "#NullType";
21
22
  export type { default as NumberType } from "#NumberType";
22
23
  export type { default as ObjectType } from "#ObjectType";
@@ -40,6 +41,7 @@ export type { default as URLType } from "#URLType";
40
41
  export type { default as UUIDType } from "#UUIDType";
41
42
  export type { default as UUIDV4Type } from "#UUIDV4Type";
42
43
  export type { default as UUIDV7Type } from "#UUIDV7Type";
44
+ import async_schema from "#async";
43
45
  import type NormalizeSchema from "#NormalizeSchema";
44
46
  import type Schema from "#Schema";
45
47
  /**
@@ -49,6 +51,7 @@ declare function schema<const S extends Schema>(s: S): NormalizeSchema<S>;
49
51
  declare namespace schema {
50
52
  var _a: <const S extends Schema>(of: S) => import("#ArrayType").default<NormalizeSchema<S>>;
51
53
  export { _a as array };
54
+ export { async_schema as async };
52
55
  export var _b: import("./BigIntType.js").default<"i64", undefined>;
53
56
  export { _b as bigint };
54
57
  export var _c: import("./BigUintType.js").default<"u64", undefined>;
@@ -66,7 +69,7 @@ declare namespace schema {
66
69
  <const Value extends import("#Parsed").default<unknown>>(of: Value): import("#RecordType").default<import("#StringType").default, Value>;
67
70
  };
68
71
  export { _h as dict };
69
- export var _j: <T extends readonly string[]>(values: T) => import("#EnumType").default<T>;
72
+ export var _j: <const V extends import("@rcompat/type").Dict<number>>(values: V) => import("#EnumType").Enum<V, undefined>;
70
73
  export { _j as enum };
71
74
  export var _k: import("#NumberType").default<"f32", undefined>;
72
75
  export { _k as f32 };
@@ -146,7 +149,113 @@ declare namespace schema {
146
149
  export { loose };
147
150
  export { strict };
148
151
  }
149
- declare function loose<const S extends Schema>(s: S): NormalizeSchema<S>;
150
- declare function strict<const S extends Schema>(s: S): NormalizeSchema<S>;
152
+ declare const loose: (<const S extends Schema>(s: S) => NormalizeSchema<S>) & {
153
+ array: <const S extends Schema>(of: S) => import("#ArrayType").default<NormalizeSchema<S>, true>;
154
+ bigint: import("./BigIntType.js").default<"i64", true>;
155
+ biguint: import("./BigUintType.js").default<"u64", true>;
156
+ blob: import("#BlobType").default;
157
+ boolean: import("#BooleanType").default<true>;
158
+ constructor: <const C extends import("@rcompat/type").AbstractNewable>(c: C) => import("#ConstructorType").default<C>;
159
+ date: import("#DateType").default<true>;
160
+ dict: {
161
+ (): import("#RecordType").default<import("#StringType").default, import("#StringType").default, true>;
162
+ <const Value extends import("#Parsed").default<unknown>>(of: Value): import("#RecordType").default<import("#StringType").default, Value, true>;
163
+ };
164
+ enum: <const V extends import("@rcompat/type").Dict<number>>(values: V) => import("#EnumType").Enum<V, true>;
165
+ f32: import("#NumberType").default<"f32", true>;
166
+ f64: import("#NumberType").default<"f64", true>;
167
+ file: import("./FileType.js").default;
168
+ function: import("#FunctionType").default;
169
+ i128: import("./BigIntType.js").default<"i128", true>;
170
+ i16: import("./IntType.js").default<"i16", true>;
171
+ i32: import("./IntType.js").default<"i32", true>;
172
+ i64: import("./BigIntType.js").default<"i64", true>;
173
+ i8: import("./IntType.js").default<"i8", true>;
174
+ int: import("./IntType.js").default<"i32", true>;
175
+ is: <T>(predicate: (x: unknown) => x is T) => import("#IsType").default<T>;
176
+ json: {
177
+ (): import("#JSONType").default<undefined>;
178
+ <S extends import("#JSONType").ParsedJSON>(inner: S): import("#JSONType").default<S>;
179
+ };
180
+ literal: <T extends string | number | boolean>(literal: T) => import("#LiteralType").default<T, true>;
181
+ null: import("#NullType").default;
182
+ number: import("#NumberType").default<"f64", true>;
183
+ object: <P extends import("@rcompat/type").Dict<Schema> = import("@rcompat/type").Dict<Schema>>(properties: P) => import("#ObjectType").default<keyof P extends never ? {} : { [K in keyof P]: NormalizeSchema<P[K]>; }, true>;
184
+ omit: <P extends import("@rcompat/type").Dict<import("#Parsed").default<unknown>>, K extends keyof P>(type: import("#ObjectType").default<P>, ...keys: K[]) => import("./OmitType.js").default<P, K, true>;
185
+ record: <const Key extends import("./RecordTypeKey.js").default, const Value extends import("#Parsed").default<unknown>>(k: Key, v: Value) => import("#RecordType").default<Key, Value, true>;
186
+ partial: <const D extends import("./Partialable.js").default>(input: D | import("#ObjectType").default<D>) => import("#PartialType").default<{ -readonly [K in keyof D]: D[K]; }, true>;
187
+ pure: <T>() => import("#PureType").default<T, "PureType">;
188
+ string: import("#StringType").default;
189
+ symbol: import("./SymbolType.js").default;
190
+ tuple: <const T extends Schema[]>(...items: T) => import("#TupleType").default<{ [K in keyof T]: NormalizeSchema<T[K]>; }, true>;
191
+ u128: import("./BigUintType.js").default<"u128", true>;
192
+ u16: import("#UintType").default<"u16", true>;
193
+ u32: import("#UintType").default<"u32", true>;
194
+ u64: import("./BigUintType.js").default<"u64", true>;
195
+ u8: import("#UintType").default<"u8", true>;
196
+ uint: import("#UintType").default<"u32", true>;
197
+ undefined: import("#UndefinedType").default;
198
+ union: {
199
+ (): import("#UnionType").default<[], true>;
200
+ <const T extends Schema[]>(...types: T): import("#UnionType").default<{ [K in keyof T]: NormalizeSchema<T[K]>; }, true>;
201
+ };
202
+ unknown: import("#UnknownType").default;
203
+ url: import("#URLType").default<true>;
204
+ uuid: import("#UUIDType").default;
205
+ };
206
+ declare const strict: (<const S extends Schema>(s: S) => NormalizeSchema<S>) & {
207
+ array: <const S extends Schema>(of: S) => import("#ArrayType").default<NormalizeSchema<S>, false>;
208
+ bigint: import("./BigIntType.js").default<"i64", false>;
209
+ biguint: import("./BigUintType.js").default<"u64", false>;
210
+ blob: import("#BlobType").default;
211
+ boolean: import("#BooleanType").default<false>;
212
+ constructor: <const C extends import("@rcompat/type").AbstractNewable>(c: C) => import("#ConstructorType").default<C>;
213
+ date: import("#DateType").default<false>;
214
+ dict: {
215
+ (): import("#RecordType").default<import("#StringType").default, import("#StringType").default, false>;
216
+ <const Value extends import("#Parsed").default<unknown>>(of: Value): import("#RecordType").default<import("#StringType").default, Value, false>;
217
+ };
218
+ enum: <const V extends import("@rcompat/type").Dict<number>>(values: V) => import("#EnumType").Enum<V, false>;
219
+ f32: import("#NumberType").default<"f32", false>;
220
+ f64: import("#NumberType").default<"f64", false>;
221
+ file: import("./FileType.js").default;
222
+ function: import("#FunctionType").default;
223
+ i128: import("./BigIntType.js").default<"i128", false>;
224
+ i16: import("./IntType.js").default<"i16", false>;
225
+ i32: import("./IntType.js").default<"i32", false>;
226
+ i64: import("./BigIntType.js").default<"i64", false>;
227
+ i8: import("./IntType.js").default<"i8", false>;
228
+ int: import("./IntType.js").default<"i32", false>;
229
+ is: <T>(predicate: (x: unknown) => x is T) => import("#IsType").default<T>;
230
+ json: {
231
+ (): import("#JSONType").default<undefined>;
232
+ <S extends import("#JSONType").ParsedJSON>(inner: S): import("#JSONType").default<S>;
233
+ };
234
+ literal: <T extends string | number | boolean>(literal: T) => import("#LiteralType").default<T, false>;
235
+ null: import("#NullType").default;
236
+ number: import("#NumberType").default<"f64", false>;
237
+ object: <P extends import("@rcompat/type").Dict<Schema> = import("@rcompat/type").Dict<Schema>>(properties: P) => import("#ObjectType").default<keyof P extends never ? {} : { [K in keyof P]: NormalizeSchema<P[K]>; }, false>;
238
+ omit: <P extends import("@rcompat/type").Dict<import("#Parsed").default<unknown>>, K extends keyof P>(type: import("#ObjectType").default<P>, ...keys: K[]) => import("./OmitType.js").default<P, K, false>;
239
+ record: <const Key extends import("./RecordTypeKey.js").default, const Value extends import("#Parsed").default<unknown>>(k: Key, v: Value) => import("#RecordType").default<Key, Value, false>;
240
+ partial: <const D extends import("./Partialable.js").default>(input: D | import("#ObjectType").default<D>) => import("#PartialType").default<{ -readonly [K in keyof D]: D[K]; }, false>;
241
+ pure: <T>() => import("#PureType").default<T, "PureType">;
242
+ string: import("#StringType").default;
243
+ symbol: import("./SymbolType.js").default;
244
+ tuple: <const T extends Schema[]>(...items: T) => import("#TupleType").default<{ [K in keyof T]: NormalizeSchema<T[K]>; }, false>;
245
+ u128: import("./BigUintType.js").default<"u128", false>;
246
+ u16: import("#UintType").default<"u16", false>;
247
+ u32: import("#UintType").default<"u32", false>;
248
+ u64: import("./BigUintType.js").default<"u64", false>;
249
+ u8: import("#UintType").default<"u8", false>;
250
+ uint: import("#UintType").default<"u32", false>;
251
+ undefined: import("#UndefinedType").default;
252
+ union: {
253
+ (): import("#UnionType").default<[], false>;
254
+ <const T extends Schema[]>(...types: T): import("#UnionType").default<{ [K in keyof T]: NormalizeSchema<T[K]>; }, false>;
255
+ };
256
+ unknown: import("#UnknownType").default;
257
+ url: import("#URLType").default<false>;
258
+ uuid: import("#UUIDType").default;
259
+ };
151
260
  export default schema;
152
261
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,6 @@
1
1
  import E from "#errors";
2
2
  import array from "#array";
3
+ import async_schema from "#async";
3
4
  import bigint from "#bigint";
4
5
  import biguint from "#biguint";
5
6
  import blob from "#blob";
@@ -50,17 +51,106 @@ import uuid from "#uuid";
50
51
  function schema(s) {
51
52
  return normalize(s);
52
53
  }
53
- function loose(s) {
54
+ const loose = Object.assign(function loose(s) {
54
55
  const i = normalize(s);
55
56
  i[Loose] = true;
56
57
  return i;
57
- }
58
- function strict(s) {
58
+ }, {
59
+ array: array.loose,
60
+ bigint: bigint.loose,
61
+ biguint: biguint.loose,
62
+ blob: blob.loose,
63
+ boolean: boolean.loose,
64
+ constructor: constructor.loose,
65
+ date: date.loose,
66
+ dict: dict.loose,
67
+ enum: enum$.loose,
68
+ f32: f32.loose,
69
+ f64: f64.loose,
70
+ file: file.loose,
71
+ function: function$.loose,
72
+ i128: i128.loose,
73
+ i16: i16.loose,
74
+ i32: i32.loose,
75
+ i64: i64.loose,
76
+ i8: i8.loose,
77
+ int: int.loose,
78
+ is: is.loose,
79
+ json: json.loose,
80
+ literal: literal.loose,
81
+ null: null$.loose,
82
+ number: number.loose,
83
+ object: object.loose,
84
+ omit: omit.loose,
85
+ record: record.loose,
86
+ partial: partial.loose,
87
+ pure: pure.loose,
88
+ string: string.loose,
89
+ symbol: symbol.loose,
90
+ tuple: tuple.loose,
91
+ u128: u128.loose,
92
+ u16: u16.loose,
93
+ u32: u32.loose,
94
+ u64: u64.loose,
95
+ u8: u8.loose,
96
+ uint: uint.loose,
97
+ undefined: undefined$.loose,
98
+ union: union.loose,
99
+ unknown: unknown.loose,
100
+ url: url.loose,
101
+ uuid: uuid.loose,
102
+ });
103
+ const strict = Object.assign(function strict(s) {
59
104
  const i = normalize(s);
60
105
  i[Loose] = false;
61
106
  return i;
62
- }
107
+ }, {
108
+ array: array.strict,
109
+ bigint: bigint.strict,
110
+ biguint: biguint.strict,
111
+ blob: blob.strict,
112
+ boolean: boolean.strict,
113
+ constructor: constructor.strict,
114
+ date: date.strict,
115
+ dict: dict.strict,
116
+ enum: enum$.strict,
117
+ f32: f32.strict,
118
+ f64: f64.strict,
119
+ file: file.strict,
120
+ function: function$.strict,
121
+ i128: i128.strict,
122
+ i16: i16.strict,
123
+ i32: i32.strict,
124
+ i64: i64.strict,
125
+ i8: i8.strict,
126
+ int: int.strict,
127
+ is: is.strict,
128
+ json: json.strict,
129
+ literal: literal.strict,
130
+ null: null$.strict,
131
+ number: number.strict,
132
+ object: object.strict,
133
+ omit: omit.strict,
134
+ record: record.strict,
135
+ partial: partial.strict,
136
+ pure: pure.strict,
137
+ string: string.strict,
138
+ symbol: symbol.strict,
139
+ tuple: tuple.strict,
140
+ u128: u128.strict,
141
+ u16: u16.strict,
142
+ u32: u32.strict,
143
+ u64: u64.strict,
144
+ u8: u8.strict,
145
+ uint: uint.strict,
146
+ undefined: undefined$.strict,
147
+ union: union.strict,
148
+ unknown: unknown.strict,
149
+ url: url.strict,
150
+ uuid: uuid.strict,
151
+ });
63
152
  schema.array = array.vanilla;
153
+ schema.async = async_schema;
64
154
  schema.bigint = bigint.vanilla;
65
155
  schema.biguint = biguint.vanilla;
66
156
  schema.blob = blob.vanilla;
@@ -104,92 +194,6 @@ schema.unknown = unknown.vanilla;
104
194
  schema.url = url.vanilla;
105
195
  schema.uuid = uuid.vanilla;
106
196
  schema.error = E.field;
107
- loose.array = array.loose;
108
- loose.bigint = bigint.loose;
109
- loose.biguint = biguint.loose;
110
- loose.blob = blob.loose;
111
- loose.boolean = boolean.loose;
112
- loose.constructor = constructor.loose;
113
- loose.date = date.loose;
114
- loose.dict = dict.loose;
115
- loose.enum = enum$.loose;
116
- loose.f32 = f32.loose;
117
- loose.f64 = f64.loose;
118
- loose.file = file.loose;
119
- loose.function = function$.loose;
120
- loose.i128 = i128.loose;
121
- loose.i16 = i16.loose;
122
- loose.i32 = i32.loose;
123
- loose.i64 = i64.loose;
124
- loose.i8 = i8.loose;
125
- loose.int = int.loose;
126
- loose.is = is.loose;
127
- loose.json = json.loose;
128
- loose.literal = literal.loose;
129
- loose.null = null$.loose;
130
- loose.number = number.loose;
131
- loose.object = object.loose;
132
- loose.omit = omit.loose;
133
- loose.record = record.loose;
134
- loose.partial = partial.loose;
135
- loose.pure = pure.loose;
136
- loose.string = string.loose;
137
- loose.symbol = symbol.loose;
138
- loose.tuple = tuple.loose;
139
- loose.u128 = u128.loose;
140
- loose.u16 = u16.loose;
141
- loose.u32 = u32.loose;
142
- loose.u64 = u64.loose;
143
- loose.u8 = u8.loose;
144
- loose.uint = uint.loose;
145
- loose.undefined = undefined$.loose;
146
- loose.union = union.loose;
147
- loose.unknown = unknown.loose;
148
- loose.url = url.loose;
149
- loose.uuid = uuid.loose;
150
- strict.array = array.strict;
151
- strict.bigint = bigint.strict;
152
- strict.biguint = biguint.strict;
153
- strict.blob = blob.strict;
154
- strict.boolean = boolean.strict;
155
- strict.constructor = constructor.strict;
156
- strict.date = date.strict;
157
- strict.dict = dict.strict;
158
- strict.enum = enum$.strict;
159
- strict.f32 = f32.strict;
160
- strict.f64 = f64.strict;
161
- strict.file = file.strict;
162
- strict.function = function$.strict;
163
- strict.i128 = i128.strict;
164
- strict.i16 = i16.strict;
165
- strict.i32 = i32.strict;
166
- strict.i64 = i64.strict;
167
- strict.i8 = i8.strict;
168
- strict.int = int.strict;
169
- strict.is = is.strict;
170
- strict.json = json.strict;
171
- strict.literal = literal.strict;
172
- strict.null = null$.strict;
173
- strict.number = number.strict;
174
- strict.object = object.strict;
175
- strict.omit = omit.strict;
176
- strict.record = record.strict;
177
- strict.partial = partial.strict;
178
- strict.pure = pure.strict;
179
- strict.string = string.strict;
180
- strict.symbol = symbol.strict;
181
- strict.tuple = tuple.strict;
182
- strict.u128 = u128.strict;
183
- strict.u16 = u16.strict;
184
- strict.u32 = u32.strict;
185
- strict.u64 = u64.strict;
186
- strict.u8 = u8.strict;
187
- strict.uint = uint.strict;
188
- strict.undefined = undefined$.strict;
189
- strict.union = union.strict;
190
- strict.unknown = unknown.strict;
191
- strict.url = url.strict;
192
- strict.uuid = uuid.strict;
193
197
  schema.loose = loose;
194
198
  schema.strict = strict;
195
199
  export default schema;
@@ -1,8 +1,11 @@
1
1
  import IsType from "#IsType";
2
+ declare const vanilla: <T>(predicate: (x: unknown) => x is T) => IsType<T>;
3
+ declare const loose: <T>(predicate: (x: unknown) => x is T) => IsType<T>;
4
+ declare const strict: <T>(predicate: (x: unknown) => x is T) => IsType<T>;
2
5
  declare const is: {
3
- vanilla: <T>(predicate: (x: unknown) => x is T) => IsType<T>;
4
- loose: <T>(predicate: (x: unknown) => x is T) => IsType<T>;
5
- strict: <T>(predicate: (x: unknown) => x is T) => IsType<T>;
6
+ vanilla: typeof vanilla;
7
+ loose: typeof loose;
8
+ strict: typeof strict;
6
9
  };
7
10
  export default is;
8
11
  //# sourceMappingURL=is.d.ts.map
@@ -10,9 +10,9 @@ import is from "@rcompat/is";
10
10
  export default function normalize(x) {
11
11
  if (is_parsed(x))
12
12
  return x;
13
- if (x === null)
13
+ if (is.null(x))
14
14
  return new NullType();
15
- if (x === undefined)
15
+ if (is.undefined(x))
16
16
  return new UndefinedType();
17
17
  if (is.string(x) || is.number(x) || is.boolean(x))
18
18
  return new LiteralType(x);
@@ -1,3 +1,4 @@
1
1
  import type ParseOptions from "#ParseOptions";
2
- export default function next(s: number | string, options?: ParseOptions): ParseOptions;
2
+ declare function next(s: number | string, options?: ParseOptions): ParseOptions;
3
+ export default next;
3
4
  //# sourceMappingURL=next.d.ts.map
@@ -1,9 +1,11 @@
1
1
  import ParsedKey from "#ParsedKey";
2
2
  import join from "#path/join";
3
- export default function next(s, options) {
3
+ import is from "@rcompat/is";
4
+ function next(s, options) {
4
5
  const base = options?.[ParsedKey] ?? "";
5
- return options === undefined
6
+ return is.undefined(options)
6
7
  ? { [ParsedKey]: join("", String(s)) }
7
8
  : { ...options, [ParsedKey]: join(base, String(s)) };
8
9
  }
10
+ export default next;
9
11
  //# sourceMappingURL=next.js.map
@@ -1,10 +1,16 @@
1
1
  import type Parsed from "#Parsed";
2
2
  import RecordType from "#RecordType";
3
3
  import type RecordTypeKey from "#RecordTypeKey";
4
+ /**
5
+ * Value is a record of the given key and value types.
6
+ */
7
+ declare const vanilla: <const Key extends RecordTypeKey, const Value extends Parsed<unknown>>(k: Key, v: Value) => RecordType<Key, Value, undefined>;
8
+ declare const loose: <const Key extends RecordTypeKey, const Value extends Parsed<unknown>>(k: Key, v: Value) => RecordType<Key, Value, true>;
9
+ declare const strict: <const Key extends RecordTypeKey, const Value extends Parsed<unknown>>(k: Key, v: Value) => RecordType<Key, Value, false>;
4
10
  declare const record: {
5
- vanilla: <const Key extends RecordTypeKey, const Value extends Parsed<unknown>>(k: Key, v: Value) => RecordType<Key, Value, undefined>;
6
- loose: <const Key extends RecordTypeKey, const Value extends Parsed<unknown>>(k: Key, v: Value) => RecordType<Key, Value, true>;
7
- strict: <const Key extends RecordTypeKey, const Value extends Parsed<unknown>>(k: Key, v: Value) => RecordType<Key, Value, false>;
11
+ vanilla: typeof vanilla;
12
+ loose: typeof loose;
13
+ strict: typeof strict;
8
14
  };
9
15
  export default record;
10
16
  //# sourceMappingURL=record.d.ts.map
@@ -9,6 +9,7 @@ declare const errors: {
9
9
  max_limit_not_finite: (limit: number) => import("@rcompat/error").TemplateError;
10
10
  extend_key_collision: (key: string) => import("@rcompat/error").TemplateError;
11
11
  union_at_least_two_members: () => import("@rcompat/error").TemplateError;
12
+ enum_invalid_key: (key: string) => import("@rcompat/error").TemplateError;
12
13
  };
13
14
  export type Code = keyof typeof errors;
14
15
  export declare const Code: { [K in Code]: K; };
@@ -11,6 +11,7 @@ const errors = error.coded({
11
11
  max_limit_not_finite: (limit) => t `max: limit ${limit} must be a finite number`,
12
12
  extend_key_collision: (key) => t `extend: key ${key} already exists and cannot be overridden`,
13
13
  union_at_least_two_members: () => t `union type must have at least two members`,
14
+ enum_invalid_key: (key) => t `enum: key ${key} must be SCREAMING_SNAKE_CASE`,
14
15
  });
15
16
  export const Code = Object.fromEntries(Object.keys(errors).map(k => [k, k]));
16
17
  export default errors;
@@ -1,4 +1,5 @@
1
1
  import ParseError from "#ParseError";
2
+ import is from "@rcompat/is";
2
3
  import test from "@rcompat/test";
3
4
  const issue_types = [
4
5
  "invalid_type",
@@ -20,7 +21,7 @@ export default test.extend((assert, subject) => {
20
21
  if (ParseError.is(e)) {
21
22
  const issue = e.issues[0];
22
23
  assert(issue.type).equals(type);
23
- if (path !== undefined)
24
+ if (is.defined(path))
24
25
  assert(issue.path).equals(path);
25
26
  }
26
27
  else {
@@ -44,10 +45,10 @@ export default test.extend((assert, subject) => {
44
45
  assert(e.issues.length).equals(matchers.length);
45
46
  for (let i = 0; i < matchers.length; i++) {
46
47
  assert(e.issues[i].type).equals(matchers[i].type);
47
- if (matchers[i].path !== undefined) {
48
+ if (is.defined(matchers[i].path)) {
48
49
  assert(e.issues[i].path).equals(matchers[i].path);
49
50
  }
50
- if (matchers[i].message !== undefined) {
51
+ if (is.defined(matchers[i].message)) {
51
52
  assert(e.issues[i].message).equals(matchers[i].message);
52
53
  }
53
54
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pema",
3
- "version": "0.8.3",
3
+ "version": "0.9.1",
4
4
  "description": "Primate schema validation",
5
5
  "homepage": "https://primate.run/docs/validation",
6
6
  "bugs": "https://github.com/primate-run/primate/issues",
@@ -17,14 +17,14 @@
17
17
  "!/**/*.spec.*"
18
18
  ],
19
19
  "dependencies": {
20
- "@rcompat/assert": "^0.13.0",
21
- "@rcompat/cli": "^0.24.0",
22
- "@rcompat/error": "^0.8.0",
23
- "@rcompat/is": "^0.11.0",
24
- "@rcompat/symbol": "^0.2.0"
20
+ "@rcompat/assert": "^0.14.0",
21
+ "@rcompat/cli": "^0.25.0",
22
+ "@rcompat/error": "^0.9.0",
23
+ "@rcompat/is": "^0.12.0",
24
+ "@rcompat/symbol": "^0.3.0"
25
25
  },
26
26
  "devDependencies": {
27
- "@rcompat/type": "^0.17.0"
27
+ "@rcompat/type": "^0.18.0"
28
28
  },
29
29
  "imports": {
30
30
  "#*": {
@@ -43,7 +43,7 @@
43
43
  }
44
44
  },
45
45
  "scripts": {
46
- "build": "npm run clean && tsgo",
46
+ "build": "npm run clean && tsc",
47
47
  "clean": "rm -rf ./lib",
48
48
  "lint": "eslint .",
49
49
  "lint:fix": "eslint . --fix",