weifuwu 0.25.2 → 0.27.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 (208) hide show
  1. package/README.md +291 -2489
  2. package/ai/provider.ts +129 -0
  3. package/ai/stream.ts +63 -0
  4. package/cli.ts +55 -257
  5. package/core/cookie.ts +114 -0
  6. package/core/env.ts +142 -0
  7. package/core/logger.ts +72 -0
  8. package/core/router.ts +795 -0
  9. package/core/serve.ts +294 -0
  10. package/core/sse.ts +85 -0
  11. package/core/trace.ts +146 -0
  12. package/graphql.ts +267 -0
  13. package/hub.ts +133 -0
  14. package/index.ts +71 -0
  15. package/mailer.ts +81 -0
  16. package/middleware/compress.ts +103 -0
  17. package/middleware/cors.ts +81 -0
  18. package/middleware/csrf.ts +112 -0
  19. package/middleware/flash.ts +144 -0
  20. package/middleware/health.ts +44 -0
  21. package/middleware/helmet.ts +98 -0
  22. package/middleware/i18n.ts +175 -0
  23. package/middleware/rate-limit.ts +167 -0
  24. package/middleware/request-id.ts +60 -0
  25. package/middleware/static.ts +149 -0
  26. package/middleware/theme.ts +84 -0
  27. package/middleware/upload.ts +168 -0
  28. package/middleware/validate.ts +186 -0
  29. package/package.json +14 -36
  30. package/postgres/client.ts +132 -0
  31. package/postgres/index.ts +4 -0
  32. package/postgres/module.ts +37 -0
  33. package/postgres/schema/columns.ts +186 -0
  34. package/postgres/schema/index.ts +36 -0
  35. package/postgres/schema/sql.ts +39 -0
  36. package/postgres/schema/table.ts +548 -0
  37. package/postgres/schema/where.ts +99 -0
  38. package/postgres/types.ts +48 -0
  39. package/queue/cron.ts +90 -0
  40. package/queue/index.ts +654 -0
  41. package/queue/types.ts +60 -0
  42. package/redis/client.ts +24 -0
  43. package/{dist/redis/index.d.ts → redis/index.ts} +2 -2
  44. package/redis/types.ts +28 -0
  45. package/types.ts +78 -0
  46. package/cli/template/app.ts +0 -22
  47. package/cli/template/index.ts +0 -10
  48. package/cli/template/locales/en.json +0 -13
  49. package/cli/template/locales/zh-CN.json +0 -13
  50. package/cli/template/locales/zh-TW.json +0 -13
  51. package/cli/template/locales/zh.json +0 -13
  52. package/cli/template/ui/app/globals.css +0 -2
  53. package/cli/template/ui/app/layout.tsx +0 -15
  54. package/cli/template/ui/app/page.tsx +0 -124
  55. package/cli/template/ui/components/Greeting.tsx +0 -3
  56. package/dist/agent/client.d.ts +0 -2
  57. package/dist/agent/index.d.ts +0 -2
  58. package/dist/agent/rest.d.ts +0 -14
  59. package/dist/agent/run.d.ts +0 -19
  60. package/dist/agent/types.d.ts +0 -55
  61. package/dist/ai/provider.d.ts +0 -45
  62. package/dist/ai/utils.d.ts +0 -5
  63. package/dist/ai/workflow.d.ts +0 -17
  64. package/dist/ai-sdk.d.ts +0 -2
  65. package/dist/ai.d.ts +0 -13
  66. package/dist/analytics.d.ts +0 -45
  67. package/dist/auth.d.ts +0 -22
  68. package/dist/cache.d.ts +0 -74
  69. package/dist/cli.d.ts +0 -2
  70. package/dist/cli.js +0 -302
  71. package/dist/client-locale.d.ts +0 -25
  72. package/dist/client-pref.d.ts +0 -3
  73. package/dist/client-router.d.ts +0 -300
  74. package/dist/client-state.d.ts +0 -22
  75. package/dist/client-theme.d.ts +0 -36
  76. package/dist/compile.d.ts +0 -15
  77. package/dist/compress.d.ts +0 -20
  78. package/dist/cookie.d.ts +0 -36
  79. package/dist/cors.d.ts +0 -25
  80. package/dist/cron-utils.d.ts +0 -73
  81. package/dist/csrf.d.ts +0 -47
  82. package/dist/deploy/config.d.ts +0 -2
  83. package/dist/deploy/gateway.d.ts +0 -2
  84. package/dist/deploy/index.d.ts +0 -4
  85. package/dist/deploy/manager.d.ts +0 -16
  86. package/dist/deploy/process.d.ts +0 -14
  87. package/dist/deploy/types.d.ts +0 -53
  88. package/dist/env.d.ts +0 -69
  89. package/dist/error-boundary.d.ts +0 -2
  90. package/dist/flash.d.ts +0 -90
  91. package/dist/fts.d.ts +0 -36
  92. package/dist/graphql.d.ts +0 -16
  93. package/dist/head.d.ts +0 -6
  94. package/dist/health.d.ts +0 -24
  95. package/dist/helmet.d.ts +0 -33
  96. package/dist/html-shell.d.ts +0 -1
  97. package/dist/hub.d.ts +0 -37
  98. package/dist/i18n.d.ts +0 -39
  99. package/dist/iii/client.d.ts +0 -2
  100. package/dist/iii/index.d.ts +0 -4
  101. package/dist/iii/register-worker.d.ts +0 -9
  102. package/dist/iii/rest.d.ts +0 -3
  103. package/dist/iii/stream.d.ts +0 -82
  104. package/dist/iii/types.d.ts +0 -121
  105. package/dist/iii/worker.d.ts +0 -2
  106. package/dist/iii/ws.d.ts +0 -22
  107. package/dist/index.d.ts +0 -101
  108. package/dist/index.js +0 -12752
  109. package/dist/kb/index.d.ts +0 -3
  110. package/dist/kb/types.d.ts +0 -72
  111. package/dist/layout.d.ts +0 -2
  112. package/dist/live.d.ts +0 -7
  113. package/dist/logdb/client.d.ts +0 -2
  114. package/dist/logdb/index.d.ts +0 -2
  115. package/dist/logdb/rest.d.ts +0 -5
  116. package/dist/logdb/types.d.ts +0 -27
  117. package/dist/logger.d.ts +0 -16
  118. package/dist/mailer.d.ts +0 -51
  119. package/dist/mcp.d.ts +0 -34
  120. package/dist/messager/agent.d.ts +0 -11
  121. package/dist/messager/client.d.ts +0 -2
  122. package/dist/messager/index.d.ts +0 -2
  123. package/dist/messager/rest.d.ts +0 -15
  124. package/dist/messager/types.d.ts +0 -57
  125. package/dist/messager/ws.d.ts +0 -14
  126. package/dist/module-server.d.ts +0 -9
  127. package/dist/not-found.d.ts +0 -2
  128. package/dist/notifier/client.d.ts +0 -2
  129. package/dist/notifier/index.d.ts +0 -2
  130. package/dist/notifier/types.d.ts +0 -105
  131. package/dist/opencode/client.d.ts +0 -2
  132. package/dist/opencode/index.d.ts +0 -2
  133. package/dist/opencode/permissions.d.ts +0 -5
  134. package/dist/opencode/prompt.d.ts +0 -8
  135. package/dist/opencode/rest.d.ts +0 -16
  136. package/dist/opencode/run.d.ts +0 -13
  137. package/dist/opencode/session.d.ts +0 -26
  138. package/dist/opencode/skills.d.ts +0 -4
  139. package/dist/opencode/tools/bash.d.ts +0 -6
  140. package/dist/opencode/tools/edit.d.ts +0 -19
  141. package/dist/opencode/tools/glob.d.ts +0 -9
  142. package/dist/opencode/tools/grep.d.ts +0 -17
  143. package/dist/opencode/tools/index.d.ts +0 -12
  144. package/dist/opencode/tools/question.d.ts +0 -5
  145. package/dist/opencode/tools/read.d.ts +0 -16
  146. package/dist/opencode/tools/skill.d.ts +0 -18
  147. package/dist/opencode/tools/web.d.ts +0 -18
  148. package/dist/opencode/tools/write.d.ts +0 -13
  149. package/dist/opencode/types.d.ts +0 -90
  150. package/dist/opencode/ws.d.ts +0 -21
  151. package/dist/permissions.d.ts +0 -51
  152. package/dist/postgres/client.d.ts +0 -4
  153. package/dist/postgres/index.d.ts +0 -4
  154. package/dist/postgres/module.d.ts +0 -17
  155. package/dist/postgres/schema/columns.d.ts +0 -99
  156. package/dist/postgres/schema/index.d.ts +0 -6
  157. package/dist/postgres/schema/sql.d.ts +0 -22
  158. package/dist/postgres/schema/table.d.ts +0 -141
  159. package/dist/postgres/schema/where.d.ts +0 -29
  160. package/dist/postgres/types.d.ts +0 -50
  161. package/dist/queue/index.d.ts +0 -2
  162. package/dist/queue/types.d.ts +0 -62
  163. package/dist/rate-limit.d.ts +0 -45
  164. package/dist/react.d.ts +0 -14
  165. package/dist/react.js +0 -751
  166. package/dist/redis/client.d.ts +0 -2
  167. package/dist/redis/types.d.ts +0 -18
  168. package/dist/request-id.d.ts +0 -40
  169. package/dist/router.d.ts +0 -73
  170. package/dist/s3.d.ts +0 -68
  171. package/dist/seo.d.ts +0 -104
  172. package/dist/serve.d.ts +0 -38
  173. package/dist/server-registry.d.ts +0 -10
  174. package/dist/session.d.ts +0 -117
  175. package/dist/sse.d.ts +0 -47
  176. package/dist/ssr-entries.d.ts +0 -4
  177. package/dist/ssr.d.ts +0 -11
  178. package/dist/static.d.ts +0 -23
  179. package/dist/stream.d.ts +0 -24
  180. package/dist/tailwind.d.ts +0 -15
  181. package/dist/tenant/client.d.ts +0 -2
  182. package/dist/tenant/graphql.d.ts +0 -3
  183. package/dist/tenant/index.d.ts +0 -2
  184. package/dist/tenant/rest.d.ts +0 -3
  185. package/dist/tenant/schema.d.ts +0 -5
  186. package/dist/tenant/types.d.ts +0 -48
  187. package/dist/tenant/utils.d.ts +0 -9
  188. package/dist/test-utils.d.ts +0 -194
  189. package/dist/theme.d.ts +0 -31
  190. package/dist/trace.d.ts +0 -95
  191. package/dist/tsx-context.d.ts +0 -32
  192. package/dist/types.d.ts +0 -47
  193. package/dist/upload.d.ts +0 -55
  194. package/dist/use-action.d.ts +0 -42
  195. package/dist/use-agent-stream.d.ts +0 -49
  196. package/dist/use-flash-message.d.ts +0 -17
  197. package/dist/use-websocket.d.ts +0 -42
  198. package/dist/user/client.d.ts +0 -30
  199. package/dist/user/index.d.ts +0 -2
  200. package/dist/user/oauth-login.d.ts +0 -21
  201. package/dist/user/oauth2.d.ts +0 -31
  202. package/dist/user/types.d.ts +0 -178
  203. package/dist/validate.d.ts +0 -32
  204. package/dist/vendor.d.ts +0 -7
  205. package/dist/webhook.d.ts +0 -79
  206. package/opencode/ui/app/globals.css +0 -1
  207. package/opencode/ui/app/layout.tsx +0 -13
  208. package/opencode/ui/app/page.tsx +0 -523
@@ -1,53 +0,0 @@
1
- import type { IncomingMessage } from 'node:http';
2
- import type { Duplex } from 'node:stream';
3
- import type { Handler, Closeable } from '../types.ts';
4
- export interface DeployConfig {
5
- domain?: string;
6
- port?: number;
7
- deployToken?: string;
8
- defaultApp?: string;
9
- apps: Record<string, AppConfig>;
10
- }
11
- export interface AppConfig {
12
- dir?: string;
13
- port?: number;
14
- entry?: string;
15
- path?: string;
16
- env?: Record<string, string>;
17
- healthEndpoint?: string;
18
- buildCommand?: string;
19
- ports?: [number, number];
20
- }
21
- export interface AppStatus {
22
- name: string;
23
- status: 'starting' | 'running' | 'stopped' | 'error';
24
- port: number;
25
- path?: string;
26
- pid?: number;
27
- uptime?: number;
28
- error?: string;
29
- }
30
- export interface DeployServer extends Closeable {
31
- close(): Promise<void>;
32
- ready: Promise<void>;
33
- url: string;
34
- apps: {
35
- list(): AppStatus[];
36
- status(name: string): AppStatus | undefined;
37
- deploy(name: string): Promise<void>;
38
- restart(name: string): Promise<void>;
39
- stop(name: string): Promise<void>;
40
- start(name: string): Promise<void>;
41
- };
42
- }
43
- export interface GatewayResult {
44
- handler: Handler;
45
- wsHandler: (req: IncomingMessage, socket: Duplex, head: Buffer) => void;
46
- }
47
- declare module '../types.ts' {
48
- interface Context {
49
- deploy?: {
50
- appName?: string;
51
- };
52
- }
53
- }
package/dist/env.d.ts DELETED
@@ -1,69 +0,0 @@
1
- import type { Context, Middleware } from './types.ts';
2
- /**
3
- * Get all public environment variables (those prefixed with `WEIFUWU_PUBLIC_`),
4
- * with the prefix stripped.
5
- *
6
- * ```ts
7
- * const pub = getPublicEnv()
8
- * // WEIFUWU_PUBLIC_API_URL=http://api.example.com → { API_URL: 'http://api.example.com' }
9
- * ```
10
- */
11
- export declare function getPublicEnv(): Record<string, string>;
12
- declare module './types.ts' {
13
- interface Context {
14
- env?: Record<string, string>;
15
- }
16
- }
17
- /**
18
- * Whether this code is running from the compiled `dist/index.js` bundle.
19
- * `false` when running TypeScript source directly (dev workflow in weifuwu repo).
20
- *
21
- * Used by modules that need to resolve package-internal files differently
22
- * depending on whether they are compiled (published npm package) or raw TS.
23
- */
24
- export declare function isBundled(): boolean;
25
- /**
26
- * Whether `NODE_ENV` is explicitly set to `'development'`.
27
- *
28
- * Used for dev-only features: HMR, livereload, React `createRoot` (not hydrate).
29
- * **Not** the opposite of {@link isProd} — when `NODE_ENV` is unset, both return `false`.
30
- */
31
- export declare function isDev(): boolean;
32
- /**
33
- * Whether `NODE_ENV` is explicitly set to `'production'`.
34
- *
35
- * Used for production-only behavior: plain-text 404, suppressed warnings, minified output.
36
- */
37
- export declare function isProd(): boolean;
38
- /**
39
- * Load environment variables from a `.env` file into `process.env`.
40
- *
41
- * Does **not** override existing `process.env` values.
42
- * Supports quoted values and inline comments.
43
- *
44
- * @param path - Path to `.env` file (default: `'.env'` relative to cwd).
45
- *
46
- * ```ts
47
- * import { loadEnv } from 'weifuwu'
48
- * loadEnv()
49
- * console.log(process.env.PORT)
50
- * ```
51
- */
52
- export declare function loadEnv(path?: string): void;
53
- /**
54
- * Public env middleware.
55
- *
56
- * Injects `ctx.env` with all environment variables prefixed with `WEIFUWU_PUBLIC_`,
57
- * with the prefix stripped. Safe to expose to the client.
58
- *
59
- * ```ts
60
- * import { env } from 'weifuwu'
61
- * app.use(env())
62
- *
63
- * // .env: WEIFUWU_PUBLIC_API_URL=https://api.example.com
64
- * // ctx: ctx.env.API_URL === 'https://api.example.com'
65
- * ```
66
- */
67
- export declare function env(): Middleware<Context, Context & {
68
- env: Record<string, string>;
69
- }>;
@@ -1,2 +0,0 @@
1
- import type { Middleware } from './types.ts';
2
- export declare function errorBoundary(errorPath: string): Middleware;
package/dist/flash.d.ts DELETED
@@ -1,90 +0,0 @@
1
- /**
2
- * Flash message middleware.
3
- *
4
- * Provides a cookie-based flash message system:
5
- * - Read: `ctx.flash.value` parses the incoming flash cookie
6
- * - Write: `ctx.flash.set(data, location)` sets a new flash and redirects
7
- * - Auto-clear: after reading, the flash cookie is cleared from the response
8
- *
9
- * ```ts
10
- * import { flash } from 'weifuwu'
11
- *
12
- * app.use(flash())
13
- *
14
- * // Read flash
15
- * app.get('/', (req, ctx) => {
16
- * const msg = ctx.flash.value // e.g. { type: 'success', text: 'Saved!' }
17
- * })
18
- *
19
- * // Set flash + redirect
20
- * app.post('/save', async (req, ctx) => {
21
- * await save()
22
- * return ctx.flash.set({ type: 'success', text: 'Saved!' }, '/articles')
23
- * })
24
- * ```
25
- */
26
- import type { Context, Middleware } from './types.ts';
27
- declare module './types.ts' {
28
- interface Context {
29
- flash: FlashInjected;
30
- }
31
- }
32
- /** Flash message module — a {@link Middleware} that injects `ctx.flash`. */
33
- export type FlashModule = Middleware<Context, Context & FlashInjected>;
34
- /** Options for {@link flash}. */
35
- export interface FlashOptions {
36
- /**
37
- * Cookie name to store the flash message.
38
- * @default 'flash'
39
- */
40
- name?: string;
41
- }
42
- /**
43
- * Flash message object injected into `ctx.flash`.
44
- *
45
- * Access the current flash with `.value`, or set a new flash with `.set()`.
46
- * The `.value` is automatically cleared after being read.
47
- */
48
- export interface FlashInjected {
49
- /**
50
- * The flash value read from the incoming cookie.
51
- * `undefined` if no flash cookie is present.
52
- * Automatically cleared after the response is sent.
53
- */
54
- value: unknown;
55
- /**
56
- * Set a flash message and return a 302 redirect response.
57
- *
58
- * @param data - Any JSON-serializable value to store as the flash message.
59
- * @param location - Redirect location (defaults to the `Referer` header).
60
- * @returns A 302 Response with a `Set-Cookie` header.
61
- *
62
- * ```ts
63
- * return ctx.flash.set({ type: 'success', text: 'Saved!' }, '/articles')
64
- * ```
65
- */
66
- set: (data: unknown, location?: string) => Response;
67
- }
68
- /**
69
- * Flash message middleware — injects `ctx.flash`.
70
- *
71
- * @param options - Cookie name configuration.
72
- * @returns Middleware that injects `ctx.flash` (`FlashInjected`).
73
- *
74
- * ```ts
75
- * app.use(flash())
76
- *
77
- * // Read
78
- * app.get('/', (req, ctx) => {
79
- * const msg = ctx.flash.value
80
- * })
81
- *
82
- * // Write + redirect
83
- * app.post('/save', async (req, ctx) => {
84
- * return ctx.flash.set({ type: 'success', text: 'Saved!' }, '/articles')
85
- * })
86
- * ```
87
- */
88
- export declare function flash(options?: FlashOptions): Middleware<Context, Context & {
89
- flash: FlashInjected;
90
- }>;
package/dist/fts.d.ts DELETED
@@ -1,36 +0,0 @@
1
- import type { SqlClient } from './vendor.ts';
2
- import type { BoundTable } from './postgres/schema/index.ts';
3
- export interface FTSSearchResult {
4
- /** Primary key value */
5
- id: unknown;
6
- /** Relevance score (0–1) */
7
- rank: number;
8
- /** The row data (all columns) */
9
- row: Record<string, unknown>;
10
- /** ts_headline highlighted snippet, if requested */
11
- headline?: string;
12
- }
13
- export interface FTSCreateIndexOptions {
14
- language?: string;
15
- indexName?: string;
16
- indexType?: 'gin' | 'gist';
17
- }
18
- export interface FTSSearchOptions {
19
- fields?: string[];
20
- limit?: number;
21
- offset?: number;
22
- headline?: boolean;
23
- language?: string;
24
- rankColumn?: string;
25
- minRank?: number;
26
- }
27
- export declare function createIndex(sql: SqlClient, table: BoundTable<any>, fields: string[], options?: FTSCreateIndexOptions): Promise<void>;
28
- export declare function dropIndex(sql: SqlClient, table: BoundTable<any>, options?: {
29
- indexName?: string;
30
- }): Promise<void>;
31
- export declare function search<T extends Record<string, unknown>>(sql: SqlClient, table: BoundTable<T>, query: string, options?: FTSSearchOptions): Promise<FTSSearchResult[]>;
32
- export declare function suggest(sql: SqlClient, table: BoundTable<any>, prefix: string, options?: {
33
- field?: string;
34
- language?: string;
35
- limit?: number;
36
- }): Promise<string[]>;
package/dist/graphql.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import { type GraphQLSchema } from 'graphql';
2
- import type { Context } from './types.ts';
3
- import { Router } from './router.ts';
4
- export interface GraphQLOptions {
5
- schema: string | GraphQLSchema;
6
- rootValue?: any;
7
- resolvers?: any;
8
- context?: (req: Request, ctx: Context) => Record<string, any> | Promise<Record<string, any>>;
9
- graphiql?: boolean;
10
- /** Max query depth (nesting). Default: 10. Set 0 to disable. */
11
- maxDepth?: number;
12
- /** Execution timeout in ms. Default: 30_000. */
13
- timeout?: number;
14
- }
15
- export type GraphQLHandler = (req: Request, ctx: Context) => GraphQLOptions | Promise<GraphQLOptions>;
16
- export declare function graphql(handler: GraphQLHandler): Router;
package/dist/head.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { type ReactNode } from 'react';
2
- export declare function Head({ children }: {
3
- children: ReactNode;
4
- }): import("react").DetailedReactHTMLElement<{
5
- id: string;
6
- }, HTMLElement>;
package/dist/health.d.ts DELETED
@@ -1,24 +0,0 @@
1
- import { Router } from './router.ts';
2
- /** Options for {@link health}. */
3
- export interface HealthOptions {
4
- /** Health check endpoint path (default: `'/__health'`). */
5
- path?: string;
6
- /** Async function that throws if the service is unhealthy. Called on each request. */
7
- check?: () => Promise<void>;
8
- }
9
- /**
10
- * Health check endpoint.
11
- *
12
- * Returns 200 with `'OK'` if the check passes, 503 if it fails.
13
- *
14
- * ```ts
15
- * import { health } from 'weifuwu'
16
- *
17
- * app.use(health({
18
- * check: async () => {
19
- * await db.query('SELECT 1')
20
- * },
21
- * }))
22
- * ```
23
- */
24
- export declare function health(options?: HealthOptions): Router;
package/dist/helmet.d.ts DELETED
@@ -1,33 +0,0 @@
1
- import type { Middleware, Context } from './types.ts';
2
- /** Options for {@link helmet}. Set any header to `false` to omit it. */
3
- export interface HelmetOptions {
4
- /** `Content-Security-Policy` header value. */
5
- contentSecurityPolicy?: string | false;
6
- /** `Cross-Origin-Embedder-Policy` header value. */
7
- crossOriginEmbedderPolicy?: string | false;
8
- /** `Cross-Origin-Opener-Policy` header value. */
9
- crossOriginOpenerPolicy?: string | false;
10
- /** `Cross-Origin-Resource-Policy` header value. */
11
- crossOriginResourcePolicy?: string | false;
12
- /** `Origin-Agent-Cluster` header value. */
13
- originAgentCluster?: string | false;
14
- /** `Referrer-Policy` header value. */
15
- referrerPolicy?: string | false;
16
- /** `Strict-Transport-Security` header value. */
17
- strictTransportSecurity?: string | false;
18
- /** `X-Content-Type-Options` header value. */
19
- xContentTypeOptions?: string | false;
20
- /** `X-DNS-Prefetch-Control` header value. */
21
- xDnsPrefetchControl?: string | false;
22
- /** `X-Download-Options` header value. */
23
- xDownloadOptions?: string | false;
24
- /** `X-Frame-Options` header value. */
25
- xFrameOptions?: string | false;
26
- /** `X-Permitted-Cross-Domain-Policies` header value. */
27
- xPermittedCrossDomainPolicies?: string | false;
28
- /** `X-XSS-Protection` header value. */
29
- xXssProtection?: string | false;
30
- /** `Permissions-Policy` header value. */
31
- permissionsPolicy?: string | false;
32
- }
33
- export declare function helmet(options?: HelmetOptions): Middleware<Context, Context>;
@@ -1 +0,0 @@
1
- export declare function buildHtmlShell(title: string, bodyElement: any, layoutComponents: any[]): any;
package/dist/hub.d.ts DELETED
@@ -1,37 +0,0 @@
1
- import type { Redis, WebSocket } from './vendor.ts';
2
- import type { Closeable } from './types.ts';
3
- /** Options for {@link createHub}. */
4
- export interface HubOptions {
5
- /** Optional Redis client for cross-process pub/sub broadcast. */
6
- redis?: Redis;
7
- /** Key prefix for Redis channels (default: `'hub:'`). */
8
- prefix?: string;
9
- }
10
- /**
11
- * In-memory (and optionally Redis-backed) pub/sub hub for WebSocket rooms.
12
- *
13
- * Used internally by the WebSocket handler to implement `ctx.ws.join()` / `ctx.ws.sendRoom()`. */
14
- export interface Hub extends Closeable {
15
- /** Subscribe a WebSocket to a room/group. */
16
- join(key: string, ws: WebSocket): void;
17
- /** Unsubscribe a WebSocket from all rooms. */
18
- leave(ws: WebSocket): void;
19
- /** Send a JSON message to all members of a room. */
20
- broadcast(key: string, data: unknown): void;
21
- /** Close the hub, disconnect Redis subscribers, clear all rooms. */
22
- close(): Promise<void>;
23
- }
24
- /**
25
- * Create a pub/sub hub for WebSocket room management.
26
- *
27
- * In-memory by default. Pass `redis` to enable cross-process broadcasting.
28
- *
29
- * ```ts
30
- * import { createHub } from 'weifuwu'
31
- *
32
- * const hub = createHub()
33
- * hub.join('room:general', ws)
34
- * hub.broadcast('room:general', { type: 'chat', text: 'Hello' })
35
- * ```
36
- */
37
- export declare function createHub(opts?: HubOptions): Hub;
package/dist/i18n.d.ts DELETED
@@ -1,39 +0,0 @@
1
- import type { Context, Middleware } from './types.ts';
2
- import { Router } from './router.ts';
3
- declare module './types.ts' {
4
- interface Context {
5
- i18n: I18nInjected;
6
- }
7
- }
8
- export interface I18nInjected {
9
- locale: string;
10
- messages?: Record<string, unknown>;
11
- t: (key: string, params?: Record<string, string>, fallback?: string) => string;
12
- set?: (value: string, loc?: string) => Response;
13
- }
14
- export interface I18nOptions {
15
- /** Default locale (default: 'en'). */
16
- default?: string;
17
- /** Directory containing `{locale}.json` translation files. */
18
- dir?: string;
19
- /** Inline translation messages keyed by locale. */
20
- messages?: Record<string, Record<string, unknown>>;
21
- /** Cookie name for locale (default: 'locale'). Set empty to disable. */
22
- cookie?: string;
23
- /** Whether to detect locale from Accept-Language header (default: true). */
24
- fromAcceptLanguage?: boolean;
25
- }
26
- /**
27
- * i18n module. Returns a Router with an attached `.middleware()` method.
28
- *
29
- * ```ts
30
- * const l = i18n({ dir: './locales' })
31
- * app.use(l.middleware()) // → ctx.i18n = { locale, t, set }
32
- * app.use('/', l) // → GET /__lang/:locale (switch route)
33
- * ```
34
- */
35
- export interface I18nModule extends Router {
36
- /** Middleware that injects `ctx.i18n = { locale, t, set }`. */
37
- middleware: () => Middleware<Context, Context & I18nInjected>;
38
- }
39
- export declare function i18n(options?: I18nOptions): I18nModule;
@@ -1,2 +0,0 @@
1
- import type { IIIModule, IIIOptions } from './types.ts';
2
- export declare function iii(_opts?: IIIOptions): IIIModule;
@@ -1,4 +0,0 @@
1
- export { iii } from './client.ts';
2
- export { createWorker } from './worker.ts';
3
- export { registerWorker } from './register-worker.ts';
4
- export type { IIIModule, IIIOptions, Worker, WorkerInfo, FunctionInfo, TriggerInfo, FunctionHandler, FunctionContext, TriggerInput, RemoteWorker, } from './types.ts';
@@ -1,9 +0,0 @@
1
- import type { FunctionHandler, TriggerInput, TriggerRequest } from './types.ts';
2
- export declare function registerWorker(url: string): {
3
- registerFunction(id: string, handler: FunctionHandler): void;
4
- unregisterFunction(id: string): void;
5
- registerTrigger(input: TriggerInput): void;
6
- unregisterTrigger(functionId: string): void;
7
- trigger(request: TriggerRequest): Promise<unknown>;
8
- close(): void;
9
- };
@@ -1,3 +0,0 @@
1
- import { Router } from '../router.ts';
2
- import type { IIIModule } from './types.ts';
3
- export declare function buildRouter(engine: IIIModule, wsHandler: any): Router;
@@ -1,82 +0,0 @@
1
- import type { Redis } from '../vendor.ts';
2
- import type { PostgresClient } from '../postgres/types.ts';
3
- import type { StreamUpdateOp, StreamSubscription } from './types.ts';
4
- export declare function createStream(opts?: {
5
- pg?: PostgresClient;
6
- redis?: Redis;
7
- streamTTL?: number;
8
- }): {
9
- subscribe(ws: WebSocket, sub: StreamSubscription): void;
10
- unsubscribe(ws: WebSocket): void;
11
- migrate(): Promise<void>;
12
- close(): Promise<void>;
13
- set(stream: string, group: string, item: string, data: unknown): Promise<{
14
- old_value: null;
15
- new_value: unknown;
16
- }>;
17
- get(stream: string, group: string, item: string): Promise<{
18
- value: any;
19
- }>;
20
- delete(stream: string, group: string, item: string): Promise<{
21
- old_value: any;
22
- }>;
23
- list(stream: string, group: string): Promise<{
24
- items: {
25
- item_id: any;
26
- data: any;
27
- }[];
28
- }>;
29
- list_groups(stream: string): Promise<{
30
- groups: any[];
31
- }>;
32
- list_all(): Promise<{
33
- streams: {
34
- stream_name: any;
35
- group_count: number;
36
- item_count: number;
37
- }[];
38
- count: number;
39
- }>;
40
- send(stream: string, group: string, type: string, data: unknown, id?: string): Promise<void>;
41
- update(stream: string, group: string, item: string, ops: StreamUpdateOp[]): Promise<{
42
- old_value: any;
43
- new_value: any;
44
- }>;
45
- } | {
46
- subscribe(ws: WebSocket, sub: StreamSubscription): void;
47
- unsubscribe(ws: WebSocket): void;
48
- migrate(): Promise<void>;
49
- close(): Promise<void>;
50
- set(stream: string, group: string, item: string, data: unknown): Promise<{
51
- old_value: unknown;
52
- new_value: unknown;
53
- }>;
54
- get(stream: string, group: string, item: string): Promise<{
55
- value: any;
56
- }>;
57
- delete(stream: string, group: string, item: string): Promise<{
58
- old_value: any;
59
- }>;
60
- list(stream: string, group: string): Promise<{
61
- items: {
62
- item_id: string;
63
- data: any;
64
- }[];
65
- }>;
66
- list_groups(stream: string): Promise<{
67
- groups: string[];
68
- }>;
69
- list_all(): Promise<{
70
- streams: {
71
- stream_name: string;
72
- group_count: number;
73
- item_count: number;
74
- }[];
75
- count: number;
76
- }>;
77
- send(stream: string, group: string, type: string, data: unknown, id?: string): Promise<void>;
78
- update(stream: string, group: string, item: string, ops: StreamUpdateOp[]): Promise<{
79
- old_value: any;
80
- new_value: any;
81
- }>;
82
- };
@@ -1,121 +0,0 @@
1
- import type { Router } from '../router.ts';
2
- import type { Closeable } from '../types.ts';
3
- import type { PostgresClient } from '../postgres/types.ts';
4
- /** A function handler receives a payload and returns a result. */
5
- export type FunctionHandler = (payload: unknown, ctx: FunctionContext) => unknown | Promise<unknown>;
6
- export interface FunctionContext {
7
- engine: IIIModule;
8
- functionId: string;
9
- workerName: string;
10
- user?: unknown;
11
- }
12
- /** Optional metadata for a trigger — iii does NOT schedule triggers, just stores them for reference. */
13
- export interface TriggerInput {
14
- type: string;
15
- function_id: string;
16
- config: Record<string, unknown>;
17
- }
18
- export interface IIIOptions {
19
- pg?: PostgresClient;
20
- }
21
- export interface TriggerRequest {
22
- function_id: string;
23
- payload: unknown;
24
- action?: 'sync' | 'void';
25
- timeout_ms?: number;
26
- }
27
- /** III (跨进程函数调用) module — register remote workers and call functions across processes. */
28
- export interface IIIModule extends Router, Closeable {
29
- wsHandler: () => any;
30
- /** Register a local worker. Its functions become callable via trigger(). */
31
- addWorker: (worker: Worker) => void;
32
- /** Call a function by ID. Returns the function's result. */
33
- trigger: (request: TriggerRequest) => Promise<unknown>;
34
- /** Remove a previously registered worker. */
35
- removeWorker: (worker: Worker) => void;
36
- /** List all registered workers. */
37
- listWorkers: () => WorkerInfo[];
38
- /** List all registered functions. */
39
- listFunctions: () => FunctionInfo[];
40
- /** List all registered trigger metadata. */
41
- listTriggers: () => TriggerInfo[];
42
- /** Create the database tables (currently no-op, kept for API compatibility). */
43
- migrate: () => Promise<void>;
44
- /** Shutdown — reject pending invocations, disconnect all workers. */
45
- close: () => Promise<void>;
46
- }
47
- export interface WorkerInfo {
48
- id: string;
49
- name: string;
50
- status: 'connected' | 'disconnected';
51
- connectedAt: number;
52
- functionCount: number;
53
- triggerCount: number;
54
- }
55
- export interface FunctionInfo {
56
- id: string;
57
- workerId: string;
58
- workerName: string;
59
- triggers: string[];
60
- }
61
- export interface TriggerInfo {
62
- id: string;
63
- type: string;
64
- function_id: string;
65
- config: Record<string, unknown>;
66
- workerId: string;
67
- }
68
- /** A worker — a group of related functions. */
69
- export interface Worker {
70
- readonly name: string;
71
- /** Register a function that can be called remotely. */
72
- registerFunction: (id: string, handler: FunctionHandler, opts?: {
73
- description?: string;
74
- }) => Worker;
75
- /** Unregister a function. */
76
- unregisterFunction: (id: string) => Worker;
77
- /** Attach metadata (the module does NOT schedule — it's stored for introspection). */
78
- registerTrigger: (input: TriggerInput) => Worker;
79
- /** Remove trigger metadata. */
80
- unregisterTrigger: (functionId: string) => Worker;
81
- /** Get all registered functions. */
82
- getFunctions: () => {
83
- id: string;
84
- handler: FunctionHandler;
85
- }[];
86
- /** Get all registered trigger metadata. */
87
- getTriggers: () => {
88
- id: string;
89
- input: TriggerInput;
90
- }[];
91
- }
92
- /** A handle to interact with a remote worker from the client side. */
93
- export interface RemoteWorker {
94
- registerFunction: (id: string, handler: FunctionHandler) => void;
95
- unregisterFunction: (id: string) => void;
96
- registerTrigger: (input: TriggerInput) => void;
97
- unregisterTrigger: (functionId: string) => void;
98
- trigger: (request: TriggerRequest) => Promise<unknown>;
99
- close: () => void;
100
- }
101
- export interface FunctionRegistration {
102
- id: string;
103
- handler: FunctionHandler;
104
- workerId: string;
105
- workerName: string;
106
- triggers: string[];
107
- }
108
- export interface TriggerRegistration {
109
- id: string;
110
- type: string;
111
- function_id: string;
112
- config: Record<string, unknown>;
113
- workerId: string;
114
- }
115
- export interface WorkerRegistration {
116
- id: string;
117
- name: string;
118
- ws?: WebSocket;
119
- functions: FunctionRegistration[];
120
- triggers: TriggerRegistration[];
121
- }
@@ -1,2 +0,0 @@
1
- import type { Worker } from './types.ts';
2
- export declare function createWorker(name: string): Worker;
package/dist/iii/ws.d.ts DELETED
@@ -1,22 +0,0 @@
1
- import type { Context } from '../types.ts';
2
- interface WsHandlerDeps {
3
- registerRemoteWorker: (ws: WebSocket, name: string) => string;
4
- unregisterRemoteWorker: (workerId: string) => void;
5
- registerRemoteFunction: (workerId: string, id: string) => void;
6
- unregisterRemoteFunction: (workerId: string, id: string) => void;
7
- registerRemoteTrigger: (workerId: string, input: {
8
- type: string;
9
- function_id: string;
10
- config: Record<string, unknown>;
11
- }) => void;
12
- unregisterRemoteTrigger: (workerId: string, functionId: string) => void;
13
- handleInvokeResult: (invocationId: string, result: unknown) => void;
14
- handleInvokeError: (invocationId: string, error: string) => void;
15
- handleInvoke: (ws: WebSocket, invocationId: string, functionId: string, payload: unknown) => void;
16
- }
17
- export declare function createWsHandler(deps: WsHandlerDeps): {
18
- open(_ws: WebSocket, _ctx: Context): void;
19
- message(ws: WebSocket, ctx: Context, data: string | Buffer): Promise<void>;
20
- close(ws: WebSocket): void;
21
- };
22
- export {};