@sharpee/core 0.9.66-beta → 0.9.69-beta
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/constants/attributes.d.ts +32 -0
- package/constants/attributes.d.ts.map +1 -0
- package/constants/attributes.js +53 -0
- package/constants/attributes.js.map +1 -0
- package/constants/core-events.d.ts +37 -0
- package/constants/core-events.d.ts.map +1 -0
- package/constants/core-events.js +50 -0
- package/constants/core-events.js.map +1 -0
- package/constants/entity-types.d.ts +15 -0
- package/constants/entity-types.d.ts.map +1 -0
- package/constants/entity-types.js +27 -0
- package/constants/entity-types.js.map +1 -0
- package/constants/index.d.ts +22 -0
- package/constants/index.d.ts.map +1 -0
- package/constants/index.js +41 -0
- package/constants/index.js.map +1 -0
- package/constants/relationships.d.ts +25 -0
- package/constants/relationships.d.ts.map +1 -0
- package/constants/relationships.js +55 -0
- package/constants/relationships.js.map +1 -0
- package/debug/index.d.ts +5 -0
- package/debug/index.d.ts.map +1 -0
- package/debug/index.js +21 -0
- package/debug/index.js.map +1 -0
- package/debug/types.d.ts +65 -0
- package/debug/types.d.ts.map +1 -0
- package/debug/types.js +39 -0
- package/debug/types.js.map +1 -0
- package/events/event-factory.d.ts +81 -0
- package/events/event-factory.d.ts.map +1 -0
- package/events/event-factory.js +74 -0
- package/events/event-factory.js.map +1 -0
- package/events/event-helpers.d.ts +118 -0
- package/events/event-helpers.d.ts.map +1 -0
- package/events/event-helpers.js +151 -0
- package/events/event-helpers.js.map +1 -0
- package/events/event-registry.d.ts +154 -0
- package/events/event-registry.d.ts.map +1 -0
- package/events/event-registry.js +24 -0
- package/events/event-registry.js.map +1 -0
- package/events/event-source.d.ts +39 -0
- package/events/event-source.d.ts.map +1 -0
- package/events/event-source.js +57 -0
- package/events/event-source.js.map +1 -0
- package/events/event-system.d.ts +27 -0
- package/events/event-system.d.ts.map +1 -0
- package/events/event-system.js +64 -0
- package/events/event-system.js.map +1 -0
- package/events/game-events.d.ts +246 -0
- package/events/game-events.d.ts.map +1 -0
- package/events/game-events.js +250 -0
- package/events/game-events.js.map +1 -0
- package/events/index.d.ts +19 -0
- package/events/index.d.ts.map +1 -0
- package/events/index.js +51 -0
- package/events/index.js.map +1 -0
- package/events/platform-events.d.ts +161 -0
- package/events/platform-events.d.ts.map +1 -0
- package/events/platform-events.js +135 -0
- package/events/platform-events.js.map +1 -0
- package/events/semantic-event-source.d.ts +85 -0
- package/events/semantic-event-source.d.ts.map +1 -0
- package/events/semantic-event-source.js +147 -0
- package/events/semantic-event-source.js.map +1 -0
- package/events/standard-events.d.ts +26 -0
- package/events/standard-events.d.ts.map +1 -0
- package/events/standard-events.js +27 -0
- package/events/standard-events.js.map +1 -0
- package/events/system-event.d.ts +62 -0
- package/events/system-event.d.ts.map +1 -0
- package/events/system-event.js +55 -0
- package/events/system-event.js.map +1 -0
- package/events/typed-event.d.ts +69 -0
- package/events/typed-event.d.ts.map +1 -0
- package/events/typed-event.js +20 -0
- package/events/typed-event.js.map +1 -0
- package/events/types.d.ts +105 -0
- package/events/types.d.ts.map +1 -0
- package/events/types.js +4 -0
- package/events/types.js.map +1 -0
- package/execution/index.d.ts +2 -0
- package/execution/index.d.ts.map +1 -0
- package/execution/index.js +23 -0
- package/execution/index.js.map +1 -0
- package/execution/types.d.ts +117 -0
- package/execution/types.d.ts.map +1 -0
- package/execution/types.js +4 -0
- package/execution/types.js.map +1 -0
- package/extensions/index.d.ts +3 -0
- package/extensions/index.d.ts.map +1 -0
- package/extensions/index.js +20 -0
- package/extensions/index.js.map +1 -0
- package/extensions/registry.d.ts +61 -0
- package/extensions/registry.d.ts.map +1 -0
- package/extensions/registry.js +153 -0
- package/extensions/registry.js.map +1 -0
- package/extensions/types.d.ts +84 -0
- package/extensions/types.d.ts.map +1 -0
- package/extensions/types.js +15 -0
- package/extensions/types.js.map +1 -0
- package/ifid/ifid.d.ts +30 -0
- package/ifid/ifid.d.ts.map +1 -0
- package/ifid/ifid.js +52 -0
- package/ifid/ifid.js.map +1 -0
- package/ifid/index.d.ts +2 -0
- package/ifid/index.d.ts.map +1 -0
- package/ifid/index.js +9 -0
- package/ifid/index.js.map +1 -0
- package/index.d.ts +11 -0
- package/index.d.ts.map +1 -0
- package/index.js +36 -0
- package/index.js.map +1 -0
- package/metadata/index.d.ts +2 -0
- package/metadata/index.d.ts.map +1 -0
- package/metadata/index.js +3 -0
- package/metadata/index.js.map +1 -0
- package/metadata/story-metadata.d.ts +64 -0
- package/metadata/story-metadata.d.ts.map +1 -0
- package/metadata/story-metadata.js +5 -0
- package/metadata/story-metadata.js.map +1 -0
- package/package.json +1 -16
- package/query/index.d.ts +9 -0
- package/query/index.d.ts.map +1 -0
- package/query/index.js +25 -0
- package/query/index.js.map +1 -0
- package/query/query-manager.d.ts +86 -0
- package/query/query-manager.d.ts.map +1 -0
- package/query/query-manager.js +391 -0
- package/query/query-manager.js.map +1 -0
- package/query/types.d.ts +188 -0
- package/query/types.d.ts.map +1 -0
- package/query/types.js +106 -0
- package/query/types.js.map +1 -0
- package/random/index.d.ts +5 -0
- package/random/index.d.ts.map +1 -0
- package/random/index.js +9 -0
- package/random/index.js.map +1 -0
- package/random/seeded-random.d.ts +32 -0
- package/random/seeded-random.d.ts.map +1 -0
- package/random/seeded-random.js +62 -0
- package/random/seeded-random.js.map +1 -0
- package/rules/compatibility.d.ts +46 -0
- package/rules/compatibility.d.ts.map +1 -0
- package/rules/compatibility.js +62 -0
- package/rules/compatibility.js.map +1 -0
- package/rules/condition-builder.d.ts +23 -0
- package/rules/condition-builder.d.ts.map +1 -0
- package/rules/condition-builder.js +16 -0
- package/rules/condition-builder.js.map +1 -0
- package/rules/helpers.d.ts +51 -0
- package/rules/helpers.d.ts.map +1 -0
- package/rules/helpers.js +111 -0
- package/rules/helpers.js.map +1 -0
- package/rules/index.d.ts +12 -0
- package/rules/index.d.ts.map +1 -0
- package/rules/index.js +34 -0
- package/rules/index.js.map +1 -0
- package/rules/rule-system.d.ts +6 -0
- package/rules/rule-system.d.ts.map +1 -0
- package/rules/rule-system.js +10 -0
- package/rules/rule-system.js.map +1 -0
- package/rules/rule-world-adapter.d.ts +43 -0
- package/rules/rule-world-adapter.d.ts.map +1 -0
- package/rules/rule-world-adapter.js +74 -0
- package/rules/rule-world-adapter.js.map +1 -0
- package/rules/simple-rule-system.d.ts +36 -0
- package/rules/simple-rule-system.d.ts.map +1 -0
- package/rules/simple-rule-system.js +135 -0
- package/rules/simple-rule-system.js.map +1 -0
- package/rules/types.d.ts +64 -0
- package/rules/types.d.ts.map +1 -0
- package/rules/types.js +6 -0
- package/rules/types.js.map +1 -0
- package/types/attribute.d.ts +40 -0
- package/types/attribute.d.ts.map +1 -0
- package/types/attribute.js +4 -0
- package/types/attribute.js.map +1 -0
- package/types/entity.d.ts +47 -0
- package/types/entity.d.ts.map +1 -0
- package/types/entity.js +4 -0
- package/types/entity.js.map +1 -0
- package/types/index.d.ts +10 -0
- package/types/index.d.ts.map +1 -0
- package/types/index.js +27 -0
- package/types/index.js.map +1 -0
- package/types/relationship.d.ts +44 -0
- package/types/relationship.d.ts.map +1 -0
- package/types/relationship.js +4 -0
- package/types/relationship.js.map +1 -0
- package/types/result.d.ts +81 -0
- package/types/result.d.ts.map +1 -0
- package/types/result.js +79 -0
- package/types/result.js.map +1 -0
- package/types/save-data.d.ts +266 -0
- package/types/save-data.d.ts.map +1 -0
- package/types/save-data.js +6 -0
- package/types/save-data.js.map +1 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Event Factory - Type-safe semantic event creation
|
|
4
|
+
*
|
|
5
|
+
* @see ADR-082 for design rationale
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.createTypedEvent = createTypedEvent;
|
|
9
|
+
exports.createMessageEvent = createMessageEvent;
|
|
10
|
+
exports.createEmptyEvent = createEmptyEvent;
|
|
11
|
+
exports.resetEventCounter = resetEventCounter;
|
|
12
|
+
let eventCounter = 0;
|
|
13
|
+
/**
|
|
14
|
+
* Create a type-safe semantic event.
|
|
15
|
+
*
|
|
16
|
+
* The data parameter is strictly typed based on the event type,
|
|
17
|
+
* providing compile-time verification of event data.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* // TypeScript enforces correct data shape
|
|
22
|
+
* const event = createTypedEvent('query.invalid', {
|
|
23
|
+
* message: 'Invalid input',
|
|
24
|
+
* hint: 'Please try again'
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* // This would be a compile error:
|
|
28
|
+
* // createTypedEvent('query.invalid', { wrongField: true });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
function createTypedEvent(type, data, options = {}) {
|
|
32
|
+
return {
|
|
33
|
+
id: options.id ?? `evt-${Date.now()}-${++eventCounter}`,
|
|
34
|
+
type,
|
|
35
|
+
timestamp: Date.now(),
|
|
36
|
+
data,
|
|
37
|
+
entities: options.entities ?? {},
|
|
38
|
+
tags: options.tags,
|
|
39
|
+
priority: options.priority,
|
|
40
|
+
narrate: options.narrate
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Create a message event (convenience helper).
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* const event = createMessageEvent('success', 'item_taken', {
|
|
49
|
+
* item: 'brass lantern'
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
function createMessageEvent(variant, messageId, params, options) {
|
|
54
|
+
const type = `message.${variant}`;
|
|
55
|
+
return createTypedEvent(type, { messageId, params }, options);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Create an empty event (for events with no data).
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* const event = createEmptyEvent('platform.quit_cancelled');
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
function createEmptyEvent(type, options) {
|
|
66
|
+
return createTypedEvent(type, {}, options);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Reset the event counter (useful for testing).
|
|
70
|
+
*/
|
|
71
|
+
function resetEventCounter() {
|
|
72
|
+
eventCounter = 0;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=event-factory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-factory.js","sourceRoot":"","sources":["../../../../../../mnt/c/repotemp/sharpee/packages/core/src/events/event-factory.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAwDH,4CAeC;AAiBD,gDAQC;AAUD,4CAKC;AAKD,8CAEC;AAhHD,IAAI,YAAY,GAAG,CAAC,CAAC;AAgCrB;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,gBAAgB,CAC9B,IAAO,EACP,IAA0B,EAC1B,UAA8B,EAAE;IAEhC,OAAO;QACL,EAAE,EAAE,OAAO,CAAC,EAAE,IAAI,OAAO,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,YAAY,EAAE;QACvD,IAAI;QACJ,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;QACrB,IAAI;QACJ,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,EAAE;QAChC,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC;AACJ,CAAC;AAOD;;;;;;;;;GASG;AACH,SAAgB,kBAAkB,CAChC,OAAuB,EACvB,SAAiB,EACjB,MAAgC,EAChC,OAA4B;IAE5B,MAAM,IAAI,GAAG,WAAW,OAAO,EAAiC,CAAC;IACjE,OAAO,gBAAgB,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,MAAM,EAAiB,EAAE,OAAO,CAAC,CAAC;AAC/E,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,gBAAgB,CAC9B,IAAO,EACP,OAA4B;IAE5B,OAAO,gBAAgB,CAAC,IAAI,EAAE,EAA0B,EAAE,OAAO,CAAC,CAAC;AACrE,CAAC;AAED;;GAEG;AACH,SAAgB,iBAAiB;IAC/B,YAAY,GAAG,CAAC,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event Helpers - Type-safe event consumption utilities
|
|
3
|
+
*
|
|
4
|
+
* These functions help consumers safely extract typed data from events
|
|
5
|
+
* without resorting to `as any` casts.
|
|
6
|
+
*
|
|
7
|
+
* @see ADR-082 for design rationale
|
|
8
|
+
*/
|
|
9
|
+
import { EventDataRegistry, EventType } from './event-registry';
|
|
10
|
+
import { ISemanticEvent } from './types';
|
|
11
|
+
/**
|
|
12
|
+
* Check if an event is of a specific type and narrow its type.
|
|
13
|
+
*
|
|
14
|
+
* This is a type guard that allows TypeScript to narrow the event
|
|
15
|
+
* type in conditional branches.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* function processEvent(event: ISemanticEvent) {
|
|
20
|
+
* if (isEventType(event, 'query.invalid')) {
|
|
21
|
+
* // TypeScript knows event.data is QueryInvalidData
|
|
22
|
+
* console.log(event.data.message);
|
|
23
|
+
* console.log(event.data.hint);
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function isEventType<T extends EventType>(event: ISemanticEvent, type: T): event is ISemanticEvent & {
|
|
29
|
+
type: T;
|
|
30
|
+
data: EventDataRegistry[T];
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Check if an event type starts with a prefix.
|
|
34
|
+
*
|
|
35
|
+
* Useful for handling categories of events (e.g., all message.* events).
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* if (hasEventPrefix(event, 'message.')) {
|
|
40
|
+
* // Handle any message event
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function hasEventPrefix(event: ISemanticEvent, prefix: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Get typed event data if the event matches the expected type.
|
|
47
|
+
*
|
|
48
|
+
* Returns undefined if the event type doesn't match. This is the safe
|
|
49
|
+
* way to extract data when you're not sure of the event type.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* const data = getEventData(event, 'quit.confirmed');
|
|
54
|
+
* if (data) {
|
|
55
|
+
* console.log(`Final score: ${data.finalScore}`);
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
export declare function getEventData<T extends EventType>(event: ISemanticEvent, expectedType: T): EventDataRegistry[T] | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Get event data with a fallback for missing properties.
|
|
62
|
+
*
|
|
63
|
+
* This is useful when you need default values for optional fields.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const { message, hint } = getEventDataWithDefaults(
|
|
68
|
+
* event,
|
|
69
|
+
* 'query.invalid',
|
|
70
|
+
* { message: 'Invalid response.', hint: undefined }
|
|
71
|
+
* );
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function getEventDataWithDefaults<T extends EventType>(event: ISemanticEvent, expectedType: T, defaults: EventDataRegistry[T]): EventDataRegistry[T];
|
|
75
|
+
/**
|
|
76
|
+
* Assert and get typed event data.
|
|
77
|
+
*
|
|
78
|
+
* Throws if the event type doesn't match. Use this when you're certain
|
|
79
|
+
* of the event type and want a clear error if assumptions are wrong.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* // In a handler that only receives 'quit.confirmed' events
|
|
84
|
+
* const data = requireEventData(event, 'quit.confirmed');
|
|
85
|
+
* console.log(`Score: ${data.finalScore}/${data.maxScore}`);
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare function requireEventData<T extends EventType>(event: ISemanticEvent, expectedType: T): EventDataRegistry[T];
|
|
89
|
+
/**
|
|
90
|
+
* Safely access a property from event data with type inference.
|
|
91
|
+
*
|
|
92
|
+
* Returns undefined if the event type doesn't match or the property
|
|
93
|
+
* doesn't exist.
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const message = getEventProperty(event, 'query.invalid', 'message');
|
|
98
|
+
* // message is string | undefined
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export declare function getEventProperty<T extends EventType, K extends keyof EventDataRegistry[T]>(event: ISemanticEvent, expectedType: T, property: K): EventDataRegistry[T][K] | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Get event data as a generic record for untyped event access.
|
|
104
|
+
*
|
|
105
|
+
* Use this when working with events that aren't yet in the EventDataRegistry.
|
|
106
|
+
* Prefer using typed helpers (isEventType, getEventData) when the event
|
|
107
|
+
* type is known.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const data = getUntypedEventData(event);
|
|
112
|
+
* if (data.customField) {
|
|
113
|
+
* console.log(data.customField);
|
|
114
|
+
* }
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare function getUntypedEventData(event: ISemanticEvent): Record<string, unknown>;
|
|
118
|
+
//# sourceMappingURL=event-helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-helpers.d.ts","sourceRoot":"","sources":["../../../../../../mnt/c/repotemp/sharpee/packages/core/src/events/event-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC;;;;;;;;;;;;;;;;GAgBG;AAC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KzB"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Event Helpers - Type-safe event consumption utilities
|
|
4
|
+
*
|
|
5
|
+
* These functions help consumers safely extract typed data from events
|
|
6
|
+
* without resorting to `as any` casts.
|
|
7
|
+
*
|
|
8
|
+
* @see ADR-082 for design rationale
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.isEventType = isEventType;
|
|
12
|
+
exports.hasEventPrefix = hasEventPrefix;
|
|
13
|
+
exports.getEventData = getEventData;
|
|
14
|
+
exports.getEventDataWithDefaults = getEventDataWithDefaults;
|
|
15
|
+
exports.requireEventData = requireEventData;
|
|
16
|
+
exports.getEventProperty = getEventProperty;
|
|
17
|
+
exports.getUntypedEventData = getUntypedEventData;
|
|
18
|
+
/**
|
|
19
|
+
* Check if an event is of a specific type and narrow its type.
|
|
20
|
+
*
|
|
21
|
+
* This is a type guard that allows TypeScript to narrow the event
|
|
22
|
+
* type in conditional branches.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* function processEvent(event: ISemanticEvent) {
|
|
27
|
+
* if (isEventType(event, 'query.invalid')) {
|
|
28
|
+
* // TypeScript knows event.data is QueryInvalidData
|
|
29
|
+
* console.log(event.data.message);
|
|
30
|
+
* console.log(event.data.hint);
|
|
31
|
+
* }
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
function isEventType(event, type) {
|
|
36
|
+
return event.type === type;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Check if an event type starts with a prefix.
|
|
40
|
+
*
|
|
41
|
+
* Useful for handling categories of events (e.g., all message.* events).
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* if (hasEventPrefix(event, 'message.')) {
|
|
46
|
+
* // Handle any message event
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
function hasEventPrefix(event, prefix) {
|
|
51
|
+
return event.type.startsWith(prefix);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get typed event data if the event matches the expected type.
|
|
55
|
+
*
|
|
56
|
+
* Returns undefined if the event type doesn't match. This is the safe
|
|
57
|
+
* way to extract data when you're not sure of the event type.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const data = getEventData(event, 'quit.confirmed');
|
|
62
|
+
* if (data) {
|
|
63
|
+
* console.log(`Final score: ${data.finalScore}`);
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
function getEventData(event, expectedType) {
|
|
68
|
+
if (event.type === expectedType) {
|
|
69
|
+
return event.data;
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Get event data with a fallback for missing properties.
|
|
75
|
+
*
|
|
76
|
+
* This is useful when you need default values for optional fields.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const { message, hint } = getEventDataWithDefaults(
|
|
81
|
+
* event,
|
|
82
|
+
* 'query.invalid',
|
|
83
|
+
* { message: 'Invalid response.', hint: undefined }
|
|
84
|
+
* );
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
function getEventDataWithDefaults(event, expectedType, defaults) {
|
|
88
|
+
if (event.type === expectedType && event.data) {
|
|
89
|
+
return { ...defaults, ...event.data };
|
|
90
|
+
}
|
|
91
|
+
return defaults;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Assert and get typed event data.
|
|
95
|
+
*
|
|
96
|
+
* Throws if the event type doesn't match. Use this when you're certain
|
|
97
|
+
* of the event type and want a clear error if assumptions are wrong.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```typescript
|
|
101
|
+
* // In a handler that only receives 'quit.confirmed' events
|
|
102
|
+
* const data = requireEventData(event, 'quit.confirmed');
|
|
103
|
+
* console.log(`Score: ${data.finalScore}/${data.maxScore}`);
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
function requireEventData(event, expectedType) {
|
|
107
|
+
if (event.type !== expectedType) {
|
|
108
|
+
throw new Error(`Expected event type '${expectedType}', got '${event.type}'`);
|
|
109
|
+
}
|
|
110
|
+
return event.data;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Safely access a property from event data with type inference.
|
|
114
|
+
*
|
|
115
|
+
* Returns undefined if the event type doesn't match or the property
|
|
116
|
+
* doesn't exist.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* const message = getEventProperty(event, 'query.invalid', 'message');
|
|
121
|
+
* // message is string | undefined
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
function getEventProperty(event, expectedType, property) {
|
|
125
|
+
if (event.type === expectedType && event.data) {
|
|
126
|
+
return event.data[property];
|
|
127
|
+
}
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Get event data as a generic record for untyped event access.
|
|
132
|
+
*
|
|
133
|
+
* Use this when working with events that aren't yet in the EventDataRegistry.
|
|
134
|
+
* Prefer using typed helpers (isEventType, getEventData) when the event
|
|
135
|
+
* type is known.
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* const data = getUntypedEventData(event);
|
|
140
|
+
* if (data.customField) {
|
|
141
|
+
* console.log(data.customField);
|
|
142
|
+
* }
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
function getUntypedEventData(event) {
|
|
146
|
+
if (event.data && typeof event.data === 'object') {
|
|
147
|
+
return event.data;
|
|
148
|
+
}
|
|
149
|
+
return {};
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=event-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-helpers.js","sourceRoot":"","sources":["../../../../../../mnt/c/repotemp/sharpee/packages/core/src/events/event-helpers.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;AAsBH,kCAKC;AAcD,wCAEC;AAgBD,oCAQC;AAgBD,4DASC;AAeD,4CAUC;AAcD,4CAYC;AAiBD,kDAOC;AAlKD;;;;;;;;;;;;;;;;GAgBG;AACH,SAAgB,WAAW,CACzB,KAAqB,EACrB,IAAO;IAEP,OAAO,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;AAC7B,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,cAAc,CAAC,KAAqB,EAAE,MAAc;IAClE,OAAO,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,YAAY,CAC1B,KAAqB,EACrB,YAAe;IAEf,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC,IAA4B,CAAC;IAC5C,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,SAAgB,wBAAwB,CACtC,KAAqB,EACrB,YAAe,EACf,QAA8B;IAE9B,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;QAC9C,OAAO,EAAE,GAAG,QAAQ,EAAE,GAAI,KAAK,CAAC,IAA6B,EAAE,CAAC;IAClE,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,SAAgB,gBAAgB,CAC9B,KAAqB,EACrB,YAAe;IAEf,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CACb,wBAAwB,YAAY,WAAW,KAAK,CAAC,IAAI,GAAG,CAC7D,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC,IAA4B,CAAC;AAC5C,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,gBAAgB,CAI9B,KAAqB,EACrB,YAAe,EACf,QAAW;IAEX,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;QAC9C,OAAQ,KAAK,CAAC,IAA6B,CAAC,QAAQ,CAAC,CAAC;IACxD,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;;;;;;;;;GAcG;AACH,SAAgB,mBAAmB,CACjC,KAAqB;IAErB,IAAI,KAAK,CAAC,IAAI,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QACjD,OAAO,KAAK,CAAC,IAA+B,CAAC;IAC/C,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event Data Registry - Central type definitions for all semantic events
|
|
3
|
+
*
|
|
4
|
+
* This module defines the mapping between event type strings and their
|
|
5
|
+
* corresponding data shapes. It serves as the single source of truth
|
|
6
|
+
* for event data types across the Sharpee platform.
|
|
7
|
+
*
|
|
8
|
+
* @see ADR-082 for the design rationale
|
|
9
|
+
*
|
|
10
|
+
* ## Extensibility
|
|
11
|
+
*
|
|
12
|
+
* Packages can extend this registry using TypeScript declaration merging:
|
|
13
|
+
*
|
|
14
|
+
* ```typescript
|
|
15
|
+
* declare module '@sharpee/core' {
|
|
16
|
+
* interface EventDataRegistry {
|
|
17
|
+
* 'my.custom.event': MyCustomData;
|
|
18
|
+
* }
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import { EntityId } from '../types/entity';
|
|
23
|
+
/**
|
|
24
|
+
* Registry mapping event type strings to their data shapes.
|
|
25
|
+
*
|
|
26
|
+
* This interface is designed to be extended via declaration merging
|
|
27
|
+
* by stdlib, stories, and other packages.
|
|
28
|
+
*/
|
|
29
|
+
export interface EventDataRegistry {
|
|
30
|
+
'query.pending': QueryPendingData;
|
|
31
|
+
'query.invalid': QueryInvalidData;
|
|
32
|
+
'query.response': QueryResponseData;
|
|
33
|
+
'message.success': MessageData;
|
|
34
|
+
'message.failure': MessageData;
|
|
35
|
+
'message.info': MessageData;
|
|
36
|
+
'message.warning': MessageData;
|
|
37
|
+
'message.debug': MessageData;
|
|
38
|
+
'game.initializing': EmptyData;
|
|
39
|
+
'game.initialized': GameInitializedData;
|
|
40
|
+
'game.starting': EmptyData;
|
|
41
|
+
'game.started': GameStartedData;
|
|
42
|
+
'game.ending': GameEndingData;
|
|
43
|
+
'game.ended': GameEndedData;
|
|
44
|
+
'game.won': GameEndedData;
|
|
45
|
+
'game.lost': GameEndedData;
|
|
46
|
+
'game.quit': EmptyData;
|
|
47
|
+
'game.aborted': EmptyData;
|
|
48
|
+
'platform.save_requested': SaveRequestedData;
|
|
49
|
+
'platform.save_completed': SaveCompletedData;
|
|
50
|
+
'platform.save_failed': SaveFailedData;
|
|
51
|
+
'platform.restore_requested': RestoreRequestedData;
|
|
52
|
+
'platform.restore_completed': RestoreCompletedData;
|
|
53
|
+
'platform.restore_failed': RestoreFailedData;
|
|
54
|
+
'platform.quit_requested': EmptyData;
|
|
55
|
+
'platform.quit_confirmed': QuitConfirmedData;
|
|
56
|
+
'platform.quit_cancelled': EmptyData;
|
|
57
|
+
'platform.restart_requested': EmptyData;
|
|
58
|
+
'platform.restart_completed': EmptyData;
|
|
59
|
+
'platform.restart_cancelled': EmptyData;
|
|
60
|
+
'turn.started': TurnData;
|
|
61
|
+
'turn.ended': TurnData;
|
|
62
|
+
'quit.confirmed': QuitConfirmedData;
|
|
63
|
+
'quit.cancelled': EmptyData;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Empty data for events that carry no payload.
|
|
67
|
+
*/
|
|
68
|
+
export interface EmptyData {
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Standard message event data.
|
|
72
|
+
*/
|
|
73
|
+
export interface MessageData {
|
|
74
|
+
messageId: string;
|
|
75
|
+
params?: Record<string, unknown>;
|
|
76
|
+
}
|
|
77
|
+
export interface QueryPendingData {
|
|
78
|
+
query: {
|
|
79
|
+
id: string;
|
|
80
|
+
messageId: string;
|
|
81
|
+
messageParams?: Record<string, unknown>;
|
|
82
|
+
options?: string[];
|
|
83
|
+
validationType?: string;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
export interface QueryInvalidData {
|
|
87
|
+
message?: string;
|
|
88
|
+
hint?: string;
|
|
89
|
+
queryId?: string;
|
|
90
|
+
}
|
|
91
|
+
export interface QueryResponseData {
|
|
92
|
+
queryId: string;
|
|
93
|
+
response: string | number | boolean;
|
|
94
|
+
}
|
|
95
|
+
export interface GameInitializedData {
|
|
96
|
+
storyId?: string;
|
|
97
|
+
storyTitle?: string;
|
|
98
|
+
storyVersion?: string;
|
|
99
|
+
}
|
|
100
|
+
export interface GameStartedData {
|
|
101
|
+
storyId?: string;
|
|
102
|
+
storyTitle?: string;
|
|
103
|
+
initialLocation?: EntityId;
|
|
104
|
+
}
|
|
105
|
+
export interface GameEndingData {
|
|
106
|
+
reason?: string;
|
|
107
|
+
}
|
|
108
|
+
export interface GameEndedData {
|
|
109
|
+
finalScore?: number;
|
|
110
|
+
maxScore?: number;
|
|
111
|
+
moves?: number;
|
|
112
|
+
reason?: string;
|
|
113
|
+
rank?: string;
|
|
114
|
+
}
|
|
115
|
+
export interface SaveRequestedData {
|
|
116
|
+
slotName?: string;
|
|
117
|
+
}
|
|
118
|
+
export interface SaveCompletedData {
|
|
119
|
+
slotName?: string;
|
|
120
|
+
timestamp?: number;
|
|
121
|
+
}
|
|
122
|
+
export interface SaveFailedData {
|
|
123
|
+
slotName?: string;
|
|
124
|
+
error?: string;
|
|
125
|
+
}
|
|
126
|
+
export interface RestoreRequestedData {
|
|
127
|
+
slotName?: string;
|
|
128
|
+
}
|
|
129
|
+
export interface RestoreCompletedData {
|
|
130
|
+
slotName?: string;
|
|
131
|
+
timestamp?: number;
|
|
132
|
+
}
|
|
133
|
+
export interface RestoreFailedData {
|
|
134
|
+
slotName?: string;
|
|
135
|
+
error?: string;
|
|
136
|
+
}
|
|
137
|
+
export interface QuitConfirmedData {
|
|
138
|
+
messageId?: string;
|
|
139
|
+
finalScore?: number;
|
|
140
|
+
maxScore?: number;
|
|
141
|
+
moves?: number;
|
|
142
|
+
}
|
|
143
|
+
export interface TurnData {
|
|
144
|
+
turn: number;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* All known event type strings.
|
|
148
|
+
*/
|
|
149
|
+
export type EventType = keyof EventDataRegistry;
|
|
150
|
+
/**
|
|
151
|
+
* Get the data type for a specific event type.
|
|
152
|
+
*/
|
|
153
|
+
export type EventDataFor<T extends EventType> = EventDataRegistry[T];
|
|
154
|
+
//# sourceMappingURL=event-registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-registry.d.ts","sourceRoot":"","sources":["../../../../../../mnt/c/repotemp/sharpee/packages/core/src/events/event-registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAKhC,eAAe,EAAE,gBAAgB,CAAC;IAClC,eAAe,EAAE,gBAAgB,CAAC;IAClC,gBAAgB,EAAE,iBAAiB,CAAC;IAMpC,iBAAiB,EAAE,WAAW,CAAC;IAC/B,iBAAiB,EAAE,WAAW,CAAC;IAC/B,cAAc,EAAE,WAAW,CAAC;IAC5B,iBAAiB,EAAE,WAAW,CAAC;IAC/B,eAAe,EAAE,WAAW,CAAC;IAM7B,mBAAmB,EAAE,SAAS,CAAC;IAC/B,kBAAkB,EAAE,mBAAmB,CAAC;IACxC,eAAe,EAAE,SAAS,C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,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,iBAAiB;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAMD,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;CACd;AAMD;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,iBAAiB,CAAC;AAEhD;;GAEG;AACH,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,SAAS,IAAI,iBAAiB,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Event Data Registry - Central type definitions for all semantic events
|
|
4
|
+
*
|
|
5
|
+
* This module defines the mapping between event type strings and their
|
|
6
|
+
* corresponding data shapes. It serves as the single source of truth
|
|
7
|
+
* for event data types across the Sharpee platform.
|
|
8
|
+
*
|
|
9
|
+
* @see ADR-082 for the design rationale
|
|
10
|
+
*
|
|
11
|
+
* ## Extensibility
|
|
12
|
+
*
|
|
13
|
+
* Packages can extend this registry using TypeScript declaration merging:
|
|
14
|
+
*
|
|
15
|
+
* ```typescript
|
|
16
|
+
* declare module '@sharpee/core' {
|
|
17
|
+
* interface EventDataRegistry {
|
|
18
|
+
* 'my.custom.event': MyCustomData;
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
//# sourceMappingURL=event-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-registry.js","sourceRoot":"","sources":["../../../../../../mnt/c/repotemp/sharpee/packages/core/src/events/event-registry.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;GAoBG"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic event source infrastructure for the narrative engine.
|
|
3
|
+
* This provides a simple pub/sub mechanism for any type of event.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Generic event source interface for pub/sub pattern
|
|
7
|
+
*/
|
|
8
|
+
export interface IGenericEventSource<T> {
|
|
9
|
+
/**
|
|
10
|
+
* Emit an event to all subscribers
|
|
11
|
+
*/
|
|
12
|
+
emit(event: T): void;
|
|
13
|
+
/**
|
|
14
|
+
* Subscribe to events
|
|
15
|
+
* @returns Unsubscribe function
|
|
16
|
+
*/
|
|
17
|
+
subscribe(handler: (event: T) => void): () => void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Simple synchronous implementation of EventSource
|
|
21
|
+
*/
|
|
22
|
+
export declare class SimpleEventSource<T> implements IGenericEventSource<T> {
|
|
23
|
+
private handlers;
|
|
24
|
+
emit(event: T): void;
|
|
25
|
+
subscribe(handler: (event: T) => void): () => void;
|
|
26
|
+
/**
|
|
27
|
+
* Get the current number of subscribers
|
|
28
|
+
*/
|
|
29
|
+
get subscriberCount(): number;
|
|
30
|
+
/**
|
|
31
|
+
* Remove all subscribers
|
|
32
|
+
*/
|
|
33
|
+
clear(): void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Create a new event source for a specific event type
|
|
37
|
+
*/
|
|
38
|
+
export declare function createEventSource<T>(): IGenericEventSource<T>;
|
|
39
|
+
//# sourceMappingURL=event-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-source.d.ts","sourceRoot":"","sources":["../../../../../../mnt/c/repotemp/sharpee/packages/core/src/events/event-source.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;GAEG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC;;OAEG;IACH,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;IAErB;;;OAGG;IACH,SAAS,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CACpD;AAED;;GAEG;AACH,qBAAa,iBAAiB,CAAC,CAAC,CAAE,YAAW,mBAAmB,CAAC,CAAC,CAAC;IACjE,OAAO,CAAC,QAAQ,CAA8B;IAE9C,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI;IAapB,SAAS,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,GAAG,MAAM,IAAI;IAYlD;;OAEG;IACH,IAAI,eAAe,IAAI,MAAM,CAE5B;IAED;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,KAAK,mBAAmB,CAAC,CAAC,CAAC,CAE7D"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Generic event source infrastructure for the narrative engine.
|
|
4
|
+
* This provides a simple pub/sub mechanism for any type of event.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.SimpleEventSource = void 0;
|
|
8
|
+
exports.createEventSource = createEventSource;
|
|
9
|
+
/**
|
|
10
|
+
* Simple synchronous implementation of EventSource
|
|
11
|
+
*/
|
|
12
|
+
class SimpleEventSource {
|
|
13
|
+
handlers = [];
|
|
14
|
+
emit(event) {
|
|
15
|
+
// Create a copy to avoid issues if handlers modify the array
|
|
16
|
+
const currentHandlers = [...this.handlers];
|
|
17
|
+
currentHandlers.forEach(handler => {
|
|
18
|
+
try {
|
|
19
|
+
handler(event);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
// Prevent one handler's error from affecting others
|
|
23
|
+
console.error('Error in event handler:', error);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
subscribe(handler) {
|
|
28
|
+
this.handlers.push(handler);
|
|
29
|
+
// Return unsubscribe function
|
|
30
|
+
return () => {
|
|
31
|
+
const index = this.handlers.indexOf(handler);
|
|
32
|
+
if (index > -1) {
|
|
33
|
+
this.handlers.splice(index, 1);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get the current number of subscribers
|
|
39
|
+
*/
|
|
40
|
+
get subscriberCount() {
|
|
41
|
+
return this.handlers.length;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Remove all subscribers
|
|
45
|
+
*/
|
|
46
|
+
clear() {
|
|
47
|
+
this.handlers = [];
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.SimpleEventSource = SimpleEventSource;
|
|
51
|
+
/**
|
|
52
|
+
* Create a new event source for a specific event type
|
|
53
|
+
*/
|
|
54
|
+
function createEventSource() {
|
|
55
|
+
return new SimpleEventSource();
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=event-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-source.js","sourceRoot":"","sources":["../../../../../../mnt/c/repotemp/sharpee/packages/core/src/events/event-source.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAmEH,8CAEC;AAnDD;;GAEG;AACH,MAAa,iBAAiB;IACpB,QAAQ,GAA2B,EAAE,CAAC;IAE9C,IAAI,CAAC,KAAQ;QACX,6DAA6D;QAC7D,MAAM,eAAe,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC3C,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;YAChC,IAAI,CAAC;gBACH,OAAO,CAAC,KAAK,CAAC,CAAC;YACjB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,oDAAoD;gBACpD,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;YAClD,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,SAAS,CAAC,OAA2B;QACnC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAE5B,8BAA8B;QAC9B,OAAO,GAAG,EAAE;YACV,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC7C,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;gBACf,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YACjC,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;IACrB,CAAC;CACF;AAzCD,8CAyCC;AAED;;GAEG;AACH,SAAgB,iBAAiB;IAC/B,OAAO,IAAI,iBAAiB,EAAK,CAAC;AACpC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ISemanticEvent } from './types';
|
|
2
|
+
import { EntityId } from '../types/entity';
|
|
3
|
+
import { ISemanticEventSource } from './semantic-event-source';
|
|
4
|
+
/**
|
|
5
|
+
* Create a new semantic event
|
|
6
|
+
*/
|
|
7
|
+
export declare function createEvent(type: string, data?: Record<string, unknown>, entities?: {
|
|
8
|
+
actor?: EntityId;
|
|
9
|
+
target?: EntityId;
|
|
10
|
+
instrument?: EntityId;
|
|
11
|
+
location?: EntityId;
|
|
12
|
+
others?: EntityId[];
|
|
13
|
+
}, metadata?: {
|
|
14
|
+
tags?: string[];
|
|
15
|
+
priority?: number;
|
|
16
|
+
narrate?: boolean;
|
|
17
|
+
source?: string;
|
|
18
|
+
sessionId?: string;
|
|
19
|
+
[key: string]: unknown;
|
|
20
|
+
}): ISemanticEvent;
|
|
21
|
+
export { SemanticEventSourceImpl as EventSourceImpl } from './semantic-event-source';
|
|
22
|
+
/**
|
|
23
|
+
* Create a new event source
|
|
24
|
+
* @deprecated Use createSemanticEventSource from './semantic-event-source'
|
|
25
|
+
*/
|
|
26
|
+
export declare function createEventSource(): ISemanticEventSource;
|
|
27
|
+
//# sourceMappingURL=event-system.d.ts.map
|