Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add json-bigint to parse big activitypub_id #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ node_modules/

.idea/

lib/

98 changes: 98 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

/* eslint-disable no-param-reassign */

var Helpers = function () {
function Helpers() {
_classCallCheck(this, Helpers);
}

_createClass(Helpers, null, [{
key: "moveParamsIntoPath",


/**
* For each `/:param` fragment in path, move the value in params
* at that key to path. If the key is not found in params, throw.
* Modifies both params and path values.
*
* @param {Object} params
* @param {String} path
* @return {XML|string|void|*}
*/
value: function moveParamsIntoPath(params, path) {
var rgxParam = /\/:(\w+)/g;

path = path.replace(rgxParam, function (hit) {
var paramName = hit.slice(2);
var suppliedVal = params[paramName];

if (!suppliedVal) {
throw new Error("Mastodon: Params object is missing a required parameter for this request: " + paramName);
}

delete params[paramName];
return "/" + suppliedVal;
});
return path;
}

/**
* When Mastodon returns a response that looks like an error response,
* use this function to attach the error info in the response body to `err`.
*
* @param {Error} err
* @param {Object} body
*/

}, {
key: "attachBodyInfoToError",
value: function attachBodyInfoToError(err, body) {
err.mastodonReply = body;

if (!body) return err;

if (body.error) {
// the body itself is an error object
err.message = body.error;
err.allErrors = err.allErrors.concat([body]);
} else if (body.errors && body.errors.length) {
// body contains multiple error objects
err.message = body.errors[0].message;
err.code = body.errors[0].code;
err.allErrors = err.allErrors.concat(body.errors);
}
return err;
}

/**
* Mastodon error object
*
* @param {String} message
* @return {Error}
*/

}, {
key: "makeMastodonError",
value: function makeMastodonError(message) {
var err = Error();
if (message) err.message = message;
err.code = null;
err.allErrors = [];
err.mastodonReply = null;
return err;
}
}]);

return Helpers;
}();

exports.default = Helpers;
Loading