@mindbase/express-knowledge 1.0.8 → 1.0.12

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/index.ts CHANGED
@@ -1,35 +1,42 @@
1
- export { default } from "./module/KnowledgeModule";
2
-
3
- // 导出类型
4
- export {
5
- type KnowledgeSafe,
6
- type KnowledgeType,
7
- type Knowledge,
8
- type KnowledgeTreeNode,
9
- type KnowledgeTag,
10
- type KnowledgeTagRelation,
11
- type InsertKnowledge,
12
- type InsertTag,
13
- } from './types';
14
-
15
- // 导出 Schema
16
- export {
17
- knowledge,
18
- createKnowledgeSchema,
19
- batchCreateKnowledgeSchema,
20
- batchDetailKnowledgeSchema,
21
- updateKnowledgeSchema,
22
- listKnowledgeSchema,
23
- searchKnowledgeSchema,
24
- moveKnowledgeSchema,
25
- updateIsTopSchema,
26
- updateSafeSchema,
27
- } from './orm/Knowledge.schema';
28
-
29
- export {
30
- knowledgeTag,
31
- knowledgeTagRelation,
32
- createTagSchema,
33
- updateTagSchema,
34
- addTagRelationSchema,
35
- } from './orm/Tag.schema';
1
+ export { default } from "./module/KnowledgeModule";
2
+
3
+ // 导出类型
4
+ export {
5
+ type KnowledgeSafe,
6
+ type KnowledgeType,
7
+ type Knowledge,
8
+ type KnowledgeTreeNode,
9
+ type KnowledgeTag,
10
+ type KnowledgeTagRelation,
11
+ type InsertKnowledge,
12
+ type InsertTag,
13
+ } from './types';
14
+
15
+ // 导出数据库表
16
+ export {
17
+ knowledge,
18
+ } from './orm/Knowledge.schema';
19
+
20
+ export {
21
+ knowledgeTag,
22
+ knowledgeTagRelation,
23
+ } from './orm/Tag.schema';
24
+
25
+ // 导出验证 Schema
26
+ export {
27
+ createKnowledgeSchema,
28
+ batchCreateKnowledgeSchema,
29
+ batchDetailKnowledgeSchema,
30
+ updateKnowledgeSchema,
31
+ listKnowledgeSchema,
32
+ searchKnowledgeSchema,
33
+ moveKnowledgeSchema,
34
+ updateIsTopSchema,
35
+ updateSafeSchema,
36
+ } from './zod/knowledge.validation';
37
+
38
+ export {
39
+ createTagSchema,
40
+ updateTagSchema,
41
+ addTagRelationSchema,
42
+ } from './zod/tag.validation';
@@ -1,123 +1,27 @@
1
- import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
2
- import { createInsertSchema, createSelectSchema } from "drizzle-zod";
3
- import { z } from "zod";
4
-
5
- /**
6
- * 知识库主表
7
- */
8
- export const knowledge = sqliteTable("knowledge", {
9
- id: integer("id").primaryKey({ autoIncrement: true }),
10
- parentId: integer("parent_id").notNull(),
11
- name: text("name").notNull(),
12
- path: text("path").notNull(),
13
- level: integer("level").notNull().default(0),
14
- type: integer("type").notNull(), // 0:文件夹 1:笔记 2:书籍
15
- safe: integer("safe").notNull().default(0),
16
- userId: integer("user_id").notNull(),
17
- // 书籍特有字段
18
- coverImage: text("cover_image"),
19
- author: text("author"),
20
- isbn: text("isbn"),
21
- description: text("description"),
22
- created: integer("created", { mode: "timestamp" }),
23
- updated: integer("updated", { mode: "timestamp" }),
24
- isDelete: integer("is_delete").notNull().default(0),
25
- isTop: integer("is_top").notNull().default(0),
26
- content: text("content"),
27
- contentText: text("content_text"),
28
- viewType: integer("view_type").default(0),
29
- });
30
-
31
- // ==================== Zod Schemas ====================
32
-
33
- /**
34
- * 创建知识库内容验证
35
- */
36
- export const createKnowledgeSchema = createInsertSchema(knowledge as any, {
37
- name: z.string().min(1, "名称不能为空").max(255, "名称不能超过255字符") as any,
38
- type: z.coerce.number().int().min(0).max(2) as any,
39
- safe: z.coerce.number().int().min(0).max(2).optional() as any,
40
- }).pick({
41
- name: true,
42
- type: true,
43
- safe: true,
44
- description: true,
45
- content: true,
46
- contentText: true,
47
- viewType: true,
48
- coverImage: true,
49
- author: true,
50
- isbn: true,
51
- });
52
-
53
- /**
54
- * 批量创建验证
55
- */
56
- export const batchCreateKnowledgeSchema = z.object({
57
- parentId: z.number().optional(),
58
- items: z
59
- .array(
60
- z.object({
61
- name: z.string().min(1, "名称不能为空").max(255),
62
- type: z.coerce.number().int().min(0).max(2),
63
- })
64
- )
65
- .min(1, "至少需要一个项目"),
66
- });
67
-
68
- /**
69
- * 批量获取详情验证
70
- */
71
- export const batchDetailKnowledgeSchema = z.object({
72
- ids: z.array(z.number().int().positive()).min(1, "至少需要一个ID"),
73
- });
74
-
75
- /**
76
- * 更新知识库内容验证
77
- */
78
- export const updateKnowledgeSchema = createInsertSchema(knowledge as any)
79
- .partial()
80
- .extend({
81
- id: z.number({ required_error: "ID不能为空" }),
82
- });
83
-
84
- /**
85
- * 列表查询验证
86
- */
87
- export const listKnowledgeSchema = z.object({
88
- pageIndex: z.coerce.number().int().positive().optional().default(1),
89
- pageSize: z.coerce.number().int().positive().optional().default(10),
90
- level: z.coerce.number().int().min(0).optional(),
91
- type: z.coerce.number().int().min(0).max(2).optional(),
92
- safe: z.array(z.coerce.number().int().min(0).max(2)).optional(),
93
- });
94
-
95
- /**
96
- * 搜索验证
97
- */
98
- export const searchKnowledgeSchema = z.object({
99
- keyword: z.string().min(1, "关键词不能为空"),
100
- pageIndex: z.coerce.number().int().positive().optional().default(1),
101
- pageSize: z.coerce.number().int().positive().optional().default(10),
102
- });
103
-
104
- /**
105
- * 移动节点验证
106
- */
107
- export const moveKnowledgeSchema = z.object({
108
- newParentId: z.number({ required_error: "新父节点ID不能为空" }),
109
- });
110
-
111
- /**
112
- * 更新置顶状态验证
113
- */
114
- export const updateIsTopSchema = z.object({
115
- isTop: z.coerce.number().int().min(0).max(1),
116
- });
117
-
118
- /**
119
- * 更新安全等级验证
120
- */
121
- export const updateSafeSchema = z.object({
122
- safe: z.coerce.number().int().min(0).max(2),
123
- });
1
+ import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
2
+
3
+ /**
4
+ * 知识库主表
5
+ */
6
+ export const knowledge = sqliteTable("knowledge", {
7
+ id: integer("id").primaryKey({ autoIncrement: true }),
8
+ parentId: integer("parent_id").notNull(),
9
+ name: text("name").notNull(),
10
+ path: text("path").notNull(),
11
+ level: integer("level").notNull().default(0),
12
+ type: integer("type").notNull(), // 0:文件夹 1:笔记 2:书籍
13
+ safe: integer("safe").notNull().default(0),
14
+ userId: integer("user_id").notNull(),
15
+ // 书籍特有字段
16
+ coverImage: text("cover_image"),
17
+ author: text("author"),
18
+ isbn: text("isbn"),
19
+ description: text("description"),
20
+ created: integer("created", { mode: "timestamp" }),
21
+ updated: integer("updated", { mode: "timestamp" }),
22
+ isDelete: integer("is_delete").notNull().default(0),
23
+ isTop: integer("is_top").notNull().default(0),
24
+ content: text("content"),
25
+ contentText: text("content_text"),
26
+ viewType: integer("view_type").default(0),
27
+ });
package/orm/Tag.schema.ts CHANGED
@@ -1,51 +1,20 @@
1
- import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
2
- import { createInsertSchema, createSelectSchema } from "drizzle-zod";
3
- import { z } from "zod";
4
-
5
- /**
6
- * 标签表
7
- */
8
- export const knowledgeTag = sqliteTable("knowledge_tag", {
9
- id: integer("id").primaryKey({ autoIncrement: true }),
10
- name: text("name").notNull().unique(),
11
- color: text("color"),
12
- userId: integer("user_id"),
13
- created: integer("created", { mode: "timestamp" }),
14
- });
15
-
16
- /**
17
- * 标签关联表(多对多)
18
- */
19
- export const knowledgeTagRelation = sqliteTable("knowledge_tag_relation", {
20
- knowledgeId: integer("knowledge_id").notNull(),
21
- tagId: integer("tag_id").notNull(),
22
- });
23
-
24
- // ==================== Zod Schemas ====================
25
-
26
- /**
27
- * 创建标签验证
28
- */
29
- export const createTagSchema = createInsertSchema(knowledgeTag as any, {
30
- name: z.string().min(1, "标签名不能为空").max(50, "标签名不能超过50字符") as any,
31
- color: z.string().regex(/^#[0-9A-Fa-f]{6}$/, "颜色必须是十六进制格式").optional() as any,
32
- }).pick({
33
- name: true,
34
- color: true,
35
- });
36
-
37
- /**
38
- * 更新标签验证
39
- */
40
- export const updateTagSchema = createInsertSchema(knowledgeTag as any)
41
- .partial()
42
- .extend({
43
- id: z.number({ required_error: "标签ID不能为空" }),
44
- });
45
-
46
- /**
47
- * 添加标签关联验证
48
- */
49
- export const addTagRelationSchema = z.object({
50
- tagId: z.number({ required_error: "标签ID不能为空" }),
51
- });
1
+ import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
2
+
3
+ /**
4
+ * 标签表
5
+ */
6
+ export const knowledgeTag = sqliteTable("knowledge_tag", {
7
+ id: integer("id").primaryKey({ autoIncrement: true }),
8
+ name: text("name").notNull().unique(),
9
+ color: text("color"),
10
+ userId: integer("user_id"),
11
+ created: integer("created", { mode: "timestamp" }),
12
+ });
13
+
14
+ /**
15
+ * 标签关联表(多对多)
16
+ */
17
+ export const knowledgeTagRelation = sqliteTable("knowledge_tag_relation", {
18
+ knowledgeId: integer("knowledge_id").notNull(),
19
+ tagId: integer("tag_id").notNull(),
20
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mindbase/express-knowledge",
3
- "version": "1.0.8",
3
+ "version": "1.0.12",
4
4
  "exports": {
5
5
  ".": "./index.ts"
6
6
  },
@@ -21,14 +21,14 @@
21
21
  "peerDependencies": {
22
22
  "@mindbase/express-auth": "^1.0.0",
23
23
  "@mindbase/express-common": "^1.0.0",
24
- "drizzle-orm": "^0.44.7",
24
+ "drizzle-orm": "^0.45.1",
25
25
  "zod": "^3.24.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "typescript": "^5.1.3"
29
29
  },
30
30
  "scripts": {
31
- "prepare": "tsc --noEmit"
31
+ "prepublishOnly": "tsc --noEmit"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"
@@ -1,7 +1,7 @@
1
1
  import { Router, type Request, type Response, type NextFunction } from "express";
2
2
  import { logger, validate } from "@mindbase/express-common";
3
3
  import * as TagService from "../../service/TagService";
4
- import * as schemas from "../../zod/tag.schema";
4
+ import * as schemas from "../../zod/tag.validation";
5
5
 
6
6
  const router = Router();
7
7
 
@@ -1,7 +1,7 @@
1
1
  import { Router, type Request, type Response, type NextFunction } from "express";
2
2
  import { logger, validate } from "@mindbase/express-common";
3
3
  import * as KnowledgeService from "../service/KnowledgeService";
4
- import * as schemas from "../zod/knowledge.schema";
4
+ import * as schemas from "../zod/knowledge.validation";
5
5
 
6
6
  const router = Router();
7
7