arkormx 2.12.7 → 2.12.9

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.
@@ -843,7 +843,8 @@ const loadRuntimeConfigSync = () => {
843
843
  for (const configPath of syncConfigPaths) {
844
844
  if (!existsSync$1(configPath)) continue;
845
845
  try {
846
- resolveAndApplyConfig(require(configPath));
846
+ const imported = require(configPath);
847
+ resolveAndApplyConfig(imported);
847
848
  return true;
848
849
  } catch {
849
850
  continue;
@@ -871,7 +872,8 @@ const loadArkormConfig = async () => {
871
872
  for (const configPath of configPaths) {
872
873
  if (!existsSync$1(configPath)) continue;
873
874
  try {
874
- resolveAndApplyConfig(await importConfigFile(configPath));
875
+ const imported = await importConfigFile(configPath);
876
+ resolveAndApplyConfig(imported);
875
877
  await awaitConfiguredModelsRegistration();
876
878
  return;
877
879
  } catch {
@@ -932,6 +934,8 @@ const getRuntimeAdapter = () => {
932
934
  * processes (the CLI) so the Node event loop drains and the process exits
933
935
  * promptly instead of hanging on pool idle timeouts. Teardown failures are
934
936
  * swallowed because the process is shutting down anyway.
937
+ *
938
+ * @returns
935
939
  */
936
940
  const disposeArkormRuntime = async () => {
937
941
  let adapterDisposed = false;
@@ -1386,7 +1390,8 @@ const expressionBuilder = {
1386
1390
  */
1387
1391
  const resolveGeneratedExpression = (expression) => {
1388
1392
  if (typeof expression === "string") return expression;
1389
- return expressionNodeToSql(expression(expressionBuilder).toExpressionNode());
1393
+ const built = expression(expressionBuilder);
1394
+ return expressionNodeToSql(built.toExpressionNode());
1390
1395
  };
1391
1396
  const quoteIdentifier = (name) => name.split(".").map((part) => `"${part.replace(/"/g, "\"\"")}"`).join(".");
1392
1397
  const quoteLiteral = (value) => {
@@ -2874,7 +2879,8 @@ const applyCreateTableOperation = (schema, operation) => {
2874
2879
  if (findModelBlock(schema, operation.table)) throw new ArkormException(`Prisma model for table [${operation.table}] already exists.`);
2875
2880
  const schemaWithEnums = ensureEnumBlocks(schema, operation.columns);
2876
2881
  const block = buildModelBlock(operation);
2877
- return applyInverseRelations(`${schemaWithEnums.trimEnd()}\n\n${block}\n`, toModelName(operation.table), operation.foreignKeys ?? [], operation.columns);
2882
+ const nextSchema = `${schemaWithEnums.trimEnd()}\n\n${block}\n`;
2883
+ return applyInverseRelations(nextSchema, toModelName(operation.table), operation.foreignKeys ?? [], operation.columns);
2878
2884
  };
2879
2885
  /**
2880
2886
  * Apply an alter table operation to a Prisma schema string, modifying the model
@@ -2887,7 +2893,8 @@ const applyCreateTableOperation = (schema, operation) => {
2887
2893
  const applyAlterTableOperation = (schema, operation) => {
2888
2894
  const model = findModelBlock(schema, operation.table);
2889
2895
  if (!model) throw new ArkormException(`Prisma model for table [${operation.table}] was not found.`);
2890
- const schemaWithEnums = ensureEnumBlocks(schema, [...operation.addColumns, ...operation.changeColumns ?? []]);
2896
+ const enumColumns = [...operation.addColumns, ...operation.changeColumns ?? []];
2897
+ const schemaWithEnums = ensureEnumBlocks(schema, enumColumns);
2891
2898
  const refreshedModel = findModelBlock(schemaWithEnums, operation.table);
2892
2899
  if (!refreshedModel) throw new ArkormException(`Prisma model for table [${operation.table}] was not found.`);
2893
2900
  let block = refreshedModel.block;
@@ -2939,7 +2946,8 @@ const applyAlterTableOperation = (schema, operation) => {
2939
2946
  injectLineIntoModelBody(bodyLines, relationLine, (line) => relationRegex.test(line));
2940
2947
  }
2941
2948
  block = bodyLines.join("\n");
2942
- return applyInverseRelations(`${schemaWithEnums.slice(0, refreshedModel.start)}${block}${schemaWithEnums.slice(refreshedModel.end)}`, model.modelName, operation.addForeignKeys ?? [], operation.addColumns);
2949
+ const nextSchema = `${schemaWithEnums.slice(0, refreshedModel.start)}${block}${schemaWithEnums.slice(refreshedModel.end)}`;
2950
+ return applyInverseRelations(nextSchema, model.modelName, operation.addForeignKeys ?? [], operation.addColumns);
2943
2951
  };
2944
2952
  /**
2945
2953
  * Apply a drop table operation to a Prisma schema string, removing the model block
@@ -3194,8 +3202,9 @@ const applyMigrationRollbackToPrismaSchema = async (migration, options = {}) =>
3194
3202
  */
3195
3203
  const runMigrationWithPrisma = async (migration, options = {}) => {
3196
3204
  const cwd = options.cwd ?? process.cwd();
3205
+ const schemaPath = options.schemaPath ?? join(cwd, "prisma", "schema.prisma");
3197
3206
  const applied = await applyMigrationToPrismaSchema(migration, {
3198
- schemaPath: options.schemaPath ?? join(cwd, "prisma", "schema.prisma"),
3207
+ schemaPath,
3199
3208
  write: options.write
3200
3209
  });
3201
3210
  const shouldGenerate = options.runGenerate ?? true;
@@ -3203,12 +3212,15 @@ const runMigrationWithPrisma = async (migration, options = {}) => {
3203
3212
  const mode = options.migrateMode ?? "dev";
3204
3213
  if (shouldGenerate) runPrismaCommand(["generate"], cwd);
3205
3214
  if (shouldMigrate) if (mode === "deploy") runPrismaCommand(["migrate", "deploy"], cwd);
3206
- else runPrismaCommand([
3207
- "migrate",
3208
- "dev",
3209
- "--name",
3210
- options.migrationName ?? `arkorm_${createMigrationTimestamp()}`
3211
- ], cwd);
3215
+ else {
3216
+ const migrationName = options.migrationName ?? `arkorm_${createMigrationTimestamp()}`;
3217
+ runPrismaCommand([
3218
+ "migrate",
3219
+ "dev",
3220
+ "--name",
3221
+ migrationName
3222
+ ], cwd);
3223
+ }
3212
3224
  return {
3213
3225
  schemaPath: applied.schemaPath,
3214
3226
  operations: applied.operations
@@ -3337,7 +3349,8 @@ const readPersistedColumnMappingsState = (filePath) => {
3337
3349
  return empty;
3338
3350
  }
3339
3351
  try {
3340
- const normalized = normalizePersistedColumnMappingsState(JSON.parse(readFileSync(filePath, "utf-8")));
3352
+ const parsed = JSON.parse(readFileSync(filePath, "utf-8"));
3353
+ const normalized = normalizePersistedColumnMappingsState(parsed);
3341
3354
  cachedColumnMappingsPath = filePath;
3342
3355
  cachedColumnMappingsState = normalized;
3343
3356
  return normalized;
@@ -4789,41 +4802,82 @@ var Relation = class {
4789
4802
  };
4790
4803
  return this;
4791
4804
  }
4805
+ where(whereOrColumn, value) {
4806
+ return this.constrain((query) => {
4807
+ if (typeof whereOrColumn === "function") return query.where(whereOrColumn);
4808
+ if (value !== void 0) return query.where(whereOrColumn, value);
4809
+ return query.where(whereOrColumn);
4810
+ });
4811
+ }
4812
+ orWhere(whereOrColumn, value) {
4813
+ return this.constrain((query) => {
4814
+ if (typeof whereOrColumn === "function") return query.orWhere(whereOrColumn);
4815
+ if (value !== void 0) return query.orWhere(whereOrColumn, value);
4816
+ return query.orWhere(whereOrColumn);
4817
+ });
4818
+ }
4792
4819
  /**
4793
- * Add a where clause to the relationship query.
4820
+ * Adds a NOT where clause to the query.
4794
4821
  *
4795
4822
  * @param where
4796
4823
  * @returns
4797
4824
  */
4798
- where(where) {
4799
- return this.constrain((query) => query.where(where));
4825
+ whereNot(where) {
4826
+ return this.constrain((query) => query.whereNot(where));
4800
4827
  }
4801
4828
  /**
4802
- * Adds an OR where clause to the query.
4829
+ * Adds an OR NOT where clause to the query.
4803
4830
  *
4804
4831
  * @param where
4805
4832
  * @returns
4806
4833
  */
4807
- orWhere(where) {
4808
- return this.constrain((query) => query.orWhere(where));
4834
+ orWhereNot(where) {
4835
+ return this.constrain((query) => query.orWhereNot(where));
4809
4836
  }
4810
4837
  /**
4811
- * Adds a NOT where clause to the query.
4838
+ * Apply a callback when the supplied value is truthy.
4812
4839
  *
4813
- * @param where
4840
+ * Keeping this on the relation avoids forcing callers to await `getQuery()`
4841
+ * merely to compose optional constraints.
4842
+ *
4843
+ * @param value
4844
+ * @param callback
4845
+ * @param defaultCallback
4814
4846
  * @returns
4815
4847
  */
4816
- whereNot(where) {
4817
- return this.constrain((query) => query.whereNot(where));
4848
+ when(value, callback, defaultCallback) {
4849
+ const resolved = typeof value === "function" ? value() : value;
4850
+ if (resolved) callback(this, resolved);
4851
+ else defaultCallback?.(this, resolved);
4852
+ return this;
4818
4853
  }
4819
4854
  /**
4820
- * Adds an OR NOT where clause to the query.
4855
+ * Apply a callback when the supplied value is falsy.
4821
4856
  *
4822
- * @param where
4857
+ * @param value
4858
+ * @param callback
4859
+ * @param defaultCallback
4823
4860
  * @returns
4824
4861
  */
4825
- orWhereNot(where) {
4826
- return this.constrain((query) => query.orWhereNot(where));
4862
+ unless(value, callback, defaultCallback) {
4863
+ const resolved = typeof value === "function" ? value() : value;
4864
+ if (!resolved) callback(this, resolved);
4865
+ else defaultCallback?.(this, resolved);
4866
+ return this;
4867
+ }
4868
+ /**
4869
+ * Pass the relation through a callback and preserve the chain.
4870
+ *
4871
+ * @param callback
4872
+ * @returns
4873
+ */
4874
+ tap(callback) {
4875
+ callback(this);
4876
+ return this;
4877
+ }
4878
+ /** Pass the relation into a callback and return its result. */
4879
+ pipe(callback) {
4880
+ return callback(this);
4827
4881
  }
4828
4882
  /**
4829
4883
  * Adds a null check for a key.
@@ -4844,6 +4898,24 @@ var Relation = class {
4844
4898
  return this.constrain((query) => query.whereNotNull(key));
4845
4899
  }
4846
4900
  /**
4901
+ * Adds an OR null check for a key.
4902
+ *
4903
+ * @param key
4904
+ * @returns
4905
+ */
4906
+ orWhereNull(key) {
4907
+ return this.constrain((query) => query.orWhereNull(key));
4908
+ }
4909
+ /**
4910
+ * Adds an OR not-null check for a key.
4911
+ *
4912
+ * @param key
4913
+ * @returns
4914
+ */
4915
+ orWhereNotNull(key) {
4916
+ return this.constrain((query) => query.orWhereNotNull(key));
4917
+ }
4918
+ /**
4847
4919
  * Adds a between range clause for a key.
4848
4920
  *
4849
4921
  * @param key
@@ -5293,6 +5365,140 @@ var Relation = class {
5293
5365
  return this.constrain((query) => query.with(relations));
5294
5366
  }
5295
5367
  /**
5368
+ * Add a relationship count/existence constraint to the related query.
5369
+ *
5370
+ * @param relation
5371
+ * @param operator
5372
+ * @param count
5373
+ * @param callback
5374
+ * @returns
5375
+ */
5376
+ has(relation, operator = ">=", count = 1, callback) {
5377
+ return this.constrain((query) => query.has(relation, operator, count, callback));
5378
+ }
5379
+ /**
5380
+ * Add an OR relationship count/existence constraint to the related query.
5381
+ *
5382
+ * @param relation
5383
+ * @param operator
5384
+ * @param count
5385
+ * @returns
5386
+ */
5387
+ orHas(relation, operator = ">=", count = 1) {
5388
+ return this.constrain((query) => query.orHas(relation, operator, count));
5389
+ }
5390
+ /**
5391
+ * Require the related query's model to have a nested relationship.
5392
+ *
5393
+ * @param relation
5394
+ * @param callback
5395
+ * @param operator
5396
+ * @param count
5397
+ * @returns
5398
+ */
5399
+ whereHas(relation, callback, operator = ">=", count = 1) {
5400
+ return this.constrain((query) => query.whereHas(relation, callback, operator, count));
5401
+ }
5402
+ /**
5403
+ * Add an OR nested relationship constraint to the related query.
5404
+ *
5405
+ * @param relation
5406
+ * @param callback
5407
+ * @param operator
5408
+ * @param count
5409
+ * @returns
5410
+ */
5411
+ orWhereHas(relation, callback, operator = ">=", count = 1) {
5412
+ return this.constrain((query) => query.orWhereHas(relation, callback, operator, count));
5413
+ }
5414
+ /**
5415
+ * Require the related query's model not to have a nested relationship.
5416
+ *
5417
+ * @param relation
5418
+ * @param callback
5419
+ * @returns
5420
+ */
5421
+ doesntHave(relation, callback) {
5422
+ return this.constrain((query) => query.doesntHave(relation, callback));
5423
+ }
5424
+ /**
5425
+ * Add an OR nested relationship absence constraint.
5426
+ *
5427
+ * @param relation
5428
+ * @returns
5429
+ */
5430
+ orDoesntHave(relation) {
5431
+ return this.constrain((query) => query.orDoesntHave(relation));
5432
+ }
5433
+ /**
5434
+ * Require a constrained nested relationship to be absent.
5435
+ *
5436
+ * @param relation
5437
+ * @param callback
5438
+ * @returns
5439
+ */
5440
+ whereDoesntHave(relation, callback) {
5441
+ return this.constrain((query) => query.whereDoesntHave(relation, callback));
5442
+ }
5443
+ /**
5444
+ * Add an OR constrained nested relationship absence clause.
5445
+ *
5446
+ * @param relation
5447
+ * @param callback
5448
+ * @returns
5449
+ */
5450
+ orWhereDoesntHave(relation, callback) {
5451
+ return this.constrain((query) => query.orWhereDoesntHave(relation, callback));
5452
+ }
5453
+ /**
5454
+ * Add a constrained polymorphic nested relationship clause.
5455
+ *
5456
+ * @param relation
5457
+ * @param types
5458
+ * @param callback
5459
+ * @param operator
5460
+ * @param count
5461
+ * @returns
5462
+ */
5463
+ whereHasMorph(relation, types, callback, operator = ">=", count = 1) {
5464
+ return this.constrain((query) => query.whereHasMorph(relation, types, callback, operator, count));
5465
+ }
5466
+ /**
5467
+ * Add an OR constrained polymorphic nested relationship clause.
5468
+ *
5469
+ * @param relation
5470
+ * @param types
5471
+ * @param callback
5472
+ * @param operator
5473
+ * @param count
5474
+ * @returns
5475
+ */
5476
+ orWhereHasMorph(relation, types, callback, operator = ">=", count = 1) {
5477
+ return this.constrain((query) => query.orWhereHasMorph(relation, types, callback, operator, count));
5478
+ }
5479
+ /**
5480
+ * Require a constrained polymorphic nested relationship to be absent.
5481
+ *
5482
+ * @param relation
5483
+ * @param types
5484
+ * @param callback
5485
+ * @returns
5486
+ */
5487
+ whereDoesntHaveMorph(relation, types, callback) {
5488
+ return this.constrain((query) => query.whereDoesntHaveMorph(relation, types, callback));
5489
+ }
5490
+ /**
5491
+ * Add an OR polymorphic nested relationship absence clause.
5492
+ *
5493
+ * @param relation
5494
+ * @param types
5495
+ * @param callback
5496
+ * @returns
5497
+ */
5498
+ orWhereDoesntHaveMorph(relation, types, callback) {
5499
+ return this.constrain((query) => query.orWhereDoesntHaveMorph(relation, types, callback));
5500
+ }
5501
+ /**
5296
5502
  * Add relationship count aggregates to the related-model query.
5297
5503
  *
5298
5504
  * @param relations
@@ -6327,11 +6533,13 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
6327
6533
  });
6328
6534
  decorated.paginate = (async (perPage = 15, page, options = {}) => {
6329
6535
  const paginator = await originalPaginate(perPage, page, options);
6330
- return new LengthAwarePaginator(this.attachPivotToResults(paginator.data, pivotRows), paginator.meta.total, paginator.meta.perPage, paginator.meta.currentPage, options);
6536
+ const data = this.attachPivotToResults(paginator.data, pivotRows);
6537
+ return new LengthAwarePaginator(data, paginator.meta.total, paginator.meta.perPage, paginator.meta.currentPage, options);
6331
6538
  });
6332
6539
  decorated.simplePaginate = (async (perPage = 15, page, options = {}) => {
6333
6540
  const paginator = await originalSimplePaginate(perPage, page, options);
6334
- return new Paginator(this.attachPivotToResults(paginator.data, pivotRows), paginator.meta.perPage, paginator.meta.currentPage, paginator.meta.hasMorePages, options);
6541
+ const data = this.attachPivotToResults(paginator.data, pivotRows);
6542
+ return new Paginator(data, paginator.meta.perPage, paginator.meta.currentPage, paginator.meta.hasMorePages, options);
6335
6543
  });
6336
6544
  decorated.clone = (() => {
6337
6545
  return this.decorateQueryBuilder(originalClone(), pivotRows);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arkormx",
3
- "version": "2.12.7",
3
+ "version": "2.12.9",
4
4
  "description": "Modern TypeScript-first ORM for Node.js.",
5
5
  "keywords": [
6
6
  "orm",
@@ -66,7 +66,7 @@
66
66
  "eslint": "^10.3.0",
67
67
  "prisma": "^7.6.0",
68
68
  "reflect-metadata": "^0.2.2",
69
- "tsdown": "^0.22.0",
69
+ "tsdown": "^0.22.2",
70
70
  "typescript": "^6.0.0",
71
71
  "typescript-eslint": "^8.59.2",
72
72
  "unplugin-swc": "^1.5.9",
@@ -78,13 +78,13 @@
78
78
  "vitest": "^4.1.8"
79
79
  },
80
80
  "engines": {
81
- "node": ">=20.0.0"
81
+ "node": ">=22.0.0"
82
82
  },
83
83
  "dependencies": {
84
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",
85
+ "@h3ravel/musket": "^2.2.13",
86
+ "@h3ravel/shared": "^2.2.7",
87
+ "@h3ravel/support": "^2.2.7",
88
88
  "dotenv": "^17.3.1",
89
89
  "jiti": "^2.7.0",
90
90
  "kysely": "^0.28.15",