not-node 6.3.86 → 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/package.json +1 -1
- package/src/auth/fields.js +1 -1
- package/src/cli/const.mjs +1 -0
- package/src/cli/lib/entity.mjs +2 -2
- package/src/cli/lib/fs.mjs +25 -19
- package/src/cli/lib/module.server.mjs +12 -11
- package/src/cli/readers/entityData.mjs +11 -4
- 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/manifest/result.filter.js +1 -1
- package/test/common.js +1 -1
- package/tmpl/files/module.server/layers/routes.manifest.ejs +12 -11
package/package.json
CHANGED
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 {
|
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
|
@@ -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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
85
|
+
console.log("mkdir", dirPath);
|
|
78
86
|
await mkdir(dirPath, { recursive: true });
|
|
79
87
|
} catch {
|
|
80
|
-
|
|
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 {
|
|
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(
|
|
29
|
+
await createDir(join(modules_dir, ModuleName, "./src"));
|
|
30
30
|
}
|
|
31
31
|
for (let layer of layersList) {
|
|
32
|
-
await createDir(
|
|
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 =
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
111
|
+
join(moduleDir, "./src"),
|
|
111
112
|
entitiesList,
|
|
112
113
|
moduleConfig
|
|
113
114
|
);
|
|
114
115
|
await renderServerControllersCommons(
|
|
115
|
-
|
|
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.indexOf('//') > 0?itm.split('//')[1]:itm);
|
|
40
41
|
result.validators = await modelValidators(inquirer);
|
|
41
|
-
result.versioning = await modelVersioning(inquirer);
|
|
42
|
-
result.increment = await modelIncrement(inquirer, result);
|
|
42
|
+
result.versioning = await modelVersioning(inquirer);
|
|
43
43
|
result.ownage = await modelOwnage(inquirer);
|
|
44
|
+
result.ownageFields = result.ownage?['not-node//owner','not-node//ownerModel']:[];
|
|
44
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});
|
|
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;
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
result.datesFields = [];
|
|
59
|
+
}
|
|
53
60
|
return result;
|
|
54
61
|
} catch (e) {
|
|
55
62
|
console.error(e);
|
|
@@ -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
|
};
|
|
@@ -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,
|