@travetto/model-firestore 8.0.0-alpha.25 → 8.0.0-alpha.27
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/model-firestore",
|
|
3
|
-
"version": "8.0.0-alpha.
|
|
3
|
+
"version": "8.0.0-alpha.27",
|
|
4
4
|
"description": "Firestore backing for the travetto model module.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@google-cloud/firestore": "^8.6.0",
|
|
29
|
-
"@travetto/config": "^8.0.0-alpha.
|
|
30
|
-
"@travetto/model": "^8.0.0-alpha.
|
|
31
|
-
"@travetto/model-indexed": "^8.0.0-alpha.
|
|
32
|
-
"@travetto/runtime": "^8.0.0-alpha.
|
|
29
|
+
"@travetto/config": "^8.0.0-alpha.20",
|
|
30
|
+
"@travetto/model": "^8.0.0-alpha.21",
|
|
31
|
+
"@travetto/model-indexed": "^8.0.0-alpha.23",
|
|
32
|
+
"@travetto/runtime": "^8.0.0-alpha.19"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@travetto/cli": "^8.0.0-alpha.
|
|
35
|
+
"@travetto/cli": "^8.0.0-alpha.26"
|
|
36
36
|
},
|
|
37
37
|
"peerDependenciesMeta": {
|
|
38
38
|
"@travetto/cli": {
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import cp from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
|
|
1
4
|
import { type CliCommandShape, CliCommand, CliModuleFlag } from '@travetto/cli';
|
|
2
|
-
import { JSONUtil, Env } from '@travetto/runtime';
|
|
5
|
+
import { JSONUtil, Env, ExecUtil, Runtime } from '@travetto/runtime';
|
|
3
6
|
import { Registry } from '@travetto/registry';
|
|
4
7
|
import { DependencyRegistryIndex } from '@travetto/di';
|
|
5
8
|
import { ModelRegistryIndex } from '@travetto/model';
|
|
6
9
|
import { isModelIndexedIndex } from '@travetto/model-indexed';
|
|
7
|
-
import { ManifestFileUtil
|
|
10
|
+
import { ManifestFileUtil } from '@travetto/manifest';
|
|
8
11
|
|
|
9
12
|
import { FirestoreModelConfig } from '../src/config.ts';
|
|
10
13
|
import { FirestoreModelService } from '../src/service.ts';
|
|
@@ -34,12 +37,15 @@ type FirestoreIndexSet = {
|
|
|
34
37
|
@CliCommand()
|
|
35
38
|
export class FirestoreIndexesCommand implements CliCommandShape {
|
|
36
39
|
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
indexFile = 'firestore.indexes.json';
|
|
41
|
+
firebaseFile = 'firebase.json';
|
|
39
42
|
|
|
40
43
|
@CliModuleFlag({ short: 'm' })
|
|
41
44
|
module: string;
|
|
42
45
|
|
|
46
|
+
/** Should we deploy after writing the json file? */
|
|
47
|
+
deploy?: boolean;
|
|
48
|
+
|
|
43
49
|
finalize(): void {
|
|
44
50
|
Env.DEBUG.set(false);
|
|
45
51
|
}
|
|
@@ -74,10 +80,37 @@ export class FirestoreIndexesCommand implements CliCommandShape {
|
|
|
74
80
|
|
|
75
81
|
const text = JSONUtil.toUTF8Pretty(outputData);
|
|
76
82
|
|
|
77
|
-
|
|
78
|
-
|
|
83
|
+
await ManifestFileUtil.bufferedFileWrite(this.indexFile, text);
|
|
84
|
+
|
|
85
|
+
const firebaseLocation = Runtime.workspaceRelative(this.firebaseFile);
|
|
86
|
+
if (!await fs.stat(firebaseLocation, { throwIfNoEntry: false })) {
|
|
87
|
+
await ManifestFileUtil.bufferedFileWrite(firebaseLocation, '{}');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const firebaseContext = JSONUtil.fromBinaryArray<{ firestore?: { database?: string, indexes?: string }[] }>(await fs.readFile(firebaseLocation));
|
|
91
|
+
const existing = (firebaseContext.firestore ??= []);
|
|
92
|
+
const found = existing.find(x => x.database === config.databaseId);
|
|
93
|
+
|
|
94
|
+
let changed = true;
|
|
95
|
+
if (!found) {
|
|
96
|
+
existing.push(({ indexes: this.indexFile, database: config.databaseId }));
|
|
97
|
+
} else if (found.indexes !== this.indexFile) {
|
|
98
|
+
found.indexes = this.indexFile;
|
|
79
99
|
} else {
|
|
80
|
-
|
|
100
|
+
changed = false;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (changed) {
|
|
104
|
+
await ManifestFileUtil.bufferedFileWrite(firebaseLocation, JSONUtil.toUTF8Pretty(firebaseContext));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (this.deploy) {
|
|
108
|
+
const child = cp.spawn(
|
|
109
|
+
'firebase', ['deploy', '--only', 'firestore:indexes'],
|
|
110
|
+
// Complete take over
|
|
111
|
+
{ stdio: 'inherit' },
|
|
112
|
+
);
|
|
113
|
+
await ExecUtil.getResult(child)
|
|
81
114
|
}
|
|
82
115
|
}
|
|
83
116
|
}
|