Merge branch 'release'

This commit is contained in:
Xu Chang 2023-02-03 16:14:30 +08:00
commit 7d9f21281a
36 changed files with 611 additions and 80 deletions

View File

@ -1,5 +1,8 @@
export declare const ActionDefDict: { export declare const ActionDefDict: {
modi: { modi: {
iState: import("../types").ActionDef<import("./Modi/Action").IAction, import("./Modi/Action").IState>; iState: import("../types").ActionDef<string, string>;
};
user: {
userState: import("../types").ActionDef<string, string>;
}; };
}; };

View File

@ -2,6 +2,8 @@
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.ActionDefDict = void 0; exports.ActionDefDict = void 0;
var Action_1 = require("./Modi/Action"); var Action_1 = require("./Modi/Action");
var Action_2 = require("./User/Action");
exports.ActionDefDict = { exports.ActionDefDict = {
modi: Action_1.ActionDefDict modi: Action_1.ActionDefDict,
user: Action_2.ActionDefDict
}; };

View File

@ -3,10 +3,12 @@ import { EntityDef as ModiEntity } from "./ModiEntity/Schema";
import { EntityDef as Oper } from "./Oper/Schema"; import { EntityDef as Oper } from "./Oper/Schema";
import { EntityDef as OperEntity } from "./OperEntity/Schema"; import { EntityDef as OperEntity } from "./OperEntity/Schema";
import { EntityDef as User } from "./User/Schema"; import { EntityDef as User } from "./User/Schema";
import { EntityDef as UserEntityGrant } from "./UserEntityGrant/Schema";
export declare type EntityDict = { export declare type EntityDict = {
modi: Modi; modi: Modi;
modiEntity: ModiEntity; modiEntity: ModiEntity;
oper: Oper; oper: Oper;
operEntity: OperEntity; operEntity: OperEntity;
user: User; user: User;
userEntityGrant: UserEntityGrant;
}; };

View File

@ -1,10 +1,10 @@
import { ActionDef } from "../../types/Action"; import { ActionDef } from "../../types/Action";
import { GenericAction } from "../../actions/action"; import { GenericAction } from "../../actions/action";
export declare type IState = 'active' | 'applied' | 'abandoned'; export declare type IState = 'active' | 'applied' | 'abandoned' | string;
export declare type IAction = 'apply' | 'abandon'; export declare type IAction = 'apply' | 'abandon' | string;
export declare type ParticularAction = IAction; export declare type ParticularAction = IAction;
export declare type Action = GenericAction | ParticularAction; export declare type Action = GenericAction | ParticularAction | string;
export declare const actions: string[]; export declare const actions: string[];
export declare const ActionDefDict: { export declare const ActionDefDict: {
iState: ActionDef<IAction, IState>; iState: ActionDef<string, string>;
}; };

View File

@ -6,18 +6,20 @@ import { FormCreateData, FormUpdateData, DeduceAggregation, Operation as OakOper
import { AppendOnlyAction } from "../../actions/action"; import { AppendOnlyAction } from "../../actions/action";
import * as Modi from "../Modi/Schema"; import * as Modi from "../Modi/Schema";
import * as User from "../User/Schema"; import * as User from "../User/Schema";
import * as UserEntityGrant from "../UserEntityGrant/Schema";
export declare type OpSchema = EntityShape & { export declare type OpSchema = EntityShape & {
modiId: ForeignKey<"modi">; modiId: ForeignKey<"modi">;
entity: "user" | string; entity: "user" | "userEntityGrant" | string;
entityId: String<64>; entityId: String<64>;
}; };
export declare type OpAttr = keyof OpSchema; export declare type OpAttr = keyof OpSchema;
export declare type Schema = EntityShape & { export declare type Schema = EntityShape & {
modiId: ForeignKey<"modi">; modiId: ForeignKey<"modi">;
entity: "user" | string; entity: "user" | "userEntityGrant" | string;
entityId: String<64>; entityId: String<64>;
modi: Modi.Schema; modi: Modi.Schema;
user?: User.Schema; user?: User.Schema;
userEntityGrant?: UserEntityGrant.Schema;
} & { } & {
[A in ExpressionKey]?: any; [A in ExpressionKey]?: any;
}; };
@ -31,8 +33,9 @@ declare type AttrFilter<E> = {
entity: E; entity: E;
entityId: Q_StringValue; entityId: Q_StringValue;
user: User.Filter; user: User.Filter;
userEntityGrant: UserEntityGrant.Filter;
}; };
export declare type Filter<E = Q_EnumValue<"user" | string>> = MakeFilter<AttrFilter<E> & ExprOp<OpAttr | string>>; export declare type Filter<E = Q_EnumValue<"user" | "userEntityGrant" | string>> = MakeFilter<AttrFilter<E> & ExprOp<OpAttr | string>>;
export declare type Projection = { export declare type Projection = {
"#id"?: NodeId; "#id"?: NodeId;
[k: string]: any; [k: string]: any;
@ -45,6 +48,7 @@ export declare type Projection = {
entity?: number; entity?: number;
entityId?: number; entityId?: number;
user?: User.Projection; user?: User.Projection;
userEntityGrant?: UserEntityGrant.Projection;
} & Partial<ExprOp<OpAttr | string>>; } & Partial<ExprOp<OpAttr | string>>;
declare type ModiEntityIdProjection = OneOf<{ declare type ModiEntityIdProjection = OneOf<{
id: number; id: number;
@ -55,6 +59,9 @@ declare type ModiIdProjection = OneOf<{
declare type UserIdProjection = OneOf<{ declare type UserIdProjection = OneOf<{
entityId: number; entityId: number;
}>; }>;
declare type UserEntityGrantIdProjection = OneOf<{
entityId: number;
}>;
export declare type SortAttr = { export declare type SortAttr = {
id: number; id: number;
} | { } | {
@ -73,6 +80,8 @@ export declare type SortAttr = {
entityId: number; entityId: number;
} | { } | {
user: User.SortAttr; user: User.SortAttr;
} | {
userEntityGrant: UserEntityGrant.SortAttr;
} | { } | {
[k: string]: any; [k: string]: any;
} | OneOf<ExprOp<OpAttr | string>>; } | OneOf<ExprOp<OpAttr | string>>;
@ -103,6 +112,17 @@ export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "entity"
} | { } | {
entity: "user"; entity: "user";
entityId: String<64>; entityId: String<64>;
} | {
entity?: never;
entityId?: never;
userEntityGrant: UserEntityGrant.CreateSingleOperation;
} | {
entity: "userEntityGrant";
entityId: String<64>;
userEntityGrant: UserEntityGrant.UpdateOperation;
} | {
entity: "userEntityGrant";
entityId: String<64>;
} | { } | {
entity?: string; entity?: string;
entityId?: string; entityId?: string;
@ -128,7 +148,11 @@ export declare type UpdateOperationData = FormUpdateData<Omit<OpSchema, "entity"
entityId?: never; entityId?: never;
entity?: never; entity?: never;
} | { } | {
entity?: ("user" | string) | null; userEntityGrant?: UserEntityGrant.CreateSingleOperation | UserEntityGrant.UpdateOperation | UserEntityGrant.RemoveOperation;
entityId?: never;
entity?: never;
} | {
entity?: ("user" | "userEntityGrant" | string) | null;
entityId?: String<64> | null; entityId?: String<64> | null;
}) & { }) & {
[k: string]: any; [k: string]: any;
@ -138,6 +162,8 @@ export declare type RemoveOperationData = {} & (({
modi?: Modi.UpdateOperation | Modi.RemoveOperation; modi?: Modi.UpdateOperation | Modi.RemoveOperation;
})) & ({ })) & ({
user?: User.UpdateOperation | User.RemoveOperation; user?: User.UpdateOperation | User.RemoveOperation;
} | {
userEntityGrant?: UserEntityGrant.UpdateOperation | UserEntityGrant.RemoveOperation;
} | { } | {
[k: string]: any; [k: string]: any;
}); });
@ -145,6 +171,7 @@ export declare type RemoveOperation = OakOperation<"remove", RemoveOperationData
export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation; export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation;
export declare type ModiIdSubQuery = Selection<ModiIdProjection>; export declare type ModiIdSubQuery = Selection<ModiIdProjection>;
export declare type UserIdSubQuery = Selection<UserIdProjection>; export declare type UserIdSubQuery = Selection<UserIdProjection>;
export declare type UserEntityGrantIdSubQuery = Selection<UserEntityGrantIdProjection>;
export declare type ModiEntityIdSubQuery = Selection<ModiEntityIdProjection>; export declare type ModiEntityIdSubQuery = Selection<ModiEntityIdProjection>;
export declare type EntityDef = { export declare type EntityDef = {
Schema: Schema; Schema: Schema;

View File

@ -13,7 +13,7 @@ exports.desc = {
params: { params: {
length: 32 length: 32
}, },
ref: ["user"] ref: ["user", "userEntityGrant"]
}, },
entityId: { entityId: {
type: "varchar", type: "varchar",

View File

@ -7,19 +7,21 @@ import { AppendOnlyAction } from "../../actions/action";
import * as Oper from "../Oper/Schema"; import * as Oper from "../Oper/Schema";
import * as Modi from "../Modi/Schema"; import * as Modi from "../Modi/Schema";
import * as User from "../User/Schema"; import * as User from "../User/Schema";
import * as UserEntityGrant from "../UserEntityGrant/Schema";
export declare type OpSchema = EntityShape & { export declare type OpSchema = EntityShape & {
operId: ForeignKey<"oper">; operId: ForeignKey<"oper">;
entity: "modi" | "user" | string; entity: "modi" | "user" | "userEntityGrant" | string;
entityId: String<64>; entityId: String<64>;
}; };
export declare type OpAttr = keyof OpSchema; export declare type OpAttr = keyof OpSchema;
export declare type Schema = EntityShape & { export declare type Schema = EntityShape & {
operId: ForeignKey<"oper">; operId: ForeignKey<"oper">;
entity: "modi" | "user" | string; entity: "modi" | "user" | "userEntityGrant" | string;
entityId: String<64>; entityId: String<64>;
oper: Oper.Schema; oper: Oper.Schema;
modi?: Modi.Schema; modi?: Modi.Schema;
user?: User.Schema; user?: User.Schema;
userEntityGrant?: UserEntityGrant.Schema;
} & { } & {
[A in ExpressionKey]?: any; [A in ExpressionKey]?: any;
}; };
@ -34,8 +36,9 @@ declare type AttrFilter<E> = {
entityId: Q_StringValue; entityId: Q_StringValue;
modi: Modi.Filter; modi: Modi.Filter;
user: User.Filter; user: User.Filter;
userEntityGrant: UserEntityGrant.Filter;
}; };
export declare type Filter<E = Q_EnumValue<"modi" | "user" | string>> = MakeFilter<AttrFilter<E> & ExprOp<OpAttr | string>>; export declare type Filter<E = Q_EnumValue<"modi" | "user" | "userEntityGrant" | string>> = MakeFilter<AttrFilter<E> & ExprOp<OpAttr | string>>;
export declare type Projection = { export declare type Projection = {
"#id"?: NodeId; "#id"?: NodeId;
[k: string]: any; [k: string]: any;
@ -49,6 +52,7 @@ export declare type Projection = {
entityId?: number; entityId?: number;
modi?: Modi.Projection; modi?: Modi.Projection;
user?: User.Projection; user?: User.Projection;
userEntityGrant?: UserEntityGrant.Projection;
} & Partial<ExprOp<OpAttr | string>>; } & Partial<ExprOp<OpAttr | string>>;
declare type OperEntityIdProjection = OneOf<{ declare type OperEntityIdProjection = OneOf<{
id: number; id: number;
@ -62,6 +66,9 @@ declare type ModiIdProjection = OneOf<{
declare type UserIdProjection = OneOf<{ declare type UserIdProjection = OneOf<{
entityId: number; entityId: number;
}>; }>;
declare type UserEntityGrantIdProjection = OneOf<{
entityId: number;
}>;
export declare type SortAttr = { export declare type SortAttr = {
id: number; id: number;
} | { } | {
@ -82,6 +89,8 @@ export declare type SortAttr = {
modi: Modi.SortAttr; modi: Modi.SortAttr;
} | { } | {
user: User.SortAttr; user: User.SortAttr;
} | {
userEntityGrant: UserEntityGrant.SortAttr;
} | { } | {
[k: string]: any; [k: string]: any;
} | OneOf<ExprOp<OpAttr | string>>; } | OneOf<ExprOp<OpAttr | string>>;
@ -120,6 +129,17 @@ export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "entity"
} | { } | {
entity: "user"; entity: "user";
entityId: String<64>; entityId: String<64>;
} | {
entity?: never;
entityId?: never;
userEntityGrant: UserEntityGrant.CreateSingleOperation;
} | {
entity: "userEntityGrant";
entityId: String<64>;
userEntityGrant: UserEntityGrant.UpdateOperation;
} | {
entity: "userEntityGrant";
entityId: String<64>;
} | { } | {
entity?: string; entity?: string;
entityId?: string; entityId?: string;
@ -143,7 +163,11 @@ export declare type UpdateOperationData = FormUpdateData<Omit<OpSchema, "entity"
entityId?: never; entityId?: never;
entity?: never; entity?: never;
} | { } | {
entity?: ("modi" | "user" | string) | null; userEntityGrant?: UserEntityGrant.CreateSingleOperation | UserEntityGrant.UpdateOperation | UserEntityGrant.RemoveOperation;
entityId?: never;
entity?: never;
} | {
entity?: ("modi" | "user" | "userEntityGrant" | string) | null;
entityId?: String<64> | null; entityId?: String<64> | null;
}) & { }) & {
[k: string]: any; [k: string]: any;
@ -153,6 +177,8 @@ export declare type RemoveOperationData = {} & ({
modi?: Modi.UpdateOperation | Modi.RemoveOperation; modi?: Modi.UpdateOperation | Modi.RemoveOperation;
} | { } | {
user?: User.UpdateOperation | User.RemoveOperation; user?: User.UpdateOperation | User.RemoveOperation;
} | {
userEntityGrant?: UserEntityGrant.UpdateOperation | UserEntityGrant.RemoveOperation;
} | { } | {
[k: string]: any; [k: string]: any;
}); });
@ -161,6 +187,7 @@ export declare type Operation = CreateOperation | UpdateOperation | RemoveOperat
export declare type OperIdSubQuery = Selection<OperIdProjection>; export declare type OperIdSubQuery = Selection<OperIdProjection>;
export declare type ModiIdSubQuery = Selection<ModiIdProjection>; export declare type ModiIdSubQuery = Selection<ModiIdProjection>;
export declare type UserIdSubQuery = Selection<UserIdProjection>; export declare type UserIdSubQuery = Selection<UserIdProjection>;
export declare type UserEntityGrantIdSubQuery = Selection<UserEntityGrantIdProjection>;
export declare type OperEntityIdSubQuery = Selection<OperEntityIdProjection>; export declare type OperEntityIdSubQuery = Selection<OperEntityIdProjection>;
export declare type EntityDef = { export declare type EntityDef = {
Schema: Schema; Schema: Schema;

View File

@ -13,7 +13,7 @@ exports.desc = {
params: { params: {
length: 32 length: 32
}, },
ref: ["modi", "user"] ref: ["modi", "user", "userEntityGrant"]
}, },
entityId: { entityId: {
type: "varchar", type: "varchar",

View File

@ -6,10 +6,12 @@ var Storage_2 = require("./ModiEntity/Storage");
var Storage_3 = require("./Oper/Storage"); var Storage_3 = require("./Oper/Storage");
var Storage_4 = require("./OperEntity/Storage"); var Storage_4 = require("./OperEntity/Storage");
var Storage_5 = require("./User/Storage"); var Storage_5 = require("./User/Storage");
var Storage_6 = require("./UserEntityGrant/Storage");
exports.storageSchema = { exports.storageSchema = {
modi: Storage_1.desc, modi: Storage_1.desc,
modiEntity: Storage_2.desc, modiEntity: Storage_2.desc,
oper: Storage_3.desc, oper: Storage_3.desc,
operEntity: Storage_4.desc, operEntity: Storage_4.desc,
user: Storage_5.desc user: Storage_5.desc,
userEntityGrant: Storage_6.desc
}; };

10
lib/base-app-domain/User/Action.d.ts vendored Normal file
View File

@ -0,0 +1,10 @@
import { ActionDef } from "../../types/Action";
import { GenericAction, RelationAction } from "../../actions/action";
export declare type UserAction = 'mergeTo' | string;
export declare type UserState = 'normal' | 'merged' | string;
export declare type ParticularAction = UserAction;
export declare type Action = GenericAction | ParticularAction | RelationAction | string;
export declare const actions: string[];
export declare const ActionDefDict: {
userState: ActionDef<string, string>;
};

View File

@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ActionDefDict = exports.actions = void 0;
exports.actions = ["count", "stat", "download", "select", "aggregate", "create", "remove", "update", "grant", "revoke", "mergeTo"];
var UserActionDef = {
stm: {
mergeTo: ['normal', 'merged']
}
};
exports.ActionDefDict = {
userState: UserActionDef
};

View File

@ -1,9 +1,10 @@
import { String, Text } from "../../types/DataType"; import { String, Text, ForeignKey } from "../../types/DataType";
import { Q_DateValue, Q_StringValue, NodeId, MakeFilter, ExprOp, ExpressionKey } from "../../types/Demand"; import { Q_DateValue, Q_StringValue, Q_EnumValue, NodeId, MakeFilter, ExprOp, ExpressionKey } from "../../types/Demand";
import { OneOf } from "../../types/Polyfill"; import { OneOf } from "../../types/Polyfill";
import * as SubQuery from "../_SubQuery"; import * as SubQuery from "../_SubQuery";
import { FormCreateData, FormUpdateData, DeduceAggregation, Operation as OakOperation, Selection as OakSelection, MakeAction as OakMakeAction, EntityShape, AggregationResult } from "../../types/Entity"; import { FormCreateData, FormUpdateData, DeduceAggregation, Operation as OakOperation, Selection as OakSelection, MakeAction as OakMakeAction, EntityShape, AggregationResult } from "../../types/Entity";
import { GenericAction, RelationAction } from "../../actions/action"; import { Action, ParticularAction, UserState } from "./Action";
import { RelationAction } from "../../actions/action";
import * as Oper from "../Oper/Schema"; import * as Oper from "../Oper/Schema";
import * as OperEntity from "../OperEntity/Schema"; import * as OperEntity from "../OperEntity/Schema";
import * as ModiEntity from "../ModiEntity/Schema"; import * as ModiEntity from "../ModiEntity/Schema";
@ -11,14 +12,21 @@ export declare type OpSchema = EntityShape & {
name?: String<16> | null; name?: String<16> | null;
nickname?: String<64> | null; nickname?: String<64> | null;
password?: Text | null; password?: Text | null;
refId?: ForeignKey<"user"> | null;
userState?: UserState | null;
}; };
export declare type OpAttr = keyof OpSchema; export declare type OpAttr = keyof OpSchema;
export declare type Schema = EntityShape & { export declare type Schema = EntityShape & {
name?: String<16> | null; name?: String<16> | null;
nickname?: String<64> | null; nickname?: String<64> | null;
password?: Text | null; password?: Text | null;
refId?: ForeignKey<"user"> | null;
userState?: UserState | null;
ref?: Schema | null;
oper$operator?: Array<Oper.Schema>; oper$operator?: Array<Oper.Schema>;
oper$operator$$aggr?: AggregationResult<Oper.Schema>; oper$operator$$aggr?: AggregationResult<Oper.Schema>;
user$ref?: Array<Schema>;
user$ref$$aggr?: AggregationResult<Schema>;
operEntity$entity?: Array<OperEntity.Schema>; operEntity$entity?: Array<OperEntity.Schema>;
operEntity$entity$$aggr?: AggregationResult<OperEntity.Schema>; operEntity$entity$$aggr?: AggregationResult<OperEntity.Schema>;
modiEntity$entity?: Array<ModiEntity.Schema>; modiEntity$entity?: Array<ModiEntity.Schema>;
@ -34,6 +42,9 @@ declare type AttrFilter = {
name: Q_StringValue; name: Q_StringValue;
nickname: Q_StringValue; nickname: Q_StringValue;
password: Q_StringValue; password: Q_StringValue;
refId: Q_StringValue | SubQuery.UserIdSubQuery;
ref: Filter;
userState: Q_EnumValue<UserState>;
}; };
export declare type Filter = MakeFilter<AttrFilter & ExprOp<OpAttr | string>>; export declare type Filter = MakeFilter<AttrFilter & ExprOp<OpAttr | string>>;
export declare type Projection = { export declare type Projection = {
@ -46,12 +57,21 @@ export declare type Projection = {
name?: number; name?: number;
nickname?: number; nickname?: number;
password?: number; password?: number;
refId?: number;
ref?: Projection;
userState?: number;
oper$operator?: Oper.Selection & { oper$operator?: Oper.Selection & {
$entity: "oper"; $entity: "oper";
}; };
oper$operator$$aggr?: Oper.Aggregation & { oper$operator$$aggr?: Oper.Aggregation & {
$entity: "oper"; $entity: "oper";
}; };
user$ref?: Selection & {
$entity: "user";
};
user$ref$$aggr?: Aggregation & {
$entity: "user";
};
operEntity$entity?: OperEntity.Selection & { operEntity$entity?: OperEntity.Selection & {
$entity: "operEntity"; $entity: "operEntity";
}; };
@ -67,6 +87,7 @@ export declare type Projection = {
} & Partial<ExprOp<OpAttr | string>>; } & Partial<ExprOp<OpAttr | string>>;
declare type UserIdProjection = OneOf<{ declare type UserIdProjection = OneOf<{
id: number; id: number;
refId: number;
}>; }>;
export declare type SortAttr = { export declare type SortAttr = {
id: number; id: number;
@ -82,6 +103,12 @@ export declare type SortAttr = {
nickname: number; nickname: number;
} | { } | {
password: number; password: number;
} | {
refId: number;
} | {
ref: SortAttr;
} | {
userState: number;
} | { } | {
[k: string]: any; [k: string]: any;
} | OneOf<ExprOp<OpAttr | string>>; } | OneOf<ExprOp<OpAttr | string>>;
@ -93,29 +120,53 @@ export declare type Sorter = SortNode[];
export declare type SelectOperation<P extends Object = Projection> = OakSelection<"select", P, Filter, Sorter>; export declare type SelectOperation<P extends Object = Projection> = OakSelection<"select", P, Filter, Sorter>;
export declare type Selection<P extends Object = Projection> = Omit<SelectOperation<P>, "action">; export declare type Selection<P extends Object = Projection> = Omit<SelectOperation<P>, "action">;
export declare type Aggregation = DeduceAggregation<Projection, Filter, Sorter>; export declare type Aggregation = DeduceAggregation<Projection, Filter, Sorter>;
export declare type CreateOperationData = FormCreateData<OpSchema> & { export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "refId">> & (({
refId?: never;
ref?: CreateSingleOperation;
} | {
refId: String<64>;
ref?: UpdateOperation;
} | {
refId?: String<64>;
})) & {
oper$operator?: OakOperation<"create", Omit<Oper.CreateOperationData, "operator" | "operatorId">[]> | Array<OakOperation<"create", Omit<Oper.CreateOperationData, "operator" | "operatorId">>>; oper$operator?: OakOperation<"create", Omit<Oper.CreateOperationData, "operator" | "operatorId">[]> | Array<OakOperation<"create", Omit<Oper.CreateOperationData, "operator" | "operatorId">>>;
user$ref?: OakOperation<UpdateOperation["action"], Omit<UpdateOperationData, "ref" | "refId">, Filter> | OakOperation<"create", Omit<CreateOperationData, "ref" | "refId">[]> | Array<OakOperation<"create", Omit<CreateOperationData, "ref" | "refId">> | OakOperation<UpdateOperation["action"], Omit<UpdateOperationData, "ref" | "refId">, Filter>>;
operEntity$entity?: OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">>>; operEntity$entity?: OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">>>;
modiEntity$entity?: OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">>>; modiEntity$entity?: OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">>>;
}; };
export declare type CreateSingleOperation = OakOperation<"create", CreateOperationData>; export declare type CreateSingleOperation = OakOperation<"create", CreateOperationData>;
export declare type CreateMultipleOperation = OakOperation<"create", Array<CreateOperationData>>; export declare type CreateMultipleOperation = OakOperation<"create", Array<CreateOperationData>>;
export declare type CreateOperation = CreateSingleOperation | CreateMultipleOperation; export declare type CreateOperation = CreateSingleOperation | CreateMultipleOperation;
export declare type UpdateOperationData = FormUpdateData<OpSchema> & { export declare type UpdateOperationData = FormUpdateData<Omit<OpSchema, "refId">> & (({
ref: CreateSingleOperation;
refId?: never;
} | {
ref: UpdateOperation;
refId?: never;
} | {
ref: RemoveOperation;
refId?: never;
} | {
ref?: never;
refId?: String<64> | null;
})) & {
[k: string]: any; [k: string]: any;
oper$operator?: OakOperation<"create", Omit<Oper.CreateOperationData, "operator" | "operatorId">[]> | Array<OakOperation<"create", Omit<Oper.CreateOperationData, "operator" | "operatorId">>>; oper$operator?: OakOperation<"create", Omit<Oper.CreateOperationData, "operator" | "operatorId">[]> | Array<OakOperation<"create", Omit<Oper.CreateOperationData, "operator" | "operatorId">>>;
user$ref?: UpdateOperation | RemoveOperation | OakOperation<"create", Omit<CreateOperationData, "ref" | "refId">[]> | Array<OakOperation<"create", Omit<CreateOperationData, "ref" | "refId">> | UpdateOperation | RemoveOperation>;
operEntity$entity?: OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">>>; operEntity$entity?: OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">>>;
modiEntity$entity?: OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">>>; modiEntity$entity?: OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">>>;
}; };
export declare type UpdateOperation = OakOperation<"update" | RelationAction | string, UpdateOperationData, Filter, Sorter>; export declare type UpdateOperation = OakOperation<"update" | ParticularAction | RelationAction | string, UpdateOperationData, Filter, Sorter>;
export declare type RemoveOperationData = {}; export declare type RemoveOperationData = {} & (({
ref?: UpdateOperation | RemoveOperation;
}));
export declare type RemoveOperation = OakOperation<"remove", RemoveOperationData, Filter, Sorter>; export declare type RemoveOperation = OakOperation<"remove", RemoveOperationData, Filter, Sorter>;
export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation; export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation;
export declare type UserIdSubQuery = Selection<UserIdProjection>; export declare type UserIdSubQuery = Selection<UserIdProjection>;
export declare type EntityDef = { export declare type EntityDef = {
Schema: Schema; Schema: Schema;
OpSchema: OpSchema; OpSchema: OpSchema;
Action: OakMakeAction<GenericAction | RelationAction> | string; Action: OakMakeAction<Action | RelationAction> | string;
Selection: Selection; Selection: Selection;
Aggregation: Aggregation; Aggregation: Aggregation;
Operation: Operation; Operation: Operation;
@ -124,5 +175,6 @@ export declare type EntityDef = {
Remove: RemoveOperation; Remove: RemoveOperation;
CreateSingle: CreateSingleOperation; CreateSingle: CreateSingleOperation;
CreateMulti: CreateMultipleOperation; CreateMulti: CreateMultipleOperation;
ParticularAction: ParticularAction;
}; };
export {}; export {};

View File

@ -1,6 +1,7 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.desc = void 0; exports.desc = void 0;
var Action_1 = require("./Action");
var action_1 = require("../../actions/action"); var action_1 = require("../../actions/action");
exports.desc = { exports.desc = {
attributes: { attributes: {
@ -18,8 +19,18 @@ exports.desc = {
}, },
password: { password: {
type: "text" type: "text"
},
refId: {
type: "ref",
ref: "user"
},
userState: {
type: "varchar",
params: {
length: 24
}
} }
}, },
actionType: "crud", actionType: "crud",
actions: action_1.genericActions.concat(action_1.relationActions) actions: Action_1.actions.concat(action_1.relationActions)
}; };

View File

@ -0,0 +1,121 @@
import { String } from "../../types/DataType";
import { Q_DateValue, Q_StringValue, NodeId, MakeFilter, ExprOp, ExpressionKey } from "../../types/Demand";
import { OneOf } from "../../types/Polyfill";
import * as SubQuery from "../_SubQuery";
import { FormCreateData, FormUpdateData, DeduceAggregation, Operation as OakOperation, Selection as OakSelection, MakeAction as OakMakeAction, EntityShape, AggregationResult } from "../../types/Entity";
import { GenericAction } from "../../actions/action";
import * as OperEntity from "../OperEntity/Schema";
import * as ModiEntity from "../ModiEntity/Schema";
export declare type OpSchema = EntityShape & {
entity: String<32>;
entityId: String<64>;
relation: String<32>;
};
export declare type OpAttr = keyof OpSchema;
export declare type Schema = EntityShape & {
entity: String<32>;
entityId: String<64>;
relation: String<32>;
operEntity$entity?: Array<OperEntity.Schema>;
operEntity$entity$$aggr?: AggregationResult<OperEntity.Schema>;
modiEntity$entity?: Array<ModiEntity.Schema>;
modiEntity$entity$$aggr?: AggregationResult<ModiEntity.Schema>;
} & {
[A in ExpressionKey]?: any;
};
declare type AttrFilter = {
id: Q_StringValue | SubQuery.UserEntityGrantIdSubQuery;
$$createAt$$: Q_DateValue;
$$seq$$: Q_StringValue;
$$updateAt$$: Q_DateValue;
entity: Q_StringValue;
entityId: Q_StringValue;
relation: Q_StringValue;
};
export declare type Filter = MakeFilter<AttrFilter & ExprOp<OpAttr | string>>;
export declare type Projection = {
"#id"?: NodeId;
[k: string]: any;
id?: number;
$$createAt$$?: number;
$$updateAt$$?: number;
$$seq$$?: number;
entity?: number;
entityId?: number;
relation?: number;
operEntity$entity?: OperEntity.Selection & {
$entity: "operEntity";
};
operEntity$entity$$aggr?: OperEntity.Aggregation & {
$entity: "operEntity";
};
modiEntity$entity?: ModiEntity.Selection & {
$entity: "modiEntity";
};
modiEntity$entity$$aggr?: ModiEntity.Aggregation & {
$entity: "modiEntity";
};
} & Partial<ExprOp<OpAttr | string>>;
declare type UserEntityGrantIdProjection = OneOf<{
id: number;
}>;
export declare type SortAttr = {
id: number;
} | {
$$createAt$$: number;
} | {
$$seq$$: number;
} | {
$$updateAt$$: number;
} | {
entity: number;
} | {
entityId: number;
} | {
relation: number;
} | {
[k: string]: any;
} | OneOf<ExprOp<OpAttr | string>>;
export declare type SortNode = {
$attr: SortAttr;
$direction?: "asc" | "desc";
};
export declare type Sorter = SortNode[];
export declare type SelectOperation<P extends Object = Projection> = OakSelection<"select", P, Filter, Sorter>;
export declare type Selection<P extends Object = Projection> = Omit<SelectOperation<P>, "action">;
export declare type Aggregation = DeduceAggregation<Projection, Filter, Sorter>;
export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "entity" | "entityId">> & ({
entity?: string;
entityId?: string;
[K: string]: any;
}) & {
operEntity$entity?: OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">>>;
modiEntity$entity?: OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">>>;
};
export declare type CreateSingleOperation = OakOperation<"create", CreateOperationData>;
export declare type CreateMultipleOperation = OakOperation<"create", Array<CreateOperationData>>;
export declare type CreateOperation = CreateSingleOperation | CreateMultipleOperation;
export declare type UpdateOperationData = FormUpdateData<OpSchema> & {
[k: string]: any;
operEntity$entity?: OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">>>;
modiEntity$entity?: OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">>>;
};
export declare type UpdateOperation = OakOperation<"update" | string, UpdateOperationData, Filter, Sorter>;
export declare type RemoveOperationData = {};
export declare type RemoveOperation = OakOperation<"remove", RemoveOperationData, Filter, Sorter>;
export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation;
export declare type UserEntityGrantIdSubQuery = Selection<UserEntityGrantIdProjection>;
export declare 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 {};

View File

@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

View File

@ -0,0 +1,3 @@
import { StorageDesc } from "../../types/Storage";
import { OpSchema } from "./Schema";
export declare const desc: StorageDesc<OpSchema>;

View File

@ -0,0 +1,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.desc = void 0;
var action_1 = require("../../actions/action");
exports.desc = {
attributes: {
entity: {
type: "varchar",
params: {
length: 32
}
},
entityId: {
type: "varchar",
params: {
length: 64
}
},
relation: {
type: "varchar",
params: {
length: 32
}
}
},
actionType: "crud",
actions: action_1.genericActions
};

View File

@ -3,6 +3,7 @@ import * as ModiEntity from "./ModiEntity/Schema";
import * as Oper from "./Oper/Schema"; import * as Oper from "./Oper/Schema";
import * as OperEntity from "./OperEntity/Schema"; import * as OperEntity from "./OperEntity/Schema";
import * as User from "./User/Schema"; import * as User from "./User/Schema";
import * as UserEntityGrant from "./UserEntityGrant/Schema";
export declare type ModiIdSubQuery = { export declare type ModiIdSubQuery = {
[K in "$in" | "$nin"]?: (ModiEntity.ModiIdSubQuery & { [K in "$in" | "$nin"]?: (ModiEntity.ModiIdSubQuery & {
entity: "modiEntity"; entity: "modiEntity";
@ -32,5 +33,12 @@ export declare type UserIdSubQuery = {
entity: "oper"; entity: "oper";
}) | (User.UserIdSubQuery & { }) | (User.UserIdSubQuery & {
entity: "user"; entity: "user";
}) | (User.UserIdSubQuery & {
entity: "user";
}) | any;
};
export declare type UserEntityGrantIdSubQuery = {
[K in "$in" | "$nin"]?: (UserEntityGrant.UserEntityGrantIdSubQuery & {
entity: "userEntityGrant";
}) | any; }) | any;
}; };

View File

@ -7,7 +7,7 @@ var modi_1 = require("../store/modi");
function createDynamicCheckers(schema, authDict) { function createDynamicCheckers(schema, authDict) {
var checkers = []; var checkers = [];
checkers.push.apply(checkers, tslib_1.__spreadArray([], tslib_1.__read((0, modi_1.createModiRelatedCheckers)(schema)), false)); checkers.push.apply(checkers, tslib_1.__spreadArray([], tslib_1.__read((0, modi_1.createModiRelatedCheckers)(schema)), false));
// checkers.push(...createRemoveCheckers<ED, Cxt>(schema)); checkers.push.apply(checkers, tslib_1.__spreadArray([], tslib_1.__read((0, checker_1.createRemoveCheckers)(schema)), false));
if (authDict) { if (authDict) {
checkers.push.apply(checkers, tslib_1.__spreadArray([], tslib_1.__read((0, checker_1.createAuthCheckers)(schema, authDict)), false)); checkers.push.apply(checkers, tslib_1.__spreadArray([], tslib_1.__read((0, checker_1.createAuthCheckers)(schema, authDict)), false));
} }

View File

@ -51,6 +51,20 @@ function addRelationship(many, one, key, notNull) {
_b)); _b));
} }
} }
/**
* 对relationship去重一旦发生对象重定义这里就有可能重复
*/
function uniqRelationships() {
for (var entity in ManyToOne) {
ManyToOne[entity] = (0, lodash_1.uniqBy)(ManyToOne[entity], function (ele) { return "".concat(ele[0], "-").concat(ele[1]); });
}
for (var entity in OneToMany) {
OneToMany[entity] = (0, lodash_1.uniqBy)(OneToMany[entity], function (ele) { return "".concat(ele[0], "-").concat(ele[1]); });
}
for (var entity in ReversePointerRelations) {
OneToMany[entity] = (0, lodash_1.uniq)(OneToMany[entity]);
}
}
function createForeignRef(entity, foreignKey, ref) { function createForeignRef(entity, foreignKey, ref) {
if (entity === foreignKey) { if (entity === foreignKey) {
return factory.createIdentifier(ref); return factory.createIdentifier(ref);
@ -317,9 +331,10 @@ function analyzeEntity(filename, path, program, relativePath) {
var sourceFile = program.getSourceFile(fullPath); var sourceFile = program.getSourceFile(fullPath);
var moduleName = filename.split('.')[0]; var moduleName = filename.split('.')[0];
if (Schema.hasOwnProperty(moduleName)) { if (Schema.hasOwnProperty(moduleName)) {
if (!path.includes('oak-general-business')) { delete ActionAsts[moduleName];
console.log("\u51FA\u73B0\u4E86\u540C\u540D\u7684Entity\u5B9A\u4E49\u300C".concat(moduleName, "\u300D\uFF0C\u5C06\u4F7F\u7528\u60A8\u6240\u5B9A\u4E49\u7684\u5BF9\u8C61\u7ED3\u6784\u53D6\u4EE3\u6389\u9ED8\u8BA4\u5BF9\u8C61\uFF0C\u8BF7\u786E\u8BA4")); delete SchemaAsts[moduleName];
} // removeFromRelationShip(moduleName);
console.warn("\u51FA\u73B0\u4E86\u540C\u540D\u7684Entity\u5B9A\u4E49\u300C".concat(moduleName, "\u300D\uFF0C\u5C06\u4F7F\u7528").concat(fullPath, "\u53D6\u4EE3\u6389\u9ED8\u8BA4\u5BF9\u8C61\uFF0C\u8BF7\u68C0\u67E5\u65B0\u7684\u5BF9\u8C61\u7ED3\u6784\u53CA\u76F8\u5173\u5E38\u91CF\u5B9A\u4E49\u4E0E\u539F\u6709\u7684\u517C\u5BB9\uFF0C\u5426\u5219\u539F\u6709\u5BF9\u8C61\u7684\u76F8\u5173\u903B\u8F91\u4F1A\u51FA\u73B0\u4E0D\u53EF\u77E5\u5F02\u5E38"));
} }
var referencedSchemas = []; var referencedSchemas = [];
var schemaAttrs = []; var schemaAttrs = [];
@ -340,7 +355,7 @@ function analyzeEntity(filename, path, program, relativePath) {
// let relationHierarchy: ts.ObjectLiteralExpression | undefined = undefined; // let relationHierarchy: ts.ObjectLiteralExpression | undefined = undefined;
// let reverseCascadeRelationHierarchy: ts.ObjectLiteralExpression | undefined = undefined; // let reverseCascadeRelationHierarchy: ts.ObjectLiteralExpression | undefined = undefined;
ts.forEachChild(sourceFile, function (node) { ts.forEachChild(sourceFile, function (node) {
var _a, _b, _c, _d; var _a, _b, _c, _d, _e;
if (ts.isImportDeclaration(node)) { if (ts.isImportDeclaration(node)) {
var entityImported = getEntityImported(node); var entityImported = getEntityImported(node);
if (entityImported) { if (entityImported) {
@ -389,7 +404,9 @@ function analyzeEntity(filename, path, program, relativePath) {
&& referencedSchemas.includes(typeArguments[0].typeName.text), "\u300C".concat(filename, "\u300D\u975E\u6CD5\u7684\u5C5E\u6027\u5B9A\u4E49\u300C").concat(attrName, "\u300D")); && referencedSchemas.includes(typeArguments[0].typeName.text), "\u300C".concat(filename, "\u300D\u975E\u6CD5\u7684\u5C5E\u6027\u5B9A\u4E49\u300C").concat(attrName, "\u300D"));
var reverseEntity = typeArguments[0].typeName.text; var reverseEntity = typeArguments[0].typeName.text;
if (ReversePointerRelations[reverseEntity]) { if (ReversePointerRelations[reverseEntity]) {
ReversePointerRelations[reverseEntity].push(moduleName); if (!ReversePointerRelations[reverseEntity].includes(moduleName)) {
ReversePointerRelations[reverseEntity].push(moduleName);
}
} }
else { else {
(0, lodash_1.assign)(ReversePointerRelations, (_a = {}, (0, lodash_1.assign)(ReversePointerRelations, (_a = {},
@ -520,6 +537,9 @@ function analyzeEntity(filename, path, program, relativePath) {
if (hasRelationDef || moduleName === 'User') { if (hasRelationDef || moduleName === 'User') {
actionDefNodes.push(factory.createTypeReferenceNode('RelationAction', undefined)); actionDefNodes.push(factory.createTypeReferenceNode('RelationAction', undefined));
} }
if (process.env.COMPLING_AS_LIB) {
actionDefNodes.push(factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword));
}
pushStatementIntoActionAst(moduleName, factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Action"), undefined, factory.createUnionTypeNode(actionDefNodes)), sourceFile); pushStatementIntoActionAst(moduleName, factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("Action"), undefined, factory.createUnionTypeNode(actionDefNodes)), sourceFile);
dealWithActions(moduleName, filename, node.type, program, sourceFile, !!hasRelationDef || moduleName === 'User'); dealWithActions(moduleName, filename, node.type, program, sourceFile, !!hasRelationDef || moduleName === 'User');
} }
@ -558,12 +578,35 @@ function analyzeEntity(filename, path, program, relativePath) {
_d)); _d));
addRelationship(relationEntityName, 'User', 'user', true); addRelationship(relationEntityName, 'User', 'user', true);
addRelationship(relationEntityName, moduleName, entityLc, true); addRelationship(relationEntityName, moduleName, entityLc, true);
// 对UserEntityGrant对象建立相应的反指关系
if (ReversePointerRelations['UserEntityGrant']) {
if (!ReversePointerRelations['UserEntityGrant'].includes(moduleName)) {
ReversePointerRelations['UserEntityGrant'].push(moduleName);
}
}
else {
(0, lodash_1.assign)(ReversePointerRelations, (_e = {},
_e['UserEntityGrant'] = [moduleName],
_e));
}
hasRelationDef = node; hasRelationDef = node;
} }
else if (node.name.text.endsWith('Action') || node.name.text.endsWith('State')) { else if (node.name.text.endsWith('Action') || node.name.text.endsWith('State')) {
(0, assert_1.default)(!localeDef, "\u3010".concat(filename, "\u3011locale\u5B9A\u4E49\u987B\u5728Action/State\u4E4B\u540E")); (0, assert_1.default)(!localeDef, "\u3010".concat(filename, "\u3011locale\u5B9A\u4E49\u987B\u5728Action/State\u4E4B\u540E"));
hasActionOrStateDef = true; hasActionOrStateDef = true;
pushStatementIntoActionAst(moduleName, factory.updateTypeAliasDeclaration(node, node.decorators, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], node.name, node.typeParameters, node.type), sourceFile); var type = node.type;
if (ts.isUnionTypeNode(type)) {
pushStatementIntoActionAst(moduleName, factory.updateTypeAliasDeclaration(node, node.decorators, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], node.name, node.typeParameters, process.env.COMPLING_AS_LIB ? factory.createUnionTypeNode(tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(type.types), false), [
factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
], false)) : type), sourceFile);
}
else {
(0, assert_1.default)(ts.isLiteralTypeNode(type) || ts.isTypeReferenceNode(type), "".concat(moduleName, " - ").concat(node.name));
pushStatementIntoActionAst(moduleName, factory.updateTypeAliasDeclaration(node, node.decorators, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], node.name, node.typeParameters, process.env.COMPLING_AS_LIB ? factory.createUnionTypeNode([
type,
factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
]) : type), sourceFile);
}
} }
else if (beforeSchema) { else if (beforeSchema) {
// 本地规定的一些形状定义,直接使用 // 本地规定的一些形状定义,直接使用
@ -3291,6 +3334,7 @@ function analyzeEntities(inputDir, relativePath) {
analyzeEntity(filename, inputDir, program, relativePath); analyzeEntity(filename, inputDir, program, relativePath);
}); });
analyzeInModi(); analyzeInModi();
uniqRelationships();
} }
exports.analyzeEntities = analyzeEntities; exports.analyzeEntities = analyzeEntities;
function buildSchema(outputDir) { function buildSchema(outputDir) {

View File

@ -4,4 +4,5 @@ export interface Schema extends EntityShape {
name?: String<16>; name?: String<16>;
nickname?: String<64>; nickname?: String<64>;
password?: Text; password?: Text;
ref?: Schema;
} }

View File

@ -1,12 +1,28 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
; ;
var UserActionDef = {
stm: {
mergeTo: ['normal', 'merged'],
},
};
var locale = { var locale = {
zh_CN: { zh_CN: {
attr: { attr: {
name: '姓名', name: '姓名',
nickname: '昵称', nickname: '昵称',
password: '密码', password: '密码',
ref: '指向用户',
userState: '状态',
}, },
action: {
mergeTo: '合并',
},
v: {
userState: {
normal: '正常',
merged: '已被合并',
},
}
}, },
}; };

7
lib/entities/UserEntityGrant.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
import { String } from '../types/DataType';
import { EntityShape } from '../types/Entity';
export interface Schema extends EntityShape {
entity: String<32>;
entityId: String<64>;
relation: String<32>;
}

View File

@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
;
var locale = {
zh_CN: {
attr: {
relation: '关系',
entity: '关联对象',
entityId: '关联对象id',
},
},
};

View File

@ -546,8 +546,8 @@ function createRemoveCheckers(schema) {
} }
}; };
for (var entity in schema) { for (var entity in schema) {
if (['operEntity'].includes(entity)) { if (['operEntity', 'modiEntity', 'userEntityGrant'].includes(entity)) {
continue; // OperEntity会指向每一个对象不必处理 continue; // 系统功能性数据,不用处理
} }
var attributes = schema[entity].attributes; var attributes = schema[entity].attributes;
for (var attr in attributes) { for (var attr in attributes) {
@ -565,7 +565,7 @@ function createRemoveCheckers(schema) {
} }
} }
// 当删除一时,要确认多上面没有指向一的数据 // 当删除一时,要确认多上面没有指向一的数据
var entities = (0, lodash_1.intersection)(Object.keys(OneToManyMatrix), Object.keys(OneToManyOnEntityMatrix)); var entities = (0, lodash_1.union)(Object.keys(OneToManyMatrix), Object.keys(OneToManyOnEntityMatrix));
var _loop_3 = function (entity) { var _loop_3 = function (entity) {
checkers.push({ checkers.push({
entity: entity, entity: entity,

View File

@ -2,6 +2,7 @@
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.createModiRelatedTriggers = exports.createModiRelatedCheckers = exports.abandonModis = exports.applyModis = exports.createOperationsFromModies = void 0; exports.createModiRelatedTriggers = exports.createModiRelatedCheckers = exports.abandonModis = exports.applyModis = exports.createOperationsFromModies = void 0;
var tslib_1 = require("tslib"); var tslib_1 = require("tslib");
var types_1 = require("../types");
var action_1 = require("../actions/action"); var action_1 = require("../actions/action");
var lodash_1 = require("../utils/lodash"); var lodash_1 = require("../utils/lodash");
var uuid_1 = require("../utils/uuid"); var uuid_1 = require("../utils/uuid");
@ -154,35 +155,52 @@ function createModiRelatedTriggers(schema) {
if (inModi) { if (inModi) {
// 当关联modi的对象被删除时对应的modi也删除 // 当关联modi的对象被删除时对应的modi也删除
triggers.push({ triggers.push({
name: "\u5F53\u5220\u9664".concat(entity, "\u5BF9\u8C61\u65F6\uFF0C\u5220\u9664\u76F8\u5173\u8054\u8FD8\u6D3B\u8DC3\u7684modi"), name: "\u5F53\u5220\u9664".concat(entity, "\u5BF9\u8C61\u65F6\uFF0C\u5220\u9664\u76F8\u5173\u8054\u7684modi\u7684modiEntity"),
action: 'remove', action: 'remove',
entity: entity, entity: entity,
when: 'after', when: 'after',
priority: types_1.REMOVE_CASCADE_PRIORITY,
fn: function (_a, context, option) { fn: function (_a, context, option) {
var operation = _a.operation; var operation = _a.operation;
return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
var data, id, _b, _c, _d; var data, id, _b, _c, _d, _e, _f, _g;
var _e; var _h, _j;
return tslib_1.__generator(this, function (_f) { return tslib_1.__generator(this, function (_k) {
switch (_f.label) { switch (_k.label) {
case 0: case 0:
data = operation.data; data = operation.data;
id = data.id; id = data.id;
_c = (_b = context).operate; _c = (_b = context).operate;
_d = ['modi']; _d = ['modiEntity'];
_e = {}; _h = {};
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()]; return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
case 1: return [4 /*yield*/, _c.apply(_b, _d.concat([(_e.id = _f.sent(), case 1: return [4 /*yield*/, _c.apply(_b, _d.concat([(_h.id = _k.sent(),
_e.action = 'remove', _h.action = 'remove',
_e.data = {}, _h.data = {},
_e.filter = { _h.filter = {
modi: {
entity: entity,
entityId: id,
},
},
_h), { dontCollect: true }]))];
case 2:
_k.sent();
_f = (_e = context).operate;
_g = ['modi'];
_j = {};
return [4 /*yield*/, (0, uuid_1.generateNewIdAsync)()];
case 3: return [4 /*yield*/, _f.apply(_e, _g.concat([(_j.id = _k.sent(),
_j.action = 'remove',
_j.data = {},
_j.filter = {
entity: entity, entity: entity,
entityId: id, entityId: id,
}, },
_e), option]))]; _j), { dontCollect: true }]))];
case 2: case 4:
_f.sent(); _k.sent();
return [2 /*return*/, 1]; return [2 /*return*/, 0];
} }
}); });
}); });

View File

@ -12,6 +12,7 @@ export declare const TRIGGER_MIN_PRIORITY = 1;
export declare const TRIGGER_MAX_PRIORITY = 99; export declare const TRIGGER_MAX_PRIORITY = 99;
export declare const DATA_CHECKER_DEFAULT_PRIORITY = 60; export declare const DATA_CHECKER_DEFAULT_PRIORITY = 60;
export declare const CHECKER_DEFAULT_PRIORITY = 99; export declare const CHECKER_DEFAULT_PRIORITY = 99;
export declare const REMOVE_CASCADE_PRIORITY = 70;
interface TriggerBase<ED extends EntityDict, T extends keyof ED> { interface TriggerBase<ED extends EntityDict, T extends keyof ED> {
checkerType?: CheckerType; checkerType?: CheckerType;
entity: T; entity: T;

View File

@ -1,6 +1,6 @@
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "__esModule", { value: true });
exports.CHECKER_DEFAULT_PRIORITY = exports.DATA_CHECKER_DEFAULT_PRIORITY = exports.TRIGGER_MAX_PRIORITY = exports.TRIGGER_MIN_PRIORITY = exports.TRIGGER_DEFAULT_PRIORITY = void 0; exports.REMOVE_CASCADE_PRIORITY = exports.CHECKER_DEFAULT_PRIORITY = exports.DATA_CHECKER_DEFAULT_PRIORITY = exports.TRIGGER_MAX_PRIORITY = exports.TRIGGER_MIN_PRIORITY = exports.TRIGGER_DEFAULT_PRIORITY = void 0;
/** /**
* 优先级越小越早执行定义在199之间 * 优先级越小越早执行定义在199之间
*/ */
@ -9,6 +9,7 @@ exports.TRIGGER_MIN_PRIORITY = 1;
exports.TRIGGER_MAX_PRIORITY = 99; exports.TRIGGER_MAX_PRIORITY = 99;
exports.DATA_CHECKER_DEFAULT_PRIORITY = 60; exports.DATA_CHECKER_DEFAULT_PRIORITY = 60;
exports.CHECKER_DEFAULT_PRIORITY = 99; exports.CHECKER_DEFAULT_PRIORITY = 99;
exports.REMOVE_CASCADE_PRIORITY = 70;
; ;
; ;
; ;

View File

@ -1,6 +1,6 @@
{ {
"name": "oak-domain", "name": "oak-domain",
"version": "2.4.4", "version": "2.5.1",
"author": { "author": {
"name": "XuChang" "name": "XuChang"
}, },

View File

@ -8,7 +8,7 @@ import { StorageSchema, EntityDict as BaseEntityDict, Checker, AuthDef, AuthDefD
export function createDynamicCheckers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>>(schema: StorageSchema<ED>, authDict?: AuthDefDict<ED>){ export function createDynamicCheckers<ED extends EntityDict & BaseEntityDict, Cxt extends AsyncContext<ED> | SyncContext<ED>>(schema: StorageSchema<ED>, authDict?: AuthDefDict<ED>){
const checkers: Checker<ED, keyof ED, Cxt>[] = []; const checkers: Checker<ED, keyof ED, Cxt>[] = [];
checkers.push(...createModiRelatedCheckers<ED, Cxt>(schema)); checkers.push(...createModiRelatedCheckers<ED, Cxt>(schema));
// checkers.push(...createRemoveCheckers<ED, Cxt>(schema)); checkers.push(...createRemoveCheckers<ED, Cxt>(schema));
if (authDict) { if (authDict) {
checkers.push(...createAuthCheckers<ED, Cxt>(schema, authDict)); checkers.push(...createAuthCheckers<ED, Cxt>(schema, authDict));
} }

View File

@ -139,6 +139,22 @@ function addRelationship(many: string, one: string, key: string, notNull: boolea
} }
} }
/**
* relationship去重
*/
function uniqRelationships() {
for (const entity in ManyToOne) {
ManyToOne[entity] = uniqBy(ManyToOne[entity], (ele) => `${ele[0]}-${ele[1]}`);
}
for (const entity in OneToMany) {
OneToMany[entity] = uniqBy(OneToMany[entity], (ele) => `${ele[0]}-${ele[1]}`);
}
for (const entity in ReversePointerRelations) {
OneToMany[entity] = uniq(OneToMany[entity]);
}
}
function createForeignRef(entity: string, foreignKey: string, ref: string) { function createForeignRef(entity: string, foreignKey: string, ref: string) {
if (entity === foreignKey) { if (entity === foreignKey) {
return factory.createIdentifier(ref) return factory.createIdentifier(ref)
@ -477,9 +493,10 @@ function analyzeEntity(filename: string, path: string, program: ts.Program, rela
const moduleName = filename.split('.')[0]; const moduleName = filename.split('.')[0];
if (Schema.hasOwnProperty(moduleName)) { if (Schema.hasOwnProperty(moduleName)) {
if (!path.includes('oak-general-business')) { delete ActionAsts[moduleName];
console.log(`出现了同名的Entity定义「${moduleName}」,将使用您所定义的对象结构取代掉默认对象,请确认`); delete SchemaAsts[moduleName];
} // removeFromRelationShip(moduleName);
console.warn(`出现了同名的Entity定义「${moduleName}」,将使用${fullPath}取代掉默认对象,请检查新的对象结构及相关常量定义与原有的兼容,否则原有对象的相关逻辑会出现不可知异常`);
} }
const referencedSchemas: string[] = []; const referencedSchemas: string[] = [];
const schemaAttrs: ts.TypeElement[] = []; const schemaAttrs: ts.TypeElement[] = [];
@ -565,7 +582,9 @@ function analyzeEntity(filename: string, path: string, program: ts.Program, rela
`${filename}」非法的属性定义「${attrName}`); `${filename}」非法的属性定义「${attrName}`);
const reverseEntity = typeArguments![0].typeName.text; const reverseEntity = typeArguments![0].typeName.text;
if (ReversePointerRelations[reverseEntity]) { if (ReversePointerRelations[reverseEntity]) {
ReversePointerRelations[reverseEntity].push(moduleName); if (!ReversePointerRelations[reverseEntity].includes(moduleName)) {
ReversePointerRelations[reverseEntity].push(moduleName);
}
} }
else { else {
assign(ReversePointerRelations, { assign(ReversePointerRelations, {
@ -721,7 +740,7 @@ function analyzeEntity(filename: string, path: string, program: ts.Program, rela
'ParticularAction', 'ParticularAction',
undefined undefined
) )
]; ] as ts.TypeNode[];
if (hasRelationDef || moduleName === 'User') { if (hasRelationDef || moduleName === 'User') {
actionDefNodes.push( actionDefNodes.push(
factory.createTypeReferenceNode( factory.createTypeReferenceNode(
@ -730,6 +749,11 @@ function analyzeEntity(filename: string, path: string, program: ts.Program, rela
) )
); );
} }
if (process.env.COMPLING_AS_LIB) {
actionDefNodes.push(
factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
);
}
pushStatementIntoActionAst( pushStatementIntoActionAst(
moduleName, moduleName,
factory.createTypeAliasDeclaration( factory.createTypeAliasDeclaration(
@ -819,21 +843,55 @@ function analyzeEntity(filename: string, path: string, program: ts.Program, rela
addRelationship(relationEntityName, 'User', 'user', true); addRelationship(relationEntityName, 'User', 'user', true);
addRelationship(relationEntityName, moduleName, entityLc, true); addRelationship(relationEntityName, moduleName, entityLc, true);
// 对UserEntityGrant对象建立相应的反指关系
if (ReversePointerRelations['UserEntityGrant']) {
if (!ReversePointerRelations['UserEntityGrant'].includes(moduleName)) {
ReversePointerRelations['UserEntityGrant'].push(moduleName);
}
}
else {
assign(ReversePointerRelations, {
['UserEntityGrant']: [moduleName],
});
}
hasRelationDef = node; hasRelationDef = node;
} }
else if (node.name.text.endsWith('Action') || node.name.text.endsWith('State')) { else if (node.name.text.endsWith('Action') || node.name.text.endsWith('State')) {
assert(!localeDef, `${filename}】locale定义须在Action/State之后`); assert(!localeDef, `${filename}】locale定义须在Action/State之后`);
hasActionOrStateDef = true; hasActionOrStateDef = true;
pushStatementIntoActionAst(moduleName, const { type } = node;
factory.updateTypeAliasDeclaration( if (ts.isUnionTypeNode(type)) {
node, pushStatementIntoActionAst(moduleName,
node.decorators, factory.updateTypeAliasDeclaration(
[factory.createModifier(ts.SyntaxKind.ExportKeyword)], node,
node.name, node.decorators,
node.typeParameters, [factory.createModifier(ts.SyntaxKind.ExportKeyword)],
node.type node.name,
), node.typeParameters,
sourceFile!); process.env.COMPLING_AS_LIB ? factory.createUnionTypeNode([
...type.types,
factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
]) : type
),
sourceFile!);
}
else {
assert(ts.isLiteralTypeNode(type) || ts.isTypeReferenceNode(type), `${moduleName} - ${node.name}`);
pushStatementIntoActionAst(moduleName,
factory.updateTypeAliasDeclaration(
node,
node.decorators,
[factory.createModifier(ts.SyntaxKind.ExportKeyword)],
node.name,
node.typeParameters,
process.env.COMPLING_AS_LIB ? factory.createUnionTypeNode([
type,
factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)
]) : type
),
sourceFile!);
}
} }
else if (beforeSchema) { else if (beforeSchema) {
// 本地规定的一些形状定义,直接使用 // 本地规定的一些形状定义,直接使用
@ -5237,7 +5295,7 @@ function constructAttributes(entity: string): ts.PropertyAssignment[] {
ele => factory.createStringLiteral(ele) ele => factory.createStringLiteral(ele)
), ),
false false
) )
) )
); );
} }
@ -6146,6 +6204,7 @@ export function analyzeEntities(inputDir: string, relativePath?: string) {
} }
); );
analyzeInModi(); analyzeInModi();
uniqRelationships();
} }
export function buildSchema(outputDir: string): void { export function buildSchema(outputDir: string): void {

View File

@ -1,20 +1,45 @@
import { String, Int, Text, Image, Datetime } from '../types/DataType'; import { String, Int, Text, Image, Datetime } from '../types/DataType';
import { LocaleDef } from '../types/Locale'; import { LocaleDef } from '../types/Locale';
import { EntityShape } from '../types/Entity'; import { EntityShape } from '../types/Entity';
import { ActionDef } from '../types/Action';
export interface Schema extends EntityShape { export interface Schema extends EntityShape {
name?: String<16>; name?: String<16>;
nickname?: String<64>; nickname?: String<64>;
password?: Text; password?: Text;
ref?: Schema;
}; };
type UserAction = 'mergeTo';
type UserState = 'normal' | 'merged';
const locale: LocaleDef<Schema, '', '', {}> = { type Action = UserAction;
const UserActionDef: ActionDef<UserAction, UserState> = {
stm: {
mergeTo: ['normal', 'merged'],
},
};
const locale: LocaleDef<Schema, Action, '', {
userState: UserState;
}> = {
zh_CN: { zh_CN: {
attr: { attr: {
name: '姓名', name: '姓名',
nickname: '昵称', nickname: '昵称',
password: '密码', password: '密码',
ref: '指向用户',
userState: '状态',
}, },
action: {
mergeTo: '合并',
},
v: {
userState: {
normal: '正常',
merged: '已被合并',
},
}
}, },
}; };

View File

@ -0,0 +1,24 @@
import { String } from '../types/DataType';
import { LocaleDef } from '../types/Locale';
import { EntityShape } from '../types/Entity';
export interface Schema extends EntityShape {
entity: String<32>;
entityId: String<64>;
relation: String<32>;
};
const locale: LocaleDef<
Schema,
'',
'',
{}
> = {
zh_CN: {
attr: {
relation: '关系',
entity: '关联对象',
entityId: '关联对象id',
},
},
};

View File

@ -10,7 +10,7 @@ import { AsyncContext } from "./AsyncRowStore";
import { getFullProjection } from './actionDef'; import { getFullProjection } from './actionDef';
import { SyncContext } from './SyncRowStore'; import { SyncContext } from './SyncRowStore';
import { firstLetterUpperCase } from '../utils/string'; import { firstLetterUpperCase } from '../utils/string';
import { intersection, uniq, difference } from '../utils/lodash'; import { union, uniq, difference } from '../utils/lodash';
import { judgeRelation } from './relation'; import { judgeRelation } from './relation';
export function translateCheckerInAsyncContext< export function translateCheckerInAsyncContext<
@ -518,8 +518,8 @@ export function createRemoveCheckers<ED extends EntityDict & BaseEntityDict, Cxt
}; };
for (const entity in schema) { for (const entity in schema) {
if (['operEntity'].includes(entity)) { if (['operEntity', 'modiEntity', 'userEntityGrant'].includes(entity)) {
continue; // OperEntity会指向每一个对象不必处理 continue; // 系统功能性数据,不用处理
} }
const { attributes } = schema[entity]; const { attributes } = schema[entity];
for (const attr in attributes) { for (const attr in attributes) {
@ -538,7 +538,7 @@ export function createRemoveCheckers<ED extends EntityDict & BaseEntityDict, Cxt
} }
// 当删除一时,要确认多上面没有指向一的数据 // 当删除一时,要确认多上面没有指向一的数据
const entities = intersection(Object.keys(OneToManyMatrix), Object.keys(OneToManyOnEntityMatrix)); const entities = union(Object.keys(OneToManyMatrix), Object.keys(OneToManyOnEntityMatrix));
for (const entity of entities) { for (const entity of entities) {
checkers.push({ checkers.push({
entity: entity as keyof ED, entity: entity as keyof ED,

View File

@ -1,6 +1,6 @@
import { EntityDict as BaseEntityDict } from '../base-app-domain'; import { EntityDict as BaseEntityDict } from '../base-app-domain';
import { OpSchema as Modi, Filter } from '../base-app-domain/Modi/Schema'; import { OpSchema as Modi } from '../base-app-domain/Modi/Schema';
import { Checker, Operation, StorageSchema, RowChecker, EntityDict, OakRowLockedException, Context, OperateOption, Trigger, RemoveTrigger, RelationChecker, LogicalChecker, LogicalRelationChecker, OakUserUnpermittedException } from '../types'; import { Operation, StorageSchema, RowChecker, EntityDict, OperateOption, Trigger, RemoveTrigger, REMOVE_CASCADE_PRIORITY } from '../types';
import { appendOnlyActions } from '../actions/action'; import { appendOnlyActions } from '../actions/action';
import { difference } from '../utils/lodash'; import { difference } from '../utils/lodash';
import { AsyncContext } from './AsyncRowStore'; import { AsyncContext } from './AsyncRowStore';
@ -153,13 +153,25 @@ export function createModiRelatedTriggers<ED extends EntityDict & BaseEntityDict
if (inModi) { if (inModi) {
// 当关联modi的对象被删除时对应的modi也删除 // 当关联modi的对象被删除时对应的modi也删除
triggers.push({ triggers.push({
name: `当删除${entity}对象时,删除相关联还活跃的modi`, name: `当删除${entity}对象时,删除相关联的modi的modiEntity`,
action: 'remove', action: 'remove',
entity, entity,
when: 'after', when: 'after',
priority: REMOVE_CASCADE_PRIORITY,
fn: async ({ operation }, context, option) => { fn: async ({ operation }, context, option) => {
const { data } = operation; const { data } = operation;
const { id } = data; const { id } = data;
await context.operate('modiEntity', {
id: await generateNewIdAsync(),
action: 'remove',
data: {},
filter: {
modi: {
entity,
entityId: id,
},
}
}, { dontCollect: true });
await context.operate('modi', { await context.operate('modi', {
id: await generateNewIdAsync(), id: await generateNewIdAsync(),
action: 'remove', action: 'remove',
@ -168,8 +180,8 @@ export function createModiRelatedTriggers<ED extends EntityDict & BaseEntityDict
entity, entity,
entityId: id, entityId: id,
} }
}, option); }, { dontCollect: true });
return 1; return 0;
}, },
} as RemoveTrigger<ED, keyof ED, Cxt>); } as RemoveTrigger<ED, keyof ED, Cxt>);
} }

View File

@ -13,6 +13,7 @@ export const TRIGGER_MIN_PRIORITY = 1;
export const TRIGGER_MAX_PRIORITY = 99; export const TRIGGER_MAX_PRIORITY = 99;
export const DATA_CHECKER_DEFAULT_PRIORITY = 60; export const DATA_CHECKER_DEFAULT_PRIORITY = 60;
export const CHECKER_DEFAULT_PRIORITY = 99; export const CHECKER_DEFAULT_PRIORITY = 99;
export const REMOVE_CASCADE_PRIORITY = 70;
interface TriggerBase<ED extends EntityDict, T extends keyof ED> { interface TriggerBase<ED extends EntityDict, T extends keyof ED> {
checkerType?: CheckerType; checkerType?: CheckerType;