not-node 6.5.10 → 6.5.12

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": "6.5.10",
3
+ "version": "6.5.12",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -54,6 +54,7 @@ module.exports = (form, req) => {
54
54
  Object.values(ACTION_DATA_TYPES).forEach((dataType) => {
55
55
  if (
56
56
  routeActionDataTypes.includes(dataType) &&
57
+ // @ts-ignore
57
58
  Object.hasOwn(extractors, dataType)
58
59
  ) {
59
60
  extractors[dataType](result, req, thisSchema, formOptions);
@@ -21,8 +21,28 @@ const extraActionsBuilder = (
21
21
  const POST_FIX_RECORD_ID = "/:record[_id]";
22
22
  const POST_FIX_ACTION_NAME = "/:actionName";
23
23
 
24
- module.exports = (MODULE_NAME, modelName, FIELDS = [], actions = {}) => {
25
- return {
24
+ const DEFAULT_LOCALES_STRINGS = ["title", "description"];
25
+
26
+ const getFormActionLocaleString = (
27
+ strName,
28
+ MODULE_NAME,
29
+ modelName,
30
+ actionName,
31
+ commonFormTitles = false
32
+ ) => {
33
+ return commonFormTitles
34
+ ? `not-node:crud_${actionName}_action_form_${strName}`
35
+ : `${MODULE_NAME}:${modelName}_form_${actionName}_${strName}`;
36
+ };
37
+
38
+ module.exports = (
39
+ MODULE_NAME,
40
+ modelName,
41
+ FIELDS = [],
42
+ actions = {},
43
+ options = {}
44
+ ) => {
45
+ const resultManifest = {
26
46
  model: modelName,
27
47
  url: "/api/:modelName",
28
48
  fields: FIELDS,
@@ -37,7 +57,6 @@ module.exports = (MODULE_NAME, modelName, FIELDS = [], actions = {}) => {
37
57
  root: true,
38
58
  },
39
59
  ],
40
- title: `${MODULE_NAME}:${modelName}_form_create_title`,
41
60
  },
42
61
  update: {
43
62
  method: "POST",
@@ -53,7 +72,6 @@ module.exports = (MODULE_NAME, modelName, FIELDS = [], actions = {}) => {
53
72
  root: true,
54
73
  },
55
74
  ],
56
- title: `${MODULE_NAME}:${modelName}_form_update_title`,
57
75
  },
58
76
  list: {
59
77
  method: "GET",
@@ -108,7 +126,6 @@ module.exports = (MODULE_NAME, modelName, FIELDS = [], actions = {}) => {
108
126
  root: true,
109
127
  },
110
128
  ],
111
- title: `${MODULE_NAME}:${modelName}_form_details_title`,
112
129
  },
113
130
  getByID: {
114
131
  method: "GET",
@@ -146,4 +163,22 @@ module.exports = (MODULE_NAME, modelName, FIELDS = [], actions = {}) => {
146
163
  ...extraActionsBuilder(MODULE_NAME, modelName, FIELDS, actions),
147
164
  },
148
165
  };
166
+
167
+ Object.keys(resultManifest.actions).forEach((actionName) => {
168
+ const actionData = resultManifest.actions[actionName];
169
+ const lst = options?.localesStrings ?? DEFAULT_LOCALES_STRINGS;
170
+ lst.forEach((strName) => {
171
+ if (!Object.hasOwn(actionData, strName)) {
172
+ actionData[strName] = getFormActionLocaleString(
173
+ strName,
174
+ MODULE_NAME,
175
+ modelName,
176
+ actionName,
177
+ options?.commonFormTitles
178
+ );
179
+ }
180
+ });
181
+ });
182
+
183
+ return resultManifest;
149
184
  };
@@ -283,6 +283,14 @@ function listAllAndPopulate(populate) {
283
283
  return query.exec();
284
284
  }
285
285
 
286
+ const getPageNumber = (skip, size) => {
287
+ if (skip === 0) {
288
+ return 0;
289
+ } else {
290
+ return Math.floor(skip / size); //
291
+ }
292
+ };
293
+
286
294
  /**
287
295
  * List record in collection and populates, with count of total founded records
288
296
  * By default sorts by _id in DESC
@@ -305,11 +313,12 @@ async function listAndCount(skip, size, sorter, filter, search, populate = []) {
305
313
  ),
306
314
  countQuery = this.countWithFilter(search || filter);
307
315
  const [list, count] = await Promise.all([listQuery, countQuery]);
316
+
308
317
  return {
309
318
  list,
310
319
  skip,
311
320
  count,
312
- page: Math.floor(skip / size) + (skip % size === 0 ? 1 : 0),
321
+ page: getPageNumber(skip, size),
313
322
  pages: Math.ceil(count / size),
314
323
  };
315
324
  }
package/src/types.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @typedef {object} notAppResponse
3
- * @property {string} status ok or error
3
+ * @property {string} status 'ok' or 'error'
4
4
  * @property {string} message
5
5
  * @property {Array<string>|Object<string, Array<string>>} [errors]
6
6
  * @property {object} [result]
@@ -907,7 +907,7 @@ module.exports = ({
907
907
  expect(res.list).to.be.deep.equal([1, 2, 3, 4]);
908
908
  expect(res.count).to.be.equal(24);
909
909
  expect(res.skip).to.be.equal(skip);
910
- expect(res.page).to.be.equal(2);
910
+ expect(res.page).to.be.equal(1);
911
911
  expect(res.pages).to.be.equal(2);
912
912
  });
913
913
  });
package/.eslintrc.json DELETED
@@ -1,36 +0,0 @@
1
- {
2
- "parserOptions": {
3
- "requireConfigFile": false,
4
- "sourceType": "module",
5
- "allowImportExportEverywhere": false,
6
- "ecmaFeatures": {
7
- "globalReturn": false
8
- },
9
- "ecmaVersion": "latest"
10
- },
11
- "env": {
12
- "es6": true,
13
- "node": true,
14
- "mongo": true,
15
- "mocha": true
16
- },
17
- "extends": [
18
- "eslint:recommended",
19
- "plugin:node/recommended",
20
- "plugin:sonarjs/recommended"
21
- ],
22
- "rules": {
23
- "node/exports-style": ["error", "module.exports"],
24
- "node/file-extension-in-import": ["error", "always"],
25
- "node/prefer-global/buffer": ["error", "always"],
26
- "node/prefer-global/console": ["error", "always"],
27
- "node/prefer-global/process": ["error", "always"],
28
- "node/prefer-global/url-search-params": ["error", "always"],
29
- "node/prefer-global/url": ["error", "always"],
30
- "node/no-unpublished-require": "warn",
31
- "indent": ["error", 4, { "SwitchCase": 1 }],
32
- "linebreak-style": ["error", "unix"],
33
- "semi": ["error", "always"],
34
- "no-useless-escape": [0]
35
- }
36
- }