not-node 6.4.14 → 6.5.1
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/bootstrap/route.js +52 -7
- package/src/form/form.js +1 -18
- package/src/generic/field._data.js +1 -1
- package/src/generic/form.js +29 -0
- package/src/generic/{form._data.js → forms/form._data.js} +1 -1
- package/src/generic/{form.authorizedAction.js → forms/form.authorizedAction.js} +1 -1
- package/src/generic/forms/form.count.js +9 -0
- package/src/generic/{form.create.js → forms/form.create.js} +2 -2
- package/src/generic/forms/form.delete.js +9 -0
- package/src/generic/forms/form.get.js +9 -0
- package/src/generic/{form.getByID.js → forms/form.getByID.js} +1 -1
- package/src/generic/{form.getById.js → forms/form.getById.js} +1 -1
- package/src/generic/forms/form.getRaw.js +9 -0
- package/src/generic/{form.list.js → forms/form.list.js} +4 -4
- package/src/generic/forms/form.listAll.js +9 -0
- package/src/generic/{form.listAndCount.js → forms/form.listAndCount.js} +4 -4
- package/src/generic/{form.update.js → forms/form.update.js} +2 -2
- package/src/generic/forms/index.js +12 -0
- package/src/generic/index.js +8 -8
package/package.json
CHANGED
package/src/bootstrap/route.js
CHANGED
|
@@ -4,7 +4,10 @@ const getApp = require("../getApp.js"),
|
|
|
4
4
|
configInit = require("not-config"),
|
|
5
5
|
{ sayForModule } = require("not-locale"),
|
|
6
6
|
{ objHas, isFunc, executeFunctionAsAsync } = require("../common"),
|
|
7
|
-
LogInit = require("not-log")
|
|
7
|
+
LogInit = require("not-log"),
|
|
8
|
+
genericFormsGenerators = require("../generic/forms"),
|
|
9
|
+
createDefaultFormInstance = require("../generic/form.js");
|
|
10
|
+
|
|
8
11
|
module.exports = ({
|
|
9
12
|
target,
|
|
10
13
|
MODULE_NAME,
|
|
@@ -33,7 +36,9 @@ module.exports = ({
|
|
|
33
36
|
accessRulesBuilders = {}, //per action builders, {actionName: (preapared: any, req: ExpressRequest)=>{/** pass or throw an exception **/ */}}
|
|
34
37
|
accessRuleBuilder = false, //universal will be used if no dedicated action builder was found
|
|
35
38
|
defaultAccessRule = false, //if builder is not found, safe by default
|
|
36
|
-
createForm =
|
|
39
|
+
createForm = createDefaultFormInstance,
|
|
40
|
+
formValidators = {},
|
|
41
|
+
dataValidators = {},
|
|
37
42
|
}) => {
|
|
38
43
|
const Log = LogInit(target, `${MODEL_NAME}/Routes'`);
|
|
39
44
|
const say = sayForModule(MODULE_NAME);
|
|
@@ -80,26 +85,66 @@ module.exports = ({
|
|
|
80
85
|
}
|
|
81
86
|
};
|
|
82
87
|
|
|
88
|
+
const initGenericActionForm = ({
|
|
89
|
+
app,
|
|
90
|
+
MODULE_NAME,
|
|
91
|
+
MODEL_NAME,
|
|
92
|
+
actionName,
|
|
93
|
+
validators,
|
|
94
|
+
dataValidators,
|
|
95
|
+
}) => {
|
|
96
|
+
if (Object.keys(genericFormsGenerators).includes(actionName)) {
|
|
97
|
+
return new genericFormsGenerators[actionName]({
|
|
98
|
+
app,
|
|
99
|
+
MODULE_NAME,
|
|
100
|
+
MODEL_NAME,
|
|
101
|
+
actionName,
|
|
102
|
+
validators,
|
|
103
|
+
dataValidators,
|
|
104
|
+
})(app);
|
|
105
|
+
} else {
|
|
106
|
+
createForm({
|
|
107
|
+
app: getApp(),
|
|
108
|
+
MODULE_NAME,
|
|
109
|
+
MODEL_NAME,
|
|
110
|
+
actionName,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
83
115
|
const getForm = (actionName) => {
|
|
84
|
-
|
|
85
|
-
|
|
116
|
+
//trying inited and cached
|
|
117
|
+
const fullFormPath = Form.createPath(
|
|
118
|
+
MODULE_NAME,
|
|
119
|
+
MODEL_NAME,
|
|
120
|
+
actionName
|
|
86
121
|
);
|
|
122
|
+
const form = getApp().getForm(fullFormPath);
|
|
87
123
|
if (form) {
|
|
88
124
|
return form;
|
|
89
125
|
}
|
|
126
|
+
|
|
90
127
|
const form2 = getApp().getForm(
|
|
91
128
|
Form.createPath(MODULE_NAME, undefined, actionName)
|
|
92
129
|
);
|
|
130
|
+
|
|
93
131
|
if (form2) {
|
|
94
132
|
return form2;
|
|
95
133
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
app: getApp(),
|
|
134
|
+
//creating new from generics lib
|
|
135
|
+
const newelyCreatedForm = initGenericActionForm({
|
|
99
136
|
MODULE_NAME,
|
|
100
137
|
MODEL_NAME,
|
|
101
138
|
actionName,
|
|
139
|
+
app: getApp(),
|
|
140
|
+
validators: formValidators,
|
|
141
|
+
dataValidators,
|
|
102
142
|
});
|
|
143
|
+
//caching
|
|
144
|
+
getApp()
|
|
145
|
+
.getModule(MODULE_NAME)
|
|
146
|
+
.setForm(fullFormPath.split("//")[1], newelyCreatedForm);
|
|
147
|
+
return newelyCreatedForm;
|
|
103
148
|
};
|
|
104
149
|
|
|
105
150
|
const beforeDecorator = async (req, res, next) => {
|
package/src/form/form.js
CHANGED
|
@@ -116,6 +116,7 @@ class Form {
|
|
|
116
116
|
this.#MODEL_NAME = MODEL_NAME;
|
|
117
117
|
this.#MODULE_NAME = MODULE_NAME;
|
|
118
118
|
this.#setFields(app, FIELDS);
|
|
119
|
+
|
|
119
120
|
this.#createValidationSchema(app);
|
|
120
121
|
this.#augmentValidationSchema();
|
|
121
122
|
this.#addInstructions(INSTRUCTIONS);
|
|
@@ -202,24 +203,6 @@ class Form {
|
|
|
202
203
|
}
|
|
203
204
|
}
|
|
204
205
|
|
|
205
|
-
/**
|
|
206
|
-
*
|
|
207
|
-
* @param {object} options
|
|
208
|
-
* @param {import('../app.js')} options.app
|
|
209
|
-
* @param {string} options.MODULE_NAME
|
|
210
|
-
* @param {string} options.MODEL_NAME
|
|
211
|
-
* @param {string} options.actionName
|
|
212
|
-
* @returns {object} instance of Form
|
|
213
|
-
*/
|
|
214
|
-
static createDefaultInstance({ app, MODULE_NAME, MODEL_NAME, actionName }) {
|
|
215
|
-
const FIELDS = [
|
|
216
|
-
["identity", "not-node//identity"],
|
|
217
|
-
["data", `${MODULE_NAME}//_${firstLetterToLower(MODEL_NAME)}`],
|
|
218
|
-
];
|
|
219
|
-
const FORM_NAME = Form.createName(MODULE_NAME, MODEL_NAME, actionName);
|
|
220
|
-
return new Form({ FIELDS, FORM_NAME, app, MODULE_NAME });
|
|
221
|
-
}
|
|
222
|
-
|
|
223
206
|
/**
|
|
224
207
|
*
|
|
225
208
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const Schema = require("mongoose").Schema;
|
|
2
2
|
const getApp = require("../getApp");
|
|
3
3
|
const { firstLetterToLower } = require("../common");
|
|
4
|
-
const genericDataForm = require("./form._data");
|
|
4
|
+
const genericDataForm = require("./forms/form._data");
|
|
5
5
|
const Form = require("../form/form");
|
|
6
6
|
|
|
7
7
|
const initGenericDataForm = ({
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const Common = require("../common.js");
|
|
2
|
+
const Form = require("../form/form.js");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param {object} options
|
|
7
|
+
* @param {import('../app.js')} options.app
|
|
8
|
+
* @param {string} options.MODULE_NAME
|
|
9
|
+
* @param {string} options.MODEL_NAME
|
|
10
|
+
* @param {string} options.actionName
|
|
11
|
+
* @returns {object} instance of Form
|
|
12
|
+
*/
|
|
13
|
+
function createDefaultInstance({
|
|
14
|
+
app,
|
|
15
|
+
MODULE_NAME,
|
|
16
|
+
MODEL_NAME,
|
|
17
|
+
actionName,
|
|
18
|
+
/* validators = [],
|
|
19
|
+
dataValidators = [],*/
|
|
20
|
+
}) {
|
|
21
|
+
const FIELDS = [
|
|
22
|
+
["identity", "not-node//identity"],
|
|
23
|
+
["data", `${MODULE_NAME}//_${Common.firstLetterToLower(MODEL_NAME)}`],
|
|
24
|
+
];
|
|
25
|
+
const FORM_NAME = Form.createName(MODULE_NAME, MODEL_NAME, actionName);
|
|
26
|
+
return new Form({ FIELDS, FORM_NAME, app, MODULE_NAME });
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = createDefaultInstance;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const Form = require("
|
|
2
|
-
const { getGenericDataField } = require("
|
|
1
|
+
const Form = require("../../form/form");
|
|
2
|
+
const { getGenericDataField } = require("../field");
|
|
3
3
|
/**
|
|
4
4
|
* Creates generic Crud form, if data field is not defined in fields/ it creates and registers field in module and sub _data form
|
|
5
5
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const Form = require("
|
|
1
|
+
const Form = require("../../form/form");
|
|
2
2
|
|
|
3
3
|
const notFilter = require("not-filter");
|
|
4
|
-
const notAppIdentity = require("
|
|
4
|
+
const notAppIdentity = require("../../identity");
|
|
5
5
|
|
|
6
6
|
const FIELDS = [
|
|
7
7
|
["query", `not-filter//_filterQuery`],
|
|
@@ -32,8 +32,8 @@ const FactoryFormList = ({ MODULE_NAME, MODEL_NAME, actionName = "list" }) => {
|
|
|
32
32
|
/**
|
|
33
33
|
*
|
|
34
34
|
*
|
|
35
|
-
* @param {import('
|
|
36
|
-
* @return {Promise<import('
|
|
35
|
+
* @param {import('../../types').notNodeExpressRequest} req
|
|
36
|
+
* @return {Promise<import('../../types').PreparedData>}
|
|
37
37
|
*/
|
|
38
38
|
async extract(req) {
|
|
39
39
|
const envs = this.extractRequestEnvs(req);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const Form = require("
|
|
1
|
+
const Form = require("../../form/form");
|
|
2
2
|
|
|
3
3
|
const notFilter = require("not-filter");
|
|
4
|
-
const notAppIdentity = require("
|
|
4
|
+
const notAppIdentity = require("../../identity");
|
|
5
5
|
|
|
6
6
|
const FIELDS = [
|
|
7
7
|
["query", `not-filter//_filterQuery`],
|
|
@@ -36,8 +36,8 @@ const FactoryFormListAndCount = ({
|
|
|
36
36
|
/**
|
|
37
37
|
*
|
|
38
38
|
*
|
|
39
|
-
* @param {import('
|
|
40
|
-
* @return {Promise<import('
|
|
39
|
+
* @param {import('../../types').notNodeExpressRequest} req
|
|
40
|
+
* @return {Promise<import('../../types').PreparedData>}
|
|
41
41
|
*/
|
|
42
42
|
async extract(req) {
|
|
43
43
|
const envs = this.extractRequestEnvs(req);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const Form = require("
|
|
2
|
-
const { getGenericDataField } = require("
|
|
1
|
+
const Form = require("../../form/form");
|
|
2
|
+
const { getGenericDataField } = require("../field");
|
|
3
3
|
/**
|
|
4
4
|
* Creates generic crUd form, if data field is not defined in fields/ it creates and registers field in module and sub _data form
|
|
5
5
|
*
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
create: require("./form.create"),
|
|
3
|
+
update: require("./form.update"),
|
|
4
|
+
list: require("./form.list"),
|
|
5
|
+
listAndCount: require("./form.listAndCount"),
|
|
6
|
+
listAll: require("./form.listAll"),
|
|
7
|
+
count: require("./form.count"),
|
|
8
|
+
get: require("./form.get"),
|
|
9
|
+
getByID: require("./form.getByID"),
|
|
10
|
+
getRaw: require("./form.getRaw"),
|
|
11
|
+
delete: require("./form.delete"),
|
|
12
|
+
};
|
package/src/generic/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
module.exports.GenericLogic = require("./logic.js");
|
|
2
2
|
module.exports.GenericRoute = require("./route.js");
|
|
3
|
-
module.exports.GenericGetByIdForm = require("./form.getById.js");
|
|
4
|
-
module.exports.GenericGetByIDForm = require("./form.getByID.js");
|
|
3
|
+
module.exports.GenericGetByIdForm = require("./forms/form.getById.js");
|
|
4
|
+
module.exports.GenericGetByIDForm = require("./forms/form.getByID.js");
|
|
5
5
|
module.exports.GenericDataField = require("./field._data.js");
|
|
6
|
-
module.exports.GenericDataForm = require("./form._data.js");
|
|
7
|
-
module.exports.GenericCreateForm = require("./form.create.js");
|
|
8
|
-
module.exports.GenericUpdateForm = require("./form.update.js");
|
|
9
|
-
module.exports.GenericAuthorizedActionForm = require("./form.authorizedAction.js");
|
|
10
|
-
module.exports.GenericListAndCountForm = require("./form.listAndCount.js");
|
|
11
|
-
module.exports.GenericListForm = require("./form.list.js");
|
|
6
|
+
module.exports.GenericDataForm = require("./forms/form._data.js");
|
|
7
|
+
module.exports.GenericCreateForm = require("./forms/form.create.js");
|
|
8
|
+
module.exports.GenericUpdateForm = require("./forms/form.update.js");
|
|
9
|
+
module.exports.GenericAuthorizedActionForm = require("./forms/form.authorizedAction.js");
|
|
10
|
+
module.exports.GenericListAndCountForm = require("./forms/form.listAndCount.js");
|
|
11
|
+
module.exports.GenericListForm = require("./forms/form.list.js");
|
|
12
12
|
|
|
13
13
|
const FORMS = {};
|
|
14
14
|
|