not-node 5.1.36 → 5.1.39

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.1.36",
3
+ "version": "5.1.39",
4
4
  "description": "node complimentary part for client side notFramework.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,8 +1,14 @@
1
1
  const getApp = require("../getApp.js"),
2
+ Form = require("../form").Form,
2
3
  HttpExceptions = require("../exceptions/http"),
3
4
  configInit = require("not-config"),
4
5
  { sayForModule } = require("not-locale"),
5
- { objHas, isFunc, executeFunctionAsAsync } = require("../common"),
6
+ {
7
+ objHas,
8
+ isFunc,
9
+ executeFunctionAsAsync,
10
+ firstLetterToUpper,
11
+ } = require("../common"),
6
12
  LogInit = require("not-log");
7
13
 
8
14
  module.exports = ({
@@ -79,6 +85,23 @@ module.exports = ({
79
85
  }
80
86
  };
81
87
 
88
+ const createDefaultForm = function ({ actionName }) {
89
+ const FIELDS = [
90
+ ["activeUser", "not-node//requiredObject"],
91
+ ["data", `${MODULE_NAME}//_data`],
92
+ ["ip", "not-node//ip"],
93
+ ];
94
+ const FORM_NAME = `${MODULE_NAME}:${firstLetterToUpper(
95
+ actionName
96
+ )}Form`;
97
+ const cls = class extends Form {
98
+ constructor({ app }) {
99
+ super({ FIELDS, FORM_NAME, app, MODULE_NAME });
100
+ }
101
+ };
102
+ return new cls({ app: getApp() });
103
+ };
104
+
82
105
  const getForm = (actionName) => {
83
106
  const form = getApp().getForm(
84
107
  [MODULE_NAME, `${MODEL_NAME}.${actionName}`].join("//")
@@ -86,7 +109,11 @@ module.exports = ({
86
109
  if (form) {
87
110
  return form;
88
111
  }
89
- return getApp().getForm([MODULE_NAME, actionName].join("//"));
112
+ const form2 = getApp().getForm([MODULE_NAME, actionName].join("//"));
113
+ if (form2) {
114
+ return form2;
115
+ }
116
+ return createDefaultForm({ actionName, MODULE_NAME });
90
117
  };
91
118
 
92
119
  const beforeDecorator = async (req, res, next) => {
@@ -5,4 +5,8 @@ module.exports = {
5
5
  label: "not-node:field_ID_label",
6
6
  readonly: true,
7
7
  },
8
+ model: {
9
+ type: Number,
10
+ required: true,
11
+ },
8
12
  };
@@ -63,7 +63,7 @@ module.exports.initSchemaField = (
63
63
  let proto = findFieldPrototype(app, srcName, type);
64
64
  if (!proto) {
65
65
  error(
66
- `field ${moduleName}//${destName} prototype ${srcName} of ${type} type is not found`
66
+ `${type} field ${moduleName}//${destName} prototype ${srcName} is not found`
67
67
  );
68
68
  }
69
69
  let schemaFieldValue = Object.assign({}, clone(proto), mutation);
@@ -102,7 +102,7 @@ const parseFieldDescription = (field) => {
102
102
  } else {
103
103
  if (field.includes(DEFAULT_SPLITER)) {
104
104
  //form 5
105
- destName = field.split(DEFAULT_SPLITER)[0];
105
+ destName = field.split(DEFAULT_SPLITER)[1];
106
106
  srcName = field;
107
107
  } else {
108
108
  destName = srcName = field; //form 1
@@ -208,11 +208,16 @@ class notModule {
208
208
  }
209
209
 
210
210
  getStatus() {
211
+ const fieldsList = Object.keys(this.fields);
211
212
  const formsList = Object.keys(this.forms);
212
213
  const modelsList = Object.keys(this.models);
213
214
  const routesList = Object.keys(this.routes);
214
215
  const actionsList = this.getActionsList();
215
216
  return {
217
+ fields: {
218
+ count: fieldsList.length,
219
+ list: fieldsList,
220
+ },
216
221
  forms: {
217
222
  count: formsList.length,
218
223
  list: formsList,
@@ -373,6 +378,19 @@ class notModule {
373
378
  this.routesWS[collectionType][collectionName][endPointType] = {};
374
379
  }
375
380
  }
381
+
382
+ printOutModuleContent() {
383
+ const status = this.getStatus();
384
+ Object.keys(status).forEach((contentType) => {
385
+ if (status[contentType].count) {
386
+ log.log(
387
+ `${this.getName()} ${contentType}(${
388
+ status[contentType].count
389
+ }): ${status[contentType].list.join(", ")}`
390
+ );
391
+ }
392
+ });
393
+ }
376
394
  }
377
395
 
378
396
  module.exports = notModule;
@@ -7,13 +7,13 @@ class VersioningExceptionSameOldData extends notError {
7
7
  }
8
8
  module.exports.VersioningExceptionSameOldData = VersioningExceptionSameOldData;
9
9
 
10
- class VersioningExceptionNoPpreviousVersions extends notError {
10
+ class VersioningExceptioNoPreviousVersions extends notError {
11
11
  constructor() {
12
12
  super("not-node:versioning_error_no_previous_versions");
13
13
  }
14
14
  }
15
- module.exports.VersioningExceptionNoPpreviousVersions =
16
- VersioningExceptionNoPpreviousVersions;
15
+ module.exports.VersioningExceptioNoPreviousVersions =
16
+ VersioningExceptioNoPreviousVersions;
17
17
 
18
18
  class IncrementExceptionIDGeneratorRebaseFailed extends notError {
19
19
  constructor() {
@@ -2,7 +2,7 @@
2
2
 
3
3
  const incrementNext = require("./increment");
4
4
  const { DBExceptionUpdateOneWasNotSuccessful } = require("../exceptions/db");
5
- const { updateResponseSuccess } = require("./utils");
5
+ //const { updateResponseSuccess } = require("./utils");
6
6
  class ModelRoutine {
7
7
  static incremental(model) {
8
8
  return model.schema.statics.__incField;
@@ -57,6 +57,7 @@ class ModelRoutine {
57
57
  return model
58
58
  .findOneAndUpdate(filter, data, {
59
59
  returnOriginal: false,
60
+ returnDocument: "fater",
60
61
  new: true,
61
62
  })
62
63
  .exec();
@@ -65,11 +66,15 @@ class ModelRoutine {
65
66
  static async updateWithVersion(model, filter, data) {
66
67
  filter.__latest = true;
67
68
  filter.__closed = false;
68
- const result = await model.updateOne(filter, data, {
69
- returnOriginal: false,
70
- });
71
- if (updateResponseSuccess(result, 1)) {
72
- return model.saveVersion(filter._id);
69
+ const result = await model
70
+ .findOneAndUpdate(filter, data, {
71
+ returnOriginal: false,
72
+ returnDocument: "fater",
73
+ new: true,
74
+ })
75
+ .exec();
76
+ if (result) {
77
+ return model.saveVersion(result._id);
73
78
  } else {
74
79
  throw new DBExceptionUpdateOneWasNotSuccessful();
75
80
  }
@@ -12,7 +12,7 @@ const TECH_FIELDS = [
12
12
  ];
13
13
 
14
14
  const {
15
- VersioningExceptioNoPpreviousVersions,
15
+ VersioningExceptioNoPreviousVersions,
16
16
  VersioningExceptionSameOldData,
17
17
  } = require("./exceptions.js");
18
18
 
@@ -74,7 +74,7 @@ class ModelVersioning {
74
74
  previous.toObject()
75
75
  );
76
76
  } else {
77
- throw new VersioningExceptioNoPpreviousVersions();
77
+ throw new VersioningExceptioNoPreviousVersions();
78
78
  }
79
79
  }
80
80