rabbah commented on issue #3152: Enrich entity views, and add count reducer
URL: 
https://github.com/apache/incubator-openwhisk/pull/3152#issuecomment-356009974
 
 
   Here are the views for reviewing convenience:
   
   * actions:
   ```js
   function (doc) {
     var PATHSEP = "/";
     var isAction = function (doc) { return (doc.exec !== undefined) };
     if (isAction(doc)) try {
       var ns = doc.namespace.split(PATHSEP);
       var root = ns[0];
       var value = {
         namespace: doc.namespace,
         name: doc.name,
         version: doc.version,
         publish: doc.publish,
         annotations: doc.annotations,
         limits: doc.limits,
         exec: { binary: doc.exec.binary || false},
         updated: doc.updated
       };
       emit([doc.namespace, doc.updated], value);
       if (root !== doc.namespace) {
         emit([root, doc.updated], value);
       }
     } catch (e) {}
   }
   ```
   
   * packages
   ```js
   function (doc) {
     var isPackage = function (doc) {  return (doc.binding !== undefined) };
     if (isPackage(doc)) try {
       var value = {
         namespace: doc.namespace,
         name: doc.name,
         version: doc.version,
         publish: doc.publish,
         annotations: doc.annotations,
         updated: doc.updated
       };
       if (Object.keys(doc.binding).length > 0) {
         value.binding = doc.binding;
       } else {
         value.binding = false;
       }
       emit([doc.namespace, doc.updated], value);
     } catch (e) {}
   }
   ```
   
   * packages-public
   ```js
   function (doc) {
     var isPublicPackage = function(doc) { 
       return Object.keys(doc.binding).length == 0 && doc.publish;
     }
     if (isPublicPackage(doc)) try {
       var value = {
         namespace: doc.namespace,
         name: doc.name,
         version: doc.version,
         publish: doc.publish,
         annotations: doc.annotations,
         updated: doc.updated,
         binding: false
       };
       emit([doc.namespace, doc.updated], value);
     } catch (e) {}
   }
   ```
   
   * rules
   ```js
   function (doc) {
     var PATHSEP = "/";
     var isRule = function (doc) {  return (doc.trigger !== undefined) };
     if (isRule(doc)) try {
       var ns = doc.namespace.split(PATHSEP);
       var root = ns[0];
       emit([doc.namespace, doc.updated], 1);
       if (root !== doc.namespace) {
         emit([root, doc.updated], 1);
       }
     } catch (e) {}
   }
   ```
   
   * triggers
   ```js
   function (doc) {
     var PATHSEP = "/";
     var isTrigger = function (doc) { return (doc.exec === undefined && 
doc.binding === undefined && doc.parameters !== undefined) };
     if (isTrigger(doc)) try {
       var ns = doc.namespace.split(PATHSEP);
       var root = ns[0];
       var value = {
         namespace: doc.namespace,
         name: doc.name,
         version: doc.version,
         publish: doc.publish,
         annotations: doc.annotations,
         updated: doc.updated
       };
       emit([doc.namespace, doc.updated], value);
       if (root !== doc.namespace) {
         emit([root, doc.updated], value);
       }
     } catch (e) {}
   }
   ```
   
   * all 
   ```js
   function (doc) {
     var PATHSEP = "/";
   
     var isPackage = function (doc) {  return (doc.binding !== undefined) };
     var isAction = function (doc) { return (doc.exec !== undefined) };
     var isTrigger = function (doc) { return (doc.exec === undefined && 
doc.binding === undefined && doc.parameters !== undefined) };
     var isRule = function (doc) {  return (doc.trigger !== undefined) };
     
     var collection = function (doc) {
       if (isPackage(doc)) return "packages";
       if (isAction(doc)) return "actions";
       if (isTrigger(doc)) return "triggers";
       if (isRule(doc)) return "rules";
       return undefined;
     };
   
     try {
       var type = collection(doc);
       if (type !== undefined) {
         var ns = doc.namespace.split(PATHSEP);
         var root = ns[0];
         var value = {
           collection: type,
           namespace: doc.namespace,
           name: doc.name,
           version: doc.version,
           publish: doc.publish,
           annotations: doc.annotations,
           updated: doc.updated
         };
         if (isAction(doc)) {
           value.limits = doc.limits;
           value.exec = { binary: doc.exec.binary || false};
         } else if (isPackage(doc)) {
           if (Object.keys(doc.binding).length > 0) {
             value.binding = doc.binding;
           } else {
             value.binding = false;
           }
         }
         emit([root, doc.updated], value);
       }
     } catch (e) {}
   }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to