@mgarlik/datastore 0.1.15 → 0.1.17
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 +10 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +10 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -635,8 +635,8 @@ var buildUri = ({
|
|
|
635
635
|
return dataSource.uri || `${dataSource.model || ""}/`;
|
|
636
636
|
};
|
|
637
637
|
var getData = async ({ id, dataSource, isPersisting, schema, SQLite, changeTime }) => {
|
|
638
|
-
if (dataSource)
|
|
639
|
-
else
|
|
638
|
+
if (dataSource) console.error("[axios] GET Data Source: ", buildUri({ dataSource, method: "read" }));
|
|
639
|
+
else console.error("axios No DataSource for ", id);
|
|
640
640
|
let persistedData = [];
|
|
641
641
|
var params = { ...dataSource?.params };
|
|
642
642
|
if (dataSource?.filter) params.filter = dataSource.filter;
|
|
@@ -652,15 +652,15 @@ var getData = async ({ id, dataSource, isPersisting, schema, SQLite, changeTime
|
|
|
652
652
|
if (changeTime) {
|
|
653
653
|
params.changeTime = changeTime;
|
|
654
654
|
} else if (isPersisting && SQLite) {
|
|
655
|
-
console.
|
|
655
|
+
console.error("[axios] Nacitani dat z SQLite pro ", id, " s parametrem changeTimeFrom: ", params.changeTimeFrom);
|
|
656
656
|
const qDatum = await SQLite.read(`SELECT * FROM documents WHERE model = '${id}' ORDER BY lastUpdate DESC`);
|
|
657
|
-
|
|
657
|
+
console.warn("[axios] SQLite.read Posledni datum update: ", qDatum[0]?.lastUpdate);
|
|
658
658
|
if (qDatum[0]?.lastUpdate) params.changeTimeFrom = qDatum[0].lastUpdate;
|
|
659
659
|
persistedData = qDatum.map((item) => {
|
|
660
660
|
try {
|
|
661
661
|
const parsedData = typeof item.data === "string" ? JSON.parse(item.data) : item.data;
|
|
662
662
|
if (!parsedData || typeof parsedData !== "object" || Array.isArray(parsedData)) {
|
|
663
|
-
|
|
663
|
+
console.warn("[axios] SQLite.read Preskakuji neplatny dokument:", item.id);
|
|
664
664
|
return null;
|
|
665
665
|
}
|
|
666
666
|
return { id: item.id, ...parsedData };
|
|
@@ -669,10 +669,9 @@ var getData = async ({ id, dataSource, isPersisting, schema, SQLite, changeTime
|
|
|
669
669
|
return null;
|
|
670
670
|
}
|
|
671
671
|
}).filter((item) => item !== null);
|
|
672
|
-
console.timeEnd("Persisted Data");
|
|
673
672
|
}
|
|
674
673
|
if (dataSource) {
|
|
675
|
-
console.
|
|
674
|
+
console.error("[axios] Stahuji data z ", buildUri({ dataSource, method: "read" }), " s parametry ", params);
|
|
676
675
|
const axiosResponse = await axios.get(buildUri({ dataSource, method: "read" }), { params: serializeParams(params) });
|
|
677
676
|
if (schema && !dataSource.readAllFields) {
|
|
678
677
|
const mapBySchema = (element) => {
|
|
@@ -710,9 +709,8 @@ var getData = async ({ id, dataSource, isPersisting, schema, SQLite, changeTime
|
|
|
710
709
|
newData = axiosResponse.data.data;
|
|
711
710
|
}
|
|
712
711
|
const dataCount = Array.isArray(newData) ? newData.length : "single";
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
`(SERVER TIME: ${axiosResponse.data.queryTime}) Data:`,
|
|
712
|
+
console.error(
|
|
713
|
+
`[axios](SERVER TIME: ${axiosResponse.data.queryTime}) Data:`,
|
|
716
714
|
dataCount,
|
|
717
715
|
"items, Size:",
|
|
718
716
|
JSON.stringify(newData).length,
|
|
@@ -724,7 +722,6 @@ var getData = async ({ id, dataSource, isPersisting, schema, SQLite, changeTime
|
|
|
724
722
|
}
|
|
725
723
|
}
|
|
726
724
|
if (Array.isArray(newData)) {
|
|
727
|
-
console.time("Maping");
|
|
728
725
|
const map = /* @__PURE__ */ new Map();
|
|
729
726
|
persistedData.forEach((item) => map.set(item.id, item));
|
|
730
727
|
newData.forEach((item) => map.set(item.id, item));
|
|
@@ -733,16 +730,14 @@ var getData = async ({ id, dataSource, isPersisting, schema, SQLite, changeTime
|
|
|
733
730
|
"axios",
|
|
734
731
|
`getData - Polozky ${id} persisted: ${persistedData.length}, newData: ${newData.length}, vysledek: ${updatedArray.length}`
|
|
735
732
|
);
|
|
736
|
-
console.
|
|
737
|
-
console.log("================== NEW DATA");
|
|
738
|
-
console.log(newData);
|
|
733
|
+
console.error("[axios] NEW DATA: ", newData);
|
|
739
734
|
return updatedArray;
|
|
740
735
|
} else {
|
|
741
736
|
return newData || [];
|
|
742
737
|
}
|
|
743
738
|
} catch (e) {
|
|
744
739
|
const msg = e instanceof Error ? e.message : String(e);
|
|
745
|
-
console.error(`[AXIOS]
|
|
740
|
+
console.error(`[AXIOS] CHYBACA PRI NACITANI DAT Z:`, JSON.stringify(dataSource, null, 2), "\nChyba:", msg);
|
|
746
741
|
throw e;
|
|
747
742
|
}
|
|
748
743
|
};
|