not-node 6.5.22 → 6.5.25

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "not-node",
3
- "version": "6.5.22",
3
+ "version": "6.5.25",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -32,6 +32,18 @@ class OwnageExceptionIdentityUserIdIsNotDefined extends notRequestError {
32
32
  module.exports.OwnageExceptionIdentityUserIdIsNotDefined =
33
33
  OwnageExceptionIdentityUserIdIsNotDefined;
34
34
 
35
+ class OwnageExceptionIdentityUserIdAndSessionIsNotDefined extends notRequestError {
36
+ constructor(actionName, identity) {
37
+ super(
38
+ "User identity `uid` and `sid` is not defined, ownage couldnt be determined",
39
+ { code: 505, params: { actionName, identity } },
40
+ null
41
+ );
42
+ }
43
+ }
44
+ module.exports.OwnageExceptionIdentityUserIdAndSessionIsNotDefined =
45
+ OwnageExceptionIdentityUserIdAndSessionIsNotDefined;
46
+
35
47
  class LogicDeleteActionException extends notRequestError {
36
48
  constructor(params, cause) {
37
49
  super("Logic Delete Action exception", { code: 505, params }, cause);
@@ -35,8 +35,6 @@ class FormExceptionTooManyRequests extends HttpExceptionTooManyRequests {
35
35
 
36
36
  module.exports.FormExceptionTooManyRequests = FormExceptionTooManyRequests;
37
37
 
38
- Error("no prepared identity or query");
39
-
40
38
  class FormExceptionIdentityOrQueryIsUndefined extends notRequestError {
41
39
  constructor(formName) {
42
40
  super("not-node:form_exception_identity_or_query_is_undefined", {
@@ -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 getOwnRaw({ targetId, identity }) {
324
+ static async getRawOwn({ targetId, identity }) {
325
325
  return await this._getOneRaw({
326
326
  targetId,
327
327
  identity,
328
328
  shouldOwn: true,
329
- action: "getOwnRaw",
329
+ action: "getRawOwn",
330
330
  });
331
331
  }
332
332
 
@@ -76,14 +76,14 @@ module.exports = ({ getLogic, before, after }) => {
76
76
  );
77
77
  }
78
78
  if (this.rootAsUser) {
79
- return await getLogic(prepared).getOwnRaw(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).getOwnRaw(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,4 +1,3 @@
1
- const notFilter = require("not-filter");
2
1
  const {
3
2
  DOCUMENT_OWNER_FIELD_NAME,
4
3
  DOCUMENT_SESSION_FIELD_NAME,
@@ -6,7 +5,8 @@ const {
6
5
  const {
7
6
  OwnageExceptionIdentityUserIdIsNotDefined,
8
7
  } = require("../../../exceptions/action.js");
9
- const ModelRoutine = require("../../../model/routine.js");
8
+
9
+ const StandartQueriesBeforeAction = require("../standart.queries.js");
10
10
 
11
11
  //checks that
12
12
  module.exports = class OwnageBeforeAction {
@@ -21,37 +21,6 @@ module.exports = class OwnageBeforeAction {
21
21
  return this.#sessionFieldName;
22
22
  }
23
23
 
24
- static setOwnage(logic, actionName, args, ownageFilter) {
25
- const { query, targetId, targetID } = args;
26
- let { filter, search } = query;
27
- if (filter) {
28
- filter = notFilter.filter.modifyRules(filter, ownageFilter);
29
- if (search) {
30
- search = notFilter.filter.modifyRules(search, filter);
31
- }
32
- }
33
- args.defaultQueryById = {
34
- _id: targetId,
35
- ...ownageFilter,
36
- };
37
- const Model = logic.getModel();
38
- const incFieldName = ModelRoutine.incremental(Model);
39
- if (incFieldName) {
40
- args.defaultQueryByID = {
41
- [incFieldName]: targetID,
42
- ...ownageFilter,
43
- };
44
- }
45
-
46
- args.defaultQueryMany = {
47
- ...ownageFilter,
48
- };
49
- //mark data as owned by
50
- if (typeof args.data == "object" && args.data) {
51
- Object.assign(args.data, ownageFilter);
52
- }
53
- }
54
-
55
24
  static createOwnageFilterForUser(identity) {
56
25
  return Object.freeze({
57
26
  [OwnageBeforeAction.ownerFieldName]: identity.uid,
@@ -105,7 +74,7 @@ module.exports = class OwnageBeforeAction {
105
74
  args.identity
106
75
  );
107
76
  }
108
- OwnageBeforeAction.setOwnage(logic, actionName, args, ownageFilter);
77
+ StandartQueriesBeforeAction.modifyQueries(args, ownageFilter);
109
78
  }
110
79
 
111
80
  static ifActionNameEndsWith_Own() {
@@ -1,7 +1,41 @@
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,7 +8,7 @@ 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 = [