Skip to content

Commit 866dfab

Browse files
committed
Initial commit
0 parents  commit 866dfab

File tree

14 files changed

+438
-0
lines changed

14 files changed

+438
-0
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (http://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# Typescript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
57+
# dotenv environment variables file
58+
.env
59+
60+
# Yarn lock
61+
yarn.lock
62+
63+
# TypeScript output
64+
out/

.npmignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.vscode/
2+
bin/app/
3+
src/
4+
src/app/
5+
out/updateReadme*
6+
.gitattributes
7+
.gitignore
8+
tsconfig.json
9+
tslint.json
10+
yarn.lock

.vscode/launch.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
// Use IntelliSense to learn about possible Node.js debug attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"type": "node",
9+
"request": "launch",
10+
"name": "Test",
11+
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
12+
"args": [
13+
"--exit",
14+
"--bail",
15+
"-u",
16+
"tdd",
17+
"--timeout",
18+
"999999",
19+
"--colors",
20+
"-r",
21+
"source-map-support/register",
22+
"${workspaceRoot}/out/**/*.test.js"
23+
],
24+
"internalConsoleOptions": "openOnSessionStart"
25+
}
26+
]
27+
}

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
"editor.tabSize": 2
4+
}

.vscode/tasks.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the tasks.json format
4+
"version": "0.1.0",
5+
"command": "tsc",
6+
"isShellCommand": true,
7+
"showOutput": "silent",
8+
"problemMatcher": "$tsc"
9+
}

LICENSE

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2017 TJ Holowaychuk, Marc Harter, makepost
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# connect-typeorm
2+
3+
A TypeORM-based session store.
4+
5+
## Usage
6+
7+
Configure TypeORM with back end of your choice:
8+
9+
```bash
10+
yarn add @types/express-session connect-typeorm express-session typeorm sqlite3
11+
```
12+
13+
Implement the `Session` entity:
14+
15+
```typescript
16+
// src/domain/Session/Session.ts
17+
18+
import { ISession } from "connect-typeorm";
19+
import { Column, Entity, Index, PrimaryColumn } from "typeorm";
20+
import { Bigint } from "typeorm-static";
21+
22+
@Entity()
23+
export class Session implements ISession {
24+
@Index()
25+
@Column("bigint", { transformer: Bigint })
26+
public expiredAt: number;
27+
28+
@PrimaryColumn("varchar", { length: 255 })
29+
public id: string;
30+
31+
@Column()
32+
public json: string;
33+
}
34+
```
35+
36+
Pass repository to `TypeormStore`:
37+
38+
```typescript
39+
// src/app/Api/Api.ts
40+
41+
import * as Express from "express";
42+
import * as ExpressSession from "express-session";
43+
import { Db } from "typeorm-static";
44+
import { Session } from "../../domain/Session/Session";
45+
46+
export class Api {
47+
public sessionRepository = Db.connection.getRepository(Session);
48+
49+
public express = Express()
50+
.use(ExpressSession({
51+
store: new TypeormStore({ ttl: 86400 }).connect(this.sessionRepository),
52+
secret: "keyboard cat",
53+
}));
54+
}
55+
```
56+
57+
## Options
58+
59+
Constructor receives an object. Following properties may be included:
60+
61+
- `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`.
62+
63+
## License
64+
65+
MIT

package.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "connect-typeorm",
3+
"description": "A TypeORM-based session store",
4+
"version": "0.1.0",
5+
"main": "out/index",
6+
"typings": "out/index",
7+
"repository": "https://github.com/makepost/typeorm-static",
8+
"author": "makepost",
9+
"license": "MIT",
10+
"devDependencies": {
11+
"pre-commit": "^1.2.2",
12+
"tslint": "^5.8.0",
13+
"typeorm": "^0.1.2",
14+
"typescript": "^2.6.1"
15+
},
16+
"dependencies": {
17+
"@types/debug": "^0.0.30",
18+
"@types/express-session": "^1.15.5",
19+
"debug": "^3.1.0",
20+
"express-session": "^1.15.6"
21+
},
22+
"peerDependencies": {
23+
"typeorm": "^0.1.2"
24+
},
25+
"scripts": {
26+
"format": "tslint --fix 'src/**/*.ts'",
27+
"lint": "tslint 'src/**/*.ts'",
28+
"prepare": "tsc -p tsconfig.json"
29+
},
30+
"pre-commit": [
31+
"lint",
32+
"prepare"
33+
]
34+
}

0 commit comments

Comments
 (0)