一些定义
This commit is contained in:
parent
169ea75924
commit
135d8ac69f
|
|
@ -1568,7 +1568,17 @@ function outputEntityDict(outputDir, printer) {
|
|||
const entityLc = (0, utils_1.firstLetterLowerCase)(entity);
|
||||
propertySignatures.push(factory.createPropertySignature(undefined, factory.createIdentifier(entityLc), undefined, factory.createTypeReferenceNode(entity)));
|
||||
}
|
||||
statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("EntityDict"), undefined, factory.createTypeLiteralNode(propertySignatures)));
|
||||
if ( /* process.env.TARGET_IN_OAK_DOMAIN */false) {
|
||||
statements.push(factory.createImportDeclaration(undefined, undefined, factory.createImportClause(false, undefined, factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier("EntityDef"))])), factory.createStringLiteral("../types/Entity"), undefined), factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("EntityDict"), undefined, factory.createIntersectionTypeNode([
|
||||
factory.createTypeLiteralNode(propertySignatures),
|
||||
factory.createTypeLiteralNode([
|
||||
factory.createIndexSignature(undefined, undefined, [factory.createParameterDeclaration(undefined, undefined, undefined, factory.createIdentifier("E"), undefined, factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword), undefined)], factory.createTypeReferenceNode(factory.createIdentifier("EntityDef"), undefined))
|
||||
])
|
||||
])));
|
||||
}
|
||||
else {
|
||||
statements.push(factory.createTypeAliasDeclaration(undefined, [factory.createModifier(ts.SyntaxKind.ExportKeyword)], factory.createIdentifier("EntityDict"), undefined, factory.createTypeLiteralNode(propertySignatures)));
|
||||
}
|
||||
const resultFile = ts.createSourceFile("someFileName.ts", "", ts.ScriptTarget.Latest, /*setParentNodes*/ false, ts.ScriptKind.TS);
|
||||
const result = printer.printNode(ts.EmitHint.Unspecified, factory.createSourceFile(statements, factory.createToken(ts.SyntaxKind.EndOfFileToken), ts.NodeFlags.None), resultFile);
|
||||
const fileName = path_1.default.join(outputDir, 'EntityDict.ts');
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
import { RunningContext } from "./Context";
|
||||
import { EntityDef } from "./Entity";
|
||||
export interface Aspect<ED extends Record<string, EntityDef>> {
|
||||
export interface Aspect<ED extends {
|
||||
[E: string]: EntityDef;
|
||||
}> {
|
||||
(params: any, context: RunningContext<ED>): any;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,19 +1,15 @@
|
|||
import { EntityDef } from './Entity';
|
||||
import { EntityDict } from './Entity';
|
||||
import { RowStore } from './RowStore';
|
||||
import { Schema as Application } from '../entities/Application';
|
||||
import { Schema as Token } from '../entities/Token';
|
||||
export interface Context<ED extends {
|
||||
[E: string]: EntityDef;
|
||||
}> {
|
||||
import { Schema as Application } from '../base-domain/Application/Schema';
|
||||
import { Schema as Token } from '../base-domain/Token/Schema';
|
||||
export interface Context<ED extends EntityDict> {
|
||||
rowStore: RowStore<ED>;
|
||||
on(event: 'commit' | 'rollback', callback: (context: Context<ED>) => Promise<void>): void;
|
||||
begin(options?: object): Promise<void>;
|
||||
commit(): Promise<void>;
|
||||
rollback(): Promise<void>;
|
||||
}
|
||||
export interface RunningContext<ED extends {
|
||||
[E: string]: EntityDef;
|
||||
}> extends Context<ED> {
|
||||
application: Application;
|
||||
token?: Token;
|
||||
export interface RunningContext<ED extends EntityDict> extends Context<ED> {
|
||||
getApplication: () => Application;
|
||||
getToken: () => Token | undefined;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,9 @@ export interface EntityDef {
|
|||
Selection: Omit<DeduceSelection<this['Schema']>, 'action'>;
|
||||
Operation: DeduceOperation<this['Schema']>;
|
||||
}
|
||||
export interface EntityDict {
|
||||
[E: string]: EntityDef;
|
||||
}
|
||||
declare type DeduceProjection<SH extends EntityShape> = Partial<{
|
||||
'#id': NodeId;
|
||||
} & {
|
||||
|
|
@ -72,9 +75,7 @@ export declare type DeduceRemoveOperationData<SH extends EntityShape> = {
|
|||
};
|
||||
export declare type DeduceRemoveOperation<SH extends EntityShape> = Operation<'remove', DeduceRemoveOperationData<SH>, DeduceFilter<SH>>;
|
||||
export declare type DeduceOperation<SH extends EntityShape> = DeduceCreateOperation<SH> | DeduceUpdateOperation<SH> | DeduceRemoveOperation<SH> | DeduceSelection<SH>;
|
||||
export interface OperationResult<ED extends {
|
||||
[K: string]: EntityDef;
|
||||
}> {
|
||||
export interface OperationResult<ED extends EntityDict> {
|
||||
operations?: {
|
||||
[T in keyof ED]?: Array<ED[keyof ED]['Operation']>;
|
||||
};
|
||||
|
|
@ -85,9 +86,7 @@ export interface OperationResult<ED extends {
|
|||
message: string;
|
||||
}>;
|
||||
}
|
||||
export declare type SelectionResult<ED extends {
|
||||
[K: string]: EntityDef;
|
||||
}, T extends keyof ED> = {
|
||||
export declare type SelectionResult<ED extends EntityDict, T extends keyof ED> = {
|
||||
result: Array<Partial<ED[T]['Schema'] & {
|
||||
[A in ExpressionKey]?: any;
|
||||
}>>;
|
||||
|
|
|
|||
|
|
@ -2,3 +2,4 @@
|
|||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
;
|
||||
;
|
||||
;
|
||||
|
|
|
|||
|
|
@ -3311,17 +3311,68 @@ function outputEntityDict(outputDir: string, printer: ts.Printer) {
|
|||
);
|
||||
}
|
||||
|
||||
statements.push(
|
||||
factory.createTypeAliasDeclaration(
|
||||
undefined,
|
||||
[factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
||||
factory.createIdentifier("EntityDict"),
|
||||
undefined,
|
||||
factory.createTypeLiteralNode(
|
||||
propertySignatures
|
||||
if (/* process.env.TARGET_IN_OAK_DOMAIN */false) {
|
||||
statements.push(
|
||||
factory.createImportDeclaration(
|
||||
undefined,
|
||||
undefined,
|
||||
factory.createImportClause(
|
||||
false,
|
||||
undefined,
|
||||
factory.createNamedImports([factory.createImportSpecifier(
|
||||
false,
|
||||
undefined,
|
||||
factory.createIdentifier("EntityDef")
|
||||
)])
|
||||
),
|
||||
factory.createStringLiteral("../types/Entity"),
|
||||
undefined
|
||||
),
|
||||
factory.createTypeAliasDeclaration(
|
||||
undefined,
|
||||
[factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
||||
factory.createIdentifier("EntityDict"),
|
||||
undefined,
|
||||
factory.createIntersectionTypeNode([
|
||||
factory.createTypeLiteralNode(
|
||||
propertySignatures
|
||||
),
|
||||
factory.createTypeLiteralNode([
|
||||
factory.createIndexSignature(
|
||||
undefined,
|
||||
undefined,
|
||||
[factory.createParameterDeclaration(
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
factory.createIdentifier("E"),
|
||||
undefined,
|
||||
factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),
|
||||
undefined
|
||||
)],
|
||||
factory.createTypeReferenceNode(
|
||||
factory.createIdentifier("EntityDef"),
|
||||
undefined
|
||||
)
|
||||
)
|
||||
])
|
||||
])
|
||||
)
|
||||
)
|
||||
);
|
||||
);
|
||||
}
|
||||
else {
|
||||
statements.push(
|
||||
factory.createTypeAliasDeclaration(
|
||||
undefined,
|
||||
[factory.createModifier(ts.SyntaxKind.ExportKeyword)],
|
||||
factory.createIdentifier("EntityDict"),
|
||||
undefined,
|
||||
factory.createTypeLiteralNode(
|
||||
propertySignatures
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
const resultFile = ts.createSourceFile("someFileName.ts", "", ts.ScriptTarget.Latest, /*setParentNodes*/ false, ts.ScriptKind.TS);
|
||||
const result = printer.printNode(
|
||||
|
|
@ -4152,7 +4203,7 @@ export function analyzeEntities(inputDir: string) {
|
|||
);
|
||||
}
|
||||
|
||||
export function buildSchema(outputDir: string): void {
|
||||
export function buildSchema(outputDir: string): void {
|
||||
addReverseRelationship();
|
||||
const printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed });
|
||||
resetOutputDir(outputDir);
|
||||
|
|
@ -4161,7 +4212,7 @@ export function buildSchema(outputDir: string): void {
|
|||
outputAction(outputDir, printer);
|
||||
outputEntityDict(outputDir, printer);
|
||||
outputStorage(outputDir, printer);
|
||||
|
||||
|
||||
if (!process.env.TARGET_IN_OAK_DOMAIN) {
|
||||
outputPackageJson(outputDir);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,10 @@
|
|||
import { EntityDef, EntityShape } from './Entity';
|
||||
import { EntityDef, EntityDict } from './Entity';
|
||||
import { RowStore } from './RowStore';
|
||||
import { Schema as Application } from '../entities/Application';
|
||||
import { Schema as Token } from '../entities/Token';
|
||||
import { Schema as Application } from '../base-domain/Application/Schema';
|
||||
import { Schema as Token } from '../base-domain/Token/Schema';
|
||||
|
||||
|
||||
export interface Context<ED extends {
|
||||
[E: string]: EntityDef;
|
||||
}>{
|
||||
export interface Context<ED extends EntityDict>{
|
||||
rowStore: RowStore<ED>;
|
||||
on(event: 'commit' | 'rollback', callback: (context: Context<ED>) => Promise<void>): void;
|
||||
begin(options?: object): Promise<void>;
|
||||
|
|
@ -14,9 +12,7 @@ export interface Context<ED extends {
|
|||
rollback():Promise<void>;
|
||||
};
|
||||
|
||||
export interface RunningContext<ED extends {
|
||||
[E: string]: EntityDef;
|
||||
}> extends Context<ED> {
|
||||
application: Application;
|
||||
token?: Token;
|
||||
export interface RunningContext<ED extends EntityDict> extends Context<ED> {
|
||||
getApplication: () => Application;
|
||||
getToken: () => Token | undefined;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -53,6 +53,10 @@ export interface EntityDef {
|
|||
Operation: DeduceOperation<this['Schema']>;
|
||||
};
|
||||
|
||||
export interface EntityDict {
|
||||
[E: string]: EntityDef;
|
||||
};
|
||||
|
||||
type DeduceProjection<SH extends EntityShape> = Partial<{
|
||||
'#id': NodeId;
|
||||
} & {
|
||||
|
|
@ -98,9 +102,7 @@ export type DeduceRemoveOperation<SH extends EntityShape> = Operation<'remove',
|
|||
|
||||
export type DeduceOperation<SH extends EntityShape> = DeduceCreateOperation<SH> | DeduceUpdateOperation<SH> | DeduceRemoveOperation<SH> | DeduceSelection<SH>;
|
||||
|
||||
export interface OperationResult<ED extends {
|
||||
[K: string]: EntityDef;
|
||||
}> {
|
||||
export interface OperationResult<ED extends EntityDict> {
|
||||
operations?: { // cud返回的结果,select返回create
|
||||
[T in keyof ED]?: Array<ED[keyof ED]['Operation']>;
|
||||
}; // create/update/remove返回的动作结果
|
||||
|
|
@ -112,9 +114,7 @@ export interface OperationResult<ED extends {
|
|||
}>;
|
||||
};
|
||||
|
||||
export type SelectionResult<ED extends {
|
||||
[K: string]: EntityDef;
|
||||
}, T extends keyof ED> = {
|
||||
export type SelectionResult<ED extends EntityDict, T extends keyof ED> = {
|
||||
result: Array<Partial<ED[T]['Schema'] & {
|
||||
[A in ExpressionKey]?: any;
|
||||
}>>;
|
||||
|
|
|
|||
Loading…
Reference in New Issue