@@ -204,57 +204,32 @@ const getAttributeType = (attr: Eloquent.Attribute): string => {
204
204
if ( attr . nullable && type !== "mixed" ) {
205
205
return `${ type } |null` ;
206
206
}
207
-
207
+
208
208
return type ;
209
209
} ;
210
210
211
- const castMapping : Record < string , ( string | RegExp ) [ ] > = {
212
- array : [
213
- "json" ,
214
- "encrypted:json" ,
215
- "encrypted:array" ,
216
- ] ,
217
- int : [
218
- "timestamp" ,
219
- ] ,
220
- mixed : [
221
- "attribute" ,
222
- "accessor" ,
223
- "encrypted" ,
224
- ] ,
225
- object : [
226
- "encrypted:object" ,
227
- ] ,
228
- string : [
229
- "hashed" ,
230
- ] ,
231
- "\\Illuminate\\Support\\Carbon" : [
232
- "date" ,
233
- "datetime" ,
234
- ] ,
235
- "\\Illuminate\\Support\\Collection" : [
236
- "encrypted:collection" ,
237
- ] ,
211
+ type TypeMapping = Record < string , ( string | RegExp ) [ ] > ;
212
+
213
+ const castMapping : TypeMapping = {
214
+ array : [ "json" , "encrypted:json" , "encrypted:array" ] ,
215
+ int : [ "timestamp" ] ,
216
+ mixed : [ "attribute" , "accessor" , "encrypted" ] ,
217
+ object : [ "encrypted:object" ] ,
218
+ string : [ "hashed" ] ,
219
+ "\\Illuminate\\Support\\Carbon" : [ "date" , "datetime" ] ,
220
+ "\\Illuminate\\Support\\Collection" : [ "encrypted:collection" ] ,
238
221
} ;
239
222
240
- const typeMapping : Record < string , ( string | RegExp ) [ ] > = {
241
- bool : [
242
- / ^ b o o l e a n ( \( ( 0 | 1 ) \) ) ? $ / ,
243
- / ^ t i n y i n t ( u n s i g n e d ) ? ( \( \d + \) ) ? $ / ,
244
- ] ,
223
+ const typeMapping : TypeMapping = {
224
+ bool : [ / ^ b o o l e a n ( \( ( 0 | 1 ) \) ) ? $ / , / ^ t i n y i n t ( u n s i g n e d ) ? ( \( \d + \) ) ? $ / ] ,
245
225
float : [
246
226
"real" ,
247
227
"money" ,
248
228
"double precision" ,
249
229
/ ^ ( d o u b l e | d e c i m a l | n u m e r i c ) ( \( \d + \, \d + \) ) ? $ / ,
250
230
] ,
251
- int : [
252
- / ^ ( b i g ) ? s e r i a l $ / ,
253
- / ^ ( s m a l l | b i g ) ? i n t ( e g e r ) ? ( u n s i g n e d ) ? $ / ,
254
- ] ,
255
- resource : [
256
- "bytea" ,
257
- ] ,
231
+ int : [ / ^ ( b i g ) ? s e r i a l $ / , / ^ ( s m a l l | b i g ) ? i n t ( e g e r ) ? ( u n s i g n e d ) ? $ / ] ,
232
+ resource : [ "bytea" ] ,
258
233
string : [
259
234
"box" ,
260
235
"cidr" ,
@@ -279,8 +254,8 @@ const typeMapping: Record<string, (string | RegExp)[]> = {
279
254
} ;
280
255
281
256
const findInMapping = (
282
- mapping : Record < string , ( string | RegExp ) [ ] > ,
283
- value : string | null
257
+ mapping : TypeMapping ,
258
+ value : string | null ,
284
259
) : string | null => {
285
260
if ( value === null ) {
286
261
return null ;
@@ -302,7 +277,11 @@ const findInMapping = (
302
277
} ;
303
278
304
279
const getActualType = ( cast : string | null , type : string ) : string => {
305
- const finalType = findInMapping ( castMapping , cast ) || cast || findInMapping ( typeMapping , type ) || "mixed" ;
280
+ const finalType =
281
+ findInMapping ( castMapping , cast ) ||
282
+ cast ||
283
+ findInMapping ( typeMapping , type ) ||
284
+ "mixed" ;
306
285
307
286
if ( finalType . includes ( "\\" ) && ! finalType . startsWith ( "\\" ) ) {
308
287
return `\\${ finalType } ` ;
0 commit comments