silgi 0.40.1 → 0.41.0
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 +17 -14
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/loader.mjs +7 -4
- package/dist/core/index.d.mts +30 -18
- package/dist/core/index.mjs +45 -46
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +1 -1
- package/dist/kit/index.mjs +4 -1
- package/dist/types/index.d.mts +148 -152
- package/package.json +1 -1
package/dist/cli/build.mjs
CHANGED
|
@@ -581,7 +581,7 @@ function resolveGroupSyntax(group) {
|
|
|
581
581
|
return groups;
|
|
582
582
|
}
|
|
583
583
|
|
|
584
|
-
const DEFAULT_FUNCTION_EXPORT_NAMES = ["createSchema", "createService", "
|
|
584
|
+
const DEFAULT_FUNCTION_EXPORT_NAMES = ["createSchema", "createService", "createResolver", "createShared", "createMiddleware"];
|
|
585
585
|
const DEFAULT_INTERFACE_EXTENDS_NAMES = ["ExtendShared", "ExtendContext"];
|
|
586
586
|
function generateUniqueIdentifier(filePath, exportName) {
|
|
587
587
|
const fileBaseName = basename(filePath);
|
|
@@ -592,7 +592,7 @@ function categorizeExports(exportedEntities, filePath, functionExportCategories
|
|
|
592
592
|
createService: "service",
|
|
593
593
|
createSchema: "schema",
|
|
594
594
|
createShared: "shared",
|
|
595
|
-
|
|
595
|
+
createResolver: "resolver",
|
|
596
596
|
createMiddleware: "middleware"
|
|
597
597
|
}, interfaceExportCategories = {
|
|
598
598
|
ExtendShared: "shared",
|
|
@@ -659,8 +659,8 @@ function registerExportsWithHooks(silgiInstance, runtimeExports, typeExports, pa
|
|
|
659
659
|
case "schema":
|
|
660
660
|
options.schemas.push(uniqueId);
|
|
661
661
|
break;
|
|
662
|
-
case "
|
|
663
|
-
options.
|
|
662
|
+
case "resolvers":
|
|
663
|
+
options.resolvers.push(uniqueId);
|
|
664
664
|
break;
|
|
665
665
|
case "middleware":
|
|
666
666
|
options.middlewares?.push?.(uniqueId);
|
|
@@ -763,8 +763,8 @@ async function scanSilgiExports(path, packageName, silgiInstance = useSilgiCLI()
|
|
|
763
763
|
functionExportCategories[name] = "schema";
|
|
764
764
|
else if (name === "createShared")
|
|
765
765
|
functionExportCategories[name] = "shared";
|
|
766
|
-
else if (name === "
|
|
767
|
-
functionExportCategories[name] = "
|
|
766
|
+
else if (name === "createResolver")
|
|
767
|
+
functionExportCategories[name] = "resolver";
|
|
768
768
|
else if (name === "createMiddleware")
|
|
769
769
|
functionExportCategories[name] = "middleware";
|
|
770
770
|
else functionExportCategories[name] = name;
|
|
@@ -1196,7 +1196,7 @@ async function prepareScanFile(silgi) {
|
|
|
1196
1196
|
const scanned = {
|
|
1197
1197
|
services: [],
|
|
1198
1198
|
shareds: [],
|
|
1199
|
-
|
|
1199
|
+
resolvers: [],
|
|
1200
1200
|
schemas: [],
|
|
1201
1201
|
middlewares: [],
|
|
1202
1202
|
addImportItem,
|
|
@@ -1233,7 +1233,7 @@ async function prepareScanFile(silgi) {
|
|
|
1233
1233
|
...generateExport("schemas", scanned.schemas),
|
|
1234
1234
|
...generateExport("services", scanned.services),
|
|
1235
1235
|
...generateExport("shareds", scanned.shareds, "undefined"),
|
|
1236
|
-
...generateExport("
|
|
1236
|
+
...generateExport("resolvers", scanned.resolvers, "[]"),
|
|
1237
1237
|
...generateExport("middlewares", scanned.middlewares)
|
|
1238
1238
|
];
|
|
1239
1239
|
await silgi.callHook("after:scan.ts", importData);
|
|
@@ -1276,7 +1276,7 @@ async function readScanFile(silgi) {
|
|
|
1276
1276
|
silgi.schemas = scanFile.schemas || {};
|
|
1277
1277
|
silgi.services = scanFile.services || {};
|
|
1278
1278
|
silgi.shareds = scanFile.shareds || {};
|
|
1279
|
-
silgi.
|
|
1279
|
+
silgi.resolvers = scanFile.resolvers || {};
|
|
1280
1280
|
return {
|
|
1281
1281
|
context,
|
|
1282
1282
|
object: {
|
|
@@ -1488,7 +1488,7 @@ async function createSilgiCLI(config = {}, opts = {}) {
|
|
|
1488
1488
|
middleware: [],
|
|
1489
1489
|
shareds: {},
|
|
1490
1490
|
schemas: {},
|
|
1491
|
-
|
|
1491
|
+
resolvers: [],
|
|
1492
1492
|
unimport: void 0,
|
|
1493
1493
|
options,
|
|
1494
1494
|
hooks,
|
|
@@ -1702,7 +1702,7 @@ async function prepareCoreFile(silgi) {
|
|
|
1702
1702
|
name: "middlewares"
|
|
1703
1703
|
},
|
|
1704
1704
|
{
|
|
1705
|
-
name: "
|
|
1705
|
+
name: "resolvers"
|
|
1706
1706
|
}
|
|
1707
1707
|
]
|
|
1708
1708
|
},
|
|
@@ -1794,7 +1794,7 @@ async function prepareCoreFile(silgi) {
|
|
|
1794
1794
|
" services: services,",
|
|
1795
1795
|
" middlewares: middlewares,",
|
|
1796
1796
|
" schemas: schemas,",
|
|
1797
|
-
"
|
|
1797
|
+
" resolvers: resolvers,",
|
|
1798
1798
|
` plugins: [${plugins.join(", ")}],`,
|
|
1799
1799
|
"",
|
|
1800
1800
|
_data.silgiConfigs.length > 0 ? _data.silgiConfigs.map((item) => {
|
|
@@ -1870,6 +1870,7 @@ async function prepareSchema(silgi) {
|
|
|
1870
1870
|
contexts: [],
|
|
1871
1871
|
setupModuleOption: [],
|
|
1872
1872
|
shareds: [],
|
|
1873
|
+
resolvers: [],
|
|
1873
1874
|
events: [],
|
|
1874
1875
|
hooks: [],
|
|
1875
1876
|
runtimeHooks: [],
|
|
@@ -1894,7 +1895,8 @@ async function prepareSchema(silgi) {
|
|
|
1894
1895
|
"",
|
|
1895
1896
|
`type SchemaExtends = typeof import('${silgiScanTS}')['schemas']`,
|
|
1896
1897
|
`type BaseServices = typeof import('${silgiScanTS}')['services']`,
|
|
1897
|
-
`type
|
|
1898
|
+
`type ResolversExtend = ${data.resolvers?.length ? data.resolvers.map(({ value }) => `${value}`).join(" & ") : "{}"}`,
|
|
1899
|
+
"",
|
|
1898
1900
|
"",
|
|
1899
1901
|
`type SilgiModuleContextExtends = ${data.contexts.length ? data.contexts.map(({ value }) => value).join(" & ") : "{}"}`,
|
|
1900
1902
|
"",
|
|
@@ -1977,8 +1979,9 @@ async function prepareSchema(silgi) {
|
|
|
1977
1979
|
SilgiRuntimeConfig: [{}, { extends: ["SilgiRuntimeConfigExtends"] }],
|
|
1978
1980
|
SilgiHooks: [{}, { extends: ["ModuleHooksExtend"] }],
|
|
1979
1981
|
SilgiRuntimeMethods: [{}, { extends: ["RuntimeMethodExtends"] }],
|
|
1980
|
-
|
|
1982
|
+
Resolvers: [{}, { extends: ["ResolversExtend"] }],
|
|
1981
1983
|
SilgiModuleOptions: [{}, { extends: ["SilgiModuleOptionExtend"] }],
|
|
1984
|
+
// TODO: bunu kontrol et.
|
|
1982
1985
|
RouteRules: [{}, { extends: ["RouteRulesExtend"] }],
|
|
1983
1986
|
MetaData: [{}, { extends: ["MetaDataExtend"] }]
|
|
1984
1987
|
}).replace(/,\s*/g, "\n"),
|
package/dist/cli/index.mjs
CHANGED
package/dist/cli/loader.mjs
CHANGED
|
@@ -351,10 +351,13 @@ async function resolvePathOptions(options) {
|
|
|
351
351
|
}
|
|
352
352
|
options.alias = {
|
|
353
353
|
...options.alias,
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
354
|
+
// '~/': join(options.srcDir, '/'),
|
|
355
|
+
// '@/': join(options.srcDir, '/'),
|
|
356
|
+
// '~~/': join(options.rootDir, '/'),
|
|
357
|
+
// '@@/': join(options.rootDir, '/'),
|
|
358
|
+
"#server/*": join(options.silgi.serverDir, "/*"),
|
|
359
|
+
"#silgi/*": join(options.build.dir, "/*"),
|
|
360
|
+
"#types/*": join(options.build.typesDir, "/*")
|
|
358
361
|
};
|
|
359
362
|
if (options.preset === "npm-package") {
|
|
360
363
|
options.alias = {
|
package/dist/core/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { SilgiConfig, Silgi, SilgiEvent, SilgiSchema, RouteEntry, CustomRequestInit, SilgiRuntimeContext,
|
|
1
|
+
import { SilgiConfig, Silgi, SilgiEvent, SilgiSchema, RouteEntry, CustomRequestInit, SilgiRuntimeContext, BaseMethodSchema, MergeAll, HTTPMethod, ServiceSetup, ServicesObject, HttpMethod, MiddlewareSetup, SilgiRuntimeShareds, Resolvers, SilgiURL, StorageConfig, SilgiCLI, SilgiStorageBase, SilgiRuntimeConfig } from 'silgi/types';
|
|
2
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
3
|
import { Storage, StorageValue } from 'unstorage';
|
|
3
4
|
import { UseContext } from 'unctx';
|
|
4
5
|
|
|
@@ -138,15 +139,11 @@ declare function getEventContext<T extends SilgiRuntimeContext>(event?: SilgiEve
|
|
|
138
139
|
* }
|
|
139
140
|
* });
|
|
140
141
|
*/
|
|
141
|
-
declare function createSchema<
|
|
142
|
-
|
|
143
|
-
path: Path;
|
|
144
|
-
/** HTTP method(s) this schema applies to (optional) */
|
|
145
|
-
method?: UsedMethod;
|
|
146
|
-
/** Schema definition */
|
|
142
|
+
declare function createSchema<Key extends string, Schema extends BaseMethodSchema>(params: {
|
|
143
|
+
key: Key;
|
|
147
144
|
setup: Schema;
|
|
148
145
|
}): {
|
|
149
|
-
[K in
|
|
146
|
+
[K in Key]: Schema;
|
|
150
147
|
};
|
|
151
148
|
|
|
152
149
|
/**
|
|
@@ -162,16 +159,33 @@ declare function deepMergeObjects<T extends readonly Record<string, any>[]>(sche
|
|
|
162
159
|
* ServiceSetup tipinden oluşan bir yardımcı fonksiyon.
|
|
163
160
|
* Tip güvenliğini artırmak için ServiceSetup objesini doğrudan döndürür.
|
|
164
161
|
*/
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
162
|
+
type SlashCount<S extends string, Count extends any[] = []> = S extends `${infer _Prefix}/${infer Rest}` ? SlashCount<Rest, [any, ...Count]> : Count['length'];
|
|
163
|
+
type Max4Slashes<S extends string> = SlashCount<S> extends 0 | 1 | 2 | 3 | 4 ? S : never;
|
|
164
|
+
declare function createService<Path extends string = string, Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | never | undefined = never, QueryParams extends StandardSchemaV1 | never | undefined = never, Resolved extends boolean = false, HiddenParameters extends boolean = false>(params: {
|
|
165
|
+
path: Max4Slashes<Path>;
|
|
166
|
+
methods: HTTPMethod[];
|
|
167
|
+
input?: Input;
|
|
168
|
+
output?: Output;
|
|
169
|
+
queryParams?: {
|
|
170
|
+
path?: PathParams;
|
|
171
|
+
query?: QueryParams;
|
|
172
|
+
};
|
|
173
|
+
setup: ServiceSetup<Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
169
174
|
}): {
|
|
170
|
-
[K in Path]:
|
|
175
|
+
[K in Path]: {
|
|
176
|
+
setup: ServiceSetup<Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
177
|
+
methods: HTTPMethod[];
|
|
178
|
+
input?: Input;
|
|
179
|
+
output?: Output;
|
|
180
|
+
queryParams?: {
|
|
181
|
+
path?: PathParams;
|
|
182
|
+
query?: QueryParams;
|
|
183
|
+
};
|
|
184
|
+
};
|
|
171
185
|
};
|
|
172
186
|
|
|
173
187
|
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}`;
|
|
174
|
-
declare function createMiddleware<S extends WildcardVariants<keyof
|
|
188
|
+
declare function createMiddleware<S extends WildcardVariants<keyof ServicesObject>, Method extends HttpMethod, UsedMethod extends readonly Method[]>(params: {
|
|
175
189
|
path: S;
|
|
176
190
|
method: UsedMethod;
|
|
177
191
|
setup: MiddlewareSetup;
|
|
@@ -215,9 +229,7 @@ declare function createShared(shared: Partial<SilgiRuntimeShareds>): SilgiRuntim
|
|
|
215
229
|
*/
|
|
216
230
|
declare function replaceRuntimeValues(obj: any, runtime: any): any;
|
|
217
231
|
|
|
218
|
-
declare function
|
|
219
|
-
[K in URL]: RouterConfig<URL>;
|
|
220
|
-
};
|
|
232
|
+
declare function createResolver(resolver: Resolvers): Resolvers;
|
|
221
233
|
declare function getUrlPrefix(path: string, method?: string): SilgiURL;
|
|
222
234
|
|
|
223
235
|
declare function createStorage(silgi: Silgi): Promise<Storage<StorageValue>>;
|
|
@@ -259,4 +271,4 @@ declare function useRuntime(): SilgiRuntimeConfig;
|
|
|
259
271
|
|
|
260
272
|
declare const autoImportTypes: string[];
|
|
261
273
|
|
|
262
|
-
export { SilgiError, autoImportTypes, createError, createMiddleware,
|
|
274
|
+
export { SilgiError, autoImportTypes, createError, createMiddleware, createResolver, createSchema, createService, createShared, createSilgi, createStorage, deepMergeObjects, getEvent, getEventContext, getUrlPrefix, handleResponse, handler, isError, middleware, replaceRuntimeValues, silgiCLICtx, silgiCtx, silgiFetch, storageMount, tryUseSilgi, tryUseSilgiCLI, updateRuntimeStorage, useRuntime, useSilgi, useSilgiCLI, useSilgiStorage };
|
package/dist/core/index.mjs
CHANGED
|
@@ -270,7 +270,7 @@ async function createSilgi(config) {
|
|
|
270
270
|
routerPrefixs: [],
|
|
271
271
|
schemas: config.schemas ?? {},
|
|
272
272
|
services: config.services ?? {},
|
|
273
|
-
|
|
273
|
+
resolvers: config.resolvers ?? [],
|
|
274
274
|
middlewares: config.middlewares ?? {},
|
|
275
275
|
globalMiddlewares: config.globalMiddlewares ?? [],
|
|
276
276
|
shared: config.shared ?? {},
|
|
@@ -298,11 +298,14 @@ async function createSilgi(config) {
|
|
|
298
298
|
silgi.router = createRouter();
|
|
299
299
|
}
|
|
300
300
|
for (const routeKey in silgi.services) {
|
|
301
|
-
let method = "
|
|
301
|
+
let method = "";
|
|
302
302
|
let route = routeKey;
|
|
303
303
|
if (routeKey.includes(":")) {
|
|
304
304
|
const [methodPart, ...routeParts2] = routeKey.split(":");
|
|
305
305
|
method = methodPart.toUpperCase();
|
|
306
|
+
if (method === "GLOBAL") {
|
|
307
|
+
method = "";
|
|
308
|
+
}
|
|
306
309
|
route = routeParts2.join(":");
|
|
307
310
|
}
|
|
308
311
|
const routeParts = route.split("/").filter(Boolean);
|
|
@@ -314,16 +317,10 @@ async function createSilgi(config) {
|
|
|
314
317
|
}
|
|
315
318
|
const methodObject = silgi.services[routeKey];
|
|
316
319
|
if (methodObject) {
|
|
317
|
-
const schemaWrapper = silgi.schemas?.[routeKey];
|
|
318
|
-
if (!schemaWrapper) {
|
|
319
|
-
silgi.logger.warn(`Schema not found for ${routeKey}`);
|
|
320
|
-
continue;
|
|
321
|
-
}
|
|
322
320
|
addRoute(silgi.router, method, route, {
|
|
323
321
|
method,
|
|
324
322
|
route,
|
|
325
|
-
service: methodObject
|
|
326
|
-
schema: schemaWrapper
|
|
323
|
+
service: methodObject
|
|
327
324
|
});
|
|
328
325
|
}
|
|
329
326
|
}
|
|
@@ -332,11 +329,14 @@ async function createSilgi(config) {
|
|
|
332
329
|
}
|
|
333
330
|
for (const routeKey in silgi.middlewares) {
|
|
334
331
|
const routeObject = silgi.middlewares[routeKey];
|
|
335
|
-
let method = "
|
|
332
|
+
let method = "";
|
|
336
333
|
let route = routeKey;
|
|
337
334
|
if (routeKey.includes(":")) {
|
|
338
335
|
const [methodPart, ...routeParts] = routeKey.split(":");
|
|
339
336
|
method = methodPart.toUpperCase();
|
|
337
|
+
if (method === "GLOBAL") {
|
|
338
|
+
method = "";
|
|
339
|
+
}
|
|
340
340
|
route = routeParts.join(":");
|
|
341
341
|
}
|
|
342
342
|
if (routeObject.global) {
|
|
@@ -561,12 +561,8 @@ function getRouterParams(event, opts = {}) {
|
|
|
561
561
|
return params;
|
|
562
562
|
}
|
|
563
563
|
|
|
564
|
-
function
|
|
565
|
-
return
|
|
566
|
-
[params.route]: {
|
|
567
|
-
...params
|
|
568
|
-
}
|
|
569
|
-
};
|
|
564
|
+
function createResolver(resolver) {
|
|
565
|
+
return resolver;
|
|
570
566
|
}
|
|
571
567
|
function getUrlPrefix(path, method) {
|
|
572
568
|
const parse = path.includes("://") ? new FastURL(path) : new URL(path, "http://localhost");
|
|
@@ -593,7 +589,7 @@ function getUrlPrefix(path, method) {
|
|
|
593
589
|
async function orchestrate(route, event, _input, graphql) {
|
|
594
590
|
const silgiCtx = useSilgi();
|
|
595
591
|
const silgiURL = getUrlPrefix(route.route || event.req.url, route.method);
|
|
596
|
-
const input = _input || (route.service?.rules?.readBeforeBody === false || graphql ? {} : await parseRequestInput(event.req));
|
|
592
|
+
const input = _input || (route.service?.setup.rules?.readBeforeBody === false || graphql ? {} : await parseRequestInput(event.req));
|
|
597
593
|
const hookContext = { earlyReturnValue: false };
|
|
598
594
|
const routerParams = _input ? input.path : getRouterParams(event);
|
|
599
595
|
const queryParams = _input ? input.query : getQuery(event);
|
|
@@ -611,8 +607,7 @@ async function orchestrate(route, event, _input, graphql) {
|
|
|
611
607
|
}
|
|
612
608
|
};
|
|
613
609
|
try {
|
|
614
|
-
|
|
615
|
-
if (!setup) {
|
|
610
|
+
if (!route.service) {
|
|
616
611
|
throw createError({
|
|
617
612
|
statusCode: 404,
|
|
618
613
|
statusMessage: "Service not found"
|
|
@@ -647,11 +642,10 @@ async function orchestrate(route, event, _input, graphql) {
|
|
|
647
642
|
}
|
|
648
643
|
silgiCtx.shared.$fetch = silgiFetch;
|
|
649
644
|
silgiCtx.shared.silgi = silgiCtx;
|
|
650
|
-
const result = await setup
|
|
645
|
+
const result = await route.service?.setup.handler(
|
|
651
646
|
inputData,
|
|
652
647
|
silgiCtx.shared,
|
|
653
|
-
event
|
|
654
|
-
event.context.source
|
|
648
|
+
event
|
|
655
649
|
);
|
|
656
650
|
await silgiCtx.callHook("fetch:after", {
|
|
657
651
|
event,
|
|
@@ -662,12 +656,12 @@ async function orchestrate(route, event, _input, graphql) {
|
|
|
662
656
|
route,
|
|
663
657
|
hookContext
|
|
664
658
|
});
|
|
665
|
-
if (setup.storage && cacheData?.cachedKey) {
|
|
666
|
-
await useSilgiStorage(setup.storage.base).setItem(
|
|
659
|
+
if (route.service.setup.storage && cacheData?.cachedKey) {
|
|
660
|
+
await useSilgiStorage(route.service.setup.storage.base).setItem(
|
|
667
661
|
cacheData.cachedKey,
|
|
668
662
|
result,
|
|
669
663
|
// Cast to StorageValue if needed
|
|
670
|
-
setup.storage.options
|
|
664
|
+
route.service.setup.storage.options
|
|
671
665
|
);
|
|
672
666
|
}
|
|
673
667
|
return result;
|
|
@@ -697,18 +691,17 @@ async function orchestrate(route, event, _input, graphql) {
|
|
|
697
691
|
}
|
|
698
692
|
}
|
|
699
693
|
async function cacheExecute(input, route, silgiURL, event) {
|
|
700
|
-
|
|
701
|
-
if (!setup || !setup.storage)
|
|
694
|
+
if (!route.service || !route.service.setup.storage)
|
|
702
695
|
return;
|
|
703
|
-
const cacheKey = setup.storage ? await generateStorageKey({
|
|
696
|
+
const cacheKey = route.service.setup.storage ? await generateStorageKey({
|
|
704
697
|
url: silgiURL,
|
|
705
698
|
input,
|
|
706
|
-
keyGenerator: setup.storage.key,
|
|
707
|
-
storageOptions: setup.storage,
|
|
699
|
+
keyGenerator: route.service.setup.storage.key,
|
|
700
|
+
storageOptions: route.service.setup.storage,
|
|
708
701
|
requestId: event?.requestId
|
|
709
702
|
}) : null;
|
|
710
703
|
if (cacheKey) {
|
|
711
|
-
const cachedResult = await useSilgiStorage(setup.storage.base).getItem(cacheKey);
|
|
704
|
+
const cachedResult = await useSilgiStorage(route.service.setup.storage.base).getItem(cacheKey);
|
|
712
705
|
if (cachedResult !== null) {
|
|
713
706
|
return {
|
|
714
707
|
success: true,
|
|
@@ -1027,15 +1020,12 @@ function getEventContext(event) {
|
|
|
1027
1020
|
}
|
|
1028
1021
|
|
|
1029
1022
|
function createSchema(params) {
|
|
1030
|
-
const {
|
|
1023
|
+
const { key, setup } = params;
|
|
1031
1024
|
const result = {};
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
const methodName = method[i];
|
|
1037
|
-
result[`${String(methodName)}:${path}`] = setup;
|
|
1038
|
-
}
|
|
1025
|
+
result[key] = {
|
|
1026
|
+
setup,
|
|
1027
|
+
key
|
|
1028
|
+
};
|
|
1039
1029
|
return result;
|
|
1040
1030
|
}
|
|
1041
1031
|
|
|
@@ -1062,14 +1052,23 @@ function deepMergeObjects(schemas) {
|
|
|
1062
1052
|
return merged;
|
|
1063
1053
|
}
|
|
1064
1054
|
|
|
1065
|
-
function defineServiceSetup(path, setup) {
|
|
1066
|
-
return setup;
|
|
1067
|
-
}
|
|
1068
1055
|
function createService(params) {
|
|
1069
|
-
const
|
|
1070
|
-
|
|
1071
|
-
|
|
1056
|
+
const slashCount = (params.path.match(/\//g) || []).length;
|
|
1057
|
+
if (slashCount > 4) {
|
|
1058
|
+
throw new Error(
|
|
1059
|
+
`Path '${params.path}' is invalid: maximum 4 '/' allowed (found ${slashCount})`
|
|
1060
|
+
);
|
|
1061
|
+
}
|
|
1062
|
+
const result = {};
|
|
1063
|
+
const { path, setup, methods, input, output, queryParams } = params;
|
|
1064
|
+
result[path] = {
|
|
1065
|
+
setup,
|
|
1066
|
+
methods,
|
|
1067
|
+
input,
|
|
1068
|
+
output,
|
|
1069
|
+
queryParams
|
|
1072
1070
|
};
|
|
1071
|
+
return result;
|
|
1073
1072
|
}
|
|
1074
1073
|
|
|
1075
1074
|
function createMiddleware(params) {
|
|
@@ -1148,4 +1147,4 @@ const autoImportTypes = [
|
|
|
1148
1147
|
"ExtractQueryParamsFromURI"
|
|
1149
1148
|
];
|
|
1150
1149
|
|
|
1151
|
-
export { SilgiError, autoImportTypes, createError, createMiddleware,
|
|
1150
|
+
export { SilgiError, autoImportTypes, createError, createMiddleware, createResolver, createSchema, createService, createShared, createSilgi, createStorage, deepMergeObjects, getEvent, getEventContext, getUrlPrefix, handleResponse, handler, isError, middleware, replaceRuntimeValues, silgiCtx, silgiFetch, storageMount, tryUseSilgi, updateRuntimeStorage, useRuntime, useSilgi, useSilgiStorage };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { SilgiError, autoImportTypes, createError, createMiddleware,
|
|
1
|
+
export { SilgiError, autoImportTypes, createError, createMiddleware, createResolver, createSchema, createService, createShared, createSilgi, createStorage, deepMergeObjects, getEvent, getEventContext, getUrlPrefix, handleResponse, handler, isError, middleware, 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';
|
|
3
4
|
import 'unstorage';
|
|
4
5
|
import 'unctx';
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { SilgiError, autoImportTypes, createError, createMiddleware,
|
|
1
|
+
export { SilgiError, autoImportTypes, createError, createMiddleware, createResolver, createSchema, createService, createShared, createSilgi, createStorage, deepMergeObjects, getEvent, getEventContext, getUrlPrefix, handleResponse, handler, isError, middleware, 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/kit/index.mjs
CHANGED
|
@@ -76,11 +76,14 @@ function removeExtension(filePath, force = false) {
|
|
|
76
76
|
return filePath;
|
|
77
77
|
}
|
|
78
78
|
function getServicePath(_route) {
|
|
79
|
-
let method = "
|
|
79
|
+
let method = "";
|
|
80
80
|
let route = _route;
|
|
81
81
|
if (route.includes(":")) {
|
|
82
82
|
const [methodPart, ...routeParts] = route.split(":");
|
|
83
83
|
method = methodPart.toUpperCase();
|
|
84
|
+
if (method === "GLOBAL") {
|
|
85
|
+
method = "";
|
|
86
|
+
}
|
|
84
87
|
route = routeParts.join(":");
|
|
85
88
|
}
|
|
86
89
|
return {
|
package/dist/types/index.d.mts
CHANGED
|
@@ -94,7 +94,6 @@ interface SilgiRuntimeContext extends Record<string, any> {
|
|
|
94
94
|
matchedRoute?: SilgiRoute;
|
|
95
95
|
sessions?: Record<string, Session>;
|
|
96
96
|
clientAddress?: string;
|
|
97
|
-
source?: any;
|
|
98
97
|
silgi: {
|
|
99
98
|
runtimeConfig?: SilgiRuntimeConfig;
|
|
100
99
|
};
|
|
@@ -130,13 +129,11 @@ interface SilgiEvent extends Record<string, unknown> {
|
|
|
130
129
|
}
|
|
131
130
|
|
|
132
131
|
/**
|
|
133
|
-
*
|
|
134
|
-
* Example:
|
|
135
|
-
* {
|
|
136
|
-
* "/api/blueSpace/basket/getBook": { ... }
|
|
137
|
-
* }
|
|
132
|
+
* Route configuration interface.
|
|
138
133
|
*/
|
|
139
|
-
interface
|
|
134
|
+
interface Resolvers {
|
|
135
|
+
}
|
|
136
|
+
interface RouteRules extends Record<string, unknown> {
|
|
140
137
|
}
|
|
141
138
|
/**
|
|
142
139
|
* Extracts the prefix (first segment) from a URL, including the leading slash.
|
|
@@ -157,7 +154,7 @@ type ExtractRoute<URL extends string> = URL extends `/${string}/${string}/${infe
|
|
|
157
154
|
* Gets all route keys from Routers as strings.
|
|
158
155
|
* All keys should start with a leading slash.
|
|
159
156
|
*/
|
|
160
|
-
type RouterKeys = keyof
|
|
157
|
+
type RouterKeys = keyof ServicesObject & string;
|
|
161
158
|
/**
|
|
162
159
|
* Extracts all prefixes (first segment) in the system, including the leading slash.
|
|
163
160
|
* @example AllPrefixes // '/api' | ...
|
|
@@ -181,100 +178,6 @@ type RoutesForPrefixAndNamespace<P extends string, N extends string> = RouterKey
|
|
|
181
178
|
* ExtractPathParamKeys<'/users/:id?'> // 'id'
|
|
182
179
|
*/
|
|
183
180
|
type ExtractPathParamKeys<S extends string> = S extends `${string}:${infer Param}/${infer Rest}` ? Param extends `${infer Key}?` ? Key | ExtractPathParamKeys<Rest> : Param | ExtractPathParamKeys<Rest> : S extends `${string}:${infer Param}` ? Param extends `${infer Key}?` ? Key : Param : never;
|
|
184
|
-
/**
|
|
185
|
-
* Route configuration interface.
|
|
186
|
-
*/
|
|
187
|
-
interface RouterConfig<T extends string = string> {
|
|
188
|
-
route: T;
|
|
189
|
-
setup?: any;
|
|
190
|
-
readBeforeBody?: boolean;
|
|
191
|
-
}
|
|
192
|
-
type RouterConfigService<T extends string = string> = Omit<RouterConfig<T>, 'route' | 'setup'>;
|
|
193
|
-
|
|
194
|
-
interface SilgiSchema {
|
|
195
|
-
}
|
|
196
|
-
interface MergedSilgiSchema {
|
|
197
|
-
}
|
|
198
|
-
type ExtractMethod<T extends string> = T extends `${infer M}:${string}` ? M : never;
|
|
199
|
-
type ExtractPath<T extends string> = T extends `${string}:${infer P}` ? P : never;
|
|
200
|
-
type RouteEntry<Schema> = {
|
|
201
|
-
[K in keyof Schema & string]: {
|
|
202
|
-
method: ExtractMethod<K>;
|
|
203
|
-
path: ExtractPath<K>;
|
|
204
|
-
raw: K;
|
|
205
|
-
schema: Schema[K];
|
|
206
|
-
};
|
|
207
|
-
}[keyof Schema & string];
|
|
208
|
-
/**
|
|
209
|
-
* Creates an object type representing path parameters extracted from a URL pattern.
|
|
210
|
-
*
|
|
211
|
-
* @example
|
|
212
|
-
* PathParamsObject<'/users/:id/posts/:postId'> // { id?: string | number, postId?: string | number }
|
|
213
|
-
*/
|
|
214
|
-
type PathParamsObject<S extends string> = {
|
|
215
|
-
[K in ExtractPathParamKeys<S>]?: string | number;
|
|
216
|
-
};
|
|
217
|
-
/**
|
|
218
|
-
* Determines if a URL pattern contains any path parameters.
|
|
219
|
-
*
|
|
220
|
-
* @example
|
|
221
|
-
* HasPathParams<'/users/:id'> // true
|
|
222
|
-
* HasPathParams<'/users'> // false
|
|
223
|
-
*/
|
|
224
|
-
type HasPathParams<S extends string> = ExtractPathParamKeys<S> extends never ? false : true;
|
|
225
|
-
/**
|
|
226
|
-
* Base schema definition for API method handlers.
|
|
227
|
-
* Defines the structure of input/output data.
|
|
228
|
-
*/
|
|
229
|
-
interface BaseMethodSchema {
|
|
230
|
-
/** Schema for request body */
|
|
231
|
-
input?: StandardSchemaV1;
|
|
232
|
-
/** Schema for response body */
|
|
233
|
-
output?: StandardSchemaV1;
|
|
234
|
-
/** Schema for URL query parameters */
|
|
235
|
-
queryParams?: StandardSchemaV1;
|
|
236
|
-
/** Schema for source data (contextual information) */
|
|
237
|
-
source?: StandardSchemaV1;
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Interface for adding path parameters schema to method definitions.
|
|
241
|
-
*/
|
|
242
|
-
interface WithPathParams<PathParamsStr extends string> {
|
|
243
|
-
/** Schema for path parameters */
|
|
244
|
-
pathParams: StandardSchemaV1<PathParamsObject<PathParamsStr>>;
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Defines the schema structure for HTTP methods, conditionally including
|
|
248
|
-
* path parameters based on the URL pattern.
|
|
249
|
-
*
|
|
250
|
-
* @example
|
|
251
|
-
* // For a route with path parameters:
|
|
252
|
-
* type UserMethodSchema = MethodSchemas<'/:id'>
|
|
253
|
-
* // Result includes required pathParams for each method
|
|
254
|
-
*
|
|
255
|
-
* // For a route without path parameters:
|
|
256
|
-
* type ListMethodSchema = MethodSchemas<''>
|
|
257
|
-
* // Result doesn't allow pathParams property
|
|
258
|
-
*/
|
|
259
|
-
type MethodSchemas<PathParamsStr extends string = ''> = {
|
|
260
|
-
[K in HTTPMethod]?: HasPathParams<PathParamsStr> extends true ? BaseMethodSchema & WithPathParams<PathParamsStr> : BaseMethodSchema & {
|
|
261
|
-
pathParams?: never;
|
|
262
|
-
};
|
|
263
|
-
};
|
|
264
|
-
/**
|
|
265
|
-
* Represents a fully resolved schema definition that maps API route paths
|
|
266
|
-
* to their method schemas.
|
|
267
|
-
*/
|
|
268
|
-
interface ResolvedSchema {
|
|
269
|
-
[routePath: string]: MethodSchemas<string>;
|
|
270
|
-
}
|
|
271
|
-
/**
|
|
272
|
-
* Represents a schema definition that has been fully resolved,
|
|
273
|
-
* typically after processing and validating all schema components.
|
|
274
|
-
*/
|
|
275
|
-
interface ResolvedSchemaDefinition {
|
|
276
|
-
[methodAndRoutePath: string]: BaseMethodSchema;
|
|
277
|
-
}
|
|
278
181
|
|
|
279
182
|
type CustomDriverName = string & {
|
|
280
183
|
_custom?: any;
|
|
@@ -313,60 +216,61 @@ interface SilgiRuntimeSharedsExtend {
|
|
|
313
216
|
interface ExtendShared {
|
|
314
217
|
}
|
|
315
218
|
|
|
219
|
+
interface ServicesObject {
|
|
220
|
+
}
|
|
316
221
|
/**
|
|
317
222
|
* Yardımcı tipler
|
|
318
223
|
*/
|
|
319
224
|
type InferInput<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferInput<T> : unknown;
|
|
320
225
|
type InferOutput<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<T> : unknown;
|
|
321
|
-
/**
|
|
322
|
-
* Direct parameter type inference for combined route strings
|
|
323
|
-
*/
|
|
324
|
-
type ServiceHandlerParameters<S, R extends keyof S> = S[R] extends {
|
|
325
|
-
pathParams?: infer P;
|
|
326
|
-
} ? S[R] extends {
|
|
327
|
-
queryParams?: infer Q;
|
|
328
|
-
} ? (P extends undefined ? object : {
|
|
329
|
-
path: InferInput<P>;
|
|
330
|
-
}) & (Q extends undefined ? object : {
|
|
331
|
-
query: InferInput<Q>;
|
|
332
|
-
}) : (P extends undefined ? object : {
|
|
333
|
-
path: InferInput<P>;
|
|
334
|
-
}) : S[R] extends {
|
|
335
|
-
queryParams?: infer Q;
|
|
336
|
-
} ? (Q extends undefined ? object : {
|
|
337
|
-
query: InferInput<Q>;
|
|
338
|
-
}) : object;
|
|
339
226
|
/**
|
|
340
227
|
* Route ve method'a göre input, output, params çıkarımı
|
|
228
|
+
*
|
|
229
|
+
* - Eğer PathParams veya QueryParams never/undefined ise parameters alanı eklenmez.
|
|
230
|
+
* - args her zaman zorunlu.
|
|
341
231
|
*/
|
|
342
|
-
type
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
}
|
|
232
|
+
type IsNever<T> = [T] extends [never] ? true : false;
|
|
233
|
+
type IsUndefined<T> = [undefined] extends [T] ? true : false;
|
|
234
|
+
type HasPath<T> = IsNever<T> extends true ? false : IsUndefined<T> extends true ? false : true;
|
|
235
|
+
type HasQuery<T> = IsNever<T> extends true ? false : IsUndefined<T> extends true ? false : true;
|
|
236
|
+
type ServiceHandlerInput<Input extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | never | undefined = never, QueryParams extends StandardSchemaV1 | never | undefined = never, HiddenParameters extends boolean = false> = HiddenParameters extends true ? {
|
|
237
|
+
args: InferInput<Input>;
|
|
238
|
+
} : HasPath<PathParams> extends true ? HasQuery<QueryParams> extends true ? {
|
|
239
|
+
args: InferInput<Input>;
|
|
240
|
+
parameters: {
|
|
241
|
+
path: InferInput<PathParams>;
|
|
242
|
+
query: Partial<InferInput<QueryParams>>;
|
|
243
|
+
};
|
|
244
|
+
} : {
|
|
245
|
+
args: InferInput<Input>;
|
|
246
|
+
parameters: {
|
|
247
|
+
path: InferInput<PathParams>;
|
|
248
|
+
};
|
|
249
|
+
} : HasQuery<QueryParams> extends true ? {
|
|
250
|
+
args: InferInput<Input>;
|
|
251
|
+
parameters: {
|
|
252
|
+
query: InferInput<QueryParams>;
|
|
253
|
+
};
|
|
254
|
+
} : {
|
|
255
|
+
args: InferInput<Input>;
|
|
256
|
+
};
|
|
355
257
|
/**
|
|
356
258
|
* Handler fonksiyon tipi
|
|
357
259
|
*
|
|
358
260
|
* Resolved = false -> handler(input, shared, event, source) // all required
|
|
359
261
|
* Resolved = true -> handler(input, shared?, event?, source?) // only input required
|
|
360
262
|
*/
|
|
361
|
-
type ServiceHandler<
|
|
263
|
+
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>> : (input: ServiceHandlerInput<Input, PathParams, QueryParams, HiddenParameters>, shared: SilgiRuntimeShareds, event: SilgiEvent) => Promise<InferOutput<Output>>;
|
|
362
264
|
/**
|
|
363
265
|
* Servis setup tipi
|
|
364
266
|
*/
|
|
365
|
-
interface ServiceSetup<
|
|
366
|
-
handler: ServiceHandler<
|
|
367
|
-
rules?:
|
|
267
|
+
interface ServiceSetup<Input extends StandardSchemaV1 = StandardSchemaV1, Output extends StandardSchemaV1 = StandardSchemaV1, PathParams extends StandardSchemaV1 | never | undefined = never, QueryParams extends StandardSchemaV1 | never | undefined = never, Resolved extends boolean = false, HiddenParameters extends boolean = false> {
|
|
268
|
+
handler: ServiceHandler<Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
269
|
+
rules?: RouteRules & {
|
|
270
|
+
readBeforeBody?: boolean;
|
|
271
|
+
};
|
|
368
272
|
modules?: Partial<SetupModuleOption>;
|
|
369
|
-
storage?: StorageConfig<ServiceHandlerInput<
|
|
273
|
+
storage?: StorageConfig<ServiceHandlerInput<Input, PathParams, QueryParams, HiddenParameters>>;
|
|
370
274
|
}
|
|
371
275
|
/**
|
|
372
276
|
* Represents a fully resolved service definition that maps route paths
|
|
@@ -375,13 +279,19 @@ interface ServiceSetup<Schema extends SilgiSchema = SilgiSchema, Route extends k
|
|
|
375
279
|
* This interface is designed to be compatible with the structure created
|
|
376
280
|
* by the createService function.
|
|
377
281
|
*
|
|
378
|
-
* Format: "
|
|
282
|
+
* Format: "routePath" => setup + methods + input + output + queryParams
|
|
379
283
|
*/
|
|
380
284
|
interface ResolvedServiceDefinition {
|
|
381
|
-
[
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
285
|
+
[routePath: string]: {
|
|
286
|
+
setup: ServiceSetup<any, any, any, any, any, any>;
|
|
287
|
+
methods: string[];
|
|
288
|
+
input?: StandardSchemaV1;
|
|
289
|
+
output?: StandardSchemaV1;
|
|
290
|
+
queryParams?: {
|
|
291
|
+
path?: StandardSchemaV1;
|
|
292
|
+
query?: StandardSchemaV1;
|
|
293
|
+
};
|
|
294
|
+
};
|
|
385
295
|
}
|
|
386
296
|
/**
|
|
387
297
|
* SilgiURL tipi
|
|
@@ -405,7 +315,7 @@ interface SilgiCLI {
|
|
|
405
315
|
services: ResolvedServiceDefinition;
|
|
406
316
|
middleware: SilgiRoute[];
|
|
407
317
|
shareds: SilgiRuntimeShareds;
|
|
408
|
-
|
|
318
|
+
resolvers: any[];
|
|
409
319
|
schemas: Record<string, any>;
|
|
410
320
|
templates: SilgiTemplate[];
|
|
411
321
|
hooks: Hookable<SilgiCLIHooks>;
|
|
@@ -592,8 +502,6 @@ interface SilgiModule<TOptions extends ModuleOptionsCustom = ModuleOptionsCustom
|
|
|
592
502
|
getMeta?: () => Promise<ModuleMeta>;
|
|
593
503
|
}
|
|
594
504
|
|
|
595
|
-
interface RouteRules extends Record<string, unknown> {
|
|
596
|
-
}
|
|
597
505
|
type MiddlewareHandler<Response extends EventHandlerResponse = EventHandlerResponse> = (event: SilgiEvent, silgi: Silgi) => Response;
|
|
598
506
|
/**
|
|
599
507
|
* Middleware Setup tipi
|
|
@@ -698,15 +606,99 @@ interface SilgiOptions {
|
|
|
698
606
|
[key: string]: any;
|
|
699
607
|
}
|
|
700
608
|
|
|
701
|
-
|
|
609
|
+
interface SilgiSchema {
|
|
610
|
+
}
|
|
611
|
+
interface MergedSilgiSchema {
|
|
612
|
+
}
|
|
613
|
+
type ExtractMethod<T extends string> = T extends `${infer M}:${string}` ? M : never;
|
|
614
|
+
type ExtractPath<T extends string> = T extends `${string}:${infer P}` ? P : never;
|
|
615
|
+
type RouteEntry<Schema> = {
|
|
616
|
+
[K in keyof Schema & string]: {
|
|
617
|
+
method: ExtractMethod<K>;
|
|
618
|
+
path: ExtractPath<K>;
|
|
619
|
+
raw: K;
|
|
620
|
+
schema: Schema[K];
|
|
621
|
+
};
|
|
622
|
+
}[keyof Schema & string];
|
|
623
|
+
/**
|
|
624
|
+
* Creates an object type representing path parameters extracted from a URL pattern.
|
|
625
|
+
*
|
|
626
|
+
* @example
|
|
627
|
+
* PathParamsObject<'/users/:id/posts/:postId'> // { id?: string | number, postId?: string | number }
|
|
628
|
+
*/
|
|
629
|
+
type PathParamsObject<S extends string> = {
|
|
630
|
+
[K in ExtractPathParamKeys<S>]?: string | number;
|
|
631
|
+
};
|
|
632
|
+
/**
|
|
633
|
+
* Determines if a URL pattern contains any path parameters.
|
|
634
|
+
*
|
|
635
|
+
* @example
|
|
636
|
+
* HasPathParams<'/users/:id'> // true
|
|
637
|
+
* HasPathParams<'/users'> // false
|
|
638
|
+
*/
|
|
639
|
+
type HasPathParams<S extends string> = ExtractPathParamKeys<S> extends never ? false : true;
|
|
640
|
+
/**
|
|
641
|
+
* Base schema definition for API method handlers.
|
|
642
|
+
* Defines the structure of input/output data.
|
|
643
|
+
*/
|
|
644
|
+
interface BaseMethodSchema {
|
|
645
|
+
/** Schema for request body */
|
|
646
|
+
input?: StandardSchemaV1;
|
|
647
|
+
/** Schema for response body */
|
|
648
|
+
output?: StandardSchemaV1;
|
|
649
|
+
/** Schema for URL query parameters */
|
|
650
|
+
queryParams?: StandardSchemaV1;
|
|
651
|
+
/** Schema for source data (contextual information) */
|
|
652
|
+
source?: StandardSchemaV1;
|
|
653
|
+
}
|
|
654
|
+
/**
|
|
655
|
+
* Interface for adding path parameters schema to method definitions.
|
|
656
|
+
*/
|
|
657
|
+
interface WithPathParams<PathParamsStr extends string> {
|
|
658
|
+
/** Schema for path parameters */
|
|
659
|
+
pathParams: StandardSchemaV1<PathParamsObject<PathParamsStr>>;
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Defines the schema structure for HTTP methods, conditionally including
|
|
663
|
+
* path parameters based on the URL pattern.
|
|
664
|
+
*
|
|
665
|
+
* @example
|
|
666
|
+
* // For a route with path parameters:
|
|
667
|
+
* type UserMethodSchema = MethodSchemas<'/:id'>
|
|
668
|
+
* // Result includes required pathParams for each method
|
|
669
|
+
*
|
|
670
|
+
* // For a route without path parameters:
|
|
671
|
+
* type ListMethodSchema = MethodSchemas<''>
|
|
672
|
+
* // Result doesn't allow pathParams property
|
|
673
|
+
*/
|
|
674
|
+
type MethodSchemas<PathParamsStr extends string = ''> = {
|
|
675
|
+
[K in HTTPMethod]?: HasPathParams<PathParamsStr> extends true ? BaseMethodSchema & WithPathParams<PathParamsStr> : BaseMethodSchema & {
|
|
676
|
+
pathParams?: never;
|
|
677
|
+
};
|
|
678
|
+
};
|
|
679
|
+
/**
|
|
680
|
+
* Represents a fully resolved schema definition that maps API route paths
|
|
681
|
+
* to their method schemas.
|
|
682
|
+
*/
|
|
683
|
+
interface ResolvedSchema {
|
|
684
|
+
[routePath: string]: MethodSchemas<string>;
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* Represents a schema definition that has been fully resolved,
|
|
688
|
+
* typically after processing and validating all schema components.
|
|
689
|
+
*/
|
|
690
|
+
interface ResolvedSchemaDefinition {
|
|
691
|
+
[methodAndRoutePath: string]: BaseMethodSchema;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
type StandardHTTPMethod = 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE';
|
|
702
695
|
type HTTPMethod = SilgiRuntimeMethods extends Record<string, any> ? keyof SilgiRuntimeMethods | StandardHTTPMethod : StandardHTTPMethod;
|
|
703
696
|
interface MetaData extends Record<string, unknown> {
|
|
704
697
|
}
|
|
705
698
|
interface SilgiRoute {
|
|
706
699
|
route?: string;
|
|
707
700
|
method?: HTTPMethod;
|
|
708
|
-
|
|
709
|
-
service?: ServiceSetup;
|
|
701
|
+
service?: ResolvedServiceDefinition[string];
|
|
710
702
|
middleware?: MiddlewareSetup;
|
|
711
703
|
}
|
|
712
704
|
interface Silgi {
|
|
@@ -716,7 +708,7 @@ interface Silgi {
|
|
|
716
708
|
globalMiddlewares: SilgiRoute[];
|
|
717
709
|
routerPrefixs: string[];
|
|
718
710
|
schemas: ResolvedSchemaDefinition;
|
|
719
|
-
|
|
711
|
+
resolvers: any[];
|
|
720
712
|
services: ResolvedServiceDefinition;
|
|
721
713
|
shared: SilgiRuntimeShareds;
|
|
722
714
|
plugins: SilgiAppPlugin[];
|
|
@@ -847,7 +839,7 @@ interface SilgiCLIHooks extends SilgiHooks {
|
|
|
847
839
|
'before:scan.ts': (data: {
|
|
848
840
|
services: string[];
|
|
849
841
|
shareds: string[];
|
|
850
|
-
|
|
842
|
+
resolvers: string[];
|
|
851
843
|
schemas: string[];
|
|
852
844
|
middlewares: string[];
|
|
853
845
|
addImportItem: (data: GenImport | GenImport[]) => void;
|
|
@@ -865,6 +857,10 @@ interface SilgiCLIHooks extends SilgiHooks {
|
|
|
865
857
|
key: string;
|
|
866
858
|
value: string;
|
|
867
859
|
}[];
|
|
860
|
+
resolvers: {
|
|
861
|
+
key: string;
|
|
862
|
+
value: string;
|
|
863
|
+
}[];
|
|
868
864
|
methods: {
|
|
869
865
|
key: string;
|
|
870
866
|
value: string;
|
|
@@ -1226,4 +1222,4 @@ interface LoadConfigOptions {
|
|
|
1226
1222
|
consola?: ConsolaInstance;
|
|
1227
1223
|
}
|
|
1228
1224
|
|
|
1229
|
-
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, HttpMethod, LoadConfigOptions, MergeAll, MergedSilgiSchema, MetaData, MethodSchemas, MiddlewareHandler, MiddlewareSetup, ModuleDefinition, ModuleHookContext, ModuleMeta, ModuleOptionsCustom, ModuleSetupInstallResult, ModuleSetupReturn, NamespacesForPrefix, NitroBuildInfo, RequiredServiceType, ResolvedMiddlewareDefinition, ResolvedModuleMeta, ResolvedModuleOptions, ResolvedSchema, ResolvedSchemaDefinition, ResolvedServiceDefinition, ResolvedSilgiTemplate, RouteEntry, RouteRules,
|
|
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, HttpMethod, LoadConfigOptions, MergeAll, 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 };
|