effect-start 0.30.1 → 0.32.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 (122) hide show
  1. package/dist/Fetch.d.ts +1 -1
  2. package/dist/Fetch.d.ts.map +1 -1
  3. package/dist/Fetch.js +1 -1
  4. package/dist/Fetch.js.map +1 -1
  5. package/dist/GlobalLayer.d.ts.map +1 -1
  6. package/dist/GlobalLayer.js.map +1 -1
  7. package/dist/Html.js +3 -3
  8. package/dist/Html.js.map +1 -1
  9. package/dist/Password.d.ts +26 -0
  10. package/dist/Password.d.ts.map +1 -0
  11. package/dist/Password.js +83 -0
  12. package/dist/Password.js.map +1 -0
  13. package/dist/Route.d.ts.map +1 -1
  14. package/dist/Route.js +1 -1
  15. package/dist/Route.js.map +1 -1
  16. package/dist/RouteBody.d.ts +10 -5
  17. package/dist/RouteBody.d.ts.map +1 -1
  18. package/dist/RouteBody.js +6 -2
  19. package/dist/RouteBody.js.map +1 -1
  20. package/dist/RouteHttp.d.ts.map +1 -1
  21. package/dist/RouteHttp.js +10 -3
  22. package/dist/RouteHttp.js.map +1 -1
  23. package/dist/RouteSse.d.ts +3 -4
  24. package/dist/RouteSse.d.ts.map +1 -1
  25. package/dist/RouteSse.js +3 -3
  26. package/dist/RouteSse.js.map +1 -1
  27. package/dist/RouteTree.d.ts +20 -5
  28. package/dist/RouteTree.d.ts.map +1 -1
  29. package/dist/RouteTree.js +172 -40
  30. package/dist/RouteTree.js.map +1 -1
  31. package/dist/StaticFiles.d.ts +23 -0
  32. package/dist/StaticFiles.d.ts.map +1 -0
  33. package/dist/StaticFiles.js +74 -0
  34. package/dist/StaticFiles.js.map +1 -0
  35. package/dist/_Mime.d.ts +2 -0
  36. package/dist/_Mime.d.ts.map +1 -0
  37. package/dist/_Mime.js +33 -0
  38. package/dist/_Mime.js.map +1 -0
  39. package/dist/_PathPattern.js +4 -4
  40. package/dist/_PathPattern.js.map +1 -1
  41. package/dist/_StreamExtra.d.ts.map +1 -1
  42. package/dist/_StreamExtra.js +0 -1
  43. package/dist/_StreamExtra.js.map +1 -1
  44. package/dist/bun/BunRoute.d.ts.map +1 -1
  45. package/dist/bun/BunRoute.js +6 -0
  46. package/dist/bun/BunRoute.js.map +1 -1
  47. package/dist/bun/BunServer.d.ts +2 -0
  48. package/dist/bun/BunServer.d.ts.map +1 -1
  49. package/dist/bun/BunServer.js +18 -7
  50. package/dist/bun/BunServer.js.map +1 -1
  51. package/dist/studio/Studio.d.ts +1 -1
  52. package/dist/studio/Studio.d.ts.map +1 -1
  53. package/dist/studio/Studio.js +5 -4
  54. package/dist/studio/Studio.js.map +1 -1
  55. package/dist/studio/StudioErrors.d.ts.map +1 -1
  56. package/dist/studio/StudioErrors.js +2 -2
  57. package/dist/studio/StudioErrors.js.map +1 -1
  58. package/dist/studio/StudioLogger.d.ts.map +1 -1
  59. package/dist/studio/StudioLogger.js +1 -3
  60. package/dist/studio/StudioLogger.js.map +1 -1
  61. package/dist/studio/StudioStore.d.ts +23 -17
  62. package/dist/studio/StudioStore.d.ts.map +1 -1
  63. package/dist/studio/StudioStore.js +48 -44
  64. package/dist/studio/StudioStore.js.map +1 -1
  65. package/dist/studio/StudioTracer.d.ts.map +1 -1
  66. package/dist/studio/StudioTracer.js +10 -4
  67. package/dist/studio/StudioTracer.js.map +1 -1
  68. package/dist/studio/routes/errors/route.d.ts +2 -2
  69. package/dist/studio/routes/errors/route.d.ts.map +1 -1
  70. package/dist/studio/routes/errors/route.js +2 -2
  71. package/dist/studio/routes/errors/route.js.map +1 -1
  72. package/dist/studio/routes/fiberDetail.d.ts +1 -1
  73. package/dist/studio/routes/fiberDetail.js +4 -4
  74. package/dist/studio/routes/fiberDetail.js.map +1 -1
  75. package/dist/studio/routes/fibers/route.d.ts +3 -3
  76. package/dist/studio/routes/fibers/route.js +4 -4
  77. package/dist/studio/routes/fibers/route.js.map +1 -1
  78. package/dist/studio/routes/logs/route.d.ts +2 -2
  79. package/dist/studio/routes/logs/route.d.ts.map +1 -1
  80. package/dist/studio/routes/logs/route.js +2 -2
  81. package/dist/studio/routes/logs/route.js.map +1 -1
  82. package/dist/studio/routes/metrics/route.d.ts +1 -1
  83. package/dist/studio/routes/system/route.d.ts +1 -1
  84. package/dist/studio/routes/traceDetail.d.ts +1 -1
  85. package/dist/studio/routes/traceDetail.js +1 -1
  86. package/dist/studio/routes/traceDetail.js.map +1 -1
  87. package/dist/studio/routes/traces/route.d.ts +3 -3
  88. package/dist/studio/routes/traces/route.js +5 -5
  89. package/dist/studio/routes/traces/route.js.map +1 -1
  90. package/dist/studio/routes/tree.d.ts +14 -14
  91. package/dist/studio/ui/Traces.d.ts +1 -0
  92. package/dist/studio/ui/Traces.d.ts.map +1 -1
  93. package/dist/studio/ui/Traces.js +32 -11
  94. package/dist/studio/ui/Traces.js.map +1 -1
  95. package/package.json +2 -2
  96. package/src/Fetch.ts +2 -2
  97. package/src/GlobalLayer.ts +1 -3
  98. package/src/Html.ts +3 -3
  99. package/src/Password.ts +130 -0
  100. package/src/Route.ts +10 -12
  101. package/src/RouteBody.ts +36 -14
  102. package/src/RouteHttp.ts +14 -3
  103. package/src/RouteSse.ts +10 -10
  104. package/src/RouteTree.ts +252 -61
  105. package/src/StaticFiles.ts +112 -0
  106. package/src/_Mime.ts +33 -0
  107. package/src/_PathPattern.ts +4 -4
  108. package/src/_StreamExtra.ts +0 -1
  109. package/src/bun/BunRoute.ts +10 -0
  110. package/src/bun/BunServer.ts +33 -7
  111. package/src/studio/Studio.ts +6 -5
  112. package/src/studio/StudioErrors.ts +2 -3
  113. package/src/studio/StudioLogger.ts +2 -3
  114. package/src/studio/StudioStore.ts +159 -115
  115. package/src/studio/StudioTracer.ts +11 -5
  116. package/src/studio/routes/errors/route.tsx +4 -5
  117. package/src/studio/routes/fiberDetail.tsx +4 -4
  118. package/src/studio/routes/fibers/route.tsx +4 -4
  119. package/src/studio/routes/logs/route.tsx +3 -1
  120. package/src/studio/routes/traceDetail.tsx +1 -1
  121. package/src/studio/routes/traces/route.tsx +8 -8
  122. package/src/studio/ui/Traces.tsx +41 -13
@@ -12,7 +12,7 @@ export default Route.get(
12
12
  Route.html(function* (ctx) {
13
13
  const url = new URL(ctx.request.url)
14
14
  const search = url.searchParams.get("traceSearch") || ""
15
- const allSpans = yield* StudioStore.allSpans(StudioStore.store.sql)
15
+ const allSpans = yield* StudioStore.allSpans()
16
16
  const names = Array.from(new Set(allSpans.map((s) => s.name))).sort()
17
17
  let spans = allSpans
18
18
  if (search) {
@@ -52,17 +52,17 @@ export default Route.get(
52
52
  }),
53
53
  Route.sse(
54
54
  Stream.fromPubSub(StudioStore.store.events).pipe(
55
- Stream.filter((e) => e._tag === "SpanStart" || e._tag === "SpanEnd"),
56
- Stream.mapEffect(() =>
55
+ Stream.filter((e) => e._tag === "TraceEnd"),
56
+ Stream.mapEffect((e) =>
57
57
  Effect.gen(function* () {
58
- const spans = yield* StudioStore.allSpans(StudioStore.store.sql)
59
- const html = Html.renderToString(<Traces.TraceGroups spans={spans} />).replace(
60
- /\n/g,
61
- "",
58
+ const traceSpans = yield* StudioStore.spansByTraceId(e.traceId)
59
+ const traceHtml = Html.renderToString(
60
+ <Traces.TraceGroup id={e.traceId} spans={traceSpans} />,
62
61
  )
62
+
63
63
  return {
64
64
  event: "datastar-patch-elements",
65
- data: `selector #traces-container\nmode inner\nelements ${html}`,
65
+ data: `selector .tl-header\nmode after\nelements ${traceHtml}`,
66
66
  }
67
67
  }),
68
68
  ),
@@ -47,6 +47,20 @@ interface TreeSpan {
47
47
  ancestorHasNextSibling: Array<boolean>
48
48
  }
49
49
 
50
+ function sortByStartTime(a: StudioStore.StudioSpan, b: StudioStore.StudioSpan): number {
51
+ if (a.startTime < b.startTime) return -1
52
+ if (a.startTime > b.startTime) return 1
53
+ return 0
54
+ }
55
+
56
+ function pickRootSpan(spans: Array<StudioStore.StudioSpan>): StudioStore.StudioSpan {
57
+ const spanIds = new Set(spans.map((span) => span.spanId))
58
+ return (
59
+ spans.find((span) => !span.parentSpanId || !spanIds.has(span.parentSpanId)) ??
60
+ spans.slice().sort(sortByStartTime)[0]
61
+ )
62
+ }
63
+
50
64
  function buildSpanTree(spans: Array<StudioStore.StudioSpan>): Array<TreeSpan> {
51
65
  const byId = new Map<bigint, StudioStore.StudioSpan>()
52
66
  const childrenOf = new Map<bigint, Array<StudioStore.StudioSpan>>()
@@ -69,23 +83,31 @@ function buildSpanTree(spans: Array<StudioStore.StudioSpan>): Array<TreeSpan> {
69
83
  }
70
84
  }
71
85
 
72
- const sortByStart = (a: StudioStore.StudioSpan, b: StudioStore.StudioSpan) =>
73
- Number(a.startTime - b.startTime)
74
-
75
- roots.sort(sortByStart)
86
+ roots.sort(sortByStartTime)
76
87
  for (const children of childrenOf.values()) {
77
- children.sort(sortByStart)
88
+ children.sort(sortByStartTime)
78
89
  }
79
90
 
80
91
  const result: Array<TreeSpan> = []
92
+ const visited = new Set<bigint>()
81
93
 
82
94
  function walk(
83
95
  span: StudioStore.StudioSpan,
84
96
  depth: number,
85
97
  isLast: boolean,
86
98
  ancestors: Array<boolean>,
99
+ lineage: Set<bigint>,
87
100
  ) {
88
- const children = childrenOf.get(span.spanId) ?? []
101
+ if (lineage.has(span.spanId) || visited.has(span.spanId)) return
102
+
103
+ const nextLineage = new Set(lineage)
104
+ nextLineage.add(span.spanId)
105
+
106
+ const children = (childrenOf.get(span.spanId) ?? []).filter(
107
+ (child) => !nextLineage.has(child.spanId) && !visited.has(child.spanId),
108
+ )
109
+
110
+ visited.add(span.spanId)
89
111
  result.push({
90
112
  span,
91
113
  depth,
@@ -94,12 +116,18 @@ function buildSpanTree(spans: Array<StudioStore.StudioSpan>): Array<TreeSpan> {
94
116
  ancestorHasNextSibling: [...ancestors],
95
117
  })
96
118
  for (let i = 0; i < children.length; i++) {
97
- walk(children[i], depth + 1, i === children.length - 1, [...ancestors, !isLast])
119
+ walk(children[i], depth + 1, i === children.length - 1, [...ancestors, !isLast], nextLineage)
98
120
  }
99
121
  }
100
122
 
101
123
  for (let i = 0; i < roots.length; i++) {
102
- walk(roots[i], 0, i === roots.length - 1, [])
124
+ walk(roots[i], 0, i === roots.length - 1, [], new Set())
125
+ }
126
+
127
+ const remaining = spans.filter((span) => !visited.has(span.spanId)).sort(sortByStartTime)
128
+
129
+ for (let i = 0; i < remaining.length; i++) {
130
+ walk(remaining[i], 0, i === remaining.length - 1, [], new Set())
103
131
  }
104
132
 
105
133
  return result
@@ -225,17 +253,17 @@ export function groupByTraceId(
225
253
  return groups
226
254
  }
227
255
 
228
- export function TraceGroup(options: { spans: Array<StudioStore.StudioSpan> }) {
256
+ export function TraceGroup(options: { id?: bigint; spans: Array<StudioStore.StudioSpan> }) {
229
257
  if (options.spans.length === 0) return null
230
- const root = options.spans.find((s) => !s.parentSpanId) ?? options.spans[0]
231
- const traceId = root.traceId
258
+ const root = pickRootSpan(options.spans)
259
+ const traceId = options.id ?? root.traceId
232
260
  const totalMs = root.durationMs ?? 0
233
261
  const rootStart = root.startTime
234
262
  const hasError = options.spans.some((s) => s.status === "error")
235
263
  const status = hasError ? "error" : root.status
236
264
 
237
265
  return (
238
- <details class="tl-row">
266
+ <details id={`trace-${traceId}`} class="tl-row">
239
267
  <summary class="tl-summary tl-cols">
240
268
  <span class="tl-cell tl-cell-status">
241
269
  <span
@@ -324,7 +352,7 @@ export function TraceDetail(options: { prefix: string; spans: Array<StudioStore.
324
352
  if (options.spans.length === 0) {
325
353
  return <div class="empty">Trace not found</div>
326
354
  }
327
- const root = options.spans.find((s) => !s.parentSpanId) ?? options.spans[0]
355
+ const root = pickRootSpan(options.spans)
328
356
  const traceId = root.traceId
329
357
  const totalMs = root.durationMs ?? 0
330
358
  const rootStart = root.startTime