@vnejs/plugins.save.auto 0.1.2 → 0.1.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.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/modules/autosave.d.ts +14 -0
- package/dist/modules/autosave.js +25 -0
- package/dist/types.d.ts +9 -0
- package/dist/types.js +1 -0
- package/package.json +41 -6
- package/src/index.ts +6 -0
- package/src/modules/autosave.ts +39 -0
- package/src/types.ts +17 -0
- package/tsconfig.json +9 -0
- package/const/const.js +0 -0
- package/const/events.js +0 -3
- package/const/params.js +0 -3
- package/const/settings.js +0 -3
- package/index.js +0 -9
- package/modules/autosave.js +0 -35
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { regPlugin } from "@vnejs/shared";
|
|
2
|
+
import { PARAMS, PLUGIN_NAME, SETTINGS_KEYS, SUBSCRIBE_EVENTS } from "@vnejs/plugins.save.auto.contract";
|
|
3
|
+
import { SaveAuto } from "./modules/autosave.js";
|
|
4
|
+
regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS, settings: SETTINGS_KEYS }, [SaveAuto]);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "@vnejs/plugins.save.auto.contract";
|
|
2
|
+
import "@vnejs/plugins.scenario.fastforward.contract";
|
|
3
|
+
import { Module } from "@vnejs/module";
|
|
4
|
+
import type { SaveAutoMakePayload } from "@vnejs/plugins.save.auto.contract";
|
|
5
|
+
import type { SaveAutoPluginConstants, SaveAutoPluginEvents, SaveAutoPluginParams, SaveAutoPluginSettings } from "../types.js";
|
|
6
|
+
export declare class SaveAuto extends Module<SaveAutoPluginEvents, SaveAutoPluginConstants, SaveAutoPluginSettings, SaveAutoPluginParams> {
|
|
7
|
+
name: string;
|
|
8
|
+
lastTs: number;
|
|
9
|
+
index: number;
|
|
10
|
+
subscribe: () => void;
|
|
11
|
+
init: () => Promise<[unknown[] | undefined, unknown[] | undefined]>;
|
|
12
|
+
onLineExec: () => Promise<unknown[]> | undefined;
|
|
13
|
+
onMake: ({ isForce }?: SaveAutoMakePayload) => Promise<unknown[]> | undefined;
|
|
14
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import "@vnejs/plugins.save.auto.contract";
|
|
2
|
+
import "@vnejs/plugins.scenario.fastforward.contract";
|
|
3
|
+
import { Module } from "@vnejs/module";
|
|
4
|
+
export class SaveAuto extends Module {
|
|
5
|
+
name = "save.auto";
|
|
6
|
+
lastTs = -1;
|
|
7
|
+
index = -1;
|
|
8
|
+
subscribe = () => {
|
|
9
|
+
this.on(this.EVENTS.SAVE_AUTO.MAKE, this.onMake);
|
|
10
|
+
};
|
|
11
|
+
init = () => Promise.all([
|
|
12
|
+
this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.SAVE_AUTO.INTERVAL, value: this.PARAMS.SAVE_AUTO.DEFAULT_INTERVAL }),
|
|
13
|
+
this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineExec }),
|
|
14
|
+
]);
|
|
15
|
+
onLineExec = () => this.emit(this.EVENTS.SAVE_AUTO.MAKE);
|
|
16
|
+
onMake = ({ isForce = false } = {}) => {
|
|
17
|
+
const ts = new Date().getTime();
|
|
18
|
+
const autosaveInterval = this.shared.settings[this.SETTINGS.SAVE_AUTO.INTERVAL];
|
|
19
|
+
if (!isForce && (this.shared.isFastforwardOn || ts - this.lastTs < autosaveInterval * 1000))
|
|
20
|
+
return;
|
|
21
|
+
this.lastTs = ts;
|
|
22
|
+
this.index = (this.index + 1) % this.PARAMS.SAVE_AUTO.MAX_INDEX;
|
|
23
|
+
return this.emit(this.EVENTS.SAVE.CREATE, { key: `auto-${this.index}` });
|
|
24
|
+
};
|
|
25
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry, VnePluginParamsMapRegistry, VnePluginSettingsMapRegistry } from "@vnejs/shared";
|
|
2
|
+
import type { PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/plugins.core.scenario.contract";
|
|
3
|
+
import type { PluginName as SettingsPluginName, SubscribeEvents as SettingsSubscribeEvents } from "@vnejs/plugins.core.settings.contract";
|
|
4
|
+
import type { PluginName as SavePluginName, SubscribeEvents as SaveSubscribeEvents } from "@vnejs/plugins.save.contract";
|
|
5
|
+
import type { Params, PluginName, SettingsKeys, SubscribeEvents } from "@vnejs/plugins.save.auto.contract";
|
|
6
|
+
export type SaveAutoPluginEvents = VnePluginEventsMapRegistry & Record<PluginName, SubscribeEvents> & Record<SavePluginName, SaveSubscribeEvents> & Record<ScenarioPluginName, ScenarioSubscribeEvents> & Record<SettingsPluginName, SettingsSubscribeEvents>;
|
|
7
|
+
export type SaveAutoPluginConstants = VnePluginConstantsMapRegistry;
|
|
8
|
+
export type SaveAutoPluginSettings = VnePluginSettingsMapRegistry & Record<PluginName, SettingsKeys>;
|
|
9
|
+
export type SaveAutoPluginParams = VnePluginParamsMapRegistry & Record<PluginName, Params>;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,17 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/plugins.save.auto",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src",
|
|
18
|
+
"tsconfig.json"
|
|
19
|
+
],
|
|
5
20
|
"scripts": {
|
|
6
21
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
22
|
+
"build": "npx @vnejs/monorepo package",
|
|
7
23
|
"publish:major:plugin": "npm run publish:major",
|
|
8
24
|
"publish:minor:plugin": "npm run publish:minor",
|
|
9
25
|
"publish:patch:plugin": "npm run publish:patch",
|
|
10
|
-
"publish:major": "
|
|
11
|
-
"publish:minor": "
|
|
12
|
-
"publish:patch": "
|
|
26
|
+
"publish:major": "npx @vnejs/monorepo publish major --access public",
|
|
27
|
+
"publish:minor": "npx @vnejs/monorepo publish minor --access public",
|
|
28
|
+
"publish:patch": "npx @vnejs/monorepo publish patch --access public"
|
|
13
29
|
},
|
|
14
30
|
"author": "",
|
|
15
31
|
"license": "ISC",
|
|
16
|
-
"
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@vnejs/plugins.save.auto.contract": "~0.0.1"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@vnejs/module": "~0.0.1",
|
|
37
|
+
"@vnejs/plugins.core.scenario.contract": "~0.0.1",
|
|
38
|
+
"@vnejs/plugins.core.settings.contract": "~0.0.1",
|
|
39
|
+
"@vnejs/plugins.save.contract": "~0.0.1",
|
|
40
|
+
"@vnejs/plugins.scenario.fastforward": "~0.1.0",
|
|
41
|
+
"@vnejs/shared": "~0.0.9"
|
|
42
|
+
},
|
|
43
|
+
"peerDependenciesMeta": {
|
|
44
|
+
"@vnejs/plugins.scenario.fastforward": {
|
|
45
|
+
"optional": true
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@vnejs/configs.ts-common": "~0.0.1",
|
|
50
|
+
"@vnejs/plugins.scenario.fastforward.contract": "~0.0.1"
|
|
51
|
+
}
|
|
17
52
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { regPlugin } from "@vnejs/shared";
|
|
2
|
+
import { PARAMS, PLUGIN_NAME, SETTINGS_KEYS, SUBSCRIBE_EVENTS } from "@vnejs/plugins.save.auto.contract";
|
|
3
|
+
|
|
4
|
+
import { SaveAuto } from "./modules/autosave.js";
|
|
5
|
+
|
|
6
|
+
regPlugin(PLUGIN_NAME, { events: SUBSCRIBE_EVENTS, params: PARAMS, settings: SETTINGS_KEYS }, [SaveAuto]);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import "@vnejs/plugins.save.auto.contract";
|
|
2
|
+
import "@vnejs/plugins.scenario.fastforward.contract";
|
|
3
|
+
|
|
4
|
+
import { Module } from "@vnejs/module";
|
|
5
|
+
import type { SaveAutoMakePayload } from "@vnejs/plugins.save.auto.contract";
|
|
6
|
+
import type { SaveCreatePayload } from "@vnejs/plugins.save.contract";
|
|
7
|
+
|
|
8
|
+
import type { SaveAutoPluginConstants, SaveAutoPluginEvents, SaveAutoPluginParams, SaveAutoPluginSettings } from "../types.js";
|
|
9
|
+
|
|
10
|
+
export class SaveAuto extends Module<SaveAutoPluginEvents, SaveAutoPluginConstants, SaveAutoPluginSettings, SaveAutoPluginParams> {
|
|
11
|
+
name = "save.auto";
|
|
12
|
+
|
|
13
|
+
lastTs = -1;
|
|
14
|
+
index = -1;
|
|
15
|
+
|
|
16
|
+
subscribe = () => {
|
|
17
|
+
this.on(this.EVENTS.SAVE_AUTO.MAKE, this.onMake);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
init = () =>
|
|
21
|
+
Promise.all([
|
|
22
|
+
this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.SAVE_AUTO.INTERVAL, value: this.PARAMS.SAVE_AUTO.DEFAULT_INTERVAL }),
|
|
23
|
+
this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: this.name, handler: this.onLineExec }),
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
onLineExec = () => this.emit(this.EVENTS.SAVE_AUTO.MAKE);
|
|
27
|
+
|
|
28
|
+
onMake = ({ isForce = false }: SaveAutoMakePayload = {}) => {
|
|
29
|
+
const ts = new Date().getTime();
|
|
30
|
+
const autosaveInterval = this.shared.settings[this.SETTINGS.SAVE_AUTO.INTERVAL];
|
|
31
|
+
|
|
32
|
+
if (!isForce && (this.shared.isFastforwardOn || ts - this.lastTs < autosaveInterval * 1000)) return;
|
|
33
|
+
|
|
34
|
+
this.lastTs = ts;
|
|
35
|
+
this.index = (this.index + 1) % this.PARAMS.SAVE_AUTO.MAX_INDEX;
|
|
36
|
+
|
|
37
|
+
return this.emit(this.EVENTS.SAVE.CREATE, { key: `auto-${this.index}` } satisfies SaveCreatePayload);
|
|
38
|
+
};
|
|
39
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { VnePluginConstantsMapRegistry, VnePluginEventsMapRegistry, VnePluginParamsMapRegistry, VnePluginSettingsMapRegistry } from "@vnejs/shared";
|
|
2
|
+
import type { PluginName as ScenarioPluginName, SubscribeEvents as ScenarioSubscribeEvents } from "@vnejs/plugins.core.scenario.contract";
|
|
3
|
+
import type { PluginName as SettingsPluginName, SubscribeEvents as SettingsSubscribeEvents } from "@vnejs/plugins.core.settings.contract";
|
|
4
|
+
import type { PluginName as SavePluginName, SubscribeEvents as SaveSubscribeEvents } from "@vnejs/plugins.save.contract";
|
|
5
|
+
import type { Params, PluginName, SettingsKeys, SubscribeEvents } from "@vnejs/plugins.save.auto.contract";
|
|
6
|
+
|
|
7
|
+
export type SaveAutoPluginEvents = VnePluginEventsMapRegistry &
|
|
8
|
+
Record<PluginName, SubscribeEvents> &
|
|
9
|
+
Record<SavePluginName, SaveSubscribeEvents> &
|
|
10
|
+
Record<ScenarioPluginName, ScenarioSubscribeEvents> &
|
|
11
|
+
Record<SettingsPluginName, SettingsSubscribeEvents>;
|
|
12
|
+
|
|
13
|
+
export type SaveAutoPluginConstants = VnePluginConstantsMapRegistry;
|
|
14
|
+
|
|
15
|
+
export type SaveAutoPluginSettings = VnePluginSettingsMapRegistry & Record<PluginName, SettingsKeys>;
|
|
16
|
+
|
|
17
|
+
export type SaveAutoPluginParams = VnePluginParamsMapRegistry & Record<PluginName, Params>;
|
package/tsconfig.json
ADDED
package/const/const.js
DELETED
|
File without changes
|
package/const/events.js
DELETED
package/const/params.js
DELETED
package/const/settings.js
DELETED
package/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { regPlugin } from "@vnejs/shared";
|
|
2
|
-
|
|
3
|
-
import { SUBSCRIBE_EVENTS } from "./const/events";
|
|
4
|
-
import * as params from "./const/params";
|
|
5
|
-
import { SETTINGS_KEYS } from "./const/settings";
|
|
6
|
-
|
|
7
|
-
import { Autosave } from "./modules/autosave";
|
|
8
|
-
|
|
9
|
-
regPlugin("SAVE_AUTO", { events: SUBSCRIBE_EVENTS, params, settings: SETTINGS_KEYS }, [Autosave]);
|
package/modules/autosave.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { Module } from "@vnejs/module";
|
|
2
|
-
|
|
3
|
-
export class Autosave extends Module {
|
|
4
|
-
name = "save.auto";
|
|
5
|
-
|
|
6
|
-
lastTs = -1;
|
|
7
|
-
index = -1;
|
|
8
|
-
|
|
9
|
-
subscribe = () => {
|
|
10
|
-
this.on(this.EVENTS.SAVE_AUTO.MAKE, this.onMake);
|
|
11
|
-
};
|
|
12
|
-
init = () =>
|
|
13
|
-
Promise.all([
|
|
14
|
-
this.emit(this.EVENTS.SETTINGS.INIT, { name: this.SETTINGS.SAVE_AUTO.INTERVAL, value: this.PARAMS.SAVE_AUTO.DEFAULT_INTERVAL }),
|
|
15
|
-
this.emit(this.EVENTS.SCENARIO.LINE_EXEC_REG, { module: "autosave", handler: this.onLineExec }),
|
|
16
|
-
]);
|
|
17
|
-
|
|
18
|
-
onLineExec = () => this.emit(this.EVENTS.SAVE_AUTO.MAKE);
|
|
19
|
-
|
|
20
|
-
onMake = async ({ isForce = false } = {}) => {
|
|
21
|
-
const [ts, autosaveInterval] = [new Date().getTime(), this.shared.settings[this.SETTINGS.SAVE_AUTO.INTERVAL]];
|
|
22
|
-
|
|
23
|
-
if (!isForce) if (this.shared.isFastforwardOn || ts - this.lastTs < autosaveInterval * 1000) return;
|
|
24
|
-
|
|
25
|
-
this.lastTs = ts;
|
|
26
|
-
|
|
27
|
-
this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { action: "start", index: this.index } });
|
|
28
|
-
|
|
29
|
-
this.index = (this.index + 1) % this.PARAMS.SAVE_AUTO.MAX_INDEX;
|
|
30
|
-
|
|
31
|
-
await this.emit(this.EVENTS.SAVE.CREATE, { key: `auto-${this.index}` });
|
|
32
|
-
|
|
33
|
-
this.emit(this.EVENTS.LOGS.EMIT, { module: this.name, value: { action: "end", index: this.index } });
|
|
34
|
-
};
|
|
35
|
-
}
|