jcs224 / deno_sessions Goto Github PK
View Code? Open in Web Editor NEWThis project forked from cmorten/session
Sessions for deno web frameworks
License: MIT License
This project forked from cmorten/session
Sessions for deno web frameworks
License: MIT License
I suggest the following changes:
have a class for each framework instead of passing a property framework string.
const session = new OakSession(โฆ)
instead of
const session = new Session({ framework: "oak" })
pass a framework instance instead of calling use
.
const session = new OakSession(app);
instead of
const session = new Session({ framework: "oak" });
app.use(session.use()(session));
const session = new OakSession(app, { path: "/", httpOnly: true, secure: false })
instead of
app.use(session.use()(session, { path: "/", httpOnly: true, secure: false }))
import { Session, SqliteStore } from "https://deno.land/x/session/mod.ts";
const store = new SqliteStore()
await store.connect()
const session = new OakSession(app, { store })
instead of
await session.init();
Maybe SqliteStore could even take a sqlite DB instance to have make it more flexible and if none is provided, create a new one.
private
instead. That would make the code a bit more readable.IStore
in interface.ts. Maybe call the interface Store
and the file store.ts
instead?if(Object.keys(this._sessionMemoryStore).includes(sessionId)) {
return true;
} else {
return false;
}
could be simplified to return Object.keys(this._sessionMemoryStore).includes(sessionId)
.
references: oslabs-beta/dashport#39
Using this library with a TypeScript deno program that uses Opine results in a failure to compile, since session
is not defined in Opine's Request interface, and trying to access it is hence illegal.
Full error message:
TS2339 [ERROR]: Property 'session' does not exist on type 'Request<ParamsDictionary, any, any>'.
await req.session.set('username', username);
~~~~~~~
I assume (though I have not tested this) that doing a similar thing with Oak will result in the same behaviour.
The workaround is to use declaration merging in a manner similar to the following:
// Bodge to add the session type to Opine's Request object.
declare global {
namespace Opine {
export interface ParamsDictionary {
[key: string]: string;
}
export type ParamsArray = string[];
export type Params = ParamsDictionary | ParamsArray;
// From https://github.com/asos-craigmorten/opine/blob/fec0bd20bdc1115978dc9adf82ac5c4e169d9b5a/src/types.ts#L17:
// "These open interfaces may be extended in an application-specific manner via declaration merging."
interface Request<
P extends Params = ParamsDictionary,
// deno-lint-ignore no-explicit-any
ResBody = any,
// deno-lint-ignore no-explicit-any
ReqQuery = any> {
session: OpineSession // specify the session object as a property of the Opine Request interface
}
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.