Giter Club home page Giter Club logo

deno_sessions's People

Contributors

aaronwlee avatar cmorten avatar denjucks avatar jcs224 avatar octo8080x avatar orangegrove1955 avatar tamasszoke avatar

Watchers

 avatar

deno_sessions's Issues

Some suggestion

I suggest the following changes:

Separate Class for each framework

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" })

Framework instance instead of method callings

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));

Pass options during new calls

const session = new OakSession(app, { path: "/", httpOnly: true, secure: false })

instead of

app.use(session.use()(session, { path: "/", httpOnly: true, secure: false }))

Pass store instance instead of string

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.

Minor things

  • As a general suggestion, I would say that underscore properties/methods are not really necessary with typescript because we can use private instead. That would make the code a bit more readable.
  • I think there is an export missing for IStore in interface.ts. Maybe call the interface Store and the file store.ts instead?
  • simplify
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

TS2339: Property 'session' does not exist on type 'Request'.

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
        }
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.