shelving 1.82.0 → 1.83.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 (91) hide show
  1. package/constraint/Constraints.js +3 -3
  2. package/constraint/FilterConstraint.d.ts +5 -5
  3. package/constraint/SortConstraint.d.ts +2 -2
  4. package/db/Change.d.ts +12 -12
  5. package/db/Collection.d.ts +4 -4
  6. package/db/Database.d.ts +29 -29
  7. package/db/Item.d.ts +4 -4
  8. package/db/Query.d.ts +4 -4
  9. package/feedback/Feedback.d.ts +2 -2
  10. package/feedback/Feedback.js +3 -2
  11. package/firestore/client/FirestoreClientProvider.js +2 -2
  12. package/firestore/lite/FirestoreLiteProvider.js +2 -2
  13. package/firestore/server/FirestoreServerProvider.js +2 -2
  14. package/package.json +1 -1
  15. package/provider/CacheProvider.d.ts +12 -12
  16. package/provider/DebugProvider.d.ts +21 -21
  17. package/provider/MemoryProvider.d.ts +16 -16
  18. package/provider/MemoryProvider.js +3 -3
  19. package/provider/Provider.d.ts +30 -30
  20. package/provider/ThroughProvider.d.ts +23 -23
  21. package/provider/ValidationProvider.d.ts +22 -22
  22. package/provider/ValidationProvider.js +2 -2
  23. package/react/useItem.d.ts +4 -4
  24. package/react/useQuery.d.ts +4 -4
  25. package/schema/AllowSchema.d.ts +25 -24
  26. package/schema/AllowSchema.js +25 -29
  27. package/schema/ArraySchema.d.ts +2 -2
  28. package/schema/BooleanSchema.d.ts +2 -2
  29. package/schema/DataSchema.d.ts +2 -2
  30. package/schema/DataSchema.js +2 -2
  31. package/schema/DateSchema.d.ts +2 -2
  32. package/schema/DictionarySchema.d.ts +19 -0
  33. package/schema/{ObjectSchema.js → DictionarySchema.js} +6 -6
  34. package/schema/LinkSchema.d.ts +2 -2
  35. package/schema/NumberSchema.d.ts +2 -2
  36. package/schema/Schema.d.ts +10 -8
  37. package/schema/Schema.js +1 -1
  38. package/schema/StringSchema.d.ts +12 -10
  39. package/schema/index.d.ts +1 -1
  40. package/schema/index.js +1 -1
  41. package/state/ArrayState.js +4 -4
  42. package/state/DataState.js +3 -3
  43. package/state/DictionaryState.d.ts +15 -0
  44. package/state/{ObjectState.js → DictionaryState.js} +6 -6
  45. package/state/index.d.ts +2 -2
  46. package/state/index.js +2 -2
  47. package/test/basics.js +1 -1
  48. package/update/ArrayUpdate.js +2 -2
  49. package/update/DataUpdate.d.ts +10 -9
  50. package/update/DataUpdate.js +6 -4
  51. package/update/DictionaryUpdate.d.ts +29 -0
  52. package/update/{ObjectUpdate.js → DictionaryUpdate.js} +14 -14
  53. package/update/hydrations.js +2 -2
  54. package/update/index.d.ts +1 -1
  55. package/update/index.js +1 -1
  56. package/util/array.d.ts +40 -111
  57. package/util/array.js +50 -114
  58. package/util/clone.d.ts +2 -2
  59. package/util/clone.js +5 -5
  60. package/util/data.d.ts +20 -53
  61. package/util/data.js +11 -1
  62. package/util/dictionary.d.ts +39 -0
  63. package/util/dictionary.js +33 -0
  64. package/util/diff.d.ts +3 -3
  65. package/util/entry.d.ts +7 -5
  66. package/util/entry.js +8 -6
  67. package/util/filter.d.ts +0 -5
  68. package/util/filter.js +0 -3
  69. package/util/hydrate.d.ts +2 -2
  70. package/util/hydrate.js +7 -8
  71. package/util/index.d.ts +1 -0
  72. package/util/index.js +1 -0
  73. package/util/map.d.ts +28 -6
  74. package/util/map.js +22 -6
  75. package/util/merge.d.ts +3 -6
  76. package/util/merge.js +4 -6
  77. package/util/object.d.ts +77 -90
  78. package/util/object.js +23 -76
  79. package/util/set.d.ts +10 -0
  80. package/util/set.js +17 -0
  81. package/util/template.d.ts +3 -3
  82. package/util/template.js +3 -3
  83. package/util/transform.d.ts +22 -45
  84. package/util/transform.js +20 -37
  85. package/util/units.d.ts +6 -12
  86. package/util/units.js +8 -4
  87. package/util/validate.d.ts +6 -5
  88. package/util/validate.js +5 -4
  89. package/schema/ObjectSchema.d.ts +0 -19
  90. package/state/ObjectState.d.ts +0 -16
  91. package/update/ObjectUpdate.d.ts +0 -29
package/util/diff.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ImmutableArray } from "./array.js";
2
- import { Data, DeepPartial } from "./data.js";
2
+ import { ImmutableObject, DeepPartial } from "./object.js";
3
3
  /** The `SAME` symbol indicates sameness. */
4
4
  export declare const SAME: unique symbol;
5
5
  /**
@@ -14,7 +14,7 @@ export declare const SAME: unique symbol;
14
14
  * - If `right` is an array, returns whatever `deepDiffArray()` returns.
15
15
  * - If `right` is an object, returns whatever `deepDiffObject()` returns.
16
16
  */
17
- export declare function deepDiff<R extends Data>(left: unknown, right: R): R | DeepPartial<R> | typeof SAME;
17
+ export declare function deepDiff<R extends ImmutableObject>(left: unknown, right: R): R | DeepPartial<R> | typeof SAME;
18
18
  export declare function deepDiff<R extends unknown>(left: unknown, right: R): R | typeof SAME;
19
19
  /**
20
20
  * Diff two arrays to produce the transformation needed to transform `left` into `right`
@@ -34,4 +34,4 @@ export declare function deepDiffArray<R extends ImmutableArray>(left: ImmutableA
34
34
  * - If the two values are deeply equal the `SAME` constant is returned.
35
35
  * - If `left` isn't an object then the result can't be diffed so entire `right` is returned.
36
36
  */
37
- export declare function deepDiffObject<R extends Data>(left: Data, right: R): R | DeepPartial<R> | typeof SAME;
37
+ export declare function deepDiffObject<R extends ImmutableObject>(left: ImmutableObject, right: R): R | DeepPartial<R> | typeof SAME;
package/util/entry.d.ts CHANGED
@@ -1,12 +1,12 @@
1
- import type { ImmutableObject } from "./object.js";
2
1
  import { ImmutableArray } from "./array.js";
3
- import { ImmutableMap } from "./map.js";
2
+ import { ImmutableObject } from "./object.js";
3
+ import { ImmutableSet } from "./set.js";
4
4
  /**
5
5
  * Single entry from a map-like object.
6
6
  * - Consistency with `UnknownObject`
7
7
  * - Always readonly.
8
8
  */
9
- export declare type Entry<K, T> = readonly [K, T];
9
+ export declare type Entry<K = unknown, T = unknown> = readonly [K, T];
10
10
  /** Extract the type for the value of an entry. */
11
11
  export declare type EntryKey<X> = X extends Entry<infer Y, unknown> ? Y : never;
12
12
  /** Extract the type for the value of an entry. */
@@ -19,5 +19,7 @@ export declare const getEntryValue: <K, T>([, v]: Entry<K, T>) => T;
19
19
  export declare function getEntryKeys<K, T>(input: Iterable<Entry<K, T>>): Iterable<K>;
20
20
  /** Yield the values of an iterable set of entries. */
21
21
  export declare function getEntryValues<K, T>(input: Iterable<Entry<K, T>>): Iterable<T>;
22
- /** Yield the entries in an object, array, or map. */
23
- export declare function getEntries<T>(input: ImmutableObject<T> | ImmutableArray<T> | ImmutableMap<string | number, T>): Iterable<Entry<string | number, T>>;
22
+ /** Yield the entries in something that can yield entries. */
23
+ export declare function getEntries<K extends number, T = K>(entries: ImmutableArray<T> | ImmutableSet<K & T> | ImmutableObject<K, T> | Iterable<Entry<K, T>>): Iterable<Entry<K, T>>;
24
+ export declare function getEntries<K extends string, T = K>(entries: ImmutableSet<K & T> | ImmutableObject<K, T> | Iterable<Entry<K, T>>): Iterable<Entry<K, T>>;
25
+ export declare function getEntries<K, T = K>(entries: ImmutableArray<K & T> | ImmutableSet<K & T> | ImmutableObject<K & PropertyKey, T> | Iterable<Entry<K, T>>): Iterable<Entry<K, T>>;
package/util/entry.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { isArray } from "./array.js";
2
- import { isMap } from "./map.js";
2
+ import { isIterable } from "./iterate.js";
3
+ import { isSet } from "./set.js";
3
4
  /** Extract the key from an object entry. */
4
5
  export const getEntryKey = ([k]) => k;
5
6
  /** Extract the value from an object entry. */
@@ -14,9 +15,10 @@ export function* getEntryValues(input) {
14
15
  for (const [, v] of input)
15
16
  yield v;
16
17
  }
17
- /** Yield the entries in an object, array, or map. */
18
- export function getEntries(input) {
19
- if (isArray(input) || isMap(input))
20
- return input.entries();
21
- return Object.entries(input);
18
+ export function getEntries(entries) {
19
+ if (isArray(entries) || isSet(entries))
20
+ return entries.entries();
21
+ if (isIterable(entries))
22
+ return entries;
23
+ return Object.entries(entries);
22
24
  }
package/util/filter.d.ts CHANGED
@@ -1,6 +1,4 @@
1
1
  import type { ImmutableArray } from "./array.js";
2
- import type { Entry } from "./entry.js";
3
- import type { ImmutableObject } from "./object.js";
4
2
  import { Matcher } from "./match.js";
5
3
  /** Filter an iterable set of items using a matcher (and optionally a target value). */
6
4
  export declare function filterItems<L>(input: Iterable<L>, matcher: Matcher<L, void>): Iterable<L>;
@@ -8,6 +6,3 @@ export declare function filterItems<L, R>(input: Iterable<L>, matcher: Matcher<L
8
6
  /** Filter an array using a matcher (and optionally a target value). */
9
7
  export declare function filterArray<L>(input: ImmutableArray<L>, matcher: Matcher<L, void>): ImmutableArray<L>;
10
8
  export declare function filterArray<L, R>(input: ImmutableArray<L>, matcher: Matcher<L, R>, target: R): ImmutableArray<L>;
11
- /** Filter an object _by its values_ using a matcher (and optionally a target value). */
12
- export declare function filterObject<L>(object: ImmutableObject<L>, matcher: Matcher<Entry<string, L>, void>): ImmutableObject<L>;
13
- export declare function filterObject<L, R>(object: ImmutableObject<L>, matcher: Matcher<Entry<string, L>, R>, target: R): ImmutableObject<L>;
package/util/filter.js CHANGED
@@ -10,6 +10,3 @@ export function filterArray(input, matcher, target) {
10
10
  const output = Array.from(filterItems(input, matcher, target));
11
11
  return output.length === input.length ? input : output;
12
12
  }
13
- export function filterObject(object, matcher, target) {
14
- return Object.fromEntries(filterItems(Object.entries(object), matcher, target));
15
- }
package/util/hydrate.d.ts CHANGED
@@ -1,11 +1,11 @@
1
+ import type { ImmutableDictionary } from "./dictionary.js";
1
2
  import type { Class } from "./class.js";
2
- import { ImmutableObject } from "./object.js";
3
3
  import { Transformable } from "./transform.js";
4
4
  /**
5
5
  * A set of hydrations describes a set of string keys and the class constructor to be dehydrated and rehydrated.
6
6
  * - We can't use `class.name` because we don't know that the name of the class will survive minification.
7
7
  */
8
- export declare type Hydrations = ImmutableObject<Class>;
8
+ export declare type Hydrations = ImmutableDictionary<Class>;
9
9
  /**
10
10
  * Deeply dehydrate a class instance based on a set of `Hydrations`
11
11
  * - Dehydration allows you to pass class instances from a server back to a client.
package/util/hydrate.js CHANGED
@@ -1,12 +1,11 @@
1
1
  import { AssertionError } from "../error/AssertionError.js";
2
2
  import { isArray } from "./array.js";
3
- import { isData } from "./data.js";
4
3
  import { isDate } from "./date.js";
5
4
  import { isMap } from "./map.js";
6
- import { isPlainObject } from "./object.js";
5
+ import { isObject, isPlainObject } from "./object.js";
7
6
  import { isSet } from "./set.js";
8
7
  import { isString } from "./string.js";
9
- import { mapArray, mapData, mapEntries, mapItems, mapObject } from "./transform.js";
8
+ import { mapArray, mapObject, mapEntries, mapItems } from "./transform.js";
10
9
  /**
11
10
  * Deeply dehydrate a class instance based on a set of `Hydrations`
12
11
  * - Dehydration allows you to pass class instances from a server back to a client.
@@ -42,7 +41,7 @@ export class Hydrator {
42
41
  return mapArray(value, this);
43
42
  if (isPlainObject(value)) {
44
43
  if (!isDehydrated(value))
45
- return mapData(value, this);
44
+ return mapObject(value, this);
46
45
  const { $type, $value } = value;
47
46
  if ($type === "Map")
48
47
  return new Map($value);
@@ -52,7 +51,7 @@ export class Hydrator {
52
51
  return new Date($value);
53
52
  const hydration = this._hydrations[$type];
54
53
  if (hydration)
55
- return { __proto__: hydration.prototype, ...mapData($value, this) };
54
+ return { __proto__: hydration.prototype, ...mapObject($value, this) };
56
55
  throw new AssertionError(`Cannot hydrate "${$type}" object`, value);
57
56
  }
58
57
  return value;
@@ -71,14 +70,14 @@ export class Dehydrator {
71
70
  if (isSet(value))
72
71
  return { $type: "Set", $value: Array.from(mapItems(value.values(), this)) };
73
72
  if (isDate(value))
74
- return { $type: "Date", $value: value.toString() };
75
- if (isData(value)) {
73
+ return { $type: "Date", $value: value.getTime() };
74
+ if (isObject(value)) {
76
75
  const proto = Object.getPrototypeOf(value);
77
76
  if (proto === Object.prototype || proto === null)
78
77
  return mapObject(value, this);
79
78
  for (const [$type, hydration] of Object.entries(this._hydrations))
80
79
  if (proto === hydration.prototype)
81
- return { $type, $value: mapData(value, this) };
80
+ return { $type, $value: mapObject(value, this) };
82
81
  throw new AssertionError(`Cannot dehydrate object`, value);
83
82
  }
84
83
  return value;
package/util/index.d.ts CHANGED
@@ -10,6 +10,7 @@ export * from "./constants.js";
10
10
  export * from "./data.js";
11
11
  export * from "./date.js";
12
12
  export * from "./debug.js";
13
+ export * from "./dictionary.js";
13
14
  export * from "./diff.js";
14
15
  export * from "./entry.js";
15
16
  export * from "./equal.js";
package/util/index.js CHANGED
@@ -10,6 +10,7 @@ export * from "./constants.js";
10
10
  export * from "./data.js";
11
11
  export * from "./date.js";
12
12
  export * from "./debug.js";
13
+ export * from "./dictionary.js";
13
14
  export * from "./diff.js";
14
15
  export * from "./entry.js";
15
16
  export * from "./equal.js";
package/util/map.d.ts CHANGED
@@ -1,24 +1,46 @@
1
+ import { Entry } from "./entry.js";
1
2
  /** `Map` that cannot be changed. */
2
3
  export declare type ImmutableMap<K = unknown, T = unknown> = ReadonlyMap<K, T>;
3
4
  /** `Map` that can be changed. */
4
5
  export declare type MutableMap<K = unknown, T = unknown> = Map<K, T>;
5
- /** Extract the type for the value of an entry. */
6
+ /** Extract the type for the value of a map. */
6
7
  export declare type MapKey<X> = X extends ReadonlyMap<infer Y, unknown> ? Y : never;
7
- /** Extract the type for the value of an entry. */
8
+ /** Extract the type for the value of a map. */
8
9
  export declare type MapValue<X> = X extends ReadonlyMap<unknown, infer Y> ? Y : never;
10
+ /** Get the type for an item of a map in entry format. */
11
+ export declare type MapItem<T extends ImmutableMap> = readonly [MapKey<T>, MapValue<T>];
9
12
  /** Things that can be converted to maps. */
10
- export declare type PossibleMap<K, T> = ImmutableMap<K, T> | Iterable<readonly [K, T]>;
13
+ export declare type PossibleMap<K, T> = ImmutableMap<K, T> | Iterable<Entry<K, T>>;
14
+ /** Things that can be converted to maps with string keys. */
15
+ export declare type PossibleStringMap<K extends string, T> = PossibleMap<K, T> | {
16
+ readonly [KK in K]: T;
17
+ };
11
18
  /** Is an unknown value a map? */
12
19
  export declare const isMap: <T extends ImmutableMap<unknown, unknown>>(v: unknown) => v is T;
20
+ /** Is an unknown value a key for an item in a map? */
21
+ export declare const isMapKey: <K, V>(map: ImmutableMap<K, V>, key: unknown) => key is K;
13
22
  /** Assert that a value is a `Map` instance. */
14
23
  export declare function assertMap<T extends ImmutableMap>(v: T | unknown): asserts v is T;
15
24
  /** Convert an iterable to a `Map` (if it's already a `Map` it passes through unchanged). */
16
- export declare function getMap<K, T>(iterable: PossibleMap<K, T>): ImmutableMap<K, T>;
25
+ export declare function getMap<K extends string, T>(input: PossibleStringMap<K, T>): ImmutableMap<K, T>;
26
+ export declare function getMap<K, T>(input: PossibleMap<K, T>): ImmutableMap<K, T>;
27
+ /** Convert an iterable to a `Map` (if it's already a `Map` it passes through unchanged). */
28
+ export declare function getRequiredMap<K extends string, T>(input: PossibleStringMap<K, T>): ImmutableRequiredMap<K, T>;
29
+ export declare function getRequiredMap<K, T>(input: PossibleMap<K, T>): ImmutableRequiredMap<K, T>;
17
30
  /** Apply a limit to a map. */
18
31
  export declare function limitMap<T>(map: ImmutableMap<T>, limit: number): ImmutableMap<T>;
19
32
  /** Function that lets new items in a map be created and updated by calling a `reduce()` callback that receives the existing value. */
20
33
  export declare function setMapItem<K, T>(map: MutableMap<K, T>, key: K, value: T): T;
21
- /** Map that changes `get()` to throw an error if the requested value doesn't exist. */
22
- export declare class RequiredMap<K, T> extends Map<K, T> {
34
+ /** Add multiple items to a set (by reference). */
35
+ export declare function setMapItems<K, T>(map: MutableMap<K, T>, items: Iterable<MapItem<ImmutableMap<K, T>>>): void;
36
+ /** Remove multiple items from a set (by reference). */
37
+ export declare function removeMapItems<K, T>(map: MutableMap<K, T>, ...keys: K[]): void;
38
+ /** Mutable map that changes `get()` to throw an error if the requested value doesn't exist. */
39
+ export declare class MutableRequiredMap<K, T> extends Map<K, T> {
23
40
  get(key: K): T;
24
41
  }
42
+ /** Immutable map that changes `get()` to throw an error if the requested value doesn't exist. */
43
+ export declare const ImmutableRequiredMap: {
44
+ new <K, T>(...params: ConstructorParameters<typeof MutableRequiredMap<K, T>>): ImmutableRequiredMap<K, T>;
45
+ };
46
+ export declare type ImmutableRequiredMap<K, T> = Omit<MutableRequiredMap<K, T>, "set" | "delete">;
package/util/map.js CHANGED
@@ -1,17 +1,21 @@
1
1
  import { AssertionError } from "../error/AssertionError.js";
2
2
  import { RequiredError } from "../error/RequiredError.js";
3
- import { limitItems } from "./iterate.js";
3
+ import { isIterable, limitItems } from "./iterate.js";
4
4
  import { getString } from "./string.js";
5
5
  /** Is an unknown value a map? */
6
6
  export const isMap = (v) => v instanceof Map;
7
+ /** Is an unknown value a key for an item in a map? */
8
+ export const isMapKey = (map, key) => map.has(key);
7
9
  /** Assert that a value is a `Map` instance. */
8
10
  export function assertMap(v) {
9
11
  if (!isMap(v))
10
12
  throw new AssertionError(`Must be map`, v);
11
13
  }
12
- /** Convert an iterable to a `Map` (if it's already a `Map` it passes through unchanged). */
13
- export function getMap(iterable) {
14
- return isMap(iterable) ? iterable : new Map(iterable);
14
+ export function getMap(input) {
15
+ return isMap(input) ? input : new Map(isIterable(input) ? input : Object.entries(input));
16
+ }
17
+ export function getRequiredMap(input) {
18
+ return input instanceof ImmutableRequiredMap ? input : new ImmutableRequiredMap(isIterable(input) ? input : Object.entries(input));
15
19
  }
16
20
  /** Apply a limit to a map. */
17
21
  export function limitMap(map, limit) {
@@ -22,11 +26,23 @@ export function setMapItem(map, key, value) {
22
26
  map.set(key, value);
23
27
  return value;
24
28
  }
25
- /** Map that changes `get()` to throw an error if the requested value doesn't exist. */
26
- export class RequiredMap extends Map {
29
+ /** Add multiple items to a set (by reference). */
30
+ export function setMapItems(map, items) {
31
+ for (const [k, v] of items)
32
+ map.set(k, v);
33
+ }
34
+ /** Remove multiple items from a set (by reference). */
35
+ export function removeMapItems(map, ...keys) {
36
+ for (const key of keys)
37
+ map.delete(key);
38
+ }
39
+ /** Mutable map that changes `get()` to throw an error if the requested value doesn't exist. */
40
+ export class MutableRequiredMap extends Map {
27
41
  get(key) {
28
42
  if (!this.has(key))
29
43
  throw new RequiredError(`Item "${getString(key)}" is required`);
30
44
  return super.get(key);
31
45
  }
32
46
  }
47
+ /** Immutable map that changes `get()` to throw an error if the requested value doesn't exist. */
48
+ export const ImmutableRequiredMap = MutableRequiredMap;
package/util/merge.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { Data } from "./data.js";
2
1
  import { ImmutableArray } from "./array.js";
3
2
  import { ImmutableObject } from "./object.js";
4
3
  declare type MergeRecursor = (left: unknown, right: unknown) => unknown;
@@ -18,7 +17,7 @@ export declare const exactMerge: MergeRecursor;
18
17
  * - Will be `left` instance if no properties/items changed.
19
18
  * - Will be merged instance otherwise.
20
19
  */
21
- export declare function shallowMerge<L extends Data, R extends Data>(left: L, right: R): L & R;
20
+ export declare function shallowMerge<L extends ImmutableObject, R extends ImmutableObject>(left: L, right: R): L & R;
22
21
  export declare function shallowMerge<L extends unknown, R extends unknown>(left: ImmutableArray<L>, right: ImmutableArray<R>): ImmutableArray<L | R>;
23
22
  export declare function shallowMerge<R>(left: unknown, right: R): R;
24
23
  /**
@@ -32,7 +31,7 @@ export declare function shallowMerge<R>(left: unknown, right: R): R;
32
31
  * - Will be `left` instance if no properties/items changed.
33
32
  * - Will be a new merged instance otherwise.
34
33
  */
35
- export declare function deepMerge<L extends Data, R extends Data>(left: L, right: R): L & R;
34
+ export declare function deepMerge<L extends ImmutableObject, R extends ImmutableObject>(left: L, right: R): L & R;
36
35
  export declare function deepMerge<L extends unknown, R extends unknown>(left: ImmutableArray<L>, right: ImmutableArray<R>): ImmutableArray<L | R>;
37
36
  export declare function deepMerge<R>(left: unknown, right: R): R;
38
37
  /**
@@ -64,7 +63,5 @@ export declare function mergeArray<L extends unknown, R extends unknown>(left: I
64
63
  * - Will be `left` instance if no properties changed.
65
64
  * - Will be a new merged object otherwise.
66
65
  */
67
- export declare function mergeData<L extends Data, R extends Data>(left: L, right: R, recursor?: MergeRecursor): L & R;
68
- /** Merge two map-like objects. */
69
- export declare const mergeObject: <T>(left: ImmutableObject<T>, right: ImmutableObject<T>, recursor?: MergeRecursor) => ImmutableObject<T>;
66
+ export declare function mergeObject<L extends ImmutableObject, R extends ImmutableObject>(left: L, right: R, recursor?: MergeRecursor): L & R;
70
67
  export {};
package/util/merge.js CHANGED
@@ -1,13 +1,13 @@
1
- import { isData } from "./data.js";
2
1
  import { isArray } from "./array.js";
2
+ import { isObject } from "./object.js";
3
3
  // Internal shared by shallow/deep merge.
4
4
  function _merge(left, right, recursor) {
5
5
  if (left === right)
6
6
  return right;
7
7
  if (isArray(right))
8
8
  return isArray(left) ? mergeArray(left, right) : right;
9
- if (isData(right))
10
- return isData(left) && !isArray(left) ? mergeData(left, right, recursor) : right;
9
+ if (isObject(right))
10
+ return isObject(left) && !isArray(left) ? mergeObject(left, right, recursor) : right;
11
11
  return right;
12
12
  }
13
13
  /**
@@ -45,7 +45,7 @@ export function mergeArray(left, right) {
45
45
  merged.push(v);
46
46
  return merged.length === left.length ? left : merged;
47
47
  }
48
- export function mergeData(left, right, recursor = exactMerge) {
48
+ export function mergeObject(left, right, recursor = exactMerge) {
49
49
  if (left === right)
50
50
  return right;
51
51
  // If `right` has no keys then merge result will always be `left` (because there's nothing to merge).
@@ -77,5 +77,3 @@ export function mergeData(left, right, recursor = exactMerge) {
77
77
  }
78
78
  return changed ? merged : left;
79
79
  }
80
- /** Merge two map-like objects. */
81
- export const mergeObject = mergeData;
package/util/object.d.ts CHANGED
@@ -1,35 +1,74 @@
1
1
  import type { ImmutableArray } from "./array.js";
2
- import type { Data, Prop } from "./data.js";
3
- import type { Entry } from "./entry.js";
4
- /** Readonly object with string keys. */
5
- export declare type ImmutableObject<T = unknown> = {
6
- readonly [key: string | number]: T;
2
+ /** Any readonly objet. */
3
+ export declare type ImmutableObject<K extends PropertyKey = PropertyKey, T = unknown> = {
4
+ readonly [KK in K]: T;
7
5
  };
8
- /** Writable object with string keys. */
9
- export declare type MutableObject<T = unknown> = {
10
- [key: string | number]: T;
6
+ /** Any writable object. */
7
+ export declare type MutableObject<K extends PropertyKey = PropertyKey, T = unknown> = {
8
+ [KK in K]: T;
11
9
  };
10
+ /** Prop for an object. */
11
+ export declare type ObjectProp<T extends ImmutableObject = ImmutableObject> = readonly [keyof T, T[keyof T]];
12
+ /** Key for an object prop. */
13
+ export declare type ObjectKey<T extends ImmutableObject = ImmutableObject> = keyof T;
14
+ /** Value for an object prop. */
15
+ export declare type ObjectValue<T extends ImmutableObject = ImmutableObject> = T[keyof T];
16
+ /** Is an unknown value an unknown object? */
17
+ export declare const isObject: <T extends ImmutableObject<PropertyKey, unknown>>(value: unknown) => value is T;
18
+ /** Assert that a value is an object */
19
+ export declare function assertObject(value: ImmutableObject | unknown): asserts value is ImmutableObject;
20
+ /** is an unknown value an unknown plain object? */
21
+ export declare function isPlainObject(value: ImmutableObject | unknown): value is ImmutableObject;
22
+ /** Assert that a value is an object */
23
+ export declare function assertPlainObject(value: ImmutableObject | unknown): asserts value is ImmutableObject;
24
+ /** Is an unknown value the key for an own prop of an object. */
25
+ export declare const isProp: <T extends ImmutableObject<PropertyKey, unknown>>(obj: T, key: unknown) => key is keyof T;
12
26
  /**
13
- * Is a value an unknown object?
14
- * - This is a TypeScript assertion object that asserts the value extends `ImmutableObject`
15
- * - Note: Arrays and other complex objects will return true.
27
+ * Mutable type is the opposite of `Readonly<T>` helper type.
28
+ * - See https://github.com/microsoft/TypeScript/issues/24509
29
+ * - Consistency with `Readonly<T>`
16
30
  */
17
- export declare const isObject: <T extends ImmutableObject<unknown>>(value: unknown) => value is T;
18
- /** Assert that a value is an object */
19
- export declare function assertObject<T extends ImmutableObject>(value: T | unknown): asserts value is T;
20
- /** Is a value a plain object? */
21
- export declare function isPlainObject<T extends ImmutableObject>(value: T | unknown): value is T;
22
- /** Assert that a value is a plain object */
23
- export declare function assertPlainObject<T extends ImmutableObject>(value: T | unknown): asserts value is T;
24
- /** Is an unknown string an own prop of an object. */
25
- export declare const isProp: <T extends ImmutableObject<unknown>>(obj: T, key: unknown) => key is keyof T;
26
- /** Turn a data object into an array of props. */
27
- export declare function getProps<T extends Data>(data: T): ImmutableArray<Prop<T>>;
28
- export declare function getProps<T extends Data>(data: T | Partial<T>): ImmutableArray<Prop<T>>;
29
- export declare function getProps<T extends ImmutableObject>(data: T): ImmutableArray<Entry<keyof T, T[keyof T]>>;
30
- export declare function getProps<T extends ImmutableObject>(data: T | Partial<T>): ImmutableArray<Entry<keyof T, T[keyof T]>>;
31
+ export declare type Mutable<T> = {
32
+ -readonly [K in keyof T]: T[K];
33
+ };
34
+ /**
35
+ * Deep partial object: deeply convert an object to its partial version.
36
+ * - Any value that extends `UnknownObject` has its props made partial.
37
+ * - Works deeply on nested objects too.
38
+ */
39
+ export declare type DeepPartial<T> = {
40
+ [K in keyof T]?: DeepPartial<T[K]>;
41
+ };
42
+ /**
43
+ * Deep mutable object: deeply convert an object to its mutable version.
44
+ * - Any value that extends `UnknownObject` has its props made mutable.
45
+ * - Works deeply on nested objects too.
46
+ */
47
+ export declare type DeepMutable<T> = {
48
+ -readonly [K in keyof T]: DeepMutable<T[K]>;
49
+ };
31
50
  /**
32
- * Extract the value of a named prop from a data object.
51
+ * Deep readonly object: deeply convert an object to its readonly version.
52
+ * - Any value that extends `UnknownObject` has its props made readonly.
53
+ * - Works deeply on nested objects too.
54
+ */
55
+ export declare type DeepReadonly<T> = {
56
+ +readonly [K in keyof T]: DeepReadonly<T[K]>;
57
+ };
58
+ /** Pick only the properties of an object that match a type. */
59
+ export declare type PickProps<T, TT> = Pick<T, {
60
+ [K in keyof T]: T[K] extends TT ? K : never;
61
+ }[keyof T]>;
62
+ /** Omit the properties of an object that match a type. */
63
+ export declare type OmitProps<T, TT> = Omit<T, {
64
+ [K in keyof T]: T[K] extends TT ? K : never;
65
+ }[keyof T]>;
66
+ /** Get the props of an object as a set of entries. */
67
+ export declare function getProps<T extends ImmutableObject>(obj: T): ImmutableArray<ObjectProp<T>>;
68
+ export declare function getProps<T extends ImmutableObject>(obj: T | Partial<T>): ImmutableArray<ObjectProp<T>>;
69
+ export declare function getProps<T extends ImmutableObject>(obj: T | Partial<T> | Iterable<ObjectProp<T>>): Iterable<ObjectProp<T>>;
70
+ /**
71
+ * Extract the value of a named prop from an object.
33
72
  * - Extraction is possibly deep if deeper keys are specified.
34
73
  *
35
74
  * @param obj The target object to get from.
@@ -42,69 +81,17 @@ export declare function getProp<T extends ImmutableObject, K1 extends keyof T, K
42
81
  export declare function getProp<T extends ImmutableObject, K1 extends keyof T, K2 extends keyof T[K1], K3 extends keyof T[K1][K2]>(obj: T, k1: K1, k2: K2, k3: K3): T[K1][K2][K3];
43
82
  export declare function getProp<T extends ImmutableObject, K1 extends keyof T, K2 extends keyof T[K1]>(obj: T, k1: K1, k2: K2): T[K1][K2];
44
83
  export declare function getProp<T extends ImmutableObject, K1 extends keyof T>(obj: T, k1: K1): T[K1];
45
- /**
46
- * Set a prop on an object (immutably).
47
- *
48
- * @param input The input data object.
49
- * @param key The key of the entry to add.
50
- * @param value The value of the entry to add. If set, the entry will only be added if its current value is not `value`
51
- *
52
- * @return New object without the specified prop (or same object if prop value didn't change).
53
- */
84
+ /** Set a prop on an object (immutably) and return a new object including that prop. */
54
85
  export declare function withProp<T extends ImmutableObject, K extends keyof T>(input: T, key: K, value: T[K]): T;
55
- /**
56
- * Set several props on an object (immutably).
57
- *
58
- * @param input The input data object.
59
- * @param props Set of props to add to the object.
60
- * @return New object with the specified prop added (or same object if no props changed).
61
- */
62
- export declare function withProps<T extends ImmutableObject>(input: T, props: T | Partial<T>): T;
63
- /**
64
- * Remove several key/value entries from an object (immutably).
65
- *
66
- * @param input The input object.
67
- * @param keys Set of keys for props to remove.
68
- *
69
- * @return New object without the specified entries (or same object if none of the entries existed).
70
- */
71
- export declare function withoutProps<T extends ImmutableObject, K extends keyof T>(input: T, ...keys: K[]): Omit<T, K>;
72
- /**
73
- * Pick several props from an object (immutably).
74
- *
75
- * @param input The input object.
76
- * @param keys Set of keys for props to pick.
77
- *
78
- * @return New object with only the specified props.
79
- */
80
- export declare function pickProps<T extends ImmutableObject, K extends keyof T>(input: T, ...keys: (keyof T)[]): Pick<T, K>;
81
- /**
82
- * Set a single named prop on an object (by reference).
83
- *
84
- * @param data The target data object to modify.
85
- * @param key The key of the prop in the object to set.
86
- * @param value The value to set the prop to.
87
- */
88
- export declare function setProp<T extends MutableObject, K extends keyof T>(data: T, key: K, value: T[K]): T[K];
89
- /**
90
- * Set several named props on an object (by reference).
91
- *
92
- * @param obj The target object to modify.
93
- * @param props An object containing new props to set on the object.
94
- */
95
- export declare function setProps<T extends MutableObject>(obj: T, props: Partial<T>): void;
96
- /**
97
- * Remove several key/value entries from an object (by reference).
98
- *
99
- * @param obj The target object to modify.
100
- * @param keys Set of keys or keys to remove.
101
- */
86
+ /** Set several props on an object (immutably) and return a new object including those props. */
87
+ export declare function withProps<T extends ImmutableObject>(input: T, props: T | Partial<T> | Iterable<ObjectProp<T>>): T;
88
+ /** Remove several props from an object (immutably) and return a new object without those props. */
89
+ export declare function omitProps<T extends ImmutableObject, K extends keyof T>(input: T, ...keys: K[]): Omit<T, K>;
90
+ /** Pick several props from an object and return a new object with only thos props. */
91
+ export declare function pickProps<T extends ImmutableObject, K extends keyof T>(input: T, ...keys: K[]): Pick<T, K>;
92
+ /** Set a single named prop on an object (by reference) and return its value. */
93
+ export declare function setProp<T extends MutableObject, K extends keyof T>(obj: T, key: K, value: T[K]): T[K];
94
+ /** Set several named props on an object (by reference). */
95
+ export declare function setProps<T extends MutableObject>(obj: T, entries: T | Partial<T> | Iterable<ObjectProp<T>>): void;
96
+ /** Remove several key/value entries from an object (by reference). */
102
97
  export declare function deleteProps<T extends MutableObject>(obj: T, ...keys: (keyof T)[]): void;
103
- /** Type that represents an empty object. */
104
- export declare type EmptyObject = {
105
- readonly [K in never]: never;
106
- };
107
- /** An empty object. */
108
- export declare const EMPTY_OBJECT: EmptyObject;
109
- /** Function that returns an an empty object. */
110
- export declare const getEmptyObject: () => EmptyObject;