fusion-framework 1.2.5 → 1.2.6

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.
Binary file
Binary file
Binary file
Binary file
package/index.js CHANGED
@@ -134,7 +134,7 @@ header.fingerprint = () =>
134
134
  : {
135
135
  'X-Powered-By': 'Fusion Framework',
136
136
  'X-Framework': 'Fusion',
137
- ['X-Fusion-Version']: '1.2.5',
137
+ ['X-Fusion-Version']: '1.2.6',
138
138
  }
139
139
 
140
140
  function isThenable(value) {
@@ -208,6 +208,26 @@ class FusionBaseApi {
208
208
  if (keys.length) out.headers = { ...headers }
209
209
  return out
210
210
  }
211
+
212
+ pagination({
213
+ page,
214
+ pageSize,
215
+ offset,
216
+ defaultPageSize = 20,
217
+ maxPageSize = 100,
218
+ } = {}) {
219
+ const query = { ...(this.query || {}) }
220
+ if (page != null) query.page = String(page)
221
+ if (pageSize != null) query.page_size = String(pageSize)
222
+ if (offset != null) query.offset = String(offset)
223
+ return parsePagination(query, { defaultPageSize, maxPageSize })
224
+ }
225
+
226
+ paginated(items, total, params = null, { page, pageSize, status = 200, headers } = {}) {
227
+ const p = params ?? this.pagination({ page, pageSize })
228
+ const body = paginatedBody(items, total, p)
229
+ return this.response(body, status, headers || {})
230
+ }
211
231
  }
212
232
 
213
233
  function apiResourceName(cls) {
@@ -973,6 +993,18 @@ function pathToFileUrl(filePath) {
973
993
  return require('url').pathToFileURL(resolved).href
974
994
  }
975
995
 
996
+ function parsePagination(query, { defaultPageSize = 20, maxPageSize = 100 } = {}) {
997
+ try {
998
+ return native.parsePagination(query, defaultPageSize, maxPageSize)
999
+ } catch (err) {
1000
+ throw new HTTPException(400, err?.message || 'invalid pagination')
1001
+ }
1002
+ }
1003
+
1004
+ function paginatedBody(items, total, params) {
1005
+ return native.paginatedBody(items, total, params)
1006
+ }
1007
+
976
1008
  const route = router
977
1009
 
978
1010
  module.exports = {
@@ -1006,6 +1038,8 @@ module.exports = {
1006
1038
  frameworkHeaders,
1007
1039
  runMiddlewareChain,
1008
1040
  coerceParam,
1041
+ parsePagination,
1042
+ paginatedBody,
1009
1043
  getHttpMethods: () => HTTP_METHODS,
1010
1044
  apiResourceNameJs: native.apiResourceNameJs,
1011
1045
  resolveRoutePathJs: native.resolveRoutePathJs,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fusion-framework",
3
- "version": "1.2.5",
3
+ "version": "1.2.6",
4
4
  "description": "Class-based HTTP framework for Node.js, powered by a shared Rust core via N-API",
5
5
  "keywords": [
6
6
  "http",