Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
// check classname
const cls = db.models[classname];
if (cls === undefined)
return fill_error(req, err_info(4040001, {
classname: classname
}));
var _req = {
session: req.session,
query: req.query.toJSON(),
request: req
};
var where = _req.query.where;
if (where !== undefined)
try {
_req.query.where = json.decode(where);
}
catch (e) {
return fill_error(req, err_info(4000003));
}
var keys = _req.query.keys;
if (keys !== undefined && typeof keys === 'string')
_req.query.keys = keys.split(',');
var result;
try {
result = func.apply(undefined, [_req, db, cls].concat(earg, [data]));
}
catch (e) {
console.error(e.stack);
if (e.type === 'validation') {
result = {
error: {
// use an old one if it's no longer available
log.error("Unable to download a fresh copy of catalog " + url + ".");
}
}
// try to read the downloaded or stale copy
try {
var json = httpStore.read(url, {"charset": "UTF-8"});
} catch (exception) {
log.error("HttpError getting " + url + ".");
return;
}
// try to parse the source file
try {
include = JSON.decode(json);
} catch (exception) {
log.error("SyntaxError in " + url + ".");
return;
}
if (include.version < TUSK.minCatalogVersion) {
log.error("Catalog at " + url + " is obsolete.");
return;
}
catalogs[url] = include;
include.url = url;
// validate the catalog
// transitively grab sub-catalogs
exports.getCatalogs(include, catalogs, order, useCache, log);
});
githubRef = source.ref || "master";
if (!source.user)
throw new Error("package source " + util.enquote(name) + " did not have a github user name");
var project = source.user + '/' + githubName;
var url = "http://github.com/" + project + "/raw/" + githubRef + "/package.json";
// download package.json if not already provided
if (!info) {
try {
var text = http.read(url).toString('utf-8');
} catch (exception) {
self.print("\0red(dropped:\0) " + name + " \0blue(because of an HTTP error\0)");
return;
}
try {
info = json.decode(text);
} catch (exception) {
self.print("\0red(dropped:\0) " + name + " \0blue(because of a JSON error\0)");
return;
}
}
info.githubName = githubName;
info.type = "zip";
info.location = 'http://github.com/' + source.user + '/' + githubName + '/zipball/' + githubRef;
} else {
throw new Error(
"Project " + util.enquote(name) +
" has an urecognized type: " +
util.enquote(source.type)
);
exports.getSources = function () {
// read .tusk/sources.json
// create .tusk/sources.json from default if necessary
var tuskDirectory = TUSK.getTuskDirectory();
var sourcesFile = tuskDirectory.join('sources.json').canonical();
if (!sourcesFile.exists()) {
sources = exports.defaultSources;
} else {
sources = JSON.decode(sourcesFile.read({"charset": "UTF-8"}));
}
sources.url = URI.pathToUri(sourcesFile);
return sources;
};
var names = names.map(function (name) {
var localPath = fs.path(fs.absolute(name).replace(/\/$/, "")); // FIXME: basename/dirname broken with trailing slash
var localPackagePath = localPath.join("package.json");
if (localPackagePath.isFile()) {
var packageData = json.decode(localPackagePath.read({charset: 'utf-8'}));
var packageName = packageData.name || String(localPath.basename());
packageData.packageUrl = "file://" + localPath;
packageData.type = "directory";
catalog.packages[packageName] = packageData;
return packageName;
} else if (util.has(catalog.packages, name)) {
// nothing to do.
return name;
}
parser.print("ERROR: Package not found: " + util.enquote(name));
return null;
}).filter(function(name) { return !!name; });
_loadIndex: function() {
var location = this.loc;
// is this a file?
if (location.indexOf("://") == -1) {
var f = Path(location);
var rawdata = f.read().toString();
}
this.packageInfo = json.decode(rawdata);
},
getPackageInfo: function(name, minimum, maximum) {
githubRef = source.ref || "master";
if (!source.user)
throw new Error("package source " + util.enquote(name) + " did not have a github user name");
var project = source.user + '/' + githubName;
var url = "http://github.com/" + project + "/raw/" + githubRef + "/package.json";
// download package.json if not already provided
if (!info) {
try {
var text = http.read(url).toString('utf-8');
} catch (exception) {
self.print("\0red(dropped:\0) " + name + " \0blue(because of an HTTP error\0)");
return;
}
try {
info = json.decode(text);
} catch (exception) {
self.print("\0red(dropped:\0) " + name + " \0blue(because of a JSON error\0)");
return;
}
}
info.githubName = githubName;
info.type = "zip";
info.location = 'http://github.com/' + source.user + '/' + githubName + '/zipball/' + githubRef;
} else {
throw new Error(
"Project " + util.enquote(name) +
" has an urecognized type: " +
util.enquote(source.type)
);
new zip.Unzip(localPath).forEach(function (entry) {
if (!packageName && entry.getName().match(/^[^\/]+\/package.json/)) {
var packageData = json.decode(entry.read('b').decodeToString("UTF-8"));
packageName = packageData.name || String(localPath.basename());
packageData.packageUrl = "file://" + localPath;
catalog.packages[packageName] = packageData;
}
});
return packageName;
exports.readCatalog = function (catalogPath) {
return JSON.decode(exports.getCatalogPath(catalogPath).read({"charset": "UTF-8"}));
};
fs.path(system.prefix).join('bin', 'sea').copy(sea);
sea.chmod(0755);
var activate = path.join('bin', 'activate.bash');
fs.path(system.prefix).join('bin', 'activate.bash')
.copy(activate);
activate.relative().symlink(activate.resolve('activate'));
path.join('README').touch();
path.join('narwhal.conf')
.write('NARWHAL_DEFAULT_ENGINE=' + system.engine);
var packagePath = path.join('package.json');
if (packagePath.isFile())
util.complete(
packageInfo,
json.decode(packagePath.read({charset:'utf-8'}))
);
packagePath.write(
json.encode(packageInfo, null, 4),
{charset:'utf-8'}
);
});