silgi 0.41.9 → 0.41.10

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.9";
4
+ const version = "0.41.10";
5
5
  const packageJson = {
6
6
  version: version};
7
7
 
@@ -1,4 +1,4 @@
1
- import { SilgiConfig, Silgi, SilgiEvent, SilgiSchema, RouteEntry, CustomRequestInit, SilgiRuntimeContext, BaseMethodSchema, MergeAll, HTTPMethod, ServiceSetup, ServicesObject, HttpMethod, MiddlewareSetup, SilgiRuntimeShareds, Resolvers, SilgiURL, StorageConfig, SilgiCLI, SilgiStorageBase, SilgiRuntimeConfig } from 'silgi/types';
1
+ import { SilgiConfig, Silgi, SilgiEvent, HTTPMethod, SilgiSchema, RouteEntry, CustomRequestInit, SilgiRuntimeContext, BaseMethodSchema, MergeAll, ServiceSetup, ServicesObject, MiddlewareSetup, SilgiRuntimeShareds, Resolvers, SilgiURL, StorageConfig, SilgiCLI, SilgiStorageBase, SilgiRuntimeConfig } from 'silgi/types';
2
2
  import { StandardSchemaV1 } from '@standard-schema/spec';
3
3
  import { Storage, StorageValue } from 'unstorage';
4
4
  import { UseContext } from 'unctx';
@@ -25,8 +25,7 @@ declare function middleware(event: SilgiEvent, url?: {
25
25
  }): Promise<any>;
26
26
  declare function handler(event: SilgiEvent, url?: {
27
27
  path?: string;
28
- method?: string;
29
- graphql?: boolean;
28
+ method?: HTTPMethod;
30
29
  }, input?: any): Promise<any>;
31
30
 
32
31
  /**
@@ -170,12 +169,11 @@ declare function createService<Path extends string = string, Input extends Stand
170
169
  path?: PathParams;
171
170
  query?: QueryParams;
172
171
  };
173
- mode: 'graphql';
174
172
  setup: ServiceSetup<Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
175
173
  }): {
176
174
  [K in Path]: {
177
175
  setup: ServiceSetup<Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
178
- methods: HTTPMethod[];
176
+ methods?: HTTPMethod[];
179
177
  input?: Input;
180
178
  output?: Output;
181
179
  queryParams?: {
@@ -187,13 +185,13 @@ declare function createService<Path extends string = string, Input extends Stand
187
185
 
188
186
  type WildcardVariants<Path extends string, Acc extends string = ''> = Path extends `${infer Head}/${infer Tail}` ? Tail extends '' ? `${Acc}${Head}` : `${Acc}${Head}/${Tail}` | `${Acc}${Head}/*` | `${Acc}${Head}/**` | WildcardVariants<Tail, `${Acc}${Head}/`> : `${Acc}${Path}`;
189
187
  type MiddlewarePath<S extends WildcardVariants<keyof ServicesObject>> = S | 'global';
190
- interface CreateMiddlewareParams<S extends WildcardVariants<keyof ServicesObject>, UsedMethod extends readonly HttpMethod[] = readonly HttpMethod[], Key extends string = string> {
188
+ interface CreateMiddlewareParams<S extends WildcardVariants<keyof ServicesObject>, UsedMethod extends readonly HTTPMethod[] = readonly HTTPMethod[], Key extends string = string> {
191
189
  path: MiddlewarePath<S>;
192
190
  methods?: UsedMethod;
193
191
  setup: MiddlewareSetup;
194
192
  key: Key;
195
193
  }
196
- type CreateMiddlewareResult<Path extends string, UsedMethod extends readonly HttpMethod[] = readonly HttpMethod[], Key extends string = string> = {
194
+ type CreateMiddlewareResult<Path extends string, UsedMethod extends readonly HTTPMethod[] = readonly HTTPMethod[], Key extends string = string> = {
197
195
  [K in `${Key}:${Path}`]: {
198
196
  setup: MiddlewareSetup;
199
197
  methods?: UsedMethod;
@@ -201,7 +199,7 @@ type CreateMiddlewareResult<Path extends string, UsedMethod extends readonly Htt
201
199
  path: Path;
202
200
  };
203
201
  };
204
- declare function createMiddleware<S extends WildcardVariants<keyof ServicesObject>, UsedMethod extends readonly HttpMethod[] = readonly HttpMethod[], Path extends MiddlewarePath<S> = MiddlewarePath<S>, Key extends string = string>(params: CreateMiddlewareParams<S, UsedMethod, Key> & {
202
+ declare function createMiddleware<S extends WildcardVariants<keyof ServicesObject>, UsedMethod extends readonly HTTPMethod[] = readonly HTTPMethod[], Path extends MiddlewarePath<S> = MiddlewarePath<S>, Key extends string = string>(params: CreateMiddlewareParams<S, UsedMethod, Key> & {
205
203
  path: Path;
206
204
  }): CreateMiddlewareResult<Path, UsedMethod, Key>;
207
205
 
@@ -305,7 +305,8 @@ async function createSilgi(config) {
305
305
  silgi.routerPrefixs.push(prefix);
306
306
  }
307
307
  }
308
- if (object.mode === "graphql") {
308
+ const methods = object.methods?.length ? object.methods : ["ALL"];
309
+ if (methods.includes("GRAPHQL")) {
309
310
  addRoute(silgi.router, "GRAPHQL", route, {
310
311
  method: ["GRAPHQL"],
311
312
  route,
@@ -313,7 +314,6 @@ async function createSilgi(config) {
313
314
  });
314
315
  continue;
315
316
  }
316
- const methods = object.methods?.length ? object.methods : ["ALL"];
317
317
  for (const method of methods) {
318
318
  const globalMethod = method === "ALL" ? "" : method.toUpperCase();
319
319
  addRoute(silgi.router, globalMethod, route, {
@@ -1007,7 +1007,21 @@ async function handler(event, url, input) {
1007
1007
  const data = middleware(event, url);
1008
1008
  _chain = data;
1009
1009
  if (silgiCtx.router) {
1010
- const match = findRoute(silgiCtx.router, url?.method || event.req.method, pathname);
1010
+ let match = findRoute(silgiCtx.router, url?.method || event.req.method, pathname);
1011
+ if (!match && url?.method === "GRAPHQL") {
1012
+ match = {
1013
+ data: {
1014
+ graphql: true,
1015
+ method: url?.method || event.req.method,
1016
+ route: url?.path,
1017
+ service: {
1018
+ setup: {},
1019
+ methods: ["GRAPHQL"]
1020
+ }
1021
+ },
1022
+ params: {}
1023
+ };
1024
+ }
1011
1025
  if (match) {
1012
1026
  if (_chain) {
1013
1027
  return _chain.then(async (_previous) => {
@@ -1082,9 +1096,8 @@ function createService(params) {
1082
1096
  );
1083
1097
  }
1084
1098
  const result = {};
1085
- const { path, setup, methods, input, output, queryParams, mode } = params;
1099
+ const { path, setup, methods, input, output, queryParams } = params;
1086
1100
  result[path] = {
1087
- mode,
1088
1101
  setup,
1089
1102
  methods,
1090
1103
  input,
@@ -285,7 +285,6 @@ interface ServiceSetup<Input extends StandardSchemaV1 = StandardSchemaV1, Output
285
285
  interface ResolvedServiceDefinition {
286
286
  [routePath: string]: {
287
287
  setup: ServiceSetup<any, any, any, any, any, any>;
288
- mode: 'graphql';
289
288
  methods: HTTPMethod[];
290
289
  input?: StandardSchemaV1;
291
290
  output?: StandardSchemaV1;
@@ -531,7 +530,6 @@ type ExtractPathParams<T extends string> = T extends `${infer _Start}:${infer Pa
531
530
  [K in Param]: string;
532
531
  } : unknown;
533
532
 
534
- type HttpMethod = 'get' | 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'head' | 'patch' | 'post' | 'put' | 'delete' | 'connect' | 'options' | 'trace';
535
533
  type RouterParams<R extends AllPaths | (string & {})> = ExtractPathParams<R>;
536
534
  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]> = {
537
535
  method?: M;
@@ -693,7 +691,7 @@ interface ResolvedSchemaDefinition {
693
691
  }
694
692
 
695
693
  type StandardHTTPMethod = 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'ALL' | 'GRAPHQL';
696
- type HTTPMethod = SilgiRuntimeMethods extends Record<string, any> ? keyof SilgiRuntimeMethods | StandardHTTPMethod : StandardHTTPMethod;
694
+ type HTTPMethod = StandardHTTPMethod | (keyof SilgiRuntimeMethods extends string ? keyof SilgiRuntimeMethods : never);
697
695
  interface MetaData extends Record<string, unknown> {
698
696
  }
699
697
  interface SilgiRoute {
@@ -1224,4 +1222,4 @@ interface LoadConfigOptions {
1224
1222
  consola?: ConsolaInstance;
1225
1223
  }
1226
1224
 
1227
- export type { AllPaths, AllPrefixes, AppConfig, Awaitable, BaseMethodSchema, BuildSilgi, CaptureError, CapturedErrorContext, CommandType, Commands, CustomRequestInit, DeepPartial, DeepRequired, DefaultHooks, DefineFrameworkOptions, DotenvOptions, EnvOptions, EventHandlerResponse, ExtendContext, ExtendShared, ExtractNamespace, ExtractPathParamKeys, ExtractPathParams, ExtractPrefix, ExtractRoute, GenImport, GenerateAppOptions, HTTPMethod, HasPathParams, HookResult, HttpMethod, LoadConfigOptions, MergeAll, 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, RoutesForPrefixAndNamespace, ScanFile, Schema, ServiceHandler, ServiceHandlerInput, ServiceSetup, 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 };
1225
+ export type { AllPaths, AllPrefixes, AppConfig, Awaitable, BaseMethodSchema, BuildSilgi, CaptureError, CapturedErrorContext, CommandType, Commands, CustomRequestInit, DeepPartial, DeepRequired, DefaultHooks, DefineFrameworkOptions, DotenvOptions, EnvOptions, EventHandlerResponse, ExtendContext, ExtendShared, ExtractNamespace, ExtractPathParamKeys, ExtractPathParams, ExtractPrefix, ExtractRoute, GenImport, GenerateAppOptions, HTTPMethod, HasPathParams, HookResult, LoadConfigOptions, MergeAll, 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, RoutesForPrefixAndNamespace, ScanFile, Schema, ServiceHandler, ServiceHandlerInput, ServiceSetup, 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.9",
4
+ "version": "0.41.10",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {