@chromahq/core 0.0.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.
@@ -0,0 +1,109 @@
1
+ export { inject as Inject } from 'inversify';
2
+
3
+ declare const METADATA_KEY: {
4
+ PARAM_TYPES: string;
5
+ TYPE: string;
6
+ RETURN_TYPE: string;
7
+ };
8
+ declare const container: any;
9
+ declare const bind: <T>(id: symbol | (new (...a: any[]) => T), cls: new (...a: any[]) => T) => any;
10
+ declare const resolve: <T>(id: symbol | (new (...a: any[]) => T)) => T;
11
+ declare function isInjectable(target: any): boolean;
12
+
13
+ declare function create(): Promise<void>;
14
+
15
+ declare abstract class IMessage {
16
+ handle(...args: any[]): Promise<void> | void;
17
+ }
18
+ declare function Message(name: string): (constructor: any) => any;
19
+
20
+ declare function Injectable(): (constructor: new (...args: any[]) => any) => void;
21
+
22
+ declare abstract class Booteable {
23
+ /**
24
+ * Boot method to be called when the service is initialized.
25
+ * This method can be used to perform any setup or initialization logic.
26
+ */
27
+ abstract boot(): void;
28
+ /**
29
+ * Optional destroy method to be called when the service is being destroyed.
30
+ * This can be used to clean up resources or perform any necessary teardown logic.
31
+ */
32
+ destroy?(): void;
33
+ }
34
+ declare function isBooteable(obj: any): obj is Booteable;
35
+ declare function isDestroyable(obj: any): obj is Booteable;
36
+
37
+ interface JobOptions {
38
+ id?: string;
39
+ delay?: number;
40
+ cron?: string;
41
+ persistent?: boolean;
42
+ }
43
+
44
+ interface IJob<T = unknown> {
45
+ readonly data?: T;
46
+ handle(context?: JobContext): Promise<void> | void;
47
+ pause?(): Promise<void> | void;
48
+ resume?(): Promise<void> | void;
49
+ stop?(): Promise<void> | void;
50
+ }
51
+ declare enum JobState {
52
+ SCHEDULED = "scheduled",
53
+ RUNNING = "running",
54
+ PAUSED = "paused",
55
+ STOPPED = "stopped",
56
+ COMPLETED = "completed",
57
+ FAILED = "failed"
58
+ }
59
+ interface JobContext {
60
+ id: string;
61
+ options?: JobOptions;
62
+ state: JobState;
63
+ createdAt: Date;
64
+ updatedAt: Date;
65
+ startedAt?: Date;
66
+ pausedAt?: Date;
67
+ stoppedAt?: Date;
68
+ completedAt?: Date;
69
+ error?: Error;
70
+ retryCount?: number;
71
+ /**
72
+ * Pause the job execution.
73
+ * @returns Promise<void> | void
74
+ */
75
+ pause: () => Promise<void> | void;
76
+ resume: () => Promise<void> | void;
77
+ stop: () => Promise<void> | void;
78
+ complete: () => Promise<void> | void;
79
+ fail: (error: Error) => Promise<void> | void;
80
+ retry: () => Promise<void> | void;
81
+ isRunning: () => boolean;
82
+ isPaused: () => boolean;
83
+ isStopped: () => boolean;
84
+ isCompleted: () => boolean;
85
+ isFailed: () => boolean;
86
+ isRetrying: () => boolean;
87
+ isScheduled: () => boolean;
88
+ isDelayed: () => boolean;
89
+ isRecurring: () => boolean;
90
+ isCron: () => boolean;
91
+ isTimeout: () => boolean;
92
+ isAlarm: () => boolean;
93
+ }
94
+
95
+ declare abstract class Job<T = unknown> implements IJob<T> {
96
+ readonly data?: T | undefined;
97
+ constructor(data?: T | undefined);
98
+ abstract handle(context?: JobContext): Promise<void> | void;
99
+ pause?(): Promise<void> | void;
100
+ resume?(): Promise<void> | void;
101
+ stop?(): Promise<void> | void;
102
+ }
103
+
104
+ declare const Delay: (ms: number) => (constructor: any) => any;
105
+
106
+ declare function Every(cron: string): (constructor: any) => any;
107
+
108
+ export { Booteable, Delay, Every, IMessage, Injectable, Job, JobState, METADATA_KEY, Message, bind, container, create, isBooteable, isDestroyable, isInjectable, resolve };
109
+ export type { IJob, JobContext };