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
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { ToolContext } from './index.ts';
|
|
2
|
-
export declare function createReadTool(ctx: ToolContext): import("ai").Tool<{
|
|
3
|
-
path: string;
|
|
4
|
-
offset?: number | undefined;
|
|
5
|
-
limit?: number | undefined;
|
|
6
|
-
}, {
|
|
7
|
-
error: string;
|
|
8
|
-
content: null;
|
|
9
|
-
totalLines: number;
|
|
10
|
-
linesReturned?: undefined;
|
|
11
|
-
} | {
|
|
12
|
-
content: string;
|
|
13
|
-
totalLines: number;
|
|
14
|
-
linesReturned: number;
|
|
15
|
-
error?: undefined;
|
|
16
|
-
}>;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { ToolContext } from './index.ts';
|
|
2
|
-
export declare function createSkillTool(ctx: ToolContext): import("ai").Tool<{
|
|
3
|
-
name: string;
|
|
4
|
-
}, {
|
|
5
|
-
error: string;
|
|
6
|
-
name?: undefined;
|
|
7
|
-
description?: undefined;
|
|
8
|
-
content?: undefined;
|
|
9
|
-
license?: undefined;
|
|
10
|
-
compatibility?: undefined;
|
|
11
|
-
} | {
|
|
12
|
-
name: string;
|
|
13
|
-
description: string;
|
|
14
|
-
content: string;
|
|
15
|
-
license: string | null;
|
|
16
|
-
compatibility: string | null;
|
|
17
|
-
error?: undefined;
|
|
18
|
-
}>;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { ToolContext } from './index.ts';
|
|
2
|
-
export declare function createWebTool(_ctx: ToolContext): import("ai").Tool<{
|
|
3
|
-
url: string;
|
|
4
|
-
}, {
|
|
5
|
-
content: string;
|
|
6
|
-
url: string;
|
|
7
|
-
contentType: string;
|
|
8
|
-
truncated: boolean;
|
|
9
|
-
status: number;
|
|
10
|
-
error?: undefined;
|
|
11
|
-
} | {
|
|
12
|
-
error: any;
|
|
13
|
-
url: string;
|
|
14
|
-
content: null;
|
|
15
|
-
contentType?: undefined;
|
|
16
|
-
truncated?: undefined;
|
|
17
|
-
status?: undefined;
|
|
18
|
-
}>;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { ToolContext } from './index.ts';
|
|
2
|
-
export declare function createWriteTool(ctx: ToolContext): import("ai").Tool<{
|
|
3
|
-
path: string;
|
|
4
|
-
content: string;
|
|
5
|
-
}, {
|
|
6
|
-
error: string;
|
|
7
|
-
path?: undefined;
|
|
8
|
-
size?: undefined;
|
|
9
|
-
} | {
|
|
10
|
-
path: string;
|
|
11
|
-
size: number;
|
|
12
|
-
error?: undefined;
|
|
13
|
-
}>;
|
package/dist/opencode/types.d.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import type { Router } from '../router.ts';
|
|
2
|
-
import type { PostgresClient } from '../postgres/types.ts';
|
|
3
|
-
import type { Closeable } from '../types.ts';
|
|
4
|
-
export interface Session {
|
|
5
|
-
id: string;
|
|
6
|
-
tenant_id: string | null;
|
|
7
|
-
user_id: number;
|
|
8
|
-
title: string | null;
|
|
9
|
-
agent_type: string;
|
|
10
|
-
model: string;
|
|
11
|
-
system_prompt: string | null;
|
|
12
|
-
workspace: string | null;
|
|
13
|
-
metadata: Record<string, unknown>;
|
|
14
|
-
active: boolean;
|
|
15
|
-
created_at: string;
|
|
16
|
-
updated_at: string;
|
|
17
|
-
}
|
|
18
|
-
export interface Message {
|
|
19
|
-
id: number;
|
|
20
|
-
session_id: string;
|
|
21
|
-
role: 'user' | 'assistant' | 'tool';
|
|
22
|
-
content: string | null;
|
|
23
|
-
tool_calls: unknown[] | null;
|
|
24
|
-
tool_results: unknown[] | null;
|
|
25
|
-
tokens_in: number;
|
|
26
|
-
tokens_out: number;
|
|
27
|
-
created_at: string;
|
|
28
|
-
}
|
|
29
|
-
export interface SkillDef {
|
|
30
|
-
name: string;
|
|
31
|
-
description: string;
|
|
32
|
-
content: string;
|
|
33
|
-
license?: string;
|
|
34
|
-
compatibility?: string;
|
|
35
|
-
path?: string;
|
|
36
|
-
}
|
|
37
|
-
export interface SkillRegistry {
|
|
38
|
-
all: SkillDef[];
|
|
39
|
-
get(name: string): SkillDef | undefined;
|
|
40
|
-
list(): SkillDef[];
|
|
41
|
-
}
|
|
42
|
-
export interface ToolPermission {
|
|
43
|
-
allow: boolean;
|
|
44
|
-
timeout?: number;
|
|
45
|
-
maxSize?: number;
|
|
46
|
-
}
|
|
47
|
-
export interface OpencodePermissions {
|
|
48
|
-
bash?: ToolPermission & {
|
|
49
|
-
allowPaths?: string[];
|
|
50
|
-
denyPaths?: string[];
|
|
51
|
-
};
|
|
52
|
-
read?: ToolPermission & {
|
|
53
|
-
denyPaths?: string[];
|
|
54
|
-
};
|
|
55
|
-
write?: ToolPermission & {
|
|
56
|
-
denyPaths?: string[];
|
|
57
|
-
};
|
|
58
|
-
edit?: ToolPermission & {
|
|
59
|
-
denyPaths?: string[];
|
|
60
|
-
};
|
|
61
|
-
grep?: ToolPermission & {
|
|
62
|
-
allowPaths?: string[];
|
|
63
|
-
};
|
|
64
|
-
glob?: ToolPermission;
|
|
65
|
-
web?: ToolPermission;
|
|
66
|
-
skill?: Record<string, ToolPermission>;
|
|
67
|
-
}
|
|
68
|
-
export interface OpencodeOptions {
|
|
69
|
-
pg: PostgresClient;
|
|
70
|
-
model?: string;
|
|
71
|
-
baseURL?: string;
|
|
72
|
-
apiKey?: string;
|
|
73
|
-
workspace?: string;
|
|
74
|
-
systemPrompt?: string;
|
|
75
|
-
skills?: SkillDef[];
|
|
76
|
-
permissions?: OpencodePermissions;
|
|
77
|
-
}
|
|
78
|
-
export interface OpencodeModule extends Router, Closeable {
|
|
79
|
-
migrate: () => Promise<void>;
|
|
80
|
-
wsHandler: () => any;
|
|
81
|
-
close: () => Promise<void>;
|
|
82
|
-
}
|
|
83
|
-
export interface WsClientInfo {
|
|
84
|
-
sessionId?: string;
|
|
85
|
-
abortController?: AbortController;
|
|
86
|
-
}
|
|
87
|
-
export interface PendingQuestion {
|
|
88
|
-
resolve: (answer: string) => void;
|
|
89
|
-
reject: (err: Error) => void;
|
|
90
|
-
}
|
package/dist/opencode/ws.d.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { WebSocket, SqlClient } from '../vendor.ts';
|
|
2
|
-
import type { LanguageModel } from 'ai';
|
|
3
|
-
import type { Context } from '../types.ts';
|
|
4
|
-
import type { PendingQuestion, SkillDef, SkillRegistry, OpencodePermissions } from './types.ts';
|
|
5
|
-
interface WsDeps {
|
|
6
|
-
sql: SqlClient;
|
|
7
|
-
model: LanguageModel;
|
|
8
|
-
workspace: string;
|
|
9
|
-
systemPrompt?: string;
|
|
10
|
-
skills: SkillDef[];
|
|
11
|
-
skillsRegistry: SkillRegistry;
|
|
12
|
-
permissions?: OpencodePermissions;
|
|
13
|
-
pendingQuestions: Map<string, PendingQuestion>;
|
|
14
|
-
}
|
|
15
|
-
export declare function createWSHandler(deps: WsDeps): {
|
|
16
|
-
open(ws: WebSocket, ctx: Context): void;
|
|
17
|
-
message(ws: WebSocket, ctx: Context, data: string | Buffer): Promise<void>;
|
|
18
|
-
close(ws: WebSocket): void;
|
|
19
|
-
error(ws: WebSocket, _ctx: Context, _err: Error): void;
|
|
20
|
-
};
|
|
21
|
-
export {};
|
package/dist/permissions.d.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import type { SqlClient } from './vendor.ts';
|
|
2
|
-
import type { Middleware, Context, Handler } from './types.ts';
|
|
3
|
-
declare module './types.ts' {
|
|
4
|
-
interface Context {
|
|
5
|
-
permissions: {
|
|
6
|
-
roles: Set<string>;
|
|
7
|
-
permissions: Set<string>;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export interface PermissionsOptions {
|
|
12
|
-
/** PostgreSQL client. */
|
|
13
|
-
pg: {
|
|
14
|
-
sql: SqlClient;
|
|
15
|
-
};
|
|
16
|
-
/** Table prefix (default: '' → _roles, _user_roles, _role_permissions). */
|
|
17
|
-
prefix?: string;
|
|
18
|
-
}
|
|
19
|
-
export interface PermissionsModule extends Middleware {
|
|
20
|
-
/**
|
|
21
|
-
* Middleware that injects `ctx.permissions = { roles, permissions }`.
|
|
22
|
-
* Reads `ctx.user.id` to look up role assignments.
|
|
23
|
-
* Must be placed after a middleware that sets `ctx.user`.
|
|
24
|
-
*/
|
|
25
|
-
(req: Request, ctx: Context, next: Handler): Response | Promise<Response>;
|
|
26
|
-
/** Assign a role to a user. Creates the role if it doesn't exist. */
|
|
27
|
-
assignRole(userId: number, role: string): Promise<void>;
|
|
28
|
-
/** Remove a role from a user. */
|
|
29
|
-
removeRole(userId: number, role: string): Promise<void>;
|
|
30
|
-
/** Grant a permission to a role. Creates the role if it doesn't exist. */
|
|
31
|
-
grantPermission(role: string, permission: string): Promise<void>;
|
|
32
|
-
/** Revoke a permission from a role. */
|
|
33
|
-
revokePermission(role: string, permission: string): Promise<void>;
|
|
34
|
-
/** Get all roles assigned to a user. */
|
|
35
|
-
getUserRoles(userId: number): Promise<string[]>;
|
|
36
|
-
/** Get all permissions for a user (union of all role permissions). */
|
|
37
|
-
getUserPermissions(userId: number): Promise<string[]>;
|
|
38
|
-
/**
|
|
39
|
-
* Middleware that rejects the request if the user does not have any of the specified roles.
|
|
40
|
-
* Must be placed after `permissions()` middleware (which injects ctx.permissions.roles).
|
|
41
|
-
*/
|
|
42
|
-
requireRole(...roles: string[]): Middleware<Context, Context>;
|
|
43
|
-
/**
|
|
44
|
-
* Middleware that rejects the request if the user does not have all specified permissions.
|
|
45
|
-
* Must be placed after `permissions()` middleware (which injects ctx.permissions.permissions).
|
|
46
|
-
*/
|
|
47
|
-
requirePermission(...permissions: string[]): Middleware<Context, Context>;
|
|
48
|
-
/** Create the underlying tables. Safe to call multiple times. */
|
|
49
|
-
migrate(): Promise<void>;
|
|
50
|
-
}
|
|
51
|
-
export declare function permissions(options: PermissionsOptions): PermissionsModule;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { PostgresOptions, PostgresClient } from './types.ts';
|
|
2
|
-
/** Migration tracking table name. Created automatically on first migrate(). */
|
|
3
|
-
export declare const MIGRATIONS_TABLE = "_weifuwu_migrations";
|
|
4
|
-
export declare function postgres(opts?: string | PostgresOptions): PostgresClient;
|
package/dist/postgres/index.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { PostgresClient } from './types.ts';
|
|
2
|
-
import type { SqlClient } from '../vendor.ts';
|
|
3
|
-
import type { ColumnBuilder, BoundTable, Table } from './schema/index.ts';
|
|
4
|
-
import type { Closeable } from '../types.ts';
|
|
5
|
-
export declare class PgModule implements Closeable {
|
|
6
|
-
protected sql: SqlClient;
|
|
7
|
-
protected pg: PostgresClient;
|
|
8
|
-
constructor(pg: PostgresClient);
|
|
9
|
-
table<R extends Record<string, unknown>>(tableOrSchema: string | Table<R>, builders?: {
|
|
10
|
-
[K in keyof R]: ColumnBuilder<R[K]>;
|
|
11
|
-
}): BoundTable<R>;
|
|
12
|
-
transaction<T>(fn: (sql: SqlClient) => Promise<T>, retryOpts?: {
|
|
13
|
-
maxRetries?: number;
|
|
14
|
-
}): Promise<T>;
|
|
15
|
-
migrate(): Promise<void>;
|
|
16
|
-
close(): Promise<void>;
|
|
17
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { SQL } from './sql.ts';
|
|
2
|
-
/** Reference to another table's column (foreign key). */
|
|
3
|
-
export interface ColumnReference {
|
|
4
|
-
/** Referenced table name. */
|
|
5
|
-
table: string;
|
|
6
|
-
/** Referenced column name (default: `'id'`). */
|
|
7
|
-
column: string;
|
|
8
|
-
/** `ON DELETE` action (e.g. `'cascade'`, `'set null'`). */
|
|
9
|
-
onDelete?: string;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Fluent column builder for DDL generation.
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* text('name').notNull().unique()
|
|
16
|
-
* integer('user_id').references('users')
|
|
17
|
-
* timestamptz('created_at').default(sql`NOW()`)
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export declare class ColumnBuilder<T> {
|
|
21
|
-
/** Column name. */
|
|
22
|
-
name: string;
|
|
23
|
-
/** SQL type string (e.g. `'TEXT'`, `'INTEGER'`). */
|
|
24
|
-
sqlType: string;
|
|
25
|
-
/** Whether this column is PRIMARY KEY. */
|
|
26
|
-
isPrimaryKey: boolean;
|
|
27
|
-
/** Whether this column allows NULL. */
|
|
28
|
-
isNullable: boolean;
|
|
29
|
-
/** Whether this column has a UNIQUE constraint. */
|
|
30
|
-
isUnique: boolean;
|
|
31
|
-
/** Whether the value is auto-generated (e.g. SERIAL, UUID defaults). */
|
|
32
|
-
isAutoGenerate: boolean;
|
|
33
|
-
/** DEFAULT expression as a raw SQL string. */
|
|
34
|
-
defaultExpr: string | null;
|
|
35
|
-
/** Foreign key reference, if any. */
|
|
36
|
-
ref: ColumnReference | null;
|
|
37
|
-
constructor(name: string, sqlType: string);
|
|
38
|
-
/** Mark as PRIMARY KEY (implies NOT NULL). */
|
|
39
|
-
primaryKey(): this;
|
|
40
|
-
/** Add NOT NULL constraint. */
|
|
41
|
-
notNull(): this;
|
|
42
|
-
/** Allow NULL values (default). */
|
|
43
|
-
nullable(): this;
|
|
44
|
-
/** Set a DEFAULT value. Accepts raw SQL, string, number, or boolean. */
|
|
45
|
-
default(expr: SQL | string | number | boolean): this;
|
|
46
|
-
/** Add UNIQUE constraint. */
|
|
47
|
-
unique(): this;
|
|
48
|
-
/** Add FOREIGN KEY reference to another table. */
|
|
49
|
-
references(table: string, column?: string, onDelete?: string): this;
|
|
50
|
-
}
|
|
51
|
-
/** Auto-incrementing integer primary key (`SERIAL`). */
|
|
52
|
-
export declare function serial(name: string): ColumnBuilder<number>;
|
|
53
|
-
/** UUID column. */
|
|
54
|
-
export declare function uuid(name: string): ColumnBuilder<string>;
|
|
55
|
-
/** TEXT column. */
|
|
56
|
-
export declare function text(name: string): ColumnBuilder<string>;
|
|
57
|
-
/** INTEGER column. */
|
|
58
|
-
export declare function integer(name: string): ColumnBuilder<number>;
|
|
59
|
-
/** BOOLEAN column (exported as `boolean`). */
|
|
60
|
-
export declare function boolean_(name: string): ColumnBuilder<boolean>;
|
|
61
|
-
export { boolean_ as boolean };
|
|
62
|
-
/** TIMESTAMPTZ column (timestamp with time zone). */
|
|
63
|
-
export declare function timestamptz(name: string): ColumnBuilder<string>;
|
|
64
|
-
/** JSONB column (stores arbitrary JSON data). */
|
|
65
|
-
export declare function jsonb<T = unknown>(name: string): ColumnBuilder<T>;
|
|
66
|
-
/** TEXT[] column (PostgreSQL array of text). */
|
|
67
|
-
export declare function textArray(name: string): ColumnBuilder<string[]>;
|
|
68
|
-
/** Vector column for pgvector (embedding storage). Requires `dimensions`. */
|
|
69
|
-
export declare function vector(name: string, dims: number): ColumnBuilder<number[]>;
|
|
70
|
-
export interface PartitionByDef {
|
|
71
|
-
type: 'RANGE' | 'LIST' | 'HASH';
|
|
72
|
-
column: string;
|
|
73
|
-
}
|
|
74
|
-
export declare function partitionBy(type: 'range' | 'list' | 'hash', column: string): PartitionByDef;
|
|
75
|
-
/**
|
|
76
|
-
* Create a pair of `created_at` / `updated_at` timestamp columns
|
|
77
|
-
* that default to `NOW()` and are NOT NULL.
|
|
78
|
-
*
|
|
79
|
-
* ```ts
|
|
80
|
-
* pgTable('users', {
|
|
81
|
-
* id: serial('id').primaryKey(),
|
|
82
|
-
* name: text('name'),
|
|
83
|
-
* ...timestamps(),
|
|
84
|
-
* })
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
87
|
-
export declare function timestamps(): {
|
|
88
|
-
readonly created_at: ColumnBuilder<string>;
|
|
89
|
-
readonly updated_at: ColumnBuilder<string>;
|
|
90
|
-
};
|
|
91
|
-
/**
|
|
92
|
-
* Convert a ColumnBuilder into a DDL column definition string.
|
|
93
|
-
*
|
|
94
|
-
* ```ts
|
|
95
|
-
* toDDL(text('name').notNull())
|
|
96
|
-
* // '"name" TEXT NOT NULL'
|
|
97
|
-
* ```
|
|
98
|
-
*/
|
|
99
|
-
export declare function toDDL(col: ColumnBuilder<unknown>): string;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { sql, SQL } from './sql.ts';
|
|
2
|
-
export { ColumnBuilder, serial, uuid, text, integer, boolean as boolean, boolean_, timestamptz, jsonb, textArray, vector, toDDL, partitionBy, timestamps, } from './columns.ts';
|
|
3
|
-
export type { PartitionByDef } from './columns.ts';
|
|
4
|
-
export { pgTable, Table, BoundTable } from './table.ts';
|
|
5
|
-
export type { IndexOptions, FindOptions, CreateOptions } from './table.ts';
|
|
6
|
-
export { eq, ne, gt, gte, lt, lte, isNull, isNotNull, like, contains, in_, and, or, not, } from './where.ts';
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A parameterized SQL fragment with template strings and bound values.
|
|
3
|
-
* Used internally by the schema builder and where helpers.
|
|
4
|
-
*/
|
|
5
|
-
export declare class SQL {
|
|
6
|
-
/** Template string parts (interleaved with values). */
|
|
7
|
-
strings: TemplateStringsArray;
|
|
8
|
-
/** Bound parameter values. */
|
|
9
|
-
values: unknown[];
|
|
10
|
-
constructor(strings: TemplateStringsArray, values: unknown[]);
|
|
11
|
-
/** Serialize to a raw SQL string (interpolating values inline for DDL use). */
|
|
12
|
-
toSQL(): string;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Tagged template helper for creating parameterized SQL fragments.
|
|
16
|
-
*
|
|
17
|
-
* ```ts
|
|
18
|
-
* sql`NOW()`
|
|
19
|
-
* sql`${column} ILIKE ${'%' + search + '%'}`
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export declare function sql(strings: TemplateStringsArray, ...values: unknown[]): SQL;
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import type { SqlClient } from '../../vendor.ts';
|
|
2
|
-
import { ColumnBuilder, type PartitionByDef } from './columns.ts';
|
|
3
|
-
import { SQL } from './sql.ts';
|
|
4
|
-
/** Options for table index creation. */
|
|
5
|
-
export interface IndexOptions {
|
|
6
|
-
/** Whether the index should be UNIQUE. */
|
|
7
|
-
unique?: boolean;
|
|
8
|
-
/** Index type: btree (default), hnsw (pgvector), gin (JSONB). */
|
|
9
|
-
type?: 'btree' | 'hnsw' | 'gin';
|
|
10
|
-
/** Create index in DESC order. */
|
|
11
|
-
desc?: boolean;
|
|
12
|
-
/** Custom operator class (e.g. `vector_cosine_ops`). */
|
|
13
|
-
operator?: string;
|
|
14
|
-
}
|
|
15
|
-
/** Options for CREATE TABLE. */
|
|
16
|
-
export interface CreateOptions {
|
|
17
|
-
/** Partition by clause (RANGE, LIST, or HASH). */
|
|
18
|
-
partitionBy?: PartitionByDef;
|
|
19
|
-
}
|
|
20
|
-
/** Options for find/read queries. */
|
|
21
|
-
export interface FindOptions {
|
|
22
|
-
/** ORDER BY clause: `{ column: 'asc' | 'desc' }`. */
|
|
23
|
-
orderBy?: Record<string, 'asc' | 'desc'>;
|
|
24
|
-
/** LIMIT. */
|
|
25
|
-
limit?: number;
|
|
26
|
-
/** OFFSET. */
|
|
27
|
-
offset?: number;
|
|
28
|
-
/** Columns to SELECT (default: all). */
|
|
29
|
-
select?: string[];
|
|
30
|
-
/** Include soft-deleted rows (also sets `withDeleted` context). */
|
|
31
|
-
withDeleted?: boolean;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Type-safe table schema + CRUD operations.
|
|
35
|
-
*
|
|
36
|
-
* Create an instance with {@link pgTable}, then call `.bind(sql)` to get a
|
|
37
|
-
* `BoundTable` for running queries.
|
|
38
|
-
*
|
|
39
|
-
* ```ts
|
|
40
|
-
* const users = pgTable('users', {
|
|
41
|
-
* id: serial('id').primaryKey(),
|
|
42
|
-
* name: text('name').notNull(),
|
|
43
|
-
* email: text('email').unique(),
|
|
44
|
-
* })
|
|
45
|
-
*
|
|
46
|
-
* const db = users.bind(sql)
|
|
47
|
-
* await db.create()
|
|
48
|
-
* await db.insert({ name: 'Alice', email: 'a@b.com' })
|
|
49
|
-
* const row = await db.findBy({ email: 'a@b.com' })
|
|
50
|
-
* ```
|
|
51
|
-
*/
|
|
52
|
-
export declare class Table<R extends Record<string, unknown>> {
|
|
53
|
-
/** Database table name. */
|
|
54
|
-
readonly tableName: string;
|
|
55
|
-
/** All column builders (order-preserving). */
|
|
56
|
-
readonly columns: ColumnBuilder<unknown>[];
|
|
57
|
-
/** Column builders keyed by property name. */
|
|
58
|
-
readonly builders: Record<string, ColumnBuilder<unknown>>;
|
|
59
|
-
private colEntries;
|
|
60
|
-
constructor(tableName: string, builders: Record<string, ColumnBuilder<unknown>>);
|
|
61
|
-
/** Check if the table has a column with the given DB name. */
|
|
62
|
-
hasColumn(dbName: string): boolean;
|
|
63
|
-
/**
|
|
64
|
-
* Bind this table schema to a SQL connection, returning a `BoundTable`
|
|
65
|
-
* that can run queries without passing `sql` to every call.
|
|
66
|
-
*/
|
|
67
|
-
bind(sql: SqlClient): BoundTable<R>;
|
|
68
|
-
/** Returns the primary key column name (DB name), or 'id' as fallback. */
|
|
69
|
-
private get pkColumn();
|
|
70
|
-
/** Adds `deleted_at IS NULL` condition if the table has soft delete and not explicitly excluded. */
|
|
71
|
-
private _softDeleteFilter;
|
|
72
|
-
create(sql: SqlClient, opts?: CreateOptions): Promise<void>;
|
|
73
|
-
drop(sql: SqlClient, opts?: {
|
|
74
|
-
cascade?: boolean;
|
|
75
|
-
}): Promise<void>;
|
|
76
|
-
createIndex(sql: SqlClient, columns: string | string[], opts?: IndexOptions): Promise<void>;
|
|
77
|
-
createUniqueIndex(sql: SqlClient, columns: string | string[]): Promise<void>;
|
|
78
|
-
private _buildConditions;
|
|
79
|
-
private _buildSET;
|
|
80
|
-
insert(sql: SqlClient, data: Partial<R>): Promise<R>;
|
|
81
|
-
insertMany(sql: SqlClient, data: Partial<R>[]): Promise<R[]>;
|
|
82
|
-
read(sql: SqlClient, id: string | number, opts?: Pick<FindOptions, 'select' | 'withDeleted'>): Promise<R | undefined>;
|
|
83
|
-
readMany(sql: SqlClient, where?: Partial<R> | SQL | SQL[], opts?: FindOptions): Promise<{
|
|
84
|
-
count: number;
|
|
85
|
-
data: R[];
|
|
86
|
-
}>;
|
|
87
|
-
update(sql: SqlClient, id: string | number, data: Partial<R>): Promise<R | undefined>;
|
|
88
|
-
updateMany(sql: SqlClient, where: Partial<R> | SQL | SQL[], data: Partial<R>): Promise<number>;
|
|
89
|
-
delete(sql: SqlClient, id: string | number): Promise<R | undefined>;
|
|
90
|
-
hardDelete(sql: SqlClient, id: string | number): Promise<R | undefined>;
|
|
91
|
-
deleteMany(sql: SqlClient, where: Partial<R> | SQL | SQL[]): Promise<number>;
|
|
92
|
-
hardDeleteMany(sql: SqlClient, where: Partial<R> | SQL | SQL[]): Promise<number>;
|
|
93
|
-
upsert(sql: SqlClient, data: Partial<R>, conflict: string | string[]): Promise<R>;
|
|
94
|
-
count(sql: SqlClient, where?: Partial<R> | SQL | SQL[]): Promise<number>;
|
|
95
|
-
}
|
|
96
|
-
export declare class BoundTable<R extends Record<string, unknown>> {
|
|
97
|
-
private inner;
|
|
98
|
-
private sql;
|
|
99
|
-
/** The underlying table name. */
|
|
100
|
-
get tableName(): string;
|
|
101
|
-
constructor(sql: SqlClient, tableName: string, builders: Record<string, ColumnBuilder<unknown>>);
|
|
102
|
-
create(opts?: CreateOptions): Promise<void>;
|
|
103
|
-
drop(opts?: {
|
|
104
|
-
cascade?: boolean;
|
|
105
|
-
}): Promise<void>;
|
|
106
|
-
createIndex(columns: string | string[], opts?: IndexOptions): Promise<void>;
|
|
107
|
-
createUniqueIndex(columns: string | string[]): Promise<void>;
|
|
108
|
-
insert(data: Partial<R>): Promise<R>;
|
|
109
|
-
insertMany(data: Partial<R>[]): Promise<R[]>;
|
|
110
|
-
read(id: string | number, opts?: Pick<FindOptions, 'select' | 'withDeleted'>): Promise<R | undefined>;
|
|
111
|
-
readMany(where?: Partial<R> | SQL | SQL[], opts?: FindOptions): Promise<{
|
|
112
|
-
count: number;
|
|
113
|
-
data: R[];
|
|
114
|
-
}>;
|
|
115
|
-
update(id: string | number, data: Partial<R>): Promise<R | undefined>;
|
|
116
|
-
updateMany(where: Partial<R> | SQL | SQL[], data: Partial<R>): Promise<number>;
|
|
117
|
-
delete(id: string | number): Promise<R | undefined>;
|
|
118
|
-
hardDelete(id: string | number): Promise<R | undefined>;
|
|
119
|
-
deleteMany(where: Partial<R> | SQL | SQL[]): Promise<number>;
|
|
120
|
-
hardDeleteMany(where: Partial<R> | SQL | SQL[]): Promise<number>;
|
|
121
|
-
upsert(data: Partial<R>, conflict: string | string[]): Promise<R>;
|
|
122
|
-
count(where?: Partial<R> | SQL | SQL[]): Promise<number>;
|
|
123
|
-
withSql(sql: SqlClient): BoundTable<R>;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Define a type-safe table schema.
|
|
127
|
-
*
|
|
128
|
-
* ```ts
|
|
129
|
-
* const users = pgTable('users', {
|
|
130
|
-
* id: serial('id').primaryKey(),
|
|
131
|
-
* name: text('name').notNull(),
|
|
132
|
-
* email: text('email').unique(),
|
|
133
|
-
* })
|
|
134
|
-
*
|
|
135
|
-
* // The generic type R preserves the column types:
|
|
136
|
-
* // Table<{ id: number; name: string; email: string }>
|
|
137
|
-
* ```
|
|
138
|
-
*/
|
|
139
|
-
export declare function pgTable<R extends Record<string, unknown>>(tableName: string, builders: {
|
|
140
|
-
[K in keyof R]: ColumnBuilder<R[K]>;
|
|
141
|
-
}): Table<R>;
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { SQL } from './sql.ts';
|
|
2
|
-
/** Column equals value: `col = val`. */
|
|
3
|
-
export declare function eq(col: string, val: unknown): SQL;
|
|
4
|
-
/** Column not equals value: `col != val`. */
|
|
5
|
-
export declare function ne(col: string, val: unknown): SQL;
|
|
6
|
-
/** Column greater than value: `col > val`. */
|
|
7
|
-
export declare function gt(col: string, val: unknown): SQL;
|
|
8
|
-
/** Column greater than or equal value: `col >= val`. */
|
|
9
|
-
export declare function gte(col: string, val: unknown): SQL;
|
|
10
|
-
/** Column less than value: `col < val`. */
|
|
11
|
-
export declare function lt(col: string, val: unknown): SQL;
|
|
12
|
-
/** Column less than or equal value: `col <= val`. */
|
|
13
|
-
export declare function lte(col: string, val: unknown): SQL;
|
|
14
|
-
/** Column IS NULL. */
|
|
15
|
-
export declare function isNull(col: string): SQL;
|
|
16
|
-
/** Column IS NOT NULL. */
|
|
17
|
-
export declare function isNotNull(col: string): SQL;
|
|
18
|
-
/** Column LIKE pattern. */
|
|
19
|
-
export declare function like(col: string, pattern: string): SQL;
|
|
20
|
-
/** Negate a condition: `NOT (condition)`. */
|
|
21
|
-
export declare function not(condition: SQL): SQL;
|
|
22
|
-
/** JSONB containment: `col @> val` (does `col` contain `val`?). */
|
|
23
|
-
export declare function contains(col: string, val: Record<string, unknown>): SQL;
|
|
24
|
-
/** Column value is in array: `col = ANY(val)`. */
|
|
25
|
-
export declare function in_(col: string, val: unknown[]): SQL;
|
|
26
|
-
/** Combine conditions with AND. */
|
|
27
|
-
export declare function and(...conditions: SQL[]): SQL;
|
|
28
|
-
/** Combine conditions with OR. */
|
|
29
|
-
export declare function or(...conditions: SQL[]): SQL;
|
package/dist/postgres/types.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import type { SqlClient } from '../vendor.ts';
|
|
2
|
-
import type { Context, Middleware, Closeable } from '../types.ts';
|
|
3
|
-
import type { ColumnBuilder, BoundTable, Table } from './schema/index.ts';
|
|
4
|
-
declare module '../types.ts' {
|
|
5
|
-
interface Context {
|
|
6
|
-
sql: SqlClient;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
export interface PostgresInjected {
|
|
10
|
-
sql: SqlClient;
|
|
11
|
-
}
|
|
12
|
-
export interface PostgresOptions {
|
|
13
|
-
connection?: string | Record<string, unknown>;
|
|
14
|
-
signal?: AbortSignal;
|
|
15
|
-
closeTimeout?: number;
|
|
16
|
-
max?: number;
|
|
17
|
-
ssl?: boolean | Record<string, unknown>;
|
|
18
|
-
idle_timeout?: number;
|
|
19
|
-
connect_timeout?: number;
|
|
20
|
-
/** Per-statement timeout in ms. Set to 0 to disable. Default: 30_000. */
|
|
21
|
-
statementTimeout?: number;
|
|
22
|
-
/** Called after every query completes. Receives query text, duration in ms, and row count. */
|
|
23
|
-
onQuery?: (query: string, durationMs: number, rowCount: number) => void;
|
|
24
|
-
}
|
|
25
|
-
export interface PostgresClient extends Middleware<Context, Context & PostgresInjected>, Closeable {
|
|
26
|
-
sql: SqlClient;
|
|
27
|
-
/** Creates the migration tracking table (_weifuwu_migrations). Called once at startup. */
|
|
28
|
-
migrate: () => Promise<void>;
|
|
29
|
-
/** Record that a module's migration has been applied (idempotent). */
|
|
30
|
-
markMigrated: (moduleName: string) => Promise<void>;
|
|
31
|
-
/** Check whether a module has already been migrated. */
|
|
32
|
-
isMigrated: (moduleName: string) => Promise<boolean>;
|
|
33
|
-
table: {
|
|
34
|
-
<R extends Record<string, unknown>>(tableName: string, builders: {
|
|
35
|
-
[K in keyof R]: ColumnBuilder<R[K]>;
|
|
36
|
-
}): BoundTable<R>;
|
|
37
|
-
<R extends Record<string, unknown>>(schema: Table<R>): BoundTable<R>;
|
|
38
|
-
};
|
|
39
|
-
transaction: <T>(fn: (sql: any) => Promise<T>, retryOpts?: {
|
|
40
|
-
maxRetries?: number;
|
|
41
|
-
}) => Promise<T>;
|
|
42
|
-
/** Snapshot of connection pool state: active, idle, waiting, max connections. */
|
|
43
|
-
poolStats: () => {
|
|
44
|
-
active: number;
|
|
45
|
-
idle: number;
|
|
46
|
-
waiting: number;
|
|
47
|
-
max: number;
|
|
48
|
-
};
|
|
49
|
-
close: () => Promise<void>;
|
|
50
|
-
}
|
package/dist/queue/index.d.ts
DELETED