Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F970791
D362.id1291.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
141 KB
Referenced Files
None
Subscribers
None
D362.id1291.diff
View Options
diff --git a/.eslintrc b/.eslintrc
new file mode 100644
--- /dev/null
+++ b/.eslintrc
@@ -0,0 +1,273 @@
+{
+ "extends": ["prettier"],
+ "parserOptions": {
+ "sourceType": "module",
+ "ecmaFeatures": {
+ "jsx": true
+ },
+ "ecmaVersion": 2018
+ },
+ "plugins": ["react"],
+ "env": {
+ "browser": true,
+ "es6": true,
+ "node": true,
+ "jest": true
+ },
+ "rules": {
+ "for-direction": 0,
+ //: "getter-return": 2,
+ //: "no-async-promise-executor": 1,
+ //: "no-await-in-loop": 1,
+ // "no-compare-neg-zero": 2,
+ // "no-cond-assign": 2,
+ // "no-console": ["error", { "allow": ["warn", "error"] }],
+ // "no-constant-condition": 2,
+ // "no-control-regex": 2,
+ // "no-debugger": 2,
+ // "no-dupe-args": 2,
+ // "no-dupe-keys": 2,
+ // "no-duplicate-case": 2,
+ // "no-empty": 2,
+ // "no-empty-character-class": 2,
+ // "no-ex-assign": 2,
+ "no-extra-boolean-cast": 2,
+ "no-extra-parens": 0,
+ "no-extra-semi": 0,
+ // "no-func-assign": 2,
+ // "no-inner-declarations": 2,
+ // "no-invalid-regexp": 2,
+ "no-irregular-whitespace": 0,
+ // "no-misleading-character-class": 2,
+ // "no-obj-calls": 2,
+ // "no-prototype-builtins": 2,
+ "no-regex-spaces": 0,
+ // "no-sparse-arrays": 2,
+ // "no-template-curly-in-string": 1,
+ // "no-unexpected-multiline": 1,
+ // "no-unreachable": 2,
+ // "no-unsafe-finally": 1,
+ "no-unsafe-negation": 2,
+ // "require-atomic-updates": 2,
+ // "use-isnan": 2,
+ "valid-jsdoc": 0,
+ // "valid-typeof": 2,
+ "accessor-pairs": 0,
+ // FIX: "array-callback-return": 2,
+ // "block-scoped-var": 1,
+ // FIX: "class-methods-use-this": 2,
+ // "complexity": 1,
+ // "consistent-return": 2,
+ "curly": 0,
+ // "default-case": 2,
+ "dot-location": 0,
+ "dot-notation": 2,
+ "eqeqeq": 2,
+ "guard-for-in": 0,
+ "max-classes-per-file": 0,
+ "no-alert": 0,
+ "no-caller": 0,
+ // "no-case-declarations": 1,
+ "no-div-regex": 0,
+ "no-else-return": 2,
+ "no-empty-function": 0,
+ // "no-empty-pattern": 2,
+ // "no-eq-null": 2,
+ // "no-eval": 2,
+ // "no-extend-native": 2,
+ // "no-extra-bind": 0
+ "no-extra-label": 2,
+ // "no-fallthrough": 2,
+ "no-floating-decimal": 2,
+ // "no-global-assign": 2,
+ "no-implicit-coercion": 2,
+ "no-implicit-globals": 0,
+ "no-implied-eval": 0,
+ "no-invalid-this": 0,
+ // "no-iterator": 2,
+ // "no-labels": 2,
+ // "no-lone-blocks": 2,
+ // "no-loop-func": 2,
+ "no-magic-numbers": 0,
+ "no-multi-spaces": 0,
+ // "no-multi-str": 2,
+ "no-new": 0,
+ // "no-new-func": 2,
+ // "no-new-wrappers": 2,
+ // "no-octal": 2,
+ // "no-octal-escape": 2,
+ // "no-param-reassign": 2,
+ // "no-proto": 2,
+ // "no-redeclare": 2,
+ "no-restricted-properties": 0,
+ // "no-return-assign": 2,
+ // "no-return-await": 2,
+ "no-script-url": 0,
+ // "no-self-assign": 2,
+ // "no-self-compare": 2,
+ // "no-sequences": 2,
+ // refactor with assert_async_throws "no-throw-literal": 2,
+ "no-unmodified-loop-condition": 0,
+ // "no-unused-expressions": 2,
+ // "no-unused-labels": 2,
+ "no-useless-call": 0,
+ // "no-useless-concat": 2,
+ // "no-useless-escape": 2,
+ "no-useless-return": 2,
+ // "no-void": 2,
+ "no-warning-comments": 0,
+ // "no-with": 2,
+ // "prefer-promise-reject-errors": 2,
+ // "radix": 2,
+ "require-await": 0,
+ "require-unicode-regexp": 0,
+ "vars-on-top": 0,
+ "wrap-iife": 0,
+ "yoda": 2,
+ "strict": 2,
+ "init-declarations": 0,
+ // "no-delete-var": 2,
+ // "no-label-var": 2,
+ "no-restricted-globals": 0,
+ // "no-shadow": 2,
+ // "no-shadow-restricted-names": 2,
+ // "no-undef": 1,
+ "no-undef-init": 0,
+ // "no-undefined": 2,
+ // "no-unused-vars": ["error", { "args": "none" }],
+ // "no-use-before-define": ["error", { "variables": true }],
+ "callback-return": 0,
+ // "global-require": 2,
+ // "handle-callback-err": 1,
+ "no-buffer-constructor": 0,
+ // "no-mixed-requires": 2,
+ "no-new-require": 0,
+ // "no-path-concat": 1,
+ "no-process-env": 0,
+ "no-process-exit": 0,
+ "no-restricted-modules": 0,
+ // "no-sync": 2,
+ "array-bracket-newline": 0,
+ "array-bracket-spacing": 0,
+ "array-element-newline": 0,
+ "block-spacing": 0,
+ "brace-style": 0,
+ "camelcase": 0,
+ "capitalized-comments": 0,
+ "comma-dangle": 0,
+ "comma-spacing": 0,
+ "comma-style": 0,
+ "computed-property-spacing": 0,
+ "consistent-this": 0,
+ "eol-last": ["error", "always"],
+ "func-call-spacing": 0,
+ "func-name-matching": 0,
+ "func-names": 0,
+ "func-style": 0,
+ "function-paren-newline": 0,
+ "id-blacklist": 0,
+ "id-length": 0,
+ "id-match": 0,
+ "implicit-arrow-linebreak": 0,
+ "indent": 0,
+ "jsx-quotes": 0,
+ "key-spacing": 0,
+ "keyword-spacing": 0,
+ "line-comment-position": 0,
+ "linebreak-style": 0,
+ "lines-around-comment": 0,
+ // FIX "lines-between-class-members": "error",
+ "max-depth": 0,
+ "max-len": 0,
+ // "max-lines": ["error", { "max": 400 }],
+ // "max-lines-per-function": ["error", 60],
+ "max-nested-callbacks": 0,
+ // "max-params": ["error", 3],
+ "max-statements": 0,
+ "max-statements-per-line": 0,
+ "multiline-comment-style": 0,
+ "multiline-ternary": 0,
+ // "new-cap": 2,
+ "new-parens": 2,
+ "newline-per-chained-call": 0,
+ // "no-array-constructor": 2,
+ // "no-bitwise": 2,
+ "no-continue": 0,
+ "no-inline-comments": 0,
+ "no-lonely-if": 2,
+ "no-mixed-operators": 0,
+ "no-mixed-spaces-and-tabs": 0,
+ "no-multi-assign": 0,
+ "no-multiple-empty-lines": 0,
+ // "no-negated-condition": 2,
+ "no-nested-ternary": 2,
+ "no-new-object": 0,
+ "no-plusplus": 0,
+ "no-tabs": 0,
+ "no-ternary": 0,
+ "no-trailing-spaces": 0,
+ "no-underscore-dangle": 0,
+ "no-unneeded-ternary": 2,
+ "no-whitespace-before-property": 0,
+ "nonblock-statement-body-position": 0,
+ "object-curly-newline": 0,
+ "object-curly-spacing": 0,
+ "object-property-newline": 0,
+ "one-var": 0,
+ "one-var-declaration-per-line": 0,
+ "operator-assignment": 0,
+ "operator-linebreak": 0,
+ "padded-blocks": 0,
+ "padding-line-between-statements": 0,
+ // FIX "prefer-object-spread": 1,
+ "quote-props": 0,
+ "quotes": 0,
+ "require-jsdoc": 0,
+ "semi": 0,
+ "semi-spacing": 0,
+ "semi-style": 0,
+ "sort-keys": 0,
+ "sort-vars": 0,
+ "space-before-blocks": 0,
+ "space-before-function-paren": 0,
+ "space-in-parens": 0,
+ "space-infix-ops": 0,
+ "space-unary-ops": 0,
+ "spaced-comment": 0,
+ "switch-colon-spacing": 0,
+ "template-tag-spacing": 0,
+ "unicode-bom": 0,
+ "wrap-regex": 0,
+ "arrow-body-style": 0,
+ "arrow-parens": 0,
+ "arrow-spacing": 0,
+ // "constructor-super": 1,
+ "generator-star-spacing": 0,
+ "no-class-assign": 0,
+ "no-confusing-arrow": 0,
+ // "no-const-assign": 2,
+ // "no-dupe-class-members": 2,
+ // "no-duplicate-imports": 2,
+ // "no-new-symbol": 2,
+ "no-restricted-imports": 0,
+ // "no-this-before-super": 2,
+ "no-useless-computed-key": 2,
+ // "no-useless-constructor": 2,
+ "no-useless-rename": 2,
+ "no-var": 2,
+ "object-shorthand": 2,
+ "prefer-arrow-callback": 2,
+ "prefer-const": 0,
+ "prefer-destructuring": 0,
+ "prefer-numeric-literals": 0,
+ "prefer-rest-params": 0,
+ "prefer-spread": 0,
+ "prefer-template": 2,
+ "require-yield": 0,
+ "rest-spread-spacing": 0,
+ "sort-imports": 0,
+ "symbol-description": 0,
+ "template-curly-spacing": 0,
+ "yield-star-spacing": 0
+ }
+}
diff --git a/.prettierrc b/.prettierrc
new file mode 100644
--- /dev/null
+++ b/.prettierrc
@@ -0,0 +1 @@
+{ "tabWidth": 4, "trailingComma": "es5", "useTabs": true }
diff --git a/lib/action.js b/lib/action.js
--- a/lib/action.js
+++ b/lib/action.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const SubjectPath = locreq("lib/data-structures/subject-path.js");
const Promise = require("bluebird");
diff --git a/lib/app/app.js b/lib/app/app.js
--- a/lib/app/app.js
+++ b/lib/app/app.js
@@ -106,10 +106,7 @@
}
createChip(constructor, declaration) {
- const chip = new constructor(
- this,
- declaration
- );
+ const chip = new constructor(this, declaration);
this.ChipManager.add_chip(
constructor.type_name,
declaration.name,
diff --git a/lib/app/base-chips/access-strategy-types/and.js b/lib/app/base-chips/access-strategy-types/and.js
--- a/lib/app/base-chips/access-strategy-types/and.js
+++ b/lib/app/base-chips/access-strategy-types/and.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
const AccessStrategy = locreq("lib/chip-types/access-strategy.js");
@@ -11,30 +10,29 @@
module.exports = function(app) {
const and = {
name: "and",
- getRestrictingQuery: async function(context, params) {
+ async getRestrictingQuery(context, params) {
const access_strategies = parse_params(app, params);
const queries = await Promise.map(access_strategies, strategy =>
strategy.getRestrictingQuery(context)
);
return new Query.And(...queries);
},
- item_sensitive: function(params) {
+ item_sensitive(params) {
const access_strategies = parse_params(app, params);
- return Promise.map(access_strategies, function(access_strategy) {
+ return Promise.map(access_strategies, access_strategy => {
return access_strategy.is_item_sensitive();
}).reduce((a, b) => a || b);
},
- checker_function: function(context, params, item) {
- return and.item_sensitive(params).then(function(item_sensitive) {
+ checker_function(context, params, item) {
+ return and.item_sensitive(params).then(item_sensitive => {
if (item_sensitive && item === undefined) {
return undefined;
- } else {
- const access_strategies = parse_params(app, params);
- const results = access_strategies.map(function(strategy) {
- return strategy.check(context, item);
- });
- return Promise.all(results);
}
+ const access_strategies = parse_params(app, params);
+ const results = access_strategies.map(strategy => {
+ return strategy.check(context, item);
+ });
+ return Promise.all(results);
});
},
};
diff --git a/lib/app/base-chips/access-strategy-types/and.subtest.js b/lib/app/base-chips/access-strategy-types/and.subtest.js
--- a/lib/app/base-chips/access-strategy-types/and.subtest.js
+++ b/lib/app/base-chips/access-strategy-types/and.subtest.js
@@ -48,7 +48,7 @@
for (const { name, strategies } of collections) {
app.createChip(Sealious.Collection, {
- name: name,
+ name,
fields: [
{
name: "number",
diff --git a/lib/app/base-chips/access-strategy-types/logged_in.js b/lib/app/base-chips/access-strategy-types/logged_in.js
--- a/lib/app/base-chips/access-strategy-types/logged_in.js
+++ b/lib/app/base-chips/access-strategy-types/logged_in.js
@@ -1,22 +1,18 @@
-"use strict";
const Promise = require("bluebird");
const Query = require("../../../datastore/query.js");
module.exports = {
name: "logged_in",
- getRestrictingQuery: async function(context) {
+ async getRestrictingQuery(context) {
if (context.user_id) {
return new Query.AllowAll();
}
return new Query.DenyAll();
},
- checker_function: function(context) {
+ checker_function(context) {
if (context.user_id) {
return Promise.resolve();
- } else {
- return Promise.reject(
- "Only logged-in users can perform this action."
- );
}
+ return Promise.reject("Only logged-in users can perform this action.");
},
};
diff --git a/lib/app/base-chips/access-strategy-types/noone.js b/lib/app/base-chips/access-strategy-types/noone.js
--- a/lib/app/base-chips/access-strategy-types/noone.js
+++ b/lib/app/base-chips/access-strategy-types/noone.js
@@ -1,13 +1,12 @@
-"use strict";
const Promise = require("bluebird");
const Query = require("../../../datastore/query.js");
module.exports = {
name: "noone",
- getRestrictingQuery: async function() {
+ async getRestrictingQuery() {
return new Query.DenyAll();
},
- checker_function: function() {
+ checker_function() {
return Promise.reject("Noone gets in!");
},
item_sensitive: false,
diff --git a/lib/app/base-chips/access-strategy-types/not.js b/lib/app/base-chips/access-strategy-types/not.js
--- a/lib/app/base-chips/access-strategy-types/not.js
+++ b/lib/app/base-chips/access-strategy-types/not.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
const AccessStrategy = locreq("lib/chip-types/access-strategy.js");
@@ -19,29 +18,29 @@
module.exports = function(app) {
return {
name: "not",
- getRestrictingQuery: async function(context, params) {
+ async getRestrictingQuery(context, params) {
//assuming "not" can take only one access strategy as a parameter
const strategy = parse_params(app, params)[0];
const query = await strategy.getRestrictingQuery(context);
return new Query.Not(query);
},
- item_sensitive: function(params) {
+ item_sensitive(params) {
const access_strategies = parse_params(app, params);
- return Promise.map(access_strategies, function(access_strategy) {
+ return Promise.map(access_strategies, access_strategy => {
return access_strategy.is_item_sensitive();
}).reduce((a, b) => a || b, false);
},
- checker_function: function(context, params, item) {
+ checker_function(context, params, item) {
const strategies = parse_params(app, params);
- return Promise.map(strategies, function(strategy) {
+ return Promise.map(strategies, strategy => {
return strategy.check(context, item);
})
.any()
- .then(function() {
+ .then(() => {
return Promise.reject("Action not allowed");
})
- .catch({ sealious_error: true }, function() {
+ .catch({ sealious_error: true }, () => {
return Promise.resolve();
});
},
diff --git a/lib/app/base-chips/access-strategy-types/not.subtest.js b/lib/app/base-chips/access-strategy-types/not.subtest.js
--- a/lib/app/base-chips/access-strategy-types/not.subtest.js
+++ b/lib/app/base-chips/access-strategy-types/not.subtest.js
@@ -43,7 +43,7 @@
for (const { name, strategy } of collections) {
app.createChip(Sealious.Collection, {
- name: name,
+ name,
fields: [
{
name: "number",
@@ -81,7 +81,7 @@
function create_less_than_strategy(app, number) {
app.createChip(app.Sealious.AccessStrategyType, {
name: `less-than(${number})`,
- getRestrictingQuery: async function() {
+ async getRestrictingQuery() {
const query = new app.Query();
const id = query.lookup({
from: "numbers",
@@ -95,7 +95,7 @@
});
return query;
},
- checker_function: async function(context, params, item) {
+ async checker_function(context, params, item) {
if (item.number.number >= number) {
return Promise.reject(
`Given value is not lower than ${number}`
diff --git a/lib/app/base-chips/access-strategy-types/or.js b/lib/app/base-chips/access-strategy-types/or.js
--- a/lib/app/base-chips/access-strategy-types/or.js
+++ b/lib/app/base-chips/access-strategy-types/or.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
const Error = locreq("lib/response/error.js").Error;
@@ -12,7 +11,7 @@
module.exports = function(app) {
const or = {
name: "or",
- getRestrictingQuery: async function(context, params) {
+ async getRestrictingQuery(context, params) {
const access_strategies = parse_params(app, params);
const queries = await Promise.map(access_strategies, strategy =>
strategy.getRestrictingQuery(context)
@@ -22,42 +21,38 @@
}
return new Query.Or(...queries);
},
- item_sensitive: function(params) {
+ item_sensitive(params) {
const access_strategies = parse_params(app, params);
- return Promise.map(access_strategies, function(access_strategy) {
+ return Promise.map(access_strategies, access_strategy => {
return access_strategy.is_item_sensitive();
}).reduce((a, b) => a || b);
},
- checker_function: function(context, params, item) {
+ checker_function(context, params, item) {
if (context.is_super) {
return Promise.resolve();
}
- return or.item_sensitive(params).then(function(item_sensitive) {
+ return or.item_sensitive(params).then(item_sensitive => {
if (item_sensitive && item === undefined) {
return undefined;
- } else {
- const access_strategies = parse_params(app, params);
- const results = access_strategies.map(function(strategy) {
- return strategy.check(context, item);
- });
- return Promise.any(results).catch(
- Promise.AggregateError,
- function(aggregated_errors) {
- aggregated_errors.forEach(function(error) {
- if (!(error instanceof Error)) {
- throw error;
- }
- });
- const error_message = aggregated_errors
- .map(
- aggregated_errors =>
- aggregated_errors.message
- )
- .reduce((a, b) => `${a} ${b}`);
- return Promise.reject(error_message);
- }
- );
}
+ const access_strategies = parse_params(app, params);
+ const results = access_strategies.map(strategy => {
+ return strategy.check(context, item);
+ });
+ return Promise.any(results).catch(
+ Promise.AggregateError,
+ aggregated_errors => {
+ aggregated_errors.forEach(error => {
+ if (!(error instanceof Error)) {
+ throw error;
+ }
+ });
+ const error_message = aggregated_errors
+ .map(aggregated_errors => aggregated_errors.message)
+ .reduce((a, b) => `${a} ${b}`);
+ return Promise.reject(error_message);
+ }
+ );
});
},
};
diff --git a/lib/app/base-chips/access-strategy-types/or.subtest.js b/lib/app/base-chips/access-strategy-types/or.subtest.js
--- a/lib/app/base-chips/access-strategy-types/or.subtest.js
+++ b/lib/app/base-chips/access-strategy-types/or.subtest.js
@@ -49,7 +49,7 @@
for (const { name, strategies } of collections) {
app.createChip(Sealious.Collection, {
- name: name,
+ name,
fields: [
{
name: "number",
diff --git a/lib/app/base-chips/access-strategy-types/owner.js b/lib/app/base-chips/access-strategy-types/owner.js
--- a/lib/app/base-chips/access-strategy-types/owner.js
+++ b/lib/app/base-chips/access-strategy-types/owner.js
@@ -1,10 +1,9 @@
-"use strict";
const Promise = require("bluebird");
const Query = require("../../../datastore/query.js");
module.exports = {
name: "owner",
- getRestrictingQuery: async function(context, params) {
+ async getRestrictingQuery(context, params) {
if (context.user_id) {
return Query.fromSingleMatch({
"_metadata.created_context.user_id": { $eq: context.user_id },
@@ -12,17 +11,16 @@
}
return new Query.DenyAll();
},
- checker_function: function(context, params, item) {
+ checker_function(context, params, item) {
if (
context.user_id &&
context.user_id === item._metadata.created_context.user_id
) {
return Promise.resolve();
- } else {
- return Promise.reject(
- "Only the owner of this resource can perform this operation on this item."
- );
}
+ return Promise.reject(
+ "Only the owner of this resource can perform this operation on this item."
+ );
},
item_sensitive: true,
};
diff --git a/lib/app/base-chips/access-strategy-types/public.js b/lib/app/base-chips/access-strategy-types/public.js
--- a/lib/app/base-chips/access-strategy-types/public.js
+++ b/lib/app/base-chips/access-strategy-types/public.js
@@ -1,14 +1,13 @@
-"use strict";
const Promise = require("bluebird");
const Query = require("../../../datastore/query.js");
module.exports = {
name: "public",
- getRestrictingQuery: async function() {
+ async getRestrictingQuery() {
return new Query.AllowAll();
},
- checker_function: function() {
+ checker_function() {
return Promise.resolve("Everybody is a winner!");
},
item_sensitive: false,
diff --git a/lib/app/base-chips/access-strategy-types/same-anon.js b/lib/app/base-chips/access-strategy-types/same-anon.js
--- a/lib/app/base-chips/access-strategy-types/same-anon.js
+++ b/lib/app/base-chips/access-strategy-types/same-anon.js
@@ -1,9 +1,8 @@
-"use strict";
const Query = require("../../../datastore/query.js");
module.exports = {
name: "same-anon",
- getRestrictingQuery: async function(context, params) {
+ async getRestrictingQuery(context, params) {
if (context.anonymous_user_id) {
return Query.fromSingleMatch({
"_metadata.created_context.anonymous_user_id":
@@ -12,7 +11,7 @@
}
return new Query.AllowAll();
},
- checker_function: function(context, params, item) {
+ checker_function(context, params, item) {
if (context.anonymous_user_id === null) {
return Promise.reject();
}
@@ -21,11 +20,10 @@
item._metadata.created_context.anonymous_user_id
) {
return Promise.resolve();
- } else {
- return Promise.reject(
- "Only the user who created this resource can have access to it"
- );
}
+ return Promise.reject(
+ "Only the user who created this resource can have access to it"
+ );
},
item_sensitive: true,
};
diff --git a/lib/app/base-chips/access-strategy-types/same-as-for-resource-in-field.js b/lib/app/base-chips/access-strategy-types/same-as-for-resource-in-field.js
--- a/lib/app/base-chips/access-strategy-types/same-as-for-resource-in-field.js
+++ b/lib/app/base-chips/access-strategy-types/same-as-for-resource-in-field.js
@@ -2,10 +2,7 @@
module.exports = app => ({
name: "same-as-for-resource-in-field",
- getRestrictingQuery: async function(
- context,
- { action_name, collection, field }
- ) {
+ async getRestrictingQuery(context, { action_name, collection, field }) {
const referenced_collection = get_referenced_collection(
app,
collection,
@@ -47,11 +44,7 @@
return Query.fromCustomPipeline(pipeline);
},
- checker_function: async function(
- context,
- { action_name, collection, field },
- item
- ) {
+ async checker_function(context, { action_name, collection, field }, item) {
const referenced_collection = get_referenced_collection(
app,
collection,
@@ -111,7 +104,7 @@
group[prop] = add_parent_prefix(group[prop], parent_property);
}
const new_prop = prop_regex.test(prop)
- ? parent_property + "." + prop
+ ? `${parent_property}.${prop}`
: prop;
acc[new_prop] = group[prop];
return acc;
diff --git a/lib/app/base-chips/access-strategy-types/same-as-for-resource-in-field.subtest.js b/lib/app/base-chips/access-strategy-types/same-as-for-resource-in-field.subtest.js
--- a/lib/app/base-chips/access-strategy-types/same-as-for-resource-in-field.subtest.js
+++ b/lib/app/base-chips/access-strategy-types/same-as-for-resource-in-field.subtest.js
@@ -98,8 +98,8 @@
await rest_api.post(
"/api/v1/collections/number-notes",
{
- note: "Lorem ipsum " + (notes.length + 1),
- number: number,
+ note: `Lorem ipsum ${notes.length + 1}`,
+ number,
},
sessions[user]
)
diff --git a/lib/app/base-chips/access-strategy-types/super.js b/lib/app/base-chips/access-strategy-types/super.js
--- a/lib/app/base-chips/access-strategy-types/super.js
+++ b/lib/app/base-chips/access-strategy-types/super.js
@@ -1,24 +1,22 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
const Query = require("../../../datastore/query.js");
const Super = {
name: "super",
- getRestrictingQuery: async function(context) {
+ async getRestrictingQuery(context) {
if (context.is_super) {
return new Query.AllowAll();
}
return new Query.DenyAll();
},
- checker_function: function(context) {
+ checker_function(context) {
if (context.is_super) {
return Promise.resolve();
- } else {
- return Promise.reject(
- "This action cannot be performed by a regular user, but only by the server itself."
- );
}
+ return Promise.reject(
+ "This action cannot be performed by a regular user, but only by the server itself."
+ );
},
item_sensitive: true,
};
diff --git a/lib/app/base-chips/access-strategy-types/themselves.js b/lib/app/base-chips/access-strategy-types/themselves.js
--- a/lib/app/base-chips/access-strategy-types/themselves.js
+++ b/lib/app/base-chips/access-strategy-types/themselves.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
const Query = require("../../../datastore/query.js");
@@ -6,16 +5,15 @@
module.exports = {
name: "themselves",
item_sensitive: true,
- getRestrictingQuery: async function(context, params) {
+ async getRestrictingQuery(context, params) {
return Query.fromSingleMatch({
sealious_id: { $eq: context.user_id },
});
},
- checker_function: function(context, params, item) {
+ checker_function(context, params, item) {
if (context.user_id === item.id) {
return Promise.resolve();
- } else {
- return Promise.reject(`You are not the user of id ${item.id}.`);
}
+ return Promise.reject(`You are not the user of id ${item.id}.`);
},
};
diff --git a/lib/app/base-chips/access-strategy-types/user-referenced-in-field.js b/lib/app/base-chips/access-strategy-types/user-referenced-in-field.js
--- a/lib/app/base-chips/access-strategy-types/user-referenced-in-field.js
+++ b/lib/app/base-chips/access-strategy-types/user-referenced-in-field.js
@@ -9,7 +9,7 @@
checker_function: (context, field_name, item) => {
if (!context.user_id) return Promise.reject("You're not logged in!");
else if (context.user_id === item[field_name]) return Promise.resolve();
- else return Promise.reject("Access not allowed for this user");
+ return Promise.reject("Access not allowed for this user");
},
item_sensitive: true,
});
diff --git a/lib/app/base-chips/access-strategy-types/user-referenced-in-field.subtest.js b/lib/app/base-chips/access-strategy-types/user-referenced-in-field.subtest.js
--- a/lib/app/base-chips/access-strategy-types/user-referenced-in-field.subtest.js
+++ b/lib/app/base-chips/access-strategy-types/user-referenced-in-field.subtest.js
@@ -28,7 +28,7 @@
["collections", "users"],
"create",
{
- username: username,
+ username,
password: "password",
email: `${username.toLowerCase()}@example.com`,
}
diff --git a/lib/app/base-chips/access-strategy-types/users-who-can.js b/lib/app/base-chips/access-strategy-types/users-who-can.js
--- a/lib/app/base-chips/access-strategy-types/users-who-can.js
+++ b/lib/app/base-chips/access-strategy-types/users-who-can.js
@@ -13,11 +13,7 @@
module.exports = app => ({
name: "users-who-can",
- get_pre_aggregation_stage: async function(
- context,
- [action_name, collection],
- item
- ) {
+ async get_pre_aggregation_stage(context, [action_name, collection], item) {
check_params(app, [action_name, collection]);
try {
await collection.get_access_strategy(action_name).check(context);
@@ -26,7 +22,7 @@
return Promise.resolve(DENY);
}
},
- checker_function: async function(context, [action_name, collection]) {
+ async checker_function(context, [action_name, collection]) {
check_params(app, [action_name, collection]);
try {
await collection.get_access_strategy(action_name).check(context);
diff --git a/lib/app/base-chips/access-strategy-types/when.js b/lib/app/base-chips/access-strategy-types/when.js
--- a/lib/app/base-chips/access-strategy-types/when.js
+++ b/lib/app/base-chips/access-strategy-types/when.js
@@ -1,4 +1,3 @@
-"use strict";
const Promise = require("bluebird");
const Query = require("../../../datastore/query.js");
@@ -29,7 +28,7 @@
module.exports = app => ({
name: "when",
- getRestrictingQuery: async function(
+ async getRestrictingQuery(
context,
[
collection_name,
@@ -47,7 +46,7 @@
when_false_name
);
},
- checker_function: async function(
+ async checker_function(
context,
[
collection_name,
diff --git a/lib/app/base-chips/calculated-field-types/aggregate.js b/lib/app/base-chips/calculated-field-types/aggregate.js
--- a/lib/app/base-chips/calculated-field-types/aggregate.js
+++ b/lib/app/base-chips/calculated-field-types/aggregate.js
@@ -1,21 +1,19 @@
-"use strict";
const Promise = require("bluebird");
module.exports = function(app) {
return {
name: "aggregate",
- calculate: function(context, params, item, db_document) {
+ calculate(context, params, item, db_document) {
let stages = params.stages;
if (params.stages instanceof Function) {
stages = params.stages(context, params, item, db_document);
}
return app.Datastore.aggregate(params.collection, stages).then(
- function(documents) {
+ documents => {
if (documents.length) {
return documents[0].result;
- } else {
- return null;
}
+ return null;
}
);
},
diff --git a/lib/app/base-chips/calculated-field-types/custom.js b/lib/app/base-chips/calculated-field-types/custom.js
--- a/lib/app/base-chips/calculated-field-types/custom.js
+++ b/lib/app/base-chips/calculated-field-types/custom.js
@@ -1,10 +1,9 @@
-"use strict";
const Promise = require("bluebird");
module.exports = function(app) {
return {
name: "custom",
- calculate: function(context, params, item, db_document) {
+ calculate(context, params, item, db_document) {
return params(app, context, item, db_document);
},
};
diff --git a/lib/app/base-chips/calculated-field-types/map-reduce.js b/lib/app/base-chips/calculated-field-types/map-reduce.js
--- a/lib/app/base-chips/calculated-field-types/map-reduce.js
+++ b/lib/app/base-chips/calculated-field-types/map-reduce.js
@@ -3,21 +3,20 @@
module.exports = function(App) {
return {
name: "map-reduce",
- calculate: function(context, params, item) {
+ calculate(context, params, item) {
const action_arguments = [
context,
params.source.subject_path,
params.source.action_name,
params.source.params,
- ].map(function(element) {
+ ].map(element => {
if (element instanceof Function) {
return element(context, params, item);
- } else {
- return element;
}
+ return element;
});
return Promise.all(action_arguments)
- .then(function(fulfilled_action_arguments) {
+ .then(fulfilled_action_arguments => {
return App.run_action.apply(
App,
fulfilled_action_arguments
diff --git a/lib/app/base-chips/collections/formatted-images.js b/lib/app/base-chips/collections/formatted-images.js
--- a/lib/app/base-chips/collections/formatted-images.js
+++ b/lib/app/base-chips/collections/formatted-images.js
@@ -1,4 +1,3 @@
-"use strict";
module.exports = {
name: "formatted-images",
fields: [
diff --git a/lib/app/base-chips/collections/password-reset-intents.subtest.js b/lib/app/base-chips/collections/password-reset-intents.subtest.js
--- a/lib/app/base-chips/collections/password-reset-intents.subtest.js
+++ b/lib/app/base-chips/collections/password-reset-intents.subtest.js
@@ -86,7 +86,7 @@
}
)).data;
const messages = (await mail_api.get_messages()).filter(
- message => message.recipients[0] == "<user@example.com>"
+ message => message.recipients[0] === "<user@example.com>"
);
assert(messages.length, 1);
assert.equal(messages[0].recipients.length, 1);
diff --git a/lib/app/base-chips/collections/users.js b/lib/app/base-chips/collections/users.js
--- a/lib/app/base-chips/collections/users.js
+++ b/lib/app/base-chips/collections/users.js
@@ -1,4 +1,3 @@
-"use strict";
module.exports = app => {
const user_roles = app.ChipManager.get_chip("collection", "user-roles");
const users = {
diff --git a/lib/app/base-chips/field-types/boolean.js b/lib/app/base-chips/field-types/boolean.js
--- a/lib/app/base-chips/field-types/boolean.js
+++ b/lib/app/base-chips/field-types/boolean.js
@@ -1,10 +1,9 @@
-"use strict";
module.exports = {
name: "boolean",
- get_description: function() {
+ get_description() {
return 'Boolean value. True or false. Can be a string: "true" or "false".';
},
- is_proper_value: function(context, params, value) {
+ is_proper_value(context, params, value) {
if (typeof value === "boolean") {
return Promise.resolve();
} else if (value.toString() === "1" || value.toString() === "0") {
@@ -14,11 +13,10 @@
(value.toLowerCase() === "true" || value.toLowerCase() === "false")
) {
return Promise.resolve();
- } else {
- return Promise.reject(`Value '${value}' is not boolean format.`);
}
+ return Promise.reject(`Value '${value}' is not boolean format.`);
},
- encode: function(context, params, value) {
+ encode(context, params, value) {
if (typeof value === "boolean") {
return value;
} else if (value.toString() === "1") {
@@ -33,13 +31,12 @@
}
}
},
- filter_to_query: function(context, params, filter) {
+ filter_to_query(context, params, filter) {
if (filter === "") {
return { $exists: false };
} else if (filter === null) {
return { $in: [true, false] };
- } else {
- return this.encode(context, params, filter);
}
+ return this.encode(context, params, filter);
},
};
diff --git a/lib/app/base-chips/field-types/cached-value.js b/lib/app/base-chips/field-types/cached-value.js
--- a/lib/app/base-chips/field-types/cached-value.js
+++ b/lib/app/base-chips/field-types/cached-value.js
@@ -1,16 +1,15 @@
-"use strict";
const { getDateTime } = require("../../../utils/get-datetime.js");
module.exports = app => ({
name: "cached-value",
- get_description: function() {
+ get_description() {
return "Caches custom values. Takes care of cache invalidation.";
},
get_default_value: async () => null,
value_path_after_field_name: ".value",
- is_proper_value: function(context, params, new_value) {
+ is_proper_value(context, params, new_value) {
if (!context.is_super) {
return Promise.reject("This is a read-only field");
}
@@ -22,7 +21,7 @@
new_value
);
},
- filter_to_query: async function(context, params, field_filter) {
+ async filter_to_query(context, params, field_filter) {
return this._call_base_method(
"filter_to_query",
context,
@@ -30,7 +29,7 @@
field_filter
);
},
- init: function(collection, field_name, params) {
+ init(collection, field_name, params) {
const { refresh_on, get_value, base_field_type } = params;
this._check_for_possible_recursive_edits(
app,
@@ -80,7 +79,7 @@
}
},
- _check_for_possible_recursive_edits: function(
+ _check_for_possible_recursive_edits(
app,
refresh_on,
collection_name,
@@ -103,7 +102,7 @@
}
},
- _refresh_outdated_cache_values: async function(
+ async _refresh_outdated_cache_values(
create_action,
collection,
field_name,
@@ -165,7 +164,7 @@
);
}
},
- encode: async function(context, params, value) {
+ async encode(context, params, value) {
return {
timestamp: context.timestamp,
value: await this._call_base_method(
@@ -176,7 +175,7 @@
),
};
},
- decode: function(context, params, value_in_db) {
+ decode(context, params, value_in_db) {
return this._call_base_method(
"decode",
context,
@@ -184,7 +183,7 @@
value_in_db ? value_in_db.value : null
);
},
- format: function(context, params, decoded_value, format) {
+ format(context, params, decoded_value, format) {
const base_field_type = app.FieldType(params.base_field_type.name);
return base_field_type.format(
context,
diff --git a/lib/app/base-chips/field-types/color.js b/lib/app/base-chips/field-types/color.js
--- a/lib/app/base-chips/field-types/color.js
+++ b/lib/app/base-chips/field-types/color.js
@@ -1,7 +1,6 @@
-"use strict";
module.exports = {
name: "color",
- is_proper_value: function(context, params, new_value) {
+ is_proper_value(context, params, new_value) {
const Color = require("color"); //putting it here not to slow down `new Sealious.app()`
try {
if (typeof new_value === "string") {
@@ -16,7 +15,7 @@
);
}
},
- encode: function(context, params, value_in_code) {
+ encode(context, params, value_in_code) {
const Color = require("color"); //putting it here not to slow down `new Sealious.app()`
const color = Color(value_in_code);
return color.hexString();
diff --git a/lib/app/base-chips/field-types/context.js b/lib/app/base-chips/field-types/context.js
--- a/lib/app/base-chips/field-types/context.js
+++ b/lib/app/base-chips/field-types/context.js
@@ -1,16 +1,14 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Context = locreq("lib/context.js");
module.exports = {
name: "context",
- is_proper_value: function(context, params, value) {
+ is_proper_value(context, params, value) {
if (value instanceof Context) {
return Promise.resolve();
- } else {
- return Promise.reject(
- "Provided value is not an instance of Sealious.Context"
- );
}
+ return Promise.reject(
+ "Provided value is not an instance of Sealious.Context"
+ );
},
};
diff --git a/lib/app/base-chips/field-types/control-access.js b/lib/app/base-chips/field-types/control-access.js
--- a/lib/app/base-chips/field-types/control-access.js
+++ b/lib/app/base-chips/field-types/control-access.js
@@ -1,6 +1,6 @@
module.exports = app => ({
name: "control-access",
- is_proper_value: async function(
+ async is_proper_value(
context,
{ target_field_type_name, target_params, target_access_strategies },
new_value,
@@ -31,7 +31,7 @@
old_value
);
},
- decode: function(
+ decode(
context,
{ target_field_type_name, target_params, target_access_strategies },
value_in_db
diff --git a/lib/app/base-chips/field-types/control-access.subtest.js b/lib/app/base-chips/field-types/control-access.subtest.js
--- a/lib/app/base-chips/field-types/control-access.subtest.js
+++ b/lib/app/base-chips/field-types/control-access.subtest.js
@@ -11,12 +11,12 @@
name: "ssh-keys",
fields: [
{
- name: "public",
+ name: "visible",
type: "text",
required: true,
},
{
- name: "private",
+ name: "hidden",
type: "control-access",
params: {
target_access_strategies: {
@@ -72,22 +72,22 @@
async function fill_keys_collections(App) {
const keys = [
{
- public: "a-public-key",
- private: "seeeeecret",
+ visible: "a-visible-key",
+ hidden: "seeeeecret",
},
{
- public: "go-get-it",
- private: "you-cannot-see",
+ visible: "go-get-it",
+ hidden: "you-cannot-see",
},
];
- for (let { public, private } of keys) {
+ for (let { visible, hidden } of keys) {
let key = await App.run_action(
new App.Sealious.SuperContext(),
["collections", "ssh-keys"],
"create",
{
- public,
- private,
+ visible,
+ hidden,
}
);
}
@@ -109,7 +109,7 @@
);
ssh_keys.forEach(key => {
- assert.deepEqual(key.private, "");
+ assert.deepEqual(key.hidden, "");
});
}));
@@ -123,7 +123,7 @@
);
ssh_keys.forEach(key => {
- assert(key.private.length >= 3);
+ assert(key.hidden.length >= 3);
});
}));
@@ -136,14 +136,14 @@
rest_api.post(
SSH_KEYS_URL,
{
- public: "XDDDDDDDDDDDD",
- private: "XD",
+ visible: "XDDDDDDDDDDDD",
+ hidden: "XD",
},
sessions.admin
),
e =>
assert.equal(
- e.response.data.data.private.message,
+ e.response.data.data.hidden.message,
"Text 'XD' is too short, minimum length is 3 chars."
)
);
@@ -156,8 +156,8 @@
const key = await rest_api.post(
SSH_KEYS_URL,
{
- public: "123123",
- private: "321321",
+ visible: "123123",
+ hidden: "321321",
},
sessions.admin
);
@@ -165,12 +165,12 @@
const updated_key = await rest_api.patch(
`${SSH_KEYS_URL}/${key.id}`,
{
- private: "654321",
+ hidden: "654321",
},
sessions.admin
);
- assert.deepEqual(updated_key.private, "654321");
+ assert.deepEqual(updated_key.hidden, "654321");
}));
it("Doesn't allow regular-user to update a protected field", async () =>
@@ -180,8 +180,8 @@
const key = await rest_api.post(
SSH_KEYS_URL,
{
- public: "123123",
- private: "321321",
+ visible: "123123",
+ hidden: "321321",
},
sessions.admin
);
@@ -190,12 +190,12 @@
() =>
rest_api.patch(
`${SSH_KEYS_URL}/${key.id}`,
- { private: "331c6883dd6010864b7ead130be77cd5" },
+ { hidden: "331c6883dd6010864b7ead130be77cd5" },
sessions["regular-user"]
),
e =>
assert.deepEqual(
- e.response.data.data.private.message,
+ e.response.data.data.hidden.message,
"You are not allowed to update this field."
)
);
diff --git a/lib/app/base-chips/field-types/date.js b/lib/app/base-chips/field-types/date.js
--- a/lib/app/base-chips/field-types/date.js
+++ b/lib/app/base-chips/field-types/date.js
@@ -1,10 +1,9 @@
-"use strict";
module.exports = {
name: "date",
- get_description: function() {
+ get_description() {
return "Date standard ISO 8601 (YYYY-MM-DD)";
},
- is_proper_value: function(context, params, date) {
+ is_proper_value(context, params, date) {
const date_in_string = date.toString();
const regex = /^([0-9]{4})-(0?[1-9]|1[0-2])-([0-2]?[0-9]|30|31)$/; // granulation_per_day
@@ -16,8 +15,7 @@
return Promise.reject(
`Value "${date}" is not date calendar format. Expected value standard IS0 8601 (YYYY-MM-DD)`
);
- } else {
- return Promise.resolve();
}
+ return Promise.resolve();
},
};
diff --git a/lib/app/base-chips/field-types/datetime.js b/lib/app/base-chips/field-types/datetime.js
--- a/lib/app/base-chips/field-types/datetime.js
+++ b/lib/app/base-chips/field-types/datetime.js
@@ -1,19 +1,18 @@
-"use strict";
-
const { getDateTime } = require("../../../utils/get-datetime.js");
module.exports = {
name: "datetime",
extends: "int",
- has_index: function(params) {
+ has_index(params) {
if (params.indexed) {
return 1;
- } else return false;
+ }
+ return false;
},
- get_description: function() {
+ get_description() {
return "Timestamp - amount of miliseconds since epoch.";
},
- is_proper_value: function(context, params, datetime) {
+ is_proper_value(context, params, datetime) {
if (Number.isInteger(datetime)) {
return Promise.resolve();
}
@@ -21,11 +20,11 @@
`Value '${datetime}' is not datetime format. Only timestamps are accepted.`
);
},
- encode: function(context, params, value_in_code) {
+ encode(context, params, value_in_code) {
const parsed_datetime = parseInt(value_in_code);
return parsed_datetime;
},
- format: function(context, params, decoded_value, format) {
+ format(context, params, decoded_value, format) {
if (decoded_value === null || decoded_value === undefined) {
return Promise.resolve(decoded_value);
}
diff --git a/lib/app/base-chips/field-types/derived-value.js b/lib/app/base-chips/field-types/derived-value.js
--- a/lib/app/base-chips/field-types/derived-value.js
+++ b/lib/app/base-chips/field-types/derived-value.js
@@ -7,7 +7,7 @@
get_description: () =>
"A value derived from an array of fields of the given collection.",
get_default_value: async () => null,
- is_proper_value: function(context, params, new_value) {
+ is_proper_value(context, params, new_value) {
return this._call_base_method(
"is_proper_value",
context,
@@ -15,7 +15,7 @@
new_value
);
},
- filter_to_query: async function(context, params, field_filter) {
+ async filter_to_query(context, params, field_filter) {
return this._call_base_method(
"filter_to_query",
context,
@@ -23,7 +23,7 @@
field_filter
);
},
- init: function(collection, field_name, params) {
+ init(collection, field_name, params) {
const { fields, derived_fn, base_field_type } = params;
if (typeof derived_fn !== "function") {
throw new Error(
@@ -113,13 +113,13 @@
);
},
- encode: async function(context, params, value) {
+ async encode(context, params, value) {
return this._call_base_method("encode", context, params, value);
},
- decode: function(context, params, value_in_db) {
+ decode(context, params, value_in_db) {
return this._call_base_method("decode", context, params, value_in_db);
},
- format: function(context, params, decoded_value, format) {
+ format(context, params, decoded_value, format) {
return this._call_base_method(
"format",
context,
diff --git a/lib/app/base-chips/field-types/email.js b/lib/app/base-chips/field-types/email.js
--- a/lib/app/base-chips/field-types/email.js
+++ b/lib/app/base-chips/field-types/email.js
@@ -1,18 +1,16 @@
-"use strict";
module.exports = {
name: "email",
- get_description: function() {
+ get_description() {
return "Email address, like something@something.sth";
},
- is_proper_value: function(context, params, value) {
+ is_proper_value(context, params, value) {
const address = value;
const regex = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if (regex.test(address) || address === "") {
return Promise.resolve();
- } else {
- return Promise.reject(`${address} is a not valid e-mail address.`);
}
+ return Promise.reject(`${address} is a not valid e-mail address.`);
},
};
diff --git a/lib/app/base-chips/field-types/enum.js b/lib/app/base-chips/field-types/enum.js
--- a/lib/app/base-chips/field-types/enum.js
+++ b/lib/app/base-chips/field-types/enum.js
@@ -1,15 +1,13 @@
-"use strict";
module.exports = {
name: "enum",
- is_proper_value: async function(context, params, value) {
+ async is_proper_value(context, params, value) {
const allowed_values =
params.values instanceof Function
? await params.values()
: params.values;
if (allowed_values.indexOf(value) !== -1) {
return Promise.resolve();
- } else {
- return Promise.reject("Allowed values: " + allowed_values.join());
}
+ return Promise.reject(`Allowed values: ${allowed_values.join()}`);
},
};
diff --git a/lib/app/base-chips/field-types/file-reference.js b/lib/app/base-chips/field-types/file-reference.js
--- a/lib/app/base-chips/field-types/file-reference.js
+++ b/lib/app/base-chips/field-types/file-reference.js
@@ -1,25 +1,21 @@
module.exports = function(app) {
return {
name: "file_reference",
- is_proper_value: function(context, params, value) {
- return app.Datastore.find("files", { id: value }).then(function(
- results
- ) {
+ is_proper_value(context, params, value) {
+ return app.Datastore.find("files", { id: value }).then(results => {
if (results.length === 0) {
- return Promise.reject("Bad file id: " + value);
- } else {
- return Promise.resolve();
+ return Promise.reject(`Bad file id: ${value}`);
}
+ return Promise.resolve();
});
},
- format: function(context, params, file_id, format) {
+ format(context, params, file_id, format) {
if (format === "internal") {
return app.Datastore.find("files", { id: file_id }).then(
a => a[0]
);
- } else {
- return file_id;
}
+ return file_id;
},
};
};
diff --git a/lib/app/base-chips/field-types/file.js b/lib/app/base-chips/field-types/file.js
--- a/lib/app/base-chips/field-types/file.js
+++ b/lib/app/base-chips/field-types/file.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
const File = locreq("lib/data-structures/file.js");
@@ -9,16 +8,16 @@
return {
name: "file",
handles_large_data: true,
- is_proper_value: function(context, params, value) {
+ is_proper_value(context, params, value) {
if (value === undefined) {
return undefined;
}
- if (typeof value == "string") {
+ if (typeof value === "string") {
return axios(value)
- .then(function() {
+ .then(() => {
return Promise.resolve();
})
- .catch(function() {
+ .catch(() => {
return Promise.reject(
`There was a problem while getting the file: '${value}'. Is the URL correct?`
);
@@ -31,24 +30,23 @@
(value.filename !== undefined && value.data instanceof Buffer)
) {
return Promise.resolve();
+ }
+ let type;
+ if (value instanceof Array) {
+ type =
+ "<Array>. If you want to upload multiple files, use array field types.";
} else {
- let type;
- if (value instanceof Array) {
- type =
- "<Array>. If you want to upload multiple files, use array field types.";
- } else {
- type = typeof data;
- }
- return Promise.reject(
- `Wrong file data format. Should be Sealious.File, but received ${type}`
- );
+ type = typeof data;
}
+ return Promise.reject(
+ `Wrong file data format. Should be Sealious.File, but received ${type}`
+ );
},
- encode: function(context, params, value_in_code) {
+ encode(context, params, value_in_code) {
if (typeof value_in_code === "string") {
return axios(value_in_code, {
responseType: "arrayBuffer",
- }).then(function(file_buffer) {
+ }).then(file_buffer => {
const filename = url
.parse(value_in_code)
.pathname.split("/")
@@ -59,11 +57,10 @@
}
if (value_in_code) {
return app.FileManager.save_file(value_in_code);
- } else {
- return null;
}
+ return null;
},
- decode: function(context, params, value_in_database) {
+ decode(context, params, value_in_database) {
if (value_in_database) {
return Promise.resolve(
new File.Reference(
@@ -73,11 +70,10 @@
);
} else if (params.no_file_value) {
return params.no_file_value;
- } else {
- return undefined;
}
+ return undefined;
},
- format: function(context, params, decoded_value, format) {
+ format(context, params, decoded_value, format) {
if (decoded_value === undefined) {
return undefined;
}
@@ -93,18 +89,16 @@
filename: null,
empty: true,
};
- } else {
- return {
- url: `/api/v1/uploaded-files/${decoded_value.id}/${
- decoded_value.filename
- }`,
- filename: decoded_value.filename,
- empty: false,
- };
}
- } else {
- return decoded_value;
+ return {
+ url: `/api/v1/uploaded-files/${decoded_value.id}/${
+ decoded_value.filename
+ }`,
+ filename: decoded_value.filename,
+ empty: false,
+ };
}
+ return decoded_value;
},
};
};
diff --git a/lib/app/base-chips/field-types/float.js b/lib/app/base-chips/field-types/float.js
--- a/lib/app/base-chips/field-types/float.js
+++ b/lib/app/base-chips/field-types/float.js
@@ -1,20 +1,18 @@
-"use strict";
module.exports = {
name: "float",
- get_description: function() {
+ get_description() {
return "Float number.";
},
- is_proper_value: function(context, params, number) {
+ is_proper_value(context, params, number) {
const test = parseFloat(number);
if (test === null || isNaN(test) || isNaN(number) === true) {
return Promise.reject(
`Value '${number}' is not a float number format.`
);
- } else {
- return Promise.resolve();
}
+ return Promise.resolve();
},
- encode: function(context, params, value_in_code) {
+ encode(context, params, value_in_code) {
const parsed_float = parseFloat(value_in_code);
return parsed_float;
},
diff --git a/lib/app/base-chips/field-types/html.js b/lib/app/base-chips/field-types/html.js
--- a/lib/app/base-chips/field-types/html.js
+++ b/lib/app/base-chips/field-types/html.js
@@ -1,9 +1,7 @@
-"use strict";
-
module.exports = {
name: "html",
extends: "text",
- encode: function(context, params, value) {
+ encode(context, params, value) {
const sanitizeHtml = require("sanitize-html"); //putting it here not to slow down `new Sealious.app()`
return {
original: value,
@@ -16,7 +14,7 @@
}),
};
},
- format: function(context, params, decoded_value, format) {
+ format(context, params, decoded_value, format) {
let ret;
if (decoded_value === undefined) return undefined;
switch (format) {
diff --git a/lib/app/base-chips/field-types/image.js b/lib/app/base-chips/field-types/image.js
--- a/lib/app/base-chips/field-types/image.js
+++ b/lib/app/base-chips/field-types/image.js
@@ -1,4 +1,3 @@
-"use strict";
const Promise = require("bluebird");
const assert = require("assert");
const locreq = require("locreq")(__dirname);
@@ -13,19 +12,14 @@
return {
name: "image",
extends: "file",
- is_proper_value: function(context, params, new_value) {
- return File.is_proper_value(context, params, new_value).then(
- function() {
- if (
- new_value.mime &&
- new_value.mime.indexOf("image/") !== 0
- ) {
- return Promise.reject("Only image files are allowed");
- }
+ is_proper_value(context, params, new_value) {
+ return File.is_proper_value(context, params, new_value).then(() => {
+ if (new_value.mime && new_value.mime.indexOf("image/") !== 0) {
+ return Promise.reject("Only image files are allowed");
}
- );
+ });
},
- format: function(context, params, decoded_value, format) {
+ format(context, params, decoded_value, format) {
const formats = params.formats || {};
if (decoded_value === undefined) {
@@ -37,12 +31,11 @@
if (format === "original") {
return File.format(context, params, decoded_value, "url");
- } else {
- return (
- `/api/v1/formatted-images/${decoded_value.id}/` +
- `${format}/${decoded_value.filename}`
- );
}
+ return (
+ `/api/v1/formatted-images/${decoded_value.id}/` +
+ `${format}/${decoded_value.filename}`
+ );
},
};
};
diff --git a/lib/app/base-chips/field-types/int.js b/lib/app/base-chips/field-types/int.js
--- a/lib/app/base-chips/field-types/int.js
+++ b/lib/app/base-chips/field-types/int.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Errors = locreq("lib/response/error.js");
@@ -23,7 +22,7 @@
false,
`Value should be larger or equal to '${params.min}.`,
];
- else return [true];
+ return [true];
},
(params, value) => {
if (Number.isFinite(params.max) && value > params.max)
@@ -31,16 +30,16 @@
false,
`Value should be smaller or equal to '${params.max}.`,
];
- else return [true];
+ return [true];
},
];
const int = {
name: "int",
- get_description: function() {
+ get_description() {
return "An integer number.";
},
- is_proper_value: function(context, params, new_value) {
+ is_proper_value(context, params, new_value) {
if (!Number.isInteger(new_value)) {
return Promise.reject(
`Value '${new_value}' is not a int number format.`
@@ -52,14 +51,13 @@
.filter(element => !element[0]);
if (failed_checks.length === 0) {
return Promise.resolve();
- } else {
- return Promise.reject(failed_checks.map(e => e[1]).join(" "));
}
+ return Promise.reject(failed_checks.map(e => e[1]).join(" "));
},
- encode: function(context, params, value_in_code) {
+ encode(context, params, value_in_code) {
return parseInt(value_in_code, 10);
},
- filter_to_query: function(context, params, field_filter) {
+ filter_to_query(context, params, field_filter) {
if (typeof field_filter !== "object") {
return {
$eq: parseInt(field_filter),
diff --git a/lib/app/base-chips/field-types/json-object.js b/lib/app/base-chips/field-types/json-object.js
--- a/lib/app/base-chips/field-types/json-object.js
+++ b/lib/app/base-chips/field-types/json-object.js
@@ -4,10 +4,10 @@
module.exports = {
name: "json-object",
- get_description: function() {
+ get_description() {
return "Stores json object value.";
},
- is_proper_value: async function(context, params, new_value) {
+ async is_proper_value(context, params, new_value) {
let stringified_value;
try {
stringified_value = JSON.stringify(new_value);
@@ -20,10 +20,10 @@
return Promise.reject("A primitive, not an object!");
}
},
- encode: function(context, params, value_in_code) {
+ encode(context, params, value_in_code) {
return JSON.parse(JSON.stringify(value_in_code));
},
- get_aggregation_stages: function(
+ get_aggregation_stages(
context,
params,
field_name,
diff --git a/lib/app/base-chips/field-types/password.js b/lib/app/base-chips/field-types/password.js
--- a/lib/app/base-chips/field-types/password.js
+++ b/lib/app/base-chips/field-types/password.js
@@ -1,4 +1,3 @@
-"use strict";
const Promise = require("bluebird");
const SecureHasher = require("../../../utils/secure-hasher.js");
const crypto = require("crypto");
@@ -6,7 +5,7 @@
module.exports = app => ({
name: "password",
extends: "text",
- get_description: function(context, { digits, capitals }) {
+ get_description(context, { digits, capitals }) {
let message = "Stores a password in a correct way";
if (!digits && !capitals) {
return message;
@@ -23,7 +22,7 @@
return message;
},
- is_proper_value: function(context, { digits, capitals }, new_value) {
+ is_proper_value(context, { digits, capitals }, new_value) {
const pattern_array = [];
if (!digits && !capitals) {
return Promise.resolve();
@@ -41,15 +40,14 @@
if (isAccepted) {
return Promise.resolve();
- } else {
- const digits = digits || "0";
- const capitals = capitals || "0";
- return Promise.reject(
- `It didn't fulfill the requirements: required digits - ${digits} , required capitals ${capitals}`
- );
}
+ const requiredDigits = digits || "0";
+ const requiredCapitals = capitals || "0";
+ return Promise.reject(
+ `It didn't fulfill the requirements: required digits - ${requiredDigits} , required capitals ${requiredCapitals}`
+ );
},
- encode: function(context, params, value_in_code) {
+ encode(context, params, value_in_code) {
const hashing_params = Object.assign(
{},
app.ConfigManager.get("password_hash"),
@@ -62,10 +60,10 @@
},
get_aggregation_stages: require("./../../../chip-types/field-type-default-methods.js")
.get_aggregation_stages,
- decode: function(context, params, value_in_db) {
+ decode(context, params, value_in_db) {
return null;
},
- format: function(context, params, decoded_value, format_params) {
+ format(context, params, decoded_value, format_params) {
return decoded_value;
},
});
diff --git a/lib/app/base-chips/field-types/reverse-single-reference.js b/lib/app/base-chips/field-types/reverse-single-reference.js
--- a/lib/app/base-chips/field-types/reverse-single-reference.js
+++ b/lib/app/base-chips/field-types/reverse-single-reference.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
const Errors = locreq("lib/response/error.js");
@@ -62,20 +61,20 @@
return {
name: "reverse-single-reference",
- get_description: function() {
+ get_description() {
return "Shows which resources from given collection point to this resource in a given field.";
},
get_default_value: async () => [],
is_old_value_sensitive: true,
- is_proper_value: function(context, params, new_value) {
+ is_proper_value(context, params, new_value) {
return context.is_super
? Promise.resolve()
: Promise.reject("This is a read-only field");
},
- filter_to_query: async function(context, params, field_filter) {
+ async filter_to_query(context, params, field_filter) {
if (typeof field_filter !== "object") {
return {
$eq: field_filter,
@@ -93,7 +92,7 @@
};
},
- format: function(context, params, decoded_value, format) {
+ format(context, params, decoded_value, format) {
// format can be "expand" or "deep-expand:<depth>", like "deep-expand:3"
if (!format) {
return decoded_value; // just the IDs
diff --git a/lib/app/base-chips/field-types/secret-token.js b/lib/app/base-chips/field-types/secret-token.js
--- a/lib/app/base-chips/field-types/secret-token.js
+++ b/lib/app/base-chips/field-types/secret-token.js
@@ -12,8 +12,7 @@
filter_to_query: (context, params, field_filter) => {
if (context.is_super) {
return { $eq: field_filter };
- } else {
- return { $eq: "nice try" };
}
+ return { $eq: "nice try" };
},
};
diff --git a/lib/app/base-chips/field-types/settable-by.js b/lib/app/base-chips/field-types/settable-by.js
--- a/lib/app/base-chips/field-types/settable-by.js
+++ b/lib/app/base-chips/field-types/settable-by.js
@@ -1,6 +1,6 @@
module.exports = app => ({
name: "settable-by",
- encode: function(context, params, new_value, old_value) {
+ encode(context, params, new_value, old_value) {
return params.target_field_type.encode(
context,
params,
@@ -8,7 +8,7 @@
old_value
);
},
- is_proper_value: async function(
+ async is_proper_value(
context,
{ target_field_type, target_params = {}, access_strategy_description },
new_value,
@@ -26,7 +26,7 @@
old_value
);
},
- format: function(
+ format(
context,
{ target_field_type, target_params },
decode_value,
@@ -39,18 +39,14 @@
format
);
},
- filter_to_query: function(
- context,
- { target_field_type, target_params },
- filter
- ) {
+ filter_to_query(context, { target_field_type, target_params }, filter) {
return target_field_type.filter_to_query(
context,
target_params,
filter
);
},
- get_aggregation_stages: function(
+ get_aggregation_stages(
context,
{ target_field_type, target_params },
field_name,
@@ -65,7 +61,7 @@
query_params
);
},
- has_index: function({ target_field_type, target_params }) {
+ has_index({ target_field_type, target_params }) {
return target_field_type.has_index(target_params);
},
});
diff --git a/lib/app/base-chips/field-types/single_reference.js b/lib/app/base-chips/field-types/single_reference.js
--- a/lib/app/base-chips/field-types/single_reference.js
+++ b/lib/app/base-chips/field-types/single_reference.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Collection = locreq("lib/chip-types/collection.js");
const Promise = require("bluebird");
@@ -7,7 +6,7 @@
return {
name: "single_reference",
has_index: () => 1,
- is_proper_value: function(context, params, new_value) {
+ is_proper_value(context, params, new_value) {
const collection = new Collection(app, params.collection);
const filter = params.filter || {};
if (new_value === "") {
@@ -41,7 +40,7 @@
)
);
},
- encode: function(context, params, value_in_code) {
+ encode(context, params, value_in_code) {
let resource_id;
if (typeof value_in_code === "string") {
resource_id = value_in_code;
@@ -50,7 +49,7 @@
}
return resource_id;
},
- format: function(context, params, decoded_value, format) {
+ format(context, params, decoded_value, format) {
// format can be "expand" or "deep-expand:<depth>", like "deep-expand:3"
if (!format) {
return decoded_value; // just the ID
@@ -90,7 +89,7 @@
{ format: query_format }
);
},
- filter_to_query: async function(context, params, field_filter) {
+ async filter_to_query(context, params, field_filter) {
// treating filter as a query here
if (typeof field_filter !== "object") {
return {
@@ -108,7 +107,7 @@
);
return { $in: resources.map(resource => resource.id) };
},
- get_aggregation_stages: function(
+ get_aggregation_stages(
context,
params,
field_name,
@@ -118,10 +117,10 @@
const collection = new Collection(app, params.collection);
const filter = {};
const temp_field_name =
- collection.name +
- "-" +
- "lookup" +
- Math.floor(Math.random().toString() * Math.pow(10, 7));
+ `${collection.name}-` +
+ `lookup${Math.floor(
+ Math.random().toString() * Math.pow(10, 7)
+ )}`;
const request_filter = query.filter && query.filter[field_name];
if (!request_filter || Object.keys(request_filter).length === 0)
return [];
@@ -143,16 +142,15 @@
let field = collection.fields[field_name];
if (!field)
return Promise.reject(
- "Unknown field in filter for '" +
- collection.name +
- "': " +
- field_name
+ `Unknown field in filter for '${
+ collection.name
+ }': ${field_name}`
);
filter[
`${temp_field_name}.0.${field_name}`
] = field.filter_to_query(context, request_filter[field_name]);
}
- return Promise.props(filter).then(function(_filter) {
+ return Promise.props(filter).then(_filter => {
return [
{
$lookup: {
diff --git a/lib/app/base-chips/field-types/text.js b/lib/app/base-chips/field-types/text.js
--- a/lib/app/base-chips/field-types/text.js
+++ b/lib/app/base-chips/field-types/text.js
@@ -1,20 +1,18 @@
-"use strict";
const Promise = require("bluebird");
const escape = require("escape-html");
module.exports = {
name: "text",
- has_index: function(params) {
+ has_index(params) {
if (params.full_text_search || params.include_in_search) {
return { original: "text" };
- } else {
- return false;
}
+ return false;
},
- get_description: function(context, params) {
+ get_description(context, params) {
return `Text with maximum length ${params.max_length}`;
},
- is_proper_value: function(context, params, new_value) {
+ is_proper_value(context, params, new_value) {
let checks = [];
checks.push(text => {
@@ -50,19 +48,20 @@
Promise.resolve()
);
},
- encode: function(context, params, value_in_code) {
+ encode(context, params, value_in_code) {
if (typeof value_in_code === "string" && value_in_code !== null) {
const result = {
original: value_in_code,
safe: escape(value_in_code),
- valueOf: function() {
+ valueOf() {
return value_in_code;
},
};
return Promise.resolve(result);
- } else return Promise.resolve(null);
+ }
+ return Promise.resolve(null);
},
- get_aggregation_stages: function(
+ get_aggregation_stages(
context,
params,
field_name,
@@ -97,7 +96,7 @@
},
];
},
- format: function(context, params, decoded_value, format) {
+ format(context, params, decoded_value, format) {
if (decoded_value === null || decoded_value === undefined) {
return Promise.resolve(decoded_value);
}
diff --git a/lib/app/base-chips/field-types/username.js b/lib/app/base-chips/field-types/username.js
--- a/lib/app/base-chips/field-types/username.js
+++ b/lib/app/base-chips/field-types/username.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const me_synonyms = locreq("lib/misc/me-synonyms.json");
const SuperContext = locreq("lib/super-context.js");
@@ -7,7 +6,7 @@
return {
name: "username",
extends: "text",
- is_proper_value: async function(context, params, new_value, old_value) {
+ async is_proper_value(context, params, new_value, old_value) {
if (old_value === new_value) {
return;
}
@@ -23,7 +22,7 @@
"show",
{ filter: { username: new_value } }
)
- .then(function({ items }) {
+ .then(({ items }) => {
if (items.length > 0) {
throw new Error("Username already taken");
}
diff --git a/lib/app/base-chips/field-types/value-existing-in-collection.js b/lib/app/base-chips/field-types/value-existing-in-collection.js
--- a/lib/app/base-chips/field-types/value-existing-in-collection.js
+++ b/lib/app/base-chips/field-types/value-existing-in-collection.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const assert = require("assert");
const Promise = require("bluebird");
@@ -6,7 +5,7 @@
module.exports = function(app) {
return {
name: "value-existing-in-collection",
- is_proper_value: async function(context, params, new_value) {
+ async is_proper_value(context, params, new_value) {
assert.equal(typeof params.field, "string");
assert(
typeof params.include_forbidden === "boolean" ||
@@ -37,27 +36,27 @@
);
}
},
- encode: async function(context, params, value_in_code, old_value) {
+ async encode(context, params, value_in_code, old_value) {
return params.collection.fields[params.field].encode(
context,
value_in_code,
old_value
);
},
- format: function(context, params, decoded_value, format) {
+ format(context, params, decoded_value, format) {
return params.collection.fields[params.field].format(
context,
decoded_value,
format
);
},
- filter_to_query: function(context, params, field_filter) {
+ filter_to_query(context, params, field_filter) {
return params.collection.fields[params.field].filter_to_query(
context,
field_filter
);
},
- get_aggregation_stages: function(context, params, field_name, query) {
+ get_aggregation_stages(context, params, field_name, query) {
return params.collection.fields[
params.field
].get_aggregation_stages(context, field_name, query);
diff --git a/lib/app/base-chips/field-types/value-exists-in-collection.js b/lib/app/base-chips/field-types/value-exists-in-collection.js
--- a/lib/app/base-chips/field-types/value-exists-in-collection.js
+++ b/lib/app/base-chips/field-types/value-exists-in-collection.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const assert = require("assert");
const Promise = require("bluebird");
@@ -6,7 +5,7 @@
module.exports = function(app) {
return {
name: "value-exists-in-collection",
- is_proper_value: async function(context, params, new_value) {
+ async is_proper_value(context, params, new_value) {
assert.equal(typeof params.field, "string");
assert(
typeof params.include_forbidden === "boolean" ||
@@ -29,35 +28,32 @@
);
if (matches.length) {
return Promise.resolve();
- } else {
- return Promise.reject(
- `No ${collection.name} with ${
- params.field
- } set to ${new_value}`
- );
}
+ return Promise.reject(
+ `No ${collection.name} with ${params.field} set to ${new_value}`
+ );
},
- encode: async function(context, params, value_in_code, old_value) {
+ async encode(context, params, value_in_code, old_value) {
return params.collection.fields[params.field].encode(
context,
value_in_code,
old_value
);
},
- format: function(context, params, decoded_value, format) {
+ format(context, params, decoded_value, format) {
return params.collection.fields[params.field].format(
context,
decoded_value,
format
);
},
- filter_to_query: function(context, params, field_filter) {
+ filter_to_query(context, params, field_filter) {
return params.collection.fields[params.field].filter_to_query(
context,
field_filter
);
},
- get_aggregation_stages: function(context, params, field_name, query) {
+ get_aggregation_stages(context, params, field_name, query) {
return params.collection.fields[
params.field
].get_aggregation_stages(context, field_name, query);
diff --git a/lib/app/chip-manager.js b/lib/app/chip-manager.js
--- a/lib/app/chip-manager.js
+++ b/lib/app/chip-manager.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
const Errors = locreq("lib/response/error.js");
@@ -16,7 +15,7 @@
];
ChipManager.pure = {
- start_chips: function(app, chips) {
+ start_chips(app, chips) {
const promises = [];
const datastore = ChipManager.pure.get_datastore_chip(app, chips);
@@ -41,7 +40,7 @@
}
return Promise.all(promises);
},
- add_chip: function(chips, type, name, chip) {
+ add_chip(chips, type, name, chip) {
if (chips[type] === undefined) {
chips[type] = [];
}
@@ -49,14 +48,14 @@
throw Error(`Chip '${type}.${name}' already exists!`);
chips[type][name] = chip;
},
- get_all_collections: function(chips) {
+ get_all_collections(chips) {
const names = [];
for (const collection in chips.collection) {
names.push(collection);
}
return names;
},
- get_chip: function(chips, type, name) {
+ get_chip(chips, type, name) {
try {
const ret = chips[type][name];
if (ret === undefined) {
@@ -73,17 +72,16 @@
);
}
},
- get_chip_amount_by_type: function(chips, type) {
+ get_chip_amount_by_type(chips, type) {
if (chips[type]) {
return Object.keys(chips[type]).length;
- } else {
- return 0;
}
+ return 0;
},
- get_datastore_chip: function(app, chips) {
+ get_datastore_chip(app, chips) {
return app.Datastore;
},
- get_chips_by_type: function(chips, chip_type) {
+ get_chips_by_type(chips, chip_type) {
return chips[chip_type];
},
};
diff --git a/lib/app/file-manager.js b/lib/app/file-manager.js
--- a/lib/app/file-manager.js
+++ b/lib/app/file-manager.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
const UUIDGenerator = require("shortid");
@@ -18,14 +17,14 @@
}
FileManager.pure = {
- save_file: function(datastore, upload_path, file) {
+ save_file(datastore, upload_path, file) {
const newID = UUIDGenerator();
const upload_path_with_sealious_name = `${upload_path}/${newID}`;
return Promise.promisify(fs.writeFile)(
upload_path_with_sealious_name,
file.data
)
- .then(function() {
+ .then(() => {
const file_database_entry = {
original_name: file.filename,
creation_context: file.context,
@@ -34,16 +33,16 @@
};
return datastore.insert("files", file_database_entry, {});
})
- .then(function() {
+ .then(() => {
return {
id: newID,
filename: file.filename,
};
});
},
- find: function(datastore, upload_path, context, query) {
- return datastore.find("files", query).then(function(documents) {
- const parsed_documents = documents.map(function(document) {
+ find(datastore, upload_path, context, query) {
+ return datastore.find("files", query).then(documents => {
+ const parsed_documents = documents.map(document => {
const ret = File.from_db_entry(document);
ret.path_on_hdd = path.resolve(upload_path, `./${ret.id}`);
return ret;
@@ -51,10 +50,10 @@
return Promise.resolve(parsed_documents);
});
},
- get_by_id: function(datastore, upload_path, context, file_id) {
+ get_by_id(datastore, upload_path, context, file_id) {
return FileManager.pure
.find(datastore, upload_path, context, { id: file_id })
- .then(function(file_array) {
+ .then(file_array => {
return Promise.resolve(file_array[0]);
});
},
diff --git a/lib/app/load-base-chips.js b/lib/app/load-base-chips.js
--- a/lib/app/load-base-chips.js
+++ b/lib/app/load-base-chips.js
@@ -1,5 +1,3 @@
-"use strict";
-
const locreq = require("locreq")(__dirname);
const AccessStrategyType = locreq("lib/chip-types/access-strategy-type.js");
@@ -77,7 +75,7 @@
BaseChipDirs.set(Collection, "collections");
const to_load = [];
-BaseChips.forEach(function(names, constructor) {
+BaseChips.forEach((names, constructor) => {
for (const i in names) {
const chip_name = names[i];
let declaration = locreq(
diff --git a/lib/app/logger.js b/lib/app/logger.js
--- a/lib/app/logger.js
+++ b/lib/app/logger.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const winston = require("winston");
const { getTimeDifference } = locreq("lib/utils/get-datetime.js");
@@ -54,7 +53,7 @@
transports: transports_array,
});
- logger.rewriters.push(function(level, msg, meta) {
+ logger.rewriters.push((level, msg, meta) => {
let ret = "";
if (Object.keys(meta).length) {
let message = "\n";
diff --git a/lib/app/metadata.js b/lib/app/metadata.js
--- a/lib/app/metadata.js
+++ b/lib/app/metadata.js
@@ -6,17 +6,16 @@
const matches = await app.Datastore.find(COLLECTION_NAME, { key });
if (matches.length) {
return matches[0].value;
- } else {
- undefined;
}
+ undefined;
},
async set(key, value) {
const matches = await app.Datastore.find(COLLECTION_NAME, { key });
if (matches.length) {
await app.Datastore.update(
COLLECTION_NAME,
- { key: key },
- { $set: { value: value } }
+ { key },
+ { $set: { value } }
);
} else {
await app.Datastore.insert(COLLECTION_NAME, { key, value });
diff --git a/lib/app/run-action-curry.js b/lib/app/run-action-curry.js
--- a/lib/app/run-action-curry.js
+++ b/lib/app/run-action-curry.js
@@ -1,4 +1,3 @@
-"use strict";
const assert = require("assert");
const locreq = require("locreq")(__dirname);
@@ -33,7 +32,7 @@
}
let subject = null;
const promise = app.RootSubject.get_subject(subject_path)
- .then(function(_subject) {
+ .then(_subject => {
subject = _subject;
return app.emit(
{
diff --git a/lib/chip-types/access-strategy-type.js b/lib/chip-types/access-strategy-type.js
--- a/lib/chip-types/access-strategy-type.js
+++ b/lib/chip-types/access-strategy-type.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
const Errors = locreq("lib/response/error.js");
@@ -25,56 +24,51 @@
AccessStrategyType.type_name = "access_strategy_type";
AccessStrategyType.pure = {
- check: function(declaration, context, params, item) {
+ check(declaration, context, params, item) {
if (context.is_super) {
return Promise.resolve();
}
return AccessStrategyType.pure
.is_item_sensitive(declaration, params)
- .then(function(is_item_sensitive) {
+ .then(is_item_sensitive => {
if (is_item_sensitive && item === undefined) {
return Promise.resolve(undefined);
- } else {
- return Promise.try(function() {
- return Promise.method(declaration.checker_function)(
- context,
- params,
- item
- ).then(function(result) {
- if (result === false) {
- return Promise.reject("Access denied");
- } else {
- return Promise.resolve(result);
- }
- });
- });
}
+ return Promise.try(() => {
+ return Promise.method(declaration.checker_function)(
+ context,
+ params,
+ item
+ ).then(result => {
+ if (result === false) {
+ return Promise.reject("Access denied");
+ }
+ return Promise.resolve(result);
+ });
+ });
})
- .catch(function(error) {
+ .catch(error => {
if (typeof error === "string") {
return Promise.reject(new Errors.BadContext(error));
- } else {
- return Promise.reject(error);
}
+ return Promise.reject(error);
});
},
- is_item_sensitive: function(declaration, params) {
+ is_item_sensitive(declaration, params) {
if (typeof declaration.item_sensitive === "function") {
return Promise.resolve(declaration.item_sensitive(params));
- } else {
- return Promise.resolve(Boolean(declaration.item_sensitive));
}
+ return Promise.resolve(Boolean(declaration.item_sensitive));
},
- getRestrictingQuery: function(declaration, context, params) {
+ getRestrictingQuery(declaration, context, params) {
if (declaration.getRestrictingQuery) {
return Promise.resolve(
declaration.getRestrictingQuery(context, params)
).then(result => {
return result;
});
- } else {
- return Promise.resolve([]);
}
+ return Promise.resolve([]);
},
};
diff --git a/lib/chip-types/access-strategy.js b/lib/chip-types/access-strategy.js
--- a/lib/chip-types/access-strategy.js
+++ b/lib/chip-types/access-strategy.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
const AccessStrategyType = locreq("lib/chip-types/access-strategy-type.js");
diff --git a/lib/chip-types/aggregated-field.js b/lib/chip-types/aggregated-field.js
--- a/lib/chip-types/aggregated-field.js
+++ b/lib/chip-types/aggregated-field.js
@@ -8,12 +8,11 @@
AggregatedField.prototype.get_aggregation_stages = function(context, item) {
const self = this;
return Promise.all(
- self.aggregations.map(function(e) {
+ self.aggregations.map(e => {
if (e instanceof Function) {
return e(context, item);
- } else {
- return e;
}
+ return e;
})
);
};
diff --git a/lib/chip-types/calculated-field-type.js b/lib/chip-types/calculated-field-type.js
--- a/lib/chip-types/calculated-field-type.js
+++ b/lib/chip-types/calculated-field-type.js
@@ -12,7 +12,7 @@
CalculatedFieldType.type_name = "calculated_field_type";
CalculatedFieldType.pure = {
- get_value: function(declaration, context, params, item, db_document) {
+ get_value(declaration, context, params, item, db_document) {
return Promise.resolve(
declaration.calculate(context, params, item, db_document)
);
@@ -31,7 +31,7 @@
const pure = CalculatedFieldType.pure;
CalculatedFieldType.prototype = {
- get_value: function(context, params, item, raw_db_entry) {
+ get_value(context, params, item, raw_db_entry) {
return pure.get_value(
this.declaration,
context,
diff --git a/lib/chip-types/channel.js b/lib/chip-types/channel.js
--- a/lib/chip-types/channel.js
+++ b/lib/chip-types/channel.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const channel = function(app, declaration) {
diff --git a/lib/chip-types/chip.js b/lib/chip-types/chip.js
--- a/lib/chip-types/chip.js
+++ b/lib/chip-types/chip.js
@@ -1,4 +1,3 @@
-"use strict";
const Promise = require("bluebird");
let ChipManager;
diff --git a/lib/chip-types/collection.js b/lib/chip-types/collection.js
--- a/lib/chip-types/collection.js
+++ b/lib/chip-types/collection.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
const assert = require("assert");
@@ -73,13 +72,7 @@
Collection.type_name = "collection";
Collection.pure = {
- add_field: function(
- app,
- field_type,
- fields,
- field_declaration,
- collection
- ) {
+ add_field(app, field_type, fields, field_declaration, collection) {
const field_object = new Field(
app,
field_declaration,
@@ -97,13 +90,13 @@
);
}
},
- add_fields: function(app, field_type, fields, field_declarations_array) {
+ add_fields(app, field_type, fields, field_declarations_array) {
for (const i in field_declarations_array) {
const declaration = field_declarations_array[i];
Collection.pure.add_field(app, field_type, fields, declaration);
}
},
- add_calculated_field: function(
+ add_calculated_field(
app,
collection,
calc_field_name,
@@ -120,7 +113,7 @@
add_special_filters(Collection, named_filters) {
Collection.named_filters = named_filters;
},
- get_unknown_field_errors: function(field_type_name, fields, values) {
+ get_unknown_field_errors(field_type_name, fields, values) {
const validation_errors = {};
for (const field_name in values) {
if (fields[field_name] === undefined) {
@@ -131,7 +124,7 @@
}
return validation_errors;
},
- get_missing_values_checker: function(
+ get_missing_values_checker(
fields,
values,
assume_delete_value_on_missing_key,
@@ -144,17 +137,16 @@
values[field_name] === undefined
);
};
- } else {
- return function(field_name) {
- return (
- fields[field_name].required &&
- values[field_name] === undefined &&
- old_values[field_name] === undefined
- );
- };
}
+ return function(field_name) {
+ return (
+ fields[field_name].required &&
+ values[field_name] === undefined &&
+ old_values[field_name] === undefined
+ );
+ };
},
- get_missing_field_values_errors: function(
+ get_missing_field_values_errors(
fields,
values,
assume_delete_value_on_missing_key,
@@ -169,21 +161,16 @@
);
return Promise.filter(Object.keys(fields), checker_fn)
- .each(function(field_name) {
+ .each(field_name => {
errors[field_name] = new Errors.ValidationError(
`Missing value for field '${field_name}'`
);
})
- .then(function() {
+ .then(() => {
return errors;
});
},
- get_invalid_field_values_errors: function(
- fields,
- context,
- values,
- old_values
- ) {
+ get_invalid_field_values_errors(fields, context, values, old_values) {
const errors = {};
const promises = [];
for (const field_name in values) {
@@ -195,7 +182,7 @@
: undefined;
const promise = fields[field_name]
.is_proper_value(context, value, old_value)
- .catch(function(error) {
+ .catch(error => {
if (
typeof error === "string" ||
error.type === "validation"
@@ -210,11 +197,11 @@
promises.push(promise);
}
}
- return Promise.all(promises).then(function() {
+ return Promise.all(promises).then(() => {
return errors;
});
},
- get_missing_required_field_values: function(fields, new_values) {
+ get_missing_required_field_values(fields, new_values) {
const errors = {};
for (const field_name in new_values) {
if (
@@ -229,7 +216,7 @@
}
return errors;
},
- validate_field_values: function(
+ validate_field_values(
field_type_name,
fields,
context,
@@ -263,7 +250,7 @@
return Promise.all(errors_array)
.reduce(merge)
- .then(function(errors) {
+ .then(errors => {
const user_errors = {};
const non_user_errors = {};
for (const field_name in errors) {
@@ -288,7 +275,7 @@
}
});
},
- encode_field_values: async function(fields, context, body, old_body) {
+ async encode_field_values(fields, context, body, old_body) {
const promises = {};
for (let field_name in fields) {
const field = fields[field_name];
@@ -316,7 +303,7 @@
}
return Promise.props(promises);
},
- get_specification: function(
+ get_specification(
name,
human_readable_name,
summary,
@@ -333,14 +320,14 @@
}
const specification = {
- name: name,
- human_readable_name: human_readable_name,
- summary: summary,
+ name,
+ human_readable_name,
+ summary,
fields: collection_specification,
};
return specification;
},
- set_access_strategy: function(app, collection, strategy_declaration) {
+ set_access_strategy(app, collection, strategy_declaration) {
if (
typeof strategy_declaration === "string" ||
strategy_declaration instanceof AccessStrategyType ||
@@ -359,12 +346,12 @@
}
}
},
- get_access_strategy: function(access_strategy_map, action_name) {
+ get_access_strategy(access_strategy_map, action_name) {
const ret =
- access_strategy_map[action_name] || access_strategy_map["default"];
+ access_strategy_map[action_name] || access_strategy_map.default;
return ret;
},
- has_large_data_fields: function(fields) {
+ has_large_data_fields(fields) {
for (const i in fields) {
const field = fields[i];
if (field.type.handles_large_data) {
@@ -373,7 +360,7 @@
}
return false;
},
- is_old_value_sensitive: function(fields, action_name) {
+ is_old_value_sensitive(fields, action_name) {
for (const i in fields) {
if (fields[i].type.is_old_value_sensitive(action_name)) {
return true;
@@ -381,7 +368,7 @@
}
return false;
},
- decode_values: function(fields, context, values) {
+ decode_values(fields, context, values) {
const decoded_values = {};
for (const key in fields) {
const value = values[key];
@@ -393,7 +380,7 @@
}
return Promise.props(decoded_values);
},
- format_decoded_values: function(fields, context, decoded_values, format) {
+ format_decoded_values(fields, context, decoded_values, format) {
const formatted_values = clone(decoded_values);
for (const field_name in formatted_values) {
const field_format = format[field_name] || undefined;
@@ -406,7 +393,7 @@
}
return Promise.props(formatted_values);
},
- _get_body: async function(fields, context, db_document, format) {
+ async _get_body(fields, context, db_document, format) {
const decoded_values = await Collection.pure.decode_values(
fields,
context,
@@ -419,7 +406,7 @@
format || {}
);
},
- _get_calculated_fields: function(
+ _get_calculated_fields(
context,
calculated_fields,
representation,
@@ -438,7 +425,7 @@
}
return Promise.props(ret);
},
- get_resource_representation: async function(
+ async get_resource_representation(
fields,
field_type_name,
context,
@@ -468,7 +455,7 @@
}
return representation;
},
- check_if_action_is_allowed: function(
+ check_if_action_is_allowed(
access_strategy_map,
context,
action_name,
@@ -481,11 +468,11 @@
return access_strategy
.check(context, resource_representation)
- .then(function(results) {
+ .then(results => {
return results;
});
},
- get_aggregation_stages: function(
+ get_aggregation_stages(
collection,
context,
action_name,
@@ -572,13 +559,13 @@
type_params
);
},
- add_special_filters: function(named_filters = []) {
+ add_special_filters(named_filters = []) {
return pure.add_special_filters(this, named_filters);
},
- get_named_filter: function(filter_name) {
+ get_named_filter(filter_name) {
return this.named_filters[filter_name];
},
- add_named_filter: function(filter_name, filter) {
+ add_named_filter(filter_name, filter) {
this.named_filters[filter_name] = filter;
},
validate_field_values(
diff --git a/lib/chip-types/datastore.js b/lib/chip-types/datastore.js
--- a/lib/chip-types/datastore.js
+++ b/lib/chip-types/datastore.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const assert = require("assert");
const Chip = require("./chip.js");
@@ -40,7 +39,7 @@
const test_collection_name = "_test";
return Promise.resolve()
- .then(function() {
+ .then(() => {
// .insert method should respond with the created document
const to_insert = {
value: 1,
@@ -48,7 +47,7 @@
};
return self
.insert(test_collection_name, to_insert)
- .then(function(response) {
+ .then(response => {
assert.deepEqual(
to_insert,
response,
@@ -57,22 +56,18 @@
return Promise.resolve();
});
})
- .then(function() {
+ .then(() => {
// check if find resolves with an array
- return self
- .find(test_collection_name, {}, {})
- .then(function(documents) {
- assert(
- documents instanceof Array,
- `datastore.${
- self.name
- }.find should resolve with an array`
- );
- return Promise.resolve();
- });
+ return self.find(test_collection_name, {}, {}).then(documents => {
+ assert(
+ documents instanceof Array,
+ `datastore.${self.name}.find should resolve with an array`
+ );
+ return Promise.resolve();
+ });
})
- .then(function() {
+ .then(() => {
// check if amount of created documents checks out
const creates = [
self.insert(test_collection_name, {
@@ -91,10 +86,10 @@
const created_so_far = 4;
return Promise.all(creates)
- .then(function() {
+ .then(() => {
return self.find(test_collection_name, {}, {});
})
- .then(function(documents) {
+ .then(documents => {
assert(
documents.length === created_so_far,
`Inserted ${created_so_far} documents so far, but ${
@@ -104,7 +99,7 @@
return Promise.resolve(created_so_far);
});
})
- .then(function(created_so_far) {
+ .then(created_so_far => {
// check if there is a proper amount of documents with random value set to rand
const documents_with_rand = created_so_far - 1;
return self
@@ -115,7 +110,7 @@
},
{}
)
- .then(function(documents) {
+ .then(documents => {
assert(
documents.length === documents_with_rand,
`Inserted ${documents_with_rand} documents with "random" set to "${rand}" so far, but ${
@@ -125,7 +120,7 @@
return Promise.resolve();
});
})
- .then(function() {
+ .then(() => {
// Should store a complex object
const complex_object = {
id: "aseoifaoeina",
@@ -136,7 +131,7 @@
};
return self
.insert(test_collection_name, complex_object)
- .then(function(response) {
+ .then(response => {
assert.deepEqual(
complex_object,
response,
@@ -146,7 +141,7 @@
id: complex_object.id,
});
})
- .then(function(response) {
+ .then(response => {
assert.deepEqual(
complex_object,
response[0],
@@ -155,13 +150,13 @@
return Promise.resolve(complex_object);
});
})
- .then(function(complex_object) {
+ .then(complex_object => {
// Should handle dot-notation nested queries
return self
.find(test_collection_name, {
name: complex_object.name,
})
- .then(function(response) {
+ .then(response => {
assert.deepEqual(
complex_object,
response[0],
@@ -170,14 +165,14 @@
return Promise.resolve(complex_object);
});
})
- .then(function(complex_object) {
+ .then(complex_object => {
return self
.find(test_collection_name, {
body: {
name: complex_object.name,
},
})
- .then(function(response) {
+ .then(response => {
assert.deepEqual(
complex_object,
response[0],
@@ -186,7 +181,7 @@
return Promise.resolve(complex_object);
});
})
- .then(function(complex_object) {
+ .then(complex_object => {
// .update should modify document values with dot notation
complex_object.name = "Hanna";
return self
@@ -199,12 +194,12 @@
name: complex_object.name,
}
)
- .then(function() {
+ .then(() => {
return self.find(test_collection_name, {
id: complex_object.id,
});
})
- .then(function(results) {
+ .then(results => {
assert.deepEqual(
complex_object,
results[0],
@@ -213,7 +208,7 @@
return Promise.resolve(complex_object);
});
})
- .then(function(complex_object) {
+ .then(complex_object => {
// .update should modify document values using nested object as a query
complex_object.name = "Marzanna";
return self
@@ -228,12 +223,12 @@
},
}
)
- .then(function() {
+ .then(() => {
return self.find(test_collection_name, {
id: complex_object.id,
});
})
- .then(function(results) {
+ .then(results => {
assert.deepEqual(
complex_object,
results[0],
@@ -242,7 +237,7 @@
return Promise.resolve(complex_object);
});
})
- .then(function(complex_object) {
+ .then(complex_object => {
// .update should insert new value to a field that previously had no value (undefined)
complex_object.other = "Focca";
return self
@@ -257,12 +252,12 @@
},
}
)
- .then(function() {
+ .then(() => {
return self.find(test_collection_name, {
id: complex_object.id,
});
})
- .then(function(results) {
+ .then(results => {
assert.deepEqual(
complex_object,
results[0],
@@ -271,14 +266,14 @@
return Promise.resolve(complex_object);
});
})
- .then(function(complex_object) {
+ .then(complex_object => {
// .remove should remove only one document when "just_one" is set to true
return Promise.all([
self.insert(test_collection_name, complex_object),
self.insert(test_collection_name, complex_object),
self.insert(test_collection_name, complex_object),
])
- .then(function() {
+ .then(() => {
// all the "complex_object" documents have the same id
return self.remove(
test_collection_name,
@@ -288,12 +283,12 @@
true
);
})
- .then(function() {
+ .then(() => {
return self.find(test_collection_name, {
id: complex_object.id,
});
})
- .then(function(results) {
+ .then(results => {
assert(
results.length === 3,
".remove should remove only *one* document when `just_one` argument is set to true"
@@ -301,14 +296,14 @@
return Promise.resolve(complex_object);
});
})
- .then(function(complex_object) {
+ .then(complex_object => {
// .remove should remove all matching documents when "just_one" is falsy
return Promise.all([
self.insert(test_collection_name, complex_object),
self.insert(test_collection_name, complex_object),
self.insert(test_collection_name, complex_object),
])
- .then(function() {
+ .then(() => {
// all the "complex_object" documents have the same id
return self.remove(
test_collection_name,
@@ -318,12 +313,12 @@
false
);
})
- .then(function() {
+ .then(() => {
return self.find(test_collection_name, {
id: complex_object.id,
});
})
- .then(function(results) {
+ .then(results => {
assert(
results.length === 0,
".remove should remove all matching documents when 'just_one' is falsy"
@@ -331,10 +326,10 @@
return Promise.resolve(complex_object);
});
})
- .then(function() {
+ .then(() => {
self.clear_collection(test_collection_name);
})
- .catch(function() {
+ .catch(() => {
self.clear_collection(test_collection_name);
return Promise.reject("Compatibility test unsuccesfull");
});
diff --git a/lib/chip-types/field-structures.js b/lib/chip-types/field-structures.js
--- a/lib/chip-types/field-structures.js
+++ b/lib/chip-types/field-structures.js
@@ -1,4 +1,3 @@
-"use strict";
const FieldStructures = {
single: require("./field-structures/single.js"),
};
diff --git a/lib/chip-types/field-type-default-methods.js b/lib/chip-types/field-type-default-methods.js
--- a/lib/chip-types/field-type-default-methods.js
+++ b/lib/chip-types/field-type-default-methods.js
@@ -1,44 +1,43 @@
-"use strict";
const Promise = require("bluebird");
const expandHash = require("expand-hash");
const FieldTypeDescription = require("../data-structures/field-type-description.js");
const default_methods = {
- init: function() {
+ init() {
return null;
},
- has_index: function(params) {
+ has_index(params) {
return false;
},
- is_proper_value: function(context, params, new_value, old_value) {
+ is_proper_value(context, params, new_value, old_value) {
return Promise.resolve();
},
- format: function(context, params, decoded_value, format_params) {
+ format(context, params, decoded_value, format_params) {
return decoded_value;
},
- encode: function(context, params, value_in_code) {
+ encode(context, params, value_in_code) {
return value_in_code;
},
- get_description: function(context, params) {
+ get_description(context, params) {
return new FieldTypeDescription(this.name);
},
- decode: function(context, params, value_in_database) {
+ decode(context, params, value_in_database) {
return value_in_database;
},
- filter_to_query: function(context, params, query) {
+ filter_to_query(context, params, query) {
return Promise.resolve(this.encode(context, params, query)).then(
- function(encoded_value) {
+ encoded_value => {
return {
$eq: encoded_value,
};
}
);
},
- full_text_search_enabled: function() {
+ full_text_search_enabled() {
return false;
},
- get_aggregation_stages: async function(
+ async get_aggregation_stages(
context,
params,
field_name,
@@ -64,7 +63,7 @@
let new_filter = null;
if (field_filter instanceof Array) {
new_filter = await Promise.all(
- field_filter.map(function(element) {
+ field_filter.map(element => {
return self.encode(context, params, element);
})
).then(filters => {
diff --git a/lib/chip-types/field-type.js b/lib/chip-types/field-type.js
--- a/lib/chip-types/field-type.js
+++ b/lib/chip-types/field-type.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
diff --git a/lib/chip-types/field.js b/lib/chip-types/field.js
--- a/lib/chip-types/field.js
+++ b/lib/chip-types/field.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const default_methods = require("./field-type-default-methods.js");
const FieldType = locreq("lib/chip-types/field-type.js");
diff --git a/lib/context.js b/lib/context.js
--- a/lib/context.js
+++ b/lib/context.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const promisify = require("bluebird-events");
const EventEmitter = require("events");
@@ -70,19 +69,18 @@
const c = new SuperContext(self);
return app
.run_action(c, ["collections", "users", this.user_id], "show")
- .then(function(user_data) {
+ .then(user_data => {
self._cached_user_data = user_data;
self.loading_user_data = false;
self.e.emit("loaded_user_data", user_data);
return user_data;
})
- .catch(function(error) {
+ .catch(error => {
self.e.emit("error");
throw error;
});
- } else {
- return Promise.resolve(self._cached_user_data);
}
+ return Promise.resolve(self._cached_user_data);
};
module.exports = Context;
diff --git a/lib/data-structures/field-type-description.js b/lib/data-structures/field-type-description.js
--- a/lib/data-structures/field-type-description.js
+++ b/lib/data-structures/field-type-description.js
@@ -1,6 +1,3 @@
-"use strict";
-"use strict";
-
const FieldTypeDescription = function(summary, raw_params, extra_info) {
this.summary = summary;
this.raw_params = raw_params;
diff --git a/lib/data-structures/file.js b/lib/data-structures/file.js
--- a/lib/data-structures/file.js
+++ b/lib/data-structures/file.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const mime = require("mime-types");
diff --git a/lib/data-structures/subject-path.js b/lib/data-structures/subject-path.js
--- a/lib/data-structures/subject-path.js
+++ b/lib/data-structures/subject-path.js
@@ -1,5 +1,3 @@
-"use strict";
-
const clone = require("clone");
const SubjectPath = function(subject_path) {
diff --git a/lib/data-structures/virtual-file.js b/lib/data-structures/virtual-file.js
--- a/lib/data-structures/virtual-file.js
+++ b/lib/data-structures/virtual-file.js
@@ -1,6 +1,3 @@
-"use strict";
-"use strict";
-
const VirtualFile = function(content, mime) {
this.content = content;
this.mime = mime || "text/plain";
diff --git a/lib/datastore/db.js b/lib/datastore/db.js
--- a/lib/datastore/db.js
+++ b/lib/datastore/db.js
@@ -1,33 +1,29 @@
-"use strict";
-var Promise = require("bluebird");
-var MongoClient = require("mongodb").MongoClient;
-var DbsCommonPart = require("./mongo-api-abstract");
+const Promise = require("bluebird");
+const MongoClient = require("mongodb").MongoClient;
+const DbsCommonPart = require("./mongo-api-abstract");
module.exports = function(App) {
const priv = { db: null };
let client = null;
- var DatastoreMongo = App.createChip(App.Sealious.Datastore, {
+ const DatastoreMongo = App.createChip(App.Sealious.Datastore, {
name: "mongo",
});
DatastoreMongo.start = function() {
- var self = this;
- var config = App.ConfigManager.get("datastore_mongo");
+ const self = this;
+ const config = App.ConfigManager.get("datastore_mongo");
- var url = `mongodb://${config.host}:${config.port}/${config.db_name}`;
- return Promise.promisify(MongoClient.connect)(url).then(function(
- _client
- ) {
+ const url = `mongodb://${config.host}:${config.port}/${config.db_name}`;
+ return Promise.promisify(MongoClient.connect)(url).then(_client => {
if (_client === null) {
return Promise.reject(
"MongoDB was not found, please make sure it's installed. Check https://docs.mongodb.org/manual/tutorial/ for more info."
);
- } else {
- client = _client;
- priv.db = _client.db(config.db_name);
- return self.post_start();
}
+ client = _client;
+ priv.db = _client.db(config.db_name);
+ return self.post_start();
});
};
diff --git a/lib/datastore/mongo-api-abstract.js b/lib/datastore/mongo-api-abstract.js
--- a/lib/datastore/mongo-api-abstract.js
+++ b/lib/datastore/mongo-api-abstract.js
@@ -1,5 +1,4 @@
-"use strict";
-var Promise = require("bluebird");
+const Promise = require("bluebird");
const merge = require("merge");
function createIndex(db_collection, index) {
@@ -9,16 +8,16 @@
);
}
-var DatabasesCommonPart = function(app, datastore, _private) {
+const DatabasesCommonPart = function(app, datastore, _private) {
datastore.post_start = function() {
datastore.client = _private.db;
const collection_names = app.ChipManager.get_all_collections();
const collections = collection_names.map(name =>
app.ChipManager.get_chip("collection", name)
);
- return Promise.map(collections, function(collection) {
- let indexes = [["sealious_id", 1]];
- for (var field_name in collection.fields) {
+ return Promise.map(collections, collection => {
+ const indexes = [["sealious_id", 1]];
+ for (const field_name in collection.fields) {
indexes.push(
Promise.all([
field_name,
@@ -28,19 +27,18 @@
}
const db_collection = _private.db.collection(collection.name);
return Promise.all(indexes)
- .then(function(collection_indexes) {
+ .then(collection_indexes => {
const all_indexes = collection_indexes
.filter(e => e[1] !== false)
- .map(function(index) {
+ .map(index => {
if (index[1] instanceof Object) {
const ret = [];
for (const i in index[1]) {
- ret.push([index[0] + "." + i, index[1][i]]);
+ ret.push([`${index[0]}.${i}`, index[1][i]]);
}
return ret;
- } else {
- return [index];
}
+ return [index];
})
.reduce((a, b) => a.concat(b), []);
@@ -60,7 +58,7 @@
{}
),
];
- if (Object.keys(text_indexes[0]).length == 0) {
+ if (!Object.keys(text_indexes[0]).length) {
text_indexes = [];
}
@@ -70,10 +68,10 @@
return merged_indexes;
})
- .each(function(index) {
+ .each(index => {
return createIndex(db_collection, index).catch(
- e => e.code == 85,
- function(error) {
+ e => e.code === 85,
+ error => {
const index_name = error.message
.match(/name: \"([^\"]+)\"/g)[1]
.replace('name: "', "")
@@ -91,23 +89,21 @@
if (!query) {
return {};
}
- var new_query = {};
- for (var attribute_name in query) {
- if (attribute_name == "sealious_id") {
+ let new_query = {};
+ for (let attribute_name in query) {
+ if (attribute_name === "sealious_id") {
new_query[attribute_name] = query[attribute_name];
- } else {
- if (query[attribute_name] instanceof Object) {
- if (attribute_name[0] === "$") {
- new_query[attribute_name] = query[attribute_name];
- } else {
- for (var i in query[attribute_name]) {
- new_query[attribute_name + "." + i] =
- query[attribute_name][i];
- }
- }
- } else {
+ } else if (query[attribute_name] instanceof Object) {
+ if (attribute_name[0] === "$") {
new_query[attribute_name] = query[attribute_name];
+ } else {
+ for (let i in query[attribute_name]) {
+ new_query[`${attribute_name}.${i}`] =
+ query[attribute_name][i];
+ }
}
+ } else {
+ new_query[attribute_name] = query[attribute_name];
}
}
return new_query;
@@ -118,7 +114,7 @@
//query = process_query(query); // - needed, ResourceCollection subject handles that now
options = options || {};
output_options = output_options || {};
- var cursor = _private.db
+ let cursor = _private.db
.collection(collection_name)
.find(query, options);
if (output_options.sort) {
@@ -162,17 +158,17 @@
datastore.insert = function(collection_name, to_insert, options) {
return Promise.promisify(_private.db.collection(collection_name).insert)
.bind(_private.db.collection(collection_name))(to_insert, options)
- .then(function(result) {
+ .then(result => {
return result.ops[0];
});
};
datastore.update = function(collection_name, query, new_value) {
query = process_query(query);
- return new Promise(function(resolve, reject) {
+ return new Promise((resolve, reject) => {
_private.db
.collection(collection_name)
- .update(query, new_value, function(err, WriteResult) {
+ .update(query, new_value, (err, WriteResult) => {
if (err) {
reject(err);
} else {
@@ -184,14 +180,14 @@
datastore.remove = function(collection_name, query, just_one) {
query = process_query(query);
- return new Promise(function(resolve, reject) {
+ return new Promise((resolve, reject) => {
if (just_one === undefined) {
just_one = 0;
}
just_one = just_one ? 1 : 0;
_private.db
.collection(collection_name)
- .remove(query, just_one, function(err, delete_response) {
+ .remove(query, just_one, (err, delete_response) => {
if (err) {
reject(err);
} else {
diff --git a/lib/datastore/negate_stage.js b/lib/datastore/negate_stage.js
--- a/lib/datastore/negate_stage.js
+++ b/lib/datastore/negate_stage.js
@@ -9,12 +9,10 @@
negated_stage.$or = stage[key].map(expression =>
negate_stage(expression)
);
+ } else if (stage[key].$not) {
+ negated_stage[key] = stage[key].$not;
} else {
- if (stage[key].$not) {
- negated_stage[key] = stage[key].$not;
- } else {
- negated_stage[key] = { $not: stage[key] };
- }
+ negated_stage[key] = { $not: stage[key] };
}
}
return negated_stage;
diff --git a/lib/datastore/query-step.js b/lib/datastore/query-step.js
--- a/lib/datastore/query-step.js
+++ b/lib/datastore/query-step.js
@@ -18,7 +18,7 @@
field => new QueryStep.Match({ [field]: stage.$match[field] })
);
}
- throw new Error("Unsupported stage: " + JSON.stringify(stage));
+ throw new Error(`Unsupported stage: ${JSON.stringify(stage)}`);
}
pushDump(dumps) {
dumps.push(this.body);
@@ -52,7 +52,7 @@
pushStage(pipeline) {
pipeline.push({ $lookup: this.body });
if (this.unwind) {
- pipeline.push({ $unwind: "$" + this.body.as });
+ pipeline.push({ $unwind: `$${this.body.as}` });
}
return pipeline;
}
diff --git a/lib/datastore/query.js b/lib/datastore/query.js
--- a/lib/datastore/query.js
+++ b/lib/datastore/query.js
@@ -1,5 +1,3 @@
-"use strict";
-
const object_hash = require("object-hash");
const QueryStep = require("./query-step.js");
const transformObject = require("../utils/transform-object.js");
diff --git a/lib/datastore/query.test.js b/lib/datastore/query.test.js
--- a/lib/datastore/query.test.js
+++ b/lib/datastore/query.test.js
@@ -55,7 +55,7 @@
},
},
{
- $unwind: "$" + authors_hash,
+ $unwind: `$${authors_hash}`,
},
{
$match: {
@@ -72,7 +72,7 @@
as: states_hash,
},
},
- { $unwind: "$" + states_hash },
+ { $unwind: `$${states_hash}` },
{
$match: {
$or: [
diff --git a/lib/email/smtp-mailer.js b/lib/email/smtp-mailer.js
--- a/lib/email/smtp-mailer.js
+++ b/lib/email/smtp-mailer.js
@@ -4,10 +4,10 @@
class SmtpMailer {
constructor(app) {
const config = app.ConfigManager.get("smtp");
- assert(typeof config.host == "string");
- assert(typeof config.port == "number");
- assert(typeof config.user == "string");
- assert(typeof config.password == "string");
+ assert(typeof config.host === "string");
+ assert(typeof config.port === "number");
+ assert(typeof config.user === "string");
+ assert(typeof config.password === "string");
this.mail_config = app.ConfigManager.get("email");
this.transport = nodemailer.createTransport({
host: config.host,
diff --git a/lib/email/templates/simple.js b/lib/email/templates/simple.js
--- a/lib/email/templates/simple.js
+++ b/lib/email/templates/simple.js
@@ -19,7 +19,7 @@
html = "dummy";
}
- const text = data.text + "\n\n" + buttons_to_text(data.buttons);
+ const text = `${data.text}\n\n${buttons_to_text(data.buttons)}`;
return new Message({
to: data.to,
subject: data.subject,
diff --git a/lib/http/error-to-boom.js b/lib/http/error-to-boom.js
--- a/lib/http/error-to-boom.js
+++ b/lib/http/error-to-boom.js
@@ -1,4 +1,3 @@
-"use strict";
const Sealious = require("../../lib/main");
const Boom = require("boom");
diff --git a/lib/http/extract-context.js b/lib/http/extract-context.js
--- a/lib/http/extract-context.js
+++ b/lib/http/extract-context.js
@@ -1,4 +1,3 @@
-"use strict";
const Sealious = require("../../lib/main");
function create_anonymous_session(app) {
@@ -20,12 +19,11 @@
filter: { "anonymous-session-id": anon_session_id },
}
)
- .then(function({ items: anon_sessions }) {
+ .then(({ items: anon_sessions }) => {
if (anon_sessions.length === 0) {
return create_anonymous_session(app);
- } else {
- return anon_sessions[0];
}
+ return anon_sessions[0];
});
}
@@ -49,7 +47,7 @@
let anonymous_user_id = null;
- await get_anonymous_data.then(function(anon_session) {
+ await get_anonymous_data.then(anon_session => {
anonymous_session_id = anon_session["anonymous-session-id"];
anonymous_user_id = anon_session["anonymous-user-id"];
});
diff --git a/lib/http/get-request-body.js b/lib/http/get-request-body.js
--- a/lib/http/get-request-body.js
+++ b/lib/http/get-request-body.js
@@ -1,9 +1,8 @@
-"use strict";
const merge = require("merge");
const Sealious = require("../../lib/main");
const squares = {
- set: function(obj, key, value) {
+ set(obj, key, value) {
const keys = key.split(/[\]\[]{1,2}/g);
if (keys.length > 1) {
keys.splice(-1); //to remove the trailing empty string;
@@ -38,14 +37,14 @@
for (const i in request.payload) {
squares.set(parsed_query, i, request.payload[i]);
}
- for (var i in request.payload) {
+ for (const i in request.payload) {
if (
request.payload[i].payload &&
request.payload[i].payload instanceof Buffer
) {
let filename = request.payload[i].filename;
- var mime_type = request.payload[i].headers["content-type"];
- var data = request.payload[i].payload;
+ const mime_type = request.payload[i].headers["content-type"];
+ const data = request.payload[i].payload;
parsed_query[i] = new Sealious.File(
context,
filename,
diff --git a/lib/http/handle-error.js b/lib/http/handle-error.js
--- a/lib/http/handle-error.js
+++ b/lib/http/handle-error.js
@@ -1,4 +1,3 @@
-"use strict";
const error_to_boom = require("./error-to-boom.js");
module.exports = function(app, h) {
@@ -6,8 +5,7 @@
app.Logger.error(error);
if (error instanceof app.Sealious.Error && error.is_user_fault) {
return error_to_boom(error);
- } else {
- return error;
}
+ return error;
};
};
diff --git a/lib/http/handle-request.js b/lib/http/handle-request.js
--- a/lib/http/handle-request.js
+++ b/lib/http/handle-request.js
@@ -1,4 +1,3 @@
-"use strict";
const Sealious = require("../../lib/main");
const get_request_body = require("./get-request-body.js");
const http_to_subject_method = require("./http-to-method-name.js");
@@ -10,12 +9,13 @@
function handle_request(app, request, h) {
try {
const config = app.ConfigManager.get("www-server");
- var path_elements = request.params.elements.split("/");
- var action_name = http_to_subject_method[request.method.toUpperCase()];
+ const path_elements = request.params.elements.split("/");
+ const action_name =
+ http_to_subject_method[request.method.toUpperCase()];
let context = null;
return extract_context(app, request)
- .then(function(_context) {
+ .then(_context => {
context = _context;
let body = get_request_body(context, request);
return app.run_action(
diff --git a/lib/http/handle-response.js b/lib/http/handle-response.js
--- a/lib/http/handle-response.js
+++ b/lib/http/handle-response.js
@@ -1,5 +1,3 @@
-"use strict";
-
module.exports = function(app, context, h) {
const config = app.ConfigManager.get("www-server");
return function(response) {
diff --git a/lib/http/http.js b/lib/http/http.js
--- a/lib/http/http.js
+++ b/lib/http/http.js
@@ -1,4 +1,3 @@
-"use strict";
const stream = require("stream");
const http = require("http");
const Promise = require("bluebird");
@@ -53,9 +52,9 @@
await server.register(require("inert"));
server.route({
- method: method,
- path: path,
- handler: async function(request, h) {
+ method,
+ path,
+ async handler(request, h) {
let context = null;
try {
context = await extract_context(app, request);
@@ -76,13 +75,13 @@
server.route({
method: ["GET", "DELETE"],
- path: path,
+ path,
handler: handle_request.bind({}, app),
});
server.route({
method: ["PATCH", "PUT", "POST"],
- path: path,
+ path,
config: {
payload: {
multipart: {
diff --git a/lib/http/routes/finalize-password-reset.subtest.js b/lib/http/routes/finalize-password-reset.subtest.js
--- a/lib/http/routes/finalize-password-reset.subtest.js
+++ b/lib/http/routes/finalize-password-reset.subtest.js
@@ -40,7 +40,7 @@
});
const message_metadata = (await mail_api.get_messages()).filter(
- message => message.recipients[0] == "<user@example.com>"
+ message => message.recipients[0] === "<user@example.com>"
)[0];
assert(message_metadata.subject);
diff --git a/lib/http/routes/finalize-registration-intent.subtest.js b/lib/http/routes/finalize-registration-intent.subtest.js
--- a/lib/http/routes/finalize-registration-intent.subtest.js
+++ b/lib/http/routes/finalize-registration-intent.subtest.js
@@ -21,7 +21,7 @@
options
);
const message_metadata = (await mail_api.get_messages()).filter(
- message => message.recipients[0] == "<user@example.com>"
+ message => message.recipients[0] === "<user@example.com>"
)[0];
assert(message_metadata.subject);
diff --git a/lib/http/setup-routes.js b/lib/http/setup-routes.js
--- a/lib/http/setup-routes.js
+++ b/lib/http/setup-routes.js
@@ -3,7 +3,7 @@
function setup_routes(App, express_app) {
const router = express.Router({ mergeParams: true });
- router.all("/*", function(req, res, next) {
+ router.all("/*", (req, res, next) => {
const elements = req.url.split("/").slice(1);
res.send();
});
diff --git a/lib/main.js b/lib/main.js
--- a/lib/main.js
+++ b/lib/main.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Sealious = {};
const {
diff --git a/lib/response/error.js b/lib/response/error.js
--- a/lib/response/error.js
+++ b/lib/response/error.js
@@ -1,4 +1,3 @@
-"use strict";
const Response = require("./response.js");
const SealiousErrors = {};
diff --git a/lib/response/response.js b/lib/response/response.js
--- a/lib/response/response.js
+++ b/lib/response/response.js
@@ -1,6 +1,3 @@
-"use strict";
-"use strict";
-
function Response(data, is_error, type, status_message) {
this.status = is_error ? "error" : "success";
this.type = type || "response";
diff --git a/lib/response/responses.js b/lib/response/responses.js
--- a/lib/response/responses.js
+++ b/lib/response/responses.js
@@ -1,12 +1,10 @@
-"use strict";
-
const SealiousResponses = {};
SealiousResponses.NewSession = function(session_id) {
this.status = "success";
this.message = "Logged in!";
Object.defineProperty(this, "metadata", {
- value: { session_id: session_id },
+ value: { session_id },
});
this.data = {};
};
diff --git a/lib/subject/predefined-subjects/collections-subject.js b/lib/subject/predefined-subjects/collections-subject.js
--- a/lib/subject/predefined-subjects/collections-subject.js
+++ b/lib/subject/predefined-subjects/collections-subject.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
diff --git a/lib/subject/predefined-subjects/formatted-images.js b/lib/subject/predefined-subjects/formatted-images.js
--- a/lib/subject/predefined-subjects/formatted-images.js
+++ b/lib/subject/predefined-subjects/formatted-images.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
diff --git a/lib/subject/predefined-subjects/me-subject.js b/lib/subject/predefined-subjects/me-subject.js
--- a/lib/subject/predefined-subjects/me-subject.js
+++ b/lib/subject/predefined-subjects/me-subject.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Subject = locreq("lib/subject/subject.js");
const Errors = locreq("lib/response/error.js");
@@ -15,7 +14,7 @@
action_name,
params
)
- .catch({ type: "not_found" }, function(error) {
+ .catch({ type: "not_found" }, error => {
throw new Errors.InvalidCredentials("You're not logged in!");
});
};
diff --git a/lib/subject/predefined-subjects/root-subject.js b/lib/subject/predefined-subjects/root-subject.js
--- a/lib/subject/predefined-subjects/root-subject.js
+++ b/lib/subject/predefined-subjects/root-subject.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Errors = locreq("lib/response/error.js");
diff --git a/lib/subject/predefined-subjects/sessions-subject.js b/lib/subject/predefined-subjects/sessions-subject.js
--- a/lib/subject/predefined-subjects/sessions-subject.js
+++ b/lib/subject/predefined-subjects/sessions-subject.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
const CurrentSessionSubject = require("../subject-types/current-session-subject.js");
diff --git a/lib/subject/predefined-subjects/specifications.js b/lib/subject/predefined-subjects/specifications.js
--- a/lib/subject/predefined-subjects/specifications.js
+++ b/lib/subject/predefined-subjects/specifications.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Subject = locreq("lib/subject/subject.js");
const Errors = locreq("lib/response/error.js");
@@ -9,7 +8,7 @@
const SpecificationsSubject = function(app) {
const actions = {
- show: function(params) {
+ show(params) {
const collections = app.ChipManager.get_chips_by_type("collection");
return Object.keys(collections).map(collection_name =>
collections[collection_name].get_specification(false)
diff --git a/lib/subject/predefined-subjects/uploaded-files.js b/lib/subject/predefined-subjects/uploaded-files.js
--- a/lib/subject/predefined-subjects/uploaded-files.js
+++ b/lib/subject/predefined-subjects/uploaded-files.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
diff --git a/lib/subject/predefined-subjects/users-subject.js b/lib/subject/predefined-subjects/users-subject.js
--- a/lib/subject/predefined-subjects/users-subject.js
+++ b/lib/subject/predefined-subjects/users-subject.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
@@ -40,30 +39,26 @@
this.get_child_subject = function(key) {
if (me_synonyms.indexOf(key) !== -1) {
return new MeSubject(app);
- } else {
- const username = key;
- return app
- .run_action(
- new SuperContext(),
- ["collections", "users"],
- "show",
- { filter: { username: username } }
- )
- .then(function(result) {
- if (result.length === 0) {
- throw new Errors.BadSubjectPath(
- `Unknown username: '${username}'`
- );
- } else {
- const user = result[0];
- return RootSubject.get_subject([
- "collections",
- "users",
- user.id,
- ]);
- }
- });
}
+ const username = key;
+ return app
+ .run_action(new SuperContext(), ["collections", "users"], "show", {
+ filter: { username },
+ })
+ .then(result => {
+ if (result.length === 0) {
+ throw new Errors.BadSubjectPath(
+ `Unknown username: '${username}'`
+ );
+ } else {
+ const user = result[0];
+ return RootSubject.get_subject([
+ "collections",
+ "users",
+ user.id,
+ ]);
+ }
+ });
};
};
diff --git a/lib/subject/subject-types/_batch_action.js b/lib/subject/subject-types/_batch_action.js
--- a/lib/subject/subject-types/_batch_action.js
+++ b/lib/subject/subject-types/_batch_action.js
@@ -1,4 +1,3 @@
-"use strict";
const Promise = require("bluebird");
const locreq = require("locreq")(__dirname);
const ArrayCartesian = locreq("lib/utils/array-cartesian.js");
@@ -35,7 +34,7 @@
"show",
{ filter }
)
- .then(function({ items: resources }) {
+ .then(({ items: resources }) => {
for (const i in map_to) {
const field_in_collection = fields[i];
const field_name = map_to[i];
@@ -44,9 +43,8 @@
resources.map(resource => {
if (field_in_collection === "id") {
return resource.id;
- } else {
- return resource[field_in_collection];
}
+ return resource[field_in_collection];
})
);
}
@@ -54,10 +52,10 @@
to_await.push(promise);
}
}
- return Promise.all(to_await).then(function() {
+ return Promise.all(to_await).then(() => {
return PromiseIterateGenerator(
new ArrayCartesian(possible_field_values),
- function(values) {
+ values => {
const body = {};
for (const i in field_names) {
body[field_names[i]] = values[i];
diff --git a/lib/subject/subject-types/collection-field-subject.js b/lib/subject/subject-types/collection-field-subject.js
--- a/lib/subject/subject-types/collection-field-subject.js
+++ b/lib/subject/subject-types/collection-field-subject.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
const merge = require("merge");
@@ -32,14 +31,13 @@
return Promise.resolve(
this.field_type.actions[action_name](context, params)
);
- } else {
- throw new Errors.DeveloperError(`Unknown action: '${action_name}'`);
}
+ throw new Errors.DeveloperError(`Unknown action: '${action_name}'`);
};
CollectionFieldSubject.prototype.get_child_subject = function(key) {
const self = this;
- return Promise.try(function() {
+ return Promise.try(() => {
return self.field_type.get_child_subject(key);
});
};
diff --git a/lib/subject/subject-types/collection-subject.js b/lib/subject/subject-types/collection-subject.js
--- a/lib/subject/subject-types/collection-subject.js
+++ b/lib/subject/subject-types/collection-subject.js
@@ -1,4 +1,3 @@
-"use strict";
const assert = require("assert");
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
@@ -63,7 +62,7 @@
* map_to[]
*/
const self = this;
- return batch_action(app, context, params, function(context, body) {
+ return batch_action(app, context, params, (context, body) => {
return app.run_action(
context,
["collections", self.collection.name],
@@ -75,7 +74,7 @@
this.delete_many = function(context, params) {
const self = this;
- return batch_action(app, context, params, function(context, body) {
+ return batch_action(app, context, params, (context, body) => {
return app
.run_action(
context,
@@ -85,7 +84,7 @@
filter: body,
}
)
- .each(function(resource) {
+ .each(resource => {
return app.run_action(
context,
["collections", self.collection.name, resource.id],
@@ -98,11 +97,10 @@
this.delete = function(context, params) {
if (params.__multiple) {
return this.delete_many(context, params);
- } else {
- throw new app.Sealious.Errors.NotFound(
- "Cannot delete a collection. Try using the '__multiple: true' mode"
- );
}
+ throw new app.Sealious.Errors.NotFound(
+ "Cannot delete a collection. Try using the '__multiple: true' mode"
+ );
};
this.get_child_subject = async function(key) {
@@ -111,15 +109,14 @@
...named_filters,
key.slice(1),
]);
- } else {
- const resource_id = key;
- const single_resource_subject = new SingleResource(
- app,
- this.collection,
- resource_id
- );
- return single_resource_subject;
}
+ const resource_id = key;
+ const single_resource_subject = new SingleResource(
+ app,
+ this.collection,
+ resource_id
+ );
+ return single_resource_subject;
};
}
@@ -133,13 +130,13 @@
) {
return collection
.check_if_action_is_allowed(context, "create", body)
- .then(function() {
+ .then(() => {
return collection.validate_field_values(context, true, body);
})
- .then(function() {
+ .then(() => {
return collection.encode_field_values(context, body);
})
- .then(function(encoded_body) {
+ .then(encoded_body => {
const newID = shortid();
const resource_data = {
_metadata: {
@@ -152,13 +149,13 @@
};
return datastore.insert(collection.name, resource_data, {});
})
- .then(function(database_entry) {
+ .then(database_entry => {
return collection.get_resource_representation(
context,
database_entry
);
})
- .then(function(representation) {
+ .then(representation => {
return new Sealious.Responses.ResourceCreated(representation);
});
};
@@ -207,7 +204,7 @@
);
const must_be_int = ["items", "page"];
- must_be_int.forEach(function(attribute_name) {
+ must_be_int.forEach(attribute_name => {
if (isNaN(parseInt(full_pagination_params[attribute_name]))) {
full_pagination_params[attribute_name] =
default_pagination_params[attribute_name];
@@ -316,9 +313,9 @@
case "create":
if (args.__multiple) {
return this.create_many(context, args);
- } else {
- return this.create_resource(context, args);
}
+ return this.create_resource(context, args);
+
case "show":
return this.list_resources(context, args);
case "delete":
diff --git a/lib/subject/subject-types/current-session-subject.js b/lib/subject/subject-types/current-session-subject.js
--- a/lib/subject/subject-types/current-session-subject.js
+++ b/lib/subject/subject-types/current-session-subject.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
diff --git a/lib/subject/subject-types/image-format.js b/lib/subject/subject-types/image-format.js
--- a/lib/subject/subject-types/image-format.js
+++ b/lib/subject/subject-types/image-format.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Subject = locreq("lib/subject/subject.js");
const Errors = locreq("lib/response/error.js");
@@ -10,19 +9,14 @@
const QUALITY = 80;
function format_hash(format_obj) {
- return format_obj.size[0] + ":" + format_obj.size[1] + "(" + QUALITY + ")";
+ return `${format_obj.size[0]}:${format_obj.size[1]}(${QUALITY})`;
}
function format_filename(original_filename, format_name) {
- return (
- original_filename
- .split(".")
- .slice(0, -1)
- .join(".") +
- "-" +
- format_name +
- ".jpg"
- );
+ return `${original_filename
+ .split(".")
+ .slice(0, -1)
+ .join(".")}-${format_name}.jpg`;
}
const ImageFormat = function(app, file_id, format_name) {
@@ -30,14 +24,12 @@
this.file_id = file_id;
function get_hdd_path(file_id) {
- return locreq.resolve(app.FileManager.upload_path + "/" + file_id);
+ return locreq.resolve(`${app.FileManager.upload_path}/${file_id}`);
}
function create_formatted_version(file_id, format_name) {
const format_obj = app.ConfigManager.get("image_formats")[format_name];
- return app.Datastore.find("files", { id: file_id }).then(function(
- matches
- ) {
+ return app.Datastore.find("files", { id: file_id }).then(matches => {
const original_file = matches[0];
const file_path = get_hdd_path(original_file.id);
const width = format_obj.size[0];
@@ -46,18 +38,19 @@
original_file.original_name,
format_name
);
- const temp_file_path =
- "/tmp/" + Math.floor(Math.random() * Math.pow(10, 7)) + ".jpg";
+ const temp_file_path = `/tmp/${Math.floor(
+ Math.random() * Math.pow(10, 7)
+ )}.jpg`;
const resize_request = gm(file_path)
.resize(width, height, "^")
.quality(QUALITY);
return Promise.promisify(resize_request.write, {
context: resize_request,
})(temp_file_path)
- .then(function() {
+ .then(() => {
return Promise.promisify(fs.readFile)(temp_file_path);
})
- .then(function(buffer) {
+ .then(buffer => {
return app.FileManager.save_file(
new app.Sealious.File(
new app.Sealious.SuperContext(),
@@ -66,7 +59,7 @@
)
);
})
- .then(function(sealious_file) {
+ .then(sealious_file => {
return app
.run_action(
new app.Sealious.SuperContext(),
@@ -80,7 +73,7 @@
)
.then(() => sealious_file);
})
- .then(function(file) {
+ .then(file => {
return Promise.promisify(fs.unlink)(temp_file_path).then(
() => file
);
@@ -107,7 +100,7 @@
$or: [{ "format.original": hash }, { "format.safe": hash }],
},
},
- ]).then(function(results) {
+ ]).then(results => {
return (
results[0] &&
results[0] && {
@@ -135,7 +128,7 @@
];
if (format_obj === undefined) {
throw new Errors.BadSubjectPath(
- "Unknown image format: " + format_name
+ `Unknown image format: ${format_name}`
);
}
return get_formatted_version(
@@ -144,15 +137,14 @@
format_name,
format_obj
)
- .then(function(result) {
+ .then(result => {
if (result !== undefined) {
return result;
- } else {
- return create_formatted_version(
- file_id,
- format_name
- );
}
+ return create_formatted_version(
+ file_id,
+ format_name
+ );
})
.then(file_description => {
let ret = new app.Sealious.File.from_db_entry(
diff --git a/lib/subject/subject-types/image-formats.js b/lib/subject/subject-types/image-formats.js
--- a/lib/subject/subject-types/image-formats.js
+++ b/lib/subject/subject-types/image-formats.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Subject = locreq("lib/subject/subject.js");
const Errors = locreq("lib/response/error.js");
diff --git a/lib/subject/subject-types/single-file-subject.js b/lib/subject/subject-types/single-file-subject.js
--- a/lib/subject/subject-types/single-file-subject.js
+++ b/lib/subject/subject-types/single-file-subject.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Subject = locreq("lib/subject/subject.js");
const Errors = locreq("lib/response/error.js");
@@ -21,7 +20,7 @@
case "show":
return app.FileManager.find(context, {
id: this.file_id,
- }).then(function(results) {
+ }).then(results => {
return results[0];
});
default:
diff --git a/lib/subject/subject-types/single-resource-subject.js b/lib/subject/subject-types/single-resource-subject.js
--- a/lib/subject/subject-types/single-resource-subject.js
+++ b/lib/subject/subject-types/single-resource-subject.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
const Subject = locreq("lib/subject/subject.js");
@@ -65,7 +64,7 @@
return datastore
.find(collection.name, { sealious_id: resource_id }, {})
- .then(function(db_entries) {
+ .then(db_entries => {
if (db_entries[0] === undefined) {
throw new Errors.NotFound(
`${collection.name}: id ${resource_id} not found`
@@ -78,14 +77,14 @@
);
}
})
- .then(function(resource_representation) {
+ .then(resource_representation => {
return collection
.check_if_action_is_allowed(
context,
"show",
resource_representation
)
- .then(function() {
+ .then(() => {
return resource_representation;
});
});
@@ -108,7 +107,7 @@
return SingleResource.prototype
.__get_resource(datastore, collection, resource_id, context, {})
- .then(function(resource_data) {
+ .then(resource_data => {
resource_representation = resource_data;
return collection.check_if_action_is_allowed(
context,
@@ -116,7 +115,7 @@
resource_representation
);
})
- .then(function() {
+ .then(() => {
return collection.validate_field_values(
context,
delete_empty_values,
@@ -124,14 +123,14 @@
resource_representation
);
})
- .then(function() {
+ .then(() => {
return collection.encode_field_values(
context,
values_to_patch,
resource_representation
);
})
- .then(function(encoded_values) {
+ .then(encoded_values => {
const query = { _metadata: resource_representation._metadata };
query._metadata.last_modified_context = context;
for (const field_name in encoded_values) {
@@ -143,7 +142,7 @@
{ $set: query }
);
})
- .then(function(patch_result) {
+ .then(patch_result => {
if (patch_result.result.n !== 1) {
throw new Error("Wrong amount of resources (!=1) modified");
}
@@ -168,14 +167,14 @@
return SingleResource.prototype
.__get_resource(datastore, collection, resource_id, context, {})
- .then(function(resource_representation) {
+ .then(resource_representation => {
return collection.check_if_action_is_allowed(
context,
"delete",
resource_representation
);
})
- .then(function() {
+ .then(() => {
return datastore.remove(
collection.name,
{
@@ -184,7 +183,7 @@
{}
);
})
- .then(function(data) {
+ .then(data => {
return Promise.resolve();
});
};
diff --git a/lib/subject/subject-types/single-specification-subject.js b/lib/subject/subject-types/single-specification-subject.js
--- a/lib/subject/subject-types/single-specification-subject.js
+++ b/lib/subject/subject-types/single-specification-subject.js
@@ -1,11 +1,10 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Subject = locreq("lib/subject/subject.js");
const Errors = locreq("lib/response/error.js");
const SingleSpecificationsSubject = function(app, collection_name) {
const actions = {
- show: function(params) {
+ show(params) {
const collection = app.ChipManager.get_chip(
"collection",
collection_name
diff --git a/lib/subject/subject.js b/lib/subject/subject.js
--- a/lib/subject/subject.js
+++ b/lib/subject/subject.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Promise = require("bluebird");
const SubjectPath = locreq("lib/data-structures/subject-path.js");
@@ -10,12 +9,11 @@
// the subject referenced by subject_path
subject_path = new SubjectPath(subject_path);
return Promise.resolve(this.get_child_subject(subject_path.head())).then(
- function(child_subject) {
+ child_subject => {
if (subject_path.elements.length === 1) {
return child_subject;
- } else {
- return child_subject.get_subject(subject_path.tail());
}
+ return child_subject.get_subject(subject_path.tail());
}
);
};
diff --git a/lib/super-context.js b/lib/super-context.js
--- a/lib/super-context.js
+++ b/lib/super-context.js
@@ -1,4 +1,3 @@
-"use strict";
const locreq = require("locreq")(__dirname);
const Context = locreq("lib/context.js");
diff --git a/lib/utils/array-cartesian.js b/lib/utils/array-cartesian.js
--- a/lib/utils/array-cartesian.js
+++ b/lib/utils/array-cartesian.js
@@ -1,4 +1,3 @@
-"use strict";
const IntegerCartesian = require("./integer-cartesian.js");
const ArrayCartesian = function(sources) {
@@ -6,7 +5,7 @@
let current_int_state = null;
return {
- next: function() {
+ next() {
const int_next_element = IntegerCartesian.next(
int_sources,
current_int_state
diff --git a/lib/utils/flatten-object-to-dot-notation.js b/lib/utils/flatten-object-to-dot-notation.js
--- a/lib/utils/flatten-object-to-dot-notation.js
+++ b/lib/utils/flatten-object-to-dot-notation.js
@@ -1,5 +1,5 @@
module.exports = function(context, obj) {
- const prefix = typeof context === "string" ? context + "." : "";
+ const prefix = typeof context === "string" ? `${context}.` : "";
return flattenObjectToDotNotation(prefix, obj);
};
@@ -9,7 +9,7 @@
if (obj[prop] && typeof obj[prop] === "object") {
Object.assign(
flattened,
- flattenObjectToDotNotation(new_prop + ".", obj[prop])
+ flattenObjectToDotNotation(`${new_prop}.`, obj[prop])
);
} else {
flattened[new_prop] = obj[prop];
diff --git a/lib/utils/get-datetime.js b/lib/utils/get-datetime.js
--- a/lib/utils/get-datetime.js
+++ b/lib/utils/get-datetime.js
@@ -1,4 +1,3 @@
-"use strict";
const prettyMs = require("pretty-ms");
const dateFormatters = {
@@ -31,13 +30,12 @@
return formats
.reduce((date_string, format) => {
if (dateFormats.includes(format)) {
- return date_string + " " + dateFormatters[format](date);
+ return `${date_string} ${dateFormatters[format](date)}`;
} else if (timeFormats.includes(format)) {
const parsed_time = date.toISOString().split("T")[1];
- return date_string + " " + timeFormatters[format](parsed_time);
- } else {
- throw new Error("Unknown format: " + format);
+ return `${date_string} ${timeFormatters[format](parsed_time)}`;
}
+ throw new Error(`Unknown format: ${format}`);
}, "")
.trimLeft();
}
diff --git a/lib/utils/get-main-app-dir.js b/lib/utils/get-main-app-dir.js
--- a/lib/utils/get-main-app-dir.js
+++ b/lib/utils/get-main-app-dir.js
@@ -1,4 +1,3 @@
-"use strict";
const path = require("path");
function get_main_app_dir() {
diff --git a/lib/utils/integer-cartesian.js b/lib/utils/integer-cartesian.js
--- a/lib/utils/integer-cartesian.js
+++ b/lib/utils/integer-cartesian.js
@@ -1,9 +1,8 @@
-"use strict";
const clone = require("clone");
const IntegerCartesian = {
// integer-only
- next: function(sources, element) {
+ next(sources, element) {
for (const i in sources) {
if (sources[i] <= 0) {
return null;
@@ -12,29 +11,28 @@
const new_element = clone(element);
if (element === null) {
return sources.map(() => 0);
- } else {
- let i = element.length - 1;
- while (i >= 0) {
- if (element[i] >= sources[i]) {
- throw new Error(
- `Invalid element. Max value on index '${i.toString()}' is '${(
- sources[i] - 1
- ).toString()}'`
- );
- }
- if (element[i] === sources[i] - 1) {
- new_element[i] = 0;
- } else {
- break;
- }
- i--;
+ }
+ let i = element.length - 1;
+ while (i >= 0) {
+ if (element[i] >= sources[i]) {
+ throw new Error(
+ `Invalid element. Max value on index '${i.toString()}' is '${(
+ sources[i] - 1
+ ).toString()}'`
+ );
}
- if (i === -1) {
- return null;
+ if (element[i] === sources[i] - 1) {
+ new_element[i] = 0;
+ } else {
+ break;
}
- new_element[i] = new_element[i] + 1;
- return new_element;
+ i--;
+ }
+ if (i === -1) {
+ return null;
}
+ new_element[i] = new_element[i] + 1;
+ return new_element;
},
};
diff --git a/lib/utils/promise-iterate-generator.js b/lib/utils/promise-iterate-generator.js
--- a/lib/utils/promise-iterate-generator.js
+++ b/lib/utils/promise-iterate-generator.js
@@ -2,11 +2,10 @@
const current = generator.next();
if (current === null) {
return Promise.resolve();
- } else {
- return fn(current).then(function() {
- return PromiseIterateGenerator(generator, fn);
- });
}
+ return fn(current).then(() => {
+ return PromiseIterateGenerator(generator, fn);
+ });
};
module.exports = PromiseIterateGenerator;
diff --git a/package.json b/package.json
--- a/package.json
+++ b/package.json
@@ -7,7 +7,9 @@
"scripts": {
"test": "mocha --timeout=10000 setup-test.js \"./lib/**/*.test.js\"",
"build": "rm -rf cosealious/* && babel cosealious-src --out-dir cosealious",
- "prepare": "npm run build"
+ "prepare": "npm run build",
+ "lint": "eslint lib/ --ext .js,.jsx --ignore-pattern node_modules/",
+ "lint:fix": "eslint lib/ --ext .js,.jsx --ignore-pattern node_modules/ --fix"
},
"repository": {
"type": "git",
@@ -56,12 +58,15 @@
"react": "^16.3.2"
},
"devDependencies": {
- "mocha": "*",
- "sinon": "^5.0.7",
- "eslint": "^3.1.1",
+ "babel-cli": "^6.26.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
- "babel-cli": "^6.26.0"
+ "eslint": "^3.1.1",
+ "eslint-config-prettier": "^3.1.0",
+ "eslint-plugin-react": "^7.11.1",
+ "mocha": "*",
+ "prettier": "^1.14.3",
+ "sinon": "^5.0.7"
}
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 25, 05:26 (22 h, 55 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
548643
Default Alt Text
D362.id1291.diff (141 KB)
Attached To
Mode
D362: ESLint config and error fixes
Attached
Detach File
Event Timeline
Log In to Comment