@activepieces/pieces-common 0.0.2 → 0.0.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/package.json
CHANGED
|
@@ -11,8 +11,9 @@ interface TimebasedPolling<INPUT> {
|
|
|
11
11
|
}
|
|
12
12
|
interface LastItemPolling<INPUT> {
|
|
13
13
|
strategy: DedupeStrategy.LAST_ITEM;
|
|
14
|
-
items: ({ propsValue }: {
|
|
14
|
+
items: ({ propsValue, lastItemId }: {
|
|
15
15
|
propsValue: INPUT;
|
|
16
|
+
lastItemId: unknown;
|
|
16
17
|
}) => Promise<{
|
|
17
18
|
id: unknown;
|
|
18
19
|
data: unknown;
|
package/src/lib/polling/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
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";
|
|
@@ -9,7 +10,7 @@ var DedupeStrategy;
|
|
|
9
10
|
})(DedupeStrategy = exports.DedupeStrategy || (exports.DedupeStrategy = {}));
|
|
10
11
|
exports.pollingHelper = {
|
|
11
12
|
poll(polling, { store, propsValue }) {
|
|
12
|
-
var _a, _b, _c;
|
|
13
|
+
var _a, _b, _c, _d;
|
|
13
14
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
14
15
|
switch (polling.strategy) {
|
|
15
16
|
case DedupeStrategy.TIMEBASED: {
|
|
@@ -21,15 +22,16 @@ exports.pollingHelper = {
|
|
|
21
22
|
}
|
|
22
23
|
case DedupeStrategy.LAST_ITEM: {
|
|
23
24
|
const lastItemId = (yield store.get("lastItem"));
|
|
24
|
-
const items = yield polling.items({ propsValue });
|
|
25
|
+
const items = yield polling.items({ propsValue, lastItemId });
|
|
25
26
|
const newLastItem = (_b = items === null || items === void 0 ? void 0 : items[0]) === null || _b === void 0 ? void 0 : _b.id;
|
|
26
|
-
if (!newLastItem) {
|
|
27
|
-
|
|
27
|
+
if (!(0, lodash_1.isNil)(newLastItem)) {
|
|
28
|
+
yield store.put("lastItem", newLastItem);
|
|
28
29
|
}
|
|
29
|
-
yield store.put("lastItem", newLastItem);
|
|
30
|
-
// get items until you find the last item
|
|
31
30
|
const lastItemIndex = items.findIndex(f => f.id === lastItemId);
|
|
32
|
-
|
|
31
|
+
if ((0, lodash_1.isNil)(lastItemId) || lastItemIndex == -1) {
|
|
32
|
+
return (_c = items === null || items === void 0 ? void 0 : items.map((item) => item.data)) !== null && _c !== void 0 ? _c : [];
|
|
33
|
+
}
|
|
34
|
+
return (_d = items === null || items === void 0 ? void 0 : items.slice(0, lastItemIndex).map((item) => item.data)) !== null && _d !== void 0 ? _d : [];
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
37
|
});
|
|
@@ -43,8 +45,14 @@ exports.pollingHelper = {
|
|
|
43
45
|
break;
|
|
44
46
|
}
|
|
45
47
|
case DedupeStrategy.LAST_ITEM: {
|
|
46
|
-
const items = (yield polling.items({ propsValue }));
|
|
47
|
-
|
|
48
|
+
const items = (yield polling.items({ propsValue, lastItemId: null }));
|
|
49
|
+
const lastItemId = (_a = items === null || items === void 0 ? void 0 : items[0]) === null || _a === void 0 ? void 0 : _a.id;
|
|
50
|
+
if (!(0, lodash_1.isNil)(lastItemId)) {
|
|
51
|
+
yield store.put("lastItem", lastItemId);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
yield store.delete("lastItem");
|
|
55
|
+
}
|
|
48
56
|
break;
|
|
49
57
|
}
|
|
50
58
|
}
|
|
@@ -68,7 +76,7 @@ exports.pollingHelper = {
|
|
|
68
76
|
break;
|
|
69
77
|
}
|
|
70
78
|
case DedupeStrategy.LAST_ITEM: {
|
|
71
|
-
items = yield polling.items({ propsValue });
|
|
79
|
+
items = yield polling.items({ propsValue, lastItemId: null });
|
|
72
80
|
break;
|
|
73
81
|
}
|
|
74
82
|
}
|
|
@@ -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,EAAuC;;;YACjG,QAAQ,OAAO,CAAC,QAAQ,EAAE;gBACtB,KAAK,cAAc,CAAC,SAAS,CAAC,CAAC;oBAC3B,MAAM,qBAAqB,GAAG,MAAA,CAAC,MAAM,KAAK,CAAC,GAAG,CAAS,UAAU,CAAC,CAAC,mCAAI,CAAC,CAAC;oBACzE,MAAM,KAAK,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,EAAE,UAAU,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,CAAC,CAAC;oBAC3F,MAAM,wBAAwB,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,iBAAiB,CAAC,EAAE,qBAAqB,CAAC,CAAC;oBAC3H,MAAM,KAAK,CAAC,GAAG,CAAC,UAAU,EAAE,wBAAwB,CAAC,CAAC;oBACtD,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,iBAAiB,GAAG,qBAAqB,CAAC,C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