silgi 0.41.10 → 0.41.12

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.10";
4
+ const version = "0.41.12";
5
5
  const packageJson = {
6
6
  version: version};
7
7
 
@@ -308,7 +308,7 @@ async function createSilgi(config) {
308
308
  const methods = object.methods?.length ? object.methods : ["ALL"];
309
309
  if (methods.includes("GRAPHQL")) {
310
310
  addRoute(silgi.router, "GRAPHQL", route, {
311
- method: ["GRAPHQL"],
311
+ method: "GRAPHQL",
312
312
  route,
313
313
  service: object
314
314
  });
@@ -317,7 +317,7 @@ async function createSilgi(config) {
317
317
  for (const method of methods) {
318
318
  const globalMethod = method === "ALL" ? "" : method.toUpperCase();
319
319
  addRoute(silgi.router, globalMethod, route, {
320
- method: [method],
320
+ method,
321
321
  route,
322
322
  service: object
323
323
  });
@@ -334,11 +334,13 @@ async function createSilgi(config) {
334
334
  _route = routeParts.join(":");
335
335
  }
336
336
  if (_route === "global") {
337
- silgi.globalMiddlewares.push({
338
- middleware: routeObject.setup,
339
- method: routeObject.methods?.length ? routeObject.methods : ["ALL"],
340
- route: _route
341
- });
337
+ for (const method of routeObject.methods?.length ? routeObject.methods : ["ALL"]) {
338
+ silgi.globalMiddlewares.push({
339
+ middleware: routeObject.setup,
340
+ method: method === "ALL" ? "" : method.toUpperCase(),
341
+ route: _route
342
+ });
343
+ }
342
344
  continue;
343
345
  }
344
346
  const methods = routeObject.methods?.length ? routeObject.methods : ["ALL"];
@@ -346,7 +348,7 @@ async function createSilgi(config) {
346
348
  const globalMethod = method === "ALL" ? "" : method.toUpperCase();
347
349
  addRoute(silgi._middlewareRouter, globalMethod, _route, {
348
350
  middleware: routeObject.setup,
349
- method: [method],
351
+ method,
350
352
  route: _route
351
353
  });
352
354
  }
@@ -586,7 +588,8 @@ function getUrlPrefix(path, method) {
586
588
 
587
589
  async function orchestrate(route, event, _input) {
588
590
  const silgiCtx = useSilgi();
589
- const silgiURL = !route.graphql ? getUrlPrefix(route.route || event.req.url, route.method) : {
591
+ const isGraphQL = route.method === "GRAPHQL";
592
+ const silgiURL = !isGraphQL ? getUrlPrefix(route.route || event.req.url, route.method) : {
590
593
  methodName: route.method || "GET",
591
594
  namespaceName: "graphql",
592
595
  prefixName: "/api",
@@ -595,7 +598,7 @@ async function orchestrate(route, event, _input) {
595
598
  pathParams: {},
596
599
  queryParams: {}
597
600
  };
598
- const input = _input || (route.service?.setup.rules?.readBeforeBody === false || route.graphql ? {} : await parseRequestInput(event.req));
601
+ const input = _input || (route.service?.setup.rules?.readBeforeBody === false || isGraphQL ? {} : await parseRequestInput(event.req));
599
602
  const hookContext = { earlyReturnValue: false };
600
603
  const routerParams = _input ? input.path : getRouterParams(event);
601
604
  const queryParams = _input ? input.query : getQuery(event);
@@ -613,7 +616,7 @@ async function orchestrate(route, event, _input) {
613
616
  }
614
617
  };
615
618
  try {
616
- if (!route.service && !route.graphql) {
619
+ if (!route.service && route.method !== "GRAPHQL") {
617
620
  throw createError({
618
621
  statusCode: 404,
619
622
  statusMessage: "Service not found"
@@ -649,7 +652,7 @@ async function orchestrate(route, event, _input) {
649
652
  silgiCtx.shared.$fetch = silgiFetch;
650
653
  silgiCtx.shared.silgi = silgiCtx;
651
654
  let result;
652
- if (!route.graphql) {
655
+ if (!isGraphQL) {
653
656
  result = await route.service?.setup.handler?.(
654
657
  inputData,
655
658
  silgiCtx.shared,
@@ -931,11 +934,8 @@ async function middleware(event, url) {
931
934
  if (_previous !== void 0 && _previous !== kNotFound) {
932
935
  return _previous;
933
936
  }
934
- let allowedMethods = m.method ?? [];
935
- if (!Array.isArray(allowedMethods)) {
936
- allowedMethods = [allowedMethods];
937
- }
938
- const methodIsAllowed = allowedMethods.length === 0 || allowedMethods.includes("ALL") || allowedMethods.includes(event.req.method);
937
+ let allowedMethod = m.method ?? "";
938
+ const methodIsAllowed = allowedMethod === "ALL" || allowedMethod === event.req.method;
939
939
  if (!methodIsAllowed) {
940
940
  return;
941
941
  }
@@ -969,11 +969,8 @@ async function middleware(event, url) {
969
969
  if (_previous !== void 0 && _previous !== kNotFound) {
970
970
  return _previous;
971
971
  }
972
- let allowedMethods = match.data.method ?? [];
973
- if (!Array.isArray(allowedMethods)) {
974
- allowedMethods = [allowedMethods];
975
- }
976
- const methodIsAllowed = allowedMethods.length === 0 || allowedMethods.includes("ALL") || allowedMethods.includes(event.req.method);
972
+ const allowedMethod = match.data.method ?? "";
973
+ const methodIsAllowed = allowedMethod === "ALL" || allowedMethod === event.req.method;
977
974
  if (!methodIsAllowed || !match.data.middleware) {
978
975
  return;
979
976
  }
@@ -1011,7 +1008,6 @@ async function handler(event, url, input) {
1011
1008
  if (!match && url?.method === "GRAPHQL") {
1012
1009
  match = {
1013
1010
  data: {
1014
- graphql: true,
1015
1011
  method: url?.method || event.req.method,
1016
1012
  route: url?.path,
1017
1013
  service: {
@@ -696,8 +696,7 @@ interface MetaData extends Record<string, unknown> {
696
696
  }
697
697
  interface SilgiRoute {
698
698
  route?: string;
699
- graphql?: boolean;
700
- method?: HTTPMethod | HTTPMethod[];
699
+ method?: HTTPMethod;
701
700
  service?: ResolvedServiceDefinition[string];
702
701
  middleware?: MiddlewareSetup;
703
702
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.41.10",
4
+ "version": "0.41.12",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {