@apify/actor-utils 0.1.8-beta.0 → 0.1.8-beta.1
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.
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ChargeResult } from 'apify';
|
|
2
2
|
/**
|
|
3
|
-
* Pushes to the default dataset, or a named dataset when `alias` is given
|
|
4
|
-
*
|
|
5
|
-
* instead of
|
|
3
|
+
* Pushes to the default dataset, or a named dataset when `alias` is given.
|
|
4
|
+
* Items that fail dataset schema-validation are repaired where possible and
|
|
5
|
+
* dropped (with a logged error) otherwise, instead of failing the whole push.
|
|
6
6
|
*
|
|
7
7
|
* @param data - A single item or array of items to push.
|
|
8
8
|
* @param options.alias - Alias of the dataset to push to, opened via {@link Actor.openDataset}.
|
|
@@ -21,9 +21,9 @@ export declare function safePushData<T extends object>(data: T | T[], options?:
|
|
|
21
21
|
}): Promise<void>;
|
|
22
22
|
/**
|
|
23
23
|
* Pushes to the default dataset and atomically charges for `eventName`, via
|
|
24
|
-
* {@link Actor.pushData}'s built-in pay-per-event support.
|
|
25
|
-
* schema-validation
|
|
26
|
-
*
|
|
24
|
+
* {@link Actor.pushData}'s built-in pay-per-event support. Items that fail
|
|
25
|
+
* dataset schema-validation are repaired where possible and dropped (with a
|
|
26
|
+
* logged error) otherwise, instead of failing the whole push.
|
|
27
27
|
*
|
|
28
28
|
* @param data - A single item or array of items to push.
|
|
29
29
|
* @param options.eventName - Pay-per-event event name to charge for this push.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"push-data.d.ts","sourceRoot":"","sources":["../../../src/gteam-internal/push-data.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"push-data.d.ts","sourceRoot":"","sources":["../../../src/gteam-internal/push-data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAgC1C;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,YAAY,CAAC,CAAC,SAAS,MAAM,EAC/C,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,EACb,OAAO,CAAC,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,KAAK,CAAA;CAAE,GAC/C,OAAO,CAAC,IAAI,CAAC,CAAC;AACjB;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,YAAY,CAAC,CAAC,SAAS,MAAM,EAC/C,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,EACb,OAAO,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,KAAK,CAAA;CAAE,GAC9C,OAAO,CAAC,YAAY,CAAC,CAAC"}
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { NonRetryableError } from '@crawlee/core';
|
|
2
1
|
import { Actor, log } from 'apify';
|
|
3
|
-
import {
|
|
2
|
+
import { pushDataWithSchemaRepair } from '../push-data-with-schema-repair/index.js';
|
|
3
|
+
// Actor.pushData(items, eventName)'s resolved value when every item got
|
|
4
|
+
// dropped and the push itself never ran — mirrors what a charge-less push
|
|
5
|
+
// would report, so callers checking `chargeableWithinLimit` don't crash on
|
|
6
|
+
// a missing result.
|
|
7
|
+
const NO_CHARGE_RESULT = {
|
|
8
|
+
eventChargeLimitReached: false,
|
|
9
|
+
chargedCount: 0,
|
|
10
|
+
chargeableWithinLimit: {},
|
|
11
|
+
};
|
|
4
12
|
/**
|
|
5
|
-
* Wraps a push call,
|
|
6
|
-
*
|
|
7
|
-
*
|
|
13
|
+
* Wraps a push call, repairing or dropping items that fail dataset
|
|
14
|
+
* schema-validation instead of letting the whole batch fail. Every dropped
|
|
15
|
+
* item is logged, so existing log-based monitoring keeps working.
|
|
8
16
|
*/
|
|
9
|
-
async function wrapPushData(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (!(error instanceof ApifyApiError) || !Array.isArray(error.data?.invalidItems)) {
|
|
15
|
-
throw error;
|
|
16
|
-
}
|
|
17
|
-
const msg = 'Dataset validation failed';
|
|
18
|
-
for (const { validationErrors } of error.data.invalidItems) {
|
|
19
|
-
log.error(msg, { msg, error: `${error}`, validationErrors });
|
|
20
|
-
}
|
|
21
|
-
throw new NonRetryableError(msg);
|
|
17
|
+
async function wrapPushData(data, pushFn) {
|
|
18
|
+
const msg = 'Dataset validation failed';
|
|
19
|
+
const { droppedItems, pushResult } = await pushDataWithSchemaRepair(pushFn, data);
|
|
20
|
+
for (const { errors } of droppedItems) {
|
|
21
|
+
log.error(msg, { msg, validationErrors: errors });
|
|
22
22
|
}
|
|
23
|
+
return pushResult;
|
|
23
24
|
}
|
|
24
25
|
export async function safePushData(data, options) {
|
|
25
26
|
const { alias, eventName } = options ?? {};
|
|
26
|
-
// Default dataset: Actor.pushData(
|
|
27
|
+
// Default dataset: Actor.pushData(items, eventName) already pushes and
|
|
27
28
|
// charges atomically, so delegate to it as-is instead of reimplementing charging.
|
|
28
29
|
if (!alias) {
|
|
29
30
|
if (eventName) {
|
|
30
|
-
|
|
31
|
+
const pushResult = await wrapPushData(data, async (items) => Actor.pushData(items, eventName));
|
|
32
|
+
return pushResult ?? NO_CHARGE_RESULT;
|
|
31
33
|
}
|
|
32
|
-
return wrapPushData(async () => Actor.pushData(
|
|
34
|
+
return wrapPushData(data, async (items) => Actor.pushData(items));
|
|
33
35
|
}
|
|
34
36
|
// Named dataset: charging is handled by the caller — call Actor.charge() themselves after this push.
|
|
35
37
|
const dataset = await Actor.openDataset({ alias });
|
|
36
|
-
return wrapPushData(async () =>
|
|
37
|
-
await dataset.pushData(data);
|
|
38
|
-
});
|
|
38
|
+
return wrapPushData(data, async (items) => dataset.pushData(items));
|
|
39
39
|
}
|
|
40
40
|
//# sourceMappingURL=push-data.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"push-data.js","sourceRoot":"","sources":["../../../src/gteam-internal/push-data.ts"],"names":[],"mappings":"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AY,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;IACtE,CAAC;IAED,qGAAqG;IACrG,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,WAAW,CAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IACtD,OAAO,YAAY,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;AACxE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apify/actor-utils",
|
|
3
|
-
"version": "0.1.8-beta.
|
|
3
|
+
"version": "0.1.8-beta.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Wrapper around Actor.pushData that survives dataset schema-validation failures by stripping offending fields and retrying. Callers pass the actual push function as pushFn.",
|
|
6
6
|
"repository": {
|
|
@@ -76,7 +76,6 @@
|
|
|
76
76
|
"devDependencies": {
|
|
77
77
|
"@apify/eslint-config": "^1.2.0",
|
|
78
78
|
"@apify/tsconfig": "^0.1.2",
|
|
79
|
-
"@crawlee/core": "3.16.0",
|
|
80
79
|
"@types/node": "^25.9.1",
|
|
81
80
|
"@vitest/coverage-v8": "^4.0.18",
|
|
82
81
|
"apify": "3.7.2",
|
|
@@ -95,14 +94,10 @@
|
|
|
95
94
|
"license": "ISC",
|
|
96
95
|
"peerDependencies": {
|
|
97
96
|
"@apify/log": "^2",
|
|
98
|
-
"@crawlee/core": "^3",
|
|
99
97
|
"apify": "^3",
|
|
100
98
|
"apify-client": "^2"
|
|
101
99
|
},
|
|
102
100
|
"peerDependenciesMeta": {
|
|
103
|
-
"@crawlee/core": {
|
|
104
|
-
"optional": true
|
|
105
|
-
},
|
|
106
101
|
"apify": {
|
|
107
102
|
"optional": true
|
|
108
103
|
},
|