memorio 5.1.2 → 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
@@ -470,8 +470,6 @@ var CONTEXTS_KEY, _contexts;
470
470
  var init_platform = __esm({
471
471
  "core/platform.ts"() {
472
472
  init_esm_shims();
473
- init_internal();
474
- init_encryption();
475
473
  __name(getSessionStorage, "getSessionStorage");
476
474
  __name(getLocalStorage, "getLocalStorage");
477
475
  __name(hasIndexedDB, "hasIndexedDB");
@@ -1674,12 +1672,8 @@ function encodeHLC(hlcValue) {
1674
1672
  }
1675
1673
  __name(encodeHLC, "encodeHLC");
1676
1674
 
1677
- // core/mutation/patch.ts
1678
- init_esm_shims();
1679
-
1680
1675
  // core/mutation/transaction.ts
1681
1676
  init_esm_shims();
1682
- init_internal();
1683
1677
  var TX_REGISTRY_KEY = "__memorio_transaction_registry__";
1684
1678
  var registry = globalThis[TX_REGISTRY_KEY] || /* @__PURE__ */ new Map();
1685
1679
  if (!globalThis[TX_REGISTRY_KEY]) {
@@ -2034,19 +2028,39 @@ if (globalThis[STATE_INSTANCE_KEY]) {
2034
2028
  const initial = store.get(key);
2035
2029
  if (initial !== void 0 && initial !== null) {
2036
2030
  let acc = state2;
2031
+ let seedOk = true;
2037
2032
  for (let i = 0; i < segments.length - 1; i++) {
2038
2033
  const seg = segments[i];
2039
- if (acc[seg] === void 0 || acc[seg] === null) acc[seg] = {};
2040
- 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);
2041
2052
  }
2042
- if (acc) acc[segments[segments.length - 1]] = deepRaw(initial);
2043
2053
  }
2044
2054
  const handler = /* @__PURE__ */ __name(() => {
2045
2055
  let current = state2;
2046
2056
  for (const seg of segments) {
2047
2057
  current = current === void 0 || current === null ? void 0 : current[seg];
2048
2058
  }
2049
- store.set(key, deepRaw(current));
2059
+ if (current === void 0) {
2060
+ store.remove(key);
2061
+ } else {
2062
+ store.set(key, deepRaw(current));
2063
+ }
2050
2064
  }, "handler");
2051
2065
  const off = dispatch.listen(normalized, handler);
2052
2066
  return typeof off === "function" ? off : () => {
@@ -3036,19 +3050,22 @@ var memory = {
3036
3050
  async patch(key, patches) {
3037
3051
  const entry = await this._getEntry(key);
3038
3052
  if (!entry) return;
3053
+ const patchedValue = JSON.parse(JSON.stringify(entry.value ?? {}));
3039
3054
  let patched = false;
3040
3055
  for (const p of patches) {
3056
+ const relativePath = p.path.replace(/^[^.]+\./, "");
3041
3057
  if (p.op === "set") {
3042
- setNestedPath({ [entry.key]: entry.value }, p.path.replace(/^[^.]+\./, ""), p.value);
3058
+ setNestedPath(patchedValue, relativePath, p.value);
3043
3059
  patched = true;
3044
3060
  } else if (p.op === "delete") {
3045
- deleteNestedPath({ [entry.key]: entry.value }, p.path.replace(/^[^.]+\./, ""));
3061
+ deleteNestedPath(patchedValue, relativePath);
3046
3062
  patched = true;
3047
3063
  }
3048
3064
  }
3049
3065
  if (!patched) return;
3050
3066
  const updated = {
3051
3067
  ...entry,
3068
+ value: patchedValue,
3052
3069
  updatedAt: now(),
3053
3070
  lastConfirmedAt: now(),
3054
3071
  version: (entry.version ? entry.version : 0) + 1,