@travetto/model-query 3.1.6 → 3.1.8
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/README.md +2 -1
- package/package.json +1 -1
- package/src/internal/util/types.ts +3 -3
- package/src/model/where-clause.ts +1 -0
- package/support/test/query.ts +141 -1
- package/support/test/types.ts +19 -0
package/README.md
CHANGED
|
@@ -158,6 +158,7 @@ One of the complexities of abstracting multiple storage mechanisms, is providing
|
|
|
158
158
|
### Array Fields
|
|
159
159
|
|
|
160
160
|
* `field: { $all: T[]] }` checks to see if the records value contains everything within `$all`
|
|
161
|
+
* `field: { $empty: boolean }` to determine if an array is missing or is of zero length.
|
|
161
162
|
|
|
162
163
|
### String Fields
|
|
163
164
|
|
|
@@ -166,7 +167,7 @@ One of the complexities of abstracting multiple storage mechanisms, is providing
|
|
|
166
167
|
### Geo Point Fields
|
|
167
168
|
|
|
168
169
|
* `field: { $geoWithin: Point[] }` determines if the value is within the bounding region of the points
|
|
169
|
-
* `field: {$near: Point, $maxDistance: number, $unit: 'km' | 'm' | 'mi' | 'ft' }` searches at a point, and looks out radially
|
|
170
|
+
* `field: { $near: Point, $maxDistance: number, $unit: 'km' | 'm' | 'mi' | 'ft' }` searches at a point, and looks out radially
|
|
170
171
|
|
|
171
172
|
### Groupings
|
|
172
173
|
|
package/package.json
CHANGED
|
@@ -3,10 +3,10 @@ import { Class } from '@travetto/base';
|
|
|
3
3
|
|
|
4
4
|
import { PointImpl } from '../model/point';
|
|
5
5
|
|
|
6
|
-
const st = (t: string | string[],
|
|
7
|
-
new Set((Array.isArray(t) ? t : [t]).map(v =>
|
|
6
|
+
const st = (t: string | string[], isArr: boolean = false): Set<string> =>
|
|
7
|
+
new Set((Array.isArray(t) ? t : [t]).map(v => isArr ? `${v}[]` : v));
|
|
8
8
|
|
|
9
|
-
const basic = (types: Set<string>): Record<string, Set<string>> => ({ $ne: types, $eq: types, $exists: st('boolean') });
|
|
9
|
+
const basic = (types: Set<string>): Record<string, Set<string>> => ({ $ne: types, $eq: types, $exists: st('boolean'), $empty: st('boolean') });
|
|
10
10
|
const scalar = (types: Set<string>): Record<string, Set<string>> => ({ $in: types, $nin: types });
|
|
11
11
|
const str = (): Record<string, Set<string>> => ({ $regex: st(['RegExp', 'string']) });
|
|
12
12
|
const comp = (types: Set<string>): Record<string, Set<string>> => ({ $lt: types, $lte: types, $gt: types, $gte: types });
|
package/support/test/query.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { BaseModelSuite } from '@travetto/model/support/test/base';
|
|
|
5
5
|
import { ModelCrudSupport } from '@travetto/model/src/service/crud';
|
|
6
6
|
import { TimeUtil } from '@travetto/base';
|
|
7
7
|
|
|
8
|
-
import { Aged, Location, Names, Note, Person, SimpleList } from './types';
|
|
8
|
+
import { Aged, Location, Names, Note, Person, SimpleList, WithNestedLists, WithNestedNestedLists } from './types';
|
|
9
9
|
|
|
10
10
|
import { ModelQuerySupport } from '../../src/service/query';
|
|
11
11
|
|
|
@@ -296,8 +296,148 @@ export abstract class ModelQuerySuite extends BaseModelSuite<ModelQuerySupport &
|
|
|
296
296
|
}
|
|
297
297
|
});
|
|
298
298
|
assert(simple4 === 3);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
@Test()
|
|
302
|
+
async verifyArrayEmptyVsNot() {
|
|
303
|
+
const service = await this.service;
|
|
304
|
+
await service.create(WithNestedLists, {
|
|
305
|
+
tags: ['a', 'b']
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
await service.create(WithNestedLists, {
|
|
309
|
+
names: ['c', 'd'],
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
await service.create(WithNestedLists, {
|
|
313
|
+
names: ['c', 'd'],
|
|
314
|
+
tags: ['e', 'f']
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
await service.create(WithNestedLists, {
|
|
318
|
+
names: ['g', 'h'],
|
|
319
|
+
tags: []
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
await service.create(WithNestedLists, {
|
|
323
|
+
names: [],
|
|
324
|
+
tags: []
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
let total = await service.queryCount(WithNestedLists, {
|
|
328
|
+
where: {
|
|
329
|
+
names: { $empty: false }
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
assert(total === 3);
|
|
333
|
+
total = await service.queryCount(WithNestedLists, {
|
|
334
|
+
where: {
|
|
335
|
+
names: { $empty: true }
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
assert(total === 2);
|
|
339
|
+
|
|
340
|
+
total = await service.queryCount(WithNestedLists, {
|
|
341
|
+
where: {
|
|
342
|
+
tags: { $empty: true }
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
assert(total === 3);
|
|
346
|
+
|
|
347
|
+
total = await service.queryCount(WithNestedLists, {
|
|
348
|
+
where: {
|
|
349
|
+
tags: { $empty: false }
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
assert(total === 2);
|
|
353
|
+
|
|
354
|
+
total = await service.queryCount(WithNestedLists, {
|
|
355
|
+
where: {
|
|
356
|
+
tags: { $empty: true },
|
|
357
|
+
names: { $empty: true }
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
assert(total === 1);
|
|
361
|
+
|
|
362
|
+
total = await service.queryCount(WithNestedLists, {
|
|
363
|
+
where: {
|
|
364
|
+
tags: { $empty: false },
|
|
365
|
+
names: { $empty: false }
|
|
366
|
+
}
|
|
367
|
+
});
|
|
299
368
|
|
|
369
|
+
assert(total === 1);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
@Test()
|
|
373
|
+
async verifyNestedArrayEmptyVsNot() {
|
|
374
|
+
const service = await this.service;
|
|
375
|
+
await service.create(WithNestedNestedLists, {
|
|
376
|
+
tags: ['a', 'b']
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
await service.create(WithNestedNestedLists, {
|
|
380
|
+
sub: { names: ['c', 'd'] },
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
await service.create(WithNestedNestedLists, {
|
|
384
|
+
sub: { names: ['c', 'd'] },
|
|
385
|
+
tags: ['e', 'f']
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
await service.create(WithNestedNestedLists, {
|
|
389
|
+
sub: { names: ['g', 'h'] },
|
|
390
|
+
tags: []
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
await service.create(WithNestedNestedLists, {
|
|
394
|
+
sub: {},
|
|
395
|
+
tags: []
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
let total = await service.queryCount(WithNestedNestedLists, {
|
|
399
|
+
where: {
|
|
400
|
+
sub: { names: { $empty: false } }
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
assert(total === 3);
|
|
404
|
+
total = await service.queryCount(WithNestedNestedLists, {
|
|
405
|
+
where: {
|
|
406
|
+
sub: { names: { $empty: true } }
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
assert(total === 2);
|
|
410
|
+
|
|
411
|
+
total = await service.queryCount(WithNestedNestedLists, {
|
|
412
|
+
where: {
|
|
413
|
+
tags: { $empty: true }
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
assert(total === 3);
|
|
417
|
+
|
|
418
|
+
total = await service.queryCount(WithNestedNestedLists, {
|
|
419
|
+
where: {
|
|
420
|
+
tags: { $empty: false }
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
assert(total === 2);
|
|
424
|
+
|
|
425
|
+
total = await service.queryCount(WithNestedNestedLists, {
|
|
426
|
+
where: {
|
|
427
|
+
tags: { $empty: true },
|
|
428
|
+
sub: { names: { $empty: true } }
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
assert(total === 1);
|
|
432
|
+
|
|
433
|
+
total = await service.queryCount(WithNestedNestedLists, {
|
|
434
|
+
where: {
|
|
435
|
+
tags: { $empty: false },
|
|
436
|
+
sub: { names: { $empty: false } }
|
|
437
|
+
}
|
|
438
|
+
});
|
|
300
439
|
|
|
440
|
+
assert(total === 1);
|
|
301
441
|
}
|
|
302
442
|
}
|
|
303
443
|
|
package/support/test/types.ts
CHANGED
|
@@ -74,4 +74,23 @@ export class Region {
|
|
|
74
74
|
export class Aged {
|
|
75
75
|
id: string;
|
|
76
76
|
createdAt: Date;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@Model()
|
|
80
|
+
export class WithNestedLists {
|
|
81
|
+
id: string;
|
|
82
|
+
tags?: string[] = [];
|
|
83
|
+
names?: string[] = [];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@Schema()
|
|
87
|
+
class NamedSubNested {
|
|
88
|
+
names?: string[] = [];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@Model()
|
|
92
|
+
export class WithNestedNestedLists {
|
|
93
|
+
id: string;
|
|
94
|
+
tags?: string[] = [];
|
|
95
|
+
sub?: NamedSubNested;
|
|
77
96
|
}
|