From 9b85667362fc765f63595d1a2eb770ed81c65729 Mon Sep 17 00:00:00 2001 From: Aleksei Ivanov Date: Sat, 24 Aug 2024 00:43:36 +0300 Subject: [PATCH] [refactor] Migrate to JSONSchema7, add typechecks, cleanup --- src/ObjectProvider.ts | 37 +++++++----------- src/ObjectProviderImpl.ts | 14 +++---- src/SparqlGen.ts | 16 ++++---- src/SparqlGenSelect.ts | 6 +-- src/models/Model.ts | 8 ++-- src/models/MstCollConstr.ts | 2 +- src/models/MstRepository.ts | 65 ++----------------------------- src/models/MstSchemas.ts | 16 ++++---- src/schema/ArtifactShapeSchema.ts | 14 +++---- src/schema/Formatters.ts | 7 +--- src/schema/RdfsSchema.ts | 17 ++++---- test-data/data/sample-module.ttl | 4 +- test-data/shapes/rm-shapes.ttl | 8 ++-- test/SparqlGen.spec.ts | 6 +-- test/schema/TestSchemas.ts | 48 +++++++++++------------ 15 files changed, 101 insertions(+), 167 deletions(-) diff --git a/src/ObjectProvider.ts b/src/ObjectProvider.ts index 0e6918d..950ad23 100644 --- a/src/ObjectProvider.ts +++ b/src/ObjectProvider.ts @@ -8,7 +8,7 @@ * SPDX-License-Identifier: GPL-3.0-only ********************************************************************************/ import uuid62 from 'uuid62'; -import { JSONSchema6 } from 'json-schema'; +import { JSONSchema7, JSONSchema7TypeName } from 'json-schema'; export function json2str(data: any): string { if (data) return JSON.stringify(data, null, 2); @@ -35,11 +35,8 @@ export function idComparator(a: JsObject, b: JsObject): number { return 0; } -export type JSONSchema6DefinitionForRdfProperty = JSONSchema6forRdfProperty; -export interface JSONSchema6forRdfProperty extends JSONSchema6 { - //uri: string; - //formatters?: { [key: string]: (value: any) => any }; - +export type JSONSchema7PropertyDefinition_LD = JSONSchema7Property_LD; +export interface JSONSchema7Property_LD extends JSONSchema7 { /** * json-ld Property * https://github.com/json-ld/json-ld.org/blob/master/schemas/jsonld-schema.json @@ -47,24 +44,22 @@ export interface JSONSchema6forRdfProperty extends JSONSchema6 { '@id'?: string; '@type'?: string; + // permissions extension valueModifiability?: string; // user or non -- system shapeModifiability?: string; // user or non -- system - contentMediaType?: string; - contentEncoding?: string; - properties?: { - [key: string]: JSONSchema6DefinitionForRdfProperty; + [key: string]: JSONSchema7PropertyDefinition_LD; }; } -export type JSONSchema6DefinitionForRdf = JSONSchema6forRdf; -export interface JSONSchema6forRdf extends JSONSchema6, JsObject { - //uri: string; - //formatField?: (field: JSONSchema6DefinitionForRdfProperty, value: any, format?: string) => any; +export type JSONSchema7Definition_LD = JSONSchema7_LD; +export interface JSONSchema7_LD extends Omit, JsObject { + allOf?: { $ref: string }[] | undefined; // override from this: "allOf?: JSONSchema6Definition[] | undefined;" + type: JSONSchema7TypeName; // restrict from this: "type?: JSONSchema6TypeName | JSONSchema6TypeName[] | undefined;" /** - * json-ld Node + * json-ld Node extensions * https://github.com/json-ld/json-ld.org/blob/master/schemas/jsonld-schema.json */ '@context'?: JsStrObjObj; // json-ld @@ -72,23 +67,21 @@ export interface JSONSchema6forRdf extends JSONSchema6, JsObject { //'@included' // json-ld //'@graph'?: [] | {}; // json-ld //'@nest' // json-ld - '@type'?: string; // json-ld + '@type'?: string; // json-ld (SHACL Shape IRI -- shape IRI itself, not shaped class IRI) //'@reverse' //'@index' - targetClass: string; + targetClass: string; // SHACL Shape Class IRI (shaped class IRI) + // Artifact extensions //inCreationMenu?: boolean; //defaultFormat?: string; //iconReference?: string; properties: { - [key: string]: JSONSchema6DefinitionForRdfProperty; + [key: string]: JSONSchema7PropertyDefinition_LD; }; } -export type JSONSchema6forRdf2 = JSONSchema6forRdf & { - '@id'?: string; -}; export function copyObjectProps(objTo: JsObject, objFrom: JsObject): void { Object.keys(objFrom).forEach((objFromKey) => { @@ -147,7 +140,7 @@ export function copyUniqueArrayElements(arrTo: any[], arrFrom: any[]): void { }); } -export function getPropKeysByFormat(schema: JSONSchema6forRdf, format: string): string[] { +export function getPropKeysByFormat(schema: JSONSchema7_LD, 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 c42ceca..20b1877 100644 --- a/src/ObjectProviderImpl.ts +++ b/src/ObjectProviderImpl.ts @@ -8,16 +8,16 @@ * SPDX-License-Identifier: GPL-3.0-only ********************************************************************************/ import { - JSONSchema6forRdf, + JSONSchema7_LD, JsObject, - JSONSchema6DefinitionForRdfProperty, + JSONSchema7PropertyDefinition_LD, copyObjectProps, copyUniqueArrayElements, } from './ObjectProvider'; export const schemaNonPrimitivePropsKeys = ['@context', 'properties', 'required']; -function combineProperties(oldObj: any, newObj: any, schema: JSONSchema6forRdf): any { +function combineProperties(oldObj: any, newObj: any, schema: JSONSchema7_LD): 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: JSONSchema6forRdf): return newData; } -export function createObjectWithoutRepetitions(objects: any[], schema: JSONSchema6forRdf): any[] { +export function createObjectWithoutRepetitions(objects: any[], schema: JSONSchema7_LD): 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]: JSONSchema6DefinitionForRdfProperty }, JsObject, string[], JsObject] { - const schemaProps: { [key: string]: JSONSchema6DefinitionForRdfProperty } = {}; +): [{ [key: string]: JSONSchema7PropertyDefinition_LD }, JsObject, string[], JsObject] { + const schemaProps: { [key: string]: JSONSchema7PropertyDefinition_LD } = {}; const schemaContexts: JsObject = {}; const schemaReqs: string[] = []; const uiSchema: JsObject = {}; @@ -261,7 +261,7 @@ export function propertyShapesToSchemaProperties( * @param schema * @param parentSchema */ -export function addToSchemaParentSchema(schema: JSONSchema6forRdf, parentSchema: JSONSchema6forRdf): JSONSchema6forRdf { +export function addToSchemaParentSchema(schema: JSONSchema7_LD, parentSchema: JSONSchema7_LD): JSONSchema7_LD { 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 5905cf2..d8d3e24 100644 --- a/src/SparqlGen.ts +++ b/src/SparqlGen.ts @@ -15,8 +15,8 @@ import { BgpPattern, Generator, OptionalPattern } from 'sparqljs'; import { Bindings } from './SparqlClient'; import { - JSONSchema6forRdf, - JSONSchema6forRdfProperty, + JSONSchema7_LD, + JSONSchema7Property_LD, JsObject, copyObjectPropsWithRenameOrFilter, JsStrObj, @@ -69,11 +69,11 @@ export function propsToSparqlVars(entConstr: Pick c.schema.targetClass === propType); diff --git a/src/models/Model.ts b/src/models/Model.ts index b5bfce8..85b0eea 100644 --- a/src/models/Model.ts +++ b/src/models/Model.ts @@ -14,15 +14,14 @@ import { ArtifactShapeSchema, PropertyShapeSchema } from '../schema/ArtifactShap import { JsObject } from '../ObjectProvider'; import { SparqlClient } from '../SparqlClient'; -import { MstRepository } from './MstRepository'; +import { MstRepository, TMstRepositorySnapshotIn } from './MstRepository'; -export const rootModelInitialState: any = { +export const rootModelInitialState: TMstRepositorySnapshotIn = { repId: '', user: { - login: 'guest@example.com', + login: 'guest@acme.com', name: 'Guest', }, - processArea: 'projects:defaultProject', ns: { current: { rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', @@ -49,7 +48,6 @@ export const rootModelInitialState: any = { [PropertyShapeSchema.targetClass]: PropertyShapeSchema['@id'], }, }, - //collsConstr: {}, colls: {}, }; diff --git a/src/models/MstCollConstr.ts b/src/models/MstCollConstr.ts index 4ca6b2c..fda27b3 100644 --- a/src/models/MstCollConstr.ts +++ b/src/models/MstCollConstr.ts @@ -230,7 +230,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: JSONSchema6forRdf = { + const schemaWithArrayProperty: JSONSchema7_LD = { ...schema, '@id': '_' + uuid62.v4(), '@context': { diff --git a/src/models/MstRepository.ts b/src/models/MstRepository.ts index 06eb9c6..71b9298 100644 --- a/src/models/MstRepository.ts +++ b/src/models/MstRepository.ts @@ -8,7 +8,7 @@ * SPDX-License-Identifier: GPL-3.0-only ********************************************************************************/ import { values } from 'mobx'; -import { types, getSnapshot, applySnapshot, getEnv, Instance } from 'mobx-state-tree'; +import { types, getSnapshot, applySnapshot, getEnv, Instance, SnapshotIn, SnapshotOut } from 'mobx-state-tree'; import { addMissingId, JsObject } from '../ObjectProvider'; import { abbreviateIri } from '../SparqlGen'; @@ -33,7 +33,6 @@ export const MstRepository = types .model('MstRepository', { repId: types.string, user: User, - //processArea: types.string, ns: MstNamespaces, schemas: MstSchemas, @@ -42,9 +41,6 @@ export const MstRepository = types * Use rep.getColl(iri) instead of rep.colls.get(iri) */ colls: types.map(MstColl), - editingData: types.map(types.boolean), - - selectedData: types.map(types.frozen()), }) /** * Views @@ -61,18 +57,6 @@ export const MstRepository = types const coll = self.colls.get(iri); return coll; }, - - getSelectedDataJs(iri: string) { - if (!iri) return undefined; - const coll = this.getColl(iri); - if (!coll) return undefined; - const id = self.selectedData.get(iri); - if (id) { - const data = coll.dataByIri(id); - if (data) return getSnapshot(data); - } - return undefined; - }, }; }) /** @@ -221,49 +205,6 @@ export const MstRepository = types }, saveData(schemaUri: string) {}, - ////////// Selection Service /////////// - - setSelectedData(iri: string, data: any) { - //console.log('setSelectedData START', { iri, data }); - if (iri /*&& */) { - //let id: string; - //if (typeof data === 'string') { - // id = data; - //} else { - // id = data['@id']; - // - //if (id && typeof id === 'string') { - // self.selectedData.set(iri, id); - // console.log('setSelectedData UPDATE', { iri, id }); - //} - self.selectedData.set(iri, data); - } - //console.log('setSelectedData END', { iri, data }); - }, - ////////// FORM /////////// - onSaveFormData(formId: string) {}, - onCancelForm(id: string) {}, - setEditing(schemaUri: string, state: boolean, reset = false) { - if (self.editingData.get(schemaUri) !== state) { - self.editingData.set(schemaUri, state); - //if (schemaUri === 'root' && this.setParentEditing) { - // self.setParentEditing(state); - //} - //if (this.saveLogicTree[schemaUri] && this.saveLogicTree[schemaUri].parent) { - // this.setEditingChanges(this.saveLogicTree[schemaUri].parent as string, state, schemaUri); - //} - //if (reset) { - // this.resetEditingChanges(schemaUri); - //} - } - }, - setModalVisible(uri: string, state: boolean) {}, - setOnValidate(form: string, id: string, state: boolean) {}, - onChangeData(path: string, data: any) {}, - setSaveLogic(parent: string, child: string) {}, - setEditingChanges(parentUri: string, state: boolean, childUri: string) {}, - onChangeFormData(form: string, path: string, data: any) {}, - resetEditingChanges(schemaUri: string) {}, /** * Edit Connection @@ -541,4 +482,6 @@ export const MstRepository = types }; }); -export type IRepository = Instance; +export type TMstRepository = Instance; +export type TMstRepositorySnapshotIn = SnapshotIn; +export type TMstRepositorySnapshotOut = SnapshotOut; diff --git a/src/models/MstSchemas.ts b/src/models/MstSchemas.ts index fed0010..3d9e68d 100644 --- a/src/models/MstSchemas.ts +++ b/src/models/MstSchemas.ts @@ -21,7 +21,7 @@ import { getRoot, } from 'mobx-state-tree'; -import { JSONSchema6forRdf, copyUniqueObjectPropsWithRenameOrFilter, JsObject } from '../ObjectProvider'; +import { JSONSchema7_LD, copyUniqueObjectPropsWithRenameOrFilter, JsObject, JsStrObjObj } from '../ObjectProvider'; import { propertyShapesToSchemaProperties, uiMapping, @@ -59,7 +59,7 @@ export function createSchemaWithSubClassOf(schema: any, iri: string, classIri?: }; } -const MstJSONSchema7TypeName = types.enumeration(['string', 'number', 'boolean', 'object', 'integer', 'array', 'null']); +const MstJSONSchema7TypeName = types.enumeration(['string', 'number', 'integer', 'boolean', 'object', 'array', 'null']); const MstJSONSchema7Type = types.union( types.string, types.number, @@ -95,7 +95,7 @@ export const MstJSONSchema7forRdf = types */ '@id': types.identifier, // id of a shape '@type': types.maybe(types.string), // type of a shape (Node or Property) - '@context': types.maybe(types.map(types.union(types.string, types.map(types.string)))), // json-ld + '@context': types.maybe(types.map(types.union(types.string, types.frozen()))), // json-ld /** * Our custom extensions from SHACL @@ -274,7 +274,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: JSONSchema6forRdf[] = yield getDirectSuperSchemas(schema); + let schemaQueue: JSONSchema7_LD[] = 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 +291,9 @@ export const MstSchemas = types return self.json.get(schemaResult['@id']); }); - const getDirectSuperSchemas = flow(function* getDirectSuperSchemas(schema: JSONSchema6forRdf) { + const getDirectSuperSchemas = flow(function* getDirectSuperSchemas(schema: JSONSchema7_LD) { //console.debug('getDirectSuperSchemas for schema=', schema['@id']); - const schemaOrUndef: JSONSchema6forRdf | undefined = schema; + const schemaOrUndef: JSONSchema7_LD | undefined = schema; const parentSchemas: any[] = []; if (schemaOrUndef.allOf) { const schemaAllOf: any[] = schemaOrUndef.allOf.filter((s1: any) => s1.$ref !== undefined); @@ -313,7 +313,7 @@ export const MstSchemas = types return parentSchemas; }); - const copyAllSchemasToOne = (schemaQueue: JSONSchema6forRdf[], schema: any) => { + const copyAllSchemasToOne = (schemaQueue: JSONSchema7_LD[], schema: any) => { let schemaOrUndefined: any | undefined; while (schemaQueue.length > 0) { schemaOrUndefined = schemaQueue.pop(); @@ -338,7 +338,7 @@ export const MstSchemas = types const loadingByIri: any = {}; return { - addSchema(schema: JSONSchema6forRdf): void { + addSchema(schema: JSONSchema7_LD): void { const iri: string = abbreviateIri(schema['@id'], repository.ns.currentJs); if (!self.json.get(iri)) { self.json.set(iri, schema as any); diff --git a/src/schema/ArtifactShapeSchema.ts b/src/schema/ArtifactShapeSchema.ts index 129c505..f9d3a94 100644 --- a/src/schema/ArtifactShapeSchema.ts +++ b/src/schema/ArtifactShapeSchema.ts @@ -7,9 +7,9 @@ * * SPDX-License-Identifier: GPL-3.0-only ********************************************************************************/ -import { JSONSchema6forRdf } from '../ObjectProvider'; +import { JSONSchema7_LD } from '../ObjectProvider'; -export const ArtifactShapeSchema: JSONSchema6forRdf = { +export const ArtifactShapeSchema: JSONSchema7_LD = { $schema: 'http://json-schema.org/draft-07/schema#', '@id': 'sh:NodeShapeShape', '@type': 'sh:NodeShape', @@ -25,10 +25,10 @@ export const ArtifactShapeSchema: JSONSchema6forRdf = { }, title: 'dcterms:title', description: 'dcterms:description', - /*property: { - '@id': 'sh:property', - '@type': 'sh:PropertyShape', - },*/ + //property: { + // '@id': 'sh:property', + // '@type': 'sh:PropertyShape', + //}, property: 'sh:property', inCreationMenu: 'rm:inCreationMenu', defaultIndividNs: { @@ -87,7 +87,7 @@ export const ArtifactShapeSchema: JSONSchema6forRdf = { required: ['@id', 'targetClass' /*, 'property'*/], // arrays should be required }; -export const PropertyShapeSchema: JSONSchema6forRdf = { +export const PropertyShapeSchema: JSONSchema7_LD = { $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 b8207b6..498b7da 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 { JSONSchema6forRdf } from '../ObjectProvider'; +import { JSONSchema7_LD } from '../ObjectProvider'; interface FormatterAndDefaultAndTitle { propertyFormatter?: (value: any) => any; @@ -16,10 +16,7 @@ interface FormatterAndDefaultAndTitle { propertyTitle?: string; } -export function getPropertyFormatterAndDefault( - schema: JSONSchema6forRdf, - propKey: string, -): FormatterAndDefaultAndTitle { +export function getPropertyFormatterAndDefault(schema: JSONSchema7_LD, 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 9f37a00..cfd0099 100644 --- a/src/schema/RdfsSchema.ts +++ b/src/schema/RdfsSchema.ts @@ -8,7 +8,9 @@ * SPDX-License-Identifier: GPL-3.0-only ********************************************************************************/ -export const NopSchema: any /*JSONSchema6forRdf*/ = { +import { JSONSchema7_LD } from '../ObjectProvider'; + +export const NopSchema: any /*JSONSchema7_LD*/ = { $schema: 'http://json-schema.org/draft-07/schema#', //$id: 'https://agentlab.eu/ns/rm/rdf#NopSchema', '@id': 'rm:NopSchema', // json-ld @@ -24,7 +26,7 @@ export const NopSchema: any /*JSONSchema6forRdf*/ = { required: ['@id'], }; -export const ResourceSchema: any /*JSONSchema6forRdf*/ = { +export const ResourceSchema: JSONSchema7_LD = { $schema: 'http://json-schema.org/draft-07/schema#', //$id: 'https://agentlab.eu/ns/rm/rdf#ResourceSchema', '@id': 'rm:ResourceSchema', // json-ld @@ -56,7 +58,7 @@ export const ResourceSchema: any /*JSONSchema6forRdf*/ = { required: ['@id'], }; -export const ClassSchema: any /*JSONSchema6forRdf*/ = { +export const ClassSchema: JSONSchema7_LD = { $schema: 'http://json-schema.org/draft-07/schema#', //$id: 'https://agentlab.eu/ns/rm/rdf#Class', '@id': 'rm:Class', // json-ld @@ -97,16 +99,17 @@ export const ClassSchema: any /*JSONSchema6forRdf*/ = { required: ['@id'], }; -/*export const DataTypeSchema: JSONSchema6forRdf = { +export const DataTypeSchema: JSONSchema7_LD = { $schema: 'http://json-schema.org/draft-07/schema#', '@id': 'rdfs:Datatype', // json-ld - '@type': 'rdfs:Datatype', // json-ld + '@type': 'rdfs:DatatypeShape', // json-ld title: 'DataType', description: 'DataType', + targetClass: 'rdfs:Datatype', type: 'object', '@context': { '@type': 'rdf:type', - 'label': 'rdfs:label', + label: 'rdfs:label', }, properties: { '@id': { @@ -130,4 +133,4 @@ export const ClassSchema: any /*JSONSchema6forRdf*/ = { // }, }, required: ['@id'], -};*/ +}; diff --git a/test-data/data/sample-module.ttl b/test-data/data/sample-module.ttl index d9570e8..9c5630f 100644 --- a/test-data/data/sample-module.ttl +++ b/test-data/data/sample-module.ttl @@ -34,7 +34,7 @@ dcterms:modified "2014-02-10T10:12:16.000Z"^^xsd:dateTime ; oslc_asset:guid "E159CD38-5205-DA02-CDAE-560D10043BD5" ; clss:status rmUserTypes:_YwrbNRmREemK5LEaKhoOow_Draft ; - clss:uri ; + clss:uri ; oslc_asset:version "1.0"^^xsd:string ; nav:processArea projects:defaultProject ; rm:assetFolder folders:samples_module . @@ -47,7 +47,7 @@ clss:_tHAikozUEeOiy8owVBW5pQ rm:xhtmlText "Requirement Module 30000 - Grouping 30001 Text"^^rdf:HTML ; rm:artifactFormat rmUserTypes:_YwcOsRmREemK5LEaKhoOow_Text ; clss:format "Text"^^xsd:string ; - clss:link ; + clss:link clss:_tHAikozUEeOiy8owVBW5pQ ; clss:status rmUserTypes:_YwrbNRmREemK5LEaKhoOow_Draft ; clss:uri clss:_tHAikozUEeOiy8owVBW5pQ ; dcterms:creator users:user1 ; diff --git a/test-data/shapes/rm-shapes.ttl b/test-data/shapes/rm-shapes.ttl index b60764a..e0a984d 100644 --- a/test-data/shapes/rm-shapes.ttl +++ b/test-data/shapes/rm-shapes.ttl @@ -234,7 +234,7 @@ rm:xhtmlTextShape rm:creatorShape a sh:PropertyShape ; sh:name "Creator"^^xsd:string ; - sh:description "An Agent, created an Artifact"^^xsd:string ; + sh:description "An Agent, created a Resource"^^xsd:string ; sh:path dcterms:creator ; sh:order 5 ; rm:shapeModifiability "system" ; @@ -247,7 +247,7 @@ rm:creatorShape rm:createdShape a sh:PropertyShape ; sh:name "Created"^^xsd:string ; - sh:description "When an Artifact was created"^^xsd:string ; + sh:description "When a Resource was created"^^xsd:string ; sh:path dcterms:created ; sh:order 6 ; rm:shapeModifiability "system" ; @@ -259,7 +259,7 @@ rm:createdShape rm:modifiedByShape a sh:PropertyShape ; sh:name "Modified By"^^xsd:string ; - sh:description "An Agent, modified an Artifact"^^xsd:string ; + sh:description "An Agent, modified a Resource"^^xsd:string ; sh:path oslc:modifiedBy ; sh:order 7 ; rm:shapeModifiability "system" ; @@ -272,7 +272,7 @@ rm:modifiedByShape rm:modifiedShape a sh:PropertyShape ; sh:name "Modified"^^xsd:string ; - sh:description "When an Artifact was modified"^^xsd:string ; + sh:description "When a Resource was modified"^^xsd:string ; sh:path dcterms:modified ; sh:order 8 ; rm:shapeModifiability "system" ; diff --git a/test/SparqlGen.spec.ts b/test/SparqlGen.spec.ts index 5b6faa0..015597d 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, JSONSchema6forRdf } from '../src/ObjectProvider'; +import { JsObject, JSONSchema7_LD } 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: JSONSchema6forRdf = { +const SchemaWithoutArrayProperties: JSONSchema7_LD = { $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: JSONSchema6forRdf = { +const SchemaWithArrayProperty: JSONSchema7_LD = { $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 840870e..ff4a969 100644 --- a/test/schema/TestSchemas.ts +++ b/test/schema/TestSchemas.ts @@ -7,13 +7,13 @@ * * SPDX-License-Identifier: GPL-3.0-only ********************************************************************************/ -import { JSONSchema6forRdf, JsObject } from '../../src/ObjectProvider'; +import { JSONSchema7_LD, 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: JSONSchema6forRdf = { +export const artifactSchema: JSONSchema7_LD = { $schema: 'http://json-schema.org/draft-07/schema#', //$id: 'https://agentlab.eu/ns/rm/rdf#ArtifactShape', '@id': 'rm:ArtifactShape', @@ -99,7 +99,7 @@ export const artifactSchema: JSONSchema6forRdf = { }, creator: { title: 'Creator', - description: 'An Agent, created an Artifact', + description: 'An Agent, created a Resource', type: 'string', format: 'iri', shapeModifiability: 'system', @@ -107,7 +107,7 @@ export const artifactSchema: JSONSchema6forRdf = { }, created: { title: 'Created', - description: 'When an Artifact was created', + description: 'When a Resource was created', type: 'string', format: 'date-time', shapeModifiability: 'system', @@ -115,7 +115,7 @@ export const artifactSchema: JSONSchema6forRdf = { }, modifiedBy: { title: 'Modified By', - description: 'An Agent, modified an Artifact', + description: 'An Agent, modified a Resource', type: 'string', format: 'iri', shapeModifiability: 'system', @@ -123,7 +123,7 @@ export const artifactSchema: JSONSchema6forRdf = { }, modified: { title: 'Modified', - description: 'When an Artifact was modified', + description: 'When a Resource was modified', type: 'string', format: 'date-time', shapeModifiability: 'system', @@ -157,7 +157,7 @@ export const artifactSchema: JSONSchema6forRdf = { required: ['@id', '@type', 'title' /*, 'identifier', 'assetFolder', 'artifactFormat'*/], }; -export const genericArtifactSchema: JSONSchema6forRdf = { +export const genericArtifactSchema: JSONSchema7_LD = { $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: JSONSchema6forRdf = { }, }; -export const classifierSchema: JSONSchema6forRdf = { +export const classifierSchema: JSONSchema7_LD = { $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: JSONSchema6forRdf = { properties: {}, }; -export const classifierCompleteSchema: JSONSchema6forRdf = { +export const classifierCompleteSchema: JSONSchema7_LD = { ...classifierSchema, '@context': { ...artifactSchema['@context'], @@ -319,7 +319,7 @@ export const artifactShape: JsObject = { '@type': 'sh:PropertyShape', class: 'pporoles:User', //datatype: undefined, - description: 'An Agent, created an Artifact', + description: 'An Agent, created a Resource', maxCount: 1, //minCount: undefined, name: 'Creator', @@ -334,7 +334,7 @@ export const artifactShape: JsObject = { '@type': 'sh:PropertyShape', //class: undefined, datatype: 'xsd:dateTime', - description: 'When an Artifact was created', + description: 'When a Resource was created', maxCount: 1, //minCount: undefined, name: 'Created', @@ -349,7 +349,7 @@ export const artifactShape: JsObject = { '@type': 'sh:PropertyShape', class: 'pporoles:User', //datatype: undefined, - description: 'An Agent, modified an Artifact', + description: 'An Agent, modified a Resource', maxCount: 1, //minCount: undefined, name: 'Modified By', @@ -364,7 +364,7 @@ export const artifactShape: JsObject = { '@type': 'sh:PropertyShape', //class: undefined, datatype: 'xsd:dateTime', - description: 'When an Artifact was modified', + description: 'When a Resource was modified', maxCount: 1, //minCount: undefined, name: 'Modified', @@ -424,7 +424,7 @@ export const artifactShape: JsObject = { title: 'Artifact', }; -export const linkSchema: JSONSchema6forRdf = { +export const linkSchema: JSONSchema7_LD = { $schema: 'http://json-schema.org/draft-07/schema#', //$id: 'https://agentlab.eu/ns/rm/user-types#UsedInShape', '@id': 'rm:LinkShape', @@ -479,28 +479,28 @@ export const linkSchema: JSONSchema6forRdf = { type: 'string', format: 'iri', title: 'Creator', - description: 'An Agent, created an Artifact', + description: 'An Agent, created a Resource', shapeModifiability: 'system', }, created: { type: 'string', format: 'date-time', title: 'Created', - description: 'When an Artifact was created', + description: 'When a Resource was created', shapeModifiability: 'system', }, modifiedBy: { type: 'string', format: 'iri', title: 'Modified By', - description: 'An Agent, modified an Artifact', + description: 'An Agent, modified a Resource', shapeModifiability: 'system', }, modified: { type: 'string', format: 'date-time', title: 'Modified', - description: 'When an Artifact was modified', + description: 'When a Resource was modified', shapeModifiability: 'system', }, processArea: { @@ -528,7 +528,7 @@ export const linkSchema: JSONSchema6forRdf = { required: ['@id', '@type', 'object', 'subject'], }; -export const usedInSchema: JSONSchema6forRdf = { +export const usedInSchema: JSONSchema7_LD = { ...linkSchema, '@id': 'rmUserTypes:UsedInShape', title: 'UsedIn Link', @@ -536,7 +536,7 @@ export const usedInSchema: JSONSchema6forRdf = { targetClass: 'rmUserTypes:UsedIn', }; -export const usedInModuleSchema: JSONSchema6forRdf = { +export const usedInModuleSchema: JSONSchema7_LD = { ...usedInSchema, allOf: [{ $ref: 'rmUserTypes:UsedInShape' }], '@id': 'rmUserTypes:UsedInModuleShape', @@ -605,7 +605,7 @@ export const usedInModuleSchema: JSONSchema6forRdf = { export const { property: artifactShapeProperty, ...artifactShapeNoProperty } = artifactShape; -export const ProductCardShapeSchema: JSONSchema6forRdf = { +export const ProductCardShapeSchema: JSONSchema7_LD = { $schema: 'http://json-schema.org/draft-07/schema#', '@id': 'iot:ProductCardCardsShape', '@type': 'sh:NodeShape', @@ -689,7 +689,7 @@ export const ProductCardShapeSchema: JSONSchema6forRdf = { required: ['@id', '@type', 'name', 'lastMonthSalesValue', 'seller'], }; -export const HSObservationShapeSchema: JSONSchema6forRdf = { +export const HSObservationShapeSchema: JSONSchema7_LD = { $schema: 'http://json-schema.org/draft-07/schema#', '@id': 'iot:HSObservationCardsShape', '@type': 'sh:NodeShape', @@ -753,7 +753,7 @@ export const HSObservationShapeSchema: JSONSchema6forRdf = { required: ['@id', '@type', 'product', 'parsedAt', 'totalSales'], }; -export const ProductCardShapeSchemaForCardsList: JSONSchema6forRdf = { +export const ProductCardShapeSchemaForCardsList: JSONSchema7_LD = { $schema: 'http://json-schema.org/draft-07/schema#', '@id': 'iot:ProductCardShapeForCardsList', '@type': 'sh:NodeShape', @@ -835,7 +835,7 @@ export const ProductCardShapeSchemaForCardsList: JSONSchema6forRdf = { required: ['@id', '@type', 'name', 'lastMonthSalesValue', 'hasObservations'], }; -export const HSObservationShapeSchemaForCardsList: JSONSchema6forRdf = { +export const HSObservationShapeSchemaForCardsList: JSONSchema7_LD = { $schema: 'http://json-schema.org/draft-07/schema#', '@id': 'iot:HSObservationShapeForCardsList', '@type': 'sh:NodeShape',