161 lines
5.3 KiB
TypeScript
161 lines
5.3 KiB
TypeScript
import { ForeignKey } from "oak-domain/lib/types/DataType";
|
|
import { Q_DateValue, Q_BooleanValue, Q_NumberValue, Q_StringValue, 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 { GenericAction } from "oak-domain/lib/actions/action";
|
|
import { Boolean } from "oak-domain/lib/types/DataType";
|
|
import * as Application from "../Application/Schema";
|
|
import * as Passport from "../Passport/Schema";
|
|
export type OpSchema = EntityShape & {
|
|
applicationId: ForeignKey<"application">;
|
|
passportId: ForeignKey<"passport">;
|
|
isDefault: Boolean;
|
|
};
|
|
export type OpAttr = keyof OpSchema;
|
|
export type Schema = EntityShape & {
|
|
applicationId: ForeignKey<"application">;
|
|
passportId: ForeignKey<"passport">;
|
|
isDefault: Boolean;
|
|
application: Application.Schema;
|
|
passport: Passport.Schema;
|
|
} & {
|
|
[A in ExpressionKey]?: any;
|
|
};
|
|
type AttrFilter = {
|
|
id: Q_StringValue;
|
|
$$createAt$$: Q_DateValue;
|
|
$$seq$$: Q_NumberValue;
|
|
$$updateAt$$: Q_DateValue;
|
|
applicationId: Q_StringValue;
|
|
application: Application.Filter;
|
|
passportId: Q_StringValue;
|
|
passport: Passport.Filter;
|
|
isDefault: Q_BooleanValue;
|
|
};
|
|
export type Filter = MakeFilter<AttrFilter & ExprOp<OpAttr | string>>;
|
|
export type Projection = {
|
|
"#id"?: NodeId;
|
|
[k: string]: any;
|
|
id?: number;
|
|
$$createAt$$?: number;
|
|
$$updateAt$$?: number;
|
|
$$seq$$?: number;
|
|
applicationId?: number;
|
|
application?: Application.Projection;
|
|
passportId?: number;
|
|
passport?: Passport.Projection;
|
|
isDefault?: number;
|
|
} & Partial<ExprOp<OpAttr | string>>;
|
|
type ApplicationPassportIdProjection = OneOf<{
|
|
id: number;
|
|
}>;
|
|
type ApplicationIdProjection = OneOf<{
|
|
applicationId: number;
|
|
}>;
|
|
type PassportIdProjection = OneOf<{
|
|
passportId: number;
|
|
}>;
|
|
export type SortAttr = {
|
|
id: number;
|
|
} | {
|
|
$$createAt$$: number;
|
|
} | {
|
|
$$seq$$: number;
|
|
} | {
|
|
$$updateAt$$: number;
|
|
} | {
|
|
applicationId: number;
|
|
} | {
|
|
application: Application.SortAttr;
|
|
} | {
|
|
passportId: number;
|
|
} | {
|
|
passport: Passport.SortAttr;
|
|
} | {
|
|
isDefault: number;
|
|
} | {
|
|
[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, "applicationId" | "passportId">> & (({
|
|
applicationId?: never;
|
|
application: Application.CreateSingleOperation;
|
|
} | {
|
|
applicationId: ForeignKey<"application">;
|
|
application?: Application.UpdateOperation;
|
|
} | {
|
|
application?: never;
|
|
applicationId: ForeignKey<"application">;
|
|
}) & ({
|
|
passportId?: never;
|
|
passport: Passport.CreateSingleOperation;
|
|
} | {
|
|
passportId: ForeignKey<"passport">;
|
|
passport?: Passport.UpdateOperation;
|
|
} | {
|
|
passport?: never;
|
|
passportId: ForeignKey<"passport">;
|
|
}));
|
|
export type CreateSingleOperation = OakOperation<"create", CreateOperationData>;
|
|
export type CreateMultipleOperation = OakOperation<"create", Array<CreateOperationData>>;
|
|
export type CreateOperation = CreateSingleOperation | CreateMultipleOperation;
|
|
export type UpdateOperationData = FormUpdateData<Omit<OpSchema, "applicationId" | "passportId">> & (({
|
|
application?: Application.CreateSingleOperation;
|
|
applicationId?: never;
|
|
} | {
|
|
application?: Application.UpdateOperation;
|
|
applicationId?: never;
|
|
} | {
|
|
application?: Application.RemoveOperation;
|
|
applicationId?: never;
|
|
} | {
|
|
application?: never;
|
|
applicationId?: ForeignKey<"application">;
|
|
}) & ({
|
|
passport?: Passport.CreateSingleOperation;
|
|
passportId?: never;
|
|
} | {
|
|
passport?: Passport.UpdateOperation;
|
|
passportId?: never;
|
|
} | {
|
|
passport?: Passport.RemoveOperation;
|
|
passportId?: never;
|
|
} | {
|
|
passport?: never;
|
|
passportId?: ForeignKey<"passport">;
|
|
})) & {
|
|
[k: string]: any;
|
|
};
|
|
export type UpdateOperation = OakOperation<"update" | string, UpdateOperationData, Filter, Sorter>;
|
|
export type RemoveOperationData = {} & (({
|
|
application?: Application.UpdateOperation | Application.RemoveOperation;
|
|
}) & ({
|
|
passport?: Passport.UpdateOperation | Passport.RemoveOperation;
|
|
}));
|
|
export type RemoveOperation = OakOperation<"remove", RemoveOperationData, Filter, Sorter>;
|
|
export type Operation = CreateOperation | UpdateOperation | RemoveOperation;
|
|
export type ApplicationIdSubQuery = Selection<ApplicationIdProjection>;
|
|
export type PassportIdSubQuery = Selection<PassportIdProjection>;
|
|
export type ApplicationPassportIdSubQuery = Selection<ApplicationPassportIdProjection>;
|
|
export type EntityDef = {
|
|
Schema: Schema;
|
|
OpSchema: OpSchema;
|
|
Action: OakMakeAction<GenericAction> | string;
|
|
Selection: Selection;
|
|
Aggregation: Aggregation;
|
|
Operation: Operation;
|
|
Create: CreateOperation;
|
|
Update: UpdateOperation;
|
|
Remove: RemoveOperation;
|
|
CreateSingle: CreateSingleOperation;
|
|
CreateMulti: CreateMultipleOperation;
|
|
};
|
|
export {};
|