silgi 0.4.12 → 0.6.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,6 +1,6 @@
1
1
  const name = "silgi";
2
2
  const type = "module";
3
- const version = "0.4.12";
3
+ const version = "0.6.0";
4
4
  const packageManager = "pnpm@9.15.1";
5
5
  const sideEffects = false;
6
6
  const exports = {
@@ -93,6 +93,18 @@ async function nitroFramework(silgi, skip = false) {
93
93
  packageImport: "silgi/runtime/internal/nitro",
94
94
  path: join(runtimeDir, "internal/nitro")
95
95
  });
96
+ silgi.hook("prepare:core.ts", (data) => {
97
+ data.importItems["nitropack/runtime"] ??= {
98
+ import: [],
99
+ from: "nitropack/runtime"
100
+ };
101
+ data.importItems["nitropack/runtime"].import.push(
102
+ { name: "useStorage" }
103
+ );
104
+ data._silgiConfigs.push({
105
+ storage: `useStorage()`
106
+ });
107
+ });
96
108
  await h3Framework(silgi, true);
97
109
  }
98
110
 
@@ -112,12 +124,39 @@ async function prepareDir(dir) {
112
124
  await fsp.mkdir(dir, { recursive: true });
113
125
  }
114
126
 
127
+ function myBabelPlugin() {
128
+ return {
129
+ visitor: {
130
+ CallExpression(path) {
131
+ const callee = path.get("callee");
132
+ if (callee.isMemberExpression() && callee.get("object").isIdentifier({ name: "console" }) && callee.get("property").isIdentifier({ name: "log" })) {
133
+ callee.get("property").replaceWithSourceString("warn");
134
+ }
135
+ },
136
+ StringLiteral(path) {
137
+ if (path.node.value === "nitropack/runtime") {
138
+ path.replaceWithSourceString("'silgi/runtime'");
139
+ }
140
+ }
141
+ }
142
+ };
143
+ }
115
144
  async function readCoreFile(silgi) {
116
145
  const path = resolve(silgi.options.silgi.serverDir, "core.ts");
117
146
  const jiti = createJiti(silgi.options.rootDir, {
118
147
  fsCache: false,
119
148
  interopDefault: true,
120
149
  moduleCache: false,
150
+ transformOptions: {
151
+ babel: {
152
+ plugins: [myBabelPlugin()]
153
+ }
154
+ },
155
+ // debug: true,
156
+ // transform(opts) {
157
+ // console.log(opts)
158
+ // return babelTransform(opts)
159
+ // },
121
160
  alias: silgi.options.alias
122
161
  });
123
162
  const resolvedPath = jiti.esmResolve(path);
@@ -188,16 +227,19 @@ function scanActionModulesUris(silgi, obj, currentPath = []) {
188
227
  if (path.length === 4) {
189
228
  const basePath = path.join("/");
190
229
  let moduleName = "";
191
- if (node.modules?.graphqlyoga) {
230
+ if (node.modules?.yoga) {
192
231
  let rootFieldName = null;
193
- if (node.modules?.graphqlyoga?.rootFieldName) {
194
- moduleName = "graphqlyoga";
195
- rootFieldName = node.modules?.graphqlyoga?.rootFieldName;
232
+ if (node.modules?.yoga?.rootFieldName) {
233
+ moduleName = "yoga";
234
+ rootFieldName = node.modules?.yoga?.rootFieldName;
196
235
  }
197
236
  if (!rootFieldName) {
198
237
  return;
199
238
  }
200
239
  uriMap[moduleName] ??= {};
240
+ if (uriMap[moduleName].rootFieldName) {
241
+ silgi.logger.withTag("scanActionModulesUris").error(`Hata ${moduleName} ${rootFieldName} ${basePath} bu zaten burada kullanilmis.`);
242
+ }
201
243
  uriMap[moduleName].rootFieldName ??= {};
202
244
  uriMap[moduleName].rootFieldName[rootFieldName] = basePath;
203
245
  }
@@ -360,7 +402,7 @@ async function createCoreFramework(silgi) {
360
402
  functions
361
403
  });
362
404
  const content = [
363
- ...functions.map((f) => ` await ${f}(framework)`)
405
+ ...functions.map((f) => f.params?.length ? ` await ${f.name}(framework, ${f.params.join(",")})` : ` await ${f.name}(framework)`)
364
406
  ];
365
407
  return {
366
408
  content,
@@ -535,7 +577,8 @@ async function silgiCoreFile(data, frameworkContext, silgi) {
535
577
  import: [
536
578
  { name: "SilgiModuleOptions", type: true },
537
579
  { name: "SilgiOptions", type: true },
538
- { name: "FrameworkContext", type: true }
580
+ { name: "FrameworkContext", type: true },
581
+ { name: "DeepPartial", type: true }
539
582
  ],
540
583
  from: "silgi/types"
541
584
  }
@@ -559,6 +602,13 @@ async function silgiCoreFile(data, frameworkContext, silgi) {
559
602
  const shareds = [];
560
603
  const schemas = [];
561
604
  const buildSilgiExtraContent = [];
605
+ const _silgiOptions = {};
606
+ const _silgiConfigs = [];
607
+ for (const module of silgi.scanModules) {
608
+ _silgiOptions[module.meta.configKey] = {
609
+ ...module.options
610
+ };
611
+ }
562
612
  await silgi.callHook("prepare:core.ts", {
563
613
  importItems,
564
614
  customImports,
@@ -566,7 +616,9 @@ async function silgiCoreFile(data, frameworkContext, silgi) {
566
616
  services,
567
617
  shareds,
568
618
  schemas,
569
- buildSilgiExtraContent
619
+ buildSilgiExtraContent,
620
+ _silgiOptions,
621
+ _silgiConfigs
570
622
  });
571
623
  if (services.length > 0) {
572
624
  importItems["silgi/core"].import.push({ name: "mergeServices" });
@@ -613,6 +665,7 @@ async function silgiCoreFile(data, frameworkContext, silgi) {
613
665
  }),
614
666
  shareds.length > 0 ? "])" : "}",
615
667
  "",
668
+ `export const _silgiOptions: DeepPartial<SilgiModuleOptions> = ${JSON.stringify(_silgiOptions, null, 2)}`,
616
669
  "",
617
670
  "export async function buildSilgi(framework: FrameworkContext, options?: Partial<SilgiModuleOptions>) {",
618
671
  " const silgi = await createSilgi({",
@@ -623,8 +676,10 @@ async function silgiCoreFile(data, frameworkContext, silgi) {
623
676
  " uris,",
624
677
  " modulesURIs,",
625
678
  ` plugins: [${plugins.join(", ")}],`,
626
- "",
679
+ _silgiConfigs.length > 0 ? ` ${_silgiConfigs.map((config) => Object.entries(config).map(([key, value]) => `${key}: ${value}`)).join(",\n ")},` : "",
627
680
  " options: {",
681
+ ` present: '${silgi.options.preset}',`,
682
+ " ..._silgiOptions,",
628
683
  " ...options,",
629
684
  " },",
630
685
  " })",
@@ -989,7 +1044,8 @@ async function _resolveSilgiModule(mod, silgi) {
989
1044
  silgi.scanModules.push({
990
1045
  meta: buildTimeModuleMeta,
991
1046
  entryPath: _url,
992
- installed: false
1047
+ installed: false,
1048
+ options: await mod.getOptions?.() || {}
993
1049
  });
994
1050
  }
995
1051
  }
@@ -1334,8 +1390,11 @@ async function createSilgiCLI(config = {}, opts = {}) {
1334
1390
  }
1335
1391
  await scanAndSyncOptions(silgi);
1336
1392
  await scanModules$1(silgi);
1337
- await scanFiles$1(silgi);
1338
- await graphqlLoadSync(silgi);
1393
+ try {
1394
+ await scanFiles$1(silgi);
1395
+ await graphqlLoadSync(silgi);
1396
+ } catch {
1397
+ }
1339
1398
  silgi.storage = await createStorageCLI(silgi);
1340
1399
  silgi.hooks.hook("close", async () => {
1341
1400
  await silgi.storage.dispose();
@@ -1,7 +1,7 @@
1
1
  import { SilgiCLIConfig, LoadConfigOptions, SilgiCLIOptions, SilgiCLI, SilgiConfig, Silgi, SilgiRouterTypes, SilgiOperation, MergedSilgiSchema, ServiceType, SilgiSchema, RequiredServiceType, SilgiModuleShared, SilgiEvent, DefaultNamespaces, BaseSchemaType } from 'silgi/types';
2
2
  import { TSConfig } from 'pkg-types';
3
3
  import { FetchOptions } from 'ofetch';
4
- export { c as createStorage, s as silgi } from '../shared/silgi.40ZJYm8F.mjs';
4
+ export { c as createStorage, s as silgi, u as useStorage } from '../shared/silgi.DRWtysQv.mjs';
5
5
  import { StandardSchemaV1 } from '@standard-schema/spec';
6
6
  import 'unstorage';
7
7
 
@@ -98,47 +98,194 @@ declare function createService<T extends SilgiSchema>(variables: ServiceType<T>)
98
98
 
99
99
  declare function createShared(shared: Partial<SilgiModuleShared>): SilgiModuleShared;
100
100
 
101
- declare enum SilgiErrorCode {
102
- AUTH_UNAUTHORIZED = "AUTH_UNAUTHORIZED",
103
- AUTH_MISSING_CONTEXT = "AUTH_MISSING_CONTEXT",
104
- AUTH_INVALID_CONTEXT = "AUTH_INVALID_CONTEXT",
105
- AUTH_PERMISSION_DENIED = "AUTH_PERMISSION_DENIED",
106
- PLUGIN_ERROR = "PLUGIN_ERROR",
107
- METHOD_NOT_FOUND = "METHOD_NOT_FOUND",
108
- EXECUTION_ERROR = "EXECUTION_ERROR",
109
- CACHE_ERROR = "CACHE_ERROR",
110
- PLUGIN_ALREADY_EXISTS = "PLUGIN_ALREADY_EXISTS",
111
- PLUGIN_NOT_FOUND = "PLUGIN_NOT_FOUND",
112
- PLUGIN_INIT_ERROR = "PLUGIN_INIT_ERROR"
101
+ declare enum HttpStatus {
102
+ /** [100] Server has received the request headers and client should proceed to send the request body */
103
+ CONTINUE = 100,
104
+ /** [101] Server is switching protocols according to Upgrade header */
105
+ SWITCHING_PROTOCOLS = 101,
106
+ /** [102] Server is processing the request but no response is available yet */
107
+ PROCESSING = 102,
108
+ /** [103] Server is likely to send a final response with the header fields in the informational response */
109
+ EARLY_HINTS = 103,
110
+ /** [200] Request succeeded and response contains requested data */
111
+ OK = 200,
112
+ /** [201] Request succeeded and new resource has been created */
113
+ CREATED = 201,
114
+ /** [202] Request accepted for processing but processing not completed */
115
+ ACCEPTED = 202,
116
+ /** [203] Request processed successfully but response may be from another source */
117
+ NON_AUTHORITATIVE_INFORMATION = 203,
118
+ /** [204] Request processed successfully but response has no content */
119
+ NO_CONTENT = 204,
120
+ /** [205] Server fulfilled the request and client should reset the document view */
121
+ RESET_CONTENT = 205,
122
+ /** [206] Server delivered only part of the resource due to range header */
123
+ PARTIAL_CONTENT = 206,
124
+ /** [207] Response conveys information about multiple resources for XML messages */
125
+ MULTI_STATUS = 207,
126
+ /** [208] Members of DAV binding have already been enumerated and not included again */
127
+ ALREADY_REPORTED = 208,
128
+ /** [226] Server has fulfilled a GET request, response is result of transformations */
129
+ IM_USED = 226,
130
+ /** [300] Multiple options for the resource from which client may choose */
131
+ MULTIPLE_CHOICES = 300,
132
+ /** [301] Resource permanently moved to new URL */
133
+ MOVED_PERMANENTLY = 301,
134
+ /** [302] Resource temporarily moved to different URL */
135
+ FOUND = 302,
136
+ /** [303] Response to request found at another URL using GET */
137
+ SEE_OTHER = 303,
138
+ /** [304] Resource has not been modified since last requested */
139
+ NOT_MODIFIED = 304,
140
+ /** [305] Deprecated. Resource must be accessed through proxy */
141
+ USE_PROXY = 305,
142
+ /** [307] Resource temporarily moved to different URL, keep method */
143
+ TEMPORARY_REDIRECT = 307,
144
+ /** [308] Resource permanently moved to different URL, keep method */
145
+ PERMANENT_REDIRECT = 308,
146
+ /** [400] Request malformed, syntax error or invalid request */
147
+ BAD_REQUEST = 400,
148
+ /** [401] Request requires user authentication or authorization */
149
+ UNAUTHORIZED = 401,
150
+ /** [402] Reserved for future use, payment required */
151
+ PAYMENT_REQUIRED = 402,
152
+ /** [403] Server understood request but refuses to authorize it */
153
+ FORBIDDEN = 403,
154
+ /** [404] Server cannot find the requested resource */
155
+ NOT_FOUND = 404,
156
+ /** [405] Request method (GET, POST, etc.) not supported for this resource */
157
+ METHOD_NOT_ALLOWED = 405,
158
+ /** [406] Resource cannot generate response matching accept headers */
159
+ NOT_ACCEPTABLE = 406,
160
+ /** [407] Client must first authenticate with the proxy */
161
+ PROXY_AUTHENTICATION_REQUIRED = 407,
162
+ /** [408] Server timed out waiting for the request */
163
+ REQUEST_TIMEOUT = 408,
164
+ /** [409] Request conflicts with current state of the server */
165
+ CONFLICT = 409,
166
+ /** [410] Resource requested is no longer available and will not be available again */
167
+ GONE = 410,
168
+ /** [411] Server requires Content-Length header field */
169
+ LENGTH_REQUIRED = 411,
170
+ /** [412] Precondition given in request headers evaluated to false */
171
+ PRECONDITION_FAILED = 412,
172
+ /** [413] Request entity larger than limits defined by server */
173
+ PAYLOAD_TOO_LARGE = 413,
174
+ /** [414] URI requested by client is longer than server can interpret */
175
+ URI_TOO_LONG = 414,
176
+ /** [415] Media format of requested data not supported by server */
177
+ UNSUPPORTED_MEDIA_TYPE = 415,
178
+ /** [416] Range specified by Range header cannot be fulfilled */
179
+ RANGE_NOT_SATISFIABLE = 416,
180
+ /** [417] Expectation indicated by Expect header cannot be met */
181
+ EXPECTATION_FAILED = 417,
182
+ /** [418] April Fools' joke by RFC 2324 - Server refuses to brew coffee in a teapot */
183
+ IM_A_TEAPOT = 418,
184
+ /** [421] Request directed at a server that is not configured to produce a response */
185
+ MISDIRECTED_REQUEST = 421,
186
+ /** [422] Server understands content type but cannot process contained instructions */
187
+ UNPROCESSABLE_ENTITY = 422,
188
+ /** [423] Requested resource is currently locked */
189
+ LOCKED = 423,
190
+ /** [424] Request failed due to failure of a previous request */
191
+ FAILED_DEPENDENCY = 424,
192
+ /** [425] Server is unwilling to risk processing a request that might be replayed */
193
+ TOO_EARLY = 425,
194
+ /** [426] Server requires client to upgrade to a different protocol */
195
+ UPGRADE_REQUIRED = 426,
196
+ /** [428] Origin server requires request to be conditional */
197
+ PRECONDITION_REQUIRED = 428,
198
+ /** [429] User has sent too many requests in a given time period */
199
+ TOO_MANY_REQUESTS = 429,
200
+ /** [431] Server refusing to process request due to oversized headers */
201
+ REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
202
+ /** [451] Server denies access for legal reasons (e.g., censorship) */
203
+ UNAVAILABLE_FOR_LEGAL_REASONS = 451,
204
+ /** [500] Generic server error, no specific message */
205
+ INTERNAL_SERVER_ERROR = 500,
206
+ /** [501] Server does not recognize method or lacks ability to fulfill */
207
+ NOT_IMPLEMENTED = 501,
208
+ /** [502] Bad response received from upstream server */
209
+ BAD_GATEWAY = 502,
210
+ /** [503] Server temporarily unavailable (overloaded/maintenance) */
211
+ SERVICE_UNAVAILABLE = 503,
212
+ /** [504] Gateway server did not get response from upstream server */
213
+ GATEWAY_TIMEOUT = 504,
214
+ /** [505] Server does not support the HTTP protocol version */
215
+ HTTP_VERSION_NOT_SUPPORTED = 505,
216
+ /** [506] Server has a circular reference in content negotiation */
217
+ VARIANT_ALSO_NEGOTIATES = 506,
218
+ /** [507] Server has insufficient storage to complete request */
219
+ INSUFFICIENT_STORAGE = 507,
220
+ /** [508] Server detected an infinite loop while processing request */
221
+ LOOP_DETECTED = 508,
222
+ /** [510] Further extensions needed for server to fulfill request */
223
+ NOT_EXTENDED = 510,
224
+ /** [511] Client needs to authenticate to gain network access */
225
+ NETWORK_AUTHENTICATION_REQUIRED = 511
113
226
  }
114
- interface SilgiErrorOptions {
115
- code: SilgiErrorCode | string;
227
+ declare enum ErrorSeverity {
228
+ DEBUG = "DEBUG",
229
+ INFO = "INFO",
230
+ WARNING = "WARNING",
231
+ ERROR = "ERROR",
232
+ CRITICAL = "CRITICAL"
233
+ }
234
+ declare enum ErrorCategory {
235
+ AUTHENTICATION = "auth",
236
+ AUTHORIZATION = "authorization",
237
+ VALIDATION = "validation",
238
+ BUSINESS = "business",
239
+ INFRASTRUCTURE = "infrastructure",
240
+ EXTERNAL = "external",
241
+ UNKNOWN = "unknown"
242
+ }
243
+ interface ErrorMetadata {
244
+ timestamp: number;
245
+ correlationId?: string;
246
+ requestId?: string;
247
+ userId?: string;
248
+ path?: string;
249
+ source?: string;
250
+ [key: string]: unknown;
251
+ }
252
+ interface BaseError {
253
+ code: number;
116
254
  message: string;
255
+ category: ErrorCategory;
256
+ severity: ErrorSeverity;
257
+ httpStatus: HttpStatus;
258
+ metadata?: ErrorMetadata;
117
259
  cause?: Error;
118
- details?: Record<string, unknown>;
119
- meta?: Record<string, unknown>;
260
+ context?: Record<string, unknown>;
120
261
  }
121
- declare class SilgiError extends Error {
122
- readonly code: string;
123
- readonly details?: Record<string, unknown>;
124
- readonly meta?: Record<string, unknown>;
125
- readonly timestamp: number;
126
- cause?: Error;
127
- constructor(options: SilgiErrorOptions);
128
- toString(): string;
129
- toJSON(): {
130
- name: string;
131
- code: string;
262
+ declare class ErrorFactory {
263
+ private static createMetadata;
264
+ static create(options: Partial<BaseError> & {
132
265
  message: string;
133
- details: Record<string, unknown> | undefined;
134
- meta: Record<string, unknown> | undefined;
135
- timestamp: number;
136
- stack: string | undefined;
137
- };
138
- static createFrom(error: unknown, code?: string): SilgiError;
139
- static isSilgiError(error: unknown): error is SilgiError;
266
+ }): SilgiError;
267
+ static authenticationError(message: string, context?: Record<string, unknown>): SilgiError;
268
+ static authorizationError(message: string, context?: Record<string, unknown>): SilgiError;
269
+ static validationError(message: string, context?: Record<string, unknown>): SilgiError;
270
+ static notFoundError(message: string, context?: Record<string, unknown>): SilgiError;
271
+ static internalError(message: string, cause?: Error): SilgiError;
272
+ }
273
+ declare class SilgiError extends Error implements BaseError {
274
+ readonly code: number;
275
+ readonly category: ErrorCategory;
276
+ readonly severity: ErrorSeverity;
277
+ readonly httpStatus: HttpStatus;
278
+ readonly metadata: ErrorMetadata;
279
+ readonly context?: Record<string, unknown>;
280
+ readonly cause?: Error;
281
+ constructor(error: BaseError);
282
+ toString(): string;
283
+ toJSON(): Record<string, unknown>;
284
+ static isError(error: unknown): error is SilgiError;
285
+ static from(error: unknown): SilgiError;
140
286
  }
287
+ declare function isBaseError(error: unknown): error is BaseError;
141
288
 
142
289
  declare function useSilgi(): Silgi;
143
290
 
144
- export { SchemaParser, SilgiError, createSchema, createService, createShared, createSilgi, createSilgiFetch, getEvent, loadOptions, mergeSchemas, mergeServices, mergeShared, parseURI, silgiGenerateType, useSilgi };
291
+ export { type BaseError, ErrorCategory, ErrorFactory, type ErrorMetadata, ErrorSeverity, HttpStatus, SchemaParser, SilgiError, createSchema, createService, createShared, createSilgi, createSilgiFetch, getEvent, isBaseError, loadOptions, mergeSchemas, mergeServices, mergeShared, parseURI, silgiGenerateType, useSilgi };
@@ -1,7 +1,7 @@
1
1
  import { SilgiCLIConfig, LoadConfigOptions, SilgiCLIOptions, SilgiCLI, SilgiConfig, Silgi, SilgiRouterTypes, SilgiOperation, MergedSilgiSchema, ServiceType, SilgiSchema, RequiredServiceType, SilgiModuleShared, SilgiEvent, DefaultNamespaces, BaseSchemaType } from 'silgi/types';
2
2
  import { TSConfig } from 'pkg-types';
3
3
  import { FetchOptions } from 'ofetch';
4
- export { c as createStorage, s as silgi } from '../shared/silgi.40ZJYm8F.js';
4
+ export { c as createStorage, s as silgi, u as useStorage } from '../shared/silgi.DRWtysQv.js';
5
5
  import { StandardSchemaV1 } from '@standard-schema/spec';
6
6
  import 'unstorage';
7
7
 
@@ -98,47 +98,194 @@ declare function createService<T extends SilgiSchema>(variables: ServiceType<T>)
98
98
 
99
99
  declare function createShared(shared: Partial<SilgiModuleShared>): SilgiModuleShared;
100
100
 
101
- declare enum SilgiErrorCode {
102
- AUTH_UNAUTHORIZED = "AUTH_UNAUTHORIZED",
103
- AUTH_MISSING_CONTEXT = "AUTH_MISSING_CONTEXT",
104
- AUTH_INVALID_CONTEXT = "AUTH_INVALID_CONTEXT",
105
- AUTH_PERMISSION_DENIED = "AUTH_PERMISSION_DENIED",
106
- PLUGIN_ERROR = "PLUGIN_ERROR",
107
- METHOD_NOT_FOUND = "METHOD_NOT_FOUND",
108
- EXECUTION_ERROR = "EXECUTION_ERROR",
109
- CACHE_ERROR = "CACHE_ERROR",
110
- PLUGIN_ALREADY_EXISTS = "PLUGIN_ALREADY_EXISTS",
111
- PLUGIN_NOT_FOUND = "PLUGIN_NOT_FOUND",
112
- PLUGIN_INIT_ERROR = "PLUGIN_INIT_ERROR"
101
+ declare enum HttpStatus {
102
+ /** [100] Server has received the request headers and client should proceed to send the request body */
103
+ CONTINUE = 100,
104
+ /** [101] Server is switching protocols according to Upgrade header */
105
+ SWITCHING_PROTOCOLS = 101,
106
+ /** [102] Server is processing the request but no response is available yet */
107
+ PROCESSING = 102,
108
+ /** [103] Server is likely to send a final response with the header fields in the informational response */
109
+ EARLY_HINTS = 103,
110
+ /** [200] Request succeeded and response contains requested data */
111
+ OK = 200,
112
+ /** [201] Request succeeded and new resource has been created */
113
+ CREATED = 201,
114
+ /** [202] Request accepted for processing but processing not completed */
115
+ ACCEPTED = 202,
116
+ /** [203] Request processed successfully but response may be from another source */
117
+ NON_AUTHORITATIVE_INFORMATION = 203,
118
+ /** [204] Request processed successfully but response has no content */
119
+ NO_CONTENT = 204,
120
+ /** [205] Server fulfilled the request and client should reset the document view */
121
+ RESET_CONTENT = 205,
122
+ /** [206] Server delivered only part of the resource due to range header */
123
+ PARTIAL_CONTENT = 206,
124
+ /** [207] Response conveys information about multiple resources for XML messages */
125
+ MULTI_STATUS = 207,
126
+ /** [208] Members of DAV binding have already been enumerated and not included again */
127
+ ALREADY_REPORTED = 208,
128
+ /** [226] Server has fulfilled a GET request, response is result of transformations */
129
+ IM_USED = 226,
130
+ /** [300] Multiple options for the resource from which client may choose */
131
+ MULTIPLE_CHOICES = 300,
132
+ /** [301] Resource permanently moved to new URL */
133
+ MOVED_PERMANENTLY = 301,
134
+ /** [302] Resource temporarily moved to different URL */
135
+ FOUND = 302,
136
+ /** [303] Response to request found at another URL using GET */
137
+ SEE_OTHER = 303,
138
+ /** [304] Resource has not been modified since last requested */
139
+ NOT_MODIFIED = 304,
140
+ /** [305] Deprecated. Resource must be accessed through proxy */
141
+ USE_PROXY = 305,
142
+ /** [307] Resource temporarily moved to different URL, keep method */
143
+ TEMPORARY_REDIRECT = 307,
144
+ /** [308] Resource permanently moved to different URL, keep method */
145
+ PERMANENT_REDIRECT = 308,
146
+ /** [400] Request malformed, syntax error or invalid request */
147
+ BAD_REQUEST = 400,
148
+ /** [401] Request requires user authentication or authorization */
149
+ UNAUTHORIZED = 401,
150
+ /** [402] Reserved for future use, payment required */
151
+ PAYMENT_REQUIRED = 402,
152
+ /** [403] Server understood request but refuses to authorize it */
153
+ FORBIDDEN = 403,
154
+ /** [404] Server cannot find the requested resource */
155
+ NOT_FOUND = 404,
156
+ /** [405] Request method (GET, POST, etc.) not supported for this resource */
157
+ METHOD_NOT_ALLOWED = 405,
158
+ /** [406] Resource cannot generate response matching accept headers */
159
+ NOT_ACCEPTABLE = 406,
160
+ /** [407] Client must first authenticate with the proxy */
161
+ PROXY_AUTHENTICATION_REQUIRED = 407,
162
+ /** [408] Server timed out waiting for the request */
163
+ REQUEST_TIMEOUT = 408,
164
+ /** [409] Request conflicts with current state of the server */
165
+ CONFLICT = 409,
166
+ /** [410] Resource requested is no longer available and will not be available again */
167
+ GONE = 410,
168
+ /** [411] Server requires Content-Length header field */
169
+ LENGTH_REQUIRED = 411,
170
+ /** [412] Precondition given in request headers evaluated to false */
171
+ PRECONDITION_FAILED = 412,
172
+ /** [413] Request entity larger than limits defined by server */
173
+ PAYLOAD_TOO_LARGE = 413,
174
+ /** [414] URI requested by client is longer than server can interpret */
175
+ URI_TOO_LONG = 414,
176
+ /** [415] Media format of requested data not supported by server */
177
+ UNSUPPORTED_MEDIA_TYPE = 415,
178
+ /** [416] Range specified by Range header cannot be fulfilled */
179
+ RANGE_NOT_SATISFIABLE = 416,
180
+ /** [417] Expectation indicated by Expect header cannot be met */
181
+ EXPECTATION_FAILED = 417,
182
+ /** [418] April Fools' joke by RFC 2324 - Server refuses to brew coffee in a teapot */
183
+ IM_A_TEAPOT = 418,
184
+ /** [421] Request directed at a server that is not configured to produce a response */
185
+ MISDIRECTED_REQUEST = 421,
186
+ /** [422] Server understands content type but cannot process contained instructions */
187
+ UNPROCESSABLE_ENTITY = 422,
188
+ /** [423] Requested resource is currently locked */
189
+ LOCKED = 423,
190
+ /** [424] Request failed due to failure of a previous request */
191
+ FAILED_DEPENDENCY = 424,
192
+ /** [425] Server is unwilling to risk processing a request that might be replayed */
193
+ TOO_EARLY = 425,
194
+ /** [426] Server requires client to upgrade to a different protocol */
195
+ UPGRADE_REQUIRED = 426,
196
+ /** [428] Origin server requires request to be conditional */
197
+ PRECONDITION_REQUIRED = 428,
198
+ /** [429] User has sent too many requests in a given time period */
199
+ TOO_MANY_REQUESTS = 429,
200
+ /** [431] Server refusing to process request due to oversized headers */
201
+ REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
202
+ /** [451] Server denies access for legal reasons (e.g., censorship) */
203
+ UNAVAILABLE_FOR_LEGAL_REASONS = 451,
204
+ /** [500] Generic server error, no specific message */
205
+ INTERNAL_SERVER_ERROR = 500,
206
+ /** [501] Server does not recognize method or lacks ability to fulfill */
207
+ NOT_IMPLEMENTED = 501,
208
+ /** [502] Bad response received from upstream server */
209
+ BAD_GATEWAY = 502,
210
+ /** [503] Server temporarily unavailable (overloaded/maintenance) */
211
+ SERVICE_UNAVAILABLE = 503,
212
+ /** [504] Gateway server did not get response from upstream server */
213
+ GATEWAY_TIMEOUT = 504,
214
+ /** [505] Server does not support the HTTP protocol version */
215
+ HTTP_VERSION_NOT_SUPPORTED = 505,
216
+ /** [506] Server has a circular reference in content negotiation */
217
+ VARIANT_ALSO_NEGOTIATES = 506,
218
+ /** [507] Server has insufficient storage to complete request */
219
+ INSUFFICIENT_STORAGE = 507,
220
+ /** [508] Server detected an infinite loop while processing request */
221
+ LOOP_DETECTED = 508,
222
+ /** [510] Further extensions needed for server to fulfill request */
223
+ NOT_EXTENDED = 510,
224
+ /** [511] Client needs to authenticate to gain network access */
225
+ NETWORK_AUTHENTICATION_REQUIRED = 511
113
226
  }
114
- interface SilgiErrorOptions {
115
- code: SilgiErrorCode | string;
227
+ declare enum ErrorSeverity {
228
+ DEBUG = "DEBUG",
229
+ INFO = "INFO",
230
+ WARNING = "WARNING",
231
+ ERROR = "ERROR",
232
+ CRITICAL = "CRITICAL"
233
+ }
234
+ declare enum ErrorCategory {
235
+ AUTHENTICATION = "auth",
236
+ AUTHORIZATION = "authorization",
237
+ VALIDATION = "validation",
238
+ BUSINESS = "business",
239
+ INFRASTRUCTURE = "infrastructure",
240
+ EXTERNAL = "external",
241
+ UNKNOWN = "unknown"
242
+ }
243
+ interface ErrorMetadata {
244
+ timestamp: number;
245
+ correlationId?: string;
246
+ requestId?: string;
247
+ userId?: string;
248
+ path?: string;
249
+ source?: string;
250
+ [key: string]: unknown;
251
+ }
252
+ interface BaseError {
253
+ code: number;
116
254
  message: string;
255
+ category: ErrorCategory;
256
+ severity: ErrorSeverity;
257
+ httpStatus: HttpStatus;
258
+ metadata?: ErrorMetadata;
117
259
  cause?: Error;
118
- details?: Record<string, unknown>;
119
- meta?: Record<string, unknown>;
260
+ context?: Record<string, unknown>;
120
261
  }
121
- declare class SilgiError extends Error {
122
- readonly code: string;
123
- readonly details?: Record<string, unknown>;
124
- readonly meta?: Record<string, unknown>;
125
- readonly timestamp: number;
126
- cause?: Error;
127
- constructor(options: SilgiErrorOptions);
128
- toString(): string;
129
- toJSON(): {
130
- name: string;
131
- code: string;
262
+ declare class ErrorFactory {
263
+ private static createMetadata;
264
+ static create(options: Partial<BaseError> & {
132
265
  message: string;
133
- details: Record<string, unknown> | undefined;
134
- meta: Record<string, unknown> | undefined;
135
- timestamp: number;
136
- stack: string | undefined;
137
- };
138
- static createFrom(error: unknown, code?: string): SilgiError;
139
- static isSilgiError(error: unknown): error is SilgiError;
266
+ }): SilgiError;
267
+ static authenticationError(message: string, context?: Record<string, unknown>): SilgiError;
268
+ static authorizationError(message: string, context?: Record<string, unknown>): SilgiError;
269
+ static validationError(message: string, context?: Record<string, unknown>): SilgiError;
270
+ static notFoundError(message: string, context?: Record<string, unknown>): SilgiError;
271
+ static internalError(message: string, cause?: Error): SilgiError;
272
+ }
273
+ declare class SilgiError extends Error implements BaseError {
274
+ readonly code: number;
275
+ readonly category: ErrorCategory;
276
+ readonly severity: ErrorSeverity;
277
+ readonly httpStatus: HttpStatus;
278
+ readonly metadata: ErrorMetadata;
279
+ readonly context?: Record<string, unknown>;
280
+ readonly cause?: Error;
281
+ constructor(error: BaseError);
282
+ toString(): string;
283
+ toJSON(): Record<string, unknown>;
284
+ static isError(error: unknown): error is SilgiError;
285
+ static from(error: unknown): SilgiError;
140
286
  }
287
+ declare function isBaseError(error: unknown): error is BaseError;
141
288
 
142
289
  declare function useSilgi(): Silgi;
143
290
 
144
- export { SchemaParser, SilgiError, createSchema, createService, createShared, createSilgi, createSilgiFetch, getEvent, loadOptions, mergeSchemas, mergeServices, mergeShared, parseURI, silgiGenerateType, useSilgi };
291
+ export { type BaseError, ErrorCategory, ErrorFactory, type ErrorMetadata, ErrorSeverity, HttpStatus, SchemaParser, SilgiError, createSchema, createService, createShared, createSilgi, createSilgiFetch, getEvent, isBaseError, loadOptions, mergeSchemas, mergeServices, mergeShared, parseURI, silgiGenerateType, useSilgi };