From df569183d1a9ed0a9e0ea5bf8d7dab52d326a33d Mon Sep 17 00:00:00 2001 From: David Luecke Date: Tue, 13 Dec 2022 08:45:54 -0800 Subject: [PATCH] fix(core): Allow services with no external methods (#2921) --- packages/feathers/src/service.ts | 5 ++++- packages/feathers/test/application.test.ts | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/feathers/src/service.ts b/packages/feathers/src/service.ts index febe0a81a4..eb852f39b9 100644 --- a/packages/feathers/src/service.ts +++ b/packages/feathers/src/service.ts @@ -63,7 +63,10 @@ export function wrapService(location: string, service: any, options: ServiceOpti const protoService = Object.create(service) const serviceOptions = normalizeServiceOptions(service, options) - if (Object.keys(serviceOptions.methods).length === 0 && typeof service.setup !== 'function') { + if ( + Object.keys(serviceOptions.methods).length === 0 && + ![...defaultServiceMethods, 'setup', 'teardown'].some((method) => typeof service[method] === 'function') + ) { throw new Error(`Invalid service object passed for path \`${location}\``) } diff --git a/packages/feathers/test/application.test.ts b/packages/feathers/test/application.test.ts index 5160972dfe..0a179c2b8e 100644 --- a/packages/feathers/test/application.test.ts +++ b/packages/feathers/test/application.test.ts @@ -165,6 +165,18 @@ describe('Feathers application', () => { ) }) + it('can register service with no external methods', async () => { + const dummyService = { + async create(data: any) { + return data + } + } + + feathers().use('dummy', dummyService, { + methods: [] + }) + }) + it('can use a root level service', async () => { const app = feathers().use('/', { async get(id: string) {