More cf compat work

This commit is contained in:
Brian Carlson 2025-04-21 16:15:46 -05:00
parent 56762beebf
commit 69e56976c6
10 changed files with 1298 additions and 199 deletions

View File

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

View File

@ -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",

View File

@ -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()

View File

@ -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,

View File

@ -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"

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

@ -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"]

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" }]
}

1400
yarn.lock

File diff suppressed because it is too large Load Diff