Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
connect-typeorm
Advanced tools
A TypeORM-based session store.
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 * 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 })
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
.
MIT
FAQs
A TypeORM-based session store
The npm package connect-typeorm receives a total of 3,778 weekly downloads. As such, connect-typeorm popularity was classified as popular.
We found that connect-typeorm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.