@sparkleideas/claims 3.5.2-patch.1

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.
@@ -0,0 +1,214 @@
1
+ /**
2
+ * Claims Domain Layer (ADR-016)
3
+ *
4
+ * Exports all domain types, events, rules, and repository interfaces
5
+ * for the issue claiming system.
6
+ *
7
+ * @module v3/claims/domain
8
+ */
9
+
10
+ // =============================================================================
11
+ // Core Types (from types.ts)
12
+ // =============================================================================
13
+
14
+ export type {
15
+ // Core identifiers
16
+ ClaimId,
17
+ IssueId,
18
+ ClaimantType,
19
+ ClaimStatus,
20
+ IssueLabel,
21
+ IssuePriority,
22
+ IssueComplexity,
23
+
24
+ // Value objects
25
+ Duration,
26
+
27
+ // Entities
28
+ Claimant,
29
+ Issue,
30
+ IssueClaim,
31
+ HandoffRecord,
32
+ IssueWithClaim,
33
+ ClaimResult,
34
+
35
+ // Query types
36
+ IssueFilters,
37
+
38
+ // Error types
39
+ ClaimErrorCode,
40
+ ClaimError,
41
+
42
+ // Work stealing types
43
+ AgentType,
44
+ StealableReason,
45
+ StealableInfo,
46
+ StealErrorCode,
47
+ StealResult,
48
+ ContestInfo,
49
+ ContestResolution,
50
+ WorkStealingConfig,
51
+ IssueClaimWithStealing,
52
+ WorkStealingEventType,
53
+ WorkStealingEvent,
54
+
55
+ // ADR-016 extended types
56
+ ExtendedClaimStatus,
57
+ AgentId,
58
+ UserId,
59
+ BlockedReason,
60
+ BlockedInfo,
61
+ StealReason,
62
+ ExtendedStealableInfo,
63
+ HandoffReason,
64
+ ExtendedHandoffInfo,
65
+ ClaimantWorkload,
66
+ ExtendedClaimant,
67
+ AgentLoadInfo,
68
+ ClaimMove,
69
+ RebalanceError,
70
+ ExtendedRebalanceResult,
71
+ RebalanceStrategy,
72
+ LoadBalancingConfig,
73
+ ExtendedIssueClaim,
74
+ ClaimNote,
75
+ StatusChange,
76
+ ClaimQueryOptions,
77
+ ClaimStatistics,
78
+
79
+ // Repository interfaces
80
+ IIssueClaimRepository,
81
+ IWorkStealingEventBus,
82
+ } from './types.js';
83
+
84
+ export {
85
+ // Utility functions
86
+ durationToMs,
87
+ generateClaimId,
88
+ isActiveClaimStatus,
89
+ getValidStatusTransitions,
90
+
91
+ // Classes
92
+ ClaimOperationError,
93
+
94
+ // Constants
95
+ DEFAULT_WORK_STEALING_CONFIG,
96
+ DEFAULT_LOAD_BALANCING_CONFIG,
97
+ } from './types.js';
98
+
99
+ // =============================================================================
100
+ // Domain Events (from events.ts)
101
+ // =============================================================================
102
+
103
+ export type {
104
+ // Base event types
105
+ ClaimDomainEvent,
106
+ ClaimEventType,
107
+ AllClaimEvents,
108
+
109
+ // Claim lifecycle events
110
+ ClaimCreatedEvent,
111
+ ClaimReleasedEvent,
112
+ ClaimExpiredEvent,
113
+ ClaimStatusChangedEvent,
114
+ ClaimNoteAddedEvent,
115
+
116
+ // Handoff events
117
+ HandoffRequestedEvent,
118
+ HandoffAcceptedEvent,
119
+ HandoffRejectedEvent,
120
+
121
+ // Review events
122
+ ReviewRequestedEvent,
123
+ ReviewCompletedEvent,
124
+
125
+ // ADR-016 extended event types
126
+ ExtendedClaimEventType,
127
+ ExtendedClaimDomainEvent,
128
+ IssueMarkedStealableEvent,
129
+ IssueStolenEvent,
130
+ StealContestStartedEvent,
131
+ StealContestResolvedExtEvent,
132
+ StealWarningEvent,
133
+ SwarmRebalancedExtEvent,
134
+ AgentOverloadedExtEvent,
135
+ AgentUnderloadedExtEvent,
136
+ AgentLoadChangedEvent,
137
+ AllExtendedClaimEvents,
138
+ } from './events.js';
139
+
140
+ export {
141
+ // Event factory functions
142
+ createClaimCreatedEvent,
143
+ createClaimReleasedEvent,
144
+ createClaimExpiredEvent,
145
+ createClaimStatusChangedEvent,
146
+ createClaimNoteAddedEvent,
147
+ createHandoffRequestedEvent,
148
+ createHandoffAcceptedEvent,
149
+ createHandoffRejectedEvent,
150
+ createReviewRequestedEvent,
151
+ createReviewCompletedEvent,
152
+
153
+ // ADR-016 extended event factories
154
+ createIssueMarkedStealableEvent,
155
+ createIssueStolenExtEvent,
156
+ createSwarmRebalancedExtEvent,
157
+ createAgentOverloadedExtEvent,
158
+ createAgentUnderloadedExtEvent,
159
+ } from './events.js';
160
+
161
+ // =============================================================================
162
+ // Repository Interfaces (from repositories.ts)
163
+ // =============================================================================
164
+
165
+ export type {
166
+ IClaimRepository,
167
+ IIssueRepository,
168
+ IClaimantRepository,
169
+ IClaimEventStore,
170
+ } from './repositories.js';
171
+
172
+ // =============================================================================
173
+ // Business Rules (from rules.ts)
174
+ // =============================================================================
175
+
176
+ export type {
177
+ RuleResult,
178
+ } from './rules.js';
179
+
180
+ export {
181
+ // Result helpers
182
+ ruleSuccess,
183
+ ruleFailure,
184
+
185
+ // Claim eligibility rules
186
+ canClaimIssue,
187
+ isIssueClaimed,
188
+ isActiveClaim,
189
+ getOriginalStatusTransitions,
190
+ getExtendedStatusTransitions,
191
+ canTransitionStatus,
192
+
193
+ // Work stealing rules
194
+ canMarkAsStealable,
195
+ canStealClaim,
196
+ requiresStealContest,
197
+
198
+ // Handoff rules
199
+ canInitiateHandoff,
200
+ canAcceptHandoff,
201
+ canRejectHandoff,
202
+
203
+ // Load balancing rules
204
+ isAgentOverloaded,
205
+ isAgentUnderloaded,
206
+ needsRebalancing,
207
+ canMoveClaim,
208
+
209
+ // Validation rules
210
+ isValidPriority,
211
+ isValidStatus,
212
+ isValidExtendedStatus,
213
+ isValidRepository,
214
+ } from './rules.js';
@@ -0,0 +1,239 @@
1
+ /**
2
+ * Claim Repository Interfaces
3
+ *
4
+ * Repository interfaces for the claims domain following DDD patterns.
5
+ *
6
+ * @module v3/claims/domain/repositories
7
+ */
8
+
9
+ import {
10
+ ClaimId,
11
+ IssueId,
12
+ Claimant,
13
+ ClaimStatus,
14
+ Issue,
15
+ IssueClaim,
16
+ IssueFilters,
17
+ HandoffRecord,
18
+ } from './types.js';
19
+
20
+ // =============================================================================
21
+ // Claim Repository Interface
22
+ // =============================================================================
23
+
24
+ /**
25
+ * Repository for managing issue claims
26
+ */
27
+ export interface IClaimRepository {
28
+ // ==========================================================================
29
+ // CRUD Operations
30
+ // ==========================================================================
31
+
32
+ /**
33
+ * Save a new claim or update an existing one
34
+ */
35
+ save(claim: IssueClaim): Promise<void>;
36
+
37
+ /**
38
+ * Find a claim by its ID
39
+ */
40
+ findById(claimId: ClaimId): Promise<IssueClaim | null>;
41
+
42
+ /**
43
+ * Find the active claim for an issue
44
+ */
45
+ findByIssueId(issueId: IssueId): Promise<IssueClaim | null>;
46
+
47
+ /**
48
+ * Find all claims for a specific claimant
49
+ */
50
+ findByClaimant(claimant: Claimant): Promise<IssueClaim[]>;
51
+
52
+ /**
53
+ * Find claims by status
54
+ */
55
+ findByStatus(status: ClaimStatus): Promise<IssueClaim[]>;
56
+
57
+ /**
58
+ * Delete a claim
59
+ */
60
+ delete(claimId: ClaimId): Promise<void>;
61
+
62
+ // ==========================================================================
63
+ // Query Operations
64
+ // ==========================================================================
65
+
66
+ /**
67
+ * Find all active claims
68
+ */
69
+ findActiveClaims(): Promise<IssueClaim[]>;
70
+
71
+ /**
72
+ * Find stale claims (claims with no activity past a threshold)
73
+ */
74
+ findStaleClaims(staleSince: Date): Promise<IssueClaim[]>;
75
+
76
+ /**
77
+ * Find claims with pending handoffs
78
+ */
79
+ findClaimsWithPendingHandoffs(): Promise<IssueClaim[]>;
80
+
81
+ /**
82
+ * Count claims by claimant
83
+ */
84
+ countByClaimant(claimantId: string): Promise<number>;
85
+
86
+ // ==========================================================================
87
+ // Lifecycle
88
+ // ==========================================================================
89
+
90
+ /**
91
+ * Initialize the repository
92
+ */
93
+ initialize(): Promise<void>;
94
+
95
+ /**
96
+ * Shutdown the repository
97
+ */
98
+ shutdown(): Promise<void>;
99
+ }
100
+
101
+ // =============================================================================
102
+ // Issue Repository Interface
103
+ // =============================================================================
104
+
105
+ /**
106
+ * Repository for accessing issues
107
+ */
108
+ export interface IIssueRepository {
109
+ // ==========================================================================
110
+ // CRUD Operations
111
+ // ==========================================================================
112
+
113
+ /**
114
+ * Find an issue by its ID
115
+ */
116
+ findById(issueId: IssueId): Promise<Issue | null>;
117
+
118
+ /**
119
+ * Find issues matching filters
120
+ */
121
+ findByFilters(filters: IssueFilters): Promise<Issue[]>;
122
+
123
+ /**
124
+ * Find all unclaimed issues matching filters
125
+ */
126
+ findAvailable(filters?: IssueFilters): Promise<Issue[]>;
127
+
128
+ /**
129
+ * Check if an issue exists
130
+ */
131
+ exists(issueId: IssueId): Promise<boolean>;
132
+
133
+ // ==========================================================================
134
+ // Lifecycle
135
+ // ==========================================================================
136
+
137
+ /**
138
+ * Initialize the repository
139
+ */
140
+ initialize(): Promise<void>;
141
+
142
+ /**
143
+ * Shutdown the repository
144
+ */
145
+ shutdown(): Promise<void>;
146
+ }
147
+
148
+ // =============================================================================
149
+ // Claimant Repository Interface
150
+ // =============================================================================
151
+
152
+ /**
153
+ * Repository for managing claimants
154
+ */
155
+ export interface IClaimantRepository {
156
+ // ==========================================================================
157
+ // CRUD Operations
158
+ // ==========================================================================
159
+
160
+ /**
161
+ * Find a claimant by ID
162
+ */
163
+ findById(claimantId: string): Promise<Claimant | null>;
164
+
165
+ /**
166
+ * Find claimants by type
167
+ */
168
+ findByType(type: 'human' | 'agent'): Promise<Claimant[]>;
169
+
170
+ /**
171
+ * Find claimants with specific capabilities
172
+ */
173
+ findByCapabilities(capabilities: string[]): Promise<Claimant[]>;
174
+
175
+ /**
176
+ * Get all available claimants (not at max workload)
177
+ */
178
+ findAvailable(): Promise<Claimant[]>;
179
+
180
+ /**
181
+ * Check if a claimant exists
182
+ */
183
+ exists(claimantId: string): Promise<boolean>;
184
+
185
+ // ==========================================================================
186
+ // Lifecycle
187
+ // ==========================================================================
188
+
189
+ /**
190
+ * Initialize the repository
191
+ */
192
+ initialize(): Promise<void>;
193
+
194
+ /**
195
+ * Shutdown the repository
196
+ */
197
+ shutdown(): Promise<void>;
198
+ }
199
+
200
+ // =============================================================================
201
+ // Event Store Interface (for domain events)
202
+ // =============================================================================
203
+
204
+ import { AllClaimEvents, ClaimDomainEvent } from './events.js';
205
+
206
+ /**
207
+ * Event store interface for claim domain events
208
+ */
209
+ export interface IClaimEventStore {
210
+ /**
211
+ * Append a new event to the store
212
+ */
213
+ append(event: ClaimDomainEvent): Promise<void>;
214
+
215
+ /**
216
+ * Get events for a specific claim
217
+ */
218
+ getEvents(claimId: ClaimId, fromVersion?: number): Promise<ClaimDomainEvent[]>;
219
+
220
+ /**
221
+ * Get events by type
222
+ */
223
+ getEventsByType(type: string): Promise<ClaimDomainEvent[]>;
224
+
225
+ /**
226
+ * Get events for an issue across all claims
227
+ */
228
+ getEventsByIssueId(issueId: IssueId): Promise<ClaimDomainEvent[]>;
229
+
230
+ /**
231
+ * Initialize the event store
232
+ */
233
+ initialize(): Promise<void>;
234
+
235
+ /**
236
+ * Shutdown the event store
237
+ */
238
+ shutdown(): Promise<void>;
239
+ }