11// import { _ } from "@feathersjs/commons";
2- import { AdapterBase , filterQuery } from '@feathersjs/adapter-commons' ;
3- import { Client } from '@elastic/elasticsearch' ;
2+ import { AdapterBase , filterQuery } from '@feathersjs/adapter-commons'
3+ import { Client } from '@elastic/elasticsearch'
44import {
55 ElasticsearchServiceOptions ,
66 ElasticsearchServiceParams ,
77 ElasticAdapterInterface ,
88 SecurityConfig
9- } from './types' ;
10- import { errorHandler } from './error-handler' ;
11- import { DEFAULT_SECURITY_CONFIG } from './utils/security' ;
9+ } from './types'
10+ import { errorHandler } from './error-handler'
11+ import { DEFAULT_SECURITY_CONFIG } from './utils/security'
1212// const errors = require('@feathersjs/errors');
1313// const debug = makeDebug('feathers-elasticsearch');
1414
15- import * as methods from './methods/index' ;
15+ import * as methods from './methods/index'
1616
1717/**
1818 * Elasticsearch adapter for FeathersJS
@@ -22,16 +22,16 @@ import * as methods from './methods/index';
2222 * @extends {AdapterBase }
2323 */
2424export class ElasticAdapter extends AdapterBase implements ElasticAdapterInterface {
25- Model ! : Client ;
26- index ! : string ;
27- parent ?: string ;
28- routing ?: string ;
29- join ?: string ;
30- meta ! : string ;
31- esVersion ?: string ;
32- esParams ?: Record < string , unknown > ;
33- security ! : Required < SecurityConfig > ;
34- core : Record < string , unknown > ;
25+ Model ! : Client
26+ index ! : string
27+ parent ?: string
28+ routing ?: string
29+ join ?: string
30+ meta ! : string
31+ esVersion ?: string
32+ esParams ?: Record < string , unknown >
33+ security ! : Required < SecurityConfig >
34+ core : Record < string , unknown >
3535
3636 /**
3737 * Creates an instance of ElasticAdapter
@@ -40,16 +40,16 @@ export class ElasticAdapter extends AdapterBase implements ElasticAdapterInterfa
4040 */
4141 constructor ( options : ElasticsearchServiceOptions ) {
4242 if ( typeof options !== 'object' ) {
43- throw new Error ( 'Elasticsearch options have to be provided' ) ;
43+ throw new Error ( 'Elasticsearch options have to be provided' )
4444 }
4545
4646 if ( ! options || ! options . Model ) {
47- throw new Error ( 'Elasticsearch `Model` (client) needs to be provided' ) ;
47+ throw new Error ( 'Elasticsearch `Model` (client) needs to be provided' )
4848 }
4949
50- const index = options . index || options . elasticsearch ?. index ;
50+ const index = options . index || options . elasticsearch ?. index
5151 if ( ! index ) {
52- throw new Error ( 'Elasticsearch `index` needs to be provided' ) ;
52+ throw new Error ( 'Elasticsearch `index` needs to be provided' )
5353 }
5454
5555 super ( {
@@ -114,28 +114,28 @@ export class ElasticAdapter extends AdapterBase implements ElasticAdapterInterfa
114114 ; [ 'Model' , 'index' , 'parent' , 'meta' , 'join' , 'esVersion' , 'esParams' ] . forEach ( ( name ) =>
115115 Object . defineProperty ( this , name , {
116116 get ( ) {
117- return this . options [ name ] ;
117+ return this . options [ name ]
118118 }
119119 } )
120- ) ;
120+ )
121121
122122 // Initialize security configuration with defaults
123123 this . security = {
124124 ...DEFAULT_SECURITY_CONFIG ,
125125 ...options . security
126- } ;
126+ }
127127
128128 // BREAKING CHANGE: Disable $index filter by default for security
129129 // Users must explicitly enable it via security.allowedIndices
130130 if ( this . security . allowedIndices . length === 0 && this . options . filters ?. $index ) {
131- delete this . options . filters . $index ;
131+ delete this . options . filters . $index
132132 }
133133
134134 // Set up core methods reference
135135 this . core = {
136136 find : methods . find ,
137137 get : methods . get
138- } ;
138+ }
139139 }
140140
141141 /**
@@ -144,20 +144,20 @@ export class ElasticAdapter extends AdapterBase implements ElasticAdapterInterfa
144144 * @returns {Object } Filtered query parameters with pagination settings
145145 */
146146 filterQuery ( params : ElasticsearchServiceParams = { } ) {
147- const options = this . getOptions ( params ) ;
148- const { filters, query } = filterQuery ( params ?. query || { } , options ) ;
147+ const options = this . getOptions ( params )
148+ const { filters, query } = filterQuery ( params ?. query || { } , options )
149149
150150 if ( ! filters . $skip || isNaN ( filters . $skip as number ) ) {
151- filters . $skip = 0 ;
151+ filters . $skip = 0
152152 }
153153
154154 if ( typeof filters . $sort === 'object' ) {
155155 filters . $sort = Object . entries ( filters . $sort ) . map ( ( [ key , val ] ) => ( {
156156 [ key ] : ( val as number ) > 0 ? 'asc' : 'desc'
157- } ) ) ;
157+ } ) )
158158 }
159159
160- return { filters, query, paginate : options . paginate } ;
160+ return { filters, query, paginate : options . paginate }
161161 }
162162
163163 /**
@@ -173,11 +173,11 @@ export class ElasticAdapter extends AdapterBase implements ElasticAdapterInterfa
173173 | { total : number ; skip : number ; limit : number ; data : Record < string , unknown > [ ] }
174174 > {
175175 return methods . find ( this , params ) . catch ( ( error : Error ) => {
176- throw errorHandler ( error , undefined ) ;
176+ throw errorHandler ( error , undefined )
177177 } ) as Promise <
178178 | Record < string , unknown > [ ]
179179 | { total : number ; skip : number ; limit : number ; data : Record < string , unknown > [ ] }
180- > ;
180+ >
181181 }
182182
183183 /**
@@ -189,8 +189,8 @@ export class ElasticAdapter extends AdapterBase implements ElasticAdapterInterfa
189189 */
190190 _get ( id : string | number , params : ElasticsearchServiceParams = { } ) : Promise < Record < string , unknown > > {
191191 return ( methods . get ( this , id , params ) as Promise < Record < string , unknown > > ) . catch ( ( error : Error ) => {
192- throw errorHandler ( error , id ) ;
193- } ) ;
192+ throw errorHandler ( error , id )
193+ } )
194194 }
195195
196196 /**
@@ -208,13 +208,13 @@ export class ElasticAdapter extends AdapterBase implements ElasticAdapterInterfa
208208 // Check if we are creating single item.
209209 if ( ! Array . isArray ( data ) ) {
210210 return methods . create ( this , data , params ) . catch ( ( error : Error ) => {
211- throw errorHandler ( error , ( data as Record < string , unknown > ) [ this . id ] as string | number ) ;
212- } ) as Promise < Record < string , unknown > > ;
211+ throw errorHandler ( error , ( data as Record < string , unknown > ) [ this . id ] as string | number )
212+ } ) as Promise < Record < string , unknown > >
213213 }
214214
215215 return methods . createBulk ( this , data , params ) . catch ( ( error : Error ) => {
216- throw errorHandler ( error ) ;
217- } ) as Promise < Record < string , unknown > [ ] > ;
216+ throw errorHandler ( error )
217+ } ) as Promise < Record < string , unknown > [ ] >
218218 }
219219
220220 /**
@@ -227,8 +227,8 @@ export class ElasticAdapter extends AdapterBase implements ElasticAdapterInterfa
227227 */
228228 _update ( id : string | number , data : Record < string , unknown > , params : ElasticsearchServiceParams = { } ) {
229229 return methods . update ( this , id , data , params ) . catch ( ( error : Error ) => {
230- throw errorHandler ( error , id ) ;
231- } ) ;
230+ throw errorHandler ( error , id )
231+ } )
232232 }
233233
234234 /**
@@ -247,13 +247,13 @@ export class ElasticAdapter extends AdapterBase implements ElasticAdapterInterfa
247247 // Check if we are patching single item.
248248 if ( id !== null ) {
249249 return methods . patch ( this , id , data , params ) . catch ( ( error : Error ) => {
250- throw errorHandler ( error , id ) ;
251- } ) as Promise < Record < string , unknown > > ;
250+ throw errorHandler ( error , id )
251+ } ) as Promise < Record < string , unknown > >
252252 }
253253
254254 return methods . patchBulk ( this , data , params ) . catch ( ( error : Error ) => {
255- throw errorHandler ( error ) ;
256- } ) as Promise < Record < string , unknown > [ ] > ;
255+ throw errorHandler ( error )
256+ } ) as Promise < Record < string , unknown > [ ] >
257257 }
258258
259259 /**
@@ -266,13 +266,13 @@ export class ElasticAdapter extends AdapterBase implements ElasticAdapterInterfa
266266 _remove ( id : string | number | null , params : ElasticsearchServiceParams = { } ) {
267267 if ( id !== null ) {
268268 return methods . remove ( this , id , params ) . catch ( ( error : Error ) => {
269- throw errorHandler ( error , id ) ;
270- } ) ;
269+ throw errorHandler ( error , id )
270+ } )
271271 }
272272
273273 return methods . removeBulk ( this , params ) . catch ( ( error : Error ) => {
274- throw errorHandler ( error ) ;
275- } ) ;
274+ throw errorHandler ( error )
275+ } )
276276 }
277277
278278 /**
@@ -283,7 +283,7 @@ export class ElasticAdapter extends AdapterBase implements ElasticAdapterInterfa
283283 */
284284 _raw ( method : string , params : ElasticsearchServiceParams = { } ) {
285285 return methods . raw ( this , method , params ) . catch ( ( error : Error ) => {
286- throw errorHandler ( error ) ;
287- } ) ;
286+ throw errorHandler ( error )
287+ } )
288288 }
289289}
0 commit comments