diff --git a/README.md b/README.md index 0ca4571..3bad17f 100644 --- a/README.md +++ b/README.md @@ -3,53 +3,105 @@ It is an intelligent SPARQL Client with SHACL Shapes support. You could use JSON objects and JSON Schemas to query SPARQL Endpoint, semi-similar to GraphQL style. Some core features requires: + - RDF4J REST API in addition to standard SPARQL 1.1 Query and SPARQL 1.1 Update. - SHACL Shapes for rdfs classes in server RDF repository. ## Features + - Retrieves lazily SPARQL Prefixes (namespaces) from server (requires RDF4J REST API) -- Retrieves lazily SHACL Shapes from server, converts it into JSON Schems and UI Schems and caches them +- Retrieves lazily SHACL Shapes from server, converts it into JSON Schemas and UI Schemas and caches them - Uses JS objects and JSON Schemas (converted from shapes) to generate SPARQL Select Queries and SPARQL Update queries - Converts SPARQL Results into JS objects for consumption in apps -- Have API server RDF repository creation and deletion (requires RDF4J REST API) +- Have API server RDF repository creation and deletion (requires RDF4J REST API) - Supports bulk-load data from local files to server RDF repository (requires RDF4J REST API) ## Usage +### RDF4J Repository Creation and Data Uploading (low level, without MST) + ```typescript -const provider = new ObjectProviderImpl(); -provider.setUser('users:guest'); -const client = provider.getClient(); -client.setServerUrl(''); -await client.createRepositoryAndSetCurrent( {'Repository ID': 'myrepo'} ); -await uploadFiles(client, files, rootFolder); +import { SparqlClientImpl, uploadFiles } from '@agentlab/sparql-jsld-client'; -//select all objects by schema (by rdfs class) -const artifacts = await provider.selectObjects('rm:Artifact'); +const client = new SparqlClientImpl('http://localhost:8181/rdf4j-server'); +await client.createRepositoryAndSetCurrent({ "Repository ID": "reqs2" }, 'native-rdfs-dt); + +const files = [ + { + file: 'vocabs/rm.ttl', + baseURI: '', + }, + { + file: 'shapes/shacl/rm/rm-shapes.ttl', + baseURI: '', + }, + { + file: 'data/cpgu/sample-collection.ttl', + baseURI: '', + }, +]; +await uploadFiles(client, files, './test/data/'); +``` + +### RDF4J Client SPARQL Queries (low level, without MST) + +```typescript +const results = await client.sparqlSelect('SELECT * WHERE ?s ?p ?o'); +``` + +### Reactive Collections (with MST and SPARQL Queries Generation) -//select all objects by schema (by rdfs class) with explisit schema object -const artifactSchema = await provider.getSchemaByUri('rm:Artifact'); -const artifacts2 = await provider.selectObjects(artifactSchema); +```typescript +import { MstRepository, rootModelInitialState } from '@agentlab/sparql-jsld-client'; -//select all objects by schema and conditions -const artifact30000 = await provider.selectObjectsWithTypeInfo(artifactSchema, { identifier: 30000 }); -const artifactsFromFolder = await provider.selectObjects(artifactSchema, { assetFolder: 'folders:samples_module' }); +const repository = MstRepository.create(rootModelInitialState, { client }); // client -- the same SparqlClientImpl instance +repository.setId('reqs2'); + +//select all objects by schema (by rdfs class) +const coll = repository.addColl('rm:ArtifactShape'); +await coll.loadColl(); +const dataJs: JsObject[] = coll.dataJs; +console.log(dataJs); + +//select all objects by schema and conditions and process it reactively +const coll2 = repository.addColl({ + entConstrs: [ + { + schema: 'rm:ArtifactShape', + conditions: { + identifier: 30000, + }, + }, + ], +}); +when( + () => coll2 !== undefined && coll2.data.length > 0, + () => { + const dataJs2: JsObject[] = coll2.dataJs; + console.log(dataJs2); + repository.removeColl(coll2); // cleanup to save some memory + }, +); ``` ## Local Development -This project was bootstrapped with [TSDX](https://github.com/jaredpalmer/tsdx). +Use pnpm. + +To to override the default settings from .env.test create file .env.test.local (git-ignored). For single test run + ```bash -yarn test -- -t "should select namespaces" +pnpm test -- -t "should select namespaces" ``` For single testsuite run + ```bash -yarn test SparqlClient.spec.ts +pnpm test SparqlClient.spec.ts ``` ## License -- [Eclipse Public License 2.0](LICENSE) +- [GPL 3.0](LICENSE) diff --git a/src/models/Model.ts b/src/models/Model.ts index f1d5fab..dee6ce9 100644 --- a/src/models/Model.ts +++ b/src/models/Model.ts @@ -19,18 +19,18 @@ import { MstRepository } from './MstRepository'; export const rootModelInitialState: any = { repId: '', user: { - //'@id': 'mailto:guest@example.com',// login: 'guest@example.com', name: 'Guest', }, processArea: 'projects:gishbbProject', ns: { current: { - rdfs: 'http://www.w3.org/2000/01/rdf-schema#', rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', + rdfs: 'http://www.w3.org/2000/01/rdf-schema#', xsd: 'http://www.w3.org/2001/XMLSchema#', - sesame: 'http://www.openrdf.org/schema/sesame#', - aldkg: 'https://agentlab.ru/ldkg/onto#', + sesame: 'http://www.openrdf.org/schema/sesame#', //rdf4j DirectType Inferencer sesame:directSubClassOf + rdf4j: 'http://rdf4j.org/schema/rdf4j#', //rdf4j Default Graph rdf4j:nil, rdf4j:SHACLShapeGraph + aldkg: 'https://agentlab.eu/ldkg/onto#', }, }, schemas: { diff --git a/src/models/MstColl.ts b/src/models/MstColl.ts index 241bb12..915647c 100644 --- a/src/models/MstColl.ts +++ b/src/models/MstColl.ts @@ -11,6 +11,7 @@ import dayjs from 'dayjs'; import { isEqual } from 'lodash-es'; import { reaction } from 'mobx'; import { + applySnapshot, types, Instance, flow, @@ -144,7 +145,7 @@ export const MstColl = types /** * Views */ - .views((self: any) => { + .views((self) => { return { /** * Returns collection objects @@ -163,15 +164,15 @@ export const MstColl = types return self.dataIntrnl; }, get dataJs() { - return getSnapshot(this.data); + return getSnapshot(this.data); }, dataByIri(iri: string) { - return self.dataIntrnl.find((e: any) => { + return self.dataIntrnl.find((e) => { // should take care of different element type API differences const eType = getType(e); if (isMapType(eType)) return e.get('@id') === iri; // [] returns undef in MST Map - if (isModelType(eType)) return e['@id'] === iri; // .get() returns exception in MST Model - const eSnp: any = getSnapshot(e); // MST Frozen??? + if (isModelType(eType)) return (e as any)['@id'] === iri; // .get() returns exception in MST Model + const eSnp = getSnapshot(e); // MST Frozen??? return eSnp['@id'] === iri; }); }, @@ -180,7 +181,7 @@ export const MstColl = types /** * Actions */ - .actions((self: any) => { + .actions((self) => { const rep: IAnyStateTreeNode = getRoot(self); const client = getEnv(self).client; let dispose: any; @@ -197,7 +198,7 @@ export const MstColl = types dispose = reaction( () => { const collConstr = self.collConstr; - const collConstrJs = getSnapshot(collConstr); + const collConstrJs = collConstr ? getSnapshot(collConstr) : undefined; //console.log('Coll reaction', collConstrJs); return collConstrJs; }, @@ -256,8 +257,8 @@ export const MstColl = types rep.ns.currentJs, client, ); - if (objects === null) self.dataIntrnl = []; - else self.dataIntrnl = objects; + if (objects === null) applySnapshot(self.dataIntrnl, []); + else applySnapshot(self.dataIntrnl, objects); //schema: {}, //selectQuery: '', self.lastSynced = dayjs().valueOf(); diff --git a/src/models/MstCollConstr.ts b/src/models/MstCollConstr.ts index 82f406f..3b33e62 100644 --- a/src/models/MstCollConstr.ts +++ b/src/models/MstCollConstr.ts @@ -88,7 +88,7 @@ export const MstEntConstr = types */ resolveType: types.maybe(types.boolean), }) - .views((self: any) => { + .views((self) => { return { get schemaJs() { return self.schema ? getSnapshot(self.schema) : undefined; @@ -104,7 +104,7 @@ export const MstEntConstr = types }, }; }) - .actions((self: any) => { + .actions((self) => { //let disp: any; return { /*afterAttach() { @@ -166,7 +166,7 @@ export const MstCollConstr = types /** * Views */ - .views((self: any) => { + .views((self) => { const rep: IAnyStateTreeNode = getRoot(self); const client = getEnv(self).client; return { @@ -191,7 +191,7 @@ export const MstCollConstr = types /** * Actions */ - .actions((self: any) => { + .actions((self) => { let disp: any; return { /*afterAttach() { diff --git a/src/models/MstRepository.ts b/src/models/MstRepository.ts index 4cd0ae3..878d577 100644 --- a/src/models/MstRepository.ts +++ b/src/models/MstRepository.ts @@ -68,10 +68,10 @@ export const MstRepository = types if (!coll) return undefined; const id = self.selectedData.get(iri); if (id) { - let data = coll.dataByIri(id); - if (data) data = getSnapshot(data); - return data; + const data = coll.dataByIri(id); + if (data) return getSnapshot(data); } + return undefined; }, }; }) diff --git a/test/Artifact.spec.ts b/test/Artifact.spec.ts index 0433bb8..3e82c16 100644 --- a/test/Artifact.spec.ts +++ b/test/Artifact.spec.ts @@ -8,6 +8,7 @@ * SPDX-License-Identifier: GPL-3.0-only ********************************************************************************/ import { afterAll, beforeAll, describe, expect, jest, it } from '@jest/globals'; +import assert from 'assert'; import { getSnapshot } from 'mobx-state-tree'; import { rootModelInitialState } from '../src/models/Model'; @@ -20,7 +21,7 @@ import { rdfServerUrl, rmRepositoryParam, rmRepositoryType } from './config'; import { vocabsFiles, shapesFiles, usersFiles, projectsFoldersFiles, samplesFiles, rootFolder } from './configTests'; import { textFormatUri } from './schema/TestSchemas'; -import { genTimestampedName, sleep } from './TestHelpers'; +import { expectToBeDefined, genTimestampedName, sleep } from './TestHelpers'; // See https://stackoverflow.com/questions/49603939/async-callback-was-not-invoked-within-the-5000ms-timeout-specified-by-jest-setti jest.setTimeout(500000); @@ -54,8 +55,8 @@ beforeAll(async () => { afterAll(async () => { try { await client.deleteRepository(rmRepositoryID); - } catch (err) { - fail(err); + } catch (err: any) { + assert.fail(err); } }); @@ -83,7 +84,7 @@ describe('create-artifact-scenario', () => { const coll = repository.addColl('rm:ArtifactShape'); await coll.loadColl(); - expect(coll).not.toBeUndefined(); + expectToBeDefined(coll); const data: any[] = coll && coll.data !== undefined ? getSnapshot(coll.data) : []; expect(data.length).toBe(15); diff --git a/test/ArtifactsInModule.spec.ts b/test/ArtifactsInModule.spec.ts index 44ec680..de93363 100644 --- a/test/ArtifactsInModule.spec.ts +++ b/test/ArtifactsInModule.spec.ts @@ -8,6 +8,7 @@ * SPDX-License-Identifier: GPL-3.0-only ********************************************************************************/ import { afterAll, beforeAll, describe, expect, jest, it } from '@jest/globals'; +import assert from 'assert'; import { when } from 'mobx'; import { getSnapshot } from 'mobx-state-tree'; @@ -21,7 +22,7 @@ import { uploadFiles } from '../src/FileUpload'; import { rdfServerUrl, rmRepositoryParam, rmRepositoryType } from './config'; import { vocabsFiles, shapesFiles, usersFiles, projectsFoldersFiles, samplesFiles, rootFolder } from './configTests'; import { artifactSchema, usedInModuleSchema, usedInSchema } from './schema/TestSchemas'; -import { genTimestampedName } from './TestHelpers'; +import { expectToBeDefined, genTimestampedName } from './TestHelpers'; // See https://stackoverflow.com/questions/49603939/async-callback-was-not-invoked-within-the-5000ms-timeout-specified-by-jest-setti jest.setTimeout(50000); @@ -49,16 +50,16 @@ beforeAll(async () => { await uploadFiles(client, samplesFiles, rootFolder); //await sleep(5000); // give RDF classifier some time to classify resources after upload await repository.ns.reloadNs(); - } catch (err) { - fail(err); + } catch (err: any) { + assert.fail(err); } }); afterAll(async () => { try { await client.deleteRepository(rmRepositoryID); - } catch (err) { - fail(err); + } catch (err: any) { + assert.fail(err); } }); @@ -172,11 +173,11 @@ describe('ArtifactsInModules query should return Module UsedInModules with assoc //provider.addSchema(usedInModuleSchema); const coll = repository.addColl(usedInModuleCollConstrJs /*{ lazy: false }*/); - expect(coll).not.toBeUndefined(); + expectToBeDefined(coll); when( - () => coll !== undefined && coll.data.length > 0, + () => coll.data.length > 0, () => { - const linksAndArtifacts: JsObject[] = getSnapshot(coll?.data); + const linksAndArtifacts: JsObject[] = coll.dataJs; expect(linksAndArtifacts.length).toBe(3); expect(linksAndArtifacts[0]).toMatchObject(moduleObject); repository.removeColl(coll); @@ -203,11 +204,11 @@ describe('ArtifactsInModules query should return Module UsedInModules with assoc }, ], }); - expect(coll).not.toBeUndefined(); + expectToBeDefined(coll); when( - () => coll !== undefined && coll.data.length > 0, + () => coll.data.length > 0, () => { - const linksAndArtifacts: JsObject[] = getSnapshot(coll?.data); + const linksAndArtifacts: JsObject[] = coll.dataJs; expect(linksAndArtifacts.length).toBe(3); expect(linksAndArtifacts[0]).toMatchObject({ '@id': 'reqs:_M1HusThYEem2Z_XixsC3pQ', @@ -278,11 +279,11 @@ describe('ArtifactsInModules query should return Module UsedInModules with assoc descending: true, }], }); - expect(coll).not.toBeUndefined(); + expectToBeDefined(coll); when( - () => coll !== undefined && coll.data.length > 0, + () => coll.data.length > 0, () => { - const linksAndArtifacts: JsObject[] = getSnapshot(coll?.data); + const linksAndArtifacts: JsObject[] = coll.dataJs; expect(linksAndArtifacts.length).toBe(3); expect(linksAndArtifacts[0]).toMatchObject({ '@id': 'reqs:_N1HusThYEem2Z_XixsC3pQ', @@ -330,11 +331,11 @@ describe('ArtifactsInModules query should return Module UsedInModules with assoc } ], }); - expect(coll).not.toBeUndefined(); + expectToBeDefined(coll); when( - () => coll !== undefined && coll.data.length > 0, + () => coll.data.length > 0, () => { - const linksAndArtifacts: JsObject[] = getSnapshot(coll?.data); + const linksAndArtifacts: JsObject[] = coll.dataJs; expect(linksAndArtifacts.length).toBe(3); expect(linksAndArtifacts[0]).toMatchObject({ depth: 6, @@ -418,13 +419,13 @@ const usedInModuleChildCollConstrJs: any = { describe('RetrieveModuleWithParent', () => { it('RetrieveModuleWithParent should sync load', async () => { const coll1 = repository.addColl(usedInModuleParentCollConstrJs); - expect(coll1).not.toBeUndefined(); + expectToBeDefined(coll1); const coll2 = repository.addColl(usedInModuleChildCollConstrJs); - expect(coll2).not.toBeUndefined(); + expectToBeDefined(coll2); await coll2.loadColl(); - const data: any = coll2 && coll2.data !== undefined ? getSnapshot(coll2.data) : []; + const data: any = coll2.dataJs; expect(data.length).toBe(3); expect(data[0]).toMatchObject(moduleObject); diff --git a/test/SimpleRetrieve.spec.ts b/test/SimpleRetrieve.spec.ts index 8638b88..963c517 100644 --- a/test/SimpleRetrieve.spec.ts +++ b/test/SimpleRetrieve.spec.ts @@ -8,6 +8,7 @@ * SPDX-License-Identifier: GPL-3.0-only ********************************************************************************/ import { afterAll, beforeAll, describe, expect, jest, it } from '@jest/globals'; +import assert from 'assert'; import { when } from 'mobx'; import { getSnapshot } from 'mobx-state-tree'; @@ -19,7 +20,7 @@ import { uploadFiles } from '../src/FileUpload'; import { rdfServerUrl, rmRepositoryParam, rmRepositoryType } from './config'; import { vocabsFiles, shapesFiles, usersFiles, projectsFoldersFiles, samplesFiles, rootFolder } from './configTests'; -import { genTimestampedName, selectHelper } from './TestHelpers'; +import { expectToBeDefined, genTimestampedName, selectHelper } from './TestHelpers'; // See https://stackoverflow.com/questions/49603939/async-callback-was-not-invoked-within-the-5000ms-timeout-specified-by-jest-setti jest.setTimeout(5000000); @@ -47,16 +48,16 @@ beforeAll(async () => { await uploadFiles(client, shapesFiles, rootFolder); //await sleep(5000); // give RDF classifier some time to classify resources after upload await repository.ns.reloadNs(); - } catch (err) { - fail(err); + } catch (err: any) { + assert.fail(err); } }); afterAll(async () => { try { await client.deleteRepository(rmRepositoryID); - } catch (err) { - fail(err); + } catch (err: any) { + assert.fail(err); } }); @@ -405,7 +406,7 @@ describe('RetrieveWithParent', () => { }, ], }); - expect(coll1).not.toBeUndefined(); + expectToBeDefined(coll1); const coll2 = repository.addColl({ '@id': 'rm:collConstr2', @@ -419,10 +420,10 @@ describe('RetrieveWithParent', () => { ], limit: 10, }); - expect(coll2).not.toBeUndefined(); + expectToBeDefined(coll2); await coll2.loadColl(); - const data: any = coll2 && coll2.data !== undefined ? getSnapshot(coll2.data) : []; + const data = coll2.dataJs; expect(data.length).toBe(1); expect(data[0]).toMatchObject(artifact30000Orig); @@ -455,26 +456,26 @@ describe('LoadMore', () => { }, { pageSize: 10 }, ); - expect(coll).not.toBeUndefined(); + expectToBeDefined(coll); await coll.loadColl(); - const data: any = coll && coll.data !== undefined ? getSnapshot(coll.data) : []; + const data = coll.dataJs; expect(data.length).toBe(2); // load another page=10 await coll.loadMore(); - const data2: any = coll && coll.data !== undefined ? getSnapshot(coll.data) : []; + const data2 = coll.dataJs; expect(data2.length).toBe(12); - data.forEach((el: any, i: any) => expect(data2[i]).toEqual(el)); + data.forEach((el, i) => expect(data2[i]).toEqual(el)); data2.slice(data.length).forEach((el: any) => expect(data).not.toContainEqual(el)); // load another 5 (the rest of it) await coll.loadMore(); - const data3: any = coll && coll.data !== undefined ? getSnapshot(coll.data) : []; + const data3 = coll.dataJs; expect(data3.length).toBe(15); // check empty load await coll.loadMore(); - const data4: any = coll && coll.data !== undefined ? getSnapshot(coll.data) : []; + const data4 = coll.dataJs; expect(data4.length).toBe(15); repository.removeColl(coll); @@ -493,14 +494,14 @@ describe('LoadMore', () => { }, { pageSize: 10 }, ); - expect(coll).not.toBeUndefined(); + expectToBeDefined(coll); const disp1 = when( - () => coll !== undefined && coll.data.length === 10, + () => coll.data.length === 10, () => { disp1(); const disp2 = when( - () => coll !== undefined && coll.data.length === 15, + () => coll.data.length === 15, () => { disp2(); repository.removeColl(coll); diff --git a/test/SparqlClient.spec.ts b/test/SparqlClient.spec.ts index da0ce5b..dda5ac9 100644 --- a/test/SparqlClient.spec.ts +++ b/test/SparqlClient.spec.ts @@ -8,6 +8,7 @@ * SPDX-License-Identifier: GPL-3.0-only ********************************************************************************/ import { afterAll, beforeAll, describe, expect, jest, it } from '@jest/globals'; +import assert from 'assert'; import { compact, ContextDefinition } from 'jsonld'; import { rootModelInitialState } from '../src/models/Model'; @@ -51,38 +52,38 @@ beforeAll(async () => { await uploadFiles(client, projectsFoldersFiles, rootFolder); await uploadFiles(client, samplesFiles, rootFolder); await uploadFiles(client, shapesFiles, rootFolder); - } catch (error: any) { - if (error.response) { + } catch (err: any) { + if (err.response) { // Request made and server responded - console.log(error.response.data); - console.log(error.response.status); - console.log(error.response.headers); - } else if (error.request) { + console.log(err.response.data); + console.log(err.response.status); + console.log(err.response.headers); + } else if (err.request) { // The request was made but no response was received - const s = error.request; - console.log(error.request); + const s = err.request; + console.log(err.request); } else { // Something happened in setting up the request that triggered an Error - console.log('Error', error.message); + console.log('Error', err.message); } - fail(error); + assert.fail(err); } }); afterAll(async () => { try { await client.deleteRepository(rmRepositoryID); - } catch (err) { - fail(err); + } catch (err: any) { + assert.fail(err); } }); describe('SparqlClient', () => { it(`SparqlClient should select namespaces`, async () => { - expect(repository.ns.current.size).toBe(5); + expect(repository.ns.current.size).toBe(6); await repository.ns.reloadNs(); //console.log(getSnapshot(repository.ns.current)); - expect(repository.ns.current.size).toBeGreaterThan(5); + expect(repository.ns.current.size).toBeGreaterThan(6); const ns = repository.ns.currentJs; expect(ns.rdf).toBe('http://www.w3.org/1999/02/22-rdf-syntax-ns#'); diff --git a/test/SparqlGen.spec.ts b/test/SparqlGen.spec.ts index 24e364a..0fdd568 100644 --- a/test/SparqlGen.spec.ts +++ b/test/SparqlGen.spec.ts @@ -27,6 +27,7 @@ import { import { testNs } from './configTests'; import { ArtifactShapeSchema, PropertyShapeSchema } from '../src/schema/ArtifactShapeSchema'; +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); @@ -697,7 +698,7 @@ describe('constructObjectsQuery', () => { orderBy: [{ expression: factory.variable('parsedAt0'), descending: false }], }; const coll = await constructObjectsQuery(collConstrJs, testNs, client); - expect(coll).not.toBeUndefined(); + expectToBeDefined(coll); //expect(coll.length).toBe(0); const genQueryStr = client.sparqlConstructParams.query; //console.log(genQueryStr); @@ -745,7 +746,7 @@ describe('constructObjectsQuery', () => { orderBy: [{ expression: factory.variable('parsedAt0'), descending: false }], }; const coll = await constructObjectsQuery(collConstrJs, testNs, client); - expect(coll).not.toBeUndefined(); + expectToBeDefined(coll); //expect(coll.length).toBe(0); const genQueryStr = client.sparqlConstructParams.query; //console.log(genQueryStr); @@ -792,7 +793,7 @@ describe('constructObjectsQuery', () => { ], }; const coll = await constructObjectsQuery(collConstrJs, testNs, client); - expect(coll).not.toBeUndefined(); + expectToBeDefined(coll); //expect(coll.length).toBe(0); const genQueryStr = client.sparqlConstructParams.query; //console.log(genQueryStr); @@ -858,7 +859,7 @@ describe('constructObjectsQuery', () => { ], }; const coll = await constructObjectsQuery(collConstrJs, testNs, client); - expect(coll).not.toBeUndefined(); + expectToBeDefined(coll); //expect(coll.length).toBe(0); const genQueryStr = client.sparqlConstructParams.query; //console.log(genQueryStr); @@ -946,7 +947,7 @@ describe('constructObjectsQuery', () => { ], }; const coll = await constructObjectsQuery(collConstrJs, testNs, client); - expect(coll).not.toBeUndefined(); + expectToBeDefined(coll); //expect(coll.length).toBe(0); const genQueryStr = client.sparqlConstructParams.query; console.log(genQueryStr); @@ -1175,7 +1176,7 @@ describe('updateObjectQuery', () => { async function selectTestHelper(collConstrJs: ICollConstrJsOpt, correctQuery: string) { const client = new SparqlClientImplMock(); const coll = await selectObjectsQuery(collConstrJs, testNs, client); - expect(coll).not.toBeUndefined(); + expectToBeDefined(coll); //expect(coll.length).toBe(0); const genQueryStr = client.sparqlSelectParams.query; //console.log(genQueryStr); @@ -1187,7 +1188,7 @@ async function selectTestHelper(collConstrJs: ICollConstrJsOpt, correctQuery: st async function constructTestHelper(collConstrJs: ICollConstrJsOpt, correctQuery: string) { const client = new SparqlClientImplMock(); const coll = await constructObjectsQuery(collConstrJs, testNs, client); - expect(coll).not.toBeUndefined(); + expectToBeDefined(coll); //expect(coll.length).toBe(0); const genQueryStr = client.sparqlConstructParams.query; //console.log(genQueryStr); diff --git a/test/SubQueries.spec.ts b/test/SubQueries.spec.ts index c718569..c6dc03c 100644 --- a/test/SubQueries.spec.ts +++ b/test/SubQueries.spec.ts @@ -28,7 +28,7 @@ import { usedInModuleSchema, usedInSchema, } from './schema/TestSchemas'; -import { genTimestampedName } from './TestHelpers'; +import { expectToBeDefined, genTimestampedName } from './TestHelpers'; // See https://stackoverflow.com/questions/49603939/async-callback-was-not-invoked-within-the-5000ms-timeout-specified-by-jest-setti jest.setTimeout(50000); @@ -39,7 +39,7 @@ const client = new SparqlClientImpl( ); client.setRepositoryId('mktp-fed20'); -describe('SubQueries should work', () => { +describe.skip('SubQueries should work', () => { it('SubQueries ProductCards', async () => { const result = await client.sparqlSelect( `PREFIX hs: @@ -118,7 +118,7 @@ describe('SubQueries should work', () => { }); }); -describe('Retrieve subqueries', () => { +describe.skip('Retrieve subqueries', () => { const client = new SparqlClientImpl( 'https://rdf4j.agentlab.ru/rdf4j-server', 'https://rdf4j.agentlab.ru/rdf4j-server/repositories/mktp-schema20/namespaces', @@ -157,7 +157,7 @@ describe('Retrieve subqueries', () => { { expression: factory.variable('parsedAt1'), descending: false }, ], }); - expect(coll1).not.toBeUndefined(); + expectToBeDefined(coll1); await coll1.loadColl(); const data: any = coll1.dataJs; expect(data.length).toBe(2); @@ -183,7 +183,7 @@ describe('Retrieve subqueries', () => { ], orderBy: [{ expression: factory.variable('parsedAt0'), descending: false }], }); - expect(coll1).not.toBeUndefined(); + expectToBeDefined(coll1); await coll1.loadColl(); const data: any = coll1.dataJs; expect(data.length).toBeGreaterThan(10); @@ -194,7 +194,7 @@ describe('Retrieve subqueries', () => { it('should return ProductCardCardsListShape schema with reverse property', async () => { let schema = await repository.schemas.loadSchemaByIri('hs:ProductCardCardsListShape'); schema = getSnapshot(schema); - expect(schema).not.toBeUndefined(); + expectToBeDefined(schema); }); it('Retrieve HSObservation-of-ProductCards with remote schema', async () => { @@ -225,7 +225,7 @@ describe('Retrieve subqueries', () => { { expression: factory.variable('parsedAt1'), descending: false }, ], }); - expect(coll1).not.toBeUndefined(); + expectToBeDefined(coll1); await coll1.loadColl(); const data: any = coll1.dataJs; expect(data.length).toBe(2); diff --git a/test/schema/ArtifactShapeSchema.spec.ts b/test/schema/ArtifactShapeSchema.spec.ts index 0c4964f..a4dd832 100644 --- a/test/schema/ArtifactShapeSchema.spec.ts +++ b/test/schema/ArtifactShapeSchema.spec.ts @@ -7,6 +7,9 @@ * * SPDX-License-Identifier: GPL-3.0-only ********************************************************************************/ +import { afterAll, beforeAll, describe, expect, jest, it } from '@jest/globals'; +import assert from 'assert'; + import { rootModelInitialState } from '../../src/models/Model'; import { MstRepository } from '../../src/models/MstRepository'; import { createSchemaWithSubClassOf, resolveSchemaFromServer } from '../../src/models/MstSchemas'; @@ -42,16 +45,16 @@ beforeAll(async () => { const files = vocabsFiles.concat(shapesFiles); await uploadFiles(client, files, rootFolder); await repository.ns.reloadNs(); - } catch (err) { - fail(err); + } catch (err: any) { + assert.fail(err); } }); afterAll(async () => { try { await client.deleteRepository(rmRepositoryID); - } catch (err) { - fail(err); + } catch (err: any) { + assert.fail(err); } });