arvo-core 1.0.1 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -3,7 +3,12 @@
3
3
  ## [1.0.0] - 2024-08-31
4
4
 
5
5
  - Finalised the first release version of the core. This contains core class such as ArvoEvent, ArvoContract, and ArvoContractLibrary. Moreover, this release contains utility functions for string manipulation, validation and OpenTelemetry
6
- ## [1.0.1] - 2024-08-31
6
+
7
+ ## [1.0.2] - 2024-08-31
7
8
 
8
9
  - Update ArvoContract description
9
10
 
11
+ ## [1.0.3] - 2024-08-31
12
+
13
+ - Making type in ArvoEvent a generic string for better type control
14
+
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
+
2
+
1
3
  # Arvo
2
4
 
3
5
  ## What is Arvo
@@ -24,10 +26,32 @@ Whether you're building a small microservice or a large-scale distributed system
24
26
 
25
27
  This core package defines primitive types and utility functions to help you quickly start building interesting and robust event-driven applications.
26
28
 
27
- At its core, Arvo has only two main data structures:
29
+ ## Documentation & Resources
30
+
31
+
32
+ | Source | Link |
33
+ | --------------- | ------------------------
34
+ | Package | https://www.npmjs.com/package/arvo-core?activeTab=readme |
35
+ | Github | https://github.com/SaadAhmad123/arvo-core |
36
+ | Documenation | https://saadahmad123.github.io/arvo-core/index.html |
37
+
38
+
39
+ ## Installation
40
+
41
+ You can install the core package via `npm` or `yarn`
42
+
43
+ ```bash
44
+ npm install arvo-core
45
+ ```
46
+ ```bash
47
+ yarn add arvo-core
48
+ ```
49
+
28
50
 
29
51
  ## Components
30
52
 
53
+ At its core, Arvo has only three main data structures:
54
+
31
55
  - [ArvoEvent](src/ArvoEvent/README.md) aims to provide a extendible variant of the open-source CloudEvent spec-ed object to define all the event in the system.
32
56
  - [ArvoContract](src/ArvoContract/README.md) is a basic class to define and impose contracts between services, ensuring trust in decoupled systems during build and development.
33
57
  - [ArvoContractLibrary](src/ArvoContractLibrary/README.md) is a utility class designed to manage and access multiple ArvoContract instances efficiently.
@@ -36,13 +60,24 @@ At its core, Arvo has only two main data structures:
36
60
 
37
61
  The package also includes utility functions for:
38
62
 
39
- - Creating ArvoEvents
63
+ - Creating ArvoEvents, ArvoContracts, and contract libraries
40
64
  - Integrating with OpenTelemetry
41
65
  - TypeScript types for core components
42
66
 
67
+ ## Getting Started
68
+
69
+ To start using Arvo in your project:
70
+
71
+ - Install the package as shown in the Installation section.
72
+ - Import the necessary components:
73
+ ```javascript
74
+ import { createArvoEvent, createArvoContract, createArvoContractLibrary } from 'arvo-core';
75
+ ```
76
+ - Begin defining your events and contracts using the provided classes.
77
+
43
78
  ## License
44
79
 
45
80
  This package is available under the MIT License. For more details, refer to the [LICENSE.md](LICENSE.md) file in the project repository.
46
81
 
47
82
  ## Change Logs
48
- See the package change logs [here](CHANGELOG.md).
83
+ For a detailed list of changes and updates, please refer to the [document](CHANGELOG.md) file.
@@ -33,13 +33,13 @@ export default class ArvoContract<T extends string = string, TAccepts extends Ar
33
33
  get uri(): T;
34
34
  /**
35
35
  * Gets the accepted record type and schema.
36
- * @returns {Readonly<TAccepts>} The frozen accepts object.
36
+ * @returns {TAccepts} The frozen accepts object.
37
37
  */
38
38
  get accepts(): TAccepts;
39
39
  /**
40
40
  * Gets all emitted event types and schemas as a readonly record.
41
41
  * Use this when you need to access all emitted events at once.
42
- * @returns {Readonly<Record<ExtractEventType<TEmits>, TEmits>>} A frozen record of all emitted events.
42
+ * @returns {Record<ExtractEventType<TEmits>, TEmits>} A frozen record of all emitted events.
43
43
  */
44
44
  get emits(): Record<ExtractEventType<TEmits>, TEmits>;
45
45
  /**
@@ -47,7 +47,7 @@ export default class ArvoContract<T extends string = string, TAccepts extends Ar
47
47
  * Use this when you need to access a single emitted event by its type.
48
48
  * @template U - The type of the emit record to retrieve.
49
49
  * @param {U} type - The type of the emit record.
50
- * @returns {Readonly<Extract<TEmits, { type: U }>>} The emit record.
50
+ * @returns {Extract<TEmits, { type: U }>} The emit record.
51
51
  * @throws {Error} If the emit type is not found in the contract.
52
52
  */
53
53
  getEmit<U extends ExtractEventType<TEmits>>(type: U): Extract<TEmits, {
@@ -37,7 +37,7 @@ var ArvoContract = /** @class */ (function () {
37
37
  Object.defineProperty(ArvoContract.prototype, "accepts", {
38
38
  /**
39
39
  * Gets the accepted record type and schema.
40
- * @returns {Readonly<TAccepts>} The frozen accepts object.
40
+ * @returns {TAccepts} The frozen accepts object.
41
41
  */
42
42
  get: function () {
43
43
  return Object.freeze(this._accepts);
@@ -49,7 +49,7 @@ var ArvoContract = /** @class */ (function () {
49
49
  /**
50
50
  * Gets all emitted event types and schemas as a readonly record.
51
51
  * Use this when you need to access all emitted events at once.
52
- * @returns {Readonly<Record<ExtractEventType<TEmits>, TEmits>>} A frozen record of all emitted events.
52
+ * @returns {Record<ExtractEventType<TEmits>, TEmits>} A frozen record of all emitted events.
53
53
  */
54
54
  get: function () {
55
55
  return Object.freeze(this._emits.reduce(function (acc, emit) {
@@ -66,7 +66,7 @@ var ArvoContract = /** @class */ (function () {
66
66
  * Use this when you need to access a single emitted event by its type.
67
67
  * @template U - The type of the emit record to retrieve.
68
68
  * @param {U} type - The type of the emit record.
69
- * @returns {Readonly<Extract<TEmits, { type: U }>>} The emit record.
69
+ * @returns {Extract<TEmits, { type: U }>} The emit record.
70
70
  * @throws {Error} If the emit type is not found in the contract.
71
71
  */
72
72
  ArvoContract.prototype.getEmit = function (type) {
@@ -9,6 +9,7 @@ import { ArvoEventData, CloudEventExtension, CreateArvoEvent } from './types';
9
9
  *
10
10
  * @template TData - The type of the event data, extending ArvoEventData.
11
11
  * @template TExtension - The type of the cloud event extension, extending CloudEventExtension.
12
+ * @template TType - The type name of the event
12
13
  *
13
14
  * @param {CreateArvoEvent<TData>} event - The event data and metadata to create the ArvoEvent.
14
15
  * @param {TExtension} [extensions] - Optional cloud event extensions.
@@ -37,4 +38,4 @@ import { ArvoEventData, CloudEventExtension, CreateArvoEvent } from './types';
37
38
  * telemetryContext
38
39
  * );
39
40
  */
40
- export declare const createArvoEvent: <TData extends ArvoEventData, TExtension extends CloudEventExtension>(event: CreateArvoEvent<TData>, extensions?: TExtension, telemetry?: TelemetryContext) => ArvoEvent<TData, TExtension>;
41
+ export declare const createArvoEvent: <TData extends ArvoEventData, TExtension extends CloudEventExtension, TType extends string>(event: CreateArvoEvent<TData, TType>, extensions?: TExtension, telemetry?: TelemetryContext) => ArvoEvent<TData, TExtension>;
@@ -17,6 +17,7 @@ var uuid_1 = require("uuid");
17
17
  *
18
18
  * @template TData - The type of the event data, extending ArvoEventData.
19
19
  * @template TExtension - The type of the cloud event extension, extending CloudEventExtension.
20
+ * @template TType - The type name of the event
20
21
  *
21
22
  * @param {CreateArvoEvent<TData>} event - The event data and metadata to create the ArvoEvent.
22
23
  * @param {TExtension} [extensions] - Optional cloud event extensions.
@@ -3,12 +3,13 @@ import { ArvoEventData, ArvoExtension, CloudEventContext, CloudEventExtension, O
3
3
  * Represents an ArvoEvent, which extends the CloudEvent specification.
4
4
  * @template TData - The type of the event data, extending ArvoEventData.
5
5
  * @template TExtension - The type of additional extensions, extending CloudEventExtension.
6
+ * @template TType - The type name of the event
6
7
  */
7
- export default class ArvoEvent<TData extends ArvoEventData = ArvoEventData, TExtension extends CloudEventExtension = CloudEventExtension> {
8
+ export default class ArvoEvent<TData extends ArvoEventData = ArvoEventData, TExtension extends CloudEventExtension = CloudEventExtension, TType extends string = string> {
8
9
  readonly id: string;
9
10
  readonly source: string;
10
11
  readonly specversion: string;
11
- readonly type: string;
12
+ readonly type: TType;
12
13
  readonly subject: string;
13
14
  readonly datacontenttype: string;
14
15
  readonly dataschema: string | null;
@@ -36,7 +37,7 @@ export default class ArvoEvent<TData extends ArvoEventData = ArvoEventData, TExt
36
37
  id: string;
37
38
  source: string;
38
39
  specversion: string;
39
- type: string;
40
+ type: TType;
40
41
  subject: string;
41
42
  datacontenttype: string;
42
43
  dataschema: string | null;
@@ -77,7 +78,7 @@ export default class ArvoEvent<TData extends ArvoEventData = ArvoEventData, TExt
77
78
  'cloudevents.event_source': string;
78
79
  'cloudevents.event_spec_version': string;
79
80
  'cloudevents.event_subject': string;
80
- 'cloudevents.event_type': string;
81
+ 'cloudevents.event_type': string | TType;
81
82
  'cloudevents.event_time': string;
82
83
  'cloudevents.event_datacontenttype': string;
83
84
  'cloudevents.event_dataschema': string;
@@ -17,6 +17,7 @@ var OpenTelemetry_1 = require("../OpenTelemetry");
17
17
  * Represents an ArvoEvent, which extends the CloudEvent specification.
18
18
  * @template TData - The type of the event data, extending ArvoEventData.
19
19
  * @template TExtension - The type of additional extensions, extending CloudEventExtension.
20
+ * @template TType - The type name of the event
20
21
  */
21
22
  var ArvoEvent = /** @class */ (function () {
22
23
  /**
@@ -23,8 +23,9 @@ export type OpenTelemetryExtension = z.infer<typeof OpenTelemetryExtensionSchema
23
23
  /**
24
24
  * Represents the input parameters for creating an ArvoEvent.
25
25
  * @template TData - The type of the event data, extending ArvoEventData.
26
+ * @template TType - The type name of the event
26
27
  */
27
- export type CreateArvoEvent<TData extends ArvoEventData> = {
28
+ export type CreateArvoEvent<TData extends ArvoEventData, TType extends string> = {
28
29
  /** Unique identifier of the event. Must be a non-empty string. If not provided, a UUID will be generated. */
29
30
  id?: string;
30
31
  /** Timestamp of when the occurrence happened. Must be in ISO 8601 format with timezone offset. */
@@ -34,7 +35,7 @@ export type CreateArvoEvent<TData extends ArvoEventData> = {
34
35
  /** The version of the CloudEvents specification used. Must be '1.0' for this version. */
35
36
  specversion?: '1.0';
36
37
  /** Describes the type of event. Should be prefixed with a reverse-DNS name. */
37
- type: string;
38
+ type: TType;
38
39
  /** Identifies the subject of the event. For Arvo, this must be the Process Id. */
39
40
  subject: string;
40
41
  /** Content type of the data value. Must include 'application/cloudevents+json' or
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arvo-core",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "This core package contains all the core classes and components of the Arvo Event Driven System",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {