rystem.repository.client 0.2.7 → 10.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.
Files changed (42) hide show
  1. package/README.md +321 -161
  2. package/package.json +6 -1
  3. package/lib/engine/Repository.d.ts +0 -27
  4. package/lib/engine/Repository.js +0 -333
  5. package/lib/engine/batch/Batch.d.ts +0 -9
  6. package/lib/engine/batch/Batch.js +0 -17
  7. package/lib/engine/batch/BatchBuilder.d.ts +0 -13
  8. package/lib/engine/batch/BatchBuilder.js +0 -48
  9. package/lib/engine/batch/BatchOperation.d.ts +0 -12
  10. package/lib/engine/batch/BatchOperation.js +0 -16
  11. package/lib/engine/batch/BatchResult.d.ts +0 -13
  12. package/lib/engine/batch/BatchResult.js +0 -18
  13. package/lib/engine/query/FilterOperationAsString.d.ts +0 -5
  14. package/lib/engine/query/FilterOperationAsString.js +0 -2
  15. package/lib/engine/query/FilterOperations.d.ts +0 -11
  16. package/lib/engine/query/FilterOperations.js +0 -15
  17. package/lib/engine/query/QueryBuilder.d.ts +0 -25
  18. package/lib/engine/query/QueryBuilder.js +0 -116
  19. package/lib/engine/query/SerializableFilter.d.ts +0 -4
  20. package/lib/engine/query/SerializableFilter.js +0 -2
  21. package/lib/engine/query/filter/WhereBuilder.d.ts +0 -33
  22. package/lib/engine/query/filter/WhereBuilder.js +0 -170
  23. package/lib/hooks/hooks.d.ts +0 -9
  24. package/lib/hooks/hooks.js +0 -28
  25. package/lib/index.d.ts +0 -11
  26. package/lib/index.js +0 -16
  27. package/lib/interfaces/ICommand.d.ts +0 -14
  28. package/lib/interfaces/ICommand.js +0 -2
  29. package/lib/interfaces/IQuery.d.ts +0 -12
  30. package/lib/interfaces/IQuery.js +0 -2
  31. package/lib/interfaces/IRepository.d.ts +0 -6
  32. package/lib/interfaces/IRepository.js +0 -2
  33. package/lib/models/Entity.d.ts +0 -11
  34. package/lib/models/Entity.js +0 -20
  35. package/lib/models/RepositoryEndpoint.d.ts +0 -12
  36. package/lib/models/RepositoryEndpoint.js +0 -16
  37. package/lib/models/State.d.ts +0 -20
  38. package/lib/models/State.js +0 -26
  39. package/lib/servicecollection/RepositoryServices.d.ts +0 -23
  40. package/lib/servicecollection/RepositoryServices.js +0 -106
  41. package/lib/servicecollection/RepositorySettings.d.ts +0 -22
  42. package/lib/servicecollection/RepositorySettings.js +0 -58
@@ -1,333 +0,0 @@
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
- }
@@ -1,9 +0,0 @@
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>;
@@ -1,17 +0,0 @@
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
- }
@@ -1,13 +0,0 @@
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
- }
@@ -1,48 +0,0 @@
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;
@@ -1,12 +0,0 @@
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>;
@@ -1,16 +0,0 @@
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,13 +0,0 @@
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>;
@@ -1,18 +0,0 @@
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
- }
@@ -1,5 +0,0 @@
1
- import { FilterOperations } from "./FilterOperations";
2
- export type FilterOperationAsString = {
3
- q: FilterOperations;
4
- v: string;
5
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,11 +0,0 @@
1
- export declare enum FilterOperations {
2
- Select = 1,
3
- Where = 2,
4
- Top = 4,
5
- Skip = 8,
6
- OrderBy = 16,
7
- OrderByDescending = 32,
8
- ThenBy = 64,
9
- ThenByDescending = 128,
10
- GroupBy = 256
11
- }
@@ -1,15 +0,0 @@
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 = {}));
@@ -1,25 +0,0 @@
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
- }
@@ -1,116 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QueryBuilder = void 0;
4
- const RepositoryEndpoint_1 = require("../../models/RepositoryEndpoint");
5
- const Repository_1 = require("../Repository");
6
- const WhereBuilder_1 = require("./filter/WhereBuilder");
7
- const FilterOperations_1 = require("./FilterOperations");
8
- class QueryBuilder {
9
- filters;
10
- repository;
11
- constructor(repository) {
12
- this.filters = {
13
- o: []
14
- };
15
- this.repository = repository;
16
- }
17
- where() {
18
- return new WhereBuilder_1.WhereBuilder(this);
19
- }
20
- filter(predicate) {
21
- this.filters.o.push({
22
- q: FilterOperations_1.FilterOperations.Where,
23
- v: predicate
24
- });
25
- return this;
26
- }
27
- top(value) {
28
- this.filters.o.push({
29
- q: FilterOperations_1.FilterOperations.Top,
30
- v: value.toString()
31
- });
32
- return this;
33
- }
34
- skip(value) {
35
- this.filters.o.push({
36
- q: FilterOperations_1.FilterOperations.Skip,
37
- v: value.toString()
38
- });
39
- return this;
40
- }
41
- orderBy(predicate) {
42
- this.filters.o.push({
43
- q: FilterOperations_1.FilterOperations.OrderBy,
44
- v: `_rystem => ${Repository_1.Repository.predicateAsString(predicate)}`
45
- });
46
- return this;
47
- }
48
- orderByDescending(predicate) {
49
- this.filters.o.push({
50
- q: FilterOperations_1.FilterOperations.OrderByDescending,
51
- v: `_rystem => ${Repository_1.Repository.predicateAsString(predicate)}`
52
- });
53
- return this;
54
- }
55
- thenBy(predicate) {
56
- this.filters.o.push({
57
- q: FilterOperations_1.FilterOperations.ThenBy,
58
- v: `_rystem => ${Repository_1.Repository.predicateAsString(predicate)}`
59
- });
60
- return this;
61
- }
62
- thenByDescending(predicate) {
63
- this.filters.o.push({
64
- q: FilterOperations_1.FilterOperations.ThenByDescending,
65
- v: `_rystem => ${Repository_1.Repository.predicateAsString(predicate)}`
66
- });
67
- return this;
68
- }
69
- execute() {
70
- return this.repository.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Query, `Query`, 'POST', this.filters, false, true, false, {
71
- 'content-type': 'application/json;charset=UTF-8',
72
- });
73
- }
74
- executeAsStream(entityReader, cancellationToken = null) {
75
- return this.repository.makeRequestAsStream(RepositoryEndpoint_1.RepositoryEndpoint.QueryStream, `Query`, 'POST', entityReader, this.filters, false, true, false, {
76
- 'content-type': 'application/json;charset=UTF-8',
77
- }, cancellationToken);
78
- }
79
- count() {
80
- return this.executeOperation("Count", "long");
81
- }
82
- max(predicate) {
83
- this.filters.o.push({
84
- q: FilterOperations_1.FilterOperations.Select,
85
- v: `_rystem => ${Repository_1.Repository.predicateAsString(predicate)}`
86
- });
87
- return this.executeOperation("Max", "decimal");
88
- }
89
- min(predicate) {
90
- this.filters.o.push({
91
- q: FilterOperations_1.FilterOperations.Select,
92
- v: `_rystem => ${Repository_1.Repository.predicateAsString(predicate)}`
93
- });
94
- return this.executeOperation("Min", "decimal");
95
- }
96
- average(predicate) {
97
- this.filters.o.push({
98
- q: FilterOperations_1.FilterOperations.Select,
99
- v: `_rystem => ${Repository_1.Repository.predicateAsString(predicate)}`
100
- });
101
- return this.executeOperation("Average", "decimal");
102
- }
103
- sum(predicate) {
104
- this.filters.o.push({
105
- q: FilterOperations_1.FilterOperations.Select,
106
- v: `_rystem => ${Repository_1.Repository.predicateAsString(predicate)}`
107
- });
108
- return this.executeOperation("Sum", "decimal");
109
- }
110
- executeOperation(operation, returnType) {
111
- return this.repository.makeRequest(RepositoryEndpoint_1.RepositoryEndpoint.Operation, `Operation?op=${operation}&returnType=${returnType}`, 'POST', this.filters, false, true, true, {
112
- 'content-type': 'application/json;charset=UTF-8',
113
- });
114
- }
115
- }
116
- exports.QueryBuilder = QueryBuilder;
@@ -1,4 +0,0 @@
1
- import { FilterOperationAsString } from "./FilterOperationAsString";
2
- export type SerializableFilter = {
3
- o: Array<FilterOperationAsString>;
4
- };