ddf-query-validator
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -9,3 +9,3 @@ "use strict"; | ||
const { dataset, branch, commit } = queryParam; | ||
return `${basePath}${dataset}/${branch}-${commit}`; | ||
return `${basePath}${dataset}/${branch}/${commit}`; | ||
} | ||
@@ -19,3 +19,3 @@ exports.getRepositoryPath = getRepositoryPath; | ||
const REPOSITORY_DESCRIPTORS = get(config, 'repositoryDescriptors', {}); | ||
const IS_DEFAULT_DATASET = isNil(queryParam.dataset) ? 'default ' : ''; | ||
const IS_DEFAULT_DATASET = isNil(queryParam.dataset); | ||
if (!IS_DEFAULT_DATASET) { | ||
@@ -28,13 +28,17 @@ const [originDataset, originBranch] = queryParam.dataset.split('#'); | ||
} | ||
const IS_DEFAULT_BRANCH = isNil(queryParam.branch) ? 'default ' : ''; | ||
const IS_DEFAULT_COMMIT = isNil(queryParam.commit) ? 'default ' : ''; | ||
const { dataset = get(config, 'defaultRepository', helper_service_1.DEFAULT_REPOSITORY_NAME), branch = get(config, 'defaultRepositoryBranch', helper_service_1.DEFAULT_REPOSITORY_BRANCH), commit = get(config, 'defaultRepositoryCommit', helper_service_1.DEFAULT_REPOSITORY_HASH) } = queryParam; | ||
const IS_DEFAULT_BRANCH = isNil(queryParam.branch); | ||
const IS_DEFAULT_COMMIT = isNil(queryParam.commit); | ||
const { dataset = get(config, 'defaultRepository', helper_service_1.DEFAULT_REPOSITORY_NAME), branch = get(config, 'defaultRepositoryBranch', helper_service_1.DEFAULT_REPOSITORY_BRANCH) } = queryParam; | ||
if (isNil(REPOSITORY_DESCRIPTORS[dataset])) { | ||
throw new Error(`No ${IS_DEFAULT_DATASET}dataset '${dataset}' was found`); | ||
throw new Error(`No ${printDataset(dataset, IS_DEFAULT_DATASET)} was found`); | ||
} | ||
if (isNil(REPOSITORY_DESCRIPTORS[dataset][branch])) { | ||
throw new Error(`No ${IS_DEFAULT_BRANCH}branch '${branch}' in ${IS_DEFAULT_DATASET}dataset '${dataset}' was found`); | ||
throw new Error(`No ${printBranch(branch, IS_DEFAULT_BRANCH)} in ${printDataset(dataset, IS_DEFAULT_DATASET)} was found`); | ||
} | ||
if (queryParam.commit === 'HEAD') { | ||
queryParam.commit = get(REPOSITORY_DESCRIPTORS, `${dataset}.${branch}.0`) || get(config, 'defaultRepositoryCommit', helper_service_1.DEFAULT_REPOSITORY_HASH); | ||
} | ||
const { commit = get(REPOSITORY_DESCRIPTORS, `${dataset}.${branch}.0`) || get(config, 'defaultRepositoryCommit', helper_service_1.DEFAULT_REPOSITORY_HASH) } = queryParam; | ||
if (!includes(REPOSITORY_DESCRIPTORS[dataset][branch], commit)) { | ||
throw new Error(`No ${IS_DEFAULT_COMMIT}commit '${commit}' in ${IS_DEFAULT_BRANCH}branch '${branch}' in ${IS_DEFAULT_DATASET}dataset '${dataset}' was found`); | ||
throw new Error(`No ${printCommit(commit, IS_DEFAULT_COMMIT)} in ${printDefault(IS_DEFAULT_BRANCH)}branch '${branch}' in ${printDataset(dataset, IS_DEFAULT_DATASET)} was found`); | ||
} | ||
@@ -45,2 +49,14 @@ const repositoryPath = getRepositoryPath('', { dataset, branch, commit }); | ||
exports.extendQueryWithRepository = extendQueryWithRepository; | ||
function printDefault(isSomethingTrue) { | ||
return isSomethingTrue ? 'default ' : ''; | ||
} | ||
function printDataset(dataset, IS_DEFAULT_DATASET) { | ||
return `${printDefault(IS_DEFAULT_DATASET)}dataset '${dataset}'`; | ||
} | ||
function printBranch(branch, IS_DEFAULT_BRANCH) { | ||
return `${printDefault(IS_DEFAULT_BRANCH)}branch '${branch}'`; | ||
} | ||
function printCommit(commit, IS_DEFAULT_COMMIT) { | ||
return `${printDefault(IS_DEFAULT_COMMIT)}commit '${commit}'`; | ||
} | ||
//# sourceMappingURL=dataset-manager.service.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const isEmpty = require("lodash.isempty"); | ||
@@ -148,4 +147,4 @@ const isNil = require("lodash.isnil"); | ||
function validateSubqueries(query, options) { | ||
return flatMap(query.join, (join, joinID) => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
return yield validateQueryStructure({ | ||
return flatMap(query.join, async (join, joinID) => { | ||
return await validateQueryStructure({ | ||
select: { key: [join.key] }, | ||
@@ -158,3 +157,3 @@ where: join.where, | ||
}, Object.assign({ joinID }, cloneDeep(options))); | ||
})); | ||
}); | ||
} | ||
@@ -161,0 +160,0 @@ function checkIfSelectIsEmpty(selectClause) { |
{ | ||
"name": "ddf-query-validator", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "DDF query validator", | ||
@@ -41,4 +41,4 @@ "main": "lib/index.js", | ||
"lodash.filter": "4.6.0", | ||
"lodash.find": "^4.6.0", | ||
"lodash.findindex": "^4.6.0", | ||
"lodash.find": "4.6.0", | ||
"lodash.findindex": "4.6.0", | ||
"lodash.first": "3.0.0", | ||
@@ -59,3 +59,3 @@ "lodash.flatmap": "4.5.0", | ||
"lodash.size": "4.2.0", | ||
"lodash.startswith": "^4.2.1", | ||
"lodash.startswith": "4.2.1", | ||
"lodash.trimstart": "4.5.1", | ||
@@ -79,5 +79,5 @@ "lodash.uniq": "4.5.0", | ||
"tslint": "5.11.0", | ||
"tslint-no-unused-expression-chai": "^0.1.3", | ||
"tslint-no-unused-expression-chai": "0.1.3", | ||
"typescript": "3.0.1" | ||
} | ||
} |
@@ -6,3 +6,3 @@ import * as isNil from 'lodash.isnil'; | ||
export function getRepositoryPath (basePath, queryParam) { | ||
export function getRepositoryPath(basePath, queryParam) { | ||
const { | ||
@@ -13,17 +13,18 @@ dataset, | ||
} = queryParam; | ||
return `${basePath}${dataset}/${branch}-${commit}`; | ||
return `${basePath}${dataset}/${branch}/${commit}`; | ||
} | ||
export function getFilePath (repositoryPath, filePath = 'datapackage.json'): string { | ||
export function getFilePath(repositoryPath, filePath = 'datapackage.json'): string { | ||
return `${repositoryPath}/${filePath}`; | ||
} | ||
export function extendQueryWithRepository (queryParam, config = {}): Error | void { | ||
export function extendQueryWithRepository(queryParam, config = {}): Error | void { | ||
// TODO: refactor unit tests | ||
// const REPOSITORY_DESCRIPTORS = get(config, 'repositoryDescriptors', {[DEFAULT_REPOSITORY]: {[DEFAULT_BRANCH]: [DEFAULT_HASH]}}); | ||
const REPOSITORY_DESCRIPTORS = get(config, 'repositoryDescriptors', {}); | ||
const IS_DEFAULT_DATASET = isNil(queryParam.dataset) ? 'default ' : ''; | ||
const IS_DEFAULT_DATASET = isNil(queryParam.dataset); | ||
if (!IS_DEFAULT_DATASET) { | ||
const [originDataset, originBranch] = queryParam.dataset.split('#'); | ||
// Check if in dataset was given branch | ||
const [ originDataset, originBranch ] = queryParam.dataset.split('#'); | ||
if (!queryParam.branch && originBranch) { | ||
@@ -35,21 +36,30 @@ queryParam.branch = originBranch; | ||
const IS_DEFAULT_BRANCH = isNil(queryParam.branch) ? 'default ' : ''; | ||
const IS_DEFAULT_COMMIT = isNil(queryParam.commit) ? 'default ' : ''; | ||
const IS_DEFAULT_BRANCH = isNil(queryParam.branch); | ||
const IS_DEFAULT_COMMIT = isNil(queryParam.commit); | ||
const { | ||
dataset = get(config, 'defaultRepository', DEFAULT_REPOSITORY_NAME), | ||
branch = get(config, 'defaultRepositoryBranch', DEFAULT_REPOSITORY_BRANCH), | ||
commit = get(config, 'defaultRepositoryCommit', DEFAULT_REPOSITORY_HASH) | ||
branch = get(config, 'defaultRepositoryBranch', DEFAULT_REPOSITORY_BRANCH) | ||
} = queryParam; | ||
if (isNil(REPOSITORY_DESCRIPTORS[ dataset ])) { | ||
throw new Error(`No ${IS_DEFAULT_DATASET}dataset '${dataset}' was found`); | ||
throw new Error(`No ${printDataset(dataset, IS_DEFAULT_DATASET)} was found`); | ||
} | ||
if (isNil(REPOSITORY_DESCRIPTORS[ dataset ][ branch ])) { | ||
throw new Error(`No ${IS_DEFAULT_BRANCH}branch '${branch}' in ${IS_DEFAULT_DATASET}dataset '${dataset}' was found`); | ||
throw new Error(`No ${printBranch(branch, IS_DEFAULT_BRANCH)} in ${printDataset(dataset, IS_DEFAULT_DATASET)} was found`); | ||
} | ||
// We never know what the hash is the HEAD on a branch, so if we don't have a commit or it equals `HEAD` in a request, | ||
// it means we have to use the first hash in config (the HEAD commit will ALWAYS be on the first place) | ||
if (queryParam.commit === 'HEAD') { | ||
queryParam.commit = get(REPOSITORY_DESCRIPTORS, `${dataset}.${branch}.0`) || get(config, 'defaultRepositoryCommit', DEFAULT_REPOSITORY_HASH); | ||
} | ||
const { | ||
commit = get(REPOSITORY_DESCRIPTORS, `${dataset}.${branch}.0`) || get(config, 'defaultRepositoryCommit', DEFAULT_REPOSITORY_HASH) | ||
} = queryParam; | ||
if (!includes(REPOSITORY_DESCRIPTORS[ dataset ][ branch ], commit)) { | ||
throw new Error(`No ${IS_DEFAULT_COMMIT}commit '${commit}' in ${IS_DEFAULT_BRANCH}branch '${branch}' in ${IS_DEFAULT_DATASET}dataset '${dataset}' was found`); | ||
throw new Error(`No ${printCommit(commit, IS_DEFAULT_COMMIT)} in ${printDefault(IS_DEFAULT_BRANCH)}branch '${branch}' in ${printDataset(dataset, IS_DEFAULT_DATASET)} was found`); | ||
} | ||
@@ -61,1 +71,17 @@ | ||
} | ||
function printDefault(isSomethingTrue) { | ||
return isSomethingTrue ? 'default ' : ''; | ||
} | ||
function printDataset(dataset, IS_DEFAULT_DATASET) { | ||
return `${printDefault(IS_DEFAULT_DATASET)}dataset '${dataset}'`; | ||
} | ||
function printBranch(branch, IS_DEFAULT_BRANCH) { | ||
return `${printDefault(IS_DEFAULT_BRANCH)}branch '${branch}'`; | ||
} | ||
function printCommit(commit, IS_DEFAULT_COMMIT) { | ||
return `${printDefault(IS_DEFAULT_COMMIT)}commit '${commit}'`; | ||
} |
@@ -16,3 +16,3 @@ import * as chai from 'chai'; | ||
export const NOT_EXISTED_COMMIT = 'unexisted_commit'; | ||
export const EXISTED_COMMIT = 'HEAD'; | ||
export const EXISTED_COMMIT = 'existed_commit'; | ||
@@ -19,0 +19,0 @@ export const fromClauseCouldnotBeEmpty = new RegExp(`'from' clause couldn't be empty`); |
@@ -147,3 +147,3 @@ import { | ||
expect(fullQuery.repositoryPath).to.equal(`${EXPECTED_DATASET}/${EXPECTED_BRANCH}-${EXPECTED_COMMIT}`); | ||
expect(fullQuery.repositoryPath).to.equal(`${EXPECTED_DATASET}/${EXPECTED_BRANCH}/${EXPECTED_COMMIT}`); | ||
}); | ||
@@ -150,0 +150,0 @@ }); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
172223
2919
Updatedlodash.find@4.6.0
Updatedlodash.findindex@4.6.0
Updatedlodash.startswith@4.2.1