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

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.
Files changed (2) hide show
  1. package/package.json +7 -7
  2. package/src/service.ts +10 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-firestore",
3
- "version": "8.0.0-alpha.17",
3
+ "version": "8.0.0-alpha.19",
4
4
  "description": "Firestore backing for the travetto model module.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -25,14 +25,14 @@
25
25
  "directory": "module/model-firestore"
26
26
  },
27
27
  "dependencies": {
28
- "@google-cloud/firestore": "^8.5.0",
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"
28
+ "@google-cloud/firestore": "^8.6.0",
29
+ "@travetto/config": "^8.0.0-alpha.17",
30
+ "@travetto/model": "^8.0.0-alpha.17",
31
+ "@travetto/model-indexed": "^8.0.0-alpha.19",
32
+ "@travetto/runtime": "^8.0.0-alpha.16"
33
33
  },
34
34
  "peerDependencies": {
35
- "@travetto/cli": "^8.0.0-alpha.20"
35
+ "@travetto/cli": "^8.0.0-alpha.22"
36
36
  },
37
37
  "peerDependenciesMeta": {
38
38
  "@travetto/cli": {
package/src/service.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { type DocumentData, FieldValue, Firestore, type Query } from '@google-cloud/firestore';
2
2
 
3
- import { castTo, JSONUtil, ShutdownManager, type Class } from '@travetto/runtime';
3
+ import { castTo, JSONUtil, ShutdownManager, type Class, RuntimeError } from '@travetto/runtime';
4
4
  import { Injectable, PostConstruct } from '@travetto/di';
5
5
  import {
6
6
  type ModelCrudSupport, ModelRegistryIndex, type ModelStorageSupport, type ModelType, NotFoundError, type OptionalId, ModelCrudUtil,
@@ -59,7 +59,10 @@ export class FirestoreModelService implements ModelCrudSupport, ModelStorageSupp
59
59
  if (!item || item.empty) {
60
60
  throw new NotFoundError(`${cls.name} Index=${idx}`, computed.getKey());
61
61
  }
62
- return item.docs[0].id;
62
+ if (item.size > 1) {
63
+ throw new RuntimeError(`Multiple items found for ${cls.name} Index=${idx}`);
64
+ }
65
+ return item.docs[0].data().id;
63
66
  }
64
67
 
65
68
  #buildIndexQuery<T extends ModelType>(cls: Class<T>, idx: SortedIndex<T>, body: KeyedIndexBody<T>): Query {
@@ -89,19 +92,17 @@ export class FirestoreModelService implements ModelCrudSupport, ModelStorageSupp
89
92
  while (!(options?.abort?.aborted) && produced < limit) {
90
93
  const query = queryBuilder().limit(batchSize).offset(offset);
91
94
 
92
- let { docs } = await query.get();
93
- if (docs.length === 0) {
95
+ const { docs, size } = await query.get();
96
+ if (size === 0) {
94
97
  break;
95
98
  }
96
99
 
97
- if (produced + docs.length > limit) {
98
- docs = docs.slice(0, limit - produced);
99
- }
100
+ const remaining = (produced + size > limit) ? docs.slice(0, limit - produced) : docs;
100
101
 
101
- offset += docs.length;
102
+ offset += size;
102
103
 
103
104
  const items = await ModelCrudUtil.filterOutNotFound(
104
- docs.map(item => ModelCrudUtil.load(cls, item.data()!)));
105
+ remaining.map(item => ModelCrudUtil.load(cls, item.data()!)));
105
106
  produced += items.length;
106
107
 
107
108
  yield { items, nextOffset: offset };
@@ -110,7 +111,6 @@ export class FirestoreModelService implements ModelCrudSupport, ModelStorageSupp
110
111
 
111
112
  @PostConstruct()
112
113
  async initializeClient(): Promise<void> {
113
- globalThis.devProcessWarningExclusions?.push((_, category) => category === 'MetadataLookupWarning');
114
114
  this.client = new Firestore({ ...this.config, useBigInt: true });
115
115
  ShutdownManager.signal.addEventListener('abort', () => this.client.terminate());
116
116
  }