UNPKG

@dasch-swiss/dsp-js

Version:

JavaScript library that handles API requests to Knora

46 lines 2.6 kB
import { JsonConvert, OperationMode, ValueCheckingMode } from "json2typescript"; import { PropertyMatchingRule } from "json2typescript/src/json2typescript/json-convert-enums"; import { forkJoin, of } from "rxjs"; import { map } from "rxjs"; import { V2Endpoint } from "../../../../src/api/v2/v2-endpoint"; import { ListNodeV2Cache } from "../../../../src/cache/ListNodeV2Cache"; import { OntologyCache } from "../../../../src/cache/ontology-cache/OntologyCache"; import { KnoraApiConfig } from "../../../../src/knora-api-config"; import { ReadResourceSequence } from "../../../../src/models/v2/resources/read/read-resource-sequence"; import { ResourcesConversionUtil } from "../../../../src/models/v2/resources/ResourcesConversionUtil"; import testthing from "../v2/resources/testding-expanded.json"; import { MockList } from "./mock-list"; import { MockOntology } from "./mock-ontology"; export var MockResource; (function (MockResource) { var jsonConvert = new JsonConvert(OperationMode.ENABLE, ValueCheckingMode.DISALLOW_NULL, false, PropertyMatchingRule.CASE_STRICT); MockResource.getTestThing = function () { var config = new KnoraApiConfig("http", ""); var v2Endpoint = new V2Endpoint(config, ""); var ontoCache = new OntologyCache(config, v2Endpoint); var listNodeCache = new ListNodeV2Cache(v2Endpoint); // replace actual cache methods with class to existing mock factories // use ontology mock factory ontoCache.getResourceClassDefinition = function (resClassIri) { var mock = MockOntology.mockIResourceClassAndPropertyDefinitions(resClassIri); return of(mock); }; // use list node mock factory listNodeCache.getNode = function (listNodeIri) { return of(MockList.mockNode(listNodeIri)); }; var resSeq = ResourcesConversionUtil.createReadResourceSequence(testthing, ontoCache, listNodeCache, jsonConvert); return resSeq.pipe(map(function (seq) { return seq.resources[0]; })); }; MockResource.getTestThings = function (length, mayHaveMoreResults) { if (length === void 0) { length = 25; } if (mayHaveMoreResults === void 0) { mayHaveMoreResults = false; } var resources = new Array(length).fill(0).map(function () { return MockResource.getTestThing(); }); return forkJoin(resources).pipe(map(function (res) { return new ReadResourceSequence(res, mayHaveMoreResults); })); }; })(MockResource || (MockResource = {})); //# sourceMappingURL=mock-resource.js.map