@api-client/core 0.5.4 → 0.5.7

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 (51) hide show
  1. package/build/browser.d.ts +1 -0
  2. package/build/browser.js +1 -0
  3. package/build/browser.js.map +1 -1
  4. package/build/index.d.ts +1 -0
  5. package/build/index.js +1 -0
  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 +1 -1
  10. package/build/src/models/Project.js +2 -2
  11. package/build/src/models/Project.js.map +1 -1
  12. package/build/src/models/RevisionInfo.d.ts +2 -2
  13. package/build/src/models/SerializableError.d.ts +1 -0
  14. package/build/src/models/SerializableError.js.map +1 -1
  15. package/build/src/runtime/store/Errors.d.ts +50 -0
  16. package/build/src/runtime/store/Errors.js +63 -0
  17. package/build/src/runtime/store/Errors.js.map +1 -0
  18. package/build/src/runtime/store/FilesSdk.d.ts +43 -27
  19. package/build/src/runtime/store/FilesSdk.js +102 -54
  20. package/build/src/runtime/store/FilesSdk.js.map +1 -1
  21. package/build/src/runtime/store/HistorySdk.d.ts +14 -7
  22. package/build/src/runtime/store/HistorySdk.js +34 -12
  23. package/build/src/runtime/store/HistorySdk.js.map +1 -1
  24. package/build/src/runtime/store/Sdk.d.ts +4 -0
  25. package/build/src/runtime/store/Sdk.js +4 -0
  26. package/build/src/runtime/store/Sdk.js.map +1 -1
  27. package/build/src/runtime/store/SdkBase.d.ts +16 -6
  28. package/build/src/runtime/store/SdkBase.js +54 -4
  29. package/build/src/runtime/store/SdkBase.js.map +1 -1
  30. package/build/src/runtime/store/SharedSdk.d.ts +8 -2
  31. package/build/src/runtime/store/SharedSdk.js +21 -7
  32. package/build/src/runtime/store/SharedSdk.js.map +1 -1
  33. package/build/src/runtime/store/StoreSdkWeb.d.ts +1 -1
  34. package/build/src/runtime/store/UsersSdk.d.ts +10 -4
  35. package/build/src/runtime/store/UsersSdk.js +12 -6
  36. package/build/src/runtime/store/UsersSdk.js.map +1 -1
  37. package/package.json +3 -4
  38. package/src/models/Backend.ts +7 -9
  39. package/src/models/HttpHistory.ts +2 -2
  40. package/src/models/Project.ts +2 -2
  41. package/src/models/RevisionInfo.ts +2 -2
  42. package/src/models/SerializableError.ts +1 -0
  43. package/src/runtime/store/Errors.ts +100 -0
  44. package/src/runtime/store/FilesSdk.ts +120 -65
  45. package/src/runtime/store/HistorySdk.ts +42 -17
  46. package/src/runtime/store/Sdk.ts +5 -0
  47. package/src/runtime/store/SdkBase.ts +63 -9
  48. package/src/runtime/store/SharedSdk.ts +26 -9
  49. package/src/runtime/store/StoreSdkWeb.ts +1 -1
  50. package/src/runtime/store/UsersSdk.ts +14 -8
  51. package/json8-patch.d.ts +0 -270
@@ -1,11 +1,15 @@
1
- import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN } from './SdkBase.js';
1
+ import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, ISdkRequestOptions } from './SdkBase.js';
2
2
  import { RouteBuilder } from './RouteBuilder.js';
3
3
  import { IListOptions, IListResponse } from '../../models/Backend.js';
4
4
  import { IUser } from '../../models/store/User.js';
5
5
 
6
6
  export class UsersSdk extends SdkBase {
7
- async me(): Promise<IUser> {
8
- const { token } = this.sdk;
7
+ /**
8
+ * Reads the current user.
9
+ * @param request Optional request options.
10
+ */
11
+ async me(request: ISdkRequestOptions = {}): Promise<IUser> {
12
+ const token = request.token || this.sdk.token;
9
13
  const url = this.sdk.getUrl(RouteBuilder.usersMe());
10
14
  const result = await this.sdk.http.get(url.toString(), { token });
11
15
  this.inspectCommonStatusCodes(result.status);
@@ -33,9 +37,10 @@ export class UsersSdk extends SdkBase {
33
37
  * Lists users in the store
34
38
  *
35
39
  * @param options Optional query options.
40
+ * @param request Optional request options.
36
41
  */
37
- async list(options?: IListOptions): Promise<IListResponse> {
38
- const { token } = this.sdk;
42
+ async list(options?: IListOptions, request: ISdkRequestOptions = {}): Promise<IListResponse<IUser>> {
43
+ const token = request.token || this.sdk.token;
39
44
  const url = this.sdk.getUrl(RouteBuilder.users());
40
45
  this.sdk.appendListOptions(url, options);
41
46
  const result = await this.sdk.http.get(url.toString(), { token });
@@ -48,7 +53,7 @@ export class UsersSdk extends SdkBase {
48
53
  if (!result.body) {
49
54
  throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
50
55
  }
51
- let data: IListResponse;
56
+ let data: IListResponse<IUser>;
52
57
  try {
53
58
  data = JSON.parse(result.body);
54
59
  } catch (e) {
@@ -63,10 +68,11 @@ export class UsersSdk extends SdkBase {
63
68
  /**
64
69
  * Reads a user information from the store.
65
70
  * @param key The user key.
71
+ * @param request Optional request options.
66
72
  * @returns The user object
67
73
  */
68
- async read(key: string): Promise<IUser> {
69
- const { token } = this.sdk;
74
+ async read(key: string, request: ISdkRequestOptions = {}): Promise<IUser> {
75
+ const token = request.token || this.sdk.token;
70
76
  const url = this.sdk.getUrl(RouteBuilder.user(key));
71
77
  const result = await this.sdk.http.get(url.toString(), { token });
72
78
  this.inspectCommonStatusCodes(result.status);
package/json8-patch.d.ts DELETED
@@ -1,270 +0,0 @@
1
- declare module "json8-patch" {
2
- export interface BaseOperation {
3
- path: string;
4
- }
5
-
6
- export interface AddOperation extends BaseOperation {
7
- op: "add";
8
- value: any;
9
- }
10
-
11
- export interface RemoveOperation extends BaseOperation {
12
- op: "remove";
13
- }
14
-
15
- /**
16
- * The JSON patch replace operation
17
- */
18
- export interface ReplaceOperation extends BaseOperation {
19
- op: "replace";
20
- value: any;
21
- }
22
-
23
- /**
24
- * The JSON patch move operation
25
- */
26
- export interface MoveOperation extends BaseOperation {
27
- op: "move";
28
- from: any;
29
- }
30
-
31
- /**
32
- * The JSON patch copy operation.
33
- */
34
- export interface CopyOperation extends BaseOperation {
35
- op: "copy";
36
- from: any;
37
- }
38
-
39
- /**
40
- * The JSON patch test operation
41
- */
42
- export interface TestOperation extends BaseOperation {
43
- op: "test";
44
- value: any;
45
- }
46
-
47
- /**
48
- * All possible JSON patch operations
49
- */
50
- export type JsonPatchOperation = AddOperation | RemoveOperation | ReplaceOperation | MoveOperation | CopyOperation | TestOperation;
51
-
52
- /**
53
- * A JSON patch as specified in RFC 6902
54
- */
55
- export type JsonPatch = JsonPatchOperation[];
56
-
57
- export interface ApplyResult<T> {
58
- doc: T;
59
- }
60
-
61
- export interface ApplyResultWithRevert<T> extends ApplyResult<T> {
62
- revert: JsonPatch;
63
- }
64
-
65
- export type PatchResult<T> = ApplyResult<T>;
66
- export type PatchResultWithRevert<T> = ApplyResultWithRevert<T>;
67
-
68
- /**
69
- * The operation is atomic, if any of the patch operation fails, the document will be restored to its original state and an error will be thrown.
70
- * @param doc The document to apply the patch operation to
71
- * @param patch The patch operations
72
- * @param options With `{reversible: false}` it will not return an additional value in the form of a `revert` property.
73
- * @returns An object with a doc property because per specification a patch can replace the original root document.
74
- */
75
- export function apply<T>(doc: T, patch: JsonPatch, options?: { reversible: false }): ApplyResult<T>;
76
- /**
77
- * The operation is atomic, if any of the patch operation fails, the document will be restored to its original state and an error will be thrown.
78
- * @param doc The document to apply the patch operation to
79
- * @param patch The patch operations
80
- * @param options With `{reversible: true}` it will return an additional value in the form of a `revert` property.
81
- * @returns An object with a doc property because per specification a patch can replace the original root document.
82
- */
83
- export function apply<T>(doc: T, patch: JsonPatch, options?: { reversible: true }): ApplyResultWithRevert<T>;
84
- /**
85
- * Alias for the `apply()` method.
86
- */
87
- export function patch<T>(doc: T, patch: JsonPatch, options?: { reversible: false }): PatchResult<T>;
88
- /**
89
- * Alias for the `apply()` method.
90
- */
91
- export function patch<T>(doc: T, patch: JsonPatch, options?: { reversible: true }): PatchResultWithRevert<T>;
92
- /**
93
- * ```javascript
94
- * ooPatch.diff(true, false);
95
- * // [{"op": "replace", "path": "", "value": "false"}]
96
- *
97
- * ooPatch.diff([], []);
98
- * // []
99
- *
100
- * ooPatch.diff({}, { foo: "bar" });
101
- * // [{"op": "add", "path": "/foo", "value": "bar"}]
102
- * ```
103
- *
104
- * @returns A diff in the form of a JSON Patch for 2 JSON values.
105
- */
106
- export function diff(doc1: unknown, doc2: unknown): JsonPatch;
107
- /**
108
- * If the patch or apply method is called with a third argument `{reversible: true}` it will return an additional value in the form of a revert property.
109
- *
110
- * The revert object can be used to revert a patch on a document.
111
- *
112
- * ```javascript
113
- * // apply the patch with the reversible option
114
- * var applyResult = ooPatch.apply(doc, patch, { reversible: true });
115
- * doc = applyResult.doc;
116
- *
117
- * // revert the patch
118
- * doc = ooPatch.revert(doc, applyResult.revert).doc;
119
- * // doc is strictly identical to the original
120
- * ```
121
- *
122
- * See also the `buildRevertPatch()` function which offers more flexibility.
123
- */
124
- export function revert<T>(doc: T, revertPatch: JsonPatch): ApplyResult<T>;
125
- /**
126
- * This method only check for JSON Patch semantic.
127
- *
128
- * ```javascript
129
- * ooPatch.valid({}) // false
130
- * ooPatch.valid([{}] // false
131
- * ooPatch.valid([{op: "foo", path: null, value: undefined}]) // false
132
- * ooPatch.valid([{op: "add", path: "/foo"}]) // false
133
- *
134
- * ooPatch.valid([]) // true
135
- * ooPatch.valid([{op: "add", path: "/foo", value: "bar"}]) // true
136
- * ```
137
- *
138
- * @returns `true` if the patch is valid, `false` otherwise.
139
- */
140
- export function valid(patch: JsonPatch): boolean;
141
- /**
142
- * Builds a valid JSON Patch from the result of a reversible `apply` operation.
143
- * You can then use this patch with `apply()` method to revert a previously applied patch.
144
- *
145
- * Because `buildRevertPatch` + `apply` offers more flexibility over `revert` it is preferred.
146
- *
147
- * - use pack/unpack with the result of `buildRevertPatch` making it ideal for storage or transport
148
- * - reverse a revert (and so on...) with `{reversible: true}`
149
- * - `diff` between reverts
150
- * - merge multiple reverts into one
151
- * - rebase reverts
152
- *
153
- * @param revert The revert value from the `apply()` or `patch()` method with `{reversible: true}`
154
- * @returns JSON Patch
155
- */
156
- export function buildRevertPatch(revert: JsonPatch): JsonPatch;
157
-
158
- export interface OperationResult<T> {
159
- /**
160
- * The patched document
161
- */
162
- doc: T;
163
- /**
164
- * The previous/replaced value if any
165
- */
166
- previous?: T;
167
- idx?: number;
168
- }
169
-
170
- /**
171
- * Add the value to the specified JSON Pointer location.
172
- * @param doc JSON document to set the value to
173
- * @param path JSON Pointer string or tokens path
174
- * @param value The value to add
175
- */
176
- export function add<T>(doc: T, path: string | string[], value: unknown): OperationResult<T>;
177
- /**
178
- * Copy the value at the specified JSON Pointer location to another location.
179
- *
180
- * @param doc JSON document to copy the value from and to
181
- * @param path JSON Pointer string or tokens path
182
- * @param dest JSON Pointer string destination of the value
183
- */
184
- export function copy<T>(doc: T, path: string | string[], dest: string): OperationResult<T>;
185
- /**
186
- * Moves the value at the specified JSON Pointer location to another location.
187
- *
188
- * @param doc JSON document to move the value from and to
189
- * @param path JSON Pointer string or tokens path
190
- * @param dest JSON Pointer string destination of the value
191
- */
192
- export function move<T>(doc: T, path: string | string[], dest: string): OperationResult<T>;
193
- /**
194
- * Removes the value at the JSON Pointer location.
195
- *
196
- * @param doc JSON document to search into
197
- * @param path JSON Pointer string or tokens patch
198
- */
199
- export function remove<T>(doc: T, path: string | string[]): OperationResult<T>;
200
- /**
201
- * Replaces the value at the JSON Pointer location
202
- *
203
- * @param doc JSON document
204
- * @param path JSON Pointer string or tokens patch
205
- * @param value JSON object to replace with
206
- */
207
- export function replace<T>(doc: T, path: string | string[], value: unknown): OperationResult<T>;
208
- /**
209
- * Tests that the value at the specified JSON Pointer location is equal to the specified value.
210
- *
211
- * @param doc JSON document
212
- * @param path JSON Pointer string or tokens patch
213
- * @param value The value to compare with
214
- */
215
- export function test<T>(doc: T, path: string | string[], value: unknown): OperationResult<T>;
216
- /**
217
- * Get the value at the JSON Pointer location.
218
- *
219
- * @param doc JSON document
220
- * @param path JSON Pointer string or tokens patch
221
- * @returns The value at the JSON Pointer location
222
- */
223
- export function get(doc: unknown, path: string | string[]): unknown;
224
- /**
225
- * Checks if the document has the property at the specified JSON Pointer location.
226
- *
227
- * @param doc JSON document
228
- * @param path JSON Pointer string or tokens path
229
- */
230
- export function has(doc: unknown, path: string | string[]): boolean;
231
- /**
232
- * Per specification patches are pretty verbose. JSON8 provides the `pack()` and the `unpack()` methods
233
- * to reduce the size of patches and save memory / space / bandwidth.
234
- *
235
- * ```javascript
236
- * var patch = [
237
- * { op: "add", path: "/a/b/c", value: ["foo", "bar"] },
238
- * { op: "remove", path: "/a/b/c" },
239
- * { op: "replace", path: "/a/b/c", value: 42 },
240
- * { op: "move", from: "/a/b/c", path: "/a/b/d" },
241
- * { op: "copy", from: "/a/b/c", path: "/a/b/e" },
242
- * { op: "test", path: "/a/b/c", value: "foo" },
243
- * ];
244
- *
245
- * var packed = ooPatch.pack(patch);
246
- *
247
- * // [
248
- * // [0, "/a/b/c", ["foo", "bar"]],
249
- * // [1, "/a/b/c"],
250
- * // [2, "/a/b/c", 42],
251
- * // [3, "/a/b/d", "/a/b/c"],
252
- * // [4, "/a/b/e", "/a/b/c"],
253
- * // [5, "/a/b/c", "foo"]
254
- * // ]
255
- * ```
256
- */
257
- export function pack(patch: JsonPatch): any[];
258
- /**
259
- * Reverses the `pack()` on a patch.
260
- *
261
- * @param packed Previously packed values.
262
- * @returns Restored patch value.
263
- */
264
- export function unpack(packed: any[]): JsonPatch;
265
- /**
266
- * Concatenates multiple patches into one.
267
- */
268
- export function concat(...patches: JsonPatch): JsonPatch;
269
-
270
- }