@travetto/model-query 8.0.0-alpha.25 → 8.0.0-alpha.26

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-query",
3
- "version": "8.0.0-alpha.25",
3
+ "version": "8.0.0-alpha.26",
4
4
  "type": "module",
5
5
  "description": "Datastore abstraction for advanced query support.",
6
6
  "keywords": [
@@ -115,3 +115,19 @@ export class PersonFamily implements ModelType {
115
115
  id: string;
116
116
  family?: Family;
117
117
  }
118
+
119
+ @Schema()
120
+ export class RecipeIngredient {
121
+ name: string;
122
+ }
123
+
124
+ @Schema()
125
+ export class RecipeSection {
126
+ ingredients: RecipeIngredient[] = [];
127
+ }
128
+
129
+ @Model()
130
+ export class Recipe implements ModelType {
131
+ id: string;
132
+ sections: RecipeSection[] = [];
133
+ }
@@ -7,7 +7,7 @@ import { Suite, Test } from '@travetto/test';
7
7
  import { BaseModelSuite } from '@travetto/model/support/test/base.ts';
8
8
 
9
9
  import type { ModelQuerySupport } from '../../src/types/query.ts';
10
- import { Aged, Location, Names, Note, Person, PersonFamily, SimpleList, WithNestedLists, WithNestedNestedLists } from './model.ts';
10
+ import { Aged, Location, Names, Note, Person, PersonFamily, Recipe, SimpleList, WithNestedLists, WithNestedNestedLists } from './model.ts';
11
11
 
12
12
  @Suite()
13
13
  export abstract class ModelQuerySuite extends BaseModelSuite<ModelQuerySupport & ModelCrudSupport> {
@@ -538,6 +538,77 @@ export abstract class ModelQuerySuite extends BaseModelSuite<ModelQuerySupport &
538
538
  assert(total === 1);
539
539
  }
540
540
 
541
+ @Test('Verify queries on nested arrays of schemas')
542
+ async verifyNestedArraySchemaQuery() {
543
+ const service = await this.service;
544
+
545
+ await service.create(
546
+ Recipe,
547
+ Recipe.from({
548
+ sections: [
549
+ {
550
+ ingredients: [{ name: 'garlic' }, { name: 'onion' }]
551
+ }
552
+ ]
553
+ })
554
+ );
555
+
556
+ await service.create(
557
+ Recipe,
558
+ Recipe.from({
559
+ sections: [
560
+ {
561
+ ingredients: [{ name: 'paprika' }, { name: 'salt' }]
562
+ }
563
+ ]
564
+ })
565
+ );
566
+
567
+ await service.create(
568
+ Recipe,
569
+ Recipe.from({
570
+ sections: [
571
+ {
572
+ ingredients: [{ name: 'garlic' }, { name: 'thyme' }]
573
+ }
574
+ ]
575
+ })
576
+ );
577
+
578
+ const matchSingle = await service.query(Recipe, {
579
+ where: {
580
+ sections: {
581
+ ingredients: {
582
+ name: 'garlic'
583
+ }
584
+ }
585
+ }
586
+ });
587
+ assert(matchSingle.length === 2);
588
+
589
+ const matchIn = await service.query(Recipe, {
590
+ where: {
591
+ sections: {
592
+ ingredients: {
593
+ name: { $in: ['onion', 'salt'] }
594
+ }
595
+ }
596
+ }
597
+ });
598
+ assert(matchIn.length === 2);
599
+
600
+ const matchNotEqual = await service.query(Recipe, {
601
+ where: {
602
+ sections: {
603
+ ingredients: {
604
+ name: { $ne: 'garlic' }
605
+ }
606
+ }
607
+ }
608
+ });
609
+ assert(matchNotEqual.length === 1);
610
+ }
611
+
541
612
  @Test('Verify array of objects property queries')
542
613
  async verifyArrayOfObjectsProperty() {
543
614
  const service = await this.service;