feat: enhance router views functionality and permissions
- Added new router views schema and types for better structure and type safety. - Implemented CRUD operations for router views including listing, updating, retrieving, and deleting views. - Introduced permission checks to ensure users can only access and modify their own views. - Updated prompts route to include additional permission checks for updating and retrieving prompts. - Refactored common query tests to align with new configurations. - Organized route imports for better maintainability.
This commit is contained in:
@@ -1,396 +1,396 @@
|
||||
import { pgTable, serial, text, jsonb, varchar, timestamp, unique, uuid, doublePrecision, json, integer, boolean, index, uniqueIndex, pgEnum } from "drizzle-orm/pg-core"
|
||||
import { sql } from "drizzle-orm"
|
||||
import { sql, sum } from "drizzle-orm"
|
||||
|
||||
export const enumCfRouterCodeType = pgEnum("enum_cf_router_code_type", ['route', 'middleware'])
|
||||
|
||||
|
||||
export const testPromptTools = pgTable("TestPromptTools", {
|
||||
id: serial().primaryKey().notNull(),
|
||||
template: text().notNull(),
|
||||
args: jsonb().notNull(),
|
||||
process: jsonb().notNull(),
|
||||
type: varchar({ length: 255 }).notNull(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
id: serial().primaryKey().notNull(),
|
||||
template: text().notNull(),
|
||||
args: jsonb().notNull(),
|
||||
process: jsonb().notNull(),
|
||||
type: varchar({ length: 255 }).notNull(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
});
|
||||
|
||||
export const aiAgent = pgTable("ai_agent", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
type: varchar({ length: 255 }).notNull(),
|
||||
baseUrl: varchar({ length: 255 }).notNull(),
|
||||
apiKey: varchar({ length: 255 }).notNull(),
|
||||
temperature: doublePrecision(),
|
||||
cache: varchar({ length: 255 }),
|
||||
cacheName: varchar({ length: 255 }),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
model: varchar({ length: 255 }).notNull(),
|
||||
data: json().default({}),
|
||||
status: varchar({ length: 255 }).default('open'),
|
||||
key: varchar({ length: 255 }).notNull(),
|
||||
description: text(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
type: varchar({ length: 255 }).notNull(),
|
||||
baseUrl: varchar({ length: 255 }).notNull(),
|
||||
apiKey: varchar({ length: 255 }).notNull(),
|
||||
temperature: doublePrecision(),
|
||||
cache: varchar({ length: 255 }),
|
||||
cacheName: varchar({ length: 255 }),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
model: varchar({ length: 255 }).notNull(),
|
||||
data: json().default({}),
|
||||
status: varchar({ length: 255 }).default('open'),
|
||||
key: varchar({ length: 255 }).notNull(),
|
||||
description: text(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
}, (table) => [
|
||||
unique("ai_agent_key_key").on(table.key),
|
||||
unique("ai_agent_key_key").on(table.key),
|
||||
]);
|
||||
|
||||
export const appsTrades = pgTable("apps_trades", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
outTradeNo: varchar("out_trade_no", { length: 255 }).notNull(),
|
||||
money: integer().notNull(),
|
||||
subject: text().notNull(),
|
||||
status: varchar({ length: 255 }).default('WAIT_BUYER_PAY').notNull(),
|
||||
type: varchar({ length: 255 }).default('alipay').notNull(),
|
||||
data: jsonb().default({"list":[]}),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
outTradeNo: varchar("out_trade_no", { length: 255 }).notNull(),
|
||||
money: integer().notNull(),
|
||||
subject: text().notNull(),
|
||||
status: varchar({ length: 255 }).default('WAIT_BUYER_PAY').notNull(),
|
||||
type: varchar({ length: 255 }).default('alipay').notNull(),
|
||||
data: jsonb().default({ "list": [] }),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
}, (table) => [
|
||||
unique("apps_trades_out_trade_no_key").on(table.outTradeNo),
|
||||
unique("apps_trades_out_trade_no_key").on(table.outTradeNo),
|
||||
]);
|
||||
|
||||
export const cfOrgs = pgTable("cf_orgs", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
username: varchar({ length: 255 }).notNull(),
|
||||
users: jsonb().default([]),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
description: varchar({ length: 255 }),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
username: varchar({ length: 255 }).notNull(),
|
||||
users: jsonb().default([]),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
description: varchar({ length: 255 }),
|
||||
}, (table) => [
|
||||
unique("cf_orgs_username_key").on(table.username),
|
||||
unique("cf_orgs_username_key").on(table.username),
|
||||
]);
|
||||
|
||||
export const cfRouterCode = pgTable("cf_router_code", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
path: varchar({ length: 255 }).notNull(),
|
||||
key: varchar({ length: 255 }).notNull(),
|
||||
active: boolean().default(false),
|
||||
project: varchar({ length: 255 }).default('default'),
|
||||
code: text().default(''),
|
||||
type: enumCfRouterCodeType().default('route'),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
middleware: varchar({ length: 255 }).array().default(["RRAY[]::character varying[])::character varying(25"]),
|
||||
next: varchar({ length: 255 }).default(''),
|
||||
exec: text().default(''),
|
||||
data: json().default({}),
|
||||
validator: json().default({}),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
path: varchar({ length: 255 }).notNull(),
|
||||
key: varchar({ length: 255 }).notNull(),
|
||||
active: boolean().default(false),
|
||||
project: varchar({ length: 255 }).default('default'),
|
||||
code: text().default(''),
|
||||
type: enumCfRouterCodeType().default('route'),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
middleware: varchar({ length: 255 }).array().default(["RRAY[]::character varying[])::character varying(25"]),
|
||||
next: varchar({ length: 255 }).default(''),
|
||||
exec: text().default(''),
|
||||
data: json().default({}),
|
||||
validator: json().default({}),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
});
|
||||
|
||||
export const cfUser = pgTable("cf_user", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
username: varchar({ length: 255 }).notNull(),
|
||||
password: varchar({ length: 255 }),
|
||||
salt: varchar({ length: 255 }),
|
||||
needChangePassword: boolean().default(false),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
description: text(),
|
||||
data: jsonb().default({}),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
type: varchar({ length: 255 }).default('user'),
|
||||
owner: uuid(),
|
||||
orgId: uuid(),
|
||||
email: varchar({ length: 255 }),
|
||||
avatar: text(),
|
||||
nickname: text(),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
username: varchar({ length: 255 }).notNull(),
|
||||
password: varchar({ length: 255 }),
|
||||
salt: varchar({ length: 255 }),
|
||||
needChangePassword: boolean().default(false),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
description: text(),
|
||||
data: jsonb().default({}),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
type: varchar({ length: 255 }).default('user'),
|
||||
owner: uuid(),
|
||||
orgId: uuid(),
|
||||
email: varchar({ length: 255 }),
|
||||
avatar: text(),
|
||||
nickname: text(),
|
||||
}, (table) => [
|
||||
unique("cf_user_username_key").on(table.username),
|
||||
unique("cf_user_username_key").on(table.username),
|
||||
]);
|
||||
|
||||
export const cfUserSecrets = pgTable("cf_user_secrets", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
description: text(),
|
||||
status: varchar({ length: 255 }).default('active'),
|
||||
title: text(),
|
||||
expiredTime: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
token: varchar({ length: 255 }).default('').notNull(),
|
||||
userId: uuid(),
|
||||
data: jsonb().default({}),
|
||||
orgId: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
description: text(),
|
||||
status: varchar({ length: 255 }).default('active'),
|
||||
title: text(),
|
||||
expiredTime: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
token: varchar({ length: 255 }).default('').notNull(),
|
||||
userId: uuid(),
|
||||
data: jsonb().default({}),
|
||||
orgId: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
});
|
||||
|
||||
export const chatHistories = pgTable("chat_histories", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
data: json(),
|
||||
chatId: uuid(),
|
||||
chatPromptId: uuid(),
|
||||
root: boolean().default(false),
|
||||
show: boolean().default(true),
|
||||
uid: varchar({ length: 255 }),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
role: varchar({ length: 255 }).default('user'),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
data: json(),
|
||||
chatId: uuid(),
|
||||
chatPromptId: uuid(),
|
||||
root: boolean().default(false),
|
||||
show: boolean().default(true),
|
||||
uid: varchar({ length: 255 }),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
role: varchar({ length: 255 }).default('user'),
|
||||
});
|
||||
|
||||
export const chatPrompts = pgTable("chat_prompts", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
title: varchar({ length: 255 }).notNull(),
|
||||
description: text(),
|
||||
data: json(),
|
||||
key: varchar({ length: 255 }).default('').notNull(),
|
||||
uid: varchar({ length: 255 }),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
title: varchar({ length: 255 }).notNull(),
|
||||
description: text(),
|
||||
data: json(),
|
||||
key: varchar({ length: 255 }).default('').notNull(),
|
||||
uid: varchar({ length: 255 }),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
});
|
||||
|
||||
export const chatSessions = pgTable("chat_sessions", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
data: json().default({}),
|
||||
chatPromptId: uuid(),
|
||||
type: varchar({ length: 255 }).default('production'),
|
||||
uid: varchar({ length: 255 }),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
title: varchar({ length: 255 }).default(''),
|
||||
key: varchar({ length: 255 }),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
data: json().default({}),
|
||||
chatPromptId: uuid(),
|
||||
type: varchar({ length: 255 }).default('production'),
|
||||
uid: varchar({ length: 255 }),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
title: varchar({ length: 255 }).default(''),
|
||||
key: varchar({ length: 255 }),
|
||||
});
|
||||
|
||||
export const fileSync = pgTable("file_sync", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
name: varchar({ length: 255 }),
|
||||
hash: varchar({ length: 255 }),
|
||||
stat: jsonb().default({}),
|
||||
data: jsonb().default({}),
|
||||
checkedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
name: varchar({ length: 255 }),
|
||||
hash: varchar({ length: 255 }),
|
||||
stat: jsonb().default({}),
|
||||
data: jsonb().default({}),
|
||||
checkedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
}, (table) => [
|
||||
index("file_sync_name_idx").using("btree", table.name.asc().nullsLast().op("text_ops")),
|
||||
index("file_sync_name_idx").using("btree", table.name.asc().nullsLast()),
|
||||
]);
|
||||
|
||||
export const kvAiChatHistory = pgTable("kv_ai_chat_history", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
username: varchar({ length: 255 }).default('').notNull(),
|
||||
model: varchar({ length: 255 }).default('').notNull(),
|
||||
group: varchar({ length: 255 }).default('').notNull(),
|
||||
title: varchar({ length: 255 }).default('').notNull(),
|
||||
messages: jsonb().default([]).notNull(),
|
||||
promptTokens: integer("prompt_tokens").default(0),
|
||||
totalTokens: integer("total_tokens").default(0),
|
||||
completionTokens: integer("completion_tokens").default(0),
|
||||
data: jsonb().default({}),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
version: integer().default(0),
|
||||
type: varchar({ length: 255 }).default('keep').notNull(),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
username: varchar({ length: 255 }).default('').notNull(),
|
||||
model: varchar({ length: 255 }).default('').notNull(),
|
||||
group: varchar({ length: 255 }).default('').notNull(),
|
||||
title: varchar({ length: 255 }).default('').notNull(),
|
||||
messages: jsonb().default([]).notNull(),
|
||||
promptTokens: integer("prompt_tokens").default(0),
|
||||
totalTokens: integer("total_tokens").default(0),
|
||||
completionTokens: integer("completion_tokens").default(0),
|
||||
data: jsonb().default({}),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
version: integer().default(0),
|
||||
type: varchar({ length: 255 }).default('keep').notNull(),
|
||||
});
|
||||
|
||||
export const kvApp = pgTable("kv_app", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
data: jsonb().default({}),
|
||||
version: varchar({ length: 255 }).default(''),
|
||||
key: varchar({ length: 255 }),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
title: varchar({ length: 255 }).default(''),
|
||||
description: varchar({ length: 255 }).default(''),
|
||||
user: varchar({ length: 255 }),
|
||||
status: varchar({ length: 255 }).default('running'),
|
||||
pid: uuid(),
|
||||
proxy: boolean().default(false),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
data: jsonb().default({}),
|
||||
version: varchar({ length: 255 }).default(''),
|
||||
key: varchar({ length: 255 }),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
title: varchar({ length: 255 }).default(''),
|
||||
description: varchar({ length: 255 }).default(''),
|
||||
user: varchar({ length: 255 }),
|
||||
status: varchar({ length: 255 }).default('running'),
|
||||
pid: uuid(),
|
||||
proxy: boolean().default(false),
|
||||
}, (table) => [
|
||||
uniqueIndex("kv_app_key_uid").using("btree", table.key.asc().nullsLast().op("text_ops"), table.uid.asc().nullsLast().op("text_ops")),
|
||||
unique("key_uid_unique").on(table.key, table.uid),
|
||||
uniqueIndex("kv_app_key_uid").using("btree", table.key.asc().nullsLast(), table.uid.asc().nullsLast()),
|
||||
unique("key_uid_unique").on(table.key, table.uid),
|
||||
]);
|
||||
|
||||
export const kvAppDomain = pgTable("kv_app_domain", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
domain: varchar({ length: 255 }).notNull(),
|
||||
appId: varchar({ length: 255 }),
|
||||
uid: varchar({ length: 255 }),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
data: jsonb(),
|
||||
status: varchar({ length: 255 }).default('running').notNull(),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
domain: varchar({ length: 255 }).notNull(),
|
||||
appId: varchar({ length: 255 }),
|
||||
uid: varchar({ length: 255 }),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
data: jsonb(),
|
||||
status: varchar({ length: 255 }).default('running').notNull(),
|
||||
}, (table) => [
|
||||
unique("kv_app_domain_domain_key").on(table.domain),
|
||||
unique("kv_app_domain_domain_key").on(table.domain),
|
||||
]);
|
||||
|
||||
export const kvAppList = pgTable("kv_app_list", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
data: json().default({}),
|
||||
version: varchar({ length: 255 }).default(''),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
key: varchar({ length: 255 }),
|
||||
status: varchar({ length: 255 }).default('running'),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
data: json().default({}),
|
||||
version: varchar({ length: 255 }).default(''),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
key: varchar({ length: 255 }),
|
||||
status: varchar({ length: 255 }).default('running'),
|
||||
});
|
||||
|
||||
export const kvConfig = pgTable("kv_config", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
title: text().default(''),
|
||||
key: text().default(''),
|
||||
description: text().default(''),
|
||||
tags: jsonb().default([]),
|
||||
data: jsonb().default({}),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
hash: text().default(''),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
title: text().default(''),
|
||||
key: text().default(''),
|
||||
description: text().default(''),
|
||||
tags: jsonb().default([]),
|
||||
data: jsonb().default({}),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
hash: text().default(''),
|
||||
});
|
||||
|
||||
export const kvContainer = pgTable("kv_container", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
title: text().default(''),
|
||||
description: text().default(''),
|
||||
type: varchar({ length: 255 }).default('render-js'),
|
||||
code: text().default(''),
|
||||
data: json().default({}),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
uid: uuid(),
|
||||
publish: json().default({}),
|
||||
tags: json().default([]),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
hash: text().default(''),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
title: text().default(''),
|
||||
description: text().default(''),
|
||||
type: varchar({ length: 255 }).default('render-js'),
|
||||
code: text().default(''),
|
||||
data: json().default({}),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
uid: uuid(),
|
||||
publish: json().default({}),
|
||||
tags: json().default([]),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
hash: text().default(''),
|
||||
});
|
||||
|
||||
export const kvGithub = pgTable("kv_github", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
title: varchar({ length: 255 }).default(''),
|
||||
githubToken: varchar({ length: 255 }).default(''),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
title: varchar({ length: 255 }).default(''),
|
||||
githubToken: varchar({ length: 255 }).default(''),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
});
|
||||
|
||||
export const kvPackages = pgTable("kv_packages", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
title: text().default(''),
|
||||
description: text().default(''),
|
||||
tags: jsonb().default([]),
|
||||
data: jsonb().default({}),
|
||||
publish: jsonb().default({}),
|
||||
expand: jsonb().default({}),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
title: text().default(''),
|
||||
description: text().default(''),
|
||||
tags: jsonb().default([]),
|
||||
data: jsonb().default({}),
|
||||
publish: jsonb().default({}),
|
||||
expand: jsonb().default({}),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
});
|
||||
|
||||
export const kvPage = pgTable("kv_page", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
title: varchar({ length: 255 }).default(''),
|
||||
description: text().default(''),
|
||||
type: varchar({ length: 255 }).default(''),
|
||||
data: json().default({}),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
publish: json().default({}),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
title: varchar({ length: 255 }).default(''),
|
||||
description: text().default(''),
|
||||
type: varchar({ length: 255 }).default(''),
|
||||
data: json().default({}),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
publish: json().default({}),
|
||||
});
|
||||
|
||||
export const kvResource = pgTable("kv_resource", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
name: varchar({ length: 255 }).default(''),
|
||||
description: text().default(''),
|
||||
source: varchar({ length: 255 }).default(''),
|
||||
sourceId: varchar({ length: 255 }).default(''),
|
||||
version: varchar({ length: 255 }).default('0.0.0'),
|
||||
data: json().default({}),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
name: varchar({ length: 255 }).default(''),
|
||||
description: text().default(''),
|
||||
source: varchar({ length: 255 }).default(''),
|
||||
sourceId: varchar({ length: 255 }).default(''),
|
||||
version: varchar({ length: 255 }).default('0.0.0'),
|
||||
data: json().default({}),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
});
|
||||
|
||||
export const kvVip = pgTable("kv_vip", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
userId: uuid().notNull(),
|
||||
level: varchar({ length: 255 }).default('free'),
|
||||
category: varchar({ length: 255 }).notNull(),
|
||||
startDate: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
endDate: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
data: jsonb().default({}),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
title: text().default('').notNull(),
|
||||
description: text().default('').notNull(),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
userId: uuid().notNull(),
|
||||
level: varchar({ length: 255 }).default('free'),
|
||||
category: varchar({ length: 255 }).notNull(),
|
||||
startDate: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
endDate: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
data: jsonb().default({}),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
title: text().default('').notNull(),
|
||||
description: text().default('').notNull(),
|
||||
});
|
||||
|
||||
export const microAppsUpload = pgTable("micro_apps_upload", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
title: varchar({ length: 255 }).default(''),
|
||||
description: varchar({ length: 255 }).default(''),
|
||||
tags: jsonb().default([]),
|
||||
type: varchar({ length: 255 }).default(''),
|
||||
source: varchar({ length: 255 }).default(''),
|
||||
data: jsonb().default({}),
|
||||
share: boolean().default(false),
|
||||
uname: varchar({ length: 255 }).default(''),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
title: varchar({ length: 255 }).default(''),
|
||||
description: varchar({ length: 255 }).default(''),
|
||||
tags: jsonb().default([]),
|
||||
type: varchar({ length: 255 }).default(''),
|
||||
source: varchar({ length: 255 }).default(''),
|
||||
data: jsonb().default({}),
|
||||
share: boolean().default(false),
|
||||
uname: varchar({ length: 255 }).default(''),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
});
|
||||
|
||||
export const microMark = pgTable("micro_mark", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
title: text().default(''),
|
||||
description: text().default(''),
|
||||
tags: jsonb().default([]),
|
||||
data: jsonb().default({}),
|
||||
uname: varchar({ length: 255 }).default(''),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
cover: text().default(''),
|
||||
thumbnail: text().default(''),
|
||||
link: text().default(''),
|
||||
summary: text().default(''),
|
||||
markType: text().default('md'),
|
||||
config: jsonb().default({}),
|
||||
puid: uuid(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
version: integer().default(1),
|
||||
fileList: jsonb().default([]),
|
||||
key: text().default(''),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
title: text().default(''),
|
||||
description: text().default(''),
|
||||
tags: jsonb().default([]),
|
||||
data: jsonb().default({}),
|
||||
uname: varchar({ length: 255 }).default(''),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
cover: text().default(''),
|
||||
thumbnail: text().default(''),
|
||||
link: text().default(''),
|
||||
summary: text().default(''),
|
||||
markType: text().default('md'),
|
||||
config: jsonb().default({}),
|
||||
puid: uuid(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
version: integer().default(1),
|
||||
fileList: jsonb().default([]),
|
||||
key: text().default(''),
|
||||
});
|
||||
|
||||
export const workShareMark = pgTable("work_share_mark", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
title: text().default(''),
|
||||
key: text().default(''),
|
||||
markType: text().default('md'),
|
||||
description: text().default(''),
|
||||
cover: text().default(''),
|
||||
link: text().default(''),
|
||||
tags: jsonb().default([]),
|
||||
summary: text().default(''),
|
||||
config: jsonb().default({}),
|
||||
data: jsonb().default({}),
|
||||
fileList: jsonb().default([]),
|
||||
uname: varchar({ length: 255 }).default(''),
|
||||
version: integer().default(1),
|
||||
markedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
uid: uuid(),
|
||||
puid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
id: uuid().primaryKey().notNull(),
|
||||
title: text().default(''),
|
||||
key: text().default(''),
|
||||
markType: text().default('md'),
|
||||
description: text().default(''),
|
||||
cover: text().default(''),
|
||||
link: text().default(''),
|
||||
tags: jsonb().default([]),
|
||||
summary: text().default(''),
|
||||
config: jsonb().default({}),
|
||||
data: jsonb().default({}),
|
||||
fileList: jsonb().default([]),
|
||||
uname: varchar({ length: 255 }).default(''),
|
||||
version: integer().default(1),
|
||||
markedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
uid: uuid(),
|
||||
puid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
});
|
||||
|
||||
|
||||
export const prompts = pgTable('cf_prompts', {
|
||||
id: uuid('id').primaryKey().defaultRandom(),
|
||||
uid: uuid('uid'),
|
||||
parents: jsonb('parents').notNull().default([]),
|
||||
parents: text('parents').array().notNull().default([]),
|
||||
data: jsonb('data').notNull().default({}),
|
||||
|
||||
title: text('title').default(''),
|
||||
@@ -402,4 +402,77 @@ export const prompts = pgTable('cf_prompts', {
|
||||
createdAt: timestamp('createdAt').notNull().defaultNow(),
|
||||
updatedAt: timestamp('updatedAt').notNull().defaultNow(),
|
||||
deletedAt: timestamp('deletedAt'),
|
||||
});
|
||||
}, (table) => [
|
||||
index('prompts_parents_idx').using('gin', table.parents),
|
||||
]);
|
||||
|
||||
export type RouterViewItem = RouterViewApi | RouterViewContext | RouterViewWorker;
|
||||
export type RouterViewApi = {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
type: 'api',
|
||||
api: {
|
||||
url: string,
|
||||
// 已初始化的query实例
|
||||
// query?: Query
|
||||
}
|
||||
}
|
||||
|
||||
export type RouterViewContext = {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
type: 'context',
|
||||
context: {
|
||||
key: string,
|
||||
// 从context中获取router
|
||||
// router?: QueryRouterServer
|
||||
}
|
||||
}
|
||||
export type RouterViewWorker = {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
type: 'worker',
|
||||
worker: {
|
||||
type: 'Worker' | 'SharedWorker' | 'serviceWorker',
|
||||
url: string,
|
||||
// 已初始化的worker实例
|
||||
// worker?: Worker | SharedWorker | ServiceWorker,
|
||||
/**
|
||||
* worker选项
|
||||
* default: { type: 'module' }
|
||||
*/
|
||||
workerOptions?: {
|
||||
type: 'module' | 'classic'
|
||||
}
|
||||
}
|
||||
}
|
||||
export type RouterViewQuery = {
|
||||
id: string,
|
||||
query: string,
|
||||
title: string
|
||||
}
|
||||
|
||||
export const routerViews = pgTable("router_views", {
|
||||
id: uuid().primaryKey().notNull().defaultRandom(),
|
||||
uid: uuid(),
|
||||
|
||||
title: text('title').default(''),
|
||||
summary: text('summary').default(''),
|
||||
description: text('description').default(''),
|
||||
tags: jsonb().default([]),
|
||||
link: text('link').default(''),
|
||||
data: jsonb().default({}).$type<{
|
||||
items: Array<RouterViewItem>
|
||||
}>(),
|
||||
|
||||
views: jsonb().default([]).$type<Array<RouterViewQuery>>(),
|
||||
createdAt: timestamp('createdAt').notNull().defaultNow(),
|
||||
updatedAt: timestamp('updatedAt').notNull().defaultNow(),
|
||||
}, (table) => [
|
||||
index('router_views_uid_idx').using('btree', table.uid.asc().nullsLast()),
|
||||
index('router_title_idx').using('btree', table.title.asc().nullsLast()),
|
||||
index('router_views_views_idx').using('gin', table.views),
|
||||
]);
|
||||
Reference in New Issue
Block a user