1
0
Fork 0

added reload for DB modules

This commit is contained in:
Frank Celler 2015-04-05 14:02:34 +02:00
parent e5cb905b62
commit de1a9fe833
2 changed files with 46 additions and 13 deletions

View File

@ -420,7 +420,7 @@ function require (path) {
/// @brief checks if a file exists as document in a collection /// @brief checks if a file exists as document in a collection
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
function checkModulePathDB (origin, path) { function checkModulePathDb (origin, path) {
'use strict'; 'use strict';
if (internal.db === undefined) { if (internal.db === undefined) {
@ -435,9 +435,11 @@ function require (path) {
} }
var n; var n;
var mc;
var collection = m[1];
try { try {
var mc = internal.db._collection(m[1]); mc = internal.db._collection(collection);
if (mc === null || typeof mc.firstExample !== "function") { if (mc === null || typeof mc.firstExample !== "function") {
return null; return null;
@ -459,7 +461,8 @@ function require (path) {
path: normalizeModuleName(path + "/.."), path: normalizeModuleName(path + "/.."),
origin: origin + path.substr(1), origin: origin + path.substr(1),
type: "js", type: "js",
content: n.content content: n.content,
revision: mc.revision()
}; };
} }
@ -633,8 +636,8 @@ function require (path) {
description = checkModulePathFile(currentPackage, root, path); description = checkModulePathFile(currentPackage, root, path);
} }
else if (currentPackage._origin.substr(0, 5) === "db://") { else if (currentPackage._isDbPackage) {
description = checkModulePathDB(currentPackage._origin, path); description = checkModulePathDb(currentPackage._origin, path);
} }
else if (currentPackage._origin.substr(0, 10) === "system:///") { else if (currentPackage._origin.substr(0, 10) === "system:///") {
description = null; description = null;
@ -650,8 +653,19 @@ function require (path) {
var localModule = currentPackage.module(description.id, description.type); var localModule = currentPackage.module(description.id, description.type);
if (localModule !== null) { if (localModule !== null) {
if (currentPackage._isDbPackage) {
if (localModule._revision === description.revision) {
return localModule; return localModule;
} }
else {
currentPackage.clearModule(description.id, description.type);
localModule = null;
}
}
else {
return localModule;
}
}
if (currentPackage._origin.substr(0, 7) === "file://") { if (currentPackage._origin.substr(0, 7) === "file://") {
var filename = fileUri2Path(description.origin); var filename = fileUri2Path(description.origin);
@ -671,12 +685,12 @@ function require (path) {
throw err; throw err;
} }
} }
else if (currentPackage._origin.substr(0, 5) !== "db://") { else if (! currentPackage._isDbPackage) {
throw new Error("package origin '" + currentPackage._origin + "' not supported"); throw new Error("package origin '" + currentPackage._origin + "' not supported");
} }
if (description.type === "js") { if (description.type === "js") {
return createModule(currentModule, currentPackage, description); localModule = createModule(currentModule, currentPackage, description);
} }
if (description.type === "coffee") { if (description.type === "coffee") {
@ -684,16 +698,20 @@ function require (path) {
description.content = cs.compile(description.content, {bare: true}); description.content = cs.compile(description.content, {bare: true});
return createModule(currentModule, currentPackage, description); localModule = createModule(currentModule, currentPackage, description);
} }
if (description.type === "json") { if (description.type === "json") {
localModule = { exports: JSON.parse(description.content) }; localModule = { exports: JSON.parse(description.content) };
return currentPackage.defineModule(description.id, description.type, localModule); localModule = currentPackage.defineModule(description.id, description.type, localModule);
} }
return null; if (localModule !== null && currentPackage._isDbPackage) {
localModule._revision = description.revision;
}
return localModule;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -990,6 +1008,7 @@ function require (path) {
this._origin = origin; // root of the package this._origin = origin; // root of the package
this._isSystem = isSystem; // is a system package this._isSystem = isSystem; // is a system package
this._isDbPackage = false;
}; };
(function () { (function () {
@ -1006,6 +1025,7 @@ function require (path) {
} }
pkg = new Package("/", {}, undefined, "db://_modules/", false); pkg = new Package("/", {}, undefined, "db://_modules/", false);
pkg._isDbPackage = true;
globalPackages.push(pkg); globalPackages.push(pkg);
systemPackage = new Package("/", { name: "ArangoDB system" }, undefined, "system:///", true); systemPackage = new Package("/", { name: "ArangoDB system" }, undefined, "system:///", true);

View File

@ -877,7 +877,20 @@ function buildRoutingTree (routes) {
analyseRoutes(storage, route); analyseRoutes(storage, route);
} }
else { else {
installRoute(storage.routes, route, "", {});
// use normal root module or app context
var appContext;
if (route.hasOwnProperty('appContext')) {
appContext = routes.appContext;
}
else {
appContext = {
module: module.root
};
}
installRoute(storage.routes, route, "", appContext);
} }
} }
catch (err) { catch (err) {