silgi 0.41.23 → 0.41.25
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 +7 -1
- package/dist/cli/index.mjs +1 -1
- package/dist/core/index.d.mts +3 -14
- package/dist/core/index.mjs +12 -7
- package/dist/index.mjs +2 -1
- package/dist/types/index.d.mts +19 -16
- package/package.json +1 -1
package/dist/cli/build.mjs
CHANGED
|
@@ -1972,7 +1972,13 @@ async function prepareSchema(silgi) {
|
|
|
1972
1972
|
generateTypes(
|
|
1973
1973
|
await resolveSchema(
|
|
1974
1974
|
{
|
|
1975
|
-
...silgi.services ? Object.
|
|
1975
|
+
...silgi.services ? Object.values(silgi.services).reduce((acc, service) => {
|
|
1976
|
+
const { route } = getServicePath(service.path);
|
|
1977
|
+
if (route) {
|
|
1978
|
+
acc[route] = "";
|
|
1979
|
+
}
|
|
1980
|
+
return acc;
|
|
1981
|
+
}, {}) : {}
|
|
1976
1982
|
}
|
|
1977
1983
|
),
|
|
1978
1984
|
{
|
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, Routers, ServiceSetup, MiddlewareSetup, SilgiRuntimeShareds, Resolvers, SilgiURL, StorageConfig, SilgiCLI, SilgiStorageBase, SilgiRuntimeConfig } from 'silgi/types';
|
|
1
|
+
import { SilgiConfig, Silgi, SilgiEvent, HTTPMethod, SilgiSchema, RouteEntry, CustomRequestInit, SilgiRuntimeContext, BaseMethodSchema, MergeAll, ServiceSetupsForMethods, ServiceDefinitionByMethodAndPath, 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';
|
|
@@ -158,19 +158,8 @@ declare function deepMergeObjects<T extends readonly Record<string, any>[]>(sche
|
|
|
158
158
|
* ServiceSetup tipinden oluşan bir yardımcı fonksiyon.
|
|
159
159
|
* Tip güvenliğini artırmak için ServiceSetup objesini doğrudan döndürür.
|
|
160
160
|
*/
|
|
161
|
-
declare function defineServiceSetup<Parent extends StandardSchemaV1, Path extends 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>(setup: ServiceSetup<Parent, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>): ServiceSetup<Parent, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
162
|
-
|
|
163
|
-
GET?: ServiceSetup<Parent, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
164
|
-
POST?: ServiceSetup<Parent, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
165
|
-
PUT?: ServiceSetup<Parent, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
166
|
-
PATCH?: ServiceSetup<Parent, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
167
|
-
DELETE?: ServiceSetup<Parent, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
168
|
-
OPTIONS?: ServiceSetup<Parent, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
169
|
-
HEAD?: ServiceSetup<Parent, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
170
|
-
CONNECT?: ServiceSetup<Parent, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
171
|
-
TRACE?: ServiceSetup<Parent, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
172
|
-
};
|
|
173
|
-
declare function createService<Parent extends StandardSchemaV1 = 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: ServiceSetupsForMethods<Parent, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>): ServiceSetupsForMethods<Parent, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
161
|
+
declare function defineServiceSetup<Parent extends StandardSchemaV1, Method extends HTTPMethod, Path extends 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>(setup: ServiceSetup<Parent, Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>): ServiceSetup<Parent, Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
162
|
+
declare function createService<Path extends string, Method extends HTTPMethod, Parent extends StandardSchemaV1 = 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>(params: ServiceSetupsForMethods<Parent, Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>): ServiceDefinitionByMethodAndPath<Path, Method, Parent, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
174
163
|
|
|
175
164
|
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}`;
|
|
176
165
|
type MiddlewarePath<S extends WildcardVariants<keyof Routers>> = S | 'global';
|
package/dist/core/index.mjs
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { toJsonSchema } from '@standard-community/standard-json';
|
|
1
2
|
import consola, { createConsola } from 'consola';
|
|
2
3
|
import { defu } from 'defu';
|
|
3
4
|
import { createHooks } from 'hookable';
|
|
4
5
|
import { createRouter, addRoute, findRoute, findAllRoutes } from 'rou3';
|
|
6
|
+
import { getServicePath } from 'silgi/kit';
|
|
5
7
|
import { useRuntimeConfig, sharedRuntimeConfig } from 'silgi/runtime';
|
|
6
8
|
import { getContext, createContext } from 'unctx';
|
|
7
9
|
import { Buffer } from 'node:buffer';
|
|
8
10
|
import { klona } from 'klona';
|
|
9
11
|
import { createStorage as createStorage$1, builtinDrivers, prefixStorage } from 'unstorage';
|
|
10
12
|
import { isDevelopment } from 'std-env';
|
|
11
|
-
import { toJsonSchema } from '@standard-community/standard-json';
|
|
12
13
|
import { FastURL, FastResponse } from 'srvx';
|
|
13
14
|
export { s as silgiCLICtx, t as tryUseSilgiCLI, u as useSilgiCLI } from '../_chunks/silgiApp.mjs';
|
|
14
15
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
@@ -298,8 +299,10 @@ async function createSilgi(config) {
|
|
|
298
299
|
if (!silgi.router) {
|
|
299
300
|
silgi.router = createRouter();
|
|
300
301
|
}
|
|
301
|
-
for (const [
|
|
302
|
-
|
|
302
|
+
for (const [_route, object] of Object.entries(silgi.services)) {
|
|
303
|
+
const { method } = getServicePath(_route);
|
|
304
|
+
if (!object)
|
|
305
|
+
continue;
|
|
303
306
|
const path = String(object.path);
|
|
304
307
|
const routeParts = path.split("/").filter(Boolean);
|
|
305
308
|
if (routeParts.length > 0) {
|
|
@@ -326,8 +329,8 @@ async function createSilgi(config) {
|
|
|
326
329
|
}
|
|
327
330
|
}
|
|
328
331
|
}
|
|
329
|
-
addRoute(silgi.router, object.apiType === "graphql" ? "" : method, routeWithParams, {
|
|
330
|
-
method: object.apiType === "graphql" ? "" : method,
|
|
332
|
+
addRoute(silgi.router, object.apiType === "rest-graphql" ? "" : method, routeWithParams, {
|
|
333
|
+
method: object.apiType === "rest-graphql" ? "" : method,
|
|
331
334
|
route: routeWithParams,
|
|
332
335
|
service: object
|
|
333
336
|
});
|
|
@@ -1018,7 +1021,7 @@ async function handler(event, url, input) {
|
|
|
1018
1021
|
const data = middleware(event, url);
|
|
1019
1022
|
_chain = data;
|
|
1020
1023
|
if (silgiCtx.router) {
|
|
1021
|
-
|
|
1024
|
+
const match = findRoute(silgiCtx.router, url.method, pathname);
|
|
1022
1025
|
if (match) {
|
|
1023
1026
|
if (_chain) {
|
|
1024
1027
|
return _chain.then(async (_previous) => {
|
|
@@ -1089,7 +1092,9 @@ function defineServiceSetup(setup) {
|
|
|
1089
1092
|
return setup;
|
|
1090
1093
|
}
|
|
1091
1094
|
function createService(params) {
|
|
1092
|
-
return
|
|
1095
|
+
return {
|
|
1096
|
+
[`${params.method}:${params.path}`]: params
|
|
1097
|
+
};
|
|
1093
1098
|
}
|
|
1094
1099
|
|
|
1095
1100
|
function createMiddleware(params) {
|
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
export { SilgiError, autoImportTypes, createError, createMiddleware, createResolver, createSchema, createService, createShared, createSilgi, createStorage, deepMergeObjects, defineServiceSetup, 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
|
+
import '@standard-community/standard-json';
|
|
3
4
|
import 'consola';
|
|
4
5
|
import 'defu';
|
|
5
6
|
import 'hookable';
|
|
6
7
|
import 'rou3';
|
|
8
|
+
import 'silgi/kit';
|
|
7
9
|
import 'silgi/runtime';
|
|
8
10
|
import 'unctx';
|
|
9
11
|
import 'node:buffer';
|
|
10
12
|
import 'klona';
|
|
11
13
|
import 'unstorage';
|
|
12
14
|
import 'std-env';
|
|
13
|
-
import '@standard-community/standard-json';
|
|
14
15
|
import 'srvx';
|
|
15
16
|
import 'node:async_hooks';
|
package/dist/types/index.d.mts
CHANGED
|
@@ -23,9 +23,9 @@ import { RouterContext } from 'rou3';
|
|
|
23
23
|
import { TransactionOptions, BuiltinDriverName, StorageValue, Storage } from 'unstorage';
|
|
24
24
|
import { ServerRequest } from 'srvx';
|
|
25
25
|
import { Defu } from 'defu';
|
|
26
|
+
import { GraphQLResolveInfo } from 'graphql';
|
|
26
27
|
import { silgiFetch } from 'silgi';
|
|
27
28
|
import { useRuntimeConfig } from 'silgi/runtime';
|
|
28
|
-
import { GraphQLResolveInfo } from 'graphql';
|
|
29
29
|
import { Unimport } from 'unimport';
|
|
30
30
|
import { ProviderName } from 'std-env';
|
|
31
31
|
import { FetchOptions, FetchResponse } from 'ofetch';
|
|
@@ -227,8 +227,6 @@ interface ExtendShared {
|
|
|
227
227
|
|
|
228
228
|
interface ServicesObject {
|
|
229
229
|
}
|
|
230
|
-
type SlashCount<S extends string, Count extends any[] = []> = S extends `${infer _Prefix}/${infer Rest}` ? SlashCount<Rest, [any, ...Count]> : Count['length'];
|
|
231
|
-
type Max4Slashes<S extends keyof Routers> = SlashCount<S> extends 0 | 1 | 2 | 3 ? S : never;
|
|
232
230
|
/**
|
|
233
231
|
* Yardımcı tipler
|
|
234
232
|
*/
|
|
@@ -269,9 +267,10 @@ type ServiceHandler<Parent extends StandardSchemaV1, Input extends StandardSchem
|
|
|
269
267
|
/**
|
|
270
268
|
* Servis setup tipi
|
|
271
269
|
*/
|
|
272
|
-
interface ServiceSetup<Parent extends StandardSchemaV1 = StandardSchemaV1, Path extends
|
|
273
|
-
path:
|
|
274
|
-
|
|
270
|
+
interface ServiceSetup<Parent extends StandardSchemaV1 = StandardSchemaV1, Method extends HTTPMethod = HTTPMethod, Path extends string = string, 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> {
|
|
271
|
+
path: Path;
|
|
272
|
+
method: Method;
|
|
273
|
+
apiType: 'rest' | 'rest-graphql';
|
|
275
274
|
handler?: ServiceHandler<Parent, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
276
275
|
rules?: MergeRouteRules;
|
|
277
276
|
modules?: Partial<SetupModuleOption>;
|
|
@@ -291,15 +290,7 @@ interface ServiceSetup<Parent extends StandardSchemaV1 = StandardSchemaV1, Path
|
|
|
291
290
|
* Format: "routePath" => setup + methods + input + output + queryParams
|
|
292
291
|
*/
|
|
293
292
|
interface ResolvedServiceDefinition {
|
|
294
|
-
|
|
295
|
-
POST?: ServiceSetup;
|
|
296
|
-
PUT?: ServiceSetup;
|
|
297
|
-
PATCH?: ServiceSetup;
|
|
298
|
-
DELETE?: ServiceSetup;
|
|
299
|
-
OPTIONS?: ServiceSetup;
|
|
300
|
-
HEAD?: ServiceSetup;
|
|
301
|
-
CONNECT?: ServiceSetup;
|
|
302
|
-
TRACE?: ServiceSetup;
|
|
293
|
+
[key: string]: ServiceSetup;
|
|
303
294
|
}
|
|
304
295
|
/**
|
|
305
296
|
* SilgiURL tipi
|
|
@@ -313,6 +304,18 @@ interface SilgiURL {
|
|
|
313
304
|
pathParams?: Record<string, string | undefined>;
|
|
314
305
|
queryParams?: Record<string, string>;
|
|
315
306
|
}
|
|
307
|
+
type ServiceSetupsForMethods<Parent extends StandardSchemaV1 = StandardSchemaV1, Method extends HTTPMethod = HTTPMethod, Path extends string = string, 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> = ServiceSetup<Parent, Method, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
308
|
+
/**
|
|
309
|
+
* Sadece belirtilen HTTP methodları için anahtar üretir.
|
|
310
|
+
* Varsayılan olarak tüm methodlar çıkar.
|
|
311
|
+
*
|
|
312
|
+
* Örnek:
|
|
313
|
+
* ServiceDefinitionByMethodAndPath<'/foo', ..., 'GET' | 'POST'>
|
|
314
|
+
* // Sadece "GET:/foo" ve "POST:/foo" anahtarları olur.
|
|
315
|
+
*/
|
|
316
|
+
type ServiceDefinitionByMethodAndPath<Path extends string, Method extends HTTPMethod = HTTPMethod, Parent extends StandardSchemaV1 = 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> = {
|
|
317
|
+
[M in Method as `${M}:${Path}`]?: ServiceSetup<Parent, M, Path, Input, Output, PathParams, QueryParams, Resolved, HiddenParameters>;
|
|
318
|
+
};
|
|
316
319
|
|
|
317
320
|
interface SilgiCLI {
|
|
318
321
|
_ignore?: Ignore;
|
|
@@ -1228,4 +1231,4 @@ interface LoadConfigOptions {
|
|
|
1228
1231
|
consola?: ConsolaInstance;
|
|
1229
1232
|
}
|
|
1230
1233
|
|
|
1231
|
-
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 };
|
|
1234
|
+
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, ServiceDefinitionByMethodAndPath, ServiceHandler, ServiceHandlerInput, ServiceSetup, ServiceSetupsForMethods, 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 };
|