@mgarlik/datastore 0.1.13 → 0.1.14

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.d.cts CHANGED
@@ -10,11 +10,11 @@ type ProviderDataSourceType = {
10
10
  * CRUD adresy - read, update, delete
11
11
  */
12
12
  crud?: {
13
- create?: string;
14
- read?: string;
15
- update?: string;
13
+ create?: string | { [key: string]: string };
14
+ read?: string | { [key: string]: string };
15
+ update?: string | { [key: string]: string };
16
16
  delete?: string;
17
- updates?: { [key: string]: string };
17
+ // updates?: { [key: string]: string };
18
18
  };
19
19
  /**
20
20
  * Prime zadani pole dat
@@ -474,7 +474,10 @@ interface UseProviderActionsResult {
474
474
  data?: JSONType;
475
475
  }, callback?: () => void) => void;
476
476
  /** Vytvoří novou položku providera. */
477
- createItem: (data: JSONType, callback?: (value: JSONType) => void) => Promise<JSONType>;
477
+ createItem: (args: {
478
+ data: JSONType;
479
+ variant?: string;
480
+ }, callback?: (value: JSONType) => void) => Promise<JSONType>;
478
481
  }
479
482
  /**
480
483
  * Vrací action helpery pro známé provider id.
package/dist/index.d.ts CHANGED
@@ -10,11 +10,11 @@ type ProviderDataSourceType = {
10
10
  * CRUD adresy - read, update, delete
11
11
  */
12
12
  crud?: {
13
- create?: string;
14
- read?: string;
15
- update?: string;
13
+ create?: string | { [key: string]: string };
14
+ read?: string | { [key: string]: string };
15
+ update?: string | { [key: string]: string };
16
16
  delete?: string;
17
- updates?: { [key: string]: string };
17
+ // updates?: { [key: string]: string };
18
18
  };
19
19
  /**
20
20
  * Prime zadani pole dat
@@ -474,7 +474,10 @@ interface UseProviderActionsResult {
474
474
  data?: JSONType;
475
475
  }, callback?: () => void) => void;
476
476
  /** Vytvoří novou položku providera. */
477
- createItem: (data: JSONType, callback?: (value: JSONType) => void) => Promise<JSONType>;
477
+ createItem: (args: {
478
+ data: JSONType;
479
+ variant?: string;
480
+ }, callback?: (value: JSONType) => void) => Promise<JSONType>;
478
481
  }
479
482
  /**
480
483
  * Vrací action helpery pro známé provider id.
package/dist/index.js CHANGED
@@ -621,14 +621,16 @@ var buildUri = ({
621
621
  }) => {
622
622
  console.log("[HANDLE DATA] BUILD URI method ", method, " from", dataSource);
623
623
  if (dataSource.crud) {
624
- if (method === "update" && dataSource.crud.updates) {
625
- if (variant && dataSource.crud.updates[variant]) return dataSource.crud.updates[variant];
626
- if (dataSource.crud[method]) return dataSource.crud[method];
627
- const firstUpdateUri = Object.values(dataSource.crud.updates)[0];
628
- if (firstUpdateUri) return firstUpdateUri;
624
+ if (typeof dataSource.crud === "string") return dataSource.crud;
625
+ if (typeof dataSource.crud[method] === "string") return dataSource.crud[method];
626
+ if (typeof dataSource.crud[method] === "object") {
627
+ if (!variant) {
628
+ if (dataSource.crud[method].default) return dataSource.crud[method].default;
629
+ } else {
630
+ if (dataSource.crud[method][variant]) return dataSource.crud[method][variant];
631
+ }
632
+ return dataSource.crud[method][0];
629
633
  }
630
- const crudUri = dataSource.crud[method];
631
- if (crudUri) return crudUri;
632
634
  }
633
635
  return dataSource.uri || `${dataSource.model || ""}/`;
634
636
  };
@@ -1619,7 +1621,7 @@ var DataStoreProvider = forwardRef(
1619
1621
  [setDocuments, setCounterDocuments, setProviders, removePersistedDocument]
1620
1622
  );
1621
1623
  const createProviderItem = useCallback(
1622
- async ({ id, data }) => {
1624
+ async ({ id, data, variant }) => {
1623
1625
  if (!providers[id]) {
1624
1626
  systemLog("dsp", "[createProviderItem] Provider neexistuje:", id);
1625
1627
  return;
@@ -1633,6 +1635,7 @@ var DataStoreProvider = forwardRef(
1633
1635
  const result = await postData({
1634
1636
  dataSource: providers[id].dataSource,
1635
1637
  schema: providers[id].schema,
1638
+ variant,
1636
1639
  val: data
1637
1640
  });
1638
1641
  return result;
@@ -2397,14 +2400,18 @@ var useProviderActions = (providerId, data) => {
2397
2400
  const deleteItem = ({ params, data: data2 }, callback) => {
2398
2401
  dispatch("deleteProviderItem", { providerId, data: data2, params }, callback);
2399
2402
  };
2400
- const createItem = (data2, callback) => {
2403
+ const createItem = ({
2404
+ data: data2,
2405
+ variant,
2406
+ callback
2407
+ }) => {
2401
2408
  systemLog("usedp", "createItem Prov. id:", providerId);
2402
2409
  return new Promise((resolve, reject) => {
2403
2410
  const wrappedCallback = (result) => {
2404
2411
  callback?.(result);
2405
2412
  resolve(result);
2406
2413
  };
2407
- dispatch("createProviderItem", { id: providerId, data: data2 }, wrappedCallback);
2414
+ dispatch("createProviderItem", { id: providerId, data: data2, variant }, wrappedCallback);
2408
2415
  });
2409
2416
  };
2410
2417
  return {