normal-store 1.1.0 → 1.2.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/build/store/add.d.ts +5 -0
- package/build/store/add.js +10 -1
- package/build/store/add.js.map +1 -1
- package/build/store/addMany.d.ts +3 -3
- package/build/store/addMany.js +4 -4
- package/build/store/addMany.js.map +1 -1
- package/build/store/get.d.ts +5 -6
- package/build/store/get.js +4 -3
- package/build/store/get.js.map +1 -1
- package/build/store/has.d.ts +14 -1
- package/build/store/has.js +8 -2
- package/build/store/has.js.map +1 -1
- package/build/store/index.js +2 -2
- package/build/store/index.js.map +1 -1
- package/build/store/patch.d.ts +14 -1
- package/build/store/patch.js +12 -1
- package/build/store/patch.js.map +1 -1
- package/build/store/remove.d.ts +3 -2
- package/build/store/remove.js +0 -1
- package/build/store/remove.js.map +1 -1
- package/build/store/update.d.ts +9 -1
- package/build/store/update.js +8 -1
- package/build/store/update.js.map +1 -1
- package/package.json +1 -1
package/build/store/add.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { Normalized, NormalizedValue } from "../types";
|
|
2
|
+
import { AddMany } from './addMany';
|
|
2
3
|
export interface AddOne {
|
|
3
4
|
<T extends Normalized<any>>(store: T, key: string, value: NormalizedValue<T>): T;
|
|
4
5
|
}
|
|
6
|
+
export interface Add extends AddOne, AddMany {
|
|
7
|
+
}
|
|
5
8
|
export declare const prependOne: AddOne;
|
|
6
9
|
export declare const appendOne: AddOne;
|
|
10
|
+
export declare const prepend: Add;
|
|
11
|
+
export declare const append: Add;
|
package/build/store/add.js
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.appendOne = exports.prependOne = void 0;
|
|
3
|
+
exports.append = exports.prepend = exports.appendOne = exports.prependOne = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
|
+
const addMany_1 = require("./addMany");
|
|
5
6
|
const update_1 = require("./update");
|
|
6
7
|
const prependOne = (normalized, key, value) => (Object.assign(Object.assign({}, (0, update_1.updateOne)(normalized, key, value)), { allKeys: (0, utils_1.prependUnique)(normalized.allKeys, key) }));
|
|
7
8
|
exports.prependOne = prependOne;
|
|
8
9
|
const appendOne = (normalized, key, value) => (Object.assign(Object.assign({}, (0, update_1.updateOne)(normalized, key, value)), { allKeys: (0, utils_1.appendUnique)(normalized.allKeys, key) }));
|
|
9
10
|
exports.appendOne = appendOne;
|
|
11
|
+
const prepend = (store, keyOrValues, valueOrGetKey) => Array.isArray(keyOrValues)
|
|
12
|
+
? (0, addMany_1.prependMany)(store, keyOrValues, valueOrGetKey)
|
|
13
|
+
: (0, exports.prependOne)(store, keyOrValues, valueOrGetKey);
|
|
14
|
+
exports.prepend = prepend;
|
|
15
|
+
const append = (store, keyOrValues, valueOrGetKey) => Array.isArray(keyOrValues)
|
|
16
|
+
? (0, addMany_1.appendMany)(store, keyOrValues, valueOrGetKey)
|
|
17
|
+
: (0, exports.appendOne)(store, keyOrValues, valueOrGetKey);
|
|
18
|
+
exports.append = append;
|
|
10
19
|
//# sourceMappingURL=add.js.map
|
package/build/store/add.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add.js","sourceRoot":"","sources":["../../src/store/add.ts"],"names":[],"mappings":";;;AACA,oCAAsD;AAEtD,qCAAqC;
|
|
1
|
+
{"version":3,"file":"add.js","sourceRoot":"","sources":["../../src/store/add.ts"],"names":[],"mappings":";;;AACA,oCAAsD;AAEtD,uCAA6D;AAC7D,qCAAqC;AAQ9B,MAAM,UAAU,GAAW,CAA4B,UAAa,EAAE,GAAW,EAAE,KAAyB,EAAK,EAAE,CAAC,iCACtH,IAAA,kBAAS,EAAC,UAAU,EAAE,GAAG,EAAE,KAAK,CAAC,KACpC,OAAO,EAAE,IAAA,qBAAa,EAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,IAC/C,CAAC;AAHU,QAAA,UAAU,cAGpB;AAEI,MAAM,SAAS,GAAW,CAA4B,UAAa,EAAE,GAAW,EAAE,KAAyB,EAAK,EAAE,CAAC,iCACrH,IAAA,kBAAS,EAAC,UAAU,EAAE,GAAG,EAAE,KAAK,CAAC,KACpC,OAAO,EAAE,IAAA,oBAAY,EAAC,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,IAC9C,CAAC;AAHU,QAAA,SAAS,aAGnB;AAEI,MAAM,OAAO,GAAQ,CAC1B,KAAQ,EACR,WAA0C,EAC1C,aAA+D,EAC5D,EAAE,CACL,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC;IACxB,CAAC,CAAC,IAAA,qBAAW,EAAC,KAAK,EAAE,WAAW,EAAE,aAA2C,CAAC;IAC9E,CAAC,CAAC,IAAA,kBAAU,EAAC,KAAK,EAAE,WAAW,EAAE,aAAmC,CAAC,CAAC;AAP7D,QAAA,OAAO,WAOsD;AAEnE,MAAM,MAAM,GAAQ,CACzB,KAAQ,EACR,WAA0C,EAC1C,aAA+D,EAC5D,EAAE,CACL,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC;IACxB,CAAC,CAAC,IAAA,oBAAU,EAAC,KAAK,EAAE,WAAW,EAAE,aAA2C,CAAC;IAC7E,CAAC,CAAC,IAAA,iBAAS,EAAC,KAAK,EAAE,WAAW,EAAE,aAAmC,CAAC,CAAC;AAP5D,QAAA,MAAM,UAOsD"}
|
package/build/store/addMany.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { GetKey, Identifiable, Normalized } from "../types";
|
|
1
|
+
import { GetKey, Identifiable, Normalized, NormalizedValue } from "../types";
|
|
2
2
|
export interface AddMany {
|
|
3
|
-
<T extends Normalized<Identifiable>>(store: T, values: T[]): T;
|
|
4
|
-
<T extends Normalized<any>>(store: T, values: T[], getKey: GetKey<T
|
|
3
|
+
<T extends Normalized<Identifiable>>(store: T, values: NormalizedValue<T>[]): T;
|
|
4
|
+
<T extends Normalized<any>>(store: T, values: NormalizedValue<T>[], getKey: GetKey<NormalizedValue<T>>): T;
|
|
5
5
|
}
|
|
6
6
|
export declare const prependMany: AddMany;
|
|
7
7
|
export declare const appendMany: AddMany;
|
package/build/store/addMany.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.appendMany = exports.prependMany = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const newKeys = (0, utils_1.withoutValues)(values.map(
|
|
8
|
-
return Object.assign(Object.assign(
|
|
5
|
+
const update_1 = require("./update");
|
|
6
|
+
const addMany = (store, values, mergeKeys, getKey = utils_1.defaultGetKey) => {
|
|
7
|
+
const newKeys = (0, utils_1.withoutValues)(values.map(getKey), store.allKeys);
|
|
8
|
+
return Object.assign(Object.assign(Object.assign({}, store), (0, update_1.updateMany)(store, values, getKey)), { allKeys: mergeKeys(store.allKeys, newKeys) });
|
|
9
9
|
};
|
|
10
10
|
const prependMany = (store, values, getKey) => addMany(store, values, (allKeys, newKeys) => [...newKeys, ...allKeys], getKey);
|
|
11
11
|
exports.prependMany = prependMany;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addMany.js","sourceRoot":"","sources":["../../src/store/addMany.ts"],"names":[],"mappings":";;;AACA,oCAAuD;
|
|
1
|
+
{"version":3,"file":"addMany.js","sourceRoot":"","sources":["../../src/store/addMany.ts"],"names":[],"mappings":";;;AACA,oCAAuD;AAEvD,qCAAsC;AAOtC,MAAM,OAAO,GAAG,CACd,KAAQ,EACR,MAA4B,EAC5B,SAA6D,EAC7D,SAAY,qBAA6B,EACtC,EAAE;IACL,MAAM,OAAO,GAAG,IAAA,qBAAa,EAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAEjE,qDACK,KAAK,GACL,IAAA,mBAAU,EAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,KACpC,OAAO,EAAE,SAAS,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,IAC1C;AACJ,CAAC,CAAC;AAEK,MAAM,WAAW,GAAY,CAA4B,KAAQ,EAAE,MAA4B,EAAE,MAAmC,EAAE,EAAE,CAC7I,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC;AADpE,QAAA,WAAW,eACyD;AAE1E,MAAM,UAAU,GAAY,CAA4B,KAAQ,EAAE,MAA4B,EAAE,MAAmC,EAAE,EAAE,CAC5I,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC;AADpE,QAAA,UAAU,cAC0D"}
|
package/build/store/get.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { Normalized } from "../types";
|
|
1
|
+
import { Normalized, NormalizedValue } from "../types";
|
|
2
2
|
export interface GetOne {
|
|
3
|
-
<T
|
|
4
|
-
<T extends Normalized<any>>(store: T, key: string): T extends Normalized<infer R> ? R | null : never;
|
|
3
|
+
<T extends Normalized<any>>(store: T, key: string): NormalizedValue<T> | null;
|
|
5
4
|
}
|
|
6
5
|
export interface GetMany {
|
|
7
|
-
<T
|
|
8
|
-
|
|
6
|
+
<T extends Normalized<any>>(store: T, keys: string[]): NormalizedValue<T>[];
|
|
7
|
+
}
|
|
8
|
+
export interface Get extends GetMany, GetOne {
|
|
9
9
|
}
|
|
10
|
-
export declare type Get = GetOne & GetMany;
|
|
11
10
|
export declare const getMany: GetMany;
|
|
12
11
|
export declare const getOne: GetOne;
|
|
13
12
|
export declare const get: Get;
|
package/build/store/get.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.get = exports.getOne = exports.getMany = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
4
5
|
const has_1 = require("./has");
|
|
5
|
-
const getMany = (
|
|
6
|
+
const getMany = (store, keys) => keys.filter((0, has_1.hasOneCurry)(store)).map((0, utils_1.getByKey)(store.byKey));
|
|
6
7
|
exports.getMany = getMany;
|
|
7
|
-
const getOne = (store, key) => (
|
|
8
|
+
const getOne = (store, key) => (0, has_1.hasOne)(store, key) ? store.byKey[key] : null;
|
|
8
9
|
exports.getOne = getOne;
|
|
9
|
-
const get = (store, keys) =>
|
|
10
|
+
const get = (store, keys) => Array.isArray(keys) ? (0, exports.getMany)(store, keys) : (0, exports.getOne)(store, keys);
|
|
10
11
|
exports.get = get;
|
|
11
12
|
//# sourceMappingURL=get.js.map
|
package/build/store/get.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../src/store/get.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"get.js","sourceRoot":"","sources":["../../src/store/get.ts"],"names":[],"mappings":";;;AACA,oCAAmC;AAEnC,+BAA4C;AAYrC,MAAM,OAAO,GAAY,CAA4B,KAAQ,EAAE,IAAc,EAAwB,EAAE,CAC5G,IAAI,CAAC,MAAM,CAAC,IAAA,iBAAW,EAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,IAAA,gBAAQ,EAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;AADhD,QAAA,OAAO,WACyC;AAEtD,MAAM,MAAM,GAAW,CAA4B,KAAQ,EAAE,GAAW,EAA6B,EAAE,CAC5G,IAAA,YAAM,EAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AADlC,QAAA,MAAM,UAC4B;AAExC,MAAM,GAAG,GAAQ,CAA4B,KAAQ,EAAE,IAAuB,EAAO,EAAE,CAC5F,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,eAAO,EAAI,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,cAAM,EAAI,KAAK,EAAE,IAAI,CAAC,CAAC;AAD5D,QAAA,GAAG,OACyD"}
|
package/build/store/has.d.ts
CHANGED
|
@@ -2,10 +2,23 @@ import { Normalized } from "../types";
|
|
|
2
2
|
export interface HasOne {
|
|
3
3
|
<T extends Normalized<any>>(store: T, key: string): boolean;
|
|
4
4
|
}
|
|
5
|
+
export interface HasOneCurry {
|
|
6
|
+
<T extends Normalized<any>>(store: T): (key: string) => boolean;
|
|
7
|
+
}
|
|
5
8
|
export interface HasMany {
|
|
6
9
|
<T extends Normalized<any>>(store: T, keys: string[]): boolean;
|
|
7
10
|
}
|
|
8
|
-
export
|
|
11
|
+
export interface HasManyCurry {
|
|
12
|
+
<T extends Normalized<any>>(store: T): (keys: string[]) => boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface Has extends HasOne, HasMany {
|
|
15
|
+
}
|
|
16
|
+
export interface HasCurry {
|
|
17
|
+
<T extends Normalized<any>>(store: T): (keys: string | string[]) => boolean;
|
|
18
|
+
}
|
|
9
19
|
export declare const hasMany: HasMany;
|
|
20
|
+
export declare const hasManyCurry: HasManyCurry;
|
|
10
21
|
export declare const hasOne: HasOne;
|
|
22
|
+
export declare const hasOneCurry: HasOneCurry;
|
|
11
23
|
export declare const has: Has;
|
|
24
|
+
export declare const hasCurry: HasCurry;
|
package/build/store/has.js
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.has = exports.hasOne = exports.hasMany = void 0;
|
|
3
|
+
exports.hasCurry = exports.has = exports.hasOneCurry = exports.hasOne = exports.hasManyCurry = exports.hasMany = void 0;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
|
-
const hasMany = (
|
|
5
|
+
const hasMany = (store, keys) => keys.every((key) => (0, exports.hasOne)(store, key));
|
|
6
6
|
exports.hasMany = hasMany;
|
|
7
|
+
const hasManyCurry = (store) => (keys) => (0, exports.hasMany)(store, keys);
|
|
8
|
+
exports.hasManyCurry = hasManyCurry;
|
|
7
9
|
const hasOne = ({ byKey }, key) => (0, utils_1.hasProperty)(byKey, key);
|
|
8
10
|
exports.hasOne = hasOne;
|
|
11
|
+
const hasOneCurry = (store) => (key) => (0, exports.hasOne)(store, key);
|
|
12
|
+
exports.hasOneCurry = hasOneCurry;
|
|
9
13
|
const has = (store, keys) => (Array.isArray(keys) ? (0, exports.hasMany)(store, keys) : (0, exports.hasOne)(store, keys));
|
|
10
14
|
exports.has = has;
|
|
15
|
+
const hasCurry = (store) => (keys) => Array.isArray(keys) ? (0, exports.hasMany)(store, keys) : (0, exports.hasOne)(store, keys);
|
|
16
|
+
exports.hasCurry = hasCurry;
|
|
11
17
|
//# sourceMappingURL=has.js.map
|
package/build/store/has.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"has.js","sourceRoot":"","sources":["../../src/store/has.ts"],"names":[],"mappings":";;;AACA,oCAAsC;
|
|
1
|
+
{"version":3,"file":"has.js","sourceRoot":"","sources":["../../src/store/has.ts"],"names":[],"mappings":";;;AACA,oCAAsC;AAwB/B,MAAM,OAAO,GAAY,CAAC,KAAsB,EAAE,IAAc,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,IAAA,cAAM,EAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;AAAvG,QAAA,OAAO,WAAgG;AAE7G,MAAM,YAAY,GAAiB,CAAC,KAAsB,EAAE,EAAE,CAAC,CAAC,IAAc,EAAE,EAAE,CAAC,IAAA,eAAO,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AAAlG,QAAA,YAAY,gBAAsF;AAExG,MAAM,MAAM,GAAW,CAAC,EAAE,KAAK,EAAmB,EAAE,GAAW,EAAE,EAAE,CAAC,IAAA,mBAAW,EAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAAtF,QAAA,MAAM,UAAgF;AAE5F,MAAM,WAAW,GAAgB,CAAC,KAAsB,EAAE,EAAE,CAAC,CAAC,GAAW,EAAE,EAAE,CAAC,IAAA,cAAM,EAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AAA3F,QAAA,WAAW,eAAgF;AAEjG,MAAM,GAAG,GAAQ,CAAC,KAAsB,EAAE,IAAuB,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,eAAO,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,cAAM,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;AAAnI,QAAA,GAAG,OAAgI;AAEzI,MAAM,QAAQ,GAAa,CAAC,KAAsB,EAAE,EAAE,CAAC,CAAC,IAAuB,EAAE,EAAE,CACxF,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,eAAO,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,cAAM,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AADtD,QAAA,QAAQ,YAC8C"}
|
package/build/store/index.js
CHANGED
|
@@ -20,8 +20,8 @@ __exportStar(require("./patch"), exports);
|
|
|
20
20
|
__exportStar(require("./remove"), exports);
|
|
21
21
|
__exportStar(require("./reorder"), exports);
|
|
22
22
|
__exportStar(require("./update"), exports);
|
|
23
|
-
const normalize = (items, getKey) => {
|
|
24
|
-
const allKeys = items.map(getKey
|
|
23
|
+
const normalize = (items, getKey = utils_1.defaultGetKey) => {
|
|
24
|
+
const allKeys = items.map(getKey);
|
|
25
25
|
return {
|
|
26
26
|
byKey: (0, utils_1.buildLookup)(allKeys, (0, utils_1.getByIndex)(items)),
|
|
27
27
|
allKeys,
|
package/build/store/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,oCAAiE;AAEjE,wCAAsB;AACtB,4CAA0B;AAC1B,wCAAsB;AACtB,wCAAsB;AACtB,0CAAwB;AACxB,2CAAyB;AACzB,4CAA0B;AAC1B,2CAAyB;AAOlB,MAAM,SAAS,GAAc,CAAmC,KAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/store/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA,oCAAiE;AAEjE,wCAAsB;AACtB,4CAA0B;AAC1B,wCAAsB;AACtB,wCAAsB;AACtB,0CAAwB;AACxB,2CAAyB;AACzB,4CAA0B;AAC1B,2CAAyB;AAOlB,MAAM,SAAS,GAAc,CAAmC,KAAU,EAAE,SAAoB,qBAA0B,EAAE,EAAE;IACnI,MAAM,OAAO,GAAG,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAElC,OAAO;QACL,KAAK,EAAE,IAAA,mBAAW,EAAI,OAAO,EAAE,IAAA,kBAAU,EAAI,KAAK,CAAC,CAAC;QACpD,OAAO;KACR,CAAC;AACJ,CAAC,CAAC;AAPW,QAAA,SAAS,aAOpB;AAEK,MAAM,WAAW,GAAG,CAAI,EAAE,OAAO,EAAE,KAAK,EAAiB,EAAO,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AAA9F,QAAA,WAAW,eAAmF;AAEpG,MAAM,WAAW,GAAG,GAAqB,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;AAAnE,QAAA,WAAW,eAAwD"}
|
package/build/store/patch.d.ts
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { Normalized, NormalizedValue } from "../types";
|
|
2
|
+
declare type PatchValue<T extends Normalized<any>> = Partial<NormalizedValue<T>> | ((value: NormalizedValue<T>) => Partial<NormalizedValue<T>>);
|
|
2
3
|
export interface PatchOne {
|
|
3
|
-
<T extends Normalized<any>>(store: T, key: string, patch:
|
|
4
|
+
<T extends Normalized<any>>(store: T, key: string, patch: PatchValue<T>): T;
|
|
5
|
+
}
|
|
6
|
+
export interface PatchManyItem<T extends Normalized<any>> {
|
|
7
|
+
key: string;
|
|
8
|
+
value: PatchValue<T>;
|
|
9
|
+
}
|
|
10
|
+
export interface PatchMany {
|
|
11
|
+
<T extends Normalized<any>>(store: T, patches: PatchManyItem<T>[]): T;
|
|
12
|
+
}
|
|
13
|
+
export interface Patch extends PatchOne, PatchMany {
|
|
4
14
|
}
|
|
5
15
|
export declare const patchOne: PatchOne;
|
|
16
|
+
export declare const patchMany: PatchMany;
|
|
17
|
+
export declare const patch: Patch;
|
|
18
|
+
export {};
|
package/build/store/patch.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.patchOne = void 0;
|
|
3
|
+
exports.patch = exports.patchMany = exports.patchOne = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
4
5
|
const get_1 = require("./get");
|
|
5
6
|
const has_1 = require("./has");
|
|
6
7
|
const update_1 = require("./update");
|
|
@@ -11,4 +12,14 @@ const patchOne = (store, key, patch) => {
|
|
|
11
12
|
return (0, update_1.updateOne)(store, key, Object.assign(Object.assign({}, value), (typeof patch === 'function' ? patch(value) : patch)));
|
|
12
13
|
};
|
|
13
14
|
exports.patchOne = patchOne;
|
|
15
|
+
const patchMany = (store, patches) => {
|
|
16
|
+
const patchesToPerform = patches.filter(({ key }) => (0, has_1.hasOne)(store, key));
|
|
17
|
+
if (patchesToPerform.length === 0)
|
|
18
|
+
return store;
|
|
19
|
+
const values = patchesToPerform.map(({ key, value }) => (Object.assign(Object.assign({}, (0, get_1.getOne)(store, key)), (typeof value === 'function' ? value((0, get_1.getOne)(store, key)) : value))));
|
|
20
|
+
return Object.assign(Object.assign({}, store), { byKey: Object.assign(Object.assign({}, store.byKey), (0, utils_1.buildLookup)(patchesToPerform.map(({ key }) => key), (0, utils_1.getByIndex)(values))) });
|
|
21
|
+
};
|
|
22
|
+
exports.patchMany = patchMany;
|
|
23
|
+
const patch = (store, keyOrPatches, value) => Array.isArray(keyOrPatches) ? (0, exports.patchMany)(store, keyOrPatches) : (0, exports.patchOne)(store, keyOrPatches, value);
|
|
24
|
+
exports.patch = patch;
|
|
14
25
|
//# sourceMappingURL=patch.js.map
|
package/build/store/patch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../../src/store/patch.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"patch.js","sourceRoot":"","sources":["../../src/store/patch.ts"],"names":[],"mappings":";;;AACA,oCAAkD;AAElD,+BAA+B;AAC/B,+BAA+B;AAC/B,qCAAqC;AAmB9B,MAAM,QAAQ,GAAa,CAA4B,KAAQ,EAAE,GAAW,EAAE,KAAoB,EAAK,EAAE;IAC9G,IAAI,CAAC,IAAA,YAAM,EAAC,KAAK,EAAE,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IAEtC,MAAM,KAAK,GAAG,IAAA,YAAM,EAAC,KAAK,EAAE,GAAG,CAAE,CAAC;IAElC,OAAO,IAAA,kBAAS,EAAC,KAAK,EAAE,GAAG,kCAAO,KAAK,GAAK,CAAC,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAG,CAAC;AACtG,CAAC,CAAC;AANW,QAAA,QAAQ,YAMnB;AAEK,MAAM,SAAS,GAAc,CAA4B,KAAQ,EAAE,OAA2B,EAAK,EAAE;IAC1G,MAAM,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,IAAA,YAAM,EAAC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC;IAEzE,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAEhD,MAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,iCACnD,IAAA,YAAM,EAAC,KAAK,EAAE,GAAG,CAAE,GACnB,CAAC,OAAO,KAAK,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAA,YAAM,EAAC,KAAK,EAAE,GAAG,CAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EACrE,CAAC,CAAC;IAEJ,uCACK,KAAK,KACR,KAAK,kCACA,KAAK,CAAC,KAAK,GACX,IAAA,mBAAW,EACZ,gBAAgB,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,EACtC,IAAA,kBAAU,EAAC,MAAM,CAAC,CACnB,KAEH;AACJ,CAAC,CAAC;AApBW,QAAA,SAAS,aAoBpB;AAEK,MAAM,KAAK,GAAU,CAA4B,KAAQ,EAAE,YAAyC,EAAE,KAAqB,EAAK,EAAE,CACvI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAA,iBAAS,EAAC,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,IAAA,gBAAQ,EAAC,KAAK,EAAE,YAAY,EAAE,KAAsB,CAAC,CAAC;AAD1G,QAAA,KAAK,SACqG"}
|
package/build/store/remove.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ export interface RemoveOne {
|
|
|
5
5
|
export interface RemoveMany {
|
|
6
6
|
<T extends Normalized<any>>(store: T, keys: string[]): T;
|
|
7
7
|
}
|
|
8
|
-
export
|
|
8
|
+
export interface Remove extends RemoveOne, RemoveMany {
|
|
9
|
+
}
|
|
9
10
|
export declare const removeOne: RemoveOne;
|
|
10
11
|
export declare const removeMany: RemoveMany;
|
|
11
|
-
export declare const remove:
|
|
12
|
+
export declare const remove: Remove;
|
package/build/store/remove.js
CHANGED
|
@@ -12,7 +12,6 @@ const removeMany = (store, keys) => {
|
|
|
12
12
|
return Object.assign(Object.assign({}, store), { allKeys: filteredKeys, byKey: (0, utils_1.buildLookup)(filteredKeys, (0, utils_1.getByKey)(store.byKey)) });
|
|
13
13
|
};
|
|
14
14
|
exports.removeMany = removeMany;
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
16
15
|
const remove = (store, keys) => Array.isArray(keys) ? (0, exports.removeMany)(store, keys) : (0, exports.removeOne)(store, keys);
|
|
17
16
|
exports.remove = remove;
|
|
18
17
|
//# sourceMappingURL=remove.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove.js","sourceRoot":"","sources":["../../src/store/remove.ts"],"names":[],"mappings":";;;AACA,oCAA6E;AAYtE,MAAM,SAAS,GAAc,CAA4B,KAAQ,EAAE,GAAW,
|
|
1
|
+
{"version":3,"file":"remove.js","sourceRoot":"","sources":["../../src/store/remove.ts"],"names":[],"mappings":";;;AACA,oCAA6E;AAYtE,MAAM,SAAS,GAAc,CAA4B,KAAQ,EAAE,GAAW,EAAK,EAAE;IAC1F,MAAM,YAAY,GAAG,IAAA,oBAAY,EAAC,KAAK,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IAEtD,uCACK,KAAK,KACR,OAAO,EAAE,YAAY,EACrB,KAAK,EAAE,IAAA,mBAAW,EAAC,YAAY,EAAE,IAAA,gBAAQ,EAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IACvD;AACJ,CAAC,CAAC;AARW,QAAA,SAAS,aAQpB;AAEK,MAAM,UAAU,GAAe,CAA4B,KAAQ,EAAE,IAAc,EAAK,EAAE;IAC/F,MAAM,YAAY,GAAG,IAAA,qBAAa,EAAC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAExD,uCACK,KAAK,KACR,OAAO,EAAE,YAAY,EACrB,KAAK,EAAE,IAAA,mBAAW,EAAC,YAAY,EAAE,IAAA,gBAAQ,EAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IACvD;AACJ,CAAC,CAAC;AARW,QAAA,UAAU,cAQrB;AAEK,MAAM,MAAM,GAAW,CAA4B,KAAQ,EAAE,IAAuB,EAAK,EAAE,CAChG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,kBAAU,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,iBAAS,EAAC,KAAK,EAAE,IAAI,CAAC,CAAC;AAD5D,QAAA,MAAM,UACsD"}
|
package/build/store/update.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import { Normalized, NormalizedValue } from "../types";
|
|
1
|
+
import { GetKey, Identifiable, Normalized, NormalizedValue } from "../types";
|
|
2
2
|
export interface UpdateOne {
|
|
3
3
|
<T extends Normalized<any>>(store: T, key: string, update: NormalizedValue<T>): T;
|
|
4
4
|
}
|
|
5
|
+
export interface UpdateMany {
|
|
6
|
+
<T extends Normalized<Identifiable>>(store: T, values: NormalizedValue<T>[]): T;
|
|
7
|
+
<T extends Normalized<any>>(store: T, values: NormalizedValue<T>[], getKey: GetKey<NormalizedValue<T>>): T;
|
|
8
|
+
}
|
|
9
|
+
export interface Update extends UpdateOne, UpdateMany {
|
|
10
|
+
}
|
|
5
11
|
export declare const updateOne: UpdateOne;
|
|
12
|
+
export declare const updateMany: UpdateMany;
|
|
13
|
+
export declare const update: Update;
|
package/build/store/update.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.updateOne = void 0;
|
|
3
|
+
exports.update = exports.updateMany = exports.updateOne = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
4
5
|
const updateOne = (store, key, value) => (Object.assign(Object.assign({}, store), { byKey: Object.assign(Object.assign({}, store.byKey), { [key]: value }) }));
|
|
5
6
|
exports.updateOne = updateOne;
|
|
7
|
+
const updateMany = (store, values, getKey = utils_1.defaultGetKey) => (Object.assign(Object.assign({}, store), { byKey: Object.assign(Object.assign({}, store.byKey), (0, utils_1.buildLookup)(values.map(getKey), (0, utils_1.getByIndex)(values))) }));
|
|
8
|
+
exports.updateMany = updateMany;
|
|
9
|
+
const update = (store, keyOrValues, valueOrGetKey) => Array.isArray(keyOrValues)
|
|
10
|
+
? (0, exports.updateMany)(store, keyOrValues, valueOrGetKey)
|
|
11
|
+
: (0, exports.updateOne)(store, keyOrValues, valueOrGetKey);
|
|
12
|
+
exports.update = update;
|
|
6
13
|
//# sourceMappingURL=update.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../src/store/update.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"update.js","sourceRoot":"","sources":["../../src/store/update.ts"],"names":[],"mappings":";;;AACA,oCAAiE;AAa1D,MAAM,SAAS,GAAc,CAA4B,KAAQ,EAAE,GAAW,EAAE,KAAyB,EAAK,EAAE,CAAC,iCACnH,KAAK,KACR,KAAK,kCAAO,KAAK,CAAC,KAAK,KAAE,CAAC,GAAG,CAAC,EAAE,KAAK,OACrC,CAAC;AAHU,QAAA,SAAS,aAGnB;AAEI,MAAM,UAAU,GAAe,CACpC,KAAQ,EACR,MAA4B,EAC5B,SAAqC,qBAA2C,EAC7E,EAAE,CAAC,iCACH,KAAK,KACR,KAAK,kCAAO,KAAK,CAAC,KAAK,GAAK,IAAA,mBAAW,EAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,IAAA,kBAAU,EAAC,MAAM,CAAC,CAAC,KAC/E,CAAC;AAPU,QAAA,UAAU,cAOpB;AAEI,MAAM,MAAM,GAAW,CAC5B,KAAQ,EACR,WAA0C,EAC1C,aAA+D,EAC5D,EAAE,CACL,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC;IACxB,CAAC,CAAC,IAAA,kBAAU,EAAC,KAAK,EAAE,WAAW,EAAE,aAA2C,CAAC;IAC7E,CAAC,CAAC,IAAA,iBAAS,EAAC,KAAK,EAAE,WAAW,EAAE,aAAmC,CAAC,CAAC;AAP5D,QAAA,MAAM,UAOsD"}
|
package/package.json
CHANGED