1
1
import { z } from "zod" ;
2
2
import { tool } from "../../tool.js" ;
3
3
import { toContent } from "../../util.js" ;
4
- import { actuate , Setup } from "../../../init/index.js" ;
4
+ import { actuate , Setup , SetupInfo } from "../../../init/index.js" ;
5
5
6
6
export const init = tool (
7
7
{
@@ -11,8 +11,24 @@ export const init = tool(
11
11
features : z . object ( {
12
12
// TODO: Add all the features here.
13
13
dataconnect : z . object ( {
14
- serviceId : z . string ( ) . optional ( ) . describe ( "The Firebase Data Connect service ID to setup." ) ,
15
- locationId : z . string ( ) . default ( "us-central1" ) . describe ( "The GCP region ID to set up the Firebase Data Connect service. For example, us-central1." ) ,
14
+ serviceId : z
15
+ . string ( )
16
+ . optional ( )
17
+ . describe (
18
+ "Configure the Firebase Data Connect service ID to setup. Default to match the current folder name." ,
19
+ ) ,
20
+ locationId : z
21
+ . string ( )
22
+ . default ( "us-central1" )
23
+ . describe ( "The GCP region ID to set up the Firebase Data Connect service." ) ,
24
+ cloudSqlInstanceId : z
25
+ . string ( )
26
+ . optional ( )
27
+ . describe ( "The GCP Cloud SQL instance ID to use in the Firebase Data Connect service." ) ,
28
+ cloudSqlDatabase : z
29
+ . string ( )
30
+ . optional ( )
31
+ . describe ( "The Postgres database ID to use in the Firebase Data Connect service." ) ,
16
32
} ) ,
17
33
} ) ,
18
34
} ) ,
@@ -21,25 +37,38 @@ export const init = tool(
21
37
readOnlyHint : false ,
22
38
} ,
23
39
_meta : {
24
- requiresProject : false , // Can start from stratch .
40
+ requiresProject : false , // Can start from scratch .
25
41
requiresAuth : false , // Will throw error if the specific feature needs it.
26
42
} ,
27
43
} ,
28
- async ( { features} , { projectId, config, rc } ) => {
44
+ async ( { features } , { projectId, config, rc } ) => {
45
+ const featuresList : string [ ] = [ ] ;
46
+ const featureInfo : SetupInfo = { } ;
47
+ if ( features . dataconnect ) {
48
+ featuresList . push ( "dataconnect" ) ;
49
+ featureInfo . dataconnect = {
50
+ serviceId : features . dataconnect . serviceId || "" ,
51
+ locationId : features . dataconnect . locationId || "" ,
52
+ cloudSqlInstanceId : features . dataconnect . cloudSqlInstanceId || "" ,
53
+ cloudSqlDatabase : features . dataconnect . cloudSqlDatabase || "" ,
54
+ connectors : [ ] , // TODO populate with GiF,
55
+ isNewInstance : false ,
56
+ isNewDatabase : false ,
57
+ schemaGql : [ ] , // TODO populate with GiF
58
+ shouldProvisionCSQL : false ,
59
+ } ;
60
+ }
61
+
29
62
const setup : Setup = {
30
63
config : config . src ,
31
64
rcfile : rc . data ,
32
- projectId,
33
- features : [ ] ,
34
- featureInfo : { } ,
65
+ projectId : projectId ,
66
+ features : featuresList ,
67
+ featureInfo : featureInfo ,
35
68
} ;
36
- if ( features . dataconnect ) {
37
- setup . features . push ( "dataconnect" ) ;
38
- setup . featureInfo . dataconnect = features . dataconnect ;
39
- }
40
69
await actuate ( setup , config , { } ) ;
41
70
return toContent (
42
- `The Firebase Data Connect Services has been initialized. You can now use the Firebase Data Connect Services. ` ,
71
+ `Successfully setup the project ${ projectId } with those features: ${ featuresList . join ( ", " ) } ` ,
43
72
) ;
44
73
} ,
45
74
) ;
0 commit comments