MCPcopy Create free account
hub / github.com/Effect-TS/effect / Service

Function Service

packages/effect/src/unstable/httpapi/HttpApiMiddleware.ts:320–379  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

318 * @since 4.0.0
319 */
320export const Service = <
321 Self,
322 Config extends {
323 requires?: any
324 provides?: any
325 clientError?: any
326 } = { requires: never; provides: never; clientError: never }
327>(): <
328 const Id extends string,
329 const Error extends ErrorConstraint = never,
330 const Security extends Record<string, HttpApiSecurity.HttpApiSecurity> = never,
331 RequiredForClient extends boolean = false
332>(
333 id: Id,
334 options?: {
335 readonly error?: Error | undefined
336 readonly security?: Security | undefined
337 readonly requiredForClient?: RequiredForClient | undefined
338 } | undefined
339) => ServiceClass<Self, Id, {
340 requires: "requires" extends keyof Config ? Config["requires"] : never
341 provides: "provides" extends keyof Config ? Config["provides"] : never
342 error: Error
343 clientError: "clientError" extends keyof Config ? Config["clientError"] : never
344 requiredForClient: RequiredForClient
345 security: Security
346}> =>
347(
348 id: string,
349 options?: {
350 readonly security?: Record<string, HttpApiSecurity.HttpApiSecurity> | undefined
351 readonly error?: ErrorConstraint | undefined
352 readonly requiredForClient?: boolean | undefined
353 } | undefined
354) => {
355 const Err = globalThis.Error as any
356 const limit = getStackTraceLimit()
357 setStackTraceLimit(2)
358 const creationError = new Err()
359 setStackTraceLimit(limit)
360
361 class Service extends Context.Service<Self, any>()(id) {}
362 const self = Service as any
363 Object.defineProperty(Service, "stack", {
364 get() {
365 return creationError.stack
366 }
367 })
368 self[TypeId] = TypeId
369 self.error = getError(options?.error)
370 self.requiredForClient = options?.requiredForClient ?? false
371 if (options?.security !== undefined) {
372 if (Object.keys(options.security).length === 0) {
373 throw new Error("HttpApiMiddleware.Service: security object must not be empty")
374 }
375 self[SecurityTypeId] = SecurityTypeId
376 self.security = options.security
377 }

Callers

nothing calls this directly

Calls 3

getStackTraceLimitFunction · 0.90
setStackTraceLimitFunction · 0.90
getErrorFunction · 0.85

Tested by

no test coverage detected