@baijimu/cmodel 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Strict TypeScript types and parser for Baijimu CModel Error Contract `1.0.0`.
4
4
 
5
5
  ```bash
6
- npm install @baijimu/cmodel@1.0.2
6
+ npm install @baijimu/cmodel@1.1.0
7
7
  ```
8
8
 
9
9
  ```ts
@@ -1 +1 @@
1
- {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,EAQpB,MAAM,YAAY,CAAC;AAqBpB,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK1C;AAED,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC,CAAC;AAEhE,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,GACvB,cAAc,CAAC,CAAC,CAAC,CAwEnB"}
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../src/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,EAQpB,MAAM,YAAY,CAAC;AAqBpB,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK1C;AAED,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC,CAAC;AAEhE,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,OAAO,EACd,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,GACvB,cAAc,CAAC,CAAC,CAAC,CAiEnB"}
package/dist/parser.js CHANGED
@@ -26,14 +26,7 @@ export class CModelContractError extends Error {
26
26
  }
27
27
  }
28
28
  export function parseCModelResponse(httpStatus, input, parseData) {
29
- const envelope = objectAt(input, "$", [
30
- "contractVersion",
31
- "errorCode",
32
- "value",
33
- "data",
34
- "systemCurrentTime",
35
- "error",
36
- ]);
29
+ const envelope = envelopeAt(input, "$");
37
30
  requiredKeys(envelope, "$", [
38
31
  "contractVersion",
39
32
  "errorCode",
@@ -223,6 +216,11 @@ function objectAt(input, path, allowedKeys) {
223
216
  fail(`${path}.${key}`, "unknown field");
224
217
  return value;
225
218
  }
219
+ function envelopeAt(input, path) {
220
+ if (typeof input !== "object" || input === null || Array.isArray(input))
221
+ fail(path, "must be an object");
222
+ return input;
223
+ }
226
224
  function requiredKeys(value, path, keys) {
227
225
  for (const key of keys)
228
226
  if (!(key in value))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baijimu/cmodel",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Strict TypeScript parser and types for the Baijimu CModel Error Contract",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",