Skip to content

upgrade for deno2, publish to jsr https://jsr.io/@y0/postgres #1034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions deno/deno.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@y0/postgres",
"version": "3.4.5",
"exports": "./src/index.js",
"license": "MulanPSL-2.0"
}
2 changes: 1 addition & 1 deletion deno/mod.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// @deno-types="./types/index.d.ts"
// @deno-types="./types/index.d"
export { default } from './src/index.js'
1 change: 0 additions & 1 deletion deno/package.json

This file was deleted.

4 changes: 2 additions & 2 deletions deno/polyfills.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* global Deno */

import { Buffer } from 'https://deno.land/[email protected]/node/buffer.ts'
import { isIP } from 'https://deno.land/[email protected]/node/net.ts'
import { Buffer } from 'node:buffer'
import { isIP } from 'node:net'

const events = () => ({ data: [], error: [], drain: [], connect: [], secureConnect: [], close: [] })

2 changes: 1 addition & 1 deletion deno/src/bytes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Buffer } from 'https://deno.land/[email protected]/node/buffer.ts'
import { Buffer } from 'node:buffer'
const size = 256
let buffer = Buffer.allocUnsafe(size)

33 changes: 27 additions & 6 deletions deno/src/connection.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { HmacSha256 } from 'https://deno.land/[email protected]/hash/sha256.ts'
import { Buffer } from 'https://deno.land/[email protected]/node/buffer.ts'
import { Buffer } from 'node:buffer'
import { setImmediate, clearImmediate } from '../polyfills.js'
import { net } from '../polyfills.js'
import { tls } from '../polyfills.js'
import crypto from 'https://deno.land/[email protected]/node/crypto.ts'
import Stream from 'https://deno.land/[email protected]/node/stream.ts'
import crypto from 'node:crypto'
import Stream from 'node:stream'


import { stringify, handleValue, arrayParser, arraySerializer } from './types.js'
@@ -1000,8 +999,30 @@ function md5(x) {
return crypto.createHash('md5').update(x).digest('hex')
}

function hmac(key, x) {
return Buffer.from(new HmacSha256(key).update(x).digest())
const UTF8 = new TextEncoder();

const hmac = async (key, x) => {
if (key.constructor == String) {
key = UTF8.encode(key);
}

if (x.constructor == String) {
x = UTF8.encode(x);
}

const cryptoKey = await crypto.subtle.importKey(
"raw",
key,
{ name: "HMAC", hash: "SHA-256" },
false,
["sign"]
);

return Buffer.from(await crypto.subtle.sign(
"HMAC",
cryptoKey,
x
));
}

function sha256(x) {
6 changes: 3 additions & 3 deletions deno/src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import process from 'https://deno.land/[email protected]/node/process.ts'
import os from 'https://deno.land/[email protected]/node/os.ts'
import fs from 'https://deno.land/[email protected]/node/fs.ts'
import process from 'node:process'
import os from 'node:os'
import fs from 'node:fs'

import {
mergeUserTypes,
2 changes: 1 addition & 1 deletion deno/src/large.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Stream from 'https://deno.land/[email protected]/node/stream.ts'
import Stream from 'node:stream'

export default function largeObject(sql, oid, mode = 0x00020000 | 0x00040000) {
return new Promise(async(resolve, reject) => {
2 changes: 1 addition & 1 deletion deno/src/subscribe.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Buffer } from 'https://deno.land/[email protected]/node/buffer.ts'
import { Buffer } from 'node:buffer'
const noop = () => { /* noop */ }

export default function Subscribe(postgres, options) {
2 changes: 1 addition & 1 deletion deno/src/types.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Buffer } from 'https://deno.land/[email protected]/node/buffer.ts'
import { Buffer } from 'node:buffer'
import { Query } from './query.js'
import { Errors } from './errors.js'

2 changes: 1 addition & 1 deletion deno/tests/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { spawn } from 'https://deno.land/[email protected]/node/child_process.ts'
import { spawn } from 'node:child_process'

await exec('dropdb', ['postgres_js_test'])

8 changes: 4 additions & 4 deletions deno/tests/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Buffer } from 'https://deno.land/[email protected]/node/buffer.ts'
import process from 'https://deno.land/[email protected]/node/process.ts'
import { Buffer } from 'node:buffer'
import process from 'node:process'
import { exec } from './bootstrap.js'

import { t, nt, ot } from './test.js' // eslint-disable-line
import { net } from '../polyfills.js'
import fs from 'https://deno.land/[email protected]/node/fs.ts'
import crypto from 'https://deno.land/[email protected]/node/crypto.ts'
import fs from 'node:fs'
import crypto from 'node:crypto'

import postgres from '../src/index.js'
const delay = ms => new Promise(r => setTimeout(r, ms))
4 changes: 2 additions & 2 deletions deno/tests/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import process from 'https://deno.land/[email protected]/node/process.ts'
import process from 'node:process'
/* eslint no-console: 0 */

import util from 'https://deno.land/[email protected]/node/util.ts'
import util from 'node:util'

let done = 0
let only = false
6 changes: 3 additions & 3 deletions deno/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Buffer } from 'https://deno.land/[email protected]/node/buffer.ts'
import process from 'https://deno.land/[email protected]/node/process.ts'
import { Readable, Writable } from 'https://deno.land/[email protected]/node/stream.ts'
import { Buffer } from 'node:buffer'
import process from 'node:process'
import { Readable, Writable } from 'node:stream'

/**
* Establish a connection to a PostgreSQL server.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
"node": ">=12"
},
"scripts": {
"deno:publish": "cd deno && deno publish --unstable-sloppy-imports",
"build": "npm run build:cjs && npm run build:deno && npm run build:cf",
"build:cjs": "node transpile.cjs",
"build:deno": "node transpile.deno.js",