silgi 0.3.1 → 0.3.3

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,7 +1,7 @@
1
1
  import * as unstorage from 'unstorage';
2
2
  import * as net from 'net';
3
3
  import * as consola from 'consola';
4
- import { D as DeepPartial, S as SilgiOptions, a as SilgiModuleOptions } from '../shared/silgi.DJkQv6rh.mjs';
4
+ import { D as DeepPartial, S as SilgiOptions, a as SilgiModuleOptions } from '../shared/silgi.Bv3UrLx7.mjs';
5
5
  import 'hookable';
6
6
  import 'ignore';
7
7
  import '@standard-schema/spec';
@@ -1,7 +1,7 @@
1
1
  import * as unstorage from 'unstorage';
2
2
  import * as net from 'net';
3
3
  import * as consola from 'consola';
4
- import { D as DeepPartial, S as SilgiOptions, a as SilgiModuleOptions } from '../shared/silgi.DJkQv6rh.js';
4
+ import { D as DeepPartial, S as SilgiOptions, a as SilgiModuleOptions } from '../shared/silgi.Bv3UrLx7.js';
5
5
  import 'hookable';
6
6
  import 'ignore';
7
7
  import '@standard-schema/spec';
@@ -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.1";
6
+ const version = "0.3.3";
7
7
  const packageManager = "pnpm@9.15.1";
8
8
  const sideEffects = false;
9
9
  const exports = {
@@ -99,6 +99,7 @@ const dependencies = {
99
99
  klona: "^2.0.6",
100
100
  mlly: "^1.7.4",
101
101
  nitropack: "^2.10.4",
102
+ ofetch: "^1.4.1",
102
103
  pathe: "^2.0.2",
103
104
  "pkg-types": "^1.3.1",
104
105
  scule: "^1.3.0",
@@ -22,7 +22,7 @@ const module = defineNuxtModule({
22
22
  nuxt.options.nitro.modules ||= [];
23
23
  nuxt.options.nitro.modules.push(await resolvePath("silgi/ecosystem/nitro"));
24
24
  nuxt.hook("prepare:types", ({ references }) => {
25
- references.push({ path: relativeWithDot(nuxt.options.buildDir, join(silgi.options.buildDir, "silgi.d.ts")) });
25
+ references.push({ path: relativeWithDot(nuxt.options.buildDir, join(silgi.buildDir, "silgi.d.ts")) });
26
26
  });
27
27
  }
28
28
  });
package/dist/index.d.mts CHANGED
@@ -1,5 +1,6 @@
1
- import { b as SilgiConfig, c as SilgiHelper, M as ModuleOptions, d as ModuleDefinition, e as SilgiModule, B as BaseSchemaType, f as SilgiServiceInterface, g as DefaultNamespaces, h as Silgi, i as SilgiOperation, j as MergedSilgiSchema, k as ServiceType, l as SilgiSchema, R as RequiredServiceType, m as SilgiModuleShared } from './shared/silgi.DJkQv6rh.mjs';
2
- export { F as Awaitable, G as CreateScope, D as DeepPartial, C as DefaultHooks, A as DefaultMethods, E as ExtendShared, t as ExtractInputFromURI, u as ExtractOutputFromURI, v as ExtractRouterParamsFromURI, r as SilgiDefaultShared, n as SilgiEvent, z as SilgiHook, o as SilgiModuleMethods, a as SilgiModuleOptions, p as SilgiModules, q as SilgiNamespaces, S as SilgiOptions, y as SilgiRouterTypes, w as SilgiStorageBase, s as SilgiURIs, U as URIsTypes, x as silgi } from './shared/silgi.DJkQv6rh.mjs';
1
+ import { b as SilgiConfig, c as SilgiHelper, d as SilgiRouterTypes, 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.Bv3UrLx7.mjs';
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, S as SilgiOptions, x as SilgiStorageBase, t as SilgiURIs, U as URIsTypes, y as silgi } from './shared/silgi.Bv3UrLx7.mjs';
3
+ import { FetchOptions } from 'ofetch';
3
4
  import { StandardSchemaV1 } from '@standard-schema/spec';
4
5
  import * as unctx_index from 'unctx/index';
5
6
  import 'consola';
@@ -54,6 +55,22 @@ declare class SilgiError extends Error {
54
55
  static isSilgiError(error: unknown): error is SilgiError;
55
56
  }
56
57
 
58
+ type RequestBodyOption<Route extends keyof SilgiRouterTypes, Method extends keyof SilgiRouterTypes[Route]> = SilgiRouterTypes[Route][Method] extends {
59
+ input: any;
60
+ } ? {
61
+ body?: SilgiRouterTypes[Route][Method]['input'];
62
+ } : {
63
+ body?: never;
64
+ };
65
+ type DefaultMethod<Route extends keyof SilgiRouterTypes> = keyof SilgiRouterTypes[Route];
66
+ type SilgiFetchOptions<Route extends keyof SilgiRouterTypes, Method extends keyof SilgiRouterTypes[Route] = keyof SilgiRouterTypes[Route]> = {
67
+ method?: Method;
68
+ } & RequestBodyOption<Route, Method> & Omit<FetchOptions, 'query' | 'body' | 'method'>;
69
+ type SilgiFetchClient = <Route extends keyof SilgiRouterTypes, Method extends keyof SilgiRouterTypes[Route] = DefaultMethod<Route>>(url: Route, options?: SilgiFetchOptions<Route, Method>) => Promise<SilgiRouterTypes[Route][Method] extends {
70
+ output: any;
71
+ } ? SilgiRouterTypes[Route][Method]['output'] : any>;
72
+ declare function createSilgiFetch(options: FetchOptions | ((options: FetchOptions) => FetchOptions), localFetch?: typeof globalThis.$fetch): SilgiFetchClient;
73
+
57
74
  /**
58
75
  * Define a Nuxt module, automatically merging defaults with user provided options, installing
59
76
  * any hooks that are provided, and calling an optional setup function for full control.
@@ -151,4 +168,4 @@ declare function createSchema<T extends Partial<Record<keyof DefaultNamespaces,
151
168
  };
152
169
  };
153
170
 
154
- export { DefaultNamespaces, type ExtendContext, MergedSilgiSchema, type Namespaces, ServiceType, Silgi, SilgiError, SilgiHelper, type SilgiModuleContext, SilgiModuleShared, SilgiSchema, createResolver, createSchema, createService, createShared, createSilgi, defineSilgiModule, mergeSchemas, mergeServices, mergeShared, normalizeResult, parseURI, relativeWithDot, silgiCtx, tryUseSilgi, useHook, useShared, useSilgi };
171
+ export { DefaultNamespaces, type ExtendContext, MergedSilgiSchema, type Namespaces, ServiceType, Silgi, SilgiError, SilgiHelper, type SilgiModuleContext, SilgiModuleShared, SilgiRouterTypes, SilgiSchema, createResolver, createSchema, createService, createShared, createSilgi, createSilgiFetch, defineSilgiModule, mergeSchemas, mergeServices, mergeShared, normalizeResult, parseURI, relativeWithDot, silgiCtx, tryUseSilgi, useHook, useShared, useSilgi };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { b as SilgiConfig, c as SilgiHelper, M as ModuleOptions, d as ModuleDefinition, e as SilgiModule, B as BaseSchemaType, f as SilgiServiceInterface, g as DefaultNamespaces, h as Silgi, i as SilgiOperation, j as MergedSilgiSchema, k as ServiceType, l as SilgiSchema, R as RequiredServiceType, m as SilgiModuleShared } from './shared/silgi.DJkQv6rh.js';
2
- export { F as Awaitable, G as CreateScope, D as DeepPartial, C as DefaultHooks, A as DefaultMethods, E as ExtendShared, t as ExtractInputFromURI, u as ExtractOutputFromURI, v as ExtractRouterParamsFromURI, r as SilgiDefaultShared, n as SilgiEvent, z as SilgiHook, o as SilgiModuleMethods, a as SilgiModuleOptions, p as SilgiModules, q as SilgiNamespaces, S as SilgiOptions, y as SilgiRouterTypes, w as SilgiStorageBase, s as SilgiURIs, U as URIsTypes, x as silgi } from './shared/silgi.DJkQv6rh.js';
1
+ import { b as SilgiConfig, c as SilgiHelper, d as SilgiRouterTypes, 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.Bv3UrLx7.js';
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, S as SilgiOptions, x as SilgiStorageBase, t as SilgiURIs, U as URIsTypes, y as silgi } from './shared/silgi.Bv3UrLx7.js';
3
+ import { FetchOptions } from 'ofetch';
3
4
  import { StandardSchemaV1 } from '@standard-schema/spec';
4
5
  import * as unctx_index from 'unctx/index';
5
6
  import 'consola';
@@ -54,6 +55,22 @@ declare class SilgiError extends Error {
54
55
  static isSilgiError(error: unknown): error is SilgiError;
55
56
  }
56
57
 
58
+ type RequestBodyOption<Route extends keyof SilgiRouterTypes, Method extends keyof SilgiRouterTypes[Route]> = SilgiRouterTypes[Route][Method] extends {
59
+ input: any;
60
+ } ? {
61
+ body?: SilgiRouterTypes[Route][Method]['input'];
62
+ } : {
63
+ body?: never;
64
+ };
65
+ type DefaultMethod<Route extends keyof SilgiRouterTypes> = keyof SilgiRouterTypes[Route];
66
+ type SilgiFetchOptions<Route extends keyof SilgiRouterTypes, Method extends keyof SilgiRouterTypes[Route] = keyof SilgiRouterTypes[Route]> = {
67
+ method?: Method;
68
+ } & RequestBodyOption<Route, Method> & Omit<FetchOptions, 'query' | 'body' | 'method'>;
69
+ type SilgiFetchClient = <Route extends keyof SilgiRouterTypes, Method extends keyof SilgiRouterTypes[Route] = DefaultMethod<Route>>(url: Route, options?: SilgiFetchOptions<Route, Method>) => Promise<SilgiRouterTypes[Route][Method] extends {
70
+ output: any;
71
+ } ? SilgiRouterTypes[Route][Method]['output'] : any>;
72
+ declare function createSilgiFetch(options: FetchOptions | ((options: FetchOptions) => FetchOptions), localFetch?: typeof globalThis.$fetch): SilgiFetchClient;
73
+
57
74
  /**
58
75
  * Define a Nuxt module, automatically merging defaults with user provided options, installing
59
76
  * any hooks that are provided, and calling an optional setup function for full control.
@@ -151,4 +168,4 @@ declare function createSchema<T extends Partial<Record<keyof DefaultNamespaces,
151
168
  };
152
169
  };
153
170
 
154
- export { DefaultNamespaces, type ExtendContext, MergedSilgiSchema, type Namespaces, ServiceType, Silgi, SilgiError, SilgiHelper, type SilgiModuleContext, SilgiModuleShared, SilgiSchema, createResolver, createSchema, createService, createShared, createSilgi, defineSilgiModule, mergeSchemas, mergeServices, mergeShared, normalizeResult, parseURI, relativeWithDot, silgiCtx, tryUseSilgi, useHook, useShared, useSilgi };
171
+ export { DefaultNamespaces, type ExtendContext, MergedSilgiSchema, type Namespaces, ServiceType, Silgi, SilgiError, SilgiHelper, type SilgiModuleContext, SilgiModuleShared, SilgiRouterTypes, SilgiSchema, createResolver, createSchema, createService, createShared, createSilgi, createSilgiFetch, defineSilgiModule, mergeSchemas, mergeServices, mergeShared, normalizeResult, parseURI, relativeWithDot, silgiCtx, tryUseSilgi, useHook, useShared, useSilgi };
package/dist/index.mjs CHANGED
@@ -375,6 +375,29 @@ async function createSilgi(config) {
375
375
  return silgi.options.helper;
376
376
  }
377
377
 
378
+ function createSilgiFetch(options, localFetch) {
379
+ return (url, opts = {}) => {
380
+ opts = typeof options === "function" ? options(opts) : { ...options, ...opts };
381
+ if (!opts.method)
382
+ opts.method = "get";
383
+ const $fetch = getFetch(url, opts, localFetch);
384
+ return $fetch(fillPath(url, opts?.path), opts);
385
+ };
386
+ }
387
+ function getFetch(url, opts, localFetch) {
388
+ if (import.meta.server && localFetch) {
389
+ const isLocalFetch = url[0] === "/" && (!opts.baseURL || opts.baseURL[0] === "/");
390
+ if (isLocalFetch)
391
+ return localFetch;
392
+ }
393
+ return globalThis.$fetch;
394
+ }
395
+ function fillPath(path, params = {}) {
396
+ for (const [k, v] of Object.entries(params))
397
+ path = path.replace(`{${k}}`, encodeURIComponent(String(v)));
398
+ return path;
399
+ }
400
+
378
401
  function defineSilgiModule(definition) {
379
402
  if (definition) {
380
403
  return _defineSilgiModule(definition);
@@ -469,4 +492,4 @@ function createSchema(silgiType) {
469
492
  return silgiType;
470
493
  }
471
494
 
472
- export { SilgiError, SilgiHelper, createSchema, createService, createShared, createSilgi, defineSilgiModule, mergeSchemas, mergeServices, mergeShared, normalizeResult, parseURI, silgi, silgiCtx, tryUseSilgi, useSilgi };
495
+ export { SilgiError, SilgiHelper, createSchema, createService, createShared, createSilgi, createSilgiFetch, defineSilgiModule, mergeSchemas, mergeServices, mergeShared, normalizeResult, parseURI, silgi, silgiCtx, tryUseSilgi, useSilgi };
@@ -805,4 +805,4 @@ interface SilgiConfig extends Pick<Silgi, 'services' | 'shared' | 'uris' | 'sche
805
805
  }
806
806
  type SilgiFunction = typeof silgi;
807
807
 
808
- export { type DefaultMethods as A, type BaseSchemaType as B, type DefaultHooks as C, type DeepPartial as D, type ExtendShared as E, type Awaitable as F, type CreateScope as G, type ModuleOptions as M, type RequiredServiceType as R, type SilgiOptions as S, type URIsTypes as U, type SilgiModuleOptions as a, type SilgiConfig as b, SilgiHelper as c, type ModuleDefinition as d, type SilgiModule as e, type SilgiServiceInterface as f, type DefaultNamespaces as g, type Silgi as h, type SilgiOperation as i, type MergedSilgiSchema as j, type ServiceType as k, type SilgiSchema as l, type SilgiModuleShared as m, type SilgiEvent as n, type SilgiModuleMethods as o, type SilgiModules as p, type SilgiNamespaces as q, type SilgiDefaultShared as r, type SilgiURIs as s, type ExtractInputFromURI as t, type ExtractOutputFromURI as u, type ExtractRouterParamsFromURI as v, type SilgiStorageBase as w, silgi as x, type SilgiRouterTypes as y, type SilgiHook as z };
808
+ export { type DefaultMethods as A, type BaseSchemaType as B, type DefaultHooks as C, type DeepPartial as D, type ExtendShared as E, type Awaitable as F, type CreateScope as G, type ModuleOptions as M, type RequiredServiceType as R, type SilgiOptions as S, type URIsTypes as U, type SilgiModuleOptions as a, type SilgiConfig as b, SilgiHelper as c, type SilgiRouterTypes as d, type ModuleDefinition as e, type SilgiModule as f, type SilgiServiceInterface as g, type DefaultNamespaces as h, type Silgi as i, type SilgiOperation as j, type MergedSilgiSchema as k, type ServiceType as l, type SilgiSchema as m, type SilgiModuleShared as n, type SilgiEvent as o, type SilgiModuleMethods as p, type SilgiModules as q, type SilgiNamespaces as r, type SilgiDefaultShared as s, type SilgiURIs as t, type ExtractInputFromURI as u, type ExtractOutputFromURI as v, type ExtractRouterParamsFromURI as w, type SilgiStorageBase as x, silgi as y, type SilgiHook as z };
@@ -805,4 +805,4 @@ interface SilgiConfig extends Pick<Silgi, 'services' | 'shared' | 'uris' | 'sche
805
805
  }
806
806
  type SilgiFunction = typeof silgi;
807
807
 
808
- export { type DefaultMethods as A, type BaseSchemaType as B, type DefaultHooks as C, type DeepPartial as D, type ExtendShared as E, type Awaitable as F, type CreateScope as G, type ModuleOptions as M, type RequiredServiceType as R, type SilgiOptions as S, type URIsTypes as U, type SilgiModuleOptions as a, type SilgiConfig as b, SilgiHelper as c, type ModuleDefinition as d, type SilgiModule as e, type SilgiServiceInterface as f, type DefaultNamespaces as g, type Silgi as h, type SilgiOperation as i, type MergedSilgiSchema as j, type ServiceType as k, type SilgiSchema as l, type SilgiModuleShared as m, type SilgiEvent as n, type SilgiModuleMethods as o, type SilgiModules as p, type SilgiNamespaces as q, type SilgiDefaultShared as r, type SilgiURIs as s, type ExtractInputFromURI as t, type ExtractOutputFromURI as u, type ExtractRouterParamsFromURI as v, type SilgiStorageBase as w, silgi as x, type SilgiRouterTypes as y, type SilgiHook as z };
808
+ export { type DefaultMethods as A, type BaseSchemaType as B, type DefaultHooks as C, type DeepPartial as D, type ExtendShared as E, type Awaitable as F, type CreateScope as G, type ModuleOptions as M, type RequiredServiceType as R, type SilgiOptions as S, type URIsTypes as U, type SilgiModuleOptions as a, type SilgiConfig as b, SilgiHelper as c, type SilgiRouterTypes as d, type ModuleDefinition as e, type SilgiModule as f, type SilgiServiceInterface as g, type DefaultNamespaces as h, type Silgi as i, type SilgiOperation as j, type MergedSilgiSchema as k, type ServiceType as l, type SilgiSchema as m, type SilgiModuleShared as n, type SilgiEvent as o, type SilgiModuleMethods as p, type SilgiModules as q, type SilgiNamespaces as r, type SilgiDefaultShared as s, type SilgiURIs as t, type ExtractInputFromURI as u, type ExtractOutputFromURI as v, type ExtractRouterParamsFromURI as w, type SilgiStorageBase as x, silgi as y, type SilgiHook as z };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.3.1",
4
+ "version": "0.3.3",
5
5
  "sideEffects": false,
6
6
  "exports": {
7
7
  ".": {
@@ -82,6 +82,7 @@
82
82
  "klona": "^2.0.6",
83
83
  "mlly": "^1.7.4",
84
84
  "nitropack": "^2.10.4",
85
+ "ofetch": "^1.4.1",
85
86
  "pathe": "^2.0.2",
86
87
  "pkg-types": "^1.3.1",
87
88
  "scule": "^1.3.0",