@travetto/model-query 3.1.5 → 3.1.7
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 +1 -0
- package/package.json +2 -2
- package/src/internal/util/types.ts +3 -3
- package/src/model/where-clause.ts +1 -0
- package/support/test/query.ts +70 -1
- package/support/test/types.ts +7 -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. Due to the nature of this operation, this is only supported on lists at the top level of the document.
|
|
161
162
|
|
|
162
163
|
### String Fields
|
|
163
164
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-query",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.7",
|
|
4
4
|
"description": "Datastore abstraction for advanced query support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"datastore",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@travetto/di": "^3.1.1",
|
|
31
|
-
"@travetto/model": "^3.1.
|
|
31
|
+
"@travetto/model": "^3.1.8",
|
|
32
32
|
"@travetto/schema": "^3.1.2"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
@@ -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 } from './types';
|
|
9
9
|
|
|
10
10
|
import { ModelQuerySupport } from '../../src/service/query';
|
|
11
11
|
|
|
@@ -296,8 +296,77 @@ 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
|
+
});
|
|
299
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
|
+
});
|
|
300
368
|
|
|
369
|
+
assert(total === 1);
|
|
301
370
|
}
|
|
302
371
|
}
|
|
303
372
|
|