firebase-tools-with-isolate 14.10.1 → 14.16.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 +5 -1
- package/lib/apphosting/backend.js +40 -15
- package/lib/apptesting/ensureProjectConfigured.js +56 -0
- package/lib/apptesting/invokeTests.js +40 -0
- package/lib/apptesting/parseTestFiles.js +75 -0
- package/lib/apptesting/types.js +18 -0
- package/lib/auth.js +37 -2
- package/lib/command.js +24 -5
- package/lib/commands/apphosting-backends-create.js +8 -5
- package/lib/commands/apptesting-execute.js +101 -0
- package/lib/commands/dataconnect-sdk-generate.js +28 -26
- package/lib/commands/dataconnect-services-list.js +1 -1
- package/lib/commands/dataconnect-sql-diff.js +2 -2
- package/lib/commands/dataconnect-sql-grant.js +7 -2
- package/lib/commands/dataconnect-sql-migrate.js +2 -2
- package/lib/commands/dataconnect-sql-setup.js +3 -5
- package/lib/commands/dataconnect-sql-shell.js +2 -2
- package/lib/commands/ext-export.js +1 -1
- package/lib/commands/firestore-bulkdelete.js +73 -0
- package/lib/commands/firestore-databases-create.js +11 -0
- package/lib/commands/firestore-operations-cancel.js +44 -0
- package/lib/commands/firestore-operations-describe.js +29 -0
- package/lib/commands/firestore-operations-list.js +29 -0
- package/lib/commands/firestore-utils.js +15 -0
- package/lib/commands/functions-config-clone.js +2 -0
- package/lib/commands/functions-config-export.js +5 -2
- package/lib/commands/functions-config-get.js +2 -0
- package/lib/commands/functions-config-set.js +2 -0
- package/lib/commands/functions-config-unset.js +2 -0
- package/lib/commands/index.js +9 -0
- package/lib/commands/init.js +24 -4
- package/lib/commands/internaltesting-functions-discover.js +20 -5
- package/lib/commands/login.js +13 -9
- package/lib/commands/use.js +5 -0
- package/lib/config.js +16 -4
- package/lib/crashlytics/addNote.js +27 -0
- package/lib/crashlytics/buildToolsJarHelper.js +1 -2
- package/lib/crashlytics/deleteNote.js +23 -0
- package/lib/crashlytics/getIssueDetails.js +26 -0
- package/lib/crashlytics/getSampleCrash.js +34 -0
- package/lib/crashlytics/listNotes.js +29 -0
- package/lib/crashlytics/listTopDevices.js +33 -0
- package/lib/crashlytics/listTopIssues.js +8 -23
- package/lib/crashlytics/listTopOperatingSystems.js +32 -0
- package/lib/crashlytics/listTopVersions.js +32 -0
- package/lib/crashlytics/updateIssue.js +35 -0
- package/lib/crashlytics/utils.js +38 -0
- package/lib/dataconnect/appFinder.js +102 -0
- package/lib/dataconnect/client.js +23 -15
- package/lib/dataconnect/ensureApis.js +6 -9
- package/lib/dataconnect/errors.js +7 -1
- package/lib/dataconnect/freeTrial.js +16 -38
- package/lib/dataconnect/load.js +105 -6
- package/lib/dataconnect/provisionCloudSql.js +67 -70
- package/lib/dataconnect/schemaMigration.js +219 -169
- package/lib/deploy/dataconnect/deploy.js +7 -9
- package/lib/deploy/dataconnect/prepare.js +7 -12
- package/lib/deploy/dataconnect/release.js +43 -31
- package/lib/deploy/firestore/deploy.js +10 -0
- package/lib/deploy/functions/backend.js +7 -1
- package/lib/deploy/functions/build.js +28 -14
- package/lib/deploy/functions/deploy.js +3 -2
- package/lib/deploy/functions/ensure.js +1 -1
- package/lib/deploy/functions/functionsDeployHelper.js +8 -1
- package/lib/deploy/functions/params.js +4 -0
- package/lib/deploy/functions/prepare.js +25 -13
- package/lib/deploy/functions/pricing.js +12 -5
- package/lib/deploy/functions/release/fabricator.js +25 -3
- package/lib/deploy/functions/release/reporter.js +1 -0
- package/lib/deploy/functions/runtimes/discovery/index.js +52 -5
- package/lib/deploy/functions/runtimes/node/index.js +83 -51
- package/lib/emulator/auth/operations.js +10 -1
- package/lib/emulator/commandUtils.js +7 -1
- package/lib/emulator/controller.js +22 -34
- package/lib/emulator/dataconnectEmulator.js +27 -24
- package/lib/emulator/downloadableEmulatorInfo.json +18 -18
- package/lib/emulator/env.js +2 -1
- package/lib/emulator/functionsEmulator.js +12 -2
- package/lib/emulator/hub.js +11 -8
- package/lib/emulator/tasksEmulator.js +1 -1
- package/lib/emulator/ui.js +3 -1
- package/lib/env.js +18 -0
- package/lib/experiments.js +20 -0
- package/lib/extensions/extensionsHelper.js +4 -15
- package/lib/extensions/runtimes/common.js +3 -2
- package/lib/extensions/utils.js +1 -12
- package/lib/firestore/api-sort.js +96 -3
- package/lib/firestore/api-types.js +20 -1
- package/lib/firestore/api.js +144 -15
- package/lib/firestore/pretty-print.js +35 -1
- package/lib/firestore/validator.js +1 -1
- package/lib/functional.js +7 -1
- package/lib/functions/deprecationWarnings.js +21 -0
- package/lib/functions/env.js +31 -16
- package/lib/functions/projectConfig.js +87 -8
- package/lib/functions/secrets.js +3 -0
- package/lib/gcp/cloudfunctions.js +1 -6
- package/lib/gcp/cloudfunctionsv2.js +3 -39
- package/lib/gcp/cloudscheduler.js +1 -1
- package/lib/gcp/cloudsql/cloudsqladmin.js +4 -16
- package/lib/gcp/cloudsql/connect.js +4 -3
- package/lib/gcp/cloudsql/permissionsSetup.js +23 -16
- package/lib/gcp/k8s.js +32 -0
- package/lib/gcp/runv2.js +181 -0
- package/lib/gemini/fdcExperience.js +5 -3
- package/lib/init/features/aitools/claude.js +43 -0
- package/lib/init/features/aitools/cursor.js +61 -0
- package/lib/init/features/aitools/gemini.js +58 -0
- package/lib/init/features/aitools/index.js +28 -0
- package/lib/init/features/aitools/promptUpdater.js +111 -0
- package/lib/init/features/aitools/studio.js +17 -0
- package/lib/init/features/aitools/types.js +2 -0
- package/lib/init/features/aitools.js +83 -0
- package/lib/init/features/apptesting/index.js +34 -0
- package/lib/init/features/dataconnect/create_app.js +53 -0
- package/lib/init/features/dataconnect/index.js +280 -186
- package/lib/init/features/dataconnect/sdk.js +232 -144
- package/lib/init/features/index.js +8 -3
- package/lib/init/features/project.js +4 -0
- package/lib/init/index.js +18 -2
- package/lib/management/apps.js +3 -3
- package/lib/management/studio.js +120 -0
- package/lib/mcp/errors.js +5 -7
- package/lib/mcp/index.js +179 -61
- package/lib/mcp/logging-transport.js +23 -0
- package/lib/mcp/prompt.js +10 -0
- package/lib/mcp/prompts/core/deploy.js +101 -0
- package/lib/mcp/prompts/core/index.js +5 -0
- package/lib/mcp/prompts/crashlytics/connect.js +114 -0
- package/lib/mcp/prompts/crashlytics/index.js +5 -0
- package/lib/mcp/prompts/dataconnect/index.js +9 -0
- package/lib/mcp/prompts/dataconnect/schema.js +67 -0
- package/lib/mcp/prompts/index.js +47 -0
- package/lib/mcp/tools/apphosting/fetch_logs.js +22 -22
- package/lib/mcp/tools/apphosting/list_backends.js +10 -10
- package/lib/mcp/tools/auth/disable_user.js +7 -7
- package/lib/mcp/tools/auth/get_user.js +13 -6
- package/lib/mcp/tools/auth/index.js +10 -10
- package/lib/mcp/tools/auth/list_users.js +6 -6
- package/lib/mcp/tools/auth/set_claims.js +7 -7
- package/lib/mcp/tools/auth/set_sms_region_policy.js +6 -6
- package/lib/mcp/tools/core/consult_assistant.js +13 -8
- package/lib/mcp/tools/core/create_android_sha.js +9 -9
- package/lib/mcp/tools/core/create_app.js +7 -7
- package/lib/mcp/tools/core/create_project.js +13 -13
- package/lib/mcp/tools/core/get_admin_sdk_config.js +7 -7
- package/lib/mcp/tools/core/get_environment.js +8 -8
- package/lib/mcp/tools/core/get_project.js +5 -5
- package/lib/mcp/tools/core/get_sdk_config.js +19 -9
- package/lib/mcp/tools/core/index.js +28 -24
- package/lib/mcp/tools/core/init.js +39 -16
- package/lib/mcp/tools/core/list_apps.js +6 -6
- package/lib/mcp/tools/core/list_projects.js +6 -6
- package/lib/mcp/tools/core/login.js +46 -0
- package/lib/mcp/tools/core/logout.js +62 -0
- package/lib/mcp/tools/core/update_environment.js +10 -10
- package/lib/mcp/tools/crashlytics/add_note.js +32 -0
- package/lib/mcp/tools/crashlytics/constants.js +11 -0
- package/lib/mcp/tools/crashlytics/delete_note.js +35 -0
- package/lib/mcp/tools/crashlytics/get_issue_details.js +31 -0
- package/lib/mcp/tools/crashlytics/get_sample_crash.js +43 -0
- package/lib/mcp/tools/crashlytics/index.js +22 -2
- package/lib/mcp/tools/crashlytics/list_notes.js +37 -0
- package/lib/mcp/tools/crashlytics/list_top_devices.js +33 -0
- package/lib/mcp/tools/crashlytics/list_top_issues.js +12 -13
- package/lib/mcp/tools/crashlytics/list_top_operating_systems.js +33 -0
- package/lib/mcp/tools/crashlytics/list_top_versions.js +33 -0
- package/lib/mcp/tools/crashlytics/update_issue.js +37 -0
- package/lib/mcp/tools/database/get_data.js +49 -0
- package/lib/mcp/tools/database/get_rules.js +39 -0
- package/lib/mcp/tools/database/index.js +8 -0
- package/lib/mcp/tools/database/set_data.js +57 -0
- package/lib/mcp/tools/database/validate_rules.js +41 -0
- package/lib/mcp/tools/dataconnect/compile.js +43 -0
- package/lib/mcp/tools/dataconnect/execute.js +71 -0
- package/lib/mcp/tools/dataconnect/generate_operation.js +8 -8
- package/lib/mcp/tools/dataconnect/generate_schema.js +6 -6
- package/lib/mcp/tools/dataconnect/index.js +10 -18
- package/lib/mcp/tools/dataconnect/list_services.js +107 -11
- package/lib/mcp/tools/firestore/delete_document.js +13 -13
- package/lib/mcp/tools/firestore/get_documents.js +13 -13
- package/lib/mcp/tools/firestore/list_collections.js +7 -10
- package/lib/mcp/tools/firestore/query_collection.js +13 -13
- package/lib/mcp/tools/index.js +24 -18
- package/lib/mcp/tools/messaging/index.js +2 -2
- package/lib/mcp/tools/messaging/send_message.js +7 -7
- package/lib/mcp/tools/remoteconfig/get_template.js +5 -5
- package/lib/mcp/tools/remoteconfig/index.js +4 -4
- package/lib/mcp/tools/remoteconfig/publish_template.js +7 -7
- package/lib/mcp/tools/remoteconfig/rollback_template.js +6 -6
- package/lib/mcp/tools/rules/get_rules.js +8 -8
- package/lib/mcp/tools/rules/validate_rules.js +10 -10
- package/lib/mcp/tools/storage/get_download_url.js +8 -8
- package/lib/mcp/tools/storage/get_rules.js +8 -8
- package/lib/mcp/types.js +2 -0
- package/lib/mcp/util/dataconnect/compile.js +20 -0
- package/lib/mcp/util/dataconnect/content.js +655 -0
- package/lib/mcp/util/dataconnect/emulator.js +16 -0
- package/lib/mcp/util.js +5 -18
- package/lib/requireAuth.js +14 -4
- package/lib/rtdb.js +10 -6
- package/lib/scopes.js +2 -1
- package/lib/serve/functions.js +4 -3
- package/lib/timeout.js +21 -0
- package/lib/track.js +18 -1
- package/lib/unzip.js +13 -0
- package/lib/utils.js +76 -2
- package/package.json +6 -4
- package/prompts/FIREBASE.md +121 -0
- package/prompts/FIREBASE_FUNCTIONS.md +221 -0
- package/schema/apptesting-yaml.json +64 -0
- package/schema/firebase-config.json +163 -53
- package/templates/init/aitools/cursor-rules-header.txt +8 -0
- package/templates/init/aitools/gemini-extension.json +11 -0
- package/templates/init/apptesting/smoke_test.yaml +6 -0
- package/templates/init/dataconnect/connector.yaml +0 -16
- package/templates/init/dataconnect/dataconnect.yaml +2 -1
- package/templates/init/dataconnect/mutations.gql +29 -29
- package/templates/init/dataconnect/queries.gql +73 -73
- package/templates/init/dataconnect/schema.gql +48 -48
- package/templates/init/firestore/firestore.indexes.json +26 -1
- package/lib/dataconnect/fileUtils.js +0 -168
- package/lib/emulator/adminSdkConfig.test.js +0 -16
- package/lib/extensions/resolveSource.js +0 -23
- package/lib/firestore/api-sort.test.js +0 -74
- package/lib/firestore/backupUtils.test.js +0 -18
- package/lib/firestore/pretty-print.test.js +0 -61
- package/lib/firestore/util.test.js +0 -42
- package/lib/mcp/tools/dataconnect/emulator.js +0 -16
- package/lib/mcp/tools/dataconnect/execute_graphql.js +0 -48
- package/lib/mcp/tools/dataconnect/execute_graphql_read.js +0 -48
- package/lib/mcp/tools/dataconnect/execute_mutation.js +0 -62
- package/lib/mcp/tools/dataconnect/execute_query.js +0 -62
- package/lib/mcp/tools/dataconnect/get_connector.js +0 -31
- package/lib/mcp/tools/dataconnect/get_schema.js +0 -31
- /package/lib/mcp/{tools → util}/dataconnect/converter.js +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.newUniqueId = exports.toDNSCompatibleId = exports.actuate = exports.askQuestions = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const clc = require("colorette");
|
|
6
6
|
const fs = require("fs-extra");
|
|
@@ -15,76 +15,69 @@ const names_1 = require("../../../dataconnect/names");
|
|
|
15
15
|
const logger_1 = require("../../../logger");
|
|
16
16
|
const templates_1 = require("../../../templates");
|
|
17
17
|
const utils_1 = require("../../../utils");
|
|
18
|
+
Object.defineProperty(exports, "newUniqueId", { enumerable: true, get: function () { return utils_1.newUniqueId; } });
|
|
18
19
|
const cloudbilling_1 = require("../../../gcp/cloudbilling");
|
|
19
20
|
const sdk = require("./sdk");
|
|
20
|
-
const fileUtils_1 = require("../../../dataconnect/fileUtils");
|
|
21
21
|
const fdcExperience_1 = require("../../../gemini/fdcExperience");
|
|
22
22
|
const configstore_1 = require("../../../configstore");
|
|
23
|
+
const track_1 = require("../../../track");
|
|
23
24
|
const DATACONNECT_YAML_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/dataconnect.yaml");
|
|
24
25
|
const CONNECTOR_YAML_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/connector.yaml");
|
|
25
26
|
const SCHEMA_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/schema.gql");
|
|
26
27
|
const QUERIES_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/queries.gql");
|
|
27
28
|
const MUTATIONS_TEMPLATE = (0, templates_1.readTemplateSync)("init/dataconnect/mutations.gql");
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
files: [],
|
|
32
|
-
};
|
|
33
|
-
const defaultConnector = {
|
|
34
|
-
id: "default",
|
|
35
|
-
path: "./connector",
|
|
36
|
-
files: [
|
|
37
|
-
{
|
|
38
|
-
path: "queries.gql",
|
|
39
|
-
content: QUERIES_TEMPLATE,
|
|
40
|
-
},
|
|
29
|
+
const templateServiceInfo = {
|
|
30
|
+
schemaGql: [{ path: "schema.gql", content: SCHEMA_TEMPLATE }],
|
|
31
|
+
connectors: [
|
|
41
32
|
{
|
|
42
|
-
|
|
43
|
-
|
|
33
|
+
id: "example",
|
|
34
|
+
path: "./example",
|
|
35
|
+
files: [
|
|
36
|
+
{
|
|
37
|
+
path: "queries.gql",
|
|
38
|
+
content: QUERIES_TEMPLATE,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
path: "mutations.gql",
|
|
42
|
+
content: MUTATIONS_TEMPLATE,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
44
45
|
},
|
|
45
46
|
],
|
|
46
47
|
};
|
|
47
|
-
const defaultSchema = { path: "schema.gql", content: SCHEMA_TEMPLATE };
|
|
48
48
|
async function askQuestions(setup) {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
let info = {
|
|
49
|
+
const info = {
|
|
50
|
+
analyticsFlow: "cli",
|
|
51
|
+
appDescription: "",
|
|
54
52
|
serviceId: "",
|
|
55
53
|
locationId: "",
|
|
56
54
|
cloudSqlInstanceId: "",
|
|
57
|
-
isNewInstance: false,
|
|
58
55
|
cloudSqlDatabase: "",
|
|
59
|
-
isNewDatabase: false,
|
|
60
|
-
connectors: [],
|
|
61
|
-
schemaGql: [],
|
|
62
56
|
shouldProvisionCSQL: false,
|
|
63
57
|
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
info.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
default: true,
|
|
84
|
-
})));
|
|
58
|
+
if (setup.projectId) {
|
|
59
|
+
const hasBilling = await (0, cloudbilling_1.isBillingEnabled)(setup);
|
|
60
|
+
await (0, ensureApis_1.ensureApis)(setup.projectId);
|
|
61
|
+
await promptForExistingServices(setup, info);
|
|
62
|
+
if (!info.serviceGql) {
|
|
63
|
+
if (!configstore_1.configstore.get("gemini")) {
|
|
64
|
+
(0, utils_1.logBullet)("Learn more about Gemini in Firebase and how it uses your data: https://firebase.google.com/docs/gemini-in-firebase#how-gemini-in-firebase-uses-your-data");
|
|
65
|
+
}
|
|
66
|
+
info.appDescription = await (0, prompt_1.input)({
|
|
67
|
+
message: `Describe your app to automatically generate a schema with Gemini [Enter to skip]:`,
|
|
68
|
+
});
|
|
69
|
+
if (info.appDescription) {
|
|
70
|
+
configstore_1.configstore.set("gemini", true);
|
|
71
|
+
await (0, ensureApis_1.ensureGIFApis)(setup.projectId);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (hasBilling) {
|
|
75
|
+
await promptForCloudSQL(setup, info);
|
|
76
|
+
}
|
|
85
77
|
}
|
|
86
78
|
setup.featureInfo = setup.featureInfo || {};
|
|
87
79
|
setup.featureInfo.dataconnect = info;
|
|
80
|
+
await sdk.askQuestions(setup);
|
|
88
81
|
}
|
|
89
82
|
exports.askQuestions = askQuestions;
|
|
90
83
|
async function actuate(setup, config, options) {
|
|
@@ -95,68 +88,182 @@ async function actuate(setup, config, options) {
|
|
|
95
88
|
if (!info) {
|
|
96
89
|
throw new Error("Data Connect feature RequiredInfo is not provided");
|
|
97
90
|
}
|
|
98
|
-
|
|
99
|
-
info.
|
|
100
|
-
info.cloudSqlInstanceId =
|
|
101
|
-
info.cloudSqlInstanceId || `${info.serviceId.toLowerCase() || "app"}-fdc`;
|
|
91
|
+
info.serviceId = info.serviceId || defaultServiceId();
|
|
92
|
+
info.cloudSqlInstanceId = info.cloudSqlInstanceId || `${info.serviceId.toLowerCase()}-fdc`;
|
|
102
93
|
info.locationId = info.locationId || `us-central1`;
|
|
103
94
|
info.cloudSqlDatabase = info.cloudSqlDatabase || `fdcdb`;
|
|
104
|
-
|
|
105
|
-
info
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
95
|
+
try {
|
|
96
|
+
await actuateWithInfo(setup, config, info, options);
|
|
97
|
+
await sdk.actuate(setup, config);
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
void (0, track_1.trackGA4)("dataconnect_init", {
|
|
101
|
+
project_status: setup.projectId ? (setup.isBillingEnabled ? "blaze" : "spark") : "missing",
|
|
102
|
+
flow: info.analyticsFlow,
|
|
103
|
+
provision_cloud_sql: String(info.shouldProvisionCSQL),
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
if (info.appDescription) {
|
|
107
|
+
setup.instructions.push(`You can visualize the Data Connect Schema in Firebase Console:
|
|
108
|
+
|
|
109
|
+
https://console.firebase.google.com/project/${setup.projectId}/dataconnect/locations/${info.locationId}/services/${info.serviceId}/schema`);
|
|
110
|
+
}
|
|
111
|
+
if (!setup.isBillingEnabled) {
|
|
112
|
+
setup.instructions.push((0, freeTrial_1.upgradeInstructions)(setup.projectId || "your-firebase-project"));
|
|
113
|
+
}
|
|
114
|
+
setup.instructions.push(`Install the Data Connect VS Code Extensions. You can explore Data Connect Query on local pgLite and Cloud SQL Postgres Instance.`);
|
|
115
|
+
}
|
|
116
|
+
exports.actuate = actuate;
|
|
117
|
+
async function actuateWithInfo(setup, config, info, options) {
|
|
118
|
+
const projectId = setup.projectId;
|
|
119
|
+
if (!projectId) {
|
|
120
|
+
info.analyticsFlow += "_save_template";
|
|
121
|
+
return await writeFiles(config, info, templateServiceInfo, options);
|
|
122
|
+
}
|
|
123
|
+
await (0, ensureApis_1.ensureApis)(projectId, true);
|
|
124
|
+
const provisionCSQL = info.shouldProvisionCSQL && (await (0, cloudbilling_1.isBillingEnabled)(setup));
|
|
125
|
+
if (provisionCSQL) {
|
|
126
|
+
await (0, provisionCloudSql_1.setupCloudSql)({
|
|
127
|
+
projectId: projectId,
|
|
112
128
|
location: info.locationId,
|
|
113
129
|
instanceId: info.cloudSqlInstanceId,
|
|
114
130
|
databaseId: info.cloudSqlDatabase,
|
|
115
|
-
|
|
116
|
-
waitForCreation: false,
|
|
131
|
+
requireGoogleMlIntegration: false,
|
|
117
132
|
});
|
|
118
133
|
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
134
|
+
const serviceName = `projects/${projectId}/locations/${info.locationId}/services/${info.serviceId}`;
|
|
135
|
+
if (!info.appDescription) {
|
|
136
|
+
if (!info.serviceGql) {
|
|
137
|
+
await downloadService(info, serviceName);
|
|
138
|
+
}
|
|
139
|
+
if (info.serviceGql) {
|
|
140
|
+
info.analyticsFlow += "_save_downloaded";
|
|
141
|
+
return await writeFiles(config, info, info.serviceGql, options);
|
|
142
|
+
}
|
|
143
|
+
info.analyticsFlow += "_save_template";
|
|
144
|
+
return await writeFiles(config, info, templateServiceInfo, options);
|
|
125
145
|
}
|
|
126
|
-
|
|
127
|
-
|
|
146
|
+
const serviceAlreadyExists = !(await (0, client_1.createService)(projectId, info.locationId, info.serviceId));
|
|
147
|
+
const schemaGql = await (0, utils_1.promiseWithSpinner)(() => (0, fdcExperience_1.generateSchema)(info.appDescription, projectId), "Generating the Data Connect Schema...");
|
|
148
|
+
const schemaFiles = [{ path: "schema.gql", content: schemaGql }];
|
|
149
|
+
if (serviceAlreadyExists) {
|
|
150
|
+
(0, utils_1.logLabeledError)("dataconnect", `Data Connect Service ${serviceName} already exists. Skip saving them...`);
|
|
151
|
+
info.analyticsFlow += "_save_gemini_service_already_exists";
|
|
152
|
+
return await writeFiles(config, info, { schemaGql: schemaFiles, connectors: [] }, options);
|
|
153
|
+
}
|
|
154
|
+
await (0, utils_1.promiseWithSpinner)(async () => {
|
|
155
|
+
const [saveSchemaGql, waitForCloudSQLProvision] = schemasDeploySequence(projectId, info, schemaFiles, provisionCSQL);
|
|
156
|
+
await (0, client_1.upsertSchema)(saveSchemaGql);
|
|
157
|
+
if (waitForCloudSQLProvision) {
|
|
158
|
+
void (0, client_1.upsertSchema)(waitForCloudSQLProvision);
|
|
159
|
+
}
|
|
160
|
+
}, "Saving the Data Connect Schema...");
|
|
161
|
+
try {
|
|
162
|
+
const [operationGql, seedDataGql] = await (0, utils_1.promiseWithSpinner)(() => Promise.all([
|
|
163
|
+
(0, fdcExperience_1.generateOperation)(fdcExperience_1.PROMPT_GENERATE_CONNECTOR, serviceName, projectId),
|
|
164
|
+
(0, fdcExperience_1.generateOperation)(fdcExperience_1.PROMPT_GENERATE_SEED_DATA, serviceName, projectId),
|
|
165
|
+
]), "Generating the Data Connect Operations...");
|
|
166
|
+
const connectors = [
|
|
167
|
+
{
|
|
168
|
+
id: "example",
|
|
169
|
+
path: "./example",
|
|
170
|
+
files: [
|
|
171
|
+
{
|
|
172
|
+
path: "queries.gql",
|
|
173
|
+
content: operationGql,
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
},
|
|
177
|
+
];
|
|
178
|
+
info.analyticsFlow += "_save_gemini";
|
|
179
|
+
await writeFiles(config, info, { schemaGql: schemaFiles, connectors: connectors, seedDataGql: seedDataGql }, options);
|
|
180
|
+
}
|
|
181
|
+
catch (err) {
|
|
182
|
+
(0, utils_1.logLabeledError)("dataconnect", `Operation Generation failed...`);
|
|
183
|
+
info.analyticsFlow += "_save_gemini_operation_error";
|
|
184
|
+
await writeFiles(config, info, { schemaGql: schemaFiles, connectors: [] }, options);
|
|
185
|
+
throw err;
|
|
128
186
|
}
|
|
129
|
-
|
|
130
|
-
|
|
187
|
+
}
|
|
188
|
+
function schemasDeploySequence(projectId, info, schemaFiles, linkToCloudSql) {
|
|
189
|
+
const serviceName = `projects/${projectId}/locations/${info.locationId}/services/${info.serviceId}`;
|
|
190
|
+
if (!linkToCloudSql) {
|
|
191
|
+
return [
|
|
192
|
+
{
|
|
193
|
+
name: `${serviceName}/schemas/${types_1.SCHEMA_ID}`,
|
|
194
|
+
datasources: [{ postgresql: {} }],
|
|
195
|
+
source: {
|
|
196
|
+
files: schemaFiles,
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
];
|
|
131
200
|
}
|
|
201
|
+
return [
|
|
202
|
+
{
|
|
203
|
+
name: `${serviceName}/schemas/${types_1.SCHEMA_ID}`,
|
|
204
|
+
datasources: [
|
|
205
|
+
{
|
|
206
|
+
postgresql: {
|
|
207
|
+
database: info.cloudSqlDatabase,
|
|
208
|
+
cloudSql: {
|
|
209
|
+
instance: `projects/${projectId}/locations/${info.locationId}/instances/${info.cloudSqlInstanceId}`,
|
|
210
|
+
},
|
|
211
|
+
schemaValidation: "NONE",
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
source: {
|
|
216
|
+
files: schemaFiles,
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
name: `${serviceName}/schemas/${types_1.SCHEMA_ID}`,
|
|
221
|
+
datasources: [
|
|
222
|
+
{
|
|
223
|
+
postgresql: {
|
|
224
|
+
database: info.cloudSqlDatabase,
|
|
225
|
+
cloudSql: {
|
|
226
|
+
instance: `projects/${projectId}/locations/${info.locationId}/instances/${info.cloudSqlInstanceId}`,
|
|
227
|
+
},
|
|
228
|
+
schemaMigration: "MIGRATE_COMPATIBLE",
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
],
|
|
232
|
+
source: {
|
|
233
|
+
files: schemaFiles,
|
|
234
|
+
},
|
|
235
|
+
},
|
|
236
|
+
];
|
|
132
237
|
}
|
|
133
|
-
|
|
134
|
-
async function writeFiles(config, info, options) {
|
|
238
|
+
async function writeFiles(config, info, serviceGql, options) {
|
|
135
239
|
const dir = config.get("dataconnect.source") || "dataconnect";
|
|
136
240
|
const subbedDataconnectYaml = subDataconnectYamlValues({
|
|
137
241
|
...info,
|
|
138
|
-
connectorDirs:
|
|
242
|
+
connectorDirs: serviceGql.connectors.map((c) => c.path),
|
|
139
243
|
});
|
|
140
244
|
config.set("dataconnect", { source: dir });
|
|
141
245
|
await config.askWriteProjectFile((0, path_1.join)(dir, "dataconnect.yaml"), subbedDataconnectYaml, !!options.force, true);
|
|
142
|
-
if (
|
|
143
|
-
|
|
246
|
+
if (serviceGql.seedDataGql) {
|
|
247
|
+
await config.askWriteProjectFile((0, path_1.join)(dir, "seed_data.gql"), serviceGql.seedDataGql, !!options.force);
|
|
248
|
+
}
|
|
249
|
+
if (serviceGql.schemaGql.length) {
|
|
250
|
+
for (const f of serviceGql.schemaGql) {
|
|
144
251
|
await config.askWriteProjectFile((0, path_1.join)(dir, "schema", f.path), f.content, !!options.force);
|
|
145
252
|
}
|
|
146
253
|
}
|
|
147
254
|
else {
|
|
148
255
|
fs.ensureFileSync((0, path_1.join)(dir, "schema", "schema.gql"));
|
|
149
256
|
}
|
|
150
|
-
for (const c of
|
|
151
|
-
await writeConnectorFiles(config, c);
|
|
257
|
+
for (const c of serviceGql.connectors) {
|
|
258
|
+
await writeConnectorFiles(config, c, options);
|
|
152
259
|
}
|
|
153
260
|
}
|
|
154
|
-
async function writeConnectorFiles(config, connectorInfo) {
|
|
261
|
+
async function writeConnectorFiles(config, connectorInfo, options) {
|
|
155
262
|
const subbedConnectorYaml = subConnectorYamlValues({ connectorId: connectorInfo.id });
|
|
156
263
|
const dir = config.get("dataconnect.source") || "dataconnect";
|
|
157
|
-
await config.askWriteProjectFile((0, path_1.join)(dir, connectorInfo.path, "connector.yaml"), subbedConnectorYaml);
|
|
264
|
+
await config.askWriteProjectFile((0, path_1.join)(dir, connectorInfo.path, "connector.yaml"), subbedConnectorYaml, !!options.force, true);
|
|
158
265
|
for (const f of connectorInfo.files) {
|
|
159
|
-
await config.askWriteProjectFile((0, path_1.join)(dir, connectorInfo.path, f.path), f.content);
|
|
266
|
+
await config.askWriteProjectFile((0, path_1.join)(dir, connectorInfo.path, f.path), f.content, !!options.force);
|
|
160
267
|
}
|
|
161
268
|
}
|
|
162
269
|
function subDataconnectYamlValues(replacementValues) {
|
|
@@ -185,55 +292,72 @@ function subConnectorYamlValues(replacementValues) {
|
|
|
185
292
|
}
|
|
186
293
|
async function promptForExistingServices(setup, info) {
|
|
187
294
|
if (!setup.projectId) {
|
|
188
|
-
return
|
|
295
|
+
return;
|
|
189
296
|
}
|
|
190
297
|
const existingServices = await (0, client_1.listAllServices)(setup.projectId);
|
|
191
|
-
|
|
192
|
-
return
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
298
|
+
if (!existingServices.length) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
const choice = await chooseExistingService(existingServices);
|
|
302
|
+
if (!choice) {
|
|
303
|
+
const existingServiceIds = existingServices.map((s) => s.name.split("/").pop());
|
|
304
|
+
info.serviceId = (0, utils_1.newUniqueId)(defaultServiceId(), existingServiceIds);
|
|
305
|
+
info.analyticsFlow += "_pick_new_service";
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
info.analyticsFlow += "_pick_existing_service";
|
|
309
|
+
const serviceName = (0, names_1.parseServiceName)(choice.name);
|
|
310
|
+
info.serviceId = serviceName.serviceId;
|
|
311
|
+
info.locationId = serviceName.location;
|
|
312
|
+
await downloadService(info, choice.name);
|
|
313
|
+
}
|
|
314
|
+
async function downloadService(info, serviceName) {
|
|
315
|
+
const schema = await (0, client_1.getSchema)(serviceName);
|
|
316
|
+
if (!schema) {
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
info.serviceGql = {
|
|
320
|
+
schemaGql: [],
|
|
321
|
+
connectors: [
|
|
322
|
+
{
|
|
323
|
+
id: "example",
|
|
324
|
+
path: "./example",
|
|
325
|
+
files: [],
|
|
326
|
+
},
|
|
327
|
+
],
|
|
328
|
+
};
|
|
329
|
+
const primaryDatasource = schema.datasources.find((d) => d.postgresql);
|
|
330
|
+
if (primaryDatasource?.postgresql?.cloudSql?.instance) {
|
|
331
|
+
const instanceName = (0, names_1.parseCloudSQLInstanceName)(primaryDatasource.postgresql.cloudSql.instance);
|
|
332
|
+
info.cloudSqlInstanceId = instanceName.instanceId;
|
|
333
|
+
}
|
|
334
|
+
if (schema.source.files?.length) {
|
|
335
|
+
info.serviceGql.schemaGql = schema.source.files;
|
|
336
|
+
}
|
|
337
|
+
info.cloudSqlDatabase = primaryDatasource?.postgresql?.database ?? "";
|
|
338
|
+
const connectors = await (0, client_1.listConnectors)(serviceName, [
|
|
339
|
+
"connectors.name",
|
|
340
|
+
"connectors.source.files",
|
|
341
|
+
]);
|
|
342
|
+
if (connectors.length) {
|
|
343
|
+
info.serviceGql.connectors = connectors.map((c) => {
|
|
344
|
+
const id = c.name.split("/").pop();
|
|
345
|
+
return {
|
|
346
|
+
id,
|
|
347
|
+
path: connectors.length === 1 ? "./example" : `./${id}`,
|
|
348
|
+
files: c.source.files || [],
|
|
349
|
+
};
|
|
350
|
+
});
|
|
228
351
|
}
|
|
229
|
-
return info;
|
|
230
352
|
}
|
|
231
353
|
async function chooseExistingService(existing) {
|
|
232
|
-
const
|
|
354
|
+
const fdcConnector = (0, utils_1.envOverride)("FDC_CONNECTOR", "");
|
|
355
|
+
const fdcService = (0, utils_1.envOverride)("FDC_SERVICE", "");
|
|
356
|
+
const serviceEnvVar = fdcConnector || fdcService;
|
|
233
357
|
if (serviceEnvVar) {
|
|
234
358
|
const [serviceLocationFromEnvVar, serviceIdFromEnvVar] = serviceEnvVar.split("/");
|
|
235
359
|
const serviceFromEnvVar = existing.find((s) => {
|
|
236
|
-
const serviceName = (0, names_1.parseServiceName)(s.
|
|
360
|
+
const serviceName = (0, names_1.parseServiceName)(s.name);
|
|
237
361
|
return (serviceName.serviceId === serviceIdFromEnvVar &&
|
|
238
362
|
serviceName.location === serviceLocationFromEnvVar);
|
|
239
363
|
});
|
|
@@ -241,10 +365,11 @@ async function chooseExistingService(existing) {
|
|
|
241
365
|
(0, utils_1.logBullet)(`Picking up the existing service ${clc.bold(serviceLocationFromEnvVar + "/" + serviceIdFromEnvVar)}.`);
|
|
242
366
|
return serviceFromEnvVar;
|
|
243
367
|
}
|
|
244
|
-
|
|
368
|
+
const envVarName = fdcConnector ? "FDC_CONNECTOR" : "FDC_SERVICE";
|
|
369
|
+
(0, utils_1.logWarning)(`Unable to pick up an existing service based on ${envVarName}=${serviceEnvVar}.`);
|
|
245
370
|
}
|
|
246
371
|
const choices = existing.map((s) => {
|
|
247
|
-
const serviceName = (0, names_1.parseServiceName)(s.
|
|
372
|
+
const serviceName = (0, names_1.parseServiceName)(s.name);
|
|
248
373
|
return {
|
|
249
374
|
name: `${serviceName.location}/${serviceName.serviceId}`,
|
|
250
375
|
value: s,
|
|
@@ -257,7 +382,10 @@ async function chooseExistingService(existing) {
|
|
|
257
382
|
});
|
|
258
383
|
}
|
|
259
384
|
async function promptForCloudSQL(setup, info) {
|
|
260
|
-
if (
|
|
385
|
+
if (!setup.projectId) {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
if (info.cloudSqlInstanceId === "") {
|
|
261
389
|
const instances = await cloudsql.listInstances(setup.projectId);
|
|
262
390
|
let choices = instances.map((i) => {
|
|
263
391
|
let display = `${i.name} (${i.region})`;
|
|
@@ -279,78 +407,41 @@ async function promptForCloudSQL(setup, info) {
|
|
|
279
407
|
choices,
|
|
280
408
|
});
|
|
281
409
|
if (info.cloudSqlInstanceId !== "") {
|
|
410
|
+
info.analyticsFlow += "_pick_existing_csql";
|
|
282
411
|
info.locationId = choices.find((c) => c.value === info.cloudSqlInstanceId).location;
|
|
283
412
|
}
|
|
413
|
+
else {
|
|
414
|
+
info.analyticsFlow += "_pick_new_csql";
|
|
415
|
+
info.cloudSqlInstanceId = await (0, prompt_1.input)({
|
|
416
|
+
message: `What ID would you like to use for your new CloudSQL instance?`,
|
|
417
|
+
default: (0, utils_1.newUniqueId)(`${defaultServiceId().toLowerCase()}-fdc`, instances.map((i) => i.name)),
|
|
418
|
+
});
|
|
419
|
+
}
|
|
284
420
|
}
|
|
285
421
|
}
|
|
286
|
-
if (info.cloudSqlInstanceId === "") {
|
|
287
|
-
info.isNewInstance = true;
|
|
288
|
-
info.cloudSqlInstanceId = await (0, prompt_1.input)({
|
|
289
|
-
message: `What ID would you like to use for your new CloudSQL instance?`,
|
|
290
|
-
default: `${info.serviceId.toLowerCase() || "app"}-fdc`,
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
422
|
if (info.locationId === "") {
|
|
294
423
|
const choices = await locationChoices(setup);
|
|
295
424
|
info.locationId = await (0, prompt_1.select)({
|
|
296
425
|
message: "What location would like to use?",
|
|
297
426
|
choices,
|
|
427
|
+
default: "us-central1",
|
|
428
|
+
});
|
|
429
|
+
info.shouldProvisionCSQL = await (0, prompt_1.confirm)({
|
|
430
|
+
message: `Would you like to provision your Cloud SQL instance and database now?`,
|
|
431
|
+
default: true,
|
|
298
432
|
});
|
|
299
433
|
}
|
|
300
|
-
if (info.
|
|
434
|
+
if (info.cloudSqlInstanceId !== "" && info.cloudSqlDatabase === "") {
|
|
301
435
|
try {
|
|
302
436
|
const dbs = await cloudsql.listDatabases(setup.projectId, info.cloudSqlInstanceId);
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
});
|
|
306
|
-
choices.push({ name: "Create a new database", value: "" });
|
|
307
|
-
if (dbs.length) {
|
|
308
|
-
info.cloudSqlDatabase = await (0, prompt_1.select)({
|
|
309
|
-
message: `Which database in ${info.cloudSqlInstanceId} would you like to use?`,
|
|
310
|
-
choices,
|
|
311
|
-
});
|
|
312
|
-
}
|
|
437
|
+
const existing = dbs.map((d) => d.name);
|
|
438
|
+
info.cloudSqlDatabase = (0, utils_1.newUniqueId)("fdcdb", existing);
|
|
313
439
|
}
|
|
314
440
|
catch (err) {
|
|
315
441
|
logger_1.logger.debug(`[dataconnect] Cannot list databases during init: ${err}`);
|
|
316
442
|
}
|
|
317
443
|
}
|
|
318
|
-
|
|
319
|
-
info.isNewDatabase = true;
|
|
320
|
-
info.cloudSqlDatabase = await (0, prompt_1.input)({
|
|
321
|
-
message: `What ID would you like to use for your new database in ${info.cloudSqlInstanceId}?`,
|
|
322
|
-
default: `fdcdb`,
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
return info;
|
|
326
|
-
}
|
|
327
|
-
async function promptForSchema(setup, info) {
|
|
328
|
-
if (info.serviceId === "") {
|
|
329
|
-
info.serviceId = await (0, prompt_1.input)({
|
|
330
|
-
message: "What ID would you like to use for this service?",
|
|
331
|
-
default: (0, path_1.basename)(process.cwd()),
|
|
332
|
-
});
|
|
333
|
-
if (setup.projectId) {
|
|
334
|
-
if (!configstore_1.configstore.get("gemini")) {
|
|
335
|
-
(0, utils_1.logBullet)("Learn more about Gemini in Firebase and how it uses your data: https://firebase.google.com/docs/gemini-in-firebase#how-gemini-in-firebase-uses-your-data");
|
|
336
|
-
}
|
|
337
|
-
if (await (0, prompt_1.confirm)({
|
|
338
|
-
message: `Do you want Gemini in Firebase to help generate a schema for your service?`,
|
|
339
|
-
default: false,
|
|
340
|
-
})) {
|
|
341
|
-
configstore_1.configstore.set("gemini", true);
|
|
342
|
-
await (0, ensureApis_1.ensureGIFApis)(setup.projectId);
|
|
343
|
-
const prompt = await (0, prompt_1.input)({
|
|
344
|
-
message: "Describe the app you are building:",
|
|
345
|
-
default: "movie rating app",
|
|
346
|
-
});
|
|
347
|
-
const schema = await (0, utils_1.promiseWithSpinner)(() => (0, fdcExperience_1.generateSchema)(prompt, setup.projectId), "Generating the Data Connect Schema...");
|
|
348
|
-
info.schemaGql = [{ path: "schema.gql", content: (0, fdcExperience_1.extractCodeBlock)(schema) }];
|
|
349
|
-
info.connectors = [emptyConnector];
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
return info;
|
|
444
|
+
return;
|
|
354
445
|
}
|
|
355
446
|
async function locationChoices(setup) {
|
|
356
447
|
if (setup.projectId) {
|
|
@@ -372,17 +463,20 @@ async function locationChoices(setup) {
|
|
|
372
463
|
];
|
|
373
464
|
}
|
|
374
465
|
}
|
|
466
|
+
function defaultServiceId() {
|
|
467
|
+
return toDNSCompatibleId((0, path_1.basename)(process.cwd()));
|
|
468
|
+
}
|
|
375
469
|
function toDNSCompatibleId(id) {
|
|
376
|
-
|
|
470
|
+
id = (0, path_1.basename)(id)
|
|
377
471
|
.toLowerCase()
|
|
378
472
|
.replaceAll(/[^a-z0-9-]/g, "")
|
|
379
473
|
.slice(0, 63);
|
|
380
|
-
while (
|
|
381
|
-
|
|
474
|
+
while (id.endsWith("-") && id.length) {
|
|
475
|
+
id = id.slice(0, id.length - 1);
|
|
382
476
|
}
|
|
383
|
-
while (
|
|
384
|
-
|
|
477
|
+
while (id.startsWith("-") && id.length) {
|
|
478
|
+
id = id.slice(1, id.length);
|
|
385
479
|
}
|
|
386
|
-
return
|
|
480
|
+
return id || "app";
|
|
387
481
|
}
|
|
388
482
|
exports.toDNSCompatibleId = toDNSCompatibleId;
|