Skip to content

Commit 69e5697

Browse files
committed
More cf compat work
1 parent 56762be commit 69e5697

10 files changed

Lines changed: 1298 additions & 199 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const TEST = 'true'

packages/pg-cloudflare/package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,18 @@
44
"description": "A socket implementation that can run on Cloudflare Workers using native TCP connections.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
7-
"type": "module",
87
"license": "MIT",
98
"devDependencies": {
109
"ts-node": "^8.5.4",
1110
"typescript": "^4.0.3"
1211
},
12+
"exports": {
13+
".": {
14+
"import": "./esm/index.mjs",
15+
"require": "./dist/index.js",
16+
"default": "./dist/index.js"
17+
}
18+
},
1319
"scripts": {
1420
"build": "tsc",
1521
"build:watch": "tsc --watch",

packages/pg-cloudflare/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ export class CloudflareSocket extends EventEmitter {
3737
if (connectListener) this.once('connect', connectListener)
3838

3939
const options: SocketOptions = this.ssl ? { secureTransport: 'starttls' } : {}
40-
const { connect } = await import('cloudflare:sockets')
40+
const mod = await import('cloudflare:sockets')
41+
const connect = mod.connect
4142
this._cfSocket = connect(`${host}:${port}`, options)
4243
this._cfWriter = this._cfSocket.writable.getWriter()
4344
this._addClosedHandler()

packages/pg-cloudflare/tsconfig.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"compilerOptions": {
3-
"module": "ES2020",
3+
"module": "node16",
44
"esModuleInterop": true,
55
"allowSyntheticDefaultImports": true,
66
"strict": true,
7-
"target": "ES2020",
7+
"target": "es2020",
88
"noImplicitAny": true,
9-
"moduleResolution": "node",
9+
"moduleResolution": "node16",
1010
"sourceMap": true,
1111
"outDir": "dist",
1212
"incremental": true,

packages/pg/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@
3535
},
3636
"devDependencies": {
3737
"@cloudflare/workers-types": "^4.20230404.0",
38+
"@cloudflare/vitest-pool-workers": "0.8.12",
3839
"async": "2.6.4",
3940
"bluebird": "3.7.2",
4041
"co": "4.6.0",
4142
"pg-copy-streams": "0.3.0",
4243
"typescript": "^4.0.3",
44+
"vitest": "~3.0.9",
4345
"workerd": "^1.20230419.0",
44-
"wrangler": "3.58.0"
46+
"wrangler": "^3.x"
4547
},
4648
"optionalDependencies": {
4749
"pg-cloudflare": "^1.1.2-alpha.0"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { Pool } from 'pg'
2+
import { test } from 'vitest'
3+
import assert from 'node:assert'
4+
5+
test('default', async () => {
6+
const pool = new Pool({
7+
connectionString: 'postgres://postgres:password@localhost:5432/postgres',
8+
})
9+
10+
const result = await pool.query('SELECT $1::text as name', ['cloudflare'])
11+
assert(result.rows[0].name === 'cloudflare')
12+
pool.end()
13+
})

packages/pg/test/vitest.config.mts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineWorkersConfig } from '@cloudflare/vitest-pool-workers/config'
2+
3+
export default defineWorkersConfig({
4+
test: {
5+
poolOptions: {
6+
workers: {
7+
wrangler: { configPath: './wrangler.jsonc' },
8+
},
9+
},
10+
},
11+
})
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
name = "pg-cf-test"
22
main = "src/index.ts"
33
compatibility_date = "2023-04-04"
4-
compatibility_flags = ["tcp_sockets_support"]
5-
node_compat = true
4+
compatibility_flags = ["tcp_sockets_support", "nodejs_compat"]

packages/pg/test/wrangler.jsonc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* For more details on how to configure Wrangler, refer to:
3+
* https://developers.cloudflare.com/workers/wrangler/configuration/
4+
*/
5+
{
6+
"$schema": "node_modules/wrangler/config-schema.json",
7+
"name": "my-first-worker",
8+
"main": "src/index.ts",
9+
"compatibility_date": "2025-04-07",
10+
"compatibility_flags": ["nodejs_compat"],
11+
"observability": {
12+
"enabled": true
13+
}
14+
/**
15+
* t
16+
* Docs: https://developers.cloudflare.com/workers/configuration/smart-placement/#smart-placement
17+
*/
18+
// "placement": { "mode": "smart" },
19+
20+
/**
21+
* Bindings
22+
* Bindings allow your Worker to interact with resources on the Cloudflare Developer Platform, including
23+
* databases, object storage, AI inference, real-time communication and more.
24+
* https://developers.cloudflare.com/workers/runtime-apis/bindings/
25+
*/
26+
27+
/**
28+
* Environment Variables
29+
* https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
30+
*/
31+
// "vars": { "MY_VARIABLE": "production_value" },
32+
/**
33+
* Note: Use secrets to store sensitive data.
34+
* https://developers.cloudflare.com/workers/configuration/secrets/
35+
*/
36+
37+
/**
38+
* Static Assets
39+
* https://developers.cloudflare.com/workers/static-assets/binding/
40+
*/
41+
// "assets": { "directory": "./public/", "binding": "ASSETS" },
42+
43+
/**
44+
* Service Bindings (communicate between multiple Workers)
45+
* https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
46+
*/
47+
// "services": [{ "binding": "MY_SERVICE", "service": "my-service" }]
48+
}

0 commit comments

Comments
 (0)