From 314022ef2a33536cd303d873534302bfe791f395 Mon Sep 17 00:00:00 2001 From: Lucas Dohmen Date: Thu, 4 Apr 2013 18:19:45 +0200 Subject: [PATCH 1/7] Foxx: Documentation Fixes --- Documentation/UserManual/Foxx.md | 23 +++++++----- js/server/modules/org/arangodb/foxx.js | 51 ++++++++++++-------------- 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/Documentation/UserManual/Foxx.md b/Documentation/UserManual/Foxx.md index d1a44bd9d1..7f6528777a 100644 --- a/Documentation/UserManual/Foxx.md +++ b/Documentation/UserManual/Foxx.md @@ -118,16 +118,16 @@ Furthermore you can describe your API by chaining the following methods onto you #### Describing a queryParam @copydetails JSF_foxx_RequestContext_queryParam -### Documenting the nickname of a route +#### Documenting the nickname of a route @copydetails JSF_foxx_RequestContext_nickname -### Documenting the summary of a route +#### Documenting the summary of a route @copydetails JSF_foxx_RequestContext_summary -### Documenting the notes of a route +#### Documenting the notes of a route @copydetails JSF_foxx_RequestContext_notes -### Documenting the error response of a route +#### Documenting the error response of a route @copydetails JSF_foxx_RequestContext_errorResponse ### Before and After Hooks @@ -218,10 +218,11 @@ A Foxx Model can be initialized with an object of attributes and their values. @copydetails JSF_foxx_model_has #### Foxx.Model#attributes -@copydetails JSF_foxx_model_attributes + +The attributes property is the internal hash containing the model's state. #### Foxx.Model#toJSON -@copydetails JSF_foxx_model_toJSON +@copydetails jsf_foxx_model_toJSON ## Foxx.Repository @@ -237,15 +238,17 @@ A repository is a gateway to the database. It gets data from the database, updat #### new Foxx.Repository @copydetails JSF_foxx_repository_initializer - #### Foxx.Repository#collection -@copydetails JSF_foxx_repository_collection + +The collection object. #### Foxx.Repository#prefix -@copydetails JSF_foxx_repository_prefix + +The prefix of the application. #### Foxx.Repository#modelPrototype -@copydetails JSF_foxx_repository_modelPrototype + +The prototype of the according model. #### Foxx.Repository#save diff --git a/js/server/modules/org/arangodb/foxx.js b/js/server/modules/org/arangodb/foxx.js index 95aacfbfd5..c3db4c8adf 100644 --- a/js/server/modules/org/arangodb/foxx.js +++ b/js/server/modules/org/arangodb/foxx.js @@ -52,13 +52,14 @@ var Application, /// @fn JSF_foxx_createUrlObject /// @brief create a new url object /// +/// This creates a new `UrlObject`. /// ArangoDB uses a certain structure we refer to as `UrlObject`. /// With the following function (which is only internal, and not /// exported) you can create an UrlObject with a given URL, /// a constraint and a method. For example: /// /// @EXAMPLES -/// internal.createUrlObject('/lecker/gans', null, 'get') +/// internal.createUrlObject('/lecker/gans', null, 'get'); //////////////////////////////////////////////////////////////////////////////// internal.createUrlObject = function (url, constraint, method) { @@ -83,8 +84,7 @@ internal.createUrlObject = function (url, constraint, method) { /// @fn JSF_foxx_application_initializer /// @brief Create a new Application /// -/// And that's Application. It's a constructor, so call it like this: -/// It takes two optional arguments as displayed above: +/// This creates a new Application. It takes two optional arguments as displayed above: /// * **The URL Prefix:** All routes you define within will be prefixed with it /// * **The Template Collection:** More information in the template section /// @@ -289,7 +289,7 @@ _.extend(Application.prototype, { /// See above for the arguments you can give. /// **A word of warning:** Do not forget that `delete` is /// a reserved word in JavaScript and therefore needs to be -/// called as `app['delete']`. There is also an alias `del` +/// called as app['delete']. There is also an alias `del` /// for this very reason. /// /// @EXAMPLES @@ -400,6 +400,7 @@ _.extend(Application.prototype, { /// @fn JSF_foxx_application_accepts /// @brief Shortform for using the FormatMiddleware /// +/// Shortform for using the FormatMiddleware /// More information about the FormatMiddleware in the corresponding section. /// This is a shortcut to add the middleware to your application: /// @@ -440,6 +441,7 @@ _.extend(RequestContext.prototype, { /// @fn JSF_foxx_RequestContext_pathParam /// @brief Describe a Path Parameter /// +/// Describe a Path Paramter: /// If you defined a route "/foxx/:id", you can constrain which format the id /// can have by giving a type. We currently support the following types: /// @@ -480,6 +482,7 @@ _.extend(RequestContext.prototype, { /// @fn JSF_foxx_RequestContext_queryParam /// @brief Describe a Query Parameter /// +/// Describe a Query Parameter: /// If you defined a route "/foxx", you can constrain which format a query /// parameter (`/foxx?a=12`) can have by giving it a type. /// We currently support the following types: @@ -517,7 +520,7 @@ _.extend(RequestContext.prototype, { //////////////////////////////////////////////////////////////////////////////// /// @fn JSF_foxx_RequestContext_nickname -/// @brief Set the nickname for this route in the documentation +/// Set the nickname for this route in the documentation //////////////////////////////////////////////////////////////////////////////// nickname: function (nickname) { @@ -533,6 +536,7 @@ _.extend(RequestContext.prototype, { /// @fn JSF_foxx_RequestContext_summary /// @brief Set the summary for this route in the documentation /// +/// Set the summary for this route in the documentation /// Can't be longer than 60 characters //////////////////////////////////////////////////////////////////////////////// @@ -548,6 +552,8 @@ _.extend(RequestContext.prototype, { //////////////////////////////////////////////////////////////////////////////// /// @fn JSF_foxx_RequestContext_notes /// @brief Set the notes for this route in the documentation +/// +/// Set the notes for this route in the documentation //////////////////////////////////////////////////////////////////////////////// notes: function (notes) { @@ -860,11 +866,6 @@ FormatMiddleware = function (allowedFormats, defaultFormat) { Model = function (attributes) { 'use strict'; -//////////////////////////////////////////////////////////////////////////////// -/// @fn JSF_foxx_model_attributes -/// @brief The attributes property is the internal hash containing the model's state. -//////////////////////////////////////////////////////////////////////////////// - this.attributes = attributes || {}; }; @@ -873,6 +874,7 @@ _.extend(Model.prototype, { /// @fn JSF_foxx_model_get /// @brief Get the value of an attribute /// +/// Get the value of an attribute /// @EXAMPLES /// instance = new Model({ /// a: 1 @@ -889,6 +891,7 @@ _.extend(Model.prototype, { /// @fn JSF_foxx_model_set /// @brief Set the value of an attribute /// +/// Set the value of an attribute /// @EXAMPLES /// instance = new Model({ /// a: 1 @@ -905,6 +908,7 @@ _.extend(Model.prototype, { /// @fn JSF_foxx_model_has /// @brief Returns true if the attribute is set to a non-null or non-undefined value. /// +/// Returns true if the attribute is set to a non-null or non-undefined value. /// @EXAMPLES /// instance = new Model({ /// a: 1 @@ -921,7 +925,10 @@ _.extend(Model.prototype, { //////////////////////////////////////////////////////////////////////////////// /// @fn JSF_foxx_model_toJSON -/// @brief Return a copy of the model which can be saved into ArangoDB (or send to the client). +/// @brief Return a copy of the model which can be saved into ArangoDB +/// +/// Return a copy of the model which can be saved into ArangoDB +/// (or send to the client). //////////////////////////////////////////////////////////////////////////////// toJSON: function () { @@ -932,6 +939,8 @@ _.extend(Model.prototype, { //////////////////////////////////////////////////////////////////////////////// /// @fn JSF_foxx_model_extend /// @brief Extend the Model prototype to add or overwrite methods. +/// +/// Extend the Model prototype to add or overwrite methods. //////////////////////////////////////////////////////////////////////////////// Model.extend = backbone_helpers.extend; @@ -940,6 +949,7 @@ Model.extend = backbone_helpers.extend; /// @fn JSF_foxx_repository_initializer /// @brief Create a new instance of Repository /// +/// Create a new instance of Repository /// A Foxx Repository is always initialized with the prefix, the collection and the modelPrototype. /// If you initialize a model, you can give it initial data as an object. /// @@ -950,31 +960,16 @@ Model.extend = backbone_helpers.extend; Repository = function (prefix, collection, modelPrototype) { 'use strict'; -//////////////////////////////////////////////////////////////////////////////// -/// @fn JSF_foxx_repository_prefix -/// @brief The prefix of the application. -//////////////////////////////////////////////////////////////////////////////// - this.prefix = prefix; - -//////////////////////////////////////////////////////////////////////////////// -/// @fn JSF_foxx_repository_collection -/// @brief The collection object. -//////////////////////////////////////////////////////////////////////////////// - this.collection = collection; - -//////////////////////////////////////////////////////////////////////////////// -/// @fn JSF_foxx_repository_modelPrototype -/// @brief The prototype of the according model. -//////////////////////////////////////////////////////////////////////////////// - this.modelPrototype = modelPrototype; }; //////////////////////////////////////////////////////////////////////////////// /// @fn JSF_foxx_repository_extend /// @brief Extend the Repository prototype to add or overwrite methods. +/// +/// Extend the Repository prototype to add or overwrite methods. //////////////////////////////////////////////////////////////////////////////// Repository.extend = backbone_helpers.extend; From 37e134ff503b9ac464be49c83f854ecbd5f59656 Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Thu, 4 Apr 2013 18:56:38 +0200 Subject: [PATCH 2/7] new Foxx --- 3rdParty/zlib-1.2.7/Makefile | 20 +- arangod/Ahuacatl/ahuacatl-grammar.c | 86 +++---- js/common/bootstrap/modules.js | 4 +- js/server/modules/org/arangodb/actions.js | 225 ++++++++++-------- .../modules/org/arangodb/foxx-manager.js | 91 ++++--- js/server/modules/org/arangodb/foxx.js | 9 +- 6 files changed, 235 insertions(+), 200 deletions(-) diff --git a/3rdParty/zlib-1.2.7/Makefile b/3rdParty/zlib-1.2.7/Makefile index 6815f0c9c2..6c499fad7b 100644 --- a/3rdParty/zlib-1.2.7/Makefile +++ b/3rdParty/zlib-1.2.7/Makefile @@ -18,26 +18,26 @@ CC=gcc -CFLAGS=-O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN +CFLAGS=-O3 -DHAVE_HIDDEN #CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7 #CFLAGS=-g -DDEBUG #CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \ # -Wstrict-prototypes -Wmissing-prototypes -SFLAGS=-O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN +SFLAGS=-O3 -fPIC -DHAVE_HIDDEN LDFLAGS= TEST_LDFLAGS=-L. libz.a -LDSHARED=gcc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map +LDSHARED=gcc -dynamiclib -install_name ${exec_prefix}/lib/libz.1.dylib -compatibility_version 1 -current_version 1.2.7 CPP=gcc -E STATICLIB=libz.a -SHAREDLIB=libz.so -SHAREDLIBV=libz.so.1.2.7 -SHAREDLIBM=libz.so.1 +SHAREDLIB=libz.dylib +SHAREDLIBV=libz.1.2.7.dylib +SHAREDLIBM=libz.1.dylib LIBS=$(STATICLIB) $(SHAREDLIBV) -AR=ar -ARFLAGS=rc +AR=/usr/bin/libtool +ARFLAGS=-o RANLIB=ranlib LDCONFIG=ldconfig LDSHAREDLIBC=-lc @@ -70,7 +70,7 @@ OBJS = $(OBJC) $(OBJA) PIC_OBJS = $(PIC_OBJC) $(PIC_OBJA) -all: static shared all64 +all: static shared static: example$(EXE) minigzip$(EXE) @@ -80,7 +80,7 @@ all64: example64$(EXE) minigzip64$(EXE) check: test -test: all teststatic testshared test64 +test: all teststatic testshared teststatic: static @TMPST=`mktemp fooXXXXXX`; \ diff --git a/arangod/Ahuacatl/ahuacatl-grammar.c b/arangod/Ahuacatl/ahuacatl-grammar.c index b501f6c7dc..e74911be16 100644 --- a/arangod/Ahuacatl/ahuacatl-grammar.c +++ b/arangod/Ahuacatl/ahuacatl-grammar.c @@ -1810,7 +1810,7 @@ yyreduce: } node = TRI_CreateNodeForAql(context, (yyvsp[(2) - (4)].strval), (yyvsp[(4) - (4)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -1826,7 +1826,7 @@ yyreduce: #line 225 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeFilterAql(context, (yyvsp[(2) - (2)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -1842,7 +1842,7 @@ yyreduce: #line 238 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeLetAql(context, (yyvsp[(2) - (4)].strval), (yyvsp[(4) - (4)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -1859,7 +1859,7 @@ yyreduce: { TRI_aql_node_t* node = TRI_CreateNodeListAql(context); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -1873,7 +1873,7 @@ yyreduce: #line 259 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeCollectAql(context, TRI_PopStackParseAql(context), (yyvsp[(4) - (4)].strval)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -1905,7 +1905,7 @@ yyreduce: #line 279 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeAssignAql(context, (yyvsp[(1) - (3)].strval), (yyvsp[(3) - (3)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -1940,7 +1940,7 @@ yyreduce: { TRI_aql_node_t* node = TRI_CreateNodeListAql(context); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -1955,7 +1955,7 @@ yyreduce: { TRI_aql_node_t* list = TRI_PopStackParseAql(context); TRI_aql_node_t* node = TRI_CreateNodeSortAql(context, list); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -1993,7 +1993,7 @@ yyreduce: #line 336 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeSortElementAql(context, (yyvsp[(1) - (2)].node), (yyvsp[(2) - (2)].boolval)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2034,7 +2034,7 @@ yyreduce: #line 359 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeLimitAql(context, TRI_CreateNodeValueIntAql(context, 0), (yyvsp[(2) - (2)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2051,7 +2051,7 @@ yyreduce: #line 370 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeLimitAql(context, (yyvsp[(2) - (4)].node), (yyvsp[(4) - (4)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2067,7 +2067,7 @@ yyreduce: #line 383 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeReturnAql(context, (yyvsp[(2) - (2)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2208,7 +2208,7 @@ yyreduce: } node = TRI_CreateNodeListAql(context); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2223,7 +2223,7 @@ yyreduce: { TRI_aql_node_t* list = TRI_PopStackParseAql(context); TRI_aql_node_t* node = TRI_CreateNodeFcallAql(context, TRI_PopStackParseAql(context), list); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2237,7 +2237,7 @@ yyreduce: #line 489 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeOperatorUnaryPlusAql(context, (yyvsp[(2) - (2)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2251,7 +2251,7 @@ yyreduce: #line 497 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeOperatorUnaryMinusAql(context, (yyvsp[(2) - (2)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2265,7 +2265,7 @@ yyreduce: #line 505 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeOperatorUnaryNotAql(context, (yyvsp[(2) - (2)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2279,7 +2279,7 @@ yyreduce: #line 516 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeOperatorBinaryOrAql(context, (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2293,7 +2293,7 @@ yyreduce: #line 524 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeOperatorBinaryAndAql(context, (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2307,7 +2307,7 @@ yyreduce: #line 532 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeOperatorBinaryPlusAql(context, (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2321,7 +2321,7 @@ yyreduce: #line 540 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeOperatorBinaryMinusAql(context, (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2335,7 +2335,7 @@ yyreduce: #line 548 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeOperatorBinaryTimesAql(context, (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2349,7 +2349,7 @@ yyreduce: #line 556 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeOperatorBinaryDivAql(context, (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2363,7 +2363,7 @@ yyreduce: #line 564 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeOperatorBinaryModAql(context, (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2377,7 +2377,7 @@ yyreduce: #line 572 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeOperatorBinaryEqAql(context, (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2391,7 +2391,7 @@ yyreduce: #line 580 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeOperatorBinaryNeAql(context, (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2405,7 +2405,7 @@ yyreduce: #line 588 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeOperatorBinaryLtAql(context, (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2419,7 +2419,7 @@ yyreduce: #line 596 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeOperatorBinaryGtAql(context, (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2433,7 +2433,7 @@ yyreduce: #line 604 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeOperatorBinaryLeAql(context, (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2447,7 +2447,7 @@ yyreduce: #line 612 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeOperatorBinaryGeAql(context, (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2461,7 +2461,7 @@ yyreduce: #line 620 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeOperatorBinaryInAql(context, (yyvsp[(1) - (3)].node), (yyvsp[(3) - (3)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2475,7 +2475,7 @@ yyreduce: #line 631 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeOperatorTernaryAql(context, (yyvsp[(1) - (5)].node), (yyvsp[(3) - (5)].node), (yyvsp[(5) - (5)].node)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2541,7 +2541,7 @@ yyreduce: #line 667 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeListAql(context); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2602,7 +2602,7 @@ yyreduce: #line 700 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeArrayAql(context); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2694,7 +2694,7 @@ yyreduce: // create a temporary variable for the row iterator (will be popped by "expansion" rule") node = TRI_CreateNodeReferenceAql(context, varname); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2750,7 +2750,7 @@ yyreduce: node = TRI_CreateNodeCollectionAql(context, (yyvsp[(1) - (1)].strval)); } - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2881,7 +2881,7 @@ yyreduce: #line 881 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeValueStringAql(context, (yyvsp[(1) - (1)].strval)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2917,7 +2917,7 @@ yyreduce: } node = TRI_CreateNodeValueDoubleAql(context, value); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2931,7 +2931,7 @@ yyreduce: #line 913 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeValueNullAql(context); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2945,7 +2945,7 @@ yyreduce: #line 921 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeValueBoolAql(context, true); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2959,7 +2959,7 @@ yyreduce: #line 929 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeValueBoolAql(context, false); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -2973,7 +2973,7 @@ yyreduce: #line 940 "arangod/Ahuacatl/ahuacatl-grammar.y" { TRI_aql_node_t* node = TRI_CreateNodeParameterAql(context, (yyvsp[(1) - (1)].strval)); - if (! node) { + if (node == NULL) { ABORT_OOM } @@ -3031,7 +3031,7 @@ yyreduce: } node = TRI_CreateNodeValueIntAql(context, value); - if (! node) { + if (node == NULL) { ABORT_OOM } diff --git a/js/common/bootstrap/modules.js b/js/common/bootstrap/modules.js index bb4800dcc4..d4f2b0d79c 100644 --- a/js/common/bootstrap/modules.js +++ b/js/common/bootstrap/modules.js @@ -1200,7 +1200,7 @@ function require (path) { /// @brief createAppModule //////////////////////////////////////////////////////////////////////////////// - ArangoApp.prototype.createAppModule = function (type, rootPackage) { + ArangoApp.prototype.createAppModule = function (type) { 'use strict'; if (type === undefined) { @@ -1218,7 +1218,7 @@ function require (path) { var pkg = new Package("application", {name: "application '" + this._name + "'"}, - rootPackage, + undefined, [ libpath ]); return new Module("application", 'application', pkg); diff --git a/js/server/modules/org/arangodb/actions.js b/js/server/modules/org/arangodb/actions.js index f3482a569f..971e3681ad 100644 --- a/js/server/modules/org/arangodb/actions.js +++ b/js/server/modules/org/arangodb/actions.js @@ -34,6 +34,7 @@ var fs = require("fs"); var console = require("console"); var arangodb = require("org/arangodb"); +var foxx = require("org/arangodb/foxx"); var foxxManager = require("org/arangodb/foxx-manager"); var moduleExists = function(name) { return module.exists; }; @@ -79,7 +80,7 @@ var ALL_METHODS = [ "DELETE", "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" ] function notImplementedFunction (route, message) { message += "\nThis error was triggered by the following route " + JSON.stringify(route); - console.error(message); + console.error("%s", message); return function (req, res, options, next) { res.responseCode = exports.HTTP_NOT_IMPLEMENTED; @@ -95,7 +96,7 @@ function notImplementedFunction (route, message) { function errorFunction (route, message) { message += "\nThis error was triggered by the following route " + JSON.stringify(route); - console.error(message); + console.error("%s", message); return function (req, res, options, next) { res.responseCode = exports.HTTP_SERVER_ERROR; @@ -221,91 +222,29 @@ function lookupCallbackStatic (content) { /// @brief looks up a callback for a callback action //////////////////////////////////////////////////////////////////////////////// -function lookupCallbackActionCallback (route, action) { +function lookupCallbackActionCallback (route, action, context) { var defn; var env; var func; var key; var app; var appModule; - var modelModule; defn = "func = (function() { var callback = " + action.callback + "; return callback;})();"; env = {}; try { - if (action.hasOwnProperty("context")) { - app = module.createApp(action.context.appId); - - if (app === null) { - throw "cannot locate application '" + action.context.name + "'" - + " in version '" + action.context.version + "'"; - } - - appModule = app.createAppModule(); - - if (action.hasOwnProperty("requiresModels")) { - var cp = action.context.collectionPrefix; - var me; - - modelModule = app.createAppModule('models', appModule._package); - me = modelModule._package._environment = {}; - - if (cp !== "") { - me.appCollectionName = function (name) { - return cp + "_" + name; - }; - - me.appCollection = function (name) { - return arangodb.db._collection(cp + "_" + name); - }; - } - else { - me.appCollectionName = function (name) { - return name; - }; - - me.appCollection = function (name) { - return arangodb.db._collection(name); - }; - } - - me.requireModel = function (path) { - modelModule.require(path); - }; - } - else { - modelModule = appModule; - } - } - else { - appModule = module.root; - modelModule = appModule; - } - - if (action.hasOwnProperty("requiresLibs")) { - var requires = action.requiresLibs; - - for (key in requires) { - if (requires.hasOwnProperty(key)) { - env[key] = appModule.require(requires[key]); - } - } - } - - if (action.hasOwnProperty("requiresModels")) { - var models = action.requiresModels; - - for (key in models) { - if (models.hasOwnProperty(key)) { - env[key] = modelModule.require(models[key]); - } + for (key in context.requires) { + if (context.requires.hasOwnProperty(key)) { + env[key] = context.requires[key]; } } env.module = module.root; + env.repositories = context.repositories; + env.require = function (path) { - return appModule.require(path); + return context.appModule.require(path); }; internal.executeScript(defn, env, route); @@ -316,7 +255,7 @@ function lookupCallbackActionCallback (route, action) { else { func = notImplementedFunction( route, - "could not define function '" + action.callback); + "could not define function for '" + action.callback + "'"); } } catch (err) { @@ -554,7 +493,7 @@ function lookupCallbackActionPrefixController (route, action) { /// @brief looks up a callback for an action //////////////////////////////////////////////////////////////////////////////// -function lookupCallbackAction (route, action) { +function lookupCallbackAction (route, action, context) { // ............................................................................. // short-cut for prefix controller @@ -569,7 +508,7 @@ function lookupCallbackAction (route, action) { // ............................................................................. if (action.hasOwnProperty('callback')) { - return lookupCallbackActionCallback(route, action); + return lookupCallbackActionCallback(route, action, context); } // ............................................................................. @@ -603,14 +542,51 @@ function lookupCallbackAction (route, action) { /// @brief looks up a callback //////////////////////////////////////////////////////////////////////////////// -function lookupCallback (route) { +function lookupCallback (route, context) { var result = null; if (route.hasOwnProperty('content')) { result = lookupCallbackStatic(route.content); } else if (route.hasOwnProperty('action')) { - result = lookupCallbackAction(route, route.action); + result = lookupCallbackAction(route, route.action, context); + } + + return result; +} + +//////////////////////////////////////////////////////////////////////////////// +/// @brief creates all contexts +//////////////////////////////////////////////////////////////////////////////// + +function createContexts (appModule, appContext, desc) { + var key; + var c; + + var result = {}; + + for (key in desc) { + if (desc.hasOwnProperty(key)) { + var d = desc[key]; + var collectionPrefix = appContext.connectionPrefix; + + result[key] = { + appModule: appModule, + repositories: {}, + requires: {} + }; + + if (d.hasOwnProperty('requires')) { + for (c in d.requires) { + if (d.requires.hasOwnProperty(c)) { + var name = d.requires[c]; + var m = appModule.require(name); + + result[key].requires[c] = m; + } + } + } + } } return result; @@ -1101,10 +1077,6 @@ function resultError (req, res, httpReturnCode, errorNum, errorMessage, headers, function reloadRouting () { var i; var j; - var routes; - var routing; - var handleRoute; - var handleMiddleware; var method; // ............................................................................. @@ -1127,9 +1099,9 @@ function reloadRouting () { // lookup all routes // ............................................................................. - routes = []; + var routes = []; + var routing = arangodb.db._collection("_routing"); - routing = arangodb.db._collection("_routing"); i = routing.all(); while (i.hasNext()) { @@ -1144,15 +1116,14 @@ function reloadRouting () { // check development routes if (internal.developmentMode) { - i = foxxManager.developmentRoutes(); - routes = routes.concat(i); + routes = routes.concat(foxxManager.developmentRoutes()); } // ............................................................................. // defines a new route // ............................................................................. - handleRoute = function (storage, urlPrefix, modulePrefix, route) { + var installRoute = function (storage, urlPrefix, modulePrefix, context, route) { var url; var callback; @@ -1163,7 +1134,7 @@ function reloadRouting () { return; } - callback = lookupCallback(route); + callback = lookupCallback(route, context); if (callback === null) { console.error("route '%s' has an unknown callback, ignoring", JSON.stringify(route)); @@ -1173,6 +1144,59 @@ function reloadRouting () { defineRoute(route, storage, url, callback); }; + // ............................................................................. + // analyses a new route + // ............................................................................. + + var analyseRoute = function (routes) { + var urlPrefix = routes.urlPrefix || ""; + var modulePrefix = routes.modulePrefix || ""; + var keys = [ 'routes', 'middleware' ]; + var repositories = {}; + var j; + + // create the application context + var appModule = module.root; + var appContext = { + collectionPrefix: "" + }; + + if (routes.hasOwnProperty('appContext')) { + appContext = routes.appContext; + appModule = module.createApp(routes.appContext.appId).createAppModule(); + } + + // create the route contexts + var contexts = createContexts(appModule, appContext, routes.context || {}); + + // install the routes + for (j = 0; j < keys.length; ++j) { + var key = keys[j]; + + if (routes.hasOwnProperty(key)) { + var r = routes[key]; + + for (i = 0; i < r.length; ++i) { + var route = r[i]; + var context = {}; + + if (route.hasOwnProperty('context')) { + var cn = route.context; + + if (contexts.hasOwnProperty(cn)) { + context = contexts[cn]; + } + else { + throw new Error("unknown context '" + cn + "'"); + } + } + + installRoute(RoutingCache[key], urlPrefix, modulePrefix, context, r[i]); + } + } + } + }; + // ............................................................................. // loop over the routes or routes bundle // ............................................................................. @@ -1183,28 +1207,19 @@ function reloadRouting () { var route = routes[j]; var r; - if (route.hasOwnProperty('routes') || route.hasOwnProperty('middleware')) { - var urlPrefix = route.urlPrefix || ""; - var modulePrefix = route.modulePrefix || ""; - - if (route.hasOwnProperty('routes')) { - r = route.routes; - - for (i = 0; i < r.length; ++i) { - handleRoute(RoutingCache.routes, urlPrefix, modulePrefix, r[i]); - } + try { + if (route.hasOwnProperty('routes') || route.hasOwnProperty('middleware')) { + analyseRoute(route); } - - if (route.hasOwnProperty('middleware')) { - r = route.middleware; - - for (i = 0; i < r.length; ++i) { - handleRoute(RoutingCache.middleware, urlPrefix, modulePrefix, r[i]); - } + else { + installRoute(RoutingCache.routes, "", "", {}, route); } } - else { - handleRoute(RoutingCache.routes, "", "", route); + catch (err) { + console.error("cannot install route '%s': %s - %s", + JSON.stringify(route), + String(err), + String(err.stack)); } } diff --git a/js/server/modules/org/arangodb/foxx-manager.js b/js/server/modules/org/arangodb/foxx-manager.js index 3311ba7925..6034b18474 100644 --- a/js/server/modules/org/arangodb/foxx-manager.js +++ b/js/server/modules/org/arangodb/foxx-manager.js @@ -332,11 +332,25 @@ function routingAalApp (app, mount, prefix) { throw "mount point must be absolute"; } + // compute the collection prefix + if (prefix === undefined) { + prefix = mount.substr(1).replace(/\//g, "_"); + } + // setup the routes routes = { urlPrefix: mount, routes: [], - middleware: [] + middleware: [], + context: {}, + + appContext: { + name: app._name, // app name + version: app._version, // app version + appId: app._id, // app identifier + mount: mount, // global mount + collectionPrefix: prefix // collection prefix + } }; routes.routes.push({ @@ -350,11 +364,6 @@ function routingAalApp (app, mount, prefix) { } }); - // compute the collection prefix - if (prefix === undefined) { - prefix = mount.substr(1).replace(/\//g, "_"); - } - // mount all applications apps = app._manifest.apps; @@ -362,51 +371,67 @@ function routingAalApp (app, mount, prefix) { if (apps.hasOwnProperty(i)) { var file = apps[i]; - // set up a context for the applications + + // set up a context for the routing table + routes.context[i] = { + repositories: {}, + requires: {} + }; + + // set up a context for the application start function context = { prefix: arangodb.normalizeURL("/" + i), // app mount - - context: { - name: app._name, // app name - version: app._version, // app version - appId: app._id, // app identifier - mount: mount, // global mount - collectionPrefix: prefix // collection prefix - } + requires: {}, + routingInfo: {} }; app.loadAppScript(app.createAppModule(), file, context); - if (context.routingInfo !== undefined) { - var ri = context.routingInfo; - var p = ri.urlPrefix; - var route; - var j; + // ............................................................................. + // routingInfo + // ............................................................................. - if (ri.hasOwnProperty("routes")) { - for (j = 0; j < ri.routes.length; ++j) { - route = ri.routes[j]; + var ri = context.routingInfo; + var p = ri.urlPrefix; + var route; + var j; + var k; + + var rm = [ "routes", "middleware" ]; + + for (k = 0; k < rm.length; ++k) { + var key = rm[k]; + + if (ri.hasOwnProperty(key)) { + var rt = ri[key]; + + for (j = 0; j < rt.length; ++j) { + route = rt[j]; if (route.hasOwnProperty("url")) { route.url.match = arangodb.normalizeURL(p + "/" + route.url.match); } - routes.routes.push(route); + route.context = i; + + routes[key].push(route); } } - if (ri.hasOwnProperty("middleware")) { - for (j = 0; j < ri.middleware.length; ++j) { - route = ri.middleware[j]; + // ............................................................................. + // repositories + // ............................................................................. - if (route.hasOwnProperty("url")) { - route.url.match = arangodb.normalizeURL(p + "/" + route.url.match); - } - - routes.middleware.push(route); - } + if (ri.hasOwnProperty("repositories")) { + routes.context[i].repositories = ri.repositories; } } + + // ............................................................................. + // requires + // ............................................................................. + + routes.context[i].requires = context.requires; } } diff --git a/js/server/modules/org/arangodb/foxx.js b/js/server/modules/org/arangodb/foxx.js index 6201b2d602..038ecdd461 100644 --- a/js/server/modules/org/arangodb/foxx.js +++ b/js/server/modules/org/arangodb/foxx.js @@ -139,16 +139,11 @@ _.extend(Application.prototype, { start: function (context) { 'use strict'; - var requires = this.requires, - prefix = context.prefix; + var prefix = context.prefix; this.routingInfo.urlPrefix = prefix + "/" + this.routingInfo.urlPrefix; - _.each(this.routingInfo.routes, function (route) { - route.action.context = context.context; - route.action.requiresLibs = requires; - }); - + context.requires = this.requires; context.routingInfo = this.routingInfo; }, From 21589bc6c63dda53ea4082d1984967cfcc7f9b85 Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Thu, 4 Apr 2013 22:56:41 +0200 Subject: [PATCH 3/7] new foxx --- js/client/modules/org/arangodb/aal.js | 15 +- js/server/modules/org/arangodb/actions.js | 162 ++++++++++++++++-- .../modules/org/arangodb/foxx-manager.js | 1 + 3 files changed, 157 insertions(+), 21 deletions(-) diff --git a/js/client/modules/org/arangodb/aal.js b/js/client/modules/org/arangodb/aal.js index 87727db251..d9cfa8154b 100644 --- a/js/client/modules/org/arangodb/aal.js +++ b/js/client/modules/org/arangodb/aal.js @@ -427,7 +427,16 @@ exports.uninstallApp = function (key) { exports.printInstalled = function (showPrefix) { var list = exports.listInstalled(showPrefix); - arangodb.printTable(list); + if (showPrefix) { + arangodb.printTable( + list, + ["MountID", "AppID", "CollectionPrefix", "Active", "Devel"]); + } + else { + arangodb.printTable( + list, + ["MountID", "AppID", "Mount", "Active", "Devel"]); + } }; //////////////////////////////////////////////////////////////////////////////// @@ -475,7 +484,9 @@ exports.listInstalled = function (showPrefix) { exports.printAvailable = function () { var list = exports.listAvailable(); - arangodb.printTable(list); + arangodb.printTable( + list, + ["AppID", "Name", "Version", "Path"]); }; //////////////////////////////////////////////////////////////////////////////// diff --git a/js/server/modules/org/arangodb/actions.js b/js/server/modules/org/arangodb/actions.js index 971e3681ad..7ff45d42db 100644 --- a/js/server/modules/org/arangodb/actions.js +++ b/js/server/modules/org/arangodb/actions.js @@ -78,6 +78,8 @@ var ALL_METHODS = [ "DELETE", "GET", "HEAD", "OPTIONS", "POST", "PUT", "PATCH" ] //////////////////////////////////////////////////////////////////////////////// function notImplementedFunction (route, message) { + 'use strict'; + message += "\nThis error was triggered by the following route " + JSON.stringify(route); console.error("%s", message); @@ -94,6 +96,8 @@ function notImplementedFunction (route, message) { //////////////////////////////////////////////////////////////////////////////// function errorFunction (route, message) { + 'use strict'; + message += "\nThis error was triggered by the following route " + JSON.stringify(route); console.error("%s", message); @@ -110,6 +114,8 @@ function errorFunction (route, message) { //////////////////////////////////////////////////////////////////////////////// function splitUrl (url) { + 'use strict'; + var cleaned; var i; var parts; @@ -160,6 +166,8 @@ function splitUrl (url) { //////////////////////////////////////////////////////////////////////////////// function lookupUrl (prefix, url) { + 'use strict'; + if (url === undefined || url === '') { return null; } @@ -188,6 +196,8 @@ function lookupUrl (prefix, url) { //////////////////////////////////////////////////////////////////////////////// function lookupCallbackStatic (content) { + 'use strict'; + var type; var body; var methods; @@ -223,6 +233,8 @@ function lookupCallbackStatic (content) { //////////////////////////////////////////////////////////////////////////////// function lookupCallbackActionCallback (route, action, context) { + 'use strict'; + var defn; var env; var func; @@ -277,6 +289,8 @@ function lookupCallbackActionCallback (route, action, context) { //////////////////////////////////////////////////////////////////////////////// function lookupCallbackActionDo (route, action) { + 'use strict'; + var func; var joined; var name; @@ -333,6 +347,8 @@ function lookupCallbackActionDo (route, action) { //////////////////////////////////////////////////////////////////////////////// function lookupCallbackActionController (route, action) { + 'use strict'; + var func; var mdl; var httpMethods = { @@ -404,6 +420,8 @@ function lookupCallbackActionController (route, action) { //////////////////////////////////////////////////////////////////////////////// function lookupCallbackActionPrefixController (route, action) { + 'use strict'; + var prefixController = action.prefixController; var httpMethods = { 'get': exports.GET, @@ -494,6 +512,7 @@ function lookupCallbackActionPrefixController (route, action) { //////////////////////////////////////////////////////////////////////////////// function lookupCallbackAction (route, action, context) { + 'use strict'; // ............................................................................. // short-cut for prefix controller @@ -543,6 +562,8 @@ function lookupCallbackAction (route, action, context) { //////////////////////////////////////////////////////////////////////////////// function lookupCallback (route, context) { + 'use strict'; + var result = null; if (route.hasOwnProperty('content')) { @@ -560,6 +581,8 @@ function lookupCallback (route, context) { //////////////////////////////////////////////////////////////////////////////// function createContexts (appModule, appContext, desc) { + 'use strict'; + var key; var c; @@ -576,6 +599,10 @@ function createContexts (appModule, appContext, desc) { requires: {} }; + // ............................................................................. + // requires + // ............................................................................. + if (d.hasOwnProperty('requires')) { for (c in d.requires) { if (d.requires.hasOwnProperty(c)) { @@ -586,6 +613,56 @@ function createContexts (appModule, appContext, desc) { } } } + + // ............................................................................. + // repositories + // ............................................................................. + + if (d.hasOwnProperty('repositories')) { + for (c in d.repositories) { + if (d.repositories.hasOwnProperty(c)) { + var rep = d.repositories[c]; + var model; + var Repo; + + if (rep.hasOwnProperty('model')) { + model = appModule.require(rep.model).Model; + + if (model === undefined) { + throw new Error("module '" + rep.model + "' does not define a model"); + } + } + else { + model = foxx.Model; + } + + if (rep.hasOwnProperty('repository')) { + Repo = appModule.require(rep.repository).Repository; + + if (Repo === undefined) { + throw new Error("module '" + rep.repository + "' does not define a repository"); + } + } + else { + Repo = foxx.Repository; + } + + var prefix = appContext.collectionPrefix; + var cname; + + if (prefix === "") { + cname = c; + } + else { + cname = prefix + "_" + c; + } + + var collection = arangodb.db._collection(cname); + + result[key].repositories[c] = new Repo(prefix, collection, model); + } + } + } } } @@ -597,6 +674,8 @@ function createContexts (appModule, appContext, desc) { //////////////////////////////////////////////////////////////////////////////// function intersectMethods (a, b) { + 'use strict'; + var d = {}; var i; var j; @@ -625,6 +704,8 @@ function intersectMethods (a, b) { //////////////////////////////////////////////////////////////////////////////// function defineRoutePart (route, subwhere, parts, pos, constraint, callback) { + 'use strict'; + var i; var p; var part; @@ -714,6 +795,8 @@ function defineRoutePart (route, subwhere, parts, pos, constraint, callback) { //////////////////////////////////////////////////////////////////////////////// function defineRoute (route, where, url, callback) { + 'use strict'; + var methods; var branch; var i; @@ -733,6 +816,8 @@ function defineRoute (route, where, url, callback) { //////////////////////////////////////////////////////////////////////////////// function flattenRouting (routes, path, urlParameters, depth, prefix) { + 'use strict'; + var cur; var i; var k; @@ -903,6 +988,8 @@ function flattenRouting (routes, path, urlParameters, depth, prefix) { //////////////////////////////////////////////////////////////////////////////// function defineHttp (options) { + 'use strict'; + var url = options.url; var contexts = options.context; var callback = options.callback; @@ -968,6 +1055,8 @@ function defineHttp (options) { //////////////////////////////////////////////////////////////////////////////// function getErrorMessage (code) { + 'use strict'; + var key; for (key in internal.errors) { @@ -986,6 +1075,8 @@ function getErrorMessage (code) { //////////////////////////////////////////////////////////////////////////////// function getJsonBody (req, res, code) { + 'use strict'; + var body; var err; @@ -1028,6 +1119,8 @@ function getJsonBody (req, res, code) { //////////////////////////////////////////////////////////////////////////////// function resultError (req, res, httpReturnCode, errorNum, errorMessage, headers, keyvals) { + 'use strict'; + var i; var msg; @@ -1075,6 +1168,8 @@ function resultError (req, res, httpReturnCode, errorNum, errorMessage, headers, //////////////////////////////////////////////////////////////////////////////// function reloadRouting () { + 'use strict'; + var i; var j; var method; @@ -1217,7 +1312,7 @@ function reloadRouting () { } catch (err) { console.error("cannot install route '%s': %s - %s", - JSON.stringify(route), + route.toString(), String(err), String(err.stack)); } @@ -1247,6 +1342,8 @@ function reloadRouting () { //////////////////////////////////////////////////////////////////////////////// function nextRouting (state) { + 'use strict'; + var i; var k; @@ -1294,6 +1391,8 @@ function nextRouting (state) { //////////////////////////////////////////////////////////////////////////////// function firstRouting (type, parts) { + 'use strict'; + var url = parts; if (typeof url === 'string') { @@ -1325,22 +1424,6 @@ function firstRouting (type, parts) { }); } -//////////////////////////////////////////////////////////////////////////////// -/// @brief checks if development mode is allowed in general -//////////////////////////////////////////////////////////////////////////////// - -function developmentModeAllowed () { - return true; -} - -//////////////////////////////////////////////////////////////////////////////// -/// @brief checks if development mode is activated for an application -//////////////////////////////////////////////////////////////////////////////// - -function developmentModeActivated (application) { - return true; -} - //////////////////////////////////////////////////////////////////////////////// /// @} //////////////////////////////////////////////////////////////////////////////// @@ -1359,6 +1442,8 @@ function developmentModeActivated (application) { //////////////////////////////////////////////////////////////////////////////// function badParameter (req, res, name) { + 'use strict'; + resultError(req, res, exports.HTTP_BAD, exports.HTTP_BAD, "invalid value for parameter '" + name + "'"); } @@ -1376,6 +1461,8 @@ function badParameter (req, res, name) { //////////////////////////////////////////////////////////////////////////////// function resultOk (req, res, httpReturnCode, result, headers) { + 'use strict'; + res.responseCode = httpReturnCode; res.contentType = "application/json; charset=utf-8"; @@ -1403,6 +1490,8 @@ function resultOk (req, res, httpReturnCode, result, headers) { //////////////////////////////////////////////////////////////////////////////// function resultBad (req, res, code, msg, headers) { + 'use strict'; + resultError(req, res, exports.HTTP_BAD, code, msg, headers); } @@ -1415,6 +1504,8 @@ function resultBad (req, res, code, msg, headers) { //////////////////////////////////////////////////////////////////////////////// function resultNotFound (req, res, code, msg, headers) { + 'use strict'; + resultError(req, res, exports.HTTP_NOT_FOUND, code, msg, headers); } @@ -1427,6 +1518,8 @@ function resultNotFound (req, res, code, msg, headers) { //////////////////////////////////////////////////////////////////////////////// function resultNotImplemented (req, res, msg, headers) { + 'use strict'; + resultError(req, res, exports.HTTP_NOT_IMPLEMENTED, @@ -1444,6 +1537,8 @@ function resultNotImplemented (req, res, msg, headers) { //////////////////////////////////////////////////////////////////////////////// function resultUnsupported (req, res, headers) { + 'use strict'; + resultError(req, res, exports.HTTP_METHOD_NOT_ALLOWED, arangodb.ERROR_HTTP_METHOD_NOT_ALLOWED, @@ -1460,6 +1555,8 @@ function resultUnsupported (req, res, headers) { //////////////////////////////////////////////////////////////////////////////// function resultPermanentRedirect (req, res, destination, headers) { + 'use strict'; + res.responseCode = exports.HTTP_MOVED_PERMANENTLY; res.contentType = "text/html"; @@ -1489,6 +1586,8 @@ function resultPermanentRedirect (req, res, destination, headers) { //////////////////////////////////////////////////////////////////////////////// function resultTemporaryRedirect (req, res, destination, headers) { + 'use strict'; + res.responseCode = exports.HTTP_TEMPORARY_REDIRECT; res.contentType = "text/html"; @@ -1527,6 +1626,8 @@ function resultTemporaryRedirect (req, res, destination, headers) { //////////////////////////////////////////////////////////////////////////////// function resultCursor (req, res, cursor, code, options) { + 'use strict'; + var rows; var count; var hasCount; @@ -1590,6 +1691,8 @@ function resultCursor (req, res, cursor, code, options) { //////////////////////////////////////////////////////////////////////////////// function collectionNotFound (req, res, collection, headers) { + 'use strict'; + if (collection === undefined) { resultError(req, res, exports.HTTP_BAD, arangodb.ERROR_HTTP_BAD_PARAMETER, @@ -1612,6 +1715,8 @@ function collectionNotFound (req, res, collection, headers) { //////////////////////////////////////////////////////////////////////////////// function indexNotFound (req, res, collection, index, headers) { + 'use strict'; + if (collection === undefined) { resultError(req, res, exports.HTTP_BAD, arangodb.ERROR_HTTP_BAD_PARAMETER, @@ -1640,6 +1745,8 @@ function indexNotFound (req, res, collection, index, headers) { //////////////////////////////////////////////////////////////////////////////// function resultException (req, res, err, headers) { + 'use strict'; + var code; var msg; var num; @@ -1707,6 +1814,8 @@ function resultException (req, res, err, headers) { //////////////////////////////////////////////////////////////////////////////// function echoRequest (req, res, options, next) { + 'use strict'; + var result; result = { request : req, options : options }; @@ -1721,6 +1830,8 @@ function echoRequest (req, res, options, next) { //////////////////////////////////////////////////////////////////////////////// function logRequest (req, res, options, next) { + 'use strict'; + var log; var level; var token; @@ -1768,6 +1879,8 @@ function logRequest (req, res, options, next) { //////////////////////////////////////////////////////////////////////////////// function redirectRequest (req, res, options, next) { + 'use strict'; + if (options.permanently) { resultPermanentRedirect(req, res, options.destination); } @@ -1781,11 +1894,24 @@ function redirectRequest (req, res, options, next) { //////////////////////////////////////////////////////////////////////////////// function pathHandler (req, res, options, next) { + 'use strict'; + var filename; var result; filename = fs.join(options.path, fs.join.apply(fs.join, req.suffix)); + if (options.hasOwnProperty('root')) { + var root = options.root; + + if (root.substr(0, 4) === "app:") { + filename = fs.join(module.appPath(), filename); + } + else if (root.substr(0, 4) === "dev:") { + filename = fs.join(module.devAppPath(), filename); + } + } + if (fs.exists(filename)) { res.responseCode = exports.HTTP_OK; res.contentType = arangodb.guessContentType(filename); @@ -1820,8 +1946,6 @@ exports.reloadRouting = reloadRouting; exports.firstRouting = firstRouting; exports.nextRouting = nextRouting; exports.routingCache = function() { return RoutingCache; }; -exports.developmentModeAllowed = developmentModeAllowed; -exports.developmentModeActivated = developmentModeActivated; // standard HTTP responses exports.badParameter = badParameter; diff --git a/js/server/modules/org/arangodb/foxx-manager.js b/js/server/modules/org/arangodb/foxx-manager.js index 6034b18474..890283477c 100644 --- a/js/server/modules/org/arangodb/foxx-manager.js +++ b/js/server/modules/org/arangodb/foxx-manager.js @@ -161,6 +161,7 @@ function installAssets (app, routes) { action: { "do": "org/arangodb/actions/pathHandler", "options": { + root: app._id, path: fs.join(app._path, directory) } } From 94e1cd18232b96150978642d48d425b33d055f03 Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Thu, 4 Apr 2013 22:58:43 +0200 Subject: [PATCH 4/7] uppercase --- js/apps/aardvark/repositories/foxxes.js | 2 +- js/apps/aardvark/repositories/swagger.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/js/apps/aardvark/repositories/foxxes.js b/js/apps/aardvark/repositories/foxxes.js index 57d7bd4dc7..d46067fb69 100644 --- a/js/apps/aardvark/repositories/foxxes.js +++ b/js/apps/aardvark/repositories/foxxes.js @@ -34,7 +34,7 @@ // Define the Repository var Foxx = require("org/arangodb/foxx"); - exports.repository = Foxx.Repository.extend({ + exports.Repository = Foxx.Repository.extend({ // Define the functionality to create a new foxx store = function (content) { throw { diff --git a/js/apps/aardvark/repositories/swagger.js b/js/apps/aardvark/repositories/swagger.js index 2928ca570f..149032f5c0 100644 --- a/js/apps/aardvark/repositories/swagger.js +++ b/js/apps/aardvark/repositories/swagger.js @@ -38,7 +38,7 @@ // Define the functionality to receive the documentation. // And transform it into swagger format. - exports.repository = Foxx.Repository.extend({ + exports.Repository = Foxx.Repository.extend({ // Get the overview of all installed foxxes. list: function() { @@ -88,4 +88,4 @@ return result; } }); -}()); \ No newline at end of file +}()); From 0ea748488b819f2d0f78b4b56f4c2527990b56b6 Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Thu, 4 Apr 2013 23:19:03 +0200 Subject: [PATCH 5/7] fixed url --- html/admin/js/collections/foxxCollection.js | 2 +- html/admin/js/models/foxx.js | 2 +- html/admin/js/views/appDocumentationView.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/html/admin/js/collections/foxxCollection.js b/html/admin/js/collections/foxxCollection.js index 8de0db4b6d..659eb8524d 100644 --- a/html/admin/js/collections/foxxCollection.js +++ b/html/admin/js/collections/foxxCollection.js @@ -1,5 +1,5 @@ window.FoxxCollection = Backbone.Collection.extend({ model: window.Foxx, - url: "../../aardvark/foxxes" + url: "../aardvark/foxxes" }); diff --git a/html/admin/js/models/foxx.js b/html/admin/js/models/foxx.js index 72f9ffe815..4380a3b0bd 100644 --- a/html/admin/js/models/foxx.js +++ b/html/admin/js/models/foxx.js @@ -8,7 +8,7 @@ window.Foxx = Backbone.Model.extend({ }, url: function() { - return "../../aardvark/foxxes/" + this.get("_key"); + return "../aardvark/foxxes/" + this.get("_key"); }, isNew: function() { diff --git a/html/admin/js/views/appDocumentationView.js b/html/admin/js/views/appDocumentationView.js index fb683cd9d7..89420f7ce5 100644 --- a/html/admin/js/views/appDocumentationView.js +++ b/html/admin/js/views/appDocumentationView.js @@ -5,7 +5,7 @@ window.AppDocumentationView = Backbone.View.extend({ initialize: function() { this.swaggerUi = new SwaggerUi({ - discoveryUrl:"../../aardvark/swagger", + discoveryUrl:"../aardvark/swagger", apiKey: false, dom_id:"swagger-ui-container", supportHeaderParams: true, From fd8db96123e061395d2d5ad98be46cfc30a7ff45 Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Thu, 4 Apr 2013 23:19:16 +0200 Subject: [PATCH 6/7] fixed syntax errors --- js/apps/aardvark/repositories/foxxes.js | 4 ++-- js/apps/aardvark/repositories/swagger.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/js/apps/aardvark/repositories/foxxes.js b/js/apps/aardvark/repositories/foxxes.js index d46067fb69..8980fe80ff 100644 --- a/js/apps/aardvark/repositories/foxxes.js +++ b/js/apps/aardvark/repositories/foxxes.js @@ -36,7 +36,7 @@ exports.Repository = Foxx.Repository.extend({ // Define the functionality to create a new foxx - store = function (content) { + store: function (content) { throw { code: 501, message: "To be implemented." @@ -75,6 +75,6 @@ code: 501, message: "To be implemented." }; - }; + } }); }()); diff --git a/js/apps/aardvark/repositories/swagger.js b/js/apps/aardvark/repositories/swagger.js index 149032f5c0..8534bbec2d 100644 --- a/js/apps/aardvark/repositories/swagger.js +++ b/js/apps/aardvark/repositories/swagger.js @@ -56,7 +56,7 @@ }, // Get details of one specific installed foxx. - show = function(appname) { + show: function(appname) { var result = {}, apis = [], key, From dcb65a92bf6e10bb912262a64c577617fa64f0f0 Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Thu, 4 Apr 2013 23:19:27 +0200 Subject: [PATCH 7/7] fixed error messages --- js/common/bootstrap/modules.js | 1 - js/server/modules/org/arangodb/actions.js | 37 ++++++++++++++--------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/js/common/bootstrap/modules.js b/js/common/bootstrap/modules.js index d4f2b0d79c..d18b38f67c 100644 --- a/js/common/bootstrap/modules.js +++ b/js/common/bootstrap/modules.js @@ -418,7 +418,6 @@ function require (path) { } if (mp === null) { - console.error("unknown application '%s'", appId); return null; } diff --git a/js/server/modules/org/arangodb/actions.js b/js/server/modules/org/arangodb/actions.js index 7ff45d42db..e6ab6b6a73 100644 --- a/js/server/modules/org/arangodb/actions.js +++ b/js/server/modules/org/arangodb/actions.js @@ -274,7 +274,7 @@ function lookupCallbackActionCallback (route, action, context) { func = errorFunction( route, "an error occurred while loading function '" - + action.callback + "': " + String(err)); + + action.callback + "': " + String(err.stack || err)); } return { @@ -318,13 +318,13 @@ function lookupCallbackActionDo (route, action) { func = notImplementedFunction( route, "an error occurred while loading action named '" + name - + "' in module '" + joined + "': " + String(err)); + + "' in module '" + joined + "': " + String(err.stack || err)); } else { func = errorFunction( route, "an error occurred while loading action named '" + name - + "' in module '" + joined + "': " + String(err)); + + "' in module '" + joined + "': " + String(err.stack || err)); } } @@ -405,13 +405,13 @@ function lookupCallbackActionController (route, action) { return notImplementedFunction( route, "cannot load/execute action controller module '" - + action.controller + ": " + String(err)); + + action.controller + ": " + String(err.stack || err)); } return errorFunction( route, "cannot load/execute action controller module '" - + action.controller + ": " + String(err)); + + action.controller + ": " + String(err.stack || err)); } } @@ -460,7 +460,7 @@ function lookupCallbackActionPrefixController (route, action) { } return efunc(route, - "cannot load prefix controller: " + String(err1))( + "cannot load prefix controller: " + String(err1.stack || err1))( req, res, options, next); } @@ -496,7 +496,7 @@ function lookupCallbackActionPrefixController (route, action) { return errorFunction( route, "Cannot load/execute prefix controller '" - + action.prefixController + "': " + String(err2))( + + action.prefixController + "': " + String(err2.stack || err2))( req, res, options, next); } @@ -1258,7 +1258,15 @@ function reloadRouting () { if (routes.hasOwnProperty('appContext')) { appContext = routes.appContext; - appModule = module.createApp(routes.appContext.appId).createAppModule(); + + var appId = appContext.appId; + var app = module.createApp(appId); + + if (app === null) { + throw new Error("unknown application '" + appId + "'"); + } + + appModule = app.createAppModule(); } // create the route contexts @@ -1311,10 +1319,9 @@ function reloadRouting () { } } catch (err) { - console.error("cannot install route '%s': %s - %s", + console.error("cannot install route '%s': %s", route.toString(), - String(err), - String(err.stack)); + String(err.stack || err)); } } @@ -1761,10 +1768,10 @@ function resultException (req, res, err, headers) { } if (msg === "") { - msg = String(err) + ": " + String(err.stack); + msg = String(err.stack || err); } else { - msg += ": " + String(err.stack); + msg += ": " + String(err.stack || err); } switch (num) { @@ -1783,7 +1790,7 @@ function resultException (req, res, err, headers) { else if (err instanceof TypeError) { num = arangodb.ERROR_TYPE_ERROR; code = exports.HTTP_BAD; - msg = String(err.message) + ": " + String(err.stack); + msg = String(err.stack || err); resultError(req, res, code, num, msg, headers); } @@ -1791,7 +1798,7 @@ function resultException (req, res, err, headers) { else { resultError(req, res, exports.HTTP_SERVER_ERROR, arangodb.ERROR_HTTP_SERVER_ERROR, - String(err) + " " + String(err.stack), + String(err.stack || err), headers); } }