@gravito/core 2.0.6 → 3.0.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.
package/dist/index.js CHANGED
@@ -3300,7 +3300,7 @@ class Gravito {
3300
3300
  // package.json
3301
3301
  var package_default = {
3302
3302
  name: "@gravito/core",
3303
- version: "2.0.6",
3303
+ version: "3.0.0",
3304
3304
  description: "",
3305
3305
  module: "./dist/index.js",
3306
3306
  main: "./dist/index.js",
@@ -5670,11 +5670,50 @@ class ConfigManager {
5670
5670
  }
5671
5671
  }
5672
5672
 
5673
+ // src/exceptions/GravitoException.ts
5674
+ class GravitoException extends Error {
5675
+ status;
5676
+ code;
5677
+ i18nKey;
5678
+ i18nParams;
5679
+ constructor(status, code, options2 = {}) {
5680
+ super(options2.message);
5681
+ this.name = "GravitoException";
5682
+ this.status = status;
5683
+ this.cause = options2.cause;
5684
+ this.code = code;
5685
+ if (options2.i18nKey) {
5686
+ this.i18nKey = options2.i18nKey;
5687
+ }
5688
+ if (options2.i18nParams) {
5689
+ this.i18nParams = options2.i18nParams;
5690
+ }
5691
+ Object.setPrototypeOf(this, new.target.prototype);
5692
+ }
5693
+ getLocalizedMessage(t) {
5694
+ if (this.i18nKey) {
5695
+ return t(this.i18nKey, this.i18nParams);
5696
+ }
5697
+ return this.message;
5698
+ }
5699
+ }
5700
+
5701
+ // src/exceptions/SystemException.ts
5702
+ class SystemException extends GravitoException {
5703
+ constructor(status, code, options2 = {}) {
5704
+ super(status, code, options2);
5705
+ this.name = "SystemException";
5706
+ Object.setPrototypeOf(this, new.target.prototype);
5707
+ }
5708
+ }
5709
+
5673
5710
  // src/exceptions/CircularDependencyException.ts
5674
- class CircularDependencyException extends Error {
5711
+ class CircularDependencyException extends SystemException {
5675
5712
  constructor(key, stack) {
5676
5713
  const path2 = [...stack, key].map(String).join(" -> ");
5677
- super(`Circular dependency detected: ${path2}`);
5714
+ super(500, "system.circular_dependency", {
5715
+ message: `Circular dependency detected: ${path2}`
5716
+ });
5678
5717
  this.name = "CircularDependencyException";
5679
5718
  }
5680
5719
  }
@@ -5840,33 +5879,6 @@ function detectRequestScopeLeaks(context) {
5840
5879
  };
5841
5880
  }
5842
5881
 
5843
- // src/exceptions/GravitoException.ts
5844
- class GravitoException extends Error {
5845
- status;
5846
- code;
5847
- i18nKey;
5848
- i18nParams;
5849
- constructor(status, code, options2 = {}) {
5850
- super(options2.message);
5851
- this.name = "GravitoException";
5852
- this.status = status;
5853
- this.cause = options2.cause;
5854
- this.code = code;
5855
- if (options2.i18nKey) {
5856
- this.i18nKey = options2.i18nKey;
5857
- }
5858
- if (options2.i18nParams) {
5859
- this.i18nParams = options2.i18nParams;
5860
- }
5861
- }
5862
- getLocalizedMessage(t) {
5863
- if (this.i18nKey) {
5864
- return t(this.i18nKey, this.i18nParams);
5865
- }
5866
- return this.message;
5867
- }
5868
- }
5869
-
5870
5882
  // src/exceptions/HttpException.ts
5871
5883
  class HttpException extends GravitoException {
5872
5884
  constructor(status, options2 = {}) {
@@ -5875,8 +5887,17 @@ class HttpException extends GravitoException {
5875
5887
  }
5876
5888
  }
5877
5889
 
5890
+ // src/exceptions/DomainException.ts
5891
+ class DomainException extends GravitoException {
5892
+ constructor(status, code, options2 = {}) {
5893
+ super(status, code, options2);
5894
+ this.name = "DomainException";
5895
+ Object.setPrototypeOf(this, new.target.prototype);
5896
+ }
5897
+ }
5898
+
5878
5899
  // src/exceptions/ValidationException.ts
5879
- class ValidationException extends GravitoException {
5900
+ class ValidationException extends DomainException {
5880
5901
  errors;
5881
5902
  redirectTo;
5882
5903
  input;
@@ -5885,6 +5906,7 @@ class ValidationException extends GravitoException {
5885
5906
  message,
5886
5907
  i18nKey: "errors.validation.failed"
5887
5908
  });
5909
+ this.name = "ValidationException";
5888
5910
  this.errors = errors;
5889
5911
  }
5890
5912
  withRedirect(url) {
@@ -10921,6 +10943,7 @@ class ModelNotFoundException extends GravitoException {
10921
10943
  i18nKey: "errors.model.not_found",
10922
10944
  i18nParams: { model, id: String(id ?? "") }
10923
10945
  });
10946
+ this.name = "ModelNotFoundException";
10924
10947
  this.model = model;
10925
10948
  if (id !== undefined) {
10926
10949
  this.id = id;
@@ -11476,6 +11499,7 @@ class PlanetCore {
11476
11499
  deferredProviders = new Map;
11477
11500
  bootedProviders = new Set;
11478
11501
  isShuttingDown = false;
11502
+ static GLOBAL_SHUTDOWN_TIMEOUT = 1e4;
11479
11503
  async initializeObservabilityAsync(obsConfig) {
11480
11504
  try {
11481
11505
  if (this.observabilityProvider && this.observabilityProvider !== this.observabilityProvider._isNoOp) {
@@ -11577,15 +11601,23 @@ class PlanetCore {
11577
11601
  }
11578
11602
  this.isShuttingDown = true;
11579
11603
  this.logger.debug("\uD83D\uDED1 Application shutdown started");
11580
- for (const provider of [...this.providers].reverse()) {
11581
- if (provider.onShutdown) {
11582
- try {
11583
- this.logger.debug(` onShutdown: ${provider.constructor.name}`);
11584
- await provider.onShutdown(this);
11585
- } catch (error) {
11586
- this.logger.error(`Error during shutdown of ${provider.constructor.name}:`, error);
11604
+ const shutdownSequence = async () => {
11605
+ for (const provider of [...this.providers].reverse()) {
11606
+ if (provider.onShutdown) {
11607
+ try {
11608
+ this.logger.debug(` onShutdown: ${provider.constructor.name}`);
11609
+ await provider.onShutdown(this);
11610
+ } catch (error) {
11611
+ this.logger.error(`Error during shutdown of ${provider.constructor.name}:`, error);
11612
+ }
11587
11613
  }
11588
11614
  }
11615
+ };
11616
+ const globalDeadline = new Promise((_, reject) => setTimeout(() => reject(new Error("[PlanetCore] Global shutdown timeout exceeded (10s)")), PlanetCore.GLOBAL_SHUTDOWN_TIMEOUT));
11617
+ try {
11618
+ await Promise.race([shutdownSequence(), globalDeadline]);
11619
+ } catch (err) {
11620
+ this.logger.warn("[PlanetCore] Forced shutdown after global timeout:", err);
11589
11621
  }
11590
11622
  this.hooks.doAction("app:shutdown", this);
11591
11623
  this.logger.debug("\u2705 Application shutdown complete");
@@ -13190,22 +13222,98 @@ class QueueDashboard {
13190
13222
  }
13191
13223
  }
13192
13224
  // src/exceptions/AuthenticationException.ts
13193
- class AuthenticationException extends GravitoException {
13225
+ class AuthenticationException extends DomainException {
13194
13226
  constructor(message = "Unauthenticated.") {
13195
13227
  super(401, "UNAUTHENTICATED", {
13196
13228
  message,
13197
13229
  i18nKey: "errors.authentication.unauthenticated"
13198
13230
  });
13231
+ this.name = "AuthenticationException";
13232
+ }
13233
+ }
13234
+
13235
+ // src/exceptions/AuthException.ts
13236
+ class AuthException extends DomainException {
13237
+ constructor(status, code, options2 = {}) {
13238
+ super(status, code, options2);
13239
+ this.name = "AuthException";
13240
+ Object.setPrototypeOf(this, new.target.prototype);
13199
13241
  }
13200
13242
  }
13201
13243
 
13202
13244
  // src/exceptions/AuthorizationException.ts
13203
- class AuthorizationException extends GravitoException {
13245
+ class AuthorizationException extends DomainException {
13204
13246
  constructor(message = "This action is unauthorized.") {
13205
13247
  super(403, "FORBIDDEN", {
13206
13248
  message,
13207
13249
  i18nKey: "errors.authorization.forbidden"
13208
13250
  });
13251
+ this.name = "AuthorizationException";
13252
+ }
13253
+ }
13254
+
13255
+ // src/exceptions/InfrastructureException.ts
13256
+ class InfrastructureException extends GravitoException {
13257
+ retryable;
13258
+ constructor(status, code, options2 = {}) {
13259
+ super(status, code, options2);
13260
+ this.name = "InfrastructureException";
13261
+ this.retryable = options2.retryable ?? false;
13262
+ Object.setPrototypeOf(this, new.target.prototype);
13263
+ }
13264
+ }
13265
+
13266
+ // src/exceptions/CacheException.ts
13267
+ class CacheException extends InfrastructureException {
13268
+ constructor(status, code, options2 = {}) {
13269
+ super(status, code, options2);
13270
+ this.name = "CacheException";
13271
+ Object.setPrototypeOf(this, new.target.prototype);
13272
+ }
13273
+ }
13274
+
13275
+ // src/exceptions/ConfigurationException.ts
13276
+ class ConfigurationException extends SystemException {
13277
+ constructor(message, options2 = {}) {
13278
+ super(500, "system.configuration_error", { ...options2, message });
13279
+ this.name = "ConfigurationException";
13280
+ Object.setPrototypeOf(this, new.target.prototype);
13281
+ }
13282
+ }
13283
+
13284
+ // src/exceptions/DatabaseException.ts
13285
+ class DatabaseException extends InfrastructureException {
13286
+ constructor(status, code, options2 = {}) {
13287
+ super(status, code, options2);
13288
+ this.name = "DatabaseException";
13289
+ Object.setPrototypeOf(this, new.target.prototype);
13290
+ }
13291
+ }
13292
+
13293
+ // src/exceptions/QueueException.ts
13294
+ class QueueException extends InfrastructureException {
13295
+ constructor(status, code, options2 = {}) {
13296
+ super(status, code, options2);
13297
+ this.name = "QueueException";
13298
+ Object.setPrototypeOf(this, new.target.prototype);
13299
+ }
13300
+ }
13301
+
13302
+ // src/exceptions/StorageException.ts
13303
+ class StorageException extends InfrastructureException {
13304
+ constructor(status, code, options2 = {}) {
13305
+ super(status, code, options2);
13306
+ this.name = "StorageException";
13307
+ Object.setPrototypeOf(this, new.target.prototype);
13308
+ }
13309
+ }
13310
+
13311
+ // src/exceptions/StreamException.ts
13312
+ class StreamException extends InfrastructureException {
13313
+ constructor(status, code, options2 = {}) {
13314
+ super(status, code, options2);
13315
+ this.name = "StreamException";
13316
+ Object.setPrototypeOf(this, new.target.prototype);
13209
13317
  }
13210
13318
  }
13211
13319
  // src/ServiceProvider.ts
@@ -13945,7 +14053,10 @@ export {
13945
14053
  ValidationException,
13946
14054
  VERSION,
13947
14055
  TestResponse,
14056
+ SystemException,
14057
+ StreamException,
13948
14058
  Str,
14059
+ StorageException,
13949
14060
  StarvationProtectionStrategy,
13950
14061
  ServiceProvider,
13951
14062
  Router,
@@ -13961,6 +14072,7 @@ export {
13961
14072
  RateLimitStrategy,
13962
14073
  RadixRouter,
13963
14074
  RadixNode,
14075
+ QueueException,
13964
14076
  QueueDepthStrategy,
13965
14077
  QueueDashboard,
13966
14078
  PriorityRebalanceStrategy,
@@ -13970,6 +14082,7 @@ export {
13970
14082
  OTelEventMetrics,
13971
14083
  NodeType,
13972
14084
  ModelNotFoundException,
14085
+ InfrastructureException,
13973
14086
  IdempotencyCache,
13974
14087
  HttpTester,
13975
14088
  HttpException,
@@ -13988,18 +14101,22 @@ export {
13988
14101
  ErrorHandler,
13989
14102
  Encrypter,
13990
14103
  DumpDieError,
14104
+ DomainException,
13991
14105
  DeadLetterQueueManager,
13992
14106
  DeadLetterQueue,
14107
+ DatabaseException,
13993
14108
  DEFAULT_EVENT_OPTIONS,
13994
14109
  CookieJar,
13995
14110
  Container,
13996
14111
  ConsoleLogger,
14112
+ ConfigurationException,
13997
14113
  ConfigManager,
13998
14114
  CompositeStrategy,
13999
14115
  CommandKernel,
14000
14116
  CircularDependencyException,
14001
14117
  CircuitBreakerState,
14002
14118
  CircuitBreaker,
14119
+ CacheException,
14003
14120
  BunWebSocketHandler,
14004
14121
  BunRequest,
14005
14122
  BunNativeAdapter,
@@ -14009,8 +14126,9 @@ export {
14009
14126
  BackpressureManager,
14010
14127
  AuthorizationException,
14011
14128
  AuthenticationException,
14129
+ AuthException,
14012
14130
  Arr,
14013
14131
  Application
14014
14132
  };
14015
14133
 
14016
- //# debugId=B420456F9068F67364756E2164756E21
14134
+ //# debugId=182898C607162D4164756E2164756E21