silgi 0.38.5 → 0.38.6
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 +5 -4
- package/dist/core/index.mjs +41 -42
- package/dist/types/index.d.mts +11 -12
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
package/dist/core/index.d.mts
CHANGED
|
@@ -243,7 +243,7 @@ declare function createService<Schema extends SilgiSchema, Path extends keyof Sc
|
|
|
243
243
|
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}`;
|
|
244
244
|
type MiddlewareParams<Schema extends SilgiSchema, Path extends keyof Schema & string, S extends string = WildcardVariants<Path>, Service extends MiddlewareDefinition = MiddlewareDefinition, Method extends string = HttpMethod, UsedMethod extends readonly Method[] = readonly never[]> = ({
|
|
245
245
|
path: S;
|
|
246
|
-
method
|
|
246
|
+
method: UsedMethod;
|
|
247
247
|
setup: Service;
|
|
248
248
|
}) | ({
|
|
249
249
|
global: true;
|
|
@@ -255,9 +255,10 @@ type MiddlewareReturn<S extends string, Service extends MiddlewareDefinition, Us
|
|
|
255
255
|
[K in S]: {
|
|
256
256
|
method: boolean;
|
|
257
257
|
global: boolean;
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
258
|
+
methods: UsedMethod extends readonly [] | undefined ? object : {
|
|
259
|
+
[M in UsedMethod[number]]: Service;
|
|
260
|
+
};
|
|
261
|
+
};
|
|
261
262
|
};
|
|
262
263
|
declare function createMiddleware<Schema extends SilgiSchema, Path extends keyof Schema & string, S extends string = WildcardVariants<Path>, Service extends MiddlewareDefinition = MiddlewareDefinition, Method extends string = HttpMethod, UsedMethod extends readonly Method[] = readonly never[]>(params: MiddlewareParams<Schema, Path, S, Service, Method, UsedMethod>): MiddlewareReturn<S, Service, UsedMethod>;
|
|
263
264
|
|
package/dist/core/index.mjs
CHANGED
|
@@ -322,37 +322,40 @@ async function createSilgi(config) {
|
|
|
322
322
|
}
|
|
323
323
|
for (const route in silgi.middlewares) {
|
|
324
324
|
const routeObject = silgi.middlewares[route];
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
silgi.globalMiddlewares.push({
|
|
330
|
-
setup: routeObject.setup,
|
|
331
|
-
route
|
|
332
|
-
});
|
|
333
|
-
} else if (method) {
|
|
334
|
-
for (const methodKey in routeObject) {
|
|
335
|
-
if (["global", "setup", "method"].includes(methodKey))
|
|
336
|
-
continue;
|
|
325
|
+
const global = routeObject.global ?? false;
|
|
326
|
+
if (global) {
|
|
327
|
+
if ("methods" in routeObject && routeObject.methods && Object.keys(routeObject.methods).length > 0) {
|
|
328
|
+
for (const methodKey in routeObject.methods) {
|
|
337
329
|
const _method = (methodKey || "").toUpperCase();
|
|
338
|
-
const object = routeObject[methodKey];
|
|
330
|
+
const object = routeObject.methods[methodKey];
|
|
331
|
+
if (!object)
|
|
332
|
+
continue;
|
|
339
333
|
silgi.globalMiddlewares.push({
|
|
340
334
|
setup: object.setup,
|
|
341
335
|
method: _method,
|
|
342
336
|
route
|
|
343
337
|
});
|
|
344
338
|
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
const _method = (method || "").toUpperCase();
|
|
349
|
-
const routeObjectMethod = routeObject[method];
|
|
350
|
-
addRoute(silgi._middlewareRouter, _method, route, {
|
|
351
|
-
setup: routeObjectMethod.setup,
|
|
352
|
-
method: _method,
|
|
339
|
+
} else {
|
|
340
|
+
silgi.globalMiddlewares.push({
|
|
341
|
+
setup: routeObject.setup,
|
|
353
342
|
route
|
|
354
343
|
});
|
|
355
344
|
}
|
|
345
|
+
} else {
|
|
346
|
+
if ("methods" in routeObject && routeObject.methods) {
|
|
347
|
+
for (const method in routeObject.methods) {
|
|
348
|
+
const _method = (method || "").toUpperCase();
|
|
349
|
+
const routeObjectMethod = routeObject.methods[method];
|
|
350
|
+
if (!routeObjectMethod)
|
|
351
|
+
continue;
|
|
352
|
+
addRoute(silgi._middlewareRouter, _method, route, {
|
|
353
|
+
setup: routeObjectMethod.setup,
|
|
354
|
+
method: _method,
|
|
355
|
+
route
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
}
|
|
356
359
|
}
|
|
357
360
|
}
|
|
358
361
|
silgi.hooks.addHooks(silgi.options.hooks);
|
|
@@ -909,7 +912,6 @@ function withDuplexIfBody(options) {
|
|
|
909
912
|
return options;
|
|
910
913
|
}
|
|
911
914
|
async function silgiFetch(_request, options, context) {
|
|
912
|
-
useSilgi();
|
|
913
915
|
let request;
|
|
914
916
|
if (typeof _request === "string") {
|
|
915
917
|
_request = substitutePathParams(_request, options?.pathParams);
|
|
@@ -1066,44 +1068,41 @@ function createMiddleware(params) {
|
|
|
1066
1068
|
[params.key]: {
|
|
1067
1069
|
method: false,
|
|
1068
1070
|
global: params.global,
|
|
1069
|
-
|
|
1071
|
+
methods: {}
|
|
1070
1072
|
}
|
|
1071
1073
|
};
|
|
1072
1074
|
}
|
|
1073
|
-
const
|
|
1074
|
-
[params.key]: {
|
|
1075
|
-
global: params.global,
|
|
1076
|
-
method: true
|
|
1077
|
-
}
|
|
1078
|
-
};
|
|
1075
|
+
const methods2 = {};
|
|
1079
1076
|
for (const m of params.method) {
|
|
1080
|
-
|
|
1077
|
+
methods2[m] = {
|
|
1081
1078
|
setup: params.setup,
|
|
1082
1079
|
global: true,
|
|
1083
1080
|
method: m
|
|
1084
1081
|
};
|
|
1085
1082
|
}
|
|
1086
|
-
return result2;
|
|
1087
|
-
}
|
|
1088
|
-
if (!params.method || params.method.length === 0) {
|
|
1089
1083
|
return {
|
|
1090
|
-
[params.
|
|
1084
|
+
[params.key]: {
|
|
1085
|
+
global: params.global,
|
|
1091
1086
|
method: true,
|
|
1092
|
-
|
|
1093
|
-
setup: params.setup
|
|
1087
|
+
methods: methods2
|
|
1094
1088
|
}
|
|
1095
1089
|
};
|
|
1096
1090
|
}
|
|
1097
|
-
const
|
|
1098
|
-
[params.path]: {}
|
|
1099
|
-
};
|
|
1091
|
+
const methods = {};
|
|
1100
1092
|
for (const m of params.method) {
|
|
1101
|
-
|
|
1093
|
+
methods[m] = {
|
|
1102
1094
|
setup: params.setup,
|
|
1103
|
-
method: m
|
|
1095
|
+
method: m,
|
|
1096
|
+
global: false
|
|
1104
1097
|
};
|
|
1105
1098
|
}
|
|
1106
|
-
return
|
|
1099
|
+
return {
|
|
1100
|
+
[params.path]: {
|
|
1101
|
+
method: true,
|
|
1102
|
+
global: false,
|
|
1103
|
+
methods
|
|
1104
|
+
}
|
|
1105
|
+
};
|
|
1107
1106
|
}
|
|
1108
1107
|
|
|
1109
1108
|
function createShared(shared) {
|
package/dist/types/index.d.mts
CHANGED
|
@@ -399,23 +399,22 @@ interface MiddlewareSetup {
|
|
|
399
399
|
storage?: StorageConfig;
|
|
400
400
|
}
|
|
401
401
|
type MiddlewareDefinition = MiddlewareSetup;
|
|
402
|
-
|
|
402
|
+
interface ResolvedMiddlewareDefinition {
|
|
403
403
|
[routePath: string]: {
|
|
404
|
-
global:
|
|
404
|
+
global: true;
|
|
405
405
|
method: false;
|
|
406
406
|
setup: MiddlewareSetup;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
method: boolean;
|
|
407
|
+
} | {
|
|
408
|
+
global: false;
|
|
409
|
+
method: true;
|
|
410
|
+
methods: {
|
|
411
|
+
[method: string]: {
|
|
412
|
+
setup: MiddlewareSetup;
|
|
413
|
+
method: string;
|
|
414
|
+
};
|
|
416
415
|
};
|
|
417
416
|
};
|
|
418
|
-
}
|
|
417
|
+
}
|
|
419
418
|
|
|
420
419
|
interface SilgiCLI {
|
|
421
420
|
_ignore?: Ignore;
|