@orion-js/dogs 4.0.0-next.2 → 4.0.0-next.4

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/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
- import { Blackbox } from '@orion-js/schema';
1
+ import * as _orion_js_schema from '@orion-js/schema';
2
+ import { Blackbox, InferSchemaType } from '@orion-js/schema';
2
3
  import { OrionLogger } from '@orion-js/logger';
3
- import * as _orion_js_mongodb from '@orion-js/mongodb';
4
- import { ModelToDocumentTypeWithoutId } from '@orion-js/mongodb';
4
+ import { Collection, MongoDB } from '@orion-js/mongodb';
5
5
 
6
6
  interface ScheduleJobOptionsBase {
7
7
  name: string;
@@ -24,37 +24,104 @@ interface ScheduleJobRecordOptions {
24
24
  uniqueIdentifier?: string;
25
25
  }
26
26
 
27
- declare class HistoryRecord {
28
- _id: string;
29
- jobId: string;
30
- executionId: string;
31
- jobName: string;
32
- type: 'recurrent' | 'event';
33
- priority: number;
34
- tries: number;
35
- uniqueIdentifier?: string;
36
- startedAt: Date;
37
- endedAt: Date;
38
- duration: number;
39
- expiresAt?: Date;
40
- status: 'success' | 'error' | 'stale';
41
- errorMessage?: string;
42
- params?: Blackbox;
43
- result?: Blackbox;
44
- }
27
+ declare const HistoryRecordSchema: {
28
+ _id: {
29
+ type: "string";
30
+ };
31
+ jobId: {
32
+ type: "string";
33
+ };
34
+ executionId: {
35
+ type: "string";
36
+ };
37
+ jobName: {
38
+ type: "string";
39
+ };
40
+ type: {
41
+ type: "string";
42
+ };
43
+ priority: {
44
+ type: "number";
45
+ };
46
+ tries: {
47
+ type: "number";
48
+ };
49
+ uniqueIdentifier: {
50
+ type: "string";
51
+ optional: true;
52
+ };
53
+ startedAt: {
54
+ type: "date";
55
+ };
56
+ endedAt: {
57
+ type: "date";
58
+ };
59
+ duration: {
60
+ type: "number";
61
+ };
62
+ expiresAt: {
63
+ type: "date";
64
+ optional: true;
65
+ };
66
+ status: {
67
+ type: "string";
68
+ enum: string[];
69
+ };
70
+ errorMessage: {
71
+ type: "string";
72
+ optional: true;
73
+ };
74
+ params: {
75
+ type: "blackbox";
76
+ optional: true;
77
+ };
78
+ result: {
79
+ type: "blackbox";
80
+ optional: true;
81
+ };
82
+ };
83
+ type HistoryRecord = InferSchemaType<typeof HistoryRecordSchema>;
45
84
 
46
- declare class JobRecord {
47
- _id: string;
48
- jobName: string;
49
- type: 'recurrent' | 'event';
50
- priority: number;
51
- uniqueIdentifier?: string;
52
- nextRunAt: Date;
53
- lastRunAt?: Date;
54
- lockedUntil?: Date;
55
- tries?: number;
56
- params?: any;
57
- }
85
+ declare const JobRecordSchema: {
86
+ _id: {
87
+ type: "string";
88
+ };
89
+ jobName: {
90
+ type: "string";
91
+ };
92
+ type: {
93
+ type: _orion_js_schema.FieldType<"event" | "recurrent"> & {
94
+ type: "event" | "recurrent";
95
+ };
96
+ };
97
+ priority: {
98
+ type: "number";
99
+ };
100
+ uniqueIdentifier: {
101
+ type: "string";
102
+ optional: true;
103
+ };
104
+ nextRunAt: {
105
+ type: "date";
106
+ };
107
+ lastRunAt: {
108
+ type: "date";
109
+ optional: true;
110
+ };
111
+ lockedUntil: {
112
+ type: "date";
113
+ optional: true;
114
+ };
115
+ tries: {
116
+ type: "number";
117
+ optional: true;
118
+ };
119
+ params: {
120
+ type: "blackbox";
121
+ optional: true;
122
+ };
123
+ };
124
+ type JobRecord = InferSchemaType<typeof JobRecordSchema>;
58
125
 
59
126
  interface JobToRun {
60
127
  jobId: string;
@@ -183,13 +250,13 @@ interface StartWorkersConfig {
183
250
  declare const defineJob: (options: JobDefinition) => JobDefinition;
184
251
 
185
252
  declare class JobsHistoryRepo {
186
- history: () => _orion_js_mongodb.Collection<HistoryRecord>;
187
- saveExecution(record: ModelToDocumentTypeWithoutId<HistoryRecord>): Promise<void>;
253
+ history: Collection<HistoryRecord>;
254
+ saveExecution(record: MongoDB.WithoutId<HistoryRecord>): Promise<void>;
188
255
  getExecutions(jobName: string, limit?: number, skip?: number): Promise<HistoryRecord[]>;
189
256
  }
190
257
 
191
258
  declare class JobsRepo {
192
- jobs: () => _orion_js_mongodb.Collection<JobRecord>;
259
+ jobs: Collection<JobRecord>;
193
260
  getJobAndLock(jobNames: string[], lockTime: number): Promise<JobToRun>;
194
261
  setJobRecordPriority(jobId: string, priority: number): Promise<void>;
195
262
  scheduleNextRun(options: {
@@ -204,12 +271,9 @@ declare class JobsRepo {
204
271
  scheduleJob(options: ScheduleJobRecordOptions): Promise<void>;
205
272
  }
206
273
 
207
- declare function Jobs(): ClassDecorator;
208
- interface JobsPropertyDescriptor extends Omit<PropertyDecorator, 'value'> {
209
- value?: JobDefinition['resolve'];
210
- }
211
- declare function RecurrentJob(options: Omit<RecurrentJobDefinition, 'resolve' | 'type'>): (target: any, propertyKey: string, descriptor: JobsPropertyDescriptor) => void;
212
- declare function EventJob(options?: Omit<EventJobDefinition, 'resolve' | 'type'>): (target: any, propertyKey: string, descriptor: JobsPropertyDescriptor) => void;
274
+ declare function Jobs(): (target: any, context: ClassDecoratorContext<any>) => void;
275
+ declare function RecurrentJob<This, TArgs extends any[], TReturn extends any>(options?: Omit<RecurrentJobDefinition, 'resolve' | 'type'>): (method: (this: This, ...args: TArgs) => TReturn, context: ClassMethodDecoratorContext<This, typeof method>) => (this: This, ...args: TArgs) => TReturn;
276
+ declare function EventJob<This, TArgs extends any[], TReturn extends any>(options?: Omit<EventJobDefinition, 'resolve' | 'type'>): (method: (this: This, ...args: TArgs) => TReturn, context: ClassMethodDecoratorContext<This, typeof method>) => (this: This, ...args: TArgs) => TReturn;
213
277
  declare function getServiceJobs(target: any): {
214
278
  [key: string]: JobDefinition;
215
279
  };
@@ -219,4 +283,4 @@ declare const jobsRepo: JobsRepo;
219
283
  declare const startWorkers: (config: Partial<StartWorkersConfig>) => WorkersInstance;
220
284
  declare const scheduleJob: (options: ScheduleJobOptions) => Promise<void>;
221
285
 
222
- export { type BaseJobDefinition, EventJob, type EventJobDefinition, type ExecutionContext, HistoryRecord, type JobDefinition, type JobDefinitionWithName, JobRecord, type JobRetryResult, type JobRetryResultBase, type JobRetryResultRunAt, type JobRetryResultRunIn, type JobToRun, Jobs, type JobsDefinition, type JobsPropertyDescriptor, type LogLevels, RecurrentJob, type RecurrentJobDefinition, type ScheduleJobOptions, type ScheduleJobOptionsBase, type ScheduleJobOptionsRunAt, type ScheduleJobOptionsRunIn, type ScheduleJobRecordOptions, type StartWorkersConfig, type WorkerInstance, type WorkersInstance, defineJob, getServiceJobs, jobsHistoryRepo, jobsRepo, scheduleJob, startWorkers };
286
+ export { type BaseJobDefinition, EventJob, type EventJobDefinition, type ExecutionContext, type HistoryRecord, HistoryRecordSchema, type JobDefinition, type JobDefinitionWithName, type JobRecord, JobRecordSchema, type JobRetryResult, type JobRetryResultBase, type JobRetryResultRunAt, type JobRetryResultRunIn, type JobToRun, Jobs, type JobsDefinition, type LogLevels, RecurrentJob, type RecurrentJobDefinition, type ScheduleJobOptions, type ScheduleJobOptionsBase, type ScheduleJobOptionsRunAt, type ScheduleJobOptionsRunIn, type ScheduleJobRecordOptions, type StartWorkersConfig, type WorkerInstance, type WorkersInstance, defineJob, getServiceJobs, jobsHistoryRepo, jobsRepo, scheduleJob, startWorkers };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { Blackbox } from '@orion-js/schema';
1
+ import * as _orion_js_schema from '@orion-js/schema';
2
+ import { Blackbox, InferSchemaType } from '@orion-js/schema';
2
3
  import { OrionLogger } from '@orion-js/logger';
3
- import * as _orion_js_mongodb from '@orion-js/mongodb';
4
- import { ModelToDocumentTypeWithoutId } from '@orion-js/mongodb';
4
+ import { Collection, MongoDB } from '@orion-js/mongodb';
5
5
 
6
6
  interface ScheduleJobOptionsBase {
7
7
  name: string;
@@ -24,37 +24,104 @@ interface ScheduleJobRecordOptions {
24
24
  uniqueIdentifier?: string;
25
25
  }
26
26
 
27
- declare class HistoryRecord {
28
- _id: string;
29
- jobId: string;
30
- executionId: string;
31
- jobName: string;
32
- type: 'recurrent' | 'event';
33
- priority: number;
34
- tries: number;
35
- uniqueIdentifier?: string;
36
- startedAt: Date;
37
- endedAt: Date;
38
- duration: number;
39
- expiresAt?: Date;
40
- status: 'success' | 'error' | 'stale';
41
- errorMessage?: string;
42
- params?: Blackbox;
43
- result?: Blackbox;
44
- }
27
+ declare const HistoryRecordSchema: {
28
+ _id: {
29
+ type: "string";
30
+ };
31
+ jobId: {
32
+ type: "string";
33
+ };
34
+ executionId: {
35
+ type: "string";
36
+ };
37
+ jobName: {
38
+ type: "string";
39
+ };
40
+ type: {
41
+ type: "string";
42
+ };
43
+ priority: {
44
+ type: "number";
45
+ };
46
+ tries: {
47
+ type: "number";
48
+ };
49
+ uniqueIdentifier: {
50
+ type: "string";
51
+ optional: true;
52
+ };
53
+ startedAt: {
54
+ type: "date";
55
+ };
56
+ endedAt: {
57
+ type: "date";
58
+ };
59
+ duration: {
60
+ type: "number";
61
+ };
62
+ expiresAt: {
63
+ type: "date";
64
+ optional: true;
65
+ };
66
+ status: {
67
+ type: "string";
68
+ enum: string[];
69
+ };
70
+ errorMessage: {
71
+ type: "string";
72
+ optional: true;
73
+ };
74
+ params: {
75
+ type: "blackbox";
76
+ optional: true;
77
+ };
78
+ result: {
79
+ type: "blackbox";
80
+ optional: true;
81
+ };
82
+ };
83
+ type HistoryRecord = InferSchemaType<typeof HistoryRecordSchema>;
45
84
 
46
- declare class JobRecord {
47
- _id: string;
48
- jobName: string;
49
- type: 'recurrent' | 'event';
50
- priority: number;
51
- uniqueIdentifier?: string;
52
- nextRunAt: Date;
53
- lastRunAt?: Date;
54
- lockedUntil?: Date;
55
- tries?: number;
56
- params?: any;
57
- }
85
+ declare const JobRecordSchema: {
86
+ _id: {
87
+ type: "string";
88
+ };
89
+ jobName: {
90
+ type: "string";
91
+ };
92
+ type: {
93
+ type: _orion_js_schema.FieldType<"event" | "recurrent"> & {
94
+ type: "event" | "recurrent";
95
+ };
96
+ };
97
+ priority: {
98
+ type: "number";
99
+ };
100
+ uniqueIdentifier: {
101
+ type: "string";
102
+ optional: true;
103
+ };
104
+ nextRunAt: {
105
+ type: "date";
106
+ };
107
+ lastRunAt: {
108
+ type: "date";
109
+ optional: true;
110
+ };
111
+ lockedUntil: {
112
+ type: "date";
113
+ optional: true;
114
+ };
115
+ tries: {
116
+ type: "number";
117
+ optional: true;
118
+ };
119
+ params: {
120
+ type: "blackbox";
121
+ optional: true;
122
+ };
123
+ };
124
+ type JobRecord = InferSchemaType<typeof JobRecordSchema>;
58
125
 
59
126
  interface JobToRun {
60
127
  jobId: string;
@@ -183,13 +250,13 @@ interface StartWorkersConfig {
183
250
  declare const defineJob: (options: JobDefinition) => JobDefinition;
184
251
 
185
252
  declare class JobsHistoryRepo {
186
- history: () => _orion_js_mongodb.Collection<HistoryRecord>;
187
- saveExecution(record: ModelToDocumentTypeWithoutId<HistoryRecord>): Promise<void>;
253
+ history: Collection<HistoryRecord>;
254
+ saveExecution(record: MongoDB.WithoutId<HistoryRecord>): Promise<void>;
188
255
  getExecutions(jobName: string, limit?: number, skip?: number): Promise<HistoryRecord[]>;
189
256
  }
190
257
 
191
258
  declare class JobsRepo {
192
- jobs: () => _orion_js_mongodb.Collection<JobRecord>;
259
+ jobs: Collection<JobRecord>;
193
260
  getJobAndLock(jobNames: string[], lockTime: number): Promise<JobToRun>;
194
261
  setJobRecordPriority(jobId: string, priority: number): Promise<void>;
195
262
  scheduleNextRun(options: {
@@ -204,12 +271,9 @@ declare class JobsRepo {
204
271
  scheduleJob(options: ScheduleJobRecordOptions): Promise<void>;
205
272
  }
206
273
 
207
- declare function Jobs(): ClassDecorator;
208
- interface JobsPropertyDescriptor extends Omit<PropertyDecorator, 'value'> {
209
- value?: JobDefinition['resolve'];
210
- }
211
- declare function RecurrentJob(options: Omit<RecurrentJobDefinition, 'resolve' | 'type'>): (target: any, propertyKey: string, descriptor: JobsPropertyDescriptor) => void;
212
- declare function EventJob(options?: Omit<EventJobDefinition, 'resolve' | 'type'>): (target: any, propertyKey: string, descriptor: JobsPropertyDescriptor) => void;
274
+ declare function Jobs(): (target: any, context: ClassDecoratorContext<any>) => void;
275
+ declare function RecurrentJob<This, TArgs extends any[], TReturn extends any>(options?: Omit<RecurrentJobDefinition, 'resolve' | 'type'>): (method: (this: This, ...args: TArgs) => TReturn, context: ClassMethodDecoratorContext<This, typeof method>) => (this: This, ...args: TArgs) => TReturn;
276
+ declare function EventJob<This, TArgs extends any[], TReturn extends any>(options?: Omit<EventJobDefinition, 'resolve' | 'type'>): (method: (this: This, ...args: TArgs) => TReturn, context: ClassMethodDecoratorContext<This, typeof method>) => (this: This, ...args: TArgs) => TReturn;
213
277
  declare function getServiceJobs(target: any): {
214
278
  [key: string]: JobDefinition;
215
279
  };
@@ -219,4 +283,4 @@ declare const jobsRepo: JobsRepo;
219
283
  declare const startWorkers: (config: Partial<StartWorkersConfig>) => WorkersInstance;
220
284
  declare const scheduleJob: (options: ScheduleJobOptions) => Promise<void>;
221
285
 
222
- export { type BaseJobDefinition, EventJob, type EventJobDefinition, type ExecutionContext, HistoryRecord, type JobDefinition, type JobDefinitionWithName, JobRecord, type JobRetryResult, type JobRetryResultBase, type JobRetryResultRunAt, type JobRetryResultRunIn, type JobToRun, Jobs, type JobsDefinition, type JobsPropertyDescriptor, type LogLevels, RecurrentJob, type RecurrentJobDefinition, type ScheduleJobOptions, type ScheduleJobOptionsBase, type ScheduleJobOptionsRunAt, type ScheduleJobOptionsRunIn, type ScheduleJobRecordOptions, type StartWorkersConfig, type WorkerInstance, type WorkersInstance, defineJob, getServiceJobs, jobsHistoryRepo, jobsRepo, scheduleJob, startWorkers };
286
+ export { type BaseJobDefinition, EventJob, type EventJobDefinition, type ExecutionContext, type HistoryRecord, HistoryRecordSchema, type JobDefinition, type JobDefinitionWithName, type JobRecord, JobRecordSchema, type JobRetryResult, type JobRetryResultBase, type JobRetryResultRunAt, type JobRetryResultRunIn, type JobToRun, Jobs, type JobsDefinition, type LogLevels, RecurrentJob, type RecurrentJobDefinition, type ScheduleJobOptions, type ScheduleJobOptionsBase, type ScheduleJobOptionsRunAt, type ScheduleJobOptionsRunIn, type ScheduleJobRecordOptions, type StartWorkersConfig, type WorkerInstance, type WorkersInstance, defineJob, getServiceJobs, jobsHistoryRepo, jobsRepo, scheduleJob, startWorkers };