-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: track logical paths in recursive validation functions
Signed-off-by: Dan Hudlow <[email protected]>
- Loading branch information
Showing
8 changed files
with
658 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/** | ||
* Copyright 2024 IBM Corporation. | ||
* SPDX-License-Identifier: Apache2.0 | ||
*/ | ||
|
||
'use strict'; | ||
|
||
/** | ||
* @private | ||
*/ | ||
class SchemaPath extends Array { | ||
constructor(physical, logical = []) { | ||
super(...physical); | ||
this.logical = Object.freeze([...logical]); | ||
Object.freeze(this); | ||
} | ||
|
||
withProperty(name) { | ||
return new SchemaPath( | ||
[...this, 'properties', name], | ||
[...this.logical, name] | ||
); | ||
} | ||
|
||
withAdditionalProperty() { | ||
return new SchemaPath( | ||
[...this, 'additionalProperties'], | ||
[...this.logical, '*'] | ||
); | ||
} | ||
|
||
withPatternProperty(pattern) { | ||
return new SchemaPath( | ||
[...this, 'patternProperties', pattern], | ||
[...this.logical, '*'] | ||
); | ||
} | ||
|
||
withArrayItem() { | ||
return new SchemaPath([...this, 'items'], [...this.logical, '[]']); | ||
} | ||
|
||
withApplicator(applicator, index) { | ||
return new SchemaPath([...this, applicator, index], this.logical); | ||
} | ||
|
||
withNot() { | ||
return new SchemaPath([...this, 'not'], this.logical); | ||
} | ||
} | ||
|
||
module.exports = SchemaPath; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.