File size: 1,265 Bytes
eb1202c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import type { Model, ModelID, ProviderID } from "./schema"

export type ModelOptions = Pick<Model.Input, "defaults" | "compatibility">

/**
 * Advanced structural provider definition helper. Built-in providers should
 * prefer explicit `configure(options).model(id)` facades so deployment config is
 * chosen before model selection. The optional `apis` map remains for external
 * structural providers that expose multiple route selectors behind one provider.
 */
export type ModelFactory<Options extends ModelOptions = ModelOptions> = (
  id: string | ModelID,
  options?: Options,
) => Model

type AnyModelFactory = (...args: never[]) => Model

export interface Definition<Factory extends AnyModelFactory = ModelFactory> {
  readonly id: ProviderID
  readonly model: Factory
  readonly apis?: Record<string, AnyModelFactory>
}

type DefinitionShape = {
  readonly id: ProviderID
  readonly model: (...args: never[]) => Model
  readonly apis?: Record<string, (...args: never[]) => Model>
}

type NoExtraFields<Input, Shape> = Input & Record<Exclude<keyof Input, keyof Shape>, never>

export const make = <DefinitionType extends DefinitionShape>(
  definition: NoExtraFields<DefinitionType, DefinitionShape>,
) => definition

export * as Provider from "./provider"