Skip to content

Commit 6d7a402

Browse files
committed
Expose db via dbSymbol
1 parent a3b0a33 commit 6d7a402

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

src/adapter/admin/core.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ import { firestore as createFirestore, firestoreSymbol } from "./firebase.mjs";
1616
*/
1717
export const nativeSymbol = Symbol("native");
1818

19+
/**
20+
* The symbol allows to access the Typesaurus database instance.
21+
*/
22+
export const dbSymbol = Symbol("db");
23+
1924
export function schema(getSchema, options) {
2025
let firestore;
2126
const schema = getSchema(schemaHelpers());
@@ -142,6 +147,7 @@ export class Collection {
142147
return new SubscriptionPromise({
143148
request: request({
144149
[nativeSymbol]: doc,
150+
[dbSymbol]: this.db,
145151
kind: "get",
146152
path: this.path,
147153
id,
@@ -171,6 +177,7 @@ export class Collection {
171177
return new SubscriptionPromise({
172178
request: request({
173179
[nativeSymbol]: docs,
180+
[dbSymbol]: this.db,
174181
kind: "many",
175182
path: this.path,
176183
ids,
@@ -235,6 +242,7 @@ export class Collection {
235242

236243
adapter() {
237244
return {
245+
db: () => this.db,
238246
collection: () => this.firebaseCollection(),
239247
doc: (snapshot) =>
240248
new Doc(this, snapshot.id, wrapData(this.db, snapshot.data())),
@@ -345,6 +353,7 @@ export function all(adapter) {
345353
return new SubscriptionPromise({
346354
request: request({
347355
[nativeSymbol]: firebaseCollection,
356+
[dbSymbol]: adapter.db(),
348357
kind: "all",
349358
...adapter.request(),
350359
}),
@@ -629,6 +638,7 @@ export function query(firestore, adapter, queries) {
629638
const sp = new SubscriptionPromise({
630639
request: request({
631640
[nativeSymbol]: firestoreQuery,
641+
[dbSymbol]: adapter.db(),
632642
kind: "query",
633643
...adapter.request(),
634644
queries: queries,

src/adapter/admin/groups.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class Group {
6262

6363
adapter() {
6464
return {
65+
db: () => this.db,
6566
collection: () => this.firestore().collectionGroup(this.name),
6667
doc: (snapshot) =>
6768
pathToDoc(

src/adapter/web/core.mjs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ import { firestore as createFirestore, firestoreSymbol } from "./firebase.mjs";
4141
*/
4242
export const nativeSymbol = Symbol("native");
4343

44+
/**
45+
* The symbol allows to access the Typesaurus database instance.
46+
*/
47+
export const dbSymbol = Symbol("db");
48+
4449
export function schema(getSchema, options) {
4550
let firestore;
4651
const schema = getSchema(schemaHelpers());
@@ -165,6 +170,7 @@ export class Collection {
165170
return new SubscriptionPromise({
166171
request: request({
167172
[nativeSymbol]: doc,
173+
[dbSymbol]: this.db,
168174
kind: "get",
169175
path: this.path,
170176
id,
@@ -197,6 +203,7 @@ export class Collection {
197203
return new SubscriptionPromise({
198204
request: request({
199205
[nativeSymbol]: docs,
206+
[dbSymbol]: this.db,
200207
kind: "many",
201208
path: this.path,
202209
ids,
@@ -247,6 +254,7 @@ export class Collection {
247254

248255
adapter() {
249256
return {
257+
db: () => this.db,
250258
collection: () => this.firebaseCollection(),
251259
doc: (snapshot) =>
252260
new Doc(this, snapshot.id, wrapData(this.db, snapshot.data())),
@@ -353,6 +361,7 @@ export function all(adapter) {
353361
return new SubscriptionPromise({
354362
request: request({
355363
[nativeSymbol]: firebaseCollection,
364+
[dbSymbol]: adapter.db(),
356365
kind: "all",
357366
...adapter.request(),
358367
}),
@@ -659,6 +668,7 @@ export function _query(firestore, adapter, queries) {
659668
get [nativeSymbol]() {
660669
return firebaseQuery();
661670
},
671+
[dbSymbol]: adapter.db(),
662672
kind: "query",
663673
...adapter.request(),
664674
queries: queries,

src/adapter/web/groups.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class Group {
7474

7575
adapter() {
7676
return {
77+
db: () => this.db,
7778
collection: () => collectionGroup(this.firestore(), this.name),
7879
doc: (snapshot) =>
7980
pathToDoc(

0 commit comments

Comments
 (0)