Skip to content

Commit 024fb75

Browse files
committed
schema 移到编译阶段
1 parent 7bfa06a commit 024fb75

File tree

9 files changed

+24
-25
lines changed

9 files changed

+24
-25
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "docbase",
3-
"version": "0.1.8",
3+
"version": "0.1.9",
44
"type": "module",
55
"workspaces": [
66
"packages/*"

packages/app/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"core": "workspace:*",
1414
"es-toolkit": "^1.33.0",
1515
"nypm": "^0.6.0",
16-
"zod-to-json-schema": "^3.24.4",
1716
"@hey-api/openapi-ts": "^0.64.12"
1817
},
1918
"dependencies": {

packages/app/src/apis/plugin/index.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { createRoute, z } from "@hono/zod-openapi";
22
import { OpenAPIHono } from "@hono/zod-openapi";
33
import { DocBasePlugin } from "core/src";
4-
import { merge } from "es-toolkit";
5-
import { zodToJsonSchema } from "zod-to-json-schema";
64

75
const app = new OpenAPIHono();
86

@@ -111,8 +109,6 @@ const listPlugin = createRoute({
111109
homepage: z.string().optional(),
112110
/** 插件图标 */
113111
icon: z.string().optional(),
114-
/** 插件参数校验 schema */
115-
paramsSchema: z.any().optional(),
116112
})),
117113
docSplitter: z.object({
118114
/** 插件类型,固定为"DocLoader" */
@@ -131,8 +127,6 @@ const listPlugin = createRoute({
131127
homepage: z.string().optional(),
132128
/** 插件图标 */
133129
icon: z.string().optional(),
134-
/** 插件参数校验 schema */
135-
paramsSchema: z.any().optional(),
136130
}),
137131
}),
138132
},
@@ -239,13 +233,11 @@ app.openapi(addPlugin, async (c) => {
239233
}
240234
})
241235

242-
const convertJSONSchema = (i: { paramsSchema?: z.ZodType; }) => merge(i, { paramsSchema: i.paramsSchema ? zodToJsonSchema(i.paramsSchema) : i.paramsSchema })
243-
244236
app.openapi(listPlugin, async (c) => {
245237
const docBase = c.get("docbase");
246238
return c.json({
247-
docLoaders: docBase.docLoaders.map(convertJSONSchema).toArray(),
248-
docSplitter: convertJSONSchema(docBase.docSplitter),
239+
docLoaders: docBase.docLoaders.toArray(),
240+
docSplitter: docBase.docSplitter,
249241
});
250242
})
251243

packages/app/src/plugins/pkgManager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { removeDependency, addDependency } from "nypm"
22
import { exists, readJSON } from "fs-extra"
33
import { join } from "path"
4+
import { DocBasePlugin } from "core/src"
45

56
export class PackageManager {
67
#path: string
@@ -12,7 +13,7 @@ export class PackageManager {
1213
this.#modulePath = join(path, "node_modules")
1314
}
1415

15-
import = async (name: string) => {
16+
import = async (name: string): Promise<DocBasePlugin> => {
1617
const m = await import(join(this.#modulePath, name))
1718
if (m.default) {
1819
return m.default

packages/core/src/DocSplitter.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export const defaultDocSplitterPlugin: DocSplitterPlugin<typeof DocSplitterPlugi
3636
name: "default",
3737
version,
3838
type: "DocSplitter",
39-
paramsSchema: DocSplitterPluginParams,
4039
init:
4140
({ len }) =>
4241
(text: string) => {

packages/core/src/Plugin.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ export interface BasePlugin<
2727
homepage?: string;
2828
/** 插件图标 */
2929
icon?: string;
30-
/** 插件参数校验 schema */
31-
paramsSchema?: PluginParams;
3230
/**
3331
* 插件初始化函数
3432
* @param params - 插件初始化参数
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
Bun.build({
2-
entrypoints: ["./index.ts"],
3-
outdir: "./dist",
4-
minify: true,
5-
target: "bun",
6-
})
1+
import { zodToJsonSchema } from "zod-to-json-schema";
2+
import { schema } from "./index"
3+
import { write } from "bun";
4+
5+
Promise.all(
6+
[
7+
Bun.build({
8+
entrypoints: ["./index.ts"],
9+
outdir: "./dist",
10+
minify: true,
11+
target: "bun",
12+
}),
13+
write("dist/schema.json", JSON.stringify(zodToJsonSchema(schema), null, 2))
14+
]
15+
)

packages/docbase-plugin-docloader-extra/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import { basename } from "path";
1111
import { single, transform } from "itertools-ts"
1212
import { z } from "zod"
1313

14-
const paramsSchema = z.object({})
14+
export const schema = z.object({})
1515

16-
const plugin: DocBasePlugin<typeof paramsSchema> = {
16+
const plugin: DocBasePlugin<typeof schema> = {
1717
type: "DocLoader",
1818
exts: exts,
1919
name: name,
@@ -23,7 +23,6 @@ const plugin: DocBasePlugin<typeof paramsSchema> = {
2323
description: description,
2424
homepage,
2525
icon,
26-
paramsSchema,
2726
init: async () => {
2827
return async (path) => {
2928
if (basename(path).startsWith("~$")) {

packages/docbase-plugin-docloader-extra/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"homepage": "https://docbase.cc",
88
"main": "dist/index.js",
99
"module": "dist/index.js",
10+
"schema": "dist/schema.json",
1011
"description": "DocBase 额外文档加载插件,支持更多格式",
1112
"icon": "https://docbase.cc/logo.svg",
1213
"exts": [
@@ -23,6 +24,7 @@
2324
"test": "bun run ./test.ts"
2425
},
2526
"devDependencies": {
27+
"zod-to-json-schema": "^3.24.4",
2628
"@llm-tools/embedjs": "^0.1.28",
2729
"@llm-tools/embedjs-interfaces": "^0.1.28",
2830
"@llm-tools/embedjs-loader-csv": "^0.1.28",

0 commit comments

Comments
 (0)