not-node 6.0.7 → 6.1.0

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 (179) hide show
  1. package/bin/not-builder.js +418 -293
  2. package/bin/not-cli.mjs +369 -0
  3. package/index.js +6 -0
  4. package/package.json +133 -128
  5. package/playground/.babelrc +11 -0
  6. package/playground/.eslintignore +4 -0
  7. package/playground/.eslintrc.json +23 -0
  8. package/playground/app/front/index.!.js +64 -0
  9. package/playground/app/front/rollup.!.js +70 -0
  10. package/playground/app/front/src/admin/main/index.js +45 -0
  11. package/playground/app/front/src/client/main/index.js +45 -0
  12. package/playground/app/front/src/common/index.js +39 -0
  13. package/playground/app/front/src/common/ncInit.js +18 -0
  14. package/playground/app/front/src/common/ws.client.main.js +35 -0
  15. package/playground/app/front/src/guest/main/index.js +34 -0
  16. package/playground/app/front/src/root/main/index.js +45 -0
  17. package/playground/app/front/src/user/main/index.js +45 -0
  18. package/playground/app/server/app.js +22 -0
  19. package/playground/app/server/config/common.json +53 -0
  20. package/playground/app/server/config/development.json +34 -0
  21. package/playground/app/server/config/production.json +34 -0
  22. package/playground/app/server/config/stage.json +34 -0
  23. package/playground/app/server/index.js +20 -0
  24. package/playground/app/server/routes/index.js +36 -0
  25. package/playground/app/server/routes/site.js +71 -0
  26. package/playground/app/server/views/admin/foot.pug +1 -0
  27. package/playground/app/server/views/admin/head.pug +7 -0
  28. package/playground/app/server/views/admin/menu.pug +2 -0
  29. package/playground/app/server/views/admin.pug +19 -0
  30. package/playground/app/server/views/dashboard.pug +20 -0
  31. package/playground/app/server/views/index.pug +15 -0
  32. package/playground/app/server/views/parts/header.android.pug +7 -0
  33. package/playground/app/server/views/parts/header.ios.pug +5 -0
  34. package/playground/app/server/views/parts/header.pug +18 -0
  35. package/playground/app/server/views/parts/menu.pug +1 -0
  36. package/playground/app/server/views/parts/overview.pug +2 -0
  37. package/playground/app/server/ws/auth.js +41 -0
  38. package/playground/app/server/ws/index.js +84 -0
  39. package/playground/bin/build.sh +8 -0
  40. package/playground/package.json +66 -0
  41. package/playground/project.manifest.json +34 -0
  42. package/src/app.js +3 -3
  43. package/src/cli/const.mjs +71 -0
  44. package/src/cli/readers/AppDescription.mjs +14 -0
  45. package/src/cli/readers/AppName.mjs +14 -0
  46. package/src/cli/readers/ModelName.mjs +14 -0
  47. package/src/cli/readers/ModuleName.mjs +14 -0
  48. package/src/cli/readers/actions.mjs +25 -0
  49. package/src/cli/readers/appName.mjs +14 -0
  50. package/src/cli/readers/cors.mjs +12 -0
  51. package/src/cli/readers/db/ioredis.mjs +3 -0
  52. package/src/cli/readers/db/mongoose.mjs +61 -0
  53. package/src/cli/readers/db/redis.mjs +3 -0
  54. package/src/cli/readers/db.mjs +30 -0
  55. package/src/cli/readers/entityData.mjs +44 -0
  56. package/src/cli/readers/entityLayers.mjs +21 -0
  57. package/src/cli/readers/fields.mjs +13 -0
  58. package/src/cli/readers/filter.mjs +34 -0
  59. package/src/cli/readers/hostname.mjs +23 -0
  60. package/src/cli/readers/index.mjs +86 -0
  61. package/src/cli/readers/init_root_user.mjs +55 -0
  62. package/src/cli/readers/isUserNeedCreateEntity.mjs +14 -0
  63. package/src/cli/readers/isUserNeedCreateServerModule.mjs +14 -0
  64. package/src/cli/readers/isUserNeedFrontModuleBootstrap.mjs +14 -0
  65. package/src/cli/readers/modelIncrement.mjs +32 -0
  66. package/src/cli/readers/modelIncrementFilter.mjs +49 -0
  67. package/src/cli/readers/modelOptions.mjs +61 -0
  68. package/src/cli/readers/modelValidators.mjs +14 -0
  69. package/src/cli/readers/modelVersioning.mjs +14 -0
  70. package/src/cli/readers/moduleLayers.mjs +25 -0
  71. package/src/cli/readers/modules.mjs +19 -0
  72. package/src/cli/readers/not_node_monitor.mjs +48 -0
  73. package/src/cli/readers/not_node_reporter.mjs +42 -0
  74. package/src/cli/readers/port.mjs +14 -0
  75. package/src/cli/readers/roles.mjs +25 -0
  76. package/src/cli/readers/rolesSecondary.mjs +14 -0
  77. package/src/cli/readers/secret.mjs +21 -0
  78. package/src/cli/readers/session.mjs +55 -0
  79. package/src/cli/readers/ssl.mjs +38 -0
  80. package/src/cli/readers/user.mjs +62 -0
  81. package/src/cli/readers/ws.mjs +35 -0
  82. package/src/cli/renderers/controllers.mjs +26 -0
  83. package/src/cli/renderers/controllersCommons.mjs +42 -0
  84. package/src/cli/renderers/controllersIndex.mjs +18 -0
  85. package/src/cli/renderers/fields.mjs +1 -0
  86. package/src/cli/renderers/forms.mjs +43 -0
  87. package/src/cli/renderers/frontModuleGuestMain.mjs +10 -0
  88. package/src/cli/renderers/frontModuleRoleMain.mjs +10 -0
  89. package/src/cli/renderers/index.mjs +29 -0
  90. package/src/cli/renderers/logics.mjs +17 -0
  91. package/src/cli/renderers/models.mjs +16 -0
  92. package/src/cli/renderers/routes.mjs +31 -0
  93. package/src/domain.js +8 -9
  94. package/src/headers.js +17 -0
  95. package/src/identity/identity.js +0 -1
  96. package/src/init/index.js +1 -0
  97. package/src/init/lib/app.js +5 -7
  98. package/src/init/lib/modules.js +2 -1
  99. package/src/init/lib/routes.js +1 -0
  100. package/src/manifest/module.js +6 -20
  101. package/src/metas.js +34 -0
  102. package/src/styler.js +38 -0
  103. package/tmpl/dirs/app.mjs +32 -0
  104. package/tmpl/dirs/front.mjs +12 -0
  105. package/tmpl/dirs/module.front.mjs +19 -0
  106. package/tmpl/dirs/module.server.controllers.common.mjs +7 -0
  107. package/tmpl/dirs/module.server.mjs +14 -0
  108. package/tmpl/dirs/server.mjs +127 -0
  109. package/tmpl/dirs/static.mjs +9 -0
  110. package/tmpl/files/app/.babelrc +11 -0
  111. package/tmpl/files/app/.eslintignore +4 -0
  112. package/tmpl/files/app/.eslintrc.json +23 -0
  113. package/tmpl/files/app/app.ejs +22 -0
  114. package/tmpl/files/app/build.sh +8 -0
  115. package/tmpl/files/app/config/common.ejs +131 -0
  116. package/tmpl/files/app/config/other.ejs +34 -0
  117. package/tmpl/files/app/deploy.pm2.ejs +23 -0
  118. package/tmpl/files/app/env.ejs +16 -0
  119. package/tmpl/files/app/front/build.env.ejs +7 -0
  120. package/tmpl/files/app/front/index.!.ejs +66 -0
  121. package/tmpl/files/app/front/rollup.!.ejs +70 -0
  122. package/tmpl/files/app/index.ejs +20 -0
  123. package/tmpl/files/app/package.ejs +66 -0
  124. package/tmpl/files/app/project.manifest.ejs +23 -0
  125. package/tmpl/files/app/routes/index.ejs +36 -0
  126. package/tmpl/files/app/routes/site.ejs +71 -0
  127. package/tmpl/files/app/views/admin/foot.ejs +1 -0
  128. package/tmpl/files/app/views/admin/head.ejs +7 -0
  129. package/tmpl/files/app/views/admin/menu.ejs +2 -0
  130. package/tmpl/files/app/views/admin.ejs +19 -0
  131. package/tmpl/files/app/views/dashboard.ejs +20 -0
  132. package/tmpl/files/app/views/index.ejs +15 -0
  133. package/tmpl/files/app/views/parts/header.android.ejs +7 -0
  134. package/tmpl/files/app/views/parts/header.ejs +18 -0
  135. package/tmpl/files/app/views/parts/header.ios.ejs +5 -0
  136. package/tmpl/files/app/views/parts/menu.ejs +1 -0
  137. package/tmpl/files/app/views/parts/overview.ejs +2 -0
  138. package/tmpl/files/app/ws/auth.ejs +41 -0
  139. package/tmpl/files/app/ws/index.ejs +84 -0
  140. package/tmpl/files/module.front/common/index.ejs +39 -0
  141. package/tmpl/files/module.front/common/ncInit.ejs +18 -0
  142. package/tmpl/files/module.front/common/ws.client.main.ejs +35 -0
  143. package/tmpl/files/module.front/role/guest.index.ejs +45 -0
  144. package/tmpl/files/module.front/role/index.ejs +34 -0
  145. package/tmpl/files/module.server/const.ejs +1 -0
  146. package/{scaffold/base.js → tmpl/files/module.server/extractor.ejs} +0 -0
  147. package/tmpl/files/module.server/index.ejs +8 -0
  148. package/tmpl/files/module.server/layers/controllers/common/crud.ejs +95 -0
  149. package/tmpl/files/module.server/layers/controllers/common/index.ejs +59 -0
  150. package/tmpl/files/module.server/layers/controllers/common/validators.ejs +44 -0
  151. package/tmpl/files/module.server/layers/controllers/common/ws.client.ejs +25 -0
  152. package/tmpl/files/module.server/layers/controllers/role/crud.ejs +11 -0
  153. package/tmpl/files/module.server/layers/controllers/role/index.ejs +29 -0
  154. package/tmpl/files/module.server/layers/fields.ejs +30 -0
  155. package/tmpl/files/module.server/layers/forms/_data.ejs +35 -0
  156. package/tmpl/files/module.server/layers/forms/create.ejs +47 -0
  157. package/tmpl/files/module.server/layers/forms/delete.ejs +8 -0
  158. package/tmpl/files/module.server/layers/forms/get.ejs +8 -0
  159. package/tmpl/files/module.server/layers/forms/getRaw.ejs +8 -0
  160. package/tmpl/files/module.server/layers/forms/listAll.ejs +8 -0
  161. package/tmpl/files/module.server/layers/forms/listAndCount.ejs +8 -0
  162. package/tmpl/files/module.server/layers/forms/update.ejs +40 -0
  163. package/tmpl/files/module.server/layers/forms/validator.ejs +32 -0
  164. package/tmpl/files/module.server/layers/forms.ejs +49 -0
  165. package/tmpl/files/module.server/layers/locales.ejs +3 -0
  166. package/tmpl/files/module.server/layers/logics.ejs +73 -0
  167. package/tmpl/files/module.server/layers/models.ejs +68 -0
  168. package/tmpl/files/module.server/layers/routes.ejs +50 -0
  169. package/tmpl/files/module.server/layers/routes.manifest.ejs +211 -0
  170. package/tmpl/files/module.server/layers/routes.ws.ejs +29 -0
  171. package/tmpl/files/module.server/validationEnv.ejs +5 -0
  172. package/tmpl/files/notComponent.ejs +57 -0
  173. package/tmpl/files/notService.ejs +39 -0
  174. package/scaffold/field.js +0 -0
  175. package/scaffold/form.js +0 -0
  176. package/scaffold/logic.js +0 -0
  177. package/scaffold/model.js +0 -0
  178. package/scaffold/module.js +0 -0
  179. package/scaffold/route.js +0 -0
@@ -0,0 +1,18 @@
1
+ import { Frame } from 'not-bulma';
2
+
3
+ const {
4
+ notSideMenu, notTopMenu,
5
+ notController} = Frame;
6
+
7
+ class ncInit extends notController {
8
+ constructor(app) {
9
+ super(app);
10
+ this.setModuleName('init');
11
+ this.log('init app');
12
+ notSideMenu.render(app);
13
+ notTopMenu.render(app);
14
+ return this;
15
+ }
16
+ }
17
+
18
+ export default ncInit;
@@ -0,0 +1,35 @@
1
+ import {notCommon} from 'not-bulma';
2
+ const logger = notCommon.createLogger(`WSClient(main)`);
3
+
4
+ const main = {
5
+ logger: logger,
6
+ getToken: () => {
7
+ return notCommon.getApp().getModel('user', {}).$token({})
8
+ .then((res) => {
9
+ logger.log('token', res.result.token);
10
+ notCommon.getApp().setWorking('token', res.result.token);
11
+ return res.result.token;
12
+ });
13
+ },
14
+ messenger: {
15
+ validateTypeAndName: false,
16
+ secure: false,//not secure, bc its not issuing tokens and has no secret key
17
+ types: {
18
+ '__service': ['updateToken'],
19
+ 'request': [],
20
+ 'response': [],
21
+ 'event': []
22
+ },
23
+ },
24
+ router:{
25
+ routes:{
26
+ event: {
27
+ notification(){
28
+ console.log(...arguments);
29
+ }
30
+ }
31
+ }
32
+ }
33
+ };
34
+
35
+ export default main;
@@ -0,0 +1,45 @@
1
+ import ncInit from "../../common/ncInit";
2
+
3
+ let manifest = {
4
+ environment: "guest",
5
+ router: {
6
+ manifest: [],
7
+ },
8
+ crud: {
9
+ containerSelector: ".main-container",
10
+ },
11
+ modules: {
12
+ user: {
13
+ loginFormContainerSelector: ".main-container",
14
+ registerFormContainerSelector: ".main-container",
15
+ },
16
+ },
17
+ initController: ncInit,
18
+ menu: {
19
+ top: {
20
+ toggleSelector: ".navbar-burger",
21
+ sections: [],
22
+ items: [
23
+ {
24
+ title: "Вход",
25
+ url: "/login",
26
+ priority: 10,
27
+ showOnTouch: true,
28
+ type: "button",
29
+ place: "start",
30
+ } , {
31
+ id: 'register',
32
+ title: 'Регистрация',
33
+ url: '/register',
34
+ type: 'button',
35
+ priority: 11,
36
+ showOnTouch:true,
37
+ place: 'start'
38
+ },
39
+ ],
40
+ },
41
+ },
42
+ };
43
+
44
+
45
+ export { ncInit, manifest };
@@ -0,0 +1,34 @@
1
+ import ncInit from "../../common/ncInit";
2
+
3
+ let manifest = {
4
+ environment: "client",
5
+ router: {
6
+ root: "/dashboard",
7
+ manifest: [],
8
+ },
9
+ crud: {
10
+ containerSelector: ".main-container",
11
+ },
12
+ modules: {
13
+ user: {},
14
+ },
15
+ brand: {
16
+ icon: {
17
+ src: "/img/icons/icon-w-64.png",
18
+ width: 48,
19
+ height: 28,
20
+ },
21
+ url: "/",
22
+ },
23
+ menu: {
24
+ side: {
25
+ sections: [],
26
+ },
27
+ top: {
28
+ sections: [],
29
+ },
30
+ },
31
+ initController: ncInit,
32
+ };
33
+
34
+ export { ncInit, manifest };
@@ -0,0 +1 @@
1
+ module.exports.MODULE_NAME = '<%- ModuleName %>';
@@ -0,0 +1,8 @@
1
+ const { generatePaths } = require("not-node").Common;
2
+
3
+ const COMPONENTS = [<%- moduleLayers.map(entry => `"${entry}"`).join(',') %>];
4
+
5
+ module.exports = {
6
+ name: require("./src/const").MODULE_NAME,
7
+ paths: generatePaths(COMPONENTS, __dirname + "/src"),
8
+ };
@@ -0,0 +1,95 @@
1
+ import Validators from "../common/validators.js";
2
+ import { Frame } from "not-bulma";
3
+ const { notCRUD } = Frame;
4
+
5
+ const MODULE_NAME = "";
6
+ const MODEL_NAME = "<%- ModelName %>";
7
+
8
+ const LABELS = {
9
+ plural: "<%- `${ModuleName}:${modelName}_label_plural` %>",
10
+ single: "<%- `${ModuleName}:${modelName}_label_single` %>",
11
+ };
12
+
13
+ class nc<%- ModelName %>Common extends notCRUD {
14
+ static MODULE_NAME = MODULE_NAME;
15
+ static MODEL_NAME = MODEL_NAME;
16
+ constructor(app, params) {
17
+ super(app, `${MODULE_NAME}.${MODEL_NAME}`);
18
+ this.setModuleName(MODULE_NAME);
19
+ this.setModelName(MODEL_NAME);
20
+ this.setOptions("names", LABELS);
21
+ this.setOptions("Validators", Validators);
22
+ this.setOptions("params", params);
23
+ this.setOptions("list", {
24
+ interface: {
25
+ combined: true,
26
+ factory: this.make.<%- modelName %>,
27
+ },
28
+ endless: false,
29
+ preload: {},
30
+ sorter: {
31
+ id: -1,
32
+ },
33
+ showSearch: true,
34
+ idField: "_id",
35
+ fields: [
36
+ <% if (increment) { %>
37
+ {
38
+ path: ":<%- modelName %>ID",
39
+ title: "ID",
40
+ searchable: true,
41
+ sortable: true,
42
+ },
43
+ <% } %>
44
+ <% for (let fieldName of fields){ %>
45
+ {
46
+ path: ":<%- fieldName %>",
47
+ title: "<%- `${ModuleName}:${modelName}_field_${fieldName}_label` %>",
48
+ searchable: true,
49
+ sortable: true,
50
+ },
51
+ <% } %>
52
+ {
53
+ path: ":_id",
54
+ title: "Действия",
55
+ type: "button",
56
+ preprocessor: (value) => {
57
+ return [
58
+ {
59
+ action: this.goDetails.bind(this, value),
60
+ title: "Подробнее",
61
+ size: "small",
62
+ },
63
+ {
64
+ action: this.goUpdate.bind(this, value),
65
+ title: "Изменить",
66
+ size: "small",
67
+ },
68
+ {
69
+ action: this.goDelete.bind(this, value),
70
+ color: "danger",
71
+ title: "Удалить",
72
+ size: "small",
73
+ style: "outlined",
74
+ },
75
+ ];
76
+ },
77
+ },
78
+ ],
79
+ });
80
+
81
+ this.start();
82
+ return this;
83
+ }
84
+
85
+ createDefault() {
86
+ let newRecord = this.make[this.getModelName()]({
87
+ _id: null,
88
+ <% for (let fieldName of fields){ %><%- fieldName %>: null,
89
+ <% } %>
90
+ });
91
+ return newRecord;
92
+ }
93
+ }
94
+
95
+ export default nc<%- ModelName %>Common;
@@ -0,0 +1,59 @@
1
+ import main from "../common/ws.client.main.js";
2
+
3
+ <% for (let {ModelName} of entities){ %>
4
+ import nc<%- {ModelName} %> from "./nc<%- {ModelName} %>.js";
5
+ <% } %>
6
+
7
+ const wsc = {
8
+ main,
9
+ };
10
+
11
+ const uis = {};
12
+
13
+ const services = {};
14
+
15
+ let manifest = {
16
+ router: {
17
+ manifest: [
18
+ <% for (let {ModelName} of entities){ %>
19
+ nc<%- {ModelName} %>.getRoutes(),
20
+ <% } %>
21
+ ],
22
+ },
23
+ menu: {
24
+ top: {
25
+ items: [
26
+ /*
27
+ {
28
+ id: "itemId",
29
+ section: "sectionId",
30
+ title: "Item title",
31
+ },
32
+ */
33
+ ],
34
+ },
35
+ side: {
36
+ sections: [
37
+ /*
38
+ {
39
+ id: "sectionId",
40
+ title: "Section title",
41
+ },
42
+ */
43
+ ],
44
+ items: [
45
+ /*
46
+ {
47
+ priority: 10, //higher goes on top
48
+ id: "sectionId.item",
49
+ section: "sectionId",
50
+ title: "Item title",
51
+ url: "/some/localUrl",
52
+ },
53
+ */
54
+ ],
55
+ },
56
+ },
57
+ };
58
+
59
+ export { manifest, wsc, services, uis};
@@ -0,0 +1,44 @@
1
+ import notValidationError from 'not-error/src/validation.error.browser.js';
2
+ /*
3
+ import vVariableLength from '../../fields/validators/variableLength.js';
4
+ const ERR_MSG_FORM_IS_DIRTY = '<%- ModuleName %>:form_is_dirty';
5
+ const ERR_MSG_FORM_VARIABLE_SHOULD_BE_LONGER_THAN_TEN_CHARS = '<%- ModuleName %>:form_variable_should_be_longer_than_ten_chars';
6
+
7
+
8
+ const actionName<%- ModelName %>Validation = async (data) => {
9
+ if (data.variable.length < 10) {
10
+ throw new notValidationError(ERR_MSG_FORM_VARIABLE_SHOULD_BE_LONGER_THAN_TEN_CHARS, {
11
+ //form wide status
12
+ form: [ERR_MSG_FORM_IS_DIRTY],
13
+ fields: {
14
+ //errors in fields
15
+ variable: [ERR_MSG_FORM_VARIABLE_SHOULD_BE_LONGER_THAN_TEN_CHARS]
16
+ }
17
+ });
18
+ }
19
+ };
20
+
21
+ */
22
+
23
+ const Validators = {
24
+
25
+ //val - value of field
26
+ //env - resources (constants, config reader, third party libs) needed for validation and provided from module level
27
+ //(val:any, env: Object)=>Promise<Boolean>
28
+ fields: {
29
+ /*
30
+ variable: vVariableLength,
31
+ */
32
+ },
33
+ //form - object with form values
34
+ //env - resources needed for validation and provided from module level
35
+ //(form:Object, env: Object)=>Promise<Boolean>
36
+ forms: {
37
+ /*
38
+ create: [actionName<%- ModelName %>Validation],
39
+ update: [actionName<%- ModelName %>Validation]
40
+ */
41
+ }
42
+ };
43
+
44
+ export default Validators;
@@ -0,0 +1,25 @@
1
+ import { notCommon } from "not-bulma";
2
+
3
+ /*
4
+ async function onEventHandler(payload) {
5
+ try {
6
+ //passing event through Application as a event bus
7
+ notCommon.getApp().emit("modelName//eventName", payload);
8
+ } catch (e) {
9
+ notCommon.error(e);
10
+ }
11
+ }
12
+ */
13
+
14
+ const main = {
15
+ router: {
16
+ routes: {
17
+ event: {
18
+ //"modelName//eventName": onEventHandler,
19
+
20
+ },
21
+ },
22
+ },
23
+ };
24
+
25
+ export default main;
@@ -0,0 +1,11 @@
1
+ import nc<%- ModelName %>Common from '../common/nc<%- ModelName %>Common.js';
2
+
3
+
4
+ class nc<%- ModelName %> extends nc<%- ModelName %>Common {
5
+ constructor(app, params) {
6
+ super(app, params);
7
+ return this;
8
+ }
9
+ }
10
+
11
+ export default nc<%- ModelName %>;
@@ -0,0 +1,29 @@
1
+ <% for (let {ModelName} of entities){ %>
2
+ import nc<%- ModelName %> from "./nc<%- ModelName %>.js";
3
+ <% } %>
4
+
5
+ const wsc = {};
6
+ const uis = {};
7
+ const services = {};
8
+
9
+ let manifest = {
10
+ router: {
11
+ manifest: [
12
+ <% for (let {ModelName} of entities){ %>
13
+ nc<%- ModelName %>.getRoutes(),
14
+ <% } %>
15
+ ],
16
+ },
17
+ menu: {
18
+ top: {
19
+ sections: [],
20
+ items: [],
21
+ },
22
+ side: {
23
+ sections: [],
24
+ items: [],
25
+ },
26
+ },
27
+ };
28
+
29
+ export { manifest, wsc, services, uis};
@@ -0,0 +1,30 @@
1
+ module.exports = {
2
+ <% if(ui){ %>
3
+ ui: {
4
+ component: "<%- ui.component %>",
5
+ label: "<%- ui.label %>",
6
+ placeholder: "<%- ui.placeholder %>",
7
+ readonly: <%= ui.readonly %>,
8
+ },
9
+ <% } %>
10
+ <% if(model){ %>
11
+ model: {
12
+ type: <%= model.type %>,
13
+ <% if (model?.ref){ %>
14
+ ref: "<%= model.ref %>",
15
+ <% } %>
16
+ <% if (Object.hasOwn(model, 'required')){ %>
17
+ required: <%= model?.required ?? false %>,
18
+ <% } %>
19
+ <% if (Object.hasOwn(model, 'default')){ %>
20
+ default: <%= model.default %>,
21
+ <% } %>
22
+ searchable: <%= model?.searchable ?? true %>,
23
+ sortable: <%= model?.sortable ?? true %>,
24
+ safe: {
25
+ update: ["@owner", "root", "admin"],
26
+ read: ["@owner", "root", "admin"],
27
+ },
28
+ },
29
+ <% } %>
30
+ };
@@ -0,0 +1,35 @@
1
+ const { MODULE_NAME } = require("../const");
2
+
3
+ const Form = require("not-node").Form;
4
+
5
+ const FIELDS = [
6
+ <% if (fields && Array.isArray(fields)) { %>
7
+ <% for(let field of fields){ %>
8
+ <%- `"${field}",` -%>
9
+ <% } %>
10
+ <% } %>
11
+ ["owner", "not-node//owner"],
12
+ ["ownerModel", "not-node//ownerModel"],
13
+ ];
14
+
15
+ const FORM_NAME = `${MODULE_NAME}:_<%- ModelName %>DataForm`;
16
+
17
+
18
+ //const validateTitle = require("./validators/title.js");
19
+
20
+ module.exports = class _DataForm extends Form {
21
+ constructor({ app }) {
22
+ super({ FIELDS, FORM_NAME, app });
23
+ }
24
+
25
+ extract(data) {
26
+ return data;
27
+ }
28
+
29
+ getFormValidationRules() {
30
+ return [
31
+ //add validators here
32
+ //validateTitle,
33
+ ];
34
+ }
35
+ };
@@ -0,0 +1,47 @@
1
+ const getIP = require("not-node").Auth.getIP;
2
+ const { MODULE_NAME } = require("../const");
3
+ //DB related validation tools
4
+ const Form = require("not-node").Form;
5
+ //form
6
+ const FIELDS = [
7
+ <% if (fields && Array.isArray(fields)) { %>
8
+ <% for(let field of fields){ %>
9
+ "<%- field %>",
10
+ <% } %>
11
+ <% } %>
12
+ ];
13
+
14
+ const FORM_NAME = `${MODULE_NAME}:<%- ModelName %>CreateForm`;
15
+
16
+ /**
17
+ *
18
+ **/
19
+ module.exports = class <%- ModelName %>CreateForm extends Form {
20
+ constructor({ app }) {
21
+ super({ FIELDS, FORM_NAME, app });
22
+ }
23
+
24
+ /**
25
+ * Extracts data
26
+ * @param {ExpressRequest} req expressjs request object
27
+ * @return {Object} forma data
28
+ **/
29
+ extract(req) {
30
+ const ip = getIP(req);
31
+ const instructions = {
32
+ <% if (fields && Array.isArray(fields)) { %>
33
+ <% for(let field of fields){ %>
34
+ <%- field+': "extractFromBody",' -%>
35
+ <% } %>
36
+ <% } %>
37
+ owner: "activeUserId",
38
+ ownerModel: "activeUserModelName",
39
+ };
40
+ const data = this.extractByInstructions(req, instructions);
41
+ return {
42
+ activeUser: req.user,
43
+ ip,
44
+ data,
45
+ };
46
+ }
47
+ };
@@ -0,0 +1,8 @@
1
+ const { MODULE_NAME } = require("../const");
2
+ //DB related validation tools
3
+ const notNode = require("not-node");
4
+
5
+ module.exports = notNode.Generic.GenericGetByIdForm({
6
+ MODULE_NAME,
7
+ actionName: "delete",
8
+ });
@@ -0,0 +1,8 @@
1
+ const { MODULE_NAME } = require("../const");
2
+ //DB related validation tools
3
+ const notNode = require("not-node");
4
+
5
+ module.exports = notNode.Generic.GenericGetByIdForm({
6
+ MODULE_NAME,
7
+ actionName: "get",
8
+ });
@@ -0,0 +1,8 @@
1
+ const { MODULE_NAME } = require("../const");
2
+ //DB related validation tools
3
+ const notNode = require("not-node");
4
+
5
+ module.exports = notNode.Generic.GenericGetByIdForm({
6
+ MODULE_NAME,
7
+ actionName: "getRaw",
8
+ });
@@ -0,0 +1,8 @@
1
+ const notNode = require("not-node");
2
+ const { MODULE_NAME } = require("../const");
3
+
4
+ module.exports = notNode.Generic.GenericListAndCountForm({
5
+ MODULE_NAME,
6
+ MODEL_NAME: "<%- ModelName %>",
7
+ actionName: "listAll",
8
+ });
@@ -0,0 +1,8 @@
1
+ const notNode = require("not-node");
2
+ const { MODULE_NAME } = require("../const");
3
+
4
+ module.exports = notNode.Generic.GenericListAndCountForm({
5
+ MODULE_NAME,
6
+ MODEL_NAME: "<%- ModelName %>",
7
+ actionName: "listAndCount",
8
+ });
@@ -0,0 +1,40 @@
1
+ const { MODULE_NAME } = require("../const");
2
+ const Form = require("not-node").Form;
3
+ const getIP = require("not-node").Auth.getIP;
4
+
5
+ const FIELDS = [
6
+ ["targetId", { required: true }, "not-node//objectId"],
7
+ ["activeUser", "not-node//requiredObject"],
8
+ ["data", `${ModuleName}//_${ModelName}_data`], //sub forms validators should start with underscore
9
+ ["ip", "not-node//ip"],
10
+ ];
11
+ const FORM_NAME = `${ModuleName}:<%- ModelName %>UpdateForm`;
12
+
13
+ module.exports = class <%- ModelName %>UpdateForm extends Form {
14
+ constructor({ app }) {
15
+ super({ FIELDS, FORM_NAME, app });
16
+ }
17
+
18
+ extract(req) {
19
+ const instructions = {
20
+ <% if (fields && Array.isArray(fields)) { %>
21
+ <% for(let field of fields){ %>
22
+ <%- field+': "extractFromBody",' -%>
23
+ <% } %>
24
+ <% } %>
25
+ owner: "fromBody",
26
+ ownerModel: "fromBody",
27
+ };
28
+ const data = this.extractByInstructions(req, instructions);
29
+ if (!req.user.isRoot() && !req.user.isAdmin()) {
30
+ data.owner = req.user._id;
31
+ data.ownerModel = "User";
32
+ }
33
+ return {
34
+ targetId: req.params._id.toString(),
35
+ activeUser: req.user,
36
+ data,
37
+ ip: getIP(req),
38
+ };
39
+ }
40
+ };
@@ -0,0 +1,32 @@
1
+ const notNode = require("not-node");
2
+ const { notValidationError } = require("not-error");
3
+
4
+ module.exports = async (
5
+ /**
6
+ * Values to validate in form
7
+ */
8
+ {owner, ownerModel, vals, to , validate },
9
+ /**
10
+ * special container to pass around global validation libs, CONSTs and inject other entities
11
+ */
12
+ validationEnvs
13
+ ) => {
14
+ //some preparations
15
+ if (
16
+ //vals checks
17
+ ) {
18
+ throw new notValidationError(
19
+ "<%- ModuleName %>:validation_error",
20
+ {
21
+ //vals: ["%- ModuleName %>:vals_should_be_valid"],
22
+ },
23
+ undefined, //no source error, its custom exception
24
+ {
25
+ //information
26
+ //vals,
27
+ //owner,
28
+ //ownerModel
29
+ }
30
+ );
31
+ }
32
+ };