This repository has been archived by the owner on Mar 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
99 additions
and
17 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
'use strict'; | ||
|
||
const AError = require('./../../core/AzuriteError'), | ||
ErrorCodes = require('./../../core/ErrorCodes'); | ||
|
||
|
||
class ConflictingTable { | ||
constructor() { | ||
} | ||
|
||
validate({ table = undefined }) { | ||
if (table !== undefined) { | ||
throw new AError(ErrorCodes.TableAlreadyExists); | ||
} | ||
} | ||
} | ||
|
||
module.exports = new ConflictingTable; |
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,43 @@ | ||
'use strict'; | ||
|
||
/** | ||
* The in-memory DB of Azurite serves as the exclusive source of truth for every validation. | ||
* Since the validation is synchronous / single-threaded we can be certain about the exact state of the entire | ||
* application before and after @see ValidationContext exits. | ||
* | ||
* In case a validation fails an according @see AzuriteException is thrown which is then processed | ||
* by the validation middleware module middleware/table/validation.js | ||
* | ||
* @class ValidationContext | ||
*/ | ||
class ValidationContext { | ||
constructor({ request = undefined, table = undefined, entity = undefined }) { | ||
this.request = request; | ||
this.table = table; | ||
this.entity = entity; | ||
} | ||
|
||
/** | ||
* Runs a validation module. | ||
* | ||
* @param {Object} valModule | ||
* @param {Object} moduleOptions - allows a validation module to selectively add attributes or overwrite them | ||
* @param {boolean} skip - if set to true validation module is not run. | ||
* @returns this | ||
* | ||
* @memberOf ValidationContext | ||
*/ | ||
run(valModule, moduleOptions, skip) { | ||
if (skip) { | ||
return this; | ||
} | ||
valModule.validate({ | ||
request: moduleOptions ? moduleOptions.request || this.request : this.request, | ||
table: moduleOptions ? moduleOptions.table || this.table : this.table, | ||
entity: moduleOptions ? moduleOptions.entity || this.entity : this.entity, | ||
moduleOptions: moduleOptions }); | ||
return this; | ||
} | ||
} | ||
|
||
module.exports = ValidationContext; |