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
@@ -3,15 +3,74 @@
3
3
  const Nife = require('nife');
4
4
  const Type = require('../type');
5
5
 
6
+ /// `REAL` type.
7
+ /// Also known as `FLOAT`, or `DOUBLE` in some databases.
8
+ ///
9
+ /// This represents a "real" number of low precision and
10
+ /// accuracy in the underlying database driver. Unlike the
11
+ /// <see>NumericType</see>, which is high precision, this
12
+ /// type can suffer from rounding errors, and won't be as
13
+ /// precise <see>NumericType</see>.
14
+ ///
15
+ /// The `length` argument is the total number of bytes needed
16
+ /// to store the underlying value. If `4`, then this will generally
17
+ /// be a `FLOAT` or equivalent type in the underlying database driver.
18
+ /// If `8`, then it will generally be a `DOUBLE` or equivalent type.
19
+ /// The `scale` argument specifies the number of digits that
20
+ /// are desired *after* the decimal place. A scale of `0` would
21
+ /// essentially mean that you want an integer (no decimal places),
22
+ /// whereas a `scale` of `2` would mean you want two decimal places.
23
+ /// It is important to call out that different database drivers
24
+ /// may interpret and use these values differently.
25
+ ///
26
+ /// Example:
27
+ /// class Real extends Model {
28
+ /// static fields = {
29
+ /// real1: Types.REAL(4, 6), // FLOAT
30
+ /// real2: Types.REAL(8, 6), // DOUBLE
31
+ /// real3: Types.REAL, // FLOAT (default)
32
+ /// };
33
+ /// }
34
+ ///
35
+ /// See: Type
6
36
  class RealType extends Type {
37
+ /// Get the "display" name for this type.
38
+ ///
39
+ /// This method is called from <see>Model.toString</see>
40
+ /// when stringifying the model for representation.
41
+ ///
42
+ /// Note:
43
+ /// This is also an instance method that can be called from
44
+ /// an instance of the type.
45
+ ///
46
+ /// Return: string
47
+ /// Return the string value `'REAL'`
7
48
  static getDisplayName() {
8
49
  return 'REAL';
9
50
  }
10
51
 
11
- getDisplayName() {
12
- return this.constructor.getDisplayName();
13
- }
14
-
52
+ /// Construct a new `REAL` type.
53
+ ///
54
+ /// The `length` argument specifies the total number of
55
+ /// bytes needed to store this value (default = `4`).
56
+ /// The `scale` argument specifies the number of digits
57
+ /// desired after the decimal place. A `scale` of `0` is valid,
58
+ /// meaning you want no digits after the decimal point.
59
+ /// Note that this is dependant on database driver support.
60
+ ///
61
+ /// Return: RealType
62
+ ///
63
+ /// Arguments:
64
+ /// length?: number = 4
65
+ /// The number of bytes needed to store the value. Use `4`
66
+ /// to end up with a `FLOAT` on most database drivers, or
67
+ /// `8` for a `DOUBLE`.
68
+ /// scale?: number = 6
69
+ /// How many digits are desired after the decimal point.
70
+ /// A value of `2` would allow two digits after the decimal
71
+ /// point. A value of `0` would allow no digits after the decimal
72
+ /// point, essentially turning this into an integer. This
73
+ /// depends on the underlying database to support it.
15
74
  constructor(length, scale) {
16
75
  super(length, scale);
17
76
 
@@ -19,6 +78,23 @@ class RealType extends Type {
19
78
  this.scale = scale;
20
79
  }
21
80
 
81
+ /// Cast provided value to underlying type.
82
+ ///
83
+ /// This will cast the incoming value to the
84
+ /// underlying type of this field, a `number`
85
+ /// primitive. A `null` or `undefined`
86
+ /// value will simply be returned.
87
+ ///
88
+ /// See <see>Type.castToType</see> for a more
89
+ /// detailed description.
90
+ ///
91
+ /// Return: number | null | undefined
92
+ /// Return the incoming `value`, cast to this
93
+ /// type. `null` and `undefined` are simply
94
+ /// returned without casting.
95
+ ///
96
+ /// Arguments:
97
+ /// context: <see name="CastToTypeContext">Type.castToType</see>
22
98
  castToType({ value }) {
23
99
  if (value == null)
24
100
  return value;
@@ -30,10 +106,41 @@ class RealType extends Type {
30
106
  return number;
31
107
  }
32
108
 
109
+ /// Check if the provided value is valid.
110
+ ///
111
+ /// This will check if the provided value is
112
+ /// a `number` instance, and if it is finite.
113
+ /// If both conditions are true, then it will
114
+ /// return `true`.
115
+ ///
116
+ /// Return: boolean
117
+ ///
118
+ /// Arguments:
119
+ /// value: any
120
+ /// The value to check.
33
121
  isValidValue(value) {
34
122
  return (Nife.instanceOf(value, 'number') && isFinite(value));
35
123
  }
36
124
 
125
+ /// Stringify the type itself.
126
+ ///
127
+ /// If a `connection` argument is provided, then this
128
+ /// will go through the connection to generate the type
129
+ /// for the underlying database. If no connection is
130
+ /// provided, then a "standard" SQL type will be returned
131
+ /// for this type instead. The "standard" type returned
132
+ /// when no `connection` is provided is `'FLOAT'`.
133
+ ///
134
+ /// Return: string
135
+ ///
136
+ /// Arguments:
137
+ /// connection?: <see>Connection</see>
138
+ /// An optional connection. If provided, send this
139
+ /// type through <see>Type.toConnectionType</see>
140
+ /// to have the connection itself generate the underlying
141
+ /// type for the database. If `connection` is not provided,
142
+ /// then this will simply return a "standard" generic matching
143
+ /// SQL type.
37
144
  toString(connection) {
38
145
  return (connection)
39
146
  ? this.toConnectionType(connection)
@@ -0,0 +1,25 @@
1
+ import ConnectionBase from '../../connection/connection-base';
2
+ import Type, { CheckDirtyContext, TypeWrapper } from '../type';
3
+
4
+ export declare interface SerializedTypeWrapper extends TypeWrapper<SerializedType> {
5
+ (options: Type | SerializedTypeOptions): SerializedType;
6
+ }
7
+
8
+ interface SerializeCallContext {
9
+ value: any;
10
+ connection: ConnectionBase | undefined;
11
+ }
12
+
13
+ export declare interface SerializedTypeOptions {
14
+ type: Type;
15
+ serialize?: (context: SerializeCallContext) => any;
16
+ deserialize?: (context: SerializeCallContext) => any;
17
+ isDirty?: (context: CheckDirtyContext) => any;
18
+ }
19
+
20
+ export declare class SerializedType extends Type {
21
+ public constructor(options: Type | SerializedTypeOptions);
22
+ public getOptions(): SerializedTypeOptions;
23
+ }
24
+
25
+ export const SERIALIZED: SerializedTypeWrapper;
@@ -2,15 +2,108 @@
2
2
 
3
3
  const Type = require('../type');
4
4
 
5
+ /// A field type that serializes and deserializes raw objects.
6
+ ///
7
+ /// The `SERIALIZED` type can be used to serialize
8
+ /// other data into a single field value. By default this
9
+ /// field type is configured to serialize `JSON`.
10
+ /// However, it can be configured to serialize and
11
+ /// deserialize in any encoding you desire.
12
+ ///
13
+ /// Something important to note right up front is that
14
+ /// this type hooks into the model instance's "dirty" system,
15
+ /// and will call your provided `serialize` and `deserialize`
16
+ /// methods to check if your object has *internally* become
17
+ /// dirty. For example, if you use this type for a field called
18
+ /// `metadata` on your `User` model, and you have an instance
19
+ /// of that user model you are working with, and you *internally*
20
+ /// change the `metadata` field like so `user.metadata.class = 'wizard';`
21
+ /// then this field type will detect that the `metadata` attribute
22
+ /// of your model is "dirty" by serializing the `metadata` value
23
+ /// and comparing it to the "undirty" serialized value, even if
24
+ /// the actual value of the `metadata` field itself hasn't changed.
25
+ /// For this reason it is important that your serializer sort
26
+ /// the serialized data if possible. If sorting isn't possible,
27
+ /// then the side-effect will be that this field may be serialized
28
+ /// and stored more often than actually needed. This system was
29
+ /// designed this way because it is likely better to get a false
30
+ /// positive and save your data, then not check at all and lose data.
31
+ /// If needed, you can always create your own child type of
32
+ /// `SerializedType`, and overload the `isDirty` method, or provided
33
+ /// an `isDirty` method to the field `options` to check
34
+ /// for dirtiness yourself, based on what makes sense with your
35
+ /// serializing algorithm.
36
+ ///
37
+ /// See: Type
5
38
  class SerializedType extends Type {
39
+ /// Get the "display" name for this type.
40
+ ///
41
+ /// This method is called from <see>Model.toString</see>
42
+ /// when stringifying the model for representation.
43
+ ///
44
+ /// Note:
45
+ /// This is also an instance method that can be called from
46
+ /// an instance of the type.
47
+ ///
48
+ /// Return: string
49
+ /// Return the string value `'SERIALIZED'`
6
50
  static getDisplayName() {
7
51
  return 'SERIALIZED';
8
52
  }
9
53
 
10
- getDisplayName() {
11
- return this.constructor.getDisplayName();
12
- }
13
-
54
+ /// Construct a new instance of the `SerializedType` type.
55
+ ///
56
+ /// Interface:
57
+ /// interface SerializeCallContext {
58
+ /// // The value to serialize or deserialize
59
+ /// value: any;
60
+ ///
61
+ /// // The database driver connection.
62
+ /// connection: Connection;
63
+ /// }
64
+ ///
65
+ /// Interface:
66
+ /// interface SerializedTypeOptions {
67
+ /// // Method to serialize data. Note how the
68
+ /// // return type is `any`. Though commonly an
69
+ /// // underlying `STRING` type will be used for
70
+ /// // the field value, that isn't a requirement.
71
+ /// // For example, you might want to encode a bitmask
72
+ /// // into a `BIGINT`. The world is your oyster.
73
+ /// //
74
+ /// // Unlike other fields, `null` and `undefined` are
75
+ /// // not simply returned. They are left up to the
76
+ /// // serializer and deserializer to handle and do
77
+ /// // with as they want. For this reason, you need
78
+ /// // to properly handle `null` and `undefined` values,
79
+ /// // even if you just return them (allowing the underlying
80
+ /// // database field to contain a `NULL` value).
81
+ /// serialize?: (context: SerializeCallContext) => any;
82
+ ///
83
+ /// // Deserialize the data provided.
84
+ /// deserialize?: (context: SerializeCallContext) => any;
85
+ ///
86
+ /// // The underlying storage type of this field. This will
87
+ /// // commonly be a `STRING` of some larger size, but isn't
88
+ /// // required to be. It can be any type that works for your
89
+ /// // serializer and deserializer.
90
+ /// type: Type;
91
+ ///
92
+ /// // Provide your own method to detect
93
+ /// // "dirtiness" of the field's value
94
+ /// // See the "isDirty" method of this
95
+ /// // class for more information.
96
+ /// isDirty?: (context: CheckDirtyContext) => any;
97
+ /// }
98
+ ///
99
+ /// Return: SerializedType
100
+ ///
101
+ /// Arguments:
102
+ /// options?: Type | SerializedTypeOptions
103
+ /// If this is a `Type`, then it will specify
104
+ /// the underlying field type that will store
105
+ /// the serialized value, and is the same as
106
+ /// specifying the `{ type: Type }` option.
14
107
  constructor(_options) {
15
108
  let options = _options;
16
109
  if (Type.isTypeClass(options) || Type.isType(options))
@@ -42,26 +135,97 @@ class SerializedType extends Type {
42
135
  Object.defineProperties(this, {
43
136
  'options': {
44
137
  writable: true,
45
- enumberable: false,
138
+ enumerable: false,
46
139
  configurable: true,
47
140
  value: options,
48
141
  },
49
142
  });
50
143
  }
51
144
 
145
+ /// Get the options passed to the field
146
+ /// when it was defined.
147
+ ///
148
+ /// Return: object
149
+ /// The options object provided to the field.
52
150
  getOptions() {
53
151
  return this.options;
54
152
  }
55
153
 
154
+ /// Call initialize on the underling type
155
+ /// field.
156
+ ///
157
+ /// See: Type.initialize
56
158
  initialize(connection, self) {
57
159
  let options = this.getOptions();
58
160
  options.type.initialize(connection, self);
59
161
  }
60
162
 
163
+ /// Cast provided value to underlying type.
164
+ ///
165
+ /// This will cast the incoming value by calling
166
+ /// <see>SerializedType.deserialize</see> on the type with the provided
167
+ /// value. If <see>SerializedType.deserialize</see> detects that the type
168
+ /// is the same as the underlying storage type (i.e.
169
+ /// `STRING`), then it will deserialize and return the
170
+ /// value. However, if the provided value is not the
171
+ /// type of the underlying storage field type, and the
172
+ /// value is not `null` or `undefined`, then it will
173
+ /// be assumed to already be deserialized and will be
174
+ /// simply returned.
175
+ ///
176
+ /// See <see>Type.castToType</see> for a more
177
+ /// detailed description.
178
+ ///
179
+ /// Return: any | null | undefined
180
+ /// Return the incoming `value`, cast to this
181
+ /// type (deserialized). `null` and `undefined` are simply
182
+ /// returned without casting by the default built-in JSON
183
+ /// deserializer... however, they may be treated differently
184
+ /// for other serializers.
185
+ ///
186
+ /// Arguments:
187
+ /// context: <see name="CastToTypeContext">Type.castToType</see>
61
188
  castToType({ value, connection }) {
62
189
  return this.deserialize(value, connection);
63
190
  }
64
191
 
192
+ /// This is called whenever the model's field
193
+ /// owning this type is changed. This method
194
+ /// will update the "dirty" serialized cache
195
+ /// contained on the model for this type. This
196
+ /// is later used to see if the field value is
197
+ /// dirty because any of the internal data of
198
+ /// the field value has changed (via a serialize
199
+ /// call that compares the value to last serialize).
200
+ ///
201
+ /// In short, this updates the last serialize cache
202
+ /// to compare it with a serialize on insert/update
203
+ /// to see if the serialized data is "dirty".
204
+ ///
205
+ /// Interface:
206
+ /// interface SetFieldValueContext {
207
+ /// // The field value that was just set onto the field.
208
+ /// value: any;
209
+ ///
210
+ /// // The field that contains this type
211
+ /// field: Field;
212
+ ///
213
+ /// // The name of the field that contains this type
214
+ /// fieldName: string;
215
+ ///
216
+ /// // The model instance itself
217
+ /// self: Model;
218
+ /// }
219
+ ///
220
+ /// Note:
221
+ /// Because type instances for fields are shared across model
222
+ /// instances, the actual "dirty" cache is stored on the model
223
+ /// itself in a `_typeData` property on the model instance.
224
+ ///
225
+ /// Return: undefined
226
+ ///
227
+ /// Arguments:
228
+ /// context: SetFieldValueContext
65
229
  onSetFieldValue({ value, fieldName, self }) {
66
230
  // we make a copy here
67
231
  // so that when the value is modified
@@ -70,6 +234,42 @@ class SerializedType extends Type {
70
234
  self._typeData[fieldName] = clonedValue;
71
235
  }
72
236
 
237
+ /// Check if this field is dirty, including if
238
+ /// the object value stored on the field has changed
239
+ /// since the last persist.
240
+ ///
241
+ /// This compares the current value of the field
242
+ /// to the last persisted value by serializing the
243
+ /// field's value and comparing it to the last serialized
244
+ /// value when the field was persisted/loaded.
245
+ ///
246
+ /// Interface:
247
+ /// interface CheckDirtyContext {
248
+ /// // The current field value to check.
249
+ /// value: any;
250
+ ///
251
+ /// // The field that contains this type
252
+ /// field: Field;
253
+ ///
254
+ /// // The name of the field that contains this type
255
+ /// fieldName: string;
256
+ ///
257
+ /// // The model instance itself
258
+ /// self: Model;
259
+ ///
260
+ /// // The underlying database connection
261
+ /// // that is attempting to insert or update
262
+ /// // this field
263
+ /// connection: Connection;
264
+ /// }
265
+ ///
266
+ /// Return: any
267
+ /// If `undefined` is returned, then this field is not considered
268
+ /// dirty. If any other value is returned, then that will be used
269
+ /// as the "dirty" value for the field.
270
+ ///
271
+ /// Arguments:
272
+ /// context: CheckDirtyContext
73
273
  isDirty(context) {
74
274
  let options = this.getOptions();
75
275
  if (typeof options.isDirty === 'function')
@@ -84,10 +284,38 @@ class SerializedType extends Type {
84
284
  return value;
85
285
  }
86
286
 
287
+ /// Validate the underlying field value.
288
+ /// For the `SerializedType` this simply
289
+ /// always returns `true`.
290
+ ///
291
+ /// Return: boolean
292
+ /// Always return `true`.
87
293
  isValidValue() {
88
294
  return true;
89
295
  }
90
296
 
297
+ /// Serialize the field's value, and
298
+ /// return the serialized result.
299
+ ///
300
+ /// Note that if no `connection` is provided
301
+ /// the current field's value is simply returned.
302
+ /// This is because it is assumed that serializing
303
+ /// will only be happening when the database driver
304
+ /// connection requests it, otherwise you likely
305
+ /// just want the raw value of the field.
306
+ ///
307
+ /// Return: any
308
+ /// The underlying field's value if no `connection`
309
+ /// argument was provided, or the serialized result
310
+ /// if a `connection` argument was provided.
311
+ ///
312
+ /// Arguments:
313
+ /// value: any
314
+ /// The value to serialize. If no `connection` argument
315
+ /// is provided, then this value will simply be returned.
316
+ /// connection?: <see>Connection</see>
317
+ /// The database driver connection requesting that this
318
+ /// field's value be serialized for storage.
91
319
  serialize(value, connection) {
92
320
  if (!connection)
93
321
  return value;
@@ -101,6 +329,41 @@ class SerializedType extends Type {
101
329
  return options.serialize({ value, connection });
102
330
  }
103
331
 
332
+ /// Deserialize the field's value, and
333
+ /// return the deserialized result.
334
+ ///
335
+ /// This is called any time `castToType`
336
+ /// is called. If the value provided is
337
+ /// not the same type as the underlying
338
+ /// storage type (i.e. `STRING`), and the
339
+ /// value is also not `null` or `undefined`,
340
+ /// then the value is simply returned. This
341
+ /// is because it is assumed if the value
342
+ /// isn't of the same type as storage
343
+ /// (i.e. `string` type), then it is already
344
+ /// deserialized, so will simply be returned.
345
+ /// `null` and `undefined` are handed directly
346
+ /// off to the provided `serialize` and `deserialize`
347
+ /// methods, so make sure your serializer can
348
+ /// properly handle these values (even if that
349
+ /// means simply returning them).
350
+ ///
351
+ /// Return: any
352
+ /// The underlying field's value. If the value
353
+ /// provided has a type that matches the underlying
354
+ /// storage type (i.e. typeof value === 'string' && internalType === 'STRING')
355
+ /// then the value will first be passed through the
356
+ /// provided `deserialize` method before it is returned.
357
+ ///
358
+ /// Arguments:
359
+ /// value: any
360
+ /// The value to deserialize. If this is *not*
361
+ /// the same type as the underlying storage type,
362
+ /// and is also *not* `null` or `undefined`, then
363
+ /// the value will simply be returned.
364
+ /// connection?: <see>Connection</see>
365
+ /// The database driver connection requesting that this
366
+ /// field's value be deserialized (usually during load).
104
367
  deserialize(value, connection) {
105
368
  let options = this.getOptions();
106
369
  let innerType = options.type;
@@ -111,6 +374,25 @@ class SerializedType extends Type {
111
374
  return options.deserialize({ value, connection });
112
375
  }
113
376
 
377
+ /// Stringify the type itself. **This will be
378
+ /// the type of the underlying storage field**.
379
+ ///
380
+ /// If a `connection` argument is provided, then this
381
+ /// will go through the connection to generate the type
382
+ /// for the underlying database. If no connection is
383
+ /// provided, then a "standard" SQL type will be returned
384
+ /// for underlying storage field type instead.
385
+ ///
386
+ /// Return: string
387
+ ///
388
+ /// Arguments:
389
+ /// connection?: <see>Connection</see>
390
+ /// An optional connection. If provided, send this
391
+ /// type through <see>Type.toConnectionType</see>
392
+ /// to have the connection itself generate the underlying
393
+ /// type for the database. If `connection` is not provided,
394
+ /// then this will simply return a "standard" generic matching
395
+ /// SQL type of the underlying storage field type.
114
396
  toString(connection) {
115
397
  let options = this.getOptions();
116
398
  let innerType = options.type;
@@ -0,0 +1,11 @@
1
+ import Type, { TypeWrapper } from '../type';
2
+
3
+ export declare interface StringTypeWrapper extends TypeWrapper<StringType> {
4
+ (length: number): StringType;
5
+ }
6
+
7
+ export declare class StringType extends Type {
8
+ public constructor(length: number);
9
+ }
10
+
11
+ export const STRING: StringTypeWrapper;
@@ -10,10 +10,6 @@ class StringType extends Type {
10
10
  return 'STRING';
11
11
  }
12
12
 
13
- getDisplayName() {
14
- return this.constructor.getDisplayName();
15
- }
16
-
17
13
  constructor(length) {
18
14
  super(length);
19
15
 
@@ -0,0 +1,11 @@
1
+ import Type, { TypeWrapper } from '../type';
2
+
3
+ export declare interface TextTypeWrapper extends TypeWrapper<TextType> {
4
+ (length: number): TextType;
5
+ }
6
+
7
+ export declare class TextType extends Type {
8
+ public constructor(length: number);
9
+ }
10
+
11
+ export const TEXT: TextTypeWrapper;
@@ -10,10 +10,6 @@ class TextType extends Type {
10
10
  return 'TEXT';
11
11
  }
12
12
 
13
- getDisplayName() {
14
- return this.constructor.getDisplayName();
15
- }
16
-
17
13
  constructor(length) {
18
14
  super(length);
19
15
 
@@ -0,0 +1,13 @@
1
+ import Type from '../type';
2
+
3
+ declare class UUIDBaseType extends Type {
4
+ getPrefix(options?: { prefix: string; }): string;
5
+ stripPrefix(value: string): { prefix: string; id: string };
6
+ addPrefix(value: string): string;
7
+ getBaseLength(): number;
8
+ getTotalLength(): number;
9
+ validateOptions(uuidArgs: Array<any>): void;
10
+ getArgsForUUID(options)
11
+ }
12
+
13
+ export default UUIDBaseType;
@@ -12,7 +12,7 @@ class UUIDBaseType extends Type {
12
12
  Object.defineProperties(this, {
13
13
  'options': {
14
14
  writable: true,
15
- enumberable: false,
15
+ enumerable: false,
16
16
  configurable: true,
17
17
  value: options,
18
18
  },
@@ -72,6 +72,9 @@ class UUIDBaseType extends Type {
72
72
  ? this.toConnectionType(connection)
73
73
  : `VARCHAR(${this.getTotalLength()})`;
74
74
  }
75
+
76
+ validateOptions() {
77
+ }
75
78
  }
76
79
 
77
80
  module.exports = UUIDBaseType;
@@ -0,0 +1,31 @@
1
+ import { DefaultValueProvider } from '../helpers/default-helpers';
2
+ import { TypeWrapper } from '../type';
3
+ import UUIDBaseType from './uuid-base';
4
+
5
+ export declare interface UUIDV1TypeWrapper extends TypeWrapper<UUIDV1Type> {
6
+ (options?: UUIDV1TypeOptions): UUIDV1Type;
7
+ }
8
+
9
+ export declare interface UUIDV1TypeOptions {
10
+ prefix?: string;
11
+ node?: Array<number>;
12
+ clockseq?: number;
13
+ msecs?: number;
14
+ nsecs?: number;
15
+ random?: Array<number>;
16
+ rng?: () => Array<number>;
17
+ buffer?: Buffer;
18
+ offset?: number;
19
+ }
20
+
21
+ export declare class UUIDV1Type extends UUIDBaseType {
22
+ declare public static Default: {
23
+ UUIDV1: DefaultValueProvider;
24
+ }
25
+
26
+ constructor(options?: UUIDV1TypeOptions);
27
+ getOptions(): UUIDV1TypeOptions;
28
+ getArgsForUUID(options: UUIDV1TypeOptions): Array<any>;
29
+ }
30
+
31
+ export const UUIDV1: UUIDV1TypeWrapper;
@@ -27,10 +27,6 @@ class UUIDV1Type extends UUIDBaseType {
27
27
  return 'UUIDV1';
28
28
  }
29
29
 
30
- getDisplayName() {
31
- return this.constructor.getDisplayName();
32
- }
33
-
34
30
  getArgsForUUID(options) {
35
31
  let uuidOptions = {};
36
32