From 8874f8d4e3cc67b08704b55ff5b59c2026fcf2e7 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Sat, 24 Aug 2024 04:13:10 +0300 Subject: [PATCH] [refactor] MST Instance and Snapshot Types --- .vscode/settings.json | 1 + package.json | 2 +- src/ObjectProvider.ts | 14 +-- src/ObjectProviderImpl.ts | 14 +-- src/SparqlGen.ts | 23 +++-- src/SparqlGenSelect.ts | 6 +- src/models/MstColl.ts | 16 ++-- src/models/MstCollConstr.ts | 90 ++++++++++++------- src/models/MstRepository.ts | 4 +- src/models/MstSchemas.ts | 52 +++++++---- src/schema/ArtifactShapeSchema.ts | 6 +- src/schema/Formatters.ts | 4 +- src/schema/RdfsSchema.ts | 10 +-- test/Artifact.spec.ts | 10 +-- test/MstModel.spec.ts | 138 +++++++++++++++++------------- test/SparqlClient.spec.ts | 16 ++-- test/SparqlClientUpload.spec.ts | 16 ++-- test/SparqlGen.spec.ts | 6 +- test/schema/TestSchemas.ts | 24 +++--- 19 files changed, 259 insertions(+), 193 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index e109493..c96c116 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -72,6 +72,7 @@ "strends", "strstarts", "Subcat", + "timeseries", "triplestore", "typeahead", "undelegate", diff --git a/package.json b/package.json index 03112a3..4c02526 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@agentlab/sparql-jsld-client", - "version": "5.1.0", + "version": "5.2.0", "description": "SPARQL JSON Schema Linked Data Client", "license": "GPL-3.0", "author": "Aleksei Ivanov ", diff --git a/src/ObjectProvider.ts b/src/ObjectProvider.ts index 950ad23..e190005 100644 --- a/src/ObjectProvider.ts +++ b/src/ObjectProvider.ts @@ -35,8 +35,8 @@ export function idComparator(a: JsObject, b: JsObject): number { return 0; } -export type JSONSchema7PropertyDefinition_LD = JSONSchema7Property_LD; -export interface JSONSchema7Property_LD extends JSONSchema7 { +export type JSONSchema7LDPropertyDefinition = JSONSchema7LDProperty; +export interface JSONSchema7LDProperty extends JSONSchema7 { /** * json-ld Property * https://github.com/json-ld/json-ld.org/blob/master/schemas/jsonld-schema.json @@ -49,12 +49,12 @@ export interface JSONSchema7Property_LD extends JSONSchema7 { shapeModifiability?: string; // user or non -- system properties?: { - [key: string]: JSONSchema7PropertyDefinition_LD; + [key: string]: JSONSchema7LDPropertyDefinition; }; } -export type JSONSchema7Definition_LD = JSONSchema7_LD; -export interface JSONSchema7_LD extends Omit, JsObject { +export type JSONSchema7LDDefinition = JSONSchema7LD; +export interface JSONSchema7LD extends Omit, JsObject { allOf?: { $ref: string }[] | undefined; // override from this: "allOf?: JSONSchema6Definition[] | undefined;" type: JSONSchema7TypeName; // restrict from this: "type?: JSONSchema6TypeName | JSONSchema6TypeName[] | undefined;" @@ -79,7 +79,7 @@ export interface JSONSchema7_LD extends Omit, JsObject { //iconReference?: string; properties: { - [key: string]: JSONSchema7PropertyDefinition_LD; + [key: string]: JSONSchema7LDPropertyDefinition; }; } @@ -140,7 +140,7 @@ export function copyUniqueArrayElements(arrTo: any[], arrFrom: any[]): void { }); } -export function getPropKeysByFormat(schema: JSONSchema7_LD, format: string): string[] { +export function getPropKeysByFormat(schema: JSONSchema7LD, format: string): string[] { const props: string[] = []; for (const key in schema.properties) { if (schema.properties[key].format === format) { diff --git a/src/ObjectProviderImpl.ts b/src/ObjectProviderImpl.ts index 20b1877..77fe796 100644 --- a/src/ObjectProviderImpl.ts +++ b/src/ObjectProviderImpl.ts @@ -8,16 +8,16 @@ * SPDX-License-Identifier: GPL-3.0-only ********************************************************************************/ import { - JSONSchema7_LD, + JSONSchema7LD, JsObject, - JSONSchema7PropertyDefinition_LD, + JSONSchema7LDPropertyDefinition, copyObjectProps, copyUniqueArrayElements, } from './ObjectProvider'; export const schemaNonPrimitivePropsKeys = ['@context', 'properties', 'required']; -function combineProperties(oldObj: any, newObj: any, schema: JSONSchema7_LD): any { +function combineProperties(oldObj: any, newObj: any, schema: JSONSchema7LD): any { const newData: any = {}; Object.keys(oldObj).forEach((key) => { if (schema.properties && oldObj[key] !== newObj[key]) { @@ -31,7 +31,7 @@ function combineProperties(oldObj: any, newObj: any, schema: JSONSchema7_LD): an return newData; } -export function createObjectWithoutRepetitions(objects: any[], schema: JSONSchema7_LD): any[] { +export function createObjectWithoutRepetitions(objects: any[], schema: JSONSchema7LD): any[] { const newData = new Map(); const usedUri: any[] = []; objects.forEach((object) => { @@ -231,8 +231,8 @@ function propertyShapeToUiSchema( export function propertyShapesToSchemaProperties( shapeProps: any[] | undefined, -): [{ [key: string]: JSONSchema7PropertyDefinition_LD }, JsObject, string[], JsObject] { - const schemaProps: { [key: string]: JSONSchema7PropertyDefinition_LD } = {}; +): [{ [key: string]: JSONSchema7LDPropertyDefinition }, JsObject, string[], JsObject] { + const schemaProps: { [key: string]: JSONSchema7LDPropertyDefinition } = {}; const schemaContexts: JsObject = {}; const schemaReqs: string[] = []; const uiSchema: JsObject = {}; @@ -261,7 +261,7 @@ export function propertyShapesToSchemaProperties( * @param schema * @param parentSchema */ -export function addToSchemaParentSchema(schema: JSONSchema7_LD, parentSchema: JSONSchema7_LD): JSONSchema7_LD { +export function addToSchemaParentSchema(schema: JSONSchema7LD, parentSchema: JSONSchema7LD): JSONSchema7LD { const parentCtx = parentSchema['@context']; if (parentCtx && typeof parentCtx !== 'string' && !Array.isArray(parentCtx)) { if (!schema['@context']) schema['@context'] = {}; diff --git a/src/SparqlGen.ts b/src/SparqlGen.ts index d8d3e24..1954cdb 100644 --- a/src/SparqlGen.ts +++ b/src/SparqlGen.ts @@ -15,8 +15,8 @@ import { BgpPattern, Generator, OptionalPattern } from 'sparqljs'; import { Bindings } from './SparqlClient'; import { - JSONSchema7_LD, - JSONSchema7Property_LD, + JSONSchema7LD, + JSONSchema7LDProperty, JsObject, copyObjectPropsWithRenameOrFilter, JsStrObj, @@ -69,11 +69,11 @@ export function propsToSparqlVars(entConstr: Pick { - while (constr.schema.properties && constr.schema.properties[varName]) { + while ( + constr?.schema && + typeof constr.schema === 'object' && + constr.schema.properties && + constr.schema.properties[varName] + ) { varName += entConstrs.length; } }); diff --git a/src/SparqlGenSelect.ts b/src/SparqlGenSelect.ts index 4fb2dbf..ad3fa96 100644 --- a/src/SparqlGenSelect.ts +++ b/src/SparqlGenSelect.ts @@ -19,7 +19,7 @@ import { copyObjectPropsWithRenameOrFilter, copyUniqueObjectProps, JsStrObjObj, - JSONSchema7_LD, + JSONSchema7LD, JsStrObj, } from './ObjectProvider'; import { @@ -79,7 +79,7 @@ export async function selectObjectsArrayProperties( for (const key of Object.keys(entConstr.schemaPropsWithArrays)) { for (const object of objects) { const prop = entConstr.schemaPropsWithArrays[key]; - const schemaWithArrayProperty: JSONSchema7_LD = { + const schemaWithArrayProperty: JSONSchema7LD = { ...schema, '@id': '_' + uuid62.v4(), '@context': { @@ -95,7 +95,7 @@ export async function selectObjectsArrayProperties( if (prop && prop.type && propType) { //let schemaUri: string | undefined; let constrWithSchema2: EntConstrInternal | undefined; - let schema2: JSONSchema7_LD; + let schema2: JSONSchema7LD; if ((prop.type === 'array' && prop.items) || prop.type === 'object') { //schemaUri = repository.schemas.getByClassId(propType); constrWithSchema2 = entConstrs.find((c) => c.schema.targetClass === propType); diff --git a/src/models/MstColl.ts b/src/models/MstColl.ts index 915647c..7b19c9f 100644 --- a/src/models/MstColl.ts +++ b/src/models/MstColl.ts @@ -28,10 +28,10 @@ import { import { JsObject } from '../ObjectProvider'; import { - MstCollConstr as MstCollConstr, + MstCollConstr, constructObjectsSnapshot, deleteObjectSnapshot, - ICollConstrSnapshotOut, + TMstCollConstrSnapshotOut, MstMapOfJsObject, } from './MstCollConstr'; @@ -245,9 +245,9 @@ export const MstColl = types //console.log('loadColl START'); self.isLoading = true; if (self.collConstr) { - const collConstr = getSnapshot(self.collConstr); + const collConstr = getSnapshot(self.collConstr); let parent: any | undefined = self.collConstr['@parent']; - if (parent) parent = getSnapshot(parent); + if (parent) parent = getSnapshot(parent); //console.log('loadColl query', { collConstr, parent }); try { const objects: JsObject[] | null = yield constructObjectsSnapshot( @@ -283,12 +283,12 @@ export const MstColl = types self.isLoading = true; if (self.collConstr) { const collConstr = { - ...getSnapshot(self.collConstr), + ...getSnapshot(self.collConstr), limit: self.pageSize, offset: self.dataIntrnl.length, }; let parent: any = self.collConstr['@parent']; - if (parent) parent = getSnapshot(parent); + if (parent) parent = getSnapshot(parent); //console.log('loadMore query', { collConstr, parent }); try { const objects: JsObject[] | null = yield constructObjectsSnapshot( @@ -355,7 +355,7 @@ export const MstColl = types elem = elem['@id']; if (!elem) return null; } - let collConstr: any = getSnapshot(self.collConstr); + let collConstr: any = getSnapshot(self.collConstr); // filter-out query modifiers like orderBy, limit... collConstr = { '@id': collConstr['@id'], @@ -363,7 +363,7 @@ export const MstColl = types entConstrs: collConstr.entConstrs, }; let parent: any = self.collConstr['@parent']; - if (parent) parent = getSnapshot(parent); + if (parent) parent = getSnapshot(parent); yield deleteObjectSnapshot(rep.schemas, rep.ns.currentJs, client, collConstr, parent, { '@_id': elem }); //@ts-ignore return self.delElemInternal(elem); diff --git a/src/models/MstCollConstr.ts b/src/models/MstCollConstr.ts index fda27b3..304d77d 100644 --- a/src/models/MstCollConstr.ts +++ b/src/models/MstCollConstr.ts @@ -14,13 +14,20 @@ import { getEnv, getRoot, Instance, - SnapshotOut, IAnyStateTreeNode, IAnyModelType, + SnapshotIn, + SnapshotOut, } from 'mobx-state-tree'; import { addMissingId, JsObject } from '../ObjectProvider'; -import { ISchemas, MstJSONSchema7forRdf, MstJSONSchema7forRdfReference } from './MstSchemas'; +import { + TMstSchemas, + MstJSONSchema7LD, + MstJSONSchema7LDReference, + TMstJSONSchema7LDSnapshotIn, + TMstJSONSchema7LDSnapshotOut, +} from './MstSchemas'; import { ICollConstrJs } from '../SparqlGen'; import { constructObjectsQuery, selectObjectsQuery } from '../SparqlGenSelect'; import { insertObjectQuery, deleteObjectQuery, updateObjectQuery } from '../SparqlGenUpdate'; @@ -50,7 +57,7 @@ export const MstEntConstr = types * could be class IRI, resolved from local schema repository (local cache) or from server * or could be 'private' schema (full qualified JS object) */ - schema: types.union(MstJSONSchema7forRdfReference, MstJSONSchema7forRdf), + schema: types.union(MstJSONSchema7LDReference, MstJSONSchema7LD), /** * Obj property corresponds schema property * Obj value -- constrain value: @@ -126,7 +133,15 @@ export const MstEntConstr = types }; }); -export type IEntConstr = Instance; +export type TMstEntConstr = Instance; +export type TMstEntConstrSnapshotIn = Omit, '@parent' | 'schema'> & { + '@parent': string | undefined; + schema: string | undefined | TMstJSONSchema7LDSnapshotIn; +}; +export type TMstEntConstrSnapshotOut = Omit, '@parent' | 'schema'> & { + '@parent': string | undefined; + schema: string | undefined | TMstJSONSchema7LDSnapshotOut; +}; /** * Collection Constraint @@ -230,7 +245,7 @@ export const MstCollConstr = types for (const key of Object.keys(entConstr.schemaPropsWithArrays)) { for (const object of objects) { const prop = entConstr.schemaPropsWithArrays[key]; - const schemaWithArrayProperty: JSONSchema7_LD = { + const schemaWithArrayProperty: JSONSchema7LD = { ...schema, '@id': '_' + uuid62.v4(), '@context': { @@ -284,7 +299,7 @@ export const MstCollConstr = types return objects; }),*/ /*selectObjects: flow(function* selectObjects() { - const collConstrJs = resolveAndClone(self as ICollConstr); + const collConstrJs = resolveAndClone(self as TMstCollConstr); const entConstrs: EntConstrInternal[] = getInternalCollConstrs(collConstrJs, self.nsJs); selectInternalEntConstrs(entConstrs); const query = selectQueryFromEntConstrs(entConstrs, collConstrJs); @@ -312,7 +327,7 @@ export const MstCollConstr = types * DELETE */ /*deleteObject: flow(function* deleteObject(conditions?: JsObject | JsObject[], loadIfNeeded = true) { - const collConstrJs = resolveAndClone(self as ICollConstr); + const collConstrJs = resolveAndClone(self as TMstCollConstr); const entConstrs: EntConstrInternal[] = getInternalCollConstrs(collConstrJs, self.nsJs, conditions); const query = deleteObjectQuery(entConstrs); const queryStr = gen.stringify(query); @@ -328,7 +343,7 @@ export const MstCollConstr = types * INSERT */ /*createObject: flow(function* createObject(data?: JsObject | JsObject[], loadIfNeeded = true) { - const collConstrJs = resolveAndClone(self as ICollConstr); + const collConstrJs = resolveAndClone(self as TMstCollConstr); const entConstrs: EntConstrInternal[] = getInternalCollConstrs(collConstrJs, self.nsJs, undefined, data); const query = insertObjectQuery(entConstrs); const queryStr = gen.stringify(query); @@ -344,7 +359,7 @@ export const MstCollConstr = types * UPDATE */ /*updateObject: flow(function* updateObject(conditions?: JsObject | JsObject[], data?: JsObject | JsObject[], loadIfNeeded = true) { - const collConstrJs = resolveAndClone(self as ICollConstr); + const collConstrJs = resolveAndClone(self as TMstCollConstr); const entConstrs: EntConstrInternal[] = getInternalCollConstrs(collConstrJs, self.nsJs, conditions, data); const query = updateObjectQuery(entConstrs); const queryStr = gen.stringify(query); @@ -359,8 +374,15 @@ export const MstCollConstr = types }; }); -export type ICollConstr = Instance; -export type ICollConstrSnapshotOut = SnapshotOut; +export type TMstCollConstr = Instance; +export type TMstCollConstrSnapshotIn = Omit, '@parent' | 'entConstrs'> & { + '@parent': string | undefined; + entConstrs: TMstEntConstrSnapshotOut[]; +}; +export type TMstCollConstrSnapshotOut = Omit, '@parent' | 'entConstrs'> & { + '@parent': string | undefined; + entConstrs: TMstEntConstrSnapshotOut[]; +}; /** * Smart deep-merge parent CollConstr and it's entConstrs into child CollConstr. @@ -370,9 +392,9 @@ export type ICollConstrSnapshotOut = SnapshotOut; * @returns */ function mergeCollConstrs( - collConstrJs: ICollConstrSnapshotOut, - parentCollConstrJs: ICollConstrSnapshotOut, -): ICollConstrSnapshotOut { + collConstrJs: TMstCollConstrSnapshotOut, + parentCollConstrJs: TMstCollConstrSnapshotOut, +): TMstCollConstrSnapshotOut { // deep-merge entConstrs props, based on parent order of EntConstrs (collConstrJs.entConstrs as any) = parentCollConstrJs.entConstrs .map((parentEntConstrJs) => { @@ -413,19 +435,19 @@ function mergeCollConstrs( return collConstrJs; } -async function resolveAndClone(self: ICollConstr) { - const data = getSnapshot(self); +async function resolveAndClone(self: TMstCollConstr) { + const data = getSnapshot(self); let parent: any = self['@parent']; - if (parent) parent = getSnapshot(parent); + if (parent) parent = getSnapshot(parent); return resolveAndCloneSnapshot(data, parent, self.rep.schemas); } async function resolveAndCloneSnapshot( - data: ICollConstrSnapshotOut, - parent: ICollConstrSnapshotOut | undefined, - schemas: ISchemas, + data: TMstCollConstrSnapshotOut, + parent: TMstCollConstrSnapshotOut | undefined, + schemas: TMstSchemas, ) { - let collConstrJs: ICollConstrSnapshotOut = cloneDeep(data); + let collConstrJs: TMstCollConstrSnapshotOut = cloneDeep(data); if (parent) collConstrJs = mergeCollConstrs(collConstrJs, cloneDeep(parent)); // resolve schema by reference. For-loop because of async-await for (let index = 0; index < collConstrJs.entConstrs.length; index++) { @@ -457,13 +479,13 @@ async function resolveAndCloneSnapshot( return collConstrJs as ICollConstrJs; } -export async function selectObjects(collConstr: ICollConstr) { +export async function selectObjects(collConstr: TMstCollConstr) { //TODO: performance const collConstrJs = await resolveAndClone(collConstr); return selectObjectsQuery(collConstrJs, collConstr.nsJs, collConstr.client); } -export async function constructObjects(collConstr: ICollConstr) { +export async function constructObjects(collConstr: TMstCollConstr) { //TODO: performance const collConstrJs = await resolveAndClone(collConstr); if (!collConstr || !collConstr.client) { @@ -482,9 +504,9 @@ export async function constructObjects(collConstr: ICollConstr) { * @returns [] or null -- if incorrect query in validation and no actual request to the server had been made */ export async function constructObjectsSnapshot( - collConstr: ICollConstrSnapshotOut, - parentCollConstr: ICollConstrSnapshotOut | undefined, - schemas: ISchemas, + collConstr: TMstCollConstrSnapshotOut, + parentCollConstr: TMstCollConstrSnapshotOut | undefined, + schemas: TMstSchemas, nsJs: any, client: SparqlClient, ) { @@ -517,7 +539,11 @@ export async function constructObjectsSnapshot( * @param conditions: JS object with properties, which defines search conditions * */ -export async function deleteObject(collConstr: ICollConstr, conditions?: JsObject | JsObject[], loadIfNeeded = true) { +export async function deleteObject( + collConstr: TMstCollConstr, + conditions?: JsObject | JsObject[], + loadIfNeeded = true, +) { //TODO: performance const collConstrJs = await resolveAndClone(collConstr); deleteObjectQuery(collConstrJs, collConstr.nsJs, collConstr.client, conditions); @@ -527,11 +553,11 @@ export async function deleteObject(collConstr: ICollConstr, conditions?: JsObjec } export async function deleteObjectSnapshot( - schemas: ISchemas, + schemas: TMstSchemas, nsJs: any, client: SparqlClient, - data: ICollConstrSnapshotOut, - parent: ICollConstrSnapshotOut | undefined, + data: TMstCollConstrSnapshotOut, + parent: TMstCollConstrSnapshotOut | undefined, conditions?: JsObject | JsObject[], ) { //TODO: performance @@ -539,7 +565,7 @@ export async function deleteObjectSnapshot( deleteObjectQuery(collConstrJs, nsJs, client, conditions); } -export async function insertObject(collConstr: ICollConstr, data?: JsObject | JsObject[], loadIfNeeded = true) { +export async function insertObject(collConstr: TMstCollConstr, data?: JsObject | JsObject[], loadIfNeeded = true) { //TODO: performance const collConstrJs = await resolveAndClone(collConstr); insertObjectQuery(collConstrJs, collConstr.nsJs, collConstr.client, data); @@ -549,7 +575,7 @@ export async function insertObject(collConstr: ICollConstr, data?: JsObject | Js } export async function updateObject( - collConstr: ICollConstr, + collConstr: TMstCollConstr, conditions?: JsObject | JsObject[], data?: JsObject | JsObject[], loadIfNeeded = true, diff --git a/src/models/MstRepository.ts b/src/models/MstRepository.ts index 71b9298..3687d01 100644 --- a/src/models/MstRepository.ts +++ b/src/models/MstRepository.ts @@ -67,7 +67,7 @@ export const MstRepository = types client.setRepositoryId(self.repId); const normalizeCollConstr = (data: any) => { - let collConstr: any; // ICollConstr + let collConstr: any; // TMstCollConstr if (!data.entConstrs) { if (typeof data === 'string') { collConstr = { @@ -93,7 +93,7 @@ export const MstRepository = types } } } else { - collConstr = data as any; // as ICollConstr + collConstr = data as any; // as TMstCollConstr } /*addCollConstr.entConstrs.forEach((s: any) => { if (s.schema && typeof s.schema === 'object') { diff --git a/src/models/MstSchemas.ts b/src/models/MstSchemas.ts index 3d9e68d..c9899d3 100644 --- a/src/models/MstSchemas.ts +++ b/src/models/MstSchemas.ts @@ -19,9 +19,11 @@ import { IAnyStateTreeNode, getEnv, getRoot, + SnapshotIn, + SnapshotOut, } from 'mobx-state-tree'; -import { JSONSchema7_LD, copyUniqueObjectPropsWithRenameOrFilter, JsObject, JsStrObjObj } from '../ObjectProvider'; +import { JSONSchema7LD, copyUniqueObjectPropsWithRenameOrFilter, JsObject, JsStrObjObj } from '../ObjectProvider'; import { propertyShapesToSchemaProperties, uiMapping, @@ -83,12 +85,15 @@ const MstJSONSchema7Array = types.array(types.late(() => MstJSONSchema7Type)); | { [x: string]: JSONValue } | Array;*/ -export const MstSchemaRef = types.model('MstJSONSchema7forRdf', { +export const MstSchemaRef = types.model('MstJSONSchema7LD', { $ref: types.string, }); -export const MstJSONSchema7forRdf = types - .model('MstJSONSchema7forRdf', { +/** + * MST JSON Schema LD + */ +export const MstJSONSchema7LD = types + .model('MstJSONSchema7LD', { /** * ext json-ld Node * https://github.com/json-ld/json-ld.org/blob/master/schemas/jsonld-schema.json @@ -100,7 +105,7 @@ export const MstJSONSchema7forRdf = types /** * Our custom extensions from SHACL */ - targetClass: types.maybe(types.string), // targetClass of a shape + targetClass: types.string, // targetClass of a shape //'path': types.maybe(types.string), // targetClass of a shape /** @@ -116,7 +121,7 @@ export const MstJSONSchema7forRdf = types title: types.maybe(types.string), description: types.maybe(types.string), - properties: types.optional(types.map(types.late((): IAnyModelType => MstJSONSchema7PropertyForRdf)), {}), + properties: types.optional(types.map(types.late((): IAnyModelType => MstJSONSchema7LDProperty)), {}), required: types.optional(types.array(types.string), []), }) @@ -138,16 +143,21 @@ export const MstJSONSchema7forRdf = types }; }); -//export interface IJSONSchema7forRdf extends Instance {} +export type TMstJSONSchema7LD = Instance; +export type TMstJSONSchema7LDSnapshotIn = SnapshotIn; +export type TMstJSONSchema7LDSnapshotOut = SnapshotOut; -export const MstJSONSchema7PropertyForRdf = types.model('MstJSONSchema7PropertyForRdf', { +/** + * MST JSON Schema LD Property + */ +export const MstJSONSchema7LDProperty = types.model('MstJSONSchema7LDProperty', { title: types.maybe(types.string), description: types.maybe(types.string), type: MstJSONSchema7TypeName, enum: types.maybe(MstJSONSchema7Array), default: types.maybe(MstJSONSchema7Type), - items: types.maybe(types.late((): IAnyModelType => MstJSONSchema7PropertyForRdf)), + items: types.maybe(types.late((): IAnyModelType => MstJSONSchema7LDProperty)), format: types.maybe(types.string), contentMediaType: types.maybe(types.string), @@ -161,10 +171,12 @@ export const MstJSONSchema7PropertyForRdf = types.model('MstJSONSchema7PropertyF shapeModifiability: types.maybe(types.string), // user or non -- system }); -//export interface IJSONSchema7PropertyForRdf extends Instance {} +export type TMstJSONSchema7LDProperty = Instance; +export type TMstJSONSchema7LDPropertySnapshotIn = SnapshotIn; +export type TMstJSONSchema7LDPropertySnapshotOut = SnapshotOut; -export const MstJSONSchema7forRdfReference = types.maybe( - types.reference(MstJSONSchema7forRdf, { +export const MstJSONSchema7LDReference = types.maybe( + types.reference(MstJSONSchema7LD, { get(identifier: string, parent): any { if (!parent) return null; const repository: IAnyStateTreeNode = getRoot(parent); @@ -185,7 +197,7 @@ export const MstSchemas = types /** * Schemas by id */ - json: types.map(MstJSONSchema7forRdf), + json: types.map(MstJSONSchema7LD), /** * Default schemas for classes */ @@ -274,7 +286,7 @@ export const MstSchemas = types const uiSchema = r.uiSchema; if (!schema) return Promise.reject('Cannot load schema with conditions' + conditions); // get parent schemas - let schemaQueue: JSONSchema7_LD[] = yield getDirectSuperSchemas(schema); + let schemaQueue: JSONSchema7LD[] = yield getDirectSuperSchemas(schema); schemaQueue = [schema, ...schemaQueue]; // copy loaded schema and parents into new schema let schemaResult: any = { '@id': schema['@id'], '@type': schema['@type'] }; @@ -291,9 +303,9 @@ export const MstSchemas = types return self.json.get(schemaResult['@id']); }); - const getDirectSuperSchemas = flow(function* getDirectSuperSchemas(schema: JSONSchema7_LD) { + const getDirectSuperSchemas = flow(function* getDirectSuperSchemas(schema: JSONSchema7LD) { //console.debug('getDirectSuperSchemas for schema=', schema['@id']); - const schemaOrUndef: JSONSchema7_LD | undefined = schema; + const schemaOrUndef: JSONSchema7LD | undefined = schema; const parentSchemas: any[] = []; if (schemaOrUndef.allOf) { const schemaAllOf: any[] = schemaOrUndef.allOf.filter((s1: any) => s1.$ref !== undefined); @@ -313,7 +325,7 @@ export const MstSchemas = types return parentSchemas; }); - const copyAllSchemasToOne = (schemaQueue: JSONSchema7_LD[], schema: any) => { + const copyAllSchemasToOne = (schemaQueue: JSONSchema7LD[], schema: any) => { let schemaOrUndefined: any | undefined; while (schemaQueue.length > 0) { schemaOrUndefined = schemaQueue.pop(); @@ -338,7 +350,7 @@ export const MstSchemas = types const loadingByIri: any = {}; return { - addSchema(schema: JSONSchema7_LD): void { + addSchema(schema: JSONSchema7LD): void { const iri: string = abbreviateIri(schema['@id'], repository.ns.currentJs); if (!self.json.get(iri)) { self.json.set(iri, schema as any); @@ -412,7 +424,9 @@ export const MstSchemas = types }; }); -export type ISchemas = Instance; +export type TMstSchemas = Instance; +export type TMstSchemasSnapshotIn = SnapshotIn; +export type TMstSchemasSnapshotOut = SnapshotOut; /** * Retrieves element's SHACL Shape from server and converts it to 'JSON Schema + LD' and UI Schema diff --git a/src/schema/ArtifactShapeSchema.ts b/src/schema/ArtifactShapeSchema.ts index f9d3a94..5549ff8 100644 --- a/src/schema/ArtifactShapeSchema.ts +++ b/src/schema/ArtifactShapeSchema.ts @@ -7,9 +7,9 @@ * * SPDX-License-Identifier: GPL-3.0-only ********************************************************************************/ -import { JSONSchema7_LD } from '../ObjectProvider'; +import { JSONSchema7LD } from '../ObjectProvider'; -export const ArtifactShapeSchema: JSONSchema7_LD = { +export const ArtifactShapeSchema: JSONSchema7LD = { $schema: 'http://json-schema.org/draft-07/schema#', '@id': 'sh:NodeShapeShape', '@type': 'sh:NodeShape', @@ -87,7 +87,7 @@ export const ArtifactShapeSchema: JSONSchema7_LD = { required: ['@id', 'targetClass' /*, 'property'*/], // arrays should be required }; -export const PropertyShapeSchema: JSONSchema7_LD = { +export const PropertyShapeSchema: JSONSchema7LD = { $schema: 'http://json-schema.org/draft-07/schema#', //$id: 'http://example.com/product.schema.json', '@id': 'sh:PropertyShapeShape', diff --git a/src/schema/Formatters.ts b/src/schema/Formatters.ts index 498b7da..45ede5e 100644 --- a/src/schema/Formatters.ts +++ b/src/schema/Formatters.ts @@ -8,7 +8,7 @@ * SPDX-License-Identifier: GPL-3.0-only ********************************************************************************/ import dayjs from 'dayjs'; -import { JSONSchema7_LD } from '../ObjectProvider'; +import { JSONSchema7LD } from '../ObjectProvider'; interface FormatterAndDefaultAndTitle { propertyFormatter?: (value: any) => any; @@ -16,7 +16,7 @@ interface FormatterAndDefaultAndTitle { propertyTitle?: string; } -export function getPropertyFormatterAndDefault(schema: JSONSchema7_LD, propKey: string): FormatterAndDefaultAndTitle { +export function getPropertyFormatterAndDefault(schema: JSONSchema7LD, propKey: string): FormatterAndDefaultAndTitle { const properties = schema.properties; const contexts = schema['@context']; const result: FormatterAndDefaultAndTitle = {}; diff --git a/src/schema/RdfsSchema.ts b/src/schema/RdfsSchema.ts index cfd0099..67d834b 100644 --- a/src/schema/RdfsSchema.ts +++ b/src/schema/RdfsSchema.ts @@ -8,9 +8,9 @@ * SPDX-License-Identifier: GPL-3.0-only ********************************************************************************/ -import { JSONSchema7_LD } from '../ObjectProvider'; +import { JSONSchema7LD } from '../ObjectProvider'; -export const NopSchema: any /*JSONSchema7_LD*/ = { +export const NopSchema: any /*JSONSchema7LD*/ = { $schema: 'http://json-schema.org/draft-07/schema#', //$id: 'https://agentlab.eu/ns/rm/rdf#NopSchema', '@id': 'rm:NopSchema', // json-ld @@ -26,7 +26,7 @@ export const NopSchema: any /*JSONSchema7_LD*/ = { required: ['@id'], }; -export const ResourceSchema: JSONSchema7_LD = { +export const ResourceSchema: JSONSchema7LD = { $schema: 'http://json-schema.org/draft-07/schema#', //$id: 'https://agentlab.eu/ns/rm/rdf#ResourceSchema', '@id': 'rm:ResourceSchema', // json-ld @@ -58,7 +58,7 @@ export const ResourceSchema: JSONSchema7_LD = { required: ['@id'], }; -export const ClassSchema: JSONSchema7_LD = { +export const ClassSchema: JSONSchema7LD = { $schema: 'http://json-schema.org/draft-07/schema#', //$id: 'https://agentlab.eu/ns/rm/rdf#Class', '@id': 'rm:Class', // json-ld @@ -99,7 +99,7 @@ export const ClassSchema: JSONSchema7_LD = { required: ['@id'], }; -export const DataTypeSchema: JSONSchema7_LD = { +export const DataTypeSchema: JSONSchema7LD = { $schema: 'http://json-schema.org/draft-07/schema#', '@id': 'rdfs:Datatype', // json-ld '@type': 'rdfs:DatatypeShape', // json-ld diff --git a/test/Artifact.spec.ts b/test/Artifact.spec.ts index f5225bf..5b02474 100644 --- a/test/Artifact.spec.ts +++ b/test/Artifact.spec.ts @@ -76,7 +76,7 @@ afterAll(async () => { }*/ describe('create-artifact-scenario', () => { - it(`should persist artifact in the store`, async () => { + it('should persist artifact in the store', async () => { //await repository.schemas.loadSchemaByClassIri('rm:Artifact'); //const artifactSchema = repository.schemas.getOrLoadSchemaByClassIri('rm:Artifact'); //await repository.schemas.loadSchemaByClassIri('clss:Grouping'); @@ -239,7 +239,7 @@ describe('create-artifact-scenario', () => { }); /*describe('Retrieve artifacts from folder', () => { - it(`select should return artifacts with expected schema`, async () => { + it('select should return artifacts with expected schema', async () => { const listFolders = await fetchProjectFoldersList({ processArea: projectAreaUri }, foldersGraphUri); const artifacts = await selectArtifacts({ assetFolder: listFolders[0]['@id] }, graphUri, apiUrl); expect(artifacts.length).toBe(3); @@ -247,7 +247,7 @@ describe('create-artifact-scenario', () => { }); describe('Modify artifact', () => { - it(`title should be modifiable`, async () => { + it('title should be modifiable', async () => { let artifacts = await selectArtifacts({}, graphUri, apiUrl); const rec = artifacts[0]; const newTitle = 'Req Title Change'; @@ -275,7 +275,7 @@ describe('Modify artifact', () => { } }); }); - it(`new pred should be addable`, async () => { + it('new pred should be addable', async () => { let artifacts = await selectArtifacts({}, graphUri, apiUrl); const rec = artifacts[0]; const newForeignModifiedBy = 'someone'; @@ -303,7 +303,7 @@ describe('Modify artifact', () => { } }); }); - it(`title and description should be modifiable`, async () => { + it('title and description should be modifiable', async () => { let artifacts = await selectArtifacts({}, graphUri, apiUrl); const rec = artifacts[0]; const newTitle = 'Req Title Change2'; diff --git a/test/MstModel.spec.ts b/test/MstModel.spec.ts index d0df296..993ce6e 100644 --- a/test/MstModel.spec.ts +++ b/test/MstModel.spec.ts @@ -9,74 +9,94 @@ ********************************************************************************/ import { afterAll, beforeAll, describe, expect, jest, it } from '@jest/globals'; import { compact, ContextDefinition } from 'jsonld'; +import { getSnapshot, isReferenceType } from 'mobx-state-tree'; + +import { expectToBeDefined, genTimestampedName } from './TestHelpers'; +import { SparqlClientImplMock } from './SparqlClientImplMock'; import { rootModelInitialState } from '../src/models/Model'; -import { MstRepository } from '../src/models/MstRepository'; +import { MstRepository, TMstRepositorySnapshotIn } from '../src/models/MstRepository'; import { SparqlClientImpl } from '../src/SparqlClientImpl'; import { uploadFiles } from '../src/FileUpload'; +import { TMstCollConstrSnapshotOut, JsObject, ICollConstrJsOpt } from '../src'; -import { expectToBeDefined, genTimestampedName } from './TestHelpers'; -import { SparqlClientImplMock } from './SparqlClientImplMock'; -import exp from 'constants'; -import { getSnapshot } from 'mobx-state-tree'; -import { JsObject } from '../src'; +const rootModelInitialStateWithColls: TMstRepositorySnapshotIn = { + ...rootModelInitialState, + colls: { + 'rm:Artifacts_Coll': { + '@id': 'rm:Artifacts_Coll', + collConstr: { + '@id': 'rm:Artifacts_Coll', + '@type': 'aldkg:CollConstr', + entConstrs: [ + { + '@id': 'rm:Artifacts_Coll_Ent', + '@type': 'aldkg:EntConstr', + schema: 'rm:ArtifactShape', + conditions: {}, + data: {}, + }, + ], + }, + updPeriod: 300, + lazy: true, + dataIntrnl: [ + { + '@id': 'file:///myfile.xml', + '@type': 'rm:Artifact', + identifier: 30000, + title: 'Requirement Module 30000 Title', + }, + { + '@id': 'clss:_tHAikozUEeOiy8owVBW5pQ', + '@type': 'rm:Artifact', + identifier: 30001, + title: 'Requirement Module 30000 - Grouping 30001 Title', + }, + { + '@id': 'clss:_zYXy8ozUEeOiy8owVBW5pQ', + '@type': 'rm:Artifact', + identifier: 30002, + title: 'Requirement Module 30000 - Grouping 30002 Title', + }, + { + '@id': 'clss:_3AP4kYzUEeOiy8owVBW5pQ', + '@type': 'rm:Artifact', + identifier: 30003, + title: 'Requirement Module 30000 - Grouping 30003 Title', + }, + ], + lastSynced: 1723761063624, + isLoading: false, + pageSize: 500, + resolveCollConstrs: true, + }, + }, +}; describe('MstModel_Coll', () => { - it(`MstModel_Coll should update `, async () => { + it('MstModel_Coll should correspond JS Types', async () => { const client = new SparqlClientImplMock(); - const rootModelInitialStateWithColls = { - ...rootModelInitialState, - colls: { - 'rm:Artifacts_Coll': { - '@id': 'rm:Artifacts_Coll', - collConstr: { - '@id': 'rm:Artifacts_Coll', - '@type': 'aldkg:CollConstr', - entConstrs: [ - { - '@id': 'rm:Artifacts_Coll_Ent', - '@type': 'aldkg:EntConstr', - schema: 'rm:ArtifactShape', - conditions: {}, - data: {}, - }, - ], - }, - updPeriod: 300, - lazy: true, - dataIntrnl: [ - { - '@id': 'file:///myfile.xml', - '@type': 'rm:Artifact', - identifier: 30000, - title: 'Requirement Module 30000 Title', - }, - { - '@id': 'clss:_tHAikozUEeOiy8owVBW5pQ', - '@type': 'rm:Artifact', - identifier: 30001, - title: 'Requirement Module 30000 - Grouping 30001 Title', - }, - { - '@id': 'clss:_zYXy8ozUEeOiy8owVBW5pQ', - '@type': 'rm:Artifact', - identifier: 30002, - title: 'Requirement Module 30000 - Grouping 30002 Title', - }, - { - '@id': 'clss:_3AP4kYzUEeOiy8owVBW5pQ', - '@type': 'rm:Artifact', - identifier: 30003, - title: 'Requirement Module 30000 - Grouping 30003 Title', - }, - ], - lastSynced: 1723761063624, - isLoading: false, - pageSize: 500, - resolveCollConstrs: true, - }, - }, + const rep = MstRepository.create(rootModelInitialStateWithColls, { client }); + const repJs = getSnapshot(rep); + expectToBeDefined(repJs); + const coll = rep.getColl('rm:Artifacts_Coll'); + expectToBeDefined(coll); + const collConstr = coll.collConstr; + expectToBeDefined(collConstr); + const collConstrJs = getSnapshot(collConstr); + expectToBeDefined(collConstrJs); + const collConstrJs2: ICollConstrJsOpt = collConstrJs; + expectToBeDefined(collConstrJs2); + const collConstrJs3: ICollConstrJsOpt = { + '@id': '3', + entConstrs: [], }; + expectToBeDefined(collConstrJs3); + }); + + it('MstModel_Coll should update', async () => { + const client = new SparqlClientImplMock(); const rep = MstRepository.create(rootModelInitialStateWithColls, { client }); const coll = rep.getColl('rm:Artifacts_Coll'); expectToBeDefined(coll); diff --git a/test/SparqlClient.spec.ts b/test/SparqlClient.spec.ts index 3323662..320bd32 100644 --- a/test/SparqlClient.spec.ts +++ b/test/SparqlClient.spec.ts @@ -79,7 +79,7 @@ afterAll(async () => { }); describe('SparqlClient', () => { - it(`SparqlClient should select namespaces`, async () => { + it('SparqlClient should select namespaces', async () => { expect(repository.ns.current.size).toBe(6); await repository.ns.reloadNs(); //console.log(getSnapshot(repository.ns.current)); @@ -88,7 +88,7 @@ describe('SparqlClient', () => { const ns = repository.ns.currentJs; expect(ns.rdf).toBe('http://www.w3.org/1999/02/22-rdf-syntax-ns#'); }); - it(`SparqlClient should select direct parent classes`, async () => { + it('SparqlClient should select direct parent classes', async () => { const query = `PREFIX rdfs: PREFIX clss: SELECT ?superClass WHERE { clss:Classifier rdfs:subClassOf ?superClass. }`; @@ -96,7 +96,7 @@ describe('SparqlClient', () => { //console.log('results', json2str(results)); expect(results.bindings).toHaveLength(1); }); - it(`SparqlClient should select one directSubClassOf with enabled inference`, async () => { + it('SparqlClient should select one directSubClassOf with enabled inference', async () => { const query = `PREFIX rdfs: PREFIX clss: SELECT ?superClass WHERE { clss:Classifier sesame:directSubClassOf ?superClass. }`; @@ -105,7 +105,7 @@ describe('SparqlClient', () => { expect(results.bindings).toHaveLength(1); }); - it(`SparqlClient should construct Artifact shape with array props`, async () => { + it('SparqlClient should construct Artifact shape with array props', async () => { /*const query = `PREFIX rdfs: PREFIX sh: PREFIX dcterms: @@ -317,7 +317,7 @@ describe('SparqlClient', () => { // abbreviate IRIs }); - it(`SparqlClient should construct Classifier shape with array props`, async () => { + it('SparqlClient should construct Classifier shape with array props', async () => { const targetClass = 'clss:Classifier'; /*const query = `PREFIX rdf: PREFIX dcterms: @@ -570,7 +570,7 @@ describe('SparqlClient', () => { }`; */ - it(`SparqlClient should construct Folder`, async () => { + it('SparqlClient should construct Folder', async () => { const query = `PREFIX rdf: PREFIX nav: PREFIX oslc: @@ -602,7 +602,7 @@ describe('SparqlClient', () => { }); //TODO: Federated Queries tests not working due to shut downed services - // it(`SparqlClient should get federated timeseries`, async () => { + // it('SparqlClient should get federated timeseries', async () => { // const client = new SparqlClientImpl(rdfServerUrl); // client.setRepositoryId('mktp-fed'); // const query = `PREFIX rdf: @@ -672,7 +672,7 @@ describe('SparqlClient', () => { // // // }); - // it(`SparqlClient should get LIMITed timeseries`, async () => { + // it('SparqlClient should get LIMITed timeseries', async () => { // const client = new SparqlClientImpl(rdfServerUrl); // client.setRepositoryId('mktp-fed'); // /*const query = `PREFIX rdf: diff --git a/test/SparqlClientUpload.spec.ts b/test/SparqlClientUpload.spec.ts index 98c12a4..206e452 100644 --- a/test/SparqlClientUpload.spec.ts +++ b/test/SparqlClientUpload.spec.ts @@ -26,7 +26,7 @@ const repository = MstRepository.create(rootModelInitialState, { client }); let rmRepositoryID: string; describe('SparqlClientUpload', () => { - it(`SparqlClient should create and delete repository`, async () => { + it('SparqlClient should create and delete repository', async () => { rmRepositoryID = genTimestampedName('test_SparqlClientUpload'); await client.createRepository( { @@ -38,7 +38,7 @@ describe('SparqlClientUpload', () => { repository.setId(rmRepositoryID); await client.deleteRepository(rmRepositoryID); }); - it(`SparqlClient should upload 1 file`, async () => { + it('SparqlClient should upload 1 file', async () => { rmRepositoryID = genTimestampedName('test_SparqlClientUpload'); await client.createRepository( { @@ -51,7 +51,7 @@ describe('SparqlClientUpload', () => { await uploadFiles(client, [vocabsFiles[0]], rootFolder); await client.deleteRepository(rmRepositoryID); }); - it(`SparqlClient should upload 1 classifier vocab`, async () => { + it('SparqlClient should upload 1 classifier vocab', async () => { rmRepositoryID = genTimestampedName('test_SparqlClientUpload'); await client.createRepository( { @@ -64,7 +64,7 @@ describe('SparqlClientUpload', () => { await uploadFiles(client, [vocabsFiles[6]], rootFolder); await client.deleteRepository(rmRepositoryID); }); - it(`SparqlClient should upload 7 vocab files`, async () => { + it('SparqlClient should upload 7 vocab files', async () => { rmRepositoryID = genTimestampedName('test_SparqlClientUpload'); await client.createRepository( { @@ -81,7 +81,7 @@ describe('SparqlClientUpload', () => { ); await client.deleteRepository(rmRepositoryID); }); - it(`SparqlClient should upload all vocab files`, async () => { + it('SparqlClient should upload all vocab files', async () => { rmRepositoryID = genTimestampedName('test_SparqlClientUpload'); await client.createRepository( { @@ -94,7 +94,7 @@ describe('SparqlClientUpload', () => { await uploadFiles(client, vocabsFiles, rootFolder); await client.deleteRepository(rmRepositoryID); }); - it(`SparqlClient should upload all vocabs and shapes files`, async () => { + it('SparqlClient should upload all vocabs and shapes files', async () => { rmRepositoryID = genTimestampedName('test_SparqlClientUpload'); await client.createRepository( { @@ -109,7 +109,7 @@ describe('SparqlClientUpload', () => { await client.deleteRepository(rmRepositoryID); }); //TODO: Did not work - /*it(`SparqlClient should upload all shapes and vocabs files`, async () => { + /*it('SparqlClient should upload all shapes and vocabs files', async () => { rmRepositoryID = genTimestampedName('test_SparqlClientUpload'); await client.createRepository( { @@ -123,7 +123,7 @@ describe('SparqlClientUpload', () => { await uploadFiles(client, vocabsFiles, rootFolder); await client.deleteRepository(rmRepositoryID); });*/ - it(`SparqlClient should upload all vocabs, shapes and data files`, async () => { + it('SparqlClient should upload all vocabs, shapes and data files', async () => { rmRepositoryID = genTimestampedName('test_SparqlClientUpload'); await client.createRepository( { diff --git a/test/SparqlGen.spec.ts b/test/SparqlGen.spec.ts index 015597d..e58f864 100644 --- a/test/SparqlGen.spec.ts +++ b/test/SparqlGen.spec.ts @@ -10,7 +10,7 @@ import { afterAll, beforeAll, beforeEach, describe, expect, jest, it } from '@jest/globals'; import { Parser } from 'sparqljs'; -import { JsObject, JSONSchema7_LD } from '../src/ObjectProvider'; +import { JsObject, JSONSchema7LD } from '../src/ObjectProvider'; import { factory, getFullIriNamedNode, ICollConstrJsOpt } from '../src/SparqlGen'; import { constructObjectsQuery, selectObjectsQuery } from '../src/SparqlGenSelect'; import { insertObjectQuery, deleteObjectQuery, updateObjectQuery } from '../src/SparqlGenUpdate'; @@ -32,7 +32,7 @@ import { expectToBeDefined } from './TestHelpers'; // See https://stackoverflow.com/questions/49603939/async-callback-was-not-invoked-within-the-5000ms-timeout-specified-by-jest-setti jest.setTimeout(500000); -const SchemaWithoutArrayProperties: JSONSchema7_LD = { +const SchemaWithoutArrayProperties: JSONSchema7LD = { $schema: 'http://json-schema.org/draft-07/schema#', //$id: 'https://agentlab.eu/ns/rm/rdf#PropertyShapeWithoutArrayProperties', '@id': 'rm:PropertyShapeWithoutArrayProperties', @@ -179,7 +179,7 @@ describe('SchemaWithoutArrayProperties', () => { )); }); -const SchemaWithArrayProperty: JSONSchema7_LD = { +const SchemaWithArrayProperty: JSONSchema7LD = { $schema: 'http://json-schema.org/draft-07/schema#', //$id: 'http://www.w3.org/ns/shacl#SchemaWithArrayProperty', '@id': 'sh:SchemaWithArrayProperty', diff --git a/test/schema/TestSchemas.ts b/test/schema/TestSchemas.ts index ff4a969..99433eb 100644 --- a/test/schema/TestSchemas.ts +++ b/test/schema/TestSchemas.ts @@ -7,13 +7,13 @@ * * SPDX-License-Identifier: GPL-3.0-only ********************************************************************************/ -import { JSONSchema7_LD, JsObject } from '../../src/ObjectProvider'; +import { JSONSchema7LD, JsObject } from '../../src/ObjectProvider'; export const textFormatUri = 'rmUserTypes:_YwcOsRmREemK5LEaKhoOow_Text'; export const collectionFormatUri = 'rmUserTypes:_YwcOsRmREemK5LEaKhoOow_Collection'; export const moduleFormatUri = 'rmUserTypes:_YwcOsRmREemK5LEaKhoOow_Module'; -export const artifactSchema: JSONSchema7_LD = { +export const artifactSchema: JSONSchema7LD = { $schema: 'http://json-schema.org/draft-07/schema#', //$id: 'https://agentlab.eu/ns/rm/rdf#ArtifactShape', '@id': 'rm:ArtifactShape', @@ -157,7 +157,7 @@ export const artifactSchema: JSONSchema7_LD = { required: ['@id', '@type', 'title' /*, 'identifier', 'assetFolder', 'artifactFormat'*/], }; -export const genericArtifactSchema: JSONSchema7_LD = { +export const genericArtifactSchema: JSONSchema7LD = { $schema: 'http://json-schema.org/draft-07/schema#', //$id: 'https://agentlab.eu/ns/rm/classifier#GenericArtifactShape', allOf: [{ $ref: 'rm:ArtifactShape' }], @@ -215,7 +215,7 @@ export const genericArtifactSchema: JSONSchema7_LD = { }, }; -export const classifierSchema: JSONSchema7_LD = { +export const classifierSchema: JSONSchema7LD = { $schema: 'http://json-schema.org/draft-07/schema#', //$id: 'https://agentlab.eu/ns/rm/classifier#ClassifierShape', allOf: [{ $ref: 'clss:GenericArtifactShape' }], @@ -232,7 +232,7 @@ export const classifierSchema: JSONSchema7_LD = { properties: {}, }; -export const classifierCompleteSchema: JSONSchema7_LD = { +export const classifierCompleteSchema: JSONSchema7LD = { ...classifierSchema, '@context': { ...artifactSchema['@context'], @@ -424,7 +424,7 @@ export const artifactShape: JsObject = { title: 'Artifact', }; -export const linkSchema: JSONSchema7_LD = { +export const linkSchema: JSONSchema7LD = { $schema: 'http://json-schema.org/draft-07/schema#', //$id: 'https://agentlab.eu/ns/rm/user-types#UsedInShape', '@id': 'rm:LinkShape', @@ -528,7 +528,7 @@ export const linkSchema: JSONSchema7_LD = { required: ['@id', '@type', 'object', 'subject'], }; -export const usedInSchema: JSONSchema7_LD = { +export const usedInSchema: JSONSchema7LD = { ...linkSchema, '@id': 'rmUserTypes:UsedInShape', title: 'UsedIn Link', @@ -536,7 +536,7 @@ export const usedInSchema: JSONSchema7_LD = { targetClass: 'rmUserTypes:UsedIn', }; -export const usedInModuleSchema: JSONSchema7_LD = { +export const usedInModuleSchema: JSONSchema7LD = { ...usedInSchema, allOf: [{ $ref: 'rmUserTypes:UsedInShape' }], '@id': 'rmUserTypes:UsedInModuleShape', @@ -605,7 +605,7 @@ export const usedInModuleSchema: JSONSchema7_LD = { export const { property: artifactShapeProperty, ...artifactShapeNoProperty } = artifactShape; -export const ProductCardShapeSchema: JSONSchema7_LD = { +export const ProductCardShapeSchema: JSONSchema7LD = { $schema: 'http://json-schema.org/draft-07/schema#', '@id': 'iot:ProductCardCardsShape', '@type': 'sh:NodeShape', @@ -689,7 +689,7 @@ export const ProductCardShapeSchema: JSONSchema7_LD = { required: ['@id', '@type', 'name', 'lastMonthSalesValue', 'seller'], }; -export const HSObservationShapeSchema: JSONSchema7_LD = { +export const HSObservationShapeSchema: JSONSchema7LD = { $schema: 'http://json-schema.org/draft-07/schema#', '@id': 'iot:HSObservationCardsShape', '@type': 'sh:NodeShape', @@ -753,7 +753,7 @@ export const HSObservationShapeSchema: JSONSchema7_LD = { required: ['@id', '@type', 'product', 'parsedAt', 'totalSales'], }; -export const ProductCardShapeSchemaForCardsList: JSONSchema7_LD = { +export const ProductCardShapeSchemaForCardsList: JSONSchema7LD = { $schema: 'http://json-schema.org/draft-07/schema#', '@id': 'iot:ProductCardShapeForCardsList', '@type': 'sh:NodeShape', @@ -835,7 +835,7 @@ export const ProductCardShapeSchemaForCardsList: JSONSchema7_LD = { required: ['@id', '@type', 'name', 'lastMonthSalesValue', 'hasObservations'], }; -export const HSObservationShapeSchemaForCardsList: JSONSchema7_LD = { +export const HSObservationShapeSchemaForCardsList: JSONSchema7LD = { $schema: 'http://json-schema.org/draft-07/schema#', '@id': 'iot:HSObservationShapeForCardsList', '@type': 'sh:NodeShape',