-
-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): Add typed client to a generated app (#2669)
- Loading branch information
Showing
15 changed files
with
117 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { generator, toFile } from '@feathershq/pinion' | ||
import { renderSource } from '../../commons' | ||
import { AppGeneratorContext } from '../index' | ||
|
||
const template = ({}: AppGeneratorContext) => | ||
`import { feathers, type Service, type TransportConnection } from '@feathersjs/feathers' | ||
// A mapping of client side services | ||
export interface ServiceTypes { | ||
} | ||
export const createClient = <Configuration = any> (connection: TransportConnection<ServiceTypes>) => { | ||
const client = feathers<ServiceTypes, Configuration>() | ||
client.configure(connection) | ||
return client | ||
} | ||
` | ||
|
||
export const generate = async (ctx: AppGeneratorContext) => | ||
generator(ctx).then( | ||
renderSource( | ||
template, | ||
toFile<AppGeneratorContext>(({ lib }) => lib, 'client') | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { generator, inject, toFile, when, after } from '@feathershq/pinion' | ||
import { ServiceGeneratorContext } from '../index' | ||
|
||
const schemaImports = ({ upperName, schemaPath }: ServiceGeneratorContext) => `import type { | ||
${upperName}Data, | ||
${upperName}Result, | ||
${upperName}Query, | ||
} from './${schemaPath}'` | ||
const declarationTemplate = ({ path, upperName }: ServiceGeneratorContext) => | ||
` '${path}': Service<${upperName}Data, ${upperName}Result, Params<${upperName}Query>>` | ||
|
||
const toClientFile = toFile<ServiceGeneratorContext>(({ lib, language }) => [lib, `client.${language}`]) | ||
|
||
export const generate = async (ctx: ServiceGeneratorContext) => | ||
generator(ctx) | ||
.then( | ||
when( | ||
(ctx) => ctx.language === 'ts', | ||
inject(schemaImports, after("from '@feathersjs/feathers'"), toClientFile) | ||
) | ||
) | ||
.then( | ||
when( | ||
(ctx) => ctx.language === 'ts', | ||
inject(declarationTemplate, after('export interface ServiceTypes'), toClientFile) | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters