silgi 0.41.35 → 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.
- package/dist/cli/index.mjs +1 -1
- package/dist/core/index.d.mts +1 -2
- package/dist/core/index.mjs +10 -26
- package/dist/index.d.mts +0 -1
- package/dist/types/index.d.mts +6 -7
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
package/dist/core/index.d.mts
CHANGED
|
@@ -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
|
|
138
|
+
declare function handler(event: SilgiEvent): Promise<any>;
|
|
140
139
|
|
|
141
140
|
declare const silgiCLICtx: UseContext<SilgiCLI>;
|
|
142
141
|
declare function useSilgiCLI(): SilgiCLI;
|
package/dist/core/index.mjs
CHANGED
|
@@ -780,27 +780,20 @@ function getUrlPrefix(path, method) {
|
|
|
780
780
|
};
|
|
781
781
|
}
|
|
782
782
|
|
|
783
|
-
async function orchestrate(route, event
|
|
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 =
|
|
786
|
+
const input = route.service?.rules?.readBeforeBody === false ? {} : await parseRequestInput(event.req);
|
|
788
787
|
const hookContext = { earlyReturnValue: false };
|
|
789
|
-
const routerParams =
|
|
790
|
-
const queryParams =
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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';
|
package/dist/types/index.d.mts
CHANGED
|
@@ -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<
|
|
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<
|
|
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<
|
|
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<
|
|
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,
|
|
317
|
-
[M in Method as `${M}:${Path}`]?: ServiceSetup<
|
|
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 {
|