@requence/task 1.0.0-alpha.44 → 1.0.0-alpha.46
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/CHANGELOG.md +12 -0
- package/build/cli.js +7 -7
- package/build/cli.js.map +2 -2
- package/build/index.js +167 -131
- package/build/index.js.map +12 -11
- package/build/types/helpers/src/files/mapOutput.d.ts.map +1 -1
- package/build/types/helpers/src/index.d.ts +3 -2
- package/build/types/helpers/src/index.d.ts.map +1 -1
- package/build/types/helpers/src/jsonschema/zod.d.ts +1 -0
- package/build/types/helpers/src/jsonschema/zod.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/NodeTree.d.ts +37 -14
- package/build/types/helpers/src/protocol/NodeTree.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/command.d.ts +8 -12
- package/build/types/helpers/src/protocol/command.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/nodeType.d.ts +4 -0
- package/build/types/helpers/src/protocol/nodeType.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/taskOptions.d.ts +0 -3
- package/build/types/helpers/src/protocol/taskOptions.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/templateNodeTypes.d.ts +32 -0
- package/build/types/helpers/src/protocol/templateNodeTypes.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/treeNodes.d.ts +20 -6
- package/build/types/helpers/src/protocol/treeNodes.d.ts.map +1 -1
- package/build/types/helpers/src/protocol/update.d.ts +2 -0
- package/build/types/helpers/src/protocol/update.d.ts.map +1 -1
- package/build/types/helpers/src/utils/debounce.d.ts +4 -0
- package/build/types/helpers/src/utils/debounce.d.ts.map +1 -0
- package/build/types/helpers/src/utils/guards.d.ts +3 -0
- package/build/types/helpers/src/utils/guards.d.ts.map +1 -0
- package/build/types/helpers/src/utils/obj.d.ts +4 -0
- package/build/types/helpers/src/utils/obj.d.ts.map +1 -0
- package/build/types/helpers/src/utils/requenceCallback.d.ts.map +1 -1
- package/build/types/helpers/src/utils/types.d.ts +3 -0
- package/build/types/helpers/src/utils/types.d.ts.map +1 -1
- package/build/types/task/src/createTask.d.ts +2 -1
- package/build/types/task/src/createTask.d.ts.map +1 -1
- package/build/types/task/src/getTask.d.ts +1 -0
- package/build/types/task/src/getTask.d.ts.map +1 -1
- package/build/types/task/src/index.d.ts +1 -0
- package/build/types/task/src/index.d.ts.map +1 -1
- package/build/types/task/src/protectTask.d.ts +7 -0
- package/build/types/task/src/protectTask.d.ts.map +1 -0
- package/build/types/task/src/types.d.ts +2 -1
- package/build/types/task/src/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/build/types/helpers/src/utils/createRemotePromise.d.ts +0 -7
- package/build/types/helpers/src/utils/createRemotePromise.d.ts.map +0 -1
- package/build/types/helpers/src/utils/isRecord.d.ts +0 -2
- package/build/types/helpers/src/utils/isRecord.d.ts.map +0 -1
package/build/index.js
CHANGED
|
@@ -49,12 +49,13 @@ function callbackToAsyncIterable(...args) {
|
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
// ../helpers/src/utils/
|
|
52
|
+
// ../helpers/src/utils/guards.ts
|
|
53
53
|
import { z } from "zod/v4";
|
|
54
54
|
var recordSchema = z.record(z.string(), z.unknown());
|
|
55
55
|
function isRecord(data) {
|
|
56
56
|
return recordSchema.safeParse(data).success;
|
|
57
57
|
}
|
|
58
|
+
var uuidSchema = z.uuid();
|
|
58
59
|
|
|
59
60
|
// ../helpers/src/utils/mapData.ts
|
|
60
61
|
function resolve(value, onResolve) {
|
|
@@ -153,110 +154,22 @@ function isCallbackObject(data) {
|
|
|
153
154
|
return callbackObjectSchema.safeParse(data).success;
|
|
154
155
|
}
|
|
155
156
|
|
|
156
|
-
// ../helpers/src/files/
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
return toFileObject(data);
|
|
171
|
-
}
|
|
172
|
-
async function stream(streamUrl, stream2, signal, contentType) {
|
|
173
|
-
const [testStream, dataStream] = stream2.tee();
|
|
174
|
-
const reader = testStream.getReader();
|
|
175
|
-
const dataPromise = reader.read().then(({ done: done2 }) => {
|
|
176
|
-
if (done2) {
|
|
177
|
-
throw new Error("No streaming date received");
|
|
178
|
-
}
|
|
179
|
-
reader.cancel();
|
|
180
|
-
});
|
|
181
|
-
const streamResponse = await fetch(streamUrl, {
|
|
182
|
-
method: "POST",
|
|
183
|
-
signal,
|
|
184
|
-
headers: contentType ? { "Content-Type": contentType } : {}
|
|
185
|
-
});
|
|
186
|
-
const data = await streamResponse.json();
|
|
187
|
-
if (!data || typeof data !== "object") {
|
|
188
|
-
throw new Error("invalid stream response");
|
|
189
|
-
}
|
|
190
|
-
const { mime, url } = data;
|
|
191
|
-
await dataPromise;
|
|
192
|
-
const done = fetch(url, {
|
|
193
|
-
method: "POST",
|
|
194
|
-
signal,
|
|
195
|
-
duplex: "half",
|
|
196
|
-
body: dataStream
|
|
197
|
-
});
|
|
198
|
-
return [toStreamObject({ mime, url }), done];
|
|
157
|
+
// ../helpers/src/files/fileObject.ts
|
|
158
|
+
import { z as z3 } from "zod/v4";
|
|
159
|
+
var fileObjectSchema = z3.object({
|
|
160
|
+
size: z3.int().positive(),
|
|
161
|
+
mime: z3.string(),
|
|
162
|
+
url: z3.url(),
|
|
163
|
+
__REQUENCE_type: z3.literal("RequenceFile")
|
|
164
|
+
});
|
|
165
|
+
function toFileObject(fileInfo) {
|
|
166
|
+
return {
|
|
167
|
+
...fileInfo,
|
|
168
|
+
__REQUENCE_type: "RequenceFile"
|
|
169
|
+
};
|
|
199
170
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
const mapped = await mapData(params.value, {
|
|
203
|
-
async Object(obj) {
|
|
204
|
-
if (obj instanceof Blob || obj instanceof RequenceFile) {
|
|
205
|
-
if (obj instanceof RequenceFile && obj.fileObject) {
|
|
206
|
-
return obj.fileObject;
|
|
207
|
-
}
|
|
208
|
-
if (params.options.uploadUrl) {
|
|
209
|
-
try {
|
|
210
|
-
if (obj instanceof Blob) {
|
|
211
|
-
return await upload(params.options.uploadUrl, obj, params.signal, obj.type);
|
|
212
|
-
}
|
|
213
|
-
if (obj instanceof RequenceFile) {
|
|
214
|
-
return await upload(params.options.uploadUrl, await obj.blob(), params.signal, obj.mimeType);
|
|
215
|
-
}
|
|
216
|
-
} catch (error) {
|
|
217
|
-
if (!(error instanceof Error)) {
|
|
218
|
-
throw error;
|
|
219
|
-
}
|
|
220
|
-
params.onFail?.(error);
|
|
221
|
-
return null;
|
|
222
|
-
}
|
|
223
|
-
} else {
|
|
224
|
-
params.onSkip?.();
|
|
225
|
-
return null;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
if (obj instanceof Response || obj instanceof RequenceStream) {
|
|
229
|
-
if (obj instanceof RequenceStream && obj.streamObject) {
|
|
230
|
-
return obj.streamObject;
|
|
231
|
-
}
|
|
232
|
-
if (params.options.streamUrl) {
|
|
233
|
-
try {
|
|
234
|
-
if (obj instanceof Response && obj.body) {
|
|
235
|
-
const [streamObject, streamPromise] = await stream(params.options.streamUrl, obj.body, params.signal, obj.headers.get("Content-Type"));
|
|
236
|
-
streamPromises.push(streamPromise);
|
|
237
|
-
return streamObject;
|
|
238
|
-
}
|
|
239
|
-
if (obj instanceof RequenceStream) {
|
|
240
|
-
const [streamObject, streamPromise] = await stream(params.options.streamUrl, obj.stream(), params.signal, obj.mimeType);
|
|
241
|
-
streamPromises.push(streamPromise);
|
|
242
|
-
return streamObject;
|
|
243
|
-
}
|
|
244
|
-
} catch (error) {
|
|
245
|
-
if (!(error instanceof Error)) {
|
|
246
|
-
throw error;
|
|
247
|
-
}
|
|
248
|
-
params.onFail?.(error);
|
|
249
|
-
return null;
|
|
250
|
-
}
|
|
251
|
-
} else {
|
|
252
|
-
params.onSkip?.();
|
|
253
|
-
return null;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
Promise.allSettled(streamPromises).then(() => params.onDone?.());
|
|
259
|
-
return mapped;
|
|
171
|
+
function isFileObject(data) {
|
|
172
|
+
return fileObjectSchema.safeParse(data).success;
|
|
260
173
|
}
|
|
261
174
|
|
|
262
175
|
// ../helpers/src/files/RequenceFile.ts
|
|
@@ -323,15 +236,15 @@ class RequenceStream {
|
|
|
323
236
|
#data;
|
|
324
237
|
#stream = null;
|
|
325
238
|
#options;
|
|
326
|
-
constructor(
|
|
327
|
-
this.#data =
|
|
239
|
+
constructor(stream, options) {
|
|
240
|
+
this.#data = stream;
|
|
328
241
|
this.#options = options;
|
|
329
242
|
}
|
|
330
|
-
static fromStreamObject(
|
|
243
|
+
static fromStreamObject(stream) {
|
|
331
244
|
const instance = new this(null, {
|
|
332
245
|
type: "x/x"
|
|
333
246
|
});
|
|
334
|
-
instance.#stream =
|
|
247
|
+
instance.#stream = stream;
|
|
335
248
|
return instance;
|
|
336
249
|
}
|
|
337
250
|
get streamObject() {
|
|
@@ -380,11 +293,11 @@ class RequenceStream {
|
|
|
380
293
|
}
|
|
381
294
|
|
|
382
295
|
// ../helpers/src/files/streamObject.ts
|
|
383
|
-
import { z as
|
|
384
|
-
var streamObjectSchema =
|
|
385
|
-
mime:
|
|
386
|
-
url:
|
|
387
|
-
__REQUENCE_type:
|
|
296
|
+
import { z as z4 } from "zod/v4";
|
|
297
|
+
var streamObjectSchema = z4.object({
|
|
298
|
+
mime: z4.string(),
|
|
299
|
+
url: z4.string().url(),
|
|
300
|
+
__REQUENCE_type: z4.literal("RequenceStream")
|
|
388
301
|
});
|
|
389
302
|
function isStreamObject(data) {
|
|
390
303
|
return streamObjectSchema.safeParse(data).success;
|
|
@@ -396,22 +309,110 @@ function toStreamObject(streamInfo) {
|
|
|
396
309
|
};
|
|
397
310
|
}
|
|
398
311
|
|
|
399
|
-
// ../helpers/src/files/
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
312
|
+
// ../helpers/src/files/mapOutput.ts
|
|
313
|
+
async function upload(uploadUrl, body, signal, contentType) {
|
|
314
|
+
const uploadResponse = await fetch(uploadUrl, {
|
|
315
|
+
method: "POST",
|
|
316
|
+
signal,
|
|
317
|
+
headers: contentType ? {
|
|
318
|
+
"Content-Type": contentType
|
|
319
|
+
} : {},
|
|
320
|
+
body
|
|
321
|
+
});
|
|
322
|
+
const data = await uploadResponse.json();
|
|
323
|
+
if (!data || typeof data !== "object") {
|
|
324
|
+
throw new Error("invalid upload response");
|
|
325
|
+
}
|
|
326
|
+
return toFileObject(data);
|
|
412
327
|
}
|
|
413
|
-
function
|
|
414
|
-
|
|
328
|
+
async function stream(streamUrl, stream2, signal, contentType) {
|
|
329
|
+
const [testStream, dataStream] = stream2.tee();
|
|
330
|
+
const reader = testStream.getReader();
|
|
331
|
+
const dataPromise = reader.read().then(({ done: done2 }) => {
|
|
332
|
+
if (done2) {
|
|
333
|
+
throw new Error("No streaming date received");
|
|
334
|
+
}
|
|
335
|
+
reader.cancel();
|
|
336
|
+
});
|
|
337
|
+
const streamResponse = await fetch(streamUrl, {
|
|
338
|
+
method: "POST",
|
|
339
|
+
signal,
|
|
340
|
+
headers: contentType ? { "Content-Type": contentType } : {}
|
|
341
|
+
});
|
|
342
|
+
const data = await streamResponse.json();
|
|
343
|
+
if (!data || typeof data !== "object") {
|
|
344
|
+
throw new Error("invalid stream response");
|
|
345
|
+
}
|
|
346
|
+
const { mime, url } = data;
|
|
347
|
+
await dataPromise;
|
|
348
|
+
const done = fetch(url, {
|
|
349
|
+
method: "POST",
|
|
350
|
+
signal,
|
|
351
|
+
duplex: "half",
|
|
352
|
+
body: dataStream
|
|
353
|
+
});
|
|
354
|
+
return [toStreamObject({ mime, url }), done];
|
|
355
|
+
}
|
|
356
|
+
async function mapOutput(params) {
|
|
357
|
+
const streamPromises = [];
|
|
358
|
+
const mapped = await mapData(params.value, {
|
|
359
|
+
async Object(obj) {
|
|
360
|
+
if (obj instanceof Blob || obj instanceof RequenceFile) {
|
|
361
|
+
if (obj instanceof RequenceFile && obj.fileObject) {
|
|
362
|
+
return obj.fileObject;
|
|
363
|
+
}
|
|
364
|
+
if (params.options.uploadUrl) {
|
|
365
|
+
try {
|
|
366
|
+
if (obj instanceof Blob) {
|
|
367
|
+
return await upload(params.options.uploadUrl, obj, params.signal, obj.type);
|
|
368
|
+
}
|
|
369
|
+
if (obj instanceof RequenceFile) {
|
|
370
|
+
return await upload(params.options.uploadUrl, await obj.blob(), params.signal, obj.mimeType);
|
|
371
|
+
}
|
|
372
|
+
} catch (error) {
|
|
373
|
+
if (!(error instanceof Error)) {
|
|
374
|
+
throw error;
|
|
375
|
+
}
|
|
376
|
+
params.onFail?.(error);
|
|
377
|
+
return null;
|
|
378
|
+
}
|
|
379
|
+
} else {
|
|
380
|
+
params.onSkip?.();
|
|
381
|
+
return null;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (obj instanceof Response || obj instanceof RequenceStream) {
|
|
385
|
+
if (obj instanceof RequenceStream && obj.streamObject) {
|
|
386
|
+
return obj.streamObject;
|
|
387
|
+
}
|
|
388
|
+
if (params.options.streamUrl) {
|
|
389
|
+
try {
|
|
390
|
+
if (obj instanceof Response && obj.body) {
|
|
391
|
+
const [streamObject, streamPromise] = await stream(params.options.streamUrl, obj.body, params.signal, obj.headers.get("Content-Type"));
|
|
392
|
+
streamPromises.push(streamPromise);
|
|
393
|
+
return streamObject;
|
|
394
|
+
}
|
|
395
|
+
if (obj instanceof RequenceStream) {
|
|
396
|
+
const [streamObject, streamPromise] = await stream(params.options.streamUrl, obj.stream(), params.signal, obj.mimeType);
|
|
397
|
+
streamPromises.push(streamPromise);
|
|
398
|
+
return streamObject;
|
|
399
|
+
}
|
|
400
|
+
} catch (error) {
|
|
401
|
+
if (!(error instanceof Error)) {
|
|
402
|
+
throw error;
|
|
403
|
+
}
|
|
404
|
+
params.onFail?.(error);
|
|
405
|
+
return null;
|
|
406
|
+
}
|
|
407
|
+
} else {
|
|
408
|
+
params.onSkip?.();
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
Promise.allSettled(streamPromises).then(() => params.onDone?.());
|
|
415
|
+
return mapped;
|
|
415
416
|
}
|
|
416
417
|
|
|
417
418
|
// ../helpers/src/utils/resolveRequenceTypes.ts
|
|
@@ -434,6 +435,7 @@ function resolveRequenceTypes(data, onCallback) {
|
|
|
434
435
|
}
|
|
435
436
|
|
|
436
437
|
// src/createTask.ts
|
|
438
|
+
import chalk from "chalk";
|
|
437
439
|
import { createEventSource } from "eventsource-client";
|
|
438
440
|
|
|
439
441
|
// src/utils/getAccessToken.ts
|
|
@@ -483,6 +485,28 @@ async function abortTask(options) {
|
|
|
483
485
|
}
|
|
484
486
|
}
|
|
485
487
|
|
|
488
|
+
// src/protectTask.ts
|
|
489
|
+
class TaskProtectError extends Error {
|
|
490
|
+
taskId;
|
|
491
|
+
constructor(message, taskId) {
|
|
492
|
+
super(message);
|
|
493
|
+
this.taskId = taskId;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
async function protectTask(options) {
|
|
497
|
+
const { apiBaseUrl, token } = getAccessToken(options.accessToken);
|
|
498
|
+
const protectUrl = `${apiBaseUrl}/task/protect/${options.taskId}`;
|
|
499
|
+
const response = await fetch(protectUrl, {
|
|
500
|
+
method: "POST",
|
|
501
|
+
headers: {
|
|
502
|
+
Authorization: `Bearer ${token}`
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
if (!response.ok) {
|
|
506
|
+
throw new TaskProtectError(await response.text(), options.taskId);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
486
510
|
// src/types.ts
|
|
487
511
|
import { z as z5 } from "zod/v4";
|
|
488
512
|
var nodeInfoSchema = z5.object({
|
|
@@ -717,6 +741,9 @@ function createTask(options, onUpdate) {
|
|
|
717
741
|
return;
|
|
718
742
|
}
|
|
719
743
|
const prepareData = await prepareResponse.json();
|
|
744
|
+
if (prepareData.branch !== "live" && !options.suppressBranchWarning) {
|
|
745
|
+
console.warn(chalk.hex("#eab308")("task is executed in", chalk.bold(prepareData.branch), "branch"));
|
|
746
|
+
}
|
|
720
747
|
taskIdPromiseWithResolvers.resolve(prepareData.taskId);
|
|
721
748
|
const mappedParams = await mapOutput({
|
|
722
749
|
value: {
|
|
@@ -775,7 +802,6 @@ function createTask(options, onUpdate) {
|
|
|
775
802
|
return resultPromiseWithResolvers.promise.finally.bind(resultPromiseWithResolvers.promise);
|
|
776
803
|
},
|
|
777
804
|
get then() {
|
|
778
|
-
console.log("THEN!");
|
|
779
805
|
startMonitoring();
|
|
780
806
|
return resultPromiseWithResolvers.promise.then.bind(resultPromiseWithResolvers.promise);
|
|
781
807
|
},
|
|
@@ -794,6 +820,13 @@ function createTask(options, onUpdate) {
|
|
|
794
820
|
accessToken: options.accessToken,
|
|
795
821
|
reason
|
|
796
822
|
});
|
|
823
|
+
},
|
|
824
|
+
async protect() {
|
|
825
|
+
const taskId = await taskIdPromiseWithResolvers.promise;
|
|
826
|
+
await protectTask({
|
|
827
|
+
taskId,
|
|
828
|
+
accessToken: options.accessToken
|
|
829
|
+
});
|
|
797
830
|
}
|
|
798
831
|
};
|
|
799
832
|
return Object.defineProperties(asyncIterable, Object.getOwnPropertyDescriptors(methods));
|
|
@@ -935,7 +968,8 @@ var taskSchema = z6.object({
|
|
|
935
968
|
taskTemplate: z6.string(),
|
|
936
969
|
name: z6.string(),
|
|
937
970
|
nodesData: z6.array(z6.object({ alias: z6.string(), data: z6.unknown() })),
|
|
938
|
-
nodesError: z6.array(z6.object({ alias: z6.string(), error: z6.string() }))
|
|
971
|
+
nodesError: z6.array(z6.object({ alias: z6.string(), error: z6.string() })),
|
|
972
|
+
branch: z6.union([z6.literal("live"), z6.string()])
|
|
939
973
|
});
|
|
940
974
|
async function getTask(taskIdOrOptions) {
|
|
941
975
|
const taskId = typeof taskIdOrOptions === "string" ? taskIdOrOptions : taskIdOrOptions.taskId;
|
|
@@ -967,6 +1001,7 @@ async function getTask(taskIdOrOptions) {
|
|
|
967
1001
|
statusText: taskData.statusText,
|
|
968
1002
|
taskTemplate: taskData.taskTemplate,
|
|
969
1003
|
name: taskData.name,
|
|
1004
|
+
branch: taskData.branch,
|
|
970
1005
|
context
|
|
971
1006
|
};
|
|
972
1007
|
}
|
|
@@ -984,6 +1019,7 @@ async function recreateTask(options, onUpdate) {
|
|
|
984
1019
|
export {
|
|
985
1020
|
watchTasks,
|
|
986
1021
|
recreateTask,
|
|
1022
|
+
protectTask,
|
|
987
1023
|
getTask,
|
|
988
1024
|
createTask,
|
|
989
1025
|
abortTask,
|
|
@@ -992,5 +1028,5 @@ export {
|
|
|
992
1028
|
RequenceFile
|
|
993
1029
|
};
|
|
994
1030
|
|
|
995
|
-
//# debugId=
|
|
1031
|
+
//# debugId=A68A986E1DFD941B64756E2164756E21
|
|
996
1032
|
//# sourceMappingURL=index.js.map
|