mythix-orm 1.0.1 → 1.0.4
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/lib/connection/connection-base.js +31 -31
- package/lib/connection/literals/literal-base.js +34 -2
- package/lib/connection/query-generator-base.js +23 -23
- package/lib/field.js +28 -0
- package/lib/model.js +3 -3
- package/lib/query-engine/model-scope.js +1 -1
- package/lib/types/concrete/datetime-type.js +1 -1
- package/lib/types/type.js +4 -0
- package/package.json +2 -2
- package/.eslintrc.js +0 -94
- package/.vscode/launch.json +0 -34
- package/.vscode/settings.json +0 -10
- package/playground/test01.js +0 -15
- package/spec/connection/connection-base-spec.js +0 -126
- package/spec/connection/literals/average-literal-spec.js +0 -45
- package/spec/connection/literals/count-literal-spec.js +0 -42
- package/spec/connection/literals/distinct-literal-spec.js +0 -42
- package/spec/connection/literals/literal-spec.js +0 -26
- package/spec/connection/literals/max-literal-spec.js +0 -42
- package/spec/connection/literals/min-literal-spec.js +0 -42
- package/spec/connection/literals/sum-literal-spec.js +0 -42
- package/spec/helpers/default-helpers-spec.js +0 -108
- package/spec/model-spec.js +0 -736
- package/spec/proxy-class/proxy-class-spec.js +0 -173
- package/spec/query-engine/__snapshots__/QueryEngine-operations-query_operations_and_chaining-can_chain_query_conditions-001.snapshot +0 -94
- package/spec/query-engine/__snapshots__/QueryEngine-operations-query_operations_and_chaining-can_construct_a_query_context_with_a_model_call-001.snapshot +0 -35
- package/spec/query-engine/__snapshots__/QueryEngine-operations-query_operations_and_chaining-can_construct_a_query_context_with_a_model_sub-001.snapshot +0 -35
- package/spec/query-engine/__snapshots__/QueryEngine-operations-query_operations_and_chaining-can_set_a_default_scope_on_a_model-001.snapshot +0 -57
- package/spec/query-engine/__snapshots__/QueryEngine-operations-query_operations_and_chaining-can_unscope_default_scope_on_a_model-001.snapshot +0 -35
- package/spec/query-engine/query-engine-spec.js +0 -99
- package/spec/support/jasmine.json +0 -13
- package/spec/support/models/blob-test-model.js +0 -19
- package/spec/support/models/extended-user-model.js +0 -38
- package/spec/support/models/index.js +0 -27
- package/spec/support/models/number-model.js +0 -24
- package/spec/support/models/role-model.js +0 -26
- package/spec/support/models/role-thing-model.js +0 -41
- package/spec/support/models/scoped-user-model.js +0 -13
- package/spec/support/models/time-model.js +0 -36
- package/spec/support/models/user-model.js +0 -70
- package/spec/support/models/user-role-model.js +0 -36
- package/spec/support/models/user-thing-model.js +0 -46
- package/spec/support/models/validation-test-model.js +0 -40
- package/spec/support/snapshots.js +0 -293
- package/spec/support/test-helpers.js +0 -13
- package/spec/types/concrete/bigint-type-spec.js +0 -84
- package/spec/types/concrete/boolean-type-spec.js +0 -83
- package/spec/types/concrete/date-type-spec.js +0 -85
- package/spec/types/concrete/datetime-type-spec.js +0 -87
- package/spec/types/concrete/float-type-spec.js +0 -71
- package/spec/types/concrete/foreign-key-type-spec.js +0 -64
- package/spec/types/concrete/integer-type-spec.js +0 -71
- package/spec/types/concrete/string-type-spec.js +0 -91
- package/spec/types/concrete/uuid-v1-type-spec.js +0 -73
- package/spec/types/concrete/uuid-v4-type-spec.js +0 -65
- package/spec/types/type-spec.js +0 -101
- package/spec/types/virtual/model-types-spec.js +0 -401
- package/spec/utils/misc-utils-spec.js +0 -61
- package/spec/utils/model-utils-spec.js +0 -55
- package/spec/utils/query-utils-spec.js +0 -105
|
@@ -228,7 +228,7 @@ class ConnectionBase extends EventEmitter {
|
|
|
228
228
|
|
|
229
229
|
escape(field, _value) {
|
|
230
230
|
var value = _value;
|
|
231
|
-
if (value
|
|
231
|
+
if (LiteralBase.isLiteral(value))
|
|
232
232
|
return value.toString(this);
|
|
233
233
|
|
|
234
234
|
value = field.type.serialize(value, this);
|
|
@@ -256,14 +256,14 @@ class ConnectionBase extends EventEmitter {
|
|
|
256
256
|
}
|
|
257
257
|
|
|
258
258
|
escapeID(value) {
|
|
259
|
-
if (value
|
|
259
|
+
if (LiteralBase.isLiteral(value))
|
|
260
260
|
return value.toString(this.connection);
|
|
261
261
|
|
|
262
262
|
return this._escapeID(value);
|
|
263
263
|
}
|
|
264
264
|
|
|
265
265
|
_averageLiteralToString(literal) {
|
|
266
|
-
if (!literal || !(literal
|
|
266
|
+
if (!literal || !LiteralBase.isLiteral(literal))
|
|
267
267
|
return;
|
|
268
268
|
|
|
269
269
|
let queryGenerator = this.getQueryGenerator();
|
|
@@ -274,7 +274,7 @@ class ConnectionBase extends EventEmitter {
|
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
_countLiteralToString(literal) {
|
|
277
|
-
if (!literal || !(literal
|
|
277
|
+
if (!literal || !LiteralBase.isLiteral(literal))
|
|
278
278
|
return;
|
|
279
279
|
|
|
280
280
|
let queryGenerator = this.getQueryGenerator();
|
|
@@ -285,7 +285,7 @@ class ConnectionBase extends EventEmitter {
|
|
|
285
285
|
}
|
|
286
286
|
|
|
287
287
|
_distinctLiteralToString(literal) {
|
|
288
|
-
if (!literal || !(literal
|
|
288
|
+
if (!literal || !LiteralBase.isLiteral(literal))
|
|
289
289
|
return;
|
|
290
290
|
|
|
291
291
|
let queryGenerator = this.getQueryGenerator();
|
|
@@ -296,7 +296,7 @@ class ConnectionBase extends EventEmitter {
|
|
|
296
296
|
}
|
|
297
297
|
|
|
298
298
|
_maxLiteralToString(literal) {
|
|
299
|
-
if (!literal || !(literal
|
|
299
|
+
if (!literal || !LiteralBase.isLiteral(literal))
|
|
300
300
|
return;
|
|
301
301
|
|
|
302
302
|
let queryGenerator = this.getQueryGenerator();
|
|
@@ -307,7 +307,7 @@ class ConnectionBase extends EventEmitter {
|
|
|
307
307
|
}
|
|
308
308
|
|
|
309
309
|
_minLiteralToString(literal) {
|
|
310
|
-
if (!literal || !(literal
|
|
310
|
+
if (!literal || !LiteralBase.isLiteral(literal))
|
|
311
311
|
return;
|
|
312
312
|
|
|
313
313
|
let queryGenerator = this.getQueryGenerator();
|
|
@@ -318,7 +318,7 @@ class ConnectionBase extends EventEmitter {
|
|
|
318
318
|
}
|
|
319
319
|
|
|
320
320
|
_sumLiteralToString(literal) {
|
|
321
|
-
if (!literal || !(literal
|
|
321
|
+
if (!literal || !LiteralBase.isLiteral(literal))
|
|
322
322
|
return;
|
|
323
323
|
|
|
324
324
|
let queryGenerator = this.getQueryGenerator();
|
|
@@ -329,19 +329,19 @@ class ConnectionBase extends EventEmitter {
|
|
|
329
329
|
}
|
|
330
330
|
|
|
331
331
|
literalToString(literal) {
|
|
332
|
-
if (
|
|
332
|
+
if (Literals.AverageLiteral.isLiteralType(literal))
|
|
333
333
|
return this._averageLiteralToString(literal);
|
|
334
|
-
else if (
|
|
334
|
+
else if (Literals.CountLiteral.isLiteralType(literal))
|
|
335
335
|
return this._countLiteralToString(literal);
|
|
336
|
-
else if (
|
|
336
|
+
else if (Literals.DistinctLiteral.isLiteralType(literal))
|
|
337
337
|
return this._distinctLiteralToString(literal);
|
|
338
|
-
else if (
|
|
338
|
+
else if (Literals.MaxLiteral.isLiteralType(literal))
|
|
339
339
|
return this._maxLiteralToString(literal);
|
|
340
|
-
else if (
|
|
340
|
+
else if (Literals.MinLiteral.isLiteralType(literal))
|
|
341
341
|
return this._minLiteralToString(literal);
|
|
342
|
-
else if (
|
|
342
|
+
else if (Literals.SumLiteral.isLiteralType(literal))
|
|
343
343
|
return this._sumLiteralToString(literal);
|
|
344
|
-
else if (
|
|
344
|
+
else if (Literals.Literal.isLiteralType(literal))
|
|
345
345
|
return literal.toString(this);
|
|
346
346
|
|
|
347
347
|
throw new Error(`${this.constructor.name}::literalToString: Unsupported literal ${literal}.`);
|
|
@@ -423,35 +423,35 @@ class ConnectionBase extends EventEmitter {
|
|
|
423
423
|
}
|
|
424
424
|
|
|
425
425
|
typeToString(type, options) {
|
|
426
|
-
if (
|
|
426
|
+
if (Types.BigIntType.isSameType(type))
|
|
427
427
|
return this._bigintTypeToString(type, options);
|
|
428
|
-
else if (
|
|
428
|
+
else if (Types.BlobType.isSameType(type))
|
|
429
429
|
return this._blobTypeToString(type, options);
|
|
430
|
-
else if (
|
|
430
|
+
else if (Types.BooleanType.isSameType(type))
|
|
431
431
|
return this._booleanTypeToString(type, options);
|
|
432
|
-
else if (
|
|
432
|
+
else if (Types.CharType.isSameType(type))
|
|
433
433
|
return this._charTypeToString(type, options);
|
|
434
|
-
else if (
|
|
434
|
+
else if (Types.DateType.isSameType(type))
|
|
435
435
|
return this._dateTypeToString(type, options);
|
|
436
|
-
else if (
|
|
436
|
+
else if (Types.DateTimeType.isSameType(type))
|
|
437
437
|
return this._datetimeTypeToString(type, options);
|
|
438
|
-
else if (
|
|
438
|
+
else if (Types.FloatType.isSameType(type))
|
|
439
439
|
return this._floatTypeToString(type, options);
|
|
440
|
-
else if (
|
|
440
|
+
else if (Types.IntegerType.isSameType(type))
|
|
441
441
|
return this._integerTypeToString(type, options);
|
|
442
|
-
else if (
|
|
442
|
+
else if (Types.StringType.isSameType(type))
|
|
443
443
|
return this._stringTypeToString(type, options);
|
|
444
|
-
else if (
|
|
444
|
+
else if (Types.TextType.isSameType(type))
|
|
445
445
|
return this._textTypeToString(type, options);
|
|
446
|
-
else if (
|
|
446
|
+
else if (Types.UUIDV1Type.isSameType(type))
|
|
447
447
|
return this._uuidV1TypeToString(type, options);
|
|
448
|
-
else if (
|
|
448
|
+
else if (Types.UUIDV3Type.isSameType(type))
|
|
449
449
|
return this._uuidV3TypeToString(type, options);
|
|
450
|
-
else if (
|
|
450
|
+
else if (Types.UUIDV4Type.isSameType(type))
|
|
451
451
|
return this._uuidV4TypeToString(type, options);
|
|
452
|
-
else if (
|
|
452
|
+
else if (Types.UUIDV5Type.isSameType(type))
|
|
453
453
|
return this._uuidV5TypeToString(type, options);
|
|
454
|
-
else if (
|
|
454
|
+
else if (Types.XIDType.isSameType(type))
|
|
455
455
|
return this._xidTypeToString(type, options);
|
|
456
456
|
|
|
457
457
|
throw new Error(`${this.constructor.name}::typeToString: Unsupported type ${type}.`);
|
|
@@ -715,7 +715,7 @@ class ConnectionBase extends EventEmitter {
|
|
|
715
715
|
let inputIsArray = false;
|
|
716
716
|
if (!Array.isArray(models)) {
|
|
717
717
|
if (!models._mythixPreparedModels) {
|
|
718
|
-
if (models
|
|
718
|
+
if (Nife.instanceOf(models, 'map', 'set'))
|
|
719
719
|
inputIsArray = true;
|
|
720
720
|
|
|
721
721
|
models = Nife.toArray(models).filter(Boolean);
|
|
@@ -3,6 +3,38 @@
|
|
|
3
3
|
const ModelUtils = require('../../utils/model-utils');
|
|
4
4
|
|
|
5
5
|
class LiteralBase {
|
|
6
|
+
static _isMythixLiteral = true;
|
|
7
|
+
|
|
8
|
+
static isLiteralClass(value) {
|
|
9
|
+
if (!value)
|
|
10
|
+
return false;
|
|
11
|
+
|
|
12
|
+
if (value.prototype instanceof LiteralBase)
|
|
13
|
+
return true;
|
|
14
|
+
|
|
15
|
+
if (value._isMythixLiteral)
|
|
16
|
+
return true;
|
|
17
|
+
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static isLiteral(value) {
|
|
22
|
+
if (!value)
|
|
23
|
+
return false;
|
|
24
|
+
|
|
25
|
+
if (value instanceof LiteralBase)
|
|
26
|
+
return true;
|
|
27
|
+
|
|
28
|
+
if (value.constructor && value.constructor._isMythixLiteral)
|
|
29
|
+
return true;
|
|
30
|
+
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static isLiteralType(value) {
|
|
35
|
+
return (this.isLiteral(value) && value.constructor && value.constructor.name === this.name);
|
|
36
|
+
}
|
|
37
|
+
|
|
6
38
|
constructor(literal, options) {
|
|
7
39
|
Object.defineProperties(this, {
|
|
8
40
|
'literal': {
|
|
@@ -21,7 +53,7 @@ class LiteralBase {
|
|
|
21
53
|
}
|
|
22
54
|
|
|
23
55
|
fullyQualifiedNameToDefinition(fullyQualifiedName) {
|
|
24
|
-
if (fullyQualifiedName
|
|
56
|
+
if (LiteralBase.isLiteral(fullyQualifiedName))
|
|
25
57
|
return fullyQualifiedName;
|
|
26
58
|
|
|
27
59
|
if (!fullyQualifiedName)
|
|
@@ -44,7 +76,7 @@ class LiteralBase {
|
|
|
44
76
|
}
|
|
45
77
|
|
|
46
78
|
definitionToField(connection, definition) {
|
|
47
|
-
if (definition
|
|
79
|
+
if (LiteralBase.isLiteral(definition))
|
|
48
80
|
return definition;
|
|
49
81
|
|
|
50
82
|
let field = connection.getField(definition.fieldNames[0], definition.modelName);
|
|
@@ -158,7 +158,7 @@ class QueryGeneratorBase {
|
|
|
158
158
|
if (!field)
|
|
159
159
|
continue;
|
|
160
160
|
|
|
161
|
-
if (field
|
|
161
|
+
if (LiteralBase.isLiteral(field)) {
|
|
162
162
|
let result = field.toString(this.connection);
|
|
163
163
|
let projectionField = this.parseFieldProjection(result, true);
|
|
164
164
|
if (projectionField === result) {
|
|
@@ -195,8 +195,8 @@ class QueryGeneratorBase {
|
|
|
195
195
|
// the list of projected fields (required
|
|
196
196
|
// by some databases)
|
|
197
197
|
const distinctSortOrder = (a, b) => {
|
|
198
|
-
let x = (a
|
|
199
|
-
let y = (b
|
|
198
|
+
let x = LiteralBase.isLiteral(a);
|
|
199
|
+
let y = LiteralBase.isLiteral(b);
|
|
200
200
|
let xStr = (x) ? a.toString(this.connection) : a;
|
|
201
201
|
let yStr = (y) ? b.toString(this.connection) : b;
|
|
202
202
|
let xIsDistinct = (typeof xStr === 'string' && LITERAL_IS_DISTINCT_RE.test(xStr));
|
|
@@ -254,7 +254,7 @@ class QueryGeneratorBase {
|
|
|
254
254
|
for (let i = 0, il = fields.length; i < il; i++) {
|
|
255
255
|
let field = fields[i];
|
|
256
256
|
|
|
257
|
-
if (field
|
|
257
|
+
if (LiteralBase.isLiteral(field))
|
|
258
258
|
return true;
|
|
259
259
|
|
|
260
260
|
if (ModelBase.isModelClass(field))
|
|
@@ -360,7 +360,7 @@ class QueryGeneratorBase {
|
|
|
360
360
|
|
|
361
361
|
let lastField = result[result.length - 1];
|
|
362
362
|
|
|
363
|
-
if (lastField
|
|
363
|
+
if (LiteralBase.isLiteral(lastField))
|
|
364
364
|
result = [ lastField ];
|
|
365
365
|
else if (typeof lastField === 'string')
|
|
366
366
|
result = [ lastField ];
|
|
@@ -433,10 +433,10 @@ class QueryGeneratorBase {
|
|
|
433
433
|
continue;
|
|
434
434
|
}
|
|
435
435
|
|
|
436
|
-
if (projectionValue
|
|
436
|
+
if (LiteralBase.isLiteral(projectionValue)) {
|
|
437
437
|
// If we already have distinct specified on the query
|
|
438
438
|
// then skip any distinct values specified by the user
|
|
439
|
-
if (hasDistinct &&
|
|
439
|
+
if (hasDistinct && Literals.DistinctLiteral.isLiteralType(projectionValue))
|
|
440
440
|
continue;
|
|
441
441
|
|
|
442
442
|
let key = projectionValue.toString(this.connection);
|
|
@@ -562,7 +562,7 @@ class QueryGeneratorBase {
|
|
|
562
562
|
if (!projectionField)
|
|
563
563
|
continue;
|
|
564
564
|
|
|
565
|
-
if (projectionField
|
|
565
|
+
if (LiteralBase.isLiteral(projectionField)) {
|
|
566
566
|
let result = projectionField.toString(this.connection);
|
|
567
567
|
let fullFieldName = this.parseFieldProjection(result);
|
|
568
568
|
if (!fullFieldName)
|
|
@@ -647,7 +647,7 @@ class QueryGeneratorBase {
|
|
|
647
647
|
if (!order)
|
|
648
648
|
return order;
|
|
649
649
|
|
|
650
|
-
if (order
|
|
650
|
+
if (LiteralBase.isLiteral(order))
|
|
651
651
|
return order;
|
|
652
652
|
|
|
653
653
|
// Is this a field?
|
|
@@ -705,11 +705,11 @@ class QueryGeneratorBase {
|
|
|
705
705
|
order = queryPart.value;
|
|
706
706
|
}
|
|
707
707
|
|
|
708
|
-
if (Nife.isNotEmpty(order) && !(order
|
|
708
|
+
if (Nife.isNotEmpty(order) && !LiteralBase.isLiteral(order)) {
|
|
709
709
|
let allModels = this.getAllModelsUsedInQuery(queryEngine, options);
|
|
710
710
|
|
|
711
711
|
order = order.map((_fieldName) => {
|
|
712
|
-
if (_fieldName
|
|
712
|
+
if (LiteralBase.isLiteral(_fieldName))
|
|
713
713
|
return _fieldName;
|
|
714
714
|
|
|
715
715
|
let { fieldName, direction } = this.getFieldDirectionSpecifier(_fieldName);
|
|
@@ -771,13 +771,13 @@ class QueryGeneratorBase {
|
|
|
771
771
|
}
|
|
772
772
|
|
|
773
773
|
_averageLiteralToString(literal) {
|
|
774
|
-
if (!literal || !(literal
|
|
774
|
+
if (!literal || !LiteralBase.isLiteral(literal))
|
|
775
775
|
return;
|
|
776
776
|
|
|
777
777
|
let field = literal.definitionToField(this.connection, literal.definition);
|
|
778
778
|
let escapedFieldName;
|
|
779
779
|
|
|
780
|
-
if (field
|
|
780
|
+
if (LiteralBase.isLiteral(field))
|
|
781
781
|
escapedFieldName = field.toString(this.connection);
|
|
782
782
|
else
|
|
783
783
|
escapedFieldName = this.getEscapedColumnName(field.Model, field, literal.options);
|
|
@@ -786,14 +786,14 @@ class QueryGeneratorBase {
|
|
|
786
786
|
}
|
|
787
787
|
|
|
788
788
|
_countLiteralToString(literal) {
|
|
789
|
-
if (!literal || !(literal
|
|
789
|
+
if (!literal || !LiteralBase.isLiteral(literal))
|
|
790
790
|
return;
|
|
791
791
|
|
|
792
792
|
let field = (literal.definition) ? literal.definitionToField(this.connection, literal.definition) : null;
|
|
793
793
|
let escapedFieldName;
|
|
794
794
|
|
|
795
795
|
if (field) {
|
|
796
|
-
if (field
|
|
796
|
+
if (LiteralBase.isLiteral(field))
|
|
797
797
|
escapedFieldName = field.toString(this.connection);
|
|
798
798
|
else
|
|
799
799
|
escapedFieldName = this.getEscapedColumnName(field.Model, field, literal.options);
|
|
@@ -805,24 +805,24 @@ class QueryGeneratorBase {
|
|
|
805
805
|
}
|
|
806
806
|
|
|
807
807
|
_distinctLiteralToString(literal) {
|
|
808
|
-
if (!literal || !(literal
|
|
808
|
+
if (!literal || !LiteralBase.isLiteral(literal))
|
|
809
809
|
return;
|
|
810
810
|
|
|
811
811
|
let field = literal.definitionToField(this.connection, literal.definition);
|
|
812
|
-
if (field
|
|
812
|
+
if (LiteralBase.isLiteral(field))
|
|
813
813
|
return `DISTINCT ${field.toString(this.connection)}`;
|
|
814
814
|
|
|
815
815
|
return `DISTINCT ${this.getEscapedProjectionName(field.Model, field, literal.options)}`;
|
|
816
816
|
}
|
|
817
817
|
|
|
818
818
|
_maxLiteralToString(literal) {
|
|
819
|
-
if (!literal || !(literal
|
|
819
|
+
if (!literal || !LiteralBase.isLiteral(literal))
|
|
820
820
|
return;
|
|
821
821
|
|
|
822
822
|
let field = literal.definitionToField(this.connection, literal.definition);
|
|
823
823
|
let escapedFieldName;
|
|
824
824
|
|
|
825
|
-
if (field
|
|
825
|
+
if (LiteralBase.isLiteral(field))
|
|
826
826
|
escapedFieldName = field.toString(this.connection);
|
|
827
827
|
else
|
|
828
828
|
escapedFieldName = this.getEscapedColumnName(field.Model, field, literal.options);
|
|
@@ -831,13 +831,13 @@ class QueryGeneratorBase {
|
|
|
831
831
|
}
|
|
832
832
|
|
|
833
833
|
_minLiteralToString(literal) {
|
|
834
|
-
if (!literal || !(literal
|
|
834
|
+
if (!literal || !LiteralBase.isLiteral(literal))
|
|
835
835
|
return;
|
|
836
836
|
|
|
837
837
|
let field = literal.definitionToField(this.connection, literal.definition);
|
|
838
838
|
let escapedFieldName;
|
|
839
839
|
|
|
840
|
-
if (field
|
|
840
|
+
if (LiteralBase.isLiteral(field))
|
|
841
841
|
escapedFieldName = field.toString(this.connection);
|
|
842
842
|
else
|
|
843
843
|
escapedFieldName = this.getEscapedColumnName(field.Model, field, literal.options);
|
|
@@ -846,13 +846,13 @@ class QueryGeneratorBase {
|
|
|
846
846
|
}
|
|
847
847
|
|
|
848
848
|
_sumLiteralToString(literal) {
|
|
849
|
-
if (!literal || !(literal
|
|
849
|
+
if (!literal || !LiteralBase.isLiteral(literal))
|
|
850
850
|
return;
|
|
851
851
|
|
|
852
852
|
let field = literal.definitionToField(this.connection, literal.definition);
|
|
853
853
|
let escapedFieldName;
|
|
854
854
|
|
|
855
|
-
if (field
|
|
855
|
+
if (LiteralBase.isLiteral(field))
|
|
856
856
|
escapedFieldName = field.toString(this.connection);
|
|
857
857
|
else
|
|
858
858
|
escapedFieldName = this.getEscapedColumnName(field.Model, field, literal.options);
|
package/lib/field.js
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
class Field {
|
|
4
|
+
static _isMythixField = true;
|
|
5
|
+
|
|
6
|
+
static isFieldClass(value) {
|
|
7
|
+
if (!value)
|
|
8
|
+
return false;
|
|
9
|
+
|
|
10
|
+
if (value.prototype instanceof Field)
|
|
11
|
+
return true;
|
|
12
|
+
|
|
13
|
+
if (value._isMythixField)
|
|
14
|
+
return true;
|
|
15
|
+
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static isField(value) {
|
|
20
|
+
if (!value)
|
|
21
|
+
return false;
|
|
22
|
+
|
|
23
|
+
if (value instanceof Field)
|
|
24
|
+
return true;
|
|
25
|
+
|
|
26
|
+
if (value.constructor && value.constructor._isMythixField)
|
|
27
|
+
return true;
|
|
28
|
+
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
4
32
|
constructor(fieldDefinition) {
|
|
5
33
|
Object.assign(this, fieldDefinition || {});
|
|
6
34
|
}
|
package/lib/model.js
CHANGED
|
@@ -516,7 +516,7 @@ class Model {
|
|
|
516
516
|
if (!field)
|
|
517
517
|
return;
|
|
518
518
|
|
|
519
|
-
if (field
|
|
519
|
+
if (Field.isField(field)) {
|
|
520
520
|
let clonedField = field.clone();
|
|
521
521
|
|
|
522
522
|
if (Type.isType(clonedField.type)) {
|
|
@@ -602,7 +602,7 @@ class Model {
|
|
|
602
602
|
|
|
603
603
|
field.Model = ModelClass;
|
|
604
604
|
|
|
605
|
-
if (!(field
|
|
605
|
+
if (!Field.isField(field))
|
|
606
606
|
field = new Field(field);
|
|
607
607
|
|
|
608
608
|
if (field.primaryKey)
|
|
@@ -1227,7 +1227,7 @@ class Model {
|
|
|
1227
1227
|
try {
|
|
1228
1228
|
let fieldValue = this[fieldName];
|
|
1229
1229
|
let promise = field.validate.call(this, fieldValue, context);
|
|
1230
|
-
if (!(promise
|
|
1230
|
+
if (!Nife.instanceOf(promise, 'promise'))
|
|
1231
1231
|
promise = Promise.resolve(promise);
|
|
1232
1232
|
|
|
1233
1233
|
promises.push(promise);
|
package/lib/types/type.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mythix-orm",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "ORM for Mythix framework",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"events": "^3.3.0",
|
|
46
46
|
"inflection": "^1.13.2",
|
|
47
47
|
"moment": "^2.29.3",
|
|
48
|
-
"nife": "^1.11.
|
|
48
|
+
"nife": "^1.11.3",
|
|
49
49
|
"sqlstring": "^2.3.3",
|
|
50
50
|
"uuid": "^8.3.2",
|
|
51
51
|
"xid-js": "^1.0.1"
|
package/.eslintrc.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/* eslint-disable no-magic-numbers */
|
|
4
|
-
|
|
5
|
-
module.exports = {
|
|
6
|
-
'env': {
|
|
7
|
-
'browser': true,
|
|
8
|
-
'commonjs': true,
|
|
9
|
-
'es2021': true,
|
|
10
|
-
},
|
|
11
|
-
'extends': [
|
|
12
|
-
'eslint:recommended',
|
|
13
|
-
],
|
|
14
|
-
'parserOptions': {
|
|
15
|
-
'ecmaVersion': 'latest',
|
|
16
|
-
},
|
|
17
|
-
'plugins': [
|
|
18
|
-
'@spothero/eslint-plugin-spothero',
|
|
19
|
-
],
|
|
20
|
-
'rules': {
|
|
21
|
-
'@spothero/spothero/ternary-parentheses': 'error',
|
|
22
|
-
'arrow-parens': 'error',
|
|
23
|
-
'arrow-spacing': [ 'error', { before: true, after: true } ],
|
|
24
|
-
'block-scoped-var': 'warn',
|
|
25
|
-
'block-spacing': 'error',
|
|
26
|
-
'brace-style': [ 'error', '1tbs' ],
|
|
27
|
-
'camelcase': 'warn',
|
|
28
|
-
'comma-dangle': [ 'error', 'always-multiline' ],
|
|
29
|
-
'comma-spacing': [ 'error', { before: false, after: true } ],
|
|
30
|
-
'comma-style': [ 'error', 'last' ],
|
|
31
|
-
'curly': [ 'error', 'multi-or-nest', 'consistent' ],
|
|
32
|
-
'default-case-last': 'error',
|
|
33
|
-
'default-param-last': 'error',
|
|
34
|
-
'eqeqeq': [ 'error', 'smart' ],
|
|
35
|
-
'func-call-spacing': [ 'error', 'never' ],
|
|
36
|
-
'guard-for-in': 'error',
|
|
37
|
-
'implicit-arrow-linebreak': [ 'error', 'beside' ],
|
|
38
|
-
'indent': [ 'error', 2, { 'SwitchCase': 1, 'MemberExpression': 'off' } ],
|
|
39
|
-
'jsx-quotes': [ 'error', 'prefer-double' ],
|
|
40
|
-
'key-spacing': [ 'error', { beforeColon: false, afterColon: true, mode: 'minimum', 'align': 'value' } ],
|
|
41
|
-
'keyword-spacing': [ 'error', { before: true, after: true } ],
|
|
42
|
-
'linebreak-style': [ 'error', 'unix' ],
|
|
43
|
-
'lines-between-class-members': 'error',
|
|
44
|
-
'max-classes-per-file': [ 'error', 3 ],
|
|
45
|
-
'new-cap': [ 'error', { 'properties': false } ],
|
|
46
|
-
'new-parens': 'error',
|
|
47
|
-
'no-array-constructor': 'warn',
|
|
48
|
-
'no-caller': 'error',
|
|
49
|
-
'no-confusing-arrow': 'error',
|
|
50
|
-
'no-empty': 'warn',
|
|
51
|
-
'no-eq-null': 0,
|
|
52
|
-
'no-eval': 'error',
|
|
53
|
-
'no-extend-native': 'error',
|
|
54
|
-
'no-extra-label': 'error',
|
|
55
|
-
'no-floating-decimal': 'error',
|
|
56
|
-
'no-global-assign': 'error',
|
|
57
|
-
'no-implied-eval': 'error',
|
|
58
|
-
'no-labels': 'error',
|
|
59
|
-
'no-lone-blocks': 'warn',
|
|
60
|
-
'no-loop-func': 0,
|
|
61
|
-
'no-magic-numbers': [ 'warn', { ignoreArrayIndexes: true, ignoreDefaultValues: true, ignore: [ -1, 0, 1, 2, 16, 32, 64, 128, 256, 1024, 2048, 200, 301, 302, 400, 401, 404, 500 ] } ],
|
|
62
|
-
'no-nested-ternary': 'error',
|
|
63
|
-
'no-param-reassign': 'error',
|
|
64
|
-
'no-promise-executor-return': 'error',
|
|
65
|
-
'no-return-assign': 'error',
|
|
66
|
-
'no-sequences': 'error',
|
|
67
|
-
'no-shadow': 0,
|
|
68
|
-
'no-throw-literal': 'warn',
|
|
69
|
-
'no-trailing-spaces': 'error',
|
|
70
|
-
'no-unmodified-loop-condition': 'warn',
|
|
71
|
-
'no-unreachable-loop': 'warn',
|
|
72
|
-
'no-unreachable': 'warn',
|
|
73
|
-
'no-unused-private-class-members': 'warn',
|
|
74
|
-
'no-unused-vars': 'warn',
|
|
75
|
-
'no-whitespace-before-property': 'error',
|
|
76
|
-
'nonblock-statement-body-position': [ 'error', 'below' ],
|
|
77
|
-
'one-var': [ 'error', 'never' ],
|
|
78
|
-
'quotes': [ 'error', 'single' ],
|
|
79
|
-
'radix': 'error',
|
|
80
|
-
'rest-spread-spacing': [ 'error', 'never' ],
|
|
81
|
-
'semi-spacing': [ 'error', { before: false, after: true } ],
|
|
82
|
-
'semi-style': [ 'error', 'last' ],
|
|
83
|
-
'semi': 'error',
|
|
84
|
-
'space-before-blocks': 'error',
|
|
85
|
-
'space-infix-ops': 'error',
|
|
86
|
-
'space-unary-ops': [ 'error', { words: false, nonwords: false } ],
|
|
87
|
-
'strict': 'error',
|
|
88
|
-
'switch-colon-spacing': [ 'error', { before: false, after: true } ],
|
|
89
|
-
'template-curly-spacing': 'error',
|
|
90
|
-
'template-tag-spacing': 'error',
|
|
91
|
-
'wrap-iife': [ 'error', 'inside' ],
|
|
92
|
-
'yoda': 'error',
|
|
93
|
-
},
|
|
94
|
-
};
|
package/.vscode/launch.json
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Use IntelliSense to learn about possible attributes.
|
|
3
|
-
// Hover to view descriptions of existing attributes.
|
|
4
|
-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
-
"version": "0.2.0",
|
|
6
|
-
"configurations": [
|
|
7
|
-
{
|
|
8
|
-
"type": "pwa-node",
|
|
9
|
-
"request": "launch",
|
|
10
|
-
"name": "Debug Unit Tests",
|
|
11
|
-
"skipFiles": [
|
|
12
|
-
"<node_internals>/**",
|
|
13
|
-
"node_modules/**/*.js",
|
|
14
|
-
"**/node_modules/**",
|
|
15
|
-
"async_hooks.js",
|
|
16
|
-
"inspector_async_hook.js"
|
|
17
|
-
],
|
|
18
|
-
"program": "${workspaceFolder}/node_modules/.bin/jasmine",
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"type": "pwa-node",
|
|
22
|
-
"request": "launch",
|
|
23
|
-
"name": "Playground Test 01",
|
|
24
|
-
"skipFiles": [
|
|
25
|
-
"<node_internals>/**",
|
|
26
|
-
"node_modules/**/*.js",
|
|
27
|
-
"**/node_modules/**",
|
|
28
|
-
"async_hooks.js",
|
|
29
|
-
"inspector_async_hook.js"
|
|
30
|
-
],
|
|
31
|
-
"program": "${workspaceFolder}/playground/test01.js",
|
|
32
|
-
}
|
|
33
|
-
]
|
|
34
|
-
}
|
package/.vscode/settings.json
DELETED
package/playground/test01.js
DELETED