MCPcopy Index your code
hub / github.com/firebase/firebase-tools / RTDBRemoveRemote

Class RTDBRemoveRemote

src/database/removeRemote.ts:21–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19}
20
21export class RTDBRemoveRemote implements RemoveRemote {
22 private instance: string;
23 private host: string;
24 private apiClient: Client;
25 private disableTriggers: boolean;
26
27 constructor(instance: string, host: string, disableTriggers: boolean) {
28 this.instance = instance;
29 this.host = host;
30 this.disableTriggers = disableTriggers;
31
32 const url = new URL(utils.getDatabaseUrl(this.host, this.instance, "/"));
33 this.apiClient = new Client({ urlPrefix: url.origin, auth: true });
34 }
35
36 deletePath(path: string): Promise<boolean> {
37 return this.patch(path, null, "all data");
38 }
39
40 deleteSubPath(path: string, subPaths: string[]): Promise<boolean> {
41 const body: any = {};
42 for (const c of subPaths) {
43 body[c] = null;
44 }
45 return this.patch(path, body, `${subPaths.length} subpaths`);
46 }
47
48 private async patch(path: string, body: any, note: string): Promise<boolean> {
49 const t0 = Date.now();
50 const url = new URL(utils.getDatabaseUrl(this.host, this.instance, path + ".json"));
51 const queryParams = {
52 print: "silent",
53 writeSizeLimit: "tiny",
54 disableTriggers: this.disableTriggers.toString(),
55 };
56 const res = await this.apiClient.request({
57 method: "PATCH",
58 path: url.pathname,
59 body,
60 queryParams,
61 responseType: "stream",
62 resolveOnHTTPError: true,
63 });
64 const dt = Date.now() - t0;
65 if (res.status >= 400) {
66 logger.debug(
67 `[database] Failed to remove ${note} at ${path} time: ${dt}ms, will try recursively chunked deletes.`,
68 );
69 return false;
70 }
71 logger.debug(`[database] Sucessfully removed ${note} at ${path} time: ${dt}ms`);
72 return true;
73 }
74}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…