shelving 1.159.0 → 1.159.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.159.0",
14
+ "version": "1.159.2",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -46,7 +46,7 @@ export declare class ArraySchema<T> extends Schema<ImmutableArray<T>> {
46
46
  readonly unique: boolean;
47
47
  readonly min: number;
48
48
  readonly max: number;
49
- constructor({ items, one, many, unique, min, max, title, value, ...options }: ArraySchemaOptions<T>);
49
+ constructor({ items, one, many, title, placeholder, unique, min, max, value, ...options }: ArraySchemaOptions<T>);
50
50
  validate(unsafeValue?: unknown): ImmutableArray<T>;
51
51
  }
52
52
  /** Valid array with specifed items. */
@@ -36,8 +36,8 @@ export class ArraySchema extends Schema {
36
36
  unique;
37
37
  min;
38
38
  max;
39
- constructor({ items, one = "item", many = `${one}s`, unique = false, min = 0, max = Number.POSITIVE_INFINITY, title = "Items", value = [], ...options }) {
40
- super({ title, value, ...options });
39
+ constructor({ items, one = "item", many = `${one}s`, title = "Items", placeholder = `No ${many}`, unique = false, min = 0, max = Number.POSITIVE_INFINITY, value = [], ...options }) {
40
+ super({ title, placeholder, value, ...options });
41
41
  this.one = one;
42
42
  this.many = many;
43
43
  this.items = items;
@@ -51,9 +51,9 @@ export class ArraySchema extends Schema {
51
51
  const validArray = validateArray(unsafeValue, this.items);
52
52
  const uniqueArray = this.unique ? getUniqueArray(validArray) : validArray;
53
53
  if (uniqueArray.length < this.min)
54
- throw new ValueFeedback(uniqueArray.length ? `Minimum ${this.min} items` : "Required", uniqueArray);
54
+ throw new ValueFeedback(uniqueArray.length ? `Minimum ${this.min} ${this.many}` : "Required", uniqueArray);
55
55
  if (uniqueArray.length > this.max)
56
- throw new ValueFeedback(`Maximum ${this.max} items`, uniqueArray);
56
+ throw new ValueFeedback(`Maximum ${this.max} ${this.many}`, uniqueArray);
57
57
  return uniqueArray;
58
58
  }
59
59
  }
@@ -14,15 +14,15 @@ export declare function isOption<K extends string>(options: ChoiceOptions<K>, op
14
14
  /** Allowed options for `ChoiceSchema` */
15
15
  export interface ChoiceSchemaOptions<K extends string> extends Omit<SchemaOptions, "value"> {
16
16
  /** Specify correct options using a dictionary of entries. */
17
- options: ChoiceOptions<K>;
17
+ readonly options: ChoiceOptions<K>;
18
18
  /** Default option for the value. */
19
- value?: K;
19
+ readonly value?: K;
20
20
  }
21
21
  /** Choose from an allowed set of values. */
22
22
  export declare class ChoiceSchema<K extends string> extends Schema<K> implements Iterable<ChoiceOption<K>> {
23
23
  readonly value: K;
24
24
  readonly options: ChoiceOptions<K>;
25
- constructor({ options, value, ...rest }: ChoiceSchemaOptions<K>);
25
+ constructor({ options, placeholder, value, ...rest }: ChoiceSchemaOptions<K>);
26
26
  validate(unsafeValue?: unknown): K;
27
27
  [Symbol.iterator](): Iterator<ChoiceOption<K>>;
28
28
  keys(): ImmutableArray<K>;
@@ -20,8 +20,8 @@ export function isOption(options, option) {
20
20
  /** Choose from an allowed set of values. */
21
21
  export class ChoiceSchema extends Schema {
22
22
  options;
23
- constructor({ options, value = requireFirst(isArray(options) ? options : getKeys(options)), ...rest }) {
24
- super({ value, ...rest });
23
+ constructor({ options, placeholder = "Empty", value = requireFirst(isArray(options) ? options : getKeys(options)), ...rest }) {
24
+ super({ value, placeholder, ...rest });
25
25
  this.options = options;
26
26
  }
27
27
  validate(unsafeValue = this.value) {
@@ -18,7 +18,7 @@ export declare class DictionarySchema<T> extends Schema<ImmutableDictionary<T>>
18
18
  readonly items: Schema<T>;
19
19
  readonly min: number;
20
20
  readonly max: number;
21
- constructor({ items, one, many, min, max, title, value, ...options }: DictionarySchemaOptions<T>);
21
+ constructor({ items, one, many, placeholder, min, max, title, value, ...options }: DictionarySchemaOptions<T>);
22
22
  validate(unsafeValue?: unknown): ImmutableDictionary<T>;
23
23
  }
24
24
  /** Valid dictionary object with specifed items. */
@@ -9,8 +9,8 @@ export class DictionarySchema extends Schema {
9
9
  items;
10
10
  min;
11
11
  max;
12
- constructor({ items, one = "item", many = "items", min = 0, max = Number.POSITIVE_INFINITY, title = "Items", value = {}, ...options }) {
13
- super({ title, value, ...options });
12
+ constructor({ items, one = "item", many = `${one}s`, placeholder = `No ${many}`, min = 0, max = Number.POSITIVE_INFINITY, title = "Items", value = {}, ...options }) {
13
+ super({ title, placeholder, value, ...options });
14
14
  this.one = one;
15
15
  this.many = many;
16
16
  this.items = items;
@@ -23,9 +23,9 @@ export class DictionarySchema extends Schema {
23
23
  const validDictionary = validateDictionary(unsafeValue, this.items);
24
24
  const length = Object.keys(validDictionary).length;
25
25
  if (length < this.min)
26
- throw new ValueFeedback(length ? `Minimum ${this.min} items` : "Required", validDictionary);
26
+ throw new ValueFeedback(length ? `Minimum ${this.min} ${this.many}` : "Required", validDictionary);
27
27
  if (length > this.max)
28
- throw new ValueFeedback(`Maximum ${this.max} items`, validDictionary);
28
+ throw new ValueFeedback(`Maximum ${this.max} ${this.many}`, validDictionary);
29
29
  return validDictionary;
30
30
  }
31
31
  }