silgi 0.37.43 → 0.37.45
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 -10
- package/dist/core/index.mjs +27 -34
- package/dist/index.d.mts +1 -2
- package/dist/index.mjs +1 -1
- package/dist/types/index.d.mts +1 -1
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
package/dist/core/index.d.mts
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
import { SilgiConfig, Silgi, SilgiEvent, SilgiSchema,
|
|
2
|
-
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
1
|
+
import { SilgiConfig, Silgi, SilgiEvent, SilgiSchema, CustomRequestInit, SilgiRuntimeContext, AllPrefixes, NamespacesForPrefix, RoutesForPrefixAndNamespace, MethodSchemas, MergeAll, ServiceMethods, SilgiRuntimeShareds, RouteConfig, SilgiURL, StorageConfig, SilgiCLI, SilgiStorageBase, SilgiRuntimeConfig } from 'silgi/types';
|
|
3
2
|
import { Storage, StorageValue } from 'unstorage';
|
|
4
3
|
import { UseContext } from 'unctx';
|
|
5
4
|
|
|
6
5
|
declare function createSilgi(config: SilgiConfig): Promise<Silgi>;
|
|
7
6
|
|
|
8
|
-
declare function createSilgiCore(event: SilgiEvent): {
|
|
9
|
-
resolve: <Schema extends SilgiSchema = SilgiSchema, Route extends keyof Schema = keyof Schema, Method extends keyof Schema[Route] = keyof Schema[Route], Resolved extends boolean = true, HiddenParameters extends boolean = false>(path: Route, method: Method, context: {
|
|
10
|
-
pathParams?: Route extends keyof Schema ? Method extends keyof Schema[Route] ? Schema[Route][Method] extends {
|
|
11
|
-
pathParams?: infer P;
|
|
12
|
-
} ? P extends StandardSchemaV1 ? StandardSchemaV1.InferInput<P> : undefined : undefined : undefined : undefined;
|
|
13
|
-
}) => Promise<Route extends keyof Schema ? Method extends keyof Schema[Route] ? ServiceSetup<Schema, Route, Method, Resolved, HiddenParameters> : undefined : undefined>;
|
|
14
|
-
};
|
|
15
7
|
/**
|
|
16
8
|
* Fetch API for Silgi framework
|
|
17
9
|
*/
|
|
@@ -22,6 +14,10 @@ declare function silgiFetch<Schema extends SilgiSchema = SilgiSchema, Route exte
|
|
|
22
14
|
declare function silgiFetch(_request: Request | URL | string, options?: RequestInit & {
|
|
23
15
|
pathParams?: Record<string, any>;
|
|
24
16
|
}, context?: SilgiRuntimeContext): Promise<Response | Promise<Response>>;
|
|
17
|
+
declare function handler(event: SilgiEvent, url?: {
|
|
18
|
+
path: string;
|
|
19
|
+
method: string;
|
|
20
|
+
}, input?: any): Promise<any>;
|
|
25
21
|
|
|
26
22
|
/**
|
|
27
23
|
* LICENSE: MIT
|
|
@@ -292,4 +288,4 @@ declare function useRuntime(): SilgiRuntimeConfig;
|
|
|
292
288
|
|
|
293
289
|
declare const autoImportTypes: string[];
|
|
294
290
|
|
|
295
|
-
export { SilgiError, autoImportTypes, createError, createRoute, createSchema, createService, createShared, createSilgi,
|
|
291
|
+
export { SilgiError, autoImportTypes, createError, createRoute, createSchema, createService, createShared, createSilgi, createStorage, deepMergeObjects, getEvent, getEventContext, getUrlPrefix, handleResponse, handler, isError, replaceRuntimeValues, silgiCLICtx, silgiCtx, silgiFetch, storageMount, tryUseSilgi, tryUseSilgiCLI, updateRuntimeStorage, useRuntime, useSilgi, useSilgiCLI, useSilgiStorage };
|
package/dist/core/index.mjs
CHANGED
|
@@ -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,
|
|
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.path ?? getRouterParams(event);
|
|
541
|
+
const queryParams = _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,
|
|
@@ -821,20 +828,6 @@ function withDuplexIfBody(options) {
|
|
|
821
828
|
}
|
|
822
829
|
return options;
|
|
823
830
|
}
|
|
824
|
-
function createSilgiCore(event) {
|
|
825
|
-
return {
|
|
826
|
-
resolve: async (path, method, context) => {
|
|
827
|
-
const silgiCtx = useSilgi();
|
|
828
|
-
if (!silgiCtx.router) {
|
|
829
|
-
return void 0;
|
|
830
|
-
}
|
|
831
|
-
const routeStr = substitutePathParams(String(path), context?.pathParams);
|
|
832
|
-
const methodStr = String(method);
|
|
833
|
-
const match = findRoute(silgiCtx.router, methodStr, routeStr);
|
|
834
|
-
return match?.data?.service;
|
|
835
|
-
}
|
|
836
|
-
};
|
|
837
|
-
}
|
|
838
831
|
async function silgiFetch(_request, options, context) {
|
|
839
832
|
const silgiCtx = useSilgi();
|
|
840
833
|
let request;
|
|
@@ -870,13 +863,13 @@ async function silgiFetch(_request, options, context) {
|
|
|
870
863
|
}
|
|
871
864
|
return handleResponse(handlerRes, silgiEvent, {});
|
|
872
865
|
}
|
|
873
|
-
async function handler(event) {
|
|
866
|
+
async function handler(event, url, input) {
|
|
874
867
|
const silgiCtx = useSilgi();
|
|
875
|
-
const pathname = event.url.pathname;
|
|
868
|
+
const pathname = url?.path || event.url.pathname;
|
|
876
869
|
let _chain = void 0;
|
|
877
870
|
_chain = Promise.resolve(await silgiCtx.callHook("request:on", event));
|
|
878
871
|
if (silgiCtx.router) {
|
|
879
|
-
const match = findRoute(silgiCtx.router, event.req.method, pathname);
|
|
872
|
+
const match = findRoute(silgiCtx.router, url?.method || event.req.method, pathname);
|
|
880
873
|
if (match) {
|
|
881
874
|
if (_chain) {
|
|
882
875
|
return _chain.then(async (_previous) => {
|
|
@@ -885,12 +878,12 @@ async function handler(event) {
|
|
|
885
878
|
}
|
|
886
879
|
event.context.params = match.params;
|
|
887
880
|
event.context.matchedRoute = match.data;
|
|
888
|
-
return orchestrate(match.data, event);
|
|
881
|
+
return orchestrate(match.data, event, input);
|
|
889
882
|
});
|
|
890
883
|
} else {
|
|
891
884
|
event.context.params = match.params;
|
|
892
885
|
event.context.matchedRoute = match.data;
|
|
893
|
-
return orchestrate(match.data, event);
|
|
886
|
+
return orchestrate(match.data, event, input);
|
|
894
887
|
}
|
|
895
888
|
}
|
|
896
889
|
}
|
|
@@ -991,4 +984,4 @@ const autoImportTypes = [
|
|
|
991
984
|
"ExtractQueryParamsFromURI"
|
|
992
985
|
];
|
|
993
986
|
|
|
994
|
-
export { SilgiError, autoImportTypes, createError, createRoute, createSchema, createService, createShared, createSilgi,
|
|
987
|
+
export { SilgiError, autoImportTypes, createError, createRoute, createSchema, createService, createShared, createSilgi, createStorage, deepMergeObjects, getEvent, getEventContext, getUrlPrefix, handleResponse, handler, isError, replaceRuntimeValues, silgiCtx, silgiFetch, storageMount, tryUseSilgi, updateRuntimeStorage, useRuntime, useSilgi, useSilgiStorage };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
export { SilgiError, autoImportTypes, createError, createRoute, createSchema, createService, createShared, createSilgi,
|
|
1
|
+
export { SilgiError, autoImportTypes, createError, createRoute, createSchema, createService, createShared, createSilgi, createStorage, deepMergeObjects, getEvent, getEventContext, getUrlPrefix, handleResponse, handler, isError, replaceRuntimeValues, silgiCLICtx, silgiCtx, silgiFetch, storageMount, tryUseSilgi, tryUseSilgiCLI, updateRuntimeStorage, useRuntime, useSilgi, useSilgiCLI, useSilgiStorage } from './core/index.mjs';
|
|
2
2
|
import 'silgi/types';
|
|
3
|
-
import '@standard-schema/spec';
|
|
4
3
|
import 'unstorage';
|
|
5
4
|
import 'unctx';
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { SilgiError, autoImportTypes, createError, createRoute, createSchema, createService, createShared, createSilgi,
|
|
1
|
+
export { SilgiError, autoImportTypes, createError, createRoute, createSchema, createService, createShared, createSilgi, createStorage, deepMergeObjects, getEvent, getEventContext, getUrlPrefix, handleResponse, handler, isError, replaceRuntimeValues, silgiCtx, silgiFetch, storageMount, tryUseSilgi, updateRuntimeStorage, useRuntime, useSilgi, useSilgiStorage } from './core/index.mjs';
|
|
2
2
|
export { s as silgiCLICtx, t as tryUseSilgiCLI, u as useSilgiCLI } from './_chunks/silgiApp.mjs';
|
|
3
3
|
import 'consola';
|
|
4
4
|
import 'defu';
|
package/dist/types/index.d.mts
CHANGED