-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12c5ab5
commit 2b1a3c8
Showing
7 changed files
with
194 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
packages/core-v2/src/project/data-specification/data-specification.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export {BackendPackageService} from "./package/implementation"; | ||
export {Package, PackageEditable} from "./package/package"; | ||
export {PackageService, SemanticModelPackageService} from "./package/package-service"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import {PackageService, SemanticModelPackageService} from "./package-service"; | ||
import {EntityModel} from "../../entity-model"; | ||
import {Package, PackageEditable} from "./package"; | ||
import {HttpFetch} from "@dataspecer/core/io/fetch/fetch-api"; | ||
|
||
/** | ||
* Implementation of PackageService that communicates with backend and provides semantic models. | ||
*/ | ||
export class BackendPackageService implements PackageService, SemanticModelPackageService { | ||
private readonly backendUrl: string; | ||
protected readonly httpFetch: HttpFetch; | ||
|
||
constructor(backendUrl: string, httpFetch: HttpFetch) { | ||
this.backendUrl = backendUrl; | ||
this.httpFetch = httpFetch; | ||
} | ||
|
||
async getPackage(packageId: string): Promise<Package> { | ||
const result = await this.httpFetch(this.getPackageUrl(packageId).toString()); | ||
return await result.json() as Package; | ||
} | ||
|
||
|
||
async createPackage(parentPackageId: string, data: PackageEditable): Promise<Package> { | ||
const result = await this.httpFetch(this.getPackageUrl(parentPackageId).toString(), { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify(data), | ||
}); | ||
return await result.json() as Package; | ||
} | ||
|
||
async updatePackage(packageId: string, data: Partial<PackageEditable>): Promise<Package> { | ||
const result = await this.httpFetch(this.getPackageUrl(packageId).toString(), { | ||
method: "PATCH", | ||
headers: { | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify(data), | ||
}); | ||
return await result.json() as Package; | ||
} | ||
|
||
async deletePackage(packageId: string): Promise<void> { | ||
await this.httpFetch(this.getPackageUrl(packageId).toString(), { | ||
method: "DELETE", | ||
}); | ||
} | ||
|
||
async constructSemanticModelPackageModels(packageId: string): Promise<EntityModel[]> { | ||
return []; | ||
} | ||
|
||
async updateSemanticModelPackageModels(packageId: string, models: EntityModel[]): Promise<Package> { | ||
const url = this.getPackageUrl(packageId); | ||
url.pathname += "/set-semantic-models"; | ||
const result = await this.httpFetch(this.getPackageUrl(packageId).toString(), { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json" | ||
}, | ||
body: JSON.stringify(models), | ||
}); | ||
return await result.json() as Package; | ||
} | ||
|
||
private getPackageUrl(packageId: string): URL { | ||
const url = new URL(this.backendUrl + "/packages"); | ||
url.searchParams.append("packageId", packageId); | ||
return url; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import {EntityModel} from "../../entity-model"; | ||
import {Package, PackageEditable} from "./package"; | ||
|
||
/** | ||
* Provides basic operations with packages. | ||
*/ | ||
export interface PackageService { | ||
/** | ||
* Returns package with all sub-packages. | ||
*/ | ||
getPackage(packageId: string): Promise<Package>; | ||
|
||
/** | ||
* Create a new empty package that can be used to store other packages or models. | ||
*/ | ||
createPackage(parentPackageId: string, data: PackageEditable): Promise<Package>; | ||
|
||
/** | ||
* Updates editable package metadata. | ||
*/ | ||
updatePackage(packageId: string, data: Partial<PackageEditable>): Promise<Package>; | ||
|
||
/** | ||
* Removes the package with all models and sub-packages. | ||
*/ | ||
deletePackage(packageId: string): Promise<void>; | ||
} | ||
|
||
export interface SemanticModelPackageService extends PackageService { | ||
/** | ||
* Constructs all models from a package with semantic model. | ||
*/ | ||
constructSemanticModelPackageModels(packageId: string): Promise<EntityModel[]>; | ||
|
||
/** | ||
* Sets semantic models that should be stored in the given package. | ||
* If the set of models is changed (new model is added or existing is removed), this method should be called. | ||
* It will update the models that are stored in the package. | ||
*/ | ||
updateSemanticModelPackageModels(packageId: string, models: EntityModel[]): Promise<Package>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import {LanguageString} from "../../semantic-model/concepts"; | ||
|
||
/** | ||
* Package is de-facto a directory in the file system that contains other packages or models. | ||
* | ||
* Each package can have metadata (name, tags, authors), which are stored as a package metadata model, but are | ||
* interpreted as a part of the package interface. | ||
*/ | ||
export interface Package { | ||
/** | ||
* Path-like identifier of the package | ||
*/ | ||
id: string; | ||
|
||
/** | ||
* Name of the package which can be extracted either from the package-metadata or from the | ||
* package identifier. | ||
*/ | ||
name: LanguageString; | ||
|
||
/** | ||
* Package tags that can be used for filtering, searching or organizing packages. | ||
* Each tag is a case-insensitive string, that does not need to be registered in advance. | ||
*/ | ||
tags: string[]; | ||
|
||
/** | ||
* Packages that are contained in this package | ||
*/ | ||
subPackages: Package[]; | ||
|
||
/** | ||
* Whether this package can be interpreted as "data specification"-specification providing semantic model. | ||
*/ | ||
providesSemanticModel: boolean; | ||
} | ||
|
||
/** | ||
* Package field that can be edited. | ||
*/ | ||
export type PackageEditable = Omit<Package, "subPackages" | "providesSemanticModel">; | ||
|
||
/** | ||
* Package that provides semantic model. | ||
*/ | ||
interface SemanticModelPackage extends Package { | ||
|
||
} |