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
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import * as Effect from "effect/Effect";
|
|
2
|
-
import * as Layer from "effect/Layer";
|
|
3
|
-
import * as Option from "effect/Option";
|
|
4
|
-
import * as Entity from "../Entity.js";
|
|
5
|
-
import * as PathPattern from "../PathPattern.js";
|
|
6
|
-
import * as Route from "../Route.js";
|
|
7
|
-
import * as RouteTree from "../RouteTree.js";
|
|
8
|
-
import * as Values from "../Values.js";
|
|
9
|
-
import * as Bundle from "./Bundle.js";
|
|
10
|
-
/**
|
|
11
|
-
* Creates a GET route that serves bundle artifacts.
|
|
12
|
-
* Mount at a path with a wildcard param (any name works).
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* RouteTree.make({
|
|
16
|
-
* "/_bundle/:path+": BundleRoute.make(Bundle.ClientBundle),
|
|
17
|
-
* })
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export const make = (tag) => Route.get(Route.render(function* (ctx) {
|
|
21
|
-
const bundle = yield* tag;
|
|
22
|
-
const url = new URL(ctx.request.url);
|
|
23
|
-
const mountPath = ctx.path ?? "/";
|
|
24
|
-
const params = PathPattern.match(mountPath, url.pathname);
|
|
25
|
-
const artifactPath = params ? Values.firstValue(params) : undefined;
|
|
26
|
-
if (!artifactPath) {
|
|
27
|
-
return Entity.make(new Uint8Array(0), { status: 404 });
|
|
28
|
-
}
|
|
29
|
-
const blob = bundle.getArtifact(artifactPath);
|
|
30
|
-
if (!blob) {
|
|
31
|
-
return Entity.make(new Uint8Array(0), { status: 404 });
|
|
32
|
-
}
|
|
33
|
-
const bytes = new Uint8Array(yield* Effect.promise(() => blob.arrayBuffer()));
|
|
34
|
-
return Entity.make(bytes, {
|
|
35
|
-
headers: {
|
|
36
|
-
"content-type": blob.type || "application/octet-stream",
|
|
37
|
-
"cache-control": "public, max-age=31536000, immutable",
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
}));
|
|
41
|
-
export const client = () => make(Bundle.ClientBundle);
|
|
42
|
-
export const layer = (options) => Layer.effect(Route.Routes, Effect.gen(function* () {
|
|
43
|
-
const existing = yield* Effect.serviceOption(Route.Routes).pipe(Effect.andThen(Option.getOrUndefined));
|
|
44
|
-
const path = options?.path ?? "/_bundle/:path+";
|
|
45
|
-
const bundleTree = Route.tree({
|
|
46
|
-
[path]: make(options?.bundle ?? Bundle.ClientBundle),
|
|
47
|
-
});
|
|
48
|
-
if (!existing)
|
|
49
|
-
return bundleTree;
|
|
50
|
-
return RouteTree.merge(existing, bundleTree);
|
|
51
|
-
}));
|
package/dist/client/Overlay.d.ts
DELETED
package/dist/client/Overlay.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
const OVERLAY_ID = "_bundler_error_overlay";
|
|
2
|
-
export function getOverlay() {
|
|
3
|
-
let overlay = document.getElementById(OVERLAY_ID);
|
|
4
|
-
if (!overlay) {
|
|
5
|
-
overlay = document.createElement("pre");
|
|
6
|
-
overlay.id = OVERLAY_ID;
|
|
7
|
-
Object.assign(overlay.style, {
|
|
8
|
-
position: "fixed",
|
|
9
|
-
top: "0",
|
|
10
|
-
left: "0",
|
|
11
|
-
right: "0",
|
|
12
|
-
maxHeight: "40%",
|
|
13
|
-
overflowY: "auto",
|
|
14
|
-
margin: "0",
|
|
15
|
-
padding: "4px",
|
|
16
|
-
background: "black",
|
|
17
|
-
color: "red",
|
|
18
|
-
fontFamily: "monospace",
|
|
19
|
-
zIndex: "2147483647",
|
|
20
|
-
whiteSpace: "pre-wrap",
|
|
21
|
-
});
|
|
22
|
-
document.body.appendChild(overlay);
|
|
23
|
-
}
|
|
24
|
-
return overlay;
|
|
25
|
-
}
|
|
26
|
-
export function showBuildError(message) {
|
|
27
|
-
const overlay = getOverlay();
|
|
28
|
-
const atBottom = overlay.scrollTop + overlay.clientHeight >= overlay.scrollHeight - 1;
|
|
29
|
-
overlay.textContent += message + "\n";
|
|
30
|
-
if (atBottom)
|
|
31
|
-
overlay.scrollTop = overlay.scrollHeight;
|
|
32
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
const ScrollKey = "_BUNDLER_SCROLL";
|
|
2
|
-
/**
|
|
3
|
-
* Persist current scroll state to session storage.
|
|
4
|
-
* Scroll state is saved relatively to visible elements.
|
|
5
|
-
*/
|
|
6
|
-
export function persist() {
|
|
7
|
-
const anchors = [];
|
|
8
|
-
const step = window.innerHeight / 4;
|
|
9
|
-
for (let i = 1; i <= 3; i++) {
|
|
10
|
-
const y = step * i;
|
|
11
|
-
const element = document.elementFromPoint(0, y);
|
|
12
|
-
if (!element)
|
|
13
|
-
continue;
|
|
14
|
-
const target = element.id ? element : (element.closest("[id]") ?? element);
|
|
15
|
-
anchors.push({
|
|
16
|
-
selector: selectorFromElement(target),
|
|
17
|
-
offset: target.getBoundingClientRect().top,
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
const state = {
|
|
21
|
-
anchors,
|
|
22
|
-
scrollY: window.scrollY,
|
|
23
|
-
};
|
|
24
|
-
sessionStorage.setItem(ScrollKey, JSON.stringify(state));
|
|
25
|
-
}
|
|
26
|
-
export function restore() {
|
|
27
|
-
const timeout = 3000;
|
|
28
|
-
const tick = 50;
|
|
29
|
-
const raw = sessionStorage.getItem(ScrollKey);
|
|
30
|
-
if (!raw)
|
|
31
|
-
return;
|
|
32
|
-
sessionStorage.removeItem(ScrollKey);
|
|
33
|
-
const state = JSON.parse(raw);
|
|
34
|
-
const apply = () => {
|
|
35
|
-
for (const anchor of state.anchors) {
|
|
36
|
-
const element = document.querySelector(anchor.selector);
|
|
37
|
-
if (element) {
|
|
38
|
-
const rect = element.getBoundingClientRect();
|
|
39
|
-
const top = window.scrollY + rect.top - anchor.offset;
|
|
40
|
-
window.scrollTo({
|
|
41
|
-
top,
|
|
42
|
-
});
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
window.scrollTo({
|
|
47
|
-
top: state.scrollY,
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
let observer;
|
|
51
|
-
let stableTimer;
|
|
52
|
-
const deadline = setTimeout(() => {
|
|
53
|
-
observer.disconnect();
|
|
54
|
-
if (stableTimer)
|
|
55
|
-
clearTimeout(stableTimer);
|
|
56
|
-
apply();
|
|
57
|
-
}, timeout);
|
|
58
|
-
observer = new MutationObserver(() => {
|
|
59
|
-
if (stableTimer)
|
|
60
|
-
clearTimeout(stableTimer);
|
|
61
|
-
stableTimer = setTimeout(() => {
|
|
62
|
-
observer.disconnect();
|
|
63
|
-
clearTimeout(deadline);
|
|
64
|
-
apply();
|
|
65
|
-
}, tick);
|
|
66
|
-
});
|
|
67
|
-
observer.observe(document.body, {
|
|
68
|
-
subtree: true,
|
|
69
|
-
childList: true,
|
|
70
|
-
attributes: true,
|
|
71
|
-
characterData: true,
|
|
72
|
-
});
|
|
73
|
-
stableTimer = setTimeout(() => {
|
|
74
|
-
observer.disconnect();
|
|
75
|
-
clearTimeout(deadline);
|
|
76
|
-
apply();
|
|
77
|
-
}, tick);
|
|
78
|
-
}
|
|
79
|
-
function selectorFromElement(element) {
|
|
80
|
-
if (element.id) {
|
|
81
|
-
return `#${CSS.escape(element.id)}`;
|
|
82
|
-
}
|
|
83
|
-
const parts = [];
|
|
84
|
-
let current = element;
|
|
85
|
-
while (current && current !== document.body) {
|
|
86
|
-
const parent = current.parentElement;
|
|
87
|
-
if (!parent)
|
|
88
|
-
break;
|
|
89
|
-
const index = Array.from(parent.children).indexOf(current) + 1;
|
|
90
|
-
parts.unshift(`${current.tagName.toLowerCase()}:nth-child(${index})`);
|
|
91
|
-
current = parent;
|
|
92
|
-
}
|
|
93
|
-
return parts.join(" > ");
|
|
94
|
-
}
|
package/dist/client/index.d.ts
DELETED
package/dist/client/index.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This module is intended to be imported in a browser bundle in a development.
|
|
3
|
-
* It is responsible for live reloading the page when bundle changes.
|
|
4
|
-
* When NODE_ENV=production, it does nothing.
|
|
5
|
-
*/
|
|
6
|
-
import * as Overlay from "./Overlay.js";
|
|
7
|
-
import * as ScrollState from "./ScrollState.js";
|
|
8
|
-
const BUNDLE_URL = globalThis._BUNDLE_URL ?? "/_bundle";
|
|
9
|
-
function reload() {
|
|
10
|
-
ScrollState.persist();
|
|
11
|
-
window.location.reload();
|
|
12
|
-
}
|
|
13
|
-
async function loadAllEntrypoints() {
|
|
14
|
-
const manifest = await fetch(`/${BUNDLE_URL}/manifest.json`).then((v) => v.json());
|
|
15
|
-
manifest.artifacts
|
|
16
|
-
.filter((v) => v.path.endsWith(".js"))
|
|
17
|
-
.forEach((artifact) => {
|
|
18
|
-
console.log(artifact.path);
|
|
19
|
-
const script = document.createElement("script");
|
|
20
|
-
script.src = `${BUNDLE_URL}/${artifact.path}`;
|
|
21
|
-
script.type = "module";
|
|
22
|
-
script.onload = () => {
|
|
23
|
-
console.debug("Bundle reloaded");
|
|
24
|
-
};
|
|
25
|
-
document.body.appendChild(script);
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
function handleBundleEvent(event) {
|
|
29
|
-
switch (event._tag) {
|
|
30
|
-
case "Change":
|
|
31
|
-
console.debug("Bundle change detected...");
|
|
32
|
-
reload();
|
|
33
|
-
break;
|
|
34
|
-
case "BuildError":
|
|
35
|
-
Overlay.showBuildError(event.error);
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
function listen() {
|
|
40
|
-
const eventSource = new EventSource(`${BUNDLE_URL}/events`);
|
|
41
|
-
eventSource.addEventListener("message", (event) => {
|
|
42
|
-
try {
|
|
43
|
-
reloadAllMetaLinks();
|
|
44
|
-
const data = JSON.parse(event.data);
|
|
45
|
-
handleBundleEvent(data);
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
console.error("Error parsing SSE event", {
|
|
49
|
-
error,
|
|
50
|
-
event,
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
eventSource.addEventListener("error", (error) => {
|
|
55
|
-
console.error("SSE connection error:", error);
|
|
56
|
-
});
|
|
57
|
-
return () => {
|
|
58
|
-
eventSource.close();
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
function reloadAllMetaLinks() {
|
|
62
|
-
for (const link of document.getElementsByTagName("link")) {
|
|
63
|
-
const url = new URL(link.href);
|
|
64
|
-
if (url.host === window.location.host) {
|
|
65
|
-
const next = link.cloneNode();
|
|
66
|
-
// TODO: this won't work when link already has query params
|
|
67
|
-
next.href = next.href + "?" + Math.random().toString(36).slice(2);
|
|
68
|
-
next.onload = () => link.remove();
|
|
69
|
-
link.parentNode.insertBefore(next, link.nextSibling);
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (process.env.NODE_ENV !== "production") {
|
|
75
|
-
window.addEventListener("load", () => {
|
|
76
|
-
ScrollState.restore();
|
|
77
|
-
listen();
|
|
78
|
-
});
|
|
79
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import * as Layer from "effect/Layer";
|
|
2
|
-
import * as Route from "../Route.ts";
|
|
3
|
-
import * as ConsoleStore from "./ConsoleStore.ts";
|
|
4
|
-
export { ConsoleStore } from "./ConsoleStore.ts";
|
|
5
|
-
export declare function layer(options?: ConsoleStore.ConsoleStoreOptions): Layer.Layer<ConsoleStore.ConsoleStore>;
|
|
6
|
-
export declare function routeLayer(prefix: string): Layer.Layer<Route.Routes, never, Route.Routes | ConsoleStore.ConsoleStore>;
|
package/dist/console/Console.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import * as Effect from "effect/Effect";
|
|
2
|
-
import * as Layer from "effect/Layer";
|
|
3
|
-
import * as Route from "../Route.js";
|
|
4
|
-
import * as RouteTree from "../RouteTree.js";
|
|
5
|
-
import * as ConsoleErrors from "./ConsoleErrors.js";
|
|
6
|
-
import * as ConsoleLogger from "./ConsoleLogger.js";
|
|
7
|
-
import * as ConsoleMetrics from "./ConsoleMetrics.js";
|
|
8
|
-
import * as ConsoleProcess from "./ConsoleProcess.js";
|
|
9
|
-
import * as ConsoleStore from "./ConsoleStore.js";
|
|
10
|
-
import * as ConsoleTracer from "./ConsoleTracer.js";
|
|
11
|
-
import consoleRoutes from "./routes/tree.js";
|
|
12
|
-
export { ConsoleStore } from "./ConsoleStore.js";
|
|
13
|
-
export function layer(options) {
|
|
14
|
-
const store = ConsoleStore.layer(options);
|
|
15
|
-
return Layer.mergeAll(ConsoleTracer.layer, ConsoleLogger.layer, ConsoleMetrics.layer, ConsoleErrors.layer, ConsoleProcess.layer).pipe(Layer.provideMerge(store));
|
|
16
|
-
}
|
|
17
|
-
export function routeLayer(prefix) {
|
|
18
|
-
return Layer.effect(Route.Routes, Effect.gen(function* () {
|
|
19
|
-
const existing = yield* Route.Routes;
|
|
20
|
-
ConsoleStore.store.prefix = prefix;
|
|
21
|
-
const tree = Route.tree({
|
|
22
|
-
[prefix]: consoleRoutes,
|
|
23
|
-
});
|
|
24
|
-
return RouteTree.merge(existing, tree);
|
|
25
|
-
}));
|
|
26
|
-
}
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
import * as Cause from "effect/Cause";
|
|
2
|
-
import * as Chunk from "effect/Chunk";
|
|
3
|
-
import * as Effect from "effect/Effect";
|
|
4
|
-
import * as Exit from "effect/Exit";
|
|
5
|
-
import * as FiberId from "effect/FiberId";
|
|
6
|
-
import * as FiberRef from "effect/FiberRef";
|
|
7
|
-
import * as HashMap from "effect/HashMap";
|
|
8
|
-
import * as Layer from "effect/Layer";
|
|
9
|
-
import * as Option from "effect/Option";
|
|
10
|
-
import * as PubSub from "effect/PubSub";
|
|
11
|
-
import * as Supervisor from "effect/Supervisor";
|
|
12
|
-
import * as ConsoleStore from "./ConsoleStore.js";
|
|
13
|
-
let errorId = 0;
|
|
14
|
-
function safeSerialize(value, depth = 0) {
|
|
15
|
-
if (depth > 4)
|
|
16
|
-
return "<deep>";
|
|
17
|
-
if (value === null || value === undefined)
|
|
18
|
-
return value;
|
|
19
|
-
if (typeof value === "bigint")
|
|
20
|
-
return `${value}n`;
|
|
21
|
-
if (typeof value === "function")
|
|
22
|
-
return undefined;
|
|
23
|
-
if (typeof value === "symbol")
|
|
24
|
-
return value.toString();
|
|
25
|
-
if (typeof value !== "object")
|
|
26
|
-
return value;
|
|
27
|
-
if (value instanceof Date)
|
|
28
|
-
return value.toISOString();
|
|
29
|
-
if (value instanceof Error)
|
|
30
|
-
return value.message;
|
|
31
|
-
if (Array.isArray(value))
|
|
32
|
-
return value.slice(0, 20).map((v) => safeSerialize(v, depth + 1));
|
|
33
|
-
const proto = Object.getPrototypeOf(value);
|
|
34
|
-
if (proto !== null && proto !== Object.prototype) {
|
|
35
|
-
if (typeof value._tag === "string") {
|
|
36
|
-
return serializeTaggedObject(value, depth);
|
|
37
|
-
}
|
|
38
|
-
return `<${proto.constructor?.name ?? "object"}>`;
|
|
39
|
-
}
|
|
40
|
-
return serializePlainObject(value, depth);
|
|
41
|
-
}
|
|
42
|
-
function serializePlainObject(obj, depth) {
|
|
43
|
-
const out = {};
|
|
44
|
-
let count = 0;
|
|
45
|
-
for (const [k, v] of Object.entries(obj)) {
|
|
46
|
-
if (count >= 20)
|
|
47
|
-
break;
|
|
48
|
-
if (typeof v === "function")
|
|
49
|
-
continue;
|
|
50
|
-
const serialized = safeSerialize(v, depth + 1);
|
|
51
|
-
if (serialized !== undefined) {
|
|
52
|
-
out[k] = serialized;
|
|
53
|
-
count++;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return out;
|
|
57
|
-
}
|
|
58
|
-
function serializeTaggedObject(obj, depth) {
|
|
59
|
-
const out = { _tag: obj._tag };
|
|
60
|
-
let count = 0;
|
|
61
|
-
for (const [k, v] of Object.entries(obj)) {
|
|
62
|
-
if (count >= 20)
|
|
63
|
-
break;
|
|
64
|
-
if (k === "_tag")
|
|
65
|
-
continue;
|
|
66
|
-
if (typeof v === "function")
|
|
67
|
-
continue;
|
|
68
|
-
if (k === "stack" || k === "name")
|
|
69
|
-
continue;
|
|
70
|
-
const serialized = safeSerialize(v, depth + 1);
|
|
71
|
-
if (serialized !== undefined) {
|
|
72
|
-
out[k] = serialized;
|
|
73
|
-
count++;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return out;
|
|
77
|
-
}
|
|
78
|
-
function extractTag(error) {
|
|
79
|
-
if (error !== null &&
|
|
80
|
-
typeof error === "object" &&
|
|
81
|
-
"_tag" in error &&
|
|
82
|
-
typeof error._tag === "string") {
|
|
83
|
-
return error._tag;
|
|
84
|
-
}
|
|
85
|
-
return undefined;
|
|
86
|
-
}
|
|
87
|
-
function extractMessage(error) {
|
|
88
|
-
if (error instanceof Error)
|
|
89
|
-
return error.message;
|
|
90
|
-
if (typeof error === "string")
|
|
91
|
-
return error;
|
|
92
|
-
const tag = extractTag(error);
|
|
93
|
-
if (tag)
|
|
94
|
-
return tag;
|
|
95
|
-
try {
|
|
96
|
-
return String(error);
|
|
97
|
-
}
|
|
98
|
-
catch {
|
|
99
|
-
return "<unknown>";
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
function extractProperties(error) {
|
|
103
|
-
if (error === null || error === undefined || typeof error !== "object")
|
|
104
|
-
return {};
|
|
105
|
-
const out = {};
|
|
106
|
-
let count = 0;
|
|
107
|
-
for (const [k, v] of Object.entries(error)) {
|
|
108
|
-
if (count >= 20)
|
|
109
|
-
break;
|
|
110
|
-
if (k === "_tag" || k === "stack" || k === "name")
|
|
111
|
-
continue;
|
|
112
|
-
if (typeof v === "function")
|
|
113
|
-
continue;
|
|
114
|
-
const serialized = safeSerialize(v, 0);
|
|
115
|
-
if (serialized !== undefined) {
|
|
116
|
-
out[k] = serialized;
|
|
117
|
-
count++;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return out;
|
|
121
|
-
}
|
|
122
|
-
const spanSymbol = Symbol.for("effect/SpanAnnotation");
|
|
123
|
-
function extractSpanName(error) {
|
|
124
|
-
if (error !== null && typeof error === "object" && spanSymbol in error) {
|
|
125
|
-
const span = error[spanSymbol];
|
|
126
|
-
return typeof span?.name === "string" ? span.name : undefined;
|
|
127
|
-
}
|
|
128
|
-
return undefined;
|
|
129
|
-
}
|
|
130
|
-
function extractDetails(cause) {
|
|
131
|
-
const details = [];
|
|
132
|
-
const failures = Chunk.toArray(Cause.failures(cause));
|
|
133
|
-
for (const error of failures) {
|
|
134
|
-
details.push({
|
|
135
|
-
kind: "fail",
|
|
136
|
-
tag: extractTag(error),
|
|
137
|
-
message: extractMessage(error),
|
|
138
|
-
properties: extractProperties(error),
|
|
139
|
-
span: extractSpanName(error),
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
const defects = Chunk.toArray(Cause.defects(cause));
|
|
143
|
-
for (const defect of defects) {
|
|
144
|
-
details.push({
|
|
145
|
-
kind: "die",
|
|
146
|
-
tag: extractTag(defect),
|
|
147
|
-
message: extractMessage(defect),
|
|
148
|
-
properties: extractProperties(defect),
|
|
149
|
-
span: extractSpanName(defect),
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
return details;
|
|
153
|
-
}
|
|
154
|
-
function make(store) {
|
|
155
|
-
return new (class extends Supervisor.AbstractSupervisor {
|
|
156
|
-
value = Effect.void;
|
|
157
|
-
onStart(_context, _effect, parent, fiber) {
|
|
158
|
-
const childId = FiberId.threadName(fiber.id());
|
|
159
|
-
if (Option.isSome(parent)) {
|
|
160
|
-
const parentId = FiberId.threadName(parent.value.id());
|
|
161
|
-
if (childId !== parentId) {
|
|
162
|
-
store.fiberParents.set(childId, parentId);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
const span = fiber.currentSpan;
|
|
166
|
-
const annotations = {};
|
|
167
|
-
const spanAnnotations = fiber.getFiberRef(FiberRef.currentTracerSpanAnnotations);
|
|
168
|
-
HashMap.forEach(spanAnnotations, (value, key) => {
|
|
169
|
-
annotations[key] = value;
|
|
170
|
-
});
|
|
171
|
-
const logAnnotations = fiber.getFiberRef(FiberRef.currentLogAnnotations);
|
|
172
|
-
HashMap.forEach(logAnnotations, (value, key) => {
|
|
173
|
-
annotations[key] = value;
|
|
174
|
-
});
|
|
175
|
-
store.fiberContexts.set(childId, {
|
|
176
|
-
spanName: span?._tag === "Span" ? span.name : undefined,
|
|
177
|
-
traceId: span ? span.traceId : undefined,
|
|
178
|
-
annotations,
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
onEnd(exit, fiber) {
|
|
182
|
-
if (Exit.isFailure(exit) && !Cause.isInterruptedOnly(exit.cause)) {
|
|
183
|
-
const error = {
|
|
184
|
-
id: String(++errorId),
|
|
185
|
-
date: new Date(),
|
|
186
|
-
fiberId: FiberId.threadName(fiber.id()),
|
|
187
|
-
interrupted: Cause.isInterrupted(exit.cause),
|
|
188
|
-
prettyPrint: Cause.pretty(exit.cause, { renderErrorCause: true }),
|
|
189
|
-
details: extractDetails(exit.cause),
|
|
190
|
-
};
|
|
191
|
-
store.errors.push(error);
|
|
192
|
-
Effect.runSync(PubSub.publish(store.events, { _tag: "Error", error }));
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
})();
|
|
196
|
-
}
|
|
197
|
-
export const layer = Layer.unwrapEffect(Effect.gen(function* () {
|
|
198
|
-
const store = yield* ConsoleStore.ConsoleStore;
|
|
199
|
-
return Supervisor.addSupervisor(make(store));
|
|
200
|
-
}));
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import * as Cause from "effect/Cause";
|
|
2
|
-
import * as Effect from "effect/Effect";
|
|
3
|
-
import * as FiberId from "effect/FiberId";
|
|
4
|
-
import * as FiberRef from "effect/FiberRef";
|
|
5
|
-
import * as HashMap from "effect/HashMap";
|
|
6
|
-
import * as HashSet from "effect/HashSet";
|
|
7
|
-
import * as Layer from "effect/Layer";
|
|
8
|
-
import * as List from "effect/List";
|
|
9
|
-
import * as Logger from "effect/Logger";
|
|
10
|
-
import * as PubSub from "effect/PubSub";
|
|
11
|
-
import * as ConsoleStore from "./ConsoleStore.js";
|
|
12
|
-
let logId = 0;
|
|
13
|
-
export const layer = Layer.effectDiscard(Effect.gen(function* () {
|
|
14
|
-
const store = yield* ConsoleStore.ConsoleStore;
|
|
15
|
-
const logger = Logger.make(({ message, logLevel, cause, fiberId, spans, annotations, date }) => {
|
|
16
|
-
const levelMap = {
|
|
17
|
-
Debug: "DEBUG",
|
|
18
|
-
Info: "INFO",
|
|
19
|
-
Warning: "WARNING",
|
|
20
|
-
Error: "ERROR",
|
|
21
|
-
Fatal: "FATAL",
|
|
22
|
-
};
|
|
23
|
-
const level = levelMap[logLevel._tag] ?? "INFO";
|
|
24
|
-
const causeStr = !Cause.isEmpty(cause)
|
|
25
|
-
? Cause.pretty(cause, { renderErrorCause: true })
|
|
26
|
-
: undefined;
|
|
27
|
-
const spanNames = [];
|
|
28
|
-
List.forEach(spans, (s) => spanNames.push(s.label));
|
|
29
|
-
const ann = {};
|
|
30
|
-
HashMap.forEach(annotations, (v, k) => {
|
|
31
|
-
ann[k] = v;
|
|
32
|
-
});
|
|
33
|
-
const log = {
|
|
34
|
-
id: String(++logId),
|
|
35
|
-
date,
|
|
36
|
-
level,
|
|
37
|
-
message: String(message),
|
|
38
|
-
fiberId: FiberId.threadName(fiberId),
|
|
39
|
-
cause: causeStr,
|
|
40
|
-
spans: spanNames,
|
|
41
|
-
annotations: ann,
|
|
42
|
-
};
|
|
43
|
-
store.logs.push(log);
|
|
44
|
-
Effect.runSync(PubSub.publish(store.events, { _tag: "Log", log }));
|
|
45
|
-
});
|
|
46
|
-
yield* FiberRef.update(FiberRef.currentLoggers, (loggers) => HashSet.add(loggers, logger));
|
|
47
|
-
}));
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import * as Effect from "effect/Effect";
|
|
2
|
-
import * as Layer from "effect/Layer";
|
|
3
|
-
import * as Metric from "effect/Metric";
|
|
4
|
-
import * as MetricKeyType from "effect/MetricKeyType";
|
|
5
|
-
import * as PubSub from "effect/PubSub";
|
|
6
|
-
import * as Schedule from "effect/Schedule";
|
|
7
|
-
import * as ConsoleStore from "./ConsoleStore.js";
|
|
8
|
-
export const layer = Layer.scopedDiscard(Effect.gen(function* () {
|
|
9
|
-
const store = yield* ConsoleStore.ConsoleStore;
|
|
10
|
-
yield* Effect.forkScoped(Effect.schedule(Effect.sync(() => {
|
|
11
|
-
const pairs = Metric.unsafeSnapshot();
|
|
12
|
-
const snapshots = [];
|
|
13
|
-
for (const pair of pairs) {
|
|
14
|
-
const key = pair.metricKey;
|
|
15
|
-
const state = pair.metricState;
|
|
16
|
-
let type = "counter";
|
|
17
|
-
let value = 0;
|
|
18
|
-
if (MetricKeyType.CounterKeyTypeTypeId in key.keyType) {
|
|
19
|
-
type = "counter";
|
|
20
|
-
value = state.count;
|
|
21
|
-
}
|
|
22
|
-
else if (MetricKeyType.GaugeKeyTypeTypeId in key.keyType) {
|
|
23
|
-
type = "gauge";
|
|
24
|
-
value = state.value;
|
|
25
|
-
}
|
|
26
|
-
else if (MetricKeyType.HistogramKeyTypeTypeId in key.keyType) {
|
|
27
|
-
type = "histogram";
|
|
28
|
-
value = {
|
|
29
|
-
buckets: state.buckets,
|
|
30
|
-
count: state.count,
|
|
31
|
-
sum: state.sum,
|
|
32
|
-
min: state.min,
|
|
33
|
-
max: state.max,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
else if (MetricKeyType.FrequencyKeyTypeTypeId in key.keyType) {
|
|
37
|
-
type = "frequency";
|
|
38
|
-
value = Object.fromEntries(state.occurrences);
|
|
39
|
-
}
|
|
40
|
-
else if (MetricKeyType.SummaryKeyTypeTypeId in key.keyType) {
|
|
41
|
-
type = "summary";
|
|
42
|
-
value = {
|
|
43
|
-
quantiles: state.quantiles,
|
|
44
|
-
count: state.count,
|
|
45
|
-
sum: state.sum,
|
|
46
|
-
min: state.min,
|
|
47
|
-
max: state.max,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
snapshots.push({
|
|
51
|
-
name: key.name,
|
|
52
|
-
type,
|
|
53
|
-
value,
|
|
54
|
-
tags: key.tags.map((t) => ({ key: t.key, value: t.value })),
|
|
55
|
-
timestamp: Date.now(),
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
store.metrics = snapshots;
|
|
59
|
-
Effect.runSync(PubSub.publish(store.events, { _tag: "MetricsSnapshot", metrics: snapshots }));
|
|
60
|
-
}), Schedule.spaced("2 seconds")));
|
|
61
|
-
}));
|