@cubicweb/client 1.6.0 → 1.8.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/lib/Errors.d.ts +3 -0
- package/lib/Errors.d.ts.map +1 -1
- package/lib/Errors.js +8 -1
- package/lib/Errors.js.map +1 -1
- package/lib/api/Api.d.ts +21 -5
- package/lib/api/Api.d.ts.map +1 -1
- package/lib/api/Api.js +104 -60
- package/lib/api/Api.js.map +1 -1
- package/lib/api/Client.d.ts +10 -2
- package/lib/api/Client.d.ts.map +1 -1
- package/lib/api/Client.js +22 -1
- package/lib/api/Client.js.map +1 -1
- package/lib/schema/classes/Utils.d.ts +2 -2
- package/lib/schema/classes/Utils.d.ts.map +1 -1
- package/lib/schema/raw/Constraints.d.ts +14 -14
- package/lib/schema/raw/Constraints.d.ts.map +1 -1
- package/lib/schema/raw/Entities.d.ts +2 -2
- package/lib/schema/raw/Entities.d.ts.map +1 -1
- package/lib/schema/raw/RelationDefinitions.d.ts +8 -8
- package/lib/schema/raw/RelationDefinitions.d.ts.map +1 -1
- package/lib/schema/raw/Schema.d.ts +1 -1
- package/lib/schema/raw/Schema.d.ts.map +1 -1
- package/lib/schema/raw/Utils.d.ts +3 -3
- package/lib/schema/raw/Utils.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/Errors.ts +7 -0
- package/src/api/Api.ts +124 -84
- package/src/api/Client.ts +23 -3
package/lib/Errors.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export declare class InconsistentSchemaError extends Error {
|
|
2
2
|
constructor(message: string);
|
|
3
3
|
}
|
|
4
|
+
export declare class ValidationError extends Error {
|
|
5
|
+
constructor(message: string);
|
|
6
|
+
}
|
|
4
7
|
export declare class TransactionClosedError extends Error {
|
|
5
8
|
constructor();
|
|
6
9
|
}
|
package/lib/Errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Errors.d.ts","sourceRoot":"","sources":["../src/Errors.ts"],"names":[],"mappings":"AAAA,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,sBAAuB,SAAQ,KAAK;;CAKhD"}
|
|
1
|
+
{"version":3,"file":"Errors.d.ts","sourceRoot":"","sources":["../src/Errors.ts"],"names":[],"mappings":"AAAA,qBAAa,uBAAwB,SAAQ,KAAK;gBACpC,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,sBAAuB,SAAQ,KAAK;;CAKhD"}
|
package/lib/Errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TransactionClosedError = exports.InconsistentSchemaError = void 0;
|
|
3
|
+
exports.TransactionClosedError = exports.ValidationError = exports.InconsistentSchemaError = void 0;
|
|
4
4
|
class InconsistentSchemaError extends Error {
|
|
5
5
|
constructor(message) {
|
|
6
6
|
super(`Inconsistent schema: ${message}`);
|
|
@@ -8,6 +8,13 @@ class InconsistentSchemaError extends Error {
|
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
exports.InconsistentSchemaError = InconsistentSchemaError;
|
|
11
|
+
class ValidationError extends Error {
|
|
12
|
+
constructor(message) {
|
|
13
|
+
super(message);
|
|
14
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.ValidationError = ValidationError;
|
|
11
18
|
class TransactionClosedError extends Error {
|
|
12
19
|
constructor() {
|
|
13
20
|
super("Trying to use a closed transaction");
|
package/lib/Errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Errors.js","sourceRoot":"","sources":["../src/Errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,uBAAwB,SAAQ,KAAK;IAChD,YAAY,OAAe;QACzB,KAAK,CAAC,wBAAwB,OAAO,EAAE,CAAC,CAAC;QACzC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AALD,0DAKC;AAED,MAAa,sBAAuB,SAAQ,KAAK;IAC/C;QACE,KAAK,CAAC,oCAAoC,CAAC,CAAC;QAC5C,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AALD,wDAKC"}
|
|
1
|
+
{"version":3,"file":"Errors.js","sourceRoot":"","sources":["../src/Errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,uBAAwB,SAAQ,KAAK;IAChD,YAAY,OAAe;QACzB,KAAK,CAAC,wBAAwB,OAAO,EAAE,CAAC,CAAC;QACzC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AALD,0DAKC;AAED,MAAa,eAAgB,SAAQ,KAAK;IACxC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AALD,0CAKC;AAED,MAAa,sBAAuB,SAAQ,KAAK;IAC/C;QACE,KAAK,CAAC,oCAAoC,CAAC,CAAC;QAC5C,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,CAAC;CACF;AALD,wDAKC"}
|
package/lib/api/Api.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { RawSchema } from "../schema/raw/Schema";
|
|
|
2
2
|
/**
|
|
3
3
|
* Type representing an RQL request and its associated parameters.
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export type RQLQuery = [string, RQLParams];
|
|
6
6
|
/**
|
|
7
7
|
* Type representing RQL parameters to send along a request.
|
|
8
8
|
*/
|
|
@@ -12,15 +12,23 @@ export interface RQLParams {
|
|
|
12
12
|
/**
|
|
13
13
|
* Type representing a row returned in a result set.
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export type RqlRow = Array<string | number | boolean | null>;
|
|
16
16
|
/**
|
|
17
17
|
* Type representing a RQL request result.
|
|
18
18
|
*/
|
|
19
|
-
export
|
|
19
|
+
export type ResultSet = Array<RqlRow>;
|
|
20
|
+
/**
|
|
21
|
+
* Type representing the currently logged user's data
|
|
22
|
+
*/
|
|
23
|
+
export interface CurrentUser {
|
|
24
|
+
login: string;
|
|
25
|
+
eid: number;
|
|
26
|
+
dcTitle: string;
|
|
27
|
+
}
|
|
20
28
|
/**
|
|
21
29
|
* Type representing the body of an error sent by CubicWeb's API.
|
|
22
30
|
*/
|
|
23
|
-
|
|
31
|
+
type ApiError = {
|
|
24
32
|
title: string;
|
|
25
33
|
message: string;
|
|
26
34
|
data?: Record<string, unknown>;
|
|
@@ -28,7 +36,7 @@ declare type ApiError = {
|
|
|
28
36
|
/**
|
|
29
37
|
* Type representing the error data sent to clients when retrieving an API error.
|
|
30
38
|
*/
|
|
31
|
-
export
|
|
39
|
+
export type ApiErrorResponse = {
|
|
32
40
|
status: number;
|
|
33
41
|
} & ApiError;
|
|
34
42
|
/**
|
|
@@ -45,6 +53,7 @@ export default class Api {
|
|
|
45
53
|
private _rqlApiUrl;
|
|
46
54
|
private _schemaApiUrl;
|
|
47
55
|
private _loginApiUrl;
|
|
56
|
+
private _currentUserApiUrl;
|
|
48
57
|
private _transactionApiUrl;
|
|
49
58
|
/**
|
|
50
59
|
* Class used to handle requests to the CubicWeb API.
|
|
@@ -81,6 +90,12 @@ export default class Api {
|
|
|
81
90
|
* @returns A promise returning true if the login was successful, false otherwise
|
|
82
91
|
*/
|
|
83
92
|
login(login: string, password: string): Promise<boolean>;
|
|
93
|
+
/**
|
|
94
|
+
* Get the current user associated to this client
|
|
95
|
+
*
|
|
96
|
+
* @returns A promise resolving to the current user
|
|
97
|
+
*/
|
|
98
|
+
currentUser(): Promise<CurrentUser>;
|
|
84
99
|
/**
|
|
85
100
|
* Starts a new transaction.
|
|
86
101
|
*
|
|
@@ -108,6 +123,7 @@ export default class Api {
|
|
|
108
123
|
* @param uuid The transaction's uuid
|
|
109
124
|
*/
|
|
110
125
|
transactionRollback(uuid: string): Promise<null>;
|
|
126
|
+
private handleUserErrors;
|
|
111
127
|
}
|
|
112
128
|
export {};
|
|
113
129
|
//# sourceMappingURL=Api.d.ts.map
|
package/lib/api/Api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Api.d.ts","sourceRoot":"","sources":["../../src/api/Api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Api.d.ts","sourceRoot":"","sources":["../../src/api/Api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,CAAC;AAE7D;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,KAAK,QAAQ,GAAG;IACd,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAA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M,GAAG,OAAO,CAAC,IAAI,CAAC;IAQtD,OAAO,CAAC,gBAAgB;CAgBzB"}
|
package/lib/api/Api.js
CHANGED
|
@@ -9,6 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const Errors_1 = require("../Errors");
|
|
12
13
|
/**
|
|
13
14
|
* Class used to handle requests to the CubicWeb API.
|
|
14
15
|
*
|
|
@@ -40,6 +41,7 @@ class Api {
|
|
|
40
41
|
this._rqlApiUrl = this.getApiRoute("rql");
|
|
41
42
|
this._schemaApiUrl = this.getApiRoute("schema");
|
|
42
43
|
this._loginApiUrl = this.getApiRoute("login");
|
|
44
|
+
this._currentUserApiUrl = this.getApiRoute("current-user");
|
|
43
45
|
Object.keys(this._transactionApiUrl).forEach((k) => (this._transactionApiUrl[k] =
|
|
44
46
|
this.getApiRoute(`transaction/${k}`)));
|
|
45
47
|
}
|
|
@@ -58,11 +60,16 @@ class Api {
|
|
|
58
60
|
*/
|
|
59
61
|
execute(query, params) {
|
|
60
62
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
try {
|
|
64
|
+
return yield nonNullFetchApi(this._rqlApiUrl, {
|
|
65
|
+
method: "POST",
|
|
66
|
+
body: JSON.stringify({ query, params }),
|
|
67
|
+
credentials: "include", // FIXME is it secure?
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
this.handleUserErrors(e);
|
|
72
|
+
}
|
|
66
73
|
});
|
|
67
74
|
}
|
|
68
75
|
/**
|
|
@@ -87,16 +94,33 @@ class Api {
|
|
|
87
94
|
*/
|
|
88
95
|
login(login, password) {
|
|
89
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
97
|
+
try {
|
|
98
|
+
yield fetchApi(this._loginApiUrl, {
|
|
99
|
+
method: "POST",
|
|
100
|
+
body: JSON.stringify({
|
|
101
|
+
login,
|
|
102
|
+
password,
|
|
103
|
+
}),
|
|
104
|
+
credentials: "include",
|
|
105
|
+
});
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
catch (_error) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Get the current user associated to this client
|
|
115
|
+
*
|
|
116
|
+
* @returns A promise resolving to the current user
|
|
117
|
+
*/
|
|
118
|
+
currentUser() {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
return yield nonNullFetchApi(this._currentUserApiUrl, {
|
|
121
|
+
method: "GET",
|
|
96
122
|
credentials: "include",
|
|
97
|
-
})
|
|
98
|
-
.then(() => true)
|
|
99
|
-
.catch(() => false);
|
|
123
|
+
});
|
|
100
124
|
});
|
|
101
125
|
}
|
|
102
126
|
/**
|
|
@@ -122,11 +146,16 @@ class Api {
|
|
|
122
146
|
*/
|
|
123
147
|
transactionExecute(uuid, query, params) {
|
|
124
148
|
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
149
|
+
try {
|
|
150
|
+
return yield fetchApi(this._transactionApiUrl.execute, {
|
|
151
|
+
method: "POST",
|
|
152
|
+
body: JSON.stringify({ uuid, query, params }),
|
|
153
|
+
credentials: "include",
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
catch (e) {
|
|
157
|
+
this.handleUserErrors(e);
|
|
158
|
+
}
|
|
130
159
|
});
|
|
131
160
|
}
|
|
132
161
|
/**
|
|
@@ -136,11 +165,16 @@ class Api {
|
|
|
136
165
|
*/
|
|
137
166
|
transactionCommit(uuid) {
|
|
138
167
|
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
168
|
+
try {
|
|
169
|
+
return yield fetchApi(this._transactionApiUrl.commit, {
|
|
170
|
+
method: "POST",
|
|
171
|
+
body: JSON.stringify({ uuid }),
|
|
172
|
+
credentials: "include",
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
catch (e) {
|
|
176
|
+
this.handleUserErrors(e);
|
|
177
|
+
}
|
|
144
178
|
});
|
|
145
179
|
}
|
|
146
180
|
/**
|
|
@@ -157,6 +191,20 @@ class Api {
|
|
|
157
191
|
});
|
|
158
192
|
});
|
|
159
193
|
}
|
|
194
|
+
handleUserErrors(error) {
|
|
195
|
+
if (typeof error === "object" &&
|
|
196
|
+
error !== null &&
|
|
197
|
+
"title" in error &&
|
|
198
|
+
typeof error.title === "string" &&
|
|
199
|
+
"message" in error &&
|
|
200
|
+
typeof error.message === "string") {
|
|
201
|
+
if (error.title === "ValidationError") {
|
|
202
|
+
throw new Errors_1.ValidationError(error.message);
|
|
203
|
+
}
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
206
|
+
throw error;
|
|
207
|
+
}
|
|
160
208
|
}
|
|
161
209
|
exports.default = Api;
|
|
162
210
|
/**
|
|
@@ -168,23 +216,20 @@ exports.default = Api;
|
|
|
168
216
|
* @param init Additional request parameters
|
|
169
217
|
* @returns A promise with the non-null fetched result
|
|
170
218
|
*/
|
|
171
|
-
|
|
172
|
-
return
|
|
173
|
-
|
|
174
|
-
if (
|
|
219
|
+
function nonNullFetchApi(input, init) {
|
|
220
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
221
|
+
const result = yield fetchApi(input, init);
|
|
222
|
+
if (result == null) {
|
|
175
223
|
const error = {
|
|
176
224
|
status: 500,
|
|
177
225
|
title: "Unexpected null response",
|
|
178
226
|
message: "Response was null but a value was expected",
|
|
179
227
|
};
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
else {
|
|
183
|
-
resolve(v);
|
|
228
|
+
throw error;
|
|
184
229
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
230
|
+
return result;
|
|
231
|
+
});
|
|
232
|
+
}
|
|
188
233
|
/**
|
|
189
234
|
* Sends a request to the given API route with the `Content-Type` header set and waits for a response.
|
|
190
235
|
* The returned promise will be rejected if the API returns HTTP error codes.
|
|
@@ -194,38 +239,37 @@ const nonNullFetchApi = (input, init) => {
|
|
|
194
239
|
* @param init Additional request parameters
|
|
195
240
|
* @returns A promise with the fetched result
|
|
196
241
|
*/
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
242
|
+
function fetchApi(input, init) {
|
|
243
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
244
|
+
let headers = init === null || init === void 0 ? void 0 : init.headers;
|
|
245
|
+
if ((init === null || init === void 0 ? void 0 : init.method) && init.method !== "GET" && init.method !== "DELETE") {
|
|
246
|
+
headers = Object.assign({ "Content-Type": "application/json;charset=UTF-8" }, init === null || init === void 0 ? void 0 : init.headers);
|
|
247
|
+
}
|
|
248
|
+
const response = yield fetch(input, Object.assign(Object.assign({}, init), { headers }));
|
|
203
249
|
const status = response.status;
|
|
204
250
|
if (status >= 200 && status < 300) {
|
|
205
251
|
if (status === 204) {
|
|
206
|
-
|
|
252
|
+
return null;
|
|
207
253
|
}
|
|
208
|
-
|
|
209
|
-
response
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
resolve(null);
|
|
215
|
-
});
|
|
254
|
+
try {
|
|
255
|
+
return yield response.json();
|
|
256
|
+
}
|
|
257
|
+
catch (e) {
|
|
258
|
+
console.error(e);
|
|
259
|
+
return null;
|
|
216
260
|
}
|
|
217
261
|
}
|
|
218
262
|
else {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
.
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
.catch((e) => {
|
|
263
|
+
let json;
|
|
264
|
+
try {
|
|
265
|
+
json = yield response.json();
|
|
266
|
+
}
|
|
267
|
+
catch (e) {
|
|
225
268
|
console.error(e);
|
|
226
|
-
|
|
227
|
-
}
|
|
269
|
+
throw { status, title: "Error", message: "" };
|
|
270
|
+
}
|
|
271
|
+
throw Object.assign({ status }, json);
|
|
228
272
|
}
|
|
229
|
-
})
|
|
230
|
-
}
|
|
273
|
+
});
|
|
274
|
+
}
|
|
231
275
|
//# sourceMappingURL=Api.js.map
|
package/lib/api/Api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Api.js","sourceRoot":"","sources":["../../src/api/Api.ts"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"Api.js","sourceRoot":"","sources":["../../src/api/Api.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sCAA4C;AAkD5C;;;;;;;GAOG;AACH,MAAqB,GAAG;IActB;;;;;;;;;OASG;IACH,YAAY,MAAc;QAtBlB,aAAQ,GAAG,IAAI,CAAC;QAKhB,uBAAkB,GAAG;YAC3B,KAAK,EAAE,EAAE;YACT,OAAO,EAAE,EAAE;YACX,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE,EAAE;SACb,CAAC;QAaA,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC1C,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAChD,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAC9C,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC;QAC3D,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,OAAO,CAC1C,CAAC,CAAC,EA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,EAAE;YACrE,OAAO,mBACL,cAAc,EAAE,gCAAgC,IAC7C,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,CACjB,CAAC;SACH;QAED,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,KAAK,kCAC7B,IAAI,KACP,OAAO,IACP,CAAC;QACH,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;QAC/B,IAAI,MAAM,IAAI,GAAG,IAAI,MAAM,GAAG,GAAG,EAAE;YACjC,IAAI,MAAM,KAAK,GAAG,EAAE;gBAClB,OAAO,IAAI,CAAC;aACb;YACD,IAAI;gBACF,OAAO,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;aAC9B;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBACjB,OAAO,IAAI,CAAC;aACb;SACF;aAAM;YACL,IAAI,IAAI,CAAC;YACT,IAAI;gBACF,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;aAC9B;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBACjB,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;aAC/C;YACD,sBAAQ,MAAM,IAAK,IAAI,EAAG;SAC3B;IACH,CAAC;CAAA"}
|
package/lib/api/Client.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema } from "../schema/classes/Schema";
|
|
2
|
-
import { RQLParams } from "./Api";
|
|
2
|
+
import { RQLParams, ResultSet, CurrentUser } from "./Api";
|
|
3
3
|
import Transaction from "./Transaction";
|
|
4
4
|
/**
|
|
5
5
|
* Class used to communicate with a CubicWeb instance's API.
|
|
@@ -22,7 +22,7 @@ export default class Client {
|
|
|
22
22
|
* @param params The additional parameters for the request
|
|
23
23
|
* @returns A promise with the request's result set
|
|
24
24
|
*/
|
|
25
|
-
execute(query: string, params?: RQLParams): Promise<
|
|
25
|
+
execute(query: string, params?: RQLParams): Promise<ResultSet>;
|
|
26
26
|
/**
|
|
27
27
|
* Retrieves the CubicWeb instance's JSON schema.
|
|
28
28
|
*
|
|
@@ -37,10 +37,18 @@ export default class Client {
|
|
|
37
37
|
* @returns A promise returning true if the login was successful, false otherwise
|
|
38
38
|
*/
|
|
39
39
|
login(login: string, password: string): Promise<boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* Get the user associated to this client
|
|
42
|
+
*
|
|
43
|
+
* @returns A promise resolving to the current user
|
|
44
|
+
*/
|
|
45
|
+
currentUser(): Promise<CurrentUser>;
|
|
40
46
|
/**
|
|
41
47
|
* Creates a new transaction and exposes the Transaction object in the given callback.
|
|
42
48
|
* Use this callback to execute RQL requests as part of the transaction.
|
|
43
49
|
* Once the callback's end is reached, the transaction is automatically committed.
|
|
50
|
+
* Note that any exception thrown by the callback will lead to the
|
|
51
|
+
* transaction being rolled back.
|
|
44
52
|
*
|
|
45
53
|
* @param callback Function to execute transaction requests in.
|
|
46
54
|
* @returns The promise returned by the callback
|
package/lib/api/Client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Client.d.ts","sourceRoot":"","sources":["../../src/api/Client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Client.d.ts","sourceRoot":"","sources":["../../src/api/Client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAY,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAC/D,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,OAAO,CAAC,GAAG,CAAM;IAEjB;;;;;;OAMG;gBACS,MAAM,EAAE,MAAM;IAI1B,IAAI,MAAM,WAET;IAED;;;;;;OAMG;IACG,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,SAAc,GAAG,OAAO,CAAC,SAAS,CAAC;IAIxE;;;;OAIG;IACG,MAAM;IAKZ;;;;;;OAMG;IACG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAI3C;;;;OAIG;IACG,WAAW,IAAI,OAAO,CAAC,WAAW,CAAC;IAIzC;;;;;;;;;OASG;IACG,WAAW,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAkB5E"}
|
package/lib/api/Client.js
CHANGED
|
@@ -67,10 +67,22 @@ class Client {
|
|
|
67
67
|
return yield this.api.login(login, password);
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Get the user associated to this client
|
|
72
|
+
*
|
|
73
|
+
* @returns A promise resolving to the current user
|
|
74
|
+
*/
|
|
75
|
+
currentUser() {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
return yield this.api.currentUser();
|
|
78
|
+
});
|
|
79
|
+
}
|
|
70
80
|
/**
|
|
71
81
|
* Creates a new transaction and exposes the Transaction object in the given callback.
|
|
72
82
|
* Use this callback to execute RQL requests as part of the transaction.
|
|
73
83
|
* Once the callback's end is reached, the transaction is automatically committed.
|
|
84
|
+
* Note that any exception thrown by the callback will lead to the
|
|
85
|
+
* transaction being rolled back.
|
|
74
86
|
*
|
|
75
87
|
* @param callback Function to execute transaction requests in.
|
|
76
88
|
* @returns The promise returned by the callback
|
|
@@ -79,7 +91,16 @@ class Client {
|
|
|
79
91
|
return __awaiter(this, void 0, void 0, function* () {
|
|
80
92
|
const transaction = new Transaction_1.default(this.api);
|
|
81
93
|
yield transaction.begin();
|
|
82
|
-
|
|
94
|
+
let result;
|
|
95
|
+
try {
|
|
96
|
+
result = yield callback(transaction);
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
if (!transaction.isClosed()) {
|
|
100
|
+
yield transaction.rollback();
|
|
101
|
+
}
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
83
104
|
if (!transaction.isClosed()) {
|
|
84
105
|
yield transaction.commit();
|
|
85
106
|
}
|
package/lib/api/Client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Client.js","sourceRoot":"","sources":["../../src/api/Client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,qDAAkD;AAClD,
|
|
1
|
+
{"version":3,"file":"Client.js","sourceRoot":"","sources":["../../src/api/Client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,qDAAkD;AAClD,gDAA+D;AAC/D,gEAAwC;AAExC;;GAEG;AACH,MAAqB,MAAM;IAGzB;;;;;;OAMG;IACH,YAAY,MAAc;QACxB,IAAI,CAAC,GAAG,GAAG,IAAI,aAAG,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;IACzB,CAAC;IAED;;;;;;OAMG;IACG,OAAO,CAAC,KAAa,EAAE,SAAoB,EAAE;;YACjD,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC/C,CAAC;KAAA;IAED;;;;OAIG;IACG,MAAM;;YACV,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;YACvC,OAAO,IAAI,eAAM,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;KAAA;IAED;;;;;;OAMG;IACG,KAAK,CAAC,KAAa,EAAE,QAAgB;;YACzC,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC/C,CAAC;KAAA;IAED;;;;OAIG;IACG,WAAW;;YACf,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;QACtC,CAAC;KAAA;IAED;;;;;;;;;OASG;IACG,WAAW,CAAI,QAAyC;;YAC5D,MAAM,WAAW,GAAG,IAAI,qBAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC9C,MAAM,WAAW,CAAC,KAAK,EAAE,CAAC;YAE1B,IAAI,MAAS,CAAC;YACd,IAAI;gBACF,MAAM,GAAG,MAAM,QAAQ,CAAC,WAAW,CAAC,CAAC;aACtC;YAAC,OAAO,KAAK,EAAE;gBACd,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,EAAE;oBAC3B,MAAM,WAAW,CAAC,QAAQ,EAAE,CAAC;iBAC9B;gBACD,MAAM,KAAK,CAAC;aACb;YACD,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,EAAE;gBAC3B,MAAM,WAAW,CAAC,MAAM,EAAE,CAAC;aAC5B;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;CACF;AAvFD,yBAuFC"}
|
|
@@ -19,12 +19,12 @@ export declare function cardinalityRequired(cardinality: Cardinality): boolean;
|
|
|
19
19
|
/**
|
|
20
20
|
* Partial raw relation definition schema type.
|
|
21
21
|
*/
|
|
22
|
-
export
|
|
22
|
+
export type RelationDefinitionMatcher<E extends EntityRawSchemaArray> = Partial<RelationDefinitionRawSchema<E>>;
|
|
23
23
|
/**
|
|
24
24
|
* Type representing a raw relation definition matched from a partial raw relation definition schema.
|
|
25
25
|
* If it finds a relation definition matching the partial one given, it will return its type.
|
|
26
26
|
* If it cannot find any relation definition matching, it will return the `never` type
|
|
27
27
|
* and TypeScript will give compile errors.
|
|
28
28
|
*/
|
|
29
|
-
export
|
|
29
|
+
export type MatchedRelationDefinition<E extends EntityRawSchemaArray, R extends RelationDefinitionRawSchemaArray<EntityRawSchemaArray>, M extends RelationDefinitionMatcher<E>> = R[number] extends infer RDef ? (RDef extends M ? RDef : never) : never;
|
|
30
30
|
//# sourceMappingURL=Utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../../src/schema/classes/Utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EACL,WAAW,EACX,2BAA2B,EAC3B,gCAAgC,EACjC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,4PAO1B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAErE;AAED;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../../src/schema/classes/Utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EACL,WAAW,EACX,2BAA2B,EAC3B,gCAAgC,EACjC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,4PAO1B,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAErE;AAED;;GAEG;AACH,MAAM,MAAM,yBAAyB,CAAC,CAAC,SAAS,oBAAoB,IAAI,OAAO,CAC7E,2BAA2B,CAAC,CAAC,CAAC,CAC/B,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,yBAAyB,CACnC,CAAC,SAAS,oBAAoB,EAC9B,CAAC,SAAS,gCAAgC,CAAC,oBAAoB,CAAC,EAChE,CAAC,SAAS,yBAAyB,CAAC,CAAC,CAAC,IACpC,CAAC,CAAC,MAAM,CAAC,SAAS,MAAM,IAAI,GAAG,CAAC,IAAI,SAAS,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC,GAAG,KAAK,CAAC"}
|
|
@@ -1,54 +1,54 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Base type used to describe a constraint.
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
type ConstraintBase<T extends string, V extends Record<string, unknown> | null> = {
|
|
5
5
|
type: T;
|
|
6
6
|
value: V;
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
9
|
* All the possible operators inside a constraint.
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
11
|
+
export type ConstraintOperator = ">" | ">=" | "<" | "<=";
|
|
12
12
|
/**
|
|
13
13
|
* THe type of a constraint message when one is present.
|
|
14
14
|
*/
|
|
15
|
-
|
|
16
|
-
export
|
|
15
|
+
type ConstraintMessage = string | null;
|
|
16
|
+
export type UniqueConstraint = ConstraintBase<"UniqueConstraint", {
|
|
17
17
|
msg: ConstraintMessage;
|
|
18
18
|
}>;
|
|
19
|
-
export
|
|
19
|
+
export type SizeConstraint = ConstraintBase<"SizeConstraint", {
|
|
20
20
|
min: number | null;
|
|
21
21
|
max: number | null;
|
|
22
22
|
msg: ConstraintMessage;
|
|
23
23
|
}>;
|
|
24
|
-
export
|
|
24
|
+
export type RegexpConstraint = ConstraintBase<"RegexpConstraint", {
|
|
25
25
|
regexp: string;
|
|
26
26
|
flags: number;
|
|
27
27
|
msg: ConstraintMessage;
|
|
28
28
|
}>;
|
|
29
|
-
export
|
|
29
|
+
export type BoundaryConstraint = ConstraintBase<"BoundaryConstraint", {
|
|
30
30
|
boundary: number | null;
|
|
31
31
|
op: ConstraintOperator;
|
|
32
32
|
msg: ConstraintMessage;
|
|
33
33
|
}>;
|
|
34
|
-
export
|
|
34
|
+
export type IntervalBoundConstraint = ConstraintBase<"IntervalBoundConstraint", {
|
|
35
35
|
minvalue: number | null;
|
|
36
36
|
maxvalue: number | null;
|
|
37
37
|
msg: ConstraintMessage;
|
|
38
38
|
}>;
|
|
39
|
-
export
|
|
39
|
+
export type StaticVocabularyConstraint = ConstraintBase<"StaticVocabularyConstraint", {
|
|
40
40
|
values: string[];
|
|
41
41
|
msg: ConstraintMessage;
|
|
42
42
|
}>;
|
|
43
|
-
export
|
|
43
|
+
export type FormatConstraint = ConstraintBase<"FormatConstraint", {
|
|
44
44
|
values: ["text/rest", "text/markdown", "text/html", "text/plain"];
|
|
45
45
|
msg: ConstraintMessage;
|
|
46
46
|
}>;
|
|
47
|
-
export
|
|
47
|
+
export type RQLVocabularyConstraint = ConstraintBase<"RQLVocabularyConstraint", {
|
|
48
48
|
expression: string;
|
|
49
49
|
mainvars: string[];
|
|
50
50
|
}>;
|
|
51
|
-
export
|
|
51
|
+
export type RQLConstraint = ConstraintBase<"RQLConstraint", {
|
|
52
52
|
expression: string;
|
|
53
53
|
mainvars: string[];
|
|
54
54
|
msg: ConstraintMessage;
|
|
@@ -56,10 +56,10 @@ export declare type RQLConstraint = ConstraintBase<"RQLConstraint", {
|
|
|
56
56
|
/**
|
|
57
57
|
* Type representing all possible constraints for attributes.
|
|
58
58
|
*/
|
|
59
|
-
export
|
|
59
|
+
export type AttributeConstraint = Readonly<UniqueConstraint | SizeConstraint | RegexpConstraint | BoundaryConstraint | IntervalBoundConstraint | StaticVocabularyConstraint | FormatConstraint | RQLConstraint>;
|
|
60
60
|
/**
|
|
61
61
|
* Type representing all possible constraints for relations.
|
|
62
62
|
*/
|
|
63
|
-
export
|
|
63
|
+
export type RelationConstraint = Readonly<RQLVocabularyConstraint | RQLConstraint>;
|
|
64
64
|
export {};
|
|
65
65
|
//# sourceMappingURL=Constraints.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Constraints.d.ts","sourceRoot":"","sources":["../../../src/schema/raw/Constraints.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"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AG,EAAE,iBAAiB,CAAA;CAAE,CAC7E,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG,cAAc,CACrD,4BAA4B,EAC5B;IAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAAC,GAAG,EAAE,iBAAiB,CAAA;CAAE,CAC7C,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,cAAc,CAC3C,kBAAkB,EAClB;IACE,MAAM,EAAE,CAAC,WAAW,EAAE,eAAe,EAAE,WAAW,EAAE,YAAY,CAAC,CAAC;IAClE,GAAG,EAAE,iBAAiB,CAAC;CACxB,CACF,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,cAAc,CAClD,yBAAyB,EACzB;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,CAC3C,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,cAAc,CACxC,eAAe,EACf;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;IAAC,GAAG,EAAE,iBAAiB,CAAA;CAAE,CACnE,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CACtC,gBAAgB,GAChB,cAAc,GACd,gBAAgB,GAChB,kBAAkB,GAClB,uBAAuB,GACvB,0BAA0B,GAC1B,gBAAgB,GAChB,aAAa,CAChB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,QAAQ,CACvC,uBAAuB,GAAG,aAAa,CACxC,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Type representing an entity schema.
|
|
3
3
|
*/
|
|
4
|
-
export
|
|
4
|
+
export type EntityRawSchema = {
|
|
5
5
|
type: string;
|
|
6
6
|
final: boolean;
|
|
7
7
|
description: string;
|
|
@@ -9,5 +9,5 @@ export declare type EntityRawSchema = {
|
|
|
9
9
|
/**
|
|
10
10
|
* Type representing a list of entity schemas.
|
|
11
11
|
*/
|
|
12
|
-
export
|
|
12
|
+
export type EntityRawSchemaArray = ReadonlyArray<EntityRawSchema>;
|
|
13
13
|
//# sourceMappingURL=Entities.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Entities.d.ts","sourceRoot":"","sources":["../../../src/schema/raw/Entities.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"Entities.d.ts","sourceRoot":"","sources":["../../../src/schema/raw/Entities.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,aAAa,CAAC,eAAe,CAAC,CAAC"}
|
|
@@ -3,17 +3,17 @@ import { EntityRawSchema, EntityRawSchemaArray } from "./Entities";
|
|
|
3
3
|
/**
|
|
4
4
|
* Type representing all the possible cardinalities in CubicWeb.
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export type Cardinality = "*" | "1" | "?" | "+";
|
|
7
7
|
/**
|
|
8
8
|
* Type representing a cardinality pair as used in relation definitions.
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
10
|
+
export type CardinalityPair = `${Cardinality}${Cardinality}`;
|
|
11
11
|
/**
|
|
12
12
|
* Type used as a base to build final relation definitions with primitive types (Int, String, ...).
|
|
13
13
|
*
|
|
14
14
|
* @internal
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
type BuildObjBase<T extends string> = {
|
|
17
17
|
object: T;
|
|
18
18
|
final: true;
|
|
19
19
|
required?: boolean;
|
|
@@ -70,11 +70,11 @@ interface CustomBuildObj<T extends string> extends BuildObjBase<T> {
|
|
|
70
70
|
*
|
|
71
71
|
* @internal
|
|
72
72
|
*/
|
|
73
|
-
export
|
|
73
|
+
export type BuildObj = Readonly<StringBuildObj | PasswordBuildObj | BytesBuildObj | IntBuildObj | BigIntBuildObj | FloatBuildObj | BooleanBuildObj | DecimalBuildObj | DateBuildObj | TimeBuildObj | DatetimeBuildObj | TZTimeBuildObj | TZDatetimeBuildObj | IntervalBuildObj | CustomBuildObj<string>>;
|
|
74
74
|
/**
|
|
75
75
|
* Type representing the possible options for an attribute.
|
|
76
76
|
*/
|
|
77
|
-
export
|
|
77
|
+
export type AttributeOptions = {
|
|
78
78
|
indexed?: boolean;
|
|
79
79
|
fulltextindexed?: boolean;
|
|
80
80
|
internationalizable?: boolean;
|
|
@@ -82,7 +82,7 @@ export declare type AttributeOptions = {
|
|
|
82
82
|
/**
|
|
83
83
|
* Type representing the possible options for a relation definition.
|
|
84
84
|
*/
|
|
85
|
-
export
|
|
85
|
+
export type RelationOptions = {
|
|
86
86
|
symmetric?: boolean;
|
|
87
87
|
inlined?: boolean;
|
|
88
88
|
fulltext_container?: "subject" | "object";
|
|
@@ -94,7 +94,7 @@ export declare type RelationOptions = {
|
|
|
94
94
|
*
|
|
95
95
|
* It can infer default values type depending on the object type if the relation is final.
|
|
96
96
|
*/
|
|
97
|
-
export
|
|
97
|
+
export type RelationDefinitionRawSchema<ESchemas extends EntityRawSchemaArray, Final extends boolean = boolean> = Readonly<{
|
|
98
98
|
type: string;
|
|
99
99
|
description: string;
|
|
100
100
|
cardinality: CardinalityPair;
|
|
@@ -112,6 +112,6 @@ export declare type RelationDefinitionRawSchema<ESchemas extends EntityRawSchema
|
|
|
112
112
|
/**
|
|
113
113
|
* Type representing a list of relation definitions.
|
|
114
114
|
*/
|
|
115
|
-
export
|
|
115
|
+
export type RelationDefinitionRawSchemaArray<ESchemas extends EntityRawSchemaArray> = ReadonlyArray<RelationDefinitionRawSchema<ESchemas, boolean>>;
|
|
116
116
|
export {};
|
|
117
117
|
//# sourceMappingURL=RelationDefinitions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RelationDefinitions.d.ts","sourceRoot":"","sources":["../../../src/schema/raw/RelationDefinitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEnE;;GAEG;AACH,
|
|
1
|
+
{"version":3,"file":"RelationDefinitions.d.ts","sourceRoot":"","sources":["../../../src/schema/raw/RelationDefinitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEnE;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,GAAG,WAAW,GAAG,WAAW,EAAE,CAAC;AAE7D;;;;GAIG;AACH,KAAK,YAAY,CAAC,CAAC,SAAS,MAAM,IAAI;IACpC,MAAM,EAAE,CAAC,CAAC;IACV,KAAK,EAAE,IAAI,CAAC;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,UAAU,cAAe,SAAQ,YAAY,CAAC,QAAQ,CAAC;IACrD,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,UAAU,gBAAiB,SAAQ,YAAY,CAAC,UAAU,CAAC;IACzD,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,UAAU,aAAc,SAAQ,YAAY,CAAC,OAAO,CAAC;IACnD,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,UAAU,WAAY,SAAQ,YAAY,CAAC,KAAK,CAAC;IAC/C,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED,UAAU,cAAe,SAAQ,YAAY,CAAC,QAAQ,CAAC;IACrD,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+6,7 @@ import { RelationDefinitionRawSchemaArray } from "./RelationDefinitions";
|
|
|
6
6
|
*
|
|
7
7
|
* `cubicweb-ctl export-schema -f typescript <YOUR_INSTANCE_NAME>`
|
|
8
8
|
*/
|
|
9
|
-
export
|
|
9
|
+
export type RawSchema<E extends EntityRawSchemaArray = EntityRawSchemaArray, R extends RelationDefinitionRawSchemaArray<E> = RelationDefinitionRawSchemaArray<E>> = {
|
|
10
10
|
entities: E;
|
|
11
11
|
relations_definitions: R;
|
|
12
12
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../../src/schema/raw/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,gCAAgC,EAAE,MAAM,uBAAuB,CAAC;AAEzE;;;;;GAKG;AACH,
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../../src/schema/raw/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,gCAAgC,EAAE,MAAM,uBAAuB,CAAC;AAEzE;;;;;GAKG;AACH,MAAM,MAAM,SAAS,CACnB,CAAC,SAAS,oBAAoB,GAAG,oBAAoB,EACrD,CAAC,SAAS,gCAAgC,CAAC,CAAC,CAAC,GAAG,gCAAgC,CAAC,CAAC,CAAC,IACjF;IACF,QAAQ,EAAE,CAAC,CAAC;IACZ,qBAAqB,EAAE,CAAC,CAAC;CAC1B,CAAC"}
|
|
@@ -6,17 +6,17 @@ import { EntityRawSchemaArray } from "./Entities";
|
|
|
6
6
|
* In the given EntityRawSchemaArray, if the entities type is a string, the schema is loosely typed.
|
|
7
7
|
* If the schema is strongly typed, the entities type would be a word (which is stricter than string).
|
|
8
8
|
*/
|
|
9
|
-
export
|
|
9
|
+
export type IsLooseSchema<E extends EntityRawSchemaArray> = string extends E[number]["type"] ? true : false;
|
|
10
10
|
/**
|
|
11
11
|
* Checks if the given entity type is present in the EntityRawSchemaArray.
|
|
12
12
|
* Use this to create conditional types.
|
|
13
13
|
*/
|
|
14
|
-
export
|
|
14
|
+
export type IsETypeInStrictSchema<E extends EntityRawSchemaArray, EType extends string> = EType extends E[number]["type"] ? true : false;
|
|
15
15
|
/**
|
|
16
16
|
* Type representing the entity's raw schema matching this type.
|
|
17
17
|
* This type only works for EntityRawSchemaArray with literals as "type" property.
|
|
18
18
|
*/
|
|
19
|
-
export
|
|
19
|
+
export type EntityRawSchemaByType<E extends EntityRawSchemaArray, T extends string> = E[number] extends infer ESchema ? ESchema extends {
|
|
20
20
|
type: T;
|
|
21
21
|
} ? ESchema : never : never;
|
|
22
22
|
//# sourceMappingURL=Utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../../src/schema/raw/Utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;;GAMG;AACH,
|
|
1
|
+
{"version":3,"file":"Utils.d.ts","sourceRoot":"","sources":["../../../src/schema/raw/Utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,oBAAoB,IACtD,MAAM,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;AAElD;;;GAGG;AACH,MAAM,MAAM,qBAAqB,CAC/B,CAAC,SAAS,oBAAoB,EAC9B,KAAK,SAAS,MAAM,IAClB,KAAK,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,KAAK,CAAC;AAEnD;;;GAGG;AACH,MAAM,MAAM,qBAAqB,CAC/B,CAAC,SAAS,oBAAoB,EAC9B,CAAC,SAAS,MAAM,IACd,CAAC,CAAC,MAAM,CAAC,SAAS,MAAM,OAAO,GAC/B,OAAO,SAAS;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,GACzB,OAAO,GACP,KAAK,GACP,KAAK,CAAC"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@cubicweb/client",
|
|
3
3
|
"description": "Official JS client for CubicWeb API",
|
|
4
4
|
"author": "Logilab",
|
|
5
|
-
"version": "1.
|
|
5
|
+
"version": "1.8.0",
|
|
6
6
|
"license": "LGPL-3.0-or-later",
|
|
7
7
|
"main": "lib/index.js",
|
|
8
8
|
"types": "lib/index.d.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"!**/__tests__/**"
|
|
26
26
|
],
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"typedoc": "^0.23.
|
|
29
|
-
"typescript": "^4.
|
|
28
|
+
"typedoc": "^0.23.24",
|
|
29
|
+
"typescript": "^4.9.4"
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/Errors.ts
CHANGED
|
@@ -5,6 +5,13 @@ export class InconsistentSchemaError extends Error {
|
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
export class ValidationError extends Error {
|
|
9
|
+
constructor(message: string) {
|
|
10
|
+
super(message);
|
|
11
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
export class TransactionClosedError extends Error {
|
|
9
16
|
constructor() {
|
|
10
17
|
super("Trying to use a closed transaction");
|
package/src/api/Api.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ValidationError } from "../Errors";
|
|
1
2
|
import { RawSchema } from "../schema/raw/Schema";
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -22,6 +23,15 @@ export type RqlRow = Array<string | number | boolean | null>;
|
|
|
22
23
|
*/
|
|
23
24
|
export type ResultSet = Array<RqlRow>;
|
|
24
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Type representing the currently logged user's data
|
|
28
|
+
*/
|
|
29
|
+
export interface CurrentUser {
|
|
30
|
+
login: string;
|
|
31
|
+
eid: number;
|
|
32
|
+
dcTitle: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
25
35
|
/**
|
|
26
36
|
* Type representing the body of an error sent by CubicWeb's API.
|
|
27
37
|
*/
|
|
@@ -52,6 +62,7 @@ export default class Api {
|
|
|
52
62
|
private _rqlApiUrl: string;
|
|
53
63
|
private _schemaApiUrl: string;
|
|
54
64
|
private _loginApiUrl: string;
|
|
65
|
+
private _currentUserApiUrl: string;
|
|
55
66
|
private _transactionApiUrl = {
|
|
56
67
|
begin: "",
|
|
57
68
|
execute: "",
|
|
@@ -74,6 +85,7 @@ export default class Api {
|
|
|
74
85
|
this._rqlApiUrl = this.getApiRoute("rql");
|
|
75
86
|
this._schemaApiUrl = this.getApiRoute("schema");
|
|
76
87
|
this._loginApiUrl = this.getApiRoute("login");
|
|
88
|
+
this._currentUserApiUrl = this.getApiRoute("current-user");
|
|
77
89
|
Object.keys(this._transactionApiUrl).forEach(
|
|
78
90
|
(k) =>
|
|
79
91
|
(this._transactionApiUrl[k as keyof typeof this._transactionApiUrl] =
|
|
@@ -97,11 +109,15 @@ export default class Api {
|
|
|
97
109
|
* @returns A promise with the request's result set
|
|
98
110
|
*/
|
|
99
111
|
async execute(query: string, params: RQLParams): Promise<ResultSet> {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
112
|
+
try {
|
|
113
|
+
return await nonNullFetchApi<ResultSet>(this._rqlApiUrl, {
|
|
114
|
+
method: "POST",
|
|
115
|
+
body: JSON.stringify({ query, params }),
|
|
116
|
+
credentials: "include", // FIXME is it secure?
|
|
117
|
+
});
|
|
118
|
+
} catch (e) {
|
|
119
|
+
this.handleUserErrors(e);
|
|
120
|
+
}
|
|
105
121
|
}
|
|
106
122
|
|
|
107
123
|
/**
|
|
@@ -124,16 +140,31 @@ export default class Api {
|
|
|
124
140
|
* @returns A promise returning true if the login was successful, false otherwise
|
|
125
141
|
*/
|
|
126
142
|
async login(login: string, password: string): Promise<boolean> {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
143
|
+
try {
|
|
144
|
+
await fetchApi<null>(this._loginApiUrl, {
|
|
145
|
+
method: "POST",
|
|
146
|
+
body: JSON.stringify({
|
|
147
|
+
login,
|
|
148
|
+
password,
|
|
149
|
+
}),
|
|
150
|
+
credentials: "include",
|
|
151
|
+
});
|
|
152
|
+
return true;
|
|
153
|
+
} catch (_error) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Get the current user associated to this client
|
|
160
|
+
*
|
|
161
|
+
* @returns A promise resolving to the current user
|
|
162
|
+
*/
|
|
163
|
+
async currentUser(): Promise<CurrentUser> {
|
|
164
|
+
return await nonNullFetchApi<CurrentUser>(this._currentUserApiUrl, {
|
|
165
|
+
method: "GET",
|
|
133
166
|
credentials: "include",
|
|
134
|
-
})
|
|
135
|
-
.then(() => true)
|
|
136
|
-
.catch(() => false);
|
|
167
|
+
});
|
|
137
168
|
}
|
|
138
169
|
|
|
139
170
|
/**
|
|
@@ -161,11 +192,15 @@ export default class Api {
|
|
|
161
192
|
query: string,
|
|
162
193
|
params: RQLParams
|
|
163
194
|
): Promise<ResultSet | null> {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
195
|
+
try {
|
|
196
|
+
return await fetchApi<ResultSet>(this._transactionApiUrl.execute, {
|
|
197
|
+
method: "POST",
|
|
198
|
+
body: JSON.stringify({ uuid, query, params }),
|
|
199
|
+
credentials: "include",
|
|
200
|
+
});
|
|
201
|
+
} catch (e) {
|
|
202
|
+
this.handleUserErrors(e);
|
|
203
|
+
}
|
|
169
204
|
}
|
|
170
205
|
|
|
171
206
|
/**
|
|
@@ -174,11 +209,15 @@ export default class Api {
|
|
|
174
209
|
* @param uuid The transaction's uuid
|
|
175
210
|
*/
|
|
176
211
|
async transactionCommit(uuid: string): Promise<null> {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
212
|
+
try {
|
|
213
|
+
return await fetchApi<null>(this._transactionApiUrl.commit, {
|
|
214
|
+
method: "POST",
|
|
215
|
+
body: JSON.stringify({ uuid }),
|
|
216
|
+
credentials: "include",
|
|
217
|
+
});
|
|
218
|
+
} catch (e) {
|
|
219
|
+
this.handleUserErrors(e);
|
|
220
|
+
}
|
|
182
221
|
}
|
|
183
222
|
|
|
184
223
|
/**
|
|
@@ -193,6 +232,23 @@ export default class Api {
|
|
|
193
232
|
credentials: "include",
|
|
194
233
|
});
|
|
195
234
|
}
|
|
235
|
+
|
|
236
|
+
private handleUserErrors(error: unknown): never {
|
|
237
|
+
if (
|
|
238
|
+
typeof error === "object" &&
|
|
239
|
+
error !== null &&
|
|
240
|
+
"title" in error &&
|
|
241
|
+
typeof error.title === "string" &&
|
|
242
|
+
"message" in error &&
|
|
243
|
+
typeof error.message === "string"
|
|
244
|
+
) {
|
|
245
|
+
if (error.title === "ValidationError") {
|
|
246
|
+
throw new ValidationError(error.message);
|
|
247
|
+
}
|
|
248
|
+
throw error;
|
|
249
|
+
}
|
|
250
|
+
throw error;
|
|
251
|
+
}
|
|
196
252
|
}
|
|
197
253
|
|
|
198
254
|
/**
|
|
@@ -204,28 +260,21 @@ export default class Api {
|
|
|
204
260
|
* @param init Additional request parameters
|
|
205
261
|
* @returns A promise with the non-null fetched result
|
|
206
262
|
*/
|
|
207
|
-
|
|
263
|
+
async function nonNullFetchApi<R = unknown>(
|
|
208
264
|
input: RequestInfo,
|
|
209
265
|
init?: RequestInit
|
|
210
|
-
)
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
} else {
|
|
223
|
-
resolve(v);
|
|
224
|
-
}
|
|
225
|
-
})
|
|
226
|
-
.catch(reject)
|
|
227
|
-
);
|
|
228
|
-
};
|
|
266
|
+
) {
|
|
267
|
+
const result = await fetchApi<R>(input, init);
|
|
268
|
+
if (result == null) {
|
|
269
|
+
const error: ApiErrorResponse = {
|
|
270
|
+
status: 500,
|
|
271
|
+
title: "Unexpected null response",
|
|
272
|
+
message: "Response was null but a value was expected",
|
|
273
|
+
};
|
|
274
|
+
throw error;
|
|
275
|
+
}
|
|
276
|
+
return result;
|
|
277
|
+
}
|
|
229
278
|
|
|
230
279
|
/**
|
|
231
280
|
* Sends a request to the given API route with the `Content-Type` header set and waits for a response.
|
|
@@ -236,7 +285,10 @@ const nonNullFetchApi = <R = unknown>(
|
|
|
236
285
|
* @param init Additional request parameters
|
|
237
286
|
* @returns A promise with the fetched result
|
|
238
287
|
*/
|
|
239
|
-
|
|
288
|
+
async function fetchApi<R = unknown>(
|
|
289
|
+
input: RequestInfo,
|
|
290
|
+
init?: RequestInit
|
|
291
|
+
): Promise<R | null> {
|
|
240
292
|
let headers = init?.headers;
|
|
241
293
|
if (init?.method && init.method !== "GET" && init.method !== "DELETE") {
|
|
242
294
|
headers = {
|
|
@@ -244,42 +296,30 @@ const fetchApi = <R = unknown>(input: RequestInfo, init?: RequestInit) => {
|
|
|
244
296
|
...init?.headers,
|
|
245
297
|
};
|
|
246
298
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
status,
|
|
275
|
-
...data,
|
|
276
|
-
});
|
|
277
|
-
})
|
|
278
|
-
.catch((e) => {
|
|
279
|
-
console.error(e);
|
|
280
|
-
reject({ status, title: "Error", message: "" });
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
})
|
|
284
|
-
);
|
|
285
|
-
};
|
|
299
|
+
|
|
300
|
+
const response = await fetch(input, {
|
|
301
|
+
...init,
|
|
302
|
+
headers,
|
|
303
|
+
});
|
|
304
|
+
const status = response.status;
|
|
305
|
+
if (status >= 200 && status < 300) {
|
|
306
|
+
if (status === 204) {
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
try {
|
|
310
|
+
return await response.json();
|
|
311
|
+
} catch (e) {
|
|
312
|
+
console.error(e);
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
} else {
|
|
316
|
+
let json;
|
|
317
|
+
try {
|
|
318
|
+
json = await response.json();
|
|
319
|
+
} catch (e) {
|
|
320
|
+
console.error(e);
|
|
321
|
+
throw { status, title: "Error", message: "" };
|
|
322
|
+
}
|
|
323
|
+
throw { status, ...json };
|
|
324
|
+
}
|
|
325
|
+
}
|
package/src/api/Client.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Schema } from "../schema/classes/Schema";
|
|
2
|
-
import Api, { RQLParams } from "./Api";
|
|
2
|
+
import Api, { RQLParams, ResultSet, CurrentUser } from "./Api";
|
|
3
3
|
import Transaction from "./Transaction";
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -30,7 +30,7 @@ export default class Client {
|
|
|
30
30
|
* @param params The additional parameters for the request
|
|
31
31
|
* @returns A promise with the request's result set
|
|
32
32
|
*/
|
|
33
|
-
async execute(query: string, params: RQLParams = {}) {
|
|
33
|
+
async execute(query: string, params: RQLParams = {}): Promise<ResultSet> {
|
|
34
34
|
return await this.api.execute(query, params);
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -55,10 +55,21 @@ export default class Client {
|
|
|
55
55
|
return await this.api.login(login, password);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
/**
|
|
59
|
+
* Get the user associated to this client
|
|
60
|
+
*
|
|
61
|
+
* @returns A promise resolving to the current user
|
|
62
|
+
*/
|
|
63
|
+
async currentUser(): Promise<CurrentUser> {
|
|
64
|
+
return await this.api.currentUser();
|
|
65
|
+
}
|
|
66
|
+
|
|
58
67
|
/**
|
|
59
68
|
* Creates a new transaction and exposes the Transaction object in the given callback.
|
|
60
69
|
* Use this callback to execute RQL requests as part of the transaction.
|
|
61
70
|
* Once the callback's end is reached, the transaction is automatically committed.
|
|
71
|
+
* Note that any exception thrown by the callback will lead to the
|
|
72
|
+
* transaction being rolled back.
|
|
62
73
|
*
|
|
63
74
|
* @param callback Function to execute transaction requests in.
|
|
64
75
|
* @returns The promise returned by the callback
|
|
@@ -66,7 +77,16 @@ export default class Client {
|
|
|
66
77
|
async transaction<T>(callback: (tr: Transaction) => Promise<T>): Promise<T> {
|
|
67
78
|
const transaction = new Transaction(this.api);
|
|
68
79
|
await transaction.begin();
|
|
69
|
-
|
|
80
|
+
|
|
81
|
+
let result: T;
|
|
82
|
+
try {
|
|
83
|
+
result = await callback(transaction);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (!transaction.isClosed()) {
|
|
86
|
+
await transaction.rollback();
|
|
87
|
+
}
|
|
88
|
+
throw error;
|
|
89
|
+
}
|
|
70
90
|
if (!transaction.isClosed()) {
|
|
71
91
|
await transaction.commit();
|
|
72
92
|
}
|