Skip to content

Commit 6a53fbe

Browse files
author
Immanuel Pelzer
committed
Fix types for Client
1 parent af2509e commit 6a53fbe

File tree

6 files changed

+100
-10
lines changed

6 files changed

+100
-10
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6+
# [5.4.2] - 2023-07-26
7+
8+
- Fix `Client` types
9+
610
# [5.4.1] - 2023-07-26
711

812
- Refactor errors and improve Error types

bin/generate-type-definitions.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
# This generate the type definitions for all files
44
npx -p typescript tsc lib/index.js lib/**/*.js --declaration --allowJs --emitDeclarationOnly --outFile lib/index.d.ts --module node16 --esModuleInterop --skipLibCheck
55
# Rename the library (we put "taube" instead of "@unu/taube")
6-
sed -i 's/declare module "index" {/declare module "@unu\/taube" {/' lib/index.d.ts
6+
sed -i '' 's/declare module "index" {/declare module "@unu\/taube" {/' lib/index.d.ts
77
# Remove all ".js" endings to fix the pathing. the generator adds these for some reason
8-
sed -i 's/\.js//g' lib/index.d.ts
8+
sed -i '' 's/\.js//g' lib/index.d.ts

lib/components/client.js

+37
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ class Client {
4141
return uri.href
4242
}
4343

44+
/**
45+
* GET an endpoint
46+
*
47+
* @param {string} path URL path. e.g. /items
48+
* @param {Object} options Options passed directly to got
49+
* @returns {Promise<any>} The response of the query
50+
*/
4451
async get(path, options = {}) {
4552
if (options?.query) {
4653
options.searchParams = options.query
@@ -59,6 +66,13 @@ class Client {
5966
}
6067
}
6168

69+
/**
70+
* GET an endpoint that returns a paginated list
71+
*
72+
* @param {string} path URL path. e.g. /items
73+
* @param {Object} options Options passed directly to got
74+
* @returns {Promise<any>} The response of the query
75+
*/
6276
async paginate(path, options = {}) {
6377
options = { ...paginationDefaultOptions, ...options }
6478
try {
@@ -73,6 +87,14 @@ class Client {
7387
}
7488
}
7589

90+
/**
91+
* POST an endpoint
92+
*
93+
* @param {string} path URL path. e.g. /items
94+
* @param {Object} payload The payload to POST
95+
* @param {Object} options Options passed directly to got
96+
* @returns {Promise<any>} The response of the query
97+
*/
7698
async post(path, payload, options = {}) {
7799
if (options?.query) {
78100
options.searchParams = options.query
@@ -93,6 +115,14 @@ class Client {
93115
}
94116
}
95117

118+
/**
119+
* PUT an endpoint
120+
*
121+
* @param {string} path URL path. e.g. /items
122+
* @param {Object} payload The payload to POST
123+
* @param {Object} options Options passed directly to got
124+
* @returns {Promise<any>} The response of the query
125+
*/
96126
async put(path, payload, options = {}) {
97127
if (options?.query) {
98128
options.searchParams = options.query
@@ -113,6 +143,13 @@ class Client {
113143
}
114144
}
115145

146+
/**
147+
* DELETE an endpoint
148+
*
149+
* @param {string} path URL path. e.g. /items
150+
* @param {Object} options Options passed directly to got
151+
* @returns {Promise<any>} The response of the query
152+
*/
116153
async delete(path, options = {}) {
117154
if (options?.query) {
118155
options.searchParams = options.query

lib/index.d.ts

+54-5
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ declare module "components/requester" {
6767
}
6868
}
6969
declare module "components/errors" {
70+
export class TaubeError extends Error {
71+
constructor(message: any, data?: any);
72+
data: any;
73+
isTaubeError: boolean;
74+
statusCode: any;
75+
toJSON(): {
76+
message: string;
77+
name: string;
78+
statusCode: any;
79+
data: any;
80+
};
81+
}
7082
export function convertToTaubeError(error: Error): any;
7183
export default errors;
7284
const errors: {
@@ -2319,11 +2331,48 @@ declare module "components/client" {
23192331
uri: any;
23202332
port: string | number;
23212333
makePath(path: any, params?: {}): string;
2322-
get(path: any, options?: {}): Promise<string>;
2323-
paginate(path: any, options?: {}): Promise<string>;
2324-
post(path: any, payload: any, options?: {}): Promise<string>;
2325-
put(path: any, payload: any, options?: {}): Promise<string>;
2326-
delete(path: any, options?: {}): Promise<string>;
2334+
/**
2335+
* GET an endpoint
2336+
*
2337+
* @param {string} path URL path. e.g. /items
2338+
* @param {Object} options Options passed directly to got
2339+
* @returns {Promise<any>} The response of the query
2340+
*/
2341+
get(path: string, options?: any): Promise<any>;
2342+
/**
2343+
* GET an endpoint that returns a paginated list
2344+
*
2345+
* @param {string} path URL path. e.g. /items
2346+
* @param {Object} options Options passed directly to got
2347+
* @returns {Promise<any>} The response of the query
2348+
*/
2349+
paginate(path: string, options?: any): Promise<any>;
2350+
/**
2351+
* POST an endpoint
2352+
*
2353+
* @param {string} path URL path. e.g. /items
2354+
* @param {Object} payload The payload to POST
2355+
* @param {Object} options Options passed directly to got
2356+
* @returns {Promise<any>} The response of the query
2357+
*/
2358+
post(path: string, payload: any, options?: any): Promise<any>;
2359+
/**
2360+
* PUT an endpoint
2361+
*
2362+
* @param {string} path URL path. e.g. /items
2363+
* @param {Object} payload The payload to POST
2364+
* @param {Object} options Options passed directly to got
2365+
* @returns {Promise<any>} The response of the query
2366+
*/
2367+
put(path: string, payload: any, options?: any): Promise<any>;
2368+
/**
2369+
* DELETE an endpoint
2370+
*
2371+
* @param {string} path URL path. e.g. /items
2372+
* @param {Object} options Options passed directly to got
2373+
* @returns {Promise<any>} The response of the query
2374+
*/
2375+
delete(path: string, options?: any): Promise<any>;
23272376
}
23282377
}
23292378
declare module "helpers/schema" {

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@unu/taube",
3-
"version": "5.4.1",
3+
"version": "5.4.2",
44
"type": "module",
55
"exports": "./lib/index.js",
66
"engines": {

0 commit comments

Comments
 (0)