MCPcopy Create free account
hub / github.com/firebase/firebase-tools / FakeListRemote

Class FakeListRemote

src/database/fakeListRemote.spec.ts:12–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10 * that accepts a JSON tree to serve upon construction.
11 */
12export class FakeListRemote implements ListRemote {
13 data: any;
14 delay: number;
15
16 /**
17 * @param data the fake database structure. Each leaf is an integer
18 * representing the subtree's size.
19 */
20 constructor(data: any) {
21 this.data = data;
22 this.delay = 0;
23 }
24
25 listPath(
26 path: string,
27 numChildren: number,
28 startAfter?: string,
29 timeout?: number,
30 ): Promise<string[]> {
31 if (timeout === 0) {
32 return Promise.reject(new Error("timeout"));
33 }
34 const d = this.dataAtPath(path);
35 if (d) {
36 let keys = Object.keys(d);
37 /*
38 * We mirror a critical implementation detail of here. Namely, the
39 * `startAfter` option (if it exists) is applied to the resulting key set
40 * before the `limitToFirst` option.
41 */
42 if (startAfter) {
43 keys = keys.filter((key) => key > startAfter);
44 }
45 keys = keys.slice(0, numChildren);
46 return Promise.resolve(keys);
47 }
48 return Promise.resolve([]);
49 }
50
51 private size(data: any): number {
52 if (typeof data === "number") {
53 return data;
54 }
55 let size = 0;
56 for (const key of Object.keys(data)) {
57 size += this.size(data[key]);
58 }
59 return size;
60 }
61
62 private dataAtPath(path: string): any {
63 const splitedPath = path.slice(1).split("/");
64 let d = this.data;
65 for (const p of splitedPath) {
66 if (d && p !== "") {
67 if (typeof d === "number") {
68 d = null;
69 } else {

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…