@activepieces/pieces-common 0.0.3 → 0.0.5
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@activepieces/pieces-common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@sinclair/typebox": "0.26.8",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"lodash": "4.17.21",
|
|
9
9
|
"nanoid": "3.3.4",
|
|
10
10
|
"@activepieces/pieces-framework": "0.3.20",
|
|
11
|
-
"@activepieces/shared": "0.3.
|
|
11
|
+
"@activepieces/shared": "0.3.32",
|
|
12
12
|
"tslib": "2.4.1"
|
|
13
13
|
},
|
|
14
14
|
"main": "./src/index.js",
|
|
@@ -25,9 +25,10 @@ export declare enum DedupeStrategy {
|
|
|
25
25
|
}
|
|
26
26
|
export declare type Polling<T> = TimebasedPolling<T> | LastItemPolling<T>;
|
|
27
27
|
export declare const pollingHelper: {
|
|
28
|
-
poll<INPUT>(polling: Polling<INPUT>, { store, propsValue }: {
|
|
28
|
+
poll<INPUT>(polling: Polling<INPUT>, { store, propsValue, maxItemsToPoll }: {
|
|
29
29
|
store: Store;
|
|
30
30
|
propsValue: INPUT;
|
|
31
|
+
maxItemsToPoll?: number | undefined;
|
|
31
32
|
}): Promise<unknown[]>;
|
|
32
33
|
onEnable<INPUT_1>(polling: Polling<INPUT_1>, { store, propsValue }: {
|
|
33
34
|
store: Store;
|
package/src/lib/polling/index.js
CHANGED
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.pollingHelper = exports.DedupeStrategy = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
5
6
|
var DedupeStrategy;
|
|
6
7
|
(function (DedupeStrategy) {
|
|
7
8
|
DedupeStrategy[DedupeStrategy["TIMEBASED"] = 0] = "TIMEBASED";
|
|
8
9
|
DedupeStrategy[DedupeStrategy["LAST_ITEM"] = 1] = "LAST_ITEM";
|
|
9
10
|
})(DedupeStrategy = exports.DedupeStrategy || (exports.DedupeStrategy = {}));
|
|
10
11
|
exports.pollingHelper = {
|
|
11
|
-
poll(polling, { store, propsValue }) {
|
|
12
|
+
poll(polling, { store, propsValue, maxItemsToPoll }) {
|
|
12
13
|
var _a, _b, _c;
|
|
13
14
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
14
15
|
switch (polling.strategy) {
|
|
@@ -22,14 +23,24 @@ exports.pollingHelper = {
|
|
|
22
23
|
case DedupeStrategy.LAST_ITEM: {
|
|
23
24
|
const lastItemId = (yield store.get("lastItem"));
|
|
24
25
|
const items = yield polling.items({ propsValue, lastItemId });
|
|
25
|
-
const newLastItem = (_b = items === null || items === void 0 ? void 0 : items[0]) === null || _b === void 0 ? void 0 : _b.id;
|
|
26
|
-
if (!lastItemId || !newLastItem) {
|
|
27
|
-
return items;
|
|
28
|
-
}
|
|
29
|
-
yield store.put("lastItem", newLastItem);
|
|
30
|
-
// get items until you find the last item
|
|
31
26
|
const lastItemIndex = items.findIndex(f => f.id === lastItemId);
|
|
32
|
-
|
|
27
|
+
let newItems = [];
|
|
28
|
+
if ((0, lodash_1.isNil)(lastItemId) || lastItemIndex == -1) {
|
|
29
|
+
newItems = items !== null && items !== void 0 ? items : [];
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
newItems = (_b = items === null || items === void 0 ? void 0 : items.slice(0, lastItemIndex)) !== null && _b !== void 0 ? _b : [];
|
|
33
|
+
}
|
|
34
|
+
// Sorted from newest to oldest
|
|
35
|
+
if (!(0, lodash_1.isNil)(maxItemsToPoll)) {
|
|
36
|
+
// Get the last polling.maxItemsToPoll items
|
|
37
|
+
newItems = newItems.slice(-maxItemsToPoll);
|
|
38
|
+
}
|
|
39
|
+
const newLastItem = (_c = newItems === null || newItems === void 0 ? void 0 : newItems[0]) === null || _c === void 0 ? void 0 : _c.id;
|
|
40
|
+
if (!(0, lodash_1.isNil)(newLastItem)) {
|
|
41
|
+
yield store.put("lastItem", newLastItem);
|
|
42
|
+
}
|
|
43
|
+
return newItems.map((item) => item.data);
|
|
33
44
|
}
|
|
34
45
|
}
|
|
35
46
|
});
|
|
@@ -44,7 +55,13 @@ exports.pollingHelper = {
|
|
|
44
55
|
}
|
|
45
56
|
case DedupeStrategy.LAST_ITEM: {
|
|
46
57
|
const items = (yield polling.items({ propsValue, lastItemId: null }));
|
|
47
|
-
|
|
58
|
+
const lastItemId = (_a = items === null || items === void 0 ? void 0 : items[0]) === null || _a === void 0 ? void 0 : _a.id;
|
|
59
|
+
if (!(0, lodash_1.isNil)(lastItemId)) {
|
|
60
|
+
yield store.put("lastItem", lastItemId);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
yield store.delete("lastItem");
|
|
64
|
+
}
|
|
48
65
|
break;
|
|
49
66
|
}
|
|
50
67
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/pieces/common/src/lib/polling/index.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/pieces/common/src/lib/polling/index.ts"],"names":[],"mappings":";;;;AACA,mCAA+B;AAwB/B,IAAY,cAGX;AAHD,WAAY,cAAc;IACtB,6DAAS,CAAA;IACT,6DAAS,CAAA;AACb,CAAC,EAHW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAGzB;AAIY,QAAA,aAAa,GAAG;IACnB,IAAI,CAAQ,OAAuB,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,cAAc,EAAgE;;;YAC1I,QAAQ,OAAO,CAAC,QAAQ,EAAE;gBACtB,KAAK,cAAc,CAAC,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