Added type definitions for hook-less service methods.#1288
Added type definitions for hook-less service methods.#1288deskoh wants to merge 3 commits intofeathersjs:masterfrom deskoh:master
Conversation
|
Thank you! I think it makes sense to add them. Can we put them into a separate interface though since it's only implemented by the service adapters? |
|
I think this needs to go into adapter-commons instead. For example, the following code won't work because it just uses an object based service instead of using adapter-commons. const feathers = require('@feathersjs/feathers')
const app = feathers()
const items = []
app.use('items', {
async create (data) {
data.id = items.length
items.push(data)
return data
},
})
const itemsService = app.service('items')
itemsService.hooks({
before: {
create: [
() => { console.log('Before hook') },
],
},
})
async function run () {
await itemsService.create({text: 'Hello, World!'})
await itemsService._create({text: 'No hooks'})
// throws TypeError: itemsService._create is not a function
}
run()If we put it into adapter-commons, then we might be able to use namespace merging, type intersection, module augmentation or some combination to ensure the type definition works properly. |
|
@jordanbtucker Existing type definitions have similar problems for object-based service. For example, referencing the code above, the snippet below also exhibits similar problems: async function run () {
await itemsService.create({text: 'Hello, World!'})
await await itemsService.get(1);
// throws TypeError: itemsService.get is not a function even though there is no type error using current type definitions.
}The type resolution need to be able to distinguish object-based service and service using the Database Common API. Not sure how to achieve this at this point. |
Related to #1269 to support Calling the hook-less service methods of the database adapters.
Hook-less service methods is also useful for in unit tests for creating / updating multiple items if
multiflag is not set as the hook-less methods does not check formultiflag,