lopata 0.18.4 → 0.19.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 (106) hide show
  1. package/dist/types/api/dispatch.d.ts +2 -2
  2. package/dist/types/api/handlers/workflows.d.ts +2 -2
  3. package/dist/types/bindings/container-cleanup.d.ts +43 -0
  4. package/dist/types/bindings/container-docker.d.ts +24 -0
  5. package/dist/types/bindings/container.d.ts +4 -2
  6. package/dist/types/bindings/do-executor-worker.d.ts +73 -89
  7. package/dist/types/bindings/do-executor.d.ts +22 -1
  8. package/dist/types/bindings/do-worker-env.d.ts +16 -7
  9. package/dist/types/bindings/durable-object.d.ts +66 -4
  10. package/dist/types/bindings/queue.d.ts +4 -1
  11. package/dist/types/bindings/rpc-stub.d.ts +23 -1
  12. package/dist/types/bindings/scheduled.d.ts +13 -3
  13. package/dist/types/bindings/service-binding.d.ts +13 -4
  14. package/dist/types/bindings/static-assets.d.ts +1 -1
  15. package/dist/types/bindings/websocket-pair.d.ts +12 -3
  16. package/dist/types/bindings/workflow.d.ts +29 -0
  17. package/dist/types/config.d.ts +2 -0
  18. package/dist/types/env.d.ts +6 -0
  19. package/dist/types/error-page-render.d.ts +6 -0
  20. package/dist/types/execution-context.d.ts +8 -0
  21. package/dist/types/generation-manager.d.ts +21 -2
  22. package/dist/types/generation.d.ts +16 -21
  23. package/dist/types/import-graph.d.ts +28 -0
  24. package/dist/types/lopata-config.d.ts +3 -3
  25. package/dist/types/plugin.d.ts +4 -1
  26. package/dist/types/rpc-validate.d.ts +9 -0
  27. package/dist/types/setup-globals.d.ts +5 -1
  28. package/dist/types/tracing/context.d.ts +12 -0
  29. package/dist/types/tracing/span.d.ts +21 -3
  30. package/dist/types/tracing/store.d.ts +17 -0
  31. package/dist/types/tsconfig.tsbuildinfo +1 -1
  32. package/dist/types/vite-plugin/index.d.ts +8 -1
  33. package/dist/types/worker-registry.d.ts +11 -4
  34. package/dist/types/worker-thread/do-protocol.d.ts +256 -0
  35. package/dist/types/worker-thread/entry.d.ts +2 -0
  36. package/dist/types/worker-thread/execution-context.d.ts +22 -0
  37. package/dist/types/worker-thread/executor.d.ts +123 -0
  38. package/dist/types/worker-thread/protocol.d.ts +553 -0
  39. package/dist/types/worker-thread/remote-trace-store.d.ts +27 -0
  40. package/dist/types/worker-thread/rpc-client.d.ts +4 -0
  41. package/dist/types/worker-thread/rpc-shared.d.ts +138 -0
  42. package/dist/types/worker-thread/serialize.d.ts +12 -0
  43. package/dist/types/worker-thread/stream-shared.d.ts +147 -0
  44. package/dist/types/worker-thread/thread-env.d.ts +42 -0
  45. package/dist/types/worker-thread/wire-handlers.d.ts +16 -0
  46. package/dist/types/worker-thread/ws-bridge-shared.d.ts +163 -0
  47. package/package.json +1 -1
  48. package/src/api/handlers/containers.ts +2 -1
  49. package/src/api/handlers/workflows.ts +39 -34
  50. package/src/bindings/container-cleanup.ts +125 -0
  51. package/src/bindings/container-docker.ts +49 -34
  52. package/src/bindings/container.ts +24 -9
  53. package/src/bindings/do-executor-inprocess.ts +9 -5
  54. package/src/bindings/do-executor-worker.ts +386 -158
  55. package/src/bindings/do-executor.ts +23 -1
  56. package/src/bindings/do-worker-entry.ts +242 -60
  57. package/src/bindings/do-worker-env.ts +296 -11
  58. package/src/bindings/durable-object.ts +231 -27
  59. package/src/bindings/email.ts +6 -0
  60. package/src/bindings/queue.ts +11 -1
  61. package/src/bindings/rpc-stub.ts +79 -10
  62. package/src/bindings/scheduled.ts +37 -30
  63. package/src/bindings/service-binding.ts +87 -33
  64. package/src/bindings/static-assets.ts +3 -2
  65. package/src/bindings/websocket-pair.ts +19 -3
  66. package/src/bindings/workflow.ts +91 -0
  67. package/src/cli/dev.ts +106 -41
  68. package/src/config.ts +6 -3
  69. package/src/db.ts +1 -0
  70. package/src/env.ts +40 -21
  71. package/src/error-page-render.ts +21 -0
  72. package/src/execution-context.ts +13 -3
  73. package/src/generation-manager.ts +144 -143
  74. package/src/generation.ts +150 -306
  75. package/src/import-graph.ts +140 -0
  76. package/src/lopata-config.ts +3 -3
  77. package/src/plugin.ts +7 -0
  78. package/src/rpc-validate.ts +29 -0
  79. package/src/setup-globals.ts +6 -17
  80. package/src/testing/durable-object.ts +5 -3
  81. package/src/testing/index.ts +8 -4
  82. package/src/tracing/context.ts +18 -0
  83. package/src/tracing/span.ts +83 -57
  84. package/src/tracing/store.ts +41 -3
  85. package/src/virtual-modules.ts +2 -0
  86. package/src/vite-plugin/dev-server-plugin.ts +4 -0
  87. package/src/vite-plugin/index.ts +8 -1
  88. package/src/worker-registry.ts +15 -2
  89. package/src/worker-thread/do-protocol.ts +237 -0
  90. package/src/worker-thread/entry.ts +453 -0
  91. package/src/worker-thread/execution-context.ts +53 -0
  92. package/src/worker-thread/executor.ts +595 -0
  93. package/src/worker-thread/protocol.ts +552 -0
  94. package/src/worker-thread/remote-trace-store.ts +90 -0
  95. package/src/worker-thread/rpc-client.ts +5 -0
  96. package/src/worker-thread/rpc-shared.ts +503 -0
  97. package/src/worker-thread/serialize.ts +37 -0
  98. package/src/worker-thread/stream-shared.ts +414 -0
  99. package/src/worker-thread/thread-env.ts +350 -0
  100. package/src/worker-thread/wire-handlers.ts +80 -0
  101. package/src/worker-thread/ws-bridge-shared.ts +482 -0
  102. package/dist/types/bindings/do-websocket-bridge.d.ts +0 -60
  103. package/dist/types/module-cache.d.ts +0 -23
  104. package/src/bindings/do-websocket-bridge.ts +0 -79
  105. package/src/module-cache.ts +0 -58
  106. package/src/tracing/global.d.ts +0 -50
@@ -1,58 +0,0 @@
1
- import path from 'node:path'
2
-
3
- interface ModuleRegistry {
4
- registry: Map<unknown, unknown>
5
- }
6
-
7
- interface BunGlobal {
8
- Loader?: ModuleRegistry
9
- }
10
-
11
- let warnedMissingRegistry = false
12
-
13
- /**
14
- * Invalidate the JavaScriptCore module registry for user-code files under
15
- * `baseDir`, excluding `node_modules`. This forces Bun to re-read and
16
- * re-evaluate every transitive dep on the next import.
17
- *
18
- * Why: lopata reloads the worker via `await import('<entry>?v=<ts>')`. That
19
- * query-string trick only invalidates the entry — Bun's module registry is
20
- * keyed by resolved specifier, so static imports inside the entry continue
21
- * to resolve to the originally cached transitive modules. Without this
22
- * call, edits to any file other than the entry itself silently no-op
23
- * across reloads (the watcher fires, `[lopata] Reloaded` prints, but the
24
- * active worker still references the old module graph).
25
- *
26
- * Caveats:
27
- * - Uses `globalThis.Loader`, an undocumented JSC/Bun internal. If Bun
28
- * ever renames or removes it, hot-reload regresses to the prior
29
- * entry-only behavior — `tests/hmr-e2e.test.ts` "transitive dep
30
- * change" cases will catch the regression.
31
- * - `node_modules` paths are skipped so dependency imports stay cached
32
- * across reloads (re-evaluating them every save would be slow and
33
- * pointless — they don't change in a dev session).
34
- */
35
- export function invalidateUserModules(baseDir: string): void {
36
- const loader = (globalThis as unknown as BunGlobal).Loader
37
- if (!loader?.registry) {
38
- if (!warnedMissingRegistry) {
39
- warnedMissingRegistry = true
40
- console.warn(
41
- '[lopata] globalThis.Loader.registry not available — transitive hot-reload is disabled. '
42
- + 'Edits to files other than the worker entrypoint will require a manual restart.',
43
- )
44
- }
45
- return
46
- }
47
-
48
- const prefix = path.resolve(baseDir) + path.sep
49
- const nodeModulesSegment = `${path.sep}node_modules${path.sep}`
50
- for (const key of [...loader.registry.keys()]) {
51
- if (typeof key !== 'string') continue
52
- // Strip query string (e.g. `?v=<ts>`) before comparing with disk paths.
53
- const pathPart = key.split('?')[0] ?? key
54
- if (!pathPart.startsWith(prefix)) continue
55
- if (pathPart.includes(nodeModulesSegment)) continue
56
- loader.registry.delete(key)
57
- }
58
- }
@@ -1,50 +0,0 @@
1
- /**
2
- * Lopata userland tracing API.
3
- *
4
- * Available on `globalThis.__lopata` when running under Lopata dev server.
5
- * In production (Cloudflare Workers) the global is `undefined` — wrap calls
6
- * in a thin helper that falls back to a no-op:
7
- *
8
- * ```ts
9
- * // app/lib/trace.ts
10
- * type TraceFn = <T>(name: string, fn: () => T | Promise<T>) => Promise<T>
11
- *
12
- * export const trace: TraceFn = (name, fn) =>
13
- * globalThis.__lopata?.trace(name, fn) ?? fn()
14
- *
15
- * export const setAttribute = (key: string, value: unknown) =>
16
- * globalThis.__lopata?.setAttribute(key, value)
17
- *
18
- * export const addEvent = (name: string, message?: string) =>
19
- * globalThis.__lopata?.addEvent(name, message)
20
- * ```
21
- *
22
- * Add this file to your tsconfig types to get autocomplete:
23
- * ```json
24
- * { "compilerOptions": { "types": ["lopata/src/tracing/global"] } }
25
- * ```
26
- */
27
-
28
- interface LopataTracing {
29
- /**
30
- * Create a traced span around `fn`. The span is visible in the Lopata
31
- * dashboard and becomes a child of the currently active span (if any).
32
- */
33
- trace<T>(name: string, fn: () => T | Promise<T>): Promise<T>
34
- /**
35
- * Create a traced span with custom attributes.
36
- */
37
- trace<T>(name: string, attrs: Record<string, unknown>, fn: () => T | Promise<T>): Promise<T>
38
-
39
- /**
40
- * Set an attribute on the currently active span.
41
- */
42
- setAttribute(key: string, value: unknown): void
43
-
44
- /**
45
- * Add an event (log entry) to the currently active span.
46
- */
47
- addEvent(name: string, message?: string, attrs?: Record<string, unknown>): void
48
- }
49
-
50
- declare var __lopata: LopataTracing | undefined