@cubicweb/client 1.9.0 → 2.1.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/api/Api.d.ts CHANGED
@@ -1,13 +1,15 @@
1
1
  import { RawSchema } from "../schema/raw/Schema";
2
+ import { TransactionResult, Transaction } from "./Transaction";
2
3
  /**
3
4
  * Type representing an RQL request and its associated parameters.
4
5
  */
5
6
  export type RQLQuery = [string, RQLParams];
7
+ export type RQLParamValue = string | number | boolean | null;
6
8
  /**
7
9
  * Type representing RQL parameters to send along a request.
8
10
  */
9
11
  export interface RQLParams {
10
- [key: string]: string | number;
12
+ [key: string]: RQLParamValue;
11
13
  }
12
14
  /**
13
15
  * Type representing a row returned in a result set.
@@ -96,33 +98,7 @@ export default class Api {
96
98
  * @returns A promise resolving to the current user
97
99
  */
98
100
  currentUser(): Promise<CurrentUser>;
99
- /**
100
- * Starts a new transaction.
101
- *
102
- * @returns A promise with the transaction uuid
103
- */
104
- transactionBegin(): Promise<string>;
105
- /**
106
- * Executes a RQL request as part of a transaction identified by the given uuid.
107
- *
108
- * @param uuid The transaction's uuid
109
- * @param query The RQL query to send
110
- * @param params The additional parameters for the request
111
- * @returns A promise with the request's result set
112
- */
113
- transactionExecute(uuid: string, query: string, params: RQLParams): Promise<ResultSet | null>;
114
- /**
115
- * Commits the transaction identified by the given uuid.
116
- *
117
- * @param uuid The transaction's uuid
118
- */
119
- transactionCommit(uuid: string): Promise<null>;
120
- /**
121
- * Rollbacks the transaction identified by the given uuid.
122
- *
123
- * @param uuid The transaction's uuid
124
- */
125
- transactionRollback(uuid: string): Promise<null>;
101
+ executeTransaction(transaction: Transaction): Promise<TransactionResult>;
126
102
  private handleUserErrors;
127
103
  }
128
104
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"Api.d.ts","sourceRoot":"","sources":["../../src/api/Api.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;A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CAAC,gBAAgB;CAgBzB"}
package/lib/api/Api.js CHANGED
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const Errors_1 = require("../Errors");
13
+ const Transaction_1 = require("./Transaction");
13
14
  /**
14
15
  * Class used to handle requests to the CubicWeb API.
15
16
  *
@@ -31,19 +32,12 @@ class Api {
31
32
  */
32
33
  constructor(apiUrl) {
33
34
  this._version = "v1";
34
- this._transactionApiUrl = {
35
- begin: "",
36
- execute: "",
37
- commit: "",
38
- rollback: "",
39
- };
40
35
  this._apiUrl = apiUrl;
41
36
  this._rqlApiUrl = this.getApiRoute("rql");
42
37
  this._schemaApiUrl = this.getApiRoute("schema");
43
38
  this._loginApiUrl = this.getApiRoute("login");
44
39
  this._currentUserApiUrl = this.getApiRoute("current-user");
45
- Object.keys(this._transactionApiUrl).forEach((k) => (this._transactionApiUrl[k] =
46
- this.getApiRoute(`transaction/${k}`)));
40
+ this._transactionApiUrl = this.getApiRoute("transaction");
47
41
  }
48
42
  get apiUrl() {
49
43
  return this._apiUrl;
@@ -123,72 +117,27 @@ class Api {
123
117
  });
124
118
  });
125
119
  }
126
- /**
127
- * Starts a new transaction.
128
- *
129
- * @returns A promise with the transaction uuid
130
- */
131
- transactionBegin() {
132
- return __awaiter(this, void 0, void 0, function* () {
133
- return nonNullFetchApi(this._transactionApiUrl.begin, {
134
- method: "POST",
135
- credentials: "include",
136
- });
137
- });
138
- }
139
- /**
140
- * Executes a RQL request as part of a transaction identified by the given uuid.
141
- *
142
- * @param uuid The transaction's uuid
143
- * @param query The RQL query to send
144
- * @param params The additional parameters for the request
145
- * @returns A promise with the request's result set
146
- */
147
- transactionExecute(uuid, query, params) {
148
- return __awaiter(this, void 0, void 0, function* () {
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
- }
159
- });
160
- }
161
- /**
162
- * Commits the transaction identified by the given uuid.
163
- *
164
- * @param uuid The transaction's uuid
165
- */
166
- transactionCommit(uuid) {
167
- return __awaiter(this, void 0, void 0, function* () {
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
- }
178
- });
179
- }
180
- /**
181
- * Rollbacks the transaction identified by the given uuid.
182
- *
183
- * @param uuid The transaction's uuid
184
- */
185
- transactionRollback(uuid) {
120
+ executeTransaction(transaction) {
186
121
  return __awaiter(this, void 0, void 0, function* () {
187
- return fetchApi(this._transactionApiUrl.rollback, {
122
+ const data = transaction.queries.map((transactionQuery) => ({
123
+ query: transactionQuery.query,
124
+ params: Object.fromEntries(Object.entries(transactionQuery.params).map(([key, value]) => [
125
+ key,
126
+ (0, Transaction_1.isTransactionQueryRef)(value)
127
+ ? {
128
+ queryIndex: value.queryIndex,
129
+ row: value.row,
130
+ column: value.column,
131
+ }
132
+ : value,
133
+ ])),
134
+ }));
135
+ const resultSets = yield nonNullFetchApi(this._transactionApiUrl, {
188
136
  method: "POST",
189
- body: JSON.stringify({ uuid }),
190
137
  credentials: "include",
138
+ body: JSON.stringify(data),
191
139
  });
140
+ return new Transaction_1.TransactionResult(resultSets);
192
141
  });
193
142
  }
194
143
  handleUserErrors(error) {
@@ -1 +1 @@
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,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import Transaction from "./Transaction";
3
+ import { Transaction, TransactionBackend, TransactionResult } from "./Transaction";
4
4
  /**
5
5
  * Class used to communicate with a CubicWeb instance's API.
6
6
  */
7
7
  export default class Client {
8
8
  private api;
9
+ private transactionBackend;
9
10
  /**
10
11
  * Class used to communicate with a CubicWeb instance's API.
11
12
  *
@@ -13,7 +14,9 @@ export default class Client {
13
14
  * Example: if you can retrieve the schema with https://example.com/api/v1/schema,
14
15
  * use https://example.com/api as `apiUrl`.
15
16
  */
16
- constructor(apiUrl: string);
17
+ constructor(apiUrl: string, options?: {
18
+ transactionBackend?: TransactionBackend;
19
+ });
17
20
  get apiUrl(): string;
18
21
  /**
19
22
  * Executes the given query and waits for the response.
@@ -44,15 +47,9 @@ export default class Client {
44
47
  */
45
48
  currentUser(): Promise<CurrentUser>;
46
49
  /**
47
- * Creates a new transaction and exposes the Transaction object in the given callback.
48
- * Use this callback to execute RQL requests as part of the transaction.
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.
52
- *
53
- * @param callback Function to execute transaction requests in.
54
- * @returns The promise returned by the callback
50
+ * @param transaction Transaction to execute
51
+ * @returns A promise fulfilled when the transaction is completed
55
52
  */
56
- transaction<T>(callback: (tr: Transaction) => Promise<T>): Promise<T>;
53
+ executeTransaction(transaction: Transaction): Promise<TransactionResult>;
57
54
  }
58
55
  //# sourceMappingURL=Client.d.ts.map
@@ -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,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;;;;;;OAM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AW,IAAI,OAAO,CAAC,WAAW,CAAC;IAIzC;;;OAGG;IACG,kBAAkB,CACtB,WAAW,EAAE,WAAW,GACvB,OAAO,CAAC,iBAAiB,CAAC;CAG9B"}
package/lib/api/Client.js CHANGED
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const Schema_1 = require("../schema/classes/Schema");
16
16
  const Api_1 = __importDefault(require("./Api"));
17
- const Transaction_1 = __importDefault(require("./Transaction"));
17
+ const Transaction_1 = require("./Transaction");
18
18
  /**
19
19
  * Class used to communicate with a CubicWeb instance's API.
20
20
  */
@@ -26,8 +26,15 @@ class Client {
26
26
  * Example: if you can retrieve the schema with https://example.com/api/v1/schema,
27
27
  * use https://example.com/api as `apiUrl`.
28
28
  */
29
- constructor(apiUrl) {
29
+ constructor(apiUrl, options = {}) {
30
30
  this.api = new Api_1.default(apiUrl);
31
+ const { transactionBackend } = options;
32
+ if (transactionBackend === undefined) {
33
+ this.transactionBackend = new Transaction_1.NativeTransactionBackend(this.api);
34
+ }
35
+ else {
36
+ this.transactionBackend = transactionBackend;
37
+ }
31
38
  }
32
39
  get apiUrl() {
33
40
  return this.api.apiUrl;
@@ -78,33 +85,12 @@ class Client {
78
85
  });
79
86
  }
80
87
  /**
81
- * Creates a new transaction and exposes the Transaction object in the given callback.
82
- * Use this callback to execute RQL requests as part of the transaction.
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.
86
- *
87
- * @param callback Function to execute transaction requests in.
88
- * @returns The promise returned by the callback
88
+ * @param transaction Transaction to execute
89
+ * @returns A promise fulfilled when the transaction is completed
89
90
  */
90
- transaction(callback) {
91
+ executeTransaction(transaction) {
91
92
  return __awaiter(this, void 0, void 0, function* () {
92
- const transaction = new Transaction_1.default(this.api);
93
- yield transaction.begin();
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
- }
104
- if (!transaction.isClosed()) {
105
- yield transaction.commit();
106
- }
107
- return result;
93
+ return yield this.transactionBackend.execute(transaction);
108
94
  });
109
95
  }
110
96
  }
@@ -1 +1 @@
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,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AC;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;;;OAGG;IACG,kBAAkB,CACtB,WAAwB;;YAExB,OAAO,MAAM,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAC5D,CAAC;KAAA;CACF;AA9ED,yBA8EC"}
@@ -1,57 +1,33 @@
1
- import Api, { RQLParams } from "./Api";
2
- /**
3
- * Class used to handle CubicWeb's transactions.
4
- * A transaction allows to execute several RQL requests without altering the database until all
5
- * changes are committed.
6
- *
7
- * You should never have to create this object yourself.
8
- * Instead, retrieve this object from the methods in the `Client` class.
9
- */
10
- export default class Transaction {
11
- private api;
12
- private _uuid;
13
- private _closed;
14
- /**
15
- * Class used to handle CubicWeb's transactions.
16
- * A transaction allows to execute several RQL requests without altering the database until all
17
- * changes are committed.
18
- *
19
- * You should never have to create this object yourself.
20
- * Instead, retrieve this object from the methods in the `Client` class.
21
- *
22
- * @param api The API object used to communicate with the CubicWeb backend.
23
- */
24
- constructor(api: Api);
25
- /**
26
- * @returns True if the connection is closed.
27
- */
28
- isClosed(): boolean;
29
- /**
30
- * This transaction unique identifier.
31
- */
32
- get uuid(): string | null;
33
- /**
34
- * Begins a new transaction an retrieves the associated uuid.
35
- */
36
- begin(): Promise<void>;
37
- /**
38
- * Executes the given query and waits for the response.
39
- * Make sure you called `begin` before using this method.
40
- * As this is a transaction changes will only be applied when you call the `commit` method.
41
- *
42
- * @param query The RQL query to send
43
- * @param params The additional parameters for the request
44
- * @returns A promise with the request's result set
45
- */
46
- execute(query: string, params?: RQLParams): Promise<import("./Api").ResultSet | null>;
47
- /**
48
- * Commits the transaction to apply all the RQL queries sent with `execute`.
49
- */
50
- commit(): Promise<void>;
51
- /**
52
- * Rollbacks all the queries sent with `execute` and closes the transaction.
53
- */
54
- rollback(): Promise<void>;
55
- private preventUsageIfClosed;
1
+ import Api, { ResultSet, RQLParamValue } from "./Api";
2
+ export declare class Transaction {
3
+ private _queries;
4
+ push(query: string, params: Record<string, RQLParamValue | TransactionQueryRef>): TransactionQuery;
5
+ get queries(): ReadonlyArray<TransactionQuery>;
6
+ }
7
+ export declare class TransactionResult {
8
+ private resultSets;
9
+ constructor(resultSets: ReadonlyArray<ResultSet>);
10
+ resolve(ref: TransactionQueryRef): string | number | boolean | null;
11
+ }
12
+ export interface TransactionQueryRef {
13
+ queryIndex: number;
14
+ row: number;
15
+ column: number;
16
+ }
17
+ export declare class TransactionQuery {
18
+ readonly query: string;
19
+ readonly params: Record<string, RQLParamValue | TransactionQueryRef>;
20
+ readonly index: number;
21
+ constructor(query: string, params: Record<string, RQLParamValue | TransactionQueryRef>, index: number);
22
+ ref(row?: number, column?: number): TransactionQueryRef;
23
+ }
24
+ export declare function isTransactionQueryRef(value: RQLParamValue | TransactionQueryRef): value is TransactionQueryRef;
25
+ export interface TransactionBackend {
26
+ execute(transaction: Transaction): Promise<TransactionResult>;
27
+ }
28
+ export declare class NativeTransactionBackend implements TransactionBackend {
29
+ private _api;
30
+ constructor(_api: Api);
31
+ execute(transaction: Transaction): Promise<TransactionResult>;
56
32
  }
57
33
  //# sourceMappingURL=Transaction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Transaction.d.ts","sourceRoot":"","sources":["../../src/api/Transaction.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,EAAE,EAAE,SAAS,EAA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AAM;gBAFb,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,mBAAmB,CAAC,EAC3D,KAAK,EAAE,MAAM;IAG/B,GAAG,CAAC,GAAG,SAAI,EAAE,MAAM,SAAI,GAAG,mBAAmB;CAO9C;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,aAAa,GAAG,mBAAmB,GACzC,KAAK,IAAI,mBAAmB,CAQ9B;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC/D;AAED,qBAAa,wBAAyB,YAAW,kBAAkB;IACrD,OAAO,CAAC,IAAI;gBAAJ,IAAI,EAAE,GAAG;IACvB,OAAO,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAGpE"}
@@ -9,92 +9,60 @@ 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");
13
- /**
14
- * Class used to handle CubicWeb's transactions.
15
- * A transaction allows to execute several RQL requests without altering the database until all
16
- * changes are committed.
17
- *
18
- * You should never have to create this object yourself.
19
- * Instead, retrieve this object from the methods in the `Client` class.
20
- */
12
+ exports.NativeTransactionBackend = exports.isTransactionQueryRef = exports.TransactionQuery = exports.TransactionResult = exports.Transaction = void 0;
21
13
  class Transaction {
22
- /**
23
- * Class used to handle CubicWeb's transactions.
24
- * A transaction allows to execute several RQL requests without altering the database until all
25
- * changes are committed.
26
- *
27
- * You should never have to create this object yourself.
28
- * Instead, retrieve this object from the methods in the `Client` class.
29
- *
30
- * @param api The API object used to communicate with the CubicWeb backend.
31
- */
32
- constructor(api) {
33
- this.api = api;
34
- this._uuid = null;
35
- this._closed = false;
14
+ constructor() {
15
+ this._queries = [];
36
16
  }
37
- /**
38
- * @returns True if the connection is closed.
39
- */
40
- isClosed() {
41
- return this._closed;
17
+ push(query, params) {
18
+ const stackedQuery = new TransactionQuery(query, params, this._queries.length);
19
+ this._queries.push(stackedQuery);
20
+ return stackedQuery;
42
21
  }
43
- /**
44
- * This transaction unique identifier.
45
- */
46
- get uuid() {
47
- return this._uuid;
22
+ get queries() {
23
+ return this._queries;
48
24
  }
49
- /**
50
- * Begins a new transaction an retrieves the associated uuid.
51
- */
52
- begin() {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- this._closed = false;
55
- this._uuid = yield this.api.transactionBegin();
56
- });
25
+ }
26
+ exports.Transaction = Transaction;
27
+ class TransactionResult {
28
+ constructor(resultSets) {
29
+ this.resultSets = resultSets;
57
30
  }
58
- /**
59
- * Executes the given query and waits for the response.
60
- * Make sure you called `begin` before using this method.
61
- * As this is a transaction changes will only be applied when you call the `commit` method.
62
- *
63
- * @param query The RQL query to send
64
- * @param params The additional parameters for the request
65
- * @returns A promise with the request's result set
66
- */
67
- execute(query, params = {}) {
68
- return __awaiter(this, void 0, void 0, function* () {
69
- this.preventUsageIfClosed();
70
- return yield this.api.transactionExecute(this.uuid, query, params);
71
- });
31
+ resolve(ref) {
32
+ return this.resultSets[ref.queryIndex][ref.row][ref.column];
72
33
  }
73
- /**
74
- * Commits the transaction to apply all the RQL queries sent with `execute`.
75
- */
76
- commit() {
77
- return __awaiter(this, void 0, void 0, function* () {
78
- this.preventUsageIfClosed();
79
- yield this.api.transactionCommit(this.uuid);
80
- this._closed = true;
81
- });
34
+ }
35
+ exports.TransactionResult = TransactionResult;
36
+ class TransactionQuery {
37
+ constructor(query, params, index) {
38
+ this.query = query;
39
+ this.params = params;
40
+ this.index = index;
41
+ }
42
+ ref(row = 0, column = 0) {
43
+ return {
44
+ queryIndex: this.index,
45
+ row,
46
+ column,
47
+ };
48
+ }
49
+ }
50
+ exports.TransactionQuery = TransactionQuery;
51
+ function isTransactionQueryRef(value) {
52
+ return (typeof value === "object" &&
53
+ value !== null &&
54
+ ["queryIndex", "row", "column"].every((key) => Object.keys(value).includes(key)));
55
+ }
56
+ exports.isTransactionQueryRef = isTransactionQueryRef;
57
+ class NativeTransactionBackend {
58
+ constructor(_api) {
59
+ this._api = _api;
82
60
  }
83
- /**
84
- * Rollbacks all the queries sent with `execute` and closes the transaction.
85
- */
86
- rollback() {
61
+ execute(transaction) {
87
62
  return __awaiter(this, void 0, void 0, function* () {
88
- this.preventUsageIfClosed();
89
- yield this.api.transactionRollback(this.uuid);
90
- this._closed = true;
63
+ return this._api.executeTransaction(transaction);
91
64
  });
92
65
  }
93
- preventUsageIfClosed() {
94
- if (this.isClosed()) {
95
- throw new Errors_1.TransactionClosedError();
96
- }
97
- }
98
66
  }
99
- exports.default = Transaction;
67
+ exports.NativeTransactionBackend = NativeTransactionBackend;
100
68
  //# sourceMappingURL=Transaction.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Transaction.js","sourceRoot":"","sources":["../../src/api/Transaction.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sCAAmD;AAGnD;;;;;;;GAOG;AACH,MAAqB,WAAW;IAI9B;;;;;;;;;OASG;IACH,YAAoB,GAAQ;QAAR,QAAG,GAAH,GAAG,CAAK;QAbpB,UAAK,GAAkB,IAAI,CAAC;QAC5B,YAAO,GAAG,KAAK,CAAC;IAYO,CAAC;IAEhC;;OAEG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;OAEG;IACG,KAAK;;YACT,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;YACrB,IAAI,CAAC,KAAK,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACjD,CAAC;KAAA;IAED;;;;;;;;OAQG;IACG,OAAO,CAAC,KAAa,EAAE,SAAoB,EAAE;;YACjD,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC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IAAG,CAAC;IAE5D,OAAO,CAAC,GAAwB;QAC9B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9D,CAAC;CACF;AAND,8CAMC;AAQD,MAAa,gBAAgB;IAC3B,YACkB,KAAa,EACb,MAA2D,EAC3D,KAAa;QAFb,UAAK,GAAL,KAAK,CAAQ;QACb,WAAM,GAAN,MAAM,CAAqD;QAC3D,UAAK,GAAL,KAAK,CAAQ;IAC5B,CAAC;IAEJ,GAAG,CAAC,GAAG,GAAG,CAAC,EAAE,MAAM,GAAG,CAAC;QACrB,OAAO;YACL,UAAU,EAAE,IAAI,CAAC,KAAK;YACtB,GAAG;YACH,MAAM;SACP,CAAC;IACJ,CAAC;CACF;AAdD,4CAcC;AAED,SAAgB,qBAAqB,CACnC,KAA0C;IAE1C,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,CAAC,YAAY,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAC5C,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CACjC,CACF,CAAC;AACJ,CAAC;AAVD,sDAUC;AAMD,MAAa,wBAAwB;IACnC,YAAoB,IAAS;QAAT,SAAI,GAAJ,IAAI,CAAK;IAAG,CAAC;IAC3B,OAAO,CAAC,WAAwB;;YACpC,OAAO,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAC;QACnD,CAAC;KAAA;CACF;AALD,4DAKC"}
package/lib/index.d.ts CHANGED
@@ -9,6 +9,6 @@ export * from "./schema/classes/Schema";
9
9
  export * from "./schema/classes/Utils";
10
10
  export * from "./Errors";
11
11
  export { default as Client } from "./api/Client";
12
- export { default as Transaction } from "./api/Transaction";
12
+ export * from "./api/Transaction";
13
13
  export { RQLQuery, RQLParams, RqlRow, ResultSet, ApiErrorResponse, } from "./api/Api";
14
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kCAAkC,CAAC;AACjD,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2CAA2C,CAAC;AAC1D,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AAEvC,cAAc,UAAU,CAAC;AAGzB,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EACL,QAAQ,EACR,SAAS,EACT,MAAM,EACN,SAAS,EACT,gBAAgB,GACjB,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kCAAkC,CAAC;AACjD,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,2CAA2C,CAAC;AAC1D,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AAEvC,cAAc,UAAU,CAAC;AAGzB,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,cAAc,CAAC;AACjD,cAAc,mBAAmB,CAAC;AAClC,OAAO,EACL,QAAQ,EACR,SAAS,EACT,MAAM,EACN,SAAS,EACT,gBAAgB,GACjB,MAAM,WAAW,CAAC"}
package/lib/index.js CHANGED
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.Transaction = exports.Client = void 0;
20
+ exports.Client = void 0;
21
21
  // Raw Schema
22
22
  __exportStar(require("./schema/raw/Constraints"), exports);
23
23
  __exportStar(require("./schema/raw/Entities"), exports);
@@ -33,6 +33,5 @@ __exportStar(require("./Errors"), exports);
33
33
  // API
34
34
  var Client_1 = require("./api/Client");
35
35
  Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return __importDefault(Client_1).default; } });
36
- var Transaction_1 = require("./api/Transaction");
37
- Object.defineProperty(exports, "Transaction", { enumerable: true, get: function () { return __importDefault(Transaction_1).default; } });
36
+ __exportStar(require("./api/Transaction"), exports);
38
37
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,aAAa;AACb,2DAAyC;AACzC,wDAAsC;AACtC,mEAAiD;AACjD,sDAAoC;AACpC,qDAAmC;AAEnC,2BAA2B;AAC3B,gEAA8C;AAC9C,4EAA0D;AAC1D,0DAAwC;AACxC,yDAAuC;AAEvC,2CAAyB;AAEzB,MAAM;AACN,uCAAiD;AAAxC,iHAAA,OAAO,OAAU;AAC1B,iDAA2D;AAAlD,2HAAA,OAAO,OAAe"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,aAAa;AACb,2DAAyC;AACzC,wDAAsC;AACtC,mEAAiD;AACjD,sDAAoC;AACpC,qDAAmC;AAEnC,2BAA2B;AAC3B,gEAA8C;AAC9C,4EAA0D;AAC1D,0DAAwC;AACxC,yDAAuC;AAEvC,2CAAyB;AAEzB,MAAM;AACN,uCAAiD;AAAxC,iHAAA,OAAO,OAAU;AAC1B,oDAAkC"}
@@ -5,10 +5,6 @@ type ConstraintBase<T extends string, V extends Record<string, unknown> | null>
5
5
  type: T;
6
6
  value: V;
7
7
  };
8
- /**
9
- * All the possible operators inside a constraint.
10
- */
11
- export type ConstraintOperator = ">" | ">=" | "<" | "<=";
12
8
  /**
13
9
  * THe type of a constraint message when one is present.
14
10
  */
@@ -26,8 +22,51 @@ export type RegexpConstraint = ConstraintBase<"RegexpConstraint", {
26
22
  flags: number;
27
23
  msg: ConstraintMessage;
28
24
  }>;
25
+ /**
26
+ * Reference to an attribute used in constraints.
27
+ *
28
+ * @property \_\_attribute\_\_ name of the attribute in the same entity
29
+ */
30
+ export interface Attribute {
31
+ __attribute__: string;
32
+ }
33
+ export interface TimeDelta {
34
+ days: number;
35
+ seconds: number;
36
+ microseconds: number;
37
+ }
38
+ /**
39
+ * Represents a date relative to the current date at the time of the check.
40
+ *
41
+ * @property \_\_today\_\_ always true
42
+ * @property offset delta to current date at the time of the check
43
+ * @property type name of the Python class used to do the comparison
44
+ */
45
+ export interface Today {
46
+ __today__: true;
47
+ offset: TimeDelta | null;
48
+ type: "Datetime" | "TZDatetime" | "Date";
49
+ }
50
+ /**
51
+ * Represents a datetime relative to the current datetime at the time of the check.
52
+ *
53
+ * @property \_\_now\_\_ always true
54
+ * @property offset delta to current date at the time of the check
55
+ */
56
+ export interface Now {
57
+ __now__: true;
58
+ offset: TimeDelta;
59
+ }
60
+ /**
61
+ * All the possible operators inside a constraint.
62
+ */
63
+ export type ConstraintOperator = ">" | ">=" | "<" | "<=";
64
+ /**
65
+ * @property value.boundary boudary value to compare the attribut
66
+ *
67
+ */
29
68
  export type BoundaryConstraint = ConstraintBase<"BoundaryConstraint", {
30
- boundary: number | null;
69
+ boundary: Attribute | Today | Now | number | null;
31
70
  op: ConstraintOperator;
32
71
  msg: ConstraintMessage;
33
72
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"Constraints.d.ts","sourceRoot":"","sources":["../../../src/schema/raw/Constraints.ts"],"names":[],"mappings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client for CubicWeb API",
4
4
  "author": "Logilab",
5
- "version": "1.9.0",
5
+ "version": "2.1.0",
6
6
  "license": "LGPL-3.0-or-later",
7
7
  "main": "lib/index.js",
8
8
  "types": "lib/index.d.ts",
package/src/api/Api.ts CHANGED
@@ -1,16 +1,22 @@
1
1
  import { ValidationError } from "../Errors";
2
2
  import { RawSchema } from "../schema/raw/Schema";
3
+ import {
4
+ TransactionResult,
5
+ Transaction,
6
+ isTransactionQueryRef,
7
+ } from "./Transaction";
3
8
 
4
9
  /**
5
10
  * Type representing an RQL request and its associated parameters.
6
11
  */
7
12
  export type RQLQuery = [string, RQLParams];
8
13
 
14
+ export type RQLParamValue = string | number | boolean | null;
9
15
  /**
10
16
  * Type representing RQL parameters to send along a request.
11
17
  */
12
18
  export interface RQLParams {
13
- [key: string]: string | number;
19
+ [key: string]: RQLParamValue;
14
20
  }
15
21
 
16
22
  /**
@@ -63,12 +69,7 @@ export default class Api {
63
69
  private _schemaApiUrl: string;
64
70
  private _loginApiUrl: string;
65
71
  private _currentUserApiUrl: string;
66
- private _transactionApiUrl = {
67
- begin: "",
68
- execute: "",
69
- commit: "",
70
- rollback: "",
71
- };
72
+ private _transactionApiUrl: string;
72
73
 
73
74
  /**
74
75
  * Class used to handle requests to the CubicWeb API.
@@ -86,11 +87,7 @@ export default class Api {
86
87
  this._schemaApiUrl = this.getApiRoute("schema");
87
88
  this._loginApiUrl = this.getApiRoute("login");
88
89
  this._currentUserApiUrl = this.getApiRoute("current-user");
89
- Object.keys(this._transactionApiUrl).forEach(
90
- (k) =>
91
- (this._transactionApiUrl[k as keyof typeof this._transactionApiUrl] =
92
- this.getApiRoute(`transaction/${k}`))
93
- );
90
+ this._transactionApiUrl = this.getApiRoute("transaction");
94
91
  }
95
92
 
96
93
  get apiUrl() {
@@ -167,70 +164,33 @@ export default class Api {
167
164
  });
168
165
  }
169
166
 
170
- /**
171
- * Starts a new transaction.
172
- *
173
- * @returns A promise with the transaction uuid
174
- */
175
- async transactionBegin(): Promise<string> {
176
- return nonNullFetchApi<string>(this._transactionApiUrl.begin, {
177
- method: "POST",
178
- credentials: "include",
179
- });
180
- }
181
-
182
- /**
183
- * Executes a RQL request as part of a transaction identified by the given uuid.
184
- *
185
- * @param uuid The transaction's uuid
186
- * @param query The RQL query to send
187
- * @param params The additional parameters for the request
188
- * @returns A promise with the request's result set
189
- */
190
- async transactionExecute(
191
- uuid: string,
192
- query: string,
193
- params: RQLParams
194
- ): Promise<ResultSet | null> {
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
- }
204
- }
205
-
206
- /**
207
- * Commits the transaction identified by the given uuid.
208
- *
209
- * @param uuid The transaction's uuid
210
- */
211
- async transactionCommit(uuid: string): Promise<null> {
212
- try {
213
- return await fetchApi<null>(this._transactionApiUrl.commit, {
167
+ async executeTransaction(
168
+ transaction: Transaction
169
+ ): Promise<TransactionResult> {
170
+ const data = transaction.queries.map((transactionQuery) => ({
171
+ query: transactionQuery.query,
172
+ params: Object.fromEntries(
173
+ Object.entries(transactionQuery.params).map(([key, value]) => [
174
+ key,
175
+ isTransactionQueryRef(value)
176
+ ? {
177
+ queryIndex: value.queryIndex,
178
+ row: value.row,
179
+ column: value.column,
180
+ }
181
+ : value,
182
+ ])
183
+ ),
184
+ }));
185
+ const resultSets = await nonNullFetchApi<ReadonlyArray<ResultSet>>(
186
+ this._transactionApiUrl,
187
+ {
214
188
  method: "POST",
215
- body: JSON.stringify({ uuid }),
216
189
  credentials: "include",
217
- });
218
- } catch (e) {
219
- this.handleUserErrors(e);
220
- }
221
- }
222
-
223
- /**
224
- * Rollbacks the transaction identified by the given uuid.
225
- *
226
- * @param uuid The transaction's uuid
227
- */
228
- async transactionRollback(uuid: string): Promise<null> {
229
- return fetchApi<null>(this._transactionApiUrl.rollback, {
230
- method: "POST",
231
- body: JSON.stringify({ uuid }),
232
- credentials: "include",
233
- });
190
+ body: JSON.stringify(data),
191
+ }
192
+ );
193
+ return new TransactionResult(resultSets);
234
194
  }
235
195
 
236
196
  private handleUserErrors(error: unknown): never {
package/src/api/Client.ts CHANGED
@@ -1,12 +1,18 @@
1
1
  import { Schema } from "../schema/classes/Schema";
2
2
  import Api, { RQLParams, ResultSet, CurrentUser } from "./Api";
3
- import Transaction from "./Transaction";
3
+ import {
4
+ NativeTransactionBackend,
5
+ Transaction,
6
+ TransactionBackend,
7
+ TransactionResult,
8
+ } from "./Transaction";
4
9
 
5
10
  /**
6
11
  * Class used to communicate with a CubicWeb instance's API.
7
12
  */
8
13
  export default class Client {
9
14
  private api: Api;
15
+ private transactionBackend: TransactionBackend;
10
16
 
11
17
  /**
12
18
  * Class used to communicate with a CubicWeb instance's API.
@@ -15,8 +21,17 @@ export default class Client {
15
21
  * Example: if you can retrieve the schema with https://example.com/api/v1/schema,
16
22
  * use https://example.com/api as `apiUrl`.
17
23
  */
18
- constructor(apiUrl: string) {
24
+ constructor(
25
+ apiUrl: string,
26
+ options: { transactionBackend?: TransactionBackend } = {}
27
+ ) {
19
28
  this.api = new Api(apiUrl);
29
+ const { transactionBackend } = options;
30
+ if (transactionBackend === undefined) {
31
+ this.transactionBackend = new NativeTransactionBackend(this.api);
32
+ } else {
33
+ this.transactionBackend = transactionBackend;
34
+ }
20
35
  }
21
36
 
22
37
  get apiUrl() {
@@ -65,31 +80,12 @@ export default class Client {
65
80
  }
66
81
 
67
82
  /**
68
- * Creates a new transaction and exposes the Transaction object in the given callback.
69
- * Use this callback to execute RQL requests as part of the transaction.
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.
73
- *
74
- * @param callback Function to execute transaction requests in.
75
- * @returns The promise returned by the callback
83
+ * @param transaction Transaction to execute
84
+ * @returns A promise fulfilled when the transaction is completed
76
85
  */
77
- async transaction<T>(callback: (tr: Transaction) => Promise<T>): Promise<T> {
78
- const transaction = new Transaction(this.api);
79
- await transaction.begin();
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
- }
90
- if (!transaction.isClosed()) {
91
- await transaction.commit();
92
- }
93
- return result;
86
+ async executeTransaction(
87
+ transaction: Transaction
88
+ ): Promise<TransactionResult> {
89
+ return await this.transactionBackend.execute(transaction);
94
90
  }
95
91
  }
@@ -1,87 +1,75 @@
1
- import { TransactionClosedError } from "../Errors";
2
- import Api, { RQLParams } from "./Api";
1
+ import Api, { ResultSet, RQLParamValue } from "./Api";
3
2
 
4
- /**
5
- * Class used to handle CubicWeb's transactions.
6
- * A transaction allows to execute several RQL requests without altering the database until all
7
- * changes are committed.
8
- *
9
- * You should never have to create this object yourself.
10
- * Instead, retrieve this object from the methods in the `Client` class.
11
- */
12
- export default class Transaction {
13
- private _uuid: string | null = null;
14
- private _closed = false;
3
+ export class Transaction {
4
+ private _queries: Array<TransactionQuery> = [];
15
5
 
16
- /**
17
- * Class used to handle CubicWeb's transactions.
18
- * A transaction allows to execute several RQL requests without altering the database until all
19
- * changes are committed.
20
- *
21
- * You should never have to create this object yourself.
22
- * Instead, retrieve this object from the methods in the `Client` class.
23
- *
24
- * @param api The API object used to communicate with the CubicWeb backend.
25
- */
26
- constructor(private api: Api) {}
27
-
28
- /**
29
- * @returns True if the connection is closed.
30
- */
31
- isClosed() {
32
- return this._closed;
6
+ push(
7
+ query: string,
8
+ params: Record<string, RQLParamValue | TransactionQueryRef>
9
+ ): TransactionQuery {
10
+ const stackedQuery = new TransactionQuery(
11
+ query,
12
+ params,
13
+ this._queries.length
14
+ );
15
+ this._queries.push(stackedQuery);
16
+ return stackedQuery;
33
17
  }
34
18
 
35
- /**
36
- * This transaction unique identifier.
37
- */
38
- get uuid() {
39
- return this._uuid;
19
+ get queries(): ReadonlyArray<TransactionQuery> {
20
+ return this._queries;
40
21
  }
22
+ }
41
23
 
42
- /**
43
- * Begins a new transaction an retrieves the associated uuid.
44
- */
45
- async begin() {
46
- this._closed = false;
47
- this._uuid = await this.api.transactionBegin();
48
- }
24
+ export class TransactionResult {
25
+ constructor(private resultSets: ReadonlyArray<ResultSet>) {}
49
26
 
50
- /**
51
- * Executes the given query and waits for the response.
52
- * Make sure you called `begin` before using this method.
53
- * As this is a transaction changes will only be applied when you call the `commit` method.
54
- *
55
- * @param query The RQL query to send
56
- * @param params The additional parameters for the request
57
- * @returns A promise with the request's result set
58
- */
59
- async execute(query: string, params: RQLParams = {}) {
60
- this.preventUsageIfClosed();
61
- return await this.api.transactionExecute(this.uuid, query, params);
27
+ resolve(ref: TransactionQueryRef) {
28
+ return this.resultSets[ref.queryIndex][ref.row][ref.column];
62
29
  }
30
+ }
63
31
 
64
- /**
65
- * Commits the transaction to apply all the RQL queries sent with `execute`.
66
- */
67
- async commit() {
68
- this.preventUsageIfClosed();
69
- await this.api.transactionCommit(this.uuid);
70
- this._closed = true;
71
- }
32
+ export interface TransactionQueryRef {
33
+ queryIndex: number;
34
+ row: number;
35
+ column: number;
36
+ }
72
37
 
73
- /**
74
- * Rollbacks all the queries sent with `execute` and closes the transaction.
75
- */
76
- async rollback() {
77
- this.preventUsageIfClosed();
78
- await this.api.transactionRollback(this.uuid);
79
- this._closed = true;
38
+ export class TransactionQuery {
39
+ constructor(
40
+ public readonly query: string,
41
+ public readonly params: Record<string, RQLParamValue | TransactionQueryRef>,
42
+ public readonly index: number
43
+ ) {}
44
+
45
+ ref(row = 0, column = 0): TransactionQueryRef {
46
+ return {
47
+ queryIndex: this.index,
48
+ row,
49
+ column,
50
+ };
80
51
  }
52
+ }
53
+
54
+ export function isTransactionQueryRef(
55
+ value: RQLParamValue | TransactionQueryRef
56
+ ): value is TransactionQueryRef {
57
+ return (
58
+ typeof value === "object" &&
59
+ value !== null &&
60
+ ["queryIndex", "row", "column"].every((key) =>
61
+ Object.keys(value).includes(key)
62
+ )
63
+ );
64
+ }
65
+
66
+ export interface TransactionBackend {
67
+ execute(transaction: Transaction): Promise<TransactionResult>;
68
+ }
81
69
 
82
- private preventUsageIfClosed(): asserts this is { uuid: string } {
83
- if (this.isClosed()) {
84
- throw new TransactionClosedError();
85
- }
70
+ export class NativeTransactionBackend implements TransactionBackend {
71
+ constructor(private _api: Api) {}
72
+ async execute(transaction: Transaction): Promise<TransactionResult> {
73
+ return this._api.executeTransaction(transaction);
86
74
  }
87
75
  }
package/src/index.ts CHANGED
@@ -15,7 +15,7 @@ export * from "./Errors";
15
15
 
16
16
  // API
17
17
  export { default as Client } from "./api/Client";
18
- export { default as Transaction } from "./api/Transaction";
18
+ export * from "./api/Transaction";
19
19
  export {
20
20
  RQLQuery,
21
21
  RQLParams,
@@ -9,11 +9,6 @@ type ConstraintBase<
9
9
  value: V;
10
10
  };
11
11
 
12
- /**
13
- * All the possible operators inside a constraint.
14
- */
15
- export type ConstraintOperator = ">" | ">=" | "<" | "<=";
16
-
17
12
  /**
18
13
  * THe type of a constraint message when one is present.
19
14
  */
@@ -34,9 +29,61 @@ export type RegexpConstraint = ConstraintBase<
34
29
  { regexp: string; flags: number; msg: ConstraintMessage }
35
30
  >;
36
31
 
32
+ /**
33
+ * Reference to an attribute used in constraints.
34
+ *
35
+ * @property \_\_attribute\_\_ name of the attribute in the same entity
36
+ */
37
+ export interface Attribute {
38
+ __attribute__: string;
39
+ }
40
+
41
+ export interface TimeDelta {
42
+ days: number;
43
+ seconds: number;
44
+ microseconds: number;
45
+ }
46
+
47
+ /**
48
+ * Represents a date relative to the current date at the time of the check.
49
+ *
50
+ * @property \_\_today\_\_ always true
51
+ * @property offset delta to current date at the time of the check
52
+ * @property type name of the Python class used to do the comparison
53
+ */
54
+ export interface Today {
55
+ __today__: true;
56
+ offset: TimeDelta | null;
57
+ type: "Datetime" | "TZDatetime" | "Date";
58
+ }
59
+
60
+ /**
61
+ * Represents a datetime relative to the current datetime at the time of the check.
62
+ *
63
+ * @property \_\_now\_\_ always true
64
+ * @property offset delta to current date at the time of the check
65
+ */
66
+ export interface Now {
67
+ __now__: true;
68
+ offset: TimeDelta;
69
+ }
70
+
71
+ /**
72
+ * All the possible operators inside a constraint.
73
+ */
74
+ export type ConstraintOperator = ">" | ">=" | "<" | "<=";
75
+
76
+ /**
77
+ * @property value.boundary boudary value to compare the attribut
78
+ *
79
+ */
37
80
  export type BoundaryConstraint = ConstraintBase<
38
81
  "BoundaryConstraint",
39
- { boundary: number | null; op: ConstraintOperator; msg: ConstraintMessage }
82
+ {
83
+ boundary: Attribute | Today | Now | number | null;
84
+ op: ConstraintOperator;
85
+ msg: ConstraintMessage;
86
+ }
40
87
  >;
41
88
  export type IntervalBoundConstraint = ConstraintBase<
42
89
  "IntervalBoundConstraint",