From ea8cab69f4c0e2cc17c7967f4f35cb488daa98ad Mon Sep 17 00:00:00 2001 From: Cavanaugh Richards Date: Wed, 21 Jun 2023 17:09:52 -0500 Subject: [PATCH 1/3] Add default value to encodeGetParams body type param. Fixes #146 --- src/http.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/http.ts b/src/http.ts index 8f0b8e0..cdc15dd 100644 --- a/src/http.ts +++ b/src/http.ts @@ -1335,7 +1335,7 @@ export class LemmyHttp { } } -function encodeGetParams(p: BodyType): string { +function encodeGetParams(p: BodyType = {}): string { return Object.entries(p) .filter(kv => !!kv[1]) .map(kv => kv.map(encodeURIComponent).join("=")) From 9b73693910d84b82ff3d1cab61e373b733689fa5 Mon Sep 17 00:00:00 2001 From: Cavanaugh Richards Date: Wed, 21 Jun 2023 17:19:30 -0500 Subject: [PATCH 2/3] Run prettier --- src/http.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/http.ts b/src/http.ts index cdc15dd..b659339 100644 --- a/src/http.ts +++ b/src/http.ts @@ -1335,7 +1335,9 @@ export class LemmyHttp { } } -function encodeGetParams(p: BodyType = {}): string { +function encodeGetParams( + p: BodyType = {} +): string { return Object.entries(p) .filter(kv => !!kv[1]) .map(kv => kv.map(encodeURIComponent).join("=")) From b5fdfa651338bd691f296990330fc63b8cffdb5c Mon Sep 17 00:00:00 2001 From: Cavanaugh Richards Date: Thu, 22 Jun 2023 13:43:49 -0500 Subject: [PATCH 3/3] Add default object to client functions where the form data or query is optional --- src/http.ts | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/http.ts b/src/http.ts index b659339..e401adb 100644 --- a/src/http.ts +++ b/src/http.ts @@ -178,7 +178,7 @@ export class LemmyHttp { * * `HTTP.GET /site` */ - getSite(form: GetSite) { + getSite(form: GetSite = {}) { return this.#wrapper(HttpType.Get, "/site", form); } @@ -222,7 +222,7 @@ export class LemmyHttp { * * `HTTP.GET /modlog` */ - getModlog(form: GetModlog) { + getModlog(form: GetModlog = {}) { return this.#wrapper( HttpType.Get, "/modlog", @@ -270,7 +270,7 @@ export class LemmyHttp { * * `HTTP.GET /community` */ - getCommunity(form: GetCommunity) { + getCommunity(form: GetCommunity = {}) { return this.#wrapper( HttpType.Get, "/community", @@ -296,7 +296,7 @@ export class LemmyHttp { * * `HTTP.GET /community/list` */ - listCommunities(form: ListCommunities) { + listCommunities(form: ListCommunities = {}) { return this.#wrapper( HttpType.Get, "/community/list", @@ -413,7 +413,7 @@ export class LemmyHttp { * * `HTTP.GET /post` */ - getPost(form: GetPost) { + getPost(form: GetPost = {}) { return this.#wrapper(HttpType.Get, "/post", form); } @@ -496,7 +496,7 @@ export class LemmyHttp { * * `HTTP.GET /post/list` */ - getPosts(form: GetPosts) { + getPosts(form: GetPosts = {}) { return this.#wrapper( HttpType.Get, "/post/list", @@ -691,7 +691,7 @@ export class LemmyHttp { * * `HTTP.GET /comment/list` */ - getComments(form: GetComments) { + getComments(form: GetComments = {}) { return this.#wrapper( HttpType.Get, "/comment/list", @@ -883,7 +883,7 @@ export class LemmyHttp { * * `HTTP.GET /user` */ - getPersonDetails(form: GetPersonDetails) { + getPersonDetails(form: GetPersonDetails = {}) { return this.#wrapper( HttpType.Get, "/user", @@ -974,7 +974,7 @@ export class LemmyHttp { * * `HTTP.GET /user/get_captcha` */ - getCaptcha(form: GetCaptcha) { + getCaptcha(form: GetCaptcha = {}) { return this.#wrapper( HttpType.Get, "/user/get_captcha", @@ -1246,7 +1246,7 @@ export class LemmyHttp { * * `HTTP.Get /federated_instances` */ - async getFederatedInstances(form: GetFederatedInstances) { + async getFederatedInstances(form: GetFederatedInstances = {}) { return this.#wrapper( HttpType.Get, "/federated_instances", @@ -1335,9 +1335,7 @@ export class LemmyHttp { } } -function encodeGetParams( - p: BodyType = {} -): string { +function encodeGetParams(p: BodyType): string { return Object.entries(p) .filter(kv => !!kv[1]) .map(kv => kv.map(encodeURIComponent).join("="))