@forge/storage 1.3.1 → 1.3.2-experimental-58938ba
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/CHANGELOG.md +328 -0
- package/out/__test__/global-storage.test.js +209 -11
- package/out/__test__/list-api.test.js +540 -1
- package/out/eap/conditions.d.ts +37 -1
- package/out/eap/conditions.d.ts.map +1 -1
- package/out/eap/conditions.js +96 -1
- package/out/entity-storage/index.d.ts +2 -0
- package/out/entity-storage/index.d.ts.map +1 -0
- package/out/entity-storage/index.js +5 -0
- package/out/entity-storage/query-api.d.ts +48 -0
- package/out/entity-storage/query-api.d.ts.map +1 -0
- package/out/entity-storage/query-api.js +118 -0
- package/out/entity-storage/storage-builder.d.ts +20 -0
- package/out/entity-storage/storage-builder.d.ts.map +1 -0
- package/out/entity-storage/storage-builder.js +23 -0
- package/out/global-storage.d.ts +8 -3
- package/out/global-storage.d.ts.map +1 -1
- package/out/global-storage.js +41 -14
- package/out/gql-queries.d.ts +98 -0
- package/out/gql-queries.d.ts.map +1 -0
- package/out/gql-queries.js +222 -0
- package/out/index.d.ts +5 -1
- package/out/index.d.ts.map +1 -1
- package/out/index.js +7 -2
- package/out/query-api.d.ts +1 -1
- package/out/query-api.d.ts.map +1 -1
- package/out/query-interfaces.d.ts +113 -0
- package/out/query-interfaces.d.ts.map +1 -0
- package/out/query-interfaces.js +8 -0
- package/out/storage-adapter.d.ts +24 -13
- package/out/storage-adapter.d.ts.map +1 -1
- package/package.json +1 -1
- package/out/queries.d.ts +0 -69
- package/out/queries.d.ts.map +0 -1
- package/out/queries.js +0 -124
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const query_api_1 = require("../query-api");
|
|
4
|
+
const query_api_2 = require("../entity-storage/query-api");
|
|
4
5
|
const conditions_1 = require("../conditions");
|
|
5
6
|
const conditions_2 = require("../eap/conditions");
|
|
6
|
-
|
|
7
|
+
const query_interfaces_1 = require("../query-interfaces");
|
|
8
|
+
describe('DefaultQueryBuilder Untyped entities', () => {
|
|
7
9
|
function newGlobalStorage() {
|
|
8
10
|
return {
|
|
9
11
|
list: jest.fn()
|
|
@@ -109,3 +111,540 @@ describe('DefaultQueryBuilder', () => {
|
|
|
109
111
|
}));
|
|
110
112
|
});
|
|
111
113
|
});
|
|
114
|
+
describe('DefaultQueryBuilder CustomEntities', () => {
|
|
115
|
+
function newGlobalStorage() {
|
|
116
|
+
return {
|
|
117
|
+
listCustomEntities: jest.fn()
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
it('should only have "entity" as option for default base query builder', () => {
|
|
121
|
+
const globalStorage = newGlobalStorage();
|
|
122
|
+
const baseQueryBuilderInstance = new query_api_2.CustomEntityBuilder(globalStorage);
|
|
123
|
+
expect(baseQueryBuilderInstance).toHaveProperty('entity');
|
|
124
|
+
expect(baseQueryBuilderInstance).not.toHaveProperty('index');
|
|
125
|
+
expect(baseQueryBuilderInstance).not.toHaveProperty('where');
|
|
126
|
+
expect(baseQueryBuilderInstance).not.toHaveProperty('andFilter');
|
|
127
|
+
expect(baseQueryBuilderInstance).not.toHaveProperty('orFilter');
|
|
128
|
+
expect(baseQueryBuilderInstance).not.toHaveProperty('cursor');
|
|
129
|
+
expect(baseQueryBuilderInstance).not.toHaveProperty('limit');
|
|
130
|
+
expect(baseQueryBuilderInstance).not.toHaveProperty('getOne');
|
|
131
|
+
expect(baseQueryBuilderInstance).not.toHaveProperty('getMany');
|
|
132
|
+
expect(baseQueryBuilderInstance).not.toHaveProperty('sortOrder');
|
|
133
|
+
});
|
|
134
|
+
it('should only have "index" as option once "entity" is initialized', () => {
|
|
135
|
+
const globalStorage = newGlobalStorage();
|
|
136
|
+
const baseQueryBuilderInstanceWithEntity = new query_api_2.CustomEntityBuilder(globalStorage).entity('books');
|
|
137
|
+
expect(baseQueryBuilderInstanceWithEntity).not.toHaveProperty('entity');
|
|
138
|
+
expect(baseQueryBuilderInstanceWithEntity).toHaveProperty('index');
|
|
139
|
+
expect(baseQueryBuilderInstanceWithEntity).not.toHaveProperty('where');
|
|
140
|
+
expect(baseQueryBuilderInstanceWithEntity).not.toHaveProperty('andFilter');
|
|
141
|
+
expect(baseQueryBuilderInstanceWithEntity).not.toHaveProperty('orFilter');
|
|
142
|
+
expect(baseQueryBuilderInstanceWithEntity).not.toHaveProperty('cursor');
|
|
143
|
+
expect(baseQueryBuilderInstanceWithEntity).not.toHaveProperty('limit');
|
|
144
|
+
expect(baseQueryBuilderInstanceWithEntity).not.toHaveProperty('getOne');
|
|
145
|
+
expect(baseQueryBuilderInstanceWithEntity).not.toHaveProperty('getMany');
|
|
146
|
+
expect(baseQueryBuilderInstanceWithEntity).not.toHaveProperty('sortOrder');
|
|
147
|
+
});
|
|
148
|
+
it('should have "where", "andFilter", "orFilter", "cursor", "limit", "sortOrder", "getOne", "getMany" as options once "index" is initialized', () => {
|
|
149
|
+
const globalStorage = newGlobalStorage();
|
|
150
|
+
const queryBuilderInstanceWithIndex = new query_api_2.CustomEntityBuilder(globalStorage).entity('books').index('by-key');
|
|
151
|
+
expect(queryBuilderInstanceWithIndex).not.toHaveProperty('entity');
|
|
152
|
+
expect(queryBuilderInstanceWithIndex).not.toHaveProperty('index');
|
|
153
|
+
expect(queryBuilderInstanceWithIndex).toHaveProperty('where');
|
|
154
|
+
expect(queryBuilderInstanceWithIndex).toHaveProperty('andFilter');
|
|
155
|
+
expect(queryBuilderInstanceWithIndex).toHaveProperty('orFilter');
|
|
156
|
+
expect(queryBuilderInstanceWithIndex).toHaveProperty('cursor');
|
|
157
|
+
expect(queryBuilderInstanceWithIndex).toHaveProperty('limit');
|
|
158
|
+
expect(queryBuilderInstanceWithIndex).toHaveProperty('sortOrder');
|
|
159
|
+
expect(queryBuilderInstanceWithIndex).toHaveProperty('getOne');
|
|
160
|
+
expect(queryBuilderInstanceWithIndex).toHaveProperty('getMany');
|
|
161
|
+
});
|
|
162
|
+
it('should not have "orFilter" once "andFilter" is used', () => {
|
|
163
|
+
const globalStorage = newGlobalStorage();
|
|
164
|
+
const queryBuilderInstanceWithAndFilter = new query_api_2.CustomEntityBuilder(globalStorage)
|
|
165
|
+
.entity('books')
|
|
166
|
+
.index('by-key')
|
|
167
|
+
.andFilter('first_name', conditions_2.FilterConditions.beginsWith('John'));
|
|
168
|
+
expect(queryBuilderInstanceWithAndFilter).not.toHaveProperty('entity');
|
|
169
|
+
expect(queryBuilderInstanceWithAndFilter).not.toHaveProperty('index');
|
|
170
|
+
expect(queryBuilderInstanceWithAndFilter).not.toHaveProperty('orFilter');
|
|
171
|
+
expect(queryBuilderInstanceWithAndFilter).toHaveProperty('where');
|
|
172
|
+
expect(queryBuilderInstanceWithAndFilter).toHaveProperty('andFilter');
|
|
173
|
+
expect(queryBuilderInstanceWithAndFilter).toHaveProperty('cursor');
|
|
174
|
+
expect(queryBuilderInstanceWithAndFilter).toHaveProperty('limit');
|
|
175
|
+
expect(queryBuilderInstanceWithAndFilter).toHaveProperty('sortOrder');
|
|
176
|
+
expect(queryBuilderInstanceWithAndFilter).toHaveProperty('getOne');
|
|
177
|
+
expect(queryBuilderInstanceWithAndFilter).toHaveProperty('getMany');
|
|
178
|
+
});
|
|
179
|
+
it('should not have "andFilter" once "orFilter" is used', () => {
|
|
180
|
+
const globalStorage = newGlobalStorage();
|
|
181
|
+
const queryBuilderInstanceWithOrFilter = new query_api_2.CustomEntityBuilder(globalStorage)
|
|
182
|
+
.entity('books')
|
|
183
|
+
.index('by-key')
|
|
184
|
+
.orFilter('first_name', conditions_2.FilterConditions.beginsWith('John'));
|
|
185
|
+
expect(queryBuilderInstanceWithOrFilter).not.toHaveProperty('entity');
|
|
186
|
+
expect(queryBuilderInstanceWithOrFilter).not.toHaveProperty('index');
|
|
187
|
+
expect(queryBuilderInstanceWithOrFilter).not.toHaveProperty('andFilter');
|
|
188
|
+
expect(queryBuilderInstanceWithOrFilter).toHaveProperty('where');
|
|
189
|
+
expect(queryBuilderInstanceWithOrFilter).toHaveProperty('orFilter');
|
|
190
|
+
expect(queryBuilderInstanceWithOrFilter).toHaveProperty('cursor');
|
|
191
|
+
expect(queryBuilderInstanceWithOrFilter).toHaveProperty('limit');
|
|
192
|
+
expect(queryBuilderInstanceWithOrFilter).toHaveProperty('sortOrder');
|
|
193
|
+
expect(queryBuilderInstanceWithOrFilter).toHaveProperty('getOne');
|
|
194
|
+
expect(queryBuilderInstanceWithOrFilter).toHaveProperty('getMany');
|
|
195
|
+
});
|
|
196
|
+
it('should be able to call "where", "cursor", "limit", "getOne", "getMany" after chaining multiple "orFilter"', async () => {
|
|
197
|
+
const globalStorage = newGlobalStorage();
|
|
198
|
+
const queryBuilderInstanceWithOrFilter = new query_api_2.CustomEntityBuilder(globalStorage)
|
|
199
|
+
.entity('books')
|
|
200
|
+
.index('by-rating-and-year', {
|
|
201
|
+
partition: [2019, 'John']
|
|
202
|
+
})
|
|
203
|
+
.orFilter('author', conditions_2.FilterConditions.contains('Doyle'))
|
|
204
|
+
.orFilter('genre', conditions_2.FilterConditions.equalsTo('horror'))
|
|
205
|
+
.where(conditions_2.WhereConditions.beginsWith('harry'))
|
|
206
|
+
.cursor('DUMMY_CURSOR_1234')
|
|
207
|
+
.limit(10)
|
|
208
|
+
.sortOrder(query_interfaces_1.SortOrder.DESC);
|
|
209
|
+
expect(queryBuilderInstanceWithOrFilter).not.toHaveProperty('entity');
|
|
210
|
+
expect(queryBuilderInstanceWithOrFilter).not.toHaveProperty('index');
|
|
211
|
+
expect(queryBuilderInstanceWithOrFilter).not.toHaveProperty('andFilter');
|
|
212
|
+
expect(queryBuilderInstanceWithOrFilter).toHaveProperty('where');
|
|
213
|
+
expect(queryBuilderInstanceWithOrFilter).toHaveProperty('orFilter');
|
|
214
|
+
expect(queryBuilderInstanceWithOrFilter).toHaveProperty('cursor');
|
|
215
|
+
expect(queryBuilderInstanceWithOrFilter).toHaveProperty('limit');
|
|
216
|
+
expect(queryBuilderInstanceWithOrFilter).toHaveProperty('sortOrder');
|
|
217
|
+
expect(queryBuilderInstanceWithOrFilter).toHaveProperty('getOne');
|
|
218
|
+
expect(queryBuilderInstanceWithOrFilter).toHaveProperty('getMany');
|
|
219
|
+
await queryBuilderInstanceWithOrFilter.getMany();
|
|
220
|
+
expect(globalStorage.listCustomEntities).toHaveBeenCalledWith(expect.objectContaining({
|
|
221
|
+
sort: query_interfaces_1.SortOrder.DESC,
|
|
222
|
+
entityName: 'books',
|
|
223
|
+
indexName: 'by-rating-and-year',
|
|
224
|
+
partition: [2019, 'John'],
|
|
225
|
+
filterOperator: 'or',
|
|
226
|
+
range: {
|
|
227
|
+
condition: 'BEGINS_WITH',
|
|
228
|
+
values: ['harry']
|
|
229
|
+
},
|
|
230
|
+
filters: [
|
|
231
|
+
{
|
|
232
|
+
property: 'author',
|
|
233
|
+
condition: 'CONTAINS',
|
|
234
|
+
values: ['Doyle']
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
property: 'genre',
|
|
238
|
+
condition: 'EQUAL_TO',
|
|
239
|
+
values: ['horror']
|
|
240
|
+
}
|
|
241
|
+
],
|
|
242
|
+
limit: 10,
|
|
243
|
+
cursor: 'DUMMY_CURSOR_1234'
|
|
244
|
+
}));
|
|
245
|
+
});
|
|
246
|
+
it('should be able to call "where", "cursor", "limit", "getOne", "getMany" after chaining multiple "andFilter"', async () => {
|
|
247
|
+
const globalStorage = newGlobalStorage();
|
|
248
|
+
const queryBuilderInstanceWithOrFilter = new query_api_2.CustomEntityBuilder(globalStorage)
|
|
249
|
+
.entity('books')
|
|
250
|
+
.index('by-rating-and-year', {
|
|
251
|
+
partition: [2019, 'John']
|
|
252
|
+
})
|
|
253
|
+
.andFilter('author', conditions_2.FilterConditions.contains('Doyle'))
|
|
254
|
+
.andFilter('genre', conditions_2.FilterConditions.equalsTo('horror'))
|
|
255
|
+
.where(conditions_2.WhereConditions.beginsWith('harry'))
|
|
256
|
+
.cursor('DUMMY_CURSOR_1234')
|
|
257
|
+
.limit(10)
|
|
258
|
+
.sortOrder(query_interfaces_1.SortOrder.DESC);
|
|
259
|
+
expect(queryBuilderInstanceWithOrFilter).not.toHaveProperty('entity');
|
|
260
|
+
expect(queryBuilderInstanceWithOrFilter).not.toHaveProperty('index');
|
|
261
|
+
expect(queryBuilderInstanceWithOrFilter).not.toHaveProperty('orFilter');
|
|
262
|
+
expect(queryBuilderInstanceWithOrFilter).toHaveProperty('where');
|
|
263
|
+
expect(queryBuilderInstanceWithOrFilter).toHaveProperty('andFilter');
|
|
264
|
+
expect(queryBuilderInstanceWithOrFilter).toHaveProperty('cursor');
|
|
265
|
+
expect(queryBuilderInstanceWithOrFilter).toHaveProperty('limit');
|
|
266
|
+
expect(queryBuilderInstanceWithOrFilter).toHaveProperty('sortOrder');
|
|
267
|
+
expect(queryBuilderInstanceWithOrFilter).toHaveProperty('getOne');
|
|
268
|
+
expect(queryBuilderInstanceWithOrFilter).toHaveProperty('getMany');
|
|
269
|
+
await queryBuilderInstanceWithOrFilter.getMany();
|
|
270
|
+
expect(globalStorage.listCustomEntities).toHaveBeenCalledWith(expect.objectContaining({
|
|
271
|
+
sort: query_interfaces_1.SortOrder.DESC,
|
|
272
|
+
entityName: 'books',
|
|
273
|
+
indexName: 'by-rating-and-year',
|
|
274
|
+
partition: [2019, 'John'],
|
|
275
|
+
filterOperator: 'and',
|
|
276
|
+
range: {
|
|
277
|
+
condition: 'BEGINS_WITH',
|
|
278
|
+
values: ['harry']
|
|
279
|
+
},
|
|
280
|
+
filters: [
|
|
281
|
+
{
|
|
282
|
+
property: 'author',
|
|
283
|
+
condition: 'CONTAINS',
|
|
284
|
+
values: ['Doyle']
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
property: 'genre',
|
|
288
|
+
condition: 'EQUAL_TO',
|
|
289
|
+
values: ['horror']
|
|
290
|
+
}
|
|
291
|
+
],
|
|
292
|
+
limit: 10,
|
|
293
|
+
cursor: 'DUMMY_CURSOR_1234'
|
|
294
|
+
}));
|
|
295
|
+
});
|
|
296
|
+
it('should pass when BETWEEN filter and range are passed', async () => {
|
|
297
|
+
const globalStorage = newGlobalStorage();
|
|
298
|
+
await new query_api_2.CustomEntityBuilder(globalStorage)
|
|
299
|
+
.entity('books')
|
|
300
|
+
.index('by-author')
|
|
301
|
+
.where(conditions_2.WhereConditions.between([1, 2]))
|
|
302
|
+
.andFilter('author', conditions_2.FilterConditions.between([3, 4]))
|
|
303
|
+
.getMany();
|
|
304
|
+
expect(globalStorage.listCustomEntities).toHaveBeenCalledWith(expect.objectContaining({
|
|
305
|
+
entityName: 'books',
|
|
306
|
+
indexName: 'by-author',
|
|
307
|
+
filterOperator: 'and',
|
|
308
|
+
range: {
|
|
309
|
+
condition: 'BETWEEN',
|
|
310
|
+
values: [1, 2]
|
|
311
|
+
},
|
|
312
|
+
filters: [
|
|
313
|
+
{
|
|
314
|
+
property: 'author',
|
|
315
|
+
condition: 'BETWEEN',
|
|
316
|
+
values: [3, 4]
|
|
317
|
+
}
|
|
318
|
+
]
|
|
319
|
+
}));
|
|
320
|
+
});
|
|
321
|
+
it('should pass when BEGINS_WITH filter and range are passed', async () => {
|
|
322
|
+
const globalStorage = newGlobalStorage();
|
|
323
|
+
await new query_api_2.CustomEntityBuilder(globalStorage)
|
|
324
|
+
.entity('books')
|
|
325
|
+
.index('by-author')
|
|
326
|
+
.where(conditions_2.WhereConditions.beginsWith(1))
|
|
327
|
+
.andFilter('author', conditions_2.FilterConditions.beginsWith(2))
|
|
328
|
+
.getMany();
|
|
329
|
+
expect(globalStorage.listCustomEntities).toHaveBeenCalledWith(expect.objectContaining({
|
|
330
|
+
entityName: 'books',
|
|
331
|
+
indexName: 'by-author',
|
|
332
|
+
filterOperator: 'and',
|
|
333
|
+
range: {
|
|
334
|
+
condition: 'BEGINS_WITH',
|
|
335
|
+
values: [1]
|
|
336
|
+
},
|
|
337
|
+
filters: [
|
|
338
|
+
{
|
|
339
|
+
property: 'author',
|
|
340
|
+
condition: 'BEGINS_WITH',
|
|
341
|
+
values: [2]
|
|
342
|
+
}
|
|
343
|
+
]
|
|
344
|
+
}));
|
|
345
|
+
});
|
|
346
|
+
it('should pass when EXISTS filter is passed', async () => {
|
|
347
|
+
const globalStorage = newGlobalStorage();
|
|
348
|
+
await new query_api_2.CustomEntityBuilder(globalStorage)
|
|
349
|
+
.entity('books')
|
|
350
|
+
.index('by-rating')
|
|
351
|
+
.andFilter('rating', conditions_2.FilterConditions.exists())
|
|
352
|
+
.getMany();
|
|
353
|
+
expect(globalStorage.listCustomEntities).toHaveBeenCalledWith(expect.objectContaining({
|
|
354
|
+
entityName: 'books',
|
|
355
|
+
indexName: 'by-rating',
|
|
356
|
+
filterOperator: 'and',
|
|
357
|
+
filters: [
|
|
358
|
+
{
|
|
359
|
+
property: 'rating',
|
|
360
|
+
condition: 'EXISTS',
|
|
361
|
+
values: [true]
|
|
362
|
+
}
|
|
363
|
+
]
|
|
364
|
+
}));
|
|
365
|
+
});
|
|
366
|
+
it('should pass when DOES_NOT_EXIST filter is passed', async () => {
|
|
367
|
+
const globalStorage = newGlobalStorage();
|
|
368
|
+
await new query_api_2.CustomEntityBuilder(globalStorage)
|
|
369
|
+
.entity('books')
|
|
370
|
+
.index('by-rating')
|
|
371
|
+
.andFilter('rating', conditions_2.FilterConditions.doesNotExist())
|
|
372
|
+
.getMany();
|
|
373
|
+
expect(globalStorage.listCustomEntities).toHaveBeenCalledWith(expect.objectContaining({
|
|
374
|
+
entityName: 'books',
|
|
375
|
+
indexName: 'by-rating',
|
|
376
|
+
filterOperator: 'and',
|
|
377
|
+
filters: [
|
|
378
|
+
{
|
|
379
|
+
property: 'rating',
|
|
380
|
+
condition: 'NOT_EXISTS',
|
|
381
|
+
values: [true]
|
|
382
|
+
}
|
|
383
|
+
]
|
|
384
|
+
}));
|
|
385
|
+
});
|
|
386
|
+
it('should pass when GREATER_THAN filter is passed', async () => {
|
|
387
|
+
const globalStorage = newGlobalStorage();
|
|
388
|
+
await new query_api_2.CustomEntityBuilder(globalStorage)
|
|
389
|
+
.entity('books')
|
|
390
|
+
.index('by-author')
|
|
391
|
+
.where(conditions_2.WhereConditions.isGreaterThan(1))
|
|
392
|
+
.andFilter('rating', conditions_2.FilterConditions.isGreaterThan(1))
|
|
393
|
+
.getMany();
|
|
394
|
+
expect(globalStorage.listCustomEntities).toHaveBeenCalledWith(expect.objectContaining({
|
|
395
|
+
entityName: 'books',
|
|
396
|
+
indexName: 'by-author',
|
|
397
|
+
range: {
|
|
398
|
+
condition: 'GREATER_THAN',
|
|
399
|
+
values: [1]
|
|
400
|
+
},
|
|
401
|
+
filterOperator: 'and',
|
|
402
|
+
filters: [
|
|
403
|
+
{
|
|
404
|
+
property: 'rating',
|
|
405
|
+
condition: 'GREATER_THAN',
|
|
406
|
+
values: [1]
|
|
407
|
+
}
|
|
408
|
+
]
|
|
409
|
+
}));
|
|
410
|
+
});
|
|
411
|
+
it('should pass when GREATER_THAN_EQUAL_TO filter is passed', async () => {
|
|
412
|
+
const globalStorage = newGlobalStorage();
|
|
413
|
+
await new query_api_2.CustomEntityBuilder(globalStorage)
|
|
414
|
+
.entity('books')
|
|
415
|
+
.index('by-author')
|
|
416
|
+
.where(conditions_2.WhereConditions.isGreaterThanEqualTo(1))
|
|
417
|
+
.andFilter('rating', conditions_2.FilterConditions.isGreaterThanEqualTo(1))
|
|
418
|
+
.getMany();
|
|
419
|
+
expect(globalStorage.listCustomEntities).toHaveBeenCalledWith(expect.objectContaining({
|
|
420
|
+
entityName: 'books',
|
|
421
|
+
indexName: 'by-author',
|
|
422
|
+
range: {
|
|
423
|
+
condition: 'GREATER_THAN_EQUAL_TO',
|
|
424
|
+
values: [1]
|
|
425
|
+
},
|
|
426
|
+
filterOperator: 'and',
|
|
427
|
+
filters: [
|
|
428
|
+
{
|
|
429
|
+
property: 'rating',
|
|
430
|
+
condition: 'GREATER_THAN_EQUAL_TO',
|
|
431
|
+
values: [1]
|
|
432
|
+
}
|
|
433
|
+
]
|
|
434
|
+
}));
|
|
435
|
+
});
|
|
436
|
+
it('should pass when LESS_THAN filter is passed', async () => {
|
|
437
|
+
const globalStorage = newGlobalStorage();
|
|
438
|
+
await new query_api_2.CustomEntityBuilder(globalStorage)
|
|
439
|
+
.entity('books')
|
|
440
|
+
.index('by-author')
|
|
441
|
+
.where(conditions_2.WhereConditions.isLessThan(1))
|
|
442
|
+
.andFilter('rating', conditions_2.FilterConditions.isLessThan(1))
|
|
443
|
+
.getMany();
|
|
444
|
+
expect(globalStorage.listCustomEntities).toHaveBeenCalledWith(expect.objectContaining({
|
|
445
|
+
entityName: 'books',
|
|
446
|
+
indexName: 'by-author',
|
|
447
|
+
range: {
|
|
448
|
+
condition: 'LESS_THAN',
|
|
449
|
+
values: [1]
|
|
450
|
+
},
|
|
451
|
+
filterOperator: 'and',
|
|
452
|
+
filters: [
|
|
453
|
+
{
|
|
454
|
+
property: 'rating',
|
|
455
|
+
condition: 'LESS_THAN',
|
|
456
|
+
values: [1]
|
|
457
|
+
}
|
|
458
|
+
]
|
|
459
|
+
}));
|
|
460
|
+
});
|
|
461
|
+
it('should pass when LESS_THAN_EQUAL_TO filter is passed', async () => {
|
|
462
|
+
const globalStorage = newGlobalStorage();
|
|
463
|
+
await new query_api_2.CustomEntityBuilder(globalStorage)
|
|
464
|
+
.entity('books')
|
|
465
|
+
.index('by-author')
|
|
466
|
+
.where(conditions_2.WhereConditions.isLessThanEqualTo(1))
|
|
467
|
+
.andFilter('rating', conditions_2.FilterConditions.isLessThanEqualTo(1))
|
|
468
|
+
.getMany();
|
|
469
|
+
expect(globalStorage.listCustomEntities).toHaveBeenCalledWith(expect.objectContaining({
|
|
470
|
+
entityName: 'books',
|
|
471
|
+
indexName: 'by-author',
|
|
472
|
+
range: {
|
|
473
|
+
condition: 'LESS_THAN_EQUAL_TO',
|
|
474
|
+
values: [1]
|
|
475
|
+
},
|
|
476
|
+
filterOperator: 'and',
|
|
477
|
+
filters: [
|
|
478
|
+
{
|
|
479
|
+
property: 'rating',
|
|
480
|
+
condition: 'LESS_THAN_EQUAL_TO',
|
|
481
|
+
values: [1]
|
|
482
|
+
}
|
|
483
|
+
]
|
|
484
|
+
}));
|
|
485
|
+
});
|
|
486
|
+
it('should pass when CONTAINS filter is passed', async () => {
|
|
487
|
+
const globalStorage = newGlobalStorage();
|
|
488
|
+
await new query_api_2.CustomEntityBuilder(globalStorage)
|
|
489
|
+
.entity('books')
|
|
490
|
+
.index('by-author')
|
|
491
|
+
.andFilter('rating', conditions_2.FilterConditions.contains('Conan'))
|
|
492
|
+
.getMany();
|
|
493
|
+
expect(globalStorage.listCustomEntities).toHaveBeenCalledWith(expect.objectContaining({
|
|
494
|
+
entityName: 'books',
|
|
495
|
+
indexName: 'by-author',
|
|
496
|
+
filterOperator: 'and',
|
|
497
|
+
filters: [
|
|
498
|
+
{
|
|
499
|
+
property: 'rating',
|
|
500
|
+
condition: 'CONTAINS',
|
|
501
|
+
values: ['Conan']
|
|
502
|
+
}
|
|
503
|
+
]
|
|
504
|
+
}));
|
|
505
|
+
});
|
|
506
|
+
it('should pass when NOT_CONTAINS filter is passed', async () => {
|
|
507
|
+
const globalStorage = newGlobalStorage();
|
|
508
|
+
await new query_api_2.CustomEntityBuilder(globalStorage)
|
|
509
|
+
.entity('books')
|
|
510
|
+
.index('by-author')
|
|
511
|
+
.andFilter('rating', conditions_2.FilterConditions.doesNotContain('Conan'))
|
|
512
|
+
.getMany();
|
|
513
|
+
expect(globalStorage.listCustomEntities).toHaveBeenCalledWith(expect.objectContaining({
|
|
514
|
+
entityName: 'books',
|
|
515
|
+
indexName: 'by-author',
|
|
516
|
+
filterOperator: 'and',
|
|
517
|
+
filters: [
|
|
518
|
+
{
|
|
519
|
+
property: 'rating',
|
|
520
|
+
condition: 'NOT_CONTAINS',
|
|
521
|
+
values: ['Conan']
|
|
522
|
+
}
|
|
523
|
+
]
|
|
524
|
+
}));
|
|
525
|
+
});
|
|
526
|
+
it('should pass when EQUAL_TO filter is passed', async () => {
|
|
527
|
+
const globalStorage = newGlobalStorage();
|
|
528
|
+
await new query_api_2.CustomEntityBuilder(globalStorage)
|
|
529
|
+
.entity('books')
|
|
530
|
+
.index('by-author')
|
|
531
|
+
.andFilter('rating', conditions_2.FilterConditions.equalsTo('Conan'))
|
|
532
|
+
.getMany();
|
|
533
|
+
expect(globalStorage.listCustomEntities).toHaveBeenCalledWith(expect.objectContaining({
|
|
534
|
+
entityName: 'books',
|
|
535
|
+
indexName: 'by-author',
|
|
536
|
+
filterOperator: 'and',
|
|
537
|
+
filters: [
|
|
538
|
+
{
|
|
539
|
+
property: 'rating',
|
|
540
|
+
condition: 'EQUAL_TO',
|
|
541
|
+
values: ['Conan']
|
|
542
|
+
}
|
|
543
|
+
]
|
|
544
|
+
}));
|
|
545
|
+
});
|
|
546
|
+
it('should pass when NOT_EQUAL_TO filter is passed', async () => {
|
|
547
|
+
const globalStorage = newGlobalStorage();
|
|
548
|
+
await new query_api_2.CustomEntityBuilder(globalStorage)
|
|
549
|
+
.entity('books')
|
|
550
|
+
.index('by-author')
|
|
551
|
+
.andFilter('rating', conditions_2.FilterConditions.notEqualsTo('Conan'))
|
|
552
|
+
.getMany();
|
|
553
|
+
expect(globalStorage.listCustomEntities).toHaveBeenCalledWith(expect.objectContaining({
|
|
554
|
+
entityName: 'books',
|
|
555
|
+
indexName: 'by-author',
|
|
556
|
+
filterOperator: 'and',
|
|
557
|
+
filters: [
|
|
558
|
+
{
|
|
559
|
+
property: 'rating',
|
|
560
|
+
condition: 'NOT_EQUAL_TO',
|
|
561
|
+
values: ['Conan']
|
|
562
|
+
}
|
|
563
|
+
]
|
|
564
|
+
}));
|
|
565
|
+
});
|
|
566
|
+
it('should pass when filter operator is passed', async () => {
|
|
567
|
+
const globalStorage = newGlobalStorage();
|
|
568
|
+
await new query_api_2.CustomEntityBuilder(globalStorage)
|
|
569
|
+
.entity('books')
|
|
570
|
+
.index('by-author')
|
|
571
|
+
.where(conditions_2.WhereConditions.between([1, 2]))
|
|
572
|
+
.orFilter('author', conditions_2.FilterConditions.between([3, 4]))
|
|
573
|
+
.getMany();
|
|
574
|
+
expect(globalStorage.listCustomEntities).toHaveBeenCalledWith(expect.objectContaining({
|
|
575
|
+
entityName: 'books',
|
|
576
|
+
indexName: 'by-author',
|
|
577
|
+
filterOperator: 'or',
|
|
578
|
+
range: {
|
|
579
|
+
condition: 'BETWEEN',
|
|
580
|
+
values: [1, 2]
|
|
581
|
+
},
|
|
582
|
+
filters: [
|
|
583
|
+
{
|
|
584
|
+
property: 'author',
|
|
585
|
+
condition: 'BETWEEN',
|
|
586
|
+
values: [3, 4]
|
|
587
|
+
}
|
|
588
|
+
]
|
|
589
|
+
}));
|
|
590
|
+
});
|
|
591
|
+
it('should pass when ASC sort is passed', async () => {
|
|
592
|
+
const globalStorage = newGlobalStorage();
|
|
593
|
+
await new query_api_2.CustomEntityBuilder(globalStorage)
|
|
594
|
+
.entity('books')
|
|
595
|
+
.index('by-rating-and-year', {
|
|
596
|
+
partition: [2019]
|
|
597
|
+
})
|
|
598
|
+
.where(conditions_2.WhereConditions.between([1, 2]))
|
|
599
|
+
.sortOrder(query_interfaces_1.SortOrder.ASC)
|
|
600
|
+
.limit(10)
|
|
601
|
+
.cursor('DUMMY_CURSOR_1234')
|
|
602
|
+
.getMany();
|
|
603
|
+
expect(globalStorage.listCustomEntities).toHaveBeenCalledWith(expect.objectContaining({
|
|
604
|
+
sort: query_interfaces_1.SortOrder.ASC,
|
|
605
|
+
entityName: 'books',
|
|
606
|
+
indexName: 'by-rating-and-year',
|
|
607
|
+
partition: [2019],
|
|
608
|
+
range: {
|
|
609
|
+
condition: 'BETWEEN',
|
|
610
|
+
values: [1, 2]
|
|
611
|
+
},
|
|
612
|
+
limit: 10,
|
|
613
|
+
cursor: 'DUMMY_CURSOR_1234'
|
|
614
|
+
}));
|
|
615
|
+
});
|
|
616
|
+
it('should pass when All entity queries operator are passed', async () => {
|
|
617
|
+
const globalStorage = newGlobalStorage();
|
|
618
|
+
await new query_api_2.CustomEntityBuilder(globalStorage)
|
|
619
|
+
.entity('books')
|
|
620
|
+
.index('by-rating-and-year', {
|
|
621
|
+
partition: [2019, 'John']
|
|
622
|
+
})
|
|
623
|
+
.where(conditions_2.WhereConditions.between([1, 2]))
|
|
624
|
+
.sortOrder(query_interfaces_1.SortOrder.DESC)
|
|
625
|
+
.orFilter('author', conditions_2.FilterConditions.contains('Doyle'))
|
|
626
|
+
.limit(10)
|
|
627
|
+
.cursor('DUMMY_CURSOR_1234')
|
|
628
|
+
.getMany();
|
|
629
|
+
expect(globalStorage.listCustomEntities).toHaveBeenCalledWith(expect.objectContaining({
|
|
630
|
+
sort: query_interfaces_1.SortOrder.DESC,
|
|
631
|
+
entityName: 'books',
|
|
632
|
+
indexName: 'by-rating-and-year',
|
|
633
|
+
partition: [2019, 'John'],
|
|
634
|
+
filterOperator: 'or',
|
|
635
|
+
range: {
|
|
636
|
+
condition: 'BETWEEN',
|
|
637
|
+
values: [1, 2]
|
|
638
|
+
},
|
|
639
|
+
filters: [
|
|
640
|
+
{
|
|
641
|
+
property: 'author',
|
|
642
|
+
condition: 'CONTAINS',
|
|
643
|
+
values: ['Doyle']
|
|
644
|
+
}
|
|
645
|
+
],
|
|
646
|
+
limit: 10,
|
|
647
|
+
cursor: 'DUMMY_CURSOR_1234'
|
|
648
|
+
}));
|
|
649
|
+
});
|
|
650
|
+
});
|
package/out/eap/conditions.d.ts
CHANGED
|
@@ -1,4 +1,40 @@
|
|
|
1
|
-
import { Predicate } from '../storage-adapter';
|
|
1
|
+
import { FilterPredicate, WherePredicate, Predicate } from '../storage-adapter';
|
|
2
2
|
export declare function isNotEqualTo(value: string[]): Predicate;
|
|
3
3
|
export declare function isIn(values: string[]): Predicate;
|
|
4
|
+
declare function beginsWith(value: string | number): WherePredicate;
|
|
5
|
+
declare function between(values: [string, string] | [number, number]): WherePredicate;
|
|
6
|
+
declare function exists(): FilterPredicate;
|
|
7
|
+
declare function doesNotExist(): FilterPredicate;
|
|
8
|
+
declare function isGreaterThan(value: string | number): WherePredicate;
|
|
9
|
+
declare function isGreaterThanEqualTo(value: string | number): WherePredicate;
|
|
10
|
+
declare function isLessThan(value: string | number): WherePredicate;
|
|
11
|
+
declare function isLessThanEqualTo(value: string | number): WherePredicate;
|
|
12
|
+
declare function contains(value: string): FilterPredicate;
|
|
13
|
+
declare function doesNotContain(value: string): FilterPredicate;
|
|
14
|
+
declare function equalsTo(value: number | string | boolean): WherePredicate;
|
|
15
|
+
declare function notEqualsTo(value: number | string | boolean): FilterPredicate;
|
|
16
|
+
export declare const WhereConditions: {
|
|
17
|
+
beginsWith: typeof beginsWith;
|
|
18
|
+
between: typeof between;
|
|
19
|
+
equalsTo: typeof equalsTo;
|
|
20
|
+
isGreaterThan: typeof isGreaterThan;
|
|
21
|
+
isGreaterThanEqualTo: typeof isGreaterThanEqualTo;
|
|
22
|
+
isLessThan: typeof isLessThan;
|
|
23
|
+
isLessThanEqualTo: typeof isLessThanEqualTo;
|
|
24
|
+
};
|
|
25
|
+
export declare const FilterConditions: {
|
|
26
|
+
beginsWith: typeof beginsWith;
|
|
27
|
+
between: typeof between;
|
|
28
|
+
contains: typeof contains;
|
|
29
|
+
doesNotContain: typeof doesNotContain;
|
|
30
|
+
equalsTo: typeof equalsTo;
|
|
31
|
+
notEqualsTo: typeof notEqualsTo;
|
|
32
|
+
exists: typeof exists;
|
|
33
|
+
doesNotExist: typeof doesNotExist;
|
|
34
|
+
isGreaterThan: typeof isGreaterThan;
|
|
35
|
+
isGreaterThanEqualTo: typeof isGreaterThanEqualTo;
|
|
36
|
+
isLessThan: typeof isLessThan;
|
|
37
|
+
isLessThanEqualTo: typeof isLessThanEqualTo;
|
|
38
|
+
};
|
|
39
|
+
export {};
|
|
4
40
|
//# sourceMappingURL=conditions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditions.d.ts","sourceRoot":"","sources":["../../src/eap/conditions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"conditions.d.ts","sourceRoot":"","sources":["../../src/eap/conditions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAChF,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,SAAS,CAKvD;AAED,wBAAgB,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAKhD;AAKD,iBAAS,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,cAAc,CAK1D;AAED,iBAAS,OAAO,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,cAAc,CAK5E;AAED,iBAAS,MAAM,IAAI,eAAe,CAKjC;AAED,iBAAS,YAAY,IAAI,eAAe,CAKvC;AAED,iBAAS,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,cAAc,CAK7D;AAED,iBAAS,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,cAAc,CAKpE;AAED,iBAAS,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,cAAc,CAK1D;AAED,iBAAS,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,cAAc,CAKjE;AAED,iBAAS,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,eAAe,CAKhD;AAED,iBAAS,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,eAAe,CAKtD;AAED,iBAAS,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,cAAc,CAKlE;AAED,iBAAS,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,eAAe,CAKtE;AAED,eAAO,MAAM,eAAe;;;;;;;;CAQ3B,CAAC;AAEF,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;CAa5B,CAAC"}
|