silgi 0.8.35 → 0.8.37

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.35";
1
+ const version = "0.8.37";
2
2
  const devDependencies = {
3
3
  "@antfu/eslint-config": "^4.2.0",
4
4
  "@fastify/deepmerge": "^2.0.2",
package/dist/cli/run.mjs CHANGED
@@ -170,7 +170,8 @@ const run = defineCommand({
170
170
  await jiti.evalModule(cleanHandler, {
171
171
  filename: import.meta.url,
172
172
  async: true,
173
- conditions: silgiConfig.conditions
173
+ conditions: silgiConfig.conditions,
174
+ forceTranspile: true
174
175
  });
175
176
  }
176
177
  }
@@ -1,4 +1,4 @@
1
- const version = "0.8.35";
1
+ const version = "0.8.37";
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.35";
1
+ const version = "0.8.37";
2
2
  const devDependencies = {
3
3
  "@antfu/eslint-config": "^4.2.0",
4
4
  "@fastify/deepmerge": "^2.0.2",
@@ -0,0 +1,33 @@
1
+ import type { FetchContext, FetchOptions } from 'ofetch';
2
+ import type { SilgiRouterTypes } from 'silgi/types';
3
+ type TrimAfterFourSlashes<T extends string> = T extends `/${infer S1}/${infer S2}/${infer S3}/${infer S4}/${infer _}` ? `/${S1}/${S2}/${S3}/${S4}` : T;
4
+ type AllPaths = SilgiRouterTypes extends {
5
+ keys: infer U;
6
+ } ? keyof U extends never ? string : keyof U : string;
7
+ type ExtractPathParams<T extends string> = T extends `${infer _Start}:${infer Param}/${infer Rest}` ? {
8
+ [K in Param]: string;
9
+ } & ExtractPathParams<Rest> : T extends `${infer _Start}:${infer Param}` ? {
10
+ [K in Param]: string;
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<R extends ValidRoute, M extends Method<R>> = {
24
+ method: M;
25
+ } & RequestBodyOption<R, M> & (RouterParams<R> extends object ? {
26
+ params?: RouterParams<R>;
27
+ } : {
28
+ params?: never;
29
+ }) & Omit<FetchOptions, 'query' | 'body' | 'method'>;
30
+ 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>>;
31
+ export declare function silgiFetchRequestInterceptor(ctx: FetchContext): void;
32
+ export declare function createSilgiFetch(options: FetchOptions | ((options: FetchOptions) => FetchOptions), localFetch?: typeof globalThis.$fetch): SilgiFetchClient;
33
+ export {};
@@ -0,0 +1,36 @@
1
+ export function silgiFetchRequestInterceptor(ctx) {
2
+ ctx.request = fillPath(ctx.request, ctx.options.path);
3
+ }
4
+ export function createSilgiFetch(options, localFetch) {
5
+ return (url, opts) => {
6
+ const finalOpts = {
7
+ ...typeof options === "function" ? options(opts) : options,
8
+ ...opts,
9
+ method: opts.method || "get"
10
+ };
11
+ const $fetch = getFetch(url, finalOpts, localFetch);
12
+ return $fetch(fillPath(url, opts.params), finalOpts);
13
+ };
14
+ }
15
+ function getFetch(url, opts, localFetch) {
16
+ if (import.meta.server && localFetch) {
17
+ const isLocalFetch = url[0] === "/" && (!opts.baseURL || opts.baseURL[0] === "/");
18
+ if (isLocalFetch)
19
+ return localFetch;
20
+ }
21
+ return globalThis.$fetch;
22
+ }
23
+ function fillPath(path, params) {
24
+ if (!params) {
25
+ if (path.includes(":"))
26
+ throw new Error("Parametreler dogru kullanmal\u0131s\u0131n\u0131z");
27
+ return path;
28
+ }
29
+ if (!path.includes(":"))
30
+ throw new Error("Path parametler : ile belirtilmelidir");
31
+ let result = path;
32
+ for (const [key, value] of Object.entries(params)) {
33
+ result = result.replace(`:${key}`, value);
34
+ }
35
+ return result;
36
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.8.35",
4
+ "version": "0.8.37",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {