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