rystem.repository.client 0.2.5 → 0.2.7
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.
|
@@ -13,6 +13,9 @@ export declare class Repository<T, TKey> implements IRepository<T, TKey> {
|
|
|
13
13
|
private transformResponse;
|
|
14
14
|
makeRequest<TResponse>(endpoint: RepositoryEndpoint, path: string, method: string, body?: any, bodyIsKey?: boolean, skipSerialization?: boolean, skipSerializationOnResponse?: boolean, headers?: HeadersInit): Promise<TResponse>;
|
|
15
15
|
makeRequestAsStream<TResponse>(endpoint: RepositoryEndpoint, path: string, method: string, reader: (entity: TResponse) => void, body?: any, bodyIsKey?: boolean, skipSerialization?: boolean, skipSerializationOnResponse?: boolean, headers?: HeadersInit, cancellationToken?: CancellationToken | null): Promise<Array<TResponse>>;
|
|
16
|
+
private isPrimitive;
|
|
17
|
+
private objectToString;
|
|
18
|
+
private keyToPlainForQuery;
|
|
16
19
|
get(key: TKey): Promise<T>;
|
|
17
20
|
insert(key: TKey, value: T): Promise<State<T, TKey>>;
|
|
18
21
|
update(key: TKey, value: T): Promise<State<T, TKey>>;
|
package/lib/engine/Repository.js
CHANGED
|
@@ -196,9 +196,34 @@ class Repository {
|
|
|
196
196
|
});
|
|
197
197
|
return response;
|
|
198
198
|
}
|
|
199
|
+
// Helper: is primitive
|
|
200
|
+
isPrimitive(value) {
|
|
201
|
+
return (value === null ||
|
|
202
|
+
(typeof value !== "object" && typeof value !== "function"));
|
|
203
|
+
}
|
|
204
|
+
// Helper: deterministic object -> string conversion
|
|
205
|
+
objectToString(obj) {
|
|
206
|
+
if (obj == null)
|
|
207
|
+
return String(obj);
|
|
208
|
+
if (Array.isArray(obj))
|
|
209
|
+
return obj.map(v => String(v)).join(this.settings.keySeparator);
|
|
210
|
+
if (typeof obj === "object")
|
|
211
|
+
return Object.values(obj).map(v => String(v)).join(this.settings.keySeparator);
|
|
212
|
+
return String(obj);
|
|
213
|
+
}
|
|
214
|
+
// Helper: convert key to plain representation for querystring when no keyTransformer is present
|
|
215
|
+
keyToPlainForQuery(key) {
|
|
216
|
+
const keyTransformer = this.settings.keyTransformer;
|
|
217
|
+
if (keyTransformer?.toPlain)
|
|
218
|
+
return String(keyTransformer.toPlain(key));
|
|
219
|
+
if (this.isPrimitive(key))
|
|
220
|
+
return String(key);
|
|
221
|
+
return this.objectToString(key);
|
|
222
|
+
}
|
|
199
223
|
get(key) {
|
|
200
224
|
if (!this.settings.complexKey) {
|
|
201
|
-
|
|
225
|
+
const keyString = this.keyToPlainForQuery(key);
|
|
226
|
+
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Get, `Get?key=${keyString}`, 'GET');
|
|
202
227
|
}
|
|
203
228
|
else {
|
|
204
229
|
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Get, `Get`, 'POST', key, true, false, false, {
|
|
@@ -208,7 +233,8 @@ class Repository {
|
|
|
208
233
|
}
|
|
209
234
|
insert(key, value) {
|
|
210
235
|
if (!this.settings.complexKey) {
|
|
211
|
-
|
|
236
|
+
const keyString = this.keyToPlainForQuery(key);
|
|
237
|
+
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Insert, `Insert?key=${keyString}`, 'POST', value, false, false, false, {
|
|
212
238
|
'content-type': 'application/json;charset=UTF-8'
|
|
213
239
|
});
|
|
214
240
|
}
|
|
@@ -223,7 +249,8 @@ class Repository {
|
|
|
223
249
|
}
|
|
224
250
|
update(key, value) {
|
|
225
251
|
if (!this.settings.complexKey) {
|
|
226
|
-
|
|
252
|
+
const keyString = this.keyToPlainForQuery(key);
|
|
253
|
+
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Update, `Update?key=${keyString}`, 'POST', value, false, false, false, {
|
|
227
254
|
'content-type': 'application/json;charset=UTF-8'
|
|
228
255
|
});
|
|
229
256
|
}
|
|
@@ -238,7 +265,8 @@ class Repository {
|
|
|
238
265
|
}
|
|
239
266
|
exist(key) {
|
|
240
267
|
if (!this.settings.complexKey) {
|
|
241
|
-
|
|
268
|
+
const keyString = this.keyToPlainForQuery(key);
|
|
269
|
+
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Exist, `Exist?key=${keyString}`, 'GET');
|
|
242
270
|
}
|
|
243
271
|
else {
|
|
244
272
|
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Exist, `Exist`, 'POST', key, true, false, false, {
|
|
@@ -248,7 +276,8 @@ class Repository {
|
|
|
248
276
|
}
|
|
249
277
|
delete(key) {
|
|
250
278
|
if (!this.settings.complexKey) {
|
|
251
|
-
|
|
279
|
+
const keyString = this.keyToPlainForQuery(key);
|
|
280
|
+
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Delete, `Delete?key=${keyString}`, 'GET');
|
|
252
281
|
}
|
|
253
282
|
else {
|
|
254
283
|
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Delete, `Delete`, 'POST', key, true, false, false, {
|
|
@@ -8,6 +8,7 @@ class RepositorySettings {
|
|
|
8
8
|
case;
|
|
9
9
|
transformer; // For T
|
|
10
10
|
keyTransformer; // For TKey
|
|
11
|
+
keySeparator;
|
|
11
12
|
complexKey;
|
|
12
13
|
headersEnrichers;
|
|
13
14
|
errorsHandlers;
|
|
@@ -17,6 +18,7 @@ class RepositorySettings {
|
|
|
17
18
|
this.path = null;
|
|
18
19
|
this.case = "PascalCase";
|
|
19
20
|
this.complexKey = false;
|
|
21
|
+
this.keySeparator = "|||";
|
|
20
22
|
this.headersEnrichers = new Array();
|
|
21
23
|
this.errorsHandlers = new Array();
|
|
22
24
|
}
|
package/package.json
CHANGED