Skip to content

Commit

Permalink
upgrade for deno2, publish to jsr https://jsr.io/@y0/postgres
Browse files Browse the repository at this point in the history
deno2 & jsr : https://deno.com/blog/jsr_open_beta

deno add jsr:@y0/postgres

1. get token for https://jsr.io/account/tokens

export DENO_AUTH_TOKENS=

2. npm run deno:publish

create file mod.js

```
import postgres from '@y0/postgres'
const pg = postgres(process.env.PG_URL)
console.log( await pg`SELECT 1` )
```

deno -A mod.js
  • Loading branch information
i18nsite committed Feb 12, 2025
1 parent 089214e commit b59e027
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 27 deletions.
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: [] })

Expand Down
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)

Expand Down
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'
Expand Down Expand Up @@ -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) {
Expand Down
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,
Expand Down
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) => {
Expand Down
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) {
Expand Down
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'

Expand Down
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'])

Expand Down
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))
Expand Down
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
Expand Down
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.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit b59e027

Please sign in to comment.