@workglow/tasks 0.0.52 → 0.0.53
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/index.js +56 -8
- package/dist/index.js.map +4 -4
- package/dist/task/FetchTask.d.ts +20 -5
- package/dist/task/FetchTask.d.ts.map +1 -1
- package/dist/task/JsonTask.d.ts +5 -0
- package/dist/task/JsonTask.d.ts.map +1 -1
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -176,9 +176,9 @@ var inputSchema3 = {
|
|
|
176
176
|
description: "The body of the request"
|
|
177
177
|
},
|
|
178
178
|
response_type: {
|
|
179
|
-
enum: ["json", "text", "blob", "arraybuffer"],
|
|
179
|
+
anyOf: [{ type: "null" }, { enum: ["json", "text", "blob", "arraybuffer"] }],
|
|
180
180
|
title: "Response Type",
|
|
181
|
-
default:
|
|
181
|
+
default: null
|
|
182
182
|
},
|
|
183
183
|
timeout: {
|
|
184
184
|
type: "number",
|
|
@@ -281,16 +281,32 @@ class FetchJob extends Job {
|
|
|
281
281
|
signal: context.signal
|
|
282
282
|
}, async (progress) => await context.updateProgress(progress));
|
|
283
283
|
if (response.ok) {
|
|
284
|
-
|
|
284
|
+
let responseType = input.response_type;
|
|
285
|
+
if (!responseType) {
|
|
286
|
+
const contentType = response.headers.get("content-type") ?? "";
|
|
287
|
+
if (contentType.includes("application/json")) {
|
|
288
|
+
responseType = "json";
|
|
289
|
+
} else if (contentType.includes("text/")) {
|
|
290
|
+
responseType = "text";
|
|
291
|
+
} else if (contentType.includes("application/octet-stream")) {
|
|
292
|
+
responseType = "arraybuffer";
|
|
293
|
+
} else if (contentType.includes("application/pdf") || contentType.includes("image/") || contentType.includes("application/zip")) {
|
|
294
|
+
responseType = "blob";
|
|
295
|
+
} else {
|
|
296
|
+
responseType = "json";
|
|
297
|
+
}
|
|
298
|
+
input.response_type = responseType;
|
|
299
|
+
}
|
|
300
|
+
if (responseType === "json") {
|
|
285
301
|
return { json: await response.json() };
|
|
286
|
-
} else if (
|
|
302
|
+
} else if (responseType === "text") {
|
|
287
303
|
return { text: await response.text() };
|
|
288
|
-
} else if (
|
|
304
|
+
} else if (responseType === "blob") {
|
|
289
305
|
return { blob: await response.blob() };
|
|
290
|
-
} else if (
|
|
306
|
+
} else if (responseType === "arraybuffer") {
|
|
291
307
|
return { arraybuffer: await response.arrayBuffer() };
|
|
292
308
|
}
|
|
293
|
-
throw new TaskInvalidInputError(`Invalid response type: ${
|
|
309
|
+
throw new TaskInvalidInputError(`Invalid response type: ${responseType}`);
|
|
294
310
|
} else {
|
|
295
311
|
if (response.status === 429 || response.status === 503 || response.headers.get("Retry-After")) {
|
|
296
312
|
let retryDate;
|
|
@@ -319,12 +335,44 @@ class FetchTask extends JobQueueTask {
|
|
|
319
335
|
static category = "Input";
|
|
320
336
|
static title = "Fetch";
|
|
321
337
|
static description = "Fetches data from a URL with progress tracking and automatic retry handling";
|
|
338
|
+
static hasDynamicSchemas = true;
|
|
322
339
|
static inputSchema() {
|
|
323
340
|
return inputSchema3;
|
|
324
341
|
}
|
|
325
342
|
static outputSchema() {
|
|
326
343
|
return outputSchema3;
|
|
327
344
|
}
|
|
345
|
+
outputSchema() {
|
|
346
|
+
const responseType = this.runInputData?.response_type ?? this.defaults?.response_type ?? null;
|
|
347
|
+
if (responseType === null || responseType === undefined) {
|
|
348
|
+
return this.constructor.outputSchema();
|
|
349
|
+
}
|
|
350
|
+
const staticSchema = this.constructor.outputSchema();
|
|
351
|
+
if (typeof staticSchema === "boolean") {
|
|
352
|
+
return staticSchema;
|
|
353
|
+
}
|
|
354
|
+
if (!staticSchema.properties) {
|
|
355
|
+
return staticSchema;
|
|
356
|
+
}
|
|
357
|
+
const properties = {};
|
|
358
|
+
if (responseType === "json" && staticSchema.properties.json) {
|
|
359
|
+
properties.json = staticSchema.properties.json;
|
|
360
|
+
} else if (responseType === "text" && staticSchema.properties.text) {
|
|
361
|
+
properties.text = staticSchema.properties.text;
|
|
362
|
+
} else if (responseType === "blob" && staticSchema.properties.blob) {
|
|
363
|
+
properties.blob = staticSchema.properties.blob;
|
|
364
|
+
} else if (responseType === "arraybuffer" && staticSchema.properties.arraybuffer) {
|
|
365
|
+
properties.arraybuffer = staticSchema.properties.arraybuffer;
|
|
366
|
+
}
|
|
367
|
+
if (Object.keys(properties).length === 0) {
|
|
368
|
+
return staticSchema;
|
|
369
|
+
}
|
|
370
|
+
return {
|
|
371
|
+
type: "object",
|
|
372
|
+
properties,
|
|
373
|
+
additionalProperties: false
|
|
374
|
+
};
|
|
375
|
+
}
|
|
328
376
|
constructor(input = {}, config = {}) {
|
|
329
377
|
config.queue = input?.queue ?? config.queue;
|
|
330
378
|
if (config.queue === undefined) {
|
|
@@ -5044,4 +5092,4 @@ export {
|
|
|
5044
5092
|
DebugLog
|
|
5045
5093
|
};
|
|
5046
5094
|
|
|
5047
|
-
//# debugId=
|
|
5095
|
+
//# debugId=45B218A2C95D262C64756E2164756E21
|