effect-start 0.25.0 → 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/dist/ChildProcess.js +0 -42
- package/dist/Commander.js +0 -410
- package/dist/ContentNegotiation.js +0 -465
- package/dist/Cookies.js +0 -371
- package/dist/Development.js +0 -94
- package/dist/Effectify.js +0 -27
- package/dist/Entity.js +0 -289
- package/dist/Fetch.js +0 -192
- package/dist/FilePathPattern.js +0 -97
- package/dist/FileRouter.js +0 -204
- package/dist/FileRouterCodegen.js +0 -298
- package/dist/FileSystem.js +0 -132
- package/dist/Http.js +0 -107
- package/dist/PathPattern.js +0 -451
- package/dist/PlatformError.js +0 -40
- package/dist/PlatformRuntime.js +0 -71
- package/dist/Route.js +0 -143
- package/dist/RouteBody.js +0 -92
- package/dist/RouteError.js +0 -76
- package/dist/RouteHook.js +0 -64
- package/dist/RouteHttp.js +0 -367
- package/dist/RouteHttpTracer.js +0 -90
- package/dist/RouteMount.js +0 -86
- package/dist/RouteSchema.js +0 -271
- package/dist/RouteSse.js +0 -94
- package/dist/RouteTree.js +0 -119
- package/dist/RouteTrie.js +0 -179
- package/dist/SchemaExtra.js +0 -99
- package/dist/Socket.js +0 -40
- package/dist/SqlIntrospect.js +0 -515
- package/dist/Start.js +0 -79
- package/dist/StartApp.js +0 -3
- package/dist/StreamExtra.js +0 -135
- package/dist/System.js +0 -38
- package/dist/TuplePathPattern.js +0 -74
- package/dist/Unique.js +0 -226
- package/dist/Values.js +0 -52
- package/dist/bun/BunBundle.js +0 -186
- package/dist/bun/BunChildProcessSpawner.js +0 -142
- package/dist/bun/BunImportTrackerPlugin.js +0 -91
- package/dist/bun/BunRoute.js +0 -157
- package/dist/bun/BunRuntime.js +0 -41
- package/dist/bun/BunServer.js +0 -285
- package/dist/bun/BunVirtualFilesPlugin.js +0 -54
- package/dist/bun/_BunEnhancedResolve.js +0 -127
- package/dist/bun/index.js +0 -5
- package/dist/bundler/Bundle.js +0 -92
- package/dist/bundler/BundleFiles.js +0 -154
- package/dist/bundler/BundleRoute.js +0 -62
- package/dist/client/Overlay.js +0 -33
- package/dist/client/ScrollState.js +0 -106
- package/dist/client/index.js +0 -97
- package/dist/console/Console.js +0 -42
- package/dist/console/ConsoleErrors.js +0 -211
- package/dist/console/ConsoleLogger.js +0 -56
- package/dist/console/ConsoleMetrics.js +0 -72
- package/dist/console/ConsoleProcess.js +0 -59
- package/dist/console/ConsoleStore.js +0 -72
- package/dist/console/ConsoleTracer.js +0 -107
- package/dist/console/Simulation.js +0 -784
- package/dist/console/index.js +0 -3
- package/dist/console/routes/tree.js +0 -30
- package/dist/datastar/actions/fetch.js +0 -536
- package/dist/datastar/actions/peek.js +0 -13
- package/dist/datastar/actions/setAll.js +0 -19
- package/dist/datastar/actions/toggleAll.js +0 -19
- package/dist/datastar/attributes/attr.js +0 -49
- package/dist/datastar/attributes/bind.js +0 -194
- package/dist/datastar/attributes/class.js +0 -54
- package/dist/datastar/attributes/computed.js +0 -25
- package/dist/datastar/attributes/effect.js +0 -10
- package/dist/datastar/attributes/indicator.js +0 -33
- package/dist/datastar/attributes/init.js +0 -27
- package/dist/datastar/attributes/jsonSignals.js +0 -33
- package/dist/datastar/attributes/on.js +0 -81
- package/dist/datastar/attributes/onIntersect.js +0 -53
- package/dist/datastar/attributes/onInterval.js +0 -31
- package/dist/datastar/attributes/onSignalPatch.js +0 -51
- package/dist/datastar/attributes/ref.js +0 -11
- package/dist/datastar/attributes/show.js +0 -32
- package/dist/datastar/attributes/signals.js +0 -18
- package/dist/datastar/attributes/style.js +0 -57
- package/dist/datastar/attributes/text.js +0 -29
- package/dist/datastar/engine.js +0 -1145
- package/dist/datastar/index.js +0 -25
- package/dist/datastar/utils.js +0 -250
- package/dist/datastar/watchers/patchElements.js +0 -486
- package/dist/datastar/watchers/patchSignals.js +0 -14
- package/dist/experimental/EncryptedCookies.js +0 -328
- package/dist/experimental/index.js +0 -1
- package/dist/hyper/Hyper.js +0 -28
- package/dist/hyper/HyperHtml.js +0 -165
- package/dist/hyper/HyperNode.js +0 -13
- package/dist/hyper/HyperRoute.js +0 -45
- package/dist/hyper/html.js +0 -30
- package/dist/hyper/index.js +0 -5
- package/dist/hyper/jsx-runtime.js +0 -14
- package/dist/index.js +0 -8
- package/dist/node/NodeFileSystem.js +0 -675
- package/dist/node/NodeUtils.js +0 -23
- package/dist/sql/Sql.js +0 -8
- package/dist/sql/bun/index.js +0 -142
- package/dist/sql/index.js +0 -1
- package/dist/sql/libsql/index.js +0 -156
- package/dist/sql/mssql/docker.js +0 -110
- package/dist/sql/mssql/index.js +0 -194
- package/dist/testing/TestLogger.js +0 -42
- package/dist/testing/index.js +0 -2
- package/dist/testing/utils.js +0 -61
- package/dist/x/cloudflare/CloudflareTunnel.js +0 -63
- package/dist/x/cloudflare/index.js +0 -1
- package/dist/x/tailscale/TailscaleTunnel.js +0 -94
- package/dist/x/tailscale/index.js +0 -1
- package/dist/x/tailwind/TailwindPlugin.js +0 -294
- package/dist/x/tailwind/compile.js +0 -210
- package/dist/x/tailwind/plugin.js +0 -17
package/dist/bun/BunBundle.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { Array, Effect, Iterable, Layer, pipe, Record } from "effect"
|
|
2
|
-
import * as NPath from "node:path"
|
|
3
|
-
import * as Bundle from "../bundler/Bundle.js"
|
|
4
|
-
|
|
5
|
-
export const buildClient = (config) => {
|
|
6
|
-
if (typeof config === "string") {
|
|
7
|
-
config = {
|
|
8
|
-
entrypoints: [config],
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const baseConfig = /** @type {const} */ {
|
|
13
|
-
sourcemap: "linked",
|
|
14
|
-
naming: {
|
|
15
|
-
entry: "[name]-[hash].[ext]",
|
|
16
|
-
chunk: "[name]-[hash].[ext]",
|
|
17
|
-
asset: "[name]-[hash].[ext]",
|
|
18
|
-
},
|
|
19
|
-
packages: "bundle",
|
|
20
|
-
publicPath: "/_bundle/",
|
|
21
|
-
}
|
|
22
|
-
const resolvedConfig = {
|
|
23
|
-
...baseConfig,
|
|
24
|
-
target: /** @type {const} */ "browser",
|
|
25
|
-
...config,
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return build(resolvedConfig)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const buildServer = (config) => {
|
|
32
|
-
if (typeof config === "string") {
|
|
33
|
-
config = {
|
|
34
|
-
entrypoints: [config],
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const baseConfig = /** @type {const} */ {
|
|
39
|
-
sourcemap: "linked",
|
|
40
|
-
naming: {
|
|
41
|
-
entry: "[dir]/[name]-[hash].[ext]",
|
|
42
|
-
chunk: "[name]-[hash].[ext]",
|
|
43
|
-
asset: "[name]-[hash].[ext]",
|
|
44
|
-
},
|
|
45
|
-
packages: "bundle",
|
|
46
|
-
}
|
|
47
|
-
const resolvedConfig = {
|
|
48
|
-
...baseConfig,
|
|
49
|
-
target: /** @type {const} */ "bun",
|
|
50
|
-
...config,
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return build(resolvedConfig)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Given a config, build a bundle and returns every time when effect is executed.
|
|
58
|
-
*/
|
|
59
|
-
export function build(
|
|
60
|
-
config,
|
|
61
|
-
) {
|
|
62
|
-
return Effect.gen(function* () {
|
|
63
|
-
const output = yield* buildBun(config)
|
|
64
|
-
const manifest = generateManifestfromBunBundle(config, output)
|
|
65
|
-
const artifactsMap = Record.fromIterableBy(output.outputs, (v) => v.path.replace(/^\.\//, ""))
|
|
66
|
-
|
|
67
|
-
const resolve = (path) => {
|
|
68
|
-
return manifest.entrypoints[path] ?? null
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const getArtifact = (path) => {
|
|
72
|
-
return artifactsMap[resolve(path)] ?? artifactsMap[path] ?? null
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return {
|
|
76
|
-
...manifest,
|
|
77
|
-
resolve,
|
|
78
|
-
getArtifact,
|
|
79
|
-
}
|
|
80
|
-
})
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function layer(tag, config) {
|
|
84
|
-
return Layer.effect(tag, build(config))
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Finds common path prefix across provided paths.
|
|
89
|
-
*/
|
|
90
|
-
function getBaseDir(paths) {
|
|
91
|
-
if (paths.length === 0) return ""
|
|
92
|
-
if (paths.length === 1) return NPath.dirname(paths[0])
|
|
93
|
-
|
|
94
|
-
const segmentsList = paths.map((path) => NPath.dirname(path).split("/").filter(Boolean))
|
|
95
|
-
|
|
96
|
-
return (
|
|
97
|
-
segmentsList[0]
|
|
98
|
-
.filter((segment, i) => segmentsList.every((segs) => segs[i] === segment))
|
|
99
|
-
.reduce((path, seg) => `${path}/${seg}`, "") ?? ""
|
|
100
|
-
)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Maps entrypoints to their respective build artifacts.
|
|
105
|
-
* Entrypoint key is trimmed to remove common path prefix.
|
|
106
|
-
*/
|
|
107
|
-
function joinBuildEntrypoints(options, output) {
|
|
108
|
-
const commonPathPrefix = getBaseDir(options.entrypoints) + "/"
|
|
109
|
-
|
|
110
|
-
return pipe(
|
|
111
|
-
Iterable.zip(
|
|
112
|
-
options.entrypoints,
|
|
113
|
-
pipe(
|
|
114
|
-
output.outputs,
|
|
115
|
-
// Filter out source maps to properly map artifacts to entrypoints.
|
|
116
|
-
Iterable.filter(
|
|
117
|
-
(v) => v.kind !== "sourcemap" && !(v.loader === "html" && v.path.endsWith(".js")),
|
|
118
|
-
),
|
|
119
|
-
),
|
|
120
|
-
),
|
|
121
|
-
Iterable.map(([entrypoint, artifact]) => {
|
|
122
|
-
return /** @type {const} */ {
|
|
123
|
-
shortPath: entrypoint.replace(commonPathPrefix, ""),
|
|
124
|
-
fullPath: entrypoint,
|
|
125
|
-
artifact,
|
|
126
|
-
}
|
|
127
|
-
}),
|
|
128
|
-
)
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Generate manifest from a build.
|
|
133
|
-
* Useful for SSR and providing source->artifact path mapping.
|
|
134
|
-
*/
|
|
135
|
-
function generateManifestfromBunBundle(
|
|
136
|
-
options,
|
|
137
|
-
output,
|
|
138
|
-
imports,
|
|
139
|
-
) {
|
|
140
|
-
const entrypointArtifacts = joinBuildEntrypoints(options, output)
|
|
141
|
-
|
|
142
|
-
return {
|
|
143
|
-
entrypoints: pipe(
|
|
144
|
-
entrypointArtifacts,
|
|
145
|
-
Iterable.map((v) => /** @type {const} */ [v.shortPath, v.artifact.path.replace(/^\.\//, "")]),
|
|
146
|
-
Record.fromEntries,
|
|
147
|
-
),
|
|
148
|
-
|
|
149
|
-
artifacts: pipe(
|
|
150
|
-
output.outputs,
|
|
151
|
-
Iterable.map((v) => {
|
|
152
|
-
// strip './' prefix
|
|
153
|
-
const shortPath = v.path.replace(/^\.\//, "")
|
|
154
|
-
|
|
155
|
-
return {
|
|
156
|
-
path: shortPath,
|
|
157
|
-
type: v.type,
|
|
158
|
-
size: v.size,
|
|
159
|
-
hash: v.hash ?? undefined,
|
|
160
|
-
imports: imports?.get(v.path),
|
|
161
|
-
}
|
|
162
|
-
}),
|
|
163
|
-
Array.fromIterable,
|
|
164
|
-
),
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function buildBun(config) {
|
|
169
|
-
return Object.assign(
|
|
170
|
-
Effect.gen(function* () {
|
|
171
|
-
const buildOutput = yield* Effect.tryPromise({
|
|
172
|
-
try: () => Bun.build(config),
|
|
173
|
-
catch: (err) => {
|
|
174
|
-
const cause = err instanceof AggregateError ? (err.errors?.[0] ?? err) : err
|
|
175
|
-
|
|
176
|
-
return new Bundle.BundleError({
|
|
177
|
-
message: "Failed to Bun.build: " + cause,
|
|
178
|
-
cause: cause,
|
|
179
|
-
})
|
|
180
|
-
},
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
return buildOutput
|
|
184
|
-
}),
|
|
185
|
-
)
|
|
186
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import * as Effect from "effect/Effect"
|
|
2
|
-
import * as Layer from "effect/Layer"
|
|
3
|
-
import * as Sink from "effect/Sink"
|
|
4
|
-
import * as Stream from "effect/Stream"
|
|
5
|
-
import * as ChildProcess from "../ChildProcess.js"
|
|
6
|
-
import * as PlatformError from "../PlatformError.js"
|
|
7
|
-
|
|
8
|
-
const toCmd = (command) => [
|
|
9
|
-
command.command,
|
|
10
|
-
...command.args,
|
|
11
|
-
]
|
|
12
|
-
|
|
13
|
-
export const layer = Layer.succeed(
|
|
14
|
-
ChildProcess.ChildProcessSpawner,
|
|
15
|
-
{
|
|
16
|
-
spawn: (command) =>
|
|
17
|
-
Effect.gen(function* () {
|
|
18
|
-
const cmd = toCmd(command)
|
|
19
|
-
|
|
20
|
-
const proc = yield* Effect.try({
|
|
21
|
-
try: () =>
|
|
22
|
-
Bun.spawn(cmd, {
|
|
23
|
-
cwd: command.cwd,
|
|
24
|
-
env: command.env,
|
|
25
|
-
stdin: command.stdin ?? "ignore",
|
|
26
|
-
stdout: command.stdout ?? "pipe",
|
|
27
|
-
stderr: command.stderr ?? "pipe",
|
|
28
|
-
detached: command.detached,
|
|
29
|
-
}),
|
|
30
|
-
catch: (err) =>
|
|
31
|
-
new PlatformError.SystemError({
|
|
32
|
-
reason: "Unknown",
|
|
33
|
-
module: "ChildProcess",
|
|
34
|
-
method: "spawn",
|
|
35
|
-
description: err instanceof Error ? err.message : "Failed to spawn process",
|
|
36
|
-
cause: err,
|
|
37
|
-
}),
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
yield* Effect.addFinalizer(() =>
|
|
41
|
-
Effect.sync(() => {
|
|
42
|
-
if (!proc.killed) {
|
|
43
|
-
proc.kill()
|
|
44
|
-
}
|
|
45
|
-
}),
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
const handle = {
|
|
49
|
-
pid: proc.pid,
|
|
50
|
-
|
|
51
|
-
exitCode: Effect.tryPromise({
|
|
52
|
-
try: () => proc.exited,
|
|
53
|
-
catch: (err) =>
|
|
54
|
-
new PlatformError.SystemError({
|
|
55
|
-
reason: "Unknown",
|
|
56
|
-
module: "ChildProcess",
|
|
57
|
-
method: "exitCode",
|
|
58
|
-
description: "Process exited unexpectedly",
|
|
59
|
-
cause: err,
|
|
60
|
-
}),
|
|
61
|
-
}),
|
|
62
|
-
|
|
63
|
-
isRunning: Effect.try({
|
|
64
|
-
try: () => !proc.killed && proc.exitCode === null,
|
|
65
|
-
catch: (err) =>
|
|
66
|
-
new PlatformError.SystemError({
|
|
67
|
-
reason: "BadResource",
|
|
68
|
-
module: "ChildProcess",
|
|
69
|
-
method: "isRunning",
|
|
70
|
-
description: err instanceof Error ? err.message : "Failed to check process status",
|
|
71
|
-
cause: err,
|
|
72
|
-
}),
|
|
73
|
-
}),
|
|
74
|
-
|
|
75
|
-
kill: (options) =>
|
|
76
|
-
Effect.try({
|
|
77
|
-
try: () => {
|
|
78
|
-
proc.kill(options?.killSignal)
|
|
79
|
-
},
|
|
80
|
-
catch: (err) =>
|
|
81
|
-
new PlatformError.SystemError({
|
|
82
|
-
reason: "BadResource",
|
|
83
|
-
module: "ChildProcess",
|
|
84
|
-
method: "kill",
|
|
85
|
-
description: err instanceof Error ? err.message : "Failed to kill process",
|
|
86
|
-
cause: err,
|
|
87
|
-
}),
|
|
88
|
-
}),
|
|
89
|
-
|
|
90
|
-
stdin: Sink.forEach((chunk) =>
|
|
91
|
-
Effect.try({
|
|
92
|
-
try: () => {
|
|
93
|
-
const sink = proc.stdin
|
|
94
|
-
sink.write(chunk)
|
|
95
|
-
},
|
|
96
|
-
catch: (err) =>
|
|
97
|
-
new PlatformError.SystemError({
|
|
98
|
-
reason: "Unknown",
|
|
99
|
-
module: "ChildProcess",
|
|
100
|
-
method: "fromWritable(stdin)",
|
|
101
|
-
description: "Failed to write to stdin",
|
|
102
|
-
cause: err,
|
|
103
|
-
}),
|
|
104
|
-
}),
|
|
105
|
-
).pipe(
|
|
106
|
-
Sink.ensuring(
|
|
107
|
-
Effect.promise(async () => {
|
|
108
|
-
const sink = proc.stdin
|
|
109
|
-
await sink.end()
|
|
110
|
-
}),
|
|
111
|
-
),
|
|
112
|
-
),
|
|
113
|
-
|
|
114
|
-
stdout: Stream.fromReadableStream(
|
|
115
|
-
() => proc.stdout,
|
|
116
|
-
(err) =>
|
|
117
|
-
new PlatformError.SystemError({
|
|
118
|
-
reason: "Unknown",
|
|
119
|
-
module: "ChildProcess",
|
|
120
|
-
method: "fromReadable(stdout)",
|
|
121
|
-
description: "Failed to read stdout stream",
|
|
122
|
-
cause: err,
|
|
123
|
-
}),
|
|
124
|
-
),
|
|
125
|
-
|
|
126
|
-
stderr: Stream.fromReadableStream(
|
|
127
|
-
() => proc.stderr,
|
|
128
|
-
(err) =>
|
|
129
|
-
new PlatformError.SystemError({
|
|
130
|
-
reason: "Unknown",
|
|
131
|
-
module: "ChildProcess",
|
|
132
|
-
method: "fromReadable(stderr)",
|
|
133
|
-
description: "Failed to read stderr stream",
|
|
134
|
-
cause: err,
|
|
135
|
-
}),
|
|
136
|
-
),
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return handle
|
|
140
|
-
}),
|
|
141
|
-
},
|
|
142
|
-
)
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import * as NPath from "node:path"
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Tracks all imported modules.
|
|
5
|
-
* State can be accessed via 'virtual:import-tracker' module within a bundle
|
|
6
|
-
* or through `state` property returned by this function.
|
|
7
|
-
*/
|
|
8
|
-
export const make = (
|
|
9
|
-
opts = {},
|
|
10
|
-
) => {
|
|
11
|
-
const foundImports = new Map()
|
|
12
|
-
const baseDir = opts.baseDir ?? process.cwd()
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
name: "import tracker",
|
|
16
|
-
setup(build) {
|
|
17
|
-
const transpiler = new Bun.Transpiler({
|
|
18
|
-
loader: "tsx",
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
// Each module that goes through this onLoad callback
|
|
22
|
-
// will record its imports in `trackedImports`
|
|
23
|
-
build.onLoad(
|
|
24
|
-
{
|
|
25
|
-
filter: /\.(ts|js)x?$/,
|
|
26
|
-
},
|
|
27
|
-
async (args) => {
|
|
28
|
-
if (!opts.includeNodeModules && args.path.includes("/node_modules/")) {
|
|
29
|
-
return undefined
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const contents = await Bun.file(args.path).arrayBuffer()
|
|
33
|
-
try {
|
|
34
|
-
const fileImport = transpiler.scanImports(contents)
|
|
35
|
-
const resolvedImports = fileImport.map((imp) => {
|
|
36
|
-
const absoluteImportPath = NPath.resolve(
|
|
37
|
-
NPath.dirname(args.path),
|
|
38
|
-
// 'file' is a default namespace, trim it
|
|
39
|
-
imp.path.replace(/^file:/, ""),
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
...imp,
|
|
44
|
-
// keep all module identifiers with namespace intact
|
|
45
|
-
path: /(\w+):/.test(imp.path)
|
|
46
|
-
? imp.path
|
|
47
|
-
: NPath.relative(baseDir, absoluteImportPath),
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
foundImports.set(NPath.relative(baseDir, args.path), resolvedImports)
|
|
51
|
-
} catch (e) {}
|
|
52
|
-
|
|
53
|
-
return undefined
|
|
54
|
-
},
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
build.onResolve(
|
|
58
|
-
{
|
|
59
|
-
filter: /^virtual:import-tracker$/,
|
|
60
|
-
},
|
|
61
|
-
() => {
|
|
62
|
-
return {
|
|
63
|
-
namespace: "effect-start",
|
|
64
|
-
path: "virtual:import-tracker",
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
build.onLoad(
|
|
70
|
-
{
|
|
71
|
-
filter: /^virtual:import-tracker$/,
|
|
72
|
-
namespace: "effect-start",
|
|
73
|
-
},
|
|
74
|
-
async (args) => {
|
|
75
|
-
// Wait for all files to be loaded, ensuring
|
|
76
|
-
// that every file goes through the above `onLoad()` function
|
|
77
|
-
// and their imports tracked
|
|
78
|
-
await args.defer()
|
|
79
|
-
|
|
80
|
-
// Emit JSON containing the stats of each import
|
|
81
|
-
return {
|
|
82
|
-
contents: JSON.stringify(Object.fromEntries(foundImports.entries())),
|
|
83
|
-
loader: "json",
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
)
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
state: foundImports,
|
|
90
|
-
}
|
|
91
|
-
}
|
package/dist/bun/BunRoute.js
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import * as Array from "effect/Array"
|
|
2
|
-
import * as Data from "effect/Data"
|
|
3
|
-
import * as Effect from "effect/Effect"
|
|
4
|
-
import * as Option from "effect/Option"
|
|
5
|
-
import * as Entity from "../Entity.js"
|
|
6
|
-
import * as FilePathPattern from "../FilePathPattern.js"
|
|
7
|
-
import * as Hyper from "../hyper/Hyper.js"
|
|
8
|
-
import * as HyperHtml from "../hyper/HyperHtml.js"
|
|
9
|
-
import * as Route from "../Route.js"
|
|
10
|
-
import * as Unique from "../Unique.js"
|
|
11
|
-
import * as BunServer from "./BunServer.js"
|
|
12
|
-
|
|
13
|
-
const INTERNAL_FETCH_HEADER = "x-effect-start-internal-fetch"
|
|
14
|
-
|
|
15
|
-
export class BunRouteError extends Data.TaggedError("BunRouteError") {}
|
|
16
|
-
|
|
17
|
-
export function descriptors(
|
|
18
|
-
route,
|
|
19
|
-
) {
|
|
20
|
-
const descriptor = Route.descriptor(route)
|
|
21
|
-
if (typeof descriptor.bunPrefix === "string" && typeof descriptor.bunLoad === "function") {
|
|
22
|
-
return descriptor
|
|
23
|
-
}
|
|
24
|
-
return undefined
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function htmlBundle(load) {
|
|
28
|
-
const bunPrefix = `/.BunRoute-${Unique.token(10)}`
|
|
29
|
-
const bunLoad = () =>
|
|
30
|
-
Promise.resolve(load()).then((mod) => ("default" in mod ? mod.default : mod))
|
|
31
|
-
const descriptors = { bunPrefix, bunLoad, format: /** @type {const} */ "html" }
|
|
32
|
-
|
|
33
|
-
return function (
|
|
34
|
-
self,
|
|
35
|
-
) {
|
|
36
|
-
const handler = (context, next) =>
|
|
37
|
-
Effect.gen(function* () {
|
|
38
|
-
const originalRequest = context.request
|
|
39
|
-
|
|
40
|
-
if (originalRequest.headers.get(INTERNAL_FETCH_HEADER) === "true") {
|
|
41
|
-
const url = new URL(originalRequest.url)
|
|
42
|
-
return yield* Effect.fail(
|
|
43
|
-
new BunRouteError({
|
|
44
|
-
reason: "ProxyError",
|
|
45
|
-
pattern: url.pathname,
|
|
46
|
-
message:
|
|
47
|
-
"Request to internal Bun server was caught by BunRoute handler. This should not happen. Please report a bug.",
|
|
48
|
-
}),
|
|
49
|
-
)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const bunServer = yield* BunServer.BunServer
|
|
53
|
-
const url = new URL(originalRequest.url)
|
|
54
|
-
|
|
55
|
-
const internalPath = `${bunPrefix}${url.pathname}`
|
|
56
|
-
const internalUrl = new URL(internalPath, bunServer.server.url)
|
|
57
|
-
|
|
58
|
-
const headers = new Headers(originalRequest.headers)
|
|
59
|
-
headers.set(INTERNAL_FETCH_HEADER, "true")
|
|
60
|
-
|
|
61
|
-
const proxyRequest = new Request(internalUrl, {
|
|
62
|
-
method: originalRequest.method,
|
|
63
|
-
headers,
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
const response = yield* Effect.tryPromise({
|
|
67
|
-
try: () => fetch(proxyRequest),
|
|
68
|
-
catch: (error) =>
|
|
69
|
-
new BunRouteError({
|
|
70
|
-
reason: "ProxyError",
|
|
71
|
-
pattern: internalPath,
|
|
72
|
-
message: `Failed to fetch internal HTML bundle: ${String(error)}`,
|
|
73
|
-
}),
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
let html = yield* Effect.tryPromise({
|
|
77
|
-
try: () => response.text(),
|
|
78
|
-
catch: (error) =>
|
|
79
|
-
new BunRouteError({
|
|
80
|
-
reason: "ProxyError",
|
|
81
|
-
pattern: internalPath,
|
|
82
|
-
message: String(error),
|
|
83
|
-
}),
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
const childEntity = yield* Entity.resolve(next(context))
|
|
87
|
-
const children = childEntity?.body ?? childEntity
|
|
88
|
-
|
|
89
|
-
let childrenHtml = ""
|
|
90
|
-
if (children != null) {
|
|
91
|
-
if ((children) instanceof Response) {
|
|
92
|
-
childrenHtml = yield* Effect.promise(() => (children).text())
|
|
93
|
-
} else if (Hyper.isGenericJsxObject(children)) {
|
|
94
|
-
childrenHtml = HyperHtml.renderToString(children)
|
|
95
|
-
} else {
|
|
96
|
-
childrenHtml = String(children)
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
html = html.replace(/%children%/g, childrenHtml)
|
|
101
|
-
|
|
102
|
-
return Entity.make(html, {
|
|
103
|
-
status: response.status,
|
|
104
|
-
headers: {
|
|
105
|
-
"content-type": response.headers.get("content-type"),
|
|
106
|
-
},
|
|
107
|
-
})
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
const route = Route.make(handler, descriptors)
|
|
111
|
-
|
|
112
|
-
return Route.set([...Route.items(self), route], Route.descriptor(self))
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Validates that a route pattern can be implemented with Bun.serve routes.
|
|
118
|
-
*
|
|
119
|
-
* Supported patterns (native or via multiple routes):
|
|
120
|
-
* - /exact - Exact match
|
|
121
|
-
* - /users/:id - Full-segment named param
|
|
122
|
-
* - /path/* - Directory wildcard
|
|
123
|
-
* - /[[404]] - Catch-all / Rest
|
|
124
|
-
*
|
|
125
|
-
* Unsupported patterns (cannot be implemented in Bun):
|
|
126
|
-
* - /pk_[id] - Prefix before param
|
|
127
|
-
* - /[id]_sfx - Suffix after param
|
|
128
|
-
* - /[id].json - Suffix with dot
|
|
129
|
-
* - /[id]~test - Suffix with tilde
|
|
130
|
-
* - /hello-* - Inline prefix wildcard
|
|
131
|
-
*/
|
|
132
|
-
|
|
133
|
-
export function validateBunPattern(pattern) {
|
|
134
|
-
const segs = FilePathPattern.segments(pattern)
|
|
135
|
-
|
|
136
|
-
const invalid = Array.findFirst(segs, (seg) => seg._tag === "InvalidSegment")
|
|
137
|
-
|
|
138
|
-
if (Option.isSome(invalid)) {
|
|
139
|
-
return Option.some(
|
|
140
|
-
new BunRouteError({
|
|
141
|
-
reason: "UnsupportedPattern",
|
|
142
|
-
pattern,
|
|
143
|
-
message: `Pattern "${pattern}" contains invalid segment.`,
|
|
144
|
-
}),
|
|
145
|
-
)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return Option.none()
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export const isHtmlBundle = (handle) => {
|
|
152
|
-
return (
|
|
153
|
-
typeof handle === "object" &&
|
|
154
|
-
handle !== null &&
|
|
155
|
-
(handle.toString() === "[object HTMLBundle]" || typeof handle.index === "string")
|
|
156
|
-
)
|
|
157
|
-
}
|
package/dist/bun/BunRuntime.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import * as GlobalValue from "effect/GlobalValue"
|
|
2
|
-
import * as MutableRef from "effect/MutableRef"
|
|
3
|
-
import * as PlatformRuntime from "../PlatformRuntime.js"
|
|
4
|
-
|
|
5
|
-
const mainFiber = GlobalValue.globalValue(Symbol.for("effect-start/BunRuntime/existingFiber"), () =>
|
|
6
|
-
MutableRef.make(undefined),
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
export const runMain = PlatformRuntime.makeRunMain(({ fiber, teardown }) => {
|
|
10
|
-
const prevFiber = MutableRef.get(mainFiber)
|
|
11
|
-
|
|
12
|
-
MutableRef.set(mainFiber, fiber)
|
|
13
|
-
|
|
14
|
-
let receivedSignal = false
|
|
15
|
-
|
|
16
|
-
fiber.addObserver((exit) => {
|
|
17
|
-
if (!receivedSignal) {
|
|
18
|
-
process.removeListener("SIGINT", onSigint)
|
|
19
|
-
process.removeListener("SIGTERM", onSigint)
|
|
20
|
-
}
|
|
21
|
-
teardown(exit, (code) => {
|
|
22
|
-
if (receivedSignal || code !== 0) {
|
|
23
|
-
process.exit(code)
|
|
24
|
-
}
|
|
25
|
-
})
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
function onSigint() {
|
|
29
|
-
receivedSignal = true
|
|
30
|
-
process.removeListener("SIGINT", onSigint)
|
|
31
|
-
process.removeListener("SIGTERM", onSigint)
|
|
32
|
-
fiber.unsafeInterruptAsFork(fiber.id())
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
process.on("SIGINT", onSigint)
|
|
36
|
-
process.on("SIGTERM", onSigint)
|
|
37
|
-
|
|
38
|
-
if (prevFiber) {
|
|
39
|
-
prevFiber.unsafeInterruptAsFork(prevFiber.id())
|
|
40
|
-
}
|
|
41
|
-
})
|