not-node 6.3.85 → 6.3.86

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.
@@ -0,0 +1,70 @@
1
+ const globals = require("globals");
2
+ const js = require("@eslint/js");
3
+
4
+ const { FlatCompat } = require("@eslint/eslintrc");
5
+
6
+ const compat = new FlatCompat({
7
+ baseDirectory: __dirname,
8
+ recommendedConfig: js.configs.recommended,
9
+ allConfig: js.configs.all,
10
+ });
11
+
12
+ module.exports = [
13
+ {
14
+ ignores: [
15
+ "node_modules/**/*",
16
+ "src/rollup.js",
17
+ "src/repos.js",
18
+ "src/lib.js",
19
+ ],
20
+ },
21
+ ...compat.extends(
22
+ "eslint:recommended",
23
+ //"plugin:node/recommended",
24
+ "plugin:sonarjs/recommended-legacy"
25
+ ),
26
+ {
27
+ languageOptions: {
28
+ globals: {
29
+ ...globals.node,
30
+ ...globals.mongo,
31
+ ...globals.mocha,
32
+ },
33
+
34
+ ecmaVersion: "latest",
35
+ sourceType: "module",
36
+
37
+ parserOptions: {
38
+ requireConfigFile: false,
39
+ allowImportExportEverywhere: false,
40
+
41
+ ecmaFeatures: {
42
+ globalReturn: false,
43
+ },
44
+ },
45
+ },
46
+
47
+ rules: {
48
+ // "node/exports-style": ["error", "module.exports"],
49
+ /*"node/file-extension-in-import": ["error", "always"],
50
+ "node/prefer-global/buffer": ["error", "always"],
51
+ "node/prefer-global/console": ["error", "always"],
52
+ "node/prefer-global/process": ["error", "always"],
53
+ "node/prefer-global/url-search-params": ["error", "always"],
54
+ "node/prefer-global/url": ["error", "always"],
55
+ "node/no-unpublished-require": "warn",*/
56
+
57
+ indent: [
58
+ "error",
59
+ 4,
60
+ {
61
+ SwitchCase: 1,
62
+ },
63
+ ],
64
+
65
+ "linebreak-style": ["error", "unix"],
66
+ semi: ["error", "always"],
67
+ "no-useless-escape": [0],
68
+ },
69
+ },
70
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "not-node",
3
- "version": "6.3.85",
3
+ "version": "6.3.86",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -47,12 +47,13 @@
47
47
  "ejs": "^3.1.10",
48
48
  "escape-string-regexp": "*",
49
49
  "express": "^4.19.2",
50
- "express-fileupload": "^1.5.0",
50
+ "express-fileupload": "^1.5.1",
51
51
  "express-session": "^1.18.0",
52
52
  "fs-extra": "*",
53
53
  "generate-password": "^1.7.1",
54
54
  "helmet": "^7.1.0",
55
- "inquirer": "^9.3.4",
55
+ "inquirer": "^10.1.8",
56
+ "inquirer-autocomplete-prompt": "^3.0.1",
56
57
  "jsonwebtoken": "^9.0.2",
57
58
  "lower-case": "*",
58
59
  "method-override": "^3.0.0",
@@ -66,10 +67,10 @@
66
67
  "not-monitor": "*",
67
68
  "not-path": "*",
68
69
  "rate-limiter-flexible": "^5.0.3",
69
- "redis": "^4.6.15",
70
+ "redis": "^4.7.0",
70
71
  "redlock": "^5.0.0-beta.2",
71
72
  "rfdc": "^1.4.1",
72
- "rimraf": "^5.0.8",
73
+ "rimraf": "^6.0.1",
73
74
  "serve-static": "*",
74
75
  "simple-git": "*",
75
76
  "validator": "*",
@@ -80,23 +81,23 @@
80
81
  "babel-eslint": "^10.1.0",
81
82
  "chai": "*",
82
83
  "chai-as-promised": "*",
83
- "eslint": "^9.6.0",
84
+ "eslint": "^9.9.0",
84
85
  "eslint-plugin-node": "^11.1.0",
85
- "eslint-plugin-sonarjs": "^1.0.3",
86
- "husky": "^9.0.11",
86
+ "eslint-plugin-sonarjs": "^1.0.4",
87
+ "husky": "^9.1.4",
87
88
  "ink-docstrap": "^1.3.2",
88
89
  "ioredis": "^5.4.1",
89
90
  "jsdoc": "^4.0.3",
90
91
  "mocha": "*",
91
92
  "mocha-suppress-logs": "^0.5.1",
92
93
  "mock-require": "^3.0.3",
93
- "mongodb-memory-server": "^9.4.0",
94
- "mongoose": "^8.4.5",
94
+ "mongodb-memory-server": "^10.0.0",
95
+ "mongoose": "^8.5.3",
95
96
  "not-error": "^0.2.9",
96
97
  "not-validation": "^0.0.9",
97
98
  "npm-run-all": "^4.1.5",
98
99
  "nyc": "^17.0.0",
99
- "retire": "^5.1.1"
100
+ "retire": "^5.1.3"
100
101
  },
101
102
  "homepage": "https://github.com/interrupter/not-node#readme",
102
103
  "nyc": {
@@ -3,7 +3,7 @@ import { resolve } from "node:path";
3
3
  import Logger from "../lib/log.mjs";
4
4
  import { createServerModule } from "../lib/module.server.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 createServerModule(modulesDir, ProjectConfig);
36
+ await createServerModule(modulesDir, ProjectConfig, allFields);
36
37
  });
37
38
  };
@@ -11,13 +11,15 @@ import {
11
11
  import { ProjectSubStructures } from "./structures.mjs";
12
12
 
13
13
  import { spawn } from "node:child_process";
14
- import { resolve, join } from "node:path";
14
+ import { resolve, join, parse } from "node:path";
15
15
  import {
16
16
  copyFile,
17
17
  constants,
18
18
  mkdir,
19
19
  writeFile,
20
20
  readFile,
21
+ readdir,
22
+ lstat,
21
23
  } from "node:fs/promises";
22
24
 
23
25
  import ejs from "ejs";
@@ -176,7 +178,103 @@ function buildClientSideScripts(siteDir) {
176
178
 
177
179
  async function readJSONFile(fname) {
178
180
  const rawdata = await readFile(fname);
179
- return JSON.parse(rawdata);
181
+ return JSON.parse(rawdata.toString());
182
+ }
183
+
184
+ async function tryDirAsync(dirPath) {
185
+ try {
186
+ const stat = await lstat(dirPath);
187
+ return stat && stat.isDirectory();
188
+ } catch {
189
+ return false;
190
+ }
191
+ }
192
+
193
+ function isJSFilename(fname) {
194
+ return new RegExp(".+.(js|cjs|mjs)+$").test(fname);
195
+ }
196
+
197
+ function removeExtension(fname) {
198
+ return parse(fname).name;
199
+ }
200
+
201
+ async function findFieldsInDir(pathToDir) {
202
+ const fields = await readdir(pathToDir);
203
+ return fields.filter(isJSFilename).map(removeExtension);
204
+ }
205
+
206
+ async function findFieldsInModule(pathToModule) {
207
+ const variants = [
208
+ join(pathToModule, "src/core/fields"),
209
+ join(pathToModule, "src/fields"),
210
+ join(pathToModule, "fields"),
211
+ ];
212
+ try {
213
+ for (const nameVariants of variants) {
214
+ if (await tryDirAsync(nameVariants)) {
215
+ return await findFieldsInDir(nameVariants);
216
+ }
217
+ }
218
+ return [];
219
+ } catch (e) {
220
+ console.error(e);
221
+ return [];
222
+ }
223
+ }
224
+
225
+ /**
226
+ *
227
+ * @param {*} modulesDirPath
228
+ * @returns {Promise<Array>}
229
+ */
230
+ async function findAllFieldsInModules(modulesDirPath) {
231
+ try {
232
+ const modulesNames = await readdir(modulesDirPath);
233
+ const result = [];
234
+ for (const moduleName of modulesNames) {
235
+ if (moduleName && moduleName.indexOf("not-") === 0) {
236
+ console.log("searchin in ", moduleName);
237
+ const listOfFieldsInModule = await findFieldsInModule(
238
+ join(modulesDirPath, moduleName)
239
+ );
240
+ if (listOfFieldsInModule && listOfFieldsInModule.length) {
241
+ const listOfFieldsDescriptions = listOfFieldsInModule.map(
242
+ (fieldName) => {
243
+ return {
244
+ fieldName,
245
+ moduleName,
246
+ fullName: `${moduleName}//${fieldName}`,
247
+ };
248
+ }
249
+ );
250
+ console.log(listOfFieldsDescriptions);
251
+ result.push(...listOfFieldsDescriptions);
252
+ }
253
+ }
254
+ }
255
+ return result;
256
+ } catch (err) {
257
+ console.error(err);
258
+ return [];
259
+ }
260
+ }
261
+
262
+ async function findAllFieldsInNodeModules(siteDirPath) {
263
+ const dirname = join(siteDirPath, "node_modules");
264
+ return await findAllFieldsInModules(dirname);
265
+ }
266
+
267
+ async function findAllFields(siteDirPath, modulesDir) {
268
+ try {
269
+ const fieldsInNodeModules = await findAllFieldsInNodeModules(
270
+ siteDirPath
271
+ );
272
+ const fieldsInProjectModules = await findAllFieldsInModules(modulesDir);
273
+ return [...fieldsInNodeModules, ...fieldsInProjectModules];
274
+ } catch (err) {
275
+ console.error(err);
276
+ return [];
277
+ }
180
278
  }
181
279
 
182
280
  export {
@@ -190,4 +288,6 @@ export {
190
288
  installPackages,
191
289
  readJSONFile,
192
290
  getProjectSiteDir,
291
+ findAllFields,
292
+ findFieldsInModule,
193
293
  };
@@ -1,7 +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";
4
5
 
6
+ inquirer.registerPrompt("autocomplete", inquirerPrompt);
5
7
  import * as Readers from "../readers/index.mjs";
6
8
  import * as Renderers from "../renderers/index.mjs";
7
9
  import Options from "../lib/opts.mjs";
@@ -91,7 +93,7 @@ async function createServerModule(modules_dir, config) {
91
93
  while (await Readers.isUserNeedCreateEntity(inquirer)) {
92
94
  const entityData = await Readers.entityData(
93
95
  inquirer,
94
- config,
96
+ moduleConfig,
95
97
  layersList
96
98
  );
97
99
  entitiesList.push(entityData);
@@ -28,27 +28,31 @@ function collectData(inquirer) {
28
28
 
29
29
  export default (inquirer, config, layersList) => {
30
30
  return collectData(inquirer).then(async (answer) => {
31
- const result = {
32
- ...answer,
33
- modelName: firstLetterToLower(answer.ModelName),
34
- actions: await actions(inquirer),
35
- fields: await fields(inquirer),
36
- layers: await entityLayers(inquirer, config, layersList),
37
- };
38
- if (result.layers.includes("models")) {
39
- result.validators = await modelValidators(inquirer);
40
- result.versioning = await modelVersioning(inquirer);
41
- result.increment = await modelIncrement(inquirer, result);
42
- result.ownage = await modelOwnage(inquirer);
43
- result.dates = await modelDates(inquirer);
44
- } else {
45
- result.increment = false;
46
- result.versioning = false;
47
- result.validators = true;
48
- result.ownage = false;
49
- result.dates = false;
31
+ try {
32
+ const result = {
33
+ ...answer,
34
+ modelName: firstLetterToLower(answer.ModelName),
35
+ actions: await actions(inquirer),
36
+ fields: await fields(inquirer, config),
37
+ layers: await entityLayers(inquirer, config, layersList),
38
+ };
39
+ if (result.layers.includes("models")) {
40
+ result.validators = await modelValidators(inquirer);
41
+ result.versioning = await modelVersioning(inquirer);
42
+ result.increment = await modelIncrement(inquirer, result);
43
+ result.ownage = await modelOwnage(inquirer);
44
+ result.dates = await modelDates(inquirer);
45
+ } else {
46
+ result.increment = false;
47
+ result.versioning = false;
48
+ result.validators = true;
49
+ result.ownage = false;
50
+ result.dates = false;
51
+ }
52
+ console.log("Entity data", JSON.stringify(result));
53
+ return result;
54
+ } catch (e) {
55
+ console.error(e);
50
56
  }
51
- console.log("Entity data", JSON.stringify(result));
52
- return result;
53
57
  });
54
58
  };
@@ -1,13 +1,53 @@
1
- export default (inquirer) => {
2
- return inquirer
3
- .prompt([
4
- {
5
- type: "input",
6
- message: "Enter comma separated fields names",
7
- name: "fields",
8
- },
9
- ])
10
- .then((answer) =>
11
- answer.fields.split(",").map((entry) => entry.trim())
12
- );
1
+ export default async (inquirer, config) => {
2
+ const result = [];
3
+ let finished = false;
4
+ while (!finished) {
5
+ try {
6
+ await inquirer
7
+ .prompt([
8
+ {
9
+ type: "autocomplete",
10
+ message: "Enter field name you want to be in model",
11
+ name: "fieldname",
12
+ source: async (answers, input = "") => {
13
+ let searchResults = [];
14
+ try {
15
+ if (typeof input == "string") {
16
+ searchResults = config.availableFields
17
+ .filter((s) =>
18
+ s.fullName
19
+ .toLowerCase()
20
+ .includes(input.toLowerCase())
21
+ )
22
+ .map((r) => r.fullName);
23
+ }
24
+ } catch (e) {
25
+ console.error(e);
26
+ }
27
+ return searchResults;
28
+ },
29
+ },
30
+ ])
31
+ .then((answer) => {
32
+ result.push(answer.fieldname.trim());
33
+ });
34
+
35
+ finished = await inquirer
36
+ .prompt([
37
+ {
38
+ type: "confirm",
39
+ name: "oneMore",
40
+ message: `Add another one field to [${result.join(
41
+ ","
42
+ )}] (default: true)?`,
43
+ default: true,
44
+ },
45
+ ])
46
+ .then((answer) => !answer.oneMore);
47
+ } catch (e) {
48
+ console.error(e);
49
+ return result;
50
+ }
51
+ }
52
+ return result;
13
53
  };
package/src/common.js CHANGED
@@ -31,7 +31,7 @@ module.exports.firstLetterToUpper = function (string) {
31
31
  module.exports.validateObjectId = (id) => {
32
32
  try {
33
33
  return id.toString().match(/^[0-9a-fA-F]{24}$/) ? true : false;
34
- } catch (e) {
34
+ } catch {
35
35
  return false;
36
36
  }
37
37
  };
@@ -62,7 +62,7 @@ module.exports.compareObjectIds = (firstId, secondId) => {
62
62
  return false;
63
63
  }
64
64
  return a === b;
65
- } catch (e) {
65
+ } catch {
66
66
  return false;
67
67
  }
68
68
  };
@@ -229,7 +229,7 @@ module.exports.tryFile = (filePath) => {
229
229
  try {
230
230
  const stat = fs.lstatSync(filePath);
231
231
  return stat && stat.isFile();
232
- } catch (e) {
232
+ } catch {
233
233
  return false;
234
234
  }
235
235
  };
@@ -243,7 +243,7 @@ module.exports.tryFileAsync = async (filePath) => {
243
243
  try {
244
244
  const stat = await fs.promises.lstat(filePath);
245
245
  return stat && stat.isFile();
246
- } catch (e) {
246
+ } catch {
247
247
  return false;
248
248
  }
249
249
  };
@@ -257,7 +257,7 @@ module.exports.tryDirAsync = async (dirPath) => {
257
257
  try {
258
258
  const stat = await fs.promises.lstat(dirPath);
259
259
  return stat && stat.isDirectory();
260
- } catch (e) {
260
+ } catch {
261
261
  return false;
262
262
  }
263
263
  };
@@ -271,7 +271,7 @@ module.exports.tryDirAsync = async (dirPath) => {
271
271
  module.exports.tryParse = (input, def = undefined) => {
272
272
  try {
273
273
  return JSON.parse(input);
274
- } catch (e) {
274
+ } catch {
275
275
  return def;
276
276
  }
277
277
  };
@@ -62,6 +62,7 @@ class notFieldsFilter {
62
62
  static #USER_DEFINED_SETS = {};
63
63
 
64
64
  static get userSets() {
65
+ //eslint-disable-next-line no-undef
65
66
  return structuredClone(this.#USER_DEFINED_SETS);
66
67
  }
67
68
 
package/src/form/form.js CHANGED
@@ -47,7 +47,7 @@ class Form {
47
47
  form: [],
48
48
  forms: {},
49
49
  };
50
- #MODEL_SCHEMA;
50
+ //#MODEL_SCHEMA;
51
51
  /**
52
52
  * @prop {string} name of form
53
53
  **/
@@ -272,7 +272,6 @@ class Form {
272
272
  * @param {import('../types').notNodeExpressRequest} [req]
273
273
  * @return {Promise<import('../types').PreparedData>}
274
274
  */
275
- //eslint-disable-next-line no-unused-vars
276
275
  async afterExtract(value, req) {
277
276
  if (this.#AFTER_EXTRACT_TRANSFORMERS) {
278
277
  this.#AFTER_EXTRACT_TRANSFORMERS.forEach((aeTransformer) => {
@@ -778,7 +777,7 @@ class Form {
778
777
  (await this.#rateLimiter.consume(
779
778
  this.#rateLimiterIdGetter(envs)
780
779
  ));
781
- } catch (_) {
780
+ } catch {
782
781
  throw new this.#rateLimiterException(envs);
783
782
  }
784
783
  }
@@ -21,12 +21,13 @@ class Identity {
21
21
  session: IdentityProviderSession,
22
22
  token: IdentityProviderToken,
23
23
  };
24
-
24
+ //eslint-disable-next-line no-unused-private-class-members
25
25
  static #primaryRoles = [
26
26
  DEFAULT_USER_ROLE_FOR_ROOT,
27
27
  DEFAULT_USER_ROLE_FOR_ADMIN,
28
28
  DEFAULT_USER_ROLE_FOR_GUEST,
29
29
  ];
30
+ //eslint-disable-next-line no-unused-private-class-members
30
31
  static #secondaryRoles = [];
31
32
 
32
33
  static setPrimaryRoles(list = []) {