Skip to content

Commit

Permalink
Paging: Make ReadResource[] a ReadResourceSequence (#169)
Browse files Browse the repository at this point in the history
* feature (paging): make ReadResource[] a ReadResourceSequence

* feature (paging): check for mayHaveMoreResults

* refactor (resources): remove console log

* fix (test framework): adapt to changes in public API

* chore (makefile): check out Knora PR branch

* fix (test framework): adapt assertions

* Revert "fix (test framework): adapt assertions"

This reverts commit fbbdc65.

* fix (makefile): remove branch option for git clone

* tests (resource conversion): adapt assertion

* docs (resource seq): add some doc strings

* fix (mock resource): fix return type of mock resource

* fix (mock resource): fix return type of mock resource

* chore (release): prepare changelog

* chore (release): fix changelog

* test (github-ci): curl should fail if answer not successful
  • Loading branch information
tobiasschweizer authored May 7, 2020
1 parent 3fefb80 commit 65b15ec
Show file tree
Hide file tree
Showing 21 changed files with 774 additions and 270 deletions.
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 1.0.0-rc.0

### Features
- add support for time value ([#59](https://github.com/dasch-swiss/knora-api-js-lib/pull/59))
- add util for handling of cardinalities ([#144](https://github.com/dasch-swiss/knora-api-js-lib/pull/144))
- add util for handling of permissions ([#142](https://github.com/dasch-swiss/knora-api-js-lib/pull/142))
- add uuid to update responses ([#151](https://github.com/dasch-swiss/knora-api-js-lib/pull/151))
- add util to determine link prop from link value prop ([#163](https://github.com/dasch-swiss/knora-api-js-lib/pull/163))

### Bug Fixes
- add time value to public API ([#150](https://github.com/dasch-swiss/knora-api-js-lib/pull/150))
- add geoname value to public API ([#158](https://github.com/dasch-swiss/knora-api-js-lib/pull/158))
- add property definition to public API ([#166](https://github.com/dasch-swiss/knora-api-js-lib/pull/166))
- add missing decorator for json2typescript ([#173](https://github.com/dasch-swiss/knora-api-js-lib/pull/173))
- update to json2typescript 1.4.1 (previous version of json2typescript had a bug) ([#160](https://github.com/dasch-swiss/knora-api-js-lib/pull/160))
- fix wrong internal import path to RxJS ([#175](https://github.com/dasch-swiss/knora-api-js-lib/pull/175))
- add missing classes to public API ([#174](https://github.com/dasch-swiss/knora-api-js-lib/pull/174))
- make RxJS a peer dependency ([#176](https://github.com/dasch-swiss/knora-api-js-lib/pull/176))
- add delete resource response to public API ([#178](https://github.com/dasch-swiss/knora-api-js-lib/pull/178))
- use consistent naming convention for v2 and admin endpoints ([#179](https://github.com/dasch-swiss/knora-api-js-lib/pull/179))

### Breaking Changes
- return multiple resources as `ReadResourceSequence` (instead of ReadResource[]) with a flag indicating whether there could be more results ([#169](https://github.com/dasch-swiss/knora-api-js-lib/pull/169))
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ knora-stack: ## runs the knora-stack
generate-test-data: ## downloads generated test data from Knora-API
@rm -rf $(CURRENT_DIR)/.tmp/typescript
mkdir -p $(CURRENT_DIR)/.tmp/typescript
sleep 90
curl -o $(CURRENT_DIR)/.tmp/ts.zip http://localhost:3333/clientapitest
sleep 120
curl --fail -o $(CURRENT_DIR)/.tmp/ts.zip http://localhost:3333/clientapitest
sleep 45
unzip $(CURRENT_DIR)/.tmp/ts.zip -d $(CURRENT_DIR)/.tmp/typescript

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"build": "rm -rf build/* && tsc && mkdir -p build/ && cp CHANGELOG.md build/ && cp LICENSE build/ && cp README.md build/ && cp package.json build/",
"yalc-publish": "npm run build && yalc publish build/ --push",
"npm-pack": "npm run test && npm run build && npm pack build/ && mkdir -p dist/ && cp *.tgz dist/ && rm *.tgz",
"npm-publish": "npm run npm-pack && npm publish build/ --dry-run",
"npm-publish": "npm run npm-pack && npm publish --tag rc build/ --dry-run",
"prepare-dev-publication": "node scripts/prepare-dev-publication.js",
"builddocs": "typedoc --out docs --readme none --name '@knora/api API Documentation' --exclude \"**/*.spec.*\" src/*.ts",
"peer-deps": "npm i rxjs@6.x --no-save"
Expand Down
4 changes: 4 additions & 0 deletions scripts/v2-test-data-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
"source": "/v2/search/things.json",
"destination": "./test/data/api/v2/resources/things.json"
},
{
"source": "/v2/search/things-with-paging.json",
"destination": "./test/data/api/v2/resources/things-with-paging.json"
},
{
"source": "/v2/lists/treelist.json",
"destination": "./test/data/api/v2/lists/treelist.json"
Expand Down
7 changes: 4 additions & 3 deletions src/api/v2/resource/resources-endpoint-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CreateResource } from "../../../models/v2/resources/create/create-resou
import { DeleteResource } from "../../../models/v2/resources/delete/delete-resource";
import { DeleteResourceResponse } from "../../../models/v2/resources/delete/delete-resource-response";
import { ReadResource } from "../../../models/v2/resources/read/read-resource";
import { ReadResourceSequence } from "../../../models/v2/resources/read/read-resource-sequence";
import { ResourcesConversionUtil } from "../../../models/v2/resources/ResourcesConversionUtil";
import { UpdateResourceMetadata } from "../../../models/v2/resources/update/update-resource-metadata";
import { UpdateResourceMetadataResponse } from "../../../models/v2/resources/update/update-resource-metadata-response";
Expand All @@ -30,7 +31,7 @@ export class ResourcesEndpointV2 extends Endpoint {
*
* @param resourceIris Iris of the resources to get.
*/
getResources(resourceIris: string[]): Observable<ReadResource[] | ApiResponseError> {
getResources(resourceIris: string[]): Observable<ReadResourceSequence | ApiResponseError> {
// TODO: Do not hard-code the URL and http call params, generate this from Knora

// make URL containing resource Iris as segments
Expand Down Expand Up @@ -63,7 +64,7 @@ export class ResourcesEndpointV2 extends Endpoint {
*/
getResource(resourceIri: string): Observable<ReadResource | ApiResponseError> {
return this.getResources([resourceIri]).pipe(
map((resources: ReadResource[]) => resources[0]),
map((resources: ReadResourceSequence) => resources.resources[0]),
catchError(error => {
return this.handleError(error);
})
Expand Down Expand Up @@ -110,7 +111,7 @@ export class ResourcesEndpointV2 extends Endpoint {
// console.log(JSON.stringify(jsonldobj));
return ResourcesConversionUtil.createReadResourceSequence(jsonldobj, this.v2Endpoint.ontologyCache, this.v2Endpoint.listNodeCache, this.jsonConvert);
}),
map((resources: ReadResource[]) => resources[0]),
map((resources: ReadResourceSequence) => resources.resources[0]),
catchError(error => {
return this.handleError(error);
})
Expand Down
5 changes: 3 additions & 2 deletions src/api/v2/resource/resources-endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CreateResource } from "../../../models/v2/resources/create/create-resou
import { DeleteResource } from "../../../models/v2/resources/delete/delete-resource";
import { DeleteResourceResponse } from "../../../models/v2/resources/delete/delete-resource-response";
import { ReadResource } from "../../../models/v2/resources/read/read-resource";
import { ReadResourceSequence } from "../../../models/v2/resources/read/read-resource-sequence";
import { UpdateResourceMetadata } from "../../../models/v2/resources/update/update-resource-metadata";
import { UpdateResourceMetadataResponse } from "../../../models/v2/resources/update/update-resource-metadata-response";
import { CreateBooleanValue } from "../../../models/v2/resources/values/create/create-boolean-value";
Expand Down Expand Up @@ -87,9 +88,9 @@ describe("ResourcesEndpoint", () => {

it("should return several resource", done => {

knoraApiConnection.v2.res.getResources(["http://rdfh.ch/0001/H6gBWUuJSuuO-CilHV8kQw", "http://rdfh.ch/0001/uqmMo72OQ2K2xe7mkIytlg"]).subscribe((response: ReadResource[]) => {
knoraApiConnection.v2.res.getResources(["http://rdfh.ch/0001/H6gBWUuJSuuO-CilHV8kQw", "http://rdfh.ch/0001/uqmMo72OQ2K2xe7mkIytlg"]).subscribe((response: ReadResourceSequence) => {

expect(response.length).toEqual(2);
expect(response.resources.length).toEqual(2);

done();
});
Expand Down
7 changes: 4 additions & 3 deletions src/api/v2/search/search-endpoint-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { catchError, map, mergeMap } from "rxjs/operators";
import { KnoraApiConfig } from "../../../knora-api-config";
import { ApiResponseError } from "../../../models/api-response-error";
import { ReadResource } from "../../../models/v2/resources/read/read-resource";
import { ReadResourceSequence } from "../../../models/v2/resources/read/read-resource-sequence";
import { ResourcesConversionUtil } from "../../../models/v2/resources/ResourcesConversionUtil";
import { CountQueryResponse } from "../../../models/v2/search/count-query-response";
import { Endpoint } from "../../endpoint";
Expand Down Expand Up @@ -122,7 +123,7 @@ export class SearchEndpointV2 extends Endpoint {
* @param offset offset to be used for paging, zero-based.
* @param params parameters for fulltext search, if any.
*/
doFulltextSearch(searchTerm: string, offset = 0, params?: IFulltextSearchParams): Observable<ReadResource[] | ApiResponseError> {
doFulltextSearch(searchTerm: string, offset = 0, params?: IFulltextSearchParams): Observable<ReadResourceSequence | ApiResponseError> {
// TODO: Do not hard-code the URL and http call params, generate this from Knora

return this.httpGet("/search/" + encodeURIComponent(searchTerm) + SearchEndpointV2.encodeFulltextParams(offset, params)).pipe(
Expand Down Expand Up @@ -172,7 +173,7 @@ export class SearchEndpointV2 extends Endpoint {
*
* @param gravsearchQuery the given Gravsearch query.
*/
doExtendedSearch(gravsearchQuery: string): Observable<ReadResource[] | ApiResponseError> {
doExtendedSearch(gravsearchQuery: string): Observable<ReadResourceSequence | ApiResponseError> {
// TODO: Do not hard-code the URL and http call params, generate this from Knora

// TODO: check if content-type have to be set to text/plain
Expand Down Expand Up @@ -224,7 +225,7 @@ export class SearchEndpointV2 extends Endpoint {
* @param offset offset to be used for paging, zero-based.
* @param params parameters for fulltext search, if any.
*/
doSearchByLabel(searchTerm: string, offset = 0, params?: ILabelSearchParams): Observable<ReadResource[] | ApiResponseError> {
doSearchByLabel(searchTerm: string, offset = 0, params?: ILabelSearchParams): Observable<ReadResourceSequence | ApiResponseError> {
// TODO: Do not hard-code the URL and http call params, generate this from Knora

return this.httpGet("/searchbylabel/" + encodeURIComponent(searchTerm) + SearchEndpointV2.encodeLabelParams(offset, params)).pipe(
Expand Down
41 changes: 21 additions & 20 deletions src/api/v2/search/search-endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MockAjaxCall } from "../../../../test/mockajaxcall";
import { KnoraApiConfig } from "../../../knora-api-config";
import { KnoraApiConnection } from "../../../knora-api-connection";
import { ReadResource } from "../../../models/v2/resources/read/read-resource";
import { ReadResourceSequence } from "../../../models/v2/resources/read/read-resource-sequence";
import { CountQueryResponse } from "../../../models/v2/search/count-query-response";
import { SearchEndpointV2 } from "./search-endpoint-v2";

Expand Down Expand Up @@ -74,9 +75,9 @@ describe("SearchEndpoint", () => {

it("should do a fulltext search with a simple search term", done => {

knoraApiConnection.v2.search.doFulltextSearch("thing", 0).subscribe((response: ReadResource[]) => {
knoraApiConnection.v2.search.doFulltextSearch("thing", 0).subscribe((response: ReadResourceSequence) => {

expect(response.length).toEqual(2);
expect(response.resources.length).toEqual(2);

done();
});
Expand All @@ -95,9 +96,9 @@ describe("SearchEndpoint", () => {

it("should do a fulltext search with a simple search term using offset 1", done => {

knoraApiConnection.v2.search.doFulltextSearch("thing", 1).subscribe((response: ReadResource[]) => {
knoraApiConnection.v2.search.doFulltextSearch("thing", 1).subscribe((response: ReadResourceSequence) => {

expect(response.length).toEqual(2);
expect(response.resources.length).toEqual(2);

done();
});
Expand All @@ -116,9 +117,9 @@ describe("SearchEndpoint", () => {

it("should do a fulltext search with a simple search term restricting the search to a specific resource class", done => {

knoraApiConnection.v2.search.doFulltextSearch("thing", 1, {limitToResourceClass: "http://0.0.0.0:3333/ontology/0001/anything/v2#Thing"}).subscribe((response: ReadResource[]) => {
knoraApiConnection.v2.search.doFulltextSearch("thing", 1, {limitToResourceClass: "http://0.0.0.0:3333/ontology/0001/anything/v2#Thing"}).subscribe((response: ReadResourceSequence) => {

expect(response.length).toEqual(2);
expect(response.resources.length).toEqual(2);

done();
});
Expand All @@ -138,9 +139,9 @@ describe("SearchEndpoint", () => {

it("should do a fulltext search with a simple search term restricting the search to a specific project", done => {

knoraApiConnection.v2.search.doFulltextSearch("thing", 1, {limitToProject: "http://rdfh.ch/projects/0001"}).subscribe((response: ReadResource[]) => {
knoraApiConnection.v2.search.doFulltextSearch("thing", 1, {limitToProject: "http://rdfh.ch/projects/0001"}).subscribe((response: ReadResourceSequence) => {

expect(response.length).toEqual(2);
expect(response.resources.length).toEqual(2);

done();
});
Expand All @@ -160,9 +161,9 @@ describe("SearchEndpoint", () => {

it("should do a fulltext search with a simple search term restricting the search to a specific standoff class", done => {

knoraApiConnection.v2.search.doFulltextSearch("thing", 1, {limitToStandoffClass: "http://api.knora.org/ontology/standoff/v2#StandoffParagraphTag"}).subscribe((response: ReadResource[]) => {
knoraApiConnection.v2.search.doFulltextSearch("thing", 1, {limitToStandoffClass: "http://api.knora.org/ontology/standoff/v2#StandoffParagraphTag"}).subscribe((response: ReadResourceSequence) => {

expect(response.length).toEqual(2);
expect(response.resources.length).toEqual(2);

done();
});
Expand Down Expand Up @@ -223,9 +224,9 @@ describe("SearchEndpoint", () => {
OFFSET 0
`;

knoraApiConnection.v2.search.doExtendedSearch(gravsearchQuery).subscribe((response: ReadResource[]) => {
knoraApiConnection.v2.search.doExtendedSearch(gravsearchQuery).subscribe((response: ReadResourceSequence) => {

expect(response.length).toEqual(2);
expect(response.resources.length).toEqual(2);

done();
});
Expand Down Expand Up @@ -313,9 +314,9 @@ describe("SearchEndpoint", () => {

it("should do a label search with a simple search term", done => {

knoraApiConnection.v2.search.doSearchByLabel("thing", 0).subscribe((response: ReadResource[]) => {
knoraApiConnection.v2.search.doSearchByLabel("thing", 0).subscribe((response: ReadResourceSequence) => {

expect(response.length).toEqual(2);
expect(response.resources.length).toEqual(2);

done();
});
Expand All @@ -334,9 +335,9 @@ describe("SearchEndpoint", () => {

it("should do a label search with a simple search term using offset 1", done => {

knoraApiConnection.v2.search.doSearchByLabel("thing", 1).subscribe((response: ReadResource[]) => {
knoraApiConnection.v2.search.doSearchByLabel("thing", 1).subscribe((response: ReadResourceSequence) => {

expect(response.length).toEqual(2);
expect(response.resources.length).toEqual(2);

done();
});
Expand All @@ -355,9 +356,9 @@ describe("SearchEndpoint", () => {

it("should do a label search with a simple search term restricting the search to a specific resource class", done => {

knoraApiConnection.v2.search.doSearchByLabel("thing", 1, {limitToResourceClass: "http://0.0.0.0:3333/ontology/0001/anything/v2#Thing"}).subscribe((response: ReadResource[]) => {
knoraApiConnection.v2.search.doSearchByLabel("thing", 1, {limitToResourceClass: "http://0.0.0.0:3333/ontology/0001/anything/v2#Thing"}).subscribe((response: ReadResourceSequence) => {

expect(response.length).toEqual(2);
expect(response.resources.length).toEqual(2);

done();
});
Expand All @@ -377,9 +378,9 @@ describe("SearchEndpoint", () => {

it("should do a label search with a simple search term restricting the search to a specific project", done => {

knoraApiConnection.v2.search.doSearchByLabel("thing", 1, {limitToProject: "http://rdfh.ch/projects/0001"}).subscribe((response: ReadResource[]) => {
knoraApiConnection.v2.search.doSearchByLabel("thing", 1, {limitToProject: "http://rdfh.ch/projects/0001"}).subscribe((response: ReadResourceSequence) => {

expect(response.length).toEqual(2);
expect(response.resources.length).toEqual(2);

done();
});
Expand Down
3 changes: 2 additions & 1 deletion src/api/v2/values/values-endpoint-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { catchError, map, mergeMap } from "rxjs/operators";
import { KnoraApiConfig } from "../../../knora-api-config";
import { ApiResponseError } from "../../../models/api-response-error";
import { ReadResource } from "../../../models/v2/resources/read/read-resource";
import { ReadResourceSequence } from "../../../models/v2/resources/read/read-resource-sequence";
import { ResourcesConversionUtil } from "../../../models/v2/resources/ResourcesConversionUtil";
import { UpdateResource } from "../../../models/v2/resources/update/update-resource";
import { CreateFileValue } from "../../../models/v2/resources/values/create/create-file-value";
Expand Down Expand Up @@ -44,7 +45,7 @@ export class ValuesEndpointV2 extends Endpoint {
// console.log(JSON.stringify(jsonldobj));
return ResourcesConversionUtil.createReadResourceSequence(jsonldobj, this.v2Endpoint.ontologyCache, this.v2Endpoint.listNodeCache, this.jsonConvert);
}),
map(resources => resources[0]),
map((resources: ReadResourceSequence) => resources.resources[0]),
catchError(error => {
return this.handleError(error);
})
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export { ResourcePropertyDefinition } from "./models/v2/ontologies/resource-prop
export { PropertyDefinition } from "./models/v2/ontologies/property-definition";
export { ResourceClassDefinition } from "./models/v2/ontologies/resource-class-definition";
export { StandoffClassDefinition } from "./models/v2/ontologies/standoff-class-definition";
export { ReadResourceSequence } from "./models/v2/resources/read/read-resource-sequence";
export { ReadResource } from "./models/v2/resources/read/read-resource";
export { CountQueryResponse } from "./models/v2/search/count-query-response";
export { UpdateResource } from "./models/v2/resources/update/update-resource";
Expand Down
1 change: 1 addition & 0 deletions src/models/v2/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class Constants {

static XMLToStandoffMapping: string = Constants.KnoraApiV2 + Constants.Delimiter + "XMLToStandoffMapping";
static Resource = Constants.KnoraApiV2 + Constants.Delimiter + "Resource";
static MayHaveMoreResults = Constants.KnoraApiV2 + Constants.Delimiter + "mayHaveMoreResults";
static ResourceIcon = Constants.KnoraApiV2 + Constants.Delimiter + "ResourceIcon";
static ForbiddenResource = Constants.KnoraApiV2 + Constants.Delimiter + "ForbiddenResource";
static BooleanValue = Constants.KnoraApiV2 + Constants.Delimiter + "BooleanValue";
Expand Down
Loading

0 comments on commit 65b15ec

Please sign in to comment.