@depup/postgres 3.4.8-depup.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.
@@ -0,0 +1,367 @@
1
+ const { Query } = require('./query.js')
2
+ const { Errors } = require('./errors.js')
3
+
4
+ const types = module.exports.types = {
5
+ string: {
6
+ to: 25,
7
+ from: null, // defaults to string
8
+ serialize: x => '' + x
9
+ },
10
+ number: {
11
+ to: 0,
12
+ from: [21, 23, 26, 700, 701],
13
+ serialize: x => '' + x,
14
+ parse: x => +x
15
+ },
16
+ json: {
17
+ to: 114,
18
+ from: [114, 3802],
19
+ serialize: x => JSON.stringify(x),
20
+ parse: x => JSON.parse(x)
21
+ },
22
+ boolean: {
23
+ to: 16,
24
+ from: 16,
25
+ serialize: x => x === true ? 't' : 'f',
26
+ parse: x => x === 't'
27
+ },
28
+ date: {
29
+ to: 1184,
30
+ from: [1082, 1114, 1184],
31
+ serialize: x => (x instanceof Date ? x : new Date(x)).toISOString(),
32
+ parse: x => new Date(x)
33
+ },
34
+ bytea: {
35
+ to: 17,
36
+ from: 17,
37
+ serialize: x => '\\x' + Buffer.from(x).toString('hex'),
38
+ parse: x => Buffer.from(x.slice(2), 'hex')
39
+ }
40
+ }
41
+
42
+ class NotTagged { then() { notTagged() } catch() { notTagged() } finally() { notTagged() }}
43
+
44
+ const Identifier = module.exports.Identifier = class Identifier extends NotTagged {
45
+ constructor(value) {
46
+ super()
47
+ this.value = escapeIdentifier(value)
48
+ }
49
+ }
50
+
51
+ const Parameter = module.exports.Parameter = class Parameter extends NotTagged {
52
+ constructor(value, type, array) {
53
+ super()
54
+ this.value = value
55
+ this.type = type
56
+ this.array = array
57
+ }
58
+ }
59
+
60
+ const Builder = module.exports.Builder = class Builder extends NotTagged {
61
+ constructor(first, rest) {
62
+ super()
63
+ this.first = first
64
+ this.rest = rest
65
+ }
66
+
67
+ build(before, parameters, types, options) {
68
+ const keyword = builders.map(([x, fn]) => ({ fn, i: before.search(x) })).sort((a, b) => a.i - b.i).pop()
69
+ return keyword.i === -1
70
+ ? escapeIdentifiers(this.first, options)
71
+ : keyword.fn(this.first, this.rest, parameters, types, options)
72
+ }
73
+ }
74
+
75
+ module.exports.handleValue = handleValue;function handleValue(x, parameters, types, options) {
76
+ let value = x instanceof Parameter ? x.value : x
77
+ if (value === undefined) {
78
+ x instanceof Parameter
79
+ ? x.value = options.transform.undefined
80
+ : value = x = options.transform.undefined
81
+
82
+ if (value === undefined)
83
+ throw Errors.generic('UNDEFINED_VALUE', 'Undefined values are not allowed')
84
+ }
85
+
86
+ return '$' + (types.push(
87
+ x instanceof Parameter
88
+ ? (parameters.push(x.value), x.array
89
+ ? x.array[x.type || inferType(x.value)] || x.type || firstIsString(x.value)
90
+ : x.type
91
+ )
92
+ : (parameters.push(x), inferType(x))
93
+ ))
94
+ }
95
+
96
+ const defaultHandlers = typeHandlers(types)
97
+
98
+ module.exports.stringify = stringify;function stringify(q, string, value, parameters, types, options) { // eslint-disable-line
99
+ for (let i = 1; i < q.strings.length; i++) {
100
+ string += (stringifyValue(string, value, parameters, types, options)) + q.strings[i]
101
+ value = q.args[i]
102
+ }
103
+
104
+ return string
105
+ }
106
+
107
+ function stringifyValue(string, value, parameters, types, o) {
108
+ return (
109
+ value instanceof Builder ? value.build(string, parameters, types, o) :
110
+ value instanceof Query ? fragment(value, parameters, types, o) :
111
+ value instanceof Identifier ? value.value :
112
+ value && value[0] instanceof Query ? value.reduce((acc, x) => acc + ' ' + fragment(x, parameters, types, o), '') :
113
+ handleValue(value, parameters, types, o)
114
+ )
115
+ }
116
+
117
+ function fragment(q, parameters, types, options) {
118
+ q.fragment = true
119
+ return stringify(q, q.strings[0], q.args[0], parameters, types, options)
120
+ }
121
+
122
+ function valuesBuilder(first, parameters, types, columns, options) {
123
+ return first.map(row =>
124
+ '(' + columns.map(column =>
125
+ stringifyValue('values', row[column], parameters, types, options)
126
+ ).join(',') + ')'
127
+ ).join(',')
128
+ }
129
+
130
+ function values(first, rest, parameters, types, options) {
131
+ const multi = Array.isArray(first[0])
132
+ const columns = rest.length ? rest.flat() : Object.keys(multi ? first[0] : first)
133
+ return valuesBuilder(multi ? first : [first], parameters, types, columns, options)
134
+ }
135
+
136
+ function select(first, rest, parameters, types, options) {
137
+ typeof first === 'string' && (first = [first].concat(rest))
138
+ if (Array.isArray(first))
139
+ return escapeIdentifiers(first, options)
140
+
141
+ let value
142
+ const columns = rest.length ? rest.flat() : Object.keys(first)
143
+ return columns.map(x => {
144
+ value = first[x]
145
+ return (
146
+ value instanceof Query ? fragment(value, parameters, types, options) :
147
+ value instanceof Identifier ? value.value :
148
+ handleValue(value, parameters, types, options)
149
+ ) + ' as ' + escapeIdentifier(options.transform.column.to ? options.transform.column.to(x) : x)
150
+ }).join(',')
151
+ }
152
+
153
+ const builders = Object.entries({
154
+ values,
155
+ in: (...xs) => {
156
+ const x = values(...xs)
157
+ return x === '()' ? '(null)' : x
158
+ },
159
+ select,
160
+ as: select,
161
+ returning: select,
162
+ '\\(': select,
163
+
164
+ update(first, rest, parameters, types, options) {
165
+ return (rest.length ? rest.flat() : Object.keys(first)).map(x =>
166
+ escapeIdentifier(options.transform.column.to ? options.transform.column.to(x) : x) +
167
+ '=' + stringifyValue('values', first[x], parameters, types, options)
168
+ )
169
+ },
170
+
171
+ insert(first, rest, parameters, types, options) {
172
+ const columns = rest.length ? rest.flat() : Object.keys(Array.isArray(first) ? first[0] : first)
173
+ return '(' + escapeIdentifiers(columns, options) + ')values' +
174
+ valuesBuilder(Array.isArray(first) ? first : [first], parameters, types, columns, options)
175
+ }
176
+ }).map(([x, fn]) => ([new RegExp('((?:^|[\\s(])' + x + '(?:$|[\\s(]))(?![\\s\\S]*\\1)', 'i'), fn]))
177
+
178
+ function notTagged() {
179
+ throw Errors.generic('NOT_TAGGED_CALL', 'Query not called as a tagged template literal')
180
+ }
181
+
182
+ const serializers = module.exports.serializers = defaultHandlers.serializers
183
+ const parsers = module.exports.parsers = defaultHandlers.parsers
184
+
185
+ const END = module.exports.END = {}
186
+
187
+ function firstIsString(x) {
188
+ if (Array.isArray(x))
189
+ return firstIsString(x[0])
190
+ return typeof x === 'string' ? 1009 : 0
191
+ }
192
+
193
+ const mergeUserTypes = module.exports.mergeUserTypes = function(types) {
194
+ const user = typeHandlers(types || {})
195
+ return {
196
+ serializers: Object.assign({}, serializers, user.serializers),
197
+ parsers: Object.assign({}, parsers, user.parsers)
198
+ }
199
+ }
200
+
201
+ function typeHandlers(types) {
202
+ return Object.keys(types).reduce((acc, k) => {
203
+ types[k].from && [].concat(types[k].from).forEach(x => acc.parsers[x] = types[k].parse)
204
+ if (types[k].serialize) {
205
+ acc.serializers[types[k].to] = types[k].serialize
206
+ types[k].from && [].concat(types[k].from).forEach(x => acc.serializers[x] = types[k].serialize)
207
+ }
208
+ return acc
209
+ }, { parsers: {}, serializers: {} })
210
+ }
211
+
212
+ function escapeIdentifiers(xs, { transform: { column } }) {
213
+ return xs.map(x => escapeIdentifier(column.to ? column.to(x) : x)).join(',')
214
+ }
215
+
216
+ const escapeIdentifier = module.exports.escapeIdentifier = function escape(str) {
217
+ return '"' + str.replace(/"/g, '""').replace(/\./g, '"."') + '"'
218
+ }
219
+
220
+ const inferType = module.exports.inferType = function inferType(x) {
221
+ return (
222
+ x instanceof Parameter ? x.type :
223
+ x instanceof Date ? 1184 :
224
+ x instanceof Uint8Array ? 17 :
225
+ (x === true || x === false) ? 16 :
226
+ typeof x === 'bigint' ? 20 :
227
+ Array.isArray(x) ? inferType(x[0]) :
228
+ 0
229
+ )
230
+ }
231
+
232
+ const escapeBackslash = /\\/g
233
+ const escapeQuote = /"/g
234
+
235
+ function arrayEscape(x) {
236
+ return x
237
+ .replace(escapeBackslash, '\\\\')
238
+ .replace(escapeQuote, '\\"')
239
+ }
240
+
241
+ const arraySerializer = module.exports.arraySerializer = function arraySerializer(xs, serializer, options, typarray) {
242
+ if (Array.isArray(xs) === false)
243
+ return xs
244
+
245
+ if (!xs.length)
246
+ return '{}'
247
+
248
+ const first = xs[0]
249
+ // Only _box (1020) has the ';' delimiter for arrays, all other types use the ',' delimiter
250
+ const delimiter = typarray === 1020 ? ';' : ','
251
+
252
+ if (Array.isArray(first) && !first.type)
253
+ return '{' + xs.map(x => arraySerializer(x, serializer, options, typarray)).join(delimiter) + '}'
254
+
255
+ return '{' + xs.map(x => {
256
+ if (x === undefined) {
257
+ x = options.transform.undefined
258
+ if (x === undefined)
259
+ throw Errors.generic('UNDEFINED_VALUE', 'Undefined values are not allowed')
260
+ }
261
+
262
+ return x === null
263
+ ? 'null'
264
+ : '"' + arrayEscape(serializer ? serializer(x.type ? x.value : x) : '' + x) + '"'
265
+ }).join(delimiter) + '}'
266
+ }
267
+
268
+ const arrayParserState = {
269
+ i: 0,
270
+ char: null,
271
+ str: '',
272
+ quoted: false,
273
+ last: 0
274
+ }
275
+
276
+ const arrayParser = module.exports.arrayParser = function arrayParser(x, parser, typarray) {
277
+ arrayParserState.i = arrayParserState.last = 0
278
+ return arrayParserLoop(arrayParserState, x, parser, typarray)
279
+ }
280
+
281
+ function arrayParserLoop(s, x, parser, typarray) {
282
+ const xs = []
283
+ // Only _box (1020) has the ';' delimiter for arrays, all other types use the ',' delimiter
284
+ const delimiter = typarray === 1020 ? ';' : ','
285
+ for (; s.i < x.length; s.i++) {
286
+ s.char = x[s.i]
287
+ if (s.quoted) {
288
+ if (s.char === '\\') {
289
+ s.str += x[++s.i]
290
+ } else if (s.char === '"') {
291
+ xs.push(parser ? parser(s.str) : s.str)
292
+ s.str = ''
293
+ s.quoted = x[s.i + 1] === '"'
294
+ s.last = s.i + 2
295
+ } else {
296
+ s.str += s.char
297
+ }
298
+ } else if (s.char === '"') {
299
+ s.quoted = true
300
+ } else if (s.char === '{') {
301
+ s.last = ++s.i
302
+ xs.push(arrayParserLoop(s, x, parser, typarray))
303
+ } else if (s.char === '}') {
304
+ s.quoted = false
305
+ s.last < s.i && xs.push(parser ? parser(x.slice(s.last, s.i)) : x.slice(s.last, s.i))
306
+ s.last = s.i + 1
307
+ break
308
+ } else if (s.char === delimiter && s.p !== '}' && s.p !== '"') {
309
+ xs.push(parser ? parser(x.slice(s.last, s.i)) : x.slice(s.last, s.i))
310
+ s.last = s.i + 1
311
+ }
312
+ s.p = s.char
313
+ }
314
+ s.last < s.i && xs.push(parser ? parser(x.slice(s.last, s.i + 1)) : x.slice(s.last, s.i + 1))
315
+ return xs
316
+ }
317
+
318
+ const toCamel = module.exports.toCamel = x => {
319
+ let str = x[0]
320
+ for (let i = 1; i < x.length; i++)
321
+ str += x[i] === '_' ? x[++i].toUpperCase() : x[i]
322
+ return str
323
+ }
324
+
325
+ const toPascal = module.exports.toPascal = x => {
326
+ let str = x[0].toUpperCase()
327
+ for (let i = 1; i < x.length; i++)
328
+ str += x[i] === '_' ? x[++i].toUpperCase() : x[i]
329
+ return str
330
+ }
331
+
332
+ const toKebab = module.exports.toKebab = x => x.replace(/_/g, '-')
333
+
334
+ const fromCamel = module.exports.fromCamel = x => x.replace(/([A-Z])/g, '_$1').toLowerCase()
335
+ const fromPascal = module.exports.fromPascal = x => (x.slice(0, 1) + x.slice(1).replace(/([A-Z])/g, '_$1')).toLowerCase()
336
+ const fromKebab = module.exports.fromKebab = x => x.replace(/-/g, '_')
337
+
338
+ function createJsonTransform(fn) {
339
+ return function jsonTransform(x, column) {
340
+ return typeof x === 'object' && x !== null && (column.type === 114 || column.type === 3802)
341
+ ? Array.isArray(x)
342
+ ? x.map(x => jsonTransform(x, column))
343
+ : Object.entries(x).reduce((acc, [k, v]) => Object.assign(acc, { [fn(k)]: jsonTransform(v, column) }), {})
344
+ : x
345
+ }
346
+ }
347
+
348
+ toCamel.column = { from: toCamel }
349
+ toCamel.value = { from: createJsonTransform(toCamel) }
350
+ fromCamel.column = { to: fromCamel }
351
+
352
+ const camel = module.exports.camel = { ...toCamel }
353
+ camel.column.to = fromCamel
354
+
355
+ toPascal.column = { from: toPascal }
356
+ toPascal.value = { from: createJsonTransform(toPascal) }
357
+ fromPascal.column = { to: fromPascal }
358
+
359
+ const pascal = module.exports.pascal = { ...toPascal }
360
+ pascal.column.to = fromPascal
361
+
362
+ toKebab.column = { from: toKebab }
363
+ toKebab.value = { from: createJsonTransform(toKebab) }
364
+ fromKebab.column = { to: fromKebab }
365
+
366
+ const kebab = module.exports.kebab = { ...toKebab }
367
+ kebab.column.to = fromKebab
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@depup/postgres",
3
+ "version": "3.4.8-depup.0",
4
+ "description": "[DepUp] Fastest full featured PostgreSQL client for Node.js",
5
+ "type": "module",
6
+ "module": "src/index.js",
7
+ "main": "cjs/src/index.js",
8
+ "exports": {
9
+ "types": "./types/index.d.ts",
10
+ "bun": "./src/index.js",
11
+ "workerd": "./cf/src/index.js",
12
+ "import": "./src/index.js",
13
+ "default": "./cjs/src/index.js"
14
+ },
15
+ "types": "types/index.d.ts",
16
+ "typings": "types/index.d.ts",
17
+ "engines": {
18
+ "node": ">=12"
19
+ },
20
+ "scripts": {
21
+ "build": "npm run build:cjs && npm run build:deno && npm run build:cf",
22
+ "build:cjs": "node transpile.cjs",
23
+ "build:deno": "node transpile.deno.js",
24
+ "build:cf": "node transpile.cf.js",
25
+ "test": "npm run test:esm && npm run test:cjs && npm run test:deno",
26
+ "test:esm": "node tests/index.js",
27
+ "test:cjs": "npm run build:cjs && cd cjs/tests && node index.js && cd ../../",
28
+ "test:deno": "npm run build:deno && cd deno/tests && deno run --no-lock --allow-all --unsafely-ignore-certificate-errors index.js && cd ../../",
29
+ "lint": "eslint src && eslint tests"
30
+ },
31
+ "files": [
32
+ "/cf/src",
33
+ "/cf/polyfills.js",
34
+ "/cjs/src",
35
+ "/cjs/package.json",
36
+ "/src",
37
+ "/types",
38
+ "changes.json",
39
+ "README.md"
40
+ ],
41
+ "author": "Rasmus Porsager <rasmus@porsager.com> (https://www.porsager.com)",
42
+ "funding": {
43
+ "type": "individual",
44
+ "url": "https://github.com/sponsors/porsager"
45
+ },
46
+ "license": "Unlicense",
47
+ "repository": "porsager/postgres",
48
+ "homepage": "https://github.com/porsager/postgres",
49
+ "bugs": "https://github.com/porsager/postgres/issues",
50
+ "keywords": [
51
+ "depup",
52
+ "dependency-bumped",
53
+ "updated-deps",
54
+ "postgres",
55
+ "driver",
56
+ "postgresql",
57
+ "postgres.js",
58
+ "postrges",
59
+ "postgre",
60
+ "client",
61
+ "sql",
62
+ "db",
63
+ "pg",
64
+ "database"
65
+ ],
66
+ "depup": {
67
+ "changes": {},
68
+ "depsUpdated": 0,
69
+ "originalPackage": "postgres",
70
+ "originalVersion": "3.4.8",
71
+ "processedAt": "2026-03-17T16:37:34.471Z",
72
+ "smokeTest": "passed"
73
+ }
74
+ }
package/src/bytes.js ADDED
@@ -0,0 +1,78 @@
1
+ const size = 256
2
+ let buffer = Buffer.allocUnsafe(size)
3
+
4
+ const messages = 'BCcDdEFfHPpQSX'.split('').reduce((acc, x) => {
5
+ const v = x.charCodeAt(0)
6
+ acc[x] = () => {
7
+ buffer[0] = v
8
+ b.i = 5
9
+ return b
10
+ }
11
+ return acc
12
+ }, {})
13
+
14
+ const b = Object.assign(reset, messages, {
15
+ N: String.fromCharCode(0),
16
+ i: 0,
17
+ inc(x) {
18
+ b.i += x
19
+ return b
20
+ },
21
+ str(x) {
22
+ const length = Buffer.byteLength(x)
23
+ fit(length)
24
+ b.i += buffer.write(x, b.i, length, 'utf8')
25
+ return b
26
+ },
27
+ i16(x) {
28
+ fit(2)
29
+ buffer.writeUInt16BE(x, b.i)
30
+ b.i += 2
31
+ return b
32
+ },
33
+ i32(x, i) {
34
+ if (i || i === 0) {
35
+ buffer.writeUInt32BE(x, i)
36
+ return b
37
+ }
38
+ fit(4)
39
+ buffer.writeUInt32BE(x, b.i)
40
+ b.i += 4
41
+ return b
42
+ },
43
+ z(x) {
44
+ fit(x)
45
+ buffer.fill(0, b.i, b.i + x)
46
+ b.i += x
47
+ return b
48
+ },
49
+ raw(x) {
50
+ buffer = Buffer.concat([buffer.subarray(0, b.i), x])
51
+ b.i = buffer.length
52
+ return b
53
+ },
54
+ end(at = 1) {
55
+ buffer.writeUInt32BE(b.i - at, at)
56
+ const out = buffer.subarray(0, b.i)
57
+ b.i = 0
58
+ buffer = Buffer.allocUnsafe(size)
59
+ return out
60
+ }
61
+ })
62
+
63
+ export default b
64
+
65
+ function fit(x) {
66
+ if (buffer.length - b.i < x) {
67
+ const prev = buffer
68
+ , length = prev.length
69
+
70
+ buffer = Buffer.allocUnsafe(length + (length >> 1) + x)
71
+ prev.copy(buffer)
72
+ }
73
+ }
74
+
75
+ function reset() {
76
+ b.i = 0
77
+ return b
78
+ }