Skip to content

Commit 7f2d731

Browse files
authored
chore(deps)!: bump @orama/orama and @orama/plugin-data-persistence to 3.0.5 (#197)
* chore(deps): bump @orama/orama to 3.0.5 and @orama/plugin-data-persistence to 3.0.5 * Update README. * Remove async calls when orama function is not async. Fix README. Improve .gitignore. Update tests.
1 parent 45b8752 commit 7f2d731

File tree

10 files changed

+63
-60
lines changed

10 files changed

+63
-60
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,13 @@ dist
140140
.idea
141141

142142
# DB test
143+
*.msp
143144
orama.json
145+
orama_[0-9]*.json
146+
orama_test_[0-9]*.json
144147

145148
# Snyk
146149
.dccache
147150
package-lock.json
148151
pnpm-lock.yaml
149152
yarn.lock
150-
*.msp
151-
orama_[0-9]*.json

README.md

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@ npm install fastify-orama
1313
### Compatibility
1414

1515
| Plugin version | Fastify version | Orama version |
16-
| ------------- |:---------------:|------------:|
17-
| `^2.0.0` | `^5.0.0` | `^2.0.0` |
18-
| `^1.0.0` | `^4.0.0` | `^2.0.0` |
16+
|----------------|:---------------:|--------------:|
17+
| `^3.0.0` | `^5.0.0` | `^3.0.0` |
18+
| `^2.0.0` | `^5.0.0` | `^2.0.0` |
19+
| `^1.0.0` | `^4.0.0` | `^2.0.0` |
1920

2021
****
2122

22-
2323
## Usage
2424

2525
This plugin adds the `orama` decorator to your Fastify application.
26-
The decorator exposes all the methods that [the Orama class exposes](https://docs.oramasearch.com/open-source/usage/create).
26+
The decorator exposes all the methods
27+
that [the Orama class exposes](https://docs.oramasearch.com/open-source/usage/create).
2728

2829
The `options` object is passed directly to the `Orama.create` constructor,
2930
so it supports [all the options that Orama supports](https://docs.oramasearch.com/open-source/usage/create).
@@ -46,7 +47,7 @@ app.register(fastifyOrama, {
4647
app.get('/quotes/:query', async function handler (req, reply) {
4748
const { params: { query } } = req
4849

49-
const search = await app.orama.search({
50+
const search = app.orama.search({
5051
term: query,
5152
properties: ["quote"]
5253
})
@@ -57,13 +58,13 @@ app.get('/quotes/:query', async function handler (req, reply) {
5758
app.listen({ port: 3000 })
5859
```
5960

60-
6161
## Usage with data persistence
6262

6363
This plugin supports data persistence out of the box.
6464
You need to pass the `persistence` option to the plugin registration!
6565

66-
This plugin uses [`@oramasearch/plugin-data-persistence`](https://docs.oramasearch.com/open-source/plugins/plugin-data-persistence)
66+
This plugin uses [
67+
`@oramasearch/plugin-data-persistence`](https://docs.oramasearch.com/open-source/plugins/plugin-data-persistence)
6768
under the hood to allow users to `load` or `persist` database instances.
6869

6970
Turning on the `persistence` option will add the `fastify.orama.persist()` method to your Fastify application.
@@ -78,8 +79,8 @@ Its constructor accepts the following options:
7879

7980
- `filePath`: The path to the file where the data will be persisted. Default: `./orama.msp`
8081
- `format`: The format of the file where the data will be persisted. Default: `binary`
81-
- `mustExistOnStart`: Whether the file must exist when the plugin is registered or not. Default: `false`. Note that if the file does not exist, you must specify the `schema` option in the plugin registration.
82-
82+
- `mustExistOnStart`: Whether the file must exist when the plugin is registered or not. Default: `false`. Note that if
83+
the file does not exist, you must specify the `schema` option in the plugin registration.
8384

8485
```js
8586
import Fastify from 'fastify'
@@ -100,10 +101,10 @@ app.register(fastifyOrama, {
100101
})
101102
})
102103

103-
app.post('/quotes', async function (req, reply) {
104+
app.post('/quotes', function (req, reply) {
104105
const { body: { author, quote } } = req
105106

106-
await fastify.orama.insert({
107+
fastify.orama.insert({
107108
author,
108109
quote
109110
})
@@ -122,7 +123,8 @@ app.listen({ port: 3000 })
122123
### PersistenceInMemory
123124

124125
This plugin comes with a `PersistenceInMemory` class that allows you to persist your data in memory.
125-
This adapter may be useful for testing purposes, when you need to share the same database instance between multiple tests.
126+
This adapter may be useful for testing purposes, when you need to share the same database instance between multiple
127+
tests.
126128

127129
Its constructor accepts the following options:
128130

@@ -140,7 +142,7 @@ await appOne.register(fastifyOrama, {
140142
})
141143

142144
// Do some stuff with the database
143-
await appOne.orama.insert({
145+
appOne.orama.insert({
144146
quote: 'Orama and Fastify are awesome together.',
145147
author: 'Mateo Nunez'
146148
})
@@ -160,7 +162,7 @@ await appTwo.register(fastifyOrama, {
160162
})
161163

162164
// The database is persisted between Fastify applications
163-
const results = await appTwo.orama.search({ term: 'Mateo Nunez' })
165+
const results = appTwo.orama.search({ term: 'Mateo Nunez' })
164166
```
165167

166168
### Custom persistence
@@ -205,8 +207,8 @@ app.register(fastifyOrama, {
205207
}
206208
})
207209

208-
app.get('/genId', async function handler (req, reply) {
209-
return { newId: await oramaInternals.uniqueId() }
210+
app.get('/genId', function handler (req, reply) {
211+
return { newId: oramaInternals.uniqueId() }
210212
})
211213
```
212214

@@ -233,12 +235,12 @@ await app.register(fastifyOrama, {
233235
})
234236

235237
const appWithOrama = app.withOrama<typeof mySchema>()
236-
const id = await appWithOrama.orama.insert({ quote: 'Hello', author: 'World' })
238+
const id = appWithOrama.orama.insert({ quote: 'Hello', author: 'World' })
237239

238240
appWithOrama.get('/hello', async () => {
239241

240242
const {orama} = appWithOrama
241-
const result = await orama.search({ term: 'hello' })
243+
const result = orama.search({ term: 'hello' })
242244

243245
return {
244246
hello: result.hits
@@ -255,8 +257,8 @@ fp(function plugins(fastify) {
255257
const fastifyWithOrama = fastify.withOrama<typeof mySchema>()
256258

257259
expectType<{
258-
insert: (document: PartialSchemaDeep<TypedDocument<Orama<typeof mySchema>>>) => Promise<string>,
259-
search: (params: SearchParams<Orama<Schema<typeof mySchema>>, typeof mySchema>) => Promise<Results<Schema<typeof mySchema>>>,
260+
insert: (document: PartialSchemaDeep<TypedDocument<Orama<typeof mySchema>>>) => string,
261+
search: (params: SearchParams<Orama<Schema<typeof mySchema>>, typeof mySchema>) => Results<Schema<typeof mySchema>>,
260262
persist?: () => Promise<any>,
261263
}>(fastifyWithOrama.orama)
262264
})

index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ type FastifyOramaPluginOptions = {
3232
declare const fastifyOrama: FastifyPluginCallback<FastifyOramaPluginOptions>
3333

3434
interface OramaApi<T> {
35-
insert: (document: PartialSchemaDeep<TypedDocument<Orama<T>>>) => Promise<string>,
36-
search: (params: SearchParams<Orama<Schema<T>>, T>) => Promise<Results<Schema<T>>>,
35+
insert: (document: PartialSchemaDeep<TypedDocument<Orama<T>>>) => string,
36+
search: (params: SearchParams<Orama<Schema<T>>, T>) => Results<Schema<T>>,
3737
persist?: () => Promise<any>,
3838
}
3939

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ async function fastifyOrama (fastify, options) {
4848
throw new Error('You must provide a schema to create a new database')
4949
}
5050

51-
db = await Orama.create(oramaOptions)
51+
db = Orama.create(oramaOptions)
5252
}
5353

5454
function withOrama () {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
},
4040
"homepage": "https://github.com/mateonunez/fastify-orama#readme",
4141
"dependencies": {
42-
"@orama/orama": "^2.0.0",
43-
"@orama/plugin-data-persistence": "^2.0.0",
42+
"@orama/orama": "^3.0.5",
43+
"@orama/plugin-data-persistence": "^3.0.5",
4444
"fastify-plugin": "^5.0.0"
4545
},
4646
"devDependencies": {

test/index.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ it('Should insert and retrieve data using Orama', async () => {
2828
}
2929
})
3030

31-
await fastify.orama.insert({
31+
fastify.orama.insert({
3232
quote: 'Hi there! This is fastify-orama plugin.',
3333
author: 'Mateo Nunez'
3434
})
3535

36-
const search = await fastify.orama.search({
36+
const search = fastify.orama.search({
3737
term: 'fastify-orama'
3838
})
3939

test/orama-proxy.test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ it('Should expose all the Orama APIs', async () => {
1919
}
2020
})
2121

22-
const harryPotterId = await fastify.orama.insert({
22+
const harryPotterId = fastify.orama.insert({
2323
title: 'Harry Potter and the Philosopher\'s Stone',
2424
director: 'Chris Columbus',
2525
plot: 'Harry Potter, an eleven-year-old orphan, discovers that he is a wizard and is invited to study at Hogwarts. Even as he escapes a dreary life and enters a world of magic, he finds trouble awaiting him.',
@@ -45,25 +45,25 @@ it('Should expose all the Orama APIs', async () => {
4545
}
4646
]
4747

48-
const docIds = await fastify.orama.insertMultiple(docs, 500)
48+
const docIds = fastify.orama.insertMultiple(docs, 500)
4949
ok(docIds.length === 2, 'the ids are returned')
5050

51-
const thePrestige = await fastify.orama.getByID(docIds[0])
51+
const thePrestige = fastify.orama.getByID(docIds[0])
5252
strictEqual(thePrestige.title, 'The prestige')
5353

54-
const docNumber = await fastify.orama.count()
54+
const docNumber = fastify.orama.count()
5555
strictEqual(docNumber, 3)
5656

57-
const del = await fastify.orama.remove(harryPotterId)
57+
const del = fastify.orama.remove(harryPotterId)
5858
ok(del, 'the document was deleted')
5959

60-
const docNumberUpdated = await fastify.orama.count()
60+
const docNumberUpdated = fastify.orama.count()
6161
strictEqual(docNumberUpdated, 2)
6262

63-
const delMultiple = await fastify.orama.removeMultiple(docIds, 500)
63+
const delMultiple = fastify.orama.removeMultiple(docIds, 500)
6464
strictEqual(delMultiple, 2, 'the documents were deleted')
6565

66-
const docEmpty = await fastify.orama.count()
66+
const docEmpty = fastify.orama.count()
6767
strictEqual(docEmpty, 0)
6868
})
6969

@@ -98,8 +98,8 @@ it('Should not expose Orama internals', async () => {
9898
}
9999
})
100100

101-
fastify.get('/genId', async function handler () {
102-
return { newId: await oramaInternals.uniqueId() }
101+
fastify.get('/genId', function handler () {
102+
return { newId: oramaInternals.uniqueId() }
103103
})
104104

105105
const response = await fastify.inject('/genId')

test/persistence.test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ const { create, insert } = require('@orama/orama')
88
const { persistToFile } = require('@orama/plugin-data-persistence/server')
99

1010
async function buildFakeDb (filePath, format) {
11-
const db = await create({
11+
const db = create({
1212
schema: {
1313
author: 'string',
1414
quote: 'string'
1515
}
1616
})
1717

18-
await insert(db, {
18+
insert(db, {
1919
author: 'Mateo Nunez',
2020
quote: 'Hi there! This is fastify-orama plugin.'
2121
})
@@ -39,7 +39,7 @@ describe('PersistenceInFile', () => {
3939

4040
await fastify.ready()
4141

42-
const results = await fastify.orama.search({ term: 'fastify-orama' })
42+
const results = fastify.orama.search({ term: 'fastify-orama' })
4343
strictEqual(results.count, 1)
4444

4545
const { document } = results.hits[Object.keys(results.hits)[0]]
@@ -56,7 +56,7 @@ describe('PersistenceInFile', () => {
5656

5757
await fastify.ready()
5858

59-
const results = await fastify.orama.search({ term: 'fastify-orama' })
59+
const results = fastify.orama.search({ term: 'fastify-orama' })
6060
strictEqual(results.count, 1)
6161

6262
const { document } = results.hits[Object.keys(results.hits)[0]]
@@ -78,11 +78,11 @@ describe('PersistenceInFile', () => {
7878
await fastify.ready()
7979

8080
{
81-
const results = await fastify.orama.search({ term: 'Mateo Nunez' })
81+
const results = fastify.orama.search({ term: 'Mateo Nunez' })
8282
strictEqual(results.count, 0)
8383
}
8484

85-
await fastify.orama.insert({
85+
fastify.orama.insert({
8686
quote: 'Orama and Fastify are awesome together.',
8787
author: 'Mateo Nunez'
8888
})
@@ -91,7 +91,7 @@ describe('PersistenceInFile', () => {
9191
strictEqual(path, opts.filePath)
9292

9393
{
94-
const results = await fastify.orama.search({ term: 'Mateo Nunez' })
94+
const results = fastify.orama.search({ term: 'Mateo Nunez' })
9595
strictEqual(results.count, 1)
9696
}
9797
})
@@ -133,7 +133,7 @@ describe('PersistenceInFile', () => {
133133

134134
await fastify.ready()
135135

136-
const results = await fastify.orama.search({ term: 'fastify-orama' })
136+
const results = fastify.orama.search({ term: 'fastify-orama' })
137137
strictEqual(results.count, 1)
138138
})
139139
})
@@ -149,19 +149,19 @@ describe('PersistenceInMemory', () => {
149149
await fastifyOne.ready()
150150

151151
{
152-
const results = await fastifyOne.orama.search({ term: 'Mateo Nunez' })
152+
const results = fastifyOne.orama.search({ term: 'Mateo Nunez' })
153153
strictEqual(results.count, 0)
154154
}
155155

156-
await fastifyOne.orama.insert({
156+
fastifyOne.orama.insert({
157157
quote: 'Orama and Fastify are awesome together.',
158158
author: 'Mateo Nunez'
159159
})
160160

161161
const inMemoryDb = await fastifyOne.orama.persist()
162162

163163
{
164-
const results = await fastifyOne.orama.search({ term: 'Mateo Nunez' })
164+
const results = fastifyOne.orama.search({ term: 'Mateo Nunez' })
165165
strictEqual(results.count, 1)
166166
}
167167

@@ -177,7 +177,7 @@ describe('PersistenceInMemory', () => {
177177
await fastifyTwo.ready()
178178

179179
{
180-
const results = await fastifyTwo.orama.search({ term: 'Mateo Nunez' })
180+
const results = fastifyTwo.orama.search({ term: 'Mateo Nunez' })
181181
strictEqual(results.count, 1)
182182
}
183183
})

test/types/index.test-d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ app.register(fastifyOrama, {
4343
})
4444

4545
const appWithOrama = app.withOrama<typeof mySchema>()
46-
const id = await appWithOrama.orama.insert({ quote: 'Hello', author: 'World' })
46+
const id = appWithOrama.orama.insert({ quote: 'Hello', author: 'World' })
4747
expectType<string>(id)
4848

4949
appWithOrama.get('/hello', async () => {
5050

5151
const {orama} = appWithOrama
52-
const result = await orama.search({ term: 'hello' })
52+
const result = orama.search({ term: 'hello' })
5353

5454
expectType<Results<InternalTypedDocument<MySchema>>>(result)
5555
expectType<string>(result.hits[0].document.author)
@@ -60,17 +60,17 @@ appWithOrama.get('/hello', async () => {
6060
})
6161

6262
expectType<{
63-
insert: (document: PartialSchemaDeep<TypedDocument<Orama<typeof mySchema>>>) => Promise<string>,
64-
search: (params: SearchParams<Orama<Schema<typeof mySchema>>, typeof mySchema>) => Promise<Results<Schema<typeof mySchema>>>,
63+
insert: (document: PartialSchemaDeep<TypedDocument<Orama<typeof mySchema>>>) => string,
64+
search: (params: SearchParams<Orama<Schema<typeof mySchema>>, typeof mySchema>) => Results<Schema<typeof mySchema>>,
6565
persist?: () => Promise<any>,
6666
}>(appWithOrama.orama)
6767

6868
fp(function(fastify) {
6969
const fastifyWithOrama = fastify.withOrama<typeof mySchema>()
7070

7171
expectType<{
72-
insert: (document: PartialSchemaDeep<TypedDocument<Orama<typeof mySchema>>>) => Promise<string>,
73-
search: (params: SearchParams<Orama<Schema<typeof mySchema>>, typeof mySchema>) => Promise<Results<Schema<typeof mySchema>>>,
72+
insert: (document: PartialSchemaDeep<TypedDocument<Orama<typeof mySchema>>>) => string,
73+
search: (params: SearchParams<Orama<Schema<typeof mySchema>>, typeof mySchema>) => Results<Schema<typeof mySchema>>,
7474
persist?: () => Promise<any>,
7575
}>(fastifyWithOrama.orama)
7676
})

0 commit comments

Comments
 (0)