@travetto/model-firestore 3.0.0-rc.4 → 3.0.0-rc.7
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 +6 -5
- package/{index.ts → __index__.ts} +0 -0
- package/package.json +18 -7
- package/src/config.ts +3 -2
- package/src/service.ts +5 -4
- package/support/service.firestore.ts +3 -3
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<!-- This file was generated by @travetto/doc and should not be modified directly -->
|
|
2
|
-
<!-- Please modify https://github.com/travetto/travetto/tree/main/module/model-firestore/
|
|
2
|
+
<!-- Please modify https://github.com/travetto/travetto/tree/main/module/model-firestore/DOC.ts and execute "npx trv doc" to rebuild -->
|
|
3
3
|
# Firestore Model Support
|
|
4
4
|
## Firestore backing for the travetto model module.
|
|
5
5
|
|
|
@@ -39,7 +39,7 @@ export class Init {
|
|
|
39
39
|
|
|
40
40
|
**Code: Structure of FirestoreModelConfig**
|
|
41
41
|
```typescript
|
|
42
|
-
import {
|
|
42
|
+
import { CommonFileResourceProvider } from '@travetto/base';
|
|
43
43
|
import { Config } from '@travetto/config';
|
|
44
44
|
|
|
45
45
|
@Config('model.firestore')
|
|
@@ -62,11 +62,12 @@ export class FirestoreModelConfig {
|
|
|
62
62
|
process.env.FIRESTORE_EMULATOR_HOST = this.emulator;
|
|
63
63
|
}
|
|
64
64
|
if (this.credentialsFile && !this.credentials) {
|
|
65
|
-
|
|
65
|
+
const resources = new CommonFileResourceProvider();
|
|
66
|
+
this.credentials = JSON.parse(await resources.read(this.credentialsFile));
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
```
|
|
70
71
|
|
|
71
|
-
Additionally, you can see that the class is registered with the [@Config](https://github.com/travetto/travetto/tree/main/module/config/src/decorator.ts#
|
|
72
|
-
standard [Configuration](https://github.com/travetto/travetto/tree/main/module/config#readme "
|
|
72
|
+
Additionally, you can see that the class is registered with the [@Config](https://github.com/travetto/travetto/tree/main/module/config/src/decorator.ts#L13) annotation, and so these values can be overridden using the
|
|
73
|
+
standard [Configuration](https://github.com/travetto/travetto/tree/main/module/config#readme "Configuration support")resolution paths.
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-firestore",
|
|
3
|
-
"
|
|
4
|
-
"version": "3.0.0-rc.4",
|
|
3
|
+
"version": "3.0.0-rc.7",
|
|
5
4
|
"description": "Firestore backing for the travetto model module.",
|
|
6
5
|
"keywords": [
|
|
7
6
|
"typescript",
|
|
@@ -16,19 +15,31 @@
|
|
|
16
15
|
"name": "Travetto Framework"
|
|
17
16
|
},
|
|
18
17
|
"files": [
|
|
19
|
-
"
|
|
18
|
+
"__index__.ts",
|
|
20
19
|
"src",
|
|
21
20
|
"support"
|
|
22
21
|
],
|
|
23
|
-
"main": "
|
|
22
|
+
"main": "__index__.ts",
|
|
24
23
|
"repository": {
|
|
25
24
|
"url": "https://github.com/travetto/travetto.git",
|
|
26
25
|
"directory": "module/model-firestore"
|
|
27
26
|
},
|
|
28
27
|
"dependencies": {
|
|
29
|
-
"@
|
|
30
|
-
"@travetto/
|
|
31
|
-
"@
|
|
28
|
+
"@google-cloud/firestore": "^5.0.2",
|
|
29
|
+
"@travetto/base": "^3.0.0-rc.5",
|
|
30
|
+
"@travetto/config": "^3.0.0-rc.7",
|
|
31
|
+
"@travetto/model": "^3.0.0-rc.7"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@travetto/command": "^3.0.0-rc.5"
|
|
35
|
+
},
|
|
36
|
+
"peerDependenciesMeta": {
|
|
37
|
+
"@travetto/command": {
|
|
38
|
+
"optional": true
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"travetto": {
|
|
42
|
+
"displayName": "Firestore Model Support"
|
|
32
43
|
},
|
|
33
44
|
"private": false,
|
|
34
45
|
"publishConfig": {
|
package/src/config.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FileResourceProvider } from '@travetto/base';
|
|
2
2
|
import { Config } from '@travetto/config';
|
|
3
3
|
|
|
4
4
|
@Config('model.firestore')
|
|
@@ -21,7 +21,8 @@ export class FirestoreModelConfig {
|
|
|
21
21
|
process.env.FIRESTORE_EMULATOR_HOST = this.emulator;
|
|
22
22
|
}
|
|
23
23
|
if (this.credentialsFile && !this.credentials) {
|
|
24
|
-
|
|
24
|
+
const resources = new FileResourceProvider({ includeCommon: true });
|
|
25
|
+
this.credentials = JSON.parse(await resources.read(this.credentialsFile));
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
}
|
package/src/service.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DocumentData, FieldValue, Firestore, PartialWithFieldValue, Query, UpdateData } from '@google-cloud/firestore';
|
|
2
2
|
|
|
3
|
-
import { ShutdownManager,
|
|
3
|
+
import { ShutdownManager, type Class } from '@travetto/base';
|
|
4
4
|
import { DeepPartial } from '@travetto/schema';
|
|
5
5
|
import { Injectable } from '@travetto/di';
|
|
6
6
|
import {
|
|
@@ -10,10 +10,11 @@ import {
|
|
|
10
10
|
|
|
11
11
|
import { ModelCrudUtil } from '@travetto/model/src/internal/service/crud';
|
|
12
12
|
import { ModelIndexedUtil } from '@travetto/model/src/internal/service/indexed';
|
|
13
|
+
import { ModelUtil } from '@travetto/model/src/internal/util';
|
|
13
14
|
|
|
14
15
|
import { FirestoreModelConfig } from './config';
|
|
15
16
|
|
|
16
|
-
const clone =
|
|
17
|
+
const clone = structuredClone;
|
|
17
18
|
|
|
18
19
|
const toSimpleObj = <T>(inp: T, missingValue: unknown = null): PartialWithFieldValue<DocumentData> =>
|
|
19
20
|
JSON.parse(JSON.stringify(inp, (_, v) => v ?? null), (_, v) => v ?? missingValue);
|
|
@@ -42,7 +43,7 @@ export class FirestoreModelService implements ModelCrudSupport, ModelStorageSupp
|
|
|
42
43
|
|
|
43
44
|
async postConstruct(): Promise<void> {
|
|
44
45
|
this.client = new Firestore(this.config);
|
|
45
|
-
ShutdownManager.onShutdown(this
|
|
46
|
+
ShutdownManager.onShutdown(this, () => this.client.terminate());
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
// Storage
|
|
@@ -57,7 +58,7 @@ export class FirestoreModelService implements ModelCrudSupport, ModelStorageSupp
|
|
|
57
58
|
|
|
58
59
|
// Crud
|
|
59
60
|
uuid(): string {
|
|
60
|
-
return
|
|
61
|
+
return ModelUtil.uuid();
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
async get<T extends ModelType>(cls: Class<T>, id: string): Promise<T> {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type { Service } from '@travetto/command/bin/
|
|
1
|
+
import { Env } from '@travetto/base';
|
|
2
|
+
import type { Service } from '@travetto/command/support/bin/service';
|
|
3
3
|
|
|
4
|
-
const version =
|
|
4
|
+
const version = Env.get('FIRESTORE_VERSION', 'latest');
|
|
5
5
|
|
|
6
6
|
export const service: Service = {
|
|
7
7
|
name: 'firestore',
|