silgi 0.41.34 → 0.41.36

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.34";
4
+ const version = "0.41.36";
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;
@@ -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 {
@@ -1048,17 +1032,15 @@ async function middleware(event) {
1048
1032
  }
1049
1033
  }
1050
1034
  event._chain = _chain;
1051
- }
1052
- async function handler(event, middlewareMode = false, input, parent, info, callBack) {
1053
- event._chain = middleware(event);
1054
- if (middlewareMode) {
1055
- if (event._chain) {
1056
- const data = await event._chain;
1057
- if (data !== void 0 && data !== kNotFound) {
1058
- return data;
1059
- }
1035
+ if (event._chain) {
1036
+ const data = await event._chain;
1037
+ if (data !== void 0 && data !== kNotFound) {
1038
+ return data;
1060
1039
  }
1061
1040
  }
1041
+ }
1042
+ async function handler(event) {
1043
+ await middleware(event);
1062
1044
  const silgiContext = useSilgi();
1063
1045
  if (silgiContext.router) {
1064
1046
  const match = findRoute(silgiContext.router, event.req.method, event.url.pathname);
@@ -1070,12 +1052,12 @@ async function handler(event, middlewareMode = false, input, parent, info, callB
1070
1052
  }
1071
1053
  event.context.params = match.params;
1072
1054
  event.context.matchedRoute = match.data;
1073
- return orchestrate(match.data, event, input, parent, info);
1055
+ return orchestrate(match.data, event);
1074
1056
  });
1075
1057
  } else {
1076
1058
  event.context.params = match.params;
1077
1059
  event.context.matchedRoute = match.data;
1078
- return orchestrate(match.data, event, input, parent, info);
1060
+ return orchestrate(match.data, event);
1079
1061
  }
1080
1062
  }
1081
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';
@@ -264,14 +263,14 @@ type ServiceHandlerInput<Input extends StandardSchemaV1 = StandardSchemaV1, Path
264
263
  * Resolved = false -> handler(input, shared, event, source) // all required
265
264
  * Resolved = true -> handler(input, shared?, event?, source?) // only input required
266
265
  */
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>;
266
+ 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
267
  /**
269
268
  * Servis setup tipi
270
269
  */
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> {
270
+ 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
271
  path: Path;
273
272
  method: Method;
274
- handler?: ServiceHandler<Parent, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
273
+ handler?: ServiceHandler<Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
275
274
  rules?: MergeRouteRules;
276
275
  modules?: Partial<SetupModuleOption>;
277
276
  storage?: StorageConfig<ServiceHandlerInput<Input, PathParams, QueryParams, HiddenParameters>>;
@@ -304,7 +303,7 @@ interface SilgiURL {
304
303
  pathParams?: Record<string, string | undefined>;
305
304
  queryParams?: Record<string, string>;
306
305
  }
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>;
306
+ 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
307
  /**
309
308
  * Sadece belirtilen HTTP methodları için anahtar üretir.
310
309
  * Varsayılan olarak tüm methodlar çıkar.
@@ -313,8 +312,8 @@ type ServiceSetupsForMethods<Parent extends StandardSchemaV1 = StandardSchemaV1,
313
312
  * ServiceDefinitionByMethodAndPath<'/foo', ..., 'GET' | 'POST'>
314
313
  * // Sadece "GET:/foo" ve "POST:/foo" anahtarları olur.
315
314
  */
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>;
315
+ 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> = {
316
+ [M in Method as `${M}:${Path}`]?: ServiceSetup<M, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
318
317
  };
319
318
 
320
319
  interface SilgiCLI {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.41.34",
4
+ "version": "0.41.36",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {