@mittwald/api-models 0.1.0-alpha.2 → 4.11.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.
- package/LICENSE +21 -0
- package/dist/esm/app/AppInstallation/AppInstallation.js +5 -5
- package/dist/esm/config/behaviors/api.js +6 -0
- package/dist/esm/customer/Customer/Customer.js +5 -5
- package/dist/esm/domain/Ingress/Ingress.js +5 -5
- package/dist/esm/lib/{withAsyncResourceVariant.js → provideReact.js} +1 -1
- package/dist/esm/project/Project/Project.js +7 -7
- package/dist/esm/react/index.js +1 -1
- package/dist/esm/server/Server/Server.js +6 -6
- package/dist/types/config/behaviors/api.d.ts +1 -0
- package/dist/types/lib/{withAsyncResourceVariant.d.ts → provideReact.d.ts} +1 -1
- package/dist/types/react/index.d.ts +2 -2
- package/package.json +4 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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.
|
|
@@ -3,15 +3,15 @@ import { classes } from "polytype";
|
|
|
3
3
|
import { DataModel } from "../../base/DataModel.js";
|
|
4
4
|
import assertObjectFound from "../../base/assertObjectFound.js";
|
|
5
5
|
import { ReferenceModel } from "../../base/ReferenceModel.js";
|
|
6
|
-
import {
|
|
6
|
+
import { provideReact } from "../../lib/provideReact.js";
|
|
7
7
|
export class AppInstallation extends ReferenceModel {
|
|
8
|
-
static find =
|
|
8
|
+
static find = provideReact(async (id) => {
|
|
9
9
|
const data = await config.behaviors.appInstallation.find(id);
|
|
10
10
|
if (data !== undefined) {
|
|
11
11
|
return new AppInstallationDetailed(data);
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
|
-
static get =
|
|
14
|
+
static get = provideReact(async (id) => {
|
|
15
15
|
const appInstallation = await this.find(id);
|
|
16
16
|
assertObjectFound(appInstallation, this, id);
|
|
17
17
|
return appInstallation;
|
|
@@ -19,11 +19,11 @@ export class AppInstallation extends ReferenceModel {
|
|
|
19
19
|
static ofId(id) {
|
|
20
20
|
return new AppInstallation(id);
|
|
21
21
|
}
|
|
22
|
-
static list =
|
|
22
|
+
static list = provideReact(async (projectId, query = {}) => {
|
|
23
23
|
const data = await config.behaviors.appInstallation.list(projectId, query);
|
|
24
24
|
return data.map((d) => new AppInstallationListItem(d));
|
|
25
25
|
});
|
|
26
|
-
getDetailed =
|
|
26
|
+
getDetailed = provideReact(() => AppInstallation.get(this.id));
|
|
27
27
|
}
|
|
28
28
|
// Common class for future extension
|
|
29
29
|
class AppInstallationCommon extends classes((DataModel), AppInstallation) {
|
|
@@ -8,6 +8,9 @@ import { apiAppInstallationBehaviors } from "../../app/AppInstallation/behaviors
|
|
|
8
8
|
class ApiSetupState {
|
|
9
9
|
_client;
|
|
10
10
|
setupWithClient(client) {
|
|
11
|
+
if (this._client !== undefined) {
|
|
12
|
+
throw new Error("API already setup. If you want to operate on the API client use api.client.");
|
|
13
|
+
}
|
|
11
14
|
this._client = client;
|
|
12
15
|
config.behaviors.project = apiProjectBehaviors(client);
|
|
13
16
|
config.behaviors.server = apiServerBehaviors(client);
|
|
@@ -18,6 +21,9 @@ class ApiSetupState {
|
|
|
18
21
|
setupWithApiToken(apiToken) {
|
|
19
22
|
return this.setupWithClient(MittwaldAPIV2Client.newWithToken(apiToken));
|
|
20
23
|
}
|
|
24
|
+
setupUnauthenticated() {
|
|
25
|
+
return this.setupWithClient(MittwaldAPIV2Client.newUnauthenticated());
|
|
26
|
+
}
|
|
21
27
|
get client() {
|
|
22
28
|
if (!this._client) {
|
|
23
29
|
throw new Error("Could not get client. Behavior not initialized.");
|
|
@@ -3,27 +3,27 @@ import { classes } from "polytype";
|
|
|
3
3
|
import { DataModel } from "../../base/DataModel.js";
|
|
4
4
|
import assertObjectFound from "../../base/assertObjectFound.js";
|
|
5
5
|
import { ReferenceModel } from "../../base/ReferenceModel.js";
|
|
6
|
-
import {
|
|
6
|
+
import { provideReact } from "../../lib/provideReact.js";
|
|
7
7
|
export class Customer extends ReferenceModel {
|
|
8
8
|
static ofId(id) {
|
|
9
9
|
return new Customer(id);
|
|
10
10
|
}
|
|
11
|
-
static find =
|
|
11
|
+
static find = provideReact(async (id) => {
|
|
12
12
|
const data = await config.behaviors.customer.find(id);
|
|
13
13
|
if (data !== undefined) {
|
|
14
14
|
return new CustomerDetailed(data);
|
|
15
15
|
}
|
|
16
16
|
});
|
|
17
|
-
static list =
|
|
17
|
+
static list = provideReact(async (query = {}) => {
|
|
18
18
|
const data = await config.behaviors.customer.list(query);
|
|
19
19
|
return Object.freeze(data.map((d) => new CustomerListItem(d)));
|
|
20
20
|
});
|
|
21
|
-
static get =
|
|
21
|
+
static get = provideReact(async (id) => {
|
|
22
22
|
const customer = await this.find(id);
|
|
23
23
|
assertObjectFound(customer, this, id);
|
|
24
24
|
return customer;
|
|
25
25
|
});
|
|
26
|
-
getDetailed =
|
|
26
|
+
getDetailed = provideReact(() => Customer.get(this.id));
|
|
27
27
|
}
|
|
28
28
|
// Common class for future extension
|
|
29
29
|
class CustomerCommon extends classes((DataModel), Customer) {
|
|
@@ -3,7 +3,7 @@ import { classes } from "polytype";
|
|
|
3
3
|
import { DataModel } from "../../base/DataModel.js";
|
|
4
4
|
import assertObjectFound from "../../base/assertObjectFound.js";
|
|
5
5
|
import { ReferenceModel } from "../../base/ReferenceModel.js";
|
|
6
|
-
import {
|
|
6
|
+
import { provideReact } from "../../lib/provideReact.js";
|
|
7
7
|
import { IngressPath } from "../IngressPath/IngressPath.js";
|
|
8
8
|
export class Ingress extends ReferenceModel {
|
|
9
9
|
static ofId(id) {
|
|
@@ -12,22 +12,22 @@ export class Ingress extends ReferenceModel {
|
|
|
12
12
|
static ofHostname(hostname) {
|
|
13
13
|
return Ingress.ofId(hostname);
|
|
14
14
|
}
|
|
15
|
-
static list =
|
|
15
|
+
static list = provideReact(async (query = {}) => {
|
|
16
16
|
const data = await config.behaviors.ingress.list(query);
|
|
17
17
|
return data.map((d) => new IngressListItem(d));
|
|
18
18
|
});
|
|
19
|
-
static find =
|
|
19
|
+
static find = provideReact(async (id) => {
|
|
20
20
|
const data = await config.behaviors.ingress.find(id);
|
|
21
21
|
if (data !== undefined) {
|
|
22
22
|
return new IngressDetailed(data);
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
|
-
static get =
|
|
25
|
+
static get = provideReact(async (id) => {
|
|
26
26
|
const ingress = await this.find(id);
|
|
27
27
|
assertObjectFound(ingress, this, id);
|
|
28
28
|
return ingress;
|
|
29
29
|
});
|
|
30
|
-
getDetailed =
|
|
30
|
+
getDetailed = provideReact(() => Ingress.get(this.id));
|
|
31
31
|
}
|
|
32
32
|
export class IngressCommon extends classes((DataModel), Ingress) {
|
|
33
33
|
baseUrl;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { reactUsePromise } from "../react/reactUsePromise.js";
|
|
2
|
-
export const
|
|
2
|
+
export const provideReact = (loader) => Object.assign(loader, {
|
|
3
3
|
asResource: (...params) => reactUsePromise.getAsyncResource(loader, params),
|
|
4
4
|
use: (...params) => reactUsePromise.getAsyncResource(loader, params).use(),
|
|
5
5
|
});
|
|
@@ -3,7 +3,7 @@ import { classes } from "polytype";
|
|
|
3
3
|
import { DataModel } from "../../base/DataModel.js";
|
|
4
4
|
import assertObjectFound from "../../base/assertObjectFound.js";
|
|
5
5
|
import { Server } from "../../server/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import { provideReact, } from "../../lib/provideReact.js";
|
|
7
7
|
import { Customer } from "../../customer/Customer/Customer.js";
|
|
8
8
|
import { ReferenceModel } from "../../base/ReferenceModel.js";
|
|
9
9
|
import { Ingress, IngressListItem } from "../../domain/index.js";
|
|
@@ -11,18 +11,18 @@ export class Project extends ReferenceModel {
|
|
|
11
11
|
static ofId(id) {
|
|
12
12
|
return new Project(id);
|
|
13
13
|
}
|
|
14
|
-
static find =
|
|
14
|
+
static find = provideReact(async (id) => {
|
|
15
15
|
const data = await config.behaviors.project.find(id);
|
|
16
16
|
if (data !== undefined) {
|
|
17
17
|
return new ProjectDetailed(data);
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
|
-
static get =
|
|
20
|
+
static get = provideReact(async (id) => {
|
|
21
21
|
const project = await this.find(id);
|
|
22
22
|
assertObjectFound(project, this, id);
|
|
23
23
|
return project;
|
|
24
24
|
});
|
|
25
|
-
static list =
|
|
25
|
+
static list = provideReact(async (query = {}) => {
|
|
26
26
|
const data = await config.behaviors.project.list(query);
|
|
27
27
|
return Object.freeze(data.map((d) => new ProjectListItem(d)));
|
|
28
28
|
});
|
|
@@ -30,9 +30,9 @@ export class Project extends ReferenceModel {
|
|
|
30
30
|
const { id } = await config.behaviors.project.create(serverId, description);
|
|
31
31
|
return new Project(id);
|
|
32
32
|
}
|
|
33
|
-
getDetailed =
|
|
34
|
-
listIngresses =
|
|
35
|
-
getDefaultIngress =
|
|
33
|
+
getDetailed = provideReact(() => Project.get(this.id));
|
|
34
|
+
listIngresses = provideReact(() => Ingress.list({ projectId: this.id }));
|
|
35
|
+
getDefaultIngress = provideReact(async () => {
|
|
36
36
|
const ingresses = await Project.ofId(this.id).listIngresses();
|
|
37
37
|
const defaultIngress = ingresses.find((i) => i.data.isDefault);
|
|
38
38
|
assertObjectFound(defaultIngress, IngressListItem, this);
|
package/dist/esm/react/index.js
CHANGED
|
@@ -4,20 +4,20 @@ import { classes } from "polytype";
|
|
|
4
4
|
import { DataModel } from "../../base/DataModel.js";
|
|
5
5
|
import assertObjectFound from "../../base/assertObjectFound.js";
|
|
6
6
|
import { Project } from "../../project/index.js";
|
|
7
|
-
import {
|
|
7
|
+
import { provideReact } from "../../lib/provideReact.js";
|
|
8
8
|
export class Server extends ReferenceModel {
|
|
9
|
-
static find =
|
|
9
|
+
static find = provideReact(async (id) => {
|
|
10
10
|
const serverData = await config.behaviors.server.find(id);
|
|
11
11
|
if (serverData !== undefined) {
|
|
12
12
|
return new ServerDetailed([serverData]);
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
|
-
static get =
|
|
15
|
+
static get = provideReact(async (id) => {
|
|
16
16
|
const server = await ServerDetailed.find(id);
|
|
17
17
|
assertObjectFound(server, this, id);
|
|
18
18
|
return server;
|
|
19
19
|
});
|
|
20
|
-
static list =
|
|
20
|
+
static list = provideReact(async (query = {}) => {
|
|
21
21
|
const projectListData = await config.behaviors.server.list(query);
|
|
22
22
|
return projectListData.map((d) => new ServerListItem([d]));
|
|
23
23
|
});
|
|
@@ -27,13 +27,13 @@ export class Server extends ReferenceModel {
|
|
|
27
27
|
async createProject(...parameters) {
|
|
28
28
|
return Project.create(this.id, ...parameters);
|
|
29
29
|
}
|
|
30
|
-
listProjects =
|
|
30
|
+
listProjects = provideReact(async (query = {}) => {
|
|
31
31
|
return Project.list({
|
|
32
32
|
...query,
|
|
33
33
|
serverId: this.id,
|
|
34
34
|
});
|
|
35
35
|
});
|
|
36
|
-
getDetailed =
|
|
36
|
+
getDetailed = provideReact(() => ServerDetailed.get(this.id));
|
|
37
37
|
}
|
|
38
38
|
// Common class for future extension
|
|
39
39
|
class ServerCommon extends classes((DataModel), Server) {
|
|
@@ -3,6 +3,7 @@ declare class ApiSetupState {
|
|
|
3
3
|
private _client;
|
|
4
4
|
setupWithClient(client: MittwaldAPIV2Client): void;
|
|
5
5
|
setupWithApiToken(apiToken: string): void;
|
|
6
|
+
setupUnauthenticated(): void;
|
|
6
7
|
get client(): MittwaldAPIV2Client;
|
|
7
8
|
get defaults(): (typeof this.client)["axios"]["defaults"];
|
|
8
9
|
get interceptors(): (typeof this.client)["axios"]["interceptors"];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AsyncResource } from "../react/reactUsePromise.js";
|
|
2
2
|
type FnParameters = unknown[];
|
|
3
3
|
type AsyncFn<TResult, TParams extends FnParameters> = (...args: TParams) => Promise<TResult>;
|
|
4
|
-
export declare const
|
|
4
|
+
export declare const provideReact: <TValue, TParams extends FnParameters>(loader: AsyncFn<TValue, TParams>) => AsyncResourceVariant<TValue, TParams>;
|
|
5
5
|
export type AsyncResourceVariant<TValue, TParams extends FnParameters> = TParams extends null ? AsyncFn<TValue, TParams> & {
|
|
6
6
|
asResource: () => AsyncResource<TValue>;
|
|
7
7
|
} : AsyncFn<TValue, TParams> & {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from "./MittwaldApiModelProvider.js";
|
|
2
2
|
export * from "./reactUsePromise.js";
|
|
3
|
-
export { type AsyncResourceVariant } from "../lib/
|
|
4
|
-
export {
|
|
3
|
+
export { type AsyncResourceVariant } from "../lib/provideReact.js";
|
|
4
|
+
export { provideReact } from "../lib/provideReact.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mittwald/api-models",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.11.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",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"test": "node --experimental-vm-modules $(yarn bin jest)"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@mittwald/api-client": "^
|
|
39
|
+
"@mittwald/api-client": "^4.11.0",
|
|
40
40
|
"another-deep-freeze": "^1.0.0",
|
|
41
41
|
"polytype": "^0.17.0",
|
|
42
42
|
"type-fest": "^4.10.3"
|
|
@@ -69,5 +69,6 @@
|
|
|
69
69
|
"react": {
|
|
70
70
|
"optional": true
|
|
71
71
|
}
|
|
72
|
-
}
|
|
72
|
+
},
|
|
73
|
+
"gitHead": "48692f21b29d6f4f51aed998a2502f32d4f0eb5c"
|
|
73
74
|
}
|