arkormx 2.11.0 → 2.11.2

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.
@@ -1008,6 +1008,49 @@ const getLatestAppliedMigrations = (state, steps) => {
1008
1008
  return right.index - left.index;
1009
1009
  }).slice(0, Math.max(0, steps)).map((entry) => entry.migration);
1010
1010
  };
1011
+ /**
1012
+ * Groups the applied migrations into batches, oldest batch first, each batch
1013
+ * holding its migration ids in application order.
1014
+ *
1015
+ * A "batch" is one `migrate` run. When no runs were recorded (e.g. legacy state
1016
+ * written before run tracking), each applied migration is treated as its own
1017
+ * batch so `--step` still behaves predictably.
1018
+ *
1019
+ * @param state
1020
+ * @returns
1021
+ */
1022
+ const resolveAppliedBatches = (state) => {
1023
+ const runs = state.runs ?? [];
1024
+ if (runs.length > 0) return runs.map((run, index) => ({
1025
+ run,
1026
+ index
1027
+ })).sort((left, right) => {
1028
+ const appliedAtOrder = left.run.appliedAt.localeCompare(right.run.appliedAt);
1029
+ if (appliedAtOrder !== 0) return appliedAtOrder;
1030
+ return left.index - right.index;
1031
+ }).map((entry) => entry.run.migrationIds);
1032
+ return state.migrations.map((migration) => [migration.id]);
1033
+ };
1034
+ /**
1035
+ * Resolves the migrations belonging to the most recent `batches` batches, ordered
1036
+ * for rollback — **reverse of the order they were applied** (most recent batch
1037
+ * first, and within each batch the migration that ran `up()` last runs `down()`
1038
+ * first), so a rollback exactly reverses how the migrations were applied.
1039
+ *
1040
+ * Defaults to a single batch (`migrate:rollback` with no `--step`); `--step=N`
1041
+ * rolls back the last N batches.
1042
+ *
1043
+ * @param state
1044
+ * @param batches
1045
+ * @returns
1046
+ */
1047
+ const getLastBatchMigrations = (state, batches = 1) => {
1048
+ if (batches < 1) return [];
1049
+ const allBatches = resolveAppliedBatches(state);
1050
+ const selected = allBatches.slice(Math.max(0, allBatches.length - batches));
1051
+ const byId = new Map(state.migrations.map((migration) => [migration.id, migration]));
1052
+ return selected.reverse().flatMap((migrationIds) => [...migrationIds].reverse()).map((id) => byId.get(id)).filter((migration) => Boolean(migration));
1053
+ };
1011
1054
 
1012
1055
  //#endregion
1013
1056
  //#region src/database/ForeignKeyBuilder.ts
@@ -4064,6 +4107,29 @@ const getRuntimeAdapter = () => {
4064
4107
  if (!runtimeConfigLoaded) loadRuntimeConfigSync();
4065
4108
  return runtimeAdapter;
4066
4109
  };
4110
+ /**
4111
+ * Releases the database resources held by the configured runtime — the adapter's
4112
+ * connection pool and/or the configured client. Intended for short-lived
4113
+ * processes (the CLI) so the Node event loop drains and the process exits
4114
+ * promptly instead of hanging on pool idle timeouts. Teardown failures are
4115
+ * swallowed because the process is shutting down anyway.
4116
+ */
4117
+ const disposeArkormRuntime = async () => {
4118
+ let adapterDisposed = false;
4119
+ try {
4120
+ if (runtimeAdapter && typeof runtimeAdapter.dispose === "function") {
4121
+ await runtimeAdapter.dispose();
4122
+ adapterDisposed = true;
4123
+ }
4124
+ } catch {}
4125
+ const client = getRuntimeClient();
4126
+ if (!client) return;
4127
+ try {
4128
+ if (typeof client.$disconnect === "function") await client.$disconnect();
4129
+ else if (!adapterDisposed && typeof client.destroy === "function") await client.destroy();
4130
+ else if (!adapterDisposed && typeof client.end === "function") await client.end();
4131
+ } catch {}
4132
+ };
4067
4133
  const getActiveTransactionClient = () => {
4068
4134
  return transactionClientStorage.getStore();
4069
4135
  };
@@ -6444,4 +6510,4 @@ var MorphToRelation = class extends Relation {
6444
6510
  };
6445
6511
 
6446
6512
  //#endregion
6447
- export { applyOperationsToPersistedColumnMappingsState as $, SetBasedEagerLoader as $n, resolvePrismaType as $t, getRuntimePrismaClient as A, where as An, buildInverseRelationLine as At, getRegisteredModels as B, getLatestAppliedMigrations as Bn, deriveRelationFieldName as Bt, getActiveTransactionClient as C, fromExpressionNode as Cn, applyMigrationRollbackToPrismaSchema as Ct, getRuntimeDebugHandler as D, raw as Dn, buildEnumBlock as Dt, getRuntimeClient as E, min as En, applyOperationsToPrismaSchema as Et, loadArkormConfig as F, computeMigrationChecksum as Fn, buildUniqueConstraintLine as Ft, loadModelsFrom as G, readAppliedMigrationsStateFromStore as Gn, formatDefaultValue as Gt, getRegisteredSeeders as H, markMigrationApplied as Hn, escapeRegex as Ht, resetArkormRuntimeForTests as I, createEmptyAppliedMigrationsState as In, createMigrationTimestamp as It, registerMigrations as J, supportsDatabaseMigrationState as Jn, generateMigrationFile as Jt, loadSeedersFrom as K, removeAppliedMigration as Kn, formatEnumDefaultValue as Kt, runArkormTransaction as L, deleteAppliedMigrationsStateFromStore as Ln, deriveCollectionFieldName as Lt, isDelegateLike as M, ForeignKeyBuilder as Mn, buildModelBlock as Mt, isQuerySchemaLike as N, buildMigrationIdentity as Nn, buildPrimaryKeyLine as Nt, getRuntimePaginationCurrentPageResolver as O, sum as On, buildFieldLine as Ot, isTransactionCapableClient as P, buildMigrationRunId as Pn, buildRelationLine as Pt, resetRuntimeRegistryForTests as Q, UnsupportedAdapterFeatureException as Qn, resolveMigrationClassName as Qt, getRegisteredFactories as R, findAppliedMigration as Rn, deriveInverseRelationAlias as Rt, getActiveTransactionAdapter as S, fn as Sn, applyMigrationRollbackToDatabase as St, getRuntimeAdapter as T, max as Tn, applyMigrationToPrismaSchema as Tt, loadFactoriesFrom as U, markMigrationRun as Un, findEnumBlock as Ut, getRegisteredPaths as V, isMigrationApplied as Vn, deriveSingularFieldName as Vt, loadMigrationsFrom as W, readAppliedMigrationsState as Wn, findModelBlock as Wt, registerPaths as X, writeAppliedMigrationsStateToStore as Xn, pad as Xt, registerModels as Y, writeAppliedMigrationsState as Yn, getMigrationPlan as Yt, registerSeeders as Z, RuntimeModuleLoader as Zn, resolveEnumName as Zt, bindAdapterToModels as _, caseWhen as _n, PRISMA_ENUM_REGEX as _t, HasOneThroughRelation as a, supportsDatabaseReset as an, getPersistedPrimaryKeyGeneration as at, emitRuntimeDebugEvent as b, count as bn, applyCreateTableOperation as bt, HasManyRelation as c, SchemaBuilder as cn, readPersistedColumnMappingsState as ct, BelongsToManyRelation as d, resolveGeneratedExpression as dn, resolveColumnMappingsFilePath as dt, runMigrationWithPrisma as en, RelationTableLoader as er, createEmptyPersistedColumnMappingsState as et, Relation as f, AggregateExpression as fn, resolvePersistedMetadataFeatures as ft, awaitConfiguredModelsRegistration as g, avg as gn, PRISMA_ENUM_MEMBER_REGEX as gt, URLDriver as h, JsonExpression as hn, writePersistedColumnMappingsState as ht, MorphManyRelation as i, supportsDatabaseMigrationExecution as in, getPersistedEnumTsType as it, getUserConfig as j, PrimaryKeyGenerationPlanner as jn, buildMigrationSource as jt, getRuntimePaginationURLDriverFactory as k, val as kn, buildIndexLine as kt, BelongsToRelation as l, EnumBuilder as ln, rebuildPersistedColumnMappingsState as lt, Paginator as m, Expression as mn, validatePersistedMetadataFeaturesForMigrations as mt, MorphToManyRelation as n, stripPrismaSchemaModelsAndEnums as nn, ArkormCollection as nr, getPersistedColumnMap as nt, HasOneRelation as o, toMigrationFileSlug as on, getPersistedTableMetadata as ot, LengthAwarePaginator as p, CaseExpression as pn, syncPersistedColumnMappingsFromState as pt, registerFactories as q, resolveMigrationStateFilePath as qn, formatRelationAction as qt, MorphOneRelation as r, supportsDatabaseCreation as rn, ArkormException as rr, getPersistedEnumMap as rt, HasManyThroughRelation as s, toModelName as sn, getPersistedTimestampColumns as st, MorphToRelation as t, runPrismaCommand as tn, RelationResolutionException as tr, deletePersistedColumnMappingsState as tt, SingleResultRelation as u, TableBuilder as un, resetPersistedColumnMappingsCache as ut, configureArkormRuntime as v, coalesce as vn, PRISMA_MODEL_REGEX as vt, getDefaultStubsPath as w, json as wn, applyMigrationToDatabase as wt, ensureArkormConfigLoading as x, expressionBuilder as xn, applyDropTableOperation as xt, defineConfig as y, col as yn, applyAlterTableOperation as yt, getRegisteredMigrations as z, getLastMigrationRun as zn, deriveRelationAlias as zt };
6513
+ export { resetRuntimeRegistryForTests as $, RuntimeModuleLoader as $n, resolveMigrationClassName as $t, getRuntimePaginationURLDriverFactory as A, val as An, buildIndexLine as At, getRegisteredMigrations as B, getLastBatchMigrations as Bn, deriveRelationAlias as Bt, getActiveTransactionAdapter as C, fn as Cn, applyMigrationRollbackToDatabase as Ct, getRuntimeClient as D, min as Dn, applyOperationsToPrismaSchema as Dt, getRuntimeAdapter as E, max as En, applyMigrationToPrismaSchema as Et, isTransactionCapableClient as F, buildMigrationRunId as Fn, buildRelationLine as Ft, loadMigrationsFrom as G, markMigrationRun as Gn, findModelBlock as Gt, getRegisteredPaths as H, getLatestAppliedMigrations as Hn, deriveSingularFieldName as Ht, loadArkormConfig as I, computeMigrationChecksum as In, buildUniqueConstraintLine as It, registerFactories as J, removeAppliedMigration as Jn, formatRelationAction as Jt, loadModelsFrom as K, readAppliedMigrationsState as Kn, formatDefaultValue as Kt, resetArkormRuntimeForTests as L, createEmptyAppliedMigrationsState as Ln, createMigrationTimestamp as Lt, getUserConfig as M, PrimaryKeyGenerationPlanner as Mn, buildMigrationSource as Mt, isDelegateLike as N, ForeignKeyBuilder as Nn, buildModelBlock as Nt, getRuntimeDebugHandler as O, raw as On, buildEnumBlock as Ot, isQuerySchemaLike as P, buildMigrationIdentity as Pn, buildPrimaryKeyLine as Pt, registerSeeders as Q, writeAppliedMigrationsStateToStore as Qn, resolveEnumName as Qt, runArkormTransaction as R, deleteAppliedMigrationsStateFromStore as Rn, deriveCollectionFieldName as Rt, ensureArkormConfigLoading as S, expressionBuilder as Sn, applyDropTableOperation as St, getDefaultStubsPath as T, json as Tn, applyMigrationToDatabase as Tt, getRegisteredSeeders as U, isMigrationApplied as Un, escapeRegex as Ut, getRegisteredModels as V, getLastMigrationRun as Vn, deriveRelationFieldName as Vt, loadFactoriesFrom as W, markMigrationApplied as Wn, findEnumBlock as Wt, registerModels as X, supportsDatabaseMigrationState as Xn, getMigrationPlan as Xt, registerMigrations as Y, resolveMigrationStateFilePath as Yn, generateMigrationFile as Yt, registerPaths as Z, writeAppliedMigrationsState as Zn, pad as Zt, bindAdapterToModels as _, avg as _n, PRISMA_ENUM_MEMBER_REGEX as _t, HasOneThroughRelation as a, supportsDatabaseMigrationExecution as an, ArkormException as ar, getPersistedEnumTsType as at, disposeArkormRuntime as b, col as bn, applyAlterTableOperation as bt, HasManyRelation as c, toModelName as cn, getPersistedTimestampColumns as ct, BelongsToManyRelation as d, TableBuilder as dn, resetPersistedColumnMappingsCache as dt, resolvePrismaType as en, UnsupportedAdapterFeatureException as er, applyOperationsToPersistedColumnMappingsState as et, Relation as f, resolveGeneratedExpression as fn, resolveColumnMappingsFilePath as ft, awaitConfiguredModelsRegistration as g, JsonExpression as gn, writePersistedColumnMappingsState as gt, URLDriver as h, Expression as hn, validatePersistedMetadataFeaturesForMigrations as ht, MorphManyRelation as i, supportsDatabaseCreation as in, ArkormCollection as ir, getPersistedEnumMap as it, getRuntimePrismaClient as j, where as jn, buildInverseRelationLine as jt, getRuntimePaginationCurrentPageResolver as k, sum as kn, buildFieldLine as kt, BelongsToRelation as l, SchemaBuilder as ln, readPersistedColumnMappingsState as lt, Paginator as m, CaseExpression as mn, syncPersistedColumnMappingsFromState as mt, MorphToManyRelation as n, runPrismaCommand as nn, RelationTableLoader as nr, deletePersistedColumnMappingsState as nt, HasOneRelation as o, supportsDatabaseReset as on, getPersistedPrimaryKeyGeneration as ot, LengthAwarePaginator as p, AggregateExpression as pn, resolvePersistedMetadataFeatures as pt, loadSeedersFrom as q, readAppliedMigrationsStateFromStore as qn, formatEnumDefaultValue as qt, MorphOneRelation as r, stripPrismaSchemaModelsAndEnums as rn, RelationResolutionException as rr, getPersistedColumnMap as rt, HasManyThroughRelation as s, toMigrationFileSlug as sn, getPersistedTableMetadata as st, MorphToRelation as t, runMigrationWithPrisma as tn, SetBasedEagerLoader as tr, createEmptyPersistedColumnMappingsState as tt, SingleResultRelation as u, EnumBuilder as un, rebuildPersistedColumnMappingsState as ut, configureArkormRuntime as v, caseWhen as vn, PRISMA_ENUM_REGEX as vt, getActiveTransactionClient as w, fromExpressionNode as wn, applyMigrationRollbackToPrismaSchema as wt, emitRuntimeDebugEvent as x, count as xn, applyCreateTableOperation as xt, defineConfig as y, coalesce as yn, PRISMA_MODEL_REGEX as yt, getRegisteredFactories as z, findAppliedMigration as zn, deriveInverseRelationAlias as zt };
@@ -1036,6 +1036,49 @@ const getLatestAppliedMigrations = (state, steps) => {
1036
1036
  return right.index - left.index;
1037
1037
  }).slice(0, Math.max(0, steps)).map((entry) => entry.migration);
1038
1038
  };
1039
+ /**
1040
+ * Groups the applied migrations into batches, oldest batch first, each batch
1041
+ * holding its migration ids in application order.
1042
+ *
1043
+ * A "batch" is one `migrate` run. When no runs were recorded (e.g. legacy state
1044
+ * written before run tracking), each applied migration is treated as its own
1045
+ * batch so `--step` still behaves predictably.
1046
+ *
1047
+ * @param state
1048
+ * @returns
1049
+ */
1050
+ const resolveAppliedBatches = (state) => {
1051
+ const runs = state.runs ?? [];
1052
+ if (runs.length > 0) return runs.map((run, index) => ({
1053
+ run,
1054
+ index
1055
+ })).sort((left, right) => {
1056
+ const appliedAtOrder = left.run.appliedAt.localeCompare(right.run.appliedAt);
1057
+ if (appliedAtOrder !== 0) return appliedAtOrder;
1058
+ return left.index - right.index;
1059
+ }).map((entry) => entry.run.migrationIds);
1060
+ return state.migrations.map((migration) => [migration.id]);
1061
+ };
1062
+ /**
1063
+ * Resolves the migrations belonging to the most recent `batches` batches, ordered
1064
+ * for rollback — **reverse of the order they were applied** (most recent batch
1065
+ * first, and within each batch the migration that ran `up()` last runs `down()`
1066
+ * first), so a rollback exactly reverses how the migrations were applied.
1067
+ *
1068
+ * Defaults to a single batch (`migrate:rollback` with no `--step`); `--step=N`
1069
+ * rolls back the last N batches.
1070
+ *
1071
+ * @param state
1072
+ * @param batches
1073
+ * @returns
1074
+ */
1075
+ const getLastBatchMigrations = (state, batches = 1) => {
1076
+ if (batches < 1) return [];
1077
+ const allBatches = resolveAppliedBatches(state);
1078
+ const selected = allBatches.slice(Math.max(0, allBatches.length - batches));
1079
+ const byId = new Map(state.migrations.map((migration) => [migration.id, migration]));
1080
+ return selected.reverse().flatMap((migrationIds) => [...migrationIds].reverse()).map((id) => byId.get(id)).filter((migration) => Boolean(migration));
1081
+ };
1039
1082
 
1040
1083
  //#endregion
1041
1084
  //#region src/database/ForeignKeyBuilder.ts
@@ -4092,6 +4135,29 @@ const getRuntimeAdapter = () => {
4092
4135
  if (!runtimeConfigLoaded) loadRuntimeConfigSync();
4093
4136
  return runtimeAdapter;
4094
4137
  };
4138
+ /**
4139
+ * Releases the database resources held by the configured runtime — the adapter's
4140
+ * connection pool and/or the configured client. Intended for short-lived
4141
+ * processes (the CLI) so the Node event loop drains and the process exits
4142
+ * promptly instead of hanging on pool idle timeouts. Teardown failures are
4143
+ * swallowed because the process is shutting down anyway.
4144
+ */
4145
+ const disposeArkormRuntime = async () => {
4146
+ let adapterDisposed = false;
4147
+ try {
4148
+ if (runtimeAdapter && typeof runtimeAdapter.dispose === "function") {
4149
+ await runtimeAdapter.dispose();
4150
+ adapterDisposed = true;
4151
+ }
4152
+ } catch {}
4153
+ const client = getRuntimeClient();
4154
+ if (!client) return;
4155
+ try {
4156
+ if (typeof client.$disconnect === "function") await client.$disconnect();
4157
+ else if (!adapterDisposed && typeof client.destroy === "function") await client.destroy();
4158
+ else if (!adapterDisposed && typeof client.end === "function") await client.end();
4159
+ } catch {}
4160
+ };
4095
4161
  const getActiveTransactionClient = () => {
4096
4162
  return transactionClientStorage.getStore();
4097
4163
  };
@@ -6922,6 +6988,12 @@ Object.defineProperty(exports, 'deriveSingularFieldName', {
6922
6988
  return deriveSingularFieldName;
6923
6989
  }
6924
6990
  });
6991
+ Object.defineProperty(exports, 'disposeArkormRuntime', {
6992
+ enumerable: true,
6993
+ get: function () {
6994
+ return disposeArkormRuntime;
6995
+ }
6996
+ });
6925
6997
  Object.defineProperty(exports, 'emitRuntimeDebugEvent', {
6926
6998
  enumerable: true,
6927
6999
  get: function () {
@@ -7018,6 +7090,12 @@ Object.defineProperty(exports, 'getDefaultStubsPath', {
7018
7090
  return getDefaultStubsPath;
7019
7091
  }
7020
7092
  });
7093
+ Object.defineProperty(exports, 'getLastBatchMigrations', {
7094
+ enumerable: true,
7095
+ get: function () {
7096
+ return getLastBatchMigrations;
7097
+ }
7098
+ });
7021
7099
  Object.defineProperty(exports, 'getLastMigrationRun', {
7022
7100
  enumerable: true,
7023
7101
  get: function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arkormx",
3
- "version": "2.11.0",
3
+ "version": "2.11.2",
4
4
  "description": "Modern TypeScript-first ORM for Node.js.",
5
5
  "keywords": [
6
6
  "orm",
@@ -81,10 +81,10 @@
81
81
  "node": ">=20.0.0"
82
82
  },
83
83
  "dependencies": {
84
- "@h3ravel/collect.js": "^5.3.7",
85
- "@h3ravel/musket": "^2.0.0",
86
- "@h3ravel/shared": "^2.1.4",
87
- "@h3ravel/support": "^2.1.4",
84
+ "@h3ravel/collect.js": "^5.4.0",
85
+ "@h3ravel/musket": "^2.2.2",
86
+ "@h3ravel/shared": "^2.2.1",
87
+ "@h3ravel/support": "^2.2.1",
88
88
  "dotenv": "^17.3.1",
89
89
  "jiti": "^2.7.0",
90
90
  "kysely": "^0.28.15",