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

Function Service

packages/effect/src/http-api/HttpApiMiddleware.ts:345–406  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

343 * @since 4.0.0
344 */
345export const Service = <
346 Self,
347 Config extends {
348 requires?: any
349 provides?: any
350 clientError?: any
351 } = { requires: never; provides: never; clientError: never }
352>(): <
353 const Id extends string,
354 const Error extends ErrorConstraint = never,
355 const Security extends Record<string, HttpApiSecurity.HttpApiSecurity> = never,
356 RequiredForClient extends boolean = false
357>(
358 id: Id,
359 options?: {
360 readonly error?: Error | undefined
361 readonly security?: Security | undefined
362 readonly requiredForClient?: RequiredForClient | undefined
363 } | undefined
364) => ServiceClass<Self, Id, {
365 requires: "requires" extends keyof Config ? Config["requires"] : never
366 provides: "provides" extends keyof Config ? Config["provides"] : never
367 error: Error
368 clientError: "clientError" extends keyof Config ? Config["clientError"] : never
369 requiredForClient: RequiredForClient
370 security: Security
371}> =>
372(
373 id: string,
374 options?: {
375 readonly security?: Record<string, HttpApiSecurity.HttpApiSecurity> | undefined
376 readonly error?: ErrorConstraint | undefined
377 readonly requiredForClient?: boolean | undefined
378 } | undefined
379) => {
380 const limit = getStackTraceLimit()
381 let creationError: globalThis.Error | undefined
382 if (limit !== 0) {
383 setStackTraceLimit(2)
384 creationError = new globalThis.Error()
385 setStackTraceLimit(limit)
386 }
387
388 class Service extends Context.Service<Self, any>()(id) {}
389 const self = Service as any
390 Object.defineProperty(Service, "stack", {
391 get() {
392 return creationError?.stack
393 }
394 })
395 self[TypeId] = TypeId
396 self.error = getError(options?.error)
397 self.requiredForClient = options?.requiredForClient ?? false
398 if (options?.security !== undefined) {
399 if (Object.keys(options.security).length === 0) {
400 throw new Error("HttpApiMiddleware.Service: security object must not be empty")
401 }
402 self[SecurityTypeId] = SecurityTypeId

Callers 1

ProblemDetailsClass · 0.70

Calls 4

getStackTraceLimitFunction · 0.90
setStackTraceLimitFunction · 0.90
getErrorFunction · 0.85
keysMethod · 0.80

Tested by

no test coverage detected