Comparing version 1.5.0-beta to 1.5.0
@@ -113,5 +113,4 @@ "use strict"; | ||
version: '', | ||
}, paths: paths, | ||
definitions: definitions }, options); | ||
}, paths: paths, definitions: definitions }, options); | ||
} | ||
exports.apiSpecToOpenApi = apiSpecToOpenApi; |
@@ -16,6 +16,5 @@ /** Type-safe wrapper around fetch() for REST APIs */ | ||
]>; | ||
declare type QueryType<Endpoint, M extends undefined | keyof Endpoint> = SafeKey<SafeKey<Endpoint, M extends undefined ? 'get' : M>, 'query'>; | ||
/** Utility for safely constructing API URLs */ | ||
export declare function apiUrlMaker<API>(prefix?: string): <Args extends [endpoint: keyof API, method?: AllMethods | undefined], Path extends Args[0] = Args[0], P extends API[Path] = API[Path], AllMethods extends keyof P = keyof P>(...[endpoint, _method]: Args) => (...paramsList: DeepReadonly<[SafeKey<SafeKey<P, Args[1] extends undefined ? "get" : Args[1]>, "query">] extends [null] ? [{}] extends [ExtractRouteParams<Path & string>] ? [] : [params: ExtractRouteParams<Path & string>] : [{}, {}] extends [ExtractRouteParams<Path & string>, SafeKey<SafeKey<P, Args[1] extends undefined ? "get" : Args[1]>, "query">] ? [params?: { | ||
[pathParam: string]: never; | ||
} | null | undefined, query?: SafeKey<SafeKey<P, Args[1] extends undefined ? "get" : Args[1]>, "query"> | undefined] : [params: [{}] extends ExtractRouteParams<Path & string> ? PlaceholderEmpty : ExtractRouteParams<Path & string>, ...query: [{}] extends [SafeKey<SafeKey<P, Args[1] extends undefined ? "get" : Args[1]>, "query">] ? [query?: SafeKey<SafeKey<P, Args[1] extends undefined ? "get" : Args[1]>, "query"> | undefined] : [query: SafeKey<SafeKey<P, Args[1] extends undefined ? "get" : Args[1]>, "query">]]>) => string; | ||
export declare function apiUrlMaker<API>(prefix?: string): <Args extends [endpoint: keyof API, method?: AllMethods | undefined], Path extends Args[0] = Args[0], P extends API[Path] = API[Path], AllMethods extends keyof P = keyof P>(...[endpoint, _method]: Args) => (...paramsList: DeepReadonly<[QueryType<P, Args[1]>] extends [null] ? [{}] extends [ExtractRouteParams<Path & string>] ? [] : [params: ExtractRouteParams<Path & string>] : [{}, {}] extends [ExtractRouteParams<Path & string>, QueryType<P, Args[1]>] ? [params?: PlaceholderEmpty | undefined, query?: QueryType<P, Args[1]> | undefined] : [params: [{}] extends ExtractRouteParams<Path & string> ? PlaceholderEmpty : ExtractRouteParams<Path & string>, ...query: [{}] extends [QueryType<P, Args[1]>] ? [query?: QueryType<P, Args[1]> | undefined] : [query: QueryType<P, Args[1]>]]>) => string; | ||
export interface Options { | ||
@@ -29,13 +28,11 @@ /** Prefix to add to all API endpoints (e.g. /api/v0) */ | ||
export declare function typedApi<API>(options?: Options): { | ||
get: <Path extends PathsForMethod<API, "get">>(endpoint: Path) => (...params: DeepReadonly<[SafeKey<SafeKey<API[Path], "get">, "query">] extends [null] ? [{}] extends [ExtractRouteParams<Path & string>] ? [] : [params: ExtractRouteParams<Path & string>] : [{}, {}] extends [ExtractRouteParams<Path & string>, SafeKey<SafeKey<API[Path], "get">, "query">] ? [params?: { | ||
[pathParam: string]: never; | ||
} | null | undefined, query?: SafeKey<SafeKey<API[Path], "get">, "query"> | undefined] : [params: [{}] extends ExtractRouteParams<Path & string> ? PlaceholderEmpty : ExtractRouteParams<Path & string>, ...query: [{}] extends [SafeKey<SafeKey<API[Path], "get">, "query">] ? [query?: SafeKey<SafeKey<API[Path], "get">, "query"> | undefined] : [query: SafeKey<SafeKey<API[Path], "get">, "query">]]>) => Promise<SafeKey<SafeKey<API[Path], "get">, "response">>; | ||
delete: <Path_1 extends PathsForMethod<API, "delete">>(endpoint: Path_1) => (...params: DeepReadonly<[SafeKey<SafeKey<API[Path_1], "delete">, "query">] extends [null] ? [{}] extends [ExtractRouteParams<Path_1 & string>] ? [] : [params: ExtractRouteParams<Path_1 & string>] : [{}, {}] extends [ExtractRouteParams<Path_1 & string>, SafeKey<SafeKey<API[Path_1], "delete">, "query">] ? [params?: { | ||
[pathParam: string]: never; | ||
} | null | undefined, query?: SafeKey<SafeKey<API[Path_1], "delete">, "query"> | undefined] : [params: [{}] extends ExtractRouteParams<Path_1 & string> ? PlaceholderEmpty : ExtractRouteParams<Path_1 & string>, ...query: [{}] extends [SafeKey<SafeKey<API[Path_1], "delete">, "query">] ? [query?: SafeKey<SafeKey<API[Path_1], "delete">, "query"> | undefined] : [query: SafeKey<SafeKey<API[Path_1], "delete">, "query">]]>) => Promise<SafeKey<SafeKey<API[Path_1], "delete">, "response">>; | ||
get: <Path extends PathsForMethod<API, "get">>(endpoint: Path) => (...params: DeepReadonly<[SafeKey<SafeKey<API[Path], "get">, "query">] extends [null] ? [{}] extends [ExtractRouteParams<Path & string>] ? [] : [params: ExtractRouteParams<Path & string>] : [{}, {}] extends [ExtractRouteParams<Path & string>, SafeKey<SafeKey<API[Path], "get">, "query">] ? [params?: PlaceholderEmpty | undefined, query?: SafeKey<SafeKey<API[Path], "get">, "query"> | undefined] : [params: [{}] extends ExtractRouteParams<Path & string> ? PlaceholderEmpty : ExtractRouteParams<Path & string>, ...query: [{}] extends [SafeKey<SafeKey<API[Path], "get">, "query">] ? [query?: SafeKey<SafeKey<API[Path], "get">, "query"> | undefined] : [query: SafeKey<SafeKey<API[Path], "get">, "query">]]>) => Promise<SafeKey<SafeKey<API[Path], "get">, "response">>; | ||
delete: <Path_1 extends PathsForMethod<API, "delete">>(endpoint: Path_1) => (...params: DeepReadonly<[SafeKey<SafeKey<API[Path_1], "delete">, "query">] extends [null] ? [{}] extends [ExtractRouteParams<Path_1 & string>] ? [] : [params: ExtractRouteParams<Path_1 & string>] : [{}, {}] extends [ExtractRouteParams<Path_1 & string>, SafeKey<SafeKey<API[Path_1], "delete">, "query">] ? [params?: PlaceholderEmpty | undefined, query?: SafeKey<SafeKey<API[Path_1], "delete">, "query"> | undefined] : [params: [{}] extends ExtractRouteParams<Path_1 & string> ? PlaceholderEmpty : ExtractRouteParams<Path_1 & string>, ...query: [{}] extends [SafeKey<SafeKey<API[Path_1], "delete">, "query">] ? [query?: SafeKey<SafeKey<API[Path_1], "delete">, "query"> | undefined] : [query: SafeKey<SafeKey<API[Path_1], "delete">, "query">]]>) => Promise<SafeKey<SafeKey<API[Path_1], "delete">, "response">>; | ||
post: <Path_2 extends PathsForMethod<API, "post">>(endpoint: Path_2) => (params: ExtractRouteParams<Path_2 & string>, body: DeepReadonly<SafeKey<SafeKey<API[Path_2], "post">, "request">>, ...queryArgs: [SafeKey<SafeKey<API[Path_2], "post">, "query">] extends [null] ? [] : [{}] extends [SafeKey<SafeKey<API[Path_2], "post">, "query">] ? [query?: SafeKey<SafeKey<API[Path_2], "post">, "query"> | undefined] : [query: SafeKey<SafeKey<API[Path_2], "post">, "query">]) => Promise<SafeKey<SafeKey<API[Path_2], "post">, "response">>; | ||
patch: <Path_3 extends PathsForMethod<API, "patch">>(endpoint: Path_3) => (params: ExtractRouteParams<Path_3 & string>, body: DeepReadonly<SafeKey<SafeKey<API[Path_3], "patch">, "request">>, ...queryArgs: [SafeKey<SafeKey<API[Path_3], "patch">, "query">] extends [null] ? [] : [{}] extends [SafeKey<SafeKey<API[Path_3], "patch">, "query">] ? [query?: SafeKey<SafeKey<API[Path_3], "patch">, "query"> | undefined] : [query: SafeKey<SafeKey<API[Path_3], "patch">, "query">]) => Promise<SafeKey<SafeKey<API[Path_3], "patch">, "response">>; | ||
put: <Path_4 extends PathsForMethod<API, "put">>(endpoint: Path_4) => (params: ExtractRouteParams<Path_4 & string>, body: DeepReadonly<SafeKey<SafeKey<API[Path_4], "put">, "request">>, ...queryArgs: [SafeKey<SafeKey<API[Path_4], "put">, "query">] extends [null] ? [] : [{}] extends [SafeKey<SafeKey<API[Path_4], "put">, "query">] ? [query?: SafeKey<SafeKey<API[Path_4], "put">, "query"> | undefined] : [query: SafeKey<SafeKey<API[Path_4], "put">, "query">]) => Promise<SafeKey<SafeKey<API[Path_4], "put">, "response">>; | ||
request: <Method extends HTTPVerb>(method: Method, path: PathsForMethod<API, Method>) => (params: ExtractRouteParams<PathsForMethod<API, Method>>, body: DeepReadonly<SafeKey<SafeKey<API[PathsForMethod<API, Method>], Method>, "request">>, ...queryArgs: [SafeKey<SafeKey<API[PathsForMethod<API, Method>], Method>, "query">] extends [null] ? [] : [{}] extends [SafeKey<SafeKey<API[PathsForMethod<API, Method>], Method>, "query">] ? [query?: SafeKey<SafeKey<API[PathsForMethod<API, Method>], Method>, "query"> | undefined] : [query: SafeKey<SafeKey<API[PathsForMethod<API, Method>], Method>, "query">]) => Promise<SafeKey<SafeKey<API[PathsForMethod<API, Method>], Method>, "response">>; | ||
request: <Method extends HTTPVerb>(method: Method, path: PathsForMethod<API, Method>) => (params: ExtractRouteParams<Extract<import("./utils").Unionize<API>, { | ||
v: Record<Method, any>; | ||
}>["k"] & keyof API & string>, body: DeepReadonly<SafeKey<SafeKey<API[PathsForMethod<API, Method>], Method>, "request">>, ...queryArgs: [SafeKey<SafeKey<API[PathsForMethod<API, Method>], Method>, "query">] extends [null] ? [] : [{}] extends [SafeKey<SafeKey<API[PathsForMethod<API, Method>], Method>, "query">] ? [query?: SafeKey<SafeKey<API[PathsForMethod<API, Method>], Method>, "query"> | undefined] : [query: SafeKey<SafeKey<API[PathsForMethod<API, Method>], Method>, "query">]) => Promise<SafeKey<SafeKey<API[PathsForMethod<API, Method>], Method>, "response">>; | ||
}; | ||
export {}; |
@@ -11,2 +11,4 @@ "use strict"; | ||
return function (d, b) { | ||
if (typeof b !== "function" && b !== null) | ||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); | ||
extendStatics(d, b); | ||
@@ -13,0 +15,0 @@ function __() { this.constructor = d; } |
{ | ||
"name": "crosswalk", | ||
"version": "1.5.0-beta", | ||
"version": "1.5.0", | ||
"description": "Type-safe express routing with TypeScript", | ||
@@ -11,4 +11,5 @@ "main": "dist/index.js", | ||
"test": "jest", | ||
"lint": "prettier --check 'src/**/*.ts'", | ||
"prettier": "prettier --write 'src/**/*.ts'", | ||
"lint": "eslint . --ext .ts,.tsx", | ||
"format": "prettier --write 'src/**/*.ts'", | ||
"format:check": "prettier --check 'src/**/*.ts'", | ||
"update-test-schema": "typescript-json-schema --required --noExtraProps --strictNullChecks src/__tests__/api.ts API --out src/__tests__/api.schema.json" | ||
@@ -34,10 +35,13 @@ }, | ||
"@types/swagger-ui-express": "^4.1.2", | ||
"@typescript-eslint/eslint-plugin": "^5.22.0", | ||
"@typescript-eslint/parser": "^5.22.0", | ||
"body-parser": "^1.19.0", | ||
"eslint": "^8.15.0", | ||
"eslint-plugin-expect-type": "^0.2.0", | ||
"express": "^4.17.2", | ||
"jest": "^26.6.3", | ||
"jest": "^28.1.0", | ||
"prettier": "^2.2.0", | ||
"spec.ts": "^1.1.3", | ||
"supertest": "^6.0.1", | ||
"ts-jest": "^26.4.4", | ||
"typescript": "4.1", | ||
"ts-jest": "^28.0.2", | ||
"typescript": "4.3", | ||
"typescript-json-schema": "^0.43.0" | ||
@@ -44,0 +48,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
57833
16
25
805