214 lines
6.4 KiB
TypeScript
214 lines
6.4 KiB
TypeScript
import { ForeignKey } from "oak-domain/lib/types/DataType";
|
|
import { Q_DateValue, Q_NumberValue, Q_StringValue, Q_EnumValue, NodeId, MakeFilter, ExprOp, ExpressionKey } from "oak-domain/lib/types/Demand";
|
|
import { OneOf } from "oak-domain/lib/types/Polyfill";
|
|
import { FormCreateData, FormUpdateData, DeduceAggregation, Operation as OakOperation, Selection as OakSelection, MakeAction as OakMakeAction, EntityShape } from "oak-domain/lib/types/Entity";
|
|
import { AppendOnlyAction } from "oak-domain/lib/actions/action";
|
|
import { Price, String } from "oak-domain/lib/types/DataType";
|
|
import * as Account from "../Account/Schema";
|
|
import * as Pay from "../Pay/Schema";
|
|
import * as Withdraw from "../Withdraw/Schema";
|
|
type Type = "deposit" | "withdraw" | "consume" | "loan" | "repay" | "withdrawBack" | "loss";
|
|
export type OpSchema = EntityShape & {
|
|
accountId: ForeignKey<"account">;
|
|
type: Type;
|
|
totalPlus: Price;
|
|
availPlus: Price;
|
|
entity: "pay" | "withdraw" | string;
|
|
entityId: String<64>;
|
|
};
|
|
export type OpAttr = keyof OpSchema;
|
|
export type Schema = EntityShape & {
|
|
accountId: ForeignKey<"account">;
|
|
type: Type;
|
|
totalPlus: Price;
|
|
availPlus: Price;
|
|
entity: "pay" | "withdraw" | string;
|
|
entityId: String<64>;
|
|
account: Account.Schema;
|
|
pay?: Pay.Schema;
|
|
withdraw?: Withdraw.Schema;
|
|
} & {
|
|
[A in ExpressionKey]?: any;
|
|
};
|
|
type AttrFilter = {
|
|
id: Q_StringValue;
|
|
$$createAt$$: Q_DateValue;
|
|
$$seq$$: Q_NumberValue;
|
|
$$updateAt$$: Q_DateValue;
|
|
accountId: Q_StringValue;
|
|
account: Account.Filter;
|
|
type: Q_EnumValue<Type>;
|
|
totalPlus: Q_NumberValue;
|
|
availPlus: Q_NumberValue;
|
|
entity: Q_EnumValue<"pay" | "withdraw" | string>;
|
|
entityId: Q_StringValue;
|
|
pay: Pay.Filter;
|
|
withdraw: Withdraw.Filter;
|
|
};
|
|
export type Filter = MakeFilter<AttrFilter & ExprOp<OpAttr | string>>;
|
|
export type Projection = {
|
|
"#id"?: NodeId;
|
|
[k: string]: any;
|
|
id?: number;
|
|
$$createAt$$?: number;
|
|
$$updateAt$$?: number;
|
|
$$seq$$?: number;
|
|
accountId?: number;
|
|
account?: Account.Projection;
|
|
type?: number;
|
|
totalPlus?: number;
|
|
availPlus?: number;
|
|
entity?: number;
|
|
entityId?: number;
|
|
pay?: Pay.Projection;
|
|
withdraw?: Withdraw.Projection;
|
|
} & Partial<ExprOp<OpAttr | string>>;
|
|
type AccountOperIdProjection = OneOf<{
|
|
id: number;
|
|
}>;
|
|
type AccountIdProjection = OneOf<{
|
|
accountId: number;
|
|
}>;
|
|
type PayIdProjection = OneOf<{
|
|
entityId: number;
|
|
}>;
|
|
type WithdrawIdProjection = OneOf<{
|
|
entityId: number;
|
|
}>;
|
|
export type SortAttr = {
|
|
id: number;
|
|
} | {
|
|
$$createAt$$: number;
|
|
} | {
|
|
$$seq$$: number;
|
|
} | {
|
|
$$updateAt$$: number;
|
|
} | {
|
|
accountId: number;
|
|
} | {
|
|
account: Account.SortAttr;
|
|
} | {
|
|
type: number;
|
|
} | {
|
|
totalPlus: number;
|
|
} | {
|
|
availPlus: number;
|
|
} | {
|
|
entity: number;
|
|
} | {
|
|
entityId: number;
|
|
} | {
|
|
pay: Pay.SortAttr;
|
|
} | {
|
|
withdraw: Withdraw.SortAttr;
|
|
} | {
|
|
[k: string]: any;
|
|
} | OneOf<ExprOp<OpAttr | string>>;
|
|
export type SortNode = {
|
|
$attr: SortAttr;
|
|
$direction?: "asc" | "desc";
|
|
};
|
|
export type Sorter = SortNode[];
|
|
export type SelectOperation<P extends Object = Projection> = OakSelection<"select", P, Filter, Sorter>;
|
|
export type Selection<P extends Object = Projection> = SelectOperation<P>;
|
|
export type Aggregation = DeduceAggregation<Projection, Filter, Sorter>;
|
|
export type CreateOperationData = FormCreateData<Omit<OpSchema, "entity" | "entityId" | "accountId">> & (({
|
|
accountId?: never;
|
|
account: Account.CreateSingleOperation;
|
|
} | {
|
|
accountId: ForeignKey<"account">;
|
|
account?: Account.UpdateOperation;
|
|
} | {
|
|
account?: never;
|
|
accountId: ForeignKey<"account">;
|
|
})) & ({
|
|
entity?: never;
|
|
entityId?: never;
|
|
pay: Pay.CreateSingleOperation;
|
|
} | {
|
|
entity: "pay";
|
|
entityId: ForeignKey<"Pay">;
|
|
pay?: Pay.UpdateOperation;
|
|
} | {
|
|
entity: "pay";
|
|
entityId: ForeignKey<"Pay">;
|
|
pay?: never;
|
|
} | {
|
|
entity?: never;
|
|
entityId?: never;
|
|
withdraw: Withdraw.CreateSingleOperation;
|
|
} | {
|
|
entity: "withdraw";
|
|
entityId: ForeignKey<"Withdraw">;
|
|
withdraw?: Withdraw.UpdateOperation;
|
|
} | {
|
|
entity: "withdraw";
|
|
entityId: ForeignKey<"Withdraw">;
|
|
withdraw?: never;
|
|
} | {
|
|
entity?: string;
|
|
entityId?: string;
|
|
[K: string]: any;
|
|
});
|
|
export type CreateSingleOperation = OakOperation<"create", CreateOperationData>;
|
|
export type CreateMultipleOperation = OakOperation<"create", Array<CreateOperationData>>;
|
|
export type CreateOperation = CreateSingleOperation | CreateMultipleOperation;
|
|
export type UpdateOperationData = FormUpdateData<Omit<OpSchema, "entity" | "entityId" | "accountId">> & (({
|
|
account?: Account.CreateSingleOperation;
|
|
accountId?: never;
|
|
} | {
|
|
account?: Account.UpdateOperation;
|
|
accountId?: never;
|
|
} | {
|
|
account?: Account.RemoveOperation;
|
|
accountId?: never;
|
|
} | {
|
|
account?: never;
|
|
accountId?: ForeignKey<"account">;
|
|
})) & ({
|
|
pay?: Pay.CreateSingleOperation | Pay.UpdateOperation | Pay.RemoveOperation;
|
|
entityId?: never;
|
|
entity?: never;
|
|
} | {
|
|
withdraw?: Withdraw.CreateSingleOperation | Withdraw.UpdateOperation | Withdraw.RemoveOperation;
|
|
entityId?: never;
|
|
entity?: never;
|
|
} | {
|
|
entity?: ("pay" | "withdraw" | string) | null;
|
|
entityId?: ForeignKey<"Pay" | "Withdraw"> | null;
|
|
pay?: never;
|
|
withdraw?: never;
|
|
}) & {
|
|
[k: string]: any;
|
|
};
|
|
export type UpdateOperation = OakOperation<"update" | string, UpdateOperationData, Filter, Sorter>;
|
|
export type RemoveOperationData = {} & (({
|
|
account?: Account.UpdateOperation | Account.RemoveOperation;
|
|
})) & ({
|
|
pay?: Pay.UpdateOperation | Pay.RemoveOperation;
|
|
} | {
|
|
withdraw?: Withdraw.UpdateOperation | Withdraw.RemoveOperation;
|
|
} | {
|
|
[k: string]: any;
|
|
});
|
|
export type RemoveOperation = OakOperation<"remove", RemoveOperationData, Filter, Sorter>;
|
|
export type Operation = CreateOperation | UpdateOperation | RemoveOperation;
|
|
export type AccountIdSubQuery = Selection<AccountIdProjection>;
|
|
export type PayIdSubQuery = Selection<PayIdProjection>;
|
|
export type WithdrawIdSubQuery = Selection<WithdrawIdProjection>;
|
|
export type AccountOperIdSubQuery = Selection<AccountOperIdProjection>;
|
|
export type EntityDef = {
|
|
Schema: Schema;
|
|
OpSchema: OpSchema;
|
|
Action: OakMakeAction<AppendOnlyAction> | string;
|
|
Selection: Selection;
|
|
Aggregation: Aggregation;
|
|
Operation: Operation;
|
|
Create: CreateOperation;
|
|
Update: UpdateOperation;
|
|
Remove: RemoveOperation;
|
|
CreateSingle: CreateSingleOperation;
|
|
CreateMulti: CreateMultipleOperation;
|
|
};
|
|
export {};
|