mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
More cf compat work
This commit is contained in:
parent
56762beebf
commit
69e56976c6
1
packages/pg-cloudflare/esm/index.mjs
Normal file
1
packages/pg-cloudflare/esm/index.mjs
Normal file
@ -0,0 +1 @@
|
||||
export const TEST = 'true'
|
||||
@ -4,12 +4,18 @@
|
||||
"description": "A socket implementation that can run on Cloudflare Workers using native TCP connections.",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"type": "module",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"ts-node": "^8.5.4",
|
||||
"typescript": "^4.0.3"
|
||||
},
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./esm/index.mjs",
|
||||
"require": "./dist/index.js",
|
||||
"default": "./dist/index.js"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"build:watch": "tsc --watch",
|
||||
|
||||
@ -37,7 +37,8 @@ export class CloudflareSocket extends EventEmitter {
|
||||
if (connectListener) this.once('connect', connectListener)
|
||||
|
||||
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._cfWriter = this._cfSocket.writable.getWriter()
|
||||
this._addClosedHandler()
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "ES2020",
|
||||
"module": "node16",
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"target": "ES2020",
|
||||
"target": "es2020",
|
||||
"noImplicitAny": true,
|
||||
"moduleResolution": "node",
|
||||
"moduleResolution": "node16",
|
||||
"sourceMap": true,
|
||||
"outDir": "dist",
|
||||
"incremental": true,
|
||||
|
||||
@ -35,13 +35,15 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@cloudflare/workers-types": "^4.20230404.0",
|
||||
"@cloudflare/vitest-pool-workers": "0.8.12",
|
||||
"async": "2.6.4",
|
||||
"bluebird": "3.7.2",
|
||||
"co": "4.6.0",
|
||||
"pg-copy-streams": "0.3.0",
|
||||
"typescript": "^4.0.3",
|
||||
"vitest": "~3.0.9",
|
||||
"workerd": "^1.20230419.0",
|
||||
"wrangler": "3.58.0"
|
||||
"wrangler": "^3.x"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"pg-cloudflare": "^1.1.2-alpha.0"
|
||||
|
||||
13
packages/pg/test/cloudflare/vitest-cf.test.ts
Normal file
13
packages/pg/test/cloudflare/vitest-cf.test.ts
Normal 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()
|
||||
})
|
||||
11
packages/pg/test/vitest.config.mts
Normal file
11
packages/pg/test/vitest.config.mts
Normal file
@ -0,0 +1,11 @@
|
||||
import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config'
|
||||
|
||||
export default defineWorkersConfig({
|
||||
test: {
|
||||
poolOptions: {
|
||||
workers: {
|
||||
wrangler: { configPath: './wrangler.jsonc' },
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -1,5 +1,4 @@
|
||||
name = "pg-cf-test"
|
||||
main = "src/index.ts"
|
||||
compatibility_date = "2023-04-04"
|
||||
compatibility_flags = ["tcp_sockets_support"]
|
||||
node_compat = true
|
||||
compatibility_flags = ["tcp_sockets_support", "nodejs_compat"]
|
||||
|
||||
48
packages/pg/test/wrangler.jsonc
Normal file
48
packages/pg/test/wrangler.jsonc
Normal 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" }]
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user