@done-coding/schema-api 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 +21 -0
- package/README.md +33 -2
- package/es/index.mjs +929 -0
- package/lib/index.cjs +1 -0
- package/package.json +60 -3
- package/schemas/bounded-list.schema.json +17 -0
- package/schemas/common-error-codes.schema.json +224 -0
- package/schemas/cursor-list-request.schema.json +24 -0
- package/schemas/cursor-list.schema.json +45 -0
- package/schemas/error-body.schema.json +109 -0
- package/schemas/list-filter.schema.json +28 -0
- package/schemas/paged-list-request.schema.json +36 -0
- package/schemas/paged-list.schema.json +52 -0
- package/schemas/service-error-codes.schema.json +97 -0
- package/schemas/success-envelope.schema.json +25 -0
- package/types/index.d.ts +515 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "service-error-codes.schema.json",
|
|
4
|
+
"title": "ServiceErrorCodes",
|
|
5
|
+
"description": "一个服务的专有业务码清单。不得重新定义通用码;OK 与 HTTP_<数字> 形式的码保留,不得使用;比较按字节精确进行,不做大小写归一。",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"service": {
|
|
9
|
+
"description": "服务标识:小写字母开头,只含小写字母、数字、短横线,最长 64 个字符。",
|
|
10
|
+
"type": "string",
|
|
11
|
+
"pattern": "^[a-z][a-z0-9\\-]{0,63}$"
|
|
12
|
+
},
|
|
13
|
+
"codes": {
|
|
14
|
+
"description": "专有码,至少 1 项;code 在清单内不重复(x-uniqueItemsBy)。",
|
|
15
|
+
"type": "array",
|
|
16
|
+
"minItems": 1,
|
|
17
|
+
"items": { "$ref": "#/$defs/code" },
|
|
18
|
+
"x-uniqueItemsBy": "code"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"required": ["service", "codes"],
|
|
22
|
+
"additionalProperties": false,
|
|
23
|
+
"$defs": {
|
|
24
|
+
"code": {
|
|
25
|
+
"title": "ServiceErrorCode",
|
|
26
|
+
"description": "一个专有码。stage 为 execute 时不得有 httpStatus 与 additionalHttpStatuses;为 accept 或 both 时必须有 httpStatus。additionalHttpStatuses 不含主状态(x-arrayExcludesProperty)。",
|
|
27
|
+
"type": "object",
|
|
28
|
+
"properties": {
|
|
29
|
+
"code": {
|
|
30
|
+
"description": "码:整体大写下划线或整体小写下划线写法,字母开头,不以下划线结尾,不含连续下划线,最长 128 个字符。",
|
|
31
|
+
"type": "string",
|
|
32
|
+
"maxLength": 128,
|
|
33
|
+
"pattern": "^(?:[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*|[a-z][a-z0-9]*(?:_[a-z0-9]+)*)$",
|
|
34
|
+
"allOf": [
|
|
35
|
+
{ "not": { "const": "OK" } },
|
|
36
|
+
{ "not": { "type": "string", "pattern": "^HTTP_[0-9]+$" } },
|
|
37
|
+
{ "not": { "$ref": "common-error-codes.schema.json#/$defs/code" } }
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
"stage": {
|
|
41
|
+
"description": "accept:受理时同步返回;execute:异步执行阶段产生;both:两者都有。",
|
|
42
|
+
"enum": ["accept", "execute", "both"]
|
|
43
|
+
},
|
|
44
|
+
"httpStatus": {
|
|
45
|
+
"description": "主 HTTP 状态,4xx 或 5xx。",
|
|
46
|
+
"type": "integer",
|
|
47
|
+
"minimum": 400,
|
|
48
|
+
"maximum": 599
|
|
49
|
+
},
|
|
50
|
+
"additionalHttpStatuses": {
|
|
51
|
+
"description": "同一个码在不同情形下的其他 HTTP 状态:至少 1 项、不重复、不含主状态。",
|
|
52
|
+
"type": "array",
|
|
53
|
+
"minItems": 1,
|
|
54
|
+
"uniqueItems": true,
|
|
55
|
+
"items": {
|
|
56
|
+
"type": "integer",
|
|
57
|
+
"minimum": 400,
|
|
58
|
+
"maximum": 599
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"retryable": {
|
|
62
|
+
"description": "原样重试是否可能成功。",
|
|
63
|
+
"type": "boolean"
|
|
64
|
+
},
|
|
65
|
+
"outcome": {
|
|
66
|
+
"description": "not_executed:确定没有执行;unknown:可能已产生副作用。",
|
|
67
|
+
"enum": ["not_executed", "unknown"]
|
|
68
|
+
},
|
|
69
|
+
"meaning": {
|
|
70
|
+
"description": "一句话含义,1–1000 个字符。",
|
|
71
|
+
"type": "string",
|
|
72
|
+
"minLength": 1,
|
|
73
|
+
"maxLength": 1000
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"required": ["code", "stage", "retryable", "outcome", "meaning"],
|
|
77
|
+
"additionalProperties": false,
|
|
78
|
+
"if": {
|
|
79
|
+
"properties": { "stage": { "const": "execute" } },
|
|
80
|
+
"required": ["stage"]
|
|
81
|
+
},
|
|
82
|
+
"then": {
|
|
83
|
+
"properties": {
|
|
84
|
+
"httpStatus": false,
|
|
85
|
+
"additionalHttpStatuses": false
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"else": {
|
|
89
|
+
"required": ["httpStatus"]
|
|
90
|
+
},
|
|
91
|
+
"x-arrayExcludesProperty": {
|
|
92
|
+
"array": "additionalHttpStatuses",
|
|
93
|
+
"property": "httpStatus"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "success-envelope.schema.json",
|
|
4
|
+
"title": "SuccessEnvelope",
|
|
5
|
+
"description": "成功外壳。成功与否、新建还是已受理以 HTTP 状态码为准,code 不随 200 / 201 / 202 变化。",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"code": {
|
|
9
|
+
"description": "成功码,恒为 OK。",
|
|
10
|
+
"const": "OK"
|
|
11
|
+
},
|
|
12
|
+
"message": {
|
|
13
|
+
"description": "说明,可以为空串。",
|
|
14
|
+
"type": "string",
|
|
15
|
+
"maxLength": 1000
|
|
16
|
+
},
|
|
17
|
+
"data": {
|
|
18
|
+
"description": "结果对象或 null;标量结果也包成对象(如 {\"count\": 3})。",
|
|
19
|
+
"type": ["object", "null"],
|
|
20
|
+
"additionalProperties": true
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"required": ["code", "message", "data"],
|
|
24
|
+
"additionalProperties": false
|
|
25
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BoundedList 响应里各字段的路径(由定义 bounded-list.schema.json 生成)。
|
|
3
|
+
*/
|
|
4
|
+
export declare const BOUNDED_LIST_RESPONSE_PATHS: {
|
|
5
|
+
readonly items: "items";
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/** 一次性列表,TItem 是元素类型。 */
|
|
9
|
+
export declare interface BoundedList<TItem = unknown> extends Omit<Generated.BoundedList, "items"> {
|
|
10
|
+
items: TItem[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 一次性列表,作成功外壳的 data。只用于条数有一个由定义决定、不随业务数据增长的上限的结果(如下拉选项);上限由各接口在自己的契约里声明,超过上限报 LIST_LIMIT_EXCEEDED,不截断。顶层允许接口自己声明的附带字段,但不得带翻页信息。
|
|
15
|
+
*/
|
|
16
|
+
declare interface BoundedList_2 {
|
|
17
|
+
/**
|
|
18
|
+
* 列表数据。
|
|
19
|
+
*/
|
|
20
|
+
items: unknown[];
|
|
21
|
+
page?: never;
|
|
22
|
+
cursor?: never;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** BoundedList:bounded-list.schema.json */
|
|
26
|
+
export declare const boundedListSchema: SchemaDocument;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 通用失败码 → HTTP 状态、能否重试、是否已执行(outcome)与含义。
|
|
30
|
+
*/
|
|
31
|
+
export declare const COMMON_ERROR_CODE_TABLE: {
|
|
32
|
+
readonly INVALID_REQUEST: {
|
|
33
|
+
readonly httpStatus: 400;
|
|
34
|
+
readonly retryable: false;
|
|
35
|
+
readonly outcome: "not_executed";
|
|
36
|
+
readonly meaning: "请求不符合接口契约";
|
|
37
|
+
};
|
|
38
|
+
readonly UNAUTHENTICATED: {
|
|
39
|
+
readonly httpStatus: 401;
|
|
40
|
+
readonly retryable: false;
|
|
41
|
+
readonly outcome: "not_executed";
|
|
42
|
+
readonly meaning: "未登录,或令牌无效、过期";
|
|
43
|
+
};
|
|
44
|
+
readonly FORBIDDEN: {
|
|
45
|
+
readonly httpStatus: 403;
|
|
46
|
+
readonly retryable: false;
|
|
47
|
+
readonly outcome: "not_executed";
|
|
48
|
+
readonly meaning: "已认证但无权执行";
|
|
49
|
+
};
|
|
50
|
+
readonly NOT_FOUND: {
|
|
51
|
+
readonly httpStatus: 404;
|
|
52
|
+
readonly retryable: false;
|
|
53
|
+
readonly outcome: "not_executed";
|
|
54
|
+
readonly meaning: "资源不存在,或调用方无权得知其存在";
|
|
55
|
+
};
|
|
56
|
+
readonly ROUTE_NOT_FOUND: {
|
|
57
|
+
readonly httpStatus: 404;
|
|
58
|
+
readonly retryable: false;
|
|
59
|
+
readonly outcome: "not_executed";
|
|
60
|
+
readonly meaning: "接口路径不存在";
|
|
61
|
+
};
|
|
62
|
+
readonly METHOD_NOT_ALLOWED: {
|
|
63
|
+
readonly httpStatus: 405;
|
|
64
|
+
readonly retryable: false;
|
|
65
|
+
readonly outcome: "not_executed";
|
|
66
|
+
readonly meaning: "接口不支持该 HTTP 方法";
|
|
67
|
+
};
|
|
68
|
+
readonly CONFLICT: {
|
|
69
|
+
readonly httpStatus: 409;
|
|
70
|
+
readonly retryable: false;
|
|
71
|
+
readonly outcome: "not_executed";
|
|
72
|
+
readonly meaning: "资源状态冲突";
|
|
73
|
+
};
|
|
74
|
+
readonly RATE_LIMITED: {
|
|
75
|
+
readonly httpStatus: 429;
|
|
76
|
+
readonly retryable: true;
|
|
77
|
+
readonly outcome: "not_executed";
|
|
78
|
+
readonly meaning: "请求过于频繁,可稍后重试";
|
|
79
|
+
};
|
|
80
|
+
readonly INTERNAL_ERROR: {
|
|
81
|
+
readonly httpStatus: 500;
|
|
82
|
+
readonly retryable: false;
|
|
83
|
+
readonly outcome: "unknown";
|
|
84
|
+
readonly meaning: "服务内部错误,可能已产生副作用";
|
|
85
|
+
};
|
|
86
|
+
readonly LIST_LIMIT_EXCEEDED: {
|
|
87
|
+
readonly httpStatus: 500;
|
|
88
|
+
readonly retryable: false;
|
|
89
|
+
readonly outcome: "unknown";
|
|
90
|
+
readonly meaning: "一次性列表的结果超出接口声明的上限";
|
|
91
|
+
};
|
|
92
|
+
readonly SERVICE_UNAVAILABLE: {
|
|
93
|
+
readonly httpStatus: 503;
|
|
94
|
+
readonly retryable: true;
|
|
95
|
+
readonly outcome: "unknown";
|
|
96
|
+
readonly meaning: "服务或其依赖暂不可用";
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* 通用失败码。错误体的 code 是开放字符串,这里只列通用的一组;
|
|
102
|
+
* 各服务可以有自己的专有码,遇到不认识的码按 HTTP 状态归类处理。
|
|
103
|
+
*/
|
|
104
|
+
export declare const COMMON_ERROR_CODES: {
|
|
105
|
+
readonly INVALID_REQUEST: "INVALID_REQUEST";
|
|
106
|
+
readonly UNAUTHENTICATED: "UNAUTHENTICATED";
|
|
107
|
+
readonly FORBIDDEN: "FORBIDDEN";
|
|
108
|
+
readonly NOT_FOUND: "NOT_FOUND";
|
|
109
|
+
readonly ROUTE_NOT_FOUND: "ROUTE_NOT_FOUND";
|
|
110
|
+
readonly METHOD_NOT_ALLOWED: "METHOD_NOT_ALLOWED";
|
|
111
|
+
readonly CONFLICT: "CONFLICT";
|
|
112
|
+
readonly RATE_LIMITED: "RATE_LIMITED";
|
|
113
|
+
readonly INTERNAL_ERROR: "INTERNAL_ERROR";
|
|
114
|
+
readonly LIST_LIMIT_EXCEEDED: "LIST_LIMIT_EXCEEDED";
|
|
115
|
+
readonly SERVICE_UNAVAILABLE: "SERVICE_UNAVAILABLE";
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export declare type CommonErrorCode = (typeof COMMON_ERROR_CODES)[keyof typeof COMMON_ERROR_CODES];
|
|
119
|
+
|
|
120
|
+
/** CommonErrorCodes:common-error-codes.schema.json */
|
|
121
|
+
export declare const commonErrorCodesSchema: SchemaDocument;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* CursorListRequest 的线上参数名(由定义 cursor-list-request.schema.json 生成)。
|
|
125
|
+
*/
|
|
126
|
+
export declare const CURSOR_LIST_REQUEST_PARAMS: {
|
|
127
|
+
readonly after: "cursor.after";
|
|
128
|
+
readonly limit: "cursor.limit";
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* CursorList 响应里各字段的路径(由定义 cursor-list.schema.json 生成)。
|
|
133
|
+
*/
|
|
134
|
+
export declare const CURSOR_LIST_RESPONSE_PATHS: {
|
|
135
|
+
readonly items: "items";
|
|
136
|
+
readonly next: "cursor.next";
|
|
137
|
+
readonly hasMore: "cursor.hasMore";
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
/** 游标式列表,TItem 是元素类型。 */
|
|
141
|
+
export declare interface CursorList<TItem = unknown> extends Omit<Generated.CursorList, "items"> {
|
|
142
|
+
items: TItem[];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* 游标式列表,作成功外壳的 data:消息流这类接着往下取的列表,不带总数。取数方向由各接口声明。顶层允许接口自己声明的附带字段,但不得重复表达翻页信息;不带 page。
|
|
147
|
+
*/
|
|
148
|
+
declare interface CursorList_2 {
|
|
149
|
+
/**
|
|
150
|
+
* 本批数据。
|
|
151
|
+
*/
|
|
152
|
+
items: unknown[];
|
|
153
|
+
cursor: CursorListCursor;
|
|
154
|
+
page?: never;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 接着取的位置。hasMore 为 true 时必须给 next。
|
|
159
|
+
*/
|
|
160
|
+
export declare interface CursorListCursor {
|
|
161
|
+
/**
|
|
162
|
+
* 下一批的游标,对调用方不透明,1–1024 个字符;没有更多时可省略。
|
|
163
|
+
*/
|
|
164
|
+
next?: string;
|
|
165
|
+
/**
|
|
166
|
+
* 是否还有更多。
|
|
167
|
+
*/
|
|
168
|
+
hasMore: boolean;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* 游标式列表的请求参数。线上以 cursor. 前缀的查询参数传递(如 cursor.limit=20),本定义约束解码后的对象;前缀下未声明的参数不合法。
|
|
173
|
+
*/
|
|
174
|
+
export declare interface CursorListRequest {
|
|
175
|
+
/**
|
|
176
|
+
* 上一批返回的 next,1–1024 个字符;首批不带。
|
|
177
|
+
*/
|
|
178
|
+
after?: string;
|
|
179
|
+
/**
|
|
180
|
+
* 本批最多取多少条;缺省值由各接口自定。
|
|
181
|
+
*/
|
|
182
|
+
limit?: number;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** CursorListRequest:cursor-list-request.schema.json */
|
|
186
|
+
export declare const cursorListRequestSchema: SchemaDocument;
|
|
187
|
+
|
|
188
|
+
/** CursorList:cursor-list.schema.json */
|
|
189
|
+
export declare const cursorListSchema: SchemaDocument;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* 错误体。HTTP 状态表达大类,包体带业务码、说明、能否重试、是否已执行与出错字段定位。code 是通用失败码时,retryable 与 outcome 必须与通用失败码表一致。
|
|
193
|
+
*/
|
|
194
|
+
export declare interface ErrorBody {
|
|
195
|
+
/**
|
|
196
|
+
* 业务码,开放字符串:字母开头,只含字母、数字、下划线,1–128 个字符;不能是 OK。使用方遇到不认识的码按 HTTP 状态归类处理。
|
|
197
|
+
*/
|
|
198
|
+
code: string;
|
|
199
|
+
/**
|
|
200
|
+
* 说明,不能是纯空白。
|
|
201
|
+
*/
|
|
202
|
+
message: string;
|
|
203
|
+
/**
|
|
204
|
+
* 错误体恒为 null。
|
|
205
|
+
*/
|
|
206
|
+
data: null;
|
|
207
|
+
error: ErrorDetail;
|
|
208
|
+
/**
|
|
209
|
+
* 请求标识,1–128 个字符,不含空白字符。
|
|
210
|
+
*/
|
|
211
|
+
requestId: string;
|
|
212
|
+
/**
|
|
213
|
+
* 补充说明,可选,不限长。
|
|
214
|
+
*/
|
|
215
|
+
detail?: string;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** ErrorBody:error-body.schema.json */
|
|
219
|
+
export declare const errorBodySchema: SchemaDocument;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* 错误的处置信息。
|
|
223
|
+
*/
|
|
224
|
+
export declare interface ErrorDetail {
|
|
225
|
+
/**
|
|
226
|
+
* 原样重试是否可能成功。
|
|
227
|
+
*/
|
|
228
|
+
retryable: boolean;
|
|
229
|
+
/**
|
|
230
|
+
* not_executed:确定没有执行;unknown:可能已产生副作用。
|
|
231
|
+
*/
|
|
232
|
+
outcome: "not_executed" | "unknown";
|
|
233
|
+
/**
|
|
234
|
+
* 逐项指出出错的输入;可以是空数组。
|
|
235
|
+
*/
|
|
236
|
+
fields?: ErrorField[];
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* 一项出错的输入。in 为 body 时用 pointer 定位、不能有 parameter;其他位置用 parameter 定位、不能有 pointer。
|
|
241
|
+
*/
|
|
242
|
+
export declare interface ErrorField {
|
|
243
|
+
/**
|
|
244
|
+
* 出错输入所在的位置。
|
|
245
|
+
*/
|
|
246
|
+
in: "body" | "query" | "path" | "header" | "cookie";
|
|
247
|
+
/**
|
|
248
|
+
* 字段级错误码:字母开头,只含字母、数字、下划线、点、短横线,1–128 个字符。
|
|
249
|
+
*/
|
|
250
|
+
code: string;
|
|
251
|
+
/**
|
|
252
|
+
* 说明,不能是纯空白。
|
|
253
|
+
*/
|
|
254
|
+
message: string;
|
|
255
|
+
/**
|
|
256
|
+
* 请求体内的位置,RFC 6901 JSON Pointer。
|
|
257
|
+
*/
|
|
258
|
+
pointer?: string;
|
|
259
|
+
/**
|
|
260
|
+
* 参数名,1–256 个字符。
|
|
261
|
+
*/
|
|
262
|
+
parameter?: string;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
declare namespace Generated {
|
|
266
|
+
export {
|
|
267
|
+
BoundedList_2 as BoundedList,
|
|
268
|
+
CursorListRequest,
|
|
269
|
+
CursorList_2 as CursorList,
|
|
270
|
+
CursorListCursor,
|
|
271
|
+
ErrorBody,
|
|
272
|
+
ErrorDetail,
|
|
273
|
+
ErrorField,
|
|
274
|
+
ListFilter,
|
|
275
|
+
ListFilterCondition,
|
|
276
|
+
PagedListRequest,
|
|
277
|
+
PagedList_2 as PagedList,
|
|
278
|
+
PagedListPage,
|
|
279
|
+
ServiceErrorCodes,
|
|
280
|
+
ServiceErrorCode,
|
|
281
|
+
SuccessEnvelope_2 as SuccessEnvelope
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* ListFilter 的线上参数名(由定义 list-filter.schema.json 生成)。
|
|
287
|
+
*/
|
|
288
|
+
export declare const LIST_FILTER_PARAMS: {
|
|
289
|
+
readonly prefix: "filter.";
|
|
290
|
+
readonly operators: {
|
|
291
|
+
readonly eq: "eq";
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* 列表的筛选参数。线上写作 filter.<字段>.<操作>(如 filter.status.eq=active),本定义约束解码后的对象 {<字段>: {<操作>: 值}};字段为小驼峰,可筛选哪些字段由接口自己声明。首版操作只有 eq。前缀下未声明的参数不合法。
|
|
297
|
+
*/
|
|
298
|
+
export declare interface ListFilter {
|
|
299
|
+
[k: string]: ListFilterCondition;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* 一个字段上的筛选条件,至少一个操作。
|
|
304
|
+
*
|
|
305
|
+
* This interface was referenced by `ListFilter`'s JSON-Schema definition
|
|
306
|
+
* via the `patternProperty` "^[a-z][a-zA-Z0-9]*$".
|
|
307
|
+
*/
|
|
308
|
+
export declare interface ListFilterCondition {
|
|
309
|
+
/**
|
|
310
|
+
* 等于;值为标量。
|
|
311
|
+
*/
|
|
312
|
+
eq?: string | number | boolean;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** ListFilter:list-filter.schema.json */
|
|
316
|
+
export declare const listFilterSchema: SchemaDocument;
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* PagedListRequest 的线上参数名(由定义 paged-list-request.schema.json 生成)。
|
|
320
|
+
*/
|
|
321
|
+
export declare const PAGED_LIST_REQUEST_PARAMS: {
|
|
322
|
+
readonly page: "page.page";
|
|
323
|
+
readonly pageSize: "page.pageSize";
|
|
324
|
+
readonly query: "page.query";
|
|
325
|
+
readonly orderBy: "page.orderBy";
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* PagedList 响应里各字段的路径(由定义 paged-list.schema.json 生成)。
|
|
330
|
+
*/
|
|
331
|
+
export declare const PAGED_LIST_RESPONSE_PATHS: {
|
|
332
|
+
readonly items: "items";
|
|
333
|
+
readonly totalRecord: "page.totalRecord";
|
|
334
|
+
readonly pageSize: "page.pageSize";
|
|
335
|
+
readonly totalPage: "page.totalPage";
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
/** 页码式列表,TItem 是元素类型。 */
|
|
339
|
+
export declare interface PagedList<TItem = unknown> extends Omit<Generated.PagedList, "items"> {
|
|
340
|
+
items: TItem[];
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* 页码式列表,作成功外壳的 data:给人翻页的表格,能跳页、有总数。顶层允许接口自己声明的附带字段,但不得重复表达翻页信息;不带 cursor。
|
|
345
|
+
*/
|
|
346
|
+
declare interface PagedList_2 {
|
|
347
|
+
/**
|
|
348
|
+
* 当前页的数据。
|
|
349
|
+
*/
|
|
350
|
+
items: unknown[];
|
|
351
|
+
page: PagedListPage;
|
|
352
|
+
cursor?: never;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* 翻页信息。不回传当前页码。totalPage 等于 ceil(totalRecord / pageSize),总数为 0 时为 0(x-totalPageEqualsCeil)。
|
|
357
|
+
*/
|
|
358
|
+
export declare interface PagedListPage {
|
|
359
|
+
/**
|
|
360
|
+
* 总条数。
|
|
361
|
+
*/
|
|
362
|
+
totalRecord: number;
|
|
363
|
+
/**
|
|
364
|
+
* 每页条数,回显请求值。
|
|
365
|
+
*/
|
|
366
|
+
pageSize: number;
|
|
367
|
+
/**
|
|
368
|
+
* 总页数。
|
|
369
|
+
*/
|
|
370
|
+
totalPage: number;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* 页码式列表的请求参数。线上以 page. 前缀的查询参数传递(如 page.pageSize=20),本定义约束解码后的对象;前缀下未声明的参数不合法。
|
|
375
|
+
*/
|
|
376
|
+
export declare interface PagedListRequest {
|
|
377
|
+
/**
|
|
378
|
+
* 页码,从 1 开始。
|
|
379
|
+
*/
|
|
380
|
+
page?: number;
|
|
381
|
+
/**
|
|
382
|
+
* 每页条数。
|
|
383
|
+
*/
|
|
384
|
+
pageSize?: number;
|
|
385
|
+
/**
|
|
386
|
+
* 模糊搜索词,最多 200 个字符。
|
|
387
|
+
*/
|
|
388
|
+
query?: string;
|
|
389
|
+
/**
|
|
390
|
+
* 排序:逗号分隔,每段是小驼峰字段名,后面可跟一个空格加 asc 或 desc(缺省 asc);逗号后可有一个空格;最多 200 个字符。
|
|
391
|
+
*/
|
|
392
|
+
orderBy?: string;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/** PagedListRequest:paged-list-request.schema.json */
|
|
396
|
+
export declare const pagedListRequestSchema: SchemaDocument;
|
|
397
|
+
|
|
398
|
+
/** PagedList:paged-list.schema.json */
|
|
399
|
+
export declare const pagedListSchema: SchemaDocument;
|
|
400
|
+
|
|
401
|
+
/** 一份 JSON Schema 定义文档。 */
|
|
402
|
+
export declare interface SchemaDocument {
|
|
403
|
+
readonly [keyword: string]: unknown;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/** 全部定义,键为定义的 $id(即文件名),可整体登记到校验器里。 */
|
|
407
|
+
export declare const schemas: {
|
|
408
|
+
readonly "bounded-list.schema.json": SchemaDocument;
|
|
409
|
+
readonly "common-error-codes.schema.json": SchemaDocument;
|
|
410
|
+
readonly "cursor-list-request.schema.json": SchemaDocument;
|
|
411
|
+
readonly "cursor-list.schema.json": SchemaDocument;
|
|
412
|
+
readonly "error-body.schema.json": SchemaDocument;
|
|
413
|
+
readonly "list-filter.schema.json": SchemaDocument;
|
|
414
|
+
readonly "paged-list-request.schema.json": SchemaDocument;
|
|
415
|
+
readonly "paged-list.schema.json": SchemaDocument;
|
|
416
|
+
readonly "service-error-codes.schema.json": SchemaDocument;
|
|
417
|
+
readonly "success-envelope.schema.json": SchemaDocument;
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
/**
|
|
421
|
+
* 一个专有码。stage 为 execute 时不得有 httpStatus 与 additionalHttpStatuses;为 accept 或 both 时必须有 httpStatus。additionalHttpStatuses 不含主状态(x-arrayExcludesProperty)。
|
|
422
|
+
*/
|
|
423
|
+
export declare interface ServiceErrorCode {
|
|
424
|
+
/**
|
|
425
|
+
* 码:整体大写下划线或整体小写下划线写法,字母开头,不以下划线结尾,不含连续下划线,最长 128 个字符。
|
|
426
|
+
*/
|
|
427
|
+
code: string;
|
|
428
|
+
/**
|
|
429
|
+
* accept:受理时同步返回;execute:异步执行阶段产生;both:两者都有。
|
|
430
|
+
*/
|
|
431
|
+
stage: "accept" | "execute" | "both";
|
|
432
|
+
/**
|
|
433
|
+
* 主 HTTP 状态,4xx 或 5xx。
|
|
434
|
+
*/
|
|
435
|
+
httpStatus?: number;
|
|
436
|
+
/**
|
|
437
|
+
* 同一个码在不同情形下的其他 HTTP 状态:至少 1 项、不重复、不含主状态。
|
|
438
|
+
*
|
|
439
|
+
* @minItems 1
|
|
440
|
+
*/
|
|
441
|
+
additionalHttpStatuses?: [number, ...number[]];
|
|
442
|
+
/**
|
|
443
|
+
* 原样重试是否可能成功。
|
|
444
|
+
*/
|
|
445
|
+
retryable: boolean;
|
|
446
|
+
/**
|
|
447
|
+
* not_executed:确定没有执行;unknown:可能已产生副作用。
|
|
448
|
+
*/
|
|
449
|
+
outcome: "not_executed" | "unknown";
|
|
450
|
+
/**
|
|
451
|
+
* 一句话含义,1–1000 个字符。
|
|
452
|
+
*/
|
|
453
|
+
meaning: string;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* 一个服务的专有业务码清单。不得重新定义通用码;OK 与 HTTP_<数字> 形式的码保留,不得使用;比较按字节精确进行,不做大小写归一。
|
|
458
|
+
*/
|
|
459
|
+
export declare interface ServiceErrorCodes {
|
|
460
|
+
/**
|
|
461
|
+
* 服务标识:小写字母开头,只含小写字母、数字、短横线,最长 64 个字符。
|
|
462
|
+
*/
|
|
463
|
+
service: string;
|
|
464
|
+
/**
|
|
465
|
+
* 专有码,至少 1 项;code 在清单内不重复(x-uniqueItemsBy)。
|
|
466
|
+
*
|
|
467
|
+
* @minItems 1
|
|
468
|
+
*/
|
|
469
|
+
codes: [ServiceErrorCode, ...ServiceErrorCode[]];
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/** ServiceErrorCodes:service-error-codes.schema.json */
|
|
473
|
+
export declare const serviceErrorCodesSchema: SchemaDocument;
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* 成功码。成功外壳的 code 只能是这一组里的值。
|
|
477
|
+
*/
|
|
478
|
+
export declare const SUCCESS_CODES: {
|
|
479
|
+
readonly OK: "OK";
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
export declare type SuccessCode = (typeof SUCCESS_CODES)[keyof typeof SUCCESS_CODES];
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* 成功外壳。TData 是结果对象的类型(或 null);标量结果也要包成对象。
|
|
486
|
+
* 约束写作 object 而非索引签名类型,是为了让 interface 声明的资源类型也能直接传入。
|
|
487
|
+
*/
|
|
488
|
+
export declare interface SuccessEnvelope<TData extends object | null = Generated.SuccessEnvelope["data"]> extends Omit<Generated.SuccessEnvelope, "data"> {
|
|
489
|
+
data: TData;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* 成功外壳。成功与否、新建还是已受理以 HTTP 状态码为准,code 不随 200 / 201 / 202 变化。
|
|
494
|
+
*/
|
|
495
|
+
declare interface SuccessEnvelope_2 {
|
|
496
|
+
/**
|
|
497
|
+
* 成功码,恒为 OK。
|
|
498
|
+
*/
|
|
499
|
+
code: "OK";
|
|
500
|
+
/**
|
|
501
|
+
* 说明,可以为空串。
|
|
502
|
+
*/
|
|
503
|
+
message: string;
|
|
504
|
+
/**
|
|
505
|
+
* 结果对象或 null;标量结果也包成对象(如 {"count": 3})。
|
|
506
|
+
*/
|
|
507
|
+
data: {
|
|
508
|
+
[k: string]: unknown;
|
|
509
|
+
} | null;
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/** SuccessEnvelope:success-envelope.schema.json */
|
|
513
|
+
export declare const successEnvelopeSchema: SchemaDocument;
|
|
514
|
+
|
|
515
|
+
export { }
|