136 lines
4.7 KiB
TypeScript
136 lines
4.7 KiB
TypeScript
import { PrimaryKey, ForeignKey, JsonProjection } from "oak-domain/lib/types/DataType";
|
|
import { Q_DateValue, Q_BooleanValue, Q_NumberValue, Q_StringValue, Q_EnumValue, NodeId, MakeFilter, FulltextFilter, ExprOp, ExpressionKey, JsonFilter, SubQueryPredicateMetadata } from "oak-domain/lib/types/Demand";
|
|
import { OneOf, ValueOf } from "oak-domain/lib/types/Polyfill";
|
|
import { FormCreateData, FormUpdateData, DeduceAggregation, Operation as OakOperation, Selection as OakSelection, MakeAction as OakMakeAction, AggregationResult } from "oak-domain/lib/types/Entity";
|
|
import { GenericAction, AppendOnlyAction, ReadOnlyAction, ExcludeUpdateAction, ExcludeRemoveAction, RelationAction } from "oak-domain/lib/actions/action";
|
|
import { ActionType, EntityShape } from "oak-domain/lib/types/Entity";
|
|
import { String, Text, Boolean, Datetime } from "oak-domain/lib/types/DataType";
|
|
import { LocaleDef } from "oak-domain/lib/types/Locale";
|
|
import { ActionDef, Index } from "oak-domain/lib/types";
|
|
import { EntityDesc } from "oak-domain/lib/types/EntityDesc";
|
|
import * as User from "../User/Schema";
|
|
export type OpSchema = EntityShape & {
|
|
userId: ForeignKey<"user">;
|
|
prevPassword?: String<32> | null;
|
|
newPassword?: String<32> | null;
|
|
result: 'success' | 'fail';
|
|
};
|
|
export type OpAttr = keyof OpSchema;
|
|
export type Schema = EntityShape & {
|
|
userId: ForeignKey<"user">;
|
|
prevPassword?: String<32> | null;
|
|
newPassword?: String<32> | null;
|
|
result: 'success' | 'fail';
|
|
user: User.Schema;
|
|
} & {
|
|
[A in ExpressionKey]?: any;
|
|
};
|
|
type AttrFilter = {
|
|
id: Q_StringValue;
|
|
$$createAt$$: Q_DateValue;
|
|
$$seq$$: Q_NumberValue;
|
|
$$updateAt$$: Q_DateValue;
|
|
userId: Q_StringValue;
|
|
user: User.Filter;
|
|
prevPassword: Q_StringValue;
|
|
newPassword: Q_StringValue;
|
|
result: Q_EnumValue<'success' | 'fail'>;
|
|
};
|
|
export type Filter = MakeFilter<AttrFilter & ExprOp<OpAttr | string>>;
|
|
export type Projection = {
|
|
"#id"?: NodeId;
|
|
[k: string]: any;
|
|
id?: number;
|
|
$$createAt$$?: number;
|
|
$$updateAt$$?: number;
|
|
$$seq$$?: number;
|
|
userId?: number;
|
|
user?: User.Projection;
|
|
prevPassword?: number;
|
|
newPassword?: number;
|
|
result?: number;
|
|
} & Partial<ExprOp<OpAttr | string>>;
|
|
type ChangePasswordTempIdProjection = OneOf<{
|
|
id: number;
|
|
}>;
|
|
type UserIdProjection = OneOf<{
|
|
userId: number;
|
|
}>;
|
|
export type SortAttr = {
|
|
id: number;
|
|
} | {
|
|
$$createAt$$: number;
|
|
} | {
|
|
$$seq$$: number;
|
|
} | {
|
|
$$updateAt$$: number;
|
|
} | {
|
|
userId: number;
|
|
} | {
|
|
user: User.SortAttr;
|
|
} | {
|
|
prevPassword: number;
|
|
} | {
|
|
newPassword: number;
|
|
} | {
|
|
result: 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, "userId">> & (({
|
|
userId?: never;
|
|
user: User.CreateSingleOperation;
|
|
} | {
|
|
userId: ForeignKey<"user">;
|
|
user?: User.UpdateOperation;
|
|
} | {
|
|
user?: never;
|
|
userId: ForeignKey<"user">;
|
|
}));
|
|
export type CreateSingleOperation = OakOperation<"create", CreateOperationData>;
|
|
export type CreateMultipleOperation = OakOperation<"create", Array<CreateOperationData>>;
|
|
export type CreateOperation = CreateSingleOperation | CreateMultipleOperation;
|
|
export type UpdateOperationData = FormUpdateData<Omit<OpSchema, "userId">> & (({
|
|
user?: User.CreateSingleOperation;
|
|
userId?: never;
|
|
} | {
|
|
user?: User.UpdateOperation;
|
|
userId?: never;
|
|
} | {
|
|
user?: User.RemoveOperation;
|
|
userId?: never;
|
|
} | {
|
|
user?: never;
|
|
userId?: ForeignKey<"user">;
|
|
})) & {
|
|
[k: string]: any;
|
|
};
|
|
export type UpdateOperation = OakOperation<"update" | string, UpdateOperationData, Filter, Sorter>;
|
|
export type RemoveOperationData = {} & (({
|
|
user?: User.UpdateOperation | User.RemoveOperation;
|
|
}));
|
|
export type RemoveOperation = OakOperation<"remove", RemoveOperationData, Filter, Sorter>;
|
|
export type Operation = CreateOperation | UpdateOperation | RemoveOperation;
|
|
export type UserIdSubQuery = Selection<UserIdProjection>;
|
|
export type ChangePasswordTempIdSubQuery = Selection<ChangePasswordTempIdProjection>;
|
|
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;
|
|
}; |