Skip to content

Commit

Permalink
fix(core): Allow services with no external methods (#2921)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Dec 13, 2022
1 parent d9449fa commit df56918
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/feathers/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}\``)
}

Expand Down
12 changes: 12 additions & 0 deletions packages/feathers/test/application.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit df56918

Please # to comment.