@mgarlik/datastore 0.1.14 → 0.1.16

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.js CHANGED
@@ -646,7 +646,7 @@ var getData = async ({ id, dataSource, isPersisting, schema, SQLite, changeTime
646
646
  if (dataSource?.data) {
647
647
  newData = dataSource.data;
648
648
  } else if (dataSource?.file) {
649
- const response = await fetch(`${process.env.PUBLIC_URL}/${dataSource.file}`);
649
+ const response = await fetch(`/${dataSource.file}`);
650
650
  newData = await response.json();
651
651
  } else {
652
652
  if (changeTime) {
@@ -654,13 +654,13 @@ var getData = async ({ id, dataSource, isPersisting, schema, SQLite, changeTime
654
654
  } else if (isPersisting && SQLite) {
655
655
  console.time("Persisted Data");
656
656
  const qDatum = await SQLite.read(`SELECT * FROM documents WHERE model = '${id}' ORDER BY lastUpdate DESC`);
657
- systemLog("axios", "SQLite.read Posledni datum update: ", qDatum[0]?.lastUpdate);
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
- systemLog("axios", "SQLite.read Preskakuji neplatny dokument:", item.id);
663
+ console.warn("[axios] SQLite.read Preskakuji neplatny dokument:", item.id);
664
664
  return null;
665
665
  }
666
666
  return { id: item.id, ...parsedData };
@@ -709,10 +709,10 @@ var getData = async ({ id, dataSource, isPersisting, schema, SQLite, changeTime
709
709
  } else {
710
710
  newData = axiosResponse.data.data;
711
711
  }
712
- systemLog(
713
- "axios",
714
- `(SERVER TIME: ${axiosResponse.data.queryTime}) Data:`,
715
- newData.length || "single",
712
+ const dataCount = Array.isArray(newData) ? newData.length : "single";
713
+ console.log(
714
+ `[axios](SERVER TIME: ${axiosResponse.data.queryTime}) Data:`,
715
+ dataCount,
716
716
  "items, Size:",
717
717
  JSON.stringify(newData).length,
718
718
  "Bytes"
@@ -727,11 +727,10 @@ var getData = async ({ id, dataSource, isPersisting, schema, SQLite, changeTime
727
727
  const map = /* @__PURE__ */ new Map();
728
728
  persistedData.forEach((item) => map.set(item.id, item));
729
729
  newData.forEach((item) => map.set(item.id, item));
730
- let updatedArray = [];
731
- updatedArray.push(...map.values());
730
+ const updatedArray = Array.from(map.values());
732
731
  systemLog(
733
732
  "axios",
734
- `getData - Polozky ${id} persisted: ${persistedData.length}, newData: ${newData.length}, vysledek: ${updatedArray.length}`
733
+ `getData - Polozky ${id} persisted: ${persistedData.length}, newData: ${newData.length}, vysledek: ${updatedArray.length}`
735
734
  );
736
735
  console.timeEnd("Maping");
737
736
  console.log("================== NEW DATA");
@@ -741,9 +740,10 @@ var getData = async ({ id, dataSource, isPersisting, schema, SQLite, changeTime
741
740
  return newData || [];
742
741
  }
743
742
  } catch (e) {
744
- console.error(`[AXIOS] CHYBA PRI NACITANI DAT Z: ${JSON.stringify(dataSource, null, 2)}
745
- ${e}`);
746
- return [];
743
+ const msg = e instanceof Error ? e.message : String(e);
744
+ console.warn(`[AXIOS] Warn CHYBABA PRI NACITANI DAT Z:`, JSON.stringify(dataSource, null, 2), "\nChyba:", msg);
745
+ console.error(`[AXIOS] CHYBABA PRI NACITANI DAT Z:`, JSON.stringify(dataSource, null, 2), "\nChyba:", msg);
746
+ throw e;
747
747
  }
748
748
  };
749
749
  var postData = async ({ dataSource, variant, schema, val }) => {