@travetto/model-firestore 8.0.0-alpha.16 → 8.0.0-alpha.17

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 CHANGED
@@ -17,7 +17,7 @@ This module provides an [Firestore](https://firebase.google.com/docs/firestore)-
17
17
 
18
18
  Supported features:
19
19
  * [CRUD](https://github.com/travetto/travetto/tree/main/module/model/src/types/crud.ts#L11)
20
- * [Indexed](https://github.com/travetto/travetto/tree/main/module/model-indexed/src/types/service.ts#L15)
20
+ * [Indexed](https://github.com/travetto/travetto/tree/main/module/model-indexed/src/types/service.ts#L16)
21
21
 
22
22
  Out of the box, by installing the module, everything should be wired up by default.If you need to customize any aspect of the source or config, you can override and register it with the [Dependency Injection](https://github.com/travetto/travetto/tree/main/module/di#readme "Dependency registration/management and injection support.") module.
23
23
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-firestore",
3
- "version": "8.0.0-alpha.16",
3
+ "version": "8.0.0-alpha.17",
4
4
  "description": "Firestore backing for the travetto model module.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -26,13 +26,13 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@google-cloud/firestore": "^8.5.0",
29
- "@travetto/config": "^8.0.0-alpha.14",
30
- "@travetto/model": "^8.0.0-alpha.14",
31
- "@travetto/model-indexed": "^8.0.0-alpha.16",
32
- "@travetto/runtime": "^8.0.0-alpha.13"
29
+ "@travetto/config": "^8.0.0-alpha.15",
30
+ "@travetto/model": "^8.0.0-alpha.15",
31
+ "@travetto/model-indexed": "^8.0.0-alpha.17",
32
+ "@travetto/runtime": "^8.0.0-alpha.14"
33
33
  },
34
34
  "peerDependencies": {
35
- "@travetto/cli": "^8.0.0-alpha.19"
35
+ "@travetto/cli": "^8.0.0-alpha.20"
36
36
  },
37
37
  "peerDependenciesMeta": {
38
38
  "@travetto/cli": {
package/src/service.ts CHANGED
@@ -9,7 +9,8 @@ import {
9
9
  import {
10
10
  type ModelIndexedSupport, type KeyedIndexSelection, type KeyedIndexBody, type ModelPageOptions, ModelIndexedUtil,
11
11
  type SingleItemIndex, type SortedIndexSelection, type ModelPageResult, type SortedIndex, type FullKeyedIndexBody,
12
- type FullKeyedIndexWithPartialBody, ModelIndexedComputedIndex, warnIfIndexedUniqueIndex, warnIfNonIndexedIndex
12
+ type FullKeyedIndexWithPartialBody, ModelIndexedComputedIndex, warnIfIndexedUniqueIndex, warnIfNonIndexedIndex,
13
+ type ModelIndexedSearchOptions, type SortedIndexSelectionType
13
14
  } from '@travetto/model-indexed';
14
15
 
15
16
  import type { FirestoreModelConfig } from './config.ts';
@@ -61,11 +62,7 @@ export class FirestoreModelService implements ModelCrudSupport, ModelStorageSupp
61
62
  return item.docs[0].id;
62
63
  }
63
64
 
64
- #buildIndexQuery<
65
- T extends ModelType,
66
- K extends KeyedIndexSelection<T>,
67
- S extends SortedIndexSelection<T>
68
- >(cls: Class<T>, idx: SortedIndex<T, K, S>, body: KeyedIndexBody<T, K>): Query {
65
+ #buildIndexQuery<T extends ModelType>(cls: Class<T>, idx: SortedIndex<T>, body: KeyedIndexBody<T>): Query {
69
66
  ModelCrudUtil.ensureNotSubType(cls);
70
67
  const computed = ModelIndexedComputedIndex.get(idx, body).validate();
71
68
 
@@ -269,4 +266,26 @@ export class FirestoreModelService implements ModelCrudSupport, ModelStorageSupp
269
266
  yield items;
270
267
  }
271
268
  }
269
+
270
+ async suggestByIndex<
271
+ T extends ModelType,
272
+ S extends SortedIndexSelection<T>,
273
+ K extends KeyedIndexSelection<T>,
274
+ B extends SortedIndexSelectionType<T, S> & string
275
+ >(cls: Class<T>, idx: SortedIndex<T, K, S>, body: KeyedIndexBody<T, K>, prefix: B, options?: ModelIndexedSearchOptions): Promise<T[]> {
276
+ const results: T[] = [];
277
+
278
+ const field = idx.sortTemplate[0].path.join('.');
279
+
280
+ for await (const { items } of this.#scanCollection(cls,
281
+ () => this.#buildIndexQuery(cls, idx, body)
282
+ .where(field, '>=', prefix)
283
+ .where(field, '<', `${prefix}\uf8ff`),
284
+ { limit: 10, ...options })
285
+ ) {
286
+ results.push(...items);
287
+ }
288
+
289
+ return results;
290
+ }
272
291
  }