apify-client 3.0.0-beta.16 → 3.0.0-beta.18
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/apify_api_error.d.ts +4 -19
- package/dist/apify_api_error.js +10 -25
- package/dist/apify_client.d.ts +1 -1
- package/dist/apify_client.js +24 -24
- package/dist/bundle.js +12 -12
- package/dist/bundle.js.map +1 -1
- package/dist/generated/schemas.d.ts +374 -374
- package/dist/generated/schemas.js +64 -64
- package/dist/http_client.d.ts +1 -55
- package/dist/http_client.js +32 -33
- package/dist/models.d.ts +2 -3
- package/dist/resource_clients/dataset.d.ts +1 -1
- package/dist/resource_clients/dataset.js +2 -2
- package/dist/resource_clients/log.d.ts +1 -16
- package/dist/resource_clients/log.js +31 -31
- package/dist/resource_clients/request_queue.d.ts +1 -7
- package/dist/resource_clients/request_queue.js +35 -36
- package/dist/resource_clients/user.js +1 -2
- package/dist/schemas.d.ts +1 -1
- package/dist/schemas.js +1 -1
- package/dist/statistics.d.ts +1 -6
- package/dist/statistics.js +2 -2
- package/dist/utils.d.ts +8 -27
- package/dist/utils.js +21 -68
- package/package.json +1 -1
package/dist/utils.js
CHANGED
|
@@ -72,17 +72,17 @@ export const anyObjectSchema = z.custom(isNonArrayObject, {
|
|
|
72
72
|
// in per parse keeps them intact without reaching into the zod config the whole process shares.
|
|
73
73
|
const { localeError } = z.locales.en();
|
|
74
74
|
/**
|
|
75
|
-
* Turns a JSON API response into the value a resource method returns: unwraps the `data` envelope
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
75
|
+
* Turns a JSON API response into the value a resource method returns: unwraps the `data` envelope and validates the
|
|
76
|
+
* result against `schema`, one of the schemas generated from the OpenAPI specification. The validated copy is what
|
|
77
|
+
* callers get, so it is the schema's output -- unknown fields and unknown enum values included, since the schemas let
|
|
78
|
+
* both through, date-time fields turned into `Date` objects, and URL fields normalized, since `z.url()` hands back the
|
|
79
|
+
* parsed URL's serialization.
|
|
80
80
|
*
|
|
81
81
|
* Throws {@link ResponseValidationError} when the response does not match the specification.
|
|
82
82
|
* @internal
|
|
83
83
|
*/
|
|
84
|
-
export function parseResponse(response, schema
|
|
85
|
-
const data =
|
|
84
|
+
export function parseResponse(response, schema) {
|
|
85
|
+
const data = pluckData(response.data);
|
|
86
86
|
const result = schema.safeParse(data, { error: localeError });
|
|
87
87
|
if (!result.success) {
|
|
88
88
|
const { method = 'GET', url = '' } = response.config;
|
|
@@ -120,53 +120,6 @@ export function catchNotFoundForResourceOrThrow(err, resourceId) {
|
|
|
120
120
|
throw err;
|
|
121
121
|
catchNotFoundOrThrow(err);
|
|
122
122
|
}
|
|
123
|
-
/**
|
|
124
|
-
* Traverses JSON structure and converts fields that end with "At" to a Date object (fields such as "modifiedAt" or
|
|
125
|
-
* "createdAt").
|
|
126
|
-
*
|
|
127
|
-
* If you want parse other fields as well, you can provide a custom matcher function shouldParseField(). This
|
|
128
|
-
* admittedly awkward approach allows this function to be reused for various purposes without introducing potential
|
|
129
|
-
* breaking changes.
|
|
130
|
-
*
|
|
131
|
-
* If the field cannot be converted to Date, it is left as is.
|
|
132
|
-
*/
|
|
133
|
-
export function parseDateFields(input, shouldParseField = null, depth = 0) {
|
|
134
|
-
// Don't go too deep to avoid stack overflows (especially if there is a circular reference). The depth of 4
|
|
135
|
-
// corresponds to obj.items.[x].someArrayField.[y].field, which is what a list response looks like: it
|
|
136
|
-
// nests one level deeper than the single resource it wraps, because both the item array and the nested
|
|
137
|
-
// array spend a level.
|
|
138
|
-
//
|
|
139
|
-
// In a list response it also reaches one level into caller-owned blobs the API stores verbatim, so a
|
|
140
|
-
// listed request's `userData.foo.somethingAt` comes back as a `Date` rather than the string it was
|
|
141
|
-
// written as.
|
|
142
|
-
// TODO: Consider removing this limitation. It might came across as an annoying surprise as it's not communicated.
|
|
143
|
-
if (depth > 4) {
|
|
144
|
-
return input;
|
|
145
|
-
}
|
|
146
|
-
if (Array.isArray(input))
|
|
147
|
-
return input.map((child) => parseDateFields(child, shouldParseField, depth + 1));
|
|
148
|
-
if (!input || typeof input !== 'object')
|
|
149
|
-
return input;
|
|
150
|
-
return Object.entries(input).reduce((output, [k, v]) => {
|
|
151
|
-
const isValObject = !!v && typeof v === 'object';
|
|
152
|
-
if (k.endsWith('At') || (shouldParseField && shouldParseField(k))) {
|
|
153
|
-
if (v) {
|
|
154
|
-
const d = new Date(v);
|
|
155
|
-
output[k] = Number.isNaN(d.getTime()) ? v : d;
|
|
156
|
-
}
|
|
157
|
-
else {
|
|
158
|
-
output[k] = v;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
else if (isValObject || Array.isArray(v)) {
|
|
162
|
-
output[k] = parseDateFields(v, shouldParseField, depth + 1);
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
output[k] = v;
|
|
166
|
-
}
|
|
167
|
-
return output;
|
|
168
|
-
}, {});
|
|
169
|
-
}
|
|
170
123
|
/**
|
|
171
124
|
* Helper function that converts array of webhooks to base64 string
|
|
172
125
|
*/
|
|
@@ -314,24 +267,24 @@ export function getVersionData() {
|
|
|
314
267
|
* Helper class to create async iterators from paginated list endpoints.
|
|
315
268
|
*/
|
|
316
269
|
export class RequestQueuePaginationIterator {
|
|
317
|
-
maxPageLimit;
|
|
318
|
-
getPage;
|
|
319
|
-
limit;
|
|
320
|
-
cursor;
|
|
270
|
+
#maxPageLimit;
|
|
271
|
+
#getPage;
|
|
272
|
+
#limit;
|
|
273
|
+
#cursor;
|
|
321
274
|
constructor(options) {
|
|
322
|
-
this
|
|
323
|
-
this
|
|
324
|
-
this
|
|
325
|
-
this
|
|
275
|
+
this.#maxPageLimit = options.maxPageLimit;
|
|
276
|
+
this.#limit = options.limit;
|
|
277
|
+
this.#cursor = options.cursor;
|
|
278
|
+
this.#getPage = options.getPage;
|
|
326
279
|
}
|
|
327
280
|
async *[Symbol.asyncIterator]() {
|
|
328
|
-
let nextCursor = this
|
|
281
|
+
let nextCursor = this.#cursor;
|
|
329
282
|
let iterateItemCount = 0;
|
|
330
283
|
while (true) {
|
|
331
|
-
const pageLimit = this
|
|
332
|
-
? Math.min(this
|
|
333
|
-
: this
|
|
334
|
-
const page = await this
|
|
284
|
+
const pageLimit = this.#limit
|
|
285
|
+
? Math.min(this.#maxPageLimit, this.#limit - iterateItemCount)
|
|
286
|
+
: this.#maxPageLimit;
|
|
287
|
+
const page = await this.#getPage({
|
|
335
288
|
limit: pageLimit,
|
|
336
289
|
cursor: nextCursor,
|
|
337
290
|
});
|
|
@@ -341,7 +294,7 @@ export class RequestQueuePaginationIterator {
|
|
|
341
294
|
yield page;
|
|
342
295
|
iterateItemCount += page.items.length;
|
|
343
296
|
// Limit reached stopping to iterate
|
|
344
|
-
if ((this
|
|
297
|
+
if ((this.#limit && iterateItemCount >= this.#limit) || !page.nextCursor)
|
|
345
298
|
return;
|
|
346
299
|
nextCursor = page.nextCursor;
|
|
347
300
|
}
|