silgi 0.34.1 → 0.34.2

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
  #!/usr/bin/env node
2
2
  import { defineCommand, runMain } from 'citty';
3
3
 
4
- const version = "0.34.1";
4
+ const version = "0.34.2";
5
5
  const packageJson = {
6
6
  version: version};
7
7
 
@@ -595,10 +595,9 @@ async function orchestrate(route, event) {
595
595
  );
596
596
  success = true;
597
597
  }
598
- await silgiCtx.callHook("execute:after", {
598
+ await silgiCtx.callHook("fetch:after", {
599
599
  url: silgiURL,
600
600
  input,
601
- event,
602
601
  result,
603
602
  success,
604
603
  modules: setup.modules
@@ -610,9 +609,8 @@ async function orchestrate(route, event) {
610
609
  }
611
610
  return result;
612
611
  } catch (err) {
613
- await silgiCtx.callHook("execute:error", {
612
+ await silgiCtx.callHook("fetch:error", {
614
613
  input,
615
- event,
616
614
  error: err instanceof Error ? err : new Error(String(err)),
617
615
  url: silgiURL
618
616
  });
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  createError as createH3Error,
3
3
  defineEventHandler,
4
- H3Error,
5
- readBody
4
+ getRequestWebStream,
5
+ H3Error
6
6
  } from "h3";
7
7
  import {
8
8
  createError,
@@ -22,14 +22,14 @@ export async function addNitroApp(silgiContext = useSilgi()) {
22
22
  event.path,
23
23
  {
24
24
  method: event.method.toUpperCase(),
25
- body: event.method.toUpperCase() === "GET" ? void 0 : await readBody(event).catch(() => void 0)
25
+ body: event.method.toUpperCase() === "GET" ? void 0 : getRequestWebStream(event),
26
+ headers: event.headers
26
27
  }
27
28
  );
28
29
  if (!resolvedRoute.ok) {
29
- await silgiContext.callHook("execute:error", {
30
+ await silgiContext.callHook("fetch:error", {
30
31
  error: new Error(resolvedRoute.statusText),
31
- url: silgiURL,
32
- event
32
+ url: silgiURL
33
33
  });
34
34
  silgiContext.captureError(
35
35
  silgiContext,
@@ -39,7 +39,6 @@ export async function addNitroApp(silgiContext = useSilgi()) {
39
39
  statusMessage: resolvedRoute.statusText
40
40
  }),
41
41
  {
42
- event,
43
42
  url: silgiURL,
44
43
  tags: ["execute"]
45
44
  }
@@ -61,10 +60,9 @@ export async function addNitroApp(silgiContext = useSilgi()) {
61
60
  cause: err
62
61
  });
63
62
  }
64
- await silgiContext.callHook("execute:error", {
63
+ await silgiContext.callHook("fetch:error", {
65
64
  error: err instanceof Error ? err : new Error(String(err)),
66
- url: silgiURL,
67
- event
65
+ url: silgiURL
68
66
  });
69
67
  silgiContext.captureError(
70
68
  silgiContext,
@@ -2,7 +2,7 @@ import { ApifulConfig } from 'apiful/config';
2
2
  import { C12InputConfig, ResolvedConfig, ConfigWatcher, WatchConfigOptions } from 'c12';
3
3
  import { ChokidarOptions } from 'chokidar';
4
4
  import { DateString, CompatibilityDateSpec, CompatibilityDates } from 'compatx';
5
- import { ConsolaInstance, ConsolaOptions, LogLevel } from 'consola';
5
+ import { ConsolaInstance, LogLevel, ConsolaOptions } from 'consola';
6
6
  import { Hookable, NestedHooks } from 'hookable';
7
7
  import { Ignore, Options } from 'ignore';
8
8
  import { TSConfig } from 'pkg-types';
@@ -11,7 +11,7 @@ import { SilgiRuntimeShareds as SilgiRuntimeShareds$1, ModuleMeta as ModuleMeta$
11
11
  import { Adapter, TablesSchema, InferModelTypes } from 'unadapter/types';
12
12
  import { UnimportPluginOptions } from 'unimport/unplugin';
13
13
  import * as h3 from 'h3';
14
- import { HTTPMethod as HTTPMethod$1, Session, H3Event } from 'h3';
14
+ import { H3Event, HTTPMethod as HTTPMethod$1, Session } from 'h3';
15
15
  import * as nitropack_types from 'nitropack/types';
16
16
  import { NitroRuntimeConfig } from 'nitropack/types';
17
17
  import { Defu } from 'defu';
@@ -21,9 +21,10 @@ import { ESMImport, ESMCodeGenOptions } from 'knitwork';
21
21
  import { Unimport } from 'unimport';
22
22
  import { Storage, TransactionOptions, BuiltinDriverName, StorageValue } from 'unstorage';
23
23
  import { StandardSchemaV1 } from '@standard-schema/spec';
24
+ import { ProviderName } from 'std-env';
25
+ import { ServerRequest } from 'srvx';
24
26
  import { RouterContext } from 'rou3';
25
27
  import { silgiFetch } from 'silgi';
26
- import { ProviderName } from 'std-env';
27
28
  import { FetchOptions, FetchResponse } from 'ofetch';
28
29
 
29
30
  interface SilgiCompatibilityIssue {
@@ -315,35 +316,6 @@ interface GenerateAppOptions {
315
316
  filter?: (template: ResolvedSilgiTemplate<any>) => boolean;
316
317
  }
317
318
 
318
- type TrimAfterFourSlashes<T extends string> = T extends `/${infer S1}/${infer S2}/${infer S3}/${infer S4}/${infer _}` ? `/${S1}/${S2}/${S3}/${S4}` : T;
319
- type AllPaths = SilgiRouterTypes extends {
320
- keys: infer U;
321
- } ? keyof U extends never ? string : keyof U : string;
322
- type ExtractPathParams<T extends string> = T extends `${infer _Start}:${infer Param}/${infer Rest}` ? {
323
- [K in Param]: string;
324
- } & ExtractPathParams<Rest> : T extends `${infer _Start}:${infer Param}` ? {
325
- [K in Param]: string;
326
- } : unknown;
327
-
328
- type HttpMethod = 'get' | 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'head' | 'patch' | 'post' | 'put' | 'delete' | 'connect' | 'options' | 'trace';
329
- type RouterParams<R extends AllPaths | (string & {})> = ExtractPathParams<R>;
330
- 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]> = {
331
- method?: M;
332
- params?: ExtractPathParams<P>;
333
- body?: SilgiRouterTypes[BasePath][M]['input'];
334
- } & Omit<FetchOptions, 'method' | 'body' | 'params'>;
335
- type SilgiFetchClient = <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<P, BasePath, M>) => Promise<FetchResponse<SilgiRouterTypes[BasePath][M]['output']>>;
336
-
337
- interface SilgiAppPlugin {
338
- (silgi: Silgi): Promise<void> | void;
339
- }
340
-
341
- interface CapturedErrorContext {
342
- event?: SilgiEvent;
343
- [key: string]: unknown;
344
- }
345
- type CaptureError = (silgi: Silgi, error: Error, context: CapturedErrorContext) => void;
346
-
347
319
  /**
348
320
  * Yardımcı tipler
349
321
  */
@@ -424,247 +396,8 @@ interface SilgiURL {
424
396
  methodName: string;
425
397
  path: string;
426
398
  raw: string;
427
- pathParams?: Record<string, string | undefined>;
428
- queryParams?: Record<string, string>;
429
- }
430
-
431
- /**
432
- * The listeners to Silgi
433
- */
434
- interface SilgiRuntimeHooks {
435
- /**
436
- * Called after Silgi initialization, when the Silgi instance is ready to work.
437
- * @param silgi The configured Silgi object
438
- * @returns Promise
439
- */
440
- 'ready': (silgi: Silgi) => HookResult;
441
- /**
442
- * Called when silgi instance is gracefully closing.
443
- * @param silgi The configured silgi object
444
- * @returns Promise
445
- */
446
- 'close': (silgi: Silgi) => HookResult;
447
- 'app:setup:start': (silgi: Silgi) => HookResult;
448
- 'request:on': (event: SilgiEvent) => HookResult;
449
- 'execute:after': (context: ModuleHookContext) => HookResult;
450
- 'execute:error': (context: ModuleHookContext) => HookResult;
451
- 'execute:finally': (context: ModuleHookContext) => HookResult;
452
- 'event:init': (event: SilgiEvent, data: {
453
- path: string;
454
- queryParams?: Record<string, string>;
455
- url: SilgiURL;
456
- }) => HookResult;
457
- 'error': CaptureError;
458
- }
459
-
460
- type CustomDriverName = string & {
461
- _custom?: any;
462
- };
463
- interface StorageMounts {
464
- [path: string]: {
465
- driver: BuiltinDriverName | CustomDriverName;
466
- [option: string]: any;
467
- };
468
- }
469
- interface SilgiStorageBase {
470
- }
471
- type StorageKeyGenerator<TInput> = (input: TInput) => string | Promise<string>;
472
- interface StorageConfig<TInput> {
473
- options: TransactionOptions;
474
- base: 'memory' | keyof SilgiStorageBase;
475
- key?: StorageKeyGenerator<TInput>;
476
- scope?: 'request' | 'global';
477
- }
478
- interface StorageKeyParams<TInput = unknown> {
479
- url: SilgiURL;
480
- input: TInput;
481
- requestId?: string;
482
- keyGenerator?: StorageKeyGenerator<TInput>;
483
- storageOptions?: Pick<StorageConfig<TInput>, 'base' | 'options' | 'scope'>;
484
- }
485
-
486
- interface SilgiRuntimeConfig {
487
- }
488
- interface SilgiOptions {
489
- consolaOptions?: Partial<ConsolaOptions>;
490
- present: PresetNameInput;
491
- hooks: Partial<SilgiRuntimeHooks & DefaultHooks>;
492
- /**
493
- * Set to `true` to enable debug mode.
494
- *
495
- * At the moment, it prints out hook names and timings on the server, and logs hook arguments as well in the browser.
496
- *
497
- * @default false
498
- */
499
- debug: boolean;
500
- storage: StorageMounts;
501
- putStorage?: Storage<StorageValue>;
502
- runtimeConfig: SilgiRuntimeConfig & {
503
- [key: string]: any;
504
- };
505
- captureError: CaptureError;
506
- adapters: Record<string, Adapter<Record<string, any>, TablesSchema, InferModelTypes<TablesSchema>>>;
507
- [key: string]: any;
508
- }
509
-
510
- interface SilgiSchema {
511
- }
512
- interface MergedSilgiSchema {
513
- }
514
- /**
515
- * Utility type for schema generics to avoid repetition
516
- */
517
- interface SchemaParams<TInput extends StandardSchemaV1 | undefined = undefined, TOutput extends StandardSchemaV1 | undefined = undefined, TPathParams extends StandardSchemaV1 | undefined = undefined, TQueryParams extends StandardSchemaV1 | undefined = undefined, TSource extends StandardSchemaV1 | undefined = undefined> {
518
- input?: TInput;
519
- output?: TOutput;
520
- pathParams?: TPathParams;
521
- queryParams?: TQueryParams;
522
- source?: TSource;
523
- }
524
- /**
525
- * Defines the structure for schema components within a service endpoint.
526
- * Allows specifying schemas for input, output, path parameters, query parameters, and source data.
527
- * @template TInput - The schema type for the request body/input.
528
- * @template TOutput - The schema type for the response body/output.
529
- * @template TPathParams - The schema type for URL path parameters.
530
- * @template TQueryParams - The schema type for URL query parameters.
531
- * @template TSource - The schema type for the source data or context.
532
- */
533
- type SchemaDefinition<TInput extends StandardSchemaV1 | undefined = undefined, TOutput extends StandardSchemaV1 | undefined = undefined, TPathParams extends StandardSchemaV1 | undefined = undefined, TQueryParams extends StandardSchemaV1 | undefined = undefined, TSource extends StandardSchemaV1 | undefined = undefined> = SchemaParams<TInput, TOutput, TPathParams, TQueryParams, TSource>;
534
- /**
535
- * ResolvedServiceDefinition: ServiceDefinition with generics resolved.
536
- * Represents the fully resolved service definition structure.
537
- */
538
- interface ResolvedSchemaDefinition {
539
- [route: string]: {
540
- [method in HTTPMethod$1]: {
541
- input?: StandardSchemaV1;
542
- output?: StandardSchemaV1;
543
- pathParams?: StandardSchemaV1;
544
- queryParams?: StandardSchemaV1;
545
- source?: StandardSchemaV1;
546
- };
547
- };
548
- }
549
-
550
- interface SilgiRuntimeShareds extends SilgiRuntimeSharedsExtend {
551
- storage: <T extends StorageValue = StorageValue>(base: StorageConfig<T>['base']) => Storage<T>;
552
- runtimeConfig: SilgiRuntimeConfig;
553
- $fetch: typeof silgiFetch;
554
- }
555
- interface SilgiRuntimeSharedsExtend {
556
- }
557
- interface ExtendShared {
558
- }
559
-
560
- interface FrameworkContext {
561
- }
562
- type HTTPMethod = 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE';
563
- interface SilgiRoute {
564
- route: string;
565
- method?: HTTPMethod;
566
- setup: ServiceSetup;
567
- schema: ResolvedSchemaDefinition;
568
- }
569
- interface Silgi {
570
- router: RouterContext<SilgiRoute>;
571
- routerPrefixs: string[];
572
- schemas: ResolvedSchemaDefinition;
573
- services: ResolvedServiceDefinition;
574
- shared: SilgiRuntimeShareds;
575
- plugins: SilgiAppPlugin[];
576
- framework: FrameworkContext;
577
- _ignore?: Ignore;
578
- hooks: Hookable<SilgiRuntimeHooks & DefaultHooks>;
579
- hook: Silgi['hooks']['hook'];
580
- callHook: Silgi['hooks']['callHook'];
581
- addHooks: Silgi['hooks']['addHooks'];
582
- ready: () => Promise<void>;
583
- close: () => Promise<void>;
584
- logger: ConsolaInstance;
585
- storage: Storage;
586
- envOptions: EnvOptions;
587
- options: SilgiOptions & SilgiRuntimeOptions;
588
- captureError: CaptureError;
589
- }
590
- interface SilgiConfig extends Partial<Omit<Silgi, 'options'>>, Partial<SilgiRuntimeOptions> {
591
- options: DeepPartial<SilgiOptions>;
592
- }
593
- interface BuildSilgi {
594
- framework: FrameworkContext;
595
- modules?: Partial<SilgiRuntimeOptions>;
596
- options?: Partial<SilgiOptions>;
597
- }
598
- type CustomRequestInit<Schema extends SilgiSchema = SilgiSchema, Route extends keyof Schema = keyof Schema, Method extends keyof Schema[Route] = keyof Schema[Route], _Resolved extends boolean = true, _HiddenParameters extends boolean = true> = Omit<RequestInit, 'body' | 'headers' | 'method'> & {
599
- method: Method;
600
- body?: Route extends keyof Schema ? Method extends keyof Schema[Route] ? Schema[Route][Method] extends {
601
- input?: infer I;
602
- } ? I extends StandardSchemaV1 ? StandardSchemaV1.InferInput<I> : unknown : unknown : unknown : unknown;
603
- headers?: Route extends keyof Schema ? Method extends keyof Schema[Route] ? Schema[Route][Method] extends {
604
- headers?: infer H;
605
- } ? H extends StandardSchemaV1 ? StandardSchemaV1.InferInput<H> : unknown : unknown : unknown : unknown;
606
- } & (Route extends keyof Schema ? Method extends keyof Schema[Route] ? Schema[Route][Method] extends {
607
- pathParams?: infer P;
608
- } ? P extends StandardSchemaV1 ? {
609
- pathParams: StandardSchemaV1.InferInput<P>;
610
- } : {
611
- pathParams?: unknown;
612
- } : {
613
- pathParams?: unknown;
614
- } : {
615
- pathParams?: unknown;
616
- } : {
617
- pathParams?: unknown;
618
- });
619
-
620
- interface ExtendContext {
621
- }
622
- interface SilgiRuntimeContext extends Record<string, any> {
623
- params?: Record<string, string>;
624
- /**
625
- * Matched router Node
626
- *
627
- * @experimental The object structure may change in non-major version.
628
- */
629
- matchedRoute?: SilgiRoute;
630
- sessions?: Record<string, Session>;
631
- clientAddress?: string;
632
- source?: any;
633
- }
634
- interface ServerRequest extends Request {
635
- /**
636
- * IP address of the client.
637
- */
638
- ip?: string | undefined;
639
- }
640
- /**
641
- * Bu nitrojs, h3 event or request context.
642
- */
643
- interface SilgiEvent extends Record<string, unknown> {
644
- /**
645
- * Event context.
646
- */
647
- readonly context: SilgiRuntimeContext;
648
- /**
649
- * Incoming HTTP request info.
650
- *
651
- * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Request)
652
- */
653
- readonly req: ServerRequest;
654
- /**
655
- * Access to the parsed request URL.
656
- *
657
- * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/URL)
658
- */
659
- readonly url: URL;
660
- /**
661
- * Prepared HTTP response.
662
- */
663
- readonly res: {
664
- status?: number;
665
- statusText?: string;
666
- readonly headers: Headers;
667
- };
399
+ pathParams?: Record<string, string | undefined>;
400
+ queryParams?: Record<string, string>;
668
401
  }
669
402
 
670
403
  interface SilgiRuntimeActions {
@@ -722,7 +455,6 @@ interface ResolvedModuleMeta extends ModuleMeta {
722
455
  name: string;
723
456
  }
724
457
  type ModuleHookContext = Readonly<{
725
- event: SilgiEvent;
726
458
  url: SilgiURL;
727
459
  input?: unknown;
728
460
  result?: unknown;
@@ -1067,6 +799,264 @@ interface LoadConfigOptions {
1067
799
  consola?: ConsolaInstance;
1068
800
  }
1069
801
 
802
+ type TrimAfterFourSlashes<T extends string> = T extends `/${infer S1}/${infer S2}/${infer S3}/${infer S4}/${infer _}` ? `/${S1}/${S2}/${S3}/${S4}` : T;
803
+ type AllPaths = SilgiRouterTypes extends {
804
+ keys: infer U;
805
+ } ? keyof U extends never ? string : keyof U : string;
806
+ type ExtractPathParams<T extends string> = T extends `${infer _Start}:${infer Param}/${infer Rest}` ? {
807
+ [K in Param]: string;
808
+ } & ExtractPathParams<Rest> : T extends `${infer _Start}:${infer Param}` ? {
809
+ [K in Param]: string;
810
+ } : unknown;
811
+
812
+ type HttpMethod = 'get' | 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'head' | 'patch' | 'post' | 'put' | 'delete' | 'connect' | 'options' | 'trace';
813
+ type RouterParams<R extends AllPaths | (string & {})> = ExtractPathParams<R>;
814
+ 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]> = {
815
+ method?: M;
816
+ params?: ExtractPathParams<P>;
817
+ body?: SilgiRouterTypes[BasePath][M]['input'];
818
+ } & Omit<FetchOptions, 'method' | 'body' | 'params'>;
819
+ type SilgiFetchClient = <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<P, BasePath, M>) => Promise<FetchResponse<SilgiRouterTypes[BasePath][M]['output']>>;
820
+
821
+ interface SilgiAppPlugin {
822
+ (silgi: Silgi): Promise<void> | void;
823
+ }
824
+
825
+ interface CapturedErrorContext {
826
+ event?: SilgiEvent;
827
+ [key: string]: unknown;
828
+ }
829
+ type CaptureError = (silgi: Silgi, error: Error, context: CapturedErrorContext) => void;
830
+
831
+ interface SilgiSchema {
832
+ }
833
+ interface MergedSilgiSchema {
834
+ }
835
+ /**
836
+ * Utility type for schema generics to avoid repetition
837
+ */
838
+ interface SchemaParams<TInput extends StandardSchemaV1 | undefined = undefined, TOutput extends StandardSchemaV1 | undefined = undefined, TPathParams extends StandardSchemaV1 | undefined = undefined, TQueryParams extends StandardSchemaV1 | undefined = undefined, TSource extends StandardSchemaV1 | undefined = undefined> {
839
+ input?: TInput;
840
+ output?: TOutput;
841
+ pathParams?: TPathParams;
842
+ queryParams?: TQueryParams;
843
+ source?: TSource;
844
+ }
845
+ /**
846
+ * Defines the structure for schema components within a service endpoint.
847
+ * Allows specifying schemas for input, output, path parameters, query parameters, and source data.
848
+ * @template TInput - The schema type for the request body/input.
849
+ * @template TOutput - The schema type for the response body/output.
850
+ * @template TPathParams - The schema type for URL path parameters.
851
+ * @template TQueryParams - The schema type for URL query parameters.
852
+ * @template TSource - The schema type for the source data or context.
853
+ */
854
+ type SchemaDefinition<TInput extends StandardSchemaV1 | undefined = undefined, TOutput extends StandardSchemaV1 | undefined = undefined, TPathParams extends StandardSchemaV1 | undefined = undefined, TQueryParams extends StandardSchemaV1 | undefined = undefined, TSource extends StandardSchemaV1 | undefined = undefined> = SchemaParams<TInput, TOutput, TPathParams, TQueryParams, TSource>;
855
+ /**
856
+ * ResolvedServiceDefinition: ServiceDefinition with generics resolved.
857
+ * Represents the fully resolved service definition structure.
858
+ */
859
+ interface ResolvedSchemaDefinition {
860
+ [route: string]: {
861
+ [method in HTTPMethod$1]: {
862
+ input?: StandardSchemaV1;
863
+ output?: StandardSchemaV1;
864
+ pathParams?: StandardSchemaV1;
865
+ queryParams?: StandardSchemaV1;
866
+ source?: StandardSchemaV1;
867
+ };
868
+ };
869
+ }
870
+
871
+ type CustomDriverName = string & {
872
+ _custom?: any;
873
+ };
874
+ interface StorageMounts {
875
+ [path: string]: {
876
+ driver: BuiltinDriverName | CustomDriverName;
877
+ [option: string]: any;
878
+ };
879
+ }
880
+ interface SilgiStorageBase {
881
+ }
882
+ type StorageKeyGenerator<TInput> = (input: TInput) => string | Promise<string>;
883
+ interface StorageConfig<TInput> {
884
+ options: TransactionOptions;
885
+ base: 'memory' | keyof SilgiStorageBase;
886
+ key?: StorageKeyGenerator<TInput>;
887
+ scope?: 'request' | 'global';
888
+ }
889
+ interface StorageKeyParams<TInput = unknown> {
890
+ url: SilgiURL;
891
+ input: TInput;
892
+ requestId?: string;
893
+ keyGenerator?: StorageKeyGenerator<TInput>;
894
+ storageOptions?: Pick<StorageConfig<TInput>, 'base' | 'options' | 'scope'>;
895
+ }
896
+
897
+ interface SilgiRuntimeShareds extends SilgiRuntimeSharedsExtend {
898
+ storage: <T extends StorageValue = StorageValue>(base: StorageConfig<T>['base']) => Storage<T>;
899
+ runtimeConfig: SilgiRuntimeConfig;
900
+ $fetch: typeof silgiFetch;
901
+ }
902
+ interface SilgiRuntimeSharedsExtend {
903
+ }
904
+ interface ExtendShared {
905
+ }
906
+
907
+ interface FrameworkContext {
908
+ }
909
+ type HTTPMethod = 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE';
910
+ interface SilgiRoute {
911
+ route: string;
912
+ method?: HTTPMethod;
913
+ setup: ServiceSetup;
914
+ schema: ResolvedSchemaDefinition;
915
+ }
916
+ interface Silgi {
917
+ router: RouterContext<SilgiRoute>;
918
+ routerPrefixs: string[];
919
+ schemas: ResolvedSchemaDefinition;
920
+ services: ResolvedServiceDefinition;
921
+ shared: SilgiRuntimeShareds;
922
+ plugins: SilgiAppPlugin[];
923
+ framework: FrameworkContext;
924
+ _ignore?: Ignore;
925
+ hooks: Hookable<SilgiRuntimeHooks & DefaultHooks>;
926
+ hook: Silgi['hooks']['hook'];
927
+ callHook: Silgi['hooks']['callHook'];
928
+ addHooks: Silgi['hooks']['addHooks'];
929
+ ready: () => Promise<void>;
930
+ close: () => Promise<void>;
931
+ logger: ConsolaInstance;
932
+ storage: Storage;
933
+ envOptions: EnvOptions;
934
+ options: SilgiOptions & SilgiRuntimeOptions;
935
+ captureError: CaptureError;
936
+ }
937
+ interface SilgiConfig extends Partial<Omit<Silgi, 'options'>>, Partial<SilgiRuntimeOptions> {
938
+ options: DeepPartial<SilgiOptions>;
939
+ }
940
+ interface BuildSilgi {
941
+ framework: FrameworkContext;
942
+ modules?: Partial<SilgiRuntimeOptions>;
943
+ options?: Partial<SilgiOptions>;
944
+ }
945
+ type CustomRequestInit<Schema extends SilgiSchema = SilgiSchema, Route extends keyof Schema = keyof Schema, Method extends keyof Schema[Route] = keyof Schema[Route], _Resolved extends boolean = true, _HiddenParameters extends boolean = true> = Omit<RequestInit, 'body' | 'headers' | 'method'> & {
946
+ method: Method;
947
+ body?: Route extends keyof Schema ? Method extends keyof Schema[Route] ? Schema[Route][Method] extends {
948
+ input?: infer I;
949
+ } ? I extends StandardSchemaV1 ? StandardSchemaV1.InferInput<I> : unknown : unknown : unknown : unknown;
950
+ headers?: Route extends keyof Schema ? Method extends keyof Schema[Route] ? Schema[Route][Method] extends {
951
+ headers?: infer H;
952
+ } ? H extends StandardSchemaV1 ? StandardSchemaV1.InferInput<H> : unknown : unknown : unknown : unknown;
953
+ } & (Route extends keyof Schema ? Method extends keyof Schema[Route] ? Schema[Route][Method] extends {
954
+ pathParams?: infer P;
955
+ } ? P extends StandardSchemaV1 ? {
956
+ pathParams: StandardSchemaV1.InferInput<P>;
957
+ } : {
958
+ pathParams?: unknown;
959
+ } : {
960
+ pathParams?: unknown;
961
+ } : {
962
+ pathParams?: unknown;
963
+ } : {
964
+ pathParams?: unknown;
965
+ });
966
+
967
+ interface ExtendContext {
968
+ }
969
+ interface SilgiRuntimeContext extends Record<string, any> {
970
+ params?: Record<string, string>;
971
+ /**
972
+ * Matched router Node
973
+ *
974
+ * @experimental The object structure may change in non-major version.
975
+ */
976
+ matchedRoute?: SilgiRoute;
977
+ sessions?: Record<string, Session>;
978
+ clientAddress?: string;
979
+ source?: any;
980
+ }
981
+ /**
982
+ * Bu nitrojs, h3 event or request context.
983
+ */
984
+ interface SilgiEvent extends Record<string, unknown> {
985
+ /**
986
+ * Event context.
987
+ */
988
+ readonly context: SilgiRuntimeContext;
989
+ /**
990
+ * Incoming HTTP request info.
991
+ *
992
+ * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Request)
993
+ */
994
+ readonly req: ServerRequest;
995
+ /**
996
+ * Access to the parsed request URL.
997
+ *
998
+ * [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/URL)
999
+ */
1000
+ readonly url: URL;
1001
+ /**
1002
+ * Prepared HTTP response.
1003
+ */
1004
+ readonly res: {
1005
+ status?: number;
1006
+ statusText?: string;
1007
+ readonly headers: Headers;
1008
+ };
1009
+ }
1010
+
1011
+ /**
1012
+ * The listeners to Silgi
1013
+ */
1014
+ interface SilgiRuntimeHooks {
1015
+ /**
1016
+ * Called after Silgi initialization, when the Silgi instance is ready to work.
1017
+ * @param silgi The configured Silgi object
1018
+ * @returns Promise
1019
+ */
1020
+ 'ready': (silgi: Silgi) => HookResult;
1021
+ /**
1022
+ * Called when silgi instance is gracefully closing.
1023
+ * @param silgi The configured silgi object
1024
+ * @returns Promise
1025
+ */
1026
+ 'close': (silgi: Silgi) => HookResult;
1027
+ 'app:setup:start': (silgi: Silgi) => HookResult;
1028
+ 'request:on': (event: SilgiEvent) => HookResult;
1029
+ 'fetch:before': (context: ModuleHookContext) => HookResult;
1030
+ 'fetch:after': (context: ModuleHookContext) => HookResult;
1031
+ 'fetch:error': (context: Omit<ModuleHookContext, 'event'>) => HookResult;
1032
+ 'fetch:finally': (context: Omit<ModuleHookContext, 'event'>) => HookResult;
1033
+ 'error': CaptureError;
1034
+ }
1035
+
1036
+ interface SilgiRuntimeConfig {
1037
+ }
1038
+ interface SilgiOptions {
1039
+ consolaOptions?: Partial<ConsolaOptions>;
1040
+ present: PresetNameInput;
1041
+ hooks: Partial<SilgiRuntimeHooks & DefaultHooks>;
1042
+ /**
1043
+ * Set to `true` to enable debug mode.
1044
+ *
1045
+ * At the moment, it prints out hook names and timings on the server, and logs hook arguments as well in the browser.
1046
+ *
1047
+ * @default false
1048
+ */
1049
+ debug: boolean;
1050
+ storage: StorageMounts;
1051
+ putStorage?: Storage<StorageValue>;
1052
+ runtimeConfig: SilgiRuntimeConfig & {
1053
+ [key: string]: any;
1054
+ };
1055
+ captureError: CaptureError;
1056
+ adapters: Record<string, Adapter<Record<string, any>, TablesSchema, InferModelTypes<TablesSchema>>>;
1057
+ [key: string]: any;
1058
+ }
1059
+
1070
1060
  interface DotenvOptions {
1071
1061
  /**
1072
1062
  * The project root directory (either absolute or relative to the current working directory).
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.34.1",
4
+ "version": "0.34.2",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {