@travetto/model-firestore 7.0.0-rc.0 → 7.0.0-rc.2

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
@@ -30,8 +30,8 @@ export class Init {
30
30
  @InjectableFactory({
31
31
  primary: true
32
32
  })
33
- static getModelSource(conf: FirestoreModelConfig) {
34
- return new FirestoreModelService(conf);
33
+ static getModelSource(config: FirestoreModelConfig) {
34
+ return new FirestoreModelService(config);
35
35
  }
36
36
  }
37
37
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/model-firestore",
3
- "version": "7.0.0-rc.0",
3
+ "version": "7.0.0-rc.2",
4
4
  "description": "Firestore backing for the travetto model module.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -26,10 +26,10 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@google-cloud/firestore": "^7.11.6",
29
- "@travetto/cli": "^7.0.0-rc.0",
30
- "@travetto/config": "^7.0.0-rc.0",
31
- "@travetto/model": "^7.0.0-rc.0",
32
- "@travetto/runtime": "^7.0.0-rc.0"
29
+ "@travetto/cli": "^7.0.0-rc.2",
30
+ "@travetto/config": "^7.0.0-rc.2",
31
+ "@travetto/model": "^7.0.0-rc.2",
32
+ "@travetto/runtime": "^7.0.0-rc.2"
33
33
  },
34
34
  "travetto": {
35
35
  "displayName": "Firestore Model Support"
package/src/service.ts CHANGED
@@ -12,8 +12,8 @@ import { FirestoreModelConfig } from './config.ts';
12
12
 
13
13
  const clone = structuredClone;
14
14
 
15
- const toSimpleObj = <T>(inp: T, missingValue: unknown = null): PartialWithFieldValue<DocumentData> =>
16
- JSON.parse(JSON.stringify(inp, (_, v) => v ?? null), (_, v) => v ?? missingValue);
15
+ const toSimpleObject = <T>(input: T, missingValue: unknown = null): PartialWithFieldValue<DocumentData> =>
16
+ JSON.parse(JSON.stringify(input, (_, value) => value ?? null), (_, value) => value ?? missingValue);
17
17
 
18
18
  /**
19
19
  * A model service backed by Firestore
@@ -49,8 +49,8 @@ export class FirestoreModelService implements ModelCrudSupport, ModelStorageSupp
49
49
  async deleteStorage(): Promise<void> { }
50
50
 
51
51
  async deleteModel(cls: Class): Promise<void> {
52
- for await (const el of this.list(cls)) {
53
- await this.delete(cls, el.id);
52
+ for await (const item of this.list(cls)) {
53
+ await this.delete(cls, item.id);
54
54
  }
55
55
  }
56
56
 
@@ -88,7 +88,7 @@ export class FirestoreModelService implements ModelCrudSupport, ModelStorageSupp
88
88
  ModelCrudUtil.ensureNotSubType(cls);
89
89
  const id = item.id;
90
90
  const full = await ModelCrudUtil.naivePartialUpdate(cls, () => this.get(cls, id), item, view);
91
- const cleaned = toSimpleObj(full, FieldValue.delete());
91
+ const cleaned = toSimpleObject(full, FieldValue.delete());
92
92
  await this.#getCollection(cls).doc(id).set(cleaned, { mergeFields: Object.keys(full) });
93
93
  return this.get(cls, id);
94
94
  }
@@ -97,22 +97,22 @@ export class FirestoreModelService implements ModelCrudSupport, ModelStorageSupp
97
97
  ModelCrudUtil.ensureNotSubType(cls);
98
98
  try {
99
99
  await this.#getCollection(cls).doc(id).delete({ exists: true });
100
- } catch (err) {
101
- if (err && err instanceof Error && err.message.includes('NOT_FOUND')) {
100
+ } catch (error) {
101
+ if (error && error instanceof Error && error.message.includes('NOT_FOUND')) {
102
102
  throw new NotFoundError(cls, id);
103
103
  }
104
- throw err;
104
+ throw error;
105
105
  }
106
106
  }
107
107
 
108
108
  async * list<T extends ModelType>(cls: Class<T>): AsyncIterable<T> {
109
109
  const batch = await this.#getCollection(cls).select().get();
110
- for (const el of batch.docs) {
110
+ for (const item of batch.docs) {
111
111
  try {
112
- yield await this.get(cls, el.id);
113
- } catch (err) {
114
- if (!(err instanceof NotFoundError)) {
115
- throw err;
112
+ yield await this.get(cls, item.id);
113
+ } catch (error) {
114
+ if (!(error instanceof NotFoundError)) {
115
+ throw error;
116
116
  }
117
117
  }
118
118
  }
@@ -124,7 +124,7 @@ export class FirestoreModelService implements ModelCrudSupport, ModelStorageSupp
124
124
 
125
125
  const { fields } = ModelIndexedUtil.computeIndexParts(cls, idx, body);
126
126
  const query = fields.reduce<Query>(
127
- (q, { path, value }) => q.where(path.join('.'), '==', value),
127
+ (result, { path, value }) => result.where(path.join('.'), '==', value),
128
128
  this.#getCollection(cls)
129
129
  );
130
130
 
@@ -133,7 +133,7 @@ export class FirestoreModelService implements ModelCrudSupport, ModelStorageSupp
133
133
  if (item && !item.empty) {
134
134
  return item.docs[0].id;
135
135
  }
136
- throw new NotFoundError(`${cls.name} Index=${idx}`, ModelIndexedUtil.computeIndexKey(cls, idx, body, { sep: '; ' })?.key);
136
+ throw new NotFoundError(`${cls.name} Index=${idx}`, ModelIndexedUtil.computeIndexKey(cls, idx, body, { separator: '; ' })?.key);
137
137
  }
138
138
 
139
139
  async getByIndex<T extends ModelType>(cls: Class<T>, idx: string, body: DeepPartial<T>): Promise<T> {
@@ -151,17 +151,17 @@ export class FirestoreModelService implements ModelCrudSupport, ModelStorageSupp
151
151
  async * listByIndex<T extends ModelType>(cls: Class<T>, idx: string, body: DeepPartial<T>): AsyncIterable<T> {
152
152
  ModelCrudUtil.ensureNotSubType(cls);
153
153
 
154
- const cfg = ModelRegistryIndex.getIndex(cls, idx, ['sorted', 'unsorted']);
155
- const { fields, sorted } = ModelIndexedUtil.computeIndexParts(cls, cfg, body, { emptySortValue: null });
156
- let query = fields.reduce<Query>((q, { path, value }) =>
157
- q.where(path.join('.'), '==', value), this.#getCollection(cls));
154
+ const config = ModelRegistryIndex.getIndex(cls, idx, ['sorted', 'unsorted']);
155
+ const { fields, sorted } = ModelIndexedUtil.computeIndexParts(cls, config, body, { emptySortValue: null });
156
+ let query = fields.reduce<Query>((result, { path, value }) =>
157
+ result.where(path.join('.'), '==', value), this.#getCollection(cls));
158
158
 
159
159
  if (sorted) {
160
160
  query = query.orderBy(sorted.path.join('.'), sorted.dir === 1 ? 'asc' : 'desc');
161
161
  }
162
162
 
163
- for (const el of (await query.get()).docs) {
164
- yield await ModelCrudUtil.load(cls, el.data()!);
163
+ for (const item of (await query.get()).docs) {
164
+ yield await ModelCrudUtil.load(cls, item.data()!);
165
165
  }
166
166
  }
167
167
  }