effect-start 0.23.1 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +18 -86
- package/src/Development.ts +3 -1
- package/src/Entity.ts +17 -0
- package/src/Fetch.ts +271 -0
- package/src/SqlIntrospect.ts +64 -70
- package/src/Start.ts +21 -24
- package/src/StartApp.ts +1 -1
- package/src/bun/BunServer.ts +42 -10
- package/src/hyper/HyperHtml.ts +0 -1
- package/src/sql/bun/index.ts +1 -1
- package/src/sql/index.ts +1 -0
- package/src/sql/libsql/index.ts +173 -0
- package/src/sql/libsql/libsql.d.ts +39 -0
- package/src/sql/mssql/index.ts +1 -1
- package/dist/BlobStore.d.ts +0 -80
- package/dist/BlobStore.js +0 -19
- package/dist/ChildProcess.d.ts +0 -60
- package/dist/ChildProcess.js +0 -30
- package/dist/Commander.d.ts +0 -100
- package/dist/Commander.js +0 -326
- package/dist/ContentNegotiation.d.ts +0 -12
- package/dist/ContentNegotiation.js +0 -359
- package/dist/Cookies.d.ts +0 -47
- package/dist/Cookies.js +0 -302
- package/dist/Development.d.ts +0 -39
- package/dist/Development.js +0 -58
- package/dist/Effectify.d.ts +0 -209
- package/dist/Effectify.js +0 -19
- package/dist/Entity.d.ts +0 -47
- package/dist/Entity.js +0 -224
- package/dist/FilePathPattern.d.ts +0 -29
- package/dist/FilePathPattern.js +0 -86
- package/dist/FileRouter.d.ts +0 -56
- package/dist/FileRouter.js +0 -148
- package/dist/FileRouterCodegen.d.ts +0 -18
- package/dist/FileRouterCodegen.js +0 -227
- package/dist/FileRouterPattern.d.ts +0 -9
- package/dist/FileRouterPattern.js +0 -35
- package/dist/FileSystem.d.ts +0 -158
- package/dist/FileSystem.js +0 -70
- package/dist/Http.d.ts +0 -37
- package/dist/Http.js +0 -88
- package/dist/HttpAppExtra.d.ts +0 -7
- package/dist/HttpAppExtra.js +0 -320
- package/dist/HttpUtils.d.ts +0 -3
- package/dist/HttpUtils.js +0 -11
- package/dist/PathPattern.d.ts +0 -134
- package/dist/PathPattern.js +0 -413
- package/dist/PlatformError.d.ts +0 -38
- package/dist/PlatformError.js +0 -25
- package/dist/PlatformRuntime.d.ts +0 -27
- package/dist/PlatformRuntime.js +0 -46
- package/dist/Route.d.ts +0 -97
- package/dist/Route.js +0 -100
- package/dist/RouteBody.d.ts +0 -47
- package/dist/RouteBody.js +0 -67
- package/dist/RouteError.d.ts +0 -98
- package/dist/RouteError.js +0 -55
- package/dist/RouteHook.d.ts +0 -12
- package/dist/RouteHook.js +0 -40
- package/dist/RouteHttp.d.ts +0 -21
- package/dist/RouteHttp.js +0 -258
- package/dist/RouteHttpTracer.d.ts +0 -10
- package/dist/RouteHttpTracer.js +0 -62
- package/dist/RouteMount.d.ts +0 -86
- package/dist/RouteMount.js +0 -63
- package/dist/RouteSchema.d.ts +0 -86
- package/dist/RouteSchema.js +0 -188
- package/dist/RouteSse.d.ts +0 -21
- package/dist/RouteSse.js +0 -79
- package/dist/RouteTree.d.ts +0 -57
- package/dist/RouteTree.js +0 -93
- package/dist/RouteTrie.d.ts +0 -20
- package/dist/RouteTrie.js +0 -152
- package/dist/RouterPattern.d.ts +0 -118
- package/dist/RouterPattern.js +0 -269
- package/dist/SchemaExtra.d.ts +0 -7
- package/dist/SchemaExtra.js +0 -74
- package/dist/Socket.d.ts +0 -27
- package/dist/Socket.js +0 -29
- package/dist/Sql.d.ts +0 -34
- package/dist/Sql.js +0 -5
- package/dist/SqlIntrospect.d.ts +0 -91
- package/dist/SqlIntrospect.js +0 -466
- package/dist/Start.d.ts +0 -44
- package/dist/Start.js +0 -49
- package/dist/StartApp.d.ts +0 -19
- package/dist/StartApp.js +0 -21
- package/dist/StreamExtra.d.ts +0 -28
- package/dist/StreamExtra.js +0 -100
- package/dist/System.d.ts +0 -7
- package/dist/System.js +0 -22
- package/dist/TuplePathPattern.d.ts +0 -9
- package/dist/TuplePathPattern.js +0 -68
- package/dist/Unique.d.ts +0 -50
- package/dist/Unique.js +0 -187
- package/dist/Values.d.ts +0 -27
- package/dist/Values.js +0 -36
- package/dist/bun/BunBlobStoreDisk.d.ts +0 -6
- package/dist/bun/BunBlobStoreDisk.js +0 -116
- package/dist/bun/BunBlobStoreS3.d.ts +0 -11
- package/dist/bun/BunBlobStoreS3.js +0 -89
- package/dist/bun/BunBlobWatcherDisk.d.ts +0 -6
- package/dist/bun/BunBlobWatcherDisk.js +0 -60
- package/dist/bun/BunBlobWatcherQueue.d.ts +0 -6
- package/dist/bun/BunBlobWatcherQueue.js +0 -17
- package/dist/bun/BunBundle.d.ts +0 -11
- package/dist/bun/BunBundle.js +0 -137
- package/dist/bun/BunChildProcessSpawner.d.ts +0 -3
- package/dist/bun/BunChildProcessSpawner.js +0 -103
- package/dist/bun/BunHttpServer.d.ts +0 -44
- package/dist/bun/BunHttpServer.js +0 -186
- package/dist/bun/BunHttpServer_web.d.ts +0 -60
- package/dist/bun/BunHttpServer_web.js +0 -252
- package/dist/bun/BunImportTrackerPlugin.d.ts +0 -13
- package/dist/bun/BunImportTrackerPlugin.js +0 -69
- package/dist/bun/BunPlatformHttpServer.d.ts +0 -10
- package/dist/bun/BunPlatformHttpServer.js +0 -53
- package/dist/bun/BunRoute.d.ts +0 -48
- package/dist/bun/BunRoute.js +0 -121
- package/dist/bun/BunRuntime.d.ts +0 -2
- package/dist/bun/BunRuntime.js +0 -31
- package/dist/bun/BunServer.d.ts +0 -40
- package/dist/bun/BunServer.js +0 -157
- package/dist/bun/BunServerRequest.d.ts +0 -60
- package/dist/bun/BunServerRequest.js +0 -252
- package/dist/bun/BunSql.d.ts +0 -4
- package/dist/bun/BunSql.js +0 -81
- package/dist/bun/BunVirtualFilesPlugin.d.ts +0 -4
- package/dist/bun/BunVirtualFilesPlugin.js +0 -40
- package/dist/bun/_BunEnhancedResolve.d.ts +0 -45
- package/dist/bun/_BunEnhancedResolve.js +0 -102
- package/dist/bun/index.d.ts +0 -5
- package/dist/bun/index.js +0 -5
- package/dist/bundler/Bundle.d.ts +0 -61
- package/dist/bundler/Bundle.js +0 -48
- package/dist/bundler/BundleFiles.d.ts +0 -13
- package/dist/bundler/BundleFiles.js +0 -96
- package/dist/bundler/BundleHttp.d.ts +0 -45
- package/dist/bundler/BundleHttp.js +0 -176
- package/dist/bundler/BundleRoute.d.ts +0 -27
- package/dist/bundler/BundleRoute.js +0 -51
- package/dist/client/Overlay.d.ts +0 -2
- package/dist/client/Overlay.js +0 -32
- package/dist/client/ScrollState.d.ts +0 -6
- package/dist/client/ScrollState.js +0 -94
- package/dist/client/index.d.ts +0 -6
- package/dist/client/index.js +0 -79
- package/dist/console/Console.d.ts +0 -6
- package/dist/console/Console.js +0 -26
- package/dist/console/ConsoleErrors.d.ts +0 -3
- package/dist/console/ConsoleErrors.js +0 -200
- package/dist/console/ConsoleLogger.d.ts +0 -3
- package/dist/console/ConsoleLogger.js +0 -47
- package/dist/console/ConsoleMetrics.d.ts +0 -3
- package/dist/console/ConsoleMetrics.js +0 -61
- package/dist/console/ConsoleProcess.d.ts +0 -3
- package/dist/console/ConsoleProcess.js +0 -49
- package/dist/console/ConsoleStore.d.ts +0 -144
- package/dist/console/ConsoleStore.js +0 -61
- package/dist/console/ConsoleTracer.d.ts +0 -3
- package/dist/console/ConsoleTracer.js +0 -94
- package/dist/console/Simulation.d.ts +0 -2
- package/dist/console/Simulation.js +0 -633
- package/dist/console/index.d.ts +0 -3
- package/dist/console/index.js +0 -3
- package/dist/console/routes/errors/route.d.ts +0 -10
- package/dist/console/routes/errors/route.js +0 -47
- package/dist/console/routes/fiberDetail.d.ts +0 -16
- package/dist/console/routes/fiberDetail.js +0 -38
- package/dist/console/routes/fibers/route.d.ts +0 -10
- package/dist/console/routes/fibers/route.js +0 -19
- package/dist/console/routes/git/route.d.ts +0 -11
- package/dist/console/routes/git/route.js +0 -33
- package/dist/console/routes/layout.d.ts +0 -9
- package/dist/console/routes/layout.js +0 -3
- package/dist/console/routes/logs/route.d.ts +0 -10
- package/dist/console/routes/logs/route.js +0 -32
- package/dist/console/routes/metrics/route.d.ts +0 -10
- package/dist/console/routes/metrics/route.js +0 -17
- package/dist/console/routes/route.d.ts +0 -6
- package/dist/console/routes/route.js +0 -5
- package/dist/console/routes/routes/route.d.ts +0 -6
- package/dist/console/routes/routes/route.js +0 -20
- package/dist/console/routes/services/route.d.ts +0 -6
- package/dist/console/routes/services/route.js +0 -12
- package/dist/console/routes/system/route.d.ts +0 -10
- package/dist/console/routes/system/route.js +0 -18
- package/dist/console/routes/traceDetail.d.ts +0 -16
- package/dist/console/routes/traceDetail.js +0 -14
- package/dist/console/routes/traces/route.d.ts +0 -10
- package/dist/console/routes/traces/route.js +0 -39
- package/dist/console/routes/tree.d.ts +0 -153
- package/dist/console/routes/tree.js +0 -29
- package/dist/console/ui/Errors.d.ts +0 -4
- package/dist/console/ui/Errors.js +0 -15
- package/dist/console/ui/Fibers.d.ts +0 -24
- package/dist/console/ui/Fibers.js +0 -121
- package/dist/console/ui/Git.d.ts +0 -20
- package/dist/console/ui/Git.js +0 -95
- package/dist/console/ui/Logs.d.ts +0 -4
- package/dist/console/ui/Logs.js +0 -25
- package/dist/console/ui/Metrics.d.ts +0 -4
- package/dist/console/ui/Metrics.js +0 -26
- package/dist/console/ui/Routes.d.ts +0 -8
- package/dist/console/ui/Routes.js +0 -70
- package/dist/console/ui/Services.d.ts +0 -10
- package/dist/console/ui/Services.js +0 -246
- package/dist/console/ui/Shell.d.ts +0 -10
- package/dist/console/ui/Shell.js +0 -7
- package/dist/console/ui/System.d.ts +0 -4
- package/dist/console/ui/System.js +0 -35
- package/dist/console/ui/Traces.d.ts +0 -12
- package/dist/console/ui/Traces.js +0 -179
- package/dist/datastar/actions/fetch.d.ts +0 -30
- package/dist/datastar/actions/fetch.js +0 -403
- package/dist/datastar/actions/peek.d.ts +0 -1
- package/dist/datastar/actions/peek.js +0 -13
- package/dist/datastar/actions/setAll.d.ts +0 -1
- package/dist/datastar/actions/setAll.js +0 -12
- package/dist/datastar/actions/toggleAll.d.ts +0 -1
- package/dist/datastar/actions/toggleAll.js +0 -12
- package/dist/datastar/attributes/attr.d.ts +0 -1
- package/dist/datastar/attributes/attr.js +0 -48
- package/dist/datastar/attributes/bind.d.ts +0 -1
- package/dist/datastar/attributes/bind.js +0 -175
- package/dist/datastar/attributes/class.d.ts +0 -1
- package/dist/datastar/attributes/class.js +0 -47
- package/dist/datastar/attributes/computed.d.ts +0 -1
- package/dist/datastar/attributes/computed.js +0 -26
- package/dist/datastar/attributes/effect.d.ts +0 -1
- package/dist/datastar/attributes/effect.js +0 -9
- package/dist/datastar/attributes/indicator.d.ts +0 -1
- package/dist/datastar/attributes/indicator.js +0 -30
- package/dist/datastar/attributes/init.d.ts +0 -1
- package/dist/datastar/attributes/init.js +0 -26
- package/dist/datastar/attributes/jsonSignals.d.ts +0 -1
- package/dist/datastar/attributes/jsonSignals.js +0 -30
- package/dist/datastar/attributes/on.d.ts +0 -1
- package/dist/datastar/attributes/on.js +0 -78
- package/dist/datastar/attributes/onIntersect.d.ts +0 -1
- package/dist/datastar/attributes/onIntersect.js +0 -53
- package/dist/datastar/attributes/onInterval.d.ts +0 -1
- package/dist/datastar/attributes/onInterval.js +0 -30
- package/dist/datastar/attributes/onSignalPatch.d.ts +0 -1
- package/dist/datastar/attributes/onSignalPatch.js +0 -42
- package/dist/datastar/attributes/ref.d.ts +0 -1
- package/dist/datastar/attributes/ref.js +0 -10
- package/dist/datastar/attributes/show.d.ts +0 -1
- package/dist/datastar/attributes/show.js +0 -31
- package/dist/datastar/attributes/signals.d.ts +0 -1
- package/dist/datastar/attributes/signals.js +0 -17
- package/dist/datastar/attributes/style.d.ts +0 -1
- package/dist/datastar/attributes/style.js +0 -50
- package/dist/datastar/attributes/text.d.ts +0 -1
- package/dist/datastar/attributes/text.js +0 -26
- package/dist/datastar/engine.d.ts +0 -162
- package/dist/datastar/engine.js +0 -999
- package/dist/datastar/happydom.d.ts +0 -1
- package/dist/datastar/happydom.js +0 -8
- package/dist/datastar/index.d.ts +0 -24
- package/dist/datastar/index.js +0 -24
- package/dist/datastar/load.d.ts +0 -24
- package/dist/datastar/load.js +0 -24
- package/dist/datastar/utils.d.ts +0 -51
- package/dist/datastar/utils.js +0 -202
- package/dist/datastar/watchers/patchElements.d.ts +0 -1
- package/dist/datastar/watchers/patchElements.js +0 -399
- package/dist/datastar/watchers/patchSignals.d.ts +0 -1
- package/dist/datastar/watchers/patchSignals.js +0 -14
- package/dist/experimental/EncryptedCookies.d.ts +0 -48
- package/dist/experimental/EncryptedCookies.js +0 -212
- package/dist/experimental/SseHttpResponse.d.ts +0 -7
- package/dist/experimental/SseHttpResponse.js +0 -28
- package/dist/experimental/index.d.ts +0 -1
- package/dist/experimental/index.js +0 -1
- package/dist/hyper/Hyper.d.ts +0 -25
- package/dist/hyper/Hyper.js +0 -23
- package/dist/hyper/HyperHtml.d.ts +0 -23
- package/dist/hyper/HyperHtml.js +0 -150
- package/dist/hyper/HyperHtml.test.d.ts +0 -1
- package/dist/hyper/HyperHtml.test.js +0 -197
- package/dist/hyper/HyperNode.d.ts +0 -14
- package/dist/hyper/HyperNode.js +0 -11
- package/dist/hyper/HyperRoute.d.ts +0 -8
- package/dist/hyper/HyperRoute.js +0 -32
- package/dist/hyper/HyperRoute.test.d.ts +0 -1
- package/dist/hyper/HyperRoute.test.js +0 -83
- package/dist/hyper/html.d.ts +0 -11
- package/dist/hyper/html.js +0 -30
- package/dist/hyper/index.d.ts +0 -6
- package/dist/hyper/index.js +0 -5
- package/dist/hyper/jsx-runtime.d.ts +0 -7
- package/dist/hyper/jsx-runtime.js +0 -8
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -8
- package/dist/inference_check.d.ts +0 -1
- package/dist/inference_check.js +0 -15
- package/dist/lint/plugin.d.ts +0 -86
- package/dist/lint/plugin.js +0 -341
- package/dist/middlewares/BasicAuthMiddleware.d.ts +0 -8
- package/dist/middlewares/BasicAuthMiddleware.js +0 -22
- package/dist/middlewares/index.d.ts +0 -1
- package/dist/middlewares/index.js +0 -1
- package/dist/node/Effectify.d.ts +0 -209
- package/dist/node/Effectify.js +0 -19
- package/dist/node/FileSystem.d.ts +0 -7
- package/dist/node/FileSystem.js +0 -420
- package/dist/node/NodeFileSystem.d.ts +0 -7
- package/dist/node/NodeFileSystem.js +0 -410
- package/dist/node/NodeUtils.d.ts +0 -2
- package/dist/node/NodeUtils.js +0 -20
- package/dist/node/PlatformError.d.ts +0 -46
- package/dist/node/PlatformError.js +0 -43
- package/dist/node/Utils.d.ts +0 -1
- package/dist/node/Utils.js +0 -19
- package/dist/repro_fail.d.ts +0 -1
- package/dist/repro_fail.js +0 -14
- package/dist/sql/bun/index.d.ts +0 -3
- package/dist/sql/bun/index.js +0 -75
- package/dist/sql/mssql/docker.d.ts +0 -2
- package/dist/sql/mssql/docker.js +0 -67
- package/dist/sql/mssql/index.d.ts +0 -21
- package/dist/sql/mssql/index.js +0 -113
- package/dist/testing/TestHttpClient.d.ts +0 -13
- package/dist/testing/TestHttpClient.js +0 -68
- package/dist/testing/TestLogger.d.ts +0 -13
- package/dist/testing/TestLogger.js +0 -32
- package/dist/testing/index.d.ts +0 -2
- package/dist/testing/index.js +0 -2
- package/dist/testing/utils.d.ts +0 -9
- package/dist/testing/utils.js +0 -39
- package/dist/x/cloudflare/CloudflareTunnel.d.ts +0 -10
- package/dist/x/cloudflare/CloudflareTunnel.js +0 -30
- package/dist/x/cloudflare/index.d.ts +0 -1
- package/dist/x/cloudflare/index.js +0 -1
- package/dist/x/datastar/Datastar.d.ts +0 -6
- package/dist/x/datastar/Datastar.js +0 -47
- package/dist/x/datastar/index.d.ts +0 -1
- package/dist/x/datastar/index.js +0 -1
- package/dist/x/tailscale/TailscaleTunnel.d.ts +0 -15
- package/dist/x/tailscale/TailscaleTunnel.js +0 -68
- package/dist/x/tailscale/index.d.ts +0 -1
- package/dist/x/tailscale/index.js +0 -1
- package/dist/x/tailwind/TailwindPlugin.d.ts +0 -23
- package/dist/x/tailwind/TailwindPlugin.js +0 -219
- package/dist/x/tailwind/compile.d.ts +0 -19
- package/dist/x/tailwind/compile.js +0 -154
- package/dist/x/tailwind/plugin.d.ts +0 -2
- package/dist/x/tailwind/plugin.js +0 -15
- /package/src/{Sql.ts → sql/Sql.ts} +0 -0
package/dist/bun/BunServer.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import * as Socket from "../Socket.ts";
|
|
2
|
-
import type * as Bun from "bun";
|
|
3
|
-
import * as Context from "effect/Context";
|
|
4
|
-
import * as Deferred from "effect/Deferred";
|
|
5
|
-
import * as Effect from "effect/Effect";
|
|
6
|
-
import * as Layer from "effect/Layer";
|
|
7
|
-
import type * as Scope from "effect/Scope";
|
|
8
|
-
export interface WebSocketContext {
|
|
9
|
-
readonly deferred: Deferred.Deferred<Bun.ServerWebSocket<WebSocketContext>>;
|
|
10
|
-
readonly closeDeferred: Deferred.Deferred<void, Socket.SocketError>;
|
|
11
|
-
readonly buffer: Array<Uint8Array | string>;
|
|
12
|
-
run: (_: Uint8Array | string) => void;
|
|
13
|
-
}
|
|
14
|
-
type FetchHandler = (request: Request, server: Bun.Server<WebSocketContext>) => Response | Promise<Response>;
|
|
15
|
-
/**
|
|
16
|
-
* Basically `Omit<Bun.Serve.Options, "fetch" | "error" | "websocket">`
|
|
17
|
-
* TypeScript 5.9 cannot verify discriminated union types used in
|
|
18
|
-
* {@link Bun.serve} so we need to define them explicitly.
|
|
19
|
-
*/
|
|
20
|
-
interface BunServeOptions {
|
|
21
|
-
readonly port?: number;
|
|
22
|
-
readonly hostname?: string;
|
|
23
|
-
readonly reusePort?: boolean;
|
|
24
|
-
readonly ipv6Only?: boolean;
|
|
25
|
-
readonly idleTimeout?: number;
|
|
26
|
-
readonly development?: boolean;
|
|
27
|
-
}
|
|
28
|
-
export type BunServer = {
|
|
29
|
-
readonly server: Bun.Server<WebSocketContext>;
|
|
30
|
-
readonly pushHandler: (fetch: FetchHandler) => void;
|
|
31
|
-
readonly popHandler: () => void;
|
|
32
|
-
};
|
|
33
|
-
export declare const BunServer: Context.Tag<BunServer, BunServer>;
|
|
34
|
-
export declare const make: (options: BunServeOptions) => Effect.Effect<BunServer, never, Scope.Scope>;
|
|
35
|
-
/**
|
|
36
|
-
* Provides HttpServer using BunServer under the hood.
|
|
37
|
-
*/
|
|
38
|
-
export declare const layer: (options?: BunServeOptions) => Layer.Layer<BunServer>;
|
|
39
|
-
export declare const withLogAddress: <A, E, R>(layer: Layer.Layer<A, E, R>) => Layer.Layer<A, E, R | Exclude<BunServer, A>>;
|
|
40
|
-
export {};
|
package/dist/bun/BunServer.js
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import * as Socket from "../Socket.js";
|
|
2
|
-
import * as Config from "effect/Config";
|
|
3
|
-
import * as Context from "effect/Context";
|
|
4
|
-
import * as Deferred from "effect/Deferred";
|
|
5
|
-
import * as Effect from "effect/Effect";
|
|
6
|
-
import * as Exit from "effect/Exit";
|
|
7
|
-
import * as Layer from "effect/Layer";
|
|
8
|
-
import * as Option from "effect/Option";
|
|
9
|
-
import * as Runtime from "effect/Runtime";
|
|
10
|
-
import * as NOs from "node:os";
|
|
11
|
-
import * as NPath from "node:path";
|
|
12
|
-
import * as PathPattern from "../PathPattern.js";
|
|
13
|
-
import * as PlataformRuntime from "../PlatformRuntime.js";
|
|
14
|
-
import * as Route from "../Route.js";
|
|
15
|
-
import * as RouteHttp from "../RouteHttp.js";
|
|
16
|
-
import * as RouteTree from "../RouteTree.js";
|
|
17
|
-
import * as BunRoute from "./BunRoute.js";
|
|
18
|
-
export const BunServer = Context.GenericTag("effect-start/BunServer");
|
|
19
|
-
export const make = (options) => Effect.gen(function* () {
|
|
20
|
-
const routes = yield* Effect.serviceOption(Route.Routes).pipe(Effect.andThen(Option.getOrUndefined));
|
|
21
|
-
const port = yield* Config.number("PORT").pipe(Effect.catchTag("ConfigError", () => {
|
|
22
|
-
return PlataformRuntime.isAgentHarness()
|
|
23
|
-
? Effect.succeed(0) // random port
|
|
24
|
-
: Effect.succeed(3000);
|
|
25
|
-
}));
|
|
26
|
-
const hostFlag = process.argv.includes("--host");
|
|
27
|
-
const hostname = yield* Config.string("HOSTNAME").pipe(Effect.catchTag("ConfigError", () => Effect.succeed(hostFlag ? "0.0.0.0" : undefined)));
|
|
28
|
-
const handlerStack = [
|
|
29
|
-
function (_request, _server) {
|
|
30
|
-
return new Response("not found", { status: 404 });
|
|
31
|
-
},
|
|
32
|
-
];
|
|
33
|
-
const service = BunServer.of({
|
|
34
|
-
// During the construction we need to create a service imlpementation
|
|
35
|
-
// first so we can provide it in the runtime that will be used in web
|
|
36
|
-
// handlers. After we create the runtime, we set it below so it's always
|
|
37
|
-
// available at runtime.
|
|
38
|
-
// An alternative approach would be to use Bun.Server.reload but I prefer
|
|
39
|
-
// to avoid it since it's badly documented and has bunch of bugs.
|
|
40
|
-
server: undefined,
|
|
41
|
-
pushHandler(fetch) {
|
|
42
|
-
handlerStack.push(fetch);
|
|
43
|
-
reload();
|
|
44
|
-
},
|
|
45
|
-
popHandler() {
|
|
46
|
-
handlerStack.pop();
|
|
47
|
-
reload();
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
const runtime = yield* Effect.runtime().pipe(Effect.andThen(Runtime.provideService(BunServer, service)));
|
|
51
|
-
let currentRoutes = routes ? yield* walkBunRoutes(runtime, routes) : {};
|
|
52
|
-
const websocket = {
|
|
53
|
-
open(ws) {
|
|
54
|
-
Deferred.unsafeDone(ws.data.deferred, Exit.succeed(ws));
|
|
55
|
-
},
|
|
56
|
-
message(ws, message) {
|
|
57
|
-
ws.data.run(message);
|
|
58
|
-
},
|
|
59
|
-
close(ws, code, closeReason) {
|
|
60
|
-
Deferred.unsafeDone(ws.data.closeDeferred, Socket.defaultCloseCodeIsError(code)
|
|
61
|
-
? Exit.fail(new Socket.SocketCloseError({
|
|
62
|
-
reason: "Close",
|
|
63
|
-
code,
|
|
64
|
-
closeReason,
|
|
65
|
-
}))
|
|
66
|
-
: Exit.void);
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
const server = Bun?.serve({
|
|
70
|
-
port,
|
|
71
|
-
hostname,
|
|
72
|
-
...options,
|
|
73
|
-
routes: currentRoutes,
|
|
74
|
-
fetch: handlerStack[0],
|
|
75
|
-
websocket,
|
|
76
|
-
});
|
|
77
|
-
// @ts-expect-error
|
|
78
|
-
service.server = server;
|
|
79
|
-
yield* Effect.addFinalizer(() => Effect.sync(() => {
|
|
80
|
-
server.stop();
|
|
81
|
-
}));
|
|
82
|
-
const reload = () => {
|
|
83
|
-
server.reload({
|
|
84
|
-
fetch: handlerStack[handlerStack.length - 1],
|
|
85
|
-
routes: currentRoutes,
|
|
86
|
-
websocket,
|
|
87
|
-
});
|
|
88
|
-
};
|
|
89
|
-
const bunServer = BunServer.of({
|
|
90
|
-
server,
|
|
91
|
-
pushHandler(fetch) {
|
|
92
|
-
handlerStack.push(fetch);
|
|
93
|
-
reload();
|
|
94
|
-
},
|
|
95
|
-
popHandler() {
|
|
96
|
-
handlerStack.pop();
|
|
97
|
-
reload();
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
return bunServer;
|
|
101
|
-
});
|
|
102
|
-
/**
|
|
103
|
-
* Provides HttpServer using BunServer under the hood.
|
|
104
|
-
*/
|
|
105
|
-
export const layer = (options) => Layer.scoped(BunServer, make(options ?? {}));
|
|
106
|
-
export const withLogAddress = (layer) => Layer.effectDiscard(BunServer.pipe(Effect.andThen((server) => {
|
|
107
|
-
const { hostname, port } = server.server;
|
|
108
|
-
const addr = hostname === "0.0.0.0" ? getLocalIp() : "localhost";
|
|
109
|
-
return Effect.log(`Listening on http://${addr}:${port}`);
|
|
110
|
-
}))).pipe(Layer.provideMerge(layer));
|
|
111
|
-
function walkBunRoutes(runtime, tree) {
|
|
112
|
-
return Effect.gen(function* () {
|
|
113
|
-
const bunRoutes = {};
|
|
114
|
-
const pathGroups = new Map();
|
|
115
|
-
const toWebHandler = RouteHttp.toWebHandlerRuntime(runtime);
|
|
116
|
-
for (const route of RouteTree.walk(tree)) {
|
|
117
|
-
const bunDescriptors = BunRoute.descriptors(route);
|
|
118
|
-
if (bunDescriptors) {
|
|
119
|
-
const htmlBundle = yield* Effect.promise(bunDescriptors.bunLoad);
|
|
120
|
-
if (htmlBundle.files) {
|
|
121
|
-
registerPrebuiltBundle(bunDescriptors.bunPrefix, htmlBundle, bunRoutes);
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
bunRoutes[`${bunDescriptors.bunPrefix}/*`] = htmlBundle;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
const path = Route.descriptor(route).path;
|
|
128
|
-
const group = pathGroups.get(path) ?? [];
|
|
129
|
-
group.push(route);
|
|
130
|
-
pathGroups.set(path, group);
|
|
131
|
-
}
|
|
132
|
-
for (const [path, routes] of pathGroups) {
|
|
133
|
-
const handler = toWebHandler(routes);
|
|
134
|
-
for (const bunPath of PathPattern.toBun(path)) {
|
|
135
|
-
bunRoutes[bunPath] = handler;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return bunRoutes;
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
function registerPrebuiltBundle(prefix, bundle, bunRoutes) {
|
|
142
|
-
const mainDir = NPath.dirname(Bun.main);
|
|
143
|
-
const indexPath = NPath.resolve(mainDir, bundle.index);
|
|
144
|
-
bunRoutes[`${prefix}/*`] = () => new Response(Bun.file(indexPath), { headers: { "content-type": "text/html;charset=utf-8" } });
|
|
145
|
-
for (const file of bundle.files ?? []) {
|
|
146
|
-
if (file.loader === "html")
|
|
147
|
-
continue;
|
|
148
|
-
const absPath = NPath.resolve(mainDir, file.path);
|
|
149
|
-
const basename = NPath.basename(file.path);
|
|
150
|
-
bunRoutes[`/${basename}`] = () => new Response(Bun.file(absPath), { headers: file.headers ?? {} });
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
function getLocalIp() {
|
|
154
|
-
return Object.values(NOs.networkInterfaces())
|
|
155
|
-
.flatMap((addresses) => addresses ?? [])
|
|
156
|
-
.find((addr) => addr.family === "IPv4" && !addr.internal)?.address;
|
|
157
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import type * as FileSystem from "@effect/platform/FileSystem";
|
|
2
|
-
import * as Headers from "@effect/platform/Headers";
|
|
3
|
-
import * as HttpIncomingMessage from "@effect/platform/HttpIncomingMessage";
|
|
4
|
-
import type { HttpMethod } from "@effect/platform/HttpMethod";
|
|
5
|
-
import * as HttpServerError from "@effect/platform/HttpServerError";
|
|
6
|
-
import * as HttpServerRequest from "@effect/platform/HttpServerRequest";
|
|
7
|
-
import * as HttpServerResponse from "@effect/platform/HttpServerResponse";
|
|
8
|
-
import type * as Multipart from "@effect/platform/Multipart";
|
|
9
|
-
import type * as Path from "@effect/platform/Path";
|
|
10
|
-
import * as Socket from "@effect/platform/Socket";
|
|
11
|
-
import * as UrlParams from "@effect/platform/UrlParams";
|
|
12
|
-
import type { Server as BunServerInstance, ServerWebSocket } from "bun";
|
|
13
|
-
import * as Deferred from "effect/Deferred";
|
|
14
|
-
import * as Effect from "effect/Effect";
|
|
15
|
-
import * as Inspectable from "effect/Inspectable";
|
|
16
|
-
import * as Option from "effect/Option";
|
|
17
|
-
import * as Runtime from "effect/Runtime";
|
|
18
|
-
import type * as Scope from "effect/Scope";
|
|
19
|
-
import * as Stream from "effect/Stream";
|
|
20
|
-
export interface WebSocketContext {
|
|
21
|
-
readonly deferred: Deferred.Deferred<ServerWebSocket<WebSocketContext>>;
|
|
22
|
-
readonly closeDeferred: Deferred.Deferred<void, Socket.SocketError>;
|
|
23
|
-
readonly buffer: Array<Uint8Array | string>;
|
|
24
|
-
run: (_: Uint8Array | string) => void;
|
|
25
|
-
}
|
|
26
|
-
export declare class ServerRequestImpl extends Inspectable.Class implements HttpServerRequest.HttpServerRequest {
|
|
27
|
-
readonly [HttpServerRequest.TypeId]: HttpServerRequest.TypeId;
|
|
28
|
-
readonly [HttpIncomingMessage.TypeId]: HttpIncomingMessage.TypeId;
|
|
29
|
-
readonly source: Request;
|
|
30
|
-
resolve: (response: Response) => void;
|
|
31
|
-
readonly url: string;
|
|
32
|
-
private bunServer;
|
|
33
|
-
headersOverride?: Headers.Headers;
|
|
34
|
-
private remoteAddressOverride?;
|
|
35
|
-
constructor(source: Request, resolve: (response: Response) => void, url: string, bunServer: BunServerInstance<WebSocketContext>, headersOverride?: Headers.Headers, remoteAddressOverride?: string);
|
|
36
|
-
toJSON(): unknown;
|
|
37
|
-
modify(options: {
|
|
38
|
-
readonly url?: string | undefined;
|
|
39
|
-
readonly headers?: Headers.Headers | undefined;
|
|
40
|
-
readonly remoteAddress?: string | undefined;
|
|
41
|
-
}): ServerRequestImpl;
|
|
42
|
-
get method(): HttpMethod;
|
|
43
|
-
get originalUrl(): string;
|
|
44
|
-
get remoteAddress(): Option.Option<string>;
|
|
45
|
-
get headers(): Headers.Headers;
|
|
46
|
-
private cachedCookies;
|
|
47
|
-
get cookies(): Record<string, string>;
|
|
48
|
-
get stream(): Stream.Stream<Uint8Array, HttpServerError.RequestError>;
|
|
49
|
-
private textEffect;
|
|
50
|
-
get text(): Effect.Effect<string, HttpServerError.RequestError>;
|
|
51
|
-
get json(): Effect.Effect<unknown, HttpServerError.RequestError>;
|
|
52
|
-
get urlParamsBody(): Effect.Effect<UrlParams.UrlParams, HttpServerError.RequestError>;
|
|
53
|
-
private multipartEffect;
|
|
54
|
-
get multipart(): Effect.Effect<Multipart.Persisted, Multipart.MultipartError, Scope.Scope | FileSystem.FileSystem | Path.Path>;
|
|
55
|
-
get multipartStream(): Stream.Stream<Multipart.Part, Multipart.MultipartError>;
|
|
56
|
-
private arrayBufferEffect;
|
|
57
|
-
get arrayBuffer(): Effect.Effect<ArrayBuffer, HttpServerError.RequestError>;
|
|
58
|
-
get upgrade(): Effect.Effect<Socket.Socket, HttpServerError.RequestError>;
|
|
59
|
-
}
|
|
60
|
-
export declare function makeResponse(request: HttpServerRequest.HttpServerRequest, response: HttpServerResponse.HttpServerResponse, runtime: Runtime.Runtime<never>): Response;
|
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import * as Cookies from "@effect/platform/Cookies";
|
|
2
|
-
import * as Headers from "@effect/platform/Headers";
|
|
3
|
-
import * as HttpApp from "@effect/platform/HttpApp";
|
|
4
|
-
import * as HttpIncomingMessage from "@effect/platform/HttpIncomingMessage";
|
|
5
|
-
import * as HttpServerError from "@effect/platform/HttpServerError";
|
|
6
|
-
import * as HttpServerRequest from "@effect/platform/HttpServerRequest";
|
|
7
|
-
import * as Socket from "@effect/platform/Socket";
|
|
8
|
-
import * as UrlParams from "@effect/platform/UrlParams";
|
|
9
|
-
import * as Deferred from "effect/Deferred";
|
|
10
|
-
import * as Effect from "effect/Effect";
|
|
11
|
-
import * as FiberSet from "effect/FiberSet";
|
|
12
|
-
import * as Inspectable from "effect/Inspectable";
|
|
13
|
-
import * as Option from "effect/Option";
|
|
14
|
-
import * as Stream from "effect/Stream";
|
|
15
|
-
export class ServerRequestImpl extends Inspectable.Class {
|
|
16
|
-
[HttpServerRequest.TypeId];
|
|
17
|
-
[HttpIncomingMessage.TypeId];
|
|
18
|
-
source;
|
|
19
|
-
resolve;
|
|
20
|
-
url;
|
|
21
|
-
bunServer;
|
|
22
|
-
headersOverride;
|
|
23
|
-
remoteAddressOverride;
|
|
24
|
-
constructor(source, resolve, url, bunServer, headersOverride, remoteAddressOverride) {
|
|
25
|
-
super();
|
|
26
|
-
this[HttpServerRequest.TypeId] = HttpServerRequest.TypeId;
|
|
27
|
-
this[HttpIncomingMessage.TypeId] = HttpIncomingMessage.TypeId;
|
|
28
|
-
this.source = source;
|
|
29
|
-
this.resolve = resolve;
|
|
30
|
-
this.url = url;
|
|
31
|
-
this.bunServer = bunServer;
|
|
32
|
-
this.headersOverride = headersOverride;
|
|
33
|
-
this.remoteAddressOverride = remoteAddressOverride;
|
|
34
|
-
}
|
|
35
|
-
toJSON() {
|
|
36
|
-
return HttpIncomingMessage.inspect(this, {
|
|
37
|
-
_id: "@effect/platform/HttpServerRequest",
|
|
38
|
-
method: this.method,
|
|
39
|
-
url: this.originalUrl,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
modify(options) {
|
|
43
|
-
return new ServerRequestImpl(this.source, this.resolve, options.url ?? this.url, this.bunServer, options.headers ?? this.headersOverride, options.remoteAddress ?? this.remoteAddressOverride);
|
|
44
|
-
}
|
|
45
|
-
get method() {
|
|
46
|
-
return this.source.method.toUpperCase();
|
|
47
|
-
}
|
|
48
|
-
get originalUrl() {
|
|
49
|
-
return this.source.url;
|
|
50
|
-
}
|
|
51
|
-
get remoteAddress() {
|
|
52
|
-
return this.remoteAddressOverride
|
|
53
|
-
? Option.some(this.remoteAddressOverride)
|
|
54
|
-
: Option.fromNullable(this.bunServer.requestIP(this.source)?.address);
|
|
55
|
-
}
|
|
56
|
-
get headers() {
|
|
57
|
-
this.headersOverride ??= Headers.fromInput(this.source.headers);
|
|
58
|
-
return this.headersOverride;
|
|
59
|
-
}
|
|
60
|
-
cachedCookies;
|
|
61
|
-
get cookies() {
|
|
62
|
-
if (this.cachedCookies) {
|
|
63
|
-
return this.cachedCookies;
|
|
64
|
-
}
|
|
65
|
-
return this.cachedCookies = Cookies.parseHeader(this.headers.cookie ?? "");
|
|
66
|
-
}
|
|
67
|
-
get stream() {
|
|
68
|
-
return this.source.body
|
|
69
|
-
? Stream.fromReadableStream(() => this.source.body, (cause) => new HttpServerError.RequestError({
|
|
70
|
-
request: this,
|
|
71
|
-
reason: "Decode",
|
|
72
|
-
cause,
|
|
73
|
-
}))
|
|
74
|
-
: Stream.fail(new HttpServerError.RequestError({
|
|
75
|
-
request: this,
|
|
76
|
-
reason: "Decode",
|
|
77
|
-
description: "can not create stream from empty body",
|
|
78
|
-
}));
|
|
79
|
-
}
|
|
80
|
-
textEffect;
|
|
81
|
-
get text() {
|
|
82
|
-
if (this.textEffect) {
|
|
83
|
-
return this.textEffect;
|
|
84
|
-
}
|
|
85
|
-
this.textEffect = Effect.runSync(Effect.cached(Effect.tryPromise({
|
|
86
|
-
try: () => this.source.text(),
|
|
87
|
-
catch: (cause) => new HttpServerError.RequestError({
|
|
88
|
-
request: this,
|
|
89
|
-
reason: "Decode",
|
|
90
|
-
cause,
|
|
91
|
-
}),
|
|
92
|
-
})));
|
|
93
|
-
return this.textEffect;
|
|
94
|
-
}
|
|
95
|
-
get json() {
|
|
96
|
-
return Effect.tryMap(this.text, {
|
|
97
|
-
try: (_) => JSON.parse(_),
|
|
98
|
-
catch: (cause) => new HttpServerError.RequestError({
|
|
99
|
-
request: this,
|
|
100
|
-
reason: "Decode",
|
|
101
|
-
cause,
|
|
102
|
-
}),
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
get urlParamsBody() {
|
|
106
|
-
return Effect.flatMap(this.text, (_) => Effect.try({
|
|
107
|
-
try: () => UrlParams.fromInput(new URLSearchParams(_)),
|
|
108
|
-
catch: (cause) => new HttpServerError.RequestError({
|
|
109
|
-
request: this,
|
|
110
|
-
reason: "Decode",
|
|
111
|
-
cause,
|
|
112
|
-
}),
|
|
113
|
-
}));
|
|
114
|
-
}
|
|
115
|
-
multipartEffect;
|
|
116
|
-
get multipart() {
|
|
117
|
-
if (this.multipartEffect) {
|
|
118
|
-
return this.multipartEffect;
|
|
119
|
-
}
|
|
120
|
-
this.multipartEffect = Effect.runSync(Effect.cached(Effect.die("Multipart not implemented")));
|
|
121
|
-
return this.multipartEffect;
|
|
122
|
-
}
|
|
123
|
-
get multipartStream() {
|
|
124
|
-
return Stream.die("Multipart stream not implemented");
|
|
125
|
-
}
|
|
126
|
-
arrayBufferEffect;
|
|
127
|
-
get arrayBuffer() {
|
|
128
|
-
if (this.arrayBufferEffect) {
|
|
129
|
-
return this.arrayBufferEffect;
|
|
130
|
-
}
|
|
131
|
-
this.arrayBufferEffect = Effect.runSync(Effect.cached(Effect.tryPromise({
|
|
132
|
-
try: () => this.source.arrayBuffer(),
|
|
133
|
-
catch: (cause) => new HttpServerError.RequestError({
|
|
134
|
-
request: this,
|
|
135
|
-
reason: "Decode",
|
|
136
|
-
cause,
|
|
137
|
-
}),
|
|
138
|
-
})));
|
|
139
|
-
return this.arrayBufferEffect;
|
|
140
|
-
}
|
|
141
|
-
get upgrade() {
|
|
142
|
-
return Effect.flatMap(Effect.all([
|
|
143
|
-
Deferred.make(),
|
|
144
|
-
Deferred.make(),
|
|
145
|
-
Effect.makeSemaphore(1),
|
|
146
|
-
]), ([deferred, closeDeferred, semaphore]) => Effect.async((resume) => {
|
|
147
|
-
const success = this.bunServer.upgrade(this.source, {
|
|
148
|
-
data: {
|
|
149
|
-
deferred,
|
|
150
|
-
closeDeferred,
|
|
151
|
-
buffer: [],
|
|
152
|
-
run: wsDefaultRun,
|
|
153
|
-
},
|
|
154
|
-
});
|
|
155
|
-
if (!success) {
|
|
156
|
-
resume(Effect.fail(new HttpServerError.RequestError({
|
|
157
|
-
request: this,
|
|
158
|
-
reason: "Decode",
|
|
159
|
-
description: "Not an upgradeable ServerRequest",
|
|
160
|
-
})));
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
resume(Effect.map(Deferred.await(deferred), (ws) => {
|
|
164
|
-
const write = (chunk) => Effect.sync(() => {
|
|
165
|
-
if (typeof chunk === "string") {
|
|
166
|
-
ws.sendText(chunk);
|
|
167
|
-
}
|
|
168
|
-
else if (Socket.isCloseEvent(chunk)) {
|
|
169
|
-
ws.close(chunk.code, chunk.reason);
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
ws.sendBinary(chunk);
|
|
173
|
-
}
|
|
174
|
-
return true;
|
|
175
|
-
});
|
|
176
|
-
const writer = Effect.succeed(write);
|
|
177
|
-
const runRaw = Effect.fnUntraced(function* (handler, opts) {
|
|
178
|
-
const set = yield* FiberSet.make();
|
|
179
|
-
const run = yield* FiberSet.runtime(set)();
|
|
180
|
-
function runRawInner(data) {
|
|
181
|
-
const result = handler(data);
|
|
182
|
-
if (Effect.isEffect(result)) {
|
|
183
|
-
run(result);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
ws.data.run = runRawInner;
|
|
187
|
-
ws.data.buffer.forEach(runRawInner);
|
|
188
|
-
ws.data.buffer.length = 0;
|
|
189
|
-
if (opts?.onOpen)
|
|
190
|
-
yield* opts.onOpen;
|
|
191
|
-
return yield* FiberSet.join(set);
|
|
192
|
-
}, Effect.scoped, Effect.onExit((exit) => {
|
|
193
|
-
ws.close(exit._tag === "Success" ? 1000 : 1011);
|
|
194
|
-
return Effect.void;
|
|
195
|
-
}), Effect.raceFirst(Deferred.await(closeDeferred)), semaphore.withPermits(1));
|
|
196
|
-
const encoder = new TextEncoder();
|
|
197
|
-
const run = (handler, opts) => runRaw((data) => typeof data === "string"
|
|
198
|
-
? handler(encoder.encode(data))
|
|
199
|
-
: handler(data), opts);
|
|
200
|
-
return Socket.Socket.of({
|
|
201
|
-
[Socket.TypeId]: Socket.TypeId,
|
|
202
|
-
run,
|
|
203
|
-
runRaw,
|
|
204
|
-
writer,
|
|
205
|
-
});
|
|
206
|
-
}));
|
|
207
|
-
}));
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
function wsDefaultRun(_) {
|
|
211
|
-
this.buffer.push(_);
|
|
212
|
-
}
|
|
213
|
-
export function makeResponse(request, response, runtime) {
|
|
214
|
-
const fields = {
|
|
215
|
-
headers: new globalThis.Headers(response.headers),
|
|
216
|
-
status: response.status,
|
|
217
|
-
};
|
|
218
|
-
if (!Cookies.isEmpty(response.cookies)) {
|
|
219
|
-
for (const header of Cookies.toSetCookieHeaders(response.cookies)) {
|
|
220
|
-
fields.headers.append("set-cookie", header);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
if (response.statusText !== undefined) {
|
|
224
|
-
fields.statusText = response.statusText;
|
|
225
|
-
}
|
|
226
|
-
if (request.method === "HEAD") {
|
|
227
|
-
return new Response(undefined, fields);
|
|
228
|
-
}
|
|
229
|
-
const ejectedResponse = HttpApp.unsafeEjectStreamScope(response);
|
|
230
|
-
const body = ejectedResponse.body;
|
|
231
|
-
switch (body._tag) {
|
|
232
|
-
case "Empty": {
|
|
233
|
-
return new Response(undefined, fields);
|
|
234
|
-
}
|
|
235
|
-
case "Uint8Array":
|
|
236
|
-
case "Raw": {
|
|
237
|
-
if (body.body instanceof Response) {
|
|
238
|
-
for (const [key, value] of fields.headers.entries()) {
|
|
239
|
-
body.body.headers.set(key, value);
|
|
240
|
-
}
|
|
241
|
-
return body.body;
|
|
242
|
-
}
|
|
243
|
-
return new Response(body.body, fields);
|
|
244
|
-
}
|
|
245
|
-
case "FormData": {
|
|
246
|
-
return new Response(body.formData, fields);
|
|
247
|
-
}
|
|
248
|
-
case "Stream": {
|
|
249
|
-
return new Response(Stream.toReadableStreamRuntime(body.stream, runtime), fields);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
}
|
package/dist/bun/BunSql.d.ts
DELETED
package/dist/bun/BunSql.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import * as Effect from "effect/Effect";
|
|
2
|
-
import * as Exit from "effect/Exit";
|
|
3
|
-
import * as FiberRef from "effect/FiberRef";
|
|
4
|
-
import * as GlobalValue from "effect/GlobalValue";
|
|
5
|
-
import * as Layer from "effect/Layer";
|
|
6
|
-
import * as Option from "effect/Option";
|
|
7
|
-
import * as Sql from "../Sql.js";
|
|
8
|
-
const wrapError = (error) => new Sql.SqlError({
|
|
9
|
-
code: error?.code ?? "UNKNOWN",
|
|
10
|
-
message: error instanceof Error ? error.message : String(error),
|
|
11
|
-
cause: error,
|
|
12
|
-
});
|
|
13
|
-
const wrapQuery = (promise) => Effect.tryPromise({ try: () => promise, catch: wrapError });
|
|
14
|
-
const makeValues = (obj, ...columns) => {
|
|
15
|
-
const items = Array.isArray(obj) ? obj : [obj];
|
|
16
|
-
const cols = columns.length > 0 ? columns : Object.keys(items[0]);
|
|
17
|
-
return { value: items, columns: cols };
|
|
18
|
-
};
|
|
19
|
-
const currentTransaction = GlobalValue.globalValue(Symbol.for("effect-start/BunSql/currentTransaction"), () => FiberRef.unsafeMake(Option.none()));
|
|
20
|
-
const runQuery = (bunSql, strings, values) => Effect.flatMap(FiberRef.get(currentTransaction), (txOpt) => {
|
|
21
|
-
if (Option.isSome(txOpt)) {
|
|
22
|
-
return wrapQuery(txOpt.value.conn(strings, ...values));
|
|
23
|
-
}
|
|
24
|
-
return wrapQuery(bunSql(strings, ...values));
|
|
25
|
-
});
|
|
26
|
-
const runUnsafe = (bunSql, query, values) => Effect.flatMap(FiberRef.get(currentTransaction), (txOpt) => {
|
|
27
|
-
if (Option.isSome(txOpt)) {
|
|
28
|
-
return wrapQuery(txOpt.value.conn.unsafe(query, values));
|
|
29
|
-
}
|
|
30
|
-
return wrapQuery(bunSql.unsafe(query, values));
|
|
31
|
-
});
|
|
32
|
-
const makeWithTransaction = (bunSql) => (self) => Effect.uninterruptibleMask((restore) => Effect.flatMap(FiberRef.get(currentTransaction), (txOpt) => {
|
|
33
|
-
if (Option.isSome(txOpt)) {
|
|
34
|
-
const { conn, depth } = txOpt.value;
|
|
35
|
-
const name = `sp_${depth}`;
|
|
36
|
-
return Effect.gen(function* () {
|
|
37
|
-
yield* wrapQuery(conn.unsafe(`SAVEPOINT ${name}`));
|
|
38
|
-
const exit = yield* Effect.exit(restore(Effect.locally(self, currentTransaction, Option.some({ conn, depth: depth + 1 }))));
|
|
39
|
-
if (Exit.isSuccess(exit)) {
|
|
40
|
-
yield* wrapQuery(conn.unsafe(`RELEASE SAVEPOINT ${name}`));
|
|
41
|
-
return exit.value;
|
|
42
|
-
}
|
|
43
|
-
yield* wrapQuery(conn.unsafe(`ROLLBACK TO SAVEPOINT ${name}`)).pipe(Effect.orDie);
|
|
44
|
-
return yield* exit;
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
const runTx = (conn) => Effect.gen(function* () {
|
|
48
|
-
yield* wrapQuery(conn.unsafe("BEGIN"));
|
|
49
|
-
const exit = yield* Effect.exit(restore(Effect.locally(self, currentTransaction, Option.some({ conn, depth: 1 }))));
|
|
50
|
-
if (Exit.isSuccess(exit)) {
|
|
51
|
-
yield* wrapQuery(conn.unsafe("COMMIT"));
|
|
52
|
-
return exit.value;
|
|
53
|
-
}
|
|
54
|
-
yield* wrapQuery(conn.unsafe("ROLLBACK")).pipe(Effect.orDie);
|
|
55
|
-
return yield* exit;
|
|
56
|
-
});
|
|
57
|
-
return Effect.matchEffect(Effect.tryPromise({ try: () => bunSql.reserve(), catch: wrapError }), {
|
|
58
|
-
onFailure: () => runTx(bunSql),
|
|
59
|
-
onSuccess: (reserved) => Effect.ensuring(runTx(reserved), Effect.sync(() => reserved.release())),
|
|
60
|
-
});
|
|
61
|
-
}));
|
|
62
|
-
export const layer = (config) => Layer.scoped(Sql.SqlClient, Effect.acquireRelease(Effect.try({
|
|
63
|
-
try: () => {
|
|
64
|
-
const bunSql = new Bun.SQL(config);
|
|
65
|
-
return Object.assign((strings, ...values) => runQuery(bunSql, strings, values), {
|
|
66
|
-
unsafe: (query, values) => runUnsafe(bunSql, query, values),
|
|
67
|
-
values: makeValues,
|
|
68
|
-
withTransaction: makeWithTransaction(bunSql),
|
|
69
|
-
reserve: Effect.acquireRelease(Effect.tryPromise({ try: () => bunSql.reserve(), catch: wrapError }), (reserved) => Effect.sync(() => reserved.release())).pipe(Effect.map((reserved) => Object.assign((strings, ...values) => wrapQuery(reserved(strings, ...values)), {
|
|
70
|
-
unsafe: (query, values) => wrapQuery(reserved.unsafe(query, values)),
|
|
71
|
-
values: makeValues,
|
|
72
|
-
}))),
|
|
73
|
-
close: (options) => wrapQuery(bunSql.close(options)),
|
|
74
|
-
});
|
|
75
|
-
},
|
|
76
|
-
catch: wrapError,
|
|
77
|
-
}), (client) => client.close().pipe(Effect.orDie)));
|
|
78
|
-
export const layerMemory = layer({
|
|
79
|
-
adapter: "sqlite",
|
|
80
|
-
filename: ":memory:",
|
|
81
|
-
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
function loaderFromPath(path) {
|
|
2
|
-
return path.slice(path.lastIndexOf(".") + 1);
|
|
3
|
-
}
|
|
4
|
-
export function make(files) {
|
|
5
|
-
return {
|
|
6
|
-
name: "virtual-fs",
|
|
7
|
-
setup(build) {
|
|
8
|
-
build.onResolve({
|
|
9
|
-
// change the filter so it only works for file namespace
|
|
10
|
-
filter: /.*/,
|
|
11
|
-
}, (args) => {
|
|
12
|
-
const resolved = resolvePath(args.path, args.resolveDir);
|
|
13
|
-
const resolvedFile = files[resolved];
|
|
14
|
-
if (resolvedFile) {
|
|
15
|
-
return {
|
|
16
|
-
path: resolved,
|
|
17
|
-
namespace: "virtual-fs",
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
return;
|
|
21
|
-
});
|
|
22
|
-
build.onLoad({
|
|
23
|
-
filter: /.*/,
|
|
24
|
-
namespace: "virtual-fs",
|
|
25
|
-
}, (args) => {
|
|
26
|
-
const contents = files[args.path];
|
|
27
|
-
if (!contents) {
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
|
-
return {
|
|
31
|
-
contents,
|
|
32
|
-
loader: loaderFromPath(args.path),
|
|
33
|
-
};
|
|
34
|
-
});
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function resolvePath(path, base = process.cwd()) {
|
|
39
|
-
return Bun.resolveSync(path, base);
|
|
40
|
-
}
|