Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c62921e

Browse files
committedFeb 12, 2025
upgrade for deno2, publish to jsr https://jsr.io/@y0/postgres
deno2 & jsr : https://deno.com/blog/jsr_open_beta publish method 1. get token for https://jsr.io/account/tokens export DENO_AUTH_TOKENS= 2. npm run deno:publish test deno add jsr:@y0/postgres crate mod.js ``` import postgres from '@y0/postgres' const pg = postgres(process.env.PG_URL) console.log( await pg`SELECT 1` ) ``` deno -A mod.js
1 parent 089214e commit c62921e

16 files changed

+56
-29
lines changed
 

‎deno/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -515,8 +515,8 @@ import { pipeline } from 'node:stream/promises'
515515
import { createWriteStream } from 'node:fs'
516516

517517
const readableStream = await sql`copy users (name, age) to stdout`.readable()
518-
await pipeline(readableStream, createWriteStream('output.tsv'))
519-
// output.tsv content: `Murray\t68\nWalter\t80\n`
518+
await pipeline(readableStream, createWriteStream('outputv'))
519+
// outputv content: `Murray\t68\nWalter\t80\n`
520520
```
521521

522522
##### Using `for await...of`

‎deno/deno.jsonc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "@y0/postgres",
3+
"version": "3.4.5",
4+
"exports": "./src/index.js",
5+
"license": "MulanPSL-2.0"
6+
}

‎deno/mod.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
// @deno-types="./types/index.d.ts"
1+
// @deno-types="./types/index.d"
22
export { default } from './src/index.js'

‎deno/package.json

-1
This file was deleted.

‎deno/polyfills.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* global Deno */
22

3-
import { Buffer } from 'https://deno.land/std@0.132.0/node/buffer.ts'
4-
import { isIP } from 'https://deno.land/std@0.132.0/node/net.ts'
3+
import { Buffer } from 'node:buffer'
4+
import { isIP } from 'node:net'
55

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

‎deno/src/bytes.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Buffer } from 'https://deno.land/std@0.132.0/node/buffer.ts'
1+
import { Buffer } from 'node:buffer'
22
const size = 256
33
let buffer = Buffer.allocUnsafe(size)
44

‎deno/src/connection.js

+27-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import { HmacSha256 } from 'https://deno.land/std@0.132.0/hash/sha256.ts'
2-
import { Buffer } from 'https://deno.land/std@0.132.0/node/buffer.ts'
1+
import { Buffer } from 'node:buffer'
32
import { setImmediate, clearImmediate } from '../polyfills.js'
43
import { net } from '../polyfills.js'
54
import { tls } from '../polyfills.js'
6-
import crypto from 'https://deno.land/std@0.132.0/node/crypto.ts'
7-
import Stream from 'https://deno.land/std@0.132.0/node/stream.ts'
5+
import crypto from 'node:crypto'
6+
import Stream from 'node:stream'
87

98

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

1003-
function hmac(key, x) {
1004-
return Buffer.from(new HmacSha256(key).update(x).digest())
1002+
const UTF8 = new TextEncoder();
1003+
1004+
const hmac = async (key, x) => {
1005+
if (key.constructor == String) {
1006+
key = UTF8.encode(key);
1007+
}
1008+
1009+
if (x.constructor == String) {
1010+
x = UTF8.encode(x);
1011+
}
1012+
1013+
const cryptoKey = await crypto.subtle.importKey(
1014+
"raw",
1015+
key,
1016+
{ name: "HMAC", hash: "SHA-256" },
1017+
false,
1018+
["sign"]
1019+
);
1020+
1021+
return Buffer.from(await crypto.subtle.sign(
1022+
"HMAC",
1023+
cryptoKey,
1024+
x
1025+
));
10051026
}
10061027

10071028
function sha256(x) {

‎deno/src/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import process from 'https://deno.land/std@0.132.0/node/process.ts'
2-
import os from 'https://deno.land/std@0.132.0/node/os.ts'
3-
import fs from 'https://deno.land/std@0.132.0/node/fs.ts'
1+
import process from 'node:process'
2+
import os from 'node:os'
3+
import fs from 'node:fs'
44

55
import {
66
mergeUserTypes,

‎deno/src/large.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Stream from 'https://deno.land/std@0.132.0/node/stream.ts'
1+
import Stream from 'node:stream'
22

33
export default function largeObject(sql, oid, mode = 0x00020000 | 0x00040000) {
44
return new Promise(async(resolve, reject) => {

‎deno/src/subscribe.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Buffer } from 'https://deno.land/std@0.132.0/node/buffer.ts'
1+
import { Buffer } from 'node:buffer'
22
const noop = () => { /* noop */ }
33

44
export default function Subscribe(postgres, options) {

‎deno/src/types.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Buffer } from 'https://deno.land/std@0.132.0/node/buffer.ts'
1+
import { Buffer } from 'node:buffer'
22
import { Query } from './query.js'
33
import { Errors } from './errors.js'
44

‎deno/tests/bootstrap.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { spawn } from 'https://deno.land/std@0.132.0/node/child_process.ts'
1+
import { spawn } from 'node:child_process'
22

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

‎deno/tests/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { Buffer } from 'https://deno.land/std@0.132.0/node/buffer.ts'
2-
import process from 'https://deno.land/std@0.132.0/node/process.ts'
1+
import { Buffer } from 'node:buffer'
2+
import process from 'node:process'
33
import { exec } from './bootstrap.js'
44

55
import { t, nt, ot } from './test.js' // eslint-disable-line
66
import { net } from '../polyfills.js'
7-
import fs from 'https://deno.land/std@0.132.0/node/fs.ts'
8-
import crypto from 'https://deno.land/std@0.132.0/node/crypto.ts'
7+
import fs from 'node:fs'
8+
import crypto from 'node:crypto'
99

1010
import postgres from '../src/index.js'
1111
const delay = ms => new Promise(r => setTimeout(r, ms))

‎deno/tests/test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import process from 'https://deno.land/std@0.132.0/node/process.ts'
1+
import process from 'node:process'
22
/* eslint no-console: 0 */
33

4-
import util from 'https://deno.land/std@0.132.0/node/util.ts'
4+
import util from 'node:util'
55

66
let done = 0
77
let only = false

‎deno/types/index.d.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Buffer } from 'https://deno.land/std@0.132.0/node/buffer.ts'
2-
import process from 'https://deno.land/std@0.132.0/node/process.ts'
3-
import { Readable, Writable } from 'https://deno.land/std@0.132.0/node/stream.ts'
1+
import { Buffer } from 'node:buffer'
2+
import process from 'node:process'
3+
import { Readable, Writable } from 'node:stream'
44

55
/**
66
* Establish a connection to a PostgreSQL server.

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"node": ">=12"
1919
},
2020
"scripts": {
21+
"deno:publish": "cd deno && deno publish --unstable-sloppy-imports",
2122
"build": "npm run build:cjs && npm run build:deno && npm run build:cf",
2223
"build:cjs": "node transpile.cjs",
2324
"build:deno": "node transpile.deno.js",

0 commit comments

Comments
 (0)
Please sign in to comment.