@cubicweb/client 1.6.0 → 1.7.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 +6 -5
- package/lib/api/Api.d.ts.map +1 -1
- package/lib/api/Api.js +91 -61
- package/lib/api/Api.js.map +1 -1
- package/lib/api/Client.d.ts +4 -2
- package/lib/api/Client.d.ts.map +1 -1
- package/lib/api/Client.js +12 -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 +102 -85
- package/src/api/Client.ts +14 -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,15 @@ 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
20
|
/**
|
|
21
21
|
* Type representing the body of an error sent by CubicWeb's API.
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
type ApiError = {
|
|
24
24
|
title: string;
|
|
25
25
|
message: string;
|
|
26
26
|
data?: Record<string, unknown>;
|
|
@@ -28,7 +28,7 @@ declare type ApiError = {
|
|
|
28
28
|
/**
|
|
29
29
|
* Type representing the error data sent to clients when retrieving an API error.
|
|
30
30
|
*/
|
|
31
|
-
export
|
|
31
|
+
export type ApiErrorResponse = {
|
|
32
32
|
status: number;
|
|
33
33
|
} & ApiError;
|
|
34
34
|
/**
|
|
@@ -108,6 +108,7 @@ export default class Api {
|
|
|
108
108
|
* @param uuid The transaction's uuid
|
|
109
109
|
*/
|
|
110
110
|
transactionRollback(uuid: string): Promise<null>;
|
|
111
|
+
private handleUserErrors;
|
|
111
112
|
}
|
|
112
113
|
export {};
|
|
113
114
|
//# 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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IAAI,OAAO,CAAC,MAAM,CAAC;IAOzC;;;;;;;OAOG;IACG,kBAAkB,CACtB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,SAAS,GAChB,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAY5B;;;;OAIG;IACG,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAYpD;;;;OAIG;IACG,mBAAmB,CAAC,IAAI,EAAE,MAAM,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
|
*
|
|
@@ -58,11 +59,16 @@ class Api {
|
|
|
58
59
|
*/
|
|
59
60
|
execute(query, params) {
|
|
60
61
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
try {
|
|
63
|
+
return yield nonNullFetchApi(this._rqlApiUrl, {
|
|
64
|
+
method: "POST",
|
|
65
|
+
body: JSON.stringify({ query, params }),
|
|
66
|
+
credentials: "include", // FIXME is it secure?
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
this.handleUserErrors(e);
|
|
71
|
+
}
|
|
66
72
|
});
|
|
67
73
|
}
|
|
68
74
|
/**
|
|
@@ -87,16 +93,20 @@ class Api {
|
|
|
87
93
|
*/
|
|
88
94
|
login(login, password) {
|
|
89
95
|
return __awaiter(this, void 0, void 0, function* () {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
96
|
+
try {
|
|
97
|
+
yield fetchApi(this._loginApiUrl, {
|
|
98
|
+
method: "POST",
|
|
99
|
+
body: JSON.stringify({
|
|
100
|
+
login,
|
|
101
|
+
password,
|
|
102
|
+
}),
|
|
103
|
+
credentials: "include",
|
|
104
|
+
});
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
catch (_error) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
100
110
|
});
|
|
101
111
|
}
|
|
102
112
|
/**
|
|
@@ -122,11 +132,16 @@ class Api {
|
|
|
122
132
|
*/
|
|
123
133
|
transactionExecute(uuid, query, params) {
|
|
124
134
|
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
135
|
+
try {
|
|
136
|
+
return yield fetchApi(this._transactionApiUrl.execute, {
|
|
137
|
+
method: "POST",
|
|
138
|
+
body: JSON.stringify({ uuid, query, params }),
|
|
139
|
+
credentials: "include",
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
this.handleUserErrors(e);
|
|
144
|
+
}
|
|
130
145
|
});
|
|
131
146
|
}
|
|
132
147
|
/**
|
|
@@ -136,11 +151,16 @@ class Api {
|
|
|
136
151
|
*/
|
|
137
152
|
transactionCommit(uuid) {
|
|
138
153
|
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
154
|
+
try {
|
|
155
|
+
return yield fetchApi(this._transactionApiUrl.commit, {
|
|
156
|
+
method: "POST",
|
|
157
|
+
body: JSON.stringify({ uuid }),
|
|
158
|
+
credentials: "include",
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
catch (e) {
|
|
162
|
+
this.handleUserErrors(e);
|
|
163
|
+
}
|
|
144
164
|
});
|
|
145
165
|
}
|
|
146
166
|
/**
|
|
@@ -157,6 +177,20 @@ class Api {
|
|
|
157
177
|
});
|
|
158
178
|
});
|
|
159
179
|
}
|
|
180
|
+
handleUserErrors(error) {
|
|
181
|
+
if (typeof error === "object" &&
|
|
182
|
+
error !== null &&
|
|
183
|
+
"title" in error &&
|
|
184
|
+
typeof error.title === "string" &&
|
|
185
|
+
"message" in error &&
|
|
186
|
+
typeof error.message === "string") {
|
|
187
|
+
if (error.title === "ValidationError") {
|
|
188
|
+
throw new Errors_1.ValidationError(error.message);
|
|
189
|
+
}
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
160
194
|
}
|
|
161
195
|
exports.default = Api;
|
|
162
196
|
/**
|
|
@@ -168,23 +202,20 @@ exports.default = Api;
|
|
|
168
202
|
* @param init Additional request parameters
|
|
169
203
|
* @returns A promise with the non-null fetched result
|
|
170
204
|
*/
|
|
171
|
-
|
|
172
|
-
return
|
|
173
|
-
|
|
174
|
-
if (
|
|
205
|
+
function nonNullFetchApi(input, init) {
|
|
206
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
207
|
+
const result = yield fetchApi(input, init);
|
|
208
|
+
if (result == null) {
|
|
175
209
|
const error = {
|
|
176
210
|
status: 500,
|
|
177
211
|
title: "Unexpected null response",
|
|
178
212
|
message: "Response was null but a value was expected",
|
|
179
213
|
};
|
|
180
|
-
|
|
214
|
+
throw error;
|
|
181
215
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
})
|
|
186
|
-
.catch(reject));
|
|
187
|
-
};
|
|
216
|
+
return result;
|
|
217
|
+
});
|
|
218
|
+
}
|
|
188
219
|
/**
|
|
189
220
|
* Sends a request to the given API route with the `Content-Type` header set and waits for a response.
|
|
190
221
|
* The returned promise will be rejected if the API returns HTTP error codes.
|
|
@@ -194,38 +225,37 @@ const nonNullFetchApi = (input, init) => {
|
|
|
194
225
|
* @param init Additional request parameters
|
|
195
226
|
* @returns A promise with the fetched result
|
|
196
227
|
*/
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
228
|
+
function fetchApi(input, init) {
|
|
229
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
230
|
+
let headers = init === null || init === void 0 ? void 0 : init.headers;
|
|
231
|
+
if ((init === null || init === void 0 ? void 0 : init.method) && init.method !== "GET" && init.method !== "DELETE") {
|
|
232
|
+
headers = Object.assign({ "Content-Type": "application/json;charset=UTF-8" }, init === null || init === void 0 ? void 0 : init.headers);
|
|
233
|
+
}
|
|
234
|
+
const response = yield fetch(input, Object.assign(Object.assign({}, init), { headers }));
|
|
203
235
|
const status = response.status;
|
|
204
236
|
if (status >= 200 && status < 300) {
|
|
205
237
|
if (status === 204) {
|
|
206
|
-
|
|
238
|
+
return null;
|
|
207
239
|
}
|
|
208
|
-
|
|
209
|
-
response
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
resolve(null);
|
|
215
|
-
});
|
|
240
|
+
try {
|
|
241
|
+
return yield response.json();
|
|
242
|
+
}
|
|
243
|
+
catch (e) {
|
|
244
|
+
console.error(e);
|
|
245
|
+
return null;
|
|
216
246
|
}
|
|
217
247
|
}
|
|
218
248
|
else {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
.
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
.catch((e) => {
|
|
249
|
+
let json;
|
|
250
|
+
try {
|
|
251
|
+
json = yield response.json();
|
|
252
|
+
}
|
|
253
|
+
catch (e) {
|
|
225
254
|
console.error(e);
|
|
226
|
-
|
|
227
|
-
}
|
|
255
|
+
throw { status, title: "Error", message: "" };
|
|
256
|
+
}
|
|
257
|
+
throw Object.assign({ status }, json);
|
|
228
258
|
}
|
|
229
|
-
})
|
|
230
|
-
}
|
|
259
|
+
});
|
|
260
|
+
}
|
|
231
261
|
//# 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;AAyC5C;;;;;;;GAOG;AACH,MAAqB,GAAG;IAatB;;;;;;;;;OASG;IACH,YAAY,MAAc;QArBlB,aAAQ,GAAG,IAAI,CAAC;QAIhB,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,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,OAAO,CAC1C,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAyC,CAAC;YACjE,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAC1C,CAAC;IACJ,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAEO,WAAW,CAAC,KAAa;QAC/B,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,QAAQ,IAAI,KAAK,EAAE,CAAC;IACrD,CAAC;IAED;;;;;;OAMG;IACG,OAAO,CAAC,KAAa,EA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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 } 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
|
*
|
|
@@ -41,6 +41,8 @@ export default class Client {
|
|
|
41
41
|
* Creates a new transaction and exposes the Transaction object in the given callback.
|
|
42
42
|
* Use this callback to execute RQL requests as part of the transaction.
|
|
43
43
|
* Once the callback's end is reached, the transaction is automatically committed.
|
|
44
|
+
* Note that any exception thrown by the callback will lead to the
|
|
45
|
+
* transaction being rolled back.
|
|
44
46
|
*
|
|
45
47
|
* @param callback Function to execute transaction requests in.
|
|
46
48
|
* @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,MAAM,OAAO,CAAC;AAClD,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;;;;;;;;;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
|
@@ -71,6 +71,8 @@ class Client {
|
|
|
71
71
|
* Creates a new transaction and exposes the Transaction object in the given callback.
|
|
72
72
|
* Use this callback to execute RQL requests as part of the transaction.
|
|
73
73
|
* Once the callback's end is reached, the transaction is automatically committed.
|
|
74
|
+
* Note that any exception thrown by the callback will lead to the
|
|
75
|
+
* transaction being rolled back.
|
|
74
76
|
*
|
|
75
77
|
* @param callback Function to execute transaction requests in.
|
|
76
78
|
* @returns The promise returned by the callback
|
|
@@ -79,7 +81,16 @@ class Client {
|
|
|
79
81
|
return __awaiter(this, void 0, void 0, function* () {
|
|
80
82
|
const transaction = new Transaction_1.default(this.api);
|
|
81
83
|
yield transaction.begin();
|
|
82
|
-
|
|
84
|
+
let result;
|
|
85
|
+
try {
|
|
86
|
+
result = yield callback(transaction);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
if (!transaction.isClosed()) {
|
|
90
|
+
yield transaction.rollback();
|
|
91
|
+
}
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
83
94
|
if (!transaction.isClosed()) {
|
|
84
95
|
yield transaction.commit();
|
|
85
96
|
}
|
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,gDAAkD;AAClD,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;;;;;;;;;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;AA9ED,yBA8EC"}
|
|
@@ -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":"Constraints.d.ts","sourceRoot":"","sources":["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AE,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,OAAO,EAAE,MAAM,GAAG,IA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emaArray } 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.7.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
|
/**
|
|
@@ -97,11 +98,15 @@ export default class Api {
|
|
|
97
98
|
* @returns A promise with the request's result set
|
|
98
99
|
*/
|
|
99
100
|
async execute(query: string, params: RQLParams): Promise<ResultSet> {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
try {
|
|
102
|
+
return await nonNullFetchApi<ResultSet>(this._rqlApiUrl, {
|
|
103
|
+
method: "POST",
|
|
104
|
+
body: JSON.stringify({ query, params }),
|
|
105
|
+
credentials: "include", // FIXME is it secure?
|
|
106
|
+
});
|
|
107
|
+
} catch (e) {
|
|
108
|
+
this.handleUserErrors(e);
|
|
109
|
+
}
|
|
105
110
|
}
|
|
106
111
|
|
|
107
112
|
/**
|
|
@@ -124,16 +129,19 @@ export default class Api {
|
|
|
124
129
|
* @returns A promise returning true if the login was successful, false otherwise
|
|
125
130
|
*/
|
|
126
131
|
async login(login: string, password: string): Promise<boolean> {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
132
|
+
try {
|
|
133
|
+
await fetchApi<null>(this._loginApiUrl, {
|
|
134
|
+
method: "POST",
|
|
135
|
+
body: JSON.stringify({
|
|
136
|
+
login,
|
|
137
|
+
password,
|
|
138
|
+
}),
|
|
139
|
+
credentials: "include",
|
|
140
|
+
});
|
|
141
|
+
return true;
|
|
142
|
+
} catch (_error) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
137
145
|
}
|
|
138
146
|
|
|
139
147
|
/**
|
|
@@ -161,11 +169,15 @@ export default class Api {
|
|
|
161
169
|
query: string,
|
|
162
170
|
params: RQLParams
|
|
163
171
|
): Promise<ResultSet | null> {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
172
|
+
try {
|
|
173
|
+
return await fetchApi<ResultSet>(this._transactionApiUrl.execute, {
|
|
174
|
+
method: "POST",
|
|
175
|
+
body: JSON.stringify({ uuid, query, params }),
|
|
176
|
+
credentials: "include",
|
|
177
|
+
});
|
|
178
|
+
} catch (e) {
|
|
179
|
+
this.handleUserErrors(e);
|
|
180
|
+
}
|
|
169
181
|
}
|
|
170
182
|
|
|
171
183
|
/**
|
|
@@ -174,11 +186,15 @@ export default class Api {
|
|
|
174
186
|
* @param uuid The transaction's uuid
|
|
175
187
|
*/
|
|
176
188
|
async transactionCommit(uuid: string): Promise<null> {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
189
|
+
try {
|
|
190
|
+
return await fetchApi<null>(this._transactionApiUrl.commit, {
|
|
191
|
+
method: "POST",
|
|
192
|
+
body: JSON.stringify({ uuid }),
|
|
193
|
+
credentials: "include",
|
|
194
|
+
});
|
|
195
|
+
} catch (e) {
|
|
196
|
+
this.handleUserErrors(e);
|
|
197
|
+
}
|
|
182
198
|
}
|
|
183
199
|
|
|
184
200
|
/**
|
|
@@ -193,6 +209,23 @@ export default class Api {
|
|
|
193
209
|
credentials: "include",
|
|
194
210
|
});
|
|
195
211
|
}
|
|
212
|
+
|
|
213
|
+
private handleUserErrors(error: unknown): never {
|
|
214
|
+
if (
|
|
215
|
+
typeof error === "object" &&
|
|
216
|
+
error !== null &&
|
|
217
|
+
"title" in error &&
|
|
218
|
+
typeof error.title === "string" &&
|
|
219
|
+
"message" in error &&
|
|
220
|
+
typeof error.message === "string"
|
|
221
|
+
) {
|
|
222
|
+
if (error.title === "ValidationError") {
|
|
223
|
+
throw new ValidationError(error.message);
|
|
224
|
+
}
|
|
225
|
+
throw error;
|
|
226
|
+
}
|
|
227
|
+
throw error;
|
|
228
|
+
}
|
|
196
229
|
}
|
|
197
230
|
|
|
198
231
|
/**
|
|
@@ -204,28 +237,21 @@ export default class Api {
|
|
|
204
237
|
* @param init Additional request parameters
|
|
205
238
|
* @returns A promise with the non-null fetched result
|
|
206
239
|
*/
|
|
207
|
-
|
|
240
|
+
async function nonNullFetchApi<R = unknown>(
|
|
208
241
|
input: RequestInfo,
|
|
209
242
|
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
|
-
};
|
|
243
|
+
) {
|
|
244
|
+
const result = await fetchApi<R>(input, init);
|
|
245
|
+
if (result == null) {
|
|
246
|
+
const error: ApiErrorResponse = {
|
|
247
|
+
status: 500,
|
|
248
|
+
title: "Unexpected null response",
|
|
249
|
+
message: "Response was null but a value was expected",
|
|
250
|
+
};
|
|
251
|
+
throw error;
|
|
252
|
+
}
|
|
253
|
+
return result;
|
|
254
|
+
}
|
|
229
255
|
|
|
230
256
|
/**
|
|
231
257
|
* Sends a request to the given API route with the `Content-Type` header set and waits for a response.
|
|
@@ -236,7 +262,10 @@ const nonNullFetchApi = <R = unknown>(
|
|
|
236
262
|
* @param init Additional request parameters
|
|
237
263
|
* @returns A promise with the fetched result
|
|
238
264
|
*/
|
|
239
|
-
|
|
265
|
+
async function fetchApi<R = unknown>(
|
|
266
|
+
input: RequestInfo,
|
|
267
|
+
init?: RequestInit
|
|
268
|
+
): Promise<R | null> {
|
|
240
269
|
let headers = init?.headers;
|
|
241
270
|
if (init?.method && init.method !== "GET" && init.method !== "DELETE") {
|
|
242
271
|
headers = {
|
|
@@ -244,42 +273,30 @@ const fetchApi = <R = unknown>(input: RequestInfo, init?: RequestInit) => {
|
|
|
244
273
|
...init?.headers,
|
|
245
274
|
};
|
|
246
275
|
}
|
|
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
|
-
};
|
|
276
|
+
|
|
277
|
+
const response = await fetch(input, {
|
|
278
|
+
...init,
|
|
279
|
+
headers,
|
|
280
|
+
});
|
|
281
|
+
const status = response.status;
|
|
282
|
+
if (status >= 200 && status < 300) {
|
|
283
|
+
if (status === 204) {
|
|
284
|
+
return null;
|
|
285
|
+
}
|
|
286
|
+
try {
|
|
287
|
+
return await response.json();
|
|
288
|
+
} catch (e) {
|
|
289
|
+
console.error(e);
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
} else {
|
|
293
|
+
let json;
|
|
294
|
+
try {
|
|
295
|
+
json = await response.json();
|
|
296
|
+
} catch (e) {
|
|
297
|
+
console.error(e);
|
|
298
|
+
throw { status, title: "Error", message: "" };
|
|
299
|
+
}
|
|
300
|
+
throw { status, ...json };
|
|
301
|
+
}
|
|
302
|
+
}
|
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 } 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
|
|
|
@@ -59,6 +59,8 @@ export default class Client {
|
|
|
59
59
|
* Creates a new transaction and exposes the Transaction object in the given callback.
|
|
60
60
|
* Use this callback to execute RQL requests as part of the transaction.
|
|
61
61
|
* Once the callback's end is reached, the transaction is automatically committed.
|
|
62
|
+
* Note that any exception thrown by the callback will lead to the
|
|
63
|
+
* transaction being rolled back.
|
|
62
64
|
*
|
|
63
65
|
* @param callback Function to execute transaction requests in.
|
|
64
66
|
* @returns The promise returned by the callback
|
|
@@ -66,7 +68,16 @@ export default class Client {
|
|
|
66
68
|
async transaction<T>(callback: (tr: Transaction) => Promise<T>): Promise<T> {
|
|
67
69
|
const transaction = new Transaction(this.api);
|
|
68
70
|
await transaction.begin();
|
|
69
|
-
|
|
71
|
+
|
|
72
|
+
let result: T;
|
|
73
|
+
try {
|
|
74
|
+
result = await callback(transaction);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
if (!transaction.isClosed()) {
|
|
77
|
+
await transaction.rollback();
|
|
78
|
+
}
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
70
81
|
if (!transaction.isClosed()) {
|
|
71
82
|
await transaction.commit();
|
|
72
83
|
}
|