Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function findItemsByJsonPath(jsonPath: string): ValidationItem[] {
if (!jsonPath) {
return [];
}
const item = findItemByExactJsonPathMatch(jsonPath);
if (typeof item !== "undefined") {
// --- we will stop if we find an exact matched item
return [item];
}
const items: ValidationItem[] = [];
const stateData = getStateData();
JsonPath.paths(stateData, jsonPath)
.map(item => JsonPath.stringify(item))
.forEach(resolvedJsonPath => {
const item = findItemByExactJsonPathMatch(resolvedJsonPath);
if (typeof item !== "undefined") {
items.push(item);
}
});
return items;
}
processInArray(keyword: string, source: any, sourceArray: any[], sourceArrayIndex: number, resultArray: any[], resultArrayIndex: number, target: any[]) {
const keywordValue: MatchKeywordValue = source[keyword];
let matchedResultArrayIndex: number;
// Handle $match.index
if (keywordValue.index !== undefined) {
matchedResultArrayIndex = keywordValue.index === "-" ? resultArray.length - 1 : keywordValue.index;
}
// Handle $match.query
else if (keywordValue.query !== undefined) {
// Try to find a matching item in the result
const path = jsonpath.paths(resultArray, keywordValue.query)[0];
matchedResultArrayIndex = path !== undefined ? path[1] as number : undefined;
}
// Handle $match.path
else if (keywordValue.path !== undefined) {
// Try to find a matching item in the result
if (jsonPtr.get(resultArray, keywordValue.path) !== undefined) {
[matchedResultArrayIndex] = jsonPtr.decodePointer(keywordValue.path)[0];
}
}
// Ignore the item if no match found
if (matchedResultArrayIndex === undefined || resultArray[matchedResultArrayIndex] === undefined) {
return {resultArray, resultArrayIndex};
}
const getFieldPaths = (schema, config = defaultConfig) => {
const typeFieldName = config.fieldNames.type; // 'type' by default
let paths = jp.paths(schema, `$..[?(@.${typeFieldName} && @.${typeFieldName}!="object")]`);
// Array path ['$','properties','field'] to jsonPath '$.properties.field'
paths = paths.map(path => jp.stringify(path));
// Remove 'definitions' fields
paths = paths.filter(path => !path.includes('.definitions.'));
logger.debug(`Paths that must be normalized ${JSON.stringify(paths)}`);
return paths;
};
public * GetDocumentLocations(jsonQuery: string): Iterable {
for (const path of paths(this.fullyResolvedAndMergedDefinition, jsonQuery)) {
for (const mappingItem of this.fullyResolvedAndMergedDefinitionMap.LookupPath(path.slice(1))) {
yield {
uri: mappingItem.source,
range: {
start: {
line: mappingItem.originalLine - 1, // VS Code deviates from the source map standard here... 0 vs. 1 based line numbers
character: mappingItem.originalColumn
},
end: {
line: mappingItem.originalLine - 1,
character: mappingItem.originalColumn // TODO: room for improvement. think there even is extended information in `name`!
}
}
};
}
}
deleteKey: function (path) {
const parent = jp.parent(this.jsonObj, path);
const paths = jp.paths(this.jsonObj, path);
const item = paths[0].pop();
if (Array.isArray(parent)) {
parent.splice(item, 1);
} else {
delete parent[item];
}
}
}
const idx = validationFieldList.findIndex(fieldPath => {
if (
JsonPath.paths(stateData, fieldPath)
.map(item => JsonPath.stringify(item))
.indexOf(jsonPath) !== -1
) {
return true;
} else {
return false;
}
});
if (idx !== -1) {
function parseSettings(i18next, settings, locale) {
const clonedSettings = cloneDeep(settings);
i18next.changeLanguage(locale);
jsonpath
.paths(clonedSettings, JSON_PATH_EXPRESSION)
.forEach(jsonpaths => setTranslate(i18next, clonedSettings, jsonpaths));
return clonedSettings;
}
module.exports = (parent, child, tagPath, document) => {
const tagPathLeaf = jp.paths(document, jpify(tagPath)).pop().pop();
return _.snakeCase([parent, child, tagPathLeaf]);
};
simplifyQueryItems(object) {
const paths = jp.paths(object, `$..items`)
paths.forEach(path => {
path.pop()
jp.apply(object, jp.stringify(path), (value) => {
if (value.in === 'query') {
value.items = { type: 'string' }
}
return value
})
})
}