From 3153f46f7d1a9bea1777201eaf38ea81cf71ead9 Mon Sep 17 00:00:00 2001 From: mateonunez Date: Sat, 14 Oct 2023 12:39:45 +0200 Subject: [PATCH 1/8] chore(package): uppdate dependencies Signed-off-by: mateonunez --- .nvmrc | 2 +- package.json | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.nvmrc b/.nvmrc index 5edcff0..3f430af 100644 --- a/.nvmrc +++ b/.nvmrc @@ -1 +1 @@ -v16 \ No newline at end of file +v18 diff --git a/package.json b/package.json index c12ae4e..77c8cd0 100644 --- a/package.json +++ b/package.json @@ -42,24 +42,24 @@ "license": "MIT", "dependencies": { "@orama/orama": "1.0.0", - "async-cache-dedupe": "^1.10.2" + "async-cache-dedupe": "^1.12.0" }, "devDependencies": { - "@types/node": "^20.1.0", - "@types/tap": "^15.0.8", - "@typescript-eslint/eslint-plugin": "^5.58.0", - "@typescript-eslint/parser": "^5.58.0", - "c8": "^7.13.0", + "@types/node": "^20.8.6", + "@types/tap": "^15.0.9", + "@typescript-eslint/eslint-plugin": "^5.62.0", + "@typescript-eslint/parser": "^5.62.0", + "c8": "^7.14.0", "cronometro": "^1.1.5", - "esbuild": "^0.17.16", - "eslint": "^8.38.0", + "esbuild": "^0.17.19", + "eslint": "^8.51.0", "husky": "^8.0.3", - "ioredis": "^5.3.1", - "prettier": "^2.8.7", - "rimraf": "^5.0.0", - "tap": "^16.3.4", + "ioredis": "^5.3.2", + "prettier": "^2.8.8", + "rimraf": "^5.0.5", + "tap": "^16.3.9", "ts-node": "^10.9.1", - "typescript": "^5.0.4" + "typescript": "^5.2.2" }, "publishConfig": { "access": "public" From f6cd29a820fec55eb99a908d9c9fc9755f3c3b36 Mon Sep 17 00:00:00 2001 From: mateonunez Date: Sat, 14 Oct 2023 13:29:58 +0200 Subject: [PATCH 2/8] chore(package)!: upgrade orama to v2 Signed-off-by: mateonunez --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 77c8cd0..c380eb9 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ }, "license": "MIT", "dependencies": { - "@orama/orama": "1.0.0", + "@orama/orama": "^2.0.0-beta.1", "async-cache-dedupe": "^1.12.0" }, "devDependencies": { From b4bcaa0534e36f225dd2182bee5c067cf41f8e7b Mon Sep 17 00:00:00 2001 From: mateonunez Date: Sat, 14 Oct 2023 13:30:37 +0200 Subject: [PATCH 3/8] fix: improve types Signed-off-by: mateonunez --- src/index.ts | 4 ++-- src/tests/index.test.ts | 16 ++++++++-------- src/tests/storage-redis.test.ts | 8 +++++--- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/index.ts b/src/index.ts index 987d4ad..53efbda 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,8 +5,8 @@ import {validateOptions} from "./lib/validation" import type {CreateCacheOptions} from "async-cache-dedupe" import type {Orama, Results, SearchParams} from "@orama/orama" -export async function createOramaCache(db: Orama, cacheOptions: CreateCacheOptions = {ttl: 60, storage: {type: "memory"}}) { - async function searchOrama(params: SearchParams): Promise { +export async function createOramaCache(db: Orama, cacheOptions: CreateCacheOptions = {ttl: 60, storage: {type: "memory"}}) { + async function searchOrama(params: SearchParams, T>): Promise> { return search(db, params) } diff --git a/src/tests/index.test.ts b/src/tests/index.test.ts index c9c04ed..290ddbe 100644 --- a/src/tests/index.test.ts +++ b/src/tests/index.test.ts @@ -12,8 +12,8 @@ test("cache", async ({test}) => { const db = await create({schema: {name: "string"}}) const cache = await createOramaCache(db) - await insert(db, {name: "foo"}) - await insert(db, {name: "bar"}) + await insert(db, {name: "foo"} as never) + await insert(db, {name: "bar"} as never) const results1 = await cache.search({term: "foo"}) const resultsCached = await cache.search({term: "foo"}) @@ -34,8 +34,8 @@ test("should cache results with multiple Orama instances", async t => { const cache = await createOramaCache(db1) const cache2 = await createOramaCache(db2) - await insert(db1, {name: "foo"}) - await insert(db2, {description: "foo"}) + await insert(db1, {name: "foo"} as never) + await insert(db2, {description: "foo"} as never) const results1 = await cache.search({term: "foo"}) const results2 = await cache2.search({term: "foo"}) @@ -53,7 +53,7 @@ test("should hit a cached key", async t => { onHit: (key: string) => t.same(JSON.parse(key), searchable) }) - await insert(db, {name: "foo"}) + await insert(db, {name: "foo"} as never) await cache.search(searchable) await cache.search(searchable) await cache.search(searchable) @@ -68,7 +68,7 @@ test("should miss a cached key", async t => { onMiss: (key: string) => t.same(JSON.parse(key), searchable) }) - await insert(db, {name: "foo"}) + await insert(db, {name: "foo"} as never) await cache.search(searchable) }) @@ -82,7 +82,7 @@ test("ttl should expire a cached key", async t => { onMiss: (key: string) => t.same(JSON.parse(key), searchable) }) - await insert(db, {name: "foo"}) + await insert(db, {name: "foo"} as never) await cache.search(searchable) await sleep(1500) @@ -99,7 +99,7 @@ test("clear should clear the cache", async t => { onMiss: (key: string) => t.same(JSON.parse(key), searchable) }) - await insert(db, {name: "foo"}) + await insert(db, {name: "foo"} as never) await cache.search(searchable) cache.clear() diff --git a/src/tests/storage-redis.test.ts b/src/tests/storage-redis.test.ts index 4890caa..57a4a2f 100644 --- a/src/tests/storage-redis.test.ts +++ b/src/tests/storage-redis.test.ts @@ -17,7 +17,10 @@ teardown(async () => { test("orama cache with redis storage", async t => { t.plan(1) - const db = await create({schema: {name: "string"}}) + const db = await create({ + schema: {name: "string"} + }) + const cache = await createOramaCache(db, { storage: { type: "redis", @@ -27,8 +30,7 @@ test("orama cache with redis storage", async t => { } }) - await insert(db, {name: "foo"}) - await insert(db, {name: "bar"}) + await insert(db, {name: "foo"} as never) const results = await cache.search({term: "foo"}) const resultsCached = await cache.search({term: "foo"}) From b5be64dfe73e7eea120e1444998aa21fa38c29a5 Mon Sep 17 00:00:00 2001 From: mateonunez Date: Sat, 14 Oct 2023 13:31:55 +0200 Subject: [PATCH 4/8] chore(ci): use Node v20 Signed-off-by: mateonunez --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f17f82e..d63dc5a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [14, 16, 18, 19] + node-version: [14, 16, 18, 20] redis-tag: [5, 6] services: redis: From 025c22dfaad002f8c8bf69181a82a23d54df9048 Mon Sep 17 00:00:00 2001 From: mateonunez Date: Sat, 14 Oct 2023 13:32:11 +0200 Subject: [PATCH 5/8] chore(ci): remove Node v14 Signed-off-by: mateonunez --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d63dc5a..03ce0d1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node-version: [14, 16, 18, 20] + node-version: [16, 18, 20] redis-tag: [5, 6] services: redis: From 066e85156437f53ad92ff5faf626f1095428dc96 Mon Sep 17 00:00:00 2001 From: mateonunez Date: Sat, 14 Oct 2023 13:33:37 +0200 Subject: [PATCH 6/8] chore(ci): run push only on main Signed-off-by: mateonunez --- .github/workflows/ci.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 03ce0d1..4469b78 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,12 @@ name: ci -on: [push, pull_request] +on: + push: + branches: + - main + pull_request: + branches: + - '*' jobs: tests: From ebe516cdcb2927419e9eb598674728579e146bdf Mon Sep 17 00:00:00 2001 From: mateonunez Date: Sat, 14 Oct 2023 14:00:12 +0200 Subject: [PATCH 7/8] chore: make Node v20 passing tests Signed-off-by: mateonunez --- package.json | 1 + src/index.ts | 2 +- src/tests/index.test.ts | 2 +- src/tests/storage-redis.test.ts | 8 ++------ src/tests/validation.test.ts | 2 +- tsconfig.cjs.json | 4 ++++ tsconfig.esm.json | 4 ++++ tsconfig.json | 19 +++++++++++-------- 8 files changed, 25 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index c380eb9..d2c2167 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "module": "./dist/esm/index.js", "types": "./dist/esm/index.d.ts", "browser": "./dist/client/index.js", + "type": "module", "homepage": "https://github.com/mateonunez/orama-cache#readme", "repository": { "type": "git", diff --git a/src/index.ts b/src/index.ts index 53efbda..ab4fac8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ import {createCache as createAsynCacheDedupe} from "async-cache-dedupe" import {search} from "@orama/orama" -import {validateOptions} from "./lib/validation" +import {validateOptions} from "./lib/validation.js" import type {CreateCacheOptions} from "async-cache-dedupe" import type {Orama, Results, SearchParams} from "@orama/orama" diff --git a/src/tests/index.test.ts b/src/tests/index.test.ts index 290ddbe..25e68e3 100644 --- a/src/tests/index.test.ts +++ b/src/tests/index.test.ts @@ -1,7 +1,7 @@ import {test} from "tap" import {promisify} from "util" import {create, insert} from "@orama/orama" -import {createOramaCache} from ".." +import {createOramaCache} from "../index.js" const sleep = promisify(setTimeout) const searchable = {term: "foo", relevance: {k: 0, b: 0, d: 0}} diff --git a/src/tests/storage-redis.test.ts b/src/tests/storage-redis.test.ts index 57a4a2f..1904f3e 100644 --- a/src/tests/storage-redis.test.ts +++ b/src/tests/storage-redis.test.ts @@ -1,15 +1,11 @@ -import {test, before, teardown} from "tap" +import {test, teardown} from "tap" import {create, insert} from "@orama/orama" -import {createOramaCache} from ".." +import {createOramaCache} from "../index.js" import Redis from "ioredis" const redisClient = new Redis() -before(async () => { - await redisClient.flushall() -}) - teardown(async () => { await redisClient.quit() }) diff --git a/src/tests/validation.test.ts b/src/tests/validation.test.ts index e1dc2a4..8f9d0f0 100644 --- a/src/tests/validation.test.ts +++ b/src/tests/validation.test.ts @@ -1,6 +1,6 @@ import {CreateCacheOptions, OptionsMemory, ValidatedCacheOptions} from "async-cache-dedupe" import {test} from "tap" -import {validateOptions} from "../lib/validation" +import {validateOptions} from "../lib/validation.js" test("should validate ttl", ({plan, throws}) => { plan(1) diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json index 390b448..084b5c3 100644 --- a/tsconfig.cjs.json +++ b/tsconfig.cjs.json @@ -3,6 +3,10 @@ "include": [ "src/**/*.ts" ], + "exclude": [ + "node_modules", + "src/**/*.test.ts" + ], "compilerOptions": { "target": "ESNext", "module": "CommonJS", diff --git a/tsconfig.esm.json b/tsconfig.esm.json index 4a2b32d..57c4496 100644 --- a/tsconfig.esm.json +++ b/tsconfig.esm.json @@ -3,6 +3,10 @@ "include": [ "src/**/*.ts" ], + "exclude": [ + "node_modules", + "src/**/*.test.ts" + ], "compilerOptions": { "target": "ESNext", "module": "ESNext", diff --git a/tsconfig.json b/tsconfig.json index d57cf70..d8c2d42 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,12 +1,12 @@ { "compilerOptions": { - "target": "ES2022", - "module": "CommonJS", + "target": "ESNext", + "module": "ESNext", "lib": [ "ESNext", - "DOM", + "DOM" ], - "moduleResolution": "node", + "moduleResolution": "Node", "esModuleInterop": true, "declaration": true, "forceConsistentCasingInFileNames": true, @@ -18,12 +18,15 @@ "async-cache-dedupe": [ "./src/types/index.d.ts" ], - } + }, }, "include": [ "src/**/*" ], "exclude": [ - "node_modules" - ] -} \ No newline at end of file + "node_modules", + ], + // "ts-node": { + // "esm": true + // } +} From ede8f38057e1f1c0be7ad37bd5c4c0a9f89493c0 Mon Sep 17 00:00:00 2001 From: mateonunez Date: Sat, 14 Oct 2023 14:03:24 +0200 Subject: [PATCH 8/8] perf: improve benchmark script Signed-off-by: mateonunez --- benchmark/{orama-cache.mjs => orama-cache.js} | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename benchmark/{orama-cache.mjs => orama-cache.js} (95%) diff --git a/benchmark/orama-cache.mjs b/benchmark/orama-cache.js similarity index 95% rename from benchmark/orama-cache.mjs rename to benchmark/orama-cache.js index 2d4e698..c1182d6 100644 --- a/benchmark/orama-cache.mjs +++ b/benchmark/orama-cache.js @@ -1,6 +1,6 @@ import cronometro from "cronometro" import {create, insertMultiple, search} from "@orama/orama" -import {createOramaCache} from "../dist/cjs/index.js" +import {createOramaCache} from "../dist/esm/index.js" import events from "./dataset/events.mjs" const db = await create({ diff --git a/package.json b/package.json index d2c2167..9f4781e 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "build:browser": "esbuild --bundle --sourcemap --target=es2019 --format=esm --outfile=./dist/client/index.js ./src/index.ts", "build": "rimraf ./dist && npm run build:esm && npm run build:cjs && npm run build:browser", "prepare": "husky install", - "benchmark": "node --no-warnings ./benchmark/orama-cache.mjs", + "benchmark": "node --no-warnings ./benchmark/orama-cache.js", "redis": "docker run --rm -p 6379:6379 redis redis-server" }, "keywords": [