@guren/orm 2.11.1 → 2.13.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.
- package/README.md +7 -1
- package/dist/index.d.ts +150 -72
- package/dist/index.js +1023 -770
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -57,7 +57,13 @@ Relationships, scopes, soft deletes, observers, accessors and mutators, and eage
|
|
|
57
57
|
|
|
58
58
|
## Mass assignment
|
|
59
59
|
|
|
60
|
-
`fillable` is the allowlist, and it is always strict: primary keys are excluded, and an `AuthenticatableModel` refuses password hashes and remember tokens whatever the list says.
|
|
60
|
+
`fillable` is the allowlist, and it is always strict: primary keys are excluded, and an `AuthenticatableModel` refuses password hashes and remember tokens whatever the list says. A column the server chooses next to request data, such as an owner, goes in `set` and stays out of `fillable`:
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
const post = await Post.create(data, { set: { authorId: user.id } })
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Writes that carry no request data at all (seeders, system records) go through `forceCreate()` and `forceUpdate()`.
|
|
61
67
|
|
|
62
68
|
## Dialect subpaths
|
|
63
69
|
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,56 @@ import { AwsDataApiPgDatabase } from "drizzle-orm/aws-data-api/pg";
|
|
|
5
5
|
import { SQLiteBunDatabase } from "drizzle-orm/bun-sqlite";
|
|
6
6
|
import { MySql2Database } from "drizzle-orm/mysql2";
|
|
7
7
|
import { RDSDataClientConfig } from "@aws-sdk/client-rds-data";
|
|
8
|
+
//#region src/relation-definitions.d.ts
|
|
9
|
+
interface BaseRelationDefinition {
|
|
10
|
+
type: 'hasMany' | 'hasOne' | 'belongsTo' | 'belongsToMany' | 'hasManyThrough' | 'morphMany' | 'morphTo';
|
|
11
|
+
name: string;
|
|
12
|
+
related: typeof Model | (() => typeof Model | Promise<typeof Model>);
|
|
13
|
+
}
|
|
14
|
+
interface HasManyRelationDefinition extends BaseRelationDefinition {
|
|
15
|
+
type: 'hasMany';
|
|
16
|
+
foreignKey: string;
|
|
17
|
+
localKey: string;
|
|
18
|
+
}
|
|
19
|
+
interface HasOneRelationDefinition extends BaseRelationDefinition {
|
|
20
|
+
type: 'hasOne';
|
|
21
|
+
foreignKey: string;
|
|
22
|
+
localKey: string;
|
|
23
|
+
}
|
|
24
|
+
interface BelongsToRelationDefinition extends BaseRelationDefinition {
|
|
25
|
+
type: 'belongsTo';
|
|
26
|
+
foreignKey: string;
|
|
27
|
+
ownerKey: string;
|
|
28
|
+
}
|
|
29
|
+
interface BelongsToManyRelationDefinition extends BaseRelationDefinition {
|
|
30
|
+
type: 'belongsToMany';
|
|
31
|
+
pivotTable: unknown;
|
|
32
|
+
foreignPivotKey: string;
|
|
33
|
+
relatedPivotKey: string;
|
|
34
|
+
parentKey: string;
|
|
35
|
+
relatedKey: string;
|
|
36
|
+
}
|
|
37
|
+
interface HasManyThroughRelationDefinition extends BaseRelationDefinition {
|
|
38
|
+
type: 'hasManyThrough';
|
|
39
|
+
through: typeof Model | (() => typeof Model | Promise<typeof Model>);
|
|
40
|
+
firstKey: string;
|
|
41
|
+
secondKey: string;
|
|
42
|
+
localKey: string;
|
|
43
|
+
secondLocalKey: string;
|
|
44
|
+
}
|
|
45
|
+
type RelationDefinition = HasManyRelationDefinition | HasOneRelationDefinition | BelongsToRelationDefinition | BelongsToManyRelationDefinition | HasManyThroughRelationDefinition | MorphManyRelationDefinition | MorphToRelationDefinition;
|
|
46
|
+
interface MorphManyRelationDefinition extends BaseRelationDefinition {
|
|
47
|
+
type: 'morphMany';
|
|
48
|
+
morphName: string;
|
|
49
|
+
localKey: string;
|
|
50
|
+
}
|
|
51
|
+
interface MorphToRelationDefinition {
|
|
52
|
+
type: 'morphTo';
|
|
53
|
+
name: string;
|
|
54
|
+
related: undefined;
|
|
55
|
+
morphName: string;
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
8
58
|
//#region src/attributes.d.ts
|
|
9
59
|
/** Accessor function: transforms a record field value after reading from DB. */
|
|
10
60
|
type AccessorFn<T = unknown> = (record: PlainObject) => T;
|
|
@@ -33,6 +83,10 @@ declare const SEAL_SCOPES: unique symbol;
|
|
|
33
83
|
declare const READ_TRANSFORMS: unique symbol;
|
|
34
84
|
/** Rows as the adapter read them, for the joins a relation loader makes. */
|
|
35
85
|
declare const RAW_RESULTS: unique symbol;
|
|
86
|
+
/** Explicit physical deletion, used by SoftDeletes.forceDelete. */
|
|
87
|
+
declare const PHYSICAL_DELETE: unique symbol;
|
|
88
|
+
/** A static delete run inside the model's lifecycle, shared with SoftDeletes. */
|
|
89
|
+
declare const LIFECYCLE_DELETE: unique symbol;
|
|
36
90
|
//#endregion
|
|
37
91
|
//#region src/QueryBuilder.d.ts
|
|
38
92
|
type FieldKey<TRecord extends PlainObject> = keyof TRecord & string;
|
|
@@ -244,7 +298,17 @@ declare class QueryBuilder<TRecord extends PlainObject = PlainObject, TResult ex
|
|
|
244
298
|
* would be a supported way to bypass mass-assignment protection entirely.
|
|
245
299
|
*/
|
|
246
300
|
[PREPARED_UPDATE](payload: PlainObject): Promise<TRecord>;
|
|
301
|
+
/**
|
|
302
|
+
* The object-where a basic adapter takes; a condition the flat object cannot
|
|
303
|
+
* carry (an OR group, an operator, two values on one field) refuses rather
|
|
304
|
+
* than writing with it dropped.
|
|
305
|
+
*/
|
|
306
|
+
private simpleWhereFor;
|
|
307
|
+
/** Returns the adapter narrowed to the operation, so no call site needs a non-null assertion. */
|
|
308
|
+
private assertWritable;
|
|
309
|
+
private assertWriteOptions;
|
|
247
310
|
delete(): Promise<number | PlainObject | void>;
|
|
311
|
+
[PHYSICAL_DELETE](): Promise<number | PlainObject | void>;
|
|
248
312
|
/** Makes the builder awaitable, resolving to `get()`. */
|
|
249
313
|
then<TResult1 = TResult[], TResult2 = never>(onfulfilled?: ((value: TResult[]) => TResult1 | PromiseLike<TResult1>) | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | null): Promise<TResult1 | TResult2>;
|
|
250
314
|
catch<TCatch = never>(onrejected?: ((reason: unknown) => TCatch | PromiseLike<TCatch>) | null): Promise<TResult[] | TCatch>;
|
|
@@ -276,9 +340,18 @@ declare class QueryBuilder<TRecord extends PlainObject = PlainObject, TResult ex
|
|
|
276
340
|
*/
|
|
277
341
|
private filtersEvaporated;
|
|
278
342
|
private assertFiltersSurvived;
|
|
343
|
+
/**
|
|
344
|
+
* `where(field, 'is null')` type-checks through the `(field, value)` overload on
|
|
345
|
+
* any string column and compiles to `field = 'is null'`, silently dropping the
|
|
346
|
+
* NULL rows. A value-taking token (`'like'`) is left alone: it can be real data.
|
|
347
|
+
*/
|
|
348
|
+
private refuseOperatorAsValue;
|
|
279
349
|
private addSimpleCondition;
|
|
280
350
|
private executeQuery;
|
|
281
|
-
/**
|
|
351
|
+
/**
|
|
352
|
+
* The flat object a basic adapter's WhereClause takes: `{}` for no conditions
|
|
353
|
+
* at all, null when the conditions are too complex for it.
|
|
354
|
+
*/
|
|
282
355
|
private toSimpleWhereClause;
|
|
283
356
|
/**
|
|
284
357
|
* Paths are delegated to Model.loadRelationsInto, which recurses the
|
|
@@ -311,6 +384,12 @@ interface ORMAdapterAdvanced extends ORMAdapter {
|
|
|
311
384
|
aggregateAdvanced?(table: unknown, fn: AggregateFunction, field: string, conditions: WhereCondition[], queryOptions?: AdapterQueryOptions): Promise<unknown>;
|
|
312
385
|
/** The handle a query built outside the ORM runs on: `trx`, else the open transaction, else the database. */
|
|
313
386
|
executor?(queryOptions?: AdapterQueryOptions): unknown;
|
|
387
|
+
/**
|
|
388
|
+
* Makes awaiting a query built on {@link executor} wait, as the adapter's own
|
|
389
|
+
* calls do, for a transaction the caller is not inside where the driver shares
|
|
390
|
+
* one connection. Patches `query` in place and returns it.
|
|
391
|
+
*/
|
|
392
|
+
queueExecution?<TQuery>(query: TQuery, queryOptions?: AdapterQueryOptions): TQuery;
|
|
314
393
|
/** `SELECT field, COUNT(*) ... GROUP BY field` under `conditions`. */
|
|
315
394
|
countByAdvanced?(table: unknown, field: string, conditions: WhereCondition[], queryOptions?: AdapterQueryOptions): Promise<Array<{
|
|
316
395
|
key: unknown;
|
|
@@ -441,6 +520,11 @@ interface AdapterQueryOptions {
|
|
|
441
520
|
trx?: unknown;
|
|
442
521
|
}
|
|
443
522
|
type ModelWriteOptions = AdapterQueryOptions;
|
|
523
|
+
/** The options of `create(data, { set })` and `update(where, data, { set })` (RFC 0031). */
|
|
524
|
+
type ModelSetOptions<T extends typeof Model, S extends PlainObject> = ModelWriteOptions & SetOption<T, S>;
|
|
525
|
+
type WithoutSet = ModelWriteOptions & {
|
|
526
|
+
set?: never;
|
|
527
|
+
};
|
|
444
528
|
type ModelQueryOptions = AdapterQueryOptions;
|
|
445
529
|
type TransactionHandle = NonNullable<AdapterQueryOptions['trx']>;
|
|
446
530
|
type SelectFrom<TDatabase> = TDatabase extends {
|
|
@@ -479,9 +563,9 @@ declare abstract class Model<TRecord extends PlainObject = PlainObject> {
|
|
|
479
563
|
/**
|
|
480
564
|
* Mass-assignment allowlist. When set, any other key in `create()`/`update()`
|
|
481
565
|
* input throws a MassAssignmentException rather than being discarded, so
|
|
482
|
-
* bugs and injection attempts surface
|
|
483
|
-
*
|
|
484
|
-
* `deniedFields()` always throws.
|
|
566
|
+
* bugs and injection attempts surface. A column the server chooses goes in
|
|
567
|
+
* `set`, and must stay out of this list. Independent of it, `id` is always
|
|
568
|
+
* stripped and `deniedFields()` always throws.
|
|
485
569
|
*/
|
|
486
570
|
static fillable?: string[];
|
|
487
571
|
/**
|
|
@@ -537,9 +621,8 @@ declare abstract class Model<TRecord extends PlainObject = PlainObject> {
|
|
|
537
621
|
/** A query with no global scopes applied, `defaultScope` included. */
|
|
538
622
|
static withoutGlobalScopes<T extends typeof Model>(this: T, queryOptions?: ModelQueryOptions): QueryBuilder<TRecordFor<T>>;
|
|
539
623
|
/**
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
* still in scope.
|
|
624
|
+
* Ahead of the `updating`/`deleting` hooks, which must not fire for a write
|
|
625
|
+
* that is refused; the builder repeats the check for its own callers.
|
|
543
626
|
*/
|
|
544
627
|
private static assertFiltersSurvived;
|
|
545
628
|
/** Applies hidden/visible filtering, accessors and appends. */
|
|
@@ -556,11 +639,13 @@ declare abstract class Model<TRecord extends PlainObject = PlainObject> {
|
|
|
556
639
|
*/
|
|
557
640
|
static [READ_TRANSFORMS]<T extends PlainObject>(records: T[], projected?: boolean): T[];
|
|
558
641
|
/**
|
|
559
|
-
* In order: `
|
|
560
|
-
*
|
|
561
|
-
*
|
|
642
|
+
* In order: a non-empty `set` is refused without `fillable`, or holding `id`,
|
|
643
|
+
* a denied or a fillable key (RFC 0031); `deniedFields()` throws, checked on
|
|
644
|
+
* the raw input so no later rule can swallow them; `id` is stripped silently;
|
|
645
|
+
* then, with `fillable` set, anything outside it throws. `set` is merged last.
|
|
562
646
|
*/
|
|
563
|
-
static filterFillable(data: PlainObject): PlainObject;
|
|
647
|
+
static filterFillable(data: PlainObject, set?: PlainObject): PlainObject;
|
|
648
|
+
private static assertSettable;
|
|
564
649
|
protected static preparePersistencePayload(data: PlainObject): Promise<PlainObject>;
|
|
565
650
|
/** @internal Lets QueryBuilder bulk updates run the same payload preparation as `Model.update()`. */
|
|
566
651
|
static prepareBulkPersistencePayload(data: PlainObject): Promise<PlainObject>;
|
|
@@ -674,21 +759,39 @@ declare abstract class Model<TRecord extends PlainObject = PlainObject> {
|
|
|
674
759
|
*/
|
|
675
760
|
private static paginationQuery;
|
|
676
761
|
static withPaginate<T extends typeof Model, K extends RelationPath<T>>(this: T, relations: K | readonly K[], options?: PaginateOptions<TRecordFor<T>>, queryOptions?: ModelQueryOptions): Promise<PaginatedResult<TRecordFor<T> & RelationTypePick<T, K | readonly K[]>>>;
|
|
677
|
-
static create<T extends typeof Model>(this: T, data: TCreateFor<T>, writeOptions?: ModelWriteOptions): Promise<TRecordFor<T>>;
|
|
678
762
|
/**
|
|
679
|
-
*
|
|
680
|
-
*
|
|
763
|
+
* `set` holds the columns the server chose, such as an owner. They skip
|
|
764
|
+
* `fillable`, must not be in it, and `data` is filtered as without `set`.
|
|
765
|
+
*
|
|
766
|
+
* @example
|
|
767
|
+
* await Post.create(data, { set: { authorId: user.id } })
|
|
768
|
+
*/
|
|
769
|
+
static create<T extends typeof Model, S extends PlainObject>(this: T, data: CreateDataFor<T, NoInfer<S>>, options: ModelSetOptions<T, S>): Promise<TRecordFor<T>>;
|
|
770
|
+
static create<T extends typeof Model>(this: T, data: TCreateFor<T>, writeOptions?: WithoutSet): Promise<TRecordFor<T>>;
|
|
771
|
+
/**
|
|
772
|
+
* Create bypassing mass-assignment protection. Data that carries nothing from
|
|
773
|
+
* the request only (OAuth linking, seeders, system records); a server-chosen
|
|
774
|
+
* column next to request data goes in `create(data, { set })`.
|
|
681
775
|
*/
|
|
682
776
|
static forceCreate<T extends typeof Model>(this: T, data: TCreateFor<T>, writeOptions?: ModelWriteOptions): Promise<TRecordFor<T>>;
|
|
683
|
-
protected static runCreate<T extends typeof Model>(this: T, data: TCreateFor<T>, writeOptions: ModelWriteOptions | undefined, applyFillable: boolean): Promise<TRecordFor<T>>;
|
|
684
|
-
|
|
777
|
+
protected static runCreate<T extends typeof Model>(this: T, data: TCreateFor<T>, writeOptions: ModelWriteOptions | undefined, applyFillable: boolean, set?: PlainObject): Promise<TRecordFor<T>>;
|
|
778
|
+
/** `set` as in `create(data, { set })`. */
|
|
779
|
+
static update<T extends typeof Model, S extends PlainObject>(this: T, where: WhereClauseFor<T>, data: Partial<CreateDataFor<T, NoInfer<S>>>, options: ModelSetOptions<T, S>): Promise<TRecordFor<T>>;
|
|
780
|
+
static update<T extends typeof Model>(this: T, where: WhereClauseFor<T>, data: Partial<TCreateFor<T>>, writeOptions?: WithoutSet): Promise<TRecordFor<T>>;
|
|
685
781
|
/**
|
|
686
|
-
* Update bypassing mass-assignment protection.
|
|
687
|
-
*
|
|
782
|
+
* Update bypassing mass-assignment protection. Data that carries nothing from
|
|
783
|
+
* the request only; a server-chosen column next to request data goes in
|
|
784
|
+
* `update(where, data, { set })`.
|
|
688
785
|
*/
|
|
689
786
|
static forceUpdate<T extends typeof Model>(this: T, where: WhereClauseFor<T>, data: Partial<TCreateFor<T>>, writeOptions?: ModelWriteOptions): Promise<TRecordFor<T>>;
|
|
690
|
-
protected static runUpdate<T extends typeof Model>(this: T, where: WhereClauseFor<T>, data: Partial<TCreateFor<T>>, writeOptions: ModelWriteOptions | undefined, applyFillable: boolean): Promise<TRecordFor<T>>;
|
|
787
|
+
protected static runUpdate<T extends typeof Model>(this: T, where: WhereClauseFor<T>, data: Partial<TCreateFor<T>>, writeOptions: ModelWriteOptions | undefined, applyFillable: boolean, set?: PlainObject): Promise<TRecordFor<T>>;
|
|
691
788
|
static delete<T extends typeof Model>(this: T, where: WhereClauseFor<T>, writeOptions?: ModelWriteOptions): Promise<number | PlainObject | void>;
|
|
789
|
+
/**
|
|
790
|
+
* Runs `write` between the `deleting` and `deleted` events, for `delete()`
|
|
791
|
+
* and the SoftDeletes overrides. Symbol-keyed and kept out of the package
|
|
792
|
+
* entry point; each caller checks its own adapter capability first.
|
|
793
|
+
*/
|
|
794
|
+
static [LIFECYCLE_DELETE](this: typeof Model, where: object, method: string, write: () => Promise<number | PlainObject | void>): Promise<number | PlainObject | void>;
|
|
692
795
|
/**
|
|
693
796
|
* A raw Drizzle builder starting at `select().from(table)`. Carries no model
|
|
694
797
|
* scopes, casts or accessors.
|
|
@@ -749,6 +852,14 @@ type TRecordFor<T extends typeof Model> = T extends {
|
|
|
749
852
|
type TCreateFor<T extends typeof Model> = T extends {
|
|
750
853
|
createType: infer R;
|
|
751
854
|
} ? R extends PlainObject ? R : PlainObject : PlainObject;
|
|
855
|
+
type OmitNamed<T, K extends PropertyKey> = { [P in keyof T as P extends K ? never : P]: T[P]; };
|
|
856
|
+
type NamedKeys<T> = keyof { [P in keyof T as string extends P ? never : number extends P ? never : P]: T[P]; };
|
|
857
|
+
type SetOption<T extends typeof Model, S> = {
|
|
858
|
+
set: S & { [K in Exclude<keyof S, SettableKey<T>>]: never; } & { [K in Extract<keyof S, keyof TCreateFor<T>>]: TCreateFor<T>[K]; };
|
|
859
|
+
};
|
|
860
|
+
type SettableKey<T extends typeof Model> = [SetKey<T>] extends [never] ? PropertyKey : SetKey<T>;
|
|
861
|
+
type SetKey<T extends typeof Model> = Exclude<NamedKeys<TCreateFor<T>>, 'id'>;
|
|
862
|
+
type CreateDataFor<T extends typeof Model, S> = OmitNamed<TCreateFor<T>, keyof S> & { [K in keyof S]?: never; };
|
|
752
863
|
type WhereClauseFor<T extends typeof Model> = WhereClause<TRecordFor<T>>;
|
|
753
864
|
type FieldFor<T extends typeof Model> = keyof TRecordFor<T> & string;
|
|
754
865
|
type RelationPath<T extends typeof Model> = RelationKey<T> | `${RelationKey<T>}.${string}`;
|
|
@@ -772,59 +883,13 @@ interface TransactionModelScope<T extends typeof Model> {
|
|
|
772
883
|
where(field: FieldFor<T>, value: unknown): QueryBuilder<TRecordFor<T>>;
|
|
773
884
|
where(field: FieldFor<T>, operator: WhereOperator, value: unknown): QueryBuilder<TRecordFor<T>>;
|
|
774
885
|
newQuery(): QueryBuilder<TRecordFor<T>>;
|
|
886
|
+
create<S extends PlainObject>(data: CreateDataFor<T, NoInfer<S>>, options: SetOption<T, S>): Promise<TRecordFor<T>>;
|
|
775
887
|
create(data: TCreateFor<T>): Promise<TRecordFor<T>>;
|
|
888
|
+
update<S extends PlainObject>(where: WhereClauseFor<T>, data: Partial<CreateDataFor<T, NoInfer<S>>>, options: SetOption<T, S>): Promise<TRecordFor<T>>;
|
|
776
889
|
update(where: WhereClauseFor<T>, data: Partial<TCreateFor<T>>): Promise<TRecordFor<T>>;
|
|
777
890
|
delete(where: WhereClauseFor<T>): Promise<number | PlainObject | void>;
|
|
778
891
|
paginate(options?: PaginateOptions<TRecordFor<T>>): Promise<PaginatedResult<TRecordFor<T>>>;
|
|
779
892
|
}
|
|
780
|
-
interface BaseRelationDefinition {
|
|
781
|
-
type: 'hasMany' | 'hasOne' | 'belongsTo' | 'belongsToMany' | 'hasManyThrough' | 'morphMany' | 'morphTo';
|
|
782
|
-
name: string;
|
|
783
|
-
related: typeof Model | (() => typeof Model | Promise<typeof Model>);
|
|
784
|
-
}
|
|
785
|
-
interface HasManyRelationDefinition extends BaseRelationDefinition {
|
|
786
|
-
type: 'hasMany';
|
|
787
|
-
foreignKey: string;
|
|
788
|
-
localKey: string;
|
|
789
|
-
}
|
|
790
|
-
interface HasOneRelationDefinition extends BaseRelationDefinition {
|
|
791
|
-
type: 'hasOne';
|
|
792
|
-
foreignKey: string;
|
|
793
|
-
localKey: string;
|
|
794
|
-
}
|
|
795
|
-
interface BelongsToRelationDefinition extends BaseRelationDefinition {
|
|
796
|
-
type: 'belongsTo';
|
|
797
|
-
foreignKey: string;
|
|
798
|
-
ownerKey: string;
|
|
799
|
-
}
|
|
800
|
-
interface BelongsToManyRelationDefinition extends BaseRelationDefinition {
|
|
801
|
-
type: 'belongsToMany';
|
|
802
|
-
pivotTable: unknown;
|
|
803
|
-
foreignPivotKey: string;
|
|
804
|
-
relatedPivotKey: string;
|
|
805
|
-
parentKey: string;
|
|
806
|
-
relatedKey: string;
|
|
807
|
-
}
|
|
808
|
-
interface HasManyThroughRelationDefinition extends BaseRelationDefinition {
|
|
809
|
-
type: 'hasManyThrough';
|
|
810
|
-
through: typeof Model | (() => typeof Model | Promise<typeof Model>);
|
|
811
|
-
firstKey: string;
|
|
812
|
-
secondKey: string;
|
|
813
|
-
localKey: string;
|
|
814
|
-
secondLocalKey: string;
|
|
815
|
-
}
|
|
816
|
-
type RelationDefinition = HasManyRelationDefinition | HasOneRelationDefinition | BelongsToRelationDefinition | BelongsToManyRelationDefinition | HasManyThroughRelationDefinition | MorphManyRelationDefinition | MorphToRelationDefinition;
|
|
817
|
-
interface MorphManyRelationDefinition extends BaseRelationDefinition {
|
|
818
|
-
type: 'morphMany';
|
|
819
|
-
morphName: string;
|
|
820
|
-
localKey: string;
|
|
821
|
-
}
|
|
822
|
-
interface MorphToRelationDefinition {
|
|
823
|
-
type: 'morphTo';
|
|
824
|
-
name: string;
|
|
825
|
-
related: undefined;
|
|
826
|
-
morphName: string;
|
|
827
|
-
}
|
|
828
893
|
type HasManyRelationResult<T extends typeof Model> = Array<TRecordFor<T>>;
|
|
829
894
|
type BelongsToRelationResult<T extends typeof Model> = TRecordFor<T> | null;
|
|
830
895
|
type HasManyRecord<TRecord extends PlainObject> = TRecord[];
|
|
@@ -918,17 +983,28 @@ declare class ModelNotFoundException extends Error {
|
|
|
918
983
|
/**
|
|
919
984
|
* Thrown when mass assignment receives fields it must not write. Discarding
|
|
920
985
|
* them silently hides bugs and can mask injection attempts, so models throw.
|
|
921
|
-
* `reason` is `'
|
|
922
|
-
* `'
|
|
986
|
+
* `reason` is `'denied'` for a field in `deniedFields()`, unassignable whatever
|
|
987
|
+
* `fillable` says, and `'not-fillable'` for every other refusal: a field outside
|
|
988
|
+
* `fillable`, or a `set` the allowlist does not admit (RFC 0031).
|
|
923
989
|
*/
|
|
924
990
|
declare class MassAssignmentException extends Error {
|
|
925
991
|
readonly model: string;
|
|
926
992
|
readonly fields: string[];
|
|
927
993
|
readonly reason: 'not-fillable' | 'denied';
|
|
994
|
+
/**
|
|
995
|
+
* `set` names the `create(data, { set })` rule that refused the fields and
|
|
996
|
+
* only changes the message: `'no-fillable'` (the model declares no `fillable`),
|
|
997
|
+
* `'id'`, `'fillable'` (a `set` key a request may already write) or
|
|
998
|
+
* `'conflict'` (a key in both `data` and `set`).
|
|
999
|
+
*/
|
|
928
1000
|
constructor(model: string, fields: string[], options?: {
|
|
929
|
-
reason?: 'not-fillable'
|
|
1001
|
+
reason?: 'not-fillable';
|
|
1002
|
+
set?: SetRule;
|
|
1003
|
+
} | {
|
|
1004
|
+
reason: 'denied';
|
|
930
1005
|
});
|
|
931
1006
|
}
|
|
1007
|
+
type SetRule = 'no-fillable' | 'id' | 'fillable' | 'conflict';
|
|
932
1008
|
//#endregion
|
|
933
1009
|
//#region src/SoftDeletes.d.ts
|
|
934
1010
|
/** The static methods the SoftDeletes mixin adds. */
|
|
@@ -952,7 +1028,7 @@ interface SoftDeletesStatic {
|
|
|
952
1028
|
*/
|
|
953
1029
|
declare function SoftDeletes<TBase extends typeof Model>(Base: TBase): TBase & SoftDeletesStatic;
|
|
954
1030
|
//#endregion
|
|
955
|
-
//#region src/adapters/drizzle-
|
|
1031
|
+
//#region src/adapters/drizzle-types.d.ts
|
|
956
1032
|
type DrizzleLikeSelect = {
|
|
957
1033
|
where?: (clause: unknown) => DrizzleLikeSelect;
|
|
958
1034
|
orderBy?: (...clauses: unknown[]) => DrizzleLikeSelect;
|
|
@@ -990,6 +1066,8 @@ type DrizzleDatabase = {
|
|
|
990
1066
|
run?(query: unknown): Promise<unknown>;
|
|
991
1067
|
transaction?<TResult>(callback: (trx: unknown) => Promise<TResult>): Promise<TResult>;
|
|
992
1068
|
};
|
|
1069
|
+
//#endregion
|
|
1070
|
+
//#region src/adapters/drizzle-adapter.d.ts
|
|
993
1071
|
declare const DrizzleAdapter: ORMAdapterAdvanced & {
|
|
994
1072
|
configure(db: DrizzleDatabase): void;
|
|
995
1073
|
getDatabase<TDatabase extends DrizzleDatabase = DrizzleDatabase>(): TDatabase;
|
|
@@ -1295,4 +1373,4 @@ declare function serializeRecord(record: PlainObject, options: {
|
|
|
1295
1373
|
/** Serialize an array of records. */
|
|
1296
1374
|
declare function serializeRecords(records: PlainObject[], options: Parameters<typeof serializeRecord>[1]): PlainObject[];
|
|
1297
1375
|
//#endregion
|
|
1298
|
-
export { type AccessorDefinitions, type AccessorFn, type AggregateFunction, type AvgValue, type AwsDataApiDatabase, type AwsDataApiDatabaseOptions, type AwsDataApiSeederContext, type BelongsToManyRecord, type BelongsToManyRelationResult, type BelongsToRecord, type BelongsToRelationResult, type BelongsToRequiredRecord, type CastType, type ConnectionContext, type D1DatabaseHandle, type D1DatabaseOptions, DrizzleAdapter, type DrizzleSelectQuery, type EagerLoadConstraint, type FindManyOptions, GlobalScopeRegistry, type GroupCondition, type HasManyRecord, type HasManyRelationResult, type HasManyThroughRecord, type HasManyThroughRelationResult, type HasOneRecord, type HasOneRelationResult, type HookCallback, type HookName, type InferModelInsert, type InferModelRecord, MassAssignmentException, type MigrationRunSummary, type MigrationStatusEntry, Model, type ModelHooks, ModelNotFoundException, type ModelObserver, type ModelObserverConstructor, type ModelPaginationMeta, type ModelQueryOptions, type MorphManyRecord, type MorphManyRelationResult, type MorphToRecord, type MorphToRelationResult, type MutatorDefinitions, type MutatorFn, type MySqlDatabase, type MySqlDatabaseOptions, type MySqlSeederContext, type ORMAdapter, type ORMAdapterAdvanced, type OrderByClause, type OrderByInput, type OrderDefinition, type OrderDirection, type OrmConnectionEnv, type PaginateOptions, type PaginatedResult, type PlainObject, type PostgresDatabase, type PostgresDatabaseOptions, type PostgresSeederContext, QueryBuilder, type QueryBuilderOptions, type ScopeFunction, type SeederContext, type SeederHandler, type SeederRunSummary, type SimpleCondition, SoftDeletes, type SoftDeletesStatic, type SqliteDatabase, type SqliteDatabaseOptions, type SqliteSeederContext, type SumValue, type TransactionHandle, type TransactionModelScope, type WhereClause, type WhereCondition, type WhereGroupCallback, type WhereOperator, type WithRelations, applyAccessors, applyMutators, buildDrizzleConditions, createAwsDataApiDatabase, createD1Database, createMySqlDatabase, createPostgresDatabase, createSqliteDatabase, defineModel, defineSeeder, executeHook, executeObservers, loadSeeders, runSeeders, serializeRecord, serializeRecords };
|
|
1376
|
+
export { type AccessorDefinitions, type AccessorFn, type AggregateFunction, type AvgValue, type AwsDataApiDatabase, type AwsDataApiDatabaseOptions, type AwsDataApiSeederContext, type BelongsToManyRecord, type BelongsToManyRelationResult, type BelongsToRecord, type BelongsToRelationResult, type BelongsToRequiredRecord, type CastType, type ConnectionContext, type D1DatabaseHandle, type D1DatabaseOptions, DrizzleAdapter, type DrizzleSelectQuery, type EagerLoadConstraint, type FindManyOptions, GlobalScopeRegistry, type GroupCondition, type HasManyRecord, type HasManyRelationResult, type HasManyThroughRecord, type HasManyThroughRelationResult, type HasOneRecord, type HasOneRelationResult, type HookCallback, type HookName, type InferModelInsert, type InferModelRecord, MassAssignmentException, type MigrationRunSummary, type MigrationStatusEntry, Model, type ModelHooks, ModelNotFoundException, type ModelObserver, type ModelObserverConstructor, type ModelPaginationMeta, type ModelQueryOptions, type ModelSetOptions, type MorphManyRecord, type MorphManyRelationResult, type MorphToRecord, type MorphToRelationResult, type MutatorDefinitions, type MutatorFn, type MySqlDatabase, type MySqlDatabaseOptions, type MySqlSeederContext, type ORMAdapter, type ORMAdapterAdvanced, type OrderByClause, type OrderByInput, type OrderDefinition, type OrderDirection, type OrmConnectionEnv, type PaginateOptions, type PaginatedResult, type PlainObject, type PostgresDatabase, type PostgresDatabaseOptions, type PostgresSeederContext, QueryBuilder, type QueryBuilderOptions, type ScopeFunction, type SeederContext, type SeederHandler, type SeederRunSummary, type SimpleCondition, SoftDeletes, type SoftDeletesStatic, type SqliteDatabase, type SqliteDatabaseOptions, type SqliteSeederContext, type SumValue, type TransactionHandle, type TransactionModelScope, type WhereClause, type WhereCondition, type WhereGroupCallback, type WhereOperator, type WithRelations, applyAccessors, applyMutators, buildDrizzleConditions, createAwsDataApiDatabase, createD1Database, createMySqlDatabase, createPostgresDatabase, createSqliteDatabase, defineModel, defineSeeder, executeHook, executeObservers, loadSeeders, runSeeders, serializeRecord, serializeRecords };
|