@orion-js/migrations 4.0.0-alpha.2 → 4.0.0-alpha.3

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.
Files changed (4) hide show
  1. package/dist/index.cjs +110607 -110634
  2. package/dist/index.d.ts +112 -112
  3. package/dist/index.js +110281 -110308
  4. package/package.json +1 -2
package/dist/index.d.ts CHANGED
@@ -3,110 +3,11 @@
3
3
  import * as MongoDB from 'mongodb';
4
4
  import { Db, MongoClient } from 'mongodb';
5
5
 
6
- export interface Options {
7
- lockTime?: number;
8
- omitJob?: boolean;
9
- }
10
- export declare function loadMigrations(migrationServices: any[], options?: Options): MigrationExecutable[];
11
- export type Blackbox = {
12
- [name: string]: any;
13
- };
14
- export type LogFunction = (message: string, metadata?: any) => void;
15
- export interface OrionLogger {
16
- debug: LogFunction;
17
- info: LogFunction;
18
- warn: LogFunction;
19
- error: LogFunction;
20
- addContext: (module: NodeJS.Module) => OrionLogger;
21
- addMetadata: (metadata: any) => OrionLogger;
22
- }
23
- export interface JobToRun {
24
- jobId: string;
25
- executionId: string;
26
- name: string;
27
- type: "event" | "recurrent";
28
- params: Blackbox;
29
- tries: number;
30
- lockTime: number;
31
- priority: number;
32
- uniqueIdentifier?: string;
33
- }
34
- export interface ExecutionContext {
35
- record: JobToRun;
36
- definition: JobDefinition;
37
- tries: number;
38
- logger: OrionLogger;
39
- extendLockTime: (extraTime: number) => Promise<void>;
40
- clearStaleTimeout: () => void;
41
- }
42
- export interface JobRetryResultBase {
43
- action: "retry" | "dismiss";
44
- }
45
- export type JobRetryResultRunIn = JobRetryResultBase & {
46
- runIn: number;
47
- };
48
- export type JobRetryResultRunAt = JobRetryResultBase & {
49
- runAt: Date;
50
- };
51
- export type JobRetryResult = JobRetryResultRunIn | JobRetryResultRunAt | JobRetryResultBase;
52
- export interface BaseJobDefinition {
53
- /**
54
- * The function to execute when the job is executed.
55
- */
56
- resolve: (params: Blackbox, context: ExecutionContext) => Promise<Blackbox | void>;
57
- /**
58
- * Called if the job fails.
59
- */
60
- onError?: (error: Error, params: Blackbox, context: ExecutionContext) => Promise<JobRetryResult>;
61
- /**
62
- * Called if the job locktime is expired. The job will be executed again.
63
- */
64
- onStale?: (params: Blackbox, context: ExecutionContext) => Promise<void>;
65
- /**
66
- * Save the executions of the job time in milliseconds. Default is 1 week. Set to 0 to disable.
67
- */
68
- saveExecutionsFor?: number;
69
- }
70
- export interface RecurrentJobDefinition extends BaseJobDefinition {
71
- /**
72
- * Type of the job.
73
- */
74
- type: "recurrent";
75
- /**
76
- * A function executed after each execution that returns the date of the next run.
77
- */
78
- getNextRun?: () => Date;
79
- /**
80
- * Run every x milliseconds. This will be ignored if getNextRun is defined.
81
- */
82
- runEvery?: number;
83
- /**
84
- * The priority of the job. Higher is more priority. Default is 100.
85
- */
86
- priority?: number;
87
- }
88
- export interface EventJobDefinition extends BaseJobDefinition {
89
- /**
90
- * Type of the job.
91
- */
92
- type: "event";
93
- }
94
- export type JobDefinition = RecurrentJobDefinition | EventJobDefinition;
95
- export interface MigrationServiceOptions {
6
+ export type MigrationId = `scnmg-${string}`;
7
+ export declare class MigrationSchema {
8
+ _id: MigrationId;
96
9
  name: string;
97
- useMongoTransactions: false;
98
- }
99
- export declare function MigrationService(options: MigrationServiceOptions): ClassDecorator;
100
- export type MigrationExecutable = {
101
- runMigration(context: ExecutionContext): Promise<void>;
102
- } & MigrationServiceOptions;
103
- export declare function getMigrationsFromServices(services: any[]): MigrationExecutable[];
104
- export declare class MigrationsService {
105
- private migrationsRepo;
106
- getNextMigration(migrationsList: MigrationExecutable[]): Promise<MigrationExecutable>;
107
- runMigrations(migrationsList: MigrationExecutable[], context: ExecutionContext): Promise<void>;
108
- runMigration(func: (context: ExecutionContext) => Promise<void>, context: ExecutionContext): Promise<void>;
109
- runAsTransaction(func: (context: ExecutionContext) => Promise<void>, context: ExecutionContext): Promise<void>;
10
+ completedAt: Date;
110
11
  }
111
12
  // Generated by dts-bundle-generator v9.5.1
112
13
  // Generated by dts-bundle-generator v9.5.1
@@ -136,7 +37,7 @@ export interface OrionCache {
136
37
  */
137
38
  invalidate(key: string): Promise<void> | void;
138
39
  }
139
- type Blackbox$1 = {
40
+ export type Blackbox = {
140
41
  [name: string]: any;
141
42
  };
142
43
  export type ModelResolverResolve = (item: any, params: any, viewer: any, info?: any) => Promise<any>;
@@ -145,7 +46,7 @@ export type ModelCheckPermissions = (parent: any, params: any, viewer: any, info
145
46
  export type GlobalGetCacheKey = (params: any, viewer: any, info: any) => Promise<any>;
146
47
  export type ModelGetCacheKey = (parent: any, params: any, viewer: any, info: any) => Promise<any>;
147
48
  export interface ExecuteOptions {
148
- params: Blackbox$1;
49
+ params: Blackbox;
149
50
  viewer: any;
150
51
  parent?: any;
151
52
  info?: any;
@@ -584,7 +485,7 @@ export type UpdateMany<ModelClass extends ModelClassBase> = (selector: ModelToMo
584
485
  export type Upsert<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, modifier: ModelToUpdateFilter<ModelClass>, options?: UpdateOptions) => Promise<MongoDB.UpdateResult>;
585
486
  export type EstimatedDocumentCount<ModelClass extends ModelClassBase> = (options?: MongoDB.EstimatedDocumentCountOptions) => Promise<number>;
586
487
  export type CountDocuments<ModelClass extends ModelClassBase> = (selector: ModelToMongoSelector<ModelClass>, options?: MongoDB.CountDocumentsOptions) => Promise<number>;
587
- export interface Collection<ModelClass extends ModelClassBase = ModelClassBase> {
488
+ declare class Collection<ModelClass extends ModelClassBase = ModelClassBase> {
588
489
  name: string;
589
490
  connectionName?: string;
590
491
  schema?: Schema$1;
@@ -632,16 +533,115 @@ export interface Collection<ModelClass extends ModelClassBase = ModelClassBase>
632
533
  createIndexesPromise: Promise<string[]>;
633
534
  connectionPromise: Promise<MongoDB.MongoClient>;
634
535
  }
635
- export type MigrationId = `scnmg-${string}`;
636
- export declare class MigrationSchema {
637
- _id: MigrationId;
638
- name: string;
639
- completedAt: Date;
640
- }
641
536
  export declare class MigrationsRepo {
642
537
  collection: Collection<MigrationSchema>;
643
538
  getCompletedMigrationNames(): Promise<string[]>;
644
539
  saveCompletedMigration(name: string): Promise<void>;
645
540
  }
541
+ export interface Options {
542
+ lockTime?: number;
543
+ omitJob?: boolean;
544
+ }
545
+ export declare function loadMigrations(migrationServices: any[], options?: Options): MigrationExecutable[];
546
+ type Blackbox$1 = {
547
+ [name: string]: any;
548
+ };
549
+ export type LogFunction = (message: string, metadata?: any) => void;
550
+ export interface OrionLogger {
551
+ debug: LogFunction;
552
+ info: LogFunction;
553
+ warn: LogFunction;
554
+ error: LogFunction;
555
+ addContext: (module: NodeJS.Module) => OrionLogger;
556
+ addMetadata: (metadata: any) => OrionLogger;
557
+ }
558
+ export interface JobToRun {
559
+ jobId: string;
560
+ executionId: string;
561
+ name: string;
562
+ type: "event" | "recurrent";
563
+ params: Blackbox$1;
564
+ tries: number;
565
+ lockTime: number;
566
+ priority: number;
567
+ uniqueIdentifier?: string;
568
+ }
569
+ export interface ExecutionContext {
570
+ record: JobToRun;
571
+ definition: JobDefinition;
572
+ tries: number;
573
+ logger: OrionLogger;
574
+ extendLockTime: (extraTime: number) => Promise<void>;
575
+ clearStaleTimeout: () => void;
576
+ }
577
+ export interface JobRetryResultBase {
578
+ action: "retry" | "dismiss";
579
+ }
580
+ export type JobRetryResultRunIn = JobRetryResultBase & {
581
+ runIn: number;
582
+ };
583
+ export type JobRetryResultRunAt = JobRetryResultBase & {
584
+ runAt: Date;
585
+ };
586
+ export type JobRetryResult = JobRetryResultRunIn | JobRetryResultRunAt | JobRetryResultBase;
587
+ export interface BaseJobDefinition {
588
+ /**
589
+ * The function to execute when the job is executed.
590
+ */
591
+ resolve: (params: Blackbox$1, context: ExecutionContext) => Promise<Blackbox$1 | void>;
592
+ /**
593
+ * Called if the job fails.
594
+ */
595
+ onError?: (error: Error, params: Blackbox$1, context: ExecutionContext) => Promise<JobRetryResult>;
596
+ /**
597
+ * Called if the job locktime is expired. The job will be executed again.
598
+ */
599
+ onStale?: (params: Blackbox$1, context: ExecutionContext) => Promise<void>;
600
+ /**
601
+ * Save the executions of the job time in milliseconds. Default is 1 week. Set to 0 to disable.
602
+ */
603
+ saveExecutionsFor?: number;
604
+ }
605
+ export interface RecurrentJobDefinition extends BaseJobDefinition {
606
+ /**
607
+ * Type of the job.
608
+ */
609
+ type: "recurrent";
610
+ /**
611
+ * A function executed after each execution that returns the date of the next run.
612
+ */
613
+ getNextRun?: () => Date;
614
+ /**
615
+ * Run every x milliseconds. This will be ignored if getNextRun is defined.
616
+ */
617
+ runEvery?: number;
618
+ /**
619
+ * The priority of the job. Higher is more priority. Default is 100.
620
+ */
621
+ priority?: number;
622
+ }
623
+ export interface EventJobDefinition extends BaseJobDefinition {
624
+ /**
625
+ * Type of the job.
626
+ */
627
+ type: "event";
628
+ }
629
+ export type JobDefinition = RecurrentJobDefinition | EventJobDefinition;
630
+ export interface MigrationServiceOptions {
631
+ name: string;
632
+ useMongoTransactions: false;
633
+ }
634
+ export declare function MigrationService(options: MigrationServiceOptions): ClassDecorator;
635
+ export type MigrationExecutable = {
636
+ runMigration(context: ExecutionContext): Promise<void>;
637
+ } & MigrationServiceOptions;
638
+ export declare function getMigrationsFromServices(services: any[]): MigrationExecutable[];
639
+ export declare class MigrationsService {
640
+ private migrationsRepo;
641
+ getNextMigration(migrationsList: MigrationExecutable[]): Promise<MigrationExecutable>;
642
+ runMigrations(migrationsList: MigrationExecutable[], context: ExecutionContext): Promise<void>;
643
+ runMigration(func: (context: ExecutionContext) => Promise<void>, context: ExecutionContext): Promise<void>;
644
+ runAsTransaction(func: (context: ExecutionContext) => Promise<void>, context: ExecutionContext): Promise<void>;
645
+ }
646
646
 
647
647
  export {};