cross-state 0.56.4 → 1.0.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/dist/{diff-CElc7pJI.d.ts → diff-CAQaunfv.d.cts} +3 -3
- package/dist/{diff-BslUrJZE.d.cts → diff-DFvRd-Gf.d.ts} +3 -3
- package/dist/{extendedJson-BZkQBXEv.js → extendedJson-Dv9q6rps.js} +2 -2
- package/dist/{extendedJson-BZkQBXEv.js.map → extendedJson-Dv9q6rps.js.map} +1 -1
- package/dist/{extendedJson-Dn2F7Edo.cjs → extendedJson-ursQ8DbQ.cjs} +1 -1
- package/dist/{extendedJson-Dn2F7Edo.cjs.map → extendedJson-ursQ8DbQ.cjs.map} +1 -1
- package/dist/index.cjs +9 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +7 -9
- package/dist/index.js.map +1 -1
- package/dist/mutative/index.cjs +2 -1
- package/dist/mutative/index.d.cts +2 -2
- package/dist/mutative/index.d.ts +2 -2
- package/dist/mutative/index.js +2 -1
- package/dist/mutative/register.cjs +4 -3
- package/dist/mutative/register.cjs.map +1 -1
- package/dist/mutative/register.d.cts +2 -4
- package/dist/mutative/register.d.ts +2 -2
- package/dist/mutative/register.js +4 -3
- package/dist/mutative/register.js.map +1 -1
- package/dist/{mutativeMethods-Bhd1Yi22.d.ts → mutativeMethods-BT1Cim3p.d.ts} +3 -3
- package/dist/{mutativeMethods-DWhwZRzv.d.cts → mutativeMethods-C8VcZWED.d.cts} +3 -3
- package/dist/{mutativeMethods-CgXk_bMt.cjs → mutativeMethods-CkNycpO9.cjs} +6 -7
- package/dist/{mutativeMethods-CgXk_bMt.cjs.map → mutativeMethods-CkNycpO9.cjs.map} +1 -1
- package/dist/{mutativeMethods-CZKeRIDL.js → mutativeMethods-Jowr0Znn.js} +4 -6
- package/dist/{mutativeMethods-CZKeRIDL.js.map → mutativeMethods-Jowr0Znn.js.map} +1 -1
- package/dist/{patchMethods-hhlLwtqE.cjs → patchMethods-B7Hm5-Qh.cjs} +4 -6
- package/dist/{patchMethods-hhlLwtqE.cjs.map → patchMethods-B7Hm5-Qh.cjs.map} +1 -1
- package/dist/{patchMethods-DXWygPZ6.d.ts → patchMethods-BmyvvHnP.d.cts} +4 -4
- package/dist/{patchMethods-BT4Tg5aG.d.cts → patchMethods-CixmHmNt.d.ts} +4 -4
- package/dist/{patchMethods-C_f3PORQ.js → patchMethods-iK2F87G0.js} +5 -7
- package/dist/{patchMethods-C_f3PORQ.js.map → patchMethods-iK2F87G0.js.map} +1 -1
- package/dist/patches/index.cjs +3 -3
- package/dist/patches/index.d.cts +3 -3
- package/dist/patches/index.d.ts +3 -3
- package/dist/patches/index.js +3 -3
- package/dist/patches/register.cjs +4 -4
- package/dist/patches/register.cjs.map +1 -1
- package/dist/patches/register.d.cts +3 -5
- package/dist/patches/register.d.ts +3 -3
- package/dist/patches/register.js +4 -4
- package/dist/patches/register.js.map +1 -1
- package/dist/{chunk-CUT6urMc.cjs → path-B-Rq5q6m.cjs} +14 -1
- package/dist/path-B-Rq5q6m.cjs.map +1 -0
- package/dist/path-CyYq74W8.js +8 -0
- package/dist/path-CyYq74W8.js.map +1 -0
- package/dist/persist/register.cjs +5 -5
- package/dist/persist/register.cjs.map +1 -1
- package/dist/persist/register.d.cts +2 -4
- package/dist/persist/register.d.ts +2 -2
- package/dist/persist/register.js +5 -5
- package/dist/persist/register.js.map +1 -1
- package/dist/{persist-CLgS5Cqw.js → persist-Bunx8xfQ.js} +12 -15
- package/dist/persist-Bunx8xfQ.js.map +1 -0
- package/dist/{persist-olbNkcdZ.d.ts → persist-CHRYYolx.d.cts} +3 -3
- package/dist/{persist-DboMIMOK.cjs → persist-DMbVdqS_.cjs} +11 -14
- package/dist/persist-DMbVdqS_.cjs.map +1 -0
- package/dist/{persist-DVKRq8RQ.d.cts → persist-DyI_JLxZ.d.ts} +3 -3
- package/dist/{propAccess-BdLsqViO.cjs → propAccess-C2AIn9RC.cjs} +4 -6
- package/dist/{propAccess-BdLsqViO.cjs.map → propAccess-C2AIn9RC.cjs.map} +1 -1
- package/dist/{propAccess-B260LXN1.js → propAccess-DvWFpYoj.js} +5 -7
- package/dist/{propAccess-B260LXN1.js.map → propAccess-DvWFpYoj.js.map} +1 -1
- package/dist/react/index.cjs +66 -80
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +70 -70
- package/dist/react/index.d.ts +70 -70
- package/dist/react/index.js +62 -77
- package/dist/react/index.js.map +1 -1
- package/dist/react/register.cjs +5 -5
- package/dist/react/register.cjs.map +1 -1
- package/dist/react/register.d.cts +3 -5
- package/dist/react/register.d.ts +3 -3
- package/dist/react/register.js +5 -5
- package/dist/react/register.js.map +1 -1
- package/dist/{scope-CfLlLxo9.cjs → scope-C1bcfK8e.cjs} +32 -7
- package/dist/scope-C1bcfK8e.cjs.map +1 -0
- package/dist/{scope-D3jkIPgn.d.ts → scope-CESkVNvI.d.cts} +3 -3
- package/dist/{scope-7LeON9bZ.js → scope-CKGsCVn3.js} +20 -7
- package/dist/scope-CKGsCVn3.js.map +1 -0
- package/dist/{scope-CcBxgcrs.d.cts → scope-DJXSRsGy.d.ts} +3 -3
- package/dist/{store-MBrcOgtz.d.cts → store-BRHFhRPm.d.ts} +21 -21
- package/dist/{store-CdST5wJZ.cjs → store-C1NYHLgR.cjs} +12 -13
- package/dist/store-C1NYHLgR.cjs.map +1 -0
- package/dist/{store-DnZ6fsiJ.d.ts → store-XcnTdeiJ.d.cts} +21 -21
- package/dist/{store-Dx8w7yT-.js → store-v3RYWzVg.js} +13 -14
- package/dist/store-v3RYWzVg.js.map +1 -0
- package/dist/{storeMethods-B_RzvMaV.cjs → storeMethods-CNu7VD6w.cjs} +135 -60
- package/dist/storeMethods-CNu7VD6w.cjs.map +1 -0
- package/dist/{storeMethods-BrKuusQ2.js → storeMethods-CQhXlHpl.js} +115 -59
- package/dist/storeMethods-CQhXlHpl.js.map +1 -0
- package/dist/{storeMethods-CmWv1YMe.d.cts → storeMethods-Dsz0-Cda.d.ts} +4 -4
- package/dist/{storeMethods-Cb1ur5K3.d.ts → storeMethods-y3PlfTHV.d.cts} +4 -4
- package/package.json +26 -37
- package/dist/hash-DNFM5y_h.js +0 -19
- package/dist/hash-DNFM5y_h.js.map +0 -1
- package/dist/hash-Dv3XlmHn.cjs +0 -30
- package/dist/hash-Dv3XlmHn.cjs.map +0 -1
- package/dist/persist-CLgS5Cqw.js.map +0 -1
- package/dist/persist-DboMIMOK.cjs.map +0 -1
- package/dist/scope-7LeON9bZ.js.map +0 -1
- package/dist/scope-CfLlLxo9.cjs.map +0 -1
- package/dist/store-CdST5wJZ.cjs.map +0 -1
- package/dist/store-Dx8w7yT-.js.map +0 -1
- package/dist/storeMethods-B_RzvMaV.cjs.map +0 -1
- package/dist/storeMethods-BrKuusQ2.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { KeyType } from "./store-
|
|
1
|
+
import { M as KeyType } from "./store-XcnTdeiJ.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/lib/diff.d.ts
|
|
4
4
|
type Patch = {
|
|
@@ -18,5 +18,5 @@ interface DiffOptions {
|
|
|
18
18
|
}
|
|
19
19
|
declare function diff(a: any, b: any, options?: DiffOptions): [patches: Patch[], reversePatches: Patch[]];
|
|
20
20
|
//#endregion
|
|
21
|
-
export {
|
|
22
|
-
//# sourceMappingURL=diff-
|
|
21
|
+
export { Patch as n, diff as r, DiffOptions as t };
|
|
22
|
+
//# sourceMappingURL=diff-CAQaunfv.d.cts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { KeyType } from "./store-
|
|
1
|
+
import { M as KeyType } from "./store-BRHFhRPm.js";
|
|
2
2
|
|
|
3
3
|
//#region src/lib/diff.d.ts
|
|
4
4
|
type Patch = {
|
|
@@ -18,5 +18,5 @@ interface DiffOptions {
|
|
|
18
18
|
}
|
|
19
19
|
declare function diff(a: any, b: any, options?: DiffOptions): [patches: Patch[], reversePatches: Patch[]];
|
|
20
20
|
//#endregion
|
|
21
|
-
export {
|
|
22
|
-
//# sourceMappingURL=diff-
|
|
21
|
+
export { Patch as n, diff as r, DiffOptions as t };
|
|
22
|
+
//# sourceMappingURL=diff-DFvRd-Gf.d.ts.map
|
|
@@ -25,5 +25,5 @@ function fromExtendedJsonString(value, reviver) {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
//#endregion
|
|
28
|
-
export {
|
|
29
|
-
//# sourceMappingURL=extendedJson-
|
|
28
|
+
export { toExtendedJsonString as i, fromExtendedJsonString as n, toExtendedJson as r, fromExtendedJson as t };
|
|
29
|
+
//# sourceMappingURL=extendedJson-Dv9q6rps.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extendedJson-
|
|
1
|
+
{"version":3,"file":"extendedJson-Dv9q6rps.js","names":[],"sources":["../src/lib/extendedJson.ts"],"sourcesContent":["export function toExtendedJson(value: unknown): unknown {\n if (value instanceof Map) {\n return {\n __map: [...value].map(([k, v]) => [toExtendedJson(k), toExtendedJson(v)]),\n };\n }\n\n if (value instanceof Set) {\n return {\n __set: [...value].map(toExtendedJson),\n };\n }\n\n if (value instanceof Date) {\n return {\n __date: value.toISOString(),\n };\n }\n\n if (typeof value === 'bigint') {\n return {\n __bigint: value.toString(),\n };\n }\n\n if (Array.isArray(value)) {\n return value.map(toExtendedJson);\n }\n\n if (typeof value === 'object' && value !== null) {\n return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, toExtendedJson(v)]));\n }\n\n return value;\n}\n\nexport function toExtendedJsonString(\n value: any,\n replacer?: (this: any, key: string, value: any) => any,\n space?: string | number,\n): string;\nexport function toExtendedJsonString(\n value: any,\n replacer?: (number | string)[] | null,\n space?: string | number,\n): string;\nexport function toExtendedJsonString(value: unknown, ...args: any[]): string {\n return JSON.stringify(toExtendedJson(value), ...args);\n}\n\nexport function fromExtendedJson(value: unknown): unknown {\n if (typeof value !== 'object' || value === null) {\n return value;\n }\n\n if ('__map' in value) {\n return new Map(\n (value.__map as [unknown, unknown][]).map(([k, v]) => [\n fromExtendedJson(k),\n fromExtendedJson(v),\n ]),\n );\n }\n\n if ('__set' in value) {\n return new Set((value.__set as unknown[]).map(fromExtendedJson));\n }\n\n if ('__date' in value) {\n return new Date(value.__date as string);\n }\n\n if ('__bigint' in value) {\n return BigInt(value.__bigint as string);\n }\n\n if (Array.isArray(value)) {\n return value.map(fromExtendedJson);\n }\n\n return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, fromExtendedJson(v)]));\n}\n\nexport function fromExtendedJsonString(\n value: string,\n reviver?: (this: any, key: string, value: any) => any,\n): unknown {\n return fromExtendedJson(JSON.parse(value, reviver));\n}\n"],"mappings":";AAAA,SAAgB,eAAe,OAAyB;AACtD,KAAI,iBAAiB,IACnB,QAAO,EACL,OAAO,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,eAAe,EAAE,EAAE,eAAe,EAAE,CAAC,CAAC,EAC1E;AAGH,KAAI,iBAAiB,IACnB,QAAO,EACL,OAAO,CAAC,GAAG,MAAM,CAAC,IAAI,eAAe,EACtC;AAGH,KAAI,iBAAiB,KACnB,QAAO,EACL,QAAQ,MAAM,aAAa,EAC5B;AAGH,KAAI,OAAO,UAAU,SACnB,QAAO,EACL,UAAU,MAAM,UAAU,EAC3B;AAGH,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,MAAM,IAAI,eAAe;AAGlC,KAAI,OAAO,UAAU,YAAY,UAAU,KACzC,QAAO,OAAO,YAAY,OAAO,QAAQ,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,GAAG,eAAe,EAAE,CAAC,CAAC,CAAC;AAG1F,QAAO;;AAaT,SAAgB,qBAAqB,OAAgB,GAAG,MAAqB;AAC3E,QAAO,KAAK,UAAU,eAAe,MAAM,EAAE,GAAG,KAAK;;AAGvD,SAAgB,iBAAiB,OAAyB;AACxD,KAAI,OAAO,UAAU,YAAY,UAAU,KACzC,QAAO;AAGT,KAAI,WAAW,MACb,QAAO,IAAI,IACR,MAAM,MAA+B,KAAK,CAAC,GAAG,OAAO,CACpD,iBAAiB,EAAE,EACnB,iBAAiB,EAAE,CACpB,CAAC,CACH;AAGH,KAAI,WAAW,MACb,QAAO,IAAI,IAAK,MAAM,MAAoB,IAAI,iBAAiB,CAAC;AAGlE,KAAI,YAAY,MACd,QAAO,IAAI,KAAK,MAAM,OAAiB;AAGzC,KAAI,cAAc,MAChB,QAAO,OAAO,MAAM,SAAmB;AAGzC,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,MAAM,IAAI,iBAAiB;AAGpC,QAAO,OAAO,YAAY,OAAO,QAAQ,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,GAAG,iBAAiB,EAAE,CAAC,CAAC,CAAC;;AAG5F,SAAgB,uBACd,OACA,SACS;AACT,QAAO,iBAAiB,KAAK,MAAM,OAAO,QAAQ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extendedJson-
|
|
1
|
+
{"version":3,"file":"extendedJson-ursQ8DbQ.cjs","names":[],"sources":["../src/lib/extendedJson.ts"],"sourcesContent":["export function toExtendedJson(value: unknown): unknown {\n if (value instanceof Map) {\n return {\n __map: [...value].map(([k, v]) => [toExtendedJson(k), toExtendedJson(v)]),\n };\n }\n\n if (value instanceof Set) {\n return {\n __set: [...value].map(toExtendedJson),\n };\n }\n\n if (value instanceof Date) {\n return {\n __date: value.toISOString(),\n };\n }\n\n if (typeof value === 'bigint') {\n return {\n __bigint: value.toString(),\n };\n }\n\n if (Array.isArray(value)) {\n return value.map(toExtendedJson);\n }\n\n if (typeof value === 'object' && value !== null) {\n return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, toExtendedJson(v)]));\n }\n\n return value;\n}\n\nexport function toExtendedJsonString(\n value: any,\n replacer?: (this: any, key: string, value: any) => any,\n space?: string | number,\n): string;\nexport function toExtendedJsonString(\n value: any,\n replacer?: (number | string)[] | null,\n space?: string | number,\n): string;\nexport function toExtendedJsonString(value: unknown, ...args: any[]): string {\n return JSON.stringify(toExtendedJson(value), ...args);\n}\n\nexport function fromExtendedJson(value: unknown): unknown {\n if (typeof value !== 'object' || value === null) {\n return value;\n }\n\n if ('__map' in value) {\n return new Map(\n (value.__map as [unknown, unknown][]).map(([k, v]) => [\n fromExtendedJson(k),\n fromExtendedJson(v),\n ]),\n );\n }\n\n if ('__set' in value) {\n return new Set((value.__set as unknown[]).map(fromExtendedJson));\n }\n\n if ('__date' in value) {\n return new Date(value.__date as string);\n }\n\n if ('__bigint' in value) {\n return BigInt(value.__bigint as string);\n }\n\n if (Array.isArray(value)) {\n return value.map(fromExtendedJson);\n }\n\n return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, fromExtendedJson(v)]));\n}\n\nexport function fromExtendedJsonString(\n value: string,\n reviver?: (this: any, key: string, value: any) => any,\n): unknown {\n return fromExtendedJson(JSON.parse(value, reviver));\n}\n"],"mappings":";;AAAA,SAAgB,eAAe,OAAyB;AACtD,KAAI,iBAAiB,IACnB,QAAO,EACL,OAAO,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,eAAe,EAAE,EAAE,eAAe,EAAE,CAAC,CAAC,EAC1E;AAGH,KAAI,iBAAiB,IACnB,QAAO,EACL,OAAO,CAAC,GAAG,MAAM,CAAC,IAAI,eAAe,EACtC;AAGH,KAAI,iBAAiB,KACnB,QAAO,EACL,QAAQ,MAAM,aAAa,EAC5B;AAGH,KAAI,OAAO,UAAU,SACnB,QAAO,EACL,UAAU,MAAM,UAAU,EAC3B;AAGH,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,MAAM,IAAI,eAAe;AAGlC,KAAI,OAAO,UAAU,YAAY,UAAU,KACzC,QAAO,OAAO,YAAY,OAAO,QAAQ,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,GAAG,eAAe,EAAE,CAAC,CAAC,CAAC;AAG1F,QAAO;;AAaT,SAAgB,qBAAqB,OAAgB,GAAG,MAAqB;AAC3E,QAAO,KAAK,UAAU,eAAe,MAAM,EAAE,GAAG,KAAK;;AAGvD,SAAgB,iBAAiB,OAAyB;AACxD,KAAI,OAAO,UAAU,YAAY,UAAU,KACzC,QAAO;AAGT,KAAI,WAAW,MACb,QAAO,IAAI,IACR,MAAM,MAA+B,KAAK,CAAC,GAAG,OAAO,CACpD,iBAAiB,EAAE,EACnB,iBAAiB,EAAE,CACpB,CAAC,CACH;AAGH,KAAI,WAAW,MACb,QAAO,IAAI,IAAK,MAAM,MAAoB,IAAI,iBAAiB,CAAC;AAGlE,KAAI,YAAY,MACd,QAAO,IAAI,KAAK,MAAM,OAAiB;AAGzC,KAAI,cAAc,MAChB,QAAO,OAAO,MAAM,SAAmB;AAGzC,KAAI,MAAM,QAAQ,MAAM,CACtB,QAAO,MAAM,IAAI,iBAAiB;AAGpC,QAAO,OAAO,YAAY,OAAO,QAAQ,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,GAAG,iBAAiB,EAAE,CAAC,CAAC,CAAC;;AAG5F,SAAgB,uBACd,OACA,SACS;AACT,QAAO,iBAAiB,KAAK,MAAM,OAAO,QAAQ,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
const require_store = require('./store-
|
|
2
|
-
const require_propAccess = require('./propAccess-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const require_persist = require('./persist-DboMIMOK.cjs');
|
|
1
|
+
const require_store = require('./store-C1NYHLgR.cjs');
|
|
2
|
+
const require_propAccess = require('./propAccess-C2AIn9RC.cjs');
|
|
3
|
+
const require_scope = require('./scope-C1bcfK8e.cjs');
|
|
4
|
+
const require_patchMethods = require('./patchMethods-B7Hm5-Qh.cjs');
|
|
5
|
+
const require_extendedJson = require('./extendedJson-ursQ8DbQ.cjs');
|
|
6
|
+
const require_persist = require('./persist-DMbVdqS_.cjs');
|
|
8
7
|
|
|
9
8
|
//#region src/core/pagedCache.ts
|
|
10
9
|
var PagedCache = class PagedCache extends require_scope.Cache {
|
|
@@ -60,10 +59,9 @@ async function loadPage(cache, helpers, oldPages) {
|
|
|
60
59
|
});
|
|
61
60
|
const pages = page === null ? oldPages : oldPages.concat(page);
|
|
62
61
|
const pageCount = getPageCount?.call(cache, pages) ?? null;
|
|
63
|
-
const hasMore = hasMorePages ? hasMorePages.call(cache, pages) : pageCount !== null ? pages.length < pageCount : page !== null;
|
|
64
62
|
return {
|
|
65
63
|
pages,
|
|
66
|
-
hasMore,
|
|
64
|
+
hasMore: hasMorePages ? hasMorePages.call(cache, pages) : pageCount !== null ? pages.length < pageCount : page !== null,
|
|
67
65
|
pageCount
|
|
68
66
|
};
|
|
69
67
|
}
|
|
@@ -107,14 +105,14 @@ exports.findOrDefault = findOrDefault;
|
|
|
107
105
|
exports.fromExtendedJson = require_extendedJson.fromExtendedJson;
|
|
108
106
|
exports.fromExtendedJsonString = require_extendedJson.fromExtendedJsonString;
|
|
109
107
|
exports.get = require_propAccess.get;
|
|
110
|
-
exports.hash =
|
|
108
|
+
exports.hash = require_scope.hash;
|
|
111
109
|
exports.mapMethods = require_store.mapMethods;
|
|
112
110
|
exports.persist = require_persist.persist;
|
|
113
111
|
exports.recordMethods = require_store.recordMethods;
|
|
114
112
|
exports.set = require_propAccess.set;
|
|
115
113
|
exports.setMethods = require_store.setMethods;
|
|
116
114
|
exports.shallowEqual = require_propAccess.shallowEqual;
|
|
117
|
-
exports.simpleHash =
|
|
115
|
+
exports.simpleHash = require_scope.simpleHash;
|
|
118
116
|
exports.strictEqual = require_propAccess.strictEqual;
|
|
119
117
|
exports.toExtendedJson = require_extendedJson.toExtendedJson;
|
|
120
118
|
exports.toExtendedJsonString = require_extendedJson.toExtendedJsonString;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["Cache","definition: PagedCacheDefinition<T, Args>","internalCreate","options","createPagedCache: typeof createPaged & { defaultOptions: CacheOptions<any, any> }","defaultCacheOptions"],"sources":["../src/core/pagedCache.ts","../src/lib/updateHelpers.ts"],"sourcesContent":["import {\n Cache,\n defaultCacheOptions,\n internalCreate,\n type CacheOptions,\n type CreateCacheResult,\n} from '@core/cache';\nimport type { CalculationActions } from '@core/commonTypes';\nimport { autobind } from '@lib/autobind';\n\nexport interface PageCacheFunctionProps<T> extends CalculationActions<Promise<PagedCacheState<T>>> {\n /**\n * Previously fetched pages (in order).\n */\n pages: T[];\n /**\n * Last fetched page or null if there are no previously fetched pages.\n */\n prevPage: T | null;\n}\n\nexport interface PageCacheFunction<T> {\n (props: PageCacheFunctionProps<T>): Promise<T | null>;\n}\n\nexport interface PagedCacheDefinition<T, Args extends any[]> {\n /**\n * Function to fetch a page.\n * The function receives the current state of the cache, including previously fetched pages.\n */\n fetchPage: (this: PagedCache<T, Args>, props: PageCacheFunctionProps<T>) => Promise<T | null>;\n /**\n * Optional function to determine the total number of pages - usually based on data in the fetched pages.\n */\n getPageCount?: (this: PagedCache<T, Args>, pages: T[]) => number | null;\n /**\n * Optional function to determine if there are more pages to fetch - usually based on data in the fetched pages.\n * If not provided, it will be assumed there are more pages until getPageCount is provided and the number of fetched pages equals the page count or until fetchPage returns null.\n */\n hasMorePages?: (this: PagedCache<T, Args>, pages: T[]) => boolean;\n}\n\nexport interface PagedCacheDefinitionFunction<T, Args extends any[]> {\n (...args: Args): PagedCacheDefinition<T, Args>;\n}\n\nexport interface PagedCacheState<T> {\n pages: T[];\n hasMore: boolean;\n pageCount: number | null;\n}\n\nexport interface FetchNextPageOptions {\n /**\n * If true, will throw if the cache is in an error state or if another page is being fetched.\n */\n throwOnError?: boolean;\n}\n\nexport class PagedCache<T, Args extends any[] = []> extends Cache<PagedCacheState<T>, Args> {\n constructor(\n public readonly definition: PagedCacheDefinition<T, Args>,\n args: Args,\n options: CacheOptions<PagedCacheState<T>, Args> = {},\n ) {\n super(async (helpers) => loadPage(this, helpers, []), args, options, undefined);\n autobind(PagedCache);\n }\n\n async fetchNextPage({ throwOnError }: FetchNextPageOptions = {}): Promise<void> {\n const { status, isStale, isUpdating, value } = this.state.get();\n\n if (status === 'error') {\n if (!throwOnError) return;\n throw new Error('Cannot fetch next page while cache is in error state');\n }\n\n if (isUpdating) {\n if (!throwOnError) return;\n throw new Error('Cannot fetch next page while another page is being fetched');\n }\n\n if (status === 'pending' || isStale) {\n await this.get().catch(() => {});\n return;\n }\n\n if (!value.hasMore) {\n if (!throwOnError) return;\n throw new Error('No more pages to fetch');\n }\n\n this.stalePromise = this.calculatedValue?.value;\n\n const ac = new AbortController();\n const promise = loadPage(\n this,\n {\n use() {\n throw new Error('Not implemented');\n },\n connect() {\n throw new Error('Not implemented');\n },\n signal: ac.signal,\n },\n value.pages,\n );\n\n this.updateValue(promise);\n\n try {\n await promise;\n } catch (error) {\n if (!throwOnError) return;\n throw error;\n }\n }\n}\n\nasync function loadPage<T, Args extends any[]>(\n cache: PagedCache<T, Args>,\n helpers: CalculationActions<Promise<PagedCacheState<T>>>,\n oldPages: T[],\n) {\n const { fetchPage, hasMorePages, getPageCount } = cache.definition;\n\n const page = await fetchPage.call(cache, {\n ...helpers,\n pages: oldPages,\n prevPage: oldPages.length > 0 ? oldPages[oldPages.length - 1]! : null,\n });\n\n const pages = page === null ? oldPages : oldPages.concat(page);\n const pageCount = getPageCount?.call(cache, pages) ?? null;\n const hasMore = hasMorePages\n ? hasMorePages.call(cache, pages)\n : pageCount !== null\n ? pages.length < pageCount\n : page !== null;\n\n return { pages, hasMore, pageCount };\n}\n\nfunction createPaged<T, Args extends any[] = []>(\n definition: PagedCacheDefinitionFunction<T, Args>,\n options?: CacheOptions<PagedCacheState<T>, Args>,\n): CreateCacheResult<PagedCacheState<T>, Args, PagedCache<T, Args>>;\n\nfunction createPaged<T>(\n definition: PagedCacheDefinition<T, []>,\n options?: CacheOptions<PagedCacheState<T>, []>,\n): CreateCacheResult<PagedCacheState<T>, [], PagedCache<T, []>>;\n\nfunction createPaged<T, Args extends any[] = []>(\n definition: PagedCacheDefinitionFunction<T, Args> | PagedCacheDefinition<T, Args>,\n options?: CacheOptions<PagedCacheState<T>, Args>,\n): CreateCacheResult<PagedCacheState<T>, Args, PagedCache<T, Args>> {\n return internalCreate<PagedCacheState<T>, Args, PagedCache<T, Args>>((args, options) => {\n let currentDefinition = definition;\n if (currentDefinition instanceof Function) {\n currentDefinition = currentDefinition(...args);\n }\n return new PagedCache(currentDefinition, args, options);\n }, options);\n}\n\nexport const createPagedCache: typeof createPaged & { defaultOptions: CacheOptions<any, any> } =\n /* @__PURE__ */ Object.assign(createPaged, {\n defaultOptions: defaultCacheOptions,\n });\n","export function findOrDefault<T>(\n array: T[],\n predicate: (item: T) => boolean,\n defaultValue: T | (() => T),\n): T {\n const index = array.findIndex(predicate);\n\n if (index >= 0) {\n return array[index]!;\n }\n\n const value = defaultValue instanceof Function ? defaultValue() : defaultValue;\n array.push(value);\n return value;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["Cache","definition: PagedCacheDefinition<T, Args>","internalCreate","options","createPagedCache: typeof createPaged & { defaultOptions: CacheOptions<any, any> }","defaultCacheOptions"],"sources":["../src/core/pagedCache.ts","../src/lib/updateHelpers.ts"],"sourcesContent":["import {\n Cache,\n defaultCacheOptions,\n internalCreate,\n type CacheOptions,\n type CreateCacheResult,\n} from '@core/cache';\nimport type { CalculationActions } from '@core/commonTypes';\nimport { autobind } from '@lib/autobind';\n\nexport interface PageCacheFunctionProps<T> extends CalculationActions<Promise<PagedCacheState<T>>> {\n /**\n * Previously fetched pages (in order).\n */\n pages: T[];\n /**\n * Last fetched page or null if there are no previously fetched pages.\n */\n prevPage: T | null;\n}\n\nexport interface PageCacheFunction<T> {\n (props: PageCacheFunctionProps<T>): Promise<T | null>;\n}\n\nexport interface PagedCacheDefinition<T, Args extends any[]> {\n /**\n * Function to fetch a page.\n * The function receives the current state of the cache, including previously fetched pages.\n */\n fetchPage: (this: PagedCache<T, Args>, props: PageCacheFunctionProps<T>) => Promise<T | null>;\n /**\n * Optional function to determine the total number of pages - usually based on data in the fetched pages.\n */\n getPageCount?: (this: PagedCache<T, Args>, pages: T[]) => number | null;\n /**\n * Optional function to determine if there are more pages to fetch - usually based on data in the fetched pages.\n * If not provided, it will be assumed there are more pages until getPageCount is provided and the number of fetched pages equals the page count or until fetchPage returns null.\n */\n hasMorePages?: (this: PagedCache<T, Args>, pages: T[]) => boolean;\n}\n\nexport interface PagedCacheDefinitionFunction<T, Args extends any[]> {\n (...args: Args): PagedCacheDefinition<T, Args>;\n}\n\nexport interface PagedCacheState<T> {\n pages: T[];\n hasMore: boolean;\n pageCount: number | null;\n}\n\nexport interface FetchNextPageOptions {\n /**\n * If true, will throw if the cache is in an error state or if another page is being fetched.\n */\n throwOnError?: boolean;\n}\n\nexport class PagedCache<T, Args extends any[] = []> extends Cache<PagedCacheState<T>, Args> {\n constructor(\n public readonly definition: PagedCacheDefinition<T, Args>,\n args: Args,\n options: CacheOptions<PagedCacheState<T>, Args> = {},\n ) {\n super(async (helpers) => loadPage(this, helpers, []), args, options, undefined);\n autobind(PagedCache);\n }\n\n async fetchNextPage({ throwOnError }: FetchNextPageOptions = {}): Promise<void> {\n const { status, isStale, isUpdating, value } = this.state.get();\n\n if (status === 'error') {\n if (!throwOnError) return;\n throw new Error('Cannot fetch next page while cache is in error state');\n }\n\n if (isUpdating) {\n if (!throwOnError) return;\n throw new Error('Cannot fetch next page while another page is being fetched');\n }\n\n if (status === 'pending' || isStale) {\n await this.get().catch(() => {});\n return;\n }\n\n if (!value.hasMore) {\n if (!throwOnError) return;\n throw new Error('No more pages to fetch');\n }\n\n this.stalePromise = this.calculatedValue?.value;\n\n const ac = new AbortController();\n const promise = loadPage(\n this,\n {\n use() {\n throw new Error('Not implemented');\n },\n connect() {\n throw new Error('Not implemented');\n },\n signal: ac.signal,\n },\n value.pages,\n );\n\n this.updateValue(promise);\n\n try {\n await promise;\n } catch (error) {\n if (!throwOnError) return;\n throw error;\n }\n }\n}\n\nasync function loadPage<T, Args extends any[]>(\n cache: PagedCache<T, Args>,\n helpers: CalculationActions<Promise<PagedCacheState<T>>>,\n oldPages: T[],\n) {\n const { fetchPage, hasMorePages, getPageCount } = cache.definition;\n\n const page = await fetchPage.call(cache, {\n ...helpers,\n pages: oldPages,\n prevPage: oldPages.length > 0 ? oldPages[oldPages.length - 1]! : null,\n });\n\n const pages = page === null ? oldPages : oldPages.concat(page);\n const pageCount = getPageCount?.call(cache, pages) ?? null;\n const hasMore = hasMorePages\n ? hasMorePages.call(cache, pages)\n : pageCount !== null\n ? pages.length < pageCount\n : page !== null;\n\n return { pages, hasMore, pageCount };\n}\n\nfunction createPaged<T, Args extends any[] = []>(\n definition: PagedCacheDefinitionFunction<T, Args>,\n options?: CacheOptions<PagedCacheState<T>, Args>,\n): CreateCacheResult<PagedCacheState<T>, Args, PagedCache<T, Args>>;\n\nfunction createPaged<T>(\n definition: PagedCacheDefinition<T, []>,\n options?: CacheOptions<PagedCacheState<T>, []>,\n): CreateCacheResult<PagedCacheState<T>, [], PagedCache<T, []>>;\n\nfunction createPaged<T, Args extends any[] = []>(\n definition: PagedCacheDefinitionFunction<T, Args> | PagedCacheDefinition<T, Args>,\n options?: CacheOptions<PagedCacheState<T>, Args>,\n): CreateCacheResult<PagedCacheState<T>, Args, PagedCache<T, Args>> {\n return internalCreate<PagedCacheState<T>, Args, PagedCache<T, Args>>((args, options) => {\n let currentDefinition = definition;\n if (currentDefinition instanceof Function) {\n currentDefinition = currentDefinition(...args);\n }\n return new PagedCache(currentDefinition, args, options);\n }, options);\n}\n\nexport const createPagedCache: typeof createPaged & { defaultOptions: CacheOptions<any, any> } =\n /* @__PURE__ */ Object.assign(createPaged, {\n defaultOptions: defaultCacheOptions,\n });\n","export function findOrDefault<T>(\n array: T[],\n predicate: (item: T) => boolean,\n defaultValue: T | (() => T),\n): T {\n const index = array.findIndex(predicate);\n\n if (index >= 0) {\n return array[index]!;\n }\n\n const value = defaultValue instanceof Function ? defaultValue() : defaultValue;\n array.push(value);\n return value;\n}\n"],"mappings":";;;;;;;;AA2DA,IAAa,aAAb,MAAa,mBAA+CA,oBAAgC;CAC1F,YACE,AAAgBC,YAChB,MACA,UAAkD,EAAE,EACpD;AACA,QAAM,OAAO,YAAY,SAAS,MAAM,SAAS,EAAE,CAAC,EAAE,MAAM,SAAS,OAAU;EAJ/D;AAKhB,yBAAS,WAAW;;CAGtB,MAAM,cAAc,EAAE,iBAAuC,EAAE,EAAiB;EAC9E,MAAM,EAAE,QAAQ,SAAS,YAAY,UAAU,KAAK,MAAM,KAAK;AAE/D,MAAI,WAAW,SAAS;AACtB,OAAI,CAAC,aAAc;AACnB,SAAM,IAAI,MAAM,uDAAuD;;AAGzE,MAAI,YAAY;AACd,OAAI,CAAC,aAAc;AACnB,SAAM,IAAI,MAAM,6DAA6D;;AAG/E,MAAI,WAAW,aAAa,SAAS;AACnC,SAAM,KAAK,KAAK,CAAC,YAAY,GAAG;AAChC;;AAGF,MAAI,CAAC,MAAM,SAAS;AAClB,OAAI,CAAC,aAAc;AACnB,SAAM,IAAI,MAAM,yBAAyB;;AAG3C,OAAK,eAAe,KAAK,iBAAiB;EAE1C,MAAM,KAAK,IAAI,iBAAiB;EAChC,MAAM,UAAU,SACd,MACA;GACE,MAAM;AACJ,UAAM,IAAI,MAAM,kBAAkB;;GAEpC,UAAU;AACR,UAAM,IAAI,MAAM,kBAAkB;;GAEpC,QAAQ,GAAG;GACZ,EACD,MAAM,MACP;AAED,OAAK,YAAY,QAAQ;AAEzB,MAAI;AACF,SAAM;WACC,OAAO;AACd,OAAI,CAAC,aAAc;AACnB,SAAM;;;;AAKZ,eAAe,SACb,OACA,SACA,UACA;CACA,MAAM,EAAE,WAAW,cAAc,iBAAiB,MAAM;CAExD,MAAM,OAAO,MAAM,UAAU,KAAK,OAAO;EACvC,GAAG;EACH,OAAO;EACP,UAAU,SAAS,SAAS,IAAI,SAAS,SAAS,SAAS,KAAM;EAClE,CAAC;CAEF,MAAM,QAAQ,SAAS,OAAO,WAAW,SAAS,OAAO,KAAK;CAC9D,MAAM,YAAY,cAAc,KAAK,OAAO,MAAM,IAAI;AAOtD,QAAO;EAAE;EAAO,SANA,eACZ,aAAa,KAAK,OAAO,MAAM,GAC/B,cAAc,OACZ,MAAM,SAAS,YACf,SAAS;EAEU;EAAW;;AAatC,SAAS,YACP,YACA,SACkE;AAClE,QAAOC,8BAA+D,MAAM,cAAY;EACtF,IAAI,oBAAoB;AACxB,MAAI,6BAA6B,SAC/B,qBAAoB,kBAAkB,GAAG,KAAK;AAEhD,SAAO,IAAI,WAAW,mBAAmB,MAAMC,UAAQ;IACtD,QAAQ;;AAGb,MAAaC,mBACK,uBAAO,OAAO,aAAa,EACzC,gBAAgBC,mCACjB,CAAC;;;;AC1KJ,SAAgB,cACd,OACA,WACA,cACG;CACH,MAAM,QAAQ,MAAM,UAAU,UAAU;AAExC,KAAI,SAAS,EACX,QAAO,MAAM;CAGf,MAAM,QAAQ,wBAAwB,WAAW,cAAc,GAAG;AAClE,OAAM,KAAK,MAAM;AACjB,QAAO"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Patch, diff } from "./diff-
|
|
4
|
-
import {
|
|
1
|
+
import { _ as ValueState, a as CacheFunction, c as CreateCacheResult, d as ResourceGroup, f as allResources, g as PendingState, h as ErrorState, i as CacheBundle, l as createCache, m as CacheState, n as createScope, o as CacheGetOptions, p as createResourceGroup, r as Cache, s as CacheOptions, t as Scope, u as Resource } from "./scope-CESkVNvI.cjs";
|
|
2
|
+
import { B as Value, C as Selector, D as UpdateFunction, E as UpdateFrom, F as PathAsString, I as SettablePath, K as Constrain, L as SettablePathAsArray, M as KeyType, N as Path, O as Use, P as PathAsArray, R as SettablePathAsString, S as Listener, T as Update, _ as Connection, a as StoreOptions, b as Duration, c as arrayMethods, d as setMethods, f as AsyncConnectionActions, g as Cancel, h as CalculationActions, i as StoreMethods, l as mapMethods, m as BaseConnectionActions, o as StoreOptionsWithMethods, p as AsyncUpdateFunction, r as Store, s as createStore, t as BoundStoreMethods, u as recordMethods, v as ConnectionActions, w as SubscribeOptions, x as Effect, y as DisposableCancel, z as SettableValue } from "./store-XcnTdeiJ.cjs";
|
|
3
|
+
import { n as Patch, r as diff } from "./diff-CAQaunfv.cjs";
|
|
4
|
+
import { a as PersistStorageBase, c as PersistStorageWithListItems, i as PersistStorage, n as PersistOptions, o as PersistStorageWithKeys, r as persist, s as PersistStorageWithLength, t as Persist } from "./persist-CHRYYolx.cjs";
|
|
5
5
|
|
|
6
6
|
//#region src/core/pagedCache.d.ts
|
|
7
7
|
interface PageCacheFunctionProps<T> extends CalculationActions<Promise<PagedCacheState<T>>> {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Patch, diff } from "./diff-
|
|
4
|
-
import {
|
|
1
|
+
import { _ as ValueState, a as CacheFunction, c as CreateCacheResult, d as ResourceGroup, f as allResources, g as PendingState, h as ErrorState, i as CacheBundle, l as createCache, m as CacheState, n as createScope, o as CacheGetOptions, p as createResourceGroup, r as Cache, s as CacheOptions, t as Scope, u as Resource } from "./scope-DJXSRsGy.js";
|
|
2
|
+
import { B as Value, C as Selector, D as UpdateFunction, E as UpdateFrom, F as PathAsString, I as SettablePath, K as Constrain, L as SettablePathAsArray, M as KeyType, N as Path, O as Use, P as PathAsArray, R as SettablePathAsString, S as Listener, T as Update, _ as Connection, a as StoreOptions, b as Duration, c as arrayMethods, d as setMethods, f as AsyncConnectionActions, g as Cancel, h as CalculationActions, i as StoreMethods, l as mapMethods, m as BaseConnectionActions, o as StoreOptionsWithMethods, p as AsyncUpdateFunction, r as Store, s as createStore, t as BoundStoreMethods, u as recordMethods, v as ConnectionActions, w as SubscribeOptions, x as Effect, y as DisposableCancel, z as SettableValue } from "./store-BRHFhRPm.js";
|
|
3
|
+
import { n as Patch, r as diff } from "./diff-DFvRd-Gf.js";
|
|
4
|
+
import { a as PersistStorageBase, c as PersistStorageWithListItems, i as PersistStorage, n as PersistOptions, o as PersistStorageWithKeys, r as persist, s as PersistStorageWithLength, t as Persist } from "./persist-DyI_JLxZ.js";
|
|
5
5
|
|
|
6
6
|
//#region src/core/pagedCache.d.ts
|
|
7
7
|
interface PageCacheFunctionProps<T> extends CalculationActions<Promise<PagedCacheState<T>>> {
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { hash, simpleHash } from "./
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { persist } from "./persist-CLgS5Cqw.js";
|
|
1
|
+
import { a as mapMethods, h as autobind, i as arrayMethods, m as calcDuration, n as createStore, o as recordMethods, s as setMethods, t as Store } from "./store-v3RYWzVg.js";
|
|
2
|
+
import { a as set, c as deepEqual, l as shallowEqual, n as get, u as strictEqual } from "./propAccess-DvWFpYoj.js";
|
|
3
|
+
import { a as defaultCacheOptions, c as allResources, d as hash, f as simpleHash, i as createCache, l as createResourceGroup, n as createScope, o as internalCreate, r as Cache, s as ResourceGroup, t as Scope, u as InstanceCache } from "./scope-CKGsCVn3.js";
|
|
4
|
+
import { i as applyPatches, r as diff } from "./patchMethods-iK2F87G0.js";
|
|
5
|
+
import { i as toExtendedJsonString, n as fromExtendedJsonString, r as toExtendedJson, t as fromExtendedJson } from "./extendedJson-Dv9q6rps.js";
|
|
6
|
+
import { t as persist } from "./persist-Bunx8xfQ.js";
|
|
8
7
|
|
|
9
8
|
//#region src/core/pagedCache.ts
|
|
10
9
|
var PagedCache = class PagedCache extends Cache {
|
|
@@ -60,10 +59,9 @@ async function loadPage(cache, helpers, oldPages) {
|
|
|
60
59
|
});
|
|
61
60
|
const pages = page === null ? oldPages : oldPages.concat(page);
|
|
62
61
|
const pageCount = getPageCount?.call(cache, pages) ?? null;
|
|
63
|
-
const hasMore = hasMorePages ? hasMorePages.call(cache, pages) : pageCount !== null ? pages.length < pageCount : page !== null;
|
|
64
62
|
return {
|
|
65
63
|
pages,
|
|
66
|
-
hasMore,
|
|
64
|
+
hasMore: hasMorePages ? hasMorePages.call(cache, pages) : pageCount !== null ? pages.length < pageCount : page !== null,
|
|
67
65
|
pageCount
|
|
68
66
|
};
|
|
69
67
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["definition: PagedCacheDefinition<T, Args>","options","createPagedCache: typeof createPaged & { defaultOptions: CacheOptions<any, any> }"],"sources":["../src/core/pagedCache.ts","../src/lib/updateHelpers.ts"],"sourcesContent":["import {\n Cache,\n defaultCacheOptions,\n internalCreate,\n type CacheOptions,\n type CreateCacheResult,\n} from '@core/cache';\nimport type { CalculationActions } from '@core/commonTypes';\nimport { autobind } from '@lib/autobind';\n\nexport interface PageCacheFunctionProps<T> extends CalculationActions<Promise<PagedCacheState<T>>> {\n /**\n * Previously fetched pages (in order).\n */\n pages: T[];\n /**\n * Last fetched page or null if there are no previously fetched pages.\n */\n prevPage: T | null;\n}\n\nexport interface PageCacheFunction<T> {\n (props: PageCacheFunctionProps<T>): Promise<T | null>;\n}\n\nexport interface PagedCacheDefinition<T, Args extends any[]> {\n /**\n * Function to fetch a page.\n * The function receives the current state of the cache, including previously fetched pages.\n */\n fetchPage: (this: PagedCache<T, Args>, props: PageCacheFunctionProps<T>) => Promise<T | null>;\n /**\n * Optional function to determine the total number of pages - usually based on data in the fetched pages.\n */\n getPageCount?: (this: PagedCache<T, Args>, pages: T[]) => number | null;\n /**\n * Optional function to determine if there are more pages to fetch - usually based on data in the fetched pages.\n * If not provided, it will be assumed there are more pages until getPageCount is provided and the number of fetched pages equals the page count or until fetchPage returns null.\n */\n hasMorePages?: (this: PagedCache<T, Args>, pages: T[]) => boolean;\n}\n\nexport interface PagedCacheDefinitionFunction<T, Args extends any[]> {\n (...args: Args): PagedCacheDefinition<T, Args>;\n}\n\nexport interface PagedCacheState<T> {\n pages: T[];\n hasMore: boolean;\n pageCount: number | null;\n}\n\nexport interface FetchNextPageOptions {\n /**\n * If true, will throw if the cache is in an error state or if another page is being fetched.\n */\n throwOnError?: boolean;\n}\n\nexport class PagedCache<T, Args extends any[] = []> extends Cache<PagedCacheState<T>, Args> {\n constructor(\n public readonly definition: PagedCacheDefinition<T, Args>,\n args: Args,\n options: CacheOptions<PagedCacheState<T>, Args> = {},\n ) {\n super(async (helpers) => loadPage(this, helpers, []), args, options, undefined);\n autobind(PagedCache);\n }\n\n async fetchNextPage({ throwOnError }: FetchNextPageOptions = {}): Promise<void> {\n const { status, isStale, isUpdating, value } = this.state.get();\n\n if (status === 'error') {\n if (!throwOnError) return;\n throw new Error('Cannot fetch next page while cache is in error state');\n }\n\n if (isUpdating) {\n if (!throwOnError) return;\n throw new Error('Cannot fetch next page while another page is being fetched');\n }\n\n if (status === 'pending' || isStale) {\n await this.get().catch(() => {});\n return;\n }\n\n if (!value.hasMore) {\n if (!throwOnError) return;\n throw new Error('No more pages to fetch');\n }\n\n this.stalePromise = this.calculatedValue?.value;\n\n const ac = new AbortController();\n const promise = loadPage(\n this,\n {\n use() {\n throw new Error('Not implemented');\n },\n connect() {\n throw new Error('Not implemented');\n },\n signal: ac.signal,\n },\n value.pages,\n );\n\n this.updateValue(promise);\n\n try {\n await promise;\n } catch (error) {\n if (!throwOnError) return;\n throw error;\n }\n }\n}\n\nasync function loadPage<T, Args extends any[]>(\n cache: PagedCache<T, Args>,\n helpers: CalculationActions<Promise<PagedCacheState<T>>>,\n oldPages: T[],\n) {\n const { fetchPage, hasMorePages, getPageCount } = cache.definition;\n\n const page = await fetchPage.call(cache, {\n ...helpers,\n pages: oldPages,\n prevPage: oldPages.length > 0 ? oldPages[oldPages.length - 1]! : null,\n });\n\n const pages = page === null ? oldPages : oldPages.concat(page);\n const pageCount = getPageCount?.call(cache, pages) ?? null;\n const hasMore = hasMorePages\n ? hasMorePages.call(cache, pages)\n : pageCount !== null\n ? pages.length < pageCount\n : page !== null;\n\n return { pages, hasMore, pageCount };\n}\n\nfunction createPaged<T, Args extends any[] = []>(\n definition: PagedCacheDefinitionFunction<T, Args>,\n options?: CacheOptions<PagedCacheState<T>, Args>,\n): CreateCacheResult<PagedCacheState<T>, Args, PagedCache<T, Args>>;\n\nfunction createPaged<T>(\n definition: PagedCacheDefinition<T, []>,\n options?: CacheOptions<PagedCacheState<T>, []>,\n): CreateCacheResult<PagedCacheState<T>, [], PagedCache<T, []>>;\n\nfunction createPaged<T, Args extends any[] = []>(\n definition: PagedCacheDefinitionFunction<T, Args> | PagedCacheDefinition<T, Args>,\n options?: CacheOptions<PagedCacheState<T>, Args>,\n): CreateCacheResult<PagedCacheState<T>, Args, PagedCache<T, Args>> {\n return internalCreate<PagedCacheState<T>, Args, PagedCache<T, Args>>((args, options) => {\n let currentDefinition = definition;\n if (currentDefinition instanceof Function) {\n currentDefinition = currentDefinition(...args);\n }\n return new PagedCache(currentDefinition, args, options);\n }, options);\n}\n\nexport const createPagedCache: typeof createPaged & { defaultOptions: CacheOptions<any, any> } =\n /* @__PURE__ */ Object.assign(createPaged, {\n defaultOptions: defaultCacheOptions,\n });\n","export function findOrDefault<T>(\n array: T[],\n predicate: (item: T) => boolean,\n defaultValue: T | (() => T),\n): T {\n const index = array.findIndex(predicate);\n\n if (index >= 0) {\n return array[index]!;\n }\n\n const value = defaultValue instanceof Function ? defaultValue() : defaultValue;\n array.push(value);\n return value;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["definition: PagedCacheDefinition<T, Args>","options","createPagedCache: typeof createPaged & { defaultOptions: CacheOptions<any, any> }"],"sources":["../src/core/pagedCache.ts","../src/lib/updateHelpers.ts"],"sourcesContent":["import {\n Cache,\n defaultCacheOptions,\n internalCreate,\n type CacheOptions,\n type CreateCacheResult,\n} from '@core/cache';\nimport type { CalculationActions } from '@core/commonTypes';\nimport { autobind } from '@lib/autobind';\n\nexport interface PageCacheFunctionProps<T> extends CalculationActions<Promise<PagedCacheState<T>>> {\n /**\n * Previously fetched pages (in order).\n */\n pages: T[];\n /**\n * Last fetched page or null if there are no previously fetched pages.\n */\n prevPage: T | null;\n}\n\nexport interface PageCacheFunction<T> {\n (props: PageCacheFunctionProps<T>): Promise<T | null>;\n}\n\nexport interface PagedCacheDefinition<T, Args extends any[]> {\n /**\n * Function to fetch a page.\n * The function receives the current state of the cache, including previously fetched pages.\n */\n fetchPage: (this: PagedCache<T, Args>, props: PageCacheFunctionProps<T>) => Promise<T | null>;\n /**\n * Optional function to determine the total number of pages - usually based on data in the fetched pages.\n */\n getPageCount?: (this: PagedCache<T, Args>, pages: T[]) => number | null;\n /**\n * Optional function to determine if there are more pages to fetch - usually based on data in the fetched pages.\n * If not provided, it will be assumed there are more pages until getPageCount is provided and the number of fetched pages equals the page count or until fetchPage returns null.\n */\n hasMorePages?: (this: PagedCache<T, Args>, pages: T[]) => boolean;\n}\n\nexport interface PagedCacheDefinitionFunction<T, Args extends any[]> {\n (...args: Args): PagedCacheDefinition<T, Args>;\n}\n\nexport interface PagedCacheState<T> {\n pages: T[];\n hasMore: boolean;\n pageCount: number | null;\n}\n\nexport interface FetchNextPageOptions {\n /**\n * If true, will throw if the cache is in an error state or if another page is being fetched.\n */\n throwOnError?: boolean;\n}\n\nexport class PagedCache<T, Args extends any[] = []> extends Cache<PagedCacheState<T>, Args> {\n constructor(\n public readonly definition: PagedCacheDefinition<T, Args>,\n args: Args,\n options: CacheOptions<PagedCacheState<T>, Args> = {},\n ) {\n super(async (helpers) => loadPage(this, helpers, []), args, options, undefined);\n autobind(PagedCache);\n }\n\n async fetchNextPage({ throwOnError }: FetchNextPageOptions = {}): Promise<void> {\n const { status, isStale, isUpdating, value } = this.state.get();\n\n if (status === 'error') {\n if (!throwOnError) return;\n throw new Error('Cannot fetch next page while cache is in error state');\n }\n\n if (isUpdating) {\n if (!throwOnError) return;\n throw new Error('Cannot fetch next page while another page is being fetched');\n }\n\n if (status === 'pending' || isStale) {\n await this.get().catch(() => {});\n return;\n }\n\n if (!value.hasMore) {\n if (!throwOnError) return;\n throw new Error('No more pages to fetch');\n }\n\n this.stalePromise = this.calculatedValue?.value;\n\n const ac = new AbortController();\n const promise = loadPage(\n this,\n {\n use() {\n throw new Error('Not implemented');\n },\n connect() {\n throw new Error('Not implemented');\n },\n signal: ac.signal,\n },\n value.pages,\n );\n\n this.updateValue(promise);\n\n try {\n await promise;\n } catch (error) {\n if (!throwOnError) return;\n throw error;\n }\n }\n}\n\nasync function loadPage<T, Args extends any[]>(\n cache: PagedCache<T, Args>,\n helpers: CalculationActions<Promise<PagedCacheState<T>>>,\n oldPages: T[],\n) {\n const { fetchPage, hasMorePages, getPageCount } = cache.definition;\n\n const page = await fetchPage.call(cache, {\n ...helpers,\n pages: oldPages,\n prevPage: oldPages.length > 0 ? oldPages[oldPages.length - 1]! : null,\n });\n\n const pages = page === null ? oldPages : oldPages.concat(page);\n const pageCount = getPageCount?.call(cache, pages) ?? null;\n const hasMore = hasMorePages\n ? hasMorePages.call(cache, pages)\n : pageCount !== null\n ? pages.length < pageCount\n : page !== null;\n\n return { pages, hasMore, pageCount };\n}\n\nfunction createPaged<T, Args extends any[] = []>(\n definition: PagedCacheDefinitionFunction<T, Args>,\n options?: CacheOptions<PagedCacheState<T>, Args>,\n): CreateCacheResult<PagedCacheState<T>, Args, PagedCache<T, Args>>;\n\nfunction createPaged<T>(\n definition: PagedCacheDefinition<T, []>,\n options?: CacheOptions<PagedCacheState<T>, []>,\n): CreateCacheResult<PagedCacheState<T>, [], PagedCache<T, []>>;\n\nfunction createPaged<T, Args extends any[] = []>(\n definition: PagedCacheDefinitionFunction<T, Args> | PagedCacheDefinition<T, Args>,\n options?: CacheOptions<PagedCacheState<T>, Args>,\n): CreateCacheResult<PagedCacheState<T>, Args, PagedCache<T, Args>> {\n return internalCreate<PagedCacheState<T>, Args, PagedCache<T, Args>>((args, options) => {\n let currentDefinition = definition;\n if (currentDefinition instanceof Function) {\n currentDefinition = currentDefinition(...args);\n }\n return new PagedCache(currentDefinition, args, options);\n }, options);\n}\n\nexport const createPagedCache: typeof createPaged & { defaultOptions: CacheOptions<any, any> } =\n /* @__PURE__ */ Object.assign(createPaged, {\n defaultOptions: defaultCacheOptions,\n });\n","export function findOrDefault<T>(\n array: T[],\n predicate: (item: T) => boolean,\n defaultValue: T | (() => T),\n): T {\n const index = array.findIndex(predicate);\n\n if (index >= 0) {\n return array[index]!;\n }\n\n const value = defaultValue instanceof Function ? defaultValue() : defaultValue;\n array.push(value);\n return value;\n}\n"],"mappings":";;;;;;;;AA2DA,IAAa,aAAb,MAAa,mBAA+C,MAAgC;CAC1F,YACE,AAAgBA,YAChB,MACA,UAAkD,EAAE,EACpD;AACA,QAAM,OAAO,YAAY,SAAS,MAAM,SAAS,EAAE,CAAC,EAAE,MAAM,SAAS,OAAU;EAJ/D;AAKhB,WAAS,WAAW;;CAGtB,MAAM,cAAc,EAAE,iBAAuC,EAAE,EAAiB;EAC9E,MAAM,EAAE,QAAQ,SAAS,YAAY,UAAU,KAAK,MAAM,KAAK;AAE/D,MAAI,WAAW,SAAS;AACtB,OAAI,CAAC,aAAc;AACnB,SAAM,IAAI,MAAM,uDAAuD;;AAGzE,MAAI,YAAY;AACd,OAAI,CAAC,aAAc;AACnB,SAAM,IAAI,MAAM,6DAA6D;;AAG/E,MAAI,WAAW,aAAa,SAAS;AACnC,SAAM,KAAK,KAAK,CAAC,YAAY,GAAG;AAChC;;AAGF,MAAI,CAAC,MAAM,SAAS;AAClB,OAAI,CAAC,aAAc;AACnB,SAAM,IAAI,MAAM,yBAAyB;;AAG3C,OAAK,eAAe,KAAK,iBAAiB;EAE1C,MAAM,KAAK,IAAI,iBAAiB;EAChC,MAAM,UAAU,SACd,MACA;GACE,MAAM;AACJ,UAAM,IAAI,MAAM,kBAAkB;;GAEpC,UAAU;AACR,UAAM,IAAI,MAAM,kBAAkB;;GAEpC,QAAQ,GAAG;GACZ,EACD,MAAM,MACP;AAED,OAAK,YAAY,QAAQ;AAEzB,MAAI;AACF,SAAM;WACC,OAAO;AACd,OAAI,CAAC,aAAc;AACnB,SAAM;;;;AAKZ,eAAe,SACb,OACA,SACA,UACA;CACA,MAAM,EAAE,WAAW,cAAc,iBAAiB,MAAM;CAExD,MAAM,OAAO,MAAM,UAAU,KAAK,OAAO;EACvC,GAAG;EACH,OAAO;EACP,UAAU,SAAS,SAAS,IAAI,SAAS,SAAS,SAAS,KAAM;EAClE,CAAC;CAEF,MAAM,QAAQ,SAAS,OAAO,WAAW,SAAS,OAAO,KAAK;CAC9D,MAAM,YAAY,cAAc,KAAK,OAAO,MAAM,IAAI;AAOtD,QAAO;EAAE;EAAO,SANA,eACZ,aAAa,KAAK,OAAO,MAAM,GAC/B,cAAc,OACZ,MAAM,SAAS,YACf,SAAS;EAEU;EAAW;;AAatC,SAAS,YACP,YACA,SACkE;AAClE,QAAO,gBAA+D,MAAM,cAAY;EACtF,IAAI,oBAAoB;AACxB,MAAI,6BAA6B,SAC/B,qBAAoB,kBAAkB,GAAG,KAAK;AAEhD,SAAO,IAAI,WAAW,mBAAmB,MAAMC,UAAQ;IACtD,QAAQ;;AAGb,MAAaC,mBACK,uBAAO,OAAO,aAAa,EACzC,gBAAgB,qBACjB,CAAC;;;;AC1KJ,SAAgB,cACd,OACA,WACA,cACG;CACH,MAAM,QAAQ,MAAM,UAAU,UAAU;AAExC,KAAI,SAAS,EACX,QAAO,MAAM;CAGf,MAAM,QAAQ,wBAAwB,WAAW,cAAc,GAAG;AAClE,OAAM,KAAK,MAAM;AACjB,QAAO"}
|
package/dist/mutative/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "../store-
|
|
2
|
-
import {
|
|
1
|
+
import "../store-XcnTdeiJ.cjs";
|
|
2
|
+
import { n as mutativeMethods, t as Mutation } from "../mutativeMethods-C8VcZWED.cjs";
|
|
3
3
|
export { type Mutation, mutativeMethods };
|
package/dist/mutative/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "../store-
|
|
2
|
-
import {
|
|
1
|
+
import "../store-BRHFhRPm.js";
|
|
2
|
+
import { n as mutativeMethods, t as Mutation } from "../mutativeMethods-BT1Cim3p.js";
|
|
3
3
|
export { type Mutation, mutativeMethods };
|
package/dist/mutative/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
require('../
|
|
3
|
-
|
|
1
|
+
require('../path-B-Rq5q6m.cjs');
|
|
2
|
+
const require_store = require('../store-C1NYHLgR.cjs');
|
|
3
|
+
require('../propAccess-C2AIn9RC.cjs');
|
|
4
|
+
const require_mutativeMethods = require('../mutativeMethods-CkNycpO9.cjs');
|
|
4
5
|
|
|
5
6
|
//#region src/mutative/register.ts
|
|
6
7
|
Object.assign(require_store.Store.prototype, require_mutativeMethods.mutativeMethods);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.cjs","names":["Store","mutativeMethods","autobind"],"sources":["../../src/mutative/register.ts"],"sourcesContent":["import { autobind } from '@lib/autobind';\nimport { mutativeMethods } from './mutativeMethods';\nimport { Store } from '@core';\n\ntype MutativeMethods = typeof mutativeMethods;\n\ndeclare module '..' {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Store<T> extends MutativeMethods {}\n}\n\nObject.assign(Store.prototype, mutativeMethods);\nautobind(Store);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"register.cjs","names":["Store","mutativeMethods","autobind"],"sources":["../../src/mutative/register.ts"],"sourcesContent":["import { autobind } from '@lib/autobind';\nimport { mutativeMethods } from './mutativeMethods';\nimport { Store } from '@core';\n\ntype MutativeMethods = typeof mutativeMethods;\n\ndeclare module '..' {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Store<T> extends MutativeMethods {}\n}\n\nObject.assign(Store.prototype, mutativeMethods);\nautobind(Store);\n"],"mappings":";;;;;;AAWA,OAAO,OAAOA,oBAAM,WAAWC,wCAAgB;AAC/CC,uBAASF,oBAAM"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import "../store-
|
|
2
|
-
import { mutativeMethods } from "../mutativeMethods-
|
|
1
|
+
import "../store-XcnTdeiJ.cjs";
|
|
2
|
+
import { n as mutativeMethods } from "../mutativeMethods-C8VcZWED.cjs";
|
|
3
3
|
|
|
4
4
|
//#region src/mutative/register.d.ts
|
|
5
5
|
type MutativeMethods = typeof mutativeMethods;
|
|
6
6
|
declare module ".." {
|
|
7
7
|
interface Store<T> extends MutativeMethods {}
|
|
8
8
|
}
|
|
9
|
-
//#endregion
|
|
10
|
-
export {};
|
|
11
9
|
//# sourceMappingURL=register.d.cts.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "../store-
|
|
2
|
-
import { mutativeMethods } from "../mutativeMethods-
|
|
1
|
+
import "../store-BRHFhRPm.js";
|
|
2
|
+
import { n as mutativeMethods } from "../mutativeMethods-BT1Cim3p.js";
|
|
3
3
|
|
|
4
4
|
//#region src/mutative/register.d.ts
|
|
5
5
|
type MutativeMethods = typeof mutativeMethods;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "../propAccess-
|
|
3
|
-
import
|
|
1
|
+
import { h as autobind, t as Store } from "../store-v3RYWzVg.js";
|
|
2
|
+
import "../propAccess-DvWFpYoj.js";
|
|
3
|
+
import "../path-CyYq74W8.js";
|
|
4
|
+
import { t as mutativeMethods } from "../mutativeMethods-Jowr0Znn.js";
|
|
4
5
|
|
|
5
6
|
//#region src/mutative/register.ts
|
|
6
7
|
Object.assign(Store.prototype, mutativeMethods);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.js","names":[],"sources":["../../src/mutative/register.ts"],"sourcesContent":["import { autobind } from '@lib/autobind';\nimport { mutativeMethods } from './mutativeMethods';\nimport { Store } from '@core';\n\ntype MutativeMethods = typeof mutativeMethods;\n\ndeclare module '..' {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Store<T> extends MutativeMethods {}\n}\n\nObject.assign(Store.prototype, mutativeMethods);\nautobind(Store);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"register.js","names":[],"sources":["../../src/mutative/register.ts"],"sourcesContent":["import { autobind } from '@lib/autobind';\nimport { mutativeMethods } from './mutativeMethods';\nimport { Store } from '@core';\n\ntype MutativeMethods = typeof mutativeMethods;\n\ndeclare module '..' {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Store<T> extends MutativeMethods {}\n}\n\nObject.assign(Store.prototype, mutativeMethods);\nautobind(Store);\n"],"mappings":";;;;;;AAWA,OAAO,OAAO,MAAM,WAAW,gBAAgB;AAC/C,SAAS,MAAM"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Constrain, Path, Store
|
|
1
|
+
import { B as Value, K as Constrain, N as Path, r as Store } from "./store-BRHFhRPm.js";
|
|
2
2
|
import { Draft } from "mutative";
|
|
3
3
|
|
|
4
4
|
//#region src/mutative/mutativeMethods.d.ts
|
|
@@ -9,5 +9,5 @@ declare const mutativeMethods: {
|
|
|
9
9
|
update: typeof update;
|
|
10
10
|
};
|
|
11
11
|
//#endregion
|
|
12
|
-
export {
|
|
13
|
-
//# sourceMappingURL=mutativeMethods-
|
|
12
|
+
export { mutativeMethods as n, Mutation as t };
|
|
13
|
+
//# sourceMappingURL=mutativeMethods-BT1Cim3p.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Constrain, Path, Store
|
|
1
|
+
import { B as Value, K as Constrain, N as Path, r as Store } from "./store-XcnTdeiJ.cjs";
|
|
2
2
|
import { Draft } from "mutative";
|
|
3
3
|
|
|
4
4
|
//#region src/mutative/mutativeMethods.d.ts
|
|
@@ -9,5 +9,5 @@ declare const mutativeMethods: {
|
|
|
9
9
|
update: typeof update;
|
|
10
10
|
};
|
|
11
11
|
//#endregion
|
|
12
|
-
export {
|
|
13
|
-
//# sourceMappingURL=mutativeMethods-
|
|
12
|
+
export { mutativeMethods as n, Mutation as t };
|
|
13
|
+
//# sourceMappingURL=mutativeMethods-C8VcZWED.d.cts.map
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
1
|
+
const require_path = require('./path-B-Rq5q6m.cjs');
|
|
2
|
+
let mutative = require("mutative");
|
|
3
|
+
mutative = require_path.__toESM(mutative);
|
|
3
4
|
|
|
4
5
|
//#region src/mutative/mutativeMethods.ts
|
|
5
6
|
function update(...args) {
|
|
6
7
|
if (args.length === 1) {
|
|
7
8
|
const [mutation] = args;
|
|
8
9
|
this.set((value) => {
|
|
9
|
-
|
|
10
|
+
return (0, mutative.create)(value, (draft) => {
|
|
10
11
|
mutation(draft);
|
|
11
12
|
});
|
|
12
|
-
return result;
|
|
13
13
|
});
|
|
14
14
|
} else {
|
|
15
15
|
const [path, mutation] = args;
|
|
16
16
|
this.set(path, (value) => {
|
|
17
|
-
|
|
17
|
+
return (0, mutative.create)(value, (draft) => {
|
|
18
18
|
mutation(draft);
|
|
19
19
|
});
|
|
20
|
-
return result;
|
|
21
20
|
});
|
|
22
21
|
}
|
|
23
22
|
}
|
|
@@ -30,4 +29,4 @@ Object.defineProperty(exports, 'mutativeMethods', {
|
|
|
30
29
|
return mutativeMethods;
|
|
31
30
|
}
|
|
32
31
|
});
|
|
33
|
-
//# sourceMappingURL=mutativeMethods-
|
|
32
|
+
//# sourceMappingURL=mutativeMethods-CkNycpO9.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutativeMethods-
|
|
1
|
+
{"version":3,"file":"mutativeMethods-CkNycpO9.cjs","names":["mutativeMethods: {\n update: typeof update;\n}"],"sources":["../src/mutative/mutativeMethods.ts"],"sourcesContent":["import type { Store } from '@core/store';\nimport type { Constrain } from '@lib/constrain';\nimport { type Path, type Value } from '@lib/path';\nimport { create, type Draft } from 'mutative';\n\nexport type Mutation<T> = (draft: Draft<T>) => void;\n\nfunction update<T>(this: Store<T>, mutation: Mutation<T>): void;\n\nfunction update<T, const P>(\n this: Store<T>,\n path: Constrain<P, Path<T>>,\n mutation: Mutation<Value<T, P>>,\n): void;\n\nfunction update<T, const TPath>(\n this: Store<T>,\n ...args:\n | [recipe: Mutation<T>]\n | [path: Constrain<TPath, Path<T>>, mutation: Mutation<Value<T, TPath>>]\n) {\n if (args.length === 1) {\n const [mutation] = args;\n\n this.set((value) => {\n const result = create(value, (draft) => {\n mutation(draft);\n });\n return result;\n });\n } else {\n const [path, mutation] = args;\n\n this.set(path, (value) => {\n const result = create(value, (draft) => {\n mutation(draft);\n });\n return result;\n });\n }\n}\n\nexport const mutativeMethods: {\n update: typeof update;\n} = {\n update,\n};\n"],"mappings":";;;;;AAeA,SAAS,OAEP,GAAG,MAGH;AACA,KAAI,KAAK,WAAW,GAAG;EACrB,MAAM,CAAC,YAAY;AAEnB,OAAK,KAAK,UAAU;AAIlB,+BAHsB,QAAQ,UAAU;AACtC,aAAS,MAAM;KACf;IAEF;QACG;EACL,MAAM,CAAC,MAAM,YAAY;AAEzB,OAAK,IAAI,OAAO,UAAU;AAIxB,+BAHsB,QAAQ,UAAU;AACtC,aAAS,MAAM;KACf;IAEF;;;AAIN,MAAaA,kBAET,EACF,QACD"}
|
|
@@ -5,23 +5,21 @@ function update(...args) {
|
|
|
5
5
|
if (args.length === 1) {
|
|
6
6
|
const [mutation] = args;
|
|
7
7
|
this.set((value) => {
|
|
8
|
-
|
|
8
|
+
return create(value, (draft) => {
|
|
9
9
|
mutation(draft);
|
|
10
10
|
});
|
|
11
|
-
return result;
|
|
12
11
|
});
|
|
13
12
|
} else {
|
|
14
13
|
const [path, mutation] = args;
|
|
15
14
|
this.set(path, (value) => {
|
|
16
|
-
|
|
15
|
+
return create(value, (draft) => {
|
|
17
16
|
mutation(draft);
|
|
18
17
|
});
|
|
19
|
-
return result;
|
|
20
18
|
});
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
21
|
const mutativeMethods = { update };
|
|
24
22
|
|
|
25
23
|
//#endregion
|
|
26
|
-
export { mutativeMethods };
|
|
27
|
-
//# sourceMappingURL=mutativeMethods-
|
|
24
|
+
export { mutativeMethods as t };
|
|
25
|
+
//# sourceMappingURL=mutativeMethods-Jowr0Znn.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutativeMethods-
|
|
1
|
+
{"version":3,"file":"mutativeMethods-Jowr0Znn.js","names":["mutativeMethods: {\n update: typeof update;\n}"],"sources":["../src/mutative/mutativeMethods.ts"],"sourcesContent":["import type { Store } from '@core/store';\nimport type { Constrain } from '@lib/constrain';\nimport { type Path, type Value } from '@lib/path';\nimport { create, type Draft } from 'mutative';\n\nexport type Mutation<T> = (draft: Draft<T>) => void;\n\nfunction update<T>(this: Store<T>, mutation: Mutation<T>): void;\n\nfunction update<T, const P>(\n this: Store<T>,\n path: Constrain<P, Path<T>>,\n mutation: Mutation<Value<T, P>>,\n): void;\n\nfunction update<T, const TPath>(\n this: Store<T>,\n ...args:\n | [recipe: Mutation<T>]\n | [path: Constrain<TPath, Path<T>>, mutation: Mutation<Value<T, TPath>>]\n) {\n if (args.length === 1) {\n const [mutation] = args;\n\n this.set((value) => {\n const result = create(value, (draft) => {\n mutation(draft);\n });\n return result;\n });\n } else {\n const [path, mutation] = args;\n\n this.set(path, (value) => {\n const result = create(value, (draft) => {\n mutation(draft);\n });\n return result;\n });\n }\n}\n\nexport const mutativeMethods: {\n update: typeof update;\n} = {\n update,\n};\n"],"mappings":";;;AAeA,SAAS,OAEP,GAAG,MAGH;AACA,KAAI,KAAK,WAAW,GAAG;EACrB,MAAM,CAAC,YAAY;AAEnB,OAAK,KAAK,UAAU;AAIlB,UAHe,OAAO,QAAQ,UAAU;AACtC,aAAS,MAAM;KACf;IAEF;QACG;EACL,MAAM,CAAC,MAAM,YAAY;AAEzB,OAAK,IAAI,OAAO,UAAU;AAIxB,UAHe,OAAO,QAAQ,UAAU;AACtC,aAAS,MAAM;KACf;IAEF;;;AAIN,MAAaA,kBAET,EACF,QACD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_propAccess = require('./propAccess-
|
|
2
|
-
const require_extendedJson = require('./extendedJson-
|
|
1
|
+
const require_propAccess = require('./propAccess-C2AIn9RC.cjs');
|
|
2
|
+
const require_extendedJson = require('./extendedJson-ursQ8DbQ.cjs');
|
|
3
3
|
|
|
4
4
|
//#region src/lib/applyPatches.ts
|
|
5
5
|
function applySinglePatch(target, patch) {
|
|
@@ -15,9 +15,7 @@ function applyPatches(target, ...patches) {
|
|
|
15
15
|
//#region src/lib/diff.ts
|
|
16
16
|
function diff(a, b, options = {}) {
|
|
17
17
|
const result = [..._diff(a, b, options)];
|
|
18
|
-
|
|
19
|
-
const reversePatches = result.map(([, reversePatch]) => reversePatch);
|
|
20
|
-
return [patches, reversePatches];
|
|
18
|
+
return [result.map(([patch]) => patch), result.map(([, reversePatch]) => reversePatch)];
|
|
21
19
|
}
|
|
22
20
|
function* _diff(a, b, options, prefix = []) {
|
|
23
21
|
if (a === b) return;
|
|
@@ -261,4 +259,4 @@ Object.defineProperty(exports, 'subscribePatches', {
|
|
|
261
259
|
return subscribePatches;
|
|
262
260
|
}
|
|
263
261
|
});
|
|
264
|
-
//# sourceMappingURL=patchMethods-
|
|
262
|
+
//# sourceMappingURL=patchMethods-B7Hm5-Qh.cjs.map
|