silgi 0.33.2 → 0.34.1
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/build.mjs +1 -2
- package/dist/cli/build.mjs +35 -309
- package/dist/cli/index.mjs +1 -1
- package/dist/cli/init.mjs +1 -2
- package/dist/cli/install.mjs +13 -2
- package/dist/cli/types.mjs +2 -10
- package/dist/cli/watch.mjs +1 -2
- package/dist/core/index.d.mts +293 -210
- package/dist/core/index.mjs +670 -465
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +3 -3
- package/dist/kit/index.d.mts +5 -31
- package/dist/kit/index.mjs +1 -55
- package/dist/runtime/internal/config.d.mts +2 -2
- package/dist/runtime/internal/next.d.mts +1 -1
- package/dist/runtime/internal/next.mjs +51 -37
- package/dist/runtime/internal/nitro.d.mts +1 -1
- package/dist/runtime/internal/nitro.mjs +87 -61
- package/dist/types/index.d.mts +418 -448
- package/package.json +6 -2
- package/dist/_chunks/routeRules.mjs +0 -288
package/dist/types/index.d.mts
CHANGED
|
@@ -2,16 +2,16 @@ import { ApifulConfig } from 'apiful/config';
|
|
|
2
2
|
import { C12InputConfig, ResolvedConfig, ConfigWatcher, WatchConfigOptions } from 'c12';
|
|
3
3
|
import { ChokidarOptions } from 'chokidar';
|
|
4
4
|
import { DateString, CompatibilityDateSpec, CompatibilityDates } from 'compatx';
|
|
5
|
-
import { ConsolaInstance,
|
|
5
|
+
import { ConsolaInstance, ConsolaOptions, LogLevel } from 'consola';
|
|
6
6
|
import { Hookable, NestedHooks } from 'hookable';
|
|
7
7
|
import { Ignore, Options } from 'ignore';
|
|
8
8
|
import { TSConfig } from 'pkg-types';
|
|
9
9
|
import { PresetName, PresetOptions, PresetNameInput } from 'silgi/presets';
|
|
10
|
-
import {
|
|
10
|
+
import { SilgiRuntimeShareds as SilgiRuntimeShareds$1, ModuleMeta as ModuleMeta$1, SilgiModule as SilgiModule$1, BuildSilgi as BuildSilgi$1, SilgiSchema as SilgiSchema$1, SilgiEvent as SilgiEvent$1, SilgiRuntimeActions as SilgiRuntimeActions$1, StorageConfig as StorageConfig$1, Commands as Commands$1, DotenvOptions as DotenvOptions$1, EnvOptions as EnvOptions$1, SilgiRuntimeConfig as SilgiRuntimeConfig$1, SilgiCLIHooks as SilgiCLIHooks$1, StorageMounts as StorageMounts$1, SilgiTemplate as SilgiTemplate$1, SilgiFrameworkInfo as SilgiFrameworkInfo$1 } from 'silgi/types';
|
|
11
11
|
import { Adapter, TablesSchema, InferModelTypes } from 'unadapter/types';
|
|
12
12
|
import { UnimportPluginOptions } from 'unimport/unplugin';
|
|
13
13
|
import * as h3 from 'h3';
|
|
14
|
-
import { H3Event } from 'h3';
|
|
14
|
+
import { HTTPMethod as HTTPMethod$1, Session, H3Event } from 'h3';
|
|
15
15
|
import * as nitropack_types from 'nitropack/types';
|
|
16
16
|
import { NitroRuntimeConfig } from 'nitropack/types';
|
|
17
17
|
import { Defu } from 'defu';
|
|
@@ -21,11 +21,11 @@ import { ESMImport, ESMCodeGenOptions } from 'knitwork';
|
|
|
21
21
|
import { Unimport } from 'unimport';
|
|
22
22
|
import { Storage, TransactionOptions, BuiltinDriverName, StorageValue } from 'unstorage';
|
|
23
23
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
24
|
+
import { RouterContext } from 'rou3';
|
|
25
|
+
import { silgiFetch } from 'silgi';
|
|
24
26
|
import { ProviderName } from 'std-env';
|
|
25
27
|
import { FetchOptions, FetchResponse } from 'ofetch';
|
|
26
28
|
|
|
27
|
-
type HookResult = Promise<void> | void;
|
|
28
|
-
|
|
29
29
|
interface SilgiCompatibilityIssue {
|
|
30
30
|
name: string;
|
|
31
31
|
message: string;
|
|
@@ -37,20 +37,45 @@ interface SilgiCompatibilityIssues extends Array<SilgiCompatibilityIssue> {
|
|
|
37
37
|
toString: () => string;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
type RequiredServiceType<T> = {
|
|
41
|
+
[K in keyof T]-?: T[K] extends Record<string, any> ? {
|
|
42
|
+
[P in keyof T[K]]-?: any;
|
|
43
|
+
} : never;
|
|
44
|
+
};
|
|
45
|
+
type EventHandlerResponse<T = undefined> = T extends undefined ? void : void | T | Promise<T>;
|
|
46
|
+
type HookResult = Promise<void> | void;
|
|
47
|
+
interface EnvOptions {
|
|
48
|
+
prefix?: string;
|
|
49
|
+
altPrefix?: string;
|
|
50
|
+
silgiPrefix?: string;
|
|
51
|
+
envExpansion?: boolean;
|
|
52
|
+
}
|
|
53
|
+
type IsPlainObject<T> = T extends object ? T extends Function ? false : T extends any[] ? false : true : false;
|
|
54
|
+
/**
|
|
55
|
+
* Recursively merges two object types. Properties in U override properties in T.
|
|
56
|
+
* @template T - The base object type.
|
|
57
|
+
* @template U - The object type to merge into T.
|
|
58
|
+
*/
|
|
59
|
+
type DeepMerge<A, B> = {
|
|
60
|
+
[K in keyof A | keyof B]: K extends keyof B ? K extends keyof A ? IsPlainObject<A[K]> extends true ? IsPlainObject<B[K]> extends true ? DeepMerge<A[K], B[K]> : B[K] : B[K] : B[K] : K extends keyof A ? A[K] : never;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Merges an array of object types recursively using DeepMerge.
|
|
64
|
+
* @template T - A tuple type containing the object types to merge.
|
|
65
|
+
*/
|
|
66
|
+
type MergeAll<T extends readonly any[]> = T extends [infer First, ...infer Rest] ? Rest extends [] ? First : DeepMerge<First, MergeAll<Rest>> : object;
|
|
67
|
+
|
|
40
68
|
interface SilgiCLI {
|
|
41
69
|
_ignore?: Ignore;
|
|
42
70
|
errors: {
|
|
43
71
|
type: 'Parser';
|
|
44
72
|
path?: string;
|
|
45
73
|
}[];
|
|
46
|
-
services:
|
|
74
|
+
services: ResolvedServiceDefinition;
|
|
47
75
|
shareds: SilgiRuntimeShareds$1;
|
|
48
|
-
uris: Record<string, any>;
|
|
49
76
|
schemas: Record<string, any>;
|
|
50
|
-
modulesURIs: Partial<Record<keyof SilgiRuntimeOptions$1 | (string & {}), any>>;
|
|
51
77
|
scannedURIs: Map<string, string>;
|
|
52
78
|
templates: SilgiTemplate[];
|
|
53
|
-
routeRules: RouteRules$1;
|
|
54
79
|
hooks: Hookable<SilgiCLIHooks>;
|
|
55
80
|
hook: SilgiCLI['hooks']['hook'];
|
|
56
81
|
callHook: SilgiCLI['hooks']['callHook'];
|
|
@@ -104,10 +129,8 @@ interface ScanFile {
|
|
|
104
129
|
context: string;
|
|
105
130
|
object: {
|
|
106
131
|
schemas: any;
|
|
107
|
-
uris: any;
|
|
108
132
|
services: any;
|
|
109
133
|
shareds: any;
|
|
110
|
-
modulesURIs: any;
|
|
111
134
|
};
|
|
112
135
|
path: string;
|
|
113
136
|
}
|
|
@@ -210,11 +233,10 @@ interface SilgiCLIHooks extends SilgiHooks {
|
|
|
210
233
|
}) => HookResult;
|
|
211
234
|
'after:core.ts': (content: string[]) => HookResult;
|
|
212
235
|
'before:scan.ts': (data: {
|
|
213
|
-
uris: Record<string, string>;
|
|
214
236
|
services: string[];
|
|
215
237
|
shareds: string[];
|
|
238
|
+
routers: string[];
|
|
216
239
|
schemas: string[];
|
|
217
|
-
modulesURIs: Record<string, string>;
|
|
218
240
|
addImportItem: (data: GenImport | GenImport[]) => void;
|
|
219
241
|
addImportItemType: (data: GenImport | GenImport[]) => void;
|
|
220
242
|
}) => HookResult;
|
|
@@ -234,14 +256,6 @@ interface SilgiCLIHooks extends SilgiHooks {
|
|
|
234
256
|
key: string;
|
|
235
257
|
value: string;
|
|
236
258
|
}[];
|
|
237
|
-
routeRules: {
|
|
238
|
-
key: string;
|
|
239
|
-
value: string;
|
|
240
|
-
}[];
|
|
241
|
-
routeRulesConfig: {
|
|
242
|
-
key: string;
|
|
243
|
-
value: string;
|
|
244
|
-
}[];
|
|
245
259
|
contexts: {
|
|
246
260
|
key: string;
|
|
247
261
|
value: string;
|
|
@@ -259,7 +273,7 @@ interface SilgiCLIHooks extends SilgiHooks {
|
|
|
259
273
|
value: string;
|
|
260
274
|
/**
|
|
261
275
|
* If extends is true, it won't be added to the key value interface.
|
|
262
|
-
* interface SilgiModuleEventsExtends extends
|
|
276
|
+
* interface SilgiModuleEventsExtends extends SilgiEvent {}
|
|
263
277
|
*/
|
|
264
278
|
extends?: boolean;
|
|
265
279
|
isSilgiContext?: boolean;
|
|
@@ -301,132 +315,356 @@ interface GenerateAppOptions {
|
|
|
301
315
|
filter?: (template: ResolvedSilgiTemplate<any>) => boolean;
|
|
302
316
|
}
|
|
303
317
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
318
|
+
type TrimAfterFourSlashes<T extends string> = T extends `/${infer S1}/${infer S2}/${infer S3}/${infer S4}/${infer _}` ? `/${S1}/${S2}/${S3}/${S4}` : T;
|
|
319
|
+
type AllPaths = SilgiRouterTypes extends {
|
|
320
|
+
keys: infer U;
|
|
321
|
+
} ? keyof U extends never ? string : keyof U : string;
|
|
322
|
+
type ExtractPathParams<T extends string> = T extends `${infer _Start}:${infer Param}/${infer Rest}` ? {
|
|
323
|
+
[K in Param]: string;
|
|
324
|
+
} & ExtractPathParams<Rest> : T extends `${infer _Start}:${infer Param}` ? {
|
|
325
|
+
[K in Param]: string;
|
|
326
|
+
} : unknown;
|
|
309
327
|
|
|
310
|
-
|
|
328
|
+
type HttpMethod = 'get' | 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'head' | 'patch' | 'post' | 'put' | 'delete' | 'connect' | 'options' | 'trace';
|
|
329
|
+
type RouterParams<R extends AllPaths | (string & {})> = ExtractPathParams<R>;
|
|
330
|
+
type SilgiFetchOptions<P extends AllPaths | (string & {}), BasePath extends keyof SilgiRouterTypes = TrimAfterFourSlashes<P> extends keyof SilgiRouterTypes ? TrimAfterFourSlashes<P> : never, M extends keyof SilgiRouterTypes[BasePath] = keyof SilgiRouterTypes[BasePath]> = {
|
|
331
|
+
method?: M;
|
|
332
|
+
params?: ExtractPathParams<P>;
|
|
333
|
+
body?: SilgiRouterTypes[BasePath][M]['input'];
|
|
334
|
+
} & Omit<FetchOptions, 'method' | 'body' | 'params'>;
|
|
335
|
+
type SilgiFetchClient = <P extends AllPaths | (string & {}), BasePath extends keyof SilgiRouterTypes = TrimAfterFourSlashes<P> extends keyof SilgiRouterTypes ? TrimAfterFourSlashes<P> : never, M extends keyof SilgiRouterTypes[BasePath] = keyof SilgiRouterTypes[BasePath]>(url: BasePath, options?: SilgiFetchOptions<P, BasePath, M>) => Promise<FetchResponse<SilgiRouterTypes[BasePath][M]['output']>>;
|
|
336
|
+
|
|
337
|
+
interface SilgiAppPlugin {
|
|
338
|
+
(silgi: Silgi): Promise<void> | void;
|
|
311
339
|
}
|
|
312
|
-
|
|
340
|
+
|
|
341
|
+
interface CapturedErrorContext {
|
|
342
|
+
event?: SilgiEvent;
|
|
343
|
+
[key: string]: unknown;
|
|
313
344
|
}
|
|
314
|
-
type
|
|
315
|
-
[Action in BaseSilgiMethodType]?: Record<string, {
|
|
316
|
-
input?: T;
|
|
317
|
-
output?: T;
|
|
318
|
-
pathParams?: T;
|
|
319
|
-
queryParams?: T;
|
|
320
|
-
source?: T;
|
|
321
|
-
}>;
|
|
322
|
-
};
|
|
345
|
+
type CaptureError = (silgi: Silgi, error: Error, context: CapturedErrorContext) => void;
|
|
323
346
|
|
|
324
|
-
|
|
347
|
+
/**
|
|
348
|
+
* Yardımcı tipler
|
|
349
|
+
*/
|
|
350
|
+
type InferInput<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferInput<T> : unknown;
|
|
351
|
+
type InferOutput<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<T> : unknown;
|
|
352
|
+
type ServiceHandlerParameters<S, R extends keyof S, M extends keyof S[R]> = S[R][M] extends {
|
|
353
|
+
pathParams?: infer P;
|
|
354
|
+
} ? S[R][M] extends {
|
|
355
|
+
queryParams?: infer Q;
|
|
356
|
+
} ? (P extends undefined ? object : {
|
|
357
|
+
path: InferInput<P>;
|
|
358
|
+
}) & (Q extends undefined ? object : {
|
|
359
|
+
query: InferInput<Q>;
|
|
360
|
+
}) : (P extends undefined ? object : {
|
|
361
|
+
path: InferInput<P>;
|
|
362
|
+
}) : S[R][M] extends {
|
|
363
|
+
queryParams?: infer Q;
|
|
364
|
+
} ? (Q extends undefined ? object : {
|
|
365
|
+
query: InferInput<Q>;
|
|
366
|
+
}) : object;
|
|
367
|
+
/**
|
|
368
|
+
* Route ve method'a göre input, output, params çıkarımı
|
|
369
|
+
*/
|
|
370
|
+
type ServiceHandlerInput<Schema extends SilgiSchema$1, Route extends keyof Schema, Method extends keyof Schema[Route], HiddenParameters extends boolean = false> = (Schema[Route][Method] extends {
|
|
371
|
+
input?: infer I;
|
|
372
|
+
} ? {
|
|
373
|
+
args: InferInput<I>;
|
|
374
|
+
} : unknown) & (HiddenParameters extends false ? (keyof ServiceHandlerParameters<Schema, Route, Method> extends never ? unknown : {
|
|
375
|
+
parameters: ServiceHandlerParameters<Schema, Route, Method>;
|
|
376
|
+
}) : unknown);
|
|
377
|
+
type ServiceHandlerOutput<Schema extends SilgiSchema$1, Route extends keyof Schema, Method extends keyof Schema[Route]> = Schema[Route][Method] extends {
|
|
378
|
+
output?: infer O;
|
|
379
|
+
} ? InferOutput<O> : unknown;
|
|
380
|
+
type ServiceHandlerSource<Schema extends SilgiSchema$1, Route extends keyof Schema, Method extends keyof Schema[Route]> = Schema[Route][Method] extends {
|
|
381
|
+
source?: infer S;
|
|
382
|
+
} ? InferInput<S> : unknown;
|
|
383
|
+
/**
|
|
384
|
+
* Handler fonksiyon tipi
|
|
385
|
+
*
|
|
386
|
+
* Resolved = false -> handler(input, shared, event, source) // all required
|
|
387
|
+
* Resolved = true -> handler(input, shared?, event?, source?) // only input required
|
|
388
|
+
*/
|
|
389
|
+
type ServiceHandler<Schema extends SilgiSchema$1, Route extends keyof Schema, Method extends keyof Schema[Route], Resolved extends boolean = false, HiddenParameters extends boolean = false> = Resolved extends true ? (input: ServiceHandlerInput<Schema, Route, Method, HiddenParameters>, shared?: SilgiRuntimeShareds$1, event?: SilgiEvent$1, source?: ServiceHandlerSource<Schema, Route, Method>) => Promise<ServiceHandlerOutput<Schema, Route, Method>> : (input: ServiceHandlerInput<Schema, Route, Method, HiddenParameters>, shared: SilgiRuntimeShareds$1, event: SilgiEvent$1, source: ServiceHandlerSource<Schema, Route, Method>) => Promise<ServiceHandlerOutput<Schema, Route, Method>>;
|
|
390
|
+
/**
|
|
391
|
+
* Servis setup tipi
|
|
392
|
+
*/
|
|
393
|
+
interface ServiceSetup<Schema extends SilgiSchema$1 = SilgiSchema$1, Route extends keyof Schema = keyof Schema, Method extends keyof Schema[Route] = keyof Schema[Route], Resolved extends boolean = false, HiddenParameters extends boolean = false> {
|
|
394
|
+
handler: ServiceHandler<Schema, Route, Method, Resolved, HiddenParameters>;
|
|
395
|
+
modules?: Partial<SilgiRuntimeActions$1>;
|
|
396
|
+
storage?: StorageConfig$1<ServiceHandlerInput<Schema, Route, Method, HiddenParameters>>;
|
|
325
397
|
}
|
|
326
|
-
|
|
327
|
-
|
|
398
|
+
/**
|
|
399
|
+
* Servis tanımı (tek bir route+method için)
|
|
400
|
+
*/
|
|
401
|
+
type ServiceDefinition<Schema extends SilgiSchema$1, Route extends keyof Schema, Method extends keyof Schema[Route], Resolved extends boolean = false> = {
|
|
402
|
+
[R in Route]: {
|
|
403
|
+
[M in Method]: ServiceSetup<Schema, R, M, Resolved>;
|
|
404
|
+
};
|
|
328
405
|
};
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
406
|
+
/**
|
|
407
|
+
* Çoklu servisleri birleştirmek için yardımcı tip
|
|
408
|
+
*/
|
|
409
|
+
type MergeServiceDefinitions<T extends object[]> = T extends [infer F, ...infer R] ? F & MergeServiceDefinitions<R extends object[] ? R : []> : unknown;
|
|
410
|
+
/**
|
|
411
|
+
* Servis oluşturmak için parametreler
|
|
412
|
+
*/
|
|
413
|
+
interface CreateServiceParams<Schema extends SilgiSchema$1, Route extends keyof Schema, Method extends keyof Schema[Route], Resolved extends boolean = false> {
|
|
414
|
+
route: Route;
|
|
332
415
|
method: Method;
|
|
333
|
-
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
action: string;
|
|
348
|
-
}> = T['service'] extends keyof SilgiSchema ? T['entity'] extends keyof SilgiSchema[T['service']] ? T['method'] extends keyof SilgiSchema[T['service']][T['entity']] ? T['action'] extends keyof SilgiSchema[T['service']][T['entity']][T['method']] ? SilgiSchema[T['service']][T['entity']][T['method']][T['action']] extends {
|
|
349
|
-
output: infer O;
|
|
350
|
-
} ? O extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<O> : never : never : never : never : never : never;
|
|
351
|
-
type GetSource<T extends {
|
|
352
|
-
service: string;
|
|
353
|
-
entity: string;
|
|
354
|
-
method: string;
|
|
355
|
-
action: string;
|
|
356
|
-
}> = T['service'] extends keyof SilgiSchema ? T['entity'] extends keyof SilgiSchema[T['service']] ? T['method'] extends keyof SilgiSchema[T['service']][T['entity']] ? T['action'] extends keyof SilgiSchema[T['service']][T['entity']][T['method']] ? SilgiSchema[T['service']][T['entity']][T['method']][T['action']] extends {
|
|
357
|
-
source: infer I;
|
|
358
|
-
} ? I : never : never : never : never : never;
|
|
359
|
-
type GetQueryParams<T extends {
|
|
360
|
-
service: string;
|
|
361
|
-
entity: string;
|
|
362
|
-
method: string;
|
|
363
|
-
action: string;
|
|
364
|
-
}> = T['service'] extends keyof SilgiSchema ? T['entity'] extends keyof SilgiSchema[T['service']] ? T['method'] extends keyof SilgiSchema[T['service']][T['entity']] ? T['action'] extends keyof SilgiSchema[T['service']][T['entity']][T['method']] ? SilgiSchema[T['service']][T['entity']][T['method']][T['action']] extends {
|
|
365
|
-
queryParams: infer Q;
|
|
366
|
-
} ? Q : never : never : never : never : never;
|
|
367
|
-
type GetPathParams<T extends {
|
|
368
|
-
service: string;
|
|
369
|
-
entity: string;
|
|
370
|
-
method: string;
|
|
371
|
-
action: string;
|
|
372
|
-
}> = T['service'] extends keyof SilgiSchema ? T['entity'] extends keyof SilgiSchema[T['service']] ? T['method'] extends keyof SilgiSchema[T['service']][T['entity']] ? T['action'] extends keyof SilgiSchema[T['service']][T['entity']][T['method']] ? SilgiSchema[T['service']][T['entity']][T['method']][T['action']] extends {
|
|
373
|
-
pathParams: infer Q;
|
|
374
|
-
} ? Q : never : never : never : never : never;
|
|
375
|
-
type ExtractInputFromURI<TURI extends keyof SilgiURIs> = GetInput<ExtractPath<TURI>>;
|
|
376
|
-
type ExtractSourceFromURI<TURI extends keyof SilgiURIs> = GetSource<ExtractPath<TURI>>;
|
|
377
|
-
type ExtractOutputFromURI<TURI extends keyof SilgiURIs> = GetOutput<ExtractPath<TURI>>;
|
|
378
|
-
type ExtractQueryParamsFromURI<TURI extends keyof SilgiURIs> = GetQueryParams<ExtractPath<TURI>>;
|
|
379
|
-
type ExtractPathParamsFromURI<TURI extends keyof SilgiURIs> = GetPathParams<ExtractPath<TURI>>;
|
|
416
|
+
setup: ServiceSetup<Schema, Route, Method, Resolved>;
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* SilgiURL tipi
|
|
420
|
+
*/
|
|
421
|
+
interface SilgiURL {
|
|
422
|
+
namespaceName: string;
|
|
423
|
+
prefixName: string;
|
|
424
|
+
methodName: string;
|
|
425
|
+
path: string;
|
|
426
|
+
raw: string;
|
|
427
|
+
pathParams?: Record<string, string | undefined>;
|
|
428
|
+
queryParams?: Record<string, string>;
|
|
429
|
+
}
|
|
380
430
|
|
|
381
431
|
/**
|
|
382
|
-
*
|
|
383
|
-
* namespace: 'coreApi'
|
|
384
|
-
* serviceName: 'basket'
|
|
385
|
-
* method: 'post'
|
|
386
|
-
* action: 'createBasket'
|
|
432
|
+
* The listeners to Silgi
|
|
387
433
|
*/
|
|
388
|
-
interface
|
|
434
|
+
interface SilgiRuntimeHooks {
|
|
389
435
|
/**
|
|
390
|
-
*
|
|
391
|
-
*
|
|
436
|
+
* Called after Silgi initialization, when the Silgi instance is ready to work.
|
|
437
|
+
* @param silgi The configured Silgi object
|
|
438
|
+
* @returns Promise
|
|
392
439
|
*/
|
|
393
|
-
|
|
440
|
+
'ready': (silgi: Silgi) => HookResult;
|
|
394
441
|
/**
|
|
395
|
-
*
|
|
396
|
-
*
|
|
442
|
+
* Called when silgi instance is gracefully closing.
|
|
443
|
+
* @param silgi The configured silgi object
|
|
444
|
+
* @returns Promise
|
|
397
445
|
*/
|
|
398
|
-
|
|
446
|
+
'close': (silgi: Silgi) => HookResult;
|
|
447
|
+
'app:setup:start': (silgi: Silgi) => HookResult;
|
|
448
|
+
'request:on': (event: SilgiEvent) => HookResult;
|
|
449
|
+
'execute:after': (context: ModuleHookContext) => HookResult;
|
|
450
|
+
'execute:error': (context: ModuleHookContext) => HookResult;
|
|
451
|
+
'execute:finally': (context: ModuleHookContext) => HookResult;
|
|
452
|
+
'event:init': (event: SilgiEvent, data: {
|
|
453
|
+
path: string;
|
|
454
|
+
queryParams?: Record<string, string>;
|
|
455
|
+
url: SilgiURL;
|
|
456
|
+
}) => HookResult;
|
|
457
|
+
'error': CaptureError;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
type CustomDriverName = string & {
|
|
461
|
+
_custom?: any;
|
|
462
|
+
};
|
|
463
|
+
interface StorageMounts {
|
|
464
|
+
[path: string]: {
|
|
465
|
+
driver: BuiltinDriverName | CustomDriverName;
|
|
466
|
+
[option: string]: any;
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
interface SilgiStorageBase {
|
|
470
|
+
}
|
|
471
|
+
type StorageKeyGenerator<TInput> = (input: TInput) => string | Promise<string>;
|
|
472
|
+
interface StorageConfig<TInput> {
|
|
473
|
+
options: TransactionOptions;
|
|
474
|
+
base: 'memory' | keyof SilgiStorageBase;
|
|
475
|
+
key?: StorageKeyGenerator<TInput>;
|
|
476
|
+
scope?: 'request' | 'global';
|
|
477
|
+
}
|
|
478
|
+
interface StorageKeyParams<TInput = unknown> {
|
|
479
|
+
url: SilgiURL;
|
|
480
|
+
input: TInput;
|
|
481
|
+
requestId?: string;
|
|
482
|
+
keyGenerator?: StorageKeyGenerator<TInput>;
|
|
483
|
+
storageOptions?: Pick<StorageConfig<TInput>, 'base' | 'options' | 'scope'>;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
interface SilgiRuntimeConfig {
|
|
487
|
+
}
|
|
488
|
+
interface SilgiOptions {
|
|
489
|
+
consolaOptions?: Partial<ConsolaOptions>;
|
|
490
|
+
present: PresetNameInput;
|
|
491
|
+
hooks: Partial<SilgiRuntimeHooks & DefaultHooks>;
|
|
399
492
|
/**
|
|
400
|
-
*
|
|
401
|
-
*
|
|
493
|
+
* Set to `true` to enable debug mode.
|
|
494
|
+
*
|
|
495
|
+
* At the moment, it prints out hook names and timings on the server, and logs hook arguments as well in the browser.
|
|
496
|
+
*
|
|
497
|
+
* @default false
|
|
402
498
|
*/
|
|
403
|
-
|
|
499
|
+
debug: boolean;
|
|
500
|
+
storage: StorageMounts;
|
|
501
|
+
putStorage?: Storage<StorageValue>;
|
|
502
|
+
runtimeConfig: SilgiRuntimeConfig & {
|
|
503
|
+
[key: string]: any;
|
|
504
|
+
};
|
|
505
|
+
captureError: CaptureError;
|
|
506
|
+
adapters: Record<string, Adapter<Record<string, any>, TablesSchema, InferModelTypes<TablesSchema>>>;
|
|
507
|
+
[key: string]: any;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
interface SilgiSchema {
|
|
511
|
+
}
|
|
512
|
+
interface MergedSilgiSchema {
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Utility type for schema generics to avoid repetition
|
|
516
|
+
*/
|
|
517
|
+
interface SchemaParams<TInput extends StandardSchemaV1 | undefined = undefined, TOutput extends StandardSchemaV1 | undefined = undefined, TPathParams extends StandardSchemaV1 | undefined = undefined, TQueryParams extends StandardSchemaV1 | undefined = undefined, TSource extends StandardSchemaV1 | undefined = undefined> {
|
|
518
|
+
input?: TInput;
|
|
519
|
+
output?: TOutput;
|
|
520
|
+
pathParams?: TPathParams;
|
|
521
|
+
queryParams?: TQueryParams;
|
|
522
|
+
source?: TSource;
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* Defines the structure for schema components within a service endpoint.
|
|
526
|
+
* Allows specifying schemas for input, output, path parameters, query parameters, and source data.
|
|
527
|
+
* @template TInput - The schema type for the request body/input.
|
|
528
|
+
* @template TOutput - The schema type for the response body/output.
|
|
529
|
+
* @template TPathParams - The schema type for URL path parameters.
|
|
530
|
+
* @template TQueryParams - The schema type for URL query parameters.
|
|
531
|
+
* @template TSource - The schema type for the source data or context.
|
|
532
|
+
*/
|
|
533
|
+
type SchemaDefinition<TInput extends StandardSchemaV1 | undefined = undefined, TOutput extends StandardSchemaV1 | undefined = undefined, TPathParams extends StandardSchemaV1 | undefined = undefined, TQueryParams extends StandardSchemaV1 | undefined = undefined, TSource extends StandardSchemaV1 | undefined = undefined> = SchemaParams<TInput, TOutput, TPathParams, TQueryParams, TSource>;
|
|
534
|
+
/**
|
|
535
|
+
* ResolvedServiceDefinition: ServiceDefinition with generics resolved.
|
|
536
|
+
* Represents the fully resolved service definition structure.
|
|
537
|
+
*/
|
|
538
|
+
interface ResolvedSchemaDefinition {
|
|
539
|
+
[route: string]: {
|
|
540
|
+
[method in HTTPMethod$1]: {
|
|
541
|
+
input?: StandardSchemaV1;
|
|
542
|
+
output?: StandardSchemaV1;
|
|
543
|
+
pathParams?: StandardSchemaV1;
|
|
544
|
+
queryParams?: StandardSchemaV1;
|
|
545
|
+
source?: StandardSchemaV1;
|
|
546
|
+
};
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
interface SilgiRuntimeShareds extends SilgiRuntimeSharedsExtend {
|
|
551
|
+
storage: <T extends StorageValue = StorageValue>(base: StorageConfig<T>['base']) => Storage<T>;
|
|
552
|
+
runtimeConfig: SilgiRuntimeConfig;
|
|
553
|
+
$fetch: typeof silgiFetch;
|
|
554
|
+
}
|
|
555
|
+
interface SilgiRuntimeSharedsExtend {
|
|
556
|
+
}
|
|
557
|
+
interface ExtendShared {
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
interface FrameworkContext {
|
|
561
|
+
}
|
|
562
|
+
type HTTPMethod = 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE';
|
|
563
|
+
interface SilgiRoute {
|
|
564
|
+
route: string;
|
|
565
|
+
method?: HTTPMethod;
|
|
566
|
+
setup: ServiceSetup;
|
|
567
|
+
schema: ResolvedSchemaDefinition;
|
|
568
|
+
}
|
|
569
|
+
interface Silgi {
|
|
570
|
+
router: RouterContext<SilgiRoute>;
|
|
571
|
+
routerPrefixs: string[];
|
|
572
|
+
schemas: ResolvedSchemaDefinition;
|
|
573
|
+
services: ResolvedServiceDefinition;
|
|
574
|
+
shared: SilgiRuntimeShareds;
|
|
575
|
+
plugins: SilgiAppPlugin[];
|
|
576
|
+
framework: FrameworkContext;
|
|
577
|
+
_ignore?: Ignore;
|
|
578
|
+
hooks: Hookable<SilgiRuntimeHooks & DefaultHooks>;
|
|
579
|
+
hook: Silgi['hooks']['hook'];
|
|
580
|
+
callHook: Silgi['hooks']['callHook'];
|
|
581
|
+
addHooks: Silgi['hooks']['addHooks'];
|
|
582
|
+
ready: () => Promise<void>;
|
|
583
|
+
close: () => Promise<void>;
|
|
584
|
+
logger: ConsolaInstance;
|
|
585
|
+
storage: Storage;
|
|
586
|
+
envOptions: EnvOptions;
|
|
587
|
+
options: SilgiOptions & SilgiRuntimeOptions;
|
|
588
|
+
captureError: CaptureError;
|
|
589
|
+
}
|
|
590
|
+
interface SilgiConfig extends Partial<Omit<Silgi, 'options'>>, Partial<SilgiRuntimeOptions> {
|
|
591
|
+
options: DeepPartial<SilgiOptions>;
|
|
592
|
+
}
|
|
593
|
+
interface BuildSilgi {
|
|
594
|
+
framework: FrameworkContext;
|
|
595
|
+
modules?: Partial<SilgiRuntimeOptions>;
|
|
596
|
+
options?: Partial<SilgiOptions>;
|
|
597
|
+
}
|
|
598
|
+
type CustomRequestInit<Schema extends SilgiSchema = SilgiSchema, Route extends keyof Schema = keyof Schema, Method extends keyof Schema[Route] = keyof Schema[Route], _Resolved extends boolean = true, _HiddenParameters extends boolean = true> = Omit<RequestInit, 'body' | 'headers' | 'method'> & {
|
|
599
|
+
method: Method;
|
|
600
|
+
body?: Route extends keyof Schema ? Method extends keyof Schema[Route] ? Schema[Route][Method] extends {
|
|
601
|
+
input?: infer I;
|
|
602
|
+
} ? I extends StandardSchemaV1 ? StandardSchemaV1.InferInput<I> : unknown : unknown : unknown : unknown;
|
|
603
|
+
headers?: Route extends keyof Schema ? Method extends keyof Schema[Route] ? Schema[Route][Method] extends {
|
|
604
|
+
headers?: infer H;
|
|
605
|
+
} ? H extends StandardSchemaV1 ? StandardSchemaV1.InferInput<H> : unknown : unknown : unknown : unknown;
|
|
606
|
+
} & (Route extends keyof Schema ? Method extends keyof Schema[Route] ? Schema[Route][Method] extends {
|
|
607
|
+
pathParams?: infer P;
|
|
608
|
+
} ? P extends StandardSchemaV1 ? {
|
|
609
|
+
pathParams: StandardSchemaV1.InferInput<P>;
|
|
610
|
+
} : {
|
|
611
|
+
pathParams?: unknown;
|
|
612
|
+
} : {
|
|
613
|
+
pathParams?: unknown;
|
|
614
|
+
} : {
|
|
615
|
+
pathParams?: unknown;
|
|
616
|
+
} : {
|
|
617
|
+
pathParams?: unknown;
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
interface ExtendContext {
|
|
621
|
+
}
|
|
622
|
+
interface SilgiRuntimeContext extends Record<string, any> {
|
|
623
|
+
params?: Record<string, string>;
|
|
404
624
|
/**
|
|
405
|
-
*
|
|
406
|
-
*
|
|
625
|
+
* Matched router Node
|
|
626
|
+
*
|
|
627
|
+
* @experimental The object structure may change in non-major version.
|
|
407
628
|
*/
|
|
408
|
-
|
|
629
|
+
matchedRoute?: SilgiRoute;
|
|
630
|
+
sessions?: Record<string, Session>;
|
|
631
|
+
clientAddress?: string;
|
|
632
|
+
source?: any;
|
|
633
|
+
}
|
|
634
|
+
interface ServerRequest extends Request {
|
|
409
635
|
/**
|
|
410
|
-
*
|
|
636
|
+
* IP address of the client.
|
|
411
637
|
*/
|
|
412
|
-
|
|
638
|
+
ip?: string | undefined;
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Bu nitrojs, h3 event or request context.
|
|
642
|
+
*/
|
|
643
|
+
interface SilgiEvent extends Record<string, unknown> {
|
|
413
644
|
/**
|
|
414
|
-
*
|
|
645
|
+
* Event context.
|
|
415
646
|
*/
|
|
416
|
-
|
|
647
|
+
readonly context: SilgiRuntimeContext;
|
|
417
648
|
/**
|
|
418
|
-
*
|
|
649
|
+
* Incoming HTTP request info.
|
|
650
|
+
*
|
|
651
|
+
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Request)
|
|
419
652
|
*/
|
|
420
|
-
|
|
653
|
+
readonly req: ServerRequest;
|
|
421
654
|
/**
|
|
422
|
-
*
|
|
655
|
+
* Access to the parsed request URL.
|
|
656
|
+
*
|
|
657
|
+
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/URL)
|
|
423
658
|
*/
|
|
424
|
-
|
|
659
|
+
readonly url: URL;
|
|
425
660
|
/**
|
|
426
|
-
*
|
|
427
|
-
* {limit: '10', page: '1'}
|
|
661
|
+
* Prepared HTTP response.
|
|
428
662
|
*/
|
|
429
|
-
|
|
663
|
+
readonly res: {
|
|
664
|
+
status?: number;
|
|
665
|
+
statusText?: string;
|
|
666
|
+
readonly headers: Headers;
|
|
667
|
+
};
|
|
430
668
|
}
|
|
431
669
|
|
|
432
670
|
interface SilgiRuntimeActions {
|
|
@@ -484,20 +722,14 @@ interface ResolvedModuleMeta extends ModuleMeta {
|
|
|
484
722
|
name: string;
|
|
485
723
|
}
|
|
486
724
|
type ModuleHookContext = Readonly<{
|
|
487
|
-
event
|
|
488
|
-
|
|
725
|
+
event: SilgiEvent;
|
|
726
|
+
url: SilgiURL;
|
|
489
727
|
input?: unknown;
|
|
490
|
-
source?: any;
|
|
491
728
|
result?: unknown;
|
|
492
729
|
modules?: SilgiRuntimeActions;
|
|
493
|
-
timestamp?: number;
|
|
494
|
-
meta?: Record<string, unknown>;
|
|
495
730
|
error?: Error;
|
|
496
731
|
success?: boolean;
|
|
497
732
|
cached?: boolean;
|
|
498
|
-
config?: {
|
|
499
|
-
returnNull: boolean;
|
|
500
|
-
};
|
|
501
733
|
}>;
|
|
502
734
|
/** The options received. */
|
|
503
735
|
type ModuleOptionsCustom = Record<string, any>;
|
|
@@ -550,9 +782,6 @@ type DeepRequired<T> = T extends (...args: any[]) => any ? T : T extends Record<
|
|
|
550
782
|
[P in keyof T]-?: DeepRequired<T[P]>;
|
|
551
783
|
} : T;
|
|
552
784
|
type Awaitable<T> = T | Promise<T>;
|
|
553
|
-
interface CreateScope {
|
|
554
|
-
execute: <TURI extends keyof SilgiURIs>(uriString: TURI, input: ExtractInputFromURI<TURI>) => Promise<ExtractOutputFromURI<TURI>>;
|
|
555
|
-
}
|
|
556
785
|
declare global {
|
|
557
786
|
var $silgiStatus: CommandType;
|
|
558
787
|
var _silgi_runtime: SilgiRuntimeOptions;
|
|
@@ -594,7 +823,6 @@ interface SilgiCLIOptions extends PresetOptions {
|
|
|
594
823
|
};
|
|
595
824
|
commandType: CommandType;
|
|
596
825
|
commands: Commands$1[];
|
|
597
|
-
routeRules: SilgiRouteRules$1;
|
|
598
826
|
schemaVendor: Schema | Schema[];
|
|
599
827
|
environments: DotenvOptions$1[];
|
|
600
828
|
activeEnvironment: 'prod' | 'docker' | 'staging' | 'testing' | '.env' | (string & {});
|
|
@@ -602,7 +830,6 @@ interface SilgiCLIOptions extends PresetOptions {
|
|
|
602
830
|
runtimeConfig: SilgiRuntimeConfig$1 & {
|
|
603
831
|
[key: string]: any;
|
|
604
832
|
};
|
|
605
|
-
serviceParseModules: ServiceParseModule$1[];
|
|
606
833
|
storages: string[];
|
|
607
834
|
namespaces: string[];
|
|
608
835
|
hooks: NestedHooks<SilgiCLIHooks$1>;
|
|
@@ -840,304 +1067,6 @@ interface LoadConfigOptions {
|
|
|
840
1067
|
consola?: ConsolaInstance;
|
|
841
1068
|
}
|
|
842
1069
|
|
|
843
|
-
type TrimAfterFourSlashes<T extends string> = T extends `/${infer S1}/${infer S2}/${infer S3}/${infer S4}/${infer _}` ? `/${S1}/${S2}/${S3}/${S4}` : T;
|
|
844
|
-
type AllPaths = SilgiRouterTypes extends {
|
|
845
|
-
keys: infer U;
|
|
846
|
-
} ? keyof U extends never ? string : keyof U : string;
|
|
847
|
-
type ExtractPathParams<T extends string> = T extends `${infer _Start}:${infer Param}/${infer Rest}` ? {
|
|
848
|
-
[K in Param]: string;
|
|
849
|
-
} & ExtractPathParams<Rest> : T extends `${infer _Start}:${infer Param}` ? {
|
|
850
|
-
[K in Param]: string;
|
|
851
|
-
} : unknown;
|
|
852
|
-
|
|
853
|
-
type HttpMethod = 'get' | 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'head' | 'patch' | 'post' | 'put' | 'delete' | 'connect' | 'options' | 'trace';
|
|
854
|
-
type RouterParams<R extends AllPaths | (string & {})> = ExtractPathParams<R>;
|
|
855
|
-
type SilgiFetchOptions<P extends AllPaths | (string & {}), BasePath extends keyof SilgiRouterTypes = TrimAfterFourSlashes<P> extends keyof SilgiRouterTypes ? TrimAfterFourSlashes<P> : never, M extends keyof SilgiRouterTypes[BasePath] = keyof SilgiRouterTypes[BasePath]> = {
|
|
856
|
-
method?: M;
|
|
857
|
-
params?: ExtractPathParams<P>;
|
|
858
|
-
body?: SilgiRouterTypes[BasePath][M]['input'];
|
|
859
|
-
} & Omit<FetchOptions, 'method' | 'body' | 'params'>;
|
|
860
|
-
type SilgiFetchClient = <P extends AllPaths | (string & {}), BasePath extends keyof SilgiRouterTypes = TrimAfterFourSlashes<P> extends keyof SilgiRouterTypes ? TrimAfterFourSlashes<P> : never, M extends keyof SilgiRouterTypes[BasePath] = keyof SilgiRouterTypes[BasePath]>(url: BasePath, options?: SilgiFetchOptions<P, BasePath, M>) => Promise<FetchResponse<SilgiRouterTypes[BasePath][M]['output']>>;
|
|
861
|
-
|
|
862
|
-
interface EnvOptions {
|
|
863
|
-
prefix?: string;
|
|
864
|
-
altPrefix?: string;
|
|
865
|
-
silgiPrefix?: string;
|
|
866
|
-
envExpansion?: boolean;
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
interface DefaultRouteConfig extends SilgiRuntimeRouteRulesConfig {
|
|
870
|
-
splat?: boolean;
|
|
871
|
-
doubleSplat?: boolean;
|
|
872
|
-
[key: string]: any;
|
|
873
|
-
}
|
|
874
|
-
interface DefaultRouteRules extends SilgiRuntimeRouteRules {
|
|
875
|
-
[key: string]: any;
|
|
876
|
-
}
|
|
877
|
-
type SilgiRouteRules = Record<DefaultRouteRules extends string ? DefaultRouteRules : string, DefaultRouteConfig>;
|
|
878
|
-
interface SilgiRuntimeRouteRules {
|
|
879
|
-
}
|
|
880
|
-
interface SilgiRuntimeRouteRulesConfig {
|
|
881
|
-
}
|
|
882
|
-
/**
|
|
883
|
-
* Interface for the object returned by createRouteRules
|
|
884
|
-
*/
|
|
885
|
-
interface RouteRules {
|
|
886
|
-
readonly rules: Record<string, DefaultRouteConfig>;
|
|
887
|
-
readonly mergedRules: Record<string, DefaultRouteConfig>;
|
|
888
|
-
importRules: (config: Record<string, DefaultRouteConfig>) => void;
|
|
889
|
-
exportRules: () => Record<string, DefaultRouteConfig>;
|
|
890
|
-
addRule: (pattern: string, config: DefaultRouteConfig) => void;
|
|
891
|
-
updateRule: (pattern: string, config: Partial<DefaultRouteConfig>) => void;
|
|
892
|
-
removeRule: (pattern: string) => void;
|
|
893
|
-
matchesRule: (url: string, pattern: string) => boolean;
|
|
894
|
-
getMatchingPatterns: (url: string) => string[];
|
|
895
|
-
getConfig: (url: string) => DefaultRouteConfig | null;
|
|
896
|
-
getParams: (url: string, pattern: string) => Record<string, string> | null;
|
|
897
|
-
match: (url: string) => {
|
|
898
|
-
pattern: string;
|
|
899
|
-
config: DefaultRouteConfig;
|
|
900
|
-
params: Record<string, string> | null;
|
|
901
|
-
} | null;
|
|
902
|
-
clear: () => void;
|
|
903
|
-
clearMergedRules: () => void;
|
|
904
|
-
precomputeMergedRules: (urls: string[]) => void;
|
|
905
|
-
setMergedRule: (url: string, config: DefaultRouteConfig) => void;
|
|
906
|
-
getMergedRules: () => Record<string, DefaultRouteConfig>;
|
|
907
|
-
configure: (config: Record<string, DefaultRouteConfig>) => void;
|
|
908
|
-
updateMergeRules: () => Record<string, DefaultRouteConfig>;
|
|
909
|
-
}
|
|
910
|
-
|
|
911
|
-
type CustomDriverName = string & {
|
|
912
|
-
_custom?: any;
|
|
913
|
-
};
|
|
914
|
-
interface StorageMounts {
|
|
915
|
-
[path: string]: {
|
|
916
|
-
driver: BuiltinDriverName | CustomDriverName;
|
|
917
|
-
[option: string]: any;
|
|
918
|
-
};
|
|
919
|
-
}
|
|
920
|
-
interface SilgiStorageBase {
|
|
921
|
-
}
|
|
922
|
-
type StorageKeyGenerator<TInput> = (input: TInput) => string | Promise<string>;
|
|
923
|
-
interface StorageConfig<TInput> {
|
|
924
|
-
options: TransactionOptions;
|
|
925
|
-
base: 'memory' | keyof SilgiStorageBase;
|
|
926
|
-
key?: StorageKeyGenerator<TInput>;
|
|
927
|
-
scope?: 'request' | 'global';
|
|
928
|
-
}
|
|
929
|
-
interface StorageKeyParams<TInput = unknown> {
|
|
930
|
-
operation: SilgiOperation;
|
|
931
|
-
input: TInput;
|
|
932
|
-
requestId?: string;
|
|
933
|
-
keyGenerator?: StorageKeyGenerator<TInput>;
|
|
934
|
-
storageOptions?: Pick<StorageConfig<TInput>, 'base' | 'options' | 'scope'>;
|
|
935
|
-
}
|
|
936
|
-
|
|
937
|
-
interface SilgiRuntimeShareds extends SilgiRuntimeSharedsExtend {
|
|
938
|
-
storage: <T extends StorageValue = StorageValue>(base: StorageConfig<T>['base']) => Storage<T>;
|
|
939
|
-
silgi: SilgiFunction;
|
|
940
|
-
runtimeConfig: SilgiRuntimeConfig;
|
|
941
|
-
}
|
|
942
|
-
interface SilgiRuntimeSharedsExtend {
|
|
943
|
-
}
|
|
944
|
-
interface ExtendShared {
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
type EventHandlerResponse<T = undefined> = T extends undefined ? void : void | T | Promise<T>;
|
|
948
|
-
type MethodHandlerType<T> = {
|
|
949
|
-
routeRules?: DefaultRouteConfig;
|
|
950
|
-
} & {
|
|
951
|
-
[Action in keyof T]: T[Action] extends Record<string, any> ? {
|
|
952
|
-
routeRules?: DefaultRouteConfig;
|
|
953
|
-
} & {
|
|
954
|
-
[Method in keyof T[Action]]?: {
|
|
955
|
-
default?: {
|
|
956
|
-
input?: StandardSchemaV1.InferInput<T[Action][Method]['input']> & {
|
|
957
|
-
parameters: StandardSchemaV1.InferInput<T[Action][Method]['pathParams']> & StandardSchemaV1.InferInput<T[Action][Method]['queryParams']>;
|
|
958
|
-
};
|
|
959
|
-
output?: StandardSchemaV1.InferInput<T[Action][Method]['output']>;
|
|
960
|
-
source?: StandardSchemaV1.InferInput<T[Action][Method]['source']>;
|
|
961
|
-
};
|
|
962
|
-
handler: (input: StandardSchemaV1.InferInput<T[Action][Method]['input']> & {
|
|
963
|
-
parameters: StandardSchemaV1.InferInput<T[Action][Method]['pathParams']> & StandardSchemaV1.InferInput<T[Action][Method]['queryParams']>;
|
|
964
|
-
}, shared: SilgiRuntimeShareds, event: SilgiEvents, source: StandardSchemaV1.InferInput<T[Action][Method]['source']>) => EventHandlerResponse<StandardSchemaV1.InferOutput<T[Action][Method]['output']>>;
|
|
965
|
-
modules?: Partial<SilgiRuntimeActions>;
|
|
966
|
-
routeRules?: DefaultRouteConfig;
|
|
967
|
-
storage?: StorageConfig<T[Action][Method]['input']>;
|
|
968
|
-
};
|
|
969
|
-
} : never;
|
|
970
|
-
};
|
|
971
|
-
interface ResolvedMethodHandlerType {
|
|
972
|
-
input?: Partial<BaseSchemaType<any>>;
|
|
973
|
-
output: Partial<BaseSchemaType<any>>;
|
|
974
|
-
handler: (input: StandardSchemaV1.InferInput<any> & {
|
|
975
|
-
parameters: any;
|
|
976
|
-
}, shared: SilgiRuntimeShareds, event: SilgiEvents, source: StandardSchemaV1.InferInput<any>) => Promise<StandardSchemaV1.InferInput<any>>;
|
|
977
|
-
modules?: Partial<SilgiRuntimeActions>;
|
|
978
|
-
storage?: StorageConfig<StandardSchemaV1.InferInput<any>>;
|
|
979
|
-
routeRules?: SilgiRouteRules;
|
|
980
|
-
execute: (input: StandardSchemaV1.InferInput<any>, shared: SilgiRuntimeShareds, event: SilgiEvents, source: StandardSchemaV1.InferInput<any>) => Promise<StandardSchemaV1.InferInput<any>>;
|
|
981
|
-
}
|
|
982
|
-
|
|
983
|
-
type SilgiServiceInterface<T extends BaseSchemaType<StandardSchemaV1>> = {
|
|
984
|
-
[Action in keyof T]: T[Action] extends Record<string, any> ? {
|
|
985
|
-
[Method in keyof T[Action]]: {
|
|
986
|
-
input: T[Action][Method]['input'];
|
|
987
|
-
output: T[Action][Method]['output'];
|
|
988
|
-
/**
|
|
989
|
-
* Example: /api/v1/users/{id}/{name}/{surname}
|
|
990
|
-
*/
|
|
991
|
-
pathParams: T[Action][Method]['pathParams'];
|
|
992
|
-
/**
|
|
993
|
-
* Example: /api/v1/users?name=ali&surname=veli
|
|
994
|
-
*/
|
|
995
|
-
queryParams: T[Action][Method]['queryParams'];
|
|
996
|
-
source: T[Action][Method]['source'];
|
|
997
|
-
};
|
|
998
|
-
} : never;
|
|
999
|
-
};
|
|
1000
|
-
type ServiceType<T> = Partial<{
|
|
1001
|
-
[Namespace in keyof T]: T[Namespace] extends Record<string, any> ? {
|
|
1002
|
-
routeRules?: DefaultRouteConfig;
|
|
1003
|
-
} & {
|
|
1004
|
-
[Service in keyof T[Namespace]]?: Partial<MethodHandlerType<T[Namespace][Service]>>;
|
|
1005
|
-
} : never;
|
|
1006
|
-
}>;
|
|
1007
|
-
type RequiredServiceType<T> = {
|
|
1008
|
-
[K in keyof T]-?: T[K] extends Record<string, any> ? {
|
|
1009
|
-
[P in keyof T[K]]-?: MethodHandlerType<T[K][P]>;
|
|
1010
|
-
} : never;
|
|
1011
|
-
};
|
|
1012
|
-
/**
|
|
1013
|
-
* const test: ResolvedServiceType = {
|
|
1014
|
-
aaa: {
|
|
1015
|
-
bbb: {
|
|
1016
|
-
delete: {
|
|
1017
|
-
storage: {
|
|
1018
|
-
handler: () => {}
|
|
1019
|
-
},
|
|
1020
|
-
},
|
|
1021
|
-
},
|
|
1022
|
-
},
|
|
1023
|
-
}
|
|
1024
|
-
*/
|
|
1025
|
-
type ResolvedServiceType = {
|
|
1026
|
-
[K in string]: {
|
|
1027
|
-
[P in string]: {
|
|
1028
|
-
[Q in BaseSilgiMethodType]?: {
|
|
1029
|
-
[M in string]: ResolvedMethodHandlerType;
|
|
1030
|
-
};
|
|
1031
|
-
};
|
|
1032
|
-
};
|
|
1033
|
-
};
|
|
1034
|
-
|
|
1035
|
-
interface FrameworkContext {
|
|
1036
|
-
}
|
|
1037
|
-
interface Silgi {
|
|
1038
|
-
schemas: any;
|
|
1039
|
-
services: RequiredServiceType<SilgiSchema>;
|
|
1040
|
-
shared: SilgiRuntimeShareds;
|
|
1041
|
-
uris: Record<string, any>;
|
|
1042
|
-
modulesURIs: Partial<Record<keyof SilgiRuntimeOptions | (string & {}), any>>;
|
|
1043
|
-
scannedHandlers: Map<string, ResolvedMethodHandlerType>;
|
|
1044
|
-
plugins: SilgiAppPlugin[];
|
|
1045
|
-
framework: FrameworkContext;
|
|
1046
|
-
routeRules: RouteRules;
|
|
1047
|
-
_ignore?: Ignore;
|
|
1048
|
-
hooks: Hookable<SilgiRuntimeHooks & DefaultHooks>;
|
|
1049
|
-
hook: Silgi['hooks']['hook'];
|
|
1050
|
-
callHook: Silgi['hooks']['callHook'];
|
|
1051
|
-
addHooks: Silgi['hooks']['addHooks'];
|
|
1052
|
-
ready: () => Promise<void>;
|
|
1053
|
-
close: () => Promise<void>;
|
|
1054
|
-
logger: ConsolaInstance;
|
|
1055
|
-
storage: Storage;
|
|
1056
|
-
envOptions: EnvOptions;
|
|
1057
|
-
options: SilgiOptions & SilgiRuntimeOptions;
|
|
1058
|
-
captureError: CaptureError;
|
|
1059
|
-
}
|
|
1060
|
-
interface SilgiConfig extends Partial<Omit<Silgi, 'options'>>, Partial<SilgiRuntimeOptions> {
|
|
1061
|
-
options: DeepPartial<SilgiOptions>;
|
|
1062
|
-
}
|
|
1063
|
-
interface SilgiFunction {
|
|
1064
|
-
execute: <TURI extends keyof SilgiURIs>(uriString: TURI, input: ExtractInputFromURI<TURI>, source?: ExtractSourceFromURI<TURI>, queryParams?: Record<string, string>) => Promise<ExtractOutputFromURI<TURI>>;
|
|
1065
|
-
}
|
|
1066
|
-
interface BuildSilgi {
|
|
1067
|
-
framework: FrameworkContext;
|
|
1068
|
-
modules?: Partial<SilgiRuntimeOptions>;
|
|
1069
|
-
options?: Partial<SilgiOptions>;
|
|
1070
|
-
}
|
|
1071
|
-
|
|
1072
|
-
interface SilgiAppPlugin {
|
|
1073
|
-
(silgi: Silgi): Promise<void> | void;
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
|
-
interface CapturedErrorContext {
|
|
1077
|
-
event?: SilgiEvents;
|
|
1078
|
-
[key: string]: unknown;
|
|
1079
|
-
}
|
|
1080
|
-
type CaptureError = (silgi: Silgi, error: Error, context: CapturedErrorContext) => void;
|
|
1081
|
-
|
|
1082
|
-
/**
|
|
1083
|
-
* The listeners to Silgi
|
|
1084
|
-
*/
|
|
1085
|
-
interface SilgiRuntimeHooks {
|
|
1086
|
-
/**
|
|
1087
|
-
* Called after Silgi initialization, when the Silgi instance is ready to work.
|
|
1088
|
-
* @param silgi The configured Silgi object
|
|
1089
|
-
* @returns Promise
|
|
1090
|
-
*/
|
|
1091
|
-
'ready': (silgi: Silgi) => HookResult;
|
|
1092
|
-
/**
|
|
1093
|
-
* Called when silgi instance is gracefully closing.
|
|
1094
|
-
* @param silgi The configured silgi object
|
|
1095
|
-
* @returns Promise
|
|
1096
|
-
*/
|
|
1097
|
-
'close': (silgi: Silgi) => HookResult;
|
|
1098
|
-
'app:setup:start': (silgi: Silgi) => HookResult;
|
|
1099
|
-
'execute:before': (context: ModuleHookContext) => HookResult;
|
|
1100
|
-
'execute:after': (context: ModuleHookContext) => HookResult;
|
|
1101
|
-
'execute:error': (context: ModuleHookContext) => HookResult;
|
|
1102
|
-
'execute:finally': (context: ModuleHookContext) => HookResult;
|
|
1103
|
-
'event:init': (event: SilgiEvents, data: {
|
|
1104
|
-
path: string;
|
|
1105
|
-
queryParams?: Record<string, string>;
|
|
1106
|
-
operation: SilgiOperation;
|
|
1107
|
-
}) => HookResult;
|
|
1108
|
-
'error': CaptureError;
|
|
1109
|
-
}
|
|
1110
|
-
|
|
1111
|
-
interface SilgiRuntimeConfig {
|
|
1112
|
-
}
|
|
1113
|
-
interface SilgiOptions {
|
|
1114
|
-
consolaOptions?: Partial<ConsolaOptions>;
|
|
1115
|
-
routeRules: SilgiRouteRules;
|
|
1116
|
-
present: PresetNameInput;
|
|
1117
|
-
hooks: Partial<SilgiRuntimeHooks & DefaultHooks>;
|
|
1118
|
-
/**
|
|
1119
|
-
* Set to `true` to enable debug mode.
|
|
1120
|
-
*
|
|
1121
|
-
* At the moment, it prints out hook names and timings on the server, and logs hook arguments as well in the browser.
|
|
1122
|
-
*
|
|
1123
|
-
* @default false
|
|
1124
|
-
*/
|
|
1125
|
-
debug: boolean;
|
|
1126
|
-
storage: StorageMounts;
|
|
1127
|
-
putStorage?: Storage<StorageValue>;
|
|
1128
|
-
runtimeConfig: SilgiRuntimeConfig & {
|
|
1129
|
-
[key: string]: any;
|
|
1130
|
-
};
|
|
1131
|
-
captureError: CaptureError;
|
|
1132
|
-
adapters: Record<string, Adapter<Record<string, any>, TablesSchema, InferModelTypes<TablesSchema>>>;
|
|
1133
|
-
[key: string]: any;
|
|
1134
|
-
}
|
|
1135
|
-
|
|
1136
|
-
interface SilgiRuntimeContext extends Record<string, any> {
|
|
1137
|
-
}
|
|
1138
|
-
interface ExtendContext {
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
1070
|
interface DotenvOptions {
|
|
1142
1071
|
/**
|
|
1143
1072
|
* The project root directory (either absolute or relative to the current working directory).
|
|
@@ -1173,23 +1102,64 @@ interface GraphQLJSON {
|
|
|
1173
1102
|
references: any;
|
|
1174
1103
|
}
|
|
1175
1104
|
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
interface ServiceParse {
|
|
1185
|
-
node: ResolvedMethodHandlerType;
|
|
1186
|
-
basePath: string;
|
|
1187
|
-
silgi: SilgiCLI;
|
|
1188
|
-
modulesURIs: Record<string, Record<string, any>>;
|
|
1189
|
-
pathLength: number;
|
|
1105
|
+
/**
|
|
1106
|
+
* Main interface containing all route definitions.
|
|
1107
|
+
* Example:
|
|
1108
|
+
* {
|
|
1109
|
+
* "/api/blueSpace/basket/getBook": { ... }
|
|
1110
|
+
* }
|
|
1111
|
+
*/
|
|
1112
|
+
interface Routers {
|
|
1190
1113
|
}
|
|
1191
|
-
|
|
1192
|
-
|
|
1114
|
+
/**
|
|
1115
|
+
* Extracts the prefix (first segment) from a URL, including the leading slash.
|
|
1116
|
+
* @example ExtractPrefix<'/api/blueSpace/basket'> // '/api'
|
|
1117
|
+
*/
|
|
1118
|
+
type ExtractPrefix<URL extends string> = URL extends `/${infer Prefix}/${string}` ? `/${Prefix}` : never;
|
|
1119
|
+
/**
|
|
1120
|
+
* Extracts the namespace (second segment) from a URL, including the leading slash.
|
|
1121
|
+
* @example ExtractNamespace<'/api/blueSpace/basket'> // '/blueSpace'
|
|
1122
|
+
*/
|
|
1123
|
+
type ExtractNamespace<URL extends string> = URL extends `/${string}/${infer Namespace}/${string}` ? `/${Namespace}` : never;
|
|
1124
|
+
/**
|
|
1125
|
+
* Extracts the route (third and subsequent segments) from a URL, including the leading slash.
|
|
1126
|
+
* @example ExtractRoute<'/api/blueSpace/basket/getBook'> // '/basket/getBook'
|
|
1127
|
+
*/
|
|
1128
|
+
type ExtractRoute<URL extends string> = URL extends `/${string}/${string}/${infer Route}` ? `/${Route}` : never;
|
|
1129
|
+
/**
|
|
1130
|
+
* Gets all route keys from Routers as strings.
|
|
1131
|
+
* All keys should start with a leading slash.
|
|
1132
|
+
*/
|
|
1133
|
+
type RouterKeys = keyof Routers & string;
|
|
1134
|
+
/**
|
|
1135
|
+
* Extracts all prefixes (first segment) in the system, including the leading slash.
|
|
1136
|
+
* @example AllPrefixes // '/api' | ...
|
|
1137
|
+
*/
|
|
1138
|
+
type AllPrefixes = RouterKeys extends infer K ? K extends string ? ExtractPrefix<K> : never : never;
|
|
1139
|
+
/**
|
|
1140
|
+
* Extracts all namespaces (second segment) for a given prefix, including the leading slash.
|
|
1141
|
+
* @example NamespacesForPrefix<'/api'> // '/blueSpace' | ...
|
|
1142
|
+
*/
|
|
1143
|
+
type NamespacesForPrefix<P extends string> = RouterKeys extends infer K ? K extends string ? K extends `${P}/${infer N}/${string}` ? `/${N}` : never : never : never;
|
|
1144
|
+
/**
|
|
1145
|
+
* Extracts all routes (third and subsequent segments) for a given prefix and namespace, including the leading slash.
|
|
1146
|
+
* @example RoutesForPrefixAndNamespace<'/api', '/blueSpace'> // '/basket/getBook' | ...
|
|
1147
|
+
*/
|
|
1148
|
+
type RoutesForPrefixAndNamespace<P extends string, N extends string> = RouterKeys extends infer K ? K extends string ? K extends `${P}${N}${infer R}` ? `${R}` : never : never : never;
|
|
1149
|
+
/**
|
|
1150
|
+
* Extracts path parameter keys from a URL pattern string.
|
|
1151
|
+
*
|
|
1152
|
+
* @example
|
|
1153
|
+
* ExtractPathParamKeys<'/users/:id/posts/:postId'> // 'id' | 'postId'
|
|
1154
|
+
* ExtractPathParamKeys<'/users/:id?'> // 'id'
|
|
1155
|
+
*/
|
|
1156
|
+
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;
|
|
1157
|
+
/**
|
|
1158
|
+
* Route configuration interface.
|
|
1159
|
+
*/
|
|
1160
|
+
interface RouteConfig<T> {
|
|
1161
|
+
route: T;
|
|
1162
|
+
setup?: any;
|
|
1193
1163
|
}
|
|
1194
1164
|
|
|
1195
|
-
export type { AllPaths, AppConfig, Awaitable,
|
|
1165
|
+
export type { AllPaths, AllPrefixes, AppConfig, Awaitable, BaseSilgiMethodType, BuildSilgi, CaptureError, CapturedErrorContext, CommandType, Commands, CreateServiceParams, CustomRequestInit, DeepPartial, DeepRequired, DefaultHooks, DefaultNamespaces, DefineFrameworkOptions, DotenvOptions, EnvOptions, EventHandlerResponse, ExtendContext, ExtendShared, ExtractNamespace, ExtractPathParamKeys, ExtractPathParams, ExtractPrefix, ExtractRoute, FrameworkContext, GenImport, GenerateAppOptions, GraphQLJSON, HTTPMethod, HookResult, HttpMethod, LoadConfigOptions, MergeAll, MergeServiceDefinitions, MergedSilgiSchema, ModuleDefinition, ModuleHookContext, ModuleMeta, ModuleOptionsCustom, ModuleSetupInstallResult, ModuleSetupReturn, NamespacesForPrefix, NitroBuildInfo, RequiredServiceType, ResolvedModuleMeta, ResolvedModuleOptions, ResolvedSchemaDefinition, ResolvedSilgiTemplate, RouteConfig, RouterParams, Routers, RoutesForPrefixAndNamespace, ScanFile, Schema, SchemaDefinition, SchemaParams, ServiceDefinition, ServiceHandler, ServiceHandlerInput, ServiceHandlerOutput, ServiceHandlerSource, ServiceSetup, Silgi, SilgiAppPlugin, SilgiCLI, SilgiCLIConfig, SilgiCLIDynamicConfig, SilgiCLIHooks, SilgiCLIOptions, SilgiCommands, SilgiCompatibility, SilgiCompatibilityIssue, SilgiCompatibilityIssues, SilgiConfig, SilgiEvent, SilgiFetchClient, SilgiFetchOptions, SilgiFrameworkInfo, SilgiHooks, SilgiModule, SilgiModuleInput, SilgiModuleOptions, SilgiNamespaces, SilgiOptions, SilgiPreset, SilgiPresetMeta, SilgiRoute, SilgiRouterTypes, SilgiRuntimeActions, SilgiRuntimeConfig, SilgiRuntimeContext, SilgiRuntimeHooks, SilgiRuntimeMethods, SilgiRuntimeOptions, SilgiRuntimeShareds, SilgiRuntimeSharedsExtend, SilgiSchema, SilgiStorageBase, SilgiTemplate, SilgiURL, StorageConfig, StorageKeyGenerator, StorageKeyParams, StorageMounts, TSReference, TrimAfterFourSlashes };
|