-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
masking similar to original firebase admin left
- Loading branch information
Showing
8 changed files
with
161 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { initFirebaseAdmin } from "./initFAS" | ||
|
||
|
||
export { | ||
initFirebaseAdmin | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { FirebaseAdminRest } from "../firestore/FARClass"; | ||
import { InitFirebaseAdminInput } from "../types"; | ||
|
||
export async function initFirebaseAdmin(options?: InitFirebaseAdminInput){ | ||
const db = await new FirebaseAdminRest(options).initApp(); | ||
return db; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { initFirebaseRest } from "../firebase-auth-utils/initFirebase"; | ||
import { DirectionOpREST, GetDocumentResponse, InitFirebaseAdminInput, WhereFilterOpREST } from "../types"; | ||
import { getDocRest } from "./getDoc"; | ||
|
||
|
||
|
||
/** | ||
* Represents a Firebase Admin REST client. | ||
*/ | ||
/** | ||
* Initializes a new instance of the FirebaseAdminRest class. | ||
* @param initialValue - Optional initial value for the FirebaseAdminConfig. | ||
*/ | ||
export class FirebaseAdminRest<T = any> { | ||
|
||
private initialValue: InitFirebaseAdminInput | undefined; | ||
|
||
constructor(initialValue?: InitFirebaseAdminInput) { | ||
this.initialValue = initialValue; | ||
return this; | ||
} | ||
|
||
async initApp() { | ||
const appInstance = await initFirebaseRest(this.initialValue); | ||
return new FirestoreOperations(appInstance.databaseId); | ||
} | ||
} | ||
|
||
/** | ||
* Nested class for operations related to documents. | ||
*/ | ||
class FirestoreOperations { | ||
|
||
constructor(private databaseId: string) { | ||
return this; | ||
} | ||
|
||
public doc<T = any>(docPath: string): DocOperations<T> { | ||
return new DocOperations<T>(docPath, this.databaseId); | ||
} | ||
|
||
public collection<T extends object>(collectionPath: string): CollectionOperations<T> { | ||
return new CollectionOperations<T>(collectionPath, this.databaseId); | ||
} | ||
} | ||
|
||
/** | ||
* Nested class for operations related to documents. | ||
*/ | ||
class DocOperations<T = any> { | ||
constructor(private docPath: string, private databaseId: string) { } | ||
|
||
// Define methods for document operations here | ||
public async get(): Promise<GetDocumentResponse<T>> { | ||
const doc = await getDocRest(this.docPath, { | ||
debug: true | ||
}); | ||
return doc; | ||
} | ||
} | ||
|
||
/** | ||
* Nested class for operations related to documents. | ||
*/ | ||
class CollectionOperations<T> { | ||
|
||
private whereQuery: { | ||
field: string, | ||
op: WhereFilterOpREST, | ||
value: any | ||
}; | ||
private orderByQuery: { | ||
field: string, | ||
direction: DirectionOpREST | ||
}; | ||
private limitQuery: number; | ||
|
||
constructor(private collectionPath: string, private databaseId: string) { | ||
this.whereQuery = { | ||
field: "", | ||
op: "EQUAL", | ||
value: "" | ||
} | ||
this.orderByQuery = { | ||
field: "", | ||
direction: "ASCENDING" | ||
} | ||
this.limitQuery = 100; | ||
} | ||
|
||
|
||
public where(field: string, op: WhereFilterOpREST, value: any) { | ||
this.whereQuery = { | ||
field: field, | ||
op: op, | ||
value: value | ||
} | ||
return this; | ||
} | ||
|
||
public orderBy(field: string, direction: DirectionOpREST) { | ||
this.orderByQuery = { | ||
field: field, | ||
direction: direction | ||
} | ||
return this; | ||
} | ||
|
||
public limit(limit: number) { | ||
this.limitQuery = limit; | ||
return this; | ||
} | ||
// Define methods for document operations here | ||
public async get(): Promise<string> { | ||
return `Retrieving from collection: ${this.collectionPath} with where(): ${this.whereQuery} with orderBy ${this.orderByQuery} with limit ${this.limitQuery} at ${this.collectionPath}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
import { FirebaseAdminRest } from "../firestore/Class"; | ||
// import { initFirebaseRest } from "../firestore"; | ||
import { initFirebaseAdmin } from "../admin"; | ||
|
||
export interface User { | ||
id: string; | ||
name: string; | ||
email: string; | ||
password: string; | ||
} | ||
|
||
async function test() { | ||
const db = new FirebaseAdminRest(); | ||
const res = await db.collection(`user`).where('name', `EQUAL`, 5).limit(5).get(); | ||
console.log(res); | ||
// await initFirebaseRest(); | ||
const db = await initFirebaseAdmin(); | ||
const doc = await db.doc<User>(`users/test_1`).get(); | ||
console.log(doc.data()) | ||
} | ||
test() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters