Skip to content

Commit

Permalink
refactor: Updates for collections API (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
adilansari authored Oct 3, 2022
1 parent 2863487 commit a3c6008
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 106 deletions.
5 changes: 2 additions & 3 deletions src/__tests__/cursor/cursor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {Tigris} from "../../tigris";
import {TigrisCursorInUseError} from "../../error";
import {ObservabilityService} from "../../proto/server/v1/observability_grpc_pb";
import TestObservabilityService from "../test-observability-service";
import {ReadResponse} from "../../proto/server/v1/api_pb";
import {DB} from "../../db";

describe("class FindCursor", () => {
Expand Down Expand Up @@ -75,8 +74,8 @@ describe("class FindCursor", () => {

it("does not allow cursor to be re-used", () => {
const cursor = db.getCollection<IBook>("books").findMany();
// cursor.stream() is a generator fn, calling next() would retrieve item from stream
cursor.stream().next();
// cursor is backed by is a generator fn, calling next() would retrieve item from stream
cursor[Symbol.asyncIterator]().next();
expect(() => cursor.toArray()).toThrow(TigrisCursorInUseError);
})

Expand Down
16 changes: 8 additions & 8 deletions src/__tests__/tigris.rpc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ describe("rpc tests", () => {
it("insert", () => {
const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true});
const db1 = tigris.getDatabase("db3");
const insertionPromise = db1.getCollection<IBook>("books").insert({
const insertionPromise = db1.getCollection<IBook>("books").insertOne({
author: "author name",
id: 0,
tags: ["science"],
Expand All @@ -182,7 +182,7 @@ describe("rpc tests", () => {
it("insert2", () => {
const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true});
const db1 = tigris.getDatabase("db3");
const insertionPromise = db1.getCollection<IBook2>("books").insert({
const insertionPromise = db1.getCollection<IBook2>("books").insertOne({
id: 0,
title: "science book",
metadata: {
Expand All @@ -202,7 +202,7 @@ describe("rpc tests", () => {
const randomNumber: number = Math.floor(Math.random() * 100);
// pass the random number in author field. mock server reads author and sets as the
// primaryKey field.
const insertionPromise = db1.getCollection<IBook1>("books-with-optional-field").insert({
const insertionPromise = db1.getCollection<IBook1>("books-with-optional-field").insertOne({
author: "" + randomNumber,
tags: ["science"],
title: "science book"
Expand All @@ -216,7 +216,7 @@ describe("rpc tests", () => {
it("insertOrReplace", () => {
const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true});
const db1 = tigris.getDatabase("db3");
const insertOrReplacePromise = db1.getCollection<IBook>("books").insertOrReplace({
const insertOrReplacePromise = db1.getCollection<IBook>("books").insertOrReplaceOne({
author: "author name",
id: 0,
tags: ["science"],
Expand All @@ -234,7 +234,7 @@ describe("rpc tests", () => {
const randomNumber: number = Math.floor(Math.random() * 100);
// pass the random number in author field. mock server reads author and sets as the
// primaryKey field.
const insertOrReplacePromise = db1.getCollection<IBook1>("books-with-optional-field").insertOrReplace({
const insertOrReplacePromise = db1.getCollection<IBook1>("books-with-optional-field").insertOrReplaceOne({
author: "" + randomNumber,
tags: ["science"],
title: "science book"
Expand Down Expand Up @@ -285,7 +285,7 @@ describe("rpc tests", () => {
it("readOne", () => {
const tigris = new Tigris({serverUrl: "0.0.0.0:" + SERVER_PORT, insecureChannel: true});
const db1 = tigris.getDatabase("db3");
const readOnePromise = db1.getCollection<IBook>("books").findOne({
const readOnePromise = db1.getCollection<IBook>("books").findOne( {
op: SelectorFilterOperator.EQ,
fields: {
id: 1
Expand Down Expand Up @@ -499,7 +499,7 @@ describe("rpc tests", () => {
const txDB = tigris.getDatabase("test-tx");
const books = txDB.getCollection<IBook>("books");
txDB.transact(tx => {
books.insert(
books.insertOne(
{
id: 1,
author: "Alice",
Expand All @@ -513,7 +513,7 @@ describe("rpc tests", () => {
fields: {
id: 1
}
}, tx).then(() => {
}, undefined, tx).then(() => {
books.update({
op: SelectorFilterOperator.EQ,
fields: {
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/tigris.utility.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
SearchRequestOptions,
SortOrder
} from "../search/types";
import {Collation} from "../proto/server/v1/api_pb";

describe("utility tests", () => {
it("base64encode", () => {
Expand Down
Loading

0 comments on commit a3c6008

Please sign in to comment.