Compare commits

...

14 Commits

Author SHA1 Message Date
Brian Carlson
306fa83d84 Publish
- pg-cloudflare@1.1.2-alpha.1
 - pg-cursor@2.13.2-alpha.1
 - pg-esm-test@1.0.1-alpha.1
 - pg-pool@3.8.1-alpha.1
 - pg-query-stream@4.8.2-alpha.1
 - pg@8.14.2-alpha.1
2025-04-21 16:16:16 -05:00
Brian Carlson
69e56976c6 More cf compat work 2025-04-21 16:15:46 -05:00
Brian Carlson
56762beebf Publish
- pg-cloudflare@1.1.2-alpha.0
 - pg-connection-string@2.7.1-alpha.0
 - pg-cursor@2.13.2-alpha.0
 - pg-esm-test@1.0.1-alpha.0
 - pg-native@3.3.1-alpha.0
 - pg-pool@3.8.1-alpha.0
 - pg-protocol@1.8.1-alpha.0
 - pg-query-stream@4.8.2-alpha.0
 - pg@8.14.2-alpha.0
2025-04-21 14:43:48 -05:00
Brian Carlson
6a9b873f5f Update PR copilot review 2025-04-21 14:04:24 -05:00
Brian Carlson
ffd5adc583 Add query-stream and cursor as esm exports 2025-04-21 13:57:24 -05:00
Brian Carlson
0a0e298e06 Add tests for connection-string and fix cloudflare module type and esm compat 2025-04-21 13:51:46 -05:00
Brian Carlson
0cb8fd4216 Begin moving files to proper extension and adding tests 2025-04-21 13:22:01 -05:00
Brian Carlson
6949c7ad73 Add (failing) test for esm compat 2025-04-21 13:09:50 -05:00
Brian Carlson
739308463d Fix broken tests 2025-04-21 12:32:44 -05:00
Brian Carlson
c484282ace Merge branch 'master' of github.com:mesqueeb/node-postgres into mesqueeb-master 2025-04-21 11:59:17 -05:00
Luca Ban
8a58659ed3 lint 2025-03-21 06:42:55 +13:00
Luca Ban
b4c1a4e935 fix: add missing types 2025-03-20 08:38:56 +13:00
Luca Ban
c2cbc2b0b1 fix: add defaults as per arethetypeswrong report 2025-03-20 08:38:51 +13:00
Luca Ban
98bc876b49 build: add esm exports 2025-03-20 08:23:45 +13:00
35 changed files with 1561 additions and 261 deletions

View File

@ -10,7 +10,7 @@
"packages/*" "packages/*"
], ],
"scripts": { "scripts": {
"test": "yarn lerna exec yarn test", "test": "yarn lerna exec --concurrency 1 yarn test",
"build": "tsc --build", "build": "tsc --build",
"build:watch": "tsc --build --watch", "build:watch": "tsc --build --watch",
"docs:build": "cd docs && yarn build", "docs:build": "cd docs && yarn build",

View File

@ -0,0 +1 @@
export const TEST = 'true'

View File

@ -1,8 +1,8 @@
{ {
"name": "pg-cloudflare", "name": "pg-cloudflare",
"version": "1.1.1", "version": "1.1.2-alpha.1",
"description": "A socket implementation that can run on Cloudflare Workers using native TCP connections.", "description": "A socket implementation that can run on Cloudflare Workers using native TCP connections.",
"main": "dist/empty.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
@ -10,8 +10,11 @@
"typescript": "^4.0.3" "typescript": "^4.0.3"
}, },
"exports": { "exports": {
"workerd": "./dist/index.js", ".": {
"default": "./dist/empty.js" "import": "./esm/index.mjs",
"require": "./dist/index.js",
"default": "./dist/index.js"
}
}, },
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",
@ -26,6 +29,7 @@
}, },
"files": [ "files": [
"/dist/*{js,ts,map}", "/dist/*{js,ts,map}",
"/src" "/src",
"/esm"
] ]
} }

View File

@ -37,7 +37,8 @@ export class CloudflareSocket extends EventEmitter {
if (connectListener) this.once('connect', connectListener) if (connectListener) this.once('connect', connectListener)
const options: SocketOptions = this.ssl ? { secureTransport: 'starttls' } : {} const options: SocketOptions = this.ssl ? { secureTransport: 'starttls' } : {}
const { connect } = await import('cloudflare:sockets') const mod = await import('cloudflare:sockets')
const connect = mod.connect
this._cfSocket = connect(`${host}:${port}`, options) this._cfSocket = connect(`${host}:${port}`, options)
this._cfWriter = this._cfSocket.writable.getWriter() this._cfWriter = this._cfSocket.writable.getWriter()
this._addClosedHandler() this._addClosedHandler()

View File

@ -1,12 +1,12 @@
{ {
"compilerOptions": { "compilerOptions": {
"module": "ES2020", "module": "node16",
"esModuleInterop": true, "esModuleInterop": true,
"allowSyntheticDefaultImports": true, "allowSyntheticDefaultImports": true,
"strict": true, "strict": true,
"target": "ES2020", "target": "es2020",
"noImplicitAny": true, "noImplicitAny": true,
"moduleResolution": "node", "moduleResolution": "node16",
"sourceMap": true, "sourceMap": true,
"outDir": "dist", "outDir": "dist",
"incremental": true, "incremental": true,

View File

@ -0,0 +1,7 @@
// ESM wrapper for pg-connection-string
import connectionString from '../index.js'
// Re-export the parse function
export const parse = connectionString.parse
export const toClientConfig = connectionString.toClientConfig
export const parseIntoClientConfig = connectionString.parseIntoClientConfig

View File

@ -1,9 +1,17 @@
{ {
"name": "pg-connection-string", "name": "pg-connection-string",
"version": "2.7.0", "version": "2.7.1-alpha.0",
"description": "Functions for dealing with a PostgresSQL connection string", "description": "Functions for dealing with a PostgresSQL connection string",
"main": "./index.js", "main": "./index.js",
"types": "./index.d.ts", "types": "./index.d.ts",
"exports": {
".": {
"types": "./index.d.ts",
"import": "./esm/index.mjs",
"require": "./index.js",
"default": "./index.js"
}
},
"scripts": { "scripts": {
"test": "istanbul cover _mocha && npm run check-coverage", "test": "istanbul cover _mocha && npm run check-coverage",
"check-coverage": "istanbul check-coverage --statements 100 --branches 100 --lines 100 --functions 100", "check-coverage": "istanbul check-coverage --statements 100 --branches 100 --lines 100 --functions 100",
@ -34,6 +42,7 @@
}, },
"files": [ "files": [
"index.js", "index.js",
"index.d.ts" "index.d.ts",
"esm"
] ]
} }

View File

@ -0,0 +1,5 @@
// ESM wrapper for pg-cursor
import Cursor from '../index.js'
// Export as default only to match CJS module
export default Cursor

View File

@ -1,6 +1,7 @@
'use strict' 'use strict'
const Result = require('pg/lib/result.js') const pg = require('pg')
const prepare = require('pg/lib/utils.js').prepareValue const { Result, utils } = pg
const prepare = utils.prepareValue
const EventEmitter = require('events').EventEmitter const EventEmitter = require('events').EventEmitter
const util = require('util') const util = require('util')

View File

@ -1,8 +1,15 @@
{ {
"name": "pg-cursor", "name": "pg-cursor",
"version": "2.13.1", "version": "2.13.2-alpha.1",
"description": "Query cursor extension for node-postgres", "description": "Query cursor extension for node-postgres",
"main": "index.js", "main": "index.js",
"exports": {
".": {
"import": "./esm/index.mjs",
"require": "./index.js",
"default": "./index.js"
}
},
"directories": { "directories": {
"test": "test" "test": "test"
}, },
@ -18,9 +25,13 @@
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"mocha": "^10.5.2", "mocha": "^10.5.2",
"pg": "^8.14.1" "pg": "^8.14.2-alpha.1"
}, },
"peerDependencies": { "peerDependencies": {
"pg": "^8" "pg": "^8"
} },
"files": [
"index.js",
"esm"
]
} }

View File

@ -0,0 +1,26 @@
{
"name": "pg-esm-test",
"version": "1.0.1-alpha.1",
"description": "A test module for PostgreSQL with ESM support",
"main": "index.js",
"type": "module",
"scripts": {
"test": "node --test"
},
"keywords": [
"postgres",
"postgresql",
"esm",
"test"
],
"devDependencies": {
"pg": "^8.14.2-alpha.1",
"pg-cloudflare": "^1.1.2-alpha.1",
"pg-cursor": "^2.13.2-alpha.1",
"pg-native": "^3.3.1-alpha.0",
"pg-pool": "^3.8.1-alpha.1",
"pg-query-stream": "^4.8.2-alpha.1"
},
"author": "Brian M. Carlson <brian.m.carlson@gmail.com>",
"license": "MIT"
}

View File

@ -0,0 +1,9 @@
import assert from 'node:assert'
import { describe, it } from 'node:test'
import { CloudflareSocket } from 'pg-cloudflare'
describe('pg-cloudflare', () => {
it('should export CloudflareSocket constructor', () => {
assert.ok(new CloudflareSocket())
})
})

View File

@ -0,0 +1,17 @@
import assert from 'node:assert'
import { describe, it } from 'node:test'
import { parse, toClientConfig, parseIntoClientConfig } from 'pg-connection-string'
describe('pg-connection-string', () => {
it('should export parse function', () => {
assert.strictEqual(typeof parse, 'function')
})
it('should export toClientConfig function', () => {
assert.strictEqual(typeof toClientConfig, 'function')
})
it('should export parseIntoClientConfig function', () => {
assert.strictEqual(typeof parseIntoClientConfig, 'function')
})
})

View File

@ -0,0 +1,9 @@
import assert from 'node:assert'
import { describe, it } from 'node:test'
import Cursor from 'pg-cursor'
describe('pg-cursor', () => {
it('should export Cursor constructor as default', () => {
assert.ok(new Cursor())
})
})

View File

@ -0,0 +1,9 @@
import assert from 'node:assert'
import { describe, it } from 'node:test'
import Client from 'pg-native'
describe('pg-native', () => {
it('should export Client constructor', () => {
assert.ok(new Client())
})
})

View File

@ -0,0 +1,9 @@
import assert from 'node:assert'
import { describe, it } from 'node:test'
import Pool from 'pg-pool'
describe('pg-pool', () => {
it('should export Pool constructor', () => {
assert.ok(new Pool())
})
})

View File

@ -0,0 +1,9 @@
import assert from 'node:assert'
import { describe, it } from 'node:test'
import QueryStream from 'pg-query-stream'
describe('pg-query-stream', () => {
it('should export QueryStream constructor as default', () => {
assert.ok(new QueryStream())
})
})

View File

@ -0,0 +1,17 @@
import assert from 'node:assert'
import { describe, it } from 'node:test'
import pg, { Client, Pool } from 'pg'
describe('pg', () => {
it('should export Client constructor', () => {
assert.ok(new Client())
})
it('should export Pool constructor', () => {
assert.ok(new Pool())
})
it('should still provide default export', () => {
assert.ok(new pg.Pool())
})
})

View File

@ -0,0 +1,5 @@
// ESM wrapper for pg-native
import Client from '../index.js'
// Export as default only to match CJS module
export default Client

View File

@ -1,8 +1,15 @@
{ {
"name": "pg-native", "name": "pg-native",
"version": "3.3.0", "version": "3.3.1-alpha.0",
"description": "A slightly nicer interface to Postgres over node-libpq", "description": "A slightly nicer interface to Postgres over node-libpq",
"main": "index.js", "main": "index.js",
"exports": {
".": {
"import": "./esm/index.mjs",
"require": "./index.js",
"default": "./index.js"
}
},
"scripts": { "scripts": {
"test": "mocha" "test": "mocha"
}, },
@ -34,5 +41,9 @@
"node-gyp": ">=10.x", "node-gyp": ">=10.x",
"okay": "^0.3.0", "okay": "^0.3.0",
"semver": "^4.1.0" "semver": "^4.1.0"
} },
"files": [
"index.js",
"esm"
]
} }

View File

@ -0,0 +1,5 @@
// ESM wrapper for pg-pool
import Pool from '../index.js'
// Export as default only to match CJS module
export default Pool

View File

@ -1,8 +1,15 @@
{ {
"name": "pg-pool", "name": "pg-pool",
"version": "3.8.0", "version": "3.8.1-alpha.1",
"description": "Connection pool for node-postgres", "description": "Connection pool for node-postgres",
"main": "index.js", "main": "index.js",
"exports": {
".": {
"import": "./esm/index.mjs",
"require": "./index.js",
"default": "./index.js"
}
},
"directories": { "directories": {
"test": "test" "test": "test"
}, },
@ -32,9 +39,13 @@
"expect.js": "0.3.1", "expect.js": "0.3.1",
"lodash": "^4.17.11", "lodash": "^4.17.11",
"mocha": "^10.5.2", "mocha": "^10.5.2",
"pg-cursor": "^1.3.0" "pg-cursor": "^2.13.2-alpha.1"
}, },
"peerDependencies": { "peerDependencies": {
"pg": ">=8.0" "pg": ">=8.0"
} },
"files": [
"index.js",
"esm"
]
} }

View File

@ -0,0 +1,11 @@
// ESM wrapper for pg-protocol
import protocol from '../dist/index.js'
// Re-export all the properties
export const DatabaseError = protocol.DatabaseError
export const SASL = protocol.SASL
export const serialize = protocol.serialize
export const parse = protocol.parse
// Re-export the default
export default protocol

View File

@ -1,9 +1,16 @@
{ {
"name": "pg-protocol", "name": "pg-protocol",
"version": "1.8.0", "version": "1.8.1-alpha.0",
"description": "The postgres client/server binary protocol, implemented in TypeScript", "description": "The postgres client/server binary protocol, implemented in TypeScript",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
"exports": {
".": {
"import": "./esm/index.js",
"require": "./dist/index.js",
"default": "./dist/index.js"
}
},
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@types/chai": "^4.2.7", "@types/chai": "^4.2.7",
@ -29,6 +36,7 @@
}, },
"files": [ "files": [
"/dist/*{js,ts,map}", "/dist/*{js,ts,map}",
"/src" "/src",
"/esm"
] ]
} }

View File

@ -0,0 +1,5 @@
// ESM wrapper for pg-query-stream
import QueryStream from '../dist/index.js'
// Export as default only to match CJS module
export default QueryStream

View File

@ -1,9 +1,16 @@
{ {
"name": "pg-query-stream", "name": "pg-query-stream",
"version": "4.8.1", "version": "4.8.2-alpha.1",
"description": "Postgres query result returned as readable stream", "description": "Postgres query result returned as readable stream",
"main": "./dist/index.js", "main": "./dist/index.js",
"types": "./dist/index.d.ts", "types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./esm/index.mjs",
"require": "./dist/index.js",
"default": "./dist/index.js"
}
},
"scripts": { "scripts": {
"test": "mocha -r ts-node/register test/**/*.ts" "test": "mocha -r ts-node/register test/**/*.ts"
}, },
@ -21,7 +28,8 @@
], ],
"files": [ "files": [
"/dist/*{js,ts,map}", "/dist/*{js,ts,map}",
"/src" "/src",
"/esm"
], ],
"author": "Brian M. Carlson", "author": "Brian M. Carlson",
"license": "MIT", "license": "MIT",
@ -37,7 +45,7 @@
"concat-stream": "~1.0.1", "concat-stream": "~1.0.1",
"eslint-plugin-promise": "^6.0.1", "eslint-plugin-promise": "^6.0.1",
"mocha": "^10.5.2", "mocha": "^10.5.2",
"pg": "^8.14.1", "pg": "^8.14.2-alpha.1",
"stream-spec": "~0.3.5", "stream-spec": "~0.3.5",
"ts-node": "^8.5.4", "ts-node": "^8.5.4",
"typescript": "^4.0.3" "typescript": "^4.0.3"
@ -46,6 +54,6 @@
"pg": "^8" "pg": "^8"
}, },
"dependencies": { "dependencies": {
"pg-cursor": "^2.13.1" "pg-cursor": "^2.13.2-alpha.1"
} }
} }

18
packages/pg/esm/index.mjs Normal file
View File

@ -0,0 +1,18 @@
// ESM wrapper for pg
import pg from '../lib/index.js'
// Re-export all the properties
export const Client = pg.Client
export const Pool = pg.Pool
export const Connection = pg.Connection
export const types = pg.types
export const Query = pg.Query
export const DatabaseError = pg.DatabaseError
export const escapeIdentifier = pg.escapeIdentifier
export const escapeLiteral = pg.escapeLiteral
// Also export the defaults
export const defaults = pg.defaults
// Re-export the default
export default pg

View File

@ -3,6 +3,8 @@
var Client = require('./client') var Client = require('./client')
var defaults = require('./defaults') var defaults = require('./defaults')
var Connection = require('./connection') var Connection = require('./connection')
var Result = require('./result')
var utils = require('./utils')
var Pool = require('pg-pool') var Pool = require('pg-pool')
const { DatabaseError } = require('pg-protocol') const { DatabaseError } = require('pg-protocol')
const { escapeIdentifier, escapeLiteral } = require('./utils') const { escapeIdentifier, escapeLiteral } = require('./utils')
@ -26,6 +28,8 @@ var PG = function (clientConstructor) {
this.DatabaseError = DatabaseError this.DatabaseError = DatabaseError
this.escapeIdentifier = escapeIdentifier this.escapeIdentifier = escapeIdentifier
this.escapeLiteral = escapeLiteral this.escapeLiteral = escapeLiteral
this.Result = Result
this.utils = utils
} }
if (typeof process.env.NODE_PG_FORCE_NATIVE !== 'undefined') { if (typeof process.env.NODE_PG_FORCE_NATIVE !== 'undefined') {

View File

@ -1,6 +1,6 @@
{ {
"name": "pg", "name": "pg",
"version": "8.14.1", "version": "8.14.2-alpha.1",
"description": "PostgreSQL client - pure javascript & libpq with the same API", "description": "PostgreSQL client - pure javascript & libpq with the same API",
"keywords": [ "keywords": [
"database", "database",
@ -19,25 +19,34 @@
}, },
"author": "Brian Carlson <brian.m.carlson@gmail.com>", "author": "Brian Carlson <brian.m.carlson@gmail.com>",
"main": "./lib", "main": "./lib",
"exports": {
".": {
"import": "./esm/index.mjs",
"require": "./lib/index.js",
"default": "./lib/index.js"
}
},
"dependencies": { "dependencies": {
"pg-connection-string": "^2.7.0", "pg-connection-string": "^2.7.1-alpha.0",
"pg-pool": "^3.8.0", "pg-pool": "^3.8.1-alpha.1",
"pg-protocol": "^1.8.0", "pg-protocol": "^1.8.1-alpha.0",
"pg-types": "^2.1.0", "pg-types": "^2.1.0",
"pgpass": "1.x" "pgpass": "1.x"
}, },
"devDependencies": { "devDependencies": {
"@cloudflare/vitest-pool-workers": "0.8.12",
"@cloudflare/workers-types": "^4.20230404.0", "@cloudflare/workers-types": "^4.20230404.0",
"async": "2.6.4", "async": "2.6.4",
"bluebird": "3.7.2", "bluebird": "3.7.2",
"co": "4.6.0", "co": "4.6.0",
"pg-copy-streams": "0.3.0", "pg-copy-streams": "0.3.0",
"typescript": "^4.0.3", "typescript": "^4.0.3",
"vitest": "~3.0.9",
"workerd": "^1.20230419.0", "workerd": "^1.20230419.0",
"wrangler": "3.58.0" "wrangler": "^3.x"
}, },
"optionalDependencies": { "optionalDependencies": {
"pg-cloudflare": "^1.1.1" "pg-cloudflare": "^1.1.2-alpha.1"
}, },
"peerDependencies": { "peerDependencies": {
"pg-native": ">=3.0.1" "pg-native": ">=3.0.1"
@ -52,6 +61,7 @@
}, },
"files": [ "files": [
"lib", "lib",
"esm",
"SPONSORS.md" "SPONSORS.md"
], ],
"license": "MIT", "license": "MIT",

View File

@ -0,0 +1,13 @@
import { Pool } from 'pg'
import { test } from 'vitest'
import assert from 'node:assert'
test('default', async () => {
const pool = new Pool({
connectionString: 'postgres://postgres:password@localhost:5432/postgres',
})
const result = await pool.query('SELECT $1::text as name', ['cloudflare'])
assert(result.rows[0].name === 'cloudflare')
pool.end()
})

View File

@ -0,0 +1,11 @@
import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config'
export default defineWorkersConfig({
test: {
poolOptions: {
workers: {
wrangler: { configPath: './wrangler.jsonc' },
},
},
},
})

View File

@ -24,7 +24,8 @@ async function test() {
}) })
try { try {
const resp = await worker.fetch('/') const resp = await worker.fetch('/')
const { rows } = await resp.json() const res = await resp.json()
const { rows } = res
assert.same(rows[0].text, 'Hello, World!') assert.same(rows[0].text, 'Hello, World!')
} finally { } finally {
await worker.stop() await worker.stop()

View File

@ -1,5 +1,4 @@
name = "pg-cf-test" name = "pg-cf-test"
main = "src/index.ts" main = "src/index.ts"
compatibility_date = "2023-04-04" compatibility_date = "2023-04-04"
compatibility_flags = ["tcp_sockets_support"] compatibility_flags = ["tcp_sockets_support", "nodejs_compat"]
node_compat = true

View File

@ -0,0 +1,48 @@
/**
* For more details on how to configure Wrangler, refer to:
* https://developers.cloudflare.com/workers/wrangler/configuration/
*/
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "my-first-worker",
"main": "src/index.ts",
"compatibility_date": "2025-04-07",
"compatibility_flags": ["nodejs_compat"],
"observability": {
"enabled": true
}
/**
* t
* Docs: https://developers.cloudflare.com/workers/configuration/smart-placement/#smart-placement
*/
// "placement": { "mode": "smart" },
/**
* Bindings
* Bindings allow your Worker to interact with resources on the Cloudflare Developer Platform, including
* databases, object storage, AI inference, real-time communication and more.
* https://developers.cloudflare.com/workers/runtime-apis/bindings/
*/
/**
* Environment Variables
* https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
*/
// "vars": { "MY_VARIABLE": "production_value" },
/**
* Note: Use secrets to store sensitive data.
* https://developers.cloudflare.com/workers/configuration/secrets/
*/
/**
* Static Assets
* https://developers.cloudflare.com/workers/static-assets/binding/
*/
// "assets": { "directory": "./public/", "binding": "ASSETS" },
/**
* Service Bindings (communicate between multiple Workers)
* https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
*/
// "services": [{ "binding": "MY_SERVICE", "service": "my-service" }]
}

1436
yarn.lock

File diff suppressed because it is too large Load Diff