pangea-server 3.3.106 → 3.3.107
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.
|
@@ -14,7 +14,7 @@ declare global {
|
|
|
14
14
|
type ColComputed<T> = CreationOptional<T>;
|
|
15
15
|
type ModelInstance<BM extends BaseModel> = InferAttributes<BM> & {
|
|
16
16
|
id: ModelId;
|
|
17
|
-
init?:
|
|
17
|
+
init?: InitModel;
|
|
18
18
|
};
|
|
19
19
|
type Where<BM extends BaseModel> = WhereOptions<BM> & Record<symbol, any>;
|
|
20
20
|
type InsertParams<BM extends BaseModel> = OptionalIfNullish<IncludeHidden<StripRelations<Omit<InferCreationAttributes<BM>, 'id' | 'init'>>>> & {
|
|
@@ -27,6 +27,7 @@ declare global {
|
|
|
27
27
|
type Tx = Transaction;
|
|
28
28
|
type Db = _Db;
|
|
29
29
|
}
|
|
30
|
+
export type InitModel = (instance: any) => void;
|
|
30
31
|
export type Models = Record<ModelName, BaseModelCtor>;
|
|
31
32
|
export type Seeds<M extends Models> = {
|
|
32
33
|
[T in keyof M]: InsertParams<InstanceType<M[T]>>[];
|
|
@@ -317,8 +317,10 @@ function processInstance(model, instance) {
|
|
|
317
317
|
processInstance(relModel, relInstance);
|
|
318
318
|
}
|
|
319
319
|
}
|
|
320
|
-
instance.
|
|
321
|
-
|
|
320
|
+
const jsonInstance = instance.toJSON();
|
|
321
|
+
instance.init?.(jsonInstance);
|
|
322
|
+
jsonInstance.init = instance.init;
|
|
323
|
+
return jsonInstance;
|
|
322
324
|
}
|
|
323
325
|
function processInstances(model, instances) {
|
|
324
326
|
return instances.map((instance) => processInstance(model, instance));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Model, Column } from 'sequelize-typescript';
|
|
2
2
|
import type { NonAttribute } from 'sequelize';
|
|
3
|
-
import type { Index, DefaultValue, GetModelFn } from '../database.types';
|
|
3
|
+
import type { InitModel, Index, DefaultValue, GetModelFn } from '../database.types';
|
|
4
4
|
type Column = {
|
|
5
5
|
allowNull: boolean;
|
|
6
6
|
defaultValue: DefaultValue | undefined;
|
|
@@ -21,7 +21,7 @@ export declare abstract class BaseModel extends Model {
|
|
|
21
21
|
private static __Relations?;
|
|
22
22
|
id: ModelId;
|
|
23
23
|
version: NonAttribute<number>;
|
|
24
|
-
init?:
|
|
24
|
+
init?: InitModel;
|
|
25
25
|
static get HiddenAttributes(): string[];
|
|
26
26
|
static get Columns(): Columns;
|
|
27
27
|
static get ColumnIndexes(): Index[];
|