abi
abi
DDeno
Created by abi on 6/20/2024 in #help
Type-narrowing/covariance/contravariance
Why is it that 5 has type 5 but {five:5} has type {five:number} and not {five:5}?
27 replies
DDeno
Created by abi on 4/14/2024 in #help
Microservices, best practices
Anyone know some good resources for best practices and guidelines when developing microservices? Mostly interested in TypeScript/AWS but also tips in general.
5 replies
DDeno
Created by abi on 12/3/2023 in #help
Relative path in `npm:` specifier
I have this in my import map:
"@heroicons/react/": "npm:@heroicons/react@2.0.18/"
"@heroicons/react/": "npm:@heroicons/react@2.0.18/"
And I try to do this:
import { Bars3Icon, BellIcon, XMarkIcon } from "@heroicons/react/24/outline";
import { Bars3Icon, BellIcon, XMarkIcon } from "@heroicons/react/24/outline";
The error.
Failed to resolve the specifier ""@heroicons/react/24/outline"" as its after-prefix portion ""24/outline"" could not be URL-parsed relative to the URL prefix "npm:@heroicons/react@2.0.18/" mapped to by the prefix "@heroicons/react/"deno(resolver-error)
Failed to resolve the specifier ""@heroicons/react/24/outline"" as its after-prefix portion ""24/outline"" could not be URL-parsed relative to the URL prefix "npm:@heroicons/react@2.0.18/" mapped to by the prefix "@heroicons/react/"deno(resolver-error)
Any ideas? Is it possible in the first place?
4 replies
DDeno
Created by abi on 7/4/2023 in #help
Changing GitHub username – what about deno.land/x?
If I change my GitHub username and I have a couple of modules on deno.land/x, what will happen to those modules exactly?
7 replies
DDeno
Created by abi on 6/17/2023 in #help
Type alias with inherited type parameter constraints
Is there any way to do this? I want SVLTN to just be a short-name alias for SomeVeryLongTypeName, and I want it to have the same parameter types, but I don't want to have to specify all of them explicitly.
type SomeVeryLongTypeName<A extends ..., B extends ..., ...> = ...
type SVLTN<A extends ..., B extends ..., ...> = SomeVeryLongTypeName<A, B, ...>
type SomeVeryLongTypeName<A extends ..., B extends ..., ...> = ...
type SVLTN<A extends ..., B extends ..., ...> = SomeVeryLongTypeName<A, B, ...>
What I would like more is:
type SVLTN = SomeVeryLongTypeName<???>
type SVLTN = SomeVeryLongTypeName<???>
Anyone?
9 replies
DDeno
Created by abi on 6/16/2023 in #help
Reasons to choose Node.js
I've been tasked to write a list of pros/cons of Deno in comparison to Node.js. I am quite honestly having a hard time formulating that many "pros" of Node.js. Could someone please let me know: what good reasons are there to choose Node.js today?
7 replies
DDeno
Created by abi on 6/15/2023 in #help
deno.land published the same GitHub tag twice
https://deno.land/x/smee_client_unofficial@v1.2.3 Could someone please just delete the older one?
5 replies
DDeno
Created by abi on 6/13/2023 in #help
Logger names and prefixes
Is there any obvious way on how to configure std/log so that loggers named my-prefix/foo/bar and my-prefix/hello/world attach to the same handlers automatically? In other words, can I configure logger handlers based on logger name prefix?
2 replies
DDeno
Created by abi on 6/13/2023 in #help
Deno and `npm:mongodb` problem with `node:`?
❯ deno check --reload main.ts
error: Relative import path "net" not prefixed with / or ./ or ../ and not in import map from "file:///Users/.../Library/Caches/deno/npm/registry.npmjs.org/mongodb/5.6.0/mongodb.d.ts"
If you want to use a built-in Node module, add a "node:" prefix (ex. "node:net").
at file:///Users/.../Library/Caches/deno/npm/registry.npmjs.org/mongodb/5.6.0/mongodb.d.ts:29:29
❯ deno check --reload main.ts
error: Relative import path "net" not prefixed with / or ./ or ../ and not in import map from "file:///Users/.../Library/Caches/deno/npm/registry.npmjs.org/mongodb/5.6.0/mongodb.d.ts"
If you want to use a built-in Node module, add a "node:" prefix (ex. "node:net").
at file:///Users/.../Library/Caches/deno/npm/registry.npmjs.org/mongodb/5.6.0/mongodb.d.ts:29:29
I'm simply importing stuff from npm:mongodb@5.6.0, why doesn't Deno understand this thing now?
6 replies
DDeno
Created by abi on 6/12/2023 in #help
Using Superagent in Deno?
Has anyone managed to make Superagent work nicely in Deno?
_ {
type: "error",
message: "Browser-only version of superagent could not find XHR"
}
_ {
type: "error",
message: "Browser-only version of superagent could not find XHR"
}
I use Superagent via dependent package smee-client from esm.sh and it seems I can't figure out how to make Superagent and/or esm.sh understand that I want the non-browser Superagent?
2 replies
DDeno
Created by abi on 6/11/2023 in #help
Oak – ctx.assert with custom response headers
Am I doing this wrong? No extra custom headers are being set in the response as far as I can see in cURL:
ctx.assert(
!missingHeaders,
Status.BadRequest,
JSON.stringify({ error: `Required headers missing: ${missingHeaders}` }),
{ expose: true, headers: { "content-type": "application/json", "foo": "bar" } },
);
ctx.assert(
!missingHeaders,
Status.BadRequest,
JSON.stringify({ error: `Required headers missing: ${missingHeaders}` }),
{ expose: true, headers: { "content-type": "application/json", "foo": "bar" } },
);
2 replies
DDeno
Created by abi on 6/11/2023 in #help
Abusing prototype CryptoKey in `node:crypto`
Is there any way that I can set the prototype of an object to specifically CryptoKey as defined by node:crypto? I am trying to get around some nasty instanceof check in a third-party library which is getting in the way.
import * as krypto from "node:crypto";
Object.setPrototypeOf(foo, krypto.webcrypto.CryptoKey.prototype);
import * as krypto from "node:crypto";
Object.setPrototypeOf(foo, krypto.webcrypto.CryptoKey.prototype);
The above gives me this error:
error: Uncaught TypeError: Cannot read properties of undefined (reading 'prototype')
error: Uncaught TypeError: Cannot read properties of undefined (reading 'prototype')
7 replies
DDeno
Created by abi on 5/29/2023 in #help
`dnt` incompatible with `addEventListener`?
I am using the log/mod.ts module from deno_std and running dnt with no special configuration as far as I know, why doesn't this just work? Some Node.js shim missing?
src/deps/deno.land/std@0.189.0/log/handlers.ts:153:5 - error TS2304: Cannot find name 'addEventListener'.

153 addEventListener("unload", this.#unloadCallback);
~~~~~~~~~~~~~~~~
src/deps/deno.land/std@0.189.0/log/handlers.ts:182:5 - error TS2304: Cannot find name 'removeEventListener'.

182 removeEventListener("unload", this.#unloadCallback);
~~~~~~~~~~~~~~~~~~~

error: Uncaught Error: Had 3 diagnostics.
throw new Error(`Had ${diagnostics.length} diagnostics.`);
^
at getProgramAndMaybeTypeCheck (https://deno.land/x/dnt@0.36.0/mod.ts:446:17)
at build (https://deno.land/x/dnt@0.36.0/mod.ts:339:17)
at eventLoopTick (ext:core/01_core.js:182:11)
at async file:///.../my_project/scripts/build_npm.ts:17:1
src/deps/deno.land/std@0.189.0/log/handlers.ts:153:5 - error TS2304: Cannot find name 'addEventListener'.

153 addEventListener("unload", this.#unloadCallback);
~~~~~~~~~~~~~~~~
src/deps/deno.land/std@0.189.0/log/handlers.ts:182:5 - error TS2304: Cannot find name 'removeEventListener'.

182 removeEventListener("unload", this.#unloadCallback);
~~~~~~~~~~~~~~~~~~~

error: Uncaught Error: Had 3 diagnostics.
throw new Error(`Had ${diagnostics.length} diagnostics.`);
^
at getProgramAndMaybeTypeCheck (https://deno.land/x/dnt@0.36.0/mod.ts:446:17)
at build (https://deno.land/x/dnt@0.36.0/mod.ts:339:17)
at eventLoopTick (ext:core/01_core.js:182:11)
at async file:///.../my_project/scripts/build_npm.ts:17:1
1 replies
DDeno
Created by abi on 5/26/2023 in #help
Simple type narrowing/type guard/assertion (?)
Is there really no simpler way of doing this without any and without external deps?
export function isFooBarBaz(
value: unknown,
): value is { Foo: { Bar: { Baz: string } } } {
return typeof value === "object" &&
value !== null &&
"Foo" in value &&
typeof value.Foo === "object" &&
value.Foo !== null &&
"Bar" in value.Foo &&
typeof value.Foo.Bar === "object" &&
value.Foo.Bar !== null &&
"Baz" in value.Foo.Bar &&
typeof value.Foo.Bar.Baz === "string";
}
export function isFooBarBaz(
value: unknown,
): value is { Foo: { Bar: { Baz: string } } } {
return typeof value === "object" &&
value !== null &&
"Foo" in value &&
typeof value.Foo === "object" &&
value.Foo !== null &&
"Bar" in value.Foo &&
typeof value.Foo.Bar === "object" &&
value.Foo.Bar !== null &&
"Baz" in value.Foo.Bar &&
typeof value.Foo.Bar.Baz === "string";
}
(What's the exact name for what I'm doing here btw? I confuse the terms.)
6 replies
DDeno
Created by abi on 5/21/2023 in #help
Remove sink from stream
Is it at all possible to "undo" adding a sink on a stream? I am trying to make it so that once the writable stream fulfills some condition, it should stop reading from the readable.
someProcess.stderr.pipeTo(
new WritableStream({
write(chunk, controller) {
if (someCondition()) {
// how the heck do i "undo" this sink?
// i want to stop processing here, and i don't care what
// happens to stderr after this point.
}
},
}),
);
someProcess.stderr.pipeTo(
new WritableStream({
write(chunk, controller) {
if (someCondition()) {
// how the heck do i "undo" this sink?
// i want to stop processing here, and i don't care what
// happens to stderr after this point.
}
},
}),
);
2 replies
DDeno
Created by abi on 5/19/2023 in #help
HTTPS w/ client certificate – works in Node.js, not in Deno
I am making an HTTPS call with a client certificate. It works great in Node.js, but when I try to do the equivalent in Deno, I get a TLS handshake error. Any ideas on what I'm doing wrong?
7 replies
DDeno
Created by abi on 5/18/2023 in #help
Using encrypted private keys with Deno
So it seems to me that Deno doesn't provide any helpers for making HTTPS requests with encrypted private keys. (This is readily available in Node.js!) Is it possible at all make HTTPS requests with encrypted private keys in Deno? Not exactly sure how all of TLS works, and on what level it would need to be implemented.
5 replies
DDeno
Created by abi on 5/12/2023 in #help
Oak, `ctx.assert`, and middleware
I thought that ctx.assert would somehow "carry along" the information about the asserted condition to the next middleware in the chain, but I can't seem to get that to work. Am I misunderstanding something here? I was thinking if I do something like this, I wouldn't have to to a null check in the last middleware, but I apparently do?
import { Application, Context } from "https://deno.land/x/oak@v12.4.0/mod.ts";

interface MyState {
value: null | 3;
}

const app = new Application<MyState>({
state: {
value: 3,
},
});

app
.use((ctx: Context<MyState>) => {
ctx.assert(ctx.state.value !== null, 500);
})
.use((ctx) => {
// 'ctx.state.value' is possibly 'null'.deno-ts(18047)
console.log(ctx.state.value + 5);
});
import { Application, Context } from "https://deno.land/x/oak@v12.4.0/mod.ts";

interface MyState {
value: null | 3;
}

const app = new Application<MyState>({
state: {
value: 3,
},
});

app
.use((ctx: Context<MyState>) => {
ctx.assert(ctx.state.value !== null, 500);
})
.use((ctx) => {
// 'ctx.state.value' is possibly 'null'.deno-ts(18047)
console.log(ctx.state.value + 5);
});
1 replies
DDeno
Created by abi on 5/11/2023 in #help
List of all deno.land packages?
Is there a list somewhere of all the deno.land packages on one page?
8 replies
DDeno
Created by abi on 5/11/2023 in #help
Safety measures (statically, not runtime) for libraries that require environment variables?
Suppose I have a Deno library which expects certain environment variables to have been configured, otherwise a crash will happen. Does anyone know of a good way to somehow ensure at "compile-time" that whatever Deno application is using the library has configured these environment variables?
16 replies