@opra/core 1.28.4 → 1.29.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 +1 -1
- package/README.md +32 -4
- package/execution-bundle.d.ts +44 -0
- package/execution-bundle.js +31 -0
- package/execution-context.d.ts +11 -4
- package/execution-context.js +7 -2
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +3 -2
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,19 +1,47 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<a href="https://oprajs.com">
|
|
4
|
+
<img src="https://oprajs.com/img/opra-header-block.webp" width="880" alt="OPRA — Open Platform for Rich APIs" />
|
|
5
|
+
</a>
|
|
6
|
+
|
|
1
7
|
# @opra/core
|
|
2
8
|
|
|
9
|
+
Runtime engine of the OPRA framework — request lifecycle, validation, and routing
|
|
10
|
+
|
|
3
11
|
[![NPM Version][npm-image]][npm-url]
|
|
4
12
|
[![NPM Downloads][downloads-image]][downloads-url]
|
|
5
13
|
[![CI Tests][ci-test-image]][ci-test-url]
|
|
6
14
|
[![Test Coverage][coveralls-image]][coveralls-url]
|
|
7
15
|
|
|
16
|
+
[🌐 Documentation](https://oprajs.com) · [🚀 Getting Started](https://oprajs.com/docs/introduction) · [📦 Packages](https://github.com/panates/opra#packages) · [💬 Issues](https://github.com/panates/opra/issues)
|
|
17
|
+
|
|
18
|
+
</div>
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
Core runtime package of the [OPRA](https://oprajs.com) framework. Provides the execution engine, platform adapter base classes, service patterns, and infrastructure utilities that all OPRA adapters and services depend on.
|
|
8
23
|
|
|
9
|
-
##
|
|
10
|
-
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- **Platform Adapter Base** — Abstract foundation for HTTP, Socket.IO, Kafka, RabbitMQ, and other transport adapters
|
|
27
|
+
- **Execution Context** — Request-scoped context carrying adapter, document, transport, and platform references
|
|
28
|
+
- **Service Pattern** — `ServiceBase` with context propagation and immutable `.for()` cloning
|
|
29
|
+
- **i18n Support** — Built-in internationalization with lazy-loading of resource bundles and localized error messages
|
|
30
|
+
- **Asset Cache** — WeakMap-based cache for automatic memory-safe asset lifecycle management
|
|
31
|
+
- **Event-Driven** — `AsyncEventEmitter`-based lifecycle hooks on both adapters and execution contexts
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install @opra/core
|
|
37
|
+
```
|
|
11
38
|
|
|
12
39
|
## Node Compatibility
|
|
13
|
-
- node >= 20.x
|
|
14
40
|
|
|
41
|
+
- node >= 20.x
|
|
15
42
|
|
|
16
43
|
## License
|
|
44
|
+
|
|
17
45
|
Available under [MIT](LICENSE) license.
|
|
18
46
|
|
|
19
47
|
[npm-image]: https://img.shields.io/npm/v/@opra/core
|
|
@@ -22,5 +50,5 @@ Available under [MIT](LICENSE) license.
|
|
|
22
50
|
[downloads-url]: https://npmjs.org/package/@opra/core
|
|
23
51
|
[ci-test-image]: https://github.com/panates/opra/actions/workflows/test.yml/badge.svg
|
|
24
52
|
[ci-test-url]: https://github.com/panates/opra/actions/workflows/test.yml
|
|
25
|
-
[coveralls-image]: https://coveralls.io/repos/github/panates/opra/badge.svg?branch=
|
|
53
|
+
[coveralls-image]: https://coveralls.io/repos/github/panates/opra/badge.svg?branch=dev
|
|
26
54
|
[coveralls-url]: https://coveralls.io/github/panates/opra?branch=main
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { OpraException, OpraSchema } from '@opra/common';
|
|
2
|
+
import { AsyncEventEmitter } from 'node-events-async';
|
|
3
|
+
import type { ExecutionContext } from './execution-context.js';
|
|
4
|
+
import type { PlatformAdapter } from './platform-adapter.js';
|
|
5
|
+
/**
|
|
6
|
+
* ExecutionBundle provides a context for executing multiple operations.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ExecutionBundle extends AsyncEventEmitter {
|
|
9
|
+
/** The platform adapter that created this context */
|
|
10
|
+
readonly __adapter: PlatformAdapter;
|
|
11
|
+
/** The transport protocol being used (e.g., 'http', 'socketio') */
|
|
12
|
+
readonly transport?: OpraSchema.Transport;
|
|
13
|
+
/** The platform name (e.g., 'express', 'koa') */
|
|
14
|
+
readonly platform: string;
|
|
15
|
+
/** A collection of ExecutionContext created during execution */
|
|
16
|
+
contexts: ExecutionContext[];
|
|
17
|
+
/** Whether a transaction will be used in this bundle context */
|
|
18
|
+
readonly transaction?: boolean;
|
|
19
|
+
success?: boolean;
|
|
20
|
+
finished?: boolean;
|
|
21
|
+
error?: OpraException;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new ExecutionContext instance.
|
|
24
|
+
*
|
|
25
|
+
* @param init - The initialization parameters for the context.
|
|
26
|
+
*/
|
|
27
|
+
constructor(init: ExecutionBundle.Initiator);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Namespace for {@link ExecutionBundle} related types and interfaces.
|
|
31
|
+
*/
|
|
32
|
+
export declare namespace ExecutionBundle {
|
|
33
|
+
/**
|
|
34
|
+
* Initialization parameters for creating an {@link ExecutionBundle}.
|
|
35
|
+
*/
|
|
36
|
+
interface Initiator {
|
|
37
|
+
/** The platform adapter */
|
|
38
|
+
__adapter: PlatformAdapter;
|
|
39
|
+
/** The transport protocol */
|
|
40
|
+
transport?: OpraSchema.Transport;
|
|
41
|
+
/** The platform name */
|
|
42
|
+
platform?: string;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { OpraException, OpraSchema } from '@opra/common';
|
|
2
|
+
import { AsyncEventEmitter } from 'node-events-async';
|
|
3
|
+
/**
|
|
4
|
+
* ExecutionBundle provides a context for executing multiple operations.
|
|
5
|
+
*/
|
|
6
|
+
export class ExecutionBundle extends AsyncEventEmitter {
|
|
7
|
+
/** The platform adapter that created this context */
|
|
8
|
+
__adapter;
|
|
9
|
+
/** The transport protocol being used (e.g., 'http', 'socketio') */
|
|
10
|
+
transport;
|
|
11
|
+
/** The platform name (e.g., 'express', 'koa') */
|
|
12
|
+
platform = '';
|
|
13
|
+
/** A collection of ExecutionContext created during execution */
|
|
14
|
+
contexts = [];
|
|
15
|
+
/** Whether a transaction will be used in this bundle context */
|
|
16
|
+
transaction;
|
|
17
|
+
success;
|
|
18
|
+
finished;
|
|
19
|
+
error;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new ExecutionContext instance.
|
|
22
|
+
*
|
|
23
|
+
* @param init - The initialization parameters for the context.
|
|
24
|
+
*/
|
|
25
|
+
constructor(init) {
|
|
26
|
+
super();
|
|
27
|
+
this.__adapter = init.__adapter;
|
|
28
|
+
this.transport = init.transport;
|
|
29
|
+
this.platform = init.platform || '';
|
|
30
|
+
}
|
|
31
|
+
}
|
package/execution-context.d.ts
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
import { DocumentNode, OpraSchema } from '@opra/common';
|
|
2
|
-
import { AsyncEventEmitter } from 'node-events-async';
|
|
2
|
+
import { AsyncEventEmitter, type EventMap } from 'node-events-async';
|
|
3
|
+
import type { ExecutionBundle } from './execution-bundle.js';
|
|
3
4
|
import type { PlatformAdapter } from './platform-adapter.js';
|
|
4
5
|
/**
|
|
5
6
|
* ExecutionContext provides a context for executing operations within an adapter.
|
|
6
7
|
* It carries information about the document node, adapter, transport, and platform.
|
|
7
8
|
*/
|
|
8
|
-
export declare class ExecutionContext extends AsyncEventEmitter {
|
|
9
|
-
/** The document node associated with this context */
|
|
10
|
-
readonly __docNode: DocumentNode;
|
|
9
|
+
export declare class ExecutionContext<T extends EventMap<T> = never> extends AsyncEventEmitter<T> {
|
|
11
10
|
/** The platform adapter that created this context */
|
|
12
11
|
readonly __adapter: PlatformAdapter;
|
|
12
|
+
/** The document node associated with this context */
|
|
13
|
+
readonly __docNode: DocumentNode;
|
|
14
|
+
/** The execution bundle associated with this context */
|
|
15
|
+
readonly bundle?: ExecutionBundle;
|
|
13
16
|
/** The transport protocol being used (e.g., 'http', 'socketio') */
|
|
14
17
|
readonly transport?: OpraSchema.Transport;
|
|
15
18
|
/** The platform name (e.g., 'express', 'koa') */
|
|
16
19
|
readonly platform: string;
|
|
17
20
|
/** A collection of errors encountered during execution */
|
|
18
21
|
errors: Error[];
|
|
22
|
+
success?: boolean;
|
|
23
|
+
finished?: boolean;
|
|
19
24
|
/**
|
|
20
25
|
* Creates a new ExecutionContext instance.
|
|
21
26
|
*
|
|
@@ -35,6 +40,8 @@ export declare namespace ExecutionContext {
|
|
|
35
40
|
__adapter: PlatformAdapter;
|
|
36
41
|
/** The document node */
|
|
37
42
|
__docNode: DocumentNode;
|
|
43
|
+
/** The execution bundle */
|
|
44
|
+
bundle?: ExecutionBundle;
|
|
38
45
|
/** The transport protocol */
|
|
39
46
|
transport?: OpraSchema.Transport;
|
|
40
47
|
/** The platform name */
|
package/execution-context.js
CHANGED
|
@@ -5,16 +5,20 @@ import { AsyncEventEmitter } from 'node-events-async';
|
|
|
5
5
|
* It carries information about the document node, adapter, transport, and platform.
|
|
6
6
|
*/
|
|
7
7
|
export class ExecutionContext extends AsyncEventEmitter {
|
|
8
|
-
/** The document node associated with this context */
|
|
9
|
-
__docNode;
|
|
10
8
|
/** The platform adapter that created this context */
|
|
11
9
|
__adapter;
|
|
10
|
+
/** The document node associated with this context */
|
|
11
|
+
__docNode;
|
|
12
|
+
/** The execution bundle associated with this context */
|
|
13
|
+
bundle;
|
|
12
14
|
/** The transport protocol being used (e.g., 'http', 'socketio') */
|
|
13
15
|
transport;
|
|
14
16
|
/** The platform name (e.g., 'express', 'koa') */
|
|
15
17
|
platform = '';
|
|
16
18
|
/** A collection of errors encountered during execution */
|
|
17
19
|
errors = [];
|
|
20
|
+
success;
|
|
21
|
+
finished;
|
|
18
22
|
/**
|
|
19
23
|
* Creates a new ExecutionContext instance.
|
|
20
24
|
*
|
|
@@ -24,6 +28,7 @@ export class ExecutionContext extends AsyncEventEmitter {
|
|
|
24
28
|
super();
|
|
25
29
|
this.__adapter = init.__adapter;
|
|
26
30
|
this.__docNode = init.__docNode;
|
|
31
|
+
this.bundle = init.bundle;
|
|
27
32
|
this.transport = init.transport;
|
|
28
33
|
this.platform = init.platform || '';
|
|
29
34
|
}
|
package/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import 'reflect-metadata';
|
|
|
2
2
|
import './augmentation/18n.augmentation.js';
|
|
3
3
|
export * from './asset-cache.js';
|
|
4
4
|
export * from './constants.js';
|
|
5
|
+
export * from './execution-bundle.js';
|
|
5
6
|
export * from './execution-context.js';
|
|
6
7
|
export * from './interfaces/logger.interface.js';
|
|
7
8
|
export * from './platform-adapter.js';
|
package/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import 'reflect-metadata';
|
|
|
2
2
|
import './augmentation/18n.augmentation.js';
|
|
3
3
|
export * from './asset-cache.js';
|
|
4
4
|
export * from './constants.js';
|
|
5
|
+
export * from './execution-bundle.js';
|
|
5
6
|
export * from './execution-context.js';
|
|
6
7
|
export * from './interfaces/logger.interface.js';
|
|
7
8
|
export * from './platform-adapter.js';
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opra/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.29.0",
|
|
4
4
|
"description": "Opra schema package",
|
|
5
5
|
"author": "Panates",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"homepage": "https://www.oprajs.com",
|
|
7
8
|
"dependencies": {
|
|
8
9
|
"node-events-async": "^1.5.2",
|
|
9
10
|
"reflect-metadata": "^0.2.2",
|
|
10
11
|
"tslib": "^2.8.1"
|
|
11
12
|
},
|
|
12
13
|
"peerDependencies": {
|
|
13
|
-
"@opra/common": "^1.
|
|
14
|
+
"@opra/common": "^1.29.0"
|
|
14
15
|
},
|
|
15
16
|
"type": "module",
|
|
16
17
|
"module": "./index.js",
|