not-node 6.3.88 → 6.3.89
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
package/src/form/form.js
CHANGED
|
@@ -87,6 +87,7 @@ class Form {
|
|
|
87
87
|
* @param {string} options.FORM_NAME
|
|
88
88
|
* @param {string} options.MODEL_NAME
|
|
89
89
|
* @param {string} options.MODULE_NAME
|
|
90
|
+
* @param {string} options.actionName
|
|
90
91
|
* @param {import('../app.js')} options.app
|
|
91
92
|
* @param {Object.<string, Function>} options.EXTRACTORS
|
|
92
93
|
* @param {Object.<string, Function>} options.TRANSFORMERS
|
|
@@ -100,6 +101,7 @@ class Form {
|
|
|
100
101
|
FORM_NAME,
|
|
101
102
|
MODEL_NAME,
|
|
102
103
|
MODULE_NAME,
|
|
104
|
+
actionName,
|
|
103
105
|
app,
|
|
104
106
|
EXTRACTORS = {},
|
|
105
107
|
ENV_EXTRACTORS = {},
|
|
@@ -108,7 +110,7 @@ class Form {
|
|
|
108
110
|
AFTER_EXTRACT_TRANSFORMERS = [],
|
|
109
111
|
rate,
|
|
110
112
|
}) {
|
|
111
|
-
this.#FORM_NAME = FORM_NAME;
|
|
113
|
+
this.#FORM_NAME = FORM_NAME ?? this.createName(MODULE_NAME, MODEL_NAME, actionName);
|
|
112
114
|
this.#MODEL_NAME = MODEL_NAME;
|
|
113
115
|
this.#MODULE_NAME = MODULE_NAME;
|
|
114
116
|
this.#PROTO_FIELDS = FIELDS;
|
|
@@ -130,10 +132,10 @@ class Form {
|
|
|
130
132
|
* Creates model name string used in logging
|
|
131
133
|
* @param {string} MODULE_NAME
|
|
132
134
|
* @param {string|undefined} MODEL_NAME
|
|
133
|
-
* @param {string} actionName
|
|
135
|
+
* @param {string} actionName = 'data'
|
|
134
136
|
* @returns {string}
|
|
135
137
|
*/
|
|
136
|
-
static createName(MODULE_NAME, MODEL_NAME, actionName) {
|
|
138
|
+
static createName(MODULE_NAME, MODEL_NAME, actionName = 'data') {
|
|
137
139
|
if (MODEL_NAME) {
|
|
138
140
|
return `${MODULE_NAME}:${MODEL_NAME}:${firstLetterToUpper(
|
|
139
141
|
actionName
|
|
@@ -660,6 +662,9 @@ class Form {
|
|
|
660
662
|
if (typeof schemaField === "undefined" || schemaField === null) {
|
|
661
663
|
return [];
|
|
662
664
|
}
|
|
665
|
+
if(schemaField.transformers && Array.isArray(schemaField.transformers)){
|
|
666
|
+
return schemaField.transformers;
|
|
667
|
+
}
|
|
663
668
|
switch (schemaField.type) {
|
|
664
669
|
case String:
|
|
665
670
|
case Schema.Types.String:
|
package/src/types.js
CHANGED
|
@@ -159,13 +159,14 @@
|
|
|
159
159
|
|
|
160
160
|
/**
|
|
161
161
|
* @typedef {object} notFieldModel
|
|
162
|
-
* @property {notFieldModelType}
|
|
163
|
-
* @property {
|
|
164
|
-
* @property {
|
|
165
|
-
* @property {boolean}
|
|
166
|
-
* @property {
|
|
167
|
-
* @property {
|
|
168
|
-
* @property {string}
|
|
162
|
+
* @property {notFieldModelType} type
|
|
163
|
+
* @property {Array<string>} [transformers] list of transformers names to pipe down aka ['xss', 'trim', 'removeDots', 'maxLength1000'], used in Form as default transforming pipeline on data extraction stage
|
|
164
|
+
* @property {any} default default value
|
|
165
|
+
* @property {boolean} [sortable] if field is sortable
|
|
166
|
+
* @property {boolean} [required] if required to be defined
|
|
167
|
+
* @property {notFieldSafety} [safe] safety requirements
|
|
168
|
+
* @property {string} [ref] mongoose model name, if type is ObjectId
|
|
169
|
+
* @property {string} [refPath] path to field with name of mongoose model this field value of ObjectId type reference to
|
|
169
170
|
*/
|
|
170
171
|
|
|
171
172
|
/**
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
const { MODULE_NAME } = require("../const");
|
|
2
|
+
const MODEL_NAME = '<%- ModelName %>';
|
|
3
|
+
const actionName = '_data';
|
|
2
4
|
|
|
3
5
|
const Form = require("not-node").Form;
|
|
4
6
|
|
|
5
7
|
const FIELDS = [<% if (fields && Array.isArray(fields)) { %><% for(let field of fields){ %>["<%- field[0] %>", "<%- field[1] %>"],
|
|
6
8
|
<% } %><% } %>];
|
|
7
9
|
|
|
8
|
-
const FORM_NAME = Form.createName();
|
|
10
|
+
const FORM_NAME = Form.createName(MODULE_NAME, MODEL_NAME, actionName);
|
|
9
11
|
|
|
10
12
|
//const validateTitle = require("./validators/title.js");
|
|
11
13
|
class _<%- ModelName %>Form extends Form {
|
|
12
14
|
constructor({ app }) {
|
|
13
|
-
super({
|
|
15
|
+
super({MODULE_NAME,MODEL_NAME,actionName, FIELDS, FORM_NAME, app });
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
//could do something with data, before validation
|