@api-client/core 0.5.1 → 0.5.4
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/build/browser.d.ts +2 -3
- package/build/browser.js +2 -2
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +2 -3
- package/build/index.js +2 -2
- package/build/index.js.map +1 -1
- package/build/src/models/Project.d.ts +41 -0
- package/build/src/models/Project.js +94 -0
- package/build/src/models/Project.js.map +1 -0
- package/build/src/models/RevisionInfo.d.ts +5 -0
- package/build/src/models/RevisionInfo.js.map +1 -1
- package/build/src/models/Thing.js +1 -1
- package/build/src/models/Thing.js.map +1 -1
- package/build/src/models/Workspace.d.ts +0 -17
- package/build/src/models/Workspace.js +3 -19
- package/build/src/models/Workspace.js.map +1 -1
- package/build/src/models/store/Deletion.d.ts +24 -0
- package/build/src/models/store/Deletion.js +2 -0
- package/build/src/models/store/Deletion.js.map +1 -0
- package/build/src/models/store/File.d.ts +75 -12
- package/build/src/models/store/File.js +120 -19
- package/build/src/models/store/File.js.map +1 -1
- package/build/src/models/store/Modification.d.ts +24 -0
- package/build/src/models/store/Modification.js +2 -0
- package/build/src/models/store/Modification.js.map +1 -0
- package/build/src/runtime/store/FilesSdk.d.ts +79 -0
- package/build/src/runtime/store/{SpacesSdk.js → FilesSdk.js} +29 -15
- package/build/src/runtime/store/FilesSdk.js.map +1 -0
- package/build/src/runtime/store/RouteBuilder.d.ts +9 -17
- package/build/src/runtime/store/RouteBuilder.js +14 -26
- package/build/src/runtime/store/RouteBuilder.js.map +1 -1
- package/build/src/runtime/store/Sdk.d.ts +2 -7
- package/build/src/runtime/store/Sdk.js +2 -7
- package/build/src/runtime/store/Sdk.js.map +1 -1
- package/build/src/runtime/store/SharedSdk.js +1 -1
- package/build/src/runtime/store/SharedSdk.js.map +1 -1
- package/build/src/runtime/store/StoreSdkNode.d.ts +2 -0
- package/build/src/runtime/store/StoreSdkNode.js.map +1 -1
- package/build/src/runtime/store/StoreSdkWeb.d.ts +2 -0
- package/build/src/runtime/store/StoreSdkWeb.js.map +1 -1
- package/package.json +1 -1
- package/src/models/Project.ts +110 -0
- package/src/models/RevisionInfo.ts +6 -0
- package/src/models/Thing.ts +1 -1
- package/src/models/Workspace.ts +4 -29
- package/src/models/store/Deletion.ts +24 -0
- package/src/models/store/File.ts +146 -26
- package/src/models/store/Modification.ts +24 -0
- package/src/runtime/store/{SpacesSdk.ts → FilesSdk.ts} +69 -20
- package/src/runtime/store/RouteBuilder.ts +14 -28
- package/src/runtime/store/Sdk.ts +2 -7
- package/src/runtime/store/SharedSdk.ts +1 -1
- package/src/runtime/store/StoreSdkNode.ts +3 -0
- package/src/runtime/store/StoreSdkWeb.ts +3 -0
- package/build/src/models/HttpProjectListItem.d.ts +0 -23
- package/build/src/models/HttpProjectListItem.js +0 -2
- package/build/src/models/HttpProjectListItem.js.map +0 -1
- package/build/src/runtime/store/ProjectsSdk.d.ts +0 -43
- package/build/src/runtime/store/ProjectsSdk.js +0 -144
- package/build/src/runtime/store/ProjectsSdk.js.map +0 -1
- package/build/src/runtime/store/SpacesSdk.d.ts +0 -57
- package/build/src/runtime/store/SpacesSdk.js.map +0 -1
- package/src/models/HttpProjectListItem.ts +0 -23
- package/src/runtime/store/ProjectsSdk.ts +0 -147
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { JsonPatch } from 'json8-patch';
|
|
2
|
-
import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, E_RESPONSE_LOCATION } from './SdkBase.js';
|
|
3
|
-
import { RouteBuilder } from './RouteBuilder.js';
|
|
4
|
-
import { IListOptions, IListResponse } from '../../models/Backend.js';
|
|
5
|
-
import { HttpProject, IHttpProject, Kind as HttpProjectKind } from '../../models/HttpProject.js';
|
|
6
|
-
|
|
7
|
-
export class ProjectsSdk extends SdkBase {
|
|
8
|
-
/**
|
|
9
|
-
* Creates a project in a user space.
|
|
10
|
-
*
|
|
11
|
-
* @param space The user space key
|
|
12
|
-
* @param project THe project to create
|
|
13
|
-
* @returns The key of the created project.
|
|
14
|
-
*/
|
|
15
|
-
async create(space: string, project: IHttpProject | HttpProject): Promise<string> {
|
|
16
|
-
const { token } = this.sdk;
|
|
17
|
-
const url = this.sdk.getUrl(RouteBuilder.spaceProjects(space));
|
|
18
|
-
const body = JSON.stringify(project);
|
|
19
|
-
const result = await this.sdk.http.post(url.toString(), { token, body });
|
|
20
|
-
this.inspectCommonStatusCodes(result.status);
|
|
21
|
-
const E_PREFIX = 'Unable to create a project. ';
|
|
22
|
-
if (result.status !== 204) {
|
|
23
|
-
this.logInvalidResponse(result);
|
|
24
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
25
|
-
}
|
|
26
|
-
const location = result.headers.get('location');
|
|
27
|
-
if (!location) {
|
|
28
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_LOCATION}`);
|
|
29
|
-
}
|
|
30
|
-
const id = location.split('/').pop();
|
|
31
|
-
return id as string;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Reads a project definition from the store.
|
|
36
|
-
* @param space The user space key
|
|
37
|
-
* @param project The project key
|
|
38
|
-
* @returns The definition of the project.
|
|
39
|
-
*/
|
|
40
|
-
async read(space: string, project: string): Promise<IHttpProject> {
|
|
41
|
-
const { token } = this.sdk;
|
|
42
|
-
const url = this.sdk.getUrl(RouteBuilder.spaceProject(space, project));
|
|
43
|
-
const result = await this.sdk.http.get(url.toString(), { token });
|
|
44
|
-
this.inspectCommonStatusCodes(result.status);
|
|
45
|
-
const E_PREFIX = 'Unable to read a project. ';
|
|
46
|
-
if (result.status !== 200) {
|
|
47
|
-
this.logInvalidResponse(result);
|
|
48
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
49
|
-
}
|
|
50
|
-
if (!result.body) {
|
|
51
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
52
|
-
}
|
|
53
|
-
let data: IHttpProject;
|
|
54
|
-
try {
|
|
55
|
-
data = JSON.parse(result.body);
|
|
56
|
-
} catch (e) {
|
|
57
|
-
throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
|
|
58
|
-
}
|
|
59
|
-
if (data.kind !== HttpProjectKind) {
|
|
60
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
|
|
61
|
-
}
|
|
62
|
-
return data;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Lists projects in the space
|
|
67
|
-
*
|
|
68
|
-
* @param space The user space key
|
|
69
|
-
* @param options Optional query options.
|
|
70
|
-
*/
|
|
71
|
-
async list(space: string, options?: IListOptions): Promise<IListResponse> {
|
|
72
|
-
const { token } = this.sdk;
|
|
73
|
-
const url = this.sdk.getUrl(RouteBuilder.spaceProjects(space));
|
|
74
|
-
this.sdk.appendListOptions(url, options);
|
|
75
|
-
const result = await this.sdk.http.get(url.toString(), { token });
|
|
76
|
-
this.inspectCommonStatusCodes(result.status);
|
|
77
|
-
const E_PREFIX = 'Unable to list projects. ';
|
|
78
|
-
if (result.status !== 200) {
|
|
79
|
-
this.logInvalidResponse(result);
|
|
80
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
81
|
-
}
|
|
82
|
-
if (!result.body) {
|
|
83
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
84
|
-
}
|
|
85
|
-
let data: IListResponse;
|
|
86
|
-
try {
|
|
87
|
-
data = JSON.parse(result.body);
|
|
88
|
-
} catch (e) {
|
|
89
|
-
throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
|
|
90
|
-
}
|
|
91
|
-
if (!Array.isArray(data.data)) {
|
|
92
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
|
|
93
|
-
}
|
|
94
|
-
return data;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Deletes a project form the store.
|
|
99
|
-
*
|
|
100
|
-
* @param space The key of the parent space.
|
|
101
|
-
* @param project The key of the project to delete.
|
|
102
|
-
*/
|
|
103
|
-
async delete(space: string, project: string): Promise<void> {
|
|
104
|
-
const { token } = this.sdk;
|
|
105
|
-
const url = this.sdk.getUrl(RouteBuilder.spaceProject(space, project));
|
|
106
|
-
const result = await this.sdk.http.delete(url.toString(), { token });
|
|
107
|
-
this.inspectCommonStatusCodes(result.status);
|
|
108
|
-
const E_PREFIX = 'Unable to delete a project. ';
|
|
109
|
-
if (result.status !== 204) {
|
|
110
|
-
this.logInvalidResponse(result);
|
|
111
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Patches a project in the store.
|
|
117
|
-
* @param space The key of the parent user space
|
|
118
|
-
* @param project The key of project to patch.
|
|
119
|
-
* @param value The JSON patch to be processed.
|
|
120
|
-
* @returns The JSON patch to revert the change using the `json8-patch` library
|
|
121
|
-
*/
|
|
122
|
-
async patch(space: string, project: string, value: JsonPatch): Promise<JsonPatch> {
|
|
123
|
-
const { token } = this.sdk;
|
|
124
|
-
const url = this.sdk.getUrl(RouteBuilder.spaceProject(space, project));
|
|
125
|
-
const body = JSON.stringify(value);
|
|
126
|
-
const result = await this.sdk.http.patch(url.toString(), { token, body });
|
|
127
|
-
this.inspectCommonStatusCodes(result.status);
|
|
128
|
-
const E_PREFIX = 'Unable to patch a project. ';
|
|
129
|
-
if (result.status !== 200) {
|
|
130
|
-
this.logInvalidResponse(result);
|
|
131
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
|
|
132
|
-
}
|
|
133
|
-
if (!result.body) {
|
|
134
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
135
|
-
}
|
|
136
|
-
let data: any;
|
|
137
|
-
try {
|
|
138
|
-
data = JSON.parse(result.body);
|
|
139
|
-
} catch (e) {
|
|
140
|
-
throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
|
|
141
|
-
}
|
|
142
|
-
if (!data.revert) {
|
|
143
|
-
throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
|
|
144
|
-
}
|
|
145
|
-
return data.revert as JsonPatch;
|
|
146
|
-
}
|
|
147
|
-
}
|