tina4-nodejs 3.10.50 → 3.10.60

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,24 +73,44 @@ export class DatabaseResult implements Iterable<Record<string, unknown>> {
73
73
  return this.records;
74
74
  }
75
75
 
76
- /** Pagination envelope with slicing. */
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
+ */
77
85
  toPaginate(page = 1, perPage = 10): {
86
+ records: Record<string, unknown>[];
78
87
  data: Record<string, unknown>[];
88
+ count: number;
89
+ total: number;
90
+ limit: number;
91
+ offset: number;
79
92
  page: number;
80
93
  per_page: number;
81
- total: number;
94
+ perPage: number;
95
+ totalPages: number;
82
96
  total_pages: number;
83
97
  has_next: boolean;
84
98
  has_prev: boolean;
85
99
  } {
86
100
  const totalPages = Math.max(1, Math.ceil(this.count / perPage));
87
- const start = (page - 1) * perPage;
88
- const end = start + perPage;
101
+ const offset = (page - 1) * perPage;
102
+ const sliced = this.records.slice(offset, offset + perPage);
89
103
  return {
90
- data: this.records.slice(start, end),
104
+ records: sliced,
105
+ data: sliced,
106
+ count: this.count,
107
+ total: this.count,
108
+ limit: perPage,
109
+ offset,
91
110
  page,
92
111
  per_page: perPage,
93
- total: this.count,
112
+ perPage,
113
+ totalPages,
94
114
  total_pages: totalPages,
95
115
  has_next: page < totalPages,
96
116
  has_prev: page > 1,
@@ -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";
@@ -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
  }