Skip to content

Commit

Permalink
Updating Base methods, removing passport middleware, WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
avoidwork committed Dec 27, 2020
1 parent b8c90ce commit fba307c
Show file tree
Hide file tree
Showing 6 changed files with 2,766 additions and 2,215 deletions.
110 changes: 15 additions & 95 deletions lib/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,144 +7,64 @@ class Base {
};
}

acl (...args) {
this.router.use(...args, "ACL");
}

bind (...args) {
this.router.use(...args, "BIND");
}

checkout (...args) {
this.router.use(...args, "CHECKOUT");
}

connect (...args) {
this.router.use(...args, "CONNECT");
}

copy (...args) {
this.router.use(...args, "COPY");
return this;
}

del (...args) {
this.router.use(...args, "DELETE");

return this;
}

delete (...args) {
this.router.use(...args, "DELETE");

return this;
}

get (...args) {
this.router.use(...args, "GET");

return this;
}

head (...args) {
this.router.use(...args, "HEAD");
}

link (...args) {
this.router.use(...args, "LINK");
}

lock (...args) {
this.router.use(...args, "LOCK");
}

"m-search" (...args) {
this.router.use(...args, "M-SEARCH");
}

merge (...args) {
this.router.use(...args, "MERGE");
}

mkactivity (...args) {
this.router.use(...args, "MKACTIVITY");
}

mkcalendar (...args) {
this.router.use(...args, "MKCALENDAR");
}

mkcol (...args) {
this.router.use(...args, "MKCOL");
}

move (...args) {
this.router.use(...args, "MOVE");
}

notify (...args) {
this.router.use(...args, "NOTIFY");
return this;
}

options (...args) {
this.router.use(...args, "OPTIONS");

return this;
}

patch (...args) {
this.router.use(...args, "PATCH");

return this;
}

post (...args) {
this.router.use(...args, "POST");
}

propfind (...args) {
this.router.use(...args, "PROPFIND");
}

proppatch (...args) {
this.router.use(...args, "PROPPATCH");
}

purge (...args) {
this.router.use(...args, "PURGE");
return this;
}

put (...args) {
this.router.use(...args, "PUT");
}

rebind (...args) {
this.router.use(...args, "REBIND");
}

report (...args) {
this.router.use(...args, "REPORT");
}

search (...args) {
this.router.use(...args, "SEARCH");
}

source (...args) {
this.router.use(...args, "SOURCE");
}

subscribe (...args) {
this.router.use(...args, "SUBSCRIBE");
return this;
}

trace (...args) {
this.router.use(...args, "TRACE");
}

unbind (...args) {
this.router.use(...args, "UNBIND");
}

unlink (...args) {
this.router.use(...args, "UNLINK");
}

unlock (...args) {
this.router.use(...args, "UNLOCK");
}

unsubscribe (...args) {
this.router.use(...args, "UNSUBSCRIBE");
return this;
}
}

Expand Down
41 changes: 19 additions & 22 deletions lib/serializers.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
"use strict";

const {STATUS_CODES} = require("http"),
serializers = new Map();

function custom (arg, err, status = 200, stack = false) {
return {
data: arg,
error: err !== null ? (stack ? err.stack : err.message) || err || STATUS_CODES[status] : null,
links: [],
status: status
};
}

function reduce (arg, err, status = 200, stack = false) {
return err !== null ? (stack ? err.stack : err.message) || err || STATUS_CODES[status] : arg;
}

serializers.set("application/javascript", custom);
serializers.set("application/json", custom);
serializers.set("application/yaml", custom);
serializers.set("application/xml", custom);
serializers.set("text/csv", custom);
serializers.set("text/html", custom);
serializers.set("text/plain", reduce);
serializers = new Map([
[
"text/plain",
function reduce (arg, err, status = 200, stack = false) {
return err !== null ? (stack ? err.stack : err.message) || err || STATUS_CODES[status] : arg;
}
],
[
"*/*",
function custom (arg, err, status = 200, stack = false) {
return {
data: arg,
error: err !== null ? (stack ? err.stack : err.message) || err || STATUS_CODES[status] : null,
links: [],
status: status
};
}
]
]);

module.exports = serializers;
2 changes: 1 addition & 1 deletion lib/tenso.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ class Tenso extends Base {
}

"static" (...args) {
middleware.static(...args);
this.router.static(...args);

return this;
}
Expand Down
7 changes: 1 addition & 6 deletions lib/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ function sort (arg, req) {

function serialize (req, res, arg) {
const status = res.statusCode;
let format = req.server.config.mimeType,
let format = "*/*",
accepts = explode(req.parsed.searchParams.get("format") || req.headers.accept || res.getHeader("content-type") || format, ","),
errz = arg instanceof Error,
result, serializer;
Expand All @@ -682,18 +682,13 @@ function serialize (req, res, arg) {
return result;
}

function ms (arg) {
return `${Number(arg / 1e6).toFixed(2)} ms`;
}

module.exports = {
auth,
bootstrap,
capitalize,
clone,
explode,
hypermedia,
ms,
serialize,
sort
};
Loading

0 comments on commit fba307c

Please sign in to comment.