Skip to content

Commit

Permalink
Merge pull request #313 from tigrisdata/main
Browse files Browse the repository at this point in the history
Beta release
  • Loading branch information
adilansari authored Apr 18, 2023
2 parents 1f46834 + 8274d62 commit 301ece8
Show file tree
Hide file tree
Showing 18 changed files with 523 additions and 26 deletions.
48 changes: 48 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
name: Bug report
about: File a bug
title: "[BUG]: <replace title>"
labels: bug
assignees: ""
---

# Prerequisites

Please answer the following questions for yourself before submitting an issue. **YOU MAY DELETE THE PREREQUISITES SECTION.**

- [ ] I am running the latest version
- [ ] I checked the documentation and found no answer
- [ ] I checked to make sure that this issue has not already been filed

# Expected Behavior

Please describe the behavior you are expecting

# Current Behavior

What is the current behavior?

# Failure Information (for bugs)

Please help provide information about the failure if this is a bug. If it is not a bug, please remove the rest of this template.

## Steps to Reproduce

Please provide detailed steps for reproducing the issue.

1. step 1
2. step 2
3. you get it...

## Context

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

> You can find Tigris SDK version on your local dev project by executing `npm list | grep "tigrisdata/core"`
- [Tigris SDK version](https://www.npmjs.com/package/@tigrisdata/core?activeTab=versions):
- Operating System:

## Failure Logs

Please include any relevant log snippets or files here.
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE/custom.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: Custom issue template
about: Describe this issue template's purpose here.
title: ""
labels: ""
assignees: ""
---
19 changes: 19 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Feature request
about: Suggest an idea for this project
title: ""
labels: ""
assignees: ""
---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
44 changes: 41 additions & 3 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,43 @@
## Describe your changes
## What type of PR is this? (check all applicable)

## How best to test these changes
- [ ] Refactor
- [ ] Feature
- [ ] Bug Fix
- [ ] Optimization
- [ ] Documentation Update

## Issue ticket number and link
## Description

## Related Tickets & Documents

<!--
For pull requests that relate or close an issue, please include them
below. We like to follow [Github's guidance on linking issues to pull requests](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue).
For example having the text: "closes #1234" would connect the current pull
request to issue 1234. And when we merge the pull request, Github will
automatically close the issue.
-->

- Related Issue #
- Closes #

## Added/updated tests?

- [ ] Yes
- [ ] No, and this is why: _please replace this line with details on why tests
have not been included_
- [ ] I need help with writing tests

### Is this change backwards compatible?

- [ ] Yes
- [ ] No, and this is why: _please replace this line with details on why?_

### Does it require updates to [Tigris docs](https://docs.tigrisdata.com/)?

- [ ] Yes, and here is the link: _please create an issue in [tigris-docs](https://github.com/tigrisdata/tigris-docs/issues) repo
and link here as `tigrisdata/tigris-docs#123`_
- [ ] No

## [optional] Are there any post deployment tasks we need to perform?
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Tigris TypeScript Client Library

[![npm](https://img.shields.io/npm/v/@tigrisdata/core)](https://www.npmjs.com/package/@tigrisdata/core)
[![ts-ci](https://github.com/tigrisdata/tigris-client-ts/actions/workflows/ts-ci.yml/badge.svg?branch=main)](https://github.com/tigrisdata/tigris-client-ts/actions/workflows/ts-ci.yml)
[![npm](https://img.shields.io/npm/v/@tigrisdata/core?logo=npm&logoColor=white)](https://www.npmjs.com/package/@tigrisdata/core)
[![build](https://github.com/tigrisdata/tigris-client-ts/actions/workflows/ts-ci.yml/badge.svg?branch=main)](https://github.com/tigrisdata/tigris-client-ts/actions/workflows/ts-ci.yml)
[![codecov](https://codecov.io/gh/tigrisdata/tigris-client-ts/branch/main/graph/badge.svg)](https://codecov.io/gh/tigrisdata/tigris-client-ts)
![LGTM Grade](https://img.shields.io/lgtm/grade/javascript/github/tigrisdata/tigris-client-ts)
[![discord](https://img.shields.io/badge/discord-tigrisdata-34D058.svg?logo=discord)](https://www.tigrisdata.com/discord/)
[![GitHub](https://img.shields.io/github/license/tigrisdata/tigris-client-ts)](https://github.com/tigrisdata/tigris-client-ts/blob/main/LICENSE)
[![Discord](https://img.shields.io/discord/1033842669983633488?color=%23596fff&label=Discord&logo=discord&logoColor=%23ffffff)](https://tigris.dev/discord)
[![Twitter Follow](https://img.shields.io/twitter/follow/tigrisdata?style=social)](https://twitter.com/tigrisdata)

# Documentation

Expand Down
2 changes: 1 addition & 1 deletion api/proto
Submodule proto updated from 1c4a37 to e86d66
27 changes: 27 additions & 0 deletions src/__tests__/fixtures/json-schema/students.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"title": "students",
"additionalProperties": false,
"type": "object",
"properties": {
"id": {
"type": "integer",
"format": "int64",
"autoGenerate": true
},
"email": {
"type": "string"
},
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"createdAt": {
"type": "string",
"format": "date-time",
"createdAt": true
}
},
"primary_key": ["id", "email"]
}
3 changes: 2 additions & 1 deletion src/__tests__/fixtures/schema/movies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export class Actor {

@TigrisCollection(MOVIES_COLLECTION_NAME)
export class Movie {
@PrimaryKey(TigrisDataTypes.STRING, { order: 1 })
// Ignored order in primary key options as it was only primary key.
@PrimaryKey(TigrisDataTypes.STRING)
movieId: string;

@SearchField(TigrisDataTypes.STRING)
Expand Down
93 changes: 93 additions & 0 deletions src/__tests__/fixtures/schema/student.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { TigrisCollection } from "../../../decorators/tigris-collection";
import { PrimaryKey } from "../../../decorators/tigris-primary-key";
import { TigrisDataTypes, TigrisSchema } from "../../../types";
import { Field } from "../../../decorators/tigris-field";

/******************************************************************************
* `Student` class demonstrates a Tigris collection schema generated using
* decorators. Type of collection fields is inferred using Reflection APIs. This
* particular schema example:
* - infers the type of collection fields automatically using Reflection APIs
* - has multiple primary keys
*****************************************************************************/
export const STUDENT_COLLECTION_NAME = "students";

@TigrisCollection(STUDENT_COLLECTION_NAME)
export class Student {
@PrimaryKey(TigrisDataTypes.INT64, { order: 1, autoGenerate: true })
id?: string;

@PrimaryKey(TigrisDataTypes.STRING, { order: 2 })
email: string;

@Field()
firstName!: string;

@Field()
lastName!: string;

@Field({ timestamp: "createdAt" })
createdAt?: Date;
}

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

/******************************************************************************
* `InvalidStudent` class demonstrates a Tigris collection schema validation,
* Schema is INVALID as it contains two primary keys but no order was specified
* in decorator under PrimaryKeyOptions.
*****************************************************************************/
export const INVALID_STUDENT_COLLECTION_NAME = "invalid_students";

@TigrisCollection(INVALID_STUDENT_COLLECTION_NAME)
export class InvalidStudent {
@PrimaryKey(TigrisDataTypes.INT64)
id?: string;

@PrimaryKey(TigrisDataTypes.STRING)
email: string;

@Field()
firstName!: string;

@Field()
lastName!: string;

@Field({ timestamp: "createdAt" })
createdAt?: Date;
}

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

/**
* `TigrisSchema` representation of the `Student` collection class .
*
* NOTE: This is only an illustration; you don't have to write this definition,
* it will be auto generated.
*/
export const StudentSchema: TigrisSchema<Student> = {
id: {
type: TigrisDataTypes.INT64,
primary_key: {
order: 1,
autoGenerate: true,
},
},
email: {
type: TigrisDataTypes.STRING,
primary_key: {
order: 2,
autoGenerate: false,
},
},
firstName: {
type: TigrisDataTypes.STRING,
},
lastName: {
type: TigrisDataTypes.STRING,
},
createdAt: {
type: TigrisDataTypes.DATE_TIME,
timestamp: "createdAt",
},
};
39 changes: 39 additions & 0 deletions src/__tests__/test-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
DescribeDatabaseResponse,
DropCollectionRequest,
DropCollectionResponse,
ExplainResponse,
FacetCount,
InsertRequest,
InsertResponse,
Expand Down Expand Up @@ -83,6 +84,11 @@ export class TestTigrisService {
["5", "eyJpZCI6NSwidGl0bGUiOiJUaW1lIFJlZ2FpbmVkIiwiYXV0aG9yIjoiTWFyY2VsIFByb3VzdCJ9"],
// base64 of {"id":6,"title":"The Prisoner","author":"Marcel Proust"}
["6", "eyJpZCI6NiwidGl0bGUiOiJUaGUgUHJpc29uZXIiLCJhdXRob3IiOiJNYXJjZWwgUHJvdXN0In0="],
// base64 of {"id":7,"title":"A Passage to India","author":"E.M. Forster","tags":["Novel","India"], "purchasedOn": "2023-04-14T09:39:19.288Z"}
[
"7",
"eyJpZCI6NywidGl0bGUiOiJBIFBhc3NhZ2UgdG8gSW5kaWEiLCJhdXRob3IiOiJFLk0uIEZvcnN0ZXIiLCJ0YWdzIjpbIk5vdmVsIiwiSW5kaWEiXSwgInB1cmNoYXNlZE9uIjogIjIwMjMtMDQtMTRUMDk6Mzk6MTkuMjg4WiJ9",
],
]);

public static readonly ALERTS_B64_BY_ID: ReadonlyMap<number, string> = new Map([
Expand Down Expand Up @@ -178,6 +184,10 @@ export class TestTigrisService {
call: ServerUnaryCall<ListCollectionsRequest, ListCollectionsResponse>,
callback: sendUnaryData<ListCollectionsResponse>
): void;
explain(
call: ServerUnaryCall<ReadRequest, ExplainResponse>,
callback: sendUnaryData<ExplainResponse>
): void;
} = {
createBranch(
call: ServerUnaryCall<CreateBranchRequest, CreateBranchResponse>,
Expand Down Expand Up @@ -482,6 +492,16 @@ export class TestTigrisService {
// base64 of book id "1"
call.write(new ReadResponse().setData(TestTigrisService.BOOKS_B64_BY_ID.get("1")));
call.end();
}
// for date type test purpose if id = 7, we find the record, else we don't
else if (
call.request.getOptions() != undefined &&
call.request.getOptions().getLimit() == 1 &&
filter["id"] == 7
) {
// base64 of book id "7"
call.write(new ReadResponse().setData(TestTigrisService.BOOKS_B64_BY_ID.get("7")));
call.end();
} else if (
call.request.getOptions() != undefined &&
call.request.getOptions().getLimit() == 1 &&
Expand Down Expand Up @@ -634,6 +654,25 @@ export class TestTigrisService {
);
callback(undefined, reply);
},
explain(
call: ServerUnaryCall<ReadRequest, ExplainResponse>,
callback: sendUnaryData<ExplainResponse>
): void {
assert(call.request.getBranch() === TestTigrisService.ExpectedBranch);

if (call.request.getProject() === "test-tx") {
const txIdHeader = call.metadata.get("Tigris-Tx-Id").toString();
const txOriginHeader = call.metadata.get("Tigris-Tx-Origin").toString();
if (txIdHeader != TestTigrisService.txId || txOriginHeader != TestTigrisService.txOrigin) {
callback(new Error("transaction mismatch - explain"));
return;
}
}
const reply: ExplainResponse = new ExplainResponse();
reply.setFilter(JSON.stringify({ author: "Marcel Proust" }));
reply.setReadType("secondary index");
callback(undefined, reply);
},
};
}

Expand Down
Loading

0 comments on commit 301ece8

Please sign in to comment.