更新数据库配置,添加默认时间戳,优化轻代码路由处理,新增示例代码文件
This commit is contained in:
@@ -10,8 +10,8 @@ export const testPromptTools = pgTable("TestPromptTools", {
|
||||
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(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
});
|
||||
|
||||
export const aiAgent = pgTable("ai_agent", {
|
||||
@@ -22,8 +22,8 @@ export const aiAgent = pgTable("ai_agent", {
|
||||
temperature: doublePrecision(),
|
||||
cache: varchar({ length: 255 }),
|
||||
cacheName: varchar({ length: 255 }),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
model: varchar({ length: 255 }).notNull(),
|
||||
data: json().default({}),
|
||||
status: varchar({ length: 255 }).default('open'),
|
||||
@@ -43,8 +43,8 @@ export const appsTrades = pgTable("apps_trades", {
|
||||
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(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
}, (table) => [
|
||||
unique("apps_trades_out_trade_no_key").on(table.outTradeNo),
|
||||
@@ -54,8 +54,8 @@ 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(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
description: varchar({ length: 255 }),
|
||||
}, (table) => [
|
||||
@@ -70,8 +70,8 @@ export const cfRouterCode = pgTable("cf_router_code", {
|
||||
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(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
middleware: varchar({ length: 255 }).array().default(["RRAY[]::character varying[])::character varying(25"]),
|
||||
next: varchar({ length: 255 }).default(''),
|
||||
exec: text().default(''),
|
||||
@@ -86,8 +86,8 @@ export const cfUser = pgTable("cf_user", {
|
||||
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(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
description: text(),
|
||||
data: jsonb().default({}),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
@@ -111,8 +111,8 @@ export const cfUserSecrets = pgTable("cf_user_secrets", {
|
||||
userId: uuid(),
|
||||
data: jsonb().default({}),
|
||||
orgId: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
});
|
||||
|
||||
export const chatHistories = pgTable("chat_histories", {
|
||||
@@ -123,8 +123,8 @@ export const chatHistories = pgTable("chat_histories", {
|
||||
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(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
role: varchar({ length: 255 }).default('user'),
|
||||
});
|
||||
|
||||
@@ -135,8 +135,8 @@ export const chatPrompts = pgTable("chat_prompts", {
|
||||
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(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
});
|
||||
|
||||
@@ -146,8 +146,8 @@ export const chatSessions = pgTable("chat_sessions", {
|
||||
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(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
title: varchar({ length: 255 }).default(''),
|
||||
key: varchar({ length: 255 }),
|
||||
});
|
||||
@@ -159,8 +159,8 @@ export const fileSync = pgTable("file_sync", {
|
||||
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(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
}, (table) => [
|
||||
index("file_sync_name_idx").using("btree", table.name.asc().nullsLast()),
|
||||
]);
|
||||
@@ -177,8 +177,8 @@ export const kvAiChatHistory = pgTable("kv_ai_chat_history", {
|
||||
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(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
version: integer().default(0),
|
||||
type: varchar({ length: 255 }).default('keep').notNull(),
|
||||
});
|
||||
@@ -189,8 +189,8 @@ export const kvApp = pgTable("kv_app", {
|
||||
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(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
title: varchar({ length: 255 }).default(''),
|
||||
description: varchar({ length: 255 }).default(''),
|
||||
@@ -208,8 +208,8 @@ export const kvAppDomain = pgTable("kv_app_domain", {
|
||||
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(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
data: jsonb(),
|
||||
status: varchar({ length: 255 }).default('running').notNull(),
|
||||
@@ -222,8 +222,8 @@ export const kvAppList = pgTable("kv_app_list", {
|
||||
data: json().default({}),
|
||||
version: varchar({ length: 255 }).default(''),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
key: varchar({ length: 255 }),
|
||||
status: varchar({ length: 255 }).default('running'),
|
||||
@@ -237,24 +237,23 @@ export const kvConfig = pgTable("kv_config", {
|
||||
tags: jsonb().default([]),
|
||||
data: jsonb().default({}),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
hash: text().default(''),
|
||||
});
|
||||
|
||||
export const kvContainer = pgTable("kv_container", {
|
||||
id: uuid().primaryKey().notNull(),
|
||||
export const kvContainer = pgTable("kv_light_code", {
|
||||
id: uuid().primaryKey().notNull().defaultRandom(),
|
||||
title: text().default(''),
|
||||
description: text().default(''),
|
||||
type: varchar({ length: 255 }).default('render-js'),
|
||||
type: text().default('render-js'),
|
||||
code: text().default(''),
|
||||
data: json().default({}),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
data: jsonb().default({}),
|
||||
createdAt: timestamp('createdAt').notNull().defaultNow(),
|
||||
updatedAt: timestamp('updatedAt').notNull().defaultNow(),
|
||||
uid: uuid(),
|
||||
tags: json().default([]),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
tags: jsonb().default([]),
|
||||
hash: text().default(''),
|
||||
});
|
||||
|
||||
@@ -263,8 +262,8 @@ export const kvGithub = pgTable("kv_github", {
|
||||
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(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
});
|
||||
|
||||
@@ -277,8 +276,8 @@ export const kvPackages = pgTable("kv_packages", {
|
||||
publish: jsonb().default({}),
|
||||
expand: jsonb().default({}),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
});
|
||||
|
||||
@@ -289,8 +288,8 @@ export const kvPage = pgTable("kv_page", {
|
||||
type: varchar({ length: 255 }).default(''),
|
||||
data: json().default({}),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
publish: json().default({}),
|
||||
});
|
||||
@@ -304,8 +303,8 @@ export const kvResource = pgTable("kv_resource", {
|
||||
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(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
});
|
||||
|
||||
@@ -317,8 +316,8 @@ export const kvVip = pgTable("kv_vip", {
|
||||
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(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
title: text().default('').notNull(),
|
||||
description: text().default('').notNull(),
|
||||
@@ -335,8 +334,8 @@ export const microAppsUpload = pgTable("micro_apps_upload", {
|
||||
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(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
});
|
||||
|
||||
export const microMark = pgTable("micro_mark", {
|
||||
@@ -347,8 +346,8 @@ export const microMark = pgTable("micro_mark", {
|
||||
data: jsonb().default({}),
|
||||
uname: varchar({ length: 255 }).default(''),
|
||||
uid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
cover: text().default(''),
|
||||
thumbnail: text().default(''),
|
||||
link: text().default(''),
|
||||
@@ -380,8 +379,8 @@ export const workShareMark = pgTable("work_share_mark", {
|
||||
markedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
uid: uuid(),
|
||||
puid: uuid(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull(),
|
||||
createdAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
updatedAt: timestamp({ withTimezone: true, mode: 'string' }).notNull().defaultNow(),
|
||||
deletedAt: timestamp({ withTimezone: true, mode: 'string' }),
|
||||
});
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ app
|
||||
path: 'light-code',
|
||||
key: 'update',
|
||||
middleware: ['auth'],
|
||||
isDebug: true,
|
||||
})
|
||||
.define(async (ctx) => {
|
||||
const tokenUser = ctx.state.tokenUser;
|
||||
@@ -111,16 +112,28 @@ app
|
||||
ctx.body = null;
|
||||
}
|
||||
} else {
|
||||
const [created] = await db
|
||||
.insert(schema.kvContainer)
|
||||
.values({
|
||||
...container,
|
||||
uid: tokenUser.id,
|
||||
})
|
||||
.returning();
|
||||
ctx.body = created;
|
||||
try {
|
||||
|
||||
console.log('created', container, 'userId', tokenUser.id);
|
||||
const [created] = await db
|
||||
.insert(schema.kvContainer)
|
||||
.values({
|
||||
title: container.title || '',
|
||||
description: container.description || '',
|
||||
type: container.type || 'light-code',
|
||||
code: container.code || '',
|
||||
data: container.data || {},
|
||||
tags: container.tags || [],
|
||||
hash: container.hash || '',
|
||||
uid: tokenUser.id,
|
||||
})
|
||||
.returning();
|
||||
ctx.body = created;
|
||||
} catch (error) {
|
||||
console.error('Error creating container:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
return ctx;
|
||||
})
|
||||
.addTo(app);
|
||||
|
||||
|
||||
44
src/test/add-demo-light-code.ts
Normal file
44
src/test/add-demo-light-code.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { app, showMore, showRes } from './common.ts';
|
||||
import crypto from 'node:crypto';
|
||||
|
||||
export const getStringHash = (str: string) => {
|
||||
return crypto.createHash('md5').update(str).digest('hex');
|
||||
}
|
||||
const code = `// 这是一个示例代码文件
|
||||
import {App} from '@kevisual/router';
|
||||
|
||||
const app = new App();
|
||||
|
||||
app.route({
|
||||
path: 'hello',
|
||||
description: 'LightCode 示例路由',
|
||||
metadata: {
|
||||
tags: ['light-code', 'example'],
|
||||
},
|
||||
}).define(async (ctx) => {
|
||||
console.log('tokenUser:', ctx.query?.tokenUser);
|
||||
ctx.body = 'Hello from LightCode!';
|
||||
}).addTo(app);
|
||||
|
||||
app.wait();`
|
||||
const code2 = `const a = 1`
|
||||
|
||||
const res = await app.run({
|
||||
path: 'light-code',
|
||||
key: 'update',
|
||||
payload: {
|
||||
data: {
|
||||
title: 'Demo Light Code',
|
||||
description: '这是一个演示用的轻代码项目,包含一个简单的路由示例。',
|
||||
type: 'light-code',
|
||||
tags: ['demo', 'light-code'],
|
||||
data: {},
|
||||
code: code,
|
||||
hash: getStringHash(code),
|
||||
},
|
||||
token: "st_idht7xpffhgu2eeh94zd8ze1t7ew3amy",
|
||||
},
|
||||
|
||||
})
|
||||
|
||||
console.log('showMore', showMore(res));
|
||||
@@ -3,7 +3,9 @@ import '@/route.ts';
|
||||
import { useConfig, useContextKey } from '@kevisual/context';
|
||||
import { Query } from '@kevisual/query';
|
||||
import util from 'node:util';
|
||||
import dotenv from 'dotenv';
|
||||
|
||||
dotenv.config();
|
||||
export {
|
||||
app,
|
||||
useContextKey
|
||||
|
||||
Reference in New Issue
Block a user