Merge branch 'release'

This commit is contained in:
Xu Chang 2023-06-12 19:31:19 +08:00
commit b0d81bbe68
58 changed files with 8185 additions and 100 deletions

View File

@ -0,0 +1,156 @@
import { String, ForeignKey } from "../../types/DataType";
import { Q_DateValue, Q_StringValue, Q_EnumValue, 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 Relation from "../Relation/Schema";
import * as ModiEntity from "../ModiEntity/Schema";
import * as OperEntity from "../OperEntity/Schema";
declare type Actions = string[];
export declare type OpSchema = EntityShape & {
relationId: ForeignKey<"relation">;
path: String<256>;
destEntity: String<32>;
deActions: Actions;
};
export declare type OpAttr = keyof OpSchema;
export declare type Schema = EntityShape & {
relationId: ForeignKey<"relation">;
path: String<256>;
destEntity: String<32>;
deActions: Actions;
relation: Relation.Schema;
modiEntity$entity?: Array<ModiEntity.Schema>;
modiEntity$entity$$aggr?: AggregationResult<ModiEntity.Schema>;
operEntity$entity?: Array<OperEntity.Schema>;
operEntity$entity$$aggr?: AggregationResult<OperEntity.Schema>;
} & {
[A in ExpressionKey]?: any;
};
declare type AttrFilter = {
id: Q_StringValue | SubQuery.ActionAuthIdSubQuery;
$$createAt$$: Q_DateValue;
$$seq$$: Q_StringValue;
$$updateAt$$: Q_DateValue;
relationId: Q_StringValue | SubQuery.RelationIdSubQuery;
relation: Relation.Filter;
path: Q_StringValue;
destEntity: Q_StringValue;
deActions: Q_EnumValue<Actions>;
};
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;
relationId?: number;
relation?: Relation.Projection;
path?: number;
destEntity?: number;
deActions?: number;
modiEntity$entity?: ModiEntity.Selection & {
$entity: "modiEntity";
};
modiEntity$entity$$aggr?: ModiEntity.Aggregation & {
$entity: "modiEntity";
};
operEntity$entity?: OperEntity.Selection & {
$entity: "operEntity";
};
operEntity$entity$$aggr?: OperEntity.Aggregation & {
$entity: "operEntity";
};
} & Partial<ExprOp<OpAttr | string>>;
declare type ActionAuthIdProjection = OneOf<{
id: number;
}>;
declare type RelationIdProjection = OneOf<{
relationId: number;
}>;
export declare type SortAttr = {
id: number;
} | {
$$createAt$$: number;
} | {
$$seq$$: number;
} | {
$$updateAt$$: number;
} | {
relationId: number;
} | {
relation: Relation.SortAttr;
} | {
path: number;
} | {
destEntity: number;
} | {
deActions: 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, "relationId">> & (({
relationId?: never;
relation: Relation.CreateSingleOperation;
} | {
relationId: String<64>;
relation?: Relation.UpdateOperation;
} | {
relationId: String<64>;
})) & {
modiEntity$entity?: OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">>>;
operEntity$entity?: OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<OperEntity.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<Omit<OpSchema, "relationId">> & (({
relation: Relation.CreateSingleOperation;
relationId?: never;
} | {
relation: Relation.UpdateOperation;
relationId?: never;
} | {
relation: Relation.RemoveOperation;
relationId?: never;
} | {
relation?: never;
relationId?: String<64> | null;
})) & {
[k: string]: any;
modiEntity$entity?: OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">>>;
operEntity$entity?: OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">>>;
};
export declare type UpdateOperation = OakOperation<"update" | string, UpdateOperationData, Filter, Sorter>;
export declare type RemoveOperationData = {} & (({
relation?: Relation.UpdateOperation | Relation.RemoveOperation;
}));
export declare type RemoveOperation = OakOperation<"remove", RemoveOperationData, Filter, Sorter>;
export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation;
export declare type RelationIdSubQuery = Selection<RelationIdProjection>;
export declare type ActionAuthIdSubQuery = Selection<ActionAuthIdProjection>;
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,49 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.desc = void 0;
var action_1 = require("../../actions/action");
exports.desc = {
attributes: {
relationId: {
notNull: true,
type: "ref",
ref: "relation"
},
path: {
notNull: true,
type: "varchar",
params: {
length: 256
}
},
destEntity: {
notNull: true,
type: "varchar",
params: {
length: 32
}
},
deActions: {
notNull: true,
type: "object"
}
},
actionType: "crud",
actions: action_1.genericActions,
indexes: [
{
name: 'index_relation_path',
attributes: [
{
name: "relationId"
},
{
name: 'path'
},
],
config: {
unique: true
}
}
]
};

View File

@ -1,14 +1,22 @@
import { EntityDef as ActionAuth } from "./ActionAuth/Schema";
import { EntityDef as Modi } from "./Modi/Schema";
import { EntityDef as ModiEntity } from "./ModiEntity/Schema";
import { EntityDef as Oper } from "./Oper/Schema";
import { EntityDef as OperEntity } from "./OperEntity/Schema";
import { EntityDef as Relation } from "./Relation/Schema";
import { EntityDef as RelationAuth } from "./RelationAuth/Schema";
import { EntityDef as User } from "./User/Schema";
import { EntityDef as UserEntityGrant } from "./UserEntityGrant/Schema";
import { EntityDef as UserRelation } from "./UserRelation/Schema";
export declare type EntityDict = {
actionAuth: ActionAuth;
modi: Modi;
modiEntity: ModiEntity;
oper: Oper;
operEntity: OperEntity;
relation: Relation;
relationAuth: RelationAuth;
user: User;
userEntityGrant: UserEntityGrant;
userRelation: UserRelation;
};

View File

@ -5,21 +5,29 @@ import * as SubQuery from "../_SubQuery";
import { FormCreateData, FormUpdateData, DeduceAggregation, Operation as OakOperation, Selection as OakSelection, MakeAction as OakMakeAction, EntityShape } from "../../types/Entity";
import { AppendOnlyAction } from "../../actions/action";
import * as Modi from "../Modi/Schema";
import * as ActionAuth from "../ActionAuth/Schema";
import * as Relation from "../Relation/Schema";
import * as RelationAuth from "../RelationAuth/Schema";
import * as User from "../User/Schema";
import * as UserEntityGrant from "../UserEntityGrant/Schema";
import * as UserRelation from "../UserRelation/Schema";
export declare type OpSchema = EntityShape & {
modiId: ForeignKey<"modi">;
entity: "user" | "userEntityGrant" | string;
entity: "actionAuth" | "relation" | "relationAuth" | "user" | "userEntityGrant" | "userRelation" | string;
entityId: String<64>;
};
export declare type OpAttr = keyof OpSchema;
export declare type Schema = EntityShape & {
modiId: ForeignKey<"modi">;
entity: "user" | "userEntityGrant" | string;
entity: "actionAuth" | "relation" | "relationAuth" | "user" | "userEntityGrant" | "userRelation" | string;
entityId: String<64>;
modi: Modi.Schema;
actionAuth?: ActionAuth.Schema;
relation?: Relation.Schema;
relationAuth?: RelationAuth.Schema;
user?: User.Schema;
userEntityGrant?: UserEntityGrant.Schema;
userRelation?: UserRelation.Schema;
} & {
[A in ExpressionKey]?: any;
};
@ -32,10 +40,14 @@ declare type AttrFilter<E> = {
modi: Modi.Filter;
entity: E;
entityId: Q_StringValue;
actionAuth: ActionAuth.Filter;
relation: Relation.Filter;
relationAuth: RelationAuth.Filter;
user: User.Filter;
userEntityGrant: UserEntityGrant.Filter;
userRelation: UserRelation.Filter;
};
export declare type Filter<E = Q_EnumValue<"user" | "userEntityGrant" | string>> = MakeFilter<AttrFilter<E> & ExprOp<OpAttr | string>>;
export declare type Filter<E = Q_EnumValue<"actionAuth" | "relation" | "relationAuth" | "user" | "userEntityGrant" | "userRelation" | string>> = MakeFilter<AttrFilter<E> & ExprOp<OpAttr | string>>;
export declare type Projection = {
"#id"?: NodeId;
[k: string]: any;
@ -47,8 +59,12 @@ export declare type Projection = {
modi?: Modi.Projection;
entity?: number;
entityId?: number;
actionAuth?: ActionAuth.Projection;
relation?: Relation.Projection;
relationAuth?: RelationAuth.Projection;
user?: User.Projection;
userEntityGrant?: UserEntityGrant.Projection;
userRelation?: UserRelation.Projection;
} & Partial<ExprOp<OpAttr | string>>;
declare type ModiEntityIdProjection = OneOf<{
id: number;
@ -56,12 +72,24 @@ declare type ModiEntityIdProjection = OneOf<{
declare type ModiIdProjection = OneOf<{
modiId: number;
}>;
declare type ActionAuthIdProjection = OneOf<{
entityId: number;
}>;
declare type RelationIdProjection = OneOf<{
entityId: number;
}>;
declare type RelationAuthIdProjection = OneOf<{
entityId: number;
}>;
declare type UserIdProjection = OneOf<{
entityId: number;
}>;
declare type UserEntityGrantIdProjection = OneOf<{
entityId: number;
}>;
declare type UserRelationIdProjection = OneOf<{
entityId: number;
}>;
export declare type SortAttr = {
id: number;
} | {
@ -78,10 +106,18 @@ export declare type SortAttr = {
entity: number;
} | {
entityId: number;
} | {
actionAuth: ActionAuth.SortAttr;
} | {
relation: Relation.SortAttr;
} | {
relationAuth: RelationAuth.SortAttr;
} | {
user: User.SortAttr;
} | {
userEntityGrant: UserEntityGrant.SortAttr;
} | {
userRelation: UserRelation.SortAttr;
} | {
[k: string]: any;
} | OneOf<ExprOp<OpAttr | string>>;
@ -102,6 +138,39 @@ export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "entity"
} | {
modiId: String<64>;
})) & ({
entity?: never;
entityId?: never;
actionAuth: ActionAuth.CreateSingleOperation;
} | {
entity: "actionAuth";
entityId: String<64>;
actionAuth: ActionAuth.UpdateOperation;
} | {
entity: "actionAuth";
entityId: String<64>;
} | {
entity?: never;
entityId?: never;
relation: Relation.CreateSingleOperation;
} | {
entity: "relation";
entityId: String<64>;
relation: Relation.UpdateOperation;
} | {
entity: "relation";
entityId: String<64>;
} | {
entity?: never;
entityId?: never;
relationAuth: RelationAuth.CreateSingleOperation;
} | {
entity: "relationAuth";
entityId: String<64>;
relationAuth: RelationAuth.UpdateOperation;
} | {
entity: "relationAuth";
entityId: String<64>;
} | {
entity?: never;
entityId?: never;
user: User.CreateSingleOperation;
@ -123,6 +192,17 @@ export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "entity"
} | {
entity: "userEntityGrant";
entityId: String<64>;
} | {
entity?: never;
entityId?: never;
userRelation: UserRelation.CreateSingleOperation;
} | {
entity: "userRelation";
entityId: String<64>;
userRelation: UserRelation.UpdateOperation;
} | {
entity: "userRelation";
entityId: String<64>;
} | {
entity?: string;
entityId?: string;
@ -144,6 +224,18 @@ export declare type UpdateOperationData = FormUpdateData<Omit<OpSchema, "entity"
modi?: never;
modiId?: String<64> | null;
})) & ({
actionAuth?: ActionAuth.CreateSingleOperation | ActionAuth.UpdateOperation | ActionAuth.RemoveOperation;
entityId?: never;
entity?: never;
} | {
relation?: Relation.CreateSingleOperation | Relation.UpdateOperation | Relation.RemoveOperation;
entityId?: never;
entity?: never;
} | {
relationAuth?: RelationAuth.CreateSingleOperation | RelationAuth.UpdateOperation | RelationAuth.RemoveOperation;
entityId?: never;
entity?: never;
} | {
user?: User.CreateSingleOperation | User.UpdateOperation | User.RemoveOperation;
entityId?: never;
entity?: never;
@ -152,7 +244,11 @@ export declare type UpdateOperationData = FormUpdateData<Omit<OpSchema, "entity"
entityId?: never;
entity?: never;
} | {
entity?: ("user" | "userEntityGrant" | string) | null;
userRelation?: UserRelation.CreateSingleOperation | UserRelation.UpdateOperation | UserRelation.RemoveOperation;
entityId?: never;
entity?: never;
} | {
entity?: ("actionAuth" | "relation" | "relationAuth" | "user" | "userEntityGrant" | "userRelation" | string) | null;
entityId?: String<64> | null;
}) & {
[k: string]: any;
@ -161,17 +257,29 @@ export declare type UpdateOperation = OakOperation<"update" | string, UpdateOper
export declare type RemoveOperationData = {} & (({
modi?: Modi.UpdateOperation | Modi.RemoveOperation;
})) & ({
actionAuth?: ActionAuth.UpdateOperation | ActionAuth.RemoveOperation;
} | {
relation?: Relation.UpdateOperation | Relation.RemoveOperation;
} | {
relationAuth?: RelationAuth.UpdateOperation | RelationAuth.RemoveOperation;
} | {
user?: User.UpdateOperation | User.RemoveOperation;
} | {
userEntityGrant?: UserEntityGrant.UpdateOperation | UserEntityGrant.RemoveOperation;
} | {
userRelation?: UserRelation.UpdateOperation | UserRelation.RemoveOperation;
} | {
[k: string]: any;
});
export declare type RemoveOperation = OakOperation<"remove", RemoveOperationData, Filter, Sorter>;
export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation;
export declare type ModiIdSubQuery = Selection<ModiIdProjection>;
export declare type ActionAuthIdSubQuery = Selection<ActionAuthIdProjection>;
export declare type RelationIdSubQuery = Selection<RelationIdProjection>;
export declare type RelationAuthIdSubQuery = Selection<RelationAuthIdProjection>;
export declare type UserIdSubQuery = Selection<UserIdProjection>;
export declare type UserEntityGrantIdSubQuery = Selection<UserEntityGrantIdProjection>;
export declare type UserRelationIdSubQuery = Selection<UserRelationIdProjection>;
export declare type ModiEntityIdSubQuery = Selection<ModiEntityIdProjection>;
export declare type EntityDef = {
Schema: Schema;

View File

@ -15,7 +15,7 @@ exports.desc = {
params: {
length: 32
},
ref: ["user", "userEntityGrant"]
ref: ["actionAuth", "relation", "relationAuth", "user", "userEntityGrant", "userRelation"]
},
entityId: {
notNull: true,

View File

@ -5,21 +5,29 @@ import * as SubQuery from "../_SubQuery";
import { FormCreateData, FormUpdateData, DeduceAggregation, Operation as OakOperation, Selection as OakSelection, MakeAction as OakMakeAction, EntityShape } from "../../types/Entity";
import { AppendOnlyAction } from "../../actions/action";
import * as Oper from "../Oper/Schema";
import * as ActionAuth from "../ActionAuth/Schema";
import * as Relation from "../Relation/Schema";
import * as RelationAuth from "../RelationAuth/Schema";
import * as User from "../User/Schema";
import * as UserEntityGrant from "../UserEntityGrant/Schema";
import * as UserRelation from "../UserRelation/Schema";
export declare type OpSchema = EntityShape & {
operId: ForeignKey<"oper">;
entity: "user" | "userEntityGrant" | string;
entity: "actionAuth" | "relation" | "relationAuth" | "user" | "userEntityGrant" | "userRelation" | string;
entityId: String<64>;
};
export declare type OpAttr = keyof OpSchema;
export declare type Schema = EntityShape & {
operId: ForeignKey<"oper">;
entity: "user" | "userEntityGrant" | string;
entity: "actionAuth" | "relation" | "relationAuth" | "user" | "userEntityGrant" | "userRelation" | string;
entityId: String<64>;
oper: Oper.Schema;
actionAuth?: ActionAuth.Schema;
relation?: Relation.Schema;
relationAuth?: RelationAuth.Schema;
user?: User.Schema;
userEntityGrant?: UserEntityGrant.Schema;
userRelation?: UserRelation.Schema;
} & {
[A in ExpressionKey]?: any;
};
@ -32,10 +40,14 @@ declare type AttrFilter<E> = {
oper: Oper.Filter;
entity: E;
entityId: Q_StringValue;
actionAuth: ActionAuth.Filter;
relation: Relation.Filter;
relationAuth: RelationAuth.Filter;
user: User.Filter;
userEntityGrant: UserEntityGrant.Filter;
userRelation: UserRelation.Filter;
};
export declare type Filter<E = Q_EnumValue<"user" | "userEntityGrant" | string>> = MakeFilter<AttrFilter<E> & ExprOp<OpAttr | string>>;
export declare type Filter<E = Q_EnumValue<"actionAuth" | "relation" | "relationAuth" | "user" | "userEntityGrant" | "userRelation" | string>> = MakeFilter<AttrFilter<E> & ExprOp<OpAttr | string>>;
export declare type Projection = {
"#id"?: NodeId;
[k: string]: any;
@ -47,8 +59,12 @@ export declare type Projection = {
oper?: Oper.Projection;
entity?: number;
entityId?: number;
actionAuth?: ActionAuth.Projection;
relation?: Relation.Projection;
relationAuth?: RelationAuth.Projection;
user?: User.Projection;
userEntityGrant?: UserEntityGrant.Projection;
userRelation?: UserRelation.Projection;
} & Partial<ExprOp<OpAttr | string>>;
declare type OperEntityIdProjection = OneOf<{
id: number;
@ -56,12 +72,24 @@ declare type OperEntityIdProjection = OneOf<{
declare type OperIdProjection = OneOf<{
operId: number;
}>;
declare type ActionAuthIdProjection = OneOf<{
entityId: number;
}>;
declare type RelationIdProjection = OneOf<{
entityId: number;
}>;
declare type RelationAuthIdProjection = OneOf<{
entityId: number;
}>;
declare type UserIdProjection = OneOf<{
entityId: number;
}>;
declare type UserEntityGrantIdProjection = OneOf<{
entityId: number;
}>;
declare type UserRelationIdProjection = OneOf<{
entityId: number;
}>;
export declare type SortAttr = {
id: number;
} | {
@ -78,10 +106,18 @@ export declare type SortAttr = {
entity: number;
} | {
entityId: number;
} | {
actionAuth: ActionAuth.SortAttr;
} | {
relation: Relation.SortAttr;
} | {
relationAuth: RelationAuth.SortAttr;
} | {
user: User.SortAttr;
} | {
userEntityGrant: UserEntityGrant.SortAttr;
} | {
userRelation: UserRelation.SortAttr;
} | {
[k: string]: any;
} | OneOf<ExprOp<OpAttr | string>>;
@ -99,6 +135,39 @@ export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "entity"
} | {
operId: String<64>;
})) & ({
entity?: never;
entityId?: never;
actionAuth: ActionAuth.CreateSingleOperation;
} | {
entity: "actionAuth";
entityId: String<64>;
actionAuth: ActionAuth.UpdateOperation;
} | {
entity: "actionAuth";
entityId: String<64>;
} | {
entity?: never;
entityId?: never;
relation: Relation.CreateSingleOperation;
} | {
entity: "relation";
entityId: String<64>;
relation: Relation.UpdateOperation;
} | {
entity: "relation";
entityId: String<64>;
} | {
entity?: never;
entityId?: never;
relationAuth: RelationAuth.CreateSingleOperation;
} | {
entity: "relationAuth";
entityId: String<64>;
relationAuth: RelationAuth.UpdateOperation;
} | {
entity: "relationAuth";
entityId: String<64>;
} | {
entity?: never;
entityId?: never;
user: User.CreateSingleOperation;
@ -120,6 +189,17 @@ export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "entity"
} | {
entity: "userEntityGrant";
entityId: String<64>;
} | {
entity?: never;
entityId?: never;
userRelation: UserRelation.CreateSingleOperation;
} | {
entity: "userRelation";
entityId: String<64>;
userRelation: UserRelation.UpdateOperation;
} | {
entity: "userRelation";
entityId: String<64>;
} | {
entity?: string;
entityId?: string;
@ -135,6 +215,18 @@ export declare type UpdateOperationData = FormUpdateData<Omit<OpSchema, "entity"
oper?: never;
operId?: String<64> | null;
})) & ({
actionAuth?: ActionAuth.CreateSingleOperation | ActionAuth.UpdateOperation | ActionAuth.RemoveOperation;
entityId?: never;
entity?: never;
} | {
relation?: Relation.CreateSingleOperation | Relation.UpdateOperation | Relation.RemoveOperation;
entityId?: never;
entity?: never;
} | {
relationAuth?: RelationAuth.CreateSingleOperation | RelationAuth.UpdateOperation | RelationAuth.RemoveOperation;
entityId?: never;
entity?: never;
} | {
user?: User.CreateSingleOperation | User.UpdateOperation | User.RemoveOperation;
entityId?: never;
entity?: never;
@ -143,24 +235,40 @@ export declare type UpdateOperationData = FormUpdateData<Omit<OpSchema, "entity"
entityId?: never;
entity?: never;
} | {
entity?: ("user" | "userEntityGrant" | string) | null;
userRelation?: UserRelation.CreateSingleOperation | UserRelation.UpdateOperation | UserRelation.RemoveOperation;
entityId?: never;
entity?: never;
} | {
entity?: ("actionAuth" | "relation" | "relationAuth" | "user" | "userEntityGrant" | "userRelation" | string) | null;
entityId?: String<64> | null;
}) & {
[k: string]: any;
};
export declare type UpdateOperation = OakOperation<"update" | string, UpdateOperationData, Filter, Sorter>;
export declare type RemoveOperationData = {} & ({
actionAuth?: ActionAuth.UpdateOperation | ActionAuth.RemoveOperation;
} | {
relation?: Relation.UpdateOperation | Relation.RemoveOperation;
} | {
relationAuth?: RelationAuth.UpdateOperation | RelationAuth.RemoveOperation;
} | {
user?: User.UpdateOperation | User.RemoveOperation;
} | {
userEntityGrant?: UserEntityGrant.UpdateOperation | UserEntityGrant.RemoveOperation;
} | {
userRelation?: UserRelation.UpdateOperation | UserRelation.RemoveOperation;
} | {
[k: string]: any;
});
export declare type RemoveOperation = OakOperation<"remove", RemoveOperationData, Filter, Sorter>;
export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation;
export declare type OperIdSubQuery = Selection<OperIdProjection>;
export declare type ActionAuthIdSubQuery = Selection<ActionAuthIdProjection>;
export declare type RelationIdSubQuery = Selection<RelationIdProjection>;
export declare type RelationAuthIdSubQuery = Selection<RelationAuthIdProjection>;
export declare type UserIdSubQuery = Selection<UserIdProjection>;
export declare type UserEntityGrantIdSubQuery = Selection<UserEntityGrantIdProjection>;
export declare type UserRelationIdSubQuery = Selection<UserRelationIdProjection>;
export declare type OperEntityIdSubQuery = Selection<OperEntityIdProjection>;
export declare type EntityDef = {
Schema: Schema;

View File

@ -15,7 +15,7 @@ exports.desc = {
params: {
length: 32
},
ref: ["user", "userEntityGrant"]
ref: ["actionAuth", "relation", "relationAuth", "user", "userEntityGrant", "userRelation"]
},
entityId: {
notNull: true,

160
lib/base-app-domain/Relation/Schema.d.ts vendored Normal file
View File

@ -0,0 +1,160 @@
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 ActionAuth from "../ActionAuth/Schema";
import * as RelationAuth from "../RelationAuth/Schema";
import * as UserRelation from "../UserRelation/Schema";
import * as ModiEntity from "../ModiEntity/Schema";
import * as OperEntity from "../OperEntity/Schema";
export declare type OpSchema = EntityShape & {
entity: String<32>;
entityId: String<64>;
name: String<32>;
display: String<32>;
};
export declare type OpAttr = keyof OpSchema;
export declare type Schema = EntityShape & {
entity: String<32>;
entityId: String<64>;
name: String<32>;
display: String<32>;
actionAuth$relation?: Array<ActionAuth.Schema>;
actionAuth$relation$$aggr?: AggregationResult<ActionAuth.Schema>;
relationAuth$relation?: Array<RelationAuth.Schema>;
relationAuth$relation$$aggr?: AggregationResult<RelationAuth.Schema>;
userRelation$relation?: Array<UserRelation.Schema>;
userRelation$relation$$aggr?: AggregationResult<UserRelation.Schema>;
modiEntity$entity?: Array<ModiEntity.Schema>;
modiEntity$entity$$aggr?: AggregationResult<ModiEntity.Schema>;
operEntity$entity?: Array<OperEntity.Schema>;
operEntity$entity$$aggr?: AggregationResult<OperEntity.Schema>;
} & {
[A in ExpressionKey]?: any;
};
declare type AttrFilter = {
id: Q_StringValue | SubQuery.RelationIdSubQuery;
$$createAt$$: Q_DateValue;
$$seq$$: Q_StringValue;
$$updateAt$$: Q_DateValue;
entity: Q_StringValue;
entityId: Q_StringValue;
name: Q_StringValue;
display: 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;
name?: number;
display?: number;
actionAuth$relation?: ActionAuth.Selection & {
$entity: "actionAuth";
};
actionAuth$relation$$aggr?: ActionAuth.Aggregation & {
$entity: "actionAuth";
};
relationAuth$relation?: RelationAuth.Selection & {
$entity: "relationAuth";
};
relationAuth$relation$$aggr?: RelationAuth.Aggregation & {
$entity: "relationAuth";
};
userRelation$relation?: UserRelation.Selection & {
$entity: "userRelation";
};
userRelation$relation$$aggr?: UserRelation.Aggregation & {
$entity: "userRelation";
};
modiEntity$entity?: ModiEntity.Selection & {
$entity: "modiEntity";
};
modiEntity$entity$$aggr?: ModiEntity.Aggregation & {
$entity: "modiEntity";
};
operEntity$entity?: OperEntity.Selection & {
$entity: "operEntity";
};
operEntity$entity$$aggr?: OperEntity.Aggregation & {
$entity: "operEntity";
};
} & Partial<ExprOp<OpAttr | string>>;
declare type RelationIdProjection = OneOf<{
id: number;
}>;
export declare type SortAttr = {
id: number;
} | {
$$createAt$$: number;
} | {
$$seq$$: number;
} | {
$$updateAt$$: number;
} | {
entity: number;
} | {
entityId: number;
} | {
name: number;
} | {
display: 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;
}) & {
actionAuth$relation?: OakOperation<ActionAuth.UpdateOperation["action"], Omit<ActionAuth.UpdateOperationData, "relation" | "relationId">, ActionAuth.Filter> | OakOperation<"create", Omit<ActionAuth.CreateOperationData, "relation" | "relationId">[]> | Array<OakOperation<"create", Omit<ActionAuth.CreateOperationData, "relation" | "relationId">> | OakOperation<ActionAuth.UpdateOperation["action"], Omit<ActionAuth.UpdateOperationData, "relation" | "relationId">, ActionAuth.Filter>>;
relationAuth$relation?: OakOperation<RelationAuth.UpdateOperation["action"], Omit<RelationAuth.UpdateOperationData, "relation" | "relationId">, RelationAuth.Filter> | OakOperation<"create", Omit<RelationAuth.CreateOperationData, "relation" | "relationId">[]> | Array<OakOperation<"create", Omit<RelationAuth.CreateOperationData, "relation" | "relationId">> | OakOperation<RelationAuth.UpdateOperation["action"], Omit<RelationAuth.UpdateOperationData, "relation" | "relationId">, RelationAuth.Filter>>;
userRelation$relation?: OakOperation<UserRelation.UpdateOperation["action"], Omit<UserRelation.UpdateOperationData, "relation" | "relationId">, UserRelation.Filter> | OakOperation<"create", Omit<UserRelation.CreateOperationData, "relation" | "relationId">[]> | Array<OakOperation<"create", Omit<UserRelation.CreateOperationData, "relation" | "relationId">> | OakOperation<UserRelation.UpdateOperation["action"], Omit<UserRelation.UpdateOperationData, "relation" | "relationId">, UserRelation.Filter>>;
modiEntity$entity?: OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">>>;
operEntity$entity?: OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<OperEntity.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;
actionAuth$relation?: ActionAuth.UpdateOperation | ActionAuth.RemoveOperation | OakOperation<"create", Omit<ActionAuth.CreateOperationData, "relation" | "relationId">[]> | Array<OakOperation<"create", Omit<ActionAuth.CreateOperationData, "relation" | "relationId">> | ActionAuth.UpdateOperation | ActionAuth.RemoveOperation>;
relationAuth$relation?: RelationAuth.UpdateOperation | RelationAuth.RemoveOperation | OakOperation<"create", Omit<RelationAuth.CreateOperationData, "relation" | "relationId">[]> | Array<OakOperation<"create", Omit<RelationAuth.CreateOperationData, "relation" | "relationId">> | RelationAuth.UpdateOperation | RelationAuth.RemoveOperation>;
userRelation$relation?: UserRelation.UpdateOperation | UserRelation.RemoveOperation | OakOperation<"create", Omit<UserRelation.CreateOperationData, "relation" | "relationId">[]> | Array<OakOperation<"create", Omit<UserRelation.CreateOperationData, "relation" | "relationId">> | UserRelation.UpdateOperation | UserRelation.RemoveOperation>;
modiEntity$entity?: OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">>>;
operEntity$entity?: OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<OperEntity.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 RelationIdSubQuery = Selection<RelationIdProjection>;
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,57 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.desc = void 0;
var action_1 = require("../../actions/action");
exports.desc = {
attributes: {
entity: {
notNull: true,
type: "varchar",
params: {
length: 32
}
},
entityId: {
notNull: true,
type: "varchar",
params: {
length: 64
}
},
name: {
notNull: true,
type: "varchar",
params: {
length: 32
}
},
display: {
notNull: true,
type: "varchar",
params: {
length: 32
}
}
},
actionType: "crud",
actions: action_1.genericActions,
indexes: [
{
name: 'index_entity_entityId_name',
attributes: [
{
name: 'entity'
},
{
name: 'entityId'
},
{
name: 'name'
}
],
config: {
unique: true
}
}
]
};

View File

@ -0,0 +1,156 @@
import { String, ForeignKey } from "../../types/DataType";
import { Q_DateValue, Q_StringValue, Q_EnumValue, 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 Relation from "../Relation/Schema";
import * as ModiEntity from "../ModiEntity/Schema";
import * as OperEntity from "../OperEntity/Schema";
declare type Relations = string[];
export declare type OpSchema = EntityShape & {
relationId: ForeignKey<"relation">;
path: String<256>;
destEntity: String<32>;
deRelations: Relations;
};
export declare type OpAttr = keyof OpSchema;
export declare type Schema = EntityShape & {
relationId: ForeignKey<"relation">;
path: String<256>;
destEntity: String<32>;
deRelations: Relations;
relation: Relation.Schema;
modiEntity$entity?: Array<ModiEntity.Schema>;
modiEntity$entity$$aggr?: AggregationResult<ModiEntity.Schema>;
operEntity$entity?: Array<OperEntity.Schema>;
operEntity$entity$$aggr?: AggregationResult<OperEntity.Schema>;
} & {
[A in ExpressionKey]?: any;
};
declare type AttrFilter = {
id: Q_StringValue | SubQuery.RelationAuthIdSubQuery;
$$createAt$$: Q_DateValue;
$$seq$$: Q_StringValue;
$$updateAt$$: Q_DateValue;
relationId: Q_StringValue | SubQuery.RelationIdSubQuery;
relation: Relation.Filter;
path: Q_StringValue;
destEntity: Q_StringValue;
deRelations: Q_EnumValue<Relations>;
};
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;
relationId?: number;
relation?: Relation.Projection;
path?: number;
destEntity?: number;
deRelations?: number;
modiEntity$entity?: ModiEntity.Selection & {
$entity: "modiEntity";
};
modiEntity$entity$$aggr?: ModiEntity.Aggregation & {
$entity: "modiEntity";
};
operEntity$entity?: OperEntity.Selection & {
$entity: "operEntity";
};
operEntity$entity$$aggr?: OperEntity.Aggregation & {
$entity: "operEntity";
};
} & Partial<ExprOp<OpAttr | string>>;
declare type RelationAuthIdProjection = OneOf<{
id: number;
}>;
declare type RelationIdProjection = OneOf<{
relationId: number;
}>;
export declare type SortAttr = {
id: number;
} | {
$$createAt$$: number;
} | {
$$seq$$: number;
} | {
$$updateAt$$: number;
} | {
relationId: number;
} | {
relation: Relation.SortAttr;
} | {
path: number;
} | {
destEntity: number;
} | {
deRelations: 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, "relationId">> & (({
relationId?: never;
relation: Relation.CreateSingleOperation;
} | {
relationId: String<64>;
relation?: Relation.UpdateOperation;
} | {
relationId: String<64>;
})) & {
modiEntity$entity?: OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">>>;
operEntity$entity?: OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<OperEntity.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<Omit<OpSchema, "relationId">> & (({
relation: Relation.CreateSingleOperation;
relationId?: never;
} | {
relation: Relation.UpdateOperation;
relationId?: never;
} | {
relation: Relation.RemoveOperation;
relationId?: never;
} | {
relation?: never;
relationId?: String<64> | null;
})) & {
[k: string]: any;
modiEntity$entity?: OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">>>;
operEntity$entity?: OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">>>;
};
export declare type UpdateOperation = OakOperation<"update" | string, UpdateOperationData, Filter, Sorter>;
export declare type RemoveOperationData = {} & (({
relation?: Relation.UpdateOperation | Relation.RemoveOperation;
}));
export declare type RemoveOperation = OakOperation<"remove", RemoveOperationData, Filter, Sorter>;
export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation;
export declare type RelationIdSubQuery = Selection<RelationIdProjection>;
export declare type RelationAuthIdSubQuery = Selection<RelationAuthIdProjection>;
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,49 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.desc = void 0;
var action_1 = require("../../actions/action");
exports.desc = {
attributes: {
relationId: {
notNull: true,
type: "ref",
ref: "relation"
},
path: {
notNull: true,
type: "varchar",
params: {
length: 256
}
},
destEntity: {
notNull: true,
type: "varchar",
params: {
length: 32
}
},
deRelations: {
notNull: true,
type: "object"
}
},
actionType: "crud",
actions: action_1.genericActions,
indexes: [
{
name: 'index_relation_path',
attributes: [
{
name: "relationId"
},
{
name: 'path'
},
],
config: {
unique: true
}
}
]
};

View File

@ -1,17 +1,25 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.storageSchema = void 0;
var Storage_1 = require("./Modi/Storage");
var Storage_2 = require("./ModiEntity/Storage");
var Storage_3 = require("./Oper/Storage");
var Storage_4 = require("./OperEntity/Storage");
var Storage_5 = require("./User/Storage");
var Storage_6 = require("./UserEntityGrant/Storage");
var Storage_1 = require("./ActionAuth/Storage");
var Storage_2 = require("./Modi/Storage");
var Storage_3 = require("./ModiEntity/Storage");
var Storage_4 = require("./Oper/Storage");
var Storage_5 = require("./OperEntity/Storage");
var Storage_6 = require("./Relation/Storage");
var Storage_7 = require("./RelationAuth/Storage");
var Storage_8 = require("./User/Storage");
var Storage_9 = require("./UserEntityGrant/Storage");
var Storage_10 = require("./UserRelation/Storage");
exports.storageSchema = {
modi: Storage_1.desc,
modiEntity: Storage_2.desc,
oper: Storage_3.desc,
operEntity: Storage_4.desc,
user: Storage_5.desc,
userEntityGrant: Storage_6.desc
actionAuth: Storage_1.desc,
modi: Storage_2.desc,
modiEntity: Storage_3.desc,
oper: Storage_4.desc,
operEntity: Storage_5.desc,
relation: Storage_6.desc,
relationAuth: Storage_7.desc,
user: Storage_8.desc,
userEntityGrant: Storage_9.desc,
userRelation: Storage_10.desc
};

View File

@ -6,6 +6,7 @@ import { FormCreateData, FormUpdateData, DeduceAggregation, Operation as OakOper
import { Action, ParticularAction, UserState } from "./Action";
import { RelationAction } from "../../actions/action";
import * as Oper from "../Oper/Schema";
import * as UserRelation from "../UserRelation/Schema";
import * as ModiEntity from "../ModiEntity/Schema";
import * as OperEntity from "../OperEntity/Schema";
export declare type OpSchema = EntityShape & {
@ -27,6 +28,8 @@ export declare type Schema = EntityShape & {
oper$operator$$aggr?: AggregationResult<Oper.Schema>;
user$ref?: Array<Schema>;
user$ref$$aggr?: AggregationResult<Schema>;
userRelation$user?: Array<UserRelation.Schema>;
userRelation$user$$aggr?: AggregationResult<UserRelation.Schema>;
modiEntity$entity?: Array<ModiEntity.Schema>;
modiEntity$entity$$aggr?: AggregationResult<ModiEntity.Schema>;
operEntity$entity?: Array<OperEntity.Schema>;
@ -72,6 +75,12 @@ export declare type Projection = {
user$ref$$aggr?: Aggregation & {
$entity: "user";
};
userRelation$user?: UserRelation.Selection & {
$entity: "userRelation";
};
userRelation$user$$aggr?: UserRelation.Aggregation & {
$entity: "userRelation";
};
modiEntity$entity?: ModiEntity.Selection & {
$entity: "modiEntity";
};
@ -131,6 +140,7 @@ export declare type CreateOperationData = FormCreateData<Omit<OpSchema, "refId">
})) & {
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>>;
userRelation$user?: OakOperation<UserRelation.UpdateOperation["action"], Omit<UserRelation.UpdateOperationData, "user" | "userId">, UserRelation.Filter> | OakOperation<"create", Omit<UserRelation.CreateOperationData, "user" | "userId">[]> | Array<OakOperation<"create", Omit<UserRelation.CreateOperationData, "user" | "userId">> | OakOperation<UserRelation.UpdateOperation["action"], Omit<UserRelation.UpdateOperationData, "user" | "userId">, UserRelation.Filter>>;
modiEntity$entity?: OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">>>;
operEntity$entity?: OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">>>;
};
@ -153,6 +163,7 @@ export declare type UpdateOperationData = FormUpdateData<Omit<OpSchema, "refId">
[k: string]: any;
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>;
userRelation$user?: UserRelation.UpdateOperation | UserRelation.RemoveOperation | OakOperation<"create", Omit<UserRelation.CreateOperationData, "user" | "userId">[]> | Array<OakOperation<"create", Omit<UserRelation.CreateOperationData, "user" | "userId">> | UserRelation.UpdateOperation | UserRelation.RemoveOperation>;
modiEntity$entity?: OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">>>;
operEntity$entity?: OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">>>;
};

View File

@ -0,0 +1,175 @@
import { String, ForeignKey } 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 User from "../User/Schema";
import * as Relation from "../Relation/Schema";
import * as ModiEntity from "../ModiEntity/Schema";
import * as OperEntity from "../OperEntity/Schema";
export declare type OpSchema = EntityShape & {
userId: ForeignKey<"user">;
relationId: ForeignKey<"relation">;
};
export declare type OpAttr = keyof OpSchema;
export declare type Schema = EntityShape & {
userId: ForeignKey<"user">;
relationId: ForeignKey<"relation">;
user: User.Schema;
relation: Relation.Schema;
modiEntity$entity?: Array<ModiEntity.Schema>;
modiEntity$entity$$aggr?: AggregationResult<ModiEntity.Schema>;
operEntity$entity?: Array<OperEntity.Schema>;
operEntity$entity$$aggr?: AggregationResult<OperEntity.Schema>;
} & {
[A in ExpressionKey]?: any;
};
declare type AttrFilter = {
id: Q_StringValue | SubQuery.UserRelationIdSubQuery;
$$createAt$$: Q_DateValue;
$$seq$$: Q_StringValue;
$$updateAt$$: Q_DateValue;
userId: Q_StringValue | SubQuery.UserIdSubQuery;
user: User.Filter;
relationId: Q_StringValue | SubQuery.RelationIdSubQuery;
relation: Relation.Filter;
};
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;
userId?: number;
user?: User.Projection;
relationId?: number;
relation?: Relation.Projection;
modiEntity$entity?: ModiEntity.Selection & {
$entity: "modiEntity";
};
modiEntity$entity$$aggr?: ModiEntity.Aggregation & {
$entity: "modiEntity";
};
operEntity$entity?: OperEntity.Selection & {
$entity: "operEntity";
};
operEntity$entity$$aggr?: OperEntity.Aggregation & {
$entity: "operEntity";
};
} & Partial<ExprOp<OpAttr | string>>;
declare type UserRelationIdProjection = OneOf<{
id: number;
}>;
declare type UserIdProjection = OneOf<{
userId: number;
}>;
declare type RelationIdProjection = OneOf<{
relationId: number;
}>;
export declare type SortAttr = {
id: number;
} | {
$$createAt$$: number;
} | {
$$seq$$: number;
} | {
$$updateAt$$: number;
} | {
userId: number;
} | {
user: User.SortAttr;
} | {
relationId: number;
} | {
relation: Relation.SortAttr;
} | {
[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, "userId" | "relationId">> & (({
userId?: never;
user: User.CreateSingleOperation;
} | {
userId: String<64>;
user?: User.UpdateOperation;
} | {
userId: String<64>;
}) & ({
relationId?: never;
relation: Relation.CreateSingleOperation;
} | {
relationId: String<64>;
relation?: Relation.UpdateOperation;
} | {
relationId: String<64>;
})) & {
modiEntity$entity?: OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">>>;
operEntity$entity?: OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<OperEntity.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<Omit<OpSchema, "userId" | "relationId">> & (({
user: User.CreateSingleOperation;
userId?: never;
} | {
user: User.UpdateOperation;
userId?: never;
} | {
user: User.RemoveOperation;
userId?: never;
} | {
user?: never;
userId?: String<64> | null;
}) & ({
relation: Relation.CreateSingleOperation;
relationId?: never;
} | {
relation: Relation.UpdateOperation;
relationId?: never;
} | {
relation: Relation.RemoveOperation;
relationId?: never;
} | {
relation?: never;
relationId?: String<64> | null;
})) & {
[k: string]: any;
modiEntity$entity?: OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<ModiEntity.CreateOperationData, "entity" | "entityId">>>;
operEntity$entity?: OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">[]> | Array<OakOperation<"create", Omit<OperEntity.CreateOperationData, "entity" | "entityId">>>;
};
export declare type UpdateOperation = OakOperation<"update" | string, UpdateOperationData, Filter, Sorter>;
export declare type RemoveOperationData = {} & (({
user?: User.UpdateOperation | User.RemoveOperation;
}) & ({
relation?: Relation.UpdateOperation | Relation.RemoveOperation;
}));
export declare type RemoveOperation = OakOperation<"remove", RemoveOperationData, Filter, Sorter>;
export declare type Operation = CreateOperation | UpdateOperation | RemoveOperation;
export declare type UserIdSubQuery = Selection<UserIdProjection>;
export declare type RelationIdSubQuery = Selection<RelationIdProjection>;
export declare type UserRelationIdSubQuery = Selection<UserRelationIdProjection>;
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,36 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.desc = void 0;
var action_1 = require("../../actions/action");
exports.desc = {
attributes: {
userId: {
notNull: true,
type: "ref",
ref: "user"
},
relationId: {
notNull: true,
type: "ref",
ref: "relation"
}
},
actionType: "crud",
actions: action_1.genericActions,
indexes: [
{
name: 'index_user_relation',
attributes: [
{
name: "userId"
},
{
name: "relationId"
},
],
config: {
unique: true
}
}
]
};

View File

@ -1,9 +1,18 @@
import * as ActionAuth from "./ActionAuth/Schema";
import * as Modi from "./Modi/Schema";
import * as ModiEntity from "./ModiEntity/Schema";
import * as Oper from "./Oper/Schema";
import * as OperEntity from "./OperEntity/Schema";
import * as Relation from "./Relation/Schema";
import * as RelationAuth from "./RelationAuth/Schema";
import * as User from "./User/Schema";
import * as UserEntityGrant from "./UserEntityGrant/Schema";
import * as UserRelation from "./UserRelation/Schema";
export declare type ActionAuthIdSubQuery = {
[K in "$in" | "$nin"]?: (ActionAuth.ActionAuthIdSubQuery & {
entity: "actionAuth";
}) | any;
};
export declare type ModiIdSubQuery = {
[K in "$in" | "$nin"]?: (ModiEntity.ModiIdSubQuery & {
entity: "modiEntity";
@ -28,11 +37,29 @@ export declare type OperEntityIdSubQuery = {
entity: "operEntity";
}) | any;
};
export declare type RelationIdSubQuery = {
[K in "$in" | "$nin"]?: (ActionAuth.RelationIdSubQuery & {
entity: "actionAuth";
}) | (RelationAuth.RelationIdSubQuery & {
entity: "relationAuth";
}) | (UserRelation.RelationIdSubQuery & {
entity: "userRelation";
}) | (Relation.RelationIdSubQuery & {
entity: "relation";
}) | any;
};
export declare type RelationAuthIdSubQuery = {
[K in "$in" | "$nin"]?: (RelationAuth.RelationAuthIdSubQuery & {
entity: "relationAuth";
}) | any;
};
export declare type UserIdSubQuery = {
[K in "$in" | "$nin"]?: (Oper.UserIdSubQuery & {
entity: "oper";
}) | (User.UserIdSubQuery & {
entity: "user";
}) | (UserRelation.UserIdSubQuery & {
entity: "userRelation";
}) | (User.UserIdSubQuery & {
entity: "user";
}) | any;
@ -42,3 +69,8 @@ export declare type UserEntityGrantIdSubQuery = {
entity: "userEntityGrant";
}) | any;
};
export declare type UserRelationIdSubQuery = {
[K in "$in" | "$nin"]?: (UserRelation.UserRelationIdSubQuery & {
entity: "userRelation";
}) | any;
};

11
lib/entities/ActionAuth.d.ts vendored Normal file
View File

@ -0,0 +1,11 @@
import { String } from '../types/DataType';
import { EntityShape } from '../types/Entity';
import { Schema as Relation } from './Relation';
declare type Actions = string[];
export interface Schema extends EntityShape {
relation: Relation;
path: String<256>;
destEntity: String<32>;
deActions: Actions;
}
export {};

View File

@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
;
var indexes = [
{
name: 'index_relation_path',
attributes: [
{
name: 'relation',
},
{
name: 'path',
},
],
config: {
unique: true,
},
},
];
var locale = {
zh_CN: {
name: '用户授权',
attr: {
relation: '关系',
path: '路径',
destEntity: '目标对象',
deActions: '目标对象动作',
},
},
};

8
lib/entities/Relation.d.ts vendored Normal file
View File

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

33
lib/entities/Relation.js Normal file
View File

@ -0,0 +1,33 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
;
var indexes = [
{
name: 'index_entity_entityId_name',
attributes: [
{
name: 'entity',
},
{
name: 'entityId',
},
{
name: 'name',
}
],
config: {
unique: true,
},
},
];
var locale = {
zh_CN: {
name: '用户授权',
attr: {
name: '关系',
entity: '目标对象',
entityId: '目标对象id',
display: '显示值',
},
},
};

11
lib/entities/RelationAuth.d.ts vendored Normal file
View File

@ -0,0 +1,11 @@
import { String } from '../types/DataType';
import { EntityShape } from '../types/Entity';
import { Schema as Relation } from './Relation';
declare type Relations = string[];
export interface Schema extends EntityShape {
relation: Relation;
path: String<256>;
destEntity: String<32>;
deRelations: Relations;
}
export {};

View File

@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
;
var indexes = [
{
name: 'index_relation_path',
attributes: [
{
name: 'relation',
},
{
name: 'path',
},
],
config: {
unique: true,
},
},
];
var locale = {
zh_CN: {
name: '用户授权',
attr: {
relation: '关系',
path: '路径',
destEntity: '目标对象',
deRelations: '目标对象关系',
},
},
};

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

@ -0,0 +1,7 @@
import { EntityShape } from '../types/Entity';
import { Schema as User } from './User';
import { Schema as Relation } from './Relation';
export interface Schema extends EntityShape {
user: User;
relation: Relation;
}

View File

@ -0,0 +1,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
;
var indexes = [
{
name: 'index_user_relation',
attributes: [
{
name: 'user',
},
{
name: 'relation',
},
],
config: {
unique: true,
},
},
];
var locale = {
zh_CN: {
name: '用户对象关系',
attr: {
user: '关系',
relation: '目标关系',
},
},
};

View File

@ -9,6 +9,7 @@ var filter_1 = require("./filter");
var relation_1 = require("./relation");
var types_1 = require("../types");
var lodash_1 = require("../utils/lodash");
var AsyncRowStore_1 = require("./AsyncRowStore");
var filter_2 = require("./filter");
var uuid_1 = require("../utils/uuid");
/**这个用来处理级联的select和update对不同能力的 */
@ -460,8 +461,8 @@ var CascadeStore = /** @class */ (function (_super) {
if (foreignKey_1) {
// 基于属性的一对多
if (isAggr) {
// 是聚合运算
cascadeSelectionFns.push(function (result) {
// 是聚合运算,只有后台才需要执行
(context instanceof AsyncRowStore_1.AsyncContext) && cascadeSelectionFns.push(function (result) {
var aggrResults = result.map(function (row) {
var _a, _b;
var aggrResult = aggregateFn.call(_this, entity2_1, {
@ -540,8 +541,8 @@ var CascadeStore = /** @class */ (function (_super) {
else {
// 基于entity的多对一
if (isAggr) {
// 是聚合运算
cascadeSelectionFns.push(function (result) {
// 是聚合运算,只有后台才需要执行
(context instanceof AsyncRowStore_1.AsyncContext) && cascadeSelectionFns.push(function (result) {
var aggrResults = result.map(function (row) {
var _a;
var aggrResult = aggregateFn.call(_this, entity2_1, {

View File

@ -113,7 +113,7 @@ function translateCheckerInAsyncContext(checker) {
var fn = (function (_a, context, option) {
var operation = _a.operation;
return tslib_1.__awaiter(_this, void 0, void 0, function () {
var result, _b, filter, action;
var result, _b, filter, action, errMsg2;
return tslib_1.__generator(this, function (_c) {
switch (_c.label) {
case 0:
@ -146,7 +146,8 @@ function translateCheckerInAsyncContext(checker) {
if (_c.sent()) {
return [2 /*return*/];
}
throw new Exception_1.OakUserUnpermittedException(errMsg_2);
errMsg2 = typeof errMsg_2 === 'function' ? errMsg_2(operation, context, option) : errMsg_2;
throw new Exception_1.OakUserUnpermittedException(errMsg2);
case 5: return [2 /*return*/, 0];
}
});
@ -236,7 +237,8 @@ function translateCheckerInSyncContext(checker) {
if ((0, filter_1.checkFilterContains)(entity, context, result, filter, true)) {
return;
}
throw new Exception_1.OakUserUnpermittedException(errMsg_4);
var errMsg2 = typeof errMsg_4 === 'function' ? errMsg_4(operation, context, option) : errMsg_4;
throw new Exception_1.OakUserUnpermittedException(errMsg2);
}
};
return {
@ -439,19 +441,20 @@ function translateCascadeRelationFilterMaker(schema, lch, entity2, pathPrefix) {
if (d.entity === attr && typeof d.entityId === 'string') {
return d.entityId;
}
throw new Exception_1.OakUserUnpermittedException();
}
else {
(0, assert_1.default)(typeof relation === 'string');
if (typeof d["".concat(attr, "Id")] === 'string') {
return d["".concat(attr, "Id")];
}
throw new Exception_1.OakUserUnpermittedException();
}
};
if (relation === 2) {
if (data instanceof Array) {
var fkIds = (0, lodash_1.uniq)(data.map(function (d) { return getForeignKeyId_1(d); }));
var fkIds = (0, lodash_1.uniq)(data.map(function (d) { return getForeignKeyId_1(d); }).filter(function (ele) { return !!ele; }));
if (fkIds.length === 0) {
return new Exception_1.OakUserUnpermittedException();
}
return {
$entity: attr,
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), { id: { $in: fkIds } }),
@ -459,6 +462,9 @@ function translateCascadeRelationFilterMaker(schema, lch, entity2, pathPrefix) {
};
}
var fkId_1 = getForeignKeyId_1(data);
if (!fkId_1) {
return new Exception_1.OakUserUnpermittedException();
}
return {
$entity: attr,
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), { id: fkId_1 }),
@ -466,7 +472,10 @@ function translateCascadeRelationFilterMaker(schema, lch, entity2, pathPrefix) {
}
(0, assert_1.default)(typeof relation === 'string');
if (data instanceof Array) {
var fkIds = (0, lodash_1.uniq)(data.map(function (d) { return getForeignKeyId_1(d); }));
var fkIds = (0, lodash_1.uniq)(data.map(function (d) { return getForeignKeyId_1(d); }).filter(function (ele) { return !!ele; }));
if (fkIds.length === 0) {
return new Exception_1.OakUserUnpermittedException();
}
return {
$entity: relation,
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), { id: { $in: fkIds } }),
@ -474,6 +483,9 @@ function translateCascadeRelationFilterMaker(schema, lch, entity2, pathPrefix) {
};
}
var fkId = getForeignKeyId_1(data);
if (!fkId) {
return new Exception_1.OakUserUnpermittedException();
}
return {
$entity: relation,
$filter: (0, filter_1.addFilterSegment)(filterMaker2(userId), { id: fkId }),
@ -484,9 +496,9 @@ function translateCascadeRelationFilterMaker(schema, lch, entity2, pathPrefix) {
var filter_4 = operation.filter;
if (filter_4) {
var counter = translateCreateFilterMaker(entity2, filter_4, userId);
if (counter instanceof Exception_1.OakUserUnpermittedException) {
throw counter;
}
// if (counter instanceof OakUserUnpermittedException) {
// throw counter;
// }
return counter;
}
throw new Exception_1.OakUserUnpermittedException();
@ -594,19 +606,25 @@ function execCreateCounter(context, counter) {
}
else if (counter === null || counter === void 0 ? void 0 : counter.$entity) {
var _a = counter, $entity = _a.$entity, $filter = _a.$filter, _b = _a.$count, $count_1 = _b === void 0 ? 1 : _b;
var count = context.count($entity, {
// count不走reinforceSelection先用select
var result = context.select($entity, {
data: {
id: 1,
},
filter: $filter,
indexFrom: 0,
count: $count_1,
}, { dontCollect: true });
if (count instanceof Promise) {
return count.then(function (c2) {
if (c2 >= $count_1) {
if (result instanceof Promise) {
return result.then(function (r2) {
if (r2.length >= $count_1) {
return undefined;
}
return new Exception_1.OakUserUnpermittedException();
});
}
else {
return count >= $count_1 ? undefined : new Exception_1.OakUserUnpermittedException();
return result.length >= $count_1 ? undefined : new Exception_1.OakUserUnpermittedException();
}
}
}
@ -784,7 +802,10 @@ function createAuthCheckers(schema, authDict) {
var filter = makePotentialFilter(operation, context, raFilterMakerDict_1[relation]);
return filter;
},
errMsg: '越权操作',
errMsg: function (operation, context) {
console.error("\u521B\u5EFA".concat(entity, "\u65F6\u8D8A\u6743\uFF0CuserId\u662F").concat(context.getCurrentUserId(), "\uFF0C\u6570\u636E\u662F").concat(JSON.stringify(operation.data)));
return "\u521B\u5EFA".concat(entity, "\u65F6\u8D8A\u6743");
},
});
checkers.push({
entity: userEntityName,
@ -842,7 +863,10 @@ function createAuthCheckers(schema, authDict) {
}
return makeFilterFromRows(toBeRemoved); */
},
errMsg: '越权操作',
errMsg: function (operation, context) {
console.error("\u79FB\u9664".concat(entity, "\u65F6\u8D8A\u6743\uFF0CuserId\u662F").concat(context.getCurrentUserId(), "\uFF0C\u79FB\u9664\u6761\u4EF6\u662F").concat(JSON.stringify(operation.filter)));
return "\u79FB\u9664".concat(entity, "\u65F6\u8D8A\u6743");
},
});
// 转让权限现在用update动作只允许update userId给其它人
// todo 等实现的时候再写
@ -859,7 +883,11 @@ function createAuthCheckers(schema, authDict) {
var filter = makePotentialFilter(operation, context, filterMaker);
return filter;
},
errMsg: '定义的actionAuth中检查出来越权操作',
errMsg: function (operation, context) {
var _a = operation, action = _a.action, data = _a.data, filter = _a.filter;
console.error("\u5BF9".concat(entity, "\u8FDB\u884C").concat(action, "\u65F6\u8D8A\u6743\uFF0CuserId\u662F").concat(context.getCurrentUserId(), "\n \u6570\u636E\u662F").concat(JSON.stringify(data), "\uFF0C\u6761\u4EF6\u662F").concat(JSON.stringify(filter)));
return "\u5BF9".concat(entity, "\u8FDB\u884C").concat(action, "\u65F6\u8D8A\u6743");
},
});
};
for (var a in actionAuth) {
@ -1305,7 +1333,7 @@ function createCreateCheckers(schema) {
continue;
}
}
else if (attr === 'entity' && attributes[attr].type === 'ref') {
else if (attr === 'entity' && attributes[attr].ref) {
var hasCascadeCreate = false;
try {
for (var _c = (e_10 = void 0, tslib_1.__values(attributes[attr].ref)), _d = _c.next(); !_d.done; _d = _c.next()) {

2
lib/types/Auth.d.ts vendored
View File

@ -35,7 +35,7 @@ export declare type RelationChecker<ED extends EntityDict, T extends keyof ED, C
when?: 'after';
action: ED[T]['Action'] | Array<ED[T]['Action']>;
relationFilter: (operation: ED[T]['Operation'] | ED[T]['Selection'], context: Cxt, option: OperateOption | SelectOption) => SyncOrAsync<ED[T]['Selection']['filter']>;
errMsg: string;
errMsg: string | ((operation: ED[T]['Operation'] | ED[T]['Selection'], context: Cxt, option?: OperateOption | SelectOption) => string);
conditionalFilter?: ED[T]['Update']['filter'] | ((operation: ED[T]['Operation'], context: Cxt, option: OperateOption) => SyncOrAsync<ED[T]['Selection']['filter']>);
};
export declare type LogicalChecker<ED extends EntityDict, T extends keyof ED, Cxt extends AsyncContext<ED> | SyncContext<ED>> = {

View File

@ -24,4 +24,10 @@ export declare abstract class Connector<ED extends EntityDict, BackCxt extends A
body: any;
headers?: Record<string, any>;
};
abstract getBridgeRouter(): string;
abstract makeBridgeUrl(url: string, headers?: Record<string, string>): string;
abstract parseBridgeRequestQuery(urlParams: string): {
url: string;
headers?: Record<string, string>;
};
}

View File

@ -181,4 +181,5 @@ export declare type Configuration = {
actionType?: ActionType;
static?: boolean;
};
export declare type OtmKey<K extends string> = K | `${K}$${number}`;
export {};

View File

@ -4,8 +4,10 @@ import { AsyncContext, AsyncRowStore } from '../store/AsyncRowStore';
import { SyncContext } from '../store/SyncRowStore';
import { Connector, EntityDict, OakException } from "../types";
export declare class SimpleConnector<ED extends EntityDict, BackCxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>> extends Connector<ED, BackCxt, FrontCxt> {
static ROUTER: string;
private serverUrl;
static ASPECT_ROUTER: string;
static BRIDGE_ROUTER: string;
private serverAspectUrl;
private serverBridgeUrl;
private makeException;
private contextBuilder;
constructor(serverUrl: string, makeException: (exceptionData: any) => OakException<ED>, contextBuilder: (str: string | undefined) => (store: AsyncRowStore<ED, BackCxt>) => Promise<BackCxt>);
@ -32,4 +34,15 @@ export declare class SimpleConnector<ED extends EntityDict, BackCxt extends Asyn
body: any;
headers?: Record<string, any> | undefined;
};
getBridgeRouter(): string;
/**
* 访url
* @param url
* @param headers
*/
makeBridgeUrl(url: string, headers?: Record<string, string>): string;
parseBridgeRequestQuery(urlParams: string): {
url: string;
headers?: Record<string, string> | undefined;
};
}

View File

@ -4,6 +4,7 @@ exports.SimpleConnector = void 0;
var tslib_1 = require("tslib");
var assert_1 = tslib_1.__importDefault(require("assert"));
var stream_1 = require("stream");
var url_1 = tslib_1.__importDefault(require("url"));
var types_1 = require("../types");
function makeContentTypeAndBody(data) {
//
@ -24,7 +25,8 @@ var SimpleConnector = /** @class */ (function (_super) {
tslib_1.__extends(SimpleConnector, _super);
function SimpleConnector(serverUrl, makeException, contextBuilder) {
var _this = _super.call(this) || this;
_this.serverUrl = "".concat(serverUrl).concat(SimpleConnector.ROUTER);
_this.serverAspectUrl = "".concat(serverUrl).concat(SimpleConnector.ASPECT_ROUTER);
_this.serverBridgeUrl = "".concat(serverUrl).concat(SimpleConnector.BRIDGE_ROUTER);
_this.makeException = makeException;
_this.contextBuilder = contextBuilder;
return _this;
@ -37,7 +39,7 @@ var SimpleConnector = /** @class */ (function (_super) {
case 0:
cxtStr = context.toString();
_a = makeContentTypeAndBody(params), contentType = _a.contentType, body = _a.body;
return [4 /*yield*/, global.fetch(this.serverUrl, {
return [4 /*yield*/, global.fetch(this.serverAspectUrl, {
method: 'POST',
headers: Object.assign({
'oak-cxt': cxtStr,
@ -82,7 +84,7 @@ var SimpleConnector = /** @class */ (function (_super) {
});
};
SimpleConnector.prototype.getRouter = function () {
return SimpleConnector.ROUTER;
return SimpleConnector.ASPECT_ROUTER;
};
SimpleConnector.prototype.parseRequest = function (headers, body, store) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
@ -139,7 +141,40 @@ var SimpleConnector = /** @class */ (function (_super) {
},
};
};
SimpleConnector.ROUTER = '/aspect';
SimpleConnector.prototype.getBridgeRouter = function () {
return SimpleConnector.BRIDGE_ROUTER;
};
/**
* 通过本地服务器桥接访问外部资源的url
* @param url
* @param headers
*/
SimpleConnector.prototype.makeBridgeUrl = function (url, headers) {
// if (process.env.PROD !== 'true') {
//     console.warn('在development下无法通过bridge访问资源将直接访问可能失败', url);
//     return url;
// }
var encodeUrl = encodeURIComponent(url);
// const urlParse = URL.parse(url, true);
// const { search } = urlParse as {
//     search: string;
// };
// if (headers) {
//     search.append('headers', JSON.stringify(headers));
// }
return "".concat(this.serverBridgeUrl, "?url=").concat(encodeUrl);
};
SimpleConnector.prototype.parseBridgeRequestQuery = function (urlParams) {
var search = new url_1.default.URLSearchParams(urlParams);
var url = search.get('url');
var headers = search.get('headers');
return {
url: url,
headers: headers && JSON.parse(headers),
};
};
SimpleConnector.ASPECT_ROUTER = '/aspect';
SimpleConnector.BRIDGE_ROUTER = '/bridge';
return SimpleConnector;
}(types_1.Connector));
exports.SimpleConnector = SimpleConnector;

View File

@ -2,4 +2,5 @@ declare const ToCent: (float: number) => number;
declare const ToYuan: (int: number) => number;
declare const StringToCent: (value: string, allowNegative?: true) => number | undefined;
declare const CentToString: (value: number) => string | undefined;
export { ToCent, ToYuan, StringToCent, CentToString, };
declare const ThousandCont: (value: number) => string | undefined;
export { ToCent, ToYuan, StringToCent, CentToString, ThousandCont };

View File

@ -1,6 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CentToString = exports.StringToCent = exports.ToYuan = exports.ToCent = void 0;
exports.ThousandCont = exports.CentToString = exports.StringToCent = exports.ToYuan = exports.ToCent = void 0;
var ToCent = function (float) {
return Math.round(float * 100);
};
@ -22,3 +22,19 @@ var CentToString = function (value) {
}
};
exports.CentToString = CentToString;
var ThousandCont = function (value) {
var value1 = "".concat(value);
var numArr = value1.split('.');
value1 = numArr[0];
var result = '';
while (value1.length > 3) {
result = ',' + value1.slice(-3) + result;
value1 = value1.slice(0, value1.length - 3);
}
if (value1) {
result = value1 + result;
}
result = result + '.' + numArr[1];
return result;
};
exports.ThousandCont = ThousandCont;

7
lib/utils/version.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
/**
*
* @param curVersion
* @param reqVersion
* @returns
*/
export declare const compareVersion: (curVersion: string, reqVersion: string) => number;

21
lib/utils/version.js Normal file
View File

@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.compareVersion = void 0;
/**
* 版本比较
* @param curVersion 当前版本
* @param reqVersion 比较版本
* @returns
*/
var compareVersion = function (curVersion, reqVersion) {
var v1 = curVersion.split('.');
var v2 = reqVersion.split('.');
for (var i = 0; i < Math.max(v1.length, v2.length); i++) {
var num1 = i < v1.length ? parseInt(v1[i], 10) : 0;
var num2 = i < v2.length ? parseInt(v2[i], 10) : 0;
if (num1 !== num2)
return num1 - num2;
}
return 0;
};
exports.compareVersion = compareVersion;

View File

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

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,49 @@
import { String } from '../types/DataType';
import { LocaleDef } from '../types/Locale';
import { EntityShape } from '../types/Entity';
import { Index } from '../types/Storage';
import { Schema as Relation } from './Relation';
type Actions = string[];
export interface Schema extends EntityShape {
relation: Relation;
path: String<256>;
destEntity: String<32>;
deActions: Actions;
};
const indexes: Index<Schema>[] = [
{
name: 'index_relation_path',
attributes: [
{
name: 'relation',
},
{
name: 'path',
},
],
config: {
unique: true,
},
},
];
const locale: LocaleDef<
Schema,
'',
'',
{}
> = {
zh_CN: {
name: '用户授权',
attr: {
relation: '关系',
path: '路径',
destEntity: '目标对象',
deActions: '目标对象动作',
},
},
};

49
src/entities/Relation.ts Normal file
View File

@ -0,0 +1,49 @@
import { String } from '../types/DataType';
import { LocaleDef } from '../types/Locale';
import { EntityShape } from '../types/Entity';
import { Index } from '../types/Storage';
export interface Schema extends EntityShape {
entity: String<32>;
entityId: String<64>; // 可以为空
name: String<32>;
display: String<32>;
};
const indexes: Index<Schema>[] = [
{
name: 'index_entity_entityId_name',
attributes: [
{
name: 'entity',
},
{
name: 'entityId',
},
{
name: 'name',
}
],
config: {
unique: true,
},
},
];
const locale: LocaleDef<
Schema,
'',
'',
{}
> = {
zh_CN: {
name: '用户授权',
attr: {
name: '关系',
entity: '目标对象',
entityId: '目标对象id',
display: '显示值',
},
},
};

View File

@ -0,0 +1,49 @@
import { String } from '../types/DataType';
import { LocaleDef } from '../types/Locale';
import { EntityShape } from '../types/Entity';
import { Index } from '../types/Storage';
import { Schema as Relation } from './Relation';
type Relations = string[];
export interface Schema extends EntityShape {
relation: Relation;
path: String<256>;
destEntity: String<32>;
deRelations: Relations;
};
const indexes: Index<Schema>[] = [
{
name: 'index_relation_path',
attributes: [
{
name: 'relation',
},
{
name: 'path',
},
],
config: {
unique: true,
},
},
];
const locale: LocaleDef<
Schema,
'',
'',
{}
> = {
zh_CN: {
name: '用户授权',
attr: {
relation: '关系',
path: '路径',
destEntity: '目标对象',
deRelations: '目标对象关系',
},
},
};

View File

@ -0,0 +1,44 @@
import { String } from '../types/DataType';
import { LocaleDef } from '../types/Locale';
import { EntityShape } from '../types/Entity';
import { Index } from '../types/Storage';
import { Schema as User } from './User';
import { Schema as Relation } from './Relation';
export interface Schema extends EntityShape {
user: User;
relation: Relation;
};
const indexes: Index<Schema>[] = [
{
name: 'index_user_relation',
attributes: [
{
name: 'user',
},
{
name: 'relation',
},
],
config: {
unique: true,
},
},
];
const locale: LocaleDef<
Schema,
'',
'',
{}
> = {
zh_CN: {
name: '用户对象关系',
attr: {
user: '关系',
relation: '目标关系',
},
},
};

View File

@ -567,8 +567,8 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
if (foreignKey) {
// 基于属性的一对多
if (isAggr) {
// 是聚合运算
cascadeSelectionFns.push(
// 是聚合运算,只有后台才需要执行
(context instanceof AsyncContext) && cascadeSelectionFns.push(
(result) => {
const aggrResults = result.map(
(row) => {
@ -660,8 +660,8 @@ export abstract class CascadeStore<ED extends EntityDict & BaseEntityDict> exten
else {
// 基于entity的多对一
if (isAggr) {
// 是聚合运算
cascadeSelectionFns.push(
// 是聚合运算,只有后台才需要执行
(context instanceof AsyncContext) && cascadeSelectionFns.push(
(result) => {
const aggrResults = result.map(
(row) => {

View File

@ -115,7 +115,8 @@ export function translateCheckerInAsyncContext<
if (await checkFilterContains<ED, T, Cxt>(entity, context, result, filter, true)) {
return;
}
throw new OakUserUnpermittedException(errMsg);
const errMsg2 = typeof errMsg === 'function' ? errMsg(operation, context, option) : errMsg;
throw new OakUserUnpermittedException(errMsg2);
}
return 0;
}) as UpdateTriggerInTxn<ED, T, Cxt>['fn'];
@ -201,7 +202,8 @@ export function translateCheckerInSyncContext<
if (checkFilterContains<ED, T, Cxt>(entity, context, result as ED[T]['Selection']['filter'], filter, true)) {
return;
}
throw new OakUserUnpermittedException(errMsg);
const errMsg2 = typeof errMsg === 'function' ? errMsg(operation, context, option) : errMsg;
throw new OakUserUnpermittedException(errMsg2);
}
};
return {
@ -243,7 +245,7 @@ type CreateRelationCounter<ED extends EntityDict & BaseEntityDict> = CreateRelat
type FilterMakeFn<ED extends EntityDict & BaseEntityDict> =
(operation: ED[keyof ED]['Operation'] | ED[keyof ED]['Selection'], userId: string) => ED[keyof ED]['Selection']['filter'] | CreateRelationCounter<ED>;
(operation: ED[keyof ED]['Operation'] | ED[keyof ED]['Selection'], userId: string) => ED[keyof ED]['Selection']['filter'] | CreateRelationCounter<ED> | OakUserUnpermittedException<ED>;
function translateCascadeRelationFilterMaker<ED extends EntityDict & BaseEntityDict>(
schema: StorageSchema<ED>,
@ -440,19 +442,20 @@ function translateCascadeRelationFilterMaker<ED extends EntityDict & BaseEntityD
if (d.entity === attr && typeof d.entityId === 'string') {
return d.entityId as string;
}
throw new OakUserUnpermittedException();
}
else {
assert(typeof relation === 'string');
if (typeof d[`${attr}Id`] === 'string') {
return d[`${attr}Id`] as string;
}
throw new OakUserUnpermittedException();
}
};
if (relation === 2) {
if (data instanceof Array) {
const fkIds = uniq(data.map(d => getForeignKeyId(d)));
const fkIds = uniq(data.map(d => getForeignKeyId(d)).filter(ele => !!ele));
if (fkIds.length === 0) {
return new OakUserUnpermittedException();
}
return {
$entity: attr,
$filter: addFilterSegment(filterMaker2(userId), { id: { $in: fkIds } }),
@ -460,6 +463,9 @@ function translateCascadeRelationFilterMaker<ED extends EntityDict & BaseEntityD
};
}
const fkId = getForeignKeyId(data);
if (!fkId) {
return new OakUserUnpermittedException();
}
return {
$entity: attr,
$filter: addFilterSegment(filterMaker2(userId), { id: fkId }),
@ -467,7 +473,10 @@ function translateCascadeRelationFilterMaker<ED extends EntityDict & BaseEntityD
}
assert(typeof relation === 'string');
if (data instanceof Array) {
const fkIds = uniq(data.map(d => getForeignKeyId(d)));
const fkIds = uniq(data.map(d => getForeignKeyId(d)).filter(ele => !!ele));
if (fkIds.length === 0) {
return new OakUserUnpermittedException();
}
return {
$entity: relation,
$filter: addFilterSegment(filterMaker2(userId), { id: { $in: fkIds } }),
@ -475,6 +484,9 @@ function translateCascadeRelationFilterMaker<ED extends EntityDict & BaseEntityD
};
}
const fkId = getForeignKeyId(data);
if (!fkId) {
return new OakUserUnpermittedException();
}
return {
$entity: relation,
$filter: addFilterSegment(filterMaker2(userId), { id: fkId }),
@ -485,9 +497,9 @@ function translateCascadeRelationFilterMaker<ED extends EntityDict & BaseEntityD
const { filter } = operation as ED[keyof ED]['Selection'];
if (filter) {
const counter = translateCreateFilterMaker(entity2, filter, userId);
if (counter instanceof OakUserUnpermittedException) {
throw counter;
}
// if (counter instanceof OakUserUnpermittedException) {
// throw counter;
// }
return counter;
}
throw new OakUserUnpermittedException();
@ -621,13 +633,19 @@ function execCreateCounter<ED extends EntityDict & BaseEntityDict, Cxt extends A
}
else if ((<CreateRelationSingleCounter<ED>>counter)?.$entity) {
const { $entity, $filter, $count = 1 } = counter as CreateRelationSingleCounter<ED>;
const count = context.count($entity, {
// count不走reinforceSelection先用select
const result = context.select($entity, {
data: {
id: 1,
},
filter: $filter,
indexFrom: 0,
count: $count,
}, { dontCollect: true });
if (count instanceof Promise) {
return count.then(
(c2) => {
if (c2 >= $count) {
if (result instanceof Promise) {
return result.then(
(r2) => {
if (r2.length >= $count) {
return undefined;
}
return new OakUserUnpermittedException();
@ -635,7 +653,7 @@ function execCreateCounter<ED extends EntityDict & BaseEntityDict, Cxt extends A
);
}
else {
return count >= $count ? undefined : new OakUserUnpermittedException();
return result.length >= $count ? undefined : new OakUserUnpermittedException();
}
}
}
@ -804,7 +822,10 @@ export function createAuthCheckers<ED extends EntityDict & BaseEntityDict, Cxt e
return filter;
},
errMsg: '越权操作',
errMsg: (operation, context) => {
console.error(`创建${entity as string}时越权userId是${context.getCurrentUserId()},数据是${JSON.stringify(operation.data)}`);
return `创建${entity as string}时越权`;
},
});
checkers.push({
@ -863,7 +884,10 @@ export function createAuthCheckers<ED extends EntityDict & BaseEntityDict, Cxt e
}
return makeFilterFromRows(toBeRemoved); */
},
errMsg: '越权操作',
errMsg: (operation, context) => {
console.error(`移除${entity as string}时越权userId是${context.getCurrentUserId()},移除条件是${JSON.stringify(operation.filter)}`);
return `移除${entity as string}时越权`;
},
});
// 转让权限现在用update动作只允许update userId给其它人
// todo 等实现的时候再写
@ -881,7 +905,12 @@ export function createAuthCheckers<ED extends EntityDict & BaseEntityDict, Cxt e
const filter = makePotentialFilter(operation, context, filterMaker);
return filter;
},
errMsg: '定义的actionAuth中检查出来越权操作',
errMsg: (operation, context) => {
const { action, data, filter } = operation as ED[keyof ED]['Create'];
console.error(`${entity as string}进行${action}时越权userId是${context.getCurrentUserId()}
${JSON.stringify(data)}${JSON.stringify(filter)}`);
return `${entity as string}进行${action}时越权`;
},
});
}
}
@ -1264,7 +1293,7 @@ export function createCreateCheckers<ED extends EntityDict & BaseEntityDict, Cxt
continue;
}
}
else if (attr === 'entity' && attributes[attr].type === 'ref') {
else if (attr === 'entity' && attributes[attr].ref) {
let hasCascadeCreate = false;
for (const ref of attributes[attr].ref as string[]) {
if (data2[ref] && data2[ref].action === 'create') {

View File

@ -46,7 +46,7 @@ export type RelationChecker<ED extends EntityDict, T extends keyof ED, Cxt exten
when?: 'after';
action: ED[T]['Action'] | Array<ED[T]['Action']>;
relationFilter: (operation: ED[T]['Operation'] | ED[T]['Selection'], context: Cxt, option: OperateOption | SelectOption) => SyncOrAsync<ED[T]['Selection']['filter']>, // 生成一个额外的relation相关的filter加在原先的filter上
errMsg: string;
errMsg: string | ((operation: ED[T]['Operation'] | ED[T]['Selection'], context: Cxt, option?: OperateOption | SelectOption) => string);
conditionalFilter?: ED[T]['Update']['filter'] | (
(operation: ED[T]['Operation'], context: Cxt, option: OperateOption) => SyncOrAsync<ED[T]['Selection']['filter']>
);

View File

@ -25,4 +25,13 @@ export abstract class Connector<ED extends EntityDict, BackCxt extends AsyncCont
body: any;
headers?: Record<string, any>;
};
abstract getBridgeRouter(): string;
abstract makeBridgeUrl(url: string, headers?: Record<string, string>): string;
abstract parseBridgeRequestQuery(urlParams: string): {
url: string;
headers?: Record<string, string>;
}
}

View File

@ -257,3 +257,6 @@ export type Configuration = {
actionType?: ActionType;
static?: boolean; // 标识是维表(变动较小,相对独立)
};
// 一对多的键值的扩展
export type OtmKey<K extends string> = K | `${K}$${number}`;

View File

@ -1,6 +1,7 @@
import assert from 'assert';
import { IncomingHttpHeaders } from "http";
import { Stream } from 'stream';
import URL from 'url';
import { AsyncContext, AsyncRowStore } from '../store/AsyncRowStore';
import { SyncContext } from '../store/SyncRowStore';
import { Connector, EntityDict, OakException, OakExternalException, OpRecord } from "../types";
@ -23,14 +24,17 @@ function makeContentTypeAndBody(data: any) {
}
export class SimpleConnector<ED extends EntityDict, BackCxt extends AsyncContext<ED>, FrontCxt extends SyncContext<ED>> extends Connector<ED, BackCxt, FrontCxt> {
static ROUTER = '/aspect';
private serverUrl: string;
static ASPECT_ROUTER = '/aspect';
static BRIDGE_ROUTER = '/bridge';
private serverAspectUrl: string;
private serverBridgeUrl: string;
private makeException: (exceptionData: any) => OakException<ED>;
private contextBuilder: (str: string | undefined) => (store: AsyncRowStore<ED, BackCxt>) => Promise<BackCxt>;
constructor(serverUrl: string, makeException: (exceptionData: any) => OakException<ED>, contextBuilder: (str: string | undefined) => (store: AsyncRowStore<ED, BackCxt>) => Promise<BackCxt>) {
super();
this.serverUrl = `${serverUrl}${SimpleConnector.ROUTER}`;
this.serverAspectUrl = `${serverUrl}${SimpleConnector.ASPECT_ROUTER}`;
this.serverBridgeUrl = `${serverUrl}${SimpleConnector.BRIDGE_ROUTER}`;
this.makeException = makeException;
this.contextBuilder = contextBuilder;
}
@ -39,7 +43,7 @@ export class SimpleConnector<ED extends EntityDict, BackCxt extends AsyncContext
const cxtStr = context.toString();
const { contentType, body } = makeContentTypeAndBody(params);
const response = await global.fetch(this.serverUrl, {
const response = await global.fetch(this.serverAspectUrl, {
method: 'POST',
headers: Object.assign(
{
@ -88,7 +92,7 @@ export class SimpleConnector<ED extends EntityDict, BackCxt extends AsyncContext
}
getRouter(): string {
return SimpleConnector.ROUTER;
return SimpleConnector.ASPECT_ROUTER;
}
async parseRequest(headers: IncomingHttpHeaders, body: any, store: AsyncRowStore<ED, BackCxt>): Promise<{ name: string; params: any; context: BackCxt; }> {
@ -130,4 +134,39 @@ export class SimpleConnector<ED extends EntityDict, BackCxt extends AsyncContext
},
};
}
getBridgeRouter(): string {
return SimpleConnector.BRIDGE_ROUTER;
}
/**
* 访url
* @param url
* @param headers
*/
makeBridgeUrl(url: string, headers?: Record<string, string>) {
// if (process.env.PROD !== 'true') {
//     console.warn('在development下无法通过bridge访问资源将直接访问可能失败', url);
//     return url;
// }
const encodeUrl = encodeURIComponent(url);
// const urlParse = URL.parse(url, true);
// const { search } = urlParse as {
//     search: string;
// };
// if (headers) {
//     search.append('headers', JSON.stringify(headers));
// }
return `${this.serverBridgeUrl}?url=${encodeUrl}`;
}
parseBridgeRequestQuery(urlParams: string): { url: string; headers?: Record<string, string> | undefined; } {
const search = new URL.URLSearchParams(urlParams);
const url = search.get('url') as string;
const headers = search.get('headers');
return {
url,
headers: headers && JSON.parse(headers),
};
}
}

View File

@ -1,27 +1,41 @@
const ToCent: (float: number) => number = (float) => {
return Math.round(float * 100);
}
};
const ToYuan: (int: number) => number = ( int) => {
const ToYuan: (int: number) => number = (int) => {
return Math.round(int) / 100;
}
};
const StringToCent: (value: string, allowNegative?: true) => number | undefined = (value, allowNegative) => {
const StringToCent: (
value: string,
allowNegative?: true
) => number | undefined = (value, allowNegative) => {
const numValue = parseInt(value, 10);
if (typeof numValue === 'number' && (numValue >= 0 || allowNegative)) {
return ToCent(numValue);
}
}
};
const CentToString: (value: number) => string | undefined = (value) => {
if (typeof value === 'number') {
return `${ToYuan(value)}`;
}
}
};
export {
ToCent,
ToYuan,
StringToCent,
CentToString,
}
const ThousandCont: (value: number) => string | undefined = (value) => {
let value1 = `${value}`;
const numArr = value1.split('.');
value1 = numArr[0];
let result = '';
while (value1.length > 3) {
result = ',' + value1.slice(-3) + result;
value1 = value1.slice(0, value1.length - 3);
}
if (value1) {
result = value1 + result;
}
result = result + '.' + numArr[1];
return result;
};
export { ToCent, ToYuan, StringToCent, CentToString, ThousandCont };

18
src/utils/version.ts Normal file
View File

@ -0,0 +1,18 @@
/**
*
* @param curVersion
* @param reqVersion
* @returns
*/
export const compareVersion = (curVersion: string, reqVersion: string): number => {
const v1 = curVersion.split('.');
const v2 = reqVersion.split('.');
for (let i = 0; i < Math.max(v1.length, v2.length); i++) {
const num1 = i < v1.length ? parseInt(v1[i], 10) : 0;
const num2 = i < v2.length ? parseInt(v2[i], 10) : 0;
if (num1 !== num2) return num1 - num2;
}
return 0;
};

View File

@ -65,7 +65,7 @@
/* Advanced Options */
"forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
},
"include": ["src/**/*" ],
"include": ["src/**/*", "scripts/ActionAuth.ts222" ],
"exclude": [
"node_modules",
"**/*.spec.ts",