@nxtedition/lib 26.0.9 → 26.0.11

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.
Files changed (3) hide show
  1. package/cache.js +31 -28
  2. package/http.js +11 -8
  3. package/package.json +1 -1
package/cache.js CHANGED
@@ -80,34 +80,37 @@ export class AsyncCache {
80
80
  this.#lru =
81
81
  opts?.lru === false || opts?.lru === null ? null : new LRUCache({ max: 4096, ...opts?.lru })
82
82
 
83
- for (let n = 0; true; n += 1) {
84
- try {
85
- this.#db = new DatabaseSync(location, { timeout: 20, ...opts?.db })
86
-
87
- this.#db.exec(`
88
- PRAGMA journal_mode = WAL;
89
- PRAGMA synchronous = NORMAL;
90
- PRAGMA temp_store = memory;
91
- PRAGMA optimize;
92
-
93
- CREATE TABLE IF NOT EXISTS cache (
94
- key TEXT PRIMARY KEY NOT NULL,
95
- val TEXT NOT NULL,
96
- ttl INTEGER NOT NULL,
97
- stale INTEGER NOT NULL
98
- );
99
- `)
100
-
101
- this.#getQuery = this.#db.prepare(`SELECT val, ttl, stale FROM cache WHERE key = ?`)
102
- this.#setQuery = this.#db.prepare(
103
- `INSERT OR REPLACE INTO cache (key, val, ttl, stale) VALUES (?, ?, ?, ?)`,
104
- )
105
- this.#delQuery = this.#db.prepare(`DELETE FROM cache WHERE key = ?`)
106
- } catch (err) {
107
- if (n > 128 || !/locked|busy/i.test(err?.message)) {
108
- throw err
109
- }
110
- }
83
+ try {
84
+ this.#db = new DatabaseSync(location, { timeout: 20, ...opts?.db })
85
+
86
+ this.#db.exec(`
87
+ PRAGMA journal_mode = WAL;
88
+ PRAGMA synchronous = NORMAL;
89
+ PRAGMA temp_store = memory;
90
+ PRAGMA optimize;
91
+
92
+ CREATE TABLE IF NOT EXISTS cache (
93
+ key TEXT PRIMARY KEY NOT NULL,
94
+ val TEXT NOT NULL,
95
+ ttl INTEGER NOT NULL,
96
+ stale INTEGER NOT NULL
97
+ );
98
+ `)
99
+
100
+ this.#getQuery = this.#db.prepare(`SELECT val, ttl, stale FROM cache WHERE key = ?`)
101
+ this.#setQuery = this.#db.prepare(
102
+ `INSERT OR REPLACE INTO cache (key, val, ttl, stale) VALUES (?, ?, ?, ?)`,
103
+ )
104
+ this.#delQuery = this.#db.prepare(`DELETE FROM cache WHERE key = ?`)
105
+ } catch (err) {
106
+ this.#db?.close()
107
+ this.#db = null
108
+
109
+ this.#getQuery = null
110
+ this.#setQuery = null
111
+ this.#delQuery = null
112
+
113
+ process.emitWarning(err)
111
114
  }
112
115
  }
113
116
 
package/http.js CHANGED
@@ -75,7 +75,7 @@ export class Context {
75
75
  return this.#req.target
76
76
  }
77
77
 
78
- this.#target ??= requestTarget(this.#req)
78
+ this.#target ??= Object.freeze(requestTarget(this.#req))
79
79
 
80
80
  if (!this.#target) {
81
81
  throw new createError.BadRequest('invalid url')
@@ -89,13 +89,10 @@ export class Context {
89
89
  return this.#req.query
90
90
  }
91
91
 
92
- this.#target ??= requestTarget(this.#req)
93
- this.#query ??=
94
- this.#target.search.length > 1
95
- ? Object.freeze(querystring.parse(this.#target.search.slice(1)))
96
- : {}
92
+ const search = this.target.search
97
93
 
98
- return this.#query
94
+ return (this.#query ??=
95
+ search.length > 1 ? Object.freeze(querystring.parse(search.slice(1))) : {})
99
96
  }
100
97
 
101
98
  get userAgent() {
@@ -373,7 +370,13 @@ export class IncomingMessage extends http.IncomingMessage {
373
370
  this.#target = undefined
374
371
  }
375
372
 
376
- return (this.#target ??= requestTarget(this))
373
+ this.#target ??= Object.freeze(requestTarget(this))
374
+
375
+ if (!this.#target) {
376
+ throw new createError.BadRequest('invalid url')
377
+ }
378
+
379
+ return this.#target
377
380
  }
378
381
 
379
382
  get query() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "26.0.9",
3
+ "version": "26.0.11",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",