@cubicweb/client 3.0.0-alpha.10 → 3.0.0-alpha.12
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/README.md +11 -20
- package/lib/api/Api.d.ts +30 -22
- package/lib/api/Api.d.ts.map +1 -1
- package/lib/api/Api.js +148 -154
- package/lib/api/Api.js.map +1 -1
- package/lib/api/Client.d.ts +21 -9
- package/lib/api/Client.d.ts.map +1 -1
- package/lib/api/Client.js +40 -57
- package/lib/api/Client.js.map +1 -1
- package/lib/api/ResultSet.d.ts +25 -0
- package/lib/api/ResultSet.d.ts.map +1 -0
- package/lib/api/ResultSet.js +12 -0
- package/lib/api/ResultSet.js.map +1 -0
- package/lib/api/binary/RQLBinary.d.ts +6 -0
- package/lib/api/binary/RQLBinary.d.ts.map +1 -0
- package/lib/api/binary/RQLBinary.js +10 -0
- package/lib/api/binary/RQLBinary.js.map +1 -0
- package/lib/api/query/RQLQuery.d.ts +40 -0
- package/lib/api/query/RQLQuery.d.ts.map +1 -0
- package/lib/api/query/RQLQuery.js +48 -0
- package/lib/api/query/RQLQuery.js.map +1 -0
- package/lib/api/query/references.d.ts +41 -0
- package/lib/api/query/references.d.ts.map +1 -0
- package/lib/api/query/references.js +50 -0
- package/lib/api/query/references.js.map +1 -0
- package/lib/api/transaction/Transaction.d.ts +25 -0
- package/lib/api/transaction/Transaction.d.ts.map +1 -0
- package/lib/api/transaction/Transaction.js +28 -0
- package/lib/api/transaction/Transaction.js.map +1 -0
- package/lib/api/transaction/TransactionResult.d.ts +32 -0
- package/lib/api/transaction/TransactionResult.d.ts.map +1 -0
- package/lib/api/transaction/TransactionResult.js +41 -0
- package/lib/api/transaction/TransactionResult.js.map +1 -0
- package/lib/{Errors.d.ts → errors.d.ts} +7 -4
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +19 -0
- package/lib/errors.js.map +1 -0
- package/lib/index.d.ts +18 -13
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +17 -34
- package/lib/index.js.map +1 -1
- package/lib/schema/classes/EntitySchema.d.ts +5 -5
- package/lib/schema/classes/EntitySchema.d.ts.map +1 -1
- package/lib/schema/classes/EntitySchema.js +3 -5
- package/lib/schema/classes/EntitySchema.js.map +1 -1
- package/lib/schema/classes/RelationDefinitionSchema.d.ts +6 -6
- package/lib/schema/classes/RelationDefinitionSchema.d.ts.map +1 -1
- package/lib/schema/classes/RelationDefinitionSchema.js +8 -10
- package/lib/schema/classes/RelationDefinitionSchema.js.map +1 -1
- package/lib/schema/classes/Schema.d.ts +7 -7
- package/lib/schema/classes/Schema.d.ts.map +1 -1
- package/lib/schema/classes/Schema.js +8 -11
- package/lib/schema/classes/Schema.js.map +1 -1
- package/lib/schema/classes/Utils.d.ts +10 -10
- package/lib/schema/classes/Utils.d.ts.map +1 -1
- package/lib/schema/classes/Utils.js +19 -35
- package/lib/schema/classes/Utils.js.map +1 -1
- package/lib/schema/raw/Constraints.d.ts +27 -0
- package/lib/schema/raw/Constraints.d.ts.map +1 -1
- package/lib/schema/raw/Constraints.js +1 -2
- package/lib/schema/raw/Entities.js +1 -2
- package/lib/schema/raw/RelationDefinitions.d.ts +3 -3
- package/lib/schema/raw/RelationDefinitions.d.ts.map +1 -1
- package/lib/schema/raw/RelationDefinitions.js +1 -2
- package/lib/schema/raw/Schema.d.ts +2 -2
- package/lib/schema/raw/Schema.d.ts.map +1 -1
- package/lib/schema/raw/Schema.js +1 -2
- package/lib/schema/raw/Utils.d.ts +1 -1
- package/lib/schema/raw/Utils.d.ts.map +1 -1
- package/lib/schema/raw/Utils.js +1 -2
- package/lib/utils.d.ts +39 -0
- package/lib/utils.d.ts.map +1 -0
- package/lib/utils.js +58 -0
- package/lib/utils.js.map +1 -0
- package/package.json +12 -5
- package/src/api/Api.ts +49 -42
- package/src/api/Client.ts +24 -15
- package/src/api/ResultSet.ts +29 -0
- package/src/api/binary/RQLBinary.ts +9 -0
- package/src/api/query/RQLQuery.ts +51 -0
- package/src/api/query/references.ts +43 -0
- package/src/api/transaction/Transaction.ts +31 -0
- package/src/api/transaction/TransactionResult.ts +46 -0
- package/src/{Errors.ts → errors.ts} +6 -7
- package/src/index.ts +21 -17
- package/src/schema/classes/EntitySchema.ts +8 -5
- package/src/schema/classes/RelationDefinitionSchema.ts +7 -7
- package/src/schema/classes/Schema.ts +10 -7
- package/src/schema/classes/Utils.ts +4 -4
- package/src/schema/raw/Constraints.ts +28 -0
- package/src/schema/raw/RelationDefinitions.ts +3 -3
- package/src/schema/raw/Schema.ts +2 -2
- package/src/schema/raw/Utils.ts +1 -1
- package/src/utils.ts +91 -0
- package/lib/Errors.d.ts.map +0 -1
- package/lib/Errors.js +0 -25
- package/lib/Errors.js.map +0 -1
- package/lib/api/Transaction.d.ts +0 -46
- package/lib/api/Transaction.d.ts.map +0 -1
- package/lib/api/Transaction.js +0 -75
- package/lib/api/Transaction.js.map +0 -1
- package/src/api/Transaction.ts +0 -94
package/src/api/Api.ts
CHANGED
|
@@ -1,46 +1,35 @@
|
|
|
1
|
-
import { ValidationError } from "../
|
|
2
|
-
import { RawSchema } from "../schema/raw/Schema";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "./
|
|
1
|
+
import { ValidationError } from "../errors.js";
|
|
2
|
+
import { RawSchema } from "../schema/raw/Schema.js";
|
|
3
|
+
import { getBinariesFromTransaction, serializeQueryParams } from "../utils.js";
|
|
4
|
+
import { ResultSet } from "./ResultSet.js";
|
|
5
|
+
import { RQLBinary } from "./binary/RQLBinary.js";
|
|
6
|
+
import { RQLQueryCellRef } from "./query/references.js";
|
|
7
|
+
import { Transaction } from "./transaction/Transaction.js";
|
|
8
|
+
import { TransactionResult } from "./transaction/TransactionResult.js";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* Type representing
|
|
11
|
+
* Type representing valid final values to use as parameters in a RQL query.
|
|
12
|
+
*
|
|
13
|
+
* For references to requests/binaries, see {@link RQLQueryCellRef} and {@link RQLQueryBinaryRef}
|
|
12
14
|
*
|
|
13
15
|
* @category Api
|
|
14
16
|
*/
|
|
15
|
-
export type
|
|
17
|
+
export type RQLQueryParamValue = string | number | boolean | null;
|
|
16
18
|
|
|
17
|
-
export type RQLParamValue = string | number | boolean | null;
|
|
18
19
|
/**
|
|
19
20
|
* Type representing RQL parameters to send along a request.
|
|
20
21
|
*
|
|
22
|
+
* Each key must be referenced in the RQL query.
|
|
23
|
+
*
|
|
21
24
|
* @category Api
|
|
22
25
|
*/
|
|
23
|
-
export type
|
|
26
|
+
export type RQLQueryParams = Record<
|
|
24
27
|
string,
|
|
25
|
-
|
|
28
|
+
RQLQueryParamValue | RQLQueryCellRef | RQLBinary
|
|
26
29
|
>;
|
|
27
30
|
|
|
28
31
|
/**
|
|
29
|
-
* Type representing
|
|
30
|
-
*
|
|
31
|
-
* @category Api
|
|
32
|
-
*/
|
|
33
|
-
export type RqlRow = Array<string | number | boolean | null>;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Type representing a RQL request result.
|
|
37
|
-
*
|
|
38
|
-
* @category Api
|
|
39
|
-
*/
|
|
40
|
-
export type ResultSet = Array<RqlRow>;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Type representing the currently logged user's data
|
|
32
|
+
* Type representing the currently logged user's data as returned by the `/current-user` route
|
|
44
33
|
*
|
|
45
34
|
* @category Api
|
|
46
35
|
*/
|
|
@@ -64,6 +53,9 @@ type ApiError = {
|
|
|
64
53
|
/**
|
|
65
54
|
* Type representing the error data sent to clients when retrieving an API error.
|
|
66
55
|
*
|
|
56
|
+
* It simply adds the HTTP status code in a `status` key to the regular CubicWeb api error,
|
|
57
|
+
* so users can handle HTTP status codes in their code.
|
|
58
|
+
*
|
|
67
59
|
* @category Api
|
|
68
60
|
*/
|
|
69
61
|
export type ApiErrorResponse = {
|
|
@@ -74,7 +66,7 @@ export type ApiErrorResponse = {
|
|
|
74
66
|
* Class used to handle requests to the CubicWeb API.
|
|
75
67
|
*
|
|
76
68
|
* You should never have to create this object yourself.
|
|
77
|
-
* Instead, retrieve this object from the methods in the
|
|
69
|
+
* Instead, retrieve this object from the methods in the {@link Client} class.
|
|
78
70
|
*
|
|
79
71
|
* @internal
|
|
80
72
|
*/
|
|
@@ -92,7 +84,7 @@ export default class Api {
|
|
|
92
84
|
* Class used to handle requests to the CubicWeb API.
|
|
93
85
|
*
|
|
94
86
|
* You should never have to create this object yourself.
|
|
95
|
-
* Instead, retrieve this object from the methods in the
|
|
87
|
+
* Instead, retrieve this object from the methods in the {@link Client} class.
|
|
96
88
|
*
|
|
97
89
|
* @param apiUrl The API url. It should not include the API version as it will be automatically added.
|
|
98
90
|
* Example: if you can retrieve the schema with https://example.com/api/v1/schema,
|
|
@@ -132,7 +124,7 @@ export default class Api {
|
|
|
132
124
|
* Tries to log in the user on the configured CubicWeb instance with the given credentials.
|
|
133
125
|
*
|
|
134
126
|
* @param login The user login
|
|
135
|
-
* @param password
|
|
127
|
+
* @param password The user password
|
|
136
128
|
* @returns A promise returning true if the login was successful, false otherwise
|
|
137
129
|
*/
|
|
138
130
|
async login(login: string, password: string): Promise<boolean> {
|
|
@@ -178,7 +170,9 @@ export default class Api {
|
|
|
178
170
|
/**
|
|
179
171
|
* Get the binary for the given entity attribute
|
|
180
172
|
*
|
|
181
|
-
* @
|
|
173
|
+
* @param eid Entity eid to fetch the binary from
|
|
174
|
+
* @param attribute Attribute on the entity in which the binary is stored
|
|
175
|
+
* @returns A promise resolving to the binary as a Blob
|
|
182
176
|
*/
|
|
183
177
|
async binary(eid: number, attribute: string): Promise<Blob> {
|
|
184
178
|
const params = new URLSearchParams({
|
|
@@ -191,10 +185,20 @@ export default class Api {
|
|
|
191
185
|
});
|
|
192
186
|
}
|
|
193
187
|
|
|
188
|
+
/**
|
|
189
|
+
* Executes the given transaction.
|
|
190
|
+
*
|
|
191
|
+
* If the {@link Transaction} object contains binaries, the request is automatically
|
|
192
|
+
* sent using `multipart/form-data` to allow uploading binaries.
|
|
193
|
+
*
|
|
194
|
+
* @param transaction Transaction to execute
|
|
195
|
+
* @returns A promise returning the transaction result on success
|
|
196
|
+
*/
|
|
194
197
|
async rql(transaction: Transaction): Promise<TransactionResult> {
|
|
198
|
+
const binaries = getBinariesFromTransaction(transaction);
|
|
195
199
|
try {
|
|
196
|
-
if (
|
|
197
|
-
return await this.multipartTransaction(transaction);
|
|
200
|
+
if (binaries.length > 0) {
|
|
201
|
+
return await this.multipartTransaction(transaction, binaries);
|
|
198
202
|
} else {
|
|
199
203
|
return await this.jsonTransaction(transaction);
|
|
200
204
|
}
|
|
@@ -204,18 +208,21 @@ export default class Api {
|
|
|
204
208
|
}
|
|
205
209
|
|
|
206
210
|
private getTransactionParams(transaction: Transaction) {
|
|
207
|
-
return transaction.queries.map((
|
|
208
|
-
query:
|
|
209
|
-
params:
|
|
211
|
+
return transaction.queries.map((rqlQuery) => ({
|
|
212
|
+
query: rqlQuery.rql,
|
|
213
|
+
params: serializeQueryParams(transaction, rqlQuery.params),
|
|
210
214
|
}));
|
|
211
215
|
}
|
|
212
216
|
|
|
213
|
-
private async multipartTransaction(
|
|
217
|
+
private async multipartTransaction(
|
|
218
|
+
transaction: Transaction,
|
|
219
|
+
binaries: RQLBinary[]
|
|
220
|
+
) {
|
|
214
221
|
const jsonParams = this.getTransactionParams(transaction);
|
|
215
222
|
const formData = new FormData();
|
|
216
223
|
formData.append("queries", JSON.stringify(jsonParams));
|
|
217
|
-
|
|
218
|
-
formData.append(
|
|
224
|
+
binaries.forEach((binary) => {
|
|
225
|
+
formData.append(binary.uuid, binary.blob);
|
|
219
226
|
});
|
|
220
227
|
|
|
221
228
|
const resultSets = await nonNullFetchApi<ReadonlyArray<ResultSet>>(
|
|
@@ -226,7 +233,7 @@ export default class Api {
|
|
|
226
233
|
body: formData,
|
|
227
234
|
}
|
|
228
235
|
);
|
|
229
|
-
return new TransactionResult(resultSets);
|
|
236
|
+
return new TransactionResult(transaction, resultSets);
|
|
230
237
|
}
|
|
231
238
|
|
|
232
239
|
private async jsonTransaction(transaction: Transaction) {
|
|
@@ -238,7 +245,7 @@ export default class Api {
|
|
|
238
245
|
body: JSON.stringify(this.getTransactionParams(transaction)),
|
|
239
246
|
}
|
|
240
247
|
);
|
|
241
|
-
return new TransactionResult(resultSets);
|
|
248
|
+
return new TransactionResult(transaction, resultSets);
|
|
242
249
|
}
|
|
243
250
|
|
|
244
251
|
private handleUserErrors(error: unknown): never {
|
package/src/api/Client.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { Schema } from "../schema/classes/Schema";
|
|
2
|
-
import Api, {
|
|
3
|
-
import {
|
|
1
|
+
import { Schema } from "../schema/classes/Schema.js";
|
|
2
|
+
import Api, { RQLQueryParams, CurrentUser } from "./Api.js";
|
|
3
|
+
import { ResultSet } from "./ResultSet.js";
|
|
4
|
+
import { RQLQuery } from "./query/RQLQuery.js";
|
|
5
|
+
import { Transaction } from "./transaction/Transaction.js";
|
|
6
|
+
import { TransactionResult } from "./transaction/TransactionResult.js";
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* Class used to communicate with a CubicWeb instance's API.
|
|
@@ -28,20 +31,19 @@ export default class Client {
|
|
|
28
31
|
/**
|
|
29
32
|
* Executes the given query and waits for the response.
|
|
30
33
|
*
|
|
31
|
-
*
|
|
34
|
+
* If binaries are given, the request is automatically
|
|
35
|
+
* sent using `multipart/form-data` to allow uploading binaries.
|
|
36
|
+
*
|
|
37
|
+
* @param rql The RQL query to send
|
|
32
38
|
* @param params The additional parameters for the request
|
|
33
39
|
* @returns A promise with the request's result set
|
|
34
40
|
*/
|
|
35
|
-
async execute(
|
|
36
|
-
query: string,
|
|
37
|
-
params: RQLParams = {},
|
|
38
|
-
binaries?: BinariesParam
|
|
39
|
-
): Promise<ResultSet> {
|
|
41
|
+
async execute(rql: string, params: RQLQueryParams = {}): Promise<ResultSet> {
|
|
40
42
|
const transaction = new Transaction();
|
|
41
|
-
const
|
|
42
|
-
transaction.
|
|
43
|
+
const query = new RQLQuery(rql, params);
|
|
44
|
+
transaction.push(query);
|
|
43
45
|
const result = await this.executeTransaction(transaction);
|
|
44
|
-
return result.
|
|
46
|
+
return result.getResultSet(query);
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
/**
|
|
@@ -58,7 +60,7 @@ export default class Client {
|
|
|
58
60
|
* Tries to log in the user on the configured CubicWeb instance with the given credentials.
|
|
59
61
|
*
|
|
60
62
|
* @param login The user login
|
|
61
|
-
* @param password
|
|
63
|
+
* @param password The user password
|
|
62
64
|
* @returns A promise returning true if the login was successful, false otherwise
|
|
63
65
|
*/
|
|
64
66
|
async login(login: string, password: string) {
|
|
@@ -84,8 +86,13 @@ export default class Client {
|
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
/**
|
|
89
|
+
* Executes the given transaction.
|
|
90
|
+
*
|
|
91
|
+
* If the {@link Transaction} object contains binaries, the request is automatically
|
|
92
|
+
* sent using `multipart/form-data` to allow uploading binaries.
|
|
93
|
+
*
|
|
87
94
|
* @param transaction Transaction to execute
|
|
88
|
-
* @returns A promise
|
|
95
|
+
* @returns A promise returning the transaction result on success
|
|
89
96
|
*/
|
|
90
97
|
async executeTransaction(
|
|
91
98
|
transaction: Transaction
|
|
@@ -96,7 +103,9 @@ export default class Client {
|
|
|
96
103
|
/**
|
|
97
104
|
* Get the binary for the given entity attribute
|
|
98
105
|
*
|
|
99
|
-
* @
|
|
106
|
+
* @param eid Entity eid to fetch the binary from
|
|
107
|
+
* @param attribute Attribute on the entity in which the binary is stored
|
|
108
|
+
* @returns A promise resolving to the binary as a Blob
|
|
100
109
|
*/
|
|
101
110
|
async getBinary(eid: number, attribute: string) {
|
|
102
111
|
return await this.api.binary(eid, attribute);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type representing a final value in a result set.
|
|
3
|
+
*
|
|
4
|
+
* Please not this type may not be accurate if you use entity methods,
|
|
5
|
+
* as those methods may return any data structure.
|
|
6
|
+
*
|
|
7
|
+
* @category Api
|
|
8
|
+
*/
|
|
9
|
+
export type ResultSetCell = string | number | boolean | null;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Type representing a row returned in a result set.
|
|
13
|
+
*
|
|
14
|
+
* @category Api
|
|
15
|
+
*/
|
|
16
|
+
export type ResultSetRow<
|
|
17
|
+
T extends ReadonlyArray<ResultSetCell> = ReadonlyArray<ResultSetCell>
|
|
18
|
+
> = T;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Class representing a RQL request result.
|
|
22
|
+
*
|
|
23
|
+
* @category Api
|
|
24
|
+
*/
|
|
25
|
+
export class ResultSet<
|
|
26
|
+
T extends ReadonlyArray<ResultSetCell> = ReadonlyArray<ResultSetCell>
|
|
27
|
+
> {
|
|
28
|
+
constructor(public readonly rows: T[]) {}
|
|
29
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from "uuid";
|
|
2
|
+
import { RQLQueryCellRef, RQLQueryRowRef } from "./references";
|
|
3
|
+
import { RQLQueryParams } from "../Api";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Class representing a RQL query to be sent to the API.
|
|
7
|
+
*
|
|
8
|
+
* Queries are identified by a uuid and are independent from transactions.
|
|
9
|
+
*
|
|
10
|
+
* If a query has been used in a transaction, RQLQuery objects can easily retrieve
|
|
11
|
+
* a reference to the query for later resolving the values in a {@link TransactionResult}.
|
|
12
|
+
*
|
|
13
|
+
* @category Api
|
|
14
|
+
*/
|
|
15
|
+
export class RQLQuery {
|
|
16
|
+
public readonly queryUUID: string;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Class representing a RQL query to be sent to the API.
|
|
20
|
+
*
|
|
21
|
+
* Queries are identified by a uuid and are independent from transactions.
|
|
22
|
+
*
|
|
23
|
+
* If a query has been used in a transaction, RQLQuery objects can easily retrieve
|
|
24
|
+
* a reference to the query for later resolving the values in a {@link TransactionResult}.
|
|
25
|
+
*
|
|
26
|
+
* @param rql The rql query
|
|
27
|
+
* @param params The parameters for the rql query
|
|
28
|
+
*
|
|
29
|
+
* @category Api
|
|
30
|
+
*/
|
|
31
|
+
constructor(
|
|
32
|
+
public readonly rql: string,
|
|
33
|
+
public readonly params: RQLQueryParams = {}
|
|
34
|
+
) {
|
|
35
|
+
this.queryUUID = uuidv4();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @returns A reference to a {@link ResultSetRow} in the result of this query.
|
|
40
|
+
*/
|
|
41
|
+
rowRef(row: number): RQLQueryRowRef {
|
|
42
|
+
return new RQLQueryRowRef(this.queryUUID, row);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @returns A reference to a {@link ResultSetCell} in the result of this query.
|
|
47
|
+
*/
|
|
48
|
+
cellRef(row: number, column: number): RQLQueryCellRef {
|
|
49
|
+
return new RQLQueryCellRef(this.queryUUID, row, column);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class representing a reference to a {@link ResultSetRow} in the result of a {@link RQLQuery}.
|
|
3
|
+
*
|
|
4
|
+
* Use this to resolve a {@link ResultSetRow} of the referenced {@link RQLQuery}
|
|
5
|
+
* from a {@link TransactionResult}.
|
|
6
|
+
*
|
|
7
|
+
* @category Api
|
|
8
|
+
*/
|
|
9
|
+
export class RQLQueryRowRef {
|
|
10
|
+
constructor(public readonly queryUUID: string, public readonly row: number) {}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Retrieve a reference to the given column in this row.
|
|
14
|
+
*
|
|
15
|
+
* @param c The column to get a reference for
|
|
16
|
+
* @returns A reference to the given column in the current row
|
|
17
|
+
*
|
|
18
|
+
* @category Api
|
|
19
|
+
*/
|
|
20
|
+
column(c: number): RQLQueryCellRef {
|
|
21
|
+
return new RQLQueryCellRef(this.queryUUID, this.row, c);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Class representing a reference to a {@link ResultSetCell} in the result of a {@link RQLQuery}.
|
|
27
|
+
*
|
|
28
|
+
* Use this to resolve a {@link ResultSetCell} of the referenced {@link RQLQuery}
|
|
29
|
+
* from a {@link TransactionResult}.
|
|
30
|
+
*
|
|
31
|
+
* This reference can also be used in parameters of other {@link RQLQuery}.
|
|
32
|
+
* If both {@link RQLQuery} are used in the same {@link RQLQuery},
|
|
33
|
+
* then the resolved value from the first query will be used in the second.
|
|
34
|
+
*
|
|
35
|
+
* @category Api
|
|
36
|
+
*/
|
|
37
|
+
export class RQLQueryCellRef {
|
|
38
|
+
constructor(
|
|
39
|
+
public readonly queryUUID: string,
|
|
40
|
+
public readonly row: number,
|
|
41
|
+
public readonly column: number
|
|
42
|
+
) {}
|
|
43
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { RQLQuery } from "../query/RQLQuery.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Class representing a set of {@link RQLQuery} executed one after the other in a single HTTP request.
|
|
5
|
+
*
|
|
6
|
+
* These {@link RQLQuery} can be linked together by using a {@link RQLQueryCellRef}
|
|
7
|
+
* of one {@link RQLQuery} in the parameters of a subsequent {@link RQLQuery}.
|
|
8
|
+
*
|
|
9
|
+
* Binary files are global to the transaction and can be referenced using a {@link RQLQueryBinaryRef}
|
|
10
|
+
* in the parameters of a {@link RQLQuery}.
|
|
11
|
+
*/
|
|
12
|
+
export class Transaction {
|
|
13
|
+
private _queries: Array<RQLQuery> = [];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Adds the given queries to the transaction.
|
|
17
|
+
*
|
|
18
|
+
* Each {@link RQLQuery} will be executed one after the other.
|
|
19
|
+
* These {@link RQLQuery} can be linked together by using a {@link RQLQueryCellRef}
|
|
20
|
+
* of one {@link RQLQuery} in the parameters of a subsequent {@link RQLQuery}.
|
|
21
|
+
*
|
|
22
|
+
* @param queries New queries to add to the transaction
|
|
23
|
+
*/
|
|
24
|
+
push(...queries: RQLQuery[]): void {
|
|
25
|
+
this._queries.push(...queries);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get queries(): ReadonlyArray<RQLQuery> {
|
|
29
|
+
return this._queries;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { getQueryIndexInTransaction } from "../../utils";
|
|
2
|
+
import { ResultSet, ResultSetCell, ResultSetRow } from "../ResultSet";
|
|
3
|
+
import { RQLQuery } from "../query/RQLQuery";
|
|
4
|
+
import { RQLQueryCellRef, RQLQueryRowRef } from "../query/references";
|
|
5
|
+
import { Transaction } from "./Transaction";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Class representing the result of a transaction.
|
|
9
|
+
*
|
|
10
|
+
* Retrieving the values is done using query references.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
*
|
|
14
|
+
* Retrieving the first value in a result set
|
|
15
|
+
*
|
|
16
|
+
* ```tsx
|
|
17
|
+
* const transaction = new Transaction()
|
|
18
|
+
* const query = new RQLQuery("Any X WHERE X name 'test'", {})
|
|
19
|
+
* transaction.push(query)
|
|
20
|
+
* const result = client.executeTransaction(transaction)
|
|
21
|
+
* const eid = result.resolve(query.cellRef(0, 0))
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @category Api
|
|
25
|
+
*/
|
|
26
|
+
export class TransactionResult {
|
|
27
|
+
constructor(
|
|
28
|
+
private transaction: Transaction,
|
|
29
|
+
private resultSets: ReadonlyArray<ResultSet>
|
|
30
|
+
) {}
|
|
31
|
+
|
|
32
|
+
getResultSet(query: RQLQuery): ResultSet {
|
|
33
|
+
const index = getQueryIndexInTransaction(this.transaction, query.queryUUID);
|
|
34
|
+
return this.resultSets[index];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
getRow(ref: RQLQueryRowRef): ResultSetRow {
|
|
38
|
+
const index = getQueryIndexInTransaction(this.transaction, ref.queryUUID);
|
|
39
|
+
return this.resultSets[index].rows[ref.row];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
getCell(ref: RQLQueryCellRef): ResultSetCell {
|
|
43
|
+
const index = getQueryIndexInTransaction(this.transaction, ref.queryUUID);
|
|
44
|
+
return this.resultSets[index].rows[ref.row][ref.column];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* There was an error processing the CubicWeb schema.
|
|
3
|
+
*/
|
|
1
4
|
export class InconsistentSchemaError extends Error {
|
|
2
5
|
constructor(message: string) {
|
|
3
6
|
super(`Inconsistent schema: ${message}`);
|
|
@@ -5,16 +8,12 @@ export class InconsistentSchemaError extends Error {
|
|
|
5
8
|
}
|
|
6
9
|
}
|
|
7
10
|
|
|
11
|
+
/**
|
|
12
|
+
* There was an error while validating the data sent to the server.
|
|
13
|
+
*/
|
|
8
14
|
export class ValidationError extends Error {
|
|
9
15
|
constructor(message: string) {
|
|
10
16
|
super(message);
|
|
11
17
|
Object.setPrototypeOf(this, new.target.prototype);
|
|
12
18
|
}
|
|
13
19
|
}
|
|
14
|
-
|
|
15
|
-
export class TransactionClosedError extends Error {
|
|
16
|
-
constructor() {
|
|
17
|
-
super("Trying to use a closed transaction");
|
|
18
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
19
|
-
}
|
|
20
|
-
}
|
package/src/index.ts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
// Raw Schema
|
|
2
|
-
export * from "./schema/raw/Constraints";
|
|
3
|
-
export * from "./schema/raw/Entities";
|
|
4
|
-
export * from "./schema/raw/RelationDefinitions";
|
|
5
|
-
export * from "./schema/raw/Schema";
|
|
6
|
-
export * from "./schema/raw/Utils";
|
|
2
|
+
export * from "./schema/raw/Constraints.js";
|
|
3
|
+
export * from "./schema/raw/Entities.js";
|
|
4
|
+
export * from "./schema/raw/RelationDefinitions.js";
|
|
5
|
+
export * from "./schema/raw/Schema.js";
|
|
6
|
+
export * from "./schema/raw/Utils.js";
|
|
7
7
|
|
|
8
8
|
// Schema Abstraction class
|
|
9
|
-
export * from "./schema/classes/EntitySchema";
|
|
10
|
-
export * from "./schema/classes/RelationDefinitionSchema";
|
|
11
|
-
export * from "./schema/classes/Schema";
|
|
12
|
-
export * from "./schema/classes/Utils";
|
|
9
|
+
export * from "./schema/classes/EntitySchema.js";
|
|
10
|
+
export * from "./schema/classes/RelationDefinitionSchema.js";
|
|
11
|
+
export * from "./schema/classes/Schema.js";
|
|
12
|
+
export * from "./schema/classes/Utils.js";
|
|
13
13
|
|
|
14
|
-
export * from "./
|
|
14
|
+
export * from "./errors.js";
|
|
15
15
|
|
|
16
16
|
// API
|
|
17
|
-
export { default as Client } from "./api/Client";
|
|
18
|
-
export * from "./api/Transaction";
|
|
19
17
|
export {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
RqlRow,
|
|
23
|
-
ResultSet,
|
|
18
|
+
RQLQueryParamValue,
|
|
19
|
+
RQLQueryParams,
|
|
24
20
|
ApiErrorResponse,
|
|
25
|
-
|
|
21
|
+
CurrentUser,
|
|
22
|
+
} from "./api/Api.js";
|
|
23
|
+
export { ResultSet, ResultSetRow, ResultSetCell } from "./api/ResultSet.js";
|
|
24
|
+
export { default as Client } from "./api/Client.js";
|
|
25
|
+
export { Transaction } from "./api/transaction/Transaction.js";
|
|
26
|
+
export { TransactionResult } from "./api/transaction/TransactionResult.js";
|
|
27
|
+
export { RQLQuery } from "./api/query/RQLQuery.js";
|
|
28
|
+
export { RQLBinary } from "./api/binary/RQLBinary.js";
|
|
29
|
+
export { RQLQueryRowRef, RQLQueryCellRef } from "./api/query/references.js";
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { EntityRawSchemaArray } from "../raw/Entities";
|
|
2
|
-
import { RelationDefinitionRawSchemaArray } from "../raw/RelationDefinitions";
|
|
3
|
-
import { RelationDefinitionSchema } from "./RelationDefinitionSchema";
|
|
4
|
-
import { Schema } from "./Schema";
|
|
5
|
-
import {
|
|
1
|
+
import { EntityRawSchemaArray } from "../raw/Entities.js";
|
|
2
|
+
import { RelationDefinitionRawSchemaArray } from "../raw/RelationDefinitions.js";
|
|
3
|
+
import { RelationDefinitionSchema } from "./RelationDefinitionSchema.js";
|
|
4
|
+
import { Schema } from "./Schema.js";
|
|
5
|
+
import {
|
|
6
|
+
MatchedRelationDefinition,
|
|
7
|
+
RelationDefinitionMatcher,
|
|
8
|
+
} from "./Utils.js";
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
11
|
* Wrapper around raw entity schemas from the Schema.
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { InconsistentSchemaError } from "../../
|
|
2
|
-
import { EntityRawSchemaArray } from "../raw/Entities";
|
|
1
|
+
import { InconsistentSchemaError } from "../../errors.js";
|
|
2
|
+
import { EntityRawSchemaArray } from "../raw/Entities.js";
|
|
3
3
|
import {
|
|
4
4
|
RelationDefinitionRawSchemaArray,
|
|
5
5
|
Cardinality,
|
|
6
|
-
} from "../raw/RelationDefinitions";
|
|
7
|
-
import { IsLooseSchema, EntityRawSchemaByType } from "../raw/Utils";
|
|
8
|
-
import { EntitySchema } from "./EntitySchema";
|
|
9
|
-
import { Schema } from "./Schema";
|
|
10
|
-
import { EntityRole, isCardinalityRequired } from "./Utils";
|
|
6
|
+
} from "../raw/RelationDefinitions.js";
|
|
7
|
+
import { IsLooseSchema, EntityRawSchemaByType } from "../raw/Utils.js";
|
|
8
|
+
import { EntitySchema } from "./EntitySchema.js";
|
|
9
|
+
import { Schema } from "./Schema.js";
|
|
10
|
+
import { EntityRole, isCardinalityRequired } from "./Utils.js";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Wrapper around raw relation definition schemas from the Schema.
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
import { EntityRawSchemaArray } from "../raw/Entities";
|
|
1
|
+
import { EntityRawSchemaArray } from "../raw/Entities.js";
|
|
2
2
|
import {
|
|
3
3
|
RelationDefinitionRawSchema,
|
|
4
4
|
RelationDefinitionRawSchemaArray,
|
|
5
|
-
} from "../raw/RelationDefinitions";
|
|
6
|
-
import { RawSchema } from "../raw/Schema";
|
|
5
|
+
} from "../raw/RelationDefinitions.js";
|
|
6
|
+
import { RawSchema } from "../raw/Schema.js";
|
|
7
7
|
import {
|
|
8
8
|
EntityRawSchemaByType,
|
|
9
9
|
IsETypeInStrictSchema,
|
|
10
10
|
IsLooseSchema,
|
|
11
|
-
} from "../raw/Utils";
|
|
12
|
-
import { EntitySchema } from "./EntitySchema";
|
|
13
|
-
import { RelationDefinitionSchema } from "./RelationDefinitionSchema";
|
|
14
|
-
import {
|
|
11
|
+
} from "../raw/Utils.js";
|
|
12
|
+
import { EntitySchema } from "./EntitySchema.js";
|
|
13
|
+
import { RelationDefinitionSchema } from "./RelationDefinitionSchema.js";
|
|
14
|
+
import {
|
|
15
|
+
RelationDefinitionMatcher,
|
|
16
|
+
MatchedRelationDefinition,
|
|
17
|
+
} from "./Utils.js";
|
|
15
18
|
|
|
16
19
|
const rawSchemaKey: unique symbol = Symbol("Indexer of the rawSchema");
|
|
17
20
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { EntityRawSchemaArray } from "../raw/Entities";
|
|
1
|
+
import { EntityRawSchemaArray } from "../raw/Entities.js";
|
|
2
2
|
import {
|
|
3
3
|
Cardinality,
|
|
4
4
|
RelationDefinitionRawSchema,
|
|
5
5
|
RelationDefinitionRawSchemaArray,
|
|
6
|
-
} from "../raw/RelationDefinitions";
|
|
7
|
-
import { Schema } from "./Schema";
|
|
8
|
-
import { EntitySchema } from "./EntitySchema";
|
|
6
|
+
} from "../raw/RelationDefinitions.js";
|
|
7
|
+
import { Schema } from "./Schema.js";
|
|
8
|
+
import { EntitySchema } from "./EntitySchema.js";
|
|
9
9
|
|
|
10
10
|
// This prefix is often applied to relation types as convention
|
|
11
11
|
// indicating a relation is viewed from the object's point of view
|