1
0
Fork 0

De-IFFE-ify all the modules.

This commit is contained in:
Alan Plum 2015-06-03 13:08:58 +02:00
parent e1186eb8e0
commit 993ad1e0ea
6 changed files with 1800 additions and 1819 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/*jslint continue:true */
'use strict';
////////////////////////////////////////////////////////////////////////////////
/// @brief Foxx application store
@ -27,26 +27,23 @@
/// @author Copyright 2015, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
(function() {
'use strict';
// -----------------------------------------------------------------------------
// --SECTION-- global variables
// -----------------------------------------------------------------------------
var checkedFishBowl = false;
var checkedFishBowl = false;
// -----------------------------------------------------------------------------
// --SECTION-- imports
// -----------------------------------------------------------------------------
var arangodb = require("org/arangodb");
var db = arangodb.db;
var download = require("internal").download;
var fs = require("fs");
var throwDownloadError = arangodb.throwDownloadError;
var utils = require("org/arangodb/foxx/manager-utils");
var arangodb = require("org/arangodb");
var db = arangodb.db;
var download = require("internal").download;
var fs = require("fs");
var throwDownloadError = arangodb.throwDownloadError;
var utils = require("org/arangodb/foxx/manager-utils");
// -----------------------------------------------------------------------------
// --SECTION-- private functions
@ -56,9 +53,9 @@
/// @brief returns the fishbowl repository
////////////////////////////////////////////////////////////////////////////////
function getFishbowlUrl () {
return "arangodb/foxx-apps";
}
function getFishbowlUrl () {
return "arangodb/foxx-apps";
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns the fishbowl collection
@ -68,190 +65,190 @@
/// used in context of the database.
////////////////////////////////////////////////////////////////////////////////
var getFishbowlStorage = function() {
var getFishbowlStorage = function() {
var c = db._collection('_fishbowl');
if (c === null) {
c = db._create('_fishbowl', { isSystem : true });
}
var c = db._collection('_fishbowl');
if (c === null) {
c = db._create('_fishbowl', { isSystem : true });
}
if (c !== null && ! checkedFishBowl) {
// ensure indexes
c.ensureFulltextIndex("description");
c.ensureFulltextIndex("name");
checkedFishBowl = true;
}
if (c !== null && ! checkedFishBowl) {
// ensure indexes
c.ensureFulltextIndex("description");
c.ensureFulltextIndex("name");
checkedFishBowl = true;
}
return c;
};
return c;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief comparator for applications
////////////////////////////////////////////////////////////////////////////////
var compareApps = function(l, r) {
var left = l.name.toLowerCase();
var right = r.name.toLowerCase();
var compareApps = function(l, r) {
var left = l.name.toLowerCase();
var right = r.name.toLowerCase();
if (left < right) {
return -1;
}
if (left < right) {
return -1;
}
if (right < left) {
return 1;
}
if (right < left) {
return 1;
}
return 0;
};
return 0;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief comparator for versions
////////////////////////////////////////////////////////////////////////////////
var compareVersions = function (a, b) {
var i;
var compareVersions = function (a, b) {
var i;
if (a === b) {
return 0;
}
// error handling
if (typeof a !== "string") {
return -1;
}
if (typeof b !== "string") {
return 1;
}
var aComponents = a.split(".");
var bComponents = b.split(".");
var len = Math.min(aComponents.length, bComponents.length);
// loop while the components are equal
for (i = 0; i < len; i++) {
// A bigger than B
if (parseInt(aComponents[i], 10) > parseInt(bComponents[i], 10)) {
return 1;
}
// B bigger than A
if (parseInt(aComponents[i], 10) < parseInt(bComponents[i], 10)) {
return -1;
}
}
// If one's a prefix of the other, the longer one is bigger one.
if (aComponents.length > bComponents.length) {
return 1;
}
if (aComponents.length < bComponents.length) {
return -1;
}
// Otherwise they are the same.
if (a === b) {
return 0;
};
}
// error handling
if (typeof a !== "string") {
return -1;
}
if (typeof b !== "string") {
return 1;
}
var aComponents = a.split(".");
var bComponents = b.split(".");
var len = Math.min(aComponents.length, bComponents.length);
// loop while the components are equal
for (i = 0; i < len; i++) {
// A bigger than B
if (parseInt(aComponents[i], 10) > parseInt(bComponents[i], 10)) {
return 1;
}
// B bigger than A
if (parseInt(aComponents[i], 10) < parseInt(bComponents[i], 10)) {
return -1;
}
}
// If one's a prefix of the other, the longer one is bigger one.
if (aComponents.length > bComponents.length) {
return 1;
}
if (aComponents.length < bComponents.length) {
return -1;
}
// Otherwise they are the same.
return 0;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief updates the fishbowl from a zip archive
////////////////////////////////////////////////////////////////////////////////
var updateFishbowlFromZip = function(filename) {
var i;
var tempPath = fs.getTempPath();
var toSave = [ ];
var updateFishbowlFromZip = function(filename) {
var i;
var tempPath = fs.getTempPath();
var toSave = [ ];
try {
fs.makeDirectoryRecursive(tempPath);
var root = fs.join(tempPath, "foxx-apps-master/applications");
// remove any previous files in the directory
fs.listTree(root).forEach(function (file) {
if (file.match(/\.json$/)) {
try {
fs.remove(fs.join(root, file));
}
catch (ignore) {
}
}
});
fs.unzipFile(filename, tempPath, false, true);
if (! fs.exists(root)) {
throw new Error("'applications' directory is missing in foxx-apps-master, giving up");
}
var m = fs.listTree(root);
var reSub = /(.*)\.json$/;
var f, match, app, desc;
for (i = 0; i < m.length; ++i) {
f = m[i];
match = reSub.exec(f);
if (match === null) {
continue;
}
app = fs.join(root, f);
try {
fs.makeDirectoryRecursive(tempPath);
var root = fs.join(tempPath, "foxx-apps-master/applications");
// remove any previous files in the directory
fs.listTree(root).forEach(function (file) {
if (file.match(/\.json$/)) {
try {
desc = JSON.parse(fs.read(app));
}
catch (err1) {
arangodb.printf("Cannot parse description for app '" + f + "': %s\n", String(err1));
continue;
}
desc._key = match[1];
if (! desc.hasOwnProperty("name")) {
desc.name = match[1];
}
toSave.push(desc);
}
if (toSave.length > 0) {
var fishbowl = getFishbowlStorage();
db._executeTransaction({
collections: {
write: fishbowl.name()
},
action: function (params) {
var c = require("internal").db._collection(params.collection);
c.truncate();
params.apps.forEach(function(app) {
c.save(app);
});
},
params: {
apps: toSave,
collection: fishbowl.name()
}
});
arangodb.printf("Updated local repository information with %d application(s)\n",
toSave.length);
}
}
catch (err) {
if (tempPath !== undefined && tempPath !== "") {
try {
fs.removeDirectoryRecursive(tempPath);
fs.remove(fs.join(root, file));
}
catch (ignore) {
}
}
});
throw err;
fs.unzipFile(filename, tempPath, false, true);
if (! fs.exists(root)) {
throw new Error("'applications' directory is missing in foxx-apps-master, giving up");
}
};
var m = fs.listTree(root);
var reSub = /(.*)\.json$/;
var f, match, app, desc;
for (i = 0; i < m.length; ++i) {
f = m[i];
match = reSub.exec(f);
if (match === null) {
continue;
}
app = fs.join(root, f);
try {
desc = JSON.parse(fs.read(app));
}
catch (err1) {
arangodb.printf("Cannot parse description for app '" + f + "': %s\n", String(err1));
continue;
}
desc._key = match[1];
if (! desc.hasOwnProperty("name")) {
desc.name = match[1];
}
toSave.push(desc);
}
if (toSave.length > 0) {
var fishbowl = getFishbowlStorage();
db._executeTransaction({
collections: {
write: fishbowl.name()
},
action: function (params) {
var c = require("internal").db._collection(params.collection);
c.truncate();
params.apps.forEach(function(app) {
c.save(app);
});
},
params: {
apps: toSave,
collection: fishbowl.name()
}
});
arangodb.printf("Updated local repository information with %d application(s)\n",
toSave.length);
}
}
catch (err) {
if (tempPath !== undefined && tempPath !== "") {
try {
fs.removeDirectoryRecursive(tempPath);
}
catch (ignore) {
}
}
throw err;
}
};
// -----------------------------------------------------------------------------
// --SECTION-- public functions
@ -261,87 +258,87 @@
/// @brief returns the search result for FOXX applications
////////////////////////////////////////////////////////////////////////////////
var searchJson = function (name) {
var searchJson = function (name) {
var fishbowl = getFishbowlStorage();
var fishbowl = getFishbowlStorage();
if (fishbowl.count() === 0) {
arangodb.print("Repository is empty, please use 'update'");
if (fishbowl.count() === 0) {
arangodb.print("Repository is empty, please use 'update'");
return [];
return [];
}
var docs;
if (name === undefined || (typeof name === "string" && name.length === 0)) {
docs = fishbowl.toArray();
}
else {
name = name.replace(/[^a-zA-Z0-9]/g, ' ');
// get results by looking in "description" attribute
docs = fishbowl.fulltext("description", "prefix:" + name).toArray();
// build a hash of keys
var i;
var keys = { };
for (i = 0; i < docs.length; ++i) {
keys[docs[i]._key] = 1;
}
var docs;
// get results by looking in "name" attribute
var docs2= fishbowl.fulltext("name", "prefix:" + name).toArray();
if (name === undefined || (typeof name === "string" && name.length === 0)) {
docs = fishbowl.toArray();
}
else {
name = name.replace(/[^a-zA-Z0-9]/g, ' ');
// get results by looking in "description" attribute
docs = fishbowl.fulltext("description", "prefix:" + name).toArray();
// build a hash of keys
var i;
var keys = { };
for (i = 0; i < docs.length; ++i) {
keys[docs[i]._key] = 1;
// merge the two result sets, avoiding duplicates
for (i = 0; i < docs2.length; ++i) {
if (!keys.hasOwnProperty(docs2[i]._key)) {
docs.push(docs2[i]);
}
// get results by looking in "name" attribute
var docs2= fishbowl.fulltext("name", "prefix:" + name).toArray();
// merge the two result sets, avoiding duplicates
for (i = 0; i < docs2.length; ++i) {
if (!keys.hasOwnProperty(docs2[i]._key)) {
docs.push(docs2[i]);
}
}
}
}
return docs;
};
return docs;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief searchs for an available FOXX applications
////////////////////////////////////////////////////////////////////////////////
var search = function (name) {
var docs = searchJson(name);
var search = function (name) {
var docs = searchJson(name);
arangodb.printTable(
docs.sort(compareApps),
[ "name", "author", "description" ],
{
prettyStrings: true,
totalString: "%s application(s) found",
emptyString: "no applications found",
rename: {
name : "Name",
author : "Author",
description : "Description"
}
arangodb.printTable(
docs.sort(compareApps),
[ "name", "author", "description" ],
{
prettyStrings: true,
totalString: "%s application(s) found",
emptyString: "no applications found",
rename: {
name : "Name",
author : "Author",
description : "Description"
}
);
};
}
);
};
////////////////////////////////////////////////////////////////////////////////
/// @brief extracts the highest version number from the document
////////////////////////////////////////////////////////////////////////////////
function extractMaxVersion (versionDoc) {
var maxVersion = "-";
var versions = Object.keys(versionDoc);
versions.sort(compareVersions);
if (versions.length > 0) {
versions.reverse();
maxVersion = versions[0];
}
return maxVersion;
var maxVersion = "-";
var versions = Object.keys(versionDoc);
versions.sort(compareVersions);
if (versions.length > 0) {
versions.reverse();
maxVersion = versions[0];
}
return maxVersion;
}
////////////////////////////////////////////////////////////////////////////////
@ -349,26 +346,26 @@ function extractMaxVersion (versionDoc) {
////////////////////////////////////////////////////////////////////////////////
function availableJson() {
var fishbowl = getFishbowlStorage();
var cursor = fishbowl.all();
var result = [];
var doc, maxVersion, res;
var fishbowl = getFishbowlStorage();
var cursor = fishbowl.all();
var result = [];
var doc, maxVersion, res;
while (cursor.hasNext()) {
doc = cursor.next();
maxVersion = extractMaxVersion(doc.versions);
while (cursor.hasNext()) {
doc = cursor.next();
maxVersion = extractMaxVersion(doc.versions);
res = {
name: doc.name,
description: doc.description || "",
author: doc.author || "",
latestVersion: maxVersion
};
res = {
name: doc.name,
description: doc.description || "",
author: doc.author || "",
latestVersion: maxVersion
};
result.push(res);
}
result.push(res);
}
return result;
return result;
}
@ -379,181 +376,179 @@ function availableJson() {
////////////////////////////////////////////////////////////////////////////////
var update = function() {
var url = utils.buildGithubUrl(getFishbowlUrl());
var filename = fs.getTempFile("downloads", false);
var path = fs.getTempFile("zip", false);
var update = function() {
var url = utils.buildGithubUrl(getFishbowlUrl());
var filename = fs.getTempFile("downloads", false);
var path = fs.getTempFile("zip", false);
try {
var result = download(url, "", {
method: "get",
followRedirects: true,
timeout: 30
}, filename);
if (result.code < 200 || result.code > 299) {
throwDownloadError("Github download from '" + url + "' failed with error code " + result.code);
}
updateFishbowlFromZip(filename);
filename = undefined;
}
catch (err) {
if (filename !== undefined && fs.exists(filename)) {
fs.remove(filename);
}
try {
var result = download(url, "", {
method: "get",
followRedirects: true,
timeout: 30
}, filename);
if (result.code < 200 || result.code > 299) {
throwDownloadError("Github download from '" + url + "' failed with error code " + result.code);
}
updateFishbowlFromZip(filename);
filename = undefined;
fs.removeDirectoryRecursive(path);
}
catch (err) {
if (filename !== undefined && fs.exists(filename)) {
fs.remove(filename);
}
try {
fs.removeDirectoryRecursive(path);
}
catch (ignore) {
}
throw err;
catch (ignore) {
}
};
throw err;
}
};
////////////////////////////////////////////////////////////////////////////////
/// @brief prints all available FOXX applications
////////////////////////////////////////////////////////////////////////////////
var available = function () {
var list = availableJson();
var available = function () {
var list = availableJson();
arangodb.printTable(
list.sort(compareApps),
[ "name", "author", "description", "latestVersion" ],
{
prettyStrings: true,
totalString: "%s application(s) found",
emptyString: "no applications found, please use 'update'",
rename: {
"name" : "Name",
"author" : "Author",
"description" : "Description",
"latestVersion" : "Latest Version"
}
arangodb.printTable(
list.sort(compareApps),
[ "name", "author", "description", "latestVersion" ],
{
prettyStrings: true,
totalString: "%s application(s) found",
emptyString: "no applications found, please use 'update'",
rename: {
"name" : "Name",
"author" : "Author",
"description" : "Description",
"latestVersion" : "Latest Version"
}
);
};
}
);
};
////////////////////////////////////////////////////////////////////////////////
/// @brief gets json-info for an available FOXX application
////////////////////////////////////////////////////////////////////////////////
var infoJson = function (name) {
utils.validateAppName(name);
utils.validateAppName(name);
var fishbowl = getFishbowlStorage();
var fishbowl = getFishbowlStorage();
if (fishbowl.count() === 0) {
arangodb.print("Repository is empty, please use 'update'");
return;
}
if (fishbowl.count() === 0) {
arangodb.print("Repository is empty, please use 'update'");
return;
}
var desc;
var desc;
try {
desc = fishbowl.document(name);
return desc;
}
catch (err) {
arangodb.print("No application '" + name + "' available, please try 'search'");
return;
}
try {
desc = fishbowl.document(name);
return desc;
}
catch (err) {
arangodb.print("No application '" + name + "' available, please try 'search'");
return;
}
};
////////////////////////////////////////////////////////////////////////////////
/// @brief create a download URL for the given app information
////////////////////////////////////////////////////////////////////////////////
var buildUrl = function(appInfo) {
// TODO Validate
var infoSplit = appInfo.split(":");
var name = infoSplit[0];
var version = infoSplit[1];
var storeInfo = infoJson(name);
if (storeInfo === undefined) {
throw "Application not found";
var buildUrl = function(appInfo) {
// TODO Validate
var infoSplit = appInfo.split(":");
var name = infoSplit[0];
var version = infoSplit[1];
var storeInfo = infoJson(name);
if (storeInfo === undefined) {
throw "Application not found";
}
var versions = storeInfo.versions;
var versionInfo;
if (version === undefined) {
versionInfo = versions[extractMaxVersion(versions)];
} else {
if (!versions.hasOwnProperty(version)) {
throw "Unknown version";
}
var versions = storeInfo.versions;
var versionInfo;
if (version === undefined) {
versionInfo = versions[extractMaxVersion(versions)];
} else {
if (!versions.hasOwnProperty(version)) {
throw "Unknown version";
}
versionInfo = versions[version];
}
return utils.buildGithubUrl(versionInfo.location, versionInfo.tag);
};
versionInfo = versions[version];
}
return utils.buildGithubUrl(versionInfo.location, versionInfo.tag);
};
////////////////////////////////////////////////////////////////////////////////
/// @brief prints info for an available FOXX application
////////////////////////////////////////////////////////////////////////////////
var info = function (name) {
var desc = infoJson(name);
arangodb.printf("Name: %s\n", desc.name);
var info = function (name) {
var desc = infoJson(name);
arangodb.printf("Name: %s\n", desc.name);
if (desc.hasOwnProperty('author')) {
arangodb.printf("Author: %s\n", desc.author);
if (desc.hasOwnProperty('author')) {
arangodb.printf("Author: %s\n", desc.author);
}
var isSystem = desc.hasOwnProperty('isSystem') && desc.isSystem;
arangodb.printf("System: %s\n", JSON.stringify(isSystem));
if (desc.hasOwnProperty('description')) {
arangodb.printf("Description: %s\n\n", desc.description);
}
var header = false;
var versions = Object.keys(desc.versions);
versions.sort(compareVersions);
versions.forEach(function (v) {
var version = desc.versions[v];
if (! header) {
arangodb.print("Versions:");
header = true;
}
var isSystem = desc.hasOwnProperty('isSystem') && desc.isSystem;
arangodb.printf("System: %s\n", JSON.stringify(isSystem));
if (desc.hasOwnProperty('description')) {
arangodb.printf("Description: %s\n\n", desc.description);
if (version.type === "github") {
if (version.hasOwnProperty("tag")) {
arangodb.printf('%s: fetch github "%s" "%s"\n', v, version.location, version.tag);
}
else if (v.hasOwnProperty("branch")) {
arangodb.printf('%s: fetch github "%s" "%s"\n', v, version.location, version.branch);
}
else {
arangodb.printf('%s: fetch "github" "%s"\n', v, version.location);
}
}
});
var header = false;
var versions = Object.keys(desc.versions);
versions.sort(compareVersions);
versions.forEach(function (v) {
var version = desc.versions[v];
if (! header) {
arangodb.print("Versions:");
header = true;
}
if (version.type === "github") {
if (version.hasOwnProperty("tag")) {
arangodb.printf('%s: fetch github "%s" "%s"\n', v, version.location, version.tag);
}
else if (v.hasOwnProperty("branch")) {
arangodb.printf('%s: fetch github "%s" "%s"\n', v, version.location, version.branch);
}
else {
arangodb.printf('%s: fetch "github" "%s"\n', v, version.location);
}
}
});
arangodb.printf("\n");
};
arangodb.printf("\n");
};
// -----------------------------------------------------------------------------
// --SECTION-- export public API
// -----------------------------------------------------------------------------
exports.available = available;
exports.availableJson = availableJson;
exports.buildUrl = buildUrl;
exports.getFishbowlStorage = getFishbowlStorage;
exports.info = info;
exports.search = search;
exports.searchJson = searchJson;
exports.update = update;
exports.available = available;
exports.availableJson = availableJson;
exports.buildUrl = buildUrl;
exports.getFishbowlStorage = getFishbowlStorage;
exports.info = info;
exports.search = search;
exports.searchJson = searchJson;
exports.update = update;
// Temporary export to avoid breaking the client
exports.compareVersions = compareVersions;
}());
// Temporary export to avoid breaking the client
exports.compareVersions = compareVersions;
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE

View File

@ -1,4 +1,4 @@
/*jshint strict: false */
'use strict';
////////////////////////////////////////////////////////////////////////////////
/// @brief Graph Data for Example
@ -26,92 +26,90 @@
/// @author Michael Hackstein
/// @author Copyright 2011-2014, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
(function() {
var Graph = require("org/arangodb/general-graph");
var Graph = require("org/arangodb/general-graph");
var createTraversalExample = function() {
var g = Graph._create("knows_graph",
[Graph._relation("knows", "persons", "persons")]
);
var a = g.persons.save({name: "Alice", _key: "alice"})._id;
var b = g.persons.save({name: "Bob", _key: "bob"})._id;
var c = g.persons.save({name: "Charlie", _key: "charlie"})._id;
var d = g.persons.save({name: "Dave", _key: "dave"})._id;
var e = g.persons.save({name: "Eve", _key: "eve"})._id;
g.knows.save(a, b, {});
g.knows.save(b, c, {});
g.knows.save(b, d, {});
g.knows.save(e, a, {});
g.knows.save(e, b, {});
return g;
};
var createTraversalExample = function() {
var g = Graph._create("knows_graph",
[Graph._relation("knows", "persons", "persons")]
);
var a = g.persons.save({name: "Alice", _key: "alice"})._id;
var b = g.persons.save({name: "Bob", _key: "bob"})._id;
var c = g.persons.save({name: "Charlie", _key: "charlie"})._id;
var d = g.persons.save({name: "Dave", _key: "dave"})._id;
var e = g.persons.save({name: "Eve", _key: "eve"})._id;
g.knows.save(a, b, {});
g.knows.save(b, c, {});
g.knows.save(b, d, {});
g.knows.save(e, a, {});
g.knows.save(e, b, {});
return g;
};
var createSocialGraph = function() {
var edgeDefinition = [];
edgeDefinition.push(Graph._relation("relation", ["female", "male"], ["female", "male"]));
var g = Graph._create("social", edgeDefinition);
var a = g.female.save({name: "Alice", _key: "alice"});
var b = g.male.save({name: "Bob", _key: "bob"});
var c = g.male.save({name: "Charly", _key: "charly"});
var d = g.female.save({name: "Diana", _key: "diana"});
g.relation.save(a._id, b._id, {type: "married", _key: "aliceAndBob"});
g.relation.save(a._id, c._id, {type: "friend", _key: "aliceAndCharly"});
g.relation.save(c._id, d._id, {type: "married", _key: "charlyAndDiana"});
g.relation.save(b._id, d._id, {type: "friend", _key: "bobAndDiana"});
return g;
};
var createSocialGraph = function() {
var edgeDefinition = [];
edgeDefinition.push(Graph._relation("relation", ["female", "male"], ["female", "male"]));
var g = Graph._create("social", edgeDefinition);
var a = g.female.save({name: "Alice", _key: "alice"});
var b = g.male.save({name: "Bob", _key: "bob"});
var c = g.male.save({name: "Charly", _key: "charly"});
var d = g.female.save({name: "Diana", _key: "diana"});
g.relation.save(a._id, b._id, {type: "married", _key: "aliceAndBob"});
g.relation.save(a._id, c._id, {type: "friend", _key: "aliceAndCharly"});
g.relation.save(c._id, d._id, {type: "married", _key: "charlyAndDiana"});
g.relation.save(b._id, d._id, {type: "friend", _key: "bobAndDiana"});
return g;
};
var createRoutePlannerGraph = function() {
var edgeDefinition = [];
edgeDefinition.push(Graph._relation(
"germanHighway", ["germanCity"], ["germanCity"])
);
edgeDefinition.push(
Graph._relation("frenchHighway", ["frenchCity"], ["frenchCity"])
);
edgeDefinition.push(Graph._relation(
"internationalHighway", ["frenchCity", "germanCity"], ["frenchCity", "germanCity"])
);
var g = Graph._create("routeplanner", edgeDefinition);
var berlin = g.germanCity.save({_key: "Berlin", population : 3000000, isCapital : true});
var cologne = g.germanCity.save({_key: "Cologne", population : 1000000, isCapital : false});
var hamburg = g.germanCity.save({_key: "Hamburg", population : 1000000, isCapital : false});
var lyon = g.frenchCity.save({_key: "Lyon", population : 80000, isCapital : false});
var paris = g.frenchCity.save({_key: "Paris", population : 4000000, isCapital : true});
g.germanHighway.save(berlin._id, cologne._id, {distance: 850});
g.germanHighway.save(berlin._id, hamburg._id, {distance: 400});
g.germanHighway.save(hamburg._id, cologne._id, {distance: 500});
g.frenchHighway.save(paris._id, lyon._id, {distance: 550});
g.internationalHighway.save(berlin._id, lyon._id, {distance: 1100});
g.internationalHighway.save(berlin._id, paris._id, {distance: 1200});
g.internationalHighway.save(hamburg._id, paris._id, {distance: 900});
g.internationalHighway.save(hamburg._id, lyon._id, {distance: 1300});
g.internationalHighway.save(cologne._id, lyon._id, {distance: 700});
g.internationalHighway.save(cologne._id, paris._id, {distance: 550});
return g;
};
var createRoutePlannerGraph = function() {
var edgeDefinition = [];
edgeDefinition.push(Graph._relation(
"germanHighway", ["germanCity"], ["germanCity"])
);
edgeDefinition.push(
Graph._relation("frenchHighway", ["frenchCity"], ["frenchCity"])
);
edgeDefinition.push(Graph._relation(
"internationalHighway", ["frenchCity", "germanCity"], ["frenchCity", "germanCity"])
);
var g = Graph._create("routeplanner", edgeDefinition);
var berlin = g.germanCity.save({_key: "Berlin", population : 3000000, isCapital : true});
var cologne = g.germanCity.save({_key: "Cologne", population : 1000000, isCapital : false});
var hamburg = g.germanCity.save({_key: "Hamburg", population : 1000000, isCapital : false});
var lyon = g.frenchCity.save({_key: "Lyon", population : 80000, isCapital : false});
var paris = g.frenchCity.save({_key: "Paris", population : 4000000, isCapital : true});
g.germanHighway.save(berlin._id, cologne._id, {distance: 850});
g.germanHighway.save(berlin._id, hamburg._id, {distance: 400});
g.germanHighway.save(hamburg._id, cologne._id, {distance: 500});
g.frenchHighway.save(paris._id, lyon._id, {distance: 550});
g.internationalHighway.save(berlin._id, lyon._id, {distance: 1100});
g.internationalHighway.save(berlin._id, paris._id, {distance: 1200});
g.internationalHighway.save(hamburg._id, paris._id, {distance: 900});
g.internationalHighway.save(hamburg._id, lyon._id, {distance: 1300});
g.internationalHighway.save(cologne._id, lyon._id, {distance: 700});
g.internationalHighway.save(cologne._id, paris._id, {distance: 550});
return g;
};
var dropGraph = function(name) {
if (Graph._exists(name)) {
return Graph._drop(name, true);
}
};
var dropGraph = function(name) {
if (Graph._exists(name)) {
return Graph._drop(name, true);
}
};
var loadGraph = function(name) {
dropGraph(name);
switch (name) {
case "knows_graph":
return createTraversalExample();
case "routeplanner":
return createRoutePlannerGraph();
case "social":
return createSocialGraph();
}
var loadGraph = function(name) {
dropGraph(name);
switch (name) {
case "knows_graph":
return createTraversalExample();
case "routeplanner":
return createRoutePlannerGraph();
case "social":
return createSocialGraph();
}
};
};
exports.loadGraph = loadGraph;
exports.dropGraph = dropGraph;
}());
exports.loadGraph = loadGraph;
exports.dropGraph = dropGraph;

View File

@ -1,4 +1,4 @@
/*jshint strict: false */
'use strict';
////////////////////////////////////////////////////////////////////////////////
/// @brief Foxx application module
@ -28,40 +28,37 @@
/// @author Copyright 2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
(function() {
'use strict';
// -----------------------------------------------------------------------------
// --SECTION-- imports
// -----------------------------------------------------------------------------
var fs = require("fs");
var internal = require("internal");
var db = internal.db;
var _= require("underscore");
var utils = require("org/arangodb/foxx/manager-utils");
var console = require("console");
var arangodb = require("org/arangodb");
var ArangoError = arangodb.ArangoError;
var errors = arangodb.errors;
var throwFileNotFound = arangodb.throwFileNotFound;
var fs = require("fs");
var internal = require("internal");
var db = internal.db;
var _= require("underscore");
var utils = require("org/arangodb/foxx/manager-utils");
var console = require("console");
var arangodb = require("org/arangodb");
var ArangoError = arangodb.ArangoError;
var errors = arangodb.errors;
var throwFileNotFound = arangodb.throwFileNotFound;
// -----------------------------------------------------------------------------
// --SECTION-- private functions
// -----------------------------------------------------------------------------
function applyDefaultConfig(config) {
var res = {};
if (config !== undefined) {
Object.keys(config).forEach(function (attr) {
if (config[attr].default !== undefined) {
res[attr] = config[attr].default;
}
});
}
return res;
function applyDefaultConfig(config) {
var res = {};
if (config !== undefined) {
Object.keys(config).forEach(function (attr) {
if (config[attr].default !== undefined) {
res[attr] = config[attr].default;
}
});
}
return res;
}
// -----------------------------------------------------------------------------
// --SECTION-- constructors and destructors
@ -71,56 +68,56 @@
// --SECTION-- AppContext
// -----------------------------------------------------------------------------
function AppContext(app) {
var prefix = fs.safeJoin(app._root, app._path);
function AppContext(app) {
var prefix = fs.safeJoin(app._root, app._path);
this._prefix = prefix;
this.comments = [];
this.name = app._name;
this.version = app._version;
this.mount = app._mount;
this.collectionPrefix = app._collectionPrefix;
this.options = app._options;
this.configuration = app._options.configuration;
this.dependencies = app._dependencies;
this.basePath = prefix;
this.baseUrl = '/_db/' + encodeURIComponent(db._name()) + app._mount;
this.isDevelopment = app._isDevelopment;
this.isProduction = ! app._isDevelopment;
this.manifest = app._manifest;
this._prefix = prefix;
this.comments = [];
this.name = app._name;
this.version = app._version;
this.mount = app._mount;
this.collectionPrefix = app._collectionPrefix;
this.options = app._options;
this.configuration = app._options.configuration;
this.dependencies = app._dependencies;
this.basePath = prefix;
this.baseUrl = '/_db/' + encodeURIComponent(db._name()) + app._mount;
this.isDevelopment = app._isDevelopment;
this.isProduction = ! app._isDevelopment;
this.manifest = app._manifest;
}
AppContext.prototype.foxxFilename = function (path) {
return fs.safeJoin(this._prefix, path);
};
AppContext.prototype.collectionName = function (name) {
var replaced = this.collectionPrefix.replace(/[:\.]+/g, '_') +
name.replace(/[^a-zA-Z0-9]/g, '_').replace(/(^_+|_+$)/g, '').substr(0, 64);
if (replaced.length === 0) {
throw new Error("Cannot derive collection name from '" + name + "'");
}
AppContext.prototype.foxxFilename = function (path) {
return fs.safeJoin(this._prefix, path);
};
return replaced;
};
AppContext.prototype.collectionName = function (name) {
var replaced = this.collectionPrefix.replace(/[:\.]+/g, '_') +
name.replace(/[^a-zA-Z0-9]/g, '_').replace(/(^_+|_+$)/g, '').substr(0, 64);
AppContext.prototype.collection = function (name) {
return db._collection(this.collectionName(name));
};
if (replaced.length === 0) {
throw new Error("Cannot derive collection name from '" + name + "'");
}
return replaced;
};
AppContext.prototype.collection = function (name) {
return db._collection(this.collectionName(name));
};
AppContext.prototype.path = function (name) {
return fs.join(this._prefix, name);
};
AppContext.prototype.path = function (name) {
return fs.join(this._prefix, name);
};
AppContext.prototype.comment = function (str) {
this.comments.push(str);
};
AppContext.prototype.comment = function (str) {
this.comments.push(str);
};
AppContext.prototype.clearComments = function () {
this.comments = [];
};
AppContext.prototype.clearComments = function () {
this.comments = [];
};
// -----------------------------------------------------------------------------
// --SECTION-- ArangoApp
@ -131,7 +128,7 @@
////////////////////////////////////////////////////////////////////////////////
function isSystemMount(mount) {
return (/^\/_/).test(mount);
return (/^\/_/).test(mount);
}
////////////////////////////////////////////////////////////////////////////////
@ -139,72 +136,72 @@ function isSystemMount(mount) {
////////////////////////////////////////////////////////////////////////////////
function computeRootAppPath(mount, isValidation) {
if (isValidation) {
return "";
}
if (isSystemMount(mount)) {
return module.systemAppPath();
}
return module.appPath();
if (isValidation) {
return "";
}
if (isSystemMount(mount)) {
return module.systemAppPath();
}
return module.appPath();
}
////////////////////////////////////////////////////////////////////////////////
/// @brief ArangoApp constructor
////////////////////////////////////////////////////////////////////////////////
function ArangoApp(config) {
if (config.error) {
this._error = config.error;
this._isBroken = true;
}
this._manifest = config.manifest || {
name: "unknown",
version: "error"
};
if (!this._manifest.configuration) {
this._manifest.configuration = {};
}
if (!this._manifest.dependencies) {
this._manifest.dependencies = {};
}
this._name = this._manifest.name;
this._version = this._manifest.version;
this._root = computeRootAppPath(config.mount, config.id === "__internal");
this._path = config.path;
this._options = config.options;
this._mount = config.mount;
this._isSystem = config.isSystem || false;
this._isDevelopment = config.isDevelopment || false;
this._exports = {};
this._collectionPrefix = this._mount.substr(1).replace(/-/g, "_").replace(/\//g, "_") + "_";
function ArangoApp(config) {
if (config.error) {
this._error = config.error;
this._isBroken = true;
}
this._manifest = config.manifest || {
name: "unknown",
version: "error"
};
if (!this._manifest.configuration) {
this._manifest.configuration = {};
}
if (!this._manifest.dependencies) {
this._manifest.dependencies = {};
}
this._name = this._manifest.name;
this._version = this._manifest.version;
this._root = computeRootAppPath(config.mount, config.id === "__internal");
this._path = config.path;
this._options = config.options;
this._mount = config.mount;
this._isSystem = config.isSystem || false;
this._isDevelopment = config.isDevelopment || false;
this._exports = {};
this._collectionPrefix = this._mount.substr(1).replace(/-/g, "_").replace(/\//g, "_") + "_";
// Apply the default configuration and ignore all missing options
var cfg = config.options.configuration;
this._options.configuration = applyDefaultConfig(this._manifest.configuration);
this.configure(cfg);
// Apply the default configuration and ignore all missing options
var cfg = config.options.configuration;
this._options.configuration = applyDefaultConfig(this._manifest.configuration);
this.configure(cfg);
var deps = config.options.dependencies;
this._options.dependencies = {};
this._dependencies = {};
this.updateDeps(deps);
var deps = config.options.dependencies;
this._options.dependencies = {};
this._dependencies = {};
this.updateDeps(deps);
this._context = new AppContext(this);
this._context.appPackage = module.createAppPackage(this);
this._context.appModule = this._context.appPackage.createAppModule(this);
this._context = new AppContext(this);
this._context.appPackage = module.createAppPackage(this);
this._context.appModule = this._context.appPackage.createAppModule(this);
if (! this._manifest.hasOwnProperty("defaultDocument")) {
this._manifest.defaultDocument = "index.html";
}
if (this._manifest.hasOwnProperty("thumbnail")) {
var thumbfile = fs.join(this._root, this._path, this._manifest.thumbnail);
try {
this._thumbnail = fs.read64(thumbfile);
} catch (err) {
console.warnLines(
"Cannot read thumbnail '%s' : %s", thumbfile, err);
}
if (! this._manifest.hasOwnProperty("defaultDocument")) {
this._manifest.defaultDocument = "index.html";
}
if (this._manifest.hasOwnProperty("thumbnail")) {
var thumbfile = fs.join(this._root, this._path, this._manifest.thumbnail);
try {
this._thumbnail = fs.read64(thumbfile);
} catch (err) {
console.warnLines(
"Cannot read thumbnail '%s' : %s", thumbfile, err);
}
}
}
// -----------------------------------------------------------------------------
// --SECTION-- private methods
@ -214,9 +211,9 @@ function computeRootAppPath(mount, isValidation) {
/// @brief prints a package
////////////////////////////////////////////////////////////////////////////////
ArangoApp.prototype._PRINT = function (context) {
context.output += '[app "' + this._name + '" (' + this._version + ')]';
};
ArangoApp.prototype._PRINT = function (context) {
context.output += '[app "' + this._name + '" (' + this._version + ')]';
};
// -----------------------------------------------------------------------------
// --SECTION-- public methods
@ -226,216 +223,215 @@ function computeRootAppPath(mount, isValidation) {
/// @brief creates a Json representation of itself to be persisted
////////////////////////////////////////////////////////////////////////////////
ArangoApp.prototype.toJSON = function () {
var json = {
manifest: this._manifest,
name: this._name,
version: this._version,
path: this._path,
options: this._options,
mount: this._mount,
root: this._root,
isSystem: this._isSystem,
isDevelopment: this._isDevelopment
};
if (this.hasOwnProperty("_error")) {
json.error = this._error;
}
if (this._manifest.hasOwnProperty("author")) {
json.author = this._manifest.author;
}
if (this._manifest.hasOwnProperty("description")) {
json.description = this._manifest.description;
}
if (this.hasOwnProperty("_thumbnail")) {
json.thumbnail = this._thumbnail;
}
return json;
ArangoApp.prototype.toJSON = function () {
var json = {
manifest: this._manifest,
name: this._name,
version: this._version,
path: this._path,
options: this._options,
mount: this._mount,
root: this._root,
isSystem: this._isSystem,
isDevelopment: this._isDevelopment
};
if (this.hasOwnProperty("_error")) {
json.error = this._error;
}
if (this._manifest.hasOwnProperty("author")) {
json.author = this._manifest.author;
}
if (this._manifest.hasOwnProperty("description")) {
json.description = this._manifest.description;
}
if (this.hasOwnProperty("_thumbnail")) {
json.thumbnail = this._thumbnail;
}
return json;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief creates a reduced Json representation of itself for output
////////////////////////////////////////////////////////////////////////////////
ArangoApp.prototype.simpleJSON = function () {
var json = {
name: this._name,
version: this._version,
mount: this._mount
};
return json;
ArangoApp.prototype.simpleJSON = function () {
var json = {
name: this._name,
version: this._version,
mount: this._mount
};
return json;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief toggles development mode
////////////////////////////////////////////////////////////////////////////////
ArangoApp.prototype.development = function(activate) {
this._isDevelopment = activate;
};
ArangoApp.prototype.development = function(activate) {
this._isDevelopment = activate;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief set app dependencies
////////////////////////////////////////////////////////////////////////////////
ArangoApp.prototype.updateDeps = function (deps) {
var expected = this._manifest.dependencies;
var invalid = [];
ArangoApp.prototype.updateDeps = function (deps) {
var expected = this._manifest.dependencies;
var invalid = [];
_.each(deps, function (mount, name) {
if (!expected[name]) {
invalid.push("Unexpected dependency " + name);
_.each(deps, function (mount, name) {
if (!expected[name]) {
invalid.push("Unexpected dependency " + name);
}
this._options.dependencies[name] = mount;
}, this);
_.each(this._options.dependencies, function (mount, name) {
Object.defineProperty(this._dependencies, name, {
configurable: true,
enumerable: true,
get: function () {
return require("org/arangodb/foxx").requireApp(mount);
}
this._options.dependencies[name] = mount;
}, this);
});
}, this);
_.each(this._options.dependencies, function (mount, name) {
Object.defineProperty(this._dependencies, name, {
configurable: true,
enumerable: true,
get: function () {
return require("org/arangodb/foxx").requireApp(mount);
}
});
}, this);
return invalid;
};
return invalid;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief set app configuration
////////////////////////////////////////////////////////////////////////////////
ArangoApp.prototype.configure = function(config) {
var expected = this._manifest.configuration;
var invalid = [];
this._options.configuration = this._options.configuration || {};
ArangoApp.prototype.configure = function(config) {
var expected = this._manifest.configuration;
var invalid = [];
this._options.configuration = this._options.configuration || {};
_.each(config, function (value, name) {
if (!expected[name]) {
invalid.push("Unexpected Option " + name);
_.each(config, function (value, name) {
if (!expected[name]) {
invalid.push("Unexpected Option " + name);
} else {
var type = expected[name].type;
var result = utils.parameterTypes[type].validate(value);
if (result.error) {
invalid.push(result.error.message.replace(/^"value"/, '"' + name + '"'));
} else {
var type = expected[name].type;
var result = utils.parameterTypes[type].validate(value);
if (result.error) {
invalid.push(result.error.message.replace(/^"value"/, '"' + name + '"'));
} else {
this._options.configuration[name] = result.value;
}
this._options.configuration[name] = result.value;
}
}, this);
}
}, this);
return invalid;
};
return invalid;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief get app configuration
////////////////////////////////////////////////////////////////////////////////
ArangoApp.prototype.getConfiguration = function (simple) {
var config = {};
var definitions = this._manifest.configuration;
var options = this._options.configuration;
_.each(definitions, function (dfn, name) {
var value = options[name] === undefined ? dfn.default : options[name];
config[name] = simple ? value : _.extend(_.clone(dfn), {
title: utils.getReadableName(name),
current: value
});
ArangoApp.prototype.getConfiguration = function (simple) {
var config = {};
var definitions = this._manifest.configuration;
var options = this._options.configuration;
_.each(definitions, function (dfn, name) {
var value = options[name] === undefined ? dfn.default : options[name];
config[name] = simple ? value : _.extend(_.clone(dfn), {
title: utils.getReadableName(name),
current: value
});
return config;
};
});
return config;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief get app dependencies
////////////////////////////////////////////////////////////////////////////////
ArangoApp.prototype.getDependencies = function(simple) {
var deps = {};
var definitions = this._manifest.dependencies;
var options = this._options.dependencies;
_.each(definitions, function (dfn, name) {
deps[name] = simple ? options[name] : {
definition: dfn,
title: utils.getReadableName(name),
current: options[name]
};
});
return deps;
};
ArangoApp.prototype.getDependencies = function(simple) {
var deps = {};
var definitions = this._manifest.dependencies;
var options = this._options.dependencies;
_.each(definitions, function (dfn, name) {
deps[name] = simple ? options[name] : {
definition: dfn,
title: utils.getReadableName(name),
current: options[name]
};
});
return deps;
};
////////////////////////////////////////////////////////////////////////////////
/// @brief App needs to be configured
////////////////////////////////////////////////////////////////////////////////
ArangoApp.prototype.needsConfiguration = function() {
var config = this.getConfiguration();
var deps = this.getDependencies();
return _.any(config, function (cfg) {
return cfg.current === undefined;
}) || _.any(deps, function (dep) {
return dep.current === undefined;
});
};
ArangoApp.prototype.needsConfiguration = function() {
var config = this.getConfiguration();
var deps = this.getDependencies();
return _.any(config, function (cfg) {
return cfg.current === undefined;
}) || _.any(deps, function (dep) {
return dep.current === undefined;
});
};
////////////////////////////////////////////////////////////////////////////////
/// @brief loadAppScript
////////////////////////////////////////////////////////////////////////////////
ArangoApp.prototype.loadAppScript = function (filename, options) {
options = options || {};
ArangoApp.prototype.loadAppScript = function (filename, options) {
options = options || {};
var appContext = _.extend({}, options.appContext, this._context);
var full = fs.join(this._root, this._path, filename);
var appContext = _.extend({}, options.appContext, this._context);
var full = fs.join(this._root, this._path, filename);
if (!fs.exists(full)) {
throwFileNotFound(full);
if (!fs.exists(full)) {
throwFileNotFound(full);
}
var fileContent = fs.read(full);
if (options.transform) {
fileContent = options.transform(fileContent);
} else if (/\.coffee$/.test(filename)) {
var cs = require("coffee-script");
fileContent = cs.compile(fileContent, {bare: true});
}
var context = {};
if (options.context) {
Object.keys(options.context).forEach(function (key) {
context[key] = options.context[key];
});
}
var localModule = appContext.appPackage.createAppModule(this, filename);
context.__filename = full;
context.__dirname = module.normalizeModuleName(full + "/..");
context.console = require("org/arangodb/foxx/console")(this._mount);
context.applicationContext = appContext;
try {
return localModule.run(fileContent, context);
} catch(e) {
if (e instanceof ArangoError) {
throw e;
}
var err = new ArangoError({
errorNum: errors.ERROR_FAILED_TO_EXECUTE_SCRIPT.code,
errorMessage: errors.ERROR_FAILED_TO_EXECUTE_SCRIPT.message
+ "\nFile: " + filename
});
err.stack = e.stack;
err.cause = e;
throw err;
}
};
var fileContent = fs.read(full);
if (options.transform) {
fileContent = options.transform(fileContent);
} else if (/\.coffee$/.test(filename)) {
var cs = require("coffee-script");
fileContent = cs.compile(fileContent, {bare: true});
}
var context = {};
if (options.context) {
Object.keys(options.context).forEach(function (key) {
context[key] = options.context[key];
});
}
var localModule = appContext.appPackage.createAppModule(this, filename);
context.__filename = full;
context.__dirname = module.normalizeModuleName(full + "/..");
context.console = require("org/arangodb/foxx/console")(this._mount);
context.applicationContext = appContext;
try {
return localModule.run(fileContent, context);
} catch(e) {
if (e instanceof ArangoError) {
throw e;
}
var err = new ArangoError({
errorNum: errors.ERROR_FAILED_TO_EXECUTE_SCRIPT.code,
errorMessage: errors.ERROR_FAILED_TO_EXECUTE_SCRIPT.message
+ "\nFile: " + filename
});
err.stack = e.stack;
err.cause = e;
throw err;
}
};
exports.ArangoApp = ArangoApp;
}());
exports.ArangoApp = ArangoApp;
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,4 @@
'use strict';
////////////////////////////////////////////////////////////////////////////////
/// @brief Foxx Swagger documentation
@ -26,67 +27,63 @@
/// @author Copyright 2015, ArangoDB GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
(function() {
'use strict';
var foxxInternal = require("org/arangodb/foxx/internals");
var _ = require("underscore");
var internal = require("internal");
var foxxInternal = require("org/arangodb/foxx/internals");
var _ = require("underscore");
var internal = require("internal");
// Wraps the docs object of a route to add swagger compatible documentation
var SwaggerDocs = function (docs, models) {
this.docs = docs;
this.models = models;
};
// Wraps the docs object of a route to add swagger compatible documentation
var SwaggerDocs = function (docs, models) {
this.docs = docs;
this.models = models;
};
SwaggerDocs.prototype.addNickname = function (httpMethod, match) {
this.docs.nickname = foxxInternal.constructNickname(httpMethod, match);
};
SwaggerDocs.prototype.addNickname = function (httpMethod, match) {
this.docs.nickname = foxxInternal.constructNickname(httpMethod, match);
};
SwaggerDocs.prototype.addPathParam = function (paramName, description, dataType, required) {
this.docs.parameters.push(foxxInternal.constructPathParamDoc(paramName, description, dataType, required));
};
SwaggerDocs.prototype.addPathParam = function (paramName, description, dataType, required) {
this.docs.parameters.push(foxxInternal.constructPathParamDoc(paramName, description, dataType, required));
};
SwaggerDocs.prototype.addQueryParam = function (paramName, description, dataType, required, allowMultiple) {
this.docs.parameters.push(foxxInternal.constructQueryParamDoc(
paramName,
description,
dataType,
required,
allowMultiple
));
};
SwaggerDocs.prototype.addQueryParam = function (paramName, description, dataType, required, allowMultiple) {
this.docs.parameters.push(foxxInternal.constructQueryParamDoc(
paramName,
description,
dataType,
required,
allowMultiple
));
};
SwaggerDocs.prototype.addBodyParam = function (paramName, description, jsonSchema) {
SwaggerDocs.prototype.addBodyParam = function (paramName, description, jsonSchema) {
var token = internal.genRandomAlphaNumbers(32);
this.models[token] = jsonSchema;
var token = internal.genRandomAlphaNumbers(32);
this.models[token] = jsonSchema;
var param = _.find(this.docs.parameters, function (parameter) {
return parameter.name === 'undocumented body';
});
var param = _.find(this.docs.parameters, function (parameter) {
return parameter.name === 'undocumented body';
if (_.isUndefined(param)) {
this.docs.parameters.push({
name: paramName,
paramType: "body",
description: description,
dataType: token
});
} else {
param.name = paramName;
param.description = description;
param.dataType = token;
}
};
if (_.isUndefined(param)) {
this.docs.parameters.push({
name: paramName,
paramType: "body",
description: description,
dataType: token
});
} else {
param.name = paramName;
param.description = description;
param.dataType = token;
}
};
SwaggerDocs.prototype.addSummary = function (summary) {
this.docs.summary = summary;
};
SwaggerDocs.prototype.addSummary = function (summary) {
this.docs.summary = summary;
};
SwaggerDocs.prototype.addNotes = function (notes) {
this.docs.notes = notes;
};
SwaggerDocs.prototype.addNotes = function (notes) {
this.docs.notes = notes;
};
exports.Docs = SwaggerDocs;
}());