@gravito/core 2.0.4 → 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/PlanetCore.d.ts +6 -0
- package/dist/compat/async-local-storage.browser.js +71 -0
- package/dist/compat/async-local-storage.browser.js.map +10 -0
- package/dist/compat/async-local-storage.js +94 -0
- package/dist/compat/async-local-storage.js.map +10 -0
- package/dist/compat/crypto.browser.js +91 -0
- package/dist/compat/crypto.browser.js.map +10 -0
- package/dist/compat/crypto.js +111 -0
- package/dist/compat/crypto.js.map +10 -0
- package/dist/events/CircuitBreaker.d.ts +12 -0
- package/dist/exceptions/AuthException.d.ts +10 -0
- package/dist/exceptions/AuthenticationException.d.ts +2 -2
- package/dist/exceptions/AuthorizationException.d.ts +2 -2
- package/dist/exceptions/CacheException.d.ts +9 -0
- package/dist/exceptions/CircularDependencyException.d.ts +2 -1
- package/dist/exceptions/ConfigurationException.d.ts +9 -0
- package/dist/exceptions/DatabaseException.d.ts +9 -0
- package/dist/exceptions/DomainException.d.ts +9 -0
- package/dist/exceptions/InfrastructureException.d.ts +17 -0
- package/dist/exceptions/QueueException.d.ts +9 -0
- package/dist/exceptions/StorageException.d.ts +9 -0
- package/dist/exceptions/StreamException.d.ts +9 -0
- package/dist/exceptions/SystemException.d.ts +9 -0
- package/dist/exceptions/ValidationException.d.ts +2 -2
- package/dist/exceptions/index.d.ts +10 -0
- package/dist/ffi/NativeAccelerator.js +398 -0
- package/dist/ffi/NativeAccelerator.js.map +12 -0
- package/dist/ffi/NativeHasher.js +125 -0
- package/dist/ffi/{index.js.map → NativeHasher.js.map} +2 -2
- package/dist/ffi/cbor-fallback.js +344 -0
- package/dist/ffi/cbor-fallback.js.map +11 -0
- package/dist/ffi/hash-fallback.js +63 -0
- package/dist/ffi/hash-fallback.js.map +10 -0
- package/dist/ffi/index.js +5 -131
- package/dist/ffi/types.js +82 -0
- package/dist/ffi/types.js.map +10 -0
- package/dist/index.browser.js +9055 -0
- package/dist/index.browser.js.map +90 -0
- package/dist/index.d.ts +479 -1
- package/dist/index.js +401 -158
- package/dist/index.js.map +27 -16
- package/dist/testing/HttpTester.d.ts +1 -0
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -1445,6 +1445,109 @@ var require_src = __commonJS((exports) => {
|
|
|
1445
1445
|
trace: trace_api_1.trace
|
|
1446
1446
|
};
|
|
1447
1447
|
});
|
|
1448
|
+
|
|
1449
|
+
// src/compat/async-local-storage.ts
|
|
1450
|
+
var AsyncLocalStorageClass;
|
|
1451
|
+
var tryGetNodeAsyncHooks = () => {
|
|
1452
|
+
try {
|
|
1453
|
+
if (typeof window === "undefined" && typeof process !== "undefined" && true) {
|
|
1454
|
+
try {
|
|
1455
|
+
const module = __require("async_hooks");
|
|
1456
|
+
return module.AsyncLocalStorage;
|
|
1457
|
+
} catch (_e1) {
|
|
1458
|
+
try {
|
|
1459
|
+
return eval("require")("node:async_hooks").AsyncLocalStorage;
|
|
1460
|
+
} catch (_e2) {
|
|
1461
|
+
return null;
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
} catch (_e) {
|
|
1466
|
+
return null;
|
|
1467
|
+
}
|
|
1468
|
+
};
|
|
1469
|
+
AsyncLocalStorageClass = tryGetNodeAsyncHooks();
|
|
1470
|
+
if (!AsyncLocalStorageClass) {
|
|
1471
|
+
AsyncLocalStorageClass = class AsyncLocalStorage {
|
|
1472
|
+
store;
|
|
1473
|
+
run(store, fn) {
|
|
1474
|
+
const prev = this.store;
|
|
1475
|
+
this.store = store;
|
|
1476
|
+
try {
|
|
1477
|
+
return fn();
|
|
1478
|
+
} finally {
|
|
1479
|
+
this.store = prev;
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
getStore() {
|
|
1483
|
+
return this.store;
|
|
1484
|
+
}
|
|
1485
|
+
disable() {
|
|
1486
|
+
this.store = undefined;
|
|
1487
|
+
}
|
|
1488
|
+
};
|
|
1489
|
+
}
|
|
1490
|
+
var AsyncLocalStorage = AsyncLocalStorageClass;
|
|
1491
|
+
|
|
1492
|
+
// src/compat/crypto.ts
|
|
1493
|
+
var randomUUIDFn;
|
|
1494
|
+
var randomBytesFn;
|
|
1495
|
+
var tryGetNodeCrypto = () => {
|
|
1496
|
+
try {
|
|
1497
|
+
if (typeof window === "undefined" && typeof process !== "undefined" && true) {
|
|
1498
|
+
return eval("require")("node:crypto");
|
|
1499
|
+
}
|
|
1500
|
+
} catch (_e) {
|
|
1501
|
+
return null;
|
|
1502
|
+
}
|
|
1503
|
+
};
|
|
1504
|
+
var nodeCrypto = tryGetNodeCrypto();
|
|
1505
|
+
if (nodeCrypto) {
|
|
1506
|
+
randomUUIDFn = nodeCrypto.randomUUID;
|
|
1507
|
+
randomBytesFn = nodeCrypto.randomBytes;
|
|
1508
|
+
} else {
|
|
1509
|
+
randomUUIDFn = () => {
|
|
1510
|
+
if (typeof globalThis.crypto?.randomUUID === "function") {
|
|
1511
|
+
return globalThis.crypto.randomUUID();
|
|
1512
|
+
}
|
|
1513
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
1514
|
+
const r = Math.random() * 16 | 0;
|
|
1515
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
1516
|
+
return v.toString(16);
|
|
1517
|
+
});
|
|
1518
|
+
};
|
|
1519
|
+
randomBytesFn = (size) => {
|
|
1520
|
+
const bytes = new Uint8Array(size);
|
|
1521
|
+
if (typeof globalThis.crypto?.getRandomValues === "function") {
|
|
1522
|
+
globalThis.crypto.getRandomValues(bytes);
|
|
1523
|
+
} else {
|
|
1524
|
+
for (let i = 0;i < size; i++) {
|
|
1525
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
1526
|
+
}
|
|
1527
|
+
}
|
|
1528
|
+
return {
|
|
1529
|
+
...Array.from(bytes),
|
|
1530
|
+
length: size,
|
|
1531
|
+
[Symbol.iterator]: () => bytes[Symbol.iterator](),
|
|
1532
|
+
toString: (encoding) => {
|
|
1533
|
+
if (encoding === "base64") {
|
|
1534
|
+
let binary = "";
|
|
1535
|
+
for (let i = 0;i < bytes.byteLength; i++) {
|
|
1536
|
+
binary += String.fromCharCode(bytes[i]);
|
|
1537
|
+
}
|
|
1538
|
+
return btoa(binary);
|
|
1539
|
+
}
|
|
1540
|
+
if (encoding === "hex") {
|
|
1541
|
+
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1542
|
+
}
|
|
1543
|
+
return "";
|
|
1544
|
+
}
|
|
1545
|
+
};
|
|
1546
|
+
};
|
|
1547
|
+
}
|
|
1548
|
+
var randomUUID = randomUUIDFn;
|
|
1549
|
+
var randomBytes = randomBytesFn;
|
|
1550
|
+
|
|
1448
1551
|
// src/ffi/hash-fallback.ts
|
|
1449
1552
|
import { createHash, createHmac } from "crypto";
|
|
1450
1553
|
|
|
@@ -3197,7 +3300,7 @@ class Gravito {
|
|
|
3197
3300
|
// package.json
|
|
3198
3301
|
var package_default = {
|
|
3199
3302
|
name: "@gravito/core",
|
|
3200
|
-
version: "
|
|
3303
|
+
version: "3.0.0",
|
|
3201
3304
|
description: "",
|
|
3202
3305
|
module: "./dist/index.js",
|
|
3203
3306
|
main: "./dist/index.js",
|
|
@@ -3206,8 +3309,8 @@ var package_default = {
|
|
|
3206
3309
|
types: "./dist/index.d.ts",
|
|
3207
3310
|
exports: {
|
|
3208
3311
|
".": {
|
|
3209
|
-
browser: "./
|
|
3210
|
-
bun: "./
|
|
3312
|
+
browser: "./dist/index.browser.js",
|
|
3313
|
+
bun: "./dist/index.js",
|
|
3211
3314
|
types: "./dist/index.d.ts",
|
|
3212
3315
|
default: "./dist/index.js"
|
|
3213
3316
|
},
|
|
@@ -3224,12 +3327,12 @@ var package_default = {
|
|
|
3224
3327
|
default: "./dist/ffi/index.js"
|
|
3225
3328
|
},
|
|
3226
3329
|
"./compat/async-local-storage": {
|
|
3227
|
-
browser: "./
|
|
3228
|
-
default: "./
|
|
3330
|
+
browser: "./dist/compat/async-local-storage.browser.js",
|
|
3331
|
+
default: "./dist/compat/async-local-storage.js"
|
|
3229
3332
|
},
|
|
3230
3333
|
"./compat/crypto": {
|
|
3231
|
-
browser: "./
|
|
3232
|
-
default: "./
|
|
3334
|
+
browser: "./dist/compat/crypto.browser.js",
|
|
3335
|
+
default: "./dist/compat/crypto.js"
|
|
3233
3336
|
}
|
|
3234
3337
|
},
|
|
3235
3338
|
files: [
|
|
@@ -3923,6 +4026,9 @@ import path2 from "path";
|
|
|
3923
4026
|
import { pathToFileURL } from "url";
|
|
3924
4027
|
|
|
3925
4028
|
// src/runtime/adapter-bun.ts
|
|
4029
|
+
function createEphemeralPort() {
|
|
4030
|
+
return Math.floor(Math.random() * 50000) + 1e4;
|
|
4031
|
+
}
|
|
3926
4032
|
function createBunAdapter() {
|
|
3927
4033
|
return {
|
|
3928
4034
|
kind: "bun",
|
|
@@ -4130,11 +4236,26 @@ function createBunAdapter() {
|
|
|
4130
4236
|
await fs2.rm(path2, { recursive: true, force: true });
|
|
4131
4237
|
},
|
|
4132
4238
|
serve(config2) {
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4239
|
+
if (config2.port !== 0) {
|
|
4240
|
+
return Bun.serve({
|
|
4241
|
+
port: config2.port,
|
|
4242
|
+
fetch: config2.fetch,
|
|
4243
|
+
websocket: config2.websocket
|
|
4244
|
+
});
|
|
4245
|
+
}
|
|
4246
|
+
let lastError;
|
|
4247
|
+
for (let attempt = 0;attempt < 20; attempt++) {
|
|
4248
|
+
try {
|
|
4249
|
+
return Bun.serve({
|
|
4250
|
+
port: createEphemeralPort(),
|
|
4251
|
+
fetch: config2.fetch,
|
|
4252
|
+
websocket: config2.websocket
|
|
4253
|
+
});
|
|
4254
|
+
} catch (error) {
|
|
4255
|
+
lastError = error;
|
|
4256
|
+
}
|
|
4257
|
+
}
|
|
4258
|
+
throw lastError ?? new Error("[RuntimeAdapter] Failed to allocate an ephemeral port");
|
|
4138
4259
|
}
|
|
4139
4260
|
};
|
|
4140
4261
|
}
|
|
@@ -5549,54 +5670,50 @@ class ConfigManager {
|
|
|
5549
5670
|
}
|
|
5550
5671
|
}
|
|
5551
5672
|
|
|
5552
|
-
// src/
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5557
|
-
|
|
5558
|
-
|
|
5559
|
-
|
|
5560
|
-
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
|
|
5564
|
-
|
|
5565
|
-
|
|
5566
|
-
}
|
|
5567
|
-
}
|
|
5568
|
-
} catch (_e) {
|
|
5569
|
-
return null;
|
|
5570
|
-
}
|
|
5571
|
-
};
|
|
5572
|
-
AsyncLocalStorageClass = tryGetNodeAsyncHooks();
|
|
5573
|
-
if (!AsyncLocalStorageClass) {
|
|
5574
|
-
AsyncLocalStorageClass = class AsyncLocalStorage {
|
|
5575
|
-
store = null;
|
|
5576
|
-
run(store, fn) {
|
|
5577
|
-
const prev = this.store;
|
|
5578
|
-
this.store = store;
|
|
5579
|
-
try {
|
|
5580
|
-
return fn();
|
|
5581
|
-
} finally {
|
|
5582
|
-
this.store = prev;
|
|
5583
|
-
}
|
|
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;
|
|
5584
5687
|
}
|
|
5585
|
-
|
|
5586
|
-
|
|
5688
|
+
if (options2.i18nParams) {
|
|
5689
|
+
this.i18nParams = options2.i18nParams;
|
|
5587
5690
|
}
|
|
5588
|
-
|
|
5589
|
-
|
|
5691
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
5692
|
+
}
|
|
5693
|
+
getLocalizedMessage(t) {
|
|
5694
|
+
if (this.i18nKey) {
|
|
5695
|
+
return t(this.i18nKey, this.i18nParams);
|
|
5590
5696
|
}
|
|
5591
|
-
|
|
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
|
+
}
|
|
5592
5708
|
}
|
|
5593
|
-
var AsyncLocalStorage = AsyncLocalStorageClass;
|
|
5594
5709
|
|
|
5595
5710
|
// src/exceptions/CircularDependencyException.ts
|
|
5596
|
-
class CircularDependencyException extends
|
|
5711
|
+
class CircularDependencyException extends SystemException {
|
|
5597
5712
|
constructor(key, stack) {
|
|
5598
5713
|
const path2 = [...stack, key].map(String).join(" -> ");
|
|
5599
|
-
super(
|
|
5714
|
+
super(500, "system.circular_dependency", {
|
|
5715
|
+
message: `Circular dependency detected: ${path2}`
|
|
5716
|
+
});
|
|
5600
5717
|
this.name = "CircularDependencyException";
|
|
5601
5718
|
}
|
|
5602
5719
|
}
|
|
@@ -5762,33 +5879,6 @@ function detectRequestScopeLeaks(context) {
|
|
|
5762
5879
|
};
|
|
5763
5880
|
}
|
|
5764
5881
|
|
|
5765
|
-
// src/exceptions/GravitoException.ts
|
|
5766
|
-
class GravitoException extends Error {
|
|
5767
|
-
status;
|
|
5768
|
-
code;
|
|
5769
|
-
i18nKey;
|
|
5770
|
-
i18nParams;
|
|
5771
|
-
constructor(status, code, options2 = {}) {
|
|
5772
|
-
super(options2.message);
|
|
5773
|
-
this.name = "GravitoException";
|
|
5774
|
-
this.status = status;
|
|
5775
|
-
this.cause = options2.cause;
|
|
5776
|
-
this.code = code;
|
|
5777
|
-
if (options2.i18nKey) {
|
|
5778
|
-
this.i18nKey = options2.i18nKey;
|
|
5779
|
-
}
|
|
5780
|
-
if (options2.i18nParams) {
|
|
5781
|
-
this.i18nParams = options2.i18nParams;
|
|
5782
|
-
}
|
|
5783
|
-
}
|
|
5784
|
-
getLocalizedMessage(t) {
|
|
5785
|
-
if (this.i18nKey) {
|
|
5786
|
-
return t(this.i18nKey, this.i18nParams);
|
|
5787
|
-
}
|
|
5788
|
-
return this.message;
|
|
5789
|
-
}
|
|
5790
|
-
}
|
|
5791
|
-
|
|
5792
5882
|
// src/exceptions/HttpException.ts
|
|
5793
5883
|
class HttpException extends GravitoException {
|
|
5794
5884
|
constructor(status, options2 = {}) {
|
|
@@ -5797,8 +5887,17 @@ class HttpException extends GravitoException {
|
|
|
5797
5887
|
}
|
|
5798
5888
|
}
|
|
5799
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
|
+
|
|
5800
5899
|
// src/exceptions/ValidationException.ts
|
|
5801
|
-
class ValidationException extends
|
|
5900
|
+
class ValidationException extends DomainException {
|
|
5802
5901
|
errors;
|
|
5803
5902
|
redirectTo;
|
|
5804
5903
|
input;
|
|
@@ -5807,6 +5906,7 @@ class ValidationException extends GravitoException {
|
|
|
5807
5906
|
message,
|
|
5808
5907
|
i18nKey: "errors.validation.failed"
|
|
5809
5908
|
});
|
|
5909
|
+
this.name = "ValidationException";
|
|
5810
5910
|
this.errors = errors;
|
|
5811
5911
|
}
|
|
5812
5912
|
withRedirect(url) {
|
|
@@ -8734,65 +8834,6 @@ class MigrationWarner {
|
|
|
8734
8834
|
}
|
|
8735
8835
|
}
|
|
8736
8836
|
|
|
8737
|
-
// src/compat/crypto.ts
|
|
8738
|
-
var randomUUIDFn;
|
|
8739
|
-
var randomBytesFn;
|
|
8740
|
-
var tryGetNodeCrypto = () => {
|
|
8741
|
-
try {
|
|
8742
|
-
if (typeof window === "undefined" && typeof process !== "undefined" && true) {
|
|
8743
|
-
return eval("require")("node:crypto");
|
|
8744
|
-
}
|
|
8745
|
-
} catch (_e) {
|
|
8746
|
-
return null;
|
|
8747
|
-
}
|
|
8748
|
-
};
|
|
8749
|
-
var nodeCrypto = tryGetNodeCrypto();
|
|
8750
|
-
if (nodeCrypto) {
|
|
8751
|
-
randomUUIDFn = nodeCrypto.randomUUID;
|
|
8752
|
-
randomBytesFn = nodeCrypto.randomBytes;
|
|
8753
|
-
} else {
|
|
8754
|
-
randomUUIDFn = () => {
|
|
8755
|
-
if (typeof globalThis.crypto?.randomUUID === "function") {
|
|
8756
|
-
return globalThis.crypto.randomUUID();
|
|
8757
|
-
}
|
|
8758
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
8759
|
-
const r = Math.random() * 16 | 0;
|
|
8760
|
-
const v = c === "x" ? r : r & 3 | 8;
|
|
8761
|
-
return v.toString(16);
|
|
8762
|
-
});
|
|
8763
|
-
};
|
|
8764
|
-
randomBytesFn = (size) => {
|
|
8765
|
-
const bytes = new Uint8Array(size);
|
|
8766
|
-
if (typeof globalThis.crypto?.getRandomValues === "function") {
|
|
8767
|
-
globalThis.crypto.getRandomValues(bytes);
|
|
8768
|
-
} else {
|
|
8769
|
-
for (let i = 0;i < size; i++) {
|
|
8770
|
-
bytes[i] = Math.floor(Math.random() * 256);
|
|
8771
|
-
}
|
|
8772
|
-
}
|
|
8773
|
-
return {
|
|
8774
|
-
...Array.from(bytes),
|
|
8775
|
-
length: size,
|
|
8776
|
-
[Symbol.iterator]: () => bytes[Symbol.iterator](),
|
|
8777
|
-
toString: (encoding) => {
|
|
8778
|
-
if (encoding === "base64") {
|
|
8779
|
-
let binary = "";
|
|
8780
|
-
for (let i = 0;i < bytes.byteLength; i++) {
|
|
8781
|
-
binary += String.fromCharCode(bytes[i]);
|
|
8782
|
-
}
|
|
8783
|
-
return btoa(binary);
|
|
8784
|
-
}
|
|
8785
|
-
if (encoding === "hex") {
|
|
8786
|
-
return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
8787
|
-
}
|
|
8788
|
-
return "";
|
|
8789
|
-
}
|
|
8790
|
-
};
|
|
8791
|
-
};
|
|
8792
|
-
}
|
|
8793
|
-
var randomUUID = randomUUIDFn;
|
|
8794
|
-
var randomBytes = randomBytesFn;
|
|
8795
|
-
|
|
8796
8837
|
// src/reliability/RetryPolicy.ts
|
|
8797
8838
|
class RetryEngine {
|
|
8798
8839
|
calculateDelay(attemptCount, policy) {
|
|
@@ -10902,6 +10943,7 @@ class ModelNotFoundException extends GravitoException {
|
|
|
10902
10943
|
i18nKey: "errors.model.not_found",
|
|
10903
10944
|
i18nParams: { model, id: String(id ?? "") }
|
|
10904
10945
|
});
|
|
10946
|
+
this.name = "ModelNotFoundException";
|
|
10905
10947
|
this.model = model;
|
|
10906
10948
|
if (id !== undefined) {
|
|
10907
10949
|
this.id = id;
|
|
@@ -11457,6 +11499,7 @@ class PlanetCore {
|
|
|
11457
11499
|
deferredProviders = new Map;
|
|
11458
11500
|
bootedProviders = new Set;
|
|
11459
11501
|
isShuttingDown = false;
|
|
11502
|
+
static GLOBAL_SHUTDOWN_TIMEOUT = 1e4;
|
|
11460
11503
|
async initializeObservabilityAsync(obsConfig) {
|
|
11461
11504
|
try {
|
|
11462
11505
|
if (this.observabilityProvider && this.observabilityProvider !== this.observabilityProvider._isNoOp) {
|
|
@@ -11558,15 +11601,23 @@ class PlanetCore {
|
|
|
11558
11601
|
}
|
|
11559
11602
|
this.isShuttingDown = true;
|
|
11560
11603
|
this.logger.debug("\uD83D\uDED1 Application shutdown started");
|
|
11561
|
-
|
|
11562
|
-
|
|
11563
|
-
|
|
11564
|
-
|
|
11565
|
-
|
|
11566
|
-
|
|
11567
|
-
|
|
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
|
+
}
|
|
11568
11613
|
}
|
|
11569
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);
|
|
11570
11621
|
}
|
|
11571
11622
|
this.hooks.doAction("app:shutdown", this);
|
|
11572
11623
|
this.logger.debug("\u2705 Application shutdown complete");
|
|
@@ -12449,6 +12500,96 @@ class CompositeStrategy {
|
|
|
12449
12500
|
return false;
|
|
12450
12501
|
}
|
|
12451
12502
|
}
|
|
12503
|
+
function createDefaultStrategies(_config) {
|
|
12504
|
+
return [new QueueDepthStrategy, new RateLimitStrategy, new PriorityRebalanceStrategy];
|
|
12505
|
+
}
|
|
12506
|
+
// src/events/MessageQueueBridge.ts
|
|
12507
|
+
class MessageQueueBridge {
|
|
12508
|
+
config;
|
|
12509
|
+
constructor(config3) {
|
|
12510
|
+
this.config = config3;
|
|
12511
|
+
if (!config3.hookManager) {
|
|
12512
|
+
throw new Error("MessageQueueBridge: hookManager is required");
|
|
12513
|
+
}
|
|
12514
|
+
if (!config3.eventBackend) {
|
|
12515
|
+
throw new Error("MessageQueueBridge: eventBackend is required");
|
|
12516
|
+
}
|
|
12517
|
+
if (!config3.dlqManager) {
|
|
12518
|
+
throw new Error("MessageQueueBridge: dlqManager is required");
|
|
12519
|
+
}
|
|
12520
|
+
}
|
|
12521
|
+
async dispatchWithQueue(eventName, args, options2) {
|
|
12522
|
+
const listeners = this.config.hookManager.getListeners(eventName);
|
|
12523
|
+
if (listeners.length === 0) {
|
|
12524
|
+
throw new Error(`[MessageQueueBridge] No listeners registered for event: ${eventName}`);
|
|
12525
|
+
}
|
|
12526
|
+
if (this.config.enableCircuitBreaker) {
|
|
12527
|
+
const breaker = this.config.hookManager.getCircuitBreaker?.(eventName);
|
|
12528
|
+
if (breaker?.getState?.() === "OPEN") {
|
|
12529
|
+
throw new Error(`[MessageQueueBridge] Circuit breaker is OPEN for event: ${eventName}`);
|
|
12530
|
+
}
|
|
12531
|
+
}
|
|
12532
|
+
const nowMs = Date.now();
|
|
12533
|
+
const task = {
|
|
12534
|
+
id: `queue-${nowMs}-${Math.random().toString(36).substr(2, 9)}`,
|
|
12535
|
+
hook: eventName,
|
|
12536
|
+
args,
|
|
12537
|
+
callbacks: listeners,
|
|
12538
|
+
options: options2 || {},
|
|
12539
|
+
createdAt: nowMs,
|
|
12540
|
+
enqueuedAt: nowMs,
|
|
12541
|
+
retryCount: 0
|
|
12542
|
+
};
|
|
12543
|
+
const jobId = task.id;
|
|
12544
|
+
await this.config.eventBackend.enqueue(task);
|
|
12545
|
+
console.info(`[MessageQueueBridge] Event "${eventName}" enqueued to Bull Queue (job: ${jobId})`);
|
|
12546
|
+
return jobId;
|
|
12547
|
+
}
|
|
12548
|
+
async processQueuedEvent(jobId, task) {
|
|
12549
|
+
let hasError = false;
|
|
12550
|
+
let lastError = null;
|
|
12551
|
+
for (const callback of task.callbacks) {
|
|
12552
|
+
try {
|
|
12553
|
+
await callback(task.args);
|
|
12554
|
+
} catch (error) {
|
|
12555
|
+
hasError = true;
|
|
12556
|
+
lastError = error;
|
|
12557
|
+
console.error(`[MessageQueueBridge] Callback failed for event "${task.hook}" (job: ${jobId}):`, error);
|
|
12558
|
+
}
|
|
12559
|
+
}
|
|
12560
|
+
if (hasError) {
|
|
12561
|
+
console.error(`[MessageQueueBridge] Event "${task.hook}" processing failed (job: ${jobId})`);
|
|
12562
|
+
throw lastError || new Error("Event processing failed");
|
|
12563
|
+
}
|
|
12564
|
+
console.info(`[MessageQueueBridge] Event "${task.hook}" processed successfully (job: ${jobId})`);
|
|
12565
|
+
}
|
|
12566
|
+
async handleJobFailure(jobId, task, error, retryCount = 0) {
|
|
12567
|
+
console.warn(`[MessageQueueBridge] Event "${task.hook}" failed after retries (job: ${jobId}), moving to DLQ`);
|
|
12568
|
+
try {
|
|
12569
|
+
const dlqId = await this.config.dlqManager.moveToDlq(task.hook, task.args, task.options, error, retryCount);
|
|
12570
|
+
console.info(`[MessageQueueBridge] Event moved to DLQ (dlq_id: ${dlqId})`);
|
|
12571
|
+
} catch (dlqError) {
|
|
12572
|
+
console.error(`[MessageQueueBridge] Failed to move event to DLQ:`, dlqError);
|
|
12573
|
+
}
|
|
12574
|
+
}
|
|
12575
|
+
async getEventStatus(eventId) {
|
|
12576
|
+
return {
|
|
12577
|
+
eventId,
|
|
12578
|
+
status: "pending",
|
|
12579
|
+
attempts: 0,
|
|
12580
|
+
createdAt: Date.now()
|
|
12581
|
+
};
|
|
12582
|
+
}
|
|
12583
|
+
getEventBackend() {
|
|
12584
|
+
return this.config.eventBackend;
|
|
12585
|
+
}
|
|
12586
|
+
getDLQManager() {
|
|
12587
|
+
return this.config.dlqManager;
|
|
12588
|
+
}
|
|
12589
|
+
getHookManager() {
|
|
12590
|
+
return this.config.hookManager;
|
|
12591
|
+
}
|
|
12592
|
+
}
|
|
12452
12593
|
// src/events/RetryScheduler.ts
|
|
12453
12594
|
class RetryScheduler {
|
|
12454
12595
|
enabled;
|
|
@@ -13081,22 +13222,98 @@ class QueueDashboard {
|
|
|
13081
13222
|
}
|
|
13082
13223
|
}
|
|
13083
13224
|
// src/exceptions/AuthenticationException.ts
|
|
13084
|
-
class AuthenticationException extends
|
|
13225
|
+
class AuthenticationException extends DomainException {
|
|
13085
13226
|
constructor(message = "Unauthenticated.") {
|
|
13086
13227
|
super(401, "UNAUTHENTICATED", {
|
|
13087
13228
|
message,
|
|
13088
13229
|
i18nKey: "errors.authentication.unauthenticated"
|
|
13089
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);
|
|
13090
13241
|
}
|
|
13091
13242
|
}
|
|
13092
13243
|
|
|
13093
13244
|
// src/exceptions/AuthorizationException.ts
|
|
13094
|
-
class AuthorizationException extends
|
|
13245
|
+
class AuthorizationException extends DomainException {
|
|
13095
13246
|
constructor(message = "This action is unauthorized.") {
|
|
13096
13247
|
super(403, "FORBIDDEN", {
|
|
13097
13248
|
message,
|
|
13098
13249
|
i18nKey: "errors.authorization.forbidden"
|
|
13099
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);
|
|
13100
13317
|
}
|
|
13101
13318
|
}
|
|
13102
13319
|
// src/ServiceProvider.ts
|
|
@@ -13422,19 +13639,35 @@ class HttpTester {
|
|
|
13422
13639
|
body
|
|
13423
13640
|
});
|
|
13424
13641
|
const response2 = await this.core.adapter.fetch(request);
|
|
13425
|
-
const setCookie2
|
|
13426
|
-
|
|
13427
|
-
|
|
13428
|
-
|
|
13429
|
-
|
|
13430
|
-
|
|
13431
|
-
|
|
13432
|
-
|
|
13433
|
-
}
|
|
13642
|
+
for (const setCookie2 of this.getSetCookieHeaders(response2.headers)) {
|
|
13643
|
+
const cookiePair = setCookie2.split(";")[0]?.trim();
|
|
13644
|
+
if (!cookiePair) {
|
|
13645
|
+
continue;
|
|
13646
|
+
}
|
|
13647
|
+
const [name, ...valueParts] = cookiePair.split("=");
|
|
13648
|
+
if (name) {
|
|
13649
|
+
this.cookies.set(name, valueParts.join("="));
|
|
13434
13650
|
}
|
|
13435
13651
|
}
|
|
13436
13652
|
return new TestResponse(response2);
|
|
13437
13653
|
}
|
|
13654
|
+
getSetCookieHeaders(headers) {
|
|
13655
|
+
const headersWithGetSetCookie = headers;
|
|
13656
|
+
const getSetCookie = headersWithGetSetCookie.getSetCookie?.();
|
|
13657
|
+
if (getSetCookie && getSetCookie.length > 0) {
|
|
13658
|
+
return getSetCookie;
|
|
13659
|
+
}
|
|
13660
|
+
const headerJson = headersWithGetSetCookie.toJSON?.();
|
|
13661
|
+
const jsonSetCookie = headerJson?.["set-cookie"];
|
|
13662
|
+
if (Array.isArray(jsonSetCookie)) {
|
|
13663
|
+
return jsonSetCookie;
|
|
13664
|
+
}
|
|
13665
|
+
if (typeof jsonSetCookie === "string") {
|
|
13666
|
+
return [jsonSetCookie];
|
|
13667
|
+
}
|
|
13668
|
+
const setCookie2 = headers.get("Set-Cookie");
|
|
13669
|
+
return setCookie2 ? [setCookie2] : [];
|
|
13670
|
+
}
|
|
13438
13671
|
}
|
|
13439
13672
|
function createHttpTester(core) {
|
|
13440
13673
|
return new HttpTester(core);
|
|
@@ -13820,7 +14053,10 @@ export {
|
|
|
13820
14053
|
ValidationException,
|
|
13821
14054
|
VERSION,
|
|
13822
14055
|
TestResponse,
|
|
14056
|
+
SystemException,
|
|
14057
|
+
StreamException,
|
|
13823
14058
|
Str,
|
|
14059
|
+
StorageException,
|
|
13824
14060
|
StarvationProtectionStrategy,
|
|
13825
14061
|
ServiceProvider,
|
|
13826
14062
|
Router,
|
|
@@ -13836,6 +14072,7 @@ export {
|
|
|
13836
14072
|
RateLimitStrategy,
|
|
13837
14073
|
RadixRouter,
|
|
13838
14074
|
RadixNode,
|
|
14075
|
+
QueueException,
|
|
13839
14076
|
QueueDepthStrategy,
|
|
13840
14077
|
QueueDashboard,
|
|
13841
14078
|
PriorityRebalanceStrategy,
|
|
@@ -13845,6 +14082,7 @@ export {
|
|
|
13845
14082
|
OTelEventMetrics,
|
|
13846
14083
|
NodeType,
|
|
13847
14084
|
ModelNotFoundException,
|
|
14085
|
+
InfrastructureException,
|
|
13848
14086
|
IdempotencyCache,
|
|
13849
14087
|
HttpTester,
|
|
13850
14088
|
HttpException,
|
|
@@ -13863,18 +14101,22 @@ export {
|
|
|
13863
14101
|
ErrorHandler,
|
|
13864
14102
|
Encrypter,
|
|
13865
14103
|
DumpDieError,
|
|
14104
|
+
DomainException,
|
|
13866
14105
|
DeadLetterQueueManager,
|
|
13867
14106
|
DeadLetterQueue,
|
|
14107
|
+
DatabaseException,
|
|
13868
14108
|
DEFAULT_EVENT_OPTIONS,
|
|
13869
14109
|
CookieJar,
|
|
13870
14110
|
Container,
|
|
13871
14111
|
ConsoleLogger,
|
|
14112
|
+
ConfigurationException,
|
|
13872
14113
|
ConfigManager,
|
|
13873
14114
|
CompositeStrategy,
|
|
13874
14115
|
CommandKernel,
|
|
13875
14116
|
CircularDependencyException,
|
|
13876
14117
|
CircuitBreakerState,
|
|
13877
14118
|
CircuitBreaker,
|
|
14119
|
+
CacheException,
|
|
13878
14120
|
BunWebSocketHandler,
|
|
13879
14121
|
BunRequest,
|
|
13880
14122
|
BunNativeAdapter,
|
|
@@ -13884,8 +14126,9 @@ export {
|
|
|
13884
14126
|
BackpressureManager,
|
|
13885
14127
|
AuthorizationException,
|
|
13886
14128
|
AuthenticationException,
|
|
14129
|
+
AuthException,
|
|
13887
14130
|
Arr,
|
|
13888
14131
|
Application
|
|
13889
14132
|
};
|
|
13890
14133
|
|
|
13891
|
-
//# debugId=
|
|
14134
|
+
//# debugId=182898C607162D4164756E2164756E21
|