silgi 0.41.17 → 0.41.19
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/build.mjs +23 -8
- package/dist/cli/index.mjs +1 -1
- package/dist/core/index.d.mts +19 -25
- package/dist/core/index.mjs +62 -51
- package/dist/index.mjs +1 -0
- package/dist/types/index.d.mts +32 -25
- package/package.json +2 -1
package/dist/cli/build.mjs
CHANGED
|
@@ -1953,15 +1953,30 @@ async function prepareSchema(silgi) {
|
|
|
1953
1953
|
generateTypes(
|
|
1954
1954
|
await resolveSchema(
|
|
1955
1955
|
{
|
|
1956
|
-
...
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1956
|
+
...Object.fromEntries(
|
|
1957
|
+
Object.entries(silgi.options.runtimeConfig).filter(
|
|
1958
|
+
([key]) => !["app", "nitro", "nuxt"].includes(key)
|
|
1959
|
+
)
|
|
1960
|
+
)
|
|
1961
|
+
}
|
|
1962
|
+
),
|
|
1963
|
+
{
|
|
1964
|
+
interfaceName: "SilgiRuntimeConfigExtends",
|
|
1965
|
+
addExport: false,
|
|
1966
|
+
addDefaults: false,
|
|
1967
|
+
allowExtraKeys: false,
|
|
1968
|
+
indentation: 0
|
|
1969
|
+
}
|
|
1970
|
+
),
|
|
1971
|
+
"",
|
|
1972
|
+
generateTypes(
|
|
1973
|
+
await resolveSchema(
|
|
1974
|
+
{
|
|
1975
|
+
...silgi.services ? Object.keys(silgi.services).reduce((acc, key) => ({ ...acc, [key]: "" }), {}) : {}
|
|
1961
1976
|
}
|
|
1962
1977
|
),
|
|
1963
1978
|
{
|
|
1964
|
-
interfaceName: "
|
|
1979
|
+
interfaceName: "RoutersExtend",
|
|
1965
1980
|
addExport: false,
|
|
1966
1981
|
addDefaults: false,
|
|
1967
1982
|
allowExtraKeys: false,
|
|
@@ -1977,7 +1992,6 @@ async function prepareSchema(silgi) {
|
|
|
1977
1992
|
SilgiSchema: [{}, { extends: ["SchemaExtends"] }],
|
|
1978
1993
|
ServicesObject: [{}, { extends: ["BaseServices"] }],
|
|
1979
1994
|
SilgiStorageBase: [{}, { extends: ["SilgiStorageBaseExtends"] }],
|
|
1980
|
-
SilgiURIs: [{}, { extends: ["SilgiURIsMerge"] }],
|
|
1981
1995
|
SilgiRuntimeContext: [{}, { extends: ["SilgiModuleContextExtends"] }],
|
|
1982
1996
|
SilgiEvent: [{}, { extends: ["SilgiModuleEventsExtends"] }],
|
|
1983
1997
|
SilgiRuntimeSharedsExtend: [{}, { extends: ["SilgiModuleSharedExtends"] }],
|
|
@@ -1991,7 +2005,8 @@ async function prepareSchema(silgi) {
|
|
|
1991
2005
|
SilgiModuleOptions: [{}, { extends: ["SilgiModuleOptionExtend"] }],
|
|
1992
2006
|
// TODO: bunu kontrol et.
|
|
1993
2007
|
RouteRules: [{}, { extends: ["RouteRulesExtend"] }],
|
|
1994
|
-
MetaData: [{}, { extends: ["MetaDataExtend"] }]
|
|
2008
|
+
MetaData: [{}, { extends: ["MetaDataExtend"] }],
|
|
2009
|
+
Routers: [{}, { extends: ["RoutersExtend"] }]
|
|
1995
2010
|
}).replace(/,\s*/g, "\n"),
|
|
1996
2011
|
"",
|
|
1997
2012
|
"export {}"
|
package/dist/cli/index.mjs
CHANGED
package/dist/core/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SilgiConfig, Silgi, SilgiEvent, HTTPMethod, SilgiSchema, RouteEntry, CustomRequestInit, SilgiRuntimeContext, BaseMethodSchema, MergeAll,
|
|
1
|
+
import { SilgiConfig, Silgi, SilgiEvent, HTTPMethod, SilgiSchema, RouteEntry, CustomRequestInit, SilgiRuntimeContext, BaseMethodSchema, MergeAll, Routers, ServiceSetup, MiddlewareSetup, SilgiRuntimeShareds, Resolvers, SilgiURL, StorageConfig, SilgiCLI, SilgiStorageBase, SilgiRuntimeConfig } from 'silgi/types';
|
|
2
2
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
3
3
|
import { Storage, StorageValue } from 'unstorage';
|
|
4
4
|
import { UseContext } from 'unctx';
|
|
@@ -159,33 +159,27 @@ declare function deepMergeObjects<T extends readonly Record<string, any>[]>(sche
|
|
|
159
159
|
* Tip güvenliğini artırmak için ServiceSetup objesini doğrudan döndürür.
|
|
160
160
|
*/
|
|
161
161
|
type SlashCount<S extends string, Count extends any[] = []> = S extends `${infer _Prefix}/${infer Rest}` ? SlashCount<Rest, [any, ...Count]> : Count['length'];
|
|
162
|
-
type Max4Slashes<S extends
|
|
163
|
-
|
|
162
|
+
type Max4Slashes<S extends keyof Routers> = SlashCount<S> extends 0 | 1 | 2 | 3 ? S : never;
|
|
163
|
+
type ServiceSetupsForMethods<Parent extends StandardSchemaV1, 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> = {
|
|
164
|
+
GET?: ServiceSetup<Parent, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
165
|
+
POST?: ServiceSetup<Parent, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
166
|
+
PUT?: ServiceSetup<Parent, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
167
|
+
PATCH?: ServiceSetup<Parent, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
168
|
+
DELETE?: ServiceSetup<Parent, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
169
|
+
OPTIONS?: ServiceSetup<Parent, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
170
|
+
HEAD?: ServiceSetup<Parent, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
171
|
+
CONNECT?: ServiceSetup<Parent, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
172
|
+
TRACE?: ServiceSetup<Parent, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
173
|
+
};
|
|
174
|
+
declare function createService<Parent extends StandardSchemaV1, Path extends keyof Routers = keyof Routers, 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>(params: {
|
|
164
175
|
path: Max4Slashes<Path>;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
output?: Output;
|
|
168
|
-
queryParams?: {
|
|
169
|
-
path?: PathParams;
|
|
170
|
-
query?: QueryParams;
|
|
171
|
-
};
|
|
172
|
-
setup: ServiceSetup<Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
173
|
-
}): {
|
|
174
|
-
[K in Path]: {
|
|
175
|
-
setup: ServiceSetup<Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
176
|
-
methods?: HTTPMethod[];
|
|
177
|
-
input?: Input;
|
|
178
|
-
output?: Output;
|
|
179
|
-
queryParams?: {
|
|
180
|
-
path?: PathParams;
|
|
181
|
-
query?: QueryParams;
|
|
182
|
-
};
|
|
183
|
-
};
|
|
176
|
+
} & ServiceSetupsForMethods<Parent, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>): {
|
|
177
|
+
[K in Path]: ServiceSetupsForMethods<Parent, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
184
178
|
};
|
|
185
179
|
|
|
186
180
|
type WildcardVariants<Path extends string, Acc extends string = ''> = Path extends `${infer Head}/${infer Tail}` ? Tail extends '' ? `${Acc}${Head}` : `${Acc}${Head}/${Tail}` | `${Acc}${Head}/*` | `${Acc}${Head}/**` | WildcardVariants<Tail, `${Acc}${Head}/`> : `${Acc}${Path}`;
|
|
187
|
-
type MiddlewarePath<S extends WildcardVariants<keyof
|
|
188
|
-
interface CreateMiddlewareParams<S extends WildcardVariants<keyof
|
|
181
|
+
type MiddlewarePath<S extends WildcardVariants<keyof Routers>> = S | 'global';
|
|
182
|
+
interface CreateMiddlewareParams<S extends WildcardVariants<keyof Routers>, UsedMethod extends readonly HTTPMethod[] = readonly HTTPMethod[], Key extends string = string> {
|
|
189
183
|
path: MiddlewarePath<S>;
|
|
190
184
|
methods?: UsedMethod;
|
|
191
185
|
setup: MiddlewareSetup;
|
|
@@ -199,7 +193,7 @@ type CreateMiddlewareResult<Path extends string, UsedMethod extends readonly HTT
|
|
|
199
193
|
path: Path;
|
|
200
194
|
};
|
|
201
195
|
};
|
|
202
|
-
declare function createMiddleware<S extends WildcardVariants<keyof
|
|
196
|
+
declare function createMiddleware<S extends WildcardVariants<keyof Routers>, UsedMethod extends readonly HTTPMethod[] = readonly HTTPMethod[], Path extends MiddlewarePath<S> = MiddlewarePath<S>, Key extends string = string>(params: CreateMiddlewareParams<S, UsedMethod, Key> & {
|
|
203
197
|
path: Path;
|
|
204
198
|
}): CreateMiddlewareResult<Path, UsedMethod, Key>;
|
|
205
199
|
|
package/dist/core/index.mjs
CHANGED
|
@@ -8,6 +8,7 @@ import { Buffer } from 'node:buffer';
|
|
|
8
8
|
import { klona } from 'klona';
|
|
9
9
|
import { createStorage as createStorage$1, builtinDrivers, prefixStorage } from 'unstorage';
|
|
10
10
|
import { isDevelopment } from 'std-env';
|
|
11
|
+
import { toJsonSchema } from '@standard-community/standard-json';
|
|
11
12
|
import { FastURL, FastResponse } from 'srvx';
|
|
12
13
|
export { s as silgiCLICtx, t as tryUseSilgiCLI, u as useSilgiCLI } from '../_chunks/silgiApp.mjs';
|
|
13
14
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
@@ -298,29 +299,37 @@ async function createSilgi(config) {
|
|
|
298
299
|
silgi.router = createRouter();
|
|
299
300
|
}
|
|
300
301
|
for (const [route, object] of Object.entries(silgi.services)) {
|
|
301
|
-
const
|
|
302
|
-
if (
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
service: object
|
|
307
|
-
});
|
|
308
|
-
continue;
|
|
309
|
-
} else {
|
|
310
|
-
const routeParts = route.split("/").filter(Boolean);
|
|
311
|
-
if (routeParts.length > 0) {
|
|
312
|
-
const prefix = `/${routeParts[0]}`;
|
|
313
|
-
if (!silgi.routerPrefixs.includes(prefix)) {
|
|
314
|
-
silgi.routerPrefixs.push(prefix);
|
|
315
|
-
}
|
|
302
|
+
const routeParts = route.split("/").filter(Boolean);
|
|
303
|
+
if (routeParts.length > 0) {
|
|
304
|
+
const prefix = `/${routeParts[0]}`;
|
|
305
|
+
if (!silgi.routerPrefixs.includes(prefix)) {
|
|
306
|
+
silgi.routerPrefixs.push(prefix);
|
|
316
307
|
}
|
|
317
308
|
}
|
|
318
|
-
for (const method of
|
|
319
|
-
|
|
320
|
-
|
|
309
|
+
for (const [method, routeObject] of Object.entries(object)) {
|
|
310
|
+
let routeWithParams = route;
|
|
311
|
+
if (routeObject.pathParams) {
|
|
312
|
+
const jsonSchema = await toJsonSchema(routeObject.pathParams);
|
|
313
|
+
if (jsonSchema && jsonSchema.properties) {
|
|
314
|
+
const paramNames = Object.keys(jsonSchema.properties);
|
|
315
|
+
if (paramNames.length > 0) {
|
|
316
|
+
const routeParts2 = routeWithParams.split("/");
|
|
317
|
+
const lastParts = routeParts2.slice(-paramNames.length);
|
|
318
|
+
const alreadyHasParams = paramNames.every((name, idx) => lastParts[idx] === `:${name}`);
|
|
319
|
+
if (!alreadyHasParams) {
|
|
320
|
+
routeWithParams = routeWithParams.replace(/\/+$/, "");
|
|
321
|
+
for (const param of paramNames) {
|
|
322
|
+
routeWithParams += `/:${param}`;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
console.log("Route:", routeWithParams, method);
|
|
329
|
+
addRoute(silgi.router, method, routeWithParams, {
|
|
321
330
|
method,
|
|
322
|
-
route,
|
|
323
|
-
service:
|
|
331
|
+
route: routeWithParams,
|
|
332
|
+
service: routeObject
|
|
324
333
|
});
|
|
325
334
|
}
|
|
326
335
|
}
|
|
@@ -391,12 +400,16 @@ class _SilgiEvent {
|
|
|
391
400
|
req;
|
|
392
401
|
url;
|
|
393
402
|
context;
|
|
403
|
+
protocol;
|
|
404
|
+
// Added property
|
|
394
405
|
_res;
|
|
395
406
|
constructor(req, context) {
|
|
396
407
|
this.context = context || new EmptyObject();
|
|
397
408
|
this.req = req;
|
|
398
409
|
const _url = req._url;
|
|
399
410
|
this.url = _url && _url instanceof URL ? _url : new FastURL(req.url);
|
|
411
|
+
let proto = this.url.protocol.replace(":", "");
|
|
412
|
+
this.protocol = proto === "https" ? "http" : proto;
|
|
400
413
|
}
|
|
401
414
|
get res() {
|
|
402
415
|
if (!this._res) {
|
|
@@ -607,7 +620,7 @@ async function orchestrate(route, event, _input) {
|
|
|
607
620
|
pathParams: {},
|
|
608
621
|
queryParams: {}
|
|
609
622
|
};
|
|
610
|
-
const input = _input || (route.service?.
|
|
623
|
+
const input = _input || (route.service?.rules?.readBeforeBody === false || isGraphQL ? {} : await parseRequestInput(event.req));
|
|
611
624
|
const hookContext = { earlyReturnValue: false };
|
|
612
625
|
const routerParams = _input ? input.path : getRouterParams(event);
|
|
613
626
|
const queryParams = _input ? input.query : getQuery(event);
|
|
@@ -619,10 +632,8 @@ async function orchestrate(route, event, _input) {
|
|
|
619
632
|
}
|
|
620
633
|
const inputData = {
|
|
621
634
|
args: input,
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
path: routerParams
|
|
625
|
-
}
|
|
635
|
+
query: queryParams,
|
|
636
|
+
path: routerParams
|
|
626
637
|
};
|
|
627
638
|
try {
|
|
628
639
|
if (!route.service && route.method !== "GRAPHQL") {
|
|
@@ -660,10 +671,17 @@ async function orchestrate(route, event, _input) {
|
|
|
660
671
|
}
|
|
661
672
|
silgiCtx.shared.$fetch = silgiFetch;
|
|
662
673
|
silgiCtx.shared.silgi = silgiCtx;
|
|
663
|
-
const result = await route.service?.
|
|
674
|
+
const result = await route.service?.handler?.(
|
|
675
|
+
// input
|
|
664
676
|
inputData,
|
|
677
|
+
// shared
|
|
665
678
|
silgiCtx.shared,
|
|
666
|
-
event
|
|
679
|
+
// event
|
|
680
|
+
event,
|
|
681
|
+
// parent - graphql
|
|
682
|
+
{},
|
|
683
|
+
// info - graphql
|
|
684
|
+
{}
|
|
667
685
|
);
|
|
668
686
|
await silgiCtx.callHook("fetch:after", {
|
|
669
687
|
event,
|
|
@@ -674,12 +692,12 @@ async function orchestrate(route, event, _input) {
|
|
|
674
692
|
route,
|
|
675
693
|
hookContext
|
|
676
694
|
});
|
|
677
|
-
if (route.service?.
|
|
678
|
-
await useSilgiStorage(route.service.
|
|
695
|
+
if (route.service?.storage && cacheData?.cachedKey) {
|
|
696
|
+
await useSilgiStorage(route.service.storage.base).setItem(
|
|
679
697
|
cacheData.cachedKey,
|
|
680
698
|
result,
|
|
681
699
|
// Cast to StorageValue if needed
|
|
682
|
-
route.service.
|
|
700
|
+
route.service.storage.options
|
|
683
701
|
);
|
|
684
702
|
}
|
|
685
703
|
return result;
|
|
@@ -709,17 +727,17 @@ async function orchestrate(route, event, _input) {
|
|
|
709
727
|
}
|
|
710
728
|
}
|
|
711
729
|
async function cacheExecute(input, route, silgiURL, event) {
|
|
712
|
-
if (!route.service || !route.service.
|
|
730
|
+
if (!route.service || !route.service.storage)
|
|
713
731
|
return;
|
|
714
|
-
const cacheKey = route.service.
|
|
732
|
+
const cacheKey = route.service.storage ? await generateStorageKey({
|
|
715
733
|
url: silgiURL,
|
|
716
734
|
input,
|
|
717
|
-
keyGenerator: route.service.
|
|
718
|
-
storageOptions: route.service.
|
|
735
|
+
keyGenerator: route.service.storage.key,
|
|
736
|
+
storageOptions: route.service.storage,
|
|
719
737
|
requestId: event?.requestId
|
|
720
738
|
}) : null;
|
|
721
739
|
if (cacheKey) {
|
|
722
|
-
const cachedResult = await useSilgiStorage(route.service.
|
|
740
|
+
const cachedResult = await useSilgiStorage(route.service.storage.base).getItem(cacheKey);
|
|
723
741
|
if (cachedResult !== null) {
|
|
724
742
|
return {
|
|
725
743
|
success: true,
|
|
@@ -941,7 +959,7 @@ async function middleware(event, url) {
|
|
|
941
959
|
return _previous;
|
|
942
960
|
}
|
|
943
961
|
const allowedMethod = m.method ?? "";
|
|
944
|
-
const methodIsAllowed = allowedMethod ===
|
|
962
|
+
const methodIsAllowed = allowedMethod === event.req.method || event.protocol === "GRAPHQL";
|
|
945
963
|
if (!methodIsAllowed) {
|
|
946
964
|
return;
|
|
947
965
|
}
|
|
@@ -976,7 +994,7 @@ async function middleware(event, url) {
|
|
|
976
994
|
return _previous;
|
|
977
995
|
}
|
|
978
996
|
const allowedMethod = match.data.method ?? "";
|
|
979
|
-
const methodIsAllowed = allowedMethod ===
|
|
997
|
+
const methodIsAllowed = allowedMethod === event.req.method || event.protocol === "GRAPHQL";
|
|
980
998
|
if (!methodIsAllowed || !match.data.middleware) {
|
|
981
999
|
return;
|
|
982
1000
|
}
|
|
@@ -1016,10 +1034,7 @@ async function handler(event, url, input) {
|
|
|
1016
1034
|
data: {
|
|
1017
1035
|
method: url?.method || event.req.method,
|
|
1018
1036
|
route: url?.path,
|
|
1019
|
-
service: {
|
|
1020
|
-
setup: {},
|
|
1021
|
-
methods: ["GRAPHQL"]
|
|
1022
|
-
}
|
|
1037
|
+
service: {}
|
|
1023
1038
|
},
|
|
1024
1039
|
params: {}
|
|
1025
1040
|
};
|
|
@@ -1091,22 +1106,18 @@ function deepMergeObjects(schemas) {
|
|
|
1091
1106
|
}
|
|
1092
1107
|
|
|
1093
1108
|
function createService(params) {
|
|
1094
|
-
const slashCount = (params.path.match(/\//g) || []).length;
|
|
1109
|
+
const slashCount = (String(params.path).match(/\//g) || []).length;
|
|
1095
1110
|
if (slashCount > 4) {
|
|
1096
1111
|
throw new Error(
|
|
1097
1112
|
`Path '${params.path}' is invalid: maximum 4 '/' allowed (found ${slashCount})`
|
|
1098
1113
|
);
|
|
1099
1114
|
}
|
|
1100
|
-
const
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
input,
|
|
1106
|
-
output,
|
|
1107
|
-
queryParams
|
|
1115
|
+
const { path, ...objects } = params;
|
|
1116
|
+
return {
|
|
1117
|
+
[path]: {
|
|
1118
|
+
...objects
|
|
1119
|
+
}
|
|
1108
1120
|
};
|
|
1109
|
-
return result;
|
|
1110
1121
|
}
|
|
1111
1122
|
|
|
1112
1123
|
function createMiddleware(params) {
|
package/dist/index.mjs
CHANGED
package/dist/types/index.d.mts
CHANGED
|
@@ -25,6 +25,7 @@ import { ServerRequest } from 'srvx';
|
|
|
25
25
|
import { Defu } from 'defu';
|
|
26
26
|
import { silgiFetch } from 'silgi';
|
|
27
27
|
import { useRuntimeConfig } from 'silgi/runtime';
|
|
28
|
+
import { GraphQLResolveInfo } from 'graphql';
|
|
28
29
|
import { Unimport } from 'unimport';
|
|
29
30
|
import { ProviderName } from 'std-env';
|
|
30
31
|
import { FetchOptions, FetchResponse } from 'ofetch';
|
|
@@ -99,10 +100,15 @@ interface SilgiRuntimeContext extends Record<string, any> {
|
|
|
99
100
|
runtimeConfig?: SilgiRuntimeConfig;
|
|
100
101
|
};
|
|
101
102
|
}
|
|
103
|
+
type EventProtocol = 'GRAPHQL' | 'HTTP' | 'WEBSOCKET';
|
|
102
104
|
/**
|
|
103
105
|
* Bu nitrojs, h3 event or request context.
|
|
104
106
|
*/
|
|
105
107
|
interface SilgiEvent extends Record<string, unknown> {
|
|
108
|
+
/**
|
|
109
|
+
* Protocol Type
|
|
110
|
+
*/
|
|
111
|
+
readonly protocol: EventProtocol;
|
|
106
112
|
/**
|
|
107
113
|
* Event context.
|
|
108
114
|
*/
|
|
@@ -134,6 +140,8 @@ interface SilgiEvent extends Record<string, unknown> {
|
|
|
134
140
|
*/
|
|
135
141
|
interface Resolvers {
|
|
136
142
|
}
|
|
143
|
+
interface Routers {
|
|
144
|
+
}
|
|
137
145
|
interface RouteRules extends Record<string, unknown> {
|
|
138
146
|
}
|
|
139
147
|
type MergeRouteRules = Partial<RouteRules> & {
|
|
@@ -158,7 +166,7 @@ type ExtractRoute<URL extends string> = URL extends `/${string}/${string}/${infe
|
|
|
158
166
|
* Gets all route keys from Routers as strings.
|
|
159
167
|
* All keys should start with a leading slash.
|
|
160
168
|
*/
|
|
161
|
-
type RouterKeys = keyof ServicesObject & string;
|
|
169
|
+
type RouterKeys = (keyof ServicesObject extends string ? keyof ServicesObject : never) & (keyof Routers extends string ? keyof Routers : never);
|
|
162
170
|
/**
|
|
163
171
|
* Extracts all prefixes (first segment) in the system, including the leading slash.
|
|
164
172
|
* @example AllPrefixes // '/api' | ...
|
|
@@ -241,20 +249,14 @@ type ServiceHandlerInput<Input extends StandardSchemaV1 = StandardSchemaV1, Path
|
|
|
241
249
|
args: InferInput<Input>;
|
|
242
250
|
} : HasPath<PathParams> extends true ? HasQuery<QueryParams> extends true ? {
|
|
243
251
|
args: InferInput<Input>;
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
query: Partial<InferInput<QueryParams>>;
|
|
247
|
-
};
|
|
252
|
+
path: InferInput<PathParams>;
|
|
253
|
+
query: Partial<InferInput<QueryParams>>;
|
|
248
254
|
} : {
|
|
249
255
|
args: InferInput<Input>;
|
|
250
|
-
|
|
251
|
-
path: InferInput<PathParams>;
|
|
252
|
-
};
|
|
256
|
+
path: InferInput<PathParams>;
|
|
253
257
|
} : HasQuery<QueryParams> extends true ? {
|
|
254
258
|
args: InferInput<Input>;
|
|
255
|
-
|
|
256
|
-
query: InferInput<QueryParams>;
|
|
257
|
-
};
|
|
259
|
+
query: InferInput<QueryParams>;
|
|
258
260
|
} : {
|
|
259
261
|
args: InferInput<Input>;
|
|
260
262
|
};
|
|
@@ -264,15 +266,19 @@ type ServiceHandlerInput<Input extends StandardSchemaV1 = StandardSchemaV1, Path
|
|
|
264
266
|
* Resolved = false -> handler(input, shared, event, source) // all required
|
|
265
267
|
* Resolved = true -> handler(input, shared?, event?, source?) // only input required
|
|
266
268
|
*/
|
|
267
|
-
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>;
|
|
269
|
+
type ServiceHandler<Parent extends StandardSchemaV1, 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, parent?: Parent, info?: GraphQLResolveInfo) => Promise<InferOutput<Output>> | InferOutput<Output> : (input: ServiceHandlerInput<Input, PathParams, QueryParams, HiddenParameters>, shared: SilgiRuntimeShareds, event: SilgiEvent, parent: Parent, info: GraphQLResolveInfo) => Promise<InferOutput<Output>> | InferOutput<Output>;
|
|
268
270
|
/**
|
|
269
271
|
* Servis setup tipi
|
|
270
272
|
*/
|
|
271
|
-
interface ServiceSetup<Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 |
|
|
272
|
-
handler?: ServiceHandler<Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
273
|
+
interface ServiceSetup<Parent extends StandardSchemaV1, 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> {
|
|
274
|
+
handler?: ServiceHandler<Parent, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
273
275
|
rules?: MergeRouteRules;
|
|
274
276
|
modules?: Partial<SetupModuleOption>;
|
|
275
277
|
storage?: StorageConfig<ServiceHandlerInput<Input, PathParams, QueryParams, HiddenParameters>>;
|
|
278
|
+
input?: Input;
|
|
279
|
+
output?: Output;
|
|
280
|
+
pathParams?: PathParams;
|
|
281
|
+
queryParams?: QueryParams;
|
|
276
282
|
}
|
|
277
283
|
/**
|
|
278
284
|
* Represents a fully resolved service definition that maps route paths
|
|
@@ -285,14 +291,15 @@ interface ServiceSetup<Input extends StandardSchemaV1 = StandardSchemaV1, Output
|
|
|
285
291
|
*/
|
|
286
292
|
interface ResolvedServiceDefinition {
|
|
287
293
|
[routePath: string]: {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
294
|
+
GET?: ServiceSetup<any, any, any, any, any, any>;
|
|
295
|
+
POST?: ServiceSetup<any, any, any, any, any, any>;
|
|
296
|
+
PUT?: ServiceSetup<any, any, any, any, any, any>;
|
|
297
|
+
PATCH?: ServiceSetup<any, any, any, any, any, any>;
|
|
298
|
+
DELETE?: ServiceSetup<any, any, any, any, any, any>;
|
|
299
|
+
OPTIONS?: ServiceSetup<any, any, any, any, any, any>;
|
|
300
|
+
HEAD?: ServiceSetup<any, any, any, any, any, any>;
|
|
301
|
+
CONNECT?: ServiceSetup<any, any, any, any, any, any>;
|
|
302
|
+
TRACE?: ServiceSetup<any, any, any, any, any, any>;
|
|
296
303
|
};
|
|
297
304
|
}
|
|
298
305
|
/**
|
|
@@ -691,14 +698,14 @@ interface ResolvedSchemaDefinition {
|
|
|
691
698
|
[methodAndRoutePath: string]: BaseMethodSchema;
|
|
692
699
|
}
|
|
693
700
|
|
|
694
|
-
type StandardHTTPMethod = 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE'
|
|
701
|
+
type StandardHTTPMethod = 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE';
|
|
695
702
|
type HTTPMethod = StandardHTTPMethod | (keyof SilgiRuntimeMethods extends string ? keyof SilgiRuntimeMethods : never);
|
|
696
703
|
interface MetaData extends Record<string, unknown> {
|
|
697
704
|
}
|
|
698
705
|
interface SilgiRoute {
|
|
699
706
|
route?: string;
|
|
700
707
|
method?: HTTPMethod;
|
|
701
|
-
service?: ResolvedServiceDefinition[string];
|
|
708
|
+
service?: ResolvedServiceDefinition[string][keyof ResolvedServiceDefinition[string]];
|
|
702
709
|
middleware?: MiddlewareSetup;
|
|
703
710
|
}
|
|
704
711
|
interface Silgi {
|
|
@@ -1222,4 +1229,4 @@ interface LoadConfigOptions {
|
|
|
1222
1229
|
consola?: ConsolaInstance;
|
|
1223
1230
|
}
|
|
1224
1231
|
|
|
1225
|
-
export type { AllPaths, AllPrefixes, AppConfig, Awaitable, BaseMethodSchema, BuildSilgi, CaptureError, CapturedErrorContext, CommandType, Commands, CustomRequestInit, DeepPartial, DeepRequired, DefaultHooks, DefineFrameworkOptions, DotenvOptions, EnvOptions, EventHandlerResponse, ExtendContext, ExtendShared, ExtractNamespace, ExtractPathParamKeys, ExtractPathParams, ExtractPrefix, ExtractRoute, GenImport, GenerateAppOptions, HTTPMethod, HasPathParams, HookResult, LoadConfigOptions, MergeAll, MergeRouteRules, MergedSilgiSchema, MetaData, MethodSchemas, MiddlewareHandler, MiddlewareSetup, ModuleDefinition, ModuleHookContext, ModuleMeta, ModuleOptionsCustom, ModuleSetupInstallResult, ModuleSetupReturn, NamespacesForPrefix, NitroBuildInfo, RequiredServiceType, ResolvedMiddlewareDefinition, ResolvedModuleMeta, ResolvedModuleOptions, ResolvedSchema, ResolvedSchemaDefinition, ResolvedServiceDefinition, ResolvedSilgiTemplate, Resolvers, RouteEntry, RouteRules, RouterParams, RoutesForPrefixAndNamespace, ScanFile, Schema, ServiceHandler, ServiceHandlerInput, ServiceSetup, ServicesObject, SetupModuleOption, Silgi, SilgiAppPlugin, SilgiCLI, SilgiCLIConfig, SilgiCLIHooks, SilgiCLIOptions, SilgiCommands, SilgiCompatibility, SilgiCompatibilityIssue, SilgiCompatibilityIssues, SilgiConfig, SilgiEvent, SilgiFetchClient, SilgiFetchOptions, SilgiFrameworkInfo, SilgiHooks, SilgiModule, SilgiModuleInput, SilgiModuleOptions, SilgiOptions, SilgiPreset, SilgiPresetMeta, SilgiRoute, SilgiRouterTypes, SilgiRuntimeConfig, SilgiRuntimeContext, SilgiRuntimeDefaultConfig, SilgiRuntimeHooks, SilgiRuntimeMethods, SilgiRuntimeOptions, SilgiRuntimeShareds, SilgiRuntimeSharedsExtend, SilgiSchema, SilgiStorageBase, SilgiTemplate, SilgiURL, StandardHTTPMethod, StorageConfig, StorageKeyGenerator, StorageKeyParams, StorageMounts, TSReference, TrimAfterFourSlashes, WithPathParams };
|
|
1232
|
+
export type { AllPaths, AllPrefixes, AppConfig, Awaitable, BaseMethodSchema, BuildSilgi, CaptureError, CapturedErrorContext, CommandType, Commands, CustomRequestInit, DeepPartial, DeepRequired, DefaultHooks, DefineFrameworkOptions, DotenvOptions, EnvOptions, EventHandlerResponse, EventProtocol, ExtendContext, ExtendShared, ExtractNamespace, ExtractPathParamKeys, ExtractPathParams, ExtractPrefix, ExtractRoute, GenImport, GenerateAppOptions, HTTPMethod, HasPathParams, HookResult, LoadConfigOptions, MergeAll, MergeRouteRules, MergedSilgiSchema, MetaData, MethodSchemas, MiddlewareHandler, MiddlewareSetup, ModuleDefinition, ModuleHookContext, ModuleMeta, ModuleOptionsCustom, ModuleSetupInstallResult, ModuleSetupReturn, NamespacesForPrefix, NitroBuildInfo, RequiredServiceType, ResolvedMiddlewareDefinition, ResolvedModuleMeta, ResolvedModuleOptions, ResolvedSchema, ResolvedSchemaDefinition, ResolvedServiceDefinition, ResolvedSilgiTemplate, Resolvers, RouteEntry, RouteRules, RouterParams, Routers, RoutesForPrefixAndNamespace, ScanFile, Schema, ServiceHandler, ServiceHandlerInput, ServiceSetup, ServicesObject, SetupModuleOption, Silgi, SilgiAppPlugin, SilgiCLI, SilgiCLIConfig, SilgiCLIHooks, SilgiCLIOptions, SilgiCommands, SilgiCompatibility, SilgiCompatibilityIssue, SilgiCompatibilityIssues, SilgiConfig, SilgiEvent, SilgiFetchClient, SilgiFetchOptions, SilgiFrameworkInfo, SilgiHooks, SilgiModule, SilgiModuleInput, SilgiModuleOptions, SilgiOptions, SilgiPreset, SilgiPresetMeta, SilgiRoute, SilgiRouterTypes, SilgiRuntimeConfig, SilgiRuntimeContext, SilgiRuntimeDefaultConfig, SilgiRuntimeHooks, SilgiRuntimeMethods, SilgiRuntimeOptions, SilgiRuntimeShareds, SilgiRuntimeSharedsExtend, SilgiSchema, SilgiStorageBase, SilgiTemplate, SilgiURL, StandardHTTPMethod, StorageConfig, StorageKeyGenerator, StorageKeyParams, StorageMounts, TSReference, TrimAfterFourSlashes, WithPathParams };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "silgi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.41.
|
|
4
|
+
"version": "0.41.19",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"exports": {
|
|
@@ -114,6 +114,7 @@
|
|
|
114
114
|
"dotenv": "^16.5.0",
|
|
115
115
|
"escape-string-regexp": "^5.0.0",
|
|
116
116
|
"exsolve": "^1.0.5",
|
|
117
|
+
"graphql": "^16.11.0",
|
|
117
118
|
"hookable": "^5.5.3",
|
|
118
119
|
"ignore": "^7.0.4",
|
|
119
120
|
"klona": "^2.0.6",
|