pema 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,22 @@
1
+ import DefaultType from "#DefaultType";
1
2
  import GenericType from "#GenericType";
2
3
  import type Infer from "#Infer";
3
4
  import OptionalType from "#OptionalType";
4
5
  import type Parsed from "#Parsed";
5
6
  import type ParseOptions from "#ParseOptions";
7
+ import type DefaultTrait from "#trait/Default";
6
8
  import type OptionalTrait from "#trait/Optional";
7
9
  import type Validator from "#Validator";
8
10
  import type Primitive from "@rcompat/type/Primitive";
9
11
  type Next<T> = {
10
12
  validators?: Validator<T>[];
11
13
  };
12
- export default class ArrayType<T extends Parsed<unknown>> extends GenericType<T, Infer<T>[], "ArrayType"> implements OptionalTrait {
14
+ export default class ArrayType<T extends Parsed<unknown>> extends GenericType<T, Infer<T>[], "ArrayType"> implements OptionalTrait, DefaultTrait<Infer<T>[]> {
13
15
  #private;
14
16
  constructor(item: T, validators?: Validator<Array<Infer<T>>>[]);
15
17
  get name(): "array";
16
18
  optional(): OptionalType<this>;
19
+ default(value: (() => Infer<T>[]) | Infer<T>[]): DefaultType<this, Infer<T>[]>;
17
20
  derive(_next: Next<Array<Infer<T>>>): this;
18
21
  /**
19
22
  * Member values are unique — only for primitive subtypes.
@@ -1,3 +1,4 @@
1
+ import DefaultType from "#DefaultType";
1
2
  import error from "#error";
2
3
  import schemafail from "#error/schemafail";
3
4
  import GenericType from "#GenericType";
@@ -30,6 +31,9 @@ export default class ArrayType extends GenericType {
30
31
  optional() {
31
32
  return new OptionalType(this);
32
33
  }
34
+ default(value) {
35
+ return new DefaultType(this, value);
36
+ }
33
37
  derive(_next) {
34
38
  const Constructor = this.constructor;
35
39
  return new Constructor(this.#item, [...this.#validators, ..._next.validators ?? []]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pema",
3
- "version": "0.2.0",
3
+ "version": "0.2.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",