Skip to content

Commit

Permalink
M1 endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
GiordanoT committed Nov 9, 2023
1 parent cd30c77 commit 6947b5e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
20 changes: 12 additions & 8 deletions src/api/persistance/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ export class Load {

static async project(project: DProject) {
const projectUrl = this.url + `projects/${project.id}`;
await Load.element(`${projectUrl}/metamodels`);
await Load.element(`${projectUrl}/models`);
await Load.element(`${projectUrl}/packages`);
await Load.element(`${projectUrl}/classes`);
await Load.element(`${projectUrl}/enumerators`);
await Load.element(`${projectUrl}/attributes`);
await Load.element(`${projectUrl}/references`);
await Load.element(`${projectUrl}/literals`);
await Promise.all([
Load.element(`${projectUrl}/metamodels`),
Load.element(`${projectUrl}/models`),
Load.element(`${projectUrl}/packages`),
Load.element(`${projectUrl}/classes`),
Load.element(`${projectUrl}/enumerators`),
Load.element(`${projectUrl}/attributes`),
Load.element(`${projectUrl}/references`),
Load.element(`${projectUrl}/literals`),
Load.element(`${projectUrl}/objects`),
Load.element(`${projectUrl}/values`)
]);
CreateElementAction.new(project);
}

Expand Down
27 changes: 16 additions & 11 deletions src/api/persistance/save.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {LProject, LModel, LPackage, LClass, LEnumerator, LAttribute, LReference, LEnumLiteral} from '../../joiner';
import type {LProject, LModel, LPackage, LClass, LEnumerator, LAttribute, LReference, LEnumLiteral, LObject, LValue} from '../../joiner';
import {U} from '../../joiner';
import Fetch from '../fetch';

Expand All @@ -9,19 +9,24 @@ export class Save {
await Fetch.post(this.url + 'projects', U.json(project));

const projectUrl = this.url + `projects/${project.id}`;
await Save.elements(`${projectUrl}/metamodels`, project.metamodels);
await Save.elements(`${projectUrl}/models`, project.models);
await Save.elements(`${projectUrl}/packages`, project.metamodels.flatMap(m => m.packages));
await Save.elements(`${projectUrl}/classes`, project.metamodels.flatMap(m => m.classes));
await Save.elements(`${projectUrl}/enumerators`, project.metamodels.flatMap(m => m.enumerators));
// await Save.elements(`${projectUrl}/attributes`, project.metamodels.flatMap(m => m.attributes));
await Save.elements(`${projectUrl}/references`, project.metamodels.flatMap(m => m.references));
// await Save.elements(`${projectUrl}/literals`, project.metamodels.flatMap(m => m.literals));
await Promise.all([
Save.elements(`${projectUrl}/metamodels`, project.metamodels),
Save.elements(`${projectUrl}/models`, project.models),
Save.elements(`${projectUrl}/packages`, project.metamodels.flatMap(m => m.packages)),
Save.elements(`${projectUrl}/classes`, project.metamodels.flatMap(m => m.classes)),
Save.elements(`${projectUrl}/enumerators`, project.metamodels.flatMap(m => m.enumerators)),
Save.elements(`${projectUrl}/attributes`, project.metamodels.flatMap(m => m.attributes)),
Save.elements(`${projectUrl}/references`, project.metamodels.flatMap(m => m.references)),
Save.elements(`${projectUrl}/literals`, project.metamodels.flatMap(m => m.literals)),
Save.elements(`${projectUrl}/objects`, project.models.flatMap(m => m.objects)),
Save.elements(`${projectUrl}/values`, project.models.flatMap(m => m.values))
]);
// todo: fix metamodels.attributes, metamodels.literals and models.values (done without sub-checking)
}

private static async elements(url: string, elements: (LModel|LPackage|LClass|LEnumerator|LAttribute|LReference|LEnumLiteral)[]): Promise<void> {
private static async elements(url: string, elements: (LModel|LPackage|LClass|LEnumerator|LAttribute|LReference|LEnumLiteral|LObject|LValue)[]): Promise<void> {
/* Override */
await Fetch.delete(url);
console.log('DEBUGGING', elements);
for(let element of elements) await Fetch.post(url, U.json(element));
}

Expand Down
15 changes: 15 additions & 0 deletions src/model/logicWrapper/LModelElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3270,6 +3270,7 @@ export class LModel<Context extends LogicContext<DModel> = any, C extends Contex
attributes!: LAttribute[];
references!: LReference[];
literals!: LEnumLiteral[];
values!: LValue[];
allSubAnnotations!: LAnnotation[];
allSubPackages!: LPackage[];
allSubObjects!: LObject[];
Expand Down Expand Up @@ -3596,6 +3597,20 @@ export class LModel<Context extends LogicContext<DModel> = any, C extends Contex
protected get_getPackageByUri(context: Context): this["getPackageByUri"] {
return (uri: string)=>context.proxyObject.allSubPackages.filter((p)=>p.uri === uri)[0]; }


/* See src/api/persistance/save.ts */

protected get_attributes(context: Context): this['attributes'] {
return context.proxyObject.classes.flatMap(c => c.attributes);
}

protected get_literals(context: Context): this['literals'] {
return context.proxyObject.enumerators.flatMap(e => e.literals);
}

protected get_values(context: Context): this['values'] {
return context.proxyObject.objects.flatMap(o => o.features);
}
}
RuntimeAccessibleClass.set_extend(DNamedElement, DModel);
RuntimeAccessibleClass.set_extend(LNamedElement, LModel);
Expand Down

0 comments on commit 6947b5e

Please sign in to comment.