-
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.
- Loading branch information
Showing
16 changed files
with
491 additions
and
387 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,12 @@ | ||
kind: pipeline | ||
name: default | ||
|
||
steps: | ||
- name: build_packages | ||
image: node | ||
commands: | ||
- npm i -g pnpm | ||
- pnpm install | ||
- pnpm run -r build | ||
- pnpm run -r --filter @rtdb2/embed test | ||
- pnpm run -r publish |
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
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
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,45 @@ | ||
import * as RTDB from "@rtdb2/core"; | ||
import { AwaitStore } from "@hibas123/utils"; | ||
import { Database, IConnector, IQueryRequest, Snapshot } from "@rtdb2/sdk"; | ||
|
||
export class EmbeddedConnector implements IConnector { | ||
#db: RTDB.Database; | ||
#session: RTDB.Session; | ||
|
||
snapshots = new Map<string, Snapshot<any>>(); | ||
offline = new AwaitStore(false); | ||
|
||
constructor(path: string) { | ||
this.#db = new RTDB.Database(path); | ||
this.#session = new RTDB.Session("session"); | ||
this.#session.root = true; // root is always true on the local session | ||
} | ||
|
||
async queryRequest<T = any>( | ||
query: IQueryRequest, | ||
id?: string, | ||
ns?: string | ||
): Promise<T> { | ||
if (Array.isArray(query)) { | ||
return this.#db.run(query as RTDB.IQuery[], this.#session); | ||
} else { | ||
if (query.type === "snapshot") { | ||
return (await this.#db.snapshot( | ||
query as RTDB.ITypedQuery<"snapshot">, | ||
this.#session, | ||
(change) => { | ||
this.snapshots.get(id).receivedData(change); | ||
} | ||
)) as any; | ||
} else if (query.type === "unsubscribe") { | ||
return this.#db.unsubscribe(id, this.#session) as any; | ||
} else { | ||
return this.#db.run([query as RTDB.IQuery], this.#session); | ||
} | ||
} | ||
} | ||
|
||
async close() { | ||
await this.#db.stop(); | ||
} | ||
} |
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,46 +1,7 @@ | ||
import { Database, Session } from "@rtdb2/core"; | ||
import Database from "@rtdb2/sdk"; | ||
import { testDB } from "@rtdb2/sdk/lib/tests"; | ||
import { EmbeddedConnector } from "./main"; | ||
|
||
const db = new Database("./test"); | ||
const db = new Database(new EmbeddedConnector("./test")); | ||
|
||
// db.run() | ||
|
||
const session = new Session("134"); | ||
|
||
async function test() { | ||
const res = await db.run( | ||
[ | ||
{ | ||
path: ["coll1", "doc1"], | ||
type: "get", | ||
}, | ||
], | ||
session | ||
); | ||
console.log(res); | ||
|
||
await db.run( | ||
[ | ||
{ | ||
path: ["coll1", "doc1"], | ||
type: "set", | ||
data: { | ||
hi: "hallo" + Date.now(), | ||
}, | ||
}, | ||
], | ||
session | ||
); | ||
|
||
const res2 = await db.run( | ||
[ | ||
{ | ||
path: ["coll1", "doc1"], | ||
type: "get", | ||
}, | ||
], | ||
session | ||
); | ||
console.log(res2); | ||
} | ||
|
||
test(); | ||
testDB(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 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
Oops, something went wrong.