IS Model interfaces are now classes

This commit is contained in:
Luca Frosini 2019-10-16 14:41:51 +02:00
parent 21a2ff9195
commit 1fb772b38b
18 changed files with 87 additions and 20 deletions

View File

@ -1,7 +1,7 @@
import { ISManageable } from './ISManageable'; import { ISManageable } from './ISManageable';
import { Header } from './properties/Header'; import { Header } from './properties/Header';
export interface ER extends ISManageable { export class ER extends ISManageable {
header: Header; header: Header;

View File

@ -1,3 +1,3 @@
export interface ISManageable { export class ISManageable {
'@class': string; '@class': string;
} }

View File

@ -1,7 +1,7 @@
import { Entity } from './Entity'; import { Entity } from './Entity';
import { IsParentOf } from '../relations/IsParentOf'; import { IsParentOf } from '../relations/IsParentOf';
export interface Context extends Entity { export class Context extends Entity {
name: string; name: string;
parent: IsParentOf<Context, Context>; parent: IsParentOf<Context, Context>;

View File

@ -1,6 +1,5 @@
import { ER } from '../ER'; import { ER } from '../ER';
// tslint:disable-next-line: no-empty-interface export abstract class Entity extends ER {
export interface Entity extends ER {
} }

View File

@ -1,6 +1,7 @@
import { Entity } from './Entity'; import { Entity } from './Entity';
// tslint:disable-next-line: no-empty-interface export class Facet extends Entity {
export interface Facet extends Entity {
[x: string]: any;
} }

View File

@ -3,7 +3,7 @@ import { ConsistsOf } from '../relations/ConsistsOf';
import { IsRelatedTo } from '../relations/IsRelatedTo'; import { IsRelatedTo } from '../relations/IsRelatedTo';
import { Facet } from './Facet'; import { Facet } from './Facet';
export interface Resource extends Entity { export class Resource extends Entity {
consistsOf: Array<ConsistsOf<Resource, Facet>>; consistsOf: Array<ConsistsOf<Resource, Facet>>;
isRelatedTo: Array<IsRelatedTo<Resource, Resource>>; isRelatedTo: Array<IsRelatedTo<Resource, Resource>>;

View File

@ -1,5 +1,5 @@
import { Property } from './Property'; import { Property } from './Property';
export interface Encrypted extends Property { export class Encrypted extends Property {
value: string; value: string;
} }

View File

@ -1,6 +1,6 @@
import { Property } from './Property'; import { Property } from './Property';
export interface Header extends Property { export class Header extends Property {
'uuid': string; 'uuid': string;
'creator': string; 'creator': string;
'modifiedBy': string; 'modifiedBy': string;

View File

@ -31,9 +31,15 @@ export enum AddConstraint {
} }
export interface PropagationConstraint extends Property { export class PropagationConstraint extends Property {
remove: RemoveConstraint; remove: RemoveConstraint;
add: AddConstraint; add: AddConstraint;
constructor(remove: RemoveConstraint, add: AddConstraint){
super();
this.remove = remove;
this.add = add;
}
} }

View File

@ -1,6 +1,6 @@
import { ISManageable } from '../ISManageable'; import { ISManageable } from '../ISManageable';
// tslint:disable-next-line: no-empty-interface // tslint:disable-next-line: no-empty-interface
export interface Property extends ISManageable { export class Property extends ISManageable {
} }

View File

@ -1,7 +1,13 @@
import { Resource } from '../entities/Resource'; import { Resource } from '../entities/Resource';
import { Relation } from './Relation'; import { Relation } from './Relation';
import { Facet } from '../entities/Facet'; import { Facet } from '../entities/Facet';
import { PropagationConstraint, RemoveConstraint, AddConstraint } from '../properties/PropagationConstraint';
export interface ConsistsOf<Out extends Resource, In extends Facet> extends Relation<Out, In> { export class ConsistsOf<Out extends Resource, In extends Facet> extends Relation<Out, In> {
constructor(propagationConstraint: PropagationConstraint =
new PropagationConstraint(RemoveConstraint.cascade, AddConstraint.unpropagate)) {
super(propagationConstraint);
}
} }

View File

@ -2,6 +2,6 @@ import { Resource } from '../entities/Resource';
import { ConsistsOf } from './ConsistsOf'; import { ConsistsOf } from './ConsistsOf';
import { Facet } from '../entities/Facet'; import { Facet } from '../entities/Facet';
export interface IsIdentifiedBy<Out extends Resource, In extends Facet> extends ConsistsOf<Out, In> { export class IsIdentifiedBy<Out extends Resource, In extends Facet> extends ConsistsOf<Out, In> {
} }

View File

@ -1,7 +1,7 @@
import { Context } from '../entities/Context'; import { Context } from '../entities/Context';
import { Relation } from './Relation'; import { Relation } from './Relation';
export interface IsParentOf<Out extends Context, In extends Context> export class IsParentOf<Out extends Context, In extends Context>
extends Relation<Out, In> { extends Relation<Out, In> {
} }

View File

@ -1,6 +1,11 @@
import { Resource } from '../entities/Resource'; import { Resource } from '../entities/Resource';
import { Relation } from './Relation'; import { Relation } from './Relation';
import { RemoveConstraint, AddConstraint, PropagationConstraint } from '../properties/PropagationConstraint';
export interface IsRelatedTo<Out extends Resource, In extends Resource> extends Relation<Out, In> { export class IsRelatedTo<Out extends Resource, In extends Resource> extends Relation<Out, In> {
constructor(propagationConstraint: PropagationConstraint =
new PropagationConstraint(RemoveConstraint.keep, AddConstraint.unpropagate)) {
super(propagationConstraint);
}
} }

View File

@ -1,9 +1,18 @@
import { Entity } from '../entities/Entity'; import { Entity } from '../entities/Entity';
import { ER } from '../ER'; import { ER } from '../ER';
import { PropagationConstraint } from '../properties/PropagationConstraint';
export interface Relation<Out extends Entity, In extends Entity> extends ER { export abstract class Relation<Out extends Entity, In extends Entity> extends ER {
source: Out; source?: Out;
target: In; target: In;
propagationConstraint?: PropagationConstraint;
[x: string]: any;
constructor(propagationConstraint?: PropagationConstraint) {
super();
this.propagationConstraint = propagationConstraint;
}
} }

View File

@ -0,0 +1,35 @@
enum OType {
Boolean = 0,
Integer = 1,
Short = 2,
Long = 3,
Float = 4,
Double = 5,
Datetime = 6,
String = 7,
Bynary = 8,
Property = 9,
'Property List' = 10,
'Property Set' = 11,
'Property Map' = 12,
Byte = 17,
Binary = 8
}
export interface PropertyDefinition {
name: string;
description: string;
mandatory: boolean;
readonly: boolean;
notnull: boolean;
max: number | null;
min: number | null;
regexp: string | null;
linkedType: OType | null;
linkedClass: string | null;
type: number | null;
}

View File

@ -1,7 +1,9 @@
import { PropertyDefinition } from './PropertyDefinition';
export interface TypeDefinition { export interface TypeDefinition {
name: string; name: string;
description: string | null; description: string | null;
abstract: boolean; abstract: boolean;
superClasses?: string[]; superClasses?: Set<string>;
properties?: any[]; properties?: Array<PropertyDefinition>;
} }

View File

@ -1,4 +1,5 @@
export const TYPE_PROPERTY_KEY = '@class'; export const TYPE_PROPERTY_KEY = '@class';
export const HEADER_PROPERTY_KEY = 'header';
export class ResourceIdentification { export class ResourceIdentification {
@ -20,6 +21,9 @@ export class ResourceIdentification {
if (propertyKey.localeCompare(TYPE_PROPERTY_KEY) === 0) { if (propertyKey.localeCompare(TYPE_PROPERTY_KEY) === 0) {
continue; continue;
} }
if (propertyKey.localeCompare(HEADER_PROPERTY_KEY) === 0) {
continue;
}
this.mandatoryProperties.add(propertyKey); this.mandatoryProperties.add(propertyKey);
} }
this.first = false; this.first = false;