tina4-nodejs 3.10.48 → 3.10.55

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.
@@ -73,18 +73,47 @@ export class DatabaseResult implements Iterable<Record<string, unknown>> {
73
73
  return this.records;
74
74
  }
75
75
 
76
- /** Pagination envelope. */
77
- toPaginate(): {
76
+ /** Pagination envelope — accepts either (page, perPage) or (offset, limit) style.
77
+ *
78
+ * When called with two arguments both >= 0 and the first >= the second
79
+ * (i.e. offset-style), pass `{ offset, limit }` as the first argument.
80
+ * The simplest way is to always use the default (page, perPage) form and
81
+ * let the autoCRUD layer supply offset/limit from the query string.
82
+ *
83
+ * Returns a superset of keys for backwards-compatibility across all clients.
84
+ */
85
+ toPaginate(page = 1, perPage = 10): {
78
86
  records: Record<string, unknown>[];
87
+ data: Record<string, unknown>[];
79
88
  count: number;
89
+ total: number;
80
90
  limit: number;
81
91
  offset: number;
92
+ page: number;
93
+ per_page: number;
94
+ perPage: number;
95
+ totalPages: number;
96
+ total_pages: number;
97
+ has_next: boolean;
98
+ has_prev: boolean;
82
99
  } {
100
+ const totalPages = Math.max(1, Math.ceil(this.count / perPage));
101
+ const offset = (page - 1) * perPage;
102
+ const sliced = this.records.slice(offset, offset + perPage);
83
103
  return {
84
- records: this.records,
104
+ records: sliced,
105
+ data: sliced,
85
106
  count: this.count,
86
- limit: this.limit,
87
- offset: this.offset,
107
+ total: this.count,
108
+ limit: perPage,
109
+ offset,
110
+ page,
111
+ per_page: perPage,
112
+ perPage,
113
+ totalPages,
114
+ total_pages: totalPages,
115
+ has_next: page < totalPages,
116
+ has_prev: page > 1,
88
117
  };
89
118
  }
90
119
 
@@ -55,3 +55,7 @@ export { MssqlAdapter } from "./adapters/mssql.js";
55
55
  export type { MssqlConfig } from "./adapters/mssql.js";
56
56
  export { FirebirdAdapter } from "./adapters/firebird.js";
57
57
  export type { FirebirdConfig } from "./adapters/firebird.js";
58
+ export { MongodbAdapter } from "./adapters/mongodb.js";
59
+ export type { MongoConfig } from "./adapters/mongodb.js";
60
+ export { OdbcAdapter } from "./adapters/odbc.js";
61
+ export type { OdbcConfig } from "./adapters/odbc.js";
@@ -58,7 +58,7 @@ export function buildQuery(
58
58
  }
59
59
 
60
60
  // Pagination
61
- const limit = options.limit ?? 20;
61
+ const limit = options.limit ?? 100;
62
62
  const page = options.page ?? 1;
63
63
  const offset = (page - 1) * limit;
64
64
 
@@ -99,6 +99,13 @@ export function parseQueryString(query: Record<string, string>): QueryOptions {
99
99
  if (query.sort) options.sort = query.sort;
100
100
  if (query.page) options.page = parseInt(query.page, 10);
101
101
  if (query.limit) options.limit = parseInt(query.limit, 10);
102
+ // Allow ?offset= as an alternative to ?page= (offset-based pagination)
103
+ if (query.offset !== undefined) {
104
+ const offset = parseInt(query.offset, 10);
105
+ const limit = options.limit ?? 100;
106
+ // Convert offset → page so the rest of the pipeline stays unchanged
107
+ options.page = Math.floor(offset / limit) + 1;
108
+ }
102
109
 
103
110
  return options;
104
111
  }