memorio 5.1.3 → 5.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/modules/redux.js CHANGED
@@ -2028,19 +2028,39 @@ if (globalThis[STATE_INSTANCE_KEY]) {
2028
2028
  const initial = store.get(key);
2029
2029
  if (initial !== void 0 && initial !== null) {
2030
2030
  let acc = state2;
2031
+ let seedOk = true;
2031
2032
  for (let i = 0; i < segments.length - 1; i++) {
2032
2033
  const seg = segments[i];
2033
- if (acc[seg] === void 0 || acc[seg] === null) acc[seg] = {};
2034
- acc = acc[seg];
2034
+ const existing = acc[seg];
2035
+ if (existing === void 0 || existing === null) {
2036
+ acc[seg] = {};
2037
+ acc = acc[seg];
2038
+ } else if (typeof existing === "object") {
2039
+ acc = existing;
2040
+ } else {
2041
+ if (DEV) {
2042
+ console.warn(
2043
+ `[memorio state] state.persist('${normalized}') aborted seeding: '${seg}' already holds a primitive value (${typeof existing}), cannot nest '${segments.slice(i + 1).join(".")}' under it.`
2044
+ );
2045
+ }
2046
+ seedOk = false;
2047
+ break;
2048
+ }
2049
+ }
2050
+ if (seedOk && acc) {
2051
+ acc[segments[segments.length - 1]] = deepRaw(initial);
2035
2052
  }
2036
- if (acc) acc[segments[segments.length - 1]] = deepRaw(initial);
2037
2053
  }
2038
2054
  const handler = /* @__PURE__ */ __name(() => {
2039
2055
  let current = state2;
2040
2056
  for (const seg of segments) {
2041
2057
  current = current === void 0 || current === null ? void 0 : current[seg];
2042
2058
  }
2043
- store.set(key, deepRaw(current));
2059
+ if (current === void 0) {
2060
+ store.remove(key);
2061
+ } else {
2062
+ store.set(key, deepRaw(current));
2063
+ }
2044
2064
  }, "handler");
2045
2065
  const off = dispatch.listen(normalized, handler);
2046
2066
  return typeof off === "function" ? off : () => {
@@ -3030,19 +3050,22 @@ var memory = {
3030
3050
  async patch(key, patches) {
3031
3051
  const entry = await this._getEntry(key);
3032
3052
  if (!entry) return;
3053
+ const patchedValue = JSON.parse(JSON.stringify(entry.value ?? {}));
3033
3054
  let patched = false;
3034
3055
  for (const p of patches) {
3056
+ const relativePath = p.path.replace(/^[^.]+\./, "");
3035
3057
  if (p.op === "set") {
3036
- setNestedPath({ [entry.key]: entry.value }, p.path.replace(/^[^.]+\./, ""), p.value);
3058
+ setNestedPath(patchedValue, relativePath, p.value);
3037
3059
  patched = true;
3038
3060
  } else if (p.op === "delete") {
3039
- deleteNestedPath({ [entry.key]: entry.value }, p.path.replace(/^[^.]+\./, ""));
3061
+ deleteNestedPath(patchedValue, relativePath);
3040
3062
  patched = true;
3041
3063
  }
3042
3064
  }
3043
3065
  if (!patched) return;
3044
3066
  const updated = {
3045
3067
  ...entry,
3068
+ value: patchedValue,
3046
3069
  updatedAt: now(),
3047
3070
  lastConfirmedAt: now(),
3048
3071
  version: (entry.version ? entry.version : 0) + 1,