memorio 4.9.30 → 4.9.35

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/index.js CHANGED
@@ -1886,6 +1886,7 @@ var schema = {
1886
1886
  };
1887
1887
 
1888
1888
  // functions/state/index.ts
1889
+ init_store();
1889
1890
  init_env();
1890
1891
  var TARGET = /* @__PURE__ */ Symbol("memorio.target");
1891
1892
  var wrapperCache = /* @__PURE__ */ new WeakMap();
@@ -1900,6 +1901,7 @@ var deepRaw = /* @__PURE__ */ __name((val, seen = null) => {
1900
1901
  if (ctor !== "Object" && ctor !== "Array") return val;
1901
1902
  const copy = Array.isArray(val) ? [] : {};
1902
1903
  for (const k of Reflect.ownKeys(val)) {
1904
+ if (!Object.prototype.propertyIsEnumerable.call(val, k)) continue;
1903
1905
  copy[k] = deepRaw(val[k], seen);
1904
1906
  }
1905
1907
  return copy;
@@ -2122,6 +2124,39 @@ if (globalThis[STATE_INSTANCE_KEY]) {
2122
2124
  internal_default.locked = false;
2123
2125
  message_default("State is now unlocked. Modifications are allowed.");
2124
2126
  };
2127
+ state2.persist = (path2) => {
2128
+ if (typeof path2 !== "string" || !path2.length) {
2129
+ if (DEV) console.warn('[memorio state] state.persist() requires a non-empty path string (e.g. "state.user")');
2130
+ return () => {
2131
+ };
2132
+ }
2133
+ const normalized = path2.startsWith("state.") ? path2 : "state." + path2;
2134
+ const key = normalized.replace(/^state\./, "");
2135
+ const segments = key.split(".");
2136
+ const initial = store.get(key);
2137
+ if (initial !== void 0 && initial !== null) {
2138
+ let acc = state2;
2139
+ for (let i = 0; i < segments.length; i++) {
2140
+ const seg = segments[i];
2141
+ if (i === segments.length - 1) {
2142
+ acc[seg] = deepRaw(initial);
2143
+ } else {
2144
+ if (acc[seg] === void 0 || acc[seg] === null) acc[seg] = {};
2145
+ acc = acc[seg];
2146
+ }
2147
+ }
2148
+ }
2149
+ const handler = /* @__PURE__ */ __name(() => {
2150
+ let current = state2;
2151
+ for (const seg of segments) {
2152
+ current = current === void 0 || current === null ? void 0 : current[seg];
2153
+ }
2154
+ store.set(key, deepRaw(current));
2155
+ }, "handler");
2156
+ const off = dispatch.listen(normalized, handler);
2157
+ return typeof off === "function" ? off : () => {
2158
+ };
2159
+ };
2125
2160
  globalThis[STATE_INSTANCE_KEY] = state2;
2126
2161
  }
2127
2162
 
@@ -3300,7 +3335,7 @@ init_internal();
3300
3335
 
3301
3336
  // package.json
3302
3337
  var package_default = {
3303
- version: "4.9.30"};
3338
+ version: "4.9.35"};
3304
3339
 
3305
3340
  // core/global.ts
3306
3341
  init_env();
package/llms.txt CHANGED
@@ -468,7 +468,7 @@ Internal event system used by state changes; also usable directly for custom eve
468
468
 
469
469
  Listeners are stored as a *list* per event name, so multiple subscribers on the
470
470
  same name each keep firing. `dispatch.listen` returns an unsubscribe function
471
- for that specific subscriber — call it to remove only that one listener without
471
+ for that specific subscriber - call it to remove only that one listener without
472
472
  affecting others registered under the same name.
473
473
 
474
474
  ```javascript
package/modules/redux.cjs CHANGED
@@ -943,246 +943,6 @@ var schema = {
943
943
  get: getSchema
944
944
  };
945
945
 
946
- // functions/state/index.ts
947
- init_env();
948
- var TARGET = /* @__PURE__ */ Symbol("memorio.target");
949
- var wrapperCache = /* @__PURE__ */ new WeakMap();
950
- var deepRaw = /* @__PURE__ */ __name((val, seen = null) => {
951
- if (val === null || typeof val !== "object") return val;
952
- if (val[TARGET] !== void 0) return deepRaw(val[TARGET], seen);
953
- if (seen) {
954
- if (seen.has(val)) return val;
955
- seen.add(val);
956
- }
957
- const ctor = val.constructor?.name;
958
- if (ctor !== "Object" && ctor !== "Array") return val;
959
- const copy = Array.isArray(val) ? [] : {};
960
- for (const k of Reflect.ownKeys(val)) {
961
- copy[k] = deepRaw(val[k], seen);
962
- }
963
- return copy;
964
- }, "deepRaw");
965
- var objPath = /* @__PURE__ */ __name((prop, object, separator = ".") => {
966
- return object.concat(prop).join(separator);
967
- }, "objPath");
968
- var buildProxy = /* @__PURE__ */ __name((obj, callback, tree = []) => {
969
- const event = /* @__PURE__ */ __name((name) => {
970
- try {
971
- dispatch.set(name, { detail: { name } });
972
- } catch (err) {
973
- if (DEV) console.warn("[memorio state] event dispatch failed:", err);
974
- }
975
- return;
976
- }, "event");
977
- return new Proxy(
978
- obj,
979
- {
980
- get(target, prop) {
981
- if (prop === "__path") {
982
- return tree.length > 0 ? "state." + tree.join(".") : "state";
983
- }
984
- if (prop === TARGET) {
985
- return target;
986
- }
987
- if (target[TARGET] !== void 0) {
988
- return target;
989
- }
990
- if (prop === "list") {
991
- message_default('Some state could be hidden when you use "state.list". Use "state" to see the complete list ');
992
- return deepRaw(target, /* @__PURE__ */ new WeakSet());
993
- }
994
- if (typeof prop === "string") {
995
- const path = tree.length > 0 ? "state." + tree.concat(prop).join(".") : "state." + prop;
996
- internal_default.lastAccessedPath = path;
997
- if (internal_default.tracking) {
998
- internal_default.trackedPaths.add(path);
999
- }
1000
- }
1001
- if (prop === "_lastPath") {
1002
- return internal_default.lastAccessedPath;
1003
- }
1004
- if (prop === "remove") {
1005
- return (key) => {
1006
- delete target[key];
1007
- return true;
1008
- };
1009
- }
1010
- if (prop === "removeAll") {
1011
- return () => {
1012
- try {
1013
- for (const key in target) {
1014
- if (typeof target[key] !== "function" && !["list", "remove", "removeAll", "lock", "unlock"].includes(key)) {
1015
- delete target[key];
1016
- }
1017
- }
1018
- } catch (error) {
1019
- console.error(error);
1020
- }
1021
- return;
1022
- };
1023
- }
1024
- if (Object.isFrozen(target[prop])) return target[prop];
1025
- if (prop === "lock" || prop === "unlock") {
1026
- const value = Reflect.get(target, prop);
1027
- if (value) return value;
1028
- }
1029
- try {
1030
- const value = Reflect.get(target, prop);
1031
- if (value && typeof value === "object" && ["Array", "Object"].includes(value.constructor.name)) {
1032
- let wrapper = wrapperCache.get(value);
1033
- if (!wrapper) {
1034
- wrapper = buildProxy(value, callback, tree.concat(prop));
1035
- wrapperCache.set(value, wrapper);
1036
- }
1037
- return wrapper;
1038
- }
1039
- return value;
1040
- } catch (error) {
1041
- console.error("Error: ", error);
1042
- return void 0;
1043
- }
1044
- },
1045
- set(target, key, value) {
1046
- if (internal_default.locked) {
1047
- console.error("Error: state is locked. Use state.unlock() to enable modifications.");
1048
- return false;
1049
- }
1050
- if (protect.includes(key)) {
1051
- console.error("key " + key + " is protected");
1052
- return false;
1053
- }
1054
- if (target[key] && typeof target[key] === "object" && Object.isFrozen(target[key])) {
1055
- console.error(`Error: state '${key}' is locked`);
1056
- return false;
1057
- }
1058
- if (target[key] && typeof target[key] === "object" && target[key].__locked) {
1059
- console.error(`Error: state '${key}' is locked. Use state.${key}.unlock() to enable modifications.`);
1060
- return false;
1061
- }
1062
- try {
1063
- const path = objPath(key, tree);
1064
- const rawValue = deepRaw(value);
1065
- const _schemaResult = schema.validate(path, rawValue);
1066
- if (!_schemaResult.valid) {
1067
- if (DEV && internal_default.debug) {
1068
- console.error(
1069
- `[memorio schema] Validation failed for '${path}':`,
1070
- _schemaResult.errors
1071
- );
1072
- }
1073
- message_default(
1074
- `[memorio schema] Validation failed for '${path}': ` + (_schemaResult.errors?.join(", ") || "unknown error")
1075
- );
1076
- return false;
1077
- }
1078
- callback(
1079
- {
1080
- action: "set",
1081
- path,
1082
- target,
1083
- newValue: rawValue,
1084
- previousValue: Reflect.get(target, key)
1085
- }
1086
- );
1087
- event("state." + path);
1088
- Reflect.set(target, key, rawValue);
1089
- internal_default.bumpStateVersion();
1090
- if (target[key] && typeof target[key] === "object") {
1091
- const lockValue = target[key];
1092
- if (lockValue && typeof lockValue === "object") {
1093
- try {
1094
- Object.defineProperty(lockValue, "__locked", {
1095
- writable: true,
1096
- enumerable: false,
1097
- configurable: false,
1098
- value: false
1099
- });
1100
- Object.defineProperty(lockValue, "lock", {
1101
- writable: false,
1102
- enumerable: false,
1103
- configurable: false,
1104
- value: /* @__PURE__ */ __name(() => {
1105
- Object.defineProperty(lockValue, "__locked", {
1106
- writable: true,
1107
- enumerable: false,
1108
- configurable: false,
1109
- value: true
1110
- });
1111
- message_default(`State '${key}' is now locked.`);
1112
- }, "value")
1113
- });
1114
- Object.defineProperty(lockValue, "unlock", {
1115
- writable: false,
1116
- enumerable: false,
1117
- configurable: false,
1118
- value: /* @__PURE__ */ __name(() => {
1119
- Object.defineProperty(lockValue, "__locked", {
1120
- writable: true,
1121
- enumerable: false,
1122
- configurable: false,
1123
- value: false
1124
- });
1125
- message_default(`State '${key}' is now unlocked.`);
1126
- }, "value")
1127
- });
1128
- } catch (err) {
1129
- if (DEV) console.warn("[memorio state] lock/unlock defineProperty failed:", err);
1130
- }
1131
- }
1132
- }
1133
- return true;
1134
- } catch (error) {
1135
- console.error("Error in set trap:", error);
1136
- return false;
1137
- }
1138
- },
1139
- deleteProperty(target, prop) {
1140
- try {
1141
- const path = objPath(prop, tree);
1142
- const previousValue = Reflect.get(target, prop);
1143
- callback({ action: "delete", path, target, previousValue });
1144
- return Reflect.deleteProperty(target, prop);
1145
- } catch (error) {
1146
- console.error("Error in deleteProperty trap:", error);
1147
- return false;
1148
- }
1149
- },
1150
- ownKeys(target) {
1151
- return Reflect.ownKeys(target);
1152
- },
1153
- getOwnPropertyDescriptor(target, prop) {
1154
- return Reflect.getOwnPropertyDescriptor(target, prop);
1155
- }
1156
- }
1157
- );
1158
- }, "buildProxy");
1159
- var STATE_INSTANCE_KEY = "__memorio_state_instance__";
1160
- var state2;
1161
- if (globalThis[STATE_INSTANCE_KEY]) {
1162
- state2 = globalThis[STATE_INSTANCE_KEY];
1163
- } else {
1164
- state2 = buildProxy({}, (mutation) => {
1165
- if (internal_default.historyEnabled) {
1166
- internal_default.recordMutation({
1167
- path: mutation.path,
1168
- action: mutation.action,
1169
- newValue: mutation.newValue,
1170
- previousValue: mutation.previousValue,
1171
- timestamp: Date.now()
1172
- });
1173
- }
1174
- });
1175
- state2.lock = () => {
1176
- internal_default.locked = true;
1177
- message_default("State is now locked. All modifications are blocked.");
1178
- };
1179
- state2.unlock = () => {
1180
- internal_default.locked = false;
1181
- message_default("State is now unlocked. Modifications are allowed.");
1182
- };
1183
- globalThis[STATE_INSTANCE_KEY] = state2;
1184
- }
1185
-
1186
946
  // functions/store/index.ts
1187
947
  init_cjs_shims();
1188
948
  init_platform();
@@ -1455,6 +1215,280 @@ if (globalThis[STORE_INSTANCE_KEY]) {
1455
1215
  globalThis[STORE_INSTANCE_KEY] = store;
1456
1216
  }
1457
1217
 
1218
+ // functions/state/index.ts
1219
+ init_env();
1220
+ var TARGET = /* @__PURE__ */ Symbol("memorio.target");
1221
+ var wrapperCache = /* @__PURE__ */ new WeakMap();
1222
+ var deepRaw = /* @__PURE__ */ __name((val, seen = null) => {
1223
+ if (val === null || typeof val !== "object") return val;
1224
+ if (val[TARGET] !== void 0) return deepRaw(val[TARGET], seen);
1225
+ if (seen) {
1226
+ if (seen.has(val)) return val;
1227
+ seen.add(val);
1228
+ }
1229
+ const ctor = val.constructor?.name;
1230
+ if (ctor !== "Object" && ctor !== "Array") return val;
1231
+ const copy = Array.isArray(val) ? [] : {};
1232
+ for (const k of Reflect.ownKeys(val)) {
1233
+ if (!Object.prototype.propertyIsEnumerable.call(val, k)) continue;
1234
+ copy[k] = deepRaw(val[k], seen);
1235
+ }
1236
+ return copy;
1237
+ }, "deepRaw");
1238
+ var objPath = /* @__PURE__ */ __name((prop, object, separator = ".") => {
1239
+ return object.concat(prop).join(separator);
1240
+ }, "objPath");
1241
+ var buildProxy = /* @__PURE__ */ __name((obj, callback, tree = []) => {
1242
+ const event = /* @__PURE__ */ __name((name) => {
1243
+ try {
1244
+ dispatch.set(name, { detail: { name } });
1245
+ } catch (err) {
1246
+ if (DEV) console.warn("[memorio state] event dispatch failed:", err);
1247
+ }
1248
+ return;
1249
+ }, "event");
1250
+ return new Proxy(
1251
+ obj,
1252
+ {
1253
+ get(target, prop) {
1254
+ if (prop === "__path") {
1255
+ return tree.length > 0 ? "state." + tree.join(".") : "state";
1256
+ }
1257
+ if (prop === TARGET) {
1258
+ return target;
1259
+ }
1260
+ if (target[TARGET] !== void 0) {
1261
+ return target;
1262
+ }
1263
+ if (prop === "list") {
1264
+ message_default('Some state could be hidden when you use "state.list". Use "state" to see the complete list ');
1265
+ return deepRaw(target, /* @__PURE__ */ new WeakSet());
1266
+ }
1267
+ if (typeof prop === "string") {
1268
+ const path = tree.length > 0 ? "state." + tree.concat(prop).join(".") : "state." + prop;
1269
+ internal_default.lastAccessedPath = path;
1270
+ if (internal_default.tracking) {
1271
+ internal_default.trackedPaths.add(path);
1272
+ }
1273
+ }
1274
+ if (prop === "_lastPath") {
1275
+ return internal_default.lastAccessedPath;
1276
+ }
1277
+ if (prop === "remove") {
1278
+ return (key) => {
1279
+ delete target[key];
1280
+ return true;
1281
+ };
1282
+ }
1283
+ if (prop === "removeAll") {
1284
+ return () => {
1285
+ try {
1286
+ for (const key in target) {
1287
+ if (typeof target[key] !== "function" && !["list", "remove", "removeAll", "lock", "unlock"].includes(key)) {
1288
+ delete target[key];
1289
+ }
1290
+ }
1291
+ } catch (error) {
1292
+ console.error(error);
1293
+ }
1294
+ return;
1295
+ };
1296
+ }
1297
+ if (Object.isFrozen(target[prop])) return target[prop];
1298
+ if (prop === "lock" || prop === "unlock") {
1299
+ const value = Reflect.get(target, prop);
1300
+ if (value) return value;
1301
+ }
1302
+ try {
1303
+ const value = Reflect.get(target, prop);
1304
+ if (value && typeof value === "object" && ["Array", "Object"].includes(value.constructor.name)) {
1305
+ let wrapper = wrapperCache.get(value);
1306
+ if (!wrapper) {
1307
+ wrapper = buildProxy(value, callback, tree.concat(prop));
1308
+ wrapperCache.set(value, wrapper);
1309
+ }
1310
+ return wrapper;
1311
+ }
1312
+ return value;
1313
+ } catch (error) {
1314
+ console.error("Error: ", error);
1315
+ return void 0;
1316
+ }
1317
+ },
1318
+ set(target, key, value) {
1319
+ if (internal_default.locked) {
1320
+ console.error("Error: state is locked. Use state.unlock() to enable modifications.");
1321
+ return false;
1322
+ }
1323
+ if (protect.includes(key)) {
1324
+ console.error("key " + key + " is protected");
1325
+ return false;
1326
+ }
1327
+ if (target[key] && typeof target[key] === "object" && Object.isFrozen(target[key])) {
1328
+ console.error(`Error: state '${key}' is locked`);
1329
+ return false;
1330
+ }
1331
+ if (target[key] && typeof target[key] === "object" && target[key].__locked) {
1332
+ console.error(`Error: state '${key}' is locked. Use state.${key}.unlock() to enable modifications.`);
1333
+ return false;
1334
+ }
1335
+ try {
1336
+ const path = objPath(key, tree);
1337
+ const rawValue = deepRaw(value);
1338
+ const _schemaResult = schema.validate(path, rawValue);
1339
+ if (!_schemaResult.valid) {
1340
+ if (DEV && internal_default.debug) {
1341
+ console.error(
1342
+ `[memorio schema] Validation failed for '${path}':`,
1343
+ _schemaResult.errors
1344
+ );
1345
+ }
1346
+ message_default(
1347
+ `[memorio schema] Validation failed for '${path}': ` + (_schemaResult.errors?.join(", ") || "unknown error")
1348
+ );
1349
+ return false;
1350
+ }
1351
+ callback(
1352
+ {
1353
+ action: "set",
1354
+ path,
1355
+ target,
1356
+ newValue: rawValue,
1357
+ previousValue: Reflect.get(target, key)
1358
+ }
1359
+ );
1360
+ event("state." + path);
1361
+ Reflect.set(target, key, rawValue);
1362
+ internal_default.bumpStateVersion();
1363
+ if (target[key] && typeof target[key] === "object") {
1364
+ const lockValue = target[key];
1365
+ if (lockValue && typeof lockValue === "object") {
1366
+ try {
1367
+ Object.defineProperty(lockValue, "__locked", {
1368
+ writable: true,
1369
+ enumerable: false,
1370
+ configurable: false,
1371
+ value: false
1372
+ });
1373
+ Object.defineProperty(lockValue, "lock", {
1374
+ writable: false,
1375
+ enumerable: false,
1376
+ configurable: false,
1377
+ value: /* @__PURE__ */ __name(() => {
1378
+ Object.defineProperty(lockValue, "__locked", {
1379
+ writable: true,
1380
+ enumerable: false,
1381
+ configurable: false,
1382
+ value: true
1383
+ });
1384
+ message_default(`State '${key}' is now locked.`);
1385
+ }, "value")
1386
+ });
1387
+ Object.defineProperty(lockValue, "unlock", {
1388
+ writable: false,
1389
+ enumerable: false,
1390
+ configurable: false,
1391
+ value: /* @__PURE__ */ __name(() => {
1392
+ Object.defineProperty(lockValue, "__locked", {
1393
+ writable: true,
1394
+ enumerable: false,
1395
+ configurable: false,
1396
+ value: false
1397
+ });
1398
+ message_default(`State '${key}' is now unlocked.`);
1399
+ }, "value")
1400
+ });
1401
+ } catch (err) {
1402
+ if (DEV) console.warn("[memorio state] lock/unlock defineProperty failed:", err);
1403
+ }
1404
+ }
1405
+ }
1406
+ return true;
1407
+ } catch (error) {
1408
+ console.error("Error in set trap:", error);
1409
+ return false;
1410
+ }
1411
+ },
1412
+ deleteProperty(target, prop) {
1413
+ try {
1414
+ const path = objPath(prop, tree);
1415
+ const previousValue = Reflect.get(target, prop);
1416
+ callback({ action: "delete", path, target, previousValue });
1417
+ return Reflect.deleteProperty(target, prop);
1418
+ } catch (error) {
1419
+ console.error("Error in deleteProperty trap:", error);
1420
+ return false;
1421
+ }
1422
+ },
1423
+ ownKeys(target) {
1424
+ return Reflect.ownKeys(target);
1425
+ },
1426
+ getOwnPropertyDescriptor(target, prop) {
1427
+ return Reflect.getOwnPropertyDescriptor(target, prop);
1428
+ }
1429
+ }
1430
+ );
1431
+ }, "buildProxy");
1432
+ var STATE_INSTANCE_KEY = "__memorio_state_instance__";
1433
+ var state2;
1434
+ if (globalThis[STATE_INSTANCE_KEY]) {
1435
+ state2 = globalThis[STATE_INSTANCE_KEY];
1436
+ } else {
1437
+ state2 = buildProxy({}, (mutation) => {
1438
+ if (internal_default.historyEnabled) {
1439
+ internal_default.recordMutation({
1440
+ path: mutation.path,
1441
+ action: mutation.action,
1442
+ newValue: mutation.newValue,
1443
+ previousValue: mutation.previousValue,
1444
+ timestamp: Date.now()
1445
+ });
1446
+ }
1447
+ });
1448
+ state2.lock = () => {
1449
+ internal_default.locked = true;
1450
+ message_default("State is now locked. All modifications are blocked.");
1451
+ };
1452
+ state2.unlock = () => {
1453
+ internal_default.locked = false;
1454
+ message_default("State is now unlocked. Modifications are allowed.");
1455
+ };
1456
+ state2.persist = (path) => {
1457
+ if (typeof path !== "string" || !path.length) {
1458
+ if (DEV) console.warn('[memorio state] state.persist() requires a non-empty path string (e.g. "state.user")');
1459
+ return () => {
1460
+ };
1461
+ }
1462
+ const normalized = path.startsWith("state.") ? path : "state." + path;
1463
+ const key = normalized.replace(/^state\./, "");
1464
+ const segments = key.split(".");
1465
+ const initial = store.get(key);
1466
+ if (initial !== void 0 && initial !== null) {
1467
+ let acc = state2;
1468
+ for (let i = 0; i < segments.length; i++) {
1469
+ const seg = segments[i];
1470
+ if (i === segments.length - 1) {
1471
+ acc[seg] = deepRaw(initial);
1472
+ } else {
1473
+ if (acc[seg] === void 0 || acc[seg] === null) acc[seg] = {};
1474
+ acc = acc[seg];
1475
+ }
1476
+ }
1477
+ }
1478
+ const handler = /* @__PURE__ */ __name(() => {
1479
+ let current = state2;
1480
+ for (const seg of segments) {
1481
+ current = current === void 0 || current === null ? void 0 : current[seg];
1482
+ }
1483
+ store.set(key, deepRaw(current));
1484
+ }, "handler");
1485
+ const off = dispatch.listen(normalized, handler);
1486
+ return typeof off === "function" ? off : () => {
1487
+ };
1488
+ };
1489
+ globalThis[STATE_INSTANCE_KEY] = state2;
1490
+ }
1491
+
1458
1492
  // functions/session/index.ts
1459
1493
  init_cjs_shims();
1460
1494
  init_platform();