Skip to content

Commit

Permalink
Merge pull request #189 from tigrisdata/main
Browse files Browse the repository at this point in the history
Beta release
  • Loading branch information
JigarJoshi authored Dec 20, 2022
2 parents 123c608 + 98d2581 commit 2e574e0
Show file tree
Hide file tree
Showing 52 changed files with 1,457 additions and 1,468 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@typescript-eslint/ban-types": [
"error",
{
"types": { "BigInt": false },
"types": { "BigInt": false, "Function": false, "Object": false },
"extendDefaults": true
}
],
Expand Down
2 changes: 1 addition & 1 deletion api/proto
Submodule proto updated from 49dd11 to 9aac84
9 changes: 8 additions & 1 deletion jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@
"collectCoverage": true,
"coverageDirectory": "coverage",
"coverageProvider": "v8",
"collectCoverageFrom": ["src/*.ts", "src/consumables/*.ts", "src/utils/*.ts", "src/search/*.ts"]
"collectCoverageFrom": [
"src/*.ts",
"src/consumables/*.ts",
"src/decorators/**/*.ts",
"src/schema/**/*.ts",
"src/search/**/*.ts",
"src/utils/**/*.ts"
]
}
25 changes: 11 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"scripts": {
"clean": "rm -rf ./src/proto/* && rm -rf dist && rm -rf node_modules",
"update_api": "git submodule update --init --recursive && git submodule update --remote --recursive --rebase && git submodule foreach --recursive git reset --hard origin/main",
"init_api": "git submodule update --init --recursive",
"protoc": "./scripts/protoc.sh",
"lint": "node ./node_modules/eslint/bin/eslint src/ --ext .ts",
"lint-fix": "npx eslint --ext .ts --fix src/",
Expand All @@ -71,7 +72,7 @@
"test": "jest --runInBand --coverage --silent --detectOpenHandles",
"prettier-check": "npx prettier --check .",
"all": "npm run clean && npm run build && npm run prettier-check && npm run lint && npm run test",
"prepare": "npm run update_api && npm run protoc && npm run tsc",
"prepare": "npm run init_api && npm run protoc && npm run tsc",
"prepublishOnly": "npm test && npm run lint",
"prettify": "npx prettier --write .",
"preversion": "npm run lint"
Expand Down Expand Up @@ -105,11 +106,11 @@
},
"dependencies": {
"@grpc/grpc-js": "^1.6.10",
"app-root-path": "^3.1.0",
"chalk": "4.1.2",
"dotenv": "^16.0.3",
"google-protobuf": "^3.21.0",
"json-bigint": "^1.0.0",
"reflect-metadata": "^0.1.13",
"typescript": "^4.7.2"
}
}
8 changes: 4 additions & 4 deletions src/__tests__/consumables/cursor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import TestService, {TestTigrisService} from "../test-service";
import {TigrisService} from "../../proto/server/v1/api_grpc_pb";
import {IBook} from "../tigris.rpc.spec";
import {Tigris} from "../../tigris";
import {TigrisCursorInUseError} from "../../error";
import {CursorInUseError} from "../../error";
import {ObservabilityService} from "../../proto/server/v1/observability_grpc_pb";
import TestObservabilityService from "../test-observability-service";
import {DB} from "../../db";
Expand All @@ -30,8 +30,8 @@ describe("class FindCursor", () => {
}
}
);
const tigris = new Tigris({serverUrl: "localhost:" + SERVER_PORT});
db = tigris.getDatabase("db3");
const tigris = new Tigris({serverUrl: "localhost:" + SERVER_PORT, projectName: "db3"});
db = tigris.getDatabase();
done();
});

Expand Down Expand Up @@ -76,7 +76,7 @@ describe("class FindCursor", () => {
const cursor = db.getCollection<IBook>("books").findMany();
// cursor is backed by is a generator fn, calling next() would retrieve item from stream
cursor[Symbol.asyncIterator]().next();
expect(() => cursor.toArray()).toThrow(TigrisCursorInUseError);
expect(() => cursor.toArray()).toThrow(CursorInUseError);
})

it("allows cursor to be re-used once reset", async () => {
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/data/basicCollection.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"format": "byte"
}
},
"collection_type": "documents",
"primary_key": [
"id"
]
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/data/basicCollectionWithObjectType.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"type": "object"
}
},
"collection_type": "documents",
"primary_key": [
"id"
]
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/data/collectionWithObjectArrays.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"format": "uuid"
}
},
"collection_type": "documents",
"primary_key": [
"id"
]
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/data/collectionWithPrimitiveArrays.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"format": "uuid"
}
},
"collection_type": "documents",
"primary_key": [
"id"
]
Expand Down
85 changes: 85 additions & 0 deletions src/__tests__/data/decoratedModels/matrices.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import { Field } from "../../../decorators/tigris-field";
import { TigrisCollectionType, TigrisDataTypes, TigrisSchema } from "../../../types";
import { TigrisCollection } from "../../../decorators/tigris-collection";
import { PrimaryKey } from "../../../decorators/tigris-primary-key";

/******************************************************************************
* `Matrix` class demonstrates a Tigris collection schema generated using
* decorators. Type of collection fields is inferred using Reflection APIs. This
* particular schema example:
* - has a nested Array (Array of Arrays)
* - infers the type of collection fields automatically using Reflection APIs
*****************************************************************************/
export class CellValue {
@Field()
length: number

@Field()
type: string;
}

export class Cell {
@Field()
x: number;

@Field()
y: number;

@Field()
value: CellValue;
}

@TigrisCollection("matrices")
export class Matrix implements TigrisCollectionType {
@PrimaryKey({order: 1})
id: string;

@Field({elements: Cell, depth: 3})
cells: Array<Array<Array<Cell>>>;
}
/********************************** END **************************************/

/**
* `TigrisSchema` representation of the collection class above.
*
* NOTE: This is only an illustration; you don't have to write this definition,
* it will be auto generated.
*/
export const ExpectedSchema: TigrisSchema<Matrix> = {
id: {
type: TigrisDataTypes.STRING,
primary_key: {
order: 1,
autoGenerate: false
},
},
cells: {
type: TigrisDataTypes.ARRAY,
items: {
type: TigrisDataTypes.ARRAY,
items: {
type: TigrisDataTypes.ARRAY,
items: {
type: {
x: {
type: TigrisDataTypes.NUMBER,
},
y: {
type: TigrisDataTypes.NUMBER,
},
value: {
type: {
length: {
type: TigrisDataTypes.NUMBER
},
type: {
type: TigrisDataTypes.STRING
}
},
},
}
}
}
}
}
}
106 changes: 106 additions & 0 deletions src/__tests__/data/decoratedModels/movies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { TigrisCollection } from "../../../decorators/tigris-collection";
import { PrimaryKey } from "../../../decorators/tigris-primary-key";
import { TigrisDataTypes, TigrisSchema } from "../../../types";
import { Field } from "../../../decorators/tigris-field";

/******************************************************************************
* `Movie` class demonstrates a Tigris collection schema generated using
* decorators. This particular schema example:
* - has an Array of another class as embedded Object
* - has an Array of primitive types
* - has an Object of type `Studio`
* - does not use reflection, all the collection fields are explicitly typed
*****************************************************************************/

export class Studio {
@Field(TigrisDataTypes.STRING)
name: string;

@Field(TigrisDataTypes.STRING)
city: string;
}

export class Actor {
@Field(TigrisDataTypes.STRING, {maxLength: 64})
firstName: string;

@Field(TigrisDataTypes.STRING, {maxLength: 64})
lastName: string;
}

@TigrisCollection("movies")
export class Movie{

@PrimaryKey(TigrisDataTypes.STRING, {autoGenerate: true, order: 1})
movieId: string;

@Field(TigrisDataTypes.STRING)
title: string;

@Field(TigrisDataTypes.INT32)
year: number;

@Field(TigrisDataTypes.ARRAY, {elements: Actor})
actors: Array<Actor>;

@Field(TigrisDataTypes.ARRAY, {elements: TigrisDataTypes.STRING})
genres: Array<string>;

@Field(TigrisDataTypes.OBJECT, {elements: Studio})
productionHouse: Studio;
}

/********************************** END **************************************/

/**
* `TigrisSchema` representation of the collection class above.
*
* NOTE: This is only an illustration; you don't have to write this definition,
* it will be auto generated.
*/
export const ExpectedSchema: TigrisSchema<Movie> = {
movieId: {
type: TigrisDataTypes.STRING,
primary_key: {
order: 1,
autoGenerate: true
}
},
title: {
type: TigrisDataTypes.STRING
},
year: {
type: TigrisDataTypes.INT32
},
actors: {
type: TigrisDataTypes.ARRAY,
items: {
type: {
firstName: {
type: TigrisDataTypes.STRING,
maxLength: 64
},
lastName: {
type: TigrisDataTypes.STRING,
maxLength: 64
}
}
}
},
genres: {
type: TigrisDataTypes.ARRAY,
items: {
type: TigrisDataTypes.STRING
}
},
productionHouse: {
type: {
name: {
type: TigrisDataTypes.STRING
},
city: {
type: TigrisDataTypes.STRING
}
}
}
}
Loading

0 comments on commit 2e574e0

Please sign in to comment.