@travetto/model-firestore 2.0.1 → 2.1.0

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
@@ -61,10 +61,6 @@ export class FirestoreModelConfig {
61
61
  if (this.emulator) {
62
62
  process.env.FIRESTORE_EMULATOR_HOST = this.emulator;
63
63
  }
64
- if (typeof this.credentials === 'string') {
65
- this.credentialsFile = this.credentials;
66
- delete this.credentials;
67
- }
68
64
  if (this.credentialsFile && !this.credentials) {
69
65
  this.credentials = JSON.parse(await ResourceManager.read(this.credentialsFile, 'utf8'));
70
66
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@travetto/model-firestore",
3
3
  "displayName": "Firestore Model Support",
4
- "version": "2.0.1",
4
+ "version": "2.1.0",
5
5
  "description": "Firestore backing for the travetto model module.",
6
6
  "keywords": [
7
7
  "typescript",
@@ -26,9 +26,9 @@
26
26
  "directory": "module/model-firestore"
27
27
  },
28
28
  "dependencies": {
29
- "@travetto/config": "^2.0.1",
30
- "@travetto/model": "^2.0.1",
31
- "@google-cloud/firestore": "^4.12.2"
29
+ "@travetto/config": "^2.1.0",
30
+ "@travetto/model": "^2.1.0",
31
+ "@google-cloud/firestore": "^5.0.2"
32
32
  },
33
33
  "private": false,
34
34
  "publishConfig": {
package/src/config.ts CHANGED
@@ -20,10 +20,6 @@ export class FirestoreModelConfig {
20
20
  if (this.emulator) {
21
21
  process.env.FIRESTORE_EMULATOR_HOST = this.emulator;
22
22
  }
23
- if (typeof this.credentials === 'string') {
24
- this.credentialsFile = this.credentials;
25
- delete this.credentials;
26
- }
27
23
  if (this.credentialsFile && !this.credentials) {
28
24
  this.credentials = JSON.parse(await ResourceManager.read(this.credentialsFile, 'utf8'));
29
25
  }
package/src/service.ts CHANGED
@@ -5,8 +5,7 @@ import { DeepPartial } from '@travetto/schema';
5
5
  import { Injectable } from '@travetto/di';
6
6
  import {
7
7
  ModelCrudSupport, ModelRegistry, ModelStorageSupport,
8
- ModelIndexedSupport, ModelType, NotFoundError, SubTypeNotSupportedError,
9
- OptionalId
8
+ ModelIndexedSupport, ModelType, NotFoundError, OptionalId
10
9
  } from '@travetto/model';
11
10
 
12
11
  import { ModelCrudUtil } from '@travetto/model/src/internal/service/crud';
@@ -77,27 +76,21 @@ export class FirestoreModelService implements ModelCrudSupport, ModelStorageSupp
77
76
  }
78
77
 
79
78
  async update<T extends ModelType>(cls: Class<T>, item: T) {
80
- if (ModelRegistry.get(cls).subType) {
81
- throw new SubTypeNotSupportedError(cls);
82
- }
79
+ ModelCrudUtil.ensureNotSubType(cls);
83
80
  item = await ModelCrudUtil.preStore(cls, item, this);
84
81
  await this.#getCollection(cls).doc(item.id).update(clone(item));
85
82
  return item;
86
83
  }
87
84
 
88
85
  async upsert<T extends ModelType>(cls: Class<T>, item: OptionalId<T>) {
89
- if (ModelRegistry.get(cls).subType) {
90
- throw new SubTypeNotSupportedError(cls);
91
- }
86
+ ModelCrudUtil.ensureNotSubType(cls);
92
87
  const prepped = await ModelCrudUtil.preStore(cls, item, this);
93
88
  await this.#getCollection(cls).doc(prepped.id).set(clone(prepped));
94
89
  return prepped;
95
90
  }
96
91
 
97
92
  async updatePartial<T extends ModelType>(cls: Class<T>, item: Partial<T> & { id: string }, view?: string) {
98
- if (ModelRegistry.get(cls).subType) {
99
- throw new SubTypeNotSupportedError(cls);
100
- }
93
+ ModelCrudUtil.ensureNotSubType(cls);
101
94
  const id = item.id;
102
95
  item = await ModelCrudUtil.naivePartialUpdate(cls, item, view, async () => ({} as unknown as T));
103
96
  const cleaned = toSimpleObj(item, FieldValue.delete());
@@ -106,9 +99,7 @@ export class FirestoreModelService implements ModelCrudSupport, ModelStorageSupp
106
99
  }
107
100
 
108
101
  async delete<T extends ModelType>(cls: Class<T>, id: string) {
109
- if (ModelRegistry.get(cls).subType) {
110
- throw new SubTypeNotSupportedError(cls);
111
- }
102
+ ModelCrudUtil.ensureNotSubType(cls);
112
103
  try {
113
104
  await this.#getCollection(cls).doc(id).delete({ exists: true } as unknown as Precondition);
114
105
  } catch (err) {
@@ -134,9 +125,7 @@ export class FirestoreModelService implements ModelCrudSupport, ModelStorageSupp
134
125
 
135
126
  // Indexed
136
127
  async #getIdByIndex<T extends ModelType>(cls: Class<T>, idx: string, body: DeepPartial<T>) {
137
- if (ModelRegistry.get(cls).subType) {
138
- throw new SubTypeNotSupportedError(cls);
139
- }
128
+ ModelCrudUtil.ensureNotSubType(cls);
140
129
 
141
130
  const { fields } = ModelIndexedUtil.computeIndexParts(cls, idx, body);
142
131
  const query = fields.reduce((q, { path, value }) => q.where(path.join('.'), '==', value),
@@ -164,9 +153,7 @@ export class FirestoreModelService implements ModelCrudSupport, ModelStorageSupp
164
153
  }
165
154
 
166
155
  async * listByIndex<T extends ModelType>(cls: Class<T>, idx: string, body: DeepPartial<T>) {
167
- if (ModelRegistry.get(cls).subType) {
168
- throw new SubTypeNotSupportedError(cls);
169
- }
156
+ ModelCrudUtil.ensureNotSubType(cls);
170
157
 
171
158
  const { fields, sorted } = ModelIndexedUtil.computeIndexParts(cls, idx, body, { emptySortValue: null });
172
159
  let query = fields.reduce((q, { path, value }) =>