silgi 0.37.44 → 0.37.46

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.37.44";
4
+ const version = "0.37.46";
5
5
  const packageJson = {
6
6
  version: version};
7
7
 
@@ -17,7 +17,7 @@ declare function silgiFetch(_request: Request | URL | string, options?: RequestI
17
17
  declare function handler(event: SilgiEvent, url?: {
18
18
  path: string;
19
19
  method: string;
20
- }): Promise<any>;
20
+ }, input?: any): Promise<any>;
21
21
 
22
22
  /**
23
23
  * LICENSE: MIT
@@ -532,14 +532,27 @@ function getUrlPrefix(path, method) {
532
532
  };
533
533
  }
534
534
 
535
- async function orchestrate(route, event) {
535
+ async function orchestrate(route, event, _input) {
536
536
  const silgiCtx = useSilgi();
537
- const silgiURL = getUrlPrefix(route.route, event.req.method);
538
- const input = route.service.routerRule?.readBeforeBody === false ? {} : await parseRequestInput(event.req);
537
+ const silgiURL = getUrlPrefix(route.route, route.method);
538
+ const input = _input || (route.service.routerRule?.readBeforeBody === false ? {} : await parseRequestInput(event.req));
539
539
  const hookContext = { earlyReturnValue: false };
540
+ const routerParams = _input ? input.path : getRouterParams(event);
541
+ const queryParams = _input ? input.query : getQuery(event);
542
+ if (_input.path) {
543
+ delete _input.path;
544
+ }
545
+ if (_input.query) {
546
+ delete _input.query;
547
+ }
548
+ const inputData = {
549
+ args: input,
550
+ parameters: {
551
+ query: queryParams,
552
+ path: routerParams
553
+ }
554
+ };
540
555
  try {
541
- const routerParams = getRouterParams(event);
542
- const queryParams = getQuery(event);
543
556
  const service = route.service;
544
557
  const cachePromise = cacheExecute(input, route, silgiURL, event);
545
558
  const beforeHookPromise = silgiCtx.callHook("fetch:before", {
@@ -571,13 +584,7 @@ async function orchestrate(route, event) {
571
584
  silgiCtx.shared.$fetch = silgiFetch;
572
585
  silgiCtx.shared.silgi = silgiCtx;
573
586
  const result = await service?.handler(
574
- {
575
- args: input,
576
- parameters: {
577
- query: queryParams,
578
- path: routerParams
579
- }
580
- },
587
+ inputData,
581
588
  silgiCtx.shared,
582
589
  event,
583
590
  event.context.source
@@ -585,7 +592,7 @@ async function orchestrate(route, event) {
585
592
  await silgiCtx.callHook("fetch:after", {
586
593
  event,
587
594
  url: silgiURL,
588
- input,
595
+ input: inputData,
589
596
  result,
590
597
  success: true,
591
598
  route,
@@ -603,7 +610,7 @@ async function orchestrate(route, event) {
603
610
  } catch (err) {
604
611
  await silgiCtx.callHook("fetch:error", {
605
612
  event,
606
- input,
613
+ input: inputData,
607
614
  error: err instanceof Error ? err : new Error(String(err)),
608
615
  url: silgiURL,
609
616
  route,
@@ -856,7 +863,7 @@ async function silgiFetch(_request, options, context) {
856
863
  }
857
864
  return handleResponse(handlerRes, silgiEvent, {});
858
865
  }
859
- async function handler(event, url) {
866
+ async function handler(event, url, input) {
860
867
  const silgiCtx = useSilgi();
861
868
  const pathname = url?.path || event.url.pathname;
862
869
  let _chain = void 0;
@@ -871,12 +878,12 @@ async function handler(event, url) {
871
878
  }
872
879
  event.context.params = match.params;
873
880
  event.context.matchedRoute = match.data;
874
- return orchestrate(match.data, event);
881
+ return orchestrate(match.data, event, input);
875
882
  });
876
883
  } else {
877
884
  event.context.params = match.params;
878
885
  event.context.matchedRoute = match.data;
879
- return orchestrate(match.data, event);
886
+ return orchestrate(match.data, event, input);
880
887
  }
881
888
  }
882
889
  }
@@ -673,7 +673,7 @@ interface SilgiMeta extends Record<string, unknown> {
673
673
  }
674
674
  interface SilgiRoute {
675
675
  route: string;
676
- method?: HTTPMethod;
676
+ method: HTTPMethod;
677
677
  service: ServiceSetup;
678
678
  schema: ResolvedSchemaDefinition;
679
679
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.37.44",
4
+ "version": "0.37.46",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "exports": {