firebase-tools-with-isolate 13.9.0 → 13.15.0-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/lib/api.js +4 -2
- package/lib/apphosting/githubConnections.js +125 -37
- package/lib/apphosting/index.js +3 -8
- package/lib/auth.js +14 -15
- package/lib/bin/firebase.js +7 -5
- package/lib/commands/dataconnect-sdk-generate.js +17 -15
- package/lib/commands/dataconnect-services-list.js +2 -8
- package/lib/commands/dataconnect-sql-migrate.js +0 -1
- package/lib/commands/deploy.js +7 -1
- package/lib/commands/ext-configure.js +1 -6
- package/lib/commands/ext-dev-init.js +27 -30
- package/lib/commands/ext-dev-upload.js +4 -6
- package/lib/commands/ext-info.js +3 -5
- package/lib/commands/ext-install.js +0 -5
- package/lib/commands/ext-uninstall.js +0 -5
- package/lib/commands/ext-update.js +0 -5
- package/lib/commands/firestore-backups-schedules-create.js +11 -14
- package/lib/commands/firestore-backups-schedules-list.js +1 -1
- package/lib/commands/firestore-backups-schedules-update.js +4 -3
- package/lib/commands/firestore-databases-create.js +24 -7
- package/lib/commands/firestore-databases-restore.js +4 -4
- package/lib/commands/firestore-databases-update.js +5 -6
- package/lib/commands/functions-secrets-set.js +9 -6
- package/lib/commands/help.js +2 -0
- package/lib/commands/hosting-channel-create.js +1 -1
- package/lib/commands/hosting-channel-delete.js +1 -1
- package/lib/commands/hosting-channel-deploy.js +1 -1
- package/lib/commands/hosting-clone.js +1 -2
- package/lib/commands/index.js +9 -11
- package/lib/commands/init.js +16 -12
- package/lib/commands/login.js +1 -2
- package/lib/commands/setup-emulators-dataconnect.js +22 -3
- package/lib/config.js +5 -0
- package/lib/crashlytics/buildToolsJarHelper.js +2 -1
- package/lib/dataconnect/build.js +1 -9
- package/lib/dataconnect/client.js +67 -28
- package/lib/dataconnect/errors.js +17 -9
- package/lib/dataconnect/fileUtils.js +30 -7
- package/lib/dataconnect/filters.js +12 -1
- package/lib/dataconnect/graphqlError.js +6 -3
- package/lib/dataconnect/load.js +9 -7
- package/lib/dataconnect/names.js +21 -1
- package/lib/dataconnect/provisionCloudSql.js +37 -20
- package/lib/dataconnect/schemaMigration.js +119 -66
- package/lib/dataconnect/types.js +8 -1
- package/lib/deploy/dataconnect/deploy.js +1 -0
- package/lib/deploy/dataconnect/prepare.js +16 -2
- package/lib/deploy/dataconnect/release.js +0 -1
- package/lib/deploy/functions/build.js +10 -1
- package/lib/deploy/functions/prepare.js +1 -1
- package/lib/deploy/functions/runtimes/discovery/index.js +2 -1
- package/lib/deploy/functions/runtimes/supported/types.js +6 -0
- package/lib/emulator/adminSdkConfig.test.js +16 -0
- package/lib/emulator/constants.js +1 -0
- package/lib/emulator/controller.js +4 -9
- package/lib/emulator/dataconnectEmulator.js +181 -35
- package/lib/emulator/download.js +4 -0
- package/lib/emulator/downloadableEmulators.js +54 -28
- package/lib/emulator/eventarcEmulator.js +68 -18
- package/lib/emulator/functionsEmulator.js +89 -0
- package/lib/emulator/functionsEmulatorShared.js +4 -0
- package/lib/emulator/hub.js +1 -1
- package/lib/emulator/portUtils.js +20 -2
- package/lib/emulator/pubsubEmulator.js +1 -1
- package/lib/emulator/registry.js +1 -1
- package/lib/emulator/storage/apis/shared.js +2 -1
- package/lib/emulator/storage/persistence.js +5 -13
- package/lib/emulator/storage/rfc.js +9 -0
- package/lib/emulator/storage/rules/config.js +4 -2
- package/lib/emulator/storage/rules/runtime.js +1 -1
- package/lib/experiments.js +8 -3
- package/lib/extensions/askUserForParam.js +1 -1
- package/lib/extensions/change-log.js +2 -4
- package/lib/extensions/displayExtensionInfo.js +0 -5
- package/lib/extensions/extensionsHelper.js +5 -7
- package/lib/extensions/provisioningHelper.js +1 -1
- package/lib/extensions/updateHelper.js +1 -2
- package/lib/extensions/warnings.js +2 -7
- package/lib/firestore/api-sort.test.js +74 -0
- package/lib/firestore/api.js +8 -7
- package/lib/firestore/backupUtils.test.js +18 -0
- package/lib/firestore/pretty-print.js +21 -1
- package/lib/firestore/pretty-print.test.js +61 -0
- package/lib/firestore/util.test.js +42 -0
- package/lib/frameworks/angular/utils.js +21 -8
- package/lib/frameworks/compose/discover/mockFileSystem.js +36 -0
- package/lib/frameworks/index.js +2 -6
- package/lib/frameworks/next/utils.js +2 -9
- package/lib/frameworks/nuxt/index.js +3 -3
- package/lib/functions/events/v2.js +2 -1
- package/lib/gcp/cloudsql/cloudsqladmin.js +20 -2
- package/lib/gcp/cloudsql/connect.js +6 -6
- package/lib/gcp/devConnect.js +36 -1
- package/lib/hosting/implicitInit.js +2 -2
- package/lib/init/features/dataconnect/index.js +252 -124
- package/lib/init/features/dataconnect/sdk.js +131 -0
- package/lib/init/features/firestore/indexes.js +2 -2
- package/lib/init/features/firestore/rules.js +2 -2
- package/lib/init/features/functions/javascript.js +6 -8
- package/lib/init/features/functions/python.js +4 -6
- package/lib/init/features/functions/typescript.js +8 -10
- package/lib/init/features/hosting/github.js +43 -21
- package/lib/init/features/hosting/index.js +3 -3
- package/lib/init/features/index.js +3 -1
- package/lib/init/features/storage.js +2 -2
- package/lib/init/index.js +1 -0
- package/lib/listFiles.js +1 -1
- package/lib/management/apps.js +2 -2
- package/lib/rc.js +2 -3
- package/lib/requireAuth.js +8 -0
- package/lib/rulesDeploy.js +14 -12
- package/lib/templates.js +23 -0
- package/lib/track.js +29 -2
- package/lib/utils.js +2 -2
- package/package.json +25 -24
- package/schema/connector-yaml.json +36 -4
- package/schema/dataconnect-yaml.json +4 -0
- package/schema/firebase-config.json +2 -8
- package/templates/_gitignore +3 -0
- package/templates/init/dataconnect/connector.yaml +11 -0
- package/templates/init/dataconnect/dataconnect.yaml +2 -1
- package/templates/init/dataconnect/mutations.gql +18 -13
- package/templates/init/dataconnect/queries.gql +34 -29
- package/templates/init/dataconnect/schema.gql +1 -1
- package/lib/extensions/billingMigrationHelper.js +0 -61
|
@@ -1,113 +1,62 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.doSetup = void 0;
|
|
3
|
+
exports.actuate = exports.doSetup = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
|
+
const clc = require("colorette");
|
|
5
6
|
const prompt_1 = require("../../../prompt");
|
|
6
|
-
const fs_1 = require("fs");
|
|
7
7
|
const provisionCloudSql_1 = require("../../../dataconnect/provisionCloudSql");
|
|
8
8
|
const freeTrial_1 = require("../../../dataconnect/freeTrial");
|
|
9
9
|
const cloudsql = require("../../../gcp/cloudsql/cloudsqladmin");
|
|
10
10
|
const ensureApis_1 = require("../../../dataconnect/ensureApis");
|
|
11
11
|
const client_1 = require("../../../dataconnect/client");
|
|
12
12
|
const emulators_1 = require("../emulators");
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
13
|
+
const names_1 = require("../../../dataconnect/names");
|
|
14
|
+
const logger_1 = require("../../../logger");
|
|
15
|
+
const templates_1 = require("../../../templates");
|
|
16
|
+
const utils_1 = require("../../../utils");
|
|
17
|
+
const DATACONNECT_YAML_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/dataconnect.yaml");
|
|
18
|
+
const CONNECTOR_YAML_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/connector.yaml");
|
|
19
|
+
const SCHEMA_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/schema.gql");
|
|
20
|
+
const QUERIES_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/queries.gql");
|
|
21
|
+
const MUTATIONS_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/mutations.gql");
|
|
22
|
+
const defaultConnector = {
|
|
23
|
+
id: "default",
|
|
24
|
+
files: [
|
|
25
|
+
{
|
|
26
|
+
path: "queries.gql",
|
|
27
|
+
content: QUERIES_TEMPLATE,
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
path: "mutations.gql",
|
|
31
|
+
content: MUTATIONS_TEMPLATE,
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
};
|
|
19
35
|
async function doSetup(setup, config) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const freeTrialInstanceId = await (0, freeTrial_1.checkForFreeTrialInstance)(setup.projectId);
|
|
42
|
-
if (!freeTrialInstanceId) {
|
|
43
|
-
choices.push({ name: "Create a new instance", value: "", location: "" });
|
|
44
|
-
}
|
|
45
|
-
if (instances.length) {
|
|
46
|
-
cloudSqlInstanceId = await (0, prompt_1.promptOnce)({
|
|
47
|
-
message: `Which CloudSSQL instance would you like to use?`,
|
|
48
|
-
type: "list",
|
|
49
|
-
choices,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
locationId = choices.find((c) => c.value === cloudSqlInstanceId).location;
|
|
53
|
-
}
|
|
54
|
-
if (cloudSqlInstanceId === "") {
|
|
55
|
-
let locationOptions = [
|
|
56
|
-
{ name: "us-central1", value: "us-central1" },
|
|
57
|
-
{ name: "europe-north1", value: "europe-north1" },
|
|
58
|
-
{ name: "europe-central2", value: "europe-central2" },
|
|
59
|
-
{ name: "europe-west1", value: "europe-west1" },
|
|
60
|
-
{ name: "southamerica-west1", value: "southamerica-west1" },
|
|
61
|
-
{ name: "us-east4", value: "us-east4" },
|
|
62
|
-
{ name: "us-west1", value: "us-west1" },
|
|
63
|
-
{ name: "asia-southeast1", value: "asia-southeast1" },
|
|
64
|
-
];
|
|
65
|
-
if (setup.projectId) {
|
|
66
|
-
const locations = await (0, client_1.listLocations)(setup.projectId);
|
|
67
|
-
locationOptions = locations.map((l) => {
|
|
68
|
-
return { name: l, value: l };
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
newInstance = true;
|
|
72
|
-
cloudSqlInstanceId = await (0, prompt_1.promptOnce)({
|
|
73
|
-
message: `What ID would you like to use for your new CloudSQL instance?`,
|
|
74
|
-
type: "input",
|
|
75
|
-
default: `dataconnect-test`,
|
|
76
|
-
});
|
|
77
|
-
locationId = await (0, prompt_1.promptOnce)({
|
|
78
|
-
message: "What location would you use for this instance?",
|
|
79
|
-
type: "list",
|
|
80
|
-
choices: locationOptions,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
const dir = config.get("dataconnect.source") || "dataconnect";
|
|
84
|
-
if (!config.has("dataconnect")) {
|
|
85
|
-
config.set("dataconnect.source", dir);
|
|
86
|
-
config.set("dataconnect.location", locationId);
|
|
87
|
-
}
|
|
88
|
-
let cloudSqlDatabase = "";
|
|
89
|
-
let newDB = false;
|
|
90
|
-
if (!newInstance && setup.projectId) {
|
|
91
|
-
const dbs = await cloudsql.listDatabases(setup.projectId, cloudSqlInstanceId);
|
|
92
|
-
const choices = dbs.map((d) => {
|
|
93
|
-
return { name: d.name, value: d.name };
|
|
94
|
-
});
|
|
95
|
-
choices.push({ name: "Create a new database", value: "" });
|
|
96
|
-
if (dbs.length) {
|
|
97
|
-
cloudSqlDatabase = await (0, prompt_1.promptOnce)({
|
|
98
|
-
message: `Which database in ${cloudSqlInstanceId} would you like to use?`,
|
|
99
|
-
type: "list",
|
|
100
|
-
choices,
|
|
101
|
-
});
|
|
102
|
-
}
|
|
36
|
+
const info = await askQuestions(setup, config);
|
|
37
|
+
await actuate(setup, config, info);
|
|
38
|
+
logger_1.logger.info("");
|
|
39
|
+
(0, utils_1.logSuccess)(`If you'd like to generate an SDK for your new connector, run ${clc.bold("firebase init dataconnect:sdk")}`);
|
|
40
|
+
}
|
|
41
|
+
exports.doSetup = doSetup;
|
|
42
|
+
async function askQuestions(setup, config) {
|
|
43
|
+
let info = {
|
|
44
|
+
serviceId: "",
|
|
45
|
+
locationId: "",
|
|
46
|
+
cloudSqlInstanceId: "",
|
|
47
|
+
isNewInstance: false,
|
|
48
|
+
cloudSqlDatabase: "",
|
|
49
|
+
isNewDatabase: false,
|
|
50
|
+
connectors: [defaultConnector],
|
|
51
|
+
schemaGql: [],
|
|
52
|
+
shouldProvisionCSQL: false,
|
|
53
|
+
};
|
|
54
|
+
info = await promptForService(setup, info);
|
|
55
|
+
if (info.cloudSqlInstanceId === "") {
|
|
56
|
+
info = await promptForCloudSQLInstance(setup, info);
|
|
103
57
|
}
|
|
104
|
-
if (cloudSqlDatabase === "") {
|
|
105
|
-
|
|
106
|
-
cloudSqlDatabase = await (0, prompt_1.promptOnce)({
|
|
107
|
-
message: `What ID would you like to use for your new database in ${cloudSqlInstanceId}?`,
|
|
108
|
-
type: "input",
|
|
109
|
-
default: `dataconnect`,
|
|
110
|
-
});
|
|
58
|
+
if (info.cloudSqlDatabase === "") {
|
|
59
|
+
info = await promptForDatabase(setup, config, info);
|
|
111
60
|
}
|
|
112
61
|
const defaultConnectionString = setup.rcfile.dataconnectEmulatorConfig?.postgres?.localConnectionString ??
|
|
113
62
|
emulators_1.DEFAULT_POSTGRES_CONNECTION;
|
|
@@ -118,49 +67,228 @@ async function doSetup(setup, config) {
|
|
|
118
67
|
default: defaultConnectionString,
|
|
119
68
|
});
|
|
120
69
|
setup.rcfile.dataconnectEmulatorConfig = { postgres: { localConnectionString } };
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
cloudSqlInstanceId,
|
|
124
|
-
cloudSqlDatabase,
|
|
125
|
-
connectorId,
|
|
126
|
-
});
|
|
127
|
-
const subbedConnectorYaml = subValues(CONNECTOR_YAML_TEMPLATE, {
|
|
128
|
-
serviceId,
|
|
129
|
-
cloudSqlInstanceId,
|
|
130
|
-
cloudSqlDatabase,
|
|
131
|
-
connectorId,
|
|
132
|
-
});
|
|
133
|
-
await config.askWriteProjectFile((0, path_1.join)(dir, "dataconnect.yaml"), subbedDataconnectYaml);
|
|
134
|
-
await config.askWriteProjectFile((0, path_1.join)(dir, "connector", "connector.yaml"), subbedConnectorYaml);
|
|
135
|
-
await config.askWriteProjectFile((0, path_1.join)(dir, "schema", "schema.gql"), SCHEMA_TEMPLATE);
|
|
136
|
-
await config.askWriteProjectFile((0, path_1.join)(dir, "connector", "queries.gql"), QUERIES_TEMPLATE);
|
|
137
|
-
await config.askWriteProjectFile((0, path_1.join)(dir, "connector", "mutations.gql"), MUTATIONS_TEMPLATE);
|
|
138
|
-
if (setup.projectId &&
|
|
139
|
-
(newInstance || newDB) &&
|
|
70
|
+
info.shouldProvisionCSQL = !!(setup.projectId &&
|
|
71
|
+
(info.isNewInstance || info.isNewDatabase) &&
|
|
140
72
|
(await (0, prompt_1.confirm)({
|
|
141
73
|
message: "Would you like to provision your CloudSQL instance and database now? This will take a few minutes.",
|
|
142
74
|
default: true,
|
|
143
|
-
})))
|
|
75
|
+
})));
|
|
76
|
+
return info;
|
|
77
|
+
}
|
|
78
|
+
async function actuate(setup, config, info) {
|
|
79
|
+
await writeFiles(config, info);
|
|
80
|
+
if (setup.projectId && info.shouldProvisionCSQL) {
|
|
144
81
|
await (0, provisionCloudSql_1.provisionCloudSql)({
|
|
145
82
|
projectId: setup.projectId,
|
|
146
|
-
locationId,
|
|
147
|
-
instanceId: cloudSqlInstanceId,
|
|
148
|
-
databaseId: cloudSqlDatabase,
|
|
83
|
+
locationId: info.locationId,
|
|
84
|
+
instanceId: info.cloudSqlInstanceId,
|
|
85
|
+
databaseId: info.cloudSqlDatabase,
|
|
149
86
|
enableGoogleMlIntegration: false,
|
|
87
|
+
waitForCreation: false,
|
|
150
88
|
});
|
|
151
89
|
}
|
|
152
90
|
}
|
|
153
|
-
exports.
|
|
154
|
-
function
|
|
91
|
+
exports.actuate = actuate;
|
|
92
|
+
async function writeFiles(config, info) {
|
|
93
|
+
const dir = config.get("dataconnect.source") || "dataconnect";
|
|
94
|
+
console.log(dir);
|
|
95
|
+
const subbedDataconnectYaml = subDataconnectYamlValues({
|
|
96
|
+
...info,
|
|
97
|
+
connectorIds: info.connectors.map((c) => `"./${c.id}"`).join(", "),
|
|
98
|
+
});
|
|
99
|
+
config.set("dataconnect", { source: dir });
|
|
100
|
+
await config.askWriteProjectFile((0, path_1.join)(dir, "dataconnect.yaml"), subbedDataconnectYaml);
|
|
101
|
+
if (info.schemaGql.length) {
|
|
102
|
+
(0, utils_1.logSuccess)("The service you chose already has GQL files deployed. We'll use those instead of the default templates.");
|
|
103
|
+
for (const f of info.schemaGql) {
|
|
104
|
+
await config.askWriteProjectFile((0, path_1.join)(dir, "schema", f.path), f.content);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
await config.askWriteProjectFile((0, path_1.join)(dir, "schema", "schema.gql"), SCHEMA_TEMPLATE);
|
|
109
|
+
}
|
|
110
|
+
for (const c of info.connectors) {
|
|
111
|
+
await writeConnectorFiles(config, c);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async function writeConnectorFiles(config, connectorInfo) {
|
|
115
|
+
const subbedConnectorYaml = subConnectorYamlValues({ connectorId: connectorInfo.id });
|
|
116
|
+
const dir = config.get("dataconnect.source") || "dataconnect";
|
|
117
|
+
await config.askWriteProjectFile((0, path_1.join)(dir, connectorInfo.id, "connector.yaml"), subbedConnectorYaml);
|
|
118
|
+
for (const f of connectorInfo.files) {
|
|
119
|
+
await config.askWriteProjectFile((0, path_1.join)(dir, connectorInfo.id, f.path), f.content);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function subDataconnectYamlValues(replacementValues) {
|
|
155
123
|
const replacements = {
|
|
156
124
|
serviceId: "__serviceId__",
|
|
157
125
|
cloudSqlDatabase: "__cloudSqlDatabase__",
|
|
158
126
|
cloudSqlInstanceId: "__cloudSqlInstanceId__",
|
|
127
|
+
connectorIds: "__connectorIds__",
|
|
128
|
+
locationId: "__location__",
|
|
129
|
+
};
|
|
130
|
+
let replaced = DATACONNECT_YAML_TEMPLATE;
|
|
131
|
+
for (const [k, v] of Object.entries(replacementValues)) {
|
|
132
|
+
replaced = replaced.replace(replacements[k], v);
|
|
133
|
+
}
|
|
134
|
+
return replaced;
|
|
135
|
+
}
|
|
136
|
+
function subConnectorYamlValues(replacementValues) {
|
|
137
|
+
const replacements = {
|
|
159
138
|
connectorId: "__connectorId__",
|
|
160
139
|
};
|
|
161
|
-
let replaced =
|
|
140
|
+
let replaced = CONNECTOR_YAML_TEMPLATE;
|
|
162
141
|
for (const [k, v] of Object.entries(replacementValues)) {
|
|
163
142
|
replaced = replaced.replace(replacements[k], v);
|
|
164
143
|
}
|
|
165
144
|
return replaced;
|
|
166
145
|
}
|
|
146
|
+
async function promptForService(setup, info) {
|
|
147
|
+
if (setup.projectId) {
|
|
148
|
+
await (0, ensureApis_1.ensureApis)(setup.projectId);
|
|
149
|
+
const existingServices = await (0, client_1.listAllServices)(setup.projectId);
|
|
150
|
+
const existingServicesAndSchemas = await Promise.all(existingServices.map(async (s) => {
|
|
151
|
+
return {
|
|
152
|
+
service: s,
|
|
153
|
+
schema: await (0, client_1.getSchema)(s.name),
|
|
154
|
+
};
|
|
155
|
+
}));
|
|
156
|
+
if (existingServicesAndSchemas.length) {
|
|
157
|
+
const choices = existingServicesAndSchemas.map((s) => {
|
|
158
|
+
const serviceName = (0, names_1.parseServiceName)(s.service.name);
|
|
159
|
+
return {
|
|
160
|
+
name: `${serviceName.location}/${serviceName.serviceId}`,
|
|
161
|
+
value: s,
|
|
162
|
+
};
|
|
163
|
+
});
|
|
164
|
+
choices.push({ name: "Create a new service", value: undefined });
|
|
165
|
+
const choice = await (0, prompt_1.promptOnce)({
|
|
166
|
+
message: "Your project already has existing services. Which would you like to set up local files for?",
|
|
167
|
+
type: "list",
|
|
168
|
+
choices,
|
|
169
|
+
});
|
|
170
|
+
if (choice) {
|
|
171
|
+
const serviceName = (0, names_1.parseServiceName)(choice.service.name);
|
|
172
|
+
info.serviceId = serviceName.serviceId;
|
|
173
|
+
info.locationId = serviceName.location;
|
|
174
|
+
if (choice.schema) {
|
|
175
|
+
if (choice.schema.primaryDatasource.postgresql?.cloudSql.instance) {
|
|
176
|
+
const instanceName = (0, names_1.parseCloudSQLInstanceName)(choice.schema.primaryDatasource.postgresql?.cloudSql.instance);
|
|
177
|
+
info.cloudSqlInstanceId = instanceName.instanceId;
|
|
178
|
+
}
|
|
179
|
+
if (choice.schema.source.files) {
|
|
180
|
+
info.schemaGql = choice.schema.source.files;
|
|
181
|
+
}
|
|
182
|
+
info.cloudSqlDatabase = choice.schema.primaryDatasource.postgresql?.database ?? "";
|
|
183
|
+
const connectors = await (0, client_1.listConnectors)(choice.service.name);
|
|
184
|
+
if (connectors.length) {
|
|
185
|
+
info.connectors = connectors.map((c) => {
|
|
186
|
+
return {
|
|
187
|
+
id: c.name.split("/").pop(),
|
|
188
|
+
files: c.source.files || [],
|
|
189
|
+
};
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (info.serviceId === "") {
|
|
197
|
+
info.serviceId = await (0, prompt_1.promptOnce)({
|
|
198
|
+
message: "What ID would you like to use for this service?",
|
|
199
|
+
type: "input",
|
|
200
|
+
default: "my-service",
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
return info;
|
|
204
|
+
}
|
|
205
|
+
async function promptForCloudSQLInstance(setup, info) {
|
|
206
|
+
if (setup.projectId) {
|
|
207
|
+
const instances = await cloudsql.listInstances(setup.projectId);
|
|
208
|
+
let choices = instances.map((i) => {
|
|
209
|
+
return { name: i.name, value: i.name, location: i.region };
|
|
210
|
+
});
|
|
211
|
+
choices = choices.filter((c) => info.locationId === "" || info.locationId === c.location);
|
|
212
|
+
if (choices.length) {
|
|
213
|
+
const freeTrialInstanceId = await (0, freeTrial_1.checkForFreeTrialInstance)(setup.projectId);
|
|
214
|
+
if (!freeTrialInstanceId) {
|
|
215
|
+
choices.push({ name: "Create a new instance", value: "", location: "" });
|
|
216
|
+
}
|
|
217
|
+
info.cloudSqlInstanceId = await (0, prompt_1.promptOnce)({
|
|
218
|
+
message: `Which CloudSQL instance would you like to use?`,
|
|
219
|
+
type: "list",
|
|
220
|
+
choices,
|
|
221
|
+
});
|
|
222
|
+
if (info.cloudSqlInstanceId !== "") {
|
|
223
|
+
info.locationId = choices.find((c) => c.value === info.cloudSqlInstanceId).location;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (info.cloudSqlInstanceId === "") {
|
|
228
|
+
info.isNewInstance = true;
|
|
229
|
+
info.cloudSqlInstanceId = await (0, prompt_1.promptOnce)({
|
|
230
|
+
message: `What ID would you like to use for your new CloudSQL instance?`,
|
|
231
|
+
type: "input",
|
|
232
|
+
default: `fdc-sql`,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
if (info.locationId === "") {
|
|
236
|
+
const choices = await locationChoices(setup);
|
|
237
|
+
info.locationId = await (0, prompt_1.promptOnce)({
|
|
238
|
+
message: "What location would like to use?",
|
|
239
|
+
type: "list",
|
|
240
|
+
choices,
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
return info;
|
|
244
|
+
}
|
|
245
|
+
async function locationChoices(setup) {
|
|
246
|
+
if (setup.projectId) {
|
|
247
|
+
const locations = await (0, client_1.listLocations)(setup.projectId);
|
|
248
|
+
return locations.map((l) => {
|
|
249
|
+
return { name: l, value: l };
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
return [
|
|
254
|
+
{ name: "us-central1", value: "us-central1" },
|
|
255
|
+
{ name: "europe-north1", value: "europe-north1" },
|
|
256
|
+
{ name: "europe-central2", value: "europe-central2" },
|
|
257
|
+
{ name: "europe-west1", value: "europe-west1" },
|
|
258
|
+
{ name: "southamerica-west1", value: "southamerica-west1" },
|
|
259
|
+
{ name: "us-east4", value: "us-east4" },
|
|
260
|
+
{ name: "us-west1", value: "us-west1" },
|
|
261
|
+
{ name: "asia-southeast1", value: "asia-southeast1" },
|
|
262
|
+
];
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
async function promptForDatabase(setup, config, info) {
|
|
266
|
+
if (!info.isNewInstance && setup.projectId) {
|
|
267
|
+
try {
|
|
268
|
+
const dbs = await cloudsql.listDatabases(setup.projectId, info.cloudSqlInstanceId);
|
|
269
|
+
const choices = dbs.map((d) => {
|
|
270
|
+
return { name: d.name, value: d.name };
|
|
271
|
+
});
|
|
272
|
+
choices.push({ name: "Create a new database", value: "" });
|
|
273
|
+
if (dbs.length) {
|
|
274
|
+
info.cloudSqlDatabase = await (0, prompt_1.promptOnce)({
|
|
275
|
+
message: `Which database in ${info.cloudSqlInstanceId} would you like to use?`,
|
|
276
|
+
type: "list",
|
|
277
|
+
choices,
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
catch (err) {
|
|
282
|
+
logger_1.logger.debug(`[dataconnect] Cannot list databases during init: ${err}`);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
if (info.cloudSqlDatabase === "") {
|
|
286
|
+
info.isNewDatabase = true;
|
|
287
|
+
info.cloudSqlDatabase = await (0, prompt_1.promptOnce)({
|
|
288
|
+
message: `What ID would you like to use for your new database in ${info.cloudSqlInstanceId}?`,
|
|
289
|
+
type: "input",
|
|
290
|
+
default: `fdcdb`,
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
return info;
|
|
294
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.actuate = exports.doSetup = void 0;
|
|
4
|
+
const yaml = require("yaml");
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const clc = require("colorette");
|
|
7
|
+
const prompt_1 = require("../../../prompt");
|
|
8
|
+
const fileUtils_1 = require("../../../dataconnect/fileUtils");
|
|
9
|
+
const load_1 = require("../../../dataconnect/load");
|
|
10
|
+
const logger_1 = require("../../../logger");
|
|
11
|
+
const dataconnectEmulator_1 = require("../../../emulator/dataconnectEmulator");
|
|
12
|
+
const error_1 = require("../../../error");
|
|
13
|
+
const lodash_1 = require("lodash");
|
|
14
|
+
const IOS = "ios";
|
|
15
|
+
const WEB = "web";
|
|
16
|
+
const ANDROID = "android";
|
|
17
|
+
async function doSetup(setup, config) {
|
|
18
|
+
const sdkInfo = await askQuestions(setup, config);
|
|
19
|
+
await actuate(sdkInfo, setup.projectId);
|
|
20
|
+
}
|
|
21
|
+
exports.doSetup = doSetup;
|
|
22
|
+
async function askQuestions(setup, config) {
|
|
23
|
+
const serviceCfgs = (0, fileUtils_1.readFirebaseJson)(config);
|
|
24
|
+
const serviceInfos = await Promise.all(serviceCfgs.map((c) => (0, load_1.load)(setup.projectId || "", config, c.source)));
|
|
25
|
+
const connectorChoices = serviceInfos
|
|
26
|
+
.map((si) => {
|
|
27
|
+
return si.connectorInfo.map((ci) => {
|
|
28
|
+
return {
|
|
29
|
+
name: `${si.dataConnectYaml.serviceId}/${ci.connectorYaml.connectorId}`,
|
|
30
|
+
value: ci,
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
})
|
|
34
|
+
.flat();
|
|
35
|
+
if (!connectorChoices.length) {
|
|
36
|
+
throw new error_1.FirebaseError(`Your config has no connectors to set up SDKs for. Run ${clc.bold("firebase init dataconnect")} to set up a service and conenctors.`);
|
|
37
|
+
}
|
|
38
|
+
const connectorInfo = await (0, prompt_1.promptOnce)({
|
|
39
|
+
message: "Which connector do you want set up a generated SDK for?",
|
|
40
|
+
type: "list",
|
|
41
|
+
choices: connectorChoices,
|
|
42
|
+
});
|
|
43
|
+
let platforms = [];
|
|
44
|
+
while (!platforms.length) {
|
|
45
|
+
platforms = await (0, prompt_1.promptOnce)({
|
|
46
|
+
message: "Which platforms do you want to set up a generated SDK for?",
|
|
47
|
+
type: "checkbox",
|
|
48
|
+
choices: [
|
|
49
|
+
{ name: "iOS (Swift)", value: IOS },
|
|
50
|
+
{ name: "Web (JavaScript)", value: WEB },
|
|
51
|
+
{ name: "Androd (Kotlin)", value: ANDROID },
|
|
52
|
+
],
|
|
53
|
+
});
|
|
54
|
+
if (!platforms.length) {
|
|
55
|
+
logger_1.logger.info("You must pick at least one platform.");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const newConnectorYaml = JSON.parse(JSON.stringify(connectorInfo.connectorYaml));
|
|
59
|
+
if (!newConnectorYaml.generate) {
|
|
60
|
+
newConnectorYaml.generate = {};
|
|
61
|
+
}
|
|
62
|
+
if (platforms.includes(IOS)) {
|
|
63
|
+
const outputDir = await (0, prompt_1.promptOnce)({
|
|
64
|
+
message: `What directory do you want to write your Swift SDK code to? (If not absolute, path will be relative to '${connectorInfo.directory}')`,
|
|
65
|
+
type: "input",
|
|
66
|
+
default: newConnectorYaml.generate.swiftSdk?.outputDir ||
|
|
67
|
+
`./../gensdk/${newConnectorYaml.connectorId}/swift-sdk`,
|
|
68
|
+
});
|
|
69
|
+
const pkg = (0, lodash_1.camelCase)(newConnectorYaml.connectorId);
|
|
70
|
+
const swiftSdk = { outputDir, package: pkg };
|
|
71
|
+
newConnectorYaml.generate.swiftSdk = swiftSdk;
|
|
72
|
+
}
|
|
73
|
+
if (platforms.includes(WEB)) {
|
|
74
|
+
const outputDir = await (0, prompt_1.promptOnce)({
|
|
75
|
+
message: `What directory do you want to write your JavaScript SDK code to? (If not absolute, path will be relative to '${connectorInfo.directory}')`,
|
|
76
|
+
type: "input",
|
|
77
|
+
default: newConnectorYaml.generate.javascriptSdk?.outputDir ||
|
|
78
|
+
`./../gensdk/${newConnectorYaml.connectorId}/javascript-sdk`,
|
|
79
|
+
});
|
|
80
|
+
const pkg = newConnectorYaml.generate.javascriptSdk?.package ??
|
|
81
|
+
`@firebasegen/${connectorInfo.connectorYaml.connectorId}`;
|
|
82
|
+
const packageJSONDir = await (0, prompt_1.promptOnce)({
|
|
83
|
+
message: "Which directory contains the package.json that you would like to add the JavaScript SDK dependency to? (Leave blank to skip)",
|
|
84
|
+
type: "input",
|
|
85
|
+
default: newConnectorYaml.generate.javascriptSdk?.packageJSONDir,
|
|
86
|
+
});
|
|
87
|
+
const javascriptSdk = {
|
|
88
|
+
outputDir,
|
|
89
|
+
package: pkg,
|
|
90
|
+
};
|
|
91
|
+
if (packageJSONDir) {
|
|
92
|
+
javascriptSdk.packageJSONDir = packageJSONDir;
|
|
93
|
+
}
|
|
94
|
+
newConnectorYaml.generate.javascriptSdk = javascriptSdk;
|
|
95
|
+
}
|
|
96
|
+
if (platforms.includes(ANDROID)) {
|
|
97
|
+
const outputDir = await (0, prompt_1.promptOnce)({
|
|
98
|
+
message: `What directory do you want to write your Kotlin SDK code to? (If not absolute, path will be relative to '${connectorInfo.directory}')`,
|
|
99
|
+
type: "input",
|
|
100
|
+
default: newConnectorYaml.generate.kotlinSdk?.outputDir ||
|
|
101
|
+
`./../gensdk/${newConnectorYaml.connectorId}/kotlin-sdk`,
|
|
102
|
+
});
|
|
103
|
+
const pkg = newConnectorYaml.generate.kotlinSdk?.package ??
|
|
104
|
+
`connectors.${(0, lodash_1.snakeCase)(connectorInfo.connectorYaml.connectorId)}`;
|
|
105
|
+
const kotlinSdk = {
|
|
106
|
+
outputDir,
|
|
107
|
+
package: pkg,
|
|
108
|
+
};
|
|
109
|
+
newConnectorYaml.generate.kotlinSdk = kotlinSdk;
|
|
110
|
+
}
|
|
111
|
+
const shouldGenerate = !!(setup.projectId &&
|
|
112
|
+
(await (0, prompt_1.confirm)({
|
|
113
|
+
message: "Would you like to generate SDK code now?",
|
|
114
|
+
default: true,
|
|
115
|
+
})));
|
|
116
|
+
const connectorYamlContents = yaml.stringify(newConnectorYaml);
|
|
117
|
+
return { connectorYamlContents, connectorInfo, shouldGenerate };
|
|
118
|
+
}
|
|
119
|
+
async function actuate(sdkInfo, projectId) {
|
|
120
|
+
const connectorYamlPath = `${sdkInfo.connectorInfo.directory}/connector.yaml`;
|
|
121
|
+
fs.writeFileSync(connectorYamlPath, sdkInfo.connectorYamlContents, "utf8");
|
|
122
|
+
logger_1.logger.info(`Wrote new config to ${connectorYamlPath}`);
|
|
123
|
+
if (projectId && sdkInfo.shouldGenerate) {
|
|
124
|
+
await dataconnectEmulator_1.DataConnectEmulator.generate({
|
|
125
|
+
configDir: sdkInfo.connectorInfo.directory,
|
|
126
|
+
connectorId: sdkInfo.connectorInfo.connectorYaml.connectorId,
|
|
127
|
+
});
|
|
128
|
+
logger_1.logger.info(`Generated SDK code for ${sdkInfo.connectorInfo.connectorYaml.connectorId}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.actuate = actuate;
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.initIndexes = void 0;
|
|
4
4
|
const clc = require("colorette");
|
|
5
|
-
const fs = require("fs");
|
|
6
5
|
const error_1 = require("../../../error");
|
|
7
6
|
const api = require("../../../firestore/api");
|
|
8
7
|
const fsutils = require("../../../fsutils");
|
|
9
8
|
const prompt_1 = require("../../../prompt");
|
|
10
9
|
const logger_1 = require("../../../logger");
|
|
10
|
+
const templates_1 = require("../../../templates");
|
|
11
11
|
const indexes = new api.FirestoreApi();
|
|
12
|
-
const INDEXES_TEMPLATE =
|
|
12
|
+
const INDEXES_TEMPLATE = (0, templates_1.readTemplateSync)("init/firestore/firestore.indexes.json");
|
|
13
13
|
function initIndexes(setup, config) {
|
|
14
14
|
logger_1.logger.info();
|
|
15
15
|
logger_1.logger.info("Firestore indexes allow you to perform complex queries while");
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.initRules = void 0;
|
|
4
4
|
const clc = require("colorette");
|
|
5
|
-
const fs = require("fs");
|
|
6
5
|
const gcp = require("../../../gcp");
|
|
7
6
|
const fsutils = require("../../../fsutils");
|
|
8
7
|
const prompt_1 = require("../../../prompt");
|
|
9
8
|
const logger_1 = require("../../../logger");
|
|
10
9
|
const utils = require("../../../utils");
|
|
10
|
+
const templates_1 = require("../../../templates");
|
|
11
11
|
const DEFAULT_RULES_FILE = "firestore.rules";
|
|
12
|
-
const RULES_TEMPLATE =
|
|
12
|
+
const RULES_TEMPLATE = (0, templates_1.readTemplateSync)("init/firestore/firestore.rules");
|
|
13
13
|
function initRules(setup, config) {
|
|
14
14
|
logger_1.logger.info();
|
|
15
15
|
logger_1.logger.info("Firestore Security Rules allow you to define how and when to allow");
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setup = void 0;
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const path = require("path");
|
|
6
4
|
const npm_dependencies_1 = require("./npm-dependencies");
|
|
7
5
|
const prompt_1 = require("../../../prompt");
|
|
8
6
|
const projectConfig_1 = require("../../../functions/projectConfig");
|
|
9
|
-
const
|
|
10
|
-
const INDEX_TEMPLATE =
|
|
11
|
-
const PACKAGE_LINTING_TEMPLATE =
|
|
12
|
-
const PACKAGE_NO_LINTING_TEMPLATE =
|
|
13
|
-
const ESLINT_TEMPLATE =
|
|
14
|
-
const GITIGNORE_TEMPLATE =
|
|
7
|
+
const templates_1 = require("../../../templates");
|
|
8
|
+
const INDEX_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/javascript/index.js");
|
|
9
|
+
const PACKAGE_LINTING_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/javascript/package.lint.json");
|
|
10
|
+
const PACKAGE_NO_LINTING_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/javascript/package.nolint.json");
|
|
11
|
+
const ESLINT_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/javascript/_eslintrc");
|
|
12
|
+
const GITIGNORE_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/javascript/_gitignore");
|
|
15
13
|
function setup(setup, config) {
|
|
16
14
|
return (0, prompt_1.prompt)(setup.functions, [
|
|
17
15
|
{
|
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setup = void 0;
|
|
4
|
-
const fs = require("fs");
|
|
5
4
|
const spawn = require("cross-spawn");
|
|
6
|
-
const path = require("path");
|
|
7
5
|
const python_1 = require("../../../deploy/functions/runtimes/python");
|
|
8
6
|
const python_2 = require("../../../functions/python");
|
|
9
7
|
const prompt_1 = require("../../../prompt");
|
|
10
8
|
const supported_1 = require("../../../deploy/functions/runtimes/supported");
|
|
11
|
-
const
|
|
12
|
-
const MAIN_TEMPLATE =
|
|
13
|
-
const REQUIREMENTS_TEMPLATE =
|
|
14
|
-
const GITIGNORE_TEMPLATE =
|
|
9
|
+
const templates_1 = require("../../../templates");
|
|
10
|
+
const MAIN_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/python/main.py");
|
|
11
|
+
const REQUIREMENTS_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/python/requirements.txt");
|
|
12
|
+
const GITIGNORE_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/python/_gitignore");
|
|
15
13
|
async function setup(setup, config) {
|
|
16
14
|
await config.askWriteProjectFile(`${setup.functions.source}/requirements.txt`, REQUIREMENTS_TEMPLATE);
|
|
17
15
|
await config.askWriteProjectFile(`${setup.functions.source}/.gitignore`, GITIGNORE_TEMPLATE);
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setup = void 0;
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const path = require("path");
|
|
6
4
|
const npm_dependencies_1 = require("./npm-dependencies");
|
|
7
5
|
const prompt_1 = require("../../../prompt");
|
|
8
6
|
const projectConfig_1 = require("../../../functions/projectConfig");
|
|
9
|
-
const
|
|
10
|
-
const PACKAGE_LINTING_TEMPLATE =
|
|
11
|
-
const PACKAGE_NO_LINTING_TEMPLATE =
|
|
12
|
-
const ESLINT_TEMPLATE =
|
|
13
|
-
const TSCONFIG_TEMPLATE =
|
|
14
|
-
const TSCONFIG_DEV_TEMPLATE =
|
|
15
|
-
const INDEX_TEMPLATE =
|
|
16
|
-
const GITIGNORE_TEMPLATE =
|
|
7
|
+
const templates_1 = require("../../../templates");
|
|
8
|
+
const PACKAGE_LINTING_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/typescript/package.lint.json");
|
|
9
|
+
const PACKAGE_NO_LINTING_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/typescript/package.nolint.json");
|
|
10
|
+
const ESLINT_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/typescript/_eslintrc");
|
|
11
|
+
const TSCONFIG_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/typescript/tsconfig.json");
|
|
12
|
+
const TSCONFIG_DEV_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/typescript/tsconfig.dev.json");
|
|
13
|
+
const INDEX_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/typescript/index.ts");
|
|
14
|
+
const GITIGNORE_TEMPLATE = (0, templates_1.readTemplateSync)("init/functions/typescript/_gitignore");
|
|
17
15
|
function setup(setup, config) {
|
|
18
16
|
return (0, prompt_1.prompt)(setup.functions, [
|
|
19
17
|
{
|