@platformatic/client
Advanced tools
Comparing version 1.26.0 to 1.27.0
import { FastifyPluginAsync, FastifyReply, FastifyRequest } from 'fastify' | ||
import { FastifyError } from '@fastify/error' | ||
type CodeClasses = 1 | 2 | 3 | 4 | 5; | ||
type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9; | ||
type StringAsNumber<T extends string> = T extends `${infer N extends number}` ? N : never; | ||
type StatusCodes<T extends CodeClasses> = StringAsNumber<`${T}${Digit}${Digit}`>; | ||
export type StatusCode1xx = StatusCodes<1>; | ||
export type StatusCode2xx = StatusCodes<2>; | ||
export type StatusCode3xx = StatusCodes<3>; | ||
export type StatusCode4xx = StatusCodes<4>; | ||
export type StatusCode5xx = StatusCodes<5>; | ||
interface Headers { | ||
@@ -5,0 +15,0 @@ [key: string]: string |
@@ -1,5 +0,20 @@ | ||
import { expectError, expectType } from 'tsd' | ||
import { | ||
expectAssignable, | ||
expectError, | ||
expectNotAssignable, | ||
expectType | ||
} from 'tsd' | ||
import fastify, { HTTPMethods } from 'fastify' | ||
import pltClient, { type PlatformaticClientPluginOptions, type GetHeadersOptions, buildOpenAPIClient, errors } from '.' | ||
import { FastifyError } from '@fastify/error' | ||
import pltClient, { | ||
errors, | ||
buildOpenAPIClient, | ||
type PlatformaticClientPluginOptions, | ||
type GetHeadersOptions, | ||
type StatusCode2xx, | ||
type StatusCode1xx, | ||
type StatusCode3xx, | ||
type StatusCode4xx, | ||
type StatusCode5xx, | ||
} from "."; | ||
import { FastifyError } from "@fastify/error"; | ||
@@ -68,2 +83,49 @@ const server = await fastify() | ||
const isSuccessfulResponse = ( | ||
status: number, | ||
): status is StatusCode2xx => status >= 200 && status <= 299; | ||
const exampleUsageOfStatusCodeType = (status: number) => { | ||
if (isSuccessfulResponse(status)) { | ||
expectType<StatusCode2xx>(status) | ||
} else { | ||
expectError<StatusCode2xx>(status) | ||
} | ||
} | ||
expectNotAssignable<StatusCode1xx>(99) | ||
expectAssignable<StatusCode1xx>(100) | ||
expectAssignable<StatusCode1xx>(101) | ||
expectAssignable<StatusCode1xx>(150) | ||
expectAssignable<StatusCode1xx>(199) | ||
expectNotAssignable<StatusCode1xx>(200) | ||
expectNotAssignable<StatusCode2xx>(199) | ||
expectAssignable<StatusCode2xx>(200) | ||
expectAssignable<StatusCode2xx>(201) | ||
expectAssignable<StatusCode2xx>(250) | ||
expectAssignable<StatusCode2xx>(299) | ||
expectNotAssignable<StatusCode2xx>(300) | ||
expectNotAssignable<StatusCode3xx>(299) | ||
expectAssignable<StatusCode3xx>(300) | ||
expectAssignable<StatusCode3xx>(301) | ||
expectAssignable<StatusCode3xx>(350) | ||
expectAssignable<StatusCode3xx>(399) | ||
expectNotAssignable<StatusCode3xx>(400) | ||
expectNotAssignable<StatusCode4xx>(399) | ||
expectAssignable<StatusCode4xx>(400) | ||
expectAssignable<StatusCode4xx>(401) | ||
expectAssignable<StatusCode4xx>(450) | ||
expectAssignable<StatusCode4xx>(499) | ||
expectNotAssignable<StatusCode4xx>(500) | ||
expectNotAssignable<StatusCode5xx>(399) | ||
expectAssignable<StatusCode5xx>(500) | ||
expectAssignable<StatusCode5xx>(501) | ||
expectAssignable<StatusCode5xx>(550) | ||
expectAssignable<StatusCode5xx>(599) | ||
expectNotAssignable<StatusCode5xx>(600) | ||
// All params and generic passed | ||
@@ -70,0 +132,0 @@ expectType<MyType>(client) |
{ | ||
"name": "@platformatic/client", | ||
"version": "1.26.0", | ||
"version": "1.27.0", | ||
"description": "A client for all platformatic backends", | ||
@@ -17,3 +17,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"borp": "^0.9.0", | ||
"borp": "^0.10.0", | ||
"c8": "^9.1.0", | ||
@@ -28,3 +28,3 @@ "desm": "^1.3.1", | ||
"typescript": "^5.3.3", | ||
"@platformatic/telemetry": "1.26.0" | ||
"@platformatic/telemetry": "1.27.0" | ||
}, | ||
@@ -31,0 +31,0 @@ "dependencies": { |
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
34797
621