@effect/platform
Advanced tools
Comparing version 0.58.5 to 0.58.6
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.use = exports.schemaPathParams = exports.schemaParams = exports.schemaNoBody = exports.schemaJson = exports.route = exports.put = exports.provideServiceEffect = exports.provideService = exports.prefixAll = exports.post = exports.patch = exports.params = exports.options = exports.mountApp = exports.mount = exports.makeRoute = exports.head = exports.get = exports.fromIterable = exports.empty = exports.del = exports.concat = exports.catchTags = exports.catchTag = exports.catchAllCause = exports.catchAll = exports.all = exports.TypeId = exports.RouteTypeId = exports.RouteContextTypeId = exports.RouteContext = void 0; | ||
exports.use = exports.schemaPathParams = exports.schemaParams = exports.schemaNoBody = exports.schemaJson = exports.route = exports.put = exports.provideServiceEffect = exports.provideService = exports.prefixAll = exports.post = exports.patch = exports.params = exports.options = exports.mountApp = exports.mount = exports.makeRoute = exports.head = exports.get = exports.fromIterable = exports.empty = exports.del = exports.concat = exports.catchTags = exports.catchTag = exports.catchAllCause = exports.catchAll = exports.append = exports.all = exports.TypeId = exports.Tag = exports.RouteTypeId = exports.RouteContextTypeId = exports.RouteContext = void 0; | ||
var internal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("./internal/httpRouter.js")); | ||
@@ -103,2 +103,7 @@ function _getRequireWildcardCache(e) { | ||
*/ | ||
const append = exports.append = internal.append; | ||
/** | ||
* @since 1.0.0 | ||
* @category combinators | ||
*/ | ||
const concat = exports.concat = internal.concat; | ||
@@ -195,2 +200,7 @@ /** | ||
const provideServiceEffect = exports.provideServiceEffect = internal.provideServiceEffect; | ||
/** | ||
* @since 1.0.0 | ||
* @category tags | ||
*/ | ||
const Tag = exports.Tag = internal.Tag; | ||
//# sourceMappingURL=HttpRouter.js.map |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.use = exports.schemaPathParams = exports.schemaParams = exports.schemaNoBody = exports.schemaJson = exports.route = exports.put = exports.provideServiceEffect = exports.provideService = exports.prefixAll = exports.post = exports.patch = exports.params = exports.options = exports.mountApp = exports.mount = exports.makeRoute = exports.head = exports.get = exports.fromIterable = exports.empty = exports.del = exports.concat = exports.catchTags = exports.catchTag = exports.catchAllCause = exports.catchAll = exports.all = exports.TypeId = exports.RouteTypeId = exports.RouteContextTypeId = exports.RouteContext = void 0; | ||
exports.use = exports.schemaPathParams = exports.schemaParams = exports.schemaNoBody = exports.schemaJson = exports.route = exports.put = exports.provideServiceEffect = exports.provideService = exports.prefixAll = exports.post = exports.patch = exports.params = exports.options = exports.mountApp = exports.mount = exports.makeRoute = exports.head = exports.get = exports.fromIterable = exports.empty = exports.del = exports.concat = exports.catchTags = exports.catchTag = exports.catchAllCause = exports.catchAll = exports.append = exports.all = exports.TypeId = exports.Tag = exports.RouteTypeId = exports.RouteContextTypeId = exports.RouteContext = void 0; | ||
var Schema = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/schema/Schema")); | ||
@@ -16,2 +16,3 @@ var Chunk = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Chunk")); | ||
var Inspectable = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Inspectable")); | ||
var Layer = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Layer")); | ||
var Option = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Option")); | ||
@@ -239,5 +240,7 @@ var Predicate = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("effect/Predicate")); | ||
exports.fromIterable = fromIterable; | ||
const makeRoute = (method, path, handler, prefix = Option.none(), uninterruptible = false) => new RouteImpl(method, path, handler, prefix, uninterruptible); | ||
const makeRoute = (method, path, handler, options) => new RouteImpl(method, path, handler, options?.prefix ? Option.some(options.prefix) : Option.none(), options?.uninterruptible ?? false); | ||
/** @internal */ | ||
exports.makeRoute = makeRoute; | ||
const append = exports.append = /*#__PURE__*/(0, _Function.dual)(2, (self, route) => new RouterImpl(Chunk.append(self.routes, route), self.mounts)); | ||
/** @internal */ | ||
const concat = exports.concat = /*#__PURE__*/(0, _Function.dual)(2, (self, that) => new RouterImpl(Chunk.appendAll(self.routes, that.routes), self.mounts)); | ||
@@ -286,2 +289,75 @@ const removeTrailingSlash = path => path.endsWith("/") ? path.slice(0, -1) : path; | ||
const provideServiceEffect = exports.provideServiceEffect = /*#__PURE__*/(0, _Function.dual)(3, (self, tag, effect) => use(self, Effect.provideServiceEffect(tag, effect))); | ||
const makeService = () => { | ||
let router = empty; | ||
return { | ||
addRoute(route) { | ||
return Effect.sync(() => { | ||
router = append(router, route); | ||
}); | ||
}, | ||
all(path, handler, options) { | ||
return Effect.sync(() => { | ||
router = all(router, path, handler, options); | ||
}); | ||
}, | ||
get(path, handler, options) { | ||
return Effect.sync(() => { | ||
router = get(router, path, handler, options); | ||
}); | ||
}, | ||
post(path, handler, options) { | ||
return Effect.sync(() => { | ||
router = post(router, path, handler, options); | ||
}); | ||
}, | ||
put(path, handler, options) { | ||
return Effect.sync(() => { | ||
router = put(router, path, handler, options); | ||
}); | ||
}, | ||
patch(path, handler, options) { | ||
return Effect.sync(() => { | ||
router = patch(router, path, handler, options); | ||
}); | ||
}, | ||
del(path, handler, options) { | ||
return Effect.sync(() => { | ||
router = del(router, path, handler, options); | ||
}); | ||
}, | ||
head(path, handler, options) { | ||
return Effect.sync(() => { | ||
router = head(router, path, handler, options); | ||
}); | ||
}, | ||
options(path, handler, opts) { | ||
return Effect.sync(() => { | ||
router = options(router, path, handler, opts); | ||
}); | ||
}, | ||
router: Effect.sync(() => router) | ||
}; | ||
}; | ||
/* @internal */ | ||
const Tag = id => () => { | ||
const Err = globalThis.Error; | ||
const limit = Err.stackTraceLimit; | ||
Err.stackTraceLimit = 2; | ||
const creationError = new Err(); | ||
Err.stackTraceLimit = limit; | ||
function TagClass() {} | ||
Object.setPrototypeOf(TagClass, Object.getPrototypeOf(Context.GenericTag(id))); | ||
TagClass.key = id; | ||
Object.defineProperty(TagClass, "stack", { | ||
get() { | ||
return creationError.stack; | ||
} | ||
}); | ||
TagClass.Live = Layer.sync(TagClass, makeService); | ||
TagClass.router = Effect.flatMap(TagClass, _ => _.router); | ||
TagClass.use = f => Layer.effectDiscard(Effect.flatMap(TagClass, f)).pipe(Layer.provide(TagClass.Live)); | ||
TagClass.useScoped = f => Layer.scopedDiscard(Effect.flatMap(TagClass, f)).pipe(Layer.provide(TagClass.Live)); | ||
return TagClass; | ||
}; | ||
exports.Tag = Tag; | ||
//# sourceMappingURL=httpRouter.js.map |
@@ -12,2 +12,3 @@ /** | ||
import type { Inspectable } from "effect/Inspectable"; | ||
import type * as Layer from "effect/Layer"; | ||
import type * as Option from "effect/Option"; | ||
@@ -51,3 +52,48 @@ import type * as Scope from "effect/Scope"; | ||
*/ | ||
type ExcludeProvided<A> = Exclude<A, RouteContext | ServerRequest.HttpServerRequest | ServerRequest.ParsedSearchParams | Scope.Scope>; | ||
type Provided = RouteContext | ServerRequest.HttpServerRequest | ServerRequest.ParsedSearchParams | Scope.Scope; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
type ExcludeProvided<A> = Exclude<A, Provided>; | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
interface Service<E, R> { | ||
readonly router: Effect.Effect<HttpRouter<E, R>>; | ||
readonly addRoute: (route: Route<E, R>) => Effect.Effect<void>; | ||
readonly all: (path: PathInput, handler: Route.Handler<E, R | Provided>, options?: { | ||
readonly uninterruptible?: boolean | undefined; | ||
} | undefined) => Effect.Effect<void>; | ||
readonly get: (path: PathInput, handler: Route.Handler<E, R | Provided>, options?: { | ||
readonly uninterruptible?: boolean | undefined; | ||
} | undefined) => Effect.Effect<void>; | ||
readonly post: (path: PathInput, handler: Route.Handler<E, R | Provided>, options?: { | ||
readonly uninterruptible?: boolean | undefined; | ||
} | undefined) => Effect.Effect<void>; | ||
readonly put: (path: PathInput, handler: Route.Handler<E, R | Provided>, options?: { | ||
readonly uninterruptible?: boolean | undefined; | ||
} | undefined) => Effect.Effect<void>; | ||
readonly patch: (path: PathInput, handler: Route.Handler<E, R | Provided>, options?: { | ||
readonly uninterruptible?: boolean | undefined; | ||
} | undefined) => Effect.Effect<void>; | ||
readonly del: (path: PathInput, handler: Route.Handler<E, R | Provided>, options?: { | ||
readonly uninterruptible?: boolean | undefined; | ||
} | undefined) => Effect.Effect<void>; | ||
readonly head: (path: PathInput, handler: Route.Handler<E, R | Provided>, options?: { | ||
readonly uninterruptible?: boolean | undefined; | ||
} | undefined) => Effect.Effect<void>; | ||
readonly options: (path: PathInput, handler: Route.Handler<E, R | Provided>, options?: { | ||
readonly uninterruptible?: boolean | undefined; | ||
} | undefined) => Effect.Effect<void>; | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
interface TagClass<Self, Name extends string, E, R> extends Context.Tag<Self, Service<E, R>> { | ||
new (_: never): Context.TagClassShape<`@effect/platform/HttpRouter/${Name}`, Service<E, R>>; | ||
readonly Live: Layer.Layer<Self>; | ||
readonly router: Effect.Effect<HttpRouter<E, R>, never, Self>; | ||
readonly use: <XA, XE, XR>(f: (router: Service<E, R>) => Effect.Effect<XA, XE, XR>) => Layer.Layer<never, XE, XR>; | ||
readonly useScoped: <XA, XE, XR>(f: (router: Service<E, R>) => Effect.Effect<XA, XE, XR>) => Layer.Layer<never, XE, Exclude<XR, Scope.Scope>>; | ||
} | ||
} | ||
@@ -168,3 +214,6 @@ /** | ||
*/ | ||
export declare const makeRoute: <E, R>(method: Method.HttpMethod, path: PathInput, handler: Route.Handler<E, R>, prefix?: Option.Option<string>, uninterruptible?: boolean) => Route<E, HttpRouter.ExcludeProvided<R>>; | ||
export declare const makeRoute: <E, R>(method: Method.HttpMethod, path: PathInput, handler: Route.Handler<E, R>, options?: { | ||
readonly prefix?: string | undefined; | ||
readonly uninterruptible?: boolean | undefined; | ||
} | undefined) => Route<E, HttpRouter.ExcludeProvided<R>>; | ||
/** | ||
@@ -182,2 +231,10 @@ * @since 1.0.0 | ||
*/ | ||
export declare const append: { | ||
<R1, E1>(route: Route<E1, R1>): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, R | HttpRouter.ExcludeProvided<R1>>; | ||
<E, R, E1, R1>(self: HttpRouter<E, R>, route: Route<E1, R1>): HttpRouter<E | E1, R | HttpRouter.ExcludeProvided<R1>>; | ||
}; | ||
/** | ||
* @since 1.0.0 | ||
* @category combinators | ||
*/ | ||
export declare const concat: { | ||
@@ -407,2 +464,7 @@ <R1, E1>(that: HttpRouter<E1, R1>): <E, R>(self: HttpRouter<E, R>) => HttpRouter<E1 | E, R1 | R>; | ||
}; | ||
/** | ||
* @since 1.0.0 | ||
* @category tags | ||
*/ | ||
export declare const Tag: <const Name extends string>(id: Name) => <Self, E = never, R = never>() => HttpRouter.TagClass<Self, Name, E, R>; | ||
//# sourceMappingURL=HttpRouter.d.ts.map |
@@ -71,2 +71,7 @@ import * as internal from "./internal/httpRouter.js"; | ||
*/ | ||
export const append = internal.append; | ||
/** | ||
* @since 1.0.0 | ||
* @category combinators | ||
*/ | ||
export const concat = internal.concat; | ||
@@ -163,2 +168,7 @@ /** | ||
export const provideServiceEffect = internal.provideServiceEffect; | ||
/** | ||
* @since 1.0.0 | ||
* @category tags | ||
*/ | ||
export const Tag = internal.Tag; | ||
//# sourceMappingURL=HttpRouter.js.map |
@@ -9,2 +9,3 @@ import * as Schema from "@effect/schema/Schema"; | ||
import * as Inspectable from "effect/Inspectable"; | ||
import * as Layer from "effect/Layer"; | ||
import * as Option from "effect/Option"; | ||
@@ -202,4 +203,6 @@ import * as Predicate from "effect/Predicate"; | ||
/** @internal */ | ||
export const makeRoute = (method, path, handler, prefix = Option.none(), uninterruptible = false) => new RouteImpl(method, path, handler, prefix, uninterruptible); | ||
export const makeRoute = (method, path, handler, options) => new RouteImpl(method, path, handler, options?.prefix ? Option.some(options.prefix) : Option.none(), options?.uninterruptible ?? false); | ||
/** @internal */ | ||
export const append = /*#__PURE__*/dual(2, (self, route) => new RouterImpl(Chunk.append(self.routes, route), self.mounts)); | ||
/** @internal */ | ||
export const concat = /*#__PURE__*/dual(2, (self, that) => new RouterImpl(Chunk.appendAll(self.routes, that.routes), self.mounts)); | ||
@@ -247,2 +250,74 @@ const removeTrailingSlash = path => path.endsWith("/") ? path.slice(0, -1) : path; | ||
export const provideServiceEffect = /*#__PURE__*/dual(3, (self, tag, effect) => use(self, Effect.provideServiceEffect(tag, effect))); | ||
const makeService = () => { | ||
let router = empty; | ||
return { | ||
addRoute(route) { | ||
return Effect.sync(() => { | ||
router = append(router, route); | ||
}); | ||
}, | ||
all(path, handler, options) { | ||
return Effect.sync(() => { | ||
router = all(router, path, handler, options); | ||
}); | ||
}, | ||
get(path, handler, options) { | ||
return Effect.sync(() => { | ||
router = get(router, path, handler, options); | ||
}); | ||
}, | ||
post(path, handler, options) { | ||
return Effect.sync(() => { | ||
router = post(router, path, handler, options); | ||
}); | ||
}, | ||
put(path, handler, options) { | ||
return Effect.sync(() => { | ||
router = put(router, path, handler, options); | ||
}); | ||
}, | ||
patch(path, handler, options) { | ||
return Effect.sync(() => { | ||
router = patch(router, path, handler, options); | ||
}); | ||
}, | ||
del(path, handler, options) { | ||
return Effect.sync(() => { | ||
router = del(router, path, handler, options); | ||
}); | ||
}, | ||
head(path, handler, options) { | ||
return Effect.sync(() => { | ||
router = head(router, path, handler, options); | ||
}); | ||
}, | ||
options(path, handler, opts) { | ||
return Effect.sync(() => { | ||
router = options(router, path, handler, opts); | ||
}); | ||
}, | ||
router: Effect.sync(() => router) | ||
}; | ||
}; | ||
/* @internal */ | ||
export const Tag = id => () => { | ||
const Err = globalThis.Error; | ||
const limit = Err.stackTraceLimit; | ||
Err.stackTraceLimit = 2; | ||
const creationError = new Err(); | ||
Err.stackTraceLimit = limit; | ||
function TagClass() {} | ||
Object.setPrototypeOf(TagClass, Object.getPrototypeOf(Context.GenericTag(id))); | ||
TagClass.key = id; | ||
Object.defineProperty(TagClass, "stack", { | ||
get() { | ||
return creationError.stack; | ||
} | ||
}); | ||
TagClass.Live = Layer.sync(TagClass, makeService); | ||
TagClass.router = Effect.flatMap(TagClass, _ => _.router); | ||
TagClass.use = f => Layer.effectDiscard(Effect.flatMap(TagClass, f)).pipe(Layer.provide(TagClass.Live)); | ||
TagClass.useScoped = f => Layer.scopedDiscard(Effect.flatMap(TagClass, f)).pipe(Layer.provide(TagClass.Live)); | ||
return TagClass; | ||
}; | ||
//# sourceMappingURL=httpRouter.js.map |
{ | ||
"name": "@effect/platform", | ||
"version": "0.58.5", | ||
"version": "0.58.6", | ||
"description": "Unified interfaces for common platform-specific services", | ||
@@ -18,4 +18,4 @@ "license": "MIT", | ||
"peerDependencies": { | ||
"@effect/schema": "^0.68.6", | ||
"effect": "^3.4.0" | ||
"@effect/schema": "^0.68.7", | ||
"effect": "^3.4.1" | ||
}, | ||
@@ -22,0 +22,0 @@ "publishConfig": { |
@@ -12,2 +12,3 @@ /** | ||
import type { Inspectable } from "effect/Inspectable" | ||
import type * as Layer from "effect/Layer" | ||
import type * as Option from "effect/Option" | ||
@@ -58,6 +59,71 @@ import type * as Scope from "effect/Scope" | ||
*/ | ||
export type ExcludeProvided<A> = Exclude< | ||
A, | ||
RouteContext | ServerRequest.HttpServerRequest | ServerRequest.ParsedSearchParams | Scope.Scope | ||
> | ||
export type Provided = RouteContext | ServerRequest.HttpServerRequest | ServerRequest.ParsedSearchParams | Scope.Scope | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export type ExcludeProvided<A> = Exclude<A, Provided> | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export interface Service<E, R> { | ||
readonly router: Effect.Effect<HttpRouter<E, R>> | ||
readonly addRoute: (route: Route<E, R>) => Effect.Effect<void> | ||
readonly all: ( | ||
path: PathInput, | ||
handler: Route.Handler<E, R | Provided>, | ||
options?: { readonly uninterruptible?: boolean | undefined } | undefined | ||
) => Effect.Effect<void> | ||
readonly get: ( | ||
path: PathInput, | ||
handler: Route.Handler<E, R | Provided>, | ||
options?: { readonly uninterruptible?: boolean | undefined } | undefined | ||
) => Effect.Effect<void> | ||
readonly post: ( | ||
path: PathInput, | ||
handler: Route.Handler<E, R | Provided>, | ||
options?: { readonly uninterruptible?: boolean | undefined } | undefined | ||
) => Effect.Effect<void> | ||
readonly put: ( | ||
path: PathInput, | ||
handler: Route.Handler<E, R | Provided>, | ||
options?: { readonly uninterruptible?: boolean | undefined } | undefined | ||
) => Effect.Effect<void> | ||
readonly patch: ( | ||
path: PathInput, | ||
handler: Route.Handler<E, R | Provided>, | ||
options?: { readonly uninterruptible?: boolean | undefined } | undefined | ||
) => Effect.Effect<void> | ||
readonly del: ( | ||
path: PathInput, | ||
handler: Route.Handler<E, R | Provided>, | ||
options?: { readonly uninterruptible?: boolean | undefined } | undefined | ||
) => Effect.Effect<void> | ||
readonly head: ( | ||
path: PathInput, | ||
handler: Route.Handler<E, R | Provided>, | ||
options?: { readonly uninterruptible?: boolean | undefined } | undefined | ||
) => Effect.Effect<void> | ||
readonly options: ( | ||
path: PathInput, | ||
handler: Route.Handler<E, R | Provided>, | ||
options?: { readonly uninterruptible?: boolean | undefined } | undefined | ||
) => Effect.Effect<void> | ||
} | ||
/** | ||
* @since 1.0.0 | ||
*/ | ||
export interface TagClass<Self, Name extends string, E, R> extends Context.Tag<Self, Service<E, R>> { | ||
new(_: never): Context.TagClassShape<`@effect/platform/HttpRouter/${Name}`, Service<E, R>> | ||
readonly Live: Layer.Layer<Self> | ||
readonly router: Effect.Effect<HttpRouter<E, R>, never, Self> | ||
readonly use: <XA, XE, XR>(f: (router: Service<E, R>) => Effect.Effect<XA, XE, XR>) => Layer.Layer<never, XE, XR> | ||
readonly useScoped: <XA, XE, XR>( | ||
f: (router: Service<E, R>) => Effect.Effect<XA, XE, XR> | ||
) => Layer.Layer<never, XE, Exclude<XR, Scope.Scope>> | ||
} | ||
} | ||
@@ -237,4 +303,3 @@ | ||
handler: Route.Handler<E, R>, | ||
prefix?: Option.Option<string>, | ||
uninterruptible?: boolean | ||
options?: { readonly prefix?: string | undefined; readonly uninterruptible?: boolean | undefined } | undefined | ||
) => Route<E, HttpRouter.ExcludeProvided<R>> = internal.makeRoute | ||
@@ -255,2 +320,24 @@ | ||
*/ | ||
export const append: { | ||
<R1, E1>( | ||
route: Route<E1, R1> | ||
): <E, R>( | ||
self: HttpRouter<E, R> | ||
) => HttpRouter< | ||
E1 | E, | ||
R | HttpRouter.ExcludeProvided<R1> | ||
> | ||
<E, R, E1, R1>( | ||
self: HttpRouter<E, R>, | ||
route: Route<E1, R1> | ||
): HttpRouter< | ||
E | E1, | ||
R | HttpRouter.ExcludeProvided<R1> | ||
> | ||
} = internal.append | ||
/** | ||
* @since 1.0.0 | ||
* @category combinators | ||
*/ | ||
export const concat: { | ||
@@ -641,1 +728,9 @@ <R1, E1>(that: HttpRouter<E1, R1>): <E, R>( | ||
} = internal.provideServiceEffect | ||
/** | ||
* @since 1.0.0 | ||
* @category tags | ||
*/ | ||
export const Tag: <const Name extends string>( | ||
id: Name | ||
) => <Self, E = never, R = never>() => HttpRouter.TagClass<Self, Name, E, R> = internal.Tag |
@@ -11,2 +11,3 @@ import type { ParseOptions } from "@effect/schema/AST" | ||
import * as Inspectable from "effect/Inspectable" | ||
import * as Layer from "effect/Layer" | ||
import * as Option from "effect/Option" | ||
@@ -321,4 +322,6 @@ import * as Predicate from "effect/Predicate" | ||
handler: Router.Route.Handler<E, R>, | ||
prefix: Option.Option<string> = Option.none(), | ||
uninterruptible = false | ||
options?: { | ||
readonly prefix?: string | undefined | ||
readonly uninterruptible?: boolean | undefined | ||
} | undefined | ||
): Router.Route<E, Router.HttpRouter.ExcludeProvided<R>> => | ||
@@ -329,7 +332,18 @@ new RouteImpl( | ||
handler, | ||
prefix, | ||
uninterruptible | ||
options?.prefix ? Option.some(options.prefix) : Option.none(), | ||
options?.uninterruptible ?? false | ||
) as any | ||
/** @internal */ | ||
export const append = dual< | ||
<R1, E1>( | ||
route: Router.Route<E1, R1> | ||
) => <E, R>(self: Router.HttpRouter<E, R>) => Router.HttpRouter<E | E1, R | Router.HttpRouter.ExcludeProvided<R1>>, | ||
<E, R, E1, R1>( | ||
self: Router.HttpRouter<E, R>, | ||
route: Router.Route<E1, R1> | ||
) => Router.HttpRouter<E | E1, R | Router.HttpRouter.ExcludeProvided<R1>> | ||
>(2, (self, route) => new RouterImpl(Chunk.append(self.routes, route) as any, self.mounts)) | ||
/** @internal */ | ||
export const concat = dual< | ||
@@ -651,1 +665,84 @@ <R1, E1>( | ||
> => use(self, Effect.provideServiceEffect(tag, effect)) as any) | ||
const makeService = <E, R>(): Router.HttpRouter.Service<E, R> => { | ||
let router = empty as Router.HttpRouter<E, R> | ||
return { | ||
addRoute(route) { | ||
return Effect.sync(() => { | ||
router = append(router, route) | ||
}) | ||
}, | ||
all(path, handler, options) { | ||
return Effect.sync(() => { | ||
router = all(router, path, handler, options) | ||
}) | ||
}, | ||
get(path, handler, options) { | ||
return Effect.sync(() => { | ||
router = get(router, path, handler, options) | ||
}) | ||
}, | ||
post(path, handler, options) { | ||
return Effect.sync(() => { | ||
router = post(router, path, handler, options) | ||
}) | ||
}, | ||
put(path, handler, options) { | ||
return Effect.sync(() => { | ||
router = put(router, path, handler, options) | ||
}) | ||
}, | ||
patch(path, handler, options) { | ||
return Effect.sync(() => { | ||
router = patch(router, path, handler, options) | ||
}) | ||
}, | ||
del(path, handler, options) { | ||
return Effect.sync(() => { | ||
router = del(router, path, handler, options) | ||
}) | ||
}, | ||
head(path, handler, options) { | ||
return Effect.sync(() => { | ||
router = head(router, path, handler, options) | ||
}) | ||
}, | ||
options(path, handler, opts) { | ||
return Effect.sync(() => { | ||
router = options(router, path, handler, opts) | ||
}) | ||
}, | ||
router: Effect.sync(() => router) | ||
} | ||
} | ||
/* @internal */ | ||
export const Tag = | ||
<const Name extends string>(id: Name) => | ||
<Self, E = never, R = never>(): Router.HttpRouter.TagClass<Self, Name, E, R> => { | ||
const Err = globalThis.Error as any | ||
const limit = Err.stackTraceLimit | ||
Err.stackTraceLimit = 2 | ||
const creationError = new Err() | ||
Err.stackTraceLimit = limit | ||
function TagClass() {} | ||
Object.setPrototypeOf(TagClass, Object.getPrototypeOf(Context.GenericTag<Self, any>(id))) | ||
TagClass.key = id | ||
Object.defineProperty(TagClass, "stack", { | ||
get() { | ||
return creationError.stack | ||
} | ||
}) | ||
TagClass.Live = Layer.sync(TagClass as any, makeService) | ||
TagClass.router = Effect.flatMap(TagClass as any, (_: any) => _.router) | ||
TagClass.use = (f: any) => | ||
Layer.effectDiscard(Effect.flatMap(TagClass as any, f)).pipe( | ||
Layer.provide(TagClass.Live) | ||
) | ||
TagClass.useScoped = (f: any) => | ||
Layer.scopedDiscard(Effect.flatMap(TagClass as any, f)).pipe( | ||
Layer.provide(TagClass.Live) | ||
) | ||
return TagClass as any | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2153206
36983