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
package/src/rpc.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * as RpcX from "./rpc.js"
2
- export * as MiddlewareMaker from "./rpc/MiddlewareMaker.js"
3
- export * as RpcContextMap from "./rpc/RpcContextMap.js"
4
- export * as RpcMiddleware from "./rpc/RpcMiddleware.js"
1
+ export * as Invalidation from "./rpc/Invalidation.ts"
2
+ export * as MiddlewareMaker from "./rpc/MiddlewareMaker.ts"
3
+ export * as RpcContextMap from "./rpc/RpcContextMap.ts"
4
+ export * as RpcMiddleware from "./rpc/RpcMiddleware.ts"
package/src/runtime.ts ADDED
@@ -0,0 +1,57 @@
1
+ import * as Exit from "effect/Exit"
2
+ import { flow } from "effect/Function"
3
+ import * as Logger from "effect/Logger"
4
+ import * as ManagedRuntime from "effect/ManagedRuntime"
5
+ import { CauseException } from "./client/errors.ts"
6
+ import { type Context } from "./Context.ts"
7
+ import * as Effect from "./Effect.ts"
8
+ import * as Layer from "./Layer.ts"
9
+
10
+ export const makeAppRuntime = Effect.fnUntraced(function*<A, E>(layer: Layer.Layer<A, E>) {
11
+ const l = layer.pipe(
12
+ Layer.provide(Logger.layer([Logger.consolePretty()])),
13
+ Layer.orDie
14
+ )
15
+ const mrt = ManagedRuntime.make(l)
16
+ yield* mrt.contextEffect
17
+ return Object.assign(mrt, {
18
+ [Symbol.dispose]() {
19
+ return Effect.runSync(mrt.disposeEffect)
20
+ },
21
+
22
+ [Symbol.asyncDispose]() {
23
+ return mrt.dispose()
24
+ }
25
+ }) // as we initialise here, there is no more error left.
26
+ })
27
+
28
+ export function initializeSync<A, E>(layer: Layer.Layer<A, E>) {
29
+ const runtime = Effect.runSync(makeAppRuntime(layer))
30
+ return runtime
31
+ }
32
+
33
+ export function initializeAsync<A, E>(layer: Layer.Layer<A, E>) {
34
+ return Effect
35
+ .runPromise(makeAppRuntime(layer))
36
+ }
37
+
38
+ // we wrap into CauseException because we want to keep the full cause of the failure.
39
+ export const makeRunPromise = <T>(services: Context<T>) =>
40
+ flow(Effect.runPromiseExitWith(services), (_) =>
41
+ _.then(
42
+ Exit.match({
43
+ onFailure: (cause) => Promise.reject(new CauseException(cause, "runPromise")),
44
+ onSuccess: (value) => Promise.resolve(value)
45
+ })
46
+ ))
47
+
48
+ export const makeRunSync = <T>(services: Context<T>) =>
49
+ flow(
50
+ Effect.runSyncExitWith(services),
51
+ Exit.match({
52
+ onFailure: (cause) => {
53
+ throw new CauseException(cause, "runSync")
54
+ },
55
+ onSuccess: (value) => value
56
+ })
57
+ )
@@ -0,0 +1,138 @@
1
+ import { SqlClient } from "effect/sql"
2
+ import * as Tracer from "effect/Tracer"
3
+ import { DataDependencyRecorder } from "./DataDependencies.ts"
4
+ import * as Effect from "./Effect.ts"
5
+ import * as Layer from "./Layer.ts"
6
+ import * as Option from "./Option.ts"
7
+ import { LocaleRef, RequestContext, spanAttributes } from "./RequestContext.ts"
8
+ import * as RequestScopedDependencies from "./RequestScopedDependencies.ts"
9
+ import { NonEmptyString255 } from "./Schema.ts"
10
+ import { ContextMapContainer, storeId } from "./Store.ts"
11
+
12
+ const withSqlTransaction = <R, E, A>(self: Effect.Effect<A, E, R>): Effect.Effect<A, E, R> =>
13
+ Effect.serviceOption(SqlClient.SqlClient).pipe(
14
+ Effect.flatMap(Option.match({
15
+ onNone: () => self,
16
+ onSome: (sql) => sql.withTransaction(self).pipe(Effect.orDie)
17
+ }))
18
+ )
19
+
20
+ export const getRequestContext = Effect
21
+ .all({
22
+ span: Effect.currentSpan.pipe(Effect.orDie),
23
+ locale: LocaleRef,
24
+ namespace: storeId
25
+ })
26
+ .pipe(
27
+ Effect.map(({ locale, namespace, span }) =>
28
+ RequestContext.make({
29
+ span: Tracer.externalSpan(span),
30
+ locale,
31
+ namespace,
32
+ name: NonEmptyString255(span.name)
33
+ })
34
+ )
35
+ )
36
+
37
+ export const getRC = Effect.all({
38
+ locale: LocaleRef,
39
+ namespace: storeId
40
+ })
41
+
42
+ const withRequestSpan = (name = "request", options?: Tracer.SpanOptions) => <R, E, A>(f: Effect.Effect<A, E, R>) =>
43
+ Effect.andThen(
44
+ getRC,
45
+ (ctx) =>
46
+ f.pipe(
47
+ Effect.withSpan(name, {
48
+ ...options,
49
+ attributes: { ...spanAttributes({ ...ctx, name: NonEmptyString255(name) }), ...options?.attributes }
50
+ }, {
51
+ captureStackTrace: options?.captureStackTrace ?? false
52
+ }),
53
+ // TODO: false
54
+ // request context info is picked up directly in the logger for annotations.
55
+ Effect.withLogSpan(name)
56
+ )
57
+ )
58
+
59
+ export interface SetupRequestOptions {
60
+ readonly withTransaction?: boolean
61
+ }
62
+
63
+ export const requestStateLayer = RequestScopedDependencies.layer(ContextMapContainer, DataDependencyRecorder)
64
+
65
+ // Build `layer` against the ambient (request) scope rather than a sub-scope of the
66
+ // returned Effect. Required when the returned value is a streaming HttpServerResponse:
67
+ // the response body keeps producing chunks (and using layer-provided state) after the
68
+ // Effect returns, so a sub-scope would close too early and run finalizers mid-stream.
69
+ export const provideOnRequestScope =
70
+ <ROut, E2, RIn>(layer: Layer.Layer<ROut, E2, RIn>) => <A, E, R>(self: Effect.Effect<A, E, R>) =>
71
+ Effect.gen(function*() {
72
+ const requestScope = yield* Effect.scope
73
+ // Fresh MemoMap per request: `Layer.buildWithScope` would otherwise reuse
74
+ // the ambient MemoMap living on the HTTP server fiber, sharing the built
75
+ // value (e.g. ContextMap) across every request handled by that server.
76
+ const memoMap = yield* Layer.makeMemoMap
77
+ const ctx = yield* Layer.buildWithMemoMap(layer, memoMap, requestScope)
78
+ return yield* Effect.provide(self, ctx)
79
+ })
80
+
81
+ export const setupRequestContextFromCurrent =
82
+ (name = "request", options?: Tracer.SpanOptions & SetupRequestOptions) => <R, E, A>(self: Effect.Effect<A, E, R>) =>
83
+ self
84
+ .pipe(
85
+ options?.withTransaction === true ? withSqlTransaction : (_) => _,
86
+ withRequestSpan(name, options),
87
+ Effect.provide(requestStateLayer, { local: true })
88
+ )
89
+
90
+ // Streaming variant: binds ContextMapContainer to the ambient (request) scope so its
91
+ // finalizer (clear()) runs only after the response body is fully drained, not when the
92
+ // outer Effect returns its HttpServerResponse value. Use for handlers that return a
93
+ // streaming HttpServerResponse (e.g. SSE) — see RequestContextMiddleware for context.
94
+ export const setupStreamingRequestContextFromCurrent =
95
+ (name = "request", options?: Tracer.SpanOptions & SetupRequestOptions) => <R, E, A>(self: Effect.Effect<A, E, R>) =>
96
+ self.pipe(
97
+ options?.withTransaction === true ? withSqlTransaction : (_) => _,
98
+ withRequestSpan(name, options),
99
+ provideOnRequestScope(requestStateLayer)
100
+ )
101
+
102
+ // TODO: consider integrating Effect.withParentSpan
103
+ export function setupRequestContext<R, E, A>(
104
+ self: Effect.Effect<A, E, R>,
105
+ requestContext: RequestContext,
106
+ options?: SetupRequestOptions
107
+ ) {
108
+ const layer = Layer.mergeAll(
109
+ requestStateLayer,
110
+ Layer.succeed(LocaleRef, requestContext.locale),
111
+ Layer.succeed(storeId, requestContext.namespace)
112
+ )
113
+ return self
114
+ .pipe(
115
+ options?.withTransaction === true ? withSqlTransaction : (_) => _,
116
+ withRequestSpan(requestContext.name),
117
+ Effect.provide(layer, { local: true })
118
+ )
119
+ }
120
+
121
+ export function setupRequestContextWithCustomSpan<R, E, A>(
122
+ self: Effect.Effect<A, E, R>,
123
+ requestContext: RequestContext,
124
+ name: string,
125
+ options?: Tracer.SpanOptions & SetupRequestOptions
126
+ ) {
127
+ const layer = Layer.mergeAll(
128
+ requestStateLayer,
129
+ Layer.succeed(LocaleRef, requestContext.locale),
130
+ Layer.succeed(storeId, requestContext.namespace)
131
+ )
132
+ return self
133
+ .pipe(
134
+ options?.withTransaction === true ? withSqlTransaction : (_) => _,
135
+ withRequestSpan(name, options),
136
+ Effect.provide(layer, { local: true })
137
+ )
138
+ }
package/src/toast.ts ADDED
@@ -0,0 +1,54 @@
1
+ import * as Context from "./Context.ts"
2
+ import { accessEffectFn } from "./Context.ts"
3
+ import * as Effect from "./Effect.ts"
4
+ import * as Option from "./Option.ts"
5
+
6
+ export type ToastId = string | number
7
+ export type ToastOpts = { id?: ToastId; timeout?: number; groupId?: string; requestId?: string }
8
+ export type ToastOptsInternal = { id?: ToastId | null; timeout?: number; groupId?: string; requestId?: string }
9
+
10
+ export type UseToast = () => {
11
+ error: (this: void, message: string, options?: ToastOpts) => ToastId
12
+ warning: (this: void, message: string, options?: ToastOpts) => ToastId
13
+ success: (this: void, message: string, options?: ToastOpts) => ToastId
14
+ info: (this: void, message: string, options?: ToastOpts) => ToastId
15
+ dismiss: (this: void, id: ToastId) => void
16
+ }
17
+
18
+ export class CurrentToastId extends Context.Opaque<CurrentToastId, { toastId: ToastId }>()("CurrentToastId") {}
19
+
20
+ /** fallback to CurrentToastId when available unless id is explicitly set to a value or null */
21
+ export const wrap = (toast: ReturnType<UseToast>) => {
22
+ const wrap = (toastHandler: (message: string, options?: ToastOpts) => ToastId) => {
23
+ return (message: string, options?: ToastOptsInternal) =>
24
+ Effect.serviceOption(CurrentToastId).pipe(
25
+ Effect.flatMap((currentToast) =>
26
+ Effect.sync(() => {
27
+ const { id: _id, ...rest } = options ?? {}
28
+ const id = _id !== undefined
29
+ ? _id ?? undefined
30
+ : Option.getOrUndefined(Option.map(currentToast, (_) => _.toastId))
31
+ // when id is undefined, we may end up with no toast at all..
32
+ return toastHandler(message, id !== undefined ? { ...rest, id } : rest)
33
+ })
34
+ )
35
+ )
36
+ }
37
+ return {
38
+ error: wrap(toast.error),
39
+ info: wrap(toast.info),
40
+ success: wrap(toast.success),
41
+ warning: wrap(toast.warning),
42
+ dismiss: (toastId: ToastId) => Effect.sync(() => toast.dismiss(toastId))
43
+ }
44
+ }
45
+
46
+ type ToastShape = ReturnType<typeof wrap>
47
+
48
+ export class Toast extends Context.Opaque<Toast, ToastShape>()("Toast") {
49
+ static readonly error = accessEffectFn(this, "error")
50
+ static readonly info = accessEffectFn(this, "info")
51
+ static readonly success = accessEffectFn(this, "success")
52
+ static readonly warning = accessEffectFn(this, "warning")
53
+ static readonly dismiss = accessEffectFn(this, "dismiss")
54
+ }
package/src/transform.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { Option } from "effect"
3
2
  import type { NonEmptyReadonlyArray } from "effect/Array"
3
+ import * as Option from "effect/Option"
4
4
  import type { Misc, Union } from "ts-toolbelt"
5
- import type * as SET from "./Set.js"
5
+ import type * as SET from "./Set.ts"
6
6
 
7
7
  // type SomeObject = {
8
8
  // 0: Option.Option<string>
@@ -51,8 +51,8 @@ const encodeOptsAsNullable_ = (value: any, cacheMap: Map<any, any>): any => {
51
51
 
52
52
  if (
53
53
  value instanceof Date
54
- || value instanceof Function
55
- || value instanceof Promise
54
+ || typeof value === "function"
55
+ || (typeof value === "object" && value !== null && "then" in value && typeof value.then === "function")
56
56
  ) {
57
57
  return value
58
58
  }
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  /* eslint-disable @typescript-eslint/no-unsafe-assignment */
3
3
 
4
- import { Effect } from "effect"
4
+ import * as Effect from "effect/Effect"
5
5
 
6
6
  interface Callback<E, A> {
7
7
  (err: E, a?: A): void
@@ -1,9 +1,28 @@
1
+ /**
2
+ * Own-property define that shadows getter-only prototype fields such as
3
+ * Effect 4 `Schema.make`. `Object.assign` uses [[Set]] and cannot.
4
+ */
5
+ export const defineOwn = (target: object, key: PropertyKey, value: unknown) => {
6
+ Object.defineProperty(target, key, {
7
+ value,
8
+ writable: true,
9
+ enumerable: true,
10
+ configurable: true
11
+ })
12
+ }
13
+
14
+ const assignOwn = <T extends object>(target: T, source: object): T => {
15
+ for (const key of Reflect.ownKeys(source)) {
16
+ const desc = Object.getOwnPropertyDescriptor(source, key)
17
+ if (!desc?.enumerable) continue
18
+ defineOwn(target, key, (source as Record<PropertyKey, unknown>)[key])
19
+ }
20
+ return target
21
+ }
22
+
1
23
  export const extend = <T extends {}, X extends {}>(a: T, ext: X) => {
2
- Object.assign(a, ext)
24
+ assignOwn(a, ext)
3
25
  return a as T & X
4
26
  }
5
27
 
6
- export const extendM = <T extends {}, X extends {}>(a: T, ext: (a: T) => X) => {
7
- Object.assign(a, ext(a))
8
- return a as typeof a & X
9
- }
28
+ export const extendM = <T extends {}, X extends {}>(a: T, ext: (a: T) => X) => extend(a, ext(a))
package/src/utils/gen.ts CHANGED
@@ -1,24 +1,24 @@
1
- import { type Effect, type Yieldable } from "effect/Effect"
1
+ import { type Effect } from "effect/Effect"
2
2
 
3
3
  export namespace EffectGenUtils {
4
4
  export type Success<EG> = EG extends Effect<infer A, infer _E, infer _R> ? A
5
5
  // there could be a case where the generator function does not yield anything, so we need to handle that
6
6
  : EG extends (..._: infer _3) => Generator<never, infer A, infer _2> ? A
7
- // v4: generators can yield Yieldable (Effect, Service, etc.), all have asEffect()
8
- : EG extends (..._: infer _3) => Generator<Yieldable<any, infer _, infer _E, infer _R>, infer A, infer _2> ? A
7
+ // generators yield Effect values
8
+ : EG extends (..._: infer _3) => Generator<Effect<any, infer _E, infer _R>, infer A, infer _2> ? A
9
9
  : never
10
10
 
11
11
  export type Error<EG> = EG extends Effect<infer _A, infer E, infer _R> ? E
12
12
  // there could be a case where the generator function does not yield anything, so we need to handle that
13
13
  : EG extends (..._: infer _3) => Generator<never, infer _A, infer _2> ? never
14
- // v4: generators can yield Yieldable (Effect, Service, etc.), all have asEffect()
15
- : EG extends (..._: infer _3) => Generator<Yieldable<any, infer _, infer E, infer _R>, infer _A, infer _2> ? E
14
+ // generators yield Effect values
15
+ : EG extends (..._: infer _3) => Generator<Effect<any, infer E, infer _R>, infer _A, infer _2> ? E
16
16
  : never
17
17
 
18
18
  export type Context<EG> = EG extends Effect<infer _A, infer _E, infer R> ? R
19
19
  // there could be a case where the generator function does not yield anything, so we need to handle that
20
20
  : EG extends (..._: infer _3) => Generator<never, infer _A, infer _2> ? never
21
- // v4: generators can yield Yieldable (Effect, Service, etc.), all have asEffect()
22
- : EG extends (..._: infer _3) => Generator<Yieldable<any, infer _, infer _E, infer R>, infer _A, infer _2> ? R
21
+ // generators yield Effect values
22
+ : EG extends (..._: infer _3) => Generator<Effect<any, infer _E, infer R>, infer _A, infer _2> ? R
23
23
  : never
24
24
  }
@@ -1,4 +1,4 @@
1
- import { type LogLevel } from "effect"
1
+ import type * as LogLevel from "effect/LogLevel"
2
2
 
3
3
  export const LogLevelToSentry = (level: LogLevel.LogLevel) => {
4
4
  switch (level) {
@@ -1,8 +1,9 @@
1
1
  /* eslint-disable @typescript-eslint/no-unsafe-argument */
2
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
3
3
 
4
- import { Effect, type LogLevel } from "effect"
5
- import * as Context from "../Context.js"
4
+ import * as Effect from "effect/Effect"
5
+ import type * as LogLevel from "effect/LogLevel"
6
+ import * as Context from "../Context.ts"
6
7
 
7
8
  type Levels = "info" | "debug" | "warn" | "error"
8
9