@@ -363,7 +363,7 @@ class TableRecord {
363
363
} )
364
364
)
365
365
setIs ( this , record , it , isNew )
366
- Object . freeze ( this )
366
+ // Object.freeze(this)
367
367
}
368
368
369
369
get entity ( ) {
@@ -1330,7 +1330,7 @@ module.exports = function (schemaName, schema, config) {
1330
1330
return db
1331
1331
. query ( view . statement , view . params , options )
1332
1332
. then ( function ( res ) {
1333
- return res . map ( function ( record ) {
1333
+ const recordset = res . map ( function ( record ) {
1334
1334
return options . toPlainObject === true ||
1335
1335
options . fetchExternalDescription === true
1336
1336
? buildPlainObject ( record , data )
@@ -1343,10 +1343,16 @@ module.exports = function (schemaName, schema, config) {
1343
1343
self
1344
1344
)
1345
1345
} )
1346
+ return config . transforms ?. read
1347
+ ? recordset . map ( config . transforms . read )
1348
+ : recordset
1346
1349
} )
1347
1350
} )
1348
1351
} ,
1349
1352
create : function ( entity , options ) {
1353
+ if ( config . transforms ?. write ) {
1354
+ entity = config . transforms . write ( entity )
1355
+ }
1350
1356
options = options || { }
1351
1357
var self = this
1352
1358
var isInstance =
@@ -1387,21 +1393,28 @@ module.exports = function (schemaName, schema, config) {
1387
1393
} )
1388
1394
. then ( function ( record ) {
1389
1395
orderAssociations ( record , data )
1390
- return options . toPlainObject === true &&
1391
- ! isInstance
1392
- ? record
1393
- : buildEntity (
1394
- record ,
1395
- data ,
1396
- false ,
1397
- false ,
1398
- entity ,
1399
- self
1400
- )
1396
+ let res =
1397
+ options . toPlainObject === true && ! isInstance
1398
+ ? record
1399
+ : buildEntity (
1400
+ record ,
1401
+ data ,
1402
+ false ,
1403
+ false ,
1404
+ entity ,
1405
+ self
1406
+ )
1407
+ if ( config . transforms ?. read ) {
1408
+ res = config . transforms . read ( res )
1409
+ }
1410
+ return res
1401
1411
} )
1402
1412
} )
1403
1413
} ,
1404
1414
update : function ( entity , key , options ) {
1415
+ if ( config . transforms ?. write ) {
1416
+ entity = config . transforms . write ( entity )
1417
+ }
1405
1418
var self = this
1406
1419
key = key || entity [ data . primaryKeyAttributes [ 0 ] ]
1407
1420
if ( ! key ) {
@@ -1509,17 +1522,21 @@ module.exports = function (schemaName, schema, config) {
1509
1522
} )
1510
1523
. then ( function ( record ) {
1511
1524
orderAssociations ( record , data )
1512
- return options . toPlainObject === true &&
1513
- ! isInstance
1514
- ? record
1515
- : buildEntity (
1516
- record ,
1517
- data ,
1518
- false ,
1519
- false ,
1520
- entity ,
1521
- self
1522
- )
1525
+ let res =
1526
+ options . toPlainObject === true && ! isInstance
1527
+ ? record
1528
+ : buildEntity (
1529
+ record ,
1530
+ data ,
1531
+ false ,
1532
+ false ,
1533
+ entity ,
1534
+ self
1535
+ )
1536
+ if ( config . transforms ?. read ) {
1537
+ res = config . transforms . read ( res )
1538
+ }
1539
+ return res
1523
1540
} )
1524
1541
} )
1525
1542
} ,
@@ -1685,6 +1702,13 @@ module.exports = function (schemaName, schema, config) {
1685
1702
rebuild ( )
1686
1703
return data . public
1687
1704
} ,
1705
+ setTransforms : function ( { read, write} ) {
1706
+ config . transforms = {
1707
+ read,
1708
+ write
1709
+ }
1710
+ return data . public
1711
+ } ,
1688
1712
setScope : function ( scope ) {
1689
1713
data . scope = scope
1690
1714
rebuild ( )
0 commit comments