shelving 1.49.2 → 1.49.3

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.49.2",
14
+ "version": "1.49.3",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -25,9 +25,9 @@
25
25
  "./db": "./db/index.js",
26
26
  "./error": "./error/index.js",
27
27
  "./feedback": "./feedback/index.js",
28
- "./firestore/client": "./firestore-client/index.js",
29
- "./firestore/lite": "./firestore-lite/index.js",
30
- "./firestore/server": "./firestore-server/index.js",
28
+ "./firestore/client": "./firestore/client/index.js",
29
+ "./firestore/lite": "./firestore/lite/index.js",
30
+ "./firestore/server": "./firestore/server/index.js",
31
31
  "./markup": "./markup/index.js",
32
32
  "./provider": "./provider/index.js",
33
33
  "./query": "./query/index.js",
@@ -1,4 +1,4 @@
1
- import { withProp, transformProps, NOERROR, LOADING, awaitNext, getData } from "../util/index.js";
1
+ import { withProp, transformData, NOERROR, LOADING, awaitNext, getData } from "../util/index.js";
2
2
  import { State } from "./State.js";
3
3
  /** State that stores a data object and has additional methods to help with that. */
4
4
  export class DataState extends State {
@@ -12,7 +12,7 @@ export class DataState extends State {
12
12
  }
13
13
  /** Update several props in this object. */
14
14
  update(updates) {
15
- this.next(transformProps(this.data, updates));
15
+ this.next(transformData(this.data, updates));
16
16
  }
17
17
  }
18
18
  /** State that stores an optional data object and has additional methods to help with that. */
@@ -35,7 +35,7 @@ export class ResultState extends State {
35
35
  }
36
36
  /** Update several props in this object. */
37
37
  update(updates) {
38
- this.next(transformProps(this.data, updates));
38
+ this.next(transformData(this.data, updates));
39
39
  }
40
40
  /** Delete this result. */
41
41
  delete() {
@@ -1,4 +1,4 @@
1
- import { transformProps, isNullish } from "../util/index.js";
1
+ import { transformData, isNullish } from "../util/index.js";
2
2
  import { Update } from "./Update.js";
3
3
  /** Update that can be applied to a data object to update its props. */
4
4
  export class DataUpdate extends Update {
@@ -11,7 +11,7 @@ export class DataUpdate extends Update {
11
11
  return new DataUpdate(!isNullish(key) ? { [key]: value } : {});
12
12
  }
13
13
  transform(existing) {
14
- return transformProps(existing, this.updates);
14
+ return transformData(existing, this.updates);
15
15
  }
16
16
  /** Return a data update with a specific prop marked for update. */
17
17
  with(key, value) {
@@ -1,4 +1,3 @@
1
- import type { Entry } from "./entry.js";
2
1
  import type { ArrayType, ImmutableArray } from "./array.js";
3
2
  import type { ImmutableMap } from "./map.js";
4
3
  import { ImmutableObject } from "./object.js";
@@ -35,12 +34,6 @@ export declare function yieldTransformed<I, O>(items: Iterable<I>, transformer:
35
34
  export declare function transformArray<T extends ImmutableArray>(arr: T, transformer: Transformer<ArrayType<T>, ArrayType<T>>): T;
36
35
  export declare function transformArray<I, O>(arr: Iterable<I>, transformer: (v: I) => O): ImmutableArray<O>;
37
36
  export declare function transformArray<I, O>(arr: Iterable<I>, transformer: Transformer<I, O>): ImmutableArray<O>;
38
- /**
39
- * Transform the _values_ of a set of entries using a transformer.
40
- * @yield Transformed entry after calling transforming the new value for each entry.
41
- */
42
- export declare function yieldTransformedValues<I, O>(entries: Iterable<Entry<I>>, transformer: (v: I) => O): Iterable<Entry<O>>;
43
- export declare function yieldTransformedValues<I, O>(entries: Iterable<Entry<I>>, transformer: Transformer<I, O>): Iterable<Entry<O>>;
44
37
  /**
45
38
  * Transform the _values_ of a map using a transformer.
46
39
  * @return New map after transforming its values.
@@ -65,7 +58,7 @@ export declare type PropTransformers<T extends Data> = {
65
58
  * Transform the props of a data object using a set of transformers for its props.
66
59
  * @returns New object with changed props (or the same object if no changes were made).
67
60
  */
68
- export declare function transformProps<T extends Data>(existing: T, transformers: PropTransformers<T>): T;
61
+ export declare function transformData<T extends Data>(existing: T, transformers: PropTransformers<T>): T;
69
62
  /** Set of named transformers for a a map-like object. */
70
63
  export declare type EntryTransformers<T> = ImmutableObject<Transformer<T | undefined, T>>;
71
64
  /** Transform some of the entries of a map-like object using a set of named transformers. */
package/util/transform.js CHANGED
@@ -16,18 +16,18 @@ export function* yieldTransformed(items, transformer) {
16
16
  export function transformArray(arr, transformer) {
17
17
  return Array.from(yieldTransformed(arr, transformer));
18
18
  }
19
- export function* yieldTransformedValues(entries, transformer) {
19
+ function* _yieldTransformedValues(entries, transformer) {
20
20
  for (const [k, v] of entries)
21
21
  yield [k, transform(v, transformer)];
22
22
  }
23
23
  export function transformMap(map, transformer) {
24
- return new Map(yieldTransformedValues(map, transformer));
24
+ return new Map(_yieldTransformedValues(map, transformer));
25
25
  }
26
26
  export function transformObject(obj, transformer) {
27
- return Object.fromEntries(yieldTransformedValues(Object.entries(obj), transformer));
27
+ return Object.fromEntries(_yieldTransformedValues(Object.entries(obj), transformer));
28
28
  }
29
29
  /** Apply transformers to the props of a data object and yield any props that changed. */
30
- function* yieldTransformedProps(existing, transformers) {
30
+ function* _yieldTransformedProps(existing, transformers) {
31
31
  for (const [k, v] of toProps(transformers))
32
32
  yield [k, transform(existing[k], v)];
33
33
  }
@@ -35,15 +35,15 @@ function* yieldTransformedProps(existing, transformers) {
35
35
  * Transform the props of a data object using a set of transformers for its props.
36
36
  * @returns New object with changed props (or the same object if no changes were made).
37
37
  */
38
- export function transformProps(existing, transformers) {
39
- return Object.fromEntries(yieldMerged(toProps(existing), yieldTransformedProps(existing, transformers)));
38
+ export function transformData(existing, transformers) {
39
+ return Object.fromEntries(yieldMerged(toProps(existing), _yieldTransformedProps(existing, transformers)));
40
40
  }
41
41
  /** Apply named transformers to the entries of a map-like object and yield any entries that changed. */
42
- function* yieldTransformedEntries(existing, updates) {
42
+ function* _yieldTransformedEntries(existing, updates) {
43
43
  for (const [k, t] of Object.entries(updates))
44
44
  yield [k, transform(existing[k], t)];
45
45
  }
46
46
  /** Transform some of the entries of a map-like object using a set of named transformers. */
47
47
  export function transformEntries(existing, updates, deletes) {
48
- return Object.fromEntries(yieldFiltered(yieldMerged(Object.entries(existing), yieldTransformedEntries(existing, updates)), isKeyInArray, deletes));
48
+ return Object.fromEntries(yieldFiltered(yieldMerged(Object.entries(existing), _yieldTransformedEntries(existing, updates)), isKeyInArray, deletes));
49
49
  }
package/util/undefined.js CHANGED
@@ -1,4 +1,4 @@
1
- import { RequiredError } from "..";
1
+ import { RequiredError } from "../error/index.js";
2
2
  /** Is a value undefined? */
3
3
  export const isUndefined = (v) => v === undefined;
4
4
  /** Is a value defined? */
@@ -1,5 +1,5 @@
1
1
  import type { Entry } from "./entry.js";
2
- import { Data, Prop, Result } from "./data.js";
2
+ import { Data, Result } from "./data.js";
3
3
  /** Object that can validate an unknown value with its `validate()` method. */
4
4
  export interface Validatable<T> {
5
5
  /**
@@ -50,14 +50,6 @@ export declare function validateItems<T>(unsafeItems: Iterable<unknown>, validat
50
50
  * - `feedback.details` will contain an entry for each invalid item (keyed by their count in the input iterable).
51
51
  */
52
52
  export declare function validateValues<T>(unsafeValues: Iterable<Entry>, validator: Validator<T>): Generator<Entry<T>, void>;
53
- /**
54
- * Validate a set of object props with a set of validators.
55
- *
56
- * @yield Valid entries for each specified validator.
57
- * @throw InvalidFeedback if one or more entries did not validate.
58
- * - `feedback.details` will contain an entry for each invalid item (keyed by their count in the input iterable).
59
- */
60
- export declare function validateProps<T extends Data>(unsafeData: Data, validators: Validators<T>): Generator<Prop<T>, void>;
61
53
  /**
62
54
  * Validate an entire object with a set of validators.
63
55
  * - Defined props in the object will be validated against the corresponding validator.
@@ -69,7 +61,7 @@ export declare function validateProps<T extends Data>(unsafeData: Data, validato
69
61
  */
70
62
  export declare function validateData<T extends Data>(unsafeData: Data, validators: Validators<T>): T;
71
63
  /**
72
- * Validate a data result.
64
+ * Validate a data result against a validator for that data.
73
65
  * @return Valid object or `null`
74
66
  */
75
67
  export declare function validateResult<T extends Data>(unsafeResult: unknown, validator: Validator<T>): Result<T>;
package/util/validate.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Feedback, InvalidFeedback } from "../feedback/index.js";
2
2
  import { isData, toProps } from "./data.js";
3
+ import { isNullish } from "./null.js";
3
4
  /** Is a given value a validator? */
4
5
  export const isValidator = (v) => typeof v === "function" || (isData(v) && typeof v.validate === "function");
5
6
  /** Validate an unknown value with a validator. */
@@ -56,6 +57,18 @@ export function* validateValues(unsafeValues, validator) {
56
57
  if (invalid)
57
58
  throw new InvalidFeedback("Invalid items", details);
58
59
  }
60
+ /**
61
+ * Validate an entire object with a set of validators.
62
+ * - Defined props in the object will be validated against the corresponding validator.
63
+ * - `undefined` props in the object will be set to the default value of that prop.
64
+ *
65
+ * @return Valid object.
66
+ * @throw InvalidFeedback if one or more entries did not validate.
67
+ * - `feedback.details` will contain an entry for each invalid item (keyed by their count in the input iterable).
68
+ */
69
+ export function validateData(unsafeData, validators) {
70
+ return Object.fromEntries(_yieldValidatedProps(unsafeData, validators));
71
+ }
59
72
  /**
60
73
  * Validate a set of object props with a set of validators.
61
74
  *
@@ -63,7 +76,7 @@ export function* validateValues(unsafeValues, validator) {
63
76
  * @throw InvalidFeedback if one or more entries did not validate.
64
77
  * - `feedback.details` will contain an entry for each invalid item (keyed by their count in the input iterable).
65
78
  */
66
- export function* validateProps(unsafeData, validators) {
79
+ function* _yieldValidatedProps(unsafeData, validators) {
67
80
  let invalid = false;
68
81
  const details = {};
69
82
  for (const [k, validator] of toProps(validators)) {
@@ -83,21 +96,9 @@ export function* validateProps(unsafeData, validators) {
83
96
  throw new InvalidFeedback("Invalid data", details);
84
97
  }
85
98
  /**
86
- * Validate an entire object with a set of validators.
87
- * - Defined props in the object will be validated against the corresponding validator.
88
- * - `undefined` props in the object will be set to the default value of that prop.
89
- *
90
- * @return Valid object.
91
- * @throw InvalidFeedback if one or more entries did not validate.
92
- * - `feedback.details` will contain an entry for each invalid item (keyed by their count in the input iterable).
93
- */
94
- export function validateData(unsafeData, validators) {
95
- return Object.fromEntries(validateProps(unsafeData, validators));
96
- }
97
- /**
98
- * Validate a data result.
99
+ * Validate a data result against a validator for that data.
99
100
  * @return Valid object or `null`
100
101
  */
101
102
  export function validateResult(unsafeResult, validator) {
102
- return unsafeResult === null || unsafeResult === undefined ? validate(unsafeResult, validator) : null;
103
+ return !isNullish(unsafeResult) ? validate(unsafeResult, validator) : null;
103
104
  }