@swarmmachina/swm-core 1.1.4 → 1.1.5

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/README.md CHANGED
@@ -327,6 +327,16 @@ const page = ctx.query('page') // ?page=1
327
327
 
328
328
  **Returns:** `string`
329
329
 
330
+ ##### `ctx.fullQuery()`
331
+
332
+ Get full raw query string.
333
+
334
+ ```javascript
335
+ const q = ctx.fullQuery() // page=1&limit=20
336
+ ```
337
+
338
+ **Returns:** `string`
339
+
330
340
  ##### `ctx.param(indexOrName)`
331
341
 
332
342
  Get URL parameter by index or name (for pattern matching in native routing).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swarmmachina/swm-core",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "Zero-dependency high-performance HTTP/WebSocket server built on uWebSockets.js",
5
5
  "keywords": [
6
6
  "http",
@@ -8,7 +8,8 @@ export default class HttpContext {
8
8
  #url = ''
9
9
  #headersCached = false
10
10
  #headers = {}
11
- #fullQuery = null
11
+ #fullQuery = ''
12
+ #fullQueryCached = false
12
13
  #fullQueryParsed = false
13
14
  #query = {}
14
15
  #params = {}
@@ -122,7 +123,8 @@ export default class HttpContext {
122
123
  this.#method = ''
123
124
  this.#headersCached = false
124
125
  this.#headers = {}
125
- this.#fullQuery = null
126
+ this.#fullQuery = ''
127
+ this.#fullQueryCached = false
126
128
  this.#fullQueryParsed = false
127
129
  this.#query = {}
128
130
  this.#params = {}
@@ -155,7 +157,8 @@ export default class HttpContext {
155
157
  this.#method = ''
156
158
  this.#headersCached = false
157
159
  this.#headers = {}
158
- this.#fullQuery = null
160
+ this.#fullQuery = ''
161
+ this.#fullQueryCached = false
159
162
  this.#fullQueryParsed = false
160
163
  this.#query = {}
161
164
  this.#params = {}
@@ -200,13 +203,14 @@ export default class HttpContext {
200
203
  }
201
204
 
202
205
  cacheQuery() {
203
- if (this.#fullQuery !== null || !this.req) {
206
+ if (this.#fullQueryCached || !this.req) {
204
207
  return
205
208
  }
206
209
 
207
210
  const fullQuery = this.req.getQuery()
208
211
 
209
212
  this.#fullQuery = typeof fullQuery === 'string' ? fullQuery : ''
213
+ this.#fullQueryCached = true
210
214
  this.#fullQueryParsed = false
211
215
  }
212
216
 
@@ -291,6 +295,27 @@ export default class HttpContext {
291
295
  return this.#url
292
296
  }
293
297
 
298
+ /**
299
+ * @returns {string}
300
+ */
301
+ fullQuery() {
302
+ if (this.#fullQueryCached) {
303
+ return this.#fullQuery
304
+ }
305
+
306
+ if (!this.req) {
307
+ return ''
308
+ }
309
+
310
+ const fullQuery = this.req.getQuery()
311
+
312
+ this.#fullQuery = typeof fullQuery === 'string' ? fullQuery : ''
313
+ this.#fullQueryCached = true
314
+ this.#fullQueryParsed = false
315
+
316
+ return this.#fullQuery
317
+ }
318
+
294
319
  /**
295
320
  * @param {string} name
296
321
  * @returns {string|undefined}
@@ -300,7 +325,7 @@ export default class HttpContext {
300
325
  return this.#query[name]
301
326
  }
302
327
 
303
- if (this.#fullQuery !== null) {
328
+ if (this.#fullQueryCached) {
304
329
  this.#parseFullQuery()
305
330
 
306
331
  if (name in this.#query) {