effect-start 0.22.1 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (313) hide show
  1. package/dist/BlobStore.d.ts +80 -0
  2. package/dist/BlobStore.js +19 -0
  3. package/dist/ChildProcess.d.ts +60 -0
  4. package/dist/ChildProcess.js +30 -0
  5. package/dist/Commander.d.ts +3 -6
  6. package/dist/Commander.js +6 -13
  7. package/dist/ContentNegotiation.d.ts +8 -9
  8. package/dist/ContentNegotiation.js +32 -37
  9. package/dist/Cookies.d.ts +47 -0
  10. package/dist/Cookies.js +273 -363
  11. package/dist/Development.d.ts +2 -2
  12. package/dist/Development.js +3 -4
  13. package/dist/Effectify.d.ts +1 -4
  14. package/dist/FilePathPattern.d.ts +3 -3
  15. package/dist/FileRouter.d.ts +5 -8
  16. package/dist/FileRouter.js +9 -10
  17. package/dist/FileRouterCodegen.d.ts +1 -1
  18. package/dist/FileRouterCodegen.js +33 -13
  19. package/dist/FileSystem.d.ts +158 -0
  20. package/dist/FileSystem.js +64 -125
  21. package/dist/Http.js +2 -6
  22. package/dist/PathPattern.d.ts +7 -7
  23. package/dist/PathPattern.js +1 -3
  24. package/dist/PlatformError.d.ts +24 -32
  25. package/dist/PlatformError.js +3 -21
  26. package/dist/PlatformRuntime.js +5 -10
  27. package/dist/Route.d.ts +14 -19
  28. package/dist/Route.js +8 -11
  29. package/dist/RouteBody.d.ts +6 -12
  30. package/dist/RouteBody.js +2 -2
  31. package/dist/RouteError.d.ts +98 -0
  32. package/dist/RouteError.js +55 -0
  33. package/dist/RouteHook.js +6 -11
  34. package/dist/RouteHttp.d.ts +3 -3
  35. package/dist/RouteHttp.js +27 -22
  36. package/dist/RouteMount.d.ts +16 -50
  37. package/dist/RouteMount.js +6 -20
  38. package/dist/RouteSchema.d.ts +22 -1
  39. package/dist/RouteSchema.js +33 -0
  40. package/dist/RouteSse.js +4 -10
  41. package/dist/RouteTree.d.ts +2 -1
  42. package/dist/RouteTree.js +17 -15
  43. package/dist/RouteTrie.d.ts +2 -2
  44. package/dist/RouteTrie.js +4 -9
  45. package/dist/SchemaExtra.d.ts +1 -1
  46. package/dist/Socket.d.ts +27 -0
  47. package/dist/Socket.js +20 -28
  48. package/dist/Sql.d.ts +34 -0
  49. package/dist/Sql.js +5 -0
  50. package/dist/SqlIntrospect.d.ts +91 -0
  51. package/dist/SqlIntrospect.js +466 -0
  52. package/dist/Start.d.ts +4 -6
  53. package/dist/Start.js +10 -2
  54. package/dist/StreamExtra.d.ts +1 -1
  55. package/dist/StreamExtra.js +9 -9
  56. package/dist/System.d.ts +7 -0
  57. package/dist/System.js +22 -0
  58. package/dist/TuplePathPattern.js +55 -50
  59. package/dist/Unique.js +7 -7
  60. package/dist/Values.d.ts +2 -1
  61. package/dist/Values.js +19 -13
  62. package/dist/bun/BunBlobStoreDisk.d.ts +6 -0
  63. package/dist/bun/BunBlobStoreDisk.js +116 -0
  64. package/dist/bun/BunBlobStoreS3.d.ts +11 -0
  65. package/dist/bun/BunBlobStoreS3.js +89 -0
  66. package/dist/bun/BunBlobWatcherDisk.d.ts +6 -0
  67. package/dist/bun/BunBlobWatcherDisk.js +60 -0
  68. package/dist/bun/BunBlobWatcherQueue.d.ts +6 -0
  69. package/dist/bun/BunBlobWatcherQueue.js +17 -0
  70. package/dist/bun/BunBundle.d.ts +5 -6
  71. package/dist/bun/BunBundle.js +7 -15
  72. package/dist/bun/BunChildProcessSpawner.d.ts +3 -0
  73. package/dist/bun/BunChildProcessSpawner.js +103 -0
  74. package/dist/bun/BunImportTrackerPlugin.d.ts +1 -1
  75. package/dist/bun/BunImportTrackerPlugin.js +3 -5
  76. package/dist/bun/BunRoute.d.ts +3 -2
  77. package/dist/bun/BunRoute.js +5 -7
  78. package/dist/bun/BunRuntime.js +1 -1
  79. package/dist/bun/BunServer.d.ts +11 -4
  80. package/dist/bun/BunServer.js +35 -11
  81. package/dist/bun/BunSql.d.ts +4 -0
  82. package/dist/bun/BunSql.js +81 -0
  83. package/dist/bun/_BunEnhancedResolve.d.ts +3 -3
  84. package/dist/bun/_BunEnhancedResolve.js +2 -4
  85. package/dist/bun/index.d.ts +1 -0
  86. package/dist/bun/index.js +1 -0
  87. package/dist/bundler/Bundle.d.ts +2 -1
  88. package/dist/bundler/Bundle.js +1 -1
  89. package/dist/bundler/BundleFiles.d.ts +5 -5
  90. package/dist/bundler/BundleFiles.js +10 -8
  91. package/dist/bundler/BundleRoute.d.ts +27 -0
  92. package/dist/bundler/BundleRoute.js +51 -0
  93. package/dist/client/ScrollState.js +2 -6
  94. package/dist/client/index.js +6 -8
  95. package/dist/console/Console.d.ts +6 -0
  96. package/dist/console/Console.js +26 -0
  97. package/dist/console/ConsoleErrors.d.ts +3 -0
  98. package/dist/console/ConsoleErrors.js +200 -0
  99. package/dist/console/ConsoleLogger.d.ts +3 -0
  100. package/dist/console/ConsoleLogger.js +47 -0
  101. package/dist/console/ConsoleMetrics.d.ts +3 -0
  102. package/dist/console/ConsoleMetrics.js +61 -0
  103. package/dist/console/ConsoleProcess.d.ts +3 -0
  104. package/dist/console/ConsoleProcess.js +49 -0
  105. package/dist/console/ConsoleStore.d.ts +144 -0
  106. package/dist/console/ConsoleStore.js +61 -0
  107. package/dist/console/ConsoleTracer.d.ts +3 -0
  108. package/dist/console/ConsoleTracer.js +94 -0
  109. package/dist/console/Simulation.d.ts +2 -0
  110. package/dist/console/Simulation.js +633 -0
  111. package/dist/console/index.d.ts +3 -0
  112. package/dist/console/index.js +3 -0
  113. package/dist/console/routes/errors/route.d.ts +10 -0
  114. package/dist/console/routes/errors/route.js +47 -0
  115. package/dist/console/routes/fiberDetail.d.ts +16 -0
  116. package/dist/console/routes/fiberDetail.js +38 -0
  117. package/dist/console/routes/fibers/route.d.ts +10 -0
  118. package/dist/console/routes/fibers/route.js +19 -0
  119. package/dist/console/routes/git/route.d.ts +11 -0
  120. package/dist/console/routes/git/route.js +33 -0
  121. package/dist/console/routes/layout.d.ts +9 -0
  122. package/dist/console/routes/layout.js +3 -0
  123. package/dist/console/routes/logs/route.d.ts +10 -0
  124. package/dist/console/routes/logs/route.js +32 -0
  125. package/dist/console/routes/metrics/route.d.ts +10 -0
  126. package/dist/console/routes/metrics/route.js +17 -0
  127. package/dist/console/routes/route.d.ts +6 -0
  128. package/dist/console/routes/route.js +5 -0
  129. package/dist/console/routes/routes/route.d.ts +6 -0
  130. package/dist/console/routes/routes/route.js +20 -0
  131. package/dist/console/routes/services/route.d.ts +6 -0
  132. package/dist/console/routes/services/route.js +12 -0
  133. package/dist/console/routes/system/route.d.ts +10 -0
  134. package/dist/console/routes/system/route.js +18 -0
  135. package/dist/console/routes/traceDetail.d.ts +16 -0
  136. package/dist/console/routes/traceDetail.js +14 -0
  137. package/dist/console/routes/traces/route.d.ts +10 -0
  138. package/dist/console/routes/traces/route.js +39 -0
  139. package/dist/console/routes/tree.d.ts +153 -0
  140. package/dist/console/routes/tree.js +29 -0
  141. package/dist/console/ui/Errors.d.ts +4 -0
  142. package/dist/console/ui/Errors.js +15 -0
  143. package/dist/console/ui/Fibers.d.ts +24 -0
  144. package/dist/console/ui/Fibers.js +121 -0
  145. package/dist/console/ui/Git.d.ts +20 -0
  146. package/dist/console/ui/Git.js +95 -0
  147. package/dist/console/ui/Logs.d.ts +4 -0
  148. package/dist/console/ui/Logs.js +25 -0
  149. package/dist/console/ui/Metrics.d.ts +4 -0
  150. package/dist/console/ui/Metrics.js +26 -0
  151. package/dist/console/ui/Routes.d.ts +8 -0
  152. package/dist/console/ui/Routes.js +70 -0
  153. package/dist/console/ui/Services.d.ts +10 -0
  154. package/dist/console/ui/Services.js +246 -0
  155. package/dist/console/ui/Shell.d.ts +10 -0
  156. package/dist/console/ui/Shell.js +7 -0
  157. package/dist/console/ui/System.d.ts +4 -0
  158. package/dist/console/ui/System.js +35 -0
  159. package/dist/console/ui/Traces.d.ts +12 -0
  160. package/dist/console/ui/Traces.js +179 -0
  161. package/dist/datastar/actions/fetch.d.ts +1 -1
  162. package/dist/datastar/actions/fetch.js +10 -18
  163. package/dist/datastar/actions/peek.js +1 -2
  164. package/dist/datastar/actions/setAll.js +1 -2
  165. package/dist/datastar/actions/toggleAll.js +1 -2
  166. package/dist/datastar/attributes/attr.js +1 -2
  167. package/dist/datastar/attributes/bind.js +10 -18
  168. package/dist/datastar/attributes/class.js +2 -5
  169. package/dist/datastar/attributes/computed.js +2 -3
  170. package/dist/datastar/attributes/effect.js +1 -2
  171. package/dist/datastar/attributes/indicator.js +2 -4
  172. package/dist/datastar/attributes/init.js +2 -3
  173. package/dist/datastar/attributes/jsonSignals.js +1 -2
  174. package/dist/datastar/attributes/on.js +41 -22
  175. package/dist/datastar/attributes/onIntersect.js +2 -3
  176. package/dist/datastar/attributes/onInterval.js +2 -3
  177. package/dist/datastar/attributes/onSignalPatch.js +2 -4
  178. package/dist/datastar/attributes/ref.js +1 -2
  179. package/dist/datastar/attributes/show.js +1 -2
  180. package/dist/datastar/attributes/signals.js +1 -2
  181. package/dist/datastar/attributes/style.js +6 -12
  182. package/dist/datastar/attributes/text.js +1 -2
  183. package/dist/datastar/engine.d.ts +13 -7
  184. package/dist/datastar/engine.js +76 -48
  185. package/dist/datastar/happydom.d.ts +1 -0
  186. package/dist/datastar/happydom.js +8 -0
  187. package/dist/datastar/index.d.ts +1 -1
  188. package/dist/datastar/index.js +1 -1
  189. package/dist/datastar/utils.js +4 -7
  190. package/dist/datastar/watchers/patchElements.js +24 -45
  191. package/dist/datastar/watchers/patchSignals.js +1 -2
  192. package/dist/experimental/EncryptedCookies.d.ts +2 -5
  193. package/dist/experimental/EncryptedCookies.js +17 -48
  194. package/dist/experimental/index.d.ts +0 -1
  195. package/dist/experimental/index.js +0 -1
  196. package/dist/hyper/Hyper.d.ts +2 -9
  197. package/dist/hyper/Hyper.js +1 -12
  198. package/dist/hyper/HyperHtml.d.ts +1 -1
  199. package/dist/hyper/HyperHtml.js +18 -12
  200. package/dist/hyper/HyperHtml.test.d.ts +1 -0
  201. package/dist/hyper/HyperHtml.test.js +197 -0
  202. package/dist/hyper/HyperRoute.test.js +14 -3
  203. package/dist/hyper/html.d.ts +11 -0
  204. package/dist/hyper/html.js +30 -0
  205. package/dist/hyper/index.d.ts +2 -0
  206. package/dist/hyper/index.js +1 -0
  207. package/dist/hyper/jsx-runtime.d.ts +1 -1
  208. package/dist/hyper/jsx-runtime.js +1 -1
  209. package/dist/index.d.ts +1 -0
  210. package/dist/index.js +1 -0
  211. package/dist/lint/plugin.d.ts +86 -0
  212. package/dist/lint/plugin.js +341 -0
  213. package/dist/node/NodeFileSystem.d.ts +2 -2
  214. package/dist/node/NodeFileSystem.js +4 -14
  215. package/dist/sql/bun/index.d.ts +3 -0
  216. package/dist/sql/bun/index.js +75 -0
  217. package/dist/sql/mssql/docker.d.ts +2 -0
  218. package/dist/sql/mssql/docker.js +67 -0
  219. package/dist/sql/mssql/index.d.ts +21 -0
  220. package/dist/sql/mssql/index.js +113 -0
  221. package/dist/testing/TestLogger.js +4 -1
  222. package/dist/testing/index.d.ts +0 -1
  223. package/dist/testing/index.js +0 -1
  224. package/dist/testing/utils.d.ts +3 -3
  225. package/dist/testing/utils.js +4 -4
  226. package/dist/x/cloudflare/CloudflareTunnel.d.ts +2 -5
  227. package/dist/x/cloudflare/CloudflareTunnel.js +14 -27
  228. package/dist/x/datastar/Datastar.d.ts +1 -1
  229. package/dist/x/datastar/Datastar.js +13 -12
  230. package/dist/x/datastar/index.d.ts +1 -2
  231. package/dist/x/datastar/index.js +1 -2
  232. package/dist/x/tailscale/TailscaleTunnel.d.ts +15 -0
  233. package/dist/x/tailscale/TailscaleTunnel.js +68 -0
  234. package/dist/x/tailscale/index.d.ts +1 -0
  235. package/dist/x/tailscale/index.js +1 -0
  236. package/dist/x/tailwind/TailwindPlugin.js +19 -19
  237. package/dist/x/tailwind/compile.d.ts +2 -2
  238. package/dist/x/tailwind/compile.js +2 -4
  239. package/package.json +22 -9
  240. package/src/ChildProcess.ts +145 -0
  241. package/src/PlatformError.ts +27 -50
  242. package/src/Route.ts +2 -2
  243. package/src/RouteError.ts +76 -0
  244. package/src/RouteHttp.ts +13 -5
  245. package/src/RouteSchema.ts +96 -1
  246. package/src/RouteTree.ts +12 -0
  247. package/src/Sql.ts +51 -0
  248. package/src/SqlIntrospect.ts +620 -0
  249. package/src/Start.ts +15 -3
  250. package/src/System.ts +43 -0
  251. package/src/Values.ts +7 -0
  252. package/src/bun/BunChildProcessSpawner.ts +143 -0
  253. package/src/bun/BunRoute.ts +5 -2
  254. package/src/bun/BunServer.ts +22 -1
  255. package/src/bun/index.ts +1 -0
  256. package/src/bundler/BundleRoute.ts +66 -0
  257. package/src/console/Console.ts +42 -0
  258. package/src/console/ConsoleErrors.ts +213 -0
  259. package/src/console/ConsoleLogger.ts +56 -0
  260. package/src/console/ConsoleMetrics.ts +72 -0
  261. package/src/console/ConsoleProcess.ts +59 -0
  262. package/src/console/ConsoleStore.ts +187 -0
  263. package/src/console/ConsoleTracer.ts +107 -0
  264. package/src/console/Simulation.ts +814 -0
  265. package/src/console/console.html +340 -0
  266. package/src/console/index.ts +3 -0
  267. package/src/console/routes/errors/route.tsx +97 -0
  268. package/src/console/routes/fiberDetail.tsx +54 -0
  269. package/src/console/routes/fibers/route.tsx +45 -0
  270. package/src/console/routes/git/route.tsx +64 -0
  271. package/src/console/routes/layout.tsx +4 -0
  272. package/src/console/routes/logs/route.tsx +77 -0
  273. package/src/console/routes/metrics/route.tsx +36 -0
  274. package/src/console/routes/route.tsx +8 -0
  275. package/src/console/routes/routes/route.tsx +30 -0
  276. package/src/console/routes/services/route.tsx +21 -0
  277. package/src/console/routes/system/route.tsx +43 -0
  278. package/src/console/routes/traceDetail.tsx +22 -0
  279. package/src/console/routes/traces/route.tsx +81 -0
  280. package/src/console/routes/tree.ts +30 -0
  281. package/src/console/ui/Errors.tsx +76 -0
  282. package/src/console/ui/Fibers.tsx +321 -0
  283. package/src/console/ui/Git.tsx +182 -0
  284. package/src/console/ui/Logs.tsx +46 -0
  285. package/src/console/ui/Metrics.tsx +78 -0
  286. package/src/console/ui/Routes.tsx +125 -0
  287. package/src/console/ui/Services.tsx +273 -0
  288. package/src/console/ui/Shell.tsx +62 -0
  289. package/src/console/ui/System.tsx +131 -0
  290. package/src/console/ui/Traces.tsx +426 -0
  291. package/src/datastar/README.md +6 -1
  292. package/src/datastar/actions/fetch.ts +0 -1
  293. package/src/datastar/attributes/on.ts +40 -20
  294. package/src/datastar/engine.ts +51 -0
  295. package/src/datastar/jsx.d.ts +79 -0
  296. package/src/hyper/Hyper.ts +1 -16
  297. package/src/hyper/HyperHtml.ts +6 -4
  298. package/src/hyper/HyperRoute.ts +2 -1
  299. package/src/hyper/html.ts +47 -0
  300. package/src/hyper/index.ts +2 -0
  301. package/src/hyper/jsx.d.ts +5 -3
  302. package/src/index.ts +1 -0
  303. package/src/lint/plugin.js +129 -0
  304. package/src/sql/bun/index.ts +147 -0
  305. package/src/sql/mssql/docker.ts +117 -0
  306. package/src/sql/mssql/index.ts +223 -0
  307. package/src/sql/mssql/mssql.d.ts +41 -0
  308. package/src/x/cloudflare/CloudflareTunnel.ts +8 -36
  309. package/src/x/tailscale/TailscaleTunnel.ts +113 -0
  310. package/src/x/tailscale/index.ts +1 -0
  311. package/src/x/datastar/Datastar.ts +0 -61
  312. package/src/x/datastar/index.ts +0 -2
  313. package/src/x/datastar/jsx-datastar.d.ts +0 -60
@@ -11,9 +11,7 @@ export function persist() {
11
11
  const element = document.elementFromPoint(0, y);
12
12
  if (!element)
13
13
  continue;
14
- const target = element.id
15
- ? element
16
- : element.closest("[id]") ?? element;
14
+ const target = element.id ? element : (element.closest("[id]") ?? element);
17
15
  anchors.push({
18
16
  selector: selectorFromElement(target),
19
17
  offset: target.getBoundingClientRect().top,
@@ -88,9 +86,7 @@ function selectorFromElement(element) {
88
86
  const parent = current.parentElement;
89
87
  if (!parent)
90
88
  break;
91
- const index = Array
92
- .from(parent.children)
93
- .indexOf(current) + 1;
89
+ const index = Array.from(parent.children).indexOf(current) + 1;
94
90
  parts.unshift(`${current.tagName.toLowerCase()}:nth-child(${index})`);
95
91
  current = parent;
96
92
  }
@@ -3,7 +3,7 @@
3
3
  * It is responsible for live reloading the page when bundle changes.
4
4
  * When NODE_ENV=production, it does nothing.
5
5
  */
6
- import { showBuildError } from "./Overlay.js";
6
+ import * as Overlay from "./Overlay.js";
7
7
  import * as ScrollState from "./ScrollState.js";
8
8
  const BUNDLE_URL = globalThis._BUNDLE_URL ?? "/_bundle";
9
9
  function reload() {
@@ -11,11 +11,9 @@ function reload() {
11
11
  window.location.reload();
12
12
  }
13
13
  async function loadAllEntrypoints() {
14
- const manifest = await fetch(`/${BUNDLE_URL}/manifest.json`)
15
- .then(v => v.json());
16
- manifest
17
- .artifacts
18
- .filter(v => v.path.endsWith(".js"))
14
+ const manifest = await fetch(`/${BUNDLE_URL}/manifest.json`).then((v) => v.json());
15
+ manifest.artifacts
16
+ .filter((v) => v.path.endsWith(".js"))
19
17
  .forEach((artifact) => {
20
18
  console.log(artifact.path);
21
19
  const script = document.createElement("script");
@@ -34,7 +32,7 @@ function handleBundleEvent(event) {
34
32
  reload();
35
33
  break;
36
34
  case "BuildError":
37
- showBuildError(event.error);
35
+ Overlay.showBuildError(event.error);
38
36
  break;
39
37
  }
40
38
  }
@@ -53,7 +51,7 @@ function listen() {
53
51
  });
54
52
  }
55
53
  });
56
- eventSource.addEventListener("error", error => {
54
+ eventSource.addEventListener("error", (error) => {
57
55
  console.error("SSE connection error:", error);
58
56
  });
59
57
  return () => {
@@ -0,0 +1,6 @@
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>;
@@ -0,0 +1,26 @@
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
+ }
@@ -0,0 +1,3 @@
1
+ import * as Layer from "effect/Layer";
2
+ import * as ConsoleStore from "./ConsoleStore.ts";
3
+ export declare const layer: Layer.Layer<never, never, ConsoleStore.ConsoleStore>;
@@ -0,0 +1,200 @@
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
+ }));
@@ -0,0 +1,3 @@
1
+ import * as Layer from "effect/Layer";
2
+ import * as ConsoleStore from "./ConsoleStore.ts";
3
+ export declare const layer: Layer.Layer<never, never, ConsoleStore.ConsoleStore>;
@@ -0,0 +1,47 @@
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
+ }));
@@ -0,0 +1,3 @@
1
+ import * as Layer from "effect/Layer";
2
+ import * as ConsoleStore from "./ConsoleStore.ts";
3
+ export declare const layer: Layer.Layer<never, never, ConsoleStore.ConsoleStore>;
@@ -0,0 +1,61 @@
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
+ }));
@@ -0,0 +1,3 @@
1
+ import * as Layer from "effect/Layer";
2
+ import * as ConsoleStore from "./ConsoleStore.ts";
3
+ export declare const layer: Layer.Layer<never, never, ConsoleStore.ConsoleStore>;
@@ -0,0 +1,49 @@
1
+ import * as NOS from "node:os";
2
+ import * as Effect from "effect/Effect";
3
+ import * as Layer from "effect/Layer";
4
+ import * as PubSub from "effect/PubSub";
5
+ import * as Schedule from "effect/Schedule";
6
+ import * as ConsoleStore from "./ConsoleStore.js";
7
+ function snapshot() {
8
+ const mem = process.memoryUsage();
9
+ const cpu = process.cpuUsage();
10
+ const res = process.resourceUsage();
11
+ const loadavg = NOS.loadavg();
12
+ return {
13
+ pid: process.pid,
14
+ uptime: process.uptime(),
15
+ memory: {
16
+ rss: mem.rss,
17
+ heapUsed: mem.heapUsed,
18
+ heapTotal: mem.heapTotal,
19
+ external: mem.external,
20
+ arrayBuffers: mem.arrayBuffers,
21
+ },
22
+ cpu: { user: cpu.user, system: cpu.system },
23
+ resourceUsage: {
24
+ maxRSS: res.maxRSS,
25
+ minorPageFault: res.minorPageFault,
26
+ majorPageFault: res.majorPageFault,
27
+ fsRead: res.fsRead,
28
+ fsWrite: res.fsWrite,
29
+ voluntaryContextSwitches: res.voluntaryContextSwitches,
30
+ involuntaryContextSwitches: res.involuntaryContextSwitches,
31
+ },
32
+ system: {
33
+ loadavg,
34
+ freemem: NOS.freemem(),
35
+ totalmem: NOS.totalmem(),
36
+ cpuCount: NOS.cpus().length,
37
+ platform: NOS.platform(),
38
+ arch: NOS.arch(),
39
+ },
40
+ };
41
+ }
42
+ export const layer = Layer.scopedDiscard(Effect.gen(function* () {
43
+ const store = yield* ConsoleStore.ConsoleStore;
44
+ yield* Effect.forkScoped(Effect.schedule(Effect.sync(() => {
45
+ const stats = snapshot();
46
+ store.process = stats;
47
+ Effect.runSync(PubSub.publish(store.events, { _tag: "ProcessSnapshot", stats }));
48
+ }), Schedule.spaced("2 seconds")));
49
+ }));
@@ -0,0 +1,144 @@
1
+ import * as Context from "effect/Context";
2
+ import * as Layer from "effect/Layer";
3
+ import * as PubSub from "effect/PubSub";
4
+ export declare const store: ConsoleStoreShape;
5
+ export interface ConsoleSpan {
6
+ readonly spanId: string;
7
+ readonly traceId: string;
8
+ readonly name: string;
9
+ readonly kind: string;
10
+ readonly parentSpanId: string | undefined;
11
+ startTime: bigint;
12
+ endTime: bigint | undefined;
13
+ durationMs: number | undefined;
14
+ status: "started" | "ok" | "error";
15
+ readonly attributes: Record<string, unknown>;
16
+ readonly events: Array<{
17
+ name: string;
18
+ startTime: bigint;
19
+ attributes?: Record<string, unknown>;
20
+ }>;
21
+ }
22
+ export interface ConsoleLog {
23
+ readonly id: string;
24
+ readonly date: Date;
25
+ readonly level: "DEBUG" | "INFO" | "WARNING" | "ERROR" | "FATAL";
26
+ readonly message: string;
27
+ readonly fiberId: string;
28
+ readonly cause: string | undefined;
29
+ readonly spans: Array<string>;
30
+ readonly annotations: Record<string, unknown>;
31
+ }
32
+ export interface ProcessStats {
33
+ readonly pid: number;
34
+ readonly uptime: number;
35
+ readonly memory: {
36
+ readonly rss: number;
37
+ readonly heapUsed: number;
38
+ readonly heapTotal: number;
39
+ readonly external: number;
40
+ readonly arrayBuffers: number;
41
+ };
42
+ readonly cpu: {
43
+ readonly user: number;
44
+ readonly system: number;
45
+ };
46
+ readonly resourceUsage: {
47
+ readonly maxRSS: number;
48
+ readonly minorPageFault: number;
49
+ readonly majorPageFault: number;
50
+ readonly fsRead: number;
51
+ readonly fsWrite: number;
52
+ readonly voluntaryContextSwitches: number;
53
+ readonly involuntaryContextSwitches: number;
54
+ };
55
+ readonly system: {
56
+ readonly loadavg: readonly [number, number, number];
57
+ readonly freemem: number;
58
+ readonly totalmem: number;
59
+ readonly cpuCount: number;
60
+ readonly platform: string;
61
+ readonly arch: string;
62
+ };
63
+ }
64
+ export interface ConsoleErrorDetail {
65
+ readonly kind: "fail" | "die";
66
+ readonly tag: string | undefined;
67
+ readonly message: string;
68
+ readonly properties: Record<string, unknown>;
69
+ readonly span: string | undefined;
70
+ }
71
+ export interface ConsoleError {
72
+ readonly id: string;
73
+ readonly date: Date;
74
+ readonly fiberId: string;
75
+ readonly interrupted: boolean;
76
+ readonly prettyPrint: string;
77
+ readonly details: Array<ConsoleErrorDetail>;
78
+ }
79
+ export interface ConsoleMetricSnapshot {
80
+ readonly name: string;
81
+ readonly type: "counter" | "gauge" | "histogram" | "summary" | "frequency";
82
+ readonly value: unknown;
83
+ readonly tags: ReadonlyArray<{
84
+ key: string;
85
+ value: string;
86
+ }>;
87
+ readonly timestamp: number;
88
+ }
89
+ export type ConsoleEvent = {
90
+ readonly _tag: "SpanStart";
91
+ readonly span: ConsoleSpan;
92
+ } | {
93
+ readonly _tag: "SpanEnd";
94
+ readonly span: ConsoleSpan;
95
+ } | {
96
+ readonly _tag: "Log";
97
+ readonly log: ConsoleLog;
98
+ } | {
99
+ readonly _tag: "Error";
100
+ readonly error: ConsoleError;
101
+ } | {
102
+ readonly _tag: "MetricsSnapshot";
103
+ readonly metrics: Array<ConsoleMetricSnapshot>;
104
+ } | {
105
+ readonly _tag: "ProcessSnapshot";
106
+ readonly stats: ProcessStats;
107
+ };
108
+ export declare class CircularBuffer<T> {
109
+ private buffer;
110
+ private head;
111
+ private count;
112
+ capacity: number;
113
+ constructor(capacity: number);
114
+ push(item: T): void;
115
+ toArray(): Array<T>;
116
+ get size(): number;
117
+ }
118
+ export interface FiberContext {
119
+ readonly spanName: string | undefined;
120
+ readonly traceId: string | undefined;
121
+ readonly annotations: Record<string, unknown>;
122
+ }
123
+ export interface ConsoleStoreShape {
124
+ prefix: string;
125
+ readonly spans: CircularBuffer<ConsoleSpan>;
126
+ readonly logs: CircularBuffer<ConsoleLog>;
127
+ readonly errors: CircularBuffer<ConsoleError>;
128
+ metrics: Array<ConsoleMetricSnapshot>;
129
+ process: ProcessStats | undefined;
130
+ readonly events: PubSub.PubSub<ConsoleEvent>;
131
+ readonly fiberParents: Map<string, string>;
132
+ readonly fiberContexts: Map<string, FiberContext>;
133
+ }
134
+ export declare function fiberIdCounter(): number;
135
+ declare const ConsoleStore_base: Context.TagClass<ConsoleStore, "effect-start/ConsoleStore", ConsoleStoreShape>;
136
+ export declare class ConsoleStore extends ConsoleStore_base {
137
+ }
138
+ export interface ConsoleStoreOptions {
139
+ readonly spanCapacity?: number;
140
+ readonly logCapacity?: number;
141
+ readonly errorCapacity?: number;
142
+ }
143
+ export declare function layer(options?: ConsoleStoreOptions): Layer.Layer<ConsoleStore>;
144
+ export {};
@@ -0,0 +1,61 @@
1
+ import * as Context from "effect/Context";
2
+ import * as Effect from "effect/Effect";
3
+ import * as GlobalValue from "effect/GlobalValue";
4
+ import * as Layer from "effect/Layer";
5
+ import * as MutableRef from "effect/MutableRef";
6
+ import * as PubSub from "effect/PubSub";
7
+ export const store = GlobalValue.globalValue(Symbol.for("effect-start/ConsoleStore"), () => ({
8
+ prefix: "/console",
9
+ spans: new CircularBuffer(1000),
10
+ logs: new CircularBuffer(5000),
11
+ errors: new CircularBuffer(1000),
12
+ metrics: [],
13
+ process: undefined,
14
+ events: Effect.runSync(PubSub.unbounded()),
15
+ fiberParents: new Map(),
16
+ fiberContexts: new Map(),
17
+ }));
18
+ export class CircularBuffer {
19
+ buffer;
20
+ head = 0;
21
+ count = 0;
22
+ capacity;
23
+ constructor(capacity) {
24
+ this.capacity = capacity;
25
+ this.buffer = Array.from({ length: capacity });
26
+ }
27
+ push(item) {
28
+ this.buffer[this.head] = item;
29
+ this.head = (this.head + 1) % this.capacity;
30
+ if (this.count < this.capacity)
31
+ this.count++;
32
+ }
33
+ toArray() {
34
+ if (this.count === 0)
35
+ return [];
36
+ const result = [];
37
+ const start = this.count < this.capacity ? 0 : this.head;
38
+ for (let i = 0; i < this.count; i++) {
39
+ result.push(this.buffer[(start + i) % this.capacity]);
40
+ }
41
+ return result;
42
+ }
43
+ get size() {
44
+ return this.count;
45
+ }
46
+ }
47
+ export function fiberIdCounter() {
48
+ const counter = GlobalValue.globalValue(Symbol.for("effect/Fiber/Id/_fiberCounter"), () => MutableRef.make(0));
49
+ return MutableRef.get(counter);
50
+ }
51
+ export class ConsoleStore extends Context.Tag("effect-start/ConsoleStore")() {
52
+ }
53
+ export function layer(options) {
54
+ if (options?.spanCapacity)
55
+ store.spans = new CircularBuffer(options.spanCapacity);
56
+ if (options?.logCapacity)
57
+ store.logs = new CircularBuffer(options.logCapacity);
58
+ if (options?.errorCapacity)
59
+ store.errors = new CircularBuffer(options.errorCapacity);
60
+ return Layer.sync(ConsoleStore, () => store);
61
+ }