silgi 0.41.8 → 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.
- package/dist/cli/index.mjs +1 -1
- package/dist/core/index.d.mts +6 -7
- package/dist/core/index.mjs +25 -17
- package/dist/types/index.d.mts +4 -5
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
package/dist/core/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SilgiConfig, Silgi, SilgiEvent, SilgiSchema, RouteEntry, CustomRequestInit, SilgiRuntimeContext, BaseMethodSchema, MergeAll,
|
|
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?:
|
|
29
|
-
graphql?: boolean;
|
|
28
|
+
method?: HTTPMethod;
|
|
30
29
|
}, input?: any): Promise<any>;
|
|
31
30
|
|
|
32
31
|
/**
|
|
@@ -174,7 +173,7 @@ declare function createService<Path extends string = string, Input extends Stand
|
|
|
174
173
|
}): {
|
|
175
174
|
[K in Path]: {
|
|
176
175
|
setup: ServiceSetup<Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
177
|
-
methods
|
|
176
|
+
methods?: HTTPMethod[];
|
|
178
177
|
input?: Input;
|
|
179
178
|
output?: Output;
|
|
180
179
|
queryParams?: {
|
|
@@ -186,13 +185,13 @@ declare function createService<Path extends string = string, Input extends Stand
|
|
|
186
185
|
|
|
187
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}`;
|
|
188
187
|
type MiddlewarePath<S extends WildcardVariants<keyof ServicesObject>> = S | 'global';
|
|
189
|
-
interface CreateMiddlewareParams<S extends WildcardVariants<keyof ServicesObject>, UsedMethod extends readonly
|
|
188
|
+
interface CreateMiddlewareParams<S extends WildcardVariants<keyof ServicesObject>, UsedMethod extends readonly HTTPMethod[] = readonly HTTPMethod[], Key extends string = string> {
|
|
190
189
|
path: MiddlewarePath<S>;
|
|
191
190
|
methods?: UsedMethod;
|
|
192
191
|
setup: MiddlewareSetup;
|
|
193
192
|
key: Key;
|
|
194
193
|
}
|
|
195
|
-
type CreateMiddlewareResult<Path extends string, UsedMethod extends readonly
|
|
194
|
+
type CreateMiddlewareResult<Path extends string, UsedMethod extends readonly HTTPMethod[] = readonly HTTPMethod[], Key extends string = string> = {
|
|
196
195
|
[K in `${Key}:${Path}`]: {
|
|
197
196
|
setup: MiddlewareSetup;
|
|
198
197
|
methods?: UsedMethod;
|
|
@@ -200,7 +199,7 @@ type CreateMiddlewareResult<Path extends string, UsedMethod extends readonly Htt
|
|
|
200
199
|
path: Path;
|
|
201
200
|
};
|
|
202
201
|
};
|
|
203
|
-
declare function createMiddleware<S extends WildcardVariants<keyof ServicesObject>, UsedMethod extends readonly
|
|
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> & {
|
|
204
203
|
path: Path;
|
|
205
204
|
}): CreateMiddlewareResult<Path, UsedMethod, Key>;
|
|
206
205
|
|
package/dist/core/index.mjs
CHANGED
|
@@ -306,6 +306,14 @@ async function createSilgi(config) {
|
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
308
|
const methods = object.methods?.length ? object.methods : ["ALL"];
|
|
309
|
+
if (methods.includes("GRAPHQL")) {
|
|
310
|
+
addRoute(silgi.router, "GRAPHQL", route, {
|
|
311
|
+
method: ["GRAPHQL"],
|
|
312
|
+
route,
|
|
313
|
+
service: object
|
|
314
|
+
});
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
309
317
|
for (const method of methods) {
|
|
310
318
|
const globalMethod = method === "ALL" ? "" : method.toUpperCase();
|
|
311
319
|
addRoute(silgi.router, globalMethod, route, {
|
|
@@ -642,7 +650,7 @@ async function orchestrate(route, event, _input) {
|
|
|
642
650
|
silgiCtx.shared.silgi = silgiCtx;
|
|
643
651
|
let result;
|
|
644
652
|
if (!route.graphql) {
|
|
645
|
-
result = await route.service?.setup.handler(
|
|
653
|
+
result = await route.service?.setup.handler?.(
|
|
646
654
|
inputData,
|
|
647
655
|
silgiCtx.shared,
|
|
648
656
|
event
|
|
@@ -692,7 +700,7 @@ async function orchestrate(route, event, _input) {
|
|
|
692
700
|
}
|
|
693
701
|
}
|
|
694
702
|
async function cacheExecute(input, route, silgiURL, event) {
|
|
695
|
-
if (!route.service || !route.service.setup
|
|
703
|
+
if (!route.service || !route.service.setup?.storage)
|
|
696
704
|
return;
|
|
697
705
|
const cacheKey = route.service.setup.storage ? await generateStorageKey({
|
|
698
706
|
url: silgiURL,
|
|
@@ -999,21 +1007,21 @@ async function handler(event, url, input) {
|
|
|
999
1007
|
const data = middleware(event, url);
|
|
1000
1008
|
_chain = data;
|
|
1001
1009
|
if (silgiCtx.router) {
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
}
|
|
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
|
+
}
|
|
1017
1025
|
if (match) {
|
|
1018
1026
|
if (_chain) {
|
|
1019
1027
|
return _chain.then(async (_previous) => {
|
package/dist/types/index.d.mts
CHANGED
|
@@ -266,7 +266,7 @@ type ServiceHandler<Input extends StandardSchemaV1, Output extends StandardSchem
|
|
|
266
266
|
* Servis setup tipi
|
|
267
267
|
*/
|
|
268
268
|
interface ServiceSetup<Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | never | undefined = never, QueryParams extends StandardSchemaV1 | never | undefined = never, Resolved extends boolean = false, HiddenParameters extends boolean = false> {
|
|
269
|
-
handler
|
|
269
|
+
handler?: ServiceHandler<Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
270
270
|
rules?: RouteRules & {
|
|
271
271
|
readBeforeBody?: boolean;
|
|
272
272
|
};
|
|
@@ -530,7 +530,6 @@ type ExtractPathParams<T extends string> = T extends `${infer _Start}:${infer Pa
|
|
|
530
530
|
[K in Param]: string;
|
|
531
531
|
} : unknown;
|
|
532
532
|
|
|
533
|
-
type HttpMethod = 'get' | 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'head' | 'patch' | 'post' | 'put' | 'delete' | 'connect' | 'options' | 'trace';
|
|
534
533
|
type RouterParams<R extends AllPaths | (string & {})> = ExtractPathParams<R>;
|
|
535
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]> = {
|
|
536
535
|
method?: M;
|
|
@@ -691,8 +690,8 @@ interface ResolvedSchemaDefinition {
|
|
|
691
690
|
[methodAndRoutePath: string]: BaseMethodSchema;
|
|
692
691
|
}
|
|
693
692
|
|
|
694
|
-
type StandardHTTPMethod = 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'ALL';
|
|
695
|
-
type HTTPMethod = SilgiRuntimeMethods extends
|
|
693
|
+
type StandardHTTPMethod = 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'ALL' | 'GRAPHQL';
|
|
694
|
+
type HTTPMethod = StandardHTTPMethod | (keyof SilgiRuntimeMethods extends string ? keyof SilgiRuntimeMethods : never);
|
|
696
695
|
interface MetaData extends Record<string, unknown> {
|
|
697
696
|
}
|
|
698
697
|
interface SilgiRoute {
|
|
@@ -1223,4 +1222,4 @@ interface LoadConfigOptions {
|
|
|
1223
1222
|
consola?: ConsolaInstance;
|
|
1224
1223
|
}
|
|
1225
1224
|
|
|
1226
|
-
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,
|
|
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 };
|