spice-js 2.5.18 → 2.5.21

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.
@@ -2,6 +2,8 @@
2
2
 
3
3
  var _path = _interopRequireDefault(require("path"));
4
4
 
5
+ var _lodash = _interopRequireDefault(require("lodash"));
6
+
5
7
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
8
 
7
9
  function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
@@ -14,15 +16,16 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
14
16
 
15
17
  try {
16
18
  var resources = ["models", "controllers", "schemas"];
17
- resources.every(resource => {
18
- var paths = _path.default.join(spice.root_path, resource);
19
19
 
20
- spice[resource] = {};
20
+ _lodash.default.each(resources,
21
+ /*#__PURE__*/
22
+ function () {
23
+ var _ref = _asyncToGenerator(function* (resource) {
24
+ var paths = _path.default.join(spice.root_path, resource);
25
+
26
+ spice[resource] = {};
21
27
 
22
- require("fs").readdirSync(paths).forEach(
23
- /*#__PURE__*/
24
- function () {
25
- var _ref = _asyncToGenerator(function* (file) {
28
+ for (var file of require("fs").readdirSync(paths)) {
26
29
  var file_name = file.split(".")[0];
27
30
  spice[resource][file_name.toLowerCase()] = (yield Promise.resolve("" + _path.default.join(paths, file)).then(s => _interopRequireWildcard(require(s)))).default;
28
31
  spice[resource][file_name] = (yield Promise.resolve("" + _path.default.join(paths, file)).then(s => _interopRequireWildcard(require(s)))).default;
@@ -30,13 +33,15 @@ try {
30
33
  if (resource == "models") {
31
34
  new spice[resource][file_name]({});
32
35
  }
33
- });
36
+ }
37
+
38
+ console.log(resource, spice[resource]);
39
+ });
34
40
 
35
- return function (_x) {
36
- return _ref.apply(this, arguments);
37
- };
38
- }());
39
- });
41
+ return function (_x) {
42
+ return _ref.apply(this, arguments);
43
+ };
44
+ }());
40
45
  } catch (error) {
41
- console.log(error);
46
+ console.log("Error Happened", error);
42
47
  }
@@ -93,6 +93,20 @@ class SpiceModel {
93
93
  collection: args.collection,
94
94
  scope: args.scope
95
95
  });
96
+
97
+ function removeDynamicProps(props) {
98
+ var returnVal = {};
99
+
100
+ for (var i in props) {
101
+ if (!_.has(props[i], "source") || _.get(props[i], "source") == "static") {
102
+ returnVal[i] = props[i];
103
+ }
104
+ }
105
+
106
+ return returnVal;
107
+ }
108
+
109
+ args.props = removeDynamicProps(args.props);
96
110
  this[_props] = args.props;
97
111
 
98
112
  for (var i in args.props) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spice-js",
3
- "version": "2.5.18",
3
+ "version": "2.5.21",
4
4
  "description": "spice",
5
5
  "main": "build/index.js",
6
6
  "repository": {
@@ -1,25 +1,24 @@
1
1
  import path from "path";
2
-
2
+ import _ from "lodash";
3
3
  try {
4
4
  let resources = ["models", "controllers", "schemas"];
5
- resources.every((resource) => {
5
+ _.each(resources, async function (resource) {
6
6
  let paths = path.join(spice.root_path, resource);
7
7
  spice[resource] = {};
8
- require("fs")
9
- .readdirSync(paths)
10
- .forEach(async function (file) {
11
- let file_name = file.split(".")[0];
12
- spice[resource][file_name.toLowerCase()] = (
13
- await import(path.join(paths, file))
14
- ).default;
15
- spice[resource][file_name] = (
16
- await import(path.join(paths, file))
17
- ).default;
18
- if (resource == "models") {
19
- new spice[resource][file_name]({});
20
- }
21
- });
8
+ for (let file of require("fs").readdirSync(paths)) {
9
+ let file_name = file.split(".")[0];
10
+ spice[resource][file_name.toLowerCase()] = (
11
+ await import(path.join(paths, file))
12
+ ).default;
13
+ spice[resource][file_name] = (
14
+ await import(path.join(paths, file))
15
+ ).default;
16
+ if (resource == "models") {
17
+ new spice[resource][file_name]({});
18
+ }
19
+ }
20
+ console.log(resource, spice[resource]);
22
21
  });
23
22
  } catch (error) {
24
- console.log(error);
23
+ console.log("Error Happened", error);
25
24
  }
@@ -1,16 +1,19 @@
1
1
  import path from "path";
2
+ import fs from "fs-extra";
2
3
 
3
4
  spice.seeds = {};
4
5
 
5
6
  let paths = path.join(spice.root_path, "seeds");
6
- require("fs")
7
- .readdirSync(paths)
8
- .forEach(function (file) {
9
- if (file != "index.js") {
10
- let seed = require(path.join(paths, file));
11
- spice.seeds[file.split(".")[0]] = seed;
12
- if (seed.run) {
13
- seed.run();
7
+ if (fs.existsSync(paths)) {
8
+ require("fs")
9
+ .readdirSync(paths)
10
+ .forEach(function (file) {
11
+ if (file != "index.js") {
12
+ let seed = require(path.join(paths, file));
13
+ spice.seeds[file.split(".")[0]] = seed;
14
+ if (seed.run) {
15
+ seed.run();
16
+ }
14
17
  }
15
- }
16
- });
18
+ });
19
+ }
@@ -50,7 +50,7 @@ export default class SpiceModel {
50
50
  before: [],
51
51
  after: [],
52
52
  },
53
- update: {
53
+ update: {
54
54
  before: [],
55
55
  after: [],
56
56
  },
@@ -69,14 +69,30 @@ export default class SpiceModel {
69
69
  cleaners: [],
70
70
  },
71
71
  };
72
+
72
73
  this.deleted = false;
73
74
  if (args.args) {
74
75
  delete args.args["ctx"];
75
76
  }
77
+
76
78
  this[_database] = new Database(args.connection || "default", {
77
79
  collection: args.collection,
78
80
  scope: args.scope,
79
81
  });
82
+
83
+ function removeDynamicProps(props) {
84
+ let returnVal = {};
85
+ for (let i in props) {
86
+ if (
87
+ !_.has(props[i], "source") ||
88
+ _.get(props[i], "source") == "static"
89
+ ) {
90
+ returnVal[i] = props[i];
91
+ }
92
+ }
93
+ return returnVal;
94
+ }
95
+ args.props = removeDynamicProps(args.props);
80
96
  this[_props] = args.props;
81
97
  for (let i in args.props) {
82
98
  if (args.args != undefined) {