@apify/actor-utils 0.1.3-beta.2 → 0.1.4-beta.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/README.md +3 -3
- package/dist/src/gteam-internal/index.d.ts +2 -0
- package/dist/src/gteam-internal/index.d.ts.map +1 -0
- package/dist/src/gteam-internal/index.js +2 -0
- package/dist/src/gteam-internal/index.js.map +1 -0
- package/dist/src/gteam-internal/push-data.d.ts +39 -0
- package/dist/src/gteam-internal/push-data.d.ts.map +1 -0
- package/dist/src/gteam-internal/push-data.js +40 -0
- package/dist/src/gteam-internal/push-data.js.map +1 -0
- package/package.json +27 -5
package/README.md
CHANGED
|
@@ -138,8 +138,7 @@ Highlights:
|
|
|
138
138
|
|
|
139
139
|
- `scripts/check-pushdata.mjs` greps `src/` and `test/` for any
|
|
140
140
|
`.pushData(` call expression and fails if one exists.
|
|
141
|
-
-
|
|
142
|
-
builds via `tsc` first, then runs the compiled suite under `node --test`.
|
|
141
|
+
- `npm test` runs the whole `test/` tree with Vitest, straight from source.
|
|
143
142
|
|
|
144
143
|
## Layout
|
|
145
144
|
|
|
@@ -147,10 +146,11 @@ Highlights:
|
|
|
147
146
|
.
|
|
148
147
|
├── index.ts # package entry point, re-exports src/
|
|
149
148
|
├── src/pushDataWithSchemaRepair.ts # the library
|
|
150
|
-
├── test/pushDataWithSchemaRepair.test.ts #
|
|
149
|
+
├── test/pushDataWithSchemaRepair.test.ts # Vitest suite
|
|
151
150
|
├── scripts/
|
|
152
151
|
│ ├── check-pushdata.mjs # CI guard against direct .pushData() calls
|
|
153
152
|
│ └── probe-errors.mjs # reference: re-derive the API error shape
|
|
154
153
|
├── tsconfig.json
|
|
154
|
+
├── vitest.config.ts
|
|
155
155
|
└── package.json
|
|
156
156
|
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/gteam-internal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/gteam-internal/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ChargeResult } from 'apify';
|
|
2
|
+
/**
|
|
3
|
+
* Pushes to the default dataset, or a named dataset when `alias` is given,
|
|
4
|
+
* converting a schema-validation failure into a {@link NonRetryableError}
|
|
5
|
+
* instead of leaving it to be retried.
|
|
6
|
+
*
|
|
7
|
+
* @param data - A single item or array of items to push.
|
|
8
|
+
* @param options.alias - Alias of the dataset to push to, opened via {@link Actor.openDataset}.
|
|
9
|
+
* Omit to push to the default dataset. Does not charge — call {@link Actor.charge}
|
|
10
|
+
* yourself afterwards if the push should be billable.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* await safePushData(item);
|
|
15
|
+
* await safePushData(report, { alias: 'competitorAnalysis' });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export declare function safePushData<T extends object>(data: T | T[], options?: {
|
|
19
|
+
alias: string;
|
|
20
|
+
}): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Pushes to the default dataset and atomically charges for `eventName`, via
|
|
23
|
+
* {@link Actor.pushData}'s built-in pay-per-event support. Converts a
|
|
24
|
+
* schema-validation failure into a {@link NonRetryableError} instead of
|
|
25
|
+
* leaving it to be retried.
|
|
26
|
+
*
|
|
27
|
+
* @param data - A single item or array of items to push.
|
|
28
|
+
* @param options.eventName - Pay-per-event event name to charge for this push.
|
|
29
|
+
* @returns The {@link ChargeResult}, e.g. to check `chargeableWithinLimit` and decide whether to keep scraping.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* const { chargeableWithinLimit } = await safePushData(item, { eventName: 'result-scraped' });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function safePushData<T extends object>(data: T | T[], options: {
|
|
37
|
+
eventName: string;
|
|
38
|
+
}): Promise<ChargeResult>;
|
|
39
|
+
//# sourceMappingURL=push-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push-data.d.ts","sourceRoot":"","sources":["../../../src/gteam-internal/push-data.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAwB1C;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,OAAO,CAAC,EAAE;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAChH;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,YAAY,CAAC,CAAC,SAAS,MAAM,EAC/C,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,EACb,OAAO,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,GAC/B,OAAO,CAAC,YAAY,CAAC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { NonRetryableError } from '@crawlee/core';
|
|
2
|
+
import { Actor, log } from 'apify';
|
|
3
|
+
import { ApifyApiError } from 'apify-client';
|
|
4
|
+
/**
|
|
5
|
+
* Wraps a push call, converting a dataset schema-validation failure into a
|
|
6
|
+
* {@link NonRetryableError} instead of a retryable one — a schema mismatch
|
|
7
|
+
* will never fix itself on retry, so retrying just burns compute.
|
|
8
|
+
*/
|
|
9
|
+
async function wrapPushData(pushDataFn) {
|
|
10
|
+
try {
|
|
11
|
+
return await pushDataFn();
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
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);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export async function safePushData(data, options) {
|
|
25
|
+
const { alias, eventName } = options ?? {};
|
|
26
|
+
// Default dataset: Actor.pushData(data, eventName) already pushes and
|
|
27
|
+
// charges atomically, so delegate to it as-is instead of reimplementing charging.
|
|
28
|
+
if (!alias) {
|
|
29
|
+
if (eventName) {
|
|
30
|
+
return wrapPushData(async () => Actor.pushData(data, eventName));
|
|
31
|
+
}
|
|
32
|
+
return wrapPushData(async () => Actor.pushData(data));
|
|
33
|
+
}
|
|
34
|
+
// Named dataset: charging is handled by the caller — call Actor.charge() themselves after this push.
|
|
35
|
+
const dataset = await Actor.openDataset({ alias });
|
|
36
|
+
return wrapPushData(async () => {
|
|
37
|
+
await dataset.pushData(data);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=push-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"push-data.js","sourceRoot":"","sources":["../../../src/gteam-internal/push-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C;;;;GAIG;AACH,KAAK,UAAU,YAAY,CAAI,UAA4B;IACvD,IAAI,CAAC;QACD,OAAO,MAAM,UAAU,EAAE,CAAC;IAC9B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,IAAI,CAAC,CAAC,KAAK,YAAY,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK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.1.4-beta.0",
|
|
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": {
|
|
@@ -24,6 +24,10 @@
|
|
|
24
24
|
"./type-utils": {
|
|
25
25
|
"types": "./dist/src/type-utils/index.d.ts",
|
|
26
26
|
"default": "./dist/src/type-utils/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./gteam-internal": {
|
|
29
|
+
"types": "./dist/src/gteam-internal/index.d.ts",
|
|
30
|
+
"default": "./dist/src/gteam-internal/index.js"
|
|
27
31
|
}
|
|
28
32
|
},
|
|
29
33
|
"files": [
|
|
@@ -40,7 +44,7 @@
|
|
|
40
44
|
"lint:fix": "eslint --fix",
|
|
41
45
|
"format": "prettier --write .",
|
|
42
46
|
"format:check": "prettier --check .",
|
|
43
|
-
"test": "
|
|
47
|
+
"test": "vitest run --coverage",
|
|
44
48
|
"check:pushdata": "node scripts/check-pushdata.mjs",
|
|
45
49
|
"check-unused": "knip",
|
|
46
50
|
"ci": "npm run typecheck && npm run lint && npm run format:check && npm run check:pushdata && npm test",
|
|
@@ -55,8 +59,11 @@
|
|
|
55
59
|
"devDependencies": {
|
|
56
60
|
"@apify/eslint-config": "^1.2.0",
|
|
57
61
|
"@apify/tsconfig": "^0.1.2",
|
|
62
|
+
"@crawlee/core": "3.16.0",
|
|
58
63
|
"@types/node": "^25.9.1",
|
|
59
|
-
"
|
|
64
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
65
|
+
"apify": "3.7.2",
|
|
66
|
+
"apify-client": "^2.17.0",
|
|
60
67
|
"eslint": "^9.39.4",
|
|
61
68
|
"eslint-config-prettier": "^10.1.8",
|
|
62
69
|
"globals": "^17.7.0",
|
|
@@ -65,10 +72,25 @@
|
|
|
65
72
|
"lint-staged": "^15.5.2",
|
|
66
73
|
"prettier": "^3.9.4",
|
|
67
74
|
"typescript": "^6.0.3",
|
|
68
|
-
"typescript-eslint": "^8.62.1"
|
|
75
|
+
"typescript-eslint": "^8.62.1",
|
|
76
|
+
"vitest": "^4.0.18"
|
|
69
77
|
},
|
|
70
78
|
"license": "ISC",
|
|
71
79
|
"peerDependencies": {
|
|
72
|
-
"@apify/log": "^2.5.44"
|
|
80
|
+
"@apify/log": "^2.5.44",
|
|
81
|
+
"@crawlee/core": "~3.16",
|
|
82
|
+
"apify": "~3.7",
|
|
83
|
+
"apify-client": "~2.17"
|
|
84
|
+
},
|
|
85
|
+
"peerDependenciesMeta": {
|
|
86
|
+
"@crawlee/core": {
|
|
87
|
+
"optional": true
|
|
88
|
+
},
|
|
89
|
+
"apify": {
|
|
90
|
+
"optional": true
|
|
91
|
+
},
|
|
92
|
+
"apify-client": {
|
|
93
|
+
"optional": true
|
|
94
|
+
}
|
|
73
95
|
}
|
|
74
96
|
}
|