Socket
Socket
Sign inDemoInstall

28

Package Overview
Dependencies
107
Maintainers
1
Versions
100
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.5.3 to 1.0.0

tests/test_project3/public/#.foo.jq

77

lib/28.js
'use strict';
exports.$28 = function(apiEndpoint){
var syncLib = require('./sync');
var Options = syncLib.Options;
var Client = syncLib.Client;
var syncLib = require('./sync');
var Options = syncLib.Options;
var Client = syncLib.Client;
this.api = require('28.io-nodejs').$28(apiEndpoint);
this.Options = Options;
var that = this;
var $28 = (function(){
function $28(apiEndpoint){
this.api = require('28.io-nodejs').$28(apiEndpoint);
this.Options = Options;
}
this.sync = function(type, projectName, projectToken, localProjectPath, overwrite, deleteOrphaned, simulate, ignore) {
var client = new Client(that.api, projectName, projectToken, localProjectPath);
$28.prototype.sync = function(type, projectName, projectToken, localProjectPath, overwrite, deleteOrphaned, simulate, ignore) {
var client = new Client(this.api, projectName, projectToken, localProjectPath);
var method = type === 'download' ? client.download : client.upload;
return method(overwrite, deleteOrphaned, simulate, ignore);
return method.apply(client, [overwrite, deleteOrphaned, simulate, ignore]);
};
this.download = function(projectName, projectToken, localProjectPath, overwrite, deleteOrphaned, simulate, ignore) {
return that.sync('download', projectName, projectToken, localProjectPath, overwrite, deleteOrphaned, simulate, ignore);
$28.prototype.download = function(projectName, projectToken, localProjectPath, overwrite, deleteOrphaned, simulate, ignore) {
return this.sync('download', projectName, projectToken, localProjectPath, overwrite, deleteOrphaned, simulate, ignore);
};
this.upload = function(projectName, projectToken, localProjectPath, overwrite, deleteOrphaned, simulate, ignore) {
return that.sync('upload', projectName, projectToken, localProjectPath, overwrite, deleteOrphaned, simulate, ignore);
$28.prototype.upload = function(projectName, projectToken, localProjectPath, overwrite, deleteOrphaned, simulate, ignore) {
return this.sync('upload', projectName, projectToken, localProjectPath, overwrite, deleteOrphaned, simulate, ignore);
};
this.truncate = function(projectName, projectToken, simulate, ignore) {
var client = new Client(that.api, projectName, projectToken);
$28.prototype.truncate = function(projectName, projectToken, simulate, ignore) {
var client = new Client(this.api, projectName, projectToken);
return client.truncate(simulate, ignore);
};
this.refreshTokens = function(email, token){
return that.api.Auth.authenticate({
$28.prototype.refreshTokens = function(email, token){
return this.api.Auth.authenticate({
email: email,

@@ -39,4 +40,4 @@ refresh_token: token,

this.login = function(email, password) {
return that.api.Auth.authenticate({
$28.prototype.login = function(email, password) {
return this.api.Auth.authenticate({
email: email,

@@ -48,4 +49,4 @@ password: password,

this.createProject = function(projectName, token) {
return that.api.Project.createProject({
$28.prototype.createProject = function(projectName, token) {
return this.api.Project.createProject({
projectName: projectName,

@@ -57,4 +58,4 @@ package: 'free',

this.deleteProject = function(projectName, token){
return that.api.Project.deleteProject({
$28.prototype.deleteProject = function(projectName, token){
return this.api.Project.deleteProject({
name: projectName,

@@ -65,8 +66,8 @@ token: token

this.listDatasources = function(projectName, token){
return that.api.Datasources(projectName).listDatasources({ token: token});
$28.prototype.listDatasources = function(projectName, token){
return this.api.Datasources(projectName).listDatasources({ token: token});
};
this.createDatasource = function(projectName, category, name, token, difault, credentials){
return that.api.Datasources(projectName).createDatasource({
$28.prototype.createDatasource = function(projectName, category, name, token, difault, credentials){
return this.api.Datasources(projectName).createDatasource({
category: category,

@@ -80,4 +81,4 @@ name: name,

this.removeDatasource = function(projectName, category, datasource, projectToken){
return that.api.Datasources(projectName).removeDatasource({
$28.prototype.removeDatasource = function(projectName, category, datasource, projectToken){
return this.api.Datasources(projectName).removeDatasource({
category: category,

@@ -89,4 +90,4 @@ datasource: datasource,

this.getDefaultMongoDBCredentials = function(projectName, token){
return that.api.Project.getDefaultMongoDBCredentials({
$28.prototype.getDefaultMongoDBCredentials = function(projectName, token){
return this.api.Project.getDefaultMongoDBCredentials({
name: projectName,

@@ -97,6 +98,6 @@ token: token

this.updateDefaultMongoDBCredentials = function(
$28.prototype.updateDefaultMongoDBCredentials = function(
projectName, token, dbType, connString, db, username, password, preDigested
){
return that.api.Project.updateDefaultMongoDBCredentials({
return this.api.Project.updateDefaultMongoDBCredentials({
name: projectName,

@@ -113,3 +114,3 @@ token: token,

this.overwriteCoercion = function(value, cmd){
$28.prototype.overwriteCoercion = function(value, cmd){
value = value.toLowerCase();

@@ -129,2 +130,6 @@ if(value === 'yes' || value === 'all' || value === 'always') {

};
};
return $28;
})();
exports.$28 = $28;

@@ -33,3 +33,3 @@ 'use strict';

var localProjectPath = process.cwd();
method(
method.apply($28, [
projectName, projectToken, localProjectPath,

@@ -39,3 +39,5 @@ cmd.overwrite === undefined ? $28.Options.OVERWRITE_ASK : cmd.overwrite,

cmd.simulate ? true : false,
Config.filterQueries
function(queries){
return Config.filterQueries(queries);
}]
).then(function(){

@@ -42,0 +44,0 @@ console.log('All done.'.grey);

@@ -27,3 +27,5 @@ 'use strict';

}
var options = {};
var options = {
ignoreUnreadableDir: true
};
var localProjectPath = process.cwd();

@@ -60,3 +62,6 @@ var vfs = new VFS($28, projectName, projectToken, localProjectPath);

client.upload(
projectName, projectToken, localProjectPath, client.Options.OVERWRITE_ALWAYS, true, false, Config.filterQueries
projectName, projectToken, localProjectPath, client.Options.OVERWRITE_ALWAYS, true, false,
function(queries){
return Config.filterQueries(queries);
}
).finally(function(){

@@ -70,6 +75,3 @@ console.log(('Watching ' + localProjectPath + '...').grey);

var file = event.file;
var filtered = {};
filtered[file] = new Date();
Config.filterQueries(filtered);
if(Object.keys(filtered).length === 0) {
if(Config.filterQuery(file) === false) {
return;

@@ -76,0 +78,0 @@ }

@@ -10,17 +10,23 @@ 'use strict';

var $28;
// Settings
var defaultSettings = {
'access_token': '',
'refresh_token': '',
'project_tokens': {},
'email': '',
'protocol': 'https',
'project_name': 'portal',
'project_domain': '28.io',
'ignore': [],
'prefix': '/api'
};
exports.Config = {
load: function(){
var Config = (function(){
// Settings
var defaultSettings = {
'access_token': '',
'refresh_token': '',
'project_tokens': {},
'email': '',
'protocol': 'https',
'project_name': 'portal',
'project_domain': '28.io',
'ignore': [],
'prefix': '/api'
};
function Config() {
}
Config.prototype.load = function(){
this.settingFile = path.join(process.env.HOME || process.env.USERPROFILE || '', '.28.json');

@@ -36,5 +42,6 @@ var localSettingFile = process.cwd() + '/.28.json';

_.defaults(this.config, defaultSettings);
},
return this;
};
save: function(session){
Config.prototype.save = function(session){
if(!this.config){

@@ -50,5 +57,6 @@ throw new Error('No config file loaded. Use load()');

this.config.saveSync(this.settingFile);
},
return this;
};
getAPIEndpoint: function(){
Config.prototype.getAPIEndpoint = function(){
if(!this.config){

@@ -58,5 +66,5 @@ throw new Error('No config file loaded. Use load()');

return this.config.protocol + '://' + this.config.project_name + '.' + this.config.project_domain + this.config.prefix;
},
getAPIClient: function(){
};
Config.prototype.getAPIClient = function(){
if($28 === undefined) {

@@ -66,17 +74,17 @@ $28 = new $28API(this.getAPIEndpoint());

return $28;
},
getEmail: function(){
};
Config.prototype.getEmail = function(){
return this.config.email;
},
getRefreshToken: function(){
};
Config.prototype.getRefreshToken = function(){
return this.config.refresh_token;
},
getAccessToken: function(){
};
Config.prototype.getAccessToken = function(){
return this.config.access_token;
},
getProjectToken: function(projectName){
};
Config.prototype.getProjectToken = function(projectName){
var token = this.config.project_tokens['project_'+projectName];

@@ -87,48 +95,42 @@ if(!token) {

return token;
},
getIgnoreList: function(){
};
Config.prototype.getIgnoreList = function(){
return this.config.ignore;
},
};
filterQueries: function(list){
var ignore = [];
var illegalPath = function(path){
var legal = true;
path.split('/').forEach(function(segment){
if(segment !== encodeURIComponent(segment)) {
legal = false;
Config.prototype.filterQuery = function(path) {
if(path.substring(path.length - 3) !== '.jq' && path.substring(path.length - 3) !== '.xq') {
return false;
} else {
var matched = false;
this.config.ignore.forEach(function(mask){
if(path.match(mask) !== null) {
matched = true;
return false;
}
});
return !legal;
};
if(matched === true) {
return false;
}
return true;
}
};
Config.prototype.filterQueries = function(aList){
var that = this;
var list = _.clone(aList);
Object.keys(list).forEach(function(path){
//Filter files that don't have a .jq or .xq suffix
if(
(path.substring(path.length - 3) !== '.jq' &&
path.substring(path.length - 3) !== '.xq') || illegalPath(path)
) {
if(!that.filterQuery(path)) {
delete list[path];
} else {
var matched = false;
ignore.forEach(function(mask){
if(path.match(mask) !== null) {
matched = true;
return false;
}
});
if(matched === true) {
delete list[path];
}
}
});
return list;
},
getProjectList: function(){
};
Config.prototype.getProjectList = function(){
return Object.keys(this.config.project_tokens).map(function(project){ return project.substring('project_'.length); });
},
};
getProjects: function(){
Config.prototype.getProjects = function(){
var that = this;

@@ -139,5 +141,5 @@ var $28 = this.getAPIClient();

});
},
handleAPIAuthError: function(error){
};
Config.prototype.handleAPIAuthError = function(error){
if(error instanceof Error) {

@@ -153,5 +155,5 @@ if(error.getCode() === 'ENOTFOUND') {

process.exit(1);
},
handleAPIError: function(error){
};
Config.prototype.handleAPIError = function(error){
if(error instanceof Error) {

@@ -167,9 +169,9 @@ console.error(error.message.red);

process.exit(1);
},
};
refreshTokens: function(){
Config.prototype.refreshTokens = function () {
console.log('Refreshing Tokens...'.grey);
var $28 = this.getAPIClient();
var that = this;
return $28.refreshTokens(this.getEmail(), this.getRefreshToken()).then(function(response){
return $28.refreshTokens(this.getEmail(), this.getRefreshToken()).then(function (response) {
var session = response.body;

@@ -180,3 +182,3 @@ that.save(session);

var now = new Date();
if(Math.abs(now.getTime() - rem.getTime()) > 30 * 1000) {
if (Math.abs(now.getTime() - rem.getTime()) > 30 * 1000) {
console.error('\nWarning: the local and remote clocks seems to be out of sync.'.yellow);

@@ -189,7 +191,12 @@ console.error('Be careful if you plan on using synchronization features that rely on the files last modified date time.'.yellow);

})
.catch(function(error){
console.error('\nUse the login command again.'.red);
that.handleAPIAuthError(error);
});
}
};
.catch(function (error) {
console.error('\nUse the login command again.'.red);
that.handleAPIAuthError(error);
});
};
return Config;
})();
exports.Config = new Config();

@@ -9,111 +9,36 @@ 'use strict';

var loc = function(isOriginRemote){
return isOriginRemote ? 'remote' : 'local';
};
var logDiff = function(diff, simulate){
var msg;
if(diff.type === 'write') {
if(diff.isOriginRemote) {
msg = ('<< '.green) + ('↙ '.blue) + diff.query;
} else {
msg = ('>> '.green) + ('↗ '.blue) + diff.query;
}
} else {
msg = ('✗'.red) + ' <' + loc(!diff.isOriginRemote) + '>/' + diff.query;
}
if(simulate === true) {
msg += ' (simulate)';
}
if(diff.type === 'write') {
console.log(msg);
} else {
console.log(msg.red);
}
};
var Client = (function(){
var Options = {
OVERWRITE_ALWAYS: 0,
OVERWRITE_NEVER: 1,
OVERWRITE_ASK: 2,
OVERWRITE_IF_NEWER: 3
};
exports.Options = Options;
var Options = {
OVERWRITE_ALWAYS: 0,
OVERWRITE_NEVER: 1,
OVERWRITE_ASK: 2,
OVERWRITE_IF_NEWER: 3
};
exports.Options = Options;
exports.Client = function($28, projectName, projectToken, localProjectPath){
var vfs = new VFS($28, projectName, projectToken, localProjectPath);
var writeLocalQuery = function(diff){
return vfs.writeLocalQuery(diff.query).then(function(){ logDiff(diff); });
var loc = function(isOriginRemote){
return isOriginRemote ? 'remote' : 'local';
};
var writeRemoteQuery = function(diff){
return vfs.writeRemoteQuery(diff.query)
.then(function(compileError){
logDiff(diff);
if(compileError) {
throw compileError;
}
});
};
var deleteLocalQuery = function(diff){
return vfs.deleteLocalQuery(diff.query).then(function(){ logDiff(diff); });
};
var deleteRemoteQuery = function(diff){
return vfs.deleteRemoteQuery(diff.query).then(function(){ logDiff(diff); });
};
var commit = function(simulate, diffs){
var modulePromises = [];
var queryPromises = [];
diffs.forEach(function(diff){
var container = diff.query.substring(0, 'modules'.length) === 'modules' ? modulePromises : queryPromises;
if(simulate) {
logDiff(diff, simulate);
} else if(diff.type === 'write'){
if(diff.isOriginRemote) {
container.push(function(){ return writeLocalQuery(diff); });
} else {
container.push(function(){ return writeRemoteQuery(diff); });
}
var logDiff = function(diff, simulate){
var msg;
if(diff.type === 'write') {
if(diff.isOriginRemote) {
msg = ('<< '.green) + ('↙ '.blue) + diff.query;
} else {
if(diff.isOriginRemote) {
container.push(function(){ return deleteLocalQuery(diff); });
} else {
container.push(function(){ return deleteRemoteQuery(diff); });
}
msg = ('>> '.green) + ('↗ '.blue) + diff.query;
}
});
var handler = function(results){
var errors = [];
results.forEach(function (result) {
if (result.state !== 'fulfilled') {
errors.push(result.reason);
}
});
if(errors.length > 0) {
throw errors;
}
return results;
};
return [
function(){
var promises = [];
modulePromises.forEach(function(promise){
promises.push(promise());
});
return Q.allSettled(promises).then(handler);
},
function(){
var promises = [];
queryPromises.forEach(function(promise){
promises.push(promise());
});
return Q.allSettled(promises).then(handler);
}
].reduce(Q.when, new Q([]));
} else {
msg = ('✗'.red) + ' <' + loc(!diff.isOriginRemote) + '>/' + diff.query;
}
if(simulate === true) {
msg += ' (simulate)';
}
if(diff.type === 'write') {
console.log(msg);
} else {
console.log(msg.red);
}
};

@@ -132,3 +57,9 @@

var sync = function(localQueries, remoteQueries, overwrite, deleteOrphaned, simulate, isOriginRemote){
function Client($28, projectName, projectToken, localProjectPath){
this.vfs = new VFS($28, projectName, projectToken, localProjectPath);
}
Client.prototype.syncImpl = function(localQueries, remoteQueries, overwrite, deleteOrphaned, simulate, isOriginRemote){
var that = this;
var promises = [];

@@ -190,33 +121,114 @@ var origin = isOriginRemote ? remoteQueries : localQueries;

}
promises.push(function(diffs){ return commit(simulate, diffs); });
promises.push(function(diffs){ return that.commit(simulate, diffs); });
return promises.reduce(Q.when, new Q([]));
};
this.sync = function(overwrite, deleteOrphaned, simulate, ignore, isOriginRemote){
Client.prototype.writeLocalQuery = function(diff){
return this.vfs.writeLocalQuery(diff.query).then(function(){ logDiff(diff); });
};
Client.prototype.writeRemoteQuery = function(diff){
return this.vfs.writeRemoteQuery(diff.query)
.then(function(compileError){
logDiff(diff);
if(compileError) {
throw compileError;
}
});
};
Client.prototype.deleteLocalQuery = function(diff){
return this.vfs.deleteLocalQuery(diff.query).then(function(){ logDiff(diff); });
};
Client.prototype.deleteRemoteQuery = function(diff){
return this.vfs.deleteRemoteQuery(diff.query).then(function(){ logDiff(diff); });
};
Client.prototype.commit = function(simulate, diffs){
var that = this;
var modulePromises = [];
var queryPromises = [];
diffs.forEach(function(diff){
var container = diff.query.substring(0, 'modules'.length) === 'modules' ? modulePromises : queryPromises;
if(simulate) {
logDiff(diff, simulate);
} else if(diff.type === 'write'){
if(diff.isOriginRemote) {
container.push(function(){ return that.writeLocalQuery(diff); });
} else {
container.push(function(){ return that.writeRemoteQuery(diff); });
}
} else {
if(diff.isOriginRemote) {
container.push(function(){ return that.deleteLocalQuery(diff); });
} else {
container.push(function(){ return that.deleteRemoteQuery(diff); });
}
}
});
var handler = function(results){
var errors = [];
results.forEach(function (result) {
if (result.state !== 'fulfilled') {
errors.push(result.reason);
}
});
if(errors.length > 0) {
throw errors;
}
return results;
};
return [
function(){
var promises = [];
modulePromises.forEach(function(promise){
promises.push(promise());
});
return Q.allSettled(promises).then(handler);
},
function(){
var promises = [];
queryPromises.forEach(function(promise){
promises.push(promise());
});
return Q.allSettled(promises).then(handler);
}
].reduce(Q.when, new Q([]));
};
Client.prototype.sync = function(overwrite, deleteOrphaned, simulate, ignore, isOriginRemote){
var that = this;
return Q.all([
vfs.getLocalQueries(),
vfs.getRemoteQueries()
this.vfs.getLocalQueries(),
this.vfs.getRemoteQueries()
])
.then(function(queries){
var localQueries = ignore(queries[0]);
var remoteQueries = ignore(queries[1]);
return sync(localQueries, remoteQueries, overwrite, deleteOrphaned, simulate, isOriginRemote);
});
.then(function(queries){
var localQueries = ignore(queries[0]);
var remoteQueries = ignore(queries[1]);
return that.syncImpl(localQueries, remoteQueries, overwrite, deleteOrphaned, simulate, isOriginRemote);
});
};
var that = this;
this.download = function(overwrite, deleteOrphaned, simulate, ignore){
return that.sync(overwrite, deleteOrphaned, simulate, ignore, true);
Client.prototype.download = function(overwrite, deleteOrphaned, simulate, ignore){
return this.sync(overwrite, deleteOrphaned, simulate, ignore, true);
};
this.upload = function(overwrite, deleteOrphaned, simulate, ignore){
return that.sync(overwrite, deleteOrphaned, simulate, ignore, false);
Client.prototype.upload = function(overwrite, deleteOrphaned, simulate, ignore){
return this.sync(overwrite, deleteOrphaned, simulate, ignore, false);
};
this.truncate = function(simulate, ignore){
return vfs.getRemoteQueries().then(function(queries){
Client.prototype.truncate = function(simulate, ignore){
var that = this;
return this.vfs.getRemoteQueries().then(function(queries){
var remoteQueries = ignore(queries);
return sync({}, remoteQueries, Options.OVERWRITE_ALWAYS, true, simulate, false);
return that.syncImpl({}, remoteQueries, Options.OVERWRITE_ALWAYS, true, simulate, false);
});
};
};
return Client;
})();
exports.Client = Client;

@@ -8,35 +8,60 @@ 'use strict';

var isModule = function(path) {
return path.substring(0, 'modules'.length) === 'modules';
};
var VFS = (function(){
var modulePath = function(path) {
var modulePath = path.substring('modules/'.length);
return modulePath.substring(0, modulePath.lastIndexOf('.'));
};
var isModule = function(path) {
return path.substring(0, 'modules'.length) === 'modules';
};
var moduleExtension = function(path){
var m = modulePath(path);
return path.substring(m.length + 'modules/'.length + 1);
};
var modulePath = function(path) {
var modulePath = path.substring('modules/'.length);
return modulePath.substring(0, modulePath.lastIndexOf('.'));
};
var normalizeLocalProjectPath = function(localProjectPath){
return localProjectPath[localProjectPath.length - 1] === '/' ? localProjectPath : (localProjectPath + '/');
};
var moduleExtension = function(path){
var m = modulePath(path);
return path.substring(m.length + 'modules/'.length + 1);
};
exports.VFS = function($28, projectName, projectToken, localProjectPath){
localProjectPath = localProjectPath ? normalizeLocalProjectPath(localProjectPath) : '';
var normalizeLocalProjectPath = function(localProjectPath){
return localProjectPath[localProjectPath.length - 1] === '/' ? localProjectPath : (localProjectPath + '/');
};
this.getLocalQuery = function(path){
var encodeLocalPath = function(path) {
var segments = path.split('/');
var result = [];
segments.forEach(function(segment){
result.push(encodeURIComponent(segment));
});
return result.join('/');
};
var encodeRemotePath = function(path) {
var segments = path.split('/');
var result = [];
segments.forEach(function(segment){
result.push(decodeURIComponent(segment));
});
return result.join('/');
};
function VFS($28, projectName, projectToken, localProjectPath){
this.$28 = $28;
this.projectName = projectName;
this.projectToken = projectToken;
this.localProjectPath = localProjectPath ? normalizeLocalProjectPath(localProjectPath) : '';
}
VFS.prototype.getLocalQuery = function(path){
return fs.readFileSync(path, 'utf-8');
};
this.getLocalQueries = function(){
ffs.mkdirRecursiveSync(localProjectPath + 'modules', 511);
ffs.mkdirRecursiveSync(localProjectPath + 'public', 511);
ffs.mkdirRecursiveSync(localProjectPath + 'private', 511);
VFS.prototype.getLocalQueries = function(){
var that = this;
ffs.mkdirRecursiveSync(this.localProjectPath + 'modules', 511);
ffs.mkdirRecursiveSync(this.localProjectPath + 'public', 511);
ffs.mkdirRecursiveSync(this.localProjectPath + 'private', 511);
return Q.all([
ffs.readdirRecursive(localProjectPath + 'modules', true, 'modules'),
ffs.readdirRecursive(localProjectPath + 'public', true, 'public'),
ffs.readdirRecursive(localProjectPath + 'private', true, 'private')
ffs.readdirRecursive(this.localProjectPath + 'modules', true, 'modules'),
ffs.readdirRecursive(this.localProjectPath + 'public', true, 'public'),
ffs.readdirRecursive(this.localProjectPath + 'private', true, 'private')
]).then(function(lists){

@@ -47,3 +72,3 @@ var queries = {};

queries[file] = {
lastModified: new Date(fs.statSync(localProjectPath + file).mtime).toISOString()
lastModified: new Date(fs.statSync(that.localProjectPath + file).mtime).toISOString()
};

@@ -55,16 +80,16 @@ });

};
this.getRemoteQueries = function(){
VFS.prototype.getRemoteQueries = function(){
return Q.all([
//Modules need to be listed/uploaded first,
//so compilation errors on main queries can make sense.
$28.Modules(projectName).listModules({
this.$28.Modules(this.projectName).listModules({
includeSystem: false,
includeNs: false,
includeSrc: false,
token: projectToken
token: this.projectToken
}),
$28.Queries(projectName).listQueries({
this.$28.Queries(this.projectName).listQueries({
visibility: '',
token: projectToken
token: this.projectToken
})

@@ -80,3 +105,3 @@ ]).then(function(lists){

var path = 'modules' + module + '.' + modules[module].extension;
queries[path] = {
queries[encodeRemotePath(path)] = {
lastModified: modules[module].lastModified

@@ -88,22 +113,22 @@ };

).forEach(function(query){
var path = query.href.substring('/v1/_queries/'.length);
queries[path] = {
lastModified: query.lastModified
};
});
var path = query.href.substring('/v1/_queries/'.length);
queries[encodeRemotePath(path)] = {
lastModified: query.lastModified
};
});
return queries;
});
};
this.deleteRemoteQuery = function(query){
VFS.prototype.deleteRemoteQuery = function(query){
var promise;
if(isModule(query)){
promise = $28.Modules(projectName).removeModule({
modulePath: modulePath(query),
token: projectToken
promise = this.$28.Modules(this.projectName).removeModule({
modulePath: encodeLocalPath(modulePath(query)),
token: this.projectToken
});
} else {
promise = $28.Queries(projectName).removeQuery({
queryPath: query,
token: projectToken
promise = this.$28.Queries(this.projectName).removeQuery({
queryPath: encodeLocalPath(query),
token: this.projectToken
});

@@ -113,6 +138,6 @@ }

};
this.deleteLocalQuery = function(query){
VFS.prototype.deleteLocalQuery = function(query){
var defered = Q.defer();
ffs.unlink(localProjectPath + query).then(function(){
ffs.unlink(this.localProjectPath + query).then(function(){
defered.resolve();

@@ -124,30 +149,31 @@ }).otherwise(function(error){

};
this.writeRemoteQuery = function(query, reportErrors){
VFS.prototype.writeRemoteQuery = function(query, reportErrors){
var that = this;
var defered = Q.defer();
ffs.readFile(localProjectPath + query, { encoding: 'utf-8' }).then(function(source){
ffs.readFile(this.localProjectPath + query, { encoding: 'utf-8' }).then(function(source){
source = source.toString();
if(isModule(query)){
$28.Modules(projectName).saveModule({
modulePath: modulePath(query),
that.$28.Modules(that.projectName).saveModule({
modulePath: encodeLocalPath(modulePath(query)),
extension: moduleExtension(query),
moduleBody: source,
compile: 'lax',
token: projectToken
token: that.projectToken
})
.then(function(result){
defered.resolve(reportErrors === true ? result.body.compilationError : undefined);
})
.catch(function(error){ defered.reject(error); });
.then(function(result){
defered.resolve(reportErrors === true ? result.body.compilationError : undefined);
})
.catch(function(error){ defered.reject(error); });
} else {
$28.Queries(projectName).saveQuery({
queryPath: query,
that.$28.Queries(that.projectName).saveQuery({
queryPath: encodeLocalPath(query),
queryBody: source,
compile: 'lax',
token: projectToken
token: that.projectToken
})
.then(function(result){
defered.resolve(result.body.compilationError);
})
.catch(function(error){ defered.reject(error); });
.then(function(result){
defered.resolve(result.body.compilationError);
})
.catch(function(error){ defered.reject(error); });
}

@@ -159,21 +185,26 @@ }).otherwise(function(error){

};
this.writeLocalQuery = function(query){
VFS.prototype.writeLocalQuery = function(query){
var that = this;
var callback = function(response){
var source = response.body;
var dir = localProjectPath + path.dirname(query);
var dir = that.localProjectPath + path.dirname(query);
ffs.mkdirRecursiveSync(dir, 511);
ffs.writeFileSync(localProjectPath + query, source, { encoding: 'utf-8' });
ffs.writeFileSync(that.localProjectPath + query, source, { encoding: 'utf-8' });
};
if(isModule(query)) {
return $28.Modules(projectName)
.getModule({ modulePath: modulePath(query), token: projectToken })
.then(callback);
return this.$28.Modules(this.projectName)
.getModule({ modulePath: encodeLocalPath(modulePath(query)), token: this.projectToken })
.then(callback);
} else {
return $28.Queries(projectName)
.getQuery({ queryPath: query, token: projectToken })
.then(callback);
return this.$28.Queries(this.projectName)
.getQuery({ queryPath: encodeLocalPath(query), token: this.projectToken })
.then(callback);
}
};
};
return VFS;
})();
exports.VFS = VFS;

@@ -9,3 +9,3 @@ {

"description": "Command line utility to download and upload 28.io queries.",
"version": "0.5.3",
"version": "1.0.0",
"keywords": [

@@ -39,3 +39,3 @@ "jsoniq",

"update-notifier": "~0.2.0",
"watch": "^0.13.0"
"watch": "git://github.com/mikeal/watch.git#0aee7194ea3bd03871a3b49851dc7cde9eef08f3"
},

@@ -42,0 +42,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc