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.
- package/README.md +291 -2489
- package/ai/provider.ts +129 -0
- package/ai/stream.ts +63 -0
- package/cli.ts +55 -257
- package/core/cookie.ts +114 -0
- package/core/env.ts +142 -0
- package/core/logger.ts +72 -0
- package/core/router.ts +795 -0
- package/core/serve.ts +294 -0
- package/core/sse.ts +85 -0
- package/core/trace.ts +146 -0
- package/graphql.ts +267 -0
- package/hub.ts +133 -0
- package/index.ts +71 -0
- package/mailer.ts +81 -0
- package/middleware/compress.ts +103 -0
- package/middleware/cors.ts +81 -0
- package/middleware/csrf.ts +112 -0
- package/middleware/flash.ts +144 -0
- package/middleware/health.ts +44 -0
- package/middleware/helmet.ts +98 -0
- package/middleware/i18n.ts +175 -0
- package/middleware/rate-limit.ts +167 -0
- package/middleware/request-id.ts +60 -0
- package/middleware/static.ts +149 -0
- package/middleware/theme.ts +84 -0
- package/middleware/upload.ts +168 -0
- package/middleware/validate.ts +186 -0
- package/package.json +14 -36
- package/postgres/client.ts +132 -0
- package/postgres/index.ts +4 -0
- package/postgres/module.ts +37 -0
- package/postgres/schema/columns.ts +186 -0
- package/postgres/schema/index.ts +36 -0
- package/postgres/schema/sql.ts +39 -0
- package/postgres/schema/table.ts +548 -0
- package/postgres/schema/where.ts +99 -0
- package/postgres/types.ts +48 -0
- package/queue/cron.ts +90 -0
- package/queue/index.ts +654 -0
- package/queue/types.ts +60 -0
- package/redis/client.ts +24 -0
- package/{dist/redis/index.d.ts → redis/index.ts} +2 -2
- package/redis/types.ts +28 -0
- package/types.ts +78 -0
- package/cli/template/app.ts +0 -22
- package/cli/template/index.ts +0 -10
- package/cli/template/locales/en.json +0 -13
- package/cli/template/locales/zh-CN.json +0 -13
- package/cli/template/locales/zh-TW.json +0 -13
- package/cli/template/locales/zh.json +0 -13
- package/cli/template/ui/app/globals.css +0 -2
- package/cli/template/ui/app/layout.tsx +0 -15
- package/cli/template/ui/app/page.tsx +0 -124
- package/cli/template/ui/components/Greeting.tsx +0 -3
- package/dist/agent/client.d.ts +0 -2
- package/dist/agent/index.d.ts +0 -2
- package/dist/agent/rest.d.ts +0 -14
- package/dist/agent/run.d.ts +0 -19
- package/dist/agent/types.d.ts +0 -55
- package/dist/ai/provider.d.ts +0 -45
- package/dist/ai/utils.d.ts +0 -5
- package/dist/ai/workflow.d.ts +0 -17
- package/dist/ai-sdk.d.ts +0 -2
- package/dist/ai.d.ts +0 -13
- package/dist/analytics.d.ts +0 -45
- package/dist/auth.d.ts +0 -22
- package/dist/cache.d.ts +0 -74
- package/dist/cli.d.ts +0 -2
- package/dist/cli.js +0 -302
- package/dist/client-locale.d.ts +0 -25
- package/dist/client-pref.d.ts +0 -3
- package/dist/client-router.d.ts +0 -300
- package/dist/client-state.d.ts +0 -22
- package/dist/client-theme.d.ts +0 -36
- package/dist/compile.d.ts +0 -15
- package/dist/compress.d.ts +0 -20
- package/dist/cookie.d.ts +0 -36
- package/dist/cors.d.ts +0 -25
- package/dist/cron-utils.d.ts +0 -73
- package/dist/csrf.d.ts +0 -47
- package/dist/deploy/config.d.ts +0 -2
- package/dist/deploy/gateway.d.ts +0 -2
- package/dist/deploy/index.d.ts +0 -4
- package/dist/deploy/manager.d.ts +0 -16
- package/dist/deploy/process.d.ts +0 -14
- package/dist/deploy/types.d.ts +0 -53
- package/dist/env.d.ts +0 -69
- package/dist/error-boundary.d.ts +0 -2
- package/dist/flash.d.ts +0 -90
- package/dist/fts.d.ts +0 -36
- package/dist/graphql.d.ts +0 -16
- package/dist/head.d.ts +0 -6
- package/dist/health.d.ts +0 -24
- package/dist/helmet.d.ts +0 -33
- package/dist/html-shell.d.ts +0 -1
- package/dist/hub.d.ts +0 -37
- package/dist/i18n.d.ts +0 -39
- package/dist/iii/client.d.ts +0 -2
- package/dist/iii/index.d.ts +0 -4
- package/dist/iii/register-worker.d.ts +0 -9
- package/dist/iii/rest.d.ts +0 -3
- package/dist/iii/stream.d.ts +0 -82
- package/dist/iii/types.d.ts +0 -121
- package/dist/iii/worker.d.ts +0 -2
- package/dist/iii/ws.d.ts +0 -22
- package/dist/index.d.ts +0 -101
- package/dist/index.js +0 -12752
- package/dist/kb/index.d.ts +0 -3
- package/dist/kb/types.d.ts +0 -72
- package/dist/layout.d.ts +0 -2
- package/dist/live.d.ts +0 -7
- package/dist/logdb/client.d.ts +0 -2
- package/dist/logdb/index.d.ts +0 -2
- package/dist/logdb/rest.d.ts +0 -5
- package/dist/logdb/types.d.ts +0 -27
- package/dist/logger.d.ts +0 -16
- package/dist/mailer.d.ts +0 -51
- package/dist/mcp.d.ts +0 -34
- package/dist/messager/agent.d.ts +0 -11
- package/dist/messager/client.d.ts +0 -2
- package/dist/messager/index.d.ts +0 -2
- package/dist/messager/rest.d.ts +0 -15
- package/dist/messager/types.d.ts +0 -57
- package/dist/messager/ws.d.ts +0 -14
- package/dist/module-server.d.ts +0 -9
- package/dist/not-found.d.ts +0 -2
- package/dist/notifier/client.d.ts +0 -2
- package/dist/notifier/index.d.ts +0 -2
- package/dist/notifier/types.d.ts +0 -105
- package/dist/opencode/client.d.ts +0 -2
- package/dist/opencode/index.d.ts +0 -2
- package/dist/opencode/permissions.d.ts +0 -5
- package/dist/opencode/prompt.d.ts +0 -8
- package/dist/opencode/rest.d.ts +0 -16
- package/dist/opencode/run.d.ts +0 -13
- package/dist/opencode/session.d.ts +0 -26
- package/dist/opencode/skills.d.ts +0 -4
- package/dist/opencode/tools/bash.d.ts +0 -6
- package/dist/opencode/tools/edit.d.ts +0 -19
- package/dist/opencode/tools/glob.d.ts +0 -9
- package/dist/opencode/tools/grep.d.ts +0 -17
- package/dist/opencode/tools/index.d.ts +0 -12
- package/dist/opencode/tools/question.d.ts +0 -5
- package/dist/opencode/tools/read.d.ts +0 -16
- package/dist/opencode/tools/skill.d.ts +0 -18
- package/dist/opencode/tools/web.d.ts +0 -18
- package/dist/opencode/tools/write.d.ts +0 -13
- package/dist/opencode/types.d.ts +0 -90
- package/dist/opencode/ws.d.ts +0 -21
- package/dist/permissions.d.ts +0 -51
- package/dist/postgres/client.d.ts +0 -4
- package/dist/postgres/index.d.ts +0 -4
- package/dist/postgres/module.d.ts +0 -17
- package/dist/postgres/schema/columns.d.ts +0 -99
- package/dist/postgres/schema/index.d.ts +0 -6
- package/dist/postgres/schema/sql.d.ts +0 -22
- package/dist/postgres/schema/table.d.ts +0 -141
- package/dist/postgres/schema/where.d.ts +0 -29
- package/dist/postgres/types.d.ts +0 -50
- package/dist/queue/index.d.ts +0 -2
- package/dist/queue/types.d.ts +0 -62
- package/dist/rate-limit.d.ts +0 -45
- package/dist/react.d.ts +0 -14
- package/dist/react.js +0 -751
- package/dist/redis/client.d.ts +0 -2
- package/dist/redis/types.d.ts +0 -18
- package/dist/request-id.d.ts +0 -40
- package/dist/router.d.ts +0 -73
- package/dist/s3.d.ts +0 -68
- package/dist/seo.d.ts +0 -104
- package/dist/serve.d.ts +0 -38
- package/dist/server-registry.d.ts +0 -10
- package/dist/session.d.ts +0 -117
- package/dist/sse.d.ts +0 -47
- package/dist/ssr-entries.d.ts +0 -4
- package/dist/ssr.d.ts +0 -11
- package/dist/static.d.ts +0 -23
- package/dist/stream.d.ts +0 -24
- package/dist/tailwind.d.ts +0 -15
- package/dist/tenant/client.d.ts +0 -2
- package/dist/tenant/graphql.d.ts +0 -3
- package/dist/tenant/index.d.ts +0 -2
- package/dist/tenant/rest.d.ts +0 -3
- package/dist/tenant/schema.d.ts +0 -5
- package/dist/tenant/types.d.ts +0 -48
- package/dist/tenant/utils.d.ts +0 -9
- package/dist/test-utils.d.ts +0 -194
- package/dist/theme.d.ts +0 -31
- package/dist/trace.d.ts +0 -95
- package/dist/tsx-context.d.ts +0 -32
- package/dist/types.d.ts +0 -47
- package/dist/upload.d.ts +0 -55
- package/dist/use-action.d.ts +0 -42
- package/dist/use-agent-stream.d.ts +0 -49
- package/dist/use-flash-message.d.ts +0 -17
- package/dist/use-websocket.d.ts +0 -42
- package/dist/user/client.d.ts +0 -30
- package/dist/user/index.d.ts +0 -2
- package/dist/user/oauth-login.d.ts +0 -21
- package/dist/user/oauth2.d.ts +0 -31
- package/dist/user/types.d.ts +0 -178
- package/dist/validate.d.ts +0 -32
- package/dist/vendor.d.ts +0 -7
- package/dist/webhook.d.ts +0 -79
- package/opencode/ui/app/globals.css +0 -1
- package/opencode/ui/app/layout.tsx +0 -13
- package/opencode/ui/app/page.tsx +0 -523
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import type { SqlClient, Context, Middleware, Closeable } from '../types.ts'
|
|
3
|
+
import type { ColumnBuilder, BoundTable, Table } from './schema/index.ts'
|
|
4
|
+
|
|
5
|
+
declare module '../types.ts' {
|
|
6
|
+
interface Context {
|
|
7
|
+
sql: SqlClient
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface PostgresInjected {
|
|
12
|
+
sql: SqlClient
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface PostgresOptions {
|
|
16
|
+
connection?: string | Record<string, unknown>
|
|
17
|
+
signal?: AbortSignal
|
|
18
|
+
closeTimeout?: number
|
|
19
|
+
max?: number
|
|
20
|
+
ssl?: boolean | Record<string, unknown>
|
|
21
|
+
idle_timeout?: number
|
|
22
|
+
connect_timeout?: number
|
|
23
|
+
/** Per-statement timeout in ms. Set to 0 to disable. Default: 30_000. */
|
|
24
|
+
statementTimeout?: number
|
|
25
|
+
/** Called after every query completes. Receives query text, duration in ms, and row count. */
|
|
26
|
+
onQuery?: (query: string, durationMs: number, rowCount: number) => void
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface PostgresClient extends Middleware<Context, Context & PostgresInjected>, Closeable {
|
|
30
|
+
sql: SqlClient
|
|
31
|
+
/** Creates the migration tracking table (_weifuwu_migrations). Called once at startup. */
|
|
32
|
+
migrate: () => Promise<void>
|
|
33
|
+
/** Record that a module's migration has been applied (idempotent). */
|
|
34
|
+
markMigrated: (moduleName: string) => Promise<void>
|
|
35
|
+
/** Check whether a module has already been migrated. */
|
|
36
|
+
isMigrated: (moduleName: string) => Promise<boolean>
|
|
37
|
+
table: {
|
|
38
|
+
<R extends Record<string, unknown>>(
|
|
39
|
+
tableName: string,
|
|
40
|
+
builders: { [K in keyof R]: ColumnBuilder<R[K]> },
|
|
41
|
+
): BoundTable<R>
|
|
42
|
+
<R extends Record<string, unknown>>(schema: Table<R>): BoundTable<R>
|
|
43
|
+
}
|
|
44
|
+
transaction: <T>(fn: (sql: any) => Promise<T>, retryOpts?: { maxRetries?: number }) => Promise<T>
|
|
45
|
+
/** Snapshot of connection pool state: active, idle, waiting, max connections. */
|
|
46
|
+
poolStats: () => { active: number; idle: number; waiting: number; max: number }
|
|
47
|
+
close: () => Promise<void>
|
|
48
|
+
}
|
package/queue/cron.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cron expression parsing utilities (moved from cron-utils.ts).
|
|
3
|
+
* Used internally by queue for scheduled job execution.
|
|
4
|
+
*
|
|
5
|
+
* All functions operate in local timezone.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
function parseField(field: string, min: number, max: number): Set<number> {
|
|
9
|
+
const values = new Set<number>()
|
|
10
|
+
|
|
11
|
+
for (const part of field.split(',')) {
|
|
12
|
+
if (part === '*') {
|
|
13
|
+
for (let i = min; i <= max; i++) values.add(i)
|
|
14
|
+
} else if (part.includes('/')) {
|
|
15
|
+
const [range, stepStr] = part.split('/')
|
|
16
|
+
const step = parseInt(stepStr, 10)
|
|
17
|
+
if (isNaN(step) || step < 1) throw new Error(`Invalid cron step: ${part}`)
|
|
18
|
+
let start = min
|
|
19
|
+
let end = max
|
|
20
|
+
if (range !== '*') {
|
|
21
|
+
const rangeParts = range.split('-')
|
|
22
|
+
start = parseInt(rangeParts[0], 10)
|
|
23
|
+
end = rangeParts.length > 1 ? parseInt(rangeParts[1], 10) : max
|
|
24
|
+
}
|
|
25
|
+
for (let i = start; i <= end; i += step) values.add(i)
|
|
26
|
+
} else if (part.includes('-')) {
|
|
27
|
+
const [s, e] = part.split('-').map(Number)
|
|
28
|
+
if (isNaN(s) || isNaN(e)) throw new Error(`Invalid cron range: ${part}`)
|
|
29
|
+
for (let i = s; i <= e; i++) values.add(i)
|
|
30
|
+
} else {
|
|
31
|
+
const val = parseInt(part, 10)
|
|
32
|
+
if (isNaN(val)) throw new Error(`Invalid cron value: ${part}`)
|
|
33
|
+
values.add(val)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const result = new Set<number>()
|
|
38
|
+
for (const v of values) {
|
|
39
|
+
if (v >= min && v <= max) result.add(v)
|
|
40
|
+
}
|
|
41
|
+
return result
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const FIELD_RANGES: [number, number][] = [
|
|
45
|
+
[0, 59],
|
|
46
|
+
[0, 23],
|
|
47
|
+
[1, 31],
|
|
48
|
+
[1, 12],
|
|
49
|
+
[0, 6],
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
export function parsePattern(pattern: string): Set<number>[] {
|
|
53
|
+
const fields = pattern.trim().split(/\s+/)
|
|
54
|
+
if (fields.length !== 5) {
|
|
55
|
+
throw new Error(`Invalid cron pattern "${pattern}": expected 5 fields, got ${fields.length}`)
|
|
56
|
+
}
|
|
57
|
+
return fields.map((f, i) => parseField(f, FIELD_RANGES[i][0], FIELD_RANGES[i][1]))
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function matches(fields: Set<number>[], date: Date): boolean {
|
|
61
|
+
return (
|
|
62
|
+
fields[0].has(date.getMinutes()) &&
|
|
63
|
+
fields[1].has(date.getHours()) &&
|
|
64
|
+
fields[2].has(date.getDate()) &&
|
|
65
|
+
fields[3].has(date.getMonth() + 1) &&
|
|
66
|
+
fields[4].has(date.getDay())
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function cronNext(expr: string, from: Date = new Date()): number {
|
|
71
|
+
const fields = parsePattern(expr)
|
|
72
|
+
|
|
73
|
+
const candidate = new Date(from.getTime() + 60_000)
|
|
74
|
+
candidate.setSeconds(0, 0)
|
|
75
|
+
|
|
76
|
+
for (let i = 0; i < 525600; i++) {
|
|
77
|
+
if (
|
|
78
|
+
fields[4].has(candidate.getDay()) &&
|
|
79
|
+
fields[3].has(candidate.getMonth() + 1) &&
|
|
80
|
+
fields[2].has(candidate.getDate()) &&
|
|
81
|
+
fields[1].has(candidate.getHours()) &&
|
|
82
|
+
fields[0].has(candidate.getMinutes())
|
|
83
|
+
) {
|
|
84
|
+
return candidate.getTime()
|
|
85
|
+
}
|
|
86
|
+
candidate.setTime(candidate.getTime() + 60_000)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
throw new Error(`No future date found for cron expression "${expr}"`)
|
|
90
|
+
}
|