arvo-core 2.1.5 → 2.1.7

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/README.md CHANGED
@@ -3,30 +3,19 @@
3
3
 
4
4
 
5
5
  # Arvo
6
+ In the landscape of event-driven systems, Arvo attempts to stand apart through its unique approach to complexity. Rather than prescribing rigid solutions, Arvo provides a thoughtful pattern language and methodology for building distributed systems. It achieves this by striking a careful balance between structure and freedom, offering strong conventions while remaining deliberately unopinionated about implementation details.
6
7
 
7
- ## What is Arvo
8
+ ## Core Philosophy
9
+ Arvo's fundamental principle is that distributed systems thrive on trust and clear contracts, yet must remain flexible in their technical implementation. While the framework ensures reliability and type safety across service boundaries through these contracts, it consciously avoids dictating how you should implement core functionalities like security, event brokerage, event handling, telemetry, or workflow orchestration. This approach enables seamless integration with your existing infrastructure and tools, whether you're using cloud providers like AWS and Azure or your own on-premise solutions.
10
+ Understanding that teams shouldn't need to reinvent common patterns, Arvo provides thoughtfully designed tools to reduce implementation complexity. The Arvo suite includes libraries like arvo-xstate for workflow orchestration using state machines and arvo-event-handler for implementing contract-based event handlers. However, these tools remain entirely optional – they exist to accelerate development when they align with your needs, but Arvo fully supports teams who choose different approaches that better suit their specific requirements.
11
+ This philosophy particularly benefits teams focusing on business logic who want to avoid rebuilding fundamental event-driven patterns. By providing essential building blocks for event creation, contract validation, state management, and telemetry, while maintaining cloud agnosticism and extensibility, Arvo reduces the complexity of distributed system development without constraining technical choices.
8
12
 
9
- Arvo is an opinionated approach to building event-driven systems. It's designed as a pattern and methodology rather than a rigid framework.
13
+ ## Design Goals
14
+ Arvo addresses the inherent complexity of distributed systems by establishing clear patterns for event handling, state management, and service communication. Instead of enforcing a rigid framework, it provides a flexible foundation that helps teams reduce cognitive load while preserving their ability to innovate and adapt. This approach ensures that whether you're building a small microservice or orchestrating a large-scale distributed system, Arvo's lightweight core and extensible architecture can grow alongside your needs, allowing you to progressively adopt more sophisticated patterns as your system evolves.
10
15
 
11
- ## Principal
12
16
 
13
- The core principle of Arvo is to provide a solid foundation with enough flexibility for customization, allowing you to impose your own technical posture, including security measures, event brokerage, and telemetry. While Arvo offers a structured approach, it encourages developers to implement their own solutions if they believe they can improve upon or diverge from Arvo's principles.
14
-
15
- If you're looking to focus on results without getting bogged down in the nitty-gritty of event creation, handling, system state management, and telemetry, while also avoiding vendor lock-in, Arvo provides an excellent starting point. I believe, it strikes a balance between opinionated design and customization, making it an ideal choice for developers who want a head start in building event-driven systems without sacrificing flexibility.
16
-
17
- Key features of Arvo include:
18
-
19
- - Lightweight and unopinionated core
20
- - Extensible architecture
21
- - Cloud-agnostic design
22
- - Built-in primitives for event-driven patterns
23
- - Easy integration with existing systems and tools
24
-
25
- Whether you're building a small microservice or a large-scale distributed system, my hope with Arvo is to offers you some of the tools and patterns to help you succeed in the world of event-driven architecture.
26
-
27
- ## Arvo suite
28
-
29
- Arvo is a collection of libraries which allows you to build the event driven system in the Arvo pattern. However, if you feel you don't have to use them or you can use them as you see fit.
17
+ ## The Arvo Framework: Build at Your Own Pace
18
+ The Arvo framework provides a cohesive set of libraries for building event-driven systems. While designed to work together seamlessly, each component remains independent - adopt what serves your needs and integrate at your own pace.
30
19
 
31
20
  | Scope | NPM | Github | Documentation |
32
21
  | ------------ | ------------------------------------------------------------- | ------------------------------------------------------------- | ------------------------------------------------------------- |
@@ -34,64 +23,169 @@ Arvo is a collection of libraries which allows you to build the event driven sys
34
23
  | Core | https://www.npmjs.com/package/arvo-core?activeTab=readme | https://github.com/SaadAhmad123/arvo-core | https://saadahmad123.github.io/arvo-core/index.html |
35
24
  | Event Handling | https://www.npmjs.com/package/arvo-event-handler?activeTab=readme | https://github.com/SaadAhmad123/arvo-event-handler | https://saadahmad123.github.io/arvo-event-handler/index.html |
36
25
 
26
+
37
27
  # Arvo - Core
38
28
 
39
- This core package defines primitive types and utility functions to help you quickly start building interesting and robust event-driven applications.
29
+ Arvo Core provides the foundational building blocks for creating robust event-driven systems. It implements industry standards while adding enterprise-grade features, enabling developers to build reliable distributed systems without sacrificing flexibility or introducing vendor lock-in.
40
30
 
41
- ## Documentation & Resources
31
+ ## Core Concepts
42
32
 
43
- | Source | Link |
44
- | ------------ | -------------------------------------------------------- |
45
- | Package | https://www.npmjs.com/package/arvo-core?activeTab=readme |
46
- | Github | https://github.com/SaadAhmad123/arvo-core |
47
- | Documenation | https://saadahmad123.github.io/arvo-core/index.html |
33
+ Understanding Arvo Core begins with its three fundamental components that work together to create a robust event-driven architecture:
48
34
 
49
- ## Installation
35
+ ### 1. Events (ArvoEvent)
50
36
 
51
- You can install the core package via `npm` or `yarn`
37
+ ArvoEvent extends the CloudEvents specification to provide a standardized way to describe events in your system. Every event is an immutable, validated instance that includes:
52
38
 
53
- ```bash
54
- npm install arvo-core
39
+ ```typescript
40
+ import { createArvoEvent } from 'arvo-core';
41
+
42
+ const event = createArvoEvent({
43
+ source: 'user-service',
44
+ type: 'user.created',
45
+ subject: 'user/123',
46
+ data: {
47
+ userId: 'usr_123',
48
+ email: 'user@example.com'
49
+ }
50
+ });
55
51
  ```
56
52
 
57
- ```bash
58
- yarn add arvo-core
53
+ ### 2. Contracts (ArvoContract)
54
+
55
+ ArvoContract defines and enforces agreements between services, ensuring type safety and validation across your distributed system:
56
+
57
+ ```typescript
58
+ import { createArvoContract, z } from 'arvo-core';
59
+
60
+ const userContract = createArvoContract({
61
+ uri: '#/contracts/user',
62
+ type: 'user.created',
63
+ versions: {
64
+ '1.0.0': {
65
+ accepts: z.object({
66
+ userId: z.string(),
67
+ email: z.string().email()
68
+ }),
69
+ emits: {
70
+ 'user.notification.sent': z.object({
71
+ userId: z.string(),
72
+ timestamp: z.date()
73
+ })
74
+ }
75
+ }
76
+ }
77
+ });
59
78
  ```
60
79
 
61
- ## Components
80
+ ### 3. Event Factory (ArvoEventFactory)
81
+
82
+ ArvoEventFactory provides a type-safe way to create events that conform to your contracts. It handles validation, OpenTelemetry integration, and ensures events meet their contract specifications:
83
+
84
+ ```typescript
85
+ import { createArvoEventFactory } from 'arvo-core';
86
+
87
+ // Create a factory for a specific contract version
88
+ const factory = createArvoEventFactory(userContract.version('1.0.0'));
89
+
90
+ // Create an event that accepts input
91
+ const inputEvent = factory.accepts({
92
+ source: 'api/users',
93
+ subject: 'user/creation',
94
+ data: {
95
+ userId: 'usr_123',
96
+ email: 'user@example.com'
97
+ }
98
+ });
99
+
100
+ // Create an event that emits output
101
+ const outputEvent = factory.emits({
102
+ type: 'user.notification.sent',
103
+ source: 'notification-service',
104
+ subject: 'notification/sent',
105
+ data: {
106
+ userId: 'usr_123',
107
+ timestamp: new Date()
108
+ }
109
+ });
110
+
111
+ // Create a system error event
112
+ const errorEvent = factory.systemError({
113
+ error: new Error('Validation failed'),
114
+ source: 'validation-service',
115
+ subject: 'validation/error'
116
+ });
117
+ ```
62
118
 
63
- At its core, Arvo has only three main data structures:
119
+ ## Installation
64
120
 
65
- - [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.
66
- - [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.
67
- - `ArvoErrorSchema` is the recommeded zod schema for all the errors in the ArvoEvents
121
+ ```bash
122
+ # Using npm
123
+ npm install arvo-core
68
124
 
69
- ## Utilities
125
+ # Using yarn
126
+ yarn add arvo-core
127
+ ```
70
128
 
71
- The package also includes utility functions for:
129
+ ## Advanced Usage
130
+
131
+ ### Working with Contract Versions
132
+
133
+ The versioning system in ArvoContract allows you to evolve your APIs while maintaining compatibility:
134
+
135
+ ```typescript
136
+ const versionedContract = createArvoContract({
137
+ uri: '#/contracts/order',
138
+ type: 'order.process',
139
+ versions: {
140
+ '1.0.0': {
141
+ accepts: z.object({ orderId: z.string() }),
142
+ emits: {
143
+ 'order.processed': z.object({ status: z.string() })
144
+ }
145
+ },
146
+ '2.0.0': {
147
+ accepts: z.object({
148
+ orderId: z.string(),
149
+ metadata: z.record(z.string())
150
+ }),
151
+ emits: {
152
+ 'order.processed': z.object({
153
+ status: z.string(),
154
+ metrics: z.object({ duration: z.number() })
155
+ })
156
+ }
157
+ }
158
+ }
159
+ });
160
+
161
+ // Create version-specific factories
162
+ const v1Factory = createArvoEventFactory(versionedContract.version('1.0.0'));
163
+ const v2Factory = createArvoEventFactory(versionedContract.version('2.0.0'));
164
+ ```
72
165
 
73
- - Creating ArvoEvents, ArvoContracts, and contract libraries
74
- - Integrating with OpenTelemetry
75
- - TypeScript types for core components
166
+ ## Integration with Other Arvo Components
76
167
 
77
- ## Getting Started
168
+ Arvo Core works seamlessly with:
169
+ - arvo-event-handler: For processing events
170
+ - arvo-xstate: For orchestration and workflow management
78
171
 
79
- To start using Arvo in your project:
172
+ Each component builds upon these core primitives while maintaining the same principles of flexibility and reliability.
80
173
 
81
- - Install the package as shown in the Installation section.
82
- - Import the necessary components:
174
+ ## Best Practices
83
175
 
84
- ```javascript
85
- import {
86
- createArvoEvent,
87
- createArvoContract,
88
- createArvoEventFactory,
89
- createSimpleArvoContract,
90
- createArvoOrchestratorContract,
91
- } from 'arvo-core';
92
- ```
176
+ 1. Use factories for event creation to ensure contract compliance
177
+ 2. Implement proper error handling using the standard error schema
178
+ 3. Enable distributed tracing in production systems
179
+ 4. Share contracts as separate packages or monorepo internals
180
+ 5. Utilize version-specific factories for different API versions
181
+
182
+ ## Resources
93
183
 
94
- - Begin defining your events and contracts using the provided classes.
184
+ | Resource | Link |
185
+ |--------------|-------------------------------------------------------------|
186
+ | Documentation | https://saadahmad123.github.io/arvo-core/index.html |
187
+ | GitHub | https://github.com/SaadAhmad123/arvo-core |
188
+ | NPM Package | https://www.npmjs.com/package/arvo-core |
95
189
 
96
190
  ## License
97
191
 
@@ -154,6 +154,7 @@ var ArvoContract = /** @class */ (function () {
154
154
  }
155
155
  else if (option === 'oldest') {
156
156
  resolvedVersion = this.getSortedVersionNumbers('ASC')[0];
157
+ // @ts-ignore
157
158
  }
158
159
  else if (!this._versions[option]) {
159
160
  throw new Error("The contract (uri=".concat(this._uri, ") does not have version=").concat(option));
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { VersionedArvoContract } from './ArvoContract/VersionedArvoContract';
2
+ import { WildCardArvoSemanticVersion } from './ArvoContract/WildCardArvoSemanticVersion';
2
3
  import ArvoEvent from './ArvoEvent';
3
4
  import { ArvoSemanticVersion } from './types';
4
5
  /**
@@ -88,13 +89,13 @@ export declare class EventDataschemaUtil {
88
89
  * // Returns: "my-contract/1.0.0"
89
90
  * ```
90
91
  */
91
- static create(contract: VersionedArvoContract<any, any>): string;
92
+ static create<T extends VersionedArvoContract<any, any>>(contract: T): `${T['uri']}/${T['version']}`;
92
93
  /**
93
94
  * Creates dataschema string with wildcard version.
94
95
  * @param contract Versioned contract
95
96
  * @returns `{contract.uri}/{WildCardArvoSemanticVersion}`
96
97
  */
97
- static createWithWildCardVersion(contract: VersionedArvoContract<any, any>): string;
98
+ static createWithWildCardVersion<T extends VersionedArvoContract<any, any>>(contract: T): `${T['uri']}/${typeof WildCardArvoSemanticVersion}`;
98
99
  /**
99
100
  * Extracts URI and version from dataschema string.
100
101
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arvo-core",
3
- "version": "2.1.5",
3
+ "version": "2.1.7",
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": {