@mgarlik/datastore 0.1.5 → 0.1.8
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/dist/index.cjs +47 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +46 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -63,6 +63,7 @@ __export(index_exports, {
|
|
|
63
63
|
filterDocumentsAsync: () => filterDocumentsAsync,
|
|
64
64
|
getValueByRules: () => getValueByRules,
|
|
65
65
|
isUuid: () => isUuid,
|
|
66
|
+
logStorageContent: () => logStorageContent,
|
|
66
67
|
recalculateObjectWithDocument: () => recalculateObjectWithDocument,
|
|
67
68
|
useDataProvider: () => useDataProvider,
|
|
68
69
|
useDataStore: () => useDataStore,
|
|
@@ -824,7 +825,7 @@ var postData = async ({ dataSource, variant, schema, val }) => {
|
|
|
824
825
|
};
|
|
825
826
|
var patchData = async ({ dataSource, variant, data }) => {
|
|
826
827
|
try {
|
|
827
|
-
|
|
828
|
+
console.log("PATCH: ", buildUri({ dataSource, variant, method: "update" }), ", Data: ", JSON.stringify(data, null, 2));
|
|
828
829
|
const response = await import_axios.default.patch(buildUri({ dataSource, variant, method: "update" }), data);
|
|
829
830
|
response.data?.queryTime && systemLog("axios", "PATCH Server Query Time: ", response.data.queryTime);
|
|
830
831
|
systemLog("axios", "PATCH Response Data: ", response.data.data.length, " Bytes");
|
|
@@ -1175,7 +1176,7 @@ var DataStoreProvider = (0, import_react.forwardRef)(
|
|
|
1175
1176
|
...socketServer?.params?.auth || {},
|
|
1176
1177
|
token: getSocketAuthToken()
|
|
1177
1178
|
};
|
|
1178
|
-
|
|
1179
|
+
console.log("PRIPOJUJI LIVE SOCKETS");
|
|
1179
1180
|
socket.connect();
|
|
1180
1181
|
}, [socket, socketServer?.params?.auth, getSocketAuthToken]);
|
|
1181
1182
|
const stopSockets = (0, import_react.useCallback)(() => {
|
|
@@ -1232,6 +1233,7 @@ var DataStoreProvider = (0, import_react.forwardRef)(
|
|
|
1232
1233
|
const item = dispatcher.actions[0];
|
|
1233
1234
|
switch (item.action) {
|
|
1234
1235
|
case "registerProvider":
|
|
1236
|
+
console.log("[DSP] Dispatcher registerProvider", item.data);
|
|
1235
1237
|
await registerProvider(item.data);
|
|
1236
1238
|
break;
|
|
1237
1239
|
case "unregisterProvider":
|
|
@@ -1391,6 +1393,7 @@ var DataStoreProvider = (0, import_react.forwardRef)(
|
|
|
1391
1393
|
systemLog("dsp", "[updateDocument]:", documentId, ", model:", model);
|
|
1392
1394
|
let data = pData;
|
|
1393
1395
|
if (typeof pData === "function") data = pData(documents[documentId]);
|
|
1396
|
+
const dataWithDocumentId = data && typeof data === "object" && !Array.isArray(data) ? { ...data, id: data.id ?? documentId } : { id: documentId };
|
|
1394
1397
|
if (fields) {
|
|
1395
1398
|
systemLog("dsp", "[updateDocument] Stahovani ", model, ", document: ", documentId, ", fields: ", fields);
|
|
1396
1399
|
systemLog("dsp", "[updateDocument] Providers: ", Object.keys(providers));
|
|
@@ -1410,6 +1413,7 @@ var DataStoreProvider = (0, import_react.forwardRef)(
|
|
|
1410
1413
|
}
|
|
1411
1414
|
}
|
|
1412
1415
|
if (data) {
|
|
1416
|
+
console.log("[updateDocument]:", documentId, ", model:", model);
|
|
1413
1417
|
var listeningProviders = 0;
|
|
1414
1418
|
var isProvidersUpdated = false;
|
|
1415
1419
|
const rand = uuid();
|
|
@@ -1426,7 +1430,7 @@ var DataStoreProvider = (0, import_react.forwardRef)(
|
|
|
1426
1430
|
var socketListeners = providerNext.dataSource?.socketListeners || [];
|
|
1427
1431
|
if (socketListeners.length === 0) {
|
|
1428
1432
|
if (providerNext.data.includes(documentId)) {
|
|
1429
|
-
if (!providerNext.dataSource?.filter || filterDocuments(
|
|
1433
|
+
if (!providerNext.dataSource?.filter || filterDocuments(dataWithDocumentId, providerNext.dataSource?.filter)) {
|
|
1430
1434
|
systemLog("dsp", "[updateDocument] - zustava v Provider bez Listeners:", key);
|
|
1431
1435
|
listeningProviders++;
|
|
1432
1436
|
providerNext.lastUpdate = {
|
|
@@ -1446,7 +1450,7 @@ var DataStoreProvider = (0, import_react.forwardRef)(
|
|
|
1446
1450
|
}
|
|
1447
1451
|
} else if (socketListeners.includes(model) || // socketListeners.includes(documentId) ||
|
|
1448
1452
|
key === model) {
|
|
1449
|
-
if (!providerNext.dataSource.filter || filterDocuments(
|
|
1453
|
+
if (!providerNext.dataSource.filter || filterDocuments(dataWithDocumentId, providerNext.dataSource.filter)) {
|
|
1450
1454
|
listeningProviders++;
|
|
1451
1455
|
providerNext.lastUpdate = {
|
|
1452
1456
|
id: uuid(),
|
|
@@ -1486,12 +1490,12 @@ var DataStoreProvider = (0, import_react.forwardRef)(
|
|
|
1486
1490
|
console.timeEnd("[DSP UPDATE DOCUMENTS INSIDE]");
|
|
1487
1491
|
return {
|
|
1488
1492
|
...prev2,
|
|
1489
|
-
[documentId]: { ...prev2[documentId], ...
|
|
1493
|
+
[documentId]: { ...prev2[documentId], ...dataWithDocumentId }
|
|
1490
1494
|
};
|
|
1491
1495
|
}
|
|
1492
1496
|
} else if (listeningProviders > 0) {
|
|
1493
1497
|
console.timeEnd("[DSP UPDATE DOCUMENTS INSIDE]");
|
|
1494
|
-
return { ...prev2, [documentId]:
|
|
1498
|
+
return { ...prev2, [documentId]: dataWithDocumentId };
|
|
1495
1499
|
}
|
|
1496
1500
|
console.timeEnd("[DSP UPDATE DOCUMENTS INSIDE]");
|
|
1497
1501
|
return prev2;
|
|
@@ -1520,7 +1524,7 @@ var DataStoreProvider = (0, import_react.forwardRef)(
|
|
|
1520
1524
|
await persistDocument({
|
|
1521
1525
|
documentId,
|
|
1522
1526
|
model,
|
|
1523
|
-
data: { ...documents[documentId], ...
|
|
1527
|
+
data: { ...documents[documentId], ...dataWithDocumentId }
|
|
1524
1528
|
});
|
|
1525
1529
|
} else {
|
|
1526
1530
|
await removePersistedDocument(documentId);
|
|
@@ -1574,13 +1578,13 @@ var DataStoreProvider = (0, import_react.forwardRef)(
|
|
|
1574
1578
|
}, [dispatch, updateDocument]);
|
|
1575
1579
|
const createDocument = (0, import_react.useCallback)(
|
|
1576
1580
|
async ({ model, documentId, data }) => {
|
|
1577
|
-
const newDocument = data;
|
|
1581
|
+
const newDocument = data && typeof data === "object" && !Array.isArray(data) ? { ...data, id: data.id ?? documentId } : { id: documentId };
|
|
1578
1582
|
console.log(`Registruji model ${model}, documentId ${documentId}, data: ${JSON.stringify(data)}`);
|
|
1579
1583
|
var providerListenersCount = 0;
|
|
1580
1584
|
Object.keys(providers).forEach((key) => {
|
|
1581
1585
|
const provider = providers[key];
|
|
1582
1586
|
var socketListeners = provider.dataSource?.socketListeners;
|
|
1583
|
-
if ((socketListeners?.includes(model) || key === model) && (!provider.dataSource?.filter || filterDocuments(
|
|
1587
|
+
if ((socketListeners?.includes(model) || key === model) && (!provider.dataSource?.filter || filterDocuments(newDocument, provider.dataSource?.filter))) {
|
|
1584
1588
|
if (!provider.data.includes(documentId)) {
|
|
1585
1589
|
setCounterDocuments((prev) => {
|
|
1586
1590
|
const newC = { ...prev };
|
|
@@ -1903,6 +1907,7 @@ var DataStoreProvider = (0, import_react.forwardRef)(
|
|
|
1903
1907
|
[id]: 1
|
|
1904
1908
|
}));
|
|
1905
1909
|
if (provider.dataSource?.socketListeners) {
|
|
1910
|
+
console.log("TATATATA");
|
|
1906
1911
|
registerProviderSockets(provider.dataSource.socketListeners, provider.dataSource.filter);
|
|
1907
1912
|
}
|
|
1908
1913
|
console.timeEnd(`[DSP] VYTVARENI PROVIDERA ${id}`);
|
|
@@ -2068,6 +2073,7 @@ var useDataProvider = (id, params, dataFilter, settings) => {
|
|
|
2068
2073
|
const prov = renderJSONTemplate(id, params ?? void 0);
|
|
2069
2074
|
setProviderId(prov.id);
|
|
2070
2075
|
retId = prov.id;
|
|
2076
|
+
console.log("Registruji z useDataProvider 1", prov.id);
|
|
2071
2077
|
dispatch("registerProvider", prov);
|
|
2072
2078
|
} else {
|
|
2073
2079
|
if (presetProviders[id]) {
|
|
@@ -2078,7 +2084,9 @@ var useDataProvider = (id, params, dataFilter, settings) => {
|
|
|
2078
2084
|
systemLog("usedp", "Provider:", prov.id, "existuje");
|
|
2079
2085
|
if (!currentProviders[prov.id]?.isPermanent) updateProviderListeners(prov.id, 1);
|
|
2080
2086
|
} else {
|
|
2081
|
-
|
|
2087
|
+
console.log("Params: ", params);
|
|
2088
|
+
console.log("Registruji z useDataProvider 2 - novy provider", prov.id);
|
|
2089
|
+
console.log(JSON.stringify(prov, null, 2));
|
|
2082
2090
|
dispatch("registerProvider", prov);
|
|
2083
2091
|
}
|
|
2084
2092
|
} else {
|
|
@@ -2268,6 +2276,34 @@ var COLOR_SOCKETS = COLOR_YELLOW;
|
|
|
2268
2276
|
var COLOR_AXIOS = COLOR_YELLOW;
|
|
2269
2277
|
var COLOR_APP = COLOR_BLUE;
|
|
2270
2278
|
var COLOR_DS = COLOR_MAGENTA;
|
|
2279
|
+
|
|
2280
|
+
// src/debugStorage.ts
|
|
2281
|
+
async function logStorageContent(storage) {
|
|
2282
|
+
try {
|
|
2283
|
+
systemLog("debug", "=== STORAGE CONTENT ===");
|
|
2284
|
+
if ("getTables" in storage) {
|
|
2285
|
+
const tablesResult = await storage.getTables();
|
|
2286
|
+
console.log("\u{1F4CA} TABULKY V DATAB\xC1ZI:", tablesResult);
|
|
2287
|
+
for (const table of tablesResult) {
|
|
2288
|
+
const tableName = table.name;
|
|
2289
|
+
try {
|
|
2290
|
+
const content = await storage.read(`SELECT * FROM '${tableName}'`);
|
|
2291
|
+
console.log(`
|
|
2292
|
+
\u{1F4CB} TABULKA: ${tableName}`);
|
|
2293
|
+
console.log(` Po\u010Det \u0159\xE1dk\u016F: ${content.length}`);
|
|
2294
|
+
console.log(content);
|
|
2295
|
+
} catch (error) {
|
|
2296
|
+
console.error(` Chyba p\u0159i \u010Dten\xED tabulky ${tableName}:`, error);
|
|
2297
|
+
}
|
|
2298
|
+
}
|
|
2299
|
+
} else {
|
|
2300
|
+
console.log("Storage neimplementuje getTables()");
|
|
2301
|
+
}
|
|
2302
|
+
systemLog("debug", "=== KONEC STORAGE CONTENT ===");
|
|
2303
|
+
} catch (error) {
|
|
2304
|
+
console.error("Chyba p\u0159i loggingu storage obsahu:", error);
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2271
2307
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2272
2308
|
0 && (module.exports = {
|
|
2273
2309
|
COLOR_APP,
|
|
@@ -2303,6 +2339,7 @@ var COLOR_DS = COLOR_MAGENTA;
|
|
|
2303
2339
|
filterDocumentsAsync,
|
|
2304
2340
|
getValueByRules,
|
|
2305
2341
|
isUuid,
|
|
2342
|
+
logStorageContent,
|
|
2306
2343
|
recalculateObjectWithDocument,
|
|
2307
2344
|
useDataProvider,
|
|
2308
2345
|
useDataStore,
|