silgi 0.37.23 → 0.37.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 +1 -5
- package/dist/cli/index.mjs +1 -1
- package/dist/runtime/internal/config.d.mts +2 -2
- package/dist/runtime/internal/config.mjs +30 -16
- package/dist/types/index.d.mts +177 -174
- package/package.json +1 -1
package/dist/cli/build.mjs
CHANGED
|
@@ -1641,17 +1641,13 @@ async function prepareConfigs(silgi) {
|
|
|
1641
1641
|
""
|
|
1642
1642
|
)}`,
|
|
1643
1643
|
"",
|
|
1644
|
-
"const
|
|
1644
|
+
"export const localRuntimeConfig = useSilgiRuntimeConfig(undefined, runtimeConfig)",
|
|
1645
1645
|
""
|
|
1646
1646
|
];
|
|
1647
1647
|
delete _data.runtimeConfig;
|
|
1648
1648
|
importData.push(`export const cliConfigs: Partial<SilgiRuntimeOptions & SilgiOptions> = ${genObjectFromRawEntries(
|
|
1649
1649
|
Object.entries(_data).map(
|
|
1650
1650
|
([key, value]) => [key, genEnsureSafeVar(value)]
|
|
1651
|
-
).concat(
|
|
1652
|
-
[
|
|
1653
|
-
["runtimeConfig", "runtime"]
|
|
1654
|
-
]
|
|
1655
1651
|
)
|
|
1656
1652
|
)}`);
|
|
1657
1653
|
importData.unshift(...baseHeaderBannerComment);
|
package/dist/cli/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { EnvOptions, SilgiEvent, SilgiRuntimeConfig } from 'silgi/types';
|
|
2
|
-
export declare function updateEnvOptions(): EnvOptions;
|
|
3
|
-
export declare function useSilgiRuntimeConfig<T extends SilgiRuntimeConfig>(event?: SilgiEvent): SilgiRuntimeConfig;
|
|
2
|
+
export declare function updateEnvOptions(runtime: SilgiRuntimeConfig): EnvOptions;
|
|
3
|
+
export declare function useSilgiRuntimeConfig<T extends SilgiRuntimeConfig>(event?: SilgiEvent, localRuntimeConfig?: SilgiRuntimeConfig): SilgiRuntimeConfig;
|
|
4
4
|
export declare function initRuntimeConfig(envOptions?: EnvOptions, inlineRuntimeConfig?: Record<string, any>): Readonly<Record<string, any>>;
|
|
5
5
|
export declare function updateRuntimeConfig(runtimeConfig: Record<string, unknown>): void;
|
|
6
6
|
export declare function applyEnv(obj: Record<string, any>, opts: EnvOptions, parentKey?: string): Record<string, any>;
|
|
@@ -3,44 +3,58 @@ import destr from "destr";
|
|
|
3
3
|
import { klona } from "klona";
|
|
4
4
|
import { snakeCase } from "scule";
|
|
5
5
|
import { asyncRuntimeStorage, useRuntime, useSilgi } from "silgi";
|
|
6
|
-
export function updateEnvOptions() {
|
|
7
|
-
const runtime = useRuntime();
|
|
6
|
+
export function updateEnvOptions(runtime) {
|
|
8
7
|
const envOptions = {
|
|
9
8
|
prefix: "NITRO_",
|
|
10
9
|
altPrefix: runtime?.silgi?.envPrefix ?? process.env.NITRO_ENV_PREFIX ?? "_",
|
|
11
10
|
silgiPrefix: "SILGI_",
|
|
12
11
|
envExpansion: runtime?.silgi?.envExpansion ?? process.env.NITRO_ENV_EXPANSION ?? false
|
|
13
12
|
};
|
|
14
|
-
const _sharedRuntimeConfig = _deepFreeze(
|
|
15
|
-
applyEnv(klona(runtime ?? {}), envOptions)
|
|
16
|
-
);
|
|
17
|
-
asyncRuntimeStorage.set(_sharedRuntimeConfig);
|
|
18
13
|
return envOptions;
|
|
19
14
|
}
|
|
20
|
-
|
|
15
|
+
let inlineRuntimeConfig;
|
|
16
|
+
function sharedRuntimeConfig(runtime) {
|
|
17
|
+
if (inlineRuntimeConfig) {
|
|
18
|
+
return inlineRuntimeConfig;
|
|
19
|
+
}
|
|
20
|
+
inlineRuntimeConfig = _deepFreeze(
|
|
21
|
+
applyEnv(klona(runtime ?? {}), updateEnvOptions(runtime))
|
|
22
|
+
);
|
|
23
|
+
if (asyncRuntimeStorage.tryUse()) {
|
|
24
|
+
asyncRuntimeStorage.unset();
|
|
25
|
+
asyncRuntimeStorage.set(inlineRuntimeConfig);
|
|
26
|
+
} else {
|
|
27
|
+
asyncRuntimeStorage.set(inlineRuntimeConfig);
|
|
28
|
+
}
|
|
29
|
+
return inlineRuntimeConfig;
|
|
30
|
+
}
|
|
31
|
+
export function useSilgiRuntimeConfig(event, localRuntimeConfig) {
|
|
32
|
+
if (localRuntimeConfig) {
|
|
33
|
+
return sharedRuntimeConfig(localRuntimeConfig);
|
|
34
|
+
}
|
|
21
35
|
const runtime = useRuntime();
|
|
22
36
|
if (!event) {
|
|
23
|
-
return runtime;
|
|
37
|
+
return sharedRuntimeConfig(runtime);
|
|
24
38
|
}
|
|
25
|
-
if (event.context.
|
|
26
|
-
return event.context.
|
|
39
|
+
if (event.context.silgi.runtimeConfig) {
|
|
40
|
+
return event.context.silgi.runtimeConfig;
|
|
27
41
|
}
|
|
28
42
|
const runtimeConfig = klona(runtime);
|
|
29
|
-
const envOptions = updateEnvOptions();
|
|
43
|
+
const envOptions = updateEnvOptions(runtime);
|
|
30
44
|
applyEnv(runtimeConfig, envOptions);
|
|
31
|
-
event.context.
|
|
45
|
+
event.context.silgi.runtimeConfig = runtimeConfig;
|
|
32
46
|
return runtimeConfig;
|
|
33
47
|
}
|
|
34
|
-
export function initRuntimeConfig(envOptions = {},
|
|
48
|
+
export function initRuntimeConfig(envOptions = {}, inlineRuntimeConfig2 = {}) {
|
|
35
49
|
const finalEnvOptions = {
|
|
36
50
|
prefix: "NITRO_",
|
|
37
|
-
altPrefix:
|
|
51
|
+
altPrefix: inlineRuntimeConfig2?.nitro?.envPrefix ?? process.env.NITRO_ENV_PREFIX ?? "_",
|
|
38
52
|
silgiPrefix: "SILGI_",
|
|
39
|
-
envExpansion:
|
|
53
|
+
envExpansion: inlineRuntimeConfig2?.nitro?.envExpansion ?? process.env.NITRO_ENV_EXPANSION ?? false,
|
|
40
54
|
...envOptions
|
|
41
55
|
};
|
|
42
56
|
return _deepFreeze(
|
|
43
|
-
applyEnv(klona(
|
|
57
|
+
applyEnv(klona(inlineRuntimeConfig2), finalEnvOptions)
|
|
44
58
|
);
|
|
45
59
|
}
|
|
46
60
|
export function updateRuntimeConfig(runtimeConfig) {
|
package/dist/types/index.d.mts
CHANGED
|
@@ -340,180 +340,6 @@ type SilgiFetchOptions<P extends AllPaths | (string & {}), BasePath extends keyo
|
|
|
340
340
|
} & Omit<FetchOptions, 'method' | 'body' | 'params'>;
|
|
341
341
|
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']>>;
|
|
342
342
|
|
|
343
|
-
interface SilgiAppPlugin {
|
|
344
|
-
(silgi: Silgi): Promise<void> | void;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
interface CapturedErrorContext {
|
|
348
|
-
event?: SilgiEvent;
|
|
349
|
-
[key: string]: unknown;
|
|
350
|
-
}
|
|
351
|
-
type CaptureError = (silgi: Silgi, error: Error, context: CapturedErrorContext) => void;
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* The listeners to Silgi
|
|
355
|
-
*/
|
|
356
|
-
interface SilgiRuntimeHooks {
|
|
357
|
-
/**
|
|
358
|
-
* Called after Silgi initialization, when the Silgi instance is ready to work.
|
|
359
|
-
* @param silgi The configured Silgi object
|
|
360
|
-
* @returns Promise
|
|
361
|
-
*/
|
|
362
|
-
'ready': (silgi: Silgi) => HookResult;
|
|
363
|
-
/**
|
|
364
|
-
* Called when silgi instance is gracefully closing.
|
|
365
|
-
* @param silgi The configured silgi object
|
|
366
|
-
* @returns Promise
|
|
367
|
-
*/
|
|
368
|
-
'close': (silgi: Silgi) => HookResult;
|
|
369
|
-
'request:on': (event: SilgiEvent) => HookResult;
|
|
370
|
-
'fetch:before': (context: ModuleHookContext) => HookResult;
|
|
371
|
-
'fetch:after': (context: ModuleHookContext) => HookResult;
|
|
372
|
-
'fetch:error': (context: ModuleHookContext) => HookResult;
|
|
373
|
-
'fetch:finally': (context: Omit<ModuleHookContext, 'event'>) => HookResult;
|
|
374
|
-
'error': CaptureError;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
type ServiceMethods<Schema extends SilgiSchema$1, Path extends keyof Schema, Resolved extends boolean = false, HiddenParameters extends boolean = false> = {
|
|
378
|
-
[M in keyof Schema[Path]]?: ServiceSetup<Schema, Path, M, Resolved, HiddenParameters>;
|
|
379
|
-
};
|
|
380
|
-
/**
|
|
381
|
-
* Yardımcı tipler
|
|
382
|
-
*/
|
|
383
|
-
type InferInput<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferInput<T> : unknown;
|
|
384
|
-
type InferOutput<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<T> : unknown;
|
|
385
|
-
type ServiceHandlerParameters<S, R extends keyof S, M extends keyof S[R]> = S[R][M] extends {
|
|
386
|
-
pathParams?: infer P;
|
|
387
|
-
} ? S[R][M] extends {
|
|
388
|
-
queryParams?: infer Q;
|
|
389
|
-
} ? (P extends undefined ? object : {
|
|
390
|
-
path: InferInput<P>;
|
|
391
|
-
}) & (Q extends undefined ? object : {
|
|
392
|
-
query: InferInput<Q>;
|
|
393
|
-
}) : (P extends undefined ? object : {
|
|
394
|
-
path: InferInput<P>;
|
|
395
|
-
}) : S[R][M] extends {
|
|
396
|
-
queryParams?: infer Q;
|
|
397
|
-
} ? (Q extends undefined ? object : {
|
|
398
|
-
query: InferInput<Q>;
|
|
399
|
-
}) : object;
|
|
400
|
-
/**
|
|
401
|
-
* Route ve method'a göre input, output, params çıkarımı
|
|
402
|
-
*/
|
|
403
|
-
type ServiceHandlerInput<Schema extends SilgiSchema$1, Route extends keyof Schema, Method extends keyof Schema[Route], HiddenParameters extends boolean = false> = (Schema[Route][Method] extends {
|
|
404
|
-
input?: infer I;
|
|
405
|
-
} ? {
|
|
406
|
-
args: InferInput<I>;
|
|
407
|
-
} : unknown) & (HiddenParameters extends false ? (keyof ServiceHandlerParameters<Schema, Route, Method> extends never ? unknown : {
|
|
408
|
-
parameters: ServiceHandlerParameters<Schema, Route, Method>;
|
|
409
|
-
}) : unknown);
|
|
410
|
-
type ServiceHandlerOutput<Schema extends SilgiSchema$1, Route extends keyof Schema, Method extends keyof Schema[Route]> = Schema[Route][Method] extends {
|
|
411
|
-
output?: infer O;
|
|
412
|
-
} ? InferOutput<O> : unknown;
|
|
413
|
-
type ServiceHandlerSource<Schema extends SilgiSchema$1, Route extends keyof Schema, Method extends keyof Schema[Route]> = Schema[Route][Method] extends {
|
|
414
|
-
source?: infer S;
|
|
415
|
-
} ? InferInput<S> : unknown;
|
|
416
|
-
/**
|
|
417
|
-
* Handler fonksiyon tipi
|
|
418
|
-
*
|
|
419
|
-
* Resolved = false -> handler(input, shared, event, source) // all required
|
|
420
|
-
* Resolved = true -> handler(input, shared?, event?, source?) // only input required
|
|
421
|
-
*/
|
|
422
|
-
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>>;
|
|
423
|
-
/**
|
|
424
|
-
* Servis setup tipi
|
|
425
|
-
*/
|
|
426
|
-
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> {
|
|
427
|
-
handler: ServiceHandler<Schema, Route, Method, Resolved, HiddenParameters>;
|
|
428
|
-
routerRule?: RouteConfigService$1;
|
|
429
|
-
modules?: Partial<SilgiRuntimeActions$1>;
|
|
430
|
-
storage?: StorageConfig$1<ServiceHandlerInput<Schema, Route, Method, HiddenParameters>>;
|
|
431
|
-
}
|
|
432
|
-
/**
|
|
433
|
-
* Represents a fully resolved service definition that maps route paths
|
|
434
|
-
* to their method handlers and configurations.
|
|
435
|
-
*
|
|
436
|
-
* This interface is designed to be compatible with the structure created
|
|
437
|
-
* by the createService function.
|
|
438
|
-
*/
|
|
439
|
-
interface ResolvedServiceDefinition {
|
|
440
|
-
[routePath: string]: {
|
|
441
|
-
[method: string]: {
|
|
442
|
-
handler: (...args: any[]) => Promise<any>;
|
|
443
|
-
modules?: Partial<SilgiRuntimeActions$1>;
|
|
444
|
-
storage?: StorageConfig$1<any>;
|
|
445
|
-
};
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
/**
|
|
449
|
-
* SilgiURL tipi
|
|
450
|
-
*/
|
|
451
|
-
interface SilgiURL {
|
|
452
|
-
namespaceName: string;
|
|
453
|
-
prefixName: string;
|
|
454
|
-
methodName: string;
|
|
455
|
-
path: string;
|
|
456
|
-
raw: string;
|
|
457
|
-
pathParams?: Record<string, string | undefined>;
|
|
458
|
-
queryParams?: Record<string, string>;
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
type CustomDriverName = string & {
|
|
462
|
-
_custom?: any;
|
|
463
|
-
};
|
|
464
|
-
interface StorageMounts {
|
|
465
|
-
[path: string]: {
|
|
466
|
-
driver: BuiltinDriverName | CustomDriverName;
|
|
467
|
-
[option: string]: any;
|
|
468
|
-
};
|
|
469
|
-
}
|
|
470
|
-
interface SilgiStorageBase {
|
|
471
|
-
}
|
|
472
|
-
type StorageKeyGenerator<TInput> = (input: TInput) => string | Promise<string>;
|
|
473
|
-
interface StorageConfig<TInput> {
|
|
474
|
-
options: TransactionOptions;
|
|
475
|
-
base: 'memory' | keyof SilgiStorageBase;
|
|
476
|
-
key?: StorageKeyGenerator<TInput>;
|
|
477
|
-
scope?: 'request' | 'global';
|
|
478
|
-
}
|
|
479
|
-
interface StorageKeyParams<TInput = unknown> {
|
|
480
|
-
url: SilgiURL;
|
|
481
|
-
input: TInput;
|
|
482
|
-
requestId?: string;
|
|
483
|
-
keyGenerator?: StorageKeyGenerator<TInput>;
|
|
484
|
-
storageOptions?: Pick<StorageConfig<TInput>, 'base' | 'options' | 'scope'>;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
interface SilgiRuntimeDefaultConfig {
|
|
488
|
-
silgi?: {
|
|
489
|
-
envPrefix?: string;
|
|
490
|
-
envExpansion?: boolean;
|
|
491
|
-
};
|
|
492
|
-
}
|
|
493
|
-
interface SilgiRuntimeConfig extends SilgiRuntimeDefaultConfig {
|
|
494
|
-
}
|
|
495
|
-
interface SilgiOptions {
|
|
496
|
-
consolaOptions?: Partial<ConsolaOptions>;
|
|
497
|
-
present: PresetNameInput;
|
|
498
|
-
hooks: Partial<SilgiRuntimeHooks & DefaultHooks>;
|
|
499
|
-
/**
|
|
500
|
-
* Set to `true` to enable debug mode.
|
|
501
|
-
*
|
|
502
|
-
* At the moment, it prints out hook names and timings on the server, and logs hook arguments as well in the browser.
|
|
503
|
-
*
|
|
504
|
-
* @default false
|
|
505
|
-
*/
|
|
506
|
-
debug: boolean;
|
|
507
|
-
storage: StorageMounts;
|
|
508
|
-
putStorage?: Storage<StorageValue>;
|
|
509
|
-
runtimeConfig: SilgiRuntimeConfig & {
|
|
510
|
-
[key: string]: any;
|
|
511
|
-
};
|
|
512
|
-
captureError: CaptureError;
|
|
513
|
-
adapters: Record<string, Adapter<Record<string, any>, TablesSchema, InferModelTypes<TablesSchema>>>;
|
|
514
|
-
[key: string]: any;
|
|
515
|
-
}
|
|
516
|
-
|
|
517
343
|
/**
|
|
518
344
|
* Main interface containing all route definitions.
|
|
519
345
|
* Example:
|
|
@@ -653,6 +479,116 @@ interface ResolvedSchemaDefinition {
|
|
|
653
479
|
};
|
|
654
480
|
}
|
|
655
481
|
|
|
482
|
+
type ServiceMethods<Schema extends SilgiSchema$1, Path extends keyof Schema, Resolved extends boolean = false, HiddenParameters extends boolean = false> = {
|
|
483
|
+
[M in keyof Schema[Path]]?: ServiceSetup<Schema, Path, M, Resolved, HiddenParameters>;
|
|
484
|
+
};
|
|
485
|
+
/**
|
|
486
|
+
* Yardımcı tipler
|
|
487
|
+
*/
|
|
488
|
+
type InferInput<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferInput<T> : unknown;
|
|
489
|
+
type InferOutput<T> = T extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<T> : unknown;
|
|
490
|
+
type ServiceHandlerParameters<S, R extends keyof S, M extends keyof S[R]> = S[R][M] extends {
|
|
491
|
+
pathParams?: infer P;
|
|
492
|
+
} ? S[R][M] extends {
|
|
493
|
+
queryParams?: infer Q;
|
|
494
|
+
} ? (P extends undefined ? object : {
|
|
495
|
+
path: InferInput<P>;
|
|
496
|
+
}) & (Q extends undefined ? object : {
|
|
497
|
+
query: InferInput<Q>;
|
|
498
|
+
}) : (P extends undefined ? object : {
|
|
499
|
+
path: InferInput<P>;
|
|
500
|
+
}) : S[R][M] extends {
|
|
501
|
+
queryParams?: infer Q;
|
|
502
|
+
} ? (Q extends undefined ? object : {
|
|
503
|
+
query: InferInput<Q>;
|
|
504
|
+
}) : object;
|
|
505
|
+
/**
|
|
506
|
+
* Route ve method'a göre input, output, params çıkarımı
|
|
507
|
+
*/
|
|
508
|
+
type ServiceHandlerInput<Schema extends SilgiSchema$1, Route extends keyof Schema, Method extends keyof Schema[Route], HiddenParameters extends boolean = false> = (Schema[Route][Method] extends {
|
|
509
|
+
input?: infer I;
|
|
510
|
+
} ? {
|
|
511
|
+
args: InferInput<I>;
|
|
512
|
+
} : unknown) & (HiddenParameters extends false ? (keyof ServiceHandlerParameters<Schema, Route, Method> extends never ? unknown : {
|
|
513
|
+
parameters: ServiceHandlerParameters<Schema, Route, Method>;
|
|
514
|
+
}) : unknown);
|
|
515
|
+
type ServiceHandlerOutput<Schema extends SilgiSchema$1, Route extends keyof Schema, Method extends keyof Schema[Route]> = Schema[Route][Method] extends {
|
|
516
|
+
output?: infer O;
|
|
517
|
+
} ? InferOutput<O> : unknown;
|
|
518
|
+
type ServiceHandlerSource<Schema extends SilgiSchema$1, Route extends keyof Schema, Method extends keyof Schema[Route]> = Schema[Route][Method] extends {
|
|
519
|
+
source?: infer S;
|
|
520
|
+
} ? InferInput<S> : unknown;
|
|
521
|
+
/**
|
|
522
|
+
* Handler fonksiyon tipi
|
|
523
|
+
*
|
|
524
|
+
* Resolved = false -> handler(input, shared, event, source) // all required
|
|
525
|
+
* Resolved = true -> handler(input, shared?, event?, source?) // only input required
|
|
526
|
+
*/
|
|
527
|
+
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>>;
|
|
528
|
+
/**
|
|
529
|
+
* Servis setup tipi
|
|
530
|
+
*/
|
|
531
|
+
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> {
|
|
532
|
+
handler: ServiceHandler<Schema, Route, Method, Resolved, HiddenParameters>;
|
|
533
|
+
routerRule?: RouteConfigService$1;
|
|
534
|
+
modules?: Partial<SilgiRuntimeActions$1>;
|
|
535
|
+
storage?: StorageConfig$1<ServiceHandlerInput<Schema, Route, Method, HiddenParameters>>;
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* Represents a fully resolved service definition that maps route paths
|
|
539
|
+
* to their method handlers and configurations.
|
|
540
|
+
*
|
|
541
|
+
* This interface is designed to be compatible with the structure created
|
|
542
|
+
* by the createService function.
|
|
543
|
+
*/
|
|
544
|
+
interface ResolvedServiceDefinition {
|
|
545
|
+
[routePath: string]: {
|
|
546
|
+
[method: string]: {
|
|
547
|
+
handler: (...args: any[]) => Promise<any>;
|
|
548
|
+
modules?: Partial<SilgiRuntimeActions$1>;
|
|
549
|
+
storage?: StorageConfig$1<any>;
|
|
550
|
+
};
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* SilgiURL tipi
|
|
555
|
+
*/
|
|
556
|
+
interface SilgiURL {
|
|
557
|
+
namespaceName: string;
|
|
558
|
+
prefixName: string;
|
|
559
|
+
methodName: string;
|
|
560
|
+
path: string;
|
|
561
|
+
raw: string;
|
|
562
|
+
pathParams?: Record<string, string | undefined>;
|
|
563
|
+
queryParams?: Record<string, string>;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
type CustomDriverName = string & {
|
|
567
|
+
_custom?: any;
|
|
568
|
+
};
|
|
569
|
+
interface StorageMounts {
|
|
570
|
+
[path: string]: {
|
|
571
|
+
driver: BuiltinDriverName | CustomDriverName;
|
|
572
|
+
[option: string]: any;
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
interface SilgiStorageBase {
|
|
576
|
+
}
|
|
577
|
+
type StorageKeyGenerator<TInput> = (input: TInput) => string | Promise<string>;
|
|
578
|
+
interface StorageConfig<TInput> {
|
|
579
|
+
options: TransactionOptions;
|
|
580
|
+
base: 'memory' | keyof SilgiStorageBase;
|
|
581
|
+
key?: StorageKeyGenerator<TInput>;
|
|
582
|
+
scope?: 'request' | 'global';
|
|
583
|
+
}
|
|
584
|
+
interface StorageKeyParams<TInput = unknown> {
|
|
585
|
+
url: SilgiURL;
|
|
586
|
+
input: TInput;
|
|
587
|
+
requestId?: string;
|
|
588
|
+
keyGenerator?: StorageKeyGenerator<TInput>;
|
|
589
|
+
storageOptions?: Pick<StorageConfig<TInput>, 'base' | 'options' | 'scope'>;
|
|
590
|
+
}
|
|
591
|
+
|
|
656
592
|
interface SilgiRuntimeShareds extends SilgiRuntimeSharedsExtend {
|
|
657
593
|
storage: <T extends StorageValue = StorageValue>(base: StorageConfig<T>['base']) => Storage<T>;
|
|
658
594
|
runtimeConfig: SilgiRuntimeConfig;
|
|
@@ -727,6 +663,70 @@ type CustomRequestInit<Schema extends SilgiSchema = SilgiSchema, Route extends k
|
|
|
727
663
|
pathParams?: unknown;
|
|
728
664
|
});
|
|
729
665
|
|
|
666
|
+
interface SilgiAppPlugin {
|
|
667
|
+
(silgi: Silgi): Promise<void> | void;
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
interface CapturedErrorContext {
|
|
671
|
+
event?: SilgiEvent;
|
|
672
|
+
[key: string]: unknown;
|
|
673
|
+
}
|
|
674
|
+
type CaptureError = (silgi: Silgi, error: Error, context: CapturedErrorContext) => void;
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* The listeners to Silgi
|
|
678
|
+
*/
|
|
679
|
+
interface SilgiRuntimeHooks {
|
|
680
|
+
/**
|
|
681
|
+
* Called after Silgi initialization, when the Silgi instance is ready to work.
|
|
682
|
+
* @param silgi The configured Silgi object
|
|
683
|
+
* @returns Promise
|
|
684
|
+
*/
|
|
685
|
+
'ready': (silgi: Silgi) => HookResult;
|
|
686
|
+
/**
|
|
687
|
+
* Called when silgi instance is gracefully closing.
|
|
688
|
+
* @param silgi The configured silgi object
|
|
689
|
+
* @returns Promise
|
|
690
|
+
*/
|
|
691
|
+
'close': (silgi: Silgi) => HookResult;
|
|
692
|
+
'request:on': (event: SilgiEvent) => HookResult;
|
|
693
|
+
'fetch:before': (context: ModuleHookContext) => HookResult;
|
|
694
|
+
'fetch:after': (context: ModuleHookContext) => HookResult;
|
|
695
|
+
'fetch:error': (context: ModuleHookContext) => HookResult;
|
|
696
|
+
'fetch:finally': (context: Omit<ModuleHookContext, 'event'>) => HookResult;
|
|
697
|
+
'error': CaptureError;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
interface SilgiRuntimeDefaultConfig {
|
|
701
|
+
silgi?: {
|
|
702
|
+
envPrefix?: string;
|
|
703
|
+
envExpansion?: boolean;
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
interface SilgiRuntimeConfig extends SilgiRuntimeDefaultConfig {
|
|
707
|
+
}
|
|
708
|
+
interface SilgiOptions {
|
|
709
|
+
consolaOptions?: Partial<ConsolaOptions>;
|
|
710
|
+
present: PresetNameInput;
|
|
711
|
+
hooks: Partial<SilgiRuntimeHooks & DefaultHooks>;
|
|
712
|
+
/**
|
|
713
|
+
* Set to `true` to enable debug mode.
|
|
714
|
+
*
|
|
715
|
+
* At the moment, it prints out hook names and timings on the server, and logs hook arguments as well in the browser.
|
|
716
|
+
*
|
|
717
|
+
* @default false
|
|
718
|
+
*/
|
|
719
|
+
debug: boolean;
|
|
720
|
+
storage: StorageMounts;
|
|
721
|
+
putStorage?: Storage<StorageValue>;
|
|
722
|
+
runtimeConfig: SilgiRuntimeConfig & {
|
|
723
|
+
[key: string]: any;
|
|
724
|
+
};
|
|
725
|
+
captureError: CaptureError;
|
|
726
|
+
adapters: Record<string, Adapter<Record<string, any>, TablesSchema, InferModelTypes<TablesSchema>>>;
|
|
727
|
+
[key: string]: any;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
730
|
interface ExtendContext {
|
|
731
731
|
}
|
|
732
732
|
interface SilgiRuntimeContext extends Record<string, any> {
|
|
@@ -740,6 +740,9 @@ interface SilgiRuntimeContext extends Record<string, any> {
|
|
|
740
740
|
sessions?: Record<string, Session>;
|
|
741
741
|
clientAddress?: string;
|
|
742
742
|
source?: any;
|
|
743
|
+
silgi: {
|
|
744
|
+
runtimeConfig?: SilgiRuntimeConfig;
|
|
745
|
+
};
|
|
743
746
|
}
|
|
744
747
|
/**
|
|
745
748
|
* Bu nitrojs, h3 event or request context.
|