firebase-tools-with-isolate 13.6.4 → 13.9.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.
Files changed (157) hide show
  1. package/README.md +4 -6
  2. package/lib/api.js +18 -8
  3. package/lib/apiv2.js +19 -13
  4. package/lib/apphosting/app.js +69 -0
  5. package/lib/apphosting/config.js +97 -0
  6. package/lib/{init/features/apphosting → apphosting}/constants.js +2 -2
  7. package/lib/apphosting/githubConnections.js +263 -0
  8. package/lib/apphosting/index.js +319 -0
  9. package/lib/{init/features/apphosting → apphosting}/repo.js +12 -12
  10. package/lib/apphosting/secrets/dialogs.js +170 -0
  11. package/lib/apphosting/secrets/index.js +103 -0
  12. package/lib/checkValidTargetFilters.js +8 -1
  13. package/lib/commands/apphosting-backends-create.js +9 -4
  14. package/lib/commands/apphosting-backends-delete.js +27 -30
  15. package/lib/commands/apphosting-backends-get.js +8 -8
  16. package/lib/commands/apphosting-backends-list.js +6 -7
  17. package/lib/commands/apphosting-secrets-access.js +24 -0
  18. package/lib/commands/apphosting-secrets-describe.js +29 -0
  19. package/lib/commands/apphosting-secrets-grantaccess.js +49 -0
  20. package/lib/commands/apphosting-secrets-set.js +56 -0
  21. package/lib/commands/dataconnect-sdk-generate.js +37 -0
  22. package/lib/commands/dataconnect-services-list.js +80 -0
  23. package/lib/commands/dataconnect-sql-diff.js +25 -0
  24. package/lib/commands/dataconnect-sql-migrate.js +45 -0
  25. package/lib/commands/deploy.js +27 -1
  26. package/lib/commands/firestore-databases-create.js +1 -0
  27. package/lib/commands/firestore-databases-restore.js +1 -0
  28. package/lib/commands/functions-secrets-access.js +2 -2
  29. package/lib/commands/functions-secrets-describe.js +14 -0
  30. package/lib/commands/functions-secrets-destroy.js +2 -2
  31. package/lib/commands/functions-secrets-get.js +3 -17
  32. package/lib/commands/functions-secrets-prune.js +2 -1
  33. package/lib/commands/functions-secrets-set.js +3 -19
  34. package/lib/commands/index.js +25 -6
  35. package/lib/commands/init.js +10 -3
  36. package/lib/commands/setup-emulators-dataconnect.js +12 -0
  37. package/lib/config.js +1 -0
  38. package/lib/dataconnect/build.js +22 -0
  39. package/lib/dataconnect/checkIam.js +30 -0
  40. package/lib/dataconnect/client.js +112 -0
  41. package/lib/dataconnect/dataplaneClient.js +16 -0
  42. package/lib/dataconnect/ensureApis.js +12 -0
  43. package/lib/dataconnect/errors.js +29 -0
  44. package/lib/dataconnect/fileUtils.js +92 -0
  45. package/lib/dataconnect/filters.js +45 -0
  46. package/lib/dataconnect/freeTrial.js +22 -0
  47. package/lib/dataconnect/graphqlError.js +12 -0
  48. package/lib/dataconnect/load.js +40 -0
  49. package/lib/dataconnect/names.js +46 -0
  50. package/lib/dataconnect/prompts.js +20 -0
  51. package/lib/dataconnect/provisionCloudSql.js +74 -0
  52. package/lib/dataconnect/schemaMigration.js +246 -0
  53. package/lib/dataconnect/types.js +22 -0
  54. package/lib/deploy/dataconnect/deploy.js +75 -0
  55. package/lib/deploy/dataconnect/index.js +9 -0
  56. package/lib/deploy/dataconnect/prepare.js +33 -0
  57. package/lib/deploy/dataconnect/release.js +65 -0
  58. package/lib/deploy/firestore/prepare.js +4 -2
  59. package/lib/deploy/functions/checkIam.js +6 -39
  60. package/lib/deploy/functions/containerCleaner.js +1 -15
  61. package/lib/deploy/functions/deploy.js +2 -2
  62. package/lib/deploy/functions/params.js +2 -2
  63. package/lib/deploy/functions/prepare.js +13 -3
  64. package/lib/deploy/functions/pricing.js +2 -2
  65. package/lib/deploy/functions/prompts.js +39 -7
  66. package/lib/deploy/functions/release/fabricator.js +12 -7
  67. package/lib/deploy/functions/release/index.js +17 -2
  68. package/lib/deploy/functions/release/planner.js +11 -3
  69. package/lib/deploy/functions/runtimes/discovery/index.js +3 -3
  70. package/lib/deploy/functions/runtimes/index.js +6 -43
  71. package/lib/deploy/functions/runtimes/node/index.js +3 -2
  72. package/lib/deploy/functions/runtimes/node/parseRuntimeAndValidateSDK.js +15 -34
  73. package/lib/deploy/functions/runtimes/python/index.js +10 -7
  74. package/lib/deploy/functions/runtimes/supported/index.js +80 -0
  75. package/lib/deploy/functions/runtimes/supported/types.js +74 -0
  76. package/lib/deploy/functions/services/index.js +4 -0
  77. package/lib/deploy/index.js +2 -0
  78. package/lib/downloadUtils.js +3 -2
  79. package/lib/emulator/constants.js +3 -0
  80. package/lib/emulator/controller.js +44 -13
  81. package/lib/emulator/dataconnectEmulator.js +95 -0
  82. package/lib/emulator/download.js +1 -1
  83. package/lib/emulator/downloadableEmulators.js +57 -8
  84. package/lib/emulator/functionsEmulator.js +2 -2
  85. package/lib/emulator/hub.js +5 -0
  86. package/lib/emulator/portUtils.js +3 -3
  87. package/lib/emulator/registry.js +6 -1
  88. package/lib/emulator/types.js +3 -0
  89. package/lib/experiments.js +31 -6
  90. package/lib/extensions/emulator/specHelper.js +9 -42
  91. package/lib/extensions/extensionsApi.js +2 -2
  92. package/lib/extensions/localHelper.js +3 -3
  93. package/lib/firestore/pretty-print.js +5 -0
  94. package/lib/frameworks/astro/index.js +1 -1
  95. package/lib/frameworks/flutter/index.js +2 -2
  96. package/lib/frameworks/next/constants.js +2 -1
  97. package/lib/frameworks/next/index.js +27 -15
  98. package/lib/frameworks/next/utils.js +33 -3
  99. package/lib/functional.js +2 -2
  100. package/lib/functions/events/v2.js +7 -1
  101. package/lib/functions/python.js +4 -3
  102. package/lib/functions/secrets.js +40 -22
  103. package/lib/gcp/apphosting.js +25 -3
  104. package/lib/gcp/cloudbuild.js +7 -3
  105. package/lib/gcp/cloudfunctions.js +5 -5
  106. package/lib/gcp/cloudfunctionsv2.js +3 -3
  107. package/lib/gcp/cloudscheduler.js +2 -2
  108. package/lib/gcp/cloudsql/cloudsqladmin.js +174 -0
  109. package/lib/gcp/cloudsql/connect.js +144 -0
  110. package/lib/gcp/cloudsql/fbToolsAuthClient.js +44 -0
  111. package/lib/gcp/computeEngine.js +7 -0
  112. package/lib/gcp/devConnect.js +25 -12
  113. package/lib/gcp/firedata.js +27 -0
  114. package/lib/gcp/iam.js +41 -1
  115. package/lib/gcp/secretManager.js +55 -7
  116. package/lib/gcp/serviceusage.js +24 -5
  117. package/lib/hosting/interactive.js +4 -0
  118. package/lib/init/features/dataconnect/index.js +166 -0
  119. package/lib/init/features/emulators.js +13 -1
  120. package/lib/init/features/functions/index.js +19 -3
  121. package/lib/init/features/functions/npm-dependencies.js +12 -23
  122. package/lib/init/features/functions/python.js +4 -3
  123. package/lib/init/features/genkit.js +53 -0
  124. package/lib/init/features/hosting/github.js +4 -5
  125. package/lib/init/features/index.js +6 -2
  126. package/lib/init/index.js +2 -0
  127. package/lib/init/spawn.js +23 -0
  128. package/lib/logger.js +22 -2
  129. package/lib/operation-poller.js +8 -2
  130. package/lib/rc.js +9 -1
  131. package/lib/requireAuth.js +1 -8
  132. package/lib/requireTosAcceptance.js +22 -0
  133. package/lib/utils.js +76 -8
  134. package/package.json +11 -5
  135. package/schema/connector-yaml.json +54 -0
  136. package/schema/dataconnect-yaml.json +72 -0
  137. package/schema/firebase-config.json +115 -2
  138. package/templates/extensions/javascript/package.lint.json +2 -2
  139. package/templates/extensions/javascript/package.nolint.json +2 -2
  140. package/templates/extensions/typescript/package.lint.json +2 -2
  141. package/templates/extensions/typescript/package.nolint.json +2 -2
  142. package/templates/init/dataconnect/connector.yaml +2 -0
  143. package/templates/init/dataconnect/dataconnect.yaml +10 -0
  144. package/templates/init/dataconnect/mutations.gql +30 -0
  145. package/templates/init/dataconnect/queries.gql +51 -0
  146. package/templates/init/dataconnect/schema.gql +28 -0
  147. package/templates/init/functions/javascript/_gitignore +2 -1
  148. package/templates/init/functions/javascript/package.lint.json +2 -2
  149. package/templates/init/functions/javascript/package.nolint.json +2 -2
  150. package/templates/init/functions/python/_gitignore +1 -0
  151. package/templates/init/functions/typescript/_eslintrc +1 -0
  152. package/templates/init/functions/typescript/_gitignore +1 -0
  153. package/templates/init/functions/typescript/package.lint.json +2 -2
  154. package/templates/init/functions/typescript/package.nolint.json +2 -2
  155. package/lib/init/features/apphosting/index.js +0 -229
  156. package/lib/monospace/index.js +0 -82
  157. /package/lib/{monospace/interfaces.js → gcp/cloudsql/types.js} +0 -0
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseConnectorName = exports.parseServiceName = void 0;
4
+ const error_1 = require("../error");
5
+ const serviceNameRegex = /projects\/(?<projectId>[^\/]+)\/locations\/(?<location>[^\/]+)\/services\/(?<serviceId>[^\/]+)/;
6
+ function parseServiceName(serviceName) {
7
+ const res = serviceNameRegex.exec(serviceName);
8
+ const projectId = res?.groups?.projectId;
9
+ const location = res?.groups?.location;
10
+ const serviceId = res?.groups?.serviceId;
11
+ if (!projectId || !location || !serviceId) {
12
+ throw new error_1.FirebaseError(`${serviceName} is not a valid service name`);
13
+ }
14
+ const toString = () => {
15
+ return `projects/${projectId}/locations/${location}/services/${serviceId}`;
16
+ };
17
+ return {
18
+ projectId,
19
+ location,
20
+ serviceId,
21
+ toString,
22
+ };
23
+ }
24
+ exports.parseServiceName = parseServiceName;
25
+ const connectorNameRegex = /projects\/(?<projectId>[^\/]+)\/locations\/(?<location>[^\/]+)\/services\/(?<serviceId>[^\/]+)\/connectors\/(?<connectorId>[^\/]+)/;
26
+ function parseConnectorName(connectorName) {
27
+ const res = connectorNameRegex.exec(connectorName);
28
+ const projectId = res?.groups?.projectId;
29
+ const location = res?.groups?.location;
30
+ const serviceId = res?.groups?.serviceId;
31
+ const connectorId = res?.groups?.connectorId;
32
+ if (!projectId || !location || !serviceId || !connectorId) {
33
+ throw new error_1.FirebaseError(`${connectorName} is not a valid connector name`);
34
+ }
35
+ const toString = () => {
36
+ return `projects/${projectId}/locations/${location}/services/${serviceId}/connectors/${connectorId}`;
37
+ };
38
+ return {
39
+ projectId,
40
+ location,
41
+ serviceId,
42
+ connectorId,
43
+ toString,
44
+ };
45
+ }
46
+ exports.parseConnectorName = parseConnectorName;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.promptDeleteConnector = void 0;
4
+ const prompt_1 = require("../prompt");
5
+ const utils = require("../utils");
6
+ const client_1 = require("./client");
7
+ async function promptDeleteConnector(options, connectorName) {
8
+ utils.logLabeledWarning("dataconnect", `Connector ${connectorName} exists but is not listed in dataconnect.yaml.`);
9
+ const confirmDeletion = await (0, prompt_1.confirm)({
10
+ default: false,
11
+ message: `Do you want to delete ${connectorName}?`,
12
+ force: options.force,
13
+ nonInteractive: options.nonInteractive,
14
+ });
15
+ if (confirmDeletion) {
16
+ await (0, client_1.deleteConnector)(connectorName);
17
+ utils.logLabeledSuccess("dataconnect", `Connector ${connectorName} deleted`);
18
+ }
19
+ }
20
+ exports.promptDeleteConnector = promptDeleteConnector;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkInstanceConfig = exports.provisionCloudSql = void 0;
4
+ const cloudSqlAdminClient = require("../gcp/cloudsql/cloudsqladmin");
5
+ const utils = require("../utils");
6
+ const checkIam_1 = require("./checkIam");
7
+ const utils_1 = require("../utils");
8
+ const GOOGLE_ML_INTEGRATION_ROLE = "roles/aiplatform.user";
9
+ const freeTrial_1 = require("./freeTrial");
10
+ const error_1 = require("../error");
11
+ async function provisionCloudSql(args) {
12
+ let connectionName;
13
+ const { projectId, locationId, instanceId, databaseId, enableGoogleMlIntegration, silent } = args;
14
+ try {
15
+ const existingInstance = await cloudSqlAdminClient.getInstance(projectId, instanceId);
16
+ silent || utils.logLabeledBullet("dataconnect", `Found existing instance ${instanceId}.`);
17
+ connectionName = existingInstance?.connectionName || "";
18
+ if (!checkInstanceConfig(existingInstance, enableGoogleMlIntegration)) {
19
+ silent ||
20
+ utils.logLabeledBullet("dataconnect", `Instance ${instanceId} settings not compatible with Firebase Data Connect. ` +
21
+ `Updating instance to enable Cloud IAM authentication and public IP. This may take a few minutes...`);
22
+ await (0, utils_1.promiseWithSpinner)(() => cloudSqlAdminClient.updateInstanceForDataConnect(existingInstance, enableGoogleMlIntegration), "Updating your instance...");
23
+ silent || utils.logLabeledBullet("dataconnect", "Instance updated");
24
+ }
25
+ }
26
+ catch (err) {
27
+ if (err.status !== 404) {
28
+ throw err;
29
+ }
30
+ const freeTrialInstanceId = await (0, freeTrial_1.checkForFreeTrialInstance)(projectId);
31
+ if (freeTrialInstanceId) {
32
+ (0, freeTrial_1.printFreeTrialUnavailable)(projectId, freeTrialInstanceId);
33
+ throw new error_1.FirebaseError("Free trial unavailable.");
34
+ }
35
+ silent ||
36
+ utils.logLabeledBullet("dataconnect", `CloudSQL instance '${instanceId}' not found, creating it. This instance is provided under the terms of the Data Connect free trial ${(0, freeTrial_1.freeTrialTermsLink)()}`);
37
+ silent || utils.logLabeledBullet("dataconnect", `This may take while...`);
38
+ const newInstance = await (0, utils_1.promiseWithSpinner)(() => cloudSqlAdminClient.createInstance(projectId, locationId, instanceId, enableGoogleMlIntegration), "Creating your instance...");
39
+ silent || utils.logLabeledBullet("dataconnect", "Instance created");
40
+ connectionName = newInstance?.connectionName || "";
41
+ }
42
+ try {
43
+ await cloudSqlAdminClient.getDatabase(projectId, instanceId, databaseId);
44
+ silent || utils.logLabeledBullet("dataconnect", `Found existing database ${databaseId}.`);
45
+ }
46
+ catch (err) {
47
+ silent ||
48
+ utils.logLabeledBullet("dataconnect", `Database ${databaseId} not found, creating it now...`);
49
+ await cloudSqlAdminClient.createDatabase(projectId, instanceId, databaseId);
50
+ silent || utils.logLabeledBullet("dataconnect", `Database ${databaseId} created.`);
51
+ }
52
+ if (enableGoogleMlIntegration) {
53
+ await (0, checkIam_1.grantRolesToCloudSqlServiceAccount)(projectId, instanceId, [GOOGLE_ML_INTEGRATION_ROLE]);
54
+ }
55
+ return connectionName;
56
+ }
57
+ exports.provisionCloudSql = provisionCloudSql;
58
+ function checkInstanceConfig(instance, requireGoogleMlIntegration) {
59
+ const settings = instance.settings;
60
+ if (!settings.ipConfiguration?.ipv4Enabled) {
61
+ return false;
62
+ }
63
+ if (requireGoogleMlIntegration) {
64
+ if (!settings.enableGoogleMlIntegration) {
65
+ return false;
66
+ }
67
+ if (!settings.databaseFlags?.some((f) => f.name === "cloudsql.enable_google_ml_integration" && f.value === "on")) {
68
+ return false;
69
+ }
70
+ }
71
+ const isIamEnabled = settings.databaseFlags?.some((f) => f.name === "cloudsql.iam_authentication" && f.value === "on") ?? false;
72
+ return isIamEnabled;
73
+ }
74
+ exports.checkInstanceConfig = checkInstanceConfig;
@@ -0,0 +1,246 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.migrateSchema = exports.diffSchema = void 0;
4
+ const clc = require("colorette");
5
+ const sql_formatter_1 = require("sql-formatter");
6
+ const types_1 = require("./types");
7
+ const client_1 = require("./client");
8
+ const connect_1 = require("../gcp/cloudsql/connect");
9
+ const prompt_1 = require("../prompt");
10
+ const logger_1 = require("../logger");
11
+ const error_1 = require("../error");
12
+ const projectUtils_1 = require("../projectUtils");
13
+ const utils_1 = require("../utils");
14
+ const errors = require("./errors");
15
+ async function diffSchema(schema) {
16
+ const { serviceName, instanceName, databaseId } = getIdentifiers(schema);
17
+ await ensureServiceIsConnectedToCloudSql(serviceName, instanceName, databaseId);
18
+ try {
19
+ await (0, client_1.upsertSchema)(schema, true);
20
+ }
21
+ catch (err) {
22
+ const invalidConnectors = errors.getInvalidConnectors(err);
23
+ if (invalidConnectors.length) {
24
+ displayInvalidConnectors(invalidConnectors);
25
+ }
26
+ const incompatible = errors.getIncompatibleSchemaError(err);
27
+ if (incompatible) {
28
+ displaySchemaChanges(incompatible);
29
+ return incompatible.diffs;
30
+ }
31
+ }
32
+ (0, utils_1.logLabeledSuccess)("dataconnect", `Database schema is up to date.`);
33
+ return [];
34
+ }
35
+ exports.diffSchema = diffSchema;
36
+ async function migrateSchema(args) {
37
+ const { options, schema, allowNonInteractiveMigration, validateOnly } = args;
38
+ const { serviceName, instanceId, instanceName, databaseId } = getIdentifiers(schema);
39
+ await ensureServiceIsConnectedToCloudSql(serviceName, instanceName, databaseId);
40
+ try {
41
+ await (0, client_1.upsertSchema)(schema, validateOnly);
42
+ logger_1.logger.debug(`Database schema was up to date for ${instanceId}:${databaseId}`);
43
+ }
44
+ catch (err) {
45
+ const incompatible = errors.getIncompatibleSchemaError(err);
46
+ const invalidConnectors = errors.getInvalidConnectors(err);
47
+ if (!incompatible && !invalidConnectors.length) {
48
+ throw err;
49
+ }
50
+ const shouldDeleteInvalidConnectors = await promptForInvalidConnectorError(options, invalidConnectors, validateOnly);
51
+ if (!shouldDeleteInvalidConnectors && invalidConnectors.length) {
52
+ const cmd = suggestedCommand(serviceName, invalidConnectors);
53
+ throw new error_1.FirebaseError(`Command aborted. Try deploying compatible connectors first with ${clc.bold(cmd)}`);
54
+ }
55
+ const migrationMode = incompatible
56
+ ? await promptForSchemaMigration(options, databaseId, incompatible, allowNonInteractiveMigration)
57
+ : "none";
58
+ if (migrationMode === "none" && incompatible) {
59
+ throw new error_1.FirebaseError("Command aborted.");
60
+ }
61
+ let diffs = [];
62
+ if (incompatible) {
63
+ diffs = await handleIncompatibleSchemaError({
64
+ options,
65
+ databaseId,
66
+ instanceId,
67
+ incompatibleSchemaError: incompatible,
68
+ choice: migrationMode,
69
+ });
70
+ }
71
+ if (invalidConnectors.length) {
72
+ await deleteInvalidConnectors(invalidConnectors);
73
+ }
74
+ await (0, client_1.upsertSchema)(schema, validateOnly);
75
+ return diffs;
76
+ }
77
+ return [];
78
+ }
79
+ exports.migrateSchema = migrateSchema;
80
+ function getIdentifiers(schema) {
81
+ const databaseId = schema.primaryDatasource.postgresql?.database;
82
+ if (!databaseId) {
83
+ throw new error_1.FirebaseError("Schema is missing primaryDatasource.postgresql?.database, cannot migrate");
84
+ }
85
+ const instanceName = schema.primaryDatasource.postgresql?.cloudSql.instance;
86
+ if (!instanceName) {
87
+ throw new error_1.FirebaseError("tried to migrate schema but instance name was not provided in dataconnect.yaml");
88
+ }
89
+ const instanceId = instanceName.split("/").pop();
90
+ const serviceName = schema.name.replace(`/schemas/${types_1.SCHEMA_ID}`, "");
91
+ return {
92
+ databaseId,
93
+ instanceId,
94
+ instanceName,
95
+ serviceName,
96
+ };
97
+ }
98
+ function suggestedCommand(serviceName, invalidConnectorNames) {
99
+ const serviceId = serviceName.split("/")[5];
100
+ const connectorIds = invalidConnectorNames.map((i) => i.split("/")[7]);
101
+ const onlys = connectorIds.map((c) => `dataconnect:${serviceId}:${c}`).join(",");
102
+ return `firebase deploy --only ${onlys}`;
103
+ }
104
+ async function handleIncompatibleSchemaError(args) {
105
+ const { incompatibleSchemaError, options, instanceId, databaseId, choice } = args;
106
+ if (incompatibleSchemaError.destructive && choice === "safe") {
107
+ throw new error_1.FirebaseError("This schema migration includes potentially destructive changes. If you'd like to execute it anyway, rerun this command with --force");
108
+ }
109
+ const projectId = (0, projectUtils_1.needProjectId)(options);
110
+ const iamUser = await (0, connect_1.setupIAMUser)(instanceId, databaseId, options);
111
+ const commandsToExecute = incompatibleSchemaError.diffs
112
+ .filter((d) => {
113
+ switch (choice) {
114
+ case "all":
115
+ return true;
116
+ case "safe":
117
+ return !d.destructive;
118
+ case "none":
119
+ return false;
120
+ }
121
+ })
122
+ .map((d) => d.sql);
123
+ if (commandsToExecute.length) {
124
+ await (0, connect_1.execute)([
125
+ `SET ROLE "${(0, connect_1.firebaseowner)(databaseId)}"`,
126
+ ...commandsToExecute,
127
+ `GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA "public" TO PUBLIC`,
128
+ ], {
129
+ projectId,
130
+ instanceId,
131
+ databaseId,
132
+ username: iamUser,
133
+ });
134
+ return incompatibleSchemaError.diffs;
135
+ }
136
+ return [];
137
+ }
138
+ async function promptForSchemaMigration(options, databaseName, err, allowNonInteractiveMigration) {
139
+ displaySchemaChanges(err);
140
+ if (!options.nonInteractive) {
141
+ const choices = err.destructive
142
+ ? [
143
+ { name: "Execute all changes (including destructive changes)", value: "all" },
144
+ { name: "Abort changes", value: "none" },
145
+ ]
146
+ : [
147
+ { name: "Execute changes", value: "safe" },
148
+ { name: "Abort changes", value: "none" },
149
+ ];
150
+ return await (0, prompt_1.promptOnce)({
151
+ message: `Would you like to execute these changes against ${databaseName}?`,
152
+ type: "list",
153
+ choices,
154
+ });
155
+ }
156
+ else if (!allowNonInteractiveMigration) {
157
+ logger_1.logger.error("Your database schema is incompatible with your Data Connect schema. Run `firebase dataconnect:sql:migrate` to migrate your database schema");
158
+ return "none";
159
+ }
160
+ else if (options.force) {
161
+ return "all";
162
+ }
163
+ else if (!err.destructive) {
164
+ return "safe";
165
+ }
166
+ else {
167
+ logger_1.logger.error("This schema migration includes potentially destructive changes. If you'd like to execute it anyway, rerun this command with --force");
168
+ return "none";
169
+ }
170
+ }
171
+ async function promptForInvalidConnectorError(options, invalidConnectors, validateOnly) {
172
+ if (!invalidConnectors.length) {
173
+ return false;
174
+ }
175
+ displayInvalidConnectors(invalidConnectors);
176
+ if (validateOnly) {
177
+ return false;
178
+ }
179
+ else if (options.force ||
180
+ (!options.nonInteractive &&
181
+ (await (0, prompt_1.confirm)({
182
+ ...options,
183
+ message: "Would you like to delete and recreate these connectors?",
184
+ })))) {
185
+ return true;
186
+ }
187
+ return false;
188
+ }
189
+ async function deleteInvalidConnectors(invalidConnectors) {
190
+ return Promise.all(invalidConnectors.map(client_1.deleteConnector));
191
+ }
192
+ function displayInvalidConnectors(invalidConnectors) {
193
+ const connectorIds = invalidConnectors.map((i) => i.split("/").pop()).join(", ");
194
+ (0, utils_1.logLabeledWarning)("dataconnect", `The schema you are deploying is incompatible with the following existing connectors: ${connectorIds}.`);
195
+ (0, utils_1.logLabeledWarning)("dataconnect", `This is a ${clc.red("breaking")} change and will cause a brief downtime.`);
196
+ }
197
+ async function ensureServiceIsConnectedToCloudSql(serviceName, instanceId, databaseId) {
198
+ let currentSchema;
199
+ try {
200
+ currentSchema = await (0, client_1.getSchema)(serviceName);
201
+ }
202
+ catch (err) {
203
+ if (err.status === 404) {
204
+ currentSchema = {
205
+ name: `${serviceName}/schemas/${types_1.SCHEMA_ID}`,
206
+ source: {
207
+ files: [],
208
+ },
209
+ primaryDatasource: {
210
+ postgresql: {
211
+ database: databaseId,
212
+ cloudSql: {
213
+ instance: instanceId,
214
+ },
215
+ },
216
+ },
217
+ };
218
+ }
219
+ else {
220
+ throw err;
221
+ }
222
+ }
223
+ if (!currentSchema.primaryDatasource.postgresql ||
224
+ currentSchema.primaryDatasource.postgresql.schemaValidation === "STRICT") {
225
+ return;
226
+ }
227
+ currentSchema.primaryDatasource.postgresql.schemaValidation = "STRICT";
228
+ try {
229
+ await (0, client_1.upsertSchema)(currentSchema, false);
230
+ }
231
+ catch (err) {
232
+ if (err.status >= 500) {
233
+ throw err;
234
+ }
235
+ logger_1.logger.debug(err);
236
+ }
237
+ }
238
+ function displaySchemaChanges(error) {
239
+ const message = "Your new schema is incompatible with the schema of your CloudSQL database. " +
240
+ "The following SQL statements will migrate your database schema to match your new Data Connect schema.\n" +
241
+ error.diffs.map(toString).join("\n");
242
+ (0, utils_1.logLabeledWarning)("dataconnect", message);
243
+ }
244
+ function toString(diff) {
245
+ return `\/** ${diff.destructive ? clc.red("Destructive: ") : ""}${diff.description}*\/\n${(0, sql_formatter_1.format)(diff.sql, { language: "postgresql" })}`;
246
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toDatasource = exports.requiresVector = exports.SCHEMA_ID = void 0;
4
+ exports.SCHEMA_ID = "main";
5
+ function requiresVector(dm) {
6
+ return dm?.primaryDataSource?.postgres?.requiredExtensions?.includes("vector") ?? false;
7
+ }
8
+ exports.requiresVector = requiresVector;
9
+ function toDatasource(projectId, locationId, ds) {
10
+ if (ds.postgresql) {
11
+ return {
12
+ postgresql: {
13
+ database: ds.postgresql.database,
14
+ cloudSql: {
15
+ instance: `projects/${projectId}/locations/${locationId}/instances/${ds.postgresql.cloudSql.instanceId}`,
16
+ },
17
+ },
18
+ };
19
+ }
20
+ return {};
21
+ }
22
+ exports.toDatasource = toDatasource;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const client = require("../../dataconnect/client");
4
+ const utils = require("../../utils");
5
+ const types_1 = require("../../dataconnect/types");
6
+ const projectUtils_1 = require("../../projectUtils");
7
+ const provisionCloudSql_1 = require("../../dataconnect/provisionCloudSql");
8
+ const names_1 = require("../../dataconnect/names");
9
+ const api_1 = require("../../api");
10
+ const ensureApiEnabled = require("../../ensureApiEnabled");
11
+ async function default_1(context, options) {
12
+ const projectId = (0, projectUtils_1.needProjectId)(options);
13
+ const serviceInfos = context.dataconnect.serviceInfos;
14
+ const services = await client.listAllServices(projectId);
15
+ const filters = context.dataconnect.filters;
16
+ if (serviceInfos.some((si) => {
17
+ return (0, types_1.requiresVector)(si.deploymentMetadata);
18
+ })) {
19
+ await ensureApiEnabled.ensure(projectId, (0, api_1.vertexAIOrigin)(), "dataconnect");
20
+ }
21
+ const servicesToCreate = serviceInfos
22
+ .filter((si) => !services.some((s) => matches(si, s)))
23
+ .filter((si) => {
24
+ return !filters || filters?.some((f) => si.dataConnectYaml.serviceId === f.serviceId);
25
+ });
26
+ const servicesToDelete = filters
27
+ ? []
28
+ : services.filter((s) => !serviceInfos.some((si) => matches(si, s)));
29
+ await Promise.all(servicesToCreate.map(async (s) => {
30
+ const { projectId, locationId, serviceId } = splitName(s.serviceName);
31
+ await client.createService(projectId, locationId, serviceId);
32
+ utils.logLabeledSuccess("dataconnect", `Created service ${s.serviceName}`);
33
+ }));
34
+ if (servicesToDelete.length) {
35
+ const warning = `The following services exist on ${projectId} but are not listed in your 'firebase.json'\n${servicesToDelete
36
+ .map((s) => s.name)
37
+ .join("\n")}\nConsider deleting these via the Firebase console if they are no longer needed.`;
38
+ utils.logLabeledWarning("dataconnect", warning);
39
+ }
40
+ utils.logLabeledBullet("dataconnect", "Checking for CloudSQL resources...");
41
+ await Promise.all(serviceInfos
42
+ .filter((si) => {
43
+ return !filters || filters?.some((f) => si.dataConnectYaml.serviceId === f.serviceId);
44
+ })
45
+ .map(async (s) => {
46
+ const instanceId = s.schema.primaryDatasource.postgresql?.cloudSql.instance
47
+ .split("/")
48
+ .pop();
49
+ const databaseId = s.schema.primaryDatasource.postgresql?.database;
50
+ if (!instanceId || !databaseId) {
51
+ return Promise.resolve();
52
+ }
53
+ const enableGoogleMlIntegration = (0, types_1.requiresVector)(s.deploymentMetadata);
54
+ return (0, provisionCloudSql_1.provisionCloudSql)({
55
+ projectId,
56
+ locationId: (0, names_1.parseServiceName)(s.serviceName).location,
57
+ instanceId,
58
+ databaseId,
59
+ enableGoogleMlIntegration,
60
+ });
61
+ }));
62
+ return;
63
+ }
64
+ exports.default = default_1;
65
+ function matches(si, s) {
66
+ return si.serviceName === s.name;
67
+ }
68
+ function splitName(serviceName) {
69
+ const parts = serviceName.split("/");
70
+ return {
71
+ projectId: parts[1],
72
+ locationId: parts[3],
73
+ serviceId: parts[5],
74
+ };
75
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.release = exports.deploy = exports.prepare = void 0;
4
+ const prepare_1 = require("./prepare");
5
+ exports.prepare = prepare_1.default;
6
+ const deploy_1 = require("./deploy");
7
+ exports.deploy = deploy_1.default;
8
+ const release_1 = require("./release");
9
+ exports.release = release_1.default;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const path = require("path");
4
+ const load_1 = require("../../dataconnect/load");
5
+ const fileUtils_1 = require("../../dataconnect/fileUtils");
6
+ const logger_1 = require("../../logger");
7
+ const utils = require("../../utils");
8
+ const projectUtils_1 = require("../../projectUtils");
9
+ const filters_1 = require("../../dataconnect/filters");
10
+ const build_1 = require("../../dataconnect/build");
11
+ const ensureApis_1 = require("../../dataconnect/ensureApis");
12
+ const requireTosAcceptance_1 = require("../../requireTosAcceptance");
13
+ const firedata_1 = require("../../gcp/firedata");
14
+ async function default_1(context, options) {
15
+ const projectId = (0, projectUtils_1.needProjectId)(options);
16
+ await (0, ensureApis_1.ensureApis)(projectId);
17
+ await (0, requireTosAcceptance_1.requireTosAcceptance)(firedata_1.DATA_CONNECT_TOS_ID)(options);
18
+ const serviceCfgs = (0, fileUtils_1.readFirebaseJson)(options.config);
19
+ utils.logLabeledBullet("dataconnect", `Preparing to deploy`);
20
+ const filters = (0, filters_1.getResourceFilters)(options);
21
+ const serviceInfos = await Promise.all(serviceCfgs.map((c) => (0, load_1.load)(projectId, c.location, path.join(options.cwd || process.cwd(), c.source))));
22
+ for (const si of serviceInfos) {
23
+ si.deploymentMetadata = await (0, build_1.build)(options, si.sourceDirectory);
24
+ }
25
+ context.dataconnect = {
26
+ serviceInfos,
27
+ filters,
28
+ };
29
+ utils.logLabeledBullet("dataconnect", `Successfully prepared schema and connectors`);
30
+ logger_1.logger.debug(JSON.stringify(context.dataconnect, null, 2));
31
+ return;
32
+ }
33
+ exports.default = default_1;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const utils = require("../../utils");
4
+ const client_1 = require("../../dataconnect/client");
5
+ const prompts_1 = require("../../dataconnect/prompts");
6
+ const schemaMigration_1 = require("../../dataconnect/schemaMigration");
7
+ async function default_1(context, options) {
8
+ const serviceInfos = context.dataconnect.serviceInfos;
9
+ const filters = context.dataconnect.filters;
10
+ const wantSchemas = serviceInfos
11
+ .filter((si) => {
12
+ return (!filters ||
13
+ filters.some((f) => {
14
+ return f.serviceId === si.dataConnectYaml.serviceId && (f.schemaOnly || f.fullService);
15
+ }));
16
+ })
17
+ .map((s) => s.schema);
18
+ if (wantSchemas.length) {
19
+ utils.logLabeledBullet("dataconnect", "Releasing Data Connect schemas...");
20
+ for (const s of wantSchemas) {
21
+ await (0, schemaMigration_1.migrateSchema)({
22
+ options,
23
+ schema: s,
24
+ allowNonInteractiveMigration: false,
25
+ validateOnly: false,
26
+ });
27
+ }
28
+ utils.logLabeledBullet("dataconnect", "Schemas released.");
29
+ }
30
+ let wantConnectors = [];
31
+ wantConnectors = wantConnectors.concat(...serviceInfos.map((si) => si.connectorInfo
32
+ .filter((c) => {
33
+ return (!filters ||
34
+ filters.some((f) => {
35
+ return (f.serviceId === si.dataConnectYaml.serviceId &&
36
+ (f.connectorId === c.connectorYaml.connectorId || f.fullService));
37
+ }));
38
+ })
39
+ .map((c) => c.connector)));
40
+ const haveConnectors = await have(serviceInfos);
41
+ const connectorsToDelete = filters
42
+ ? []
43
+ : haveConnectors.filter((h) => !wantConnectors.some((w) => w.name === h.name));
44
+ if (wantConnectors.length) {
45
+ utils.logLabeledBullet("dataconnect", "Releasing connectors...");
46
+ await Promise.all(wantConnectors.map(async (c) => {
47
+ await (0, client_1.upsertConnector)(c);
48
+ utils.logLabeledSuccess("dataconnect", `Deployed connector ${c.name}`);
49
+ }));
50
+ for (const c of connectorsToDelete) {
51
+ await (0, prompts_1.promptDeleteConnector)(options, c.name);
52
+ }
53
+ utils.logLabeledBullet("dataconnect", "Connectors released.");
54
+ }
55
+ utils.logLabeledSuccess("dataconnect", "Deploy complete!");
56
+ return;
57
+ }
58
+ exports.default = default_1;
59
+ async function have(serviceInfos) {
60
+ let connectors = [];
61
+ for (const si of serviceInfos) {
62
+ connectors = connectors.concat(await (0, client_1.listConnectors)(si.serviceName));
63
+ }
64
+ return connectors;
65
+ }
@@ -27,9 +27,11 @@ async function default_1(context, options) {
27
27
  const targets = options.only.split(",");
28
28
  const excludeRules = targets.indexOf("firestore:indexes") >= 0;
29
29
  const excludeIndexes = targets.indexOf("firestore:rules") >= 0;
30
+ const includeRules = targets.indexOf("firestore:rules") >= 0;
31
+ const includeIndexes = targets.indexOf("firestore:indexes") >= 0;
30
32
  const onlyFirestore = targets.indexOf("firestore") >= 0;
31
- context.firestoreIndexes = !excludeIndexes || onlyFirestore;
32
- context.firestoreRules = !excludeRules || onlyFirestore;
33
+ context.firestoreIndexes = !excludeIndexes || includeIndexes || onlyFirestore;
34
+ context.firestoreRules = !excludeRules || includeRules || onlyFirestore;
33
35
  }
34
36
  else {
35
37
  context.firestoreIndexes = true;