postgrejs 3.12.2 → 3.14.0
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.
- package/README.md +49 -0
- package/connection/connection.js +7 -2
- package/connection/intl-connection.d.ts +1 -0
- package/connection/intl-connection.js +4 -3
- package/constants.d.ts +1 -1
- package/constants.js +1 -1
- package/data-types/date-type.js +8 -1
- package/package.json +1 -1
- package/protocol/frontend.d.ts +14 -1
- package/protocol/frontend.js +39 -5
- package/protocol/pg-socket.d.ts +27 -3
- package/protocol/pg-socket.js +132 -34
- package/protocol/smart-buffer.d.ts +5 -4
- package/protocol/smart-buffer.js +21 -1
- package/protocol/workerd-socket.d.ts +87 -0
- package/protocol/workerd-socket.js +245 -0
- package/util/resolved-bind-type.d.ts +15 -0
- package/util/resolved-bind-type.js +85 -0
- package/util/runtime.d.ts +6 -0
- package/util/runtime.js +19 -0
- package/util/stringify-arrayliteral.js +9 -2
- package/util/unspecified-param.d.ts +14 -0
- package/util/unspecified-param.js +40 -0
- package/util/unspecified-value.d.ts +26 -0
- package/util/unspecified-value.js +63 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Follows a value's `toPostgres()` until it reaches one that has none.
|
|
3
|
+
*
|
|
4
|
+
* `toPostgres()` is `pg`'s extension point for a type that knows how to
|
|
5
|
+
* write itself: a library with its own geometry, money or domain class
|
|
6
|
+
* implements it, and the value goes out as that class says rather than
|
|
7
|
+
* as whatever `String()` makes of it. The result is followed rather than
|
|
8
|
+
* returned, because what it hands back may itself be a `Date`, an array,
|
|
9
|
+
* a `Buffer` or another such value.
|
|
10
|
+
*
|
|
11
|
+
* @param v The value a parameter is about to be written from.
|
|
12
|
+
* @returns The value to write, which is `v` itself unless it had one.
|
|
13
|
+
* @throws TypeError if the values form a cycle.
|
|
14
|
+
*/
|
|
15
|
+
/* Only for a parameter with no declared type. A declared type owns its
|
|
16
|
+
own encoding and is an answer the caller gave, not a guess.
|
|
17
|
+
|
|
18
|
+
This client's own classes are unaffected: every one of their
|
|
19
|
+
`toPostgres()` is `return this.toString()`, which is what the path
|
|
20
|
+
below used to reach anyway. What changes is a caller's class, which
|
|
21
|
+
used to be written `[object Object]` - silently, with a row written
|
|
22
|
+
and no error. */
|
|
23
|
+
export function resolveToPostgres(v) {
|
|
24
|
+
if (v === null || typeof v !== 'object' || typeof v.toPostgres !== 'function')
|
|
25
|
+
return v;
|
|
26
|
+
const seen = [];
|
|
27
|
+
while (v !== null &&
|
|
28
|
+
typeof v === 'object' &&
|
|
29
|
+
typeof v.toPostgres === 'function') {
|
|
30
|
+
if (seen.includes(v))
|
|
31
|
+
throw new TypeError('Circular reference while preparing a parameter: toPostgres() returned a value that leads back to itself');
|
|
32
|
+
seen.push(v);
|
|
33
|
+
v = v.toPostgres();
|
|
34
|
+
}
|
|
35
|
+
return v;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The text an undeclared parameter - or one element of an undeclared
|
|
39
|
+
* array - goes out as.
|
|
40
|
+
*
|
|
41
|
+
* Follows `toPostgres()` first, then writes a plain object as JSON and
|
|
42
|
+
* anything else as its own text.
|
|
43
|
+
*
|
|
44
|
+
* @param v The value to render.
|
|
45
|
+
* @returns What to put on the wire, before any array quoting.
|
|
46
|
+
*/
|
|
47
|
+
/* The two rules `pg`'s `prepareValue` has that this path did not. The
|
|
48
|
+
rest of its rules are either already here in their own branch - a
|
|
49
|
+
Date, an array, a Buffer - or deliberately not taken: it writes a Date
|
|
50
|
+
with a `T` where this client writes a space, and quotes the elements
|
|
51
|
+
of a number array where this client writes them bare, which is 10-26%
|
|
52
|
+
smaller and parses identically. Those are spellings the server reads
|
|
53
|
+
the same way; these two are a value that arrives as something else. */
|
|
54
|
+
export function unspecifiedText(v) {
|
|
55
|
+
v = resolveToPostgres(v);
|
|
56
|
+
if (v !== null &&
|
|
57
|
+
typeof v === 'object' &&
|
|
58
|
+
!(v instanceof Date) &&
|
|
59
|
+
!Buffer.isBuffer(v) &&
|
|
60
|
+
!Array.isArray(v))
|
|
61
|
+
return JSON.stringify(v);
|
|
62
|
+
return '' + v;
|
|
63
|
+
}
|