silgi 0.4.12 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,63 @@
1
- import { D as DefaultNamespaces, B as BaseSchemaType, S as SilgiServiceInterface } from '../shared/silgi.yr8vHHvd.js';
2
- export { A as AppConfig, o as Awaitable, l as BaseSilgiMethodType, W as CaptureError, V as CapturedErrorContext, C as CreateScope, n as DeepPartial, m as DefaultHooks, N as EventHandlerResponse, a2 as ExtendShared, ae as ExtractInputFromURI, af as ExtractOutputFromURI, ag as ExtractRouterParamsFromURI, a3 as FrameworkContext, a7 as ImportItem, L as LoadConfigOptions, Y as MergedSilgiSchema, O as MethodHandlerType, Q as MethodResponse, K as MethodSchemaType, G as ModuleConfigurations, y as ModuleDefinition, v as ModuleHookContext, M as ModuleMeta, w as ModuleOptions, z as ModuleSetupInstallResult, E as ModuleSetupReturn, ab as NitroBuildInfo, _ as RequiredServiceType, P as ResolvedMethodHandlerType, R as ResolvedModuleMeta, x as ResolvedModuleOptions, $ as ResolvedServiceType, Z as ServiceType, a4 as Silgi, U as SilgiAppPlugin, a8 as SilgiCLI, b as SilgiCLIConfig, a9 as SilgiCLIDynamicConfig, c as SilgiCLIHooks, a as SilgiCLIOptions, u as SilgiCompatibility, d as SilgiCompatibilityIssue, e as SilgiCompatibilityIssues, a5 as SilgiConfig, a0 as SilgiDefaultShared, g as SilgiEvent, aa as SilgiFrameworkInfo, a6 as SilgiFunction, k as SilgiHook, p as SilgiHooks, h as SilgiMethods, F as SilgiModule, t as SilgiModuleInput, r as SilgiModuleMethods, s as SilgiModuleOptions, a1 as SilgiModuleShared, q as SilgiModules, i as SilgiNamespaces, H as SilgiOperation, f as SilgiOptions, I as SilgiPreset, J as SilgiPresetMeta, j as SilgiRouterTypes, X as SilgiSchema, ai as SilgiStorageBase, ac as SilgiURIs, ak as StorageConfig, aj as StorageKeyGenerator, al as StorageKeyParams, ah as StorageMounts, T as TSReference, ad as URIsTypes } from '../shared/silgi.yr8vHHvd.js';
1
+ import { b as SilgiOperation, c as SilgiEvent, d as ModuleConfigurations, B as BaseSchemaType, e as BaseSilgiMethodType, f as SilgiModules, D as DefaultHooks, g as SilgiModuleOptions, h as DeepPartial, H as HookResult, i as ModuleHookContext, j as DefaultNamespaces } from '../shared/silgi.CN_giHTc.js';
2
+ export { A as AppConfig, t as Awaitable, C as CreateScope, W as ExtractInputFromURI, X as ExtractOutputFromURI, Y as ExtractRouterParamsFromURI, K as ImportItem, L as LoadConfigOptions, J as MergedSilgiSchema, a as ModuleDefinition, x as ModuleMeta, M as ModuleOptions, z as ModuleSetupInstallResult, E as ModuleSetupReturn, Q as NitroBuildInfo, R as ResolvedModuleMeta, y as ResolvedModuleOptions, N as SilgiCLI, l as SilgiCLIConfig, O as SilgiCLIDynamicConfig, m as SilgiCLIHooks, k as SilgiCLIOptions, w as SilgiCompatibility, n as SilgiCompatibilityIssue, o as SilgiCompatibilityIssues, P as SilgiFrameworkInfo, s as SilgiHook, p as SilgiMethods, S as SilgiModule, v as SilgiModuleInput, u as SilgiModuleMethods, q as SilgiNamespaces, F as SilgiPreset, G as SilgiPresetMeta, r as SilgiRouterTypes, I as SilgiSchema, U as SilgiURIs, T as TSReference, V as URIsTypes } from '../shared/silgi.CN_giHTc.js';
3
+ import { ConsolaOptions, ConsolaInstance } from 'consola';
4
+ import { PresetNameInput } from 'silgi/presets';
5
+ import { BuiltinDriverName, TransactionOptions, Storage } from 'unstorage';
6
+ import { Hookable } from 'hookable';
7
+ import { Ignore } from 'ignore';
8
+ import { u as useStorage, s as silgi } from '../shared/silgi.DGmIWx95.js';
3
9
  import { StandardSchemaV1 } from '@standard-schema/spec';
4
10
  import 'defu';
5
11
  import '@graphql-tools/utils';
6
12
  import 'pkg-types';
7
- import 'consola';
8
- import 'hookable';
9
- import 'ignore';
10
- import 'silgi/presets';
11
13
  import 'silgi/types';
12
14
  import 'unimport';
13
- import 'unstorage';
14
15
  import 'c12';
15
16
  import 'chokidar';
16
17
  import 'compatx';
17
18
  import 'unimport/unplugin';
18
19
  import 'std-env';
19
- import '../shared/silgi.40ZJYm8F.js';
20
+
21
+ type CustomDriverName = string & {
22
+ _custom?: any;
23
+ };
24
+ interface StorageMounts {
25
+ [path: string]: {
26
+ driver: BuiltinDriverName | CustomDriverName;
27
+ [option: string]: any;
28
+ };
29
+ }
30
+ interface SilgiStorageBase {
31
+ }
32
+ type StorageKeyGenerator<TInput> = (input: TInput) => string | Promise<string>;
33
+ interface StorageConfig<TInput> {
34
+ options: TransactionOptions;
35
+ base: '/memory:cache' | keyof SilgiStorageBase;
36
+ key?: StorageKeyGenerator<TInput>;
37
+ scope?: 'request' | 'global';
38
+ }
39
+ interface StorageKeyParams<TInput = unknown> {
40
+ operation: SilgiOperation;
41
+ input: TInput;
42
+ requestId?: string;
43
+ keyGenerator?: StorageKeyGenerator<TInput>;
44
+ storageOptions?: Pick<StorageConfig<TInput>, 'base' | 'options' | 'scope'>;
45
+ }
46
+
47
+ interface SilgiOptions {
48
+ consolaOptions?: Partial<ConsolaOptions>;
49
+ present: PresetNameInput;
50
+ /**
51
+ * Set to `true` to enable debug mode.
52
+ *
53
+ * At the moment, it prints out hook names and timings on the server, and logs hook arguments as well in the browser.
54
+ *
55
+ * @default false
56
+ */
57
+ debug: boolean;
58
+ storage: StorageMounts;
59
+ [key: string]: any;
60
+ }
20
61
 
21
62
  interface SilgiModuleContext extends Record<string, any> {
22
63
  }
@@ -31,6 +72,152 @@ interface GraphQLJSON {
31
72
  references: any;
32
73
  }
33
74
 
75
+ interface SilgiDefaultShared extends SilgiModuleShared {
76
+ storage: (...data: Parameters<typeof useStorage>) => ReturnType<typeof useStorage>;
77
+ silgi: SilgiFunction;
78
+ }
79
+ interface SilgiModuleShared {
80
+ }
81
+ interface ExtendShared {
82
+ }
83
+
84
+ interface MethodSchemaType<Input, Output> {
85
+ default: {
86
+ input?: Input;
87
+ output: Output;
88
+ };
89
+ handler: (input: Input, shared: SilgiDefaultShared, event: SilgiEvent) => Promise<Output>;
90
+ modules?: Partial<ModuleConfigurations>;
91
+ storage?: StorageConfig<Input>;
92
+ }
93
+ type EventHandlerResponse<T = undefined> = T extends undefined ? void : void | T | Promise<T>;
94
+ type MethodHandlerType<T> = {
95
+ [Action in keyof T]: T[Action] extends Record<string, any> ? {
96
+ [Method in keyof T[Action]]: {
97
+ default?: {
98
+ input?: StandardSchemaV1.InferInput<T[Action][Method]['input']>;
99
+ output?: StandardSchemaV1.InferInput<T[Action][Method]['output']>;
100
+ };
101
+ handler: (router: StandardSchemaV1.InferInput<T[Action][Method]['router']>, input: StandardSchemaV1.InferInput<T[Action][Method]['input']>, shared: SilgiDefaultShared, event: SilgiEvent) => EventHandlerResponse<StandardSchemaV1.InferOutput<T[Action][Method]['output']>>;
102
+ modules?: Partial<ModuleConfigurations>;
103
+ storage?: StorageConfig<T[Action][Method]['input']>;
104
+ };
105
+ } : never;
106
+ };
107
+ interface ResolvedMethodHandlerType {
108
+ input?: Partial<BaseSchemaType<any>>;
109
+ output: Partial<BaseSchemaType<any>>;
110
+ handler: (router: StandardSchemaV1.InferInput<any>, input: StandardSchemaV1.InferInput<any>, shared: SilgiDefaultShared, event: SilgiEvent) => Promise<StandardSchemaV1.InferInput<any>>;
111
+ modules?: Partial<ModuleConfigurations>;
112
+ storage?: StorageConfig<StandardSchemaV1.InferInput<any>>;
113
+ execute: (input: StandardSchemaV1.InferInput<any>, shared: SilgiDefaultShared, event: SilgiEvent) => Promise<StandardSchemaV1.InferInput<any>>;
114
+ }
115
+
116
+ type SilgiServiceInterface<T extends BaseSchemaType<StandardSchemaV1>> = {
117
+ [Action in keyof T]: T[Action] extends Record<string, any> ? {
118
+ [Method in keyof T[Action]]: {
119
+ input: T[Action][Method]['input'];
120
+ output: T[Action][Method]['output'];
121
+ router: T[Action][Method]['router'];
122
+ };
123
+ } : never;
124
+ };
125
+ type ServiceType<T> = Partial<{
126
+ [Namespace in keyof T]: T[Namespace] extends Record<string, any> ? {
127
+ [Service in keyof T[Namespace]]?: MethodHandlerType<T[Namespace][Service]>;
128
+ } : never;
129
+ }>;
130
+ type RequiredServiceType<T> = {
131
+ [K in keyof T]-?: T[K] extends Record<string, any> ? {
132
+ [P in keyof T[K]]-?: MethodHandlerType<T[K][P]>;
133
+ } : never;
134
+ };
135
+ /**
136
+ * const test: ResolvedServiceType = {
137
+ aaa: {
138
+ bbb: {
139
+ delete: {
140
+ storage: {
141
+ handler: () => {}
142
+ },
143
+ },
144
+ },
145
+ },
146
+ }
147
+ */
148
+ type ResolvedServiceType = {
149
+ [K in string]: {
150
+ [P in string]: {
151
+ [Q in BaseSilgiMethodType]?: {
152
+ [M in string]: ResolvedMethodHandlerType;
153
+ };
154
+ };
155
+ };
156
+ };
157
+
158
+ interface FrameworkContext {
159
+ }
160
+ interface Silgi {
161
+ schemas: any;
162
+ services: ResolvedServiceType;
163
+ shared: SilgiDefaultShared;
164
+ uris: Record<string, any>;
165
+ modulesURIs: Partial<Record<keyof SilgiModules, any>>;
166
+ scannedHandlers: Map<string, ResolvedMethodHandlerType>;
167
+ plugins: SilgiAppPlugin[];
168
+ framework: FrameworkContext;
169
+ _ignore?: Ignore;
170
+ hooks: Hookable<SilgiHooks & DefaultHooks>;
171
+ hook: Silgi['hooks']['hook'];
172
+ callHook: Silgi['hooks']['callHook'];
173
+ addHooks: Silgi['hooks']['addHooks'];
174
+ ready: () => Promise<void>;
175
+ close: () => Promise<void>;
176
+ logger: ConsolaInstance;
177
+ storage: Storage;
178
+ options: SilgiOptions & SilgiModuleOptions;
179
+ captureError: CaptureError;
180
+ }
181
+ interface SilgiConfig extends Pick<Silgi, 'services' | 'shared' | 'uris' | 'schemas' | 'modulesURIs' | 'plugins' | 'framework'>, Partial<SilgiModuleOptions> {
182
+ options: DeepPartial<SilgiOptions>;
183
+ }
184
+ type SilgiFunction = typeof silgi;
185
+
186
+ interface SilgiAppPlugin {
187
+ (silgi: Silgi): Promise<void> | void;
188
+ }
189
+
190
+ interface CapturedErrorContext {
191
+ event?: SilgiEvent;
192
+ [key: string]: unknown;
193
+ }
194
+ type CaptureError = (error: Error, context: CapturedErrorContext) => void;
195
+
196
+ /**
197
+ * The listeners to Silgi
198
+ */
199
+ interface SilgiHooks {
200
+ /**
201
+ * Called after Silgi initialization, when the Silgi instance is ready to work.
202
+ * @param silgi The configured Silgi object
203
+ * @returns Promise
204
+ */
205
+ 'ready': (silgi: Silgi) => HookResult;
206
+ /**
207
+ * Called when silgi instance is gracefully closing.
208
+ * @param silgi The configured silgi object
209
+ * @returns Promise
210
+ */
211
+ 'close': (silgi: Silgi) => HookResult;
212
+ 'app:setup:start': (silgi: Silgi) => HookResult;
213
+ 'action:before': (context: ModuleHookContext) => HookResult;
214
+ 'action:after': (context: ModuleHookContext) => HookResult;
215
+ 'action:error': (context: ModuleHookContext) => HookResult;
216
+ 'action:finally': (context: ModuleHookContext) => HookResult;
217
+ 'event:before': (event: SilgiEvent) => HookResult;
218
+ 'error': CaptureError;
219
+ }
220
+
34
221
  interface BaseNamespaceType extends Record<keyof DefaultNamespaces, Record<string, BaseSchemaType<StandardSchemaV1>>> {
35
222
  }
36
223
  type Namespaces<T extends BaseNamespaceType> = {
@@ -41,4 +228,4 @@ type Namespaces<T extends BaseNamespaceType> = {
41
228
 
42
229
  declare const autoImportTypes: string[];
43
230
 
44
- export { type BaseNamespaceType, BaseSchemaType, DefaultNamespaces, type ExtendContext, type GraphQLJSON, type Namespaces, type SilgiModuleContext, SilgiServiceInterface, autoImportTypes };
231
+ export { type BaseNamespaceType, BaseSchemaType, BaseSilgiMethodType, type CaptureError, type CapturedErrorContext, DeepPartial, DefaultHooks, DefaultNamespaces, type EventHandlerResponse, type ExtendContext, type ExtendShared, type FrameworkContext, type GraphQLJSON, type MethodHandlerType, type MethodSchemaType, ModuleConfigurations, ModuleHookContext, type Namespaces, type RequiredServiceType, type ResolvedMethodHandlerType, type ResolvedServiceType, type ServiceType, type Silgi, type SilgiAppPlugin, type SilgiConfig, type SilgiDefaultShared, SilgiEvent, type SilgiFunction, type SilgiHooks, type SilgiModuleContext, SilgiModuleOptions, type SilgiModuleShared, SilgiModules, SilgiOperation, type SilgiOptions, type SilgiServiceInterface, type SilgiStorageBase, type StorageConfig, type StorageKeyGenerator, type StorageKeyParams, type StorageMounts, autoImportTypes };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "silgi",
3
3
  "type": "module",
4
- "version": "0.4.12",
4
+ "version": "0.5.0",
5
5
  "sideEffects": false,
6
6
  "exports": {
7
7
  "./cli": {