simple-backups 1.1.0 → 1.1.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.
- package/README.md +14 -0
- package/package.json +11 -3
- package/src/index.d.ts +79 -0
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ This package aims to simplify the task of automatically creating and pruning bac
|
|
|
16
16
|
## Features
|
|
17
17
|
- Simple-to-use API
|
|
18
18
|
- JSDoc Type Support
|
|
19
|
+
- TypeScript Type Definitions
|
|
19
20
|
- Automatic Backup Creation
|
|
20
21
|
- Multi-Window Backup Retention
|
|
21
22
|
- CPU & Memory Efficient
|
|
@@ -82,6 +83,19 @@ backups.on('error', (error) => {
|
|
|
82
83
|
});
|
|
83
84
|
```
|
|
84
85
|
|
|
86
|
+
## TypeScript
|
|
87
|
+
SimpleBackups includes first-party TypeScript declarations. No separate `@types` package is required.
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import {
|
|
91
|
+
SimpleBackups,
|
|
92
|
+
type Backup,
|
|
93
|
+
type BackupAdapters,
|
|
94
|
+
type BackupWindow,
|
|
95
|
+
type SimpleBackupsOptions
|
|
96
|
+
} from 'simple-backups';
|
|
97
|
+
```
|
|
98
|
+
|
|
85
99
|
## SimpleBackups
|
|
86
100
|
Below is a breakdown of the `SimpleBackups` class.
|
|
87
101
|
|
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simple-backups",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Simple yet unopinionated zero-dependency package to easily setup automatic backups for any data source that persists to any storage mechanism.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
|
+
"types": "./src/index.d.ts",
|
|
7
8
|
"exports": {
|
|
8
|
-
".":
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./src/index.d.ts",
|
|
11
|
+
"import": "./src/index.js",
|
|
12
|
+
"default": "./src/index.js"
|
|
13
|
+
}
|
|
9
14
|
},
|
|
10
15
|
"files": [
|
|
11
16
|
"src",
|
|
@@ -13,7 +18,7 @@
|
|
|
13
18
|
"LICENSE"
|
|
14
19
|
],
|
|
15
20
|
"scripts": {
|
|
16
|
-
"test": "node --test"
|
|
21
|
+
"test": "node --test && tsc --project tsconfig.json"
|
|
17
22
|
},
|
|
18
23
|
"keywords": [
|
|
19
24
|
"backup",
|
|
@@ -29,5 +34,8 @@
|
|
|
29
34
|
"license": "MIT",
|
|
30
35
|
"engines": {
|
|
31
36
|
"node": ">=20"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"typescript": "7.0.2"
|
|
32
40
|
}
|
|
33
41
|
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A backup managed by SimpleBackups.
|
|
3
|
+
*/
|
|
4
|
+
export interface Backup {
|
|
5
|
+
/** The unique identifier of the backup. */
|
|
6
|
+
id: string;
|
|
7
|
+
|
|
8
|
+
/** The timestamp at which the backup was created (in milliseconds). */
|
|
9
|
+
timestamp: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* A retention window used by SimpleBackups.
|
|
14
|
+
*/
|
|
15
|
+
export interface BackupWindow {
|
|
16
|
+
/** The width of each retention slot in this window (in milliseconds). */
|
|
17
|
+
interval_ms: number;
|
|
18
|
+
|
|
19
|
+
/** The maximum number of backups to keep in this window. */
|
|
20
|
+
limit: number;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Adapter methods used to persist backups in an upstream storage mechanism.
|
|
25
|
+
*/
|
|
26
|
+
export interface BackupAdapters {
|
|
27
|
+
/** Lists all backups from the upstream storage mechanism. */
|
|
28
|
+
list(): Backup[] | Promise<Backup[]>;
|
|
29
|
+
|
|
30
|
+
/** Creates and persists a new backup in the upstream storage mechanism. */
|
|
31
|
+
create(): Backup | Promise<Backup>;
|
|
32
|
+
|
|
33
|
+
/** Attempts to delete a backup and reports whether the deletion succeeded. */
|
|
34
|
+
delete(backup: Backup): boolean | Promise<boolean>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Options used to construct a SimpleBackups instance.
|
|
39
|
+
*/
|
|
40
|
+
export interface SimpleBackupsOptions {
|
|
41
|
+
/** The backup adapters to use. */
|
|
42
|
+
adapters: BackupAdapters;
|
|
43
|
+
|
|
44
|
+
/** The backup retention windows to maintain. */
|
|
45
|
+
windows: BackupWindow[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type SimpleBackupsBackupEvent = 'create' | 'delete';
|
|
49
|
+
export type SimpleBackupsErrorEvent = 'error';
|
|
50
|
+
export type SimpleBackupsBackupListener = (backup: Backup) => void;
|
|
51
|
+
export type SimpleBackupsErrorListener = (error: Error) => void;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Automatically creates and prunes backups using the configured adapters and retention windows.
|
|
55
|
+
*/
|
|
56
|
+
export class SimpleBackups {
|
|
57
|
+
constructor(options: SimpleBackupsOptions);
|
|
58
|
+
|
|
59
|
+
on(event: SimpleBackupsBackupEvent, listener: SimpleBackupsBackupListener): this;
|
|
60
|
+
on(event: SimpleBackupsErrorEvent, listener: SimpleBackupsErrorListener): this;
|
|
61
|
+
|
|
62
|
+
once(event: SimpleBackupsBackupEvent, listener: SimpleBackupsBackupListener): this;
|
|
63
|
+
once(event: SimpleBackupsErrorEvent, listener: SimpleBackupsErrorListener): this;
|
|
64
|
+
|
|
65
|
+
off(event: SimpleBackupsBackupEvent, listener: SimpleBackupsBackupListener): this;
|
|
66
|
+
off(event: SimpleBackupsErrorEvent, listener: SimpleBackupsErrorListener): this;
|
|
67
|
+
|
|
68
|
+
emit(event: SimpleBackupsBackupEvent, backup: Backup): boolean;
|
|
69
|
+
emit(event: SimpleBackupsErrorEvent, error: Error): boolean;
|
|
70
|
+
|
|
71
|
+
/** Destroys this instance, stops its internal interval and removes its event listeners. */
|
|
72
|
+
destroy(): void;
|
|
73
|
+
|
|
74
|
+
/** The current cached backups, returned as a new array. */
|
|
75
|
+
readonly backups: Backup[];
|
|
76
|
+
|
|
77
|
+
/** Whether this instance has been destroyed. */
|
|
78
|
+
readonly destroyed: boolean;
|
|
79
|
+
}
|