provider.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import type { RouteDefaultsInput } from "./route/client"
  2. import type { Model, ModelID, ProviderID } from "./schema"
  3. export type ModelOptions = RouteDefaultsInput
  4. /**
  5. * Advanced structural provider definition helper. Built-in providers should
  6. * prefer explicit `configure(options).model(id)` facades so deployment config is
  7. * chosen before model selection. The optional `apis` map remains for external
  8. * structural providers that expose multiple route selectors behind one provider.
  9. */
  10. export type ModelFactory<Options extends ModelOptions = ModelOptions> = (
  11. id: string | ModelID,
  12. options?: Options,
  13. ) => Model
  14. type AnyModelFactory = (...args: never[]) => Model
  15. export interface Definition<Factory extends AnyModelFactory = ModelFactory> {
  16. readonly id: ProviderID
  17. readonly model: Factory
  18. readonly apis?: Record<string, AnyModelFactory>
  19. }
  20. type DefinitionShape = {
  21. readonly id: ProviderID
  22. readonly model: (...args: never[]) => Model
  23. readonly apis?: Record<string, (...args: never[]) => Model>
  24. }
  25. type NoExtraFields<Input, Shape> = Input & Record<Exclude<keyof Input, keyof Shape>, never>
  26. export const make = <DefinitionType extends DefinitionShape>(
  27. definition: NoExtraFields<DefinitionType, DefinitionShape>,
  28. ) => definition
  29. export * as Provider from "./provider"