Skip to content

Commit

Permalink
Merge pull request #366 from tigrisdata/main
Browse files Browse the repository at this point in the history
Minor release
  • Loading branch information
adilansari authored May 11, 2023
2 parents 54157d8 + 19860bf commit bd1e30e
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Tigris TypeScript Client Library

[![npm](https://img.shields.io/npm/v/@tigrisdata/core?logo=npm&logoColor=white)](https://www.npmjs.com/package/@tigrisdata/core)
[![npm@beta](https://img.shields.io/npm/v/@tigrisdata/core/beta.svg?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)
[![GitHub](https://img.shields.io/github/license/tigrisdata/tigris-client-ts)](https://github.com/tigrisdata/tigris-client-ts/blob/main/LICENSE)
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
},
{
"name": "beta",
"prerelease": true,
"channel": false
"prerelease": true
},
{
"name": "alpha",
Expand Down
2 changes: 1 addition & 1 deletion reviewpad.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ labels:

rules:
- name: is-release-branch
spec: $base() == "beta"
spec: $base() == "beta" || $base() == "alpha" || $base() == "release"
- name: is-main-branch
spec: $base() == "main"

Expand Down
20 changes: 20 additions & 0 deletions src/__tests__/tigris.search.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ describe("Search Indexing", () => {
const createPromise = tigris.createOrUpdateIndex("any other index", bookSchema);
await expect(createPromise).rejects.toThrow("Server error");
});
it("fails for not adding the TigrisSearchIndex decorator", async () => {
const createPromise = tigris.createOrUpdateIndex(BlogPostWithoutDecorator);
await expect(createPromise).rejects.toThrow(
"An attempt was made to retrieve an index with the name"
);
});
});

describe("getIndex", () => {
Expand Down Expand Up @@ -224,3 +230,17 @@ class BlogPost {
@SearchField({ sort: true })
createdAt: Date;
}

class BlogPostWithoutDecorator {
@SearchField({ facet: true })
text: string;

@SearchField({ elements: TigrisDataTypes.STRING })
comments: Array<string>;

@SearchField()
author: string;

@SearchField({ sort: true })
createdAt: Date;
}
3 changes: 3 additions & 0 deletions src/schema/decorated-schema-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export class DecoratedSchemaProcessor {

processIndex(cls: new () => TigrisIndexType): IndexSchema<typeof cls> {
const index = this.storage.getIndexByTarget(cls);
if (!index) {
return;
}
const schema = this.buildTigrisSchema(index.target, false);
return {
name: index.indexName,
Expand Down
10 changes: 10 additions & 0 deletions src/search/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ export class Search {

if (mayBeClass && !schema) {
const generatedIndex = this.schemaProcessor.processIndex(mayBeClass);
if (!generatedIndex) {
return new Promise<SearchIndex<T>>((resolve, reject) => {
reject(
new Error(
`An attempt was made to retrieve an index with the name ${indexName} but there is no index defined with that name.` +
+"Please make sure an index has been defined using the 'TigrisSearchIndex' decorator."
)
);
});
}
schema = generatedIndex.schema as TigrisIndexSchema<T>;
// if indexName is not provided, use the one from model class
indexName = indexName ?? generatedIndex.name;
Expand Down
5 changes: 4 additions & 1 deletion src/tigris.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,10 @@ export class Tigris {
}
}

private close(): void {
/**
* Shutdown, if ping is being used in order to keep connection alive.
*/
public close(): void {
if (this.pingId !== undefined) {
clearInterval(this.pingId);
}
Expand Down

0 comments on commit bd1e30e

Please sign in to comment.