alepha 0.8.1 → 0.9.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.
package/topic/redis.d.ts CHANGED
@@ -1,44 +1,45 @@
1
+ import * as _alepha_core0$1 from "alepha";
2
+ import * as _alepha_core0 from "alepha";
3
+ import { Alepha } from "alepha";
1
4
  import { SubscribeCallback, TopicProvider, UnSubscribeFn } from "alepha/topic";
2
- import { Alepha, HookDescriptor, Logger, Module, Static, TObject, TString } from "alepha";
3
5
  import { RedisProvider, RedisSubscriberProvider } from "alepha/redis";
4
6
 
5
7
  //#region src/providers/RedisTopicProvider.d.ts
6
- declare const envSchema: TObject<{
7
- REDIS_TOPIC_PREFIX: TString;
8
- }>;
9
- declare class RedisTopicProvider implements TopicProvider {
10
- protected readonly env: Static<typeof envSchema>;
8
+ declare class RedisTopicProvider extends TopicProvider {
9
+ protected readonly env: {
10
+ REDIS_TOPIC_PREFIX: string;
11
+ };
12
+ protected readonly alepha: Alepha;
11
13
  protected readonly redisProvider: RedisProvider;
12
14
  protected readonly redisSubscriberProvider: RedisSubscriberProvider;
13
- protected readonly log: Logger;
14
- protected readonly stop: HookDescriptor<"stop">;
15
+ protected readonly log: _alepha_core0$1.Logger;
16
+ protected readonly start: _alepha_core0$1.HookDescriptor<"start">;
15
17
  prefix(queue: string): string;
16
18
  /**
17
- * Publish a message to a topic.
18
- */
19
+ * Publish a message to a topic.
20
+ */
19
21
  publish(topic: string, message: string): Promise<void>;
20
22
  /**
21
- * Subscribe to a topic.
22
- */
23
+ * Subscribe to a topic.
24
+ */
23
25
  subscribe(name: string, callback: SubscribeCallback): Promise<UnSubscribeFn>;
24
26
  /**
25
- * Unsubscribe from a topic.
26
- */
27
+ * Unsubscribe from a topic.
28
+ */
27
29
  unsubscribe(name: string, callback?: SubscribeCallback): Promise<void>;
28
30
  }
31
+ //# sourceMappingURL=RedisTopicProvider.d.ts.map
29
32
  //#endregion
30
33
  //#region src/index.d.ts
31
- // ---------------------------------------------------------------------------------------------------------------------
32
34
  /**
33
- * Plugin for Alepha Topic that provides Redis pub/sub capabilities.
34
- *
35
- * @see {@link RedisTopicProvider}
36
- * @module alepha.topic.redis
37
- */
38
- declare class AlephaTopicRedis implements Module {
39
- readonly name = "alepha.topic.redis";
40
- readonly $services: (alepha: Alepha) => Alepha;
41
- }
35
+ * Plugin for Alepha Topic that provides Redis pub/sub capabilities.
36
+ *
37
+ * @see {@link RedisTopicProvider}
38
+ * @module alepha.topic.redis
39
+ */
40
+ declare const AlephaTopicRedis: _alepha_core0.ModuleDescriptor;
41
+ //# sourceMappingURL=index.d.ts.map
42
+
42
43
  //#endregion
43
44
  export { AlephaTopicRedis, RedisTopicProvider };
44
45
  //# sourceMappingURL=index.d.ts.map
package/topic.d.ts CHANGED
@@ -1,67 +1,92 @@
1
+ import * as _alepha_core2 from "alepha";
2
+ import * as _alepha_core0$1 from "alepha";
1
3
  import * as _alepha_core0 from "alepha";
2
- import { Alepha, KIND, Module, OPTIONS, Static, TSchema } from "alepha";
4
+ import { Alepha, Descriptor, KIND, Service, Static, TSchema } from "alepha";
3
5
  import { DateTimeProvider, DurationLike } from "alepha/datetime";
4
6
 
5
7
  //#region src/providers/TopicProvider.d.ts
6
- declare class TopicProvider {
7
- constructor();
8
+ /**
9
+ * Base class for topic providers.
10
+ */
11
+ declare abstract class TopicProvider {
12
+ protected readonly alepha: Alepha;
8
13
  /**
9
14
  * Publish a message to a topic.
10
15
  *
11
16
  * @param topic - The topic to publish to.
12
17
  * @param message - The message to publish.
13
18
  */
14
- publish(_topic: string, _message: string): Promise<void>;
19
+ abstract publish(topic: string, message: string): Promise<void>;
15
20
  /**
16
21
  * Subscribe to a topic.
17
22
  *
18
23
  * @param topic - The topic to subscribe to.
19
24
  * @param callback - The callback to call when a message is received.
20
25
  */
21
- subscribe(_topic: string, _callback: SubscribeCallback): Promise<UnSubscribeFn>;
26
+ abstract subscribe(topic: string, callback: SubscribeCallback): Promise<UnSubscribeFn>;
22
27
  /**
23
28
  * Unsubscribe from a topic.
24
29
  *
25
30
  * @param topic - The topic to unsubscribe from.
26
31
  */
27
- unsubscribe(_topic: string): Promise<void>;
32
+ abstract unsubscribe(topic: string): Promise<void>;
33
+ /**
34
+ * Returns the list of $subscribers for this provider.
35
+ */
36
+ protected subscribers(): Array<() => Promise<unknown>>;
28
37
  }
29
38
  type SubscribeCallback = (message: string) => Promise<void> | void;
30
39
  type UnSubscribeFn = () => Promise<void>;
31
40
  //# sourceMappingURL=TopicProvider.d.ts.map
32
41
  //#endregion
33
42
  //#region src/descriptors/$topic.d.ts
34
- declare const KEY$1 = "TOPIC";
35
43
  /**
36
44
  * Create a new topic.
37
45
  */
38
46
  declare const $topic: {
39
47
  <T extends TopicMessageSchema>(options: TopicDescriptorOptions<T>): TopicDescriptor<T>;
40
- [KIND]: string;
48
+ [KIND]: typeof TopicDescriptor;
41
49
  };
42
- interface TopicMessageSchema {
43
- headers?: TSchema;
44
- payload: TSchema;
45
- }
46
- interface TopicDescriptorOptions<T extends TopicMessageSchema = TopicMessageSchema> {
50
+ interface TopicDescriptorOptions<T extends TopicMessageSchema> {
51
+ /**
52
+ * Topic key.
53
+ *
54
+ * If not provided, the propertyKey is used as the topic name.
55
+ */
47
56
  name?: string;
57
+ /**
58
+ * Describe the topic. For documentation purposes.
59
+ */
48
60
  description?: string;
49
- provider?: "memory" | (() => TopicProvider);
61
+ /**
62
+ * Override the default topic provider.
63
+ *
64
+ * If not provided, the default provider is used.
65
+ * If "memory" is provided, the default in-memory provider is used.
66
+ * If a class is provided, it must extend `TopicProvider`.
67
+ */
68
+ provider?: "memory" | Service<TopicProvider>;
69
+ /**
70
+ * Topic message schema.
71
+ */
50
72
  schema: T;
51
- handler?: (message: {
52
- payload: Static<T["payload"]>;
53
- }) => Promise<void>;
73
+ /**
74
+ * Add a subscriber handler.
75
+ */
76
+ handler?: TopicHandler<T>;
54
77
  }
55
- interface TopicDescriptor<T extends TopicMessageSchema = TopicMessageSchema> {
56
- [KIND]: typeof KEY$1;
57
- [OPTIONS]: TopicDescriptorOptions<T>;
58
- name(): string;
59
- provider(): TopicProvider;
60
- publish(payload: Static<T["payload"]>): Promise<void>;
61
- subscribe(fn: (message: TopicMessage<T>) => void): Promise<UnSubscribeFn>;
62
- wait(options?: TopicWaitOptions<T>): Promise<Static<T["payload"]>>;
78
+ declare class TopicDescriptor<T extends TopicMessageSchema> extends Descriptor<TopicDescriptorOptions<T>> {
79
+ protected readonly log: _alepha_core2.Logger;
80
+ protected readonly dateTimeProvider: DateTimeProvider;
81
+ readonly provider: TopicProvider;
82
+ get name(): string;
83
+ publish(payload: TopicMessage<T>["payload"]): Promise<void>;
84
+ subscribe(handler: TopicHandler<T>): Promise<UnSubscribeFn>;
85
+ wait(options?: TopicWaitOptions<T>): Promise<TopicMessage<T>>;
86
+ protected $provider(): TopicProvider;
87
+ protected parseMessage(message: string): TopicMessage<T>;
63
88
  }
64
- interface TopicMessage<T extends TopicMessageSchema = TopicMessageSchema> {
89
+ interface TopicMessage<T extends TopicMessageSchema> {
65
90
  payload: Static<T["payload"]>;
66
91
  }
67
92
  interface TopicWaitOptions<T extends TopicMessageSchema> {
@@ -70,30 +95,27 @@ interface TopicWaitOptions<T extends TopicMessageSchema> {
70
95
  payload: Static<T["payload"]>;
71
96
  }) => boolean;
72
97
  }
98
+ interface TopicMessageSchema {
99
+ headers?: TSchema;
100
+ payload: TSchema;
101
+ }
102
+ type TopicHandler<T extends TopicMessageSchema = TopicMessageSchema> = (message: TopicMessage<T>) => unknown;
103
+ //# sourceMappingURL=$topic.d.ts.map
73
104
  //#endregion
74
105
  //#region src/descriptors/$subscriber.d.ts
75
- declare const KEY = "SUBSCRIBER";
76
106
  /**
77
- * Subscriber descriptor.
78
- *
79
- * @param options - The subscriber options.
80
- * @returns The descriptor value.
107
+ * Subscribe to a $topic.
81
108
  */
82
109
  declare const $subscriber: {
83
110
  <T extends TopicMessageSchema>(options: SubscriberDescriptorOptions<T>): SubscriberDescriptor<T>;
84
- [KIND]: string;
111
+ [KIND]: typeof SubscriberDescriptor;
85
112
  };
86
- interface SubscriberDescriptorOptions<T extends TopicMessageSchema = TopicMessageSchema> {
113
+ interface SubscriberDescriptorOptions<T extends TopicMessageSchema> {
87
114
  topic: TopicDescriptor<T>;
88
- handler: (message: {
89
- payload: Static<T["payload"]>;
90
- }) => Promise<void>;
91
- }
92
- interface SubscriberDescriptor<T extends TopicMessageSchema = TopicMessageSchema> {
93
- [KIND]: typeof KEY;
94
- [OPTIONS]: SubscriberDescriptorOptions<T>;
95
- topic: () => TopicDescriptor<T>;
115
+ handler: TopicHandler<T>;
96
116
  }
117
+ declare class SubscriberDescriptor<T extends TopicMessageSchema> extends Descriptor<SubscriberDescriptorOptions<T>> {}
118
+ //# sourceMappingURL=$subscriber.d.ts.map
97
119
  //#endregion
98
120
  //#region src/errors/TopicTimeoutError.d.ts
99
121
  declare class TopicTimeoutError extends Error {
@@ -104,8 +126,10 @@ declare class TopicTimeoutError extends Error {
104
126
  //# sourceMappingURL=TopicTimeoutError.d.ts.map
105
127
  //#endregion
106
128
  //#region src/providers/MemoryTopicProvider.d.ts
107
- declare class MemoryTopicProvider implements TopicProvider {
129
+ declare class MemoryTopicProvider extends TopicProvider {
130
+ protected readonly log: _alepha_core0$1.Logger;
108
131
  protected readonly subscriptions: Record<string, SubscribeCallback[]>;
132
+ protected readonly start: _alepha_core0$1.HookDescriptor<"start">;
109
133
  /**
110
134
  * Publish a message to a topic.
111
135
  *
@@ -129,74 +153,6 @@ declare class MemoryTopicProvider implements TopicProvider {
129
153
  }
130
154
  //# sourceMappingURL=MemoryTopicProvider.d.ts.map
131
155
  //#endregion
132
- //#region src/providers/TopicDescriptorProvider.d.ts
133
- declare class TopicDescriptorProvider {
134
- protected readonly log: _alepha_core0.Logger;
135
- protected readonly alepha: Alepha;
136
- protected readonly dateTimeProvider: DateTimeProvider;
137
- protected readonly topicProvider: TopicProvider;
138
- protected readonly memoryTopicProvider: MemoryTopicProvider;
139
- protected readonly topics: TopicDescriptor[];
140
- protected readonly subscribers: Array<SubscriberDescriptorOptions & {
141
- unsub?: UnSubscribeFn;
142
- }>;
143
- protected readonly configure: _alepha_core0.HookDescriptor<"configure">;
144
- protected readonly start: _alepha_core0.HookDescriptor<"start">;
145
- /**
146
- * Process the descriptors.
147
- *
148
- * @protected
149
- */
150
- protected processDescriptors(): void;
151
- /**
152
- * Process the queue descriptors.
153
- *
154
- * @protected
155
- */
156
- protected processTopicDescriptors(): void;
157
- /**
158
- * Wait for a message on the topic.
159
- *
160
- * @param topic
161
- * @param options
162
- * @protected
163
- */
164
- protected wait(topic: TopicDescriptor, options?: TopicWaitOptions<any>): Promise<unknown>;
165
- /**
166
- * Process the consumer descriptors.
167
- *
168
- * @protected
169
- */
170
- protected processSubscriberDescriptors(): void;
171
- /**
172
- * Get the provider for the queue.
173
- *
174
- * @param options - The queue options.
175
- * @protected
176
- */
177
- protected provider(options: TopicDescriptorOptions): TopicProvider;
178
- /**
179
- * Publish a message to the topic.
180
- *
181
- * @param topic
182
- * @param message
183
- * @protected
184
- */
185
- protected publish<T extends TopicMessageSchema = TopicMessageSchema>(topic: TopicDescriptor<T>, message: TopicMessage<T>): Promise<void>;
186
- /**
187
- * Process a message.
188
- *
189
- * @param subscriber
190
- * @param message
191
- * @protected
192
- */
193
- protected processMessage(subscriber: SubscriberDescriptorOptions, message: string): Promise<void>;
194
- protected parseMessage(schema: any, message: string): {
195
- payload: any;
196
- };
197
- }
198
- //# sourceMappingURL=TopicDescriptorProvider.d.ts.map
199
- //#endregion
200
156
  //#region src/index.d.ts
201
157
  /**
202
158
  * Generic interface for pub/sub messaging.
@@ -207,12 +163,9 @@ declare class TopicDescriptorProvider {
207
163
  * @see {@link $subscriber}
208
164
  * @module alepha.topic
209
165
  */
210
- declare class AlephaTopic implements Module {
211
- readonly name = "alepha.topic";
212
- readonly $services: (alepha: Alepha) => Alepha;
213
- }
166
+ declare const AlephaTopic: _alepha_core0.ModuleDescriptor;
214
167
  //# sourceMappingURL=index.d.ts.map
215
168
 
216
169
  //#endregion
217
- export { $subscriber, $topic, AlephaTopic, MemoryTopicProvider, SubscribeCallback, SubscriberDescriptor, SubscriberDescriptorOptions, TopicDescriptor, TopicDescriptorOptions, TopicDescriptorProvider, TopicMessage, TopicMessageSchema, TopicProvider, TopicTimeoutError, TopicWaitOptions, UnSubscribeFn };
170
+ export { $subscriber, $topic, AlephaTopic, MemoryTopicProvider, SubscribeCallback, SubscriberDescriptor, SubscriberDescriptorOptions, TopicDescriptor, TopicDescriptorOptions, TopicHandler, TopicMessage, TopicMessageSchema, TopicProvider, TopicTimeoutError, TopicWaitOptions, UnSubscribeFn };
218
171
  //# sourceMappingURL=index.d.ts.map