not-node 6.5.15 → 6.5.18

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.15",
3
+ "version": "6.5.18",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -24,7 +24,7 @@ function getOwnerId(data, ownerFieldName = CONST.DOCUMENT_OWNER_FIELD_NAME) {
24
24
  /**
25
25
  * Check if data is belongs to user
26
26
  * @param {Object} data object
27
- * @param {import('mongoose').Schema.Types.ObjectId} user_id possible owner
27
+ * @param {import('mongoose').Schema.Types.ObjectId|string} user_id possible owner
28
28
  * @return {boolean} true - belongs, false - not belongs
29
29
  **/
30
30
 
@@ -89,6 +89,7 @@ module.exports = ({
89
89
  MODULE_NAME,
90
90
  MODEL_NAME,
91
91
  actionName,
92
+ config,
92
93
  formProps,
93
94
  }) => {
94
95
  if (Object.keys(genericFormsGenerators).includes(actionName)) {
@@ -97,6 +98,7 @@ module.exports = ({
97
98
  MODULE_NAME,
98
99
  MODEL_NAME,
99
100
  actionName,
101
+ config,
100
102
  ...formProps,
101
103
  });
102
104
  return new formConstructor({
@@ -104,6 +106,7 @@ module.exports = ({
104
106
  MODULE_NAME,
105
107
  MODEL_NAME,
106
108
  actionName,
109
+ config,
107
110
  ...formProps,
108
111
  });
109
112
  } else {
@@ -112,6 +115,7 @@ module.exports = ({
112
115
  MODULE_NAME,
113
116
  MODEL_NAME,
114
117
  actionName,
118
+ config,
115
119
  ...formProps,
116
120
  });
117
121
  }
@@ -151,6 +155,7 @@ module.exports = ({
151
155
  MODEL_NAME,
152
156
  actionName,
153
157
  app: getApp(),
158
+ config,
154
159
  formProps: selectActionFormProps(formsProps, actionName),
155
160
  });
156
161
  //caching
package/src/form/form.js CHANGED
@@ -1,6 +1,7 @@
1
1
  const Schema = require("mongoose").Schema;
2
2
  const validator = require("validator");
3
3
  const notPath = require("not-path");
4
+ const notConfig = require("not-config");
4
5
  const FormFabric = require("./fabric");
5
6
  const Auth = require("../auth");
6
7
  const { createSchemaFromFields } = require("../fields");
@@ -80,6 +81,10 @@ class Form {
80
81
  };
81
82
 
82
83
  #INSTRUCTIONS = undefined;
84
+ /**
85
+ * @prop {import('../types.js').notAppConfigReader} name of model
86
+ **/
87
+ #CONFIG;
83
88
 
84
89
  #rateLimiter = undefined;
85
90
  #rateLimiterIdGetter = (data) => data.identity.sid;
@@ -87,7 +92,7 @@ class Form {
87
92
  #rateLimiterClientName = InitRateLimiter.DEFAULT_CLIENT;
88
93
 
89
94
  /**
90
- *
95
+ * @memberof Form
91
96
  * @param {Object} options
92
97
  * @param {Array<string|Array<string>>} [options.FIELDS]
93
98
  * @param {string} [options.FORM_NAME]
@@ -95,6 +100,7 @@ class Form {
95
100
  * @param {string} options.MODULE_NAME
96
101
  * @param {string} options.actionName
97
102
  * @param {import('../app.js')} options.app
103
+ * @param {import('../types.js').notAppConfigReader} [options.config]
98
104
  * @param {Object.<string, Function>} [options.EXTRACTORS]
99
105
  * @param {Object.<string, Function>} [options.TRANSFORMERS]
100
106
  * @param {import('../types.js').notAppFormProcessingPipe} [options.INSTRUCTIONS]
@@ -109,6 +115,7 @@ class Form {
109
115
  MODULE_NAME,
110
116
  actionName,
111
117
  app,
118
+ config,
112
119
  EXTRACTORS = {},
113
120
  ENV_EXTRACTORS = {},
114
121
  TRANSFORMERS = {},
@@ -120,8 +127,8 @@ class Form {
120
127
  FORM_NAME ?? Form.createName(MODULE_NAME, MODEL_NAME, actionName);
121
128
  this.#MODEL_NAME = MODEL_NAME;
122
129
  this.#MODULE_NAME = MODULE_NAME;
130
+ config && this.#setConfig(config);
123
131
  this.#setFields(app, FIELDS);
124
-
125
132
  this.#createValidationSchema(app);
126
133
  this.#augmentValidationSchema();
127
134
  INSTRUCTIONS && this.#addInstructions(INSTRUCTIONS);
@@ -132,6 +139,34 @@ class Form {
132
139
  this.#createRateLimiter(rate);
133
140
  }
134
141
 
142
+ /**
143
+ *
144
+ * @param {import('../types.js').notAppConfigReader} config
145
+ * @memberof Form
146
+ */
147
+ #setConfig(config) {
148
+ this.#CONFIG = config;
149
+ }
150
+
151
+ /**
152
+ * Returns module config reader
153
+ * @readonly
154
+ * @returns {import('../types.js').notAppConfigReader}
155
+ * @memberof Form
156
+ */
157
+ get config() {
158
+ if (!this.#CONFIG) {
159
+ this.#CONFIG = notConfig.forModule(this.#MODULE_NAME);
160
+ }
161
+ return this.#CONFIG;
162
+ }
163
+
164
+ /**
165
+ *
166
+ * @param {import('../app.js')} app
167
+ * @param {Array<string|Array<string>>} FIELDS
168
+ * @returns
169
+ */
135
170
  #setFields(app, FIELDS = []) {
136
171
  try {
137
172
  const warning = () =>
@@ -25,14 +25,14 @@ module.exports = ({ getLogic, before, after }) => {
25
25
  );
26
26
  }
27
27
  if (this.rootAsUser) {
28
- return await getLogic().createOwn(prepared);
28
+ return await getLogic(prepared).createOwn(prepared);
29
29
  } else {
30
- return await getLogic().create(prepared);
30
+ return await getLogic(prepared).create(prepared);
31
31
  }
32
32
  }
33
33
 
34
34
  static async create(req, res, next, prepared) {
35
- return await getLogic().createOwn(prepared);
35
+ return await getLogic(prepared).createOwn(prepared);
36
36
  }
37
37
 
38
38
  static async _get(req, res, next, prepared) {
@@ -42,14 +42,14 @@ module.exports = ({ getLogic, before, after }) => {
42
42
  );
43
43
  }
44
44
  if (this.rootAsUser) {
45
- return await getLogic().getOwn(prepared);
45
+ return await getLogic(prepared).getOwn(prepared);
46
46
  } else {
47
- return await getLogic().get(prepared);
47
+ return await getLogic(prepared).get(prepared);
48
48
  }
49
49
  }
50
50
 
51
51
  static async get(req, res, next, prepared) {
52
- return await getLogic().getOwn(prepared);
52
+ return await getLogic(prepared).getOwn(prepared);
53
53
  }
54
54
 
55
55
  static async _getByID(req, res, next, prepared) {
@@ -59,14 +59,14 @@ module.exports = ({ getLogic, before, after }) => {
59
59
  );
60
60
  }
61
61
  if (this.rootAsUser) {
62
- return await getLogic().getByIDOwn(prepared);
62
+ return await getLogic(prepared).getByIDOwn(prepared);
63
63
  } else {
64
- return await getLogic().getByID(prepared);
64
+ return await getLogic(prepared).getByID(prepared);
65
65
  }
66
66
  }
67
67
 
68
68
  static async getByID(req, res, next, prepared) {
69
- return await getLogic().getByIDOwn(prepared);
69
+ return await getLogic(prepared).getByIDOwn(prepared);
70
70
  }
71
71
 
72
72
  static async _getRaw(req, res, next, prepared) {
@@ -76,14 +76,14 @@ module.exports = ({ getLogic, before, after }) => {
76
76
  );
77
77
  }
78
78
  if (this.rootAsUser) {
79
- return await getLogic().getOwnRaw(prepared);
79
+ return await getLogic(prepared).getOwnRaw(prepared);
80
80
  } else {
81
- return await getLogic().getRaw(prepared);
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().getOwnRaw(prepared);
86
+ return await getLogic(prepared).getOwnRaw(prepared);
87
87
  }
88
88
 
89
89
  static async _update(req, res, next, prepared) {
@@ -93,14 +93,14 @@ module.exports = ({ getLogic, before, after }) => {
93
93
  );
94
94
  }
95
95
  if (this.rootAsUser) {
96
- return await getLogic().updateOwn(prepared);
96
+ return await getLogic(prepared).updateOwn(prepared);
97
97
  } else {
98
- return await getLogic().update(prepared);
98
+ return await getLogic(prepared).update(prepared);
99
99
  }
100
100
  }
101
101
 
102
102
  static async update(req, res, next, prepared) {
103
- return await getLogic().updateOwn(prepared);
103
+ return await getLogic(prepared).updateOwn(prepared);
104
104
  }
105
105
 
106
106
  static async _listAll(req, res, next, prepared) {
@@ -110,14 +110,14 @@ module.exports = ({ getLogic, before, after }) => {
110
110
  );
111
111
  }
112
112
  if (this.rootAsUser) {
113
- return await getLogic().listAllOwn(prepared);
113
+ return await getLogic(prepared).listAllOwn(prepared);
114
114
  } else {
115
- return await getLogic().listAll(prepared);
115
+ return await getLogic(prepared).listAll(prepared);
116
116
  }
117
117
  }
118
118
 
119
119
  static async listAll(req, res, next, prepared) {
120
- return await getLogic().listAllOwn(prepared);
120
+ return await getLogic(prepared).listAllOwn(prepared);
121
121
  }
122
122
 
123
123
  static async _listAndCount(req, res, next, prepared) {
@@ -127,14 +127,14 @@ module.exports = ({ getLogic, before, after }) => {
127
127
  );
128
128
  }
129
129
  if (this.rootAsUser) {
130
- return await getLogic().listAndCountOwn(prepared);
130
+ return await getLogic(prepared).listAndCountOwn(prepared);
131
131
  } else {
132
- return await getLogic().listAndCount(prepared);
132
+ return await getLogic(prepared).listAndCount(prepared);
133
133
  }
134
134
  }
135
135
 
136
136
  static async listAndCount(req, res, next, prepared) {
137
- return await getLogic().listAndCountOwn(prepared);
137
+ return await getLogic(prepared).listAndCountOwn(prepared);
138
138
  }
139
139
 
140
140
  static async _list(req, res, next, prepared) {
@@ -144,14 +144,14 @@ module.exports = ({ getLogic, before, after }) => {
144
144
  );
145
145
  }
146
146
  if (this.rootAsUser) {
147
- return await getLogic().listOwn(prepared);
147
+ return await getLogic(prepared).listOwn(prepared);
148
148
  } else {
149
- return await getLogic().list(prepared);
149
+ return await getLogic(prepared).list(prepared);
150
150
  }
151
151
  }
152
152
 
153
153
  static async list(req, res, next, prepared) {
154
- return await getLogic().listOwn(prepared);
154
+ return await getLogic(prepared).listOwn(prepared);
155
155
  }
156
156
 
157
157
  static async _count(req, res, next, prepared) {
@@ -161,14 +161,14 @@ module.exports = ({ getLogic, before, after }) => {
161
161
  );
162
162
  }
163
163
  if (this.rootAsUser) {
164
- return await getLogic().countOwn(prepared);
164
+ return await getLogic(prepared).countOwn(prepared);
165
165
  } else {
166
- return await getLogic().count(prepared);
166
+ return await getLogic(prepared).count(prepared);
167
167
  }
168
168
  }
169
169
 
170
170
  static async count(req, res, next, prepared) {
171
- return await getLogic().countOwn(prepared);
171
+ return await getLogic(prepared).countOwn(prepared);
172
172
  }
173
173
 
174
174
  static async _delete(req, res, next, prepared) {
@@ -178,14 +178,14 @@ module.exports = ({ getLogic, before, after }) => {
178
178
  );
179
179
  }
180
180
  if (this.rootAsUser) {
181
- return await getLogic().deleteOwn(prepared);
181
+ return await getLogic(prepared).deleteOwn(prepared);
182
182
  } else {
183
- return await getLogic().delete(prepared);
183
+ return await getLogic(prepared).delete(prepared);
184
184
  }
185
185
  }
186
186
 
187
187
  static async delete(req, res, next, prepared) {
188
- return await getLogic().deleteOwn(prepared);
188
+ return await getLogic(prepared).deleteOwn(prepared);
189
189
  }
190
190
  }
191
191
 
package/src/types.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @typedef {object} notAppResponse
2
+ * @typedef {object} notAppResponse
3
3
  * @property {string} status 'ok' or 'error'
4
4
  * @property {string} message
5
5
  * @property {Array<string>|Object<string, Array<string>>} [errors]
@@ -18,9 +18,9 @@
18
18
 
19
19
  /**
20
20
  * @typedef {Object} PreparedData
21
- * @property {notAppIdentityData} [identity] user identity information
21
+ * @property {notAppIdentityData} [identity] user identity information
22
22
  * @property {Object} [data]
23
- * @property {string} [action]
23
+ * @property {string} [action]
24
24
  * @property {Query} [query]
25
25
  * @property {number} [targetID] target item ID
26
26
  * @property {Object} [activeUser] current user info
@@ -149,8 +149,9 @@
149
149
  /**
150
150
  * @typedef {object} notFieldSafety
151
151
  * @property {Array<string>} create
152
- * @property {Array<string>} update
153
152
  * @property {Array<string>} read
153
+ * @property {Array<string>} update
154
+ * @property {Array<string>} delete
154
155
  */
155
156
 
156
157
  /**
@@ -231,4 +232,10 @@
231
232
  * @typedef {import('mongoose').Document & notAppDocumentMethods} notAppDocument
232
233
  **/
233
234
 
235
+ /**
236
+ * @typedef {object} notAppConfigReader
237
+ * @property {function(string, [any]):string|number|object|undefined} get
238
+ * @property {function(string, string|number|object|undefined):notAppConfigReader} set
239
+ **/
240
+
234
241
  module.exports = {};