not-node 6.3.85 → 6.3.87
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/eslint.config.cjs +70 -0
- package/package.json +12 -11
- package/src/auth/fields.js +1 -1
- package/src/cli/actions/module.server.mjs +3 -2
- package/src/cli/const.mjs +1 -0
- package/src/cli/lib/entity.mjs +2 -2
- package/src/cli/lib/fs.mjs +123 -17
- package/src/cli/lib/module.server.mjs +15 -12
- package/src/cli/readers/entityData.mjs +32 -21
- package/src/cli/readers/fields.mjs +52 -12
- package/src/cli/renderers/controllersCommons.mjs +2 -2
- package/src/cli/renderers/controllersIndex.mjs +13 -7
- package/src/cli/renderers/fields.mjs +1 -1
- package/src/cli/renderers/forms.mjs +1 -1
- package/src/cli/renderers/models.mjs +1 -1
- package/src/common.js +6 -6
- package/src/fields/filter.js +1 -0
- package/src/form/form.js +2 -3
- package/src/identity/identity.js +2 -1
- package/src/manifest/result.filter.js +1 -1
- package/test/common.js +1 -1
- package/tmpl/files/module.server/layers/routes.manifest.ejs +12 -11
|
@@ -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.
|
|
3
|
+
"version": "6.3.87",
|
|
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.
|
|
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": "^
|
|
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.
|
|
70
|
+
"redis": "^4.7.0",
|
|
70
71
|
"redlock": "^5.0.0-beta.2",
|
|
71
72
|
"rfdc": "^1.4.1",
|
|
72
|
-
"rimraf": "^
|
|
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.
|
|
84
|
+
"eslint": "^9.9.0",
|
|
84
85
|
"eslint-plugin-node": "^11.1.0",
|
|
85
|
-
"eslint-plugin-sonarjs": "^1.0.
|
|
86
|
-
"husky": "^9.
|
|
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": "^
|
|
94
|
-
"mongoose": "^8.
|
|
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.
|
|
100
|
+
"retire": "^5.1.3"
|
|
100
101
|
},
|
|
101
102
|
"homepage": "https://github.com/interrupter/not-node#readme",
|
|
102
103
|
"nyc": {
|
package/src/auth/fields.js
CHANGED
|
@@ -34,7 +34,7 @@ function isOwner(
|
|
|
34
34
|
ownerFieldName = CONST.DOCUMENT_OWNER_FIELD_NAME
|
|
35
35
|
) {
|
|
36
36
|
const ownerId = getOwnerId(data, ownerFieldName);
|
|
37
|
-
|
|
37
|
+
|
|
38
38
|
if (typeof ownerId !== "undefined") {
|
|
39
39
|
return COMMON.compareObjectIds(ownerId, user_id);
|
|
40
40
|
} else {
|
|
@@ -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
|
};
|
package/src/cli/const.mjs
CHANGED
package/src/cli/lib/entity.mjs
CHANGED
|
@@ -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,
|
package/src/cli/lib/fs.mjs
CHANGED
|
@@ -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";
|
|
@@ -26,22 +28,30 @@ import Options from "./opts.mjs";
|
|
|
26
28
|
const PATH_TMPL = Options.PATH_TMPL;
|
|
27
29
|
|
|
28
30
|
async function renderFile(input, dest, data) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
+
}
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
async function createFileContent(filePath, structure, config) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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);
|
|
45
55
|
}
|
|
46
56
|
}
|
|
47
57
|
|
|
@@ -72,10 +82,10 @@ function getProjectSiteDir(dir, CWD) {
|
|
|
72
82
|
|
|
73
83
|
async function createDir(dirPath) {
|
|
74
84
|
try {
|
|
75
|
-
|
|
85
|
+
console.log("mkdir", dirPath);
|
|
76
86
|
await mkdir(dirPath, { recursive: true });
|
|
77
87
|
} catch {
|
|
78
|
-
|
|
88
|
+
console.error("Can't create directory", dirPath);
|
|
79
89
|
}
|
|
80
90
|
}
|
|
81
91
|
|
|
@@ -176,7 +186,101 @@ function buildClientSideScripts(siteDir) {
|
|
|
176
186
|
|
|
177
187
|
async function readJSONFile(fname) {
|
|
178
188
|
const rawdata = await readFile(fname);
|
|
179
|
-
return JSON.parse(rawdata);
|
|
189
|
+
return JSON.parse(rawdata.toString());
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
async function tryDirAsync(dirPath) {
|
|
193
|
+
try {
|
|
194
|
+
const stat = await lstat(dirPath);
|
|
195
|
+
return stat && stat.isDirectory();
|
|
196
|
+
} catch {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
function isJSFilename(fname) {
|
|
202
|
+
return new RegExp(".+.(js|cjs|mjs)+$").test(fname);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function removeExtension(fname) {
|
|
206
|
+
return parse(fname).name;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
async function findFieldsInDir(pathToDir) {
|
|
210
|
+
const fields = await readdir(pathToDir);
|
|
211
|
+
return fields.filter(isJSFilename).map(removeExtension);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async function findFieldsInModule(pathToModule) {
|
|
215
|
+
const variants = [
|
|
216
|
+
join(pathToModule, "src/core/fields"),
|
|
217
|
+
join(pathToModule, "src/fields"),
|
|
218
|
+
join(pathToModule, "fields"),
|
|
219
|
+
];
|
|
220
|
+
try {
|
|
221
|
+
for (const nameVariants of variants) {
|
|
222
|
+
if (await tryDirAsync(nameVariants)) {
|
|
223
|
+
return await findFieldsInDir(nameVariants);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return [];
|
|
227
|
+
} catch (e) {
|
|
228
|
+
console.error(e);
|
|
229
|
+
return [];
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
*
|
|
235
|
+
* @param {*} modulesDirPath
|
|
236
|
+
* @returns {Promise<Array>}
|
|
237
|
+
*/
|
|
238
|
+
async function findAllFieldsInModules(modulesDirPath) {
|
|
239
|
+
try {
|
|
240
|
+
const modulesNames = await readdir(modulesDirPath);
|
|
241
|
+
const result = [];
|
|
242
|
+
for (const moduleName of modulesNames) {
|
|
243
|
+
if (moduleName && moduleName.indexOf("not-") === 0) {
|
|
244
|
+
const listOfFieldsInModule = await findFieldsInModule(
|
|
245
|
+
join(modulesDirPath, moduleName)
|
|
246
|
+
);
|
|
247
|
+
if (listOfFieldsInModule && listOfFieldsInModule.length) {
|
|
248
|
+
const listOfFieldsDescriptions = listOfFieldsInModule.map(
|
|
249
|
+
(fieldName) => {
|
|
250
|
+
return {
|
|
251
|
+
fieldName,
|
|
252
|
+
moduleName,
|
|
253
|
+
fullName: `${moduleName}//${fieldName}`,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
);
|
|
257
|
+
result.push(...listOfFieldsDescriptions);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return result;
|
|
262
|
+
} catch (err) {
|
|
263
|
+
console.error(err);
|
|
264
|
+
return [];
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
async function findAllFieldsInNodeModules(siteDirPath) {
|
|
269
|
+
const dirname = join(siteDirPath, "node_modules");
|
|
270
|
+
return await findAllFieldsInModules(dirname);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
async function findAllFields(siteDirPath, modulesDir) {
|
|
274
|
+
try {
|
|
275
|
+
const fieldsInNodeModules = await findAllFieldsInNodeModules(
|
|
276
|
+
siteDirPath
|
|
277
|
+
);
|
|
278
|
+
const fieldsInProjectModules = await findAllFieldsInModules(modulesDir);
|
|
279
|
+
return [...fieldsInNodeModules, ...fieldsInProjectModules];
|
|
280
|
+
} catch (err) {
|
|
281
|
+
console.error(err);
|
|
282
|
+
return [];
|
|
283
|
+
}
|
|
180
284
|
}
|
|
181
285
|
|
|
182
286
|
export {
|
|
@@ -190,4 +294,6 @@ export {
|
|
|
190
294
|
installPackages,
|
|
191
295
|
readJSONFile,
|
|
192
296
|
getProjectSiteDir,
|
|
297
|
+
findAllFields,
|
|
298
|
+
findFieldsInModule,
|
|
193
299
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { firstLetterToLower } from "../../../src/common.js";
|
|
2
|
-
import {
|
|
2
|
+
import { join } 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";
|
|
@@ -24,10 +26,10 @@ function entitiesInLayers(layersList = []) {
|
|
|
24
26
|
|
|
25
27
|
async function createLayersDirs(modules_dir, layersList, ModuleName) {
|
|
26
28
|
if (layersList.length) {
|
|
27
|
-
await createDir(
|
|
29
|
+
await createDir(join(modules_dir, ModuleName, "./src"));
|
|
28
30
|
}
|
|
29
31
|
for (let layer of layersList) {
|
|
30
|
-
await createDir(
|
|
32
|
+
await createDir(join(modules_dir, ModuleName, "./src", layer));
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
|
|
@@ -36,7 +38,8 @@ async function renderServerControllersCommons(
|
|
|
36
38
|
entitiesData,
|
|
37
39
|
config
|
|
38
40
|
) {
|
|
39
|
-
const dirPath =
|
|
41
|
+
const dirPath = join(module_src_dir, `./common`);
|
|
42
|
+
//console.log('renderServerControllersCommons',dirPath);
|
|
40
43
|
await createDir(dirPath);
|
|
41
44
|
await createDirContent(
|
|
42
45
|
dirPath,
|
|
@@ -60,7 +63,7 @@ async function renderServerContollersIndexes(
|
|
|
60
63
|
const subDirList = [...config.roles];
|
|
61
64
|
for (let dirName of subDirList) {
|
|
62
65
|
await Renderers.controllersIndex(
|
|
63
|
-
|
|
66
|
+
join(module_src_dir, `./controllers/${dirName}`),
|
|
64
67
|
entitiesData,
|
|
65
68
|
config,
|
|
66
69
|
renderFile,
|
|
@@ -69,12 +72,12 @@ async function renderServerContollersIndexes(
|
|
|
69
72
|
}
|
|
70
73
|
}
|
|
71
74
|
|
|
72
|
-
async function createServerModule(modules_dir, config) {
|
|
75
|
+
async function createServerModule(modules_dir, config, availableFields) {
|
|
73
76
|
//read module name
|
|
74
77
|
const ModuleName = await Readers.ModuleName(inquirer);
|
|
75
78
|
const moduleName = firstLetterToLower(ModuleName);
|
|
76
|
-
const moduleDir =
|
|
77
|
-
const moduleConfig = { ...config, moduleName, ModuleName };
|
|
79
|
+
const moduleDir = join(modules_dir, ModuleName);
|
|
80
|
+
const moduleConfig = { ...config, moduleName, ModuleName, availableFields };
|
|
78
81
|
await createDir(moduleDir);
|
|
79
82
|
//console.log(JSON.stringify(moduleConfig, null, 4));
|
|
80
83
|
await createDirContent(
|
|
@@ -91,26 +94,26 @@ async function createServerModule(modules_dir, config) {
|
|
|
91
94
|
while (await Readers.isUserNeedCreateEntity(inquirer)) {
|
|
92
95
|
const entityData = await Readers.entityData(
|
|
93
96
|
inquirer,
|
|
94
|
-
|
|
97
|
+
moduleConfig,
|
|
95
98
|
layersList
|
|
96
99
|
);
|
|
97
100
|
entitiesList.push(entityData);
|
|
98
101
|
}
|
|
99
102
|
for (let entityData of entitiesList) {
|
|
100
103
|
await renderEntityFiles(
|
|
101
|
-
|
|
104
|
+
join(moduleDir, "./src"),
|
|
102
105
|
entityData,
|
|
103
106
|
moduleConfig
|
|
104
107
|
);
|
|
105
108
|
}
|
|
106
109
|
if (layersList.includes("controllers")) {
|
|
107
110
|
await renderServerContollersIndexes(
|
|
108
|
-
|
|
111
|
+
join(moduleDir, "./src"),
|
|
109
112
|
entitiesList,
|
|
110
113
|
moduleConfig
|
|
111
114
|
);
|
|
112
115
|
await renderServerControllersCommons(
|
|
113
|
-
|
|
116
|
+
join(moduleDir, "./src/controllers"),
|
|
114
117
|
entitiesList,
|
|
115
118
|
moduleConfig
|
|
116
119
|
);
|
|
@@ -28,27 +28,38 @@ function collectData(inquirer) {
|
|
|
28
28
|
|
|
29
29
|
export default (inquirer, config, layersList) => {
|
|
30
30
|
return collectData(inquirer).then(async (answer) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
result.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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.fieldsShortNames = result.fields.map((itm) => itm.indexOf('//') > 0?itm.split('//')[1]:itm);
|
|
41
|
+
result.validators = await modelValidators(inquirer);
|
|
42
|
+
result.versioning = await modelVersioning(inquirer);
|
|
43
|
+
result.ownage = await modelOwnage(inquirer);
|
|
44
|
+
result.ownageFields = result.ownage?['not-node//owner','not-node//ownerModel']:[];
|
|
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});
|
|
49
|
+
} else {
|
|
50
|
+
result.fields = [];
|
|
51
|
+
result.fieldsShortNames = [];
|
|
52
|
+
result.increment = false;
|
|
53
|
+
result.versioning = false;
|
|
54
|
+
result.validators = true;
|
|
55
|
+
result.ownage = false;
|
|
56
|
+
result.ownageFields = [];
|
|
57
|
+
result.dates = false;
|
|
58
|
+
result.datesFields = [];
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
} catch (e) {
|
|
62
|
+
console.error(e);
|
|
50
63
|
}
|
|
51
|
-
console.log("Entity data", JSON.stringify(result));
|
|
52
|
-
return result;
|
|
53
64
|
});
|
|
54
65
|
};
|
|
@@ -1,13 +1,53 @@
|
|
|
1
|
-
export default (inquirer) => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
};
|
|
@@ -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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
};
|
|
@@ -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}
|
|
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/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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
274
|
+
} catch {
|
|
275
275
|
return def;
|
|
276
276
|
}
|
|
277
277
|
};
|
package/src/fields/filter.js
CHANGED
package/src/form/form.js
CHANGED
|
@@ -47,7 +47,7 @@ class Form {
|
|
|
47
47
|
form: [],
|
|
48
48
|
forms: {},
|
|
49
49
|
};
|
|
50
|
-
|
|
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
|
}
|
package/src/identity/identity.js
CHANGED
|
@@ -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 = []) {
|
|
@@ -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);
|
|
@@ -3,11 +3,12 @@ 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
|
-
|
|
6
|
+
<% const fieldsShortNames = (fields | []).map((entry) => entry.indexOf('//')>-1?entry.split('//')[0]:entry); %>
|
|
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 %>",
|
|
11
|
+
<% } %><% } %>
|
|
11
12
|
<% if (ownage){ %>["owner", "not-node//owner"],
|
|
12
13
|
["ownerModel", "not-node//ownerModel"],<% } %>
|
|
13
14
|
<% if (dates){ %> ["createdAt", "not-node//createdAt"],
|
|
@@ -33,12 +34,12 @@ module.exports = {
|
|
|
33
34
|
{
|
|
34
35
|
auth: true,
|
|
35
36
|
role: "admin",
|
|
36
|
-
fields: [<%-
|
|
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: [
|
|
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
|
-
<%-
|
|
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
|
-
<%-
|
|
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
|
-
<%-
|
|
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
|
-
<%-
|
|
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
|
-
<%-
|
|
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: [<%-
|
|
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
|
-
<%-
|
|
184
|
+
<%- fieldsShortNames.map((entry) => `"${entry}"`).join(',') %>,
|
|
184
185
|
<% if (dates){ %>"createdAt","updatedAt",<% } %>
|
|
185
186
|
],
|
|
186
187
|
postFix: actionNamePath,
|