@cubicweb/client 1.0.3 → 1.1.1
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 +7 -0
- package/lib/Errors.d.ts.map +1 -0
- package/lib/Errors.js +18 -0
- package/lib/Errors.js.map +1 -0
- package/lib/api/Api.d.ts +27 -0
- package/lib/api/Api.d.ts.map +1 -0
- package/lib/api/Api.js +131 -0
- package/lib/api/Api.js.map +1 -0
- package/lib/api/Client.d.ts +12 -0
- package/lib/api/Client.d.ts.map +1 -0
- package/lib/api/Client.js +51 -0
- package/lib/api/Client.js.map +1 -0
- package/lib/api/Transaction.d.ts +15 -0
- package/lib/api/Transaction.d.ts.map +1 -0
- package/lib/api/Transaction.js +58 -0
- package/lib/api/Transaction.js.map +1 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +34 -0
- package/lib/index.js.map +1 -0
- package/lib/schema/Schema.d.ts +147 -0
- package/lib/schema/Schema.d.ts.map +1 -0
- package/lib/schema/Schema.js +240 -0
- package/lib/schema/Schema.js.map +1 -0
- package/lib/schema/SchemaJSON.d.ts +121 -0
- package/lib/schema/SchemaJSON.d.ts.map +1 -0
- package/lib/schema/SchemaJSON.js +3 -0
- package/lib/schema/SchemaJSON.js.map +1 -0
- package/package.json +1 -1
- package/src/Errors.ts +0 -13
- package/src/api/Api.ts +72 -25
- package/src/api/Client.ts +5 -1
- package/src/api/Transaction.ts +1 -3
- package/src/schema/Schema.ts +25 -87
package/lib/Errors.d.ts
ADDED
|
@@ -0,0 +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"}
|
package/lib/Errors.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionClosedError = exports.InconsistentSchemaError = void 0;
|
|
4
|
+
class InconsistentSchemaError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(`Inconsistent schema: ${message}`);
|
|
7
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.InconsistentSchemaError = InconsistentSchemaError;
|
|
11
|
+
class TransactionClosedError extends Error {
|
|
12
|
+
constructor() {
|
|
13
|
+
super("Trying to use a closed transaction");
|
|
14
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.TransactionClosedError = TransactionClosedError;
|
|
18
|
+
//# sourceMappingURL=Errors.js.map
|
|
@@ -0,0 +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"}
|
package/lib/api/Api.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { RawSchema } from "../schema/SchemaJSON";
|
|
2
|
+
export declare type RQLQuery = [string, RQLParams];
|
|
3
|
+
export interface RQLParams {
|
|
4
|
+
[key: string]: string | number;
|
|
5
|
+
}
|
|
6
|
+
export declare type RqlRow = Array<string | number | boolean | null>;
|
|
7
|
+
export declare type ResultSet = Array<RqlRow>;
|
|
8
|
+
export declare type ApiError = {
|
|
9
|
+
error: string;
|
|
10
|
+
message: string;
|
|
11
|
+
};
|
|
12
|
+
export declare type ApiErrorResponse = {
|
|
13
|
+
status: number;
|
|
14
|
+
} & ApiError;
|
|
15
|
+
export default class Api {
|
|
16
|
+
private apiUrl;
|
|
17
|
+
private transactionApiUrl;
|
|
18
|
+
constructor(apiUrl: string);
|
|
19
|
+
execute(query: string, params: RQLParams): Promise<ResultSet>;
|
|
20
|
+
schema(): Promise<RawSchema>;
|
|
21
|
+
login(login: string, password: string): Promise<boolean>;
|
|
22
|
+
transactionBegin(): Promise<string>;
|
|
23
|
+
transactionExecute(uuid: string, query: string, params: RQLParams): Promise<ResultSet>;
|
|
24
|
+
transactionCommit(uuid: string): Promise<null>;
|
|
25
|
+
transactionRollback(uuid: string): Promise<null>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=Api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Api.d.ts","sourceRoot":"","sources":["../../src/api/Api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,oBAAY,QAAQ,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAE3C,MAAM,WAAW,SAAS;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;CAChC;AAED,oBAAY,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,CAAC;AAC7D,oBAAY,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;AACtC,oBAAY,QAAQ,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAC1D,oBAAY,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,QAAQ,CAAC;AAEb,MAAM,CAAC,OAAO,OAAO,GAAG;IACtB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,iBAAiB,CAAS;gBAEtB,MAAM,EAAE,MAAM;IAKpB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IAQ7D,MAAM,IAAI,OAAO,CAAC,SAAS,CAAC;IAO5B,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAaxD,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IAQnC,kBAAkB,CACtB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,SAAS,GAChB,OAAO,CAAC,SAAS,CAAC;IAQf,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ9C,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAOvD"}
|
package/lib/api/Api.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
class Api {
|
|
13
|
+
constructor(apiUrl) {
|
|
14
|
+
this.apiUrl = `${apiUrl}/v1`;
|
|
15
|
+
this.transactionApiUrl = `${this.apiUrl}/transaction`;
|
|
16
|
+
}
|
|
17
|
+
execute(query, params) {
|
|
18
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
return nonNullFetchApi(`${this.apiUrl}/rql`, {
|
|
20
|
+
method: "POST",
|
|
21
|
+
body: JSON.stringify({ query, params }),
|
|
22
|
+
credentials: "include", // FIXME is it secure?
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
schema() {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
return nonNullFetchApi(`${this.apiUrl}/schema`, {
|
|
29
|
+
method: "GET",
|
|
30
|
+
credentials: "include",
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
login(login, password) {
|
|
35
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
return fetchApi(`${this.apiUrl}/login`, {
|
|
37
|
+
method: "POST",
|
|
38
|
+
body: JSON.stringify({
|
|
39
|
+
login,
|
|
40
|
+
password,
|
|
41
|
+
}),
|
|
42
|
+
credentials: "include",
|
|
43
|
+
})
|
|
44
|
+
.then(() => true)
|
|
45
|
+
.catch(() => false);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
transactionBegin() {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
return nonNullFetchApi(this.transactionApiUrl, {
|
|
51
|
+
method: "POST",
|
|
52
|
+
body: JSON.stringify({ action: "begin" }),
|
|
53
|
+
credentials: "include",
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
transactionExecute(uuid, query, params) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
return nonNullFetchApi(this.transactionApiUrl, {
|
|
60
|
+
method: "POST",
|
|
61
|
+
body: JSON.stringify({ action: "execute", uuid, query, params }),
|
|
62
|
+
credentials: "include",
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
transactionCommit(uuid) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
return fetchApi(this.transactionApiUrl, {
|
|
69
|
+
method: "POST",
|
|
70
|
+
body: JSON.stringify({ action: "commit", uuid }),
|
|
71
|
+
credentials: "include",
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
transactionRollback(uuid) {
|
|
76
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
return fetchApi(this.transactionApiUrl, {
|
|
78
|
+
method: "POST",
|
|
79
|
+
body: JSON.stringify({ action: "commit", uuid }),
|
|
80
|
+
credentials: "include",
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.default = Api;
|
|
86
|
+
const nonNullFetchApi = (input, init) => {
|
|
87
|
+
return new Promise((resolve, reject) => fetchApi(input, init)
|
|
88
|
+
.then((v) => {
|
|
89
|
+
if (v == null) {
|
|
90
|
+
const error = {
|
|
91
|
+
status: 500,
|
|
92
|
+
error: "Unexpected null response",
|
|
93
|
+
message: "Response was null but a value was expected",
|
|
94
|
+
};
|
|
95
|
+
reject(error);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
resolve(v);
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
.catch(reject));
|
|
102
|
+
};
|
|
103
|
+
const fetchApi = (input, init) => {
|
|
104
|
+
return new Promise((resolve, reject) => fetch(input, init).then((response) => {
|
|
105
|
+
const status = response.status;
|
|
106
|
+
if (status >= 200 && status < 300) {
|
|
107
|
+
if (status === 204) {
|
|
108
|
+
resolve(null);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
response
|
|
112
|
+
.json()
|
|
113
|
+
.then(resolve)
|
|
114
|
+
.catch((e) => {
|
|
115
|
+
console.error(e);
|
|
116
|
+
resolve(null);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
response.json().then((data) => {
|
|
122
|
+
reject({
|
|
123
|
+
status,
|
|
124
|
+
error: data.error,
|
|
125
|
+
message: data.message,
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}));
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=Api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Api.js","sourceRoot":"","sources":["../../src/api/Api.ts"],"names":[],"mappings":";;;;;;;;;;;AAeA,MAAqB,GAAG;IAItB,YAAY,MAAc;QACxB,IAAI,CAAC,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC;QAC7B,IAAI,CAAC,iBAAiB,GAAG,GAAG,IAAI,CAAC,MAAM,cAAc,CAAC;IACxD,CAAC;IAEK,OAAO,CAAC,KAAa,EAAE,MAAiB;;YAC5C,OAAO,eAAe,CAAY,GAAG,IAAI,CAAC,MAAM,MAAM,EAAE;gBACtD,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;gBACvC,WAAW,EAAE,SAAS,EAAE,sBAAsB;aAC/C,CAAC,CAAC;QACL,CAAC;KAAA;IAEK,MAAM;;YACV,OAAO,eAAe,CAAY,GAAG,IAAI,CAAC,MAAM,SAAS,EAAE;gBACzD,MAAM,EAAE,KAAK;gBACb,WAAW,EAAE,SAAS;aACvB,CAAC,CAAC;QACL,CAAC;KAAA;IAEK,KAAK,CAAC,KAAa,EAAE,QAAgB;;YACzC,OAAO,QAAQ,CAAO,GAAG,IAAI,CAAC,MAAM,QAAQ,EAAE;gBAC5C,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;oBACnB,KAAK;oBACL,QAAQ;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AAc,EAAE,EAAE;gBACtC,MAAM,CAAC;oBACL,MAAM;oBACN,KAAK,EAAE,IAAI,CAAC,KAAK;oBACjB,OAAO,EAAE,IAAI,CAAC,OAAO;iBACtB,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;SACJ;IACH,CAAC,CAAC,CACL,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Schema } from "../schema/Schema";
|
|
2
|
+
import { RQLParams } from "./Api";
|
|
3
|
+
import Transaction from "./Transaction";
|
|
4
|
+
export default class Client {
|
|
5
|
+
private api;
|
|
6
|
+
constructor(apiUrl: string);
|
|
7
|
+
execute(query: string, params?: RQLParams): Promise<import("./Api").ResultSet>;
|
|
8
|
+
schema(): Promise<Schema<import("..").EntityRawSchemaArray, import("..").RelationDefinitionRawSchemaArray<import("..").EntityRawSchemaArray>>>;
|
|
9
|
+
login(login: string, password: string): Promise<boolean>;
|
|
10
|
+
transaction<T>(callback: (tr: Transaction) => Promise<T>): Promise<T>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=Client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Client.d.ts","sourceRoot":"","sources":["../../src/api/Client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,OAAO,CAAC,GAAG,CAAM;gBAEL,MAAM,EAAE,MAAM;IAIpB,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,SAAc;IAI7C,MAAM;IAKN,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAIrC,WAAW,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAS5E"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const Schema_1 = require("../schema/Schema");
|
|
16
|
+
const Api_1 = __importDefault(require("./Api"));
|
|
17
|
+
const Transaction_1 = __importDefault(require("./Transaction"));
|
|
18
|
+
class Client {
|
|
19
|
+
constructor(apiUrl) {
|
|
20
|
+
this.api = new Api_1.default(apiUrl);
|
|
21
|
+
}
|
|
22
|
+
execute(query, params = {}) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
return yield this.api.execute(query, params);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
schema() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const schema = yield this.api.schema();
|
|
30
|
+
return new Schema_1.Schema(schema);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
login(login, password) {
|
|
34
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
return yield this.api.login(login, password);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
transaction(callback) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const transaction = new Transaction_1.default(this.api);
|
|
41
|
+
yield transaction.begin();
|
|
42
|
+
const result = yield callback(transaction);
|
|
43
|
+
if (!transaction.isClosed()) {
|
|
44
|
+
transaction.commit();
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.default = Client;
|
|
51
|
+
//# sourceMappingURL=Client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Client.js","sourceRoot":"","sources":["../../src/api/Client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,6CAA0C;AAC1C,gDAAuC;AACvC,gEAAwC;AAExC,MAAqB,MAAM;IAGzB,YAAY,MAAc;QACxB,IAAI,CAAC,GAAG,GAAG,IAAI,aAAG,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC;IAEK,OAAO,CAAC,KAAa,EAAE,SAAoB,EAAE;;YACjD,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC/C,CAAC;KAAA;IAEK,MAAM;;YACV,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;YACvC,OAAO,IAAI,eAAM,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;KAAA;IAEK,KAAK,CAAC,KAAa,EAAE,QAAgB;;YACzC,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC/C,CAAC;KAAA;IAEK,WAAW,CAAI,QAAyC;;YAC5D,MAAM,WAAW,GAAG,IAAI,qBAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YAC9C,MAAM,WAAW,CAAC,KAAK,EAAE,CAAC;YAC1B,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,WAAW,CAAC,CAAC;YAC3C,IAAI,CAAC,WAAW,CAAC,QAAQ,EAAE,EAAE;gBAC3B,WAAW,CAAC,MAAM,EAAE,CAAC;aACtB;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;CACF;AA7BD,yBA6BC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import Api, { RQLParams } from "./Api";
|
|
2
|
+
export default class Transaction {
|
|
3
|
+
private api;
|
|
4
|
+
private _uuid;
|
|
5
|
+
private _closed;
|
|
6
|
+
constructor(api: Api);
|
|
7
|
+
isClosed(): boolean;
|
|
8
|
+
get uuid(): string | null;
|
|
9
|
+
begin(): Promise<void>;
|
|
10
|
+
execute(query: string, params?: RQLParams): Promise<import("./Api").ResultSet>;
|
|
11
|
+
commit(): Promise<void>;
|
|
12
|
+
rollback(): Promise<void>;
|
|
13
|
+
private preventUsageIfClosed;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=Transaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Transaction.d.ts","sourceRoot":"","sources":["../../src/api/Transaction.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,EAAE,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,CAAC,OAAO,OAAO,WAAW;IAIlB,OAAO,CAAC,GAAG;IAHvB,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,OAAO,CAAS;gBAEJ,GAAG,EAAE,GAAG;IAE5B,QAAQ;IAIR,IAAI,IAAI,kBAEP;IAEK,KAAK;IAKL,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,SAAc;IAK7C,MAAM;IAMN,QAAQ;IAMd,OAAO,CAAC,oBAAoB;CAK7B"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const Errors_1 = require("../Errors");
|
|
13
|
+
class Transaction {
|
|
14
|
+
constructor(api) {
|
|
15
|
+
this.api = api;
|
|
16
|
+
this._uuid = null;
|
|
17
|
+
this._closed = false;
|
|
18
|
+
}
|
|
19
|
+
isClosed() {
|
|
20
|
+
return this._closed;
|
|
21
|
+
}
|
|
22
|
+
get uuid() {
|
|
23
|
+
return this._uuid;
|
|
24
|
+
}
|
|
25
|
+
begin() {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
this._closed = false;
|
|
28
|
+
this._uuid = yield this.api.transactionBegin();
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
execute(query, params = {}) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
this.preventUsageIfClosed();
|
|
34
|
+
return yield this.api.transactionExecute(this.uuid, query, params);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
commit() {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
this.preventUsageIfClosed();
|
|
40
|
+
yield this.api.transactionCommit(this.uuid);
|
|
41
|
+
this._closed = true;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
rollback() {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
this.preventUsageIfClosed();
|
|
47
|
+
yield this.api.transactionRollback(this.uuid);
|
|
48
|
+
this._closed = true;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
preventUsageIfClosed() {
|
|
52
|
+
if (this.isClosed()) {
|
|
53
|
+
throw new Errors_1.TransactionClosedError();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.default = Transaction;
|
|
58
|
+
//# sourceMappingURL=Transaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Transaction.js","sourceRoot":"","sources":["../../src/api/Transaction.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,sCAAmD;AAGnD,MAAqB,WAAW;IAI9B,YAAoB,GAAQ;QAAR,QAAG,GAAH,GAAG,CAAK;QAHpB,UAAK,GAAkB,IAAI,CAAC;QAC5B,YAAO,GAAG,KAAK,CAAC;IAEO,CAAC;IAEhC,QAAQ;QACN,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAEK,KAAK;;YACT,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;YACrB,IAAI,CAAC,KAAK,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QACjD,CAAC;KAAA;IAEK,OAAO,CAAC,KAAa,EAAE,SAAoB,EAAE;;YACjD,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC5B,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QACrE,CAAC;KAAA;IAEK,MAAM;;YACV,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC5B,MAAM,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC5C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACtB,CAAC;KAAA;IAEK,QAAQ;;YACZ,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC5B,MAAM,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAC9C,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACtB,CAAC;KAAA;IAEO,oBAAoB;QAC1B,IAAI,IAAI,CAAC,QAAQ,EAAE,EAAE;YACnB,MAAM,IAAI,+BAAsB,EAAE,CAAC;SACpC;IACH,CAAC;CACF;AAzCD,8BAyCC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { getLooseSchema, Schema, EntitySchema, RelationDefinitionSchema, } from "./schema/Schema";
|
|
2
|
+
export * from "./schema/SchemaJSON";
|
|
3
|
+
export * from "./Errors";
|
|
4
|
+
export { default as Client } from "./api/Client";
|
|
5
|
+
export { default as Api } from "./api/Api";
|
|
6
|
+
export { default as Transaction } from "./api/Transaction";
|
|
7
|
+
export { RQLQuery, RQLParams, RqlRow, ResultSet, ApiErrorResponse, } from "./api/Api";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,MAAM,EACN,YAAY,EACZ,wBAAwB,GACzB,MAAM,iBAAiB,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,UAAU,CAAC;AACzB,OAAO,EAAE,OAAO,IAAI,MAAM,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,OAAO,IAAI,GAAG,EAAE,MAAM,WAAW,CAAC;AAC3C,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"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.Transaction = exports.Api = exports.Client = exports.RelationDefinitionSchema = exports.EntitySchema = exports.Schema = exports.getLooseSchema = void 0;
|
|
21
|
+
var Schema_1 = require("./schema/Schema");
|
|
22
|
+
Object.defineProperty(exports, "getLooseSchema", { enumerable: true, get: function () { return Schema_1.getLooseSchema; } });
|
|
23
|
+
Object.defineProperty(exports, "Schema", { enumerable: true, get: function () { return Schema_1.Schema; } });
|
|
24
|
+
Object.defineProperty(exports, "EntitySchema", { enumerable: true, get: function () { return Schema_1.EntitySchema; } });
|
|
25
|
+
Object.defineProperty(exports, "RelationDefinitionSchema", { enumerable: true, get: function () { return Schema_1.RelationDefinitionSchema; } });
|
|
26
|
+
__exportStar(require("./schema/SchemaJSON"), exports);
|
|
27
|
+
__exportStar(require("./Errors"), exports);
|
|
28
|
+
var Client_1 = require("./api/Client");
|
|
29
|
+
Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return __importDefault(Client_1).default; } });
|
|
30
|
+
var Api_1 = require("./api/Api");
|
|
31
|
+
Object.defineProperty(exports, "Api", { enumerable: true, get: function () { return __importDefault(Api_1).default; } });
|
|
32
|
+
var Transaction_1 = require("./api/Transaction");
|
|
33
|
+
Object.defineProperty(exports, "Transaction", { enumerable: true, get: function () { return __importDefault(Transaction_1).default; } });
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,0CAKyB;AAJvB,wGAAA,cAAc,OAAA;AACd,gGAAA,MAAM,OAAA;AACN,sGAAA,YAAY,OAAA;AACZ,kHAAA,wBAAwB,OAAA;AAE1B,sDAAoC;AACpC,2CAAyB;AACzB,uCAAiD;AAAxC,iHAAA,OAAO,OAAU;AAC1B,iCAA2C;AAAlC,2GAAA,OAAO,OAAO;AACvB,iDAA2D;AAAlD,2HAAA,OAAO,OAAe"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { Cardinality } from "..";
|
|
2
|
+
import { RawSchema, RelationDefinitionRawSchema, RelationDefinitionRawSchemaArray, EntityRawSchemaArray, EntityRawSchemaByType, IsLooseSchema, IsETypeInStrictSchema } from "./SchemaJSON";
|
|
3
|
+
declare const rawSchemaKey: unique symbol;
|
|
4
|
+
/**
|
|
5
|
+
* Returns the given schema using loose typing.
|
|
6
|
+
* Can be useful when working for generic schemas
|
|
7
|
+
*
|
|
8
|
+
* @param schema The schema to create a loose type for
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export declare const getLooseSchema: <E extends EntityRawSchemaArray = EntityRawSchemaArray, R extends RelationDefinitionRawSchemaArray<E> = RelationDefinitionRawSchemaArray<E>>(schema: Schema<E, R>) => Schema<EntityRawSchemaArray, RelationDefinitionRawSchemaArray<EntityRawSchemaArray>>;
|
|
12
|
+
/**
|
|
13
|
+
* Wrapper around the raw JSON Schema
|
|
14
|
+
*/
|
|
15
|
+
export declare class Schema<E extends EntityRawSchemaArray = EntityRawSchemaArray, // List of all entities
|
|
16
|
+
R extends RelationDefinitionRawSchemaArray<E> = RelationDefinitionRawSchemaArray<E>> {
|
|
17
|
+
[rawSchemaKey]: RawSchema<E, R>;
|
|
18
|
+
constructor(rawSchema: RawSchema<E, R>);
|
|
19
|
+
get entities(): EntitySchema<E, R, E[number]>[];
|
|
20
|
+
get relationsDefinitions(): RelationDefinitionSchema<E, R, R[number]>[];
|
|
21
|
+
/**
|
|
22
|
+
* Returns the entity schema for the given entity type if it exists.
|
|
23
|
+
* When using TypeScript, this method can detect if the given type does not exist
|
|
24
|
+
* in the schema.
|
|
25
|
+
*
|
|
26
|
+
* @param entityType The entity type string
|
|
27
|
+
* @returns A new EntitySchema or null if the type does not exist
|
|
28
|
+
*/
|
|
29
|
+
getEntity<EType extends string>(entityType: EType): IsLooseSchema<E> extends true ? EntitySchema<E, R, E[number]> | null : IsETypeInStrictSchema<E, EType> extends true ? EntitySchema<E, R, EntityRawSchemaByType<E, EType>> : null;
|
|
30
|
+
/**
|
|
31
|
+
* Finds relations in the Schema matching the partial relation given
|
|
32
|
+
*
|
|
33
|
+
* @param matcher Partial relation definition to match against
|
|
34
|
+
* @returns Matched relation schema classes
|
|
35
|
+
*/
|
|
36
|
+
matchRelationDefinitions<M extends RelationDefinitionMatcher<E>>(matcher: M): RelationDefinitionSchema<E, R, MatchedRelationDefinition<E, R, {
|
|
37
|
+
subject: E[number]["type"];
|
|
38
|
+
}>>[];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Wrapper around raw entities from the Schema
|
|
42
|
+
*/
|
|
43
|
+
export declare class EntitySchema<E extends EntityRawSchemaArray = EntityRawSchemaArray, // List of all entities
|
|
44
|
+
R extends RelationDefinitionRawSchemaArray<E> = RelationDefinitionRawSchemaArray<E>, // List of all relation defintions
|
|
45
|
+
ERawSchema extends E[number] = E[number]> {
|
|
46
|
+
private schema;
|
|
47
|
+
private entityRawSchema;
|
|
48
|
+
constructor(schema: Schema<E, R>, entityRawSchema: ERawSchema);
|
|
49
|
+
/**
|
|
50
|
+
* The type of the entity. This can also be referred to as the entity' name.
|
|
51
|
+
*/
|
|
52
|
+
get type(): ERawSchema["type"];
|
|
53
|
+
/**
|
|
54
|
+
* A short description which can be used as documentation for the entity.
|
|
55
|
+
*/
|
|
56
|
+
get description(): ERawSchema["description"];
|
|
57
|
+
/**
|
|
58
|
+
* True if the current entity is a primitive type such as string or int
|
|
59
|
+
*/
|
|
60
|
+
get final(): ERawSchema["final"];
|
|
61
|
+
/**
|
|
62
|
+
* Gets the list of relation definitions with this entity as subject
|
|
63
|
+
*/
|
|
64
|
+
get subjectRelationDefinitions(): RelationDefinitionSchema<E, R, MatchedRelationDefinition<E, R, {
|
|
65
|
+
subject: ERawSchema["type"];
|
|
66
|
+
}>>[];
|
|
67
|
+
/**
|
|
68
|
+
* Gets the list of relation definitions with this entity as object
|
|
69
|
+
*/
|
|
70
|
+
get objectRelationsDefinitions(): RelationDefinitionSchema<E, R, MatchedRelationDefinition<E, R, {
|
|
71
|
+
object: ERawSchema["type"];
|
|
72
|
+
}>>[];
|
|
73
|
+
/**
|
|
74
|
+
* Finds relations in the Schema matching the partial relation given
|
|
75
|
+
*
|
|
76
|
+
* @param matcher Partial relation definition to match against
|
|
77
|
+
* @returns Matched relation schema classes
|
|
78
|
+
*/
|
|
79
|
+
matchRelationDefinitions<M extends RelationDefinitionMatcher<E>>(matcher: M): RelationDefinitionSchema<E, R, MatchedRelationDefinition<E, R, {
|
|
80
|
+
subject: ERawSchema["type"];
|
|
81
|
+
}>>[];
|
|
82
|
+
/**
|
|
83
|
+
* Gets the list of attributes names for this entity
|
|
84
|
+
*/
|
|
85
|
+
get attributes(): RelationDefinitionSchema<E, R, R[number]>[];
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Wrapper around raw relation definitions from the Schema
|
|
89
|
+
*/
|
|
90
|
+
export declare class RelationDefinitionSchema<E extends EntityRawSchemaArray = EntityRawSchemaArray, // List of all entities
|
|
91
|
+
R extends RelationDefinitionRawSchemaArray<E> = RelationDefinitionRawSchemaArray<E>, // List of all relation defintions
|
|
92
|
+
RDef extends R[number] = R[number]> {
|
|
93
|
+
private schema;
|
|
94
|
+
private relDef;
|
|
95
|
+
constructor(schema: Schema<E, R>, relDef: RDef);
|
|
96
|
+
/**
|
|
97
|
+
* The type of the relation. This can also be referred to as the relation's name.
|
|
98
|
+
*/
|
|
99
|
+
get type(): RDef["type"];
|
|
100
|
+
/**
|
|
101
|
+
* A short description which can be used as documentation for the relation.
|
|
102
|
+
*/
|
|
103
|
+
get description(): RDef["description"];
|
|
104
|
+
/**
|
|
105
|
+
* True if the object of the relation is a primitive type.
|
|
106
|
+
* In this case the relation iscalled an "attribute"
|
|
107
|
+
*/
|
|
108
|
+
get final(): RDef["final"];
|
|
109
|
+
/**
|
|
110
|
+
* The list of constraints if any. Only attributes (relations with final = true) have constraints.
|
|
111
|
+
* In other cases this returns null.
|
|
112
|
+
*/
|
|
113
|
+
get constraints(): RDef["constraints"];
|
|
114
|
+
/**
|
|
115
|
+
* The default value for this relation.
|
|
116
|
+
* It can be used when creating new relations if user did not enter a value (even if required).
|
|
117
|
+
*/
|
|
118
|
+
get default(): RDef extends {
|
|
119
|
+
default: infer V;
|
|
120
|
+
} ? V : undefined;
|
|
121
|
+
get cardinality(): RDef["cardinality"];
|
|
122
|
+
get subjectCardinality(): Cardinality;
|
|
123
|
+
get objectCardinality(): Cardinality;
|
|
124
|
+
/**
|
|
125
|
+
* Gets the entity associated to this relation's subject
|
|
126
|
+
*
|
|
127
|
+
* @throws InconsistentSchemaError if the relation's subject is not a valid entity
|
|
128
|
+
*/
|
|
129
|
+
get subject(): IsLooseSchema<E> extends true ? EntitySchema<E, R, E[number]> : EntitySchema<E, R, EntityRawSchemaByType<E, RDef["subject"]>>;
|
|
130
|
+
/**
|
|
131
|
+
* Gets the entity associated to this relation's object
|
|
132
|
+
*
|
|
133
|
+
* @throws InconsistentSchemaError if the relation's object is not a valid entity
|
|
134
|
+
*/
|
|
135
|
+
get object(): IsLooseSchema<E> extends true ? EntitySchema<E, R, E[number]> : EntitySchema<E, R, EntityRawSchemaByType<E, RDef["object"]>>;
|
|
136
|
+
/**
|
|
137
|
+
* Checks if the relation is required when using the subject or object pointof view
|
|
138
|
+
*
|
|
139
|
+
* @param role The point of view to use
|
|
140
|
+
* @returns
|
|
141
|
+
*/
|
|
142
|
+
isRequired(role: "subject" | "object"): boolean;
|
|
143
|
+
}
|
|
144
|
+
export declare type RelationDefinitionMatcher<E extends EntityRawSchemaArray> = Partial<RelationDefinitionRawSchema<E>>;
|
|
145
|
+
export declare type MatchedRelationDefinition<E extends EntityRawSchemaArray, R extends RelationDefinitionRawSchemaArray<EntityRawSchemaArray>, M extends RelationDefinitionMatcher<E>> = R[number] extends infer RDef ? (RDef extends M ? RDef : never) : never;
|
|
146
|
+
export {};
|
|
147
|
+
//# sourceMappingURL=Schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Schema.d.ts","sourceRoot":"","sources":["../../src/schema/Schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAEjC,OAAO,EACL,SAAS,EACT,2BAA2B,EAC3B,gCAAgC,EAChC,oBAAoB,EACpB,qBAAqB,EACrB,aAAa,EACb,qBAAqB,EACtB,MAAM,cAAc,CAAC;AAEtB,QAAA,MAAM,YAAY,EAAE,OAAO,MAA2C,CAAC;AAEvE;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,4PAU1B,CAAC;AAEF;;GAEG;AACH,qBAAa,MAAM,CACjB,CAAC,SAAS,oBAAoB,GAAG,oBAAoB,EAAE,uBAAuB;AAC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