@done-coding/schema-api 0.0.1-alpha.0 → 0.0.1-alpha.1

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/es/index.mjs CHANGED
@@ -88,17 +88,17 @@ const d = {
88
88
  items: "items",
89
89
  next: "cursor.next",
90
90
  hasMore: "cursor.hasMore"
91
- }, S = {
91
+ }, f = {
92
92
  prefix: "filter.",
93
93
  operators: {
94
94
  eq: "eq"
95
95
  }
96
- }, _ = {
96
+ }, g = {
97
97
  page: "page.page",
98
98
  pageSize: "page.pageSize",
99
99
  query: "page.query",
100
100
  orderBy: "page.orderBy"
101
- }, T = {
101
+ }, S = {
102
102
  items: "items",
103
103
  totalRecord: "page.totalRecord",
104
104
  pageSize: "page.pageSize",
@@ -123,7 +123,7 @@ const d = {
123
123
  $schema: "https://json-schema.org/draft/2020-12/schema",
124
124
  $id: "common-error-codes.schema.json",
125
125
  title: "CommonErrorCodes",
126
- description: "通用失败码表:每个码固定 HTTP 状态(x-httpStatus)、能否重试与是否已执行。作为约束使用时(错误体引用它):code 是通用失败码时,error.retryable 与 error.outcome 必须与本表一致。$defs/code 列出全部通用失败码,须与 allOf 各项一一对应。",
126
+ description: "通用失败码表:每个码固定 HTTP 状态(x-httpStatus),并给出能否重试与是否已执行的缺省值(default)。错误体引用本表:code 是通用失败码时,服务未另行指定 error.retryable 与 error.outcome 就取表中值;服务能确定更具体的重试性或执行结局时可以覆盖,任何合法的 retryable 与 outcome 都合法。$defs/code 列出全部通用失败码,须与 allOf 各项一一对应。",
127
127
  $defs: {
128
128
  code: {
129
129
  description: "通用失败码。",
@@ -159,10 +159,10 @@ const d = {
159
159
  error: {
160
160
  properties: {
161
161
  retryable: {
162
- const: !1
162
+ default: !1
163
163
  },
164
164
  outcome: {
165
- const: "not_executed"
165
+ default: "not_executed"
166
166
  }
167
167
  }
168
168
  }
@@ -185,10 +185,10 @@ const d = {
185
185
  error: {
186
186
  properties: {
187
187
  retryable: {
188
- const: !1
188
+ default: !1
189
189
  },
190
190
  outcome: {
191
- const: "not_executed"
191
+ default: "not_executed"
192
192
  }
193
193
  }
194
194
  }
@@ -211,10 +211,10 @@ const d = {
211
211
  error: {
212
212
  properties: {
213
213
  retryable: {
214
- const: !1
214
+ default: !1
215
215
  },
216
216
  outcome: {
217
- const: "not_executed"
217
+ default: "not_executed"
218
218
  }
219
219
  }
220
220
  }
@@ -237,10 +237,10 @@ const d = {
237
237
  error: {
238
238
  properties: {
239
239
  retryable: {
240
- const: !1
240
+ default: !1
241
241
  },
242
242
  outcome: {
243
- const: "not_executed"
243
+ default: "not_executed"
244
244
  }
245
245
  }
246
246
  }
@@ -263,10 +263,10 @@ const d = {
263
263
  error: {
264
264
  properties: {
265
265
  retryable: {
266
- const: !1
266
+ default: !1
267
267
  },
268
268
  outcome: {
269
- const: "not_executed"
269
+ default: "not_executed"
270
270
  }
271
271
  }
272
272
  }
@@ -289,10 +289,10 @@ const d = {
289
289
  error: {
290
290
  properties: {
291
291
  retryable: {
292
- const: !1
292
+ default: !1
293
293
  },
294
294
  outcome: {
295
- const: "not_executed"
295
+ default: "not_executed"
296
296
  }
297
297
  }
298
298
  }
@@ -315,10 +315,10 @@ const d = {
315
315
  error: {
316
316
  properties: {
317
317
  retryable: {
318
- const: !1
318
+ default: !1
319
319
  },
320
320
  outcome: {
321
- const: "not_executed"
321
+ default: "not_executed"
322
322
  }
323
323
  }
324
324
  }
@@ -341,10 +341,10 @@ const d = {
341
341
  error: {
342
342
  properties: {
343
343
  retryable: {
344
- const: !0
344
+ default: !0
345
345
  },
346
346
  outcome: {
347
- const: "not_executed"
347
+ default: "not_executed"
348
348
  }
349
349
  }
350
350
  }
@@ -367,10 +367,10 @@ const d = {
367
367
  error: {
368
368
  properties: {
369
369
  retryable: {
370
- const: !1
370
+ default: !1
371
371
  },
372
372
  outcome: {
373
- const: "unknown"
373
+ default: "unknown"
374
374
  }
375
375
  }
376
376
  }
@@ -393,10 +393,10 @@ const d = {
393
393
  error: {
394
394
  properties: {
395
395
  retryable: {
396
- const: !1
396
+ default: !1
397
397
  },
398
398
  outcome: {
399
- const: "unknown"
399
+ default: "unknown"
400
400
  }
401
401
  }
402
402
  }
@@ -419,10 +419,10 @@ const d = {
419
419
  error: {
420
420
  properties: {
421
421
  retryable: {
422
- const: !0
422
+ default: !0
423
423
  },
424
424
  outcome: {
425
- const: "unknown"
425
+ default: "unknown"
426
426
  }
427
427
  }
428
428
  }
@@ -507,7 +507,7 @@ const d = {
507
507
  $schema: "https://json-schema.org/draft/2020-12/schema",
508
508
  $id: "error-body.schema.json",
509
509
  title: "ErrorBody",
510
- description: "错误体。HTTP 状态表达大类,包体带业务码、说明、能否重试、是否已执行与出错字段定位。code 是通用失败码时,retryable 与 outcome 必须与通用失败码表一致。",
510
+ description: "错误体。HTTP 状态表达大类,包体带业务码、说明、能否重试、是否已执行与出错字段定位。code 是通用失败码时,retryable 与 outcome 的缺省值见通用失败码表,服务能确定更具体的情形时可以覆盖。",
511
511
  type: "object",
512
512
  properties: {
513
513
  code: {
@@ -697,7 +697,7 @@ const d = {
697
697
  $schema: "https://json-schema.org/draft/2020-12/schema",
698
698
  $id: "paged-list.schema.json",
699
699
  title: "PagedList",
700
- description: "页码式列表,作成功外壳的 data:给人翻页的表格,能跳页、有总数。顶层允许接口自己声明的附带字段,但不得重复表达翻页信息;不带 cursor。",
700
+ description: "页码式列表,作成功外壳的 data:给人翻页的表格,能跳页、有总数。顶层允许接口自己声明的附带字段,但不得重复表达翻页信息;不带 cursor。items 的条数不超过 page.pageSize,也不超过 page.totalRecord(x-itemsWithinPage)。",
701
701
  "x-pathConstants": "PAGED_LIST_RESPONSE_PATHS",
702
702
  type: "object",
703
703
  properties: {
@@ -711,6 +711,7 @@ const d = {
711
711
  cursor: !1
712
712
  },
713
713
  required: ["items", "page"],
714
+ "x-itemsWithinPage": !0,
714
715
  $defs: {
715
716
  page: {
716
717
  title: "PagedListPage",
@@ -754,7 +755,7 @@ const d = {
754
755
  "x-totalPageEqualsCeil": !0
755
756
  }
756
757
  }
757
- }, c = {
758
+ }, p = {
758
759
  $schema: "https://json-schema.org/draft/2020-12/schema",
759
760
  $id: "service-error-codes.schema.json",
760
761
  title: "ServiceErrorCodes",
@@ -869,7 +870,7 @@ const d = {
869
870
  }
870
871
  }
871
872
  }
872
- }, p = {
873
+ }, c = {
873
874
  $schema: "https://json-schema.org/draft/2020-12/schema",
874
875
  $id: "success-envelope.schema.json",
875
876
  title: "SuccessEnvelope",
@@ -893,7 +894,7 @@ const d = {
893
894
  },
894
895
  required: ["code", "message", "data"],
895
896
  additionalProperties: !1
896
- }, g = {
897
+ }, _ = {
897
898
  "bounded-list.schema.json": e,
898
899
  "common-error-codes.schema.json": t,
899
900
  "cursor-list-request.schema.json": r,
@@ -902,8 +903,8 @@ const d = {
902
903
  "list-filter.schema.json": i,
903
904
  "paged-list-request.schema.json": a,
904
905
  "paged-list.schema.json": n,
905
- "service-error-codes.schema.json": c,
906
- "success-envelope.schema.json": p
906
+ "service-error-codes.schema.json": p,
907
+ "success-envelope.schema.json": c
907
908
  };
908
909
  export {
909
910
  l as BOUNDED_LIST_RESPONSE_PATHS,
@@ -911,9 +912,9 @@ export {
911
912
  m as COMMON_ERROR_CODE_TABLE,
912
913
  h as CURSOR_LIST_REQUEST_PARAMS,
913
914
  E as CURSOR_LIST_RESPONSE_PATHS,
914
- S as LIST_FILTER_PARAMS,
915
- _ as PAGED_LIST_REQUEST_PARAMS,
916
- T as PAGED_LIST_RESPONSE_PATHS,
915
+ f as LIST_FILTER_PARAMS,
916
+ g as PAGED_LIST_REQUEST_PARAMS,
917
+ S as PAGED_LIST_RESPONSE_PATHS,
917
918
  d as SUCCESS_CODES,
918
919
  e as boundedListSchema,
919
920
  t as commonErrorCodesSchema,
@@ -923,7 +924,7 @@ export {
923
924
  i as listFilterSchema,
924
925
  a as pagedListRequestSchema,
925
926
  n as pagedListSchema,
926
- g as schemas,
927
- c as serviceErrorCodesSchema,
928
- p as successEnvelopeSchema
927
+ _ as schemas,
928
+ p as serviceErrorCodesSchema,
929
+ c as successEnvelopeSchema
929
930
  };
package/lib/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d={OK:"OK"},m={INVALID_REQUEST:"INVALID_REQUEST",UNAUTHENTICATED:"UNAUTHENTICATED",FORBIDDEN:"FORBIDDEN",NOT_FOUND:"NOT_FOUND",ROUTE_NOT_FOUND:"ROUTE_NOT_FOUND",METHOD_NOT_ALLOWED:"METHOD_NOT_ALLOWED",CONFLICT:"CONFLICT",RATE_LIMITED:"RATE_LIMITED",INTERNAL_ERROR:"INTERNAL_ERROR",LIST_LIMIT_EXCEEDED:"LIST_LIMIT_EXCEEDED",SERVICE_UNAVAILABLE:"SERVICE_UNAVAILABLE"},u={INVALID_REQUEST:{httpStatus:400,retryable:!1,outcome:"not_executed",meaning:"请求不符合接口契约"},UNAUTHENTICATED:{httpStatus:401,retryable:!1,outcome:"not_executed",meaning:"未登录,或令牌无效、过期"},FORBIDDEN:{httpStatus:403,retryable:!1,outcome:"not_executed",meaning:"已认证但无权执行"},NOT_FOUND:{httpStatus:404,retryable:!1,outcome:"not_executed",meaning:"资源不存在,或调用方无权得知其存在"},ROUTE_NOT_FOUND:{httpStatus:404,retryable:!1,outcome:"not_executed",meaning:"接口路径不存在"},METHOD_NOT_ALLOWED:{httpStatus:405,retryable:!1,outcome:"not_executed",meaning:"接口不支持该 HTTP 方法"},CONFLICT:{httpStatus:409,retryable:!1,outcome:"not_executed",meaning:"资源状态冲突"},RATE_LIMITED:{httpStatus:429,retryable:!0,outcome:"not_executed",meaning:"请求过于频繁,可稍后重试"},INTERNAL_ERROR:{httpStatus:500,retryable:!1,outcome:"unknown",meaning:"服务内部错误,可能已产生副作用"},LIST_LIMIT_EXCEEDED:{httpStatus:500,retryable:!1,outcome:"unknown",meaning:"一次性列表的结果超出接口声明的上限"},SERVICE_UNAVAILABLE:{httpStatus:503,retryable:!0,outcome:"unknown",meaning:"服务或其依赖暂不可用"}},l={items:"items"},E={after:"cursor.after",limit:"cursor.limit"},S={items:"items",next:"cursor.next",hasMore:"cursor.hasMore"},h={prefix:"filter.",operators:{eq:"eq"}},_={page:"page.page",pageSize:"page.pageSize",query:"page.query",orderBy:"page.orderBy"},T={items:"items",totalRecord:"page.totalRecord",pageSize:"page.pageSize",totalPage:"page.totalPage"},e={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"bounded-list.schema.json",title:"BoundedList",description:"一次性列表,作成功外壳的 data。只用于条数有一个由定义决定、不随业务数据增长的上限的结果(如下拉选项);上限由各接口在自己的契约里声明,超过上限报 LIST_LIMIT_EXCEEDED,不截断。顶层允许接口自己声明的附带字段,但不得带翻页信息。","x-pathConstants":"BOUNDED_LIST_RESPONSE_PATHS",type:"object",properties:{items:{description:"列表数据。",type:"array"},page:!1,cursor:!1},required:["items"]},t={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"common-error-codes.schema.json",title:"CommonErrorCodes",description:"通用失败码表:每个码固定 HTTP 状态(x-httpStatus)、能否重试与是否已执行。作为约束使用时(错误体引用它):code 是通用失败码时,error.retryable 与 error.outcome 必须与本表一致。$defs/code 列出全部通用失败码,须与 allOf 各项一一对应。",$defs:{code:{description:"通用失败码。",enum:["INVALID_REQUEST","UNAUTHENTICATED","FORBIDDEN","NOT_FOUND","ROUTE_NOT_FOUND","METHOD_NOT_ALLOWED","CONFLICT","RATE_LIMITED","INTERNAL_ERROR","LIST_LIMIT_EXCEEDED","SERVICE_UNAVAILABLE"]}},allOf:[{description:"请求不符合接口契约","x-httpStatus":400,if:{properties:{code:{const:"INVALID_REQUEST"}},required:["code"]},then:{properties:{error:{properties:{retryable:{const:!1},outcome:{const:"not_executed"}}}}}},{description:"未登录,或令牌无效、过期","x-httpStatus":401,if:{properties:{code:{const:"UNAUTHENTICATED"}},required:["code"]},then:{properties:{error:{properties:{retryable:{const:!1},outcome:{const:"not_executed"}}}}}},{description:"已认证但无权执行","x-httpStatus":403,if:{properties:{code:{const:"FORBIDDEN"}},required:["code"]},then:{properties:{error:{properties:{retryable:{const:!1},outcome:{const:"not_executed"}}}}}},{description:"资源不存在,或调用方无权得知其存在","x-httpStatus":404,if:{properties:{code:{const:"NOT_FOUND"}},required:["code"]},then:{properties:{error:{properties:{retryable:{const:!1},outcome:{const:"not_executed"}}}}}},{description:"接口路径不存在","x-httpStatus":404,if:{properties:{code:{const:"ROUTE_NOT_FOUND"}},required:["code"]},then:{properties:{error:{properties:{retryable:{const:!1},outcome:{const:"not_executed"}}}}}},{description:"接口不支持该 HTTP 方法","x-httpStatus":405,if:{properties:{code:{const:"METHOD_NOT_ALLOWED"}},required:["code"]},then:{properties:{error:{properties:{retryable:{const:!1},outcome:{const:"not_executed"}}}}}},{description:"资源状态冲突","x-httpStatus":409,if:{properties:{code:{const:"CONFLICT"}},required:["code"]},then:{properties:{error:{properties:{retryable:{const:!1},outcome:{const:"not_executed"}}}}}},{description:"请求过于频繁,可稍后重试","x-httpStatus":429,if:{properties:{code:{const:"RATE_LIMITED"}},required:["code"]},then:{properties:{error:{properties:{retryable:{const:!0},outcome:{const:"not_executed"}}}}}},{description:"服务内部错误,可能已产生副作用","x-httpStatus":500,if:{properties:{code:{const:"INTERNAL_ERROR"}},required:["code"]},then:{properties:{error:{properties:{retryable:{const:!1},outcome:{const:"unknown"}}}}}},{description:"一次性列表的结果超出接口声明的上限","x-httpStatus":500,if:{properties:{code:{const:"LIST_LIMIT_EXCEEDED"}},required:["code"]},then:{properties:{error:{properties:{retryable:{const:!1},outcome:{const:"unknown"}}}}}},{description:"服务或其依赖暂不可用","x-httpStatus":503,if:{properties:{code:{const:"SERVICE_UNAVAILABLE"}},required:["code"]},then:{properties:{error:{properties:{retryable:{const:!0},outcome:{const:"unknown"}}}}}}]},r={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"cursor-list-request.schema.json",title:"CursorListRequest",description:"游标式列表的请求参数。线上以 cursor. 前缀的查询参数传递(如 cursor.limit=20),本定义约束解码后的对象;前缀下未声明的参数不合法。","x-paramPrefix":"cursor","x-pathConstants":"CURSOR_LIST_REQUEST_PARAMS",type:"object",properties:{after:{description:"上一批返回的 next,1–1024 个字符;首批不带。",type:"string",minLength:1,maxLength:1024},limit:{description:"本批最多取多少条;缺省值由各接口自定。",type:"integer",minimum:1,maximum:100}},additionalProperties:!1},o={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"cursor-list.schema.json",title:"CursorList",description:"游标式列表,作成功外壳的 data:消息流这类接着往下取的列表,不带总数。取数方向由各接口声明。顶层允许接口自己声明的附带字段,但不得重复表达翻页信息;不带 page。","x-pathConstants":"CURSOR_LIST_RESPONSE_PATHS",type:"object",properties:{items:{description:"本批数据。",type:"array"},cursor:{$ref:"#/$defs/cursor"},page:!1},required:["items","cursor"],$defs:{cursor:{title:"CursorListCursor",description:"接着取的位置。hasMore 为 true 时必须给 next。",type:"object",properties:{next:{description:"下一批的游标,对调用方不透明,1–1024 个字符;没有更多时可省略。",type:"string",minLength:1,maxLength:1024},hasMore:{description:"是否还有更多。",type:"boolean"}},required:["hasMore"],additionalProperties:!1,if:{properties:{hasMore:{const:!0}},required:["hasMore"]},then:{required:["next"]}}}},s={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"error-body.schema.json",title:"ErrorBody",description:"错误体。HTTP 状态表达大类,包体带业务码、说明、能否重试、是否已执行与出错字段定位。code 是通用失败码时,retryable 与 outcome 必须与通用失败码表一致。",type:"object",properties:{code:{description:"业务码,开放字符串:字母开头,只含字母、数字、下划线,1–128 个字符;不能是 OK。使用方遇到不认识的码按 HTTP 状态归类处理。",type:"string",pattern:"^[A-Za-z][A-Za-z0-9_]{0,127}$",not:{const:"OK"}},message:{description:"说明,不能是纯空白。",type:"string",maxLength:1e3,pattern:"\\S"},data:{description:"错误体恒为 null。",type:"null"},error:{$ref:"#/$defs/errorDetail"},requestId:{description:"请求标识,1–128 个字符,不含空白字符。",type:"string",pattern:"^\\S{1,128}$"},detail:{description:"补充说明,可选,不限长。",type:"string"}},required:["code","message","data","error","requestId"],additionalProperties:!1,allOf:[{$ref:"common-error-codes.schema.json"}],$defs:{errorDetail:{title:"ErrorDetail",description:"错误的处置信息。",type:"object",properties:{retryable:{description:"原样重试是否可能成功。",type:"boolean"},outcome:{description:"not_executed:确定没有执行;unknown:可能已产生副作用。",enum:["not_executed","unknown"]},fields:{description:"逐项指出出错的输入;可以是空数组。",type:"array",items:{$ref:"#/$defs/errorField"}}},required:["retryable","outcome"],additionalProperties:!1},errorField:{title:"ErrorField",description:"一项出错的输入。in 为 body 时用 pointer 定位、不能有 parameter;其他位置用 parameter 定位、不能有 pointer。",type:"object",properties:{in:{description:"出错输入所在的位置。",enum:["body","query","path","header","cookie"]},code:{description:"字段级错误码:字母开头,只含字母、数字、下划线、点、短横线,1–128 个字符。",type:"string",pattern:"^[A-Za-z][A-Za-z0-9_.\\-]{0,127}$"},message:{description:"说明,不能是纯空白。",type:"string",maxLength:1e3,pattern:"\\S"},pointer:{description:"请求体内的位置,RFC 6901 JSON Pointer。",type:"string",pattern:"^(?:(?:/(?:[^~/]|~[01])*)*/(?:(?:[^~/]|~[01])*(?:[^~/\\n]|~[01]))?)?$"},parameter:{description:"参数名,1–256 个字符。",type:"string",minLength:1,maxLength:256}},required:["in","code","message"],additionalProperties:!1,if:{properties:{in:{const:"body"}},required:["in"]},then:{required:["pointer"],properties:{parameter:!1}},else:{required:["parameter"],properties:{pointer:!1}}}}},i={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"list-filter.schema.json",title:"ListFilter",description:"列表的筛选参数。线上写作 filter.<字段>.<操作>(如 filter.status.eq=active),本定义约束解码后的对象 {<字段>: {<操作>: 值}};字段为小驼峰,可筛选哪些字段由接口自己声明。首版操作只有 eq。前缀下未声明的参数不合法。","x-paramPrefix":"filter","x-pathConstants":"LIST_FILTER_PARAMS",type:"object",patternProperties:{"^[a-z][a-zA-Z0-9]*$":{$ref:"#/$defs/condition"}},additionalProperties:!1,$defs:{condition:{title:"ListFilterCondition",description:"一个字段上的筛选条件,至少一个操作。",type:"object",properties:{eq:{description:"等于;值为标量。",type:["string","number","boolean"]}},minProperties:1,additionalProperties:!1}}},a={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"paged-list-request.schema.json",title:"PagedListRequest",description:"页码式列表的请求参数。线上以 page. 前缀的查询参数传递(如 page.pageSize=20),本定义约束解码后的对象;前缀下未声明的参数不合法。","x-paramPrefix":"page","x-pathConstants":"PAGED_LIST_REQUEST_PARAMS",type:"object",properties:{page:{description:"页码,从 1 开始。",type:"integer",minimum:1,default:1},pageSize:{description:"每页条数。",type:"integer",minimum:1,maximum:100,default:10},query:{description:"模糊搜索词,最多 200 个字符。",type:"string",maxLength:200},orderBy:{description:"排序:逗号分隔,每段是小驼峰字段名,后面可跟一个空格加 asc 或 desc(缺省 asc);逗号后可有一个空格;最多 200 个字符。",type:"string",maxLength:200,pattern:"^[a-z][a-zA-Z0-9]*(?: (?:asc|desc))?(?:, ?[a-z][a-zA-Z0-9]*(?: (?:asc|desc))?)*$"}},additionalProperties:!1},n={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"paged-list.schema.json",title:"PagedList",description:"页码式列表,作成功外壳的 data:给人翻页的表格,能跳页、有总数。顶层允许接口自己声明的附带字段,但不得重复表达翻页信息;不带 cursor。","x-pathConstants":"PAGED_LIST_RESPONSE_PATHS",type:"object",properties:{items:{description:"当前页的数据。",type:"array"},page:{$ref:"#/$defs/page"},cursor:!1},required:["items","page"],$defs:{page:{title:"PagedListPage",description:"翻页信息。不回传当前页码。totalPage 等于 ceil(totalRecord / pageSize),总数为 0 时为 0(x-totalPageEqualsCeil)。",type:"object",properties:{totalRecord:{description:"总条数。",type:"integer",minimum:0},pageSize:{description:"每页条数,回显请求值。",type:"integer",minimum:1,maximum:100},totalPage:{description:"总页数。",type:"integer",minimum:0}},required:["totalRecord","pageSize","totalPage"],additionalProperties:!1,if:{properties:{totalRecord:{const:0}},required:["totalRecord"]},then:{properties:{totalPage:{const:0}}},"x-totalPageEqualsCeil":!0}}},c={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"service-error-codes.schema.json",title:"ServiceErrorCodes",description:"一个服务的专有业务码清单。不得重新定义通用码;OK 与 HTTP_<数字> 形式的码保留,不得使用;比较按字节精确进行,不做大小写归一。",type:"object",properties:{service:{description:"服务标识:小写字母开头,只含小写字母、数字、短横线,最长 64 个字符。",type:"string",pattern:"^[a-z][a-z0-9\\-]{0,63}$"},codes:{description:"专有码,至少 1 项;code 在清单内不重复(x-uniqueItemsBy)。",type:"array",minItems:1,items:{$ref:"#/$defs/code"},"x-uniqueItemsBy":"code"}},required:["service","codes"],additionalProperties:!1,$defs:{code:{title:"ServiceErrorCode",description:"一个专有码。stage 为 execute 时不得有 httpStatus 与 additionalHttpStatuses;为 accept 或 both 时必须有 httpStatus。additionalHttpStatuses 不含主状态(x-arrayExcludesProperty)。",type:"object",properties:{code:{description:"码:整体大写下划线或整体小写下划线写法,字母开头,不以下划线结尾,不含连续下划线,最长 128 个字符。",type:"string",maxLength:128,pattern:"^(?:[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*|[a-z][a-z0-9]*(?:_[a-z0-9]+)*)$",allOf:[{not:{const:"OK"}},{not:{type:"string",pattern:"^HTTP_[0-9]+$"}},{not:{$ref:"common-error-codes.schema.json#/$defs/code"}}]},stage:{description:"accept:受理时同步返回;execute:异步执行阶段产生;both:两者都有。",enum:["accept","execute","both"]},httpStatus:{description:"主 HTTP 状态,4xx 或 5xx。",type:"integer",minimum:400,maximum:599},additionalHttpStatuses:{description:"同一个码在不同情形下的其他 HTTP 状态:至少 1 项、不重复、不含主状态。",type:"array",minItems:1,uniqueItems:!0,items:{type:"integer",minimum:400,maximum:599}},retryable:{description:"原样重试是否可能成功。",type:"boolean"},outcome:{description:"not_executed:确定没有执行;unknown:可能已产生副作用。",enum:["not_executed","unknown"]},meaning:{description:"一句话含义,1–1000 个字符。",type:"string",minLength:1,maxLength:1e3}},required:["code","stage","retryable","outcome","meaning"],additionalProperties:!1,if:{properties:{stage:{const:"execute"}},required:["stage"]},then:{properties:{httpStatus:!1,additionalHttpStatuses:!1}},else:{required:["httpStatus"]},"x-arrayExcludesProperty":{array:"additionalHttpStatuses",property:"httpStatus"}}}},p={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"success-envelope.schema.json",title:"SuccessEnvelope",description:"成功外壳。成功与否、新建还是已受理以 HTTP 状态码为准,code 不随 200 / 201 / 202 变化。",type:"object",properties:{code:{description:"成功码,恒为 OK。",const:"OK"},message:{description:"说明,可以为空串。",type:"string",maxLength:1e3},data:{description:'结果对象或 null;标量结果也包成对象(如 {"count": 3})。',type:["object","null"],additionalProperties:!0}},required:["code","message","data"],additionalProperties:!1},g={"bounded-list.schema.json":e,"common-error-codes.schema.json":t,"cursor-list-request.schema.json":r,"cursor-list.schema.json":o,"error-body.schema.json":s,"list-filter.schema.json":i,"paged-list-request.schema.json":a,"paged-list.schema.json":n,"service-error-codes.schema.json":c,"success-envelope.schema.json":p};exports.BOUNDED_LIST_RESPONSE_PATHS=l;exports.COMMON_ERROR_CODES=m;exports.COMMON_ERROR_CODE_TABLE=u;exports.CURSOR_LIST_REQUEST_PARAMS=E;exports.CURSOR_LIST_RESPONSE_PATHS=S;exports.LIST_FILTER_PARAMS=h;exports.PAGED_LIST_REQUEST_PARAMS=_;exports.PAGED_LIST_RESPONSE_PATHS=T;exports.SUCCESS_CODES=d;exports.boundedListSchema=e;exports.commonErrorCodesSchema=t;exports.cursorListRequestSchema=r;exports.cursorListSchema=o;exports.errorBodySchema=s;exports.listFilterSchema=i;exports.pagedListRequestSchema=a;exports.pagedListSchema=n;exports.schemas=g;exports.serviceErrorCodesSchema=c;exports.successEnvelopeSchema=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d={OK:"OK"},u={INVALID_REQUEST:"INVALID_REQUEST",UNAUTHENTICATED:"UNAUTHENTICATED",FORBIDDEN:"FORBIDDEN",NOT_FOUND:"NOT_FOUND",ROUTE_NOT_FOUND:"ROUTE_NOT_FOUND",METHOD_NOT_ALLOWED:"METHOD_NOT_ALLOWED",CONFLICT:"CONFLICT",RATE_LIMITED:"RATE_LIMITED",INTERNAL_ERROR:"INTERNAL_ERROR",LIST_LIMIT_EXCEEDED:"LIST_LIMIT_EXCEEDED",SERVICE_UNAVAILABLE:"SERVICE_UNAVAILABLE"},m={INVALID_REQUEST:{httpStatus:400,retryable:!1,outcome:"not_executed",meaning:"请求不符合接口契约"},UNAUTHENTICATED:{httpStatus:401,retryable:!1,outcome:"not_executed",meaning:"未登录,或令牌无效、过期"},FORBIDDEN:{httpStatus:403,retryable:!1,outcome:"not_executed",meaning:"已认证但无权执行"},NOT_FOUND:{httpStatus:404,retryable:!1,outcome:"not_executed",meaning:"资源不存在,或调用方无权得知其存在"},ROUTE_NOT_FOUND:{httpStatus:404,retryable:!1,outcome:"not_executed",meaning:"接口路径不存在"},METHOD_NOT_ALLOWED:{httpStatus:405,retryable:!1,outcome:"not_executed",meaning:"接口不支持该 HTTP 方法"},CONFLICT:{httpStatus:409,retryable:!1,outcome:"not_executed",meaning:"资源状态冲突"},RATE_LIMITED:{httpStatus:429,retryable:!0,outcome:"not_executed",meaning:"请求过于频繁,可稍后重试"},INTERNAL_ERROR:{httpStatus:500,retryable:!1,outcome:"unknown",meaning:"服务内部错误,可能已产生副作用"},LIST_LIMIT_EXCEEDED:{httpStatus:500,retryable:!1,outcome:"unknown",meaning:"一次性列表的结果超出接口声明的上限"},SERVICE_UNAVAILABLE:{httpStatus:503,retryable:!0,outcome:"unknown",meaning:"服务或其依赖暂不可用"}},l={items:"items"},E={after:"cursor.after",limit:"cursor.limit"},S={items:"items",next:"cursor.next",hasMore:"cursor.hasMore"},h={prefix:"filter.",operators:{eq:"eq"}},_={page:"page.page",pageSize:"page.pageSize",query:"page.query",orderBy:"page.orderBy"},T={items:"items",totalRecord:"page.totalRecord",pageSize:"page.pageSize",totalPage:"page.totalPage"},e={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"bounded-list.schema.json",title:"BoundedList",description:"一次性列表,作成功外壳的 data。只用于条数有一个由定义决定、不随业务数据增长的上限的结果(如下拉选项);上限由各接口在自己的契约里声明,超过上限报 LIST_LIMIT_EXCEEDED,不截断。顶层允许接口自己声明的附带字段,但不得带翻页信息。","x-pathConstants":"BOUNDED_LIST_RESPONSE_PATHS",type:"object",properties:{items:{description:"列表数据。",type:"array"},page:!1,cursor:!1},required:["items"]},t={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"common-error-codes.schema.json",title:"CommonErrorCodes",description:"通用失败码表:每个码固定 HTTP 状态(x-httpStatus),并给出能否重试与是否已执行的缺省值(default)。错误体引用本表:code 是通用失败码时,服务未另行指定 error.retryable 与 error.outcome 就取表中值;服务能确定更具体的重试性或执行结局时可以覆盖,任何合法的 retryable 与 outcome 都合法。$defs/code 列出全部通用失败码,须与 allOf 各项一一对应。",$defs:{code:{description:"通用失败码。",enum:["INVALID_REQUEST","UNAUTHENTICATED","FORBIDDEN","NOT_FOUND","ROUTE_NOT_FOUND","METHOD_NOT_ALLOWED","CONFLICT","RATE_LIMITED","INTERNAL_ERROR","LIST_LIMIT_EXCEEDED","SERVICE_UNAVAILABLE"]}},allOf:[{description:"请求不符合接口契约","x-httpStatus":400,if:{properties:{code:{const:"INVALID_REQUEST"}},required:["code"]},then:{properties:{error:{properties:{retryable:{default:!1},outcome:{default:"not_executed"}}}}}},{description:"未登录,或令牌无效、过期","x-httpStatus":401,if:{properties:{code:{const:"UNAUTHENTICATED"}},required:["code"]},then:{properties:{error:{properties:{retryable:{default:!1},outcome:{default:"not_executed"}}}}}},{description:"已认证但无权执行","x-httpStatus":403,if:{properties:{code:{const:"FORBIDDEN"}},required:["code"]},then:{properties:{error:{properties:{retryable:{default:!1},outcome:{default:"not_executed"}}}}}},{description:"资源不存在,或调用方无权得知其存在","x-httpStatus":404,if:{properties:{code:{const:"NOT_FOUND"}},required:["code"]},then:{properties:{error:{properties:{retryable:{default:!1},outcome:{default:"not_executed"}}}}}},{description:"接口路径不存在","x-httpStatus":404,if:{properties:{code:{const:"ROUTE_NOT_FOUND"}},required:["code"]},then:{properties:{error:{properties:{retryable:{default:!1},outcome:{default:"not_executed"}}}}}},{description:"接口不支持该 HTTP 方法","x-httpStatus":405,if:{properties:{code:{const:"METHOD_NOT_ALLOWED"}},required:["code"]},then:{properties:{error:{properties:{retryable:{default:!1},outcome:{default:"not_executed"}}}}}},{description:"资源状态冲突","x-httpStatus":409,if:{properties:{code:{const:"CONFLICT"}},required:["code"]},then:{properties:{error:{properties:{retryable:{default:!1},outcome:{default:"not_executed"}}}}}},{description:"请求过于频繁,可稍后重试","x-httpStatus":429,if:{properties:{code:{const:"RATE_LIMITED"}},required:["code"]},then:{properties:{error:{properties:{retryable:{default:!0},outcome:{default:"not_executed"}}}}}},{description:"服务内部错误,可能已产生副作用","x-httpStatus":500,if:{properties:{code:{const:"INTERNAL_ERROR"}},required:["code"]},then:{properties:{error:{properties:{retryable:{default:!1},outcome:{default:"unknown"}}}}}},{description:"一次性列表的结果超出接口声明的上限","x-httpStatus":500,if:{properties:{code:{const:"LIST_LIMIT_EXCEEDED"}},required:["code"]},then:{properties:{error:{properties:{retryable:{default:!1},outcome:{default:"unknown"}}}}}},{description:"服务或其依赖暂不可用","x-httpStatus":503,if:{properties:{code:{const:"SERVICE_UNAVAILABLE"}},required:["code"]},then:{properties:{error:{properties:{retryable:{default:!0},outcome:{default:"unknown"}}}}}}]},r={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"cursor-list-request.schema.json",title:"CursorListRequest",description:"游标式列表的请求参数。线上以 cursor. 前缀的查询参数传递(如 cursor.limit=20),本定义约束解码后的对象;前缀下未声明的参数不合法。","x-paramPrefix":"cursor","x-pathConstants":"CURSOR_LIST_REQUEST_PARAMS",type:"object",properties:{after:{description:"上一批返回的 next,1–1024 个字符;首批不带。",type:"string",minLength:1,maxLength:1024},limit:{description:"本批最多取多少条;缺省值由各接口自定。",type:"integer",minimum:1,maximum:100}},additionalProperties:!1},o={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"cursor-list.schema.json",title:"CursorList",description:"游标式列表,作成功外壳的 data:消息流这类接着往下取的列表,不带总数。取数方向由各接口声明。顶层允许接口自己声明的附带字段,但不得重复表达翻页信息;不带 page。","x-pathConstants":"CURSOR_LIST_RESPONSE_PATHS",type:"object",properties:{items:{description:"本批数据。",type:"array"},cursor:{$ref:"#/$defs/cursor"},page:!1},required:["items","cursor"],$defs:{cursor:{title:"CursorListCursor",description:"接着取的位置。hasMore 为 true 时必须给 next。",type:"object",properties:{next:{description:"下一批的游标,对调用方不透明,1–1024 个字符;没有更多时可省略。",type:"string",minLength:1,maxLength:1024},hasMore:{description:"是否还有更多。",type:"boolean"}},required:["hasMore"],additionalProperties:!1,if:{properties:{hasMore:{const:!0}},required:["hasMore"]},then:{required:["next"]}}}},s={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"error-body.schema.json",title:"ErrorBody",description:"错误体。HTTP 状态表达大类,包体带业务码、说明、能否重试、是否已执行与出错字段定位。code 是通用失败码时,retryable 与 outcome 的缺省值见通用失败码表,服务能确定更具体的情形时可以覆盖。",type:"object",properties:{code:{description:"业务码,开放字符串:字母开头,只含字母、数字、下划线,1–128 个字符;不能是 OK。使用方遇到不认识的码按 HTTP 状态归类处理。",type:"string",pattern:"^[A-Za-z][A-Za-z0-9_]{0,127}$",not:{const:"OK"}},message:{description:"说明,不能是纯空白。",type:"string",maxLength:1e3,pattern:"\\S"},data:{description:"错误体恒为 null。",type:"null"},error:{$ref:"#/$defs/errorDetail"},requestId:{description:"请求标识,1–128 个字符,不含空白字符。",type:"string",pattern:"^\\S{1,128}$"},detail:{description:"补充说明,可选,不限长。",type:"string"}},required:["code","message","data","error","requestId"],additionalProperties:!1,allOf:[{$ref:"common-error-codes.schema.json"}],$defs:{errorDetail:{title:"ErrorDetail",description:"错误的处置信息。",type:"object",properties:{retryable:{description:"原样重试是否可能成功。",type:"boolean"},outcome:{description:"not_executed:确定没有执行;unknown:可能已产生副作用。",enum:["not_executed","unknown"]},fields:{description:"逐项指出出错的输入;可以是空数组。",type:"array",items:{$ref:"#/$defs/errorField"}}},required:["retryable","outcome"],additionalProperties:!1},errorField:{title:"ErrorField",description:"一项出错的输入。in 为 body 时用 pointer 定位、不能有 parameter;其他位置用 parameter 定位、不能有 pointer。",type:"object",properties:{in:{description:"出错输入所在的位置。",enum:["body","query","path","header","cookie"]},code:{description:"字段级错误码:字母开头,只含字母、数字、下划线、点、短横线,1–128 个字符。",type:"string",pattern:"^[A-Za-z][A-Za-z0-9_.\\-]{0,127}$"},message:{description:"说明,不能是纯空白。",type:"string",maxLength:1e3,pattern:"\\S"},pointer:{description:"请求体内的位置,RFC 6901 JSON Pointer。",type:"string",pattern:"^(?:(?:/(?:[^~/]|~[01])*)*/(?:(?:[^~/]|~[01])*(?:[^~/\\n]|~[01]))?)?$"},parameter:{description:"参数名,1–256 个字符。",type:"string",minLength:1,maxLength:256}},required:["in","code","message"],additionalProperties:!1,if:{properties:{in:{const:"body"}},required:["in"]},then:{required:["pointer"],properties:{parameter:!1}},else:{required:["parameter"],properties:{pointer:!1}}}}},i={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"list-filter.schema.json",title:"ListFilter",description:"列表的筛选参数。线上写作 filter.<字段>.<操作>(如 filter.status.eq=active),本定义约束解码后的对象 {<字段>: {<操作>: 值}};字段为小驼峰,可筛选哪些字段由接口自己声明。首版操作只有 eq。前缀下未声明的参数不合法。","x-paramPrefix":"filter","x-pathConstants":"LIST_FILTER_PARAMS",type:"object",patternProperties:{"^[a-z][a-zA-Z0-9]*$":{$ref:"#/$defs/condition"}},additionalProperties:!1,$defs:{condition:{title:"ListFilterCondition",description:"一个字段上的筛选条件,至少一个操作。",type:"object",properties:{eq:{description:"等于;值为标量。",type:["string","number","boolean"]}},minProperties:1,additionalProperties:!1}}},a={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"paged-list-request.schema.json",title:"PagedListRequest",description:"页码式列表的请求参数。线上以 page. 前缀的查询参数传递(如 page.pageSize=20),本定义约束解码后的对象;前缀下未声明的参数不合法。","x-paramPrefix":"page","x-pathConstants":"PAGED_LIST_REQUEST_PARAMS",type:"object",properties:{page:{description:"页码,从 1 开始。",type:"integer",minimum:1,default:1},pageSize:{description:"每页条数。",type:"integer",minimum:1,maximum:100,default:10},query:{description:"模糊搜索词,最多 200 个字符。",type:"string",maxLength:200},orderBy:{description:"排序:逗号分隔,每段是小驼峰字段名,后面可跟一个空格加 asc 或 desc(缺省 asc);逗号后可有一个空格;最多 200 个字符。",type:"string",maxLength:200,pattern:"^[a-z][a-zA-Z0-9]*(?: (?:asc|desc))?(?:, ?[a-z][a-zA-Z0-9]*(?: (?:asc|desc))?)*$"}},additionalProperties:!1},n={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"paged-list.schema.json",title:"PagedList",description:"页码式列表,作成功外壳的 data:给人翻页的表格,能跳页、有总数。顶层允许接口自己声明的附带字段,但不得重复表达翻页信息;不带 cursor。items 的条数不超过 page.pageSize,也不超过 page.totalRecord(x-itemsWithinPage)。","x-pathConstants":"PAGED_LIST_RESPONSE_PATHS",type:"object",properties:{items:{description:"当前页的数据。",type:"array"},page:{$ref:"#/$defs/page"},cursor:!1},required:["items","page"],"x-itemsWithinPage":!0,$defs:{page:{title:"PagedListPage",description:"翻页信息。不回传当前页码。totalPage 等于 ceil(totalRecord / pageSize),总数为 0 时为 0(x-totalPageEqualsCeil)。",type:"object",properties:{totalRecord:{description:"总条数。",type:"integer",minimum:0},pageSize:{description:"每页条数,回显请求值。",type:"integer",minimum:1,maximum:100},totalPage:{description:"总页数。",type:"integer",minimum:0}},required:["totalRecord","pageSize","totalPage"],additionalProperties:!1,if:{properties:{totalRecord:{const:0}},required:["totalRecord"]},then:{properties:{totalPage:{const:0}}},"x-totalPageEqualsCeil":!0}}},c={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"service-error-codes.schema.json",title:"ServiceErrorCodes",description:"一个服务的专有业务码清单。不得重新定义通用码;OK 与 HTTP_<数字> 形式的码保留,不得使用;比较按字节精确进行,不做大小写归一。",type:"object",properties:{service:{description:"服务标识:小写字母开头,只含小写字母、数字、短横线,最长 64 个字符。",type:"string",pattern:"^[a-z][a-z0-9\\-]{0,63}$"},codes:{description:"专有码,至少 1 项;code 在清单内不重复(x-uniqueItemsBy)。",type:"array",minItems:1,items:{$ref:"#/$defs/code"},"x-uniqueItemsBy":"code"}},required:["service","codes"],additionalProperties:!1,$defs:{code:{title:"ServiceErrorCode",description:"一个专有码。stage 为 execute 时不得有 httpStatus 与 additionalHttpStatuses;为 accept 或 both 时必须有 httpStatus。additionalHttpStatuses 不含主状态(x-arrayExcludesProperty)。",type:"object",properties:{code:{description:"码:整体大写下划线或整体小写下划线写法,字母开头,不以下划线结尾,不含连续下划线,最长 128 个字符。",type:"string",maxLength:128,pattern:"^(?:[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*|[a-z][a-z0-9]*(?:_[a-z0-9]+)*)$",allOf:[{not:{const:"OK"}},{not:{type:"string",pattern:"^HTTP_[0-9]+$"}},{not:{$ref:"common-error-codes.schema.json#/$defs/code"}}]},stage:{description:"accept:受理时同步返回;execute:异步执行阶段产生;both:两者都有。",enum:["accept","execute","both"]},httpStatus:{description:"主 HTTP 状态,4xx 或 5xx。",type:"integer",minimum:400,maximum:599},additionalHttpStatuses:{description:"同一个码在不同情形下的其他 HTTP 状态:至少 1 项、不重复、不含主状态。",type:"array",minItems:1,uniqueItems:!0,items:{type:"integer",minimum:400,maximum:599}},retryable:{description:"原样重试是否可能成功。",type:"boolean"},outcome:{description:"not_executed:确定没有执行;unknown:可能已产生副作用。",enum:["not_executed","unknown"]},meaning:{description:"一句话含义,1–1000 个字符。",type:"string",minLength:1,maxLength:1e3}},required:["code","stage","retryable","outcome","meaning"],additionalProperties:!1,if:{properties:{stage:{const:"execute"}},required:["stage"]},then:{properties:{httpStatus:!1,additionalHttpStatuses:!1}},else:{required:["httpStatus"]},"x-arrayExcludesProperty":{array:"additionalHttpStatuses",property:"httpStatus"}}}},p={$schema:"https://json-schema.org/draft/2020-12/schema",$id:"success-envelope.schema.json",title:"SuccessEnvelope",description:"成功外壳。成功与否、新建还是已受理以 HTTP 状态码为准,code 不随 200 / 201 / 202 变化。",type:"object",properties:{code:{description:"成功码,恒为 OK。",const:"OK"},message:{description:"说明,可以为空串。",type:"string",maxLength:1e3},data:{description:'结果对象或 null;标量结果也包成对象(如 {"count": 3})。',type:["object","null"],additionalProperties:!0}},required:["code","message","data"],additionalProperties:!1},g={"bounded-list.schema.json":e,"common-error-codes.schema.json":t,"cursor-list-request.schema.json":r,"cursor-list.schema.json":o,"error-body.schema.json":s,"list-filter.schema.json":i,"paged-list-request.schema.json":a,"paged-list.schema.json":n,"service-error-codes.schema.json":c,"success-envelope.schema.json":p};exports.BOUNDED_LIST_RESPONSE_PATHS=l;exports.COMMON_ERROR_CODES=u;exports.COMMON_ERROR_CODE_TABLE=m;exports.CURSOR_LIST_REQUEST_PARAMS=E;exports.CURSOR_LIST_RESPONSE_PATHS=S;exports.LIST_FILTER_PARAMS=h;exports.PAGED_LIST_REQUEST_PARAMS=_;exports.PAGED_LIST_RESPONSE_PATHS=T;exports.SUCCESS_CODES=d;exports.boundedListSchema=e;exports.commonErrorCodesSchema=t;exports.cursorListRequestSchema=r;exports.cursorListSchema=o;exports.errorBodySchema=s;exports.listFilterSchema=i;exports.pagedListRequestSchema=a;exports.pagedListSchema=n;exports.schemas=g;exports.serviceErrorCodesSchema=c;exports.successEnvelopeSchema=p;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/schema-api",
3
- "version": "0.0.1-alpha.0",
3
+ "version": "0.0.1-alpha.1",
4
4
  "description": "跨前后端通用接口结构的类型、常量与定义文件",
5
5
  "private": false,
6
6
  "main": "lib/index.cjs",
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "common-error-codes.schema.json",
4
4
  "title": "CommonErrorCodes",
5
- "description": "通用失败码表:每个码固定 HTTP 状态(x-httpStatus)、能否重试与是否已执行。作为约束使用时(错误体引用它):code 是通用失败码时,error.retryable 与 error.outcome 必须与本表一致。$defs/code 列出全部通用失败码,须与 allOf 各项一一对应。",
5
+ "description": "通用失败码表:每个码固定 HTTP 状态(x-httpStatus),并给出能否重试与是否已执行的缺省值(default)。错误体引用本表:code 是通用失败码时,服务未另行指定 error.retryable 与 error.outcome 就取表中值;服务能确定更具体的重试性或执行结局时可以覆盖,任何合法的 retryable 与 outcome 都合法。$defs/code 列出全部通用失败码,须与 allOf 各项一一对应。",
6
6
  "$defs": {
7
7
  "code": {
8
8
  "description": "通用失败码。",
@@ -33,8 +33,8 @@
33
33
  "properties": {
34
34
  "error": {
35
35
  "properties": {
36
- "retryable": { "const": false },
37
- "outcome": { "const": "not_executed" }
36
+ "retryable": { "default": false },
37
+ "outcome": { "default": "not_executed" }
38
38
  }
39
39
  }
40
40
  }
@@ -51,8 +51,8 @@
51
51
  "properties": {
52
52
  "error": {
53
53
  "properties": {
54
- "retryable": { "const": false },
55
- "outcome": { "const": "not_executed" }
54
+ "retryable": { "default": false },
55
+ "outcome": { "default": "not_executed" }
56
56
  }
57
57
  }
58
58
  }
@@ -69,8 +69,8 @@
69
69
  "properties": {
70
70
  "error": {
71
71
  "properties": {
72
- "retryable": { "const": false },
73
- "outcome": { "const": "not_executed" }
72
+ "retryable": { "default": false },
73
+ "outcome": { "default": "not_executed" }
74
74
  }
75
75
  }
76
76
  }
@@ -87,8 +87,8 @@
87
87
  "properties": {
88
88
  "error": {
89
89
  "properties": {
90
- "retryable": { "const": false },
91
- "outcome": { "const": "not_executed" }
90
+ "retryable": { "default": false },
91
+ "outcome": { "default": "not_executed" }
92
92
  }
93
93
  }
94
94
  }
@@ -105,8 +105,8 @@
105
105
  "properties": {
106
106
  "error": {
107
107
  "properties": {
108
- "retryable": { "const": false },
109
- "outcome": { "const": "not_executed" }
108
+ "retryable": { "default": false },
109
+ "outcome": { "default": "not_executed" }
110
110
  }
111
111
  }
112
112
  }
@@ -123,8 +123,8 @@
123
123
  "properties": {
124
124
  "error": {
125
125
  "properties": {
126
- "retryable": { "const": false },
127
- "outcome": { "const": "not_executed" }
126
+ "retryable": { "default": false },
127
+ "outcome": { "default": "not_executed" }
128
128
  }
129
129
  }
130
130
  }
@@ -141,8 +141,8 @@
141
141
  "properties": {
142
142
  "error": {
143
143
  "properties": {
144
- "retryable": { "const": false },
145
- "outcome": { "const": "not_executed" }
144
+ "retryable": { "default": false },
145
+ "outcome": { "default": "not_executed" }
146
146
  }
147
147
  }
148
148
  }
@@ -159,8 +159,8 @@
159
159
  "properties": {
160
160
  "error": {
161
161
  "properties": {
162
- "retryable": { "const": true },
163
- "outcome": { "const": "not_executed" }
162
+ "retryable": { "default": true },
163
+ "outcome": { "default": "not_executed" }
164
164
  }
165
165
  }
166
166
  }
@@ -177,8 +177,8 @@
177
177
  "properties": {
178
178
  "error": {
179
179
  "properties": {
180
- "retryable": { "const": false },
181
- "outcome": { "const": "unknown" }
180
+ "retryable": { "default": false },
181
+ "outcome": { "default": "unknown" }
182
182
  }
183
183
  }
184
184
  }
@@ -195,8 +195,8 @@
195
195
  "properties": {
196
196
  "error": {
197
197
  "properties": {
198
- "retryable": { "const": false },
199
- "outcome": { "const": "unknown" }
198
+ "retryable": { "default": false },
199
+ "outcome": { "default": "unknown" }
200
200
  }
201
201
  }
202
202
  }
@@ -213,8 +213,8 @@
213
213
  "properties": {
214
214
  "error": {
215
215
  "properties": {
216
- "retryable": { "const": true },
217
- "outcome": { "const": "unknown" }
216
+ "retryable": { "default": true },
217
+ "outcome": { "default": "unknown" }
218
218
  }
219
219
  }
220
220
  }
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "error-body.schema.json",
4
4
  "title": "ErrorBody",
5
- "description": "错误体。HTTP 状态表达大类,包体带业务码、说明、能否重试、是否已执行与出错字段定位。code 是通用失败码时,retryable 与 outcome 必须与通用失败码表一致。",
5
+ "description": "错误体。HTTP 状态表达大类,包体带业务码、说明、能否重试、是否已执行与出错字段定位。code 是通用失败码时,retryable 与 outcome 的缺省值见通用失败码表,服务能确定更具体的情形时可以覆盖。",
6
6
  "type": "object",
7
7
  "properties": {
8
8
  "code": {
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "paged-list.schema.json",
4
4
  "title": "PagedList",
5
- "description": "页码式列表,作成功外壳的 data:给人翻页的表格,能跳页、有总数。顶层允许接口自己声明的附带字段,但不得重复表达翻页信息;不带 cursor。",
5
+ "description": "页码式列表,作成功外壳的 data:给人翻页的表格,能跳页、有总数。顶层允许接口自己声明的附带字段,但不得重复表达翻页信息;不带 cursor。items 的条数不超过 page.pageSize,也不超过 page.totalRecord(x-itemsWithinPage)。",
6
6
  "x-pathConstants": "PAGED_LIST_RESPONSE_PATHS",
7
7
  "type": "object",
8
8
  "properties": {
@@ -14,6 +14,7 @@
14
14
  "cursor": false
15
15
  },
16
16
  "required": ["items", "page"],
17
+ "x-itemsWithinPage": true,
17
18
  "$defs": {
18
19
  "page": {
19
20
  "title": "PagedListPage",
package/types/index.d.ts CHANGED
@@ -26,7 +26,8 @@ declare interface BoundedList_2 {
26
26
  export declare const boundedListSchema: SchemaDocument;
27
27
 
28
28
  /**
29
- * 通用失败码 → HTTP 状态、能否重试、是否已执行(outcome)与含义。
29
+ * 通用失败码 → HTTP 状态、能否重试与是否已执行(outcome)的缺省值、含义。
30
+ * retryable 与 outcome 是缺省值:服务未另行指定时取表中值,能确定更具体的情形时可以覆盖。
30
31
  */
31
32
  export declare const COMMON_ERROR_CODE_TABLE: {
32
33
  readonly INVALID_REQUEST: {
@@ -189,7 +190,7 @@ export declare const cursorListRequestSchema: SchemaDocument;
189
190
  export declare const cursorListSchema: SchemaDocument;
190
191
 
191
192
  /**
192
- * 错误体。HTTP 状态表达大类,包体带业务码、说明、能否重试、是否已执行与出错字段定位。code 是通用失败码时,retryable 与 outcome 必须与通用失败码表一致。
193
+ * 错误体。HTTP 状态表达大类,包体带业务码、说明、能否重试、是否已执行与出错字段定位。code 是通用失败码时,retryable 与 outcome 的缺省值见通用失败码表,服务能确定更具体的情形时可以覆盖。
193
194
  */
194
195
  export declare interface ErrorBody {
195
196
  /**
@@ -341,7 +342,7 @@ export declare interface PagedList<TItem = unknown> extends Omit<Generated.Paged
341
342
  }
342
343
 
343
344
  /**
344
- * 页码式列表,作成功外壳的 data:给人翻页的表格,能跳页、有总数。顶层允许接口自己声明的附带字段,但不得重复表达翻页信息;不带 cursor。
345
+ * 页码式列表,作成功外壳的 data:给人翻页的表格,能跳页、有总数。顶层允许接口自己声明的附带字段,但不得重复表达翻页信息;不带 cursor。items 的条数不超过 page.pageSize,也不超过 page.totalRecord(x-itemsWithinPage)。
345
346
  */
346
347
  declare interface PagedList_2 {
347
348
  /**