@done-coding/schema-api 0.0.1-alpha.2 → 0.0.1-alpha.3

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