effect-start 0.22.0 → 0.23.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 (313) hide show
  1. package/dist/BlobStore.d.ts +80 -0
  2. package/dist/BlobStore.js +19 -0
  3. package/dist/ChildProcess.d.ts +60 -0
  4. package/dist/ChildProcess.js +30 -0
  5. package/dist/Commander.d.ts +3 -6
  6. package/dist/Commander.js +6 -13
  7. package/dist/ContentNegotiation.d.ts +8 -9
  8. package/dist/ContentNegotiation.js +32 -37
  9. package/dist/Cookies.d.ts +47 -0
  10. package/dist/Cookies.js +273 -363
  11. package/dist/Development.d.ts +2 -2
  12. package/dist/Development.js +3 -4
  13. package/dist/Effectify.d.ts +1 -4
  14. package/dist/FilePathPattern.d.ts +3 -3
  15. package/dist/FileRouter.d.ts +5 -8
  16. package/dist/FileRouter.js +9 -10
  17. package/dist/FileRouterCodegen.d.ts +1 -1
  18. package/dist/FileRouterCodegen.js +33 -13
  19. package/dist/FileSystem.d.ts +158 -0
  20. package/dist/FileSystem.js +64 -125
  21. package/dist/Http.js +2 -6
  22. package/dist/PathPattern.d.ts +7 -7
  23. package/dist/PathPattern.js +1 -3
  24. package/dist/PlatformError.d.ts +24 -32
  25. package/dist/PlatformError.js +3 -21
  26. package/dist/PlatformRuntime.js +5 -10
  27. package/dist/Route.d.ts +14 -19
  28. package/dist/Route.js +8 -11
  29. package/dist/RouteBody.d.ts +6 -12
  30. package/dist/RouteBody.js +2 -2
  31. package/dist/RouteError.d.ts +98 -0
  32. package/dist/RouteError.js +55 -0
  33. package/dist/RouteHook.js +6 -11
  34. package/dist/RouteHttp.d.ts +3 -3
  35. package/dist/RouteHttp.js +27 -22
  36. package/dist/RouteMount.d.ts +16 -50
  37. package/dist/RouteMount.js +6 -20
  38. package/dist/RouteSchema.d.ts +22 -1
  39. package/dist/RouteSchema.js +33 -0
  40. package/dist/RouteSse.js +4 -10
  41. package/dist/RouteTree.d.ts +2 -1
  42. package/dist/RouteTree.js +17 -15
  43. package/dist/RouteTrie.d.ts +2 -2
  44. package/dist/RouteTrie.js +4 -9
  45. package/dist/SchemaExtra.d.ts +1 -1
  46. package/dist/Socket.d.ts +27 -0
  47. package/dist/Socket.js +20 -28
  48. package/dist/Sql.d.ts +34 -0
  49. package/dist/Sql.js +5 -0
  50. package/dist/SqlIntrospect.d.ts +91 -0
  51. package/dist/SqlIntrospect.js +466 -0
  52. package/dist/Start.d.ts +4 -6
  53. package/dist/Start.js +10 -2
  54. package/dist/StreamExtra.d.ts +1 -1
  55. package/dist/StreamExtra.js +9 -9
  56. package/dist/System.d.ts +7 -0
  57. package/dist/System.js +22 -0
  58. package/dist/TuplePathPattern.js +55 -50
  59. package/dist/Unique.js +7 -7
  60. package/dist/Values.d.ts +2 -1
  61. package/dist/Values.js +19 -13
  62. package/dist/bun/BunBlobStoreDisk.d.ts +6 -0
  63. package/dist/bun/BunBlobStoreDisk.js +116 -0
  64. package/dist/bun/BunBlobStoreS3.d.ts +11 -0
  65. package/dist/bun/BunBlobStoreS3.js +89 -0
  66. package/dist/bun/BunBlobWatcherDisk.d.ts +6 -0
  67. package/dist/bun/BunBlobWatcherDisk.js +60 -0
  68. package/dist/bun/BunBlobWatcherQueue.d.ts +6 -0
  69. package/dist/bun/BunBlobWatcherQueue.js +17 -0
  70. package/dist/bun/BunBundle.d.ts +5 -6
  71. package/dist/bun/BunBundle.js +7 -15
  72. package/dist/bun/BunChildProcessSpawner.d.ts +3 -0
  73. package/dist/bun/BunChildProcessSpawner.js +103 -0
  74. package/dist/bun/BunImportTrackerPlugin.d.ts +1 -1
  75. package/dist/bun/BunImportTrackerPlugin.js +3 -5
  76. package/dist/bun/BunRoute.d.ts +3 -2
  77. package/dist/bun/BunRoute.js +5 -7
  78. package/dist/bun/BunRuntime.js +1 -1
  79. package/dist/bun/BunServer.d.ts +11 -4
  80. package/dist/bun/BunServer.js +35 -11
  81. package/dist/bun/BunSql.d.ts +4 -0
  82. package/dist/bun/BunSql.js +81 -0
  83. package/dist/bun/_BunEnhancedResolve.d.ts +3 -3
  84. package/dist/bun/_BunEnhancedResolve.js +2 -4
  85. package/dist/bun/index.d.ts +1 -0
  86. package/dist/bun/index.js +1 -0
  87. package/dist/bundler/Bundle.d.ts +2 -1
  88. package/dist/bundler/Bundle.js +1 -1
  89. package/dist/bundler/BundleFiles.d.ts +5 -5
  90. package/dist/bundler/BundleFiles.js +10 -8
  91. package/dist/bundler/BundleRoute.d.ts +27 -0
  92. package/dist/bundler/BundleRoute.js +51 -0
  93. package/dist/client/ScrollState.js +2 -6
  94. package/dist/client/index.js +6 -8
  95. package/dist/console/Console.d.ts +6 -0
  96. package/dist/console/Console.js +26 -0
  97. package/dist/console/ConsoleErrors.d.ts +3 -0
  98. package/dist/console/ConsoleErrors.js +200 -0
  99. package/dist/console/ConsoleLogger.d.ts +3 -0
  100. package/dist/console/ConsoleLogger.js +47 -0
  101. package/dist/console/ConsoleMetrics.d.ts +3 -0
  102. package/dist/console/ConsoleMetrics.js +61 -0
  103. package/dist/console/ConsoleProcess.d.ts +3 -0
  104. package/dist/console/ConsoleProcess.js +49 -0
  105. package/dist/console/ConsoleStore.d.ts +144 -0
  106. package/dist/console/ConsoleStore.js +61 -0
  107. package/dist/console/ConsoleTracer.d.ts +3 -0
  108. package/dist/console/ConsoleTracer.js +94 -0
  109. package/dist/console/Simulation.d.ts +2 -0
  110. package/dist/console/Simulation.js +633 -0
  111. package/dist/console/index.d.ts +3 -0
  112. package/dist/console/index.js +3 -0
  113. package/dist/console/routes/errors/route.d.ts +10 -0
  114. package/dist/console/routes/errors/route.js +47 -0
  115. package/dist/console/routes/fiberDetail.d.ts +16 -0
  116. package/dist/console/routes/fiberDetail.js +38 -0
  117. package/dist/console/routes/fibers/route.d.ts +10 -0
  118. package/dist/console/routes/fibers/route.js +19 -0
  119. package/dist/console/routes/git/route.d.ts +11 -0
  120. package/dist/console/routes/git/route.js +33 -0
  121. package/dist/console/routes/layout.d.ts +9 -0
  122. package/dist/console/routes/layout.js +3 -0
  123. package/dist/console/routes/logs/route.d.ts +10 -0
  124. package/dist/console/routes/logs/route.js +32 -0
  125. package/dist/console/routes/metrics/route.d.ts +10 -0
  126. package/dist/console/routes/metrics/route.js +17 -0
  127. package/dist/console/routes/route.d.ts +6 -0
  128. package/dist/console/routes/route.js +5 -0
  129. package/dist/console/routes/routes/route.d.ts +6 -0
  130. package/dist/console/routes/routes/route.js +20 -0
  131. package/dist/console/routes/services/route.d.ts +6 -0
  132. package/dist/console/routes/services/route.js +12 -0
  133. package/dist/console/routes/system/route.d.ts +10 -0
  134. package/dist/console/routes/system/route.js +18 -0
  135. package/dist/console/routes/traceDetail.d.ts +16 -0
  136. package/dist/console/routes/traceDetail.js +14 -0
  137. package/dist/console/routes/traces/route.d.ts +10 -0
  138. package/dist/console/routes/traces/route.js +39 -0
  139. package/dist/console/routes/tree.d.ts +153 -0
  140. package/dist/console/routes/tree.js +29 -0
  141. package/dist/console/ui/Errors.d.ts +4 -0
  142. package/dist/console/ui/Errors.js +15 -0
  143. package/dist/console/ui/Fibers.d.ts +24 -0
  144. package/dist/console/ui/Fibers.js +121 -0
  145. package/dist/console/ui/Git.d.ts +20 -0
  146. package/dist/console/ui/Git.js +95 -0
  147. package/dist/console/ui/Logs.d.ts +4 -0
  148. package/dist/console/ui/Logs.js +25 -0
  149. package/dist/console/ui/Metrics.d.ts +4 -0
  150. package/dist/console/ui/Metrics.js +26 -0
  151. package/dist/console/ui/Routes.d.ts +8 -0
  152. package/dist/console/ui/Routes.js +70 -0
  153. package/dist/console/ui/Services.d.ts +10 -0
  154. package/dist/console/ui/Services.js +246 -0
  155. package/dist/console/ui/Shell.d.ts +10 -0
  156. package/dist/console/ui/Shell.js +7 -0
  157. package/dist/console/ui/System.d.ts +4 -0
  158. package/dist/console/ui/System.js +35 -0
  159. package/dist/console/ui/Traces.d.ts +12 -0
  160. package/dist/console/ui/Traces.js +179 -0
  161. package/dist/datastar/actions/fetch.d.ts +1 -1
  162. package/dist/datastar/actions/fetch.js +10 -18
  163. package/dist/datastar/actions/peek.js +1 -2
  164. package/dist/datastar/actions/setAll.js +1 -2
  165. package/dist/datastar/actions/toggleAll.js +1 -2
  166. package/dist/datastar/attributes/attr.js +1 -2
  167. package/dist/datastar/attributes/bind.js +10 -18
  168. package/dist/datastar/attributes/class.js +2 -5
  169. package/dist/datastar/attributes/computed.js +2 -3
  170. package/dist/datastar/attributes/effect.js +1 -2
  171. package/dist/datastar/attributes/indicator.js +2 -4
  172. package/dist/datastar/attributes/init.js +2 -3
  173. package/dist/datastar/attributes/jsonSignals.js +1 -2
  174. package/dist/datastar/attributes/on.js +41 -22
  175. package/dist/datastar/attributes/onIntersect.js +2 -3
  176. package/dist/datastar/attributes/onInterval.js +2 -3
  177. package/dist/datastar/attributes/onSignalPatch.js +2 -4
  178. package/dist/datastar/attributes/ref.js +1 -2
  179. package/dist/datastar/attributes/show.js +1 -2
  180. package/dist/datastar/attributes/signals.js +1 -2
  181. package/dist/datastar/attributes/style.js +6 -12
  182. package/dist/datastar/attributes/text.js +1 -2
  183. package/dist/datastar/engine.d.ts +13 -7
  184. package/dist/datastar/engine.js +76 -48
  185. package/dist/datastar/happydom.d.ts +1 -0
  186. package/dist/datastar/happydom.js +8 -0
  187. package/dist/datastar/index.d.ts +1 -1
  188. package/dist/datastar/index.js +1 -1
  189. package/dist/datastar/utils.js +4 -7
  190. package/dist/datastar/watchers/patchElements.js +24 -45
  191. package/dist/datastar/watchers/patchSignals.js +1 -2
  192. package/dist/experimental/EncryptedCookies.d.ts +2 -5
  193. package/dist/experimental/EncryptedCookies.js +17 -48
  194. package/dist/experimental/index.d.ts +0 -1
  195. package/dist/experimental/index.js +0 -1
  196. package/dist/hyper/Hyper.d.ts +2 -9
  197. package/dist/hyper/Hyper.js +1 -12
  198. package/dist/hyper/HyperHtml.d.ts +1 -1
  199. package/dist/hyper/HyperHtml.js +18 -12
  200. package/dist/hyper/HyperHtml.test.d.ts +1 -0
  201. package/dist/hyper/HyperHtml.test.js +197 -0
  202. package/dist/hyper/HyperRoute.test.js +14 -3
  203. package/dist/hyper/html.d.ts +11 -0
  204. package/dist/hyper/html.js +30 -0
  205. package/dist/hyper/index.d.ts +2 -0
  206. package/dist/hyper/index.js +1 -0
  207. package/dist/hyper/jsx-runtime.d.ts +1 -1
  208. package/dist/hyper/jsx-runtime.js +1 -1
  209. package/dist/index.d.ts +1 -0
  210. package/dist/index.js +1 -0
  211. package/dist/lint/plugin.d.ts +86 -0
  212. package/dist/lint/plugin.js +341 -0
  213. package/dist/node/NodeFileSystem.d.ts +2 -2
  214. package/dist/node/NodeFileSystem.js +4 -14
  215. package/dist/sql/bun/index.d.ts +3 -0
  216. package/dist/sql/bun/index.js +75 -0
  217. package/dist/sql/mssql/docker.d.ts +2 -0
  218. package/dist/sql/mssql/docker.js +67 -0
  219. package/dist/sql/mssql/index.d.ts +21 -0
  220. package/dist/sql/mssql/index.js +113 -0
  221. package/dist/testing/TestLogger.js +4 -1
  222. package/dist/testing/index.d.ts +0 -1
  223. package/dist/testing/index.js +0 -1
  224. package/dist/testing/utils.d.ts +3 -3
  225. package/dist/testing/utils.js +4 -4
  226. package/dist/x/cloudflare/CloudflareTunnel.d.ts +2 -5
  227. package/dist/x/cloudflare/CloudflareTunnel.js +14 -27
  228. package/dist/x/datastar/Datastar.d.ts +1 -1
  229. package/dist/x/datastar/Datastar.js +13 -12
  230. package/dist/x/datastar/index.d.ts +1 -2
  231. package/dist/x/datastar/index.js +1 -2
  232. package/dist/x/tailscale/TailscaleTunnel.d.ts +15 -0
  233. package/dist/x/tailscale/TailscaleTunnel.js +68 -0
  234. package/dist/x/tailscale/index.d.ts +1 -0
  235. package/dist/x/tailscale/index.js +1 -0
  236. package/dist/x/tailwind/TailwindPlugin.js +19 -19
  237. package/dist/x/tailwind/compile.d.ts +2 -2
  238. package/dist/x/tailwind/compile.js +2 -4
  239. package/package.json +22 -10
  240. package/src/ChildProcess.ts +145 -0
  241. package/src/PlatformError.ts +27 -50
  242. package/src/Route.ts +2 -2
  243. package/src/RouteError.ts +76 -0
  244. package/src/RouteHttp.ts +13 -5
  245. package/src/RouteSchema.ts +96 -1
  246. package/src/RouteTree.ts +12 -0
  247. package/src/Sql.ts +51 -0
  248. package/src/SqlIntrospect.ts +620 -0
  249. package/src/Start.ts +15 -3
  250. package/src/System.ts +43 -0
  251. package/src/Values.ts +7 -0
  252. package/src/bun/BunChildProcessSpawner.ts +143 -0
  253. package/src/bun/BunRoute.ts +5 -2
  254. package/src/bun/BunServer.ts +22 -1
  255. package/src/bun/index.ts +1 -0
  256. package/src/bundler/BundleRoute.ts +66 -0
  257. package/src/console/Console.ts +42 -0
  258. package/src/console/ConsoleErrors.ts +213 -0
  259. package/src/console/ConsoleLogger.ts +56 -0
  260. package/src/console/ConsoleMetrics.ts +72 -0
  261. package/src/console/ConsoleProcess.ts +59 -0
  262. package/src/console/ConsoleStore.ts +187 -0
  263. package/src/console/ConsoleTracer.ts +107 -0
  264. package/src/console/Simulation.ts +814 -0
  265. package/src/console/console.html +340 -0
  266. package/src/console/index.ts +3 -0
  267. package/src/console/routes/errors/route.tsx +97 -0
  268. package/src/console/routes/fiberDetail.tsx +54 -0
  269. package/src/console/routes/fibers/route.tsx +45 -0
  270. package/src/console/routes/git/route.tsx +64 -0
  271. package/src/console/routes/layout.tsx +4 -0
  272. package/src/console/routes/logs/route.tsx +77 -0
  273. package/src/console/routes/metrics/route.tsx +36 -0
  274. package/src/console/routes/route.tsx +8 -0
  275. package/src/console/routes/routes/route.tsx +30 -0
  276. package/src/console/routes/services/route.tsx +21 -0
  277. package/src/console/routes/system/route.tsx +43 -0
  278. package/src/console/routes/traceDetail.tsx +22 -0
  279. package/src/console/routes/traces/route.tsx +81 -0
  280. package/src/console/routes/tree.ts +30 -0
  281. package/src/console/ui/Errors.tsx +76 -0
  282. package/src/console/ui/Fibers.tsx +321 -0
  283. package/src/console/ui/Git.tsx +182 -0
  284. package/src/console/ui/Logs.tsx +46 -0
  285. package/src/console/ui/Metrics.tsx +78 -0
  286. package/src/console/ui/Routes.tsx +125 -0
  287. package/src/console/ui/Services.tsx +273 -0
  288. package/src/console/ui/Shell.tsx +62 -0
  289. package/src/console/ui/System.tsx +131 -0
  290. package/src/console/ui/Traces.tsx +426 -0
  291. package/src/datastar/README.md +6 -1
  292. package/src/datastar/actions/fetch.ts +0 -1
  293. package/src/datastar/attributes/on.ts +40 -20
  294. package/src/datastar/engine.ts +51 -0
  295. package/src/datastar/jsx.d.ts +79 -0
  296. package/src/hyper/Hyper.ts +1 -16
  297. package/src/hyper/HyperHtml.ts +6 -4
  298. package/src/hyper/HyperRoute.ts +2 -1
  299. package/src/hyper/html.ts +47 -0
  300. package/src/hyper/index.ts +2 -0
  301. package/src/hyper/jsx.d.ts +5 -3
  302. package/src/index.ts +1 -0
  303. package/src/lint/plugin.js +129 -0
  304. package/src/sql/bun/index.ts +147 -0
  305. package/src/sql/mssql/docker.ts +117 -0
  306. package/src/sql/mssql/index.ts +223 -0
  307. package/src/sql/mssql/mssql.d.ts +41 -0
  308. package/src/x/cloudflare/CloudflareTunnel.ts +8 -36
  309. package/src/x/tailscale/TailscaleTunnel.ts +113 -0
  310. package/src/x/tailscale/index.ts +1 -0
  311. package/src/x/datastar/Datastar.ts +0 -61
  312. package/src/x/datastar/index.ts +0 -2
  313. package/src/x/datastar/jsx-datastar.d.ts +0 -60
@@ -1,4 +1,4 @@
1
- import * as FileSystem from "@effect/platform/FileSystem";
1
+ import * as FileSystem from "./FileSystem.js";
2
2
  import * as Context from "effect/Context";
3
3
  import * as Effect from "effect/Effect";
4
4
  import * as Function from "effect/Function";
@@ -28,15 +28,14 @@ export const filterDirectory = (event) => {
28
28
  export const watchSource = (opts) => {
29
29
  const baseDir = opts?.path ?? process.cwd();
30
30
  const customFilter = opts?.filter;
31
- return Function.pipe(Stream.unwrap(Effect.map(FileSystem.FileSystem, fs => fs.watch(baseDir, { recursive: opts?.recursive ?? true }))), customFilter ? Stream.filter(customFilter) : Function.identity, Stream.rechunk(1), Stream.throttle({
31
+ return Function.pipe(Stream.unwrap(Effect.map(FileSystem.FileSystem, (fs) => fs.watch(baseDir, { recursive: opts?.recursive ?? true }))), customFilter ? Stream.filter(customFilter) : Function.identity, Stream.rechunk(1), Stream.throttle({
32
32
  units: 1,
33
33
  cost: () => 1,
34
34
  duration: "400 millis",
35
35
  strategy: "enforce",
36
36
  }));
37
37
  };
38
- export const watch = (opts) => Effect
39
- .gen(function* () {
38
+ export const watch = (opts) => Effect.gen(function* () {
40
39
  devState.count++;
41
40
  if (devState.count === 1) {
42
41
  const pubsub = yield* PubSub.unbounded();
@@ -2,10 +2,7 @@ import * as Effect from "effect/Effect";
2
2
  interface Callback<E, A> {
3
3
  (err: E, a?: A): void;
4
4
  }
5
- type ArgsWithCallback<Args extends Array<any>, E, A> = [
6
- ...args: Args,
7
- cb: Callback<E, A>
8
- ];
5
+ type ArgsWithCallback<Args extends Array<any>, E, A> = [...args: Args, cb: Callback<E, A>];
9
6
  type WithoutNull<A> = unknown extends A ? void : Exclude<A, null | undefined>;
10
7
  type Effectify<T, E> = T extends {
11
8
  (...args: ArgsWithCallback<infer Args1, infer _E1, infer A1>): infer _R1;
@@ -17,13 +17,13 @@ export type Segment = {
17
17
  _tag: "InvalidSegment";
18
18
  value: string;
19
19
  };
20
- export declare function segments(pattern: string): Segment[];
20
+ export declare function segments(pattern: string): Array<Segment>;
21
21
  export type ValidationError = {
22
22
  _tag: "FilePathPatternError";
23
23
  pattern: string;
24
24
  message: string;
25
25
  };
26
- export type ValidationResult = Either.Either<Segment[], ValidationError>;
26
+ export type ValidationResult = Either.Either<Array<Segment>, ValidationError>;
27
27
  export declare function validate(pattern: string): ValidationResult;
28
- export declare function format(segs: Segment[]): `/${string}`;
28
+ export declare function format(segs: Array<Segment>): `/${string}`;
29
29
  export declare function toPathPattern(pattern: string): Either.Either<PathPattern.PathPattern, ValidationError>;
@@ -1,4 +1,4 @@
1
- import * as FileSystem from "@effect/platform/FileSystem";
1
+ import * as FileSystem from "./FileSystem.ts";
2
2
  import * as Effect from "effect/Effect";
3
3
  import * as Layer from "effect/Layer";
4
4
  import * as FilePathPattern from "./FilePathPattern.ts";
@@ -20,17 +20,14 @@ export type RouteModule = {
20
20
  };
21
21
  export type LazyRouteModule = () => Promise<RouteModule>;
22
22
  export type FileRoutes = {
23
- [path: PathPattern.PathPattern]: [
24
- LazyRouteModule,
25
- ...LazyRouteModule[]
26
- ];
23
+ [path: PathPattern.PathPattern]: [LazyRouteModule, ...LazyRouteModule[]];
27
24
  };
28
25
  export type Segment = FilePathPattern.Segment;
29
26
  export type FileRoute = {
30
27
  handle: "route" | "layer";
31
28
  modulePath: `/${string}`;
32
29
  routePath: `/${string}`;
33
- segments: Segment[];
30
+ segments: Array<Segment>;
34
31
  };
35
32
  /**
36
33
  * Routes sorted by depth, with rest parameters at the end.
@@ -39,7 +36,7 @@ export type FileRoute = {
39
36
  * - users/[userId]/route.tsx
40
37
  * - [[rest]]/route.tsx
41
38
  */
42
- export type OrderedFileRoutes = FileRoute[];
39
+ export type OrderedFileRoutes = Array<FileRoute>;
43
40
  export declare function parseRoute(path: string): FileRoute | null;
44
41
  /**
45
42
  * Generates a tree file that references all routes.
@@ -55,5 +52,5 @@ export declare function layer(options: {
55
52
  }): Layer.Layer<Route.Routes, FileRouterError, FileSystem.FileSystem>;
56
53
  export declare function fromFileRoutes(fileRoutes: FileRoutes): Effect.Effect<RouteTree.RouteTree>;
57
54
  export declare function walkRoutesDirectory(dir: string): Effect.Effect<OrderedFileRoutes, PlatformError.PlatformError | FileRouterError, FileSystem.FileSystem>;
58
- export declare function getFileRoutes(paths: string[]): Effect.Effect<OrderedFileRoutes, FileRouterError>;
55
+ export declare function getFileRoutes(paths: Array<string>): Effect.Effect<OrderedFileRoutes, FileRouterError>;
59
56
  export {};
@@ -1,4 +1,4 @@
1
- import * as FileSystem from "@effect/platform/FileSystem";
1
+ import * as FileSystem from "./FileSystem.js";
2
2
  import * as Data from "effect/Data";
3
3
  import * as Effect from "effect/Effect";
4
4
  import * as Either from "effect/Either";
@@ -19,8 +19,7 @@ const ROUTE_PATH_REGEX = /^\/?(.*\/?)(?:route|layer)\.(jsx?|tsx?)$/;
19
19
  export function parseRoute(path) {
20
20
  const segs = FilePathPattern.segments(path);
21
21
  const lastSeg = segs.at(-1);
22
- const handleMatch = lastSeg?._tag === "LiteralSegment"
23
- && lastSeg.value.match(/^(route|layer)\.(tsx?|jsx?)$/);
22
+ const handleMatch = lastSeg?._tag === "LiteralSegment" && lastSeg.value.match(/^(route|layer)\.(tsx?|jsx?)$/);
24
23
  const handle = handleMatch ? handleMatch[1] : null;
25
24
  if (!handle) {
26
25
  return null;
@@ -73,7 +72,7 @@ export function layer(loadOrOptions) {
73
72
  const m = yield* importModule(options.load);
74
73
  const routeTree = yield* fromFileRoutes(m.default);
75
74
  // Watch for changes (only when Development service is available)
76
- yield* Function.pipe(Development.stream(), Stream.filter(e => e._tag !== "Reload" && e.path.startsWith(relativeRoutesPath)), Stream.runForEach(() => FileRouterCodegen.update(routesPath, treeFilename)), Effect.fork);
75
+ yield* Function.pipe(Development.stream(), Stream.filter((e) => e._tag !== "Reload" && e.path.startsWith(relativeRoutesPath)), Stream.runForEach(() => FileRouterCodegen.update(routesPath, treeFilename)), Effect.fork);
77
76
  return routeTree;
78
77
  }));
79
78
  }
@@ -106,9 +105,9 @@ export function walkRoutesDirectory(dir) {
106
105
  export function getFileRoutes(paths) {
107
106
  return Effect.gen(function* () {
108
107
  const routes = paths
109
- .map(f => f.match(ROUTE_PATH_REGEX))
108
+ .map((f) => f.match(ROUTE_PATH_REGEX))
110
109
  .filter(Boolean)
111
- .map(v => {
110
+ .map((v) => {
112
111
  const path = v[0];
113
112
  try {
114
113
  return parseRoute(path);
@@ -125,11 +124,11 @@ export function getFileRoutes(paths) {
125
124
  const bHasRest = b.segments.some((seg) => seg._tag === "RestSegment");
126
125
  return (
127
126
  // rest is a dominant factor (routes with rest come last)
128
- (+aHasRest - +bHasRest) * 1000
127
+ (+aHasRest - +bHasRest) * 1000 +
129
128
  // depth is reversed for rest
130
- + (aDepth - bDepth) * (1 - 2 * +aHasRest)
129
+ (aDepth - bDepth) * (1 - 2 * +aHasRest) +
131
130
  // lexicographic comparison as tiebreaker
132
- + a.modulePath.localeCompare(b.modulePath) * 0.001);
131
+ a.modulePath.localeCompare(b.modulePath) * 0.001);
133
132
  });
134
133
  // Detect conflicting routes at the same path
135
134
  const routesByPath = new Map();
@@ -139,7 +138,7 @@ export function getFileRoutes(paths) {
139
138
  routesByPath.set(route.routePath, existing);
140
139
  }
141
140
  for (const [path, pathRoutes] of routesByPath) {
142
- const routeHandles = pathRoutes.filter(h => h.handle === "route");
141
+ const routeHandles = pathRoutes.filter((h) => h.handle === "route");
143
142
  if (routeHandles.length > 1) {
144
143
  yield* new FileRouterError({ reason: "Conflict", path });
145
144
  }
@@ -1,4 +1,4 @@
1
- import * as FileSystem from "@effect/platform/FileSystem";
1
+ import * as FileSystem from "./FileSystem.ts";
2
2
  import * as Effect from "effect/Effect";
3
3
  import * as Schema from "effect/Schema";
4
4
  import * as FilePathPattern from "./FilePathPattern.ts";
@@ -6,7 +6,7 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
6
6
  }
7
7
  return path;
8
8
  };
9
- import * as FileSystem from "@effect/platform/FileSystem";
9
+ import * as FileSystem from "./FileSystem.js";
10
10
  import * as Effect from "effect/Effect";
11
11
  import * as Either from "effect/Either";
12
12
  import * as Schema from "effect/Schema";
@@ -45,11 +45,13 @@ export function generatePathParamsSchema(segments) {
45
45
  export function validateRouteModules(path, routes) {
46
46
  return Effect.gen(function* () {
47
47
  const fs = yield* FileSystem.FileSystem;
48
- const routeHandles = routes.filter(h => h.handle === "route");
48
+ const routeHandles = routes.filter((h) => h.handle === "route");
49
49
  for (const handle of routeHandles) {
50
50
  const routeModulePath = NPath.resolve(path, handle.modulePath);
51
51
  const expectedSchema = generatePathParamsSchema(handle.segments);
52
- const fileExists = yield* fs.exists(routeModulePath).pipe(Effect.catchAll(() => Effect.succeed(false)));
52
+ const fileExists = yield* fs
53
+ .exists(routeModulePath)
54
+ .pipe(Effect.catchAll(() => Effect.succeed(false)));
53
55
  if (!fileExists) {
54
56
  continue;
55
57
  }
@@ -68,9 +70,7 @@ export function validateRouteModules(path, routes) {
68
70
  const routeSet = module.default;
69
71
  // extract user schema
70
72
  const userSchema = undefined;
71
- if (expectedSchema
72
- && userSchema
73
- && !SchemaExtra.schemaEqual(userSchema, expectedSchema)) {
73
+ if (expectedSchema && userSchema && !SchemaExtra.schemaEqual(userSchema, expectedSchema)) {
74
74
  const relativeFilePath = NPath.relative(process.cwd(), routeModulePath);
75
75
  yield* Effect.logError(`Route '${relativeFilePath}' has incorrect PathParams schema, expected schemaPathParams(${SchemaExtra.formatSchemaCode(expectedSchema)})`);
76
76
  }
@@ -108,7 +108,7 @@ export function generateCode(fileRoutes) {
108
108
  while (true) {
109
109
  const pathData = routesByPath.get(currentPath);
110
110
  if (pathData?.layers) {
111
- const matchingLayers = pathData.layers.filter(layer => layerMatchesRoute(layer, route));
111
+ const matchingLayers = pathData.layers.filter((layer) => layerMatchesRoute(layer, route));
112
112
  allLayers.unshift(...matchingLayers);
113
113
  }
114
114
  if (currentPath === "/")
@@ -125,7 +125,7 @@ export function generateCode(fileRoutes) {
125
125
  // Order: route first, then layers from innermost to outermost
126
126
  const loaders = [
127
127
  `() => import(".${route.modulePath}")`,
128
- ...allLayers.reverse().map(layer => `() => import(".${layer.modulePath}")`),
128
+ ...allLayers.reverse().map((layer) => `() => import(".${layer.modulePath}")`),
129
129
  ];
130
130
  entries.push({ path: pathPattern, loaders });
131
131
  }
@@ -156,7 +156,11 @@ export function update(routesPath, treePath = "server.gen.ts") {
156
156
  return Effect.gen(function* () {
157
157
  treePath = NPath.resolve(routesPath, treePath);
158
158
  const fs = yield* FileSystem.FileSystem;
159
- const files = yield* fs.readDirectory(routesPath, { recursive: true }).pipe(Effect.mapError((cause) => new FileRouter.FileRouterError({ reason: "FileSystem", cause, path: routesPath })));
159
+ const files = yield* fs.readDirectory(routesPath, { recursive: true }).pipe(Effect.mapError((cause) => new FileRouter.FileRouterError({
160
+ reason: "FileSystem",
161
+ cause,
162
+ path: routesPath,
163
+ })));
160
164
  const fileRoutes = yield* FileRouter.getFileRoutes(files);
161
165
  // Validate route modules
162
166
  yield* validateRouteModules(routesPath, fileRoutes);
@@ -172,7 +176,11 @@ export function update(routesPath, treePath = "server.gen.ts") {
172
176
  const emptyCode = "export default {}\n";
173
177
  if (existingCode !== emptyCode) {
174
178
  yield* Effect.logDebug(`Clearing file routes tree: ${treePath}`);
175
- yield* fs.writeFileString(treePath, emptyCode).pipe(Effect.mapError((cause) => new FileRouter.FileRouterError({ reason: "FileSystem", cause, path: treePath })));
179
+ yield* fs.writeFileString(treePath, emptyCode).pipe(Effect.mapError((cause) => new FileRouter.FileRouterError({
180
+ reason: "FileSystem",
181
+ cause,
182
+ path: treePath,
183
+ })));
176
184
  }
177
185
  }
178
186
  return;
@@ -180,7 +188,11 @@ export function update(routesPath, treePath = "server.gen.ts") {
180
188
  // Write if content differs
181
189
  if (existingCode !== newCode) {
182
190
  yield* Effect.logDebug(`Updating file routes tree: ${treePath}`);
183
- yield* fs.writeFileString(treePath, newCode).pipe(Effect.mapError((cause) => new FileRouter.FileRouterError({ reason: "FileSystem", cause, path: treePath })));
191
+ yield* fs.writeFileString(treePath, newCode).pipe(Effect.mapError((cause) => new FileRouter.FileRouterError({
192
+ reason: "FileSystem",
193
+ cause,
194
+ path: treePath,
195
+ })));
184
196
  }
185
197
  else {
186
198
  yield* Effect.logDebug(`File routes tree unchanged: ${treePath}`);
@@ -191,7 +203,11 @@ export function dump(routesPath, treePath = "server.gen.ts") {
191
203
  return Effect.gen(function* () {
192
204
  treePath = NPath.resolve(routesPath, treePath);
193
205
  const fs = yield* FileSystem.FileSystem;
194
- const files = yield* fs.readDirectory(routesPath, { recursive: true }).pipe(Effect.mapError((cause) => new FileRouter.FileRouterError({ reason: "FileSystem", cause, path: routesPath })));
206
+ const files = yield* fs.readDirectory(routesPath, { recursive: true }).pipe(Effect.mapError((cause) => new FileRouter.FileRouterError({
207
+ reason: "FileSystem",
208
+ cause,
209
+ path: routesPath,
210
+ })));
195
211
  const fileRoutes = yield* FileRouter.getFileRoutes(files);
196
212
  // Validate route modules
197
213
  yield* validateRouteModules(routesPath, fileRoutes);
@@ -202,6 +218,10 @@ export function dump(routesPath, treePath = "server.gen.ts") {
202
218
  return;
203
219
  }
204
220
  yield* Effect.logDebug(`Generating file routes tree: ${treePath}`);
205
- yield* fs.writeFileString(treePath, code).pipe(Effect.mapError((cause) => new FileRouter.FileRouterError({ reason: "FileSystem", cause, path: treePath })));
221
+ yield* fs.writeFileString(treePath, code).pipe(Effect.mapError((cause) => new FileRouter.FileRouterError({
222
+ reason: "FileSystem",
223
+ cause,
224
+ path: treePath,
225
+ })));
206
226
  });
207
227
  }
@@ -0,0 +1,158 @@
1
+ import * as Brand from "effect/Brand";
2
+ import * as Context from "effect/Context";
3
+ import * as Data from "effect/Data";
4
+ import * as Effect from "effect/Effect";
5
+ import * as Option from "effect/Option";
6
+ import * as Sink from "effect/Sink";
7
+ import type * as Scope from "effect/Scope";
8
+ import * as Stream from "effect/Stream";
9
+ import * as PlatformError from "./PlatformError.ts";
10
+ export interface FileSystem {
11
+ readonly access: (path: string, options?: AccessFileOptions) => Effect.Effect<void, PlatformError.PlatformError>;
12
+ readonly copy: (fromPath: string, toPath: string, options?: CopyOptions) => Effect.Effect<void, PlatformError.PlatformError>;
13
+ readonly copyFile: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError.PlatformError>;
14
+ readonly chmod: (path: string, mode: number) => Effect.Effect<void, PlatformError.PlatformError>;
15
+ readonly chown: (path: string, uid: number, gid: number) => Effect.Effect<void, PlatformError.PlatformError>;
16
+ readonly exists: (path: string) => Effect.Effect<boolean, PlatformError.PlatformError>;
17
+ readonly link: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError.PlatformError>;
18
+ readonly makeDirectory: (path: string, options?: MakeDirectoryOptions) => Effect.Effect<void, PlatformError.PlatformError>;
19
+ readonly makeTempDirectory: (options?: MakeTempDirectoryOptions) => Effect.Effect<string, PlatformError.PlatformError>;
20
+ readonly makeTempDirectoryScoped: (options?: MakeTempDirectoryOptions) => Effect.Effect<string, PlatformError.PlatformError, Scope.Scope>;
21
+ readonly makeTempFile: (options?: MakeTempFileOptions) => Effect.Effect<string, PlatformError.PlatformError>;
22
+ readonly makeTempFileScoped: (options?: MakeTempFileOptions) => Effect.Effect<string, PlatformError.PlatformError, Scope.Scope>;
23
+ readonly open: (path: string, options?: OpenFileOptions) => Effect.Effect<File, PlatformError.PlatformError, Scope.Scope>;
24
+ readonly readDirectory: (path: string, options?: ReadDirectoryOptions) => Effect.Effect<Array<string>, PlatformError.PlatformError>;
25
+ readonly readFile: (path: string) => Effect.Effect<Uint8Array, PlatformError.PlatformError>;
26
+ readonly readFileString: (path: string, encoding?: string) => Effect.Effect<string, PlatformError.PlatformError>;
27
+ readonly readLink: (path: string) => Effect.Effect<string, PlatformError.PlatformError>;
28
+ readonly realPath: (path: string) => Effect.Effect<string, PlatformError.PlatformError>;
29
+ readonly remove: (path: string, options?: RemoveOptions) => Effect.Effect<void, PlatformError.PlatformError>;
30
+ readonly rename: (oldPath: string, newPath: string) => Effect.Effect<void, PlatformError.PlatformError>;
31
+ readonly sink: (path: string, options?: SinkOptions) => Sink.Sink<void, Uint8Array, never, PlatformError.PlatformError>;
32
+ readonly stat: (path: string) => Effect.Effect<File.Info, PlatformError.PlatformError>;
33
+ readonly stream: (path: string, options?: StreamOptions) => Stream.Stream<Uint8Array, PlatformError.PlatformError>;
34
+ readonly symlink: (fromPath: string, toPath: string) => Effect.Effect<void, PlatformError.PlatformError>;
35
+ readonly truncate: (path: string, length?: SizeInput) => Effect.Effect<void, PlatformError.PlatformError>;
36
+ readonly utimes: (path: string, atime: Date | number, mtime: Date | number) => Effect.Effect<void, PlatformError.PlatformError>;
37
+ readonly watch: (path: string, options?: WatchOptions) => Stream.Stream<WatchEvent, PlatformError.PlatformError>;
38
+ readonly writeFile: (path: string, data: Uint8Array, options?: WriteFileOptions) => Effect.Effect<void, PlatformError.PlatformError>;
39
+ readonly writeFileString: (path: string, data: string, options?: WriteFileStringOptions) => Effect.Effect<void, PlatformError.PlatformError>;
40
+ }
41
+ export declare const FileSystem: Context.Tag<FileSystem, FileSystem>;
42
+ export type Size = Brand.Branded<bigint, "Size">;
43
+ export type SizeInput = bigint | number | Size;
44
+ export declare const Size: (bytes: SizeInput) => Size;
45
+ export type OpenFlag = "r" | "r+" | "w" | "wx" | "w+" | "wx+" | "a" | "ax" | "a+" | "ax+";
46
+ export type SeekMode = "start" | "current";
47
+ export interface AccessFileOptions {
48
+ readonly ok?: boolean;
49
+ readonly readable?: boolean;
50
+ readonly writable?: boolean;
51
+ }
52
+ export interface MakeDirectoryOptions {
53
+ readonly recursive?: boolean;
54
+ readonly mode?: number;
55
+ }
56
+ export interface CopyOptions {
57
+ readonly overwrite?: boolean;
58
+ readonly preserveTimestamps?: boolean;
59
+ }
60
+ export interface MakeTempDirectoryOptions {
61
+ readonly directory?: string;
62
+ readonly prefix?: string;
63
+ }
64
+ export interface MakeTempFileOptions {
65
+ readonly directory?: string;
66
+ readonly prefix?: string;
67
+ readonly suffix?: string;
68
+ }
69
+ export interface OpenFileOptions {
70
+ readonly flag?: OpenFlag;
71
+ readonly mode?: number;
72
+ }
73
+ export interface ReadDirectoryOptions {
74
+ readonly recursive?: boolean;
75
+ }
76
+ export interface RemoveOptions {
77
+ readonly recursive?: boolean;
78
+ readonly force?: boolean;
79
+ }
80
+ export interface SinkOptions extends OpenFileOptions {
81
+ }
82
+ export interface StreamOptions {
83
+ readonly bufferSize?: number;
84
+ readonly bytesToRead?: SizeInput;
85
+ readonly chunkSize?: SizeInput;
86
+ readonly offset?: SizeInput;
87
+ }
88
+ export interface WriteFileOptions {
89
+ readonly flag?: OpenFlag;
90
+ readonly mode?: number;
91
+ }
92
+ export interface WriteFileStringOptions {
93
+ readonly flag?: OpenFlag;
94
+ readonly mode?: number;
95
+ }
96
+ export interface WatchOptions {
97
+ readonly recursive?: boolean;
98
+ }
99
+ export declare const FileTypeId: unique symbol;
100
+ export type FileTypeId = typeof FileTypeId;
101
+ export interface File {
102
+ readonly [FileTypeId]: FileTypeId;
103
+ readonly fd: File.Descriptor;
104
+ readonly stat: Effect.Effect<File.Info, PlatformError.PlatformError>;
105
+ readonly seek: (offset: SizeInput, from: SeekMode) => Effect.Effect<void>;
106
+ readonly sync: Effect.Effect<void, PlatformError.PlatformError>;
107
+ readonly read: (buffer: Uint8Array) => Effect.Effect<Size, PlatformError.PlatformError>;
108
+ readonly readAlloc: (size: SizeInput) => Effect.Effect<Option.Option<Uint8Array>, PlatformError.PlatformError>;
109
+ readonly truncate: (length?: SizeInput) => Effect.Effect<void, PlatformError.PlatformError>;
110
+ readonly write: (buffer: Uint8Array) => Effect.Effect<Size, PlatformError.PlatformError>;
111
+ readonly writeAll: (buffer: Uint8Array) => Effect.Effect<void, PlatformError.PlatformError>;
112
+ }
113
+ export declare namespace File {
114
+ type Descriptor = Brand.Branded<number, "FileDescriptor">;
115
+ type Type = "File" | "Directory" | "SymbolicLink" | "BlockDevice" | "CharacterDevice" | "FIFO" | "Socket" | "Unknown";
116
+ interface Info {
117
+ readonly type: Type;
118
+ readonly mtime: Option.Option<Date>;
119
+ readonly atime: Option.Option<Date>;
120
+ readonly birthtime: Option.Option<Date>;
121
+ readonly dev: number;
122
+ readonly ino: Option.Option<number>;
123
+ readonly mode: number;
124
+ readonly nlink: Option.Option<number>;
125
+ readonly uid: Option.Option<number>;
126
+ readonly gid: Option.Option<number>;
127
+ readonly rdev: Option.Option<number>;
128
+ readonly size: Size;
129
+ readonly blksize: Option.Option<Size>;
130
+ readonly blocks: Option.Option<number>;
131
+ }
132
+ }
133
+ export declare const FileDescriptor: Brand.Brand.Constructor<File.Descriptor>;
134
+ export type WatchEvent = WatchEvent.Create | WatchEvent.Update | WatchEvent.Remove;
135
+ export declare namespace WatchEvent {
136
+ interface Create {
137
+ readonly _tag: "Create";
138
+ readonly path: string;
139
+ }
140
+ interface Update {
141
+ readonly _tag: "Update";
142
+ readonly path: string;
143
+ }
144
+ interface Remove {
145
+ readonly _tag: "Remove";
146
+ readonly path: string;
147
+ }
148
+ }
149
+ export declare const WatchEventCreate: Data.Case.Constructor<WatchEvent.Create, "_tag">;
150
+ export declare const WatchEventUpdate: Data.Case.Constructor<WatchEvent.Update, "_tag">;
151
+ export declare const WatchEventRemove: Data.Case.Constructor<WatchEvent.Remove, "_tag">;
152
+ declare const WatchBackend_base: Context.TagClass<WatchBackend, "@effect/platform/FileSystem/WatchBackend", {
153
+ readonly register: (path: string, stat: File.Info, options?: WatchOptions) => Option.Option<Stream.Stream<WatchEvent, PlatformError.PlatformError>>;
154
+ }>;
155
+ export declare class WatchBackend extends WatchBackend_base {
156
+ }
157
+ export declare const make: (impl: Omit<FileSystem, "exists" | "readFileString" | "stream" | "sink" | "writeFileString">) => FileSystem;
158
+ export {};
@@ -1,131 +1,70 @@
1
1
  /*
2
2
  * Adapted from @effect/platform
3
3
  */
4
- import * as Brand from "effect/Brand"
5
- import * as Channel from "effect/Channel"
6
- import * as Chunk from "effect/Chunk"
7
- import * as Context from "effect/Context"
8
- import * as Data from "effect/Data"
9
- import * as Effect from "effect/Effect"
10
- import * as Function from "effect/Function"
11
- import * as Option from "effect/Option"
12
- import * as Sink from "effect/Sink"
13
- import * as Stream from "effect/Stream"
14
- import * as PlatformError from "./PlatformError.js"
15
-
16
- export const FileSystem = Context.GenericTag(
17
- "@effect/platform/FileSystem",
18
- )
19
-
20
- export const Size = (bytes) =>
21
- typeof bytes === "bigint" ? bytes : BigInt(bytes)
22
-
23
- export const FileTypeId = Symbol.for("@effect/platform/FileSystem/File")
24
-
25
- export const FileDescriptor = Brand.nominal()
26
-
27
- export const WatchEventCreate = Data.tagged(
28
- "Create",
29
- )
30
-
31
- export const WatchEventUpdate = Data.tagged(
32
- "Update",
33
- )
34
-
35
- export const WatchEventRemove = Data.tagged(
36
- "Remove",
37
- )
38
-
39
- export class WatchBackend extends Context.Tag("@effect/platform/FileSystem/WatchBackend")() {}
40
-
41
- export const make = (
42
- impl,
43
- ) => {
44
- return FileSystem.of({
45
- ...impl,
46
- exists: (path) =>
47
- Function.pipe(
48
- impl.access(path),
49
- Effect.as(true),
50
- Effect.catchTag("SystemError", (e) => e.reason === "NotFound" ? Effect.succeed(false) : Effect.fail(e)),
51
- ),
52
- readFileString: (path, encoding) =>
53
- Effect.tryMap(impl.readFile(path), {
54
- try: (_) => new TextDecoder(encoding).decode(_),
55
- catch: (cause) =>
56
- new PlatformError.BadArgument({
57
- module: "FileSystem",
58
- method: "readFileString",
59
- description: "invalid encoding",
60
- cause,
61
- }),
62
- }),
63
- stream: (path, options) =>
64
- Function.pipe(
65
- impl.open(path, { flag: "r" }),
66
- options?.offset
67
- ? Effect.tap((file) => file.seek(options.offset, "start"))
68
- : Function.identity,
69
- Effect.map((file) => fileStream(file, options)),
70
- Stream.unwrapScoped,
71
- ),
72
- sink: (path, options) =>
73
- Function.pipe(
74
- impl.open(path, { flag: "w", ...options }),
75
- Effect.map((file) => Sink.forEach((_) => file.writeAll(_))),
76
- Sink.unwrapScoped,
77
- ),
78
- writeFileString: (path, data, options) =>
79
- Effect.flatMap(
80
- Effect.try({
81
- try: () => new TextEncoder().encode(data),
82
- catch: (cause) =>
83
- new PlatformError.BadArgument({
84
- module: "FileSystem",
85
- method: "writeFileString",
86
- description: "could not encode string",
87
- cause,
4
+ import * as Brand from "effect/Brand";
5
+ import * as Channel from "effect/Channel";
6
+ import * as Chunk from "effect/Chunk";
7
+ import * as Context from "effect/Context";
8
+ import * as Data from "effect/Data";
9
+ import * as Effect from "effect/Effect";
10
+ import * as Function from "effect/Function";
11
+ import * as Option from "effect/Option";
12
+ import * as Sink from "effect/Sink";
13
+ import * as Stream from "effect/Stream";
14
+ import * as PlatformError from "./PlatformError.js";
15
+ export const FileSystem = Context.GenericTag("@effect/platform/FileSystem");
16
+ export const Size = (bytes) => typeof bytes === "bigint" ? bytes : BigInt(bytes);
17
+ export const FileTypeId = Symbol.for("@effect/platform/FileSystem/File");
18
+ export const FileDescriptor = Brand.nominal();
19
+ export const WatchEventCreate = Data.tagged("Create");
20
+ export const WatchEventUpdate = Data.tagged("Update");
21
+ export const WatchEventRemove = Data.tagged("Remove");
22
+ export class WatchBackend extends Context.Tag("@effect/platform/FileSystem/WatchBackend")() {
23
+ }
24
+ export const make = (impl) => {
25
+ return FileSystem.of({
26
+ ...impl,
27
+ exists: (path) => Function.pipe(impl.access(path), Effect.as(true), Effect.catchTag("SystemError", (e) => e.reason === "NotFound" ? Effect.succeed(false) : Effect.fail(e))),
28
+ readFileString: (path, encoding) => Effect.tryMap(impl.readFile(path), {
29
+ try: (_) => new TextDecoder(encoding).decode(_),
30
+ catch: (cause) => new PlatformError.BadArgument({
31
+ module: "FileSystem",
32
+ method: "readFileString",
33
+ description: "invalid encoding",
34
+ cause,
88
35
  }),
89
36
  }),
90
- (_) => impl.writeFile(path, _, options),
91
- ),
92
- })
93
- }
94
-
95
- const fileStream = (file, {
96
- bufferSize = 16,
97
- bytesToRead: bytesToRead_,
98
- chunkSize: chunkSize_ = Size(64 * 1024),
99
- } = {}) => {
100
- const bytesToRead = bytesToRead_ !== undefined ? Size(bytesToRead_) : undefined
101
- const chunkSize = Size(chunkSize_)
102
-
103
- function loop(
104
- totalBytesRead,
105
- ) {
106
- if (bytesToRead !== undefined && bytesToRead <= totalBytesRead) {
107
- return Channel.void
37
+ stream: (path, options) => Function.pipe(impl.open(path, { flag: "r" }), options?.offset
38
+ ? Effect.tap((file) => file.seek(options.offset, "start"))
39
+ : Function.identity, Effect.map((file) => fileStream(file, options)), Stream.unwrapScoped),
40
+ sink: (path, options) => Function.pipe(impl.open(path, { flag: "w", ...options }), Effect.map((file) => Sink.forEach((_) => file.writeAll(_))), Sink.unwrapScoped),
41
+ writeFileString: (path, data, options) => Effect.flatMap(Effect.try({
42
+ try: () => new TextEncoder().encode(data),
43
+ catch: (cause) => new PlatformError.BadArgument({
44
+ module: "FileSystem",
45
+ method: "writeFileString",
46
+ description: "could not encode string",
47
+ cause,
48
+ }),
49
+ }), (_) => impl.writeFile(path, _, options)),
50
+ });
51
+ };
52
+ const fileStream = (file, { bufferSize = 16, bytesToRead: bytesToRead_, chunkSize: chunkSize_ = Size(64 * 1024), } = {}) => {
53
+ const bytesToRead = bytesToRead_ !== undefined ? Size(bytesToRead_) : undefined;
54
+ const chunkSize = Size(chunkSize_);
55
+ function loop(totalBytesRead) {
56
+ if (bytesToRead !== undefined && bytesToRead <= totalBytesRead) {
57
+ return Channel.void;
58
+ }
59
+ const toRead = bytesToRead !== undefined && bytesToRead - totalBytesRead < chunkSize
60
+ ? bytesToRead - totalBytesRead
61
+ : chunkSize;
62
+ return Channel.flatMap(file.readAlloc(toRead), Option.match({
63
+ onNone: () => Channel.void,
64
+ onSome: (buf) => Channel.flatMap(Channel.write(Chunk.of(buf)), () => loop(totalBytesRead + BigInt(buf.length))),
65
+ }));
108
66
  }
109
-
110
- const toRead = bytesToRead !== undefined && (bytesToRead - totalBytesRead) < chunkSize
111
- ? bytesToRead - totalBytesRead
112
- : chunkSize
113
-
114
- return Channel.flatMap(
115
- file.readAlloc(toRead),
116
- Option.match({
117
- onNone: () => Channel.void,
118
- onSome: (buf) =>
119
- Channel.flatMap(
120
- Channel.write(Chunk.of(buf)),
121
- () => loop(totalBytesRead + BigInt(buf.length)),
122
- ),
123
- }),
124
- )
125
- }
126
-
127
- return Stream.bufferChunks(
128
- Stream.fromChannel(loop(BigInt(0))),
129
- { capacity: bufferSize },
130
- )
131
- }
67
+ return Stream.bufferChunks(Stream.fromChannel(loop(BigInt(0))), {
68
+ capacity: bufferSize,
69
+ });
70
+ };
package/dist/Http.js CHANGED
@@ -1,8 +1,6 @@
1
1
  import * as Values from "./Values.js";
2
2
  export function fetch(handler, init) {
3
- const url = "path" in init
4
- ? `http://localhost${init.path}`
5
- : init.url;
3
+ const url = "path" in init ? `http://localhost${init.path}` : init.url;
6
4
  const isPlain = Values.isPlainObject(init.body);
7
5
  const headers = new Headers(init.headers);
8
6
  if (isPlain && !headers.has("Content-Type")) {
@@ -17,9 +15,7 @@ export function fetch(handler, init) {
17
15
  return Promise.resolve(handler(request));
18
16
  }
19
17
  export function createAbortableRequest(init) {
20
- const url = "path" in init
21
- ? `http://localhost${init.path}`
22
- : init.url;
18
+ const url = "path" in init ? `http://localhost${init.path}` : init.url;
23
19
  const controller = new AbortController();
24
20
  const request = new Request(url, { ...init, signal: controller.signal });
25
21
  return { request, abort: () => controller.abort() };