@guren/orm 1.0.0-rc.18 → 1.0.0-rc.20
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 +6 -9
- 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
|
@@ -6,11 +6,12 @@ if (!marker) {
|
|
|
6
6
|
globalScope[INSTANCE_KEY] = { count: 1, warned: false };
|
|
7
7
|
} else {
|
|
8
8
|
marker.count += 1;
|
|
9
|
-
|
|
9
|
+
const quiet = typeof process !== "undefined" && process.env.GUREN_QUIET_DUPLICATE_ORM === "1";
|
|
10
|
+
if (!marker.warned && !quiet) {
|
|
10
11
|
marker.warned = true;
|
|
11
12
|
console.warn(
|
|
12
13
|
`[guren/orm] ${marker.count} copies of @guren/orm are loaded in this process. Adapter configuration and model state are NOT shared between copies, so database access will fail with "database has not been configured" for models imported through the extra copy.
|
|
13
|
-
[guren/orm] This usually means mixed @guren/* versions (check \`bun pm ls | grep @guren\`). Fix it by aligning all @guren/* packages to the same release, e.g. \`bunx guren upgrade\` or updating every @guren/* entry in package.json together, then reinstalling.`
|
|
14
|
+
[guren/orm] This usually means mixed @guren/* versions (check \`bun pm ls | grep @guren\`). Fix it by aligning all @guren/* packages to the same release, e.g. \`bunx guren upgrade\` or updating every @guren/* entry in package.json together, then reinstalling. Set GUREN_QUIET_DUPLICATE_ORM=1 to silence this warning (e.g. monorepo dev where src and dist copies coexist by design).`
|
|
14
15
|
);
|
|
15
16
|
}
|
|
16
17
|
}
|
|
@@ -731,13 +732,9 @@ var QueryBuilder = class {
|
|
|
731
732
|
const results = await this.executeQuery();
|
|
732
733
|
return results.length;
|
|
733
734
|
}
|
|
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) {
|
|
735
|
+
async paginate(pageOrOptions = 1, perPageArg = DEFAULT_PAGINATION_SIZE) {
|
|
736
|
+
const page = typeof pageOrOptions === "object" ? pageOrOptions.page ?? 1 : pageOrOptions;
|
|
737
|
+
const perPage = typeof pageOrOptions === "object" ? pageOrOptions.perPage ?? DEFAULT_PAGINATION_SIZE : perPageArg;
|
|
741
738
|
const sanitizedPage = Number.isFinite(page) && page >= 1 ? Math.floor(page) : 1;
|
|
742
739
|
const sanitizedPerPage = Number.isFinite(perPage) && perPage >= 1 ? Math.floor(perPage) : DEFAULT_PAGINATION_SIZE;
|
|
743
740
|
const total = await this.count();
|