@mgarlik/datastore 0.1.12 → 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.cjs CHANGED
@@ -691,14 +691,16 @@ var buildUri = ({
691
691
  }) => {
692
692
  console.log("[HANDLE DATA] BUILD URI method ", method, " from", dataSource);
693
693
  if (dataSource.crud) {
694
- if (method === "update" && dataSource.crud.updates) {
695
- if (variant && dataSource.crud.updates[variant]) return dataSource.crud.updates[variant];
696
- if (dataSource.crud[method]) return dataSource.crud[method];
697
- const firstUpdateUri = Object.values(dataSource.crud.updates)[0];
698
- if (firstUpdateUri) return firstUpdateUri;
694
+ if (typeof dataSource.crud === "string") return dataSource.crud;
695
+ if (typeof dataSource.crud[method] === "string") return dataSource.crud[method];
696
+ if (typeof dataSource.crud[method] === "object") {
697
+ if (!variant) {
698
+ if (dataSource.crud[method].default) return dataSource.crud[method].default;
699
+ } else {
700
+ if (dataSource.crud[method][variant]) return dataSource.crud[method][variant];
701
+ }
702
+ return dataSource.crud[method][0];
699
703
  }
700
- const crudUri = dataSource.crud[method];
701
- if (crudUri) return crudUri;
702
704
  }
703
705
  return dataSource.uri || `${dataSource.model || ""}/`;
704
706
  };
@@ -1689,7 +1691,7 @@ var DataStoreProvider = (0, import_react.forwardRef)(
1689
1691
  [setDocuments, setCounterDocuments, setProviders, removePersistedDocument]
1690
1692
  );
1691
1693
  const createProviderItem = (0, import_react.useCallback)(
1692
- async ({ id, data }) => {
1694
+ async ({ id, data, variant }) => {
1693
1695
  if (!providers[id]) {
1694
1696
  systemLog("dsp", "[createProviderItem] Provider neexistuje:", id);
1695
1697
  return;
@@ -1703,6 +1705,7 @@ var DataStoreProvider = (0, import_react.forwardRef)(
1703
1705
  const result = await postData({
1704
1706
  dataSource: providers[id].dataSource,
1705
1707
  schema: providers[id].schema,
1708
+ variant,
1706
1709
  val: data
1707
1710
  });
1708
1711
  return result;
@@ -2467,14 +2470,18 @@ var useProviderActions = (providerId, data) => {
2467
2470
  const deleteItem = ({ params, data: data2 }, callback) => {
2468
2471
  dispatch("deleteProviderItem", { providerId, data: data2, params }, callback);
2469
2472
  };
2470
- const createItem = (data2, callback) => {
2473
+ const createItem = ({
2474
+ data: data2,
2475
+ variant,
2476
+ callback
2477
+ }) => {
2471
2478
  systemLog("usedp", "createItem Prov. id:", providerId);
2472
2479
  return new Promise((resolve, reject) => {
2473
2480
  const wrappedCallback = (result) => {
2474
2481
  callback?.(result);
2475
2482
  resolve(result);
2476
2483
  };
2477
- dispatch("createProviderItem", { id: providerId, data: data2 }, wrappedCallback);
2484
+ dispatch("createProviderItem", { id: providerId, data: data2, variant }, wrappedCallback);
2478
2485
  });
2479
2486
  };
2480
2487
  return {