Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade dependencies and Orama #111

Merged
merged 8 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
name: ci

on: [push, pull_request]
on:
push:
branches:
- main
pull_request:
branches:
- '*'

jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14, 16, 18, 19]
node-version: [16, 18, 20]
redis-tag: [5, 6]
services:
redis:
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16
v18
2 changes: 1 addition & 1 deletion benchmark/orama-cache.mjs → benchmark/orama-cache.js
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
31 changes: 16 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -26,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": [
Expand All @@ -41,25 +42,25 @@
},
"license": "MIT",
"dependencies": {
"@orama/orama": "1.0.0",
"async-cache-dedupe": "^1.10.2"
"@orama/orama": "^2.0.0-beta.1",
"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"
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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"

export async function createOramaCache(db: Orama, cacheOptions: CreateCacheOptions = {ttl: 60, storage: {type: "memory"}}) {
async function searchOrama(params: SearchParams): Promise<Results> {
export async function createOramaCache<T>(db: Orama<T>, cacheOptions: CreateCacheOptions = {ttl: 60, storage: {type: "memory"}}) {
async function searchOrama(params: SearchParams<Orama<T>, T>): Promise<Results<T>> {
return search(db, params)
}

Expand Down
18 changes: 9 additions & 9 deletions src/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -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}}
Expand All @@ -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"})
Expand All @@ -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"})
Expand All @@ -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)
Expand All @@ -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)
})

Expand All @@ -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)
Expand All @@ -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()
Expand Down
16 changes: 7 additions & 9 deletions src/tests/storage-redis.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
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()
})

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",
Expand All @@ -27,8 +26,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"})
Expand Down
2 changes: 1 addition & 1 deletion src/tests/validation.test.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 4 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"src/**/*.test.ts"
],
"compilerOptions": {
"target": "ESNext",
"module": "CommonJS",
Expand Down
4 changes: 4 additions & 0 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"src/**/*.test.ts"
],
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
Expand Down
19 changes: 11 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -18,12 +18,15 @@
"async-cache-dedupe": [
"./src/types/index.d.ts"
],
}
},
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules"
]
}
"node_modules",
],
// "ts-node": {
// "esm": true
// }
}