alepha 0.11.4 → 0.11.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/redis.d.ts CHANGED
@@ -1 +1,82 @@
1
- export * from '@alepha/redis';
1
+ import * as _alepha_core3 from "alepha";
2
+ import { Alepha, Static } from "alepha";
3
+ import * as _alepha_logger0 from "alepha/logger";
4
+ import { RedisClientType, SetOptions, createClient } from "@redis/client";
5
+
6
+ //#region src/providers/RedisProvider.d.ts
7
+ declare const envSchema: _alepha_core3.TObject<{
8
+ REDIS_PORT: _alepha_core3.TInteger;
9
+ REDIS_HOST: _alepha_core3.TString;
10
+ REDIS_PASSWORD: _alepha_core3.TOptional<_alepha_core3.TString>;
11
+ }>;
12
+ declare module "alepha" {
13
+ interface Env extends Partial<Static<typeof envSchema>> {}
14
+ }
15
+ type RedisClient = RedisClientType<{}, {}, {}, 3, {
16
+ 36: BufferConstructor;
17
+ }>;
18
+ type RedisClientOptions = Parameters<typeof createClient>[0];
19
+ type RedisSetOptions = SetOptions;
20
+ /**
21
+ * Redis client provider.
22
+ */
23
+ declare class RedisProvider {
24
+ protected readonly log: _alepha_logger0.Logger;
25
+ protected readonly alepha: Alepha;
26
+ protected readonly env: {
27
+ REDIS_PASSWORD?: string | undefined;
28
+ REDIS_PORT: number;
29
+ REDIS_HOST: string;
30
+ };
31
+ protected readonly client: RedisClient;
32
+ get publisher(): RedisClient;
33
+ protected readonly start: _alepha_core3.HookDescriptor<"start">;
34
+ protected readonly stop: _alepha_core3.HookDescriptor<"stop">;
35
+ /**
36
+ * Connect to the Redis server.
37
+ */
38
+ connect(): Promise<void>;
39
+ /**
40
+ * Close the connection to the Redis server.
41
+ */
42
+ close(): Promise<void>;
43
+ duplicate(options?: Partial<RedisClientOptions>): RedisClient;
44
+ get(key: string): Promise<Buffer | undefined>;
45
+ set(key: string, value: Buffer | string, options?: RedisSetOptions): Promise<Buffer>;
46
+ has(key: string): Promise<boolean>;
47
+ keys(pattern: string): Promise<string[]>;
48
+ del(keys: string[]): Promise<void>;
49
+ /**
50
+ * Redis subscriber client factory method.
51
+ */
52
+ protected createClient(): RedisClient;
53
+ }
54
+ //#endregion
55
+ //#region src/providers/RedisSubscriberProvider.d.ts
56
+ declare class RedisSubscriberProvider {
57
+ protected readonly log: _alepha_logger0.Logger;
58
+ protected readonly alepha: Alepha;
59
+ protected readonly redisProvider: RedisProvider;
60
+ protected readonly client: RedisClient;
61
+ get subscriber(): RedisClient;
62
+ protected readonly start: _alepha_core3.HookDescriptor<"start">;
63
+ protected readonly stop: _alepha_core3.HookDescriptor<"stop">;
64
+ connect(): Promise<void>;
65
+ close(): Promise<void>;
66
+ /**
67
+ * Redis subscriber client factory method.
68
+ */
69
+ protected createClient(): RedisClient;
70
+ }
71
+ //#endregion
72
+ //#region src/index.d.ts
73
+ /**
74
+ * Redis client provider for Alepha applications.
75
+ *
76
+ * @see {@link RedisProvider}
77
+ * @module alepha.redis
78
+ */
79
+ declare const AlephaRedis: _alepha_core3.Service<_alepha_core3.Module<{}>>;
80
+ //#endregion
81
+ export { AlephaRedis, RedisClient, RedisClientOptions, RedisProvider, RedisSetOptions, RedisSubscriberProvider };
82
+ //# sourceMappingURL=index.d.ts.map
package/scheduler.d.ts CHANGED
@@ -1 +1,145 @@
1
- export * from '@alepha/scheduler';
1
+ import * as _alepha_core1 from "alepha";
2
+ import { Alepha, Async, Descriptor, KIND, Static } from "alepha";
3
+ import * as _alepha_lock0 from "alepha/lock";
4
+ import { DateTime, DateTimeProvider, DurationLike } from "alepha/datetime";
5
+ import * as _alepha_logger0 from "alepha/logger";
6
+ import * as dayjs0 from "dayjs";
7
+ import { Cron } from "cron-schedule";
8
+
9
+ //#region src/constants/CRON.d.ts
10
+ declare const CRON: {
11
+ EVERY_MINUTE: string;
12
+ EVERY_5_MINUTES: string;
13
+ EVERY_15_MINUTES: string;
14
+ EVERY_30_MINUTES: string;
15
+ EVERY_HOUR: string;
16
+ EVERY_DAY_AT_MIDNIGHT: string;
17
+ };
18
+ //#endregion
19
+ //#region src/providers/CronProvider.d.ts
20
+ declare class CronProvider {
21
+ protected readonly dt: DateTimeProvider;
22
+ protected readonly alepha: Alepha;
23
+ protected readonly log: _alepha_logger0.Logger;
24
+ protected readonly cronJobs: Array<CronJob>;
25
+ getCronJobs(): Array<CronJob>;
26
+ protected readonly start: _alepha_core1.HookDescriptor<"start">;
27
+ protected readonly stop: _alepha_core1.HookDescriptor<"stop">;
28
+ protected boot(name: string | CronJob): void;
29
+ abort(name: string | CronJob): void;
30
+ /**
31
+ * Registers a cron job.
32
+ *
33
+ * It's automatically done when using the `$scheduler` descriptor but can also be used manually.
34
+ */
35
+ createCronJob(name: string, expression: string, handler: (context: {
36
+ now: DateTime;
37
+ }) => Promise<void>, start?: boolean): void;
38
+ protected run(task: CronJob, now?: dayjs0.Dayjs): void;
39
+ }
40
+ interface CronJob {
41
+ name: string;
42
+ expression: string;
43
+ handler: (context: {
44
+ now: DateTime;
45
+ }) => Promise<void>;
46
+ cron: Cron;
47
+ loop: boolean;
48
+ running?: boolean;
49
+ onError?: (error: Error) => void;
50
+ abort: AbortController;
51
+ }
52
+ //#endregion
53
+ //#region src/descriptors/$scheduler.d.ts
54
+ /**
55
+ * Scheduler descriptor.
56
+ */
57
+ declare const $scheduler: {
58
+ (options: SchedulerDescriptorOptions): SchedulerDescriptor;
59
+ [KIND]: typeof SchedulerDescriptor;
60
+ };
61
+ type SchedulerDescriptorOptions = {
62
+ /**
63
+ * Function to run on schedule.
64
+ */
65
+ handler: (args: SchedulerHandlerArguments) => Async<void>;
66
+ /**
67
+ * Name of the scheduler. Defaults to the function name.
68
+ */
69
+ name?: string;
70
+ /**
71
+ * Optional description of the scheduler.
72
+ */
73
+ description?: string;
74
+ /**
75
+ * Cron expression or interval to run the scheduler.
76
+ */
77
+ cron?: string;
78
+ /**
79
+ * Cron expression or interval to run the scheduler.
80
+ */
81
+ interval?: DurationLike;
82
+ /**
83
+ * If true, the scheduler will be locked and only one instance will run at a time.
84
+ * You probably need to import {@link AlephaLockRedis} for distributed locking.
85
+ *
86
+ * @default true
87
+ */
88
+ lock?: boolean;
89
+ };
90
+ declare const envSchema: _alepha_core1.TObject<{
91
+ SCHEDULER_PREFIX: _alepha_core1.TOptional<_alepha_core1.TString>;
92
+ }>;
93
+ declare module "alepha" {
94
+ interface Env extends Partial<Static<typeof envSchema>> {}
95
+ }
96
+ declare class SchedulerDescriptor extends Descriptor<SchedulerDescriptorOptions> {
97
+ protected readonly log: _alepha_logger0.Logger;
98
+ protected readonly env: {
99
+ SCHEDULER_PREFIX?: string | undefined;
100
+ };
101
+ protected readonly alepha: Alepha;
102
+ protected readonly dateTimeProvider: DateTimeProvider;
103
+ protected readonly cronProvider: CronProvider;
104
+ get name(): string;
105
+ protected onInit(): void;
106
+ trigger(): Promise<void>;
107
+ protected schedulerLock: _alepha_lock0.LockDescriptor<(args: SchedulerHandlerArguments) => Promise<void>>;
108
+ }
109
+ interface SchedulerHandlerArguments {
110
+ now: DateTime;
111
+ }
112
+ //#endregion
113
+ //#region src/index.d.ts
114
+ declare module "alepha" {
115
+ interface Hooks {
116
+ "scheduler:begin": {
117
+ name: string;
118
+ now: DateTime;
119
+ context: string;
120
+ };
121
+ "scheduler:success": {
122
+ name: string;
123
+ context: string;
124
+ };
125
+ "scheduler:error": {
126
+ name: string;
127
+ error: Error;
128
+ context: string;
129
+ };
130
+ "scheduler:end": {
131
+ name: string;
132
+ context: string;
133
+ };
134
+ }
135
+ }
136
+ /**
137
+ * Generic interface for scheduling tasks.
138
+ *
139
+ * @see {@link $scheduler}
140
+ * @module alepha.scheduler
141
+ */
142
+ declare const AlephaScheduler: _alepha_core1.Service<_alepha_core1.Module<{}>>;
143
+ //#endregion
144
+ export { $scheduler, AlephaScheduler, CRON, CronJob, CronProvider, SchedulerDescriptor, SchedulerDescriptorOptions, SchedulerHandlerArguments };
145
+ //# sourceMappingURL=index.d.ts.map