@stackbit/cms-core 0.0.19-alpha.1 → 0.0.19
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/annotator/html.d.ts +0 -1
- package/dist/annotator/index.d.ts +2 -3
- package/dist/annotator/react.d.ts +0 -1
- package/dist/common/common-schema.d.ts +10 -3
- package/dist/common/common-schema.js +4 -3
- package/dist/common/common-schema.js.map +1 -1
- package/dist/consts.d.ts +0 -1
- package/dist/encoder.d.ts +7 -36
- package/dist/encoder.js +40 -63
- package/dist/encoder.js.map +1 -1
- package/dist/index.d.ts +6 -11
- package/dist/index.js +11 -37
- package/dist/index.js.map +1 -1
- package/dist/stackbit/index.d.ts +3 -7
- package/dist/stackbit/index.js +10 -13
- package/dist/stackbit/index.js.map +1 -1
- package/dist/utils/index.d.ts +7 -8
- 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/dist/utils/schema-utils.d.ts +2 -3
- package/package.json +4 -8
- package/src/common/common-schema.js +14 -0
- package/src/{encoder.ts → encoder.js} +17 -55
- package/src/index.js +13 -0
- package/src/stackbit/{index.ts → index.js} +9 -5
- package/src/utils/lazy-poller.ts +74 -0
- package/dist/annotator/html.d.ts.map +0 -1
- package/dist/annotator/index.d.ts.map +0 -1
- package/dist/annotator/react.d.ts.map +0 -1
- package/dist/common/common-schema.d.ts.map +0 -1
- package/dist/consts.d.ts.map +0 -1
- package/dist/content-source-interface.d.ts +0 -324
- package/dist/content-source-interface.d.ts.map +0 -1
- package/dist/content-source-interface.js +0 -28
- package/dist/content-source-interface.js.map +0 -1
- package/dist/content-store-types.d.ts +0 -328
- package/dist/content-store-types.d.ts.map +0 -1
- package/dist/content-store-types.js +0 -3
- package/dist/content-store-types.js.map +0 -1
- package/dist/content-store.d.ts +0 -207
- package/dist/content-store.d.ts.map +0 -1
- package/dist/content-store.js +0 -1743
- package/dist/content-store.js.map +0 -1
- package/dist/encoder.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/stackbit/index.d.ts.map +0 -1
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/schema-utils.d.ts.map +0 -1
- package/dist/utils/timer.d.ts +0 -18
- package/dist/utils/timer.d.ts.map +0 -1
- package/dist/utils/timer.js +0 -36
- package/dist/utils/timer.js.map +0 -1
- package/src/common/common-schema.ts +0 -12
- package/src/content-source-interface.ts +0 -468
- package/src/content-store-types.ts +0 -416
- package/src/content-store.ts +0 -2233
- package/src/index.ts +0 -10
- package/src/utils/timer.ts +0 -42
|
@@ -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,iBAAiB,CAAC;QAC3C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACnC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED,eAAe;QACX,IAAI,IAAI,CAAC,YAAY,EAAE;YACnB,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;SACnC;QACD,IAAI,CAAC,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QAChE,IAAI,IAAI,CAAC,UAAU,EAAE;YACjB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;YACnC,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC;YACxB,IAAI,CAAC,cAAc,EAAE,CAAC;SACzB;IACL,CAAC;IAED,KAAK;QACD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3B,IAAI,IAAI,CAAC,YAAY,EAAE;YACnB,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAChC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;SAC5B;QACD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACvB,IAAI,IAAI,CAAC,WAAW,EAAE;YAClB,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAC/B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;SAC3B;IACL,CAAC;IAEO,cAAc;QAClB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,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"}
|
|
@@ -3,12 +3,12 @@ export function isObjectField(field: any): boolean;
|
|
|
3
3
|
export function isModelField(field: any): boolean;
|
|
4
4
|
export function isModelsField(field: any): boolean;
|
|
5
5
|
export function isReferenceField(field: any): boolean;
|
|
6
|
-
export function isCustomModelField(field: any, modelsByName: any):
|
|
6
|
+
export function isCustomModelField(field: any, modelsByName: any): any;
|
|
7
7
|
export function isListField(field: any): boolean;
|
|
8
8
|
export function isListOfObjectsField(field: any): boolean;
|
|
9
9
|
export function isListOfModelField(field: any): boolean;
|
|
10
10
|
export function isListOfModelsField(field: any): boolean;
|
|
11
|
-
export function isListOfCustomModelField(field: any):
|
|
11
|
+
export function isListOfCustomModelField(field: any): any;
|
|
12
12
|
export function isListOfReferenceField(field: any): boolean;
|
|
13
13
|
/**
|
|
14
14
|
* Gets a list field and returns its items field. If list field does not define
|
|
@@ -84,4 +84,3 @@ export function resolveLabelFieldForModel(model: any, modelLabelFieldPath: any,
|
|
|
84
84
|
export function resolveLabelFieldFromFields(fields: any): any;
|
|
85
85
|
export function getUrlPath(stackbitModel: any): any;
|
|
86
86
|
export function getNormalizedModelType(stackbitModel: any): any;
|
|
87
|
-
//# sourceMappingURL=schema-utils.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackbit/cms-core",
|
|
3
|
-
"version": "0.0.19
|
|
3
|
+
"version": "0.0.19",
|
|
4
4
|
"description": "stackbit-dev",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
"author": "Stackbit Inc.",
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@types/lodash": "^4.14.182",
|
|
22
21
|
"jest": "^27.4.7",
|
|
23
22
|
"prettier": "^2.5.1",
|
|
24
23
|
"ts-jest": "^27.1.3",
|
|
@@ -28,8 +27,7 @@
|
|
|
28
27
|
"@babel/parser": "^7.11.5",
|
|
29
28
|
"@babel/traverse": "^7.11.5",
|
|
30
29
|
"@iarna/toml": "^2.2.3",
|
|
31
|
-
"@stackbit/sdk": "^0.2.
|
|
32
|
-
"@stackbit/utils": "^0.2.4-alpha.0",
|
|
30
|
+
"@stackbit/sdk": "^0.2.37",
|
|
33
31
|
"chalk": "^4.0.1",
|
|
34
32
|
"esm": "^3.2.25",
|
|
35
33
|
"fs-extra": "^8.1.0",
|
|
@@ -39,9 +37,7 @@
|
|
|
39
37
|
"lodash": "^4.17.20",
|
|
40
38
|
"micromatch": "^4.0.2",
|
|
41
39
|
"moment": "^2.29.1",
|
|
42
|
-
"parse5": "^6.0.1"
|
|
43
|
-
"sanitize-filename": "^1.6.3",
|
|
44
|
-
"slugify": "^1.6.5"
|
|
40
|
+
"parse5": "^6.0.1"
|
|
45
41
|
},
|
|
46
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "2102ed599336f5b42c03e91636176d7e79b3fdde"
|
|
47
43
|
}
|
|
@@ -1,34 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
const _ = require('lodash');
|
|
2
|
+
const consts = require('./consts');
|
|
3
|
+
const { mergeAtPath, omitByNil } = require('./utils');
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export interface FieldDataItem {
|
|
8
|
-
type: 'object';
|
|
9
|
-
srcObjectLabel: string;
|
|
10
|
-
srcModelName: string;
|
|
11
|
-
srcModelLabel: string;
|
|
12
|
-
fields: Record<string, any>;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface FieldDataRootItem extends Omit<FieldDataItem, 'type'> {
|
|
16
|
-
type: 'object' | 'image' | 'file';
|
|
17
|
-
srcType: string;
|
|
18
|
-
srcProjectId: string;
|
|
19
|
-
srcProjectUrl: string;
|
|
20
|
-
srcEnvironment: string;
|
|
21
|
-
srcObjectId: string;
|
|
22
|
-
srcObjectUrl: string;
|
|
23
|
-
isChanged: boolean;
|
|
24
|
-
status: 'modified' | 'added' | 'deleted' | 'published';
|
|
25
|
-
createdAt: string;
|
|
26
|
-
createdBy?: string;
|
|
27
|
-
updatedAt: string;
|
|
28
|
-
updatedBy?: string[];
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function mapObjectFields({ data, model, fieldDataPath, fieldDataPathsInverted, fieldModelPath, encodeValue, delegate }: any): any {
|
|
5
|
+
function mapObjectFields({ data, model, fieldDataPath, fieldDataPathsInverted, fieldModelPath, encodeValue, delegate }) {
|
|
32
6
|
if (!fieldModelPath) {
|
|
33
7
|
fieldModelPath = [model.name];
|
|
34
8
|
}
|
|
@@ -52,7 +26,7 @@ function mapObjectFields({ data, model, fieldDataPath, fieldDataPathsInverted, f
|
|
|
52
26
|
return accum;
|
|
53
27
|
}
|
|
54
28
|
|
|
55
|
-
let childFieldModelPath
|
|
29
|
+
let childFieldModelPath;
|
|
56
30
|
if (_.get(model, 'isList') && field.name === 'items') {
|
|
57
31
|
childFieldModelPath = fieldModelPath;
|
|
58
32
|
} else {
|
|
@@ -61,7 +35,7 @@ function mapObjectFields({ data, model, fieldDataPath, fieldDataPathsInverted, f
|
|
|
61
35
|
|
|
62
36
|
const fieldPath = ['fields', field.name];
|
|
63
37
|
|
|
64
|
-
const mapLocalizedField = (accum
|
|
38
|
+
const mapLocalizedField = (accum, localizedField) => {
|
|
65
39
|
const localePath = fieldModel.localized ? ['locales', localizedField.locale] : [];
|
|
66
40
|
const fullFieldDataPath = _.concat(fieldPath, localePath);
|
|
67
41
|
|
|
@@ -107,7 +81,7 @@ function mapObjectFields({ data, model, fieldDataPath, fieldDataPathsInverted, f
|
|
|
107
81
|
);
|
|
108
82
|
}
|
|
109
83
|
|
|
110
|
-
function mapField({ fieldValue, fieldModel, fieldDataPath, fieldModelPath, delegate }
|
|
84
|
+
function mapField({ fieldValue, fieldModel, fieldDataPath, fieldModelPath, delegate }) {
|
|
111
85
|
if (_.includes(consts.SIMPLE_VALUE_FIELDS, fieldModel.type)) {
|
|
112
86
|
return {
|
|
113
87
|
fieldData: { value: fieldValue }
|
|
@@ -118,10 +92,10 @@ function mapField({ fieldValue, fieldModel, fieldDataPath, fieldModelPath, deleg
|
|
|
118
92
|
};
|
|
119
93
|
} else if (fieldModel.type === 'list') {
|
|
120
94
|
const itemsModel = _.get(fieldModel, 'items');
|
|
121
|
-
let getListItemModel
|
|
95
|
+
let getListItemModel;
|
|
122
96
|
if (_.isArray(itemsModel)) {
|
|
123
97
|
// in Sanity, list items may have multiple types, in this case, 'items' will be an array
|
|
124
|
-
getListItemModel = (listItem
|
|
98
|
+
getListItemModel = (listItem, fieldModel) => delegate.getItemTypeForListItem(listItem, fieldModel);
|
|
125
99
|
} else {
|
|
126
100
|
// get the type of list items, if type is not defined, set string as it is the default
|
|
127
101
|
const listItemsType = _.get(itemsModel, 'type', 'string');
|
|
@@ -150,7 +124,7 @@ function mapField({ fieldValue, fieldModel, fieldDataPath, fieldModelPath, deleg
|
|
|
150
124
|
};
|
|
151
125
|
},
|
|
152
126
|
{
|
|
153
|
-
fieldData: { items: []
|
|
127
|
+
fieldData: { items: [] }
|
|
154
128
|
}
|
|
155
129
|
);
|
|
156
130
|
} else if (fieldModel.type === 'object') {
|
|
@@ -214,7 +188,7 @@ function mapField({ fieldValue, fieldModel, fieldDataPath, fieldModelPath, deleg
|
|
|
214
188
|
}
|
|
215
189
|
}
|
|
216
190
|
|
|
217
|
-
function fieldModelToFieldData(fieldModel
|
|
191
|
+
function fieldModelToFieldData(fieldModel, overrides) {
|
|
218
192
|
const type = ['reference', 'model'].includes(fieldModel.type) ? 'object' : fieldModel.type;
|
|
219
193
|
return omitByNil(
|
|
220
194
|
_.assign(
|
|
@@ -250,7 +224,7 @@ function fieldModelToFieldData(fieldModel: any, overrides?: any): any {
|
|
|
250
224
|
);
|
|
251
225
|
}
|
|
252
226
|
|
|
253
|
-
function getFieldModelNames(fieldModel
|
|
227
|
+
function getFieldModelNames(fieldModel) {
|
|
254
228
|
const fieldType = fieldModel.type;
|
|
255
229
|
if (fieldType === 'reference' || fieldType === 'model') {
|
|
256
230
|
return _.clone(_.get(fieldModel, 'models', []));
|
|
@@ -282,7 +256,7 @@ function unsetObject() {
|
|
|
282
256
|
};
|
|
283
257
|
}
|
|
284
258
|
|
|
285
|
-
function unresolvedReference(fieldValue
|
|
259
|
+
function unresolvedReference(fieldValue, delegate) {
|
|
286
260
|
return {
|
|
287
261
|
fieldData: {
|
|
288
262
|
type: 'unresolved_reference',
|
|
@@ -300,7 +274,7 @@ function unresolvedModel() {
|
|
|
300
274
|
};
|
|
301
275
|
}
|
|
302
276
|
|
|
303
|
-
function mapData(data
|
|
277
|
+
function mapData(data, prevEncodingResult, delegate) {
|
|
304
278
|
// scan model instances and replace their 'data' with an identity-mapped data
|
|
305
279
|
return _.reduce(
|
|
306
280
|
data,
|
|
@@ -330,24 +304,12 @@ function mapData(data: any, prevEncodingResult: any, delegate: any): any {
|
|
|
330
304
|
);
|
|
331
305
|
}
|
|
332
306
|
|
|
333
|
-
|
|
334
|
-
fieldData: FieldData;
|
|
335
|
-
encodedData?: any[];
|
|
336
|
-
hashedData?: Record<string, any>;
|
|
337
|
-
fieldDataPaths?: string[];
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
export interface EncodeDataOptions {
|
|
341
|
-
data: any[];
|
|
342
|
-
prevEncodingResult?: EncodingResult | null;
|
|
343
|
-
delegate: any;
|
|
344
|
-
encodeDelimiter: string;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
export default function encodeData({ data, prevEncodingResult, delegate }: EncodeDataOptions): EncodingResult {
|
|
307
|
+
function encodeData({ data, prevEncodingResult, delegate }) {
|
|
348
308
|
data = _.cloneDeep(data);
|
|
349
309
|
const mappedData = mapData(data, prevEncodingResult, delegate);
|
|
350
310
|
return {
|
|
351
311
|
fieldData: mappedData.fieldData
|
|
352
312
|
};
|
|
353
313
|
}
|
|
314
|
+
|
|
315
|
+
module.exports = encodeData;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const encodeData = require('./encoder');
|
|
2
|
+
const stackbit = require('./stackbit');
|
|
3
|
+
const annotator = require('./annotator');
|
|
4
|
+
const utils = require('./utils');
|
|
5
|
+
const consts = require('./consts');
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
utils,
|
|
9
|
+
consts,
|
|
10
|
+
annotator,
|
|
11
|
+
encodeData,
|
|
12
|
+
stackbit
|
|
13
|
+
};
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const _ = require('lodash');
|
|
2
|
+
const { loadConfig, isListDataModel } = require('@stackbit/sdk');
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
module.exports = {
|
|
5
|
+
fetchAndConvertSchema
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
function fetchAndConvertSchema(options) {
|
|
5
9
|
return loadConfig({ dirPath: options.dirPath }).then(({ config, errors }) => {
|
|
6
10
|
if (!config) {
|
|
7
|
-
return { schema: {}
|
|
11
|
+
return { schema: {}, errors };
|
|
8
12
|
}
|
|
9
13
|
wrapListDataModels(config);
|
|
10
14
|
const schema = _.pick(config, [
|
|
@@ -34,7 +38,7 @@ export function fetchAndConvertSchema(options: { dirPath: string }): Promise<{ s
|
|
|
34
38
|
});
|
|
35
39
|
}
|
|
36
40
|
|
|
37
|
-
function wrapListDataModels(config
|
|
41
|
+
function wrapListDataModels(config) {
|
|
38
42
|
_.forEach(config.models, (model) => {
|
|
39
43
|
if (!isListDataModel(model)) {
|
|
40
44
|
return;
|
|
@@ -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
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"html.d.ts","sourceRoot":"","sources":["../../src/annotator/html.js"],"names":[],"mappings":"AAKA,gGA6CC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/annotator/index.js"],"names":[],"mappings":"AA6GA,sGAqBC;AArCD,wHAcC;AAlCD;;;;;;;;;;cAkBC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../src/annotator/react.js"],"names":[],"mappings":"AASA,gGA0CC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"common-schema.d.ts","sourceRoot":"","sources":["../../src/common/common-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,eAAO,MAAM,WAAW,EAAE,UASzB,CAAC"}
|
package/dist/consts.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB;;;;;;;;;;;;;;;;CAgBvB,CAAC;AAEX,eAAO,MAAM,oBAAoB;;;;;CAKvB,CAAC;AAEX,eAAO,MAAM,mBAAmB,UAAkG,CAAC;AAEnI,eAAO,MAAM,yBAAyB,MAAM,CAAC;AAE7C,eAAO,MAAM,qBAAqB,UAYjC,CAAC;AAEF,eAAO,MAAM,oBAAoB,UAAgB,CAAC"}
|