@feathersjs/transport-commons 5.0.0-pre.21 → 5.0.0-pre.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/http.ts CHANGED
@@ -1,12 +1,12 @@
1
- import { MethodNotAllowed } from '@feathersjs/errors/lib';
2
- import { HookContext, NullableId, Params } from '@feathersjs/feathers';
3
- import encodeUrl from 'encodeurl';
1
+ import { MethodNotAllowed } from '@feathersjs/errors/lib'
2
+ import { HookContext, NullableId, Params } from '@feathersjs/feathers'
3
+ import encodeUrl from 'encodeurl'
4
4
 
5
- export const METHOD_HEADER = 'x-service-method';
5
+ export const METHOD_HEADER = 'x-service-method'
6
6
 
7
7
  export interface ServiceParams {
8
- id: NullableId,
9
- data: any,
8
+ id: NullableId
9
+ data: any
10
10
  params: Params
11
11
  }
12
12
 
@@ -16,80 +16,80 @@ export const statusCodes = {
16
16
  methodNotAllowed: 405,
17
17
  success: 200,
18
18
  seeOther: 303
19
- };
19
+ }
20
20
 
21
21
  export const knownMethods: { [key: string]: string } = {
22
22
  post: 'create',
23
23
  patch: 'patch',
24
24
  put: 'update',
25
25
  delete: 'remove'
26
- };
26
+ }
27
27
 
28
- export function getServiceMethod (_httpMethod: string, id: unknown, headerOverride?: string) {
29
- const httpMethod = _httpMethod.toLowerCase();
28
+ export function getServiceMethod(_httpMethod: string, id: unknown, headerOverride?: string) {
29
+ const httpMethod = _httpMethod.toLowerCase()
30
30
 
31
31
  if (httpMethod === 'post' && headerOverride) {
32
- return headerOverride;
32
+ return headerOverride
33
33
  }
34
34
 
35
- const mappedMethod = knownMethods[httpMethod];
35
+ const mappedMethod = knownMethods[httpMethod]
36
36
 
37
37
  if (mappedMethod) {
38
- return mappedMethod;
38
+ return mappedMethod
39
39
  }
40
40
 
41
41
  if (httpMethod === 'get') {
42
- return id === null ? 'find' : 'get';
42
+ return id === null ? 'find' : 'get'
43
43
  }
44
44
 
45
- throw new MethodNotAllowed(`Method ${_httpMethod} not allowed`);
45
+ throw new MethodNotAllowed(`Method ${_httpMethod} not allowed`)
46
46
  }
47
47
 
48
48
  export const argumentsFor = {
49
- get: ({ id, params }: ServiceParams) => [ id, params ],
50
- find: ({ params }: ServiceParams) => [ params ],
51
- create: ({ data, params }: ServiceParams) => [ data, params ],
52
- update: ({ id, data, params }: ServiceParams) => [ id, data, params ],
53
- patch: ({ id, data, params }: ServiceParams) => [ id, data, params ],
54
- remove: ({ id, params }: ServiceParams) => [ id, params ],
55
- default: ({ data, params }: ServiceParams) => [ data, params ]
49
+ get: ({ id, params }: ServiceParams) => [id, params],
50
+ find: ({ params }: ServiceParams) => [params],
51
+ create: ({ data, params }: ServiceParams) => [data, params],
52
+ update: ({ id, data, params }: ServiceParams) => [id, data, params],
53
+ patch: ({ id, data, params }: ServiceParams) => [id, data, params],
54
+ remove: ({ id, params }: ServiceParams) => [id, params],
55
+ default: ({ data, params }: ServiceParams) => [data, params]
56
56
  }
57
57
 
58
- export function getStatusCode (context: HookContext, body: any, location: string|string[]) {
59
- const { http = {} } = context;
58
+ export function getStatusCode(context: HookContext, body: any, location: string | string[]) {
59
+ const { http = {} } = context
60
60
 
61
61
  if (http.status) {
62
- return http.status;
62
+ return http.status
63
63
  }
64
64
 
65
65
  if (context.method === 'create') {
66
- return statusCodes.created;
66
+ return statusCodes.created
67
67
  }
68
68
 
69
69
  if (location !== undefined) {
70
- return statusCodes.seeOther;
70
+ return statusCodes.seeOther
71
71
  }
72
72
 
73
73
  if (!body) {
74
- return statusCodes.noContent;
74
+ return statusCodes.noContent
75
75
  }
76
76
 
77
- return statusCodes.success;
77
+ return statusCodes.success
78
78
  }
79
79
 
80
- export function getResponse (context: HookContext) {
81
- const { http = {} } = context;
82
- const body = context.dispatch !== undefined ? context.dispatch : context.result;
80
+ export function getResponse(context: HookContext) {
81
+ const { http = {} } = context
82
+ const body = context.dispatch !== undefined ? context.dispatch : context.result
83
83
 
84
- let headers = http.headers || {};
85
- let location = headers.Location;
84
+ let headers = http.headers || {}
85
+ let location = headers.Location
86
86
 
87
87
  if (http.location !== undefined) {
88
- location = encodeUrl(http.location);
89
- headers = { ...headers, Location: location };
88
+ location = encodeUrl(http.location)
89
+ headers = { ...headers, Location: location }
90
90
  }
91
91
 
92
- const status = getStatusCode(context, body, location);
92
+ const status = getStatusCode(context, body, location)
93
93
 
94
- return { status, headers, body };
94
+ return { status, headers, body }
95
95
  }
package/src/index.ts CHANGED
@@ -1,13 +1,6 @@
1
- import { socket } from './socket';
2
- import { routing } from './routing';
3
- import { channels, Channel, CombinedChannel, RealTimeConnection } from './channels';
1
+ import { socket } from './socket'
2
+ import { routing } from './routing'
3
+ import { channels, Channel, CombinedChannel, RealTimeConnection } from './channels'
4
4
 
5
- export * as http from './http';
6
- export {
7
- socket,
8
- routing,
9
- channels,
10
- Channel,
11
- CombinedChannel,
12
- RealTimeConnection
13
- };
5
+ export * as http from './http'
6
+ export { socket, routing, channels, Channel, CombinedChannel, RealTimeConnection }
@@ -1,50 +1,54 @@
1
- import { Application, Service, ServiceOptions } from '@feathersjs/feathers';
2
- import { Router } from './router';
1
+ import { Application, Service, ServiceOptions } from '@feathersjs/feathers'
2
+ import { Router } from './router'
3
3
 
4
4
  declare module '@feathersjs/feathers/lib/declarations' {
5
5
  interface RouteLookup {
6
- service: Service,
6
+ service: Service
7
7
  params: { [key: string]: any }
8
8
  }
9
9
 
10
- interface Application<Services, Settings> { // eslint-disable-line
10
+ interface Application<Services, Settings> {
11
+ // eslint-disable-line
11
12
  routes: Router<{
12
- service: Service,
13
+ service: Service
13
14
  params?: { [key: string]: any }
14
- }>;
15
- lookup (path: string): RouteLookup;
15
+ }>
16
+ lookup(path: string): RouteLookup
16
17
  }
17
18
  }
18
19
 
19
- export * from './router';
20
+ export * from './router'
20
21
 
21
22
  const lookup = function (this: Application, path: string) {
22
- const result = this.routes.lookup(path);
23
+ const result = this.routes.lookup(path)
23
24
 
24
25
  if (result === null) {
25
- return null;
26
+ return null
26
27
  }
27
28
 
28
- const { params: colonParams, data: { service, params: dataParams } } = result;
29
+ const {
30
+ params: colonParams,
31
+ data: { service, params: dataParams }
32
+ } = result
29
33
 
30
- const params = dataParams ? { ...dataParams, ...colonParams } : colonParams;
34
+ const params = dataParams ? { ...dataParams, ...colonParams } : colonParams
31
35
 
32
- return { service, params };
33
- };
36
+ return { service, params }
37
+ }
34
38
 
35
39
  export const routing = () => (app: Application) => {
36
40
  if (typeof app.lookup === 'function') {
37
- return;
41
+ return
38
42
  }
39
43
 
40
- app.routes = new Router();
41
- app.lookup = lookup;
44
+ app.routes = new Router()
45
+ app.lookup = lookup
42
46
 
43
47
  // Add a mixin that registers a service on the router
44
48
  app.mixins.push((service: Service, path: string, options: ServiceOptions) => {
45
- const { routeParams: params = {} } = options;
49
+ const { routeParams: params = {} } = options
46
50
 
47
- app.routes.insert(path, { service, params });
48
- app.routes.insert(`${path}/:__id`, { service, params });
49
- });
50
- };
51
+ app.routes.insert(path, { service, params })
52
+ app.routes.insert(`${path}/:__id`, { service, params })
53
+ })
54
+ }
@@ -1,98 +1,100 @@
1
- import { stripSlashes } from '@feathersjs/commons';
1
+ import { stripSlashes } from '@feathersjs/commons'
2
2
 
3
3
  export interface LookupData {
4
- params: { [key: string]: string };
4
+ params: { [key: string]: string }
5
5
  }
6
6
 
7
7
  export interface LookupResult<T> extends LookupData {
8
- data?: T;
8
+ data?: T
9
9
  }
10
10
 
11
11
  export class RouteNode<T = any> {
12
- data?: T;
13
- children: { [key: string]: RouteNode } = {};
14
- placeholders: RouteNode[] = [];
12
+ data?: T
13
+ children: { [key: string]: RouteNode } = {}
14
+ placeholders: RouteNode[] = []
15
15
 
16
- constructor (public name: string, public depth: number) {}
16
+ constructor(public name: string, public depth: number) {}
17
17
 
18
- insert (path: string[], data: T): RouteNode<T> {
18
+ insert(path: string[], data: T): RouteNode<T> {
19
19
  if (this.depth === path.length) {
20
20
  if (this.data !== undefined) {
21
- throw new Error(`Path ${path.join('/')} already exists`);
21
+ throw new Error(`Path ${path.join('/')} already exists`)
22
22
  }
23
23
 
24
- this.data = data;
25
- return this;
24
+ this.data = data
25
+ return this
26
26
  }
27
27
 
28
- const current = path[this.depth];
29
- const nextDepth = this.depth + 1;
28
+ const current = path[this.depth]
29
+ const nextDepth = this.depth + 1
30
30
 
31
31
  if (current.startsWith(':')) {
32
32
  // Insert a placeholder node like /messages/:id
33
- const placeholderName = current.substring(1);
34
- let placeholder = this.placeholders.find(p => p.name === placeholderName);
33
+ const placeholderName = current.substring(1)
34
+ let placeholder = this.placeholders.find((p) => p.name === placeholderName)
35
35
 
36
36
  if (!placeholder) {
37
- placeholder = new RouteNode(placeholderName, nextDepth);
38
- this.placeholders.push(placeholder);
37
+ placeholder = new RouteNode(placeholderName, nextDepth)
38
+ this.placeholders.push(placeholder)
39
39
  }
40
40
 
41
- return placeholder.insert(path, data);
41
+ return placeholder.insert(path, data)
42
42
  }
43
43
 
44
- const child = this.children[current] || new RouteNode(current, nextDepth);
44
+ const child = this.children[current] || new RouteNode(current, nextDepth)
45
45
 
46
- this.children[current] = child;
46
+ this.children[current] = child
47
47
 
48
- return child.insert(path, data);
48
+ return child.insert(path, data)
49
49
  }
50
50
 
51
- lookup (path: string[], info: LookupData): LookupResult<T>|null {
51
+ lookup(path: string[], info: LookupData): LookupResult<T> | null {
52
52
  if (path.length === this.depth) {
53
- return this.data === undefined ? null : {
54
- ...info,
55
- data: this.data
56
- }
53
+ return this.data === undefined
54
+ ? null
55
+ : {
56
+ ...info,
57
+ data: this.data
58
+ }
57
59
  }
58
60
 
59
- const current = path[this.depth];
60
- const child = this.children[current];
61
+ const current = path[this.depth]
62
+ const child = this.children[current]
61
63
 
62
64
  if (child) {
63
- return child.lookup(path, info);
65
+ return child.lookup(path, info)
64
66
  }
65
67
 
66
68
  // This will return the first placeholder that matches early
67
- for(const placeholder of this.placeholders) {
68
- const result = placeholder.lookup(path, info);
69
+ for (const placeholder of this.placeholders) {
70
+ const result = placeholder.lookup(path, info)
69
71
 
70
72
  if (result !== null) {
71
- result.params[placeholder.name] = current;
72
- return result;
73
+ result.params[placeholder.name] = current
74
+ return result
73
75
  }
74
76
  }
75
77
 
76
- return null;
78
+ return null
77
79
  }
78
80
  }
79
81
 
80
82
  export class Router<T = any> {
81
- constructor (public root: RouteNode<T> = new RouteNode<T>('', 0)) {}
83
+ constructor(public root: RouteNode<T> = new RouteNode<T>('', 0)) {}
82
84
 
83
- getPath (path: string) {
84
- return stripSlashes(path).split('/');
85
+ getPath(path: string) {
86
+ return stripSlashes(path).split('/')
85
87
  }
86
88
 
87
- insert (path: string, data: T) {
88
- return this.root.insert(this.getPath(path), data);
89
+ insert(path: string, data: T) {
90
+ return this.root.insert(this.getPath(path), data)
89
91
  }
90
92
 
91
- lookup (path: string) {
93
+ lookup(path: string) {
92
94
  if (typeof path !== 'string') {
93
- return null;
95
+ return null
94
96
  }
95
97
 
96
- return this.root.lookup(this.getPath(path), { params: {} });
98
+ return this.root.lookup(this.getPath(path), { params: {} })
97
99
  }
98
100
  }
@@ -1,70 +1,70 @@
1
- import { Application, getServiceOptions, Params } from '@feathersjs/feathers';
2
- import { createDebug } from '@feathersjs/commons';
3
- import { channels } from '../channels';
4
- import { routing } from '../routing';
5
- import { getDispatcher, runMethod } from './utils';
6
- import { RealTimeConnection } from '../channels/channel/base';
1
+ import { Application, getServiceOptions, Params } from '@feathersjs/feathers'
2
+ import { createDebug } from '@feathersjs/commons'
3
+ import { channels } from '../channels'
4
+ import { routing } from '../routing'
5
+ import { getDispatcher, runMethod } from './utils'
6
+ import { RealTimeConnection } from '../channels/channel/base'
7
7
 
8
- const debug = createDebug('@feathersjs/transport-commons');
8
+ const debug = createDebug('@feathersjs/transport-commons')
9
9
 
10
10
  export interface SocketOptions {
11
- done: Promise<any>;
12
- emit: string;
13
- socketMap: WeakMap<RealTimeConnection, any>;
14
- socketKey?: any;
15
- getParams: (socket: any) => RealTimeConnection;
11
+ done: Promise<any>
12
+ emit: string
13
+ socketMap: WeakMap<RealTimeConnection, any>
14
+ socketKey?: any
15
+ getParams: (socket: any) => RealTimeConnection
16
16
  }
17
17
 
18
- export function socket ({ done, emit, socketMap, socketKey, getParams }: SocketOptions) {
18
+ export function socket({ done, emit, socketMap, socketKey, getParams }: SocketOptions) {
19
19
  return (app: Application) => {
20
20
  const leaveChannels = (connection: RealTimeConnection) => {
21
- const { channels } = app;
21
+ const { channels } = app
22
22
 
23
23
  if (channels.length) {
24
- app.channel(app.channels).leave(connection);
24
+ app.channel(app.channels).leave(connection)
25
25
  }
26
- };
26
+ }
27
27
 
28
- app.configure(channels());
29
- app.configure(routing());
28
+ app.configure(channels())
29
+ app.configure(routing())
30
30
 
31
- app.on('publish', getDispatcher(emit, socketMap, socketKey));
32
- app.on('disconnect', leaveChannels);
31
+ app.on('publish', getDispatcher(emit, socketMap, socketKey))
32
+ app.on('disconnect', leaveChannels)
33
33
  app.on('logout', (_authResult: any, params: Params) => {
34
- const { connection } = params;
34
+ const { connection } = params
35
35
 
36
36
  if (connection) {
37
- leaveChannels(connection);
37
+ leaveChannels(connection)
38
38
  }
39
- });
39
+ })
40
40
 
41
41
  // `connection` event
42
- done.then(provider => provider.on('connection', (connection: any) =>
43
- app.emit('connection', getParams(connection)))
44
- );
42
+ done.then((provider) =>
43
+ provider.on('connection', (connection: any) => app.emit('connection', getParams(connection)))
44
+ )
45
45
 
46
46
  // `socket.emit('methodName', 'serviceName', ...args)` handlers
47
- done.then(provider => provider.on('connection', (connection: any) => {
48
- const methodHandlers = Object.keys(app.services).reduce((result, name) => {
49
- const { methods } = getServiceOptions(app.service(name));
47
+ done.then((provider) =>
48
+ provider.on('connection', (connection: any) => {
49
+ const methodHandlers = Object.keys(app.services).reduce((result, name) => {
50
+ const { methods } = getServiceOptions(app.service(name))
50
51
 
51
- methods.forEach(method => {
52
- if (!result[method]) {
53
- result[method] = (...args: any[]) => {
54
- const path = args.shift();
52
+ methods.forEach((method) => {
53
+ if (!result[method]) {
54
+ result[method] = (...args: any[]) => {
55
+ const path = args.shift()
55
56
 
56
- debug(`Got '${method}' call for service '${path}'`);
57
- runMethod(app, getParams(connection), path, method, args);
57
+ debug(`Got '${method}' call for service '${path}'`)
58
+ runMethod(app, getParams(connection), path, method, args)
59
+ }
58
60
  }
59
- }
60
- });
61
+ })
61
62
 
62
- return result;
63
- }, {} as any);
63
+ return result
64
+ }, {} as any)
64
65
 
65
- Object.keys(methodHandlers).forEach(key =>
66
- connection.on(key, methodHandlers[key])
67
- );
68
- }));
69
- };
66
+ Object.keys(methodHandlers).forEach((key) => connection.on(key, methodHandlers[key]))
67
+ })
68
+ )
69
+ }
70
70
  }
@@ -1,114 +1,121 @@
1
- import { HookContext, Application, createContext, getServiceOptions } from '@feathersjs/feathers';
2
- import { NotFound, MethodNotAllowed, BadRequest } from '@feathersjs/errors';
3
- import { createDebug } from '@feathersjs/commons';
4
- import isEqual from 'lodash/isEqual';
5
- import { CombinedChannel } from '../channels/channel/combined';
6
- import { RealTimeConnection } from '../channels/channel/base';
1
+ import { HookContext, Application, createContext, getServiceOptions } from '@feathersjs/feathers'
2
+ import { NotFound, MethodNotAllowed, BadRequest } from '@feathersjs/errors'
3
+ import { createDebug } from '@feathersjs/commons'
4
+ import isEqual from 'lodash/isEqual'
5
+ import { CombinedChannel } from '../channels/channel/combined'
6
+ import { RealTimeConnection } from '../channels/channel/base'
7
7
 
8
- const debug = createDebug('@feathersjs/transport-commons');
8
+ const debug = createDebug('@feathersjs/transport-commons')
9
9
 
10
- export const DEFAULT_PARAMS_POSITION = 1;
10
+ export const DEFAULT_PARAMS_POSITION = 1
11
11
 
12
12
  export const paramsPositions: { [key: string]: number } = {
13
13
  find: 0,
14
14
  update: 2,
15
15
  patch: 2
16
- };
16
+ }
17
17
 
18
- export function normalizeError (e: any) {
19
- const hasToJSON = typeof e.toJSON === 'function';
20
- const result = hasToJSON ? e.toJSON() : {};
18
+ export function normalizeError(e: any) {
19
+ const hasToJSON = typeof e.toJSON === 'function'
20
+ const result = hasToJSON ? e.toJSON() : {}
21
21
 
22
22
  if (!hasToJSON) {
23
- Object.getOwnPropertyNames(e).forEach(key => {
24
- result[key] = e[key];
25
- });
23
+ Object.getOwnPropertyNames(e).forEach((key) => {
24
+ result[key] = e[key]
25
+ })
26
26
  }
27
27
 
28
28
  if (process.env.NODE_ENV === 'production') {
29
- delete result.stack;
29
+ delete result.stack
30
30
  }
31
31
 
32
- delete result.hook;
32
+ delete result.hook
33
33
 
34
- return result;
34
+ return result
35
35
  }
36
36
 
37
- export function getDispatcher (emit: string, socketMap: WeakMap<RealTimeConnection, any>, socketKey?: any) {
37
+ export function getDispatcher(emit: string, socketMap: WeakMap<RealTimeConnection, any>, socketKey?: any) {
38
38
  return function (event: string, channel: CombinedChannel, context: HookContext, data?: any) {
39
- debug(`Dispatching '${event}' to ${channel.length} connections`);
39
+ debug(`Dispatching '${event}' to ${channel.length} connections`)
40
40
 
41
- channel.connections.forEach(connection => {
41
+ channel.connections.forEach((connection) => {
42
42
  // The reference between connection and socket is set in `app.setup`
43
- const socket = socketKey ? connection[socketKey] : socketMap.get(connection);
43
+ const socket = socketKey ? connection[socketKey] : socketMap.get(connection)
44
44
 
45
45
  if (socket) {
46
- const eventName = `${context.path || ''} ${event}`.trim();
46
+ const eventName = `${context.path || ''} ${event}`.trim()
47
47
 
48
- let result = channel.dataFor(connection) || context.dispatch || context.result;
48
+ let result = channel.dataFor(connection) || context.dispatch || context.result
49
49
 
50
50
  // If we are getting events from an array but try to dispatch individual data
51
51
  // try to get the individual item to dispatch from the correct index.
52
52
  if (!Array.isArray(data) && Array.isArray(context.result) && Array.isArray(result)) {
53
- result = context.result.find(resultData => isEqual(resultData, data));
53
+ result = context.result.find((resultData) => isEqual(resultData, data))
54
54
  }
55
55
 
56
- debug(`Dispatching '${eventName}' to Socket ${socket.id} with`, result);
56
+ debug(`Dispatching '${eventName}' to Socket ${socket.id} with`, result)
57
57
 
58
- socket[emit](eventName, result);
58
+ socket[emit](eventName, result)
59
59
  }
60
- });
61
- };
60
+ })
61
+ }
62
62
  }
63
63
 
64
- export async function runMethod (app: Application, connection: RealTimeConnection, path: string, method: string, args: any[]) {
65
- const trace = `method '${method}' on service '${path}'`;
66
- const methodArgs = args.slice(0);
67
- const callback = typeof methodArgs[methodArgs.length - 1] === 'function'
68
- ? methodArgs.pop() : function () {};
69
-
70
- debug(`Running ${trace}`, connection, args);
64
+ export async function runMethod(
65
+ app: Application,
66
+ connection: RealTimeConnection,
67
+ path: string,
68
+ method: string,
69
+ args: any[]
70
+ ) {
71
+ const trace = `method '${method}' on service '${path}'`
72
+ const methodArgs = args.slice(0)
73
+ const callback =
74
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
75
+ typeof methodArgs[methodArgs.length - 1] === 'function' ? methodArgs.pop() : function () {}
76
+
77
+ debug(`Running ${trace}`, connection, args)
71
78
 
72
79
  const handleError = (error: any) => {
73
- debug(`Error in ${trace}`, error);
74
- callback(normalizeError(error));
75
- };
80
+ debug(`Error in ${trace}`, error)
81
+ callback(normalizeError(error))
82
+ }
76
83
 
77
84
  try {
78
- const lookup = app.lookup(path);
85
+ const lookup = app.lookup(path)
79
86
 
80
87
  // No valid service was found throw a NotFound error
81
88
  if (lookup === null) {
82
- throw new NotFound(`Service '${path}' not found`);
89
+ throw new NotFound(`Service '${path}' not found`)
83
90
  }
84
91
 
85
- const { service, params: route = {} } = lookup;
86
- const { methods } = getServiceOptions(service);
92
+ const { service, params: route = {} } = lookup
93
+ const { methods } = getServiceOptions(service)
87
94
 
88
95
  // Only service methods are allowed
89
96
  if (!methods.includes(method)) {
90
- throw new MethodNotAllowed(`Method '${method}' not allowed on service '${path}'`);
97
+ throw new MethodNotAllowed(`Method '${method}' not allowed on service '${path}'`)
91
98
  }
92
99
 
93
- const position = paramsPositions[method] !== undefined ? paramsPositions[method] : DEFAULT_PARAMS_POSITION;
94
- const query = Object.assign({}, methodArgs[position]);
100
+ const position = paramsPositions[method] !== undefined ? paramsPositions[method] : DEFAULT_PARAMS_POSITION
101
+ const query = Object.assign({}, methodArgs[position])
95
102
  // `params` have to be re-mapped to the query and added with the route
96
- const params = Object.assign({ query, route, connection }, connection);
103
+ const params = Object.assign({ query, route, connection }, connection)
97
104
 
98
105
  // `params` is always the last parameter. Error if we got more arguments.
99
- if (methodArgs.length > (position + 1)) {
100
- throw new BadRequest(`Too many arguments for '${method}' method`);
106
+ if (methodArgs.length > position + 1) {
107
+ throw new BadRequest(`Too many arguments for '${method}' method`)
101
108
  }
102
109
 
103
- methodArgs[position] = params;
110
+ methodArgs[position] = params
104
111
 
105
- const ctx = createContext(service, method);
106
- const returnedCtx: HookContext = await (service as any)[method](...methodArgs, ctx);
107
- const result = returnedCtx.dispatch || returnedCtx.result;
112
+ const ctx = createContext(service, method)
113
+ const returnedCtx: HookContext = await (service as any)[method](...methodArgs, ctx)
114
+ const result = returnedCtx.dispatch || returnedCtx.result
108
115
 
109
- debug(`Returned successfully ${trace}`, result);
110
- callback(null, result);
116
+ debug(`Returned successfully ${trace}`, result)
117
+ callback(null, result)
111
118
  } catch (error: any) {
112
- handleError(error);
119
+ handleError(error)
113
120
  }
114
121
  }