Skip to content

Commit 1d45427

Browse files
authored
feat(cli): Adding ClientService to CLI (#2750)
1 parent c7bf80d commit 1d45427

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed

packages/cli/src/app/templates/client.tpl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { AppGeneratorContext } from '../index'
44

55
const template = ({}: AppGeneratorContext) =>
66
`import { feathers } from '@feathersjs/feathers'
7-
import type { Service, TransportConnection, Params } from '@feathersjs/feathers'
7+
import type { Paginated, ClientService, TransportConnection, Params } from '@feathersjs/feathers'
88
99
export interface ServiceTypes {
1010
// A mapping of client side services

packages/cli/src/app/templates/tsconfig.json.tpl.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ export const generate = (ctx: AppGeneratorContext) =>
1717
rootDir: `./${lib}`,
1818
declaration: true,
1919
strict: true,
20-
esModuleInterop: true,
21-
skipLibCheck: true
20+
esModuleInterop: true
2221
},
2322
include: [lib],
2423
exclude: ['test']

packages/cli/src/authentication/templates/knex.tpl.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ export async function down(knex: Knex): Promise<void> {
3131
table.dropColumn('email')
3232
table.dropColumn('password')`
3333
: `
34-
table.dropColumn('${name}Id')`
34+
table.dropColumn('${name}Id')
35+
`
3536
)
36-
.join(',\n')}
37+
.join('\n')}
3738
})
3839
}
3940
`

packages/cli/src/service/templates/client.tpl.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,26 @@ import { ServiceGeneratorContext } from '../index'
33

44
const schemaImports = ({ upperName, folder, fileName }: ServiceGeneratorContext) => `import type {
55
${upperName}Data,
6+
${upperName}Patch,
67
${upperName}Result,
78
${upperName}Query,
89
} from './services/${folder.join('/')}/${fileName}.schema'
910
10-
export * from './services/${folder.join('/')}/${fileName}.schema'`
11+
export type {
12+
${upperName}Data,
13+
${upperName}Patch,
14+
${upperName}Result,
15+
${upperName}Query,
16+
}`
1117

1218
const declarationTemplate = ({ path, upperName }: ServiceGeneratorContext) =>
13-
` '${path}': Service<${upperName}Result, ${upperName}Data, Params<${upperName}Query>>`
19+
` '${path}': ClientService<
20+
${upperName}Result,
21+
${upperName}Data,
22+
${upperName}Patch,
23+
Paginated<${upperName}Result>,
24+
Params<${upperName}Query>
25+
>`
1426

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

packages/feathers/src/declarations.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,33 @@ export interface ServiceOptions {
2626
routeParams?: { [key: string]: any }
2727
}
2828

29+
export interface ClientService<
30+
Result = any,
31+
Data = Partial<Result>,
32+
PatchData = Data,
33+
FindResult = Paginated<Result>,
34+
P = Params
35+
> {
36+
find(params?: P): Promise<FindResult>
37+
38+
get(id: Id, params?: P): Promise<Result>
39+
40+
create(data: Data[], params?: P): Promise<Result[]>
41+
create(data: Data, params?: P): Promise<Result>
42+
43+
update(id: Id, data: Data, params?: P): Promise<Result>
44+
update(id: NullableId, data: Data, params?: P): Promise<Result | Result[]>
45+
update(id: null, data: Data, params?: P): Promise<Result[]>
46+
47+
patch(id: NullableId, data: PatchData, params?: P): Promise<Result | Result[]>
48+
patch(id: Id, data: PatchData, params?: P): Promise<Result>
49+
patch(id: null, data: PatchData, params?: P): Promise<Result[]>
50+
51+
remove(id: NullableId, params?: P): Promise<Result | Result[]>
52+
remove(id: Id, params?: P): Promise<Result>
53+
remove(id: null, params?: P): Promise<Result[]>
54+
}
55+
2956
export interface ServiceMethods<T = any, D = Partial<T>, P = Params> {
3057
find(params?: P): Promise<T | T[]>
3158

0 commit comments

Comments
 (0)