arkormx 2.7.0 → 2.8.0

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.
@@ -1,7 +1,7 @@
1
- import { Collection } from "@h3ravel/collect.js";
2
1
  import { Kysely, Transaction } from "kysely";
3
- import { Command } from "@h3ravel/musket";
4
2
  import { PrismaClient } from "@prisma/client";
3
+ import { Collection } from "@h3ravel/collect.js";
4
+ import { Command } from "@h3ravel/musket";
5
5
 
6
6
  //#region src/types/migrations.d.ts
7
7
  type SchemaColumnType = 'id' | 'uuid' | 'enum' | 'string' | 'text' | 'integer' | 'bigInteger' | 'float' | 'boolean' | 'json' | 'date' | 'timestamp';
@@ -2083,7 +2083,19 @@ declare abstract class Model<TSchema extends ModelQuerySchemaLike | Record<strin
2083
2083
  protected readonly attributes: Record<string, unknown>;
2084
2084
  protected original: Record<string, unknown>;
2085
2085
  protected changes: Record<string, unknown>;
2086
+ protected previous: Record<string, unknown>;
2086
2087
  protected readonly touchedAttributes: Set<string>;
2088
+ /**
2089
+ * Indicates whether the model corresponds to a row that exists in the
2090
+ * database. Hydrated and freshly inserted models are marked as existing;
2091
+ * models built with `new Model(...)` are not until they are saved.
2092
+ */
2093
+ exists: boolean;
2094
+ /**
2095
+ * Indicates whether the model was inserted during the current lifecycle
2096
+ * (i.e. the last successful save performed a create rather than an update).
2097
+ */
2098
+ wasRecentlyCreated: boolean;
2087
2099
  constructor(attributes?: Record<string, unknown>);
2088
2100
  private static emitDeprecationWarning;
2089
2101
  /**
@@ -2239,6 +2251,48 @@ declare abstract class Model<TSchema extends ModelQuerySchemaLike | Record<strin
2239
2251
  * @returns
2240
2252
  */
2241
2253
  static scope<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any, any>, TModel extends Model<any, any> = InstanceType<TThis>, TDelegate extends ModelQuerySchemaLike = QuerySchemaForModel<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>;
2254
+ /**
2255
+ * Start a query constrained by the given where clause.
2256
+ *
2257
+ * @param this
2258
+ * @param where
2259
+ * @returns
2260
+ */
2261
+ static where<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any, any>, TModel extends Model<any, any> = InstanceType<TThis>, TDelegate extends ModelQuerySchemaLike = QuerySchemaForModel<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis, where: QuerySchemaWhere<TDelegate>): QueryBuilder<TModel, TDelegate>;
2262
+ /**
2263
+ * Retrieve all records for the model.
2264
+ *
2265
+ * @param this
2266
+ * @returns
2267
+ */
2268
+ static all<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any, any>, TModel extends Model<any, any> = InstanceType<TThis>, TDelegate extends ModelQuerySchemaLike = QuerySchemaForModel<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis): Promise<ArkormCollection<TModel>>;
2269
+ /**
2270
+ * Create and persist a new record, returning the hydrated model instance.
2271
+ *
2272
+ * @param this
2273
+ * @param data
2274
+ * @returns
2275
+ */
2276
+ static create<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any, any>, TModel extends Model<any, any> = InstanceType<TThis>, TDelegate extends ModelQuerySchemaLike = QuerySchemaForModel<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis, data: ModelCreateData<TModel, TDelegate>): Promise<TModel>;
2277
+ /**
2278
+ * Insert new records or update existing records by one or more unique keys.
2279
+ *
2280
+ * @param this
2281
+ * @param values
2282
+ * @param uniqueBy
2283
+ * @param update
2284
+ * @returns
2285
+ */
2286
+ static upsert<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any, any>, TModel extends Model<any, any> = InstanceType<TThis>, TDelegate extends ModelQuerySchemaLike = QuerySchemaForModel<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis, values: Array<Record<string, unknown>>, uniqueBy: string | string[], update?: string[] | null): Promise<number>;
2287
+ /**
2288
+ * Delete records by their primary key(s), dispatching model events for each
2289
+ * matched record. Returns the number of records deleted.
2290
+ *
2291
+ * @param this
2292
+ * @param ids
2293
+ * @returns
2294
+ */
2295
+ static destroy<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any, any>, TModel extends Model<any, any> = InstanceType<TThis>, TDelegate extends ModelQuerySchemaLike = QuerySchemaForModel<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis, ids: string | number | Array<string | number>): Promise<number>;
2242
2296
  /**
2243
2297
  * Get the soft delete configuration for the model, including whether
2244
2298
  * soft deletes are enabled and the name of the deleted at column.
@@ -2297,6 +2351,15 @@ declare abstract class Model<TSchema extends ModelQuerySchemaLike | Record<strin
2297
2351
  */
2298
2352
  update(attributes: Partial<TAttributes>): Promise<boolean>;
2299
2353
  update(attributes: Record<string, unknown>): Promise<boolean>;
2354
+ /**
2355
+ * Update the model and persist it within a transaction, rethrowing on
2356
+ * failure. Unlike update(), errors are not swallowed.
2357
+ *
2358
+ * @param attributes
2359
+ * @returns
2360
+ */
2361
+ updateOrFail(attributes: Partial<TAttributes>): Promise<this>;
2362
+ updateOrFail(attributes: Record<string, unknown>): Promise<this>;
2300
2363
  /**
2301
2364
  * Get the value of an attribute, applying any get mutators or casts if defined.
2302
2365
  *
@@ -2316,8 +2379,10 @@ declare abstract class Model<TSchema extends ModelQuerySchemaLike | Record<strin
2316
2379
  setAttribute(key: string, value: unknown): this;
2317
2380
  /**
2318
2381
  * Save the model to the database.
2319
- * If the model has an identifier (id), it will perform an update.
2320
- * Otherwise, it will perform a create.
2382
+ * If the model already exists in the database it performs an update;
2383
+ * otherwise it performs an insert. Existence is tracked through the
2384
+ * `exists` flag rather than the presence of a primary-key value, so a model
2385
+ * built with an explicit primary key still inserts on its first save.
2321
2386
  *
2322
2387
  * @returns
2323
2388
  */
@@ -2328,6 +2393,13 @@ declare abstract class Model<TSchema extends ModelQuerySchemaLike | Record<strin
2328
2393
  * @returns
2329
2394
  */
2330
2395
  saveQuietly(): Promise<this>;
2396
+ /**
2397
+ * Save the model within a transaction, rolling back and rethrowing if the
2398
+ * operation fails. Unlike update(), this never swallows errors.
2399
+ *
2400
+ * @returns
2401
+ */
2402
+ saveOrFail(): Promise<this>;
2331
2403
  /**
2332
2404
  * Delete the model from the database.
2333
2405
  * If soft deletes are enabled, it will perform a soft delete by
@@ -2343,6 +2415,13 @@ declare abstract class Model<TSchema extends ModelQuerySchemaLike | Record<strin
2343
2415
  * @returns
2344
2416
  */
2345
2417
  deleteQuietly(): Promise<this>;
2418
+ /**
2419
+ * Delete the model within a transaction, rolling back and rethrowing if the
2420
+ * operation fails.
2421
+ *
2422
+ * @returns
2423
+ */
2424
+ deleteOrFail(): Promise<this>;
2346
2425
  /**
2347
2426
  * Permanently delete the model from the database, regardless of whether soft
2348
2427
  * deletes are enabled.
@@ -2443,6 +2522,24 @@ declare abstract class Model<TSchema extends ModelQuerySchemaLike | Record<strin
2443
2522
  * @returns
2444
2523
  */
2445
2524
  wasChanged(keys?: string | string[]): boolean;
2525
+ /**
2526
+ * Get the attributes that were changed during the last successful
2527
+ * persistence operation.
2528
+ *
2529
+ * @returns
2530
+ */
2531
+ getChanges(): Partial<TAttributes>;
2532
+ /**
2533
+ * Get the attribute snapshot that was persisted before the last successful
2534
+ * persistence operation.
2535
+ *
2536
+ * @returns
2537
+ */
2538
+ getPrevious(): Partial<TAttributes>;
2539
+ /**
2540
+ * @param key The attribute key to retrieve the previous value for.
2541
+ */
2542
+ getPrevious<TKey extends keyof TAttributes & string>(key: TKey): TAttributes[TKey] | undefined;
2446
2543
  /**
2447
2544
  * Convert the model instance to a plain object, applying visibility
2448
2545
  * rules, appends, and mutators.
@@ -2676,6 +2773,13 @@ declare abstract class Model<TSchema extends ModelQuerySchemaLike | Record<strin
2676
2773
  * @param previousOriginal
2677
2774
  */
2678
2775
  private syncChanges;
2776
+ /**
2777
+ * Capture the attribute snapshot that was persisted before the most recent
2778
+ * save so it can be read back via getPrevious().
2779
+ *
2780
+ * @param previousOriginal
2781
+ */
2782
+ private syncPrevious;
2679
2783
  /**
2680
2784
  * Resolve lifecycle state for the provided model class.
2681
2785
  *
@@ -3799,6 +3903,35 @@ declare class QueryBuilder<TModel, TDelegate extends ModelQuerySchemaLike = Mode
3799
3903
  * @returns
3800
3904
  */
3801
3905
  firstOrFail(): Promise<TModel>;
3906
+ /**
3907
+ * Returns the first record matching the given attributes or instantiates a
3908
+ * new, unpersisted model populated with the merged attributes and values.
3909
+ *
3910
+ * @param attributes
3911
+ * @param values
3912
+ * @returns
3913
+ */
3914
+ firstOrNew(attributes: Record<string, unknown>, values?: Record<string, unknown>): Promise<TModel>;
3915
+ /**
3916
+ * Returns the first record matching the given attributes or creates and
3917
+ * persists a new record populated with the merged attributes and values.
3918
+ *
3919
+ * @param attributes
3920
+ * @param values
3921
+ * @returns
3922
+ */
3923
+ firstOrCreate(attributes: Record<string, unknown>, values?: Record<string, unknown>): Promise<TModel>;
3924
+ /**
3925
+ * Returns the first record matching the query, or the result of the
3926
+ * fallback callback when no record exists. An optional column list narrows
3927
+ * the selected columns before the lookup.
3928
+ *
3929
+ * @param columnsOrCallback
3930
+ * @param maybeCallback
3931
+ * @returns
3932
+ */
3933
+ firstOr<TResult>(callback: () => TResult | Promise<TResult>): Promise<TModel | TResult>;
3934
+ firstOr<TResult>(columns: string[], callback: () => TResult | Promise<TResult>): Promise<TModel | TResult>;
3802
3935
  /**
3803
3936
  * Finds a record by a specific key and value.
3804
3937
  * This is a convenience method that is equivalent to
@@ -3925,6 +4058,15 @@ declare class QueryBuilder<TModel, TDelegate extends ModelQuerySchemaLike = Mode
3925
4058
  * @returns
3926
4059
  */
3927
4060
  updateOrInsert(attributes: Record<string, unknown>, values?: Record<string, unknown> | ((exists: boolean) => Record<string, unknown> | Promise<Record<string, unknown>>)): Promise<boolean>;
4061
+ /**
4062
+ * Update the first record matching the given attributes, or create a new
4063
+ * record populated with the merged attributes and values when none exists.
4064
+ *
4065
+ * @param attributes
4066
+ * @param values
4067
+ * @returns
4068
+ */
4069
+ updateOrCreate(attributes: Record<string, unknown>, values?: Record<string, unknown>): Promise<TModel>;
3928
4070
  private shouldFallbackUpdateOrInsertUpsert;
3929
4071
  /**
3930
4072
  * Insert new records or update existing records by one or more unique keys.
@@ -3942,6 +4084,14 @@ declare class QueryBuilder<TModel, TDelegate extends ModelQuerySchemaLike = Mode
3942
4084
  * @returns
3943
4085
  */
3944
4086
  delete(): Promise<TModel | null>;
4087
+ /**
4088
+ * Hydrate a row that was just deleted, marking the resulting model as no
4089
+ * longer existing in the database.
4090
+ *
4091
+ * @param attributes
4092
+ * @returns
4093
+ */
4094
+ private hydrateDeleted;
3945
4095
  /**
3946
4096
  * Deletes the first record matching the current query constraints and throws
3947
4097
  * when no record matches.
@@ -1,7 +1,7 @@
1
- import { Kysely, Transaction } from "kysely";
2
- import { PrismaClient } from "@prisma/client";
3
1
  import { Collection } from "@h3ravel/collect.js";
2
+ import { Kysely, Transaction } from "kysely";
4
3
  import { Command } from "@h3ravel/musket";
4
+ import { PrismaClient } from "@prisma/client";
5
5
 
6
6
  //#region src/types/migrations.d.ts
7
7
  type SchemaColumnType = 'id' | 'uuid' | 'enum' | 'string' | 'text' | 'integer' | 'bigInteger' | 'float' | 'boolean' | 'json' | 'date' | 'timestamp';
@@ -2083,7 +2083,19 @@ declare abstract class Model<TSchema extends ModelQuerySchemaLike | Record<strin
2083
2083
  protected readonly attributes: Record<string, unknown>;
2084
2084
  protected original: Record<string, unknown>;
2085
2085
  protected changes: Record<string, unknown>;
2086
+ protected previous: Record<string, unknown>;
2086
2087
  protected readonly touchedAttributes: Set<string>;
2088
+ /**
2089
+ * Indicates whether the model corresponds to a row that exists in the
2090
+ * database. Hydrated and freshly inserted models are marked as existing;
2091
+ * models built with `new Model(...)` are not until they are saved.
2092
+ */
2093
+ exists: boolean;
2094
+ /**
2095
+ * Indicates whether the model was inserted during the current lifecycle
2096
+ * (i.e. the last successful save performed a create rather than an update).
2097
+ */
2098
+ wasRecentlyCreated: boolean;
2087
2099
  constructor(attributes?: Record<string, unknown>);
2088
2100
  private static emitDeprecationWarning;
2089
2101
  /**
@@ -2239,6 +2251,48 @@ declare abstract class Model<TSchema extends ModelQuerySchemaLike | Record<strin
2239
2251
  * @returns
2240
2252
  */
2241
2253
  static scope<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any, any>, TModel extends Model<any, any> = InstanceType<TThis>, TDelegate extends ModelQuerySchemaLike = QuerySchemaForModel<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>;
2254
+ /**
2255
+ * Start a query constrained by the given where clause.
2256
+ *
2257
+ * @param this
2258
+ * @param where
2259
+ * @returns
2260
+ */
2261
+ static where<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any, any>, TModel extends Model<any, any> = InstanceType<TThis>, TDelegate extends ModelQuerySchemaLike = QuerySchemaForModel<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis, where: QuerySchemaWhere<TDelegate>): QueryBuilder<TModel, TDelegate>;
2262
+ /**
2263
+ * Retrieve all records for the model.
2264
+ *
2265
+ * @param this
2266
+ * @returns
2267
+ */
2268
+ static all<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any, any>, TModel extends Model<any, any> = InstanceType<TThis>, TDelegate extends ModelQuerySchemaLike = QuerySchemaForModel<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis): Promise<ArkormCollection<TModel>>;
2269
+ /**
2270
+ * Create and persist a new record, returning the hydrated model instance.
2271
+ *
2272
+ * @param this
2273
+ * @param data
2274
+ * @returns
2275
+ */
2276
+ static create<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any, any>, TModel extends Model<any, any> = InstanceType<TThis>, TDelegate extends ModelQuerySchemaLike = QuerySchemaForModel<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis, data: ModelCreateData<TModel, TDelegate>): Promise<TModel>;
2277
+ /**
2278
+ * Insert new records or update existing records by one or more unique keys.
2279
+ *
2280
+ * @param this
2281
+ * @param values
2282
+ * @param uniqueBy
2283
+ * @param update
2284
+ * @returns
2285
+ */
2286
+ static upsert<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any, any>, TModel extends Model<any, any> = InstanceType<TThis>, TDelegate extends ModelQuerySchemaLike = QuerySchemaForModel<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis, values: Array<Record<string, unknown>>, uniqueBy: string | string[], update?: string[] | null): Promise<number>;
2287
+ /**
2288
+ * Delete records by their primary key(s), dispatching model events for each
2289
+ * matched record. Returns the number of records deleted.
2290
+ *
2291
+ * @param this
2292
+ * @param ids
2293
+ * @returns
2294
+ */
2295
+ static destroy<TThis extends abstract new (attributes?: Record<string, unknown>) => Model<any, any>, TModel extends Model<any, any> = InstanceType<TThis>, TDelegate extends ModelQuerySchemaLike = QuerySchemaForModel<TModel extends Model<infer TSchema, any> ? TSchema : Record<string, any>, TModel extends Model<any, infer TAttributes> ? TAttributes : Record<string, any>>>(this: TThis, ids: string | number | Array<string | number>): Promise<number>;
2242
2296
  /**
2243
2297
  * Get the soft delete configuration for the model, including whether
2244
2298
  * soft deletes are enabled and the name of the deleted at column.
@@ -2297,6 +2351,15 @@ declare abstract class Model<TSchema extends ModelQuerySchemaLike | Record<strin
2297
2351
  */
2298
2352
  update(attributes: Partial<TAttributes>): Promise<boolean>;
2299
2353
  update(attributes: Record<string, unknown>): Promise<boolean>;
2354
+ /**
2355
+ * Update the model and persist it within a transaction, rethrowing on
2356
+ * failure. Unlike update(), errors are not swallowed.
2357
+ *
2358
+ * @param attributes
2359
+ * @returns
2360
+ */
2361
+ updateOrFail(attributes: Partial<TAttributes>): Promise<this>;
2362
+ updateOrFail(attributes: Record<string, unknown>): Promise<this>;
2300
2363
  /**
2301
2364
  * Get the value of an attribute, applying any get mutators or casts if defined.
2302
2365
  *
@@ -2316,8 +2379,10 @@ declare abstract class Model<TSchema extends ModelQuerySchemaLike | Record<strin
2316
2379
  setAttribute(key: string, value: unknown): this;
2317
2380
  /**
2318
2381
  * Save the model to the database.
2319
- * If the model has an identifier (id), it will perform an update.
2320
- * Otherwise, it will perform a create.
2382
+ * If the model already exists in the database it performs an update;
2383
+ * otherwise it performs an insert. Existence is tracked through the
2384
+ * `exists` flag rather than the presence of a primary-key value, so a model
2385
+ * built with an explicit primary key still inserts on its first save.
2321
2386
  *
2322
2387
  * @returns
2323
2388
  */
@@ -2328,6 +2393,13 @@ declare abstract class Model<TSchema extends ModelQuerySchemaLike | Record<strin
2328
2393
  * @returns
2329
2394
  */
2330
2395
  saveQuietly(): Promise<this>;
2396
+ /**
2397
+ * Save the model within a transaction, rolling back and rethrowing if the
2398
+ * operation fails. Unlike update(), this never swallows errors.
2399
+ *
2400
+ * @returns
2401
+ */
2402
+ saveOrFail(): Promise<this>;
2331
2403
  /**
2332
2404
  * Delete the model from the database.
2333
2405
  * If soft deletes are enabled, it will perform a soft delete by
@@ -2343,6 +2415,13 @@ declare abstract class Model<TSchema extends ModelQuerySchemaLike | Record<strin
2343
2415
  * @returns
2344
2416
  */
2345
2417
  deleteQuietly(): Promise<this>;
2418
+ /**
2419
+ * Delete the model within a transaction, rolling back and rethrowing if the
2420
+ * operation fails.
2421
+ *
2422
+ * @returns
2423
+ */
2424
+ deleteOrFail(): Promise<this>;
2346
2425
  /**
2347
2426
  * Permanently delete the model from the database, regardless of whether soft
2348
2427
  * deletes are enabled.
@@ -2443,6 +2522,24 @@ declare abstract class Model<TSchema extends ModelQuerySchemaLike | Record<strin
2443
2522
  * @returns
2444
2523
  */
2445
2524
  wasChanged(keys?: string | string[]): boolean;
2525
+ /**
2526
+ * Get the attributes that were changed during the last successful
2527
+ * persistence operation.
2528
+ *
2529
+ * @returns
2530
+ */
2531
+ getChanges(): Partial<TAttributes>;
2532
+ /**
2533
+ * Get the attribute snapshot that was persisted before the last successful
2534
+ * persistence operation.
2535
+ *
2536
+ * @returns
2537
+ */
2538
+ getPrevious(): Partial<TAttributes>;
2539
+ /**
2540
+ * @param key The attribute key to retrieve the previous value for.
2541
+ */
2542
+ getPrevious<TKey extends keyof TAttributes & string>(key: TKey): TAttributes[TKey] | undefined;
2446
2543
  /**
2447
2544
  * Convert the model instance to a plain object, applying visibility
2448
2545
  * rules, appends, and mutators.
@@ -2676,6 +2773,13 @@ declare abstract class Model<TSchema extends ModelQuerySchemaLike | Record<strin
2676
2773
  * @param previousOriginal
2677
2774
  */
2678
2775
  private syncChanges;
2776
+ /**
2777
+ * Capture the attribute snapshot that was persisted before the most recent
2778
+ * save so it can be read back via getPrevious().
2779
+ *
2780
+ * @param previousOriginal
2781
+ */
2782
+ private syncPrevious;
2679
2783
  /**
2680
2784
  * Resolve lifecycle state for the provided model class.
2681
2785
  *
@@ -3799,6 +3903,35 @@ declare class QueryBuilder<TModel, TDelegate extends ModelQuerySchemaLike = Mode
3799
3903
  * @returns
3800
3904
  */
3801
3905
  firstOrFail(): Promise<TModel>;
3906
+ /**
3907
+ * Returns the first record matching the given attributes or instantiates a
3908
+ * new, unpersisted model populated with the merged attributes and values.
3909
+ *
3910
+ * @param attributes
3911
+ * @param values
3912
+ * @returns
3913
+ */
3914
+ firstOrNew(attributes: Record<string, unknown>, values?: Record<string, unknown>): Promise<TModel>;
3915
+ /**
3916
+ * Returns the first record matching the given attributes or creates and
3917
+ * persists a new record populated with the merged attributes and values.
3918
+ *
3919
+ * @param attributes
3920
+ * @param values
3921
+ * @returns
3922
+ */
3923
+ firstOrCreate(attributes: Record<string, unknown>, values?: Record<string, unknown>): Promise<TModel>;
3924
+ /**
3925
+ * Returns the first record matching the query, or the result of the
3926
+ * fallback callback when no record exists. An optional column list narrows
3927
+ * the selected columns before the lookup.
3928
+ *
3929
+ * @param columnsOrCallback
3930
+ * @param maybeCallback
3931
+ * @returns
3932
+ */
3933
+ firstOr<TResult>(callback: () => TResult | Promise<TResult>): Promise<TModel | TResult>;
3934
+ firstOr<TResult>(columns: string[], callback: () => TResult | Promise<TResult>): Promise<TModel | TResult>;
3802
3935
  /**
3803
3936
  * Finds a record by a specific key and value.
3804
3937
  * This is a convenience method that is equivalent to
@@ -3925,6 +4058,15 @@ declare class QueryBuilder<TModel, TDelegate extends ModelQuerySchemaLike = Mode
3925
4058
  * @returns
3926
4059
  */
3927
4060
  updateOrInsert(attributes: Record<string, unknown>, values?: Record<string, unknown> | ((exists: boolean) => Record<string, unknown> | Promise<Record<string, unknown>>)): Promise<boolean>;
4061
+ /**
4062
+ * Update the first record matching the given attributes, or create a new
4063
+ * record populated with the merged attributes and values when none exists.
4064
+ *
4065
+ * @param attributes
4066
+ * @param values
4067
+ * @returns
4068
+ */
4069
+ updateOrCreate(attributes: Record<string, unknown>, values?: Record<string, unknown>): Promise<TModel>;
3928
4070
  private shouldFallbackUpdateOrInsertUpsert;
3929
4071
  /**
3930
4072
  * Insert new records or update existing records by one or more unique keys.
@@ -3942,6 +4084,14 @@ declare class QueryBuilder<TModel, TDelegate extends ModelQuerySchemaLike = Mode
3942
4084
  * @returns
3943
4085
  */
3944
4086
  delete(): Promise<TModel | null>;
4087
+ /**
4088
+ * Hydrate a row that was just deleted, marking the resulting model as no
4089
+ * longer existing in the database.
4090
+ *
4091
+ * @param attributes
4092
+ * @returns
4093
+ */
4094
+ private hydrateDeleted;
3945
4095
  /**
3946
4096
  * Deletes the first record matching the current query constraints and throws
3947
4097
  * when no record matches.