silgi 0.24.19 → 0.24.21

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/index.d.mts CHANGED
@@ -1,285 +1,5 @@
1
- import * as unctx from 'unctx';
2
- import { Silgi, SilgiCLI, SilgiConfig, SilgiEvents, SilgiFunction, SilgiOperation, MergedSilgiSchema, ServiceType, SilgiSchema, RequiredServiceType, SilgiRuntimeSharedsExtend, SilgiRuntimeContext, DefaultNamespaces, BaseSchemaType, SilgiRuntimeShareds, StorageConfig, SilgiStorageBase, SilgiCLIConfig, LoadConfigOptions, SilgiCLIOptions, DotenvOptions } from 'silgi/types';
3
- import { StandardSchemaV1 } from '@standard-schema/spec';
4
- import { Storage, StorageValue } from 'unstorage';
5
- import { Stats } from 'node:fs';
6
-
7
- declare const silgiAppCtx: unctx.UseContext<Silgi>;
8
- declare const silgiCtx: unctx.UseContext<SilgiCLI>;
9
- declare function useSilgiApp(): Silgi;
10
- /**
11
- * Get access to Nuxt instance.
12
- *
13
- * Returns null if Nuxt instance is unavailable.
14
- * @example
15
- * ```js
16
- * const silgi = tryUseSilgiApp()
17
- * if (silgi) {
18
- * // Do something
19
- * }
20
- * ```
21
- */
22
- declare function tryUseSilgiApp(): Silgi | null;
23
- declare function useSilgi(): SilgiCLI;
24
- declare function silgiClose(): Promise<void>;
25
- declare function tryUseSilgi(): SilgiCLI | null;
26
-
27
- declare function createSilgiApp(config: SilgiConfig): Promise<Silgi>;
28
-
29
- declare function silgi(event?: SilgiEvents | Record<string, any>): SilgiFunction;
30
-
31
- interface RouteTemplateValidator {
32
- (value: string): boolean;
33
- }
34
- interface RouteTemplateConfig {
35
- pattern: string;
36
- validators?: Record<string, RouteTemplateValidator>;
37
- }
38
- type URITemplate = string | RouteTemplateConfig;
39
- declare function parseURI(uri: string, uris: Record<string, URITemplate>): SilgiOperation;
40
-
41
- type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
42
- declare function mergeSchemas<T extends MergedSilgiSchema[]>(typesOrArray: [...T] | T): UnionToIntersection<T[number]>;
43
- declare function mergeServices<T extends ServiceType<SilgiSchema>[]>(servicesOrArray: [...T] | T): RequiredServiceType<SilgiSchema>;
44
- declare function mergeShared<T extends SilgiRuntimeSharedsExtend[]>(sharedOrArray: [...T] | T): UnionToIntersection<T[number]>;
45
-
46
- declare function getEvent<T extends SilgiEvents>(event?: SilgiEvents): T;
47
- declare function getEventContext<T extends SilgiRuntimeContext>(event?: SilgiEvents): T;
48
-
49
- declare function createSchema<T extends Partial<Record<keyof DefaultNamespaces, Record<string, BaseSchemaType<StandardSchemaV1>>>>>(silgiType: T): {
50
- [K in keyof T]: {
51
- [P in keyof T[K]]: T[K][P];
52
- };
53
- };
54
-
55
- declare function createService<T extends SilgiSchema>(variables: ServiceType<T>): ServiceType<T>;
56
-
57
- declare function createShared(shared: Partial<SilgiRuntimeShareds>): SilgiRuntimeShareds;
58
-
59
- /**
60
- * Recursively replaces values starting with 'runtime.' with their actual values from runtime config
61
- */
62
- declare function replaceRuntimeValues(obj: any, runtime: any): any;
63
-
64
- declare function createStorage(silgi: Silgi): Promise<Storage<StorageValue>>;
65
- declare function useSilgiStorage<T extends StorageValue = StorageValue>(base?: StorageConfig<T>['base'] | (string & {})): Storage<T>;
66
-
67
- declare enum HttpStatus {
68
- /** [100] Server has received the request headers and client should proceed to send the request body */
69
- CONTINUE = 100,
70
- /** [101] Server is switching protocols according to Upgrade header */
71
- SWITCHING_PROTOCOLS = 101,
72
- /** [102] Server is processing the request but no response is available yet */
73
- PROCESSING = 102,
74
- /** [103] Server is likely to send a final response with the header fields in the informational response */
75
- EARLY_HINTS = 103,
76
- /** [200] Request succeeded and response contains requested data */
77
- OK = 200,
78
- /** [201] Request succeeded and new resource has been created */
79
- CREATED = 201,
80
- /** [202] Request accepted for processing but processing not completed */
81
- ACCEPTED = 202,
82
- /** [203] Request processed successfully but response may be from another source */
83
- NON_AUTHORITATIVE_INFORMATION = 203,
84
- /** [204] Request processed successfully but response has no content */
85
- NO_CONTENT = 204,
86
- /** [205] Server fulfilled the request and client should reset the document view */
87
- RESET_CONTENT = 205,
88
- /** [206] Server delivered only part of the resource due to range header */
89
- PARTIAL_CONTENT = 206,
90
- /** [207] Response conveys information about multiple resources for XML messages */
91
- MULTI_STATUS = 207,
92
- /** [208] Members of DAV binding have already been enumerated and not included again */
93
- ALREADY_REPORTED = 208,
94
- /** [226] Server has fulfilled a GET request, response is result of transformations */
95
- IM_USED = 226,
96
- /** [300] Multiple options for the resource from which client may choose */
97
- MULTIPLE_CHOICES = 300,
98
- /** [301] Resource permanently moved to new URL */
99
- MOVED_PERMANENTLY = 301,
100
- /** [302] Resource temporarily moved to different URL */
101
- FOUND = 302,
102
- /** [303] Response to request found at another URL using GET */
103
- SEE_OTHER = 303,
104
- /** [304] Resource has not been modified since last requested */
105
- NOT_MODIFIED = 304,
106
- /** [305] Deprecated. Resource must be accessed through proxy */
107
- USE_PROXY = 305,
108
- /** [307] Resource temporarily moved to different URL, keep method */
109
- TEMPORARY_REDIRECT = 307,
110
- /** [308] Resource permanently moved to different URL, keep method */
111
- PERMANENT_REDIRECT = 308,
112
- /** [400] Request malformed, syntax error or invalid request */
113
- BAD_REQUEST = 400,
114
- /** [401] Request requires user authentication or authorization */
115
- UNAUTHORIZED = 401,
116
- /** [402] Reserved for future use, payment required */
117
- PAYMENT_REQUIRED = 402,
118
- /** [403] Server understood request but refuses to authorize it */
119
- FORBIDDEN = 403,
120
- /** [404] Server cannot find the requested resource */
121
- NOT_FOUND = 404,
122
- /** [405] Request method (GET, POST, etc.) not supported for this resource */
123
- METHOD_NOT_ALLOWED = 405,
124
- /** [406] Resource cannot generate response matching accept headers */
125
- NOT_ACCEPTABLE = 406,
126
- /** [407] Client must first authenticate with the proxy */
127
- PROXY_AUTHENTICATION_REQUIRED = 407,
128
- /** [408] Server timed out waiting for the request */
129
- REQUEST_TIMEOUT = 408,
130
- /** [409] Request conflicts with current state of the server */
131
- CONFLICT = 409,
132
- /** [410] Resource requested is no longer available and will not be available again */
133
- GONE = 410,
134
- /** [411] Server requires Content-Length header field */
135
- LENGTH_REQUIRED = 411,
136
- /** [412] Precondition given in request headers evaluated to false */
137
- PRECONDITION_FAILED = 412,
138
- /** [413] Request entity larger than limits defined by server */
139
- PAYLOAD_TOO_LARGE = 413,
140
- /** [414] URI requested by client is longer than server can interpret */
141
- URI_TOO_LONG = 414,
142
- /** [415] Media format of requested data not supported by server */
143
- UNSUPPORTED_MEDIA_TYPE = 415,
144
- /** [416] Range specified by Range header cannot be fulfilled */
145
- RANGE_NOT_SATISFIABLE = 416,
146
- /** [417] Expectation indicated by Expect header cannot be met */
147
- EXPECTATION_FAILED = 417,
148
- /** [418] April Fools' joke by RFC 2324 - Server refuses to brew coffee in a teapot */
149
- IM_A_TEAPOT = 418,
150
- /** [421] Request directed at a server that is not configured to produce a response */
151
- MISDIRECTED_REQUEST = 421,
152
- /** [422] Server understands content type but cannot process contained instructions */
153
- UNPROCESSABLE_ENTITY = 422,
154
- /** [423] Requested resource is currently locked */
155
- LOCKED = 423,
156
- /** [424] Request failed due to failure of a previous request */
157
- FAILED_DEPENDENCY = 424,
158
- /** [425] Server is unwilling to risk processing a request that might be replayed */
159
- TOO_EARLY = 425,
160
- /** [426] Server requires client to upgrade to a different protocol */
161
- UPGRADE_REQUIRED = 426,
162
- /** [428] Origin server requires request to be conditional */
163
- PRECONDITION_REQUIRED = 428,
164
- /** [429] User has sent too many requests in a given time period */
165
- TOO_MANY_REQUESTS = 429,
166
- /** [431] Server refusing to process request due to oversized headers */
167
- REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
168
- /** [451] Server denies access for legal reasons (e.g., censorship) */
169
- UNAVAILABLE_FOR_LEGAL_REASONS = 451,
170
- /** [500] Generic server error, no specific message */
171
- INTERNAL_SERVER_ERROR = 500,
172
- /** [501] Server does not recognize method or lacks ability to fulfill */
173
- NOT_IMPLEMENTED = 501,
174
- /** [502] Bad response received from upstream server */
175
- BAD_GATEWAY = 502,
176
- /** [503] Server temporarily unavailable (overloaded/maintenance) */
177
- SERVICE_UNAVAILABLE = 503,
178
- /** [504] Gateway server did not get response from upstream server */
179
- GATEWAY_TIMEOUT = 504,
180
- /** [505] Server does not support the HTTP protocol version */
181
- HTTP_VERSION_NOT_SUPPORTED = 505,
182
- /** [506] Server has a circular reference in content negotiation */
183
- VARIANT_ALSO_NEGOTIATES = 506,
184
- /** [507] Server has insufficient storage to complete request */
185
- INSUFFICIENT_STORAGE = 507,
186
- /** [508] Server detected an infinite loop while processing request */
187
- LOOP_DETECTED = 508,
188
- /** [510] Further extensions needed for server to fulfill request */
189
- NOT_EXTENDED = 510,
190
- /** [511] Client needs to authenticate to gain network access */
191
- NETWORK_AUTHENTICATION_REQUIRED = 511
192
- }
193
- declare enum ErrorSeverity {
194
- DEBUG = "DEBUG",
195
- INFO = "INFO",
196
- WARNING = "WARNING",
197
- ERROR = "ERROR",
198
- CRITICAL = "CRITICAL"
199
- }
200
- declare enum ErrorCategory {
201
- AUTHENTICATION = "auth",
202
- AUTHORIZATION = "authorization",
203
- VALIDATION = "validation",
204
- BUSINESS = "business",
205
- INFRASTRUCTURE = "infrastructure",
206
- EXTERNAL = "external",
207
- UNKNOWN = "unknown"
208
- }
209
- interface ErrorMetadata {
210
- timestamp: number;
211
- correlationId?: string;
212
- requestId?: string;
213
- userId?: string;
214
- path?: string;
215
- source?: string;
216
- [key: string]: unknown;
217
- }
218
- interface BaseError {
219
- code: number;
220
- message: string;
221
- category: ErrorCategory;
222
- severity: ErrorSeverity;
223
- httpStatus: HttpStatus;
224
- metadata?: ErrorMetadata;
225
- cause?: Error;
226
- context?: Record<string, unknown>;
227
- }
228
- declare class ErrorFactory {
229
- private static createMetadata;
230
- static create(options: Partial<BaseError> & {
231
- message: string;
232
- }): SilgiError;
233
- static authenticationError(message: string, context?: Record<string, unknown>): SilgiError;
234
- static authorizationError(message: string, context?: Record<string, unknown>): SilgiError;
235
- static validationError(message: string, context?: Record<string, unknown>): SilgiError;
236
- static notFoundError(message: string, context?: Record<string, unknown>): SilgiError;
237
- static internalError(message: string, cause?: Error): SilgiError;
238
- }
239
- declare class SilgiError extends Error implements BaseError {
240
- readonly code: number;
241
- readonly category: ErrorCategory;
242
- readonly severity: ErrorSeverity;
243
- readonly httpStatus: HttpStatus;
244
- readonly metadata: ErrorMetadata;
245
- readonly context?: Record<string, unknown>;
246
- readonly cause?: Error;
247
- constructor(error: BaseError);
248
- toString(): string;
249
- toJSON(): Record<string, unknown>;
250
- static isError(error: unknown): error is SilgiError;
251
- static from(error: unknown): SilgiError;
252
- }
253
- declare function isBaseError(error: unknown): error is BaseError;
254
-
255
- declare function storageMount<T extends Storage = Storage>(silgi?: Silgi): (base: keyof SilgiStorageBase, driver: Parameters<Storage['mount']>[1]) => T;
256
-
257
- declare function loadOptions(configOverrides?: SilgiCLIConfig, opts?: LoadConfigOptions): Promise<SilgiCLIOptions>;
258
-
259
- /**
260
- * Prepares route rules for the build
261
- */
262
- declare function prepareBuild(silgi: SilgiCLI): Promise<void>;
263
-
264
- declare function prepare(_silgi: SilgiCLI): Promise<void>;
265
-
266
- declare function reloadScan(path: string, _stats?: Stats): Promise<void>;
267
-
268
- type Env = typeof process.env;
269
- /**
270
- * Load and interpolate environment variables into `process.env`.
271
- * If you need more control (or access to the values), consider using `loadDotenv` instead
272
- *
273
- */
274
- declare function setupDotenv(options: DotenvOptions): Promise<Env>;
275
-
276
- declare function createSilgi(config?: SilgiCLIConfig, opts?: LoadConfigOptions): Promise<SilgiCLI>;
277
-
278
- declare function writeCoreFile(silgi: SilgiCLI): Promise<void>;
279
-
280
- declare function writeTypesAndFiles(silgi: SilgiCLI): Promise<void>;
281
-
282
- declare const autoImportTypes: string[];
283
-
284
- export { ErrorCategory, ErrorFactory, ErrorSeverity, HttpStatus, SilgiError, autoImportTypes, createSchema, createService, createShared, createSilgi, createSilgiApp, createStorage, getEvent, getEventContext, isBaseError, loadOptions, mergeSchemas, mergeServices, mergeShared, parseURI, prepare, prepareBuild, reloadScan, replaceRuntimeValues, setupDotenv, silgi, silgiAppCtx, silgiClose, silgiCtx, storageMount, tryUseSilgi, tryUseSilgiApp, useSilgi, useSilgiApp, useSilgiStorage, writeCoreFile, writeTypesAndFiles };
285
- export type { BaseError, ErrorMetadata };
1
+ export { BaseError, ErrorCategory, ErrorFactory, ErrorMetadata, 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 } from './core/index.mjs';
2
+ import 'silgi/types';
3
+ import '@standard-schema/spec';
4
+ import 'unstorage';
5
+ import 'unctx';