arkormx 0.2.10 → 0.2.11

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/cli.mjs CHANGED
@@ -1135,6 +1135,7 @@ let runtimeConfigLoaded = false;
1135
1135
  let runtimeConfigLoadingPromise;
1136
1136
  let runtimeClientResolver;
1137
1137
  let runtimePaginationURLDriverFactory;
1138
+ let runtimePaginationCurrentPageResolver;
1138
1139
  const mergePathConfig = (paths) => {
1139
1140
  const defaults = baseConfig.paths ?? {};
1140
1141
  const current = userConfig.paths ?? {};
@@ -1175,6 +1176,7 @@ const configureArkormRuntime = (prisma, options = {}) => {
1175
1176
  Object.assign(userConfig, { ...nextConfig });
1176
1177
  runtimeClientResolver = prisma;
1177
1178
  runtimePaginationURLDriverFactory = nextConfig.pagination?.urlDriver;
1179
+ runtimePaginationCurrentPageResolver = nextConfig.pagination?.resolveCurrentPage;
1178
1180
  };
1179
1181
  /**
1180
1182
  * Resolve and apply the ArkORM configuration from an imported module.
package/dist/index.cjs CHANGED
@@ -1275,6 +1275,7 @@ let runtimeConfigLoaded = false;
1275
1275
  let runtimeConfigLoadingPromise;
1276
1276
  let runtimeClientResolver;
1277
1277
  let runtimePaginationURLDriverFactory;
1278
+ let runtimePaginationCurrentPageResolver;
1278
1279
  const mergePathConfig = (paths) => {
1279
1280
  const defaults = baseConfig.paths ?? {};
1280
1281
  const current = userConfig.paths ?? {};
@@ -1324,6 +1325,7 @@ const configureArkormRuntime = (prisma, options = {}) => {
1324
1325
  Object.assign(userConfig, { ...nextConfig });
1325
1326
  runtimeClientResolver = prisma;
1326
1327
  runtimePaginationURLDriverFactory = nextConfig.pagination?.urlDriver;
1328
+ runtimePaginationCurrentPageResolver = nextConfig.pagination?.resolveCurrentPage;
1327
1329
  };
1328
1330
  /**
1329
1331
  * Reset the ArkORM runtime configuration.
@@ -1338,6 +1340,7 @@ const resetArkormRuntimeForTests = () => {
1338
1340
  runtimeConfigLoadingPromise = void 0;
1339
1341
  runtimeClientResolver = void 0;
1340
1342
  runtimePaginationURLDriverFactory = void 0;
1343
+ runtimePaginationCurrentPageResolver = void 0;
1341
1344
  };
1342
1345
  /**
1343
1346
  * Resolve a Prisma client instance from the provided resolver, which can be either
@@ -1453,6 +1456,15 @@ const getRuntimePaginationURLDriverFactory = () => {
1453
1456
  return runtimePaginationURLDriverFactory;
1454
1457
  };
1455
1458
  /**
1459
+ * Get the configured current-page resolver from runtime config.
1460
+ *
1461
+ * @returns
1462
+ */
1463
+ const getRuntimePaginationCurrentPageResolver = () => {
1464
+ if (!runtimeConfigLoaded) loadRuntimeConfigSync();
1465
+ return runtimePaginationCurrentPageResolver;
1466
+ };
1467
+ /**
1456
1468
  * Check if a given value is a Prisma delegate-like object
1457
1469
  * by verifying the presence of common delegate methods.
1458
1470
  *
@@ -3505,6 +3517,13 @@ var QueryBuilder = class QueryBuilder {
3505
3517
  this.delegate = delegate;
3506
3518
  this.model = model;
3507
3519
  }
3520
+ resolvePaginationPage(page, options) {
3521
+ if (typeof page !== "undefined") return Number.isFinite(page) ? Math.max(1, page) : 1;
3522
+ const pageName = options.pageName ?? "page";
3523
+ const resolvedPage = getRuntimePaginationCurrentPageResolver()?.(pageName, options);
3524
+ if (typeof resolvedPage !== "number" || !Number.isFinite(resolvedPage)) return 1;
3525
+ return Math.max(1, resolvedPage);
3526
+ }
3508
3527
  /**
3509
3528
  * Adds a where clause to the query. Multiple calls to where will combine
3510
3529
  * the clauses with AND logic.
@@ -4623,15 +4642,14 @@ var QueryBuilder = class QueryBuilder {
4623
4642
  * @param options
4624
4643
  * @returns
4625
4644
  */
4626
- async paginate(page = 1, perPage = 15, options = {}) {
4645
+ async paginate(perPage = 15, page = void 0, options = {}) {
4646
+ const currentPage = this.resolvePaginationPage(page, options);
4627
4647
  if (this.hasRelationFilters() || this.hasRelationAggregates()) {
4628
- const currentPage = Math.max(1, page);
4629
4648
  const pageSize = Math.max(1, perPage);
4630
4649
  const rows = (await this.get()).all();
4631
4650
  const start = (currentPage - 1) * pageSize;
4632
4651
  return new LengthAwarePaginator(new ArkormCollection(rows.slice(start, start + pageSize)), rows.length, pageSize, currentPage, options);
4633
4652
  }
4634
- const currentPage = Math.max(1, page);
4635
4653
  const pageSize = Math.max(1, perPage);
4636
4654
  const total = await this.count();
4637
4655
  return new LengthAwarePaginator(await this.clone().skip((currentPage - 1) * pageSize).take(pageSize).get(), total, pageSize, currentPage, options);
@@ -4643,9 +4661,9 @@ var QueryBuilder = class QueryBuilder {
4643
4661
  * @param page
4644
4662
  * @returns
4645
4663
  */
4646
- async simplePaginate(perPage = 15, page = 1, options = {}) {
4664
+ async simplePaginate(perPage = 15, page = void 0, options = {}) {
4665
+ const currentPage = this.resolvePaginationPage(page, options);
4647
4666
  if (this.hasRelationFilters() || this.hasRelationAggregates()) {
4648
- const currentPage = Math.max(1, page);
4649
4667
  const pageSize = Math.max(1, perPage);
4650
4668
  const rows = (await this.get()).all();
4651
4669
  const start = (currentPage - 1) * pageSize;
@@ -4653,7 +4671,6 @@ var QueryBuilder = class QueryBuilder {
4653
4671
  const hasMorePages = start + pageSize < rows.length;
4654
4672
  return new Paginator(new ArkormCollection(pageRows), pageSize, currentPage, hasMorePages, options);
4655
4673
  }
4656
- const currentPage = Math.max(1, page);
4657
4674
  const pageSize = Math.max(1, perPage);
4658
4675
  const items = await this.clone().skip((currentPage - 1) * pageSize).take(pageSize + 1).get();
4659
4676
  const hasMorePages = items.all().length > pageSize;
@@ -5546,6 +5563,7 @@ exports.getDefaultStubsPath = getDefaultStubsPath;
5546
5563
  exports.getLastMigrationRun = getLastMigrationRun;
5547
5564
  exports.getLatestAppliedMigrations = getLatestAppliedMigrations;
5548
5565
  exports.getMigrationPlan = getMigrationPlan;
5566
+ exports.getRuntimePaginationCurrentPageResolver = getRuntimePaginationCurrentPageResolver;
5549
5567
  exports.getRuntimePaginationURLDriverFactory = getRuntimePaginationURLDriverFactory;
5550
5568
  exports.getRuntimePrismaClient = getRuntimePrismaClient;
5551
5569
  exports.getUserConfig = getUserConfig;
package/dist/index.d.cts CHANGED
@@ -1039,6 +1039,7 @@ declare class QueryBuilder<TModel, TDelegate extends PrismaDelegateLike = Prisma
1039
1039
  * @param model
1040
1040
  */
1041
1041
  constructor(delegate: TDelegate, model: ModelStatic<TModel, TDelegate>);
1042
+ private resolvePaginationPage;
1042
1043
  /**
1043
1044
  * Adds a where clause to the query. Multiple calls to where will combine
1044
1045
  * the clauses with AND logic.
@@ -1700,7 +1701,7 @@ declare class QueryBuilder<TModel, TDelegate extends PrismaDelegateLike = Prisma
1700
1701
  * @param options
1701
1702
  * @returns
1702
1703
  */
1703
- paginate(page?: number, perPage?: number, options?: PaginationOptions): Promise<LengthAwarePaginator<TModel>>;
1704
+ paginate(perPage?: number, page?: number | undefined, options?: PaginationOptions): Promise<LengthAwarePaginator<TModel>>;
1704
1705
  /**
1705
1706
  * Paginates results without calculating total row count.
1706
1707
  *
@@ -1708,7 +1709,7 @@ declare class QueryBuilder<TModel, TDelegate extends PrismaDelegateLike = Prisma
1708
1709
  * @param page
1709
1710
  * @returns
1710
1711
  */
1711
- simplePaginate(perPage?: number, page?: number, options?: PaginationOptions): Promise<Paginator<TModel>>;
1712
+ simplePaginate(perPage?: number, page?: number | undefined, options?: PaginationOptions): Promise<Paginator<TModel>>;
1712
1713
  /**
1713
1714
  * Creates a clone of the current query builder instance with the same state.
1714
1715
  *
@@ -1799,6 +1800,7 @@ interface ArkormConfig {
1799
1800
  */
1800
1801
  pagination?: {
1801
1802
  urlDriver?: PaginationURLDriverFactory;
1803
+ resolveCurrentPage?: PaginationCurrentPageResolver;
1802
1804
  };
1803
1805
  /**
1804
1806
  * @property paths Optional custom paths for various generated files.
@@ -1866,6 +1868,7 @@ interface PaginationOptions {
1866
1868
  fragment?: string;
1867
1869
  pageName?: string;
1868
1870
  }
1871
+ type PaginationCurrentPageResolver = (pageName: string, options: PaginationOptions) => number | undefined;
1869
1872
  interface PaginationURLDriver {
1870
1873
  getPageName: () => string;
1871
1874
  url: (page: number) => string;
@@ -3128,6 +3131,12 @@ declare const getRuntimePrismaClient: () => PrismaClientLike | undefined;
3128
3131
  * @returns
3129
3132
  */
3130
3133
  declare const getRuntimePaginationURLDriverFactory: () => PaginationURLDriverFactory | undefined;
3134
+ /**
3135
+ * Get the configured current-page resolver from runtime config.
3136
+ *
3137
+ * @returns
3138
+ */
3139
+ declare const getRuntimePaginationCurrentPageResolver: () => PaginationCurrentPageResolver | undefined;
3131
3140
  /**
3132
3141
  * Check if a given value is a Prisma delegate-like object
3133
3142
  * by verifying the presence of common delegate methods.
@@ -3182,4 +3191,4 @@ declare class URLDriver {
3182
3191
  url(page: number): string;
3183
3192
  }
3184
3193
  //#endregion
3185
- export { ArkormCollection, ArkormException, Attribute, AttributeOptions, CliApp, ForeignKeyBuilder, InitCommand, InlineFactory, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateRollbackCommand, Migration, MigrationHistoryCommand, Model, ModelFactory, ModelNotFoundException, ModelsSyncCommand, PRISMA_MODEL_REGEX, Paginator, PrismaDelegateMap, QueryBuilder, SEEDER_BRAND, SchemaBuilder, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, TableBuilder, URLDriver, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToPrismaSchema, applyMigrationToPrismaSchema, applyOperationsToPrismaSchema, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createMigrationTimestamp, createPrismaAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationFieldName, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findModelBlock, formatDefaultValue, formatRelationAction, generateMigrationFile, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, removeAppliedMigration, resetArkormRuntimeForTests, resolveCast, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePrismaType, runMigrationWithPrisma, runPrismaCommand, toMigrationFileSlug, toModelName, writeAppliedMigrationsState };
3194
+ export { ArkormCollection, ArkormException, Attribute, AttributeOptions, CliApp, ForeignKeyBuilder, InitCommand, InlineFactory, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateRollbackCommand, Migration, MigrationHistoryCommand, Model, ModelFactory, ModelNotFoundException, ModelsSyncCommand, PRISMA_MODEL_REGEX, Paginator, PrismaDelegateMap, QueryBuilder, SEEDER_BRAND, SchemaBuilder, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, TableBuilder, URLDriver, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToPrismaSchema, applyMigrationToPrismaSchema, applyOperationsToPrismaSchema, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createMigrationTimestamp, createPrismaAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationFieldName, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findModelBlock, formatDefaultValue, formatRelationAction, generateMigrationFile, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getRuntimePaginationCurrentPageResolver, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, removeAppliedMigration, resetArkormRuntimeForTests, resolveCast, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePrismaType, runMigrationWithPrisma, runPrismaCommand, toMigrationFileSlug, toModelName, writeAppliedMigrationsState };
package/dist/index.d.mts CHANGED
@@ -1039,6 +1039,7 @@ declare class QueryBuilder<TModel, TDelegate extends PrismaDelegateLike = Prisma
1039
1039
  * @param model
1040
1040
  */
1041
1041
  constructor(delegate: TDelegate, model: ModelStatic<TModel, TDelegate>);
1042
+ private resolvePaginationPage;
1042
1043
  /**
1043
1044
  * Adds a where clause to the query. Multiple calls to where will combine
1044
1045
  * the clauses with AND logic.
@@ -1700,7 +1701,7 @@ declare class QueryBuilder<TModel, TDelegate extends PrismaDelegateLike = Prisma
1700
1701
  * @param options
1701
1702
  * @returns
1702
1703
  */
1703
- paginate(page?: number, perPage?: number, options?: PaginationOptions): Promise<LengthAwarePaginator<TModel>>;
1704
+ paginate(perPage?: number, page?: number | undefined, options?: PaginationOptions): Promise<LengthAwarePaginator<TModel>>;
1704
1705
  /**
1705
1706
  * Paginates results without calculating total row count.
1706
1707
  *
@@ -1708,7 +1709,7 @@ declare class QueryBuilder<TModel, TDelegate extends PrismaDelegateLike = Prisma
1708
1709
  * @param page
1709
1710
  * @returns
1710
1711
  */
1711
- simplePaginate(perPage?: number, page?: number, options?: PaginationOptions): Promise<Paginator<TModel>>;
1712
+ simplePaginate(perPage?: number, page?: number | undefined, options?: PaginationOptions): Promise<Paginator<TModel>>;
1712
1713
  /**
1713
1714
  * Creates a clone of the current query builder instance with the same state.
1714
1715
  *
@@ -1799,6 +1800,7 @@ interface ArkormConfig {
1799
1800
  */
1800
1801
  pagination?: {
1801
1802
  urlDriver?: PaginationURLDriverFactory;
1803
+ resolveCurrentPage?: PaginationCurrentPageResolver;
1802
1804
  };
1803
1805
  /**
1804
1806
  * @property paths Optional custom paths for various generated files.
@@ -1866,6 +1868,7 @@ interface PaginationOptions {
1866
1868
  fragment?: string;
1867
1869
  pageName?: string;
1868
1870
  }
1871
+ type PaginationCurrentPageResolver = (pageName: string, options: PaginationOptions) => number | undefined;
1869
1872
  interface PaginationURLDriver {
1870
1873
  getPageName: () => string;
1871
1874
  url: (page: number) => string;
@@ -3128,6 +3131,12 @@ declare const getRuntimePrismaClient: () => PrismaClientLike | undefined;
3128
3131
  * @returns
3129
3132
  */
3130
3133
  declare const getRuntimePaginationURLDriverFactory: () => PaginationURLDriverFactory | undefined;
3134
+ /**
3135
+ * Get the configured current-page resolver from runtime config.
3136
+ *
3137
+ * @returns
3138
+ */
3139
+ declare const getRuntimePaginationCurrentPageResolver: () => PaginationCurrentPageResolver | undefined;
3131
3140
  /**
3132
3141
  * Check if a given value is a Prisma delegate-like object
3133
3142
  * by verifying the presence of common delegate methods.
@@ -3182,4 +3191,4 @@ declare class URLDriver {
3182
3191
  url(page: number): string;
3183
3192
  }
3184
3193
  //#endregion
3185
- export { ArkormCollection, ArkormException, Attribute, AttributeOptions, CliApp, ForeignKeyBuilder, InitCommand, InlineFactory, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateRollbackCommand, Migration, MigrationHistoryCommand, Model, ModelFactory, ModelNotFoundException, ModelsSyncCommand, PRISMA_MODEL_REGEX, Paginator, PrismaDelegateMap, QueryBuilder, SEEDER_BRAND, SchemaBuilder, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, TableBuilder, URLDriver, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToPrismaSchema, applyMigrationToPrismaSchema, applyOperationsToPrismaSchema, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createMigrationTimestamp, createPrismaAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationFieldName, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findModelBlock, formatDefaultValue, formatRelationAction, generateMigrationFile, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, removeAppliedMigration, resetArkormRuntimeForTests, resolveCast, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePrismaType, runMigrationWithPrisma, runPrismaCommand, toMigrationFileSlug, toModelName, writeAppliedMigrationsState };
3194
+ export { ArkormCollection, ArkormException, Attribute, AttributeOptions, CliApp, ForeignKeyBuilder, InitCommand, InlineFactory, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateRollbackCommand, Migration, MigrationHistoryCommand, Model, ModelFactory, ModelNotFoundException, ModelsSyncCommand, PRISMA_MODEL_REGEX, Paginator, PrismaDelegateMap, QueryBuilder, SEEDER_BRAND, SchemaBuilder, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, TableBuilder, URLDriver, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToPrismaSchema, applyMigrationToPrismaSchema, applyOperationsToPrismaSchema, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createMigrationTimestamp, createPrismaAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationFieldName, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findModelBlock, formatDefaultValue, formatRelationAction, generateMigrationFile, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getRuntimePaginationCurrentPageResolver, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, removeAppliedMigration, resetArkormRuntimeForTests, resolveCast, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePrismaType, runMigrationWithPrisma, runPrismaCommand, toMigrationFileSlug, toModelName, writeAppliedMigrationsState };
package/dist/index.mjs CHANGED
@@ -1246,6 +1246,7 @@ let runtimeConfigLoaded = false;
1246
1246
  let runtimeConfigLoadingPromise;
1247
1247
  let runtimeClientResolver;
1248
1248
  let runtimePaginationURLDriverFactory;
1249
+ let runtimePaginationCurrentPageResolver;
1249
1250
  const mergePathConfig = (paths) => {
1250
1251
  const defaults = baseConfig.paths ?? {};
1251
1252
  const current = userConfig.paths ?? {};
@@ -1295,6 +1296,7 @@ const configureArkormRuntime = (prisma, options = {}) => {
1295
1296
  Object.assign(userConfig, { ...nextConfig });
1296
1297
  runtimeClientResolver = prisma;
1297
1298
  runtimePaginationURLDriverFactory = nextConfig.pagination?.urlDriver;
1299
+ runtimePaginationCurrentPageResolver = nextConfig.pagination?.resolveCurrentPage;
1298
1300
  };
1299
1301
  /**
1300
1302
  * Reset the ArkORM runtime configuration.
@@ -1309,6 +1311,7 @@ const resetArkormRuntimeForTests = () => {
1309
1311
  runtimeConfigLoadingPromise = void 0;
1310
1312
  runtimeClientResolver = void 0;
1311
1313
  runtimePaginationURLDriverFactory = void 0;
1314
+ runtimePaginationCurrentPageResolver = void 0;
1312
1315
  };
1313
1316
  /**
1314
1317
  * Resolve a Prisma client instance from the provided resolver, which can be either
@@ -1424,6 +1427,15 @@ const getRuntimePaginationURLDriverFactory = () => {
1424
1427
  return runtimePaginationURLDriverFactory;
1425
1428
  };
1426
1429
  /**
1430
+ * Get the configured current-page resolver from runtime config.
1431
+ *
1432
+ * @returns
1433
+ */
1434
+ const getRuntimePaginationCurrentPageResolver = () => {
1435
+ if (!runtimeConfigLoaded) loadRuntimeConfigSync();
1436
+ return runtimePaginationCurrentPageResolver;
1437
+ };
1438
+ /**
1427
1439
  * Check if a given value is a Prisma delegate-like object
1428
1440
  * by verifying the presence of common delegate methods.
1429
1441
  *
@@ -3476,6 +3488,13 @@ var QueryBuilder = class QueryBuilder {
3476
3488
  this.delegate = delegate;
3477
3489
  this.model = model;
3478
3490
  }
3491
+ resolvePaginationPage(page, options) {
3492
+ if (typeof page !== "undefined") return Number.isFinite(page) ? Math.max(1, page) : 1;
3493
+ const pageName = options.pageName ?? "page";
3494
+ const resolvedPage = getRuntimePaginationCurrentPageResolver()?.(pageName, options);
3495
+ if (typeof resolvedPage !== "number" || !Number.isFinite(resolvedPage)) return 1;
3496
+ return Math.max(1, resolvedPage);
3497
+ }
3479
3498
  /**
3480
3499
  * Adds a where clause to the query. Multiple calls to where will combine
3481
3500
  * the clauses with AND logic.
@@ -4594,15 +4613,14 @@ var QueryBuilder = class QueryBuilder {
4594
4613
  * @param options
4595
4614
  * @returns
4596
4615
  */
4597
- async paginate(page = 1, perPage = 15, options = {}) {
4616
+ async paginate(perPage = 15, page = void 0, options = {}) {
4617
+ const currentPage = this.resolvePaginationPage(page, options);
4598
4618
  if (this.hasRelationFilters() || this.hasRelationAggregates()) {
4599
- const currentPage = Math.max(1, page);
4600
4619
  const pageSize = Math.max(1, perPage);
4601
4620
  const rows = (await this.get()).all();
4602
4621
  const start = (currentPage - 1) * pageSize;
4603
4622
  return new LengthAwarePaginator(new ArkormCollection(rows.slice(start, start + pageSize)), rows.length, pageSize, currentPage, options);
4604
4623
  }
4605
- const currentPage = Math.max(1, page);
4606
4624
  const pageSize = Math.max(1, perPage);
4607
4625
  const total = await this.count();
4608
4626
  return new LengthAwarePaginator(await this.clone().skip((currentPage - 1) * pageSize).take(pageSize).get(), total, pageSize, currentPage, options);
@@ -4614,9 +4632,9 @@ var QueryBuilder = class QueryBuilder {
4614
4632
  * @param page
4615
4633
  * @returns
4616
4634
  */
4617
- async simplePaginate(perPage = 15, page = 1, options = {}) {
4635
+ async simplePaginate(perPage = 15, page = void 0, options = {}) {
4636
+ const currentPage = this.resolvePaginationPage(page, options);
4618
4637
  if (this.hasRelationFilters() || this.hasRelationAggregates()) {
4619
- const currentPage = Math.max(1, page);
4620
4638
  const pageSize = Math.max(1, perPage);
4621
4639
  const rows = (await this.get()).all();
4622
4640
  const start = (currentPage - 1) * pageSize;
@@ -4624,7 +4642,6 @@ var QueryBuilder = class QueryBuilder {
4624
4642
  const hasMorePages = start + pageSize < rows.length;
4625
4643
  return new Paginator(new ArkormCollection(pageRows), pageSize, currentPage, hasMorePages, options);
4626
4644
  }
4627
- const currentPage = Math.max(1, page);
4628
4645
  const pageSize = Math.max(1, perPage);
4629
4646
  const items = await this.clone().skip((currentPage - 1) * pageSize).take(pageSize + 1).get();
4630
4647
  const hasMorePages = items.all().length > pageSize;
@@ -5452,4 +5469,4 @@ var Model = class Model {
5452
5469
  };
5453
5470
 
5454
5471
  //#endregion
5455
- export { ArkormCollection, ArkormException, Attribute, CliApp, ForeignKeyBuilder, InitCommand, InlineFactory, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateRollbackCommand, Migration, MigrationHistoryCommand, Model, ModelFactory, ModelNotFoundException, ModelsSyncCommand, PRISMA_MODEL_REGEX, Paginator, QueryBuilder, SEEDER_BRAND, SchemaBuilder, SeedCommand, Seeder, TableBuilder, URLDriver, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToPrismaSchema, applyMigrationToPrismaSchema, applyOperationsToPrismaSchema, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createMigrationTimestamp, createPrismaAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationFieldName, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findModelBlock, formatDefaultValue, formatRelationAction, generateMigrationFile, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, removeAppliedMigration, resetArkormRuntimeForTests, resolveCast, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePrismaType, runMigrationWithPrisma, runPrismaCommand, toMigrationFileSlug, toModelName, writeAppliedMigrationsState };
5472
+ export { ArkormCollection, ArkormException, Attribute, CliApp, ForeignKeyBuilder, InitCommand, InlineFactory, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateRollbackCommand, Migration, MigrationHistoryCommand, Model, ModelFactory, ModelNotFoundException, ModelsSyncCommand, PRISMA_MODEL_REGEX, Paginator, QueryBuilder, SEEDER_BRAND, SchemaBuilder, SeedCommand, Seeder, TableBuilder, URLDriver, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToPrismaSchema, applyMigrationToPrismaSchema, applyOperationsToPrismaSchema, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createMigrationTimestamp, createPrismaAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationFieldName, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findModelBlock, formatDefaultValue, formatRelationAction, generateMigrationFile, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getRuntimePaginationCurrentPageResolver, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, removeAppliedMigration, resetArkormRuntimeForTests, resolveCast, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePrismaType, runMigrationWithPrisma, runPrismaCommand, toMigrationFileSlug, toModelName, writeAppliedMigrationsState };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arkormx",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
4
4
  "description": "Modern TypeScript-first ORM for Node.js.",
5
5
  "keywords": [
6
6
  "orm",