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.
- package/constraint/Constraints.js +3 -3
- package/constraint/FilterConstraint.d.ts +5 -5
- package/constraint/SortConstraint.d.ts +2 -2
- package/db/Change.d.ts +12 -12
- package/db/Collection.d.ts +4 -4
- package/db/Database.d.ts +29 -29
- package/db/Item.d.ts +4 -4
- package/db/Query.d.ts +4 -4
- package/feedback/Feedback.d.ts +2 -2
- package/feedback/Feedback.js +3 -2
- package/firestore/client/FirestoreClientProvider.js +2 -2
- package/firestore/lite/FirestoreLiteProvider.js +2 -2
- package/firestore/server/FirestoreServerProvider.js +2 -2
- package/package.json +1 -1
- package/provider/CacheProvider.d.ts +12 -12
- package/provider/DebugProvider.d.ts +21 -21
- package/provider/MemoryProvider.d.ts +16 -16
- package/provider/MemoryProvider.js +3 -3
- package/provider/Provider.d.ts +30 -30
- package/provider/ThroughProvider.d.ts +23 -23
- package/provider/ValidationProvider.d.ts +22 -22
- package/provider/ValidationProvider.js +2 -2
- package/react/useItem.d.ts +4 -4
- package/react/useQuery.d.ts +4 -4
- package/schema/AllowSchema.d.ts +25 -24
- package/schema/AllowSchema.js +25 -29
- package/schema/ArraySchema.d.ts +2 -2
- package/schema/BooleanSchema.d.ts +2 -2
- package/schema/DataSchema.d.ts +2 -2
- package/schema/DataSchema.js +2 -2
- package/schema/DateSchema.d.ts +2 -2
- package/schema/DictionarySchema.d.ts +19 -0
- package/schema/{ObjectSchema.js → DictionarySchema.js} +6 -6
- package/schema/LinkSchema.d.ts +2 -2
- package/schema/NumberSchema.d.ts +2 -2
- package/schema/Schema.d.ts +10 -8
- package/schema/Schema.js +1 -1
- package/schema/StringSchema.d.ts +12 -10
- package/schema/index.d.ts +1 -1
- package/schema/index.js +1 -1
- package/state/ArrayState.js +4 -4
- package/state/DataState.js +3 -3
- package/state/DictionaryState.d.ts +15 -0
- package/state/{ObjectState.js → DictionaryState.js} +6 -6
- package/state/index.d.ts +2 -2
- package/state/index.js +2 -2
- package/test/basics.js +1 -1
- package/update/ArrayUpdate.js +2 -2
- package/update/DataUpdate.d.ts +10 -9
- package/update/DataUpdate.js +6 -4
- package/update/DictionaryUpdate.d.ts +29 -0
- package/update/{ObjectUpdate.js → DictionaryUpdate.js} +14 -14
- package/update/hydrations.js +2 -2
- package/update/index.d.ts +1 -1
- package/update/index.js +1 -1
- package/util/array.d.ts +40 -111
- package/util/array.js +50 -114
- package/util/clone.d.ts +2 -2
- package/util/clone.js +5 -5
- package/util/data.d.ts +20 -53
- package/util/data.js +11 -1
- package/util/dictionary.d.ts +39 -0
- package/util/dictionary.js +33 -0
- package/util/diff.d.ts +3 -3
- package/util/entry.d.ts +7 -5
- package/util/entry.js +8 -6
- package/util/filter.d.ts +0 -5
- package/util/filter.js +0 -3
- package/util/hydrate.d.ts +2 -2
- package/util/hydrate.js +7 -8
- package/util/index.d.ts +1 -0
- package/util/index.js +1 -0
- package/util/map.d.ts +28 -6
- package/util/map.js +22 -6
- package/util/merge.d.ts +3 -6
- package/util/merge.js +4 -6
- package/util/object.d.ts +77 -90
- package/util/object.js +23 -76
- package/util/set.d.ts +10 -0
- package/util/set.js +17 -0
- package/util/template.d.ts +3 -3
- package/util/template.js +3 -3
- package/util/transform.d.ts +22 -45
- package/util/transform.js +20 -37
- package/util/units.d.ts +6 -12
- package/util/units.js +8 -4
- package/util/validate.d.ts +6 -5
- package/util/validate.js +5 -4
- package/schema/ObjectSchema.d.ts +0 -19
- package/state/ObjectState.d.ts +0 -16
- 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 {
|
|
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
|
|
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
|
|
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 {
|
|
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
|
|
23
|
-
export declare function getEntries<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 {
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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 =
|
|
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,
|
|
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
|
|
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, ...
|
|
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.
|
|
75
|
-
if (
|
|
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:
|
|
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
package/util/index.js
CHANGED
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
|
|
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
|
|
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<
|
|
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>(
|
|
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
|
-
/**
|
|
22
|
-
export declare
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
/**
|
|
26
|
-
export
|
|
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
|
|
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
|
|
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
|
|
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 (
|
|
10
|
-
return
|
|
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
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
/**
|
|
9
|
-
export declare type MutableObject<T = unknown> = {
|
|
10
|
-
[
|
|
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
|
-
*
|
|
14
|
-
* -
|
|
15
|
-
* -
|
|
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
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
export declare
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
*/
|
|
62
|
-
export declare function
|
|
63
|
-
/**
|
|
64
|
-
|
|
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;
|