mythix-orm 1.5.6 → 1.6.1

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 +3 -2
  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
@@ -0,0 +1,27 @@
1
+ import { DefaultValueProvider } from '../helpers/default-helpers';
2
+ import { TypeWrapper } from '../type';
3
+ import UUIDBaseType from './uuid-base';
4
+
5
+ export declare interface UUIDV3TypeWrapper extends TypeWrapper<UUIDV3Type> {
6
+ (options?: UUIDV3TypeOptions): UUIDV3Type;
7
+ }
8
+
9
+ export declare interface UUIDV3TypeOptions {
10
+ prefix?: string;
11
+ name?: string | Array<number>;
12
+ namespace?: string | Array<number>;
13
+ buffer?: Buffer;
14
+ offset?: number;
15
+ }
16
+
17
+ export declare class UUIDV3Type extends UUIDBaseType {
18
+ declare public static Default: {
19
+ UUIDV3: DefaultValueProvider;
20
+ }
21
+
22
+ constructor(options?: UUIDV3TypeOptions);
23
+ getOptions(): UUIDV3TypeOptions;
24
+ getArgsForUUID(options: UUIDV3TypeOptions): Array<any>;
25
+ }
26
+
27
+ export const UUIDV3: UUIDV3TypeWrapper;
@@ -27,10 +27,6 @@ class UUIDV3Type extends UUIDBaseType {
27
27
  return 'UUIDV3';
28
28
  }
29
29
 
30
- getDisplayName() {
31
- return this.constructor.getDisplayName();
32
- }
33
-
34
30
  getArgsForUUID(options) {
35
31
  let uuidOptions = {};
36
32
 
@@ -0,0 +1,27 @@
1
+ import { DefaultValueProvider } from '../helpers/default-helpers';
2
+ import { TypeWrapper } from '../type';
3
+ import UUIDBaseType from './uuid-base';
4
+
5
+ export declare interface UUIDV4TypeWrapper extends TypeWrapper<UUIDV4Type> {
6
+ (options?: UUIDV4TypeOptions): UUIDV4Type;
7
+ }
8
+
9
+ export declare interface UUIDV4TypeOptions {
10
+ prefix?: string;
11
+ random?: Array<number>;
12
+ rng?: () => Array<number>;
13
+ buffer?: Buffer;
14
+ offset?: number;
15
+ }
16
+
17
+ export declare class UUIDV4Type extends UUIDBaseType {
18
+ declare public static Default: {
19
+ UUIDV4: DefaultValueProvider;
20
+ }
21
+
22
+ constructor(options?: UUIDV4TypeOptions);
23
+ getOptions(): UUIDV4TypeOptions;
24
+ getArgsForUUID(options: UUIDV4TypeOptions): Array<any>;
25
+ }
26
+
27
+ export const UUIDV4: UUIDV4TypeWrapper;
@@ -27,10 +27,6 @@ class UUIDV4Type extends UUIDBaseType {
27
27
  return 'UUIDV4';
28
28
  }
29
29
 
30
- getDisplayName() {
31
- return this.constructor.getDisplayName();
32
- }
33
-
34
30
  getArgsForUUID(options) {
35
31
  let uuidOptions = {};
36
32
 
@@ -0,0 +1,27 @@
1
+ import { DefaultValueProvider } from '../helpers/default-helpers';
2
+ import { TypeWrapper } from '../type';
3
+ import UUIDBaseType from './uuid-base';
4
+
5
+ export declare interface UUIDV5TypeWrapper extends TypeWrapper<UUIDV5Type> {
6
+ (options?: UUIDV5TypeOptions): UUIDV5Type;
7
+ }
8
+
9
+ export declare interface UUIDV5TypeOptions {
10
+ prefix?: string;
11
+ name?: string | Array<number>;
12
+ namespace?: string | Array<number>;
13
+ buffer?: Buffer;
14
+ offset?: number;
15
+ }
16
+
17
+ export declare class UUIDV5Type extends UUIDBaseType {
18
+ declare public static Default: {
19
+ UUIDV5: DefaultValueProvider;
20
+ }
21
+
22
+ constructor(options?: UUIDV5TypeOptions);
23
+ getOptions(): UUIDV5TypeOptions;
24
+ getArgsForUUID(options: UUIDV5TypeOptions): Array<any>;
25
+ }
26
+
27
+ export const UUIDV5: UUIDV5TypeWrapper;
@@ -27,10 +27,6 @@ class UUIDV5Type extends UUIDBaseType {
27
27
  return 'UUIDV5';
28
28
  }
29
29
 
30
- getDisplayName() {
31
- return this.constructor.getDisplayName();
32
- }
33
-
34
30
  getArgsForUUID(options) {
35
31
  let uuidOptions = {};
36
32
 
@@ -0,0 +1,17 @@
1
+ import { DefaultValueProvider } from '../helpers/default-helpers';
2
+ import { TypeWrapper } from '../type';
3
+ import UUIDBaseType from './uuid-base';
4
+
5
+ export declare interface XIDTypeWrapper extends TypeWrapper<XIDType> {
6
+ (): XIDType;
7
+ }
8
+
9
+ export declare class XIDType extends UUIDBaseType {
10
+ declare public static Default: {
11
+ XID: DefaultValueProvider;
12
+ }
13
+
14
+ constructor();
15
+ }
16
+
17
+ export const XID: XIDTypeWrapper;
@@ -20,10 +20,6 @@ class XIDType extends UUIDBaseType {
20
20
  return 'XID';
21
21
  }
22
22
 
23
- getDisplayName() {
24
- return this.constructor.getDisplayName();
25
- }
26
-
27
23
  castToType(args) {
28
24
  let { value } = args;
29
25
  if (value == null)
@@ -0,0 +1,61 @@
1
+ import ConnectionBase from '../../connection/connection-base';
2
+ import Field from '../../field';
3
+ import { GenericObject } from '../../interfaces/common';
4
+ import { Model } from '../../model';
5
+
6
+ export const FLAG_ON_INITIALIZE: number;
7
+ export const FLAG_ON_INSERT: number;
8
+ export const FLAG_ON_UPDATE: number;
9
+ export const FLAG_ON_STORE: number;
10
+ export const FLAG_LITERAL: number;
11
+ export const FLAG_REMOTE: number;
12
+
13
+ export declare interface DefaultValueContext {
14
+ _initial: boolean;
15
+ connection: ConnectionBase;
16
+ data: GenericObject | undefined;
17
+ field: Field;
18
+ fieldName: string;
19
+ fieldValue: any;
20
+ self: Model;
21
+ }
22
+
23
+ export declare interface DefaultValueProvider {
24
+ (context: DefaultValueContext): any;
25
+ mythixFlags: number | undefined;
26
+ }
27
+
28
+ export declare interface DefaultValueFlagsOptions {
29
+ onInitialize: boolean;
30
+ onInsert: boolean;
31
+ onUpdate: boolean;
32
+ onStore: boolean;
33
+ literal: boolean;
34
+ remote: boolean;
35
+ }
36
+
37
+ export declare type DefaultValueFlags = number | 'onInitialize' | 'onInsert' | 'onUpdate' | 'onStore' | 'literal' | 'remote';
38
+
39
+ export declare function defaultValueFlags(func: Function, flagsObj: DefaultValueFlagsOptions): DefaultValueProvider;
40
+ export declare function getDefaultValueFlags(func: Function): number;
41
+ export declare function checkDefaultValueFlags(func: Function, checkFlags: Array<DefaultValueFlags>): boolean;
42
+
43
+ // For AUTOINCREMENT
44
+ export declare interface AutoIncrementDefaultValueProvider extends DefaultValueProvider {
45
+ _mythixIsAutoIncrement: boolean;
46
+ }
47
+
48
+ // For DATETIME_NOW.LOCAL and DATE_NOW.LOCAL
49
+ export declare interface UpdateLocalDefaultValueProvider extends DefaultValueProvider {
50
+ UPDATE: DefaultValueProvider;
51
+ }
52
+
53
+ // For DATETIME_NOW and DATE_NOW
54
+ export declare interface UpdateDefaultValueProvider extends DefaultValueProvider {
55
+ UPDATE: DefaultValueProvider;
56
+ LOCAL: UpdateLocalDefaultValueProvider;
57
+ }
58
+
59
+ export const AUTO_INCREMENT: AutoIncrementDefaultValueProvider;
60
+ export const DATETIME_NOW: UpdateDefaultValueProvider;
61
+ export const DATE_NOW: UpdateDefaultValueProvider;
@@ -0,0 +1 @@
1
+ export * from './default-helpers';
@@ -0,0 +1,6 @@
1
+ export * from './type';
2
+ export { default as Type } from './type';
3
+ export * from './concrete';
4
+ export * from './virtual';
5
+ export * as DefaultHelpers from './helpers';
6
+ export * as Helpers from './helpers';
@@ -24,6 +24,7 @@ const {
24
24
  UUIDV4Type,
25
25
  UUIDV5Type,
26
26
  XIDType,
27
+ UUIDBaseType,
27
28
  BIGINT,
28
29
  BLOB,
29
30
  BOOLEAN,
@@ -75,6 +76,7 @@ module.exports = {
75
76
  UUIDV4Type,
76
77
  UUIDV5Type,
77
78
  XIDType,
79
+ UUIDBaseType,
78
80
  BIGINT,
79
81
  BLOB,
80
82
  BOOLEAN,
@@ -0,0 +1,89 @@
1
+ import ConnectionBase from '../connection/connection-base';
2
+ import Field from '../field';
3
+ import { GenericObject } from '../interfaces/common';
4
+ import { Model, ModelClass } from '../model';
5
+ import { DefaultValueProvider } from './helpers/default-helpers';
6
+
7
+ export declare type TypeClass = typeof Type;
8
+
9
+ export declare interface TypeWrapper<T = Type, P = DefaultValueProvider> {
10
+ (...any: Array<any>): T;
11
+ Default?: { [ key: string ]: P };
12
+ _isMythixFieldType: boolean;
13
+ clone: () => TypeClass;
14
+ isTypeClass: (value: any) => boolean;
15
+ isType: (value: any) => boolean;
16
+ instantiateType: (type: Type | TypeClass) => Type;
17
+ isVirtual: () => boolean;
18
+ isRelational: () => boolean;
19
+ isForeignKey: () => boolean;
20
+ exposeToModel: () => boolean;
21
+ getDisplayName: () => string;
22
+ }
23
+
24
+ export declare interface CastToTypeContext {
25
+ connection: ConnectionBase;
26
+ field: Field;
27
+ Model: ModelClass;
28
+ self: Model;
29
+ value: any;
30
+ }
31
+
32
+ export declare interface CheckDirtyContext {
33
+ value: any;
34
+ field: Field;
35
+ fieldName: string;
36
+ self: Model;
37
+ connection: ConnectionBase;
38
+ }
39
+
40
+ export declare interface SetFieldValueContext {
41
+ value: any;
42
+ field: Field;
43
+ fieldName: string;
44
+ self: Model;
45
+ }
46
+
47
+ declare class Type {
48
+ declare public static _isMythixFieldType: boolean;
49
+ public static clone(): TypeClass;
50
+
51
+ public static getDisplayName(): string;
52
+ public static isTypeClass(value: any): boolean;
53
+ public static isType(value): boolean;
54
+ public static isSameType(value: any): boolean;
55
+ public static instantiateType(type: Type | TypeClass): Type;
56
+ public static isVirtual(): boolean;
57
+ public static isRelational(): boolean;
58
+ public static isForeignKey(): boolean;
59
+ public static exposeToModel(): boolean;
60
+ public static wrapConstructor(TypeKlass: TypeClass): TypeWrapper;
61
+
62
+ declare public _args: Array<any>;
63
+ declare public _Model: ModelClass | undefined;
64
+ declare public _field: Field | undefined;
65
+
66
+ public constructor(...args: Array<any>);
67
+ public clone(): Type;
68
+ public isVirtual(): boolean;
69
+ public isRelational(): boolean;
70
+ public isForeignKey(): boolean;
71
+ public exposeToModel(): boolean;
72
+ public isRemote(): boolean;
73
+ public isValidValue(value: any): boolean;
74
+ public getField(): Field | undefined;
75
+ public setField(field: Field): void;
76
+ public getModel(): ModelClass | undefined;
77
+ public setModel(Model: ModelClass): void;
78
+ public castToType(context: CastToTypeContext): any;
79
+ public initialize(connection: ConnectionBase, self: Model): void;
80
+ public isDirty(context: CheckDirtyContext): any;
81
+ public onSetFieldValue(context: SetFieldValueContext): void;
82
+ public serialize(value: any, connection?: ConnectionBase): any;
83
+ public deserialize(value: any, connection?: ConnectionBase): any;
84
+ public toConnectionType(connection?: ConnectionBase, options?: GenericObject): string;
85
+ public toString(connection?: ConnectionBase): string;
86
+ public getDisplayName(): string;
87
+ }
88
+
89
+ export default Type;
package/lib/types/type.js CHANGED
@@ -4,6 +4,14 @@ const { checkDefaultValueFlags } = require('./helpers/default-helpers');
4
4
 
5
5
  /// Base type class for all other field types.
6
6
  class Type {
7
+ static getDisplayName() {
8
+ return '<UNKNOWN>';
9
+ }
10
+
11
+ getDisplayName() {
12
+ return this.constructor.getDisplayName();
13
+ }
14
+
7
15
  static _isMythixFieldType = true;
8
16
 
9
17
  static clone = function() {
@@ -85,6 +93,7 @@ class Type {
85
93
  'isRelational',
86
94
  'isForeignKey',
87
95
  'exposeToModel',
96
+ 'getDisplayName',
88
97
  ];
89
98
 
90
99
  for (let i = 0, il = staticPropertiesToCopy.length; i < il; i++) {
@@ -98,7 +107,7 @@ class Type {
98
107
  Object.defineProperties(TypeWrapper, {
99
108
  'name': {
100
109
  writable: false,
101
- enumberable: false,
110
+ enumerable: false,
102
111
  configurable: false,
103
112
  value: `${TypeKlass.name}Wrapper`,
104
113
  },
@@ -111,42 +120,22 @@ class Type {
111
120
  Object.defineProperties(this, {
112
121
  '_args': {
113
122
  writable: true,
114
- enumberable: false,
123
+ enumerable: false,
115
124
  configurable: true,
116
125
  value: args,
117
126
  },
118
127
  '_Model': {
119
128
  writable: true,
120
- enumberable: false,
129
+ enumerable: false,
121
130
  configurable: true,
122
131
  value: null,
123
132
  },
124
133
  '_field': {
125
134
  writable: true,
126
- enumberable: false,
127
- configurable: true,
128
- value: null,
129
- },
130
- '_modelInstance': {
131
- writable: true,
132
- enumberable: false,
133
- configurable: true,
134
- value: null,
135
- },
136
- '_connection': {
137
- writable: true,
138
- enumberable: false,
135
+ enumerable: false,
139
136
  configurable: true,
140
137
  value: null,
141
138
  },
142
- '_initialized': {
143
- enumberable: false,
144
- configurable: true,
145
- get: () => {
146
- return !!(this._Model && this._field);
147
- },
148
- set: () => {},
149
- },
150
139
  });
151
140
  }
152
141
 
@@ -156,7 +145,6 @@ class Type {
156
145
 
157
146
  newInstance._Model = this._Model;
158
147
  newInstance._field = this._field;
159
- newInstance._modelInstance = this._modelInstance;
160
148
 
161
149
  return newInstance;
162
150
  }
@@ -240,6 +228,7 @@ class Type {
240
228
  /// };
241
229
  ///
242
230
  /// Return: any
231
+ ///
243
232
  /// Arguments:
244
233
  /// context: CastToTypeContext
245
234
  /// The "context" passed to `castToType`. This contains
@@ -248,6 +237,23 @@ class Type {
248
237
  return value;
249
238
  }
250
239
 
240
+ /// Initialize a model instance against this type.
241
+ ///
242
+ /// Initialize is called whenever a model instance is
243
+ /// created. Note that the type instance is shared
244
+ /// across all model instances. `initialize` is still
245
+ /// called for every model instance that is created however,
246
+ /// because the type class can modify the model it
247
+ /// exists on. For example, the `Model` and `Models` type
248
+ /// inject custom relational methods onto each model instance.
249
+ ///
250
+ /// Return: undefined
251
+ ///
252
+ /// Arguments:
253
+ /// connection: <see>Connection</see>
254
+ /// The database connection of the calling model instance.
255
+ /// self: Model
256
+ /// The actual model instance that is calling this method.
251
257
  // eslint-disable-next-line no-unused-vars
252
258
  initialize(connection, self) {
253
259
  }
@@ -266,6 +272,32 @@ class Type {
266
272
  return value;
267
273
  }
268
274
 
275
+ /// Convert this type to the underlying type
276
+ /// of the database driver.
277
+ ///
278
+ /// This is generally called by a `QueryGenerator`
279
+ /// instance to convert the field's type to the
280
+ /// underlying type of the database. If a `connection`
281
+ /// argument is provided, then it will proxy the
282
+ /// call to <see>Connection.typeToString</see>.
283
+ /// If no `connection` argument is provided, then
284
+ /// it will simply return the "common" SQL string
285
+ /// representation for this type.
286
+ ///
287
+ /// Return: string
288
+ /// A string type representing the underlying
289
+ /// database driver type, or the "common" SQL
290
+ /// type if not `connection` is provided.
291
+ ///
292
+ /// Arguments:
293
+ /// connection: <see>Connection</see>
294
+ /// The database driver connection this type
295
+ /// is being converted to.
296
+ /// options?: object
297
+ /// Any options to pass through with the type
298
+ /// conversion. This options object will be
299
+ /// passed to the <see>Connection.typeToString</see>
300
+ /// call.
269
301
  toConnectionType(connection, options) {
270
302
  if (!connection)
271
303
  return this.toString();
@@ -0,0 +1,4 @@
1
+ export * from './model-type';
2
+ export * from './models-type';
3
+ export * from './relational-type-base';
4
+ export { default as RelationalTypeBase } from './relational-type-base';
@@ -0,0 +1,15 @@
1
+ import Field from '../../field';
2
+ import { GenericObject } from '../../interfaces/common';
3
+ import { TypeWrapper } from '../type';
4
+ import RelationalTypeBase, { QueryFactory } from './relational-type-base';
5
+ import { Model as _Model, Models } from '../../model';
6
+
7
+ export declare interface Model<T extends _Model, M = Models> extends TypeWrapper<ModelType<T, M>> {
8
+ (targetModelName: string, queryFactory: QueryFactory<T, M>, options?: GenericObject): ModelType<T, M>;
9
+ }
10
+
11
+ export declare class ModelType<T extends _Model, M = Models> extends RelationalTypeBase<T, M> {
12
+ public fieldNameToOperationName(field: Field, operation: string, rootMethod: boolean): string;
13
+ }
14
+
15
+ export function Model<T extends _Model, M = Models>(targetModelName: string, queryFactory: QueryFactory<T, M>, options?: GenericObject): ModelType<T, M>;
@@ -8,7 +8,7 @@ const ModelUtils = require('../../utils/model-utils');
8
8
  // create{fieldName}, get{fieldName}, etc...
9
9
  const TYPE_OPERATIONS = {
10
10
  'queryFor': async function({ field, type }, userQuery, options, ...args) {
11
- return await type.prepareQuery({ connection: null, self: this, field, userQuery, options }, args);
11
+ return await type.prepareQuery({ connection: null, self: this, field, options }, [ userQuery ].concat(args));
12
12
  },
13
13
  'create': async function({ field, type, get }, model, options) {
14
14
  if (!model)
@@ -51,7 +51,7 @@ const TYPE_OPERATIONS = {
51
51
  return result;
52
52
  },
53
53
  'get': async function({ field, type }, userQuery, options, ...args) {
54
- let query = await type.prepareQuery({ connection: null, self: this, field, userQuery, options }, args);
54
+ let query = await type.prepareQuery({ connection: null, self: this, field, options }, [ userQuery ].concat(args));
55
55
  return await query.first(null, options);
56
56
  },
57
57
  'update': async function({ fullMethodName, field, type, create }, attributes, _options, ...args) {
@@ -0,0 +1,15 @@
1
+ import Field from '../../field';
2
+ import { GenericObject } from '../../interfaces/common';
3
+ import { Model, Models as _Models } from '../../model';
4
+ import { TypeWrapper } from '../type';
5
+ import RelationalTypeBase, { QueryFactory } from './relational-type-base';
6
+
7
+ export declare interface Models<T extends Model, M = _Models> extends TypeWrapper<ModelsType<T, M>> {
8
+ (targetModelName: string, queryFactory: QueryFactory<T, M>, options?: GenericObject): ModelsType<T, M>;
9
+ }
10
+
11
+ export declare class ModelsType<T extends Model, M = _Models> extends RelationalTypeBase<T, M> {
12
+ public fieldNameToOperationName(field: Field, operation: string, rootMethod: boolean): string;
13
+ }
14
+
15
+ export function Models<T extends Model, M = _Models>(targetModelName: string, queryFactory: QueryFactory<T, M>, options?: GenericObject): ModelsType<T, M>;
@@ -94,7 +94,7 @@ async function destroyRelatedModels(connection, field, type, TargetModel, stored
94
94
  // addTo{fieldName}, get{fieldName}, etc...
95
95
  const TYPE_OPERATIONS = {
96
96
  'queryFor': async function({ field, type }, userQuery, options, ...args) {
97
- return await type.prepareQuery({ connection: null, self: this, field, userQuery, options }, args);
97
+ return await type.prepareQuery({ connection: null, self: this, field, options }, [ userQuery ].concat(args));
98
98
  },
99
99
  'addTo': async function({ field }, _models, options) {
100
100
  let models = Nife.toArray(_models).filter(Boolean);
@@ -124,7 +124,7 @@ const TYPE_OPERATIONS = {
124
124
  },
125
125
  'get': function({ field, type }, userQuery, options, ...args) {
126
126
  const doGet = async function*() {
127
- let query = await type.prepareQuery({ connection: null, self: this, field, userQuery, options }, args);
127
+ let query = await type.prepareQuery({ connection: null, self: this, field, options }, [ userQuery ].concat(args));
128
128
  let results = query.all(Object.assign({}, options, { stream: true }));
129
129
  let primaryModelRelationalArray = [];
130
130
 
@@ -222,15 +222,15 @@ const TYPE_OPERATIONS = {
222
222
  }, _options);
223
223
  },
224
224
  'destroy': async function({ field, type }, userQuery, options, ...args) {
225
- let query = await type.prepareQuery({ connection: null, self: this, field, userQuery, options }, args);
225
+ let query = await type.prepareQuery({ connection: null, self: this, field, options }, [ userQuery ].concat(args));
226
226
  return await query.destroy(options);
227
227
  },
228
228
  'count': async function({ field, type }, userQuery, options, ...args) {
229
- let query = await type.prepareQuery({ connection: null, self: this, field, userQuery, options }, args);
229
+ let query = await type.prepareQuery({ connection: null, self: this, field, options }, [ userQuery ].concat(args));
230
230
  return await query.count(null, options);
231
231
  },
232
232
  'pluck': async function({ field, type }, userQuery, fields, options, ...args) {
233
- let query = await type.prepareQuery({ connection: null, self: this, field, fields, userQuery, options }, args);
233
+ let query = await type.prepareQuery({ connection: null, self: this, field, fields, options }, [ userQuery ].concat(args));
234
234
  return await query.pluck(fields, options);
235
235
  },
236
236
  'has': async function({ count }, userQuery, options, ...args) {
@@ -0,0 +1,46 @@
1
+ import ConnectionBase from '../../connection/connection-base';
2
+ import Field from '../../field';
3
+ import { GenericObject } from '../../interfaces/common';
4
+ import { Model, ModelClass, Models } from '../../model';
5
+ import { QueryEngine } from '../../query-engine';
6
+ import Type from '../type';
7
+
8
+ export declare interface QueryFactoryContext<T extends Model> {
9
+ type: Type;
10
+ self: T;
11
+ connection: ConnectionBase;
12
+ field: Field;
13
+ }
14
+
15
+ export declare interface QueryFactory<T extends Model, M = Models> {
16
+ (context: QueryFactoryContext<T>, models: M, ...args: Array<any>): QueryEngine | Promise<QueryEngine>;
17
+ }
18
+
19
+ export declare interface RelationalInfo {
20
+ Model: ModelClass;
21
+ modelName: string;
22
+ field: Field | null;
23
+ fieldName: string | null;
24
+ }
25
+
26
+ export declare interface RelationalContext {
27
+ PrimaryModel: ModelClass;
28
+ TargetModel: ModelClass;
29
+ TargetField: Field;
30
+ target: RelationalInfo;
31
+ source: RelationalInfo;
32
+ }
33
+
34
+ declare class RelationalTypeBase<T extends Model, M = Models> extends Type {
35
+ declare public targetModelName: string;
36
+ declare public queryFactory: QueryFactory<T, M>;
37
+ declare public options: string;
38
+
39
+ constructor(targetModelName: string, queryFactory: QueryFactory<T, M>, options?: GenericObject);
40
+ getOptions(): GenericObject;
41
+ walkQueryRelations(connection: ConnectionBase, callback: (context: RelationalContext) => void, context: QueryFactoryContext<T>, ...args: Array<any>): Promise<QueryEngine>;
42
+ getTargetModel(connection?: ConnectionBase): ModelClass;
43
+ prepareQuery(context: QueryFactoryContext<T>, args: Array<any>): Promise<QueryEngine>;
44
+ }
45
+
46
+ export default RelationalTypeBase;