silgi 0.0.14 → 0.1.2
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/README.md +31 -2
- package/dist/chunks/generate.mjs +1118 -844
- package/dist/cli/config.d.mts +1630 -16
- package/dist/cli/config.d.ts +1630 -16
- package/dist/cli/index.mjs +50 -40
- package/dist/ecosystem/nitro/module.d.mts +10 -0
- package/dist/ecosystem/nitro/module.d.ts +10 -0
- package/dist/ecosystem/nitro/module.mjs +65 -0
- package/dist/ecosystem/nitro/runtime/plugin.d.ts +3 -0
- package/dist/ecosystem/nitro/runtime/plugin.mjs +2 -0
- package/dist/index.d.mts +147 -29
- package/dist/index.d.ts +147 -29
- package/dist/index.mjs +464 -6
- package/dist/shared/silgi.BaeZYxPa.d.mts +871 -0
- package/dist/shared/silgi.BaeZYxPa.d.ts +871 -0
- package/dist/shared/silgi.CbXGs1ur.mjs +317 -0
- package/dist/shared/silgi.KTm2r-Fb.mjs +25 -0
- package/dist/shared/silgi.wK7ZsagJ.mjs +484 -0
- package/package.json +48 -39
- package/dist/plugins/openapi.d.mts +0 -138
- package/dist/plugins/openapi.d.ts +0 -138
- package/dist/plugins/openapi.mjs +0 -204
- package/dist/plugins/scalar.d.mts +0 -14
- package/dist/plugins/scalar.d.ts +0 -14
- package/dist/plugins/scalar.mjs +0 -66
- package/dist/shared/silgi.BMCYk2cR.mjs +0 -841
- package/dist/shared/silgi.D5qK9QOm.d.mts +0 -301
- package/dist/shared/silgi.D5qK9QOm.d.ts +0 -301
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
import { ConsolaInstance, ConsolaOptions } from 'consola';
|
|
2
|
-
import { Router } from 'h3';
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
import { Hookable } from 'hookable';
|
|
5
|
-
|
|
6
|
-
interface DefaultContext {
|
|
7
|
-
requestId?: string;
|
|
8
|
-
}
|
|
9
|
-
interface DefaultInterface {
|
|
10
|
-
}
|
|
11
|
-
interface DefaultHooks {
|
|
12
|
-
}
|
|
13
|
-
type SilgiDefaultContext<T = DefaultContext> = T & DefaultContext;
|
|
14
|
-
type SilgiDefaultInterface<T = DefaultInterface> = T & DefaultInterface;
|
|
15
|
-
type SchemaGenerated<T> = {
|
|
16
|
-
[K in keyof T]: {
|
|
17
|
-
input: z.ZodType<any>;
|
|
18
|
-
output: z.ZodType<any>;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
type ServiceScope<T> = keyof ExtractScope<T> & string;
|
|
23
|
-
type GetScopes<T> = ServiceScope<T>;
|
|
24
|
-
type GetServiceNames<T, TScope extends ServiceScope<T>> = keyof ExtractScope<T>[TScope] & string;
|
|
25
|
-
type PluginHookContext<TContext extends DefaultContext, TInterface extends DefaultInterface> = Readonly<{
|
|
26
|
-
initSilgi: InitSilgi<TContext, TInterface>;
|
|
27
|
-
requestContext?: TContext;
|
|
28
|
-
scope: GetScopes<TInterface>;
|
|
29
|
-
serviceName: GetServiceNames<TInterface, GetScopes<TInterface>>;
|
|
30
|
-
methodName: string;
|
|
31
|
-
input: unknown;
|
|
32
|
-
result?: unknown;
|
|
33
|
-
options?: ServiceHandlerOptions<any, TInterface>;
|
|
34
|
-
timestamp?: number;
|
|
35
|
-
meta?: Record<string, unknown>;
|
|
36
|
-
error?: Error;
|
|
37
|
-
hookName?: string;
|
|
38
|
-
success?: boolean;
|
|
39
|
-
}>;
|
|
40
|
-
type PluginPriority = 'HIGHEST' | 'HIGH' | 'NORMAL' | 'LOW' | 'LOWEST';
|
|
41
|
-
interface PergelPlugin<TContext extends DefaultContext = DefaultContext, TInterface extends DefaultInterface = DefaultInterface, TPluginConfig = any> {
|
|
42
|
-
readonly name: keyof ExtractPluginConfig<TInterface> | string;
|
|
43
|
-
readonly system?: {
|
|
44
|
-
context?: boolean;
|
|
45
|
-
shared?: boolean;
|
|
46
|
-
services?: boolean;
|
|
47
|
-
methodConfig?: boolean;
|
|
48
|
-
moduleConfig?: boolean;
|
|
49
|
-
};
|
|
50
|
-
readonly priority?: PluginPriority;
|
|
51
|
-
readonly dependencies?: ReadonlyArray<keyof ExtractPluginConfig<TInterface>>;
|
|
52
|
-
defaults?: TPluginConfig;
|
|
53
|
-
readonly setup: (options: TPluginConfig, silgi: InitSilgi<TContext, TInterface>) => Promise<void> | void;
|
|
54
|
-
}
|
|
55
|
-
type ExtractPluginConfig<T> = T extends {
|
|
56
|
-
plugins: infer P;
|
|
57
|
-
} ? P : never;
|
|
58
|
-
interface BasePluginConfig {
|
|
59
|
-
active?: boolean;
|
|
60
|
-
}
|
|
61
|
-
type PluginConfiguration<TInterface extends DefaultInterface, K extends keyof ExtractPluginConfig<TInterface> = keyof ExtractPluginConfig<TInterface>> = ExtractPluginConfig<TInterface>[K] & BasePluginConfig;
|
|
62
|
-
type PluginConfigurations<TInterface extends DefaultInterface> = {
|
|
63
|
-
[K in keyof ExtractPluginConfig<TInterface>]?: PluginConfiguration<TInterface, K>;
|
|
64
|
-
};
|
|
65
|
-
type MethodPluginConfig<TInterface extends DefaultInterface> = PluginConfigurations<TInterface>;
|
|
66
|
-
interface ServicePluginConfig<TInterface extends DefaultInterface> {
|
|
67
|
-
plugins?: PluginConfigurations<TInterface>;
|
|
68
|
-
methodPlugins?: Record<string, MethodPluginConfig<TInterface>>;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
type HookResult = Promise<void> | void;
|
|
72
|
-
/**
|
|
73
|
-
* The listeners to Silgi
|
|
74
|
-
*/
|
|
75
|
-
interface SilgiHooks<TContext extends DefaultContext, TInterface extends DefaultInterface> {
|
|
76
|
-
/**
|
|
77
|
-
* Called after Silgi initialization, when the Silgi instance is ready to work.
|
|
78
|
-
* @param silgi The configured Silgi object
|
|
79
|
-
* @returns Promise
|
|
80
|
-
*/
|
|
81
|
-
'ready': (silgi: Silgi<TContext, TInterface>) => HookResult;
|
|
82
|
-
/**
|
|
83
|
-
* Called when silgi instance is gracefully closing.
|
|
84
|
-
* @param silgi The configured silgi object
|
|
85
|
-
* @returns Promise
|
|
86
|
-
*/
|
|
87
|
-
'close': (silgi: Silgi<TContext, TInterface>) => HookResult;
|
|
88
|
-
'app:setup:start': (silgi: InitSilgi<TContext, TInterface>) => HookResult;
|
|
89
|
-
'app:error': (context: PluginHookContext<TContext, TInterface>) => HookResult;
|
|
90
|
-
'app:finalize': (context: PluginHookContext<TContext, TInterface>) => HookResult;
|
|
91
|
-
'service:beforeExecute': (context: PluginHookContext<TContext, TInterface>) => HookResult;
|
|
92
|
-
'service:afterExecute': (context: PluginHookContext<TContext, TInterface>) => HookResult;
|
|
93
|
-
'plugin:register:before': (plugin: PergelPlugin<TContext, TInterface, any> | Array<PergelPlugin<TContext, TInterface, any>>) => HookResult;
|
|
94
|
-
'plugin:register:after': (plugin: PergelPlugin<TContext, TInterface, any> | Array<PergelPlugin<TContext, TInterface, any>>) => HookResult;
|
|
95
|
-
'request:context': (context: TContext) => HookResult;
|
|
96
|
-
'plugin:setup:finish': ({ plugin, initSilgi, }: {
|
|
97
|
-
plugin: PergelPlugin<TContext, TInterface, any>;
|
|
98
|
-
initSilgi: PluginHookContext<TContext, TInterface>['initSilgi'];
|
|
99
|
-
}) => HookResult;
|
|
100
|
-
'h3:app:setup': (router: Router) => HookResult;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
interface Silgi<TContext extends DefaultContext, TInterface extends DefaultInterface> {
|
|
104
|
-
_version: string;
|
|
105
|
-
hooks: Hookable<SilgiHooks<TContext, TInterface> & DefaultHooks>;
|
|
106
|
-
hooksNames: string[];
|
|
107
|
-
hook: Silgi<TContext, TInterface>['hooks']['hook'];
|
|
108
|
-
callHook: Silgi<TContext, TInterface>['hooks']['callHook'];
|
|
109
|
-
addHooks: Silgi<TContext, TInterface>['hooks']['addHooks'];
|
|
110
|
-
ready: () => Promise<void>;
|
|
111
|
-
close: () => Promise<void>;
|
|
112
|
-
logger: ConsolaInstance;
|
|
113
|
-
options: SilgiOptions<TContext, TInterface>;
|
|
114
|
-
h3Router?: Router;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
interface CreateScope<TContext extends DefaultContext, TInterface extends DefaultInterface> {
|
|
118
|
-
<TScope extends GetScopes<TInterface>>(scope: TScope): {
|
|
119
|
-
service: <TServiceName extends GetServiceNames<TInterface, TScope>>(serviceName: TServiceName) => {
|
|
120
|
-
execute: <TMethodName extends keyof ExtractScope<TInterface>[TScope][TServiceName]>(methodName: TMethodName, input: ExtractScope<TInterface>[TScope][TServiceName][TMethodName] extends ServiceMethod<infer TInput, any> ? TInput : never, context?: TContext) => ServiceMethodResult<ExtractScope<TInterface>[TScope][TServiceName][TMethodName]>;
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
type InitializedCreateScope<TContext extends DefaultContext, TInterface extends DefaultInterface> = CreateScope<TContext & DefaultContext, TInterface & DefaultInterface>;
|
|
125
|
-
|
|
126
|
-
declare class InitSilgi<TContext extends DefaultContext, TInterface extends DefaultInterface> {
|
|
127
|
-
silgi: Silgi<TContext, TInterface>;
|
|
128
|
-
constructor(silgi: Silgi<TContext, TInterface>);
|
|
129
|
-
createCacheProvider<TContext extends DefaultContext, TInterface extends DefaultInterface>(cacheOptions?: SilgiOptions<TContext, TInterface>['cache'], context?: TContext): CacheProvider;
|
|
130
|
-
private log;
|
|
131
|
-
use(plugin: PergelPlugin<TContext, TInterface, any> | Array<PergelPlugin<TContext, TInterface, any>>): Promise<void>;
|
|
132
|
-
getService<TScope extends keyof ExtractScope<TInterface>, TScopedService extends keyof ExtractScope<TInterface>[TScope]>(scope: TScope, name: TScopedService): ServiceExecutor<ExtractScope<TInterface>[TScope][TScopedService], TContext, TInterface>;
|
|
133
|
-
listScopes(): Array<GetScopes<TInterface>>;
|
|
134
|
-
getScope<TScope extends GetScopes<TInterface>>(scope: TScope): {
|
|
135
|
-
name: Array<GetServiceNames<TInterface, TScope>>;
|
|
136
|
-
scope: string;
|
|
137
|
-
};
|
|
138
|
-
getScopeServices<TScope extends GetScopes<TInterface>>(scope: TScope): {
|
|
139
|
-
services: Array<ExtractServiceNames<TInterface, TScope>>;
|
|
140
|
-
scope: TScope;
|
|
141
|
-
methods: {
|
|
142
|
-
[K in ExtractServiceNames<TInterface, TScope>]: Array<keyof ExtractScope<TInterface>[TScope][K]>;
|
|
143
|
-
};
|
|
144
|
-
};
|
|
145
|
-
getAllServices(): {
|
|
146
|
-
[TScope in GetScopes<TInterface>]: {
|
|
147
|
-
services: Array<ExtractServiceNames<TInterface, TScope>>;
|
|
148
|
-
scope: TScope;
|
|
149
|
-
methods: {
|
|
150
|
-
[K in ExtractServiceNames<TInterface, TScope>]: Array<keyof ExtractScope<TInterface>[TScope][K]>;
|
|
151
|
-
};
|
|
152
|
-
};
|
|
153
|
-
};
|
|
154
|
-
scope<TScope extends keyof ExtractScope<TInterface>>(scope: TScope, context: TContext): {
|
|
155
|
-
service: <TServiceName extends keyof ExtractScope<TInterface>[TScope]>(serviceName: TServiceName) => {
|
|
156
|
-
execute: <TMethodName extends keyof ExtractScope<TInterface>[TScope][TServiceName]>(methodName: TMethodName, input: ExtractScope<TInterface>[TScope][TServiceName][TMethodName] extends ServiceMethod<infer TInput, any> ? TInput : never) => ServiceMethodResult<ExtractScope<TInterface>[TScope][TServiceName][TMethodName]>;
|
|
157
|
-
};
|
|
158
|
-
};
|
|
159
|
-
getFromCache(key: string): Promise<any | null>;
|
|
160
|
-
setInCache(key: string, value: any, ttl: number): Promise<void>;
|
|
161
|
-
getServiceRegistryEntries(): [string, ServiceExecutor<any, TContext, TInterface>][];
|
|
162
|
-
createScope(context: TContext): CreateScope<TContext & DefaultContext, TInterface & DefaultInterface>;
|
|
163
|
-
setEvent(key: string, value: any): void;
|
|
164
|
-
getEvent(key: string): any;
|
|
165
|
-
buidApp(): Promise<void>;
|
|
166
|
-
addH3App(router: Router): Promise<void>;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
declare class PluginManager<TContext extends DefaultContext, TInterface extends DefaultInterface> {
|
|
170
|
-
private readonly silgi;
|
|
171
|
-
private readonly plugins;
|
|
172
|
-
private pluginPriorities;
|
|
173
|
-
constructor(silgi: InitSilgi<TContext, TInterface>);
|
|
174
|
-
private log;
|
|
175
|
-
register(plugin: PergelPlugin<TContext, TInterface, any>): void;
|
|
176
|
-
private calculatePluginPriorities;
|
|
177
|
-
runSetupHook(): Promise<void>;
|
|
178
|
-
runHook(hookName: keyof SilgiHooks<TContext, TInterface>, context: PluginHookContext<TContext, TInterface>): Promise<void>;
|
|
179
|
-
executePluginHook(plugin: PergelPlugin<TContext, TInterface, any>, hookName: keyof SilgiHooks<TContext, TInterface>, context: PluginHookContext<TContext, TInterface>): Promise<void>;
|
|
180
|
-
private handlePluginError;
|
|
181
|
-
getPlugin(name: string): Promise<PergelPlugin<TContext, TInterface, any> | undefined>;
|
|
182
|
-
isPluginsRegistered(): boolean;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
type MethodIdentifier = string | symbol;
|
|
186
|
-
type ServiceIdentifier = string;
|
|
187
|
-
type ScopeIdentifier = string;
|
|
188
|
-
type ExtractShared<T> = T extends {
|
|
189
|
-
shared: infer P;
|
|
190
|
-
} ? P extends object ? P : never : never;
|
|
191
|
-
type ExtractScope<T> = T extends {
|
|
192
|
-
scopes: infer S;
|
|
193
|
-
} ? S : never;
|
|
194
|
-
type SilgiContext<TContext extends DefaultContext, TInterface extends DefaultInterface> = {
|
|
195
|
-
_context: TContext;
|
|
196
|
-
silgi: InitSilgi<TContext, TInterface>;
|
|
197
|
-
scope?: ScopeIdentifier;
|
|
198
|
-
serviceName?: ServiceIdentifier;
|
|
199
|
-
methodName?: MethodIdentifier;
|
|
200
|
-
};
|
|
201
|
-
interface ServiceMethod<TInput = unknown, TOutput = unknown, TInterface extends DefaultInterface = DefaultInterface> {
|
|
202
|
-
input: TInput;
|
|
203
|
-
output: TOutput;
|
|
204
|
-
plugins?: PluginConfigurations<TInterface>;
|
|
205
|
-
}
|
|
206
|
-
type CacheScope = 'request' | 'global';
|
|
207
|
-
type CacheProviderType = 'memory' | 'file' | 'custom';
|
|
208
|
-
type CacheKeyGenerator<TInput> = (input: TInput) => string | Promise<string>;
|
|
209
|
-
interface CacheConfig<TInput> {
|
|
210
|
-
ttl: number;
|
|
211
|
-
scope: CacheScope;
|
|
212
|
-
key?: CacheKeyGenerator<TInput>;
|
|
213
|
-
namespace?: string;
|
|
214
|
-
}
|
|
215
|
-
interface SecurityOptions {
|
|
216
|
-
rateLimit?: {
|
|
217
|
-
windowMs: number;
|
|
218
|
-
max: number;
|
|
219
|
-
};
|
|
220
|
-
timeout?: number;
|
|
221
|
-
maxPayloadSize?: number;
|
|
222
|
-
allowedOrigins?: string[];
|
|
223
|
-
}
|
|
224
|
-
interface ServiceHandlerOptions<TInput, TInterface extends DefaultInterface> {
|
|
225
|
-
security?: SecurityOptions;
|
|
226
|
-
cache?: CacheConfig<TInput>;
|
|
227
|
-
plugins?: PluginConfigurations<TInterface>;
|
|
228
|
-
}
|
|
229
|
-
interface ServiceHandler<TInput, TOutput, TContext, TInterface extends DefaultInterface> {
|
|
230
|
-
handler: (input: TInput, shared: ExtractShared<TInterface>, context: TContext) => Promise<TOutput>;
|
|
231
|
-
options?: ServiceHandlerOptions<TInput, TInterface>;
|
|
232
|
-
_input?: TInput;
|
|
233
|
-
_output?: TOutput;
|
|
234
|
-
}
|
|
235
|
-
type ServiceResponse<T> = {
|
|
236
|
-
success: true;
|
|
237
|
-
data: T;
|
|
238
|
-
cached?: boolean;
|
|
239
|
-
} | {
|
|
240
|
-
success: false;
|
|
241
|
-
error: {
|
|
242
|
-
code: string;
|
|
243
|
-
message: string;
|
|
244
|
-
details?: Record<string, unknown>;
|
|
245
|
-
};
|
|
246
|
-
};
|
|
247
|
-
type ServiceMethodResult<T> = Promise<ServiceResponse<T extends ServiceMethod<any, infer O> ? O : never>>;
|
|
248
|
-
interface CacheProvider {
|
|
249
|
-
get: (key: string) => Promise<any | null>;
|
|
250
|
-
set: (key: string, value: any, ttl: number) => Promise<void>;
|
|
251
|
-
delete: (key: string) => Promise<void>;
|
|
252
|
-
clear: () => Promise<void>;
|
|
253
|
-
}
|
|
254
|
-
interface CacheProviderOptions<TContext> {
|
|
255
|
-
memory?: {
|
|
256
|
-
maxSize?: number;
|
|
257
|
-
object?: TContext;
|
|
258
|
-
};
|
|
259
|
-
file?: {
|
|
260
|
-
dir?: string;
|
|
261
|
-
prefix?: string;
|
|
262
|
-
object?: TContext;
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
interface SilgiOptions<TContext extends DefaultContext, TInterface extends DefaultInterface> {
|
|
266
|
-
_cacheProvider: CacheProvider;
|
|
267
|
-
_serviceRegistry: Map<string, ServiceExecutor<any, TContext, TInterface>>;
|
|
268
|
-
_pluginManager: PluginManager<TContext, TInterface>;
|
|
269
|
-
_eventContext?: Map<string, SilgiContext<TContext, TInterface>>;
|
|
270
|
-
services: Array<ServiceExecutor<any, TContext, TInterface>>;
|
|
271
|
-
shared: ExtractShared<TInterface>;
|
|
272
|
-
cache?: {
|
|
273
|
-
type?: CacheProviderType;
|
|
274
|
-
provider?: CacheProvider | ((object?: TContext) => CacheProvider);
|
|
275
|
-
options?: CacheProviderOptions<TContext>;
|
|
276
|
-
};
|
|
277
|
-
debug?: boolean;
|
|
278
|
-
consolaOptions?: Partial<ConsolaOptions>;
|
|
279
|
-
h3Router?: Router;
|
|
280
|
-
plugins?: PergelPlugin<TContext, TInterface, any> | Array<PergelPlugin<TContext, TInterface, any>>;
|
|
281
|
-
}
|
|
282
|
-
type OmitSilgiOptions<TContext extends DefaultContext, TInterface extends DefaultInterface> = Omit<SilgiOptions<TContext, TInterface>, '_cacheProvider' | '_serviceRegistry' | '_pluginManager' | 'shared'> & {
|
|
283
|
-
shared?: Partial<ExtractShared<TInterface>>;
|
|
284
|
-
};
|
|
285
|
-
interface ServiceExecutor<TService, TContext extends DefaultContext, TInterface extends DefaultInterface> {
|
|
286
|
-
scope: ScopeIdentifier;
|
|
287
|
-
name: ServiceIdentifier;
|
|
288
|
-
handlers: Map<MethodIdentifier, ServiceHandler<any, any, any, TInterface>>;
|
|
289
|
-
plugins?: PluginConfigurations<TInterface>;
|
|
290
|
-
methodPlugins?: Record<string, Record<string, any>>;
|
|
291
|
-
execute: <K extends keyof TService>(methodName: K, input: TService[K] extends ServiceMethod<infer I, any> ? I : never, context: {
|
|
292
|
-
initSilgi: InitSilgi<TContext, TInterface>;
|
|
293
|
-
requestContext: TContext;
|
|
294
|
-
scope: ScopeIdentifier;
|
|
295
|
-
serviceName: ServiceIdentifier;
|
|
296
|
-
methodName: MethodIdentifier;
|
|
297
|
-
}) => ServiceMethodResult<TService[K]>;
|
|
298
|
-
}
|
|
299
|
-
type ExtractServiceNames<TInterface extends DefaultInterface, TScope extends keyof ExtractScope<TInterface>> = keyof ExtractScope<TInterface>[TScope] & string;
|
|
300
|
-
|
|
301
|
-
export { type CacheScope as C, type DefaultContext as D, type ExtractScope as E, InitSilgi as I, type MethodPluginConfig as M, type OmitSilgiOptions as O, type PergelPlugin as P, type ServicePluginConfig as S, type DefaultInterface as a, type ServiceMethod as b, type ExtractShared as c, type CacheKeyGenerator as d, type ServiceExecutor as e, type Silgi as f, type InitializedCreateScope as g, type DefaultHooks as h, type SilgiDefaultContext as i, type SilgiDefaultInterface as j, type SchemaGenerated as k };
|
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
import { ConsolaInstance, ConsolaOptions } from 'consola';
|
|
2
|
-
import { Router } from 'h3';
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
import { Hookable } from 'hookable';
|
|
5
|
-
|
|
6
|
-
interface DefaultContext {
|
|
7
|
-
requestId?: string;
|
|
8
|
-
}
|
|
9
|
-
interface DefaultInterface {
|
|
10
|
-
}
|
|
11
|
-
interface DefaultHooks {
|
|
12
|
-
}
|
|
13
|
-
type SilgiDefaultContext<T = DefaultContext> = T & DefaultContext;
|
|
14
|
-
type SilgiDefaultInterface<T = DefaultInterface> = T & DefaultInterface;
|
|
15
|
-
type SchemaGenerated<T> = {
|
|
16
|
-
[K in keyof T]: {
|
|
17
|
-
input: z.ZodType<any>;
|
|
18
|
-
output: z.ZodType<any>;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
type ServiceScope<T> = keyof ExtractScope<T> & string;
|
|
23
|
-
type GetScopes<T> = ServiceScope<T>;
|
|
24
|
-
type GetServiceNames<T, TScope extends ServiceScope<T>> = keyof ExtractScope<T>[TScope] & string;
|
|
25
|
-
type PluginHookContext<TContext extends DefaultContext, TInterface extends DefaultInterface> = Readonly<{
|
|
26
|
-
initSilgi: InitSilgi<TContext, TInterface>;
|
|
27
|
-
requestContext?: TContext;
|
|
28
|
-
scope: GetScopes<TInterface>;
|
|
29
|
-
serviceName: GetServiceNames<TInterface, GetScopes<TInterface>>;
|
|
30
|
-
methodName: string;
|
|
31
|
-
input: unknown;
|
|
32
|
-
result?: unknown;
|
|
33
|
-
options?: ServiceHandlerOptions<any, TInterface>;
|
|
34
|
-
timestamp?: number;
|
|
35
|
-
meta?: Record<string, unknown>;
|
|
36
|
-
error?: Error;
|
|
37
|
-
hookName?: string;
|
|
38
|
-
success?: boolean;
|
|
39
|
-
}>;
|
|
40
|
-
type PluginPriority = 'HIGHEST' | 'HIGH' | 'NORMAL' | 'LOW' | 'LOWEST';
|
|
41
|
-
interface PergelPlugin<TContext extends DefaultContext = DefaultContext, TInterface extends DefaultInterface = DefaultInterface, TPluginConfig = any> {
|
|
42
|
-
readonly name: keyof ExtractPluginConfig<TInterface> | string;
|
|
43
|
-
readonly system?: {
|
|
44
|
-
context?: boolean;
|
|
45
|
-
shared?: boolean;
|
|
46
|
-
services?: boolean;
|
|
47
|
-
methodConfig?: boolean;
|
|
48
|
-
moduleConfig?: boolean;
|
|
49
|
-
};
|
|
50
|
-
readonly priority?: PluginPriority;
|
|
51
|
-
readonly dependencies?: ReadonlyArray<keyof ExtractPluginConfig<TInterface>>;
|
|
52
|
-
defaults?: TPluginConfig;
|
|
53
|
-
readonly setup: (options: TPluginConfig, silgi: InitSilgi<TContext, TInterface>) => Promise<void> | void;
|
|
54
|
-
}
|
|
55
|
-
type ExtractPluginConfig<T> = T extends {
|
|
56
|
-
plugins: infer P;
|
|
57
|
-
} ? P : never;
|
|
58
|
-
interface BasePluginConfig {
|
|
59
|
-
active?: boolean;
|
|
60
|
-
}
|
|
61
|
-
type PluginConfiguration<TInterface extends DefaultInterface, K extends keyof ExtractPluginConfig<TInterface> = keyof ExtractPluginConfig<TInterface>> = ExtractPluginConfig<TInterface>[K] & BasePluginConfig;
|
|
62
|
-
type PluginConfigurations<TInterface extends DefaultInterface> = {
|
|
63
|
-
[K in keyof ExtractPluginConfig<TInterface>]?: PluginConfiguration<TInterface, K>;
|
|
64
|
-
};
|
|
65
|
-
type MethodPluginConfig<TInterface extends DefaultInterface> = PluginConfigurations<TInterface>;
|
|
66
|
-
interface ServicePluginConfig<TInterface extends DefaultInterface> {
|
|
67
|
-
plugins?: PluginConfigurations<TInterface>;
|
|
68
|
-
methodPlugins?: Record<string, MethodPluginConfig<TInterface>>;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
type HookResult = Promise<void> | void;
|
|
72
|
-
/**
|
|
73
|
-
* The listeners to Silgi
|
|
74
|
-
*/
|
|
75
|
-
interface SilgiHooks<TContext extends DefaultContext, TInterface extends DefaultInterface> {
|
|
76
|
-
/**
|
|
77
|
-
* Called after Silgi initialization, when the Silgi instance is ready to work.
|
|
78
|
-
* @param silgi The configured Silgi object
|
|
79
|
-
* @returns Promise
|
|
80
|
-
*/
|
|
81
|
-
'ready': (silgi: Silgi<TContext, TInterface>) => HookResult;
|
|
82
|
-
/**
|
|
83
|
-
* Called when silgi instance is gracefully closing.
|
|
84
|
-
* @param silgi The configured silgi object
|
|
85
|
-
* @returns Promise
|
|
86
|
-
*/
|
|
87
|
-
'close': (silgi: Silgi<TContext, TInterface>) => HookResult;
|
|
88
|
-
'app:setup:start': (silgi: InitSilgi<TContext, TInterface>) => HookResult;
|
|
89
|
-
'app:error': (context: PluginHookContext<TContext, TInterface>) => HookResult;
|
|
90
|
-
'app:finalize': (context: PluginHookContext<TContext, TInterface>) => HookResult;
|
|
91
|
-
'service:beforeExecute': (context: PluginHookContext<TContext, TInterface>) => HookResult;
|
|
92
|
-
'service:afterExecute': (context: PluginHookContext<TContext, TInterface>) => HookResult;
|
|
93
|
-
'plugin:register:before': (plugin: PergelPlugin<TContext, TInterface, any> | Array<PergelPlugin<TContext, TInterface, any>>) => HookResult;
|
|
94
|
-
'plugin:register:after': (plugin: PergelPlugin<TContext, TInterface, any> | Array<PergelPlugin<TContext, TInterface, any>>) => HookResult;
|
|
95
|
-
'request:context': (context: TContext) => HookResult;
|
|
96
|
-
'plugin:setup:finish': ({ plugin, initSilgi, }: {
|
|
97
|
-
plugin: PergelPlugin<TContext, TInterface, any>;
|
|
98
|
-
initSilgi: PluginHookContext<TContext, TInterface>['initSilgi'];
|
|
99
|
-
}) => HookResult;
|
|
100
|
-
'h3:app:setup': (router: Router) => HookResult;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
interface Silgi<TContext extends DefaultContext, TInterface extends DefaultInterface> {
|
|
104
|
-
_version: string;
|
|
105
|
-
hooks: Hookable<SilgiHooks<TContext, TInterface> & DefaultHooks>;
|
|
106
|
-
hooksNames: string[];
|
|
107
|
-
hook: Silgi<TContext, TInterface>['hooks']['hook'];
|
|
108
|
-
callHook: Silgi<TContext, TInterface>['hooks']['callHook'];
|
|
109
|
-
addHooks: Silgi<TContext, TInterface>['hooks']['addHooks'];
|
|
110
|
-
ready: () => Promise<void>;
|
|
111
|
-
close: () => Promise<void>;
|
|
112
|
-
logger: ConsolaInstance;
|
|
113
|
-
options: SilgiOptions<TContext, TInterface>;
|
|
114
|
-
h3Router?: Router;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
interface CreateScope<TContext extends DefaultContext, TInterface extends DefaultInterface> {
|
|
118
|
-
<TScope extends GetScopes<TInterface>>(scope: TScope): {
|
|
119
|
-
service: <TServiceName extends GetServiceNames<TInterface, TScope>>(serviceName: TServiceName) => {
|
|
120
|
-
execute: <TMethodName extends keyof ExtractScope<TInterface>[TScope][TServiceName]>(methodName: TMethodName, input: ExtractScope<TInterface>[TScope][TServiceName][TMethodName] extends ServiceMethod<infer TInput, any> ? TInput : never, context?: TContext) => ServiceMethodResult<ExtractScope<TInterface>[TScope][TServiceName][TMethodName]>;
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
type InitializedCreateScope<TContext extends DefaultContext, TInterface extends DefaultInterface> = CreateScope<TContext & DefaultContext, TInterface & DefaultInterface>;
|
|
125
|
-
|
|
126
|
-
declare class InitSilgi<TContext extends DefaultContext, TInterface extends DefaultInterface> {
|
|
127
|
-
silgi: Silgi<TContext, TInterface>;
|
|
128
|
-
constructor(silgi: Silgi<TContext, TInterface>);
|
|
129
|
-
createCacheProvider<TContext extends DefaultContext, TInterface extends DefaultInterface>(cacheOptions?: SilgiOptions<TContext, TInterface>['cache'], context?: TContext): CacheProvider;
|
|
130
|
-
private log;
|
|
131
|
-
use(plugin: PergelPlugin<TContext, TInterface, any> | Array<PergelPlugin<TContext, TInterface, any>>): Promise<void>;
|
|
132
|
-
getService<TScope extends keyof ExtractScope<TInterface>, TScopedService extends keyof ExtractScope<TInterface>[TScope]>(scope: TScope, name: TScopedService): ServiceExecutor<ExtractScope<TInterface>[TScope][TScopedService], TContext, TInterface>;
|
|
133
|
-
listScopes(): Array<GetScopes<TInterface>>;
|
|
134
|
-
getScope<TScope extends GetScopes<TInterface>>(scope: TScope): {
|
|
135
|
-
name: Array<GetServiceNames<TInterface, TScope>>;
|
|
136
|
-
scope: string;
|
|
137
|
-
};
|
|
138
|
-
getScopeServices<TScope extends GetScopes<TInterface>>(scope: TScope): {
|
|
139
|
-
services: Array<ExtractServiceNames<TInterface, TScope>>;
|
|
140
|
-
scope: TScope;
|
|
141
|
-
methods: {
|
|
142
|
-
[K in ExtractServiceNames<TInterface, TScope>]: Array<keyof ExtractScope<TInterface>[TScope][K]>;
|
|
143
|
-
};
|
|
144
|
-
};
|
|
145
|
-
getAllServices(): {
|
|
146
|
-
[TScope in GetScopes<TInterface>]: {
|
|
147
|
-
services: Array<ExtractServiceNames<TInterface, TScope>>;
|
|
148
|
-
scope: TScope;
|
|
149
|
-
methods: {
|
|
150
|
-
[K in ExtractServiceNames<TInterface, TScope>]: Array<keyof ExtractScope<TInterface>[TScope][K]>;
|
|
151
|
-
};
|
|
152
|
-
};
|
|
153
|
-
};
|
|
154
|
-
scope<TScope extends keyof ExtractScope<TInterface>>(scope: TScope, context: TContext): {
|
|
155
|
-
service: <TServiceName extends keyof ExtractScope<TInterface>[TScope]>(serviceName: TServiceName) => {
|
|
156
|
-
execute: <TMethodName extends keyof ExtractScope<TInterface>[TScope][TServiceName]>(methodName: TMethodName, input: ExtractScope<TInterface>[TScope][TServiceName][TMethodName] extends ServiceMethod<infer TInput, any> ? TInput : never) => ServiceMethodResult<ExtractScope<TInterface>[TScope][TServiceName][TMethodName]>;
|
|
157
|
-
};
|
|
158
|
-
};
|
|
159
|
-
getFromCache(key: string): Promise<any | null>;
|
|
160
|
-
setInCache(key: string, value: any, ttl: number): Promise<void>;
|
|
161
|
-
getServiceRegistryEntries(): [string, ServiceExecutor<any, TContext, TInterface>][];
|
|
162
|
-
createScope(context: TContext): CreateScope<TContext & DefaultContext, TInterface & DefaultInterface>;
|
|
163
|
-
setEvent(key: string, value: any): void;
|
|
164
|
-
getEvent(key: string): any;
|
|
165
|
-
buidApp(): Promise<void>;
|
|
166
|
-
addH3App(router: Router): Promise<void>;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
declare class PluginManager<TContext extends DefaultContext, TInterface extends DefaultInterface> {
|
|
170
|
-
private readonly silgi;
|
|
171
|
-
private readonly plugins;
|
|
172
|
-
private pluginPriorities;
|
|
173
|
-
constructor(silgi: InitSilgi<TContext, TInterface>);
|
|
174
|
-
private log;
|
|
175
|
-
register(plugin: PergelPlugin<TContext, TInterface, any>): void;
|
|
176
|
-
private calculatePluginPriorities;
|
|
177
|
-
runSetupHook(): Promise<void>;
|
|
178
|
-
runHook(hookName: keyof SilgiHooks<TContext, TInterface>, context: PluginHookContext<TContext, TInterface>): Promise<void>;
|
|
179
|
-
executePluginHook(plugin: PergelPlugin<TContext, TInterface, any>, hookName: keyof SilgiHooks<TContext, TInterface>, context: PluginHookContext<TContext, TInterface>): Promise<void>;
|
|
180
|
-
private handlePluginError;
|
|
181
|
-
getPlugin(name: string): Promise<PergelPlugin<TContext, TInterface, any> | undefined>;
|
|
182
|
-
isPluginsRegistered(): boolean;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
type MethodIdentifier = string | symbol;
|
|
186
|
-
type ServiceIdentifier = string;
|
|
187
|
-
type ScopeIdentifier = string;
|
|
188
|
-
type ExtractShared<T> = T extends {
|
|
189
|
-
shared: infer P;
|
|
190
|
-
} ? P extends object ? P : never : never;
|
|
191
|
-
type ExtractScope<T> = T extends {
|
|
192
|
-
scopes: infer S;
|
|
193
|
-
} ? S : never;
|
|
194
|
-
type SilgiContext<TContext extends DefaultContext, TInterface extends DefaultInterface> = {
|
|
195
|
-
_context: TContext;
|
|
196
|
-
silgi: InitSilgi<TContext, TInterface>;
|
|
197
|
-
scope?: ScopeIdentifier;
|
|
198
|
-
serviceName?: ServiceIdentifier;
|
|
199
|
-
methodName?: MethodIdentifier;
|
|
200
|
-
};
|
|
201
|
-
interface ServiceMethod<TInput = unknown, TOutput = unknown, TInterface extends DefaultInterface = DefaultInterface> {
|
|
202
|
-
input: TInput;
|
|
203
|
-
output: TOutput;
|
|
204
|
-
plugins?: PluginConfigurations<TInterface>;
|
|
205
|
-
}
|
|
206
|
-
type CacheScope = 'request' | 'global';
|
|
207
|
-
type CacheProviderType = 'memory' | 'file' | 'custom';
|
|
208
|
-
type CacheKeyGenerator<TInput> = (input: TInput) => string | Promise<string>;
|
|
209
|
-
interface CacheConfig<TInput> {
|
|
210
|
-
ttl: number;
|
|
211
|
-
scope: CacheScope;
|
|
212
|
-
key?: CacheKeyGenerator<TInput>;
|
|
213
|
-
namespace?: string;
|
|
214
|
-
}
|
|
215
|
-
interface SecurityOptions {
|
|
216
|
-
rateLimit?: {
|
|
217
|
-
windowMs: number;
|
|
218
|
-
max: number;
|
|
219
|
-
};
|
|
220
|
-
timeout?: number;
|
|
221
|
-
maxPayloadSize?: number;
|
|
222
|
-
allowedOrigins?: string[];
|
|
223
|
-
}
|
|
224
|
-
interface ServiceHandlerOptions<TInput, TInterface extends DefaultInterface> {
|
|
225
|
-
security?: SecurityOptions;
|
|
226
|
-
cache?: CacheConfig<TInput>;
|
|
227
|
-
plugins?: PluginConfigurations<TInterface>;
|
|
228
|
-
}
|
|
229
|
-
interface ServiceHandler<TInput, TOutput, TContext, TInterface extends DefaultInterface> {
|
|
230
|
-
handler: (input: TInput, shared: ExtractShared<TInterface>, context: TContext) => Promise<TOutput>;
|
|
231
|
-
options?: ServiceHandlerOptions<TInput, TInterface>;
|
|
232
|
-
_input?: TInput;
|
|
233
|
-
_output?: TOutput;
|
|
234
|
-
}
|
|
235
|
-
type ServiceResponse<T> = {
|
|
236
|
-
success: true;
|
|
237
|
-
data: T;
|
|
238
|
-
cached?: boolean;
|
|
239
|
-
} | {
|
|
240
|
-
success: false;
|
|
241
|
-
error: {
|
|
242
|
-
code: string;
|
|
243
|
-
message: string;
|
|
244
|
-
details?: Record<string, unknown>;
|
|
245
|
-
};
|
|
246
|
-
};
|
|
247
|
-
type ServiceMethodResult<T> = Promise<ServiceResponse<T extends ServiceMethod<any, infer O> ? O : never>>;
|
|
248
|
-
interface CacheProvider {
|
|
249
|
-
get: (key: string) => Promise<any | null>;
|
|
250
|
-
set: (key: string, value: any, ttl: number) => Promise<void>;
|
|
251
|
-
delete: (key: string) => Promise<void>;
|
|
252
|
-
clear: () => Promise<void>;
|
|
253
|
-
}
|
|
254
|
-
interface CacheProviderOptions<TContext> {
|
|
255
|
-
memory?: {
|
|
256
|
-
maxSize?: number;
|
|
257
|
-
object?: TContext;
|
|
258
|
-
};
|
|
259
|
-
file?: {
|
|
260
|
-
dir?: string;
|
|
261
|
-
prefix?: string;
|
|
262
|
-
object?: TContext;
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
interface SilgiOptions<TContext extends DefaultContext, TInterface extends DefaultInterface> {
|
|
266
|
-
_cacheProvider: CacheProvider;
|
|
267
|
-
_serviceRegistry: Map<string, ServiceExecutor<any, TContext, TInterface>>;
|
|
268
|
-
_pluginManager: PluginManager<TContext, TInterface>;
|
|
269
|
-
_eventContext?: Map<string, SilgiContext<TContext, TInterface>>;
|
|
270
|
-
services: Array<ServiceExecutor<any, TContext, TInterface>>;
|
|
271
|
-
shared: ExtractShared<TInterface>;
|
|
272
|
-
cache?: {
|
|
273
|
-
type?: CacheProviderType;
|
|
274
|
-
provider?: CacheProvider | ((object?: TContext) => CacheProvider);
|
|
275
|
-
options?: CacheProviderOptions<TContext>;
|
|
276
|
-
};
|
|
277
|
-
debug?: boolean;
|
|
278
|
-
consolaOptions?: Partial<ConsolaOptions>;
|
|
279
|
-
h3Router?: Router;
|
|
280
|
-
plugins?: PergelPlugin<TContext, TInterface, any> | Array<PergelPlugin<TContext, TInterface, any>>;
|
|
281
|
-
}
|
|
282
|
-
type OmitSilgiOptions<TContext extends DefaultContext, TInterface extends DefaultInterface> = Omit<SilgiOptions<TContext, TInterface>, '_cacheProvider' | '_serviceRegistry' | '_pluginManager' | 'shared'> & {
|
|
283
|
-
shared?: Partial<ExtractShared<TInterface>>;
|
|
284
|
-
};
|
|
285
|
-
interface ServiceExecutor<TService, TContext extends DefaultContext, TInterface extends DefaultInterface> {
|
|
286
|
-
scope: ScopeIdentifier;
|
|
287
|
-
name: ServiceIdentifier;
|
|
288
|
-
handlers: Map<MethodIdentifier, ServiceHandler<any, any, any, TInterface>>;
|
|
289
|
-
plugins?: PluginConfigurations<TInterface>;
|
|
290
|
-
methodPlugins?: Record<string, Record<string, any>>;
|
|
291
|
-
execute: <K extends keyof TService>(methodName: K, input: TService[K] extends ServiceMethod<infer I, any> ? I : never, context: {
|
|
292
|
-
initSilgi: InitSilgi<TContext, TInterface>;
|
|
293
|
-
requestContext: TContext;
|
|
294
|
-
scope: ScopeIdentifier;
|
|
295
|
-
serviceName: ServiceIdentifier;
|
|
296
|
-
methodName: MethodIdentifier;
|
|
297
|
-
}) => ServiceMethodResult<TService[K]>;
|
|
298
|
-
}
|
|
299
|
-
type ExtractServiceNames<TInterface extends DefaultInterface, TScope extends keyof ExtractScope<TInterface>> = keyof ExtractScope<TInterface>[TScope] & string;
|
|
300
|
-
|
|
301
|
-
export { type CacheScope as C, type DefaultContext as D, type ExtractScope as E, InitSilgi as I, type MethodPluginConfig as M, type OmitSilgiOptions as O, type PergelPlugin as P, type ServicePluginConfig as S, type DefaultInterface as a, type ServiceMethod as b, type ExtractShared as c, type CacheKeyGenerator as d, type ServiceExecutor as e, type Silgi as f, type InitializedCreateScope as g, type DefaultHooks as h, type SilgiDefaultContext as i, type SilgiDefaultInterface as j, type SchemaGenerated as k };
|