mirror of https://github.com/abpframework/abp.git
1 changed files with 74 additions and 20 deletions
@ -1,43 +1,97 @@ |
|||||
import { Import } from './import'; |
import { Import } from './import'; |
||||
import { Omissible } from './util'; |
import { Options } from './util'; |
||||
|
|
||||
export class Model { |
export class Model { |
||||
imports: Import[] = []; |
readonly imports: Import[] = []; |
||||
interfaces: Interface[] = []; |
readonly interfaces: Interface[] = []; |
||||
namespace: string; |
readonly namespace: string; |
||||
path: string; |
readonly path: string; |
||||
|
|
||||
constructor(options: ModelOptions) { |
constructor(options: ModelOptions) { |
||||
Object.assign(this, options); |
Object.assign(this, options); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
export type ModelOptions = Omissible<Model, 'imports' | 'interfaces'>; |
export type ModelOptions = Options<Model, 'imports' | 'interfaces'>; |
||||
|
|
||||
export class Interface { |
export class Interface { |
||||
base: string | null; |
readonly base: string | null; |
||||
identifier: string; |
readonly identifier: string; |
||||
namespace: string; |
readonly namespace: string; |
||||
properties: Property[] = []; |
readonly generics: Generic[] = []; |
||||
ref: string; |
readonly properties: Property[] = []; |
||||
|
readonly ref: string; |
||||
|
|
||||
constructor(options: InterfaceOptions) { |
constructor(options: InterfaceOptions) { |
||||
Object.assign(this, options); |
Object.assign(this, options); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
export type InterfaceOptions = Omissible<Interface, 'properties'>; |
export type InterfaceOptions = Options<Interface, 'generics' | 'properties'>; |
||||
|
|
||||
export class Property { |
abstract class TypeRef { |
||||
name: string; |
readonly refs: string[] = []; |
||||
type: string; |
|
||||
default = ''; |
|
||||
optional: '' | '?' = ''; |
|
||||
refs: string[] = []; |
|
||||
|
|
||||
constructor(options: PropertyOptions) { |
protected _type = ''; |
||||
|
get type() { |
||||
|
return this._type; |
||||
|
} |
||||
|
set type(value: string) { |
||||
|
if (!value) return; |
||||
|
this._type = value; |
||||
|
} |
||||
|
|
||||
|
protected _default = ''; |
||||
|
get default() { |
||||
|
return this._default; |
||||
|
} |
||||
|
set default(value: string) { |
||||
|
if (!value) return; |
||||
|
this._default = ` = ${value}`; |
||||
|
} |
||||
|
|
||||
|
constructor(options: TypeRefOptions) { |
||||
Object.assign(this, options); |
Object.assign(this, options); |
||||
} |
} |
||||
|
|
||||
|
setDefault(value: string) { |
||||
|
this.default = value; |
||||
|
} |
||||
|
|
||||
|
setType(value: string) { |
||||
|
this.type = value; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
type TypeRefOptionalKeys = 'default' | 'refs'; |
||||
|
type TypeRefOptions = Options<TypeRef, TypeRefOptionalKeys>; |
||||
|
|
||||
|
export class Generic extends TypeRef { |
||||
|
constructor(options: GenericOptions) { |
||||
|
super(options); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export type GenericOptions = Options<Generic, TypeRefOptionalKeys>; |
||||
|
|
||||
|
export class Property extends TypeRef { |
||||
|
readonly name: string; |
||||
|
private _optional: '' | '?' = ''; |
||||
|
get optional() { |
||||
|
return this.default ? '' : this._optional; |
||||
|
} |
||||
|
|
||||
|
set optional(value: '' | '?') { |
||||
|
this._optional = value; |
||||
|
} |
||||
|
|
||||
|
constructor(options: PropertyOptions) { |
||||
|
super(options); |
||||
|
} |
||||
|
|
||||
|
setOptional(isOptional: boolean) { |
||||
|
this.optional = isOptional ? '?' : ''; |
||||
|
} |
||||
} |
} |
||||
|
|
||||
export type PropertyOptions = Omissible<Property, 'default' | 'optional' | 'refs'>; |
export type PropertyOptions = Options<Property, TypeRefOptionalKeys | 'optional'>; |
||||
|
|||||
Loading…
Reference in new issue