arkormx 2.11.3 → 2.11.5

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.
@@ -9,6 +9,7 @@ import { fileURLToPath } from "url";
9
9
  import path from "path";
10
10
  import { existsSync as existsSync$1, mkdirSync as mkdirSync$1, readFileSync as readFileSync$1, rmSync as rmSync$1, writeFileSync as writeFileSync$1 } from "node:fs";
11
11
  import { createHash, randomUUID } from "node:crypto";
12
+ import { AsyncLocalStorage as AsyncLocalStorage$1 } from "node:async_hooks";
12
13
  import { spawnSync } from "node:child_process";
13
14
  import { str } from "@h3ravel/support";
14
15
 
@@ -2467,6 +2468,34 @@ var SchemaBuilder = class SchemaBuilder {
2467
2468
  }
2468
2469
  };
2469
2470
 
2471
+ //#endregion
2472
+ //#region src/helpers/migration-planning.ts
2473
+ /**
2474
+ * Tracks whether a migration body is currently being invoked purely to collect
2475
+ * its schema plan (rather than to actually apply it).
2476
+ *
2477
+ * A migration's `up()`/`down()` is executed both to gather its {@link SchemaOperation}s
2478
+ * and, when it uses helpers like `DB.raw()`, as real database side effects. Some
2479
+ * flows (column-mapping sync, feature validation) re-invoke `up()` on already
2480
+ * applied migrations solely to rebuild metadata — they must NOT re-run those side
2481
+ * effects, or a rollback would replay every still-applied migration's raw SQL
2482
+ * against a schema it was never meant to touch again.
2483
+ *
2484
+ * While this context is active, direct data-affecting `DB` calls become no-ops.
2485
+ * Actual apply/rollback runs outside it, so side effects happen normally.
2486
+ */
2487
+ const STORAGE_KEY = Symbol.for("arkorm.migrationPlanningStorage");
2488
+ const globalScope = globalThis;
2489
+ const migrationPlanningStorage = globalScope[STORAGE_KEY] ?? (globalScope[STORAGE_KEY] = new AsyncLocalStorage$1());
2490
+ /** Runs `fn` in a side-effect-free migration-planning context. */
2491
+ const runInMigrationPlanning = async (fn) => {
2492
+ return await migrationPlanningStorage.run(true, async () => await fn());
2493
+ };
2494
+ /** True when a migration body is being invoked only to collect its schema plan. */
2495
+ const isMigrationPlanningActive = () => {
2496
+ return migrationPlanningStorage.getStore() === true;
2497
+ };
2498
+
2470
2499
  //#endregion
2471
2500
  //#region src/helpers/migrations.ts
2472
2501
  const PRISMA_MODEL_REGEX = /model\s+(\w+)\s*\{[\s\S]*?\n\}/g;
@@ -3151,11 +3180,15 @@ const generateMigrationFile = (name, options = {}) => {
3151
3180
  * @param direction The direction of the migration to plan for ('up' or 'down').
3152
3181
  * @returns A promise that resolves to an array of schema operations that would be performed.
3153
3182
  */
3154
- const getMigrationPlan = async (migration, direction = "up") => {
3183
+ const getMigrationPlan = async (migration, direction = "up", options = {}) => {
3155
3184
  const instance = typeof migration === "function" ? new migration() : migration;
3156
3185
  const schema = new SchemaBuilder();
3157
- if (direction === "up") await instance.up(schema);
3158
- else await instance.down(schema);
3186
+ const invoke = async () => {
3187
+ if (direction === "up") await instance.up(schema);
3188
+ else await instance.down(schema);
3189
+ };
3190
+ if (options.inert) await runInMigrationPlanning(invoke);
3191
+ else await invoke();
3159
3192
  return schema.getOperations();
3160
3193
  };
3161
3194
  const supportsDatabaseMigrationExecution = (adapter) => {
@@ -3563,7 +3596,7 @@ const rebuildPersistedColumnMappingsState = async (state, availableMigrations, f
3563
3596
  className: migration.className
3564
3597
  }
3565
3598
  });
3566
- const operations = await getMigrationPlan(migrationClass, "up");
3599
+ const operations = await getMigrationPlan(migrationClass, "up", { inert: true });
3567
3600
  nextState = applyOperationsToPersistedColumnMappingsState(nextState, operations, features);
3568
3601
  }
3569
3602
  return nextState;
@@ -3580,7 +3613,7 @@ const syncPersistedColumnMappingsFromState = async (cwd, state, availableMigrati
3580
3613
  const validatePersistedMetadataFeaturesForMigrations = async (migrations, features = resolvePersistedMetadataFeatures()) => {
3581
3614
  let nextState = createEmptyPersistedColumnMappingsState();
3582
3615
  for (const [migrationClass] of migrations) {
3583
- const operations = await getMigrationPlan(migrationClass, "up");
3616
+ const operations = await getMigrationPlan(migrationClass, "up", { inert: true });
3584
3617
  nextState = applyOperationsToPersistedColumnMappingsState(nextState, operations, features);
3585
3618
  }
3586
3619
  };
@@ -5387,6 +5420,7 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
5387
5420
  this.pivotColumns = /* @__PURE__ */ new Set();
5388
5421
  this.pivotAccessor = "pivot";
5389
5422
  this.shouldAttachPivot = false;
5423
+ this.pivotValues = /* @__PURE__ */ new Map();
5390
5424
  }
5391
5425
  /**
5392
5426
  * Specifies additional pivot columns to include on the related models.
@@ -5430,6 +5464,22 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
5430
5464
  this.shouldAttachPivot = true;
5431
5465
  return this;
5432
5466
  }
5467
+ withPivotValue(column, value) {
5468
+ if (typeof column === "object" && column !== null) {
5469
+ Object.entries(column).forEach(([name, columnValue]) => {
5470
+ this.applyPivotValue(name, columnValue);
5471
+ });
5472
+ return this;
5473
+ }
5474
+ return this.applyPivotValue(column, value);
5475
+ }
5476
+ applyPivotValue(column, value) {
5477
+ const normalized = column.trim();
5478
+ if (normalized.length === 0) return this;
5479
+ this.wherePivot(normalized, value);
5480
+ this.pivotValues.set(normalized, value);
5481
+ return this;
5482
+ }
5433
5483
  /**
5434
5484
  * Specifies a custom pivot model to use for the pivot records. The pivot model can
5435
5485
  * be used to define custom behavior or methods on the pivot records, as well as to
@@ -5621,6 +5671,7 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
5621
5671
  }
5622
5672
  buildPivotInsertValues(related, attributes = {}) {
5623
5673
  const values = {
5674
+ ...Object.fromEntries(this.pivotValues),
5624
5675
  ...attributes,
5625
5676
  [this.foreignPivotKey]: this.resolveParentPivotValue(),
5626
5677
  [this.relatedPivotKey]: this.resolveRelatedPivotValue(related)
@@ -6510,4 +6561,4 @@ var MorphToRelation = class extends Relation {
6510
6561
  };
6511
6562
 
6512
6563
  //#endregion
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 };
6564
+ export { resetRuntimeRegistryForTests as $, writeAppliedMigrationsState as $n, resolveMigrationClassName as $t, getRuntimePaginationURLDriverFactory as A, raw as An, buildIndexLine as At, getRegisteredMigrations as B, deleteAppliedMigrationsStateFromStore as Bn, deriveRelationAlias as Bt, getActiveTransactionAdapter as C, count as Cn, applyMigrationRollbackToDatabase as Ct, getRuntimeClient as D, json as Dn, applyOperationsToPrismaSchema as Dt, getRuntimeAdapter as E, fromExpressionNode as En, applyMigrationToPrismaSchema as Et, isTransactionCapableClient as F, ForeignKeyBuilder as Fn, buildRelationLine as Ft, loadMigrationsFrom as G, isMigrationApplied as Gn, findModelBlock as Gt, getRegisteredPaths as H, getLastBatchMigrations as Hn, deriveSingularFieldName as Ht, loadArkormConfig as I, buildMigrationIdentity as In, buildUniqueConstraintLine as It, registerFactories as J, readAppliedMigrationsState as Jn, formatRelationAction as Jt, loadModelsFrom as K, markMigrationApplied as Kn, formatDefaultValue as Kt, resetArkormRuntimeForTests as L, buildMigrationRunId as Ln, createMigrationTimestamp as Lt, getUserConfig as M, val as Mn, buildMigrationSource as Mt, isDelegateLike as N, where as Nn, buildModelBlock as Nt, getRuntimeDebugHandler as O, max as On, buildEnumBlock as Ot, isQuerySchemaLike as P, PrimaryKeyGenerationPlanner as Pn, buildPrimaryKeyLine as Pt, registerSeeders as Q, supportsDatabaseMigrationState as Qn, resolveEnumName as Qt, runArkormTransaction as R, computeMigrationChecksum as Rn, deriveCollectionFieldName as Rt, ensureArkormConfigLoading as S, col as Sn, applyDropTableOperation as St, getDefaultStubsPath as T, fn as Tn, applyMigrationToDatabase as Tt, getRegisteredSeeders as U, getLastMigrationRun as Un, escapeRegex as Ut, getRegisteredModels as V, findAppliedMigration as Vn, deriveRelationFieldName as Vt, loadFactoriesFrom as W, getLatestAppliedMigrations as Wn, findEnumBlock as Wt, registerModels as X, removeAppliedMigration as Xn, getMigrationPlan as Xt, registerMigrations as Y, readAppliedMigrationsStateFromStore as Yn, generateMigrationFile as Yt, registerPaths as Z, resolveMigrationStateFilePath as Zn, pad as Zt, bindAdapterToModels as _, Expression as _n, PRISMA_ENUM_MEMBER_REGEX as _t, HasOneThroughRelation as a, supportsDatabaseMigrationExecution as an, RelationResolutionException as ar, getPersistedEnumTsType as at, disposeArkormRuntime as b, caseWhen as bn, applyAlterTableOperation as bt, HasManyRelation as c, toModelName as cn, getPersistedTimestampColumns as ct, BelongsToManyRelation as d, SchemaBuilder as dn, resetPersistedColumnMappingsCache as dt, resolvePrismaType as en, writeAppliedMigrationsStateToStore as er, applyOperationsToPersistedColumnMappingsState as et, Relation as f, EnumBuilder as fn, resolveColumnMappingsFilePath as ft, awaitConfiguredModelsRegistration as g, CaseExpression as gn, writePersistedColumnMappingsState as gt, URLDriver as h, AggregateExpression as hn, validatePersistedMetadataFeaturesForMigrations as ht, MorphManyRelation as i, supportsDatabaseCreation as in, RelationTableLoader as ir, getPersistedEnumMap as it, getRuntimePrismaClient as j, sum as jn, buildInverseRelationLine as jt, getRuntimePaginationCurrentPageResolver as k, min as kn, buildFieldLine as kt, BelongsToRelation as l, isMigrationPlanningActive as ln, readPersistedColumnMappingsState as lt, Paginator as m, resolveGeneratedExpression as mn, syncPersistedColumnMappingsFromState as mt, MorphToManyRelation as n, runPrismaCommand as nn, UnsupportedAdapterFeatureException as nr, deletePersistedColumnMappingsState as nt, HasOneRelation as o, supportsDatabaseReset as on, ArkormCollection as or, getPersistedPrimaryKeyGeneration as ot, LengthAwarePaginator as p, TableBuilder as pn, resolvePersistedMetadataFeatures as pt, loadSeedersFrom as q, markMigrationRun as qn, formatEnumDefaultValue as qt, MorphOneRelation as r, stripPrismaSchemaModelsAndEnums as rn, SetBasedEagerLoader as rr, getPersistedColumnMap as rt, HasManyThroughRelation as s, toMigrationFileSlug as sn, ArkormException as sr, getPersistedTableMetadata as st, MorphToRelation as t, runMigrationWithPrisma as tn, RuntimeModuleLoader as tr, createEmptyPersistedColumnMappingsState as tt, SingleResultRelation as u, runInMigrationPlanning as un, rebuildPersistedColumnMappingsState as ut, configureArkormRuntime as v, JsonExpression as vn, PRISMA_ENUM_REGEX as vt, getActiveTransactionClient as w, expressionBuilder as wn, applyMigrationRollbackToPrismaSchema as wt, emitRuntimeDebugEvent as x, coalesce as xn, applyCreateTableOperation as xt, defineConfig as y, avg as yn, PRISMA_MODEL_REGEX as yt, getRegisteredFactories as z, createEmptyAppliedMigrationsState as zn, deriveInverseRelationAlias as zt };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arkormx",
3
- "version": "2.11.3",
3
+ "version": "2.11.5",
4
4
  "description": "Modern TypeScript-first ORM for Node.js.",
5
5
  "keywords": [
6
6
  "orm",