effect-app 4.0.0-beta.21 → 4.0.0-beta.210

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 (219) hide show
  1. package/CHANGELOG.md +952 -0
  2. package/dist/Array.d.ts +1 -1
  3. package/dist/Chunk.d.ts +1 -1
  4. package/dist/Chunk.d.ts.map +1 -1
  5. package/dist/Config/SecretURL.d.ts +1 -1
  6. package/dist/Config/SecretURL.d.ts.map +1 -1
  7. package/dist/Config/SecretURL.js +2 -2
  8. package/dist/Config/internal/configSecretURL.d.ts +1 -1
  9. package/dist/Config/internal/configSecretURL.d.ts.map +1 -1
  10. package/dist/Config.d.ts +7 -0
  11. package/dist/Config.d.ts.map +1 -0
  12. package/dist/Config.js +6 -0
  13. package/dist/ConfigProvider.d.ts +39 -0
  14. package/dist/ConfigProvider.d.ts.map +1 -0
  15. package/dist/ConfigProvider.js +42 -0
  16. package/dist/Context.d.ts +40 -0
  17. package/dist/Context.d.ts.map +1 -0
  18. package/dist/Context.js +67 -0
  19. package/dist/Effect.d.ts +9 -10
  20. package/dist/Effect.d.ts.map +1 -1
  21. package/dist/Effect.js +3 -6
  22. package/dist/Function.d.ts +1 -1
  23. package/dist/Function.d.ts.map +1 -1
  24. package/dist/Inputify.type.d.ts +1 -1
  25. package/dist/Layer.d.ts +7 -6
  26. package/dist/Layer.d.ts.map +1 -1
  27. package/dist/Layer.js +1 -1
  28. package/dist/NonEmptySet.d.ts +1 -1
  29. package/dist/NonEmptySet.d.ts.map +1 -1
  30. package/dist/Option.d.ts +1 -1
  31. package/dist/Option.d.ts.map +1 -1
  32. package/dist/Pure.d.ts +5 -5
  33. package/dist/Pure.d.ts.map +1 -1
  34. package/dist/Pure.js +13 -13
  35. package/dist/Schema/Class.d.ts +66 -20
  36. package/dist/Schema/Class.d.ts.map +1 -1
  37. package/dist/Schema/Class.js +189 -22
  38. package/dist/Schema/FastCheck.d.ts +1 -1
  39. package/dist/Schema/FastCheck.d.ts.map +1 -1
  40. package/dist/Schema/Methods.d.ts +1 -1
  41. package/dist/Schema/SchemaParser.d.ts +5 -0
  42. package/dist/Schema/SchemaParser.d.ts.map +1 -0
  43. package/dist/Schema/SchemaParser.js +6 -0
  44. package/dist/Schema/SpecialJsonSchema.d.ts +33 -0
  45. package/dist/Schema/SpecialJsonSchema.d.ts.map +1 -0
  46. package/dist/Schema/SpecialJsonSchema.js +122 -0
  47. package/dist/Schema/SpecialOpenApi.d.ts +32 -0
  48. package/dist/Schema/SpecialOpenApi.d.ts.map +1 -0
  49. package/dist/Schema/SpecialOpenApi.js +123 -0
  50. package/dist/Schema/brand.d.ts +4 -2
  51. package/dist/Schema/brand.d.ts.map +1 -1
  52. package/dist/Schema/brand.js +1 -1
  53. package/dist/Schema/email.d.ts +1 -1
  54. package/dist/Schema/email.d.ts.map +1 -1
  55. package/dist/Schema/email.js +7 -4
  56. package/dist/Schema/ext.d.ts +117 -45
  57. package/dist/Schema/ext.d.ts.map +1 -1
  58. package/dist/Schema/ext.js +131 -42
  59. package/dist/Schema/moreStrings.d.ts +37 -25
  60. package/dist/Schema/moreStrings.d.ts.map +1 -1
  61. package/dist/Schema/moreStrings.js +15 -16
  62. package/dist/Schema/numbers.d.ts +15 -15
  63. package/dist/Schema/numbers.d.ts.map +1 -1
  64. package/dist/Schema/numbers.js +10 -12
  65. package/dist/Schema/phoneNumber.d.ts +1 -1
  66. package/dist/Schema/phoneNumber.d.ts.map +1 -1
  67. package/dist/Schema/phoneNumber.js +6 -3
  68. package/dist/Schema/schema.d.ts +1 -1
  69. package/dist/Schema/strings.d.ts +5 -5
  70. package/dist/Schema/strings.d.ts.map +1 -1
  71. package/dist/Schema/strings.js +1 -5
  72. package/dist/Schema.d.ts +147 -15
  73. package/dist/Schema.d.ts.map +1 -1
  74. package/dist/Schema.js +131 -16
  75. package/dist/Set.d.ts +1 -1
  76. package/dist/Set.d.ts.map +1 -1
  77. package/dist/TypeTest.d.ts +1 -1
  78. package/dist/Types.d.ts +1 -1
  79. package/dist/Widen.type.d.ts +1 -1
  80. package/dist/_ext/Array.d.ts +1 -1
  81. package/dist/_ext/Array.d.ts.map +1 -1
  82. package/dist/_ext/date.d.ts +1 -1
  83. package/dist/_ext/misc.d.ts +1 -1
  84. package/dist/_ext/ord.ext.d.ts +1 -1
  85. package/dist/_ext/ord.ext.d.ts.map +1 -1
  86. package/dist/builtin.d.ts +1 -1
  87. package/dist/builtin.d.ts.map +1 -1
  88. package/dist/client/InvalidationKeys.d.ts +29 -0
  89. package/dist/client/InvalidationKeys.d.ts.map +1 -0
  90. package/dist/client/InvalidationKeys.js +33 -0
  91. package/dist/client/apiClientFactory.d.ts +20 -32
  92. package/dist/client/apiClientFactory.d.ts.map +1 -1
  93. package/dist/client/apiClientFactory.js +95 -32
  94. package/dist/client/clientFor.d.ts +51 -17
  95. package/dist/client/clientFor.d.ts.map +1 -1
  96. package/dist/client/clientFor.js +9 -1
  97. package/dist/client/errors.d.ts +49 -25
  98. package/dist/client/errors.d.ts.map +1 -1
  99. package/dist/client/errors.js +43 -17
  100. package/dist/client/makeClient.d.ts +481 -33
  101. package/dist/client/makeClient.d.ts.map +1 -1
  102. package/dist/client/makeClient.js +66 -24
  103. package/dist/client.d.ts +2 -1
  104. package/dist/client.d.ts.map +1 -1
  105. package/dist/client.js +2 -1
  106. package/dist/faker.d.ts +1 -1
  107. package/dist/faker.d.ts.map +1 -1
  108. package/dist/http/Request.d.ts +2 -2
  109. package/dist/http/Request.d.ts.map +1 -1
  110. package/dist/http/internal/lib.d.ts +1 -1
  111. package/dist/http.d.ts +1 -1
  112. package/dist/ids.d.ts +12 -12
  113. package/dist/ids.d.ts.map +1 -1
  114. package/dist/ids.js +3 -2
  115. package/dist/index.d.ts +5 -8
  116. package/dist/index.d.ts.map +1 -1
  117. package/dist/index.js +6 -8
  118. package/dist/logger.d.ts +1 -1
  119. package/dist/middleware.d.ts +14 -8
  120. package/dist/middleware.d.ts.map +1 -1
  121. package/dist/middleware.js +14 -8
  122. package/dist/rpc/Invalidation.d.ts +402 -0
  123. package/dist/rpc/Invalidation.d.ts.map +1 -0
  124. package/dist/rpc/Invalidation.js +150 -0
  125. package/dist/rpc/MiddlewareMaker.d.ts +5 -4
  126. package/dist/rpc/MiddlewareMaker.d.ts.map +1 -1
  127. package/dist/rpc/MiddlewareMaker.js +57 -37
  128. package/dist/rpc/RpcContextMap.d.ts +3 -3
  129. package/dist/rpc/RpcContextMap.d.ts.map +1 -1
  130. package/dist/rpc/RpcContextMap.js +4 -4
  131. package/dist/rpc/RpcMiddleware.d.ts +5 -4
  132. package/dist/rpc/RpcMiddleware.d.ts.map +1 -1
  133. package/dist/rpc/RpcMiddleware.js +1 -1
  134. package/dist/rpc.d.ts +2 -2
  135. package/dist/rpc.d.ts.map +1 -1
  136. package/dist/rpc.js +2 -2
  137. package/dist/transform.d.ts +1 -1
  138. package/dist/transform.d.ts.map +1 -1
  139. package/dist/transform.js +3 -3
  140. package/dist/utils/effectify.d.ts +1 -1
  141. package/dist/utils/extend.d.ts +1 -1
  142. package/dist/utils/extend.d.ts.map +1 -1
  143. package/dist/utils/gen.d.ts +2 -2
  144. package/dist/utils/gen.d.ts.map +1 -1
  145. package/dist/utils/logLevel.d.ts +2 -2
  146. package/dist/utils/logLevel.d.ts.map +1 -1
  147. package/dist/utils/logger.d.ts +3 -3
  148. package/dist/utils/logger.d.ts.map +1 -1
  149. package/dist/utils/logger.js +3 -3
  150. package/dist/utils.d.ts +31 -38
  151. package/dist/utils.d.ts.map +1 -1
  152. package/dist/utils.js +12 -25
  153. package/dist/validation/validators.d.ts +1 -1
  154. package/dist/validation/validators.d.ts.map +1 -1
  155. package/dist/validation.d.ts +1 -1
  156. package/dist/validation.d.ts.map +1 -1
  157. package/package.json +46 -24
  158. package/src/Config/SecretURL.ts +2 -1
  159. package/src/Config.ts +14 -0
  160. package/src/ConfigProvider.ts +48 -0
  161. package/src/{ServiceMap.ts → Context.ts} +52 -59
  162. package/src/Effect.ts +12 -14
  163. package/src/Layer.ts +6 -5
  164. package/src/Pure.ts +17 -18
  165. package/src/Schema/Class.ts +268 -62
  166. package/src/Schema/SchemaParser.ts +12 -0
  167. package/src/Schema/SpecialJsonSchema.ts +137 -0
  168. package/src/Schema/SpecialOpenApi.ts +130 -0
  169. package/src/Schema/brand.ts +21 -1
  170. package/src/Schema/email.ts +7 -2
  171. package/src/Schema/ext.ts +204 -72
  172. package/src/Schema/moreStrings.ts +40 -37
  173. package/src/Schema/numbers.ts +14 -16
  174. package/src/Schema/phoneNumber.ts +5 -1
  175. package/src/Schema/strings.ts +4 -8
  176. package/src/Schema.ts +314 -20
  177. package/src/client/InvalidationKeys.ts +50 -0
  178. package/src/client/apiClientFactory.ts +223 -129
  179. package/src/client/clientFor.ts +95 -29
  180. package/src/client/errors.ts +52 -26
  181. package/src/client/makeClient.ts +572 -71
  182. package/src/client.ts +1 -0
  183. package/src/ids.ts +3 -2
  184. package/src/index.ts +5 -10
  185. package/src/middleware.ts +13 -9
  186. package/src/rpc/Invalidation.ts +226 -0
  187. package/src/rpc/MiddlewareMaker.ts +65 -60
  188. package/src/rpc/README.md +2 -2
  189. package/src/rpc/RpcContextMap.ts +6 -5
  190. package/src/rpc/RpcMiddleware.ts +5 -4
  191. package/src/rpc.ts +1 -1
  192. package/src/transform.ts +2 -2
  193. package/src/utils/gen.ts +1 -1
  194. package/src/utils/logger.ts +2 -2
  195. package/src/utils.ts +50 -132
  196. package/test/dist/rpc.test.d.ts.map +1 -1
  197. package/test/dist/secretURL.test.d.ts.map +1 -0
  198. package/test/dist/special.test.d.ts.map +1 -0
  199. package/test/dist/stream-error.types.d.ts +2 -0
  200. package/test/dist/stream-error.types.d.ts.map +1 -0
  201. package/test/dist/stream-error.types.js +27 -0
  202. package/test/rpc.test.ts +45 -6
  203. package/test/schema.test.ts +581 -7
  204. package/test/secretURL.test.ts +157 -0
  205. package/test/special.test.ts +1023 -0
  206. package/test/utils.test.ts +6 -6
  207. package/tsconfig.base.json +3 -4
  208. package/tsconfig.json +0 -1
  209. package/tsconfig.json.bak +2 -2
  210. package/tsconfig.src.json +29 -29
  211. package/tsconfig.test.json +2 -2
  212. package/dist/Operations.d.ts +0 -123
  213. package/dist/Operations.d.ts.map +0 -1
  214. package/dist/Operations.js +0 -29
  215. package/dist/ServiceMap.d.ts +0 -44
  216. package/dist/ServiceMap.d.ts.map +0 -1
  217. package/dist/ServiceMap.js +0 -91
  218. package/eslint.config.mjs +0 -26
  219. package/src/Operations.ts +0 -55
package/package.json CHANGED
@@ -1,31 +1,30 @@
1
1
  {
2
2
  "name": "effect-app",
3
- "version": "4.0.0-beta.21",
3
+ "version": "4.0.0-beta.210",
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.11",
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"
26
25
  },
27
26
  "peerDependencies": {
28
- "effect": "^4.0.0-beta.36"
27
+ "effect": "^4.0.0-beta.62"
29
28
  },
30
29
  "typesVersions": {
31
30
  "*": {
@@ -47,10 +46,22 @@
47
46
  "types": "./dist/Chunk.d.ts",
48
47
  "default": "./dist/Chunk.js"
49
48
  },
49
+ "./Config": {
50
+ "types": "./dist/Config.d.ts",
51
+ "default": "./dist/Config.js"
52
+ },
50
53
  "./Config/SecretURL": {
51
54
  "types": "./dist/Config/SecretURL.d.ts",
52
55
  "default": "./dist/Config/SecretURL.js"
53
56
  },
57
+ "./ConfigProvider": {
58
+ "types": "./dist/ConfigProvider.d.ts",
59
+ "default": "./dist/ConfigProvider.js"
60
+ },
61
+ "./Context": {
62
+ "types": "./dist/Context.d.ts",
63
+ "default": "./dist/Context.js"
64
+ },
54
65
  "./Effect": {
55
66
  "types": "./dist/Effect.d.ts",
56
67
  "default": "./dist/Effect.js"
@@ -71,10 +82,6 @@
71
82
  "types": "./dist/NonEmptySet.d.ts",
72
83
  "default": "./dist/NonEmptySet.js"
73
84
  },
74
- "./Operations": {
75
- "types": "./dist/Operations.d.ts",
76
- "default": "./dist/Operations.js"
77
- },
78
85
  "./Option": {
79
86
  "types": "./dist/Option.d.ts",
80
87
  "default": "./dist/Option.js"
@@ -99,6 +106,18 @@
99
106
  "types": "./dist/Schema/Methods.d.ts",
100
107
  "default": "./dist/Schema/Methods.js"
101
108
  },
109
+ "./Schema/SchemaParser": {
110
+ "types": "./dist/Schema/SchemaParser.d.ts",
111
+ "default": "./dist/Schema/SchemaParser.js"
112
+ },
113
+ "./Schema/SpecialJsonSchema": {
114
+ "types": "./dist/Schema/SpecialJsonSchema.d.ts",
115
+ "default": "./dist/Schema/SpecialJsonSchema.js"
116
+ },
117
+ "./Schema/SpecialOpenApi": {
118
+ "types": "./dist/Schema/SpecialOpenApi.d.ts",
119
+ "default": "./dist/Schema/SpecialOpenApi.js"
120
+ },
102
121
  "./Schema/brand": {
103
122
  "types": "./dist/Schema/brand.d.ts",
104
123
  "default": "./dist/Schema/brand.js"
@@ -131,10 +150,6 @@
131
150
  "types": "./dist/Schema/strings.d.ts",
132
151
  "default": "./dist/Schema/strings.js"
133
152
  },
134
- "./ServiceMap": {
135
- "types": "./dist/ServiceMap.d.ts",
136
- "default": "./dist/ServiceMap.js"
137
- },
138
153
  "./Set": {
139
154
  "types": "./dist/Set.d.ts",
140
155
  "default": "./dist/Set.js"
@@ -175,6 +190,10 @@
175
190
  "types": "./dist/client.d.ts",
176
191
  "default": "./dist/client.js"
177
192
  },
193
+ "./client/InvalidationKeys": {
194
+ "types": "./dist/client/InvalidationKeys.d.ts",
195
+ "default": "./dist/client/InvalidationKeys.js"
196
+ },
178
197
  "./client/apiClientFactory": {
179
198
  "types": "./dist/client/apiClientFactory.d.ts",
180
199
  "default": "./dist/client/apiClientFactory.js"
@@ -219,6 +238,10 @@
219
238
  "types": "./dist/rpc.d.ts",
220
239
  "default": "./dist/rpc.js"
221
240
  },
241
+ "./rpc/Invalidation": {
242
+ "types": "./dist/rpc/Invalidation.d.ts",
243
+ "default": "./dist/rpc/Invalidation.js"
244
+ },
222
245
  "./rpc/MiddlewareMaker": {
223
246
  "types": "./dist/rpc/MiddlewareMaker.d.ts",
224
247
  "default": "./dist/rpc/MiddlewareMaker.js"
@@ -280,20 +303,19 @@
280
303
  "scripts": {
281
304
  "watch": "pnpm build:tsc -w",
282
305
  "build:tsc": "pnpm clean-dist && effect-app-cli packagejson && pnpm check",
283
- "check": "tsc --build",
306
+ "check": "tsgo --build",
284
307
  "build:tsc-src": "pnpm clean-dist && effect-app-cli packagejson tsc --build ./tsconfig.src.json",
285
308
  "build:src": "pnpm build:tsc-src",
286
309
  "build": "pnpm build:tsc",
287
- "watch2": "pnpm clean-dist && NODE_OPTIONS=--max-old-space-size=6144 tsc -w",
310
+ "watch2": "pnpm clean-dist && NODE_OPTIONS=--max-old-space-size=6144 tsgo -w",
288
311
  "clean": "rm -rf dist",
289
312
  "clean-dist": "sh ../../scripts/clean-dist.sh",
290
313
  "circular": "pnpm circular:src && pnpm circular:dist",
291
314
  "circular:src": "madge --circular --ts-config ./tsconfig.json --extensions ts ./src",
292
315
  "circular:dist": "madge --circular --extensions js ./dist",
293
- "compile": "NODE_OPTIONS=--max-old-space-size=6144 tsc --noEmit",
294
- "lint": "NODE_OPTIONS=--max-old-space-size=6144 ESLINT_TS=1 eslint ./src",
295
- "lint:watch": "ESLINT_TS=1 esw -w --changed --clear --ext ts,tsx .",
296
- "lint-fix": "pnpm lint --fix",
316
+ "compile": "NODE_OPTIONS=--max-old-space-size=6144 tsgo --noEmit",
317
+ "lint": "oxlint --type-aware ./src && pnpm exec dprint check --config ../../dprint.jsonc .",
318
+ "lint-fix": "oxlint --type-aware --fix ./src && pnpm exec dprint fmt --config ../../dprint.jsonc .",
297
319
  "test": "vitest",
298
320
  "test:run": "pnpm run test run --passWithNoTests",
299
321
  "testsuite": "pnpm lint && pnpm circular && pnpm run test:run",
@@ -21,6 +21,7 @@ import * as internal from "./internal/configSecretURL.js"
21
21
  * @since 1.0.0
22
22
  * @category models
23
23
  */
24
+ // eslint-disable-next-line import/namespace
24
25
  export interface SecretURL extends Redacted.Redacted, Equal.Equal {
25
26
  /** @internal */
26
27
  readonly raw: Array<number>
@@ -73,5 +74,5 @@ export const value: (self: SecretURL) => string = internal.value
73
74
  export const unsafeWipe: (self: SecretURL) => void = internal.unsafeWipe
74
75
 
75
76
  export const secretURL = (name?: string): Config.Config<SecretURL> => {
76
- return Config.map(Config.string(name), fromString)
77
+ return Config.map(Config.nonEmptyString(name), fromString)
77
78
  }
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,17 @@
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
- */
2
+ /* eslint-disable import/namespace */
7
3
 
8
4
  import { type Effect, Layer, type Scope, type Types } from "effect"
9
- import * as ServiceMap from "effect/ServiceMap"
5
+ import * as CTX from "effect/Context"
10
6
  import { type Yieldable } from "./Effect.js"
11
7
 
12
- export * from "effect/ServiceMap"
8
+ export * from "effect/Context"
13
9
 
14
10
  export interface Opaque<Self extends object, in out Shape extends object>
15
- extends ServiceMap.Key<Self, Self>, Yieldable<Opaque<Self, Shape>, Self, never, Self>
11
+ extends CTX.Key<Self, Self>, Yieldable<Opaque<Self, Shape>, Self, never, Self>
16
12
  {
17
13
  of(this: void, self: Shape): Self
18
- serviceMap(self: Shape): ServiceMap.ServiceMap<Self>
14
+ context(self: Shape): CTX.Context<Self>
19
15
  // a version that leverages the Shape -> Self conversion
20
16
  toLayer: <E, R>(
21
17
  eff: Effect.Effect<Shape, E, R>
@@ -25,11 +21,11 @@ export interface Opaque<Self extends object, in out Shape extends object>
25
21
  }
26
22
 
27
23
  // export interface OpaqueMake<Self extends object, in out Shape extends object, E, R>
28
- // extends ServiceMap.Service<Self, Self>
24
+ // extends CTX.Service<Self, Self>
29
25
  // {
30
26
  // // temp while sorting out https://github.com/Effect-TS/effect-smol/pull/1534
31
27
  // of(self: Shape): Self
32
- // serviceMap2(self: Shape): ServiceMap.ServiceMap<Self>
28
+ // contextMap2(self: Shape): CTX.Context<Self>
33
29
  // // a version that leverages the Shape -> Self conversion
34
30
  // toLayer: {
35
31
  // <E, R>(
@@ -44,7 +40,7 @@ export function assignTag<Identifier extends object, Shape extends object = Iden
44
40
  creationError?: Error
45
41
  ) {
46
42
  return <S extends object>(cls: S): S & Opaque<Identifier, Shape> => {
47
- const tag = ServiceMap.Service<Identifier, Shape>(key)
43
+ const tag = CTX.Service<Identifier, Shape>(key)
48
44
  let fields = tag
49
45
  if (Reflect.ownKeys(cls).includes("key")) {
50
46
  const { key, ...rest } = tag
@@ -67,54 +63,51 @@ export function assignTag<Identifier extends object, Shape extends object = Iden
67
63
  }
68
64
  }
69
65
 
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
- : {}
66
+ /** Accessor for a service method that returns a plain value. Wraps via `useSync`. */
67
+ export const accessFn = <
68
+ Self extends object,
69
+ Shape extends Record<PropertyKey, any>,
70
+ K extends keyof Shape
71
+ >(
72
+ Tag: Opaque<Self, Shape>,
73
+ key: K
74
+ ): Shape[K] extends (...args: [...infer Args]) => infer A ? (...args: Readonly<Args>) => Effect.Effect<A, never, Self>
75
+ : never => ((...args: Array<any>) => Tag.useSync((s: any) => s[key](...args))) as any
83
76
 
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
- }
77
+ /** Accessor for a service method that returns an Effect. Delegates via `use`. */
78
+ export const accessEffectFn = <
79
+ Self extends object,
80
+ Shape extends Record<PropertyKey, any>,
81
+ K extends keyof Shape
82
+ >(
83
+ Tag: Opaque<Self, Shape>,
84
+ key: K
85
+ ): Shape[K] extends (...args: [...infer Args]) => Effect.Effect<infer A, infer E, infer R>
86
+ ? (...args: Readonly<Args>) => Effect.Effect<A, E, Self | R>
87
+ : never => ((...args: Array<any>) => Tag.use((s: any) => s[key](...args))) as any
88
+
89
+ /** Accessor for a service property (constant). Wraps via `useSync`. */
90
+ export const accessCn = <
91
+ Self extends object,
92
+ Shape extends Record<PropertyKey, any>,
93
+ K extends keyof Shape
94
+ >(
95
+ Tag: Opaque<Self, Shape>,
96
+ key: K
97
+ ): Effect.Effect<Shape[K], never, Self> => Tag.useSync((s) => s[key])
98
+
99
+ /** Accessor for a service property that is an Effect. Delegates via `use`. */
100
+ export const accessEffectCn = <
101
+ Self extends object,
102
+ Shape extends Record<PropertyKey, any>,
103
+ K extends keyof Shape
104
+ >(
105
+ Tag: Opaque<Self, Shape>,
106
+ key: K
107
+ ): Shape[K] extends Effect.Effect<infer A, infer E, infer R> ? Effect.Effect<A, E, Self | R>
108
+ : never => Tag.use((s: any) => s[key]) as any
116
109
 
117
- export const TypeId = "~ServiceMap.Opaque"
110
+ export const TypeId = "~Context.Opaque"
118
111
 
119
112
  // export function Opaque<const Key extends string>(key: Key) {
120
113
  // return <Identifier extends object, Shape extends object>() => {
@@ -179,7 +172,7 @@ export const Opaque: {
179
172
  >
180
173
  & { readonly make: Make }
181
174
  } = () => (id: string, options: any) => {
182
- const svc = ServiceMap.Service()(id, options) as any
175
+ const svc = CTX.Service()(id, options) as any
183
176
  return Object.assign(svc, {
184
177
  toLayer: (eff: Effect.Effect<any, any, any>) => {
185
178
  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
@@ -140,28 +136,30 @@ type ValuesE<T> = T extends { [s: string]: infer S } ? ServiceE<S> : never
140
136
  * const b = a({ str: "" }) // valid, but shouldn't be!
141
137
  * ```
142
138
  */
139
+ // eslint-disable-next-line import/namespace
143
140
  export interface EffectUnunified<R, E, A> extends Effect.Effect<R, E, A> {}
144
141
 
145
142
  export type LowerFirst<S extends PropertyKey> = S extends `${infer First}${infer Rest}` ? `${Lowercase<First>}${Rest}`
146
143
  : S
147
- export type LowerServices<T extends Record<string, ServiceMap.Service<any, any> | Effect.Effect<any, any, any>>> = {
144
+ export type LowerServices<T extends Record<string, Context.Service<any, any> | Effect.Effect<any, any, any>>> = {
148
145
  [key in keyof T as LowerFirst<key>]: ServiceA<T[key]>
149
146
  }
150
147
 
151
- export function allLower<T extends Record<string, ServiceMap.Service<any, any> | Effect.Effect<any, any, any>>>(
148
+ export function allLower<T extends Record<string, Context.Service<any, any> | Effect.Effect<any, any, any>>>(
152
149
  services: T
153
150
  ) {
154
151
  return Effect.all(
155
152
  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
153
+ const svc = services[cur]!
154
+ prev[((cur as string)[0]!.toLowerCase() + (cur as string).slice(1)) as unknown as LowerFirst<typeof cur>] =
155
+ "asEffect" in svc ? svc.asEffect() : svc
158
156
  return prev
159
157
  }, {} as any),
160
158
  { concurrency: "inherit" }
161
159
  ) as any as Effect.Effect<LowerServices<T>, ValuesE<T>, ValuesR<T>>
162
160
  }
163
161
 
164
- export function allLowerWith<T extends Record<string, ServiceMap.Service<any, any> | Effect.Effect<any, any, any>>, A>(
162
+ export function allLowerWith<T extends Record<string, Context.Service<any, any> | Effect.Effect<any, any, any>>, A>(
165
163
  services: T,
166
164
  fn: (services: LowerServices<T>) => A
167
165
  ) {
@@ -169,7 +167,7 @@ export function allLowerWith<T extends Record<string, ServiceMap.Service<any, an
169
167
  }
170
168
 
171
169
  export function allLowerWithEffect<
172
- T extends Record<string, ServiceMap.Service<any, any> | Effect.Effect<any, any, any>>,
170
+ T extends Record<string, Context.Service<any, any> | Effect.Effect<any, any, any>>,
173
171
  R,
174
172
  E,
175
173
  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"
@@ -11,13 +12,13 @@ type MakeEff<S, E, R> = {
11
12
  readonly make: Effect.Effect<S, E, R>
12
13
  }
13
14
  type MakeGen<S, E = never, R = never> = {
14
- readonly make: () => Generator<Yieldable<any, any, E, R>, S, any>
15
+ readonly make: () => Generator<Yieldable<any, any, E, R>, S>
15
16
  }
16
17
  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