pynect 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +478 -2
- package/SECURITY.md +34 -0
- package/binding.gyp +60 -0
- package/dist/cli/codegen.d.ts +3 -0
- package/dist/cli/codegen.d.ts.map +1 -0
- package/dist/cli/codegen.js +543 -0
- package/dist/cli/codegen.js.map +1 -0
- package/dist/cli/sync.d.ts +3 -0
- package/dist/cli/sync.d.ts.map +1 -0
- package/dist/cli/sync.js +48 -0
- package/dist/cli/sync.js.map +1 -0
- package/dist/config/project.d.ts +57 -0
- package/dist/config/project.d.ts.map +1 -0
- package/dist/config/project.js +176 -0
- package/dist/config/project.js.map +1 -0
- package/dist/core/IsolatedWorker.d.ts +39 -0
- package/dist/core/IsolatedWorker.d.ts.map +1 -0
- package/dist/core/IsolatedWorker.js +178 -0
- package/dist/core/IsolatedWorker.js.map +1 -0
- package/dist/core/PyCallable.d.ts +67 -0
- package/dist/core/PyCallable.d.ts.map +1 -0
- package/dist/core/PyCallable.js +104 -0
- package/dist/core/PyCallable.js.map +1 -0
- package/dist/core/PyContext.d.ts +76 -0
- package/dist/core/PyContext.d.ts.map +1 -0
- package/dist/core/PyContext.js +239 -0
- package/dist/core/PyContext.js.map +1 -0
- package/dist/core/PyIterator.d.ts +84 -0
- package/dist/core/PyIterator.d.ts.map +1 -0
- package/dist/core/PyIterator.js +243 -0
- package/dist/core/PyIterator.js.map +1 -0
- package/dist/core/PyModule.d.ts +53 -0
- package/dist/core/PyModule.d.ts.map +1 -0
- package/dist/core/PyModule.js +162 -0
- package/dist/core/PyModule.js.map +1 -0
- package/dist/core/PyProxy.d.ts +75 -0
- package/dist/core/PyProxy.d.ts.map +1 -0
- package/dist/core/PyProxy.js +563 -0
- package/dist/core/PyProxy.js.map +1 -0
- package/dist/core/PyRuntime.d.ts +112 -0
- package/dist/core/PyRuntime.d.ts.map +1 -0
- package/dist/core/PyRuntime.js +546 -0
- package/dist/core/PyRuntime.js.map +1 -0
- package/dist/env/PackageInstaller.d.ts +232 -0
- package/dist/env/PackageInstaller.d.ts.map +1 -0
- package/dist/env/PackageInstaller.js +628 -0
- package/dist/env/PackageInstaller.js.map +1 -0
- package/dist/env/ProjectEnvironment.d.ts +63 -0
- package/dist/env/ProjectEnvironment.d.ts.map +1 -0
- package/dist/env/ProjectEnvironment.js +379 -0
- package/dist/env/ProjectEnvironment.js.map +1 -0
- package/dist/env/PyfigAdapter.d.ts +32 -0
- package/dist/env/PyfigAdapter.d.ts.map +1 -0
- package/dist/env/PyfigAdapter.js +10 -0
- package/dist/env/PyfigAdapter.js.map +1 -0
- package/dist/env/PythonDetector.d.ts +48 -0
- package/dist/env/PythonDetector.d.ts.map +1 -0
- package/dist/env/PythonDetector.js +182 -0
- package/dist/env/PythonDetector.js.map +1 -0
- package/dist/env/PythonProvisioner.d.ts +16 -0
- package/dist/env/PythonProvisioner.d.ts.map +1 -0
- package/dist/env/PythonProvisioner.js +42 -0
- package/dist/env/PythonProvisioner.js.map +1 -0
- package/dist/env/VenvManager.d.ts +55 -0
- package/dist/env/VenvManager.d.ts.map +1 -0
- package/dist/env/VenvManager.js +153 -0
- package/dist/env/VenvManager.js.map +1 -0
- package/dist/env/executables.d.ts +3 -0
- package/dist/env/executables.d.ts.map +1 -0
- package/dist/env/executables.js +14 -0
- package/dist/env/executables.js.map +1 -0
- package/dist/index.d.ts +182 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +393 -0
- package/dist/index.js.map +1 -0
- package/dist/native/NativeAddonLoader.d.ts +11 -0
- package/dist/native/NativeAddonLoader.d.ts.map +1 -0
- package/dist/native/NativeAddonLoader.js +75 -0
- package/dist/native/NativeAddonLoader.js.map +1 -0
- package/dist/plugins/Plugin.interface.d.ts +41 -0
- package/dist/plugins/Plugin.interface.d.ts.map +1 -0
- package/dist/plugins/Plugin.interface.js +12 -0
- package/dist/plugins/Plugin.interface.js.map +1 -0
- package/dist/plugins/PluginManager.d.ts +26 -0
- package/dist/plugins/PluginManager.d.ts.map +1 -0
- package/dist/plugins/PluginManager.js +174 -0
- package/dist/plugins/PluginManager.js.map +1 -0
- package/dist/plugins/builtin/NumpyPlugin.d.ts +17 -0
- package/dist/plugins/builtin/NumpyPlugin.d.ts.map +1 -0
- package/dist/plugins/builtin/NumpyPlugin.js +41 -0
- package/dist/plugins/builtin/NumpyPlugin.js.map +1 -0
- package/dist/plugins/builtin/PandasPlugin.d.ts +19 -0
- package/dist/plugins/builtin/PandasPlugin.d.ts.map +1 -0
- package/dist/plugins/builtin/PandasPlugin.js +57 -0
- package/dist/plugins/builtin/PandasPlugin.js.map +1 -0
- package/dist/plugins/builtin/TorchPlugin.d.ts +23 -0
- package/dist/plugins/builtin/TorchPlugin.d.ts.map +1 -0
- package/dist/plugins/builtin/TorchPlugin.js +50 -0
- package/dist/plugins/builtin/TorchPlugin.js.map +1 -0
- package/dist/plugins/index.d.ts +7 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +12 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/serialization/DataFrameBridge.d.ts +141 -0
- package/dist/serialization/DataFrameBridge.d.ts.map +1 -0
- package/dist/serialization/DataFrameBridge.js +355 -0
- package/dist/serialization/DataFrameBridge.js.map +1 -0
- package/dist/serialization/MsgPackSerializer.d.ts +45 -0
- package/dist/serialization/MsgPackSerializer.d.ts.map +1 -0
- package/dist/serialization/MsgPackSerializer.js +242 -0
- package/dist/serialization/MsgPackSerializer.js.map +1 -0
- package/dist/serialization/NumpyBridge.d.ts +96 -0
- package/dist/serialization/NumpyBridge.d.ts.map +1 -0
- package/dist/serialization/NumpyBridge.js +323 -0
- package/dist/serialization/NumpyBridge.js.map +1 -0
- package/dist/serialization/Serializer.d.ts +78 -0
- package/dist/serialization/Serializer.d.ts.map +1 -0
- package/dist/serialization/Serializer.js +281 -0
- package/dist/serialization/Serializer.js.map +1 -0
- package/dist/types/addon.d.ts +131 -0
- package/dist/types/addon.d.ts.map +1 -0
- package/dist/types/addon.js +32 -0
- package/dist/types/addon.js.map +1 -0
- package/dist/types/config.d.ts +233 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +60 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +12 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/python.d.ts +235 -0
- package/dist/types/python.d.ts.map +1 -0
- package/dist/types/python.js +7 -0
- package/dist/types/python.js.map +1 -0
- package/dist/utils/ErrorTranslator.d.ts +83 -0
- package/dist/utils/ErrorTranslator.d.ts.map +1 -0
- package/dist/utils/ErrorTranslator.js +210 -0
- package/dist/utils/ErrorTranslator.js.map +1 -0
- package/dist/utils/Locking.d.ts +3 -0
- package/dist/utils/Locking.d.ts.map +1 -0
- package/dist/utils/Locking.js +10 -0
- package/dist/utils/Locking.js.map +1 -0
- package/dist/utils/Logger.d.ts +27 -0
- package/dist/utils/Logger.d.ts.map +1 -0
- package/dist/utils/Logger.js +115 -0
- package/dist/utils/Logger.js.map +1 -0
- package/dist/utils/MemoryMonitor.d.ts +43 -0
- package/dist/utils/MemoryMonitor.d.ts.map +1 -0
- package/dist/utils/MemoryMonitor.js +143 -0
- package/dist/utils/MemoryMonitor.js.map +1 -0
- package/package.json +114 -4
- package/python/ast_inspector.py +248 -0
- package/python/error_handler.py +432 -0
- package/python/isolated_worker.py +94 -0
- package/python/pynect_dispatcher.py +382 -0
- package/python/pynect_runtime.py +574 -0
- package/python/serializer.py +373 -0
- package/python/type_inspector.py +315 -0
- package/scripts/build-native.js +50 -0
- package/scripts/cli.js +21 -0
- package/scripts/ensure-native.js +85 -0
- package/scripts/postinstall.js +40 -0
- package/scripts/pyfig.js +113 -0
- package/scripts/python-provisioner.js +23 -0
- package/scripts/smoke-python-boundary.js +103 -0
- package/src/native/NativeAddonLoader.ts +98 -0
- package/src/native/gil_guard.cpp +25 -0
- package/src/native/gil_guard.h +174 -0
- package/src/native/pynect_addon.cpp +942 -0
- package/src/native/python_bridge.cpp +904 -0
- package/src/native/python_bridge.h +263 -0
- package/src/native/thread_pool.cpp +375 -0
- package/src/native/thread_pool.h +185 -0
- package/src/native/type_converter.cpp +906 -0
- package/src/native/type_converter.h +271 -0
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pynect - Error Translator
|
|
3
|
+
* Converts Python exceptions into proper JavaScript Error subclasses.
|
|
4
|
+
* Preserves full traceback, exception type, and chained causes.
|
|
5
|
+
*/
|
|
6
|
+
import type { PyErrorInfo } from '../types/python';
|
|
7
|
+
/**
|
|
8
|
+
* Base class for all Python-originating errors.
|
|
9
|
+
* Provides access to Python-specific error metadata.
|
|
10
|
+
*/
|
|
11
|
+
export declare class PythonError extends Error {
|
|
12
|
+
/** Python exception class name (e.g. 'ValueError', 'FileNotFoundError') */
|
|
13
|
+
readonly pythonType: string;
|
|
14
|
+
/** Python module where the exception originated */
|
|
15
|
+
readonly pythonModule: string;
|
|
16
|
+
/** Full Python traceback string */
|
|
17
|
+
readonly traceback: string;
|
|
18
|
+
/** Original PyErrorInfo object */
|
|
19
|
+
readonly pyErrorInfo: PyErrorInfo;
|
|
20
|
+
constructor(info: PyErrorInfo);
|
|
21
|
+
/** Format error with Python traceback for display */
|
|
22
|
+
format(): string;
|
|
23
|
+
}
|
|
24
|
+
export declare class PythonValueError extends PythonError {
|
|
25
|
+
constructor(info: PyErrorInfo);
|
|
26
|
+
}
|
|
27
|
+
export declare class PythonTypeError extends PythonError {
|
|
28
|
+
constructor(info: PyErrorInfo);
|
|
29
|
+
}
|
|
30
|
+
export declare class PythonKeyError extends PythonError {
|
|
31
|
+
constructor(info: PyErrorInfo);
|
|
32
|
+
}
|
|
33
|
+
export declare class PythonIndexError extends PythonError {
|
|
34
|
+
constructor(info: PyErrorInfo);
|
|
35
|
+
}
|
|
36
|
+
export declare class PythonAttributeError extends PythonError {
|
|
37
|
+
constructor(info: PyErrorInfo);
|
|
38
|
+
}
|
|
39
|
+
export declare class PythonImportError extends PythonError {
|
|
40
|
+
constructor(info: PyErrorInfo);
|
|
41
|
+
}
|
|
42
|
+
export declare class PythonModuleNotFoundError extends PythonImportError {
|
|
43
|
+
constructor(info: PyErrorInfo);
|
|
44
|
+
}
|
|
45
|
+
export declare class PythonFileNotFoundError extends PythonError {
|
|
46
|
+
constructor(info: PyErrorInfo);
|
|
47
|
+
}
|
|
48
|
+
export declare class PythonPermissionError extends PythonError {
|
|
49
|
+
constructor(info: PyErrorInfo);
|
|
50
|
+
}
|
|
51
|
+
export declare class PythonRuntimeError extends PythonError {
|
|
52
|
+
constructor(info: PyErrorInfo);
|
|
53
|
+
}
|
|
54
|
+
export declare class PythonMemoryError extends PythonError {
|
|
55
|
+
constructor(info: PyErrorInfo);
|
|
56
|
+
}
|
|
57
|
+
export declare class PythonStopIteration extends PythonError {
|
|
58
|
+
constructor(info: PyErrorInfo);
|
|
59
|
+
}
|
|
60
|
+
export declare class PythonTimeoutError extends Error {
|
|
61
|
+
readonly timeoutMs: number;
|
|
62
|
+
constructor(timeoutMs: number, operation: string);
|
|
63
|
+
}
|
|
64
|
+
export declare class PynectNotInitializedError extends Error {
|
|
65
|
+
constructor(message?: string);
|
|
66
|
+
}
|
|
67
|
+
export declare class PynectShutdownError extends Error {
|
|
68
|
+
constructor(message?: string);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Translates a PyErrorInfo (from the C++ addon) into the appropriate
|
|
72
|
+
* JavaScript Error subclass. Falls back to generic PythonError.
|
|
73
|
+
*/
|
|
74
|
+
export declare function translatePythonError(info: PyErrorInfo): PythonError;
|
|
75
|
+
/**
|
|
76
|
+
* Type guard: checks whether a value is a PythonError.
|
|
77
|
+
*/
|
|
78
|
+
export declare function isPythonError(value: unknown): value is PythonError;
|
|
79
|
+
/**
|
|
80
|
+
* Type guard: checks whether a value is a specific Python exception type.
|
|
81
|
+
*/
|
|
82
|
+
export declare function isPythonErrorOfType(value: unknown, pythonType: string): value is PythonError;
|
|
83
|
+
//# sourceMappingURL=ErrorTranslator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorTranslator.d.ts","sourceRoot":"","sources":["../../src/utils/ErrorTranslator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD;;;GAGG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC,2EAA2E;IAC3E,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,mDAAmD;IACnD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,mCAAmC;IACnC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,kCAAkC;IAClC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;gBAEtB,IAAI,EAAE,WAAW;IAiB7B,qDAAqD;IACrD,MAAM,IAAI,MAAM;CAUjB;AAID,qBAAa,gBAAiB,SAAQ,WAAW;gBACnC,IAAI,EAAE,WAAW;CAK9B;AAED,qBAAa,eAAgB,SAAQ,WAAW;gBAClC,IAAI,EAAE,WAAW;CAK9B;AAED,qBAAa,cAAe,SAAQ,WAAW;gBACjC,IAAI,EAAE,WAAW;CAK9B;AAED,qBAAa,gBAAiB,SAAQ,WAAW;gBACnC,IAAI,EAAE,WAAW;CAK9B;AAED,qBAAa,oBAAqB,SAAQ,WAAW;gBACvC,IAAI,EAAE,WAAW;CAK9B;AAED,qBAAa,iBAAkB,SAAQ,WAAW;gBACpC,IAAI,EAAE,WAAW;CAK9B;AAED,qBAAa,yBAA0B,SAAQ,iBAAiB;gBAClD,IAAI,EAAE,WAAW;CAK9B;AAED,qBAAa,uBAAwB,SAAQ,WAAW;gBAC1C,IAAI,EAAE,WAAW;CAK9B;AAED,qBAAa,qBAAsB,SAAQ,WAAW;gBACxC,IAAI,EAAE,WAAW;CAK9B;AAED,qBAAa,kBAAmB,SAAQ,WAAW;gBACrC,IAAI,EAAE,WAAW;CAK9B;AAED,qBAAa,iBAAkB,SAAQ,WAAW;gBACpC,IAAI,EAAE,WAAW;CAK9B;AAED,qBAAa,mBAAoB,SAAQ,WAAW;gBACtC,IAAI,EAAE,WAAW;CAK9B;AAED,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;gBAEf,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;CAMjD;AAED,qBAAa,yBAA0B,SAAQ,KAAK;gBACtC,OAAO,SAAyD;CAK7E;AAED,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,OAAO,SAAuC;CAK3D;AAsBD;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,CAGnE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,WAAW,CAElE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,KAAK,IAAI,WAAW,CAE5F"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* pynect - Error Translator
|
|
4
|
+
* Converts Python exceptions into proper JavaScript Error subclasses.
|
|
5
|
+
* Preserves full traceback, exception type, and chained causes.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.PynectShutdownError = exports.PynectNotInitializedError = exports.PythonTimeoutError = exports.PythonStopIteration = exports.PythonMemoryError = exports.PythonRuntimeError = exports.PythonPermissionError = exports.PythonFileNotFoundError = exports.PythonModuleNotFoundError = exports.PythonImportError = exports.PythonAttributeError = exports.PythonIndexError = exports.PythonKeyError = exports.PythonTypeError = exports.PythonValueError = exports.PythonError = void 0;
|
|
9
|
+
exports.translatePythonError = translatePythonError;
|
|
10
|
+
exports.isPythonError = isPythonError;
|
|
11
|
+
exports.isPythonErrorOfType = isPythonErrorOfType;
|
|
12
|
+
/**
|
|
13
|
+
* Base class for all Python-originating errors.
|
|
14
|
+
* Provides access to Python-specific error metadata.
|
|
15
|
+
*/
|
|
16
|
+
class PythonError extends Error {
|
|
17
|
+
/** Python exception class name (e.g. 'ValueError', 'FileNotFoundError') */
|
|
18
|
+
pythonType;
|
|
19
|
+
/** Python module where the exception originated */
|
|
20
|
+
pythonModule;
|
|
21
|
+
/** Full Python traceback string */
|
|
22
|
+
traceback;
|
|
23
|
+
/** Original PyErrorInfo object */
|
|
24
|
+
pyErrorInfo;
|
|
25
|
+
constructor(info) {
|
|
26
|
+
super(`[Python ${info.type}] ${info.message}`);
|
|
27
|
+
this.name = 'PythonError';
|
|
28
|
+
this.pythonType = info.type;
|
|
29
|
+
this.pythonModule = info.module ?? 'builtins';
|
|
30
|
+
this.traceback = info.traceback;
|
|
31
|
+
this.pyErrorInfo = info;
|
|
32
|
+
// Maintain proper prototype chain
|
|
33
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
34
|
+
// Capture stack trace
|
|
35
|
+
if (Error.captureStackTrace) {
|
|
36
|
+
Error.captureStackTrace(this, PythonError);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** Format error with Python traceback for display */
|
|
40
|
+
format() {
|
|
41
|
+
return [
|
|
42
|
+
`PythonError: ${this.pythonType}: ${this.pyErrorInfo.message}`,
|
|
43
|
+
'',
|
|
44
|
+
'--- Python Traceback ---',
|
|
45
|
+
this.traceback,
|
|
46
|
+
'--- Node.js Stack ---',
|
|
47
|
+
this.stack ?? '',
|
|
48
|
+
].join('\n');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.PythonError = PythonError;
|
|
52
|
+
// Specific Python Exception Subclasses
|
|
53
|
+
class PythonValueError extends PythonError {
|
|
54
|
+
constructor(info) {
|
|
55
|
+
super(info);
|
|
56
|
+
this.name = 'PythonValueError';
|
|
57
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.PythonValueError = PythonValueError;
|
|
61
|
+
class PythonTypeError extends PythonError {
|
|
62
|
+
constructor(info) {
|
|
63
|
+
super(info);
|
|
64
|
+
this.name = 'PythonTypeError';
|
|
65
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.PythonTypeError = PythonTypeError;
|
|
69
|
+
class PythonKeyError extends PythonError {
|
|
70
|
+
constructor(info) {
|
|
71
|
+
super(info);
|
|
72
|
+
this.name = 'PythonKeyError';
|
|
73
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.PythonKeyError = PythonKeyError;
|
|
77
|
+
class PythonIndexError extends PythonError {
|
|
78
|
+
constructor(info) {
|
|
79
|
+
super(info);
|
|
80
|
+
this.name = 'PythonIndexError';
|
|
81
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.PythonIndexError = PythonIndexError;
|
|
85
|
+
class PythonAttributeError extends PythonError {
|
|
86
|
+
constructor(info) {
|
|
87
|
+
super(info);
|
|
88
|
+
this.name = 'PythonAttributeError';
|
|
89
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.PythonAttributeError = PythonAttributeError;
|
|
93
|
+
class PythonImportError extends PythonError {
|
|
94
|
+
constructor(info) {
|
|
95
|
+
super(info);
|
|
96
|
+
this.name = 'PythonImportError';
|
|
97
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.PythonImportError = PythonImportError;
|
|
101
|
+
class PythonModuleNotFoundError extends PythonImportError {
|
|
102
|
+
constructor(info) {
|
|
103
|
+
super(info);
|
|
104
|
+
this.name = 'PythonModuleNotFoundError';
|
|
105
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.PythonModuleNotFoundError = PythonModuleNotFoundError;
|
|
109
|
+
class PythonFileNotFoundError extends PythonError {
|
|
110
|
+
constructor(info) {
|
|
111
|
+
super(info);
|
|
112
|
+
this.name = 'PythonFileNotFoundError';
|
|
113
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.PythonFileNotFoundError = PythonFileNotFoundError;
|
|
117
|
+
class PythonPermissionError extends PythonError {
|
|
118
|
+
constructor(info) {
|
|
119
|
+
super(info);
|
|
120
|
+
this.name = 'PythonPermissionError';
|
|
121
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.PythonPermissionError = PythonPermissionError;
|
|
125
|
+
class PythonRuntimeError extends PythonError {
|
|
126
|
+
constructor(info) {
|
|
127
|
+
super(info);
|
|
128
|
+
this.name = 'PythonRuntimeError';
|
|
129
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
exports.PythonRuntimeError = PythonRuntimeError;
|
|
133
|
+
class PythonMemoryError extends PythonError {
|
|
134
|
+
constructor(info) {
|
|
135
|
+
super(info);
|
|
136
|
+
this.name = 'PythonMemoryError';
|
|
137
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.PythonMemoryError = PythonMemoryError;
|
|
141
|
+
class PythonStopIteration extends PythonError {
|
|
142
|
+
constructor(info) {
|
|
143
|
+
super(info);
|
|
144
|
+
this.name = 'PythonStopIteration';
|
|
145
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.PythonStopIteration = PythonStopIteration;
|
|
149
|
+
class PythonTimeoutError extends Error {
|
|
150
|
+
timeoutMs;
|
|
151
|
+
constructor(timeoutMs, operation) {
|
|
152
|
+
super(`Python operation timed out after ${timeoutMs}ms: ${operation}`);
|
|
153
|
+
this.name = 'PythonTimeoutError';
|
|
154
|
+
this.timeoutMs = timeoutMs;
|
|
155
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.PythonTimeoutError = PythonTimeoutError;
|
|
159
|
+
class PynectNotInitializedError extends Error {
|
|
160
|
+
constructor(message = 'pynect is not initialized. Call pynect.init() first.') {
|
|
161
|
+
super(message);
|
|
162
|
+
this.name = 'PynectNotInitializedError';
|
|
163
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.PynectNotInitializedError = PynectNotInitializedError;
|
|
167
|
+
class PynectShutdownError extends Error {
|
|
168
|
+
constructor(message = 'pynect runtime has been shut down.') {
|
|
169
|
+
super(message);
|
|
170
|
+
this.name = 'PynectShutdownError';
|
|
171
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
exports.PynectShutdownError = PynectShutdownError;
|
|
175
|
+
const EXCEPTION_MAP = {
|
|
176
|
+
ValueError: PythonValueError,
|
|
177
|
+
TypeError: PythonTypeError,
|
|
178
|
+
KeyError: PythonKeyError,
|
|
179
|
+
IndexError: PythonIndexError,
|
|
180
|
+
AttributeError: PythonAttributeError,
|
|
181
|
+
ImportError: PythonImportError,
|
|
182
|
+
ModuleNotFoundError: PythonModuleNotFoundError,
|
|
183
|
+
FileNotFoundError: PythonFileNotFoundError,
|
|
184
|
+
PermissionError: PythonPermissionError,
|
|
185
|
+
RuntimeError: PythonRuntimeError,
|
|
186
|
+
MemoryError: PythonMemoryError,
|
|
187
|
+
StopIteration: PythonStopIteration,
|
|
188
|
+
StopAsyncIteration: PythonStopIteration,
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Translates a PyErrorInfo (from the C++ addon) into the appropriate
|
|
192
|
+
* JavaScript Error subclass. Falls back to generic PythonError.
|
|
193
|
+
*/
|
|
194
|
+
function translatePythonError(info) {
|
|
195
|
+
const Ctor = EXCEPTION_MAP[info.type] ?? PythonError;
|
|
196
|
+
return new Ctor(info);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Type guard: checks whether a value is a PythonError.
|
|
200
|
+
*/
|
|
201
|
+
function isPythonError(value) {
|
|
202
|
+
return value instanceof PythonError;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Type guard: checks whether a value is a specific Python exception type.
|
|
206
|
+
*/
|
|
207
|
+
function isPythonErrorOfType(value, pythonType) {
|
|
208
|
+
return value instanceof PythonError && value.pythonType === pythonType;
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=ErrorTranslator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ErrorTranslator.js","sourceRoot":"","sources":["../../src/utils/ErrorTranslator.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAqMH,oDAGC;AAKD,sCAEC;AAKD,kDAEC;AAlND;;;GAGG;AACH,MAAa,WAAY,SAAQ,KAAK;IACpC,2EAA2E;IAClE,UAAU,CAAS;IAC5B,mDAAmD;IAC1C,YAAY,CAAS;IAC9B,mCAAmC;IAC1B,SAAS,CAAS;IAC3B,kCAAkC;IACzB,WAAW,CAAc;IAElC,YAAY,IAAiB;QAC3B,KAAK,CAAC,WAAW,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QAC/C,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC;QAC5B,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,MAAM,IAAI,UAAU,CAAC;QAC9C,IAAI,CAA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aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC;IACrD,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,OAAO,KAAK,YAAY,WAAW,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,SAAgB,mBAAmB,CAAC,KAAc,EAAE,UAAkB;IACpE,OAAO,KAAK,YAAY,WAAW,IAAI,KAAK,CAAC,UAAU,KAAK,UAAU,CAAC;AACzE,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type LockAction, type LockOptions, type LockPredicate, type LockResult } from 'loqkit';
|
|
2
|
+
export declare function withPynectLock<TContext extends object, TResult>(context: TContext, action: LockAction<TContext, TResult>, predicate?: LockPredicate<TContext>, options?: LockOptions<TContext>): Promise<LockResult<TContext, TResult>>;
|
|
3
|
+
//# sourceMappingURL=Locking.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Locking.d.ts","sourceRoot":"","sources":["../../src/utils/Locking.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,UAAU,EACf,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,UAAU,EAChB,MAAM,QAAQ,CAAC;AAEhB,wBAAsB,cAAc,CAAC,QAAQ,SAAS,MAAM,EAAE,OAAO,EACnE,OAAO,EAAE,QAAQ,EACjB,MAAM,EAAE,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,EACrC,SAAS,CAAC,EAAE,aAAa,CAAC,QAAQ,CAAC,EACnC,OAAO,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,GAC9B,OAAO,CAAC,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAIxC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withPynectLock = withPynectLock;
|
|
4
|
+
const loqkit_1 = require("loqkit");
|
|
5
|
+
async function withPynectLock(context, action, predicate, options) {
|
|
6
|
+
return predicate
|
|
7
|
+
? (0, loqkit_1.withLock)(context, action, predicate, options)
|
|
8
|
+
: (0, loqkit_1.withLock)(context, action, options);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=Locking.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Locking.js","sourceRoot":"","sources":["../../src/utils/Locking.ts"],"names":[],"mappings":";;AAQA,wCASC;AAjBD,mCAMgB;AAET,KAAK,UAAU,cAAc,CAClC,OAAiB,EACjB,MAAqC,EACrC,SAAmC,EACnC,OAA+B;IAE/B,OAAO,SAAS;QACd,CAAC,CAAC,IAAA,iBAAQ,EAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC;QAC/C,CAAC,CAAC,IAAA,iBAAQ,EAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* pynect - Logger
|
|
3
|
+
* Structured logger with level filtering and colorized output.
|
|
4
|
+
*/
|
|
5
|
+
import type { LogLevel } from '../types/config';
|
|
6
|
+
export declare class Logger {
|
|
7
|
+
private _level;
|
|
8
|
+
private _prefix;
|
|
9
|
+
private static _globalLevel;
|
|
10
|
+
constructor(prefix: string, level?: LogLevel);
|
|
11
|
+
static setGlobalLevel(level: LogLevel): void;
|
|
12
|
+
setLevel(level: LogLevel): void;
|
|
13
|
+
private _shouldLog;
|
|
14
|
+
private _format;
|
|
15
|
+
error(message: string, data?: unknown): void;
|
|
16
|
+
warn(message: string, data?: unknown): void;
|
|
17
|
+
info(message: string, data?: unknown): void;
|
|
18
|
+
debug(message: string, data?: unknown): void;
|
|
19
|
+
success(message: string, data?: unknown): void;
|
|
20
|
+
time(label: string): () => void;
|
|
21
|
+
child(subPrefix: string): Logger;
|
|
22
|
+
}
|
|
23
|
+
/** Global logger factory */
|
|
24
|
+
export declare function createLogger(prefix: string, level?: LogLevel): Logger;
|
|
25
|
+
/** Default Pynect logger */
|
|
26
|
+
export declare const logger: Logger;
|
|
27
|
+
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/utils/Logger.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AA6BhD,qBAAa,MAAM;IACjB,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAC,YAAY,CAAoB;gBAEnC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,QAAQ;IAK5C,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAI5C,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAI/B,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,OAAO;IAYf,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAM5C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAM3C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAM3C,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAM5C,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAM9C,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,IAAI;IAQ/B,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;CAGjC;AAED,4BAA4B;AAC5B,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,QAAQ,GAAG,MAAM,CAErE;AAED,4BAA4B;AAC5B,eAAO,MAAM,MAAM,QAAyB,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* pynect - Logger
|
|
4
|
+
* Structured logger with level filtering and colorized output.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.logger = exports.Logger = void 0;
|
|
8
|
+
exports.createLogger = createLogger;
|
|
9
|
+
const LEVELS = {
|
|
10
|
+
silent: 0,
|
|
11
|
+
error: 1,
|
|
12
|
+
warn: 2,
|
|
13
|
+
info: 3,
|
|
14
|
+
debug: 4,
|
|
15
|
+
};
|
|
16
|
+
const COLORS = {
|
|
17
|
+
reset: '\x1b[0m',
|
|
18
|
+
red: '\x1b[31m',
|
|
19
|
+
yellow: '\x1b[33m',
|
|
20
|
+
cyan: '\x1b[36m',
|
|
21
|
+
gray: '\x1b[90m',
|
|
22
|
+
green: '\x1b[32m',
|
|
23
|
+
blue: '\x1b[34m',
|
|
24
|
+
};
|
|
25
|
+
function colorize(color, text) {
|
|
26
|
+
if (!process.stdout.isTTY) {
|
|
27
|
+
return text;
|
|
28
|
+
}
|
|
29
|
+
return `${COLORS[color]}${text}${COLORS.reset}`;
|
|
30
|
+
}
|
|
31
|
+
function formatTimestamp() {
|
|
32
|
+
return new Date().toISOString().replace('T', ' ').replace('Z', '');
|
|
33
|
+
}
|
|
34
|
+
class Logger {
|
|
35
|
+
_level;
|
|
36
|
+
_prefix;
|
|
37
|
+
static _globalLevel = 'warn';
|
|
38
|
+
constructor(prefix, level) {
|
|
39
|
+
this._prefix = prefix;
|
|
40
|
+
this._level = level ?? Logger._globalLevel;
|
|
41
|
+
}
|
|
42
|
+
static setGlobalLevel(level) {
|
|
43
|
+
Logger._globalLevel = level;
|
|
44
|
+
}
|
|
45
|
+
setLevel(level) {
|
|
46
|
+
this._level = level;
|
|
47
|
+
}
|
|
48
|
+
_shouldLog(level) {
|
|
49
|
+
return LEVELS[level] <= LEVELS[this._level];
|
|
50
|
+
}
|
|
51
|
+
_format(level, message, data) {
|
|
52
|
+
const ts = colorize('gray', formatTimestamp());
|
|
53
|
+
const lvl = level;
|
|
54
|
+
const prefix = colorize('blue', `[${this._prefix}]`);
|
|
55
|
+
let line = `${ts} ${lvl} ${prefix} ${message}`;
|
|
56
|
+
if (data !== undefined) {
|
|
57
|
+
const dataStr = typeof data === 'string' ? data : JSON.stringify(data, null, 2);
|
|
58
|
+
line += `\n${colorize('gray', dataStr)}`;
|
|
59
|
+
}
|
|
60
|
+
return line;
|
|
61
|
+
}
|
|
62
|
+
error(message, data) {
|
|
63
|
+
if (!this._shouldLog('error')) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const lvl = colorize('red', 'ERROR');
|
|
67
|
+
console.error(this._format(lvl, message, data));
|
|
68
|
+
}
|
|
69
|
+
warn(message, data) {
|
|
70
|
+
if (!this._shouldLog('warn')) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const lvl = colorize('yellow', 'WARN ');
|
|
74
|
+
console.warn(this._format(lvl, message, data));
|
|
75
|
+
}
|
|
76
|
+
info(message, data) {
|
|
77
|
+
if (!this._shouldLog('info')) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const lvl = colorize('cyan', 'INFO ');
|
|
81
|
+
console.info(this._format(lvl, message, data));
|
|
82
|
+
}
|
|
83
|
+
debug(message, data) {
|
|
84
|
+
if (!this._shouldLog('debug')) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const lvl = colorize('gray', 'DEBUG');
|
|
88
|
+
console.debug(this._format(lvl, message, data));
|
|
89
|
+
}
|
|
90
|
+
success(message, data) {
|
|
91
|
+
if (!this._shouldLog('info')) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const lvl = colorize('green', 'OK ');
|
|
95
|
+
console.info(this._format(lvl, message, data));
|
|
96
|
+
}
|
|
97
|
+
time(label) {
|
|
98
|
+
const start = performance.now();
|
|
99
|
+
return () => {
|
|
100
|
+
const elapsed = (performance.now() - start).toFixed(2);
|
|
101
|
+
this.debug(`${label} completed in ${elapsed}ms`);
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
child(subPrefix) {
|
|
105
|
+
return new Logger(`${this._prefix}:${subPrefix}`, this._level);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.Logger = Logger;
|
|
109
|
+
/** Global logger factory */
|
|
110
|
+
function createLogger(prefix, level) {
|
|
111
|
+
return new Logger(prefix, level);
|
|
112
|
+
}
|
|
113
|
+
/** Default Pynect logger */
|
|
114
|
+
exports.logger = createLogger('pynect');
|
|
115
|
+
//# sourceMappingURL=Logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Logger.js","sourceRoot":"","sources":["../../src/utils/Logger.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA6GH,oCAEC;AA3GD,MAAM,MAAM,GAA6B;IACvC,MAAM,EAAE,CAAC;IACT,KAAK,EAAE,CAAC;IACR,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;CACT,CAAC;AAEF,MAAM,MAAM,GAAG;IACb,KAAK,EAAE,SAAS;IAChB,GAAG,EAAE,UAAU;IACf,MAAM,EAAE,UAAU;IAClB,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,UAAU;IAChB,KAAK,EAAE,UAAU;IACjB,IAAI,EAAE,UAAU;CACjB,CAAC;AAEF,SAAS,QAAQ,CAAC,KAA0B,EAAE,IAAY;IACxD,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QAAA,OAAO,IAAI,CAAC;IAAA,CAAC;IACzC,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC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Memory Monitor
|
|
3
|
+
* Tracks Python object references, heap usage, and triggers GC when needed.
|
|
4
|
+
*/
|
|
5
|
+
import type { NativeAddon } from '../types/addon';
|
|
6
|
+
export interface MemorySnapshot {
|
|
7
|
+
timestamp: number;
|
|
8
|
+
pythonHeapBytes: number;
|
|
9
|
+
pythonHeapPeakBytes: number;
|
|
10
|
+
trackedObjects: number;
|
|
11
|
+
pendingCallbacks: number;
|
|
12
|
+
nodeHeapUsed: number;
|
|
13
|
+
nodeHeapTotal: number;
|
|
14
|
+
nodeExternal: number;
|
|
15
|
+
}
|
|
16
|
+
export interface MemoryThresholds {
|
|
17
|
+
/** Trigger GC when Python heap exceeds this (bytes). Default: 1GB */
|
|
18
|
+
gcThreshold: number;
|
|
19
|
+
/** Emit warning when tracked objects exceed this. Default: 10000 */
|
|
20
|
+
objectWarningCount: number;
|
|
21
|
+
/** Emit warning when pending callbacks exceed this. Default: 500 */
|
|
22
|
+
callbackWarningCount: number;
|
|
23
|
+
}
|
|
24
|
+
export declare class MemoryMonitor {
|
|
25
|
+
private readonly _logger;
|
|
26
|
+
private _addon;
|
|
27
|
+
private _snapshots;
|
|
28
|
+
private _maxSnapshots;
|
|
29
|
+
private _monitorInterval;
|
|
30
|
+
private _thresholds;
|
|
31
|
+
constructor(thresholds?: Partial<MemoryThresholds>);
|
|
32
|
+
attach(addon: NativeAddon): void;
|
|
33
|
+
startMonitoring(intervalMs?: number): void;
|
|
34
|
+
stopMonitoring(): void;
|
|
35
|
+
takeSnapshot(): Promise<MemorySnapshot>;
|
|
36
|
+
getSnapshots(): MemorySnapshot[];
|
|
37
|
+
getLatestSnapshot(): MemorySnapshot | null;
|
|
38
|
+
forceGC(): Promise<void>;
|
|
39
|
+
private _checkMemory;
|
|
40
|
+
private _parseBytes;
|
|
41
|
+
private _formatBytes;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=MemoryMonitor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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