@storyous/mongodb 1.0.0

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 (46) hide show
  1. package/README.md +89 -0
  2. package/__tests__/appData.test.js +36 -0
  3. package/__tests__/appData.test.ts +39 -0
  4. package/__tests__/fixtures.test.js +40 -0
  5. package/__tests__/fixtures.test.ts +44 -0
  6. package/__tests__/getMongoClient.js +19 -0
  7. package/__tests__/getMongoClient.ts +24 -0
  8. package/__tests__/migrations/1642152064249-test.js +7 -0
  9. package/__tests__/migrations/1642152064249-test.ts +7 -0
  10. package/__tests__/mongoLocker.test.js +151 -0
  11. package/__tests__/mongoLocker.test.ts +191 -0
  12. package/__tests__/runMigration.test.js +22 -0
  13. package/__tests__/runMigration.test.ts +23 -0
  14. package/__tests__/withTransaction.test.js +40 -0
  15. package/__tests__/withTransaction.test.ts +67 -0
  16. package/lib/appData/index.js +40 -0
  17. package/lib/appData/index.ts +48 -0
  18. package/lib/concurrentTask.js +20 -0
  19. package/lib/concurrentTask.ts +30 -0
  20. package/lib/fixtures.js +28 -0
  21. package/lib/fixtures.ts +36 -0
  22. package/lib/getCollection.js +8 -0
  23. package/lib/getCollection.ts +4 -0
  24. package/lib/getMongoLocker.js +53 -0
  25. package/lib/getMongoLocker.ts +71 -0
  26. package/lib/index.js +27 -0
  27. package/lib/index.ts +25 -0
  28. package/lib/migrations/Migration.js +22 -0
  29. package/lib/migrations/Migration.ts +29 -0
  30. package/lib/migrations/MigrationsStore.js +65 -0
  31. package/lib/migrations/MigrationsStore.ts +73 -0
  32. package/lib/migrations/runMigrations.js +50 -0
  33. package/lib/migrations/runMigrations.ts +57 -0
  34. package/lib/migrations/template.js +7 -0
  35. package/lib/migrations/template.ts +6 -0
  36. package/lib/mongoClient.js +18 -0
  37. package/lib/mongoClient.ts +25 -0
  38. package/lib/mongoErrorCodes.js +11 -0
  39. package/lib/mongoErrorCodes.ts +10 -0
  40. package/lib/mongoLocker.js +17 -0
  41. package/lib/mongoLocker.ts +15 -0
  42. package/lib/withTransaction.js +21 -0
  43. package/lib/withTransaction.ts +24 -0
  44. package/package.json +40 -0
  45. package/tsconfig.json +14 -0
  46. package/types/migrate/index.d.ts +101 -0
@@ -0,0 +1,101 @@
1
+ /* eslint-disable max-classes-per-file, no-use-before-define, no-dupe-class-members */
2
+
3
+ // TODO: Copied from 'migrate' package from master branch.
4
+ // Types was not published yet. If will be released new version you can remove this file.
5
+
6
+ declare module 'migrate' {
7
+
8
+ import type { EventEmitter } from 'events';
9
+
10
+ type MigrationOptions = {
11
+ set?: MigrationSet;
12
+ stateStore?: string | FileStore;
13
+ migrationsDirectory?: string;
14
+ filterFunction?: (migration: string) => boolean;
15
+ sortFunction?: (migration1: Migration, migration2: Migration) => boolean;
16
+ };
17
+
18
+ type NextFunction = () => void;
19
+ type CallbackError = (err: any) => void;
20
+ type DoneCallback = (
21
+ err: any,
22
+ store: {
23
+ lastRun?: string;
24
+ migrations: Pick<Migration, 'title' | 'description' | 'timestamp'>[];
25
+ }
26
+ ) => void
27
+
28
+ export default function migrate(
29
+ title: string,
30
+ up: (next: NextFunction) => void,
31
+ down: (next: NextFunction) => void
32
+ ): void;
33
+
34
+ export function load(
35
+ opts: MigrationOptions,
36
+ cb: (err: any, set: MigrationSet) => void
37
+ ): void;
38
+
39
+ declare class Migration {
40
+ constructor(
41
+ title: string,
42
+ up: (next: NextFunction) => void,
43
+ down: (next: NextFunction) => void,
44
+ description: string
45
+ );
46
+
47
+ title: string;
48
+
49
+ up: (next: NextFunction) => void;
50
+
51
+ down: (next: NextFunction) => void;
52
+
53
+ description: string;
54
+
55
+ timestamp: number | null;
56
+ }
57
+
58
+ export class MigrationSet extends EventEmitter {
59
+ constructor(store: FileStore);
60
+
61
+ addMigration(
62
+ title: string,
63
+ up: (next: NextFunction) => void,
64
+ down: (next: NextFunction) => void
65
+ ): void;
66
+
67
+ addMigration(migration: Migration): void;
68
+
69
+ save(cb: CallbackError): void;
70
+
71
+ down(migrationName: string, cb: CallbackError): void;
72
+
73
+ down(cb: CallbackError): void;
74
+
75
+ up(migrationName: string, cb: CallbackError): void;
76
+
77
+ up(cb: CallbackError): void;
78
+
79
+ migrate(
80
+ direction: 'up' | 'down',
81
+ migrationName: string,
82
+ cb: CallbackError
83
+ ): void;
84
+
85
+ migrate(direction: 'up' | 'down', cb: CallbackError): void;
86
+
87
+ migrations: Migration[];
88
+
89
+ map: { [title: string]: Migration };
90
+
91
+ lastRun: string | null;
92
+ }
93
+
94
+ declare class FileStore {
95
+ constructor(path: string);
96
+
97
+ save(set: MigrationSet, cb: CallbackError): void;
98
+
99
+ load(cb: DoneCallback): void;
100
+ }
101
+ }