Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: typing improvement #140

Merged
merged 3 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:

strategy:
matrix:
node-version: [12.x, 14.x, 16.x]
node-version: [12.x, 14.x, 16.x, 18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'yarn'
Expand Down
6 changes: 5 additions & 1 deletion src/driver/Firestore/InProcessFirestore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FieldValue } from "@google-cloud/firestore"
import { Firestore } from "@google-cloud/firestore"
import flatten from "flat"
import _ from "lodash"
import { Readable } from "stream"
Expand Down Expand Up @@ -60,6 +60,10 @@ export class InProcessFirestore implements IFirestore {
public storage = {},
) {}

asFirestore(): Firestore {
return (this as unknown) as Firestore
}

collection(collectionPath: string): IFirestoreCollectionRef {
return new InProcessFirestoreCollectionRef(
this,
Expand Down
13 changes: 7 additions & 6 deletions tests/driver/Firestore/InProcessFirestore.batch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { InProcessFirestore } from "../../../src/driver/Firestore/InProcessFires
describe("In-process Firestore batched writes", () => {
test("documentation example batch", async () => {
// Given we have a in-process Firestore DB;
const db = new InProcessFirestore()
const db = new InProcessFirestore().asFirestore()

// And there is some initial data;
await db
Expand Down Expand Up @@ -110,7 +110,7 @@ describe("In-process Firestore batched writes", () => {
"can set in batch on a document that doesn't exist, with merge %s",
async (merge) => {
// Given we have a in-process Firestore DB;
const db = new InProcessFirestore()
const db = new InProcessFirestore().asFirestore()

// When we get a new write batch;
const batch = db.batch()
Expand All @@ -127,7 +127,7 @@ describe("In-process Firestore batched writes", () => {
)

test("cannot create existing document in a batch write", async () => {
const db = new InProcessFirestore()
const db = new InProcessFirestore().asFirestore()
// Given there is an existing document;
const initial = await db
.collection("animals")
Expand Down Expand Up @@ -164,7 +164,7 @@ describe("In-process Firestore batched writes", () => {

test("cannot reuse committed batch", async () => {
// Given we have a write batch;
const db = new InProcessFirestore()
const db = new InProcessFirestore().asFirestore()
const batch = db.batch()

// And we make a change in the batch;
Expand Down Expand Up @@ -192,10 +192,11 @@ describe("In-process Firestore batched writes", () => {
test("throws if an undefined field is written in a batch", async () => {
// Given we have a write batch;
const db = new InProcessFirestore()
const batch = db.batch()
const fs = db.asFirestore()
const batch = fs.batch()

// And we make a change in the batch;
const docRef = db.collection("things").doc("thingA")
const docRef = fs.collection("things").doc("thingA")
batch.create(docRef, { foo: "bar", bar: undefined })

// The commit should throw
Expand Down