Skip to content

Commit

Permalink
feat(cli): Adding ClientService to CLI (#2750)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Sep 15, 2022
1 parent c7bf80d commit 1d45427
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/cli/src/app/templates/client.tpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AppGeneratorContext } from '../index'

const template = ({}: AppGeneratorContext) =>
`import { feathers } from '@feathersjs/feathers'
import type { Service, TransportConnection, Params } from '@feathersjs/feathers'
import type { Paginated, ClientService, TransportConnection, Params } from '@feathersjs/feathers'
export interface ServiceTypes {
// A mapping of client side services
Expand Down
3 changes: 1 addition & 2 deletions packages/cli/src/app/templates/tsconfig.json.tpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export const generate = (ctx: AppGeneratorContext) =>
rootDir: `./${lib}`,
declaration: true,
strict: true,
esModuleInterop: true,
skipLibCheck: true
esModuleInterop: true
},
include: [lib],
exclude: ['test']
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/authentication/templates/knex.tpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ export async function down(knex: Knex): Promise<void> {
table.dropColumn('email')
table.dropColumn('password')`
: `
table.dropColumn('${name}Id')`
table.dropColumn('${name}Id')
`
)
.join(',\n')}
.join('\n')}
})
}
`
Expand Down
16 changes: 14 additions & 2 deletions packages/cli/src/service/templates/client.tpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,26 @@ import { ServiceGeneratorContext } from '../index'

const schemaImports = ({ upperName, folder, fileName }: ServiceGeneratorContext) => `import type {
${upperName}Data,
${upperName}Patch,
${upperName}Result,
${upperName}Query,
} from './services/${folder.join('/')}/${fileName}.schema'
export * from './services/${folder.join('/')}/${fileName}.schema'`
export type {
${upperName}Data,
${upperName}Patch,
${upperName}Result,
${upperName}Query,
}`

const declarationTemplate = ({ path, upperName }: ServiceGeneratorContext) =>
` '${path}': Service<${upperName}Result, ${upperName}Data, Params<${upperName}Query>>`
` '${path}': ClientService<
${upperName}Result,
${upperName}Data,
${upperName}Patch,
Paginated<${upperName}Result>,
Params<${upperName}Query>
>`

const toClientFile = toFile<ServiceGeneratorContext>(({ lib }) => [lib, 'client.ts'])

Expand Down
27 changes: 27 additions & 0 deletions packages/feathers/src/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,33 @@ export interface ServiceOptions {
routeParams?: { [key: string]: any }
}

export interface ClientService<
Result = any,
Data = Partial<Result>,
PatchData = Data,
FindResult = Paginated<Result>,
P = Params
> {
find(params?: P): Promise<FindResult>

get(id: Id, params?: P): Promise<Result>

create(data: Data[], params?: P): Promise<Result[]>
create(data: Data, params?: P): Promise<Result>

update(id: Id, data: Data, params?: P): Promise<Result>
update(id: NullableId, data: Data, params?: P): Promise<Result | Result[]>
update(id: null, data: Data, params?: P): Promise<Result[]>

patch(id: NullableId, data: PatchData, params?: P): Promise<Result | Result[]>
patch(id: Id, data: PatchData, params?: P): Promise<Result>
patch(id: null, data: PatchData, params?: P): Promise<Result[]>

remove(id: NullableId, params?: P): Promise<Result | Result[]>
remove(id: Id, params?: P): Promise<Result>
remove(id: null, params?: P): Promise<Result[]>
}

export interface ServiceMethods<T = any, D = Partial<T>, P = Params> {
find(params?: P): Promise<T | T[]>

Expand Down

0 comments on commit 1d45427

Please sign in to comment.