-
Notifications
You must be signed in to change notification settings - Fork 0
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
4 changed files
with
71 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# ![Virtua SA logo](https://www.virtua.ch/favicon.png) VPX - Virtua Parse eXtender :: Changelog | ||
|
||
## 1.0.1 | ||
|
||
* Add `VpxLoggedEntities` configuration to force *VPX* to monitor only given entities | ||
* *VPX* is now able to run Parse Server intances older than 2.7.2 | ||
|
||
## 1.0.0 - First public release | ||
|
||
*VPX* supports for now : | ||
|
||
* Entity operation logging (`created`, `updated`, `deleted`) in `VpxOperationEntityLog` | ||
* Custom cloud code execution (stored in `VpxCustomCloudCode`, called with `vpx-exec-ccc`) |
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 |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
``` | ||
3. Restart your Parse server. | ||
|
||
Note : *VPX* requires at least `[email protected]` to work properly, but it has been made compatible in a degraded mode for older versions. | ||
|
||
## Usage | ||
|
||
*VPX* will monitor every modification made on user Parse entities and log them in the class `VpxEntityOperationLog`: | ||
|
@@ -37,6 +39,7 @@ These parameters can be created with Parse Dashboard in `Config > Create a param | |
| Parameter | Type | Default value | Description | ||
| :-------------------- | :------- | :---------------------------------- | :------------------------------------------- | ||
| `VpxCustomCloudCode` | `String` | `null` | Your custom cloud code to run on Parse server | ||
| `VpxLoggedEntities` | `Array` | `null` | Names of entities to monitor, use `null` to let *VPX* discover new entities | ||
| `VpxLoggedOperations` | `Array` | `["created", "updated", "deleted"]` | Operation types allowed to be logged | ||
|
||
## Jobs | ||
|
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 |
---|---|---|
|
@@ -21,6 +21,12 @@ | |
//var Parse = require('parse/node'); | ||
|
||
function VirtuaParseExtended() { | ||
/** | ||
* Operation on these entities are logged by VPX. | ||
* @type string[] | ||
*/ | ||
var currentLoggedOperationEntities = []; | ||
|
||
/** | ||
* Custom script that can be evaluated. | ||
* @private | ||
|
@@ -37,9 +43,11 @@ function VirtuaParseExtended() { | |
|
||
/** | ||
* Operation on these entities will be logged by VPX. | ||
* An empty array means no entities will be monitored, | ||
* a null value means all entities will be monitored. | ||
* @type string[] | ||
*/ | ||
var loggedOperationEntities = []; | ||
var loggedOperationEntities = null; | ||
|
||
/** | ||
* Initialize VPX. | ||
|
@@ -48,15 +56,19 @@ function VirtuaParseExtended() { | |
this.init = function() { | ||
console.info('[VPX] Initializing ...'); | ||
// Create the VpxEntityOperationLog collection if needed | ||
var schema = new Parse.Schema('VpxEntityOperationLog'); | ||
schema.get().catch(function(error) { | ||
const schema = new Parse.Schema('VpxEntityOperationLog'); | ||
schema.addString('targetClass') | ||
.addString('targetId') | ||
.addString('operation'); | ||
schema.save(); | ||
console.info('[VPX] VpxEntityOperationLog schema created.'); | ||
}); | ||
if (typeof Parse.Schema === "function") { | ||
var schema = new Parse.Schema('VpxEntityOperationLog'); | ||
schema.get().catch(function(error) { | ||
const schema = new Parse.Schema('VpxEntityOperationLog'); | ||
schema.addString('targetClass') | ||
.addString('targetId') | ||
.addString('operation'); | ||
schema.save(); | ||
console.info('[VPX] VpxEntityOperationLog schema created.'); | ||
}); | ||
} else { | ||
console.warn('[VPX] VpxEntityOperationLog schema cannot be created, please upgrade to [email protected] !'); | ||
} | ||
// Register jobs | ||
Parse.Cloud.job('vpx-reload', reloadJob); | ||
Parse.Cloud.job('vpx-exec-ccc', execCustomCloudCodeJob); | ||
|
@@ -114,33 +126,47 @@ function VirtuaParseExtended() { | |
}); | ||
} | ||
|
||
/** | ||
* Register triggers on user Parse entities. | ||
* @argument object entity | ||
*/ | ||
monitorEntityOperation = function(className) { | ||
// Skip Parse Core entities, the log itself and already monitored entities | ||
if (!(className.startsWith('_') || className == 'VpxEntityOperationLog' || currentLoggedOperationEntities.includes(className))) { | ||
console.info('[VPX] Processing : ' + className + ' ...'); | ||
Parse.Cloud.afterSave(className, afterSaveTrigger); | ||
Parse.Cloud.afterDelete(className, afterDeleteTrigger); | ||
currentLoggedOperationEntities.push(className); | ||
console.info('[VPX] Registred entity for operation logging: ' + className); | ||
} | ||
} | ||
|
||
/** | ||
* Loads configuration of Virtua Parse eXtended. | ||
* @returns void | ||
*/ | ||
load = function() { | ||
console.log('[VPX] Already monitored entities: ' + loggedOperationEntities); | ||
// Register the triggers for every entities managed by Parse | ||
Parse.Schema.all().then(function(result) { | ||
result.forEach(function(entity) { | ||
var className = entity.className; | ||
// Skip Parse Core entities, the log itself and already monitored entities | ||
if (!(className.startsWith('_') || className == 'VpxEntityOperationLog' || loggedOperationEntities.includes(className))) { | ||
console.info('[VPX] Processing : ' + className + ' ...'); | ||
Parse.Cloud.afterSave(className, afterSaveTrigger); | ||
Parse.Cloud.afterDelete(className, afterDeleteTrigger); | ||
loggedOperationEntities.push(className); | ||
console.info('[VPX] Registred entity for operation logging: ' + className); | ||
} | ||
}); | ||
console.log('[VPX] Monitored entities: ' + loggedOperationEntities); | ||
}); | ||
// Load configuration | ||
Parse.Config.get().then(function(config) { | ||
customCloudCode = config.get('VpxCustomCloudCode') || customCloudCode; | ||
loggedOperationEntities = config.get('VpxLoggedEntities') || loggedOperationEntities; | ||
loggedOperationTypes = config.get('VpxLoggedOperations') || loggedOperationTypes; | ||
console.info('[VPX] VpxCustomCloudCode: ' + customCloudCode); | ||
console.info('[VPX] VpxLoggedEntities: ' + loggedOperationEntities); | ||
console.info('[VPX] VpxLoggedOperations: ' + loggedOperationTypes); | ||
console.info('[VPX] Already monitored entities: ' + currentLoggedOperationEntities); | ||
// Register the triggers for every entities managed by Parse | ||
if (loggedOperationEntities === null && typeof Parse.Schema === "function") { | ||
console.info('[VPX] Discovering new entities to monitor ...'); | ||
Parse.Schema.all().then(function(result) { | ||
result.map(x => x.className).forEach(monitorEntityOperation); | ||
console.info('[VPX] Monitored entities: ' + currentLoggedOperationEntities); | ||
}); | ||
} else { | ||
console.info('[VPX] Using value of VpxLoggedEntities to register new entities to monitor ...'); | ||
loggedOperationEntities.forEach(monitorEntityOperation); | ||
console.info('[VPX] Monitored entities: ' + currentLoggedOperationEntities); | ||
} | ||
}); | ||
} | ||
|
||
|
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