alepha 0.6.7 → 0.6.8

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,135 @@
1
- export * from '@alepha/redis';
1
+ import * as _alepha_core from '@alepha/core';
2
+ import { Static, Alepha } from '@alepha/core';
3
+ import * as Redis from 'ioredis';
4
+ import Redis__default from 'ioredis';
5
+
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
+ type StringFormatOption = 'date-time' | 'time' | 'date' | 'email' | 'idn-email' | 'hostname' | 'idn-hostname' | 'ipv4' | 'ipv6' | 'uri' | 'uri-reference' | 'iri' | 'uuid' | 'iri-reference' | 'uri-template' | 'json-pointer' | 'relative-json-pointer' | 'regex' | ({} & string);
16
+ type StringContentEncodingOption = '7bit' | '8bit' | 'binary' | 'quoted-printable' | 'base64' | ({} & string);
17
+ interface StringOptions extends SchemaOptions {
18
+ /** The maximum string length */
19
+ maxLength?: number;
20
+ /** The minimum string length */
21
+ minLength?: number;
22
+ /** A regular expression pattern this string should match */
23
+ pattern?: string;
24
+ /** A format this string should match */
25
+ format?: StringFormatOption;
26
+ /** The content encoding for this string */
27
+ contentEncoding?: StringContentEncodingOption;
28
+ /** The content media type for this string */
29
+ contentMediaType?: string;
30
+ }
31
+ interface TString extends TSchema, StringOptions {
32
+ [Kind]: 'String';
33
+ static: string;
34
+ type: 'string';
35
+ }
36
+
37
+ interface NumberOptions extends SchemaOptions {
38
+ exclusiveMaximum?: number;
39
+ exclusiveMinimum?: number;
40
+ maximum?: number;
41
+ minimum?: number;
42
+ multipleOf?: number;
43
+ }
44
+ interface TNumber extends TSchema, NumberOptions {
45
+ [Kind]: 'Number';
46
+ static: number;
47
+ type: 'number';
48
+ }
49
+
50
+ type TOptional<T extends TSchema> = T & {
51
+ [OptionalKind]: 'Optional';
52
+ };
53
+
54
+ interface SchemaOptions {
55
+ $schema?: string;
56
+ /** Id for this schema */
57
+ $id?: string;
58
+ /** Title of this schema */
59
+ title?: string;
60
+ /** Description of this schema */
61
+ description?: string;
62
+ /** Default value for this schema */
63
+ default?: any;
64
+ /** Example values matching this schema */
65
+ examples?: any;
66
+ /** Optional annotation for readOnly */
67
+ readOnly?: boolean;
68
+ /** Optional annotation for writeOnly */
69
+ writeOnly?: boolean;
70
+ [prop: string]: any;
71
+ }
72
+ interface TKind {
73
+ [Kind]: string;
74
+ }
75
+ interface TSchema extends TKind, SchemaOptions {
76
+ [ReadonlyKind]?: string;
77
+ [OptionalKind]?: string;
78
+ [Hint]?: string;
79
+ params: unknown[];
80
+ static: unknown;
81
+ }
82
+
83
+ declare const envSchema: _alepha_core.TObject<{
84
+ REDIS_PORT: TNumber;
85
+ REDIS_HOST: TString;
86
+ REDIS_PASSWORD: TOptional<TString>;
87
+ }>;
88
+ declare module "alepha" {
89
+ interface Env extends Partial<Static<typeof envSchema>> {
90
+ }
91
+ }
92
+ type RedisClient = Redis__default;
93
+ declare class RedisProvider {
94
+ protected readonly log: _alepha_core.Logger;
95
+ protected readonly alepha: Alepha;
96
+ protected readonly env: {
97
+ REDIS_PASSWORD?: string | undefined;
98
+ REDIS_PORT: number;
99
+ REDIS_HOST: string;
100
+ };
101
+ protected readonly client: Redis__default;
102
+ get publisher(): RedisClient;
103
+ protected readonly start: _alepha_core.HookDescriptor<"start">;
104
+ protected readonly stop: _alepha_core.HookDescriptor<"stop">;
105
+ /**
106
+ * Connect to the Redis server.
107
+ */
108
+ connect(): Promise<void>;
109
+ /**
110
+ * Close the connection to the Redis server.
111
+ */
112
+ close(): Promise<void>;
113
+ /**
114
+ * Redis subscriber client factory method.
115
+ */
116
+ protected createClient(): RedisClient;
117
+ }
118
+
119
+ declare class RedisSubscriberProvider {
120
+ protected readonly log: _alepha_core.Logger;
121
+ protected readonly alepha: Alepha;
122
+ protected readonly redisProvider: RedisProvider;
123
+ protected readonly client: Redis.default;
124
+ get subscriber(): RedisClient;
125
+ protected readonly start: _alepha_core.HookDescriptor<"start">;
126
+ protected readonly stop: _alepha_core.HookDescriptor<"stop">;
127
+ connect(): Promise<void>;
128
+ close(): void;
129
+ /**
130
+ * Redis subscriber client factory method.
131
+ */
132
+ protected createClient(): RedisClient;
133
+ }
134
+
135
+ export { type RedisClient, RedisProvider, RedisSubscriberProvider };
package/scheduler.d.ts CHANGED
@@ -1 +1,185 @@
1
- export * from '@alepha/scheduler';
1
+ import * as _alepha_core from '@alepha/core';
2
+ import { Async, KIND, OPTIONS, Static, Alepha } from '@alepha/core';
3
+ import { DurationLike, DateTimeProvider, Interval } from '@alepha/datetime';
4
+ import * as _alepha_lock from '@alepha/lock';
5
+ import { CronJob } from 'cron';
6
+
7
+ declare const KEY = "SCHEDULER";
8
+ type SchedulerDescriptorOptions = {
9
+ /**
10
+ * Function to run on schedule.
11
+ */
12
+ handler: () => Async<void>;
13
+ /**
14
+ * Name of the scheduler. Defaults to the function name.
15
+ */
16
+ name?: string;
17
+ /**
18
+ * Optional description of the scheduler.
19
+ */
20
+ description?: string;
21
+ /**
22
+ * Cron expression or interval to run the scheduler.
23
+ */
24
+ cron?: string;
25
+ /**
26
+ * Cron expression or interval to run the scheduler.
27
+ */
28
+ interval?: DurationLike;
29
+ /**
30
+ * If true, the scheduler will be locked and only one instance will run at a time.
31
+ * Defaults to true.
32
+ */
33
+ lock?: boolean;
34
+ };
35
+ interface SchedulerDescriptor {
36
+ [KIND]: typeof KEY;
37
+ [OPTIONS]: SchedulerDescriptorOptions;
38
+ (): Promise<void>;
39
+ }
40
+ /**
41
+ * Scheduler descriptor.
42
+ *
43
+ * @param options - The scheduler options.
44
+ * @returns The descriptor value.
45
+ */
46
+ declare const $scheduler: {
47
+ (options: SchedulerDescriptorOptions): SchedulerDescriptor;
48
+ [KIND]: string;
49
+ };
50
+ declare const isScheduler: (value: any) => value is SchedulerDescriptor;
51
+
52
+ /** Symbol key applied to readonly types */
53
+ declare const ReadonlyKind: unique symbol;
54
+ /** Symbol key applied to optional types */
55
+ declare const OptionalKind: unique symbol;
56
+ /** Symbol key applied to types */
57
+ declare const Hint: unique symbol;
58
+ /** Symbol key applied to types */
59
+ declare const Kind: unique symbol;
60
+
61
+ type StringFormatOption = 'date-time' | 'time' | 'date' | 'email' | 'idn-email' | 'hostname' | 'idn-hostname' | 'ipv4' | 'ipv6' | 'uri' | 'uri-reference' | 'iri' | 'uuid' | 'iri-reference' | 'uri-template' | 'json-pointer' | 'relative-json-pointer' | 'regex' | ({} & string);
62
+ type StringContentEncodingOption = '7bit' | '8bit' | 'binary' | 'quoted-printable' | 'base64' | ({} & string);
63
+ interface StringOptions extends SchemaOptions {
64
+ /** The maximum string length */
65
+ maxLength?: number;
66
+ /** The minimum string length */
67
+ minLength?: number;
68
+ /** A regular expression pattern this string should match */
69
+ pattern?: string;
70
+ /** A format this string should match */
71
+ format?: StringFormatOption;
72
+ /** The content encoding for this string */
73
+ contentEncoding?: StringContentEncodingOption;
74
+ /** The content media type for this string */
75
+ contentMediaType?: string;
76
+ }
77
+ interface TString extends TSchema, StringOptions {
78
+ [Kind]: 'String';
79
+ static: string;
80
+ type: 'string';
81
+ }
82
+
83
+ type TOptional<T extends TSchema> = T & {
84
+ [OptionalKind]: 'Optional';
85
+ };
86
+
87
+ interface SchemaOptions {
88
+ $schema?: string;
89
+ /** Id for this schema */
90
+ $id?: string;
91
+ /** Title of this schema */
92
+ title?: string;
93
+ /** Description of this schema */
94
+ description?: string;
95
+ /** Default value for this schema */
96
+ default?: any;
97
+ /** Example values matching this schema */
98
+ examples?: any;
99
+ /** Optional annotation for readOnly */
100
+ readOnly?: boolean;
101
+ /** Optional annotation for writeOnly */
102
+ writeOnly?: boolean;
103
+ [prop: string]: any;
104
+ }
105
+ interface TKind {
106
+ [Kind]: string;
107
+ }
108
+ interface TSchema extends TKind, SchemaOptions {
109
+ [ReadonlyKind]?: string;
110
+ [OptionalKind]?: string;
111
+ [Hint]?: string;
112
+ params: unknown[];
113
+ static: unknown;
114
+ }
115
+
116
+ declare const envSchema: _alepha_core.TObject<{
117
+ SCHEDULER_PREFIX: TOptional<TString>;
118
+ }>;
119
+ declare module "alepha" {
120
+ interface Env extends Partial<Static<typeof envSchema>> {
121
+ }
122
+ }
123
+ declare class SchedulerDescriptorProvider {
124
+ protected readonly log: _alepha_core.Logger;
125
+ protected readonly env: {
126
+ SCHEDULER_PREFIX?: string | undefined;
127
+ };
128
+ protected readonly alepha: Alepha;
129
+ protected readonly dateTimeProvider: DateTimeProvider;
130
+ protected readonly schedulers: Scheduler[];
131
+ protected readonly configure: _alepha_core.HookDescriptor<"configure">;
132
+ protected readonly start: _alepha_core.HookDescriptor<"start">;
133
+ protected readonly stop: _alepha_core.HookDescriptor<"stop">;
134
+ /**
135
+ * Get the schedulers.
136
+ */
137
+ getSchedulers(): Scheduler[];
138
+ /**
139
+ * Process scheduler descriptors.
140
+ *
141
+ * @protected
142
+ */
143
+ protected processSchedulerDescriptors(): void;
144
+ /**
145
+ * Create a scheduler.
146
+ *
147
+ * @param options - The scheduler options.
148
+ * @param instance - The instance of the scheduler.
149
+ * @param key - Property key name.
150
+ * @protected
151
+ */
152
+ protected createScheduler(options: SchedulerDescriptorOptions, instance: any, key: string): Scheduler;
153
+ trigger(name: string): Promise<void>;
154
+ protected runLock: _alepha_lock.LockDescriptor<(options: SchedulerDescriptorOptions & {
155
+ name: string;
156
+ }) => Promise<void>>;
157
+ protected run(options: SchedulerDescriptorOptions): Promise<void>;
158
+ /**
159
+ * Prefix the scheduler key.
160
+ *
161
+ * @param key
162
+ * @protected
163
+ */
164
+ protected prefix(key: string): string;
165
+ /**
166
+ *
167
+ * @param options
168
+ * @protected
169
+ */
170
+ protected getLockGracePeriod(options: SchedulerDescriptorOptions): number;
171
+ }
172
+ interface Scheduler {
173
+ name: string;
174
+ options: SchedulerDescriptorOptions;
175
+ trigger: () => Promise<void>;
176
+ cronJob?: CronJob;
177
+ interval?: Interval;
178
+ }
179
+
180
+ declare class SchedulerModule {
181
+ protected readonly alepha: Alepha;
182
+ constructor();
183
+ }
184
+
185
+ export { $scheduler, type Scheduler, type SchedulerDescriptor, type SchedulerDescriptorOptions, SchedulerDescriptorProvider, SchedulerModule, isScheduler };