silgi 0.41.35 → 0.41.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,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { defineCommand, runMain } from 'citty';
3
3
 
4
- const version = "0.41.35";
4
+ const version = "0.41.37";
5
5
  const packageJson = {
6
6
  version: version};
7
7
 
@@ -1,6 +1,5 @@
1
1
  import { SilgiRuntimeConfig, SilgiConfig, Silgi, SilgiEvent, SilgiRuntimeContext, SilgiSchema, RouteEntry, CustomRequestInit, SilgiCLI, SilgiStorageBase, MergeAll, Routers, HTTPMethod, MiddlewareSetup, Resolvers, SilgiURL, BaseMethodSchema, ServiceSetupsForMethods, ServiceDefinitionByMethodAndPath, ServiceSetup, SilgiRuntimeShareds, StorageConfig } from 'silgi/types';
2
2
  import { ServerRequest } from 'srvx';
3
- import { GraphQLResolveInfo } from 'graphql';
4
3
  import { UseContext } from 'unctx';
5
4
  import { Storage, StorageValue } from 'unstorage';
6
5
  import { StandardSchemaV1 } from '@standard-schema/spec';
@@ -136,7 +135,7 @@ declare function silgiFetch(_request: Request | URL, options?: RequestInit & {
136
135
  pathParams?: Record<string, any>;
137
136
  }, context?: SilgiRuntimeContext): Promise<Response | Promise<Response>>;
138
137
  declare function middleware(event: SilgiEvent): Promise<any>;
139
- declare function handler(event: SilgiEvent, middlewareMode?: boolean, input?: any, parent?: any, info?: GraphQLResolveInfo, callBack?: () => any | Promise<any>): Promise<any>;
138
+ declare function handler(event: SilgiEvent): Promise<any>;
140
139
 
141
140
  declare const silgiCLICtx: UseContext<SilgiCLI>;
142
141
  declare function useSilgiCLI(): SilgiCLI;
@@ -238,8 +237,8 @@ declare function createSchema<Key extends string, Schema extends BaseMethodSchem
238
237
  * ServiceSetup tipinden oluşan bir yardımcı fonksiyon.
239
238
  * Tip güvenliğini artırmak için ServiceSetup objesini doğrudan döndürür.
240
239
  */
241
- declare function defineServiceSetup<Parent extends StandardSchemaV1, Method extends HTTPMethod, Path extends keyof Routers, Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | undefined | never = undefined, QueryParams extends StandardSchemaV1 | undefined | never = undefined, Resolved extends boolean = false, HiddenParameters extends boolean = false>(setup: Omit<ServiceSetup<Parent, Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>, 'method' | 'path'>): Omit<ServiceSetup<Parent, Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>, 'method' | 'path'>;
242
- declare function createService<Path extends string, Method extends HTTPMethod, Parent extends StandardSchemaV1 = StandardSchemaV1, Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | undefined | never = undefined, QueryParams extends StandardSchemaV1 | undefined | never = undefined, Resolved extends boolean = false, HiddenParameters extends boolean = false>(params: ServiceSetupsForMethods<Parent, Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>): ServiceDefinitionByMethodAndPath<Path, Method, Parent, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
240
+ declare function defineServiceSetup<Method extends HTTPMethod, Path extends keyof Routers, Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | undefined | never = undefined, QueryParams extends StandardSchemaV1 | undefined | never = undefined, Resolved extends boolean = false, HiddenParameters extends boolean = false>(setup: Omit<ServiceSetup<Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>, 'method' | 'path'>): Omit<ServiceSetup<Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>, 'method' | 'path'>;
241
+ declare function createService<Path extends string, Method extends HTTPMethod, Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | undefined | never = undefined, QueryParams extends StandardSchemaV1 | undefined | never = undefined, Resolved extends boolean = false, HiddenParameters extends boolean = false>(params: ServiceSetupsForMethods<Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>): ServiceDefinitionByMethodAndPath<Path, Method, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
243
242
 
244
243
  declare function createShared(shared: Partial<SilgiRuntimeShareds>): SilgiRuntimeShareds;
245
244
 
@@ -780,27 +780,20 @@ function getUrlPrefix(path, method) {
780
780
  };
781
781
  }
782
782
 
783
- async function orchestrate(route, event, _input, parent, info) {
783
+ async function orchestrate(route, event) {
784
784
  const silgiCtx = useSilgi();
785
- const isGraphQL = event.context.protocol === "GRAPHQL";
786
785
  const silgiURL = getUrlPrefix(route.route || event.req.url, route.method);
787
- const input = _input || (route.service?.rules?.readBeforeBody === false || isGraphQL ? {} : await parseRequestInput(event.req));
786
+ const input = route.service?.rules?.readBeforeBody === false ? {} : await parseRequestInput(event.req);
788
787
  const hookContext = { earlyReturnValue: false };
789
- const routerParams = _input ? input.path : getRouterParams(event);
790
- const queryParams = _input ? input.query : getQuery(event);
791
- if (_input?.path) {
792
- delete _input.path;
793
- }
794
- if (_input?.query) {
795
- delete _input.query;
796
- }
788
+ const routerParams = input.path || getRouterParams(event);
789
+ const queryParams = input.query || getQuery(event);
797
790
  const inputData = {
798
791
  args: input,
799
792
  query: queryParams,
800
793
  path: routerParams
801
794
  };
802
795
  try {
803
- if (!route.service && !isGraphQL) {
796
+ if (!route.service) {
804
797
  throw createError({
805
798
  statusCode: 404,
806
799
  statusMessage: "Service not found"
@@ -841,11 +834,7 @@ async function orchestrate(route, event, _input, parent, info) {
841
834
  // shared
842
835
  silgiCtx.shared,
843
836
  // event
844
- event,
845
- // parent - graphql
846
- parent,
847
- // info - graphql
848
- info
837
+ event
849
838
  );
850
839
  await silgiCtx.callHook("fetch:after", {
851
840
  event,
@@ -989,12 +978,7 @@ async function middleware(event) {
989
978
  if (_previous !== void 0 && _previous !== kNotFound) {
990
979
  return _previous;
991
980
  }
992
- const allowedMethod = m.method ?? "";
993
- const methodIsAllowed = allowedMethod === event.req.method || event.protocol === "GRAPHQL";
994
- if (!methodIsAllowed) {
995
- return;
996
- }
997
- if (!m.middleware) {
981
+ if (!(m.method === event.req.method) || !m.middleware) {
998
982
  return;
999
983
  }
1000
984
  try {
@@ -1055,7 +1039,7 @@ async function middleware(event) {
1055
1039
  }
1056
1040
  }
1057
1041
  }
1058
- async function handler(event, middlewareMode = false, input, parent, info, callBack) {
1042
+ async function handler(event) {
1059
1043
  await middleware(event);
1060
1044
  const silgiContext = useSilgi();
1061
1045
  if (silgiContext.router) {
@@ -1068,12 +1052,12 @@ async function handler(event, middlewareMode = false, input, parent, info, callB
1068
1052
  }
1069
1053
  event.context.params = match.params;
1070
1054
  event.context.matchedRoute = match.data;
1071
- return orchestrate(match.data, event, input, parent, info);
1055
+ return orchestrate(match.data, event);
1072
1056
  });
1073
1057
  } else {
1074
1058
  event.context.params = match.params;
1075
1059
  event.context.matchedRoute = match.data;
1076
- return orchestrate(match.data, event, input, parent, info);
1060
+ return orchestrate(match.data, event);
1077
1061
  }
1078
1062
  }
1079
1063
  }
package/dist/index.d.mts CHANGED
@@ -1,7 +1,6 @@
1
1
  export { SilgiError, SilgiHttpEvent, autoImportTypes, createError, createMiddleware, createResolver, createSchema, createService, createShared, createSilgi, createStorage, deepMergeObjects, defineServiceSetup, getEvent, getEventContext, getUrlPrefix, handleResponse, handler, isError, kHandled, kNotFound, middleware, replaceRuntimeValues, silgiCLICtx, silgiCtx, silgiFetch, storageMount, tryUseSilgi, tryUseSilgiCLI, updateRuntimeStorage, useRuntime, useSilgi, useSilgiCLI, useSilgiStorage } from './core/index.mjs';
2
2
  import 'silgi/types';
3
3
  import 'srvx';
4
- import 'graphql';
5
4
  import 'unctx';
6
5
  import 'unstorage';
7
6
  import '@standard-schema/spec';
@@ -23,7 +23,6 @@ import { RouterContext } from 'rou3';
23
23
  import { TransactionOptions, BuiltinDriverName, StorageValue, Storage } from 'unstorage';
24
24
  import { ServerRequest } from 'srvx';
25
25
  import { Defu } from 'defu';
26
- import { GraphQLResolveInfo } from 'graphql';
27
26
  import { silgiFetch } from 'silgi';
28
27
  import { useRuntimeConfig } from 'silgi/runtime';
29
28
  import { Unimport } from 'unimport';
@@ -228,6 +227,8 @@ interface ExtendShared {
228
227
 
229
228
  interface ServicesObject {
230
229
  }
230
+ type SlashCount<S extends string, Count extends any[] = []> = S extends `${infer _Prefix}/${infer Rest}` ? SlashCount<Rest, [any, ...Count]> : Count['length'];
231
+ type Max4Slashes<S extends keyof Routers> = SlashCount<S> extends 0 | 1 | 2 | 3 ? S : never;
231
232
  /**
232
233
  * Yardımcı tipler
233
234
  */
@@ -264,14 +265,14 @@ type ServiceHandlerInput<Input extends StandardSchemaV1 = StandardSchemaV1, Path
264
265
  * Resolved = false -> handler(input, shared, event, source) // all required
265
266
  * Resolved = true -> handler(input, shared?, event?, source?) // only input required
266
267
  */
267
- type ServiceHandler<Parent extends StandardSchemaV1, Input extends StandardSchemaV1, Output extends StandardSchemaV1, PathParams extends StandardSchemaV1 | never | undefined = never, QueryParams extends StandardSchemaV1 | never | undefined = never, Resolved extends boolean = false, HiddenParameters extends boolean = false> = Resolved extends true ? (input: ServiceHandlerInput<Input, PathParams, QueryParams, HiddenParameters>, shared?: SilgiRuntimeShareds, event?: SilgiEvent, parent?: Parent, info?: GraphQLResolveInfo) => Promise<InferOutput<Output>> | InferOutput<Output> : (input: ServiceHandlerInput<Input, PathParams, QueryParams, HiddenParameters>, shared: SilgiRuntimeShareds, event: SilgiEvent, parent?: Parent, info?: GraphQLResolveInfo) => Promise<InferOutput<Output>> | InferOutput<Output>;
268
+ type ServiceHandler<Input extends StandardSchemaV1, Output extends StandardSchemaV1, PathParams extends StandardSchemaV1 | never | undefined = never, QueryParams extends StandardSchemaV1 | never | undefined = never, Resolved extends boolean = false, HiddenParameters extends boolean = false> = Resolved extends true ? (input: ServiceHandlerInput<Input, PathParams, QueryParams, HiddenParameters>, shared?: SilgiRuntimeShareds, event?: SilgiEvent) => Promise<InferOutput<Output>> | InferOutput<Output> : (input: ServiceHandlerInput<Input, PathParams, QueryParams, HiddenParameters>, shared: SilgiRuntimeShareds, event: SilgiEvent) => Promise<InferOutput<Output>> | InferOutput<Output>;
268
269
  /**
269
270
  * Servis setup tipi
270
271
  */
271
- interface ServiceSetup<Parent extends StandardSchemaV1 = StandardSchemaV1, Method extends HTTPMethod = HTTPMethod, Path extends string = string, Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | undefined | never = undefined, QueryParams extends StandardSchemaV1 | undefined | never = undefined, Resolved extends boolean = false, HiddenParameters extends boolean = false> {
272
+ interface ServiceSetup<Method extends HTTPMethod = HTTPMethod, Path extends string = string, Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | undefined | never = undefined, QueryParams extends StandardSchemaV1 | undefined | never = undefined, Resolved extends boolean = false, HiddenParameters extends boolean = false> {
272
273
  path: Path;
273
274
  method: Method;
274
- handler?: ServiceHandler<Parent, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
275
+ handler?: ServiceHandler<Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
275
276
  rules?: MergeRouteRules;
276
277
  modules?: Partial<SetupModuleOption>;
277
278
  storage?: StorageConfig<ServiceHandlerInput<Input, PathParams, QueryParams, HiddenParameters>>;
@@ -304,7 +305,7 @@ interface SilgiURL {
304
305
  pathParams?: Record<string, string | undefined>;
305
306
  queryParams?: Record<string, string>;
306
307
  }
307
- type ServiceSetupsForMethods<Parent extends StandardSchemaV1 = StandardSchemaV1, Method extends HTTPMethod = HTTPMethod, Path extends string = string, Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | undefined | never = undefined, QueryParams extends StandardSchemaV1 | undefined | never = undefined, Resolved extends boolean = false, HiddenParameters extends boolean = false> = ServiceSetup<Parent, Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
308
+ type ServiceSetupsForMethods<Method extends HTTPMethod = HTTPMethod, Path extends string = string, Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | undefined | never = undefined, QueryParams extends StandardSchemaV1 | undefined | never = undefined, Resolved extends boolean = false, HiddenParameters extends boolean = false> = ServiceSetup<Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
308
309
  /**
309
310
  * Sadece belirtilen HTTP methodları için anahtar üretir.
310
311
  * Varsayılan olarak tüm methodlar çıkar.
@@ -313,8 +314,8 @@ type ServiceSetupsForMethods<Parent extends StandardSchemaV1 = StandardSchemaV1,
313
314
  * ServiceDefinitionByMethodAndPath<'/foo', ..., 'GET' | 'POST'>
314
315
  * // Sadece "GET:/foo" ve "POST:/foo" anahtarları olur.
315
316
  */
316
- type ServiceDefinitionByMethodAndPath<Path extends string, Method extends HTTPMethod = HTTPMethod, Parent extends StandardSchemaV1 = StandardSchemaV1, Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | undefined | never = undefined, QueryParams extends StandardSchemaV1 | undefined | never = undefined, Resolved extends boolean = false, HiddenParameters extends boolean = false> = {
317
- [M in Method as `${M}:${Path}`]?: ServiceSetup<Parent, M, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
317
+ type ServiceDefinitionByMethodAndPath<Path extends string, Method extends HTTPMethod = HTTPMethod, Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | undefined | never = undefined, QueryParams extends StandardSchemaV1 | undefined | never = undefined, Resolved extends boolean = false, HiddenParameters extends boolean = false> = {
318
+ [M in Method as `${M}:${Path}`]?: ServiceSetup<M, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
318
319
  };
319
320
 
320
321
  interface SilgiCLI {
@@ -1233,4 +1234,4 @@ interface LoadConfigOptions {
1233
1234
  consola?: ConsolaInstance;
1234
1235
  }
1235
1236
 
1236
- export type { AllPaths, AllPrefixes, AppConfig, Awaitable, BaseMethodSchema, BuildSilgi, CaptureError, CapturedErrorContext, CommandType, Commands, CustomRequestInit, DeepPartial, DeepRequired, DefaultHooks, DefineFrameworkOptions, DotenvOptions, EnvOptions, EventHandlerResponse, EventProtocol, ExtendContext, ExtendShared, ExtractNamespace, ExtractPathParamKeys, ExtractPathParams, ExtractPrefix, ExtractRoute, GenImport, GenerateAppOptions, HTTPMethod, HasPathParams, HookResult, LoadConfigOptions, MergeAll, MergeRouteRules, MergedSilgiSchema, MetaData, MethodSchemas, MiddlewareHandler, MiddlewareSetup, ModuleDefinition, ModuleHookContext, ModuleMeta, ModuleOptionsCustom, ModuleSetupInstallResult, ModuleSetupReturn, NamespacesForPrefix, NitroBuildInfo, RequiredServiceType, ResolvedMiddlewareDefinition, ResolvedModuleMeta, ResolvedModuleOptions, ResolvedSchema, ResolvedSchemaDefinition, ResolvedServiceDefinition, ResolvedSilgiTemplate, Resolvers, RouteEntry, RouteRules, RouterParams, Routers, RoutesForPrefixAndNamespace, ScanFile, Schema, ServiceDefinitionByMethodAndPath, ServiceHandler, ServiceHandlerInput, ServiceSetup, ServiceSetupsForMethods, ServicesObject, SetupModuleOption, Silgi, SilgiAppPlugin, SilgiCLI, SilgiCLIConfig, SilgiCLIHooks, SilgiCLIOptions, SilgiCommands, SilgiCompatibility, SilgiCompatibilityIssue, SilgiCompatibilityIssues, SilgiConfig, SilgiEvent, SilgiFetchClient, SilgiFetchOptions, SilgiFrameworkInfo, SilgiHooks, SilgiModule, SilgiModuleInput, SilgiModuleOptions, SilgiOptions, SilgiPreset, SilgiPresetMeta, SilgiRoute, SilgiRouterTypes, SilgiRuntimeConfig, SilgiRuntimeContext, SilgiRuntimeDefaultConfig, SilgiRuntimeHooks, SilgiRuntimeMethods, SilgiRuntimeOptions, SilgiRuntimeShareds, SilgiRuntimeSharedsExtend, SilgiSchema, SilgiStorageBase, SilgiTemplate, SilgiURL, StandardHTTPMethod, StorageConfig, StorageKeyGenerator, StorageKeyParams, StorageMounts, TSReference, TrimAfterFourSlashes, WithPathParams };
1237
+ export type { AllPaths, AllPrefixes, AppConfig, Awaitable, BaseMethodSchema, BuildSilgi, CaptureError, CapturedErrorContext, CommandType, Commands, CustomRequestInit, DeepPartial, DeepRequired, DefaultHooks, DefineFrameworkOptions, DotenvOptions, EnvOptions, EventHandlerResponse, EventProtocol, ExtendContext, ExtendShared, ExtractNamespace, ExtractPathParamKeys, ExtractPathParams, ExtractPrefix, ExtractRoute, GenImport, GenerateAppOptions, HTTPMethod, HasPathParams, HookResult, LoadConfigOptions, Max4Slashes, MergeAll, MergeRouteRules, MergedSilgiSchema, MetaData, MethodSchemas, MiddlewareHandler, MiddlewareSetup, ModuleDefinition, ModuleHookContext, ModuleMeta, ModuleOptionsCustom, ModuleSetupInstallResult, ModuleSetupReturn, NamespacesForPrefix, NitroBuildInfo, RequiredServiceType, ResolvedMiddlewareDefinition, ResolvedModuleMeta, ResolvedModuleOptions, ResolvedSchema, ResolvedSchemaDefinition, ResolvedServiceDefinition, ResolvedSilgiTemplate, Resolvers, RouteEntry, RouteRules, RouterParams, Routers, RoutesForPrefixAndNamespace, ScanFile, Schema, ServiceDefinitionByMethodAndPath, ServiceHandler, ServiceHandlerInput, ServiceSetup, ServiceSetupsForMethods, ServicesObject, SetupModuleOption, Silgi, SilgiAppPlugin, SilgiCLI, SilgiCLIConfig, SilgiCLIHooks, SilgiCLIOptions, SilgiCommands, SilgiCompatibility, SilgiCompatibilityIssue, SilgiCompatibilityIssues, SilgiConfig, SilgiEvent, SilgiFetchClient, SilgiFetchOptions, SilgiFrameworkInfo, SilgiHooks, SilgiModule, SilgiModuleInput, SilgiModuleOptions, SilgiOptions, SilgiPreset, SilgiPresetMeta, SilgiRoute, SilgiRouterTypes, SilgiRuntimeConfig, SilgiRuntimeContext, SilgiRuntimeDefaultConfig, SilgiRuntimeHooks, SilgiRuntimeMethods, SilgiRuntimeOptions, SilgiRuntimeShareds, SilgiRuntimeSharedsExtend, SilgiSchema, SilgiStorageBase, SilgiTemplate, SilgiURL, StandardHTTPMethod, StorageConfig, StorageKeyGenerator, StorageKeyParams, StorageMounts, TSReference, TrimAfterFourSlashes, WithPathParams };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.41.35",
4
+ "version": "0.41.37",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {