spice-js 2.5.25 → 2.5.28

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.
@@ -23,6 +23,7 @@ var SDate = require("sonover-date"),
23
23
  UUID = require("uuid"),
24
24
  _ = require("lodash"),
25
25
  _database = Symbol(),
26
+ _ctx = Symbol(),
26
27
  _props = Symbol(),
27
28
  _args = Symbol(),
28
29
  _hooks = Symbol(),
@@ -48,7 +49,7 @@ class SpiceModel {
48
49
  }
49
50
 
50
51
  try {
51
- var _args$args;
52
+ var _args$args, _args2, _args2$args;
52
53
 
53
54
  var dbtype = spice.config.database.connections[args.connection].type || "couchbase";
54
55
 
@@ -57,6 +58,7 @@ class SpiceModel {
57
58
  this.type = "";
58
59
  this[_args] = args.args;
59
60
  this[_disable_lifecycle_events] = ((_args$args = args.args) == null ? void 0 : _args$args.disable_lifecycle_events) || false;
61
+ this[_ctx] = (_args2 = args) == null ? void 0 : (_args2$args = _args2.args) == null ? void 0 : _args2$args.ctx;
60
62
  this[_hooks] = {
61
63
  create: {
62
64
  before: [],
@@ -90,10 +92,11 @@ class SpiceModel {
90
92
  }
91
93
  };
92
94
  this.deleted = false;
93
-
95
+ /*
94
96
  if (args.args) {
95
97
  delete args.args["ctx"];
96
98
  }
99
+ */
97
100
 
98
101
  this[_database] = new Database(args.connection || "default", {
99
102
  collection: args.collection,
@@ -445,12 +448,12 @@ class SpiceModel {
445
448
  })();
446
449
  }
447
450
 
448
- query(query) {
451
+ query(query, scope) {
449
452
  var _this2 = this;
450
453
 
451
454
  return _asyncToGenerator(function* () {
452
455
  try {
453
- var results = yield _this2.database.query(query);
456
+ var results = yield _this2.database.query(query, scope);
454
457
  return results;
455
458
  } catch (error) {
456
459
  throw error;
@@ -732,7 +735,8 @@ class SpiceModel {
732
735
  operation: op,
733
736
  when,
734
737
  old_data,
735
- resource: _this9.type
738
+ resource: _this9.type,
739
+ ctx: _this9[_ctx]
736
740
  }
737
741
  });
738
742
  resourceLifecycleTriggered.dispatch();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spice-js",
3
- "version": "2.5.25",
3
+ "version": "2.5.28",
4
4
  "description": "spice",
5
5
  "main": "build/index.js",
6
6
  "repository": {
@@ -9,6 +9,7 @@ var SDate = require("sonover-date"),
9
9
  UUID = require("uuid"),
10
10
  _ = require("lodash"),
11
11
  _database = Symbol(),
12
+ _ctx = Symbol(),
12
13
  _props = Symbol(),
13
14
  _args = Symbol(),
14
15
  _hooks = Symbol(),
@@ -41,6 +42,7 @@ export default class SpiceModel {
41
42
  this[_args] = args.args;
42
43
  this[_disable_lifecycle_events] =
43
44
  args.args?.disable_lifecycle_events || false;
45
+ this[_ctx] = args?.args?.ctx;
44
46
  this[_hooks] = {
45
47
  create: {
46
48
  before: [],
@@ -75,10 +77,12 @@ export default class SpiceModel {
75
77
  };
76
78
 
77
79
  this.deleted = false;
80
+
81
+ /*
78
82
  if (args.args) {
79
83
  delete args.args["ctx"];
80
84
  }
81
-
85
+ */
82
86
  this[_database] = new Database(args.connection || "default", {
83
87
  collection: args.collection,
84
88
  scope: args.scope,
@@ -371,9 +375,9 @@ export default class SpiceModel {
371
375
  }
372
376
  }
373
377
 
374
- async query(query) {
378
+ async query(query, scope) {
375
379
  try {
376
- let results = await this.database.query(query);
380
+ let results = await this.database.query(query, scope);
377
381
  return results;
378
382
  } catch (error) {
379
383
  throw error;
@@ -617,7 +621,14 @@ export default class SpiceModel {
617
621
  try {
618
622
  if (this[_disable_lifecycle_events] == false) {
619
623
  let resourceLifecycleTriggered = new ResourceLifecycleTriggered({
620
- data: { data, operation: op, when, old_data, resource: this.type },
624
+ data: {
625
+ data,
626
+ operation: op,
627
+ when,
628
+ old_data,
629
+ resource: this.type,
630
+ ctx: this[_ctx],
631
+ },
621
632
  });
622
633
  resourceLifecycleTriggered.dispatch();
623
634
  }