arkormx 2.0.0-next.20 → 2.0.0-next.21
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 +272 -1
- package/dist/index.d.cts +87 -12
- package/dist/index.d.mts +87 -12
- package/dist/index.mjs +272 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -9154,6 +9154,277 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
9154
9154
|
conditions: [baseCondition, this.pivotWhere]
|
|
9155
9155
|
};
|
|
9156
9156
|
}
|
|
9157
|
+
buildPivotTarget() {
|
|
9158
|
+
return {
|
|
9159
|
+
table: this.throughDelegate,
|
|
9160
|
+
primaryKey: this.relatedPivotKey
|
|
9161
|
+
};
|
|
9162
|
+
}
|
|
9163
|
+
buildRelatedPivotCondition(relatedValues) {
|
|
9164
|
+
const normalizedValues = relatedValues.filter((value) => value != null);
|
|
9165
|
+
if (normalizedValues.length === 0) return null;
|
|
9166
|
+
if (normalizedValues.length === 1) return {
|
|
9167
|
+
type: "comparison",
|
|
9168
|
+
column: this.relatedPivotKey,
|
|
9169
|
+
operator: "=",
|
|
9170
|
+
value: normalizedValues[0]
|
|
9171
|
+
};
|
|
9172
|
+
return {
|
|
9173
|
+
type: "comparison",
|
|
9174
|
+
column: this.relatedPivotKey,
|
|
9175
|
+
operator: "in",
|
|
9176
|
+
value: normalizedValues
|
|
9177
|
+
};
|
|
9178
|
+
}
|
|
9179
|
+
buildPivotMutationWhere(relatedValues = []) {
|
|
9180
|
+
const baseCondition = this.buildPivotWhere(this.resolveParentPivotValue());
|
|
9181
|
+
const relatedCondition = this.buildRelatedPivotCondition(relatedValues);
|
|
9182
|
+
if (!relatedCondition) return baseCondition;
|
|
9183
|
+
return {
|
|
9184
|
+
type: "group",
|
|
9185
|
+
operator: "and",
|
|
9186
|
+
conditions: [baseCondition, relatedCondition]
|
|
9187
|
+
};
|
|
9188
|
+
}
|
|
9189
|
+
normalizeIdentifierValue(value) {
|
|
9190
|
+
if (typeof value === "string" && /^-?\d+$/.test(value)) return Number(value);
|
|
9191
|
+
return value;
|
|
9192
|
+
}
|
|
9193
|
+
isPlainObject(value) {
|
|
9194
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && !(value instanceof Date);
|
|
9195
|
+
}
|
|
9196
|
+
isModelLike(value) {
|
|
9197
|
+
return this.isPlainObject(value) && typeof value.getAttribute === "function";
|
|
9198
|
+
}
|
|
9199
|
+
normalizeRelatedItems(related) {
|
|
9200
|
+
return Array.isArray(related) ? related : [related];
|
|
9201
|
+
}
|
|
9202
|
+
normalizeSyncEntries(related, pivotAttributes = {}) {
|
|
9203
|
+
if (Array.isArray(related)) return related.map((item) => ({
|
|
9204
|
+
related: item,
|
|
9205
|
+
attributes: { ...pivotAttributes }
|
|
9206
|
+
}));
|
|
9207
|
+
if (this.isPlainObject(related) && !this.isModelLike(related)) return Object.entries(related).map(([key, attributes]) => ({
|
|
9208
|
+
related: this.normalizeIdentifierValue(key),
|
|
9209
|
+
attributes: this.isPlainObject(attributes) ? attributes : {}
|
|
9210
|
+
}));
|
|
9211
|
+
return [{
|
|
9212
|
+
related,
|
|
9213
|
+
attributes: { ...pivotAttributes }
|
|
9214
|
+
}];
|
|
9215
|
+
}
|
|
9216
|
+
resolveParentPivotValue() {
|
|
9217
|
+
return this.parent.getAttribute(this.parentKey);
|
|
9218
|
+
}
|
|
9219
|
+
resolveRelatedPivotValue(related) {
|
|
9220
|
+
if (related && typeof related === "object" && "getAttribute" in related) return related.getAttribute(this.relatedKey);
|
|
9221
|
+
return related;
|
|
9222
|
+
}
|
|
9223
|
+
buildPivotInsertValues(related, attributes = {}) {
|
|
9224
|
+
const values = {
|
|
9225
|
+
...attributes,
|
|
9226
|
+
[this.foreignPivotKey]: this.resolveParentPivotValue(),
|
|
9227
|
+
[this.relatedPivotKey]: this.resolveRelatedPivotValue(related)
|
|
9228
|
+
};
|
|
9229
|
+
if (this.pivotCreatedAtColumn && !(this.pivotCreatedAtColumn in values)) values[this.pivotCreatedAtColumn] = /* @__PURE__ */ new Date();
|
|
9230
|
+
if (this.pivotUpdatedAtColumn && !(this.pivotUpdatedAtColumn in values)) values[this.pivotUpdatedAtColumn] = /* @__PURE__ */ new Date();
|
|
9231
|
+
return values;
|
|
9232
|
+
}
|
|
9233
|
+
attachPivotToSingleResult(related, pivotRow) {
|
|
9234
|
+
if (!this.shouldAttachPivotAttributes()) return related;
|
|
9235
|
+
related.setAttribute(this.pivotAccessor, this.createPivotRecord(pivotRow));
|
|
9236
|
+
return related;
|
|
9237
|
+
}
|
|
9238
|
+
async insertPivotRow(values, adapter = this.getRelationAdapter()) {
|
|
9239
|
+
await adapter.insert({
|
|
9240
|
+
target: this.buildPivotTarget(),
|
|
9241
|
+
values
|
|
9242
|
+
});
|
|
9243
|
+
}
|
|
9244
|
+
async selectPivotRows(where, adapter = this.getRelationAdapter()) {
|
|
9245
|
+
return await adapter.select({
|
|
9246
|
+
target: this.buildPivotTarget(),
|
|
9247
|
+
where
|
|
9248
|
+
});
|
|
9249
|
+
}
|
|
9250
|
+
async deletePivotRows(where, adapter = this.getRelationAdapter()) {
|
|
9251
|
+
if (typeof adapter.deleteMany === "function") return await adapter.deleteMany({
|
|
9252
|
+
target: this.buildPivotTarget(),
|
|
9253
|
+
where
|
|
9254
|
+
});
|
|
9255
|
+
const rows = await this.selectPivotRows(where, adapter);
|
|
9256
|
+
await Promise.all(rows.map(async (row) => {
|
|
9257
|
+
await adapter.delete({
|
|
9258
|
+
target: this.buildPivotTarget(),
|
|
9259
|
+
where: {
|
|
9260
|
+
type: "group",
|
|
9261
|
+
operator: "and",
|
|
9262
|
+
conditions: Object.entries(row).map(([column, value]) => ({
|
|
9263
|
+
type: "comparison",
|
|
9264
|
+
column,
|
|
9265
|
+
operator: "=",
|
|
9266
|
+
value
|
|
9267
|
+
}))
|
|
9268
|
+
}
|
|
9269
|
+
});
|
|
9270
|
+
}));
|
|
9271
|
+
return rows.length;
|
|
9272
|
+
}
|
|
9273
|
+
buildPivotUpdateValues(attributes = {}) {
|
|
9274
|
+
const values = { ...attributes };
|
|
9275
|
+
if (this.pivotUpdatedAtColumn && !(this.pivotUpdatedAtColumn in values)) values[this.pivotUpdatedAtColumn] = /* @__PURE__ */ new Date();
|
|
9276
|
+
return values;
|
|
9277
|
+
}
|
|
9278
|
+
async updatePivotRows(related, attributes, adapter = this.getRelationAdapter()) {
|
|
9279
|
+
const values = this.buildPivotUpdateValues(attributes);
|
|
9280
|
+
if (Object.keys(values).length === 0) return 0;
|
|
9281
|
+
const where = this.buildPivotMutationWhere([this.resolveRelatedPivotValue(related)]);
|
|
9282
|
+
if (typeof adapter.updateMany === "function") return await adapter.updateMany({
|
|
9283
|
+
target: this.buildPivotTarget(),
|
|
9284
|
+
where,
|
|
9285
|
+
values
|
|
9286
|
+
});
|
|
9287
|
+
const rows = await this.selectPivotRows(where, adapter);
|
|
9288
|
+
await Promise.all(rows.map(async (row) => {
|
|
9289
|
+
await adapter.update({
|
|
9290
|
+
target: this.buildPivotTarget(),
|
|
9291
|
+
where: {
|
|
9292
|
+
type: "group",
|
|
9293
|
+
operator: "and",
|
|
9294
|
+
conditions: Object.entries(row).map(([column, value]) => ({
|
|
9295
|
+
type: "comparison",
|
|
9296
|
+
column,
|
|
9297
|
+
operator: "=",
|
|
9298
|
+
value
|
|
9299
|
+
}))
|
|
9300
|
+
},
|
|
9301
|
+
values
|
|
9302
|
+
});
|
|
9303
|
+
}));
|
|
9304
|
+
return rows.length;
|
|
9305
|
+
}
|
|
9306
|
+
/**
|
|
9307
|
+
* Creates a new instance of the related model with the given attributes and attaches
|
|
9308
|
+
* pivot attributes if pivot attributes should be included.
|
|
9309
|
+
*
|
|
9310
|
+
* @param attributes The attributes to initialize the related model with.
|
|
9311
|
+
* @returns A new instance of the related model.
|
|
9312
|
+
*/
|
|
9313
|
+
make(attributes = {}) {
|
|
9314
|
+
return this.related.hydrate(attributes);
|
|
9315
|
+
}
|
|
9316
|
+
/**
|
|
9317
|
+
* Creates a new related model record with the given attributes, creates a pivot record
|
|
9318
|
+
* with the given pivot attributes, and attaches pivot attributes if pivot attributes
|
|
9319
|
+
* should be included.
|
|
9320
|
+
*
|
|
9321
|
+
* @param attributes The attributes to initialize the related model with.
|
|
9322
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
9323
|
+
* @returns A new instance of the related model with pivot attributes attached.
|
|
9324
|
+
*/
|
|
9325
|
+
async create(attributes = {}, pivotAttributes = {}) {
|
|
9326
|
+
const related = await this.related.query().create(attributes);
|
|
9327
|
+
const pivotRow = this.buildPivotInsertValues(related, pivotAttributes);
|
|
9328
|
+
await this.insertPivotRow(pivotRow);
|
|
9329
|
+
return this.attachPivotToSingleResult(related, pivotRow);
|
|
9330
|
+
}
|
|
9331
|
+
/**
|
|
9332
|
+
* Saves a related model record, creates a pivot record with the given pivot attributes
|
|
9333
|
+
* if the related model was not previously persisted, and attaches pivot attributes if
|
|
9334
|
+
* pivot attributes should be included.
|
|
9335
|
+
*
|
|
9336
|
+
* @param related The related model instance to save.
|
|
9337
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
9338
|
+
* @returns A new instance of the related model with pivot attributes attached.
|
|
9339
|
+
*/
|
|
9340
|
+
async save(related, pivotAttributes = {}) {
|
|
9341
|
+
const saveable = related;
|
|
9342
|
+
let persisted = related;
|
|
9343
|
+
if (typeof saveable.save === "function") try {
|
|
9344
|
+
persisted = await saveable.save();
|
|
9345
|
+
} catch (error) {
|
|
9346
|
+
if (!(typeof error === "object" && error !== null && "code" in error && error.code === "MODEL_NOT_FOUND")) throw error;
|
|
9347
|
+
const attributes = typeof saveable.getRawAttributes === "function" ? saveable.getRawAttributes() : {};
|
|
9348
|
+
persisted = await this.related.query().create(attributes);
|
|
9349
|
+
}
|
|
9350
|
+
const pivotRow = this.buildPivotInsertValues(persisted, pivotAttributes);
|
|
9351
|
+
await this.insertPivotRow(pivotRow);
|
|
9352
|
+
return this.attachPivotToSingleResult(persisted, pivotRow);
|
|
9353
|
+
}
|
|
9354
|
+
/**
|
|
9355
|
+
* Attaches one or more related model records to the parent model by creating pivot
|
|
9356
|
+
* records with the given pivot attributes if pivot attributes should be included.
|
|
9357
|
+
*
|
|
9358
|
+
* @param related The related model instance(s) to attach.
|
|
9359
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
9360
|
+
* @returns The number of related model records attached.
|
|
9361
|
+
*/
|
|
9362
|
+
async attach(related, pivotAttributes = {}) {
|
|
9363
|
+
const items = Array.isArray(related) ? related : [related];
|
|
9364
|
+
await Promise.all(items.map(async (item) => {
|
|
9365
|
+
await this.insertPivotRow(this.buildPivotInsertValues(item, pivotAttributes));
|
|
9366
|
+
}));
|
|
9367
|
+
return items.length;
|
|
9368
|
+
}
|
|
9369
|
+
/**
|
|
9370
|
+
* Detaches one or more related model records from the parent model by deleting
|
|
9371
|
+
* matching pivot rows. When no related value is provided, all matching pivot rows
|
|
9372
|
+
* for the parent are removed.
|
|
9373
|
+
*
|
|
9374
|
+
* @param related
|
|
9375
|
+
* @returns
|
|
9376
|
+
*/
|
|
9377
|
+
async detach(related) {
|
|
9378
|
+
const where = related === void 0 ? this.buildPivotWhere(this.resolveParentPivotValue()) : this.buildPivotMutationWhere(this.normalizeRelatedItems(related).map((item) => this.resolveRelatedPivotValue(item)));
|
|
9379
|
+
return await this.deletePivotRows(where);
|
|
9380
|
+
}
|
|
9381
|
+
/**
|
|
9382
|
+
* Synchronizes the pivot table so only the provided related values remain attached.
|
|
9383
|
+
* Existing matching rows can receive updated pivot attributes during the operation.
|
|
9384
|
+
*
|
|
9385
|
+
* @param related
|
|
9386
|
+
* @param pivotAttributes
|
|
9387
|
+
* @returns
|
|
9388
|
+
*/
|
|
9389
|
+
async sync(related, pivotAttributes = {}) {
|
|
9390
|
+
return await this.getRelationAdapter().transaction(async (transaction) => {
|
|
9391
|
+
const existingRows = await this.selectPivotRows(this.buildPivotWhere(this.resolveParentPivotValue()), transaction);
|
|
9392
|
+
const desiredEntries = /* @__PURE__ */ new Map();
|
|
9393
|
+
this.normalizeSyncEntries(related, pivotAttributes).forEach((entry) => {
|
|
9394
|
+
const relatedValue = this.resolveRelatedPivotValue(entry.related);
|
|
9395
|
+
if (relatedValue == null) return;
|
|
9396
|
+
desiredEntries.set(String(relatedValue), {
|
|
9397
|
+
related: relatedValue,
|
|
9398
|
+
attributes: entry.attributes
|
|
9399
|
+
});
|
|
9400
|
+
});
|
|
9401
|
+
let detached = 0;
|
|
9402
|
+
let attached = 0;
|
|
9403
|
+
let updated = 0;
|
|
9404
|
+
const existingKeys = /* @__PURE__ */ new Set();
|
|
9405
|
+
for (const row of existingRows) {
|
|
9406
|
+
const relatedValue = row[this.relatedPivotKey];
|
|
9407
|
+
if (relatedValue == null) continue;
|
|
9408
|
+
const relatedKey = String(relatedValue);
|
|
9409
|
+
existingKeys.add(relatedKey);
|
|
9410
|
+
if (!desiredEntries.has(relatedKey)) detached += await this.deletePivotRows(this.buildPivotMutationWhere([relatedValue]), transaction);
|
|
9411
|
+
}
|
|
9412
|
+
for (const [relatedKey, entry] of desiredEntries) {
|
|
9413
|
+
if (!existingKeys.has(relatedKey)) {
|
|
9414
|
+
await this.insertPivotRow(this.buildPivotInsertValues(entry.related, entry.attributes), transaction);
|
|
9415
|
+
attached += 1;
|
|
9416
|
+
continue;
|
|
9417
|
+
}
|
|
9418
|
+
if (Object.keys(entry.attributes).length === 0) continue;
|
|
9419
|
+
updated += await this.updatePivotRows(entry.related, entry.attributes, transaction);
|
|
9420
|
+
}
|
|
9421
|
+
return {
|
|
9422
|
+
attached,
|
|
9423
|
+
detached,
|
|
9424
|
+
updated
|
|
9425
|
+
};
|
|
9426
|
+
});
|
|
9427
|
+
}
|
|
9157
9428
|
shouldAttachPivotAttributes() {
|
|
9158
9429
|
return this.shouldAttachPivot || this.pivotColumns.size > 0 || Boolean(this.pivotCreatedAtColumn) || Boolean(this.pivotUpdatedAtColumn) || Boolean(this.pivotModel);
|
|
9159
9430
|
}
|
|
@@ -9239,7 +9510,7 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
9239
9510
|
return query;
|
|
9240
9511
|
}
|
|
9241
9512
|
async loadPivotRowsForParent() {
|
|
9242
|
-
const parentValue = this.
|
|
9513
|
+
const parentValue = this.resolveParentPivotValue();
|
|
9243
9514
|
return await this.createRelationTableLoader().selectRows({
|
|
9244
9515
|
table: this.throughDelegate,
|
|
9245
9516
|
where: this.buildPivotWhere(parentValue),
|
package/dist/index.d.cts
CHANGED
|
@@ -791,6 +791,82 @@ declare class BelongsToManyRelation<TParent, TRelated> extends Relation<TRelated
|
|
|
791
791
|
private addPivotWhere;
|
|
792
792
|
private makePivotComparison;
|
|
793
793
|
private buildPivotWhere;
|
|
794
|
+
private buildPivotTarget;
|
|
795
|
+
private buildRelatedPivotCondition;
|
|
796
|
+
private buildPivotMutationWhere;
|
|
797
|
+
private normalizeIdentifierValue;
|
|
798
|
+
private isPlainObject;
|
|
799
|
+
private isModelLike;
|
|
800
|
+
private normalizeRelatedItems;
|
|
801
|
+
private normalizeSyncEntries;
|
|
802
|
+
private resolveParentPivotValue;
|
|
803
|
+
private resolveRelatedPivotValue;
|
|
804
|
+
private buildPivotInsertValues;
|
|
805
|
+
private attachPivotToSingleResult;
|
|
806
|
+
private insertPivotRow;
|
|
807
|
+
private selectPivotRows;
|
|
808
|
+
private deletePivotRows;
|
|
809
|
+
private buildPivotUpdateValues;
|
|
810
|
+
private updatePivotRows;
|
|
811
|
+
/**
|
|
812
|
+
* Creates a new instance of the related model with the given attributes and attaches
|
|
813
|
+
* pivot attributes if pivot attributes should be included.
|
|
814
|
+
*
|
|
815
|
+
* @param attributes The attributes to initialize the related model with.
|
|
816
|
+
* @returns A new instance of the related model.
|
|
817
|
+
*/
|
|
818
|
+
make(attributes?: Record<string, unknown>): TRelated;
|
|
819
|
+
/**
|
|
820
|
+
* Creates a new related model record with the given attributes, creates a pivot record
|
|
821
|
+
* with the given pivot attributes, and attaches pivot attributes if pivot attributes
|
|
822
|
+
* should be included.
|
|
823
|
+
*
|
|
824
|
+
* @param attributes The attributes to initialize the related model with.
|
|
825
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
826
|
+
* @returns A new instance of the related model with pivot attributes attached.
|
|
827
|
+
*/
|
|
828
|
+
create(attributes?: Record<string, unknown>, pivotAttributes?: Record<string, unknown>): Promise<TRelated>;
|
|
829
|
+
/**
|
|
830
|
+
* Saves a related model record, creates a pivot record with the given pivot attributes
|
|
831
|
+
* if the related model was not previously persisted, and attaches pivot attributes if
|
|
832
|
+
* pivot attributes should be included.
|
|
833
|
+
*
|
|
834
|
+
* @param related The related model instance to save.
|
|
835
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
836
|
+
* @returns A new instance of the related model with pivot attributes attached.
|
|
837
|
+
*/
|
|
838
|
+
save(related: TRelated, pivotAttributes?: Record<string, unknown>): Promise<TRelated>;
|
|
839
|
+
/**
|
|
840
|
+
* Attaches one or more related model records to the parent model by creating pivot
|
|
841
|
+
* records with the given pivot attributes if pivot attributes should be included.
|
|
842
|
+
*
|
|
843
|
+
* @param related The related model instance(s) to attach.
|
|
844
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
845
|
+
* @returns The number of related model records attached.
|
|
846
|
+
*/
|
|
847
|
+
attach(related: TRelated | unknown | Array<TRelated | unknown>, pivotAttributes?: Record<string, unknown>): Promise<number>;
|
|
848
|
+
/**
|
|
849
|
+
* Detaches one or more related model records from the parent model by deleting
|
|
850
|
+
* matching pivot rows. When no related value is provided, all matching pivot rows
|
|
851
|
+
* for the parent are removed.
|
|
852
|
+
*
|
|
853
|
+
* @param related
|
|
854
|
+
* @returns
|
|
855
|
+
*/
|
|
856
|
+
detach(related?: TRelated | unknown | Array<TRelated | unknown>): Promise<number>;
|
|
857
|
+
/**
|
|
858
|
+
* Synchronizes the pivot table so only the provided related values remain attached.
|
|
859
|
+
* Existing matching rows can receive updated pivot attributes during the operation.
|
|
860
|
+
*
|
|
861
|
+
* @param related
|
|
862
|
+
* @param pivotAttributes
|
|
863
|
+
* @returns
|
|
864
|
+
*/
|
|
865
|
+
sync(related: TRelated | unknown | Array<TRelated | unknown> | Record<string, Record<string, unknown>>, pivotAttributes?: Record<string, unknown>): Promise<{
|
|
866
|
+
attached: number;
|
|
867
|
+
detached: number;
|
|
868
|
+
updated: number;
|
|
869
|
+
}>;
|
|
794
870
|
private shouldAttachPivotAttributes;
|
|
795
871
|
private getPivotColumnSelection;
|
|
796
872
|
/**
|
|
@@ -1343,7 +1419,7 @@ declare abstract class Model<TSchema extends PrismaDelegateLike | Record<string,
|
|
|
1343
1419
|
* @param this
|
|
1344
1420
|
* @returns
|
|
1345
1421
|
*/
|
|
1346
|
-
static query<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any
|
|
1422
|
+
static query<TThis extends abstract new (attributes?: Record<string, unknown>) => unknown, TModel extends Model<any, any> = InstanceType<TThis> & Model<any, any>, TDelegate extends PrismaDelegateLike = DelegateForModelSchema<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis): QueryBuilder<TModel, TDelegate>;
|
|
1347
1423
|
/**
|
|
1348
1424
|
* Boot hook for subclasses to register scopes or perform one-time setup.
|
|
1349
1425
|
*/
|
|
@@ -1358,14 +1434,14 @@ declare abstract class Model<TSchema extends PrismaDelegateLike | Record<string,
|
|
|
1358
1434
|
* @param this
|
|
1359
1435
|
* @returns
|
|
1360
1436
|
*/
|
|
1361
|
-
static withTrashed<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any
|
|
1437
|
+
static withTrashed<TThis extends abstract new (attributes?: Record<string, unknown>) => unknown, TModel extends Model<any, any> = InstanceType<TThis> & Model<any, any>, TDelegate extends PrismaDelegateLike = DelegateForModelSchema<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis): QueryBuilder<TModel, TDelegate>;
|
|
1362
1438
|
/**
|
|
1363
1439
|
* Get a query builder instance that only includes soft-deleted records.
|
|
1364
1440
|
*
|
|
1365
1441
|
* @param this
|
|
1366
1442
|
* @returns
|
|
1367
1443
|
*/
|
|
1368
|
-
static onlyTrashed<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any
|
|
1444
|
+
static onlyTrashed<TThis extends abstract new (attributes?: Record<string, unknown>) => unknown, TModel extends Model<any, any> = InstanceType<TThis> & Model<any, any>, TDelegate extends PrismaDelegateLike = DelegateForModelSchema<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis): QueryBuilder<TModel, TDelegate>;
|
|
1369
1445
|
/**
|
|
1370
1446
|
* Get a query builder instance that excludes soft-deleted records.
|
|
1371
1447
|
* This is the default behavior of the query builder, but this method can be used
|
|
@@ -1376,7 +1452,7 @@ declare abstract class Model<TSchema extends PrismaDelegateLike | Record<string,
|
|
|
1376
1452
|
* @param args
|
|
1377
1453
|
* @returns
|
|
1378
1454
|
*/
|
|
1379
|
-
static scope<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any
|
|
1455
|
+
static scope<TThis extends abstract new (attributes?: Record<string, unknown>) => unknown, TModel extends Model<any, any> = InstanceType<TThis> & Model<any, any>, TDelegate extends PrismaDelegateLike = DelegateForModelSchema<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis, name: string, ...args: unknown[]): QueryBuilder<TModel, TDelegate>;
|
|
1380
1456
|
/**
|
|
1381
1457
|
* Get the soft delete configuration for the model, including whether
|
|
1382
1458
|
* soft deletes are enabled and the name of the deleted at column.
|
|
@@ -1431,9 +1507,7 @@ declare abstract class Model<TSchema extends PrismaDelegateLike | Record<string,
|
|
|
1431
1507
|
* @param key
|
|
1432
1508
|
* @returns
|
|
1433
1509
|
*/
|
|
1434
|
-
getAttribute<TKey extends
|
|
1435
|
-
getAttribute<TKey extends keyof this & string>(key: TKey): this[TKey] extends ((...args: any[]) => any) ? unknown : this[TKey];
|
|
1436
|
-
getAttribute<TKey extends keyof TAttributes & string>(key: TKey): TAttributes[TKey];
|
|
1510
|
+
getAttribute<TSelf extends this, TKey extends string>(this: TSelf, key: TKey): ModelAttributeValue<TSelf, TAttributes, TKey>;
|
|
1437
1511
|
getAttribute(key: string): unknown;
|
|
1438
1512
|
/**
|
|
1439
1513
|
* Set the value of an attribute, applying any set mutators or casts if defined.
|
|
@@ -1442,9 +1516,7 @@ declare abstract class Model<TSchema extends PrismaDelegateLike | Record<string,
|
|
|
1442
1516
|
* @param value
|
|
1443
1517
|
* @returns
|
|
1444
1518
|
*/
|
|
1445
|
-
setAttribute<TKey extends
|
|
1446
|
-
setAttribute<TKey extends keyof this & string>(key: TKey, value: this[TKey] extends ((...args: any[]) => any) ? never : this[TKey]): this;
|
|
1447
|
-
setAttribute<TKey extends keyof TAttributes & string>(key: TKey, value: TAttributes[TKey]): this;
|
|
1519
|
+
setAttribute<TSelf extends this, TKey extends string>(this: TSelf, key: TKey, value: ModelAttributeValue<TSelf, TAttributes, TKey>): this;
|
|
1448
1520
|
setAttribute(key: string, value: unknown): this;
|
|
1449
1521
|
/**
|
|
1450
1522
|
* Save the model to the database.
|
|
@@ -1869,11 +1941,14 @@ interface AttributeSchemaDelegate<TAttributes extends Record<string, unknown>> e
|
|
|
1869
1941
|
type DelegateForModelSchema<TSchema extends PrismaDelegateLike | Record<string, unknown> | string, TAttributes extends Record<string, unknown> = ModelAttributesOf<TSchema>> = TSchema extends PrismaDelegateLike ? TSchema : TSchema extends string ? DelegateFromPrismaClient<TSchema> extends PrismaDelegateLike ? DelegateFromPrismaClient<TSchema> : PrismaDelegateLike : AttributeSchemaDelegate<TAttributes>;
|
|
1870
1942
|
type ModelAttributesOf<TSchema extends PrismaDelegateLike | Record<string, unknown> | string> = TSchema extends PrismaDelegateLike ? DelegateRow<TSchema> extends Record<string, unknown> ? DelegateRow<TSchema> : Record<string, any> : TSchema extends string ? DelegateFromPrismaClient<TSchema> extends PrismaDelegateLike ? DelegateRow<DelegateFromPrismaClient<TSchema>> extends Record<string, unknown> ? DelegateRow<DelegateFromPrismaClient<TSchema>> : Record<string, any> : Record<string, any> : TSchema extends Record<string, unknown> ? TSchema : Record<string, any>;
|
|
1871
1943
|
type ModelAttributes<TModel> = TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>;
|
|
1944
|
+
type BaseModelInstance = Model<any, any>;
|
|
1945
|
+
type ModelDeclaredAttributeKey<TModel> = { [TKey in keyof TModel & string]: TKey extends keyof BaseModelInstance ? never : TModel[TKey] extends ((...args: any[]) => any) ? never : TKey }[keyof TModel & string];
|
|
1872
1946
|
type RelationshipResultProvider<TResult = unknown> = {
|
|
1873
1947
|
getResults: (...args: any[]) => Promise<TResult>;
|
|
1874
1948
|
};
|
|
1875
|
-
type ModelRelationshipKey<TModel> = { [TKey in keyof TModel & string]: TModel[TKey] extends ((...args: any[]) => infer TReturn) ? TReturn extends RelationshipResultProvider<any> ? TKey : never : never }[keyof TModel & string];
|
|
1949
|
+
type ModelRelationshipKey<TModel> = { [TKey in keyof TModel & string]: TKey extends keyof BaseModelInstance ? never : TModel[TKey] extends ((...args: any[]) => infer TReturn) ? Parameters<TModel[TKey]> extends [] ? TReturn extends RelationshipResultProvider<any> ? TKey : never : never : never }[keyof TModel & string];
|
|
1876
1950
|
type ModelRelationshipResult<TModel, TKey extends ModelRelationshipKey<TModel>> = TModel[TKey] extends ((...args: any[]) => infer TReturn) ? TReturn extends RelationshipResultProvider<infer TResult> ? TResult : never : never;
|
|
1951
|
+
type ModelAttributeValue<TModel, TAttributes extends Record<string, unknown>, TKey extends string> = TKey extends ModelRelationshipKey<TModel> ? ModelRelationshipResult<TModel, TKey> : TKey extends ModelDeclaredAttributeKey<TModel> ? TModel[TKey] : TKey extends keyof TAttributes & string ? TAttributes[TKey] : unknown;
|
|
1877
1952
|
type ModelCreateData<TModel, TDelegate extends PrismaDelegateLike> = TModel extends Model<any, infer TAttributes> ? TDelegate extends AttributeSchemaDelegate<TAttributes> ? AttributeCreateInput<TAttributes> : DelegateCreateData<TDelegate> : DelegateCreateData<TDelegate>;
|
|
1878
1953
|
type ModelUpdateData<TModel, TDelegate extends PrismaDelegateLike> = TModel extends Model<any, infer TAttributes> ? TDelegate extends AttributeSchemaDelegate<TAttributes> ? AttributeUpdateInput<TAttributes> : DelegateUpdateData<TDelegate> : DelegateUpdateData<TDelegate>;
|
|
1879
1954
|
type RelatedModelClass<TInstance = unknown> = (abstract new (attributes?: Record<string, unknown>) => TInstance) & RelationshipModelStatic;
|
|
@@ -4983,4 +5058,4 @@ declare class URLDriver {
|
|
|
4983
5058
|
url(page: number): string;
|
|
4984
5059
|
}
|
|
4985
5060
|
//#endregion
|
|
4986
|
-
export { AdapterBindableModel, AdapterCapabilities, AdapterCapability, AdapterInspectionRequest, AdapterModelFieldStructure, AdapterModelIntrospectionOptions, AdapterModelStructure, AdapterQueryInspection, AdapterQueryOperation, AdapterTransactionContext, AggregateOperation, AggregateSelection, AggregateSpec, AppliedMigrationEntry, AppliedMigrationRun, AppliedMigrationsState, ArkormBootContext, ArkormCollection, ArkormConfig, ArkormDebugEvent, ArkormDebugHandler, ArkormErrorContext, ArkormException, Attribute, AttributeCreateInput, AttributeOptions, AttributeOrderBy, AttributeSchemaDelegate, AttributeSelect, AttributeUpdateInput, AttributeWhereInput, BelongsToManyRelationMetadata, BelongsToRelationMetadata, CastDefinition, CastHandler, CastMap, CastType, CliApp, ClientResolver, ColumnMap, DB, DatabaseAdapter, DatabasePrimitive, DatabaseRow, DatabaseRows, DatabaseTableOptions, DatabaseTablePersistedMetadataOptions, DatabaseValue, DelegateCreateData, DelegateFindManyArgs, DelegateForModelSchema, DelegateInclude, DelegateOrderBy, DelegateRow, DelegateRows, DelegateSelect, DelegateUniqueWhere, DelegateUpdateArgs, DelegateUpdateData, DelegateWhere, DeleteManySpec, DeleteSpec, EagerLoadConstraint, EagerLoadMap, EnumBuilder, FactoryAttributes, FactoryDefinition, FactoryModelConstructor, FactoryState, ForeignKeyBuilder, GenerateMigrationOptions, GeneratedMigrationFile, GetUserConfig, GlobalScope, HasManyRelationMetadata, HasManyThroughRelationMetadata, HasOneRelationMetadata, HasOneThroughRelationMetadata, InitCommand, InlineFactory, InsertManySpec, InsertSpec, KyselyDatabaseAdapter, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateFreshCommand, MigrateRollbackCommand, Migration, MigrationClass, MigrationHistoryCommand, MigrationInstanceLike, MissingDelegateException, Model, ModelAttributes, ModelAttributesOf, ModelCreateData, ModelEventDispatcher, ModelEventHandler, ModelEventHandlerConstructor, ModelEventListener, ModelEventName, ModelFactory, ModelLifecycleState, ModelMetadata, ModelNotFoundException, ModelRelationshipKey, ModelRelationshipResult, ModelStatic, ModelUpdateData, ModelsSyncCommand, MorphManyRelationMetadata, MorphOneRelationMetadata, MorphToManyRelationMetadata, PRISMA_ENUM_MEMBER_REGEX, PRISMA_ENUM_REGEX, PRISMA_MODEL_REGEX, PaginationCurrentPageResolver, PaginationMeta, PaginationOptions, PaginationURLDriver, PaginationURLDriverFactory, Paginator, PersistedColumnMappingsState, PersistedMetadataFeatures, PersistedPrimaryKeyGeneration, PersistedTableMetadata, PersistedTimestampColumn, PivotModel, PivotModelStatic, PrimaryKeyGeneration, PrimaryKeyGenerationPlanner, PrismaClientLike, PrismaDatabaseAdapter, PrismaDelegateLike, PrismaDelegateMap, PrismaDelegateNameMapping, PrismaFindManyArgsLike, PrismaLikeInclude, PrismaLikeOrderBy, PrismaLikeScalarFilter, PrismaLikeSelect, PrismaLikeSortOrder, PrismaLikeWhereInput, PrismaMigrationWorkflowOptions, PrismaSchemaSyncOptions, PrismaTransactionCallback, PrismaTransactionCapableClient, PrismaTransactionOptions, QueryBuilder, QueryComparisonCondition, QueryComparisonOperator, QueryCondition, QueryConstraintException, QueryExecutionException, QueryExecutionExceptionContext, QueryGroupCondition, QueryLogicalOperator, QueryNotCondition, QueryOrderBy, QueryRawCondition, QuerySelectColumn, QueryTarget, RelatedModelClass, RelationAggregateSpec, RelationColumnLookupSpec, RelationConstraint, RelationDefaultResolver, RelationDefaultValue, RelationFilterSpec, RelationLoadPlan, RelationLoadSpec, RelationMetadata, RelationMetadataProvider, RelationMetadataType, RelationResolutionException, RelationTableLookupSpec, RelationshipModelStatic, RuntimeModuleLoader, SEEDER_BRAND, SchemaBuilder, SchemaColumn, SchemaColumnType, SchemaForeignKey, SchemaForeignKeyAction, SchemaIndex, SchemaOperation, SchemaTableAlterOperation, SchemaTableCreateOperation, SchemaTableDropOperation, ScopeNotDefinedException, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, SelectSpec, Serializable, SimplePaginationMeta, SoftDeleteConfig, SoftDeleteQueryMode, SortDirection, TableBuilder, TimestampColumnBehavior, URLDriver, UniqueConstraintResolutionException, UnsupportedAdapterFeatureException, UpdateManySpec, UpdateSpec, UpsertSpec, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToDatabase, applyMigrationRollbackToPrismaSchema, applyMigrationToDatabase, applyMigrationToPrismaSchema, applyOperationsToPersistedColumnMappingsState, applyOperationsToPrismaSchema, bindAdapterToModels, buildEnumBlock, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createEmptyAppliedMigrationsState, createEmptyPersistedColumnMappingsState, createKyselyAdapter, createMigrationTimestamp, createPrismaAdapter, createPrismaCompatibilityAdapter, createPrismaDatabaseAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deleteAppliedMigrationsStateFromStore, deletePersistedColumnMappingsState, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationAlias, deriveRelationFieldName, deriveSingularFieldName, emitRuntimeDebugEvent, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findEnumBlock, findModelBlock, formatDefaultValue, formatEnumDefaultValue, formatRelationAction, generateMigrationFile, getActiveTransactionClient, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getPersistedColumnMap, getPersistedEnumMap, getPersistedEnumTsType, getPersistedPrimaryKeyGeneration, getPersistedTableMetadata, getPersistedTimestampColumns, getRuntimeAdapter, getRuntimeDebugHandler, getRuntimePaginationCurrentPageResolver, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, isTransactionCapableClient, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, readAppliedMigrationsStateFromStore, readPersistedColumnMappingsState, rebuildPersistedColumnMappingsState, removeAppliedMigration, resetArkormRuntimeForTests, resetPersistedColumnMappingsCache, resolveCast, resolveColumnMappingsFilePath, resolveEnumName, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePersistedMetadataFeatures, resolvePrismaType, runArkormTransaction, runMigrationWithPrisma, runPrismaCommand, stripPrismaSchemaModelsAndEnums, supportsDatabaseMigrationExecution, supportsDatabaseMigrationState, supportsDatabaseReset, syncPersistedColumnMappingsFromState, toMigrationFileSlug, toModelName, validatePersistedMetadataFeaturesForMigrations, writeAppliedMigrationsState, writeAppliedMigrationsStateToStore, writePersistedColumnMappingsState };
|
|
5061
|
+
export { AdapterBindableModel, AdapterCapabilities, AdapterCapability, AdapterInspectionRequest, AdapterModelFieldStructure, AdapterModelIntrospectionOptions, AdapterModelStructure, AdapterQueryInspection, AdapterQueryOperation, AdapterTransactionContext, AggregateOperation, AggregateSelection, AggregateSpec, AppliedMigrationEntry, AppliedMigrationRun, AppliedMigrationsState, ArkormBootContext, ArkormCollection, ArkormConfig, ArkormDebugEvent, ArkormDebugHandler, ArkormErrorContext, ArkormException, Attribute, AttributeCreateInput, AttributeOptions, AttributeOrderBy, AttributeSchemaDelegate, AttributeSelect, AttributeUpdateInput, AttributeWhereInput, BelongsToManyRelationMetadata, BelongsToRelationMetadata, CastDefinition, CastHandler, CastMap, CastType, CliApp, ClientResolver, ColumnMap, DB, DatabaseAdapter, DatabasePrimitive, DatabaseRow, DatabaseRows, DatabaseTableOptions, DatabaseTablePersistedMetadataOptions, DatabaseValue, DelegateCreateData, DelegateFindManyArgs, DelegateForModelSchema, DelegateInclude, DelegateOrderBy, DelegateRow, DelegateRows, DelegateSelect, DelegateUniqueWhere, DelegateUpdateArgs, DelegateUpdateData, DelegateWhere, DeleteManySpec, DeleteSpec, EagerLoadConstraint, EagerLoadMap, EnumBuilder, FactoryAttributes, FactoryDefinition, FactoryModelConstructor, FactoryState, ForeignKeyBuilder, GenerateMigrationOptions, GeneratedMigrationFile, GetUserConfig, GlobalScope, HasManyRelationMetadata, HasManyThroughRelationMetadata, HasOneRelationMetadata, HasOneThroughRelationMetadata, InitCommand, InlineFactory, InsertManySpec, InsertSpec, KyselyDatabaseAdapter, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateFreshCommand, MigrateRollbackCommand, Migration, MigrationClass, MigrationHistoryCommand, MigrationInstanceLike, MissingDelegateException, Model, ModelAttributeValue, ModelAttributes, ModelAttributesOf, ModelCreateData, ModelDeclaredAttributeKey, ModelEventDispatcher, ModelEventHandler, ModelEventHandlerConstructor, ModelEventListener, ModelEventName, ModelFactory, ModelLifecycleState, ModelMetadata, ModelNotFoundException, ModelRelationshipKey, ModelRelationshipResult, ModelStatic, ModelUpdateData, ModelsSyncCommand, MorphManyRelationMetadata, MorphOneRelationMetadata, MorphToManyRelationMetadata, PRISMA_ENUM_MEMBER_REGEX, PRISMA_ENUM_REGEX, PRISMA_MODEL_REGEX, PaginationCurrentPageResolver, PaginationMeta, PaginationOptions, PaginationURLDriver, PaginationURLDriverFactory, Paginator, PersistedColumnMappingsState, PersistedMetadataFeatures, PersistedPrimaryKeyGeneration, PersistedTableMetadata, PersistedTimestampColumn, PivotModel, PivotModelStatic, PrimaryKeyGeneration, PrimaryKeyGenerationPlanner, PrismaClientLike, PrismaDatabaseAdapter, PrismaDelegateLike, PrismaDelegateMap, PrismaDelegateNameMapping, PrismaFindManyArgsLike, PrismaLikeInclude, PrismaLikeOrderBy, PrismaLikeScalarFilter, PrismaLikeSelect, PrismaLikeSortOrder, PrismaLikeWhereInput, PrismaMigrationWorkflowOptions, PrismaSchemaSyncOptions, PrismaTransactionCallback, PrismaTransactionCapableClient, PrismaTransactionOptions, QueryBuilder, QueryComparisonCondition, QueryComparisonOperator, QueryCondition, QueryConstraintException, QueryExecutionException, QueryExecutionExceptionContext, QueryGroupCondition, QueryLogicalOperator, QueryNotCondition, QueryOrderBy, QueryRawCondition, QuerySelectColumn, QueryTarget, RelatedModelClass, RelationAggregateSpec, RelationColumnLookupSpec, RelationConstraint, RelationDefaultResolver, RelationDefaultValue, RelationFilterSpec, RelationLoadPlan, RelationLoadSpec, RelationMetadata, RelationMetadataProvider, RelationMetadataType, RelationResolutionException, RelationTableLookupSpec, RelationshipModelStatic, RuntimeModuleLoader, SEEDER_BRAND, SchemaBuilder, SchemaColumn, SchemaColumnType, SchemaForeignKey, SchemaForeignKeyAction, SchemaIndex, SchemaOperation, SchemaTableAlterOperation, SchemaTableCreateOperation, SchemaTableDropOperation, ScopeNotDefinedException, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, SelectSpec, Serializable, SimplePaginationMeta, SoftDeleteConfig, SoftDeleteQueryMode, SortDirection, TableBuilder, TimestampColumnBehavior, URLDriver, UniqueConstraintResolutionException, UnsupportedAdapterFeatureException, UpdateManySpec, UpdateSpec, UpsertSpec, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToDatabase, applyMigrationRollbackToPrismaSchema, applyMigrationToDatabase, applyMigrationToPrismaSchema, applyOperationsToPersistedColumnMappingsState, applyOperationsToPrismaSchema, bindAdapterToModels, buildEnumBlock, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createEmptyAppliedMigrationsState, createEmptyPersistedColumnMappingsState, createKyselyAdapter, createMigrationTimestamp, createPrismaAdapter, createPrismaCompatibilityAdapter, createPrismaDatabaseAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deleteAppliedMigrationsStateFromStore, deletePersistedColumnMappingsState, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationAlias, deriveRelationFieldName, deriveSingularFieldName, emitRuntimeDebugEvent, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findEnumBlock, findModelBlock, formatDefaultValue, formatEnumDefaultValue, formatRelationAction, generateMigrationFile, getActiveTransactionClient, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getPersistedColumnMap, getPersistedEnumMap, getPersistedEnumTsType, getPersistedPrimaryKeyGeneration, getPersistedTableMetadata, getPersistedTimestampColumns, getRuntimeAdapter, getRuntimeDebugHandler, getRuntimePaginationCurrentPageResolver, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, isTransactionCapableClient, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, readAppliedMigrationsStateFromStore, readPersistedColumnMappingsState, rebuildPersistedColumnMappingsState, removeAppliedMigration, resetArkormRuntimeForTests, resetPersistedColumnMappingsCache, resolveCast, resolveColumnMappingsFilePath, resolveEnumName, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePersistedMetadataFeatures, resolvePrismaType, runArkormTransaction, runMigrationWithPrisma, runPrismaCommand, stripPrismaSchemaModelsAndEnums, supportsDatabaseMigrationExecution, supportsDatabaseMigrationState, supportsDatabaseReset, syncPersistedColumnMappingsFromState, toMigrationFileSlug, toModelName, validatePersistedMetadataFeaturesForMigrations, writeAppliedMigrationsState, writeAppliedMigrationsStateToStore, writePersistedColumnMappingsState };
|
package/dist/index.d.mts
CHANGED
|
@@ -791,6 +791,82 @@ declare class BelongsToManyRelation<TParent, TRelated> extends Relation<TRelated
|
|
|
791
791
|
private addPivotWhere;
|
|
792
792
|
private makePivotComparison;
|
|
793
793
|
private buildPivotWhere;
|
|
794
|
+
private buildPivotTarget;
|
|
795
|
+
private buildRelatedPivotCondition;
|
|
796
|
+
private buildPivotMutationWhere;
|
|
797
|
+
private normalizeIdentifierValue;
|
|
798
|
+
private isPlainObject;
|
|
799
|
+
private isModelLike;
|
|
800
|
+
private normalizeRelatedItems;
|
|
801
|
+
private normalizeSyncEntries;
|
|
802
|
+
private resolveParentPivotValue;
|
|
803
|
+
private resolveRelatedPivotValue;
|
|
804
|
+
private buildPivotInsertValues;
|
|
805
|
+
private attachPivotToSingleResult;
|
|
806
|
+
private insertPivotRow;
|
|
807
|
+
private selectPivotRows;
|
|
808
|
+
private deletePivotRows;
|
|
809
|
+
private buildPivotUpdateValues;
|
|
810
|
+
private updatePivotRows;
|
|
811
|
+
/**
|
|
812
|
+
* Creates a new instance of the related model with the given attributes and attaches
|
|
813
|
+
* pivot attributes if pivot attributes should be included.
|
|
814
|
+
*
|
|
815
|
+
* @param attributes The attributes to initialize the related model with.
|
|
816
|
+
* @returns A new instance of the related model.
|
|
817
|
+
*/
|
|
818
|
+
make(attributes?: Record<string, unknown>): TRelated;
|
|
819
|
+
/**
|
|
820
|
+
* Creates a new related model record with the given attributes, creates a pivot record
|
|
821
|
+
* with the given pivot attributes, and attaches pivot attributes if pivot attributes
|
|
822
|
+
* should be included.
|
|
823
|
+
*
|
|
824
|
+
* @param attributes The attributes to initialize the related model with.
|
|
825
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
826
|
+
* @returns A new instance of the related model with pivot attributes attached.
|
|
827
|
+
*/
|
|
828
|
+
create(attributes?: Record<string, unknown>, pivotAttributes?: Record<string, unknown>): Promise<TRelated>;
|
|
829
|
+
/**
|
|
830
|
+
* Saves a related model record, creates a pivot record with the given pivot attributes
|
|
831
|
+
* if the related model was not previously persisted, and attaches pivot attributes if
|
|
832
|
+
* pivot attributes should be included.
|
|
833
|
+
*
|
|
834
|
+
* @param related The related model instance to save.
|
|
835
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
836
|
+
* @returns A new instance of the related model with pivot attributes attached.
|
|
837
|
+
*/
|
|
838
|
+
save(related: TRelated, pivotAttributes?: Record<string, unknown>): Promise<TRelated>;
|
|
839
|
+
/**
|
|
840
|
+
* Attaches one or more related model records to the parent model by creating pivot
|
|
841
|
+
* records with the given pivot attributes if pivot attributes should be included.
|
|
842
|
+
*
|
|
843
|
+
* @param related The related model instance(s) to attach.
|
|
844
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
845
|
+
* @returns The number of related model records attached.
|
|
846
|
+
*/
|
|
847
|
+
attach(related: TRelated | unknown | Array<TRelated | unknown>, pivotAttributes?: Record<string, unknown>): Promise<number>;
|
|
848
|
+
/**
|
|
849
|
+
* Detaches one or more related model records from the parent model by deleting
|
|
850
|
+
* matching pivot rows. When no related value is provided, all matching pivot rows
|
|
851
|
+
* for the parent are removed.
|
|
852
|
+
*
|
|
853
|
+
* @param related
|
|
854
|
+
* @returns
|
|
855
|
+
*/
|
|
856
|
+
detach(related?: TRelated | unknown | Array<TRelated | unknown>): Promise<number>;
|
|
857
|
+
/**
|
|
858
|
+
* Synchronizes the pivot table so only the provided related values remain attached.
|
|
859
|
+
* Existing matching rows can receive updated pivot attributes during the operation.
|
|
860
|
+
*
|
|
861
|
+
* @param related
|
|
862
|
+
* @param pivotAttributes
|
|
863
|
+
* @returns
|
|
864
|
+
*/
|
|
865
|
+
sync(related: TRelated | unknown | Array<TRelated | unknown> | Record<string, Record<string, unknown>>, pivotAttributes?: Record<string, unknown>): Promise<{
|
|
866
|
+
attached: number;
|
|
867
|
+
detached: number;
|
|
868
|
+
updated: number;
|
|
869
|
+
}>;
|
|
794
870
|
private shouldAttachPivotAttributes;
|
|
795
871
|
private getPivotColumnSelection;
|
|
796
872
|
/**
|
|
@@ -1343,7 +1419,7 @@ declare abstract class Model<TSchema extends PrismaDelegateLike | Record<string,
|
|
|
1343
1419
|
* @param this
|
|
1344
1420
|
* @returns
|
|
1345
1421
|
*/
|
|
1346
|
-
static query<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any
|
|
1422
|
+
static query<TThis extends abstract new (attributes?: Record<string, unknown>) => unknown, TModel extends Model<any, any> = InstanceType<TThis> & Model<any, any>, TDelegate extends PrismaDelegateLike = DelegateForModelSchema<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis): QueryBuilder<TModel, TDelegate>;
|
|
1347
1423
|
/**
|
|
1348
1424
|
* Boot hook for subclasses to register scopes or perform one-time setup.
|
|
1349
1425
|
*/
|
|
@@ -1358,14 +1434,14 @@ declare abstract class Model<TSchema extends PrismaDelegateLike | Record<string,
|
|
|
1358
1434
|
* @param this
|
|
1359
1435
|
* @returns
|
|
1360
1436
|
*/
|
|
1361
|
-
static withTrashed<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any
|
|
1437
|
+
static withTrashed<TThis extends abstract new (attributes?: Record<string, unknown>) => unknown, TModel extends Model<any, any> = InstanceType<TThis> & Model<any, any>, TDelegate extends PrismaDelegateLike = DelegateForModelSchema<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis): QueryBuilder<TModel, TDelegate>;
|
|
1362
1438
|
/**
|
|
1363
1439
|
* Get a query builder instance that only includes soft-deleted records.
|
|
1364
1440
|
*
|
|
1365
1441
|
* @param this
|
|
1366
1442
|
* @returns
|
|
1367
1443
|
*/
|
|
1368
|
-
static onlyTrashed<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any
|
|
1444
|
+
static onlyTrashed<TThis extends abstract new (attributes?: Record<string, unknown>) => unknown, TModel extends Model<any, any> = InstanceType<TThis> & Model<any, any>, TDelegate extends PrismaDelegateLike = DelegateForModelSchema<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis): QueryBuilder<TModel, TDelegate>;
|
|
1369
1445
|
/**
|
|
1370
1446
|
* Get a query builder instance that excludes soft-deleted records.
|
|
1371
1447
|
* This is the default behavior of the query builder, but this method can be used
|
|
@@ -1376,7 +1452,7 @@ declare abstract class Model<TSchema extends PrismaDelegateLike | Record<string,
|
|
|
1376
1452
|
* @param args
|
|
1377
1453
|
* @returns
|
|
1378
1454
|
*/
|
|
1379
|
-
static scope<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any
|
|
1455
|
+
static scope<TThis extends abstract new (attributes?: Record<string, unknown>) => unknown, TModel extends Model<any, any> = InstanceType<TThis> & Model<any, any>, TDelegate extends PrismaDelegateLike = DelegateForModelSchema<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis, name: string, ...args: unknown[]): QueryBuilder<TModel, TDelegate>;
|
|
1380
1456
|
/**
|
|
1381
1457
|
* Get the soft delete configuration for the model, including whether
|
|
1382
1458
|
* soft deletes are enabled and the name of the deleted at column.
|
|
@@ -1431,9 +1507,7 @@ declare abstract class Model<TSchema extends PrismaDelegateLike | Record<string,
|
|
|
1431
1507
|
* @param key
|
|
1432
1508
|
* @returns
|
|
1433
1509
|
*/
|
|
1434
|
-
getAttribute<TKey extends
|
|
1435
|
-
getAttribute<TKey extends keyof this & string>(key: TKey): this[TKey] extends ((...args: any[]) => any) ? unknown : this[TKey];
|
|
1436
|
-
getAttribute<TKey extends keyof TAttributes & string>(key: TKey): TAttributes[TKey];
|
|
1510
|
+
getAttribute<TSelf extends this, TKey extends string>(this: TSelf, key: TKey): ModelAttributeValue<TSelf, TAttributes, TKey>;
|
|
1437
1511
|
getAttribute(key: string): unknown;
|
|
1438
1512
|
/**
|
|
1439
1513
|
* Set the value of an attribute, applying any set mutators or casts if defined.
|
|
@@ -1442,9 +1516,7 @@ declare abstract class Model<TSchema extends PrismaDelegateLike | Record<string,
|
|
|
1442
1516
|
* @param value
|
|
1443
1517
|
* @returns
|
|
1444
1518
|
*/
|
|
1445
|
-
setAttribute<TKey extends
|
|
1446
|
-
setAttribute<TKey extends keyof this & string>(key: TKey, value: this[TKey] extends ((...args: any[]) => any) ? never : this[TKey]): this;
|
|
1447
|
-
setAttribute<TKey extends keyof TAttributes & string>(key: TKey, value: TAttributes[TKey]): this;
|
|
1519
|
+
setAttribute<TSelf extends this, TKey extends string>(this: TSelf, key: TKey, value: ModelAttributeValue<TSelf, TAttributes, TKey>): this;
|
|
1448
1520
|
setAttribute(key: string, value: unknown): this;
|
|
1449
1521
|
/**
|
|
1450
1522
|
* Save the model to the database.
|
|
@@ -1869,11 +1941,14 @@ interface AttributeSchemaDelegate<TAttributes extends Record<string, unknown>> e
|
|
|
1869
1941
|
type DelegateForModelSchema<TSchema extends PrismaDelegateLike | Record<string, unknown> | string, TAttributes extends Record<string, unknown> = ModelAttributesOf<TSchema>> = TSchema extends PrismaDelegateLike ? TSchema : TSchema extends string ? DelegateFromPrismaClient<TSchema> extends PrismaDelegateLike ? DelegateFromPrismaClient<TSchema> : PrismaDelegateLike : AttributeSchemaDelegate<TAttributes>;
|
|
1870
1942
|
type ModelAttributesOf<TSchema extends PrismaDelegateLike | Record<string, unknown> | string> = TSchema extends PrismaDelegateLike ? DelegateRow<TSchema> extends Record<string, unknown> ? DelegateRow<TSchema> : Record<string, any> : TSchema extends string ? DelegateFromPrismaClient<TSchema> extends PrismaDelegateLike ? DelegateRow<DelegateFromPrismaClient<TSchema>> extends Record<string, unknown> ? DelegateRow<DelegateFromPrismaClient<TSchema>> : Record<string, any> : Record<string, any> : TSchema extends Record<string, unknown> ? TSchema : Record<string, any>;
|
|
1871
1943
|
type ModelAttributes<TModel> = TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>;
|
|
1944
|
+
type BaseModelInstance = Model<any, any>;
|
|
1945
|
+
type ModelDeclaredAttributeKey<TModel> = { [TKey in keyof TModel & string]: TKey extends keyof BaseModelInstance ? never : TModel[TKey] extends ((...args: any[]) => any) ? never : TKey }[keyof TModel & string];
|
|
1872
1946
|
type RelationshipResultProvider<TResult = unknown> = {
|
|
1873
1947
|
getResults: (...args: any[]) => Promise<TResult>;
|
|
1874
1948
|
};
|
|
1875
|
-
type ModelRelationshipKey<TModel> = { [TKey in keyof TModel & string]: TModel[TKey] extends ((...args: any[]) => infer TReturn) ? TReturn extends RelationshipResultProvider<any> ? TKey : never : never }[keyof TModel & string];
|
|
1949
|
+
type ModelRelationshipKey<TModel> = { [TKey in keyof TModel & string]: TKey extends keyof BaseModelInstance ? never : TModel[TKey] extends ((...args: any[]) => infer TReturn) ? Parameters<TModel[TKey]> extends [] ? TReturn extends RelationshipResultProvider<any> ? TKey : never : never : never }[keyof TModel & string];
|
|
1876
1950
|
type ModelRelationshipResult<TModel, TKey extends ModelRelationshipKey<TModel>> = TModel[TKey] extends ((...args: any[]) => infer TReturn) ? TReturn extends RelationshipResultProvider<infer TResult> ? TResult : never : never;
|
|
1951
|
+
type ModelAttributeValue<TModel, TAttributes extends Record<string, unknown>, TKey extends string> = TKey extends ModelRelationshipKey<TModel> ? ModelRelationshipResult<TModel, TKey> : TKey extends ModelDeclaredAttributeKey<TModel> ? TModel[TKey] : TKey extends keyof TAttributes & string ? TAttributes[TKey] : unknown;
|
|
1877
1952
|
type ModelCreateData<TModel, TDelegate extends PrismaDelegateLike> = TModel extends Model<any, infer TAttributes> ? TDelegate extends AttributeSchemaDelegate<TAttributes> ? AttributeCreateInput<TAttributes> : DelegateCreateData<TDelegate> : DelegateCreateData<TDelegate>;
|
|
1878
1953
|
type ModelUpdateData<TModel, TDelegate extends PrismaDelegateLike> = TModel extends Model<any, infer TAttributes> ? TDelegate extends AttributeSchemaDelegate<TAttributes> ? AttributeUpdateInput<TAttributes> : DelegateUpdateData<TDelegate> : DelegateUpdateData<TDelegate>;
|
|
1879
1954
|
type RelatedModelClass<TInstance = unknown> = (abstract new (attributes?: Record<string, unknown>) => TInstance) & RelationshipModelStatic;
|
|
@@ -4983,4 +5058,4 @@ declare class URLDriver {
|
|
|
4983
5058
|
url(page: number): string;
|
|
4984
5059
|
}
|
|
4985
5060
|
//#endregion
|
|
4986
|
-
export { AdapterBindableModel, AdapterCapabilities, AdapterCapability, AdapterInspectionRequest, AdapterModelFieldStructure, AdapterModelIntrospectionOptions, AdapterModelStructure, AdapterQueryInspection, AdapterQueryOperation, AdapterTransactionContext, AggregateOperation, AggregateSelection, AggregateSpec, AppliedMigrationEntry, AppliedMigrationRun, AppliedMigrationsState, ArkormBootContext, ArkormCollection, ArkormConfig, ArkormDebugEvent, ArkormDebugHandler, ArkormErrorContext, ArkormException, Attribute, AttributeCreateInput, AttributeOptions, AttributeOrderBy, AttributeSchemaDelegate, AttributeSelect, AttributeUpdateInput, AttributeWhereInput, BelongsToManyRelationMetadata, BelongsToRelationMetadata, CastDefinition, CastHandler, CastMap, CastType, CliApp, ClientResolver, ColumnMap, DB, DatabaseAdapter, DatabasePrimitive, DatabaseRow, DatabaseRows, DatabaseTableOptions, DatabaseTablePersistedMetadataOptions, DatabaseValue, DelegateCreateData, DelegateFindManyArgs, DelegateForModelSchema, DelegateInclude, DelegateOrderBy, DelegateRow, DelegateRows, DelegateSelect, DelegateUniqueWhere, DelegateUpdateArgs, DelegateUpdateData, DelegateWhere, DeleteManySpec, DeleteSpec, EagerLoadConstraint, EagerLoadMap, EnumBuilder, FactoryAttributes, FactoryDefinition, FactoryModelConstructor, FactoryState, ForeignKeyBuilder, GenerateMigrationOptions, GeneratedMigrationFile, GetUserConfig, GlobalScope, HasManyRelationMetadata, HasManyThroughRelationMetadata, HasOneRelationMetadata, HasOneThroughRelationMetadata, InitCommand, InlineFactory, InsertManySpec, InsertSpec, KyselyDatabaseAdapter, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateFreshCommand, MigrateRollbackCommand, Migration, MigrationClass, MigrationHistoryCommand, MigrationInstanceLike, MissingDelegateException, Model, ModelAttributes, ModelAttributesOf, ModelCreateData, ModelEventDispatcher, ModelEventHandler, ModelEventHandlerConstructor, ModelEventListener, ModelEventName, ModelFactory, ModelLifecycleState, ModelMetadata, ModelNotFoundException, ModelRelationshipKey, ModelRelationshipResult, ModelStatic, ModelUpdateData, ModelsSyncCommand, MorphManyRelationMetadata, MorphOneRelationMetadata, MorphToManyRelationMetadata, PRISMA_ENUM_MEMBER_REGEX, PRISMA_ENUM_REGEX, PRISMA_MODEL_REGEX, PaginationCurrentPageResolver, PaginationMeta, PaginationOptions, PaginationURLDriver, PaginationURLDriverFactory, Paginator, PersistedColumnMappingsState, PersistedMetadataFeatures, PersistedPrimaryKeyGeneration, PersistedTableMetadata, PersistedTimestampColumn, PivotModel, PivotModelStatic, PrimaryKeyGeneration, PrimaryKeyGenerationPlanner, PrismaClientLike, PrismaDatabaseAdapter, PrismaDelegateLike, PrismaDelegateMap, PrismaDelegateNameMapping, PrismaFindManyArgsLike, PrismaLikeInclude, PrismaLikeOrderBy, PrismaLikeScalarFilter, PrismaLikeSelect, PrismaLikeSortOrder, PrismaLikeWhereInput, PrismaMigrationWorkflowOptions, PrismaSchemaSyncOptions, PrismaTransactionCallback, PrismaTransactionCapableClient, PrismaTransactionOptions, QueryBuilder, QueryComparisonCondition, QueryComparisonOperator, QueryCondition, QueryConstraintException, QueryExecutionException, QueryExecutionExceptionContext, QueryGroupCondition, QueryLogicalOperator, QueryNotCondition, QueryOrderBy, QueryRawCondition, QuerySelectColumn, QueryTarget, RelatedModelClass, RelationAggregateSpec, RelationColumnLookupSpec, RelationConstraint, RelationDefaultResolver, RelationDefaultValue, RelationFilterSpec, RelationLoadPlan, RelationLoadSpec, RelationMetadata, RelationMetadataProvider, RelationMetadataType, RelationResolutionException, RelationTableLookupSpec, RelationshipModelStatic, RuntimeModuleLoader, SEEDER_BRAND, SchemaBuilder, SchemaColumn, SchemaColumnType, SchemaForeignKey, SchemaForeignKeyAction, SchemaIndex, SchemaOperation, SchemaTableAlterOperation, SchemaTableCreateOperation, SchemaTableDropOperation, ScopeNotDefinedException, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, SelectSpec, Serializable, SimplePaginationMeta, SoftDeleteConfig, SoftDeleteQueryMode, SortDirection, TableBuilder, TimestampColumnBehavior, URLDriver, UniqueConstraintResolutionException, UnsupportedAdapterFeatureException, UpdateManySpec, UpdateSpec, UpsertSpec, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToDatabase, applyMigrationRollbackToPrismaSchema, applyMigrationToDatabase, applyMigrationToPrismaSchema, applyOperationsToPersistedColumnMappingsState, applyOperationsToPrismaSchema, bindAdapterToModels, buildEnumBlock, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createEmptyAppliedMigrationsState, createEmptyPersistedColumnMappingsState, createKyselyAdapter, createMigrationTimestamp, createPrismaAdapter, createPrismaCompatibilityAdapter, createPrismaDatabaseAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deleteAppliedMigrationsStateFromStore, deletePersistedColumnMappingsState, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationAlias, deriveRelationFieldName, deriveSingularFieldName, emitRuntimeDebugEvent, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findEnumBlock, findModelBlock, formatDefaultValue, formatEnumDefaultValue, formatRelationAction, generateMigrationFile, getActiveTransactionClient, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getPersistedColumnMap, getPersistedEnumMap, getPersistedEnumTsType, getPersistedPrimaryKeyGeneration, getPersistedTableMetadata, getPersistedTimestampColumns, getRuntimeAdapter, getRuntimeDebugHandler, getRuntimePaginationCurrentPageResolver, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, isTransactionCapableClient, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, readAppliedMigrationsStateFromStore, readPersistedColumnMappingsState, rebuildPersistedColumnMappingsState, removeAppliedMigration, resetArkormRuntimeForTests, resetPersistedColumnMappingsCache, resolveCast, resolveColumnMappingsFilePath, resolveEnumName, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePersistedMetadataFeatures, resolvePrismaType, runArkormTransaction, runMigrationWithPrisma, runPrismaCommand, stripPrismaSchemaModelsAndEnums, supportsDatabaseMigrationExecution, supportsDatabaseMigrationState, supportsDatabaseReset, syncPersistedColumnMappingsFromState, toMigrationFileSlug, toModelName, validatePersistedMetadataFeaturesForMigrations, writeAppliedMigrationsState, writeAppliedMigrationsStateToStore, writePersistedColumnMappingsState };
|
|
5061
|
+
export { AdapterBindableModel, AdapterCapabilities, AdapterCapability, AdapterInspectionRequest, AdapterModelFieldStructure, AdapterModelIntrospectionOptions, AdapterModelStructure, AdapterQueryInspection, AdapterQueryOperation, AdapterTransactionContext, AggregateOperation, AggregateSelection, AggregateSpec, AppliedMigrationEntry, AppliedMigrationRun, AppliedMigrationsState, ArkormBootContext, ArkormCollection, ArkormConfig, ArkormDebugEvent, ArkormDebugHandler, ArkormErrorContext, ArkormException, Attribute, AttributeCreateInput, AttributeOptions, AttributeOrderBy, AttributeSchemaDelegate, AttributeSelect, AttributeUpdateInput, AttributeWhereInput, BelongsToManyRelationMetadata, BelongsToRelationMetadata, CastDefinition, CastHandler, CastMap, CastType, CliApp, ClientResolver, ColumnMap, DB, DatabaseAdapter, DatabasePrimitive, DatabaseRow, DatabaseRows, DatabaseTableOptions, DatabaseTablePersistedMetadataOptions, DatabaseValue, DelegateCreateData, DelegateFindManyArgs, DelegateForModelSchema, DelegateInclude, DelegateOrderBy, DelegateRow, DelegateRows, DelegateSelect, DelegateUniqueWhere, DelegateUpdateArgs, DelegateUpdateData, DelegateWhere, DeleteManySpec, DeleteSpec, EagerLoadConstraint, EagerLoadMap, EnumBuilder, FactoryAttributes, FactoryDefinition, FactoryModelConstructor, FactoryState, ForeignKeyBuilder, GenerateMigrationOptions, GeneratedMigrationFile, GetUserConfig, GlobalScope, HasManyRelationMetadata, HasManyThroughRelationMetadata, HasOneRelationMetadata, HasOneThroughRelationMetadata, InitCommand, InlineFactory, InsertManySpec, InsertSpec, KyselyDatabaseAdapter, LengthAwarePaginator, MIGRATION_BRAND, MakeFactoryCommand, MakeMigrationCommand, MakeModelCommand, MakeSeederCommand, MigrateCommand, MigrateFreshCommand, MigrateRollbackCommand, Migration, MigrationClass, MigrationHistoryCommand, MigrationInstanceLike, MissingDelegateException, Model, ModelAttributeValue, ModelAttributes, ModelAttributesOf, ModelCreateData, ModelDeclaredAttributeKey, ModelEventDispatcher, ModelEventHandler, ModelEventHandlerConstructor, ModelEventListener, ModelEventName, ModelFactory, ModelLifecycleState, ModelMetadata, ModelNotFoundException, ModelRelationshipKey, ModelRelationshipResult, ModelStatic, ModelUpdateData, ModelsSyncCommand, MorphManyRelationMetadata, MorphOneRelationMetadata, MorphToManyRelationMetadata, PRISMA_ENUM_MEMBER_REGEX, PRISMA_ENUM_REGEX, PRISMA_MODEL_REGEX, PaginationCurrentPageResolver, PaginationMeta, PaginationOptions, PaginationURLDriver, PaginationURLDriverFactory, Paginator, PersistedColumnMappingsState, PersistedMetadataFeatures, PersistedPrimaryKeyGeneration, PersistedTableMetadata, PersistedTimestampColumn, PivotModel, PivotModelStatic, PrimaryKeyGeneration, PrimaryKeyGenerationPlanner, PrismaClientLike, PrismaDatabaseAdapter, PrismaDelegateLike, PrismaDelegateMap, PrismaDelegateNameMapping, PrismaFindManyArgsLike, PrismaLikeInclude, PrismaLikeOrderBy, PrismaLikeScalarFilter, PrismaLikeSelect, PrismaLikeSortOrder, PrismaLikeWhereInput, PrismaMigrationWorkflowOptions, PrismaSchemaSyncOptions, PrismaTransactionCallback, PrismaTransactionCapableClient, PrismaTransactionOptions, QueryBuilder, QueryComparisonCondition, QueryComparisonOperator, QueryCondition, QueryConstraintException, QueryExecutionException, QueryExecutionExceptionContext, QueryGroupCondition, QueryLogicalOperator, QueryNotCondition, QueryOrderBy, QueryRawCondition, QuerySelectColumn, QueryTarget, RelatedModelClass, RelationAggregateSpec, RelationColumnLookupSpec, RelationConstraint, RelationDefaultResolver, RelationDefaultValue, RelationFilterSpec, RelationLoadPlan, RelationLoadSpec, RelationMetadata, RelationMetadataProvider, RelationMetadataType, RelationResolutionException, RelationTableLookupSpec, RelationshipModelStatic, RuntimeModuleLoader, SEEDER_BRAND, SchemaBuilder, SchemaColumn, SchemaColumnType, SchemaForeignKey, SchemaForeignKeyAction, SchemaIndex, SchemaOperation, SchemaTableAlterOperation, SchemaTableCreateOperation, SchemaTableDropOperation, ScopeNotDefinedException, SeedCommand, Seeder, SeederCallArgument, SeederConstructor, SeederInput, SelectSpec, Serializable, SimplePaginationMeta, SoftDeleteConfig, SoftDeleteQueryMode, SortDirection, TableBuilder, TimestampColumnBehavior, URLDriver, UniqueConstraintResolutionException, UnsupportedAdapterFeatureException, UpdateManySpec, UpdateSpec, UpsertSpec, applyAlterTableOperation, applyCreateTableOperation, applyDropTableOperation, applyMigrationRollbackToDatabase, applyMigrationRollbackToPrismaSchema, applyMigrationToDatabase, applyMigrationToPrismaSchema, applyOperationsToPersistedColumnMappingsState, applyOperationsToPrismaSchema, bindAdapterToModels, buildEnumBlock, buildFieldLine, buildIndexLine, buildInverseRelationLine, buildMigrationIdentity, buildMigrationRunId, buildMigrationSource, buildModelBlock, buildRelationLine, computeMigrationChecksum, configureArkormRuntime, createEmptyAppliedMigrationsState, createEmptyPersistedColumnMappingsState, createKyselyAdapter, createMigrationTimestamp, createPrismaAdapter, createPrismaCompatibilityAdapter, createPrismaDatabaseAdapter, createPrismaDelegateMap, defineConfig, defineFactory, deleteAppliedMigrationsStateFromStore, deletePersistedColumnMappingsState, deriveCollectionFieldName, deriveInverseRelationAlias, deriveRelationAlias, deriveRelationFieldName, deriveSingularFieldName, emitRuntimeDebugEvent, ensureArkormConfigLoading, escapeRegex, findAppliedMigration, findEnumBlock, findModelBlock, formatDefaultValue, formatEnumDefaultValue, formatRelationAction, generateMigrationFile, getActiveTransactionClient, getDefaultStubsPath, getLastMigrationRun, getLatestAppliedMigrations, getMigrationPlan, getPersistedColumnMap, getPersistedEnumMap, getPersistedEnumTsType, getPersistedPrimaryKeyGeneration, getPersistedTableMetadata, getPersistedTimestampColumns, getRuntimeAdapter, getRuntimeDebugHandler, getRuntimePaginationCurrentPageResolver, getRuntimePaginationURLDriverFactory, getRuntimePrismaClient, getUserConfig, inferDelegateName, isDelegateLike, isMigrationApplied, isTransactionCapableClient, loadArkormConfig, markMigrationApplied, markMigrationRun, pad, readAppliedMigrationsState, readAppliedMigrationsStateFromStore, readPersistedColumnMappingsState, rebuildPersistedColumnMappingsState, removeAppliedMigration, resetArkormRuntimeForTests, resetPersistedColumnMappingsCache, resolveCast, resolveColumnMappingsFilePath, resolveEnumName, resolveMigrationClassName, resolveMigrationStateFilePath, resolvePersistedMetadataFeatures, resolvePrismaType, runArkormTransaction, runMigrationWithPrisma, runPrismaCommand, stripPrismaSchemaModelsAndEnums, supportsDatabaseMigrationExecution, supportsDatabaseMigrationState, supportsDatabaseReset, syncPersistedColumnMappingsFromState, toMigrationFileSlug, toModelName, validatePersistedMetadataFeaturesForMigrations, writeAppliedMigrationsState, writeAppliedMigrationsStateToStore, writePersistedColumnMappingsState };
|
package/dist/index.mjs
CHANGED
|
@@ -9125,6 +9125,277 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
9125
9125
|
conditions: [baseCondition, this.pivotWhere]
|
|
9126
9126
|
};
|
|
9127
9127
|
}
|
|
9128
|
+
buildPivotTarget() {
|
|
9129
|
+
return {
|
|
9130
|
+
table: this.throughDelegate,
|
|
9131
|
+
primaryKey: this.relatedPivotKey
|
|
9132
|
+
};
|
|
9133
|
+
}
|
|
9134
|
+
buildRelatedPivotCondition(relatedValues) {
|
|
9135
|
+
const normalizedValues = relatedValues.filter((value) => value != null);
|
|
9136
|
+
if (normalizedValues.length === 0) return null;
|
|
9137
|
+
if (normalizedValues.length === 1) return {
|
|
9138
|
+
type: "comparison",
|
|
9139
|
+
column: this.relatedPivotKey,
|
|
9140
|
+
operator: "=",
|
|
9141
|
+
value: normalizedValues[0]
|
|
9142
|
+
};
|
|
9143
|
+
return {
|
|
9144
|
+
type: "comparison",
|
|
9145
|
+
column: this.relatedPivotKey,
|
|
9146
|
+
operator: "in",
|
|
9147
|
+
value: normalizedValues
|
|
9148
|
+
};
|
|
9149
|
+
}
|
|
9150
|
+
buildPivotMutationWhere(relatedValues = []) {
|
|
9151
|
+
const baseCondition = this.buildPivotWhere(this.resolveParentPivotValue());
|
|
9152
|
+
const relatedCondition = this.buildRelatedPivotCondition(relatedValues);
|
|
9153
|
+
if (!relatedCondition) return baseCondition;
|
|
9154
|
+
return {
|
|
9155
|
+
type: "group",
|
|
9156
|
+
operator: "and",
|
|
9157
|
+
conditions: [baseCondition, relatedCondition]
|
|
9158
|
+
};
|
|
9159
|
+
}
|
|
9160
|
+
normalizeIdentifierValue(value) {
|
|
9161
|
+
if (typeof value === "string" && /^-?\d+$/.test(value)) return Number(value);
|
|
9162
|
+
return value;
|
|
9163
|
+
}
|
|
9164
|
+
isPlainObject(value) {
|
|
9165
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) && !(value instanceof Date);
|
|
9166
|
+
}
|
|
9167
|
+
isModelLike(value) {
|
|
9168
|
+
return this.isPlainObject(value) && typeof value.getAttribute === "function";
|
|
9169
|
+
}
|
|
9170
|
+
normalizeRelatedItems(related) {
|
|
9171
|
+
return Array.isArray(related) ? related : [related];
|
|
9172
|
+
}
|
|
9173
|
+
normalizeSyncEntries(related, pivotAttributes = {}) {
|
|
9174
|
+
if (Array.isArray(related)) return related.map((item) => ({
|
|
9175
|
+
related: item,
|
|
9176
|
+
attributes: { ...pivotAttributes }
|
|
9177
|
+
}));
|
|
9178
|
+
if (this.isPlainObject(related) && !this.isModelLike(related)) return Object.entries(related).map(([key, attributes]) => ({
|
|
9179
|
+
related: this.normalizeIdentifierValue(key),
|
|
9180
|
+
attributes: this.isPlainObject(attributes) ? attributes : {}
|
|
9181
|
+
}));
|
|
9182
|
+
return [{
|
|
9183
|
+
related,
|
|
9184
|
+
attributes: { ...pivotAttributes }
|
|
9185
|
+
}];
|
|
9186
|
+
}
|
|
9187
|
+
resolveParentPivotValue() {
|
|
9188
|
+
return this.parent.getAttribute(this.parentKey);
|
|
9189
|
+
}
|
|
9190
|
+
resolveRelatedPivotValue(related) {
|
|
9191
|
+
if (related && typeof related === "object" && "getAttribute" in related) return related.getAttribute(this.relatedKey);
|
|
9192
|
+
return related;
|
|
9193
|
+
}
|
|
9194
|
+
buildPivotInsertValues(related, attributes = {}) {
|
|
9195
|
+
const values = {
|
|
9196
|
+
...attributes,
|
|
9197
|
+
[this.foreignPivotKey]: this.resolveParentPivotValue(),
|
|
9198
|
+
[this.relatedPivotKey]: this.resolveRelatedPivotValue(related)
|
|
9199
|
+
};
|
|
9200
|
+
if (this.pivotCreatedAtColumn && !(this.pivotCreatedAtColumn in values)) values[this.pivotCreatedAtColumn] = /* @__PURE__ */ new Date();
|
|
9201
|
+
if (this.pivotUpdatedAtColumn && !(this.pivotUpdatedAtColumn in values)) values[this.pivotUpdatedAtColumn] = /* @__PURE__ */ new Date();
|
|
9202
|
+
return values;
|
|
9203
|
+
}
|
|
9204
|
+
attachPivotToSingleResult(related, pivotRow) {
|
|
9205
|
+
if (!this.shouldAttachPivotAttributes()) return related;
|
|
9206
|
+
related.setAttribute(this.pivotAccessor, this.createPivotRecord(pivotRow));
|
|
9207
|
+
return related;
|
|
9208
|
+
}
|
|
9209
|
+
async insertPivotRow(values, adapter = this.getRelationAdapter()) {
|
|
9210
|
+
await adapter.insert({
|
|
9211
|
+
target: this.buildPivotTarget(),
|
|
9212
|
+
values
|
|
9213
|
+
});
|
|
9214
|
+
}
|
|
9215
|
+
async selectPivotRows(where, adapter = this.getRelationAdapter()) {
|
|
9216
|
+
return await adapter.select({
|
|
9217
|
+
target: this.buildPivotTarget(),
|
|
9218
|
+
where
|
|
9219
|
+
});
|
|
9220
|
+
}
|
|
9221
|
+
async deletePivotRows(where, adapter = this.getRelationAdapter()) {
|
|
9222
|
+
if (typeof adapter.deleteMany === "function") return await adapter.deleteMany({
|
|
9223
|
+
target: this.buildPivotTarget(),
|
|
9224
|
+
where
|
|
9225
|
+
});
|
|
9226
|
+
const rows = await this.selectPivotRows(where, adapter);
|
|
9227
|
+
await Promise.all(rows.map(async (row) => {
|
|
9228
|
+
await adapter.delete({
|
|
9229
|
+
target: this.buildPivotTarget(),
|
|
9230
|
+
where: {
|
|
9231
|
+
type: "group",
|
|
9232
|
+
operator: "and",
|
|
9233
|
+
conditions: Object.entries(row).map(([column, value]) => ({
|
|
9234
|
+
type: "comparison",
|
|
9235
|
+
column,
|
|
9236
|
+
operator: "=",
|
|
9237
|
+
value
|
|
9238
|
+
}))
|
|
9239
|
+
}
|
|
9240
|
+
});
|
|
9241
|
+
}));
|
|
9242
|
+
return rows.length;
|
|
9243
|
+
}
|
|
9244
|
+
buildPivotUpdateValues(attributes = {}) {
|
|
9245
|
+
const values = { ...attributes };
|
|
9246
|
+
if (this.pivotUpdatedAtColumn && !(this.pivotUpdatedAtColumn in values)) values[this.pivotUpdatedAtColumn] = /* @__PURE__ */ new Date();
|
|
9247
|
+
return values;
|
|
9248
|
+
}
|
|
9249
|
+
async updatePivotRows(related, attributes, adapter = this.getRelationAdapter()) {
|
|
9250
|
+
const values = this.buildPivotUpdateValues(attributes);
|
|
9251
|
+
if (Object.keys(values).length === 0) return 0;
|
|
9252
|
+
const where = this.buildPivotMutationWhere([this.resolveRelatedPivotValue(related)]);
|
|
9253
|
+
if (typeof adapter.updateMany === "function") return await adapter.updateMany({
|
|
9254
|
+
target: this.buildPivotTarget(),
|
|
9255
|
+
where,
|
|
9256
|
+
values
|
|
9257
|
+
});
|
|
9258
|
+
const rows = await this.selectPivotRows(where, adapter);
|
|
9259
|
+
await Promise.all(rows.map(async (row) => {
|
|
9260
|
+
await adapter.update({
|
|
9261
|
+
target: this.buildPivotTarget(),
|
|
9262
|
+
where: {
|
|
9263
|
+
type: "group",
|
|
9264
|
+
operator: "and",
|
|
9265
|
+
conditions: Object.entries(row).map(([column, value]) => ({
|
|
9266
|
+
type: "comparison",
|
|
9267
|
+
column,
|
|
9268
|
+
operator: "=",
|
|
9269
|
+
value
|
|
9270
|
+
}))
|
|
9271
|
+
},
|
|
9272
|
+
values
|
|
9273
|
+
});
|
|
9274
|
+
}));
|
|
9275
|
+
return rows.length;
|
|
9276
|
+
}
|
|
9277
|
+
/**
|
|
9278
|
+
* Creates a new instance of the related model with the given attributes and attaches
|
|
9279
|
+
* pivot attributes if pivot attributes should be included.
|
|
9280
|
+
*
|
|
9281
|
+
* @param attributes The attributes to initialize the related model with.
|
|
9282
|
+
* @returns A new instance of the related model.
|
|
9283
|
+
*/
|
|
9284
|
+
make(attributes = {}) {
|
|
9285
|
+
return this.related.hydrate(attributes);
|
|
9286
|
+
}
|
|
9287
|
+
/**
|
|
9288
|
+
* Creates a new related model record with the given attributes, creates a pivot record
|
|
9289
|
+
* with the given pivot attributes, and attaches pivot attributes if pivot attributes
|
|
9290
|
+
* should be included.
|
|
9291
|
+
*
|
|
9292
|
+
* @param attributes The attributes to initialize the related model with.
|
|
9293
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
9294
|
+
* @returns A new instance of the related model with pivot attributes attached.
|
|
9295
|
+
*/
|
|
9296
|
+
async create(attributes = {}, pivotAttributes = {}) {
|
|
9297
|
+
const related = await this.related.query().create(attributes);
|
|
9298
|
+
const pivotRow = this.buildPivotInsertValues(related, pivotAttributes);
|
|
9299
|
+
await this.insertPivotRow(pivotRow);
|
|
9300
|
+
return this.attachPivotToSingleResult(related, pivotRow);
|
|
9301
|
+
}
|
|
9302
|
+
/**
|
|
9303
|
+
* Saves a related model record, creates a pivot record with the given pivot attributes
|
|
9304
|
+
* if the related model was not previously persisted, and attaches pivot attributes if
|
|
9305
|
+
* pivot attributes should be included.
|
|
9306
|
+
*
|
|
9307
|
+
* @param related The related model instance to save.
|
|
9308
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
9309
|
+
* @returns A new instance of the related model with pivot attributes attached.
|
|
9310
|
+
*/
|
|
9311
|
+
async save(related, pivotAttributes = {}) {
|
|
9312
|
+
const saveable = related;
|
|
9313
|
+
let persisted = related;
|
|
9314
|
+
if (typeof saveable.save === "function") try {
|
|
9315
|
+
persisted = await saveable.save();
|
|
9316
|
+
} catch (error) {
|
|
9317
|
+
if (!(typeof error === "object" && error !== null && "code" in error && error.code === "MODEL_NOT_FOUND")) throw error;
|
|
9318
|
+
const attributes = typeof saveable.getRawAttributes === "function" ? saveable.getRawAttributes() : {};
|
|
9319
|
+
persisted = await this.related.query().create(attributes);
|
|
9320
|
+
}
|
|
9321
|
+
const pivotRow = this.buildPivotInsertValues(persisted, pivotAttributes);
|
|
9322
|
+
await this.insertPivotRow(pivotRow);
|
|
9323
|
+
return this.attachPivotToSingleResult(persisted, pivotRow);
|
|
9324
|
+
}
|
|
9325
|
+
/**
|
|
9326
|
+
* Attaches one or more related model records to the parent model by creating pivot
|
|
9327
|
+
* records with the given pivot attributes if pivot attributes should be included.
|
|
9328
|
+
*
|
|
9329
|
+
* @param related The related model instance(s) to attach.
|
|
9330
|
+
* @param pivotAttributes The attributes to initialize the pivot record with.
|
|
9331
|
+
* @returns The number of related model records attached.
|
|
9332
|
+
*/
|
|
9333
|
+
async attach(related, pivotAttributes = {}) {
|
|
9334
|
+
const items = Array.isArray(related) ? related : [related];
|
|
9335
|
+
await Promise.all(items.map(async (item) => {
|
|
9336
|
+
await this.insertPivotRow(this.buildPivotInsertValues(item, pivotAttributes));
|
|
9337
|
+
}));
|
|
9338
|
+
return items.length;
|
|
9339
|
+
}
|
|
9340
|
+
/**
|
|
9341
|
+
* Detaches one or more related model records from the parent model by deleting
|
|
9342
|
+
* matching pivot rows. When no related value is provided, all matching pivot rows
|
|
9343
|
+
* for the parent are removed.
|
|
9344
|
+
*
|
|
9345
|
+
* @param related
|
|
9346
|
+
* @returns
|
|
9347
|
+
*/
|
|
9348
|
+
async detach(related) {
|
|
9349
|
+
const where = related === void 0 ? this.buildPivotWhere(this.resolveParentPivotValue()) : this.buildPivotMutationWhere(this.normalizeRelatedItems(related).map((item) => this.resolveRelatedPivotValue(item)));
|
|
9350
|
+
return await this.deletePivotRows(where);
|
|
9351
|
+
}
|
|
9352
|
+
/**
|
|
9353
|
+
* Synchronizes the pivot table so only the provided related values remain attached.
|
|
9354
|
+
* Existing matching rows can receive updated pivot attributes during the operation.
|
|
9355
|
+
*
|
|
9356
|
+
* @param related
|
|
9357
|
+
* @param pivotAttributes
|
|
9358
|
+
* @returns
|
|
9359
|
+
*/
|
|
9360
|
+
async sync(related, pivotAttributes = {}) {
|
|
9361
|
+
return await this.getRelationAdapter().transaction(async (transaction) => {
|
|
9362
|
+
const existingRows = await this.selectPivotRows(this.buildPivotWhere(this.resolveParentPivotValue()), transaction);
|
|
9363
|
+
const desiredEntries = /* @__PURE__ */ new Map();
|
|
9364
|
+
this.normalizeSyncEntries(related, pivotAttributes).forEach((entry) => {
|
|
9365
|
+
const relatedValue = this.resolveRelatedPivotValue(entry.related);
|
|
9366
|
+
if (relatedValue == null) return;
|
|
9367
|
+
desiredEntries.set(String(relatedValue), {
|
|
9368
|
+
related: relatedValue,
|
|
9369
|
+
attributes: entry.attributes
|
|
9370
|
+
});
|
|
9371
|
+
});
|
|
9372
|
+
let detached = 0;
|
|
9373
|
+
let attached = 0;
|
|
9374
|
+
let updated = 0;
|
|
9375
|
+
const existingKeys = /* @__PURE__ */ new Set();
|
|
9376
|
+
for (const row of existingRows) {
|
|
9377
|
+
const relatedValue = row[this.relatedPivotKey];
|
|
9378
|
+
if (relatedValue == null) continue;
|
|
9379
|
+
const relatedKey = String(relatedValue);
|
|
9380
|
+
existingKeys.add(relatedKey);
|
|
9381
|
+
if (!desiredEntries.has(relatedKey)) detached += await this.deletePivotRows(this.buildPivotMutationWhere([relatedValue]), transaction);
|
|
9382
|
+
}
|
|
9383
|
+
for (const [relatedKey, entry] of desiredEntries) {
|
|
9384
|
+
if (!existingKeys.has(relatedKey)) {
|
|
9385
|
+
await this.insertPivotRow(this.buildPivotInsertValues(entry.related, entry.attributes), transaction);
|
|
9386
|
+
attached += 1;
|
|
9387
|
+
continue;
|
|
9388
|
+
}
|
|
9389
|
+
if (Object.keys(entry.attributes).length === 0) continue;
|
|
9390
|
+
updated += await this.updatePivotRows(entry.related, entry.attributes, transaction);
|
|
9391
|
+
}
|
|
9392
|
+
return {
|
|
9393
|
+
attached,
|
|
9394
|
+
detached,
|
|
9395
|
+
updated
|
|
9396
|
+
};
|
|
9397
|
+
});
|
|
9398
|
+
}
|
|
9128
9399
|
shouldAttachPivotAttributes() {
|
|
9129
9400
|
return this.shouldAttachPivot || this.pivotColumns.size > 0 || Boolean(this.pivotCreatedAtColumn) || Boolean(this.pivotUpdatedAtColumn) || Boolean(this.pivotModel);
|
|
9130
9401
|
}
|
|
@@ -9210,7 +9481,7 @@ var BelongsToManyRelation = class BelongsToManyRelation extends Relation {
|
|
|
9210
9481
|
return query;
|
|
9211
9482
|
}
|
|
9212
9483
|
async loadPivotRowsForParent() {
|
|
9213
|
-
const parentValue = this.
|
|
9484
|
+
const parentValue = this.resolveParentPivotValue();
|
|
9214
9485
|
return await this.createRelationTableLoader().selectRows({
|
|
9215
9486
|
table: this.throughDelegate,
|
|
9216
9487
|
where: this.buildPivotWhere(parentValue),
|