Effect Utilities

import { ... } from "@95octane/common/effect"

Re-exports core Effect modules (Effect, Layer, Context, Schema, Config, Data, Logger, Option, Either, Exit, pipe) alongside custom helpers.

schemaParser

Parses unknown data against an Effect Schema. Returns validated data or fails with MyError (code INVALID_SCHEMA).

const user = yield* schemaParser(UserSchema, rawData, "getUserById");
console.log(user.name);
  • Uses permissive parsing (ignores excess properties)
  • Returns all validation errors, not just the first

schemaParserEither

Same as schemaParser but returns Either<MyError, T> for manual error handling instead of failing the Effect.

const result = yield* schemaParserEither(UserSchema, rawData, "getUserById");
if (Either.isLeft(result)) {
  // handle error
}

withSpan

Creates an OpenTelemetry span around an Effect operation for tracing.

Effect
  .gen(function*() {
    // logic
  })
  .pipe(
    withSpan("functionName", "path/to/file.ts", {
      "custom.attribute": value,
    }),
  );