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
377
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.1 to 0.13.2

6

Http/Headers.d.ts

@@ -1,3 +0,3 @@

import * as HashMap from "@effect/data/HashMap";
import type * as Option from "@effect/data/Option";
import * as ReadonlyRecord from "@effect/data/ReadonlyRecord";
/**

@@ -7,3 +7,3 @@ * @since 1.0.0

*/
export interface Headers extends HashMap.HashMap<string, string> {
export interface Headers extends ReadonlyRecord.ReadonlyRecord<string> {
}

@@ -14,3 +14,3 @@ /**

*/
export type Input = Headers | Readonly<Record<string, string>> | Iterable<readonly [string, string]>;
export type Input = Headers | Iterable<readonly [string, string]>;
/**

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

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

var _Function = /*#__PURE__*/require("@effect/data/Function");
var HashMap = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/HashMap"));
var ReadonlyArray = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/ReadonlyArray"));
var ReadonlyRecord = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/ReadonlyRecord"));
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); }

@@ -20,3 +21,3 @@ 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; }

*/
const empty = /*#__PURE__*/HashMap.empty();
const empty = /*#__PURE__*/ReadonlyRecord.empty();
/**

@@ -30,8 +31,6 @@ * @since 1.0.0

return empty;
} else if (HashMap.isHashMap(input)) {
return input;
} else if (Symbol.iterator in input) {
return HashMap.fromIterable([...input].map(([k, v]) => [k.toLowerCase(), v]));
return ReadonlyRecord.fromEntries(ReadonlyArray.map(ReadonlyArray.fromIterable(input), ([k, v]) => [k.toLowerCase(), v]));
}
return HashMap.fromIterable(Object.entries(input).map(([k, v]) => [k.toLowerCase(), v]));
return ReadonlyRecord.fromEntries(Object.entries(input).map(([k, v]) => [k.toLowerCase(), v]));
};

@@ -43,3 +42,3 @@ /**

exports.fromInput = fromInput;
const has = /*#__PURE__*/(0, _Function.dual)(2, (self, key) => HashMap.has(self, key.toLowerCase()));
const has = /*#__PURE__*/(0, _Function.dual)(2, (self, key) => ReadonlyRecord.has(self, key.toLowerCase()));
/**

@@ -50,3 +49,3 @@ * @since 1.0.0

exports.has = has;
const get = /*#__PURE__*/(0, _Function.dual)(2, (self, key) => HashMap.get(self, key.toLowerCase()));
const get = /*#__PURE__*/(0, _Function.dual)(2, (self, key) => ReadonlyRecord.get(self, key.toLowerCase()));
/**

@@ -57,3 +56,6 @@ * @since 1.0.0

exports.get = get;
const set = /*#__PURE__*/(0, _Function.dual)(3, (self, key, value) => HashMap.set(self, key.toLowerCase(), value));
const set = /*#__PURE__*/(0, _Function.dual)(3, (self, key, value) => ({
...self,
[key.toLowerCase()]: value
}));
/**

@@ -64,3 +66,6 @@ * @since 1.0.0

exports.set = set;
const setAll = /*#__PURE__*/(0, _Function.dual)(2, (self, headers) => HashMap.union(self, fromInput(headers)));
const setAll = /*#__PURE__*/(0, _Function.dual)(2, (self, headers) => ({
...self,
...fromInput(headers)
}));
/**

@@ -71,4 +76,4 @@ * @since 1.0.0

exports.setAll = setAll;
const remove = /*#__PURE__*/(0, _Function.dual)(2, (self, key) => HashMap.remove(self, key.toLowerCase()));
const remove = /*#__PURE__*/(0, _Function.dual)(2, (self, key) => ReadonlyRecord.remove(self, key.toLowerCase()));
exports.remove = remove;
//# sourceMappingURL=Headers.js.map

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

const parse = Schema.parse(schema);
return self => parse(Object.fromEntries(self.headers));
return self => parse(self.headers);
};

@@ -53,0 +53,0 @@ /**

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

})), url => Effect.suspend(() => {
const headers = new Headers([...request.headers]);
const headers = new Headers(request.headers);
const send = body => Effect.map(Effect.tryPromise({

@@ -51,0 +51,0 @@ try: signal => globalThis.fetch(url, {

@@ -17,6 +17,10 @@ "use strict";

exports.make = make;
const logger = /*#__PURE__*/make(httpApp => Effect.withLogSpan(Effect.onExit(httpApp, exit => Effect.flatMap(ServerRequest.ServerRequest, request => Effect.annotateLogs(Effect.log("", exit._tag === "Failure" ? exit.cause : undefined), {
const logger = /*#__PURE__*/make(httpApp => Effect.withLogSpan(Effect.flatMap(ServerRequest.ServerRequest, request => Effect.tap(Effect.tapErrorCause(httpApp, cause => Effect.annotateLogs(Effect.log(cause), {
"http.method": request.method,
"http.url": request.url,
"http.status": exit._tag === "Success" ? exit.value.status : 500
"http.status": 500
})), response => Effect.annotateLogs(Effect.log(""), {
"http.method": request.method,
"http.url": request.url,
"http.status": response.status
}))), "http.span"));

@@ -33,6 +37,3 @@ /** @internal */

exports.tracer = tracer;
const xForwardedHeaders = /*#__PURE__*/make(httpApp => Effect.flatMap(ServerRequest.ServerRequest, request => {
const forwardedHost = Headers.get(request.headers, "x-forwarded-host");
return forwardedHost._tag === "Some" ? Effect.updateService(httpApp, ServerRequest.ServerRequest, _ => _.replaceHeaders(Headers.set(request.headers, "host", forwardedHost.value))) : httpApp;
}));
const xForwardedHeaders = /*#__PURE__*/make(httpApp => Effect.updateService(httpApp, ServerRequest.ServerRequest, request => request.headers["x-forwarded-host"] ? request.replaceHeaders(Headers.set(request.headers, "host", request.headers["x-forwarded-host"])) : request));
/** @internal */

@@ -39,0 +40,0 @@ exports.xForwardedHeaders = xForwardedHeaders;

@@ -82,11 +82,8 @@ "use strict";

const router = (0, _findMyWay.default)();
Chunk.forEach(self.mounts, ([path, app]) => {
const fn = () => {};
fn.handler = Effect.updateService(app, ServerRequest.ServerRequest, request => sliceRequestUrl(request, path));
router.all(path, fn);
router.all(path + "/*", fn);
});
const mounts = Chunk.toReadonlyArray(self.mounts);
const mountsLen = mounts.length;
Chunk.forEach(self.routes, route => {
const fn = () => {};
fn.handler = route;
function fn(_, __) {
return route;
}
if (route.method === "*") {

@@ -99,2 +96,10 @@ router.all(route.path, fn);

return Effect.flatMap(ServerRequest.ServerRequest, request => {
if (mountsLen > 0) {
for (let i = 0; i < mountsLen; i++) {
const [path, app] = mounts[i];
if (request.url.startsWith(path)) {
return Effect.provideService(app, ServerRequest.ServerRequest, sliceRequestUrl(request, path));
}
}
}
const result = router.find(request.method, request.url);

@@ -106,11 +111,7 @@ if (result === null) {

}
const handler = result.handler.handler;
if (RouteTypeId in handler) {
const route = handler;
if (route.prefix._tag === "Some") {
request = sliceRequestUrl(request, route.prefix.value);
}
return Effect.mapInputContext(route.handler, context => Context.add(Context.add(context, ServerRequest.ServerRequest, request), RouteContext, new RouteContextImpl(result.params, result.searchParams)));
const route = result.handler();
if (route.prefix._tag === "Some") {
request = sliceRequestUrl(request, route.prefix.value);
}
return handler;
return Effect.mapInputContext(route.handler, context => Context.add(Context.add(context, ServerRequest.ServerRequest, request), RouteContext, new RouteContextImpl(result.params, result.searchParams)));
});

@@ -117,0 +118,0 @@ };

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

var _Function = /*#__PURE__*/require("@effect/data/Function");
var Option = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/data/Option"));
var _Pipeable = /*#__PURE__*/require("@effect/data/Pipeable");

@@ -26,5 +25,18 @@ var Effect = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/io/Effect"));

this.statusText = statusText;
this.headers = headers;
this.body = body;
this[TypeId] = TypeId;
if (body.contentType || body.contentLength) {
const newHeaders = {
...headers
};
if (body.contentType) {
newHeaders["content-type"] = body.contentType;
}
if (body.contentLength) {
newHeaders["content-length"] = body.contentLength.toString();
}
this.headers = newHeaders;
} else {
this.headers = headers;
}
}

@@ -90,3 +102,3 @@ pipe() {

} else if (options?.headers) {
return Option.getOrUndefined(Headers.get("content-type")(options.headers));
return options.headers["content-type"];
} else {

@@ -111,11 +123,2 @@ return;

headers = Headers.remove(Headers.remove(headers, "Content-Type"), "Content-length");
} else {
const contentType = body.contentType;
if (contentType) {
headers = Headers.set(headers, "content-type", contentType);
}
const contentLength = body.contentLength;
if (contentLength) {
headers = Headers.set(headers, "content-length", contentLength.toString());
}
}

@@ -122,0 +125,0 @@ return new ServerResponseImpl(self.status, self.statusText, headers, body);

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

@@ -32,7 +32,7 @@ "license": "MIT",

"peerDependencies": {
"@effect/data": "^0.17.1",
"@effect/io": "^0.38.0",
"@effect/schema": "^0.33.0",
"@effect/data": "^0.17.5",
"@effect/io": "^0.38.2",
"@effect/schema": "^0.33.1",
"@effect/stream": "^0.34.0"
}
}

@@ -5,4 +5,5 @@ /**

import { dual } from "@effect/data/Function"
import * as HashMap from "@effect/data/HashMap"
import type * as Option from "@effect/data/Option"
import * as ReadonlyArray from "@effect/data/ReadonlyArray"
import * as ReadonlyRecord from "@effect/data/ReadonlyRecord"

@@ -13,3 +14,3 @@ /**

*/
export interface Headers extends HashMap.HashMap<string, string> {}
export interface Headers extends ReadonlyRecord.ReadonlyRecord<string> {}

@@ -20,3 +21,3 @@ /**

*/
export type Input = Headers | Readonly<Record<string, string>> | Iterable<readonly [string, string]>
export type Input = Headers | Iterable<readonly [string, string]>

@@ -27,3 +28,3 @@ /**

*/
export const empty: Headers = HashMap.empty()
export const empty: Headers = ReadonlyRecord.empty()

@@ -37,8 +38,11 @@ /**

return empty
} else if (HashMap.isHashMap(input)) {
return input
} else if (Symbol.iterator in input) {
return HashMap.fromIterable([...input].map(([k, v]) => [k.toLowerCase(), v])) as Headers
return ReadonlyRecord.fromEntries(ReadonlyArray.map(
ReadonlyArray.fromIterable(input),
([k, v]) => [k.toLowerCase(), v] as const
))
}
return HashMap.fromIterable(Object.entries(input).map(([k, v]) => [k.toLowerCase(), v]))
return ReadonlyRecord.fromEntries(
Object.entries(input).map(([k, v]) => [k.toLowerCase(), v])
)
}

@@ -56,3 +60,3 @@

(self: Headers, key: string) => boolean
>(2, (self, key) => HashMap.has(self, key.toLowerCase()))
>(2, (self, key) => ReadonlyRecord.has(self, key.toLowerCase()))

@@ -69,3 +73,3 @@ /**

(self: Headers, key: string) => Option.Option<string>
>(2, (self, key) => HashMap.get(self, key.toLowerCase()))
>(2, (self, key) => ReadonlyRecord.get(self, key.toLowerCase()))

@@ -82,3 +86,6 @@ /**

(self: Headers, key: string, value: string) => Headers
>(3, (self, key, value) => HashMap.set(self, key.toLowerCase(), value))
>(3, (self, key, value) => ({
...self,
[key.toLowerCase()]: value
}))

@@ -95,7 +102,6 @@ /**

(self: Headers, headers: Input) => Headers
>(2, (self, headers) =>
HashMap.union(
self,
fromInput(headers)
))
>(2, (self, headers) => ({
...self,
...fromInput(headers)
}))

@@ -112,2 +118,2 @@ /**

(self: Headers, key: string) => Headers
>(2, (self, key) => HashMap.remove(self, key.toLowerCase()))
>(2, (self, key) => ReadonlyRecord.remove(self, key.toLowerCase()))

@@ -68,4 +68,3 @@ /**

const parse = Schema.parse(schema)
return <E>(self: IncomingMessage<E>): Effect.Effect<never, ParseResult.ParseError, A> =>
parse(Object.fromEntries(self.headers))
return <E>(self: IncomingMessage<E>): Effect.Effect<never, ParseResult.ParseError, A> => parse(self.headers)
}

@@ -72,0 +71,0 @@

@@ -33,3 +33,3 @@ import * as Context from "@effect/data/Context"

const setProto = <R, E, A>(
f: (request: ClientRequest.ClientRequest.NonEffectBody) => Effect.Effect<R, E, A>
f: (request: ClientRequest.ClientRequest) => Effect.Effect<R, E, A>
) => {

@@ -69,3 +69,3 @@ Object.setPrototypeOf(f, clientProto)

Effect.suspend(() => {
const headers = new Headers([...request.headers] as any)
const headers = new Headers(request.headers)
const send = (body: BodyInit | undefined) =>

@@ -123,3 +123,3 @@ Effect.map(

export const catchTag: {
<E extends { _tag: string }, K extends E["_tag"] & string, R1, E1, A1>(
<K extends (E extends { _tag: string } ? E["_tag"] : never), E, R1, E1, A1>(
tag: K,

@@ -130,3 +130,3 @@ f: (e: Extract<E, { _tag: K }>) => Effect.Effect<R1, E1, A1>

) => Client.Client<R1 | R, E1 | Exclude<E, { _tag: K }>, A1 | A>
<R, E extends { _tag: string }, A, K extends E["_tag"] & string, E1, R1, A1>(
<R, E, A, K extends (E extends { _tag: string } ? E["_tag"] : never), R1, E1, A1>(
self: Client.Client<R, E, A>,

@@ -138,3 +138,3 @@ tag: K,

3,
<R, E extends { _tag: string }, A, K extends E["_tag"] & string, E1, R1, A1>(
<R, E, A, K extends (E extends { _tag: string } ? E["_tag"] : never), R1, E1, A1>(
self: Client.Client<R, E, A>,

@@ -150,8 +150,7 @@ tag: K,

<
E extends { _tag: string },
Cases extends {
[K in E["_tag"]]+?:
| ((error: Extract<E, { _tag: K }>) => Effect.Effect<any, any, any>)
| undefined
}
E,
Cases
extends (E extends { _tag: string }
? { [K in E["_tag"]]+?: ((error: Extract<E, { _tag: K }>) => Effect.Effect<any, any, any>) }
: {})
>(

@@ -188,7 +187,6 @@ cases: Cases

A,
Cases extends {
[K in E["_tag"]]+?:
| ((error: Extract<E, { _tag: K }>) => Effect.Effect<any, any, any>)
| undefined
}
Cases
extends (E extends { _tag: string }
? { [K in E["_tag"]]+?: ((error: Extract<E, { _tag: K }>) => Effect.Effect<any, any, any>) }
: {})
>(

@@ -226,7 +224,6 @@ self: Client.Client<R, E, A>,

A,
Cases extends {
[K in E["_tag"]]+?:
| ((error: Extract<E, { _tag: K }>) => Effect.Effect<any, any, any>)
| undefined
}
Cases
extends (E extends { _tag: string }
? { [K in E["_tag"]]+?: ((error: Extract<E, { _tag: K }>) => Effect.Effect<any, any, any>) }
: {})
>(

@@ -233,0 +230,0 @@ self: Client.Client<R, E, A>,

@@ -14,12 +14,17 @@ import { dual } from "@effect/data/Function"

Effect.withLogSpan(
Effect.onExit(
httpApp,
(exit) =>
Effect.flatMap(
ServerRequest.ServerRequest,
(request) =>
Effect.annotateLogs(Effect.log("", exit._tag === "Failure" ? exit.cause : undefined), {
Effect.flatMap(
ServerRequest.ServerRequest,
(request) =>
Effect.tap(
Effect.tapErrorCause(httpApp, (cause) =>
Effect.annotateLogs(Effect.log(cause), {
"http.method": request.method,
"http.url": request.url,
"http.status": exit._tag === "Success" ? exit.value.status : 500
"http.status": 500
})),
(response) =>
Effect.annotateLogs(Effect.log(""), {
"http.method": request.method,
"http.url": request.url,
"http.status": response.status
})

@@ -50,9 +55,10 @@ )

export const xForwardedHeaders = make((httpApp) =>
Effect.flatMap(ServerRequest.ServerRequest, (request) => {
const forwardedHost = Headers.get(request.headers, "x-forwarded-host")
return forwardedHost._tag === "Some"
? Effect.updateService(httpApp, ServerRequest.ServerRequest, (_) =>
_.replaceHeaders(Headers.set(request.headers, "host", forwardedHost.value)))
: httpApp
})
Effect.updateService(httpApp, ServerRequest.ServerRequest, (request) =>
request.headers["x-forwarded-host"]
? request.replaceHeaders(Headers.set(
request.headers,
"host",
request.headers["x-forwarded-host"]
))
: request)
)

@@ -59,0 +65,0 @@

@@ -98,11 +98,8 @@ import * as Chunk from "@effect/data/Chunk"

const router = FindMyWay()
Chunk.forEach(self.mounts, ([path, app]) => {
const fn = () => {}
fn.handler = Effect.updateService(app, ServerRequest.ServerRequest, (request) => sliceRequestUrl(request, path))
router.all(path, fn)
router.all(path + "/*", fn)
})
const mounts = Chunk.toReadonlyArray(self.mounts)
const mountsLen = mounts.length
Chunk.forEach(self.routes, (route) => {
const fn = () => {}
fn.handler = route
function fn(_: any, __: any) {
return route
}
if (route.method === "*") {

@@ -117,2 +114,15 @@ router.all(route.path, fn)

(request): App.Default<Exclude<R, Router.RouteContext>, E | Error.RouteNotFound> => {
if (mountsLen > 0) {
for (let i = 0; i < mountsLen; i++) {
const [path, app] = mounts[i]
if (request.url.startsWith(path)) {
return Effect.provideService(
app,
ServerRequest.ServerRequest,
sliceRequestUrl(request, path)
) as App.Default<Exclude<R, Router.RouteContext>, E>
}
}
}
const result = router.find(request.method as HTTPMethod, request.url)

@@ -122,19 +132,15 @@ if (result === null) {

}
const handler = (result.handler as any).handler
if (RouteTypeId in handler) {
const route = handler as Router.Route<R, E>
if (route.prefix._tag === "Some") {
request = sliceRequestUrl(request, route.prefix.value)
}
return Effect.mapInputContext(
route.handler,
(context) =>
Context.add(
Context.add(context, ServerRequest.ServerRequest, request),
RouteContext,
new RouteContextImpl(result.params, result.searchParams)
) as Context.Context<R>
)
const route = (result.handler as any)() as Router.Route<R, E>
if (route.prefix._tag === "Some") {
request = sliceRequestUrl(request, route.prefix.value)
}
return (handler as App.Default<Exclude<R, Router.RouteContext>, E>)
return Effect.mapInputContext(
route.handler,
(context) =>
Context.add(
Context.add(context, ServerRequest.ServerRequest, request),
RouteContext,
new RouteContextImpl(result.params, result.searchParams)
) as Context.Context<R>
)
}

@@ -141,0 +147,0 @@ )

import { dual } from "@effect/data/Function"
import * as Option from "@effect/data/Option"
import { pipeArguments } from "@effect/data/Pipeable"

@@ -23,9 +22,22 @@ import * as Effect from "@effect/io/Effect"

readonly [TypeId]: ServerResponse.TypeId
readonly headers: Headers.Headers
constructor(
readonly status: number,
readonly statusText: string | undefined,
readonly headers: Headers.Headers,
headers: Headers.Headers,
readonly body: Body.Body
) {
this[TypeId] = TypeId
if (body.contentType || body.contentLength) {
const newHeaders = { ...headers }
if (body.contentType) {
newHeaders["content-type"] = body.contentType
}
if (body.contentLength) {
newHeaders["content-length"] = body.contentLength.toString()
}
this.headers = newHeaders
} else {
this.headers = headers
}
}

@@ -201,3 +213,3 @@ pipe() {

} else if (options?.headers) {
return Option.getOrUndefined(Headers.get("content-type")(options.headers))
return options.headers["content-type"]
} else {

@@ -252,12 +264,2 @@ return

headers = Headers.remove(Headers.remove(headers, "Content-Type"), "Content-length")
} else {
const contentType = body.contentType
if (contentType) {
headers = Headers.set(headers, "content-type", contentType)
}
const contentLength = body.contentLength
if (contentLength) {
headers = Headers.set(headers, "content-length", contentLength.toString())
}
}

@@ -264,0 +266,0 @@ return 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

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