@mittwald/api-models 4.60.0 → 4.61.0

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.
@@ -5,7 +5,7 @@ import { apiServerBehaviors } from "../../server/Server/behaviors/index.js";
5
5
  import { apiCustomerBehaviors } from "../../customer/Customer/behaviors/index.js";
6
6
  import { apiIngressBehaviors } from "../../domain/Ingress/behaviors/index.js";
7
7
  import { apiAppInstallationBehaviors } from "../../app/AppInstallation/behaviors/index.js";
8
- import { updateCacheTagsBeforeRequest } from "../../react/asyncResourceInvalidation.js";
8
+ import { addUrlTagToProvideReactCache } from "../../react/asyncResourceInvalidation.js";
9
9
  class ApiSetupState {
10
10
  _client;
11
11
  setupWithClient(client) {
@@ -14,7 +14,7 @@ class ApiSetupState {
14
14
  }
15
15
  this._client = client;
16
16
  this._client.defaultRequestOptions.onBeforeRequest =
17
- updateCacheTagsBeforeRequest;
17
+ addUrlTagToProvideReactCache;
18
18
  config.behaviors.project = apiProjectBehaviors(client);
19
19
  config.behaviors.server = apiServerBehaviors(client);
20
20
  config.behaviors.customer = apiCustomerBehaviors(client);
@@ -2,7 +2,7 @@ import { reactProvisionContext } from "./reactProvisionContext.js";
2
2
  import { refresh } from "@mittwald/react-use-promise";
3
3
  import { Store } from "@mittwald/react-use-promise/store";
4
4
  const cacheTagStore = new Store();
5
- export const refreshModels = (tag) => {
5
+ export const refreshProvideReactCache = (tag) => {
6
6
  cacheTagStore.getAll(tag).forEach((ids) => {
7
7
  ids.forEach((id) => {
8
8
  refresh({
@@ -11,7 +11,7 @@ export const refreshModels = (tag) => {
11
11
  });
12
12
  });
13
13
  };
14
- export const addCacheTag = (tag) => {
14
+ export const addTagToProvideReactCache = (tag) => {
15
15
  const context = reactProvisionContext.use();
16
16
  if (context) {
17
17
  const ids = cacheTagStore.get(tag) ?? new Set();
@@ -21,9 +21,9 @@ export const addCacheTag = (tag) => {
21
21
  });
22
22
  }
23
23
  };
24
- export const updateCacheTagsBeforeRequest = (request) => {
24
+ export const addUrlTagToProvideReactCache = (request) => {
25
25
  const url = request.requestConfig.url;
26
26
  if (request.requestConfig.method === "GET" && url) {
27
- addCacheTag(url);
27
+ addTagToProvideReactCache(url);
28
28
  }
29
29
  };
@@ -1,4 +1,4 @@
1
- export { refreshModels, addCacheTag } from "./asyncResourceInvalidation.js";
1
+ export { refreshProvideReactCache, addTagToProvideReactCache, addUrlTagToProvideReactCache, } from "./asyncResourceInvalidation.js";
2
2
  export * from "./MittwaldApiModelProvider.js";
3
3
  export * from "./reactUsePromise.js";
4
4
  export { provideReact } from "./provideReact.js";
@@ -0,0 +1,21 @@
1
+ import { provideReact } from "./provideReact.js";
2
+ import { expectType } from "tsd";
3
+ const reactProvided = provideReact(async (ignoredP1, ignoredP2) => Promise.resolve("foo"));
4
+ function ignoredTestReturnTypesOfProvideReact() {
5
+ const usedValue = reactProvided.use("foo");
6
+ const asAsyncResource = reactProvided.asResource("foo");
7
+ expectType(usedValue);
8
+ expectType(asAsyncResource.use());
9
+ }
10
+ function ignoredTestParameterTypesOfProvideReact() {
11
+ reactProvided.use("foo", true);
12
+ reactProvided.asResource("foo", true);
13
+ reactProvided.use("foo");
14
+ reactProvided.asResource("foo");
15
+ // @ts-expect-error Not assignable
16
+ reactProvided.asResource(42);
17
+ // @ts-expect-error Not assignable
18
+ reactProvided.asResource("foo", 42);
19
+ // @ts-expect-error Not assignable
20
+ reactProvided.asResource("foo", true, 42);
21
+ }
@@ -1,4 +1,4 @@
1
1
  import { Commons } from "@mittwald/api-client";
2
- export declare const refreshModels: (tag: string) => void;
3
- export declare const addCacheTag: (tag: string) => void;
4
- export declare const updateCacheTagsBeforeRequest: Commons.RequestOptions["onBeforeRequest"];
2
+ export declare const refreshProvideReactCache: (tag: string) => void;
3
+ export declare const addTagToProvideReactCache: (tag: string) => void;
4
+ export declare const addUrlTagToProvideReactCache: Commons.RequestOptions["onBeforeRequest"];
@@ -1,4 +1,4 @@
1
- export { refreshModels, addCacheTag } from "./asyncResourceInvalidation.js";
1
+ export { refreshProvideReactCache, addTagToProvideReactCache, addUrlTagToProvideReactCache, } from "./asyncResourceInvalidation.js";
2
2
  export * from "./MittwaldApiModelProvider.js";
3
3
  export * from "./reactUsePromise.js";
4
4
  export { type AsyncResourceVariant } from "./provideReact.js";
@@ -3,7 +3,7 @@ import { AsyncReturnType } from "type-fest";
3
3
  type AsyncFn = (...args: any[]) => Promise<unknown>;
4
4
  export declare const provideReact: <T extends AsyncFn>(loader: T, dependencies?: string[]) => AsyncResourceVariant<T>;
5
5
  export type AsyncResourceVariant<T extends AsyncFn> = T & {
6
- asResource: (...params: Parameters<T>) => AsyncResource<ReturnType<T>>;
6
+ asResource: (...params: Parameters<T>) => AsyncResource<AsyncReturnType<T>>;
7
7
  use: (...params: Parameters<T>) => AsyncReturnType<T>;
8
8
  };
9
9
  export {};
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mittwald/api-models",
3
- "version": "4.60.0",
3
+ "version": "4.61.0",
4
4
  "author": "Mittwald CM Service GmbH & Co. KG <opensource@mittwald.de>",
5
5
  "type": "module",
6
6
  "description": "Collection of domain models for coherent interaction with the API",
@@ -44,6 +44,7 @@
44
44
  "context": "^3.0.31",
45
45
  "object-code": "^1.3.3",
46
46
  "polytype": "^0.17.0",
47
+ "tsd": "^0.31.2",
47
48
  "type-fest": "^4.23.0"
48
49
  },
49
50
  "devDependencies": {
@@ -81,5 +82,5 @@
81
82
  "optional": true
82
83
  }
83
84
  },
84
- "gitHead": "8058044c2d8ab32e0507561baa1172cbfbce4fe0"
85
+ "gitHead": "87f9b29bfab46d969b2061411b3dc7c4b7dd9699"
85
86
  }