diff --git a/.changeset/tender-bikes-reply.md b/.changeset/tender-bikes-reply.md new file mode 100644 index 0000000000..e2c35069cd --- /dev/null +++ b/.changeset/tender-bikes-reply.md @@ -0,0 +1,5 @@ +--- +"effect": minor +--- + +change `Request` type parameters order from `Request` to `Request` diff --git a/packages/effect/mod.sh b/packages/effect/mod.sh index f2857cf163..cf0a298205 100755 --- a/packages/effect/mod.sh +++ b/packages/effect/mod.sh @@ -1,5 +1,5 @@ #!/bin/bash -dirs=(../effect/test) +dirs=(../effect/src) for dir in ${dirs[@]}; do echo Refactoring $dir diff --git a/packages/effect/mod.ts b/packages/effect/mod.ts index fdcdc3f5ce..c39bf14436 100644 --- a/packages/effect/mod.ts +++ b/packages/effect/mod.ts @@ -10,7 +10,8 @@ const enabled = { swapTakeParams: false, swapFiberParams: false, swapRuntimeFiberParams: false, - swapFiberSetParams: true, + swapFiberSetParams: false, + swapRequestParams: true, cleanupSTM: false, cleanupEffect: false, cleanupStream: false, @@ -97,6 +98,7 @@ const swapTakeParams = swapParamsEA("Take") const swapFiberParams = swapParamsEA("Fiber") const swapRuntimeFiberParams = swapParamsEA("FiberRuntime") const swapFiberSetParams = swapParamsEA("FiberSet") +const swapRequestParams = swapParamsEA("Request") const swapSTMParams = swapParamsREA("STM") const swapSTMGenParams = swapParamsREA("STMGen") @@ -154,6 +156,9 @@ export default function transformer(file: cs.FileInfo, api: cs.API) { if (enabled.swapFiberSetParams) { swapFiberSetParams(ast) } + if (enabled.swapRequestParams) { + swapRequestParams(ast) + } if (enabled.cleanupEffect) { cleanupEffect(ast) } diff --git a/packages/effect/src/KeyedPool.ts b/packages/effect/src/KeyedPool.ts index 0d86b0c265..5fe529facd 100644 --- a/packages/effect/src/KeyedPool.ts +++ b/packages/effect/src/KeyedPool.ts @@ -21,7 +21,7 @@ export const KeyedPoolTypeId: unique symbol = internal.KeyedPoolTypeId export type KeyedPoolTypeId = typeof KeyedPoolTypeId /** - * A `KeyedPool` is a pool of `Pool`s of items of type `A`. Each pool + * A `KeyedPool` is a pool of `Pool`s of items of type `A`. Each pool * in the `KeyedPool` is associated with a key of type `K`. * * @since 2.0.0 diff --git a/packages/effect/src/Request.ts b/packages/effect/src/Request.ts index 8e8fc35487..a89090657c 100644 --- a/packages/effect/src/Request.ts +++ b/packages/effect/src/Request.ts @@ -29,13 +29,13 @@ export const RequestTypeId: unique symbol = internal.RequestTypeId export type RequestTypeId = typeof RequestTypeId /** - * A `Request` is a request from a data source for a value of type `A` + * A `Request` is a request from a data source for a value of type `A` * that may fail with an `E`. * * @since 2.0.0 * @category models */ -export interface Request extends Request.Variance {} +export interface Request extends Request.Variance {} /** * @since 2.0.0 @@ -45,10 +45,10 @@ export declare namespace Request { * @since 2.0.0 * @category models */ - export interface Variance { + export interface Variance { readonly [RequestTypeId]: { - readonly _E: Types.Covariant readonly _A: Types.Covariant + readonly _E: Types.Covariant } } @@ -66,7 +66,7 @@ export declare namespace Request { * @since 2.0.0 * @category type-level */ - export type Error> = [T] extends [Request] ? _E : never + export type Error> = [T] extends [Request] ? _E : never /** * A utility type to extract the value type from a `Request`. @@ -74,7 +74,7 @@ export declare namespace Request { * @since 2.0.0 * @category type-level */ - export type Success> = [T] extends [Request] ? _A : never + export type Success> = [T] extends [Request] ? _A : never /** * A utility type to extract the result type from a `Request`. @@ -82,7 +82,7 @@ export declare namespace Request { * @since 2.0.0 * @category type-level */ - export type Result> = T extends Request ? Exit.Exit : never + export type Result> = T extends Request ? Exit.Exit : never /** * A utility type to extract the optional result type from a `Request`. @@ -90,7 +90,7 @@ export declare namespace Request { * @since 2.0.0 * @category type-level */ - export type OptionalResult> = T extends Request + export type OptionalResult> = T extends Request ? Exit.Exit, E> : never } @@ -140,7 +140,7 @@ export const tagged: & { _tag: string }>( export const Class: new>( args: Types.Equals>, {}> extends true ? void : { readonly [P in keyof A as P extends keyof Request ? never : P]: A[P] } -) => Request & Readonly = internal.Class as any +) => Request & Readonly = internal.Class as any /** * Provides a Tagged constructor for a Request Class. @@ -163,7 +163,7 @@ export const TaggedClass: ( ) => new>( args: Types.Equals>, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" | keyof Request ? never : P]: A[P] } -) => Request & Readonly & { readonly _tag: Tag } = internal.TaggedClass as any +) => Request & Readonly & { readonly _tag: Tag } = internal.TaggedClass as any /** * Complete a `Request` with the specified result. @@ -303,8 +303,8 @@ export type EntryTypeId = typeof EntryTypeId export interface Entry extends Entry.Variance { readonly request: R readonly result: Deferred< - [R] extends [Request] ? _A : never, - [R] extends [Request] ? _E : never + [R] extends [Request] ? _A : never, + [R] extends [Request] ? _E : never > readonly listeners: Listeners readonly ownerId: FiberId diff --git a/packages/effect/src/RequestResolver.ts b/packages/effect/src/RequestResolver.ts index 087cd11780..e8ebea96eb 100644 --- a/packages/effect/src/RequestResolver.ts +++ b/packages/effect/src/RequestResolver.ts @@ -219,7 +219,7 @@ export const eitherWith: { * @since 2.0.0 * @category constructors */ -export const fromFunction: >( +export const fromFunction: >( f: (request: A) => Request.Request.Success ) => RequestResolver = internal.fromFunction @@ -231,7 +231,7 @@ export const fromFunction: >( * @since 2.0.0 * @category constructors */ -export const fromFunctionBatched: >( +export const fromFunctionBatched: >( f: (chunk: Array) => Iterable> ) => RequestResolver = internal.fromFunctionBatched @@ -257,7 +257,7 @@ export const fromEffect: >( export const fromEffectTagged: & { readonly _tag: string }>() => < Fns extends { readonly [Tag in A["_tag"]]: [Extract] extends [infer Req] - ? Req extends Request.Request + ? Req extends Request.Request ? (requests: Array) => Effect.Effect, ReqE, any> : never : never diff --git a/packages/effect/src/internal/dataSource.ts b/packages/effect/src/internal/dataSource.ts index 0bbeff6c37..85972230fc 100644 --- a/packages/effect/src/internal/dataSource.ts +++ b/packages/effect/src/internal/dataSource.ts @@ -181,7 +181,7 @@ export const eitherWith = dual< )) /** @internal */ -export const fromFunction = >( +export const fromFunction = >( f: (request: A) => Request.Request.Success ): RequestResolver.RequestResolver => makeBatched((requests: Array) => @@ -192,7 +192,7 @@ export const fromFunction = >( ).identified("FromFunction", f) /** @internal */ -export const fromFunctionBatched = >( +export const fromFunctionBatched = >( f: (chunk: Array) => Iterable> ): RequestResolver.RequestResolver => makeBatched((as: Array) => @@ -224,7 +224,7 @@ export const fromEffectTagged = < < Fns extends { readonly [Tag in A["_tag"]]: [Extract] extends [infer Req] ? - Req extends Request.Request ? + Req extends Request.Request ? (requests: Array) => Effect.Effect, ReqE, any> : never : never diff --git a/packages/effect/src/internal/request.ts b/packages/effect/src/internal/request.ts index 321f0f81ac..c1966b3f1d 100644 --- a/packages/effect/src/internal/request.ts +++ b/packages/effect/src/internal/request.ts @@ -49,7 +49,7 @@ export const tagged = & { _tag: string }>( export const Class: new>( args: Types.Equals>, {}> extends true ? void : { readonly [P in keyof A as P extends keyof Request.Request ? never : P]: A[P] } -) => Request.Request & Readonly = (function() { +) => Request.Request & Readonly = (function() { function Class(this: any, args: any) { if (args) { Object.assign(this, args) @@ -65,7 +65,7 @@ export const TaggedClass = ( ): new>( args: Types.Equals>, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" | keyof Request.Request ? never : P]: A[P] } -) => Request.Request & Readonly & { readonly _tag: Tag } => { +) => Request.Request & Readonly & { readonly _tag: Tag } => { return class TaggedClass extends Class { readonly _tag = tag } as any diff --git a/packages/effect/test/Effect/query-nested.test.ts b/packages/effect/test/Effect/query-nested.test.ts index 9de99bdcd0..ab9ca1bb94 100644 --- a/packages/effect/test/Effect/query-nested.test.ts +++ b/packages/effect/test/Effect/query-nested.test.ts @@ -38,27 +38,27 @@ interface ChildExtra { readonly extra: string } -export interface GetAllParents extends Request.Request> { +export interface GetAllParents extends Request.Request> { readonly _tag: "GetAllParents" } export const GetAllParents = Request.tagged("GetAllParents") -export interface GetParentChildren extends Request.Request> { +export interface GetParentChildren extends Request.Request> { readonly _tag: "GetParentChildren" readonly id: number } export const GetParentChildren = Request.tagged("GetParentChildren") -export interface GetChildInfo extends Request.Request { +export interface GetChildInfo extends Request.Request { readonly _tag: "GetChildInfo" readonly id: number } export const GetChildInfo = Request.tagged("GetChildInfo") -export interface GetChildExtra extends Request.Request { +export interface GetChildExtra extends Request.Request { readonly _tag: "GetChildExtra" readonly id: number } diff --git a/packages/effect/test/Effect/query.test.ts b/packages/effect/test/Effect/query.test.ts index f0f65b746e..27bf453900 100644 --- a/packages/effect/test/Effect/query.test.ts +++ b/packages/effect/test/Effect/query.test.ts @@ -36,7 +36,7 @@ export const userNames: ReadonlyMap = new Map( export type UserRequest = GetAllIds | GetNameById -export interface GetAllIds extends Request.Request> { +export interface GetAllIds extends Request.Request> { readonly _tag: "GetAllIds" } diff --git a/packages/rpc/src/Resolver.ts b/packages/rpc/src/Resolver.ts index 25c1d001ae..20b783c3eb 100644 --- a/packages/rpc/src/Resolver.ts +++ b/packages/rpc/src/Resolver.ts @@ -18,7 +18,7 @@ export interface RpcResolver extends Resolver.RequestResolver * @category models * @since 1.0.0 */ -export interface RpcRequest extends Request.Request { +export interface RpcRequest extends Request.Request { readonly payload: RpcRequest.Payload readonly hash: number readonly schema: RpcSchema.Any diff --git a/packages/schema/src/Schema.ts b/packages/schema/src/Schema.ts index a6a36c8a25..0b052d51e0 100644 --- a/packages/schema/src/Schema.ts +++ b/packages/schema/src/Schema.ts @@ -4697,7 +4697,7 @@ export const TaggedError = () => * @since 1.0.0 */ export interface TaggedRequest - extends Request.Request, Serializable.SerializableWithResult + extends Request.Request, Serializable.SerializableWithResult { readonly _tag: Tag }