firebase-tools-with-isolate 13.2.1-0 → 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.
Files changed (46) hide show
  1. package/lib/auth.js +11 -2
  2. package/lib/commands/apphosting-backends-create.js +6 -3
  3. package/lib/commands/apphosting-backends-delete.js +3 -5
  4. package/lib/commands/apphosting-backends-get.js +2 -2
  5. package/lib/commands/apphosting-backends-list.js +3 -3
  6. package/lib/commands/apphosting-builds-create.js +4 -4
  7. package/lib/commands/apphosting-builds-get.js +2 -2
  8. package/lib/commands/apphosting-rollouts-create.js +3 -3
  9. package/lib/commands/apphosting-rollouts-list.js +2 -2
  10. package/lib/commands/firestore-backups-delete.js +44 -0
  11. package/lib/commands/firestore-backups-get.js +25 -0
  12. package/lib/commands/firestore-backups-list.js +33 -0
  13. package/lib/commands/firestore-backups-schedules-create.js +67 -0
  14. package/lib/commands/firestore-backups-schedules-delete.js +46 -0
  15. package/lib/commands/firestore-backups-schedules-list.js +27 -0
  16. package/lib/commands/firestore-backups-schedules-update.js +33 -0
  17. package/lib/commands/firestore-databases-create.js +4 -2
  18. package/lib/commands/firestore-databases-delete.js +4 -2
  19. package/lib/commands/firestore-databases-get.js +3 -1
  20. package/lib/commands/firestore-databases-list.js +3 -1
  21. package/lib/commands/firestore-databases-restore.js +42 -0
  22. package/lib/commands/firestore-databases-update.js +4 -2
  23. package/lib/commands/firestore-indexes-list.js +5 -3
  24. package/lib/commands/firestore-locations.js +3 -1
  25. package/lib/commands/index.js +11 -1
  26. package/lib/commands/init.js +3 -3
  27. package/lib/deploy/functions/runtimes/index.js +2 -0
  28. package/lib/deploy/functions/runtimes/python/index.js +4 -1
  29. package/lib/deploy/functions/services/firestore.js +1 -1
  30. package/lib/emulator/downloadableEmulators.js +3 -3
  31. package/lib/emulator/storage/rules/runtime.js +1 -1
  32. package/lib/experiments.js +2 -2
  33. package/lib/firestore/api-sort.js +23 -1
  34. package/lib/firestore/api-types.js +6 -1
  35. package/lib/firestore/api.js +18 -115
  36. package/lib/firestore/backupUtils.js +30 -0
  37. package/lib/firestore/delete.js +3 -3
  38. package/lib/firestore/pretty-print.js +184 -0
  39. package/lib/gcp/apphosting.js +2 -2
  40. package/lib/gcp/cloudbuild.js +7 -2
  41. package/lib/gcp/firestore.js +89 -6
  42. package/lib/init/features/apphosting/index.js +140 -79
  43. package/lib/init/features/apphosting/repo.js +80 -32
  44. package/lib/init/features/hosting/github.js +5 -0
  45. package/lib/prompt.js +1 -0
  46. package/package.json +10 -5
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.command = void 0;
4
- const command_1 = require("../command");
5
4
  const clc = require("colorette");
5
+ const command_1 = require("../command");
6
6
  const fsi = require("../firestore/api");
7
7
  const logger_1 = require("../logger");
8
8
  const requirePermissions_1 = require("../requirePermissions");
9
9
  const types_1 = require("../emulator/types");
10
10
  const commandUtils_1 = require("../emulator/commandUtils");
11
+ const pretty_print_1 = require("../firestore/pretty-print");
11
12
  exports.command = new command_1.Command("firestore:indexes")
12
13
  .description("List indexes in your project's Cloud Firestore database.")
13
14
  .option("--pretty", "Pretty print. When not specified the indexes are printed in the " +
@@ -17,17 +18,18 @@ exports.command = new command_1.Command("firestore:indexes")
17
18
  .before(commandUtils_1.warnEmulatorNotSupported, types_1.Emulators.FIRESTORE)
18
19
  .action(async (options) => {
19
20
  const indexApi = new fsi.FirestoreApi();
21
+ const printer = new pretty_print_1.PrettyPrint();
20
22
  const databaseId = options.database ?? "(default)";
21
23
  const indexes = await indexApi.listIndexes(options.project, databaseId);
22
24
  const fieldOverrides = await indexApi.listFieldOverrides(options.project, databaseId);
23
25
  const indexSpec = indexApi.makeIndexSpec(indexes, fieldOverrides);
24
26
  if (options.pretty) {
25
27
  logger_1.logger.info(clc.bold(clc.white("Compound Indexes")));
26
- indexApi.prettyPrintIndexes(indexes);
28
+ printer.prettyPrintIndexes(indexes);
27
29
  if (fieldOverrides) {
28
30
  logger_1.logger.info();
29
31
  logger_1.logger.info(clc.bold(clc.white("Field Overrides")));
30
- indexApi.printFieldOverrides(fieldOverrides);
32
+ printer.printFieldOverrides(fieldOverrides);
31
33
  }
32
34
  }
33
35
  else {
@@ -7,18 +7,20 @@ const logger_1 = require("../logger");
7
7
  const requirePermissions_1 = require("../requirePermissions");
8
8
  const types_1 = require("../emulator/types");
9
9
  const commandUtils_1 = require("../emulator/commandUtils");
10
+ const pretty_print_1 = require("../firestore/pretty-print");
10
11
  exports.command = new command_1.Command("firestore:locations")
11
12
  .description("List possible locations for your Cloud Firestore project.")
12
13
  .before(requirePermissions_1.requirePermissions, ["datastore.locations.list"])
13
14
  .before(commandUtils_1.warnEmulatorNotSupported, types_1.Emulators.FIRESTORE)
14
15
  .action(async (options) => {
15
16
  const api = new fsi.FirestoreApi();
17
+ const printer = new pretty_print_1.PrettyPrint();
16
18
  const locations = await api.locations(options.project);
17
19
  if (options.json) {
18
20
  logger_1.logger.info(JSON.stringify(locations, undefined, 2));
19
21
  }
20
22
  else {
21
- api.prettyPrintLocations(locations);
23
+ printer.prettyPrintLocations(locations);
22
24
  }
23
25
  return locations;
24
26
  });
@@ -101,6 +101,16 @@ function load(client) {
101
101
  client.firestore.databases.create = loadCommand("firestore-databases-create");
102
102
  client.firestore.databases.update = loadCommand("firestore-databases-update");
103
103
  client.firestore.databases.delete = loadCommand("firestore-databases-delete");
104
+ client.firestore.databases.restore = loadCommand("firestore-databases-restore");
105
+ client.firestore.backups = {};
106
+ client.firestore.backups.schedules = {};
107
+ client.firestore.backups.list = loadCommand("firestore-backups-list");
108
+ client.firestore.backups.get = loadCommand("firestore-backups-get");
109
+ client.firestore.backups.delete = loadCommand("firestore-backups-delete");
110
+ client.firestore.backups.schedules.list = loadCommand("firestore-backups-schedules-list");
111
+ client.firestore.backups.schedules.create = loadCommand("firestore-backups-schedules-create");
112
+ client.firestore.backups.schedules.update = loadCommand("firestore-backups-schedules-update");
113
+ client.firestore.backups.schedules.delete = loadCommand("firestore-backups-schedules-delete");
104
114
  client.functions = {};
105
115
  client.functions.config = {};
106
116
  client.functions.config.clone = loadCommand("functions-config-clone");
@@ -144,7 +154,7 @@ function load(client) {
144
154
  client.internaltesting.functions = {};
145
155
  client.internaltesting.functions.discover = loadCommand("internaltesting-functions-discover");
146
156
  }
147
- if (experiments.isEnabled("internalframeworks")) {
157
+ if (experiments.isEnabled("apphosting")) {
148
158
  client.apphosting = {};
149
159
  client.apphosting.backends = {};
150
160
  client.apphosting.backends.list = loadCommand("apphosting-backends-list");
@@ -69,10 +69,10 @@ const choices = [
69
69
  checked: false,
70
70
  },
71
71
  ];
72
- if ((0, experiments_1.isEnabled)("internalframeworks")) {
72
+ if ((0, experiments_1.isEnabled)("apphosting")) {
73
73
  choices.push({
74
- value: "internalframeworks",
75
- name: "Frameworks: Get started with Frameworks projects.",
74
+ value: "apphosting",
75
+ name: "App Hosting: Get started with App Hosting projects.",
76
76
  checked: false,
77
77
  });
78
78
  }
@@ -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 = "python311";
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
  }
@@ -23,9 +23,9 @@ const EMULATOR_UPDATE_DETAILS = {
23
23
  expectedChecksum: "2fd771101c0e1f7898c04c9204f2ce63",
24
24
  },
25
25
  firestore: {
26
- version: "1.18.2",
27
- expectedSize: 63929486,
28
- expectedChecksum: "7b066cd684baf9bcd4a56a258be344a5",
26
+ version: "1.19.1",
27
+ expectedSize: 67187672,
28
+ expectedChecksum: "859b1ac2a6040cccddd993c43586347c",
29
29
  },
30
30
  storage: {
31
31
  version: "1.1.3",
@@ -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,
@@ -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
- internalframeworks: {
75
+ apphosting: {
76
76
  shortDescription: "Allow CLI option for Frameworks",
77
- default: true,
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 = {}));
@@ -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.indexOf("__default__") < 0;
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.indexOf(mode) < 0) {
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
- prettyIndexString(index, includeState = true) {
511
- let result = "";
512
- if (index.state && includeState) {
513
- const stateMsg = `[${index.state}] `;
514
- if (index.state === types.State.READY) {
515
- result += clc.green(stateMsg);
516
- }
517
- else if (index.state === types.State.CREATING) {
518
- result += clc.yellow(stateMsg);
519
- }
520
- else {
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 result;
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;
@@ -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");
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PrettyPrint = void 0;
4
+ const clc = require("colorette");
5
+ const Table = require("cli-table");
6
+ const sort = require("./api-sort");
7
+ const types = require("./api-types");
8
+ const logger_1 = require("../logger");
9
+ const util = require("./util");
10
+ class PrettyPrint {
11
+ prettyPrintIndexes(indexes) {
12
+ if (indexes.length === 0) {
13
+ logger_1.logger.info("None");
14
+ return;
15
+ }
16
+ const sortedIndexes = indexes.sort(sort.compareApiIndex);
17
+ sortedIndexes.forEach((index) => {
18
+ logger_1.logger.info(this.prettyIndexString(index));
19
+ });
20
+ }
21
+ prettyPrintDatabases(databases) {
22
+ if (databases.length === 0) {
23
+ logger_1.logger.info("No databases found.");
24
+ return;
25
+ }
26
+ const sortedDatabases = databases.sort(sort.compareApiDatabase);
27
+ const table = new Table({
28
+ head: ["Database Name"],
29
+ colWidths: [Math.max(...sortedDatabases.map((database) => database.name.length + 5), 20)],
30
+ });
31
+ table.push(...sortedDatabases.map((database) => [this.prettyDatabaseString(database)]));
32
+ logger_1.logger.info(table.toString());
33
+ }
34
+ prettyPrintDatabase(database) {
35
+ const table = new Table({
36
+ head: ["Field", "Value"],
37
+ colWidths: [25, Math.max(50, 5 + database.name.length)],
38
+ });
39
+ 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)]);
40
+ logger_1.logger.info(table.toString());
41
+ }
42
+ prettyPrintBackups(backups) {
43
+ if (backups.length === 0) {
44
+ logger_1.logger.info("No backups found.");
45
+ return;
46
+ }
47
+ const sortedBackups = backups.sort(sort.compareApiBackup);
48
+ const table = new Table({
49
+ head: ["Backup Name", "Database Name", "Snapshot Time", "State"],
50
+ colWidths: [
51
+ Math.max(...sortedBackups.map((backup) => backup.name.length + 5), 20),
52
+ Math.max(...sortedBackups.map((backup) => backup.database.length + 5), 20),
53
+ 30,
54
+ 10,
55
+ ],
56
+ });
57
+ table.push(...sortedBackups.map((backup) => [
58
+ this.prettyBackupString(backup),
59
+ this.prettyDatabaseString(backup.database || ""),
60
+ backup.snapshotTime,
61
+ backup.state,
62
+ ]));
63
+ logger_1.logger.info(table.toString());
64
+ }
65
+ prettyPrintBackupSchedules(backupSchedules, databaseId) {
66
+ if (backupSchedules.length === 0) {
67
+ logger_1.logger.info(`No backup schedules for database ${databaseId} found.`);
68
+ return;
69
+ }
70
+ const sortedBackupSchedules = backupSchedules.sort(sort.compareApiBackupSchedule);
71
+ sortedBackupSchedules.forEach((schedule) => this.prettyPrintBackupSchedule(schedule));
72
+ }
73
+ prettyPrintBackupSchedule(backupSchedule) {
74
+ const table = new Table({
75
+ head: ["Field", "Value"],
76
+ colWidths: [25, Math.max(50, 5 + backupSchedule.name.length)],
77
+ });
78
+ table.push(["Name", clc.yellow(backupSchedule.name)], ["Create Time", clc.yellow(backupSchedule.createTime)], ["Last Update Time", clc.yellow(backupSchedule.updateTime)], ["Retention", clc.yellow(backupSchedule.retention)], ["Recurrence", this.prettyRecurrenceString(backupSchedule)]);
79
+ logger_1.logger.info(table.toString());
80
+ }
81
+ prettyRecurrenceString(backupSchedule) {
82
+ if (backupSchedule.dailyRecurrence) {
83
+ return clc.yellow("DAILY");
84
+ }
85
+ else if (backupSchedule.weeklyRecurrence) {
86
+ return clc.yellow(`WEEKLY (${backupSchedule.weeklyRecurrence.day})`);
87
+ }
88
+ return "";
89
+ }
90
+ prettyPrintBackup(backup) {
91
+ const table = new Table({
92
+ head: ["Field", "Value"],
93
+ colWidths: [25, Math.max(50, 5 + backup.name.length, 5 + backup.database.length)],
94
+ });
95
+ table.push(["Name", clc.yellow(backup.name)], ["Database", clc.yellow(backup.database)], ["Database UID", clc.yellow(backup.databaseUid)], ["State", clc.yellow(backup.state)], ["Snapshot Time", clc.yellow(backup.snapshotTime)], ["Expire Time", clc.yellow(backup.expireTime)], ["Stats", clc.yellow(backup.stats)]);
96
+ logger_1.logger.info(table.toString());
97
+ }
98
+ prettyPrintLocations(locations) {
99
+ if (locations.length === 0) {
100
+ logger_1.logger.info("No Locations Available");
101
+ return;
102
+ }
103
+ const table = new Table({
104
+ head: ["Display Name", "LocationId"],
105
+ colWidths: [20, 30],
106
+ });
107
+ table.push(...locations
108
+ .sort(sort.compareLocation)
109
+ .map((location) => [location.displayName, location.locationId]));
110
+ logger_1.logger.info(table.toString());
111
+ }
112
+ printFieldOverrides(fields) {
113
+ if (fields.length === 0) {
114
+ logger_1.logger.info("None");
115
+ return;
116
+ }
117
+ const sortedFields = fields.sort(sort.compareApiField);
118
+ sortedFields.forEach((field) => {
119
+ logger_1.logger.info(this.prettyFieldString(field));
120
+ });
121
+ }
122
+ prettyIndexString(index, includeState = true) {
123
+ let result = "";
124
+ if (index.state && includeState) {
125
+ const stateMsg = `[${index.state}] `;
126
+ if (index.state === types.State.READY) {
127
+ result += clc.green(stateMsg);
128
+ }
129
+ else if (index.state === types.State.CREATING) {
130
+ result += clc.yellow(stateMsg);
131
+ }
132
+ else {
133
+ result += clc.red(stateMsg);
134
+ }
135
+ }
136
+ const nameInfo = util.parseIndexName(index.name);
137
+ result += clc.cyan(`(${nameInfo.collectionGroupId})`);
138
+ result += " -- ";
139
+ index.fields.forEach((field) => {
140
+ if (field.fieldPath === "__name__") {
141
+ return;
142
+ }
143
+ const orderOrArrayConfig = field.order ? field.order : field.arrayConfig;
144
+ result += `(${field.fieldPath},${orderOrArrayConfig}) `;
145
+ });
146
+ return result;
147
+ }
148
+ prettyBackupString(backup) {
149
+ return clc.yellow(backup.name || "");
150
+ }
151
+ prettyBackupScheduleString(backupSchedule) {
152
+ return clc.yellow(backupSchedule.name || "");
153
+ }
154
+ prettyDatabaseString(database) {
155
+ return clc.yellow(typeof database === "string" ? database : database.name);
156
+ }
157
+ prettyFieldString(field) {
158
+ let result = "";
159
+ const parsedName = util.parseFieldName(field.name);
160
+ result +=
161
+ "[" +
162
+ clc.cyan(parsedName.collectionGroupId) +
163
+ "." +
164
+ clc.yellow(parsedName.fieldPath) +
165
+ "] --";
166
+ const fieldIndexes = field.indexConfig.indexes || [];
167
+ if (fieldIndexes.length > 0) {
168
+ fieldIndexes.forEach((index) => {
169
+ const firstField = index.fields[0];
170
+ const mode = firstField.order || firstField.arrayConfig;
171
+ result += ` (${mode})`;
172
+ });
173
+ }
174
+ else {
175
+ result += " (no indexes)";
176
+ }
177
+ const fieldTtl = field.ttlConfig;
178
+ if (fieldTtl) {
179
+ result += ` TTL(${fieldTtl.state})`;
180
+ }
181
+ return result;
182
+ }
183
+ }
184
+ exports.PrettyPrint = PrettyPrint;