@stackbit/cms-core 0.0.8 → 0.0.9-alpha.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.
- package/dist/common/common-schema.d.ts +10 -0
- package/dist/common/common-schema.js +15 -0
- package/dist/common/common-schema.js.map +1 -0
- package/dist/utils/lazy-poller.d.ts +21 -0
- package/dist/utils/lazy-poller.js +56 -0
- package/dist/utils/lazy-poller.js.map +1 -0
- package/package.json +2 -2
- package/src/common/common-schema.js +14 -0
- package/src/utils/lazy-poller.ts +74 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const IMAGE_MODEL = {
|
|
3
|
+
type: 'image',
|
|
4
|
+
name: '__image_model',
|
|
5
|
+
label: 'Image',
|
|
6
|
+
labelField: 'title',
|
|
7
|
+
fields: [
|
|
8
|
+
{ name: 'title', type: 'string' },
|
|
9
|
+
{ name: 'url', type: 'string' }
|
|
10
|
+
]
|
|
11
|
+
};
|
|
12
|
+
module.exports = {
|
|
13
|
+
IMAGE_MODEL
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=common-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common-schema.js","sourceRoot":"","sources":["../../src/common/common-schema.js"],"names":[],"mappings":";AAAA,MAAM,WAAW,GAAG;IAChB,IAAI,EAAE,OAAO;IACb,IAAI,EAAE,eAAe;IACrB,KAAK,EAAE,OAAO;IACd,UAAU,EAAE,OAAO;IACnB,MAAM,EAAE;QACJ,EAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAC;QAC/B,EAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAC;KAChC;CACJ,CAAC;AAEF,MAAM,CAAC,OAAO,GAAG;IACb,WAAW;CACd,CAAA"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface LazyPollerOptions<T> {
|
|
2
|
+
notificationCallback: T;
|
|
3
|
+
sleepTimeoutMs?: number;
|
|
4
|
+
pollingIntervalMs?: number;
|
|
5
|
+
logger: any;
|
|
6
|
+
}
|
|
7
|
+
export declare abstract class LazyPoller<T> {
|
|
8
|
+
protected notificationCallback: T;
|
|
9
|
+
private readonly sleepTimeoutMs;
|
|
10
|
+
private readonly pollingIntervalMs;
|
|
11
|
+
private sleepTimeout;
|
|
12
|
+
private pollTimeout;
|
|
13
|
+
private isSleeping;
|
|
14
|
+
private logger;
|
|
15
|
+
protected constructor({ notificationCallback, sleepTimeoutMs, pollingIntervalMs, logger }: LazyPollerOptions<T>);
|
|
16
|
+
resetSleepTimer(): void;
|
|
17
|
+
sleep(): void;
|
|
18
|
+
private setPollTimeout;
|
|
19
|
+
private callPoll;
|
|
20
|
+
protected abstract poll(notificationCallback: T): any;
|
|
21
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LazyPoller = void 0;
|
|
4
|
+
class LazyPoller {
|
|
5
|
+
constructor({ notificationCallback, sleepTimeoutMs = 30 * 60 * 1000, pollingIntervalMs = 1000, logger }) {
|
|
6
|
+
this.notificationCallback = notificationCallback;
|
|
7
|
+
this.sleepTimeoutMs = sleepTimeoutMs;
|
|
8
|
+
this.pollingIntervalMs = pollingIntervalMs;
|
|
9
|
+
this.logger = logger;
|
|
10
|
+
this.sleepTimeout = null;
|
|
11
|
+
this.pollTimeout = null;
|
|
12
|
+
this.isSleeping = true;
|
|
13
|
+
this.sleep = this.sleep.bind(this);
|
|
14
|
+
this.callPoll = this.callPoll.bind(this);
|
|
15
|
+
}
|
|
16
|
+
resetSleepTimer() {
|
|
17
|
+
if (this.sleepTimeout) {
|
|
18
|
+
clearTimeout(this.sleepTimeout);
|
|
19
|
+
}
|
|
20
|
+
this.sleepTimeout = setTimeout(this.sleep, this.sleepTimeoutMs);
|
|
21
|
+
if (this.isSleeping) {
|
|
22
|
+
this.logger.debug('start polling');
|
|
23
|
+
this.isSleeping = false;
|
|
24
|
+
this.setPollTimeout();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
sleep() {
|
|
28
|
+
this.logger.debug('sleep');
|
|
29
|
+
if (this.sleepTimeout) {
|
|
30
|
+
clearTimeout(this.sleepTimeout);
|
|
31
|
+
this.sleepTimeout = null;
|
|
32
|
+
}
|
|
33
|
+
this.isSleeping = true;
|
|
34
|
+
if (this.pollTimeout) {
|
|
35
|
+
clearTimeout(this.pollTimeout);
|
|
36
|
+
this.pollTimeout = null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
setPollTimeout() {
|
|
40
|
+
this.pollTimeout = setTimeout(this.callPoll, this.pollingIntervalMs);
|
|
41
|
+
}
|
|
42
|
+
async callPoll() {
|
|
43
|
+
this.pollTimeout = null;
|
|
44
|
+
return Promise.resolve(this.poll(this.notificationCallback))
|
|
45
|
+
.catch(error => {
|
|
46
|
+
this.logger.error('error in pollCallback', { error: error.message });
|
|
47
|
+
})
|
|
48
|
+
.finally(() => {
|
|
49
|
+
if (!this.isSleeping) {
|
|
50
|
+
this.setPollTimeout();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.LazyPoller = LazyPoller;
|
|
56
|
+
//# sourceMappingURL=lazy-poller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy-poller.js","sourceRoot":"","sources":["../../src/utils/lazy-poller.ts"],"names":[],"mappings":";;;AASA,MAAsB,UAAU;IAS5B,YAAsB,EAAE,oBAAoB,EAAE,cAAc,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,iBAAiB,GAAG,IAAI,EAAE,MAAM,EAAwB;QACnI,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;QACjD,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,iBAAiB,GAAG,i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AC,iBAAiB,CAAC,CAAC;IACzE,CAAC;IAEO,KAAK,CAAC,QAAQ;QAClB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;aACvD,KAAK,CAAC,KAAK,CAAC,EAAE;YACX,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,uBAAuB,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACzE,CAAC,CAAC;aACD,OAAO,CAAC,GAAG,EAAE;YACV,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE;gBAClB,IAAI,CAAC,cAAc,EAAE,CAAC;aACzB;QACL,CAAC,CAAC,CAAC;IACX,CAAC;CAGJ;AAhED,gCAgEC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackbit/cms-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9-alpha.0",
|
|
4
4
|
"description": "stackbit-dev",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"moment": "^2.29.1",
|
|
40
40
|
"parse5": "^6.0.1"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "3183c88a1c25dcb7349eb7e9f455935ec8c658bb"
|
|
43
43
|
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export interface LazyPollerOptions<T> {
|
|
4
|
+
notificationCallback: T;
|
|
5
|
+
sleepTimeoutMs?: number;
|
|
6
|
+
pollingIntervalMs?: number;
|
|
7
|
+
logger: any;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export abstract class LazyPoller<T> {
|
|
11
|
+
protected notificationCallback: T;
|
|
12
|
+
private readonly sleepTimeoutMs: number;
|
|
13
|
+
private readonly pollingIntervalMs: number;
|
|
14
|
+
private sleepTimeout: null | ReturnType<typeof setTimeout>;
|
|
15
|
+
private pollTimeout: null | ReturnType<typeof setTimeout>;
|
|
16
|
+
private isSleeping: boolean;
|
|
17
|
+
private logger: any;
|
|
18
|
+
|
|
19
|
+
protected constructor({ notificationCallback, sleepTimeoutMs = 30 * 60 * 1000, pollingIntervalMs = 1000, logger }: LazyPollerOptions<T>) {
|
|
20
|
+
this.notificationCallback = notificationCallback;
|
|
21
|
+
this.sleepTimeoutMs = sleepTimeoutMs;
|
|
22
|
+
this.pollingIntervalMs = pollingIntervalMs;
|
|
23
|
+
this.logger = logger;
|
|
24
|
+
this.sleepTimeout = null;
|
|
25
|
+
this.pollTimeout = null;
|
|
26
|
+
this.isSleeping = true;
|
|
27
|
+
this.sleep = this.sleep.bind(this);
|
|
28
|
+
this.callPoll = this.callPoll.bind(this);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
resetSleepTimer() {
|
|
32
|
+
if (this.sleepTimeout) {
|
|
33
|
+
clearTimeout(this.sleepTimeout);
|
|
34
|
+
}
|
|
35
|
+
this.sleepTimeout = setTimeout(this.sleep, this.sleepTimeoutMs);
|
|
36
|
+
if (this.isSleeping) {
|
|
37
|
+
this.logger.debug('start polling');
|
|
38
|
+
this.isSleeping = false;
|
|
39
|
+
this.setPollTimeout();
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
sleep() {
|
|
44
|
+
this.logger.debug('sleep');
|
|
45
|
+
if (this.sleepTimeout) {
|
|
46
|
+
clearTimeout(this.sleepTimeout);
|
|
47
|
+
this.sleepTimeout = null;
|
|
48
|
+
}
|
|
49
|
+
this.isSleeping = true;
|
|
50
|
+
if (this.pollTimeout) {
|
|
51
|
+
clearTimeout(this.pollTimeout);
|
|
52
|
+
this.pollTimeout = null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private setPollTimeout() {
|
|
57
|
+
this.pollTimeout = setTimeout(this.callPoll, this.pollingIntervalMs);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private async callPoll() {
|
|
61
|
+
this.pollTimeout = null;
|
|
62
|
+
return Promise.resolve(this.poll(this.notificationCallback))
|
|
63
|
+
.catch(error => {
|
|
64
|
+
this.logger.error('error in pollCallback', { error: error.message });
|
|
65
|
+
})
|
|
66
|
+
.finally(() => {
|
|
67
|
+
if (!this.isSleeping) {
|
|
68
|
+
this.setPollTimeout();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
protected abstract poll(notificationCallback: T): any;
|
|
74
|
+
}
|