not-node 6.3.87 → 6.3.88

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.88",
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
@@ -174,7 +174,7 @@ class Form {
174
174
  static createDefaultInstance({ app, MODULE_NAME, MODEL_NAME, actionName }) {
175
175
  const FIELDS = [
176
176
  ["identity", "not-node//identity"],
177
- ["data", `${MODULE_NAME}//_${MODEL_NAME}`],
177
+ ["data", `${MODULE_NAME}//_${firstLetterToLower(MODEL_NAME)}`],
178
178
  ];
179
179
  const FORM_NAME = Form.createName(MODULE_NAME, MODEL_NAME, actionName);
180
180
  return new Form({ FIELDS, FORM_NAME, app, MODULE_NAME });
@@ -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)}`,
@@ -2,22 +2,13 @@ const { MODULE_NAME } = require("../const");
2
2
 
3
3
  const Form = require("not-node").Form;
4
4
 
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
- ];
5
+ const FIELDS = [<% if (fields && Array.isArray(fields)) { %><% for(let field of fields){ %>["<%- field[0] %>", "<%- field[1] %>"],
6
+ <% } %><% } %>];
16
7
 
17
- const FORM_NAME = `${MODULE_NAME}:_<%- ModelName %>DataForm`;
8
+ const FORM_NAME = Form.createName();
18
9
 
19
10
  //const validateTitle = require("./validators/title.js");
20
- class _<%- ModelName %>_DataForm extends Form {
11
+ class _<%- ModelName %>Form extends Form {
21
12
  constructor({ app }) {
22
13
  super({ FIELDS, FORM_NAME, app });
23
14
  }
@@ -36,4 +27,4 @@ class _<%- ModelName %>_DataForm extends Form {
36
27
  }
37
28
  }
38
29
 
39
- module.exports = _<%- ModelName %>_DataForm;
30
+ 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