File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -456,6 +456,24 @@ export function setNow(...fieldNames: string[]): Hook;
456
456
*/
457
457
export function setSlug ( slug : string , fieldName ?: string ) : Hook ;
458
458
459
+ export interface SequelizeConversion {
460
+ js : ( sqlValue : any ) => any ;
461
+ sql : ( jsValue : any ) => any ;
462
+ }
463
+
464
+ export interface SequelizeConverts < C > {
465
+ [ name : string ] : keyof C | 'boolean' | 'date' | 'json' ;
466
+ }
467
+
468
+ /**
469
+ * {@link https://feathers-plus.github.io/v1/feathers-hooks-common/index.html#SequelizeConvert }
470
+ */
471
+ export function sequelizeConvert < C extends { [ name : string ] : SequelizeConversion } > (
472
+ converts : SequelizeConverts < C > | null | undefined | false ,
473
+ ignores : string [ ] | null | undefined | false ,
474
+ conversions ?: C
475
+ ) : Hook ;
476
+
459
477
/**
460
478
* Filter data or result records using a MongoDB-like selection syntax.
461
479
* {@link https://feathers-plus.github.io/v1/feathers-hooks-common/index.html#Sifter}
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ import {
25
25
existsByDot ,
26
26
fastJoin ,
27
27
fgraphql ,
28
+ FGraphQLHookOptions ,
28
29
getByDot ,
29
30
getItems ,
30
31
iff ,
@@ -47,6 +48,7 @@ import {
47
48
ResolverMap ,
48
49
runHook ,
49
50
runParallel ,
51
+ sequelizeConvert ,
50
52
serialize ,
51
53
setByDot ,
52
54
setNow ,
@@ -63,11 +65,10 @@ import {
63
65
validate ,
64
66
validateSchema ,
65
67
when ,
66
- FGraphQLHookOptions ,
67
68
} from 'feathers-hooks-common' ;
68
- import ajv = require( 'ajv' ) ;
69
69
import { parse } from 'graphql' ;
70
70
import * as libphonenumberjs from 'libphonenumber-js' ;
71
+ import ajv = require( 'ajv' ) ;
71
72
72
73
const context1 : HookContext = {
73
74
type : 'before' ,
@@ -386,6 +387,19 @@ setNow('createdAt', 'updatedAt');
386
387
// $ExpectType Hook
387
388
setSlug ( 'storeId' ) ;
388
389
390
+ // $ExpectType Hook
391
+ sequelizeConvert ( {
392
+ aBool : 'boolean' ,
393
+ aDate : 'date' ,
394
+ anObject : 'json' ,
395
+ aNumber : 'strToInt'
396
+ } , null , {
397
+ strToInt : {
398
+ js : ( sqlValue : string ) => + sqlValue ,
399
+ sql : ( jsValue : number ) => `${ jsValue } ` ,
400
+ }
401
+ } ) ;
402
+
389
403
// $ExpectType Hook
390
404
sifter ( ctx => item => true ) ;
391
405
You can’t perform that action at this time.
0 commit comments