@cubicweb/client 1.4.0 → 1.5.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 +87 -3
- package/lib/api/Api.d.ts.map +1 -1
- package/lib/api/Api.js +99 -10
- package/lib/api/Api.js.map +1 -1
- package/lib/api/Client.d.ts +39 -1
- package/lib/api/Client.d.ts.map +1 -1
- package/lib/api/Client.js +41 -1
- package/lib/api/Client.js.map +1 -1
- package/lib/api/Transaction.d.ts +42 -0
- package/lib/api/Transaction.d.ts.map +1 -1
- package/lib/api/Transaction.js +42 -0
- package/lib/api/Transaction.js.map +1 -1
- package/lib/index.d.ts +9 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +13 -9
- package/lib/index.js.map +1 -1
- package/lib/schema/classes/EntitySchema.d.ts +71 -0
- package/lib/schema/classes/EntitySchema.d.ts.map +1 -0
- package/lib/schema/classes/EntitySchema.js +83 -0
- package/lib/schema/classes/EntitySchema.js.map +1 -0
- package/lib/schema/classes/RelationDefinitionSchema.d.ts +87 -0
- package/lib/schema/classes/RelationDefinitionSchema.d.ts.map +1 -0
- package/lib/schema/classes/RelationDefinitionSchema.js +128 -0
- package/lib/schema/classes/RelationDefinitionSchema.js.map +1 -0
- package/lib/schema/classes/Schema.d.ts +54 -0
- package/lib/schema/classes/Schema.d.ts.map +1 -0
- package/lib/schema/classes/Schema.js +75 -0
- package/lib/schema/classes/Schema.js.map +1 -0
- package/lib/schema/classes/Utils.d.ts +30 -0
- package/lib/schema/classes/Utils.d.ts.map +1 -0
- package/lib/schema/classes/Utils.js +25 -0
- package/lib/schema/classes/Utils.js.map +1 -0
- package/lib/schema/raw/Constraints.d.ts +58 -0
- package/lib/schema/raw/Constraints.d.ts.map +1 -0
- package/lib/schema/raw/Constraints.js +3 -0
- package/lib/schema/raw/Constraints.js.map +1 -0
- package/lib/schema/raw/Entities.d.ts +13 -0
- package/lib/schema/raw/Entities.d.ts.map +1 -0
- package/lib/schema/{SchemaJSON.js → raw/Entities.js} +1 -1
- package/lib/schema/raw/Entities.js.map +1 -0
- package/lib/schema/raw/RelationDefinitions.d.ts +113 -0
- package/lib/schema/raw/RelationDefinitions.d.ts.map +1 -0
- package/lib/schema/raw/RelationDefinitions.js +3 -0
- package/lib/schema/raw/RelationDefinitions.js.map +1 -0
- package/lib/schema/raw/Schema.d.ts +13 -0
- package/lib/schema/raw/Schema.d.ts.map +1 -0
- package/lib/schema/raw/Schema.js +3 -0
- package/lib/schema/raw/Schema.js.map +1 -0
- package/lib/schema/raw/Utils.d.ts +22 -0
- package/lib/schema/raw/Utils.d.ts.map +1 -0
- package/lib/schema/raw/Utils.js +3 -0
- package/lib/schema/raw/Utils.js.map +1 -0
- package/package.json +1 -1
- package/src/api/Api.ts +128 -15
- package/src/api/Client.ts +42 -1
- package/src/api/Transaction.ts +42 -0
- package/src/index.ts +15 -8
- package/src/schema/classes/EntitySchema.ts +125 -0
- package/src/schema/classes/RelationDefinitionSchema.ts +156 -0
- package/src/schema/classes/Schema.ts +122 -0
- package/src/schema/classes/Utils.ts +52 -0
- package/src/schema/raw/Constraints.ts +77 -0
- package/src/schema/raw/Entities.ts +13 -0
- package/src/schema/{SchemaJSON.ts → raw/RelationDefinitions.ts} +36 -101
- package/src/schema/raw/Schema.ts +16 -0
- package/src/schema/raw/Utils.ts +33 -0
- package/lib/schema/Schema.d.ts +0 -156
- package/lib/schema/Schema.d.ts.map +0 -1
- package/lib/schema/Schema.js +0 -246
- package/lib/schema/Schema.js.map +0 -1
- package/lib/schema/SchemaJSON.d.ts +0 -140
- package/lib/schema/SchemaJSON.d.ts.map +0 -1
- package/lib/schema/SchemaJSON.js.map +0 -1
- package/src/schema/Schema.ts +0 -371
package/lib/api/Api.d.ts
CHANGED
|
@@ -1,28 +1,112 @@
|
|
|
1
|
-
import { RawSchema } from "../schema/
|
|
1
|
+
import { RawSchema } from "../schema/raw/Schema";
|
|
2
|
+
/**
|
|
3
|
+
* Type representing an RQL request and its associated parameters.
|
|
4
|
+
*/
|
|
2
5
|
export declare type RQLQuery = [string, RQLParams];
|
|
6
|
+
/**
|
|
7
|
+
* Type representing RQL parameters to send along a request.
|
|
8
|
+
*/
|
|
3
9
|
export interface RQLParams {
|
|
4
10
|
[key: string]: string | number;
|
|
5
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Type representing a row returned in a result set.
|
|
14
|
+
*/
|
|
6
15
|
export declare type RqlRow = Array<string | number | boolean | null>;
|
|
16
|
+
/**
|
|
17
|
+
* Type representing a RQL request result.
|
|
18
|
+
*/
|
|
7
19
|
export declare type ResultSet = Array<RqlRow>;
|
|
20
|
+
/**
|
|
21
|
+
* Type representing the body of an error sent by CubicWeb's API.
|
|
22
|
+
*/
|
|
8
23
|
declare type ApiError = {
|
|
9
24
|
title: string;
|
|
10
25
|
message: string;
|
|
11
26
|
data?: Record<string, unknown>;
|
|
12
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* Type representing the error data sent to clients when retrieving an API error.
|
|
30
|
+
*/
|
|
13
31
|
export declare type ApiErrorResponse = {
|
|
14
32
|
status: number;
|
|
15
33
|
} & ApiError;
|
|
34
|
+
/**
|
|
35
|
+
* Class used to handle requests to the CubicWeb API.
|
|
36
|
+
*
|
|
37
|
+
* You should never have to create this object yourself.
|
|
38
|
+
* Instead, retrieve this object from the methods in the `Client` class.
|
|
39
|
+
*
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
16
42
|
export default class Api {
|
|
17
|
-
private
|
|
18
|
-
private
|
|
43
|
+
private _apiUrl;
|
|
44
|
+
private _version;
|
|
45
|
+
private _rqlApiUrl;
|
|
46
|
+
private _schemaApiUrl;
|
|
47
|
+
private _loginApiUrl;
|
|
48
|
+
private _transactionApiUrl;
|
|
49
|
+
/**
|
|
50
|
+
* Class used to handle requests to the CubicWeb API.
|
|
51
|
+
*
|
|
52
|
+
* You should never have to create this object yourself.
|
|
53
|
+
* Instead, retrieve this object from the methods in the `Client` class.
|
|
54
|
+
*
|
|
55
|
+
* @param apiUrl The API url. It should not include the API version as it will be automatically added.
|
|
56
|
+
* Example: if you can retrieve the schema with https://example.com/api/v1/schema,
|
|
57
|
+
* use https://example.com/api as `apiUrl`.
|
|
58
|
+
*/
|
|
19
59
|
constructor(apiUrl: string);
|
|
60
|
+
get apiUrl(): string;
|
|
61
|
+
private getApiRoute;
|
|
62
|
+
/**
|
|
63
|
+
* Executes the given query and waits for the response.
|
|
64
|
+
*
|
|
65
|
+
* @param query The RQL query to send
|
|
66
|
+
* @param params The additional parameters for the request
|
|
67
|
+
* @returns A promise with the request's result set
|
|
68
|
+
*/
|
|
20
69
|
execute(query: string, params: RQLParams): Promise<ResultSet>;
|
|
70
|
+
/**
|
|
71
|
+
* Retrieves the CubicWeb instance's JSON schema.
|
|
72
|
+
*
|
|
73
|
+
* @returns The CubicWeb instance's JSON schema.
|
|
74
|
+
*/
|
|
21
75
|
schema(): Promise<RawSchema>;
|
|
76
|
+
/**
|
|
77
|
+
* Tries to log in the user on the configured CubicWeb instance with the given credentials.
|
|
78
|
+
*
|
|
79
|
+
* @param login The user login
|
|
80
|
+
* @param password THe user password
|
|
81
|
+
* @returns A promise returning true if the login was successful, false otherwise
|
|
82
|
+
*/
|
|
22
83
|
login(login: string, password: string): Promise<boolean>;
|
|
84
|
+
/**
|
|
85
|
+
* Starts a new transaction.
|
|
86
|
+
*
|
|
87
|
+
* @returns A promise with the transaction uuid
|
|
88
|
+
*/
|
|
23
89
|
transactionBegin(): Promise<string>;
|
|
90
|
+
/**
|
|
91
|
+
* Executes a RQL request as part of a transaction identified by the given uuid.
|
|
92
|
+
*
|
|
93
|
+
* @param uuid The transaction's uuid
|
|
94
|
+
* @param query The RQL query to send
|
|
95
|
+
* @param params The additional parameters for the request
|
|
96
|
+
* @returns A promise with the request's result set
|
|
97
|
+
*/
|
|
24
98
|
transactionExecute(uuid: string, query: string, params: RQLParams): Promise<ResultSet | null>;
|
|
99
|
+
/**
|
|
100
|
+
* Commits the transaction identified by the given uuid.
|
|
101
|
+
*
|
|
102
|
+
* @param uuid The transaction's uuid
|
|
103
|
+
*/
|
|
25
104
|
transactionCommit(uuid: string): Promise<null>;
|
|
105
|
+
/**
|
|
106
|
+
* Rollbacks the transaction identified by the given uuid.
|
|
107
|
+
*
|
|
108
|
+
* @param uuid The transaction's uuid
|
|
109
|
+
*/
|
|
26
110
|
transactionRollback(uuid: string): Promise<null>;
|
|
27
111
|
}
|
|
28
112
|
export {};
|
package/lib/api/Api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Api.d.ts","sourceRoot":"","sources":["../../src/api/Api.ts"],"names":[],"mappings":"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;
|
|
1
|
+
{"version":3,"file":"Api.d.ts","sourceRoot":"","sources":["../../src/api/Api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD;;GAEG;AACH,oBAAY,QAAQ,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;CAChC;AAED;;GAEG;AACH,oBAAY,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAC,CAAC;AAE7D;;GAEG;AACH,oBAAY,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;AAEtC;;GAEG;AACH,aAAK,Q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AOvD"}
|
package/lib/api/Api.js
CHANGED
|
@@ -9,37 +9,85 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
/**
|
|
13
|
+
* Class used to handle requests to the CubicWeb API.
|
|
14
|
+
*
|
|
15
|
+
* You should never have to create this object yourself.
|
|
16
|
+
* Instead, retrieve this object from the methods in the `Client` class.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
12
20
|
class Api {
|
|
21
|
+
/**
|
|
22
|
+
* Class used to handle requests to the CubicWeb API.
|
|
23
|
+
*
|
|
24
|
+
* You should never have to create this object yourself.
|
|
25
|
+
* Instead, retrieve this object from the methods in the `Client` class.
|
|
26
|
+
*
|
|
27
|
+
* @param apiUrl The API url. It should not include the API version as it will be automatically added.
|
|
28
|
+
* Example: if you can retrieve the schema with https://example.com/api/v1/schema,
|
|
29
|
+
* use https://example.com/api as `apiUrl`.
|
|
30
|
+
*/
|
|
13
31
|
constructor(apiUrl) {
|
|
14
|
-
this.
|
|
32
|
+
this._version = "v1";
|
|
33
|
+
this._transactionApiUrl = {
|
|
15
34
|
begin: "",
|
|
16
35
|
execute: "",
|
|
17
36
|
commit: "",
|
|
18
37
|
rollback: "",
|
|
19
38
|
};
|
|
20
|
-
this.
|
|
21
|
-
|
|
39
|
+
this._apiUrl = apiUrl;
|
|
40
|
+
this._rqlApiUrl = this.getApiRoute("rql");
|
|
41
|
+
this._schemaApiUrl = this.getApiRoute("schema");
|
|
42
|
+
this._loginApiUrl = this.getApiRoute("login");
|
|
43
|
+
Object.keys(this._transactionApiUrl).forEach((k) => (this._transactionApiUrl[k] =
|
|
44
|
+
this.getApiRoute(`transaction/${k}`)));
|
|
22
45
|
}
|
|
46
|
+
get apiUrl() {
|
|
47
|
+
return this._apiUrl;
|
|
48
|
+
}
|
|
49
|
+
getApiRoute(route) {
|
|
50
|
+
return `${this._apiUrl}/${this._version}/${route}`;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Executes the given query and waits for the response.
|
|
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
|
+
*/
|
|
23
59
|
execute(query, params) {
|
|
24
60
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
return nonNullFetchApi(
|
|
61
|
+
return nonNullFetchApi(this._rqlApiUrl, {
|
|
26
62
|
method: "POST",
|
|
27
63
|
body: JSON.stringify({ query, params }),
|
|
28
64
|
credentials: "include", // FIXME is it secure?
|
|
29
65
|
});
|
|
30
66
|
});
|
|
31
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Retrieves the CubicWeb instance's JSON schema.
|
|
70
|
+
*
|
|
71
|
+
* @returns The CubicWeb instance's JSON schema.
|
|
72
|
+
*/
|
|
32
73
|
schema() {
|
|
33
74
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
return nonNullFetchApi(
|
|
75
|
+
return nonNullFetchApi(this._schemaApiUrl, {
|
|
35
76
|
method: "GET",
|
|
36
77
|
credentials: "include",
|
|
37
78
|
});
|
|
38
79
|
});
|
|
39
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* Tries to log in the user on the configured CubicWeb instance with the given credentials.
|
|
83
|
+
*
|
|
84
|
+
* @param login The user login
|
|
85
|
+
* @param password THe user password
|
|
86
|
+
* @returns A promise returning true if the login was successful, false otherwise
|
|
87
|
+
*/
|
|
40
88
|
login(login, password) {
|
|
41
89
|
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
return fetchApi(
|
|
90
|
+
return fetchApi(this._loginApiUrl, {
|
|
43
91
|
method: "POST",
|
|
44
92
|
body: JSON.stringify({
|
|
45
93
|
login,
|
|
@@ -51,35 +99,58 @@ class Api {
|
|
|
51
99
|
.catch(() => false);
|
|
52
100
|
});
|
|
53
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Starts a new transaction.
|
|
104
|
+
*
|
|
105
|
+
* @returns A promise with the transaction uuid
|
|
106
|
+
*/
|
|
54
107
|
transactionBegin() {
|
|
55
108
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
return nonNullFetchApi(this.
|
|
109
|
+
return nonNullFetchApi(this._transactionApiUrl.begin, {
|
|
57
110
|
method: "POST",
|
|
58
111
|
credentials: "include",
|
|
59
112
|
});
|
|
60
113
|
});
|
|
61
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Executes a RQL request as part of a transaction identified by the given uuid.
|
|
117
|
+
*
|
|
118
|
+
* @param uuid The transaction's uuid
|
|
119
|
+
* @param query The RQL query to send
|
|
120
|
+
* @param params The additional parameters for the request
|
|
121
|
+
* @returns A promise with the request's result set
|
|
122
|
+
*/
|
|
62
123
|
transactionExecute(uuid, query, params) {
|
|
63
124
|
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
return fetchApi(this.
|
|
125
|
+
return fetchApi(this._transactionApiUrl.execute, {
|
|
65
126
|
method: "POST",
|
|
66
127
|
body: JSON.stringify({ uuid, query, params }),
|
|
67
128
|
credentials: "include",
|
|
68
129
|
});
|
|
69
130
|
});
|
|
70
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Commits the transaction identified by the given uuid.
|
|
134
|
+
*
|
|
135
|
+
* @param uuid The transaction's uuid
|
|
136
|
+
*/
|
|
71
137
|
transactionCommit(uuid) {
|
|
72
138
|
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
return fetchApi(this.
|
|
139
|
+
return fetchApi(this._transactionApiUrl.commit, {
|
|
74
140
|
method: "POST",
|
|
75
141
|
body: JSON.stringify({ uuid }),
|
|
76
142
|
credentials: "include",
|
|
77
143
|
});
|
|
78
144
|
});
|
|
79
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Rollbacks the transaction identified by the given uuid.
|
|
148
|
+
*
|
|
149
|
+
* @param uuid The transaction's uuid
|
|
150
|
+
*/
|
|
80
151
|
transactionRollback(uuid) {
|
|
81
152
|
return __awaiter(this, void 0, void 0, function* () {
|
|
82
|
-
return fetchApi(this.
|
|
153
|
+
return fetchApi(this._transactionApiUrl.rollback, {
|
|
83
154
|
method: "POST",
|
|
84
155
|
body: JSON.stringify({ uuid }),
|
|
85
156
|
credentials: "include",
|
|
@@ -88,6 +159,15 @@ class Api {
|
|
|
88
159
|
}
|
|
89
160
|
}
|
|
90
161
|
exports.default = Api;
|
|
162
|
+
/**
|
|
163
|
+
* Behaves the same as `fetchAPI` but forbids null responses.
|
|
164
|
+
* If this function detects a null response from the API,
|
|
165
|
+
* the promise will be rejected with a 500 error code.
|
|
166
|
+
*
|
|
167
|
+
* @param input The API route to use
|
|
168
|
+
* @param init Additional request parameters
|
|
169
|
+
* @returns A promise with the non-null fetched result
|
|
170
|
+
*/
|
|
91
171
|
const nonNullFetchApi = (input, init) => {
|
|
92
172
|
return new Promise((resolve, reject) => fetchApi(input, init)
|
|
93
173
|
.then((v) => {
|
|
@@ -105,6 +185,15 @@ const nonNullFetchApi = (input, init) => {
|
|
|
105
185
|
})
|
|
106
186
|
.catch(reject));
|
|
107
187
|
};
|
|
188
|
+
/**
|
|
189
|
+
* Sends a request to the given API route with the `Content-Type` header set and waits for a response.
|
|
190
|
+
* The returned promise will be rejected if the API returns HTTP error codes.
|
|
191
|
+
* The rejected promise will contain an `ApiErrorResponse` object.
|
|
192
|
+
*
|
|
193
|
+
* @param input The API route to use
|
|
194
|
+
* @param init Additional request parameters
|
|
195
|
+
* @returns A promise with the fetched result
|
|
196
|
+
*/
|
|
108
197
|
const fetchApi = (input, init) => {
|
|
109
198
|
let headers = init === null || init === void 0 ? void 0 : init.headers;
|
|
110
199
|
if ((init === null || init === void 0 ? void 0 : init.method) && init.method !== "GET" && init.method !== "DELETE") {
|
package/lib/api/Api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Api.js","sourceRoot":"","sources":["../../src/api/Api.ts"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"Api.js","sourceRoot":"","sources":["../../src/api/Api.ts"],"names":[],"mappings":";;;;;;;;;;;AAwCA;;;;;;;GAOG;AACH,MAAqB,GAAG;IAatB;;;;;;;;;OASG;IACH,YAAY,MAAc;QArBlB,aAAQ,GAAG,IAAI,CAAC;QAIhB,uBAAkB,GAAG;YAC3B,KAAK,EAAE,EAAE;YACT,OAAO,EAAE,EAAE;YACX,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE,EAAE;SACb,CAAC;QAaA,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;QAC1C,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QAChD,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAC9C,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,OAAO,CAC1C,CAAC,CAAC,EAAE,EAAE,CACJ,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAyC,CAAC;YACjE,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAC1C,CAAC;IACJ,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAEO,WAAW,CAAC,KAAa;QAC/B,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,QAAQ,IAAI,KAAK,EAAE,CAAC;IACrD,CAAC;IAED;;;;;;OAMG;IACG,OAAO,CAAC,KAAa,EAAE,MAAiB;;YAC5C,OAAO,eAAe,CAAY,IAAI,CAAC,UAAU,EAAE;gBACjD,MAAM,EAAE,MAAM;gBACd,IAAI,EAAE,IAAI,CAAC,SAAS,C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ema";
|
|
1
|
+
import { Schema } from "../schema/classes/Schema";
|
|
2
2
|
import { RQLParams } from "./Api";
|
|
3
3
|
import Transaction from "./Transaction";
|
|
4
|
+
/**
|
|
5
|
+
* Class used to communicate with a CubicWeb instance's API.
|
|
6
|
+
*/
|
|
4
7
|
export default class Client {
|
|
5
8
|
private api;
|
|
9
|
+
/**
|
|
10
|
+
* Class used to communicate with a CubicWeb instance's API.
|
|
11
|
+
*
|
|
12
|
+
* @param apiUrl The API url. It should not include the API version as it will be automatically added.
|
|
13
|
+
* Example: if you can retrieve the schema with https://example.com/api/v1/schema,
|
|
14
|
+
* use https://example.com/api as `apiUrl`.
|
|
15
|
+
*/
|
|
6
16
|
constructor(apiUrl: string);
|
|
17
|
+
get apiUrl(): string;
|
|
18
|
+
/**
|
|
19
|
+
* Executes the given query and waits for the response.
|
|
20
|
+
*
|
|
21
|
+
* @param query The RQL query to send
|
|
22
|
+
* @param params The additional parameters for the request
|
|
23
|
+
* @returns A promise with the request's result set
|
|
24
|
+
*/
|
|
7
25
|
execute(query: string, params?: RQLParams): Promise<import("./Api").ResultSet>;
|
|
26
|
+
/**
|
|
27
|
+
* Retrieves the CubicWeb instance's JSON schema.
|
|
28
|
+
*
|
|
29
|
+
* @returns The CubicWeb instance's JSON schema.
|
|
30
|
+
*/
|
|
8
31
|
schema(): Promise<Schema<import("..").EntityRawSchemaArray, import("..").RelationDefinitionRawSchemaArray<import("..").EntityRawSchemaArray>>>;
|
|
32
|
+
/**
|
|
33
|
+
* Tries to log in the user on the configured CubicWeb instance with the given credentials.
|
|
34
|
+
*
|
|
35
|
+
* @param login The user login
|
|
36
|
+
* @param password THe user password
|
|
37
|
+
* @returns A promise returning true if the login was successful, false otherwise
|
|
38
|
+
*/
|
|
9
39
|
login(login: string, password: string): Promise<boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new transaction and exposes the Transaction object in the given callback.
|
|
42
|
+
* Use this callback to execute RQL requests as part of the transaction.
|
|
43
|
+
* Once the callback's end is reached, the transaction is automatically committed.
|
|
44
|
+
*
|
|
45
|
+
* @param callback Function to execute transaction requests in.
|
|
46
|
+
* @returns The promise returned by the callback
|
|
47
|
+
*/
|
|
10
48
|
transaction<T>(callback: (tr: Transaction) => Promise<T>): Promise<T>;
|
|
11
49
|
}
|
|
12
50
|
//# sourceMappingURL=Client.d.ts.map
|
package/lib/api/Client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Client.d.ts","sourceRoot":"","sources":["../../src/api/Client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"Client.d.ts","sourceRoot":"","sources":["../../src/api/Client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,WAAW,MAAM,eAAe,CAAC;AAExC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,MAAM;IACzB,OAAO,CAAC,GAAG,CAAM;IAEjB;;;;;;OAMG;gBACS,MAAM,EAAE,MAAM;IAI1B,IAAI,MAAM,WAET;IAED;;;;;;OAMG;IACG,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,SAAc;IAInD;;;;OAIG;IACG,MAAM;IAKZ;;;;;;OAMG;IACG,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM;IAI3C;;;;;;;OAOG;IACG,WAAW,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAS5E"}
|
package/lib/api/Client.js
CHANGED
|
@@ -12,29 +12,69 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const Schema_1 = require("../schema/Schema");
|
|
15
|
+
const Schema_1 = require("../schema/classes/Schema");
|
|
16
16
|
const Api_1 = __importDefault(require("./Api"));
|
|
17
17
|
const Transaction_1 = __importDefault(require("./Transaction"));
|
|
18
|
+
/**
|
|
19
|
+
* Class used to communicate with a CubicWeb instance's API.
|
|
20
|
+
*/
|
|
18
21
|
class Client {
|
|
22
|
+
/**
|
|
23
|
+
* Class used to communicate with a CubicWeb instance's API.
|
|
24
|
+
*
|
|
25
|
+
* @param apiUrl The API url. It should not include the API version as it will be automatically added.
|
|
26
|
+
* Example: if you can retrieve the schema with https://example.com/api/v1/schema,
|
|
27
|
+
* use https://example.com/api as `apiUrl`.
|
|
28
|
+
*/
|
|
19
29
|
constructor(apiUrl) {
|
|
20
30
|
this.api = new Api_1.default(apiUrl);
|
|
21
31
|
}
|
|
32
|
+
get apiUrl() {
|
|
33
|
+
return this.api.apiUrl;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Executes the given query and waits for the response.
|
|
37
|
+
*
|
|
38
|
+
* @param query The RQL query to send
|
|
39
|
+
* @param params The additional parameters for the request
|
|
40
|
+
* @returns A promise with the request's result set
|
|
41
|
+
*/
|
|
22
42
|
execute(query, params = {}) {
|
|
23
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
24
44
|
return yield this.api.execute(query, params);
|
|
25
45
|
});
|
|
26
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Retrieves the CubicWeb instance's JSON schema.
|
|
49
|
+
*
|
|
50
|
+
* @returns The CubicWeb instance's JSON schema.
|
|
51
|
+
*/
|
|
27
52
|
schema() {
|
|
28
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
54
|
const schema = yield this.api.schema();
|
|
30
55
|
return new Schema_1.Schema(schema);
|
|
31
56
|
});
|
|
32
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Tries to log in the user on the configured CubicWeb instance with the given credentials.
|
|
60
|
+
*
|
|
61
|
+
* @param login The user login
|
|
62
|
+
* @param password THe user password
|
|
63
|
+
* @returns A promise returning true if the login was successful, false otherwise
|
|
64
|
+
*/
|
|
33
65
|
login(login, password) {
|
|
34
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
67
|
return yield this.api.login(login, password);
|
|
36
68
|
});
|
|
37
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Creates a new transaction and exposes the Transaction object in the given callback.
|
|
72
|
+
* Use this callback to execute RQL requests as part of the transaction.
|
|
73
|
+
* Once the callback's end is reached, the transaction is automatically committed.
|
|
74
|
+
*
|
|
75
|
+
* @param callback Function to execute transaction requests in.
|
|
76
|
+
* @returns The promise returned by the callback
|
|
77
|
+
*/
|
|
38
78
|
transaction(callback) {
|
|
39
79
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
80
|
const transaction = new Transaction_1.default(this.api);
|
package/lib/api/Client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Client.js","sourceRoot":"","sources":["../../src/api/Client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"Client.js","sourceRoot":"","sources":["../../src/api/Client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,qDAAkD;AAClD,gDAAuC;AACvC,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;;;;;;;OAOG;IACG,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,MAAM,WAAW,CAAC,MAAM,EAAE,CAAC;aAC5B;YACD,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;CACF;AAnED,yBAmEC"}
|
package/lib/api/Transaction.d.ts
CHANGED
|
@@ -1,14 +1,56 @@
|
|
|
1
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
|
+
*/
|
|
2
10
|
export default class Transaction {
|
|
3
11
|
private api;
|
|
4
12
|
private _uuid;
|
|
5
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
|
+
*/
|
|
6
24
|
constructor(api: Api);
|
|
25
|
+
/**
|
|
26
|
+
* @returns True if the connection is closed.
|
|
27
|
+
*/
|
|
7
28
|
isClosed(): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* This transaction unique identifier.
|
|
31
|
+
*/
|
|
8
32
|
get uuid(): string | null;
|
|
33
|
+
/**
|
|
34
|
+
* Begins a new transaction an retrieves the associated uuid.
|
|
35
|
+
*/
|
|
9
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
|
+
*/
|
|
10
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
|
+
*/
|
|
11
50
|
commit(): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Rollbacks all the queries sent with `execute` and closes the transaction.
|
|
53
|
+
*/
|
|
12
54
|
rollback(): Promise<void>;
|
|
13
55
|
private preventUsageIfClosed;
|
|
14
56
|
}
|
|
@@ -1 +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;
|
|
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;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,WAAW;IAclB,OAAO,CAAC,GAAG;IAbvB,OAAO,CAAC,KAAK,CAAuB;IACpC,OAAO,CAAC,OAAO,CAAS;IAExB;;;;;;;;;OASG;gBACiB,GAAG,EAAE,GAAG;IAE5B;;OAEG;IACH,QAAQ;IAIR;;OAEG;IACH,IAAI,IAAI,kBAEP;IAED;;OAEG;IACG,KAAK;IAKX;;;;;;;;OAQG;IACG,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,SAAc;IAKnD;;OAEG;IACG,MAAM;IAMZ;;OAEG;IACG,QAAQ;IAMd,OAAO,CAAC,oBAAoB;CAK7B"}
|
package/lib/api/Transaction.js
CHANGED
|
@@ -10,30 +10,69 @@ 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
|
+
/**
|
|
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
|
+
*/
|
|
13
21
|
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
|
+
*/
|
|
14
32
|
constructor(api) {
|
|
15
33
|
this.api = api;
|
|
16
34
|
this._uuid = null;
|
|
17
35
|
this._closed = false;
|
|
18
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* @returns True if the connection is closed.
|
|
39
|
+
*/
|
|
19
40
|
isClosed() {
|
|
20
41
|
return this._closed;
|
|
21
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* This transaction unique identifier.
|
|
45
|
+
*/
|
|
22
46
|
get uuid() {
|
|
23
47
|
return this._uuid;
|
|
24
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* Begins a new transaction an retrieves the associated uuid.
|
|
51
|
+
*/
|
|
25
52
|
begin() {
|
|
26
53
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
54
|
this._closed = false;
|
|
28
55
|
this._uuid = yield this.api.transactionBegin();
|
|
29
56
|
});
|
|
30
57
|
}
|
|
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
|
+
*/
|
|
31
67
|
execute(query, params = {}) {
|
|
32
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
69
|
this.preventUsageIfClosed();
|
|
34
70
|
return yield this.api.transactionExecute(this.uuid, query, params);
|
|
35
71
|
});
|
|
36
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Commits the transaction to apply all the RQL queries sent with `execute`.
|
|
75
|
+
*/
|
|
37
76
|
commit() {
|
|
38
77
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
78
|
this.preventUsageIfClosed();
|
|
@@ -41,6 +80,9 @@ class Transaction {
|
|
|
41
80
|
this._closed = true;
|
|
42
81
|
});
|
|
43
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Rollbacks all the queries sent with `execute` and closes the transaction.
|
|
85
|
+
*/
|
|
44
86
|
rollback() {
|
|
45
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
88
|
this.preventUsageIfClosed();
|
|
@@ -1 +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;
|
|
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;YAC5B,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QACrE,CAAC;KAAA;IAED;;OAEG;IACG,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;IAED;;OAEG;IACG,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;AA3ED,8BA2EC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from "./schema/
|
|
1
|
+
export * from "./schema/raw/Constraints";
|
|
2
|
+
export * from "./schema/raw/Entities";
|
|
3
|
+
export * from "./schema/raw/RelationDefinitions";
|
|
4
|
+
export * from "./schema/raw/Schema";
|
|
5
|
+
export * from "./schema/raw/Utils";
|
|
6
|
+
export * from "./schema/classes/EntitySchema";
|
|
7
|
+
export * from "./schema/classes/RelationDefinitionSchema";
|
|
8
|
+
export * from "./schema/classes/Schema";
|
|
9
|
+
export * from "./schema/classes/Utils";
|
|
3
10
|
export * from "./Errors";
|
|
4
11
|
export { default as Client } from "./api/Client";
|
|
5
|
-
export { default as Api } from "./api/Api";
|
|
6
12
|
export { default as Transaction } from "./api/Transaction";
|
|
7
13
|
export { RQLQuery, RQLParams, RqlRow, ResultSet, ApiErrorResponse, } from "./api/Api";
|
|
8
14
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
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"}
|