@powfix/core-js 0.9.22 → 0.9.24
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/.yarnrc +1 -0
- package/dist/src/services/time/TimeService.d.ts +14 -15
- package/dist/src/services/time/TimeService.js +22 -24
- package/dist/src/utils/Sequencer.d.ts +2 -3
- package/dist/src/utils/Sequencer.js +2 -2
- package/package.json +2 -1
- package/src/services/time/TimeService.ts +23 -23
- package/src/utils/Sequencer.ts +2 -2
package/.yarnrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
registry https://nexus.vhd.kr/repository/yarn-proxy/
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import EventEmitter3 from 'eventemitter3';
|
|
2
|
+
export declare enum TimeServiceStatus {
|
|
3
|
+
STOPPED = 0,
|
|
4
|
+
RUNNING = 1
|
|
5
|
+
}
|
|
6
|
+
export declare enum TimeServiceEvent {
|
|
7
|
+
SYNCED = "SYNCED",
|
|
8
|
+
SYNC_INTERVAL_CHANGED = "SYNC_INTERVAL_CHANGED"
|
|
9
|
+
}
|
|
3
10
|
export declare class TimeService {
|
|
4
|
-
|
|
11
|
+
private static readonly DEFAULT_SYNC_INTERVAL;
|
|
12
|
+
protected status: TimeServiceStatus;
|
|
5
13
|
private offset?;
|
|
6
14
|
private option;
|
|
7
15
|
private syncedAt?;
|
|
8
16
|
private emitter;
|
|
9
|
-
readonly on:
|
|
10
|
-
readonly off:
|
|
17
|
+
readonly on: <T extends string | symbol>(event: T, fn: (...args: any[]) => void, context?: any) => EventEmitter3<string | symbol, any>;
|
|
18
|
+
readonly off: <T extends string | symbol>(event: T, fn?: ((...args: any[]) => void) | undefined, context?: any, once?: boolean | undefined) => EventEmitter3<string | symbol, any>;
|
|
11
19
|
private readonly emit;
|
|
12
20
|
static calculateNTPResultOffset(ntpResult: TimeService.NTPResult): TimeService.Offset;
|
|
13
21
|
constructor(option: TimeService.Option);
|
|
@@ -25,7 +33,7 @@ export declare class TimeService {
|
|
|
25
33
|
getServerTime(): TimeService.TimeStamp | null;
|
|
26
34
|
getTime(): number;
|
|
27
35
|
private readonly fetchServerNTPResult;
|
|
28
|
-
getStatus():
|
|
36
|
+
getStatus(): TimeServiceStatus;
|
|
29
37
|
start(): void;
|
|
30
38
|
stop(): void;
|
|
31
39
|
sync(): Promise<TimeService.Offset | null>;
|
|
@@ -34,11 +42,6 @@ export declare class TimeService {
|
|
|
34
42
|
private stopSync;
|
|
35
43
|
}
|
|
36
44
|
export declare namespace TimeService {
|
|
37
|
-
const DEFAULT_SYNC_INTERVAL: number;
|
|
38
|
-
enum Status {
|
|
39
|
-
STOPPED = 0,
|
|
40
|
-
RUNNING = 1
|
|
41
|
-
}
|
|
42
45
|
type Offset = number;
|
|
43
46
|
type TimeStamp = number;
|
|
44
47
|
interface NTPResult {
|
|
@@ -57,8 +60,4 @@ export declare namespace TimeService {
|
|
|
57
60
|
clientTimeProvider?: ClientTimeProvider | undefined;
|
|
58
61
|
serverTimeProvider?: ServerTimeProvider | undefined;
|
|
59
62
|
}
|
|
60
|
-
enum EVENT {
|
|
61
|
-
SYNCED = "SYNCED",
|
|
62
|
-
SYNC_INTERVAL_CHANGED = "SYNC_INTERVAL_CHANGED"
|
|
63
|
-
}
|
|
64
63
|
}
|
|
@@ -12,18 +12,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.TimeService = void 0;
|
|
16
|
-
const
|
|
15
|
+
exports.TimeService = exports.TimeServiceEvent = exports.TimeServiceStatus = void 0;
|
|
16
|
+
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
17
17
|
const LOG_TAG = 'TimeService';
|
|
18
|
+
var TimeServiceStatus;
|
|
19
|
+
(function (TimeServiceStatus) {
|
|
20
|
+
TimeServiceStatus[TimeServiceStatus["STOPPED"] = 0] = "STOPPED";
|
|
21
|
+
TimeServiceStatus[TimeServiceStatus["RUNNING"] = 1] = "RUNNING";
|
|
22
|
+
})(TimeServiceStatus || (exports.TimeServiceStatus = TimeServiceStatus = {}));
|
|
23
|
+
var TimeServiceEvent;
|
|
24
|
+
(function (TimeServiceEvent) {
|
|
25
|
+
TimeServiceEvent["SYNCED"] = "SYNCED";
|
|
26
|
+
TimeServiceEvent["SYNC_INTERVAL_CHANGED"] = "SYNC_INTERVAL_CHANGED";
|
|
27
|
+
})(TimeServiceEvent || (exports.TimeServiceEvent = TimeServiceEvent = {}));
|
|
18
28
|
class TimeService {
|
|
19
29
|
static calculateNTPResultOffset(ntpResult) {
|
|
20
30
|
const { t1, t2, t3, t4 } = ntpResult;
|
|
21
31
|
return ((t2 - t1) + (t3 - t4)) / 2;
|
|
22
32
|
}
|
|
23
33
|
constructor(option) {
|
|
24
|
-
this.status =
|
|
34
|
+
this.status = TimeServiceStatus.STOPPED;
|
|
25
35
|
// Emitter
|
|
26
|
-
this.emitter = new
|
|
36
|
+
this.emitter = new eventemitter3_1.default();
|
|
27
37
|
this.on = this.emitter.on;
|
|
28
38
|
this.off = this.emitter.off;
|
|
29
39
|
this.emit = this.emitter.emit;
|
|
@@ -73,7 +83,7 @@ class TimeService {
|
|
|
73
83
|
setSyncedAt(syncedAt) {
|
|
74
84
|
this.syncedAt = syncedAt;
|
|
75
85
|
// Emit
|
|
76
|
-
this.emit(
|
|
86
|
+
this.emit(TimeServiceEvent.SYNCED, syncedAt);
|
|
77
87
|
return syncedAt;
|
|
78
88
|
}
|
|
79
89
|
getSyncInterval() {
|
|
@@ -90,8 +100,8 @@ class TimeService {
|
|
|
90
100
|
setSyncInterval(interval) {
|
|
91
101
|
this.option.syncInterval = interval;
|
|
92
102
|
// Emit
|
|
93
|
-
this.emit(
|
|
94
|
-
if (this.status ===
|
|
103
|
+
this.emit(TimeServiceEvent.SYNC_INTERVAL_CHANGED, interval);
|
|
104
|
+
if (this.status === TimeServiceStatus.RUNNING) {
|
|
95
105
|
if (this.syncHandler !== undefined) {
|
|
96
106
|
this.stopSync();
|
|
97
107
|
this.startSync();
|
|
@@ -124,24 +134,24 @@ class TimeService {
|
|
|
124
134
|
return this.status;
|
|
125
135
|
}
|
|
126
136
|
start() {
|
|
127
|
-
if (this.status !==
|
|
137
|
+
if (this.status !== TimeServiceStatus.STOPPED) {
|
|
128
138
|
console.warn(LOG_TAG, 'service is not stopped');
|
|
129
139
|
return;
|
|
130
140
|
}
|
|
131
141
|
// Change status
|
|
132
|
-
this.status =
|
|
142
|
+
this.status = TimeServiceStatus.RUNNING;
|
|
133
143
|
// Sync immediately
|
|
134
144
|
this.sync().finally(() => { });
|
|
135
145
|
// Start sync
|
|
136
146
|
this.startSync();
|
|
137
147
|
}
|
|
138
148
|
stop() {
|
|
139
|
-
if (this.status !==
|
|
149
|
+
if (this.status !== TimeServiceStatus.RUNNING) {
|
|
140
150
|
console.warn(LOG_TAG, 'service is not running');
|
|
141
151
|
return;
|
|
142
152
|
}
|
|
143
153
|
// Change status
|
|
144
|
-
this.status =
|
|
154
|
+
this.status = TimeServiceStatus.RUNNING;
|
|
145
155
|
// Stop sync
|
|
146
156
|
this.stopSync();
|
|
147
157
|
// Reset offset
|
|
@@ -220,16 +230,4 @@ class TimeService {
|
|
|
220
230
|
;
|
|
221
231
|
}
|
|
222
232
|
exports.TimeService = TimeService;
|
|
223
|
-
|
|
224
|
-
TimeService.DEFAULT_SYNC_INTERVAL = 60000;
|
|
225
|
-
let Status;
|
|
226
|
-
(function (Status) {
|
|
227
|
-
Status[Status["STOPPED"] = 0] = "STOPPED";
|
|
228
|
-
Status[Status["RUNNING"] = 1] = "RUNNING";
|
|
229
|
-
})(Status = TimeService.Status || (TimeService.Status = {}));
|
|
230
|
-
let EVENT;
|
|
231
|
-
(function (EVENT) {
|
|
232
|
-
EVENT["SYNCED"] = "SYNCED";
|
|
233
|
-
EVENT["SYNC_INTERVAL_CHANGED"] = "SYNC_INTERVAL_CHANGED";
|
|
234
|
-
})(EVENT = TimeService.EVENT || (TimeService.EVENT = {}));
|
|
235
|
-
})(TimeService || (exports.TimeService = TimeService = {}));
|
|
233
|
+
TimeService.DEFAULT_SYNC_INTERVAL = 60000;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import EventEmitter from 'events';
|
|
1
|
+
import EventEmitter3 from 'eventemitter3';
|
|
3
2
|
export interface Sequence {
|
|
4
3
|
key: string;
|
|
5
4
|
required?: boolean;
|
|
@@ -30,7 +29,7 @@ export declare class Sequencer {
|
|
|
30
29
|
currentSequence: Sequence | null;
|
|
31
30
|
startTimestamp: number | null;
|
|
32
31
|
endTimestamp: number | null;
|
|
33
|
-
eventEmitter:
|
|
32
|
+
eventEmitter: EventEmitter3<string | symbol, any>;
|
|
34
33
|
constructor(option?: SequencerOption);
|
|
35
34
|
get getCurrentTimeStamp(): number;
|
|
36
35
|
get executionTime(): number | null;
|
|
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.Sequencer = exports.SequencerEvent = exports.SequencerStatus = void 0;
|
|
16
16
|
const moment_1 = __importDefault(require("moment/moment"));
|
|
17
|
-
const
|
|
17
|
+
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
18
18
|
var SequencerStatus;
|
|
19
19
|
(function (SequencerStatus) {
|
|
20
20
|
SequencerStatus[SequencerStatus["IDLE"] = 0] = "IDLE";
|
|
@@ -39,7 +39,7 @@ class Sequencer {
|
|
|
39
39
|
this.startTimestamp = null;
|
|
40
40
|
this.endTimestamp = null;
|
|
41
41
|
// Emitter
|
|
42
|
-
this.eventEmitter = new
|
|
42
|
+
this.eventEmitter = new eventemitter3_1.default();
|
|
43
43
|
this.pushSequence = (sequence) => {
|
|
44
44
|
this.sequences.push(sequence);
|
|
45
45
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powfix/core-js",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.24",
|
|
4
4
|
"description": "core package",
|
|
5
5
|
"author": "Kwon Kyung-Min <powfix@gmail.com>",
|
|
6
6
|
"private": false,
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"base-64": "^1.0.0",
|
|
26
|
+
"eventemitter3": "^5.0.1",
|
|
26
27
|
"jwt-decode": "^4.0.0",
|
|
27
28
|
"redis": "^4.6.11",
|
|
28
29
|
"uuid": "9.0.1"
|
|
@@ -1,15 +1,27 @@
|
|
|
1
|
-
import
|
|
1
|
+
import EventEmitter3 from 'eventemitter3';
|
|
2
2
|
|
|
3
3
|
const LOG_TAG: string = 'TimeService';
|
|
4
4
|
|
|
5
|
+
export enum TimeServiceStatus {
|
|
6
|
+
STOPPED = 0,
|
|
7
|
+
RUNNING = 1,
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export enum TimeServiceEvent {
|
|
11
|
+
SYNCED = 'SYNCED',
|
|
12
|
+
SYNC_INTERVAL_CHANGED = 'SYNC_INTERVAL_CHANGED',
|
|
13
|
+
}
|
|
14
|
+
|
|
5
15
|
export class TimeService {
|
|
6
|
-
|
|
16
|
+
private static readonly DEFAULT_SYNC_INTERVAL: number = 60000;
|
|
17
|
+
|
|
18
|
+
protected status: TimeServiceStatus = TimeServiceStatus.STOPPED;
|
|
7
19
|
private offset?: TimeService.Offset | undefined;
|
|
8
20
|
private option: TimeService.Option;
|
|
9
21
|
private syncedAt?: TimeService.TimeStamp | undefined;
|
|
10
22
|
|
|
11
23
|
// Emitter
|
|
12
|
-
private emitter = new
|
|
24
|
+
private emitter = new EventEmitter3();
|
|
13
25
|
public readonly on = this.emitter.on;
|
|
14
26
|
public readonly off = this.emitter.off;
|
|
15
27
|
private readonly emit = this.emitter.emit;
|
|
@@ -68,7 +80,7 @@ export class TimeService {
|
|
|
68
80
|
this.syncedAt = syncedAt;
|
|
69
81
|
|
|
70
82
|
// Emit
|
|
71
|
-
this.emit(
|
|
83
|
+
this.emit(TimeServiceEvent.SYNCED, syncedAt);
|
|
72
84
|
|
|
73
85
|
return syncedAt;
|
|
74
86
|
}
|
|
@@ -91,9 +103,9 @@ export class TimeService {
|
|
|
91
103
|
this.option.syncInterval = interval;
|
|
92
104
|
|
|
93
105
|
// Emit
|
|
94
|
-
this.emit(
|
|
106
|
+
this.emit(TimeServiceEvent.SYNC_INTERVAL_CHANGED, interval);
|
|
95
107
|
|
|
96
|
-
if (this.status ===
|
|
108
|
+
if (this.status === TimeServiceStatus.RUNNING) {
|
|
97
109
|
if (this.syncHandler !== undefined) {
|
|
98
110
|
this.stopSync();
|
|
99
111
|
this.startSync();
|
|
@@ -137,18 +149,18 @@ export class TimeService {
|
|
|
137
149
|
return null;
|
|
138
150
|
}
|
|
139
151
|
|
|
140
|
-
public getStatus():
|
|
152
|
+
public getStatus(): TimeServiceStatus {
|
|
141
153
|
return this.status;
|
|
142
154
|
}
|
|
143
155
|
|
|
144
156
|
public start() {
|
|
145
|
-
if (this.status !==
|
|
157
|
+
if (this.status !== TimeServiceStatus.STOPPED) {
|
|
146
158
|
console.warn(LOG_TAG, 'service is not stopped');
|
|
147
159
|
return;
|
|
148
160
|
}
|
|
149
161
|
|
|
150
162
|
// Change status
|
|
151
|
-
this.status =
|
|
163
|
+
this.status = TimeServiceStatus.RUNNING;
|
|
152
164
|
|
|
153
165
|
// Sync immediately
|
|
154
166
|
this.sync().finally(() => {});
|
|
@@ -158,13 +170,13 @@ export class TimeService {
|
|
|
158
170
|
}
|
|
159
171
|
|
|
160
172
|
public stop() {
|
|
161
|
-
if (this.status !==
|
|
173
|
+
if (this.status !== TimeServiceStatus.RUNNING) {
|
|
162
174
|
console.warn(LOG_TAG, 'service is not running');
|
|
163
175
|
return;
|
|
164
176
|
}
|
|
165
177
|
|
|
166
178
|
// Change status
|
|
167
|
-
this.status =
|
|
179
|
+
this.status = TimeServiceStatus.RUNNING;
|
|
168
180
|
|
|
169
181
|
// Stop sync
|
|
170
182
|
this.stopSync();
|
|
@@ -260,13 +272,6 @@ export class TimeService {
|
|
|
260
272
|
}
|
|
261
273
|
|
|
262
274
|
export namespace TimeService {
|
|
263
|
-
export const DEFAULT_SYNC_INTERVAL: number = 60000;
|
|
264
|
-
|
|
265
|
-
export enum Status {
|
|
266
|
-
STOPPED = 0,
|
|
267
|
-
RUNNING = 1,
|
|
268
|
-
}
|
|
269
|
-
|
|
270
275
|
export type Offset = number;
|
|
271
276
|
export type TimeStamp = number;
|
|
272
277
|
|
|
@@ -296,9 +301,4 @@ export namespace TimeService {
|
|
|
296
301
|
clientTimeProvider?: ClientTimeProvider | undefined;
|
|
297
302
|
serverTimeProvider?: ServerTimeProvider | undefined;
|
|
298
303
|
}
|
|
299
|
-
|
|
300
|
-
export enum EVENT {
|
|
301
|
-
SYNCED = 'SYNCED',
|
|
302
|
-
SYNC_INTERVAL_CHANGED = 'SYNC_INTERVAL_CHANGED',
|
|
303
|
-
}
|
|
304
304
|
}
|
package/src/utils/Sequencer.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import moment from "moment/moment";
|
|
2
|
-
import
|
|
2
|
+
import EventEmitter3 from 'eventemitter3';
|
|
3
3
|
|
|
4
4
|
export interface Sequence {
|
|
5
5
|
key: string; // 고유키값
|
|
@@ -40,7 +40,7 @@ export class Sequencer {
|
|
|
40
40
|
endTimestamp: number | null = null;
|
|
41
41
|
|
|
42
42
|
// Emitter
|
|
43
|
-
eventEmitter = new
|
|
43
|
+
eventEmitter = new EventEmitter3();
|
|
44
44
|
|
|
45
45
|
constructor(option?: SequencerOption) {
|
|
46
46
|
if (option?.sequences) {
|