provider.ts 986 B

12345678910111213141516171819202122232425262728293031
  1. import type { RouteModelInput } from "./route/client"
  2. import type { ModelID, ModelRef, ProviderID } from "./schema"
  3. export type ModelOptions = Omit<RouteModelInput, "id">
  4. export type ModelFactory<Options extends ModelOptions = ModelOptions> = (
  5. id: string | ModelID,
  6. options?: Options,
  7. ) => ModelRef
  8. type AnyModelFactory = (...args: never[]) => ModelRef
  9. export interface Definition<Factory extends AnyModelFactory = ModelFactory> {
  10. readonly id: ProviderID
  11. readonly model: Factory
  12. readonly apis?: Record<string, AnyModelFactory>
  13. }
  14. type DefinitionShape = {
  15. readonly id: ProviderID
  16. readonly model: (...args: never[]) => ModelRef
  17. readonly apis?: Record<string, (...args: never[]) => ModelRef>
  18. }
  19. type NoExtraFields<Input, Shape> = Input & Record<Exclude<keyof Input, keyof Shape>, never>
  20. export const make = <DefinitionType extends DefinitionShape>(
  21. definition: NoExtraFields<DefinitionType, DefinitionShape>,
  22. ) => definition
  23. export * as Provider from "./provider"