effect-app 4.0.0-beta.26 → 4.0.0-beta.261

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 (368) hide show
  1. package/CHANGELOG.md +1194 -0
  2. package/dist/Array.d.ts +3 -2
  3. package/dist/Array.d.ts.map +1 -1
  4. package/dist/Array.js +4 -4
  5. package/dist/Chunk.d.ts +1 -1
  6. package/dist/Chunk.d.ts.map +1 -1
  7. package/dist/Config/SecretURL.d.ts +4 -2
  8. package/dist/Config/SecretURL.d.ts.map +1 -1
  9. package/dist/Config/SecretURL.js +3 -6
  10. package/dist/Config/internal/configSecretURL.d.ts +1 -1
  11. package/dist/Config/internal/configSecretURL.d.ts.map +1 -1
  12. package/dist/Config/internal/configSecretURL.js +2 -2
  13. package/dist/Config.d.ts +7 -0
  14. package/dist/Config.d.ts.map +1 -0
  15. package/dist/Config.js +6 -0
  16. package/dist/ConfigProvider.d.ts +39 -0
  17. package/dist/ConfigProvider.d.ts.map +1 -0
  18. package/dist/ConfigProvider.js +42 -0
  19. package/dist/Context.d.ts +42 -0
  20. package/dist/Context.d.ts.map +1 -0
  21. package/dist/Context.js +67 -0
  22. package/dist/DataDependencies.d.ts +158 -0
  23. package/dist/DataDependencies.d.ts.map +1 -0
  24. package/dist/DataDependencies.js +39 -0
  25. package/dist/Effect.d.ts +13 -12
  26. package/dist/Effect.d.ts.map +1 -1
  27. package/dist/Effect.js +5 -8
  28. package/dist/Emailer.d.ts +51 -0
  29. package/dist/Emailer.d.ts.map +1 -0
  30. package/dist/Emailer.js +7 -0
  31. package/dist/Function.d.ts +1 -1
  32. package/dist/Function.d.ts.map +1 -1
  33. package/dist/Inputify.type.d.ts +1 -1
  34. package/dist/Layer.d.ts +11 -7
  35. package/dist/Layer.d.ts.map +1 -1
  36. package/dist/Layer.js +3 -2
  37. package/dist/Model/Repository/Registry.d.ts +21 -0
  38. package/dist/Model/Repository/Registry.d.ts.map +1 -0
  39. package/dist/Model/Repository/Registry.js +18 -0
  40. package/dist/Model/Repository/ext.d.ts +60 -0
  41. package/dist/Model/Repository/ext.d.ts.map +1 -0
  42. package/dist/Model/Repository/ext.js +122 -0
  43. package/dist/Model/Repository/internal/internal.d.ts +63 -0
  44. package/dist/Model/Repository/internal/internal.d.ts.map +1 -0
  45. package/dist/Model/Repository/internal/internal.js +430 -0
  46. package/dist/Model/Repository/legacy.d.ts +21 -0
  47. package/dist/Model/Repository/legacy.d.ts.map +1 -0
  48. package/dist/Model/Repository/legacy.js +2 -0
  49. package/dist/Model/Repository/makeRepo.d.ts +54 -0
  50. package/dist/Model/Repository/makeRepo.d.ts.map +1 -0
  51. package/dist/Model/Repository/makeRepo.js +27 -0
  52. package/dist/Model/Repository/service.d.ts +121 -0
  53. package/dist/Model/Repository/service.d.ts.map +1 -0
  54. package/dist/Model/Repository/service.js +2 -0
  55. package/dist/Model/Repository/validation.d.ts +58 -0
  56. package/dist/Model/Repository/validation.d.ts.map +1 -0
  57. package/dist/Model/Repository/validation.js +32 -0
  58. package/dist/Model/Repository.d.ts +7 -0
  59. package/dist/Model/Repository.d.ts.map +1 -0
  60. package/dist/Model/Repository.js +7 -0
  61. package/dist/Model/dsl.d.ts +33 -0
  62. package/dist/Model/dsl.d.ts.map +1 -0
  63. package/dist/Model/dsl.js +43 -0
  64. package/dist/Model/filter/filterApi.d.ts +30 -0
  65. package/dist/Model/filter/filterApi.d.ts.map +1 -0
  66. package/dist/Model/filter/filterApi.js +2 -0
  67. package/dist/Model/filter/types/errors.d.ts +29 -0
  68. package/dist/Model/filter/types/errors.d.ts.map +1 -0
  69. package/dist/Model/filter/types/errors.js +2 -0
  70. package/dist/Model/filter/types/fields.d.ts +15 -0
  71. package/dist/Model/filter/types/fields.d.ts.map +1 -0
  72. package/dist/Model/filter/types/fields.js +2 -0
  73. package/dist/Model/filter/types/path/common.d.ts +316 -0
  74. package/dist/Model/filter/types/path/common.d.ts.map +1 -0
  75. package/dist/Model/filter/types/path/common.js +2 -0
  76. package/dist/Model/filter/types/path/eager.d.ts +95 -0
  77. package/dist/Model/filter/types/path/eager.d.ts.map +1 -0
  78. package/dist/Model/filter/types/path/eager.js +31 -0
  79. package/dist/Model/filter/types/path/index.d.ts +4 -0
  80. package/dist/Model/filter/types/path/index.d.ts.map +1 -0
  81. package/dist/Model/filter/types/path/index.js +3 -0
  82. package/dist/Model/filter/types/utils.d.ts +79 -0
  83. package/dist/Model/filter/types/utils.d.ts.map +1 -0
  84. package/dist/Model/filter/types/utils.js +2 -0
  85. package/dist/Model/filter/types/validator.d.ts +30 -0
  86. package/dist/Model/filter/types/validator.d.ts.map +1 -0
  87. package/dist/Model/filter/types/validator.js +2 -0
  88. package/dist/Model/filter/types.d.ts +5 -0
  89. package/dist/Model/filter/types.d.ts.map +1 -0
  90. package/dist/Model/filter/types.js +7 -0
  91. package/dist/Model/query/dsl.d.ts +493 -0
  92. package/dist/Model/query/dsl.d.ts.map +1 -0
  93. package/dist/Model/query/dsl.js +376 -0
  94. package/dist/Model/query/new-kid-interpreter.d.ts +136 -0
  95. package/dist/Model/query/new-kid-interpreter.d.ts.map +1 -0
  96. package/dist/Model/query/new-kid-interpreter.js +336 -0
  97. package/dist/Model/query.d.ts +15 -0
  98. package/dist/Model/query.d.ts.map +1 -0
  99. package/dist/Model/query.js +3 -0
  100. package/dist/Model.d.ts +5 -0
  101. package/dist/Model.d.ts.map +1 -0
  102. package/dist/Model.js +5 -0
  103. package/dist/NonEmptySet.d.ts +4 -2
  104. package/dist/NonEmptySet.d.ts.map +1 -1
  105. package/dist/NonEmptySet.js +2 -2
  106. package/dist/Option.d.ts +2 -1
  107. package/dist/Option.d.ts.map +1 -1
  108. package/dist/Option.js +3 -1
  109. package/dist/Pure.d.ts +8 -6
  110. package/dist/Pure.d.ts.map +1 -1
  111. package/dist/Pure.js +17 -14
  112. package/dist/QueueMaker.d.ts +13 -0
  113. package/dist/QueueMaker.d.ts.map +1 -0
  114. package/dist/QueueMaker.js +4 -0
  115. package/dist/RequestContext.d.ts +91 -0
  116. package/dist/RequestContext.d.ts.map +1 -0
  117. package/dist/RequestContext.js +49 -0
  118. package/dist/Schema/Class.d.ts +66 -20
  119. package/dist/Schema/Class.d.ts.map +1 -1
  120. package/dist/Schema/Class.js +192 -27
  121. package/dist/Schema/FastCheck.d.ts +1 -1
  122. package/dist/Schema/FastCheck.d.ts.map +1 -1
  123. package/dist/Schema/Methods.d.ts +1 -1
  124. package/dist/Schema/SchemaParser.d.ts +5 -0
  125. package/dist/Schema/SchemaParser.d.ts.map +1 -0
  126. package/dist/Schema/SchemaParser.js +6 -0
  127. package/dist/Schema/SpecialJsonSchema.d.ts +34 -0
  128. package/dist/Schema/SpecialJsonSchema.d.ts.map +1 -0
  129. package/dist/Schema/SpecialJsonSchema.js +118 -0
  130. package/dist/Schema/SpecialOpenApi.d.ts +32 -0
  131. package/dist/Schema/SpecialOpenApi.d.ts.map +1 -0
  132. package/dist/Schema/SpecialOpenApi.js +123 -0
  133. package/dist/Schema/brand.d.ts +5 -3
  134. package/dist/Schema/brand.d.ts.map +1 -1
  135. package/dist/Schema/brand.js +3 -1
  136. package/dist/Schema/email.d.ts +1 -1
  137. package/dist/Schema/email.d.ts.map +1 -1
  138. package/dist/Schema/email.js +7 -4
  139. package/dist/Schema/ext.d.ts +339 -56
  140. package/dist/Schema/ext.d.ts.map +1 -1
  141. package/dist/Schema/ext.js +358 -53
  142. package/dist/Schema/moreStrings.d.ts +83 -37
  143. package/dist/Schema/moreStrings.d.ts.map +1 -1
  144. package/dist/Schema/moreStrings.js +49 -42
  145. package/dist/Schema/numbers.d.ts +35 -22
  146. package/dist/Schema/numbers.d.ts.map +1 -1
  147. package/dist/Schema/numbers.js +55 -12
  148. package/dist/Schema/phoneNumber.d.ts +1 -1
  149. package/dist/Schema/phoneNumber.d.ts.map +1 -1
  150. package/dist/Schema/phoneNumber.js +6 -3
  151. package/dist/Schema/schema.d.ts +1 -1
  152. package/dist/Schema/strings.d.ts +19 -5
  153. package/dist/Schema/strings.d.ts.map +1 -1
  154. package/dist/Schema/strings.js +1 -5
  155. package/dist/Schema.d.ts +214 -8
  156. package/dist/Schema.d.ts.map +1 -1
  157. package/dist/Schema.js +190 -11
  158. package/dist/Set.d.ts +5 -2
  159. package/dist/Set.d.ts.map +1 -1
  160. package/dist/Set.js +3 -2
  161. package/dist/Store.d.ts +170 -0
  162. package/dist/Store.d.ts.map +1 -0
  163. package/dist/Store.js +121 -0
  164. package/dist/TypeTest.d.ts +1 -1
  165. package/dist/Types.d.ts +1 -1
  166. package/dist/Widen.type.d.ts +1 -1
  167. package/dist/_ext/Array.d.ts +2 -2
  168. package/dist/_ext/Array.d.ts.map +1 -1
  169. package/dist/_ext/Array.js +4 -2
  170. package/dist/_ext/date.d.ts +1 -1
  171. package/dist/_ext/misc.d.ts +5 -2
  172. package/dist/_ext/misc.d.ts.map +1 -1
  173. package/dist/_ext/misc.js +4 -2
  174. package/dist/_ext/ord.ext.d.ts +3 -2
  175. package/dist/_ext/ord.ext.d.ts.map +1 -1
  176. package/dist/_ext/ord.ext.js +2 -2
  177. package/dist/builtin.d.ts +1 -1
  178. package/dist/builtin.d.ts.map +1 -1
  179. package/dist/client/InvalidationKeys.d.ts +29 -0
  180. package/dist/client/InvalidationKeys.d.ts.map +1 -0
  181. package/dist/client/InvalidationKeys.js +33 -0
  182. package/dist/client/apiClientFactory.d.ts +20 -32
  183. package/dist/client/apiClientFactory.d.ts.map +1 -1
  184. package/dist/client/apiClientFactory.js +104 -34
  185. package/dist/client/clientFor.d.ts +53 -19
  186. package/dist/client/clientFor.d.ts.map +1 -1
  187. package/dist/client/clientFor.js +9 -1
  188. package/dist/client/errors.d.ts +49 -25
  189. package/dist/client/errors.d.ts.map +1 -1
  190. package/dist/client/errors.js +43 -17
  191. package/dist/client/makeClient.d.ts +495 -33
  192. package/dist/client/makeClient.d.ts.map +1 -1
  193. package/dist/client/makeClient.js +66 -24
  194. package/dist/client.d.ts +6 -5
  195. package/dist/client.d.ts.map +1 -1
  196. package/dist/client.js +2 -1
  197. package/dist/faker.d.ts +1 -1
  198. package/dist/faker.d.ts.map +1 -1
  199. package/dist/http/Request.d.ts +2 -2
  200. package/dist/http/Request.d.ts.map +1 -1
  201. package/dist/http/Request.js +2 -2
  202. package/dist/http/internal/lib.d.ts +1 -1
  203. package/dist/http.d.ts +1 -1
  204. package/dist/ids.d.ts +43 -15
  205. package/dist/ids.d.ts.map +1 -1
  206. package/dist/ids.js +30 -5
  207. package/dist/index.d.ts +7 -8
  208. package/dist/index.d.ts.map +1 -1
  209. package/dist/index.js +8 -8
  210. package/dist/logger.d.ts +1 -1
  211. package/dist/middleware.d.ts +14 -8
  212. package/dist/middleware.d.ts.map +1 -1
  213. package/dist/middleware.js +14 -8
  214. package/dist/rpc/Invalidation.d.ts +420 -0
  215. package/dist/rpc/Invalidation.d.ts.map +1 -0
  216. package/dist/rpc/Invalidation.js +168 -0
  217. package/dist/rpc/MiddlewareMaker.d.ts +12 -8
  218. package/dist/rpc/MiddlewareMaker.d.ts.map +1 -1
  219. package/dist/rpc/MiddlewareMaker.js +59 -38
  220. package/dist/rpc/RpcContextMap.d.ts +4 -4
  221. package/dist/rpc/RpcContextMap.d.ts.map +1 -1
  222. package/dist/rpc/RpcContextMap.js +4 -4
  223. package/dist/rpc/RpcMiddleware.d.ts +15 -11
  224. package/dist/rpc/RpcMiddleware.d.ts.map +1 -1
  225. package/dist/rpc/RpcMiddleware.js +1 -1
  226. package/dist/rpc.d.ts +2 -2
  227. package/dist/rpc.d.ts.map +1 -1
  228. package/dist/rpc.js +2 -2
  229. package/dist/runtime.d.ts +19 -0
  230. package/dist/runtime.d.ts.map +1 -0
  231. package/dist/runtime.js +40 -0
  232. package/dist/setupRequest.d.ts +19 -0
  233. package/dist/setupRequest.d.ts.map +1 -0
  234. package/dist/setupRequest.js +69 -0
  235. package/dist/toast.d.ts +51 -0
  236. package/dist/toast.d.ts.map +1 -0
  237. package/dist/toast.js +34 -0
  238. package/dist/transform.d.ts +2 -2
  239. package/dist/transform.d.ts.map +1 -1
  240. package/dist/transform.js +4 -5
  241. package/dist/utils/effectify.d.ts +2 -2
  242. package/dist/utils/effectify.d.ts.map +1 -1
  243. package/dist/utils/effectify.js +2 -2
  244. package/dist/utils/extend.d.ts +1 -1
  245. package/dist/utils/extend.d.ts.map +1 -1
  246. package/dist/utils/gen.d.ts +5 -5
  247. package/dist/utils/gen.d.ts.map +1 -1
  248. package/dist/utils/logLevel.d.ts +3 -3
  249. package/dist/utils/logLevel.d.ts.map +1 -1
  250. package/dist/utils/logger.d.ts +5 -4
  251. package/dist/utils/logger.d.ts.map +1 -1
  252. package/dist/utils/logger.js +4 -4
  253. package/dist/utils.d.ts +40 -45
  254. package/dist/utils.d.ts.map +1 -1
  255. package/dist/utils.js +19 -27
  256. package/dist/validation/validators.d.ts +1 -1
  257. package/dist/validation/validators.d.ts.map +1 -1
  258. package/dist/validation.d.ts +1 -1
  259. package/dist/validation.d.ts.map +1 -1
  260. package/dist/withToast.d.ts +30 -0
  261. package/dist/withToast.d.ts.map +1 -0
  262. package/dist/withToast.js +64 -0
  263. package/package.json +20 -245
  264. package/src/Array.ts +3 -3
  265. package/src/Config/SecretURL.ts +5 -2
  266. package/src/Config/internal/configSecretURL.ts +1 -1
  267. package/src/Config.ts +14 -0
  268. package/src/ConfigProvider.ts +48 -0
  269. package/src/{ServiceMap.ts → Context.ts} +56 -63
  270. package/src/Effect.ts +12 -14
  271. package/src/Emailer.ts +51 -0
  272. package/src/Layer.ts +10 -6
  273. package/src/Model/Repository/Registry.ts +34 -0
  274. package/src/Model/Repository/ext.ts +375 -0
  275. package/src/Model/Repository/internal/internal.ts +741 -0
  276. package/src/Model/Repository/legacy.ts +29 -0
  277. package/src/Model/Repository/makeRepo.ts +145 -0
  278. package/src/Model/Repository/service.ts +666 -0
  279. package/src/Model/Repository/validation.ts +31 -0
  280. package/src/Model/Repository.ts +6 -0
  281. package/src/Model/dsl.ts +129 -0
  282. package/src/Model/filter/filterApi.ts +60 -0
  283. package/src/Model/filter/types/errors.ts +47 -0
  284. package/src/Model/filter/types/fields.ts +50 -0
  285. package/src/Model/filter/types/path/common.ts +404 -0
  286. package/src/Model/filter/types/path/eager.ts +297 -0
  287. package/src/Model/filter/types/path/index.ts +4 -0
  288. package/src/Model/filter/types/utils.ts +128 -0
  289. package/src/Model/filter/types/validator.ts +46 -0
  290. package/src/Model/filter/types.ts +6 -0
  291. package/src/Model/query/dsl.ts +2694 -0
  292. package/src/Model/query/new-kid-interpreter.ts +484 -0
  293. package/src/Model/query.ts +13 -0
  294. package/src/Model.ts +4 -0
  295. package/src/NonEmptySet.ts +3 -1
  296. package/src/Option.ts +2 -0
  297. package/src/Pure.ts +21 -19
  298. package/src/QueueMaker.ts +19 -0
  299. package/src/RequestContext.ts +62 -0
  300. package/src/Schema/Class.ts +274 -68
  301. package/src/Schema/SchemaParser.ts +12 -0
  302. package/src/Schema/SpecialJsonSchema.ts +139 -0
  303. package/src/Schema/SpecialOpenApi.ts +130 -0
  304. package/src/Schema/brand.ts +22 -2
  305. package/src/Schema/email.ts +7 -2
  306. package/src/Schema/ext.ts +443 -88
  307. package/src/Schema/moreStrings.ts +146 -67
  308. package/src/Schema/numbers.ts +96 -27
  309. package/src/Schema/phoneNumber.ts +5 -1
  310. package/src/Schema/strings.ts +22 -13
  311. package/src/Schema.ts +374 -10
  312. package/src/Set.ts +5 -1
  313. package/src/Store.ts +277 -0
  314. package/src/_ext/Array.ts +3 -1
  315. package/src/_ext/misc.ts +4 -1
  316. package/src/_ext/ord.ext.ts +2 -1
  317. package/src/client/InvalidationKeys.ts +50 -0
  318. package/src/client/apiClientFactory.ts +230 -131
  319. package/src/client/clientFor.ts +102 -31
  320. package/src/client/errors.ts +52 -26
  321. package/src/client/makeClient.ts +592 -71
  322. package/src/client.ts +5 -4
  323. package/src/http/Request.ts +1 -1
  324. package/src/ids.ts +32 -5
  325. package/src/index.ts +7 -10
  326. package/src/middleware.ts +13 -9
  327. package/src/rpc/Invalidation.ts +261 -0
  328. package/src/rpc/MiddlewareMaker.ts +83 -75
  329. package/src/rpc/README.md +2 -2
  330. package/src/rpc/RpcContextMap.ts +6 -5
  331. package/src/rpc/RpcMiddleware.ts +18 -12
  332. package/src/rpc.ts +1 -1
  333. package/src/runtime.ts +56 -0
  334. package/src/setupRequest.ts +134 -0
  335. package/src/toast.ts +54 -0
  336. package/src/transform.ts +3 -3
  337. package/src/utils/effectify.ts +1 -1
  338. package/src/utils/gen.ts +8 -8
  339. package/src/utils/logLevel.ts +1 -1
  340. package/src/utils/logger.ts +4 -3
  341. package/src/utils.ts +62 -139
  342. package/src/withToast.ts +133 -0
  343. package/test/dist/rpc-dynamic-middleware.test.d.ts.map +1 -0
  344. package/test/dist/rpc.test.d.ts.map +1 -1
  345. package/test/dist/secretURL.test.d.ts.map +1 -0
  346. package/test/dist/special.test.d.ts.map +1 -0
  347. package/test/dist/stream-error.types.d.ts +2 -0
  348. package/test/dist/stream-error.types.d.ts.map +1 -0
  349. package/test/dist/stream-error.types.js +27 -0
  350. package/test/moreStrings.test.ts +1 -1
  351. package/test/rpc.test.ts +46 -6
  352. package/test/schema.test.ts +459 -30
  353. package/test/secretURL.test.ts +160 -0
  354. package/test/special.test.ts +1026 -0
  355. package/test/utils.test.ts +7 -7
  356. package/tsconfig.base.json +6 -5
  357. package/tsconfig.json +2 -1
  358. package/tsconfig.json.bak +2 -2
  359. package/tsconfig.src.json +29 -29
  360. package/tsconfig.test.json +2 -2
  361. package/dist/Operations.d.ts +0 -123
  362. package/dist/Operations.d.ts.map +0 -1
  363. package/dist/Operations.js +0 -29
  364. package/dist/ServiceMap.d.ts +0 -44
  365. package/dist/ServiceMap.d.ts.map +0 -1
  366. package/dist/ServiceMap.js +0 -91
  367. package/eslint.config.mjs +0 -26
  368. package/src/Operations.ts +0 -55
package/src/client.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  // codegen:start {preset: barrel, include: ./client/*.ts}
2
- export * from "./client/apiClientFactory.js"
3
- export * from "./client/clientFor.js"
4
- export * from "./client/errors.js"
5
- export * from "./client/makeClient.js"
2
+ export * from "./client/apiClientFactory.ts"
3
+ export * from "./client/clientFor.ts"
4
+ export * from "./client/errors.ts"
5
+ export * from "./client/InvalidationKeys.ts"
6
+ export * from "./client/makeClient.ts"
6
7
  // codegen:end
@@ -1,4 +1,4 @@
1
- import { Option } from "effect"
1
+ import * as Option from "effect/Option"
2
2
  import type { HttpClientResponse } from "effect/unstable/http/HttpClientResponse"
3
3
  import * as Effect from "../Effect.js"
4
4
  import { HttpClient, HttpClientError, HttpClientRequest, HttpHeaders } from "./internal/lib.js"
package/src/ids.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { brandedStringId, type Codec, NonEmptyString255, StringId, type StringIdBrand, withDefaultMake } from "effect-app/Schema"
2
2
  import type { B } from "effect-app/Schema/schema"
3
+ import * as Effect from "effect/Effect"
3
4
  import type { Simplify } from "effect/Types"
4
- import { S } from "./index.js"
5
+ import * as S from "./Schema.js"
5
6
  import { extendM } from "./utils.js"
6
7
 
7
8
  export interface RequestIdBrand extends StringIdBrand {
@@ -9,20 +10,46 @@ export interface RequestIdBrand extends StringIdBrand {
9
10
  }
10
11
 
11
12
  export type RequestId = NonEmptyString255
12
- // a request id may be made from a span id, which does not comply with StringId schema.
13
+ /**
14
+ * Schema for a request id.
15
+ *
16
+ * A request id may be made from a span id, which does not comply with the
17
+ * `StringId` schema (hence the looser `NonEmptyString255` base).
18
+ *
19
+ * `.withConstructorDefault` => fresh `StringId` (construction-only; not
20
+ * applied during decode — cannot be used to JIT-migrate database fields).
21
+ * See `./Schema/ext.ts` for the full policy note.
22
+ */
13
23
  export const RequestId = extendM(
14
24
  Object
15
25
  .assign(Object.create(NonEmptyString255) as {}, NonEmptyString255 as unknown as Codec<NonEmptyString255, string>),
16
26
  (s) => {
17
- const make = StringId.make as () => NonEmptyString255
27
+ function make(): NonEmptyString255
28
+ function make(input: string, options?: S.MakeOptions): NonEmptyString255
29
+ function make(input?: string, options?: S.MakeOptions): NonEmptyString255 {
30
+ const id = input === undefined ? StringId.make() : StringId.make(input, options)
31
+ return id as NonEmptyString255
32
+ }
18
33
  return ({
19
34
  make,
20
- withDefault: s.pipe(S.withDefaultConstructor(make))
35
+ /**
36
+ * Construction-only default: fresh `StringId`. Applied only when the
37
+ * field is omitted from `.make(...)` input. NOT applied during decode —
38
+ * cannot be used to JIT-migrate database fields. See `./Schema/ext.ts`
39
+ * file-level note.
40
+ */
41
+ withConstructorDefault: S.withConstructorDefault(Effect.sync(make))(s as typeof s & S.WithoutConstructorDefault)
21
42
  })
22
43
  }
23
44
  )
24
45
  .pipe(withDefaultMake)
25
46
 
26
47
  export interface UserProfileIdBrand extends Simplify<B.Brand<"UserProfileId"> & StringIdBrand> {}
27
- export type UserProfileId = StringId & UserProfileIdBrand
48
+ export type UserProfileId = string & UserProfileIdBrand
49
+ /**
50
+ * Branded `StringId` for user profiles.
51
+ *
52
+ * Exposes `.withConstructorDefault` (fresh id) — construction-only; not
53
+ * applied during decode. See `./Schema/ext.ts` for the full policy note.
54
+ */
28
55
  export const UserProfileId = brandedStringId<UserProfileId>()
package/src/index.ts CHANGED
@@ -1,23 +1,19 @@
1
+ // eslint-disable-next-line import/no-unassigned-import
1
2
  import "./builtin.js"
2
3
 
3
- import * as ServiceMap from "./ServiceMap.js"
4
-
5
4
  export * as Fnc from "./Function.js"
6
5
  export * as Utils from "./utils.js"
7
6
 
8
7
  export * as Array from "./Array.js"
8
+ export * as Config from "./Config.js"
9
+ export * as ConfigProvider from "./ConfigProvider.js"
10
+ export * as Context from "./Context.js"
9
11
  export * as Effect from "./Effect.js"
10
12
  export * as Layer from "./Layer.js"
13
+ export * as Model from "./Model.js"
11
14
  export * as NonEmptySet from "./NonEmptySet.js"
12
- export * as ServiceMap from "./ServiceMap.js"
13
15
  export * as Set from "./Set.js"
14
-
15
- export {
16
- /**
17
- * @deprecated use ServiceMap directly instead
18
- */
19
- ServiceMap as Context
20
- }
16
+ export * as Store from "./Store.js"
21
17
 
22
18
  export { type NonEmptyArray, type NonEmptyReadonlyArray } from "./Array.js"
23
19
 
@@ -26,5 +22,6 @@ export * from "effect"
26
22
  export type * as Types from "./Types.js"
27
23
 
28
24
  export * as SecretURL from "./Config/SecretURL.js"
25
+ export * as RpcX from "./rpc.js"
29
26
  export * as S from "./Schema.js"
30
27
  export { copy } from "./utils.js"
package/src/middleware.ts CHANGED
@@ -1,21 +1,25 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { ServiceMap } from "effect-app"
3
- import { RpcX } from "./rpc.js"
2
+ import * as Context from "effect-app/Context"
3
+ import { RpcMiddleware } from "./rpc.js"
4
4
 
5
- export class DevMode extends ServiceMap.Reference("DevMode", { defaultValue: () => false }) {}
5
+ export class DevMode extends Context.Reference("DevMode", { defaultValue: () => false }) {}
6
6
 
7
- export class RequestCacheMiddleware
8
- extends RpcX.RpcMiddleware.Tag<RequestCacheMiddleware>()("RequestCacheMiddleware")
9
- {}
7
+ export class RequestCacheMiddleware extends RpcMiddleware.Tag<RequestCacheMiddleware>()("RequestCacheMiddleware") {}
10
8
 
11
9
  export class ConfigureInterruptibilityMiddleware
12
- extends RpcX.RpcMiddleware.Tag<ConfigureInterruptibilityMiddleware>()("ConfigureInterruptibilityMiddleware")
10
+ extends RpcMiddleware.Tag<ConfigureInterruptibilityMiddleware>()("ConfigureInterruptibilityMiddleware")
13
11
  {}
14
12
 
15
- export class LoggerMiddleware extends RpcX.RpcMiddleware.Tag<LoggerMiddleware>()("LoggerMiddleware") {}
13
+ export class LoggerMiddleware extends RpcMiddleware.Tag<LoggerMiddleware>()("LoggerMiddleware") {}
16
14
 
17
- export class DevModeMiddleware extends RpcX.RpcMiddleware.Tag<DevModeMiddleware>()("DevModeMiddleware") {}
15
+ export class DevModeMiddleware extends RpcMiddleware.Tag<DevModeMiddleware>()("DevModeMiddleware") {}
18
16
 
17
+ /**
18
+ * Generic middlewares attached by `makeRouter` to every request.
19
+ *
20
+ * Invalidation key wrap/unwrap is handled by the routing layer (server) and the
21
+ * api client factory (client) directly — there is no middleware tag for it.
22
+ */
19
23
  export const DefaultGenericMiddlewares = [
20
24
  RequestCacheMiddleware,
21
25
  ConfigureInterruptibilityMiddleware,
@@ -0,0 +1,261 @@
1
+ import * as Ref from "effect/Ref"
2
+ import { Rpc } from "effect/unstable/rpc"
3
+ import { type ClientForOptions, makeQueryKey } from "../client/clientFor.js"
4
+ import * as Context from "../Context.js"
5
+ import * as Effect from "../Effect.js"
6
+ import * as S from "../Schema.js"
7
+
8
+ /**
9
+ * Shorthand for a handler-derived invalidation key.
10
+ * Accepts an RPC handler object so `add(GetMe)` is equivalent to
11
+ * `add(makeQueryKey(GetMe))`.
12
+ */
13
+ export type InvalidationKeyInput = InvalidationKey | { readonly id: string; readonly options?: ClientForOptions }
14
+
15
+ const normalizeKey = (input: InvalidationKeyInput): InvalidationKey => {
16
+ if (Array.isArray(input)) return input
17
+ const handler = input as { id: string; options?: ClientForOptions }
18
+ return makeQueryKey(handler.options ? { id: handler.id, options: handler.options } : { id: handler.id })
19
+ }
20
+
21
+ // Disambiguates `add` overloads: a `string[]` means a single key; an array
22
+ // containing arrays-or-objects means a batch of inputs.
23
+ const isBatch = (
24
+ input: InvalidationKeyInput | ReadonlyArray<InvalidationKeyInput>
25
+ ): input is ReadonlyArray<InvalidationKeyInput> =>
26
+ Array.isArray(input) && input.length > 0 && typeof input[0] !== "string"
27
+
28
+ const normalizeInputs = (
29
+ input: InvalidationKeyInput | ReadonlyArray<InvalidationKeyInput>
30
+ ): ReadonlyArray<InvalidationKey> => isBatch(input) ? input.map(normalizeKey) : [normalizeKey(input)]
31
+
32
+ /**
33
+ * A single segment within an `InvalidationKey` array.
34
+ * Accepts any JSON-compatible value: string, number, boolean, null,
35
+ * arrays and objects recursively — matching TanStack Query's `queryKey` element type.
36
+ */
37
+ export const InvalidationKeySegment = S.Json
38
+ export type InvalidationKeySegment = S.Schema.Type<typeof InvalidationKeySegment>
39
+
40
+ /** Schema for a single invalidation key – an array of segments compatible with TanStack Query `queryKey`. */
41
+ export const InvalidationKey = S.Array(InvalidationKeySegment)
42
+ export type InvalidationKey = S.Schema.Type<typeof InvalidationKey>
43
+
44
+ /** Schema for the full set of invalidation keys – an array of `InvalidationKey`. */
45
+ export const InvalidationKeys = S.Array(InvalidationKey)
46
+ export type InvalidationKeys = S.Schema.Type<typeof InvalidationKeys>
47
+
48
+ /** Metadata included in every command response for server-driven cache invalidation. */
49
+ export const CommandMetaData = S.Struct({ invalidateQueries: InvalidationKeys })
50
+ export type CommandMetaData = S.Schema.Type<typeof CommandMetaData>
51
+
52
+ /**
53
+ * Wraps a command's success schema so that the wire format carries both the `payload`
54
+ * (the handler's actual return value) and `metadata` (server-driven cache invalidation keys).
55
+ * Transparent to users: the server handler returns the plain payload and the client receives
56
+ * the plain payload — wrapping/unwrapping is handled internally by the routing layer.
57
+ */
58
+ export const CommandResponseWithMetaData = <S extends S.Top>(success: S) =>
59
+ S.Struct({ payload: success, metadata: CommandMetaData })
60
+
61
+ /**
62
+ * Wraps a command's failure schema so that the wire format carries both the `error`
63
+ * (the handler's actual failure value) and `metadata` (server-driven cache invalidation keys
64
+ * accumulated thus far before the failure occurred).
65
+ * Transparent to users: the server handler fails with the plain error and the client receives
66
+ * the plain error — wrapping/unwrapping is handled internally by the routing layer.
67
+ */
68
+ export const CommandFailureWithMetaData = <E extends S.Top>(error: E) =>
69
+ S.Struct({ _tag: S.Literal("CommandFailureWithMetaData"), error, metadata: CommandMetaData })
70
+
71
+ /**
72
+ * Stream chunk schema for stream responses with metadata.
73
+ * Each item is either a data value, an intermediate "metadata" signal carrying cache
74
+ * invalidation keys accumulated since the previous drain, or a final "done" signal.
75
+ * Transparent to users: stream handlers return plain values and clients receive plain values —
76
+ * wrapping/unwrapping is handled internally by the routing layer.
77
+ *
78
+ * The "done" chunk is always the last item in the stream and carries any remaining invalidation
79
+ * keys. An optional "metadata" chunk may appear after any "value" chunk and carries keys
80
+ * accumulated since the last drain (V3: mid-stream invalidation).
81
+ */
82
+ export const StreamResponseChunk = <S extends S.Top>(success: S) =>
83
+ S.Union([
84
+ S.Struct({ _tag: S.Literal("value"), value: success }),
85
+ S.Struct({ _tag: S.Literal("metadata"), metadata: CommandMetaData }),
86
+ S.Struct({ _tag: S.Literal("done"), metadata: CommandMetaData })
87
+ ])
88
+
89
+ export type StreamResponseChunk<A> =
90
+ | { readonly _tag: "value"; readonly value: A }
91
+ | { readonly _tag: "metadata"; readonly metadata: CommandMetaData }
92
+ | { readonly _tag: "done"; readonly metadata: CommandMetaData }
93
+
94
+ /**
95
+ * Stream chunk schema for stream failures with metadata.
96
+ * Used to signal a stream failure while still carrying cache invalidation keys
97
+ * accumulated thus far.
98
+ */
99
+ export const StreamFailureChunk = <E extends S.Top>(error: E) =>
100
+ S.Struct({ _tag: S.Literal("error"), error, metadata: CommandMetaData })
101
+
102
+ export type StreamFailureChunk<E> = { readonly _tag: "error"; readonly error: E; readonly metadata: CommandMetaData }
103
+
104
+ /**
105
+ * Context annotation for declaring static cache invalidation keys on a low-level `Rpc` definition.
106
+ * These keys are always included in the command response metadata, regardless of the handler logic.
107
+ *
108
+ * Prefer using `makeQueryKey` over raw string arrays to stay in sync with the actual query
109
+ * definitions without manual string maintenance:
110
+ *
111
+ * ```ts
112
+ * import { makeQueryKey } from "effect-app/client"
113
+ * import { Invalidation } from "effect-app/rpc"
114
+ * import * as UserRsc from "../User/index.js" // separate module to avoid circular deps
115
+ *
116
+ * class UpdateProfile extends Rpc.make("UpdateProfile", { ... })
117
+ * .annotate(Invalidation.Invalidates, [makeQueryKey(UserRsc.GetMe), makeQueryKey(UserRsc.GetProfile)]) {}
118
+ * ```
119
+ *
120
+ * **Circular dependency note:** if mutations and queries live in the same file you may hit a
121
+ * circular reference at evaluation time. The idiomatic fix is to move mutations into their own
122
+ * module (e.g. `User/mutations.ts`) that directly imports the relevant query classes rather than
123
+ * re-exporting them through a barrel.
124
+ *
125
+ * For the higher-level `Command`/`Query` builders from `makeRpcClient`, use the
126
+ * `invalidatesQueries` callback argument instead (it receives the same query keys at runtime).
127
+ */
128
+ export const Invalidates = Context.Reference<ReadonlyArray<InvalidationKey>>(
129
+ "effect-app/rpc/Invalidates",
130
+ { defaultValue: () => [] }
131
+ )
132
+ export type Invalidates = typeof Invalidates
133
+
134
+ /** The shape of the per-request service that accumulates invalidation keys. */
135
+ export interface InvalidationSetService {
136
+ readonly add: (
137
+ input: InvalidationKeyInput | ReadonlyArray<InvalidationKeyInput>
138
+ ) => Effect.Effect<void>
139
+ readonly get: Effect.Effect<ReadonlyArray<InvalidationKey>>
140
+ /**
141
+ * V3: Reads all currently accumulated keys and resets the bucket to empty.
142
+ * Used by the stream routing layer to emit intermediate "metadata" chunks
143
+ * without re-sending keys that have already been forwarded to the client.
144
+ */
145
+ readonly drain: Effect.Effect<ReadonlyArray<InvalidationKey>>
146
+ }
147
+
148
+ /**
149
+ * Request-scoped service for accumulating invalidation keys dynamically inside a handler.
150
+ * Provided by `InvalidationMiddlewareLive` for every RPC call; has a no-op default so it is
151
+ * safe to use even when the HTTP middleware is absent (tests, workers, etc.).
152
+ *
153
+ * Use `InvalidationSet.add(key)` as a shorthand to skip `.use(_ => _.add(key))`. The
154
+ * underlying service is still available via `.use` / `.useSync` for advanced cases.
155
+ *
156
+ * `add` accepts an RPC handler directly (e.g. `UserRsc.GetMe`) — its query key is derived via
157
+ * `makeQueryKey` so keys stay in sync with the actual query definitions. Raw `InvalidationKey`
158
+ * arrays and arrays of either form are also accepted.
159
+ *
160
+ * ```ts
161
+ * import * as Effect from "effect/Effect"
162
+ * import { Invalidation } from "effect-app/rpc"
163
+ * import * as CartRsc from "../Cart/queries.js"
164
+ * import * as UserRsc from "../User/queries.js"
165
+ *
166
+ * const handler = Effect.fnUntraced(function*(req: UpdateCartRequest) {
167
+ * const cart = yield* CartRepo.save(req.cart)
168
+ *
169
+ * // single handler
170
+ * yield* Invalidation.InvalidationSet.add(UserRsc.GetMe)
171
+ *
172
+ * // batch
173
+ * if (cart.isCheckedOut) {
174
+ * yield* Invalidation.InvalidationSet.add([CartRsc.GetCartStats, UserRsc.GetMe])
175
+ * }
176
+ *
177
+ * return cart
178
+ * })
179
+ * ```
180
+ *
181
+ * You can combine static (`Invalidates` annotation) and dynamic (`InvalidationSet.use`) keys:
182
+ * the annotation pre-populates the set before the handler runs; dynamic additions accumulate
183
+ * throughout the handler. All keys are included in the command response metadata.
184
+ */
185
+ const InvalidationSetRef = Context.Reference<InvalidationSetService>(
186
+ "effect-app/rpc/InvalidationSet",
187
+ {
188
+ defaultValue: () => ({
189
+ add: (_input: InvalidationKeyInput | ReadonlyArray<InvalidationKeyInput>) => Effect.void,
190
+ get: Effect.succeed([] as ReadonlyArray<InvalidationKey>),
191
+ drain: Effect.succeed([] as ReadonlyArray<InvalidationKey>)
192
+ })
193
+ }
194
+ )
195
+ export const InvalidationSet = Object.assign(InvalidationSetRef, {
196
+ /**
197
+ * Shortcut for `InvalidationSet.use(_ => _.add(input))`. Accepts a single
198
+ * `InvalidationKeyInput` or an array of them.
199
+ */
200
+ add: (input: InvalidationKeyInput | ReadonlyArray<InvalidationKeyInput>) =>
201
+ InvalidationSetRef.use((_) => _.add(input))
202
+ })
203
+ export type InvalidationSet = typeof InvalidationSetRef
204
+
205
+ /** Creates a fresh `InvalidationSet` implementation backed by a `Ref`. */
206
+ export const makeInvalidationSet = (ref: Ref.Ref<ReadonlyArray<InvalidationKey>>): InvalidationSetService => ({
207
+ add: (input) => Ref.update(ref, (keys) => [...keys, ...normalizeInputs(input)]),
208
+ get: Ref.get(ref),
209
+ drain: Ref.getAndSet(ref, [])
210
+ })
211
+
212
+ /**
213
+ * `Rpc.Custom` definition for command RPCs that wrap the success/error schemas
214
+ * with `CommandResponseWithMetaData` / `CommandFailureWithMetaData`. The wrap
215
+ * lets server forward accumulated invalidation keys on both success and
216
+ * handler-thrown failure paths. Middleware-thrown errors bypass the wrap
217
+ * (the handler never ran, so no metadata) and flow raw at the Cause level —
218
+ * the client decodes them via the `rpc.middlewares[*].error` failure-union
219
+ * channel of `Rpc.exitSchema`.
220
+ */
221
+ // eslint-disable-next-line import/namespace
222
+ export interface CommandRpc extends Rpc.Custom {
223
+ readonly out: Rpc.Custom.Out<
224
+ ReturnType<typeof CommandResponseWithMetaData<this["success"] & S.Top>>,
225
+ ReturnType<typeof CommandFailureWithMetaData<this["error"] & S.Top>>
226
+ >
227
+ }
228
+
229
+ /**
230
+ * Custom Rpc constructor for command RPCs.
231
+ * Wraps the success schema with `CommandResponseWithMetaData` and the error
232
+ * schema with `CommandFailureWithMetaData`.
233
+ */
234
+ export const makeCommandRpc = Rpc.custom<CommandRpc>(({ defect, error, success }) => ({
235
+ success: CommandResponseWithMetaData(success),
236
+ error: CommandFailureWithMetaData(error),
237
+ defect
238
+ }))
239
+
240
+ /**
241
+ * `Rpc.Custom` definition for stream RPCs that wrap the success/error schemas
242
+ * with `StreamResponseChunk` / `StreamFailureChunk`.
243
+ */
244
+ // eslint-disable-next-line import/namespace
245
+ export interface StreamRpc extends Rpc.Custom {
246
+ readonly out: Rpc.Custom.Out<
247
+ ReturnType<typeof StreamResponseChunk<this["success"] & S.Top>>,
248
+ ReturnType<typeof StreamFailureChunk<this["error"] & S.Top>>
249
+ >
250
+ }
251
+
252
+ /**
253
+ * Custom Rpc constructor for stream RPCs.
254
+ * Wraps the success schema with `StreamResponseChunk` and
255
+ * the error schema with `StreamFailureChunk`.
256
+ */
257
+ export const makeStreamRpc = Rpc.custom<StreamRpc>(({ defect, error, success }) => ({
258
+ success: StreamResponseChunk(success),
259
+ error: StreamFailureChunk(error),
260
+ defect
261
+ }))