not-node 5.0.19 → 5.1.0
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/.eslintrc.json +1 -1
- package/bin/not-deploy.js +52 -0
- package/error.format +11 -0
- package/index.js +22 -18
- package/package.json +1 -1
- package/src/app.js +61 -58
- package/src/auth/abstract.js +17 -19
- package/src/auth/const.js +8 -12
- package/src/auth/fields.js +143 -124
- package/src/auth/index.js +14 -14
- package/src/auth/roles.js +64 -63
- package/src/auth/routes.js +89 -54
- package/src/auth/rules.js +63 -63
- package/src/auth/session.js +60 -62
- package/src/bootstrap/form.js +18 -0
- package/src/bootstrap/index.js +11 -0
- package/src/bootstrap/logic.js +50 -0
- package/src/bootstrap/model.js +15 -0
- package/src/bootstrap/route.js +139 -0
- package/src/common.js +86 -79
- package/src/core/fields/ID.js +6 -6
- package/src/core/fields/__closed.js +3 -3
- package/src/core/fields/__latest.js +3 -3
- package/src/core/fields/__version.js +3 -3
- package/src/core/fields/__versions.js +3 -3
- package/src/core/fields/_id.js +6 -6
- package/src/core/fields/active.js +9 -9
- package/src/core/fields/codeName.js +9 -9
- package/src/core/fields/createdAt.js +17 -17
- package/src/core/fields/default.js +9 -9
- package/src/core/fields/description.js +11 -11
- package/src/core/fields/email.js +9 -9
- package/src/core/fields/enabled.js +9 -9
- package/src/core/fields/expiredAt.js +16 -16
- package/src/core/fields/height.js +11 -11
- package/src/core/fields/ip.js +10 -10
- package/src/core/fields/objectId.js +10 -10
- package/src/core/fields/owner.js +13 -13
- package/src/core/fields/ownerModel.js +11 -11
- package/src/core/fields/price.js +11 -11
- package/src/core/fields/requiredObject.js +10 -10
- package/src/core/fields/session.js +10 -10
- package/src/core/fields/size.js +11 -11
- package/src/core/fields/telephone.js +9 -9
- package/src/core/fields/title.js +15 -15
- package/src/core/fields/updatedAt.js +17 -17
- package/src/core/fields/userId.js +11 -12
- package/src/core/fields/uuid.js +11 -11
- package/src/core/fields/validators/email.js +6 -4
- package/src/core/fields/validators/owner.js +6 -4
- package/src/core/fields/width.js +11 -11
- package/src/domain.js +435 -431
- package/src/env.js +23 -23
- package/src/error.js +20 -23
- package/src/exceptions/db.js +23 -0
- package/src/exceptions/http.js +43 -0
- package/src/fields/index.js +139 -121
- package/src/form/fabric.js +19 -24
- package/src/form/form.js +195 -186
- package/src/form/index.js +2 -2
- package/src/generic/index.js +2 -0
- package/src/generic/logic.js +595 -0
- package/src/generic/route.js +76 -0
- package/src/getApp.js +2 -0
- package/src/init/additional.js +7 -7
- package/src/init/app.js +75 -68
- package/src/init/bodyparser.js +14 -14
- package/src/init/compression.js +6 -7
- package/src/init/core.js +12 -12
- package/src/init/cors.js +22 -24
- package/src/init/db/index.js +41 -43
- package/src/init/db/ioredis.js +28 -20
- package/src/init/db/mongoose.js +42 -32
- package/src/init/db/redis.js +59 -48
- package/src/init/env.js +44 -36
- package/src/init/express.js +18 -21
- package/src/init/fileupload.js +8 -10
- package/src/init/http.js +65 -47
- package/src/init/index.js +141 -148
- package/src/init/informer.js +7 -9
- package/src/init/methodoverride.js +4 -6
- package/src/init/middleware.js +23 -26
- package/src/init/modules.js +4 -4
- package/src/init/monitoring.js +8 -8
- package/src/init/rateLimiter.js +53 -45
- package/src/init/routes.js +67 -69
- package/src/init/security.js +37 -33
- package/src/init/sequence.js +111 -107
- package/src/init/sequence.standart.js +54 -56
- package/src/init/sessions/index.js +21 -21
- package/src/init/sessions/mongoose.js +49 -36
- package/src/init/sessions/redis.js +28 -27
- package/src/init/static.js +53 -40
- package/src/init/template.js +17 -17
- package/src/lib.js +230 -200
- package/src/manifest/batchRunner.js +26 -25
- package/src/manifest/initializator/forms.js +24 -24
- package/src/manifest/initializator/index.js +8 -10
- package/src/manifest/initializator/manifests.js +45 -42
- package/src/manifest/initializator/models.js +37 -34
- package/src/manifest/manifest.filter.js +130 -97
- package/src/manifest/manifest.js +103 -77
- package/src/manifest/module.js +350 -360
- package/src/manifest/registrator/fields.js +90 -85
- package/src/manifest/registrator/forms.js +47 -47
- package/src/manifest/registrator/index.js +14 -16
- package/src/manifest/registrator/locales.js +17 -16
- package/src/manifest/registrator/logics.js +66 -64
- package/src/manifest/registrator/models.js +64 -62
- package/src/manifest/registrator/routes.js +171 -132
- package/src/manifest/registrator/routes.ws.js +109 -103
- package/src/manifest/route.js +216 -161
- package/src/model/buildValidator.js +53 -42
- package/src/model/default.js +304 -286
- package/src/model/enrich.js +69 -61
- package/src/model/increment.js +124 -137
- package/src/model/proto.js +179 -148
- package/src/model/routine.js +85 -76
- package/src/model/utils.js +33 -0
- package/src/model/versioning.js +148 -124
- package/src/obsolete.js +12 -8
- package/src/parser.js +29 -22
- package/src/repos.js +29 -31
- package/src/rollup.js +75 -65
- package/src/shell.helpers.js +28 -28
- package/static.js +31 -0
- package/src/manifest/module.models.js +0 -0
- package/src/manifest/module.status.js +0 -0
package/src/env.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
const {objHas} = require(
|
|
1
|
+
const { objHas } = require("./common");
|
|
2
2
|
|
|
3
3
|
const ENVS = {
|
|
4
|
-
|
|
4
|
+
process: process.env.NODE_ENV || "development",
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
module.exports = class notEnv {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Returns application environment variable
|
|
10
|
+
* @param {string} key name of var
|
|
11
|
+
* @return {object|undefined} value or undefined
|
|
12
|
+
*/
|
|
13
|
+
static getEnv(key) {
|
|
14
|
+
if (objHas(ENVS, key)) {
|
|
15
|
+
return ENVS[key];
|
|
16
|
+
} else {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
18
19
|
}
|
|
19
|
-
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Setting application environment variable
|
|
23
|
+
* @param {string} key name of var
|
|
24
|
+
* @param {object} val value
|
|
25
|
+
* @return {notDomain} chainable
|
|
26
|
+
*/
|
|
27
|
+
static setEnv(key, val) {
|
|
28
|
+
ENVS[key] = val;
|
|
29
|
+
return notEnv;
|
|
30
|
+
}
|
|
31
31
|
};
|
package/src/error.js
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
1
|
/** @module not-node/Error */
|
|
2
2
|
|
|
3
|
-
const {objHas} = require(
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
http = require('http');
|
|
3
|
+
const { objHas } = require("./common");
|
|
4
|
+
const util = require("util"),
|
|
5
|
+
http = require("http");
|
|
7
6
|
|
|
8
7
|
function HttpError(status, message) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
Error.apply(this, arguments);
|
|
9
|
+
Error.captureStackTrace(this, HttpError);
|
|
10
|
+
this.status = status;
|
|
11
|
+
this.message = message || http.STATUS_CODES[status] || "Error";
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
util.inherits(HttpError, Error);
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
HttpError.prototype.name = 'HttpError';
|
|
19
|
-
|
|
16
|
+
HttpError.prototype.name = "HttpError";
|
|
20
17
|
|
|
21
18
|
module.exports.Http = HttpError;
|
|
22
19
|
|
|
@@ -28,17 +25,17 @@ module.exports.Http = HttpError;
|
|
|
28
25
|
* @return {object} modified errors
|
|
29
26
|
*/
|
|
30
27
|
|
|
31
|
-
module.exports.addError = function(errors, field, error) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
28
|
+
module.exports.addError = function (errors, field, error) {
|
|
29
|
+
if (!errors) {
|
|
30
|
+
errors = {};
|
|
31
|
+
}
|
|
32
|
+
if (!objHas(errors, field)) {
|
|
33
|
+
errors[field] = [];
|
|
34
|
+
} else {
|
|
35
|
+
if (!Array.isArray(errors[field])) {
|
|
36
|
+
errors[field] = [errors[field]];
|
|
37
|
+
}
|
|
40
38
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return errors;
|
|
39
|
+
errors[field].push(error);
|
|
40
|
+
return errors;
|
|
44
41
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const { notRequestError } = require("not-error");
|
|
2
|
+
|
|
3
|
+
//delete wasnt successful, or error, or count of deleted documents dont match requested
|
|
4
|
+
class DBExceptionDeleteWasNotSuccessful extends notRequestError {
|
|
5
|
+
constructor({ params = {}, cause = null }) {
|
|
6
|
+
super("DB Delete Was Not Successful", { code: 505, ...params }, cause);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
module.exports.DBExceptionDeleteWasNotSuccessful =
|
|
10
|
+
DBExceptionDeleteWasNotSuccessful;
|
|
11
|
+
|
|
12
|
+
//delete wasnt successful, bc document is owned by another user
|
|
13
|
+
class DBExceptionDocumentIsNotOwnerByActiveUser extends notRequestError {
|
|
14
|
+
constructor({ params = {}, cause = null }) {
|
|
15
|
+
super(
|
|
16
|
+
"DB Only Owners Could Delete their documents",
|
|
17
|
+
{ code: 403, ...params },
|
|
18
|
+
cause
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
module.exports.DBExceptionDocumentIsNotOwnerByActiveUser =
|
|
23
|
+
DBExceptionDocumentIsNotOwnerByActiveUser;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
const { notRequestError } = require("not-error");
|
|
2
|
+
|
|
3
|
+
//https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses
|
|
4
|
+
|
|
5
|
+
//form of request is not valid
|
|
6
|
+
class HttpExceptionBadRequest extends notRequestError {
|
|
7
|
+
constructor({ params = {}, cause = null }) {
|
|
8
|
+
super("Bad Request", { code: 400, ...params }, cause);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
module.exports.HttpExceptionBadRequest = HttpExceptionBadRequest;
|
|
12
|
+
|
|
13
|
+
//user is not authenticated
|
|
14
|
+
class HttpExceptionUnauthorized extends notRequestError {
|
|
15
|
+
constructor({ params = {}, cause = null }) {
|
|
16
|
+
super("Unauthorized", { code: 401, ...params }, cause);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
module.exports.HttpExceptionUnauthorized = HttpExceptionUnauthorized;
|
|
20
|
+
|
|
21
|
+
//user is too poor to go there
|
|
22
|
+
class HttpExceptionPaymentRequired extends notRequestError {
|
|
23
|
+
constructor({ params = {}, cause = null }) {
|
|
24
|
+
super("Payment Required", { code: 402, ...params }, cause);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
module.exports.HttpExceptionPaymentRequired = HttpExceptionPaymentRequired;
|
|
28
|
+
|
|
29
|
+
//user identity is known, but he has no right to go there
|
|
30
|
+
class HttpExceptionForbidden extends notRequestError {
|
|
31
|
+
constructor({ params = {}, cause = null }) {
|
|
32
|
+
super("Forbidden", { code: 403, ...params }, cause);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
module.exports.HttpExceptionForbidden = HttpExceptionForbidden;
|
|
36
|
+
|
|
37
|
+
//requested address is not exists
|
|
38
|
+
class HttpExceptionNotFound extends notRequestError {
|
|
39
|
+
constructor({ params = {}, cause = null }) {
|
|
40
|
+
super("Not Found", { code: 404, ...params }, cause);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
module.exports.HttpExceptionNotFound = HttpExceptionNotFound;
|
package/src/fields/index.js
CHANGED
|
@@ -1,22 +1,31 @@
|
|
|
1
|
-
const clone = require(
|
|
2
|
-
const notPath = require(
|
|
3
|
-
const {error} = require(
|
|
4
|
-
const {notError} = require('not-error');
|
|
1
|
+
const clone = require("rfdc")();
|
|
2
|
+
const notPath = require("not-path");
|
|
3
|
+
const { error } = require("not-log")(module, "init//fields");
|
|
5
4
|
|
|
6
|
-
const {
|
|
7
|
-
objHas,
|
|
8
|
-
} = require('../common');
|
|
5
|
+
const { objHas } = require("../common");
|
|
9
6
|
|
|
10
|
-
const DEFAULT_TYPE =
|
|
11
|
-
const DEFAULT_FROM =
|
|
12
|
-
const DEFAULT_TO =
|
|
7
|
+
const DEFAULT_TYPE = "ui";
|
|
8
|
+
const DEFAULT_FROM = ":FIELDS";
|
|
9
|
+
const DEFAULT_TO = ":thisSchema";
|
|
13
10
|
|
|
14
|
-
module.exports.initFileSchemaFromFields = ({
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
11
|
+
module.exports.initFileSchemaFromFields = ({
|
|
12
|
+
app,
|
|
13
|
+
mod,
|
|
14
|
+
type = DEFAULT_TYPE,
|
|
15
|
+
from = DEFAULT_FROM,
|
|
16
|
+
to = DEFAULT_TO,
|
|
17
|
+
moduleName = "",
|
|
18
|
+
}) => {
|
|
19
|
+
const FIELDS = notPath.get(from, mod);
|
|
20
|
+
if (FIELDS && Array.isArray(FIELDS)) {
|
|
21
|
+
const schema = module.exports.createSchemaFromFields(
|
|
22
|
+
app,
|
|
23
|
+
FIELDS,
|
|
24
|
+
type,
|
|
25
|
+
moduleName
|
|
26
|
+
);
|
|
27
|
+
notPath.set(to, mod, schema);
|
|
28
|
+
}
|
|
20
29
|
};
|
|
21
30
|
|
|
22
31
|
/**
|
|
@@ -26,131 +35,140 @@ fields = [
|
|
|
26
35
|
['someID', {}, 'ID'], //copy of standart ID field under name as someID
|
|
27
36
|
]
|
|
28
37
|
**/
|
|
29
|
-
module.exports.createSchemaFromFields = (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
module.exports.createSchemaFromFields = (
|
|
39
|
+
app,
|
|
40
|
+
fields,
|
|
41
|
+
type = "ui",
|
|
42
|
+
moduleName
|
|
43
|
+
) => {
|
|
44
|
+
let schema = {};
|
|
45
|
+
fields.forEach((field) => {
|
|
46
|
+
let [schemaFieldName, schemaFieldValue] =
|
|
47
|
+
module.exports.initSchemaField(app, field, false, type, moduleName);
|
|
48
|
+
schema[schemaFieldName] = schemaFieldValue;
|
|
49
|
+
});
|
|
50
|
+
return schema;
|
|
36
51
|
};
|
|
37
52
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
module.exports.initSchemaField = (
|
|
54
|
+
app,
|
|
55
|
+
field,
|
|
56
|
+
resultOnly = true,
|
|
57
|
+
type = "ui",
|
|
58
|
+
moduleName
|
|
59
|
+
) => {
|
|
60
|
+
//log(field);
|
|
61
|
+
let { srcName, destName, mutation } = parseFieldDescription(field);
|
|
62
|
+
let proto = findFieldPrototype(app, srcName, type);
|
|
63
|
+
if (!proto) {
|
|
64
|
+
error(
|
|
65
|
+
`field ${moduleName}//${destName} prototype ${srcName} of ${type} type is not found`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
let schemaFieldValue = Object.assign({}, clone(proto), mutation);
|
|
69
|
+
if (resultOnly) {
|
|
70
|
+
return schemaFieldValue;
|
|
71
|
+
} else {
|
|
72
|
+
return [destName, schemaFieldValue];
|
|
73
|
+
}
|
|
56
74
|
};
|
|
57
75
|
|
|
58
76
|
/**
|
|
59
|
-
* field form
|
|
60
|
-
* 'destFieldNameSameAsSourceFieldName' - form 1
|
|
61
|
-
* ['destFieldName', {full: true, field: 'content'}] - form 2
|
|
62
|
-
* ['destFieldName', 'srcFieldName'] //field alias, form 3
|
|
63
|
-
* ['destFieldName', {mutation: 'content'}, 'srcFieldName']// - form 4
|
|
64
|
-
**/
|
|
77
|
+
* field form
|
|
78
|
+
* 'destFieldNameSameAsSourceFieldName' - form 1
|
|
79
|
+
* ['destFieldName', {full: true, field: 'content'}] - form 2
|
|
80
|
+
* ['destFieldName', 'srcFieldName'] //field alias, form 3
|
|
81
|
+
* ['destFieldName', {mutation: 'content'}, 'srcFieldName']// - form 4
|
|
82
|
+
**/
|
|
65
83
|
const parseFieldDescription = (field) => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
84
|
+
let srcName,
|
|
85
|
+
destName,
|
|
86
|
+
mutation = {};
|
|
87
|
+
if (Array.isArray(field)) {
|
|
88
|
+
destName = srcName = field[0];
|
|
89
|
+
if (field.length === 2) {
|
|
90
|
+
if (typeof field[1] === "string") {
|
|
91
|
+
srcName = field[1]; //form 3
|
|
92
|
+
} else {
|
|
93
|
+
mutation = field[1]; //form 2
|
|
94
|
+
}
|
|
95
|
+
} else if (field.length === 3) {
|
|
96
|
+
//form 4
|
|
97
|
+
mutation = field[1];
|
|
98
|
+
srcName = field[2];
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
destName = srcName = field; //form 1
|
|
80
102
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
destName,
|
|
87
|
-
mutation
|
|
88
|
-
};
|
|
103
|
+
return {
|
|
104
|
+
srcName,
|
|
105
|
+
destName,
|
|
106
|
+
mutation,
|
|
107
|
+
};
|
|
89
108
|
};
|
|
90
109
|
|
|
91
110
|
const findFieldPrototype = (app, name, type) => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
111
|
+
const fieldPrototype = app.getField(name);
|
|
112
|
+
if (fieldPrototype && objHas(fieldPrototype, type)) {
|
|
113
|
+
return fieldPrototype[type];
|
|
114
|
+
} else {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
98
117
|
};
|
|
99
118
|
|
|
100
119
|
/**
|
|
101
|
-
* Creates fields UI representation schema from list of fields in DB model
|
|
102
|
-
* and library of fields
|
|
103
|
-
* @param {object} app notApplication instance
|
|
104
|
-
* @param {object} schema model db schema
|
|
105
|
-
* @param {Array<string|Array>} rawMutationsList fields mutations, for little tuning
|
|
106
|
-
* @param {Array<string>} privateFields fields to omit from result
|
|
107
|
-
* @param {string} moduleName for detailed reports on issues, in which module and what field is faulty
|
|
108
|
-
* @returns {object} resulting UI rendering schema for fields
|
|
109
|
-
**/
|
|
120
|
+
* Creates fields UI representation schema from list of fields in DB model
|
|
121
|
+
* and library of fields
|
|
122
|
+
* @param {object} app notApplication instance
|
|
123
|
+
* @param {object} schema model db schema
|
|
124
|
+
* @param {Array<string|Array>} rawMutationsList fields mutations, for little tuning
|
|
125
|
+
* @param {Array<string>} privateFields fields to omit from result
|
|
126
|
+
* @param {string} moduleName for detailed reports on issues, in which module and what field is faulty
|
|
127
|
+
* @returns {object} resulting UI rendering schema for fields
|
|
128
|
+
**/
|
|
110
129
|
|
|
111
130
|
module.exports.initManifestFields = (
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
131
|
+
app, //notApplication
|
|
132
|
+
schema, //schema of model
|
|
133
|
+
rawMutationsList = [], //fields mutations
|
|
134
|
+
privateFields = [], //fields to omit
|
|
135
|
+
moduleName //module name for reporting
|
|
117
136
|
) => {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return
|
|
139
|
-
}
|
|
137
|
+
let //shallow copy of array
|
|
138
|
+
mutationsList = [...rawMutationsList],
|
|
139
|
+
list = [];
|
|
140
|
+
if (schema && Object.keys(schema).length > 0) {
|
|
141
|
+
let rawKeys = Object.keys(schema);
|
|
142
|
+
rawKeys
|
|
143
|
+
.filter((key) => !privateFields.includes(key))
|
|
144
|
+
.forEach((key) => {
|
|
145
|
+
let mutation = getMutationForField(key, mutationsList);
|
|
146
|
+
if (mutation) {
|
|
147
|
+
list.push(mutation);
|
|
148
|
+
mutationsList.splice(mutationsList.indexOf(mutation), 1);
|
|
149
|
+
} else {
|
|
150
|
+
list.push(key);
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
list.push(...mutationsList);
|
|
154
|
+
} else {
|
|
155
|
+
list = mutationsList;
|
|
156
|
+
}
|
|
157
|
+
return module.exports.createSchemaFromFields(app, list, "ui", moduleName);
|
|
140
158
|
};
|
|
141
159
|
|
|
142
160
|
/**
|
|
143
|
-
* Returns mutation tuple for a field or false
|
|
144
|
-
* @param {string} name field name
|
|
145
|
-
* @param {Array} list fields description lists
|
|
146
|
-
* @return {boolean|item}
|
|
147
|
-
*/
|
|
161
|
+
* Returns mutation tuple for a field or false
|
|
162
|
+
* @param {string} name field name
|
|
163
|
+
* @param {Array} list fields description lists
|
|
164
|
+
* @return {boolean|item}
|
|
165
|
+
*/
|
|
148
166
|
function getMutationForField(name, list) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
167
|
+
for (let item of list) {
|
|
168
|
+
if (Array.isArray(item) && item[0] === name) {
|
|
169
|
+
return item;
|
|
170
|
+
}
|
|
152
171
|
}
|
|
153
|
-
|
|
154
|
-
return false;
|
|
172
|
+
return false;
|
|
155
173
|
}
|
|
156
174
|
module.exports.getMutationForField = getMutationForField;
|
package/src/form/fabric.js
CHANGED
|
@@ -1,28 +1,23 @@
|
|
|
1
|
-
const Form = require(
|
|
1
|
+
const Form = require("./form");
|
|
2
2
|
|
|
3
3
|
module.exports = class FormFabric {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
super({
|
|
13
|
-
FIELDS,
|
|
14
|
-
FORM_NAME: `${MODULE_NAME}:${FORM_NAME}`
|
|
15
|
-
});
|
|
16
|
-
}
|
|
4
|
+
static create({ FIELDS, MODULE_NAME, FORM_NAME, extractor }) {
|
|
5
|
+
return class extends Form {
|
|
6
|
+
constructor() {
|
|
7
|
+
super({
|
|
8
|
+
FIELDS,
|
|
9
|
+
FORM_NAME: `${MODULE_NAME}:${FORM_NAME}`,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
17
12
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Extracts data
|
|
15
|
+
* @param {ExpressRequest} req expressjs request object
|
|
16
|
+
* @return {Object} forma data
|
|
17
|
+
**/
|
|
18
|
+
extract(req) {
|
|
19
|
+
return extractor(req);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
}
|
|
28
23
|
};
|