rystem.repository.client 0.1.2 → 0.2.2
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/engine/Repository.d.ts +4 -2
- package/lib/engine/Repository.js +144 -25
- package/lib/engine/batch/Batch.d.ts +7 -2
- package/lib/engine/batch/Batch.js +15 -0
- package/lib/engine/batch/BatchBuilder.js +14 -14
- package/lib/engine/batch/BatchOperation.d.ts +12 -0
- package/lib/engine/batch/BatchOperation.js +16 -0
- package/lib/engine/batch/BatchResult.d.ts +9 -2
- package/lib/engine/batch/BatchResult.js +16 -0
- package/lib/engine/query/QueryBuilder.js +3 -3
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/models/Entity.d.ts +7 -0
- package/lib/models/Entity.js +18 -0
- package/lib/models/State.d.ts +12 -1
- package/lib/models/State.js +24 -0
- package/lib/servicecollection/RepositorySettings.d.ts +7 -0
- package/lib/servicecollection/RepositorySettings.js +4 -0
- package/package.json +5 -5
- package/lib/engine/batch/BatchElement.d.ts +0 -5
- package/lib/engine/batch/BatchElement.js +0 -2
|
@@ -9,8 +9,10 @@ export declare class Repository<T, TKey> implements IRepository<T, TKey> {
|
|
|
9
9
|
private baseUri;
|
|
10
10
|
private settings;
|
|
11
11
|
constructor(baseUri: string | null, settings: RepositorySettings);
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
private serializeRequestBody;
|
|
13
|
+
private transformResponse;
|
|
14
|
+
makeRequest<TResponse>(endpoint: RepositoryEndpoint, path: string, method: string, body?: any, bodyIsKey?: boolean, skipSerialization?: boolean, skipSerializationOnResponse?: boolean, headers?: HeadersInit): Promise<TResponse>;
|
|
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>>;
|
|
14
16
|
get(key: TKey): Promise<T>;
|
|
15
17
|
insert(key: TKey, value: T): Promise<State<T, TKey>>;
|
|
16
18
|
update(key: TKey, value: T): Promise<State<T, TKey>>;
|
package/lib/engine/Repository.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Repository = void 0;
|
|
4
|
+
const Entity_1 = require("../models/Entity");
|
|
4
5
|
const RepositoryEndpoint_1 = require("../models/RepositoryEndpoint");
|
|
6
|
+
const State_1 = require("../models/State");
|
|
5
7
|
const BatchBuilder_1 = require("./batch/BatchBuilder");
|
|
8
|
+
const Batch_1 = require("./batch/Batch");
|
|
9
|
+
const BatchResult_1 = require("./batch/BatchResult");
|
|
6
10
|
const QueryBuilder_1 = require("./query/QueryBuilder");
|
|
7
11
|
class Repository {
|
|
8
12
|
baseUri;
|
|
@@ -14,7 +18,121 @@ class Repository {
|
|
|
14
18
|
this.baseUri = settings.uri;
|
|
15
19
|
this.settings = settings;
|
|
16
20
|
}
|
|
17
|
-
|
|
21
|
+
serializeRequestBody(body, isKey) {
|
|
22
|
+
const { transformer, keyTransformer } = this.settings;
|
|
23
|
+
if (!body)
|
|
24
|
+
return body;
|
|
25
|
+
// Entity<T, TKey> → SerializedEntity<T, TKey>
|
|
26
|
+
if ((0, Entity_1.isEntity)(body)) {
|
|
27
|
+
return {
|
|
28
|
+
v: transformer?.toPlain?.(body.value) ?? body.value,
|
|
29
|
+
k: keyTransformer?.toPlain?.(body.key) ?? body.key,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// Batch<T, TKey> → SerializedBatch<T, TKey>
|
|
33
|
+
if ((0, Batch_1.isBatch)(body)) {
|
|
34
|
+
return {
|
|
35
|
+
v: body.values.map(op => ({
|
|
36
|
+
c: op.command,
|
|
37
|
+
k: op.key && keyTransformer?.toPlain ? keyTransformer.toPlain(op.key) : op.key,
|
|
38
|
+
v: op.value && transformer?.toPlain ? transformer.toPlain(op.value) : op.value,
|
|
39
|
+
})),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
// State<T, TKey> → SerializedState<T, TKey>
|
|
43
|
+
if ((0, State_1.isState)(body)) {
|
|
44
|
+
return {
|
|
45
|
+
i: body.isOk,
|
|
46
|
+
c: body.code,
|
|
47
|
+
m: body.message,
|
|
48
|
+
e: {
|
|
49
|
+
k: keyTransformer?.toPlain?.(body.entity.key) ?? body.entity.key,
|
|
50
|
+
v: transformer?.toPlain?.(body.entity.value) ?? body.entity.value,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
// Fallback — assume it's T
|
|
55
|
+
if (!isKey)
|
|
56
|
+
return transformer?.toPlain?.(body) ?? body;
|
|
57
|
+
else
|
|
58
|
+
return keyTransformer?.toPlain?.(body) ?? body;
|
|
59
|
+
}
|
|
60
|
+
transformResponse(res) {
|
|
61
|
+
const { transformer, keyTransformer } = this.settings;
|
|
62
|
+
if (!res)
|
|
63
|
+
return res;
|
|
64
|
+
// SerializedState<T, TKey> → State<T, TKey>
|
|
65
|
+
if ((0, State_1.isSerializedState)(res)) {
|
|
66
|
+
return {
|
|
67
|
+
isOk: res.i,
|
|
68
|
+
code: res.c,
|
|
69
|
+
message: res.m,
|
|
70
|
+
entity: res.e ? {
|
|
71
|
+
key: res.e.k && keyTransformer?.fromPlain ? keyTransformer.fromPlain(res.e.k) : res.e.k,
|
|
72
|
+
value: res.e.v && transformer?.fromPlain ? transformer.fromPlain(res.e.v) : res.e.v,
|
|
73
|
+
} : res.e,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
// SerializedEntity<T, TKey> → Entity<T, TKey>
|
|
77
|
+
if ((0, Entity_1.isSerializedEntity)(res)) {
|
|
78
|
+
return {
|
|
79
|
+
key: res.k && keyTransformer?.fromPlain ? keyTransformer.fromPlain(res.k) : res.k,
|
|
80
|
+
value: res.v && transformer?.fromPlain ? transformer.fromPlain(res.v) : res.v,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
// SerializedEntity<T, TKey>[] → Entity<T, TKey>[]
|
|
84
|
+
if ((0, Entity_1.isSerializedEntityArray)(res)) {
|
|
85
|
+
return res.map(item => ({
|
|
86
|
+
key: item.k && keyTransformer?.fromPlain ? keyTransformer.fromPlain(item.k) : item.k,
|
|
87
|
+
value: item.v && transformer?.fromPlain ? transformer.fromPlain(item.v) : item.v,
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
// SerializedBatchResult<T, TKey>[] → BatchResult<T, TKey>[]
|
|
91
|
+
if (Array.isArray(res) && res.every(BatchResult_1.isSerializedBatchResult)) {
|
|
92
|
+
return res.map(item => ({
|
|
93
|
+
code: item.c,
|
|
94
|
+
key: item.k && keyTransformer?.fromPlain ? keyTransformer.fromPlain(item.k) : item.k,
|
|
95
|
+
state: item.s ? {
|
|
96
|
+
isOk: item.s.i,
|
|
97
|
+
code: item.s.c,
|
|
98
|
+
message: item.s.m,
|
|
99
|
+
entity: item.s.e ? {
|
|
100
|
+
key: item.s.e.k && keyTransformer?.fromPlain ? keyTransformer.fromPlain(item.s.e.k) : item.s.e.k,
|
|
101
|
+
value: item.s.e.v && transformer?.fromPlain ? transformer.fromPlain(item.s.e.v) : item.s.e.v,
|
|
102
|
+
} : item.s.e,
|
|
103
|
+
} : item.s,
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
// SerializedBatch<T, TKey> → Batch<T, TKey>
|
|
107
|
+
if ((0, Batch_1.isSerializedBatch)(res)) {
|
|
108
|
+
return {
|
|
109
|
+
values: res.v.map((op) => ({
|
|
110
|
+
command: op.c,
|
|
111
|
+
key: op.k && keyTransformer?.fromPlain ? keyTransformer.fromPlain(op.k) : op.k,
|
|
112
|
+
value: op.v && transformer?.fromPlain ? transformer.fromPlain(op.v) : op.v,
|
|
113
|
+
})),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
// SerializedBatchResult<T, TKey> → BatchResult<T, TKey>
|
|
117
|
+
if ((0, BatchResult_1.isSerializedBatchResult)(res)) {
|
|
118
|
+
return {
|
|
119
|
+
code: res.c,
|
|
120
|
+
key: keyTransformer?.fromPlain?.(res.k) ?? res.k,
|
|
121
|
+
state: res.s ? {
|
|
122
|
+
isOk: res.s.i,
|
|
123
|
+
code: res.s.c,
|
|
124
|
+
message: res.s.m,
|
|
125
|
+
entity: res.s.e ? {
|
|
126
|
+
key: res.s.e.k && keyTransformer?.fromPlain ? keyTransformer.fromPlain(res.s.e.k) : res.s.e.k,
|
|
127
|
+
value: res.s.e.v && transformer?.fromPlain ? transformer.fromPlain(res.s.e.v) : res.s.e.v,
|
|
128
|
+
} : res.s.e,
|
|
129
|
+
} : res.s,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
// Fallback: T ← fromPlain
|
|
133
|
+
return transformer?.fromPlain?.(res) ?? res;
|
|
134
|
+
}
|
|
135
|
+
async makeRequest(endpoint, path, method, body = null, bodyIsKey = false, skipSerialization = false, skipSerializationOnResponse = false, headers = {}) {
|
|
18
136
|
let retry = true;
|
|
19
137
|
let response = null;
|
|
20
138
|
const uri = `${this.baseUri}/${path}`;
|
|
@@ -22,10 +140,12 @@ class Repository {
|
|
|
22
140
|
response = await fetch(uri, {
|
|
23
141
|
method: method,
|
|
24
142
|
headers: this.settings.enrichHeaders(endpoint, uri, method, headers, body),
|
|
25
|
-
body: body == null ? null : JSON.stringify(body)
|
|
143
|
+
body: body == null ? null : JSON.stringify(skipSerialization ? body : this.serializeRequestBody(body, bodyIsKey))
|
|
26
144
|
})
|
|
27
|
-
.then(res => {
|
|
28
|
-
const json = res.json();
|
|
145
|
+
.then(async (res) => {
|
|
146
|
+
const json = await res.json();
|
|
147
|
+
if (!res.ok)
|
|
148
|
+
throw json;
|
|
29
149
|
return json;
|
|
30
150
|
})
|
|
31
151
|
.catch((err) => {
|
|
@@ -34,20 +154,20 @@ class Repository {
|
|
|
34
154
|
})
|
|
35
155
|
.then(res => {
|
|
36
156
|
retry = false;
|
|
37
|
-
return res;
|
|
157
|
+
return skipSerializationOnResponse ? res : this.transformResponse(res);
|
|
38
158
|
});
|
|
39
159
|
if (retry)
|
|
40
160
|
await new Promise(f => setTimeout(f, 200));
|
|
41
161
|
}
|
|
42
162
|
return response;
|
|
43
163
|
}
|
|
44
|
-
async makeRequestAsStream(endpoint, path, method, reader, body = null, headers = {}, cancellationToken = null) {
|
|
164
|
+
async makeRequestAsStream(endpoint, path, method, reader, body = null, bodyIsKey = false, skipSerialization = false, skipSerializationOnResponse = false, headers = {}, cancellationToken = null) {
|
|
45
165
|
const uri = `${this.baseUri}/${path}/Stream`;
|
|
46
166
|
let response = [];
|
|
47
167
|
await fetch(uri, {
|
|
48
168
|
method: method,
|
|
49
169
|
headers: this.settings.enrichHeaders(endpoint, uri, method, headers, body),
|
|
50
|
-
body: body == null ? null : JSON.stringify(body)
|
|
170
|
+
body: body == null ? null : JSON.stringify(skipSerialization ? body : this.serializeRequestBody(body, bodyIsKey))
|
|
51
171
|
})
|
|
52
172
|
.then(async (res) => {
|
|
53
173
|
const bodyReader = res.body?.getReader();
|
|
@@ -62,16 +182,15 @@ class Repository {
|
|
|
62
182
|
if (cancellationToken?.isCancellationRequested())
|
|
63
183
|
break;
|
|
64
184
|
decoder.decodeChunk(value, entity => {
|
|
65
|
-
|
|
66
|
-
|
|
185
|
+
const transformed = skipSerializationOnResponse ? entity : this.transformResponse(entity);
|
|
186
|
+
response.push(transformed);
|
|
187
|
+
reader(transformed);
|
|
67
188
|
});
|
|
68
189
|
}
|
|
69
190
|
bodyReader.releaseLock();
|
|
70
191
|
}
|
|
71
192
|
})
|
|
72
193
|
.catch(async (err) => {
|
|
73
|
-
console.log(err);
|
|
74
|
-
console.log("in errordalsjdlasjdlasjdlas");
|
|
75
194
|
this.settings.manageError(endpoint, uri, method, headers, body, err);
|
|
76
195
|
return null;
|
|
77
196
|
});
|
|
@@ -82,38 +201,38 @@ class Repository {
|
|
|
82
201
|
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Get, `Get?key=${key}`, 'GET');
|
|
83
202
|
}
|
|
84
203
|
else {
|
|
85
|
-
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Get, `Get`, 'POST', key, {
|
|
86
|
-
'content-type': 'application/json;charset=UTF-8'
|
|
204
|
+
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Get, `Get`, 'POST', key, true, false, false, {
|
|
205
|
+
'content-type': 'application/json;charset=UTF-8'
|
|
87
206
|
});
|
|
88
207
|
}
|
|
89
208
|
}
|
|
90
209
|
insert(key, value) {
|
|
91
210
|
if (!this.settings.complexKey) {
|
|
92
|
-
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Insert, `Insert?key=${key}`, 'POST', value, {
|
|
93
|
-
'content-type': 'application/json;charset=UTF-8'
|
|
211
|
+
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Insert, `Insert?key=${key}`, 'POST', value, false, false, false, {
|
|
212
|
+
'content-type': 'application/json;charset=UTF-8'
|
|
94
213
|
});
|
|
95
214
|
}
|
|
96
215
|
else {
|
|
97
216
|
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Insert, `Insert`, 'POST', {
|
|
98
217
|
value: value,
|
|
99
218
|
key: key
|
|
100
|
-
}, {
|
|
101
|
-
'content-type': 'application/json;charset=UTF-8'
|
|
219
|
+
}, false, false, false, {
|
|
220
|
+
'content-type': 'application/json;charset=UTF-8'
|
|
102
221
|
});
|
|
103
222
|
}
|
|
104
223
|
}
|
|
105
224
|
update(key, value) {
|
|
106
225
|
if (!this.settings.complexKey) {
|
|
107
|
-
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Update, `Update?key=${key}`, 'POST', value, {
|
|
108
|
-
'content-type': 'application/json;charset=UTF-8'
|
|
226
|
+
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Update, `Update?key=${key}`, 'POST', value, false, false, false, {
|
|
227
|
+
'content-type': 'application/json;charset=UTF-8'
|
|
109
228
|
});
|
|
110
229
|
}
|
|
111
230
|
else {
|
|
112
231
|
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Update, `Update`, 'POST', {
|
|
113
232
|
value: value,
|
|
114
233
|
key: key
|
|
115
|
-
}, {
|
|
116
|
-
'content-type': 'application/json;charset=UTF-8'
|
|
234
|
+
}, false, false, false, {
|
|
235
|
+
'content-type': 'application/json;charset=UTF-8'
|
|
117
236
|
});
|
|
118
237
|
}
|
|
119
238
|
}
|
|
@@ -122,8 +241,8 @@ class Repository {
|
|
|
122
241
|
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Exist, `Exist?key=${key}`, 'GET');
|
|
123
242
|
}
|
|
124
243
|
else {
|
|
125
|
-
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Exist, `Exist`, 'POST', key, {
|
|
126
|
-
'content-type': 'application/json;charset=UTF-8'
|
|
244
|
+
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Exist, `Exist`, 'POST', key, true, false, false, {
|
|
245
|
+
'content-type': 'application/json;charset=UTF-8'
|
|
127
246
|
});
|
|
128
247
|
}
|
|
129
248
|
}
|
|
@@ -132,8 +251,8 @@ class Repository {
|
|
|
132
251
|
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Delete, `Delete?key=${key}`, 'GET');
|
|
133
252
|
}
|
|
134
253
|
else {
|
|
135
|
-
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Delete, `Delete`, 'POST', key, {
|
|
136
|
-
'content-type': 'application/json;charset=UTF-8'
|
|
254
|
+
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Delete, `Delete`, 'POST', key, true, false, false, {
|
|
255
|
+
'content-type': 'application/json;charset=UTF-8'
|
|
137
256
|
});
|
|
138
257
|
}
|
|
139
258
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BatchOperation } from "./BatchOperation";
|
|
2
2
|
export type Batch<T, TKey> = {
|
|
3
|
-
|
|
3
|
+
values: Array<BatchOperation<T, TKey>>;
|
|
4
4
|
};
|
|
5
|
+
export type SerializedBatch<T, TKey> = {
|
|
6
|
+
v: Array<BatchOperation<T, TKey>>;
|
|
7
|
+
};
|
|
8
|
+
export declare function isBatch<T, TKey>(obj: any): obj is Batch<T, TKey>;
|
|
9
|
+
export declare function isSerializedBatch<T, TKey>(obj: any): obj is SerializedBatch<T, TKey>;
|
|
@@ -1,2 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isBatch = isBatch;
|
|
4
|
+
exports.isSerializedBatch = isSerializedBatch;
|
|
5
|
+
const BatchOperation_1 = require("./BatchOperation");
|
|
6
|
+
function isBatch(obj) {
|
|
7
|
+
return (typeof obj === 'object' &&
|
|
8
|
+
obj !== null &&
|
|
9
|
+
Array.isArray(obj.values) &&
|
|
10
|
+
obj.values.every(BatchOperation_1.isBatchOperation));
|
|
11
|
+
}
|
|
12
|
+
function isSerializedBatch(obj) {
|
|
13
|
+
return (typeof obj === 'object' &&
|
|
14
|
+
obj !== null &&
|
|
15
|
+
Array.isArray(obj.v) &&
|
|
16
|
+
obj.v.every(BatchOperation_1.isSerializedBatchOperation));
|
|
17
|
+
}
|
|
@@ -7,40 +7,40 @@ class BatchBuilder {
|
|
|
7
7
|
repository;
|
|
8
8
|
constructor(repository) {
|
|
9
9
|
this.batch = {
|
|
10
|
-
|
|
10
|
+
values: []
|
|
11
11
|
};
|
|
12
12
|
this.repository = repository;
|
|
13
13
|
}
|
|
14
14
|
addInsert(key, value) {
|
|
15
|
-
this.batch.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
this.batch.values.push({
|
|
16
|
+
command: 1,
|
|
17
|
+
key: key,
|
|
18
|
+
value: value
|
|
19
19
|
});
|
|
20
20
|
return this;
|
|
21
21
|
}
|
|
22
22
|
addUpdate(key, value) {
|
|
23
|
-
this.batch.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
this.batch.values.push({
|
|
24
|
+
command: 2,
|
|
25
|
+
key: key,
|
|
26
|
+
value: value
|
|
27
27
|
});
|
|
28
28
|
return this;
|
|
29
29
|
}
|
|
30
30
|
addDelete(key) {
|
|
31
|
-
this.batch.
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
this.batch.values.push({
|
|
32
|
+
command: 4,
|
|
33
|
+
key: key
|
|
34
34
|
});
|
|
35
35
|
return this;
|
|
36
36
|
}
|
|
37
37
|
execute() {
|
|
38
|
-
return this.repository.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Batch, `Batch`, 'POST', this.batch, {
|
|
38
|
+
return this.repository.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Batch, `Batch`, 'POST', this.batch, false, false, false, {
|
|
39
39
|
'content-type': 'application/json;charset=UTF-8',
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
executeAsStream(entityReader, cancellationToken = null) {
|
|
43
|
-
return this.repository.makeRequestAsStream(RepositoryEndpoint_1.RepositoryEndpoint.BatchStream, `Batch`, 'POST', entityReader, this.batch, {
|
|
43
|
+
return this.repository.makeRequestAsStream(RepositoryEndpoint_1.RepositoryEndpoint.BatchStream, `Batch`, 'POST', entityReader, this.batch, false, false, false, {
|
|
44
44
|
'content-type': 'application/json;charset=UTF-8',
|
|
45
45
|
}, cancellationToken);
|
|
46
46
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type BatchOperation<T, TKey> = {
|
|
2
|
+
command: 1 | 2 | 4;
|
|
3
|
+
key: TKey;
|
|
4
|
+
value: T | null;
|
|
5
|
+
};
|
|
6
|
+
export type SerializedBatchOperation<T, TKey> = {
|
|
7
|
+
c: 1 | 2 | 4;
|
|
8
|
+
k: TKey;
|
|
9
|
+
v: T | null;
|
|
10
|
+
};
|
|
11
|
+
export declare function isBatchOperation<T, TKey>(obj: any): obj is BatchOperation<T, TKey>;
|
|
12
|
+
export declare function isSerializedBatchOperation<T, TKey>(obj: any): obj is SerializedBatchOperation<T, TKey>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isBatchOperation = isBatchOperation;
|
|
4
|
+
exports.isSerializedBatchOperation = isSerializedBatchOperation;
|
|
5
|
+
function isBatchOperation(obj) {
|
|
6
|
+
return (typeof obj === 'object' &&
|
|
7
|
+
obj !== null &&
|
|
8
|
+
(obj.command === 1 || obj.command === 2 || obj.command === 4) &&
|
|
9
|
+
'key' in obj);
|
|
10
|
+
}
|
|
11
|
+
function isSerializedBatchOperation(obj) {
|
|
12
|
+
return (typeof obj === 'object' &&
|
|
13
|
+
obj !== null &&
|
|
14
|
+
(obj.c === 1 || obj.c === 2 || obj.c === 4) &&
|
|
15
|
+
'k' in obj);
|
|
16
|
+
}
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import { State } from "../../models/State";
|
|
1
|
+
import { State, SerializedState } from "../../models/State";
|
|
2
2
|
export type BatchResult<T, TKey> = {
|
|
3
|
+
code: 1 | 2 | 4;
|
|
4
|
+
key: TKey;
|
|
5
|
+
state: State<T, TKey>;
|
|
6
|
+
};
|
|
7
|
+
export type SerializedBatchResult<T, TKey> = {
|
|
3
8
|
c: 1 | 2 | 4;
|
|
4
9
|
k: TKey;
|
|
5
|
-
s:
|
|
10
|
+
s: SerializedState<T, TKey>;
|
|
6
11
|
};
|
|
12
|
+
export declare function isBatchResult<T, TKey>(obj: any): obj is BatchResult<T, TKey>;
|
|
13
|
+
export declare function isSerializedBatchResult<T, TKey>(obj: any): obj is SerializedBatchResult<T, TKey>;
|
|
@@ -1,2 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isBatchResult = isBatchResult;
|
|
4
|
+
exports.isSerializedBatchResult = isSerializedBatchResult;
|
|
5
|
+
function isBatchResult(obj) {
|
|
6
|
+
return (typeof obj === 'object' &&
|
|
7
|
+
obj !== null &&
|
|
8
|
+
(obj.code === 1 || obj.code === 2 || obj.code === 4) &&
|
|
9
|
+
'key' in obj &&
|
|
10
|
+
'state' in obj);
|
|
11
|
+
}
|
|
12
|
+
function isSerializedBatchResult(obj) {
|
|
13
|
+
return (typeof obj === 'object' &&
|
|
14
|
+
obj !== null &&
|
|
15
|
+
(obj.c === 1 || obj.c === 2 || obj.c === 4) &&
|
|
16
|
+
'k' in obj &&
|
|
17
|
+
's' in obj);
|
|
18
|
+
}
|
|
@@ -67,12 +67,12 @@ class QueryBuilder {
|
|
|
67
67
|
return this;
|
|
68
68
|
}
|
|
69
69
|
execute() {
|
|
70
|
-
return this.repository.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Query, `Query`, 'POST', this.filters, {
|
|
70
|
+
return this.repository.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Query, `Query`, 'POST', this.filters, false, true, false, {
|
|
71
71
|
'content-type': 'application/json;charset=UTF-8',
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
executeAsStream(entityReader, cancellationToken = null) {
|
|
75
|
-
return this.repository.makeRequestAsStream(RepositoryEndpoint_1.RepositoryEndpoint.QueryStream, `Query`, 'POST', entityReader, this.filters, {
|
|
75
|
+
return this.repository.makeRequestAsStream(RepositoryEndpoint_1.RepositoryEndpoint.QueryStream, `Query`, 'POST', entityReader, this.filters, false, true, false, {
|
|
76
76
|
'content-type': 'application/json;charset=UTF-8',
|
|
77
77
|
}, cancellationToken);
|
|
78
78
|
}
|
|
@@ -108,7 +108,7 @@ class QueryBuilder {
|
|
|
108
108
|
return this.executeOperation("Sum", "decimal");
|
|
109
109
|
}
|
|
110
110
|
executeOperation(operation, returnType) {
|
|
111
|
-
return this.repository.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Operation, `Operation?op=${operation}&returnType=${returnType}`, 'POST', this.filters, {
|
|
111
|
+
return this.repository.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Operation, `Operation?op=${operation}&returnType=${returnType}`, 'POST', this.filters, false, true, true, {
|
|
112
112
|
'content-type': 'application/json;charset=UTF-8',
|
|
113
113
|
});
|
|
114
114
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -6,4 +6,5 @@ export type { Entity } from "./models/Entity";
|
|
|
6
6
|
export type { State } from "./models/State";
|
|
7
7
|
export { RepositoryEndpoint } from "./models/RepositoryEndpoint";
|
|
8
8
|
export { RepositoryServices } from "./servicecollection/RepositoryServices";
|
|
9
|
+
export { RepositorySettings, ITransformer } from "./servicecollection/RepositorySettings";
|
|
9
10
|
export { useRepository, useCommand, useQuery } from "./hooks/hooks";
|
package/lib/index.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useQuery = exports.useCommand = exports.useRepository = exports.RepositoryServices = exports.RepositoryEndpoint = void 0;
|
|
3
|
+
exports.useQuery = exports.useCommand = exports.useRepository = exports.RepositorySettings = exports.RepositoryServices = exports.RepositoryEndpoint = void 0;
|
|
4
4
|
var RepositoryEndpoint_1 = require("./models/RepositoryEndpoint");
|
|
5
5
|
Object.defineProperty(exports, "RepositoryEndpoint", { enumerable: true, get: function () { return RepositoryEndpoint_1.RepositoryEndpoint; } });
|
|
6
6
|
var RepositoryServices_1 = require("./servicecollection/RepositoryServices");
|
|
7
7
|
Object.defineProperty(exports, "RepositoryServices", { enumerable: true, get: function () { return RepositoryServices_1.RepositoryServices; } });
|
|
8
|
+
var RepositorySettings_1 = require("./servicecollection/RepositorySettings");
|
|
9
|
+
Object.defineProperty(exports, "RepositorySettings", { enumerable: true, get: function () { return RepositorySettings_1.RepositorySettings; } });
|
|
8
10
|
var hooks_1 = require("./hooks/hooks");
|
|
9
11
|
Object.defineProperty(exports, "useRepository", { enumerable: true, get: function () { return hooks_1.useRepository; } });
|
|
10
12
|
Object.defineProperty(exports, "useCommand", { enumerable: true, get: function () { return hooks_1.useCommand; } });
|
package/lib/models/Entity.d.ts
CHANGED
|
@@ -2,3 +2,10 @@ export type Entity<T, TKey> = {
|
|
|
2
2
|
value: T;
|
|
3
3
|
key: TKey;
|
|
4
4
|
};
|
|
5
|
+
export type SerializedEntity<T, TKey> = {
|
|
6
|
+
v: T;
|
|
7
|
+
k: TKey;
|
|
8
|
+
};
|
|
9
|
+
export declare function isEntity<T, TKey>(obj: any): obj is Entity<T, TKey>;
|
|
10
|
+
export declare function isSerializedEntity<T, TKey>(obj: any): obj is SerializedEntity<T, TKey>;
|
|
11
|
+
export declare function isSerializedEntityArray<T, TKey>(arr: any): arr is SerializedEntity<T, TKey>[];
|
package/lib/models/Entity.js
CHANGED
|
@@ -1,2 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEntity = isEntity;
|
|
4
|
+
exports.isSerializedEntity = isSerializedEntity;
|
|
5
|
+
exports.isSerializedEntityArray = isSerializedEntityArray;
|
|
6
|
+
function isEntity(obj) {
|
|
7
|
+
return (typeof obj === 'object' &&
|
|
8
|
+
obj !== null &&
|
|
9
|
+
'value' in obj &&
|
|
10
|
+
'key' in obj);
|
|
11
|
+
}
|
|
12
|
+
function isSerializedEntity(obj) {
|
|
13
|
+
return (typeof obj === 'object' &&
|
|
14
|
+
obj !== null &&
|
|
15
|
+
'v' in obj &&
|
|
16
|
+
'k' in obj);
|
|
17
|
+
}
|
|
18
|
+
function isSerializedEntityArray(arr) {
|
|
19
|
+
return Array.isArray(arr) && arr.every(isSerializedEntity);
|
|
20
|
+
}
|
package/lib/models/State.d.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
export type State<T, TKey> = {
|
|
2
2
|
isOk: boolean;
|
|
3
|
-
|
|
3
|
+
entity: {
|
|
4
4
|
key: TKey;
|
|
5
5
|
value: T;
|
|
6
6
|
};
|
|
7
|
+
code: number | null;
|
|
8
|
+
message: string | null;
|
|
9
|
+
};
|
|
10
|
+
export type SerializedState<T, TKey> = {
|
|
11
|
+
i: boolean;
|
|
12
|
+
e: {
|
|
13
|
+
k: TKey;
|
|
14
|
+
v: T;
|
|
15
|
+
};
|
|
7
16
|
c: number | null;
|
|
8
17
|
m: string | null;
|
|
9
18
|
};
|
|
19
|
+
export declare function isState<T, TKey>(obj: any): obj is State<T, TKey>;
|
|
20
|
+
export declare function isSerializedState<T, TKey>(obj: any): obj is SerializedState<T, TKey>;
|
package/lib/models/State.js
CHANGED
|
@@ -1,2 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isState = isState;
|
|
4
|
+
exports.isSerializedState = isSerializedState;
|
|
5
|
+
function isState(obj) {
|
|
6
|
+
return (typeof obj === 'object' &&
|
|
7
|
+
obj !== null &&
|
|
8
|
+
typeof obj.isOk === 'boolean' &&
|
|
9
|
+
typeof obj.entity === 'object' &&
|
|
10
|
+
obj.entity !== null &&
|
|
11
|
+
'key' in obj.entity &&
|
|
12
|
+
'value' in obj.entity &&
|
|
13
|
+
('code' in obj || obj.code === null) &&
|
|
14
|
+
('message' in obj || obj.message === null));
|
|
15
|
+
}
|
|
16
|
+
function isSerializedState(obj) {
|
|
17
|
+
return (typeof obj === 'object' &&
|
|
18
|
+
obj !== null &&
|
|
19
|
+
typeof obj.i === 'boolean' &&
|
|
20
|
+
(obj.e === null || (typeof obj.e === 'object' &&
|
|
21
|
+
obj.e !== null &&
|
|
22
|
+
'k' in obj.e &&
|
|
23
|
+
'v' in obj.e)) &&
|
|
24
|
+
('c' in obj || obj.c === null) &&
|
|
25
|
+
('m' in obj || obj.m === null));
|
|
26
|
+
}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { RepositoryEndpoint } from "../models/RepositoryEndpoint";
|
|
2
|
+
export interface ITransformer<T> {
|
|
3
|
+
toPlain: (input: T | any) => any;
|
|
4
|
+
fromPlain: (input: any) => T;
|
|
5
|
+
}
|
|
2
6
|
export declare class RepositorySettings {
|
|
3
7
|
name: string;
|
|
4
8
|
uri: string | null;
|
|
5
9
|
path: string | null;
|
|
10
|
+
case: "PascalCase" | "CamelCase";
|
|
11
|
+
transformer?: ITransformer<any>;
|
|
12
|
+
keyTransformer?: ITransformer<any>;
|
|
6
13
|
complexKey: boolean;
|
|
7
14
|
private headersEnrichers;
|
|
8
15
|
private errorsHandlers;
|
|
@@ -5,6 +5,9 @@ class RepositorySettings {
|
|
|
5
5
|
name;
|
|
6
6
|
uri;
|
|
7
7
|
path;
|
|
8
|
+
case;
|
|
9
|
+
transformer; // For T
|
|
10
|
+
keyTransformer; // For TKey
|
|
8
11
|
complexKey;
|
|
9
12
|
headersEnrichers;
|
|
10
13
|
errorsHandlers;
|
|
@@ -12,6 +15,7 @@ class RepositorySettings {
|
|
|
12
15
|
this.name = "";
|
|
13
16
|
this.uri = null;
|
|
14
17
|
this.path = null;
|
|
18
|
+
this.case = "PascalCase";
|
|
15
19
|
this.complexKey = false;
|
|
16
20
|
this.headersEnrichers = new Array();
|
|
17
21
|
this.errorsHandlers = new Array();
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rystem.repository.client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"author": "Alessandro Rapiti <alessandro.rapiti44@gmail.com>",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "It can simplify the integration with rystem repository server.",
|
|
7
7
|
"main": "./lib/index.js",
|
|
8
8
|
"types": "./lib/index.d.ts",
|
|
9
|
-
"dependencies": {
|
|
10
|
-
},
|
|
11
9
|
"devDependencies": {
|
|
12
|
-
"react": "
|
|
13
|
-
"react-
|
|
10
|
+
"@types/react": "19.0.10",
|
|
11
|
+
"@types/react-dom": "19.0.4",
|
|
12
|
+
"@typescript-eslint/parser": "8.24.1",
|
|
13
|
+
"typescript": "5.7.3"
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"/lib"
|