not-node 6.5.21 → 6.5.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/common.js +10 -0
- package/src/generic/logic.js +2 -2
- package/src/generic/route.js +2 -2
- package/src/logic/actions/index.js +3 -0
- package/src/logic/actions/standart.own.js +18 -0
- package/src/logic/actions.before/index.js +1 -0
- package/src/logic/actions.before/ownage/ownage.js +66 -37
- package/src/logic/actions.before/populate/populate.js +10 -1
- package/src/logic/actions.before/standart.queries.js +39 -3
- package/src/logic/generic.js +26 -2
- package/src/logic/logic.js +18 -15
package/package.json
CHANGED
package/src/common.js
CHANGED
|
@@ -486,3 +486,13 @@ const findSignature = (obj, signatures, strict = true, typeStrict = true) => {
|
|
|
486
486
|
});
|
|
487
487
|
};
|
|
488
488
|
module.exports.findSignature = findSignature;
|
|
489
|
+
|
|
490
|
+
const isAction = (action) =>
|
|
491
|
+
action &&
|
|
492
|
+
(typeof action.run === "function" || typeof action === "function");
|
|
493
|
+
|
|
494
|
+
module.exports.isAction = isAction;
|
|
495
|
+
|
|
496
|
+
const isArrayOfActions = (list) => list.every(isAction);
|
|
497
|
+
|
|
498
|
+
module.exports.isArrayOfActions = isArrayOfActions;
|
package/src/generic/logic.js
CHANGED
|
@@ -321,12 +321,12 @@ module.exports = ({
|
|
|
321
321
|
* @param {import('../types').PreparedData} prepared
|
|
322
322
|
* @returns {Promise<Object>} requested document
|
|
323
323
|
**/
|
|
324
|
-
static async
|
|
324
|
+
static async getRawOwn({ targetId, identity }) {
|
|
325
325
|
return await this._getOneRaw({
|
|
326
326
|
targetId,
|
|
327
327
|
identity,
|
|
328
328
|
shouldOwn: true,
|
|
329
|
-
action: "
|
|
329
|
+
action: "getRawOwn",
|
|
330
330
|
});
|
|
331
331
|
}
|
|
332
332
|
|
package/src/generic/route.js
CHANGED
|
@@ -76,14 +76,14 @@ module.exports = ({ getLogic, before, after }) => {
|
|
|
76
76
|
);
|
|
77
77
|
}
|
|
78
78
|
if (this.rootAsUser) {
|
|
79
|
-
return await getLogic(prepared).
|
|
79
|
+
return await getLogic(prepared).getRawOwn(prepared);
|
|
80
80
|
} else {
|
|
81
81
|
return await getLogic(prepared).getRaw(prepared);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
static async getRaw(req, res, next, prepared) {
|
|
86
|
-
return await getLogic(prepared).
|
|
86
|
+
return await getLogic(prepared).getRawOwn(prepared);
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
static async _update(req, res, next, prepared) {
|
|
@@ -3,6 +3,9 @@ const ActionsSetsLibrary = require("../actions.lib");
|
|
|
3
3
|
let actionsSetsLibrary = new ActionsSetsLibrary();
|
|
4
4
|
|
|
5
5
|
actionsSetsLibrary.add("standart", require("./standart"));
|
|
6
|
+
|
|
7
|
+
actionsSetsLibrary.add("standartOwn", require("./standart.own"));
|
|
8
|
+
|
|
6
9
|
actionsSetsLibrary.add("increment", require("./increment"));
|
|
7
10
|
|
|
8
11
|
module.exports = actionsSetsLibrary;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Duplicates standart set with names postpended with 'Own'
|
|
3
|
+
* Work with:
|
|
4
|
+
* beforeActionsOnCondition = [
|
|
5
|
+
* require("./actions.before/ownage/ownage.js").ifActionNameEndsWith_Own(),
|
|
6
|
+
* ],
|
|
7
|
+
* It modifies filtering queries before actions with names ended with 'Own'
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const standartSet = require("./standart");
|
|
11
|
+
|
|
12
|
+
const standartOwnSet = {};
|
|
13
|
+
Object.keys(standartSet).forEach((actionName) => {
|
|
14
|
+
standartOwnSet[`${actionName}Own`] = standartSet[actionName];
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
Object.freeze(standartOwnSet);
|
|
18
|
+
module.exports = standartOwnSet;
|
|
@@ -1,57 +1,86 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
1
|
+
const {
|
|
2
|
+
DOCUMENT_OWNER_FIELD_NAME,
|
|
3
|
+
DOCUMENT_SESSION_FIELD_NAME,
|
|
4
|
+
} = require("../../../auth/const.js");
|
|
3
5
|
const {
|
|
4
6
|
OwnageExceptionIdentityUserIdIsNotDefined,
|
|
5
7
|
} = require("../../../exceptions/action.js");
|
|
6
|
-
|
|
8
|
+
|
|
9
|
+
const StandartQueriesBeforeAction = require("../standart.queries.js");
|
|
7
10
|
|
|
8
11
|
//checks that
|
|
9
12
|
module.exports = class OwnageBeforeAction {
|
|
10
13
|
static #ownerFieldName = DOCUMENT_OWNER_FIELD_NAME;
|
|
14
|
+
static #sessionFieldName = DOCUMENT_SESSION_FIELD_NAME;
|
|
11
15
|
|
|
12
16
|
static get ownerFieldName() {
|
|
13
17
|
return this.#ownerFieldName;
|
|
14
18
|
}
|
|
15
19
|
|
|
16
|
-
static
|
|
17
|
-
|
|
20
|
+
static get sessionFieldName() {
|
|
21
|
+
return this.#sessionFieldName;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static createOwnageFilterForUser(identity) {
|
|
25
|
+
return Object.freeze({
|
|
26
|
+
[OwnageBeforeAction.ownerFieldName]: identity.uid,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static createOwnageFilterForSession(identity) {
|
|
31
|
+
return Object.freeze({
|
|
32
|
+
[OwnageBeforeAction.sessionFieldName]: identity.sid,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Returns object with filtering conditions to restrict access by owner or session
|
|
38
|
+
*
|
|
39
|
+
* @static
|
|
40
|
+
* @param {import('../../../types.js').notAppIdentityData} identity
|
|
41
|
+
* @return {object}
|
|
42
|
+
*/
|
|
43
|
+
static getOwnageFilterForIdentity(identity) {
|
|
18
44
|
if (identity.uid) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (filter) {
|
|
23
|
-
filter = notFilter.filter.modifyRules(filter, {
|
|
24
|
-
[OwnageBeforeAction.ownerFieldName]: identity?.uid,
|
|
25
|
-
});
|
|
26
|
-
if (search) {
|
|
27
|
-
search = notFilter.filter.modifyRules(search, filter);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
args.defaultQueryById = {
|
|
31
|
-
_id: targetId,
|
|
32
|
-
[OwnageBeforeAction.ownerFieldName]: identity?.uid,
|
|
33
|
-
};
|
|
34
|
-
const Model = logic.getModel();
|
|
35
|
-
const incFieldName = ModelRoutine.incremental(Model);
|
|
36
|
-
if (incFieldName) {
|
|
37
|
-
args.defaultQueryByID = {
|
|
38
|
-
[incFieldName]: targetID,
|
|
39
|
-
[OwnageBeforeAction.ownerFieldName]: identity?.uid,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
args.defaultQueryMany = {
|
|
44
|
-
[OwnageBeforeAction.ownerFieldName]: identity?.uid,
|
|
45
|
-
};
|
|
46
|
-
//mark data as owned by
|
|
47
|
-
if (data) {
|
|
48
|
-
data[OwnageBeforeAction.ownerFieldName] = identity.uid;
|
|
49
|
-
}
|
|
45
|
+
return OwnageBeforeAction.createOwnageFilterForUser(identity);
|
|
46
|
+
} else if (identity.sid) {
|
|
47
|
+
return OwnageBeforeAction.createOwnageFilterForSession(identity);
|
|
50
48
|
} else {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
*
|
|
55
|
+
*
|
|
56
|
+
* @static
|
|
57
|
+
* @param {import('../../logic.js')} logic
|
|
58
|
+
* @param {String} actionName
|
|
59
|
+
* @param {import('../../../types.js').PreparedData} args
|
|
60
|
+
*/
|
|
61
|
+
static async run(logic, actionName, args) {
|
|
62
|
+
if (!args.identity) {
|
|
51
63
|
throw new OwnageExceptionIdentityUserIdIsNotDefined(
|
|
52
64
|
actionName,
|
|
53
|
-
|
|
65
|
+
undefined
|
|
54
66
|
);
|
|
55
67
|
}
|
|
68
|
+
const ownageFilter = OwnageBeforeAction.getOwnageFilterForIdentity(
|
|
69
|
+
args.identity
|
|
70
|
+
);
|
|
71
|
+
if (ownageFilter === null) {
|
|
72
|
+
throw new OwnageExceptionIdentityUserIdIsNotDefined(
|
|
73
|
+
actionName,
|
|
74
|
+
args.identity
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
StandartQueriesBeforeAction.modifyQueries(args, ownageFilter);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
static ifActionNameEndsWith_Own() {
|
|
81
|
+
return Object.freeze({
|
|
82
|
+
condition: (actionName) => actionName.endsWith("Own"),
|
|
83
|
+
action: OwnageBeforeAction,
|
|
84
|
+
});
|
|
56
85
|
}
|
|
57
86
|
};
|
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
module.exports = class PopulateBeforeAction {
|
|
2
|
-
static async run(
|
|
2
|
+
static async run(logic, actionName, args) {
|
|
3
|
+
try {
|
|
4
|
+
const { identity } = args;
|
|
5
|
+
args.populate = await logic.getPopulate(actionName, {
|
|
6
|
+
identity,
|
|
7
|
+
});
|
|
8
|
+
} catch (e) {
|
|
9
|
+
logic.log.error(e);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
3
12
|
};
|
|
@@ -1,13 +1,49 @@
|
|
|
1
|
+
const notFilter = require("not-filter");
|
|
1
2
|
const ModelRoutine = require("../../model/routine.js");
|
|
2
3
|
|
|
3
4
|
//adds to args object few basic queries
|
|
4
5
|
module.exports = class StandartQueriesBeforeAction {
|
|
6
|
+
static modifyQueries(args, modificationFilter) {
|
|
7
|
+
const { query } = args;
|
|
8
|
+
let { filter, search } = query;
|
|
9
|
+
if (filter) {
|
|
10
|
+
filter = notFilter.filter.modifyRules(filter, modificationFilter);
|
|
11
|
+
if (search) {
|
|
12
|
+
search = notFilter.filter.modifyRules(search, filter);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
if (args.defaultQueryById) {
|
|
16
|
+
args.defaultQueryById = notFilter.filter.modifyRules(
|
|
17
|
+
args.defaultQueryById,
|
|
18
|
+
modificationFilter
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
if (args.defaultQueryByID) {
|
|
22
|
+
args.defaultQueryByID = notFilter.filter.modifyRules(
|
|
23
|
+
args.defaultQueryByID,
|
|
24
|
+
modificationFilter
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
args.defaultQueryMany = notFilter.filter.modifyRules(
|
|
29
|
+
args.defaultQueryMany,
|
|
30
|
+
modificationFilter
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
//mark data as owned by
|
|
34
|
+
if (typeof args.data == "object" && args.data) {
|
|
35
|
+
Object.assign(args.data, modificationFilter);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
5
39
|
static async run(logic, actionName, args) {
|
|
6
40
|
try {
|
|
7
41
|
const { targetId, targetID } = args;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
42
|
+
if (targetId) {
|
|
43
|
+
args.defaultQueryById = {
|
|
44
|
+
_id: targetId,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
11
47
|
const Model = logic.getModel();
|
|
12
48
|
const incFieldName = ModelRoutine.incremental(Model);
|
|
13
49
|
if (
|
package/src/logic/generic.js
CHANGED
|
@@ -8,11 +8,18 @@ module.exports = ({
|
|
|
8
8
|
MODEL_NAME,
|
|
9
9
|
USER_MODEL_NAME = "not-user//User",
|
|
10
10
|
actionRunner = undefined,
|
|
11
|
-
actionsSets = ["standart"],
|
|
11
|
+
actionsSets = ["standart", "standartOwn"],
|
|
12
12
|
actions = {},
|
|
13
13
|
beforeActions = {},
|
|
14
|
-
|
|
14
|
+
beforeActionsOnCondition = [
|
|
15
|
+
require("./actions.before/ownage/ownage.js").ifActionNameEndsWith_Own(),
|
|
16
|
+
], //each item = {condition: (actionName)=>boolean, action}
|
|
17
|
+
beforeActionsAll = [
|
|
18
|
+
require("./actions.before/standart.queries.js"),
|
|
19
|
+
require("./actions.before/populate/populate.js"),
|
|
20
|
+
],
|
|
15
21
|
afterActions = {},
|
|
22
|
+
afterActionsOnCondition = [], //each item = {condition: (actionName)=>boolean, action}
|
|
16
23
|
populateBuilders = {},
|
|
17
24
|
afterActionsAll = [],
|
|
18
25
|
defaultPopulate = [],
|
|
@@ -36,11 +43,28 @@ module.exports = ({
|
|
|
36
43
|
defaultPopulate,
|
|
37
44
|
});
|
|
38
45
|
|
|
46
|
+
//adds before/after to all
|
|
39
47
|
beforeActionsAll.forEach((action) => {
|
|
40
48
|
Logic.onBefore(undefined, action);
|
|
41
49
|
});
|
|
50
|
+
|
|
42
51
|
afterActionsAll.forEach((action) => Logic.onAfter(undefined, action));
|
|
43
52
|
|
|
53
|
+
//adds before/after to as many as satisfies condition
|
|
54
|
+
Object.keys(ACTIONS).forEach((actionName) => {
|
|
55
|
+
beforeActionsOnCondition.forEach(({ condition, action }) => {
|
|
56
|
+
if (condition(actionName)) {
|
|
57
|
+
Logic.onBefore(actionName, action);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
afterActionsOnCondition.forEach(({ condition, action }) => {
|
|
61
|
+
if (condition(actionName)) {
|
|
62
|
+
Logic.onAfter(actionName, action);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
//adds before/after per actionName
|
|
44
68
|
Object.keys(beforeActions).forEach((actionName) =>
|
|
45
69
|
beforeActions[actionName].forEach((action) =>
|
|
46
70
|
Logic.onBefore(actionName, action)
|
package/src/logic/logic.js
CHANGED
|
@@ -17,8 +17,8 @@ class LogicProxied {
|
|
|
17
17
|
actions = new Map();
|
|
18
18
|
actionRunner = ActionRunner;
|
|
19
19
|
|
|
20
|
-
populateBuilders = {};
|
|
21
|
-
defaultPopulate = [];
|
|
20
|
+
#populateBuilders = {};
|
|
21
|
+
#defaultPopulate = [];
|
|
22
22
|
|
|
23
23
|
MODEL_NAME;
|
|
24
24
|
MODULE_NAME;
|
|
@@ -32,7 +32,6 @@ class LogicProxied {
|
|
|
32
32
|
logAction;
|
|
33
33
|
logDebugAction;
|
|
34
34
|
|
|
35
|
-
|
|
36
35
|
constructor(
|
|
37
36
|
actions = {},
|
|
38
37
|
actionRunner = ActionRunner,
|
|
@@ -48,9 +47,15 @@ class LogicProxied {
|
|
|
48
47
|
this.MODEL_NAME = MODEL_NAME;
|
|
49
48
|
this.MODULE_NAME = MODULE_NAME;
|
|
50
49
|
this.USER_MODEL_NAME = USER_MODEL_NAME;
|
|
50
|
+
if (defaultPopulate) {
|
|
51
|
+
this.#defaultPopulate = defaultPopulate;
|
|
52
|
+
}
|
|
53
|
+
Object.freeze(this.#defaultPopulate);
|
|
51
54
|
|
|
52
|
-
|
|
53
|
-
|
|
55
|
+
if (populateBuilders) {
|
|
56
|
+
this.#populateBuilders = populateBuilders;
|
|
57
|
+
}
|
|
58
|
+
Object.freeze(this.#populateBuilders);
|
|
54
59
|
|
|
55
60
|
actionRunner && (this.actionRunner = actionRunner);
|
|
56
61
|
this.afterPipes = new NamedActionPipes(
|
|
@@ -70,7 +75,7 @@ class LogicProxied {
|
|
|
70
75
|
|
|
71
76
|
// proxy logic, do something before each call of all methods inside class
|
|
72
77
|
// like if arg passed is 3, print something additionally
|
|
73
|
-
return
|
|
78
|
+
return (this.#proxy = new Proxy(this, {
|
|
74
79
|
get(target, prop) {
|
|
75
80
|
if (target.actions.has(prop)) {
|
|
76
81
|
return target.#getActionRunner(prop);
|
|
@@ -78,7 +83,7 @@ class LogicProxied {
|
|
|
78
83
|
return target[prop];
|
|
79
84
|
}
|
|
80
85
|
},
|
|
81
|
-
});
|
|
86
|
+
}));
|
|
82
87
|
}
|
|
83
88
|
|
|
84
89
|
#initTools(target) {
|
|
@@ -105,9 +110,7 @@ class LogicProxied {
|
|
|
105
110
|
this.log &&
|
|
106
111
|
this.log.debug(
|
|
107
112
|
new Date(),
|
|
108
|
-
`${this.MODULE_NAME}//Logic//${
|
|
109
|
-
this.MODEL_NAME
|
|
110
|
-
}//${action}`,
|
|
113
|
+
`${this.MODULE_NAME}//Logic//${this.MODEL_NAME}//${action}`,
|
|
111
114
|
identity?.ip,
|
|
112
115
|
identity?.root
|
|
113
116
|
);
|
|
@@ -132,16 +135,16 @@ class LogicProxied {
|
|
|
132
135
|
|
|
133
136
|
async getPopulate(actionName, prepared) {
|
|
134
137
|
if (
|
|
135
|
-
this
|
|
136
|
-
objHas(this
|
|
137
|
-
isFunc(this
|
|
138
|
+
this.#populateBuilders &&
|
|
139
|
+
objHas(this.#populateBuilders, actionName) &&
|
|
140
|
+
isFunc(this.#populateBuilders[actionName])
|
|
138
141
|
) {
|
|
139
142
|
return await executeFunctionAsAsync(
|
|
140
|
-
this
|
|
143
|
+
this.#populateBuilders[actionName],
|
|
141
144
|
[prepared]
|
|
142
145
|
);
|
|
143
146
|
}
|
|
144
|
-
return this
|
|
147
|
+
return [...this.#defaultPopulate];
|
|
145
148
|
}
|
|
146
149
|
|
|
147
150
|
#getActionRunner(actionName) {
|