@@ -6,11 +6,11 @@ const path = require('path')
6
6
const { existsSync } = require ( 'fs' )
7
7
const { restoreFromFile, persistToFile } = require ( '@orama/plugin-data-persistence' )
8
8
9
- async function FastifyOrama ( fastify , options , next ) {
9
+ async function FastifyOrama ( fastify , options ) {
10
10
const { schema, defaultLanguage = 'english' , stemming = true , persistence = false } = options
11
11
12
12
if ( fastify . orama ) {
13
- return next ( new Error ( 'fastify-orama is already registered' ) )
13
+ throw new Error ( 'fastify-orama is already registered' )
14
14
}
15
15
16
16
let db
@@ -23,12 +23,12 @@ async function FastifyOrama (fastify, options, next) {
23
23
const datbaseExists = existsSync ( path . resolve ( dbName ) )
24
24
25
25
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` )
27
27
}
28
28
29
29
db = await restoreFromFile ( dbFormat , `./${ dbName } ` )
30
30
} 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' ) }
32
32
33
33
db = await create ( {
34
34
schema,
@@ -37,13 +37,11 @@ async function FastifyOrama (fastify, options, next) {
37
37
} )
38
38
}
39
39
40
- await fastify . decorate ( 'orama' , {
40
+ fastify . decorate ( 'orama' , {
41
41
insert : ( ...args ) => insert ( db , ...args ) ,
42
42
search : ( ...args ) => search ( db , ...args ) ,
43
43
save : ( ) => persistToFile ( db , dbFormat , dbName )
44
44
} )
45
-
46
- next ( )
47
45
}
48
46
49
47
module . exports = fp ( FastifyOrama , {
0 commit comments