silgi 0.41.28 → 0.41.29
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.mjs +64 -3
- package/dist/types/index.d.mts +2 -0
- package/package.json +1 -1
package/dist/cli/index.mjs
CHANGED
package/dist/core/index.mjs
CHANGED
|
@@ -312,9 +312,20 @@ async function createSilgi(config) {
|
|
|
312
312
|
}
|
|
313
313
|
}
|
|
314
314
|
let routeWithParams = path;
|
|
315
|
+
let pathParamNames = {};
|
|
316
|
+
let queryParamNames = {};
|
|
315
317
|
if (object.pathParams) {
|
|
316
318
|
const jsonSchema = await toJsonSchema(object.pathParams);
|
|
317
319
|
if (jsonSchema && jsonSchema.properties) {
|
|
320
|
+
pathParamNames = Object.keys(jsonSchema.properties).reduce((acc, key) => {
|
|
321
|
+
const prop = jsonSchema.properties?.[key];
|
|
322
|
+
if (typeof prop === "object" && prop !== null && "type" in prop) {
|
|
323
|
+
acc[key] = prop.type ?? "string";
|
|
324
|
+
} else {
|
|
325
|
+
acc[key] = "string";
|
|
326
|
+
}
|
|
327
|
+
return acc;
|
|
328
|
+
}, {});
|
|
318
329
|
const paramNames = Object.keys(jsonSchema.properties);
|
|
319
330
|
if (paramNames.length > 0) {
|
|
320
331
|
const routeParts2 = routeWithParams.split("/");
|
|
@@ -329,22 +340,42 @@ async function createSilgi(config) {
|
|
|
329
340
|
}
|
|
330
341
|
}
|
|
331
342
|
}
|
|
343
|
+
if (object.queryParams) {
|
|
344
|
+
const jsonSchema = await toJsonSchema(object.queryParams);
|
|
345
|
+
if (jsonSchema && jsonSchema.properties) {
|
|
346
|
+
queryParamNames = Object.keys(jsonSchema.properties).reduce((acc, key) => {
|
|
347
|
+
const prop = jsonSchema.properties?.[key];
|
|
348
|
+
if (typeof prop === "object" && prop !== null && "type" in prop) {
|
|
349
|
+
acc[key] = prop.type ?? "string";
|
|
350
|
+
} else {
|
|
351
|
+
acc[key] = "string";
|
|
352
|
+
}
|
|
353
|
+
return acc;
|
|
354
|
+
}, {});
|
|
355
|
+
}
|
|
356
|
+
}
|
|
332
357
|
if (object.apiType === "rest-graphql") {
|
|
333
358
|
addRoute(silgi.router, "", routeWithParams, {
|
|
334
359
|
method: "",
|
|
335
360
|
route: routeWithParams,
|
|
336
|
-
service: object
|
|
361
|
+
service: object,
|
|
362
|
+
queryParams: queryParamNames,
|
|
363
|
+
pathParams: pathParamNames
|
|
337
364
|
});
|
|
338
365
|
addRoute(silgi.router, method, routeWithParams, {
|
|
339
366
|
method,
|
|
340
367
|
route: routeWithParams,
|
|
341
|
-
service: object
|
|
368
|
+
service: object,
|
|
369
|
+
queryParams: queryParamNames,
|
|
370
|
+
pathParams: pathParamNames
|
|
342
371
|
});
|
|
343
372
|
} else {
|
|
344
373
|
addRoute(silgi.router, method, routeWithParams, {
|
|
345
374
|
method,
|
|
346
375
|
route: routeWithParams,
|
|
347
|
-
service: object
|
|
376
|
+
service: object,
|
|
377
|
+
queryParams: queryParamNames,
|
|
378
|
+
pathParams: pathParamNames
|
|
348
379
|
});
|
|
349
380
|
}
|
|
350
381
|
}
|
|
@@ -1036,6 +1067,36 @@ async function handler(event, url, input) {
|
|
|
1036
1067
|
if (silgiCtx.router) {
|
|
1037
1068
|
const match = findRoute(silgiCtx.router, url.method, pathname);
|
|
1038
1069
|
if (match) {
|
|
1070
|
+
if (url.method === "" && input) {
|
|
1071
|
+
if (input?.path) {
|
|
1072
|
+
const expectedPathKeys = Object.keys(match.data.pathParams ?? {});
|
|
1073
|
+
const inputPathKeys = Object.keys(input.path);
|
|
1074
|
+
for (const key of inputPathKeys) {
|
|
1075
|
+
if (!expectedPathKeys.includes(key)) {
|
|
1076
|
+
throw createError({
|
|
1077
|
+
message: `Unexpected path param key: ${key}`,
|
|
1078
|
+
statusCode: 400,
|
|
1079
|
+
statusMessage: "Invalid path parameter"
|
|
1080
|
+
});
|
|
1081
|
+
}
|
|
1082
|
+
}
|
|
1083
|
+
match.data.pathParams = input.path;
|
|
1084
|
+
}
|
|
1085
|
+
if (input?.query) {
|
|
1086
|
+
const expectedQueryKeys = Object.keys(match.data.queryParams ?? {});
|
|
1087
|
+
const inputQueryKeys = Object.keys(input.query);
|
|
1088
|
+
for (const key of inputQueryKeys) {
|
|
1089
|
+
if (!expectedQueryKeys.includes(key)) {
|
|
1090
|
+
throw createError({
|
|
1091
|
+
message: `Unexpected query param key: ${key}`,
|
|
1092
|
+
statusCode: 400,
|
|
1093
|
+
statusMessage: "Invalid query parameter"
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
match.data.queryParams = input.query;
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1039
1100
|
if (_chain) {
|
|
1040
1101
|
return _chain.then(async (_previous) => {
|
|
1041
1102
|
if (_previous !== void 0 && _previous !== kNotFound) {
|
package/dist/types/index.d.mts
CHANGED
|
@@ -709,6 +709,8 @@ interface SilgiRoute {
|
|
|
709
709
|
method?: HTTPMethod;
|
|
710
710
|
service?: ResolvedServiceDefinition[keyof ResolvedServiceDefinition];
|
|
711
711
|
middleware?: MiddlewareSetup;
|
|
712
|
+
queryParams?: Record<string, string>;
|
|
713
|
+
pathParams?: Record<string, string>;
|
|
712
714
|
}
|
|
713
715
|
interface Silgi {
|
|
714
716
|
router: RouterContext<SilgiRoute>;
|