|
|
@@ -3,7 +3,7 @@ import {FALLBACK_LANGUAGE, Language} from './language'; |
|
|
|
import {FALLBACK_MEDIA_TYPE, MediaType} from './media-type'; |
|
|
|
import {Charset, FALLBACK_CHARSET} from './charset'; |
|
|
|
import * as v from 'valibot'; |
|
|
|
import {BackendBuilder, createBackend, CreateBackendParams} from '../backend'; |
|
|
|
import {Backend, createBackend, CreateBackendParams} from '../backend'; |
|
|
|
import {ClientBuilder, createClient, CreateClientParams} from '../client'; |
|
|
|
|
|
|
|
type ApplicationMap<T extends { name: string }> = Map<T['name'], T>; |
|
|
@@ -20,20 +20,33 @@ export interface ApplicationParams { |
|
|
|
name: string; |
|
|
|
} |
|
|
|
|
|
|
|
export interface ApplicationBuilder { |
|
|
|
mediaType(mediaType: MediaType): this; |
|
|
|
language(language: Language): this; |
|
|
|
charset(charset: Charset): this; |
|
|
|
export interface Application< |
|
|
|
Resources extends Resource[] = [], |
|
|
|
MediaTypes extends MediaType[] = [], |
|
|
|
Charsets extends Charset[] = [], |
|
|
|
Languages extends Language[] = [] |
|
|
|
> { |
|
|
|
mediaType<MediaTypeName extends string = string>(mediaType: MediaType<MediaTypeName>): Application< |
|
|
|
Resources, [...MediaTypes, MediaType<MediaTypeName>], Charsets, Languages |
|
|
|
>; |
|
|
|
language<LanguageName extends string = string>(language: Language<LanguageName>): Application< |
|
|
|
Resources, MediaTypes, Charsets, [...Languages, Language<LanguageName>] |
|
|
|
>; |
|
|
|
charset<CharsetName extends string = string>(charset: Charset<CharsetName>): Application< |
|
|
|
Resources, MediaTypes, [...Charsets, Charset<CharsetName>], Languages |
|
|
|
>; |
|
|
|
resource< |
|
|
|
Schema extends v.BaseSchema, |
|
|
|
CurrentItemName extends string = string, |
|
|
|
CurrentRouteName extends string = string |
|
|
|
>(resRaw: Resource<Schema, CurrentItemName, CurrentRouteName>): this; |
|
|
|
createBackend(params: Omit<CreateBackendParams, 'app'>): BackendBuilder; |
|
|
|
>(resRaw: Resource<Schema, CurrentItemName, CurrentRouteName>): Application< |
|
|
|
[...Resources, Resource<Schema, CurrentItemName, CurrentRouteName>], MediaTypes, Charsets, Languages |
|
|
|
>; |
|
|
|
createBackend(params: Omit<CreateBackendParams, 'app'>): Backend; |
|
|
|
createClient(params: Omit<CreateClientParams, 'app'>): ClientBuilder; |
|
|
|
} |
|
|
|
|
|
|
|
export const application = (appParams: ApplicationParams): ApplicationBuilder => { |
|
|
|
export const application = (appParams: ApplicationParams): Application => { |
|
|
|
const appState: ApplicationState = { |
|
|
|
name: appParams.name, |
|
|
|
resources: new Set<Resource<any>>(), |
|
|
|