Skip to content

Commit e89f3d2

Browse files
committed
feat(endpoints): add useEndpoints convenience function
1 parent 22619a1 commit e89f3d2

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

packages/endpoints/src/convenience.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,27 @@ import { EndpointSchemas } from './core';
44
import { GenerateEndpoints, generateEndpoints } from './generators';
55
import { EndpointInvoker } from './invoker';
66

7+
/**
8+
* Convenience function that generates invocable endpoint functions
9+
* from the given endpoint schemas.
10+
*
11+
* @see `generateEndpoints` - for manually generating endpoints
12+
*
13+
* @example
14+
* ```ts
15+
* export const USER_ENDPOINTS = {
16+
* // ...
17+
* } as const satisfies EndpointSchemas;
18+
* ```
19+
* ```ts
20+
* private userEndpoints = useEndpoints(USER_ENDPOINTS);
21+
* ```
22+
*/
23+
export const useEndpoints = <Schemas extends EndpointSchemas>(
24+
schemas: Schemas,
25+
invoker = inject(EndpointInvoker),
26+
): GenerateEndpoints<Schemas> => generateEndpoints(invoker, schemas);
27+
728
/**
829
* Convenience function that creates a typed `InjectionToken` with a default
930
* value of a collection of endpoints generated from the given schemas,

0 commit comments

Comments
 (0)