diff --git a/lib/compiler/schemalBuilder.js b/lib/compiler/schemalBuilder.js index f2ad8b5..55f4f3f 100644 --- a/lib/compiler/schemalBuilder.js +++ b/lib/compiler/schemalBuilder.js @@ -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'); diff --git a/lib/types/Aspect.d.ts b/lib/types/Aspect.d.ts index 4e0631b..1bc2fa9 100644 --- a/lib/types/Aspect.d.ts +++ b/lib/types/Aspect.d.ts @@ -1,5 +1,7 @@ import { RunningContext } from "./Context"; import { EntityDef } from "./Entity"; -export interface Aspect> { +export interface Aspect { (params: any, context: RunningContext): any; } diff --git a/lib/types/Context.d.ts b/lib/types/Context.d.ts index ef8ab84..ef824db 100644 --- a/lib/types/Context.d.ts +++ b/lib/types/Context.d.ts @@ -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 { +import { Schema as Application } from '../base-domain/Application/Schema'; +import { Schema as Token } from '../base-domain/Token/Schema'; +export interface Context { rowStore: RowStore; on(event: 'commit' | 'rollback', callback: (context: Context) => Promise): void; begin(options?: object): Promise; commit(): Promise; rollback(): Promise; } -export interface RunningContext extends Context { - application: Application; - token?: Token; +export interface RunningContext extends Context { + getApplication: () => Application; + getToken: () => Token | undefined; } diff --git a/lib/types/Entity.d.ts b/lib/types/Entity.d.ts index 26892a7..5295ba6 100644 --- a/lib/types/Entity.d.ts +++ b/lib/types/Entity.d.ts @@ -42,6 +42,9 @@ export interface EntityDef { Selection: Omit, 'action'>; Operation: DeduceOperation; } +export interface EntityDict { + [E: string]: EntityDef; +} declare type DeduceProjection = Partial<{ '#id': NodeId; } & { @@ -72,9 +75,7 @@ export declare type DeduceRemoveOperationData = { }; export declare type DeduceRemoveOperation = Operation<'remove', DeduceRemoveOperationData, DeduceFilter>; export declare type DeduceOperation = DeduceCreateOperation | DeduceUpdateOperation | DeduceRemoveOperation | DeduceSelection; -export interface OperationResult { +export interface OperationResult { operations?: { [T in keyof ED]?: Array; }; @@ -85,9 +86,7 @@ export interface OperationResult; } -export declare type SelectionResult = { +export declare type SelectionResult = { result: Array>; diff --git a/lib/types/Entity.js b/lib/types/Entity.js index 89f6374..a4c47f6 100644 --- a/lib/types/Entity.js +++ b/lib/types/Entity.js @@ -2,3 +2,4 @@ Object.defineProperty(exports, "__esModule", { value: true }); ; ; +; diff --git a/src/compiler/schemalBuilder.ts b/src/compiler/schemalBuilder.ts index 6abf52e..0388662 100644 --- a/src/compiler/schemalBuilder.ts +++ b/src/compiler/schemalBuilder.ts @@ -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); } diff --git a/src/types/Context.ts b/src/types/Context.ts index 80060b3..524f677 100644 --- a/src/types/Context.ts +++ b/src/types/Context.ts @@ -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{ +export interface Context{ rowStore: RowStore; on(event: 'commit' | 'rollback', callback: (context: Context) => Promise): void; begin(options?: object): Promise; @@ -14,9 +12,7 @@ export interface Context; }; -export interface RunningContext extends Context { - application: Application; - token?: Token; +export interface RunningContext extends Context { + getApplication: () => Application; + getToken: () => Token | undefined; }; diff --git a/src/types/Entity.ts b/src/types/Entity.ts index f942899..3ce6d49 100644 --- a/src/types/Entity.ts +++ b/src/types/Entity.ts @@ -53,6 +53,10 @@ export interface EntityDef { Operation: DeduceOperation; }; +export interface EntityDict { + [E: string]: EntityDef; +}; + type DeduceProjection = Partial<{ '#id': NodeId; } & { @@ -98,9 +102,7 @@ export type DeduceRemoveOperation = Operation<'remove', export type DeduceOperation = DeduceCreateOperation | DeduceUpdateOperation | DeduceRemoveOperation | DeduceSelection; -export interface OperationResult { +export interface OperationResult { operations?: { // cud返回的结果,select返回create [T in keyof ED]?: Array; }; // create/update/remove返回的动作结果 @@ -112,9 +114,7 @@ export interface OperationResult; }; -export type SelectionResult = { +export type SelectionResult = { result: Array>;