@theelena/shared 1.0.2 → 1.0.4
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/dist/chunk-DAZIRU7I.js +112 -0
- package/dist/events/index.d.ts +172 -0
- package/dist/events/index.js +20 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +20 -0
- package/package.json +13 -10
- package/src/events/base.ts +0 -153
- package/src/events/index.ts +0 -3
- package/src/events/notification.events.ts +0 -23
- package/src/events/order.events.ts +0 -25
- package/src/index.ts +0 -1
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// src/events/base.ts
|
|
2
|
+
var EventChannels = {
|
|
3
|
+
restaurant: (restaurantId) => `restaurant:${restaurantId}`,
|
|
4
|
+
user: (userId) => `user:${userId}`,
|
|
5
|
+
global: () => "global"
|
|
6
|
+
};
|
|
7
|
+
var BaseEvent = class {
|
|
8
|
+
/**
|
|
9
|
+
* Event payload data
|
|
10
|
+
*/
|
|
11
|
+
data;
|
|
12
|
+
/**
|
|
13
|
+
* Event creation timestamp (milliseconds since epoch)
|
|
14
|
+
*/
|
|
15
|
+
timestamp;
|
|
16
|
+
constructor(data) {
|
|
17
|
+
this.data = data;
|
|
18
|
+
this.timestamp = Date.now();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Deduce scope from event type prefix
|
|
22
|
+
* Override in subclass if custom scope logic is needed
|
|
23
|
+
*/
|
|
24
|
+
getScope() {
|
|
25
|
+
const domain = this.type.split(".")[0] ?? "";
|
|
26
|
+
const restaurantDomains = ["order", "product", "sale", "customer", "table", "category"];
|
|
27
|
+
if (restaurantDomains.includes(domain)) {
|
|
28
|
+
return "restaurant";
|
|
29
|
+
}
|
|
30
|
+
const userDomains = ["notification", "system", "alert"];
|
|
31
|
+
if (userDomains.includes(domain)) {
|
|
32
|
+
return "user";
|
|
33
|
+
}
|
|
34
|
+
return "global";
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get the Redis channel for this event based on context
|
|
38
|
+
*/
|
|
39
|
+
getChannel(context) {
|
|
40
|
+
const scope = this.getScope();
|
|
41
|
+
switch (scope) {
|
|
42
|
+
case "restaurant":
|
|
43
|
+
return EventChannels.restaurant(context.restaurantId);
|
|
44
|
+
case "user":
|
|
45
|
+
return EventChannels.user(context.userId);
|
|
46
|
+
case "global":
|
|
47
|
+
return EventChannels.global();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Get all channels this event should be published to
|
|
52
|
+
* By default, only returns the primary channel
|
|
53
|
+
* Override for multi-channel publishing
|
|
54
|
+
*/
|
|
55
|
+
getChannels(context) {
|
|
56
|
+
return [this.getChannel(context)];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Serialize event for transmission
|
|
60
|
+
*/
|
|
61
|
+
toJSON() {
|
|
62
|
+
return {
|
|
63
|
+
type: this.type,
|
|
64
|
+
data: this.data,
|
|
65
|
+
timestamp: this.timestamp
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Create event instance from serialized data
|
|
70
|
+
* Must be implemented by concrete event classes for deserialization
|
|
71
|
+
*/
|
|
72
|
+
static fromJSON(json) {
|
|
73
|
+
return new this(json.data);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// src/events/order.events.ts
|
|
78
|
+
var OrderCreatedEvent = class extends BaseEvent {
|
|
79
|
+
type = "order.created";
|
|
80
|
+
};
|
|
81
|
+
var OrderStatusChangedEvent = class extends BaseEvent {
|
|
82
|
+
type = "order.status_changed";
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// src/events/table.events.ts
|
|
86
|
+
var TableStatusChangedEvent = class extends BaseEvent {
|
|
87
|
+
type = "table.status_changed";
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// src/events/notification.events.ts
|
|
91
|
+
var SystemNotificationEvent = class extends BaseEvent {
|
|
92
|
+
type = "system.notification";
|
|
93
|
+
};
|
|
94
|
+
var AlertEvent = class extends BaseEvent {
|
|
95
|
+
type = "alert.triggered";
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// src/events/staff.events.ts
|
|
99
|
+
var StaffJoinedEvent = class extends BaseEvent {
|
|
100
|
+
type = "staff.joined";
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export {
|
|
104
|
+
EventChannels,
|
|
105
|
+
BaseEvent,
|
|
106
|
+
OrderCreatedEvent,
|
|
107
|
+
OrderStatusChangedEvent,
|
|
108
|
+
TableStatusChangedEvent,
|
|
109
|
+
SystemNotificationEvent,
|
|
110
|
+
AlertEvent,
|
|
111
|
+
StaffJoinedEvent
|
|
112
|
+
};
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event scope types for channel routing
|
|
3
|
+
*/
|
|
4
|
+
type EventScope = "restaurant" | "user" | "global";
|
|
5
|
+
/**
|
|
6
|
+
* Context required for channel resolution
|
|
7
|
+
*/
|
|
8
|
+
interface EventContext {
|
|
9
|
+
restaurantId: string;
|
|
10
|
+
userId: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Serialized event format for SSE transmission
|
|
14
|
+
*/
|
|
15
|
+
interface SerializedEvent<TData = unknown> {
|
|
16
|
+
type: string;
|
|
17
|
+
data: TData;
|
|
18
|
+
timestamp: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Channel name generators for event routing
|
|
22
|
+
*/
|
|
23
|
+
declare const EventChannels: {
|
|
24
|
+
readonly restaurant: (restaurantId: string) => string;
|
|
25
|
+
readonly user: (userId: string) => string;
|
|
26
|
+
readonly global: () => string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Base class for all application events
|
|
30
|
+
*
|
|
31
|
+
* Scope is automatically deduced from event type prefix:
|
|
32
|
+
* - 'order.*', 'product.*', 'sale.*', 'customer.*' → restaurant scope
|
|
33
|
+
* - 'notification.*', 'system.*' → user scope (owner messages)
|
|
34
|
+
* - default → global scope
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```typescript
|
|
38
|
+
* class OrderCreatedEvent extends BaseEvent<OrderCreatedData> {
|
|
39
|
+
* readonly type = 'order.created' as const;
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* const event = new OrderCreatedEvent({ orderId: '123', ... });
|
|
43
|
+
* const channel = event.getChannel({ restaurantId: 'abc', userId: 'xyz' });
|
|
44
|
+
* // Returns: 'restaurant:abc'
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
declare abstract class BaseEvent<TData = unknown> {
|
|
48
|
+
/**
|
|
49
|
+
* Event type identifier - used for routing and filtering
|
|
50
|
+
* Convention: '{domain}.{action}' e.g., 'order.created', 'notification.sent'
|
|
51
|
+
*/
|
|
52
|
+
abstract readonly type: string;
|
|
53
|
+
/**
|
|
54
|
+
* Event payload data
|
|
55
|
+
*/
|
|
56
|
+
readonly data: TData;
|
|
57
|
+
/**
|
|
58
|
+
* Event creation timestamp (milliseconds since epoch)
|
|
59
|
+
*/
|
|
60
|
+
readonly timestamp: number;
|
|
61
|
+
constructor(data: TData);
|
|
62
|
+
/**
|
|
63
|
+
* Deduce scope from event type prefix
|
|
64
|
+
* Override in subclass if custom scope logic is needed
|
|
65
|
+
*/
|
|
66
|
+
protected getScope(): EventScope;
|
|
67
|
+
/**
|
|
68
|
+
* Get the Redis channel for this event based on context
|
|
69
|
+
*/
|
|
70
|
+
getChannel(context: EventContext): string;
|
|
71
|
+
/**
|
|
72
|
+
* Get all channels this event should be published to
|
|
73
|
+
* By default, only returns the primary channel
|
|
74
|
+
* Override for multi-channel publishing
|
|
75
|
+
*/
|
|
76
|
+
getChannels(context: EventContext): string[];
|
|
77
|
+
/**
|
|
78
|
+
* Serialize event for transmission
|
|
79
|
+
*/
|
|
80
|
+
toJSON(): SerializedEvent<TData>;
|
|
81
|
+
/**
|
|
82
|
+
* Create event instance from serialized data
|
|
83
|
+
* Must be implemented by concrete event classes for deserialization
|
|
84
|
+
*/
|
|
85
|
+
static fromJSON<T extends BaseEvent>(this: new (data: any) => T, json: SerializedEvent): T;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Type helper to extract data type from event class
|
|
89
|
+
*/
|
|
90
|
+
type EventData<E extends BaseEvent> = E extends BaseEvent<infer D> ? D : never;
|
|
91
|
+
/**
|
|
92
|
+
* Type helper for event class constructor
|
|
93
|
+
*/
|
|
94
|
+
type EventClass<E extends BaseEvent = BaseEvent> = new (data: EventData<E>) => E;
|
|
95
|
+
|
|
96
|
+
interface OrderCreatedData {
|
|
97
|
+
orderId: string;
|
|
98
|
+
orderNumber: string;
|
|
99
|
+
orderType: "takeout" | "dine_in" | "reservation";
|
|
100
|
+
customerName?: string;
|
|
101
|
+
tableName?: string;
|
|
102
|
+
}
|
|
103
|
+
interface OrderStatusChangedData {
|
|
104
|
+
orderId: string;
|
|
105
|
+
orderNumber: string;
|
|
106
|
+
oldStatus: string;
|
|
107
|
+
newStatus: string;
|
|
108
|
+
updatedBy: string;
|
|
109
|
+
}
|
|
110
|
+
declare class OrderCreatedEvent extends BaseEvent<OrderCreatedData> {
|
|
111
|
+
readonly type: "order.created";
|
|
112
|
+
}
|
|
113
|
+
declare class OrderStatusChangedEvent extends BaseEvent<OrderStatusChangedData> {
|
|
114
|
+
readonly type: "order.status_changed";
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
interface TableStatusChangedData {
|
|
118
|
+
tableId: string;
|
|
119
|
+
tableNumber: string;
|
|
120
|
+
oldStatus: "disponible" | "ocupada" | "reservada";
|
|
121
|
+
newStatus: "disponible" | "ocupada" | "reservada";
|
|
122
|
+
reason?: string;
|
|
123
|
+
}
|
|
124
|
+
declare class TableStatusChangedEvent extends BaseEvent<TableStatusChangedData> {
|
|
125
|
+
readonly type: "table.status_changed";
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
interface SystemNotificationData {
|
|
129
|
+
title: string;
|
|
130
|
+
message: string;
|
|
131
|
+
severity: "info" | "warning" | "error" | "success";
|
|
132
|
+
actionUrl?: string;
|
|
133
|
+
}
|
|
134
|
+
interface AlertData {
|
|
135
|
+
alertId: string;
|
|
136
|
+
alertType: string;
|
|
137
|
+
message: string;
|
|
138
|
+
metadata?: Record<string, unknown>;
|
|
139
|
+
}
|
|
140
|
+
declare class SystemNotificationEvent extends BaseEvent<SystemNotificationData> {
|
|
141
|
+
readonly type: "system.notification";
|
|
142
|
+
}
|
|
143
|
+
declare class AlertEvent extends BaseEvent<AlertData> {
|
|
144
|
+
readonly type: "alert.triggered";
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Staff Events
|
|
149
|
+
* Module: Staff Management (Module 15)
|
|
150
|
+
*
|
|
151
|
+
* Events related to staff members joining organizations
|
|
152
|
+
*/
|
|
153
|
+
|
|
154
|
+
interface StaffJoinedData {
|
|
155
|
+
memberId: string;
|
|
156
|
+
userName: string;
|
|
157
|
+
userEmail: string;
|
|
158
|
+
role: string;
|
|
159
|
+
restaurantId: string;
|
|
160
|
+
restaurantName: string;
|
|
161
|
+
joinedAt: string;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* StaffJoinedEvent
|
|
165
|
+
* Fired when a new staff member accepts an invitation and joins an organization
|
|
166
|
+
* Scope: restaurant (prefix "staff.*" → routes to restaurant:{restaurantId})
|
|
167
|
+
*/
|
|
168
|
+
declare class StaffJoinedEvent extends BaseEvent<StaffJoinedData> {
|
|
169
|
+
readonly type: "staff.joined";
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export { type AlertData, AlertEvent, BaseEvent, EventChannels, type EventClass, type EventContext, type EventData, type EventScope, type OrderCreatedData, OrderCreatedEvent, type OrderStatusChangedData, OrderStatusChangedEvent, type SerializedEvent, type StaffJoinedData, StaffJoinedEvent, type SystemNotificationData, SystemNotificationEvent, type TableStatusChangedData, TableStatusChangedEvent };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AlertEvent,
|
|
3
|
+
BaseEvent,
|
|
4
|
+
EventChannels,
|
|
5
|
+
OrderCreatedEvent,
|
|
6
|
+
OrderStatusChangedEvent,
|
|
7
|
+
StaffJoinedEvent,
|
|
8
|
+
SystemNotificationEvent,
|
|
9
|
+
TableStatusChangedEvent
|
|
10
|
+
} from "../chunk-DAZIRU7I.js";
|
|
11
|
+
export {
|
|
12
|
+
AlertEvent,
|
|
13
|
+
BaseEvent,
|
|
14
|
+
EventChannels,
|
|
15
|
+
OrderCreatedEvent,
|
|
16
|
+
OrderStatusChangedEvent,
|
|
17
|
+
StaffJoinedEvent,
|
|
18
|
+
SystemNotificationEvent,
|
|
19
|
+
TableStatusChangedEvent
|
|
20
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AlertData, AlertEvent, BaseEvent, EventChannels, EventClass, EventContext, EventData, EventScope, OrderCreatedData, OrderCreatedEvent, OrderStatusChangedData, OrderStatusChangedEvent, SerializedEvent, StaffJoinedData, StaffJoinedEvent, SystemNotificationData, SystemNotificationEvent, TableStatusChangedData, TableStatusChangedEvent } from './events/index.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AlertEvent,
|
|
3
|
+
BaseEvent,
|
|
4
|
+
EventChannels,
|
|
5
|
+
OrderCreatedEvent,
|
|
6
|
+
OrderStatusChangedEvent,
|
|
7
|
+
StaffJoinedEvent,
|
|
8
|
+
SystemNotificationEvent,
|
|
9
|
+
TableStatusChangedEvent
|
|
10
|
+
} from "./chunk-DAZIRU7I.js";
|
|
11
|
+
export {
|
|
12
|
+
AlertEvent,
|
|
13
|
+
BaseEvent,
|
|
14
|
+
EventChannels,
|
|
15
|
+
OrderCreatedEvent,
|
|
16
|
+
OrderStatusChangedEvent,
|
|
17
|
+
StaffJoinedEvent,
|
|
18
|
+
SystemNotificationEvent,
|
|
19
|
+
TableStatusChangedEvent
|
|
20
|
+
};
|
package/package.json
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theelena/shared",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"main": "./
|
|
6
|
-
"types": "./
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
-
"types": "./
|
|
10
|
-
"import": "./
|
|
11
|
-
"default": "./src/index.ts"
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
12
11
|
},
|
|
13
12
|
"./events": {
|
|
14
|
-
"types": "./
|
|
15
|
-
"import": "./
|
|
16
|
-
"default": "./src/events/index.ts"
|
|
13
|
+
"types": "./dist/events/index.d.ts",
|
|
14
|
+
"import": "./dist/events/index.js"
|
|
17
15
|
}
|
|
18
16
|
},
|
|
19
17
|
"files": [
|
|
20
|
-
"
|
|
18
|
+
"dist"
|
|
21
19
|
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsup src/index.ts src/events/index.ts --format esm --dts --out-dir dist",
|
|
22
|
+
"build:watch": "tsup src/index.ts src/events/index.ts --format esm --dts --out-dir dist --watch"
|
|
23
|
+
},
|
|
22
24
|
"devDependencies": {
|
|
25
|
+
"tsup": "^8.0.2",
|
|
23
26
|
"typescript": "^5"
|
|
24
27
|
}
|
|
25
28
|
}
|
package/src/events/base.ts
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Event scope types for channel routing
|
|
3
|
-
*/
|
|
4
|
-
export type EventScope = "restaurant" | "user" | "global";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Context required for channel resolution
|
|
8
|
-
*/
|
|
9
|
-
export interface EventContext {
|
|
10
|
-
restaurantId: string;
|
|
11
|
-
userId: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Serialized event format for SSE transmission
|
|
16
|
-
*/
|
|
17
|
-
export interface SerializedEvent<TData = unknown> {
|
|
18
|
-
type: string;
|
|
19
|
-
data: TData;
|
|
20
|
-
timestamp: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Channel name generators for event routing
|
|
25
|
-
*/
|
|
26
|
-
export const EventChannels = {
|
|
27
|
-
restaurant: (restaurantId: string) => `restaurant:${restaurantId}`,
|
|
28
|
-
user: (userId: string) => `user:${userId}`,
|
|
29
|
-
global: () => "global",
|
|
30
|
-
} as const;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Base class for all application events
|
|
34
|
-
*
|
|
35
|
-
* Scope is automatically deduced from event type prefix:
|
|
36
|
-
* - 'order.*', 'product.*', 'sale.*', 'customer.*' → restaurant scope
|
|
37
|
-
* - 'notification.*', 'system.*' → user scope (owner messages)
|
|
38
|
-
* - default → global scope
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```typescript
|
|
42
|
-
* class OrderCreatedEvent extends BaseEvent<OrderCreatedData> {
|
|
43
|
-
* readonly type = 'order.created' as const;
|
|
44
|
-
* }
|
|
45
|
-
*
|
|
46
|
-
* const event = new OrderCreatedEvent({ orderId: '123', ... });
|
|
47
|
-
* const channel = event.getChannel({ restaurantId: 'abc', userId: 'xyz' });
|
|
48
|
-
* // Returns: 'restaurant:abc'
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
export abstract class BaseEvent<TData = unknown> {
|
|
52
|
-
/**
|
|
53
|
-
* Event type identifier - used for routing and filtering
|
|
54
|
-
* Convention: '{domain}.{action}' e.g., 'order.created', 'notification.sent'
|
|
55
|
-
*/
|
|
56
|
-
abstract readonly type: string;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Event payload data
|
|
60
|
-
*/
|
|
61
|
-
readonly data: TData;
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Event creation timestamp (milliseconds since epoch)
|
|
65
|
-
*/
|
|
66
|
-
readonly timestamp: number;
|
|
67
|
-
|
|
68
|
-
constructor(data: TData) {
|
|
69
|
-
this.data = data;
|
|
70
|
-
this.timestamp = Date.now();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Deduce scope from event type prefix
|
|
75
|
-
* Override in subclass if custom scope logic is needed
|
|
76
|
-
*/
|
|
77
|
-
protected getScope(): EventScope {
|
|
78
|
-
const domain = this.type.split(".")[0] ?? "";
|
|
79
|
-
|
|
80
|
-
const restaurantDomains = ["order", "product", "sale", "customer", "table", "category"];
|
|
81
|
-
if (restaurantDomains.includes(domain)) {
|
|
82
|
-
return "restaurant";
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const userDomains = ["notification", "system", "alert"];
|
|
86
|
-
if (userDomains.includes(domain)) {
|
|
87
|
-
return "user";
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return "global";
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Get the Redis channel for this event based on context
|
|
95
|
-
*/
|
|
96
|
-
getChannel(context: EventContext): string {
|
|
97
|
-
const scope = this.getScope();
|
|
98
|
-
|
|
99
|
-
switch (scope) {
|
|
100
|
-
case "restaurant":
|
|
101
|
-
return EventChannels.restaurant(context.restaurantId);
|
|
102
|
-
case "user":
|
|
103
|
-
return EventChannels.user(context.userId);
|
|
104
|
-
case "global":
|
|
105
|
-
return EventChannels.global();
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Get all channels this event should be published to
|
|
111
|
-
* By default, only returns the primary channel
|
|
112
|
-
* Override for multi-channel publishing
|
|
113
|
-
*/
|
|
114
|
-
getChannels(context: EventContext): string[] {
|
|
115
|
-
return [this.getChannel(context)];
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Serialize event for transmission
|
|
120
|
-
*/
|
|
121
|
-
toJSON(): SerializedEvent<TData> {
|
|
122
|
-
return {
|
|
123
|
-
type: this.type,
|
|
124
|
-
data: this.data,
|
|
125
|
-
timestamp: this.timestamp,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Create event instance from serialized data
|
|
131
|
-
* Must be implemented by concrete event classes for deserialization
|
|
132
|
-
*/
|
|
133
|
-
static fromJSON<T extends BaseEvent>(
|
|
134
|
-
this: new (data: any) => T,
|
|
135
|
-
json: SerializedEvent
|
|
136
|
-
): T {
|
|
137
|
-
return new this(json.data);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Type helper to extract data type from event class
|
|
143
|
-
*/
|
|
144
|
-
export type EventData<E extends BaseEvent> = E extends BaseEvent<infer D>
|
|
145
|
-
? D
|
|
146
|
-
: never;
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Type helper for event class constructor
|
|
150
|
-
*/
|
|
151
|
-
export type EventClass<E extends BaseEvent = BaseEvent> = new (
|
|
152
|
-
data: EventData<E>
|
|
153
|
-
) => E;
|
package/src/events/index.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { BaseEvent } from "./base";
|
|
2
|
-
|
|
3
|
-
export interface SystemNotificationData {
|
|
4
|
-
title: string;
|
|
5
|
-
message: string;
|
|
6
|
-
severity: "info" | "warning" | "error" | "success";
|
|
7
|
-
actionUrl?: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface AlertData {
|
|
11
|
-
alertId: string;
|
|
12
|
-
alertType: string;
|
|
13
|
-
message: string;
|
|
14
|
-
metadata?: Record<string, unknown>;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class SystemNotificationEvent extends BaseEvent<SystemNotificationData> {
|
|
18
|
-
readonly type = "system.notification" as const;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class AlertEvent extends BaseEvent<AlertData> {
|
|
22
|
-
readonly type = "alert.triggered" as const;
|
|
23
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { BaseEvent } from "./base";
|
|
2
|
-
|
|
3
|
-
export interface OrderCreatedData {
|
|
4
|
-
orderId: string;
|
|
5
|
-
orderNumber: string;
|
|
6
|
-
orderType: "takeout" | "dine_in" | "reservation";
|
|
7
|
-
customerName?: string;
|
|
8
|
-
tableName?: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface OrderStatusChangedData {
|
|
12
|
-
orderId: string;
|
|
13
|
-
orderNumber: string;
|
|
14
|
-
oldStatus: string;
|
|
15
|
-
newStatus: string;
|
|
16
|
-
updatedBy: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class OrderCreatedEvent extends BaseEvent<OrderCreatedData> {
|
|
20
|
-
readonly type = "order.created" as const;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export class OrderStatusChangedEvent extends BaseEvent<OrderStatusChangedData> {
|
|
24
|
-
readonly type = "order.status_changed" as const;
|
|
25
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./events";
|