diff --git a/.changeset/wet-laws-smoke.md b/.changeset/wet-laws-smoke.md new file mode 100644 index 0000000000..fad3f205c1 --- /dev/null +++ b/.changeset/wet-laws-smoke.md @@ -0,0 +1,8 @@ +--- +"@effect/platform": patch +"effect": patch +"@effect/cli": patch +"@effect/rpc": patch +--- + +Changed various function signatures to return `Array` instead of `ReadonlyArray` diff --git a/packages/cli/src/internal/commandDescriptor.ts b/packages/cli/src/internal/commandDescriptor.ts index 00ed9ace1f..49c1366801 100644 --- a/packages/cli/src/internal/commandDescriptor.ts +++ b/packages/cli/src/internal/commandDescriptor.ts @@ -512,7 +512,7 @@ const parseInternal = ( case "Standard": { const parseCommandLine = ( args: ReadonlyArray - ): Effect.Effect, ValidationError.ValidationError> => + ): Effect.Effect, ValidationError.ValidationError> => Arr.matchLeft(args, { onEmpty: () => { const error = InternalHelpDoc.p(`Missing command name: '${self.name}'`) diff --git a/packages/effect/src/ConfigProvider.ts b/packages/effect/src/ConfigProvider.ts index 57c11d8541..001d6ac570 100644 --- a/packages/effect/src/ConfigProvider.ts +++ b/packages/effect/src/ConfigProvider.ts @@ -81,7 +81,7 @@ export declare namespace ConfigProvider { path: ReadonlyArray, config: Config.Config.Primitive, split?: boolean - ): Effect.Effect, ConfigError.ConfigError> + ): Effect.Effect, ConfigError.ConfigError> enumerateChildren( path: ReadonlyArray ): Effect.Effect, ConfigError.ConfigError> @@ -162,7 +162,7 @@ export const makeFlat: (options: { path: ReadonlyArray, config: Config.Config.Primitive, split: boolean - ) => Effect.Effect, ConfigError.ConfigError> + ) => Effect.Effect, ConfigError.ConfigError> readonly enumerateChildren: ( path: ReadonlyArray ) => Effect.Effect, ConfigError.ConfigError> diff --git a/packages/effect/src/Metric.ts b/packages/effect/src/Metric.ts index be6d1cb2d4..cd33096579 100644 --- a/packages/effect/src/Metric.ts +++ b/packages/effect/src/Metric.ts @@ -361,7 +361,7 @@ export const set: { * @since 2.0.0 * @category getters */ -export const snapshot: Effect.Effect> = internal.snapshot +export const snapshot: Effect.Effect> = internal.snapshot /** * Creates a metric that ignores input and produces constant output. diff --git a/packages/effect/src/MetricRegistry.ts b/packages/effect/src/MetricRegistry.ts index 0d2c239602..e43d8519b5 100644 --- a/packages/effect/src/MetricRegistry.ts +++ b/packages/effect/src/MetricRegistry.ts @@ -25,7 +25,7 @@ export type MetricRegistryTypeId = typeof MetricRegistryTypeId */ export interface MetricRegistry { readonly [MetricRegistryTypeId]: MetricRegistryTypeId - snapshot(): ReadonlyArray + snapshot(): Array get>( key: MetricKey.MetricKey ): MetricHook.MetricHook< diff --git a/packages/effect/src/internal/configProvider.ts b/packages/effect/src/internal/configProvider.ts index e30a3cb010..fe8a0f9227 100644 --- a/packages/effect/src/internal/configProvider.ts +++ b/packages/effect/src/internal/configProvider.ts @@ -68,7 +68,7 @@ export const makeFlat = ( path: ReadonlyArray, config: Config.Config.Primitive, split: boolean - ) => Effect.Effect, ConfigError.ConfigError> + ) => Effect.Effect, ConfigError.ConfigError> readonly enumerateChildren: ( path: ReadonlyArray ) => Effect.Effect, ConfigError.ConfigError> @@ -114,7 +114,7 @@ export const fromEnv = ( path: ReadonlyArray, primitive: Config.Config.Primitive, split = true - ): Effect.Effect, ConfigError.ConfigError> => { + ): Effect.Effect, ConfigError.ConfigError> => { const pathString = makePathString(path) const current = getEnv() const valueOpt = pathString in current ? Option.some(current[pathString]!) : Option.none() @@ -165,7 +165,7 @@ export const fromMap = ( path: ReadonlyArray, primitive: Config.Config.Primitive, split = true - ): Effect.Effect, ConfigError.ConfigError> => { + ): Effect.Effect, ConfigError.ConfigError> => { const pathString = makePathString(path) const valueOpt = mapWithIndexSplit.has(pathString) ? Option.some(mapWithIndexSplit.get(pathString)!) : @@ -240,20 +240,20 @@ const fromFlatLoop = ( prefix: ReadonlyArray, config: Config.Config, split: boolean -): Effect.Effect, ConfigError.ConfigError> => { +): Effect.Effect, ConfigError.ConfigError> => { const op = config as _config.ConfigPrimitive switch (op._tag) { case OpCodes.OP_CONSTANT: { - return core.succeed(Arr.of(op.value)) as Effect.Effect, ConfigError.ConfigError> + return core.succeed(Arr.of(op.value)) as Effect.Effect, ConfigError.ConfigError> } case OpCodes.OP_DESCRIBED: { return core.suspend( () => fromFlatLoop(flat, prefix, op.config, split) - ) as unknown as Effect.Effect, ConfigError.ConfigError> + ) as unknown as Effect.Effect, ConfigError.ConfigError> } case OpCodes.OP_FAIL: { return core.fail(configError.MissingData(prefix, op.message)) as Effect.Effect< - ReadonlyArray, + Array, ConfigError.ConfigError > } @@ -269,11 +269,11 @@ const fromFlatLoop = ( } return core.fail(error1) }) - ) as unknown as Effect.Effect, ConfigError.ConfigError> + ) as unknown as Effect.Effect, ConfigError.ConfigError> } case OpCodes.OP_LAZY: { return core.suspend(() => fromFlatLoop(flat, prefix, op.config(), split)) as Effect.Effect< - ReadonlyArray, + Array, ConfigError.ConfigError > } @@ -290,7 +290,7 @@ const fromFlatLoop = ( ) ) ) - ) as unknown as Effect.Effect, ConfigError.ConfigError> + ) as unknown as Effect.Effect, ConfigError.ConfigError> } case OpCodes.OP_NESTED: { return core.suspend(() => @@ -300,7 +300,7 @@ const fromFlatLoop = ( op.config, split ) - ) as unknown as Effect.Effect, ConfigError.ConfigError> + ) as unknown as Effect.Effect, ConfigError.ConfigError> } case OpCodes.OP_PRIMITIVE: { return pipe( @@ -317,7 +317,7 @@ const fromFlatLoop = ( }) ) ) - ) as unknown as Effect.Effect, ConfigError.ConfigError> + ) as unknown as Effect.Effect, ConfigError.ConfigError> } case OpCodes.OP_SEQUENCE: { return pipe( @@ -330,7 +330,7 @@ const fromFlatLoop = ( if (indices.length === 0) { return core.suspend(() => core.map(fromFlatLoop(flat, patchedPrefix, op.config, true), Arr.of) - ) as unknown as Effect.Effect, ConfigError.ConfigError> + ) as unknown as Effect.Effect, ConfigError.ConfigError> } return pipe( core.forEachSequential( @@ -344,7 +344,7 @@ const fromFlatLoop = ( } return Arr.of(flattened) }) - ) as unknown as Effect.Effect, ConfigError.ConfigError> + ) as unknown as Effect.Effect, ConfigError.ConfigError> }) ) ) @@ -382,7 +382,7 @@ const fromFlatLoop = ( ) ) ) - ) as unknown as Effect.Effect, ConfigError.ConfigError> + ) as unknown as Effect.Effect, ConfigError.ConfigError> } case OpCodes.OP_ZIP_WITH: { return core.suspend(() => @@ -430,7 +430,7 @@ const fromFlatLoop = ( ) ) ) - ) as unknown as Effect.Effect, ConfigError.ConfigError> + ) as unknown as Effect.Effect, ConfigError.ConfigError> } } } @@ -592,7 +592,7 @@ export const within = dual< return orElse(nest, () => self) }) -const splitPathString = (text: string, delim: string): ReadonlyArray => { +const splitPathString = (text: string, delim: string): Array => { const split = text.split(new RegExp(`\\s*${regexp.escape(delim)}\\s*`)) return split } @@ -603,7 +603,7 @@ const parsePrimitive = ( primitive: Config.Config.Primitive, delimiter: string, split: boolean -): Effect.Effect, ConfigError.ConfigError> => { +): Effect.Effect, ConfigError.ConfigError> => { if (!split) { return pipe( primitive.parse(text), @@ -620,11 +620,11 @@ const parsePrimitive = ( ) } -const transpose = (array: ReadonlyArray>): ReadonlyArray> => { +const transpose = (array: ReadonlyArray>): Array> => { return Object.keys(array[0]).map((column) => array.map((row) => row[column as any])) } -const indicesFrom = (quotedIndices: HashSet.HashSet): Effect.Effect> => +const indicesFrom = (quotedIndices: HashSet.HashSet): Effect.Effect> => pipe( core.forEachSequential(quotedIndices, parseQuotedIndex), core.mapBoth({ diff --git a/packages/effect/src/internal/metric.ts b/packages/effect/src/internal/metric.ts index 43f0b2d9f9..3830e78338 100644 --- a/packages/effect/src/internal/metric.ts +++ b/packages/effect/src/internal/metric.ts @@ -525,9 +525,9 @@ export const zip = dual< ) /** @internal */ -export const unsafeSnapshot = (): ReadonlyArray => globalMetricRegistry.snapshot() +export const unsafeSnapshot = (): Array => globalMetricRegistry.snapshot() /** @internal */ -export const snapshot: Effect.Effect> = core.sync( +export const snapshot: Effect.Effect> = core.sync( unsafeSnapshot ) diff --git a/packages/effect/src/internal/metric/registry.ts b/packages/effect/src/internal/metric/registry.ts index beef571737..4417acafbc 100644 --- a/packages/effect/src/internal/metric/registry.ts +++ b/packages/effect/src/internal/metric/registry.ts @@ -27,7 +27,7 @@ class MetricRegistryImpl implements MetricRegistry.MetricRegistry { MetricHook.MetricHook.Root >() - snapshot(): ReadonlyArray { + snapshot(): Array { const result: Array = [] for (const [key, hook] of this.map) { result.push(metricPair.unsafeMake(key, hook.get())) diff --git a/packages/platform/README.md b/packages/platform/README.md index 41c7e27c0b..1234cad7bf 100644 --- a/packages/platform/README.md +++ b/packages/platform/README.md @@ -295,7 +295,7 @@ Here's a list of operations that can be performed using the `FileSystem` tag: | **makeTempFile** | `options?: MakeTempFileOptions` | `Effect` | Create a temporary file. The directory creation is functionally equivalent to `makeTempDirectory`. The file name will be a randomly generated string. | | **makeTempFileScoped** | `options?: MakeTempFileOptions` | `Effect` | Create a temporary file inside a scope. Functionally equivalent to `makeTempFile`, but the file will be automatically deleted when the scope is closed. | | **open** | `path: string`, `options?: OpenFileOptions` | `Effect` | Open a file at `path` with the specified `options`. The file handle will be automatically closed when the scope is closed. | -| **readDirectory** | `path: string`, `options?: ReadDirectoryOptions` | `Effect, PlatformError>` | List the contents of a directory. You can recursively list the contents of nested directories by setting the `recursive` option. | +| **readDirectory** | `path: string`, `options?: ReadDirectoryOptions` | `Effect, PlatformError>` | List the contents of a directory. You can recursively list the contents of nested directories by setting the `recursive` option. | | **readFile** | `path: string` | `Effect` | Read the contents of a file. | | **readFileString** | `path: string`, `encoding?: string` | `Effect` | Read the contents of a file as a string. | | **readLink** | `path: string` | `Effect` | Read the destination of a symbolic link. | diff --git a/packages/platform/src/Command.ts b/packages/platform/src/Command.ts index f224fd4e97..d9eb48c751 100644 --- a/packages/platform/src/Command.ts +++ b/packages/platform/src/Command.ts @@ -172,7 +172,7 @@ export const flatten: (self: Command) => NonEmptyReadonlyArray export const lines: ( command: Command, encoding?: string -) => Effect, PlatformError, CommandExecutor> = internal.lines +) => Effect, PlatformError, CommandExecutor> = internal.lines /** * Create a command with the specified process name and an optional list of diff --git a/packages/platform/src/CommandExecutor.ts b/packages/platform/src/CommandExecutor.ts index bea7f74053..85ff4ae63b 100644 --- a/packages/platform/src/CommandExecutor.ts +++ b/packages/platform/src/CommandExecutor.ts @@ -52,7 +52,7 @@ export interface CommandExecutor { * * If an encoding is not specified, the encoding will default to `utf-8`. */ - readonly lines: (command: Command, encoding?: string) => Effect, PlatformError> + readonly lines: (command: Command, encoding?: string) => Effect, PlatformError> /** * Runs the command returning the output as a `Stream`. */ diff --git a/packages/platform/src/FileSystem.ts b/packages/platform/src/FileSystem.ts index fb1babaf72..db9ed8f589 100644 --- a/packages/platform/src/FileSystem.ts +++ b/packages/platform/src/FileSystem.ts @@ -137,7 +137,7 @@ export interface FileSystem { readonly readDirectory: ( path: string, options?: ReadDirectoryOptions - ) => Effect.Effect, PlatformError> + ) => Effect.Effect, PlatformError> /** * Read the contents of a file. */ diff --git a/packages/platform/src/Transferable.ts b/packages/platform/src/Transferable.ts index b7cb9e3cd4..13f4d31466 100644 --- a/packages/platform/src/Transferable.ts +++ b/packages/platform/src/Transferable.ts @@ -15,8 +15,8 @@ import * as Option from "effect/Option" export interface CollectorService { readonly addAll: (_: Iterable) => Effect.Effect readonly unsafeAddAll: (_: Iterable) => void - readonly read: Effect.Effect> - readonly unsafeRead: () => ReadonlyArray + readonly read: Effect.Effect> + readonly unsafeRead: () => Array readonly unsafeClear: () => void readonly clear: Effect.Effect } @@ -41,7 +41,7 @@ export const unsafeMakeCollector = (): CollectorService => { tranferables.push(transfer) } } - const unsafeRead = (): ReadonlyArray => tranferables + const unsafeRead = (): Array => tranferables const unsafeClear = (): void => { tranferables.length = 0 } diff --git a/packages/platform/src/internal/command.ts b/packages/platform/src/internal/command.ts index b8ef6ec47b..3dad65929e 100644 --- a/packages/platform/src/internal/command.ts +++ b/packages/platform/src/internal/command.ts @@ -98,7 +98,7 @@ export const runInShell = dual< export const lines = ( command: Command.Command, encoding = "utf-8" -): Effect.Effect, PlatformError, CommandExecutor.CommandExecutor> => +): Effect.Effect, PlatformError, CommandExecutor.CommandExecutor> => Effect.flatMap(commandExecutor.CommandExecutor, (executor) => executor.lines(command, encoding)) const Proto = { diff --git a/packages/platform/src/internal/commandExecutor.ts b/packages/platform/src/internal/commandExecutor.ts index f56979a4b4..1ae82c8497 100644 --- a/packages/platform/src/internal/commandExecutor.ts +++ b/packages/platform/src/internal/commandExecutor.ts @@ -52,7 +52,7 @@ export const makeExecutor = (start: _CommandExecutor.CommandExecutor["start"]): return pipe( streamLines(command, encoding), Stream.runCollect, - Effect.map(Chunk.toReadonlyArray) + Effect.map(Chunk.toArray) ) }, streamLines diff --git a/packages/rpc/src/Router.ts b/packages/rpc/src/Router.ts index 2b2b49c97e..786007341e 100644 --- a/packages/rpc/src/Router.ts +++ b/packages/rpc/src/Router.ts @@ -317,7 +317,7 @@ export const toHandlerEffect = >(router: R, options?: const getEncode = withRequestTag((req) => Schema.encode(Serializable.exitSchema(req))) const getEncodeChunk = withRequestTag((req) => Schema.encode(Schema.Chunk(Serializable.exitSchema(req)))) - return (u: unknown): Effect.Effect, ParseError, Router.Context> => + return (u: unknown): Effect.Effect, ParseError, Router.Context> => Effect.flatMap( decode(u), Effect.forEach((req): Effect.Effect => {