silgi 0.33.2 → 0.34.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.
@@ -30,7 +30,6 @@ const SilgiCLIDefaults = {
30
30
  version: "0.0.1"
31
31
  }
32
32
  },
33
- serviceParseModules: [],
34
33
  storages: [],
35
34
  devServer: {
36
35
  watch: []
@@ -69,19 +68,11 @@ const SilgiCLIDefaults = {
69
68
  // Modules
70
69
  _modules: [],
71
70
  modules: [],
72
- routeRules: {},
73
- // Features
74
- // experimental: {},
75
71
  future: {},
76
72
  storage: {},
77
73
  devStorage: {},
78
74
  stub: false,
79
- // bundledStorage: [],
80
- // publicAssets: [],
81
- // serverAssets: [],
82
75
  plugins: [],
83
- // tasks: {},
84
- // scheduledTasks: {},
85
76
  imports: {
86
77
  exclude: [],
87
78
  dirs: [],
@@ -268,7 +259,8 @@ function getSilgiImportsPreset() {
268
259
  "createShared",
269
260
  "useSilgi",
270
261
  "createService",
271
- "createSchema"
262
+ "createSchema",
263
+ "createRouter"
272
264
  ]
273
265
  },
274
266
  // {
@@ -14,8 +14,6 @@ import 'hookable';
14
14
  import 'silgi/kit';
15
15
  import 'silgi/runtime/meta';
16
16
  import 'unimport';
17
- import '../_chunks/routeRules.mjs';
18
- import 'ufo';
19
17
  import '@clack/prompts';
20
18
  import 'node:fs';
21
19
  import 'dotenv';
@@ -26,6 +24,7 @@ import 'semver/functions/satisfies.js';
26
24
  import 'node:url';
27
25
  import 'defu';
28
26
  import 'exsolve';
27
+ import 'ufo';
29
28
  import 'node:fs/promises';
30
29
  import 'globby';
31
30
  import 'ignore';
@@ -1,37 +1,304 @@
1
- import { SilgiConfig, Silgi, SilgiEvents, SilgiFunction, SilgiOperation, MergedSilgiSchema, ServiceType, SilgiSchema, RequiredServiceType, SilgiRuntimeSharedsExtend, SilgiRuntimeContext, DefaultNamespaces, BaseSchemaType, SilgiRuntimeShareds, StorageConfig, SilgiCLI, SilgiStorageBase } from 'silgi/types';
1
+ import { SilgiConfig, Silgi, SilgiEvent, SilgiSchema, ServiceSetup, CustomRequestInit, SilgiRuntimeContext, AllPrefixes, NamespacesForPrefix, RoutesForPrefixAndNamespace, HTTPMethod, ExtractPathParamKeys, MergeAll, SilgiRuntimeShareds, RouteConfig, StorageConfig, SilgiCLI, SilgiStorageBase } from 'silgi/types';
2
2
  import { StandardSchemaV1 } from '@standard-schema/spec';
3
3
  import { Storage, StorageValue } from 'unstorage';
4
4
  import { UseContext } from 'unctx';
5
5
 
6
6
  declare function createSilgi(config: SilgiConfig): Promise<Silgi>;
7
7
 
8
- declare function silgi(event?: SilgiEvents | Record<string, any>): SilgiFunction;
8
+ declare function createSilgiCore(event: SilgiEvent): {
9
+ resolve: <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 = false>(path: Route, method: Method, context: {
10
+ pathParams?: Route extends keyof Schema ? Method extends keyof Schema[Route] ? Schema[Route][Method] extends {
11
+ pathParams?: infer P;
12
+ } ? P extends StandardSchemaV1 ? StandardSchemaV1.InferInput<P> : undefined : undefined : undefined : undefined;
13
+ }) => Promise<Route extends keyof Schema ? Method extends keyof Schema[Route] ? ServiceSetup<Schema, Route, Method, Resolved, HiddenParameters> : undefined : undefined>;
14
+ };
15
+ /**
16
+ * Fetch API for Silgi framework
17
+ */
18
+ declare function silgiFetch<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>(_request: Route, options?: CustomRequestInit<Schema, Route, Method, Resolved, HiddenParameters>, context?: SilgiRuntimeContext): Promise<Response | Promise<Response>>;
19
+ /**
20
+ * Fetch API for Silgi framework using standard Request options
21
+ */
22
+ declare function silgiFetch(_request: Request | URL | string, options?: RequestInit & {
23
+ pathParams?: Record<string, any>;
24
+ }, context?: SilgiRuntimeContext): Promise<Response | Promise<Response>>;
9
25
 
10
- interface RouteTemplateValidator {
11
- (value: string): boolean;
12
- }
13
- interface RouteTemplateConfig {
14
- pattern: string;
15
- validators?: Record<string, RouteTemplateValidator>;
26
+ /**
27
+ * LICENSE: MIT
28
+ * Credits:
29
+ * - H3 - https://github.com/h3js/h3
30
+ */
31
+ /**
32
+ * Silgi Runtime Error
33
+ * @class
34
+ * @extends Error
35
+ * @property {number} statusCode - An integer indicating the HTTP response status code.
36
+ * @property {string} statusMessage - A string representing the HTTP status message.
37
+ * @property {boolean} fatal - Indicates if the error is a fatal error.
38
+ * @property {boolean} unhandled - Indicates if the error was unhandled and auto-captured.
39
+ * @property {DataT} data - An extra data that will be included in the response.
40
+ * This can be used to pass additional information about the error.
41
+ */
42
+ declare class SilgiError<DataT = unknown> extends Error {
43
+ static __silgi_error__: boolean;
44
+ statusCode: number;
45
+ fatal: boolean;
46
+ unhandled: boolean;
47
+ statusMessage?: string;
48
+ data?: DataT;
49
+ cause?: unknown;
50
+ constructor(message: string, opts?: {
51
+ cause?: unknown;
52
+ });
53
+ toJSON(): Pick<SilgiError<DataT>, 'message' | 'statusCode' | 'statusMessage' | 'data'>;
16
54
  }
17
- type URITemplate = string | RouteTemplateConfig;
18
- declare function parseURI(uri: string, uris: Record<string, URITemplate>): SilgiOperation;
55
+ /**
56
+ * Creates a new `Error` that can be used to handle both internal and runtime errors.
57
+ *
58
+ * @param input {string | (Partial<SilgiError> & { status?: number; statusText?: string })} - The error message or an object containing error properties.
59
+ * If a string is provided, it will be used as the error `message`.
60
+ *
61
+ * @example
62
+ * // String error where `statusCode` defaults to `500`
63
+ * throw createError("An error occurred");
64
+ * // Object error
65
+ * throw createError({
66
+ * statusCode: 400,
67
+ * statusMessage: "Bad Request",
68
+ * message: "Invalid input",
69
+ * data: { field: "email" }
70
+ * });
71
+ *
72
+ *
73
+ * @return {SilgiError} - An instance of SilgiError.
74
+ *
75
+ * @remarks
76
+ * - Typically, `message` contains a brief, human-readable description of the error, while `statusMessage` is specific to HTTP responses and describes
77
+ * the status text related to the response status code.
78
+ * - In a client-server context, using a short `statusMessage` is recommended because it can be accessed on the client side. Otherwise, a `message`
79
+ * passed to `createError` on the server will not propagate to the client.
80
+ * - Consider avoiding putting dynamic user input in the `message` to prevent potential security issues.
81
+ */
82
+ declare function createError<DataT = unknown>(input: string | (Partial<SilgiError<DataT>> & {
83
+ status?: number;
84
+ statusText?: string;
85
+ })): SilgiError<DataT>;
86
+ /**
87
+ * Checks if the given input is an instance of SilgiError.
88
+ *
89
+ * @param input {*} - The input to check.
90
+ * @return {boolean} - Returns true if the input is an instance of SilgiError, false otherwise.
91
+ */
92
+ declare function isError<DataT = unknown>(input: any): input is SilgiError<DataT>;
19
93
 
20
- type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
21
- declare function mergeSchemas<T extends MergedSilgiSchema[]>(typesOrArray: [...T] | T): UnionToIntersection<T[number]>;
22
- declare function mergeServices<T extends ServiceType<SilgiSchema>[]>(servicesOrArray: [...T] | T): RequiredServiceType<SilgiSchema>;
23
- declare function mergeShared<T extends SilgiRuntimeSharedsExtend[]>(sharedOrArray: [...T] | T): UnionToIntersection<T[number]>;
94
+ type MaybePromise<T> = T | Promise<T>;
95
+ interface SilgiHandlerConfig {
96
+ debug?: boolean;
97
+ onError?: (error: SilgiError, event: SilgiEvent) => MaybePromise<void | unknown>;
98
+ onRequest?: (event: SilgiEvent) => MaybePromise<void>;
99
+ onBeforeResponse?: (event: SilgiEvent, response: Response | PreparedResponse) => MaybePromise<void>;
100
+ }
101
+ type PreparedResponse = ResponseInit & {
102
+ body?: BodyInit | null;
103
+ };
104
+ declare function handleResponse(val: unknown, event: SilgiEvent, config: SilgiHandlerConfig): Response | Promise<Response>;
24
105
 
25
- declare function getEvent<T extends SilgiEvents>(event?: SilgiEvents): T;
26
- declare function getEventContext<T extends SilgiRuntimeContext>(event?: SilgiEvents): T;
106
+ declare function getEvent<T extends SilgiEvent>(event?: SilgiEvent): T;
107
+ declare function getEventContext<T extends SilgiRuntimeContext>(event?: SilgiEvent): T;
27
108
 
28
- declare function createSchema<T extends Partial<Record<keyof DefaultNamespaces, Record<string, BaseSchemaType<StandardSchemaV1>>>>>(silgiType: T): {
29
- [K in keyof T]: {
30
- [P in keyof T[K]]: T[K][P];
109
+ /**
110
+ * Creates an object type representing path parameters extracted from a URL pattern.
111
+ *
112
+ * @example
113
+ * PathParamsObject<'/users/:id/posts/:postId'> // { id: string | number, postId: string | number }
114
+ */
115
+ type PathParamsObject<S extends string> = {
116
+ [K in ExtractPathParamKeys<S>]: string | number;
117
+ };
118
+ /**
119
+ * Determines if a URL pattern contains any path parameters.
120
+ *
121
+ * @example
122
+ * HasPathParams<'/users/:id'> // true
123
+ * HasPathParams<'/users'> // false
124
+ */
125
+ type HasPathParams<S extends string> = ExtractPathParamKeys<S> extends never ? false : true;
126
+ /**
127
+ * Base schema definition for API method handlers.
128
+ * Defines the structure of input/output data.
129
+ */
130
+ interface BaseMethodSchema {
131
+ /** Schema for request body */
132
+ input?: StandardSchemaV1;
133
+ /** Schema for response body */
134
+ output?: StandardSchemaV1;
135
+ /** Schema for URL query parameters */
136
+ queryParams?: StandardSchemaV1;
137
+ /** Schema for source data (contextual information) */
138
+ source?: StandardSchemaV1;
139
+ }
140
+ /**
141
+ * Interface for adding path parameters schema to method definitions.
142
+ */
143
+ interface WithPathParams<PathParamsStr extends string> {
144
+ /** Schema for path parameters */
145
+ pathParams: StandardSchemaV1<PathParamsObject<PathParamsStr>>;
146
+ }
147
+ /**
148
+ * Defines the schema structure for HTTP methods, conditionally including
149
+ * path parameters based on the URL pattern.
150
+ *
151
+ * @example
152
+ * // For a route with path parameters:
153
+ * type UserMethodSchema = MethodSchemas<'/:id'>
154
+ * // Result includes required pathParams for each method
155
+ *
156
+ * // For a route without path parameters:
157
+ * type ListMethodSchema = MethodSchemas<''>
158
+ * // Result doesn't allow pathParams property
159
+ */
160
+ type MethodSchemas<PathParamsStr extends string = ''> = {
161
+ [K in HTTPMethod]?: HasPathParams<PathParamsStr> extends true ? BaseMethodSchema & WithPathParams<PathParamsStr> : BaseMethodSchema & {
162
+ pathParams?: never;
31
163
  };
32
164
  };
165
+ /**
166
+ * Creates a type-safe API route schema definition.
167
+ *
168
+ * This utility function helps you define API schemas with proper typing for
169
+ * input, output, path parameters, and query parameters.
170
+ *
171
+ * @template P - API prefix (e.g., '/api')
172
+ * @template N - API namespace (e.g., '/v1')
173
+ * @template R - Route path (e.g., '/users' or '/users/:id')
174
+ * @template Methods - HTTP method definitions
175
+ *
176
+ * @param params - Schema configuration parameters
177
+ * @returns Route schema object with complete type information
178
+ *
179
+ * @example
180
+ * // Define a user API schema with GET and POST methods
181
+ * const userSchema = createSchema({
182
+ * prefix: '/api',
183
+ * namespace: '/v1',
184
+ * path: '/users',
185
+ * methods: {
186
+ * GET: {
187
+ * output: z.object({
188
+ * users: z.array(z.object({ id: z.string(), name: z.string() }))
189
+ * })
190
+ * },
191
+ * POST: {
192
+ * input: z.object({
193
+ * name: z.string().min(2),
194
+ * email: z.string().email()
195
+ * }),
196
+ * output: z.object({
197
+ * id: z.string(),
198
+ * created: z.boolean()
199
+ * })
200
+ * }
201
+ * }
202
+ * });
203
+ *
204
+ * // Define a user detail API with path parameters
205
+ * const userDetailSchema = createSchema({
206
+ * prefix: '/api',
207
+ * namespace: '/v1',
208
+ * path: '/users/:id',
209
+ * methods: {
210
+ * GET: {
211
+ * pathParams: z.object({
212
+ * id: z.string().uuid()
213
+ * }),
214
+ * output: z.object({
215
+ * name: z.string(),
216
+ * email: z.string(),
217
+ * createdAt: z.date()
218
+ * })
219
+ * },
220
+ * PUT: {
221
+ * pathParams: z.object({
222
+ * id: z.string().uuid()
223
+ * }),
224
+ * input: z.object({
225
+ * name: z.string().optional(),
226
+ * email: z.string().email().optional()
227
+ * }),
228
+ * queryParams: z.object({
229
+ * version: z.number().optional()
230
+ * })
231
+ * },
232
+ * DELETE: {
233
+ * pathParams: z.object({
234
+ * id: z.string().uuid()
235
+ * }),
236
+ * output: z.object({
237
+ * success: z.boolean()
238
+ * })
239
+ * }
240
+ * }
241
+ * });
242
+ *
243
+ * // Example with nested route parameters
244
+ * const postCommentSchema = createSchema({
245
+ * prefix: '/api',
246
+ * namespace: '/v1',
247
+ * path: '/posts/:postId/comments/:commentId',
248
+ * methods: {
249
+ * GET: {
250
+ * pathParams: z.object({
251
+ * postId: z.string(),
252
+ * commentId: z.string()
253
+ * }),
254
+ * output: z.object({
255
+ * content: z.string(),
256
+ * author: z.string()
257
+ * })
258
+ * },
259
+ * PATCH: {
260
+ * pathParams: z.object({
261
+ * postId: z.string(),
262
+ * commentId: z.string()
263
+ * }),
264
+ * input: z.object({
265
+ * content: z.string().min(1).max(500)
266
+ * })
267
+ * }
268
+ * }
269
+ * });
270
+ */
271
+ declare function createSchema<P extends AllPrefixes, N extends NamespacesForPrefix<P>, R extends RoutesForPrefixAndNamespace<P, N>, Methods extends MethodSchemas<R> = MethodSchemas<R>>(params: {
272
+ /** API prefix, such as '/api' */
273
+ prefix: P;
274
+ /** API namespace, such as '/v1' */
275
+ namespace: N;
276
+ /** Route path, such as '/users' or '/users/:id' */
277
+ path: R;
278
+ /** HTTP method schemas */
279
+ methods: Methods;
280
+ }): Record<`${P}${N}${R}`, Methods>;
33
281
 
34
- declare function createService<T extends SilgiSchema>(variables: ServiceType<T>): ServiceType<T>;
282
+ /**
283
+ * Merges multiple service definition objects into a single object.
284
+ * Performs a complete deep merge of all service definition objects.
285
+ * @template T - A tuple type representing the array of service definition objects to merge.
286
+ * @param {T} schemas - An array of service definition objects created by `createSchema`.
287
+ * @returns {MergeAll<T>} A single object containing all merged service definitions.
288
+ */
289
+ declare function deepMergeObjects<T extends readonly Record<string, any>[]>(schemas: [...T]): MergeAll<T>;
290
+
291
+ type ServiceMethods<Schema extends SilgiSchema, Path extends keyof Schema, Resolved extends boolean = false, HiddenParameters extends boolean = false> = {
292
+ [M in keyof Schema[Path]]?: ServiceSetup<Schema, Path, M, Resolved, HiddenParameters>;
293
+ };
294
+ declare function createService<Schema extends SilgiSchema, Path extends keyof Schema, Resolved extends boolean = false, Methods extends ServiceMethods<Schema, Path, Resolved> = ServiceMethods<Schema, Path, Resolved>>(params: {
295
+ path: Path;
296
+ methods: Methods;
297
+ }): {
298
+ [R in Path]: {
299
+ [M in keyof Methods]: Methods[M];
300
+ };
301
+ };
35
302
 
36
303
  declare function createShared(shared: Partial<SilgiRuntimeShareds>): SilgiRuntimeShareds;
37
304
 
@@ -40,197 +307,13 @@ declare function createShared(shared: Partial<SilgiRuntimeShareds>): SilgiRuntim
40
307
  */
41
308
  declare function replaceRuntimeValues(obj: any, runtime: any): any;
42
309
 
310
+ declare function createRoute<URL extends string>(params: RouteConfig<URL>): {
311
+ [K in URL]: RouteConfig<URL>;
312
+ };
313
+
43
314
  declare function createStorage(silgi: Silgi): Promise<Storage<StorageValue>>;
44
315
  declare function useSilgiStorage<T extends StorageValue = StorageValue>(base?: StorageConfig<T>['base'] | (string & {})): Storage<T>;
45
316
 
46
- declare enum HttpStatus {
47
- /** [100] Server has received the request headers and client should proceed to send the request body */
48
- CONTINUE = 100,
49
- /** [101] Server is switching protocols according to Upgrade header */
50
- SWITCHING_PROTOCOLS = 101,
51
- /** [102] Server is processing the request but no response is available yet */
52
- PROCESSING = 102,
53
- /** [103] Server is likely to send a final response with the header fields in the informational response */
54
- EARLY_HINTS = 103,
55
- /** [200] Request succeeded and response contains requested data */
56
- OK = 200,
57
- /** [201] Request succeeded and new resource has been created */
58
- CREATED = 201,
59
- /** [202] Request accepted for processing but processing not completed */
60
- ACCEPTED = 202,
61
- /** [203] Request processed successfully but response may be from another source */
62
- NON_AUTHORITATIVE_INFORMATION = 203,
63
- /** [204] Request processed successfully but response has no content */
64
- NO_CONTENT = 204,
65
- /** [205] Server fulfilled the request and client should reset the document view */
66
- RESET_CONTENT = 205,
67
- /** [206] Server delivered only part of the resource due to range header */
68
- PARTIAL_CONTENT = 206,
69
- /** [207] Response conveys information about multiple resources for XML messages */
70
- MULTI_STATUS = 207,
71
- /** [208] Members of DAV binding have already been enumerated and not included again */
72
- ALREADY_REPORTED = 208,
73
- /** [226] Server has fulfilled a GET request, response is result of transformations */
74
- IM_USED = 226,
75
- /** [300] Multiple options for the resource from which client may choose */
76
- MULTIPLE_CHOICES = 300,
77
- /** [301] Resource permanently moved to new URL */
78
- MOVED_PERMANENTLY = 301,
79
- /** [302] Resource temporarily moved to different URL */
80
- FOUND = 302,
81
- /** [303] Response to request found at another URL using GET */
82
- SEE_OTHER = 303,
83
- /** [304] Resource has not been modified since last requested */
84
- NOT_MODIFIED = 304,
85
- /** [305] Deprecated. Resource must be accessed through proxy */
86
- USE_PROXY = 305,
87
- /** [307] Resource temporarily moved to different URL, keep method */
88
- TEMPORARY_REDIRECT = 307,
89
- /** [308] Resource permanently moved to different URL, keep method */
90
- PERMANENT_REDIRECT = 308,
91
- /** [400] Request malformed, syntax error or invalid request */
92
- BAD_REQUEST = 400,
93
- /** [401] Request requires user authentication or authorization */
94
- UNAUTHORIZED = 401,
95
- /** [402] Reserved for future use, payment required */
96
- PAYMENT_REQUIRED = 402,
97
- /** [403] Server understood request but refuses to authorize it */
98
- FORBIDDEN = 403,
99
- /** [404] Server cannot find the requested resource */
100
- NOT_FOUND = 404,
101
- /** [405] Request method (GET, POST, etc.) not supported for this resource */
102
- METHOD_NOT_ALLOWED = 405,
103
- /** [406] Resource cannot generate response matching accept headers */
104
- NOT_ACCEPTABLE = 406,
105
- /** [407] Client must first authenticate with the proxy */
106
- PROXY_AUTHENTICATION_REQUIRED = 407,
107
- /** [408] Server timed out waiting for the request */
108
- REQUEST_TIMEOUT = 408,
109
- /** [409] Request conflicts with current state of the server */
110
- CONFLICT = 409,
111
- /** [410] Resource requested is no longer available and will not be available again */
112
- GONE = 410,
113
- /** [411] Server requires Content-Length header field */
114
- LENGTH_REQUIRED = 411,
115
- /** [412] Precondition given in request headers evaluated to false */
116
- PRECONDITION_FAILED = 412,
117
- /** [413] Request entity larger than limits defined by server */
118
- PAYLOAD_TOO_LARGE = 413,
119
- /** [414] URI requested by client is longer than server can interpret */
120
- URI_TOO_LONG = 414,
121
- /** [415] Media format of requested data not supported by server */
122
- UNSUPPORTED_MEDIA_TYPE = 415,
123
- /** [416] Range specified by Range header cannot be fulfilled */
124
- RANGE_NOT_SATISFIABLE = 416,
125
- /** [417] Expectation indicated by Expect header cannot be met */
126
- EXPECTATION_FAILED = 417,
127
- /** [418] April Fools' joke by RFC 2324 - Server refuses to brew coffee in a teapot */
128
- IM_A_TEAPOT = 418,
129
- /** [421] Request directed at a server that is not configured to produce a response */
130
- MISDIRECTED_REQUEST = 421,
131
- /** [422] Server understands content type but cannot process contained instructions */
132
- UNPROCESSABLE_ENTITY = 422,
133
- /** [423] Requested resource is currently locked */
134
- LOCKED = 423,
135
- /** [424] Request failed due to failure of a previous request */
136
- FAILED_DEPENDENCY = 424,
137
- /** [425] Server is unwilling to risk processing a request that might be replayed */
138
- TOO_EARLY = 425,
139
- /** [426] Server requires client to upgrade to a different protocol */
140
- UPGRADE_REQUIRED = 426,
141
- /** [428] Origin server requires request to be conditional */
142
- PRECONDITION_REQUIRED = 428,
143
- /** [429] User has sent too many requests in a given time period */
144
- TOO_MANY_REQUESTS = 429,
145
- /** [431] Server refusing to process request due to oversized headers */
146
- REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
147
- /** [451] Server denies access for legal reasons (e.g., censorship) */
148
- UNAVAILABLE_FOR_LEGAL_REASONS = 451,
149
- /** [500] Generic server error, no specific message */
150
- INTERNAL_SERVER_ERROR = 500,
151
- /** [501] Server does not recognize method or lacks ability to fulfill */
152
- NOT_IMPLEMENTED = 501,
153
- /** [502] Bad response received from upstream server */
154
- BAD_GATEWAY = 502,
155
- /** [503] Server temporarily unavailable (overloaded/maintenance) */
156
- SERVICE_UNAVAILABLE = 503,
157
- /** [504] Gateway server did not get response from upstream server */
158
- GATEWAY_TIMEOUT = 504,
159
- /** [505] Server does not support the HTTP protocol version */
160
- HTTP_VERSION_NOT_SUPPORTED = 505,
161
- /** [506] Server has a circular reference in content negotiation */
162
- VARIANT_ALSO_NEGOTIATES = 506,
163
- /** [507] Server has insufficient storage to complete request */
164
- INSUFFICIENT_STORAGE = 507,
165
- /** [508] Server detected an infinite loop while processing request */
166
- LOOP_DETECTED = 508,
167
- /** [510] Further extensions needed for server to fulfill request */
168
- NOT_EXTENDED = 510,
169
- /** [511] Client needs to authenticate to gain network access */
170
- NETWORK_AUTHENTICATION_REQUIRED = 511
171
- }
172
- declare enum ErrorSeverity {
173
- DEBUG = "DEBUG",
174
- INFO = "INFO",
175
- WARNING = "WARNING",
176
- ERROR = "ERROR",
177
- CRITICAL = "CRITICAL"
178
- }
179
- declare enum ErrorCategory {
180
- AUTHENTICATION = "auth",
181
- AUTHORIZATION = "authorization",
182
- VALIDATION = "validation",
183
- BUSINESS = "business",
184
- INFRASTRUCTURE = "infrastructure",
185
- EXTERNAL = "external",
186
- UNKNOWN = "unknown"
187
- }
188
- interface ErrorMetadata {
189
- timestamp: number;
190
- correlationId?: string;
191
- requestId?: string;
192
- userId?: string;
193
- path?: string;
194
- source?: string;
195
- [key: string]: unknown;
196
- }
197
- interface BaseError {
198
- code: number;
199
- message: string;
200
- category: ErrorCategory;
201
- severity: ErrorSeverity;
202
- httpStatus: HttpStatus;
203
- metadata?: ErrorMetadata;
204
- cause?: Error;
205
- context?: Record<string, unknown>;
206
- }
207
- declare class ErrorFactory {
208
- private static createMetadata;
209
- static create(options: Partial<BaseError> & {
210
- message: string;
211
- }): SilgiError;
212
- static authenticationError(message: string, context?: Record<string, unknown>): SilgiError;
213
- static authorizationError(message: string, context?: Record<string, unknown>): SilgiError;
214
- static validationError(message: string, context?: Record<string, unknown>): SilgiError;
215
- static notFoundError(message: string, context?: Record<string, unknown>): SilgiError;
216
- static internalError(message: string, cause?: Error): SilgiError;
217
- }
218
- declare class SilgiError extends Error implements BaseError {
219
- readonly code: number;
220
- readonly category: ErrorCategory;
221
- readonly severity: ErrorSeverity;
222
- readonly httpStatus: HttpStatus;
223
- readonly metadata: ErrorMetadata;
224
- readonly context?: Record<string, unknown>;
225
- readonly cause?: Error;
226
- constructor(error: BaseError);
227
- toString(): string;
228
- toJSON(): Record<string, unknown>;
229
- static isError(error: unknown): error is SilgiError;
230
- static from(error: unknown): SilgiError;
231
- }
232
- declare function isBaseError(error: unknown): error is BaseError;
233
-
234
317
  declare const silgiCtx: UseContext<Silgi>;
235
318
  declare function useSilgi(): Silgi;
236
319
  /**
@@ -255,5 +338,4 @@ declare function storageMount<T extends Storage = Storage>(silgi?: Silgi): (base
255
338
 
256
339
  declare const autoImportTypes: string[];
257
340
 
258
- export { ErrorCategory, ErrorFactory, ErrorSeverity, HttpStatus, SilgiError, autoImportTypes, createSchema, createService, createShared, createSilgi, createStorage, getEvent, getEventContext, isBaseError, mergeSchemas, mergeServices, mergeShared, parseURI, replaceRuntimeValues, silgi, silgiCLICtx, silgiCtx, storageMount, tryUseSilgi, tryUseSilgiCLI, useSilgi, useSilgiCLI, useSilgiStorage };
259
- export type { BaseError, ErrorMetadata };
341
+ export { SilgiError, autoImportTypes, createError, createRoute, createSchema, createService, createShared, createSilgi, createSilgiCore, createStorage, deepMergeObjects, getEvent, getEventContext, handleResponse, isError, replaceRuntimeValues, silgiCLICtx, silgiCtx, silgiFetch, storageMount, tryUseSilgi, tryUseSilgiCLI, useSilgi, useSilgiCLI, useSilgiStorage };