@travetto/model-firestore 2.0.3 → 2.1.1
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 +0 -4
- package/package.json +4 -4
- package/src/service.ts +7 -20
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.
|
|
4
|
+
"version": "2.1.1",
|
|
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.
|
|
30
|
-
"@travetto/model": "^2.
|
|
31
|
-
"@google-cloud/firestore": "^
|
|
29
|
+
"@travetto/config": "^2.1.1",
|
|
30
|
+
"@travetto/model": "^2.1.1",
|
|
31
|
+
"@google-cloud/firestore": "^5.0.2"
|
|
32
32
|
},
|
|
33
33
|
"private": false,
|
|
34
34
|
"publishConfig": {
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 }) =>
|