Closed FossPrime closed 1 year ago
This is somewhat related to my comment in https://github.com/feathersjs/feathers/issues/3209#issuecomment-1605619697 in that making all service method implementations explicit, we can use the now finalised decorators to make it a lot more easily visible in a single file what the flow of your data will be (of course you can use the normal format as well). This is an example that I sent to @marshallswain which I believe shows the same thing you are suggesting in the resolveData
hook:
import { feathers, hooks, service } from '@feathersjs/feathers'
import { authenticate } from '@feathersjs/authentication'
import { Type, Static, validateData } from '@feathersjs/typebox'
import { KnexDatabase } from '@birdhaus/knex'
const messageSchema = Type.Object({
id: Type.Number(),
text: Type.String()
})
type Message = Static<typeof messageSchema>
@hooks([
authenticate('jwt')
])
@service()
class MessageService {
db: KnexDatabase<Message>
constructor () {
this.db = new KnexDatabase<Message>({
Model: app.get('knexClient')
})
}
async find () {
return this.db.find()
}
@hooks([
validateData(messageSchema),
resolveData({
createdAt: async () => Date.now()
})
])
async create(data: Message) {
return this.db.create(data)
}
}
export const app = feathers<{ messages: MessageService }>()
.use('messages', new MessageService())
Sounds like good ideas! Closing in favor of #3209 as it's apparently the first step towards DX improvements in this area.
Summary
It would standardize things more and clean up boilerplate and ease learning if we had Resolvers in the hooks DSL-like format. This is now possible as of TypeScript 4.4.
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-4.html#symbol-and-template-string-pattern-index-signatures
Proposed format
Current format
Additional notes
createDataResultSchema: [createDataSchema, { 'properties.createdAt.type': 'string' }],