firebase-tools-with-isolate 13.0.2 → 13.3.1
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/README.md +6 -2
- package/lib/appdistribution/client.js +36 -28
- package/lib/appdistribution/options-parser-util.js +80 -1
- package/lib/appdistribution/types.js +31 -0
- package/lib/auth.js +11 -2
- package/lib/commands/appdistribution-distribute.js +70 -10
- package/lib/commands/apphosting-backends-create.js +6 -3
- package/lib/commands/apphosting-backends-delete.js +3 -5
- package/lib/commands/apphosting-backends-get.js +2 -2
- package/lib/commands/apphosting-backends-list.js +21 -37
- package/lib/commands/apphosting-builds-create.js +8 -8
- package/lib/commands/apphosting-builds-get.js +2 -2
- package/lib/commands/apphosting-rollouts-create.js +5 -5
- package/lib/commands/apphosting-rollouts-list.js +6 -3
- package/lib/commands/firestore-backups-delete.js +44 -0
- package/lib/commands/firestore-backups-get.js +25 -0
- package/lib/commands/firestore-backups-list.js +33 -0
- package/lib/commands/firestore-backups-schedules-create.js +67 -0
- package/lib/commands/firestore-backups-schedules-delete.js +46 -0
- package/lib/commands/firestore-backups-schedules-list.js +27 -0
- package/lib/commands/firestore-backups-schedules-update.js +33 -0
- package/lib/commands/firestore-databases-create.js +4 -2
- package/lib/commands/firestore-databases-delete.js +4 -2
- package/lib/commands/firestore-databases-get.js +3 -1
- package/lib/commands/firestore-databases-list.js +3 -1
- package/lib/commands/firestore-databases-restore.js +42 -0
- package/lib/commands/firestore-databases-update.js +4 -2
- package/lib/commands/firestore-indexes-list.js +5 -3
- package/lib/commands/firestore-locations.js +3 -1
- package/lib/commands/functions-config-export.js +4 -2
- package/lib/commands/index.js +11 -1
- package/lib/commands/init.js +3 -3
- package/lib/commands/use.js +4 -1
- package/lib/deploy/functions/runtimes/index.js +2 -0
- package/lib/deploy/functions/runtimes/python/index.js +4 -1
- package/lib/deploy/functions/services/firestore.js +1 -1
- package/lib/deploy/hosting/convertConfig.js +5 -0
- package/lib/deploy/hosting/prepare.js +2 -1
- package/lib/emulator/auth/handlers.js +1 -1
- package/lib/emulator/auth/operations.js +42 -13
- package/lib/emulator/auth/state.js +14 -0
- package/lib/emulator/downloadableEmulators.js +3 -3
- package/lib/emulator/storage/metadata.js +1 -1
- package/lib/emulator/storage/rules/runtime.js +1 -1
- package/lib/experiments.js +2 -2
- package/lib/firestore/api-sort.js +23 -1
- package/lib/firestore/api-types.js +6 -1
- package/lib/firestore/api.js +18 -115
- package/lib/firestore/backupUtils.js +30 -0
- package/lib/firestore/delete.js +3 -3
- package/lib/firestore/pretty-print.js +184 -0
- package/lib/frameworks/angular/index.js +2 -2
- package/lib/frameworks/angular/utils.js +14 -10
- package/lib/frameworks/astro/index.js +1 -2
- package/lib/frameworks/flutter/index.js +1 -1
- package/lib/frameworks/index.js +2 -3
- package/lib/frameworks/next/index.js +5 -3
- package/lib/frameworks/nuxt/index.js +2 -2
- package/lib/frameworks/nuxt2/index.js +1 -2
- package/lib/frameworks/sveltekit/index.js +2 -2
- package/lib/frameworks/utils.js +11 -2
- package/lib/frameworks/vite/index.js +8 -4
- package/lib/functions/env.js +2 -0
- package/lib/gcp/apphosting.js +103 -17
- package/lib/gcp/cloudbuild.js +7 -2
- package/lib/gcp/cloudfunctionsv2.js +2 -4
- package/lib/gcp/firestore.js +89 -6
- package/lib/hosting/api.js +3 -9
- package/lib/hosting/options.js +2 -1
- package/lib/init/features/apphosting/index.js +150 -68
- package/lib/init/features/apphosting/repo.js +80 -32
- package/lib/init/features/hosting/github.js +6 -1
- package/lib/metaprogramming.js +3 -0
- package/lib/prompt.js +1 -0
- package/lib/utils.js +1 -12
- package/package.json +15 -10
package/lib/commands/use.js
CHANGED
|
@@ -70,7 +70,10 @@ exports.command = new command_1.Command("use [alias_or_project_id]")
|
|
|
70
70
|
}
|
|
71
71
|
if (hasAlias) {
|
|
72
72
|
if (!project) {
|
|
73
|
-
return utils.reject("Unable to use alias " +
|
|
73
|
+
return utils.reject("Unable to use alias " +
|
|
74
|
+
clc.bold(newActive) +
|
|
75
|
+
", " +
|
|
76
|
+
verifyMessage(resolvedProject));
|
|
74
77
|
}
|
|
75
78
|
utils.makeActiveProject(options.projectRoot, newActive);
|
|
76
79
|
logger_1.logger.info("Now using alias", clc.bold(newActive), "(" + resolvedProject + ")");
|
|
@@ -14,6 +14,7 @@ const RUNTIMES = [
|
|
|
14
14
|
"nodejs20",
|
|
15
15
|
"python310",
|
|
16
16
|
"python311",
|
|
17
|
+
"python312",
|
|
17
18
|
];
|
|
18
19
|
const EXPERIMENTAL_RUNTIMES = [];
|
|
19
20
|
const DEPRECATED_RUNTIMES = ["nodejs6", "nodejs8"];
|
|
@@ -36,6 +37,7 @@ const MESSAGE_FRIENDLY_RUNTIMES = {
|
|
|
36
37
|
nodejs20: "Node.js 20",
|
|
37
38
|
python310: "Python 3.10",
|
|
38
39
|
python311: "Python 3.11",
|
|
40
|
+
python312: "Python 3.12",
|
|
39
41
|
};
|
|
40
42
|
function getHumanFriendlyRuntimeName(runtime) {
|
|
41
43
|
return MESSAGE_FRIENDLY_RUNTIMES[runtime] || runtime;
|
|
@@ -11,7 +11,7 @@ const discovery = require("../discovery");
|
|
|
11
11
|
const logger_1 = require("../../../../logger");
|
|
12
12
|
const python_1 = require("../../../../functions/python");
|
|
13
13
|
const error_1 = require("../../../../error");
|
|
14
|
-
exports.LATEST_VERSION = "
|
|
14
|
+
exports.LATEST_VERSION = "python312";
|
|
15
15
|
async function tryCreateDelegate(context) {
|
|
16
16
|
const requirementsTextPath = path.join(context.sourceDir, "requirements.txt");
|
|
17
17
|
if (!(await (0, util_1.promisify)(fs.exists)(requirementsTextPath))) {
|
|
@@ -35,6 +35,9 @@ function getPythonBinary(runtime) {
|
|
|
35
35
|
else if (runtime === "python311") {
|
|
36
36
|
return "python3.11";
|
|
37
37
|
}
|
|
38
|
+
else if (runtime === "python312") {
|
|
39
|
+
return "python3.12";
|
|
40
|
+
}
|
|
38
41
|
return "python";
|
|
39
42
|
}
|
|
40
43
|
exports.getPythonBinary = getPythonBinary;
|
|
@@ -9,7 +9,7 @@ async function getDatabase(project, databaseId) {
|
|
|
9
9
|
if (dbCache.has(key)) {
|
|
10
10
|
return dbCache.get(key);
|
|
11
11
|
}
|
|
12
|
-
const db = await firestore.getDatabase(project, databaseId);
|
|
12
|
+
const db = await firestore.getDatabase(project, databaseId, false);
|
|
13
13
|
dbCache.set(key, db);
|
|
14
14
|
return db;
|
|
15
15
|
}
|
|
@@ -133,6 +133,11 @@ async function convertConfig(context, functionsPayload, deploy) {
|
|
|
133
133
|
},
|
|
134
134
|
};
|
|
135
135
|
if (rewrite.function.pinTag) {
|
|
136
|
+
if (endpoint.minInstances) {
|
|
137
|
+
throw new error_1.FirebaseError(`Function ${endpoint.id} has minInstances set and is in a rewrite ` +
|
|
138
|
+
"pinTags=true. These features are not currently compatible with each " +
|
|
139
|
+
"other.");
|
|
140
|
+
}
|
|
136
141
|
experiments.assertEnabled("pintags", "pin a function version");
|
|
137
142
|
apiRewrite.run.tag = runTags.TODO_TAG_NAME;
|
|
138
143
|
}
|
|
@@ -155,7 +155,8 @@ async function unsafePins(context, config) {
|
|
|
155
155
|
const existingUntaggedRewrites = {};
|
|
156
156
|
for (const rewrite of channelConfig?.release?.version?.config?.rewrites || []) {
|
|
157
157
|
if ("run" in rewrite && !rewrite.run.tag) {
|
|
158
|
-
existingUntaggedRewrites[rewriteTarget(rewrite)] =
|
|
158
|
+
existingUntaggedRewrites[rewriteTarget(rewrite)] =
|
|
159
|
+
`${rewrite.run.region}/${rewrite.run.serviceId}`;
|
|
159
160
|
}
|
|
160
161
|
}
|
|
161
162
|
return Object.keys(targetTaggedRewrites).filter((target) => targetTaggedRewrites[target] === existingUntaggedRewrites[target]);
|
|
@@ -159,7 +159,7 @@ function registerHandlers(app, getProjectStateByApiKey) {
|
|
|
159
159
|
res.set("Content-Type", "text/html; charset=utf-8");
|
|
160
160
|
const apiKey = req.query.apiKey;
|
|
161
161
|
const providerId = req.query.providerId;
|
|
162
|
-
const tenantId = req.query.tenantId;
|
|
162
|
+
const tenantId = (req.query.tenantId || req.query.tid);
|
|
163
163
|
if (!apiKey || !providerId) {
|
|
164
164
|
return res.status(400).json({
|
|
165
165
|
authEmulator: {
|
|
@@ -485,13 +485,21 @@ function createAuthUri(state, reqBody) {
|
|
|
485
485
|
}
|
|
486
486
|
}
|
|
487
487
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
488
|
+
if (state.enableImprovedEmailPrivacy) {
|
|
489
|
+
return {
|
|
490
|
+
kind: "identitytoolkit#CreateAuthUriResponse",
|
|
491
|
+
sessionId,
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
else {
|
|
495
|
+
return {
|
|
496
|
+
kind: "identitytoolkit#CreateAuthUriResponse",
|
|
497
|
+
registered,
|
|
498
|
+
allProviders,
|
|
499
|
+
sessionId,
|
|
500
|
+
signinMethods,
|
|
501
|
+
};
|
|
502
|
+
}
|
|
495
503
|
}
|
|
496
504
|
const SESSION_COOKIE_MIN_VALID_DURATION = 5 * 60;
|
|
497
505
|
exports.SESSION_COOKIE_MAX_VALID_DURATION = 14 * 24 * 60 * 60;
|
|
@@ -636,7 +644,14 @@ function sendOobCode(state, reqBody, ctx) {
|
|
|
636
644
|
mode = "resetPassword";
|
|
637
645
|
(0, errors_1.assert)(reqBody.email, "MISSING_EMAIL");
|
|
638
646
|
email = (0, utils_1.canonicalizeEmailAddress)(reqBody.email);
|
|
639
|
-
|
|
647
|
+
const maybeUser = state.getUserByEmail(email);
|
|
648
|
+
if (state.enableImprovedEmailPrivacy && !maybeUser) {
|
|
649
|
+
return {
|
|
650
|
+
kind: "identitytoolkit#GetOobConfirmationCodeResponse",
|
|
651
|
+
email,
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
(0, errors_1.assert)(maybeUser, "EMAIL_NOT_FOUND");
|
|
640
655
|
break;
|
|
641
656
|
case "VERIFY_EMAIL":
|
|
642
657
|
mode = "verifyEmail";
|
|
@@ -1168,7 +1183,7 @@ async function signInWithIdp(state, reqBody) {
|
|
|
1168
1183
|
}
|
|
1169
1184
|
else {
|
|
1170
1185
|
if (!response.localId) {
|
|
1171
|
-
throw new Error("Internal assertion error: localId not set for
|
|
1186
|
+
throw new Error("Internal assertion error: localId not set for existing user.");
|
|
1172
1187
|
}
|
|
1173
1188
|
const maybeUser = state.getUserByLocalId(response.localId);
|
|
1174
1189
|
(0, errors_1.assert)(maybeUser, "USER_NOT_FOUND");
|
|
@@ -1219,10 +1234,18 @@ async function signInWithPassword(state, reqBody) {
|
|
|
1219
1234
|
}
|
|
1220
1235
|
const email = (0, utils_1.canonicalizeEmailAddress)(reqBody.email);
|
|
1221
1236
|
let user = state.getUserByEmail(email);
|
|
1222
|
-
(
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1237
|
+
if (state.enableImprovedEmailPrivacy) {
|
|
1238
|
+
(0, errors_1.assert)(user, "INVALID_LOGIN_CREDENTIALS");
|
|
1239
|
+
(0, errors_1.assert)(!user.disabled, "USER_DISABLED");
|
|
1240
|
+
(0, errors_1.assert)(user.passwordHash && user.salt, "INVALID_LOGIN_CREDENTIALS");
|
|
1241
|
+
(0, errors_1.assert)(user.passwordHash === hashPassword(reqBody.password, user.salt), "INVALID_LOGIN_CREDENTIALS");
|
|
1242
|
+
}
|
|
1243
|
+
else {
|
|
1244
|
+
(0, errors_1.assert)(user, "EMAIL_NOT_FOUND");
|
|
1245
|
+
(0, errors_1.assert)(!user.disabled, "USER_DISABLED");
|
|
1246
|
+
(0, errors_1.assert)(user.passwordHash && user.salt, "INVALID_PASSWORD");
|
|
1247
|
+
(0, errors_1.assert)(user.passwordHash === hashPassword(reqBody.password, user.salt), "INVALID_PASSWORD");
|
|
1248
|
+
}
|
|
1226
1249
|
const response = {
|
|
1227
1250
|
kind: "identitytoolkit#VerifyPasswordResponse",
|
|
1228
1251
|
registered: true,
|
|
@@ -1339,6 +1362,9 @@ function getEmulatorProjectConfig(state) {
|
|
|
1339
1362
|
signIn: {
|
|
1340
1363
|
allowDuplicateEmails: !state.oneAccountPerEmail,
|
|
1341
1364
|
},
|
|
1365
|
+
emailPrivacyConfig: {
|
|
1366
|
+
enableImprovedEmailPrivacy: state.enableImprovedEmailPrivacy,
|
|
1367
|
+
},
|
|
1342
1368
|
};
|
|
1343
1369
|
}
|
|
1344
1370
|
function updateEmulatorProjectConfig(state, reqBody, ctx) {
|
|
@@ -1346,6 +1372,9 @@ function updateEmulatorProjectConfig(state, reqBody, ctx) {
|
|
|
1346
1372
|
if (reqBody.signIn?.allowDuplicateEmails != null) {
|
|
1347
1373
|
updateMask.push("signIn.allowDuplicateEmails");
|
|
1348
1374
|
}
|
|
1375
|
+
if (reqBody.emailPrivacyConfig?.enableImprovedEmailPrivacy != null) {
|
|
1376
|
+
updateMask.push("emailPrivacyConfig.enableImprovedEmailPrivacy");
|
|
1377
|
+
}
|
|
1349
1378
|
ctx.params.query.updateMask = updateMask.join();
|
|
1350
1379
|
updateConfig(state, reqBody, ctx);
|
|
1351
1380
|
return getEmulatorProjectConfig(state);
|
|
@@ -408,6 +408,9 @@ class AgentProjectState extends ProjectState {
|
|
|
408
408
|
this._config = {
|
|
409
409
|
signIn: { allowDuplicateEmails: false },
|
|
410
410
|
blockingFunctions: {},
|
|
411
|
+
emailPrivacyConfig: {
|
|
412
|
+
enableImprovedEmailPrivacy: false,
|
|
413
|
+
},
|
|
411
414
|
};
|
|
412
415
|
}
|
|
413
416
|
get authCloudFunction() {
|
|
@@ -419,6 +422,12 @@ class AgentProjectState extends ProjectState {
|
|
|
419
422
|
set oneAccountPerEmail(oneAccountPerEmail) {
|
|
420
423
|
this._config.signIn.allowDuplicateEmails = !oneAccountPerEmail;
|
|
421
424
|
}
|
|
425
|
+
get enableImprovedEmailPrivacy() {
|
|
426
|
+
return !!this._config.emailPrivacyConfig.enableImprovedEmailPrivacy;
|
|
427
|
+
}
|
|
428
|
+
set enableImprovedEmailPrivacy(improveEmailPrivacy) {
|
|
429
|
+
this._config.emailPrivacyConfig.enableImprovedEmailPrivacy = improveEmailPrivacy;
|
|
430
|
+
}
|
|
422
431
|
get allowPasswordSignup() {
|
|
423
432
|
return true;
|
|
424
433
|
}
|
|
@@ -466,6 +475,8 @@ class AgentProjectState extends ProjectState {
|
|
|
466
475
|
if (!updateMask) {
|
|
467
476
|
this.oneAccountPerEmail = !update.signIn?.allowDuplicateEmails ?? true;
|
|
468
477
|
this.blockingFunctionsConfig = update.blockingFunctions ?? {};
|
|
478
|
+
this.enableImprovedEmailPrivacy =
|
|
479
|
+
update.emailPrivacyConfig?.enableImprovedEmailPrivacy ?? false;
|
|
469
480
|
return this.config;
|
|
470
481
|
}
|
|
471
482
|
return applyMask(updateMask, this.config, update);
|
|
@@ -538,6 +549,9 @@ class TenantProjectState extends ProjectState {
|
|
|
538
549
|
get oneAccountPerEmail() {
|
|
539
550
|
return this.parentProject.oneAccountPerEmail;
|
|
540
551
|
}
|
|
552
|
+
get enableImprovedEmailPrivacy() {
|
|
553
|
+
return this.parentProject.enableImprovedEmailPrivacy;
|
|
554
|
+
}
|
|
541
555
|
get authCloudFunction() {
|
|
542
556
|
return this.parentProject.authCloudFunction;
|
|
543
557
|
}
|
|
@@ -23,9 +23,9 @@ const EMULATOR_UPDATE_DETAILS = {
|
|
|
23
23
|
expectedChecksum: "2fd771101c0e1f7898c04c9204f2ce63",
|
|
24
24
|
},
|
|
25
25
|
firestore: {
|
|
26
|
-
version: "1.
|
|
27
|
-
expectedSize:
|
|
28
|
-
expectedChecksum: "
|
|
26
|
+
version: "1.19.1",
|
|
27
|
+
expectedSize: 67187672,
|
|
28
|
+
expectedChecksum: "859b1ac2a6040cccddd993c43586347c",
|
|
29
29
|
},
|
|
30
30
|
storage: {
|
|
31
31
|
version: "1.1.3",
|
|
@@ -250,7 +250,7 @@ class CloudStorageBucketMetadata {
|
|
|
250
250
|
this.location = "US";
|
|
251
251
|
this.storageClass = "STANDARD";
|
|
252
252
|
this.etag = "====";
|
|
253
|
-
this.locationType = "
|
|
253
|
+
this.locationType = "multi-region";
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
256
|
exports.CloudStorageBucketMetadata = CloudStorageBucketMetadata;
|
|
@@ -333,7 +333,7 @@ function createAuthExpressionValue(opts) {
|
|
|
333
333
|
return toExpressionValue(null);
|
|
334
334
|
}
|
|
335
335
|
else {
|
|
336
|
-
const tokenPayload = jwt.decode(opts.token);
|
|
336
|
+
const tokenPayload = jwt.decode(opts.token, { json: true });
|
|
337
337
|
const jsonValue = {
|
|
338
338
|
uid: tokenPayload.user_id,
|
|
339
339
|
token: tokenPayload,
|
package/lib/experiments.js
CHANGED
|
@@ -72,9 +72,9 @@ exports.ALL_EXPERIMENTS = experiments({
|
|
|
72
72
|
"These commands are not meant for public consumption and may break or disappear " +
|
|
73
73
|
"without a notice.",
|
|
74
74
|
},
|
|
75
|
-
|
|
75
|
+
apphosting: {
|
|
76
76
|
shortDescription: "Allow CLI option for Frameworks",
|
|
77
|
-
default:
|
|
77
|
+
default: false,
|
|
78
78
|
public: false,
|
|
79
79
|
},
|
|
80
80
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compareFieldOverride = exports.compareApiField = exports.compareLocation = exports.compareApiDatabase = exports.compareApiIndex = exports.compareSpecIndex = void 0;
|
|
3
|
+
exports.compareFieldOverride = exports.compareApiField = exports.compareApiBackupSchedule = exports.compareApiBackup = exports.compareLocation = exports.compareApiDatabase = exports.compareApiIndex = exports.compareSpecIndex = void 0;
|
|
4
4
|
const API = require("./api-types");
|
|
5
5
|
const util = require("./util");
|
|
6
6
|
const QUERY_SCOPE_SEQUENCE = [
|
|
@@ -42,6 +42,28 @@ function compareLocation(a, b) {
|
|
|
42
42
|
return a.locationId > b.locationId ? 1 : -1;
|
|
43
43
|
}
|
|
44
44
|
exports.compareLocation = compareLocation;
|
|
45
|
+
function compareApiBackup(a, b) {
|
|
46
|
+
const aLocation = a.name.split("/")[3];
|
|
47
|
+
const bLocation = b.name.split("/")[3];
|
|
48
|
+
if (aLocation && bLocation && aLocation !== bLocation) {
|
|
49
|
+
return aLocation > bLocation ? 1 : -1;
|
|
50
|
+
}
|
|
51
|
+
if (a.snapshotTime && b.snapshotTime && a.snapshotTime !== b.snapshotTime) {
|
|
52
|
+
return a.snapshotTime > b.snapshotTime ? -1 : 1;
|
|
53
|
+
}
|
|
54
|
+
return a.name > b.name ? 1 : -1;
|
|
55
|
+
}
|
|
56
|
+
exports.compareApiBackup = compareApiBackup;
|
|
57
|
+
function compareApiBackupSchedule(a, b) {
|
|
58
|
+
if (a.dailyRecurrence && !b.dailyRecurrence) {
|
|
59
|
+
return -1;
|
|
60
|
+
}
|
|
61
|
+
else if (a.weeklyRecurrence && b.dailyRecurrence) {
|
|
62
|
+
return 1;
|
|
63
|
+
}
|
|
64
|
+
return a.name > b.name ? 1 : -1;
|
|
65
|
+
}
|
|
66
|
+
exports.compareApiBackupSchedule = compareApiBackupSchedule;
|
|
45
67
|
function compareApiField(a, b) {
|
|
46
68
|
const aName = util.parseFieldName(a.name);
|
|
47
69
|
const bName = util.parseFieldName(b.name);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PointInTimeRecoveryEnablement = exports.PointInTimeRecoveryEnablementOption = exports.DatabaseDeleteProtectionState = exports.DatabaseDeleteProtectionStateOption = exports.DatabaseType = exports.StateTtl = exports.State = exports.ArrayConfig = exports.Order = exports.QueryScope = exports.Mode = void 0;
|
|
3
|
+
exports.RecurrenceType = exports.PointInTimeRecoveryEnablement = exports.PointInTimeRecoveryEnablementOption = exports.DatabaseDeleteProtectionState = exports.DatabaseDeleteProtectionStateOption = exports.DatabaseType = exports.StateTtl = exports.State = exports.ArrayConfig = exports.Order = exports.QueryScope = exports.Mode = void 0;
|
|
4
4
|
var Mode;
|
|
5
5
|
(function (Mode) {
|
|
6
6
|
Mode["ASCENDING"] = "ASCENDING";
|
|
@@ -58,3 +58,8 @@ var PointInTimeRecoveryEnablement;
|
|
|
58
58
|
PointInTimeRecoveryEnablement["ENABLED"] = "POINT_IN_TIME_RECOVERY_ENABLED";
|
|
59
59
|
PointInTimeRecoveryEnablement["DISABLED"] = "POINT_IN_TIME_RECOVERY_DISABLED";
|
|
60
60
|
})(PointInTimeRecoveryEnablement = exports.PointInTimeRecoveryEnablement || (exports.PointInTimeRecoveryEnablement = {}));
|
|
61
|
+
var RecurrenceType;
|
|
62
|
+
(function (RecurrenceType) {
|
|
63
|
+
RecurrenceType["DAILY"] = "DAILY";
|
|
64
|
+
RecurrenceType["WEEKLY"] = "WEEKLY";
|
|
65
|
+
})(RecurrenceType = exports.RecurrenceType || (exports.RecurrenceType = {}));
|
package/lib/firestore/api.js
CHANGED
|
@@ -12,9 +12,11 @@ const prompt_1 = require("../prompt");
|
|
|
12
12
|
const api_1 = require("../api");
|
|
13
13
|
const error_1 = require("../error");
|
|
14
14
|
const apiv2_1 = require("../apiv2");
|
|
15
|
+
const pretty_print_1 = require("./pretty-print");
|
|
15
16
|
class FirestoreApi {
|
|
16
17
|
constructor() {
|
|
17
18
|
this.apiClient = new apiv2_1.Client({ urlPrefix: api_1.firestoreOrigin, apiVersion: "v1" });
|
|
19
|
+
this.printer = new pretty_print_1.PrettyPrint();
|
|
18
20
|
}
|
|
19
21
|
async deploy(options, indexes, fieldOverrides, databaseId = "(default)") {
|
|
20
22
|
const spec = this.upgradeOldSpec({
|
|
@@ -49,7 +51,7 @@ class FirestoreApi {
|
|
|
49
51
|
}
|
|
50
52
|
else if (!options.force) {
|
|
51
53
|
const indexesString = indexesToDelete
|
|
52
|
-
.map((x) => this.prettyIndexString(x, false))
|
|
54
|
+
.map((x) => this.printer.prettyIndexString(x, false))
|
|
53
55
|
.join("\n\t");
|
|
54
56
|
utils.logLabeledBullet("firestore", `The following indexes are defined in your project but are not present in your firestore indexes file:\n\t${indexesString}`);
|
|
55
57
|
}
|
|
@@ -86,7 +88,7 @@ class FirestoreApi {
|
|
|
86
88
|
}
|
|
87
89
|
else if (!options.force) {
|
|
88
90
|
const indexesString = fieldOverridesToDelete
|
|
89
|
-
.map((x) => this.prettyFieldString(x))
|
|
91
|
+
.map((x) => this.printer.prettyFieldString(x))
|
|
90
92
|
.join("\n\t");
|
|
91
93
|
utils.logLabeledBullet("firestore", `The following field overrides are defined in your project but are not present in your firestore indexes file:\n\t${indexesString}`);
|
|
92
94
|
}
|
|
@@ -145,7 +147,7 @@ class FirestoreApi {
|
|
|
145
147
|
return [];
|
|
146
148
|
}
|
|
147
149
|
return fields.filter((field) => {
|
|
148
|
-
return field.name.
|
|
150
|
+
return !field.name.includes("__default__");
|
|
149
151
|
});
|
|
150
152
|
}
|
|
151
153
|
makeIndexSpec(indexes, fields) {
|
|
@@ -184,64 +186,6 @@ class FirestoreApi {
|
|
|
184
186
|
fieldOverrides: sortedFields,
|
|
185
187
|
};
|
|
186
188
|
}
|
|
187
|
-
prettyPrintIndexes(indexes) {
|
|
188
|
-
if (indexes.length === 0) {
|
|
189
|
-
logger_1.logger.info("None");
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
const sortedIndexes = indexes.sort(sort.compareApiIndex);
|
|
193
|
-
sortedIndexes.forEach((index) => {
|
|
194
|
-
logger_1.logger.info(this.prettyIndexString(index));
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
prettyPrintDatabases(databases) {
|
|
198
|
-
if (databases.length === 0) {
|
|
199
|
-
logger_1.logger.info("No databases found.");
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
const sortedDatabases = databases.sort(sort.compareApiDatabase);
|
|
203
|
-
const Table = require("cli-table");
|
|
204
|
-
const table = new Table({
|
|
205
|
-
head: ["Database Name"],
|
|
206
|
-
colWidths: [Math.max(...sortedDatabases.map((database) => database.name.length + 5), 20)],
|
|
207
|
-
});
|
|
208
|
-
table.push(...sortedDatabases.map((database) => [this.prettyDatabaseString(database)]));
|
|
209
|
-
logger_1.logger.info(table.toString());
|
|
210
|
-
}
|
|
211
|
-
prettyPrintDatabase(database) {
|
|
212
|
-
const Table = require("cli-table");
|
|
213
|
-
const table = new Table({
|
|
214
|
-
head: ["Field", "Value"],
|
|
215
|
-
colWidths: [25, Math.max(50, 5 + database.name.length)],
|
|
216
|
-
});
|
|
217
|
-
table.push(["Name", clc.yellow(database.name)], ["Create Time", clc.yellow(database.createTime)], ["Last Update Time", clc.yellow(database.updateTime)], ["Type", clc.yellow(database.type)], ["Location", clc.yellow(database.locationId)], ["Delete Protection State", clc.yellow(database.deleteProtectionState)], ["Point In Time Recovery", clc.yellow(database.pointInTimeRecoveryEnablement)], ["Earliest Version Time", clc.yellow(database.earliestVersionTime)], ["Version Retention Period", clc.yellow(database.versionRetentionPeriod)]);
|
|
218
|
-
logger_1.logger.info(table.toString());
|
|
219
|
-
}
|
|
220
|
-
prettyPrintLocations(locations) {
|
|
221
|
-
if (locations.length === 0) {
|
|
222
|
-
logger_1.logger.info("No Locations Available");
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
const Table = require("cli-table");
|
|
226
|
-
const table = new Table({
|
|
227
|
-
head: ["Display Name", "LocationId"],
|
|
228
|
-
colWidths: [20, 30],
|
|
229
|
-
});
|
|
230
|
-
table.push(...locations
|
|
231
|
-
.sort(sort.compareLocation)
|
|
232
|
-
.map((location) => [location.displayName, location.locationId]));
|
|
233
|
-
logger_1.logger.info(table.toString());
|
|
234
|
-
}
|
|
235
|
-
printFieldOverrides(fields) {
|
|
236
|
-
if (fields.length === 0) {
|
|
237
|
-
logger_1.logger.info("None");
|
|
238
|
-
return;
|
|
239
|
-
}
|
|
240
|
-
const sortedFields = fields.sort(sort.compareApiField);
|
|
241
|
-
sortedFields.forEach((field) => {
|
|
242
|
-
logger_1.logger.info(this.prettyFieldString(field));
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
189
|
validateSpec(spec) {
|
|
246
190
|
validator.assertHas(spec, "indexes");
|
|
247
191
|
spec.indexes.forEach((index) => {
|
|
@@ -391,7 +335,7 @@ class FirestoreApi {
|
|
|
391
335
|
return index.order || index.arrayConfig;
|
|
392
336
|
});
|
|
393
337
|
for (const mode of fieldModes) {
|
|
394
|
-
if (specModes.
|
|
338
|
+
if (!specModes.includes(mode)) {
|
|
395
339
|
return false;
|
|
396
340
|
}
|
|
397
341
|
}
|
|
@@ -507,60 +451,19 @@ class FirestoreApi {
|
|
|
507
451
|
}
|
|
508
452
|
return database;
|
|
509
453
|
}
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
result += clc.red(stateMsg);
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
const nameInfo = util.parseIndexName(index.name);
|
|
525
|
-
result += clc.cyan(`(${nameInfo.collectionGroupId})`);
|
|
526
|
-
result += " -- ";
|
|
527
|
-
index.fields.forEach((field) => {
|
|
528
|
-
if (field.fieldPath === "__name__") {
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
const orderOrArrayConfig = field.order ? field.order : field.arrayConfig;
|
|
532
|
-
result += `(${field.fieldPath},${orderOrArrayConfig}) `;
|
|
533
|
-
});
|
|
534
|
-
return result;
|
|
535
|
-
}
|
|
536
|
-
prettyDatabaseString(database) {
|
|
537
|
-
return clc.yellow(database.name);
|
|
538
|
-
}
|
|
539
|
-
prettyFieldString(field) {
|
|
540
|
-
let result = "";
|
|
541
|
-
const parsedName = util.parseFieldName(field.name);
|
|
542
|
-
result +=
|
|
543
|
-
"[" +
|
|
544
|
-
clc.cyan(parsedName.collectionGroupId) +
|
|
545
|
-
"." +
|
|
546
|
-
clc.yellow(parsedName.fieldPath) +
|
|
547
|
-
"] --";
|
|
548
|
-
const fieldIndexes = field.indexConfig.indexes || [];
|
|
549
|
-
if (fieldIndexes.length > 0) {
|
|
550
|
-
fieldIndexes.forEach((index) => {
|
|
551
|
-
const firstField = index.fields[0];
|
|
552
|
-
const mode = firstField.order || firstField.arrayConfig;
|
|
553
|
-
result += ` (${mode})`;
|
|
554
|
-
});
|
|
555
|
-
}
|
|
556
|
-
else {
|
|
557
|
-
result += " (no indexes)";
|
|
558
|
-
}
|
|
559
|
-
const fieldTtl = field.ttlConfig;
|
|
560
|
-
if (fieldTtl) {
|
|
561
|
-
result += ` TTL(${fieldTtl.state})`;
|
|
454
|
+
async restoreDatabase(project, databaseId, backupName) {
|
|
455
|
+
const url = `/projects/${project}/databases:restore`;
|
|
456
|
+
const payload = {
|
|
457
|
+
databaseId,
|
|
458
|
+
backup: backupName,
|
|
459
|
+
};
|
|
460
|
+
const options = { queryParams: { databaseId: databaseId } };
|
|
461
|
+
const res = await this.apiClient.post(url, payload, options);
|
|
462
|
+
const database = res.body.response;
|
|
463
|
+
if (!database) {
|
|
464
|
+
throw new error_1.FirebaseError("Not found");
|
|
562
465
|
}
|
|
563
|
-
return
|
|
466
|
+
return database;
|
|
564
467
|
}
|
|
565
468
|
}
|
|
566
469
|
exports.FirestoreApi = FirestoreApi;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateRetention = exports.Duration = exports.DURATION_REGEX = void 0;
|
|
4
|
+
const error_1 = require("../error");
|
|
5
|
+
exports.DURATION_REGEX = /^(\d+)([hdmw])$/;
|
|
6
|
+
var Duration;
|
|
7
|
+
(function (Duration) {
|
|
8
|
+
Duration[Duration["MINUTE"] = 60] = "MINUTE";
|
|
9
|
+
Duration[Duration["HOUR"] = 3600] = "HOUR";
|
|
10
|
+
Duration[Duration["DAY"] = 86400] = "DAY";
|
|
11
|
+
Duration[Duration["WEEK"] = 604800] = "WEEK";
|
|
12
|
+
})(Duration = exports.Duration || (exports.Duration = {}));
|
|
13
|
+
const DURATIONS = {
|
|
14
|
+
m: Duration.MINUTE,
|
|
15
|
+
h: Duration.HOUR,
|
|
16
|
+
d: Duration.DAY,
|
|
17
|
+
w: Duration.WEEK,
|
|
18
|
+
};
|
|
19
|
+
function calculateRetention(flag) {
|
|
20
|
+
const match = exports.DURATION_REGEX.exec(flag);
|
|
21
|
+
if (!match) {
|
|
22
|
+
throw new error_1.FirebaseError(`"retention" flag must be a duration string (e.g. 24h, 2w, or 7d)`);
|
|
23
|
+
}
|
|
24
|
+
const d = parseInt(match[1], 10) * DURATIONS[match[2]];
|
|
25
|
+
if (isNaN(d)) {
|
|
26
|
+
throw new error_1.FirebaseError(`Failed to parse provided retention time "${flag}"`);
|
|
27
|
+
}
|
|
28
|
+
return d;
|
|
29
|
+
}
|
|
30
|
+
exports.calculateRetention = calculateRetention;
|
package/lib/firestore/delete.js
CHANGED
|
@@ -219,7 +219,7 @@ class FirestoreDelete {
|
|
|
219
219
|
}
|
|
220
220
|
numPendingDeletes++;
|
|
221
221
|
firestore
|
|
222
|
-
.deleteDocuments(this.project, toDelete)
|
|
222
|
+
.deleteDocuments(this.project, toDelete, true)
|
|
223
223
|
.then((numDeleted) => {
|
|
224
224
|
FirestoreDelete.progressBar.tick(numDeleted);
|
|
225
225
|
numDocsDeleted += numDeleted;
|
|
@@ -280,7 +280,7 @@ class FirestoreDelete {
|
|
|
280
280
|
let initialDelete;
|
|
281
281
|
if (this.isDocumentPath) {
|
|
282
282
|
const doc = { name: this.root + "/" + this.path };
|
|
283
|
-
initialDelete = firestore.deleteDocument(doc).catch((err) => {
|
|
283
|
+
initialDelete = firestore.deleteDocument(doc, true).catch((err) => {
|
|
284
284
|
logger_1.logger.debug("deletePath:initialDelete:error", err);
|
|
285
285
|
if (this.allDescendants) {
|
|
286
286
|
return Promise.resolve();
|
|
@@ -297,7 +297,7 @@ class FirestoreDelete {
|
|
|
297
297
|
}
|
|
298
298
|
deleteDatabase() {
|
|
299
299
|
return firestore
|
|
300
|
-
.listCollectionIds(this.project)
|
|
300
|
+
.listCollectionIds(this.project, true)
|
|
301
301
|
.catch((err) => {
|
|
302
302
|
logger_1.logger.debug("deleteDatabase:listCollectionIds:error", err);
|
|
303
303
|
return utils.reject("Unable to list collection IDs");
|