effect-app 4.0.0-beta.99 → 4.0.1

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 (391) hide show
  1. package/CHANGELOG.md +2042 -0
  2. package/dist/Array.d.ts +1 -17
  3. package/dist/Array.d.ts.map +1 -1
  4. package/dist/Array.js +3 -27
  5. package/dist/Chunk.d.ts +3 -27
  6. package/dist/Chunk.d.ts.map +1 -1
  7. package/dist/Chunk.js +4 -39
  8. package/dist/Config/SecretURL.d.ts +3 -1
  9. package/dist/Config/SecretURL.d.ts.map +1 -1
  10. package/dist/Config/SecretURL.js +3 -6
  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 +0 -5
  14. package/dist/Config.d.ts.map +1 -1
  15. package/dist/Config.js +7 -5
  16. package/dist/ConfigProvider.d.ts +0 -37
  17. package/dist/ConfigProvider.d.ts.map +1 -1
  18. package/dist/ConfigProvider.js +5 -41
  19. package/dist/Context.d.ts +6 -4
  20. package/dist/Context.d.ts.map +1 -1
  21. package/dist/Context.js +4 -3
  22. package/dist/DataDependencies.d.ts +136 -0
  23. package/dist/DataDependencies.d.ts.map +1 -0
  24. package/dist/DataDependencies.js +112 -0
  25. package/dist/DateTime.d.ts +33 -0
  26. package/dist/DateTime.d.ts.map +1 -0
  27. package/dist/DateTime.js +18 -0
  28. package/dist/Effect.d.ts +3 -14
  29. package/dist/Effect.d.ts.map +1 -1
  30. package/dist/Effect.js +8 -26
  31. package/dist/Emailer.d.ts +51 -0
  32. package/dist/Emailer.d.ts.map +1 -0
  33. package/dist/Emailer.js +7 -0
  34. package/dist/Function.d.ts +0 -4
  35. package/dist/Function.d.ts.map +1 -1
  36. package/dist/Function.js +1 -7
  37. package/dist/Layer.d.ts +6 -3
  38. package/dist/Layer.d.ts.map +1 -1
  39. package/dist/Layer.js +3 -2
  40. package/dist/Model/Repository/Registry.d.ts +22 -0
  41. package/dist/Model/Repository/Registry.d.ts.map +1 -0
  42. package/dist/Model/Repository/Registry.js +18 -0
  43. package/dist/Model/Repository/dependency.d.ts +6 -0
  44. package/dist/Model/Repository/dependency.d.ts.map +1 -0
  45. package/dist/Model/Repository/dependency.js +29 -0
  46. package/dist/Model/Repository/ext.d.ts +60 -0
  47. package/dist/Model/Repository/ext.d.ts.map +1 -0
  48. package/dist/Model/Repository/ext.js +124 -0
  49. package/dist/Model/Repository/internal/internal.d.ts +68 -0
  50. package/dist/Model/Repository/internal/internal.d.ts.map +1 -0
  51. package/dist/Model/Repository/internal/internal.js +610 -0
  52. package/dist/Model/Repository/legacy.d.ts +21 -0
  53. package/dist/Model/Repository/legacy.d.ts.map +1 -0
  54. package/dist/Model/Repository/legacy.js +2 -0
  55. package/dist/Model/Repository/makeRepo.d.ts +71 -0
  56. package/dist/Model/Repository/makeRepo.d.ts.map +1 -0
  57. package/dist/Model/Repository/makeRepo.js +30 -0
  58. package/dist/Model/Repository/service.d.ts +121 -0
  59. package/dist/Model/Repository/service.d.ts.map +1 -0
  60. package/dist/Model/Repository/service.js +2 -0
  61. package/dist/Model/Repository/validation.d.ts +72 -0
  62. package/dist/Model/Repository/validation.d.ts.map +1 -0
  63. package/dist/Model/Repository/validation.js +39 -0
  64. package/dist/Model/Repository.d.ts +8 -0
  65. package/dist/Model/Repository.d.ts.map +1 -0
  66. package/dist/Model/Repository.js +8 -0
  67. package/dist/Model/dsl.d.ts +34 -0
  68. package/dist/Model/dsl.d.ts.map +1 -0
  69. package/dist/Model/dsl.js +45 -0
  70. package/dist/Model/filter/filterApi.d.ts +30 -0
  71. package/dist/Model/filter/filterApi.d.ts.map +1 -0
  72. package/dist/Model/filter/filterApi.js +2 -0
  73. package/dist/Model/filter/types/errors.d.ts +29 -0
  74. package/dist/Model/filter/types/errors.d.ts.map +1 -0
  75. package/dist/Model/filter/types/errors.js +2 -0
  76. package/dist/Model/filter/types/fields.d.ts +15 -0
  77. package/dist/Model/filter/types/fields.d.ts.map +1 -0
  78. package/dist/Model/filter/types/fields.js +2 -0
  79. package/dist/Model/filter/types/path/common.d.ts +316 -0
  80. package/dist/Model/filter/types/path/common.d.ts.map +1 -0
  81. package/dist/Model/filter/types/path/common.js +2 -0
  82. package/dist/Model/filter/types/path/eager.d.ts +94 -0
  83. package/dist/Model/filter/types/path/eager.d.ts.map +1 -0
  84. package/dist/Model/filter/types/path/eager.js +36 -0
  85. package/dist/Model/filter/types/path/index.d.ts +4 -0
  86. package/dist/Model/filter/types/path/index.d.ts.map +1 -0
  87. package/dist/Model/filter/types/path/index.js +3 -0
  88. package/dist/Model/filter/types/utils.d.ts +79 -0
  89. package/dist/Model/filter/types/utils.d.ts.map +1 -0
  90. package/dist/Model/filter/types/utils.js +2 -0
  91. package/dist/Model/filter/types/validator.d.ts +30 -0
  92. package/dist/Model/filter/types/validator.d.ts.map +1 -0
  93. package/dist/Model/filter/types/validator.js +2 -0
  94. package/dist/Model/filter/types.d.ts +5 -0
  95. package/dist/Model/filter/types.d.ts.map +1 -0
  96. package/dist/Model/filter/types.js +7 -0
  97. package/dist/Model/query/dsl.d.ts +630 -0
  98. package/dist/Model/query/dsl.d.ts.map +1 -0
  99. package/dist/Model/query/dsl.js +376 -0
  100. package/dist/Model/query/new-kid-interpreter.d.ts +132 -0
  101. package/dist/Model/query/new-kid-interpreter.d.ts.map +1 -0
  102. package/dist/Model/query/new-kid-interpreter.js +369 -0
  103. package/dist/Model/query.d.ts +15 -0
  104. package/dist/Model/query.d.ts.map +1 -0
  105. package/dist/Model/query.js +3 -0
  106. package/dist/Model.d.ts +6 -0
  107. package/dist/Model.d.ts.map +1 -0
  108. package/dist/Model.js +6 -0
  109. package/dist/NonEmptySet.d.ts +3 -1
  110. package/dist/NonEmptySet.d.ts.map +1 -1
  111. package/dist/NonEmptySet.js +2 -2
  112. package/dist/Option.d.ts +1 -2
  113. package/dist/Option.d.ts.map +1 -1
  114. package/dist/Option.js +3 -7
  115. package/dist/Pure.d.ts +9 -7
  116. package/dist/Pure.d.ts.map +1 -1
  117. package/dist/Pure.js +20 -17
  118. package/dist/QueueMaker.d.ts +11 -0
  119. package/dist/QueueMaker.d.ts.map +1 -0
  120. package/dist/QueueMaker.js +11 -0
  121. package/dist/RequestContext.d.ts +87 -0
  122. package/dist/RequestContext.d.ts.map +1 -0
  123. package/dist/RequestContext.js +45 -0
  124. package/dist/RequestScopedDependencies.d.ts +21 -0
  125. package/dist/RequestScopedDependencies.d.ts.map +1 -0
  126. package/dist/RequestScopedDependencies.js +16 -0
  127. package/dist/Schema/Class.d.ts +163 -16
  128. package/dist/Schema/Class.d.ts.map +1 -1
  129. package/dist/Schema/Class.js +193 -21
  130. package/dist/Schema/FastCheck.d.ts.map +1 -1
  131. package/dist/Schema/SchemaParser.d.ts +5 -0
  132. package/dist/Schema/SchemaParser.d.ts.map +1 -0
  133. package/dist/Schema/SchemaParser.js +6 -0
  134. package/dist/Schema/SpecialJsonSchema.d.ts +15 -2
  135. package/dist/Schema/SpecialJsonSchema.d.ts.map +1 -1
  136. package/dist/Schema/SpecialJsonSchema.js +70 -12
  137. package/dist/Schema/SpecialOpenApi.d.ts +1 -1
  138. package/dist/Schema/SpecialOpenApi.js +3 -3
  139. package/dist/Schema/brand.d.ts +5 -5
  140. package/dist/Schema/brand.d.ts.map +1 -1
  141. package/dist/Schema/brand.js +6 -4
  142. package/dist/Schema/email.d.ts.map +1 -1
  143. package/dist/Schema/email.js +8 -5
  144. package/dist/Schema/ext.d.ts +279 -75
  145. package/dist/Schema/ext.d.ts.map +1 -1
  146. package/dist/Schema/ext.js +330 -72
  147. package/dist/Schema/moreStrings.d.ts +82 -48
  148. package/dist/Schema/moreStrings.d.ts.map +1 -1
  149. package/dist/Schema/moreStrings.js +85 -51
  150. package/dist/Schema/numbers.d.ts +33 -21
  151. package/dist/Schema/numbers.d.ts.map +1 -1
  152. package/dist/Schema/numbers.js +64 -12
  153. package/dist/Schema/phoneNumber.d.ts.map +1 -1
  154. package/dist/Schema/phoneNumber.js +6 -6
  155. package/dist/Schema/schema.d.ts +1 -1
  156. package/dist/Schema/schema.d.ts.map +1 -1
  157. package/dist/Schema/schema.js +2 -2
  158. package/dist/Schema/strings.d.ts +18 -4
  159. package/dist/Schema/strings.d.ts.map +1 -1
  160. package/dist/Schema/strings.js +1 -5
  161. package/dist/Schema.d.ts +224 -7
  162. package/dist/Schema.d.ts.map +1 -1
  163. package/dist/Schema.js +190 -24
  164. package/dist/SchemaAST.d.ts +2 -0
  165. package/dist/SchemaAST.d.ts.map +1 -0
  166. package/dist/SchemaAST.js +2 -0
  167. package/dist/Set.d.ts +4 -1
  168. package/dist/Set.d.ts.map +1 -1
  169. package/dist/Set.js +8 -6
  170. package/dist/Store.d.ts +215 -0
  171. package/dist/Store.d.ts.map +1 -0
  172. package/dist/Store.js +113 -0
  173. package/dist/_ext/Array.d.ts +1 -1
  174. package/dist/_ext/Array.d.ts.map +1 -1
  175. package/dist/_ext/Array.js +4 -2
  176. package/dist/_ext/ord.ext.d.ts +2 -1
  177. package/dist/_ext/ord.ext.d.ts.map +1 -1
  178. package/dist/_ext/ord.ext.js +2 -2
  179. package/dist/builtin.d.ts +2 -14
  180. package/dist/builtin.d.ts.map +1 -1
  181. package/dist/builtin.js +1 -1
  182. package/dist/client/InvalidationKeys.d.ts +30 -0
  183. package/dist/client/InvalidationKeys.d.ts.map +1 -0
  184. package/dist/client/InvalidationKeys.js +37 -0
  185. package/dist/client/apiClientFactory.d.ts +13 -8
  186. package/dist/client/apiClientFactory.d.ts.map +1 -1
  187. package/dist/client/apiClientFactory.js +154 -34
  188. package/dist/client/clientFor.d.ts +48 -13
  189. package/dist/client/clientFor.d.ts.map +1 -1
  190. package/dist/client/clientFor.js +9 -1
  191. package/dist/client/errors.d.ts +74 -28
  192. package/dist/client/errors.d.ts.map +1 -1
  193. package/dist/client/errors.js +41 -10
  194. package/dist/client/makeClient.d.ts +487 -32
  195. package/dist/client/makeClient.d.ts.map +1 -1
  196. package/dist/client/makeClient.js +47 -21
  197. package/dist/client.d.ts +2 -0
  198. package/dist/client.d.ts.map +1 -1
  199. package/dist/client.js +3 -1
  200. package/dist/faker.d.ts.map +1 -1
  201. package/dist/http/Request.d.ts +2 -2
  202. package/dist/http/Request.d.ts.map +1 -1
  203. package/dist/http/Request.js +2 -2
  204. package/dist/http/internal/lib.d.ts +12 -12
  205. package/dist/http/internal/lib.d.ts.map +1 -1
  206. package/dist/http/internal/lib.js +13 -13
  207. package/dist/ids.d.ts +32 -14
  208. package/dist/ids.d.ts.map +1 -1
  209. package/dist/ids.js +38 -7
  210. package/dist/index.d.ts +3 -0
  211. package/dist/index.d.ts.map +1 -1
  212. package/dist/index.js +5 -1
  213. package/dist/middleware.d.ts +12 -6
  214. package/dist/middleware.d.ts.map +1 -1
  215. package/dist/middleware.js +13 -7
  216. package/dist/migration/nativeEffect.d.ts +21 -0
  217. package/dist/migration/nativeEffect.d.ts.map +1 -0
  218. package/dist/migration/nativeEffect.js +598 -0
  219. package/dist/rpc/Invalidation.d.ts +1124 -0
  220. package/dist/rpc/Invalidation.d.ts.map +1 -0
  221. package/dist/rpc/Invalidation.js +178 -0
  222. package/dist/rpc/MiddlewareMaker.d.ts +10 -7
  223. package/dist/rpc/MiddlewareMaker.d.ts.map +1 -1
  224. package/dist/rpc/MiddlewareMaker.js +57 -37
  225. package/dist/rpc/RpcContextMap.d.ts +2 -2
  226. package/dist/rpc/RpcContextMap.d.ts.map +1 -1
  227. package/dist/rpc/RpcMiddleware.d.ts +13 -10
  228. package/dist/rpc/RpcMiddleware.d.ts.map +1 -1
  229. package/dist/rpc/RpcMiddleware.js +2 -2
  230. package/dist/rpc.d.ts +1 -1
  231. package/dist/rpc.d.ts.map +1 -1
  232. package/dist/rpc.js +2 -2
  233. package/dist/runtime.d.ts +19 -0
  234. package/dist/runtime.d.ts.map +1 -0
  235. package/dist/runtime.js +40 -0
  236. package/dist/setupRequest.d.ts +20 -0
  237. package/dist/setupRequest.d.ts.map +1 -0
  238. package/dist/setupRequest.js +72 -0
  239. package/dist/toast.d.ts +51 -0
  240. package/dist/toast.d.ts.map +1 -0
  241. package/dist/toast.js +34 -0
  242. package/dist/transform.d.ts +1 -1
  243. package/dist/transform.d.ts.map +1 -1
  244. package/dist/transform.js +4 -5
  245. package/dist/utils/effectify.d.ts +1 -1
  246. package/dist/utils/effectify.d.ts.map +1 -1
  247. package/dist/utils/effectify.js +2 -2
  248. package/dist/utils/extend.d.ts +6 -1
  249. package/dist/utils/extend.d.ts.map +1 -1
  250. package/dist/utils/extend.js +24 -6
  251. package/dist/utils/gen.d.ts +4 -4
  252. package/dist/utils/gen.d.ts.map +1 -1
  253. package/dist/utils/logLevel.d.ts +2 -2
  254. package/dist/utils/logLevel.d.ts.map +1 -1
  255. package/dist/utils/logger.d.ts +2 -1
  256. package/dist/utils/logger.d.ts.map +1 -1
  257. package/dist/utils/logger.js +2 -2
  258. package/dist/utils.d.ts +34 -45
  259. package/dist/utils.d.ts.map +1 -1
  260. package/dist/utils.js +33 -49
  261. package/dist/validation/validators.d.ts.map +1 -1
  262. package/dist/validation.d.ts.map +1 -1
  263. package/dist/withToast.d.ts +30 -0
  264. package/dist/withToast.d.ts.map +1 -0
  265. package/dist/withToast.js +64 -0
  266. package/package.json +25 -266
  267. package/src/Array.ts +7 -39
  268. package/src/Chunk.ts +6 -55
  269. package/src/Config/SecretURL.ts +6 -3
  270. package/src/Config/internal/configSecretURL.ts +2 -2
  271. package/src/Config.ts +6 -13
  272. package/src/ConfigProvider.ts +4 -47
  273. package/src/Context.ts +9 -8
  274. package/src/DataDependencies.ts +171 -0
  275. package/src/DateTime.ts +473 -0
  276. package/src/Effect.ts +10 -32
  277. package/src/Emailer.ts +51 -0
  278. package/src/Function.ts +0 -7
  279. package/src/Inputify.type.ts +1 -1
  280. package/src/Layer.ts +8 -5
  281. package/src/Model/Repository/Registry.ts +35 -0
  282. package/src/Model/Repository/dependency.ts +32 -0
  283. package/src/Model/Repository/ext.ts +374 -0
  284. package/src/Model/Repository/internal/internal.ts +987 -0
  285. package/src/Model/Repository/legacy.ts +29 -0
  286. package/src/Model/Repository/makeRepo.ts +168 -0
  287. package/src/Model/Repository/service.ts +676 -0
  288. package/src/Model/Repository/validation.ts +38 -0
  289. package/src/Model/Repository.ts +7 -0
  290. package/src/Model/dsl.ts +130 -0
  291. package/src/Model/filter/filterApi.ts +78 -0
  292. package/src/Model/filter/types/errors.ts +47 -0
  293. package/src/Model/filter/types/fields.ts +50 -0
  294. package/src/Model/filter/types/path/common.ts +404 -0
  295. package/src/Model/filter/types/path/eager.ts +329 -0
  296. package/src/Model/filter/types/path/index.ts +4 -0
  297. package/src/Model/filter/types/utils.ts +128 -0
  298. package/src/Model/filter/types/validator.ts +46 -0
  299. package/src/Model/filter/types.ts +6 -0
  300. package/src/Model/query/dsl.ts +3092 -0
  301. package/src/Model/query/new-kid-interpreter.ts +531 -0
  302. package/src/Model/query.ts +13 -0
  303. package/src/Model.ts +5 -0
  304. package/src/NonEmptySet.ts +6 -4
  305. package/src/Option.ts +3 -8
  306. package/src/Pure.ts +20 -17
  307. package/src/QueueMaker.ts +11 -0
  308. package/src/RequestContext.ts +48 -0
  309. package/src/RequestScopedDependencies.ts +45 -0
  310. package/src/Schema/Class.ts +550 -56
  311. package/src/Schema/SchemaParser.ts +12 -0
  312. package/src/Schema/SpecialJsonSchema.ts +75 -7
  313. package/src/Schema/SpecialOpenApi.ts +5 -5
  314. package/src/Schema/brand.ts +27 -12
  315. package/src/Schema/email.ts +9 -7
  316. package/src/Schema/ext.ts +405 -95
  317. package/src/Schema/moreStrings.ts +213 -88
  318. package/src/Schema/numbers.ts +107 -29
  319. package/src/Schema/phoneNumber.ts +8 -9
  320. package/src/Schema/schema.ts +1 -1
  321. package/src/Schema/strings.ts +23 -14
  322. package/src/Schema.ts +403 -46
  323. package/src/SchemaAST.ts +1 -0
  324. package/src/Set.ts +10 -5
  325. package/src/Store.ts +325 -0
  326. package/src/_ext/Array.ts +4 -2
  327. package/src/_ext/ord.ext.ts +2 -1
  328. package/src/builtin-json.d.ts +24 -0
  329. package/src/builtin.ts +16 -21
  330. package/src/client/InvalidationKeys.ts +55 -0
  331. package/src/client/apiClientFactory.ts +295 -129
  332. package/src/client/clientFor.ts +101 -33
  333. package/src/client/errors.ts +66 -20
  334. package/src/client/makeClient.ts +519 -60
  335. package/src/client.ts +6 -4
  336. package/src/http/Request.ts +4 -4
  337. package/src/http/internal/lib.ts +12 -12
  338. package/src/http.ts +1 -1
  339. package/src/ids.ts +45 -8
  340. package/src/index.ts +20 -16
  341. package/src/middleware.ts +12 -8
  342. package/src/migration/nativeEffect.ts +645 -0
  343. package/src/rpc/Invalidation.ts +278 -0
  344. package/src/rpc/MiddlewareMaker.ts +86 -79
  345. package/src/rpc/README.md +2 -2
  346. package/src/rpc/RpcContextMap.ts +4 -4
  347. package/src/rpc/RpcMiddleware.ts +18 -13
  348. package/src/rpc.ts +4 -4
  349. package/src/runtime.ts +57 -0
  350. package/src/setupRequest.ts +138 -0
  351. package/src/toast.ts +54 -0
  352. package/src/transform.ts +4 -4
  353. package/src/utils/effectify.ts +1 -1
  354. package/src/utils/extend.ts +24 -5
  355. package/src/utils/gen.ts +7 -7
  356. package/src/utils/logLevel.ts +1 -1
  357. package/src/utils/logger.ts +3 -2
  358. package/src/utils.ts +85 -175
  359. package/src/validation.ts +2 -2
  360. package/src/withToast.ts +133 -0
  361. package/test/dateTimeLocal.test.ts +55 -0
  362. package/test/dist/dateTimeLocal.test.d.ts.map +1 -0
  363. package/test/dist/nativeEffectMigration.test.d.ts.map +1 -0
  364. package/test/dist/rpc.test.d.ts.map +1 -1
  365. package/test/dist/rpcMiddlewareContext.test.d.ts.map +1 -0
  366. package/test/moreStrings.test.ts +55 -10
  367. package/test/nativeEffectMigration.test.ts +77 -0
  368. package/test/rpc.test.ts +28 -11
  369. package/test/rpcMiddlewareContext.test.ts +63 -0
  370. package/test/schema.test.ts +318 -55
  371. package/test/secretURL.test.ts +4 -1
  372. package/test/special.test.ts +663 -131
  373. package/test/utils.test.ts +5 -5
  374. package/tsconfig.base.json +6 -4
  375. package/tsconfig.json +9 -1
  376. package/tsconfig.src.json +29 -29
  377. package/tsconfig.test.json +2 -2
  378. package/dist/Operations.d.ts +0 -124
  379. package/dist/Operations.d.ts.map +0 -1
  380. package/dist/Operations.js +0 -29
  381. package/dist/_ext/date.d.ts +0 -15
  382. package/dist/_ext/date.d.ts.map +0 -1
  383. package/dist/_ext/date.js +0 -16
  384. package/dist/_ext/misc.d.ts +0 -14
  385. package/dist/_ext/misc.d.ts.map +0 -1
  386. package/dist/_ext/misc.js +0 -17
  387. package/eslint.config.mjs +0 -26
  388. package/src/Operations.ts +0 -55
  389. package/src/_ext/date.ts +0 -27
  390. package/src/_ext/misc.ts +0 -46
  391. package/tsconfig.json.bak +0 -12
@@ -2,12 +2,12 @@
2
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
3
3
 
4
4
  import * as Record from "effect/Record"
5
- import type * as Request from "effect/Request"
5
+ import type * as Stream from "effect/Stream"
6
6
  import type { Path } from "path-parser"
7
7
  import qs from "query-string"
8
- import type * as Effect from "../Effect.js"
9
- import type * as S from "../Schema.js"
10
- import { type Req } from "./apiClientFactory.js"
8
+ import type * as Effect from "../Effect.ts"
9
+ import type * as S from "../Schema.ts"
10
+ import { type Req } from "./apiClientFactory.ts"
11
11
 
12
12
  export function makePathWithQuery(
13
13
  path: Path,
@@ -63,56 +63,124 @@ export type Client<M extends RequestsAny, ModuleName extends string> = RequestHa
63
63
  ModuleName
64
64
  >
65
65
 
66
- export type ExtractResponse<T> = T extends S.Codec<any> ? S.Schema.Type<T>
66
+ export type ExtractResponse<T> = T extends S.Codec<any> ? T["Type"]
67
67
  : T extends unknown ? void
68
68
  : never
69
69
 
70
- export type ExtractEResponse<T> = T extends S.Codec<any> ? S.Codec.Encoded<T>
70
+ export type ExtractEResponse<T> = T extends S.Codec<any> ? T["Encoded"]
71
71
  : T extends unknown ? void
72
72
  : never
73
73
 
74
- type IsEmpty<T> = keyof T extends never ? true
75
- : false
76
-
77
- // v4: Request.RequestTypeId, S.symbolSerializable, S.symbolWithResult removed — use keyof Request to filter internal props
78
- type Cruft = "_tag" | keyof Request.Request<any, any, any>
79
-
80
74
  export interface ClientForOptions {
81
75
  readonly skipQueryKey?: readonly string[]
76
+ /**
77
+ * Middleware tag to attach to every rpc on the client. Schema-only — the
78
+ * client never invokes the middleware (no Live impl required), but its
79
+ * declared `error` schema joins the rpc failure union via
80
+ * `Rpc.exitSchema`'s `rpc.middlewares[*].error` walk. Required when
81
+ * middleware can throw errors that aren't part of the resource's declared
82
+ * error union (e.g. auth middleware throwing `NotLoggedInError`); without
83
+ * it the client decode would fail with a `SchemaError` for stream rpcs.
84
+ */
82
85
  }
83
86
 
84
- export interface RequestHandler<A, E, R, Request extends Req, Id extends string> {
85
- handler: Effect.Effect<A, E, R>
87
+ // $Project/$Configuration.Index
88
+ // -> "$Project", "$Configuration", "Index"
89
+ export const makeQueryKey = ({ id, options }: { id: string; options?: ClientForOptions }) =>
90
+ id
91
+ .split("/")
92
+ .filter((segment: string) => !options || !options.skipQueryKey?.includes(segment))
93
+ .map((segment: string) => "$" + segment)
94
+ .join(".")
95
+ .split(".")
96
+
97
+ export interface RequestHandlerWithInput<I, A, E, R, Request extends Req, Id extends string> {
98
+ handler: (i: I) => Effect.Effect<A, E, R>
86
99
  id: Id
87
100
  options?: ClientForOptions
88
101
  Request: Request
102
+ queryKeyProjectionHash?: string
103
+ disableQueryInvalidation?: boolean
89
104
  }
90
105
 
91
- export interface RequestHandlerWithInput<I, A, E, R, Request extends Req, Id extends string> {
92
- handler: (i: I) => Effect.Effect<A, E, R>
106
+ /** Type alias: a no-input handler is simply `RequestHandlerWithInput<void, …>`. */
107
+ export type RequestHandler<A, E, R, Request extends Req, Id extends string> = RequestHandlerWithInput<
108
+ void,
109
+ A,
110
+ E,
111
+ R,
112
+ Request,
113
+ Id
114
+ >
115
+
116
+ export interface RequestStreamHandlerWithInput<I, A, E, R, Request extends Req, Id extends string, Final = A> {
117
+ handler: (i: I) => Stream.Stream<A, E, R>
93
118
  id: Id
94
119
  options?: ClientForOptions
95
120
  Request: Request
121
+ /**
122
+ * Phantom type property (never set at runtime) that carries the `Final` type to
123
+ * `StreamMutationWithExtensions`. The tilde prefix follows the Effect convention for
124
+ * phantom/virtual properties and prevents accidental runtime access.
125
+ * Stream failures bubble through the execute effect's typed error channel `E`;
126
+ * the reactive `AsyncResult` ref also mirrors the failure for live progress UI.
127
+ */
128
+ readonly "~final"?: Final
96
129
  }
97
130
 
131
+ /** Type alias: a no-input stream handler is simply `RequestStreamHandlerWithInput<void, …>`. */
132
+ export type RequestStreamHandler<A, E, R, Request extends Req, Id extends string, Final = A> =
133
+ RequestStreamHandlerWithInput<void, A, E, R, Request, Id, Final>
134
+
98
135
  // make sure this is exported or d.ts of apiClientFactory breaks?!
99
- type ReqDecodingServices<M> = M extends { readonly "~decodingServices": infer DS } ? DS : never
136
+ export type RequestInputFromMake<I extends { readonly make: (...args: any[]) => any }> = Parameters<I["make"]> extends
137
+ [] ? void : Parameters<I["make"]>[0]
138
+
139
+ // Has no input only when the request schema declares no payload fields (the auto-added
140
+ // `_tag` field is ignored). Any payload fields (even all-optional) produce a function handler.
141
+ type HasNoFields<I> = I extends { readonly fields: infer F extends S.Struct.Fields }
142
+ ? [Exclude<keyof F, "_tag">] extends [never] ? true : false
143
+ : false
144
+
145
+ type RequestInput<I extends { readonly make: (...args: any[]) => any }> = Parameters<I["make"]>[0]
146
+
147
+ /**
148
+ * Caller-facing input type for a request. `void` when the request schema has no fields;
149
+ * otherwise `make`'s first param type.
150
+ */
151
+ export type HandlerInput<I extends { readonly make: (...args: any[]) => any }> = HasNoFields<I> extends true ? void
152
+ : RequestInput<I>
153
+
154
+ /** Extracts the final-value type from a stream request. Defaults to the success type when no `final` schema is set. */
155
+ type FinalTypeOf<T extends Req> = T extends { readonly final: infer F extends S.Top } ? F["Type"]
156
+ : T["success"]["Type"]
157
+
158
+ // `T["success"]` / `T["error"]` are constrained to `S.Top` via `Req`, so we
159
+ // can read `["DecodingServices"]` directly. Avoids the conditional in
160
+ // `S.Codec.DecodingServices<X> = X extends Top ? X["DecodingServices"] : never`,
161
+ // which tsgo (native) fails to reduce in this generic position and leaves as
162
+ // `unknown`, polluting the `R` channel of every client handler.
163
+ type RequestHandlerFor<R, E, T extends Req, Id extends string> = T["stream"] extends true
164
+ ? RequestStreamHandlerWithInput<
165
+ HandlerInput<T>,
166
+ T["success"]["Type"],
167
+ T["error"]["Type"] | E,
168
+ R | T["success"]["DecodingServices"] | T["error"]["DecodingServices"],
169
+ T,
170
+ Id,
171
+ FinalTypeOf<T>
172
+ >
173
+ : RequestHandlerWithInput<
174
+ HandlerInput<T>,
175
+ T["success"]["Type"],
176
+ T["error"]["Type"] | E,
177
+ R | T["success"]["DecodingServices"] | T["error"]["DecodingServices"],
178
+ T,
179
+ Id
180
+ >
100
181
 
101
182
  export type RequestHandlers<R, E, M extends RequestsAny, ModuleName extends string> = {
102
- [K in keyof M as M[K] extends Req ? K : never]: IsEmpty<Omit<S.Schema.Type<M[K]>, Cruft>> extends true
103
- ? RequestHandler<
104
- S.Schema.Type<M[K]["success"]>,
105
- S.Schema.Type<M[K]["error"]> | E,
106
- R | ReqDecodingServices<M[K]>,
107
- M[K],
108
- `${ModuleName}.${K & string}`
109
- >
110
- : RequestHandlerWithInput<
111
- Omit<S.Schema.Type<M[K]>, Cruft>,
112
- S.Schema.Type<M[K]["success"]>,
113
- S.Schema.Type<M[K]["error"]> | E,
114
- R | ReqDecodingServices<M[K]>,
115
- M[K],
116
- `${ModuleName}.${K & string}`
117
- >
183
+ [K in keyof M as M[K] extends Req ? K : never]: Extract<M[K], Req> extends infer T extends Req
184
+ ? RequestHandlerFor<R, E, T, `${ModuleName}.${K & string}`>
185
+ : never
118
186
  }
@@ -1,19 +1,20 @@
1
1
  /** @effect-diagnostics overriddenSchemaConstructor:skip-file */
2
2
  import { TaggedErrorClass } from "effect-app/Schema"
3
3
  import * as Cause from "effect/Cause"
4
- import * as S from "../Schema.js"
4
+ import * as S from "../Schema.ts"
5
5
 
6
- export const tryToJson = (error: { toJSON(): unknown; toString(): string }) => {
6
+ export const tryToJson = (error: unknown) => {
7
7
  try {
8
- return error.toJSON()
8
+ const errorJson = (error as any).toJSON()
9
+ return errorJson && typeof errorJson === "object" ? errorJson as Record<string, unknown> : { error }
9
10
  } catch {
10
11
  try {
11
- return error.toString()
12
+ return { error: (error as any).toString() }
12
13
  } catch (err) {
13
14
  try {
14
- return `Failed to convert error: ${err}`
15
+ return { error: `Failed to convert error: ${err}` }
15
16
  } catch {
16
- return `Failed to convert error: unknown failure`
17
+ return { error: `Failed to convert error: unknown failure` }
17
18
  }
18
19
  }
19
20
  }
@@ -29,7 +30,7 @@ export class NotFoundError<ItemType = string> extends TaggedErrorClass<NotFoundE
29
30
  props: { type: string; id: unknown; cause?: unknown },
30
31
  disableValidation?: boolean
31
32
  ) {
32
- super(props as any, disableValidation as any)
33
+ super(props, disableValidation as any)
33
34
  }
34
35
  override get message() {
35
36
  return `Didn't find ${(this as any).type}#${JSON.stringify((this as any).id)}`
@@ -47,7 +48,7 @@ export class InvalidStateError extends TaggedErrorClass<InvalidStateError>()("In
47
48
  }) {
48
49
  constructor(messageOrObject: string | { message: string; cause?: unknown }, disableValidation?: boolean) {
49
50
  super(
50
- typeof messageOrObject === "object" ? messageOrObject : { message: messageOrObject } as any,
51
+ typeof messageOrObject === "object" ? messageOrObject : { message: messageOrObject },
51
52
  disableValidation as any
52
53
  )
53
54
  }
@@ -61,7 +62,7 @@ export class ServiceUnavailableError extends TaggedErrorClass<ServiceUnavailable
61
62
  }) {
62
63
  constructor(messageOrObject: string | { message: string; cause?: unknown }, disableValidation?: boolean) {
63
64
  super(
64
- typeof messageOrObject === "object" ? messageOrObject : { message: messageOrObject } as any,
65
+ typeof messageOrObject === "object" ? messageOrObject : { message: messageOrObject },
65
66
  disableValidation as any
66
67
  )
67
68
  }
@@ -77,7 +78,7 @@ export class ValidationError extends TaggedErrorClass<ValidationError>()("Valida
77
78
  props: { errors: ReadonlyArray<unknown>; cause?: unknown },
78
79
  disableValidation?: boolean
79
80
  ) {
80
- super(props as any, disableValidation as any)
81
+ super(props, disableValidation as any)
81
82
  }
82
83
  override get message() {
83
84
  return `Validation failed: ${(this as any).errors.map((e: any) => JSON.stringify(e, undefined, 2)).join(",\n")}`
@@ -91,7 +92,7 @@ export class NotLoggedInError extends TaggedErrorClass<NotLoggedInError>()("NotL
91
92
  message: S.String
92
93
  }) {
93
94
  constructor(messageOrObject?: string | { message: string; cause?: unknown }, disableValidation?: boolean) {
94
- super(messageFallback(messageOrObject) as any, disableValidation as any)
95
+ super(messageFallback(messageOrObject), disableValidation as any)
95
96
  }
96
97
  override toString() {
97
98
  return `NotLoggedInError: ${this.message}`
@@ -105,7 +106,7 @@ export class LoginError extends TaggedErrorClass<LoginError>()("NotLoggedInError
105
106
  message: S.String
106
107
  }) {
107
108
  constructor(messageOrObject?: string | { message: string; cause?: unknown }, disableValidation?: boolean) {
108
- super(messageFallback(messageOrObject) as any, disableValidation as any)
109
+ super(messageFallback(messageOrObject), disableValidation as any)
109
110
  }
110
111
  override toString() {
111
112
  return `LoginError: ${this.message}`
@@ -116,7 +117,7 @@ export class UnauthorizedError extends TaggedErrorClass<UnauthorizedError>()("Un
116
117
  message: S.String
117
118
  }) {
118
119
  constructor(messageOrObject?: string | { message: string; cause?: unknown }, disableValidation?: boolean) {
119
- super(messageFallback(messageOrObject) as any, disableValidation as any)
120
+ super(messageFallback(messageOrObject), disableValidation as any)
120
121
  }
121
122
  override toString() {
122
123
  return `UnauthorizedError: ${this.message}`
@@ -144,7 +145,7 @@ export class OptimisticConcurrencyException extends TaggedErrorClass<OptimisticC
144
145
  disableValidation?: boolean
145
146
  ) {
146
147
  super(
147
- "message" in args ? args : { message: `Existing ${args.type} ${args.id} record changed` } as any,
148
+ "message" in args ? args : { message: `Existing ${args.type} ${args.id} record changed` },
148
149
  disableValidation as any
149
150
  )
150
151
  if (!("message" in args)) {
@@ -156,6 +157,45 @@ export class OptimisticConcurrencyException extends TaggedErrorClass<OptimisticC
156
157
  }
157
158
  }
158
159
 
160
+ /**
161
+ * Raised by a store adapter when a database operation fails for an
162
+ * infrastructure reason (request timeout, throttle, 5xx, dropped socket, or any
163
+ * non-conflict error). Distinct from `OptimisticConcurrencyException`, which is
164
+ * an expected etag conflict.
165
+ *
166
+ * `transient` is set by the adapter for failures worth retrying (timeout /
167
+ * throttle / 5xx / network). `cause` is the underlying adapter error, carried
168
+ * through a `Defect` schema so it serializes (an `Error` encodes to
169
+ * `{ name, message, cause }`) instead of breaking JSON encoding of the channel.
170
+ *
171
+ * Treated by the api/client/FE machinery like an unexpected (500-class) error.
172
+ */
173
+ export class DatabaseError extends TaggedErrorClass<DatabaseError>()(
174
+ "DatabaseError",
175
+ {
176
+ message: S.String,
177
+ transient: S.Boolean,
178
+ cause: S.optional(S.Defect())
179
+ }
180
+ ) {
181
+ constructor(
182
+ args: { message?: string; transient?: boolean; cause?: unknown },
183
+ disableValidation?: boolean
184
+ ) {
185
+ super(
186
+ {
187
+ message: args.message ?? "Database operation failed",
188
+ transient: args.transient ?? false,
189
+ cause: args.cause
190
+ },
191
+ disableValidation as any
192
+ )
193
+ }
194
+ override toString() {
195
+ return `DatabaseError: ${this.message}`
196
+ }
197
+ }
198
+
159
199
  const MutationOnlyErrors = [
160
200
  InvalidStateError,
161
201
  OptimisticConcurrencyException
@@ -167,7 +207,8 @@ const GeneralErrors = [
167
207
  LoginError,
168
208
  UnauthorizedError,
169
209
  ValidationError,
170
- ServiceUnavailableError
210
+ ServiceUnavailableError,
211
+ DatabaseError
171
212
  ] as const
172
213
 
173
214
  export const SupportedErrors = S.Union([
@@ -202,11 +243,16 @@ export const silenceError = (e: Record<PropertyKey, any>) => {
202
243
  }
203
244
 
204
245
  export class CauseException<E> extends Error {
205
- constructor(readonly originalCause: Cause.Cause<E>, readonly _tag: string) {
246
+ readonly originalCause: Cause.Cause<E>
247
+ readonly _tag: string
248
+
249
+ constructor(originalCause: Cause.Cause<E>, _tag: string) {
206
250
  const limit = Error.stackTraceLimit
207
251
  Error.stackTraceLimit = 0
208
252
  super()
209
253
  Error.stackTraceLimit = limit
254
+ this.originalCause = originalCause
255
+ this._tag = _tag
210
256
  this.cause = Cause.squash(originalCause)
211
257
  // v4: makeFiberFailure removed — use Cause.prettyErrors instead
212
258
  const errors = Cause.prettyErrors(originalCause)
@@ -247,17 +293,17 @@ export class CauseException<E> extends Error {
247
293
  }
248
294
  }
249
295
 
250
- export const tryToReport = (error: { toReport(): unknown; toString(): string }) => {
296
+ export const tryToReport = (error: { toReport(): Record<string, unknown>; toString(): string }) => {
251
297
  try {
252
298
  return error.toReport()
253
299
  } catch {
254
300
  try {
255
- return error.toString()
301
+ return { error: error.toString() }
256
302
  } catch (err) {
257
303
  try {
258
- return `Failed to convert error: ${err}`
304
+ return { error: `Failed to convert error: ${err}` }
259
305
  } catch {
260
- return `Failed to convert error: unknown failure`
306
+ return { error: `Failed to convert error: unknown failure` }
261
307
  }
262
308
  }
263
309
  }