silgi 0.39.8 → 0.39.10
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 +16 -13
- package/dist/core/index.mjs +18 -8
- package/dist/types/index.d.mts +20 -19
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
package/dist/core/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SilgiConfig, Silgi, SilgiEvent, SilgiSchema, RouteEntry, CustomRequestInit, SilgiRuntimeContext, Routers, HTTPMethod, HasPathParams, BaseMethodSchema, WithPathParams, MergeAll,
|
|
1
|
+
import { SilgiConfig, Silgi, SilgiEvent, SilgiSchema, RouteEntry, CustomRequestInit, SilgiRuntimeContext, Routers, HTTPMethod, HasPathParams, BaseMethodSchema, WithPathParams, MergeAll, ServiceSetup, HttpMethod, MiddlewareSetup, SilgiRuntimeShareds, RouterConfig, SilgiURL, StorageConfig, SilgiCLI, SilgiStorageBase, SilgiRuntimeConfig } from 'silgi/types';
|
|
2
2
|
import { Storage, StorageValue } from 'unstorage';
|
|
3
3
|
import { UseContext } from 'unctx';
|
|
4
4
|
|
|
@@ -168,11 +168,25 @@ declare function createService<Schema extends SilgiSchema, Path extends keyof Sc
|
|
|
168
168
|
}): {
|
|
169
169
|
[K in Path]: ServiceSetup<Schema, Path, Resolved, HiddenParameters>;
|
|
170
170
|
};
|
|
171
|
+
|
|
171
172
|
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}`;
|
|
173
|
+
declare function createMiddleware<S extends WildcardVariants<keyof Routers>, Method extends HttpMethod, UsedMethod extends readonly Method[]>(params: {
|
|
174
|
+
path: S;
|
|
175
|
+
method: UsedMethod;
|
|
176
|
+
setup: MiddlewareSetup;
|
|
177
|
+
global?: undefined;
|
|
178
|
+
}): {
|
|
179
|
+
[K in `${UsedMethod[number]}:${S}`]: {
|
|
180
|
+
setup: MiddlewareSetup;
|
|
181
|
+
method: UsedMethod[number];
|
|
182
|
+
global: undefined;
|
|
183
|
+
};
|
|
184
|
+
};
|
|
172
185
|
declare function createMiddleware<Global extends string>(params: {
|
|
173
186
|
global: Global;
|
|
174
187
|
setup: MiddlewareSetup;
|
|
175
188
|
method?: undefined | readonly [];
|
|
189
|
+
path?: undefined;
|
|
176
190
|
}): {
|
|
177
191
|
[K in `GLOBAL:${Global}`]: {
|
|
178
192
|
setup: MiddlewareSetup;
|
|
@@ -184,6 +198,7 @@ declare function createMiddleware<Global extends string, Method extends HttpMeth
|
|
|
184
198
|
global: Global;
|
|
185
199
|
setup: MiddlewareSetup;
|
|
186
200
|
method: UsedMethod;
|
|
201
|
+
path?: undefined;
|
|
187
202
|
}): {
|
|
188
203
|
[K in `${UsedMethod[number]}:${Global}`]: {
|
|
189
204
|
setup: MiddlewareSetup;
|
|
@@ -191,18 +206,6 @@ declare function createMiddleware<Global extends string, Method extends HttpMeth
|
|
|
191
206
|
method: UsedMethod[number];
|
|
192
207
|
};
|
|
193
208
|
};
|
|
194
|
-
declare function createMiddleware<S extends WildcardVariants<keyof Routers>, Method extends HttpMethod, UsedMethod extends readonly Method[]>(params: {
|
|
195
|
-
path: S;
|
|
196
|
-
method: UsedMethod;
|
|
197
|
-
setup: MiddlewareSetup;
|
|
198
|
-
global?: undefined;
|
|
199
|
-
}): {
|
|
200
|
-
[K in `${UsedMethod[number]}:${S}`]: {
|
|
201
|
-
setup: MiddlewareSetup;
|
|
202
|
-
method: UsedMethod[number];
|
|
203
|
-
global: undefined;
|
|
204
|
-
};
|
|
205
|
-
};
|
|
206
209
|
|
|
207
210
|
declare function createShared(shared: Partial<SilgiRuntimeShareds>): SilgiRuntimeShareds;
|
|
208
211
|
|
package/dist/core/index.mjs
CHANGED
|
@@ -332,7 +332,6 @@ async function createSilgi(config) {
|
|
|
332
332
|
}
|
|
333
333
|
for (const routeKey in silgi.middlewares) {
|
|
334
334
|
const routeObject = silgi.middlewares[routeKey];
|
|
335
|
-
const global = routeObject.global ?? false;
|
|
336
335
|
let method = "ALL";
|
|
337
336
|
let route = routeKey;
|
|
338
337
|
if (routeKey.includes(":")) {
|
|
@@ -340,12 +339,22 @@ async function createSilgi(config) {
|
|
|
340
339
|
method = methodPart.toUpperCase();
|
|
341
340
|
route = routeParts.join(":");
|
|
342
341
|
}
|
|
343
|
-
if (global) {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
342
|
+
if (routeObject.global) {
|
|
343
|
+
if (routeObject.method) {
|
|
344
|
+
for (const method2 of routeObject.method) {
|
|
345
|
+
silgi.globalMiddlewares.push({
|
|
346
|
+
middleware: routeObject.setup,
|
|
347
|
+
method: method2,
|
|
348
|
+
route
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
} else {
|
|
352
|
+
silgi.globalMiddlewares.push({
|
|
353
|
+
middleware: routeObject.setup,
|
|
354
|
+
method,
|
|
355
|
+
route
|
|
356
|
+
});
|
|
357
|
+
}
|
|
349
358
|
} else {
|
|
350
359
|
addRoute(silgi._middlewareRouter, method, route, {
|
|
351
360
|
middleware: routeObject.setup,
|
|
@@ -1031,7 +1040,7 @@ function createSchema(params) {
|
|
|
1031
1040
|
const { path, method, setup } = params;
|
|
1032
1041
|
const result = {};
|
|
1033
1042
|
if (!method) {
|
|
1034
|
-
throw new Error(
|
|
1043
|
+
throw new Error(`Method is required createSchema ${path}`);
|
|
1035
1044
|
}
|
|
1036
1045
|
for (let i = 0; i < method.length; i++) {
|
|
1037
1046
|
const methodName = method[i];
|
|
@@ -1072,6 +1081,7 @@ function createService(params) {
|
|
|
1072
1081
|
[path]: setup
|
|
1073
1082
|
};
|
|
1074
1083
|
}
|
|
1084
|
+
|
|
1075
1085
|
function createMiddleware(params) {
|
|
1076
1086
|
if (params.global) {
|
|
1077
1087
|
const globalKey = params.global;
|
package/dist/types/index.d.mts
CHANGED
|
@@ -395,25 +395,6 @@ interface SilgiURL {
|
|
|
395
395
|
pathParams?: Record<string, string | undefined>;
|
|
396
396
|
queryParams?: Record<string, string>;
|
|
397
397
|
}
|
|
398
|
-
interface RouteRules extends Record<string, unknown> {
|
|
399
|
-
}
|
|
400
|
-
type MiddlewareHandler<Response extends EventHandlerResponse = EventHandlerResponse> = (event: SilgiEvent, silgi: Silgi) => Response;
|
|
401
|
-
/**
|
|
402
|
-
* Middleware Setup tipi
|
|
403
|
-
*/
|
|
404
|
-
interface MiddlewareSetup {
|
|
405
|
-
handler: MiddlewareHandler;
|
|
406
|
-
rules?: RouteRules;
|
|
407
|
-
modules?: Partial<SetupModuleOption>;
|
|
408
|
-
storage?: StorageConfig;
|
|
409
|
-
}
|
|
410
|
-
interface ResolvedMiddlewareDefinition {
|
|
411
|
-
[methodAndPath: string]: {
|
|
412
|
-
setup: MiddlewareSetup;
|
|
413
|
-
global?: string | undefined;
|
|
414
|
-
method: HTTPMethod | false;
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
398
|
|
|
418
399
|
interface SilgiCLI {
|
|
419
400
|
_ignore?: Ignore;
|
|
@@ -612,6 +593,26 @@ interface SilgiModule<TOptions extends ModuleOptionsCustom = ModuleOptionsCustom
|
|
|
612
593
|
getMeta?: () => Promise<ModuleMeta>;
|
|
613
594
|
}
|
|
614
595
|
|
|
596
|
+
interface RouteRules extends Record<string, unknown> {
|
|
597
|
+
}
|
|
598
|
+
type MiddlewareHandler<Response extends EventHandlerResponse = EventHandlerResponse> = (event: SilgiEvent, silgi: Silgi) => Response;
|
|
599
|
+
/**
|
|
600
|
+
* Middleware Setup tipi
|
|
601
|
+
*/
|
|
602
|
+
interface MiddlewareSetup {
|
|
603
|
+
handler: MiddlewareHandler;
|
|
604
|
+
rules?: RouteRules;
|
|
605
|
+
modules?: Partial<SetupModuleOption>;
|
|
606
|
+
storage?: StorageConfig;
|
|
607
|
+
}
|
|
608
|
+
interface ResolvedMiddlewareDefinition {
|
|
609
|
+
[methodAndPath: string]: {
|
|
610
|
+
setup: MiddlewareSetup;
|
|
611
|
+
global?: string | undefined;
|
|
612
|
+
method?: HTTPMethod[];
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
|
|
615
616
|
type TrimAfterFourSlashes<T extends string> = T extends `/${infer S1}/${infer S2}/${infer S3}/${infer S4}/${infer _}` ? `/${S1}/${S2}/${S3}/${S4}` : T;
|
|
616
617
|
type AllPaths = SilgiRouterTypes extends {
|
|
617
618
|
keys: infer U;
|