fets 0.4.6 → 0.4.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fets",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "description": "TypeScript HTTP Framework focusing on e2e type-safety, easy setup, performance & great developer experience",
5
5
  "sideEffects": false,
6
6
  "dependencies": {
@@ -2,6 +2,9 @@ import type { TypedResponseWithJSONStatusMap } from '../../typed-fetch.cjs';
2
2
  export type OAuth2AuthParams<TSecurityScheme> = TSecurityScheme extends {
3
3
  type: 'oauth2';
4
4
  } ? {
5
+ /**
6
+ * `Authorization` header is required for OAuth2.
7
+ */
5
8
  headers: {
6
9
  /**
7
10
  * The access token string as issued by the authorization server.
@@ -2,6 +2,9 @@ import type { TypedResponseWithJSONStatusMap } from '../../typed-fetch.js';
2
2
  export type OAuth2AuthParams<TSecurityScheme> = TSecurityScheme extends {
3
3
  type: 'oauth2';
4
4
  } ? {
5
+ /**
6
+ * `Authorization` header is required for OAuth2.
7
+ */
5
8
  headers: {
6
9
  /**
7
10
  * The access token string as issued by the authorization server.
@@ -1,7 +1,7 @@
1
- import type { B, Call, Objects, Pipe, Strings, Tuples } from 'hotscript';
2
- import type { O } from 'ts-toolbelt';
1
+ import type { B, Call, Fn, Objects, Pipe, Strings, Tuples } from 'hotscript';
2
+ import { type O } from 'ts-toolbelt';
3
3
  import { HTTPMethod, NotOkStatusCode, OkStatusCode, StatusCode, TypedResponse } from '../typed-fetch.cjs';
4
- import type { FromSchema, JSONSchema, OpenAPIDocument } from '../types.cjs';
4
+ import type { FromSchema, JSONSchema, OpenAPIDocument, Simplify } from '../types.cjs';
5
5
  import type { OASOAuthPath, OAuth2AuthParams } from './auth/oauth.cjs';
6
6
  type JSONSchema7TypeName = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null';
7
7
  type Mutable<Type> = FixJSONSchema<{
@@ -39,8 +39,6 @@ interface OASParamPropMap {
39
39
  path: 'params';
40
40
  header: 'headers';
41
41
  }
42
- type UnionToIntersectionHelper<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
43
- type UnionToIntersection<U> = boolean extends U ? UnionToIntersectionHelper<Exclude<U, boolean>> & boolean : UnionToIntersectionHelper<U>;
44
42
  export type OASParamObj<TParameter extends {
45
43
  name: string;
46
44
  }> = TParameter extends {
@@ -66,20 +64,29 @@ export type OASParamObj<TParameter extends {
66
64
  enum: TParameter['enum'];
67
65
  }> : unknown;
68
66
  };
69
- export type OASParamMap<TParameters extends {
70
- name: string;
67
+ interface OASParamToRequestParam<TParameters extends {
71
68
  in: string;
72
- }[]> = UnionToIntersection<{
73
- [TIndex in keyof TParameters]: TParameters[TIndex] extends {
69
+ required?: boolean;
70
+ }[]> extends Fn {
71
+ return: this['arg0'] extends {
72
+ name: string;
74
73
  in: infer TParamType;
75
- } ? TParameters[TIndex] extends {
76
- required: true;
77
- } ? {
78
- [TKey in TParamType extends keyof OASParamPropMap ? OASParamPropMap[TParamType] : never]: OASParamObj<TParameters[TIndex]>;
74
+ } ? TParameters extends [{
75
+ in: TParamType;
76
+ required?: true;
77
+ }] ? {
78
+ [TKey in TParamType extends keyof OASParamPropMap ? OASParamPropMap[TParamType] : never]: OASParamObj<this['arg0']>;
79
79
  } : {
80
- [TKey in TParamType extends keyof OASParamPropMap ? OASParamPropMap[TParamType] : never]?: OASParamObj<TParameters[TIndex]>;
81
- } : never;
82
- }[number]>;
80
+ [TKey in TParamType extends keyof OASParamPropMap ? OASParamPropMap[TParamType] : never]?: OASParamObj<this['arg0']>;
81
+ } : {};
82
+ }
83
+ export type OASParamMap<TParameters extends {
84
+ name: string;
85
+ in: string;
86
+ }[]> = Pipe<TParameters, [
87
+ Tuples.Map<OASParamToRequestParam<TParameters>>,
88
+ Tuples.ToIntersection
89
+ ]>;
83
90
  export type OASClient<TOAS extends OpenAPIDocument> = {
84
91
  [TPath in keyof OASPathMap<TOAS>]: {
85
92
  [TMethod in keyof OASMethodMap<TOAS, TPath>]: OASRequestParams<TOAS, TPath, TMethod> extends {
@@ -90,7 +97,7 @@ export type OASClient<TOAS extends OpenAPIDocument> = {
90
97
  headers: {};
91
98
  } | {
92
99
  query: {};
93
- } ? (requestParams: OASRequestParams<TOAS, TPath, TMethod>, init?: RequestInit) => Promise<OASResponse<TOAS, TPath, TMethod>> : (requestParams?: OASRequestParams<TOAS, TPath, TMethod>, init?: RequestInit) => Promise<OASResponse<TOAS, TPath, TMethod>>;
100
+ } ? (requestParams: Simplify<OASRequestParams<TOAS, TPath, TMethod>>, init?: RequestInit) => Promise<OASResponse<TOAS, TPath, TMethod>> : (requestParams?: Simplify<OASRequestParams<TOAS, TPath, TMethod>>, init?: RequestInit) => Promise<OASResponse<TOAS, TPath, TMethod>>;
94
101
  };
95
102
  } & OASOAuthPath<TOAS>;
96
103
  export type OASModel<TOAS extends OpenAPIDocument, TName extends string> = TOAS extends {
@@ -1,7 +1,7 @@
1
- import type { B, Call, Objects, Pipe, Strings, Tuples } from 'hotscript';
2
- import type { O } from 'ts-toolbelt';
1
+ import type { B, Call, Fn, Objects, Pipe, Strings, Tuples } from 'hotscript';
2
+ import { type O } from 'ts-toolbelt';
3
3
  import { HTTPMethod, NotOkStatusCode, OkStatusCode, StatusCode, TypedResponse } from '../typed-fetch.js';
4
- import type { FromSchema, JSONSchema, OpenAPIDocument } from '../types.js';
4
+ import type { FromSchema, JSONSchema, OpenAPIDocument, Simplify } from '../types.js';
5
5
  import type { OASOAuthPath, OAuth2AuthParams } from './auth/oauth.js';
6
6
  type JSONSchema7TypeName = 'string' | 'number' | 'integer' | 'boolean' | 'object' | 'array' | 'null';
7
7
  type Mutable<Type> = FixJSONSchema<{
@@ -39,8 +39,6 @@ interface OASParamPropMap {
39
39
  path: 'params';
40
40
  header: 'headers';
41
41
  }
42
- type UnionToIntersectionHelper<U> = (U extends unknown ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
43
- type UnionToIntersection<U> = boolean extends U ? UnionToIntersectionHelper<Exclude<U, boolean>> & boolean : UnionToIntersectionHelper<U>;
44
42
  export type OASParamObj<TParameter extends {
45
43
  name: string;
46
44
  }> = TParameter extends {
@@ -66,20 +64,29 @@ export type OASParamObj<TParameter extends {
66
64
  enum: TParameter['enum'];
67
65
  }> : unknown;
68
66
  };
69
- export type OASParamMap<TParameters extends {
70
- name: string;
67
+ interface OASParamToRequestParam<TParameters extends {
71
68
  in: string;
72
- }[]> = UnionToIntersection<{
73
- [TIndex in keyof TParameters]: TParameters[TIndex] extends {
69
+ required?: boolean;
70
+ }[]> extends Fn {
71
+ return: this['arg0'] extends {
72
+ name: string;
74
73
  in: infer TParamType;
75
- } ? TParameters[TIndex] extends {
76
- required: true;
77
- } ? {
78
- [TKey in TParamType extends keyof OASParamPropMap ? OASParamPropMap[TParamType] : never]: OASParamObj<TParameters[TIndex]>;
74
+ } ? TParameters extends [{
75
+ in: TParamType;
76
+ required?: true;
77
+ }] ? {
78
+ [TKey in TParamType extends keyof OASParamPropMap ? OASParamPropMap[TParamType] : never]: OASParamObj<this['arg0']>;
79
79
  } : {
80
- [TKey in TParamType extends keyof OASParamPropMap ? OASParamPropMap[TParamType] : never]?: OASParamObj<TParameters[TIndex]>;
81
- } : never;
82
- }[number]>;
80
+ [TKey in TParamType extends keyof OASParamPropMap ? OASParamPropMap[TParamType] : never]?: OASParamObj<this['arg0']>;
81
+ } : {};
82
+ }
83
+ export type OASParamMap<TParameters extends {
84
+ name: string;
85
+ in: string;
86
+ }[]> = Pipe<TParameters, [
87
+ Tuples.Map<OASParamToRequestParam<TParameters>>,
88
+ Tuples.ToIntersection
89
+ ]>;
83
90
  export type OASClient<TOAS extends OpenAPIDocument> = {
84
91
  [TPath in keyof OASPathMap<TOAS>]: {
85
92
  [TMethod in keyof OASMethodMap<TOAS, TPath>]: OASRequestParams<TOAS, TPath, TMethod> extends {
@@ -90,7 +97,7 @@ export type OASClient<TOAS extends OpenAPIDocument> = {
90
97
  headers: {};
91
98
  } | {
92
99
  query: {};
93
- } ? (requestParams: OASRequestParams<TOAS, TPath, TMethod>, init?: RequestInit) => Promise<OASResponse<TOAS, TPath, TMethod>> : (requestParams?: OASRequestParams<TOAS, TPath, TMethod>, init?: RequestInit) => Promise<OASResponse<TOAS, TPath, TMethod>>;
100
+ } ? (requestParams: Simplify<OASRequestParams<TOAS, TPath, TMethod>>, init?: RequestInit) => Promise<OASResponse<TOAS, TPath, TMethod>> : (requestParams?: Simplify<OASRequestParams<TOAS, TPath, TMethod>>, init?: RequestInit) => Promise<OASResponse<TOAS, TPath, TMethod>>;
94
101
  };
95
102
  } & OASOAuthPath<TOAS>;
96
103
  export type OASModel<TOAS extends OpenAPIDocument, TName extends string> = TOAS extends {
@@ -5,6 +5,9 @@ import { LazySerializedResponse } from './Response.cjs';
5
5
  import type { HTTPMethod, StatusCode, TypedRequest, TypedResponse, TypedResponseWithJSONStatusMap } from './typed-fetch.cjs';
6
6
  import { AddRouteWithZodSchemasOpts, RouteZodSchemas, TypedRequestFromRouteZodSchemas, TypedResponseFromRouteZodSchemas } from './zod/types.cjs';
7
7
  export { TypedRequest as RouterRequest };
8
+ export type Simplify<T> = {
9
+ [KeyType in keyof T]: Simplify<T[KeyType]>;
10
+ } & {};
8
11
  export type JSONSerializer = (obj: any) => string;
9
12
  export type JSONSchema = Exclude<JSONSchemaOrBoolean, boolean>;
10
13
  export interface OpenAPIInfo {
@@ -5,6 +5,9 @@ import { LazySerializedResponse } from './Response.js';
5
5
  import type { HTTPMethod, StatusCode, TypedRequest, TypedResponse, TypedResponseWithJSONStatusMap } from './typed-fetch.js';
6
6
  import { AddRouteWithZodSchemasOpts, RouteZodSchemas, TypedRequestFromRouteZodSchemas, TypedResponseFromRouteZodSchemas } from './zod/types.js';
7
7
  export { TypedRequest as RouterRequest };
8
+ export type Simplify<T> = {
9
+ [KeyType in keyof T]: Simplify<T[KeyType]>;
10
+ } & {};
8
11
  export type JSONSerializer = (obj: any) => string;
9
12
  export type JSONSchema = Exclude<JSONSchemaOrBoolean, boolean>;
10
13
  export interface OpenAPIInfo {