Skip to content

Commit

Permalink
rename proxy to accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
mikearnaldi committed Sep 28, 2024
1 parent 03da5a7 commit cb2bce0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
44 changes: 27 additions & 17 deletions packages/effect/src/Effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6387,6 +6387,14 @@ export declare namespace Service {
| WithDependencies<{ scoped: Effect<AllowedType<P>, any, any> }>
| WithDependencies<{ sync: () => AllowedType<P> }>

/**
* @since 2.0.0
* @category models
*/
export type Options =
| (Service.Maker<Service.ProhibitedType> & { accessors: true })
| (Service.Maker<{}> & { accessors?: false })

/**
* @since 2.0.0
* @category models
Expand Down Expand Up @@ -6435,20 +6443,25 @@ export declare namespace Service {
* @since 2.0.0
* @category models
*/
export type ReturnWithMaker<Self, Id extends string, Maker, Proxy extends boolean> =
export type ReturnWithOptions<
Self,
Id extends string,
Options,
Proxy extends boolean = Options extends { accessors: true } ? true : false
> =
& {}
& Maker extends { scoped: Effect<infer Type, infer E, infer R> } ?
& Options extends { scoped: Effect<infer Type, infer E, infer R> } ?
& Return<Self, Id, Type, Proxy>
& DefaultLayer<Self, E, Exclude<R, Scope.Scope>, Maker>
& InstanceLayers<Self, E, Exclude<R, Scope.Scope>, Maker>
: Maker extends { effect: Effect<infer Type, infer E, infer R> } ?
& DefaultLayer<Self, E, Exclude<R, Scope.Scope>, Options>
& InstanceLayers<Self, E, Exclude<R, Scope.Scope>, Options>
: Options extends { effect: Effect<infer Type, infer E, infer R> } ?
& Return<Self, Id, Type, Proxy>
& DefaultLayer<Self, E, R, Maker>
& InstanceLayers<Self, E, R, Maker>
: Maker extends { sync: () => infer Type } ?
& DefaultLayer<Self, E, R, Options>
& InstanceLayers<Self, E, R, Options>
: Options extends { sync: () => infer Type } ?
& Return<Self, Id, Type, Proxy>
& DefaultLayer<Self, never, never, Maker>
& InstanceLayers<Self, never, never, Maker>
& DefaultLayer<Self, never, never, Options>
& InstanceLayers<Self, never, never, Options>
: never
}

Expand All @@ -6458,18 +6471,15 @@ export declare namespace Service {
*/
export const Service: {
<Self>(): {
<
const Id extends string,
Maker extends (Service.Maker<Service.ProhibitedType> & { proxy: true }) | (Service.Maker<{}> & { proxy?: false })
>(
<const Id extends string, Options extends Service.Options>(
id: Id,
maker: Maker
): Service.ReturnWithMaker<Self, Id, Maker, Maker extends { proxy: true } ? true : false>
maker: Options
): Service.ReturnWithOptions<Self, Id, Options>
}
} = function() {
return function() {
const [id, maker] = arguments
const proxy = "proxy" in maker ? maker["proxy"] : false
const proxy = "accessors" in maker ? maker["accessors"] : false
const limit = Error.stackTraceLimit
Error.stackTraceLimit = 2
const creationError = new Error()
Expand Down
10 changes: 3 additions & 7 deletions packages/effect/test/Effect/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@ import * as it from "effect/test/utils/extend"
import { describe, expect } from "vitest"

class Prefix extends Effect.Service<Prefix>()("Prefix", {
sync: () => ({
prefix: "PRE"
})
sync: () => ({ prefix: "PRE" })
}) {}

class Postfix extends Effect.Service<Postfix>()("Postfix", {
sync: () => ({
postfix: "POST"
})
sync: () => ({ postfix: "POST" })
}) {}

const messages: Array<string> = []

class Logger extends Effect.Service<Logger>()("Logger", {
proxy: true,
accessors: true,
effect: Effect.gen(function*() {
const { prefix } = yield* Prefix
const { postfix } = yield* Postfix
Expand Down

0 comments on commit cb2bce0

Please sign in to comment.