not-node 6.3.93 → 6.3.94

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.93",
3
+ "version": "6.3.94",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -3,7 +3,7 @@ import { resolve } from "node:path";
3
3
  import { createEntity } from "../lib/entity.mjs";
4
4
  import Logger from "../lib/log.mjs";
5
5
  import { loadProjectConfig } from "../lib/project.mjs";
6
- import { getProjectSiteDir } from "../lib/fs.mjs";
6
+ import { getProjectSiteDir, findAllFields } from "../lib/fs.mjs";
7
7
 
8
8
  export default (program, { CWD }) => {
9
9
  program
@@ -27,11 +27,12 @@ export default (program, { CWD }) => {
27
27
  siteDir,
28
28
  infoFromManifest.serverModulesDir
29
29
  );
30
+ const allFields = await findAllFields(siteDir, modulesDir);
30
31
  console.log("creating server module in", modulesDir);
31
32
  const ProjectConfig = {
32
33
  path: opts.dir,
33
34
  ...infoFromManifest,
34
35
  };
35
- await createEntity(modulesDir, ProjectConfig);
36
+ await createEntity(modulesDir, ProjectConfig, allFields);
36
37
  });
37
38
  };
@@ -1,6 +1,9 @@
1
1
  import { firstLetterToLower } from "../../../src/common.js";
2
2
  import { resolve } from "node:path";
3
3
  import inquirer from "inquirer";
4
+ import inquirerPrompt from "inquirer-autocomplete-prompt";
5
+
6
+ inquirer.registerPrompt("autocomplete", inquirerPrompt);
4
7
  import * as Readers from "../readers/index.mjs";
5
8
  import * as Renderers from "../renderers/index.mjs";
6
9
  import { renderFile, createDir } from "./fs.mjs";
@@ -33,12 +36,18 @@ async function renderEntityFiles(module_src_dir, data, config) {
33
36
  }
34
37
  }
35
38
 
36
- async function createEntity(modules_dir, config) {
39
+ async function createEntity(modules_dir, config, availableFields) {
37
40
  const ModuleName = await Readers.ModuleName(inquirer);
38
41
  const moduleName = firstLetterToLower(ModuleName);
39
42
  const moduleDir = resolve(modules_dir, ModuleName);
40
43
  const moduleLayers = await Readers.moduleLayers(inquirer);
41
- const moduleConfig = { ...config, moduleName, ModuleName, moduleLayers };
44
+ const moduleConfig = {
45
+ ...config,
46
+ moduleName,
47
+ ModuleName,
48
+ moduleLayers,
49
+ availableFields,
50
+ };
42
51
  // console.log("moduleConfig", moduleConfig);
43
52
  const entityData = await Readers.entityData(
44
53
  inquirer,
@@ -1,4 +1,7 @@
1
- import { firstLetterToLower } from "../../../src/common.js";
1
+ import {
2
+ firstLetterToLower,
3
+ moduleNameTransformer,
4
+ } from "../../../src/common.js";
2
5
  import { join } from "node:path";
3
6
  import inquirer from "inquirer";
4
7
  import inquirerPrompt from "inquirer-autocomplete-prompt";
@@ -75,9 +78,16 @@ async function renderServerContollersIndexes(
75
78
  async function createServerModule(modules_dir, config, availableFields) {
76
79
  //read module name
77
80
  const ModuleName = await Readers.ModuleName(inquirer);
81
+ const ModuleNameHumanReadable = moduleNameTransformer(ModuleName);
78
82
  const moduleName = firstLetterToLower(ModuleName);
79
83
  const moduleDir = join(modules_dir, ModuleName);
80
- const moduleConfig = { ...config, moduleName, ModuleName, availableFields };
84
+ const moduleConfig = {
85
+ ...config,
86
+ moduleName,
87
+ ModuleName,
88
+ ModuleNameHumanReadable,
89
+ availableFields,
90
+ };
81
91
  await createDir(moduleDir);
82
92
  //console.log(JSON.stringify(moduleConfig, null, 4));
83
93
  await createDirContent(
@@ -57,12 +57,15 @@ export default async (inquirer, config) => {
57
57
  fieldname = answer.fieldname.trim();
58
58
  });
59
59
  result.push([fieldname, fieldtype]);
60
+ const selectedFields = result.map(
61
+ (itm) => `${itm[1]} as ${itm[0]}`
62
+ );
60
63
  finished = await inquirer
61
64
  .prompt([
62
65
  {
63
66
  type: "confirm",
64
67
  name: "oneMore",
65
- message: `Add another one field to [${result.join(
68
+ message: `Add another one field to [${selectedFields.join(
66
69
  ","
67
70
  )}] (default: true)?`,
68
71
  default: true,
@@ -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,
@@ -21,6 +21,7 @@ export default async (
21
21
  }
22
22
 
23
23
  if (entitiesList.length) {
24
+ //common validators
24
25
  const TMPL_FILE_PATH_VALIDATORS = resolve(
25
26
  PATH_TMPL,
26
27
  TEMPLATES_DIR,
@@ -38,5 +39,23 @@ export default async (
38
39
  ...entitiesList[0],
39
40
  }
40
41
  );
42
+ //common service
43
+ const TMPL_FILE_PATH_COMMON_SERVICE = resolve(
44
+ PATH_TMPL,
45
+ TEMPLATES_DIR,
46
+ `service.ejs`
47
+ );
48
+ const DEST_FILE_PATH_COMMON_SERVICE = resolve(
49
+ module_layer_dir,
50
+ `ns${config.ModuleNameHumanReadable}Common.js`
51
+ );
52
+ await createFileContent(
53
+ TMPL_FILE_PATH_COMMON_SERVICE,
54
+ DEST_FILE_PATH_COMMON_SERVICE,
55
+ {
56
+ ...config,
57
+ ...entitiesList[0],
58
+ }
59
+ );
41
60
  }
42
61
  };
package/src/common.js CHANGED
@@ -23,6 +23,27 @@ module.exports.firstLetterToUpper = function (string) {
23
23
  return string.charAt(0).toUpperCase() + string.slice(1);
24
24
  };
25
25
 
26
+ /**
27
+ * transforms not-module-name -> ModuleName
28
+ * @param {string} moduleName
29
+ * @return {string}
30
+ */
31
+ function moduleNameTransformer(moduleName) {
32
+ //not-module-name -> [not,module,name]
33
+ const ModuleNameParts = moduleName.split("-");
34
+ //[not,module,name] -> [module,name]
35
+ const moduleNameSelectedParts =
36
+ ModuleNameParts[0] === "not"
37
+ ? ModuleNameParts.splice(1)
38
+ : ModuleNameParts;
39
+ //[module,name] -> ModuleName
40
+ return moduleNameSelectedParts
41
+ .map(module.exports.firstLetterToUpper)
42
+ .join("");
43
+ }
44
+
45
+ module.exports.moduleNameTransformer = moduleNameTransformer;
46
+
26
47
  /**
27
48
  * Validates if string is a ObjectId
28
49
  * @param {string|import('mongoose').Schema.Types.ObjectId} id ObjectId string to validate
@@ -1,95 +1,94 @@
1
1
  import { MODULE_NAME } from "../../const.js";
2
2
  import Validators from "../common/validators.js";
3
- import { Frame } from "not-bulma";
3
+ import { Frame, notCommon } from "not-bulma";
4
4
  import CRUDActionList from "not-bulma/src/frame/crud/actions/list";
5
5
 
6
6
  const { notCRUD } = Frame;
7
7
 
8
8
  const MODEL_NAME = "<%- ModelName %>";
9
+ const modelName = notCommon.lowerFirstLetter(MODEL_NAME);
9
10
 
10
- const LABELS = {
11
- plural: `${MODULE_NAME}:${MODEL_NAME}_label_plural`,
12
- single: `${MODULE_NAME}:${MODEL_NAME}_label_single`,
13
- };
11
+ const LABELS = {
12
+ plural: `${MODULE_NAME}:${modelName}_label_plural`,
13
+ single: `${MODULE_NAME}:${modelName}_label_single`,
14
+ };
14
15
 
15
- Object.freeze(LABELS);
16
+ Object.freeze(LABELS);
16
17
 
17
- class nc<%- ModelName %>Common extends notCRUD {
18
- static get MODULE_NAME(){
18
+ class nc<%- ModelName %>Common extends notCRUD {
19
+ static get MODULE_NAME(){
19
20
  return MODULE_NAME;
20
- }
21
+ }
21
22
 
22
- static get MODEL_NAME(){
23
+ static get MODEL_NAME(){
23
24
  return MODEL_NAME;
24
- }
25
+ }
25
26
 
26
- static get LABELS(){
27
+ static get LABELS(){
27
28
  return LABELS;
28
- }
29
+ }
29
30
 
30
- constructor(app, params) {
31
+ constructor(app, params) {
31
32
  super(app, `${MODULE_NAME}.${MODEL_NAME}`);
32
33
  this.setModuleName(MODULE_NAME);
33
34
  this.setModelName(MODEL_NAME);
34
35
  this.setOptions("names", LABELS);
35
- this.setOptions("Validators", Validators);
36
+ this.setValidators(Validators);
36
37
  this.setOptions("params", params);
37
38
  this.setOptions("list", {
38
- interface: {
39
- combined: true,
40
- factory: this.make.<%- modelName %>,
39
+ interface: {
40
+ combined: true,
41
+ factory: this.make.<%- modelName %>,
41
42
  },
42
43
  endless: false,
43
44
  preload: {},
44
45
  sorter: {
45
- id: -1,
46
+ id: -1,
46
47
  },
47
48
  showSearch: true,
48
49
  idField: "_id",
49
50
  fields: [
50
- <% if (increment) { %>
51
+ <% if (increment) { %>
51
52
  {
52
- path: ":<%- modelName %>ID",
53
+ path: ":<%- modelName %>ID",
53
54
  title: "ID",
54
55
  searchable: true,
55
56
  sortable: true,
56
- },
57
- <% } %>
58
- <% for (let fieldName of fields){ %>
59
- {
60
- path: ":<%- fieldName[0] %>",
61
- title: `${MODULE_NAME}:<%- `${modelName}_field_${fieldName[0]}_label` %>`,
62
- searchable: true,
63
- sortable: true,
64
- },
65
- <% } %>
66
- {
67
- path: ":_id",
68
- title: "Действия",
69
- type: "button",
70
- preprocessor: (value) => CRUDActionList.createActionsButtons(this, value),
71
- },
72
- ],
73
- });
74
-
75
- this.start();
76
- return this;
77
- }
78
-
79
- createDefault() {
80
- let newRecord = this.getModel({
81
- <% for (let fieldName of fields){ %><%- fieldName[0] %>: undefined,
82
- <% } %>
83
- });
84
- return newRecord;
85
- }
57
+ },
58
+ <% } %>
59
+ <% for (let fieldName of fields){ %>
60
+ {
61
+ path: ":<%- fieldName[0] %>",
62
+ title: `${MODULE_NAME}:<%- `${modelName}_field_${fieldName[0]}_label` %>`,
63
+ searchable: true,
64
+ sortable: true,
65
+ },
66
+ <% } %>
67
+ {
68
+ path: ":_id",
69
+ title: "Действия",
70
+ type: "button",
71
+ preprocessor: (value) => CRUDActionList.createActionsButtons(this, value),
72
+ },
73
+ ],
74
+ });
86
75
 
87
- static getMenu(){
88
- return notCRUD.getCommonMenu(nc<%- ModelName %>Common);
89
- }
76
+ this.start();
77
+ return this;
78
+ }
90
79
 
91
- }
80
+ createDefault() {
81
+ let newRecord = this.getModel({
82
+ <% for (let fieldName of fields){ %><%- fieldName[0] %>: undefined,
83
+ <% } %>
84
+ });
85
+ return newRecord;
86
+ }
92
87
 
93
- export default nc<%- ModelName %>Common;
88
+ static getMenu(){
89
+ return notCRUD.getCommonMenu(nc<%- ModelName %>Common);
90
+ }
94
91
 
92
+ }
95
93
 
94
+ export default nc<%- ModelName %>Common;
@@ -1,4 +1,5 @@
1
1
  import main from "../common/ws.client.main.js";
2
+ import ns<%- ModuleNameHumanReadable %>Common from "./ns<%- ModuleNameHumanReadable %>Common.js";
2
3
 
3
4
  <% for (let {ModelName} of entities){ %>
4
5
  import nc<%- {ModelName} %> from "./nc<%- {ModelName} %>.js";
@@ -10,7 +11,7 @@ const wsc = {
10
11
 
11
12
  const uis = {};
12
13
 
13
- const services = {};
14
+ const services = {ns<%- ModuleNameHumanReadable %>Common};
14
15
 
15
16
  let manifest = {
16
17
  router: {
@@ -0,0 +1,23 @@
1
+ import { Builder } from "not-validation";
2
+ import Validator from "validator";
3
+
4
+ export default class ns<%- ModuleNameHumanReadable %>Common {
5
+ constructor(app) {
6
+ this.app = app;
7
+ }
8
+
9
+ destroy() {
10
+ delete this.app;
11
+ }
12
+
13
+ augmentValidators(validators) {
14
+ return Builder(validators, () => this.getValidatorEnv());
15
+ }
16
+
17
+ getValidatorEnv() {
18
+ return {
19
+ config: this.app.getConfigReaderForModule("<%- moduleName %>"),
20
+ validator: Validator,
21
+ };
22
+ }
23
+ }
@@ -1,10 +1,13 @@
1
+ import ns<%- ModuleNameHumanReadable %>Common from "../common/ns<%- ModuleNameHumanReadable %>Common.js";
1
2
  <% for (let {ModelName} of entities){ %>
2
3
  import nc<%- ModelName %> from "./nc<%- ModelName %>.js";
3
4
  <% } %>
4
5
 
5
6
  const wsc = {};
6
7
  const uis = {};
7
- const services = {};
8
+ const services = {
9
+ ns<%- ModuleNameHumanReadable %>Common
10
+ };
8
11
 
9
12
  let manifest = {
10
13
  router: {
@@ -1,57 +0,0 @@
1
- import UI<%- ComponentName %> from "./<%- componentName %>.svelte";
2
-
3
- class not<%- ComponentName %> extends notBase{
4
-
5
- static UIConstructor = UI<%- ComponentName %>;
6
-
7
- constructor({
8
- target = null,
9
- name = "Default",
10
- options = {},
11
- working = {},
12
- data = {},
13
- }){
14
- super({
15
- working: {
16
- name: `${name}<%- ComponentName %>`,
17
- ...working,
18
- },
19
- options,
20
- data,
21
- });
22
- if (target) {
23
- this.setOptions("target", target);
24
- }
25
- this.render();
26
- }
27
-
28
- render(){
29
- this.remove();
30
- if(this.UIConstructor){
31
- this.ui = new this.UIConstructor({
32
- target: this.getOptions('target'),
33
- props:{
34
- /* props */
35
- }
36
- });
37
- }
38
- }
39
-
40
- update(){
41
- if(this.ui){
42
- this.ui.$set({ /* update props */ });
43
- }
44
- }
45
-
46
- remove(){
47
- if (this.ui) {
48
- this.ui.$destroy();
49
- this.ui = null;
50
- }
51
- return this;
52
- }
53
-
54
- }
55
-
56
- export default not<%- ComponentName %>;
57
-
@@ -1,39 +0,0 @@
1
- const INTERVAL = 360;
2
- const INIT_UPDATE_DELAY = 5;
3
-
4
- class ns<%- ServiceName %> {
5
- #INTERVAL = INTERVAL;
6
- #INIT_UPDATE_DELAY = INIT_UPDATE_DELAY;
7
-
8
- constructor(app) {
9
- this.app = app;
10
- <% if(modelName){ %>
11
- this.interface = this.app.getInterface("<%- modelName %>"");
12
- if(this.interface){
13
- this.init();
14
- }else{
15
- app.error('no network interface');
16
- }
17
- <% }else{ %>
18
- this.init();
19
- <% } %>
20
- };
21
-
22
- init() {
23
- setTimeout(this.update.bind(this), this.#INIT_UPDATE_DELAY * 100);
24
- this.int = setInterval(this.update.bind(this), this.#INTERVAL * 1000);
25
- window.addEventListener('unload', () => {
26
- clearInterval(this.int);
27
- delete this.app;
28
- <% if(modelName){ %>
29
- delete this.interface;
30
- <% } %>
31
- });
32
- }
33
-
34
- update() {
35
- //serve
36
- }}
37
-
38
-
39
- export default ns<%- ServiceName %>;