weifuwu 0.17.13 → 0.17.17

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.
@@ -0,0 +1,6 @@
1
+ import type { Sql } from '../vendor.ts';
2
+ import type { AgentModule } from '../agent/types.ts';
3
+ import type { Hub } from '../hub.ts';
4
+ export declare function runAgentRouting(sql: Sql<{}>, messages: {
5
+ insert: (data: any) => Promise<any>;
6
+ }, agents: AgentModule | undefined, hub: Hub, channelId: number, content: string): Promise<void>;
@@ -1,6 +1,7 @@
1
1
  import type { Sql } from '../vendor.ts';
2
2
  import { Router } from '../router.ts';
3
3
  import type { AgentModule } from '../agent/types.ts';
4
+ import type { Hub } from '../hub.ts';
4
5
  import type { BoundTable } from '../postgres/schema/index.ts';
5
6
  interface RestDeps {
6
7
  sql: Sql<{}>;
@@ -8,6 +9,7 @@ interface RestDeps {
8
9
  members: BoundTable<any>;
9
10
  messages: BoundTable<any>;
10
11
  agents?: AgentModule;
12
+ hub: Hub;
11
13
  }
12
14
  export declare function buildRouter(deps: RestDeps): Router;
13
15
  export {};
@@ -1,10 +1,14 @@
1
1
  import type { Sql } from '../vendor.ts';
2
2
  import type { AgentModule } from '../agent/types.ts';
3
+ import type { Hub } from '../hub.ts';
3
4
  interface WSDeps {
4
5
  sql: Sql<{}>;
5
6
  agents?: AgentModule;
6
7
  redis?: import('../vendor.ts').Redis;
7
8
  }
8
- export declare function broadcastToChannel(channelId: number, data: any): void;
9
- export declare function createWSHandler(deps: WSDeps): any;
9
+ export declare function broadcastToChannel(hub: Hub | undefined, channelId: number, data: any): void;
10
+ export declare function createWSHandler(deps: WSDeps): {
11
+ handler: any;
12
+ hub: Hub;
13
+ };
10
14
  export {};
package/dist/react.d.ts CHANGED
@@ -3,7 +3,7 @@ export type { UseWebsocketOptions, UseWebsocketReturn } from './use-websocket.ts
3
3
  export { useAction } from './use-action.ts';
4
4
  export type { UseActionOptions, UseActionReturn } from './use-action.ts';
5
5
  export { Link, useNavigate, navigate, useNavigating } from './client-router.ts';
6
- export { TsxContext, useCtx, setCtx } from './tsx-context.ts';
6
+ export { TsxContext, useCtx, setCtx, getCtx } from './tsx-context.ts';
7
7
  export { Head } from './head.tsx';
8
8
  export { createStore, useData, useQueryState } from './client-state.ts';
9
9
  export type { StoreApi } from './client-state.ts';
package/dist/react.js CHANGED
@@ -144,7 +144,9 @@ import { createElement, useCallback as useCallback3, useState as useState3, useE
144
144
  // tsx-context.ts
145
145
  import { useSyncExternalStore, createContext } from "react";
146
146
  var fallbackT = (key, _params, fallback) => fallback ?? key;
147
- var _ctx = { params: {}, query: {}, parsed: {}, prefs: {}, env: {}, t: fallbackT, user: {} };
147
+ var DEFAULT_CTX = { params: {}, query: {}, parsed: {}, prefs: {}, env: {}, t: fallbackT, user: {} };
148
+ var _ctx = DEFAULT_CTX;
149
+ var _snapshot = { params: _ctx.params, query: _ctx.query, user: _ctx.user, parsed: _ctx.parsed, prefs: _ctx.prefs, env: _ctx.env };
148
150
  var _listeners = /* @__PURE__ */ new Set();
149
151
  var subscribe = (cb) => {
150
152
  _listeners.add(cb);
@@ -152,16 +154,23 @@ var subscribe = (cb) => {
152
154
  _listeners.delete(cb);
153
155
  };
154
156
  };
155
- var getSnapshot = () => ({ params: _ctx.params, query: _ctx.query, user: _ctx.user, parsed: _ctx.parsed, prefs: _ctx.prefs, env: _ctx.env });
157
+ var getSnapshot = () => _snapshot;
156
158
  var getServerSnapshot = getSnapshot;
159
+ var _alsGetStore = null;
157
160
  function setCtx(value) {
158
161
  _ctx = { ..._ctx, ...value };
162
+ _snapshot = { params: _ctx.params, query: _ctx.query, user: _ctx.user, parsed: _ctx.parsed, prefs: _ctx.prefs, env: _ctx.env };
159
163
  _listeners.forEach((fn) => fn());
160
164
  }
165
+ var _cachedT = null;
161
166
  function _buildT() {
167
+ if (_cachedT) return _cachedT;
162
168
  const messages = typeof window !== "undefined" ? window.__LOCALE_DATA__ : globalThis.__LOCALE_DATA__;
163
- if (!messages) return fallbackT;
164
- return (key, params, fallback) => {
169
+ if (!messages) {
170
+ _cachedT = fallbackT;
171
+ return fallbackT;
172
+ }
173
+ _cachedT = (key, params, fallback) => {
165
174
  const msg = key.split(".").reduce((o, k) => o?.[k], messages);
166
175
  if (msg === void 0 || msg === null) return fallback ?? key;
167
176
  if (!params) return String(msg);
@@ -169,14 +178,23 @@ function _buildT() {
169
178
  for (const [k, v] of Object.entries(params)) result = result.replace(`{${k}}`, v);
170
179
  return result;
171
180
  };
181
+ return _cachedT;
182
+ }
183
+ function _readCtx() {
184
+ const alsStore = _alsGetStore?.();
185
+ const base = alsStore ?? _ctx;
186
+ const data = typeof window !== "undefined" ? window.__WEIFUWU_CTX : null;
187
+ const t = typeof base.t === "function" && base.t !== fallbackT ? base.t : _buildT();
188
+ return { ...base, ...data, t };
172
189
  }
173
190
  function useCtx() {
174
191
  useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
175
- const data = typeof window !== "undefined" ? window.__WEIFUWU_CTX : null;
176
- const t = _ctx.t !== fallbackT ? _ctx.t : _buildT();
177
- return { ..._ctx, ...data, t };
192
+ return _readCtx();
193
+ }
194
+ function getCtx() {
195
+ return _readCtx();
178
196
  }
179
- var TsxContext = createContext({ params: {}, query: {}, parsed: {}, prefs: {}, env: {}, t: fallbackT, user: {} });
197
+ var TsxContext = createContext(DEFAULT_CTX);
180
198
 
181
199
  // client-router.ts
182
200
  var _navigating = false;
@@ -521,6 +539,7 @@ export {
521
539
  Link,
522
540
  TsxContext,
523
541
  createStore,
542
+ getCtx,
524
543
  navigate,
525
544
  setCtx,
526
545
  useAction,
@@ -9,6 +9,17 @@ export interface CtxValue {
9
9
  t: (key: string, params?: Record<string, string>, fallback?: string) => string;
10
10
  env: Record<string, string>;
11
11
  }
12
+ /** @internal Injected by tsx-instance.ts for async-safe context isolation */
13
+ export declare function __registerAls(getStore: () => CtxValue | undefined): void;
12
14
  export declare function setCtx(value: Partial<CtxValue>): void;
15
+ /**
16
+ * React hook — returns the current request context.
17
+ * Must be called from a React component or custom hook.
18
+ */
13
19
  export declare function useCtx(): CtxValue;
20
+ /**
21
+ * Plain accessor — returns the current request context without calling any React hooks.
22
+ * Safe to call from utility functions, route handlers, middleware, load functions, etc.
23
+ */
24
+ export declare function getCtx(): CtxValue;
14
25
  export declare const TsxContext: import("react").Context<CtxValue>;
@@ -1,6 +1,6 @@
1
1
  import { Router } from './router.ts';
2
- import { TsxContext, useCtx, setCtx } from './tsx-context.ts';
3
- export { TsxContext, useCtx, setCtx };
2
+ import { TsxContext, useCtx, setCtx, getCtx } from './tsx-context.ts';
3
+ export { TsxContext, useCtx, setCtx, getCtx };
4
4
  export interface TsxOptions {
5
5
  dir: string;
6
6
  }
@@ -19,8 +19,18 @@ export declare class TsxInstance {
19
19
  private clientBundleCache;
20
20
  private clientBuildParams;
21
21
  private clientRouteLog;
22
+ private watcher;
23
+ private twWatcher;
24
+ private debounceTimer;
22
25
  constructor(options: TsxOptions);
23
- build(): Promise<Router>;
26
+ build(): Promise<Router & {
27
+ stop: () => void;
28
+ }>;
29
+ /**
30
+ * Clean up file watchers and pending timers. Call when shutting down
31
+ * to prevent resource leaks.
32
+ */
33
+ stop(): void;
24
34
  private compileTailwind;
25
35
  private setupTailwind;
26
36
  private buildClientBundle;
package/dist/tsx.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- import { TsxContext, useCtx, setCtx } from './tsx-instance.ts';
1
+ import { TsxContext, useCtx, setCtx, getCtx } from './tsx-instance.ts';
2
2
  import type { TsxOptions } from './tsx-instance.ts';
3
3
  import type { Router } from './router.ts';
4
- export { TsxContext, useCtx, setCtx };
4
+ export { TsxContext, useCtx, setCtx, getCtx };
5
5
  export type { TsxOptions };
6
- export declare function tsx(options: TsxOptions): Promise<Router>;
6
+ export declare function tsx(options: TsxOptions): Promise<Router & {
7
+ stop: () => void;
8
+ }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weifuwu",
3
- "version": "0.17.13",
3
+ "version": "0.17.17",
4
4
  "description": "Web-standard HTTP framework for Node.js — (req, ctx) => Response",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",