Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/okikio/utils.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930import * as endpoint from '@okikio/server/endpoint';import * as resource from '@okikio/resource';
import type { ServiceDefinition, ServiceImplementation, ServiceImplementationInput,} from './types.ts';
/** Bind an exact service definition to its HTTP endpoint, middleware, and resource implementations. */export function implement< Definition extends ServiceDefinition, Host extends object = import('@okikio/server/endpoint').EmptyEndpointHost,>( definition: Definition, input: ServiceImplementationInput<Host>,): ServiceImplementation<Definition, Host> { const endpointBindings = endpoint.handlers(...(input.endpoints ?? [])); const middleware = Object.freeze([...(input.middleware ?? [])]); const resources = input.resources ?? resource.implementations(); return Object.freeze({ kind: 'service-implementation', definition, endpoints: endpointBindings, middleware, resources, ...(input.hostType !== undefined ? { hostType: input.hostType } : {}), });}