@api-client/core 0.5.2 → 0.5.5

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.
Files changed (88) hide show
  1. package/build/browser.d.ts +2 -1
  2. package/build/browser.js +2 -1
  3. package/build/browser.js.map +1 -1
  4. package/build/index.d.ts +2 -1
  5. package/build/index.js +2 -1
  6. package/build/index.js.map +1 -1
  7. package/build/src/models/Backend.d.ts +7 -9
  8. package/build/src/models/HttpHistory.d.ts +2 -2
  9. package/build/src/models/Project.d.ts +41 -0
  10. package/build/src/models/Project.js +94 -0
  11. package/build/src/models/Project.js.map +1 -0
  12. package/build/src/models/RevisionInfo.d.ts +5 -0
  13. package/build/src/models/RevisionInfo.js.map +1 -1
  14. package/build/src/models/SerializableError.d.ts +1 -0
  15. package/build/src/models/SerializableError.js.map +1 -1
  16. package/build/src/models/Thing.js +1 -1
  17. package/build/src/models/Thing.js.map +1 -1
  18. package/build/src/models/Workspace.d.ts +0 -17
  19. package/build/src/models/Workspace.js +3 -19
  20. package/build/src/models/Workspace.js.map +1 -1
  21. package/build/src/models/store/Deletion.d.ts +24 -0
  22. package/build/src/models/store/Deletion.js +2 -0
  23. package/build/src/models/store/Deletion.js.map +1 -0
  24. package/build/src/models/store/File.d.ts +75 -12
  25. package/build/src/models/store/File.js +120 -19
  26. package/build/src/models/store/File.js.map +1 -1
  27. package/build/src/models/store/Modification.d.ts +24 -0
  28. package/build/src/models/store/Modification.js +2 -0
  29. package/build/src/models/store/Modification.js.map +1 -0
  30. package/build/src/runtime/store/Errors.d.ts +50 -0
  31. package/build/src/runtime/store/Errors.js +63 -0
  32. package/build/src/runtime/store/Errors.js.map +1 -0
  33. package/build/src/runtime/store/FilesSdk.d.ts +94 -0
  34. package/build/src/runtime/store/FilesSdk.js +247 -0
  35. package/build/src/runtime/store/FilesSdk.js.map +1 -0
  36. package/build/src/runtime/store/HistorySdk.d.ts +14 -7
  37. package/build/src/runtime/store/HistorySdk.js +34 -12
  38. package/build/src/runtime/store/HistorySdk.js.map +1 -1
  39. package/build/src/runtime/store/RouteBuilder.d.ts +9 -17
  40. package/build/src/runtime/store/RouteBuilder.js +14 -26
  41. package/build/src/runtime/store/RouteBuilder.js.map +1 -1
  42. package/build/src/runtime/store/Sdk.d.ts +6 -7
  43. package/build/src/runtime/store/Sdk.js +6 -7
  44. package/build/src/runtime/store/Sdk.js.map +1 -1
  45. package/build/src/runtime/store/SdkBase.d.ts +16 -6
  46. package/build/src/runtime/store/SdkBase.js +54 -4
  47. package/build/src/runtime/store/SdkBase.js.map +1 -1
  48. package/build/src/runtime/store/SharedSdk.d.ts +8 -2
  49. package/build/src/runtime/store/SharedSdk.js +22 -8
  50. package/build/src/runtime/store/SharedSdk.js.map +1 -1
  51. package/build/src/runtime/store/StoreSdkNode.d.ts +1 -1
  52. package/build/src/runtime/store/StoreSdkWeb.d.ts +1 -1
  53. package/build/src/runtime/store/UsersSdk.d.ts +10 -4
  54. package/build/src/runtime/store/UsersSdk.js +12 -6
  55. package/build/src/runtime/store/UsersSdk.js.map +1 -1
  56. package/package.json +2 -2
  57. package/src/models/Backend.ts +7 -9
  58. package/src/models/HttpHistory.ts +2 -2
  59. package/src/models/Project.ts +110 -0
  60. package/src/models/RevisionInfo.ts +6 -0
  61. package/src/models/SerializableError.ts +1 -0
  62. package/src/models/Thing.ts +1 -1
  63. package/src/models/Workspace.ts +4 -29
  64. package/src/models/store/Deletion.ts +24 -0
  65. package/src/models/store/File.ts +146 -26
  66. package/src/models/store/Modification.ts +24 -0
  67. package/src/runtime/store/Errors.ts +100 -0
  68. package/src/runtime/store/FilesSdk.ts +302 -0
  69. package/src/runtime/store/HistorySdk.ts +42 -17
  70. package/src/runtime/store/RouteBuilder.ts +14 -28
  71. package/src/runtime/store/Sdk.ts +7 -7
  72. package/src/runtime/store/SdkBase.ts +63 -9
  73. package/src/runtime/store/SharedSdk.ts +27 -10
  74. package/src/runtime/store/StoreSdkNode.ts +1 -1
  75. package/src/runtime/store/StoreSdkWeb.ts +1 -1
  76. package/src/runtime/store/UsersSdk.ts +14 -8
  77. package/build/src/models/HttpProjectListItem.d.ts +0 -23
  78. package/build/src/models/HttpProjectListItem.js +0 -2
  79. package/build/src/models/HttpProjectListItem.js.map +0 -1
  80. package/build/src/runtime/store/ProjectsSdk.d.ts +0 -43
  81. package/build/src/runtime/store/ProjectsSdk.js +0 -144
  82. package/build/src/runtime/store/ProjectsSdk.js.map +0 -1
  83. package/build/src/runtime/store/SpacesSdk.d.ts +0 -62
  84. package/build/src/runtime/store/SpacesSdk.js +0 -194
  85. package/build/src/runtime/store/SpacesSdk.js.map +0 -1
  86. package/src/models/HttpProjectListItem.ts +0 -23
  87. package/src/runtime/store/ProjectsSdk.ts +0 -147
  88. package/src/runtime/store/SpacesSdk.ts +0 -209
@@ -1,209 +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 { IWorkspace, Workspace, Kind as WorkspaceKind } from '../../models/Workspace.js';
6
- import { AccessOperation } from '../../models/store/Permission.js';
7
- import WebSocketNode from 'ws';
8
-
9
- export interface ISpaceCreateOptions {
10
- /**
11
- * Optional parent space id.
12
- * When set it creates a space under this parent.
13
- */
14
- parent?: string;
15
- }
16
-
17
- export class SpacesSdk extends SdkBase {
18
- /**
19
- * Lists spaces in the store.
20
- * @param options Optional query options.
21
- */
22
- async list(options?: IListOptions): Promise<IListResponse> {
23
- const { token } = this.sdk;
24
- const url = this.sdk.getUrl(RouteBuilder.spaces());
25
- this.sdk.appendListOptions(url, options);
26
- const result = await this.sdk.http.get(url.toString(), { token });
27
- this.inspectCommonStatusCodes(result.status);
28
- const E_PREFIX = 'Unable to list spaces. ';
29
- if (result.status !== 200) {
30
- this.logInvalidResponse(result);
31
- throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
32
- }
33
- if (!result.body) {
34
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
35
- }
36
- let data: IListResponse;
37
- try {
38
- data = JSON.parse(result.body);
39
- } catch (e) {
40
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
41
- }
42
- if (!Array.isArray(data.data)) {
43
- throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
44
- }
45
- return data;
46
- }
47
-
48
- /**
49
- * Creates a workspace in the store.
50
- * @param space The workspace definition.
51
- * @returns The key of the creates space.
52
- */
53
- async create(space: IWorkspace | Workspace, opts: ISpaceCreateOptions = {}): Promise<string> {
54
- const { token } = this.sdk;
55
- const path = opts.parent ? RouteBuilder.space(opts.parent) : RouteBuilder.spaces();
56
- const url = this.sdk.getUrl(path);
57
- const body = JSON.stringify(space);
58
- const result = await this.sdk.http.post(url.toString(), { token, body });
59
- this.inspectCommonStatusCodes(result.status);
60
- const E_PREFIX = 'Unable to create a user space. ';
61
- if (result.status !== 204) {
62
- this.logInvalidResponse(result);
63
- throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
64
- }
65
- const location = result.headers.get('location');
66
- if (!location) {
67
- throw new Error(`${E_PREFIX}${E_RESPONSE_LOCATION}`);
68
- }
69
- const id = location.split('/').pop();
70
- return id as string;
71
- }
72
-
73
- /**
74
- * Reads a user space definition from the store.
75
- * @param key The user space key
76
- * @returns The definition of the user space.
77
- */
78
- async read(key: string): Promise<IWorkspace> {
79
- const { token } = this.sdk;
80
- const url = this.sdk.getUrl(RouteBuilder.space(key));
81
- const result = await this.sdk.http.get(url.toString(), { token });
82
- this.inspectCommonStatusCodes(result.status);
83
- const E_PREFIX = 'Unable to read a user space. ';
84
- if (result.status !== 200) {
85
- this.logInvalidResponse(result);
86
- throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
87
- }
88
- if (!result.body) {
89
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
90
- }
91
- let data: IWorkspace;
92
- try {
93
- data = JSON.parse(result.body);
94
- } catch (e) {
95
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
96
- }
97
- if (data.kind !== WorkspaceKind) {
98
- throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
99
- }
100
- return data;
101
- }
102
-
103
- /**
104
- * Patches a user space in the store.
105
- * @param key The key of the user space to patch
106
- * @param value The JSON patch to be processed.
107
- * @returns The JSON patch to revert the change using the `json8-patch` library
108
- */
109
- async patch(key: string, value: JsonPatch): Promise<JsonPatch> {
110
- const { token } = this.sdk;
111
- const url = this.sdk.getUrl(RouteBuilder.space(key));
112
- const body = JSON.stringify(value);
113
- const result = await this.sdk.http.patch(url.toString(), { token, body });
114
- this.inspectCommonStatusCodes(result.status);
115
- const E_PREFIX = 'Unable to patch a user space. ';
116
- if (result.status !== 200) {
117
- this.logInvalidResponse(result);
118
- throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
119
- }
120
- if (!result.body) {
121
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
122
- }
123
- let data: any;
124
- try {
125
- data = JSON.parse(result.body);
126
- } catch (e) {
127
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
128
- }
129
- if (!data.revert) {
130
- throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
131
- }
132
- return data.revert as JsonPatch;
133
- }
134
-
135
- /**
136
- * Deletes the space in the store.
137
- *
138
- * @param key The key of the space to delete.
139
- */
140
- async delete(key: string): Promise<void> {
141
- const { token } = this.sdk;
142
- const url = this.sdk.getUrl(RouteBuilder.space(key));
143
- const result = await this.sdk.http.delete(url.toString(), { token });
144
- this.inspectCommonStatusCodes(result.status);
145
- const E_PREFIX = 'Unable to delete a user space. ';
146
- if (result.status !== 204) {
147
- this.logInvalidResponse(result);
148
- throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
149
- }
150
- }
151
-
152
- /**
153
- * Updates the sharing options of the space.
154
- *
155
- * @param key The user space key
156
- * @param value The patch operation on the space's ACL
157
- */
158
- async patchUsers(key: string, value: AccessOperation[]): Promise<void> {
159
- const { token } = this.sdk;
160
- const url = this.sdk.getUrl(RouteBuilder.spaceUsers(key));
161
- const body = JSON.stringify(value);
162
- const result = await this.sdk.http.patch(url.toString(), { token, body });
163
- this.inspectCommonStatusCodes(result.status);
164
- const E_PREFIX = 'Unable to patch a user space. ';
165
- if (result.status !== 204) {
166
- this.logInvalidResponse(result);
167
- throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
168
- }
169
- }
170
-
171
- /**
172
- * Lists uses having access to the user space.
173
- *
174
- * @param key The user space key
175
- */
176
- async listUsers(key: string): Promise<IListResponse> {
177
- const { token } = this.sdk;
178
- const url = this.sdk.getUrl(RouteBuilder.spaceUsers(key));
179
- const result = await this.sdk.http.get(url.toString(), { token });
180
- this.inspectCommonStatusCodes(result.status);
181
- const E_PREFIX = 'Unable to list users in the space. ';
182
- if (result.status !== 200) {
183
- this.logInvalidResponse(result);
184
- throw new Error(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`);
185
- }
186
- if (!result.body) {
187
- throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
188
- }
189
- let data: IListResponse;
190
- try {
191
- data = JSON.parse(result.body);
192
- } catch (e) {
193
- throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
194
- }
195
- if (!Array.isArray(data.data)) {
196
- throw new Error(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`);
197
- }
198
- return data;
199
- }
200
-
201
- /**
202
- * Creates a WS client that listens to the spaces events.
203
- */
204
- async observeSpaces(): Promise<WebSocketNode | WebSocket> {
205
- const { token } = this.sdk;
206
- const url = this.sdk.getUrl(RouteBuilder.spaces());
207
- return this.sdk.ws.createAndConnect(url.toString(), token);
208
- }
209
- }