@mittwald/api-models 4.59.0 → 4.60.0-beta.1
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/esm/config/behaviors/api.js +3 -0
- package/dist/esm/project/Project/Project.js +1 -1
- package/dist/esm/react/MittwaldApiModelProvider.js +8 -8
- package/dist/esm/react/asyncResourceInvalidation.js +29 -0
- package/dist/esm/react/index.js +1 -0
- package/dist/esm/react/provideReact.js +17 -5
- package/dist/esm/react/reactProvisionContext.js +2 -0
- package/dist/types/project/Project/Project.d.ts +1 -1
- package/dist/types/react/MittwaldApiModelProvider.d.ts +6 -2
- package/dist/types/react/asyncResourceInvalidation.d.ts +4 -0
- package/dist/types/react/index.d.ts +1 -0
- package/dist/types/react/reactProvisionContext.d.ts +3 -0
- package/dist/types/react/reactUsePromise.d.ts +1 -0
- package/package.json +11 -5
- package/LICENSE +0 -21
|
@@ -5,6 +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
9
|
class ApiSetupState {
|
|
9
10
|
_client;
|
|
10
11
|
setupWithClient(client) {
|
|
@@ -12,6 +13,8 @@ class ApiSetupState {
|
|
|
12
13
|
throw new Error("API already setup. If you want to operate on the API client use api.client.");
|
|
13
14
|
}
|
|
14
15
|
this._client = client;
|
|
16
|
+
this._client.defaultRequestOptions.onBeforeRequest =
|
|
17
|
+
updateCacheTagsBeforeRequest;
|
|
15
18
|
config.behaviors.project = apiProjectBehaviors(client);
|
|
16
19
|
config.behaviors.server = apiServerBehaviors(client);
|
|
17
20
|
config.behaviors.customer = apiCustomerBehaviors(client);
|
|
@@ -34,7 +34,7 @@ export class Project extends ReferenceModel {
|
|
|
34
34
|
assertObjectFound(project, this, id);
|
|
35
35
|
return project;
|
|
36
36
|
});
|
|
37
|
-
query(query = {}) {
|
|
37
|
+
static query(query = {}) {
|
|
38
38
|
return new ProjectListQuery(query);
|
|
39
39
|
}
|
|
40
40
|
/** @deprecated: use query(), Customer.projects or Server.projects */
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { usePromise } from "@mittwald/react-use-promise";
|
|
2
2
|
import { setModule } from "./reactUsePromise.js";
|
|
3
|
-
let loadingPromise = undefined;
|
|
4
3
|
export const MittwaldApiModelProvider = (props) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
const { fallback, children } = props;
|
|
5
|
+
const module = usePromise(() => import("@mittwald/react-use-promise").then(setModule), [], {
|
|
6
|
+
useSuspense: false,
|
|
7
|
+
});
|
|
8
|
+
if (!module.hasValue) {
|
|
9
|
+
return fallback;
|
|
10
10
|
}
|
|
11
|
-
return
|
|
11
|
+
return children;
|
|
12
12
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { reactProvisionContext } from "./reactProvisionContext.js";
|
|
2
|
+
import { refresh } from "@mittwald/react-use-promise";
|
|
3
|
+
import { Store } from "@mittwald/react-use-promise/store";
|
|
4
|
+
const cacheTagStore = new Store();
|
|
5
|
+
export const refreshModels = (tag) => {
|
|
6
|
+
cacheTagStore.getAll(tag).forEach((ids) => {
|
|
7
|
+
ids.forEach((id) => {
|
|
8
|
+
refresh({
|
|
9
|
+
tag: String(id),
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
export const addCacheTag = (tag) => {
|
|
15
|
+
const context = reactProvisionContext.use();
|
|
16
|
+
if (context) {
|
|
17
|
+
const ids = cacheTagStore.get(tag) ?? new Set();
|
|
18
|
+
ids.add(context.id);
|
|
19
|
+
cacheTagStore.set(tag, () => ids, {
|
|
20
|
+
tags: [tag],
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
export const updateCacheTagsBeforeRequest = (request) => {
|
|
25
|
+
const url = request.requestConfig.url;
|
|
26
|
+
if (request.requestConfig.method === "GET" && url) {
|
|
27
|
+
addCacheTag(url);
|
|
28
|
+
}
|
|
29
|
+
};
|
package/dist/esm/react/index.js
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import { reactUsePromise } from "./reactUsePromise.js";
|
|
2
|
+
import { hash } from "object-code";
|
|
3
|
+
import { reactProvisionContext } from "./reactProvisionContext.js";
|
|
2
4
|
export const provideReact = (loader, dependencies) => {
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const provisionId = String(hash({
|
|
6
|
+
loader,
|
|
7
|
+
dependencies,
|
|
8
|
+
}));
|
|
9
|
+
const getAsyncResource = (params) => {
|
|
10
|
+
const paramsHash = params && params.length > 0 ? String(hash(params)) : "";
|
|
11
|
+
const contextId = provisionId + paramsHash;
|
|
12
|
+
const loaderWithContext = reactProvisionContext.bind({
|
|
13
|
+
id: contextId,
|
|
14
|
+
}, loader);
|
|
15
|
+
return reactUsePromise.getAsyncResource(loaderWithContext, params, {
|
|
16
|
+
loaderId: provisionId,
|
|
17
|
+
tags: [contextId],
|
|
18
|
+
});
|
|
19
|
+
};
|
|
8
20
|
return Object.assign(loader, {
|
|
9
21
|
asResource: (...params) => getAsyncResource(params),
|
|
10
22
|
use: (...params) => getAsyncResource(params).use(),
|
|
@@ -15,7 +15,7 @@ export declare class Project extends ReferenceModel {
|
|
|
15
15
|
static ofId(id: string): Project;
|
|
16
16
|
static find: AsyncResourceVariant<(id: string) => Promise<ProjectDetailed | undefined>>;
|
|
17
17
|
static get: AsyncResourceVariant<(id: string) => Promise<ProjectDetailed>>;
|
|
18
|
-
query(query?: ProjectListQueryModelData): ProjectListQuery;
|
|
18
|
+
static query(query?: ProjectListQueryModelData): ProjectListQuery;
|
|
19
19
|
/** @deprecated: use query(), Customer.projects or Server.projects */
|
|
20
20
|
static list: AsyncResourceVariant<(query?: ProjectListQueryData) => Promise<Readonly<Array<ProjectListItem>>>>;
|
|
21
21
|
static create(serverId: string, description: string): Promise<Project>;
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import { FC, PropsWithChildren } from "react";
|
|
2
|
-
|
|
1
|
+
import { FC, PropsWithChildren, ReactNode } from "react";
|
|
2
|
+
interface Props extends PropsWithChildren {
|
|
3
|
+
fallback?: ReactNode;
|
|
4
|
+
}
|
|
5
|
+
export declare const MittwaldApiModelProvider: FC<Props>;
|
|
6
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mittwald/api-models",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.60.0-beta.1",
|
|
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",
|
|
@@ -39,17 +39,22 @@
|
|
|
39
39
|
"test:unit": "node --experimental-vm-modules $(yarn bin jest)"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@mittwald/api-client": "
|
|
42
|
+
"@mittwald/api-client": "workspace:^",
|
|
43
43
|
"another-deep-freeze": "^1.0.0",
|
|
44
|
+
"context": "^3.0.31",
|
|
44
45
|
"object-code": "^1.3.3",
|
|
45
46
|
"polytype": "^0.17.0",
|
|
46
47
|
"type-fest": "^4.23.0"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@jest/globals": "^29.7.0",
|
|
50
|
-
"@mittwald/react-use-promise": "^2.
|
|
51
|
+
"@mittwald/react-use-promise": "^2.5.0",
|
|
52
|
+
"@testing-library/dom": "^10.4.0",
|
|
53
|
+
"@testing-library/jest-dom": "^6.5.0",
|
|
54
|
+
"@testing-library/react": "^16.0.1",
|
|
51
55
|
"@types/jest": "^29.5.12",
|
|
52
56
|
"@types/react": "^18.3.3",
|
|
57
|
+
"@types/react-dom": "^18",
|
|
53
58
|
"@typescript-eslint/eslint-plugin": "^7.18.0",
|
|
54
59
|
"@typescript-eslint/parser": "^7.18.0",
|
|
55
60
|
"eslint": "^8.57.0",
|
|
@@ -57,8 +62,10 @@
|
|
|
57
62
|
"eslint-plugin-json": "^3.1.0",
|
|
58
63
|
"eslint-plugin-prettier": "^5.2.1",
|
|
59
64
|
"jest": "^29.7.0",
|
|
65
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
60
66
|
"prettier": "^3.3.3",
|
|
61
67
|
"react": "^18.3.1",
|
|
68
|
+
"react-dom": "^18.3.1",
|
|
62
69
|
"rimraf": "^5.0.10",
|
|
63
70
|
"ts-jest": "^29.2.4",
|
|
64
71
|
"typescript": "^5.5.4"
|
|
@@ -73,6 +80,5 @@
|
|
|
73
80
|
"react": {
|
|
74
81
|
"optional": true
|
|
75
82
|
}
|
|
76
|
-
}
|
|
77
|
-
"gitHead": "9300cc09b76184f2d270d48f706e978e44759fa5"
|
|
83
|
+
}
|
|
78
84
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2023 Mittwald CM Service GmbH & Co. KG and contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|