Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 0 additions & 73 deletions .yarn/patches/@effect-vitest-npm-0.29.0-1c8cf3c306.patch

This file was deleted.

2 changes: 1 addition & 1 deletion apps/hash-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"axios": "1.20.0",
"cors": "2.8.5",
"dedent": "1.7.0",
"effect": "3.21.0",
"effect": "4.0.3",
"exponential-backoff": "3.1.3",
"express": "5.2.0",
"express-handlebars": "8.0.4",
Expand Down
17 changes: 12 additions & 5 deletions apps/hash-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ import { promisify } from "node:util";
import KeyvRedis from "@keyv/redis";
import * as Sentry from "@sentry/node";
import cors from "cors";
import { Effect, Exit, Layer, Logger, LogLevel, ManagedRuntime } from "effect";
import { RuntimeException } from "effect/Cause";
import {
Cause,
Effect,
Exit,
Layer,
Logger,
ManagedRuntime,
References,
} from "effect";
import express, { raw } from "express";
import { create as handlebarsCreate } from "express-handlebars";
import { ipKeyGenerator, rateLimit } from "express-rate-limit";
Expand Down Expand Up @@ -815,7 +822,7 @@ const main = async () => {
RequestIdProducer.layer,
JsonDecoder.layer,
JsonEncoder.layer,
Logger.pretty,
Logger.layer([Logger.consolePretty(), Logger.tracerLogger]),
),
);

Expand Down Expand Up @@ -857,7 +864,7 @@ const main = async () => {
const effect = Effect.gen(function* () {
const textQueryParam = req.query.text;
if (typeof textQueryParam !== "string") {
return yield* new RuntimeException(
return yield* new Cause.IllegalArgumentError(
"text query parameter is required",
);
}
Expand All @@ -870,7 +877,7 @@ const main = async () => {
Transport.multiaddr(`/dns/${rpcHost}/tcp/${rpcPort}`),
),
),
Logger.withMinimumLogLevel(LogLevel.Trace),
Effect.provideService(References.MinimumLogLevel, "Trace"),
);

runtime.runCallback(effect, {
Expand Down
2 changes: 1 addition & 1 deletion libs/@local/eslint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@eslint/eslintrc": "3.3.3",
"@typescript-eslint/eslint-plugin": "8.71.0",
"@typescript-eslint/parser": "8.71.0",
"effect": "3.21.0",
"effect": "4.0.3",
"eslint": "9.39.4",
"eslint-config-airbnb": "19.0.4",
"eslint-config-flat-gitignore": "2.2.1",
Expand Down
8 changes: 4 additions & 4 deletions libs/@local/eslint/src/builtIn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Array as ReadonlyArray, Option, pipe, Predicate } from "effect";
import { Array as ReadonlyArray, pipe, Predicate, Result } from "effect";

import { defineConfig, type ESConfig } from "./utils.js";

Expand Down Expand Up @@ -46,15 +46,15 @@ const noRestrictedImports = (
ReadonlyArray.filter(Predicate.isNotUndefined),
ReadonlyArray.filterMap((entry) =>
Array.isArray(entry) && entry.length === 2
? Option.some(entry[1])
: Option.none(),
? Result.succeed(entry[1])
: Result.failVoid,
),
);

const current = candidates.at(-1);

// the value should be a dictionary with `paths` and `patterns` keys
if (!Predicate.isRecord(current) || Predicate.hasProperty(current, "name")) {
if (!Predicate.isObject(current) || Predicate.hasProperty(current, "name")) {
throw new Error(
"expected no-restricted-imports to follow the `paths` and `patterns` structure",
);
Expand Down
2 changes: 1 addition & 1 deletion libs/@local/graph/sdk/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@local/hash-graph-client": "workspace:*",
"@local/hash-graph-store": "workspace:*",
"@temporalio/client": "1.20.2",
"effect": "3.21.0",
"effect": "4.0.3",
"uuid": "14.0.0"
},
"devDependencies": {
Expand Down
71 changes: 36 additions & 35 deletions libs/@local/graph/sdk/typescript/src/harpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import {
Function,
Option,
pipe,
Predicate,
Result,
Schema,
SchemaTransformation,
Stream,
} from "effect";

Expand All @@ -29,40 +30,40 @@ import {
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- otherwise TypeScript will fail on inference, I don't know why
import { RequestIdProducer } from "@local/harpc-client/wire-protocol";

const ServerResult = <A, I, R>(ok: Schema.Schema<A, I, R>) =>
Schema.transform(
Schema.Union(
Schema.Struct({
Ok: ok,
}),
Schema.Struct({
Err: Schema.Unknown,
}),
),
Schema.Either({
left: Schema.instanceOf(ClientError.ServerError),
right: Schema.typeSchema(ok),
const ServerResult = <A, I, RD, RE>(ok: Schema.Codec<A, I, RD, RE>) =>
Schema.Union([
Schema.Struct({
Ok: ok,
}),
Schema.Struct({
Err: Schema.Unknown,
}),
{
strict: true,
decode: (value) => {
if (Predicate.hasProperty(value, "Ok")) {
return { _tag: "Right", right: value.Ok } as const;
}
]).pipe(
Schema.decodeTo(
Schema.Result(
Schema.toType(ok),
Schema.instanceOf(ClientError.ServerError),
),
SchemaTransformation.transform<
Result.Result<A, ClientError.ServerError>,
{ readonly Ok: A } | { readonly Err: unknown }
>({
decode: (value) => {
if ("Ok" in value) {
return Result.succeed(value.Ok);
}

return {
_tag: "Left",
left: new ClientError.ServerError({ cause: value.Err }),
} as const;
},
encode: (value) => {
if (value._tag === "Right") {
return { Ok: value.right };
}
return Result.fail(new ClientError.ServerError({ cause: value.Err }));
},
encode: (value) => {
if (Result.isSuccess(value)) {
return { Ok: value.success };
}

return { Err: value.left.cause } as const;
},
},
return { Err: value.failure.cause };
},
}),
),
);

export class EchoSubsystem {
Expand All @@ -84,7 +85,7 @@ export class EchoSubsystem {
Stream.succeed,
encoder.encode(Schema.String),
Stream.runCollect,
Effect.map(Stream.fromChunk),
Effect.map(Stream.fromArray),
);

const request = yield* Request.make(
Expand All @@ -102,10 +103,10 @@ export class EchoSubsystem {
const items = decoder.decode(response.body, ServerResult(Schema.String));
const item = yield* Stream.runHead(items);

const eitherItem = Option.getOrThrowWith(item, () =>
const resultItem = Option.getOrThrowWith(item, () =>
ClientError.ExpectedItemCountMismatchError.exactly(1, 0),
);

return yield* eitherItem;
return yield* Effect.fromResult(resultItem);
}, Effect.map(Function.identity));
}
11 changes: 3 additions & 8 deletions libs/@local/harpc/client/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,15 @@
"@libp2p/tcp": "11.0.28",
"@multiformats/dns": "1.0.10",
"@multiformats/multiaddr": "13.0.3",
"effect": "3.21.0",
"effect": "4.0.3",
"it-stream-types": "2.0.2",
"libp2p": "3.3.11",
"multiformats": "14.0.5",
"uint8arraylist": "3.0.2"
},
"devDependencies": {
"@effect/cluster": "0.50.6",
"@effect/experimental": "0.56.0",
"@effect/platform": "0.92.1",
"@effect/platform-node": "0.98.4",
"@effect/rpc": "0.71.1",
"@effect/sql": "0.46.0",
"@effect/vitest": "patch:@effect/vitest@npm%3A0.29.0#~/.yarn/patches/@effect-vitest-npm-0.29.0-1c8cf3c306.patch",
"@effect/platform-node": "4.0.3",
"@effect/vitest": "4.0.3",
"@local/eslint": "workspace:*",
"@local/tsconfig": "workspace:*",
"@tsconfig/bases": "catalog:",
Expand Down
26 changes: 13 additions & 13 deletions libs/@local/harpc/client/typescript/src/binary/MutableBuffer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Data, Either, Function, pipe, Pipeable } from "effect";
import { Data, Function, pipe, Pipeable, Result } from "effect";

import { createProto } from "../utils.js";
import * as MutableBytes from "./MutableBytes.js";
Expand All @@ -22,7 +22,7 @@ export type Read = typeof Read;

export type ReadBuffer = MutableBuffer<Read>;

export type ReadResult<T, E = UnexpectedEndOfBufferError> = Either.Either<T, E>;
export type ReadResult<T, E = UnexpectedEndOfBufferError> = Result.Result<T, E>;

const Write: unique symbol = Symbol(
"@local/harpc-client/binary/MutableBuffer/Write",
Expand All @@ -32,7 +32,7 @@ export type Write = typeof Write;

export type WriteBuffer = MutableBuffer<Write>;

export type WriteResult<E = UnexpectedEndOfBufferError> = Either.Either<
export type WriteResult<E = UnexpectedEndOfBufferError> = Result.Result<
WriteBuffer,
E
>;
Expand Down Expand Up @@ -89,17 +89,17 @@ export const makeWrite = (buffer?: MutableBytes.MutableBytes): WriteBuffer =>
const validateBounds = <T>(
self: MutableBuffer<T>,
width: number,
): Either.Either<void, UnexpectedEndOfBufferError> => {
): Result.Result<void, UnexpectedEndOfBufferError> => {
const impl = self as MutableBufferImpl<T>;

return impl.index + width > MutableBytes.length(impl.bytes)
? Either.left(
? Result.fail(
new UnexpectedEndOfBufferError({
index: impl.index,
length: MutableBytes.length(impl.bytes),
}),
)
: Either.right(undefined);
: Result.succeed(undefined);
};

/**
Expand All @@ -122,7 +122,7 @@ const putInt = (sign: "u" | "i", width: 1 | 2 | 4) =>
>(2, (self, value) =>
pipe(
validateBounds(self, width),
Either.map(() => {
Result.map(() => {
const impl = self as MutableBufferImpl<Write>;
const view = MutableBytes.asDataView(impl.bytes);

Expand Down Expand Up @@ -173,7 +173,7 @@ export const putI32 = putInt("i", 4);
const getInt = (sign: "u" | "i", width: 1 | 2 | 4) => (self: ReadBuffer) =>
pipe(
validateBounds(self, width),
Either.map(() => {
Result.map(() => {
const impl = self as MutableBufferImpl<Read>;
const view = MutableBytes.asDataView(impl.bytes);

Expand Down Expand Up @@ -215,7 +215,7 @@ export const putSlice = Function.dual<
>(2, (self, value) =>
pipe(
validateBounds(self, value.length),
Either.map(() => {
Result.map(() => {
const impl = self as MutableBufferImpl<Write>;

const slice = MutableBytes.asArray(impl.bytes);
Expand All @@ -232,7 +232,7 @@ export const putSlice = Function.dual<
export const getSlice = (self: ReadBuffer, byteLength: number) =>
pipe(
validateBounds(self, byteLength),
Either.map(() => {
Result.map(() => {
const impl = self as MutableBufferImpl<Read>;

const slice = MutableBytes.asArray(impl.bytes).slice(
Expand All @@ -257,15 +257,15 @@ export const advance = Function.dual<
length: number,
) => <T>(
self: MutableBuffer<T>,
) => Either.Either<MutableBuffer<T>, UnexpectedEndOfBufferError>,
) => Result.Result<MutableBuffer<T>, UnexpectedEndOfBufferError>,
<T>(
self: MutableBuffer<T>,
length: number,
) => Either.Either<MutableBuffer<T>, UnexpectedEndOfBufferError>
) => Result.Result<MutableBuffer<T>, UnexpectedEndOfBufferError>
>(2, <T>(self: MutableBuffer<T>, byteLength: number) =>
pipe(
validateBounds(self, byteLength),
Either.map(() => {
Result.map(() => {
const impl = self as MutableBufferImpl<T>;

impl.index = impl.index + byteLength;
Expand Down
Loading
Loading