effect-app 4.0.0-beta.13 → 4.0.0-beta.131

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/CHANGELOG.md +503 -0
  2. package/dist/Config/SecretURL.js +2 -2
  3. package/dist/Config.d.ts +7 -0
  4. package/dist/Config.d.ts.map +1 -0
  5. package/dist/Config.js +6 -0
  6. package/dist/ConfigProvider.d.ts +39 -0
  7. package/dist/ConfigProvider.d.ts.map +1 -0
  8. package/dist/ConfigProvider.js +42 -0
  9. package/dist/{ServiceMap.d.ts → Context.d.ts} +14 -18
  10. package/dist/Context.d.ts.map +1 -0
  11. package/dist/Context.js +66 -0
  12. package/dist/Effect.d.ts +8 -9
  13. package/dist/Effect.d.ts.map +1 -1
  14. package/dist/Effect.js +3 -6
  15. package/dist/Layer.d.ts +5 -4
  16. package/dist/Layer.d.ts.map +1 -1
  17. package/dist/Layer.js +1 -1
  18. package/dist/Operations.d.ts +198 -33
  19. package/dist/Operations.d.ts.map +1 -1
  20. package/dist/Pure.d.ts +2 -2
  21. package/dist/Pure.d.ts.map +1 -1
  22. package/dist/Pure.js +13 -13
  23. package/dist/Schema/Class.d.ts +48 -10
  24. package/dist/Schema/Class.d.ts.map +1 -1
  25. package/dist/Schema/Class.js +120 -16
  26. package/dist/Schema/SpecialJsonSchema.d.ts +33 -0
  27. package/dist/Schema/SpecialJsonSchema.d.ts.map +1 -0
  28. package/dist/Schema/SpecialJsonSchema.js +122 -0
  29. package/dist/Schema/SpecialOpenApi.d.ts +32 -0
  30. package/dist/Schema/SpecialOpenApi.d.ts.map +1 -0
  31. package/dist/Schema/SpecialOpenApi.js +123 -0
  32. package/dist/Schema/brand.d.ts +10 -1
  33. package/dist/Schema/brand.d.ts.map +1 -1
  34. package/dist/Schema/brand.js +1 -1
  35. package/dist/Schema/email.d.ts.map +1 -1
  36. package/dist/Schema/email.js +9 -4
  37. package/dist/Schema/ext.d.ts +112 -47
  38. package/dist/Schema/ext.d.ts.map +1 -1
  39. package/dist/Schema/ext.js +115 -53
  40. package/dist/Schema/moreStrings.d.ts +110 -10
  41. package/dist/Schema/moreStrings.d.ts.map +1 -1
  42. package/dist/Schema/moreStrings.js +19 -10
  43. package/dist/Schema/numbers.d.ts +126 -14
  44. package/dist/Schema/numbers.d.ts.map +1 -1
  45. package/dist/Schema/numbers.js +10 -9
  46. package/dist/Schema/phoneNumber.d.ts.map +1 -1
  47. package/dist/Schema/phoneNumber.js +8 -3
  48. package/dist/Schema/strings.d.ts +36 -4
  49. package/dist/Schema/strings.d.ts.map +1 -1
  50. package/dist/Schema/strings.js +1 -1
  51. package/dist/Schema.d.ts +74 -55
  52. package/dist/Schema.d.ts.map +1 -1
  53. package/dist/Schema.js +85 -64
  54. package/dist/client/apiClientFactory.d.ts +12 -28
  55. package/dist/client/apiClientFactory.d.ts.map +1 -1
  56. package/dist/client/apiClientFactory.js +16 -17
  57. package/dist/client/clientFor.d.ts +6 -5
  58. package/dist/client/clientFor.d.ts.map +1 -1
  59. package/dist/client/errors.d.ts +18 -9
  60. package/dist/client/errors.d.ts.map +1 -1
  61. package/dist/client/errors.js +35 -10
  62. package/dist/client/makeClient.d.ts +73 -28
  63. package/dist/client/makeClient.d.ts.map +1 -1
  64. package/dist/client/makeClient.js +49 -23
  65. package/dist/http/Request.d.ts.map +1 -1
  66. package/dist/http/Request.js +5 -5
  67. package/dist/ids.d.ts +2 -2
  68. package/dist/ids.d.ts.map +1 -1
  69. package/dist/ids.js +3 -2
  70. package/dist/index.d.ts +3 -7
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js +4 -8
  73. package/dist/middleware.d.ts +2 -2
  74. package/dist/middleware.d.ts.map +1 -1
  75. package/dist/middleware.js +3 -3
  76. package/dist/rpc/MiddlewareMaker.d.ts +4 -3
  77. package/dist/rpc/MiddlewareMaker.d.ts.map +1 -1
  78. package/dist/rpc/MiddlewareMaker.js +23 -24
  79. package/dist/rpc/RpcContextMap.d.ts +2 -2
  80. package/dist/rpc/RpcContextMap.d.ts.map +1 -1
  81. package/dist/rpc/RpcContextMap.js +4 -4
  82. package/dist/rpc/RpcMiddleware.d.ts +4 -3
  83. package/dist/rpc/RpcMiddleware.d.ts.map +1 -1
  84. package/dist/rpc/RpcMiddleware.js +1 -1
  85. package/dist/utils/gen.d.ts +1 -1
  86. package/dist/utils/gen.d.ts.map +1 -1
  87. package/dist/utils/logger.d.ts +2 -2
  88. package/dist/utils/logger.d.ts.map +1 -1
  89. package/dist/utils/logger.js +3 -3
  90. package/dist/utils.d.ts +7 -1
  91. package/dist/utils.d.ts.map +1 -1
  92. package/dist/utils.js +8 -2
  93. package/package.json +30 -14
  94. package/src/Config/SecretURL.ts +1 -1
  95. package/src/Config.ts +14 -0
  96. package/src/ConfigProvider.ts +48 -0
  97. package/src/{ServiceMap.ts → Context.ts} +51 -59
  98. package/src/Effect.ts +11 -14
  99. package/src/Layer.ts +5 -4
  100. package/src/Pure.ts +17 -18
  101. package/src/Schema/Class.ts +157 -30
  102. package/src/Schema/SpecialJsonSchema.ts +137 -0
  103. package/src/Schema/SpecialOpenApi.ts +130 -0
  104. package/src/Schema/brand.ts +18 -3
  105. package/src/Schema/email.ts +10 -2
  106. package/src/Schema/ext.ts +196 -87
  107. package/src/Schema/moreStrings.ts +31 -17
  108. package/src/Schema/numbers.ts +14 -13
  109. package/src/Schema/phoneNumber.ts +8 -1
  110. package/src/Schema/strings.ts +4 -4
  111. package/src/Schema.ts +195 -104
  112. package/src/client/apiClientFactory.ts +104 -112
  113. package/src/client/clientFor.ts +6 -1
  114. package/src/client/errors.ts +42 -17
  115. package/src/client/makeClient.ts +150 -61
  116. package/src/http/Request.ts +7 -4
  117. package/src/ids.ts +2 -1
  118. package/src/index.ts +3 -10
  119. package/src/middleware.ts +2 -2
  120. package/src/rpc/MiddlewareMaker.ts +33 -44
  121. package/src/rpc/RpcContextMap.ts +6 -5
  122. package/src/rpc/RpcMiddleware.ts +5 -4
  123. package/src/utils/gen.ts +1 -1
  124. package/src/utils/logger.ts +2 -2
  125. package/src/utils.ts +8 -4
  126. package/test/dist/moreStrings.test.d.ts.map +1 -0
  127. package/test/dist/rpc.test.d.ts.map +1 -1
  128. package/test/dist/secretURL.test.d.ts.map +1 -0
  129. package/test/dist/special.test.d.ts.map +1 -0
  130. package/test/moreStrings.test.ts +17 -0
  131. package/test/rpc.test.ts +30 -6
  132. package/test/schema.test.ts +517 -4
  133. package/test/secretURL.test.ts +157 -0
  134. package/test/special.test.ts +862 -0
  135. package/test/utils.test.ts +2 -2
  136. package/tsconfig.base.json +0 -1
  137. package/tsconfig.json +0 -1
  138. package/dist/ServiceMap.d.ts.map +0 -1
  139. package/dist/ServiceMap.js +0 -91
package/package.json CHANGED
@@ -1,31 +1,31 @@
1
1
  {
2
2
  "name": "effect-app",
3
- "version": "4.0.0-beta.13",
3
+ "version": "4.0.0-beta.131",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "dependencies": {
7
7
  "@tsconfig/strictest": "^2.0.8",
8
8
  "date-fns": "^4.1.0",
9
- "nanoid": "^5.1.6",
9
+ "nanoid": "^5.1.9",
10
10
  "path-parser": "^6.1.0",
11
11
  "query-string": "^9.3.1",
12
12
  "ts-pattern": "^5.9.0",
13
13
  "ts-toolbelt": "^9.6.0",
14
- "uuid": "^13.0.0",
15
- "validator": "^13.15.26"
14
+ "uuid": "^14.0.0",
15
+ "validator": "^13.15.35"
16
16
  },
17
17
  "devDependencies": {
18
18
  "@faker-js/faker": "^8.4.1",
19
- "@types/node": "25.3.3",
19
+ "@types/node": "25.6.0",
20
20
  "@types/uuid": "^11.0.0",
21
21
  "@types/validator": "^13.15.10",
22
- "fast-check": "~4.5.3",
23
- "typescript": "~5.9.3",
24
- "vitest": "^4.0.18",
25
- "@effect-app/eslint-shared-config": "0.5.7-beta.2"
22
+ "fast-check": "~4.7.0",
23
+ "typescript": "~6.0.3",
24
+ "vitest": "^4.1.5",
25
+ "@effect-app/eslint-shared-config": "0.6.0-beta.10"
26
26
  },
27
27
  "peerDependencies": {
28
- "effect": "^4.0.0-beta.31"
28
+ "effect": "^4.0.0-beta.52"
29
29
  },
30
30
  "typesVersions": {
31
31
  "*": {
@@ -47,10 +47,22 @@
47
47
  "types": "./dist/Chunk.d.ts",
48
48
  "default": "./dist/Chunk.js"
49
49
  },
50
+ "./Config": {
51
+ "types": "./dist/Config.d.ts",
52
+ "default": "./dist/Config.js"
53
+ },
50
54
  "./Config/SecretURL": {
51
55
  "types": "./dist/Config/SecretURL.d.ts",
52
56
  "default": "./dist/Config/SecretURL.js"
53
57
  },
58
+ "./ConfigProvider": {
59
+ "types": "./dist/ConfigProvider.d.ts",
60
+ "default": "./dist/ConfigProvider.js"
61
+ },
62
+ "./Context": {
63
+ "types": "./dist/Context.d.ts",
64
+ "default": "./dist/Context.js"
65
+ },
54
66
  "./Effect": {
55
67
  "types": "./dist/Effect.d.ts",
56
68
  "default": "./dist/Effect.js"
@@ -99,6 +111,14 @@
99
111
  "types": "./dist/Schema/Methods.d.ts",
100
112
  "default": "./dist/Schema/Methods.js"
101
113
  },
114
+ "./Schema/SpecialJsonSchema": {
115
+ "types": "./dist/Schema/SpecialJsonSchema.d.ts",
116
+ "default": "./dist/Schema/SpecialJsonSchema.js"
117
+ },
118
+ "./Schema/SpecialOpenApi": {
119
+ "types": "./dist/Schema/SpecialOpenApi.d.ts",
120
+ "default": "./dist/Schema/SpecialOpenApi.js"
121
+ },
102
122
  "./Schema/brand": {
103
123
  "types": "./dist/Schema/brand.d.ts",
104
124
  "default": "./dist/Schema/brand.js"
@@ -131,10 +151,6 @@
131
151
  "types": "./dist/Schema/strings.d.ts",
132
152
  "default": "./dist/Schema/strings.js"
133
153
  },
134
- "./ServiceMap": {
135
- "types": "./dist/ServiceMap.d.ts",
136
- "default": "./dist/ServiceMap.js"
137
- },
138
154
  "./Set": {
139
155
  "types": "./dist/Set.d.ts",
140
156
  "default": "./dist/Set.js"
@@ -73,5 +73,5 @@ export const value: (self: SecretURL) => string = internal.value
73
73
  export const unsafeWipe: (self: SecretURL) => void = internal.unsafeWipe
74
74
 
75
75
  export const secretURL = (name?: string): Config.Config<SecretURL> => {
76
- return Config.map(Config.string(name), fromString)
76
+ return Config.map(Config.nonEmptyString(name), fromString)
77
77
  }
package/src/Config.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { type Config, make } from "effect/Config"
2
+ import { dual } from "effect/Function"
3
+
4
+ import * as ConfigProvider from "./ConfigProvider.js"
5
+
6
+ export const nested: {
7
+ (name: string): <A>(self: Config<A>) => Config<A>
8
+ <A>(self: Config<A>, name: string): Config<A>
9
+ } = dual(
10
+ 2,
11
+ <A>(self: Config<A>, name: string): Config<A> => make((provider) => self.parse(ConfigProvider.nested(provider, name)))
12
+ )
13
+
14
+ export * from "effect/Config"
@@ -0,0 +1,48 @@
1
+ import { type ConfigProvider, make, type Path } from "effect/ConfigProvider"
2
+ import { dual } from "effect/Function"
3
+
4
+ /**
5
+ * Scopes a provider so that all lookups are prefixed with the given path
6
+ * segments.
7
+ *
8
+ * When to use:
9
+ * - Namespacing config under a prefix like `"app"` or `"database"`.
10
+ * - Reusing the same provider shape for multiple sub-configs.
11
+ *
12
+ * Accepts a single string or a full `Path` array. The prefix is prepended
13
+ * *after* any `mapInput` transformation runs, so ordering matters when
14
+ * composing with {@link mapInput} or {@link constantCase}.
15
+ *
16
+ * Supports both data-last and data-first calling conventions.
17
+ *
18
+ * **Example** (Nesting under a prefix)
19
+ *
20
+ * ```ts
21
+ * import { ConfigProvider } from "effect"
22
+ *
23
+ * const provider = ConfigProvider.fromEnv({
24
+ * env: { APP_HOST: "localhost", APP_PORT: "3000" }
25
+ * })
26
+ *
27
+ * // Lookups for ["HOST"] now resolve to ["APP", "HOST"]
28
+ * const scoped = ConfigProvider.nested(provider, "APP")
29
+ * ```
30
+ *
31
+ * @see {@link mapInput} – for arbitrary path transformations
32
+ *
33
+ * @category Combinators
34
+ * @since 4.0.0
35
+ */
36
+ export const nested: {
37
+ (prefix: string | Path): (self: ConfigProvider) => ConfigProvider
38
+ (self: ConfigProvider, prefix: string | Path): ConfigProvider
39
+ } = dual(
40
+ 2,
41
+ (self: ConfigProvider, prefix: string | Path): ConfigProvider => {
42
+ let path: Path = typeof prefix === "string" ? [prefix] : prefix
43
+ if (self.mapInput) path = self.mapInput(path)
44
+ return make(self.get, self.mapInput, self.prefix ? [...self.prefix, ...path] : path)
45
+ }
46
+ )
47
+
48
+ export * from "effect/ConfigProvider"
@@ -1,21 +1,16 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- /**
3
- * We're doing the long way around here with assignTag, TagBase & TagBaseTagged,
4
- * because there's a typescript compiler issue where it will complain about Equal.symbol, and Hash.symbol not being accessible.
5
- * https://github.com/microsoft/TypeScript/issues/52644
6
- */
7
2
 
8
3
  import { type Effect, Layer, type Scope, type Types } from "effect"
9
- import * as ServiceMap from "effect/ServiceMap"
4
+ import * as CTX from "effect/Context"
10
5
  import { type Yieldable } from "./Effect.js"
11
6
 
12
- export * from "effect/ServiceMap"
7
+ export * from "effect/Context"
13
8
 
14
9
  export interface Opaque<Self extends object, in out Shape extends object>
15
- extends ServiceMap.Key<Self, Self>, Yieldable<Opaque<Self, Shape>, Self, never, Self>
10
+ extends CTX.Key<Self, Self>, Yieldable<Opaque<Self, Shape>, Self, never, Self>
16
11
  {
17
12
  of(this: void, self: Shape): Self
18
- serviceMap(self: Shape): ServiceMap.ServiceMap<Self>
13
+ context(self: Shape): CTX.Context<Self>
19
14
  // a version that leverages the Shape -> Self conversion
20
15
  toLayer: <E, R>(
21
16
  eff: Effect.Effect<Shape, E, R>
@@ -25,11 +20,11 @@ export interface Opaque<Self extends object, in out Shape extends object>
25
20
  }
26
21
 
27
22
  // export interface OpaqueMake<Self extends object, in out Shape extends object, E, R>
28
- // extends ServiceMap.Service<Self, Self>
23
+ // extends CTX.Service<Self, Self>
29
24
  // {
30
25
  // // temp while sorting out https://github.com/Effect-TS/effect-smol/pull/1534
31
26
  // of(self: Shape): Self
32
- // serviceMap2(self: Shape): ServiceMap.ServiceMap<Self>
27
+ // contextMap2(self: Shape): CTX.Context<Self>
33
28
  // // a version that leverages the Shape -> Self conversion
34
29
  // toLayer: {
35
30
  // <E, R>(
@@ -44,7 +39,7 @@ export function assignTag<Identifier extends object, Shape extends object = Iden
44
39
  creationError?: Error
45
40
  ) {
46
41
  return <S extends object>(cls: S): S & Opaque<Identifier, Shape> => {
47
- const tag = ServiceMap.Service<Identifier, Shape>(key)
42
+ const tag = CTX.Service<Identifier, Shape>(key)
48
43
  let fields = tag
49
44
  if (Reflect.ownKeys(cls).includes("key")) {
50
45
  const { key, ...rest } = tag
@@ -67,54 +62,51 @@ export function assignTag<Identifier extends object, Shape extends object = Iden
67
62
  }
68
63
  }
69
64
 
70
- export type ServiceAcessorShape<Self, Type> = Type extends Record<PropertyKey, any> ? {
71
- [
72
- k in keyof Type as Type[k] extends ((...args: [...infer Args]) => infer Ret)
73
- ? ((...args: Readonly<Args>) => Ret) extends Type[k] ? k : never
74
- : k
75
- ]: Type[k] extends (...args: [...infer Args]) => Effect.Effect<infer A, infer E, infer R>
76
- ? (...args: Readonly<Args>) => Effect.Effect<A, E, Self | R>
77
- : Type[k] extends (...args: [...infer Args]) => infer A
78
- ? (...args: Readonly<Args>) => Effect.Effect<A, never, Self>
79
- : Type[k] extends Effect.Effect<infer A, infer E, infer R> ? Effect.Effect<A, E, Self | R>
80
- : Effect.Effect<Type[k], never, Self>
81
- }
82
- : {}
65
+ /** Accessor for a service method that returns a plain value. Wraps via `useSync`. */
66
+ export const accessFn = <
67
+ Self extends object,
68
+ Shape extends Record<PropertyKey, any>,
69
+ K extends keyof Shape
70
+ >(
71
+ Tag: Opaque<Self, Shape>,
72
+ key: K
73
+ ): Shape[K] extends (...args: [...infer Args]) => infer A ? (...args: Readonly<Args>) => Effect.Effect<A, never, Self>
74
+ : never => ((...args: Array<any>) => Tag.useSync((s: any) => s[key](...args))) as any
83
75
 
84
- /**
85
- * Only use this in very specific cases where using dependencies directly is prefered, like inside command handlers.
86
- */
87
- export const proxify = <T extends object>(Tag: T) =>
88
- <Self, Shape>():
89
- & T
90
- & ServiceAcessorShape<Self, Shape> =>
91
- {
92
- const cache = new Map()
93
- const done = new Proxy(Tag, {
94
- get(_target: any, prop: any, _receiver) {
95
- if (prop === "use") {
96
- // @ts-expect-error abc
97
- return (body) => (Tag as any).use(body)
98
- }
99
- if (prop in Tag) {
100
- return (Tag as any)[prop]
101
- }
102
- if (cache.has(prop)) {
103
- return cache.get(prop)
104
- }
105
- const fn = (...args: Array<any>) => (Tag as any).use((s: any) => s[prop](...args))
106
- const cn = (Tag as any).use((s: any) => s[prop])
107
- // @effect-diagnostics effect/floatingEffect:off
108
- Object.assign(fn, cn)
109
- Object.setPrototypeOf(fn, Object.getPrototypeOf(cn))
110
- cache.set(prop, fn)
111
- return fn
112
- }
113
- })
114
- return done
115
- }
76
+ /** Accessor for a service method that returns an Effect. Delegates via `use`. */
77
+ export const accessEffectFn = <
78
+ Self extends object,
79
+ Shape extends Record<PropertyKey, any>,
80
+ K extends keyof Shape
81
+ >(
82
+ Tag: Opaque<Self, Shape>,
83
+ key: K
84
+ ): Shape[K] extends (...args: [...infer Args]) => Effect.Effect<infer A, infer E, infer R>
85
+ ? (...args: Readonly<Args>) => Effect.Effect<A, E, Self | R>
86
+ : never => ((...args: Array<any>) => Tag.use((s: any) => s[key](...args))) as any
87
+
88
+ /** Accessor for a service property (constant). Wraps via `useSync`. */
89
+ export const accessCn = <
90
+ Self extends object,
91
+ Shape extends Record<PropertyKey, any>,
92
+ K extends keyof Shape
93
+ >(
94
+ Tag: Opaque<Self, Shape>,
95
+ key: K
96
+ ): Effect.Effect<Shape[K], never, Self> => Tag.useSync((s) => s[key])
97
+
98
+ /** Accessor for a service property that is an Effect. Delegates via `use`. */
99
+ export const accessEffectCn = <
100
+ Self extends object,
101
+ Shape extends Record<PropertyKey, any>,
102
+ K extends keyof Shape
103
+ >(
104
+ Tag: Opaque<Self, Shape>,
105
+ key: K
106
+ ): Shape[K] extends Effect.Effect<infer A, infer E, infer R> ? Effect.Effect<A, E, Self | R>
107
+ : never => Tag.use((s: any) => s[key]) as any
116
108
 
117
- export const TypeId = "~ServiceMap.Opaque"
109
+ export const TypeId = "~Context.Opaque"
118
110
 
119
111
  // export function Opaque<const Key extends string>(key: Key) {
120
112
  // return <Identifier extends object, Shape extends object>() => {
@@ -179,7 +171,7 @@ export const Opaque: {
179
171
  >
180
172
  & { readonly make: Make }
181
173
  } = () => (id: string, options: any) => {
182
- const svc = ServiceMap.Service()(id, options) as any
174
+ const svc = CTX.Service()(id, options) as any
183
175
  return Object.assign(svc, {
184
176
  toLayer: (eff: Effect.Effect<any, any, any>) => {
185
177
  return Layer.effect(svc, eff)
package/src/Effect.ts CHANGED
@@ -2,11 +2,11 @@
2
2
  /* eslint-disable prefer-destructuring */
3
3
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
4
 
5
- import { Effect, Option, Ref, type ServiceMap } from "effect"
5
+ import { Effect, Option, Ref } from "effect"
6
6
  import * as Def from "effect/Deferred"
7
- import * as Fiber from "effect/Fiber"
8
7
  import type { Scope } from "effect/Scope"
9
8
  import type { Semaphore } from "effect/Semaphore"
9
+ import type * as Context from "./Context.js"
10
10
  import { curry } from "./Function.js"
11
11
  import { typedKeysOf } from "./utils.js"
12
12
 
@@ -111,15 +111,11 @@ export function modifyWithPermitWithEffect<A>(ref: Ref.Ref<A>, semaphore: Semaph
111
111
  )
112
112
  }
113
113
 
114
- export function joinAll<E, A>(fibers: Iterable<Fiber.Fiber<A, E>>): Effect.Effect<readonly A[], E> {
115
- return Fiber.joinAll(fibers) as any
116
- }
117
-
118
114
  type ServiceA<T> = T extends Effect.Effect<infer S, any, any> ? S
119
- : T extends ServiceMap.Service<any, infer S> ? S
115
+ : T extends Context.Service<any, infer S> ? S
120
116
  : never
121
117
  type ServiceR<T> = T extends Effect.Effect<any, any, infer R> ? R
122
- : T extends ServiceMap.Service<infer I, any> ? I
118
+ : T extends Context.Service<infer I, any> ? I
123
119
  : never
124
120
  type ServiceE<T> = T extends Effect.Effect<any, infer E, any> ? E : never
125
121
  // type Values<T> = T extends { [s: string]: infer S } ? ServiceA<S> : never
@@ -144,24 +140,25 @@ export interface EffectUnunified<R, E, A> extends Effect.Effect<R, E, A> {}
144
140
 
145
141
  export type LowerFirst<S extends PropertyKey> = S extends `${infer First}${infer Rest}` ? `${Lowercase<First>}${Rest}`
146
142
  : S
147
- export type LowerServices<T extends Record<string, ServiceMap.Service<any, any> | Effect.Effect<any, any, any>>> = {
143
+ export type LowerServices<T extends Record<string, Context.Service<any, any> | Effect.Effect<any, any, any>>> = {
148
144
  [key in keyof T as LowerFirst<key>]: ServiceA<T[key]>
149
145
  }
150
146
 
151
- export function allLower<T extends Record<string, ServiceMap.Service<any, any> | Effect.Effect<any, any, any>>>(
147
+ export function allLower<T extends Record<string, Context.Service<any, any> | Effect.Effect<any, any, any>>>(
152
148
  services: T
153
149
  ) {
154
150
  return Effect.all(
155
151
  typedKeysOf(services).reduce((prev, cur) => {
156
- const svc = services[cur]
157
- prev[((cur as string)[0]!.toLowerCase() + (cur as string).slice(1)) as unknown as LowerFirst<typeof cur>] = svc // "_id" in svc && svc._id === TagTypeId ? svc : svc
152
+ const svc = services[cur]!
153
+ prev[((cur as string)[0]!.toLowerCase() + (cur as string).slice(1)) as unknown as LowerFirst<typeof cur>] =
154
+ "asEffect" in svc ? svc.asEffect() : svc
158
155
  return prev
159
156
  }, {} as any),
160
157
  { concurrency: "inherit" }
161
158
  ) as any as Effect.Effect<LowerServices<T>, ValuesE<T>, ValuesR<T>>
162
159
  }
163
160
 
164
- export function allLowerWith<T extends Record<string, ServiceMap.Service<any, any> | Effect.Effect<any, any, any>>, A>(
161
+ export function allLowerWith<T extends Record<string, Context.Service<any, any> | Effect.Effect<any, any, any>>, A>(
165
162
  services: T,
166
163
  fn: (services: LowerServices<T>) => A
167
164
  ) {
@@ -169,7 +166,7 @@ export function allLowerWith<T extends Record<string, ServiceMap.Service<any, an
169
166
  }
170
167
 
171
168
  export function allLowerWithEffect<
172
- T extends Record<string, ServiceMap.Service<any, any> | Effect.Effect<any, any, any>>,
169
+ T extends Record<string, Context.Service<any, any> | Effect.Effect<any, any, any>>,
173
170
  R,
174
171
  E,
175
172
  A
package/src/Layer.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { type Array, Effect, Layer, type Scope, type ServiceMap, type Types } from "effect"
1
+ import { type Array, Effect, Layer, type Scope, type Types } from "effect"
2
2
  import { type Yieldable } from "effect/Effect"
3
3
  import { dual } from "effect/Function"
4
+ import type * as Context from "./Context.js"
4
5
  import { type EffectGenUtils } from "./utils/gen.js"
5
6
 
6
7
  export * from "effect/Layer"
@@ -17,7 +18,7 @@ type MakeGenNo<S> = {
17
18
  readonly make: () => Generator<unknown, S>
18
19
  }
19
20
  type MakeErr<Opts> = Opts extends { make: () => any } ? EffectGenUtils.Error<Opts["make"]> : never
20
- type MakeContext<Opts> = Opts extends { make: () => any } ? EffectGenUtils.ServiceMap<Opts["make"]> : never
21
+ type MakeContext<Opts> = Opts extends { make: () => any } ? EffectGenUtils.Context<Opts["make"]> : never
21
22
 
22
23
  type DependenciesOpt = { dependencies?: Array.NonEmptyReadonlyArray<Layer.Any> }
23
24
  type Dependencies = { dependencies: Array.NonEmptyReadonlyArray<Layer.Any> }
@@ -41,12 +42,12 @@ type PackedOrUnpackedLayer<I, Opts> = Opts extends Dependencies ? PackedLayers<I
41
42
 
42
43
  export const make: {
43
44
  <I, S>(
44
- tag: ServiceMap.Service<I, S>
45
+ tag: Context.Service<I, S>
45
46
  ): <Opts extends Make<Types.NoInfer<S>, any, any>>(
46
47
  options: Opts
47
48
  ) => PackedOrUnpackedLayer<I, Opts>
48
49
  <I, S, Opts extends Make<Types.NoInfer<S>, any, any>>(
49
- tag: ServiceMap.Service<I, S>,
50
+ tag: Context.Service<I, S>,
50
51
  options: Opts
51
52
  ): PackedOrUnpackedLayer<I, Opts>
52
53
  } = dual(2, (tag, options) => {
package/src/Pure.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  import { Chunk, Effect, Layer, Result } from "effect"
3
+ import * as Context from "./Context.js"
3
4
  import { tuple } from "./Function.js"
4
- import * as ServiceMap from "./ServiceMap.js"
5
5
 
6
6
  const S1 = Symbol()
7
7
  const S2 = Symbol()
@@ -86,9 +86,9 @@ export function GMU<W, S, S2, GA, MR, ME>(modify: (i: GA) => Pure<W, S, S2, MR,
86
86
  ) => GMU_(get, modify, update)
87
87
  }
88
88
 
89
- const tagg = ServiceMap.Service<{ env: PureEnv<never, unknown, never> }>("PureEnv")
89
+ const tagg = Context.Service<{ env: PureEnv<never, unknown, never> }>("PureEnv")
90
90
  function castTag<W, S, S2>() {
91
- return tagg as any as ServiceMap.Service<PureEnvEnv<W, S, S2>, PureEnvEnv<W, S, S2>>
91
+ return tagg as any as Context.Service<PureEnvEnv<W, S, S2>, PureEnvEnv<W, S, S2>>
92
92
  }
93
93
 
94
94
  export const ServiceTag = Symbol()
@@ -100,9 +100,9 @@ export abstract class PhantomTypeParameter<Identifier extends keyof any, Instant
100
100
  }
101
101
  }
102
102
 
103
- export type ServiceShape<T extends ServiceMap.ServiceClass.Shape<any, any>> = Omit<
103
+ export type ServiceShape<T extends Context.ServiceClass.Shape<any, any>> = Omit<
104
104
  T,
105
- keyof ServiceMap.ServiceClass.Shape<any, any>
105
+ keyof Context.ServiceClass.Shape<any, any>
106
106
  >
107
107
 
108
108
  export abstract class ServiceTagged<ServiceKey> extends PhantomTypeParameter<string, ServiceKey> {}
@@ -117,11 +117,11 @@ export interface PureEnvEnv<W, S, S2> extends ServiceTagged<typeof PureEnvEnv> {
117
117
  }
118
118
 
119
119
  export function get<S>(): Pure<never, S, S, never, never, S> {
120
- return (castTag<never, S, S>() as any).use((_: any) => _.env.state)
120
+ return (castTag<never, S, S>()).useSync((_) => _.env.state)
121
121
  }
122
122
 
123
123
  export function set<S>(s: S): Pure<never, S, S, never, never, void> {
124
- return (castTag<never, S, S>() as any).use((_: any) => {
124
+ return (castTag<never, S, S>()).useSync((_) => {
125
125
  _.env.state = s
126
126
  })
127
127
  }
@@ -129,13 +129,13 @@ export function set<S>(s: S): Pure<never, S, S, never, never, void> {
129
129
  export type PureLogT<W> = Pure<W, unknown, never, never, never, void>
130
130
 
131
131
  export function log<W>(w: W): PureLogT<W> {
132
- return (castTag<W, unknown, never>() as any).use((_: any) => {
132
+ return (castTag<W, unknown, never>()).useSync((_) => {
133
133
  _.env.log = Chunk.append(_.env.log, w)
134
134
  })
135
135
  }
136
136
 
137
137
  export function logMany<W>(w: Iterable<W>): PureLogT<W> {
138
- return (castTag<W, unknown, never>() as any).use((_: any) => {
138
+ return (castTag<W, unknown, never>()).useSync((_) => {
139
139
  _.env.log = Chunk.appendAll(_.env.log, Chunk.fromIterable(w))
140
140
  })
141
141
  }
@@ -150,17 +150,16 @@ export function runAll<R, E, A, W3, S1, S3, S4 extends S1>(
150
150
  > {
151
151
  const a = Effect
152
152
  .flatMap(self, (x) =>
153
- (castTag<W3, S1, S3>() as any)
154
- .use(
155
- ({ env: _ }: any) => Effect.sync(() => ({ log: _.log, state: _.state }))
153
+ (castTag<W3, S1, S3>())
154
+ .useSync(
155
+ ({ env: _ }) => ({ log: _.log, state: _.state })
156
156
  )
157
157
  .pipe(
158
- Effect.flatMap((_: any) => Effect.succeed(_)),
159
158
  Effect.map(
160
- ({ log, state }: any) => tuple(log, Result.succeed(tuple(state, x)))
159
+ ({ log, state }) => tuple(log, Result.succeed(tuple(state, x)))
161
160
  )
162
161
  ))
163
- .pipe(Effect.catch((err: any) => (tagg as any).use((env: any) => tuple(env.env.log, Result.fail(err)))))
162
+ .pipe(Effect.catch((err: any) => tagg.useSync((env) => tuple(env.env.log, Result.fail(err)))))
164
163
  return Effect.provide(a, Layer.succeed(tagg, { env: makePureEnv<W3, S3, S4>(s) as any }) as any) as any
165
164
  }
166
165
 
@@ -198,11 +197,11 @@ export function runA<R, E, A, W3, S1, S3, S4 extends S1>(
198
197
  export function modify<S2, A, S3>(
199
198
  mod: (s: S2) => readonly [S3, A]
200
199
  ): Effect.Effect<A, never, { env: PureEnv<never, S2, S3> }> {
201
- return (castTag<never, S3, S2>() as any).use((_: any) => {
200
+ return (castTag<never, S3, S2>()).useSync((_) => {
202
201
  const [s, a] = mod(_.env.state)
203
202
  _.env.state = s as any
204
203
  return a
205
- })
204
+ }) as any
206
205
  }
207
206
 
208
207
  export function modifyM<W, R, E, A, S2, S3>(
@@ -210,7 +209,7 @@ export function modifyM<W, R, E, A, S2, S3>(
210
209
  ): Effect.Effect<A, E, FixEnv<R, W, S2, S3>> {
211
210
  // return serviceWithEffect(_ => Ref.modifyM_(_.state, mod))
212
211
  return Effect.flatMap(
213
- (castTag<W, S3, S2>() as any).use((_: any) => _),
212
+ (castTag<W, S3, S2>()).useSync((_) => _),
214
213
  (_: any) =>
215
214
  Effect.map(mod(_.env.state), ([s, a]: any) => {
216
215
  _.env.state = s