Skip to content

Commit e3059aa

Browse files
committed
Apply value transforms before serialization
1 parent 43bb705 commit e3059aa

10 files changed

Lines changed: 16 additions & 12 deletions

File tree

cf/src/connection.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,8 +958,9 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
958958
return b.i32(0xFFFFFFFF)
959959

960960
type = types[i]
961+
x = options.transform.value.to ? options.transform.value.to(x, { type }) : x
961962
parameters[i] = x = type in options.serializers
962-
? options.serializers[type](x, options, type)
963+
? options.serializers[type](x)
963964
: '' + x
964965

965966
prev = b.i

cf/src/types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const types = {
1717
json: {
1818
to: 114,
1919
from: [114, 3802],
20-
serialize: (x, options, type) => JSON.stringify(options && options.transform.value.to ? options.transform.value.to(x, { type }) : x),
20+
serialize: x => JSON.stringify(x),
2121
parse: x => JSON.parse(x)
2222
},
2323
boolean: {

cjs/src/connection.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,8 +956,9 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
956956
return b.i32(0xFFFFFFFF)
957957

958958
type = types[i]
959+
x = options.transform.value.to ? options.transform.value.to(x, { type }) : x
959960
parameters[i] = x = type in options.serializers
960-
? options.serializers[type](x, options, type)
961+
? options.serializers[type](x)
961962
: '' + x
962963

963964
prev = b.i

cjs/src/types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const types = module.exports.types = {
1616
json: {
1717
to: 114,
1818
from: [114, 3802],
19-
serialize: (x, options, type) => JSON.stringify(options && options.transform.value.to ? options.transform.value.to(x, { type }) : x),
19+
serialize: x => JSON.stringify(x),
2020
parse: x => JSON.parse(x)
2121
},
2222
boolean: {

deno/src/connection.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,8 +959,9 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
959959
return b.i32(0xFFFFFFFF)
960960

961961
type = types[i]
962+
x = options.transform.value.to ? options.transform.value.to(x, { type }) : x
962963
parameters[i] = x = type in options.serializers
963-
? options.serializers[type](x, options, type)
964+
? options.serializers[type](x)
964965
: '' + x
965966

966967
prev = b.i

deno/src/types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const types = {
1717
json: {
1818
to: 114,
1919
from: [114, 3802],
20-
serialize: (x, options, type) => JSON.stringify(options && options.transform.value.to ? options.transform.value.to(x, { type }) : x),
20+
serialize: x => JSON.stringify(x),
2121
parse: x => JSON.parse(x)
2222
},
2323
boolean: {

deno/types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ declare namespace postgres {
333333
interface PostgresType<T = any> {
334334
to: number;
335335
from: number[];
336-
serialize: (value: T, options?: ParsedOptions, type?: number) => unknown;
336+
serialize: (value: T) => unknown;
337337
parse: (raw: any) => T;
338338
}
339339

@@ -398,7 +398,7 @@ declare namespace postgres {
398398
pass: null;
399399
/** @inheritdoc */
400400
transform: Transform;
401-
serializers: Record<number, (value: any, options?: ParsedOptions, type?: number) => unknown>;
401+
serializers: Record<number, (value: any) => unknown>;
402402
parsers: Record<number, (value: any) => unknown>;
403403
}
404404

src/connection.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,8 +956,9 @@ function Connection(options, queues = {}, { onopen = noop, onend = noop, onclose
956956
return b.i32(0xFFFFFFFF)
957957

958958
type = types[i]
959+
x = options.transform.value.to ? options.transform.value.to(x, { type }) : x
959960
parameters[i] = x = type in options.serializers
960-
? options.serializers[type](x, options, type)
961+
? options.serializers[type](x)
961962
: '' + x
962963

963964
prev = b.i

src/types.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const types = {
1616
json: {
1717
to: 114,
1818
from: [114, 3802],
19-
serialize: (x, options, type) => JSON.stringify(options && options.transform.value.to ? options.transform.value.to(x, { type }) : x),
19+
serialize: x => JSON.stringify(x),
2020
parse: x => JSON.parse(x)
2121
},
2222
boolean: {

types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ declare namespace postgres {
331331
interface PostgresType<T = any> {
332332
to: number;
333333
from: number[];
334-
serialize: (value: T, options?: ParsedOptions, type?: number) => unknown;
334+
serialize: (value: T) => unknown;
335335
parse: (raw: any) => T;
336336
}
337337

@@ -396,7 +396,7 @@ declare namespace postgres {
396396
pass: null;
397397
/** @inheritdoc */
398398
transform: Transform;
399-
serializers: Record<number, (value: any, options?: ParsedOptions, type?: number) => unknown>;
399+
serializers: Record<number, (value: any) => unknown>;
400400
parsers: Record<number, (value: any) => unknown>;
401401
}
402402

0 commit comments

Comments
 (0)