Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rxjs v7.8 (#DEV-3541) #636

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ jobs:
sudo npm install --global @bazel/bazelisk
- name: Install dependencies
run: make npm-install
- name: Get api client test data from knora-api (makefile variant)
run: make get-test-data-from-release
# - name: Copy api client test data from folder
# run: make copy-test-data-from-folder
- name: Prepare test data
run: make prepare-test-data
- name: Run unit tests
Expand Down
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
THIS_FILE := $(lastword $(MAKEFILE_LIST))
CURRENT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))

TEST_DATA_SRC_DIR := $(CURRENT_DIR)/test/
TEST_DATA_FILE := client-test-data.zip

include vars.mk

# Function to get github release asset id and to download client-test-data.zip from knora-api release
Expand Down Expand Up @@ -42,6 +45,12 @@ get-test-data-from-release: ## get the test-data from assets in github release c
@rm -rf client-test-data.zip
@$(call download-test-data,$(API_REPO),$(API_VERSION))

.PHONY: copy-test-data-from-folder
copy-test-data-from-folder:
rm -f $(CURRENT_DIR)/$(TEST_DATA_FILE)
@echo "Copying $(TEST_DATA_FILE) from $(TEST_DATA_SRC_DIR) to $(CURRENT_DIR)"
cp $(TEST_DATA_SRC_DIR)$(TEST_DATA_FILE) $(CURRENT_DIR)/$(TEST_DATA_FILE)

.PHONY: generate-test-data
generate-test-data: ## generate test data from Knora-API
@rm -rf $(CURRENT_DIR)/.tmp/typescript
Expand Down
Binary file added client-test-data.zip
Binary file not shown.
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"prepare-dev-publication": "node scripts/prepare-dev-publication.js",
"build-docs": "typedoc --options typedoc.json src",
"typedoc-config": "node scripts/typedoc-config.js",
"peer-deps": "npm i rxjs@6.x --no-save",
"peer-deps": "npm i rxjs@7.8 --no-save",
"build-local": "npm i && npm run peer-deps && npm run prepare-dev-publication && npm run yalc-publish"
},
"repository": {
Expand Down Expand Up @@ -69,9 +69,10 @@
"@babel/helper-compilation-targets": "^7.16.7",
"@types/jsonld": "^1.5.6",
"json2typescript": "1.4.1",
"jsonld": "^8.1.0"
"jsonld": "^8.1.0",
"rxjs": "^7.8.1"
},
"peerDependencies": {
"rxjs": "6.x"
"rxjs": "^7.8.1"
}
}
}
42 changes: 21 additions & 21 deletions src/api/endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("Test class Endpoint", () => {
const endpoint = new Endpoint(config, "/test");

endpoint["httpGet"]().subscribe(
(response: AjaxResponse) => {
(response: AjaxResponse<any>) => {
expect(response.status).toEqual(200);
expect(response.response).toEqual({test: "test"});

Expand All @@ -46,7 +46,7 @@ describe("Test class Endpoint", () => {
const endpoint = new Endpoint(config, "/test");

endpoint["httpGet"]().subscribe(
(response: AjaxResponse) => {
(response: AjaxResponse<any>) => {
},
err => {
expect(err instanceof Error).toBeTruthy();
Expand All @@ -73,7 +73,7 @@ describe("Test class Endpoint", () => {
const endpoint = new Endpoint(config, "/test");

endpoint["httpGet"]("/mypath").subscribe(
(response: AjaxResponse) => {
(response: AjaxResponse<any>) => {
expect(response.status).toEqual(200);
expect(response.response).toEqual({test: "test"});

Expand Down Expand Up @@ -101,7 +101,7 @@ describe("Test class Endpoint", () => {
endpoint.jsonWebToken = "testtoken";

endpoint["httpGet"]().subscribe(
(response: AjaxResponse) => {
(response: AjaxResponse<any>) => {
expect(response.status).toEqual(200);
expect(response.response).toEqual({test: "test"});

Expand All @@ -127,7 +127,7 @@ describe("Test class Endpoint", () => {
const endpoint = new Endpoint(config, "/test");

endpoint["httpGet"](undefined, {"my-feature-toggle": "my-awesome-feature"}).subscribe(
(response: AjaxResponse) => {
(response: AjaxResponse<any>) => {
expect(response.status).toEqual(200);
expect(response.response).toEqual({test: "test"});

Expand All @@ -153,7 +153,7 @@ describe("Test class Endpoint", () => {
const endpoint = new Endpoint(config, "/test");

endpoint["httpPost"]("", {mydata: "data"}).subscribe(
(response: AjaxResponse) => {
(response: AjaxResponse<any>) => {
expect(response.status).toEqual(200);
expect(response.response).toEqual({test: "test"});

Expand Down Expand Up @@ -181,7 +181,7 @@ describe("Test class Endpoint", () => {
const endpoint = new Endpoint(config, "/test");

endpoint["httpPost"]("", {mydata: "data"}).subscribe(
(response: AjaxResponse) => {
(response: AjaxResponse<any>) => {

},
err => {
Expand Down Expand Up @@ -211,7 +211,7 @@ describe("Test class Endpoint", () => {
const endpoint = new Endpoint(config, "/test");

endpoint["httpPost"]("/mypath", {mydata: "data"}).subscribe(
(response: AjaxResponse) => {
(response: AjaxResponse<any>) => {
expect(response.status).toEqual(200);
expect(response.response).toEqual({test: "test"});

Expand Down Expand Up @@ -241,7 +241,7 @@ describe("Test class Endpoint", () => {
endpoint.jsonWebToken = "testtoken";

endpoint["httpPost"]("", {mydata: "data"}).subscribe(
(response: AjaxResponse) => {
(response: AjaxResponse<any>) => {
expect(response.status).toEqual(200);
expect(response.response).toEqual({test: "test"});

Expand Down Expand Up @@ -272,7 +272,7 @@ describe("Test class Endpoint", () => {
const endpoint = new Endpoint(config, "/test");

endpoint["httpPost"](undefined, {mydata: "data"}, undefined, {"my-feature-toggle": "my-awesome-feature"}).subscribe(
(response: AjaxResponse) => {
(response: AjaxResponse<any>) => {
expect(response.status).toEqual(200);
expect(response.response).toEqual({test: "test"});

Expand Down Expand Up @@ -319,7 +319,7 @@ describe("Test class Endpoint", () => {
`;

endpoint["httpPost"](undefined, gravsearchQuery, "sparql", {"my-feature-toggle": "my-awesome-feature"}).subscribe(
(response: AjaxResponse) => {
(response: AjaxResponse<any>) => {
expect(response.status).toEqual(200);
expect(response.response).toEqual({test: "test"});

Expand Down Expand Up @@ -352,7 +352,7 @@ describe("Test class Endpoint", () => {
const endpoint = new Endpoint(config, "/test");

endpoint["httpPut"]("", {mydata: "data"}).subscribe(
(response: AjaxResponse) => {
(response: AjaxResponse<any>) => {
expect(response.status).toEqual(200);
expect(response.response).toEqual({test: "test"});

Expand Down Expand Up @@ -380,7 +380,7 @@ describe("Test class Endpoint", () => {
const endpoint = new Endpoint(config, "/test");

endpoint["httpPut"]("", {mydata: "data"}).subscribe(
(response: AjaxResponse) => {
(response: AjaxResponse<any>) => {
},
err => {
expect(err instanceof Error).toBeTruthy();
Expand Down Expand Up @@ -409,7 +409,7 @@ describe("Test class Endpoint", () => {
const endpoint = new Endpoint(config, "/test");

endpoint["httpPut"]("/mypath", {mydata: "data"}).subscribe(
(response: AjaxResponse) => {
(response: AjaxResponse<any>) => {
expect(response.status).toEqual(200);
expect(response.response).toEqual({test: "test"});

Expand Down Expand Up @@ -439,7 +439,7 @@ describe("Test class Endpoint", () => {
endpoint.jsonWebToken = "testtoken";

endpoint["httpPut"]("/mypath", {mydata: "data"}).subscribe(
(response: AjaxResponse) => {
(response: AjaxResponse<any>) => {
expect(response.status).toEqual(200);
expect(response.response).toEqual({test: "test"});

Expand Down Expand Up @@ -470,7 +470,7 @@ describe("Test class Endpoint", () => {
const endpoint = new Endpoint(config, "/test");

endpoint["httpPut"](undefined, {mydata: "data"}, undefined, {"my-feature-toggle": "my-awesome-feature"}).subscribe(
(response: AjaxResponse) => {
(response: AjaxResponse<any>) => {
expect(response.status).toEqual(200);
expect(response.response).toEqual({test: "test"});

Expand Down Expand Up @@ -501,7 +501,7 @@ describe("Test class Endpoint", () => {
const endpoint = new Endpoint(config, "/test");

endpoint["httpDelete"]().subscribe(
(response: AjaxResponse) => {
(response: AjaxResponse<any>) => {
expect(response.status).toEqual(200);
expect(response.response).toEqual({test: "test"});

Expand All @@ -527,7 +527,7 @@ describe("Test class Endpoint", () => {
const endpoint = new Endpoint(config, "/test");

endpoint["httpDelete"]().subscribe(
(response: AjaxResponse) => {
(response: AjaxResponse<any>) => {
},
err => {
expect(err instanceof Error).toBeTruthy();
Expand All @@ -554,7 +554,7 @@ describe("Test class Endpoint", () => {
const endpoint = new Endpoint(config, "/test");

endpoint["httpDelete"]("/mypath").subscribe(
(response: AjaxResponse) => {
(response: AjaxResponse<any>) => {
expect(response.status).toEqual(200);
expect(response.response).toEqual({test: "test"});

Expand Down Expand Up @@ -582,7 +582,7 @@ describe("Test class Endpoint", () => {
endpoint.jsonWebToken = "testtoken";

endpoint["httpDelete"]().subscribe(
(response: AjaxResponse) => {
(response: AjaxResponse<any>) => {
expect(response.status).toEqual(200);
expect(response.response).toEqual({test: "test"});

Expand All @@ -608,7 +608,7 @@ describe("Test class Endpoint", () => {
const endpoint = new Endpoint(config, "/test");

endpoint["httpDelete"](undefined, {"my-feature-toggle": "my-awesome-feature"}).subscribe(
(response: AjaxResponse) => {
(response: AjaxResponse<any>) => {
expect(response.status).toEqual(200);
expect(response.response).toEqual({test: "test"});

Expand Down
17 changes: 10 additions & 7 deletions src/api/endpoint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { JsonConvert, OperationMode, ValueCheckingMode } from "json2typescript";
import { PropertyMatchingRule } from "json2typescript/src/json2typescript/json-convert-enums";
import { Observable, throwError } from "rxjs";
import { ajax, AjaxError, AjaxRequest, AjaxResponse } from "rxjs/ajax";
import { AjaxError, AjaxRequest, AjaxResponse, ajax } from "rxjs/ajax";
import { KnoraApiConfig } from "../knora-api-config";
import { ApiResponseError } from "../models/api-response-error";
import { DataError } from "../models/data-error";
Expand Down Expand Up @@ -66,7 +66,7 @@ export class Endpoint {
* @param path the relative URL for the request
* @param headerOpts additional headers, if any.
*/
protected httpGet(path?: string, headerOpts?: IHeaderOptions): Observable<AjaxResponse> {
protected httpGet(path?: string, headerOpts?: IHeaderOptions): Observable<AjaxResponse<any>> {
if (path === undefined) path = "";

return ajax(this.setAjaxRequest(path, "GET", undefined, this.constructHeader(undefined, headerOpts)))
Expand All @@ -84,7 +84,7 @@ export class Endpoint {
* @param contentType content content type of body, if any.
* @param headerOpts additional headers, if any.
*/
protected httpPost(path?: string, body?: any, contentType: "json" | "sparql" = "json", headerOpts?: IHeaderOptions): Observable<AjaxResponse> {
protected httpPost(path?: string, body?: any, contentType: "json" | "sparql" = "json", headerOpts?: IHeaderOptions): Observable<AjaxResponse<any>> {

if (path === undefined) path = "";

Expand All @@ -103,7 +103,7 @@ export class Endpoint {
* @param contentType content content type of body, if any.
* @param headerOpts additional headers, if any.
*/
protected httpPut(path?: string, body?: any, contentType: "json" = "json", headerOpts?: IHeaderOptions): Observable<AjaxResponse> {
protected httpPut(path?: string, body?: any, contentType: "json" = "json", headerOpts?: IHeaderOptions): Observable<AjaxResponse<any>> {

if (path === undefined) path = "";

Expand All @@ -122,7 +122,7 @@ export class Endpoint {
* @param contentType content content type of body, if any.
* @param headerOpts additional headers, if any.
*/
protected httpPatch(path?: string, body?: any, contentType: "json" = "json", headerOpts?: IHeaderOptions): Observable<AjaxResponse> {
protected httpPatch(path?: string, body?: any, contentType: "json" = "json", headerOpts?: IHeaderOptions): Observable<AjaxResponse<any>> {

if (path === undefined) path = "";

Expand All @@ -139,7 +139,7 @@ export class Endpoint {
* @param path the relative URL for the request.
* @param headerOpts additional headers, if any.
*/
protected httpDelete(path?: string, headerOpts?: IHeaderOptions): Observable<AjaxResponse> {
protected httpDelete(path?: string, headerOpts?: IHeaderOptions): Observable<AjaxResponse<any>> {

if (path === undefined) path = "";

Expand Down Expand Up @@ -231,7 +231,7 @@ export class Endpoint {
* @param [headers] IHeaderOptions
* @returns AjaxRequest object
*/
private setAjaxRequest(path: string, method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE", body?: any, headers?: IHeaderOptions): AjaxRequest {
private setAjaxRequest(path: string, method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE", body: any, headers: IHeaderOptions): AjaxRequest {

let apiUrl = this.knoraApiConfig.apiUrl;

Expand All @@ -241,6 +241,9 @@ export class Endpoint {
body: body,
async: true,
withCredentials: true,
crossDomain: true,
timeout: 0,
responseType: "json",
headers: headers
};

Expand Down
2 changes: 1 addition & 1 deletion src/api/operators/retryOnError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function retryOnError(delayMs: number, maxRetries: number, retryOnErrorSt
let retries = maxRetries;

// inspired by https://medium.com/angular-in-depth/retry-failed-http-requests-in-angular-f5959d486294
return (src: Observable<AjaxResponse>): Observable<AjaxResponse> =>
return (src: Observable<AjaxResponse<any>>): Observable<AjaxResponse<any>> =>
src.pipe(
// when no error is thrown, this simply returns the source Observable
retryWhen(errors =>
Expand Down
6 changes: 3 additions & 3 deletions src/api/v2/authentication/authentication-endpoint-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class AuthenticationEndpointV2 extends Endpoint {
credentials[property] = id;

return this.httpPost("", credentials).pipe(
map((ajaxResponse: AjaxResponse) => {
map((ajaxResponse: AjaxResponse<any>) => {
// Make sure the web token is stored.
const responseData = ApiResponseData.fromAjaxResponse(ajaxResponse, LoginResponse, this.jsonConvert);
this.jsonWebToken = responseData.body.token;
Expand All @@ -49,7 +49,7 @@ export class AuthenticationEndpointV2 extends Endpoint {
logout(): Observable<ApiResponseData<LogoutResponse> | ApiResponseError> {

return this.httpDelete("").pipe(
map((ajaxResponse: AjaxResponse) => {
map((ajaxResponse: AjaxResponse<any>) => {
// Make sure the web token is removed.
const responseData = ApiResponseData.fromAjaxResponse(ajaxResponse, LogoutResponse, this.jsonConvert);
this.jsonWebToken = "";
Expand All @@ -68,7 +68,7 @@ export class AuthenticationEndpointV2 extends Endpoint {
checkCredentials(): Observable<ApiResponseData<CredentialsResponse> | ApiResponseError> {

return this.httpGet("").pipe(
map((ajaxResponse: AjaxResponse) => {
map((ajaxResponse: AjaxResponse<any>) => {
return ApiResponseData.fromAjaxResponse(ajaxResponse, CredentialsResponse);
}),
catchError(error => this.handleError(error))
Expand Down
4 changes: 2 additions & 2 deletions src/api/v2/list/lists-endpoint-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ListsEndpointV2 extends Endpoint {
getNode(nodeIri: string): Observable<ListNodeV2 | ApiResponseError> {
// TODO: Do not hard-code the URL and http call params, generate this from Knora
return this.httpGet("/node/" + encodeURIComponent(nodeIri)).pipe(
mergeMap((ajaxResponse: AjaxResponse) => {
mergeMap((ajaxResponse: AjaxResponse<any>) => {
// TODO: @rosenth Adapt context object
// TODO: adapt getOntologyIriFromEntityIri
return jsonld.compact(ajaxResponse.response, {});
Expand All @@ -47,7 +47,7 @@ export class ListsEndpointV2 extends Endpoint {
getList(rootNodeIri: string): Observable<ListNodeV2 | ApiResponseError> {
// TODO: Do not hard-code the URL and http call params, generate this from Knora
return this.httpGet("/lists/" + encodeURIComponent(rootNodeIri)).pipe(
mergeMap((ajaxResponse: AjaxResponse) => {
mergeMap((ajaxResponse: AjaxResponse<any>) => {
// TODO: @rosenth Adapt context object
// TODO: adapt getOntologyIriFromEntityIri
return jsonld.compact(ajaxResponse.response, {});
Expand Down
Loading
Loading