mythix-orm 1.11.4 → 1.11.6

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.
@@ -280,6 +280,16 @@ class ConnectionBase extends EventEmitter {
280
280
  return new QueryGeneratorBase(this);
281
281
  }
282
282
 
283
+ stackAssign(obj, ..._args) {
284
+ let newObj = Object.create(obj || {});
285
+ let args = _args.filter(Boolean);
286
+
287
+ if (args.length > 0)
288
+ Object.assign(newObj, ...args);
289
+
290
+ return newObj;
291
+ }
292
+
283
293
  /// This method is an internal method that parses
284
294
  /// the "lock mode" options passed to a call to
285
295
  /// <see>Connection.transaction</see>.
@@ -3,6 +3,10 @@
3
3
  const LiteralFieldBase = require('./literal-field-base');
4
4
 
5
5
  class AverageLiteral extends LiteralFieldBase {
6
+ static isAggregate() {
7
+ return true;
8
+ }
9
+
6
10
  toString(connection, options) {
7
11
  if (!connection)
8
12
  return `${this.constructor.name} {}`;
@@ -7,6 +7,10 @@ class CountLiteral extends LiteralFieldBase {
7
7
  return false;
8
8
  }
9
9
 
10
+ static isAggregate() {
11
+ return true;
12
+ }
13
+
10
14
  toString(connection, options) {
11
15
  if (!connection)
12
16
  return `${this.constructor.name} {}`;
@@ -43,6 +43,14 @@ class LiteralBase {
43
43
  return (this.isLiteral(value) && value.constructor && value.constructor.name === this.name);
44
44
  }
45
45
 
46
+ static isAggregate() {
47
+ return false;
48
+ }
49
+
50
+ isAggregate() {
51
+ return this.constructor.isAggregate();
52
+ }
53
+
46
54
  constructor(literal, options) {
47
55
  Object.defineProperties(this, {
48
56
  'literal': {
@@ -87,6 +95,9 @@ class LiteralBase {
87
95
  if (LiteralBase.isLiteral(definition))
88
96
  return definition;
89
97
 
98
+ if (!definition.fieldNames)
99
+ return definition;
100
+
90
101
  let field = connection.getField(definition.fieldNames[0], definition.modelName);
91
102
  if (!field) {
92
103
  if (definition.fieldNames[0] && definition.modelName) {
@@ -109,6 +120,10 @@ class LiteralBase {
109
120
  toString() {
110
121
  return this.literal;
111
122
  }
123
+
124
+ valueOf() {
125
+ return this.literal;
126
+ }
112
127
  }
113
128
 
114
129
  module.exports = LiteralBase;
@@ -20,6 +20,8 @@ class LiteralFieldBase extends LiteralBase {
20
20
  } catch (error) {
21
21
  if (isRequired)
22
22
  throw error;
23
+
24
+ definition = fullyQualifiedName;
23
25
  }
24
26
  }
25
27
 
@@ -47,6 +49,10 @@ class LiteralFieldBase extends LiteralBase {
47
49
 
48
50
  return this.definitionToField(connection, this.definition);
49
51
  }
52
+
53
+ valueOf() {
54
+ return this.definition;
55
+ }
50
56
  }
51
57
 
52
58
  module.exports = LiteralFieldBase;
@@ -3,6 +3,10 @@
3
3
  const LiteralFieldBase = require('./literal-field-base');
4
4
 
5
5
  class MaxLiteral extends LiteralFieldBase {
6
+ static isAggregate() {
7
+ return true;
8
+ }
9
+
6
10
  toString(connection, options) {
7
11
  if (!connection)
8
12
  return `${this.constructor.name} {}`;
@@ -3,6 +3,10 @@
3
3
  const LiteralFieldBase = require('./literal-field-base');
4
4
 
5
5
  class MinLiteral extends LiteralFieldBase {
6
+ static isAggregate() {
7
+ return true;
8
+ }
9
+
6
10
  toString(connection, options) {
7
11
  if (!connection)
8
12
  return `${this.constructor.name} {}`;
@@ -3,6 +3,10 @@
3
3
  const LiteralFieldBase = require('./literal-field-base');
4
4
 
5
5
  class SumLiteral extends LiteralFieldBase {
6
+ static isAggregate() {
7
+ return true;
8
+ }
9
+
6
10
  toString(connection, options) {
7
11
  if (!connection)
8
12
  return `${this.constructor.name} {}`;
@@ -15,14 +15,8 @@ class QueryGeneratorBase {
15
15
  });
16
16
  }
17
17
 
18
- stackAssign(obj, ..._args) {
19
- let newObj = Object.create(obj || {});
20
- let args = _args.filter(Boolean);
21
-
22
- if (args.length > 0)
23
- Object.assign(newObj, ...args);
24
-
25
- return newObj;
18
+ stackAssign(obj, ...args) {
19
+ return this.connection.stackAssign(obj, ...args);
26
20
  }
27
21
 
28
22
  escape(...args) {
package/lib/model.js CHANGED
@@ -450,14 +450,16 @@ class Model {
450
450
  /// a connection to your models. This will allow you to provide a
451
451
  /// connection directly when you create the model, which can make
452
452
  /// interacting with the model less tiresome. i.e. `new Model(null, { connection })`.
453
- _getConnection(connection) {
453
+ _getConnection(_connection) {
454
+ let connection = _connection;
454
455
  if (connection)
455
456
  return connection;
456
457
 
457
- if (this._connection)
458
- return this._connection;
458
+ connection = this.constructor._getConnection();
459
+ if (connection)
460
+ return connection;
459
461
 
460
- return this.constructor._getConnection();
462
+ return this._connection;
461
463
  }
462
464
 
463
465
  static getConnection(_connection) {
@@ -353,6 +353,8 @@ class ModelScope extends QueryEngineBase {
353
353
  distinctValue = new DistinctLiteral(`${fullyQualifiedName.Model.getModelName()}:${fullyQualifiedName.fieldName}`);
354
354
  } else if (LiteralBase.isLiteral(fullyQualifiedName)) {
355
355
  distinctValue = new DistinctLiteral(fullyQualifiedName);
356
+ } else if (!fullyQualifiedName) {
357
+ distinctValue = null;
356
358
  } else {
357
359
  throw new TypeError(`QueryEngine::ModelScope::DISTINCT: Invalid value provided [${(fullyQualifiedName) ? fullyQualifiedName.toString() : fullyQualifiedName}]. All values provided must be strings, fields, or literals.`);
358
360
  }
@@ -1,15 +1,17 @@
1
1
  'use strict';
2
2
 
3
- let globalAsyncStore;
4
-
5
- try {
6
- const { AsyncLocalStorage } = require('async_hooks');
7
- globalAsyncStore = new AsyncLocalStorage();
8
- } catch (error) {
9
- globalAsyncStore = {
10
- getStore: () => undefined,
11
- run: (context, callback) => callback(),
12
- };
3
+ let globalAsyncStore = global._mythixGlobalAsyncLocalStore;
4
+
5
+ if (!globalAsyncStore) {
6
+ try {
7
+ const { AsyncLocalStorage } = require('async_hooks');
8
+ global._mythixGlobalAsyncLocalStore = globalAsyncStore = new AsyncLocalStorage();
9
+ } catch (error) {
10
+ global._mythixGlobalAsyncLocalStore = globalAsyncStore = {
11
+ getStore: () => undefined,
12
+ run: (context, callback) => callback(),
13
+ };
14
+ }
13
15
  }
14
16
 
15
17
  function getContextStore() {
@@ -40,16 +42,13 @@ function setContextValue(key, value) {
40
42
  }
41
43
 
42
44
  function runInContext(context, callback) {
43
- return new Promise((resolve, reject) => {
44
- globalAsyncStore.run({ parent: globalAsyncStore.getStore(), context }, async () => {
45
- try {
46
- let result = await callback();
47
- resolve(result);
48
- } catch (error) {
49
- reject(error);
50
- }
51
- });
52
- });
45
+ return globalAsyncStore.run(
46
+ {
47
+ parent: globalAsyncStore.getStore(),
48
+ context,
49
+ },
50
+ callback,
51
+ );
53
52
  }
54
53
 
55
54
  module.exports = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mythix-orm",
3
- "version": "1.11.4",
3
+ "version": "1.11.6",
4
4
  "description": "ORM for Mythix framework",
5
5
  "main": "lib/index",
6
6
  "type": "commonjs",