@fjell/core 4.4.48 → 4.4.50
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 +92 -0
- package/dist/Coordinate.d.ts +7 -0
- package/dist/errors/ActionError.d.ts +51 -0
- package/dist/errors/BusinessLogicError.d.ts +4 -0
- package/dist/errors/DuplicateError.d.ts +4 -0
- package/dist/errors/NotFoundError.d.ts +4 -0
- package/dist/errors/PermissionError.d.ts +4 -0
- package/dist/errors/ValidationError.d.ts +4 -0
- package/dist/errors/index.d.ts +6 -0
- package/dist/event/emitter.d.ts +140 -0
- package/dist/event/events.d.ts +81 -0
- package/dist/event/index.d.ts +38 -0
- package/dist/event/matching.d.ts +54 -0
- package/dist/event/subscription.d.ts +74 -0
- package/dist/event/types.d.ts +186 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +1584 -47
- package/dist/item/IUtils.d.ts +6 -3
- package/dist/operations/OperationContext.d.ts +10 -0
- package/dist/operations/Operations.d.ts +259 -0
- package/dist/operations/contained.d.ts +65 -0
- package/dist/operations/errorEnhancer.d.ts +79 -0
- package/dist/operations/index.d.ts +2 -0
- package/dist/operations/methods.d.ts +134 -0
- package/dist/operations/primary.d.ts +57 -0
- package/dist/operations/specialized.d.ts +41 -0
- package/dist/operations/wrappers/createActionWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createAllActionWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createAllFacetWrapper.d.ts +27 -0
- package/dist/operations/wrappers/createAllWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createCreateWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createFacetWrapper.d.ts +27 -0
- package/dist/operations/wrappers/createFindOneWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createFindWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createGetWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createOneWrapper.d.ts +38 -0
- package/dist/operations/wrappers/createRemoveWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createUpdateWrapper.d.ts +28 -0
- package/dist/operations/wrappers/createUpsertWrapper.d.ts +28 -0
- package/dist/operations/wrappers/index.d.ts +34 -0
- package/dist/operations/wrappers/types.d.ts +48 -0
- package/dist/validation/ItemValidator.d.ts +43 -0
- package/dist/validation/KeyValidator.d.ts +56 -0
- package/dist/validation/LocationValidator.d.ts +39 -0
- package/dist/validation/QueryValidator.d.ts +57 -0
- package/dist/validation/index.d.ts +15 -0
- package/dist/validation/index.js +501 -0
- package/dist/validation/types.d.ts +38 -0
- package/package.json +7 -2
- package/src/Coordinate.ts +35 -0
- package/src/errors/ActionError.ts +69 -0
- package/src/errors/BusinessLogicError.ts +24 -0
- package/src/errors/DuplicateError.ts +57 -0
- package/src/errors/NotFoundError.ts +24 -0
- package/src/errors/PermissionError.ts +31 -0
- package/src/errors/ValidationError.ts +27 -0
- package/src/errors/index.ts +7 -0
- package/src/event/emitter.ts +247 -0
- package/src/event/events.ts +178 -0
- package/src/event/index.ts +130 -0
- package/src/event/matching.ts +264 -0
- package/src/event/subscription.ts +181 -0
- package/src/event/types.ts +282 -0
- package/src/index.ts +57 -0
- package/src/item/IUtils.ts +9 -80
- package/src/operations/OperationContext.ts +12 -0
- package/src/operations/Operations.ts +357 -0
- package/src/operations/contained.ts +134 -0
- package/src/operations/errorEnhancer.ts +204 -0
- package/src/operations/index.ts +2 -0
- package/src/operations/methods.ts +363 -0
- package/src/operations/primary.ts +101 -0
- package/src/operations/specialized.ts +71 -0
- package/src/operations/wrappers/createActionWrapper.ts +108 -0
- package/src/operations/wrappers/createAllActionWrapper.ts +109 -0
- package/src/operations/wrappers/createAllFacetWrapper.ts +98 -0
- package/src/operations/wrappers/createAllWrapper.ts +103 -0
- package/src/operations/wrappers/createCreateWrapper.ts +117 -0
- package/src/operations/wrappers/createFacetWrapper.ts +97 -0
- package/src/operations/wrappers/createFindOneWrapper.ts +105 -0
- package/src/operations/wrappers/createFindWrapper.ts +105 -0
- package/src/operations/wrappers/createGetWrapper.ts +96 -0
- package/src/operations/wrappers/createOneWrapper.ts +128 -0
- package/src/operations/wrappers/createRemoveWrapper.ts +91 -0
- package/src/operations/wrappers/createUpdateWrapper.ts +106 -0
- package/src/operations/wrappers/createUpsertWrapper.ts +108 -0
- package/src/operations/wrappers/index.ts +39 -0
- package/src/operations/wrappers/types.ts +63 -0
- package/src/validation/ItemValidator.ts +131 -0
- package/src/validation/KeyValidator.ts +365 -0
- package/src/validation/LocationValidator.ts +136 -0
- package/src/validation/QueryValidator.ts +250 -0
- package/src/validation/index.ts +32 -0
- package/src/validation/types.ts +45 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { BaseEvent } from './events';
|
|
2
|
+
import { Subscription } from './subscription';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Common event types used throughout the event system.
|
|
6
|
+
* Libraries can extend these with custom event types as needed.
|
|
7
|
+
*/
|
|
8
|
+
export const STANDARD_EVENT_TYPES = {
|
|
9
|
+
CREATE: 'create',
|
|
10
|
+
UPDATE: 'update',
|
|
11
|
+
DELETE: 'delete',
|
|
12
|
+
ACTION: 'action',
|
|
13
|
+
} as const;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Type for standard event type values.
|
|
17
|
+
*/
|
|
18
|
+
export type StandardEventType = typeof STANDARD_EVENT_TYPES[keyof typeof STANDARD_EVENT_TYPES];
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Common scope identifiers used by storage libraries.
|
|
22
|
+
* Libraries should use these standard scopes for consistency.
|
|
23
|
+
*/
|
|
24
|
+
export const STANDARD_SCOPES = {
|
|
25
|
+
FIRESTORE: 'firestore',
|
|
26
|
+
SEQUELIZE: 'sequelize',
|
|
27
|
+
POSTGRESQL: 'postgresql',
|
|
28
|
+
MYSQL: 'mysql',
|
|
29
|
+
MONGODB: 'mongodb',
|
|
30
|
+
REDIS: 'redis',
|
|
31
|
+
} as const;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Type for standard scope values.
|
|
35
|
+
*/
|
|
36
|
+
export type StandardScope = typeof STANDARD_SCOPES[keyof typeof STANDARD_SCOPES];
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Status of a subscription.
|
|
40
|
+
* Used to track subscription lifecycle and health.
|
|
41
|
+
*/
|
|
42
|
+
export enum SubscriptionStatus {
|
|
43
|
+
PENDING = 'pending', // Subscription created but not yet active
|
|
44
|
+
ACTIVE = 'active', // Subscription is active and receiving events
|
|
45
|
+
PAUSED = 'paused', // Subscription is paused (not receiving events)
|
|
46
|
+
ERROR = 'error', // Subscription has encountered an error
|
|
47
|
+
CANCELLED = 'cancelled', // Subscription has been cancelled/unsubscribed
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Metadata about a subscription's current state.
|
|
52
|
+
* Used for monitoring and debugging subscription health.
|
|
53
|
+
*/
|
|
54
|
+
export interface SubscriptionMetadata {
|
|
55
|
+
/** Current status of the subscription */
|
|
56
|
+
status: SubscriptionStatus;
|
|
57
|
+
|
|
58
|
+
/** When the subscription was created */
|
|
59
|
+
createdAt: Date;
|
|
60
|
+
|
|
61
|
+
/** When the subscription was last updated */
|
|
62
|
+
updatedAt: Date;
|
|
63
|
+
|
|
64
|
+
/** When the subscription last received an event */
|
|
65
|
+
lastEventAt?: Date;
|
|
66
|
+
|
|
67
|
+
/** Total number of events received by this subscription */
|
|
68
|
+
eventCount: number;
|
|
69
|
+
|
|
70
|
+
/** Any error that occurred with this subscription */
|
|
71
|
+
lastError?: Error;
|
|
72
|
+
|
|
73
|
+
/** Additional metadata specific to the storage implementation */
|
|
74
|
+
implementationMetadata?: Record<string, unknown>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Enhanced subscription interface that includes metadata.
|
|
79
|
+
* Used internally by libraries for subscription management.
|
|
80
|
+
*/
|
|
81
|
+
export type ManagedSubscription<
|
|
82
|
+
S extends string,
|
|
83
|
+
L1 extends string = never,
|
|
84
|
+
L2 extends string = never,
|
|
85
|
+
L3 extends string = never,
|
|
86
|
+
L4 extends string = never,
|
|
87
|
+
L5 extends string = never
|
|
88
|
+
> = Subscription<S, L1, L2, L3, L4, L5> & {
|
|
89
|
+
/** Metadata about this subscription's state */
|
|
90
|
+
metadata: SubscriptionMetadata;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Event handler function type.
|
|
95
|
+
* Used for type-safe event callbacks.
|
|
96
|
+
*/
|
|
97
|
+
export type EventHandler<
|
|
98
|
+
S extends string,
|
|
99
|
+
L1 extends string = never,
|
|
100
|
+
L2 extends string = never,
|
|
101
|
+
L3 extends string = never,
|
|
102
|
+
L4 extends string = never,
|
|
103
|
+
L5 extends string = never
|
|
104
|
+
> = (event: BaseEvent<S, L1, L2, L3, L4, L5>) => void | Promise<void>;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Event handler with error handling.
|
|
108
|
+
* Allows handlers to indicate success/failure for better error tracking.
|
|
109
|
+
*/
|
|
110
|
+
export type SafeEventHandler<
|
|
111
|
+
S extends string,
|
|
112
|
+
L1 extends string = never,
|
|
113
|
+
L2 extends string = never,
|
|
114
|
+
L3 extends string = never,
|
|
115
|
+
L4 extends string = never,
|
|
116
|
+
L5 extends string = never
|
|
117
|
+
> = (event: BaseEvent<S, L1, L2, L3, L4, L5>) => Promise<{ success: boolean; error?: Error }>;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Batch of events for efficient processing.
|
|
121
|
+
* Used when multiple events need to be processed together.
|
|
122
|
+
*/
|
|
123
|
+
export interface EventBatch<
|
|
124
|
+
S extends string,
|
|
125
|
+
L1 extends string = never,
|
|
126
|
+
L2 extends string = never,
|
|
127
|
+
L3 extends string = never,
|
|
128
|
+
L4 extends string = never,
|
|
129
|
+
L5 extends string = never
|
|
130
|
+
> {
|
|
131
|
+
/** Events in this batch */
|
|
132
|
+
events: BaseEvent<S, L1, L2, L3, L4, L5>[];
|
|
133
|
+
|
|
134
|
+
/** When this batch was created */
|
|
135
|
+
createdAt: Date;
|
|
136
|
+
|
|
137
|
+
/** Optional: transaction ID if these events are part of a transaction */
|
|
138
|
+
transactionId?: string;
|
|
139
|
+
|
|
140
|
+
/** Optional: batch metadata */
|
|
141
|
+
metadata?: Record<string, unknown>;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Statistics about event processing.
|
|
146
|
+
* Used for monitoring and performance analysis.
|
|
147
|
+
*/
|
|
148
|
+
export interface EventStats {
|
|
149
|
+
/** Total events processed */
|
|
150
|
+
totalEvents: number;
|
|
151
|
+
|
|
152
|
+
/** Events processed by type */
|
|
153
|
+
eventsByType: Record<string, number>;
|
|
154
|
+
|
|
155
|
+
/** Events processed by scope */
|
|
156
|
+
eventsByScope: Record<string, number>;
|
|
157
|
+
|
|
158
|
+
/** Average event processing time in milliseconds */
|
|
159
|
+
averageProcessingTime: number;
|
|
160
|
+
|
|
161
|
+
/** Number of active subscriptions */
|
|
162
|
+
activeSubscriptions: number;
|
|
163
|
+
|
|
164
|
+
/** Number of failed event deliveries */
|
|
165
|
+
failedDeliveries: number;
|
|
166
|
+
|
|
167
|
+
/** When these stats were last updated */
|
|
168
|
+
lastUpdated: Date;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Configuration for event system behavior.
|
|
173
|
+
* Used by libraries to customize event processing.
|
|
174
|
+
*/
|
|
175
|
+
export interface EventSystemConfig {
|
|
176
|
+
/** Maximum number of events to batch together */
|
|
177
|
+
maxBatchSize?: number;
|
|
178
|
+
|
|
179
|
+
/** Maximum time to wait before processing a batch (milliseconds) */
|
|
180
|
+
maxBatchWaitTime?: number;
|
|
181
|
+
|
|
182
|
+
/** Maximum number of retry attempts for failed event deliveries */
|
|
183
|
+
maxRetryAttempts?: number;
|
|
184
|
+
|
|
185
|
+
/** Delay between retry attempts (milliseconds) */
|
|
186
|
+
retryDelay?: number;
|
|
187
|
+
|
|
188
|
+
/** Whether to enable event statistics collection */
|
|
189
|
+
enableStats?: boolean;
|
|
190
|
+
|
|
191
|
+
/** Maximum number of subscriptions to allow */
|
|
192
|
+
maxSubscriptions?: number;
|
|
193
|
+
|
|
194
|
+
/** Cleanup interval for inactive subscriptions (milliseconds) */
|
|
195
|
+
subscriptionCleanupInterval?: number;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Default configuration values.
|
|
200
|
+
* Libraries can use these as defaults and override as needed.
|
|
201
|
+
*/
|
|
202
|
+
export const DEFAULT_EVENT_CONFIG: Required<EventSystemConfig> = {
|
|
203
|
+
maxBatchSize: 100,
|
|
204
|
+
maxBatchWaitTime: 50, // 50ms
|
|
205
|
+
maxRetryAttempts: 3,
|
|
206
|
+
retryDelay: 1000, // 1 second
|
|
207
|
+
enableStats: true,
|
|
208
|
+
maxSubscriptions: 1000,
|
|
209
|
+
subscriptionCleanupInterval: 300000, // 5 minutes
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Error types specific to the event system.
|
|
214
|
+
* Used for better error handling and debugging.
|
|
215
|
+
*/
|
|
216
|
+
export class EventSystemError extends Error {
|
|
217
|
+
constructor(message: string, public readonly code: string, public readonly details?: Record<string, unknown>) {
|
|
218
|
+
super(message);
|
|
219
|
+
this.name = 'EventSystemError';
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export class SubscriptionError extends EventSystemError {
|
|
224
|
+
constructor(message: string, public readonly subscriptionId: string, details?: Record<string, unknown>) {
|
|
225
|
+
super(message, 'SUBSCRIPTION_ERROR', { subscriptionId, ...details });
|
|
226
|
+
this.name = 'SubscriptionError';
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export class EventEmissionError extends EventSystemError {
|
|
231
|
+
constructor(message: string, public readonly eventType: string, details?: Record<string, unknown>) {
|
|
232
|
+
super(message, 'EVENT_EMISSION_ERROR', { eventType, ...details });
|
|
233
|
+
this.name = 'EventEmissionError';
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export class EventMatchingError extends EventSystemError {
|
|
238
|
+
constructor(message: string, details?: Record<string, unknown>) {
|
|
239
|
+
super(message, 'EVENT_MATCHING_ERROR', details);
|
|
240
|
+
this.name = 'EventMatchingError';
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Utility function to create standardized error messages.
|
|
246
|
+
*/
|
|
247
|
+
export function createEventSystemError(
|
|
248
|
+
type: 'subscription' | 'emission' | 'matching' | 'general',
|
|
249
|
+
message: string,
|
|
250
|
+
details?: Record<string, unknown>
|
|
251
|
+
): EventSystemError {
|
|
252
|
+
switch (type) {
|
|
253
|
+
case 'subscription':
|
|
254
|
+
return new SubscriptionError(message, details?.subscriptionId as string || 'unknown', details);
|
|
255
|
+
case 'emission':
|
|
256
|
+
return new EventEmissionError(message, details?.eventType as string || 'unknown', details);
|
|
257
|
+
case 'matching':
|
|
258
|
+
return new EventMatchingError(message, details);
|
|
259
|
+
case 'general':
|
|
260
|
+
default:
|
|
261
|
+
return new EventSystemError(message, 'GENERAL_ERROR', details);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Utility function to check if an error is an EventSystemError.
|
|
267
|
+
*/
|
|
268
|
+
export function isEventSystemError(error: unknown): error is EventSystemError {
|
|
269
|
+
return error instanceof EventSystemError;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Utility type for extracting the item type from an event.
|
|
274
|
+
*/
|
|
275
|
+
export type ExtractItemType<T> = T extends BaseEvent<infer S, any, any, any, any, any> ? S : never;
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Utility type for extracting all type parameters from an event.
|
|
279
|
+
*/
|
|
280
|
+
export type ExtractEventTypes<T> = T extends BaseEvent<infer S, infer L1, infer L2, infer L3, infer L4, infer L5>
|
|
281
|
+
? { S: S; L1: L1; L2: L2; L3: L3; L4: L4; L5: L5 }
|
|
282
|
+
: never;
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export * from "./dictionary";
|
|
2
2
|
export * from "./keys";
|
|
3
3
|
export * from "./items";
|
|
4
|
+
export * from "./Coordinate";
|
|
5
|
+
export * from "./Coordinate";
|
|
4
6
|
export { IFactory } from "./item/IFactory";
|
|
5
7
|
export { AItemService } from "./AItemService";
|
|
6
8
|
|
|
@@ -11,3 +13,58 @@ export * from './item/IQFactory';
|
|
|
11
13
|
export * from './item/IQUtils';
|
|
12
14
|
export * from './item/IUtils';
|
|
13
15
|
export * from './item/ItemQuery';
|
|
16
|
+
|
|
17
|
+
// Validation module
|
|
18
|
+
export * from './validation';
|
|
19
|
+
|
|
20
|
+
// Error types and handling
|
|
21
|
+
export * from './errors';
|
|
22
|
+
export * from './operations';
|
|
23
|
+
|
|
24
|
+
// Event system
|
|
25
|
+
export * from './event';
|
|
26
|
+
|
|
27
|
+
// Operations interfaces
|
|
28
|
+
export type {
|
|
29
|
+
Operations,
|
|
30
|
+
OperationParams,
|
|
31
|
+
AffectedKeys,
|
|
32
|
+
CreateOptions
|
|
33
|
+
} from './operations/Operations';
|
|
34
|
+
export {
|
|
35
|
+
isPriKey as isOperationPriKey,
|
|
36
|
+
isComKey as isOperationComKey
|
|
37
|
+
} from './operations/Operations';
|
|
38
|
+
export type {
|
|
39
|
+
GetMethod,
|
|
40
|
+
CreateMethod,
|
|
41
|
+
UpdateMethod,
|
|
42
|
+
RemoveMethod,
|
|
43
|
+
UpsertMethod,
|
|
44
|
+
AllMethod,
|
|
45
|
+
OneMethod,
|
|
46
|
+
FindMethod,
|
|
47
|
+
FindOneMethod,
|
|
48
|
+
FinderMethod,
|
|
49
|
+
ActionMethod,
|
|
50
|
+
ActionOperationMethod,
|
|
51
|
+
AllActionMethod,
|
|
52
|
+
AllActionOperationMethod,
|
|
53
|
+
FacetMethod,
|
|
54
|
+
FacetOperationMethod,
|
|
55
|
+
AllFacetMethod,
|
|
56
|
+
AllFacetOperationMethod,
|
|
57
|
+
OperationsExtensions
|
|
58
|
+
} from './operations/methods';
|
|
59
|
+
|
|
60
|
+
// Operation wrappers - automatic validation for all operations
|
|
61
|
+
export * from './operations/wrappers';
|
|
62
|
+
// Core architectural patterns
|
|
63
|
+
export type { PrimaryOperations } from './operations/primary';
|
|
64
|
+
export type { ContainedOperations } from './operations/contained';
|
|
65
|
+
|
|
66
|
+
// UI usage patterns (React providers, etc.)
|
|
67
|
+
export type {
|
|
68
|
+
CollectionOperations,
|
|
69
|
+
InstanceOperations
|
|
70
|
+
} from './operations/specialized';
|
package/src/item/IUtils.ts
CHANGED
|
@@ -1,88 +1,17 @@
|
|
|
1
1
|
/* eslint-disable indent */
|
|
2
2
|
|
|
3
3
|
import { Item } from "../items";
|
|
4
|
-
import { isComKey, isPriKey
|
|
5
|
-
import {
|
|
4
|
+
import { isComKey, isPriKey } from "../key/KUtils";
|
|
5
|
+
import { ComKey, PriKey } from "../keys";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated Use validatePK from @fjell/core/validation instead
|
|
9
|
+
* Re-exported for backward compatibility
|
|
10
|
+
*/
|
|
11
|
+
export { validatePK, validateKeys } from '../validation/ItemValidator';
|
|
8
12
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const validatePKForItem = <
|
|
12
|
-
S extends string,
|
|
13
|
-
L1 extends string = never,
|
|
14
|
-
L2 extends string = never,
|
|
15
|
-
L3 extends string = never,
|
|
16
|
-
L4 extends string = never,
|
|
17
|
-
L5 extends string = never,
|
|
18
|
-
>(item: Item<S, L1, L2, L3, L4, L5>, pkType: S): Item<S, L1, L2, L3, L4, L5> => {
|
|
19
|
-
if (!item) {
|
|
20
|
-
logger.error('Validating PK, Item is undefined', { item });
|
|
21
|
-
throw new Error('Validating PK, Item is undefined');
|
|
22
|
-
}
|
|
23
|
-
if (!item.key) {
|
|
24
|
-
logger.error('Validating PK, Item does not have a key', { item });
|
|
25
|
-
throw new Error('Validating PK, Item does not have a key');
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const keyTypeArray = toKeyTypeArray(item.key as ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>);
|
|
29
|
-
if (keyTypeArray[0] !== pkType) {
|
|
30
|
-
logger.error('Key Type Array Mismatch', { keyTypeArray, pkType });
|
|
31
|
-
throw new Error(`Item does not have the correct primary key type. Expected ${pkType}, got ${keyTypeArray[0]}`);
|
|
32
|
-
}
|
|
33
|
-
return item;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export const validatePK = <
|
|
37
|
-
S extends string,
|
|
38
|
-
L1 extends string = never,
|
|
39
|
-
L2 extends string = never,
|
|
40
|
-
L3 extends string = never,
|
|
41
|
-
L4 extends string = never,
|
|
42
|
-
L5 extends string = never,
|
|
43
|
-
>(
|
|
44
|
-
input: Item<S, L1, L2, L3, L4, L5> | Item<S, L1, L2, L3, L4, L5>[],
|
|
45
|
-
pkType: S,
|
|
46
|
-
): Item<S, L1, L2, L3, L4, L5> | Item<S, L1, L2, L3, L4, L5>[] => {
|
|
47
|
-
logger.trace('Checking Return Type', { input });
|
|
48
|
-
|
|
49
|
-
if (Array.isArray(input)) {
|
|
50
|
-
return input.map((item) => validatePKForItem(item, pkType));
|
|
51
|
-
}
|
|
52
|
-
return validatePKForItem(input, pkType);
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const validateKeys = <
|
|
56
|
-
S extends string,
|
|
57
|
-
L1 extends string = never,
|
|
58
|
-
L2 extends string = never,
|
|
59
|
-
L3 extends string = never,
|
|
60
|
-
L4 extends string = never,
|
|
61
|
-
L5 extends string = never,
|
|
62
|
-
>(
|
|
63
|
-
item: Item<S, L1, L2, L3, L4, L5>,
|
|
64
|
-
keyTypes: AllItemTypeArrays<S, L1, L2, L3, L4, L5>,
|
|
65
|
-
): Item<S, L1, L2, L3, L4, L5> => {
|
|
66
|
-
logger.trace('Checking Return Type', { item });
|
|
67
|
-
if (!item) {
|
|
68
|
-
throw new Error('validating keys, item is undefined');
|
|
69
|
-
}
|
|
70
|
-
if (!item.key) {
|
|
71
|
-
throw new Error('validating keys, item does not have a key: ' + JSON.stringify(item));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const keyTypeArray = toKeyTypeArray(item.key as ComKey<S, L1, L2, L3, L4, L5> | PriKey<S>);
|
|
75
|
-
if (keyTypeArray.length !== keyTypes.length) {
|
|
76
|
-
throw new Error(`Item does not have the correct number of keys. Expected ${keyTypes.length}, but got ${keyTypeArray.length}`);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const match: boolean = JSON.stringify(keyTypeArray) === JSON.stringify(keyTypes);
|
|
80
|
-
if (!match) {
|
|
81
|
-
logger.error('Key Type Array Mismatch', { keyTypeArray, thisKeyTypes: keyTypes });
|
|
82
|
-
throw new Error(`Item does not have the correct key types. Expected [${keyTypes.join(', ')}], but got [${keyTypeArray.join(', ')}]`);
|
|
83
|
-
}
|
|
84
|
-
return item;
|
|
85
|
-
};
|
|
13
|
+
// validatePK and validateKeys have been moved to ../validation/ItemValidator.ts
|
|
14
|
+
// They are re-exported above for backward compatibility
|
|
86
15
|
|
|
87
16
|
export const isPriItem = <
|
|
88
17
|
S extends string,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ComKey, LocKeyArray, PriKey } from '../keys';
|
|
2
|
+
import type { ErrorInfo } from '../errors/ActionError';
|
|
3
|
+
|
|
4
|
+
export interface OperationContext {
|
|
5
|
+
itemType: string;
|
|
6
|
+
operationType: ErrorInfo['operation']['type'];
|
|
7
|
+
operationName: string;
|
|
8
|
+
params: Record<string, any>;
|
|
9
|
+
key?: PriKey<any> | ComKey<any, any, any, any, any, any>;
|
|
10
|
+
locations?: LocKeyArray<any, any, any, any, any>;
|
|
11
|
+
}
|
|
12
|
+
|