FjordWarden
FjordWarden
Explore posts from servers
DDeno
Created by FjordWarden on 10/9/2024 in #help
Run npm publish
How can I run npm publish with Deno2?
2 replies
DDeno
Created by FjordWarden on 9/21/2024 in #help
Import PyTorchJS
I wanted to try pytorch with js but I am running into some problems importing the NPM package. Maybe someone here know more.
> import * as pytorch from 'npm:pytorchjs'
Initialize ⣯ [00:02]


Warning [email protected] is deprecated: This package is no longer supported.
Warning [email protected] is deprecated: This package is no longer supported.
Warning [email protected] is deprecated: This package is no longer supported.
Warning [email protected] is deprecated: This package is no longer supported.
Warning [email protected] is deprecated: This package is no longer supported.
Warning [email protected] is deprecated: This package is no longer supported.
Initialize ⣟ [00:02] 216/220cated: This package is no longer supported.
- [email protected]: Glob versions prior to v9 are no longer supported
- [email protected] is deprecated:
Uncaught Error: Could not locate the bindings file. Tried:
→ /Users/me/Code/node_modules/.deno/@[email protected]/node_modules/@arition/torch-js/build/torch-js.node
> import * as pytorch from 'npm:pytorchjs'
Initialize ⣯ [00:02]


Warning [email protected] is deprecated: This package is no longer supported.
Warning [email protected] is deprecated: This package is no longer supported.
Warning [email protected] is deprecated: This package is no longer supported.
Warning [email protected] is deprecated: This package is no longer supported.
Warning [email protected] is deprecated: This package is no longer supported.
Warning [email protected] is deprecated: This package is no longer supported.
Initialize ⣟ [00:02] 216/220cated: This package is no longer supported.
- [email protected]: Glob versions prior to v9 are no longer supported
- [email protected] is deprecated:
Uncaught Error: Could not locate the bindings file. Tried:
→ /Users/me/Code/node_modules/.deno/@[email protected]/node_modules/@arition/torch-js/build/torch-js.node
1 replies
DDeno
Created by FjordWarden on 10/26/2023 in #help
Multiple subdomains
How can I listen for incoming http request on multiple subdomains?
3 replies
DDeno
Created by FjordWarden on 10/25/2023 in #help
Can't upgrade request to websocket
I want to use a websocket in one of my middlewares. But I keep getting an error saying I can't upgrade my connection:
[uncaught application error]: TypeError - Invalid Header: 'upgrade' header must contain 'websocket'
[uncaught application error]: TypeError - Invalid Header: 'upgrade' header must contain 'websocket'
I've googled this error but only find old results relating this error to the version of deno or oak lib where I run the latest deno (1.37.2) and oak (12.6.1).
import {Application,Router} from 'https://deno.land/x/[email protected]/mod.ts'

function RefreshMiddleware() {
return async (ctx,next) => {
console.log('url',ctx.request.url.href)
if (ctx.request.url.href.endsWith("/refresh")) {
console.log(ctx.isUpgradable);
console.log(ctx.request.headers.get("connection"));
const socket = ctx.upgrade()
} else next()
}
}

const app = new Application()
app.addEventListener("error", e => console.error(e.error))

// Logger
app.use(async (ctx, next) => {
const start = Date.now()
await next()
console.log(`${ctx.request.method} ${ctx.request.url} - ${Date.now() - start}ms`)
})
app.use(RefreshMiddleware())
app.use((ctx) => {ctx.response.body = "Hello World!"})

await app.listen({port: 8000})
import {Application,Router} from 'https://deno.land/x/[email protected]/mod.ts'

function RefreshMiddleware() {
return async (ctx,next) => {
console.log('url',ctx.request.url.href)
if (ctx.request.url.href.endsWith("/refresh")) {
console.log(ctx.isUpgradable);
console.log(ctx.request.headers.get("connection"));
const socket = ctx.upgrade()
} else next()
}
}

const app = new Application()
app.addEventListener("error", e => console.error(e.error))

// Logger
app.use(async (ctx, next) => {
const start = Date.now()
await next()
console.log(`${ctx.request.method} ${ctx.request.url} - ${Date.now() - start}ms`)
})
app.use(RefreshMiddleware())
app.use((ctx) => {ctx.response.body = "Hello World!"})

await app.listen({port: 8000})
11 replies
DDeno
Created by FjordWarden on 9/29/2023 in #help
BDD with async tests
I'd like to run some tests that all call the same helper function that wraps the bdd it function. Something like this:
describe('why u no work?', async ()=>{
const test = async (s) => {let r = await Promise.resolve(0); it(s, ()=>assertEquals(0,r))}
await test('a')
await test('b')
await test('c')
})
describe('why u no work?', async ()=>{
const test = async (s) => {let r = await Promise.resolve(0); it(s, ()=>assertEquals(0,r))}
await test('a')
await test('b')
await test('c')
})
It works with a non-async version but I'd like to know how to do this in a async way.
3 replies
DDeno
Created by FjordWarden on 9/17/2023 in #help
Can't import typescript module
Why can I only import the js file and not the ts file?
import * as zip from "https://deno.land/x/[email protected]/index.js"
import * as zipjs from "https://deno.land/x/[email protected]/index.d.ts";

zipjs.Writer //undefined
zip.ZipWriter //[class ZipWriter]
import * as zip from "https://deno.land/x/[email protected]/index.js"
import * as zipjs from "https://deno.land/x/[email protected]/index.d.ts";

zipjs.Writer //undefined
zip.ZipWriter //[class ZipWriter]
3 replies
DDeno
Created by FjordWarden on 9/6/2023 in #help
Read CSV files inside zip file using the web streams API
I need to read a number of csv files inside a zip file. The basic example I've got working so far is the following:
import {BlobReader,ZipReader,ZipWriter} from 'https://deno.land/x/zipjs/index.js'
import {readCSV} from 'https://deno.land/x/csv/mod.ts'
import {CsvParseStream} from 'https://deno.land/[email protected]/csv/mod.ts'

const srcFile = await Deno.open('/data.zip')
const zipReader = new ZipReader(srcFile)
for (let entry of (await zipReader.getEntries())) {
console.log('filename ', entry.filename)
let csvStream = new CsvParseStream({skipFirstRow:false,columns:undefined})
if (entry.filename.startsWith('code')) {
await entry.getData(csvStream.writable)
for await (const chunk of csvStream.readable) {
console.log(chunk)
}
}
}
import {BlobReader,ZipReader,ZipWriter} from 'https://deno.land/x/zipjs/index.js'
import {readCSV} from 'https://deno.land/x/csv/mod.ts'
import {CsvParseStream} from 'https://deno.land/[email protected]/csv/mod.ts'

const srcFile = await Deno.open('/data.zip')
const zipReader = new ZipReader(srcFile)
for (let entry of (await zipReader.getEntries())) {
console.log('filename ', entry.filename)
let csvStream = new CsvParseStream({skipFirstRow:false,columns:undefined})
if (entry.filename.startsWith('code')) {
await entry.getData(csvStream.writable)
for await (const chunk of csvStream.readable) {
console.log(chunk)
}
}
}
The problem is that the chunk is some weird array of strings of numbers and not the row I would expect.
[ "34", "67", "97", ...1356838 more items
[ "34", "67", "97", ...1356838 more items
Any help would be welcome.
2 replies
DDeno
Created by FjordWarden on 7/9/2023 in #help
Sanitize multiple test steps
Is it possible to sanitize multiple steps inside of one test. I want to test my DB with somthing like this:
test('db', {permissions:{net:true,env:true},sanitizeOps:false,sanitizeResources:false}, async t=>{
await testDB(async sql => {
assertOk(await ddl(sql))
await sql`insert into task values ${sql(task)}`
t.step('popTask', async ()=>assertEquals((await popTask(sql)).ok[0], task))
t.step('upsertFiling', async ()=>assertOk(async()=>await upsertFiling(sql, {id:1})))
})
})
test('db', {permissions:{net:true,env:true},sanitizeOps:false,sanitizeResources:false}, async t=>{
await testDB(async sql => {
assertOk(await ddl(sql))
await sql`insert into task values ${sql(task)}`
t.step('popTask', async ()=>assertEquals((await popTask(sql)).ok[0], task))
t.step('upsertFiling', async ()=>assertOk(async()=>await upsertFiling(sql, {id:1})))
})
})
But I get this error Started test step while another test step with sanitizers was running:
5 replies
DDeno
Created by FjordWarden on 6/15/2023 in #help
Deno hangs on error
Why does Deno hang when XML.parse throws an error?
let text = '<xml><xbrli:xbrl><hi>Hello</hi></xbrli:xbrl></xml>'
import * as XML from "https://deno.land/x/xml/mod.ts"

let parseXml = text => {
try{
return XML.parse(text)
}catch(e){
return null
}
};

parseXml(text)
console.log('ok')
try{
parseXml('fail')
}catch(e){
console.log(e)
}
let text = '<xml><xbrli:xbrl><hi>Hello</hi></xbrli:xbrl></xml>'
import * as XML from "https://deno.land/x/xml/mod.ts"

let parseXml = text => {
try{
return XML.parse(text)
}catch(e){
return null
}
};

parseXml(text)
console.log('ok')
try{
parseXml('fail')
}catch(e){
console.log(e)
}
2 replies