@n6k.io/build 0.0.1 → 0.0.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@n6k.io/build",
3
- "version": "0.0.1",
3
+ "version": "0.0.4",
4
4
  "private": false,
5
5
  "description": "Static build pipeline (.mdx + ts/tsx/js/jsx → esbuild bundle → HTML) for n6k apps",
6
6
  "homepage": "https://github.com/n6k-io/build#readme",
@@ -81,7 +81,7 @@
81
81
  },
82
82
  "devDependencies": {
83
83
  "@eslint/js": "^10.0.1",
84
- "@n6k.io/db": "link:@n6k.io/db",
84
+ "@n6k.io/db": "^0.5.0",
85
85
  "@storybook/react": "^10.4.4",
86
86
  "@tanstack/react-query": "^5.101.0",
87
87
  "@types/bun": "latest",
@@ -0,0 +1,8 @@
1
+ // Virtual module provided by the `bundleN6kWorkers` Vite plugin (src/vite/workers.ts).
2
+ // Resolves to the DuckDB worker script URLs: stable `/_n6k/workers/*` paths in
3
+ // dev, content-hashed `assets/*-[hash].js` URLs in a production/static build.
4
+ declare module "virtual:n6k-workers" {
5
+ export const duckdbWorkerUrl: string;
6
+ export const fetchWorkerUrl: string;
7
+ export const wsWorkerUrl: string;
8
+ }
@@ -1,21 +1,34 @@
1
1
  import { useMemo, type ReactNode } from "react";
2
2
  import { DuckDBProvider } from "@n6k.io/db/react";
3
- import { N6K_DEFAULT_WORKER_URLS } from "@n6k.io/db/workers";
3
+ import {
4
+ duckdbWorkerUrl,
5
+ fetchWorkerUrl,
6
+ wsWorkerUrl,
7
+ } from "virtual:n6k-workers";
4
8
  import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
5
9
 
10
+ // Worker URLs come from the `bundleN6kWorkers` Vite plugin's virtual module —
11
+ // the same source the real app (v3's DuckDBProviderClient) uses. This is what
12
+ // makes the workers actually ship: in a static build the plugin only emits the
13
+ // content-hashed worker assets when `virtual:n6k-workers` is imported. The old
14
+ // `N6K_DEFAULT_WORKER_URLS` resolved the canonical `/_n6k/workers/*` paths,
15
+ // which exist only via the dev middleware — so a static Storybook (GitHub Pages)
16
+ // 404'd on every worker. Dev still resolves those same stable paths here.
17
+ const duckdbOptions = {
18
+ fetchWorkerUrl,
19
+ duckdbWorkerUrl,
20
+ wsWorkerUrl,
21
+ };
22
+
6
23
  /**
7
24
  * The provider stack every n6k story needs: a fresh react-query client and a
8
- * DuckDB-WASM context. Worker URLs come straight from the driver's canonical
9
- * manifest (`N6K_DEFAULT_WORKER_URLS`) rather than being hardcoded, so they can
10
- * never drift from what the `bundleN6kWorkers` Vite middleware actually serves.
25
+ * DuckDB-WASM context.
11
26
  */
12
27
  export function StoryShell({ children }: { children: ReactNode }) {
13
28
  const queryClient = useMemo(() => new QueryClient(), []);
14
29
  return (
15
30
  <QueryClientProvider client={queryClient}>
16
- <DuckDBProvider duckdbOptions={N6K_DEFAULT_WORKER_URLS}>
17
- {children}
18
- </DuckDBProvider>
31
+ <DuckDBProvider duckdbOptions={duckdbOptions}>{children}</DuckDBProvider>
19
32
  </QueryClientProvider>
20
33
  );
21
34
  }
@@ -11,31 +11,14 @@ export function initLogger(debug: boolean) {
11
11
  }
12
12
  }
13
13
 
14
- // pino does not expose its underlying stream in its public types, so narrow to
15
- // the one method we need (`end`) via a runtime type guard rather than a cast.
16
- function hasFlushableStream(
17
- l: unknown,
18
- ): l is { stream: { end: (cb: () => void) => void } } {
19
- return (
20
- typeof l === "object" &&
21
- l !== null &&
22
- "stream" in l &&
23
- typeof l.stream === "object" &&
24
- l.stream !== null &&
25
- "end" in l.stream &&
26
- typeof l.stream.end === "function"
27
- );
28
- }
29
-
14
+ // Drain pino's buffered logs before the process exits. pino keeps its output
15
+ // stream on an internal Symbol (not a public `.stream` property), so there is
16
+ // nothing to `.end()` directly — `logger.flush(cb)` is the supported drain: it
17
+ // invokes the callback once the underlying stream (including the pino-pretty
18
+ // worker thread) has flushed.
30
19
  export function flushLogger(): Promise<void> {
31
20
  return new Promise((resolve) => {
32
- logger.flush(() => {
33
- if (hasFlushableStream(logger)) {
34
- logger.stream.end(() => resolve());
35
- } else {
36
- resolve();
37
- }
38
- });
21
+ logger.flush(() => resolve());
39
22
  });
40
23
  }
41
24