hyper-ts-session
Advanced tools
Comparing version 0.1.3 to 0.2.0
@@ -5,2 +5,9 @@ # Changelog | ||
## [0.2.0](https://github.com/thewilkybarkid/hyper-ts-session/compare/v0.1.3...v0.2.0) (2023-01-17) | ||
### Features | ||
* don't swallow Keyv errors ([7a5b508](https://github.com/thewilkybarkid/hyper-ts-session/commit/7a5b508f8b6099b8d2d12bc6b5c0c3f605c9339a)) | ||
### [0.1.3](https://github.com/thewilkybarkid/hyper-ts-session/compare/v0.1.2...v0.1.3) (2022-07-01) | ||
@@ -7,0 +14,0 @@ |
@@ -21,3 +21,3 @@ import * as J from 'fp-ts/Json'; | ||
*/ | ||
export declare function getSession<I = StatusOpen>(): ReaderMiddleware<SessionEnv, I, I, 'no-session', JsonRecord>; | ||
export declare function getSession<I = StatusOpen>(): ReaderMiddleware<SessionEnv, I, I, 'no-session' | Error, JsonRecord>; | ||
/** | ||
@@ -29,3 +29,3 @@ * Returns a middleware that stores a value in a session. | ||
*/ | ||
export declare function storeSession(session: JsonRecord): ReaderMiddleware<SessionEnv, HeadersOpen, HeadersOpen, never, void>; | ||
export declare function storeSession(session: JsonRecord): ReaderMiddleware<SessionEnv, HeadersOpen, HeadersOpen, Error, void>; | ||
/** | ||
@@ -37,2 +37,2 @@ * Returns a middleware that ends the current session. | ||
*/ | ||
export declare function endSession(): ReaderMiddleware<SessionEnv, HeadersOpen, HeadersOpen, never, void>; | ||
export declare function endSession(): ReaderMiddleware<SessionEnv, HeadersOpen, HeadersOpen, Error, void>; |
@@ -45,3 +45,2 @@ "use strict"; | ||
const E = __importStar(require("fp-ts/Either")); | ||
const O = __importStar(require("fp-ts/Option")); | ||
const r = __importStar(require("fp-ts/Record")); | ||
@@ -64,3 +63,3 @@ const TE = __importStar(require("fp-ts/TaskEither")); | ||
function getSession() { | ||
return (0, function_1.pipe)(RM.ask(), RM.chain(({ sessionStore }) => (0, function_1.pipe)(currentSessionId(), RM.chainTaskEitherKW((0, function_1.flow)(TE.tryCatchK((key) => __awaiter(this, void 0, void 0, function* () { return yield sessionStore.get(key); }), function_1.constVoid), TE.chainOptionK(function_1.constVoid)(O.fromNullable))), RM.mapLeft(() => 'no-session')))); | ||
return (0, function_1.pipe)(RM.ask(), RM.chain(({ sessionStore }) => (0, function_1.pipe)(currentSessionId(), RM.chainTaskEitherKW((0, function_1.flow)(TE.tryCatchK((key) => __awaiter(this, void 0, void 0, function* () { return yield sessionStore.get(key); }), E.toError), TE.chainEitherKW(E.fromNullable('no-session'))))))); | ||
} | ||
@@ -75,3 +74,3 @@ exports.getSession = getSession; | ||
function storeSession(session) { | ||
return (0, function_1.pipe)(currentSessionId(), RM.orElse(newSession), RM.chainReaderTaskK(saveSession(session))); | ||
return (0, function_1.pipe)(currentSessionId(), RM.orElse(newSession), RM.chainReaderTaskEitherK(saveSession(session))); | ||
} | ||
@@ -88,3 +87,3 @@ exports.storeSession = storeSession; | ||
httpOnly: true, | ||
}), RM.chain(() => currentSessionId()), RM.chainReaderTaskK(deleteSession), RM.orElseW(() => RM.right(undefined))); | ||
}), RM.chain(() => currentSessionId()), RM.chainReaderTaskEitherKW(deleteSession), RM.orElseW(error => (error === 'no-session' ? RM.right(undefined) : RM.left(error)))); | ||
} | ||
@@ -104,10 +103,10 @@ exports.endSession = endSession; | ||
function saveSession(session) { | ||
return key => (0, function_1.flow)(TE.tryCatchK(({ sessionStore }) => __awaiter(this, void 0, void 0, function* () { | ||
return key => TE.tryCatchK(({ sessionStore }) => __awaiter(this, void 0, void 0, function* () { | ||
yield sessionStore.set(key, session); | ||
}), function_1.constVoid), TE.toUnion); | ||
}), E.toError); | ||
} | ||
function deleteSession(key) { | ||
return (0, function_1.flow)(TE.tryCatchK(({ sessionStore }) => __awaiter(this, void 0, void 0, function* () { | ||
return TE.tryCatchK(({ sessionStore }) => __awaiter(this, void 0, void 0, function* () { | ||
yield sessionStore.delete(key); | ||
}), function_1.constVoid), TE.toUnion); | ||
}), E.toError); | ||
} | ||
@@ -114,0 +113,0 @@ function getCookie(name) { |
{ | ||
"name": "hyper-ts-session", | ||
"description": "hyper-ts middleware for sessions.", | ||
"version": "0.1.3", | ||
"version": "0.2.0", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "homepage": "https://github.com/thewilkybarkid/hyper-ts-session", |
11927
150