weifuwu 0.24.1 → 0.24.3

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 (58) hide show
  1. package/README.md +818 -712
  2. package/cli/template/app.ts +5 -1
  3. package/cli/template/index.ts +4 -1
  4. package/cli/template/locales/en.json +6 -1
  5. package/cli/template/locales/zh-CN.json +6 -1
  6. package/cli/template/locales/zh-TW.json +6 -1
  7. package/cli/template/locales/zh.json +6 -1
  8. package/cli/template/ui/app/globals.css +1 -1
  9. package/cli/template/ui/app/page.tsx +55 -16
  10. package/cli.ts +148 -104
  11. package/dist/agent/rest.d.ts +1 -1
  12. package/dist/agent/run.d.ts +2 -2
  13. package/dist/ai/workflow.d.ts +1 -1
  14. package/dist/ai-sdk.d.ts +1 -1
  15. package/dist/cli.js +135 -97
  16. package/dist/compile.d.ts +7 -12
  17. package/dist/cookie.d.ts +24 -0
  18. package/dist/fts.d.ts +5 -5
  19. package/dist/iii/index.d.ts +1 -1
  20. package/dist/index.d.ts +5 -5
  21. package/dist/index.js +1233 -639
  22. package/dist/live.d.ts +2 -3
  23. package/dist/logdb/rest.d.ts +1 -1
  24. package/dist/mailer.d.ts +1 -1
  25. package/dist/messager/agent.d.ts +2 -2
  26. package/dist/messager/rest.d.ts +3 -3
  27. package/dist/messager/ws.d.ts +3 -3
  28. package/dist/module-server.d.ts +10 -0
  29. package/dist/opencode/index.d.ts +1 -1
  30. package/dist/opencode/permissions.d.ts +1 -1
  31. package/dist/opencode/run.d.ts +1 -1
  32. package/dist/opencode/session.d.ts +9 -9
  33. package/dist/opencode/tools/web.d.ts +1 -1
  34. package/dist/opencode/ws.d.ts +1 -2
  35. package/dist/permissions.d.ts +2 -2
  36. package/dist/postgres/module.d.ts +3 -3
  37. package/dist/postgres/schema/index.d.ts +1 -1
  38. package/dist/postgres/schema/table.d.ts +22 -20
  39. package/dist/postgres/types.d.ts +4 -4
  40. package/dist/queue/types.d.ts +1 -1
  41. package/dist/react.d.ts +1 -1
  42. package/dist/react.js +135 -90
  43. package/dist/router.d.ts +10 -10
  44. package/dist/server-registry.d.ts +12 -0
  45. package/dist/session.d.ts +1 -2
  46. package/dist/stream.d.ts +0 -5
  47. package/dist/tenant/graphql.d.ts +2 -2
  48. package/dist/tenant/index.d.ts +1 -1
  49. package/dist/tenant/rest.d.ts +2 -2
  50. package/dist/test-utils.d.ts +3 -3
  51. package/dist/user/index.d.ts +1 -1
  52. package/dist/user/oauth-login.d.ts +2 -2
  53. package/dist/vendor.d.ts +4 -0
  54. package/opencode/ui/app/globals.css +1 -1
  55. package/opencode/ui/app/layout.tsx +2 -3
  56. package/opencode/ui/app/page.tsx +302 -73
  57. package/package.json +27 -4
  58. package/cli/template/.weifuwu/ssr/2e3a7e60.js +0 -112
package/dist/cli.js CHANGED
@@ -28,7 +28,12 @@ async function cmdInit(name, opts) {
28
28
  const targetDir = resolve(process.cwd(), name);
29
29
  const pkg = await readPkg();
30
30
  const v = pkg.version;
31
- const depVer = (depName) => `^${(pkg.devDependencies?.[depName] || "0.0.0").replace(/^\^/, "")}`;
31
+ const typeVersions = {
32
+ "@types/react": "^19",
33
+ "@types/react-dom": "^19",
34
+ "@types/node": "^22"
35
+ };
36
+ const depVer = (depName) => typeVersions[depName] || `^${(pkg.devDependencies?.[depName] || "0.0.0").replace(/^\^/, "")}`;
32
37
  await mkdir(targetDir, { recursive: true });
33
38
  const templateDir = join(pkgRoot, "cli", "template");
34
39
  await cp(templateDir, targetDir, { recursive: true });
@@ -53,23 +58,29 @@ async function cmdInit(name, opts) {
53
58
  await rmrf(join(targetDir, "locales"));
54
59
  } catch {
55
60
  }
56
- await writeFile(join(targetDir, "app.ts"), [
57
- `import { Router } from 'weifuwu'`,
58
- ``,
59
- `export const app = new Router()`,
60
- ``,
61
- `app.get('/', () => new Response('Hello from ${name}!'))`,
62
- `app.get('/api/ping', () => Response.json({ pong: true, time: new Date().toISOString() }))`,
63
- ``
64
- ].join("\n"));
65
- await writeFile(join(targetDir, "index.ts"), [
66
- `import { serve } from 'weifuwu'`,
67
- `import { app } from './app.ts'`,
68
- ``,
69
- `const port = Number(process.env.PORT) || 3000`,
70
- `serve(app.handler(), { port })`,
71
- ``
72
- ].join("\n"));
61
+ await writeFile(
62
+ join(targetDir, "app.ts"),
63
+ [
64
+ `import { Router } from 'weifuwu'`,
65
+ ``,
66
+ `export const app = new Router()`,
67
+ ``,
68
+ `app.get('/', () => new Response('Hello from ${name}!'))`,
69
+ `app.get('/api/ping', () => Response.json({ pong: true, time: new Date().toISOString() }))`,
70
+ ``
71
+ ].join("\n")
72
+ );
73
+ await writeFile(
74
+ join(targetDir, "index.ts"),
75
+ [
76
+ `import { serve } from 'weifuwu'`,
77
+ `import { app } from './app.ts'`,
78
+ ``,
79
+ `const port = Number(process.env.PORT) || 3000`,
80
+ `serve(app.handler(), { port })`,
81
+ ``
82
+ ].join("\n")
83
+ );
73
84
  }
74
85
  const deps = { weifuwu: `^${v}` };
75
86
  const devDeps = {};
@@ -81,55 +92,74 @@ async function cmdInit(name, opts) {
81
92
  devDeps["@types/react-dom"] = depVer("@types/react-dom");
82
93
  }
83
94
  devDeps["@types/node"] = depVer("@types/node");
84
- await writeFile(join(targetDir, "package.json"), JSON.stringify({
85
- name,
86
- type: "module",
87
- scripts: {
88
- dev: "NODE_ENV=development node --watch index.ts",
89
- start: "node index.ts"
90
- },
91
- dependencies: deps,
92
- devDependencies: devDeps
93
- }, null, 2) + "\n");
95
+ await writeFile(
96
+ join(targetDir, "package.json"),
97
+ JSON.stringify(
98
+ {
99
+ name,
100
+ type: "module",
101
+ scripts: {
102
+ dev: "NODE_ENV=development node --watch index.ts",
103
+ start: "node index.ts"
104
+ },
105
+ dependencies: deps,
106
+ devDependencies: devDeps
107
+ },
108
+ null,
109
+ 2
110
+ ) + "\n"
111
+ );
94
112
  const include = opts.minimal ? ["*.ts"] : ["*.ts", "ui/**/*.ts", "ui/**/*.tsx"];
95
- await writeFile(join(targetDir, "tsconfig.json"), JSON.stringify({
96
- compilerOptions: {
97
- target: "ESNext",
98
- module: "NodeNext",
99
- moduleResolution: "NodeNext",
100
- strict: true,
101
- jsx: "react-jsx",
102
- skipLibCheck: true,
103
- noEmit: true,
104
- allowImportingTsExtensions: true
105
- },
106
- include
107
- }, null, 2) + "\n");
113
+ await writeFile(
114
+ join(targetDir, "tsconfig.json"),
115
+ JSON.stringify(
116
+ {
117
+ compilerOptions: {
118
+ target: "ESNext",
119
+ module: "NodeNext",
120
+ moduleResolution: "NodeNext",
121
+ strict: true,
122
+ jsx: "react-jsx",
123
+ skipLibCheck: true,
124
+ noEmit: true,
125
+ allowImportingTsExtensions: true
126
+ },
127
+ include
128
+ },
129
+ null,
130
+ 2
131
+ ) + "\n"
132
+ );
108
133
  await writeFile(join(targetDir, ".gitignore"), "node_modules\ndist\n.env\n.sessions\n.weifuwu\n");
109
134
  await writeFile(join(targetDir, ".env"), "PORT=3000\n");
110
- await writeFile(join(targetDir, "AGENTS.md"), [
111
- `# ${name}`,
112
- "",
113
- `This is a [weifuwu](https://weifuwu.io) application \u2014 pure Node.js, no build step.`,
114
- "",
115
- "## Commands",
116
- "",
117
- "- `npm run dev` \u2014 start dev server with hot reload",
118
- "- `npm start` \u2014 start production server",
119
- "- `npm install` \u2014 install dependencies",
120
- "- `npx tsc --noEmit` \u2014 type-check",
121
- "",
122
- "## API Reference",
123
- "",
124
- "See `node_modules/weifuwu/README.md` for the full documentation.",
125
- ""
126
- ].join("\n"));
135
+ await writeFile(
136
+ join(targetDir, "AGENTS.md"),
137
+ [
138
+ `# ${name}`,
139
+ "",
140
+ `This is a [weifuwu](https://weifuwu.io) application \u2014 pure Node.js, no build step.`,
141
+ "",
142
+ "## Commands",
143
+ "",
144
+ "- `npm run dev` \u2014 start dev server with hot reload",
145
+ "- `npm start` \u2014 start production server",
146
+ "- `npm install` \u2014 install dependencies",
147
+ "- `npx tsc --noEmit` \u2014 type-check",
148
+ "",
149
+ "## API Reference",
150
+ "",
151
+ "See `node_modules/weifuwu/README.md` for the full documentation.",
152
+ ""
153
+ ].join("\n")
154
+ );
127
155
  if (!opts.skipInstall) {
128
156
  console.log("\nInstalling dependencies...");
129
157
  execSync("npm install", { cwd: targetDir, stdio: "inherit" });
130
158
  }
131
- console.log(`
132
- \u2705 Created ${name}/ \u2014 cd ${name} && ${opts.skipInstall ? "npm install && " : ""}npm run dev`);
159
+ console.log(
160
+ `
161
+ \u2705 Created ${name}/ \u2014 cd ${name} && ${opts.skipInstall ? "npm install && " : ""}npm run dev`
162
+ );
133
163
  }
134
164
  async function cmdDev() {
135
165
  const entry = existsSync("index.ts") ? "index.ts" : existsSync("app.ts") ? "app.ts" : null;
@@ -152,43 +182,49 @@ async function cmdGenerate(type, name) {
152
182
  process.exit(1);
153
183
  }
154
184
  await mkdir(dir, { recursive: true });
155
- await writeFile(join(dir, "index.ts"), [
156
- `import type { Middleware } from 'weifuwu'`,
157
- ``,
158
- `export interface ${capitalize(name)}Options {`,
159
- ` // Add your options here`,
160
- `}`,
161
- ``,
162
- `export function ${name}(opts?: ${capitalize(name)}Options): Middleware {`,
163
- ` return async (req, ctx, next) => {`,
164
- ` // Your middleware logic here`,
165
- ` return next(req, ctx)`,
166
- ` }`,
167
- `}`,
168
- ``
169
- ].join("\n"));
185
+ await writeFile(
186
+ join(dir, "index.ts"),
187
+ [
188
+ `import type { Middleware } from 'weifuwu'`,
189
+ ``,
190
+ `export interface ${capitalize(name)}Options {`,
191
+ ` // Add your options here`,
192
+ `}`,
193
+ ``,
194
+ `export function ${name}(opts?: ${capitalize(name)}Options): Middleware {`,
195
+ ` return async (req, ctx, next) => {`,
196
+ ` // Your middleware logic here`,
197
+ ` return next(req, ctx)`,
198
+ ` }`,
199
+ `}`,
200
+ ``
201
+ ].join("\n")
202
+ );
170
203
  await mkdir(join(dir, "..", "test"), { recursive: true });
171
- await writeFile(join(dir, "..", "test", `${name}.test.ts`), [
172
- `import { describe, it } from 'node:test'`,
173
- `import assert from 'node:assert/strict'`,
174
- `import { ${name} } from '../${name}/index.ts'`,
175
- `import { Router } from 'weifuwu'`,
176
- ``,
177
- `describe('${name}', () => {`,
178
- ` it('works as middleware', async () => {`,
179
- ` const app = new Router()`,
180
- ` app.use(${name}())`,
181
- ` app.get('/', () => new Response('ok'))`,
182
- ``,
183
- ` const res = await app.handler()(`,
184
- ` new Request('http://localhost/'),`,
185
- ` { params: {}, query: {} } as any,`,
186
- ` )`,
187
- ` assert.equal(res.status, 200)`,
188
- ` })`,
189
- `})`,
190
- ``
191
- ].join("\n"));
204
+ await writeFile(
205
+ join(dir, "..", "test", `${name}.test.ts`),
206
+ [
207
+ `import { describe, it } from 'node:test'`,
208
+ `import assert from 'node:assert/strict'`,
209
+ `import { ${name} } from '../${name}/index.ts'`,
210
+ `import { Router } from 'weifuwu'`,
211
+ ``,
212
+ `describe('${name}', () => {`,
213
+ ` it('works as middleware', async () => {`,
214
+ ` const app = new Router()`,
215
+ ` app.use(${name}())`,
216
+ ` app.get('/', () => new Response('ok'))`,
217
+ ``,
218
+ ` const res = await app.handler()(`,
219
+ ` new Request('http://localhost/'),`,
220
+ ` { params: {}, query: {} } as any,`,
221
+ ` )`,
222
+ ` assert.equal(res.status, 200)`,
223
+ ` })`,
224
+ `})`,
225
+ ``
226
+ ].join("\n")
227
+ );
192
228
  console.log(`\u2705 Created module ${name}/ with index.ts and test/${name}.test.ts`);
193
229
  }
194
230
  function capitalize(s) {
@@ -242,7 +278,9 @@ if (cmd === "version" || cmd === "-v" || cmd === "--version") {
242
278
  console.error("Usage: npx weifuwu init <name> [--minimal] [--skip-install]");
243
279
  process.exit(1);
244
280
  }
245
- cmdInit(name, { minimal: !!values.minimal, skipInstall: !!values["skip-install"] }).catch(console.error);
281
+ cmdInit(name, { minimal: !!values.minimal, skipInstall: !!values["skip-install"] }).catch(
282
+ console.error
283
+ );
246
284
  } else if (cmd === "dev") {
247
285
  cmdDev();
248
286
  } else if (cmd === "generate" || cmd === "g") {
package/dist/compile.d.ts CHANGED
@@ -2,21 +2,16 @@ export declare const OUT_DIR = ".weifuwu/ssr";
2
2
  export declare function id(s: string): string;
3
3
  export declare function clearCompileCache(): void;
4
4
  export declare function compileTsx(path: string): Promise<any>;
5
- /** Dev hot-reload: CJS + in-memory + vm (faster than ESM + disk + import) */
6
- export declare function compileTsxDev(path: string): Promise<any>;
7
- /** Auto-select dev (vm) or prod (ESM + import) compilation */
5
+ /**
6
+ * Dev hot-reload: per-file transformSync (~0.5ms) + shared vm context.
7
+ * No bundler, no disk I/O. Relative imports are resolved through
8
+ * server-registry recursively.
9
+ */
10
+ export declare function compileTsxDev(path: string): any;
11
+ /** Auto-select dev (registry+vm) or prod (ESM + import) compilation */
8
12
  export declare function compile(path: string): Promise<any>;
9
13
  export declare let vendorHash: string;
10
14
  /** Build a single vendor bundle containing all needed vendor modules */
11
15
  export declare function compileVendorBundle(): Promise<string>;
12
- /** Compile page component for browser (served at /__ssr/[hash].js).
13
- * The weifuwu source modules are externalized — they come from the vendor
14
- * bundle at runtime via importmap, ensuring store is shared. */
15
- export declare function compileBrowser(path: string, outDir?: string): Promise<string>;
16
- /** Hot-reload: ESM bundle, calls __WFW_REFRESH on import */
17
- export declare function compileHotComponent(path: string): Promise<{
18
- hash: string;
19
- code: string;
20
- }>;
21
16
  /** Clean up esbuild's internal worker pool. Call when you're done compiling. */
22
17
  export declare function closeCompile(): Promise<void>;
package/dist/cookie.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ /** Options for setting a cookie. All fields map to standard Set-Cookie attributes. */
1
2
  export interface CookieOptions {
2
3
  domain?: string;
3
4
  path?: string;
@@ -7,6 +8,29 @@ export interface CookieOptions {
7
8
  secure?: boolean;
8
9
  sameSite?: 'strict' | 'lax' | 'none';
9
10
  }
11
+ /** Parse cookies from a Request's `Cookie` header.
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * const cookies = getCookies(req)
16
+ * console.log(cookies.session_id) // value or undefined
17
+ * ``` */
10
18
  export declare function getCookies(req: Request): Record<string, string>;
19
+ /** Set a cookie on a Response.
20
+ *
21
+ * Appends a `Set-Cookie` header to the existing response headers.
22
+ * Returns a new Response with the added header.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const res = new Response('ok')
27
+ * return setCookie(res, 'session', token, { httpOnly: true, path: '/' })
28
+ * ``` */
11
29
  export declare function setCookie(res: Response, name: string, value: string, options?: CookieOptions): Response;
30
+ /** Delete a cookie by setting `Max-Age=0`.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * return deleteCookie(res, 'session')
35
+ * ``` */
12
36
  export declare function deleteCookie(res: Response, name: string, options?: Omit<CookieOptions, 'maxAge'>): Response;
package/dist/fts.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Sql } from './vendor.ts';
1
+ import type { SqlClient } from './vendor.ts';
2
2
  import type { BoundTable } from './postgres/schema/index.ts';
3
3
  export interface FTSSearchResult {
4
4
  /** Primary key value */
@@ -24,12 +24,12 @@ export interface FTSSearchOptions {
24
24
  rankColumn?: string;
25
25
  minRank?: number;
26
26
  }
27
- export declare function createIndex(sql: Sql<{}>, table: BoundTable<any>, fields: string[], options?: FTSCreateIndexOptions): Promise<void>;
28
- export declare function dropIndex(sql: Sql<{}>, table: BoundTable<any>, options?: {
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
29
  indexName?: string;
30
30
  }): Promise<void>;
31
- export declare function search<T extends Record<string, unknown>>(sql: Sql<{}>, table: BoundTable<T>, query: string, options?: FTSSearchOptions): Promise<FTSSearchResult[]>;
32
- export declare function suggest(sql: Sql<{}>, table: BoundTable<any>, prefix: string, options?: {
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
33
  field?: string;
34
34
  language?: string;
35
35
  limit?: number;
@@ -1,4 +1,4 @@
1
1
  export { iii } from './client.ts';
2
2
  export { createWorker } from './worker.ts';
3
3
  export { registerWorker } from './register-worker.ts';
4
- export type { IIIModule, IIIOptions, Worker, WorkerInfo, FunctionInfo, TriggerInfo, FunctionHandler, FunctionContext, TriggerInput, RemoteWorker } from './types.ts';
4
+ export type { IIIModule, IIIOptions, Worker, WorkerInfo, FunctionInfo, TriggerInfo, FunctionHandler, FunctionContext, TriggerInput, RemoteWorker, } from './types.ts';
package/dist/index.d.ts CHANGED
@@ -57,7 +57,7 @@ export type { AgentOptions, AgentModule, AgentConfig, RunParams, RunResult, Know
57
57
  export { messager } from './messager/index.ts';
58
58
  export type { MessagerOptions, MessagerModule, Channel, ChannelMember, Message, } from './messager/types.ts';
59
59
  export { deploy, defineConfig } from './deploy/index.ts';
60
- export type { DeployConfig, AppConfig, DeployServer, AppStatus, } from './deploy/types.ts';
60
+ export type { DeployConfig, AppConfig, DeployServer, AppStatus } from './deploy/types.ts';
61
61
  export { opencode } from './opencode/index.ts';
62
62
  export type { OpencodeOptions, OpencodeModule, SkillDef, OpencodePermissions, Session as OpencodeSession, } from './opencode/types.ts';
63
63
  export { health } from './health.ts';
@@ -77,20 +77,20 @@ export type { MailerOptions, MailOptions, Mailer } from './mailer.ts';
77
77
  export { csrf } from './csrf.ts';
78
78
  export type { CsrfOptions, CsrfInjected } from './csrf.ts';
79
79
  export { logdb } from './logdb/index.ts';
80
- export type { LogdbOptions, LogdbModule, LogEntry, LogEntryInput, } from './logdb/types.ts';
80
+ export type { LogdbOptions, LogdbModule, LogEntry, LogEntryInput } from './logdb/types.ts';
81
81
  export { iii, createWorker, registerWorker } from './iii/index.ts';
82
82
  export type { IIIModule, IIIOptions, WorkerInfo, FunctionInfo, TriggerInfo, FunctionHandler, FunctionContext, TriggerInput, RemoteWorker, TriggerRequest, } from './iii/types.ts';
83
83
  export { ssr } from './ssr.ts';
84
84
  export { session, MemoryStore, RedisStore } from './session.ts';
85
- export type { Session, SessionOptions, SessionStore, SessionData, SessionInjected } from './session.ts';
85
+ export type { Session, SessionOptions, SessionStore, SessionData, SessionInjected, } from './session.ts';
86
86
  export { cache, MemoryCache, RedisCache } from './cache.ts';
87
87
  export type { CacheOptions, CacheStore, CacheMiddleware, CachedResponse } from './cache.ts';
88
88
  export { webhook } from './webhook.ts';
89
- export type { WebhookOptions, WebhookModule, WebhookEvent, WebhookHandler, PlatformConfig, CustomVerifierConfig } from './webhook.ts';
89
+ export type { WebhookOptions, WebhookModule, WebhookEvent, WebhookHandler, PlatformConfig, CustomVerifierConfig, } from './webhook.ts';
90
90
  export * as fts from './fts.ts';
91
91
  export { s3 } from './s3.ts';
92
92
  export type { S3Options, S3PutOptions, S3UrlOptions, S3Module, S3Body } from './s3.ts';
93
93
  export { knowledgeBase } from './kb/index.ts';
94
- export type { KBOptions, KBIngestOptions, KBSearchResult, KBSearchOptions, KBListEntry, KBModule } from './kb/types.ts';
94
+ export type { KBOptions, KBIngestOptions, KBSearchResult, KBSearchOptions, KBListEntry, KBModule, } from './kb/types.ts';
95
95
  export { permissions } from './permissions.ts';
96
96
  export type { PermissionsOptions, PermissionsModule } from './permissions.ts';