effect-start 0.23.1 → 0.26.0

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 (351) hide show
  1. package/package.json +18 -86
  2. package/src/Development.ts +3 -1
  3. package/src/Entity.ts +17 -0
  4. package/src/Fetch.ts +271 -0
  5. package/src/SqlIntrospect.ts +64 -70
  6. package/src/Start.ts +21 -24
  7. package/src/StartApp.ts +1 -1
  8. package/src/bun/BunServer.ts +42 -10
  9. package/src/hyper/HyperHtml.ts +0 -1
  10. package/src/sql/bun/index.ts +1 -1
  11. package/src/sql/index.ts +1 -0
  12. package/src/sql/libsql/index.ts +173 -0
  13. package/src/sql/libsql/libsql.d.ts +39 -0
  14. package/src/sql/mssql/index.ts +1 -1
  15. package/dist/BlobStore.d.ts +0 -80
  16. package/dist/BlobStore.js +0 -19
  17. package/dist/ChildProcess.d.ts +0 -60
  18. package/dist/ChildProcess.js +0 -30
  19. package/dist/Commander.d.ts +0 -100
  20. package/dist/Commander.js +0 -326
  21. package/dist/ContentNegotiation.d.ts +0 -12
  22. package/dist/ContentNegotiation.js +0 -359
  23. package/dist/Cookies.d.ts +0 -47
  24. package/dist/Cookies.js +0 -302
  25. package/dist/Development.d.ts +0 -39
  26. package/dist/Development.js +0 -58
  27. package/dist/Effectify.d.ts +0 -209
  28. package/dist/Effectify.js +0 -19
  29. package/dist/Entity.d.ts +0 -47
  30. package/dist/Entity.js +0 -224
  31. package/dist/FilePathPattern.d.ts +0 -29
  32. package/dist/FilePathPattern.js +0 -86
  33. package/dist/FileRouter.d.ts +0 -56
  34. package/dist/FileRouter.js +0 -148
  35. package/dist/FileRouterCodegen.d.ts +0 -18
  36. package/dist/FileRouterCodegen.js +0 -227
  37. package/dist/FileRouterPattern.d.ts +0 -9
  38. package/dist/FileRouterPattern.js +0 -35
  39. package/dist/FileSystem.d.ts +0 -158
  40. package/dist/FileSystem.js +0 -70
  41. package/dist/Http.d.ts +0 -37
  42. package/dist/Http.js +0 -88
  43. package/dist/HttpAppExtra.d.ts +0 -7
  44. package/dist/HttpAppExtra.js +0 -320
  45. package/dist/HttpUtils.d.ts +0 -3
  46. package/dist/HttpUtils.js +0 -11
  47. package/dist/PathPattern.d.ts +0 -134
  48. package/dist/PathPattern.js +0 -413
  49. package/dist/PlatformError.d.ts +0 -38
  50. package/dist/PlatformError.js +0 -25
  51. package/dist/PlatformRuntime.d.ts +0 -27
  52. package/dist/PlatformRuntime.js +0 -46
  53. package/dist/Route.d.ts +0 -97
  54. package/dist/Route.js +0 -100
  55. package/dist/RouteBody.d.ts +0 -47
  56. package/dist/RouteBody.js +0 -67
  57. package/dist/RouteError.d.ts +0 -98
  58. package/dist/RouteError.js +0 -55
  59. package/dist/RouteHook.d.ts +0 -12
  60. package/dist/RouteHook.js +0 -40
  61. package/dist/RouteHttp.d.ts +0 -21
  62. package/dist/RouteHttp.js +0 -258
  63. package/dist/RouteHttpTracer.d.ts +0 -10
  64. package/dist/RouteHttpTracer.js +0 -62
  65. package/dist/RouteMount.d.ts +0 -86
  66. package/dist/RouteMount.js +0 -63
  67. package/dist/RouteSchema.d.ts +0 -86
  68. package/dist/RouteSchema.js +0 -188
  69. package/dist/RouteSse.d.ts +0 -21
  70. package/dist/RouteSse.js +0 -79
  71. package/dist/RouteTree.d.ts +0 -57
  72. package/dist/RouteTree.js +0 -93
  73. package/dist/RouteTrie.d.ts +0 -20
  74. package/dist/RouteTrie.js +0 -152
  75. package/dist/RouterPattern.d.ts +0 -118
  76. package/dist/RouterPattern.js +0 -269
  77. package/dist/SchemaExtra.d.ts +0 -7
  78. package/dist/SchemaExtra.js +0 -74
  79. package/dist/Socket.d.ts +0 -27
  80. package/dist/Socket.js +0 -29
  81. package/dist/Sql.d.ts +0 -34
  82. package/dist/Sql.js +0 -5
  83. package/dist/SqlIntrospect.d.ts +0 -91
  84. package/dist/SqlIntrospect.js +0 -466
  85. package/dist/Start.d.ts +0 -44
  86. package/dist/Start.js +0 -49
  87. package/dist/StartApp.d.ts +0 -19
  88. package/dist/StartApp.js +0 -21
  89. package/dist/StreamExtra.d.ts +0 -28
  90. package/dist/StreamExtra.js +0 -100
  91. package/dist/System.d.ts +0 -7
  92. package/dist/System.js +0 -22
  93. package/dist/TuplePathPattern.d.ts +0 -9
  94. package/dist/TuplePathPattern.js +0 -68
  95. package/dist/Unique.d.ts +0 -50
  96. package/dist/Unique.js +0 -187
  97. package/dist/Values.d.ts +0 -27
  98. package/dist/Values.js +0 -36
  99. package/dist/bun/BunBlobStoreDisk.d.ts +0 -6
  100. package/dist/bun/BunBlobStoreDisk.js +0 -116
  101. package/dist/bun/BunBlobStoreS3.d.ts +0 -11
  102. package/dist/bun/BunBlobStoreS3.js +0 -89
  103. package/dist/bun/BunBlobWatcherDisk.d.ts +0 -6
  104. package/dist/bun/BunBlobWatcherDisk.js +0 -60
  105. package/dist/bun/BunBlobWatcherQueue.d.ts +0 -6
  106. package/dist/bun/BunBlobWatcherQueue.js +0 -17
  107. package/dist/bun/BunBundle.d.ts +0 -11
  108. package/dist/bun/BunBundle.js +0 -137
  109. package/dist/bun/BunChildProcessSpawner.d.ts +0 -3
  110. package/dist/bun/BunChildProcessSpawner.js +0 -103
  111. package/dist/bun/BunHttpServer.d.ts +0 -44
  112. package/dist/bun/BunHttpServer.js +0 -186
  113. package/dist/bun/BunHttpServer_web.d.ts +0 -60
  114. package/dist/bun/BunHttpServer_web.js +0 -252
  115. package/dist/bun/BunImportTrackerPlugin.d.ts +0 -13
  116. package/dist/bun/BunImportTrackerPlugin.js +0 -69
  117. package/dist/bun/BunPlatformHttpServer.d.ts +0 -10
  118. package/dist/bun/BunPlatformHttpServer.js +0 -53
  119. package/dist/bun/BunRoute.d.ts +0 -48
  120. package/dist/bun/BunRoute.js +0 -121
  121. package/dist/bun/BunRuntime.d.ts +0 -2
  122. package/dist/bun/BunRuntime.js +0 -31
  123. package/dist/bun/BunServer.d.ts +0 -40
  124. package/dist/bun/BunServer.js +0 -157
  125. package/dist/bun/BunServerRequest.d.ts +0 -60
  126. package/dist/bun/BunServerRequest.js +0 -252
  127. package/dist/bun/BunSql.d.ts +0 -4
  128. package/dist/bun/BunSql.js +0 -81
  129. package/dist/bun/BunVirtualFilesPlugin.d.ts +0 -4
  130. package/dist/bun/BunVirtualFilesPlugin.js +0 -40
  131. package/dist/bun/_BunEnhancedResolve.d.ts +0 -45
  132. package/dist/bun/_BunEnhancedResolve.js +0 -102
  133. package/dist/bun/index.d.ts +0 -5
  134. package/dist/bun/index.js +0 -5
  135. package/dist/bundler/Bundle.d.ts +0 -61
  136. package/dist/bundler/Bundle.js +0 -48
  137. package/dist/bundler/BundleFiles.d.ts +0 -13
  138. package/dist/bundler/BundleFiles.js +0 -96
  139. package/dist/bundler/BundleHttp.d.ts +0 -45
  140. package/dist/bundler/BundleHttp.js +0 -176
  141. package/dist/bundler/BundleRoute.d.ts +0 -27
  142. package/dist/bundler/BundleRoute.js +0 -51
  143. package/dist/client/Overlay.d.ts +0 -2
  144. package/dist/client/Overlay.js +0 -32
  145. package/dist/client/ScrollState.d.ts +0 -6
  146. package/dist/client/ScrollState.js +0 -94
  147. package/dist/client/index.d.ts +0 -6
  148. package/dist/client/index.js +0 -79
  149. package/dist/console/Console.d.ts +0 -6
  150. package/dist/console/Console.js +0 -26
  151. package/dist/console/ConsoleErrors.d.ts +0 -3
  152. package/dist/console/ConsoleErrors.js +0 -200
  153. package/dist/console/ConsoleLogger.d.ts +0 -3
  154. package/dist/console/ConsoleLogger.js +0 -47
  155. package/dist/console/ConsoleMetrics.d.ts +0 -3
  156. package/dist/console/ConsoleMetrics.js +0 -61
  157. package/dist/console/ConsoleProcess.d.ts +0 -3
  158. package/dist/console/ConsoleProcess.js +0 -49
  159. package/dist/console/ConsoleStore.d.ts +0 -144
  160. package/dist/console/ConsoleStore.js +0 -61
  161. package/dist/console/ConsoleTracer.d.ts +0 -3
  162. package/dist/console/ConsoleTracer.js +0 -94
  163. package/dist/console/Simulation.d.ts +0 -2
  164. package/dist/console/Simulation.js +0 -633
  165. package/dist/console/index.d.ts +0 -3
  166. package/dist/console/index.js +0 -3
  167. package/dist/console/routes/errors/route.d.ts +0 -10
  168. package/dist/console/routes/errors/route.js +0 -47
  169. package/dist/console/routes/fiberDetail.d.ts +0 -16
  170. package/dist/console/routes/fiberDetail.js +0 -38
  171. package/dist/console/routes/fibers/route.d.ts +0 -10
  172. package/dist/console/routes/fibers/route.js +0 -19
  173. package/dist/console/routes/git/route.d.ts +0 -11
  174. package/dist/console/routes/git/route.js +0 -33
  175. package/dist/console/routes/layout.d.ts +0 -9
  176. package/dist/console/routes/layout.js +0 -3
  177. package/dist/console/routes/logs/route.d.ts +0 -10
  178. package/dist/console/routes/logs/route.js +0 -32
  179. package/dist/console/routes/metrics/route.d.ts +0 -10
  180. package/dist/console/routes/metrics/route.js +0 -17
  181. package/dist/console/routes/route.d.ts +0 -6
  182. package/dist/console/routes/route.js +0 -5
  183. package/dist/console/routes/routes/route.d.ts +0 -6
  184. package/dist/console/routes/routes/route.js +0 -20
  185. package/dist/console/routes/services/route.d.ts +0 -6
  186. package/dist/console/routes/services/route.js +0 -12
  187. package/dist/console/routes/system/route.d.ts +0 -10
  188. package/dist/console/routes/system/route.js +0 -18
  189. package/dist/console/routes/traceDetail.d.ts +0 -16
  190. package/dist/console/routes/traceDetail.js +0 -14
  191. package/dist/console/routes/traces/route.d.ts +0 -10
  192. package/dist/console/routes/traces/route.js +0 -39
  193. package/dist/console/routes/tree.d.ts +0 -153
  194. package/dist/console/routes/tree.js +0 -29
  195. package/dist/console/ui/Errors.d.ts +0 -4
  196. package/dist/console/ui/Errors.js +0 -15
  197. package/dist/console/ui/Fibers.d.ts +0 -24
  198. package/dist/console/ui/Fibers.js +0 -121
  199. package/dist/console/ui/Git.d.ts +0 -20
  200. package/dist/console/ui/Git.js +0 -95
  201. package/dist/console/ui/Logs.d.ts +0 -4
  202. package/dist/console/ui/Logs.js +0 -25
  203. package/dist/console/ui/Metrics.d.ts +0 -4
  204. package/dist/console/ui/Metrics.js +0 -26
  205. package/dist/console/ui/Routes.d.ts +0 -8
  206. package/dist/console/ui/Routes.js +0 -70
  207. package/dist/console/ui/Services.d.ts +0 -10
  208. package/dist/console/ui/Services.js +0 -246
  209. package/dist/console/ui/Shell.d.ts +0 -10
  210. package/dist/console/ui/Shell.js +0 -7
  211. package/dist/console/ui/System.d.ts +0 -4
  212. package/dist/console/ui/System.js +0 -35
  213. package/dist/console/ui/Traces.d.ts +0 -12
  214. package/dist/console/ui/Traces.js +0 -179
  215. package/dist/datastar/actions/fetch.d.ts +0 -30
  216. package/dist/datastar/actions/fetch.js +0 -403
  217. package/dist/datastar/actions/peek.d.ts +0 -1
  218. package/dist/datastar/actions/peek.js +0 -13
  219. package/dist/datastar/actions/setAll.d.ts +0 -1
  220. package/dist/datastar/actions/setAll.js +0 -12
  221. package/dist/datastar/actions/toggleAll.d.ts +0 -1
  222. package/dist/datastar/actions/toggleAll.js +0 -12
  223. package/dist/datastar/attributes/attr.d.ts +0 -1
  224. package/dist/datastar/attributes/attr.js +0 -48
  225. package/dist/datastar/attributes/bind.d.ts +0 -1
  226. package/dist/datastar/attributes/bind.js +0 -175
  227. package/dist/datastar/attributes/class.d.ts +0 -1
  228. package/dist/datastar/attributes/class.js +0 -47
  229. package/dist/datastar/attributes/computed.d.ts +0 -1
  230. package/dist/datastar/attributes/computed.js +0 -26
  231. package/dist/datastar/attributes/effect.d.ts +0 -1
  232. package/dist/datastar/attributes/effect.js +0 -9
  233. package/dist/datastar/attributes/indicator.d.ts +0 -1
  234. package/dist/datastar/attributes/indicator.js +0 -30
  235. package/dist/datastar/attributes/init.d.ts +0 -1
  236. package/dist/datastar/attributes/init.js +0 -26
  237. package/dist/datastar/attributes/jsonSignals.d.ts +0 -1
  238. package/dist/datastar/attributes/jsonSignals.js +0 -30
  239. package/dist/datastar/attributes/on.d.ts +0 -1
  240. package/dist/datastar/attributes/on.js +0 -78
  241. package/dist/datastar/attributes/onIntersect.d.ts +0 -1
  242. package/dist/datastar/attributes/onIntersect.js +0 -53
  243. package/dist/datastar/attributes/onInterval.d.ts +0 -1
  244. package/dist/datastar/attributes/onInterval.js +0 -30
  245. package/dist/datastar/attributes/onSignalPatch.d.ts +0 -1
  246. package/dist/datastar/attributes/onSignalPatch.js +0 -42
  247. package/dist/datastar/attributes/ref.d.ts +0 -1
  248. package/dist/datastar/attributes/ref.js +0 -10
  249. package/dist/datastar/attributes/show.d.ts +0 -1
  250. package/dist/datastar/attributes/show.js +0 -31
  251. package/dist/datastar/attributes/signals.d.ts +0 -1
  252. package/dist/datastar/attributes/signals.js +0 -17
  253. package/dist/datastar/attributes/style.d.ts +0 -1
  254. package/dist/datastar/attributes/style.js +0 -50
  255. package/dist/datastar/attributes/text.d.ts +0 -1
  256. package/dist/datastar/attributes/text.js +0 -26
  257. package/dist/datastar/engine.d.ts +0 -162
  258. package/dist/datastar/engine.js +0 -999
  259. package/dist/datastar/happydom.d.ts +0 -1
  260. package/dist/datastar/happydom.js +0 -8
  261. package/dist/datastar/index.d.ts +0 -24
  262. package/dist/datastar/index.js +0 -24
  263. package/dist/datastar/load.d.ts +0 -24
  264. package/dist/datastar/load.js +0 -24
  265. package/dist/datastar/utils.d.ts +0 -51
  266. package/dist/datastar/utils.js +0 -202
  267. package/dist/datastar/watchers/patchElements.d.ts +0 -1
  268. package/dist/datastar/watchers/patchElements.js +0 -399
  269. package/dist/datastar/watchers/patchSignals.d.ts +0 -1
  270. package/dist/datastar/watchers/patchSignals.js +0 -14
  271. package/dist/experimental/EncryptedCookies.d.ts +0 -48
  272. package/dist/experimental/EncryptedCookies.js +0 -212
  273. package/dist/experimental/SseHttpResponse.d.ts +0 -7
  274. package/dist/experimental/SseHttpResponse.js +0 -28
  275. package/dist/experimental/index.d.ts +0 -1
  276. package/dist/experimental/index.js +0 -1
  277. package/dist/hyper/Hyper.d.ts +0 -25
  278. package/dist/hyper/Hyper.js +0 -23
  279. package/dist/hyper/HyperHtml.d.ts +0 -23
  280. package/dist/hyper/HyperHtml.js +0 -150
  281. package/dist/hyper/HyperHtml.test.d.ts +0 -1
  282. package/dist/hyper/HyperHtml.test.js +0 -197
  283. package/dist/hyper/HyperNode.d.ts +0 -14
  284. package/dist/hyper/HyperNode.js +0 -11
  285. package/dist/hyper/HyperRoute.d.ts +0 -8
  286. package/dist/hyper/HyperRoute.js +0 -32
  287. package/dist/hyper/HyperRoute.test.d.ts +0 -1
  288. package/dist/hyper/HyperRoute.test.js +0 -83
  289. package/dist/hyper/html.d.ts +0 -11
  290. package/dist/hyper/html.js +0 -30
  291. package/dist/hyper/index.d.ts +0 -6
  292. package/dist/hyper/index.js +0 -5
  293. package/dist/hyper/jsx-runtime.d.ts +0 -7
  294. package/dist/hyper/jsx-runtime.js +0 -8
  295. package/dist/index.d.ts +0 -8
  296. package/dist/index.js +0 -8
  297. package/dist/inference_check.d.ts +0 -1
  298. package/dist/inference_check.js +0 -15
  299. package/dist/lint/plugin.d.ts +0 -86
  300. package/dist/lint/plugin.js +0 -341
  301. package/dist/middlewares/BasicAuthMiddleware.d.ts +0 -8
  302. package/dist/middlewares/BasicAuthMiddleware.js +0 -22
  303. package/dist/middlewares/index.d.ts +0 -1
  304. package/dist/middlewares/index.js +0 -1
  305. package/dist/node/Effectify.d.ts +0 -209
  306. package/dist/node/Effectify.js +0 -19
  307. package/dist/node/FileSystem.d.ts +0 -7
  308. package/dist/node/FileSystem.js +0 -420
  309. package/dist/node/NodeFileSystem.d.ts +0 -7
  310. package/dist/node/NodeFileSystem.js +0 -410
  311. package/dist/node/NodeUtils.d.ts +0 -2
  312. package/dist/node/NodeUtils.js +0 -20
  313. package/dist/node/PlatformError.d.ts +0 -46
  314. package/dist/node/PlatformError.js +0 -43
  315. package/dist/node/Utils.d.ts +0 -1
  316. package/dist/node/Utils.js +0 -19
  317. package/dist/repro_fail.d.ts +0 -1
  318. package/dist/repro_fail.js +0 -14
  319. package/dist/sql/bun/index.d.ts +0 -3
  320. package/dist/sql/bun/index.js +0 -75
  321. package/dist/sql/mssql/docker.d.ts +0 -2
  322. package/dist/sql/mssql/docker.js +0 -67
  323. package/dist/sql/mssql/index.d.ts +0 -21
  324. package/dist/sql/mssql/index.js +0 -113
  325. package/dist/testing/TestHttpClient.d.ts +0 -13
  326. package/dist/testing/TestHttpClient.js +0 -68
  327. package/dist/testing/TestLogger.d.ts +0 -13
  328. package/dist/testing/TestLogger.js +0 -32
  329. package/dist/testing/index.d.ts +0 -2
  330. package/dist/testing/index.js +0 -2
  331. package/dist/testing/utils.d.ts +0 -9
  332. package/dist/testing/utils.js +0 -39
  333. package/dist/x/cloudflare/CloudflareTunnel.d.ts +0 -10
  334. package/dist/x/cloudflare/CloudflareTunnel.js +0 -30
  335. package/dist/x/cloudflare/index.d.ts +0 -1
  336. package/dist/x/cloudflare/index.js +0 -1
  337. package/dist/x/datastar/Datastar.d.ts +0 -6
  338. package/dist/x/datastar/Datastar.js +0 -47
  339. package/dist/x/datastar/index.d.ts +0 -1
  340. package/dist/x/datastar/index.js +0 -1
  341. package/dist/x/tailscale/TailscaleTunnel.d.ts +0 -15
  342. package/dist/x/tailscale/TailscaleTunnel.js +0 -68
  343. package/dist/x/tailscale/index.d.ts +0 -1
  344. package/dist/x/tailscale/index.js +0 -1
  345. package/dist/x/tailwind/TailwindPlugin.d.ts +0 -23
  346. package/dist/x/tailwind/TailwindPlugin.js +0 -219
  347. package/dist/x/tailwind/compile.d.ts +0 -19
  348. package/dist/x/tailwind/compile.js +0 -154
  349. package/dist/x/tailwind/plugin.d.ts +0 -2
  350. package/dist/x/tailwind/plugin.js +0 -15
  351. /package/src/{Sql.ts → sql/Sql.ts} +0 -0
@@ -1,410 +0,0 @@
1
- import * as Effect from "effect/Effect";
2
- import * as Function from "effect/Function";
3
- import * as Layer from "effect/Layer";
4
- import * as Option from "effect/Option";
5
- import * as FileSystem from "../FileSystem.js";
6
- import * as Stream from "effect/Stream";
7
- import * as NCrypto from "node:crypto";
8
- import * as NFS from "node:fs";
9
- import * as NOS from "node:os";
10
- import * as NPath from "node:path";
11
- import * as PlatformError from "../PlatformError.js";
12
- import * as Effectify from "../Effectify.js";
13
- const handleBadArgument = (method) => (cause) => new PlatformError.BadArgument({
14
- module: "FileSystem",
15
- method,
16
- cause,
17
- });
18
- const access = (() => {
19
- const nodeAccess = Effectify.effectify(NFS.access, handleErrnoException("FileSystem", "access"), handleBadArgument("access"));
20
- return (path, options) => {
21
- let mode = NFS.constants.F_OK;
22
- if (options?.readable) {
23
- mode |= NFS.constants.R_OK;
24
- }
25
- if (options?.writable) {
26
- mode |= NFS.constants.W_OK;
27
- }
28
- return nodeAccess(path, mode);
29
- };
30
- })();
31
- const copy = (() => {
32
- const nodeCp = Effectify.effectify(NFS.cp, handleErrnoException("FileSystem", "copy"), handleBadArgument("copy"));
33
- return (fromPath, toPath, options) => nodeCp(fromPath, toPath, {
34
- force: options?.overwrite ?? false,
35
- preserveTimestamps: options?.preserveTimestamps ?? false,
36
- recursive: true,
37
- });
38
- })();
39
- const copyFile = (() => {
40
- const nodeCopyFile = Effectify.effectify(NFS.copyFile, handleErrnoException("FileSystem", "copyFile"), handleBadArgument("copyFile"));
41
- return (fromPath, toPath) => nodeCopyFile(fromPath, toPath);
42
- })();
43
- const chmod = (() => {
44
- const nodeChmod = Effectify.effectify(NFS.chmod, handleErrnoException("FileSystem", "chmod"), handleBadArgument("chmod"));
45
- return (path, mode) => nodeChmod(path, mode);
46
- })();
47
- const chown = (() => {
48
- const nodeChown = Effectify.effectify(NFS.chown, handleErrnoException("FileSystem", "chown"), handleBadArgument("chown"));
49
- return (path, uid, gid) => nodeChown(path, uid, gid);
50
- })();
51
- const link = (() => {
52
- const nodeLink = Effectify.effectify(NFS.link, handleErrnoException("FileSystem", "link"), handleBadArgument("link"));
53
- return (existingPath, newPath) => nodeLink(existingPath, newPath);
54
- })();
55
- const makeDirectory = (() => {
56
- const nodeMkdir = Effectify.effectify(NFS.mkdir, handleErrnoException("FileSystem", "makeDirectory"), handleBadArgument("makeDirectory"));
57
- return (path, options) => nodeMkdir(path, {
58
- recursive: options?.recursive ?? false,
59
- mode: options?.mode,
60
- });
61
- })();
62
- const makeTempDirectoryFactory = (method) => {
63
- const nodeMkdtemp = Effectify.effectify(NFS.mkdtemp, handleErrnoException("FileSystem", method), handleBadArgument(method));
64
- return (options) => Effect.suspend(() => {
65
- const prefix = options?.prefix ?? "";
66
- const directory = typeof options?.directory === "string" ? NPath.join(options.directory, ".") : NOS.tmpdir();
67
- return nodeMkdtemp(prefix ? NPath.join(directory, prefix) : directory + "/");
68
- });
69
- };
70
- const makeTempDirectory = makeTempDirectoryFactory("makeTempDirectory");
71
- const removeFactory = (method) => {
72
- const nodeRm = Effectify.effectify(NFS.rm, handleErrnoException("FileSystem", method), handleBadArgument(method));
73
- return (path, options) => nodeRm(path, {
74
- recursive: options?.recursive ?? false,
75
- force: options?.force ?? false,
76
- });
77
- };
78
- const remove = removeFactory("remove");
79
- const makeTempDirectoryScoped = (() => {
80
- const makeDirectory = makeTempDirectoryFactory("makeTempDirectoryScoped");
81
- const removeDirectory = removeFactory("makeTempDirectoryScoped");
82
- return (options) => Effect.acquireRelease(makeDirectory(options), (directory) => Effect.orDie(removeDirectory(directory, { recursive: true })));
83
- })();
84
- const openFactory = (method) => {
85
- const nodeOpen = Effectify.effectify(NFS.open, handleErrnoException("FileSystem", method), handleBadArgument(method));
86
- const nodeClose = Effectify.effectify(NFS.close, handleErrnoException("FileSystem", method), handleBadArgument(method));
87
- return (path, options) => Function.pipe(Effect.acquireRelease(nodeOpen(path, options?.flag ?? "r", options?.mode), (fd) => Effect.orDie(nodeClose(fd))), Effect.map((fd) => makeFile(FileSystem.FileDescriptor(fd), options?.flag?.startsWith("a") ?? false)));
88
- };
89
- const open = openFactory("open");
90
- const makeFile = (() => {
91
- const nodeReadFactory = (method) => Effectify.effectify(NFS.read, handleErrnoException("FileSystem", method), handleBadArgument(method));
92
- const nodeRead = nodeReadFactory("read");
93
- const nodeReadAlloc = nodeReadFactory("readAlloc");
94
- const nodeStat = Effectify.effectify(NFS.fstat, handleErrnoException("FileSystem", "stat"), handleBadArgument("stat"));
95
- const nodeTruncate = Effectify.effectify(NFS.ftruncate, handleErrnoException("FileSystem", "truncate"), handleBadArgument("truncate"));
96
- const nodeSync = Effectify.effectify(NFS.fsync, handleErrnoException("FileSystem", "sync"), handleBadArgument("sync"));
97
- const nodeWriteFactory = (method) => Effectify.effectify(NFS.write, handleErrnoException("FileSystem", method), handleBadArgument(method));
98
- const nodeWrite = nodeWriteFactory("write");
99
- const nodeWriteAll = nodeWriteFactory("writeAll");
100
- class FileImpl {
101
- [FileSystem.FileTypeId];
102
- fd;
103
- append;
104
- semaphore = Effect.unsafeMakeSemaphore(1);
105
- position = 0n;
106
- constructor(fd, append) {
107
- this[FileSystem.FileTypeId] = FileSystem.FileTypeId;
108
- this.fd = fd;
109
- this.append = append;
110
- }
111
- get stat() {
112
- return Effect.map(nodeStat(this.fd), makeFileInfo);
113
- }
114
- get sync() {
115
- return nodeSync(this.fd);
116
- }
117
- seek(offset, from) {
118
- const offsetSize = FileSystem.Size(offset);
119
- return this.semaphore.withPermits(1)(Effect.sync(() => {
120
- if (from === "start") {
121
- this.position = offsetSize;
122
- }
123
- else if (from === "current") {
124
- this.position = this.position + offsetSize;
125
- }
126
- return this.position;
127
- }));
128
- }
129
- read(buffer) {
130
- return this.semaphore.withPermits(1)(Effect.map(Effect.suspend(() => nodeRead(this.fd, {
131
- buffer,
132
- position: this.position,
133
- })), (bytesRead) => {
134
- const sizeRead = FileSystem.Size(bytesRead);
135
- this.position = this.position + sizeRead;
136
- return sizeRead;
137
- }));
138
- }
139
- readAlloc(size) {
140
- const sizeNumber = Number(size);
141
- return this.semaphore.withPermits(1)(Effect.flatMap(Effect.sync(() => Buffer.allocUnsafeSlow(sizeNumber)), (buffer) => Effect.map(nodeReadAlloc(this.fd, {
142
- buffer,
143
- position: this.position,
144
- }), (bytesRead) => {
145
- if (bytesRead === 0) {
146
- return Option.none();
147
- }
148
- this.position = this.position + BigInt(bytesRead);
149
- if (bytesRead === sizeNumber) {
150
- return Option.some(buffer);
151
- }
152
- const dst = Buffer.allocUnsafeSlow(bytesRead);
153
- buffer.copy(dst, 0, 0, bytesRead);
154
- return Option.some(dst);
155
- })));
156
- }
157
- truncate(length) {
158
- return this.semaphore.withPermits(1)(Effect.map(nodeTruncate(this.fd, length ? Number(length) : undefined), () => {
159
- if (!this.append) {
160
- const len = BigInt(length ?? 0);
161
- if (this.position > len) {
162
- this.position = len;
163
- }
164
- }
165
- }));
166
- }
167
- write(buffer) {
168
- return this.semaphore.withPermits(1)(Effect.map(Effect.suspend(() => nodeWrite(this.fd, buffer, undefined, undefined, this.append ? undefined : Number(this.position))), (bytesWritten) => {
169
- const sizeWritten = FileSystem.Size(bytesWritten);
170
- if (!this.append) {
171
- this.position = this.position + sizeWritten;
172
- }
173
- return sizeWritten;
174
- }));
175
- }
176
- writeAllChunk(buffer) {
177
- return Effect.flatMap(Effect.suspend(() => nodeWriteAll(this.fd, buffer, undefined, undefined, this.append ? undefined : Number(this.position))), (bytesWritten) => {
178
- if (bytesWritten === 0) {
179
- return Effect.fail(new PlatformError.SystemError({
180
- module: "FileSystem",
181
- method: "writeAll",
182
- reason: "WriteZero",
183
- pathOrDescriptor: this.fd,
184
- description: "write returned 0 bytes written",
185
- }));
186
- }
187
- if (!this.append) {
188
- this.position = this.position + BigInt(bytesWritten);
189
- }
190
- return bytesWritten < buffer.length
191
- ? this.writeAllChunk(buffer.subarray(bytesWritten))
192
- : Effect.void;
193
- });
194
- }
195
- writeAll(buffer) {
196
- return this.semaphore.withPermits(1)(this.writeAllChunk(buffer));
197
- }
198
- }
199
- return (fd, append) => new FileImpl(fd, append);
200
- })();
201
- const makeTempFileFactory = (method) => {
202
- const makeDirectory = makeTempDirectoryFactory(method);
203
- const open = openFactory(method);
204
- const randomHexString = (bytes) => Effect.sync(() => NCrypto.randomBytes(bytes).toString("hex"));
205
- return (options) => Function.pipe(Effect.zip(makeDirectory(options), randomHexString(6)), Effect.map(([directory, random]) => NPath.join(directory, random + (options?.suffix ?? ""))), Effect.tap((path) => Effect.scoped(open(path, { flag: "w+" }))));
206
- };
207
- const makeTempFile = makeTempFileFactory("makeTempFile");
208
- const makeTempFileScoped = (() => {
209
- const makeFile = makeTempFileFactory("makeTempFileScoped");
210
- const removeDirectory = removeFactory("makeTempFileScoped");
211
- return (options) => Effect.acquireRelease(makeFile(options), (file) => Effect.orDie(removeDirectory(NPath.dirname(file), { recursive: true })));
212
- })();
213
- const readDirectory = (path, options) => Effect.tryPromise({
214
- try: () => NFS.promises.readdir(path, options),
215
- catch: (err) => handleErrnoException("FileSystem", "readDirectory")(err, [path]),
216
- });
217
- const readFile = (path) => Effect.async((resume, signal) => {
218
- try {
219
- NFS.readFile(path, { signal }, (err, data) => {
220
- if (err) {
221
- resume(Effect.fail(handleErrnoException("FileSystem", "readFile")(err, [path])));
222
- }
223
- else {
224
- resume(Effect.succeed(data));
225
- }
226
- });
227
- }
228
- catch (err) {
229
- resume(Effect.fail(handleBadArgument("readFile")(err)));
230
- }
231
- });
232
- const readLink = (() => {
233
- const nodeReadLink = Effectify.effectify(NFS.readlink, handleErrnoException("FileSystem", "readLink"), handleBadArgument("readLink"));
234
- return (path) => nodeReadLink(path);
235
- })();
236
- const realPath = (() => {
237
- const nodeRealPath = Effectify.effectify(NFS.realpath, handleErrnoException("FileSystem", "realPath"), handleBadArgument("realPath"));
238
- return (path) => nodeRealPath(path);
239
- })();
240
- const rename = (() => {
241
- const nodeRename = Effectify.effectify(NFS.rename, handleErrnoException("FileSystem", "rename"), handleBadArgument("rename"));
242
- return (oldPath, newPath) => nodeRename(oldPath, newPath);
243
- })();
244
- const makeFileInfo = (stat) => ({
245
- type: stat.isFile()
246
- ? "File"
247
- : stat.isDirectory()
248
- ? "Directory"
249
- : stat.isSymbolicLink()
250
- ? "SymbolicLink"
251
- : stat.isBlockDevice()
252
- ? "BlockDevice"
253
- : stat.isCharacterDevice()
254
- ? "CharacterDevice"
255
- : stat.isFIFO()
256
- ? "FIFO"
257
- : stat.isSocket()
258
- ? "Socket"
259
- : "Unknown",
260
- mtime: Option.fromNullable(stat.mtime),
261
- atime: Option.fromNullable(stat.atime),
262
- birthtime: Option.fromNullable(stat.birthtime),
263
- dev: stat.dev,
264
- rdev: Option.fromNullable(stat.rdev),
265
- ino: Option.fromNullable(stat.ino),
266
- mode: stat.mode,
267
- nlink: Option.fromNullable(stat.nlink),
268
- uid: Option.fromNullable(stat.uid),
269
- gid: Option.fromNullable(stat.gid),
270
- size: FileSystem.Size(stat.size),
271
- blksize: Option.map(Option.fromNullable(stat.blksize), FileSystem.Size),
272
- blocks: Option.fromNullable(stat.blocks),
273
- });
274
- const stat = (() => {
275
- const nodeStat = Effectify.effectify(NFS.stat, handleErrnoException("FileSystem", "stat"), handleBadArgument("stat"));
276
- return (path) => Effect.map(nodeStat(path), makeFileInfo);
277
- })();
278
- const symlink = (() => {
279
- const nodeSymlink = Effectify.effectify(NFS.symlink, handleErrnoException("FileSystem", "symlink"), handleBadArgument("symlink"));
280
- return (target, path) => nodeSymlink(target, path);
281
- })();
282
- const truncate = (() => {
283
- const nodeTruncate = Effectify.effectify(NFS.truncate, handleErrnoException("FileSystem", "truncate"), handleBadArgument("truncate"));
284
- return (path, length) => nodeTruncate(path, length !== undefined ? Number(length) : undefined);
285
- })();
286
- const utimes = (() => {
287
- const nodeUtimes = Effectify.effectify(NFS.utimes, handleErrnoException("FileSystem", "utime"), handleBadArgument("utime"));
288
- return (path, atime, mtime) => nodeUtimes(path, atime, mtime);
289
- })();
290
- const watchNode = (path, options) => Stream.asyncScoped((emit) => Effect.acquireRelease(Effect.sync(() => {
291
- const watcher = NFS.watch(path, { recursive: options?.recursive }, (event, path) => {
292
- if (!path)
293
- return;
294
- switch (event) {
295
- case "rename": {
296
- emit.fromEffect(Effect.matchEffect(stat(path), {
297
- onSuccess: (_) => Effect.succeed(FileSystem.WatchEventCreate({ path })),
298
- onFailure: (err) => err._tag === "SystemError" && err.reason === "NotFound"
299
- ? Effect.succeed(FileSystem.WatchEventRemove({ path }))
300
- : Effect.fail(err),
301
- }));
302
- return;
303
- }
304
- case "change": {
305
- emit.single(FileSystem.WatchEventUpdate({ path }));
306
- return;
307
- }
308
- }
309
- });
310
- watcher.on("error", (error) => {
311
- emit.fail(new PlatformError.SystemError({
312
- module: "FileSystem",
313
- reason: "Unknown",
314
- method: "watch",
315
- pathOrDescriptor: path,
316
- cause: error,
317
- }));
318
- });
319
- watcher.on("close", () => {
320
- emit.end();
321
- });
322
- return watcher;
323
- }), (watcher) => Effect.sync(() => watcher.close())));
324
- const watch = (backend, path, options) => stat(path).pipe(Effect.map((stat) => backend.pipe(Option.flatMap((_) => _.register(path, stat, options)), Option.getOrElse(() => watchNode(path, options)))), Stream.unwrap);
325
- const writeFile = (path, data, options) => Effect.async((resume, signal) => {
326
- try {
327
- NFS.writeFile(path, data, {
328
- signal,
329
- flag: options?.flag,
330
- mode: options?.mode,
331
- }, (err) => {
332
- if (err) {
333
- resume(Effect.fail(handleErrnoException("FileSystem", "writeFile")(err, [path])));
334
- }
335
- else {
336
- resume(Effect.void);
337
- }
338
- });
339
- }
340
- catch (err) {
341
- resume(Effect.fail(handleBadArgument("writeFile")(err)));
342
- }
343
- });
344
- const make = Effect.map(Effect.serviceOption(FileSystem.WatchBackend), (backend) => FileSystem.make({
345
- access,
346
- chmod,
347
- chown,
348
- copy,
349
- copyFile,
350
- link,
351
- makeDirectory,
352
- makeTempDirectory,
353
- makeTempDirectoryScoped,
354
- makeTempFile,
355
- makeTempFileScoped,
356
- open,
357
- readDirectory,
358
- readFile,
359
- readLink,
360
- realPath,
361
- remove,
362
- rename,
363
- stat,
364
- symlink,
365
- truncate,
366
- utimes,
367
- watch(path, options) {
368
- return watch(backend, path, options);
369
- },
370
- writeFile,
371
- }));
372
- export const layer = Layer.effect(FileSystem.FileSystem, make);
373
- export { PlatformError as Error };
374
- export function handleErrnoException(module, method) {
375
- return function (err, [path]) {
376
- let reason = "Unknown";
377
- switch (err.code) {
378
- case "ENOENT":
379
- reason = "NotFound";
380
- break;
381
- case "EACCES":
382
- reason = "PermissionDenied";
383
- break;
384
- case "EEXIST":
385
- reason = "AlreadyExists";
386
- break;
387
- case "EISDIR":
388
- reason = "BadResource";
389
- break;
390
- case "ENOTDIR":
391
- reason = "BadResource";
392
- break;
393
- case "EBUSY":
394
- reason = "Busy";
395
- break;
396
- case "ELOOP":
397
- reason = "BadResource";
398
- break;
399
- }
400
- return new PlatformError.SystemError({
401
- reason,
402
- module,
403
- method,
404
- pathOrDescriptor: path,
405
- syscall: err.syscall,
406
- description: err.message,
407
- cause: err,
408
- });
409
- };
410
- }
@@ -1,2 +0,0 @@
1
- export declare const getEntrypoint: () => string;
2
- export declare const findClosestPackageJson: (path: string) => Promise<string | undefined>;
@@ -1,20 +0,0 @@
1
- import * as NFS from "node:fs/promises";
2
- import * as NPath from "node:path";
3
- export const getEntrypoint = () => NPath.dirname(process.argv[1]);
4
- export const findClosestPackageJson = async (path) => {
5
- const resolved = NPath.resolve(path);
6
- const stat = await NFS.stat(resolved).catch(() => undefined);
7
- let dir = stat?.isDirectory() ? resolved : NPath.dirname(resolved);
8
- const root = NPath.parse(dir).root;
9
- while (dir !== root) {
10
- const candidate = NPath.join(dir, "package.json");
11
- try {
12
- await NFS.access(candidate);
13
- return candidate;
14
- }
15
- catch {
16
- dir = NPath.dirname(dir);
17
- }
18
- }
19
- return undefined;
20
- };
@@ -1,46 +0,0 @@
1
- import type * as Cause from "effect/Cause";
2
- import * as Schema from "effect/Schema";
3
- import type * as Types from "effect/Types";
4
- import { TypeId as TypeId_ } from "@effect/platform/Error";
5
- export declare const TypeId: typeof TypeId_;
6
- export type TypeId = typeof TypeId;
7
- export declare const isPlatformError: (u: unknown) => u is PlatformError;
8
- export declare const TypeIdError: <const TypeId extends symbol, const Tag extends string>(typeId: TypeId, tag: Tag) => new <A extends Record<string, any>>(args: Types.Simplify<A>) => Cause.YieldableError & Record<TypeId, TypeId> & {
9
- readonly _tag: Tag;
10
- } & Readonly<A>;
11
- export declare const Module: Schema.Literal<["Clipboard", "Command", "FileSystem", "KeyValueStore", "Path", "Stream", "Terminal"]>;
12
- declare const BadArgument_base: Schema.TaggedErrorClass<BadArgument, "BadArgument", {
13
- readonly _tag: Schema.tag<"BadArgument">;
14
- } & {
15
- module: Schema.Literal<["Clipboard", "Command", "FileSystem", "KeyValueStore", "Path", "Stream", "Terminal"]>;
16
- method: typeof Schema.String;
17
- description: Schema.optional<typeof Schema.String>;
18
- cause: Schema.optional<typeof Schema.Defect>;
19
- }>;
20
- export declare class BadArgument extends BadArgument_base {
21
- readonly [TypeId]: typeof TypeId;
22
- get message(): string;
23
- }
24
- export declare const SystemErrorReason: Schema.Literal<["AlreadyExists", "BadResource", "Busy", "InvalidData", "NotFound", "PermissionDenied", "TimedOut", "UnexpectedEof", "Unknown", "WouldBlock", "WriteZero"]>;
25
- export type SystemErrorReason = typeof SystemErrorReason.Type;
26
- declare const SystemError_base: Schema.TaggedErrorClass<SystemError, "SystemError", {
27
- readonly _tag: Schema.tag<"SystemError">;
28
- } & {
29
- reason: Schema.Literal<["AlreadyExists", "BadResource", "Busy", "InvalidData", "NotFound", "PermissionDenied", "TimedOut", "UnexpectedEof", "Unknown", "WouldBlock", "WriteZero"]>;
30
- module: Schema.Literal<["Clipboard", "Command", "FileSystem", "KeyValueStore", "Path", "Stream", "Terminal"]>;
31
- method: typeof Schema.String;
32
- description: Schema.optional<typeof Schema.String>;
33
- syscall: Schema.optional<typeof Schema.String>;
34
- pathOrDescriptor: Schema.optional<Schema.Union<[typeof Schema.String, typeof Schema.Number]>>;
35
- cause: Schema.optional<typeof Schema.Defect>;
36
- }>;
37
- export declare class SystemError extends SystemError_base {
38
- readonly [TypeId]: typeof TypeId;
39
- get message(): string;
40
- }
41
- export type PlatformError = BadArgument | SystemError;
42
- export declare const PlatformError: Schema.Union<[
43
- typeof BadArgument,
44
- typeof SystemError
45
- ]>;
46
- export {};
@@ -1,43 +0,0 @@
1
- import * as Data from "effect/Data";
2
- import * as Predicate from "effect/Predicate";
3
- import * as Schema from "effect/Schema";
4
- import { TypeId as TypeId_ } from "@effect/platform/Error";
5
- export const TypeId = TypeId_;
6
- export const isPlatformError = (u) => Predicate.hasProperty(u, TypeId);
7
- export const TypeIdError = (typeId, tag) => {
8
- class Base extends Data.Error {
9
- _tag = tag;
10
- }
11
- ;
12
- Base.prototype[typeId] = typeId;
13
- Base.prototype.name = tag;
14
- return Base;
15
- };
16
- export const Module = Schema.Literal("Clipboard", "Command", "FileSystem", "KeyValueStore", "Path", "Stream", "Terminal");
17
- export class BadArgument extends Schema.TaggedError("@effect/platform/Error/BadArgument")("BadArgument", {
18
- module: Module,
19
- method: Schema.String,
20
- description: Schema.optional(Schema.String),
21
- cause: Schema.optional(Schema.Defect),
22
- }) {
23
- [TypeId] = TypeId;
24
- get message() {
25
- return `${this.module}.${this.method}${this.description ? `: ${this.description}` : ""}`;
26
- }
27
- }
28
- export const SystemErrorReason = Schema.Literal("AlreadyExists", "BadResource", "Busy", "InvalidData", "NotFound", "PermissionDenied", "TimedOut", "UnexpectedEof", "Unknown", "WouldBlock", "WriteZero");
29
- export class SystemError extends Schema.TaggedError("@effect/platform/Error/SystemError")("SystemError", {
30
- reason: SystemErrorReason,
31
- module: Module,
32
- method: Schema.String,
33
- description: Schema.optional(Schema.String),
34
- syscall: Schema.optional(Schema.String),
35
- pathOrDescriptor: Schema.optional(Schema.Union(Schema.String, Schema.Number)),
36
- cause: Schema.optional(Schema.Defect),
37
- }) {
38
- [TypeId] = TypeId;
39
- get message() {
40
- return `${this.reason}: ${this.module}.${this.method}${this.pathOrDescriptor !== undefined ? ` (${this.pathOrDescriptor})` : ""}${this.description ? `: ${this.description}` : ""}`;
41
- }
42
- }
43
- export const PlatformError = Schema.Union(BadArgument, SystemError);
@@ -1 +0,0 @@
1
- export declare const findClosestPackageJson: (path: string) => Promise<string | undefined>;
@@ -1,19 +0,0 @@
1
- import * as NFS from "node:fs/promises";
2
- import * as NPath from "node:path";
3
- export const findClosestPackageJson = async (path) => {
4
- const resolved = NPath.resolve(path);
5
- const stat = await NFS.stat(resolved).catch(() => undefined);
6
- let dir = stat?.isDirectory() ? resolved : NPath.dirname(resolved);
7
- const root = NPath.parse(dir).root;
8
- while (dir !== root) {
9
- const candidate = NPath.join(dir, "package.json");
10
- try {
11
- await NFS.access(candidate);
12
- return candidate;
13
- }
14
- catch {
15
- dir = NPath.dirname(dir);
16
- }
17
- }
18
- return undefined;
19
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,14 +0,0 @@
1
- import { Context } from "effect";
2
- import * as Route from "./RouteBody";
3
- const ServiceA = Context.GenericTag("ServiceA");
4
- const ServiceB = Context.GenericTag("ServiceB");
5
- // This handler requires BOTH ServiceA and ServiceB.
6
- // In the original type definition, Generator requires all yields to have the same R.
7
- // ServiceA != ServiceB, so this should fail type checking.
8
- const handler = Route.handle(function* () {
9
- yield* ServiceA;
10
- yield* ServiceB;
11
- return "ok";
12
- });
13
- // To avoid unused variable warning
14
- console.log(handler);
@@ -1,3 +0,0 @@
1
- import * as Layer from "effect/Layer";
2
- import * as Sql from "../../Sql.ts";
3
- export declare const layer: (config: ConstructorParameters<typeof Bun.SQL>[0]) => Layer.Layer<Sql.SqlClient, Sql.SqlError>;
@@ -1,75 +0,0 @@
1
- import * as Effect from "effect/Effect";
2
- import * as Exit from "effect/Exit";
3
- import * as FiberRef from "effect/FiberRef";
4
- import * as GlobalValue from "effect/GlobalValue";
5
- import * as Layer from "effect/Layer";
6
- import * as Option from "effect/Option";
7
- import * as Sql from "../../Sql.js";
8
- const errorCode = (error) => {
9
- const e = error;
10
- if (typeof e?.errno === "string")
11
- return e.errno;
12
- return e?.code ?? "UNKNOWN";
13
- };
14
- const wrapError = (error) => new Sql.SqlError({
15
- code: errorCode(error),
16
- message: error instanceof Error ? error.message : String(error),
17
- cause: error,
18
- });
19
- const wrap = (fn) => Effect.tryPromise({ try: () => Promise.resolve(fn()), catch: wrapError });
20
- const makeValues = (obj, ...columns) => {
21
- const items = Array.isArray(obj) ? obj : [obj];
22
- const cols = columns.length > 0 ? columns : Object.keys(items[0]);
23
- return { value: items, columns: cols };
24
- };
25
- const currentTransaction = GlobalValue.globalValue(Symbol.for("effect-start/sql/bun/currentTransaction"), () => FiberRef.unsafeMake(Option.none()));
26
- const makeRun = (bunSql) => (fn) => Effect.flatMap(FiberRef.get(currentTransaction), (txOpt) => wrap(() => fn(Option.isSome(txOpt) ? txOpt.value.conn : bunSql)));
27
- const makeWithTransaction = (bunSql) => (self) => Effect.uninterruptibleMask((restore) => Effect.flatMap(FiberRef.get(currentTransaction), (txOpt) => {
28
- if (Option.isSome(txOpt)) {
29
- const { conn, depth } = txOpt.value;
30
- const name = `sp_${depth}`;
31
- return Effect.gen(function* () {
32
- yield* wrap(() => conn.unsafe(`SAVEPOINT ${name}`));
33
- const exit = yield* Effect.exit(restore(Effect.locally(self, currentTransaction, Option.some({ conn, depth: depth + 1 }))));
34
- if (Exit.isSuccess(exit)) {
35
- yield* wrap(() => conn.unsafe(`RELEASE SAVEPOINT ${name}`));
36
- return exit.value;
37
- }
38
- yield* wrap(() => conn.unsafe(`ROLLBACK TO SAVEPOINT ${name}`)).pipe(Effect.orDie);
39
- return yield* exit;
40
- });
41
- }
42
- const runTx = (conn) => Effect.gen(function* () {
43
- yield* wrap(() => conn.unsafe("BEGIN"));
44
- const exit = yield* Effect.exit(restore(Effect.locally(self, currentTransaction, Option.some({ conn, depth: 1 }))));
45
- if (Exit.isSuccess(exit)) {
46
- yield* wrap(() => conn.unsafe("COMMIT"));
47
- return exit.value;
48
- }
49
- yield* wrap(() => conn.unsafe("ROLLBACK")).pipe(Effect.orDie);
50
- return yield* exit;
51
- });
52
- return Effect.matchEffect(wrap(() => bunSql.reserve()), {
53
- onFailure: () => runTx(bunSql),
54
- onSuccess: (reserved) => Effect.ensuring(runTx(reserved), Effect.sync(() => reserved.release())),
55
- });
56
- }));
57
- export const layer = (config) => Layer.scoped(Sql.SqlClient, Effect.acquireRelease(Effect.try({
58
- try: () => {
59
- const bunSql = new Bun.SQL(config);
60
- const run = makeRun(bunSql);
61
- const use = (fn) => Effect.tryPromise({ try: () => Promise.resolve(fn(bunSql)), catch: wrapError });
62
- return Object.assign((strings, ...values) => run((conn) => conn(strings, ...values)), {
63
- unsafe: (query, values) => run((conn) => conn.unsafe(query, values)),
64
- values: makeValues,
65
- withTransaction: makeWithTransaction(bunSql),
66
- reserve: Effect.acquireRelease(wrap(() => bunSql.reserve()), (reserved) => Effect.sync(() => reserved.release())).pipe(Effect.map((reserved) => Object.assign((strings, ...values) => wrap(() => reserved(strings, ...values)), {
67
- unsafe: (query, values) => wrap(() => reserved.unsafe(query, values)),
68
- values: makeValues,
69
- }))),
70
- close: (options) => use((bunSql) => bunSql.close(options)),
71
- use,
72
- });
73
- },
74
- catch: wrapError,
75
- }), (client) => client.close().pipe(Effect.orDie)));
@@ -1,2 +0,0 @@
1
- export declare const start: () => Promise<void>;
2
- export declare const stop: () => Promise<void>;