arkormx 2.0.0-next.24 → 2.0.0-next.25
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.cjs +31 -14
- package/dist/index.d.cts +10 -3
- package/dist/index.d.mts +10 -3
- package/dist/index.mjs +31 -14
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -7648,8 +7648,8 @@ var QueryBuilder = class QueryBuilder {
|
|
|
7648
7648
|
return affected;
|
|
7649
7649
|
}
|
|
7650
7650
|
/**
|
|
7651
|
-
* Deletes
|
|
7652
|
-
*
|
|
7651
|
+
* Deletes the first record matching the current query constraints and returns
|
|
7652
|
+
* it as a hydrated model instance. Returns null when no record matches.
|
|
7653
7653
|
*
|
|
7654
7654
|
* @returns
|
|
7655
7655
|
*/
|
|
@@ -7663,13 +7663,26 @@ var QueryBuilder = class QueryBuilder {
|
|
|
7663
7663
|
const adapter = this.requireAdapter();
|
|
7664
7664
|
if (!this.isUniqueWhere(where) && directSpec && typeof adapter.deleteFirst === "function") {
|
|
7665
7665
|
const deleted = await adapter.deleteFirst(directSpec);
|
|
7666
|
-
if (!deleted)
|
|
7666
|
+
if (!deleted) return null;
|
|
7667
7667
|
return this.model.hydrate(deleted);
|
|
7668
7668
|
}
|
|
7669
|
-
const uniqueWhere = await this.resolveUniqueWhere(where);
|
|
7670
|
-
|
|
7669
|
+
const uniqueWhere = await this.resolveUniqueWhere(where, false);
|
|
7670
|
+
if (!uniqueWhere) return null;
|
|
7671
|
+
const deleted = await this.executeDeleteRow(uniqueWhere, false);
|
|
7672
|
+
if (!deleted) return null;
|
|
7671
7673
|
return this.model.hydrate(deleted);
|
|
7672
7674
|
}
|
|
7675
|
+
/**
|
|
7676
|
+
* Deletes the first record matching the current query constraints and throws
|
|
7677
|
+
* when no record matches.
|
|
7678
|
+
*
|
|
7679
|
+
* @returns
|
|
7680
|
+
*/
|
|
7681
|
+
async deleteOrFail() {
|
|
7682
|
+
const deleted = await this.delete();
|
|
7683
|
+
if (!deleted) throw new ModelNotFoundException(this.model.name, "Record not found for delete operation.", { operation: "delete" });
|
|
7684
|
+
return deleted;
|
|
7685
|
+
}
|
|
7673
7686
|
tryBuildInsertSpec(values) {
|
|
7674
7687
|
return {
|
|
7675
7688
|
target: this.buildQueryTarget(),
|
|
@@ -8443,7 +8456,7 @@ var QueryBuilder = class QueryBuilder {
|
|
|
8443
8456
|
}
|
|
8444
8457
|
return updated;
|
|
8445
8458
|
}
|
|
8446
|
-
async executeDeleteRow(where) {
|
|
8459
|
+
async executeDeleteRow(where, failIfMissing = true) {
|
|
8447
8460
|
const adapter = this.requireAdapter();
|
|
8448
8461
|
const spec = this.tryBuildDeleteSpec(where);
|
|
8449
8462
|
if (!spec) throw new UnsupportedAdapterFeatureException("Delete could not be compiled into an Arkorm delete specification.", {
|
|
@@ -8451,7 +8464,9 @@ var QueryBuilder = class QueryBuilder {
|
|
|
8451
8464
|
model: this.model.name
|
|
8452
8465
|
});
|
|
8453
8466
|
const deleted = await adapter.delete(spec);
|
|
8454
|
-
if (!deleted)
|
|
8467
|
+
if (!deleted) return failIfMissing ? (() => {
|
|
8468
|
+
throw new ModelNotFoundException(this.model.name, "Record not found for delete operation.", { operation: "delete" });
|
|
8469
|
+
})() : null;
|
|
8455
8470
|
return deleted;
|
|
8456
8471
|
}
|
|
8457
8472
|
/**
|
|
@@ -8480,7 +8495,7 @@ var QueryBuilder = class QueryBuilder {
|
|
|
8480
8495
|
* @param where
|
|
8481
8496
|
* @returns
|
|
8482
8497
|
*/
|
|
8483
|
-
async resolveUniqueWhere(where) {
|
|
8498
|
+
async resolveUniqueWhere(where, failIfMissing = true) {
|
|
8484
8499
|
if (this.isUniqueWhere(where)) return where;
|
|
8485
8500
|
const condition = this.tryBuildQueryCondition(where);
|
|
8486
8501
|
if (!condition) throw new UniqueConstraintResolutionException("Unable to resolve a unique identifier for update/delete operation from the current query shape.", {
|
|
@@ -8494,10 +8509,12 @@ var QueryBuilder = class QueryBuilder {
|
|
|
8494
8509
|
where: condition,
|
|
8495
8510
|
limit: 1
|
|
8496
8511
|
});
|
|
8497
|
-
if (!row)
|
|
8498
|
-
|
|
8499
|
-
|
|
8500
|
-
|
|
8512
|
+
if (!row) return failIfMissing ? (() => {
|
|
8513
|
+
throw new ModelNotFoundException(this.model.name, "Record not found for update/delete operation.", {
|
|
8514
|
+
operation: "resolveUniqueWhere",
|
|
8515
|
+
meta: { where }
|
|
8516
|
+
});
|
|
8517
|
+
})() : null;
|
|
8501
8518
|
const primaryKey = this.model.getPrimaryKey();
|
|
8502
8519
|
if (!Object.prototype.hasOwnProperty.call(row, primaryKey)) throw new UniqueConstraintResolutionException(`Unable to resolve a unique identifier for update/delete operation. Include [${primaryKey}] in the query constraints.`, {
|
|
8503
8520
|
operation: "resolveUniqueWhere",
|
|
@@ -10691,7 +10708,7 @@ var Model = class Model {
|
|
|
10691
10708
|
await Model.dispatchEvent(constructor, "deleted", this);
|
|
10692
10709
|
return this;
|
|
10693
10710
|
}
|
|
10694
|
-
const deleted = await constructor.query().where({ [primaryKey]: identifier }).
|
|
10711
|
+
const deleted = await constructor.query().where({ [primaryKey]: identifier }).deleteOrFail();
|
|
10695
10712
|
this.fill(deleted.getRawAttributes());
|
|
10696
10713
|
this.syncChanges(previousOriginal);
|
|
10697
10714
|
this.syncOriginal();
|
|
@@ -10720,7 +10737,7 @@ var Model = class Model {
|
|
|
10720
10737
|
const previousOriginal = this.getOriginal();
|
|
10721
10738
|
await Model.dispatchEvent(constructor, "forceDeleting", this);
|
|
10722
10739
|
await Model.dispatchEvent(constructor, "deleting", this);
|
|
10723
|
-
const deleted = await constructor.query().withTrashed().where({ [primaryKey]: identifier }).
|
|
10740
|
+
const deleted = await constructor.query().withTrashed().where({ [primaryKey]: identifier }).deleteOrFail();
|
|
10724
10741
|
this.fill(deleted.getRawAttributes());
|
|
10725
10742
|
this.syncChanges(previousOriginal);
|
|
10726
10743
|
this.syncOriginal();
|
package/dist/index.d.cts
CHANGED
|
@@ -2698,12 +2698,19 @@ declare class QueryBuilder<TModel, TDelegate extends PrismaDelegateLike = Prisma
|
|
|
2698
2698
|
*/
|
|
2699
2699
|
upsert(values: Array<Record<string, unknown>>, uniqueBy: string | string[], update?: string[] | null): Promise<number>;
|
|
2700
2700
|
/**
|
|
2701
|
-
* Deletes
|
|
2702
|
-
*
|
|
2701
|
+
* Deletes the first record matching the current query constraints and returns
|
|
2702
|
+
* it as a hydrated model instance. Returns null when no record matches.
|
|
2703
2703
|
*
|
|
2704
2704
|
* @returns
|
|
2705
2705
|
*/
|
|
2706
|
-
delete(): Promise<TModel>;
|
|
2706
|
+
delete(): Promise<TModel | null>;
|
|
2707
|
+
/**
|
|
2708
|
+
* Deletes the first record matching the current query constraints and throws
|
|
2709
|
+
* when no record matches.
|
|
2710
|
+
*
|
|
2711
|
+
* @returns
|
|
2712
|
+
*/
|
|
2713
|
+
deleteOrFail(): Promise<TModel>;
|
|
2707
2714
|
private tryBuildInsertSpec;
|
|
2708
2715
|
private tryBuildInsertManySpec;
|
|
2709
2716
|
private tryBuildUpsertSpec;
|
package/dist/index.d.mts
CHANGED
|
@@ -2698,12 +2698,19 @@ declare class QueryBuilder<TModel, TDelegate extends PrismaDelegateLike = Prisma
|
|
|
2698
2698
|
*/
|
|
2699
2699
|
upsert(values: Array<Record<string, unknown>>, uniqueBy: string | string[], update?: string[] | null): Promise<number>;
|
|
2700
2700
|
/**
|
|
2701
|
-
* Deletes
|
|
2702
|
-
*
|
|
2701
|
+
* Deletes the first record matching the current query constraints and returns
|
|
2702
|
+
* it as a hydrated model instance. Returns null when no record matches.
|
|
2703
2703
|
*
|
|
2704
2704
|
* @returns
|
|
2705
2705
|
*/
|
|
2706
|
-
delete(): Promise<TModel>;
|
|
2706
|
+
delete(): Promise<TModel | null>;
|
|
2707
|
+
/**
|
|
2708
|
+
* Deletes the first record matching the current query constraints and throws
|
|
2709
|
+
* when no record matches.
|
|
2710
|
+
*
|
|
2711
|
+
* @returns
|
|
2712
|
+
*/
|
|
2713
|
+
deleteOrFail(): Promise<TModel>;
|
|
2707
2714
|
private tryBuildInsertSpec;
|
|
2708
2715
|
private tryBuildInsertManySpec;
|
|
2709
2716
|
private tryBuildUpsertSpec;
|
package/dist/index.mjs
CHANGED
|
@@ -7619,8 +7619,8 @@ var QueryBuilder = class QueryBuilder {
|
|
|
7619
7619
|
return affected;
|
|
7620
7620
|
}
|
|
7621
7621
|
/**
|
|
7622
|
-
* Deletes
|
|
7623
|
-
*
|
|
7622
|
+
* Deletes the first record matching the current query constraints and returns
|
|
7623
|
+
* it as a hydrated model instance. Returns null when no record matches.
|
|
7624
7624
|
*
|
|
7625
7625
|
* @returns
|
|
7626
7626
|
*/
|
|
@@ -7634,13 +7634,26 @@ var QueryBuilder = class QueryBuilder {
|
|
|
7634
7634
|
const adapter = this.requireAdapter();
|
|
7635
7635
|
if (!this.isUniqueWhere(where) && directSpec && typeof adapter.deleteFirst === "function") {
|
|
7636
7636
|
const deleted = await adapter.deleteFirst(directSpec);
|
|
7637
|
-
if (!deleted)
|
|
7637
|
+
if (!deleted) return null;
|
|
7638
7638
|
return this.model.hydrate(deleted);
|
|
7639
7639
|
}
|
|
7640
|
-
const uniqueWhere = await this.resolveUniqueWhere(where);
|
|
7641
|
-
|
|
7640
|
+
const uniqueWhere = await this.resolveUniqueWhere(where, false);
|
|
7641
|
+
if (!uniqueWhere) return null;
|
|
7642
|
+
const deleted = await this.executeDeleteRow(uniqueWhere, false);
|
|
7643
|
+
if (!deleted) return null;
|
|
7642
7644
|
return this.model.hydrate(deleted);
|
|
7643
7645
|
}
|
|
7646
|
+
/**
|
|
7647
|
+
* Deletes the first record matching the current query constraints and throws
|
|
7648
|
+
* when no record matches.
|
|
7649
|
+
*
|
|
7650
|
+
* @returns
|
|
7651
|
+
*/
|
|
7652
|
+
async deleteOrFail() {
|
|
7653
|
+
const deleted = await this.delete();
|
|
7654
|
+
if (!deleted) throw new ModelNotFoundException(this.model.name, "Record not found for delete operation.", { operation: "delete" });
|
|
7655
|
+
return deleted;
|
|
7656
|
+
}
|
|
7644
7657
|
tryBuildInsertSpec(values) {
|
|
7645
7658
|
return {
|
|
7646
7659
|
target: this.buildQueryTarget(),
|
|
@@ -8414,7 +8427,7 @@ var QueryBuilder = class QueryBuilder {
|
|
|
8414
8427
|
}
|
|
8415
8428
|
return updated;
|
|
8416
8429
|
}
|
|
8417
|
-
async executeDeleteRow(where) {
|
|
8430
|
+
async executeDeleteRow(where, failIfMissing = true) {
|
|
8418
8431
|
const adapter = this.requireAdapter();
|
|
8419
8432
|
const spec = this.tryBuildDeleteSpec(where);
|
|
8420
8433
|
if (!spec) throw new UnsupportedAdapterFeatureException("Delete could not be compiled into an Arkorm delete specification.", {
|
|
@@ -8422,7 +8435,9 @@ var QueryBuilder = class QueryBuilder {
|
|
|
8422
8435
|
model: this.model.name
|
|
8423
8436
|
});
|
|
8424
8437
|
const deleted = await adapter.delete(spec);
|
|
8425
|
-
if (!deleted)
|
|
8438
|
+
if (!deleted) return failIfMissing ? (() => {
|
|
8439
|
+
throw new ModelNotFoundException(this.model.name, "Record not found for delete operation.", { operation: "delete" });
|
|
8440
|
+
})() : null;
|
|
8426
8441
|
return deleted;
|
|
8427
8442
|
}
|
|
8428
8443
|
/**
|
|
@@ -8451,7 +8466,7 @@ var QueryBuilder = class QueryBuilder {
|
|
|
8451
8466
|
* @param where
|
|
8452
8467
|
* @returns
|
|
8453
8468
|
*/
|
|
8454
|
-
async resolveUniqueWhere(where) {
|
|
8469
|
+
async resolveUniqueWhere(where, failIfMissing = true) {
|
|
8455
8470
|
if (this.isUniqueWhere(where)) return where;
|
|
8456
8471
|
const condition = this.tryBuildQueryCondition(where);
|
|
8457
8472
|
if (!condition) throw new UniqueConstraintResolutionException("Unable to resolve a unique identifier for update/delete operation from the current query shape.", {
|
|
@@ -8465,10 +8480,12 @@ var QueryBuilder = class QueryBuilder {
|
|
|
8465
8480
|
where: condition,
|
|
8466
8481
|
limit: 1
|
|
8467
8482
|
});
|
|
8468
|
-
if (!row)
|
|
8469
|
-
|
|
8470
|
-
|
|
8471
|
-
|
|
8483
|
+
if (!row) return failIfMissing ? (() => {
|
|
8484
|
+
throw new ModelNotFoundException(this.model.name, "Record not found for update/delete operation.", {
|
|
8485
|
+
operation: "resolveUniqueWhere",
|
|
8486
|
+
meta: { where }
|
|
8487
|
+
});
|
|
8488
|
+
})() : null;
|
|
8472
8489
|
const primaryKey = this.model.getPrimaryKey();
|
|
8473
8490
|
if (!Object.prototype.hasOwnProperty.call(row, primaryKey)) throw new UniqueConstraintResolutionException(`Unable to resolve a unique identifier for update/delete operation. Include [${primaryKey}] in the query constraints.`, {
|
|
8474
8491
|
operation: "resolveUniqueWhere",
|
|
@@ -10662,7 +10679,7 @@ var Model = class Model {
|
|
|
10662
10679
|
await Model.dispatchEvent(constructor, "deleted", this);
|
|
10663
10680
|
return this;
|
|
10664
10681
|
}
|
|
10665
|
-
const deleted = await constructor.query().where({ [primaryKey]: identifier }).
|
|
10682
|
+
const deleted = await constructor.query().where({ [primaryKey]: identifier }).deleteOrFail();
|
|
10666
10683
|
this.fill(deleted.getRawAttributes());
|
|
10667
10684
|
this.syncChanges(previousOriginal);
|
|
10668
10685
|
this.syncOriginal();
|
|
@@ -10691,7 +10708,7 @@ var Model = class Model {
|
|
|
10691
10708
|
const previousOriginal = this.getOriginal();
|
|
10692
10709
|
await Model.dispatchEvent(constructor, "forceDeleting", this);
|
|
10693
10710
|
await Model.dispatchEvent(constructor, "deleting", this);
|
|
10694
|
-
const deleted = await constructor.query().withTrashed().where({ [primaryKey]: identifier }).
|
|
10711
|
+
const deleted = await constructor.query().withTrashed().where({ [primaryKey]: identifier }).deleteOrFail();
|
|
10695
10712
|
this.fill(deleted.getRawAttributes());
|
|
10696
10713
|
this.syncChanges(previousOriginal);
|
|
10697
10714
|
this.syncOriginal();
|