Skip to content

Commit

Permalink
fix(core): update nimma & json-schema (#2012)
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Dec 29, 2021
1 parent 84f6d72 commit 67a6104
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 62 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"jest": "^27.4.3",
"jest-mock": "^27.4.2",
"jest-when": "^3.4.2",
"json-schema": "^0.3.0",
"json-schema": "^0.4.0",
"karma": "^6.1.1",
"karma-chrome-launcher": "^3.1.0",
"karma-jasmine": "^3.3.1",
Expand Down
8 changes: 4 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@
},
"dependencies": {
"@stoplight/better-ajv-errors": "1.0.1",
"@stoplight/json": "3.17.0",
"@stoplight/json": "~3.17.1",
"@stoplight/lifecycle": "2.3.2",
"@stoplight/path": "1.3.2",
"@stoplight/spectral-parsers": "^1.0.0",
"@stoplight/spectral-ref-resolver": "^1.0.0",
"@stoplight/spectral-runtime": "^1.0.0",
"@stoplight/types": "12.3.0",
"ajv": "~8.6.0",
"ajv": "^8.6.0",
"ajv-errors": "~3.0.0",
"ajv-formats": "~2.1.0",
"blueimp-md5": "2.18.0",
"json-schema": "0.3.0",
"json-schema": "0.4.0",
"jsonpath-plus": "6.0.1",
"lodash": "~4.17.21",
"lodash.topath": "^4.5.2",
"minimatch": "3.0.4",
"nimma": "0.1.6",
"nimma": "0.1.7",
"simple-eval": "1.0.0",
"tslib": "^2.3.0"
},
Expand Down
45 changes: 18 additions & 27 deletions packages/core/src/runner/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Ruleset } from '../ruleset/ruleset';
import Nimma, { Callback } from 'nimma/legacy'; // legacy = Node v12, nimma without /legacy supports only 14+
import { jsonPathPlus } from 'nimma/fallbacks';
import { isPlainObject } from '@stoplight/json';
import { isAggregateError } from '../guards/isAggregateError';

export class Runner {
public readonly results: IRuleResult[];
Expand Down Expand Up @@ -96,30 +95,22 @@ function execute(input: unknown, callbacks: Record<string, Callback[]>, jsonPath
return;
}

try {
const nimma = new Nimma(jsonPathExpressions, {
fallback: jsonPathPlus,
unsafe: false,
output: 'auto',
});

nimma.query(
input,
Object.entries(callbacks).reduce<Record<string, Callback>>((mapped, [key, cbs]) => {
mapped[key] = scope => {
for (const cb of cbs) {
cb(scope);
}
};

return mapped;
}, {}),
);
} catch (e) {
if (isAggregateError(e) && e.errors.length === 1) {
throw e.errors[0];
} else {
throw e;
}
}
const nimma = new Nimma(jsonPathExpressions, {
fallback: jsonPathPlus,
unsafe: false,
output: 'auto',
});

nimma.query(
input,
Object.entries(callbacks).reduce<Record<string, Callback>>((mapped, [key, cbs]) => {
mapped[key] = scope => {
for (const cb of cbs) {
cb(scope);
}
};

return mapped;
}, {}),
);
}
29 changes: 22 additions & 7 deletions packages/functions/src/__tests__/__helpers__/tester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,26 @@ export default async function <O = unknown>(
},
});

const results = await s.run(input instanceof Document ? input : JSON.stringify(input));
return results
.filter(result => result.code === 'my-rule')
.map(error => ({
path: error.path,
message: error.message,
}));
try {
const results = await s.run(input instanceof Document ? input : JSON.stringify(input));
return results
.filter(result => result.code === 'my-rule')
.map(error => ({
path: error.path,
message: error.message,
}));
} catch (e: unknown) {
if (
e instanceof Error &&
Array.isArray((e as Error & { errors?: unknown }).errors) &&
(e as Error & { errors: unknown[] }).errors.length === 1
) {
const actualError = (e as Error & { errors: [unknown] }).errors[0];
throw actualError instanceof Error && 'cause' in (actualError as Error & { cause?: unknown })
? (actualError as Error & { cause: unknown }).cause
: actualError;
} else {
throw e;
}
}
}
46 changes: 23 additions & 23 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2028,7 +2028,7 @@ __metadata:
resolution: "@stoplight/spectral-core@workspace:packages/core"
dependencies:
"@stoplight/better-ajv-errors": 1.0.1
"@stoplight/json": 3.17.0
"@stoplight/json": ~3.17.1
"@stoplight/lifecycle": 2.3.2
"@stoplight/path": 1.3.2
"@stoplight/spectral-formats": "*"
Expand All @@ -2041,16 +2041,16 @@ __metadata:
"@types/json-schema": ^7.0.7
"@types/minimatch": ^3.0.5
"@types/treeify": ^1.0.0
ajv: ~8.6.0
ajv: ^8.6.0
ajv-errors: ~3.0.0
ajv-formats: ~2.1.0
blueimp-md5: 2.18.0
json-schema: 0.3.0
json-schema: 0.4.0
jsonpath-plus: 6.0.1
lodash: ~4.17.21
lodash.topath: ^4.5.2
minimatch: 3.0.4
nimma: 0.1.6
nimma: 0.1.7
nock: ^13.1.0
simple-eval: 1.0.0
treeify: ^1.1.0
Expand Down Expand Up @@ -3068,12 +3068,12 @@ __metadata:
languageName: node
linkType: hard

"astring@npm:^1.7.5":
version: 1.7.5
resolution: "astring@npm:1.7.5"
"astring@npm:^1.7.5, astring@npm:^1.8.1":
version: 1.8.1
resolution: "astring@npm:1.8.1"
bin:
astring: bin/astring
checksum: b432c3f35473ccb7ae715c9e7f5f2ea3eb6864809396d5a0cd4a00959bced3d8aaddf3d87a86e5c0f2f00a210fe789c2835e9dc48ac7c6dfe8be483f655a9490
checksum: 2a86ff8cc0c8f25694865cb8b22cdff784b8a0b115bd970c3def864618f22fe6ea78c3bef3ecdc359b2e5eb254a16d408ab06fa52a44e887b298cbf980a8083c
languageName: node
linkType: hard

Expand Down Expand Up @@ -7019,10 +7019,10 @@ __metadata:
languageName: node
linkType: hard

"jsep@npm:^1.1.2":
version: 1.1.2
resolution: "jsep@npm:1.1.2"
checksum: 189f29e522eec611793fcc81e8dbf919ecc1e9dd7858b9e34e32461280ae35e89a14ada91f8715b38650717b1571ab4480a46f53d60513079882ccc103f5b9c1
"jsep@npm:^1.1.2, jsep@npm:^1.2.0":
version: 1.2.0
resolution: "jsep@npm:1.2.0"
checksum: 7166871e91f6be3409658b7417955a72bba4341b664e9cf062c9e0150e7f465aedc4d8fbb67e7967e3c224cbb41f155a0c16df489614421578cb96f1ba1c5519
languageName: node
linkType: hard

Expand Down Expand Up @@ -7099,10 +7099,10 @@ __metadata:
languageName: node
linkType: hard

"json-schema@npm:0.3.0, json-schema@npm:^0.3.0":
version: 0.3.0
resolution: "json-schema@npm:0.3.0"
checksum: 5287563499c05e156b88fd3998b53fc4bccd29a6233c9b4417d36f8f34bf56d586388745a92a9dccd15822f63c360c045973c12eb4a6a4b4f3fd8fb864d80a14
"json-schema@npm:0.4.0, json-schema@npm:^0.4.0":
version: 0.4.0
resolution: "json-schema@npm:0.4.0"
checksum: 66389434c3469e698da0df2e7ac5a3281bcff75e797a5c127db7c5b56270e01ae13d9afa3c03344f76e32e81678337a8c912bdbb75101c62e487dc3778461d72
languageName: node
linkType: hard

Expand Down Expand Up @@ -7989,22 +7989,22 @@ __metadata:
languageName: node
linkType: hard

"nimma@npm:0.1.6":
version: 0.1.6
resolution: "nimma@npm:0.1.6"
"nimma@npm:0.1.7":
version: 0.1.7
resolution: "nimma@npm:0.1.7"
dependencies:
"@jsep-plugin/regex": ^1.0.1
"@jsep-plugin/ternary": ^1.0.2
astring: ^1.7.5
jsep: ^1.1.2
astring: ^1.8.1
jsep: ^1.2.0
jsonpath-plus: ^6.0.1
lodash.topath: ^4.5.2
dependenciesMeta:
jsonpath-plus:
optional: true
lodash.topath:
optional: true
checksum: aca1ac2838049f541444f5da3fcc178692344cc1f8c0c87cd40f3e7e3a92e8b0b14ad391e7a6cde7032a42741a9c3fb46b1752214d031650e606375d97e548db
checksum: 6dcf4aa3dd35c714142f04cfde76727202e1aea802cde0584ef35eabf45d217a9352c55e65045ff91956bb348b3b07ede4ca13af5a6bc8e7ce2f3b2ca353f9bd
languageName: node
linkType: hard

Expand Down Expand Up @@ -9301,7 +9301,7 @@ __metadata:
jest: ^27.4.3
jest-mock: ^27.4.2
jest-when: ^3.4.2
json-schema: ^0.3.0
json-schema: ^0.4.0
karma: ^6.1.1
karma-chrome-launcher: ^3.1.0
karma-jasmine: ^3.3.1
Expand Down

0 comments on commit 67a6104

Please sign in to comment.