not-node 6.4.12 → 6.4.14

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.12",
3
+ "version": "6.4.14",
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
  };
@@ -0,0 +1,71 @@
1
+ const Schema = require("mongoose").Schema;
2
+ const getApp = require("../getApp");
3
+ const { firstLetterToLower } = require("../common");
4
+ const genericDataForm = require("./form._data");
5
+ const Form = require("../form/form");
6
+
7
+ const initGenericDataForm = ({
8
+ MODULE_NAME,
9
+ MODEL_NAME,
10
+ actionName,
11
+ formName,
12
+ validators = [],
13
+ afterExtract = async (input /*, req = null*/) => input,
14
+ }) => {
15
+ try {
16
+ const cls = genericDataForm({
17
+ MODULE_NAME,
18
+ MODEL_NAME,
19
+ actionName,
20
+ validators,
21
+ afterExtract,
22
+ });
23
+ const App = getApp();
24
+ App.getModule(MODULE_NAME).setFormConstructor(formName, cls);
25
+ App.getModule(MODULE_NAME).setForm(formName, new cls(App));
26
+ return true;
27
+ } catch (e) {
28
+ getApp().logger.error(e);
29
+ return false;
30
+ }
31
+ };
32
+
33
+ module.exports = ({
34
+ MODULE_NAME,
35
+ MODEL_NAME,
36
+ actionName = "_data",
37
+ FORM_PATH,
38
+ validators = [],
39
+ afterExtract = async (input /*, req = null*/) => input,
40
+ }) => {
41
+ if (!FORM_PATH) {
42
+ FORM_PATH = Form.createPath(MODULE_NAME, MODEL_NAME, actionName);
43
+ }
44
+ const formName = FORM_PATH.split("//")[1];
45
+ if (!getApp().getModule(MODULE_NAME).getFormConstructor(formName)) {
46
+ initGenericDataForm({
47
+ MODULE_NAME,
48
+ MODEL_NAME,
49
+ actionName,
50
+ formName,
51
+ validators,
52
+ afterExtract,
53
+ });
54
+ }
55
+ return {
56
+ model: {
57
+ type: Schema.Types.Mixed,
58
+ required: true,
59
+ validate: [
60
+ {
61
+ validator(val) {
62
+ return getApp().getForm(FORM_PATH).run(val);
63
+ },
64
+ message: `${MODULE_NAME}:${firstLetterToLower(
65
+ MODEL_NAME
66
+ )}_data_is_not_valid`,
67
+ },
68
+ ],
69
+ },
70
+ };
71
+ };
@@ -0,0 +1,54 @@
1
+ const getApp = require("../getApp");
2
+ const genericDataField = require("./field._data");
3
+ const Form = require("../form/form");
4
+
5
+ const initGenericDataField = (
6
+ MODULE_NAME,
7
+ MODEL_NAME,
8
+ actionName = "_data",
9
+ validators = [],
10
+ afterExtract = async (input /*, req = null*/) => input
11
+ ) => {
12
+ //not-module//modelName._data
13
+ const fieldGenericPath = Form.createPath(
14
+ MODULE_NAME,
15
+ MODEL_NAME,
16
+ actionName
17
+ );
18
+ //modelName._data
19
+ const fieldGenericName = fieldGenericPath.split("//")[1];
20
+ const App = getApp();
21
+ //if already exists - returning full path to it
22
+ if (App.getModule(MODULE_NAME).getField(fieldGenericName)) {
23
+ return fieldGenericPath;
24
+ }
25
+ //create new definition, register, return
26
+ return genericDataField({
27
+ MODULE_NAME,
28
+ MODEL_NAME,
29
+ FORM_PATH: fieldGenericPath,
30
+ validators,
31
+ afterExtract,
32
+ });
33
+ };
34
+
35
+ const getGenericDataField = ({
36
+ fieldPath,
37
+ MODULE_NAME,
38
+ MODEL_NAME,
39
+ validators,
40
+ afterExtract,
41
+ }) => {
42
+ if (getApp().getField(fieldPath)) {
43
+ return fieldPath;
44
+ } else {
45
+ return initGenericDataField({
46
+ MODULE_NAME,
47
+ MODEL_NAME,
48
+ validators,
49
+ afterExtract,
50
+ });
51
+ }
52
+ };
53
+
54
+ module.exports = { getGenericDataField, initGenericDataField };
@@ -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,58 @@
1
+ const Form = require("../form/form");
2
+ const { getGenericDataField } = require("./field");
3
+ /**
4
+ * Creates generic Crud form, if data field is not defined in fields/ it creates and registers field in module and sub _data form
5
+ *
6
+ * @param {Object} param
7
+ * @param {string} param.MODULE_NAME
8
+ * @param {string} param.MODEL_NAME
9
+ * @param {string} [param.actionName="create"]
10
+ * @param {string} [param.dataFieldName = "_data"]
11
+ * @param {Array<function>} [param.validators = []]
12
+ * @param {Array<function>} [param.dataValidators = []],
13
+ * @param {function} [param.afterExtract = async (input , req) => input]
14
+ * @param {function} [param.afterDataExtract = async (input, req) => input]
15
+ */
16
+ module.exports = ({
17
+ MODULE_NAME,
18
+ MODEL_NAME,
19
+ actionName = "create",
20
+ dataFieldName = "data",
21
+ validators = [],
22
+ dataValidators = [],
23
+ afterExtract = async (input /*, req*/) => input,
24
+ afterDataExtract = async (input /*, req*/) => input,
25
+ }) => {
26
+ const defaultDataFieldPath = Form.createPath(
27
+ MODULE_NAME,
28
+ MODEL_NAME,
29
+ dataFieldName
30
+ );
31
+
32
+ const dataFieldDefinition = getGenericDataField({
33
+ fieldPath: defaultDataFieldPath,
34
+ MODULE_NAME,
35
+ MODEL_NAME,
36
+ validators: dataValidators,
37
+ afterExtract: afterDataExtract,
38
+ });
39
+
40
+ const FIELDS = [
41
+ ["identity", "not-node//identity"],
42
+ ["data", dataFieldDefinition],
43
+ ];
44
+ return class extends Form {
45
+ constructor({ app }) {
46
+ super({ FIELDS, app, MODULE_NAME, MODEL_NAME, actionName });
47
+ }
48
+
49
+ async afterExtract(input, req) {
50
+ input = await super.afterExtract(input, req);
51
+ return await afterExtract(input, req);
52
+ }
53
+
54
+ getFormValidationRules() {
55
+ return validators;
56
+ }
57
+ };
58
+ };
@@ -0,0 +1,62 @@
1
+ const Form = require("../form/form");
2
+ const { getGenericDataField } = require("./field");
3
+ /**
4
+ * Creates generic crUd form, if data field is not defined in fields/ it creates and registers field in module and sub _data form
5
+ *
6
+ * @param {Object} param
7
+ * @param {string} param.MODULE_NAME
8
+ * @param {string} param.MODEL_NAME
9
+ * @param {string} [param.actionName="update"]
10
+ * @param {string} [param.dataFieldName = "_data"]
11
+ * @param {Array<function>} [param.validators = []]
12
+ * @param {Array<function>} [param.dataValidators = []],
13
+ * @param {function} [param.afterExtract = async (input , req) => input]
14
+ * @param {function} [param.afterDataExtract = async (input, req) => input]
15
+ */
16
+ function genericUpdateForm({
17
+ MODULE_NAME,
18
+ MODEL_NAME,
19
+ actionName = "update",
20
+ dataFieldName = "_data",
21
+ validators = [],
22
+ dataValidators = [],
23
+ afterExtract = async (input /*, req*/) => input,
24
+ afterDataExtract = async (input /*, req*/) => input,
25
+ }) {
26
+ const defaultDataFieldPath = Form.createPath(
27
+ MODULE_NAME,
28
+ MODEL_NAME,
29
+ dataFieldName
30
+ );
31
+
32
+ const dataFieldDefinition = getGenericDataField({
33
+ fieldPath: defaultDataFieldPath,
34
+ MODULE_NAME,
35
+ MODEL_NAME,
36
+ validators: dataValidators,
37
+ afterExtract: afterDataExtract,
38
+ });
39
+
40
+ const FIELDS = [
41
+ ["targetId", { required: true }, "not-node//objectId"],
42
+ ["identity", "not-node//identity"],
43
+ ["data", dataFieldDefinition],
44
+ ];
45
+
46
+ return class extends Form {
47
+ constructor({ app }) {
48
+ super({ FIELDS, app, MODULE_NAME, MODEL_NAME, actionName });
49
+ }
50
+
51
+ async afterExtract(input, req) {
52
+ input = await super.afterExtract(input, req);
53
+ return await afterExtract(input, req);
54
+ }
55
+
56
+ getFormValidationRules() {
57
+ return validators;
58
+ }
59
+ };
60
+ }
61
+
62
+ module.exports = genericUpdateForm;
@@ -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");