spice-js 2.5.4 → 2.5.8

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,7 +2,8 @@ import path from "path";
2
2
  import fs from "fs";
3
3
  import _ from "lodash";
4
4
 
5
- let ordered_modules = ["logger", "error", "database", "views", "routes"];
5
+ let ordered_modules = ["map", "logger", "error", "database"];
6
+ let last_modules = ["views", "routes"];
6
7
  export async function load() {
7
8
  try {
8
9
  /* console.log('loading from array')*/
@@ -10,14 +11,14 @@ export async function load() {
10
11
  let bootstrap_path = path.resolve(
11
12
  path.join(spice.module_root_path, "/bootstrap")
12
13
  );
13
-
14
+
14
15
  let app_bootstrap_path = path.resolve(
15
16
  path.join(spice.root_path, "/bootstrap")
16
17
  );
17
18
 
18
19
  /* console.log('MODULE Bootstrap directory', bootstrap_path);
19
20
  console.log('APP Bootstrap directory', app_bootstrap_path); */
20
-
21
+ console.log("Loading Ordered Files", ordered_modules);
21
22
  for (let file of ordered_modules) {
22
23
  let mod = require(path.join(bootstrap_path, file));
23
24
  if (_.isFunction(mod)) {
@@ -33,7 +34,8 @@ export async function load() {
33
34
  console.log("Loading:", file);
34
35
  if (
35
36
  file != "index.js" &&
36
- !_.includes(ordered_modules, file.split(".")[0])
37
+ !_.includes(ordered_modules, file.split(".")[0]) &&
38
+ !_.includes(last_modules, file.split(".")[0])
37
39
  ) {
38
40
  let mod = require(path.join(loadder_path, file.split(".")[0]));
39
41
  if (_.isFunction(mod)) {
@@ -42,6 +44,14 @@ export async function load() {
42
44
  }
43
45
  }
44
46
  }
47
+
48
+ for (let file of last_modules) {
49
+ let mod = require(path.join(bootstrap_path, file));
50
+ if (_.isFunction(mod)) {
51
+ await mod();
52
+ }
53
+ console.log("loaded", file);
54
+ }
45
55
  } catch (e) {
46
56
  console.log(e.stack);
47
57
  }
@@ -242,7 +242,10 @@ export default class SpiceModel {
242
242
  return _.join(returnVal, "|");
243
243
  }
244
244
 
245
- getValidationRules(method = "POST", { complete = false, pick = [], omit = [] } = {}) {
245
+ getValidationRules(
246
+ method = "POST",
247
+ { complete = false, pick = [], omit = [] } = {}
248
+ ) {
246
249
  let rules = {};
247
250
  let filters = {};
248
251
  let working_properties = this.props;
@@ -743,14 +746,17 @@ export default class SpiceModel {
743
746
  case "string": {
744
747
  this.addModifier({
745
748
  when: properties[i].map.when || "read",
746
- execute: async (data) =>
747
- await this.mapToObject(
749
+ execute: async (data) => {
750
+ return await this.mapToObject(
748
751
  data,
749
- properties[i].map.reference,
752
+ _.isString(properties[i].map.reference)
753
+ ? spice.models[properties[i].map.reference]
754
+ : properties[i].map.reference,
750
755
  i,
751
756
  properties[i].map.destination || i,
752
757
  properties[i]
753
- ),
758
+ );
759
+ },
754
760
  });
755
761
  break;
756
762
  }
@@ -758,14 +764,25 @@ export default class SpiceModel {
758
764
  case "array": {
759
765
  this.addModifier({
760
766
  when: properties[i].map.when || "read",
761
- execute: async (data) =>
762
- await this.mapToObjectArray(
767
+ execute: async (data) => {
768
+ console.log(
769
+ _.isString(properties[i].map.reference),
770
+ _.isString(properties[i].map.reference)
771
+ ? spice.models[properties[i].map.reference]
772
+ : properties[i].map.reference,
773
+ spice.models,
774
+ properties[i].map.reference
775
+ );
776
+ return await this.mapToObjectArray(
763
777
  data,
764
- properties[i].map.reference,
778
+ _.isString(properties[i].map.reference)
779
+ ? spice.models[properties[i].map.reference]
780
+ : properties[i].map.reference,
765
781
  i,
766
782
  properties[i].map.destination || i,
767
783
  properties[i]
768
- ),
784
+ );
785
+ },
769
786
  });
770
787
  break;
771
788
  }
@@ -1,28 +1,30 @@
1
- var views = require('koa-views');
1
+ var views = require("koa-views");
2
2
  const path = require("path");
3
- const juice = require('juice');
4
- import _ from 'lodash';
5
-
3
+ const juice = require("juice");
4
+ import _ from "lodash";
6
5
 
7
6
  export default class Storage {
7
+ constructor(args = {}) {
8
+ this.driver_name = args.driver_name || spice.config.storage.default_driver;
9
+ this.driver_options = _.merge(
10
+ spice.config.storage.drivers[this.driver_name],
11
+ args.options
12
+ );
13
+ //console.log(this.driver_name, spice.config.storage.providers)
14
+ this.Driver = spice.config.storage.providers[this.driver_name];
15
+ }
8
16
 
9
- constructor(args = {}) {
10
- this.driver_name = args.driver_name || spice.config.storage.default_driver;
11
- this.driver_options = _.merge(spice.config.storage.drivers[this.driver_name], args.options);
12
- //console.log(this.driver_name, spice.config.storage.providers)
13
- this.Driver = spice.config.storage.providers[this.driver_name];
14
- }
15
-
16
-
17
- async save({files, path,
18
- options,
19
- }) {
20
- if (options) {
21
- this.driver_options = _.merge(this.driver_options, options);
22
- }
23
- //console.log(this.Driver);
24
- let driver = new this.Driver(this.driver_options);
25
-
26
- return await driver.save({files, path});
17
+ async save({ files, path, options }) {
18
+ if (options) {
19
+ this.driver_options = _.merge(this.driver_options, options);
27
20
  }
28
- }
21
+ //console.log(this.Driver);
22
+ let driver = new this.Driver(this.driver_options);
23
+ return await driver.save({
24
+ files,
25
+ path: this.driver_options.base_path
26
+ ? `${this.driver_options.base_path}/${path}`
27
+ : path,
28
+ });
29
+ }
30
+ }