cross-state 1.9.6 → 1.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/dist/{diff-Bcr0h7-x.d.cts → diff-BzE2cDaU.d.cts} +2 -2
  2. package/dist/{diff-CwiTYAVK.d.ts → diff-Cvc-z20n.d.ts} +2 -2
  3. package/dist/{extendedJson-DA3RQ_ly.js → extendedJson-BOmrkRrD.js} +2 -2
  4. package/dist/{extendedJson-DA3RQ_ly.js.map → extendedJson-BOmrkRrD.js.map} +1 -1
  5. package/dist/{extendedJson-DzXMFE1P.cjs → extendedJson-pbOLcymB.cjs} +2 -2
  6. package/dist/{extendedJson-DzXMFE1P.cjs.map → extendedJson-pbOLcymB.cjs.map} +1 -1
  7. package/dist/index.cjs +9 -8
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +6 -6
  10. package/dist/index.d.ts +6 -6
  11. package/dist/index.js +8 -8
  12. package/dist/index.js.map +1 -1
  13. package/dist/mutative/index.cjs +2 -1
  14. package/dist/mutative/index.d.cts +1 -1
  15. package/dist/mutative/index.d.ts +1 -1
  16. package/dist/mutative/index.js +1 -1
  17. package/dist/mutative/register.cjs +2 -2
  18. package/dist/mutative/register.cjs.map +1 -1
  19. package/dist/mutative/register.d.cts +2 -2
  20. package/dist/mutative/register.d.ts +2 -2
  21. package/dist/mutative/register.js +2 -2
  22. package/dist/mutative/register.js.map +1 -1
  23. package/dist/{mutativeMethods-CwDMtUNs.cjs → mutativeMethods-AiKkraqx.cjs} +1 -1
  24. package/dist/mutativeMethods-AiKkraqx.cjs.map +1 -0
  25. package/dist/{mutativeMethods-Do8JiJ5A.d.cts → mutativeMethods-BHPlSHBi.d.cts} +2 -2
  26. package/dist/{mutativeMethods-t67Kp1uA.d.ts → mutativeMethods-COQxFB3B.d.ts} +2 -2
  27. package/dist/{mutativeMethods-BrDU8SwY.js → mutativeMethods-qVJ36MY5.js} +1 -1
  28. package/dist/mutativeMethods-qVJ36MY5.js.map +1 -0
  29. package/dist/{patchMethods-C21iQqML.d.ts → patchMethods--ekCkYUF.d.ts} +4 -4
  30. package/dist/{patchMethods-CZje49Dk.cjs → patchMethods-BBQDDqwe.cjs} +9 -9
  31. package/dist/patchMethods-BBQDDqwe.cjs.map +1 -0
  32. package/dist/{patchMethods-Cui462lc.js → patchMethods-D3cdG80W.js} +9 -9
  33. package/dist/patchMethods-D3cdG80W.js.map +1 -0
  34. package/dist/{patchMethods-Cyb6MEOG.d.cts → patchMethods-R3f7HxTy.d.cts} +4 -4
  35. package/dist/patches/index.cjs +2 -1
  36. package/dist/patches/index.d.cts +1 -1
  37. package/dist/patches/index.d.ts +1 -1
  38. package/dist/patches/index.js +1 -1
  39. package/dist/patches/register.cjs +2 -2
  40. package/dist/patches/register.cjs.map +1 -1
  41. package/dist/patches/register.d.cts +2 -2
  42. package/dist/patches/register.d.ts +2 -2
  43. package/dist/patches/register.js +2 -2
  44. package/dist/patches/register.js.map +1 -1
  45. package/dist/{path-Il5r4PV4.cjs → path-B9-Z0127.cjs} +1 -1
  46. package/dist/{path-Il5r4PV4.cjs.map → path-B9-Z0127.cjs.map} +1 -1
  47. package/dist/{path-CCEtQjMB.js → path-C-5jTZu5.js} +1 -1
  48. package/dist/{path-CCEtQjMB.js.map → path-C-5jTZu5.js.map} +1 -1
  49. package/dist/persist/register.cjs +2 -2
  50. package/dist/persist/register.cjs.map +1 -1
  51. package/dist/persist/register.d.cts +2 -2
  52. package/dist/persist/register.d.ts +2 -2
  53. package/dist/persist/register.js +2 -2
  54. package/dist/persist/register.js.map +1 -1
  55. package/dist/{persist-CG1WHP6D.cjs → persist-B341lrOA.cjs} +43 -45
  56. package/dist/persist-B341lrOA.cjs.map +1 -0
  57. package/dist/{persist-CkZ7CzW8.d.cts → persist-CoSWtRt0.d.cts} +3 -3
  58. package/dist/{persist-3Nff6j1f.d.ts → persist-XVT4fROX.d.ts} +3 -3
  59. package/dist/{persist-CNA2sYtB.js → persist-xv73m7UR.js} +43 -45
  60. package/dist/persist-xv73m7UR.js.map +1 -0
  61. package/dist/{propAccess-BxCKNeOj.js → propAccess-CsUaG5V_.js} +8 -8
  62. package/dist/propAccess-CsUaG5V_.js.map +1 -0
  63. package/dist/{propAccess-udIdjqwY.cjs → propAccess-DdLF12Jq.cjs} +8 -8
  64. package/dist/propAccess-DdLF12Jq.cjs.map +1 -0
  65. package/dist/react/index.cjs +118 -117
  66. package/dist/react/index.cjs.map +1 -1
  67. package/dist/react/index.d.cts +98 -98
  68. package/dist/react/index.d.ts +97 -97
  69. package/dist/react/index.js +119 -119
  70. package/dist/react/index.js.map +1 -1
  71. package/dist/react/register.cjs +3 -3
  72. package/dist/react/register.cjs.map +1 -1
  73. package/dist/react/register.d.cts +2 -2
  74. package/dist/react/register.d.ts +2 -2
  75. package/dist/react/register.js +3 -3
  76. package/dist/react/register.js.map +1 -1
  77. package/dist/{scope-DkX72a-2.cjs → scope-8MUrzqlS.cjs} +60 -60
  78. package/dist/scope-8MUrzqlS.cjs.map +1 -0
  79. package/dist/{scope-8uUaV6I8.d.cts → scope-BQjncWGt.d.cts} +25 -25
  80. package/dist/{scope-CQE3HDNI.js → scope-BfaweXvz.js} +61 -61
  81. package/dist/scope-BfaweXvz.js.map +1 -0
  82. package/dist/{scope-qdOAlRWQ.d.ts → scope-BztVo2P8.d.ts} +25 -25
  83. package/dist/{store-D4q5zD7q.js → store-BmlnyYal.js} +81 -81
  84. package/dist/store-BmlnyYal.js.map +1 -0
  85. package/dist/{store-Cq1PqvEo.d.ts → store-dThvqc0k.d.cts} +55 -55
  86. package/dist/{store-21GsOOLS.d.cts → store-dThvqc0k.d.ts} +55 -55
  87. package/dist/{store-CPqOf4y5.cjs → store-fmAYV5hy.cjs} +80 -80
  88. package/dist/store-fmAYV5hy.cjs.map +1 -0
  89. package/dist/{storeMethods-BjuI0joo.d.cts → storeMethods-CYX3AAnA.d.ts} +4 -4
  90. package/dist/{storeMethods-BZb4k7Ma.cjs → storeMethods-DYgUGHSk.cjs} +14 -14
  91. package/dist/storeMethods-DYgUGHSk.cjs.map +1 -0
  92. package/dist/{storeMethods-CK9-Q17H.d.ts → storeMethods-DrMQ7hqX.d.cts} +4 -4
  93. package/dist/{storeMethods-CWeGkXoz.js → storeMethods-pGlt0zfb.js} +14 -14
  94. package/dist/storeMethods-pGlt0zfb.js.map +1 -0
  95. package/package.json +46 -63
  96. package/dist/mutativeMethods-BrDU8SwY.js.map +0 -1
  97. package/dist/mutativeMethods-CwDMtUNs.cjs.map +0 -1
  98. package/dist/patchMethods-CZje49Dk.cjs.map +0 -1
  99. package/dist/patchMethods-Cui462lc.js.map +0 -1
  100. package/dist/persist-CG1WHP6D.cjs.map +0 -1
  101. package/dist/persist-CNA2sYtB.js.map +0 -1
  102. package/dist/propAccess-BxCKNeOj.js.map +0 -1
  103. package/dist/propAccess-udIdjqwY.cjs.map +0 -1
  104. package/dist/scope-CQE3HDNI.js.map +0 -1
  105. package/dist/scope-DkX72a-2.cjs.map +0 -1
  106. package/dist/store-CPqOf4y5.cjs.map +0 -1
  107. package/dist/store-D4q5zD7q.js.map +0 -1
  108. package/dist/storeMethods-BZb4k7Ma.cjs.map +0 -1
  109. package/dist/storeMethods-CWeGkXoz.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { M as KeyType } from "./store-21GsOOLS.cjs";
1
+ import { h as KeyType } from "./store-dThvqc0k.cjs";
2
2
 
3
3
  //#region src/lib/diff.d.ts
4
4
  type Patch = {
@@ -20,4 +20,4 @@ interface DiffOptions {
20
20
  declare function diff(a: any, b: any, options?: DiffOptions): [patches: Patch[], reversePatches: Patch[]];
21
21
  //#endregion
22
22
  export { Patch as n, diff as r, DiffOptions as t };
23
- //# sourceMappingURL=diff-Bcr0h7-x.d.cts.map
23
+ //# sourceMappingURL=diff-BzE2cDaU.d.cts.map
@@ -1,4 +1,4 @@
1
- import { M as KeyType } from "./store-Cq1PqvEo.js";
1
+ import { h as KeyType } from "./store-dThvqc0k.js";
2
2
 
3
3
  //#region src/lib/diff.d.ts
4
4
  type Patch = {
@@ -20,4 +20,4 @@ interface DiffOptions {
20
20
  declare function diff(a: any, b: any, options?: DiffOptions): [patches: Patch[], reversePatches: Patch[]];
21
21
  //#endregion
22
22
  export { Patch as n, diff as r, DiffOptions as t };
23
- //# sourceMappingURL=diff-CwiTYAVK.d.ts.map
23
+ //# sourceMappingURL=diff-Cvc-z20n.d.ts.map
@@ -1,4 +1,4 @@
1
- import { c as deepEqual, o as isObject } from "./propAccess-BxCKNeOj.js";
1
+ import { c as deepEqual, o as isObject } from "./propAccess-CsUaG5V_.js";
2
2
 
3
3
  //#region src/lib/diff.ts
4
4
  function diff(a, b, options = {}) {
@@ -135,4 +135,4 @@ function fromExtendedJsonString(value, reviver) {
135
135
 
136
136
  //#endregion
137
137
  export { diff as a, toExtendedJsonString as i, fromExtendedJsonString as n, toExtendedJson as r, fromExtendedJson as t };
138
- //# sourceMappingURL=extendedJson-DA3RQ_ly.js.map
138
+ //# sourceMappingURL=extendedJson-BOmrkRrD.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"extendedJson-DA3RQ_ly.js","names":[],"sources":["../src/lib/diff.ts","../src/lib/extendedJson.ts"],"sourcesContent":["import { isObject } from '@lib/helpers';\nimport { deepEqual } from './equals';\nimport type { KeyType } from './path';\n\nexport type Patch =\n | { op: 'add'; path: KeyType[]; value: any }\n | { op: 'remove'; path: KeyType[] }\n | { op: 'replace'; path: KeyType[]; value: any };\n\nexport interface DiffOptions {\n stopAt?: number | ((path: KeyType[]) => boolean);\n diffArrays?: boolean;\n}\n\nexport function diff(\n a: any,\n b: any,\n options: DiffOptions = {},\n): [patches: Patch[], reversePatches: Patch[]] {\n const result = [..._diff(a, b, options)];\n const patches = result.map(([patch]) => patch);\n const reversePatches = result.map(([, reversePatch]) => reversePatch);\n\n return [patches, reversePatches];\n}\n\nfunction* _diff(\n a: any,\n b: any,\n options: DiffOptions,\n prefix: KeyType[] = [],\n): Iterable<[patch: Patch, reversePatch: Patch]> {\n if (a === b) {\n return;\n }\n\n if (\n (typeof options.stopAt === 'number' && prefix.length >= options.stopAt) ||\n (typeof options.stopAt === 'function' && options.stopAt(prefix))\n ) {\n if (deepEqual(a, b)) {\n return;\n }\n\n return yield [\n { op: 'replace', path: prefix, value: b },\n { op: 'replace', path: prefix, value: a },\n ];\n }\n\n if (a instanceof Date && b instanceof Date) {\n if (a.getTime() === b.getTime()) {\n return;\n }\n\n return yield [\n { op: 'replace', path: prefix, value: b },\n { op: 'replace', path: prefix, value: a },\n ];\n }\n\n if (a instanceof Map && b instanceof Map) {\n return yield* mapDiff(a, b, options, prefix);\n }\n\n if (a instanceof Set && b instanceof Set) {\n if (deepEqual(a, b)) {\n return;\n }\n\n return yield [\n { op: 'replace', path: prefix, value: b },\n { op: 'replace', path: prefix, value: a },\n ];\n }\n\n if (!options.diffArrays && Array.isArray(a) && Array.isArray(b)) {\n if (deepEqual(a, b)) {\n return;\n }\n\n return yield [\n { op: 'replace', path: prefix, value: b },\n { op: 'replace', path: prefix, value: a },\n ];\n }\n\n if (\n isObject(a) &&\n isObject(b) &&\n (options.diffArrays || (!Array.isArray(a) && !Array.isArray(b)))\n ) {\n return yield* objectDiff(a, b, options, prefix);\n }\n\n yield [\n { op: 'replace', path: prefix, value: b },\n { op: 'replace', path: prefix, value: a },\n ];\n}\n\nfunction* mapDiff(\n a: Map<any, any>,\n b: Map<any, any>,\n options: { stopAt?: number | ((path: KeyType[]) => boolean) },\n prefix: KeyType[],\n): Iterable<[patch: Patch, reversePatch: Patch]> {\n for (const [key, value] of a) {\n if (!b.has(key)) {\n yield [\n { op: 'remove', path: [...prefix, key] },\n { op: 'add', path: [...prefix, key], value },\n ];\n } else {\n yield* _diff(value, b.get(key), options, [...prefix, key]);\n }\n }\n\n for (const [key, value] of b) {\n if (!a.has(key)) {\n yield [\n { op: 'add', path: [...prefix, key], value },\n { op: 'remove', path: [...prefix, key] },\n ];\n }\n }\n}\n\nfunction* objectDiff(\n a: any,\n b: any,\n options: { stopAt?: number | ((path: KeyType[]) => boolean) },\n prefix: KeyType[],\n): Iterable<[patch: Patch, reversePatch: Patch]> {\n for (const [key, value] of Object.entries(a)) {\n if (!(key in b)) {\n yield [\n { op: 'remove', path: [...prefix, key] },\n { op: 'add', path: [...prefix, key], value },\n ];\n } else {\n yield* _diff(value, b[key], options, [...prefix, key]);\n }\n }\n\n for (const [key, value] of Object.entries(b)) {\n if (!(key in a)) {\n yield [\n { op: 'add', path: [...prefix, key], value },\n { op: 'remove', path: [...prefix, key] },\n ];\n }\n }\n}\n","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":";;;AAcA,SAAgB,KACd,GACA,GACA,UAAuB,EAAE,EACoB;CAC7C,MAAM,SAAS,CAAC,GAAG,MAAM,GAAG,GAAG,QAAQ,CAAC;AAIxC,QAAO,CAHS,OAAO,KAAK,CAAC,WAAW,MAAM,EACvB,OAAO,KAAK,GAAG,kBAAkB,aAAa,CAErC;;AAGlC,UAAU,MACR,GACA,GACA,SACA,SAAoB,EAAE,EACyB;AAC/C,KAAI,MAAM,EACR;AAGF,KACG,OAAO,QAAQ,WAAW,YAAY,OAAO,UAAU,QAAQ,UAC/D,OAAO,QAAQ,WAAW,cAAc,QAAQ,OAAO,OAAO,EAC/D;AACA,MAAI,UAAU,GAAG,EAAE,CACjB;AAGF,SAAO,MAAM,CACX;GAAE,IAAI;GAAW,MAAM;GAAQ,OAAO;GAAG,EACzC;GAAE,IAAI;GAAW,MAAM;GAAQ,OAAO;GAAG,CAC1C;;AAGH,KAAI,aAAa,QAAQ,aAAa,MAAM;AAC1C,MAAI,EAAE,SAAS,KAAK,EAAE,SAAS,CAC7B;AAGF,SAAO,MAAM,CACX;GAAE,IAAI;GAAW,MAAM;GAAQ,OAAO;GAAG,EACzC;GAAE,IAAI;GAAW,MAAM;GAAQ,OAAO;GAAG,CAC1C;;AAGH,KAAI,aAAa,OAAO,aAAa,IACnC,QAAO,OAAO,QAAQ,GAAG,GAAG,SAAS,OAAO;AAG9C,KAAI,aAAa,OAAO,aAAa,KAAK;AACxC,MAAI,UAAU,GAAG,EAAE,CACjB;AAGF,SAAO,MAAM,CACX;GAAE,IAAI;GAAW,MAAM;GAAQ,OAAO;GAA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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
+ {"version":3,"file":"extendedJson-BOmrkRrD.js","names":[],"sources":["../src/lib/diff.ts","../src/lib/extendedJson.ts"],"sourcesContent":["import { deepEqual } from './equals';\nimport type { KeyType } from './path';\nimport { isObject } from '@lib/helpers';\n\nexport type Patch =\n | { op: 'add'; path: KeyType[]; value: any }\n | { op: 'remove'; path: KeyType[] }\n | { op: 'replace'; path: KeyType[]; value: any };\n\nexport interface DiffOptions {\n stopAt?: number | ((path: KeyType[]) => boolean);\n diffArrays?: boolean;\n}\n\nexport function diff(\n a: any,\n b: any,\n options: DiffOptions = {},\n): [patches: Patch[], reversePatches: Patch[]] {\n const result = [..._diff(a, b, options)];\n const patches = result.map(([patch]) => patch);\n const reversePatches = result.map(([, reversePatch]) => reversePatch);\n\n return [patches, reversePatches];\n}\n\nfunction* _diff(\n a: any,\n b: any,\n options: DiffOptions,\n prefix: KeyType[] = [],\n): Iterable<[patch: Patch, reversePatch: Patch]> {\n if (a === b) {\n return;\n }\n\n if (\n (typeof options.stopAt === 'number' && prefix.length >= options.stopAt) ||\n (typeof options.stopAt === 'function' && options.stopAt(prefix))\n ) {\n if (deepEqual(a, b)) {\n return;\n }\n\n return yield [\n { op: 'replace', path: prefix, value: b },\n { op: 'replace', path: prefix, value: a },\n ];\n }\n\n if (a instanceof Date && b instanceof Date) {\n if (a.getTime() === b.getTime()) {\n return;\n }\n\n return yield [\n { op: 'replace', path: prefix, value: b },\n { op: 'replace', path: prefix, value: a },\n ];\n }\n\n if (a instanceof Map && b instanceof Map) {\n return yield* mapDiff(a, b, options, prefix);\n }\n\n if (a instanceof Set && b instanceof Set) {\n if (deepEqual(a, b)) {\n return;\n }\n\n return yield [\n { op: 'replace', path: prefix, value: b },\n { op: 'replace', path: prefix, value: a },\n ];\n }\n\n if (!options.diffArrays && Array.isArray(a) && Array.isArray(b)) {\n if (deepEqual(a, b)) {\n return;\n }\n\n return yield [\n { op: 'replace', path: prefix, value: b },\n { op: 'replace', path: prefix, value: a },\n ];\n }\n\n if (\n isObject(a) &&\n isObject(b) &&\n (options.diffArrays || (!Array.isArray(a) && !Array.isArray(b)))\n ) {\n return yield* objectDiff(a, b, options, prefix);\n }\n\n yield [\n { op: 'replace', path: prefix, value: b },\n { op: 'replace', path: prefix, value: a },\n ];\n}\n\nfunction* mapDiff(\n a: Map<any, any>,\n b: Map<any, any>,\n options: { stopAt?: number | ((path: KeyType[]) => boolean) },\n prefix: KeyType[],\n): Iterable<[patch: Patch, reversePatch: Patch]> {\n for (const [key, value] of a) {\n if (!b.has(key)) {\n yield [\n { op: 'remove', path: [...prefix, key] },\n { op: 'add', path: [...prefix, key], value },\n ];\n } else {\n yield* _diff(value, b.get(key), options, [...prefix, key]);\n }\n }\n\n for (const [key, value] of b) {\n if (!a.has(key)) {\n yield [\n { op: 'add', path: [...prefix, key], value },\n { op: 'remove', path: [...prefix, key] },\n ];\n }\n }\n}\n\nfunction* objectDiff(\n a: any,\n b: any,\n options: { stopAt?: number | ((path: KeyType[]) => boolean) },\n prefix: KeyType[],\n): Iterable<[patch: Patch, reversePatch: Patch]> {\n for (const [key, value] of Object.entries(a)) {\n if (!(key in b)) {\n yield [\n { op: 'remove', path: [...prefix, key] },\n { op: 'add', path: [...prefix, key], value },\n ];\n } else {\n yield* _diff(value, b[key], options, [...prefix, key]);\n }\n }\n\n for (const [key, value] of Object.entries(b)) {\n if (!(key in a)) {\n yield [\n { op: 'add', path: [...prefix, key], value },\n { op: 'remove', path: [...prefix, key] },\n ];\n }\n }\n}\n","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":";;;AAcA,SAAgB,KACd,GACA,GACA,UAAuB,CAAC,GACqB;CAC7C,MAAM,SAAS,CAAC,GAAG,MAAM,GAAG,GAAG,OAAO,CAAC;CAIvC,OAAO,CAHS,OAAO,KAAK,CAAC,WAAW,KAG1B,GAFS,OAAO,KAAK,GAAG,kBAAkB,YAE1B,CAAC;AACjC;AAEA,UAAU,MACR,GACA,GACA,SACA,SAAoB,CAAC,GAC0B;CAC/C,IAAI,MAAM,GACR;CAGF,IACG,OAAO,QAAQ,WAAW,YAAY,OAAO,UAAU,QAAQ,UAC/D,OAAO,QAAQ,WAAW,cAAc,QAAQ,OAAO,MAAM,GAC9D;EACA,IAAI,UAAU,GAAG,CAAC,GAChB;EAGF,OAAO,MAAM,CACX;GAAE,IAAI;GAAW,MAAM;GAAQ,OAAO;EAAE,GACxC;GAAE,IAAI;GAAW,MAAM;GAAQ,OAAO;EAAE,CAC1C;CACF;CAEA,IAAI,aAAa,QAAQ,aAAa,MAAM;EAC1C,IAAI,EAAE,QAAQ,MAAM,EAAE,QAAQ,GAC5B;EAGF,OAAO,MAAM,CACX;GAAE,IAAI;GAAW,MAAM;GAAQ,OAAO;EAAE,GACxC;GAAE,IAAI;GAAW,MAAM;GAAQ,OAAO;EAAE,CAC1C;CACF;CAEA,IAAI,aAAa,OAAO,aAAa,KACnC,OAAO,OAAO,QAAQ,GAAG,GAAG,SAAS,MAAM;CAG7C,IAAI,aAAa,OAAO,aAAa,KAAK;EACxC,IAAI,UAAU,GAAG,CAAC,GAChB;EAGF,OAAO,MAAM,CACX;GAAE,IAAI;GAAW,MAAM;GAAQ,OAAO;EAAE,GACxC;GAAE,IAAI;G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iBAAiB,OAAyB;CACxD,IAAI,OAAO,UAAU,YAAY,UAAU,MACzC,OAAO;CAGT,IAAI,WAAW,OACb,OAAO,IAAI,IACR,MAAM,MAA+B,KAAK,CAAC,GAAG,OAAO,CACpD,iBAAiB,CAAC,GAClB,iBAAiB,CAAC,CACpB,CAAC,CACH;CAGF,IAAI,WAAW,OACb,OAAO,IAAI,IAAK,MAAM,MAAoB,IAAI,gBAAgB,CAAC;CAGjE,IAAI,YAAY,OACd,OAAO,IAAI,KAAK,MAAM,MAAgB;CAGxC,IAAI,cAAc,OAChB,OAAO,OAAO,MAAM,QAAkB;CAGxC,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,MAAM,IAAI,gBAAgB;CAGnC,OAAO,OAAO,YAAY,OAAO,QAAQ,KAAK,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;AAC3F;AAEA,SAAgB,uBACd,OACA,SACS;CACT,OAAO,iBAAiB,KAAK,MAAM,OAAO,OAAO,CAAC;AACpD"}
@@ -1,4 +1,4 @@
1
- const require_propAccess = require('./propAccess-udIdjqwY.cjs');
1
+ const require_propAccess = require('./propAccess-DdLF12Jq.cjs');
2
2
 
3
3
  //#region src/lib/diff.ts
4
4
  function diff(a, b, options = {}) {
@@ -164,4 +164,4 @@ Object.defineProperty(exports, 'toExtendedJsonString', {
164
164
  return toExtendedJsonString;
165
165
  }
166
166
  });
167
- //# sourceMappingURL=extendedJson-DzXMFE1P.cjs.map
167
+ //# sourceMappingURL=extendedJson-pbOLcymB.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"extendedJson-DzXMFE1P.cjs","names":["deepEqual","isObject"],"sources":["../src/lib/diff.ts","../src/lib/extendedJson.ts"],"sourcesContent":["import { isObject } from '@lib/helpers';\nimport { deepEqual } from './equals';\nimport type { KeyType } from './path';\n\nexport type Patch =\n | { op: 'add'; path: KeyType[]; value: any }\n | { op: 'remove'; path: KeyType[] }\n | { op: 'replace'; path: KeyType[]; value: any };\n\nexport interface DiffOptions {\n stopAt?: number | ((path: KeyType[]) => boolean);\n diffArrays?: boolean;\n}\n\nexport function diff(\n a: any,\n b: any,\n options: DiffOptions = {},\n): [patches: Patch[], reversePatches: Patch[]] {\n const result = [..._diff(a, b, options)];\n const patches = result.map(([patch]) => patch);\n const reversePatches = result.map(([, reversePatch]) => reversePatch);\n\n return [patches, reversePatches];\n}\n\nfunction* _diff(\n a: any,\n b: any,\n options: DiffOptions,\n prefix: KeyType[] = [],\n): Iterable<[patch: Patch, reversePatch: Patch]> {\n if (a === b) {\n return;\n }\n\n if (\n (typeof options.stopAt === 'number' && prefix.length >= options.stopAt) ||\n (typeof options.stopAt === 'function' && options.stopAt(prefix))\n ) {\n if (deepEqual(a, b)) {\n return;\n }\n\n return yield [\n { op: 'replace', path: prefix, value: b },\n { op: 'replace', path: prefix, value: a },\n ];\n }\n\n if (a instanceof Date && b instanceof Date) {\n if (a.getTime() === b.getTime()) {\n return;\n }\n\n return yield [\n { op: 'replace', path: prefix, value: b },\n { op: 'replace', path: prefix, value: a },\n ];\n }\n\n if (a instanceof Map && b instanceof Map) {\n return yield* mapDiff(a, b, options, prefix);\n }\n\n if (a instanceof Set && b instanceof Set) {\n if (deepEqual(a, b)) {\n return;\n }\n\n return yield [\n { op: 'replace', path: prefix, value: b },\n { op: 'replace', path: prefix, value: a },\n ];\n }\n\n if (!options.diffArrays && Array.isArray(a) && Array.isArray(b)) {\n if (deepEqual(a, b)) {\n return;\n }\n\n return yield [\n { op: 'replace', path: prefix, value: b },\n { op: 'replace', path: prefix, value: a },\n ];\n }\n\n if (\n isObject(a) &&\n isObject(b) &&\n (options.diffArrays || (!Array.isArray(a) && !Array.isArray(b)))\n ) {\n return yield* objectDiff(a, b, options, prefix);\n }\n\n yield [\n { op: 'replace', path: prefix, value: b },\n { op: 'replace', path: prefix, value: a },\n ];\n}\n\nfunction* mapDiff(\n a: Map<any, any>,\n b: Map<any, any>,\n options: { stopAt?: number | ((path: KeyType[]) => boolean) },\n prefix: KeyType[],\n): Iterable<[patch: Patch, reversePatch: Patch]> {\n for (const [key, value] of a) {\n if (!b.has(key)) {\n yield [\n { op: 'remove', path: [...prefix, key] },\n { op: 'add', path: [...prefix, key], value },\n ];\n } else {\n yield* _diff(value, b.get(key), options, [...prefix, key]);\n }\n }\n\n for (const [key, value] of b) {\n if (!a.has(key)) {\n yield [\n { op: 'add', path: [...prefix, key], value },\n { op: 'remove', path: [...prefix, key] },\n ];\n }\n }\n}\n\nfunction* objectDiff(\n a: any,\n b: any,\n options: { stopAt?: number | ((path: KeyType[]) => boolean) },\n prefix: KeyType[],\n): Iterable<[patch: Patch, reversePatch: Patch]> {\n for (const [key, value] of Object.entries(a)) {\n if (!(key in b)) {\n yield [\n { op: 'remove', path: [...prefix, key] },\n { op: 'add', path: [...prefix, key], value },\n ];\n } else {\n yield* _diff(value, b[key], options, [...prefix, key]);\n }\n }\n\n for (const [key, value] of Object.entries(b)) {\n if (!(key in a)) {\n yield [\n { op: 'add', path: [...prefix, key], value },\n { op: 'remove', path: [...prefix, key] },\n ];\n }\n }\n}\n","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":";;;AAcA,SAAgB,KACd,GACA,GACA,UAAuB,EAAE,EACoB;CAC7C,MAAM,SAAS,CAAC,GAAG,MAAM,GAAG,GAAG,QAAQ,CAAC;AAIxC,QAAO,CAHS,OAAO,KAAK,CAAC,WAAW,MAAM,EACvB,OAAO,KAAK,GAAG,kBAAkB,aAAa,CAErC;;AAGlC,UAAU,MACR,GACA,GACA,SACA,SAAoB,EAAE,EACyB;AAC/C,KAAI,MAAM,EACR;AAGF,KACG,OAAO,QAAQ,WAAW,YAAY,OAAO,UAAU,QAAQ,UAC/D,OAAO,QAAQ,WAAW,cAAc,QAAQ,OAAO,OAAO,EAC/D;AACA,MAAIA,6BAAU,GAAG,EAAE,CACjB;AAGF,SAAO,MAAM,CACX;GAAE,IAAI;GAAW,MAAM;GAAQ,OAAO;GAAG,EACzC;GAAE,IAAI;GAAW,MAAM;GAAQ,OAAO;GAAG,CAC1C;;AAGH,KAAI,aAAa,QAAQ,aAAa,MAAM;AAC1C,MAAI,EAAE,SAAS,KAAK,EAAE,SAAS,CAC7B;AAGF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,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
+ {"version":3,"file":"extendedJson-pbOLcymB.cjs","names":["deepEqual","isObject"],"sources":["../src/lib/diff.ts","../src/lib/extendedJson.ts"],"sourcesContent":["import { deepEqual } from './equals';\nimport type { KeyType } from './path';\nimport { isObject } from '@lib/helpers';\n\nexport type Patch =\n | { op: 'add'; path: KeyType[]; value: any }\n | { op: 'remove'; path: KeyType[] }\n | { op: 'replace'; path: KeyType[]; value: any };\n\nexport interface DiffOptions {\n stopAt?: number | ((path: KeyType[]) => boolean);\n diffArrays?: boolean;\n}\n\nexport function diff(\n a: any,\n b: any,\n options: DiffOptions = {},\n): [patches: Patch[], reversePatches: Patch[]] {\n const result = [..._diff(a, b, options)];\n const patches = result.map(([patch]) => patch);\n const reversePatches = result.map(([, reversePatch]) => reversePatch);\n\n return [patches, reversePatches];\n}\n\nfunction* _diff(\n a: any,\n b: any,\n options: DiffOptions,\n prefix: KeyType[] = [],\n): Iterable<[patch: Patch, reversePatch: Patch]> {\n if (a === b) {\n return;\n }\n\n if (\n (typeof options.stopAt === 'number' && prefix.length >= options.stopAt) ||\n (typeof options.stopAt === 'function' && options.stopAt(prefix))\n ) {\n if (deepEqual(a, b)) {\n return;\n }\n\n return yield [\n { op: 'replace', path: prefix, value: b },\n { op: 'replace', path: prefix, value: a },\n ];\n }\n\n if (a instanceof Date && b instanceof Date) {\n if (a.getTime() === b.getTime()) {\n return;\n }\n\n return yield [\n { op: 'replace', path: prefix, value: b },\n { op: 'replace', path: prefix, value: a },\n ];\n }\n\n if (a instanceof Map && b instanceof Map) {\n return yield* mapDiff(a, b, options, prefix);\n }\n\n if (a instanceof Set && b instanceof Set) {\n if (deepEqual(a, b)) {\n return;\n }\n\n return yield [\n { op: 'replace', path: prefix, value: b },\n { op: 'replace', path: prefix, value: a },\n ];\n }\n\n if (!options.diffArrays && Array.isArray(a) && Array.isArray(b)) {\n if (deepEqual(a, b)) {\n return;\n }\n\n return yield [\n { op: 'replace', path: prefix, value: b },\n { op: 'replace', path: prefix, value: a },\n ];\n }\n\n if (\n isObject(a) &&\n isObject(b) &&\n (options.diffArrays || (!Array.isArray(a) && !Array.isArray(b)))\n ) {\n return yield* objectDiff(a, b, options, prefix);\n }\n\n yield [\n { op: 'replace', path: prefix, value: b },\n { op: 'replace', path: prefix, value: a },\n ];\n}\n\nfunction* mapDiff(\n a: Map<any, any>,\n b: Map<any, any>,\n options: { stopAt?: number | ((path: KeyType[]) => boolean) },\n prefix: KeyType[],\n): Iterable<[patch: Patch, reversePatch: Patch]> {\n for (const [key, value] of a) {\n if (!b.has(key)) {\n yield [\n { op: 'remove', path: [...prefix, key] },\n { op: 'add', path: [...prefix, key], value },\n ];\n } else {\n yield* _diff(value, b.get(key), options, [...prefix, key]);\n }\n }\n\n for (const [key, value] of b) {\n if (!a.has(key)) {\n yield [\n { op: 'add', path: [...prefix, key], value },\n { op: 'remove', path: [...prefix, key] },\n ];\n }\n }\n}\n\nfunction* objectDiff(\n a: any,\n b: any,\n options: { stopAt?: number | ((path: KeyType[]) => boolean) },\n prefix: KeyType[],\n): Iterable<[patch: Patch, reversePatch: Patch]> {\n for (const [key, value] of Object.entries(a)) {\n if (!(key in b)) {\n yield [\n { op: 'remove', path: [...prefix, key] },\n { op: 'add', path: [...prefix, key], value },\n ];\n } else {\n yield* _diff(value, b[key], options, [...prefix, key]);\n }\n }\n\n for (const [key, value] of Object.entries(b)) {\n if (!(key in a)) {\n yield [\n { op: 'add', path: [...prefix, key], value },\n { op: 'remove', path: [...prefix, key] },\n ];\n }\n }\n}\n","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":";;;AAcA,SAAgB,KACd,GACA,GACA,UAAuB,CAAC,GACqB;CAC7C,MAAM,SAAS,CAAC,GAAG,MAAM,GAAG,GAAG,OAAO,CAAC;CAIvC,OAAO,CAHS,OAAO,KAAK,CAAC,WAAW,KAG1B,GAFS,OAAO,KAAK,GAAG,kBAAkB,YAE1B,CAAC;AACjC;AAEA,UAAU,MACR,GACA,GACA,SACA,SAAoB,CAAC,GAC0B;CAC/C,IAAI,MAAM,GACR;CAGF,IACG,OAAO,QAAQ,WAAW,YAAY,OAAO,UAAU,QAAQ,UAC/D,OAAO,QAAQ,WAAW,cAAc,QAAQ,OAAO,MAAM,GAC9D;EACA,IAAIA,6BAAU,GAAG,CAAC,GAChB;EAGF,OAAO,MAAM,CACX;GAAE,IAAI;GAAW,MAAM;GAAQ,OAAO;EAAE,GACxC;GAAE,IAAI;GAAW,MAAM;GAAQ,OAAO;EAAE,CAC1C;CACF;CAEA,IAAI,aAAa,QAAQ,aAAa,MAAM;EAC1C,IAAI,EAAE,QAAQ,MAAM,EAAE,QAAQ,GAC5B;EAGF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U,MAAM,SAAS,EAC3B;CAGF,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,MAAM,IAAI,cAAc;CAGjC,IAAI,OAAO,UAAU,YAAY,UAAU,MACzC,OAAO,OAAO,YAAY,OAAO,QAAQ,KAAK,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAAC;CAGzF,OAAO;AACT;AAYA,SAAgB,qBAAqB,OAAgB,GAAG,MAAqB;CAC3E,OAAO,KAAK,UAAU,eAAe,KAAK,GAAG,GAAG,IAAI;AACtD;AAEA,SAAgB,iBAAiB,OAAyB;CACxD,IAAI,OAAO,UAAU,YAAY,UAAU,MACzC,OAAO;CAGT,IAAI,WAAW,OACb,OAAO,IAAI,IACR,MAAM,MAA+B,KAAK,CAAC,GAAG,OAAO,CACpD,iBAAiB,CAAC,GAClB,iBAAiB,CAAC,CACpB,CAAC,CACH;CAGF,IAAI,WAAW,OACb,OAAO,IAAI,IAAK,MAAM,MAAoB,IAAI,gBAAgB,CAAC;CAGjE,IAAI,YAAY,OACd,OAAO,IAAI,KAAK,MAAM,MAAgB;CAGxC,IAAI,cAAc,OAChB,OAAO,OAAO,MAAM,QAAkB;CAGxC,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,MAAM,IAAI,gBAAgB;CAGnC,OAAO,OAAO,YAAY,OAAO,QAAQ,KAAK,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,GAAG,iBAAiB,CAAC,CAAC,CAAC,CAAC;AAC3F;AAEA,SAAgB,uBACd,OACA,SACS;CACT,OAAO,iBAAiB,KAAK,MAAM,OAAO,OAAO,CAAC;AACpD"}
package/dist/index.cjs CHANGED
@@ -1,9 +1,10 @@
1
- const require_store = require('./store-CPqOf4y5.cjs');
2
- const require_propAccess = require('./propAccess-udIdjqwY.cjs');
3
- const require_scope = require('./scope-DkX72a-2.cjs');
4
- const require_patchMethods = require('./patchMethods-CZje49Dk.cjs');
5
- const require_extendedJson = require('./extendedJson-DzXMFE1P.cjs');
6
- const require_persist = require('./persist-CG1WHP6D.cjs');
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_store = require('./store-fmAYV5hy.cjs');
3
+ const require_scope = require('./scope-8MUrzqlS.cjs');
4
+ const require_propAccess = require('./propAccess-DdLF12Jq.cjs');
5
+ const require_patchMethods = require('./patchMethods-BBQDDqwe.cjs');
6
+ const require_extendedJson = require('./extendedJson-pbOLcymB.cjs');
7
+ const require_persist = require('./persist-B341lrOA.cjs');
7
8
 
8
9
  //#region src/core/pagedCache.ts
9
10
  var PagedCache = class PagedCache extends require_scope.Cache {
@@ -66,10 +67,10 @@ async function loadPage(cache, helpers, oldPages) {
66
67
  };
67
68
  }
68
69
  function createPaged(definition, options) {
69
- return require_scope.internalCreate((args, options$1) => {
70
+ return require_scope.internalCreate((args, options) => {
70
71
  let currentDefinition = definition;
71
72
  if (currentDefinition instanceof Function) currentDefinition = currentDefinition(...args);
72
- return new PagedCache(currentDefinition, args, options$1);
73
+ return new PagedCache(currentDefinition, args, options);
73
74
  }, options);
74
75
  }
75
76
  const createPagedCache = /* @__PURE__ */ Object.assign(createPaged, { defaultOptions: require_scope.defaultCacheOptions });
@@ -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":";;;;;;;;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,CAAC,KAAK,CAAC;CAChE,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"}
1
+ {"version":3,"file":"index.cjs","names":["Cache","internalCreate","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,AAAgB,YAChB,MACA,UAAkD,CAAC,GACnD;EACA,MAAM,OAAO,YAAY,SAAS,MAAM,SAAS,CAAC,CAAC,GAAG,MAAM,SAAS,MAAS;EAJ9D;EAKhB,uBAAS,UAAU;CACrB;CAEA,MAAM,cAAc,EAAE,iBAAuC,CAAC,GAAkB;EAC9E,MAAM,EAAE,QAAQ,SAAS,YAAY,UAAU,KAAK,MAAM,IAAI;EAE9D,IAAI,WAAW,SAAS;GACtB,IAAI,CAAC,cAAc;GACnB,MAAM,IAAI,MAAM,sDAAsD;EACxE;EAEA,IAAI,YAAY;GACd,IAAI,CAAC,cAAc;GACnB,MAAM,IAAI,MAAM,4DAA4D;EAC9E;EAEA,IAAI,WAAW,aAAa,SAAS;GACnC,MAAM,KAAK,IAAI,EAAE,YAAY,CAAC,CAAC;GAC/B;EACF;EAEA,IAAI,CAAC,MAAM,SAAS;GAClB,IAAI,CAAC,cAAc;GACnB,MAAM,IAAI,MAAM,wBAAwB;EAC1C;EAEA,KAAK,eAAe,KAAK,iBAAiB;EAE1C,MAAM,KAAK,IAAI,gBAAgB;EAC/B,MAAM,UAAU,SACd,MACA;GACE,MAAM;IACJ,MAAM,IAAI,MAAM,iBAAiB;GACnC;GACA,UAAU;IACR,MAAM,IAAI,MAAM,iBAAiB;GACnC;GACA,QAAQ,GAAG;EACb,GACA,MAAM,KACR;EAEA,KAAK,YAAY,OAAO;EAExB,IAAI;GACF,MAAM;EACR,SAAS,OAAO;GACd,IAAI,CAAC,cAAc;GACnB,MAAM;EACR;CACF;AACF;AAEA,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;CACnE,CAAC;CAED,MAAM,QAAQ,SAAS,OAAO,WAAW,SAAS,OAAO,CAAC,IAAI,CAAC;CAC/D,MAAM,YAAY,cAAc,KAAK,OAAO,KAAK,KAAK;CAOtD,OAAO;EAAE;EAAO,SANA,eACZ,aAAa,KAAK,OAAO,KAAK,IAC9B,cAAc,OACZ,MAAM,SAAS,YACf,SAAS;EAEU;CAAU;AACrC;AAYA,SAAS,YACP,YACA,SACkE;CAClE,OAAOC,8BAA+D,MAAM,YAAY;EACtF,IAAI,oBAAoB;EACxB,IAAI,6BAA6B,UAC/B,oBAAoB,kBAAkB,GAAG,IAAI;EAE/C,OAAO,IAAI,WAAW,mBAAmB,MAAM,OAAO;CACxD,GAAG,OAAO;AACZ;AAEA,MAAa,mBACK,uBAAO,OAAO,aAAa,EACzC,gBAAgBC,kCAClB,CAAC;;;;AC1KH,SAAgB,cACd,OACA,WACA,cACG;CACH,MAAM,QAAQ,MAAM,UAAU,SAAS;CAEvC,IAAI,SAAS,GACX,OAAO,MAAM;CAGf,MAAM,QAAQ,wBAAwB,WAAW,aAAa,IAAI;CAClE,MAAM,KAAK,KAAK;CAChB,OAAO;AACT"}
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
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-8uUaV6I8.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-21GsOOLS.cjs";
3
- import { n as Patch, r as diff } from "./diff-Bcr0h7-x.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-CkZ7CzW8.cjs";
1
+ import { A as AsyncUpdateFunction, B as Selector, C as Value, F as ConnectionActions, G as Use, H as Update, I as DisposableCancel, L as Duration, M as CalculationActions, N as Cancel, O as Constrain, P as Connection, R as Effect, S as SettableValue, U as UpdateFrom, V as SubscribeOptions, W as UpdateFunction, _ as PathAsArray, a as StoreOptions, b as SettablePathAsArray, c as arrayMethods, d as setMethods, g as Path, i as StoreMethods, j as BaseConnectionActions, k as AsyncConnectionActions, l as mapMethods, o as StoreOptionsWithMethods, r as Store, s as createStore, t as BoundStoreMethods, u as recordMethods, v as PathAsString, x as SettablePathAsString, y as SettablePath, z as Listener } from "./store-dThvqc0k.cjs";
2
+ import { _ as createResourceGroup, a as CacheFunction, c as CreateCacheResult, d as ErrorState, f as PendingState, g as allResources, h as ResourceGroup, i as CacheBundle, l as createCache, m as Resource, n as createScope, o as CacheGetOptions, p as ValueState, r as Cache, s as CacheOptions, t as Scope, u as CacheState } from "./scope-BQjncWGt.cjs";
3
+ import { n as Patch, r as diff } from "./diff-BzE2cDaU.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-CoSWtRt0.cjs";
5
5
 
6
6
  //#region src/core/pagedCache.d.ts
7
7
  interface PageCacheFunctionProps<T> extends CalculationActions<Promise<PagedCacheState<T>>> {
@@ -113,10 +113,10 @@ declare class InstanceCache<Args extends any[], T extends object> {
113
113
  //#endregion
114
114
  //#region src/lib/propAccess.d.ts
115
115
  declare function get<T, const P>(object: T, path: Constrain<P, Path<T>>): Value<T, P>;
116
- declare function set<T, const P>(object: T, path: Constrain<P, SettablePath<T>>, value: SettableValue<T, P>, rootPath?: string | readonly KeyType[]): T;
116
+ declare function set<T, const P>(object: T, path: Constrain<P, SettablePath<T>>, value: SettableValue<T, P>): T;
117
117
  //#endregion
118
118
  //#region src/lib/updateHelpers.d.ts
119
119
  declare function findOrDefault<T>(array: T[], predicate: (item: T) => boolean, defaultValue: T | (() => T)): T;
120
120
  //#endregion
121
- export { AsyncConnectionActions, AsyncUpdateFunction, BaseConnectionActions, BoundStoreMethods, Cache, CacheBundle, CacheFunction, CacheGetOptions, CacheOptions, CacheState, CalculationActions, Cancel, Connection, ConnectionActions, CreateCacheResult, DisposableCancel, Duration, Effect, ErrorState, FetchNextPageOptions, type Hashable, InstanceCache, Listener, PageCacheFunction, PageCacheFunctionProps, PagedCache, PagedCacheDefinition, PagedCacheDefinitionFunction, PagedCacheState, type Patch, type Path, type PathAsArray, type PathAsString, PendingState, Persist, PersistOptions, PersistStorage, PersistStorageBase, PersistStorageWithKeys, PersistStorageWithLength, PersistStorageWithListItems, Resource, ResourceGroup, Scope, Selector, type SettablePath, type SettablePathAsArray, type SettablePathAsString, Store, StoreMethods, StoreOptions, StoreOptionsWithMethods, SubscribeOptions, Update, UpdateFrom, UpdateFunction, Use, type Value, ValueState, allResources, applyPatches, arrayMethods, calcDuration, createCache, createPagedCache, createResourceGroup, createScope, createStore, deepEqual, diff, findOrDefault, fromExtendedJson, fromExtendedJsonString, get, hash, mapMethods, persist, recordMethods, set, setMethods, shallowEqual, simpleHash, strictEqual, toExtendedJson, toExtendedJsonString };
121
+ export { type AsyncConnectionActions, type AsyncUpdateFunction, type BaseConnectionActions, type BoundStoreMethods, Cache, type CacheBundle, type CacheFunction, type CacheGetOptions, type CacheOptions, CacheState, type CalculationActions, type Cancel, type Connection, type ConnectionActions, type CreateCacheResult, type DisposableCancel, type Duration, type Effect, ErrorState, type FetchNextPageOptions, type Hashable, InstanceCache, type Listener, type PageCacheFunction, type PageCacheFunctionProps, PagedCache, type PagedCacheDefinition, type PagedCacheDefinitionFunction, type PagedCacheState, type Patch, type Path, type PathAsArray, type PathAsString, PendingState, type Persist, type PersistOptions, type PersistStorage, type PersistStorageBase, type PersistStorageWithKeys, type PersistStorageWithLength, type PersistStorageWithListItems, type Resource, ResourceGroup, Scope, type Selector, type SettablePath, type SettablePathAsArray, type SettablePathAsString, Store, type StoreMethods, type StoreOptions, type StoreOptionsWithMethods, type SubscribeOptions, type Update, type UpdateFrom, type UpdateFunction, type Use, type Value, ValueState, allResources, applyPatches, arrayMethods, calcDuration, createCache, createPagedCache, createResourceGroup, createScope, createStore, deepEqual, diff, findOrDefault, fromExtendedJson, fromExtendedJsonString, get, hash, mapMethods, persist, recordMethods, set, setMethods, shallowEqual, simpleHash, strictEqual, toExtendedJson, toExtendedJsonString };
122
122
  //# sourceMappingURL=index.d.cts.map
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
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-qdOAlRWQ.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-Cq1PqvEo.js";
3
- import { n as Patch, r as diff } from "./diff-CwiTYAVK.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-3Nff6j1f.js";
1
+ import { A as AsyncUpdateFunction, B as Selector, C as Value, F as ConnectionActions, G as Use, H as Update, I as DisposableCancel, L as Duration, M as CalculationActions, N as Cancel, O as Constrain, P as Connection, R as Effect, S as SettableValue, U as UpdateFrom, V as SubscribeOptions, W as UpdateFunction, _ as PathAsArray, a as StoreOptions, b as SettablePathAsArray, c as arrayMethods, d as setMethods, g as Path, i as StoreMethods, j as BaseConnectionActions, k as AsyncConnectionActions, l as mapMethods, o as StoreOptionsWithMethods, r as Store, s as createStore, t as BoundStoreMethods, u as recordMethods, v as PathAsString, x as SettablePathAsString, y as SettablePath, z as Listener } from "./store-dThvqc0k.js";
2
+ import { _ as createResourceGroup, a as CacheFunction, c as CreateCacheResult, d as ErrorState, f as PendingState, g as allResources, h as ResourceGroup, i as CacheBundle, l as createCache, m as Resource, n as createScope, o as CacheGetOptions, p as ValueState, r as Cache, s as CacheOptions, t as Scope, u as CacheState } from "./scope-BztVo2P8.js";
3
+ import { n as Patch, r as diff } from "./diff-Cvc-z20n.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-XVT4fROX.js";
5
5
 
6
6
  //#region src/core/pagedCache.d.ts
7
7
  interface PageCacheFunctionProps<T> extends CalculationActions<Promise<PagedCacheState<T>>> {
@@ -113,10 +113,10 @@ declare class InstanceCache<Args extends any[], T extends object> {
113
113
  //#endregion
114
114
  //#region src/lib/propAccess.d.ts
115
115
  declare function get<T, const P>(object: T, path: Constrain<P, Path<T>>): Value<T, P>;
116
- declare function set<T, const P>(object: T, path: Constrain<P, SettablePath<T>>, value: SettableValue<T, P>, rootPath?: string | readonly KeyType[]): T;
116
+ declare function set<T, const P>(object: T, path: Constrain<P, SettablePath<T>>, value: SettableValue<T, P>): T;
117
117
  //#endregion
118
118
  //#region src/lib/updateHelpers.d.ts
119
119
  declare function findOrDefault<T>(array: T[], predicate: (item: T) => boolean, defaultValue: T | (() => T)): T;
120
120
  //#endregion
121
- export { AsyncConnectionActions, AsyncUpdateFunction, BaseConnectionActions, BoundStoreMethods, Cache, CacheBundle, CacheFunction, CacheGetOptions, CacheOptions, CacheState, CalculationActions, Cancel, Connection, ConnectionActions, CreateCacheResult, DisposableCancel, Duration, Effect, ErrorState, FetchNextPageOptions, type Hashable, InstanceCache, Listener, PageCacheFunction, PageCacheFunctionProps, PagedCache, PagedCacheDefinition, PagedCacheDefinitionFunction, PagedCacheState, type Patch, type Path, type PathAsArray, type PathAsString, PendingState, Persist, PersistOptions, PersistStorage, PersistStorageBase, PersistStorageWithKeys, PersistStorageWithLength, PersistStorageWithListItems, Resource, ResourceGroup, Scope, Selector, type SettablePath, type SettablePathAsArray, type SettablePathAsString, Store, StoreMethods, StoreOptions, StoreOptionsWithMethods, SubscribeOptions, Update, UpdateFrom, UpdateFunction, Use, type Value, ValueState, allResources, applyPatches, arrayMethods, calcDuration, createCache, createPagedCache, createResourceGroup, createScope, createStore, deepEqual, diff, findOrDefault, fromExtendedJson, fromExtendedJsonString, get, hash, mapMethods, persist, recordMethods, set, setMethods, shallowEqual, simpleHash, strictEqual, toExtendedJson, toExtendedJsonString };
121
+ export { type AsyncConnectionActions, type AsyncUpdateFunction, type BaseConnectionActions, type BoundStoreMethods, Cache, type CacheBundle, type CacheFunction, type CacheGetOptions, type CacheOptions, CacheState, type CalculationActions, type Cancel, type Connection, type ConnectionActions, type CreateCacheResult, type DisposableCancel, type Duration, type Effect, ErrorState, type FetchNextPageOptions, type Hashable, InstanceCache, type Listener, type PageCacheFunction, type PageCacheFunctionProps, PagedCache, type PagedCacheDefinition, type PagedCacheDefinitionFunction, type PagedCacheState, type Patch, type Path, type PathAsArray, type PathAsString, PendingState, type Persist, type PersistOptions, type PersistStorage, type PersistStorageBase, type PersistStorageWithKeys, type PersistStorageWithLength, type PersistStorageWithListItems, type Resource, ResourceGroup, Scope, type Selector, type SettablePath, type SettablePathAsArray, type SettablePathAsString, Store, type StoreMethods, type StoreOptions, type StoreOptionsWithMethods, type SubscribeOptions, type Update, type UpdateFrom, type UpdateFunction, type Use, type Value, ValueState, allResources, applyPatches, arrayMethods, calcDuration, createCache, createPagedCache, createResourceGroup, createScope, createStore, deepEqual, diff, findOrDefault, fromExtendedJson, fromExtendedJsonString, get, hash, mapMethods, persist, recordMethods, set, setMethods, shallowEqual, simpleHash, strictEqual, toExtendedJson, toExtendedJsonString };
122
122
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
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-D4q5zD7q.js";
2
- import { a as set, c as deepEqual, l as shallowEqual, n as get, u as strictEqual } from "./propAccess-BxCKNeOj.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-CQE3HDNI.js";
4
- import { r as applyPatches } from "./patchMethods-Cui462lc.js";
5
- import { a as diff, i as toExtendedJsonString, n as fromExtendedJsonString, r as toExtendedJson, t as fromExtendedJson } from "./extendedJson-DA3RQ_ly.js";
6
- import { t as persist } from "./persist-CNA2sYtB.js";
1
+ import { a as mapMethods, h as autobind, i as arrayMethods, n as createStore, o as recordMethods, s as setMethods, t as Store, u as calcDuration } from "./store-BmlnyYal.js";
2
+ import { a as defaultCacheOptions, c as hash, d as allResources, f as createResourceGroup, i as createCache, l as simpleHash, n as createScope, o as internalCreate, r as Cache, s as InstanceCache, t as Scope, u as ResourceGroup } from "./scope-BfaweXvz.js";
3
+ import { a as set, c as deepEqual, l as shallowEqual, n as get, u as strictEqual } from "./propAccess-CsUaG5V_.js";
4
+ import { r as applyPatches } from "./patchMethods-D3cdG80W.js";
5
+ import { a as diff, i as toExtendedJsonString, n as fromExtendedJsonString, r as toExtendedJson, t as fromExtendedJson } from "./extendedJson-BOmrkRrD.js";
6
+ import { t as persist } from "./persist-xv73m7UR.js";
7
7
 
8
8
  //#region src/core/pagedCache.ts
9
9
  var PagedCache = class PagedCache extends Cache {
@@ -66,10 +66,10 @@ async function loadPage(cache, helpers, oldPages) {
66
66
  };
67
67
  }
68
68
  function createPaged(definition, options) {
69
- return internalCreate((args, options$1) => {
69
+ return internalCreate((args, options) => {
70
70
  let currentDefinition = definition;
71
71
  if (currentDefinition instanceof Function) currentDefinition = currentDefinition(...args);
72
- return new PagedCache(currentDefinition, args, options$1);
72
+ return new PagedCache(currentDefinition, args, options);
73
73
  }, options);
74
74
  }
75
75
  const createPagedCache = /* @__PURE__ */ Object.assign(createPaged, { defaultOptions: defaultCacheOptions });
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":";;;;;;;;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,CAAC,KAAK,CAAC;CAChE,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"}
1
+ {"version":3,"file":"index.js","names":[],"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,AAAgB,YAChB,MACA,UAAkD,CAAC,GACnD;EACA,MAAM,OAAO,YAAY,SAAS,MAAM,SAAS,CAAC,CAAC,GAAG,MAAM,SAAS,MAAS;EAJ9D;EAKhB,SAAS,UAAU;CACrB;CAEA,MAAM,cAAc,EAAE,iBAAuC,CAAC,GAAkB;EAC9E,MAAM,EAAE,QAAQ,SAAS,YAAY,UAAU,KAAK,MAAM,IAAI;EAE9D,IAAI,WAAW,SAAS;GACtB,IAAI,CAAC,cAAc;GACnB,MAAM,IAAI,MAAM,sDAAsD;EACxE;EAEA,IAAI,YAAY;GACd,IAAI,CAAC,cAAc;GACnB,MAAM,IAAI,MAAM,4DAA4D;EAC9E;EAEA,IAAI,WAAW,aAAa,SAAS;GACnC,MAAM,KAAK,IAAI,EAAE,YAAY,CAAC,CAAC;GAC/B;EACF;EAEA,IAAI,CAAC,MAAM,SAAS;GAClB,IAAI,CAAC,cAAc;GACnB,MAAM,IAAI,MAAM,wBAAwB;EAC1C;EAEA,KAAK,eAAe,KAAK,iBAAiB;EAE1C,MAAM,KAAK,IAAI,gBAAgB;EAC/B,MAAM,UAAU,SACd,MACA;GACE,MAAM;IACJ,MAAM,IAAI,MAAM,iBAAiB;GACnC;GACA,UAAU;IACR,MAAM,IAAI,MAAM,iBAAiB;GACnC;GACA,QAAQ,GAAG;EACb,GACA,MAAM,KACR;EAEA,KAAK,YAAY,OAAO;EAExB,IAAI;GACF,MAAM;EACR,SAAS,OAAO;GACd,IAAI,CAAC,cAAc;GACnB,MAAM;EACR;CACF;AACF;AAEA,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;CACnE,CAAC;CAED,MAAM,QAAQ,SAAS,OAAO,WAAW,SAAS,OAAO,CAAC,IAAI,CAAC;CAC/D,MAAM,YAAY,cAAc,KAAK,OAAO,KAAK,KAAK;CAOtD,OAAO;EAAE;EAAO,SANA,eACZ,aAAa,KAAK,OAAO,KAAK,IAC9B,cAAc,OACZ,MAAM,SAAS,YACf,SAAS;EAEU;CAAU;AACrC;AAYA,SAAS,YACP,YACA,SACkE;CAClE,OAAO,gBAA+D,MAAM,YAAY;EACtF,IAAI,oBAAoB;EACxB,IAAI,6BAA6B,UAC/B,oBAAoB,kBAAkB,GAAG,IAAI;EAE/C,OAAO,IAAI,WAAW,mBAAmB,MAAM,OAAO;CACxD,GAAG,OAAO;AACZ;AAEA,MAAa,mBACK,uBAAO,OAAO,aAAa,EACzC,gBAAgB,oBAClB,CAAC;;;;AC1KH,SAAgB,cACd,OACA,WACA,cACG;CACH,MAAM,QAAQ,MAAM,UAAU,SAAS;CAEvC,IAAI,SAAS,GACX,OAAO,MAAM;CAGf,MAAM,QAAQ,wBAAwB,WAAW,aAAa,IAAI;CAClE,MAAM,KAAK,KAAK;CAChB,OAAO;AACT"}
@@ -1,3 +1,4 @@
1
- const require_mutativeMethods = require('../mutativeMethods-CwDMtUNs.cjs');
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_mutativeMethods = require('../mutativeMethods-AiKkraqx.cjs');
2
3
 
3
4
  exports.mutativeMethods = require_mutativeMethods.mutativeMethods;
@@ -1,2 +1,2 @@
1
- import { n as mutativeMethods, t as Mutation } from "../mutativeMethods-Do8JiJ5A.cjs";
1
+ import { n as mutativeMethods, t as Mutation } from "../mutativeMethods-BHPlSHBi.cjs";
2
2
  export { type Mutation, mutativeMethods };
@@ -1,2 +1,2 @@
1
- import { n as mutativeMethods, t as Mutation } from "../mutativeMethods-t67Kp1uA.js";
1
+ import { n as mutativeMethods, t as Mutation } from "../mutativeMethods-COQxFB3B.js";
2
2
  export { type Mutation, mutativeMethods };
@@ -1,3 +1,3 @@
1
- import { t as mutativeMethods } from "../mutativeMethods-BrDU8SwY.js";
1
+ import { t as mutativeMethods } from "../mutativeMethods-qVJ36MY5.js";
2
2
 
3
3
  export { mutativeMethods };
@@ -1,5 +1,5 @@
1
- const require_store = require('../store-CPqOf4y5.cjs');
2
- const require_mutativeMethods = require('../mutativeMethods-CwDMtUNs.cjs');
1
+ const require_store = require('../store-fmAYV5hy.cjs');
2
+ const require_mutativeMethods = require('../mutativeMethods-AiKkraqx.cjs');
3
3
 
4
4
  //#region src/mutative/register.ts
5
5
  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":";;;;AAWA,OAAO,OAAOA,oBAAM,WAAWC,wCAAgB;AAC/CC,uBAASF,oBAAM"}
1
+ {"version":3,"file":"register.cjs","names":["Store","mutativeMethods","autobind"],"sources":["../../src/mutative/register.ts"],"sourcesContent":["import { mutativeMethods } from './mutativeMethods';\nimport { Store } from '@core';\nimport { autobind } from '@lib/autobind';\n\ntype MutativeMethods = typeof mutativeMethods;\n\ndeclare module '@core' {\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,uCAAe;AAC9CC,uBAASF,mBAAK"}
@@ -1,8 +1,8 @@
1
- import { n as mutativeMethods } from "../mutativeMethods-Do8JiJ5A.cjs";
1
+ import { n as mutativeMethods } from "../mutativeMethods-BHPlSHBi.cjs";
2
2
 
3
3
  //#region src/mutative/register.d.ts
4
4
  type MutativeMethods = typeof mutativeMethods;
5
- declare module ".." {
5
+ declare module "@core" {
6
6
  interface Store<T> extends MutativeMethods {}
7
7
  }
8
8
  //# sourceMappingURL=register.d.cts.map
@@ -1,8 +1,8 @@
1
- import { n as mutativeMethods } from "../mutativeMethods-t67Kp1uA.js";
1
+ import { n as mutativeMethods } from "../mutativeMethods-COQxFB3B.js";
2
2
 
3
3
  //#region src/mutative/register.d.ts
4
4
  type MutativeMethods = typeof mutativeMethods;
5
- declare module ".." {
5
+ declare module "@core" {
6
6
  interface Store<T> extends MutativeMethods {}
7
7
  }
8
8
  //# sourceMappingURL=register.d.ts.map
@@ -1,5 +1,5 @@
1
- import { h as autobind, t as Store } from "../store-D4q5zD7q.js";
2
- import { t as mutativeMethods } from "../mutativeMethods-BrDU8SwY.js";
1
+ import { h as autobind, t as Store } from "../store-BmlnyYal.js";
2
+ import { t as mutativeMethods } from "../mutativeMethods-qVJ36MY5.js";
3
3
 
4
4
  //#region src/mutative/register.ts
5
5
  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":";;;;AAWA,OAAO,OAAO,MAAM,WAAW,gBAAgB;AAC/C,SAAS,MAAM"}
1
+ {"version":3,"file":"register.js","names":[],"sources":["../../src/mutative/register.ts"],"sourcesContent":["import { mutativeMethods } from './mutativeMethods';\nimport { Store } from '@core';\nimport { autobind } from '@lib/autobind';\n\ntype MutativeMethods = typeof mutativeMethods;\n\ndeclare module '@core' {\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,eAAe;AAC9C,SAAS,KAAK"}
@@ -27,4 +27,4 @@ Object.defineProperty(exports, 'mutativeMethods', {
27
27
  return mutativeMethods;
28
28
  }
29
29
  });
30
- //# sourceMappingURL=mutativeMethods-CwDMtUNs.cjs.map
30
+ //# sourceMappingURL=mutativeMethods-AiKkraqx.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutativeMethods-AiKkraqx.cjs","names":[],"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;CACA,IAAI,KAAK,WAAW,GAAG;EACrB,MAAM,CAAC,YAAY;EAEnB,KAAK,KAAK,UAAU;GAIlB,4BAHsB,QAAQ,UAAU;IACtC,SAAS,KAAK;GAChB,CACY;EACd,CAAC;CACH,OAAO;EACL,MAAM,CAAC,MAAM,YAAY;EAEzB,KAAK,IAAI,OAAO,UAAU;GAIxB,4BAHsB,QAAQ,UAAU;IACtC,SAAS,KAAK;GAChB,CACY;EACd,CAAC;CACH;AACF;AAEA,MAAa,kBAET,EACF,OACF"}
@@ -1,4 +1,4 @@
1
- import { B as Value, K as Constrain, N as Path, r as Store } from "./store-21GsOOLS.cjs";
1
+ import { C as Value, O as Constrain, g as Path, r as Store } from "./store-dThvqc0k.cjs";
2
2
  import { Draft } from "mutative";
3
3
 
4
4
  //#region src/mutative/mutativeMethods.d.ts
@@ -10,4 +10,4 @@ declare const mutativeMethods: {
10
10
  };
11
11
  //#endregion
12
12
  export { mutativeMethods as n, Mutation as t };
13
- //# sourceMappingURL=mutativeMethods-Do8JiJ5A.d.cts.map
13
+ //# sourceMappingURL=mutativeMethods-BHPlSHBi.d.cts.map
@@ -1,4 +1,4 @@
1
- import { B as Value, K as Constrain, N as Path, r as Store } from "./store-Cq1PqvEo.js";
1
+ import { C as Value, O as Constrain, g as Path, r as Store } from "./store-dThvqc0k.js";
2
2
  import { Draft } from "mutative";
3
3
 
4
4
  //#region src/mutative/mutativeMethods.d.ts
@@ -10,4 +10,4 @@ declare const mutativeMethods: {
10
10
  };
11
11
  //#endregion
12
12
  export { mutativeMethods as n, Mutation as t };
13
- //# sourceMappingURL=mutativeMethods-t67Kp1uA.d.ts.map
13
+ //# sourceMappingURL=mutativeMethods-COQxFB3B.d.ts.map
@@ -22,4 +22,4 @@ const mutativeMethods = { update };
22
22
 
23
23
  //#endregion
24
24
  export { mutativeMethods as t };
25
- //# sourceMappingURL=mutativeMethods-BrDU8SwY.js.map
25
+ //# sourceMappingURL=mutativeMethods-qVJ36MY5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutativeMethods-qVJ36MY5.js","names":[],"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;CACA,IAAI,KAAK,WAAW,GAAG;EACrB,MAAM,CAAC,YAAY;EAEnB,KAAK,KAAK,UAAU;GAIlB,OAHe,OAAO,QAAQ,UAAU;IACtC,SAAS,KAAK;GAChB,CACY;EACd,CAAC;CACH,OAAO;EACL,MAAM,CAAC,MAAM,YAAY;EAEzB,KAAK,IAAI,OAAO,UAAU;GAIxB,OAHe,OAAO,QAAQ,UAAU;IACtC,SAAS,KAAK;GAChB,CACY;EACd,CAAC;CACH;AACF;AAEA,MAAa,kBAET,EACF,OACF"}
@@ -1,5 +1,5 @@
1
- import { g as Cancel, r as Store, w as SubscribeOptions, y as DisposableCancel } from "./store-Cq1PqvEo.js";
2
- import { n as Patch, t as DiffOptions } from "./diff-CwiTYAVK.js";
1
+ import { I as DisposableCancel, N as Cancel, V as SubscribeOptions, r as Store } from "./store-dThvqc0k.js";
2
+ import { n as Patch, t as DiffOptions } from "./diff-Cvc-z20n.js";
3
3
 
4
4
  //#region src/patches/patchMethods.d.ts
5
5
  interface SyncMessage {
@@ -10,7 +10,7 @@ interface SyncMessage {
10
10
  interface HistoryEntry extends SyncMessage {
11
11
  reversePatches: Patch[];
12
12
  }
13
- declare module ".." {
13
+ declare module "@core" {
14
14
  interface Store<T> {
15
15
  __patches?: {
16
16
  value: T;
@@ -45,4 +45,4 @@ declare const patchMethods: {
45
45
  };
46
46
  //#endregion
47
47
  export { SyncMessage as n, patchMethods as r, SubscribePatchOptions as t };
48
- //# sourceMappingURL=patchMethods-C21iQqML.d.ts.map
48
+ //# sourceMappingURL=patchMethods--ekCkYUF.d.ts.map