diff --git a/deno/deno.jsonc b/deno/deno.jsonc new file mode 100644 index 00000000..9485c653 --- /dev/null +++ b/deno/deno.jsonc @@ -0,0 +1,6 @@ +{ + "name": "@y0/postgres", + "version": "3.4.5", + "exports": "./src/index.js", + "license": "MulanPSL-2.0" +} diff --git a/deno/mod.js b/deno/mod.js index 7cbf18c3..e1fde7eb 100644 --- a/deno/mod.js +++ b/deno/mod.js @@ -1,2 +1,2 @@ -// @deno-types="./types/index.d.ts" +// @deno-types="./types/index.d" export { default } from './src/index.js' diff --git a/deno/package.json b/deno/package.json deleted file mode 100644 index 0292b995..00000000 --- a/deno/package.json +++ /dev/null @@ -1 +0,0 @@ -{"type":"commonjs"} \ No newline at end of file diff --git a/deno/polyfills.js b/deno/polyfills.js index 71ee694d..eb8c36a9 100644 --- a/deno/polyfills.js +++ b/deno/polyfills.js @@ -1,7 +1,7 @@ /* global Deno */ -import { Buffer } from 'https://deno.land/std@0.132.0/node/buffer.ts' -import { isIP } from 'https://deno.land/std@0.132.0/node/net.ts' +import { Buffer } from 'node:buffer' +import { isIP } from 'node:net' const events = () => ({ data: [], error: [], drain: [], connect: [], secureConnect: [], close: [] }) diff --git a/deno/src/bytes.js b/deno/src/bytes.js index fe9359db..48b6f983 100644 --- a/deno/src/bytes.js +++ b/deno/src/bytes.js @@ -1,4 +1,4 @@ -import { Buffer } from 'https://deno.land/std@0.132.0/node/buffer.ts' +import { Buffer } from 'node:buffer' const size = 256 let buffer = Buffer.allocUnsafe(size) diff --git a/deno/src/connection.js b/deno/src/connection.js index 1726a9aa..60dc420c 100644 --- a/deno/src/connection.js +++ b/deno/src/connection.js @@ -1,10 +1,9 @@ -import { HmacSha256 } from 'https://deno.land/std@0.132.0/hash/sha256.ts' -import { Buffer } from 'https://deno.land/std@0.132.0/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/std@0.132.0/node/crypto.ts' -import Stream from 'https://deno.land/std@0.132.0/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) { diff --git a/deno/src/index.js b/deno/src/index.js index 3bbdf2ba..1ca950f8 100644 --- a/deno/src/index.js +++ b/deno/src/index.js @@ -1,6 +1,6 @@ -import process from 'https://deno.land/std@0.132.0/node/process.ts' -import os from 'https://deno.land/std@0.132.0/node/os.ts' -import fs from 'https://deno.land/std@0.132.0/node/fs.ts' +import process from 'node:process' +import os from 'node:os' +import fs from 'node:fs' import { mergeUserTypes, diff --git a/deno/src/large.js b/deno/src/large.js index 1b9f42d2..8ae150dd 100644 --- a/deno/src/large.js +++ b/deno/src/large.js @@ -1,4 +1,4 @@ -import Stream from 'https://deno.land/std@0.132.0/node/stream.ts' +import Stream from 'node:stream' export default function largeObject(sql, oid, mode = 0x00020000 | 0x00040000) { return new Promise(async(resolve, reject) => { diff --git a/deno/src/subscribe.js b/deno/src/subscribe.js index b20efb96..8716100e 100644 --- a/deno/src/subscribe.js +++ b/deno/src/subscribe.js @@ -1,4 +1,4 @@ -import { Buffer } from 'https://deno.land/std@0.132.0/node/buffer.ts' +import { Buffer } from 'node:buffer' const noop = () => { /* noop */ } export default function Subscribe(postgres, options) { diff --git a/deno/src/types.js b/deno/src/types.js index ea0da6a2..aa2ead29 100644 --- a/deno/src/types.js +++ b/deno/src/types.js @@ -1,4 +1,4 @@ -import { Buffer } from 'https://deno.land/std@0.132.0/node/buffer.ts' +import { Buffer } from 'node:buffer' import { Query } from './query.js' import { Errors } from './errors.js' diff --git a/deno/tests/bootstrap.js b/deno/tests/bootstrap.js index da416896..c75ddc40 100644 --- a/deno/tests/bootstrap.js +++ b/deno/tests/bootstrap.js @@ -1,4 +1,4 @@ -import { spawn } from 'https://deno.land/std@0.132.0/node/child_process.ts' +import { spawn } from 'node:child_process' await exec('dropdb', ['postgres_js_test']) diff --git a/deno/tests/index.js b/deno/tests/index.js index 5b5d6e57..3dda27ce 100644 --- a/deno/tests/index.js +++ b/deno/tests/index.js @@ -1,11 +1,11 @@ -import { Buffer } from 'https://deno.land/std@0.132.0/node/buffer.ts' -import process from 'https://deno.land/std@0.132.0/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/std@0.132.0/node/fs.ts' -import crypto from 'https://deno.land/std@0.132.0/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)) diff --git a/deno/tests/test.js b/deno/tests/test.js index f61a253f..343eedf3 100644 --- a/deno/tests/test.js +++ b/deno/tests/test.js @@ -1,7 +1,7 @@ -import process from 'https://deno.land/std@0.132.0/node/process.ts' +import process from 'node:process' /* eslint no-console: 0 */ -import util from 'https://deno.land/std@0.132.0/node/util.ts' +import util from 'node:util' let done = 0 let only = false diff --git a/deno/types/index.d.ts b/deno/types/index.d.ts index 2088662d..5c1665db 100644 --- a/deno/types/index.d.ts +++ b/deno/types/index.d.ts @@ -1,6 +1,6 @@ -import { Buffer } from 'https://deno.land/std@0.132.0/node/buffer.ts' -import process from 'https://deno.land/std@0.132.0/node/process.ts' -import { Readable, Writable } from 'https://deno.land/std@0.132.0/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. diff --git a/package.json b/package.json index d53fe2ca..558e2713 100644 --- a/package.json +++ b/package.json @@ -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",