diff --git a/README.md b/README.md index 21cc2b5..82c87f0 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/package.json b/package.json index b849fff..03c7c97 100644 --- a/package.json +++ b/package.json @@ -40,8 +40,7 @@ }, { "name": "beta", - "prerelease": true, - "channel": false + "prerelease": true }, { "name": "alpha", diff --git a/reviewpad.yml b/reviewpad.yml index a33ad08..75a4b75 100644 --- a/reviewpad.yml +++ b/reviewpad.yml @@ -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" diff --git a/src/__tests__/tigris.search.spec.ts b/src/__tests__/tigris.search.spec.ts index fbbe102..632f696 100644 --- a/src/__tests__/tigris.search.spec.ts +++ b/src/__tests__/tigris.search.spec.ts @@ -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", () => { @@ -224,3 +230,17 @@ class BlogPost { @SearchField({ sort: true }) createdAt: Date; } + +class BlogPostWithoutDecorator { + @SearchField({ facet: true }) + text: string; + + @SearchField({ elements: TigrisDataTypes.STRING }) + comments: Array; + + @SearchField() + author: string; + + @SearchField({ sort: true }) + createdAt: Date; +} diff --git a/src/schema/decorated-schema-processor.ts b/src/schema/decorated-schema-processor.ts index 8a6f6d0..9b02456 100644 --- a/src/schema/decorated-schema-processor.ts +++ b/src/schema/decorated-schema-processor.ts @@ -40,6 +40,9 @@ export class DecoratedSchemaProcessor { processIndex(cls: new () => TigrisIndexType): IndexSchema { const index = this.storage.getIndexByTarget(cls); + if (!index) { + return; + } const schema = this.buildTigrisSchema(index.target, false); return { name: index.indexName, diff --git a/src/search/search.ts b/src/search/search.ts index 9d4911f..854c541 100644 --- a/src/search/search.ts +++ b/src/search/search.ts @@ -53,6 +53,16 @@ export class Search { if (mayBeClass && !schema) { const generatedIndex = this.schemaProcessor.processIndex(mayBeClass); + if (!generatedIndex) { + return new Promise>((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; // if indexName is not provided, use the one from model class indexName = indexName ?? generatedIndex.name; diff --git a/src/tigris.ts b/src/tigris.ts index 2b0e2e8..d6ee982 100644 --- a/src/tigris.ts +++ b/src/tigris.ts @@ -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); }