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/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, converts the
76
- * date fields and validates the result against `schema`, one of the schemas generated from the OpenAPI
77
- * specification. The validated copy is what callers get, so it is the schema's output -- unknown fields and unknown
78
- * enum values included, since the schemas let both through, and URL fields normalized, since `z.url()` hands back
79
- * the parsed URL's serialization.
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, shouldParseField = null) {
85
- const data = parseDateFields(pluckData(response.data), shouldParseField);
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.maxPageLimit = options.maxPageLimit;
323
- this.limit = options.limit;
324
- this.cursor = options.cursor;
325
- this.getPage = options.getPage;
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.cursor;
281
+ let nextCursor = this.#cursor;
329
282
  let iterateItemCount = 0;
330
283
  while (true) {
331
- const pageLimit = this.limit
332
- ? Math.min(this.maxPageLimit, this.limit - iterateItemCount)
333
- : this.maxPageLimit;
334
- const page = await this.getPage({
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.limit && iterateItemCount >= this.limit) || !page.nextCursor)
297
+ if ((this.#limit && iterateItemCount >= this.#limit) || !page.nextCursor)
345
298
  return;
346
299
  nextCursor = page.nextCursor;
347
300
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apify-client",
3
- "version": "3.0.0-beta.16",
3
+ "version": "3.0.0-beta.18",
4
4
  "description": "Apify API client for JavaScript",
5
5
  "engines": {
6
6
  "node": ">=22.0.0"