silgi 0.8.43 → 0.8.44

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.
@@ -1,4 +1,4 @@
1
- const version = "0.8.43";
1
+ const version = "0.8.44";
2
2
  const devDependencies = {
3
3
  "@antfu/eslint-config": "^4.2.0",
4
4
  "@fastify/deepmerge": "^2.0.2",
@@ -1,4 +1,4 @@
1
- const version = "0.8.43";
1
+ const version = "0.8.44";
2
2
  const devDependencies = {
3
3
  "@antfu/eslint-config": "^4.2.0",
4
4
  "@fastify/deepmerge": "^2.0.2",
@@ -1,4 +1,4 @@
1
- const version = "0.8.43";
1
+ const version = "0.8.44";
2
2
  const devDependencies = {
3
3
  "@antfu/eslint-config": "^4.2.0",
4
4
  "@fastify/deepmerge": "^2.0.2",
@@ -1,4 +1,4 @@
1
- import type { FetchContext, FetchOptions } from 'ofetch';
1
+ import type { FetchContext, FetchOptions, FetchResponse } from 'ofetch';
2
2
  import type { SilgiRouterTypes } from 'silgi/types';
3
3
  type TrimAfterFourSlashes<T extends string> = T extends `/${infer S1}/${infer S2}/${infer S3}/${infer S4}/${infer _}` ? `/${S1}/${S2}/${S3}/${S4}` : T;
4
4
  type AllPaths = SilgiRouterTypes extends {
@@ -9,23 +9,14 @@ type ExtractPathParams<T extends string> = T extends `${infer _Start}:${infer Pa
9
9
  } & ExtractPathParams<Rest> : T extends `${infer _Start}:${infer Param}` ? {
10
10
  [K in Param]: string;
11
11
  } : object;
12
- type ValidRoute = AllPaths | (string & {});
13
- type Method<R extends ValidRoute> = TrimAfterFourSlashes<R> extends keyof SilgiRouterTypes ? keyof SilgiRouterTypes[TrimAfterFourSlashes<R>] : never;
14
- export type FetchResponseData<R extends ValidRoute, M extends Method<R>> = TrimAfterFourSlashes<R> extends keyof SilgiRouterTypes ? SilgiRouterTypes[TrimAfterFourSlashes<R>][M]['output'] : never;
15
- export type RequestBodyOption<R extends ValidRoute, M extends Method<R>> = TrimAfterFourSlashes<R> extends keyof SilgiRouterTypes ? SilgiRouterTypes[TrimAfterFourSlashes<R>][M] extends {
16
- input: infer I;
17
- } ? {
18
- body: I;
19
- } : {
20
- body?: never;
21
- } : never;
22
- export type RouterParams<R extends ValidRoute> = ExtractPathParams<R>;
23
- type SilgiFetchOptions<P extends AllPaths | (string & {}), BasePath extends keyof SilgiRouterTypes = TrimAfterFourSlashes<P> extends keyof SilgiRouterTypes ? TrimAfterFourSlashes<P> : never, M extends keyof SilgiRouterTypes[BasePath] = keyof SilgiRouterTypes[BasePath]> = {
12
+ export type RouterParams<R extends AllPaths | (string & {})> = ExtractPathParams<R>;
13
+ type SilgiFetchOptions<T, P extends AllPaths | (string & {}), BasePath extends keyof SilgiRouterTypes = TrimAfterFourSlashes<P> extends keyof SilgiRouterTypes ? TrimAfterFourSlashes<P> : never, M extends keyof SilgiRouterTypes[BasePath] = keyof SilgiRouterTypes[BasePath]> = {
24
14
  method?: M;
25
15
  params?: ExtractPathParams<P>;
26
16
  body?: SilgiRouterTypes[BasePath][M]['input'];
27
17
  } & Omit<FetchOptions, 'method' | 'body' | 'params'>;
28
- export type SilgiFetchClient = <R extends ValidRoute, M extends Method<R> = 'get' extends Method<R> ? 'get' : Method<R>>(url: R, options: SilgiFetchOptions<R, M>) => Promise<FetchResponseData<R, M>>;
18
+ export type SilgiFetchClient = <T, P extends AllPaths | (string & {}), BasePath extends keyof SilgiRouterTypes = TrimAfterFourSlashes<P> extends keyof SilgiRouterTypes ? TrimAfterFourSlashes<P> : never, M extends keyof SilgiRouterTypes[BasePath] = keyof SilgiRouterTypes[BasePath]>(url: BasePath, options: SilgiFetchOptions<T, P, BasePath, M>) => Promise<FetchResponse<SilgiRouterTypes[BasePath][M]['output']>>;
29
19
  export declare function silgiFetchRequestInterceptor(ctx: FetchContext): void;
30
20
  export declare function createSilgiFetch(options: FetchOptions | ((options: FetchOptions) => FetchOptions), localFetch?: typeof globalThis.$fetch): SilgiFetchClient;
21
+ export declare function silgi$fetch<T, P extends AllPaths | (string & {}), BasePath extends keyof SilgiRouterTypes = TrimAfterFourSlashes<P> extends keyof SilgiRouterTypes ? TrimAfterFourSlashes<P> : never, M extends keyof SilgiRouterTypes[BasePath] = keyof SilgiRouterTypes[BasePath]>(url: P, opts?: SilgiFetchOptions<T, P, BasePath, M>): Promise<FetchResponse<SilgiRouterTypes[BasePath][M]['output']>>;
31
22
  export {};
@@ -12,6 +12,14 @@ export function createSilgiFetch(options, localFetch) {
12
12
  return $fetch(fillPath(url, opts.params), finalOpts);
13
13
  };
14
14
  }
15
+ export function silgi$fetch(url, opts) {
16
+ const finalOpts = {
17
+ ...opts,
18
+ method: opts?.method || "get"
19
+ };
20
+ const $fetch = getFetch(url, finalOpts);
21
+ return $fetch(fillPath(url, opts.params), finalOpts);
22
+ }
15
23
  function getFetch(url, opts, localFetch) {
16
24
  if (import.meta.server && localFetch) {
17
25
  const isLocalFetch = url[0] === "/" && (!opts.baseURL || opts.baseURL[0] === "/");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.8.43",
4
+ "version": "0.8.44",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {