not-node 5.0.7 → 5.0.10

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "not-node",
3
- "version": "5.0.7",
3
+ "version": "5.0.10",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/auth/rules.js CHANGED
@@ -6,11 +6,11 @@ function ruleHasRootDirective(rule){
6
6
  }
7
7
 
8
8
 
9
- function compareWithRoot(rule, admin){
9
+ function compareWithRoot(rule, root){
10
10
  if (Object.prototype.hasOwnProperty.call(rule, 'admin')) {
11
- return rule.admin && admin;
11
+ return rule.admin && root;
12
12
  } else {
13
- return rule.root && admin;
13
+ return rule.root && root;
14
14
  }
15
15
  }
16
16
 
@@ -51,18 +51,16 @@ function compareAuthStatus(rule, auth){
51
51
 
52
52
  /**
53
53
  * Check rule against presented credentials
54
- * @param {object} rule action rule
55
- * {
56
- * auth - if user should be authenticated
57
- * role - if user shoud have some role
58
- * admin - if user should be super user
59
- * }
60
- * @param {Boolean} auth user state of auth
61
- * @param {String|Array} role user state of role
62
- * @param {Boolean} admin user state of admin
63
- * @return {boolean} pass or not
54
+ * @param {object} rule action rule
55
+ * @param {boolean} rule.auth if user should be authenticated
56
+ * @param {Array<String>} rule.role if user shoud have some role
57
+ * @param {boolean} rule.root if user should be super user
58
+ * @param {Boolean} auth user state of auth
59
+ * @param {String|Array} role user state of role
60
+ * @param {Boolean} root user state of root
61
+ * @return {boolean} pass or not
64
62
  */
65
- function checkCredentials(rule, auth, role, admin) {
63
+ function checkCredentials(rule, auth, role, root) {
66
64
  //no rule - no access
67
65
  if (typeof rule === 'undefined' || rule === null) {
68
66
  return false;
@@ -72,7 +70,7 @@ function checkCredentials(rule, auth, role, admin) {
72
70
  //start comparing from top tier flags
73
71
  //if we have root/admin(obsolete) field field in rule compare only it
74
72
  if (ruleHasRootDirective(rule)) {
75
- return compareWithRoot(rule, admin);
73
+ return compareWithRoot(rule, root);
76
74
  } else {
77
75
  //if we have roles in rule, then using role based aproach
78
76
  if (Object.prototype.hasOwnProperty.call(rule, 'role')) {
@@ -1,4 +1,7 @@
1
1
  {
2
+ "booleans_false": "True",
3
+ "booleans_true": "False",
4
+ "form_validation_error": "Form validation error",
2
5
  "field_active_label": "Active",
3
6
  "field_codeName_label": "Code name",
4
7
  "field_codeName_placeholder": "Code name",
@@ -1,26 +1,29 @@
1
1
  {
2
- "field_active_label": "Active",
3
- "field_codeName_label": "Code name",
4
- "field_codeName_placeholder": "Code name",
5
- "field_createdAt_label": "Created At",
6
- "field_createdAt_placeholder": "Date and time of creation",
7
- "field_default_label": "Default",
8
-
9
- "field_title_label": "Title",
10
- "field_title_placeholder": "Title of item",
11
- "field_description_label": "Description",
12
- "field_description_placeholder": "Short description of item",
13
- "field_enabled_label": "Enabled",
14
- "field_expiredAt_label": "Expired At",
15
- "field_expiredAt_placeholder": "Date and time of expiration",
16
- "field_updatedAt_label": "Updated At",
17
- "field_updatedAt_placeholder": "Date and time of last update",
18
- "field_height_label": "Height",
19
- "field_height_placeholder": "Height",
20
- "field_width_label": "Width",
21
- "field_width_placeholder": "Width",
22
- "field_size_label": "Size",
23
- "field_size_placeholder": "Size",
2
+ "booleans_false": "Да",
3
+ "booleans_true": "Нет",
4
+ "form_validation_error": "Форма заполнена с ошибками",
5
+ "field_active_label": "Активна",
6
+ "field_codeName_label": "Псевдоним",
7
+ "field_codeName_placeholder": "some_spaceless_pseudonim",
8
+ "field_createdAt_label": "Создано",
9
+ "field_createdAt_placeholder": "Дата и время создания",
10
+ "field_default_label": "По умолчанию",
11
+
12
+ "field_title_label": "Название",
13
+ "field_title_placeholder": "Название объекта",
14
+ "field_description_label": "Описание",
15
+ "field_description_placeholder": "Короткое описание",
16
+ "field_enabled_label": "Включено",
17
+ "field_expiredAt_label": "Действительно до",
18
+ "field_expiredAt_placeholder": "Дата и время истечения срока действия",
19
+ "field_updatedAt_label": "Обновлено",
20
+ "field_updatedAt_placeholder": "Дата и время обновления",
21
+ "field_height_label": "Высота",
22
+ "field_height_placeholder": "Высота",
23
+ "field_width_label": "Ширина",
24
+ "field_width_placeholder": "Ширина",
25
+ "field_size_label": "Размер",
26
+ "field_size_placeholder": "Размер",
24
27
 
25
28
  "field_email_label": "Email",
26
29
  "field_email_placeholder": "email@server.ru",
@@ -32,15 +35,15 @@
32
35
  "field_ID_placeholder": "ID",
33
36
 
34
37
  "field_IP_label": "IP",
35
- "field_IP_placeholder": "IP",
38
+ "field_IP_placeholder": "ip адрес",
36
39
 
37
- "field_price_label": "Price",
38
- "field_price_placeholder": "Price",
40
+ "field_price_label": "Цена",
41
+ "field_price_placeholder": "Цена",
39
42
 
40
- "field_session_label": "Session",
41
- "field_session_placeholder": "Session",
43
+ "field_session_label": "Сессия",
44
+ "field_session_placeholder": "Сессия",
42
45
  "field_userId_label": "UserId",
43
- "field_userId_placeholder": "UserId",
46
+ "field_userId_placeholder": "",
44
47
 
45
48
  "field_UUID_label": "UUID",
46
49
  "field_UUID_placeholder": "UUID"
package/src/form/form.js CHANGED
@@ -4,10 +4,6 @@ const {
4
4
  createSchemaFromFields
5
5
  } = require('../fields');
6
6
 
7
- const {
8
- byFieldsValidators
9
- } = require('../model/enrich');
10
-
11
7
  const {objHas} = require('../common');
12
8
 
13
9
  const ValidationBuilder = require('not-validation').Builder;
@@ -154,9 +150,7 @@ class Form {
154
150
  }
155
151
 
156
152
  #createModelSchema(app){
157
- return byFieldsValidators(
158
- createSchemaFromFields(app, this.#PROTO_FIELDS, 'model', this.#FORM_NAME)
159
- );
153
+ return createSchemaFromFields(app, this.#PROTO_FIELDS, 'model', this.#FORM_NAME);
160
154
  }
161
155
 
162
156
 
@@ -173,7 +167,6 @@ class Form {
173
167
  this.#SCHEMA = ValidationBuilder(this.#SCHEMA, this.getValidatorEnvGetter());
174
168
  }
175
169
 
176
-
177
170
  /**
178
171
  * Validates form data or throws
179
172
  * @param {Object} data form data
@@ -7,7 +7,7 @@ function extractValidationEnvGetter(options){
7
7
  return options.getValidationEnv;
8
8
  }else{
9
9
  //should return at least empty object
10
- return ()=>{return {};};
10
+ return ()=>{return {validate};};
11
11
  }
12
12
  }
13
13
 
@@ -62,6 +62,19 @@ function secureUpdate(thisModel, which, cmd, opts){
62
62
 
63
63
  module.exports.secureUpdate = secureUpdate;
64
64
 
65
+ function updateResponseSuccess(res){
66
+ if(res){
67
+ const responseList = Object.keys(res);
68
+ if(responseList.includes('ok')){
69
+ return (res.ok === 1 && res.n === 1);
70
+ }else{
71
+ return (res.matchedCount === 1 && res.modifiedCount === 1);
72
+ }
73
+ }else{
74
+ return false;
75
+ }
76
+ }
77
+
65
78
  /**
66
79
  * Generate new ID for current model and filterFields
67
80
  **/
@@ -99,8 +112,8 @@ function newGetNext() {
99
112
  new: true,
100
113
  upsert: true
101
114
  };
102
- let res = await secureUpdate(thisModel, which, cmd, opts);
103
- if(res.ok === 1 && res.n === 1){
115
+ const res = await secureUpdate(thisModel, which, cmd, opts);
116
+ if(updateResponseSuccess(res)){
104
117
  const doc = await thisModel.findOne({id});
105
118
  return doc.seq;
106
119
  }else{
@@ -133,7 +146,7 @@ function newRebase(){
133
146
  };
134
147
  //updating
135
148
  let res = await secureUpdate(thisModel, which, cmd, opts);
136
- if(res.ok === 1 && res.n === 1){
149
+ if(updateResponseSuccess(res)){
137
150
  return ID;
138
151
  }else{
139
152
  throw new Error('ID generator rebase failed');
@@ -1,193 +0,0 @@
1
- const clone = require('rfdc')();
2
- const fs = require('fs');
3
- const path = require('path');
4
- const {objHas, tryFile} = require('../common');
5
-
6
- const DEFAULT_FIELD_REGISTRATION_RULES = {
7
- overwrite: false,
8
- compose: true
9
- };
10
-
11
- const FIELDS = {};
12
-
13
- module.exports.importFromDir = (srcDir, {overwrite = false, compose = true} = DEFAULT_FIELD_REGISTRATION_RULES)=>{
14
- fs.readdirSync(srcDir).forEach((file) => {
15
- let fromPath = path.join(srcDir, file);
16
- if (!tryFile(fromPath)) { return; }
17
- const parts = path.parse(fromPath);
18
- registerField(parts.name, require(fromPath), {overwrite, compose});
19
- });
20
- };
21
-
22
-
23
- const registerField = module.exports.registerField = (name, value, {overwrite = false, compose = true} = DEFAULT_FIELD_REGISTRATION_RULES)=>{
24
- if(objHas(FIELDS, name)){
25
- if(overwrite){
26
- FIELDS[name] = value;
27
- }else if(compose){
28
- Object.assign(FIELDS[name], value);
29
- }
30
- }else{
31
- FIELDS[name] = value;
32
- }
33
- };
34
-
35
-
36
- module.exports.registerFields = (fields, {overwrite = false, compose = true})=>{
37
- for(let t in fields){
38
- module.exports.registerField(t, fields[t], {overwrite, compose});
39
- }
40
- };
41
-
42
- /**
43
- list = [
44
- 'title', //for standart only name
45
- ['titleNonStandart', {component: 'UITextforBlind'}] //arrays of [name, mutation]
46
- ['someID', {}, 'ID'], //copy of standart ID field under name as someID
47
- ]
48
- */
49
- module.exports.initFields = (list, type = 'ui') => {
50
- let fields = {};
51
- list.forEach((field) => {
52
- let res = module.exports.initField(field, false, type);
53
- fields[res[0]] = res[1];
54
- });
55
- return fields;
56
- };
57
-
58
-
59
- /**
60
- * Retrieves field information
61
- * there are few signatures of this function
62
- * (field:string, resultOnly:boolean = true, type:string = 'ui')=> Object | [string, Object]
63
- * (field:Array<string, Object>, resultOnly:boolean = true, type:string = 'ui')=> Object | [string, Object]
64
- * @param {(string|Array)} field field to retrieve from store and init
65
- field: string - just name of the field
66
- field: Array - [destinationField:string, mutation: Object, sourceField:string]
67
- field: Array - [sourceField:string, mutation: Object]
68
- sourceField - standart field to extend
69
- mutation - to extend by
70
- destinationField - name of resulting field,
71
- if no dest then src will be used
72
- * @param {boolean} resultOnly return only result, if false then returns [name, value]
73
- * @param {string} type type of field information
74
- **/
75
- module.exports.initField = (field, resultOnly = true, type = 'ui') => {
76
- let srcName, destName, mutation = {};
77
- if (Array.isArray(field)) {
78
- destName = srcName = field[0];
79
- mutation = field[1];
80
- if (field.length === 3) {
81
- srcName = field[2];
82
- }
83
- } else {
84
- destName = srcName = field;
85
- }
86
- let proto = findFieldDescription(srcName, type);
87
- let result = Object.assign({}, clone(proto), mutation);
88
- if (resultOnly) {
89
- return result;
90
- } else {
91
- return [destName, result];
92
- }
93
- };
94
-
95
- function findFieldDescription(name, type){
96
- return (objHas(FIELDS, name) && objHas(FIELDS[name], type)) ? FIELDS[name][type]:{};
97
- }
98
-
99
-
100
-
101
- /**
102
- * Returns mutation tuple for a field or false
103
- * @param {string} name field name
104
- * @param {Array} list fields description lists
105
- * @return {boolean|item}
106
- */
107
- function getMutationForField(name, list) {
108
- for(let item of list){
109
- if (Array.isArray(item) && item[0] === name) {
110
- return item;
111
- }
112
- }
113
- return false;
114
- }
115
- module.exports.getMutationForField = getMutationForField;
116
-
117
- /**
118
- * Takes in mongoose model schema, scans for fields names and creates list of
119
- * field's names to initialize from LIB, if in supplied rawMutationsList, exists
120
- * mutation for a field in list, field name in list will be replaced by a
121
- * mutation description
122
- * @param {Object} schema mongoose model schema
123
- * @param {Array} rawMutationsList list of mutations [src, mutation]/[dst,mutation,src]
124
- * @returns {Object} initialized ui descriptions of fields for schema
125
- **/
126
- module.exports.fromSchema = (schema, rawMutationsList = []) => {
127
- let
128
- //shallow copy of array
129
- mutationsList = [...rawMutationsList],
130
- list = [];
131
- if (schema && Object.keys(schema).length > 0) {
132
- let rawKeys = Object.keys(schema);
133
- rawKeys.forEach((key) => {
134
- let mutation = getMutationForField(key, mutationsList);
135
- if (mutation) {
136
- list.push(mutation);
137
- mutationsList.splice(mutationsList.indexOf(mutation), 1);
138
- } else {
139
- list.push(key);
140
- }
141
- });
142
- list.push(...mutationsList);
143
- return module.exports.initFields(list);
144
- }else{
145
- return {};
146
- }
147
- };
148
-
149
- module.exports.LIB = FIELDS;
150
-
151
-
152
- module.exports.initFieldsFromApp = (list, type = 'ui', app) => {
153
- let fields = {};
154
- list.forEach((field) => {
155
- let res = module.exports.initFieldFromApp(field, false, type, app);
156
- fields[res[0]] = res[1];
157
- });
158
- return fields;
159
- };
160
-
161
-
162
- module.exports.initFieldFromApp = (field, resultOnly = true, type = 'ui', app) => {
163
- let srcName, destName, mutation = {};
164
- if (Array.isArray(field)) {
165
- destName = srcName = field[0];
166
- mutation = field[1];
167
- if (field.length === 3) {
168
- srcName = field[2];
169
- }
170
- } else {
171
- destName = srcName = field;
172
- }
173
- let proto = findFieldDescriptionFromApp(srcName, type, app);
174
- if(proto){
175
- let result = Object.assign({}, clone(proto), mutation);
176
- if (resultOnly) {
177
- return result;
178
- } else {
179
- return [destName, result];
180
- }
181
- }else{
182
- throw new Error(`Field (${srcName}) definition is not found`);
183
- }
184
- };
185
-
186
- function findFieldDescriptionFromApp(name, type, app){
187
- const field = app.getField(name);
188
- if(field && objHas(field, type)){
189
- return field[type];
190
- }else{
191
- return null;
192
- }
193
- }
@@ -1,7 +0,0 @@
1
- module.exports = class InitFields{
2
- async run({master/*, config*/}){
3
- //compress output
4
- const compression = require('compression');
5
- master.getServer().use(compression());
6
- }
7
- };
File without changes
File without changes
File without changes