npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jojoxd/connect-typeorm

v1.2.0

Published

A TypeORM-based session store

Downloads

1

Readme

connect-typeorm

A TypeORM-based session store.

Usage

Configure TypeORM with back end of your choice:

yarn add @types/express-session connect-typeorm express-session typeorm sqlite3

Implement the Session entity:

// src/domain/Session/Session.ts

import { ISession } from "connect-typeorm";
import { Column, Entity, Index, PrimaryColumn } from "typeorm";
@Entity()
export class Session implements ISession {
  @Index()
  @Column("bigint")
  public expiredAt = Date.now();

  @PrimaryColumn("varchar", { length: 255 })
  public id = "";

  @Column("text")
  public json = "";
}

Pass repository to TypeormStore:

// src/app/Api/Api.ts

import { TypeormStore } from "connect-typeorm";
import * as Express from "express";
import * as ExpressSession from "express-session";
import { Db } from "typeorm-static";
import { Session } from "../../domain/Session/Session";

export class Api {
  public sessionRepository = Db.connection.getRepository(Session);

  public express = Express().use(
    ExpressSession({
      resave: false,
      saveUninitialized: false,
      store: new TypeormStore({
        cleanupLimit: 2,
        limitSubquery: false, // If using MariaDB.
        ttl: 86400
      }).connect(this.sessionRepository),
      secret: "keyboard cat"
    })
  );
}

TypeORM uses { "bigNumberStrings": true } option by default for node-mysql, you can use a Transformer to fix this issue:

import { Bigint } from "typeorm-static";
@Column("bigint", { transformer: Bigint })

Options

Constructor receives an object. Following properties may be included:

  • cleanupLimit For every new session, remove this many expired ones. Defaults to 0, in case you need to analyze sessions retrospectively.

  • limitSubquery Select and delete expired sessions in one query. Defaults to true, you can set false to make two queries, in case you want cleanupLimit but your MariaDB version doesn't support limit in a subquery.

  • ttl Session time to live (expiration) in seconds. Defaults to session.maxAge (if set), or one day. This may also be set to a function of the form (store, sess, sessionID) => number.

  • onError Error handler for database exception. It is a function of the form (store: TypeormStore, error: Error) => void. If not set, any database error will cause the TypeormStore to be marked as "disconnected", and stop reading/writing to the database, therefore not loading sessions and causing all requests to be considered unauthenticated.

License

MIT