Skip to content

Commit

Permalink
Add types tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitayutanov committed Sep 19, 2024
1 parent 5a802d4 commit 1f70841
Show file tree
Hide file tree
Showing 3 changed files with 244 additions and 64 deletions.
34 changes: 17 additions & 17 deletions js/cli/src/generate/hooks-gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class HooksGenerator extends BaseGenerator {
useProgramEvent,
UseProgramParameters as useSailsProgramParameters,
UseProgramQueryParameters,
UseProgramEventParameters`,
UseProgramEventParameters`
)
// TODO: combine with above after hooks update
.import(
Expand All @@ -34,7 +34,7 @@ export class HooksGenerator extends BaseGenerator {
FunctionName,
QueryName,
QueryReturn,
EventReturn`,
EventReturn`
)
.import(`./${LIB_FILE_NAME}`, 'Program');
};
Expand Down Expand Up @@ -62,9 +62,9 @@ export class HooksGenerator extends BaseGenerator {
.line('QueryReturn<ProgramType[TServiceName][TFunctionName]>', false)
.reduceIndent()
.line('>,', false)
.line("'program' | 'serviceName' | 'functionName'", false)
.line("'serviceName' | 'functionName'", false)
.reduceIndent()
.line('> & ProgramParameter')
.line('>')
.line()
.line('type UseEventParameters<', false)
.increaseIndent()
Expand All @@ -81,16 +81,16 @@ export class HooksGenerator extends BaseGenerator {
.line('EventCallbackArgs<Event<ProgramType[TServiceName][TFunctionName]>>', false)
.reduceIndent()
.line('>,', false)
.line("'program' | 'serviceName' | 'functionName'", false)
.line("'serviceName' | 'functionName'", false)
.reduceIndent()
.line('> & ProgramParameter')
.line('> &')
.line();
};

private generateUseProgram = () =>
this._out
.block('export function useProgram(parameters: UseProgramParameters)', () =>
this._out.line('return useSailsProgram({ library: Program, ...parameters })'),
this._out.line('return useSailsProgram({ library: Program, ...parameters })')
)
.line();

Expand All @@ -101,9 +101,9 @@ export class HooksGenerator extends BaseGenerator {
.block(`export function ${name}({ program }: ProgramParameter)`, () =>
this._out.line(
`return useSendProgramTransaction({ program, serviceName: '${toLowerCaseFirst(
serviceName,
)}', functionName: '${toLowerCaseFirst(functionName)}' })`,
),
serviceName
)}', functionName: '${toLowerCaseFirst(functionName)}' })`
)
)
.line();
};
Expand All @@ -115,9 +115,9 @@ export class HooksGenerator extends BaseGenerator {
.block(`export function ${name}({ program }: ProgramParameter)`, () =>
this._out.line(
`return usePrepareProgramTransaction({ program, serviceName: '${toLowerCaseFirst(
serviceName,
)}', functionName: '${toLowerCaseFirst(functionName)}' })`,
),
serviceName
)}', functionName: '${toLowerCaseFirst(functionName)}' })`
)
)
.line();
};
Expand All @@ -132,8 +132,8 @@ export class HooksGenerator extends BaseGenerator {
`export function ${name}(parameters: UseQueryParameters<'${formattedServiceName}', '${formattedFunctionName}'>)`,
() =>
this._out.line(
`return useProgramQuery({ ...parameters, serviceName: '${formattedServiceName}', functionName: '${formattedFunctionName}' })`,
),
`return useProgramQuery({ ...parameters, serviceName: '${formattedServiceName}', functionName: '${formattedFunctionName}' })`
)
)
.line();
};
Expand All @@ -148,8 +148,8 @@ export class HooksGenerator extends BaseGenerator {
`export function ${name}(parameters: UseEventParameters<'${formattedServiceName}', '${functionName}'>)`,
() =>
this._out.line(
`return useProgramEvent({...parameters, serviceName: '${formattedServiceName}', functionName: '${functionName}' })`,
),
`return useProgramEvent({...parameters, serviceName: '${formattedServiceName}', functionName: '${functionName}' })`
)
)
.line();
};
Expand Down
Loading

0 comments on commit 1f70841

Please sign in to comment.