@lark-base-open/base-database-app-sdk 0.0.0-stage → 0.0.1-alpha.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/LICENSE +6 -0
- package/README.md +30 -2
- package/capabilities.json +75 -0
- package/development-pairing.json +11 -0
- package/dist/capabilities-56e403e7.d.ts +22 -0
- package/dist/chunk-3JX3FIBG.js +1 -0
- package/dist/chunk-HEMWSWXI.js +1 -0
- package/dist/chunk-OHPYKFCM.js +1 -0
- package/dist/chunk-YDAVA3BB.js +1 -0
- package/dist/components.d.ts +5 -0
- package/dist/components.js +1 -0
- package/dist/index-64557073.d.ts +306 -0
- package/dist/page.d.ts +137 -0
- package/dist/page.js +1 -0
- package/dist/server.cjs +1 -0
- package/dist/server.d.cts +78 -0
- package/dist/server.d.ts +78 -0
- package/dist/server.js +1 -0
- package/dist/shared.cjs +1 -0
- package/dist/shared.d.cts +177 -0
- package/dist/shared.d.ts +177 -0
- package/dist/shared.js +1 -0
- package/dist/testing.d.ts +73 -0
- package/dist/testing.js +1 -0
- package/dist/theme.css +168 -0
- package/dist/vite.d.ts +15 -0
- package/dist/vite.js +3 -0
- package/docs/README.md +16 -0
- package/docs/capabilities.md +59 -0
- package/docs/compat.md +36 -0
- package/docs/components.md +34 -0
- package/docs/exports.md +39 -0
- package/docs/page.md +101 -0
- package/docs/server.md +92 -0
- package/docs/shared.md +21 -0
- package/docs/start-base-app.md +47 -0
- package/docs/testing.md +57 -0
- package/docs/upgrade.md +44 -0
- package/examples/capabilities.ts +7 -0
- package/examples/compat.ts +21 -0
- package/examples/components.tsx +11 -0
- package/examples/contract-types.ts +41 -0
- package/examples/development-context.ts +17 -0
- package/examples/http.ts +12 -0
- package/examples/link.ts +10 -0
- package/examples/mock.ts +8 -0
- package/examples/msw.ts +5 -0
- package/examples/page.ts +6 -0
- package/examples/server.ts +57 -0
- package/examples/shared.ts +10 -0
- package/examples/start-base-app.tsx +8 -0
- package/examples/upgrade.ts +7 -0
- package/examples/upload.ts +18 -0
- package/examples/vite.ts +2 -0
- package/package.json +105 -4
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import {
|
|
3
|
+
defineFunction,
|
|
4
|
+
bindFunctionRuntime,
|
|
5
|
+
} from "@lark-base-open/base-database-app-sdk/server";
|
|
6
|
+
// 实际工程将 input/output 放独立 contract.ts,CLI 只提取 Schema 依赖图。
|
|
7
|
+
const input = z.object({ title: z.string().min(1) });
|
|
8
|
+
const ignored = z.object({
|
|
9
|
+
id: z.string(),
|
|
10
|
+
name: z.string(),
|
|
11
|
+
reason: z.string(),
|
|
12
|
+
});
|
|
13
|
+
const output = z.discriminatedUnion("status", [
|
|
14
|
+
z.object({
|
|
15
|
+
status: z.literal("success"),
|
|
16
|
+
appliedIds: z.array(z.string()),
|
|
17
|
+
notFoundIds: z.tuple([]),
|
|
18
|
+
ignoredFields: z.tuple([]),
|
|
19
|
+
attachments: z.json().optional(),
|
|
20
|
+
noop: z.boolean().optional(),
|
|
21
|
+
}),
|
|
22
|
+
z.object({
|
|
23
|
+
status: z.literal("partial"),
|
|
24
|
+
appliedIds: z.array(z.string()),
|
|
25
|
+
notFoundIds: z.array(z.string()),
|
|
26
|
+
ignoredFields: z.array(ignored),
|
|
27
|
+
attachments: z.json().optional(),
|
|
28
|
+
}),
|
|
29
|
+
z.object({
|
|
30
|
+
status: z.literal("failed"),
|
|
31
|
+
code: z.string(),
|
|
32
|
+
upstreamCode: z.number().optional(),
|
|
33
|
+
retryable: z.literal(false),
|
|
34
|
+
appliedIds: z.tuple([]),
|
|
35
|
+
}),
|
|
36
|
+
z.object({
|
|
37
|
+
status: z.literal("unknown"),
|
|
38
|
+
code: z.string(),
|
|
39
|
+
retryable: z.literal(false),
|
|
40
|
+
requestedIds: z.array(z.string()).optional(),
|
|
41
|
+
logid: z.string().optional(),
|
|
42
|
+
}),
|
|
43
|
+
]);
|
|
44
|
+
const handler = defineFunction({
|
|
45
|
+
input,
|
|
46
|
+
output,
|
|
47
|
+
handler: (params, ctx) =>
|
|
48
|
+
ctx.records.create(
|
|
49
|
+
{ baseToken: "baseFromCatalog", tableId: "tblFromCatalog" },
|
|
50
|
+
[{ title: params.title }],
|
|
51
|
+
),
|
|
52
|
+
});
|
|
53
|
+
// 此绑定入口由 CLI 生成;业务 handler 不选择区域、不持有身份凭据。
|
|
54
|
+
export default bindFunctionRuntime(handler, {
|
|
55
|
+
platformEnv: "online",
|
|
56
|
+
brand: "feishu",
|
|
57
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { classifyRuntimeError, type WriteResult } from '@lark-base-open/base-database-app-sdk/shared';
|
|
2
|
+
export function writeMessage(result: WriteResult): string {
|
|
3
|
+
switch (result.status) {
|
|
4
|
+
case 'success': return `已写入 ${result.appliedIds.length} 条`;
|
|
5
|
+
case 'partial': return '部分完成,请检查缺失记录和忽略字段';
|
|
6
|
+
case 'failed': return '请求未发送,请修正输入或运行环境';
|
|
7
|
+
case 'unknown': return '结果待核对,请勿直接重试';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export const describeError = classifyRuntimeError;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { startBaseApp } from '@lark-base-open/base-database-app-sdk/page';
|
|
2
|
+
import '@lark-base-open/base-database-app-sdk/page/styles.css';
|
|
3
|
+
function App() { return <main>订单工作台</main>; }
|
|
4
|
+
export function mountApp() {
|
|
5
|
+
const app = startBaseApp({ app: App, locale: 'zh', theme: 'host' });
|
|
6
|
+
void app.ready.catch(() => console.warn('应用启动失败'));
|
|
7
|
+
return () => app.dispose(); // 卸载或 HMR 时调用。
|
|
8
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// 模板 1 可先迁移 helper 导入;切换启动入口与模板 2 是独立的手动步骤。
|
|
2
|
+
import { installLinkGuard, siteRuntime, classifyRuntimeError } from '@lark-base-open/base-database-app-sdk/page';
|
|
3
|
+
export function initializeRuntime() {
|
|
4
|
+
const uninstall = installLinkGuard();
|
|
5
|
+
void siteRuntime.ready().catch(error => console.warn(classifyRuntimeError(error)));
|
|
6
|
+
return uninstall;
|
|
7
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { requireCapability, siteRuntime } from '@lark-base-open/base-database-app-sdk/page';
|
|
2
|
+
export async function upload(baseToken: string, tableId: string, file: File) {
|
|
3
|
+
await requireCapability('attachment.upload');
|
|
4
|
+
let dimensions: { image_width: number; image_height: number } | undefined;
|
|
5
|
+
if (!file.type) throw new Error('无法识别文件类型');
|
|
6
|
+
if (file.type.startsWith('image/')) {
|
|
7
|
+
const url = URL.createObjectURL(file);
|
|
8
|
+
try {
|
|
9
|
+
const image = new Image(); image.src = url; await image.decode();
|
|
10
|
+
if (image.naturalWidth <= 0 || image.naturalHeight <= 0) throw new Error('无法读取图片尺寸');
|
|
11
|
+
dimensions = { image_width: image.naturalWidth, image_height: image.naturalHeight };
|
|
12
|
+
} finally { URL.revokeObjectURL(url); }
|
|
13
|
+
}
|
|
14
|
+
const result = await siteRuntime.uploadAttachment({ baseToken, tableId, file,
|
|
15
|
+
onProgress: ({ loaded, total }) => console.info(`${loaded}/${total}`) });
|
|
16
|
+
return { file_token: result.fileToken, ...dimensions };
|
|
17
|
+
// 下一步经业务 FaaS 挂载;上传成功不代表单元格写入成功。
|
|
18
|
+
}
|
package/examples/vite.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,107 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-base-open/base-database-app-sdk",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1-alpha.0",
|
|
4
|
+
"description": "Base Database \u9875\u9762\u4e0e\u670d\u52a1\u7aef SDK\u3001\u5e73\u53f0\u7ec4\u4ef6\u53ca\u6d4b\u8bd5\u5de5\u5177",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"sideEffects": [
|
|
7
|
+
"**/*.css"
|
|
8
|
+
],
|
|
9
|
+
"exports": {
|
|
10
|
+
"./page": {
|
|
11
|
+
"types": "./dist/page.d.ts",
|
|
12
|
+
"import": "./dist/page.js"
|
|
13
|
+
},
|
|
14
|
+
"./server": {
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./dist/server.d.ts",
|
|
17
|
+
"default": "./dist/server.js"
|
|
18
|
+
},
|
|
19
|
+
"require": {
|
|
20
|
+
"types": "./dist/server.d.cts",
|
|
21
|
+
"default": "./dist/server.cjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"./shared": {
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/shared.d.ts",
|
|
27
|
+
"default": "./dist/shared.js"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./dist/shared.d.cts",
|
|
31
|
+
"default": "./dist/shared.cjs"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"./testing": {
|
|
35
|
+
"types": "./dist/testing.d.ts",
|
|
36
|
+
"import": "./dist/testing.js"
|
|
37
|
+
},
|
|
38
|
+
"./components": {
|
|
39
|
+
"types": "./dist/components.d.ts",
|
|
40
|
+
"import": "./dist/components.js"
|
|
41
|
+
},
|
|
42
|
+
"./page/styles.css": "./dist/theme.css",
|
|
43
|
+
"./vite": {
|
|
44
|
+
"types": "./dist/vite.d.ts",
|
|
45
|
+
"import": "./dist/vite.js"
|
|
46
|
+
},
|
|
47
|
+
"./development-pairing.json": "./development-pairing.json"
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"dist",
|
|
51
|
+
"docs",
|
|
52
|
+
"examples",
|
|
53
|
+
"README.md",
|
|
54
|
+
"LICENSE",
|
|
55
|
+
"capabilities.json",
|
|
56
|
+
"development-pairing.json"
|
|
57
|
+
],
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "tsup && tsup --config tsup.cjs.config.ts && cp src/page/theme.css dist/theme.css",
|
|
60
|
+
"test": "npm run build && node --import tsx --test test/*.test.ts && npm run test:types && npm run test:components",
|
|
61
|
+
"test:types": "tsc -p tsconfig.examples.json && tsc -p tsconfig.server.json && tsc -p tsconfig.cjs.json",
|
|
62
|
+
"test:browser": "node test/browser/verify.mjs && node test/browser/ui-verify.mjs",
|
|
63
|
+
"test:components": "vitest run",
|
|
64
|
+
"docs:exports": "node scripts/doc-exports.mjs"
|
|
65
|
+
},
|
|
66
|
+
"dependencies": {
|
|
67
|
+
"@lark-base-open/base-site-channel": "0.1.5",
|
|
68
|
+
"@radix-ui/react-popover": "1.2.0",
|
|
69
|
+
"@standard-schema/spec": "1.0.0",
|
|
70
|
+
"cmdk": "1.1.1"
|
|
71
|
+
},
|
|
72
|
+
"peerDependencies": {
|
|
73
|
+
"@tanstack/react-query": "5.104.1",
|
|
74
|
+
"msw": "2.11.6",
|
|
75
|
+
"react": "^19.2.0",
|
|
76
|
+
"react-dom": "^19.2.0"
|
|
77
|
+
},
|
|
78
|
+
"peerDependenciesMeta": {
|
|
79
|
+
"msw": {
|
|
80
|
+
"optional": true
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"devDependencies": {
|
|
84
|
+
"@testing-library/react": "16.3.0",
|
|
85
|
+
"@types/node": "22.15.0",
|
|
86
|
+
"@types/react": "19.2.17",
|
|
87
|
+
"@types/react-dom": "19.2.3",
|
|
88
|
+
"jsdom": "26.1.0",
|
|
89
|
+
"msw": "2.11.6",
|
|
90
|
+
"pngjs": "7.0.0",
|
|
91
|
+
"tsup": "6.7.0",
|
|
92
|
+
"tsx": "4.20.3",
|
|
93
|
+
"typescript": "5.8.3",
|
|
94
|
+
"vitest": "3.2.4",
|
|
95
|
+
"zod": "4.2.1"
|
|
96
|
+
},
|
|
97
|
+
"typesVersions": {
|
|
98
|
+
"*": {
|
|
99
|
+
"server": [
|
|
100
|
+
"dist/server.d.cts"
|
|
101
|
+
],
|
|
102
|
+
"shared": [
|
|
103
|
+
"dist/shared.d.cts"
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|