Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@effect/platform

Package Overview
Dependencies
Maintainers
3
Versions
399
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@effect/platform - npm Package Compare versions

Comparing version 0.13.9 to 0.13.10

61

Http/Body.d.ts
/**
* @since 1.0.0
*/
import type * as Data from "@effect/data/Data";
import type * as Effect from "@effect/io/Effect";
import type * as PlatformError from "@effect/platform/Error";
import type * as FileSystem from "@effect/platform/FileSystem";
import type * as ParseResult from "@effect/schema/ParseResult";
import type * as Schema from "@effect/schema/Schema";

@@ -23,11 +25,6 @@ import type * as Stream_ from "@effect/stream/Stream";

*/
export type Body = Empty | Raw | Uint8Array | EffectBody | FormData | Stream;
export type Body = Empty | Raw | Uint8Array | FormData | Stream;
/**
* @since 1.0.0
* @category models
*/
export type NonEffect = Exclude<Body, EffectBody>;
/**
* @since 1.0.0
*/
export declare namespace Body {

@@ -47,2 +44,37 @@ /**

* @since 1.0.0
* @category type ids
*/
export declare const ErrorTypeId: unique symbol;
/**
* @since 1.0.0
* @category type ids
*/
export type ErrorTypeId = typeof ErrorTypeId;
/**
* @since 1.0.0
* @category errors
*/
export interface BodyError extends Data.Case {
readonly [ErrorTypeId]: ErrorTypeId;
readonly _tag: "BodyError";
readonly reason: BodyErrorReason;
}
/**
* @since 1.0.0
* @category errors
*/
export declare const BodyError: (reason: BodyErrorReason) => BodyError;
/**
* @since 1.0.0
* @category errors
*/
export type BodyErrorReason = {
readonly _tag: "JsonError";
readonly error: unknown;
} | {
readonly _tag: "SchemaError";
readonly error: ParseResult.ParseError;
};
/**
* @since 1.0.0
* @category models

@@ -93,17 +125,4 @@ */

* @since 1.0.0
* @category models
*/
export interface EffectBody extends Body.Proto {
readonly _tag: "Effect";
readonly effect: Effect.Effect<never, unknown, NonEffect>;
}
/**
* @since 1.0.0
* @category constructors
*/
export declare const effect: (body: Effect.Effect<never, unknown, NonEffect>) => EffectBody;
/**
* @since 1.0.0
* @category constructors
*/
export declare const unsafeJson: (body: unknown) => Uint8Array;

@@ -114,3 +133,3 @@ /**

*/
export declare const json: (body: unknown) => EffectBody;
export declare const json: (body: unknown) => Effect.Effect<never, BodyError, Uint8Array>;
/**

@@ -120,3 +139,3 @@ * @since 1.0.0

*/
export declare const jsonSchema: <I, A>(schema: Schema.Schema<I, A>) => (body: A) => EffectBody;
export declare const jsonSchema: <I, A>(schema: Schema.Schema<I, A>) => (body: A) => Effect.Effect<never, BodyError, Uint8Array>;
/**

@@ -123,0 +142,0 @@ * @since 1.0.0

@@ -6,3 +6,3 @@ "use strict";

});
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;
exports.unsafeJson = exports.uint8Array = exports.text = exports.stream = exports.raw = exports.jsonSchema = exports.json = exports.formData = exports.fileInfo = exports.file = exports.empty = exports.TypeId = exports.ErrorTypeId = exports.BodyError = void 0;
var internal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/internal/http/body"));

@@ -18,5 +18,17 @@ 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
*/
exports.TypeId = TypeId;
const ErrorTypeId = internal.ErrorTypeId;
/**
* @since 1.0.0
* @category errors
*/
exports.ErrorTypeId = ErrorTypeId;
const BodyError = internal.BodyError;
/**
* @since 1.0.0
* @category constructors
*/
exports.TypeId = TypeId;
exports.BodyError = BodyError;
const empty = internal.empty;

@@ -46,8 +58,2 @@ /**

exports.text = text;
const effect = internal.effect;
/**
* @since 1.0.0
* @category constructors
*/
exports.effect = effect;
const unsafeJson = internal.unsafeJson;

@@ -54,0 +60,0 @@ /**

@@ -165,3 +165,3 @@ /**

*/
export declare const make: (f: (request: ClientRequest.ClientRequest.NonEffectBody) => Effect.Effect<never, Error.HttpClientError, ClientResponse.ClientResponse>) => Client.Default;
export declare const make: (f: (request: ClientRequest.ClientRequest) => Effect.Effect<never, Error.HttpClientError, ClientResponse.ClientResponse>) => Client.Default;
/**

@@ -168,0 +168,0 @@ * @since 1.0.0

@@ -39,14 +39,2 @@ /**

* @since 1.0.0
*/
export declare namespace ClientRequest {
/**
* @since 1.0.0
* @category models
*/
interface NonEffectBody extends ClientRequest {
readonly body: Body.NonEffect;
}
}
/**
* @since 1.0.0
* @category models

@@ -256,10 +244,2 @@ */

*/
export declare const effectBody: {
(body: Effect.Effect<never, unknown, Body.NonEffect>): (self: ClientRequest) => ClientRequest;
(self: ClientRequest, body: Effect.Effect<never, unknown, Body.NonEffect>): ClientRequest;
};
/**
* @since 1.0.0
* @category combinators
*/
export declare const textBody: {

@@ -274,4 +254,4 @@ (body: string, contentType?: string): (self: ClientRequest) => ClientRequest;

export declare const jsonBody: {
(body: unknown): (self: ClientRequest) => ClientRequest;
(self: ClientRequest, body: unknown): ClientRequest;
(body: unknown): (self: ClientRequest) => Effect.Effect<never, Body.BodyError, ClientRequest>;
(self: ClientRequest, body: unknown): Effect.Effect<never, Body.BodyError, ClientRequest>;
};

@@ -291,4 +271,4 @@ /**

export declare const schemaBody: <I, A>(schema: Schema.Schema<I, A>) => {
(body: A): (self: ClientRequest) => ClientRequest;
(self: ClientRequest, body: A): ClientRequest;
(body: A): (self: ClientRequest) => Effect.Effect<never, Body.BodyError, ClientRequest>;
(self: ClientRequest, body: A): Effect.Effect<never, Body.BodyError, ClientRequest>;
};

@@ -295,0 +275,0 @@ /**

@@ -6,3 +6,3 @@ "use strict";

});
exports.urlParamsBody = exports.updateUrl = exports.unsafeJsonBody = exports.uint8ArrayBody = exports.textBody = exports.streamBody = exports.setUrlParams = exports.setUrlParam = exports.setUrl = exports.setMethod = exports.setHeaders = exports.setHeader = exports.setBody = exports.schemaBody = exports.put = exports.prependUrl = exports.post = exports.patch = exports.options = exports.modify = exports.make = exports.jsonBody = exports.head = exports.get = exports.formDataBody = exports.fileBody = exports.effectBody = exports.del = exports.bearerToken = exports.basicAuth = exports.appendUrlParams = exports.appendUrlParam = exports.appendUrl = exports.acceptJson = exports.accept = exports.TypeId = void 0;
exports.urlParamsBody = exports.updateUrl = exports.unsafeJsonBody = exports.uint8ArrayBody = exports.textBody = exports.streamBody = exports.setUrlParams = exports.setUrlParam = exports.setUrl = exports.setMethod = exports.setHeaders = exports.setHeader = exports.setBody = exports.schemaBody = exports.put = exports.prependUrl = exports.post = exports.patch = exports.options = exports.modify = exports.make = exports.jsonBody = exports.head = exports.get = exports.formDataBody = exports.fileBody = exports.del = exports.bearerToken = exports.basicAuth = exports.appendUrlParams = exports.appendUrlParam = exports.appendUrl = exports.acceptJson = exports.accept = exports.TypeId = void 0;
var internal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/internal/http/clientRequest"));

@@ -177,8 +177,2 @@ 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.uint8ArrayBody = uint8ArrayBody;
const effectBody = internal.effectBody;
/**
* @since 1.0.0
* @category combinators
*/
exports.effectBody = effectBody;
const textBody = internal.textBody;

@@ -185,0 +179,0 @@ /**

@@ -11,4 +11,2 @@ /**

import type * as Headers from "@effect/platform/Http/Headers";
import type * as Error from "@effect/platform/Http/ServerError";
import type * as ServerRequest from "@effect/platform/Http/ServerRequest";
import type * as UrlParams from "@effect/platform/Http/UrlParams";

@@ -40,14 +38,2 @@ import type * as Schema from "@effect/schema/Schema";

* @since 1.0.0
*/
export declare namespace ServerResponse {
/**
* @since 1.0.0
* @category models
*/
interface NonEffectBody extends ServerResponse {
readonly body: Body.NonEffect;
}
}
/**
* @since 1.0.0
* @category models

@@ -85,6 +71,2 @@ */

* @since 1.0.0
*/
export declare const toNonEffectBody: (self: ServerResponse) => Effect.Effect<ServerRequest.ServerRequest, Error.ResponseError, ServerResponse.NonEffectBody>;
/**
* @since 1.0.0
* @category constructors

@@ -107,3 +89,3 @@ */

*/
export declare const json: (body: unknown, options?: Options.WithContent) => ServerResponse;
export declare const json: (body: unknown, options?: Options.WithContent) => Effect.Effect<never, Body.BodyError, ServerResponse>;
/**

@@ -113,3 +95,3 @@ * @since 1.0.0

*/
export declare const schemaJson: <I, A>(schema: Schema.Schema<I, A>) => (body: A, options?: Options.WithContent) => ServerResponse;
export declare const schemaJson: <I, A>(schema: Schema.Schema<I, A>) => (body: A, options?: Options.WithContent) => Effect.Effect<never, Body.BodyError, ServerResponse>;
/**

@@ -129,7 +111,2 @@ * @since 1.0.0

*/
export declare const effect: (body: Effect.Effect<never, unknown, Body.NonEffect>, options?: Options.WithContent) => ServerResponse;
/**
* @since 1.0.0
* @category constructors
*/
export declare const raw: (body: unknown, options?: Options) => ServerResponse;

@@ -136,0 +113,0 @@ /**

@@ -6,3 +6,3 @@ "use strict";

});
exports.urlParams = exports.unsafeJson = exports.uint8Array = exports.toNonEffectBody = exports.text = exports.stream = exports.setHeaders = exports.setHeader = exports.setBody = exports.schemaJson = exports.raw = exports.json = exports.isServerResponse = exports.formData = exports.file = exports.empty = exports.effect = exports.TypeId = void 0;
exports.urlParams = exports.unsafeJson = exports.uint8Array = exports.text = exports.stream = exports.setHeaders = exports.setHeader = exports.setBody = exports.schemaJson = exports.raw = exports.json = exports.isServerResponse = exports.formData = exports.file = exports.empty = exports.TypeId = void 0;
var internal = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/internal/http/serverResponse"));

@@ -23,10 +23,5 @@ 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 constructors
*/
exports.isServerResponse = isServerResponse;
const toNonEffectBody = internal.toNonEffectBody;
/**
* @since 1.0.0
* @category constructors
*/
exports.toNonEffectBody = toNonEffectBody;
const empty = internal.empty;

@@ -74,8 +69,2 @@ /**

exports.urlParams = urlParams;
const effect = internal.effect;
/**
* @since 1.0.0
* @category constructors
*/
exports.effect = effect;
const raw = internal.raw;

@@ -82,0 +71,0 @@ /**

@@ -6,3 +6,4 @@ "use strict";

});
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;
exports.unsafeJson = exports.uint8Array = exports.text = exports.stream = exports.raw = exports.jsonSchema = exports.json = exports.formData = exports.fileInfo = exports.file = exports.empty = exports.TypeId = exports.ErrorTypeId = exports.BodyError = void 0;
var Data = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Data"));
var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Effect"));

@@ -15,3 +16,13 @@ var FileSystem = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/FileSystem"));

const TypeId = /*#__PURE__*/Symbol.for("@effect/platform/Http/Body");
/** @internal */
exports.TypeId = TypeId;
const ErrorTypeId = /*#__PURE__*/Symbol.for("@effect/platform/Http/Body/BodyError");
exports.ErrorTypeId = ErrorTypeId;
const bodyError = /*#__PURE__*/Data.tagged("BodyError");
/** @internal */
const BodyError = reason => bodyError({
[ErrorTypeId]: ErrorTypeId,
reason
});
exports.BodyError = BodyError;
class EmptyImpl {

@@ -54,19 +65,14 @@ constructor() {

const text = (body, contentType) => uint8Array(new TextEncoder().encode(body), contentType ?? "text/plain");
/** @internal */
exports.text = text;
class EffectBodyImpl {
constructor(effect, contentType) {
this.effect = effect;
this.contentType = contentType;
this._tag = "Effect";
this[TypeId] = TypeId;
}
}
/** @internal */
const effect = body => new EffectBodyImpl(body);
/** @internal */
exports.effect = effect;
const unsafeJson = body => uint8Array(new TextEncoder().encode(JSON.stringify(body)), "application/json");
/** @internal */
exports.unsafeJson = unsafeJson;
const json = body => effect(Effect.try(() => unsafeJson(body)));
const json = body => Effect.try({
try: () => unsafeJson(body),
catch: error => BodyError({
_tag: "JsonError",
error
})
});
/** @internal */

@@ -76,3 +82,6 @@ exports.json = json;

const encode = Schema.encode(schema);
return body => effect(Effect.flatMap(encode(body), json => Effect.try(() => unsafeJson(json))));
return body => Effect.flatMap(Effect.mapError(encode(body), error => BodyError({
_tag: "SchemaError",
error
})), json);
};

@@ -79,0 +88,0 @@ /** @internal */

@@ -39,8 +39,3 @@ "use strict";

/** @internal */
const make = f => {
function client(request) {
return Effect.flatMap(internalRequest.resolveBody(request), request => f(request));
}
return setProto(client);
};
const make = f => setProto(f);
/** @internal */

@@ -47,0 +42,0 @@ exports.make = make;

@@ -6,3 +6,3 @@ "use strict";

});
exports.urlParamsBody = exports.updateUrl = exports.unsafeJsonBody = exports.uint8ArrayBody = exports.textBody = exports.streamBody = exports.setUrlParams = exports.setUrlParam = exports.setUrl = exports.setMethod = exports.setHeaders = exports.setHeader = exports.setBody = exports.schemaBody = exports.resolveBody = exports.put = exports.prependUrl = exports.post = exports.patch = exports.options = exports.modify = exports.make = exports.jsonBody = exports.isClientRequest = exports.head = exports.get = exports.formDataBody = exports.fileBody = exports.empty = exports.effectBody = exports.del = exports.bearerToken = exports.basicAuth = exports.appendUrlParams = exports.appendUrlParam = exports.appendUrl = exports.acceptJson = exports.accept = exports.TypeId = void 0;
exports.urlParamsBody = exports.updateUrl = exports.unsafeJsonBody = exports.uint8ArrayBody = exports.textBody = exports.streamBody = exports.setUrlParams = exports.setUrlParam = exports.setUrl = exports.setMethod = exports.setHeaders = exports.setHeader = exports.setBody = exports.schemaBody = exports.put = exports.prependUrl = exports.post = exports.patch = exports.options = exports.modify = exports.make = exports.jsonBody = exports.isClientRequest = exports.head = exports.get = exports.formDataBody = exports.fileBody = exports.empty = exports.del = exports.bearerToken = exports.basicAuth = exports.appendUrlParams = exports.appendUrlParam = exports.appendUrl = exports.acceptJson = exports.accept = exports.TypeId = void 0;
var _Function = /*#__PURE__*/require("@effect/data/Function");

@@ -14,3 +14,2 @@ var _Pipeable = /*#__PURE__*/require("@effect/data/Pipeable");

var internalBody = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/internal/http/body"));
var internalError = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/internal/http/clientError"));
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); }

@@ -162,9 +161,6 @@ 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.uint8ArrayBody = uint8ArrayBody;
const effectBody = /*#__PURE__*/(0, _Function.dual)(2, (self, body) => setBody(self, internalBody.effect(body)));
/** @internal */
exports.effectBody = effectBody;
const textBody = /*#__PURE__*/(0, _Function.dual)(args => isClientRequest(args[0]), (self, body, contentType = "text/plain") => setBody(self, internalBody.text(body, contentType)));
/** @internal */
exports.textBody = textBody;
const jsonBody = /*#__PURE__*/(0, _Function.dual)(2, (self, body) => setBody(self, internalBody.json(body)));
const jsonBody = /*#__PURE__*/(0, _Function.dual)(2, (self, body) => Effect.map(internalBody.json(body), body => setBody(self, body)));
/** @internal */

@@ -180,3 +176,3 @@ exports.jsonBody = jsonBody;

const encode = internalBody.jsonSchema(schema);
return (0, _Function.dual)(2, (self, body) => setBody(self, encode(body)));
return (0, _Function.dual)(2, (self, body) => Effect.map(encode(body), body => setBody(self, body)));
};

@@ -195,10 +191,3 @@ /** @internal */

} = {}) => setBody(self, internalBody.stream(body, contentType, contentLength)));
/** @internal */
exports.streamBody = streamBody;
const resolveBody = self => self.body._tag === "Effect" ? Effect.map(Effect.mapError(self.body.effect, error => internalError.requestError({
reason: "Encode",
request: self,
error
})), body => setBody(self, body)) : Effect.succeed(self);
exports.resolveBody = resolveBody;
//# sourceMappingURL=clientRequest.js.map

@@ -6,3 +6,3 @@ "use strict";

});
exports.urlParams = exports.unsafeJson = exports.uint8Array = exports.toNonEffectBody = exports.text = exports.stream = exports.setStatus = exports.setHeaders = exports.setHeader = exports.setBody = exports.schemaJson = exports.raw = exports.json = exports.isServerResponse = exports.getContentType = exports.formData = exports.file = exports.empty = exports.effect = exports.TypeId = void 0;
exports.urlParams = exports.unsafeJson = exports.uint8Array = exports.text = exports.stream = exports.setStatus = exports.setHeaders = exports.setHeader = exports.setBody = exports.schemaJson = exports.raw = exports.json = exports.isServerResponse = exports.getContentType = exports.formData = exports.file = exports.empty = exports.TypeId = void 0;
var _Function = /*#__PURE__*/require("@effect/data/Function");

@@ -14,6 +14,4 @@ var _Pipeable = /*#__PURE__*/require("@effect/data/Pipeable");

var Headers = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/Http/Headers"));
var ServerRequest = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/Http/ServerRequest"));
var UrlParams = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/Http/UrlParams"));
var internalBody = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/internal/http/body"));
var internalError = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/platform/internal/http/serverError"));
var Mime = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("mime"));

@@ -54,10 +52,2 @@ 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.isServerResponse = isServerResponse;
const toNonEffectBody = self => self.body._tag === "Effect" ? Effect.map(Effect.catchAll(self.body.effect, error => Effect.flatMap(ServerRequest.ServerRequest, request => Effect.fail(internalError.responseError({
reason: "Decode",
request,
response: self,
error
})))), body => setBody(self, body)) : Effect.succeed(self);
/** @internal */
exports.toNonEffectBody = toNonEffectBody;
const empty = options => new ServerResponseImpl(options?.status ?? 204, options?.statusText, options?.headers ?? Headers.empty, internalBody.empty);

@@ -72,3 +62,3 @@ /** @internal */

exports.text = text;
const json = (body, options) => new ServerResponseImpl(options?.status ?? 200, options?.statusText, options?.headers ?? Headers.empty, internalBody.json(body));
const json = (body, options) => Effect.map(internalBody.json(body), body => new ServerResponseImpl(options?.status ?? 200, options?.statusText, options?.headers ?? Headers.empty, body));
/** @internal */

@@ -81,3 +71,3 @@ exports.json = json;

const encode = internalBody.jsonSchema(schema);
return (body, options) => new ServerResponseImpl(options?.status ?? 200, options?.statusText, options?.headers ?? Headers.empty, encode(body));
return (body, options) => Effect.map(encode(body), body => new ServerResponseImpl(options?.status ?? 200, options?.statusText, options?.headers ?? Headers.empty, body));
};

@@ -112,5 +102,2 @@ /** @internal */

exports.urlParams = urlParams;
const effect = (body, options) => new ServerResponseImpl(options?.status ?? 200, options?.statusText, options?.headers ?? Headers.empty, internalBody.effect(body));
/** @internal */
exports.effect = effect;
const raw = (body, options) => new ServerResponseImpl(options?.status ?? 200, options?.statusText, options?.headers ?? Headers.empty, internalBody.raw(body));

@@ -117,0 +104,0 @@ /** @internal */

{
"name": "@effect/platform",
"version": "0.13.9",
"version": "0.13.10",
"description": "Unified interfaces for common platform-specific services",

@@ -5,0 +5,0 @@ "license": "MIT",

/**
* @since 1.0.0
*/
import type * as Data from "@effect/data/Data"
import type * as Effect from "@effect/io/Effect"

@@ -8,2 +9,3 @@ import type * as PlatformError from "@effect/platform/Error"

import * as internal from "@effect/platform/internal/http/body"
import type * as ParseResult from "@effect/schema/ParseResult"
import type * as Schema from "@effect/schema/Schema"

@@ -28,13 +30,7 @@ import type * as Stream_ from "@effect/stream/Stream"

*/
export type Body = Empty | Raw | Uint8Array | EffectBody | FormData | Stream
export type Body = Empty | Raw | Uint8Array | FormData | Stream
/**
* @since 1.0.0
* @category models
*/
export type NonEffect = Exclude<Body, EffectBody>
/**
* @since 1.0.0
*/
export namespace Body {

@@ -55,2 +51,41 @@ /**

* @since 1.0.0
* @category type ids
*/
export const ErrorTypeId: unique symbol = internal.ErrorTypeId
/**
* @since 1.0.0
* @category type ids
*/
export type ErrorTypeId = typeof ErrorTypeId
/**
* @since 1.0.0
* @category errors
*/
export interface BodyError extends Data.Case {
readonly [ErrorTypeId]: ErrorTypeId
readonly _tag: "BodyError"
readonly reason: BodyErrorReason
}
/**
* @since 1.0.0
* @category errors
*/
export const BodyError: (reason: BodyErrorReason) => BodyError = internal.BodyError
/**
* @since 1.0.0
* @category errors
*/
export type BodyErrorReason = {
readonly _tag: "JsonError"
readonly error: unknown
} | {
readonly _tag: "SchemaError"
readonly error: ParseResult.ParseError
}
/**
* @since 1.0.0
* @category models

@@ -108,19 +143,4 @@ */

* @since 1.0.0
* @category models
*/
export interface EffectBody extends Body.Proto {
readonly _tag: "Effect"
readonly effect: Effect.Effect<never, unknown, NonEffect>
}
/**
* @since 1.0.0
* @category constructors
*/
export const effect: (body: Effect.Effect<never, unknown, NonEffect>) => EffectBody = internal.effect
/**
* @since 1.0.0
* @category constructors
*/
export const unsafeJson: (body: unknown) => Uint8Array = internal.unsafeJson

@@ -132,3 +152,3 @@

*/
export const json: (body: unknown) => EffectBody = internal.json
export const json: (body: unknown) => Effect.Effect<never, BodyError, Uint8Array> = internal.json

@@ -139,3 +159,5 @@ /**

*/
export const jsonSchema: <I, A>(schema: Schema.Schema<I, A>) => (body: A) => EffectBody = internal.jsonSchema
export const jsonSchema: <I, A>(
schema: Schema.Schema<I, A>
) => (body: A) => Effect.Effect<never, BodyError, Uint8Array> = internal.jsonSchema

@@ -142,0 +164,0 @@ /**

@@ -207,3 +207,3 @@ /**

f: (
request: ClientRequest.ClientRequest.NonEffectBody
request: ClientRequest.ClientRequest
) => Effect.Effect<never, Error.HttpClientError, ClientResponse.ClientResponse>

@@ -210,0 +210,0 @@ ) => Client.Default = internal.make

@@ -44,15 +44,2 @@ /**

* @since 1.0.0
*/
export namespace ClientRequest {
/**
* @since 1.0.0
* @category models
*/
export interface NonEffectBody extends ClientRequest {
readonly body: Body.NonEffect
}
}
/**
* @since 1.0.0
* @category models

@@ -291,11 +278,2 @@ */

*/
export const effectBody: {
(body: Effect.Effect<never, unknown, Body.NonEffect>): (self: ClientRequest) => ClientRequest
(self: ClientRequest, body: Effect.Effect<never, unknown, Body.NonEffect>): ClientRequest
} = internal.effectBody
/**
* @since 1.0.0
* @category combinators
*/
export const textBody: {

@@ -311,4 +289,4 @@ (body: string, contentType?: string): (self: ClientRequest) => ClientRequest

export const jsonBody: {
(body: unknown): (self: ClientRequest) => ClientRequest
(self: ClientRequest, body: unknown): ClientRequest
(body: unknown): (self: ClientRequest) => Effect.Effect<never, Body.BodyError, ClientRequest>
(self: ClientRequest, body: unknown): Effect.Effect<never, Body.BodyError, ClientRequest>
} = internal.jsonBody

@@ -329,5 +307,7 @@

*/
export const schemaBody: <I, A>(schema: Schema.Schema<I, A>) => {
(body: A): (self: ClientRequest) => ClientRequest
(self: ClientRequest, body: A): ClientRequest
export const schemaBody: <I, A>(
schema: Schema.Schema<I, A>
) => {
(body: A): (self: ClientRequest) => Effect.Effect<never, Body.BodyError, ClientRequest>
(self: ClientRequest, body: A): Effect.Effect<never, Body.BodyError, ClientRequest>
} = internal.schemaBody

@@ -334,0 +314,0 @@

@@ -11,4 +11,2 @@ /**

import type * as Headers from "@effect/platform/Http/Headers"
import type * as Error from "@effect/platform/Http/ServerError"
import type * as ServerRequest from "@effect/platform/Http/ServerRequest"
import type * as UrlParams from "@effect/platform/Http/UrlParams"

@@ -45,15 +43,2 @@ import * as internal from "@effect/platform/internal/http/serverResponse"

* @since 1.0.0
*/
export namespace ServerResponse {
/**
* @since 1.0.0
* @category models
*/
export interface NonEffectBody extends ServerResponse {
readonly body: Body.NonEffect
}
}
/**
* @since 1.0.0
* @category models

@@ -93,10 +78,2 @@ */

* @since 1.0.0
*/
export const toNonEffectBody: (
self: ServerResponse
) => Effect.Effect<ServerRequest.ServerRequest, Error.ResponseError, ServerResponse.NonEffectBody> =
internal.toNonEffectBody
/**
* @since 1.0.0
* @category constructors

@@ -122,3 +99,6 @@ */

*/
export const json: (body: unknown, options?: Options.WithContent) => ServerResponse = internal.json
export const json: (
body: unknown,
options?: Options.WithContent
) => Effect.Effect<never, Body.BodyError, ServerResponse> = internal.json

@@ -131,3 +111,4 @@ /**

schema: Schema.Schema<I, A>
) => (body: A, options?: Options.WithContent) => ServerResponse = internal.schemaJson
) => (body: A, options?: Options.WithContent) => Effect.Effect<never, Body.BodyError, ServerResponse> =
internal.schemaJson

@@ -150,11 +131,2 @@ /**

*/
export const effect: (
body: Effect.Effect<never, unknown, Body.NonEffect>,
options?: Options.WithContent
) => ServerResponse = internal.effect
/**
* @since 1.0.0
* @category constructors
*/
export const raw: (body: unknown, options?: Options) => ServerResponse = internal.raw

@@ -161,0 +133,0 @@

@@ -0,1 +1,2 @@

import * as Data from "@effect/data/Data"
import * as Effect from "@effect/io/Effect"

@@ -13,2 +14,13 @@ import type * as PlatformError from "@effect/platform/Error"

/** @internal */
export const ErrorTypeId: Body.ErrorTypeId = Symbol.for(
"@effect/platform/Http/Body/BodyError"
) as Body.ErrorTypeId
const bodyError = Data.tagged<Body.BodyError>("BodyError")
/** @internal */
export const BodyError = (reason: Body.BodyErrorReason): Body.BodyError =>
bodyError({ [ErrorTypeId]: ErrorTypeId, reason })
class EmptyImpl implements Body.Empty {

@@ -63,19 +75,3 @@ readonly [TypeId]: Body.TypeId

class EffectBodyImpl implements Body.EffectBody {
readonly [TypeId]: Body.TypeId
readonly _tag = "Effect"
constructor(
readonly effect: Effect.Effect<never, unknown, Body.NonEffect>,
readonly contentType?: string
) {
this[TypeId] = TypeId
}
}
/** @internal */
export const effect = (
body: Effect.Effect<never, unknown, Body.NonEffect>
): Body.EffectBody => new EffectBodyImpl(body)
/** @internal */
export const unsafeJson = (body: unknown): Body.Uint8Array =>

@@ -85,3 +81,7 @@ uint8Array(new TextEncoder().encode(JSON.stringify(body)), "application/json")

/** @internal */
export const json = (body: unknown): Body.EffectBody => effect(Effect.try(() => unsafeJson(body)))
export const json = (body: unknown): Effect.Effect<never, Body.BodyError, Body.Uint8Array> =>
Effect.try({
try: () => unsafeJson(body),
catch: (error) => BodyError({ _tag: "JsonError", error })
})

@@ -91,7 +91,7 @@ /** @internal */

const encode = Schema.encode(schema)
return (body: A): Body.EffectBody =>
effect(Effect.flatMap(
encode(body),
(json) => Effect.try(() => unsafeJson(json))
))
return (body: A): Effect.Effect<never, Body.BodyError, Body.Uint8Array> =>
Effect.flatMap(
Effect.mapError(encode(body), (error) => BodyError({ _tag: "SchemaError", error })),
json
)
}

@@ -98,0 +98,0 @@

@@ -46,13 +46,5 @@ import * as Context from "@effect/data/Context"

f: (
request: ClientRequest.ClientRequest.NonEffectBody
request: ClientRequest.ClientRequest
) => Effect.Effect<never, Error.HttpClientError, ClientResponse.ClientResponse>
): Client.Client.Default => {
function client(request: ClientRequest.ClientRequest) {
return Effect.flatMap(
internalRequest.resolveBody(request),
(request) => f(request)
)
}
return setProto(client)
}
): Client.Client.Default => setProto(f)

@@ -102,3 +94,3 @@ /** @internal */

const convertBody = (body: Body.NonEffect): BodyInit | undefined => {
const convertBody = (body: Body.Body): BodyInit | undefined => {
switch (body._tag) {

@@ -105,0 +97,0 @@ case "Empty":

@@ -13,3 +13,2 @@ import { dual } from "@effect/data/Function"

import * as internalBody from "@effect/platform/internal/http/body"
import * as internalError from "@effect/platform/internal/http/clientError"
import type * as Schema from "@effect/schema/Schema"

@@ -318,16 +317,2 @@ import type * as Stream from "@effect/stream/Stream"

/** @internal */
export const effectBody = dual<
(
body: Effect.Effect<never, unknown, Body.NonEffect>
) => (self: ClientRequest.ClientRequest) => ClientRequest.ClientRequest,
(
self: ClientRequest.ClientRequest,
body: Effect.Effect<never, unknown, Body.NonEffect>
) => ClientRequest.ClientRequest
>(
2,
(self, body) => setBody(self, internalBody.effect(body))
)
/** @internal */
export const textBody = dual<

@@ -343,5 +328,10 @@ (body: string, contentType?: string) => (self: ClientRequest.ClientRequest) => ClientRequest.ClientRequest,

export const jsonBody = dual<
(body: unknown) => (self: ClientRequest.ClientRequest) => ClientRequest.ClientRequest,
(self: ClientRequest.ClientRequest, body: unknown) => ClientRequest.ClientRequest
>(2, (self, body) => setBody(self, internalBody.json(body)))
(
body: unknown
) => (self: ClientRequest.ClientRequest) => Effect.Effect<never, Body.BodyError, ClientRequest.ClientRequest>,
(
self: ClientRequest.ClientRequest,
body: unknown
) => Effect.Effect<never, Body.BodyError, ClientRequest.ClientRequest>
>(2, (self, body) => Effect.map(internalBody.json(body), (body) => setBody(self, body)))

@@ -374,10 +364,12 @@ /** @internal */

export const schemaBody = <I, A>(schema: Schema.Schema<I, A>): {
(body: A): (self: ClientRequest.ClientRequest) => ClientRequest.ClientRequest
(self: ClientRequest.ClientRequest, body: A): ClientRequest.ClientRequest
(body: A): (self: ClientRequest.ClientRequest) => Effect.Effect<never, Body.BodyError, ClientRequest.ClientRequest>
(self: ClientRequest.ClientRequest, body: A): Effect.Effect<never, Body.BodyError, ClientRequest.ClientRequest>
} => {
const encode = internalBody.jsonSchema(schema)
return dual<
(body: A) => (self: ClientRequest.ClientRequest) => ClientRequest.ClientRequest,
(self: ClientRequest.ClientRequest, body: A) => ClientRequest.ClientRequest
>(2, (self, body) => setBody(self, encode(body)))
(
body: A
) => (self: ClientRequest.ClientRequest) => Effect.Effect<never, Body.BodyError, ClientRequest.ClientRequest>,
(self: ClientRequest.ClientRequest, body: A) => Effect.Effect<never, Body.BodyError, ClientRequest.ClientRequest>
>(2, (self, body) => Effect.map(encode(body), (body) => setBody(self, body)))
}

@@ -426,17 +418,1 @@

)
/** @internal */
export const resolveBody = (
self: ClientRequest.ClientRequest
): Effect.Effect<never, Error.RequestError, ClientRequest.ClientRequest.NonEffectBody> =>
self.body._tag === "Effect"
? Effect.map(
Effect.mapError(self.body.effect, (error) =>
internalError.requestError({
reason: "Encode",
request: self,
error
})),
(body) => setBody(self, body) as ClientRequest.ClientRequest.NonEffectBody
)
: Effect.succeed(self as ClientRequest.ClientRequest.NonEffectBody)

@@ -9,8 +9,5 @@ import { dual, pipe } from "@effect/data/Function"

import * as Headers from "@effect/platform/Http/Headers"
import type * as Error from "@effect/platform/Http/ServerError"
import * as ServerRequest from "@effect/platform/Http/ServerRequest"
import type * as ServerResponse from "@effect/platform/Http/ServerResponse"
import * as UrlParams from "@effect/platform/Http/UrlParams"
import * as internalBody from "@effect/platform/internal/http/body"
import * as internalError from "@effect/platform/internal/http/serverError"
import type * as Schema from "@effect/schema/Schema"

@@ -56,25 +53,2 @@ import type * as Stream from "@effect/stream/Stream"

/** @internal */
export const toNonEffectBody = (
self: ServerResponse.ServerResponse
): Effect.Effect<ServerRequest.ServerRequest, Error.ResponseError, ServerResponse.ServerResponse.NonEffectBody> =>
self.body._tag === "Effect" ?
Effect.map(
Effect.catchAll(self.body.effect, (error) =>
Effect.flatMap(
ServerRequest.ServerRequest,
(request) =>
Effect.fail(
internalError.responseError({
reason: "Decode",
request,
response: self,
error
})
)
)),
(body) => setBody(self, body) as ServerResponse.ServerResponse.NonEffectBody
) :
Effect.succeed(self as ServerResponse.ServerResponse.NonEffectBody)
/** @internal */
export const empty = (options?: ServerResponse.Options.WithContent): ServerResponse.ServerResponse =>

@@ -110,9 +84,13 @@ new ServerResponseImpl(

/** @internal */
export const json = (body: unknown, options?: ServerResponse.Options.WithContent): ServerResponse.ServerResponse =>
new ServerResponseImpl(
options?.status ?? 200,
options?.statusText,
options?.headers ?? Headers.empty,
internalBody.json(body)
)
export const json = (
body: unknown,
options?: ServerResponse.Options.WithContent
): Effect.Effect<never, Body.BodyError, ServerResponse.ServerResponse> =>
Effect.map(internalBody.json(body), (body) =>
new ServerResponseImpl(
options?.status ?? 200,
options?.statusText,
options?.headers ?? Headers.empty,
body
))

@@ -136,9 +114,13 @@ /** @internal */

const encode = internalBody.jsonSchema(schema)
return (body: A, options?: ServerResponse.Options.WithContent): ServerResponse.ServerResponse =>
new ServerResponseImpl(
options?.status ?? 200,
options?.statusText,
options?.headers ?? Headers.empty,
encode(body)
)
return (
body: A,
options?: ServerResponse.Options.WithContent
): Effect.Effect<never, Body.BodyError, ServerResponse.ServerResponse> =>
Effect.map(encode(body), (body) =>
new ServerResponseImpl(
options?.status ?? 200,
options?.statusText,
options?.headers ?? Headers.empty,
body
))
}

@@ -197,14 +179,2 @@

/** @internal */
export const effect = (
body: Effect.Effect<never, unknown, Body.NonEffect>,
options?: ServerResponse.Options.WithContent
): ServerResponse.ServerResponse =>
new ServerResponseImpl(
options?.status ?? 200,
options?.statusText,
options?.headers ?? Headers.empty,
internalBody.effect(body)
)
/** @internal */
export const raw = (body: unknown, options?: ServerResponse.Options): ServerResponse.ServerResponse =>

@@ -211,0 +181,0 @@ new ServerResponseImpl(

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc