@guren/orm 1.0.0-rc.18 → 1.0.0-rc.19
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/dist/index.d.ts +14 -6
- package/dist/index.js +3 -7
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -195,11 +195,19 @@ declare class QueryBuilder<TRecord extends PlainObject = PlainObject, TResult ex
|
|
|
195
195
|
count(): Promise<number>;
|
|
196
196
|
/**
|
|
197
197
|
* Paginate the query results.
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
198
|
+
*
|
|
199
|
+
* Accepts either positional arguments or the same options object shape as
|
|
200
|
+
* `Model.paginate()` so the two APIs stay interchangeable:
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* await Post.where('published', true).paginate(2, 10)
|
|
204
|
+
* await Post.where('published', true).paginate({ page: 2, perPage: 10 })
|
|
201
205
|
*/
|
|
202
206
|
paginate(page?: number, perPage?: number): Promise<PaginatedResult<TResult>>;
|
|
207
|
+
paginate(options: {
|
|
208
|
+
page?: number;
|
|
209
|
+
perPage?: number;
|
|
210
|
+
}): Promise<PaginatedResult<TResult>>;
|
|
203
211
|
/**
|
|
204
212
|
* Bulk update records matching the current conditions.
|
|
205
213
|
* @param data - Data to set on matching records
|
|
@@ -1189,9 +1197,9 @@ type RelationTypesFor<T extends typeof Model> = T extends {
|
|
|
1189
1197
|
type RelationKey<T extends typeof Model> = keyof RelationTypesFor<T> & string;
|
|
1190
1198
|
type RelationKeyOrString<T extends typeof Model> = RelationKey<T> extends never ? string : RelationKey<T>;
|
|
1191
1199
|
type RelationNameUnion<Names> = Names extends readonly (infer Items)[] ? Items : Names;
|
|
1192
|
-
type RelationTypePick<T extends typeof Model, Names> =
|
|
1193
|
-
[K in
|
|
1194
|
-
}
|
|
1200
|
+
type RelationTypePick<T extends typeof Model, Names> = {
|
|
1201
|
+
[K in RelationNameUnion<Names> & string & keyof RelationTypesFor<T>]: RelationTypesFor<T>[K];
|
|
1202
|
+
};
|
|
1195
1203
|
type RelationCountPick<Names> = {
|
|
1196
1204
|
[K in RelationNameUnion<Names> & string as `${K}Count`]: number;
|
|
1197
1205
|
};
|
package/dist/index.js
CHANGED
|
@@ -731,13 +731,9 @@ var QueryBuilder = class {
|
|
|
731
731
|
const results = await this.executeQuery();
|
|
732
732
|
return results.length;
|
|
733
733
|
}
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
* @param perPage - Records per page (default: 15)
|
|
738
|
-
* @returns Paginated result with data and metadata
|
|
739
|
-
*/
|
|
740
|
-
async paginate(page = 1, perPage = DEFAULT_PAGINATION_SIZE) {
|
|
734
|
+
async paginate(pageOrOptions = 1, perPageArg = DEFAULT_PAGINATION_SIZE) {
|
|
735
|
+
const page = typeof pageOrOptions === "object" ? pageOrOptions.page ?? 1 : pageOrOptions;
|
|
736
|
+
const perPage = typeof pageOrOptions === "object" ? pageOrOptions.perPage ?? DEFAULT_PAGINATION_SIZE : perPageArg;
|
|
741
737
|
const sanitizedPage = Number.isFinite(page) && page >= 1 ? Math.floor(page) : 1;
|
|
742
738
|
const sanitizedPerPage = Number.isFinite(perPage) && perPage >= 1 ? Math.floor(perPage) : DEFAULT_PAGINATION_SIZE;
|
|
743
739
|
const total = await this.count();
|