fastify-session-better-sqlite3-store 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,7 @@ jobs:
13
13
  strategy:
14
14
  matrix:
15
15
  os: [ubuntu-latest, windows-latest, macOs-latest]
16
- node-version: [12.x, 14.x, 16.x, 18.x]
16
+ node-version: [14.x, 16.x, 18.x]
17
17
 
18
18
  steps:
19
19
  - uses: actions/checkout@v3
package/README.md CHANGED
@@ -2,9 +2,10 @@
2
2
 
3
3
  ![ci](https://github.com/mrdcvlsc/fastify-session-better-sqlite3-store/actions/workflows/ci.yml/badge.svg)
4
4
  ![standard](https://github.com/mrdcvlsc/fastify-session-better-sqlite3-store/actions/workflows/standard.yml/badge.svg)
5
- [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
5
+ ![node version](https://img.shields.io/badge/node%20-%3E=%2014.x-brightgreen.svg)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)
6
7
 
7
- Session store for [@fastify/session](https://github.com/fastify/session) using [better-sqlite3](https://github.com/WiseLibs/better-sqlite3). By default [@fastify/session](https://github.com/fastify/session) stores sessions in-memory. Using this package's class you can store sessions on an **SQLite3** database instead.
8
+ [better-sqlite3](https://github.com/WiseLibs/better-sqlite3) session store for [@fastify/session](https://github.com/fastify/session). By default [@fastify/session](https://github.com/fastify/session) stores sessions in-memory. With this small package you can store sessions on an **SQLite3** database instead.
8
9
 
9
10
  ## Installation
10
11
 
@@ -17,20 +18,20 @@ npm install fastify-session-better-sqlite3-store
17
18
  Use with `fastify-session`'s `store` property.
18
19
 
19
20
  ```js
20
- const fastify = require('fastify')({logger:true})
21
+ const fastify = require('fastify')({ logger: true })
21
22
  const fastifyCookie = require('@fastify/cookie')
22
23
  const fastifySession = require('@fastify/session')
23
- const db = require('better-sqlite3')(`./sqlite.db`)
24
+ const db = require('better-sqlite3')('./sqlite.db')
24
25
 
25
26
  // require module
26
27
  const SqliteStore = require('fastify-session-better-sqlite3-store')
27
28
 
28
29
  fastify.register(fastifyCookie)
29
- fastify.register(fastifySession,{
30
+ fastify.register(fastifySession, {
31
+ store: new SqliteStore(db),
30
32
  // ...
31
33
  // other session options
32
34
  // ...
33
- store: new SqliteStore(db)
34
35
  })
35
36
  ```
36
37
 
package/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict'
2
2
 
3
+ const NODE_VERSION_REQUIREMENT = 14
3
4
  const EventEmitter = require('events')
4
5
 
5
6
  class SqliteStore extends EventEmitter {
@@ -8,6 +9,11 @@ class SqliteStore extends EventEmitter {
8
9
  * @param {string} table table name where session data will be stored, defaults to `session`.
9
10
  */
10
11
  constructor (sqlite3db, table = 'session') {
12
+ const nodeVersion = Number(process.version.match(/^v(\d+)/)[1])
13
+ if (nodeVersion < NODE_VERSION_REQUIREMENT) {
14
+ throw new Error(`node '${process.version}' not supported, needs 'v14.x' or greater`)
15
+ }
16
+
11
17
  try {
12
18
  sqlite3db.exec(`
13
19
  create table ${table} (
@@ -18,7 +24,7 @@ class SqliteStore extends EventEmitter {
18
24
  )
19
25
  } catch (err) {
20
26
  if (err.toString() !== 'SqliteError: table session already exists') {
21
- throw Error(err.toString())
27
+ throw err
22
28
  }
23
29
  }
24
30
  super()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastify-session-better-sqlite3-store",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "A simple session store for fastify-session using better-sqlite3",
5
5
  "main": "index.js",
6
6
  "scripts": {