silgi 0.3.8 → 0.3.9

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.
@@ -3,7 +3,7 @@ import consola from 'consola';
3
3
 
4
4
  const name = "silgi";
5
5
  const type = "module";
6
- const version = "0.3.8";
6
+ const version = "0.3.9";
7
7
  const packageManager = "pnpm@9.15.1";
8
8
  const sideEffects = false;
9
9
  const exports = {
@@ -83,7 +83,8 @@ const peerDependencies = {
83
83
  nitropack: "^2.10.4",
84
84
  nuxt: "^3.15.3",
85
85
  typescript: "^5.7.3",
86
- zod: "^3.24.1"
86
+ zod: "^3.24.1",
87
+ vue: "^3.5.13"
87
88
  };
88
89
  const peerDependenciesMeta = {
89
90
  "@nuxt/kit": {
@@ -100,6 +101,9 @@ const peerDependenciesMeta = {
100
101
  },
101
102
  zod: {
102
103
  optional: true
104
+ },
105
+ vue: {
106
+ optional: true
103
107
  }
104
108
  };
105
109
  const dependencies = {
@@ -142,6 +146,7 @@ const devDependencies = {
142
146
  nuxt: "^3.15.3",
143
147
  unbuild: "^3.3.1",
144
148
  vitest: "^3.0.3",
149
+ vue: "^3.5.13",
145
150
  zod: "^3.24.1"
146
151
  };
147
152
  const resolutions = {
@@ -1,13 +1,19 @@
1
- import type { AvailableRouterMethod, NitroFetchRequest } from 'nitropack';
2
- import type { UseFetchOptions } from 'nuxt/app';
3
- import type { FetchError } from 'ofetch';
4
- import type { SilgiRouterTypes } from 'silgi';
5
- export type KeysOf<T> = Array<T extends T ? keyof T extends string ? keyof T : never : never>;
6
- export declare function useSilgiFetch<Route extends keyof SilgiRouterTypes, Method extends Extract<keyof SilgiRouterTypes[Route], string>, ResT = SilgiRouterTypes[Route][Method] extends {
7
- output: any;
8
- } ? SilgiRouterTypes[Route][Method]['output'] : never, ErrorT = FetchError>(request: Route | (() => Route), opts?: Omit<UseFetchOptions<ResT extends void ? unknown : ResT, ResT extends void ? unknown : ResT, KeysOf<ResT extends void ? unknown : ResT>, ResT extends void ? unknown : ResT, NitroFetchRequest, ResT extends void ? 'get' : AvailableRouterMethod<NitroFetchRequest>>, 'method' | 'body' | 'default' | 'transform' | 'pick' | 'getCachedData'> & {
9
- method?: Method;
10
- body?: SilgiRouterTypes[Route][Method] extends {
11
- input: any;
12
- } ? SilgiRouterTypes[Route][Method]['input'] : never;
13
- }): import("nuxt/app").AsyncData<import("nuxt/dist/app/composables/asyncData").PickFrom<(ResT extends void ? unknown : ResT) extends infer T ? T extends (ResT extends void ? unknown : ResT) ? T extends void ? unknown : T : never : never, import("nuxt/dist/app/composables/asyncData").KeysOf<(ResT extends void ? unknown : ResT) extends infer T_1 ? T_1 extends (ResT extends void ? unknown : ResT) ? T_1 extends void ? unknown : T_1 : never : never>> | null, ErrorT | null>;
1
+ import type { AsyncData, UseFetchOptions } from 'nuxt/app';
2
+ import type { $Fetch } from 'ofetch';
3
+ import type { Ref } from 'vue';
4
+ import type { FetchResponseData, FetchResponseError, FilterMethods, ParamsOption, RequestBodyOption, SilgiRouterTypes } from 'silgi';
5
+ export type OpenFetchClientName = 'ofetch';
6
+ type PickFrom<T, K extends Array<string>> = T extends Array<any> ? T : T extends Record<string, any> ? keyof T extends K[number] ? T : K[number] extends never ? T : Pick<T, K[number]> : T;
7
+ type KeysOf<T> = Array<T extends T ? keyof T extends string ? keyof T : never : never>;
8
+ type ComputedOptions<T> = {
9
+ [K in keyof T]: T[K] extends Function ? T[K] : ComputedOptions<T[K]> | Ref<T[K]> | T[K];
10
+ };
11
+ type ComputedMethodOption<M, P> = 'get' extends keyof P ? ComputedOptions<{
12
+ method?: M;
13
+ }> : ComputedOptions<{
14
+ method: M;
15
+ }>;
16
+ type UseOpenFetchOptions<ReqT extends keyof SilgiRouterTypes, Method extends keyof SilgiRouterTypes[ReqT], LowercasedMethod, Params, ResT, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null, Operation = 'get' extends LowercasedMethod ? ('get' extends keyof Params ? Params['get'] : never) : LowercasedMethod extends keyof Params ? Params[LowercasedMethod] : never> = ComputedMethodOption<Method, Params> & ComputedOptions<ParamsOption<Operation>> & ComputedOptions<RequestBodyOption<ReqT, Method>> & Omit<UseFetchOptions<ResT, DataT, PickKeys, DefaultT>, 'query' | 'body' | 'method'>;
17
+ export type UseOpenFetchClient<Paths extends keyof SilgiRouterTypes, Lazy extends boolean> = <Methods extends FilterMethods<Paths>, Method extends Extract<keyof Methods, string> | Uppercase<Extract<keyof Methods, string>>, LowercasedMethod extends Lowercase<Method> extends keyof Methods ? Lowercase<Method> : never, DefaultMethod extends 'get' extends LowercasedMethod ? 'get' : LowercasedMethod, ResT = Methods[DefaultMethod] extends Record<string | number, any> ? FetchResponseData<Paths, Method> : never, ErrorT = Methods[DefaultMethod] extends Record<string | number, any> ? FetchResponseError<Methods[DefaultMethod]> : never, DataT = ResT, PickKeys extends KeysOf<DataT> = KeysOf<DataT>, DefaultT = null>(url: Paths | (() => Paths), options?: Lazy extends true ? Omit<UseOpenFetchOptions<Paths, Method, LowercasedMethod, Methods, ResT, DataT, PickKeys, DefaultT>, 'lazy'> : UseOpenFetchOptions<Paths, Method, LowercasedMethod, Methods, ResT, DataT, PickKeys, DefaultT>, autoKey?: string) => AsyncData<PickFrom<DataT, PickKeys> | DefaultT, ErrorT | null>;
18
+ export declare function createUseOpenFetch<Paths extends keyof SilgiRouterTypes, Lazy extends boolean = false>(client: $Fetch | OpenFetchClientName, lazy?: Lazy): UseOpenFetchClient<Paths, Lazy>;
19
+ export {};
@@ -1,10 +1,10 @@
1
- import { useFetch } from "nuxt/app";
2
- export function useSilgiFetch(request, opts = {}) {
3
- const { method, body, ...rest } = opts;
4
- return useFetch(request, {
5
- ...rest,
6
- // key,
7
- body,
8
- method: method ?? "get"
9
- });
1
+ import { useFetch, useNuxtApp } from "nuxt/app";
2
+ import { toValue } from "vue";
3
+ export function createUseOpenFetch(client, lazy = false) {
4
+ return (url, options = {}, autoKey) => {
5
+ const nuxtApp = useNuxtApp();
6
+ const $fetch = typeof client === "string" ? nuxtApp[`$${client}`] : client;
7
+ const opts = { $fetch, key: autoKey, ...options };
8
+ return useFetch(() => toValue(url), lazy ? { ...opts, lazy } : opts);
9
+ };
10
10
  }
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { b as SilgiConfig, c as SilgiHelper, d as SilgiRouterTypes, S as SilgiOptions, M as ModuleOptions, e as ModuleDefinition, f as SilgiModule, B as BaseSchemaType, g as SilgiServiceInterface, h as DefaultNamespaces, i as Silgi, j as SilgiOperation, k as MergedSilgiSchema, l as ServiceType, m as SilgiSchema, R as RequiredServiceType, n as SilgiModuleShared } from './shared/silgi.ClpvycKI.mjs';
2
2
  export { F as Awaitable, G as CreateScope, D as DeepPartial, C as DefaultHooks, A as DefaultMethods, E as ExtendShared, u as ExtractInputFromURI, v as ExtractOutputFromURI, w as ExtractRouterParamsFromURI, s as SilgiDefaultShared, o as SilgiEvent, z as SilgiHook, p as SilgiModuleMethods, a as SilgiModuleOptions, q as SilgiModules, r as SilgiNamespaces, x as SilgiStorageBase, t as SilgiURIs, U as URIsTypes, y as silgi } from './shared/silgi.ClpvycKI.mjs';
3
- import { FetchOptions } from 'ofetch';
3
+ import { FetchError, FetchContext, FetchOptions } from 'ofetch';
4
4
  import { LoadConfigOptions } from 'c12';
5
5
  import { StandardSchemaV1 } from '@standard-schema/spec';
6
6
  import * as unctx_index from 'unctx/index';
@@ -56,6 +56,19 @@ declare class SilgiError extends Error {
56
56
  static isSilgiError(error: unknown): error is SilgiError;
57
57
  }
58
58
 
59
+ type FetchResponseData<Route extends keyof SilgiRouterTypes, Method extends keyof SilgiRouterTypes[Route]> = SilgiRouterTypes[Route][Method] extends {
60
+ output: any;
61
+ } ? SilgiRouterTypes[Route][Method]['output'] : never;
62
+ type FetchResponseError<T extends Record<string | number, any>> = FetchError;
63
+ type MethodOption<M, P> = 'get' extends keyof P ? {
64
+ method?: M;
65
+ } : {
66
+ method: M;
67
+ };
68
+ type ParamsOption<T> = T extends {
69
+ parameters?: any;
70
+ query?: any;
71
+ } ? T['parameters'] : Record<string, never>;
59
72
  type RequestBodyOption<Route extends keyof SilgiRouterTypes, Method extends keyof SilgiRouterTypes[Route]> = SilgiRouterTypes[Route][Method] extends {
60
73
  input: any;
61
74
  } ? {
@@ -70,13 +83,13 @@ type RouterParams<Route extends keyof SilgiRouterTypes, Method extends keyof Sil
70
83
  } : {
71
84
  params?: never;
72
85
  };
86
+ type FilterMethods<T extends keyof SilgiRouterTypes> = keyof SilgiRouterTypes[T];
73
87
  type DefaultMethod<Route extends keyof SilgiRouterTypes> = keyof SilgiRouterTypes[Route];
74
- type SilgiFetchOptions<Route extends keyof SilgiRouterTypes, Method extends keyof SilgiRouterTypes[Route] = keyof SilgiRouterTypes[Route]> = {
88
+ type SilgiFetchOptions<Route extends keyof SilgiRouterTypes, Method extends keyof SilgiRouterTypes[Route] = DefaultMethod<Route>> = {
75
89
  method?: Method;
76
90
  } & RequestBodyOption<Route, Method> & RouterParams<Route, Method> & Omit<FetchOptions, 'query' | 'body' | 'method'>;
77
- type SilgiFetchClient = <Route extends keyof SilgiRouterTypes, Method extends keyof SilgiRouterTypes[Route] = DefaultMethod<Route>>(url: Route, options?: SilgiFetchOptions<Route, Method>) => Promise<SilgiRouterTypes[Route][Method] extends {
78
- output: any;
79
- } ? SilgiRouterTypes[Route][Method]['output'] : any>;
91
+ type SilgiFetchClient = <Route extends keyof SilgiRouterTypes, Method extends keyof SilgiRouterTypes[Route] = DefaultMethod<Route>, ResT = FetchResponseData<Route, Method>>(url: Route, options?: SilgiFetchOptions<Route, Method>) => Promise<ResT>;
92
+ declare function silgiFetchRequestInterceptor(ctx: FetchContext): void;
80
93
  declare function createSilgiFetch(options: FetchOptions | ((options: FetchOptions) => FetchOptions), localFetch?: typeof globalThis.$fetch): SilgiFetchClient;
81
94
 
82
95
  interface LoadSilgiConfigOptions extends Omit<LoadConfigOptions<SilgiOptions>, 'overrides'> {
@@ -181,4 +194,4 @@ declare function createSchema<T extends Partial<Record<keyof DefaultNamespaces,
181
194
  };
182
195
  };
183
196
 
184
- export { DefaultNamespaces, type ExtendContext, MergedSilgiSchema, type Namespaces, ServiceType, Silgi, SilgiError, SilgiHelper, type SilgiModuleContext, SilgiModuleShared, SilgiOptions, SilgiRouterTypes, SilgiSchema, createResolver, createSchema, createService, createShared, createSilgi, createSilgiFetch, defineSilgiModule, loadSilgiConfig, mergeSchemas, mergeServices, mergeShared, normalizeResult, parseURI, relativeWithDot, silgiCtx, tryUseSilgi, useHook, useShared, useSilgi };
197
+ export { DefaultNamespaces, type ExtendContext, type FetchResponseData, type FetchResponseError, type FilterMethods, MergedSilgiSchema, type MethodOption, type Namespaces, type ParamsOption, type RequestBodyOption, type RouterParams, ServiceType, Silgi, SilgiError, type SilgiFetchClient, SilgiHelper, type SilgiModuleContext, SilgiModuleShared, SilgiOptions, SilgiRouterTypes, SilgiSchema, createResolver, createSchema, createService, createShared, createSilgi, createSilgiFetch, defineSilgiModule, loadSilgiConfig, mergeSchemas, mergeServices, mergeShared, normalizeResult, parseURI, relativeWithDot, silgiCtx, silgiFetchRequestInterceptor, tryUseSilgi, useHook, useShared, useSilgi };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { b as SilgiConfig, c as SilgiHelper, d as SilgiRouterTypes, S as SilgiOptions, M as ModuleOptions, e as ModuleDefinition, f as SilgiModule, B as BaseSchemaType, g as SilgiServiceInterface, h as DefaultNamespaces, i as Silgi, j as SilgiOperation, k as MergedSilgiSchema, l as ServiceType, m as SilgiSchema, R as RequiredServiceType, n as SilgiModuleShared } from './shared/silgi.ClpvycKI.js';
2
2
  export { F as Awaitable, G as CreateScope, D as DeepPartial, C as DefaultHooks, A as DefaultMethods, E as ExtendShared, u as ExtractInputFromURI, v as ExtractOutputFromURI, w as ExtractRouterParamsFromURI, s as SilgiDefaultShared, o as SilgiEvent, z as SilgiHook, p as SilgiModuleMethods, a as SilgiModuleOptions, q as SilgiModules, r as SilgiNamespaces, x as SilgiStorageBase, t as SilgiURIs, U as URIsTypes, y as silgi } from './shared/silgi.ClpvycKI.js';
3
- import { FetchOptions } from 'ofetch';
3
+ import { FetchError, FetchContext, FetchOptions } from 'ofetch';
4
4
  import { LoadConfigOptions } from 'c12';
5
5
  import { StandardSchemaV1 } from '@standard-schema/spec';
6
6
  import * as unctx_index from 'unctx/index';
@@ -56,6 +56,19 @@ declare class SilgiError extends Error {
56
56
  static isSilgiError(error: unknown): error is SilgiError;
57
57
  }
58
58
 
59
+ type FetchResponseData<Route extends keyof SilgiRouterTypes, Method extends keyof SilgiRouterTypes[Route]> = SilgiRouterTypes[Route][Method] extends {
60
+ output: any;
61
+ } ? SilgiRouterTypes[Route][Method]['output'] : never;
62
+ type FetchResponseError<T extends Record<string | number, any>> = FetchError;
63
+ type MethodOption<M, P> = 'get' extends keyof P ? {
64
+ method?: M;
65
+ } : {
66
+ method: M;
67
+ };
68
+ type ParamsOption<T> = T extends {
69
+ parameters?: any;
70
+ query?: any;
71
+ } ? T['parameters'] : Record<string, never>;
59
72
  type RequestBodyOption<Route extends keyof SilgiRouterTypes, Method extends keyof SilgiRouterTypes[Route]> = SilgiRouterTypes[Route][Method] extends {
60
73
  input: any;
61
74
  } ? {
@@ -70,13 +83,13 @@ type RouterParams<Route extends keyof SilgiRouterTypes, Method extends keyof Sil
70
83
  } : {
71
84
  params?: never;
72
85
  };
86
+ type FilterMethods<T extends keyof SilgiRouterTypes> = keyof SilgiRouterTypes[T];
73
87
  type DefaultMethod<Route extends keyof SilgiRouterTypes> = keyof SilgiRouterTypes[Route];
74
- type SilgiFetchOptions<Route extends keyof SilgiRouterTypes, Method extends keyof SilgiRouterTypes[Route] = keyof SilgiRouterTypes[Route]> = {
88
+ type SilgiFetchOptions<Route extends keyof SilgiRouterTypes, Method extends keyof SilgiRouterTypes[Route] = DefaultMethod<Route>> = {
75
89
  method?: Method;
76
90
  } & RequestBodyOption<Route, Method> & RouterParams<Route, Method> & Omit<FetchOptions, 'query' | 'body' | 'method'>;
77
- type SilgiFetchClient = <Route extends keyof SilgiRouterTypes, Method extends keyof SilgiRouterTypes[Route] = DefaultMethod<Route>>(url: Route, options?: SilgiFetchOptions<Route, Method>) => Promise<SilgiRouterTypes[Route][Method] extends {
78
- output: any;
79
- } ? SilgiRouterTypes[Route][Method]['output'] : any>;
91
+ type SilgiFetchClient = <Route extends keyof SilgiRouterTypes, Method extends keyof SilgiRouterTypes[Route] = DefaultMethod<Route>, ResT = FetchResponseData<Route, Method>>(url: Route, options?: SilgiFetchOptions<Route, Method>) => Promise<ResT>;
92
+ declare function silgiFetchRequestInterceptor(ctx: FetchContext): void;
80
93
  declare function createSilgiFetch(options: FetchOptions | ((options: FetchOptions) => FetchOptions), localFetch?: typeof globalThis.$fetch): SilgiFetchClient;
81
94
 
82
95
  interface LoadSilgiConfigOptions extends Omit<LoadConfigOptions<SilgiOptions>, 'overrides'> {
@@ -181,4 +194,4 @@ declare function createSchema<T extends Partial<Record<keyof DefaultNamespaces,
181
194
  };
182
195
  };
183
196
 
184
- export { DefaultNamespaces, type ExtendContext, MergedSilgiSchema, type Namespaces, ServiceType, Silgi, SilgiError, SilgiHelper, type SilgiModuleContext, SilgiModuleShared, SilgiOptions, SilgiRouterTypes, SilgiSchema, createResolver, createSchema, createService, createShared, createSilgi, createSilgiFetch, defineSilgiModule, loadSilgiConfig, mergeSchemas, mergeServices, mergeShared, normalizeResult, parseURI, relativeWithDot, silgiCtx, tryUseSilgi, useHook, useShared, useSilgi };
197
+ export { DefaultNamespaces, type ExtendContext, type FetchResponseData, type FetchResponseError, type FilterMethods, MergedSilgiSchema, type MethodOption, type Namespaces, type ParamsOption, type RequestBodyOption, type RouterParams, ServiceType, Silgi, SilgiError, type SilgiFetchClient, SilgiHelper, type SilgiModuleContext, SilgiModuleShared, SilgiOptions, SilgiRouterTypes, SilgiSchema, createResolver, createSchema, createService, createShared, createSilgi, createSilgiFetch, defineSilgiModule, loadSilgiConfig, mergeSchemas, mergeServices, mergeShared, normalizeResult, parseURI, relativeWithDot, silgiCtx, silgiFetchRequestInterceptor, tryUseSilgi, useHook, useShared, useSilgi };
package/dist/index.mjs CHANGED
@@ -376,6 +376,9 @@ async function createSilgi(config) {
376
376
  return silgi.options.helper;
377
377
  }
378
378
 
379
+ function silgiFetchRequestInterceptor(ctx) {
380
+ ctx.request = fillPath(ctx.request, ctx.options.path);
381
+ }
379
382
  function createSilgiFetch(options, localFetch) {
380
383
  return (url, opts = {}) => {
381
384
  opts = typeof options === "function" ? options(opts) : { ...options, ...opts };
@@ -493,4 +496,4 @@ function createSchema(silgiType) {
493
496
  return silgiType;
494
497
  }
495
498
 
496
- export { SilgiError, SilgiHelper, createSchema, createService, createShared, createSilgi, createSilgiFetch, defineSilgiModule, mergeSchemas, mergeServices, mergeShared, normalizeResult, parseURI, silgi, silgiCtx, tryUseSilgi, useSilgi };
499
+ export { SilgiError, SilgiHelper, createSchema, createService, createShared, createSilgi, createSilgiFetch, defineSilgiModule, mergeSchemas, mergeServices, mergeShared, normalizeResult, parseURI, silgi, silgiCtx, silgiFetchRequestInterceptor, tryUseSilgi, useSilgi };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.3.8",
4
+ "version": "0.3.9",
5
5
  "sideEffects": false,
6
6
  "exports": {
7
7
  ".": {
@@ -66,7 +66,8 @@
66
66
  "nitropack": "^2.10.4",
67
67
  "nuxt": "^3.15.3",
68
68
  "typescript": "^5.7.3",
69
- "zod": "^3.24.1"
69
+ "zod": "^3.24.1",
70
+ "vue": "^3.5.13"
70
71
  },
71
72
  "peerDependenciesMeta": {
72
73
  "@nuxt/kit": {
@@ -83,6 +84,9 @@
83
84
  },
84
85
  "zod": {
85
86
  "optional": true
87
+ },
88
+ "vue": {
89
+ "optional": true
86
90
  }
87
91
  },
88
92
  "dependencies": {
@@ -125,6 +129,7 @@
125
129
  "nuxt": "^3.15.3",
126
130
  "unbuild": "^3.3.1",
127
131
  "vitest": "^3.0.3",
132
+ "vue": "^3.5.13",
128
133
  "zod": "^3.24.1"
129
134
  },
130
135
  "resolutions": {