@1auth/store-sql 0.0.0-alpha.45 → 0.0.0-alpha.47
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.
- package/index.js +12 -0
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
const options = {
|
|
2
2
|
log: undefined,
|
|
3
3
|
query: undefined, // async (sql, parameters) => {}
|
|
4
|
+
// number of seconds after expire before removal
|
|
5
|
+
// 10d chosen based on EFF DNT Policy
|
|
6
|
+
timeToLiveExpireOffset: 10 * 24 * 60 * 60,
|
|
7
|
+
timeToLiveKey: 'remove',
|
|
4
8
|
// mode:
|
|
5
9
|
// ?: use `?` for variables, ie sqlite
|
|
6
10
|
// $: use `$1` for variables, ie postgres
|
|
@@ -66,6 +70,11 @@ export const insert = async (table, values = {}) => {
|
|
|
66
70
|
if (options.log) {
|
|
67
71
|
options.log('@1auth/store-sql insert(', table, values, ')')
|
|
68
72
|
}
|
|
73
|
+
if (values.expire && options.timeToLiveKey) {
|
|
74
|
+
values[options.timeToLiveKey] =
|
|
75
|
+
values.expire + options.timeToLiveExpireOffset
|
|
76
|
+
}
|
|
77
|
+
values = structuredClone(values)
|
|
69
78
|
normalizeValues(values)
|
|
70
79
|
const { insert, parameters } = makeSqlParts({}, values)
|
|
71
80
|
const sql = `INSERT INTO ${table} ${insert} RETURNING id`
|
|
@@ -100,6 +109,7 @@ export const update = async (table, filters = {}, values = {}) => {
|
|
|
100
109
|
if (options.log) {
|
|
101
110
|
options.log('@1auth/store-sql update(', table, filters, values, ')')
|
|
102
111
|
}
|
|
112
|
+
values = structuredClone(values)
|
|
103
113
|
normalizeValues(values)
|
|
104
114
|
const { update, where, parameters } = makeSqlParts(filters, values)
|
|
105
115
|
const sql = `UPDATE ${table} SET ${update} ${where}`
|
|
@@ -122,6 +132,7 @@ const normalizeValues = (values) => {
|
|
|
122
132
|
values.verify &&= new Date(values.verify * 1000).toISOString()
|
|
123
133
|
values.lastused &&= new Date(values.lastused * 1000).toISOString()
|
|
124
134
|
values.expire &&= new Date(values.expire * 1000).toISOString()
|
|
135
|
+
values.remove &&= new Date(values.remove * 1000).toISOString()
|
|
125
136
|
}
|
|
126
137
|
|
|
127
138
|
const parseValues = (values) => {
|
|
@@ -131,6 +142,7 @@ const parseValues = (values) => {
|
|
|
131
142
|
values.verify &&= Date.parse(values.verify) / 1000
|
|
132
143
|
values.lastused &&= Date.parse(values.lastused) / 1000
|
|
133
144
|
values.expire &&= Date.parse(values.expire) / 1000
|
|
145
|
+
values.remove &&= Date.parse(values.remove) / 1000
|
|
134
146
|
}
|
|
135
147
|
|
|
136
148
|
// export for testing
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1auth/store-sql",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.47",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -55,6 +55,6 @@
|
|
|
55
55
|
"uuid": "^11.0.0"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"better-sqlite3": "11.
|
|
58
|
+
"better-sqlite3": "^11.0.0"
|
|
59
59
|
}
|
|
60
60
|
}
|