Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: replace jsonpath with equivalents due to inability to handle bi… #32

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"dependencies": {
"@openactive/data-model-validator": "^2.0.0",
"cache-parser": "^1.2.4",
"jsonpath": "^1.1.1",
"lodash": "^4.17.21",
"luxon": "^1.4.2",
"node-fetch": "^2.2.0"
Expand Down
9 changes: 3 additions & 6 deletions src/rules/page/after-change-number-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const {
ValidationErrorCategory,
ValidationErrorSeverity,
} = require('@openactive/data-model-validator');
const jp = require('jsonpath');
const _ = require('lodash');
const RpdeRule = require('../../rpde-rule');
const RpdeErrorType = require('../../errors/rpde-error-type');
const UrlHelper = require('../../helpers/url-helper');
Expand Down Expand Up @@ -53,12 +53,9 @@ class AfterChangeNumberRule extends RpdeRule {
const lastChangeNumber = UrlHelper.getParam('afterChangeNumber', node.url) || this.lastChangeNumber;
const afterChangeNumber = UrlHelper.getParam('afterChangeNumber', node.data.next, node.url);
if (afterChangeNumber !== null) {
const modified = jp.query(node.data, '$.items[0].modified');
const modified = _.get(node.data, 'items[0].modified');
if (
modified.length === 0
|| (
typeof modified[0] !== 'number'
&& !modified[0].match(/^[1-9][0-9]*$/)
_.isNil(modified) || (typeof modified !== 'number' && !modified.match(/^[1-9][0-9]*$/)
)
) {
node.log.addPageError(
Expand Down
14 changes: 7 additions & 7 deletions src/rules/page/after-timestamp-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const {
ValidationErrorCategory,
ValidationErrorSeverity,
} = require('@openactive/data-model-validator');
const jp = require('jsonpath');
const _ = require('lodash');
const RpdeRule = require('../../rpde-rule');
const RpdeErrorType = require('../../errors/rpde-error-type');
const UrlHelper = require('../../helpers/url-helper');
Expand Down Expand Up @@ -93,15 +93,15 @@ class AfterTimestampRule extends RpdeRule {
const afterTimestamp = UrlHelper.getParam('afterTimestamp', node.data.next, node.url);
const afterId = UrlHelper.getParam('afterId', node.data.next, node.url);
if (afterTimestamp !== null) {
const modified = jp.query(node.data, '$.items[0].modified');
const modified = _.get(node.data, 'items[0].modified');
if (modified.length !== 0) {
if (
typeof modified[0] === 'number'
|| modified[0].match(/^[1-9][0-9]*$/)
typeof modified === 'number'
|| modified.match(/^[1-9][0-9]*$/)
) {
if (
typeof modified[0] === 'string'
&& modified[0].match(/^[1-9][0-9]*$/)
typeof modified === 'string'
&& modified.match(/^[1-9][0-9]*$/)
) {
node.log.addPageError(
node.url,
Expand Down Expand Up @@ -187,7 +187,7 @@ class AfterTimestampRule extends RpdeRule {

// Do we have a last item that matches afterId and afterTimestamp?
if (node.data.items.length > 0) {
const lastItem = jp.query(node.data, `$.items[${node.data.items.length - 1}]`)[0];
const lastItem = _.get(node.data, `items[${node.data.items.length - 1}]`);
const lastItemModified = lastItem.modified;
const lastItemId = lastItem.id;
const lastItemCompare = {
Expand Down
6 changes: 3 additions & 3 deletions src/rules/page/deleted-items-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const {
ValidationErrorCategory,
ValidationErrorSeverity,
} = require('@openactive/data-model-validator');
const jp = require('jsonpath');
const _ = require('lodash');
const RpdeRule = require('../../rpde-rule');
const RpdeErrorType = require('../../errors/rpde-error-type');

Expand Down Expand Up @@ -30,8 +30,8 @@ const DeletedItemsRule = class extends RpdeRule {
return;
}
if (!this.deletedItemsFound) {
const deleted = jp.query(node.data, '$..items[?(@.state=="deleted")]');
if (deleted.length > 0) {
const hasDeleted = _.isArray(node.data.items) && node.data.items.some((item) => item.state === 'deleted');
if (hasDeleted) {
this.deletedItemsFound = true;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/rules/page/duplicate-items-rule.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const {
ValidationErrorCategory,
ValidationErrorSeverity,
} = require('@openactive/data-model-validator');
const jp = require('jsonpath');
const _ = require('lodash');
const RpdeRule = require('../../rpde-rule');
const RpdeErrorType = require('../../errors/rpde-error-type');

Expand Down Expand Up @@ -34,7 +34,7 @@ const DuplicateItemsRule = class extends RpdeRule {
if (typeof node.data !== 'object' || node.isItemDuplicationPermissible) {
return;
}
const ids = jp.query(node.data, '$.items[*].id');
const ids = (_.isArray(node.data.items) && node.data.items.map((item) => item.id)) || [];
for (const id of ids) {
if (this.itemMap.indexOf(id) >= 0) {
node.log.addPageError(
Expand Down
Loading