mythix-orm 1.5.6 → 1.6.2

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.
Files changed (97) hide show
  1. package/lib/connection/connection-base.d.ts +180 -0
  2. package/lib/connection/connection-base.js +242 -16
  3. package/lib/connection/index.d.ts +5 -0
  4. package/lib/connection/literals/average-literal.d.ts +5 -0
  5. package/lib/connection/literals/count-literal.d.ts +5 -0
  6. package/lib/connection/literals/distinct-literal.d.ts +5 -0
  7. package/lib/connection/literals/field-literal.d.ts +5 -0
  8. package/lib/connection/literals/index.d.ts +10 -0
  9. package/lib/connection/literals/literal-base.d.ts +22 -0
  10. package/lib/connection/literals/literal-base.js +2 -2
  11. package/lib/connection/literals/literal-field-base.d.ts +17 -0
  12. package/lib/connection/literals/literal-field-base.js +4 -4
  13. package/lib/connection/literals/literal.d.ts +5 -0
  14. package/lib/connection/literals/max-literal.d.ts +5 -0
  15. package/lib/connection/literals/min-literal.d.ts +5 -0
  16. package/lib/connection/literals/sum-literal.d.ts +5 -0
  17. package/lib/connection/query-generator-base.d.ts +121 -0
  18. package/lib/connection/query-generator-base.js +5 -6
  19. package/lib/field.d.ts +61 -0
  20. package/lib/field.js +9 -0
  21. package/lib/index.d.ts +7 -0
  22. package/lib/index.js +7 -1
  23. package/lib/interfaces/common.ts +3 -0
  24. package/lib/model.d.ts +205 -0
  25. package/lib/model.js +136 -32
  26. package/lib/proxy-class/proxy-class.js +6 -6
  27. package/lib/query-engine/index.d.ts +1 -0
  28. package/lib/query-engine/model-scope.js +2 -2
  29. package/lib/query-engine/query-engine-base.js +2 -2
  30. package/lib/query-engine/query-engine.d.ts +144 -0
  31. package/lib/query-engine/query-engine.js +4 -0
  32. package/lib/types/concrete/bigint-type.d.ts +16 -0
  33. package/lib/types/concrete/bigint-type.js +8 -5
  34. package/lib/types/concrete/blob-type.d.ts +11 -0
  35. package/lib/types/concrete/blob-type.js +5 -4
  36. package/lib/types/concrete/boolean-type.d.ts +11 -0
  37. package/lib/types/concrete/boolean-type.js +4 -4
  38. package/lib/types/concrete/char-type.d.ts +11 -0
  39. package/lib/types/concrete/char-type.js +4 -4
  40. package/lib/types/concrete/date-type.d.ts +16 -0
  41. package/lib/types/concrete/date-type.js +9 -4
  42. package/lib/types/concrete/datetime-type.d.ts +16 -0
  43. package/lib/types/concrete/datetime-type.js +9 -4
  44. package/lib/types/concrete/foreign-key-type.d.ts +32 -0
  45. package/lib/types/concrete/foreign-key-type.js +274 -10
  46. package/lib/types/concrete/index.d.ts +19 -0
  47. package/lib/types/concrete/index.js +2 -0
  48. package/lib/types/concrete/integer-type.d.ts +16 -0
  49. package/lib/types/concrete/integer-type.js +6 -4
  50. package/lib/types/concrete/numeric-type.d.ts +11 -0
  51. package/lib/types/concrete/numeric-type.js +6 -4
  52. package/lib/types/concrete/real-type.d.ts +11 -0
  53. package/lib/types/concrete/real-type.js +111 -4
  54. package/lib/types/concrete/serialized-type.d.ts +25 -0
  55. package/lib/types/concrete/serialized-type.js +287 -5
  56. package/lib/types/concrete/string-type.d.ts +11 -0
  57. package/lib/types/concrete/string-type.js +0 -4
  58. package/lib/types/concrete/text-type.d.ts +11 -0
  59. package/lib/types/concrete/text-type.js +0 -4
  60. package/lib/types/concrete/uuid-base.d.ts +13 -0
  61. package/lib/types/concrete/uuid-base.js +4 -1
  62. package/lib/types/concrete/uuid-v1-type.d.ts +31 -0
  63. package/lib/types/concrete/uuid-v1-type.js +0 -4
  64. package/lib/types/concrete/uuid-v3-type.d.ts +27 -0
  65. package/lib/types/concrete/uuid-v3-type.js +0 -4
  66. package/lib/types/concrete/uuid-v4-type.d.ts +27 -0
  67. package/lib/types/concrete/uuid-v4-type.js +0 -4
  68. package/lib/types/concrete/uuid-v5-type.d.ts +27 -0
  69. package/lib/types/concrete/uuid-v5-type.js +0 -4
  70. package/lib/types/concrete/xid-type.d.ts +17 -0
  71. package/lib/types/concrete/xid-type.js +0 -4
  72. package/lib/types/helpers/default-helpers.d.ts +61 -0
  73. package/lib/types/helpers/index.d.ts +1 -0
  74. package/lib/types/index.d.ts +6 -0
  75. package/lib/types/index.js +2 -0
  76. package/lib/types/type.d.ts +89 -0
  77. package/lib/types/type.js +57 -25
  78. package/lib/types/virtual/index.d.ts +4 -0
  79. package/lib/types/virtual/model-type.d.ts +15 -0
  80. package/lib/types/virtual/model-type.js +2 -2
  81. package/lib/types/virtual/models-type.d.ts +15 -0
  82. package/lib/types/virtual/models-type.js +5 -5
  83. package/lib/types/virtual/relational-type-base.d.ts +46 -0
  84. package/lib/types/virtual/relational-type-base.js +12 -20
  85. package/lib/utils/index.d.ts +6 -0
  86. package/lib/utils/index.js +1 -4
  87. package/lib/utils/misc-utils.d.ts +4 -0
  88. package/lib/utils/misc-utils.js +0 -35
  89. package/lib/utils/model-utils.d.ts +90 -0
  90. package/lib/utils/model-utils.js +4 -4
  91. package/lib/utils/query-utils.d.ts +11 -0
  92. package/package.json +8 -7
  93. package/.biblorc.js +0 -29
  94. package/docs/Associations.md +0 -539
  95. package/docs/Certifications.md +0 -22
  96. package/docs/Home.md +0 -54
  97. package/docs/Query Engine.md +0 -428
package/lib/model.js CHANGED
@@ -39,7 +39,7 @@ class CacheKey {
39
39
 
40
40
  function bindStaticWhereToModelClass(ModelClass) {
41
41
  const whereProp = {
42
- enumberable: true,
42
+ enumerable: true,
43
43
  configurable: true,
44
44
  set: function() {},
45
45
  get: function() {
@@ -122,6 +122,7 @@ function bindStaticWhereToModelClass(ModelClass) {
122
122
  /// and instance version. We are only listing the `static`
123
123
  /// versions because the instance versions generally will
124
124
  /// just be proxies to these `static` methods.
125
+ ///
125
126
  /// Note:
126
127
  /// An underscore prefix on a method in Mythix ORM
127
128
  /// implies that this method should not be overloaded
@@ -142,6 +143,7 @@ class Model {
142
143
  /// named `_isMythixModel` that is truthy.
143
144
  ///
144
145
  /// Return: boolean
146
+ ///
145
147
  /// Arguments:
146
148
  /// value: Function
147
149
  /// Value to check.
@@ -170,6 +172,7 @@ class Model {
170
172
  /// (`value.constructor._isMythixModel`)
171
173
  ///
172
174
  /// Return: boolean
175
+ ///
173
176
  /// Arguments:
174
177
  /// value: any
175
178
  /// Value to check
@@ -195,6 +198,7 @@ class Model {
195
198
  /// name alone will be returned as a string.
196
199
  ///
197
200
  /// Return: string
201
+ ///
198
202
  /// Arguments:
199
203
  /// showFields?: boolean
200
204
  /// If `true`, then list the models fields.
@@ -229,6 +233,7 @@ class Model {
229
233
  /// be found).
230
234
  ///
231
235
  /// Return: <see>Connection</see>
236
+ ///
232
237
  /// Arguments:
233
238
  /// connection?: <see>Connection</see>
234
239
  /// An optional connection that can be provided.
@@ -243,6 +248,7 @@ class Model {
243
248
  /// See <see>Model.static _getConnection</see>
244
249
  ///
245
250
  /// Return: <see>Connection</see>
251
+ ///
246
252
  /// Arguments:
247
253
  /// connection?: <see>Connection</see>
248
254
  /// An optional connection that can be provided.
@@ -252,6 +258,7 @@ class Model {
252
258
  /// if that also fails to find a connection, the finally
253
259
  /// the method will call <see>Model.static _getConnection</see>
254
260
  /// to get the bound connection, if any is available.
261
+ ///
255
262
  /// Note:
256
263
  /// Pay attention that unlike <see>Model.static _getConnection</see>
257
264
  /// this checks the model's instance for `._connection` property. If that is
@@ -283,6 +290,7 @@ class Model {
283
290
  /// connection.
284
291
  ///
285
292
  /// Return: <see>Connection</see>
293
+ ///
286
294
  /// Arguments:
287
295
  /// connection?: <see>Connection</see>
288
296
  /// An optional connection that can be provided.
@@ -320,6 +328,7 @@ class Model {
320
328
  /// a new class that inherited from `this` class.
321
329
  ///
322
330
  /// Return: class extends <see>Model</see>
331
+ ///
323
332
  /// Arguments:
324
333
  /// connection?: <see>Connection</see>
325
334
  /// The connection instance to bind to
@@ -349,7 +358,7 @@ class Model {
349
358
  }
350
359
 
351
360
  const whereProp = {
352
- enumberable: false,
361
+ enumerable: false,
353
362
  configurable: true,
354
363
  get: () => {
355
364
  return ModelClass.getQueryEngine(connection);
@@ -360,7 +369,7 @@ class Model {
360
369
  Object.defineProperties(ModelClass, {
361
370
  '_mythixBoundConnection': {
362
371
  writable: true,
363
- enumberable: false,
372
+ enumerable: false,
364
373
  configurable: true,
365
374
  value: connection,
366
375
  },
@@ -382,6 +391,7 @@ class Model {
382
391
  /// generally be supplied by the connection.
383
392
  ///
384
393
  /// Return: class <see>QueryEngine</see>
394
+ ///
385
395
  /// Arguments:
386
396
  /// connection?: <see>Connection</see>
387
397
  /// An optional connection to pass through.
@@ -402,6 +412,7 @@ class Model {
402
412
  /// so make sure you always call it first: `Model.where.unscoped()...`
403
413
  ///
404
414
  /// Return: <see>QueryEngine</see>
415
+ ///
405
416
  /// Arguments:
406
417
  /// connection?: <see>Connection</see>
407
418
  /// An optional connection to pass through.
@@ -454,7 +465,9 @@ class Model {
454
465
  /// return baseQuery.active.EQ(true);
455
466
  /// }
456
467
  /// }
468
+ ///
457
469
  /// Return: <see>QueryEngine</see>
470
+ ///
458
471
  /// Arguments:
459
472
  /// query: <see>QueryEngine</see>
460
473
  /// The query that you should add onto.
@@ -476,6 +489,7 @@ class Model {
476
489
  /// the query to the user to start interacting with.
477
490
  ///
478
491
  /// Return: <see>QueryEngine</see>
492
+ ///
479
493
  /// Arguments:
480
494
  /// connection?: <see>Connection</see>
481
495
  /// An optional connection to pass through.
@@ -499,6 +513,7 @@ class Model {
499
513
  ///
500
514
  /// Return: Map<string, array<object>>
501
515
  /// The format is `Map[modelName] = [ { targetFieldName, sourceFieldName }, ... ]`
516
+ ///
502
517
  /// Arguments:
503
518
  /// connection?: <see>Connection</see>
504
519
  /// An optional connection to pass through.
@@ -544,6 +559,7 @@ class Model {
544
559
  ///
545
560
  /// Return: Map<string, Model>
546
561
  /// The format is `Map[modelName] = Model`
562
+ ///
547
563
  /// Arguments:
548
564
  /// connection?: <see>Connection</see>
549
565
  /// An optional connection to pass through.
@@ -583,6 +599,7 @@ class Model {
583
599
  ///
584
600
  /// Return: Array<string>
585
601
  /// The format is `Array[] = modelName`
602
+ ///
586
603
  /// Arguments:
587
604
  /// connection?: <see>Connection</see>
588
605
  /// An optional connection to pass through.
@@ -606,12 +623,13 @@ class Model {
606
623
  return this.constructor.getForeignKeysTargetModelNames(connection);
607
624
  }
608
625
 
609
- /// Return all the foreign key target field names.
610
- /// This will return the target field names of all
626
+ /// Return all the foreign key target fields.
627
+ /// This will return the target fields of all
611
628
  /// foreign key fields specified on the model.
612
629
  ///
613
630
  /// Return: Array<string>
614
- /// The format is `Array[] = modelName`
631
+ /// An array of all foreign key field info `Array<{ targetFieldName: string, sourceFieldName: string }>`
632
+ ///
615
633
  /// Arguments:
616
634
  /// connection?: <see>Connection</see>
617
635
  /// An optional connection to pass through.
@@ -648,6 +666,7 @@ class Model {
648
666
  /// Return: object<{ targetFieldName, sourceFieldName }>
649
667
  /// This will be the relationship info for this foreign key field
650
668
  /// which will be an object of the shape `{ targetFieldName, sourceFieldName }`.
669
+ ///
651
670
  /// Arguments:
652
671
  /// connection?: <see>Connection</see>
653
672
  /// An optional connection to pass through.
@@ -688,6 +707,7 @@ class Model {
688
707
  /// Return: boolean
689
708
  /// `true` if the specified `modelName` model is pointed
690
709
  /// to by one of the foreign key fields, `false` otherwise.
710
+ ///
691
711
  /// Arguments:
692
712
  /// connection?: <see>Connection</see>
693
713
  /// An optional connection to pass through.
@@ -712,6 +732,7 @@ class Model {
712
732
  ///
713
733
  /// Return: string
714
734
  /// The name of the table for this model.
735
+ ///
715
736
  /// Arguments:
716
737
  /// connection?: <see>Connection</see>
717
738
  /// An optional connection to pass through.
@@ -762,12 +783,16 @@ class Model {
762
783
  /// Note:
763
784
  /// This will return the "singular" name of the model
764
785
  /// which is the same as <see>Model.static getModelName</see>.
786
+ ///
765
787
  /// Note:
766
788
  /// This method simply calls <see>Model.static getModelName</see>
767
789
  /// to get the singular model name.
790
+ ///
768
791
  /// Return: string
769
792
  /// The name the model in singular form.
793
+ ///
770
794
  /// See: Model.static getPluralModelName
795
+ ///
771
796
  /// See: Model.static getModelName
772
797
  static getSingularName() {
773
798
  return this.getModelName();
@@ -785,8 +810,10 @@ class Model {
785
810
  ///
786
811
  /// Note:
787
812
  /// This will return the "plural" name of the model.
813
+ ///
788
814
  /// Return: string
789
815
  /// The name the model in plural form.
816
+ ///
790
817
  /// See: Model.static getSingularName
791
818
  static getPluralModelName() {
792
819
  return Inflection.pluralize(this.getSingularName());
@@ -799,12 +826,23 @@ class Model {
799
826
  /// Get the Model class for this model.
800
827
  ///
801
828
  /// Return: class <see>Model</see>
802
- static getModel() {
829
+ static getModel(modelName) {
830
+ if (modelName) {
831
+ if (modelName === this.getModelName())
832
+ return this;
833
+
834
+ let connection = this.getConnection();
835
+ if (!connection)
836
+ return;
837
+
838
+ return connection.getModel(modelName);
839
+ }
840
+
803
841
  return this;
804
842
  }
805
843
 
806
- getModel() {
807
- return this.constructor.getModel();
844
+ getModel(modelName) {
845
+ return this.constructor.getModel(modelName);
808
846
  }
809
847
 
810
848
  /// Get the fields for this model. You can optionally
@@ -826,12 +864,15 @@ class Model {
826
864
  /// `columnName`. A model's fields are always initialized when
827
865
  /// the model is first bound to a connection, or when this method
828
866
  /// is first called.
867
+ ///
829
868
  /// Note:
830
869
  /// In Mythix ORM you **never** specify a field via its `columnName`.
831
870
  /// You always use a field's defined `fieldName` to match against
832
871
  /// a field. Using a `columnName` simply won't work, unless `columnName`
833
872
  /// and `fieldName` just happen to have the same value.
873
+ ///
834
874
  /// Return: Array<<see>Field</see>> | Object<string, <see>Field</see>>
875
+ ///
835
876
  /// Arguments:
836
877
  /// fieldNames?: Array<string>
837
878
  /// An array of field names to fetch. If not
@@ -843,13 +884,13 @@ class Model {
843
884
  Object.defineProperties(this, {
844
885
  'fields': {
845
886
  writable: true,
846
- enumberable: true,
887
+ enumerable: true,
847
888
  configurable: true,
848
889
  value: fields,
849
890
  },
850
891
  '_sortedFields': {
851
892
  writable: true,
852
- enumberable: true,
893
+ enumerable: true,
853
894
  configurable: true,
854
895
  value: null,
855
896
  },
@@ -885,7 +926,9 @@ class Model {
885
926
  /// You always use a field's defined `fieldName` to match against
886
927
  /// a field. Using a `columnName` simply won't work, unless `columnName`
887
928
  /// and `fieldName` just happen to have the same value.
929
+ ///
888
930
  /// Return: Array<<see>Field</see>>
931
+ ///
889
932
  /// Arguments:
890
933
  /// fieldNames?: Array<string>
891
934
  /// An array of field names to fetch. If not
@@ -951,7 +994,9 @@ class Model {
951
994
  /// you can also simply provide a raw object with the same shape, and
952
995
  /// it will be automatically converted to a <see>Field</see> instance
953
996
  /// for you.
997
+ ///
954
998
  /// Return: Array<<see>Field</see>> | object<string, <see>Field</see>>
999
+ ///
955
1000
  /// Arguments:
956
1001
  /// mergeFields?: Array<<see>Field</see>> | Set<<see>Field</see>> | Object<string, <see>Field</see>> | Map<string, <see>Field</see>>
957
1002
  /// A list of fields to merge into the current
@@ -1026,7 +1071,9 @@ class Model {
1026
1071
  /// Note:
1027
1072
  /// The cache for built fields is stored directly on the input `fields`
1028
1073
  /// argument, under a non-enumerable `_mythixFieldsInitialized` cache key.
1074
+ ///
1029
1075
  /// Return: Array<<see>Field</see>> | object<string, <see>Field</see>>
1076
+ ///
1030
1077
  /// Arguments:
1031
1078
  /// fields: Array<<see>Field</see>> | Set<<see>Field</see>> | Object<string, <see>Field</see>> | Map<string, <see>Field</see>>
1032
1079
  /// A list of fields to work off of. When this method is
@@ -1090,13 +1137,13 @@ class Model {
1090
1137
  Object.defineProperties(finalizedFields, {
1091
1138
  '_mythixFieldsInitialized': {
1092
1139
  writable: true,
1093
- enumberable: false,
1140
+ enumerable: false,
1094
1141
  configurable: true,
1095
1142
  value: true,
1096
1143
  },
1097
1144
  '_primaryKeyField': {
1098
1145
  writable: true,
1099
- enumberable: false,
1146
+ enumerable: false,
1100
1147
  configurable: true,
1101
1148
  value: primaryKeyField,
1102
1149
  },
@@ -1135,6 +1182,7 @@ class Model {
1135
1182
  /// }
1136
1183
  ///
1137
1184
  /// Return: Array<any>
1185
+ ///
1138
1186
  /// Arguments:
1139
1187
  /// callback: Function(context: IterationContext)
1140
1188
  /// A callback method that will be called for
@@ -1265,7 +1313,9 @@ class Model {
1265
1313
  /// You always use a field's defined `fieldName` to match against
1266
1314
  /// a field. Using a `columnName` simply won't work, unless `columnName`
1267
1315
  /// and `fieldName` just happen to have the same value.
1316
+ ///
1268
1317
  /// Return: <see>Field</see>
1318
+ ///
1269
1319
  /// Arguments:
1270
1320
  /// fieldName: string
1271
1321
  /// The specified field name to find. This **is not** the `columnName` of the field.
@@ -1299,7 +1349,9 @@ class Model {
1299
1349
  /// You always use a field's defined `fieldName` to match against
1300
1350
  /// a field. Using a `columnName` simply won't work, unless `columnName`
1301
1351
  /// and `fieldName` just happen to have the same value.
1352
+ ///
1302
1353
  /// Return: boolean
1354
+ ///
1303
1355
  /// Arguments:
1304
1356
  /// fieldName: string
1305
1357
  /// The specified field name to find. This **is not** the `columnName` of the field.
@@ -1346,6 +1398,7 @@ class Model {
1346
1398
  /// Internally, Mythix ORM will call `this.connection.defaultOrder(options)`,
1347
1399
  /// which--if not overloaded--will simply call this method from the
1348
1400
  /// model itself.
1401
+ ///
1349
1402
  /// Note:
1350
1403
  /// A "fully qualified field name" in Mythix ORM means
1351
1404
  /// a full field definition, including the model name.
@@ -1355,6 +1408,7 @@ class Model {
1355
1408
  /// field name* example would be simply `"id"`. Since this
1356
1409
  /// contains no model prefix, this is "short hand", and is
1357
1410
  /// **not** a fully qualified field name.
1411
+ ///
1358
1412
  /// Return: Array<string> | null
1359
1413
  /// An array of fully qualified field names to specify the ORDER.
1360
1414
  /// Prefix a field name with `+` to specify ASCending order, i.e.
@@ -1373,6 +1427,7 @@ class Model {
1373
1427
  /// Return: <see>QueryEngine</see>
1374
1428
  /// A <see>QueryEngine</see> instance (a query) for
1375
1429
  /// this model.
1430
+ ///
1376
1431
  /// Arguments:
1377
1432
  /// options?: `object { connection: Connection }`
1378
1433
  /// An object, which if supplied, should contain a
@@ -1401,6 +1456,7 @@ class Model {
1401
1456
  ///
1402
1457
  /// Return: <see>Model</see>
1403
1458
  /// Return the model instance(s) created.
1459
+ ///
1404
1460
  /// Arguments:
1405
1461
  /// models: Array<<see>Model</see>> | <see>Model</see> | Array<object> | object
1406
1462
  /// Specify the model(s) to create.
@@ -1426,6 +1482,7 @@ class Model {
1426
1482
  ///
1427
1483
  /// Return: number
1428
1484
  /// Return the number of models stored in the database for this model type.
1485
+ ///
1429
1486
  /// Arguments:
1430
1487
  /// options?: object
1431
1488
  /// An "options" object to pass off to the underlying <see>Connection</see> methods.
@@ -1443,8 +1500,10 @@ class Model {
1443
1500
  /// This will fetch ALL rows for the model. If this is not what you want,
1444
1501
  /// then construct a query first, and call `all` from the query itself, i.e.
1445
1502
  /// `User.where.firstName.EQ('Bob').all(options)`.
1503
+ ///
1446
1504
  /// Return: Array<<see>Model</see>>
1447
1505
  /// Return all models of this type from the database.
1506
+ ///
1448
1507
  /// Arguments:
1449
1508
  /// options?: object
1450
1509
  /// An "options" object to pass off to the underlying <see>Connection</see> methods.
@@ -1463,6 +1522,10 @@ class Model {
1463
1522
  return this.getWhereWithConnection(options).all(options);
1464
1523
  }
1465
1524
 
1525
+ static fetchAll(options) {
1526
+ return this.all({ ...(options || {}), stream: true });
1527
+ }
1528
+
1466
1529
  /// Get the first (limit) rows from the database for this model type.
1467
1530
  ///
1468
1531
  /// Note:
@@ -1470,6 +1533,7 @@ class Model {
1470
1533
  /// If you wish to filter, and specify the order, then construct a
1471
1534
  /// query first, and call the `first` method from the query itself, i.e.
1472
1535
  /// `User.where.firstName.EQ('Bob').ORDER('+User:firstName').first(options)`
1536
+ ///
1473
1537
  /// Return: <see>Model</see> | Array<<see>Model</see>>
1474
1538
  /// Return `limit` models of this type from the database. If
1475
1539
  /// `limit` is `null`, `undefined`, or `1`, then a single model
@@ -1477,6 +1541,7 @@ class Model {
1477
1541
  /// If the `limit` argument is more than `1`, then an array
1478
1542
  /// of model instances will be returned, or an empty array if
1479
1543
  /// nothing is found.
1544
+ ///
1480
1545
  /// Arguments:
1481
1546
  /// limit?: number = 1
1482
1547
  /// The number of model instances to fetch from the database.
@@ -1500,10 +1565,12 @@ class Model {
1500
1565
  /// If you wish to filter, and specify the order, then construct a
1501
1566
  /// query first, and call the `last` method from the query itself, i.e.
1502
1567
  /// `User.where.firstName.EQ('Bob').ORDER('+User:firstName').last(options)`
1568
+ ///
1503
1569
  /// Note:
1504
1570
  /// This works by telling the underlying query generator to invert
1505
1571
  /// the specified ORDER of the query, and then it selects the first
1506
1572
  /// `limit` rows from the result.
1573
+ ///
1507
1574
  /// Return: <see>Model</see> | Array<<see>Model</see>>
1508
1575
  /// Return `limit` models of this type from the database. If
1509
1576
  /// `limit` is `null`, `undefined`, or `1`, then a single model
@@ -1511,6 +1578,7 @@ class Model {
1511
1578
  /// If the `limit` argument is more than `1`, then an array
1512
1579
  /// of model instances will be returned, or an empty array if
1513
1580
  /// nothing is found.
1581
+ ///
1514
1582
  /// Arguments:
1515
1583
  /// limit?: number = 1
1516
1584
  /// The number of model instances to fetch from the database.
@@ -1534,16 +1602,19 @@ class Model {
1534
1602
  /// If you wish to filter and limit, and specify the order, then construct a
1535
1603
  /// query first, and call the `pluck` method from the query itself, i.e.
1536
1604
  /// `User.where.firstName.EQ('Bob').LIMIT(50).ORDER('+User:firstName').pluck([ 'User:firstName' ], options)`
1605
+ ///
1537
1606
  /// Note:
1538
1607
  /// In Mythix ORM you **never** specify a field via its `columnName`.
1539
1608
  /// You always use a field's defined `fieldName` to match against
1540
1609
  /// a field. Using a `columnName` simply won't work, unless `columnName`
1541
1610
  /// and `fieldName` just happen to have the same value.
1611
+ ///
1542
1612
  /// Return: Array<any> | Array<Array<any>>
1543
1613
  /// If only a single field is specified, then a flat array
1544
1614
  /// of values will be returned across all rows. If more than
1545
1615
  /// one field is specified, then an array of arrays (rows) will
1546
1616
  /// be returned for the fields specified.
1617
+ ///
1547
1618
  /// Arguments:
1548
1619
  /// fields?: Array<string>
1549
1620
  /// An array of fully qualified field names to pluck from the underlying
@@ -1562,6 +1633,7 @@ class Model {
1562
1633
  /// Construct a new <see>Model</see> instance.
1563
1634
  ///
1564
1635
  /// Return: <see>Model</see>
1636
+ ///
1565
1637
  /// Arguments:
1566
1638
  /// data?: object
1567
1639
  /// Attributes to provide to the new model instance.
@@ -1597,7 +1669,7 @@ class Model {
1597
1669
  let options = _options || {};
1598
1670
 
1599
1671
  const whereProp = {
1600
- enumberable: false,
1672
+ enumerable: false,
1601
1673
  configurable: true,
1602
1674
  get: () => {
1603
1675
  return this.constructor.where(this._getConnection());
@@ -1608,66 +1680,66 @@ class Model {
1608
1680
  Object.defineProperties(this, {
1609
1681
  '_options': {
1610
1682
  writable: true,
1611
- enumberable: false,
1683
+ enumerable: false,
1612
1684
  configurable: true,
1613
1685
  value: options,
1614
1686
  },
1615
1687
  '_mythixModelInstance': {
1616
1688
  writable: false,
1617
- enumberable: false,
1689
+ enumerable: false,
1618
1690
  configurable: false,
1619
1691
  value: true,
1620
1692
  },
1621
1693
  '_connection': {
1622
1694
  writable: false,
1623
- enumberable: false,
1695
+ enumerable: false,
1624
1696
  configurable: false,
1625
1697
  value: this._getConnection(options.connection),
1626
1698
  },
1627
1699
  '_fieldData': {
1628
1700
  writable: true,
1629
- enumberable: false,
1701
+ enumerable: false,
1630
1702
  configurable: true,
1631
1703
  value: {},
1632
1704
  },
1633
1705
  '_dirtyFieldData': {
1634
1706
  writable: true,
1635
- enumberable: false,
1707
+ enumerable: false,
1636
1708
  configurable: true,
1637
1709
  value: {},
1638
1710
  },
1639
1711
  '_typeData': {
1640
1712
  writable: true,
1641
- enumberable: false,
1713
+ enumerable: false,
1642
1714
  configurable: true,
1643
1715
  value: {},
1644
1716
  },
1645
- 'dirtyID': {
1717
+ '_dirtyID': {
1646
1718
  writable: true,
1647
- enumberable: false,
1719
+ enumerable: false,
1648
1720
  configurable: true,
1649
1721
  value: new CacheKey(),
1650
1722
  },
1651
1723
  '_persisted': {
1652
1724
  writable: true,
1653
- enumberable: false,
1725
+ enumerable: false,
1654
1726
  configurable: true,
1655
1727
  value: false,
1656
1728
  },
1657
1729
  '__order': {
1658
1730
  writable: true,
1659
- enumberable: false,
1731
+ enumerable: false,
1660
1732
  configurable: true,
1661
1733
  value: 0,
1662
1734
  },
1663
1735
  '__assignedRelatedModels': {
1664
1736
  writable: true,
1665
- enumberable: false,
1737
+ enumerable: false,
1666
1738
  configurable: true,
1667
1739
  value: new Map(),
1668
1740
  },
1669
1741
  'changes': {
1670
- enumberable: false,
1742
+ enumerable: false,
1671
1743
  configurable: true,
1672
1744
  get: () => {
1673
1745
  return this._getDirtyFields();
@@ -1701,6 +1773,7 @@ class Model {
1701
1773
  /// the field values for the model.
1702
1774
  ///
1703
1775
  /// Return: `undefined`
1776
+ ///
1704
1777
  /// Arguments:
1705
1778
  /// data?: object
1706
1779
  /// Attributes provided to the model through
@@ -1743,7 +1816,7 @@ class Model {
1743
1816
  _constructField(fieldName, field) {
1744
1817
  Object.defineProperties(this, {
1745
1818
  [fieldName]: {
1746
- enumberable: false,
1819
+ enumerable: false,
1747
1820
  configurable: true,
1748
1821
  get: () => {
1749
1822
  return this._getFieldValue(fieldName, field);
@@ -1772,15 +1845,18 @@ class Model {
1772
1845
  /// Note:
1773
1846
  /// All fields have already been constructed before this
1774
1847
  /// method is called via <see>Model._constructFields</see>.
1848
+ ///
1775
1849
  /// Note:
1776
1850
  /// Virtual fields are not constructed against the model instance,
1777
1851
  /// however, field types *can* modify the instance, and some do.
1778
1852
  /// For example, the `Types.Model` and `Types.Models` virtual field
1779
1853
  /// types inject relational methods on the model.
1854
+ ///
1780
1855
  /// Note:
1781
1856
  /// Only concrete fields are considered "attributes" of the model,
1782
1857
  /// and can have an initial value provided via the `data` argument
1783
1858
  /// to the constructor, or via a `defaultValue` property on the field.
1859
+ ///
1784
1860
  /// Arguments:
1785
1861
  /// data?: object
1786
1862
  /// Attributes values for fields. Can be nothing, in which case
@@ -1820,6 +1896,7 @@ class Model {
1820
1896
  ///
1821
1897
  /// Return: any
1822
1898
  /// The value provided, cast to the type of the field.
1899
+ ///
1823
1900
  /// Arguments:
1824
1901
  /// field: <see>Field</see>
1825
1902
  /// The field to use to cast the value. The `type` property
@@ -2004,7 +2081,9 @@ class Model {
2004
2081
  /// the `update` or `insert` "options", then the default value
2005
2082
  /// for the field will be fetched via the <see>QueryGenerator.getFieldDefaultValue</see>
2006
2083
  /// method through the provided `connection`.
2084
+ ///
2007
2085
  /// Return: DirtyFieldChangeList
2086
+ ///
2008
2087
  /// Arguments:
2009
2088
  /// options?: DirtyFieldOptions
2010
2089
  /// Options to provide to the method.
@@ -2049,7 +2128,7 @@ class Model {
2049
2128
 
2050
2129
  // Does the connection dirtyFieldHelper report that we are
2051
2130
  // dirty?
2052
- if (connection && typeof connection.dirtyFieldHelper === 'function') {
2131
+ if (connection) {
2053
2132
  let value = connection.dirtyFieldHelper({ options, fieldData, dirtyFieldData, dirtyFields, field, fieldName });
2054
2133
  if (value !== undefined) {
2055
2134
  // Cache this result so subsequent calls
@@ -2112,12 +2191,15 @@ class Model {
2112
2191
  /// inside a field's `get` method. If you do, you will enter an
2113
2192
  /// infinite recursive loop. Instead, call the provided `get`
2114
2193
  /// method (as provided by the context), or call <see>Model.getDataValue</see>.
2194
+ ///
2115
2195
  /// Return: any
2196
+ ///
2116
2197
  /// Arguments:
2117
2198
  /// fieldName: string
2118
2199
  /// The name of the field whose value we wish to get.
2119
2200
  /// field: <see>Field</see>
2120
2201
  /// The field definition itself for the value we wish to get.
2202
+ ///
2121
2203
  /// See: Field
2122
2204
  _getFieldValue(fieldName, field) {
2123
2205
  let value = this.getDataValue(fieldName);
@@ -2151,17 +2233,21 @@ class Model {
2151
2233
  /// Note:
2152
2234
  /// This method will mark the field as dirty if the value provided
2153
2235
  /// differs from the current value the field has.
2236
+ ///
2154
2237
  /// Note:
2155
2238
  /// Never call this method (or set the model attribute by name), while
2156
2239
  /// inside a field's `set` method. If you do, you will enter an
2157
2240
  /// infinite recursive loop. Instead, call the provided `set`
2158
2241
  /// method (as provided by the context), or call <see>Model.setDataValue</see>.
2242
+ ///
2159
2243
  /// Return: undefined
2244
+ ///
2160
2245
  /// Arguments:
2161
2246
  /// fieldName: string
2162
2247
  /// The name of the field whose value we wish to get.
2163
2248
  /// field: <see>Field</see>
2164
2249
  /// The field definition itself for the value we wish to get.
2250
+ ///
2165
2251
  /// See: Field
2166
2252
  _setFieldValue(fieldName, field, value) {
2167
2253
  if (typeof field.set === 'function') {
@@ -2193,9 +2279,9 @@ class Model {
2193
2279
  return this._persisted;
2194
2280
  }
2195
2281
 
2196
- /// Update the `this.dirtyID` cache key of the model.
2282
+ /// Update the `this._dirtyID` cache key of the model.
2197
2283
  /// This is called any time a field is marked as "dirty" on the model.
2198
- /// The `dirtyID` property of a model is an instance of
2284
+ /// The `_dirtyID` property of a model is an instance of
2199
2285
  /// a <see>CacheKey</see> that is intended to be used for
2200
2286
  /// caching systems. The <see>CacheKey</see> instance can
2201
2287
  /// be used for a key into a WeakMap, which can cache things.
@@ -2204,7 +2290,7 @@ class Model {
2204
2290
  /// any cache for this model will be invalidated as soon
2205
2291
  /// as any field on the model is dirty.
2206
2292
  updateDirtyID() {
2207
- this.dirtyID = new CacheKey(this.dirtyID);
2293
+ this._dirtyID = new CacheKey(this._dirtyID);
2208
2294
  }
2209
2295
 
2210
2296
  /// Check if the model is dirty or not.
@@ -2215,6 +2301,7 @@ class Model {
2215
2301
  /// one or more fields are marked as "dirty".
2216
2302
  ///
2217
2303
  /// Return: boolean
2304
+ ///
2218
2305
  /// Arguments:
2219
2306
  /// fieldName?: string
2220
2307
  /// If provided, check if this one field is dirty. If not
@@ -2254,6 +2341,7 @@ class Model {
2254
2341
  /// the field.
2255
2342
  ///
2256
2343
  /// Return: boolean
2344
+ ///
2257
2345
  /// Arguments:
2258
2346
  /// fieldName?: string
2259
2347
  /// If specified, clear only this field's "dirty" status.
@@ -2283,6 +2371,7 @@ class Model {
2283
2371
  ///
2284
2372
  /// Return: Array<<see>Field</see>>
2285
2373
  /// The dirty fields of the model.
2374
+ ///
2286
2375
  /// Arguments:
2287
2376
  /// options?: object
2288
2377
  /// If provided, this will be the "options" supplied to
@@ -2309,6 +2398,7 @@ class Model {
2309
2398
  /// from the underlying `this._fieldData` storage area for field values.
2310
2399
  ///
2311
2400
  /// Return: any
2401
+ ///
2312
2402
  /// Arguments:
2313
2403
  /// fieldName: string
2314
2404
  /// The name of the field whose value you wish to fetch.
@@ -2343,7 +2433,9 @@ class Model {
2343
2433
  /// Note:
2344
2434
  /// This method will always call <see>Model.updateDirtyID</see>,
2345
2435
  /// invalidating all down-stream cache for this model instance.
2436
+ ///
2346
2437
  /// Return: undefined
2438
+ ///
2347
2439
  /// Arguments:
2348
2440
  /// fieldName: string
2349
2441
  /// The name of the field whose value you wish to set.
@@ -2403,6 +2495,7 @@ class Model {
2403
2495
  /// Note:
2404
2496
  /// Field's with `undefined` values will not be included in the
2405
2497
  /// resulting object.
2498
+ ///
2406
2499
  /// Return: object
2407
2500
  /// All models attributes (field values).
2408
2501
  getAttributes() {
@@ -2434,13 +2527,16 @@ class Model {
2434
2527
  /// Note:
2435
2528
  /// Any `undefined` value in the provided object will be
2436
2529
  /// ignored, and no update will occur for the field.
2530
+ ///
2437
2531
  /// Note:
2438
2532
  /// If a raw object instead of a model instance is provided,
2439
2533
  /// then `hasOwnProperty` is called for each field name,
2440
2534
  /// and if the provided object doesn't contain its "own"
2441
2535
  /// property matching the field name, the field will be
2442
2536
  /// silently skipped, and not set.
2537
+ ///
2443
2538
  /// Return: undefined
2539
+ ///
2444
2540
  /// Arguments:
2445
2541
  /// attributes: object | Model
2446
2542
  /// The attributes to set on the model. The keys
@@ -2534,12 +2630,14 @@ class Model {
2534
2630
  /// anything else. You must provide the implementation of each
2535
2631
  /// `validate` method directly yourself (which could for example
2536
2632
  /// use a RegExp to check the field's value).
2633
+ ///
2537
2634
  /// Return: Array<any>
2538
2635
  /// Results of each `validate` call from each field. Will generally
2539
2636
  /// be `undefined` for each call. The validation for a field will
2540
2637
  /// only fail if an exception is thrown. `false` or `null` as a
2541
2638
  /// return value from a `validate` call is meaningless
2542
2639
  /// (unless you yourself wish to do something with it).
2640
+ ///
2543
2641
  /// Arguments:
2544
2642
  /// context: object
2545
2643
  /// A context object that is provided to all model hooks.
@@ -2775,6 +2873,7 @@ class Model {
2775
2873
  /// error. Errors will be thrown. `false` simply means that
2776
2874
  /// the model had no dirty fields, so it was never sent to
2777
2875
  /// the database.
2876
+ ///
2778
2877
  /// Arguments:
2779
2878
  /// options?: object
2780
2879
  /// Options to pass to the underlying connection
@@ -2833,7 +2932,9 @@ class Model {
2833
2932
  /// A primary key is required on the model for this method
2834
2933
  /// to work. If you don't have a primary key defined, then
2835
2934
  /// you will need to create your own "reload" operation.
2935
+ ///
2836
2936
  /// Return: undefined
2937
+ ///
2837
2938
  /// Arguments:
2838
2939
  /// options?: object
2839
2940
  /// Options to pass to the underlying <see>QueryEngine.first</see>
@@ -2880,8 +2981,10 @@ class Model {
2880
2981
  /// A primary key is required on the model for this method
2881
2982
  /// to work. If you don't have a primary key defined, then
2882
2983
  /// you will need to create your own "destroy" operation.
2984
+ ///
2883
2985
  /// Return: number
2884
2986
  /// The number of rows modified in the database.
2987
+ ///
2885
2988
  /// Arguments:
2886
2989
  /// options?: object
2887
2990
  /// Options to pass to the underlying <see>QueryEngine.destroy</see>
@@ -2917,6 +3020,7 @@ class Model {
2917
3020
  ///
2918
3021
  /// Return: object
2919
3022
  /// All model attributes, ready to be serialized.
3023
+ ///
2920
3024
  /// See: Type.serialize
2921
3025
  toJSON() {
2922
3026
  let result = {};
@@ -2956,4 +3060,4 @@ class Model {
2956
3060
 
2957
3061
  bindStaticWhereToModelClass(Model);
2958
3062
 
2959
- module.exports = Model;
3063
+ module.exports = { Model, CacheKey };