Skip to content

Commit af99068

Browse files
authored
fix: fix plugin api (#141)
1 parent 30597dd commit af99068

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ const path = require('path')
66
const { existsSync } = require('fs')
77
const { restoreFromFile, persistToFile } = require('@orama/plugin-data-persistence')
88

9-
async function FastifyOrama (fastify, options, next) {
9+
async function FastifyOrama (fastify, options) {
1010
const { schema, defaultLanguage = 'english', stemming = true, persistence = false } = options
1111

1212
if (fastify.orama) {
13-
return next(new Error('fastify-orama is already registered'))
13+
throw new Error('fastify-orama is already registered')
1414
}
1515

1616
let db
@@ -23,12 +23,12 @@ async function FastifyOrama (fastify, options, next) {
2323
const datbaseExists = existsSync(path.resolve(dbName))
2424

2525
if (!datbaseExists) {
26-
return next(new Error(`The database file ${dbName} does not exist`))
26+
throw new Error(`The database file ${dbName} does not exist`)
2727
}
2828

2929
db = await restoreFromFile(dbFormat, `./${dbName}`)
3030
} else {
31-
if (!schema) return next(new Error('You must provide a schema to create a new database'))
31+
if (!schema) { throw new Error('You must provide a schema to create a new database') }
3232

3333
db = await create({
3434
schema,
@@ -37,13 +37,11 @@ async function FastifyOrama (fastify, options, next) {
3737
})
3838
}
3939

40-
await fastify.decorate('orama', {
40+
fastify.decorate('orama', {
4141
insert: (...args) => insert(db, ...args),
4242
search: (...args) => search(db, ...args),
4343
save: () => persistToFile(db, dbFormat, dbName)
4444
})
45-
46-
next()
4745
}
4846

4947
module.exports = fp(FastifyOrama, {

0 commit comments

Comments
 (0)