Closed daffl closed 1 year ago
Name | Link |
---|---|
Latest commit | 4943803224fbd85df4b3838b4391532b48a8c79f |
Latest deploy log | https://app.netlify.com/sites/feathers-dove/deploys/63d6b30d4fd4ea0008529189 |
I definitely prefer to group the types and variables, like this:
// For more information about this file see https://dove.feathersjs.com/guides/cli/service.shared.html
import type { Params } from '@feathersjs/feathers'
import type { ClientApplication } from '../../client'
import type { Message, MessageData, MessagePatch, MessageQuery, MessageService } from './messages.class'
export type { Message, MessageData, MessagePatch, MessageQuery }
export type MessageClientService = Pick<MessageService<Params<MessageQuery>>, (typeof messageMethods)[number]>
export const messagePath = 'messages'
export const messageMethods = ['find', 'get', 'create', 'patch', 'remove'] as const
export const messageClient = (client: ClientApplication) => {
const connection = client.get('connection')
client.use(messagePath, connection.service(messagePath), {
methods: messageMethods
})
}
// Add this service to the client service type index
declare module '../../client' {
interface ServiceTypes {
[messagePath]: MessageClientService
}
}
Also, it's worth noting that the JS version will look like this:
export const messagePath = 'messages'
export const messageMethods = ['find', 'get', 'create', 'patch', 'remove']
export const messageClient = (client) => {
const connection = client.get('connection')
client.use(messagePath, connection.service(messagePath), {
methods: messageMethods
})
}
Filenames we talked about:
service.shared.ts
service.client.ts
service.common.ts
After reviewing it further, I think service.shared.ts
makes the most sense.
This pull request adds a
<service>.shared
file to a generated application which contains information that is shared between the client and the server:<service>Path
which contains the actual service path. This allows to change the path in a single place (as noted in #2951)<service>Methods
which contains a list of externally available methods. This allows to easily add or remove an external service method without having to update it in multiple placesA shared service file looks like this:
This file can also be used to e.g. define common helpers and schemas that can be used on both sides to e.g. do client side validation.
Closes https://github.com/feathersjs/feathers/issues/2951