not-node 6.4.11 → 6.4.13

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.4.11",
3
+ "version": "6.4.13",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -5,7 +5,6 @@ const getApp = require("../getApp.js"),
5
5
  { sayForModule } = require("not-locale"),
6
6
  { objHas, isFunc, executeFunctionAsAsync } = require("../common"),
7
7
  LogInit = require("not-log");
8
-
9
8
  module.exports = ({
10
9
  target,
11
10
  MODULE_NAME,
@@ -94,6 +93,7 @@ module.exports = ({
94
93
  if (form2) {
95
94
  return form2;
96
95
  }
96
+
97
97
  return createForm({
98
98
  app: getApp(),
99
99
  MODULE_NAME,
@@ -109,6 +109,7 @@ module.exports = ({
109
109
  JSON.stringify(req.notRouteData, null, 4)
110
110
  );
111
111
  const actionName = req.notRouteData.actionName;
112
+
112
113
  const trimmedActionName = actionName.replace("_", "");
113
114
  const FormValidator = getForm(trimmedActionName);
114
115
  const prepared = FormValidator
@@ -2,4 +2,7 @@ module.exports = {
2
2
  ui: {
3
3
  component: "UIHidden",
4
4
  },
5
+ model: {
6
+ safe: require("../safety.protocols").systemManageable,
7
+ },
5
8
  };
@@ -2,4 +2,7 @@ module.exports = {
2
2
  ui: {
3
3
  component: "UIHidden",
4
4
  },
5
+ model: {
6
+ safe: require("../safety.protocols").systemManageable,
7
+ },
5
8
  };
@@ -2,4 +2,7 @@ module.exports = {
2
2
  ui: {
3
3
  component: "UIHidden",
4
4
  },
5
+ model: {
6
+ safe: require("../safety.protocols").systemManageable,
7
+ },
5
8
  };
@@ -2,4 +2,7 @@ module.exports = {
2
2
  ui: {
3
3
  component: "UIHidden",
4
4
  },
5
+ model: {
6
+ safe: require("../safety.protocols").systemManageable,
7
+ },
5
8
  };
@@ -10,6 +10,6 @@ module.exports = {
10
10
  searchable: true,
11
11
  required: true,
12
12
  transformers: ["xss"],
13
- safe: require("../safety.protocols").ownerRootAdmin,
13
+ safe: require("../safety.protocols").systemManageable,
14
14
  },
15
15
  };
@@ -11,6 +11,7 @@ module.exports = {
11
11
  type: Date,
12
12
  required: true,
13
13
  default: Date.now,
14
- safe: require("../safety.protocols").ownerRootAdmin,
14
+
15
+ safe: require("../safety.protocols").systemManageable,
15
16
  },
16
17
  };
package/src/form/form.js CHANGED
@@ -11,6 +11,7 @@ const {
11
11
  isFunc,
12
12
  firstLetterToUpper,
13
13
  firstLetterToLower,
14
+ copyObj,
14
15
  } = require("../common");
15
16
 
16
17
  const ValidationBuilder = require("not-validation").Builder;
@@ -97,7 +98,7 @@ class Form {
97
98
  * @param {import('../types.js').notAppFormRateLimiterOptions} options.rate
98
99
  */
99
100
  constructor({
100
- FIELDS,
101
+ FIELDS = [],
101
102
  FORM_NAME,
102
103
  MODEL_NAME,
103
104
  MODULE_NAME,
@@ -114,7 +115,7 @@ class Form {
114
115
  FORM_NAME ?? Form.createName(MODULE_NAME, MODEL_NAME, actionName);
115
116
  this.#MODEL_NAME = MODEL_NAME;
116
117
  this.#MODULE_NAME = MODULE_NAME;
117
- this.#PROTO_FIELDS = FIELDS;
118
+ this.#setFields(app, FIELDS);
118
119
  this.#createValidationSchema(app);
119
120
  this.#augmentValidationSchema();
120
121
  this.#addInstructions(INSTRUCTIONS);
@@ -125,6 +126,42 @@ class Form {
125
126
  this.#createRateLimiter(rate);
126
127
  }
127
128
 
129
+ #setFields(app, FIELDS = []) {
130
+ try {
131
+ const warning = () =>
132
+ app.logger.warn(`No PROTO_FIELDS for ${this.#FORM_NAME} form`);
133
+ if (FIELDS && Array.isArray(FIELDS) && FIELDS.length) {
134
+ this.#PROTO_FIELDS = FIELDS;
135
+ } else if (this.#MODEL_NAME) {
136
+ let modelPath = `${this.#MODEL_NAME}`;
137
+ if (this.#MODULE_NAME) {
138
+ modelPath = `${this.#MODULE_NAME}//${this.#MODEL_NAME}`;
139
+ }
140
+ //no path to model - returning after warning
141
+ if (!modelPath) {
142
+ warning();
143
+ return;
144
+ }
145
+ const mod = app.getModelFile(modelPath);
146
+ //no module or fields in module exports - returning after warning
147
+ if (
148
+ !(
149
+ mod &&
150
+ mod.FIELDS &&
151
+ Array.isArray(mod.FIELDS) &&
152
+ mod.FIELDS.length
153
+ )
154
+ ) {
155
+ warning();
156
+ return;
157
+ }
158
+ this.#PROTO_FIELDS = copyObj(mod.FIELDS);
159
+ }
160
+ } catch (e) {
161
+ app.logger.error(e);
162
+ }
163
+ }
164
+
128
165
  get FORM_NAME() {
129
166
  return this.#FORM_NAME;
130
167
  }
@@ -0,0 +1,24 @@
1
+ const Schema = require("mongoose").Schema;
2
+ const getApp = require("../getApp");
3
+ const { firstLetterToLower } = require("../common");
4
+
5
+ module.exports = ({ MODULE_NAME, MODEL_NAME, actionName = "data" }) => {
6
+ return {
7
+ model: {
8
+ type: Schema.Types.Mixed,
9
+ required: true,
10
+ validate: [
11
+ {
12
+ validator(val) {
13
+ return getApp()
14
+ .getForm(`${MODULE_NAME}//_${actionName}`)
15
+ .run(val);
16
+ },
17
+ message: `${MODULE_NAME}:${firstLetterToLower(
18
+ MODEL_NAME
19
+ )}_data_is_not_valid`,
20
+ },
21
+ ],
22
+ },
23
+ };
24
+ };
@@ -0,0 +1,28 @@
1
+ const Form = require("../form/form");
2
+
3
+ module.exports = ({
4
+ MODULE_NAME,
5
+ MODEL_NAME,
6
+ actionName = "_data",
7
+ validators = [],
8
+ afterExtract = async (input /*, req = null*/) => input,
9
+ }) => {
10
+ return class extends Form {
11
+ constructor({ app }) {
12
+ super({ app, MODULE_NAME, MODEL_NAME, actionName });
13
+ }
14
+
15
+ extract(data) {
16
+ return data;
17
+ }
18
+
19
+ async afterExtract(input, req) {
20
+ input = await super.afterExtract(input, req);
21
+ return await afterExtract(input, req);
22
+ }
23
+
24
+ getFormValidationRules() {
25
+ return validators;
26
+ }
27
+ };
28
+ };
@@ -0,0 +1,29 @@
1
+ const Form = require("../form/form");
2
+
3
+ module.exports = ({
4
+ MODULE_NAME,
5
+ MODEL_NAME,
6
+ actionName = "create",
7
+ dataFieldName = "data",
8
+ validators = [],
9
+ afterExtract = async (input /*, req*/) => input,
10
+ }) => {
11
+ const FIELDS = [
12
+ ["identity", "not-node//identity"],
13
+ ["data", `${MODULE_NAME}//_${dataFieldName}`],
14
+ ];
15
+ return class extends Form {
16
+ constructor({ app }) {
17
+ super({ FIELDS, app, MODULE_NAME, MODEL_NAME, actionName });
18
+ }
19
+
20
+ async afterExtract(input, req) {
21
+ input = await super.afterExtract(input, req);
22
+ return await afterExtract(input, req);
23
+ }
24
+
25
+ getFormValidationRules() {
26
+ return validators;
27
+ }
28
+ };
29
+ };
@@ -0,0 +1,31 @@
1
+ const Form = require("../form/form");
2
+
3
+ module.exports = ({
4
+ MODULE_NAME,
5
+ MODEL_NAME,
6
+ actionName = "update",
7
+ dataFieldName = "data",
8
+ validators = [],
9
+ afterExtract = async (input /*, req*/) => input,
10
+ }) => {
11
+ const FIELDS = [
12
+ ["targetId", { required: true }, "not-node//objectId"],
13
+ ["identity", "not-node//identity"],
14
+ ["data", `${MODULE_NAME}//_${dataFieldName}`],
15
+ ];
16
+
17
+ return class extends Form {
18
+ constructor({ app }) {
19
+ super({ FIELDS, app, MODULE_NAME, MODEL_NAME, actionName });
20
+ }
21
+
22
+ async afterExtract(input, req) {
23
+ input = await super.afterExtract(input, req);
24
+ return await afterExtract(input, req);
25
+ }
26
+
27
+ getFormValidationRules() {
28
+ return validators;
29
+ }
30
+ };
31
+ };
@@ -2,6 +2,10 @@ module.exports.GenericLogic = require("./logic.js");
2
2
  module.exports.GenericRoute = require("./route.js");
3
3
  module.exports.GenericGetByIdForm = require("./form.getById.js");
4
4
  module.exports.GenericGetByIDForm = require("./form.getByID.js");
5
+ module.exports.GenericDataField = require("./field._data.js");
6
+ module.exports.GenericDataForm = require("./form._data.js");
7
+ module.exports.GenericCreateForm = require("./form.create.js");
8
+ module.exports.GenericUpdateForm = require("./form.update.js");
5
9
  module.exports.GenericAuthorizedActionForm = require("./form.authorizedAction.js");
6
10
  module.exports.GenericListAndCountForm = require("./form.listAndCount.js");
7
11
  module.exports.GenericListForm = require("./form.list.js");