Skip to content

Commit dd24b59

Browse files
committed
添加国际化助手和插件范围数据存储的支持,更新相关文档和 JSON Schema 定义
1 parent 671efb4 commit dd24b59

File tree

9 files changed

+160
-0
lines changed

9 files changed

+160
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: I18nContext
3+
description: Internationalization Helper
4+
---
5+
6+
Internationalization Helper
7+
8+
## Properties
9+
10+
| Property | Type | Required | Description |
11+
| :--- | :--- | :--- | :--- |

content/docs/references/system/PluginContext.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ description: PluginContext Schema Reference
1010
| **ql** | `object` || ObjectQL Data Access Client |
1111
| **os** | `object` || Access to System Core |
1212
| **logger** | `object` || Structured Logger |
13+
| **storage** | `object` || Plugin Scoped Data Storage (KV) |
14+
| **i18n** | `object` || Internationalization Helper |
1315
| **metadata** | `any` | optional | Metadata registry |
1416
| **events** | `any` | optional | Event bus |
1517
| **app** | `object` || App Runtime Capabilities |
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
title: ScopedStorage
3+
description: Plugin Scoped Data Storage (KV)
4+
---
5+
6+
Plugin Scoped Data Storage (KV)
7+
8+
## Properties
9+
10+
| Property | Type | Required | Description |
11+
| :--- | :--- | :--- | :--- |
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"$ref": "#/definitions/I18nContext",
3+
"definitions": {
4+
"I18nContext": {
5+
"type": "object",
6+
"properties": {},
7+
"additionalProperties": false,
8+
"description": "Internationalization Helper"
9+
}
10+
},
11+
"$schema": "http://json-schema.org/draft-07/schema#"
12+
}

packages/spec/json-schema/Manifest.json

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,55 @@
206206
"additionalProperties": false
207207
},
208208
"description": "Theme contributions"
209+
},
210+
"translations": {
211+
"type": "array",
212+
"items": {
213+
"type": "object",
214+
"properties": {
215+
"locale": {
216+
"type": "string"
217+
},
218+
"path": {
219+
"type": "string"
220+
}
221+
},
222+
"required": [
223+
"locale",
224+
"path"
225+
],
226+
"additionalProperties": false
227+
},
228+
"description": "Translation resources"
229+
},
230+
"actions": {
231+
"type": "array",
232+
"items": {
233+
"type": "object",
234+
"properties": {
235+
"name": {
236+
"type": "string",
237+
"description": "Unique action name"
238+
},
239+
"label": {
240+
"type": "string"
241+
},
242+
"description": {
243+
"type": "string"
244+
},
245+
"input": {
246+
"description": "Input validation schema"
247+
},
248+
"output": {
249+
"description": "Output schema"
250+
}
251+
},
252+
"required": [
253+
"name"
254+
],
255+
"additionalProperties": false
256+
},
257+
"description": "Exposed server actions"
209258
}
210259
},
211260
"additionalProperties": false,

packages/spec/json-schema/PluginContext.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@
3535
"additionalProperties": false,
3636
"description": "Structured Logger"
3737
},
38+
"storage": {
39+
"type": "object",
40+
"properties": {},
41+
"additionalProperties": false,
42+
"description": "Plugin Scoped Data Storage (KV)"
43+
},
44+
"i18n": {
45+
"type": "object",
46+
"properties": {},
47+
"additionalProperties": false,
48+
"description": "Internationalization Helper"
49+
},
3850
"metadata": {
3951
"description": "Metadata registry"
4052
},
@@ -68,6 +80,8 @@
6880
"ql",
6981
"os",
7082
"logger",
83+
"storage",
84+
"i18n",
7185
"app"
7286
],
7387
"additionalProperties": false
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"$ref": "#/definitions/ScopedStorage",
3+
"definitions": {
4+
"ScopedStorage": {
5+
"type": "object",
6+
"properties": {},
7+
"additionalProperties": false,
8+
"description": "Plugin Scoped Data Storage (KV)"
9+
}
10+
},
11+
"$schema": "http://json-schema.org/draft-07/schema#"
12+
}

packages/spec/src/system/manifest.zod.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,27 @@ export const ManifestSchema = z.object({
116116
label: z.string(),
117117
path: z.string(),
118118
})).optional().describe('Theme contributions'),
119+
120+
/**
121+
* Register Translations.
122+
* Path to translation files (e.g. "locales/en.json").
123+
*/
124+
translations: z.array(z.object({
125+
locale: z.string(),
126+
path: z.string(),
127+
})).optional().describe('Translation resources'),
128+
129+
/**
130+
* Register Server Actions.
131+
* Invocable functions exposed to Flows or API.
132+
*/
133+
actions: z.array(z.object({
134+
name: z.string().describe('Unique action name'),
135+
label: z.string().optional(),
136+
description: z.string().optional(),
137+
input: z.any().optional().describe('Input validation schema'),
138+
output: z.any().optional().describe('Output schema'),
139+
})).optional().describe('Exposed server actions'),
119140
}).optional().describe('Platform contributions'),
120141

121142
/**

packages/spec/src/system/plugin.zod.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ export const SystemAPISchema = z.object({
3030
getConfig: z.function().args(z.string()).returns(z.promise(z.any())),
3131
}).describe('Access to System Core');
3232

33+
export const ScopedStorageSchema = z.object({
34+
get: z.function().args(z.string()).returns(z.promise(z.any())).describe('Get value by key'),
35+
set: z.function().args(z.string(), z.any()).returns(z.promise(z.void())).describe('Set value for key'),
36+
delete: z.function().args(z.string()).returns(z.promise(z.void())).describe('Delete key'),
37+
}).describe('Plugin Scoped Data Storage (KV)');
38+
39+
export const I18nContextSchema = z.object({
40+
t: z.function().args(z.string(), z.record(z.any()).optional()).returns(z.string()).describe('Translate a key'),
41+
getLocale: z.function().returns(z.string()).describe('Get current context locale'),
42+
}).describe('Internationalization Helper');
43+
3344
/**
3445
* Plugin Context Schema
3546
*
@@ -76,6 +87,23 @@ export const PluginContextSchema = z.object({
7687
*/
7788
logger: LoggerSchema,
7889

90+
/**
91+
* Scoped Storage.
92+
* Key-Value store isolated for this plugin.
93+
*
94+
* @example
95+
* await context.storage.set('last_sync', Date.now());
96+
*/
97+
storage: ScopedStorageSchema,
98+
99+
/**
100+
* I18n Helper.
101+
*
102+
* @example
103+
* const msg = context.i18n.t('error.invalid_input');
104+
*/
105+
i18n: I18nContextSchema,
106+
79107
/**
80108
* Metadata registry.
81109
* Provides access to system metadata like object schemas, field definitions, etc.

0 commit comments

Comments
 (0)