alepha 0.7.3 → 0.7.5

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/queue.d.ts CHANGED
@@ -1,83 +1,38 @@
1
1
  import * as _alepha_core from '@alepha/core';
2
- import { TSchema as TSchema$1, KIND, OPTIONS, Static, Alepha } from '@alepha/core';
2
+ import { TSchema as TSchema$1, KIND, OPTIONS, Static, Alepha, Module } from '@alepha/core';
3
3
  import { DateTimeProvider } from '@alepha/datetime';
4
- import { RedisProvider } from '@alepha/redis';
5
4
 
6
- /** Symbol key applied to readonly types */
7
- declare const ReadonlyKind: unique symbol;
8
- /** Symbol key applied to optional types */
9
- declare const OptionalKind: unique symbol;
10
- /** Symbol key applied to types */
11
- declare const Hint: unique symbol;
12
- /** Symbol key applied to types */
13
- declare const Kind: unique symbol;
14
-
15
- interface TUnsafe<T> extends TSchema {
16
- [Kind]: string;
17
- static: T;
18
- }
19
-
20
- interface NumberOptions extends SchemaOptions {
21
- exclusiveMaximum?: number;
22
- exclusiveMinimum?: number;
23
- maximum?: number;
24
- minimum?: number;
25
- multipleOf?: number;
26
- }
27
- interface TNumber extends TSchema, NumberOptions {
28
- [Kind]: 'Number';
29
- static: number;
30
- type: 'number';
31
- }
32
-
33
- interface SchemaOptions {
34
- $schema?: string;
35
- /** Id for this schema */
36
- $id?: string;
37
- /** Title of this schema */
38
- title?: string;
39
- /** Description of this schema */
40
- description?: string;
41
- /** Default value for this schema */
42
- default?: any;
43
- /** Example values matching this schema */
44
- examples?: any;
45
- /** Optional annotation for readOnly */
46
- readOnly?: boolean;
47
- /** Optional annotation for writeOnly */
48
- writeOnly?: boolean;
49
- [prop: string]: any;
50
- }
51
- interface TKind {
52
- [Kind]: string;
53
- }
54
- interface TSchema extends TKind, SchemaOptions {
55
- [ReadonlyKind]?: string;
56
- [OptionalKind]?: string;
57
- [Hint]?: string;
58
- params: unknown[];
59
- static: unknown;
60
- }
61
-
62
- declare class QueueProvider {
63
- constructor();
5
+ /**
6
+ * Minimalist Queue interface.
7
+ *
8
+ * Will be probably enhanced in the future to support more advanced features. But for now, it's enough!
9
+ */
10
+ declare abstract class QueueProvider {
64
11
  /**
65
12
  * Push a message to the queue.
66
13
  *
67
- * @param queue - The queue name.
68
- * @param message - The message to push.
14
+ * @param queue Name of the queue to push the message to.
15
+ * @param message String message to be pushed to the queue. Buffer messages are not supported for now.
69
16
  */
70
- push(_queue: string, _message: string): Promise<void>;
17
+ abstract push(queue: string, message: string): Promise<void>;
71
18
  /**
72
19
  * Pop a message from the queue.
73
20
  *
74
- * @param queue - The queue name.
75
- * @returns The message popped.
21
+ * @param queue Name of the queue to pop the message from.
22
+ *
23
+ * @returns The message popped or `undefined` if the queue is empty.
76
24
  */
77
- pop(_queue: string): Promise<string | undefined>;
25
+ abstract pop(queue: string): Promise<string | undefined>;
78
26
  }
79
27
 
80
28
  declare const KEY$1 = "QUEUE";
29
+ /**
30
+ * Queue descriptor.
31
+ */
32
+ declare const $queue: {
33
+ <T extends QueueMessageSchema>(options: QueueDescriptorOptions<T>): QueueDescriptor<T>;
34
+ [KIND]: string;
35
+ };
81
36
  interface QueueMessageSchema {
82
37
  headers?: TSchema$1;
83
38
  payload: TSchema$1;
@@ -98,18 +53,15 @@ interface QueueDescriptor<T extends QueueMessageSchema = QueueMessageSchema> {
98
53
  provider(): QueueProvider;
99
54
  push(...payload: Array<Static<T["payload"]>>): Promise<void>;
100
55
  }
56
+
57
+ declare const KEY = "CONSUMER";
101
58
  /**
102
- * Queue descriptor.
103
- *
104
- * @param options - The queue options.
105
- * @returns The descriptor value.
59
+ * Consumer descriptor.
106
60
  */
107
- declare const $queue: {
108
- <T extends QueueMessageSchema>(options: QueueDescriptorOptions<T>): QueueDescriptor<T>;
61
+ declare const $consumer: {
62
+ <T extends QueueMessageSchema>(options: ConsumerDescriptorOptions<T>): ConsumerDescriptor<T>;
109
63
  [KIND]: string;
110
64
  };
111
-
112
- declare const KEY = "CONSUMER";
113
65
  interface ConsumerDescriptorOptions<T extends QueueMessageSchema = QueueMessageSchema> {
114
66
  queue: QueueDescriptor<T>;
115
67
  handler: (message: {
@@ -122,44 +74,66 @@ interface ConsumerDescriptor<T extends QueueMessageSchema = QueueMessageSchema>
122
74
  queue(): QueueDescriptor<T>;
123
75
  stop(): Promise<void>;
124
76
  }
125
- /**
126
- * Consumer descriptor.
127
- *
128
- * @param options - The consumer options.
129
- * @returns The descriptor value.
130
- */
131
- declare const $consumer: {
132
- <T extends QueueMessageSchema>(options: ConsumerDescriptorOptions<T>): ConsumerDescriptor<T>;
133
- [KIND]: string;
134
- };
135
77
 
136
78
  declare class MemoryQueueProvider implements QueueProvider {
137
- /**
138
- * The in-memory queue list.
139
- */
140
- protected queueList: Record<string, string[]>;
141
79
  protected readonly log: _alepha_core.Logger;
142
- /**
143
- * Push a message to a queue.
144
- * The message is added to the end of the queue.
145
- * The queue is created if it does not exist.
146
- *
147
- * @param queue - The queue to push to.
148
- * @param messages The messages to push.
149
- */
80
+ protected queueList: Record<string, string[]>;
150
81
  push(queue: string, ...messages: string[]): Promise<void>;
151
- /**
152
- * Pop a message from a queue.
153
- * The message is removed from the queue.
154
- * If the queue is empty, this method will return undefined.
155
- *
156
- * @param queue - The queue to pop from.
157
- * @returns The message that was popped from the queue.
158
- */
159
82
  pop(queue: string): Promise<string | undefined>;
160
83
  }
161
84
 
162
- declare const envSchema$1: _alepha_core.TObject<{
85
+ /** Symbol key applied to readonly types */
86
+ declare const ReadonlyKind: unique symbol;
87
+ /** Symbol key applied to optional types */
88
+ declare const OptionalKind: unique symbol;
89
+ /** Symbol key applied to types */
90
+ declare const Hint: unique symbol;
91
+ /** Symbol key applied to types */
92
+ declare const Kind: unique symbol;
93
+
94
+ interface NumberOptions extends SchemaOptions {
95
+ exclusiveMaximum?: number;
96
+ exclusiveMinimum?: number;
97
+ maximum?: number;
98
+ minimum?: number;
99
+ multipleOf?: number;
100
+ }
101
+ interface TNumber extends TSchema, NumberOptions {
102
+ [Kind]: 'Number';
103
+ static: number;
104
+ type: 'number';
105
+ }
106
+
107
+ interface SchemaOptions {
108
+ $schema?: string;
109
+ /** Id for this schema */
110
+ $id?: string;
111
+ /** Title of this schema */
112
+ title?: string;
113
+ /** Description of this schema */
114
+ description?: string;
115
+ /** Default value for this schema */
116
+ default?: any;
117
+ /** Example values matching this schema */
118
+ examples?: any;
119
+ /** Optional annotation for readOnly */
120
+ readOnly?: boolean;
121
+ /** Optional annotation for writeOnly */
122
+ writeOnly?: boolean;
123
+ [prop: string]: any;
124
+ }
125
+ interface TKind {
126
+ [Kind]: string;
127
+ }
128
+ interface TSchema extends TKind, SchemaOptions {
129
+ [ReadonlyKind]?: string;
130
+ [OptionalKind]?: string;
131
+ [Hint]?: string;
132
+ params: unknown[];
133
+ static: unknown;
134
+ }
135
+
136
+ declare const envSchema: _alepha_core.TObject<{
163
137
  /**
164
138
  * The interval in milliseconds to wait before checking for new messages.
165
139
  */
@@ -175,7 +149,7 @@ declare const envSchema$1: _alepha_core.TObject<{
175
149
  QUEUE_WORKER_CONCURRENCY: TNumber;
176
150
  }>;
177
151
  declare module "alepha" {
178
- interface Env extends Partial<Static<typeof envSchema$1>> {
152
+ interface Env extends Partial<Static<typeof envSchema>> {
179
153
  }
180
154
  }
181
155
  interface QueueDescriptorProviderState {
@@ -217,90 +191,63 @@ declare class QueueDescriptorProvider {
217
191
  protected processQueueDescriptors(): void;
218
192
  /**
219
193
  * Process the consumer descriptors.
220
- *
221
- * @protected
222
194
  */
223
195
  protected processConsumerDescriptors(): void;
196
+ /**
197
+ * Get the provider for the queue.
198
+ */
199
+ protected provider(options: QueueDescriptorOptions<any>): QueueProvider;
200
+ /**
201
+ * Push an item to the queue.
202
+ */
203
+ protected push<T extends QueueMessageSchema>(queue: QueueDescriptor<T>, ...payloads: Array<Static<T["payload"]>>): Promise<void>;
224
204
  /**
225
205
  * Start the workers.
226
- *
227
- * @param consumers
228
- * @protected
206
+ * This method will create an endless loop that will check for new messages!
229
207
  */
230
208
  protected startWorkers(consumers: Array<ConsumerDescriptorOptions>): void;
231
209
  /**
232
- * Wait for the next message.
210
+ * Wait for the next message, where `n` is the worker number.
233
211
  *
234
- * @param n
235
- * @protected
212
+ * This method will wait for a certain amount of time, increasing the wait time again if no message is found.
236
213
  */
237
214
  protected waitForNextMessage(n: number): Promise<void>;
238
215
  /**
239
216
  * Get the next message.
240
- *
241
- * @param consumers
242
- * @protected
243
217
  */
244
218
  protected getNextMessage(consumers: Array<ConsumerDescriptorOptions>): Promise<undefined | {
245
- message: any;
246
219
  consumer: ConsumerDescriptorOptions;
220
+ message: string;
247
221
  }>;
248
222
  /**
249
223
  * Process a message from a queue.
250
- *
251
- * @param response
252
- * @protected
253
224
  */
254
225
  protected processMessage(response: {
255
226
  message: any;
256
227
  consumer: ConsumerDescriptorOptions;
257
228
  }): Promise<void>;
258
229
  /**
259
- * Stop the workers
230
+ * Stop the workers.
260
231
  *
261
- * @protected
232
+ * This method will stop the workers and wait for them to finish processing.
262
233
  */
263
234
  protected stopWorkers(): Promise<void>;
264
- /**
265
- * Get the provider for the queue.
266
- *
267
- * @param options - The queue options.
268
- * @protected
269
- */
270
- protected provider(options: QueueDescriptorOptions<any>): QueueProvider;
271
- /**
272
- * Push an item to the queue.
273
- *
274
- * @param queue
275
- * @param payloads
276
- * @protected
277
- */
278
- protected push<T extends QueueMessageSchema>(queue: QueueDescriptor<T>, ...payloads: Array<Static<T["payload"]>>): Promise<void>;
279
- }
280
-
281
- declare class RedisQueueProvider implements QueueProvider {
282
- protected readonly env: {
283
- REDIS_QUEUE_PREFIX: string;
284
- };
285
- protected readonly redisProvider: RedisProvider;
286
- prefix(queue: string): string;
287
- push(queue: string, message: string): Promise<void>;
288
- pop(queue: string): Promise<string | undefined>;
289
235
  }
290
236
 
291
- declare const envSchema: _alepha_core.TObject<{
292
- QUEUE_PROVIDER: TUnsafe<"memory" | "redis">;
293
- }>;
294
- declare module "alepha/core" {
295
- interface Env extends Partial<Static<typeof envSchema>> {
296
- }
297
- }
298
- declare class QueueModule {
299
- protected readonly alepha: Alepha;
300
- protected readonly env: {
301
- QUEUE_PROVIDER: "memory" | "redis";
302
- };
303
- constructor();
237
+ /**
238
+ * Alepha Queue Module
239
+ *
240
+ * Generic interface for queueing.
241
+ * Gives you the ability to create queues and consumers.
242
+ * This module provides only a memory implementation of the queue provider.
243
+ *
244
+ * @see {@link $queue}
245
+ * @see {@link $consumer}
246
+ * @module alepha.queue
247
+ */
248
+ declare class AlephaQueue implements Module {
249
+ readonly name = "alepha.queue";
250
+ readonly $services: (alepha: Alepha) => Alepha;
304
251
  }
305
252
 
306
- export { $consumer, $queue, type ConsumerDescriptor, type ConsumerDescriptorOptions, MemoryQueueProvider, type QueueDescriptor, type QueueDescriptorOptions, QueueDescriptorProvider, type QueueDescriptorProviderState, type QueueMessageSchema, QueueModule, QueueProvider, RedisQueueProvider };
253
+ export { $consumer, $queue, AlephaQueue, type ConsumerDescriptor, type ConsumerDescriptorOptions, MemoryQueueProvider, type QueueDescriptor, type QueueDescriptorOptions, QueueDescriptorProvider, type QueueDescriptorProviderState, type QueueMessageSchema, QueueProvider };
package/react/auth.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _alepha_core from '@alepha/core';
2
- import { Async, KIND, OPTIONS, Alepha } from '@alepha/core';
2
+ import { Async, KIND, OPTIONS, Alepha, Module } from '@alepha/core';
3
3
  import { UserAccountToken } from '@alepha/security';
4
4
  import * as _alepha_server from '@alepha/server';
5
5
  import { HttpVirtualClient, HttpClient } from '@alepha/server';
@@ -142,6 +142,7 @@ interface AuthDescriptorOptions {
142
142
  clientSecret?: string;
143
143
  redirectUri?: string;
144
144
  useIdToken?: boolean;
145
+ logoutUri?: string;
145
146
  };
146
147
  }
147
148
  interface AuthDescriptor {
@@ -236,6 +237,7 @@ declare class ReactAuthProvider {
236
237
  redirectUri: string;
237
238
  fallback?: () => Async<AccessToken>;
238
239
  useIdToken?: boolean;
240
+ logoutUri?: string;
239
241
  }>;
240
242
  /**
241
243
  *
@@ -261,6 +263,7 @@ interface AuthProvider {
261
263
  };
262
264
  fallback?: () => Async<AccessToken>;
263
265
  useIdToken?: boolean;
266
+ logoutUri?: string;
264
267
  }
265
268
  interface ReactUser {
266
269
  id: string;
@@ -300,9 +303,17 @@ declare module "alepha/react" {
300
303
  user?: ReactUser;
301
304
  }
302
305
  }
303
- declare class ReactAuthModule {
304
- protected readonly alepha: Alepha;
305
- constructor();
306
+ /**
307
+ * Alepha React Authentication Module
308
+ *
309
+ * The ReactAuthModule provides authentication services for React applications.
310
+ *
311
+ * @see {@link ReactAuthProvider}
312
+ * @module alepha.react.auth
313
+ */
314
+ declare class AlephaReactAuth implements Module {
315
+ readonly name = "alepha.react.auth";
316
+ readonly $services: (alepha: Alepha) => void;
306
317
  }
307
318
 
308
- export { $auth, type AccessToken, type AuthDescriptor, type AuthDescriptorOptions, type AuthHook, type AuthProvider, ReactAuth, ReactAuthModule, ReactAuthProvider, type ReactUser, type SessionTokens, useAuth };
319
+ export { $auth, type AccessToken, AlephaReactAuth, type AuthDescriptor, type AuthDescriptorOptions, type AuthHook, type AuthProvider, ReactAuth, ReactAuthProvider, type ReactUser, type SessionTokens, useAuth };