not-node 6.3.86 → 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.
Files changed (31) hide show
  1. package/package.json +1 -1
  2. package/src/auth/fields.js +1 -1
  3. package/src/cli/const.mjs +1 -0
  4. package/src/cli/lib/entity.mjs +2 -2
  5. package/src/cli/lib/fs.mjs +25 -19
  6. package/src/cli/lib/module.server.mjs +12 -11
  7. package/src/cli/readers/entityData.mjs +9 -2
  8. package/src/cli/readers/fields.mjs +29 -4
  9. package/src/cli/renderers/controllersCommons.mjs +2 -2
  10. package/src/cli/renderers/controllersIndex.mjs +13 -7
  11. package/src/cli/renderers/fields.mjs +1 -1
  12. package/src/cli/renderers/forms.mjs +1 -1
  13. package/src/cli/renderers/models.mjs +1 -1
  14. package/src/form/form.js +1 -1
  15. package/src/manifest/result.filter.js +1 -1
  16. package/test/common.js +1 -1
  17. package/tmpl/files/module.server/layers/controllers/common/crud.ejs +3 -3
  18. package/tmpl/files/module.server/layers/controllers/common/validators.ejs +1 -1
  19. package/tmpl/files/module.server/layers/fields.data.ejs +1 -1
  20. package/tmpl/files/module.server/layers/forms/_data.ejs +5 -14
  21. package/tmpl/files/module.server/layers/forms/create.ejs +2 -28
  22. package/tmpl/files/module.server/layers/forms/delete.ejs +2 -0
  23. package/tmpl/files/module.server/layers/forms/get.ejs +2 -1
  24. package/tmpl/files/module.server/layers/forms/getRaw.ejs +2 -1
  25. package/tmpl/files/module.server/layers/forms/listAll.ejs +4 -3
  26. package/tmpl/files/module.server/layers/forms/listAndCount.ejs +4 -3
  27. package/tmpl/files/module.server/layers/forms/update.ejs +2 -17
  28. package/tmpl/files/module.server/layers/forms.ejs +5 -31
  29. package/tmpl/files/module.server/layers/models.ejs +7 -13
  30. package/tmpl/files/module.server/layers/routes.manifest.ejs +15 -14
  31. package/tmpl/files/module.server/layers/routes.ws.ejs +6 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "not-node",
3
- "version": "6.3.86",
3
+ "version": "6.3.88",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -34,7 +34,7 @@ function isOwner(
34
34
  ownerFieldName = CONST.DOCUMENT_OWNER_FIELD_NAME
35
35
  ) {
36
36
  const ownerId = getOwnerId(data, ownerFieldName);
37
- console.log("ownerId", ownerId, typeof ownerId);
37
+
38
38
  if (typeof ownerId !== "undefined") {
39
39
  return COMMON.compareObjectIds(ownerId, user_id);
40
40
  } else {
package/src/cli/const.mjs CHANGED
@@ -32,6 +32,7 @@ const DEFAULT_MODULE_LAYERS = [
32
32
  export { DEFAULT_MODULE_LAYERS };
33
33
 
34
34
  const DEFAULT_ENTITY_LAYERS = [
35
+ "fields",
35
36
  "forms",
36
37
  "models",
37
38
  "logics",
@@ -39,13 +39,13 @@ async function createEntity(modules_dir, config) {
39
39
  const moduleDir = resolve(modules_dir, ModuleName);
40
40
  const moduleLayers = await Readers.moduleLayers(inquirer);
41
41
  const moduleConfig = { ...config, moduleName, ModuleName, moduleLayers };
42
- console.log("moduleConfig", moduleConfig);
42
+ // console.log("moduleConfig", moduleConfig);
43
43
  const entityData = await Readers.entityData(
44
44
  inquirer,
45
45
  moduleConfig,
46
46
  moduleConfig.moduleLayers
47
47
  );
48
- console.log("entityData", entityData);
48
+ //console.log("entityData", entityData);
49
49
  await renderEntityFiles(
50
50
  resolve(moduleDir, "./src"),
51
51
  entityData,
@@ -28,22 +28,30 @@ import Options from "./opts.mjs";
28
28
  const PATH_TMPL = Options.PATH_TMPL;
29
29
 
30
30
  async function renderFile(input, dest, data) {
31
- Logger.log("render", dest);
32
- const renderedFileContent = await ejs.renderFile(input, data, {
33
- async: true,
34
- });
35
- await writeFile(dest, renderedFileContent);
31
+ try{
32
+ Logger.log("render", dest);
33
+ const renderedFileContent = await ejs.renderFile(input, data, {
34
+ async: true,
35
+ });
36
+ await writeFile(dest, renderedFileContent);
37
+ }catch(e){
38
+ console.error(e);
39
+ }
36
40
  }
37
41
 
38
42
  async function createFileContent(filePath, structure, config) {
39
- if (typeof structure == "string") {
40
- await copyTmplFile(resolve(PATH_TMPL, structure), filePath);
41
- return;
42
- }
43
- if (Object.hasOwn(structure, "tmpl")) {
44
- const tmplFilePath = resolve(PATH_TMPL, structure.tmpl);
45
- const data = await readArgs(structure, config);
46
- await renderFile(tmplFilePath, filePath, data);
43
+ try{
44
+ if (typeof structure == "string") {
45
+ await copyTmplFile(resolve(PATH_TMPL, structure), filePath);
46
+ return;
47
+ }
48
+ if (Object.hasOwn(structure, "tmpl")) {
49
+ const tmplFilePath = resolve(PATH_TMPL, structure.tmpl);
50
+ const data = await readArgs(structure, config);
51
+ await renderFile(tmplFilePath, filePath, data);
52
+ }
53
+ }catch(e){
54
+ console.error(e);
47
55
  }
48
56
  }
49
57
 
@@ -74,10 +82,10 @@ function getProjectSiteDir(dir, CWD) {
74
82
 
75
83
  async function createDir(dirPath) {
76
84
  try {
77
- //console.log("mkdir", dirPath);
85
+ console.log("mkdir", dirPath);
78
86
  await mkdir(dirPath, { recursive: true });
79
87
  } catch {
80
- // console.error("Can't create directory", dirPath);
88
+ console.error("Can't create directory", dirPath);
81
89
  }
82
90
  }
83
91
 
@@ -232,8 +240,7 @@ async function findAllFieldsInModules(modulesDirPath) {
232
240
  const modulesNames = await readdir(modulesDirPath);
233
241
  const result = [];
234
242
  for (const moduleName of modulesNames) {
235
- if (moduleName && moduleName.indexOf("not-") === 0) {
236
- console.log("searchin in ", moduleName);
243
+ if (moduleName && moduleName.indexOf("not-") === 0) {
237
244
  const listOfFieldsInModule = await findFieldsInModule(
238
245
  join(modulesDirPath, moduleName)
239
246
  );
@@ -246,8 +253,7 @@ async function findAllFieldsInModules(modulesDirPath) {
246
253
  fullName: `${moduleName}//${fieldName}`,
247
254
  };
248
255
  }
249
- );
250
- console.log(listOfFieldsDescriptions);
256
+ );
251
257
  result.push(...listOfFieldsDescriptions);
252
258
  }
253
259
  }
@@ -1,5 +1,5 @@
1
1
  import { firstLetterToLower } from "../../../src/common.js";
2
- import { resolve } from "node:path";
2
+ import { join } from "node:path";
3
3
  import inquirer from "inquirer";
4
4
  import inquirerPrompt from "inquirer-autocomplete-prompt";
5
5
 
@@ -26,10 +26,10 @@ function entitiesInLayers(layersList = []) {
26
26
 
27
27
  async function createLayersDirs(modules_dir, layersList, ModuleName) {
28
28
  if (layersList.length) {
29
- await createDir(resolve(modules_dir, ModuleName, "./src"));
29
+ await createDir(join(modules_dir, ModuleName, "./src"));
30
30
  }
31
31
  for (let layer of layersList) {
32
- await createDir(resolve(modules_dir, ModuleName, "./src", layer));
32
+ await createDir(join(modules_dir, ModuleName, "./src", layer));
33
33
  }
34
34
  }
35
35
 
@@ -38,7 +38,8 @@ async function renderServerControllersCommons(
38
38
  entitiesData,
39
39
  config
40
40
  ) {
41
- const dirPath = resolve(module_src_dir, `./common`);
41
+ const dirPath = join(module_src_dir, `./common`);
42
+ //console.log('renderServerControllersCommons',dirPath);
42
43
  await createDir(dirPath);
43
44
  await createDirContent(
44
45
  dirPath,
@@ -62,7 +63,7 @@ async function renderServerContollersIndexes(
62
63
  const subDirList = [...config.roles];
63
64
  for (let dirName of subDirList) {
64
65
  await Renderers.controllersIndex(
65
- resolve(module_src_dir, `./controllers/${dirName}`),
66
+ join(module_src_dir, `./controllers/${dirName}`),
66
67
  entitiesData,
67
68
  config,
68
69
  renderFile,
@@ -71,12 +72,12 @@ async function renderServerContollersIndexes(
71
72
  }
72
73
  }
73
74
 
74
- async function createServerModule(modules_dir, config) {
75
+ async function createServerModule(modules_dir, config, availableFields) {
75
76
  //read module name
76
77
  const ModuleName = await Readers.ModuleName(inquirer);
77
78
  const moduleName = firstLetterToLower(ModuleName);
78
- const moduleDir = resolve(modules_dir, ModuleName);
79
- const moduleConfig = { ...config, moduleName, ModuleName };
79
+ const moduleDir = join(modules_dir, ModuleName);
80
+ const moduleConfig = { ...config, moduleName, ModuleName, availableFields };
80
81
  await createDir(moduleDir);
81
82
  //console.log(JSON.stringify(moduleConfig, null, 4));
82
83
  await createDirContent(
@@ -100,19 +101,19 @@ async function createServerModule(modules_dir, config) {
100
101
  }
101
102
  for (let entityData of entitiesList) {
102
103
  await renderEntityFiles(
103
- resolve(moduleDir, "./src"),
104
+ join(moduleDir, "./src"),
104
105
  entityData,
105
106
  moduleConfig
106
107
  );
107
108
  }
108
109
  if (layersList.includes("controllers")) {
109
110
  await renderServerContollersIndexes(
110
- resolve(moduleDir, "./src"),
111
+ join(moduleDir, "./src"),
111
112
  entitiesList,
112
113
  moduleConfig
113
114
  );
114
115
  await renderServerControllersCommons(
115
- resolve(moduleDir, "./src/controllers"),
116
+ join(moduleDir, "./src/controllers"),
116
117
  entitiesList,
117
118
  moduleConfig
118
119
  );
@@ -37,19 +37,26 @@ 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[0]);
40
41
  result.validators = await modelValidators(inquirer);
41
42
  result.versioning = await modelVersioning(inquirer);
42
- result.increment = await modelIncrement(inquirer, result);
43
43
  result.ownage = await modelOwnage(inquirer);
44
+ result.ownageFields = result.ownage?[['owner','not-node//owner'],['ownerModel','not-node//ownerModel']]:[];
44
45
  result.dates = await modelDates(inquirer);
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 });
45
49
  } else {
50
+ result.fields = [];
51
+ result.fieldsShortNames = [];
46
52
  result.increment = false;
47
53
  result.versioning = false;
48
54
  result.validators = true;
49
55
  result.ownage = false;
56
+ result.ownageFields = [];
50
57
  result.dates = false;
58
+ result.datesFields = [];
51
59
  }
52
- console.log("Entity data", JSON.stringify(result));
53
60
  return result;
54
61
  } catch (e) {
55
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
  {
@@ -7,8 +7,8 @@ export default async (
7
7
  config,
8
8
  createFileContent,
9
9
  PATH_TMPL
10
- ) => {
11
- for (let entityData of entitiesList) {
10
+ ) => {
11
+ for (let entityData of entitiesList) {
12
12
  const TMPL_FILE_PATH = resolve(PATH_TMPL, TEMPLATES_DIR, `crud.ejs`);
13
13
  const DEST_FILE_PATH = resolve(
14
14
  module_layer_dir,
@@ -9,11 +9,17 @@ export default async (
9
9
  createFileContent,
10
10
  PATH_TMPL
11
11
  ) => {
12
- const TMPL_FILE_PATH = resolve(PATH_TMPL, CONTROLLER_INDEX_TMPL);
13
- const DEST_FILE_PATH = resolve(module_layer_dir, `index.js`);
14
- console.log("creating", TMPL_FILE_PATH, DEST_FILE_PATH);
15
- await createFileContent(TMPL_FILE_PATH, DEST_FILE_PATH, {
16
- ...config,
17
- entities: data,
18
- });
12
+ try{
13
+ const TMPL_FILE_PATH = resolve(PATH_TMPL, CONTROLLER_INDEX_TMPL);
14
+ const DEST_FILE_PATH = resolve(module_layer_dir, `index.js`);
15
+ console.log("creating", TMPL_FILE_PATH, DEST_FILE_PATH);
16
+ await createFileContent(TMPL_FILE_PATH, DEST_FILE_PATH, {
17
+ ...config,
18
+ entities: data,
19
+ });
20
+ }catch(e){
21
+
22
+ console.error(module_layer_dir,e);
23
+ }
24
+
19
25
  };
@@ -19,7 +19,7 @@ export default async (
19
19
  );
20
20
  const DEST_FILE_PATH_DATA = resolve(
21
21
  module_layer_dir,
22
- `_${data.modelName}_data.js`
22
+ `_${data.modelName}.js`
23
23
  );
24
24
  await renderEntityDataField(
25
25
  createFileContent,
@@ -56,7 +56,7 @@ export default async (
56
56
  const TMPL_FILE_PATH_DATA = resolve(PATH_TMPL, TEMPLATES_DIR, `_data.ejs`);
57
57
  const DEST_FILE_PATH_DATA = resolve(
58
58
  module_layer_dir,
59
- `_${data.modelName}_data.js`
59
+ `_${data.modelName}.js`
60
60
  );
61
61
  await renderEntityActionForm(
62
62
  createFileContent,
@@ -11,6 +11,6 @@ export default async (
11
11
  const TMPL_FILE_PATH = resolve(PATH_TMPL, TEMPLATE_FILE);
12
12
  const DEST_FILE_PATH = resolve(module_layer_dir, `${data.modelName}.js`);
13
13
  const args = { ...config, ...data };
14
- console.log(JSON.stringify(args, null, 4));
14
+ //console.log(JSON.stringify(args, null, 4));
15
15
  await createFileContent(TMPL_FILE_PATH, DEST_FILE_PATH, args);
16
16
  };
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 });
@@ -190,7 +190,7 @@ module.exports = class notManifestRouteResultFilter {
190
190
  }
191
191
 
192
192
  static filterStrict(target, filteringArray) {
193
- console.log(target, filteringArray);
193
+ //console.log(target, filteringArray);
194
194
  //to form ['id', 'user', 'files']
195
195
  const filteringArrayDirectChildren = filteringArray.map(
196
196
  (propName) => propName.split(notPath.PATH_SPLIT)[0]
package/test/common.js CHANGED
@@ -99,7 +99,7 @@ describe("Common", function () {
99
99
  let to = undefined;
100
100
  try {
101
101
  Common.mapBind({ getModel() {} }, to, ["getModel"]);
102
- console.log(to);
102
+ //console.log(to);
103
103
  done(new Error("should throw"));
104
104
  } catch (e) {
105
105
  expect(e).to.be.instanceof(Error);
@@ -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;
@@ -7,11 +7,12 @@ const modelName = firstLetterToLower(MODEL_NAME);
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 %>",<% } %><% } %>
11
- <% if (ownage){ %>["owner", "not-node//owner"],
12
- ["ownerModel", "not-node//ownerModel"],<% } %>
13
- <% if (dates){ %> ["createdAt", "not-node//createdAt"],
14
- ["updatedAt", "not-node//updatedAt"],<% } %>
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] %>"],
15
+ <% } %><% } %>
15
16
  ];
16
17
 
17
18
  const actionNamePath = "/:actionName";
@@ -33,12 +34,12 @@ module.exports = {
33
34
  {
34
35
  auth: true,
35
36
  role: "admin",
36
- fields: [<%- fields.map((entry) => `"${entry}"`).join(',') %>,<% if (ownage){ %>"owner",<% } %>],
37
+ fields: [<%- fieldsShortNames.map((entry) => `"${entry}"`).join(',') %>,<% if (ownage){ %>"owner",<% } %>],
37
38
  },
38
39
  {
39
40
  auth: true,
40
41
  role: ["client", "confirmed"],
41
- fields: [<% if (fields && Array.isArray(fields)) { %><% for(let field of fields){ %>"<%- field %>",<% } %><% } %>],
42
+ fields: [<%- fieldsShortNames.map((entry) => `"${entry}"`).join(',') %>],
42
43
  },
43
44
  ],
44
45
  data: ["data"],
@@ -58,7 +59,7 @@ module.exports = {
58
59
  fields: [
59
60
  "_id",
60
61
  <% if (increment){ %>"<%- modelName %>ID",<% } %>
61
- <%- fields.map((entry) => `"${entry}"`).join(',') %>,
62
+ <%- fieldsShortNames.map((entry) => `"${entry}"`).join(',') %>,
62
63
  <% if (ownage){ %>"owner","ownerModel",<% } %>
63
64
  <% if (dates){ %>"createdAt","updatedAt",<% } %>
64
65
  ],
@@ -69,7 +70,7 @@ module.exports = {
69
70
  fields: [
70
71
  "_id",
71
72
  <% if (increment){ %>"<%- modelName %>ID",<% } %>
72
- <%- fields.map((entry) => `"${entry}"`).join(',') %>,
73
+ <%- fieldsShortNames.map((entry) => `"${entry}"`).join(',') %>,
73
74
  <% if (dates){ %>"createdAt","updatedAt",<% } %>
74
75
  ],
75
76
  },
@@ -90,7 +91,7 @@ module.exports = {
90
91
  fields: [
91
92
  "_id",
92
93
  <% if (increment){ %>"<%- modelName %>ID",<% } %>
93
- <%- fields.map((entry) => `"${entry}"`).join(',') %>,
94
+ <%- fieldsShortNames.map((entry) => `"${entry}"`).join(',') %>,
94
95
  <% if (ownage){ %>"owner","ownerModel",<% } %>
95
96
  <% if (dates){ %>"createdAt","updatedAt",<% } %>
96
97
  ],
@@ -100,7 +101,7 @@ module.exports = {
100
101
  role: ["client", "confirmed"],
101
102
  fields: [
102
103
  <% if (increment){ %>"<%- modelName %>ID",<% } %>
103
- <%- fields.map((entry) => `"${entry}"`).join(',') %>,
104
+ <%- fieldsShortNames.map((entry) => `"${entry}"`).join(',') %>,
104
105
  <% if (dates){ %>"createdAt","updatedAt",<% } %>
105
106
  ],
106
107
  },
@@ -119,14 +120,14 @@ module.exports = {
119
120
  auth: true,
120
121
  role: ["admin"],
121
122
  fields: [
122
- <%- fields.map((entry) => `"${entry}"`).join(',') %>,
123
+ <%- fieldsShortNames.map((entry) => `"${entry}"`).join(',') %>,
123
124
  <% if (ownage){ %>"owner", "ownerModel",<% } %>
124
125
  ],
125
126
  },
126
127
  {
127
128
  auth: true,
128
129
  role: ["client", "confirmed"],
129
- fields: [<%- fields.map((entry) => `"${entry}"`).join(',') %>],
130
+ fields: [<%- fieldsShortNames.map((entry) => `"${entry}"`).join(',') %>],
130
131
  },
131
132
  ],
132
133
  data: ["data"],
@@ -180,7 +181,7 @@ module.exports = {
180
181
  title: "not-node:crud_listAll_action_form_title",
181
182
  description: "not-node:crud_listAll_action_form_description",
182
183
  fields: [
183
- <%- fields.map((entry) => `"${entry}"`).join(',') %>,
184
+ <%- fieldsShortNames.map((entry) => `"${entry}"`).join(',') %>,
184
185
  <% if (dates){ %>"createdAt","updatedAt",<% } %>
185
186
  ],
186
187
  postFix: actionNamePath,
@@ -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