Skip to content

Commit 888cfb0

Browse files
committed
feat: 添加 ApiMethod 枚举及其 JSON Schema 定义,更新相关类型以支持 API 操作
1 parent 9566a83 commit 888cfb0

3 files changed

Lines changed: 66 additions & 14 deletions

File tree

content/docs/references/data/object.mdx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,36 @@ description: Object protocol schemas
1212
## TypeScript Usage
1313

1414
```typescript
15-
import { CDCConfigSchema, IndexSchema, ObjectSchema, ObjectCapabilitiesSchema, PartitioningConfigSchema, SoftDeleteConfigSchema, TenancyConfigSchema, VersioningConfigSchema } from '@objectstack/spec/data';
16-
import type { CDCConfig, Index, Object, ObjectCapabilities, PartitioningConfig, SoftDeleteConfig, TenancyConfig, VersioningConfig } from '@objectstack/spec/data';
15+
import { ApiMethodSchema, CDCConfigSchema, IndexSchema, ObjectSchema, ObjectCapabilitiesSchema, PartitioningConfigSchema, SoftDeleteConfigSchema, TenancyConfigSchema, VersioningConfigSchema } from '@objectstack/spec/data';
16+
import type { ApiMethod, CDCConfig, Index, Object, ObjectCapabilities, PartitioningConfig, SoftDeleteConfig, TenancyConfig, VersioningConfig } from '@objectstack/spec/data';
1717

1818
// Validate data
19-
const result = CDCConfigSchema.parse(data);
19+
const result = ApiMethodSchema.parse(data);
2020
```
2121

2222
---
2323

24+
## ApiMethod
25+
26+
### Allowed Values
27+
28+
* `get`
29+
* `list`
30+
* `create`
31+
* `update`
32+
* `delete`
33+
* `upsert`
34+
* `bulk`
35+
* `aggregate`
36+
* `history`
37+
* `search`
38+
* `restore`
39+
* `purge`
40+
* `import`
41+
* `export`
42+
43+
---
44+
2445
## CDCConfig
2546

2647
### Properties
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"$ref": "#/definitions/ApiMethod",
3+
"definitions": {
4+
"ApiMethod": {
5+
"type": "string",
6+
"enum": [
7+
"get",
8+
"list",
9+
"create",
10+
"update",
11+
"delete",
12+
"upsert",
13+
"bulk",
14+
"aggregate",
15+
"history",
16+
"search",
17+
"restore",
18+
"purge",
19+
"import",
20+
"export"
21+
]
22+
}
23+
},
24+
"$schema": "http://json-schema.org/draft-07/schema#"
25+
}

packages/spec/src/data/object.zod.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@ import { z } from 'zod';
22
import { FieldSchema } from './field.zod';
33
import { ValidationRuleSchema } from './validation.zod';
44

5+
/**
6+
* API Operations Enum
7+
*/
8+
export const ApiMethod = z.enum([
9+
'get', 'list', // Read
10+
'create', 'update', 'delete', // Write
11+
'upsert', // Idempotent Write
12+
'bulk', // Batch operations
13+
'aggregate', // Analytics (count, sum)
14+
'history', // Audit access
15+
'search', // Search access
16+
'restore', 'purge', // Trash management
17+
'import', 'export', // Data portability
18+
]);
19+
export type ApiMethod = z.infer<typeof ApiMethod>;
20+
521
/**
622
* Capability Flags
723
* Defines what system features are enabled for this object.
@@ -26,17 +42,7 @@ export const ObjectCapabilities = z.object({
2642
* API Supported Operations
2743
* Granular control over API exposure.
2844
*/
29-
apiMethods: z.array(z.enum([
30-
'get', 'list', // Read
31-
'create', 'update', 'delete', // Write
32-
'upsert', // Idempotent Write
33-
'bulk', // Batch operations
34-
'aggregate', // Analytics (count, sum)
35-
'history', // Audit access
36-
'search', // Search access
37-
'restore', 'purge', // Trash management
38-
'import', 'export', // Data portability
39-
])).optional().describe('Whitelist of allowed API operations'),
45+
apiMethods: z.array(ApiMethod).optional().describe('Whitelist of allowed API operations'),
4046

4147
/** Enable standard attachments/files engine */
4248
files: z.boolean().default(false).describe('Enable file attachments and document management'),

0 commit comments

Comments
 (0)