(options?: {
readonly rootPath?: string | undefined
readonly preserveEmptyStrings?: boolean | undefined
}): Effect.Effect<
ConfigProvider,
never,
Path_.Path | FileSystem.FileSystem
>Creates a ConfigProvider that reads configuration from a directory tree
on disk, where each file is a leaf value and each directory is a container.
When to use
Use when you expose each config key as a file under a directory, such as Kubernetes ConfigMap or Secret volume mounts.
Details
Resolution tries a regular file first and returns a Value node for
non-empty trimmed file contents. If the file read fails, it tries a directory
and returns a Record node with immediate child names as keys. If both fail
with NotFound, it returns undefined. Other platform failures return
SourceError.
Requires Path and FileSystem in the Effect context. Defaults to root
path /; override with { rootPath: "/etc/config" }.
Literal empty strings are treated as missing values by default after file
contents are trimmed. Pass { preserveEmptyStrings: true } to keep empty
strings as explicit values. Directory listings still reflect the file names
present on disk.
Example (Reading config from a directory)
import { ConfigProvider, Effect } from "effect"
const program = Effect.gen(function*() {
const provider = yield* ConfigProvider.fromDir({
rootPath: "/etc/myapp"
})
return provider
})export const const fromDir: (options?: {
readonly rootPath?: string | undefined
readonly preserveEmptyStrings?:
| boolean
| undefined
}) => Effect.Effect<
ConfigProvider,
never,
Path_.Path | FileSystem.FileSystem
>
Creates a ConfigProvider that reads configuration from a directory tree
on disk, where each file is a leaf value and each directory is a container.
When to use
Use when you expose each config key as a file under a directory, such as
Kubernetes ConfigMap or Secret volume mounts.
Details
Resolution tries a regular file first and returns a Value node for
non-empty trimmed file contents. If the file read fails, it tries a directory
and returns a Record node with immediate child names as keys. If both fail
with NotFound, it returns undefined. Other platform failures return
SourceError.
Requires Path and FileSystem in the Effect context. Defaults to root
path /; override with { rootPath: "/etc/config" }.
Literal empty strings are treated as missing values by default after file
contents are trimmed. Pass { preserveEmptyStrings: true } to keep empty
strings as explicit values. Directory listings still reflect the file names
present on disk.
Example (Reading config from a directory)
import { ConfigProvider, Effect } from "effect"
const program = Effect.gen(function*() {
const provider = yield* ConfigProvider.fromDir({
rootPath: "/etc/myapp"
})
return provider
})
fromDir: (options: | {
readonly rootPath?: string | undefined
readonly preserveEmptyStrings?:
| boolean
| undefined
}
| undefined
options?: {
readonly rootPath?: string | undefinedrootPath?: string | undefined
readonly preserveEmptyStrings?: boolean | undefinedpreserveEmptyStrings?: boolean | undefined
}) => import EffectEffect.interface Effect<out A, out E = never, out R = never>The Effect interface defines a value that lazily describes a workflow or
job. The workflow requires some context R, and may fail with an error of
type E, or succeed with a value of type A.
When to use
Use when you need to represent a lazy, composable workflow that can require
services, fail with a typed error, or succeed with a typed value.
Details
Effect values model resourceful interaction with the outside world,
including synchronous, asynchronous, concurrent, and parallel interaction.
They use a fiber-based concurrency model, with built-in support for
scheduling, fine-grained interruption, structured concurrency, and high
scalability.
To run an Effect value, you need a Runtime, which is a type that is
capable of executing Effect values.
Effect<
ConfigProvider,
never,
import Path_Path_.Path | import FileSystemFileSystem.FileSystem
> = import EffectEffect.const fnUntraced: <Effect.Effect<FileSystem.FileSystem, never, FileSystem.FileSystem> | Effect.Effect<Path_.Path, never, Path_.Path>, ConfigProvider, [options: {
readonly rootPath?: string | undefined;
readonly preserveEmptyStrings?: boolean | undefined;
} | undefined]>(body: (this: unassigned, options: {
readonly rootPath?: string | undefined;
readonly preserveEmptyStrings?: boolean | undefined;
} | undefined) => Generator<Effect.Effect<FileSystem.FileSystem, never, FileSystem.FileSystem> | Effect.Effect<...>, ConfigProvider, never>) => (options: {
readonly rootPath?: string | undefined;
readonly preserveEmptyStrings?: boolean | undefined;
} | undefined) => Effect.Effect<...> (+41 overloads)
fnUntraced(function*(options: | {
readonly rootPath?: string | undefined
readonly preserveEmptyStrings?:
| boolean
| undefined
}
| undefined
options) {
const const platformPath: Path_.Pathconst platformPath: {
sep: string;
basename: (path: string, suffix?: string) => string;
dirname: (path: string) => string;
extname: (path: string) => string;
format: (pathObject: Partial<Path.Parsed>) => string;
fromFileUrl: (url: URL) => Effect.Effect<string, BadArgument>;
isAbsolute: (path: string) => boolean;
join: (...paths: ReadonlyArray<string>) => string;
normalize: (path: string) => string;
parse: (path: string) => Path.Parsed;
relative: (from: string, to: string) => string;
resolve: (...pathSegments: ReadonlyArray<string>) => string;
toFileUrl: (path: string) => Effect.Effect<URL, BadArgument>;
toNamespacedPath: (path: string) => string;
}
platformPath = yield* import Path_Path_.const Path: Context.Service<Path_.Path, Path_.Path>namespace Path
const Path: {
key: string;
Service: {
sep: string;
basename: (path: string, suffix?: string) => string;
dirname: (path: string) => string;
extname: (path: string) => string;
format: (pathObject: Partial<Path.Parsed>) => string;
fromFileUrl: (url: URL) => Effect.Effect<string, BadArgument>;
isAbsolute: (path: string) => boolean;
join: (...paths: ReadonlyArray<string>) => string;
normalize: (path: string) => string;
parse: (path: string) => Path.Parsed;
relative: (from: string, to: string) => string;
resolve: (...pathSegments: ReadonlyArray<string>) => string;
toFileUrl: (path: string) => Effect.Effect<URL, BadArgument>;
toNamespacedPath: (path: string) => string;
};
of: (this: void, self: Path_.Path) => Path_.Path;
context: (self: Path_.Path) => Context.Context<Path_.Path>;
use: (f: (service: Path_.Path) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, Path_.Path | R>;
useSync: (f: (service: Path_.Path) => A) => Effect.Effect<A, never, Path_.Path>;
Identifier: Identifier;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
Defines the service interface for platform-specific path manipulation.
When to use
Use to depend on path operations through the Effect environment instead of a
concrete host path module.
Details
The service exposes operations for joining, normalizing, parsing,
formatting, and converting file system paths. URL conversion methods return
Effects because invalid file URLs or paths can fail with BadArgument.
Example (Using path operations)
import { Effect, Path } from "effect"
const program = Effect.gen(function*() {
const path = yield* Path.Path
// Use various path operations
const joined = path.join("home", "user", "documents")
const normalized = path.normalize("./path/../to/file.txt")
const basename = path.basename("/path/to/file.txt")
const dirname = path.dirname("/path/to/file.txt")
const extname = path.extname("file.txt")
const isAbs = path.isAbsolute("/absolute/path")
const parsed = path.parse("/path/to/file.txt")
const relative = path.relative("/from/path", "/to/path")
const resolved = path.resolve("relative", "path")
console.log({
joined,
normalized,
basename,
dirname,
extname,
isAbs,
parsed,
relative,
resolved
})
})
Namespace containing types associated with the Path service.
When to use
Use to reference types associated with path parsing and formatting.
Example (Working with parsed paths)
import { Effect, Path } from "effect"
// Access types and utilities in the Path namespace
const program = Effect.gen(function*() {
const path = yield* Path.Path
// Parse a path and get a Path.Parsed object
const parsed = path.parse("/home/user/file.txt")
// The parsed object conforms to the Path.Parsed interface
const exampleParsed = {
root: "/",
dir: "/home/user",
base: "file.txt",
ext: ".txt",
name: "file"
}
console.log(parsed, exampleParsed)
})
Service tag for accessing the current Path implementation.
When to use
Use when you need path operations supplied by an effect's environment.
Example (Providing a custom Path service)
import { Effect, Layer, Path } from "effect"
// Create a custom path implementation
const customPath: Path.Path = {
[Path.TypeId]: Path.TypeId,
sep: "/",
basename: (path: string, suffix?: string) => {
const base = path.split("/").pop() || ""
return suffix && base.endsWith(suffix)
? base.slice(0, -suffix.length)
: base
},
dirname: (path: string) => path.split("/").slice(0, -1).join("/") || "/",
extname: (path: string) => {
const match = path.match(/\.[^.]*$/)
return match ? match[0] : ""
},
format: (pathObject) => {
const dir = pathObject.dir || ""
const name = pathObject.name || ""
const ext = pathObject.ext || ""
return dir ? `${dir}/${name}${ext}` : `${name}${ext}`
},
fromFileUrl: (url: URL) => Effect.succeed(url.pathname),
isAbsolute: (path: string) => path.startsWith("/"),
join: (...paths: ReadonlyArray<string>) => paths.join("/"),
normalize: (path: string) => path.replace(/\/+/g, "/"),
parse: (path: string) => ({
root: path.startsWith("/") ? "/" : "",
dir: path.split("/").slice(0, -1).join("/") || "/",
base: path.split("/").pop() || "",
ext: path.match(/\.[^.]*$/)?.[0] || "",
name: path.split("/").pop()?.replace(/\.[^.]*$/, "") || ""
}),
relative: (from: string, to: string) => to.replace(from, ""),
resolve: (...pathSegments: ReadonlyArray<string>) => pathSegments.join("/"),
toFileUrl: (path: string) => Effect.succeed(new URL(`file://${path}`)),
toNamespacedPath: (path: string) => path
}
// Provide the path service
const customPathLayer = Layer.succeed(Path.Path)(customPath)
const program = Effect.gen(function*() {
const path = yield* Path.Path
const joined = path.join("home", "user", "file.txt")
console.log(joined) // "home/user/file.txt"
})
// Run with custom path implementation
const result = Effect.provide(program, customPathLayer)
Path
const const fs: FileSystem.FileSystemconst fs: {
access: (path: string, options?: { readonly ok?: boolean | undefined; readonly readable?: boolean | undefined; readonly writable?: boolean | undefined }) => Effect.Effect<void, PlatformError>;
copy: (fromPath: string, toPath: string, options?: { readonly overwrite?: boolean | undefined; readonly preserveTimestamps?: boolean | undefined }) => Effect.Effect<void, PlatformError>;
copyFile: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError>;
chmod: (path: string, mode: number) => Effect.Effect<void, PlatformError>;
chown: (path: string, uid: number, gid: number) => Effect.Effect<void, PlatformError>;
glob: (pattern: string, options?: { readonly root?: string | undefined; readonly exclude?: ReadonlyArray<string> | undefined }) => Effect.Effect<Array<string>, PlatformError>;
exists: (path: string) => Effect.Effect<boolean, PlatformError>;
link: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError>;
makeDirectory: (path: string, options?: { readonly recursive?: boolean | undefined; readonly mode?: number | undefined }) => Effect.Effect<void, PlatformError>;
makeTempDirectory: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined }) => Effect.Effect<string, PlatformError>;
makeTempDirectoryScoped: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined }) => Effect.Effect<string, PlatformError, Scope>;
makeTempFile: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined; readonly suffix?: string | undefined }) => Effect.Effect<string, PlatformError>;
makeTempFileScoped: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined; readonly suffix?: string | undefined }) => Effect.Effect<string, PlatformError, Scope>;
open: (path: string, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Effect.Effect<File, PlatformError, Scope>;
readDirectory: (path: string, options?: { readonly recursive?: boolean | undefined }) => Effect.Effect<Array<string>, PlatformError>;
readFile: (path: string) => Effect.Effect<Uint8Array, PlatformError>;
readFileString: (path: string, encoding?: string) => Effect.Effect<string, PlatformError>;
readLink: (path: string) => Effect.Effect<string, PlatformError>;
realPath: (path: string) => Effect.Effect<string, PlatformError>;
remove: (path: string, options?: { readonly recursive?: boolean | undefined; readonly force?: boolean | undefined }) => Effect.Effect<void, PlatformError>;
rename: (oldPath: string, newPath: string) => Effect.Effect<void, PlatformError>;
sink: (path: string, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Sink.Sink<void, Uint8Array, never, PlatformError>;
stat: (path: string) => Effect.Effect<File.Info, PlatformError>;
stream: (path: string, options?: { readonly bytesToRead?: SizeInput | undefined; readonly chunkSize?: SizeInput | undefined; readonly offset?: SizeInput | undefined }) => Stream.Stream<Uint8Array, PlatformError>;
symlink: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError>;
truncate: (path: string, length?: SizeInput) => Effect.Effect<void, PlatformError>;
utimes: (path: string, atime: Date | number, mtime: Date | number) => Effect.Effect<void, PlatformError>;
watch: (path: string) => Stream.Stream<WatchEvent, PlatformError>;
writeFile: (path: string, data: Uint8Array, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Effect.Effect<void, PlatformError>;
writeFileString: (path: string, data: string, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Effect.Effect<void, PlatformError>;
}
fs = yield* import FileSystemFileSystem.const FileSystem: Context.Service<
FileSystem,
FileSystem
>
const FileSystem: {
key: string;
Service: {
access: (path: string, options?: { readonly ok?: boolean | undefined; readonly readable?: boolean | undefined; readonly writable?: boolean | undefined }) => Effect.Effect<void, PlatformError>;
copy: (fromPath: string, toPath: string, options?: { readonly overwrite?: boolean | undefined; readonly preserveTimestamps?: boolean | undefined }) => Effect.Effect<void, PlatformError>;
copyFile: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError>;
chmod: (path: string, mode: number) => Effect.Effect<void, PlatformError>;
chown: (path: string, uid: number, gid: number) => Effect.Effect<void, PlatformError>;
glob: (pattern: string, options?: { readonly root?: string | undefined; readonly exclude?: ReadonlyArray<string> | undefined }) => Effect.Effect<Array<string>, PlatformError>;
exists: (path: string) => Effect.Effect<boolean, PlatformError>;
link: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError>;
makeDirectory: (path: string, options?: { readonly recursive?: boolean | undefined; readonly mode?: number | undefined }) => Effect.Effect<void, PlatformError>;
makeTempDirectory: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined }) => Effect.Effect<string, PlatformError>;
makeTempDirectoryScoped: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined }) => Effect.Effect<string, PlatformError, Scope>;
makeTempFile: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined; readonly suffix?: string | undefined }) => Effect.Effect<string, PlatformError>;
makeTempFileScoped: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined; readonly suffix?: string | undefined }) => Effect.Effect<string, PlatformError, Scope>;
open: (path: string, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Effect.Effect<File, PlatformError, Scope>;
readDirectory: (path: string, options?: { readonly recursive?: boolean | undefined }) => Effect.Effect<Array<string>, PlatformError>;
readFile: (path: string) => Effect.Effect<Uint8Array, PlatformError>;
readFileString: (path: string, encoding?: string) => Effect.Effect<string, PlatformError>;
readLink: (path: string) => Effect.Effect<string, PlatformError>;
realPath: (path: string) => Effect.Effect<string, PlatformError>;
remove: (path: string, options?: { readonly recursive?: boolean | undefined; readonly force?: boolean | undefined }) => Effect.Effect<void, PlatformError>;
rename: (oldPath: string, newPath: string) => Effect.Effect<void, PlatformError>;
sink: (path: string, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Sink.Sink<void, Uint8Array, never, PlatformError>;
stat: (path: string) => Effect.Effect<File.Info, PlatformError>;
stream: (path: string, options?: { readonly bytesToRead?: SizeInput | undefined; readonly chunkSize?: SizeInput | undefined; readonly offset?: SizeInput | undefined }) => Stream.Stream<Uint8Array, PlatformError>;
symlink: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError>;
truncate: (path: string, length?: SizeInput) => Effect.Effect<void, PlatformError>;
utimes: (path: string, atime: Date | number, mtime: Date | number) => Effect.Effect<void, PlatformError>;
watch: (path: string) => Stream.Stream<WatchEvent, PlatformError>;
writeFile: (path: string, data: Uint8Array, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Effect.Effect<void, PlatformError>;
writeFileString: (path: string, data: string, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Effect.Effect<void, PlatformError>;
};
of: (this: void, self: FileSystem.FileSystem) => FileSystem.FileSystem;
context: (self: FileSystem.FileSystem) => Context.Context<FileSystem.FileSystem>;
use: (f: (service: FileSystem.FileSystem) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, FileSystem.FileSystem | R>;
useSync: (f: (service: FileSystem.FileSystem) => A) => Effect.Effect<A, never, FileSystem.FileSystem>;
Identifier: Identifier;
stack: string | undefined;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
Core interface for file system operations in Effect.
Details
The FileSystem interface provides a comprehensive set of file and directory operations
that work cross-platform. All operations return Effect values that can be composed,
transformed, and executed safely with proper error handling.
Example (Accessing file system operations)
import { Console, Effect, FileSystem } from "effect"
const program = Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
// Basic file operations
const exists = yield* fs.exists("./config.json")
if (!exists) {
yield* fs.writeFileString("./config.json", "{\"env\": \"development\"}")
}
// Directory operations
yield* fs.makeDirectory("./logs", { recursive: true })
// File information
const stats = yield* fs.stat("./config.json")
yield* Console.log(`File size: ${stats.size} bytes`)
// Streaming operations
const content = yield* fs.readFileString("./config.json")
yield* Console.log("Config:", content)
})
Service tag for platform file-system operations.
When to use
Use to access or provide operations for files, directories, permissions,
streams, and sinks through the Effect context.
Details
This key is used to provide and access the FileSystem service in the Effect context.
Example (Accessing and providing FileSystem)
import { Effect, FileSystem } from "effect"
// Access the FileSystem service
const program = Effect.gen(function*() {
const fs = yield* FileSystem.FileSystem
const exists = yield* fs.exists("./data.txt")
if (exists) {
const content = yield* fs.readFileString("./data.txt")
yield* Effect.log("File content:", content)
}
})
// Provide a custom FileSystem implementation
declare const platformImpl: Omit<
FileSystem.FileSystem,
"exists" | "readFileString" | "stream" | "sink" | "writeFileString"
>
const customFs = FileSystem.make(platformImpl)
const withCustomFs = Effect.provideService(
program,
FileSystem.FileSystem,
customFs
)
FileSystem
const const rootPath: stringrootPath = options: | {
readonly rootPath?: string | undefined
readonly preserveEmptyStrings?:
| boolean
| undefined
}
| undefined
options?.rootPath?: string | undefinedrootPath ?? "/"
const const preserveEmptyStrings: booleanpreserveEmptyStrings = options: | {
readonly rootPath?: string | undefined
readonly preserveEmptyStrings?:
| boolean
| undefined
}
| undefined
options?.preserveEmptyStrings?: boolean | undefinedpreserveEmptyStrings === true
return function make(
get: (
path: Path
) => Effect.Effect<
Node | undefined,
SourceError
>
): ConfigProvider
Creates a ConfigProvider from a raw lookup function.
When to use
Use when implementing a provider backed by a custom store, such as a
database, remote API, or in-memory map.
Details
The get callback receives a Path and must return
Effect<Node | undefined, SourceError>. Return undefined when the path
does not exist; fail with SourceError only for actual I/O errors.
Example (Creating a simple in-memory provider)
import { ConfigProvider, Effect } from "effect"
const data: Record<string, string> = {
host: "localhost",
port: "5432"
}
const provider = ConfigProvider.make((path) => {
const key = path.join(".")
const value = data[key]
return Effect.succeed(
value !== undefined ? ConfigProvider.makeValue(value) : undefined
)
})
make((path: Path(parameter) path: {
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<string | number>>): Array<string | number>; (...items: Array<string | number | ConcatArray<string | number>>): Array<string | number> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<string | number>;
indexOf: (searchElement: string | number, fromIndex?: number) => number;
lastIndexOf: (searchElement: string | number, fromIndex?: number) => number;
every: { (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) =>…;
some: (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: string | number, index: number, array: ReadonlyArray<string | number>) => void, thisArg?: any) => void;
map: (callbackfn: (value: string | number, index: number, array: ReadonlyArray<string | number>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => value is S, thisArg?: any): Array<S>; (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => unknown, th…;
reduce: { (callbackfn: (previousValue: string | number, currentValue: string | number, currentIndex: number, array: ReadonlyArray<string | number>) => string | number): string | number; (callbackfn: (previousValue: string | number, currentValue: s…;
reduceRight: { (callbackfn: (previousValue: string | number, currentValue: string | number, currentIndex: number, array: ReadonlyArray<string | number>) => string | number): string | number; (callbackfn: (previousValue: string | number, currentValue: s…;
find: { (predicate: (value: string | number, index: number, obj: ReadonlyArray<string | number>) => value is S, thisArg?: any): S | undefined; (predicate: (value: string | number, index: number, obj: ReadonlyArray<string | number>) => unknown, t…;
findIndex: (predicate: (value: string | number, index: number, obj: ReadonlyArray<string | number>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, string | number]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<string | number>;
includes: (searchElement: string | number, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: string | number, index: number, array: Array<string | number>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => string | number | undefined;
findLast: { (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => value is S, thisArg?: any): S | undefined; (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => unknow…;
findLastIndex: (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => unknown, thisArg?: any) => number;
toReversed: () => Array<string | number>;
toSorted: (compareFn?: ((a: string | number, b: string | number) => number) | undefined) => Array<string | number>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<string | number>): Array<string | number>; (start: number, deleteCount?: number): Array<string | number> };
with: (index: number, value: string | number) => Array<string | number>;
}
path) => {
const const fullPath: stringfullPath = const platformPath: Path_.Pathconst platformPath: {
sep: string;
basename: (path: string, suffix?: string) => string;
dirname: (path: string) => string;
extname: (path: string) => string;
format: (pathObject: Partial<Path.Parsed>) => string;
fromFileUrl: (url: URL) => Effect.Effect<string, BadArgument>;
isAbsolute: (path: string) => boolean;
join: (...paths: ReadonlyArray<string>) => string;
normalize: (path: string) => string;
parse: (path: string) => Path.Parsed;
relative: (from: string, to: string) => string;
resolve: (...pathSegments: ReadonlyArray<string>) => string;
toFileUrl: (path: string) => Effect.Effect<URL, BadArgument>;
toNamespacedPath: (path: string) => string;
}
platformPath.Path.join: (...paths: ReadonlyArray<string>) => stringjoin(const rootPath: stringrootPath, ...path: Path(parameter) path: {
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<string | number>>): Array<string | number>; (...items: Array<string | number | ConcatArray<string | number>>): Array<string | number> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<string | number>;
indexOf: (searchElement: string | number, fromIndex?: number) => number;
lastIndexOf: (searchElement: string | number, fromIndex?: number) => number;
every: { (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) =>…;
some: (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: string | number, index: number, array: ReadonlyArray<string | number>) => void, thisArg?: any) => void;
map: (callbackfn: (value: string | number, index: number, array: ReadonlyArray<string | number>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => value is S, thisArg?: any): Array<S>; (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => unknown, th…;
reduce: { (callbackfn: (previousValue: string | number, currentValue: string | number, currentIndex: number, array: ReadonlyArray<string | number>) => string | number): string | number; (callbackfn: (previousValue: string | number, currentValue: s…;
reduceRight: { (callbackfn: (previousValue: string | number, currentValue: string | number, currentIndex: number, array: ReadonlyArray<string | number>) => string | number): string | number; (callbackfn: (previousValue: string | number, currentValue: s…;
find: { (predicate: (value: string | number, index: number, obj: ReadonlyArray<string | number>) => value is S, thisArg?: any): S | undefined; (predicate: (value: string | number, index: number, obj: ReadonlyArray<string | number>) => unknown, t…;
findIndex: (predicate: (value: string | number, index: number, obj: ReadonlyArray<string | number>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, string | number]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<string | number>;
includes: (searchElement: string | number, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: string | number, index: number, array: Array<string | number>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => string | number | undefined;
findLast: { (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => value is S, thisArg?: any): S | undefined; (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => unknow…;
findLastIndex: (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => unknown, thisArg?: any) => number;
toReversed: () => Array<string | number>;
toSorted: (compareFn?: ((a: string | number, b: string | number) => number) | undefined) => Array<string | number>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<string | number>): Array<string | number>; (start: number, deleteCount?: number): Array<string | number> };
with: (index: number, value: string | number) => Array<string | number>;
}
path.ReadonlyArray<string | number>.map<string>(callbackfn: (value: string | number, index: number, array: readonly (string | number)[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(var String: StringConstructorAllows manipulation and formatting of text strings and determination and location of substrings within strings.
String))
// Try reading as a *file*
const const asFile: Effect.Effect<
Node | undefined,
PlatformError,
never
>
const asFile: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
asFile = const fs: FileSystem.FileSystemconst fs: {
access: (path: string, options?: { readonly ok?: boolean | undefined; readonly readable?: boolean | undefined; readonly writable?: boolean | undefined }) => Effect.Effect<void, PlatformError>;
copy: (fromPath: string, toPath: string, options?: { readonly overwrite?: boolean | undefined; readonly preserveTimestamps?: boolean | undefined }) => Effect.Effect<void, PlatformError>;
copyFile: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError>;
chmod: (path: string, mode: number) => Effect.Effect<void, PlatformError>;
chown: (path: string, uid: number, gid: number) => Effect.Effect<void, PlatformError>;
glob: (pattern: string, options?: { readonly root?: string | undefined; readonly exclude?: ReadonlyArray<string> | undefined }) => Effect.Effect<Array<string>, PlatformError>;
exists: (path: string) => Effect.Effect<boolean, PlatformError>;
link: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError>;
makeDirectory: (path: string, options?: { readonly recursive?: boolean | undefined; readonly mode?: number | undefined }) => Effect.Effect<void, PlatformError>;
makeTempDirectory: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined }) => Effect.Effect<string, PlatformError>;
makeTempDirectoryScoped: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined }) => Effect.Effect<string, PlatformError, Scope>;
makeTempFile: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined; readonly suffix?: string | undefined }) => Effect.Effect<string, PlatformError>;
makeTempFileScoped: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined; readonly suffix?: string | undefined }) => Effect.Effect<string, PlatformError, Scope>;
open: (path: string, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Effect.Effect<File, PlatformError, Scope>;
readDirectory: (path: string, options?: { readonly recursive?: boolean | undefined }) => Effect.Effect<Array<string>, PlatformError>;
readFile: (path: string) => Effect.Effect<Uint8Array, PlatformError>;
readFileString: (path: string, encoding?: string) => Effect.Effect<string, PlatformError>;
readLink: (path: string) => Effect.Effect<string, PlatformError>;
realPath: (path: string) => Effect.Effect<string, PlatformError>;
remove: (path: string, options?: { readonly recursive?: boolean | undefined; readonly force?: boolean | undefined }) => Effect.Effect<void, PlatformError>;
rename: (oldPath: string, newPath: string) => Effect.Effect<void, PlatformError>;
sink: (path: string, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Sink.Sink<void, Uint8Array, never, PlatformError>;
stat: (path: string) => Effect.Effect<File.Info, PlatformError>;
stream: (path: string, options?: { readonly bytesToRead?: SizeInput | undefined; readonly chunkSize?: SizeInput | undefined; readonly offset?: SizeInput | undefined }) => Stream.Stream<Uint8Array, PlatformError>;
symlink: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError>;
truncate: (path: string, length?: SizeInput) => Effect.Effect<void, PlatformError>;
utimes: (path: string, atime: Date | number, mtime: Date | number) => Effect.Effect<void, PlatformError>;
watch: (path: string) => Stream.Stream<WatchEvent, PlatformError>;
writeFile: (path: string, data: Uint8Array, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Effect.Effect<void, PlatformError>;
writeFileString: (path: string, data: string, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Effect.Effect<void, PlatformError>;
}
fs.FileSystem.readFileString: (path: string, encoding?: string) => Effect.Effect<string, PlatformError>Read the contents of a file.
readFileString(const fullPath: stringfullPath).Pipeable.pipe<Effect.Effect<string, PlatformError, never>, Effect.Effect<Node | undefined, PlatformError, never>>(this: Effect.Effect<string, PlatformError, never>, ab: (_: Effect.Effect<string, PlatformError, never>) => Effect.Effect<Node | undefined, PlatformError, never>): Effect.Effect<Node | undefined, PlatformError, never> (+21 overloads)pipe(
import EffectEffect.const map: {
<A, B>(f: (a: A) => B): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E, R>
<A, E, R, B>(
self: Effect<A, E, R>,
f: (a: A) => B
): Effect<B, E, R>
}
map((content: stringcontent) => function stringNode(
value: string,
preserveEmptyStrings: boolean
): Node | undefined
stringNode(content: stringcontent.String.trim(): stringRemoves the leading and trailing white space and line terminator characters from a string.
trim(), const preserveEmptyStrings: booleanpreserveEmptyStrings))
)
// If not a file, try reading as a *directory*
const const asDirectory: Effect.Effect<
Node,
PlatformError,
never
>
const asDirectory: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
asDirectory = const fs: FileSystem.FileSystemconst fs: {
access: (path: string, options?: { readonly ok?: boolean | undefined; readonly readable?: boolean | undefined; readonly writable?: boolean | undefined }) => Effect.Effect<void, PlatformError>;
copy: (fromPath: string, toPath: string, options?: { readonly overwrite?: boolean | undefined; readonly preserveTimestamps?: boolean | undefined }) => Effect.Effect<void, PlatformError>;
copyFile: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError>;
chmod: (path: string, mode: number) => Effect.Effect<void, PlatformError>;
chown: (path: string, uid: number, gid: number) => Effect.Effect<void, PlatformError>;
glob: (pattern: string, options?: { readonly root?: string | undefined; readonly exclude?: ReadonlyArray<string> | undefined }) => Effect.Effect<Array<string>, PlatformError>;
exists: (path: string) => Effect.Effect<boolean, PlatformError>;
link: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError>;
makeDirectory: (path: string, options?: { readonly recursive?: boolean | undefined; readonly mode?: number | undefined }) => Effect.Effect<void, PlatformError>;
makeTempDirectory: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined }) => Effect.Effect<string, PlatformError>;
makeTempDirectoryScoped: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined }) => Effect.Effect<string, PlatformError, Scope>;
makeTempFile: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined; readonly suffix?: string | undefined }) => Effect.Effect<string, PlatformError>;
makeTempFileScoped: (options?: { readonly directory?: string | undefined; readonly prefix?: string | undefined; readonly suffix?: string | undefined }) => Effect.Effect<string, PlatformError, Scope>;
open: (path: string, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Effect.Effect<File, PlatformError, Scope>;
readDirectory: (path: string, options?: { readonly recursive?: boolean | undefined }) => Effect.Effect<Array<string>, PlatformError>;
readFile: (path: string) => Effect.Effect<Uint8Array, PlatformError>;
readFileString: (path: string, encoding?: string) => Effect.Effect<string, PlatformError>;
readLink: (path: string) => Effect.Effect<string, PlatformError>;
realPath: (path: string) => Effect.Effect<string, PlatformError>;
remove: (path: string, options?: { readonly recursive?: boolean | undefined; readonly force?: boolean | undefined }) => Effect.Effect<void, PlatformError>;
rename: (oldPath: string, newPath: string) => Effect.Effect<void, PlatformError>;
sink: (path: string, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Sink.Sink<void, Uint8Array, never, PlatformError>;
stat: (path: string) => Effect.Effect<File.Info, PlatformError>;
stream: (path: string, options?: { readonly bytesToRead?: SizeInput | undefined; readonly chunkSize?: SizeInput | undefined; readonly offset?: SizeInput | undefined }) => Stream.Stream<Uint8Array, PlatformError>;
symlink: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError>;
truncate: (path: string, length?: SizeInput) => Effect.Effect<void, PlatformError>;
utimes: (path: string, atime: Date | number, mtime: Date | number) => Effect.Effect<void, PlatformError>;
watch: (path: string) => Stream.Stream<WatchEvent, PlatformError>;
writeFile: (path: string, data: Uint8Array, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Effect.Effect<void, PlatformError>;
writeFileString: (path: string, data: string, options?: { readonly flag?: OpenFlag | undefined; readonly mode?: number | undefined }) => Effect.Effect<void, PlatformError>;
}
fs.FileSystem.readDirectory: (path: string, options?: { readonly recursive?: boolean | undefined }) => Effect.Effect<Array<string>, PlatformError>List the contents of a directory.
Details
You can recursively list the contents of nested directories by setting the
recursive option.
readDirectory(const fullPath: stringfullPath).Pipeable.pipe<Effect.Effect<string[], PlatformError, never>, Effect.Effect<Node, PlatformError, never>>(this: Effect.Effect<string[], PlatformError, never>, ab: (_: Effect.Effect<string[], PlatformError, never>) => Effect.Effect<Node, PlatformError, never>): Effect.Effect<Node, PlatformError, never> (+21 overloads)pipe(
import EffectEffect.const map: {
<A, B>(f: (a: A) => B): <E, R>(
self: Effect<A, E, R>
) => Effect<B, E, R>
<A, E, R, B>(
self: Effect<A, E, R>,
f: (a: A) => B
): Effect<B, E, R>
}
map((entries: string[]entries) => function makeRecord(
keys: ReadonlySet<string>,
value?: string
): Node
Creates a Record node representing an object-like container with known
child keys.
When to use
Use when you need to describe a directory or JSON object inside a custom
provider.
Details
The optional value allows a node to be both a container and a leaf at the
same time (for example, an env var A=x that also has children A_FOO and
A_BAR).
Example (Creating a record node)
import { ConfigProvider } from "effect"
const node = ConfigProvider.makeRecord(new Set(["host", "port"]))
// { _tag: "Record", keys: Set(["host", "port"]), value: undefined }
makeRecord(new var Set: SetConstructor
new <string>(iterable?: Iterable<string> | null | undefined) => Set<string> (+1 overload)
Set(entries: string[]entries.Array<string>.map<string>(callbackfn: (value: string, index: number, array: string[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((entry: stringentry) => const platformPath: Path_.Pathconst platformPath: {
sep: string;
basename: (path: string, suffix?: string) => string;
dirname: (path: string) => string;
extname: (path: string) => string;
format: (pathObject: Partial<Path.Parsed>) => string;
fromFileUrl: (url: URL) => Effect.Effect<string, BadArgument>;
isAbsolute: (path: string) => boolean;
join: (...paths: ReadonlyArray<string>) => string;
normalize: (path: string) => string;
parse: (path: string) => Path.Parsed;
relative: (from: string, to: string) => string;
resolve: (...pathSegments: ReadonlyArray<string>) => string;
toFileUrl: (path: string) => Effect.Effect<URL, BadArgument>;
toNamespacedPath: (path: string) => string;
}
platformPath.Path.basename: (path: string, suffix?: string) => stringbasename(entry: stringentry)))))
)
return const asFile: Effect.Effect<
Node | undefined,
PlatformError,
never
>
const asFile: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
asFile.Pipeable.pipe<Effect.Effect<Node | undefined, PlatformError, never>, Effect.Effect<Node | undefined, PlatformError, never>, Effect.Effect<Node | undefined, SourceError, never>>(this: Effect.Effect<...>, ab: (_: Effect.Effect<Node | undefined, PlatformError, never>) => Effect.Effect<Node | undefined, PlatformError, never>, bc: (_: Effect.Effect<Node | undefined, PlatformError, never>) => Effect.Effect<...>): Effect.Effect<...> (+21 overloads)pipe(
import EffectEffect.catch<PlatformError, Node | undefined, PlatformError, never>(f: (e: PlatformError) => Effect.Effect<Node | undefined, PlatformError, never>): <A, R>(self: Effect.Effect<A, PlatformError, R>) => Effect.Effect<Node | A | undefined, PlatformError, R> (+1 overload)
export catch
catch((fileCause: PlatformError(parameter) fileCause: {
message: string;
name: string;
stack: string;
cause: unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
_tag: Tag;
reason: BadArgument | SystemError;
}
fileCause) =>
const asDirectory: Effect.Effect<
Node,
PlatformError,
never
>
const asDirectory: {
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
asDirectory.Pipeable.pipe<Effect.Effect<Node, PlatformError, never>, Effect.Effect<Node | undefined, PlatformError, never>>(this: Effect.Effect<Node, PlatformError, never>, ab: (_: Effect.Effect<Node, PlatformError, never>) => Effect.Effect<Node | undefined, PlatformError, never>): Effect.Effect<Node | undefined, PlatformError, never> (+21 overloads)pipe(
import EffectEffect.catch<PlatformError, undefined, PlatformError, never>(f: (e: PlatformError) => Effect.Effect<undefined, PlatformError, never>): <A, R>(self: Effect.Effect<A, PlatformError, R>) => Effect.Effect<A | undefined, PlatformError, R> (+1 overload)
export catch
catch((dirCause: PlatformError(parameter) dirCause: {
message: string;
name: string;
stack: string;
cause: unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
_tag: Tag;
reason: BadArgument | SystemError;
}
dirCause) =>
const isNotFound: (
cause: PlatformError
) => boolean
isNotFound(fileCause: PlatformError(parameter) fileCause: {
message: string;
name: string;
stack: string;
cause: unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
_tag: Tag;
reason: BadArgument | SystemError;
}
fileCause) && const isNotFound: (
cause: PlatformError
) => boolean
isNotFound(dirCause: PlatformError(parameter) dirCause: {
message: string;
name: string;
stack: string;
cause: unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
_tag: Tag;
reason: BadArgument | SystemError;
}
dirCause)
? import EffectEffect.const succeed: <A>(value: A) => Effect<A>Creates an Effect that always succeeds with a given value.
When to use
Use when an effect should complete successfully with a specific value without any errors
or external dependencies.
Example (Creating a successful effect)
import { Effect } from "effect"
// Creating an effect that represents a successful scenario
//
// ┌─── Effect<number, never, never>
// ▼
const success = Effect.succeed(42)
succeed(var undefinedundefined)
: import EffectEffect.const fail: <E>(
error: E
) => Effect<never, E>
Creates an Effect that represents a recoverable error.
When to use
Use to explicitly signal a recoverable error in an Effect.
Details
The error keeps propagating unless it is handled. You can handle tagged
errors with functions like
catchTag
or
catchTags
.
Example (Creating a failed effect)
import { Data, Effect } from "effect"
class OperationFailedError extends Data.TaggedError("OperationFailedError")<{}> {}
// ┌─── Effect<never, OperationFailedError, never>
// ▼
const failure = Effect.fail(
new OperationFailedError()
)
fail(const isNotFound: (
cause: PlatformError
) => boolean
isNotFound(fileCause: PlatformError(parameter) fileCause: {
message: string;
name: string;
stack: string;
cause: unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
_tag: Tag;
reason: BadArgument | SystemError;
}
fileCause) ? dirCause: PlatformError(parameter) dirCause: {
message: string;
name: string;
stack: string;
cause: unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
_tag: Tag;
reason: BadArgument | SystemError;
}
dirCause : fileCause: PlatformError(parameter) fileCause: {
message: string;
name: string;
stack: string;
cause: unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
_tag: Tag;
reason: BadArgument | SystemError;
}
fileCause)
)
)
),
import EffectEffect.const mapError: {
<E, E2>(f: (e: E) => E2): <A, R>(
self: Effect<A, E, R>
) => Effect<A, E2, R>
<A, E, R, E2>(
self: Effect<A, E, R>,
f: (e: E) => E2
): Effect<A, E2, R>
}
mapError((cause: PlatformError(parameter) cause: {
message: string;
name: string;
stack: string;
cause: unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
_tag: Tag;
reason: BadArgument | SystemError;
}
cause: class PlatformErrorclass PlatformError {
message: string;
name: string;
stack: string;
cause: unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
_tag: Tag;
reason: BadArgument | SystemError;
}
Tagged error used by platform APIs to report either invalid arguments or
system-level failures.
When to use
Use as the shared error type for platform APIs that expose invalid arguments
and host or operating-system failures through a single Effect error
channel.
Details
The reason field contains the underlying BadArgument or SystemError.
When that reason has a cause, the cause is preserved on the wrapper.
PlatformError) =>
new constructor SourceError<{
readonly message: string;
readonly cause?: unknown;
}>(args: {
readonly message: string;
readonly cause?: unknown;
}): Cause.YieldableError & {
readonly _tag: Tag;
} & Readonly<A>
Typed error indicating that a configuration source could not be read.
When to use
Use when you need to report that a custom provider's underlying store is
unreachable or produced an I/O error while reading configuration data.
Gotchas
Do not use SourceError for "key not found". That case is represented by
returning undefined from load.
Example (Failing with a SourceError)
import { ConfigProvider, Effect } from "effect"
const provider = ConfigProvider.make((_path) =>
Effect.fail(
new ConfigProvider.SourceError({ message: "connection refused" })
)
)
SourceError({
message: stringmessage: `Failed to read file at ${const platformPath: Path_.Pathconst platformPath: {
sep: string;
basename: (path: string, suffix?: string) => string;
dirname: (path: string) => string;
extname: (path: string) => string;
format: (pathObject: Partial<Path.Parsed>) => string;
fromFileUrl: (url: URL) => Effect.Effect<string, BadArgument>;
isAbsolute: (path: string) => boolean;
join: (...paths: ReadonlyArray<string>) => string;
normalize: (path: string) => string;
parse: (path: string) => Path.Parsed;
relative: (from: string, to: string) => string;
resolve: (...pathSegments: ReadonlyArray<string>) => string;
toFileUrl: (path: string) => Effect.Effect<URL, BadArgument>;
toNamespacedPath: (path: string) => string;
}
platformPath.Path.join: (...paths: ReadonlyArray<string>) => stringjoin(const rootPath: stringrootPath, ...path: Path(parameter) path: {
length: number;
toString: () => string;
toLocaleString: { (): string; (locales: string | string[], options?: Intl.NumberFormatOptions & Intl.DateTimeFormatOptions): string };
concat: { (...items: Array<ConcatArray<string | number>>): Array<string | number>; (...items: Array<string | number | ConcatArray<string | number>>): Array<string | number> };
join: (separator?: string) => string;
slice: (start?: number, end?: number) => Array<string | number>;
indexOf: (searchElement: string | number, fromIndex?: number) => number;
lastIndexOf: (searchElement: string | number, fromIndex?: number) => number;
every: { (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => value is S, thisArg?: any): this is readonly S[]; (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) =>…;
some: (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => unknown, thisArg?: any) => boolean;
forEach: (callbackfn: (value: string | number, index: number, array: ReadonlyArray<string | number>) => void, thisArg?: any) => void;
map: (callbackfn: (value: string | number, index: number, array: ReadonlyArray<string | number>) => U, thisArg?: any) => Array<U>;
filter: { (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => value is S, thisArg?: any): Array<S>; (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => unknown, th…;
reduce: { (callbackfn: (previousValue: string | number, currentValue: string | number, currentIndex: number, array: ReadonlyArray<string | number>) => string | number): string | number; (callbackfn: (previousValue: string | number, currentValue: s…;
reduceRight: { (callbackfn: (previousValue: string | number, currentValue: string | number, currentIndex: number, array: ReadonlyArray<string | number>) => string | number): string | number; (callbackfn: (previousValue: string | number, currentValue: s…;
find: { (predicate: (value: string | number, index: number, obj: ReadonlyArray<string | number>) => value is S, thisArg?: any): S | undefined; (predicate: (value: string | number, index: number, obj: ReadonlyArray<string | number>) => unknown, t…;
findIndex: (predicate: (value: string | number, index: number, obj: ReadonlyArray<string | number>) => unknown, thisArg?: any) => number;
entries: () => ArrayIterator<[number, string | number]>;
keys: () => ArrayIterator<number>;
values: () => ArrayIterator<string | number>;
includes: (searchElement: string | number, fromIndex?: number) => boolean;
flatMap: (callback: (this: This, value: string | number, index: number, array: Array<string | number>) => U | ReadonlyArray<U>, thisArg?: This | undefined) => Array<U>;
flat: (this: A, depth?: D | undefined) => Array<FlatArray<A, D>>;
at: (index: number) => string | number | undefined;
findLast: { (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => value is S, thisArg?: any): S | undefined; (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => unknow…;
findLastIndex: (predicate: (value: string | number, index: number, array: ReadonlyArray<string | number>) => unknown, thisArg?: any) => number;
toReversed: () => Array<string | number>;
toSorted: (compareFn?: ((a: string | number, b: string | number) => number) | undefined) => Array<string | number>;
toSpliced: { (start: number, deleteCount: number, ...items: Array<string | number>): Array<string | number>; (start: number, deleteCount?: number): Array<string | number> };
with: (index: number, value: string | number) => Array<string | number>;
}
path.ReadonlyArray<string | number>.map<string>(callbackfn: (value: string | number, index: number, array: readonly (string | number)[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(var String: StringConstructorAllows manipulation and formatting of text strings and determination and location of substrings within strings.
String))}`,
cause?: PlatformError(property) cause?: {
message: string;
name: string;
stack: string;
cause: unknown;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
_tag: Tag;
reason: BadArgument | SystemError;
}
cause
})
)
)
})
})