import * 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, ): ServiceImplementation { 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 } : {}), }); }