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.
- package/dist/BlobStore.d.ts +80 -0
- package/dist/BlobStore.js +19 -0
- package/dist/ChildProcess.d.ts +60 -0
- package/dist/ChildProcess.js +30 -0
- package/dist/Commander.d.ts +3 -6
- package/dist/Commander.js +6 -13
- package/dist/ContentNegotiation.d.ts +8 -9
- package/dist/ContentNegotiation.js +32 -37
- package/dist/Cookies.d.ts +47 -0
- package/dist/Cookies.js +273 -363
- package/dist/Development.d.ts +2 -2
- package/dist/Development.js +3 -4
- package/dist/Effectify.d.ts +1 -4
- package/dist/FilePathPattern.d.ts +3 -3
- package/dist/FileRouter.d.ts +5 -8
- package/dist/FileRouter.js +9 -10
- package/dist/FileRouterCodegen.d.ts +1 -1
- package/dist/FileRouterCodegen.js +33 -13
- package/dist/FileSystem.d.ts +158 -0
- package/dist/FileSystem.js +64 -125
- package/dist/Http.js +2 -6
- package/dist/PathPattern.d.ts +7 -7
- package/dist/PathPattern.js +1 -3
- package/dist/PlatformError.d.ts +24 -32
- package/dist/PlatformError.js +3 -21
- package/dist/PlatformRuntime.js +5 -10
- package/dist/Route.d.ts +14 -19
- package/dist/Route.js +8 -11
- package/dist/RouteBody.d.ts +6 -12
- package/dist/RouteBody.js +2 -2
- package/dist/RouteError.d.ts +98 -0
- package/dist/RouteError.js +55 -0
- package/dist/RouteHook.js +6 -11
- package/dist/RouteHttp.d.ts +3 -3
- package/dist/RouteHttp.js +27 -22
- package/dist/RouteMount.d.ts +16 -50
- package/dist/RouteMount.js +6 -20
- package/dist/RouteSchema.d.ts +22 -1
- package/dist/RouteSchema.js +33 -0
- package/dist/RouteSse.js +4 -10
- package/dist/RouteTree.d.ts +2 -1
- package/dist/RouteTree.js +17 -15
- package/dist/RouteTrie.d.ts +2 -2
- package/dist/RouteTrie.js +4 -9
- package/dist/SchemaExtra.d.ts +1 -1
- package/dist/Socket.d.ts +27 -0
- package/dist/Socket.js +20 -28
- package/dist/Sql.d.ts +34 -0
- package/dist/Sql.js +5 -0
- package/dist/SqlIntrospect.d.ts +91 -0
- package/dist/SqlIntrospect.js +466 -0
- package/dist/Start.d.ts +4 -6
- package/dist/Start.js +10 -2
- package/dist/StreamExtra.d.ts +1 -1
- package/dist/StreamExtra.js +9 -9
- package/dist/System.d.ts +7 -0
- package/dist/System.js +22 -0
- package/dist/TuplePathPattern.js +55 -50
- package/dist/Unique.js +7 -7
- package/dist/Values.d.ts +2 -1
- package/dist/Values.js +19 -13
- package/dist/bun/BunBlobStoreDisk.d.ts +6 -0
- package/dist/bun/BunBlobStoreDisk.js +116 -0
- package/dist/bun/BunBlobStoreS3.d.ts +11 -0
- package/dist/bun/BunBlobStoreS3.js +89 -0
- package/dist/bun/BunBlobWatcherDisk.d.ts +6 -0
- package/dist/bun/BunBlobWatcherDisk.js +60 -0
- package/dist/bun/BunBlobWatcherQueue.d.ts +6 -0
- package/dist/bun/BunBlobWatcherQueue.js +17 -0
- package/dist/bun/BunBundle.d.ts +5 -6
- package/dist/bun/BunBundle.js +7 -15
- package/dist/bun/BunChildProcessSpawner.d.ts +3 -0
- package/dist/bun/BunChildProcessSpawner.js +103 -0
- package/dist/bun/BunImportTrackerPlugin.d.ts +1 -1
- package/dist/bun/BunImportTrackerPlugin.js +3 -5
- package/dist/bun/BunRoute.d.ts +3 -2
- package/dist/bun/BunRoute.js +5 -7
- package/dist/bun/BunRuntime.js +1 -1
- package/dist/bun/BunServer.d.ts +11 -4
- package/dist/bun/BunServer.js +35 -11
- package/dist/bun/BunSql.d.ts +4 -0
- package/dist/bun/BunSql.js +81 -0
- package/dist/bun/_BunEnhancedResolve.d.ts +3 -3
- package/dist/bun/_BunEnhancedResolve.js +2 -4
- package/dist/bun/index.d.ts +1 -0
- package/dist/bun/index.js +1 -0
- package/dist/bundler/Bundle.d.ts +2 -1
- package/dist/bundler/Bundle.js +1 -1
- package/dist/bundler/BundleFiles.d.ts +5 -5
- package/dist/bundler/BundleFiles.js +10 -8
- package/dist/bundler/BundleRoute.d.ts +27 -0
- package/dist/bundler/BundleRoute.js +51 -0
- package/dist/client/ScrollState.js +2 -6
- package/dist/client/index.js +6 -8
- package/dist/console/Console.d.ts +6 -0
- package/dist/console/Console.js +26 -0
- package/dist/console/ConsoleErrors.d.ts +3 -0
- package/dist/console/ConsoleErrors.js +200 -0
- package/dist/console/ConsoleLogger.d.ts +3 -0
- package/dist/console/ConsoleLogger.js +47 -0
- package/dist/console/ConsoleMetrics.d.ts +3 -0
- package/dist/console/ConsoleMetrics.js +61 -0
- package/dist/console/ConsoleProcess.d.ts +3 -0
- package/dist/console/ConsoleProcess.js +49 -0
- package/dist/console/ConsoleStore.d.ts +144 -0
- package/dist/console/ConsoleStore.js +61 -0
- package/dist/console/ConsoleTracer.d.ts +3 -0
- package/dist/console/ConsoleTracer.js +94 -0
- package/dist/console/Simulation.d.ts +2 -0
- package/dist/console/Simulation.js +633 -0
- package/dist/console/index.d.ts +3 -0
- package/dist/console/index.js +3 -0
- package/dist/console/routes/errors/route.d.ts +10 -0
- package/dist/console/routes/errors/route.js +47 -0
- package/dist/console/routes/fiberDetail.d.ts +16 -0
- package/dist/console/routes/fiberDetail.js +38 -0
- package/dist/console/routes/fibers/route.d.ts +10 -0
- package/dist/console/routes/fibers/route.js +19 -0
- package/dist/console/routes/git/route.d.ts +11 -0
- package/dist/console/routes/git/route.js +33 -0
- package/dist/console/routes/layout.d.ts +9 -0
- package/dist/console/routes/layout.js +3 -0
- package/dist/console/routes/logs/route.d.ts +10 -0
- package/dist/console/routes/logs/route.js +32 -0
- package/dist/console/routes/metrics/route.d.ts +10 -0
- package/dist/console/routes/metrics/route.js +17 -0
- package/dist/console/routes/route.d.ts +6 -0
- package/dist/console/routes/route.js +5 -0
- package/dist/console/routes/routes/route.d.ts +6 -0
- package/dist/console/routes/routes/route.js +20 -0
- package/dist/console/routes/services/route.d.ts +6 -0
- package/dist/console/routes/services/route.js +12 -0
- package/dist/console/routes/system/route.d.ts +10 -0
- package/dist/console/routes/system/route.js +18 -0
- package/dist/console/routes/traceDetail.d.ts +16 -0
- package/dist/console/routes/traceDetail.js +14 -0
- package/dist/console/routes/traces/route.d.ts +10 -0
- package/dist/console/routes/traces/route.js +39 -0
- package/dist/console/routes/tree.d.ts +153 -0
- package/dist/console/routes/tree.js +29 -0
- package/dist/console/ui/Errors.d.ts +4 -0
- package/dist/console/ui/Errors.js +15 -0
- package/dist/console/ui/Fibers.d.ts +24 -0
- package/dist/console/ui/Fibers.js +121 -0
- package/dist/console/ui/Git.d.ts +20 -0
- package/dist/console/ui/Git.js +95 -0
- package/dist/console/ui/Logs.d.ts +4 -0
- package/dist/console/ui/Logs.js +25 -0
- package/dist/console/ui/Metrics.d.ts +4 -0
- package/dist/console/ui/Metrics.js +26 -0
- package/dist/console/ui/Routes.d.ts +8 -0
- package/dist/console/ui/Routes.js +70 -0
- package/dist/console/ui/Services.d.ts +10 -0
- package/dist/console/ui/Services.js +246 -0
- package/dist/console/ui/Shell.d.ts +10 -0
- package/dist/console/ui/Shell.js +7 -0
- package/dist/console/ui/System.d.ts +4 -0
- package/dist/console/ui/System.js +35 -0
- package/dist/console/ui/Traces.d.ts +12 -0
- package/dist/console/ui/Traces.js +179 -0
- package/dist/datastar/actions/fetch.d.ts +1 -1
- package/dist/datastar/actions/fetch.js +10 -18
- package/dist/datastar/actions/peek.js +1 -2
- package/dist/datastar/actions/setAll.js +1 -2
- package/dist/datastar/actions/toggleAll.js +1 -2
- package/dist/datastar/attributes/attr.js +1 -2
- package/dist/datastar/attributes/bind.js +10 -18
- package/dist/datastar/attributes/class.js +2 -5
- package/dist/datastar/attributes/computed.js +2 -3
- package/dist/datastar/attributes/effect.js +1 -2
- package/dist/datastar/attributes/indicator.js +2 -4
- package/dist/datastar/attributes/init.js +2 -3
- package/dist/datastar/attributes/jsonSignals.js +1 -2
- package/dist/datastar/attributes/on.js +41 -22
- package/dist/datastar/attributes/onIntersect.js +2 -3
- package/dist/datastar/attributes/onInterval.js +2 -3
- package/dist/datastar/attributes/onSignalPatch.js +2 -4
- package/dist/datastar/attributes/ref.js +1 -2
- package/dist/datastar/attributes/show.js +1 -2
- package/dist/datastar/attributes/signals.js +1 -2
- package/dist/datastar/attributes/style.js +6 -12
- package/dist/datastar/attributes/text.js +1 -2
- package/dist/datastar/engine.d.ts +13 -7
- package/dist/datastar/engine.js +76 -48
- package/dist/datastar/happydom.d.ts +1 -0
- package/dist/datastar/happydom.js +8 -0
- package/dist/datastar/index.d.ts +1 -1
- package/dist/datastar/index.js +1 -1
- package/dist/datastar/utils.js +4 -7
- package/dist/datastar/watchers/patchElements.js +24 -45
- package/dist/datastar/watchers/patchSignals.js +1 -2
- package/dist/experimental/EncryptedCookies.d.ts +2 -5
- package/dist/experimental/EncryptedCookies.js +17 -48
- package/dist/experimental/index.d.ts +0 -1
- package/dist/experimental/index.js +0 -1
- package/dist/hyper/Hyper.d.ts +2 -9
- package/dist/hyper/Hyper.js +1 -12
- package/dist/hyper/HyperHtml.d.ts +1 -1
- package/dist/hyper/HyperHtml.js +18 -12
- package/dist/hyper/HyperHtml.test.d.ts +1 -0
- package/dist/hyper/HyperHtml.test.js +197 -0
- package/dist/hyper/HyperRoute.test.js +14 -3
- package/dist/hyper/html.d.ts +11 -0
- package/dist/hyper/html.js +30 -0
- package/dist/hyper/index.d.ts +2 -0
- package/dist/hyper/index.js +1 -0
- package/dist/hyper/jsx-runtime.d.ts +1 -1
- package/dist/hyper/jsx-runtime.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lint/plugin.d.ts +86 -0
- package/dist/lint/plugin.js +341 -0
- package/dist/node/NodeFileSystem.d.ts +2 -2
- package/dist/node/NodeFileSystem.js +4 -14
- package/dist/sql/bun/index.d.ts +3 -0
- package/dist/sql/bun/index.js +75 -0
- package/dist/sql/mssql/docker.d.ts +2 -0
- package/dist/sql/mssql/docker.js +67 -0
- package/dist/sql/mssql/index.d.ts +21 -0
- package/dist/sql/mssql/index.js +113 -0
- package/dist/testing/TestLogger.js +4 -1
- package/dist/testing/index.d.ts +0 -1
- package/dist/testing/index.js +0 -1
- package/dist/testing/utils.d.ts +3 -3
- package/dist/testing/utils.js +4 -4
- package/dist/x/cloudflare/CloudflareTunnel.d.ts +2 -5
- package/dist/x/cloudflare/CloudflareTunnel.js +14 -27
- package/dist/x/datastar/Datastar.d.ts +1 -1
- package/dist/x/datastar/Datastar.js +13 -12
- package/dist/x/datastar/index.d.ts +1 -2
- package/dist/x/datastar/index.js +1 -2
- package/dist/x/tailscale/TailscaleTunnel.d.ts +15 -0
- package/dist/x/tailscale/TailscaleTunnel.js +68 -0
- package/dist/x/tailscale/index.d.ts +1 -0
- package/dist/x/tailscale/index.js +1 -0
- package/dist/x/tailwind/TailwindPlugin.js +19 -19
- package/dist/x/tailwind/compile.d.ts +2 -2
- package/dist/x/tailwind/compile.js +2 -4
- package/package.json +22 -10
- package/src/ChildProcess.ts +145 -0
- package/src/PlatformError.ts +27 -50
- package/src/Route.ts +2 -2
- package/src/RouteError.ts +76 -0
- package/src/RouteHttp.ts +13 -5
- package/src/RouteSchema.ts +96 -1
- package/src/RouteTree.ts +12 -0
- package/src/Sql.ts +51 -0
- package/src/SqlIntrospect.ts +620 -0
- package/src/Start.ts +15 -3
- package/src/System.ts +43 -0
- package/src/Values.ts +7 -0
- package/src/bun/BunChildProcessSpawner.ts +143 -0
- package/src/bun/BunRoute.ts +5 -2
- package/src/bun/BunServer.ts +22 -1
- package/src/bun/index.ts +1 -0
- package/src/bundler/BundleRoute.ts +66 -0
- package/src/console/Console.ts +42 -0
- package/src/console/ConsoleErrors.ts +213 -0
- package/src/console/ConsoleLogger.ts +56 -0
- package/src/console/ConsoleMetrics.ts +72 -0
- package/src/console/ConsoleProcess.ts +59 -0
- package/src/console/ConsoleStore.ts +187 -0
- package/src/console/ConsoleTracer.ts +107 -0
- package/src/console/Simulation.ts +814 -0
- package/src/console/console.html +340 -0
- package/src/console/index.ts +3 -0
- package/src/console/routes/errors/route.tsx +97 -0
- package/src/console/routes/fiberDetail.tsx +54 -0
- package/src/console/routes/fibers/route.tsx +45 -0
- package/src/console/routes/git/route.tsx +64 -0
- package/src/console/routes/layout.tsx +4 -0
- package/src/console/routes/logs/route.tsx +77 -0
- package/src/console/routes/metrics/route.tsx +36 -0
- package/src/console/routes/route.tsx +8 -0
- package/src/console/routes/routes/route.tsx +30 -0
- package/src/console/routes/services/route.tsx +21 -0
- package/src/console/routes/system/route.tsx +43 -0
- package/src/console/routes/traceDetail.tsx +22 -0
- package/src/console/routes/traces/route.tsx +81 -0
- package/src/console/routes/tree.ts +30 -0
- package/src/console/ui/Errors.tsx +76 -0
- package/src/console/ui/Fibers.tsx +321 -0
- package/src/console/ui/Git.tsx +182 -0
- package/src/console/ui/Logs.tsx +46 -0
- package/src/console/ui/Metrics.tsx +78 -0
- package/src/console/ui/Routes.tsx +125 -0
- package/src/console/ui/Services.tsx +273 -0
- package/src/console/ui/Shell.tsx +62 -0
- package/src/console/ui/System.tsx +131 -0
- package/src/console/ui/Traces.tsx +426 -0
- package/src/datastar/README.md +6 -1
- package/src/datastar/actions/fetch.ts +0 -1
- package/src/datastar/attributes/on.ts +40 -20
- package/src/datastar/engine.ts +51 -0
- package/src/datastar/jsx.d.ts +79 -0
- package/src/hyper/Hyper.ts +1 -16
- package/src/hyper/HyperHtml.ts +6 -4
- package/src/hyper/HyperRoute.ts +2 -1
- package/src/hyper/html.ts +47 -0
- package/src/hyper/index.ts +2 -0
- package/src/hyper/jsx.d.ts +5 -3
- package/src/index.ts +1 -0
- package/src/lint/plugin.js +129 -0
- package/src/sql/bun/index.ts +147 -0
- package/src/sql/mssql/docker.ts +117 -0
- package/src/sql/mssql/index.ts +223 -0
- package/src/sql/mssql/mssql.d.ts +41 -0
- package/src/x/cloudflare/CloudflareTunnel.ts +8 -36
- package/src/x/tailscale/TailscaleTunnel.ts +113 -0
- package/src/x/tailscale/index.ts +1 -0
- package/src/x/datastar/Datastar.ts +0 -61
- package/src/x/datastar/index.ts +0 -2
- package/src/x/datastar/jsx-datastar.d.ts +0 -60
package/dist/Development.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as FileSystem from "
|
|
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();
|
package/dist/Effectify.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
28
|
+
export declare function format(segs: Array<Segment>): `/${string}`;
|
|
29
29
|
export declare function toPathPattern(pattern: string): Either.Either<PathPattern.PathPattern, ValidationError>;
|
package/dist/FileRouter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as FileSystem from "
|
|
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
|
|
55
|
+
export declare function getFileRoutes(paths: Array<string>): Effect.Effect<OrderedFileRoutes, FileRouterError>;
|
|
59
56
|
export {};
|
package/dist/FileRouter.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as FileSystem from "
|
|
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
|
-
|
|
129
|
+
(aDepth - bDepth) * (1 - 2 * +aHasRest) +
|
|
131
130
|
// lexicographic comparison as tiebreaker
|
|
132
|
-
|
|
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
|
}
|
|
@@ -6,7 +6,7 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
|
|
|
6
6
|
}
|
|
7
7
|
return path;
|
|
8
8
|
};
|
|
9
|
-
import * as FileSystem from "
|
|
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
|
|
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({
|
|
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({
|
|
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({
|
|
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({
|
|
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({
|
|
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 {};
|
package/dist/FileSystem.js
CHANGED
|
@@ -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
|
|
17
|
-
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
export const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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() };
|