silgi 0.41.7 → 0.41.9
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 -0
- package/dist/core/index.mjs +22 -17
- package/dist/types/index.d.mts +4 -3
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
package/dist/core/index.d.mts
CHANGED
|
@@ -170,6 +170,7 @@ declare function createService<Path extends string = string, Input extends Stand
|
|
|
170
170
|
path?: PathParams;
|
|
171
171
|
query?: QueryParams;
|
|
172
172
|
};
|
|
173
|
+
mode: 'graphql';
|
|
173
174
|
setup: ServiceSetup<Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
174
175
|
}): {
|
|
175
176
|
[K in Path]: {
|
package/dist/core/index.mjs
CHANGED
|
@@ -305,6 +305,14 @@ async function createSilgi(config) {
|
|
|
305
305
|
silgi.routerPrefixs.push(prefix);
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
|
+
if (object.mode === "graphql") {
|
|
309
|
+
addRoute(silgi.router, "GRAPHQL", route, {
|
|
310
|
+
method: ["GRAPHQL"],
|
|
311
|
+
route,
|
|
312
|
+
service: object
|
|
313
|
+
});
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
308
316
|
const methods = object.methods?.length ? object.methods : ["ALL"];
|
|
309
317
|
for (const method of methods) {
|
|
310
318
|
const globalMethod = method === "ALL" ? "" : method.toUpperCase();
|
|
@@ -605,7 +613,7 @@ async function orchestrate(route, event, _input) {
|
|
|
605
613
|
}
|
|
606
614
|
};
|
|
607
615
|
try {
|
|
608
|
-
if (!route.service) {
|
|
616
|
+
if (!route.service && !route.graphql) {
|
|
609
617
|
throw createError({
|
|
610
618
|
statusCode: 404,
|
|
611
619
|
statusMessage: "Service not found"
|
|
@@ -640,11 +648,14 @@ async function orchestrate(route, event, _input) {
|
|
|
640
648
|
}
|
|
641
649
|
silgiCtx.shared.$fetch = silgiFetch;
|
|
642
650
|
silgiCtx.shared.silgi = silgiCtx;
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
651
|
+
let result;
|
|
652
|
+
if (!route.graphql) {
|
|
653
|
+
result = await route.service?.setup.handler?.(
|
|
654
|
+
inputData,
|
|
655
|
+
silgiCtx.shared,
|
|
656
|
+
event
|
|
657
|
+
);
|
|
658
|
+
}
|
|
648
659
|
await silgiCtx.callHook("fetch:after", {
|
|
649
660
|
event,
|
|
650
661
|
url: silgiURL,
|
|
@@ -654,7 +665,7 @@ async function orchestrate(route, event, _input) {
|
|
|
654
665
|
route,
|
|
655
666
|
hookContext
|
|
656
667
|
});
|
|
657
|
-
if (route.service
|
|
668
|
+
if (route.service?.setup.storage && cacheData?.cachedKey) {
|
|
658
669
|
await useSilgiStorage(route.service.setup.storage.base).setItem(
|
|
659
670
|
cacheData.cachedKey,
|
|
660
671
|
result,
|
|
@@ -689,7 +700,7 @@ async function orchestrate(route, event, _input) {
|
|
|
689
700
|
}
|
|
690
701
|
}
|
|
691
702
|
async function cacheExecute(input, route, silgiURL, event) {
|
|
692
|
-
if (!route.service || !route.service.setup
|
|
703
|
+
if (!route.service || !route.service.setup?.storage)
|
|
693
704
|
return;
|
|
694
705
|
const cacheKey = route.service.setup.storage ? await generateStorageKey({
|
|
695
706
|
url: silgiURL,
|
|
@@ -996,14 +1007,7 @@ async function handler(event, url, input) {
|
|
|
996
1007
|
const data = middleware(event, url);
|
|
997
1008
|
_chain = data;
|
|
998
1009
|
if (silgiCtx.router) {
|
|
999
|
-
const match =
|
|
1000
|
-
data: {
|
|
1001
|
-
graphql: true,
|
|
1002
|
-
method: url?.method || event.req.method,
|
|
1003
|
-
route: url.path
|
|
1004
|
-
},
|
|
1005
|
-
params: {}
|
|
1006
|
-
};
|
|
1010
|
+
const match = findRoute(silgiCtx.router, url?.method || event.req.method, pathname);
|
|
1007
1011
|
if (match) {
|
|
1008
1012
|
if (_chain) {
|
|
1009
1013
|
return _chain.then(async (_previous) => {
|
|
@@ -1078,8 +1082,9 @@ function createService(params) {
|
|
|
1078
1082
|
);
|
|
1079
1083
|
}
|
|
1080
1084
|
const result = {};
|
|
1081
|
-
const { path, setup, methods, input, output, queryParams } = params;
|
|
1085
|
+
const { path, setup, methods, input, output, queryParams, mode } = params;
|
|
1082
1086
|
result[path] = {
|
|
1087
|
+
mode,
|
|
1083
1088
|
setup,
|
|
1084
1089
|
methods,
|
|
1085
1090
|
input,
|
package/dist/types/index.d.mts
CHANGED
|
@@ -261,12 +261,12 @@ type ServiceHandlerInput<Input extends StandardSchemaV1 = StandardSchemaV1, Path
|
|
|
261
261
|
* Resolved = false -> handler(input, shared, event, source) // all required
|
|
262
262
|
* Resolved = true -> handler(input, shared?, event?, source?) // only input required
|
|
263
263
|
*/
|
|
264
|
-
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>> : (input: ServiceHandlerInput<Input, PathParams, QueryParams, HiddenParameters>, shared: SilgiRuntimeShareds, event: SilgiEvent) => Promise<InferOutput<Output
|
|
264
|
+
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>;
|
|
265
265
|
/**
|
|
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
|
};
|
|
@@ -285,6 +285,7 @@ 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';
|
|
288
289
|
methods: HTTPMethod[];
|
|
289
290
|
input?: StandardSchemaV1;
|
|
290
291
|
output?: StandardSchemaV1;
|
|
@@ -691,7 +692,7 @@ interface ResolvedSchemaDefinition {
|
|
|
691
692
|
[methodAndRoutePath: string]: BaseMethodSchema;
|
|
692
693
|
}
|
|
693
694
|
|
|
694
|
-
type StandardHTTPMethod = 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'ALL';
|
|
695
|
+
type StandardHTTPMethod = 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'ALL' | 'GRAPHQL';
|
|
695
696
|
type HTTPMethod = SilgiRuntimeMethods extends Record<string, any> ? keyof SilgiRuntimeMethods | StandardHTTPMethod : StandardHTTPMethod;
|
|
696
697
|
interface MetaData extends Record<string, unknown> {
|
|
697
698
|
}
|