@effect/platform
Advanced tools
Comparing version 0.13.3 to 0.13.4
@@ -144,3 +144,3 @@ /** | ||
*/ | ||
export declare const stream: (body: Stream_.Stream<never, unknown, globalThis.Uint8Array>) => Stream; | ||
export declare const stream: (body: Stream_.Stream<never, unknown, globalThis.Uint8Array>, contentType?: string, contentLength?: number, etag?: string) => Stream; | ||
/** | ||
@@ -153,2 +153,9 @@ * @since 1.0.0 | ||
}) => Effect.Effect<FileSystem.FileSystem, PlatformError.PlatformError, Stream>; | ||
/** | ||
* @since 1.0.0 | ||
* @category constructors | ||
*/ | ||
export declare const fileInfo: (path: string, info: FileSystem.File.Info, options?: FileSystem.StreamOptions & { | ||
readonly contentType?: string; | ||
}) => Effect.Effect<FileSystem.FileSystem, PlatformError.PlatformError, Stream>; | ||
//# sourceMappingURL=Body.d.ts.map |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.unsafeJson = exports.uint8Array = exports.text = exports.stream = exports.raw = exports.jsonSchema = exports.json = exports.formData = exports.file = exports.empty = exports.effect = exports.TypeId = void 0; | ||
exports.unsafeJson = exports.uint8Array = exports.text = exports.stream = exports.raw = exports.jsonSchema = exports.json = exports.formData = exports.fileInfo = exports.file = exports.empty = exports.effect = exports.TypeId = void 0; | ||
var internal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/internal/http/body")); | ||
@@ -82,3 +82,9 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
const file = internal.file; | ||
/** | ||
* @since 1.0.0 | ||
* @category constructors | ||
*/ | ||
exports.file = file; | ||
const fileInfo = internal.fileInfo; | ||
exports.fileInfo = fileInfo; | ||
//# sourceMappingURL=Body.js.map |
@@ -17,5 +17,16 @@ /** | ||
* @since 1.0.0 | ||
* @category type ids | ||
*/ | ||
export declare const TypeId: unique symbol; | ||
/** | ||
* @since 1.0.0 | ||
* @category type ids | ||
*/ | ||
export type TypeId = typeof TypeId; | ||
/** | ||
* @since 1.0.0 | ||
* @category models | ||
*/ | ||
export interface Client<R, E, A> extends Pipeable { | ||
readonly [TypeId]: TypeId; | ||
(request: ClientRequest.ClientRequest): Effect.Effect<R, E, A>; | ||
@@ -22,0 +33,0 @@ } |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.tapRequest = exports.tap = exports.schemaFunction = exports.retry = exports.mapRequestEffect = exports.mapRequest = exports.mapEffect = exports.map = exports.make = exports.layer = exports.filterStatusOk = exports.filterStatus = exports.filterOrFail = exports.filterOrElse = exports.fetchOk = exports.fetch = exports.catchTags = exports.catchTag = exports.catchAll = exports.Client = void 0; | ||
exports.tapRequest = exports.tap = exports.schemaFunction = exports.retry = exports.mapRequestEffect = exports.mapRequest = exports.mapEffect = exports.map = exports.make = exports.layer = exports.filterStatusOk = exports.filterStatus = exports.filterOrFail = exports.filterOrElse = exports.fetchOk = exports.fetch = exports.catchTags = exports.catchTag = exports.catchAll = exports.TypeId = exports.Client = void 0; | ||
var internal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/internal/http/client")); | ||
@@ -13,4 +13,10 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
* @since 1.0.0 | ||
* @category type ids | ||
*/ | ||
const TypeId = internal.TypeId; | ||
/** | ||
* @since 1.0.0 | ||
* @category tags | ||
*/ | ||
exports.TypeId = TypeId; | ||
const Client = internal.tag; | ||
@@ -17,0 +23,0 @@ /** |
@@ -226,3 +226,3 @@ /** | ||
*/ | ||
export declare const transform: (<R, E, R1, E1>(f: (self: Route.Handler<R, E>) => Route.Handler<R1, E1>) => (self: Router<R, E>) => Router<R1, E1>) & (<R_1, E_1, R1_1, E1_1>(self: Router<R_1, E_1>, f: (self: Route.Handler<R_1, E_1>) => Route.Handler<R1_1, E1_1>) => Router<R1_1, E1_1>); | ||
export declare const use: (<R, E, R1, E1>(f: (self: Route.Handler<R, E>) => Route.Handler<R1, E1>) => (self: Router<R, E>) => Router<R1, E1>) & (<R_1, E_1, R1_1, E1_1>(self: Router<R_1, E_1>, f: (self: Route.Handler<R_1, E_1>) => Route.Handler<R1_1, E1_1>) => Router<R1_1, E1_1>); | ||
/** | ||
@@ -229,0 +229,0 @@ * @since 1.0.0 |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.transform = exports.searchParams = exports.schemaParams = 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.searchParams = exports.schemaParams = 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; | ||
var internal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/internal/http/router")); | ||
@@ -153,3 +153,3 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
exports.options = options; | ||
const transform = internal.transform; | ||
const use = internal.use; | ||
/** | ||
@@ -159,3 +159,3 @@ * @since 1.0.0 | ||
*/ | ||
exports.transform = transform; | ||
exports.use = use; | ||
const catchAll = internal.catchAll; | ||
@@ -162,0 +162,0 @@ /** |
@@ -9,2 +9,3 @@ /** | ||
import type * as Body from "@effect/platform/Http/Body"; | ||
import type * as Etag from "@effect/platform/Http/Etag"; | ||
import type * as Headers from "@effect/platform/Http/Headers"; | ||
@@ -144,3 +145,3 @@ import type * as Error from "@effect/platform/Http/ServerError"; | ||
*/ | ||
export declare const file: (path: string, options?: Options & FileSystem.StreamOptions) => Effect.Effect<FileSystem.FileSystem, PlatformError.PlatformError, ServerResponse>; | ||
export declare const file: (path: string, options?: Options & FileSystem.StreamOptions) => Effect.Effect<FileSystem.FileSystem | Etag.Generator, PlatformError.PlatformError, ServerResponse>; | ||
/** | ||
@@ -147,0 +148,0 @@ * @since 1.0.0 |
@@ -6,6 +6,7 @@ "use strict"; | ||
}); | ||
exports.unsafeJson = exports.uint8Array = exports.text = exports.stream = exports.raw = exports.jsonSchema = exports.json = exports.formData = exports.file = exports.empty = exports.effect = exports.TypeId = void 0; | ||
exports.unsafeJson = exports.uint8Array = exports.text = exports.stream = exports.raw = exports.jsonSchema = exports.json = exports.formData = exports.fileInfo = exports.file = exports.empty = exports.effect = exports.TypeId = void 0; | ||
var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Effect")); | ||
var FileSystem = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/FileSystem")); | ||
var Schema = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/schema/Schema")); | ||
var Mime = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("mime/lite")); | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
@@ -78,4 +79,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
exports.jsonSchema = jsonSchema; | ||
const file = (path, options) => Effect.flatMap(FileSystem.FileSystem, fs => Effect.map(fs.stat(path), stat => stream(fs.stream(path, options), options?.contentType, Number(stat.size)))); | ||
const file = (path, options) => Effect.flatMap(FileSystem.FileSystem, fs => Effect.map(fs.stat(path), info => stream(fs.stream(path, options), options?.contentType ?? Mime.getType(path) ?? undefined, Number(info.size)))); | ||
/** @internal */ | ||
exports.file = file; | ||
const fileInfo = (path, info, options) => Effect.map(FileSystem.FileSystem, fs => stream(fs.stream(path, options), options?.contentType ?? Mime.getType(path) ?? undefined, Number(info.size))); | ||
exports.fileInfo = fileInfo; | ||
class FormDataImpl { | ||
@@ -82,0 +86,0 @@ constructor(formData) { |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.tapRequest = exports.tap = exports.tag = exports.schemaFunction = exports.retry = exports.mapRequestEffect = exports.mapRequest = exports.mapEffect = exports.map = exports.make = exports.layer = exports.filterStatusOk = exports.filterStatus = exports.filterOrFail = exports.filterOrElse = exports.fetchOk = exports.fetch = exports.catchTags = exports.catchTag = exports.catchAll = void 0; | ||
exports.tapRequest = exports.tap = exports.tag = exports.schemaFunction = exports.retry = exports.mapRequestEffect = exports.mapRequest = exports.mapEffect = exports.map = exports.make = exports.layer = exports.filterStatusOk = exports.filterStatus = exports.filterOrFail = exports.filterOrElse = exports.fetchOk = exports.fetch = exports.catchTags = exports.catchTag = exports.catchAll = exports.TypeId = void 0; | ||
var Context = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Context")); | ||
@@ -24,5 +24,9 @@ var _Function = /*#__PURE__*/require("@effect/data/Function"); | ||
/** @internal */ | ||
const tag = /*#__PURE__*/Context.Tag("@effect/platform/Http/Client"); | ||
const TypeId = /*#__PURE__*/Symbol.for("@effect/platform/Http/Client"); | ||
/** @internal */ | ||
exports.TypeId = TypeId; | ||
const tag = /*#__PURE__*/Context.Tag(TypeId); | ||
exports.tag = tag; | ||
const clientProto = { | ||
[TypeId]: TypeId, | ||
pipe() { | ||
@@ -29,0 +33,0 @@ return (0, _Pipeable.pipeArguments)(this, arguments); |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.transform = exports.searchParams = exports.schemaParams = 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.searchParams = exports.schemaParams = 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; | ||
var Chunk = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Chunk")); | ||
@@ -190,21 +190,21 @@ var Context = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Context")); | ||
exports.options = options; | ||
const transform = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => new RouterImpl(Chunk.map(self.routes, route => new RouteImpl(route.method, route.path, f(route.handler), route.prefix)), Chunk.map(self.mounts, ([path, app]) => [path, f(app)]))); | ||
const use = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => new RouterImpl(Chunk.map(self.routes, route => new RouteImpl(route.method, route.path, f(route.handler), route.prefix)), Chunk.map(self.mounts, ([path, app]) => [path, f(app)]))); | ||
/** @internal */ | ||
exports.transform = transform; | ||
const catchAll = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => transform(self, Effect.catchAll(f))); | ||
exports.use = use; | ||
const catchAll = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => use(self, Effect.catchAll(f))); | ||
/** @internal */ | ||
exports.catchAll = catchAll; | ||
const catchAllCause = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => transform(self, Effect.catchAllCause(f))); | ||
const catchAllCause = /*#__PURE__*/(0, _Function.dual)(2, (self, f) => use(self, Effect.catchAllCause(f))); | ||
/** @internal */ | ||
exports.catchAllCause = catchAllCause; | ||
const catchTag = /*#__PURE__*/(0, _Function.dual)(3, (self, k, f) => transform(self, Effect.catchTag(k, f))); | ||
const catchTag = /*#__PURE__*/(0, _Function.dual)(3, (self, k, f) => use(self, Effect.catchTag(k, f))); | ||
/** @internal */ | ||
exports.catchTag = catchTag; | ||
const catchTags = /*#__PURE__*/(0, _Function.dual)(2, (self, cases) => transform(self, Effect.catchTags(cases))); | ||
const catchTags = /*#__PURE__*/(0, _Function.dual)(2, (self, cases) => use(self, Effect.catchTags(cases))); | ||
exports.catchTags = catchTags; | ||
const provideService = /*#__PURE__*/(0, _Function.dual)(3, (self, tag, service) => transform(self, Effect.provideService(tag, service))); | ||
const provideService = /*#__PURE__*/(0, _Function.dual)(3, (self, tag, service) => use(self, Effect.provideService(tag, service))); | ||
/* @internal */ | ||
exports.provideService = provideService; | ||
const provideServiceEffect = /*#__PURE__*/(0, _Function.dual)(3, (self, tag, effect) => transform(self, Effect.provideServiceEffect(tag, effect))); | ||
const provideServiceEffect = /*#__PURE__*/(0, _Function.dual)(3, (self, tag, effect) => use(self, Effect.provideServiceEffect(tag, effect))); | ||
exports.provideServiceEffect = provideServiceEffect; | ||
//# sourceMappingURL=router.js.map |
@@ -16,3 +16,3 @@ "use strict"; | ||
exports.TypeId = TypeId; | ||
const serverTag = /*#__PURE__*/Context.Tag("@effect/platform/Http/Server"); | ||
const serverTag = /*#__PURE__*/Context.Tag(TypeId); | ||
exports.serverTag = serverTag; | ||
@@ -19,0 +19,0 @@ const serverProto = { |
@@ -10,2 +10,4 @@ "use strict"; | ||
var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Effect")); | ||
var FileSystem = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/FileSystem")); | ||
var Etag = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/Http/Etag")); | ||
var Headers = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/Http/Headers")); | ||
@@ -79,3 +81,20 @@ var ServerRequest = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/Http/ServerRequest")); | ||
exports.schemaJson = schemaJson; | ||
const file = (path, options) => Effect.map(internalBody.file(path, options), body => new ServerResponseImpl(options?.status ?? 200, options?.statusText, options?.headers ?? Headers.empty, body)); | ||
const file = (path, options) => Effect.map(({ | ||
body, | ||
etag, | ||
info | ||
}) => { | ||
const headers = { | ||
...(options?.headers ?? {}), | ||
etag: Etag.toString(etag) | ||
}; | ||
if (info.mtime._tag === "Some") { | ||
headers["last-modified"] = info.mtime.value.toUTCString(); | ||
} | ||
return new ServerResponseImpl(options?.status ?? 200, options?.statusText, headers, body); | ||
})(Effect.bind("body", ({ | ||
info | ||
}) => internalBody.fileInfo(path, info, options))(Effect.bind("etag", ({ | ||
info | ||
}) => Effect.flatMap(Etag.Generator, generator => generator.fromFileInfo(info)))(Effect.bindTo(Effect.flatMap(FileSystem.FileSystem, fs => fs.stat(path)), "info")))); | ||
/** @internal */ | ||
@@ -82,0 +101,0 @@ exports.file = file; |
{ | ||
"name": "@effect/platform", | ||
"version": "0.13.3", | ||
"version": "0.13.4", | ||
"description": "Unified interfaces for common platform-specific services", | ||
@@ -29,2 +29,3 @@ "license": "MIT", | ||
"find-my-way": "^7.6.2", | ||
"mime": "^3.0.0", | ||
"path-browserify": "^1.0.1" | ||
@@ -31,0 +32,0 @@ }, |
@@ -166,3 +166,8 @@ /** | ||
*/ | ||
export const stream: (body: Stream_.Stream<never, unknown, globalThis.Uint8Array>) => Stream = internal.stream | ||
export const stream: ( | ||
body: Stream_.Stream<never, unknown, globalThis.Uint8Array>, | ||
contentType?: string, | ||
contentLength?: number, | ||
etag?: string | ||
) => Stream = internal.stream | ||
@@ -177,1 +182,11 @@ /** | ||
) => Effect.Effect<FileSystem.FileSystem, PlatformError.PlatformError, Stream> = internal.file | ||
/** | ||
* @since 1.0.0 | ||
* @category constructors | ||
*/ | ||
export const fileInfo: ( | ||
path: string, | ||
info: FileSystem.File.Info, | ||
options?: FileSystem.StreamOptions & { readonly contentType?: string } | ||
) => Effect.Effect<FileSystem.FileSystem, PlatformError.PlatformError, Stream> = internal.fileInfo |
@@ -19,5 +19,18 @@ /** | ||
* @since 1.0.0 | ||
* @category type ids | ||
*/ | ||
export const TypeId: unique symbol = internal.TypeId | ||
/** | ||
* @since 1.0.0 | ||
* @category type ids | ||
*/ | ||
export type TypeId = typeof TypeId | ||
/** | ||
* @since 1.0.0 | ||
* @category models | ||
*/ | ||
export interface Client<R, E, A> extends Pipeable { | ||
readonly [TypeId]: TypeId | ||
(request: ClientRequest.ClientRequest): Effect.Effect<R, E, A> | ||
@@ -24,0 +37,0 @@ } |
@@ -349,3 +349,3 @@ /** | ||
*/ | ||
export const transform = internal.transform | ||
export const use = internal.use | ||
@@ -357,4 +357,9 @@ /** | ||
export const catchAll: { | ||
<E, R2, E2>(f: (e: E) => Route.Handler<R2, E2>): <R>(self: Router<R, E>) => Router<R2 | R, E2> | ||
<R, E, R2, E2>(self: Router<R, E>, f: (e: E) => Route.Handler<R2, E2>): Router<R | R2, E2> | ||
<E, R2, E2>(f: (e: E) => Route.Handler<R2, E2>): <R>( | ||
self: Router<R, E> | ||
) => Router<R2 | R, E2> | ||
<R, E, R2, E2>( | ||
self: Router<R, E>, | ||
f: (e: E) => Route.Handler<R2, E2> | ||
): Router<R | R2, E2> | ||
} = internal.catchAll | ||
@@ -367,4 +372,9 @@ | ||
export const catchAllCause: { | ||
<E, R2, E2>(f: (e: Cause.Cause<E>) => Route.Handler<R2, E2>): <R>(self: Router<R, E>) => Router<R2 | R, E2> | ||
<R, E, R2, E2>(self: Router<R, E>, f: (e: Cause.Cause<E>) => Route.Handler<R2, E2>): Router<R | R2, E2> | ||
<E, R2, E2>(f: (e: Cause.Cause<E>) => Route.Handler<R2, E2>): <R>( | ||
self: Router<R, E> | ||
) => Router<R2 | R, E2> | ||
<R, E, R2, E2>( | ||
self: Router<R, E>, | ||
f: (e: Cause.Cause<E>) => Route.Handler<R2, E2> | ||
): Router<R | R2, E2> | ||
} = internal.catchAllCause | ||
@@ -395,17 +405,24 @@ | ||
E, | ||
Cases extends E extends { _tag: string } | ||
? { [K in E["_tag"]]+?: ((error: Extract<E, { _tag: K }>) => Route.Handler<any, any>) | undefined } | ||
Cases extends E extends { _tag: string } ? { | ||
[K in E["_tag"]]+?: | ||
| ((error: Extract<E, { _tag: K }>) => Route.Handler<any, any>) | ||
| undefined | ||
} | ||
: {} | ||
>( | ||
cases: Cases | ||
): <R>( | ||
self: Router<R, E> | ||
) => Router< | ||
): <R>(self: Router<R, E>) => Router< | ||
| R | ||
| { | ||
[K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect.Effect<infer R, any, any> ? R : never | ||
[K in keyof Cases]: Cases[K] extends ( | ||
...args: Array<any> | ||
) => Effect.Effect<infer R, any, any> ? R | ||
: never | ||
}[keyof Cases], | ||
| Exclude<E, { _tag: keyof Cases }> | ||
| { | ||
[K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect.Effect<any, infer E, any> ? E : never | ||
[K in keyof Cases]: Cases[K] extends ( | ||
...args: Array<any> | ||
) => Effect.Effect<any, infer E, any> ? E | ||
: never | ||
}[keyof Cases] | ||
@@ -416,5 +433,8 @@ > | ||
E, | ||
Cases extends E extends { _tag: string } | ||
? { [K in E["_tag"]]+?: ((error: Extract<E, { _tag: K }>) => Route.Handler<any, any>) | undefined } : | ||
{} | ||
Cases extends E extends { _tag: string } ? { | ||
[K in E["_tag"]]+?: | ||
| ((error: Extract<E, { _tag: K }>) => Route.Handler<any, any>) | ||
| undefined | ||
} | ||
: {} | ||
>( | ||
@@ -426,7 +446,13 @@ self: Router<R, E>, | ||
| { | ||
[K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect.Effect<infer R, any, any> ? R : never | ||
[K in keyof Cases]: Cases[K] extends ( | ||
...args: Array<any> | ||
) => Effect.Effect<infer R, any, any> ? R | ||
: never | ||
}[keyof Cases], | ||
| Exclude<E, { _tag: keyof Cases }> | ||
| { | ||
[K in keyof Cases]: Cases[K] extends (...args: Array<any>) => Effect.Effect<any, infer E, any> ? E : never | ||
[K in keyof Cases]: Cases[K] extends ( | ||
...args: Array<any> | ||
) => Effect.Effect<any, infer E, any> ? E | ||
: never | ||
}[keyof Cases] | ||
@@ -441,6 +467,8 @@ > | ||
export const provideService: { | ||
<T extends Context.Tag<any, any>>( | ||
tag: T, | ||
service: Context.Tag.Service<T> | ||
): <R, E>(self: Router<R, E>) => Router<Exclude<R, Context.Tag.Identifier<T>>, E> | ||
<T extends Context.Tag<any, any>>(tag: T, service: Context.Tag.Service<T>): < | ||
R, | ||
E | ||
>( | ||
self: Router<R, E> | ||
) => Router<Exclude<R, Context.Tag.Identifier<T>>, E> | ||
<R, E, T extends Context.Tag<any, any>>( | ||
@@ -461,3 +489,5 @@ self: Router<R, E>, | ||
effect: Effect.Effect<R1, E1, Context.Tag.Service<T>> | ||
): <R, E>(self: Router<R, E>) => Router<R1 | Exclude<R, Context.Tag.Identifier<T>>, E1 | E> | ||
): <R, E>( | ||
self: Router<R, E> | ||
) => Router<R1 | Exclude<R, Context.Tag.Identifier<T>>, E1 | E> | ||
<R, E, T extends Context.Tag<any, any>, R1, E1>( | ||
@@ -464,0 +494,0 @@ self: Router<R, E>, |
@@ -9,2 +9,3 @@ /** | ||
import type * as Body from "@effect/platform/Http/Body" | ||
import type * as Etag from "@effect/platform/Http/Etag" | ||
import type * as Headers from "@effect/platform/Http/Headers" | ||
@@ -176,3 +177,3 @@ import type * as Error from "@effect/platform/Http/ServerError" | ||
options?: Options & FileSystem.StreamOptions | ||
) => Effect.Effect<FileSystem.FileSystem, PlatformError.PlatformError, ServerResponse> = internal.file | ||
) => Effect.Effect<FileSystem.FileSystem | Etag.Generator, PlatformError.PlatformError, ServerResponse> = internal.file | ||
@@ -179,0 +180,0 @@ /** |
@@ -7,2 +7,3 @@ import * as Effect from "@effect/io/Effect" | ||
import type * as Stream_ from "@effect/stream/Stream" | ||
import * as Mime from "mime/lite" | ||
@@ -104,5 +105,23 @@ /** @internal */ | ||
(fs) => | ||
Effect.map( | ||
fs.stat(path), | ||
(stat) => stream(fs.stream(path, options), options?.contentType, Number(stat.size)) | ||
Effect.map(fs.stat(path), (info) => | ||
stream( | ||
fs.stream(path, options), | ||
options?.contentType ?? Mime.getType(path) ?? undefined, | ||
Number(info.size) | ||
)) | ||
) | ||
/** @internal */ | ||
export const fileInfo = ( | ||
path: string, | ||
info: FileSystem.File.Info, | ||
options?: FileSystem.StreamOptions & { readonly contentType?: string } | ||
): Effect.Effect<FileSystem.FileSystem, PlatformError.PlatformError, Body.Stream> => | ||
Effect.map( | ||
FileSystem.FileSystem, | ||
(fs) => | ||
stream( | ||
fs.stream(path, options), | ||
options?.contentType ?? Mime.getType(path) ?? undefined, | ||
Number(info.size) | ||
) | ||
@@ -109,0 +128,0 @@ ) |
@@ -24,5 +24,9 @@ import * as Context from "@effect/data/Context" | ||
/** @internal */ | ||
export const tag = Context.Tag<Client.Client.Default>("@effect/platform/Http/Client") | ||
export const TypeId: Client.TypeId = Symbol.for("@effect/platform/Http/Client") as Client.TypeId | ||
/** @internal */ | ||
export const tag = Context.Tag<Client.Client.Default>(TypeId) | ||
const clientProto = { | ||
[TypeId]: TypeId, | ||
pipe() { | ||
@@ -29,0 +33,0 @@ return pipeArguments(this, arguments) |
@@ -308,3 +308,3 @@ import * as Chunk from "@effect/data/Chunk" | ||
/** @internal */ | ||
export const transform = dual< | ||
export const use = dual< | ||
<R, E, R1, E1>( | ||
@@ -338,3 +338,3 @@ f: (self: Router.Route.Handler<R, E>) => Router.Route.Handler<R1, E1> | ||
) => Router.Router<R2 | R, E2> | ||
>(2, (self, f) => transform(self, Effect.catchAll(f))) | ||
>(2, (self, f) => use(self, Effect.catchAll(f))) | ||
@@ -350,3 +350,3 @@ /** @internal */ | ||
) => Router.Router<R2 | R, E2> | ||
>(2, (self, f) => transform(self, Effect.catchAllCause(f))) | ||
>(2, (self, f) => use(self, Effect.catchAllCause(f))) | ||
@@ -364,3 +364,3 @@ /** @internal */ | ||
) => Router.Router<R | R1, Exclude<E, { _tag: K }> | E1> | ||
>(3, (self, k, f) => transform(self, Effect.catchTag(k, f))) | ||
>(3, (self, k, f) => use(self, Effect.catchTag(k, f))) | ||
@@ -407,3 +407,3 @@ /** @internal */ | ||
> | ||
} = dual(2, (self: Router.Router<any, any>, cases: {}) => transform(self, Effect.catchTags(cases))) | ||
} = dual(2, (self: Router.Router<any, any>, cases: {}) => use(self, Effect.catchTags(cases))) | ||
@@ -420,3 +420,3 @@ export const provideService = dual< | ||
) => Router.Router<Exclude<R, Context.Tag.Identifier<T>>, E> | ||
>(3, (self, tag, service) => transform(self, Effect.provideService(tag, service))) | ||
>(3, (self, tag, service) => use(self, Effect.provideService(tag, service))) | ||
@@ -438,2 +438,2 @@ /* @internal */ | ||
effect: Effect.Effect<R1, E1, Context.Tag.Service<T>> | ||
) => transform(self, Effect.provideServiceEffect(tag, effect))) | ||
) => use(self, Effect.provideServiceEffect(tag, effect))) |
@@ -15,3 +15,3 @@ import * as Context from "@effect/data/Context" | ||
/** @internal */ | ||
export const serverTag = Context.Tag<Server.Server>("@effect/platform/Http/Server") | ||
export const serverTag = Context.Tag<Server.Server>(TypeId) | ||
@@ -18,0 +18,0 @@ const serverProto = { |
@@ -1,7 +0,8 @@ | ||
import { dual } from "@effect/data/Function" | ||
import { dual, pipe } from "@effect/data/Function" | ||
import { pipeArguments } from "@effect/data/Pipeable" | ||
import * as Effect from "@effect/io/Effect" | ||
import type * as PlatformError from "@effect/platform/Error" | ||
import type * as FileSystem from "@effect/platform/FileSystem" | ||
import * as FileSystem from "@effect/platform/FileSystem" | ||
import type * as Body from "@effect/platform/Http/Body" | ||
import * as Etag from "@effect/platform/Http/Etag" | ||
import * as Headers from "@effect/platform/Http/Headers" | ||
@@ -144,10 +145,31 @@ import type * as Error from "@effect/platform/Http/ServerError" | ||
options?: ServerResponse.Options & FileSystem.StreamOptions | ||
): Effect.Effect<FileSystem.FileSystem, PlatformError.PlatformError, ServerResponse.ServerResponse> => | ||
Effect.map(internalBody.file(path, options), (body) => | ||
new ServerResponseImpl( | ||
options?.status ?? 200, | ||
options?.statusText, | ||
options?.headers ?? Headers.empty, | ||
body | ||
)) | ||
): Effect.Effect< | ||
FileSystem.FileSystem | Etag.Generator, | ||
PlatformError.PlatformError, | ||
ServerResponse.ServerResponse | ||
> => | ||
pipe( | ||
Effect.bindTo(Effect.flatMap(FileSystem.FileSystem, (fs) => fs.stat(path)), "info"), | ||
Effect.bind("etag", ({ info }) => | ||
Effect.flatMap( | ||
Etag.Generator, | ||
(generator) => generator.fromFileInfo(info) | ||
)), | ||
Effect.bind("body", ({ info }) => internalBody.fileInfo(path, info, options)), | ||
Effect.map(({ body, etag, info }) => { | ||
const headers: Record<string, string> = { | ||
...(options?.headers ?? {}), | ||
etag: Etag.toString(etag) | ||
} | ||
if (info.mtime._tag === "Some") { | ||
headers["last-modified"] = info.mtime.value.toUTCString() | ||
} | ||
return new ServerResponseImpl( | ||
options?.status ?? 200, | ||
options?.statusText, | ||
headers, | ||
body | ||
) | ||
}) | ||
) | ||
@@ -154,0 +176,0 @@ /** @internal */ |
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
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
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
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
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
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
930656
329
16031
7
+ Addedmime@^3.0.0
+ Addedmime@3.0.0(transitive)