not-node 6.3.87 → 6.3.89

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.3.87",
3
+ "version": "6.3.89",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -37,15 +37,15 @@ export default (inquirer, config, layersList) => {
37
37
  layers: await entityLayers(inquirer, config, layersList),
38
38
  };
39
39
  if (result.layers.includes("models")) {
40
- result.fieldsShortNames = result.fields.map((itm) => itm.indexOf('//') > 0?itm.split('//')[1]:itm);
40
+ result.fieldsShortNames = result.fields.map((itm) => itm[0]);
41
41
  result.validators = await modelValidators(inquirer);
42
- result.versioning = await modelVersioning(inquirer);
42
+ result.versioning = await modelVersioning(inquirer);
43
43
  result.ownage = await modelOwnage(inquirer);
44
- result.ownageFields = result.ownage?['not-node//owner','not-node//ownerModel']:[];
44
+ result.ownageFields = result.ownage?[['owner','not-node//owner'],['ownerModel','not-node//ownerModel']]:[];
45
45
  result.dates = await modelDates(inquirer);
46
- result.datesFields = result.dates?['not-node//createdAt','not-node//updatedAt']:[];
47
- const fieldsCompleteList = [...result.fields, ...result.ownageFields, ...result.datesFields];
48
- result.increment = await modelIncrement(inquirer, {fields:fieldsCompleteList});
46
+ result.datesFields = result.dates?[['createdAt','not-node//createdAt'],['updatedAt','not-node//updatedAt']]:[];
47
+ const fieldsCompleteList = [...result.fields, ...result.ownageFields, ...result.datesFields].map(itm=>itm[0]);
48
+ result.increment = await modelIncrement(inquirer, { fields: fieldsCompleteList });
49
49
  } else {
50
50
  result.fields = [];
51
51
  result.fieldsShortNames = [];
@@ -56,7 +56,7 @@ export default (inquirer, config, layersList) => {
56
56
  result.ownageFields = [];
57
57
  result.dates = false;
58
58
  result.datesFields = [];
59
- }
59
+ }
60
60
  return result;
61
61
  } catch (e) {
62
62
  console.error(e);
@@ -3,12 +3,14 @@ export default async (inquirer, config) => {
3
3
  let finished = false;
4
4
  while (!finished) {
5
5
  try {
6
+ let fieldtype = "";
7
+ let fieldname = "";
6
8
  await inquirer
7
9
  .prompt([
8
10
  {
9
11
  type: "autocomplete",
10
- message: "Enter field name you want to be in model",
11
- name: "fieldname",
12
+ message: "Enter model field type",
13
+ name: "fieldtype",
12
14
  source: async (answers, input = "") => {
13
15
  let searchResults = [];
14
16
  try {
@@ -29,9 +31,32 @@ export default async (inquirer, config) => {
29
31
  },
30
32
  ])
31
33
  .then((answer) => {
32
- result.push(answer.fieldname.trim());
34
+ fieldtype = answer.fieldtype.trim();
35
+ });
36
+ await inquirer
37
+ .prompt([
38
+ {
39
+ message: "Enter model field name",
40
+ name: "fieldname",
41
+ default:
42
+ fieldtype.indexOf("//") > 0
43
+ ? fieldtype.split("//")[1]
44
+ : fieldtype,
45
+ validate: (str) => {
46
+ if (str.indexOf("//") > -1) {
47
+ return "Should not have // in it";
48
+ }
49
+ if (!/[_A-z0-9]+/.test(str)) {
50
+ return "Should comply to [_A-z0-9]+";
51
+ }
52
+ return true;
53
+ },
54
+ },
55
+ ])
56
+ .then((answer) => {
57
+ fieldname = answer.fieldname.trim();
33
58
  });
34
-
59
+ result.push([fieldname, fieldtype]);
35
60
  finished = await inquirer
36
61
  .prompt([
37
62
  {
package/src/form/form.js CHANGED
@@ -87,6 +87,7 @@ class Form {
87
87
  * @param {string} options.FORM_NAME
88
88
  * @param {string} options.MODEL_NAME
89
89
  * @param {string} options.MODULE_NAME
90
+ * @param {string} options.actionName
90
91
  * @param {import('../app.js')} options.app
91
92
  * @param {Object.<string, Function>} options.EXTRACTORS
92
93
  * @param {Object.<string, Function>} options.TRANSFORMERS
@@ -100,6 +101,7 @@ class Form {
100
101
  FORM_NAME,
101
102
  MODEL_NAME,
102
103
  MODULE_NAME,
104
+ actionName,
103
105
  app,
104
106
  EXTRACTORS = {},
105
107
  ENV_EXTRACTORS = {},
@@ -108,7 +110,7 @@ class Form {
108
110
  AFTER_EXTRACT_TRANSFORMERS = [],
109
111
  rate,
110
112
  }) {
111
- this.#FORM_NAME = FORM_NAME;
113
+ this.#FORM_NAME = FORM_NAME ?? this.createName(MODULE_NAME, MODEL_NAME, actionName);
112
114
  this.#MODEL_NAME = MODEL_NAME;
113
115
  this.#MODULE_NAME = MODULE_NAME;
114
116
  this.#PROTO_FIELDS = FIELDS;
@@ -130,10 +132,10 @@ class Form {
130
132
  * Creates model name string used in logging
131
133
  * @param {string} MODULE_NAME
132
134
  * @param {string|undefined} MODEL_NAME
133
- * @param {string} actionName
135
+ * @param {string} actionName = 'data'
134
136
  * @returns {string}
135
137
  */
136
- static createName(MODULE_NAME, MODEL_NAME, actionName) {
138
+ static createName(MODULE_NAME, MODEL_NAME, actionName = 'data') {
137
139
  if (MODEL_NAME) {
138
140
  return `${MODULE_NAME}:${MODEL_NAME}:${firstLetterToUpper(
139
141
  actionName
@@ -174,7 +176,7 @@ class Form {
174
176
  static createDefaultInstance({ app, MODULE_NAME, MODEL_NAME, actionName }) {
175
177
  const FIELDS = [
176
178
  ["identity", "not-node//identity"],
177
- ["data", `${MODULE_NAME}//_${MODEL_NAME}`],
179
+ ["data", `${MODULE_NAME}//_${firstLetterToLower(MODEL_NAME)}`],
178
180
  ];
179
181
  const FORM_NAME = Form.createName(MODULE_NAME, MODEL_NAME, actionName);
180
182
  return new Form({ FIELDS, FORM_NAME, app, MODULE_NAME });
@@ -660,6 +662,9 @@ class Form {
660
662
  if (typeof schemaField === "undefined" || schemaField === null) {
661
663
  return [];
662
664
  }
665
+ if(schemaField.transformers && Array.isArray(schemaField.transformers)){
666
+ return schemaField.transformers;
667
+ }
663
668
  switch (schemaField.type) {
664
669
  case String:
665
670
  case Schema.Types.String:
package/src/types.js CHANGED
@@ -159,13 +159,14 @@
159
159
 
160
160
  /**
161
161
  * @typedef {object} notFieldModel
162
- * @property {notFieldModelType} type
163
- * @property {any} default default value
164
- * @property {boolean} [sortable] if field is sortable
165
- * @property {boolean} [required] if required to be defined
166
- * @property {notFieldSafety} [safe] safety requirements
167
- * @property {string} [ref] mongoose model name, if type is ObjectId
168
- * @property {string} [refPath] path to field with name of mongoose model this field value of ObjectId type reference to
162
+ * @property {notFieldModelType} type
163
+ * @property {Array<string>} [transformers] list of transformers names to pipe down aka ['xss', 'trim', 'removeDots', 'maxLength1000'], used in Form as default transforming pipeline on data extraction stage
164
+ * @property {any} default default value
165
+ * @property {boolean} [sortable] if field is sortable
166
+ * @property {boolean} [required] if required to be defined
167
+ * @property {notFieldSafety} [safe] safety requirements
168
+ * @property {string} [ref] mongoose model name, if type is ObjectId
169
+ * @property {string} [refPath] path to field with name of mongoose model this field value of ObjectId type reference to
169
170
  */
170
171
 
171
172
  /**
@@ -45,8 +45,8 @@ class nc<%- ModelName %>Common extends notCRUD {
45
45
  <% } %>
46
46
  <% for (let fieldName of fields){ %>
47
47
  {
48
- path: ":<%- fieldName %>",
49
- title: `${MODULE_NAME}:<%- `${modelName}_field_${fieldName}_label` %>`,
48
+ path: ":<%- fieldName[0] %>",
49
+ title: `${MODULE_NAME}:<%- `${modelName}_field_${fieldName[0]}_label` %>`,
50
50
  searchable: true,
51
51
  sortable: true,
52
52
  },
@@ -66,7 +66,7 @@ class nc<%- ModelName %>Common extends notCRUD {
66
66
 
67
67
  createDefault() {
68
68
  let newRecord = this.getModel({
69
- <% for (let fieldName of fields){ %><%- fieldName %>: undefined,
69
+ <% for (let fieldName of fields){ %><%- fieldName[0] %>: undefined,
70
70
  <% } %>
71
71
  });
72
72
  return newRecord;
@@ -1,4 +1,4 @@
1
- import notValidationError from 'not-error/src/validation.error.browser.js';
1
+ import notValidationError from 'not-error/src/validation.error.browser.mjs';
2
2
  /*
3
3
  import vVariableLength from '../../fields/validators/variableLength.js';
4
4
  const ERR_MSG_FORM_IS_DIRTY = '<%- ModuleName %>:form_is_dirty';
@@ -14,7 +14,7 @@ module.exports = {
14
14
  return notNode.Application.getForm(
15
15
  `${MODULE_NAME}//_${firstLetterToLower(
16
16
  MODEL_NAME
17
- )}_data`
17
+ )}`
18
18
  ).run(val);
19
19
  },
20
20
  message: `${MODULE_NAME}:${firstLetterToLower(MODEL_NAME)}`,
@@ -1,25 +1,18 @@
1
1
  const { MODULE_NAME } = require("../const");
2
+ const MODEL_NAME = '<%- ModelName %>';
3
+ const actionName = '_data';
2
4
 
3
5
  const Form = require("not-node").Form;
4
6
 
5
- const FIELDS = [
6
- <% if (fields && Array.isArray(fields)) { %>
7
- <% for(let field of fields){ %>
8
- <%- `"${field}",` -%>
9
- <% } %>
10
- <% } %>
11
- <% if (ownage) { %>
12
- ["owner", "not-node//owner"],
13
- ["ownerModel", "not-node//ownerModel"],
14
- <% } %>
15
- ];
7
+ const FIELDS = [<% if (fields && Array.isArray(fields)) { %><% for(let field of fields){ %>["<%- field[0] %>", "<%- field[1] %>"],
8
+ <% } %><% } %>];
16
9
 
17
- const FORM_NAME = `${MODULE_NAME}:_<%- ModelName %>DataForm`;
10
+ const FORM_NAME = Form.createName(MODULE_NAME, MODEL_NAME, actionName);
18
11
 
19
12
  //const validateTitle = require("./validators/title.js");
20
- class _<%- ModelName %>_DataForm extends Form {
13
+ class _<%- ModelName %>Form extends Form {
21
14
  constructor({ app }) {
22
- super({ FIELDS, FORM_NAME, app });
15
+ super({MODULE_NAME,MODEL_NAME,actionName, FIELDS, FORM_NAME, app });
23
16
  }
24
17
 
25
18
  //could do something with data, before validation
@@ -36,4 +29,4 @@ class _<%- ModelName %>_DataForm extends Form {
36
29
  }
37
30
  }
38
31
 
39
- module.exports = _<%- ModelName %>_DataForm;
32
+ module.exports = _<%- ModelName %>Form;
@@ -8,7 +8,7 @@ const FORM_NAME = Form.createName(MODULE_NAME, MODEL_NAME, actionName);
8
8
  //form
9
9
  const FIELDS = [
10
10
  ["identity", "not-node//identity"],
11
- ["data", `${MODULE_NAME}//_<%- modelName %>_data`],
11
+ ["data", `${MODULE_NAME}//_<%- modelName %>`],
12
12
  ];
13
13
 
14
14
  /**
@@ -16,33 +16,7 @@ const FIELDS = [
16
16
  **/
17
17
  class <%- ModelName %>CreateForm extends Form {
18
18
  constructor({ app }) {
19
- super({ FIELDS, FORM_NAME, app });
20
- }
21
-
22
- /**
23
- * Extracts data
24
- * @param {import('not-node/src/types.js').notNodeExpressRequest} req expressjs request object
25
- * @return {Promise<Object>} form data
26
- **/
27
- async extract(req) {
28
- const data = this.extractByInstructionsFromRouteActionFields(
29
- req, //request object
30
- ["fromBody", "xss"], //extraction common pipe [extractor, ...transformers]
31
- {} //exceptions {fieldName: [extractor, ...transformers],...}
32
- );
33
- //contains targetId, identity and some more. look full list in not-node/src/form/env_extractors/index.js
34
- const envs = this.extractRequestEnvs(req);
35
- <% if ( ownage ) { %>
36
- //admin could change ownage for others hardwired
37
- if (!identity.admin) {
38
- data.owner = identity.uid;
39
- data.ownerModel = 'User';
40
- }
41
- <% } %>
42
- return {
43
- ...envs,
44
- data
45
- };
19
+ super({MODULE_NAME, MODEL_NAME,actionName, FIELDS, FORM_NAME, app });
46
20
  }
47
21
  }
48
22
 
@@ -1,8 +1,10 @@
1
1
  const { MODULE_NAME } = require("../const");
2
+ const MODEL_NAME = '<%- ModelName %>';
2
3
  //DB related validation tools
3
4
  const notNode = require("not-node");
4
5
 
5
6
  module.exports = notNode.Generic.GenericGetByIdForm({
6
7
  MODULE_NAME,
8
+ MODEL_NAME,
7
9
  actionName: "delete",
8
10
  });
@@ -1,8 +1,9 @@
1
1
  const { MODULE_NAME } = require("../const");
2
+ const MODEL_NAME = '<%- ModelName %>';
2
3
  //DB related validation tools
3
4
  const notNode = require("not-node");
4
5
 
5
6
  module.exports = notNode.Generic.GenericGetByIdForm({
6
- MODULE_NAME,
7
+ MODULE_NAME,MODEL_NAME,
7
8
  actionName: "get",
8
9
  });
@@ -1,8 +1,9 @@
1
1
  const { MODULE_NAME } = require("../const");
2
+ const MODEL_NAME = '<%- ModelName %>';
2
3
  //DB related validation tools
3
4
  const notNode = require("not-node");
4
5
 
5
6
  module.exports = notNode.Generic.GenericGetByIdForm({
6
- MODULE_NAME,
7
+ MODULE_NAME,MODEL_NAME,
7
8
  actionName: "getRaw",
8
9
  });
@@ -1,8 +1,9 @@
1
1
  const notNode = require("not-node");
2
2
  const { MODULE_NAME } = require("../const");
3
+ const MODEL_NAME = '<%- ModelName %>';
3
4
 
4
5
  module.exports = notNode.Generic.GenericListAndCountForm({
5
- MODULE_NAME,
6
- MODEL_NAME: "<%- ModelName %>",
6
+ MODULE_NAME,
7
+ MODEL_NAME,
7
8
  actionName: "listAll",
8
- });
9
+ });
@@ -1,8 +1,9 @@
1
1
  const notNode = require("not-node");
2
2
  const { MODULE_NAME } = require("../const");
3
+ const MODEL_NAME = '<%- ModelName %>';
3
4
 
4
5
  module.exports = notNode.Generic.GenericListAndCountForm({
5
- MODULE_NAME,
6
- MODEL_NAME: "<%- ModelName %>",
6
+ MODULE_NAME,
7
+ MODEL_NAME,
7
8
  actionName: "listAndCount",
8
- });
9
+ });
@@ -2,35 +2,20 @@ const Form = require("not-node").Form;
2
2
 
3
3
  const { MODULE_NAME } = require("../const");
4
4
  const MODEL_NAME = '<%- ModelName %>';
5
+
5
6
  const actionName = 'update';
6
7
  const FORM_NAME = Form.createName(MODULE_NAME, MODEL_NAME, actionName);
7
8
 
8
9
  const FIELDS = [
9
10
  ["targetId", { required: true }, "not-node//objectId"],
10
11
  ["identity", "not-node//identity"],
11
- ["data", `${MODULE_NAME}//_<%- modelName %>_data`], //sub forms validators should start with underscore
12
+ ["data", `${MODULE_NAME}//_<%- modelName %>`], //sub forms validators should start with underscore
12
13
  ];
13
14
 
14
15
  class <%- ModelName %>UpdateForm extends Form {
15
16
  constructor({ app }) {
16
17
  super({ FIELDS, FORM_NAME, app });
17
18
  }
18
-
19
- async extract(req) {
20
- const data = this.extractByInstructionsFromRouteActionFields(req, ["fromBody", "xss"], {});
21
- const envs = this.extractRequestEnvs(req);
22
- <% if ( ownage ) { %>
23
- //admin could change ownage for others hardwired
24
- if (!identity.admin) {
25
- data.owner && delete data.owner;
26
- data.ownerModel && delete data.ownerModel;
27
- }
28
- <% } %>
29
- return {
30
- ...envs, //contains targetId, identity and some more. look list in not-node/src/form/env_extractors/index.js
31
- data,
32
- };
33
- }
34
19
  }
35
20
 
36
21
  module.exports = <%- ModelName %>UpdateForm;
@@ -1,46 +1,20 @@
1
1
  const { MODULE_NAME } = require("../const");
2
+ const MODEL_NAME = '<%- ModelName %>';
2
3
  //DB related validation tools
3
4
  const Form = require("not-node").Form;
4
5
  //form
5
6
  const FIELDS = [
6
7
  ["identity", "not-node//identity"],
7
- ["data", `${MODULE_NAME}//_data`],
8
+ ["data", `${MODULE_NAME}//_<%- modelName %>`],
8
9
  ];
9
10
 
10
- const FORM_NAME = `${MODULE_NAME}:CreateForm`;
11
+ const FORM_NAME = Form.createName(MODULE_NAME, MODEL_NAME, actionName);
11
12
  const USER_MODEL_NAME = "User";
12
13
  /**
13
14
  *
14
15
  **/
15
- module.exports = class CreateForm extends Form {
16
+ module.exports = class extends Form {
16
17
  constructor({ app }) {
17
- super({ FIELDS, FORM_NAME, app });
18
- }
19
-
20
- /**
21
- * Extracts data
22
- * @param {ExpressRequest} req expressjs request object
23
- * @return {Object} forma data
24
- **/
25
- extract(req) {
26
- const ip = getIP(req);
27
- const instructions = {
28
- title: "fromBody",
29
- keys: "fromBody",
30
- owner: "fromBody", //req.body.owner || req.user._id.toString(),
31
- ownerModel: "fromBody", //req.body.ownerModel || USER_MODEL_NAME,
32
- };
33
- const data = this.extractByInstructions(req, instructions);
34
-
35
- if (!req.user.isRoot() && !req.user.isAdmin()) {
36
- data.owner = req.user._id.toString();
37
- data.ownerModel = USER_MODEL_NAME;
38
- }
39
-
40
- return {
41
- data,
42
- activeUser: req.user,
43
- ip,
44
- };
18
+ super({MODULE_NAME, MODEL_NAME, FIELDS, FORM_NAME, app });
45
19
  }
46
20
  };
@@ -17,19 +17,13 @@ module.exports.enrich = {
17
17
  };
18
18
 
19
19
  const FIELDS = [
20
- <% if (fields && Array.isArray(fields)) { %>
21
- <% for(let field of fields){ %>
22
- "<%- field %>",
23
- <% } %>
24
- <% } %>
25
- <% if (ownage){ %>
26
- ["owner", "not-node//owner"],
27
- ["ownerModel", "not-node//ownerModel"],
28
- <% } %>
29
- <% if (dates){ %>
30
- ["createdAt", "not-node//createdAt"],
31
- ["updatedAt", "not-node//updatedAt"],
32
- <% } %>
20
+ <% if (increment){ %>["<%- modelName %>ID", "not-node//ID"],<% } %>
21
+ <% if (fields && Array.isArray(fields)) { %><% for(let field of fields){ %>["<%- field[0] %>", "<%- field[1] %>"],
22
+ <% } %><% } %>
23
+ <% if (ownage && ownageFields && Array.isArray(ownageFields)){ %><% for(let field of ownageFields){ %>["<%- field[0] %>", "<%- field[1] %>"],
24
+ <% } %><% } %>
25
+ <% if (dates && datesFields && Array.isArray(datesFields)){ %><% for(let field of datesFields){ %>["<%- field[0] %>", "<%- field[1] %>"],
26
+ <% } %><% } %>
33
27
  ];
34
28
 
35
29
  module.exports.FIELDS = FIELDS;
@@ -3,16 +3,16 @@ const { firstLetterToLower } = require("not-node").Common;
3
3
  const ACTION_SIGNATURES = require('not-node/src/auth/const').ACTION_SIGNATURES;
4
4
  const MODEL_NAME = "<%- ModelName %>";
5
5
  const modelName = firstLetterToLower(MODEL_NAME);
6
- <% const fieldsShortNames = (fields | []).map((entry) => entry.indexOf('//')>-1?entry.split('//')[0]:entry); %>
6
+
7
7
  const FIELDS = [
8
8
  ["_id", "not-node//_id"],
9
9
  <% if (increment){ %>["<%- modelName %>ID", "not-node//ID"],<% } %>
10
- <% if (fields && Array.isArray(fields)) { %><% for(let field of fields){ %>"<%- field %>",
10
+ <% if (fields && Array.isArray(fields)) { %><% for(let field of fields){ %>["<%- field[0] %>", "<%- field[1] %>"],
11
+ <% } %><% } %>
12
+ <% if (ownage && ownageFields && Array.isArray(ownageFields)){ %><% for(let field of ownageFields){ %>["<%- field[0] %>", "<%- field[1] %>"],
13
+ <% } %><% } %>
14
+ <% if (dates && datesFields && Array.isArray(datesFields)){ %><% for(let field of datesFields){ %>["<%- field[0] %>", "<%- field[1] %>"],
11
15
  <% } %><% } %>
12
- <% if (ownage){ %>["owner", "not-node//owner"],
13
- ["ownerModel", "not-node//ownerModel"],<% } %>
14
- <% if (dates){ %> ["createdAt", "not-node//createdAt"],
15
- ["updatedAt", "not-node//updatedAt"],<% } %>
16
16
  ];
17
17
 
18
18
  const actionNamePath = "/:actionName";
@@ -6,12 +6,14 @@ const getLogic = () =>
6
6
  notNode.Application.getLogic(`${MODULE_NAME}//${MODEL_NAME}`);
7
7
 
8
8
 
9
- async function someAction({ data, client }) {
9
+ async function someAction({
10
+ data, //client request data
11
+ client, //wsclient object
12
+ identity //notAppIdentityData
13
+ }) {
10
14
  return await getLogic().getData({
11
15
  data,
12
- activeUser: client.identity,
13
- ip: client.getIP(),
14
- root: false,
16
+ identity
15
17
  });
16
18
  }
17
19