rystem.repository.client 10.1.0-beta.3 → 11.1.0-beta.3
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 +27 -0
- package/lib/engine/Repository.js +333 -0
- package/lib/engine/batch/Batch.d.ts +9 -0
- package/lib/engine/batch/Batch.js +17 -0
- package/lib/engine/batch/BatchBuilder.d.ts +13 -0
- package/lib/engine/batch/BatchBuilder.js +48 -0
- package/lib/engine/batch/BatchOperation.d.ts +12 -0
- package/lib/engine/batch/BatchOperation.js +16 -0
- package/lib/engine/batch/BatchResult.d.ts +13 -0
- package/lib/engine/batch/BatchResult.js +18 -0
- package/lib/engine/query/FilterOperationAsString.d.ts +5 -0
- package/lib/engine/query/FilterOperationAsString.js +2 -0
- package/lib/engine/query/FilterOperations.d.ts +11 -0
- package/lib/engine/query/FilterOperations.js +15 -0
- package/lib/engine/query/QueryBuilder.d.ts +25 -0
- package/lib/engine/query/QueryBuilder.js +116 -0
- package/lib/engine/query/SerializableFilter.d.ts +4 -0
- package/lib/engine/query/SerializableFilter.js +2 -0
- package/lib/engine/query/filter/WhereBuilder.d.ts +33 -0
- package/lib/engine/query/filter/WhereBuilder.js +170 -0
- package/lib/hooks/hooks.d.ts +9 -0
- package/lib/hooks/hooks.js +28 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +16 -0
- package/lib/interfaces/ICommand.d.ts +14 -0
- package/lib/interfaces/ICommand.js +2 -0
- package/lib/interfaces/IQuery.d.ts +12 -0
- package/lib/interfaces/IQuery.js +2 -0
- package/lib/interfaces/IRepository.d.ts +6 -0
- package/lib/interfaces/IRepository.js +2 -0
- package/lib/models/Entity.d.ts +11 -0
- package/lib/models/Entity.js +20 -0
- package/lib/models/RepositoryEndpoint.d.ts +12 -0
- package/lib/models/RepositoryEndpoint.js +16 -0
- package/lib/models/State.d.ts +20 -0
- package/lib/models/State.js +26 -0
- package/lib/servicecollection/RepositoryServices.d.ts +23 -0
- package/lib/servicecollection/RepositoryServices.js +106 -0
- package/lib/servicecollection/RepositorySettings.d.ts +22 -0
- package/lib/servicecollection/RepositorySettings.js +58 -0
- package/package.json +10 -6
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CancellationToken } from "typescript";
|
|
2
|
+
import { IRepository } from "../interfaces/IRepository";
|
|
3
|
+
import { RepositoryEndpoint } from "../models/RepositoryEndpoint";
|
|
4
|
+
import { State } from "../models/State";
|
|
5
|
+
import { RepositorySettings } from "../servicecollection/RepositorySettings";
|
|
6
|
+
import { BatchBuilder } from "./batch/BatchBuilder";
|
|
7
|
+
import { QueryBuilder } from "./query/QueryBuilder";
|
|
8
|
+
export declare class Repository<T, TKey> implements IRepository<T, TKey> {
|
|
9
|
+
private baseUri;
|
|
10
|
+
private settings;
|
|
11
|
+
constructor(baseUri: string | null, settings: RepositorySettings);
|
|
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>>;
|
|
16
|
+
private isPrimitive;
|
|
17
|
+
private objectToString;
|
|
18
|
+
private keyToPlainForQuery;
|
|
19
|
+
get(key: TKey): Promise<T>;
|
|
20
|
+
insert(key: TKey, value: T): Promise<State<T, TKey>>;
|
|
21
|
+
update(key: TKey, value: T): Promise<State<T, TKey>>;
|
|
22
|
+
exist(key: TKey): Promise<State<T, TKey>>;
|
|
23
|
+
delete(key: TKey): Promise<State<T, TKey>>;
|
|
24
|
+
batch(): BatchBuilder<T, TKey>;
|
|
25
|
+
query(): QueryBuilder<T, TKey>;
|
|
26
|
+
static predicateAsString<T>(predicate: (value: T) => any): string;
|
|
27
|
+
}
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Repository = void 0;
|
|
4
|
+
const Entity_1 = require("../models/Entity");
|
|
5
|
+
const RepositoryEndpoint_1 = require("../models/RepositoryEndpoint");
|
|
6
|
+
const State_1 = require("../models/State");
|
|
7
|
+
const BatchBuilder_1 = require("./batch/BatchBuilder");
|
|
8
|
+
const Batch_1 = require("./batch/Batch");
|
|
9
|
+
const BatchResult_1 = require("./batch/BatchResult");
|
|
10
|
+
const QueryBuilder_1 = require("./query/QueryBuilder");
|
|
11
|
+
class Repository {
|
|
12
|
+
baseUri;
|
|
13
|
+
settings;
|
|
14
|
+
constructor(baseUri, settings) {
|
|
15
|
+
if (settings.uri == null)
|
|
16
|
+
this.baseUri = `${baseUri}${settings.path}`;
|
|
17
|
+
else
|
|
18
|
+
this.baseUri = settings.uri;
|
|
19
|
+
this.settings = settings;
|
|
20
|
+
}
|
|
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 = {}) {
|
|
136
|
+
let retry = true;
|
|
137
|
+
let response = null;
|
|
138
|
+
const uri = `${this.baseUri}/${path}`;
|
|
139
|
+
while (retry) {
|
|
140
|
+
response = await fetch(uri, {
|
|
141
|
+
method: method,
|
|
142
|
+
headers: await this.settings.enrichHeaders(endpoint, uri, method, headers, body),
|
|
143
|
+
body: body == null ? null : JSON.stringify(skipSerialization ? body : this.serializeRequestBody(body, bodyIsKey))
|
|
144
|
+
})
|
|
145
|
+
.then(async (res) => {
|
|
146
|
+
const json = await res.json();
|
|
147
|
+
if (!res.ok)
|
|
148
|
+
throw json;
|
|
149
|
+
return json;
|
|
150
|
+
})
|
|
151
|
+
.catch(async (err) => {
|
|
152
|
+
retry = await this.settings.manageError(endpoint, uri, method, headers, body, err);
|
|
153
|
+
return null;
|
|
154
|
+
})
|
|
155
|
+
.then(res => {
|
|
156
|
+
retry = false;
|
|
157
|
+
return skipSerializationOnResponse ? res : this.transformResponse(res);
|
|
158
|
+
});
|
|
159
|
+
if (retry)
|
|
160
|
+
await new Promise(f => setTimeout(f, 200));
|
|
161
|
+
}
|
|
162
|
+
return response;
|
|
163
|
+
}
|
|
164
|
+
async makeRequestAsStream(endpoint, path, method, reader, body = null, bodyIsKey = false, skipSerialization = false, skipSerializationOnResponse = false, headers = {}, cancellationToken = null) {
|
|
165
|
+
const uri = `${this.baseUri}/${path}/Stream`;
|
|
166
|
+
let response = [];
|
|
167
|
+
await fetch(uri, {
|
|
168
|
+
method: method,
|
|
169
|
+
headers: await this.settings.enrichHeaders(endpoint, uri, method, headers, body),
|
|
170
|
+
body: body == null ? null : JSON.stringify(skipSerialization ? body : this.serializeRequestBody(body, bodyIsKey))
|
|
171
|
+
})
|
|
172
|
+
.then(async (res) => {
|
|
173
|
+
const bodyReader = res.body?.getReader();
|
|
174
|
+
const decoder = new JsonStreamDecoder();
|
|
175
|
+
if (bodyReader != undefined) {
|
|
176
|
+
while (true) {
|
|
177
|
+
const { done, value } = await bodyReader.read();
|
|
178
|
+
if (done)
|
|
179
|
+
break;
|
|
180
|
+
if (!value)
|
|
181
|
+
continue;
|
|
182
|
+
if (cancellationToken?.isCancellationRequested())
|
|
183
|
+
break;
|
|
184
|
+
decoder.decodeChunk(value, entity => {
|
|
185
|
+
const transformed = skipSerializationOnResponse ? entity : this.transformResponse(entity);
|
|
186
|
+
response.push(transformed);
|
|
187
|
+
reader(transformed);
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
bodyReader.releaseLock();
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
.catch(async (err) => {
|
|
194
|
+
this.settings.manageError(endpoint, uri, method, headers, body, err);
|
|
195
|
+
return null;
|
|
196
|
+
});
|
|
197
|
+
return response;
|
|
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
|
+
}
|
|
223
|
+
get(key) {
|
|
224
|
+
if (!this.settings.complexKey) {
|
|
225
|
+
const keyString = this.keyToPlainForQuery(key);
|
|
226
|
+
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Get, `Get?key=${keyString}`, 'GET');
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Get, `Get`, 'POST', key, true, false, false, {
|
|
230
|
+
'content-type': 'application/json;charset=UTF-8'
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
insert(key, value) {
|
|
235
|
+
if (!this.settings.complexKey) {
|
|
236
|
+
const keyString = this.keyToPlainForQuery(key);
|
|
237
|
+
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Insert, `Insert?key=${keyString}`, 'POST', value, false, false, false, {
|
|
238
|
+
'content-type': 'application/json;charset=UTF-8'
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Insert, `Insert`, 'POST', {
|
|
243
|
+
value: value,
|
|
244
|
+
key: key
|
|
245
|
+
}, false, false, false, {
|
|
246
|
+
'content-type': 'application/json;charset=UTF-8'
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
update(key, value) {
|
|
251
|
+
if (!this.settings.complexKey) {
|
|
252
|
+
const keyString = this.keyToPlainForQuery(key);
|
|
253
|
+
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Update, `Update?key=${keyString}`, 'POST', value, false, false, false, {
|
|
254
|
+
'content-type': 'application/json;charset=UTF-8'
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Update, `Update`, 'POST', {
|
|
259
|
+
value: value,
|
|
260
|
+
key: key
|
|
261
|
+
}, false, false, false, {
|
|
262
|
+
'content-type': 'application/json;charset=UTF-8'
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
exist(key) {
|
|
267
|
+
if (!this.settings.complexKey) {
|
|
268
|
+
const keyString = this.keyToPlainForQuery(key);
|
|
269
|
+
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Exist, `Exist?key=${keyString}`, 'GET');
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Exist, `Exist`, 'POST', key, true, false, false, {
|
|
273
|
+
'content-type': 'application/json;charset=UTF-8'
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
delete(key) {
|
|
278
|
+
if (!this.settings.complexKey) {
|
|
279
|
+
const keyString = this.keyToPlainForQuery(key);
|
|
280
|
+
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Delete, `Delete?key=${keyString}`, 'GET');
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
return this.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Delete, `Delete`, 'POST', key, true, false, false, {
|
|
284
|
+
'content-type': 'application/json;charset=UTF-8'
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
batch() {
|
|
289
|
+
return new BatchBuilder_1.BatchBuilder(this);
|
|
290
|
+
}
|
|
291
|
+
query() {
|
|
292
|
+
return new QueryBuilder_1.QueryBuilder(this);
|
|
293
|
+
}
|
|
294
|
+
static predicateAsString(predicate) {
|
|
295
|
+
const splittedPredicate = predicate.toString().split('.');
|
|
296
|
+
const variableName = splittedPredicate.slice(-(splittedPredicate.length - 1)).join('.');
|
|
297
|
+
return `_rystem.${variableName}`;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
exports.Repository = Repository;
|
|
301
|
+
class JsonStreamDecoder {
|
|
302
|
+
level = 0;
|
|
303
|
+
partialItem = '';
|
|
304
|
+
static JTOKEN_START_OBJECT = '{';
|
|
305
|
+
static JTOKEN_END_OBJECT = '}';
|
|
306
|
+
decoder = new TextDecoder();
|
|
307
|
+
decodeChunk(value, decodedItemCallback) {
|
|
308
|
+
const chunk = this.decoder.decode(value);
|
|
309
|
+
let itemStart = 0;
|
|
310
|
+
for (let i = 0; i < chunk.length; i++) {
|
|
311
|
+
if (chunk[i] === JsonStreamDecoder.JTOKEN_START_OBJECT) {
|
|
312
|
+
if (this.level === 0) {
|
|
313
|
+
itemStart = i;
|
|
314
|
+
}
|
|
315
|
+
this.level++;
|
|
316
|
+
}
|
|
317
|
+
if (chunk[i] === JsonStreamDecoder.JTOKEN_END_OBJECT) {
|
|
318
|
+
this.level--;
|
|
319
|
+
if (this.level === 0) {
|
|
320
|
+
let item = chunk.substring(itemStart, i + 1);
|
|
321
|
+
if (this.partialItem) {
|
|
322
|
+
item = this.partialItem + item;
|
|
323
|
+
this.partialItem = '';
|
|
324
|
+
}
|
|
325
|
+
decodedItemCallback(JSON.parse(item));
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
if (this.level !== 0) {
|
|
330
|
+
this.partialItem = chunk.substring(itemStart);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BatchOperation } from "./BatchOperation";
|
|
2
|
+
export type Batch<T, TKey> = {
|
|
3
|
+
values: Array<BatchOperation<T, TKey>>;
|
|
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>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Repository } from "../Repository";
|
|
2
|
+
import { BatchResult } from "./BatchResult";
|
|
3
|
+
import { CancellationToken } from "typescript";
|
|
4
|
+
export declare class BatchBuilder<T, TKey> {
|
|
5
|
+
private batch;
|
|
6
|
+
private repository;
|
|
7
|
+
constructor(repository: Repository<T, TKey>);
|
|
8
|
+
addInsert(key: TKey, value: T): BatchBuilder<T, TKey>;
|
|
9
|
+
addUpdate(key: TKey, value: T): BatchBuilder<T, TKey>;
|
|
10
|
+
addDelete(key: TKey): BatchBuilder<T, TKey>;
|
|
11
|
+
execute(): Promise<Array<BatchResult<T, TKey>>>;
|
|
12
|
+
executeAsStream(entityReader: (entity: BatchResult<T, TKey>) => void, cancellationToken?: CancellationToken | null): Promise<Array<BatchResult<T, TKey>>>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BatchBuilder = void 0;
|
|
4
|
+
const RepositoryEndpoint_1 = require("../../models/RepositoryEndpoint");
|
|
5
|
+
class BatchBuilder {
|
|
6
|
+
batch;
|
|
7
|
+
repository;
|
|
8
|
+
constructor(repository) {
|
|
9
|
+
this.batch = {
|
|
10
|
+
values: []
|
|
11
|
+
};
|
|
12
|
+
this.repository = repository;
|
|
13
|
+
}
|
|
14
|
+
addInsert(key, value) {
|
|
15
|
+
this.batch.values.push({
|
|
16
|
+
command: 1,
|
|
17
|
+
key: key,
|
|
18
|
+
value: value
|
|
19
|
+
});
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
addUpdate(key, value) {
|
|
23
|
+
this.batch.values.push({
|
|
24
|
+
command: 2,
|
|
25
|
+
key: key,
|
|
26
|
+
value: value
|
|
27
|
+
});
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
addDelete(key) {
|
|
31
|
+
this.batch.values.push({
|
|
32
|
+
command: 4,
|
|
33
|
+
key: key
|
|
34
|
+
});
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
execute() {
|
|
38
|
+
return this.repository.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Batch, `Batch`, 'POST', this.batch, false, false, false, {
|
|
39
|
+
'content-type': 'application/json;charset=UTF-8',
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
executeAsStream(entityReader, cancellationToken = null) {
|
|
43
|
+
return this.repository.makeRequestAsStream(RepositoryEndpoint_1.RepositoryEndpoint.BatchStream, `Batch`, 'POST', entityReader, this.batch, false, false, false, {
|
|
44
|
+
'content-type': 'application/json;charset=UTF-8',
|
|
45
|
+
}, cancellationToken);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.BatchBuilder = BatchBuilder;
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { State, SerializedState } from "../../models/State";
|
|
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> = {
|
|
8
|
+
c: 1 | 2 | 4;
|
|
9
|
+
k: TKey;
|
|
10
|
+
s: SerializedState<T, TKey>;
|
|
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>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FilterOperations = void 0;
|
|
4
|
+
var FilterOperations;
|
|
5
|
+
(function (FilterOperations) {
|
|
6
|
+
FilterOperations[FilterOperations["Select"] = 1] = "Select";
|
|
7
|
+
FilterOperations[FilterOperations["Where"] = 2] = "Where";
|
|
8
|
+
FilterOperations[FilterOperations["Top"] = 4] = "Top";
|
|
9
|
+
FilterOperations[FilterOperations["Skip"] = 8] = "Skip";
|
|
10
|
+
FilterOperations[FilterOperations["OrderBy"] = 16] = "OrderBy";
|
|
11
|
+
FilterOperations[FilterOperations["OrderByDescending"] = 32] = "OrderByDescending";
|
|
12
|
+
FilterOperations[FilterOperations["ThenBy"] = 64] = "ThenBy";
|
|
13
|
+
FilterOperations[FilterOperations["ThenByDescending"] = 128] = "ThenByDescending";
|
|
14
|
+
FilterOperations[FilterOperations["GroupBy"] = 256] = "GroupBy";
|
|
15
|
+
})(FilterOperations || (exports.FilterOperations = FilterOperations = {}));
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CancellationToken } from "typescript";
|
|
2
|
+
import { Entity } from "../../models/Entity";
|
|
3
|
+
import { Repository } from "../Repository";
|
|
4
|
+
import { WhereBuilder } from "./filter/WhereBuilder";
|
|
5
|
+
export declare class QueryBuilder<T, TKey> {
|
|
6
|
+
private filters;
|
|
7
|
+
private repository;
|
|
8
|
+
constructor(repository: Repository<T, TKey>);
|
|
9
|
+
where(): WhereBuilder<T, TKey>;
|
|
10
|
+
filter(predicate: string): this;
|
|
11
|
+
top(value: number): this;
|
|
12
|
+
skip(value: number): this;
|
|
13
|
+
orderBy(predicate: (value: T) => any): this;
|
|
14
|
+
orderByDescending(predicate: (value: T) => any): this;
|
|
15
|
+
thenBy(predicate: (value: T) => any): this;
|
|
16
|
+
thenByDescending(predicate: (value: T) => any): this;
|
|
17
|
+
execute(): Promise<Array<Entity<T, TKey>>>;
|
|
18
|
+
executeAsStream(entityReader: (entity: Entity<T, TKey>) => void, cancellationToken?: CancellationToken | null): Promise<Array<Entity<T, TKey>>>;
|
|
19
|
+
count(): Promise<number>;
|
|
20
|
+
max(predicate: (value: T) => any): Promise<number>;
|
|
21
|
+
min(predicate: (value: T) => any): Promise<number>;
|
|
22
|
+
average(predicate: (value: T) => any): Promise<number>;
|
|
23
|
+
sum(predicate: (value: T) => any): Promise<number>;
|
|
24
|
+
private executeOperation;
|
|
25
|
+
}
|