Skip to content

Commit

Permalink
Rename and made readonly non-native fields in metamodels
Browse files Browse the repository at this point in the history
  • Loading branch information
akphi committed May 10, 2022
1 parent d0962ae commit c5677f7
Show file tree
Hide file tree
Showing 126 changed files with 361 additions and 304 deletions.
10 changes: 10 additions & 0 deletions .changeset/cold-readers-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@finos/legend-application': patch
'@finos/legend-extension-dsl-diagram': patch
'@finos/legend-extension-mapping-generation': patch
'@finos/legend-graph': patch
'@finos/legend-query': patch
'@finos/legend-server-sdlc': patch
'@finos/legend-shared': patch
'@finos/legend-studio': patch
---
5 changes: 5 additions & 0 deletions .changeset/new-poems-end.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@finos/legend-graph': major
---

**BREAKING CHANGE:** Renamed extra fields added to the metamodels for navigation or other graph management purposes, such as `owner`, `parent`, `uuid`, etc. to `_OWNER`, `_PARENT`, `_UUID`, etc.; these fields are also made `readonly`.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
* editing _something_ but allows user to edit via text.
*/
export abstract class LambdaEditorState {
uuid = uuid();
readonly uuid = uuid();
lambdaPrefix: string;
lambdaString: string; // value shown in lambda editor which can be edited
parserError?: ParserError | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import { DIAGRAM_HASH_STRUCTURE } from '../../../../DSLDiagram_ModelUtils';
import type { Class, PackageableElementReference } from '@finos/legend-graph';

export class ClassView extends PositionedRectangle implements Hashable {
owner: Diagram;
readonly _OWNER: Diagram;

class: PackageableElementReference<Class>;
id: string;
hideProperties?: boolean | undefined;
Expand All @@ -36,7 +37,7 @@ export class ClassView extends PositionedRectangle implements Hashable {
_class: PackageableElementReference<Class>,
) {
super(new Point(0, 0), new Rectangle(0, 0));
this.owner = owner;
this._OWNER = owner;
this.id = id;
this.class = _class;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class ClassViewExplicitReference extends ClassViewReference {

private constructor(value: ClassView) {
const ownerReference = PackageableElementExplicitReference.create(
value.owner,
value._OWNER,
);
super(ownerReference, value);
this.ownerReference = ownerReference;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import { ClassViewExplicitReference } from './DSLDiagram_ClassViewReference';
import { DIAGRAM_HASH_STRUCTURE } from '../../../../DSLDiagram_ModelUtils';

export class RelationshipView implements Hashable {
owner: Diagram;
readonly _OWNER: Diagram;

from: RelationshipEdgeView;
to: RelationshipEdgeView;
/**
Expand All @@ -39,7 +40,7 @@ export class RelationshipView implements Hashable {
path: Point[] = [];

constructor(owner: Diagram, from: ClassView, to: ClassView) {
this.owner = owner;
this._OWNER = owner;
this.from = new RelationshipEdgeView(
ClassViewExplicitReference.create(from),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const DIAGRAM_EDITOR_HOTKEY_MAP = Object.freeze({
});

export abstract class DiagramEditorSidePanelState {
uuid = uuid();
readonly uuid = uuid();
editorStore: EditorStore;
diagramEditorState: DiagramEditorState;

Expand Down Expand Up @@ -277,15 +277,15 @@ export class DiagramEditorState extends ElementEditorState {
} else if (this.renderer.mouseOverClassProperty) {
return this.isReadOnly ||
this.editorStore.graphManagerState.isElementReadOnly(
this.renderer.mouseOverClassProperty.owner,
this.renderer.mouseOverClassProperty._OWNER,
)
? 'diagram-editor__cursor--not-allowed'
: 'diagram-editor__cursor--text';
} else if (this.renderer.mouseOverPropertyHolderViewLabel) {
return this.isReadOnly ||
this.editorStore.graphManagerState.isElementReadOnly(
this.renderer.mouseOverPropertyHolderViewLabel.property.value
.owner,
._OWNER,
)
? 'diagram-editor__cursor--not-allowed'
: 'diagram-editor__cursor--text';
Expand Down Expand Up @@ -400,7 +400,7 @@ export class DiagramEditorState extends ElementEditorState {
): void => {
if (
!this.isReadOnly &&
!this.editorStore.graphManagerState.isElementReadOnly(property.owner)
!this.editorStore.graphManagerState.isElementReadOnly(property._OWNER)
) {
this.setInlinePropertyEditorState(
new DiagramEditorInlinePropertyEditorState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ const ArrayEditor = observer(
{arrayValues.map((value, idx) => (
// NOTE: since the value must be unique, we will use it as the key
<div
key={value.value.uuid}
key={value.value._UUID}
className={
showEditInput === idx
? 'mapping-generation-editor__configuration__item'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ test(unitTest('Enumeration is loaded properly'), () => {
const profile = graph.getProfile('ui::test1::ProfileTest');
const taggedValue = guaranteeNonNullable(pureEnum.taggedValues[0]);
expect(taggedValue.value).toEqual('Enumeration Tag');
expect(profile).toEqual(taggedValue.tag.value.owner);
expect(profile).toEqual(pureEnum.stereotypes[0]?.value.owner);
expect(profile).toEqual(taggedValue.tag.value._OWNER);
expect(profile).toEqual(pureEnum.stereotypes[0]?.value._OWNER);
});

test(unitTest('Class is loaded properly'), () => {
Expand All @@ -65,7 +65,7 @@ test(unitTest('Class is loaded properly'), () => {
const stereotype = guaranteeNonNullable(testClass.stereotypes[0]).value;
expect(
graph
.getProfile(stereotype.owner.path)
.getProfile(stereotype._OWNER.path)
.stereotypes.find((s) => s.value === stereotype.value),
).toBeDefined();
const personClass = graph.getClass('ui::test2::Person');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class TabularDataSet {
}

export class TdsExecutionResult extends ExecutionResult {
uuid = uuid();
readonly _UUID = uuid();
override builder = new TdsBuilder();
result = new TabularDataSet();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
* limitations under the License.
*/

import { uuid } from '@finos/legend-shared';
import type { RelationalDatabaseConnection } from '../../../models/metamodels/pure/packageableElements/store/relational/connection/RelationalDatabaseConnection';

export class DatabasePattern {
readonly uuid = uuid();
schemaPattern = '';
tablePattern = '';
escapeSchemaPattern?: boolean | undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/legend-graph/src/helpers/MappingHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const getAllSuperSetImplementations = (
) {
const superSetImpl = [
getClassMappingById(
currentSetImpl.parent,
currentSetImpl._PARENT,
currentSetImpl.superSetImplementationId,
),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ export interface PackageableElementVisitor<T> {
}

export abstract class PackageableElement implements Hashable, Stubable {
readonly uuid = uuid();

readonly _UUID = uuid();
protected _isDeleted = false;
protected _isDisposed = false;

name: string;
package?: Package | undefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class PackageableElementImplicitReference<
// when the parent section does not exist or has been deleted
if (
this.parentSection === undefined ||
this.parentSection.parent.isDeleted
this.parentSection._OWNER.isDeleted
) {
return currentElementPath;
}
Expand Down Expand Up @@ -240,7 +240,7 @@ export class OptionalPackageableElementImplicitReference<
// when the parent section does not exist or has been deleted
if (
this.parentSection === undefined ||
this.parentSection.parent.isDeleted
this.parentSection._OWNER.isDeleted
) {
return currentElementPath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ export interface ConnectionVisitor<T> {
}

export abstract class Connection implements Hashable {
readonly uuid = uuid();
readonly _UUID = uuid();

// in Pure right now, this is of type Any[1], but technically it should be a store
/**
* NOTE: in Pure right now, this is of type Any[1], but technically it should be a store
*/
store: PackageableElementReference<Store>;

constructor(store: PackageableElementReference<Store>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type PropertyOwner = Class | Association;

export interface AbstractProperty extends Hashable, Stubable {
name: string;
owner: PropertyOwner;
_OWNER: PropertyOwner;
genericType: GenericTypeReference;
multiplicity: Multiplicity;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import {
type Hashable,
type Writable,
guaranteeNonNullable,
guaranteeType,
assertTrue,
Expand All @@ -36,19 +37,6 @@ import type { StereotypeReference } from './StereotypeReference';
import { DerivedProperty } from './DerivedProperty';
import type { AbstractProperty } from './AbstractProperty';

// NOTE: we might want to revisit this decision to initialize to association properties to stubs
const initAssociationProperties = (
association: Association,
): [Property, Property] => {
const properties: [Property, Property] = [
Property.createStub(Class.createStub(), Class.createStub()),
Property.createStub(Class.createStub(), Class.createStub()),
];
properties[0].owner = association;
properties[1].owner = association;
return properties;
};

/**
* Assocation needs exactly 2 properties (for 2 classes, not enumeration, not primitive), e.g.
* employees: Person[*]
Expand All @@ -69,17 +57,30 @@ export class Association
extends PackageableElement
implements AnnotatedElement, Hashable, Stubable
{
properties: [Property, Property] = initAssociationProperties(this);
stereotypes: StereotypeReference[] = [];
taggedValues: TaggedValue[] = [];
derivedProperties: DerivedProperty[] = [];

/**
* To store the abstract properties generated while processing the milestoning properties. The properties
* generated are `allVersions`, `allVersionsInRange` and derived property with date parameter.
*/
_generatedMilestonedProperties: AbstractProperty[] = [];

properties!: [Property, Property];
stereotypes: StereotypeReference[] = [];
taggedValues: TaggedValue[] = [];
derivedProperties: DerivedProperty[] = [];

constructor(name: string) {
super(name);

// NOTE: we might want to revisit this decision to initialize to association properties to stubs
const properties: [Property, Property] = [
Property.createStub(Class.createStub(), Class.createStub()),
Property.createStub(Class.createStub(), Class.createStub()),
];
(properties[0] as Writable<Property>)._OWNER = this;
(properties[1] as Writable<Property>)._OWNER = this;
this.properties = properties;
}

getFirstProperty = (): Property => guaranteeNonNullable(this.properties[0]);
getSecondProperty = (): Property => guaranteeNonNullable(this.properties[1]);
getOtherProperty = (property: Property): Property => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import type { Class } from './Class';
import type { Stubable } from '../../../../../helpers/Stubable';

export class Constraint implements Hashable, Stubable {
readonly uuid = uuid();
owner: Class;
readonly _UUID = uuid();
readonly _OWNER: Class;

name: string;
/**
Expand All @@ -42,7 +42,7 @@ export class Constraint implements Hashable, Stubable {

constructor(name: string, owner: Class, functionDefinition: RawLambda) {
this.name = name;
this.owner = owner;
this._OWNER = owner;
this.functionDefinition = functionDefinition;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import {
export class DerivedProperty
implements AbstractProperty, AnnotatedElement, Hashable, Stubable
{
readonly uuid = uuid();
owner: PropertyOwner; // readonly
readonly _UUID = uuid();
readonly _OWNER: PropertyOwner;

name: string;
genericType: GenericTypeReference;
Expand Down Expand Up @@ -64,7 +64,7 @@ export class DerivedProperty
this.name = name;
this.multiplicity = multiplicity;
this.genericType = genericType;
this.owner = owner;
this._OWNER = owner;
}
static createStub = (type: Type, _class: Class): DerivedProperty =>
new DerivedProperty(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ import type { Stubable } from '../../../../../helpers/Stubable';
import type { StereotypeReference } from './StereotypeReference';

export class Enum implements AnnotatedElement, Hashable, Stubable {
readonly uuid = uuid();
owner: Enumeration;
readonly _UUID = uuid();
readonly _OWNER: Enumeration;

name: string;
stereotypes: StereotypeReference[] = [];
taggedValues: TaggedValue[] = [];

constructor(name: string, owner: Enumeration) {
this.name = name;
this.owner = owner;
this._OWNER = owner;
}

static createStub = (parentEnumeration: Enumeration): Enum =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class EnumValueExplicitReference extends EnumValueReference {

private constructor(value: Enum) {
const ownerReference = PackageableElementExplicitReference.create(
value.owner,
value._OWNER,
);
super(ownerReference, value);
this.ownerReference = ownerReference;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ import type { Type } from './Type';
import type { Stubable } from '../../../../../helpers/Stubable';

export class GenericType implements Stubable {
readonly uuid = uuid();
readonly _UUID = uuid();

rawType: Type;

constructor(rawType: Type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import type { StereotypeReference } from './StereotypeReference';
export class Property
implements AbstractProperty, AnnotatedElement, Hashable, Stubable
{
readonly uuid = uuid();
owner: PropertyOwner; // readonly
readonly _UUID = uuid();
readonly _OWNER: PropertyOwner;

name: string;
multiplicity: Multiplicity;
Expand All @@ -51,7 +51,7 @@ export class Property
this.name = name;
this.multiplicity = multiplicity;
this.genericType = genericType;
this.owner = owner;
this._OWNER = owner;
}

static createStub = (type: Type, _class: Class): Property =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ export class PropertyExplicitReference extends PropertyReference {

private constructor(value: AbstractProperty) {
const ownerReference = PackageableElementExplicitReference.create(
value.owner instanceof Association
? value.owner.getPropertyAssociatedClass(value)
: value.owner,
value._OWNER instanceof Association
? value._OWNER.getPropertyAssociatedClass(value)
: value._OWNER,
);
super(ownerReference, value);
this.ownerReference = ownerReference;
Expand Down
Loading

0 comments on commit c5677f7

Please sign in to comment.