0.1.16 #17

Merged
Thilawyn merged 3 commits from next into master 2024-09-04 01:02:54 +02:00
3 changed files with 34 additions and 26 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "@thilawyn/thilalib",
"version": "0.1.15",
"version": "0.1.16",
"type": "module",
"files": [
"./dist"

View File

@@ -1,12 +1,12 @@
import { Context, Effect, Layer } from "effect"
import jwt from "jsonwebtoken"
import type * as JWT from "jsonwebtoken"
export class JSONWebToken extends Context.Tag("JSONWebToken")<JSONWebToken, {
sign: (
payload: string | object | Buffer,
secretOrPrivateKey: jwt.Secret,
options: jwt.SignOptions,
secretOrPrivateKey: JWT.Secret,
options: JWT.SignOptions,
) => Effect.Effect<
string,
Error,
@@ -15,17 +15,23 @@ export class JSONWebToken extends Context.Tag("JSONWebToken")<JSONWebToken, {
verify: (
token: string,
secretOrPublicKey: jwt.Secret,
options: jwt.VerifyOptions,
secretOrPublicKey: JWT.Secret,
options: JWT.VerifyOptions,
) => Effect.Effect<
string | jwt.Jwt | jwt.JwtPayload,
jwt.VerifyErrors | Error,
string | JWT.Jwt | JWT.JwtPayload,
JWT.VerifyErrors | Error,
never
>,
}>() {}
export const JSONWebTokenLive = Layer.succeed(JSONWebToken, {
const importJWT = Effect.tryPromise({
try: () => import("jsonwebtoken"),
catch: cause => new Error("Could not import 'jsonwebtoken'. Make sure it is installed.", { cause }),
})
export const JSONWebTokenLive = Layer.effect(JSONWebToken, importJWT.pipe(
Effect.map(jwt => JSONWebToken.of({
sign: (payload, secretOrPrivateKey, options) => Effect.async(resume =>
jwt.sign(payload, secretOrPrivateKey, options, (err, token) => {
resume(token
@@ -43,4 +49,5 @@ export const JSONWebTokenLive = Layer.succeed(JSONWebToken, {
)
})
),
})
}))
))

View File

@@ -8,4 +8,5 @@ export * from "./MutableClass"
export * from "./MutableTaggedClass"
export * from "./Tag"
export * from "./TaggedClass"
export * as TanStackForm from "./TanStackForm"
export * from "./toJsonifiable"