@trigger.dev/sdk 4.3.2 → 4.4.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/dist/commonjs/v3/hooks.d.ts +1 -1
- package/dist/commonjs/v3/hooks.js.map +1 -1
- package/dist/commonjs/v3/index.d.ts +1 -0
- package/dist/commonjs/v3/index.js +1 -0
- package/dist/commonjs/v3/index.js.map +1 -1
- package/dist/commonjs/v3/query.d.ts +112 -0
- package/dist/commonjs/v3/query.js +48 -0
- package/dist/commonjs/v3/query.js.map +1 -0
- package/dist/commonjs/v3/shared.js +67 -9
- package/dist/commonjs/v3/shared.js.map +1 -1
- package/dist/commonjs/v3/streams.js +2 -2
- package/dist/commonjs/v3/streams.js.map +1 -1
- package/dist/commonjs/v3/streams.test.d.ts +1 -0
- package/dist/commonjs/v3/streams.test.js +51 -0
- package/dist/commonjs/v3/streams.test.js.map +1 -0
- package/dist/commonjs/version.js +1 -1
- package/dist/esm/v3/hooks.d.ts +1 -1
- package/dist/esm/v3/hooks.js.map +1 -1
- package/dist/esm/v3/index.d.ts +1 -0
- package/dist/esm/v3/index.js +1 -0
- package/dist/esm/v3/index.js.map +1 -1
- package/dist/esm/v3/query.d.ts +112 -0
- package/dist/esm/v3/query.js +45 -0
- package/dist/esm/v3/query.js.map +1 -0
- package/dist/esm/v3/shared.js +68 -10
- package/dist/esm/v3/shared.js.map +1 -1
- package/dist/esm/v3/streams.js +2 -2
- package/dist/esm/v3/streams.js.map +1 -1
- package/dist/esm/v3/streams.test.d.ts +1 -0
- package/dist/esm/v3/streams.test.js +49 -0
- package/dist/esm/v3/streams.test.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/package.json +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AnyOnStartHookFunction, type TaskStartHookParams, type OnStartHookFunction, type AnyOnFailureHookFunction, type AnyOnSuccessHookFunction, type AnyOnCompleteHookFunction, type TaskCompleteResult, type AnyOnWaitHookFunction, type AnyOnResumeHookFunction, type AnyOnCatchErrorHookFunction, type AnyOnMiddlewareHookFunction, type AnyOnCancelHookFunction, type AnyOnStartAttemptHookFunction } from "@trigger.dev/core/v3";
|
|
2
|
-
export type { AnyOnStartHookFunction, TaskStartHookParams, OnStartHookFunction, AnyOnFailureHookFunction, AnyOnSuccessHookFunction, AnyOnCompleteHookFunction, TaskCompleteResult, AnyOnWaitHookFunction, AnyOnResumeHookFunction, AnyOnCatchErrorHookFunction, AnyOnMiddlewareHookFunction, AnyOnCancelHookFunction, };
|
|
2
|
+
export type { AnyOnStartHookFunction, AnyOnStartAttemptHookFunction, TaskStartHookParams, OnStartHookFunction, AnyOnFailureHookFunction, AnyOnSuccessHookFunction, AnyOnCompleteHookFunction, TaskCompleteResult, AnyOnWaitHookFunction, AnyOnResumeHookFunction, AnyOnCatchErrorHookFunction, AnyOnMiddlewareHookFunction, AnyOnCancelHookFunction, };
|
|
3
3
|
export declare function onStart(name: string, fn: AnyOnStartHookFunction): void;
|
|
4
4
|
export declare function onStart(fn: AnyOnStartHookFunction): void;
|
|
5
5
|
export declare function onStartAttempt(name: string, fn: AnyOnStartAttemptHookFunction): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../src/v3/hooks.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../src/v3/hooks.ts"],"names":[],"mappings":";;AAmCA,0BAQC;AAID,wCAQC;AAID,8BAQC;AAID,8BAQC;AAID,gCAQC;AAID,wBAKC;AAID,4BAQC;AAOD,sCAKC;AAID,oCAQC;AAID,gCAQC;AAID,4BAQC;AAhKD,6CAe8B;AAoB9B,SAAgB,OAAO,CACrB,QAAyC,EACzC,EAA2B;IAE3B,mBAAc,CAAC,uBAAuB,CAAC;QACrC,EAAE,EAAE,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC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* from "./otel.js";
|
|
|
17
17
|
export * from "./schemas.js";
|
|
18
18
|
export * from "./heartbeats.js";
|
|
19
19
|
export * from "./streams.js";
|
|
20
|
+
export * from "./query.js";
|
|
20
21
|
export type { Context };
|
|
21
22
|
import type { Context } from "./shared.js";
|
|
22
23
|
import type { ApiClientConfiguration } from "@trigger.dev/core/v3";
|
|
@@ -49,6 +49,7 @@ __exportStar(require("./otel.js"), exports);
|
|
|
49
49
|
__exportStar(require("./schemas.js"), exports);
|
|
50
50
|
__exportStar(require("./heartbeats.js"), exports);
|
|
51
51
|
__exportStar(require("./streams.js"), exports);
|
|
52
|
+
__exportStar(require("./query.js"), exports);
|
|
52
53
|
var v3_1 = require("@trigger.dev/core/v3");
|
|
53
54
|
Object.defineProperty(exports, "ApiError", { enumerable: true, get: function () { return v3_1.ApiError; } });
|
|
54
55
|
Object.defineProperty(exports, "AuthenticationError", { enumerable: true, get: function () { return v3_1.AuthenticationError; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v3/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,8CAA4B;AAC5B,uCAAsD;AAA7C,iGAAA,KAAK,OAAA;AACd,yCAAuD;AAA9C,kGAAA,KAAK,OAAA;AAAE,8GAAA,iBAAiB,OAAA;AACjC,6CAA2B;AAC3B,6CAA2B;AAC3B,4CAA0B;AAC1B,iDAA+B;AAC/B,6CAA2B;AAC3B,uDAAqC;AACrC,4CAA0B;AAC1B,gDAA8B;AAC9B,+CAA6B;AAC7B,gDAA8B;AAC9B,8CAA4B;AAC5B,4CAA0B;AAC1B,+CAA6B;AAC7B,kDAAgC;AAChC,+CAA6B;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v3/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,8CAA4B;AAC5B,uCAAsD;AAA7C,iGAAA,KAAK,OAAA;AACd,yCAAuD;AAA9C,kGAAA,KAAK,OAAA;AAAE,8GAAA,iBAAiB,OAAA;AACjC,6CAA2B;AAC3B,6CAA2B;AAC3B,4CAA0B;AAC1B,iDAA+B;AAC/B,6CAA2B;AAC3B,uDAAqC;AACrC,4CAA0B;AAC1B,gDAA8B;AAC9B,+CAA6B;AAC7B,gDAA8B;AAC9B,8CAA4B;AAC5B,4CAA0B;AAC1B,+CAA6B;AAC7B,kDAAgC;AAChC,+CAA6B;AAC7B,6CAA2B;AAS3B,2CAe8B;AAd5B,8FAAA,QAAQ,OAAA;AACR,yGAAA,mBAAmB,OAAA;AACnB,qGAAA,eAAe,OAAA;AACf,mGAAA,aAAa,OAAA;AACb,yGAAA,mBAAmB,OAAA;AACnB,mGAAA,aAAa,OAAA;AACb,2GAAA,qBAAqB,OAAA;AACrB,oGAAA,cAAc,OAAA;AACd,8GAAA,wBAAwB,OAAA;AACxB,uGAAA,iBAAiB,OAAA;AACjB,sGAAA,gBAAgB,OAAA;AAChB,4GAAA,sBAAsB,OAAA;AACtB,4FAAA,MAAM,OAAA;AAIR,qCASmB;AARjB,+FAAA,IAAI,OAAA;AASN,kEAAkD;AAClD,wDAAwC;AACxC,sDAAsC;AAGtC,qCAA4C;AAAnC,oGAAA,SAAS,OAAA;AAAE,+FAAA,IAAI,OAAA"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { ApiRequestOptions, Prettify } from "@trigger.dev/core/v3";
|
|
2
|
+
export type { QueryTable, RunsTableRow, RunFriendlyStatus } from "@trigger.dev/core/v3";
|
|
3
|
+
export type QueryScope = "environment" | "project" | "organization";
|
|
4
|
+
export type QueryFormat = "json" | "csv";
|
|
5
|
+
/**
|
|
6
|
+
* Options for executing a TRQL query
|
|
7
|
+
*/
|
|
8
|
+
export type QueryOptions = {
|
|
9
|
+
/**
|
|
10
|
+
* The scope of the query - determines what data is accessible
|
|
11
|
+
* - "environment": Current environment only (default)
|
|
12
|
+
* - "project": All environments in the project
|
|
13
|
+
* - "organization": All projects in the organization
|
|
14
|
+
*
|
|
15
|
+
* @default "environment"
|
|
16
|
+
*/
|
|
17
|
+
scope?: QueryScope;
|
|
18
|
+
/**
|
|
19
|
+
* Time period to query (e.g., "7d", "30d", "1h")
|
|
20
|
+
* Cannot be used with `from` or `to`
|
|
21
|
+
*/
|
|
22
|
+
period?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Start of time range as a Date object or Unix timestamp in milliseconds.
|
|
25
|
+
* Must be used with `to`.
|
|
26
|
+
*/
|
|
27
|
+
from?: Date | number;
|
|
28
|
+
/**
|
|
29
|
+
* End of time range as a Date object or Unix timestamp in milliseconds.
|
|
30
|
+
* Must be used with `from`.
|
|
31
|
+
*/
|
|
32
|
+
to?: Date | number;
|
|
33
|
+
/**
|
|
34
|
+
* Response format
|
|
35
|
+
* - "json": Returns structured data (default)
|
|
36
|
+
* - "csv": Returns CSV string
|
|
37
|
+
*
|
|
38
|
+
* @default "json"
|
|
39
|
+
*/
|
|
40
|
+
format?: QueryFormat;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Execute a TRQL query and get the results as a CSV string.
|
|
44
|
+
*
|
|
45
|
+
* @param {string} query - The TRQL query string to execute
|
|
46
|
+
* @param {QueryOptions & { format: "csv" }} options - Query options with `format: "csv"`
|
|
47
|
+
* @param {ApiRequestOptions} [requestOptions] - Optional API request configuration
|
|
48
|
+
* @returns A promise resolving to `{ format: "csv", results: string }` where `results` is the raw CSV text
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const csvResult = await query.execute(
|
|
53
|
+
* "SELECT run_id, status, triggered_at FROM runs",
|
|
54
|
+
* { format: "csv", period: "7d" }
|
|
55
|
+
* );
|
|
56
|
+
* const lines = csvResult.results.split('\n');
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
declare function execute(query: string, options: QueryOptions & {
|
|
60
|
+
format: "csv";
|
|
61
|
+
}, requestOptions?: ApiRequestOptions): Promise<{
|
|
62
|
+
format: "csv";
|
|
63
|
+
results: string;
|
|
64
|
+
}>;
|
|
65
|
+
/**
|
|
66
|
+
* Execute a TRQL query and return typed JSON rows.
|
|
67
|
+
*
|
|
68
|
+
* @template TRow - The shape of each row in the result set. Use {@link QueryTable} for type-safe column access (e.g. `QueryTable<"runs", "status" | "run_id">`)
|
|
69
|
+
* @param {string} query - The TRQL query string to execute
|
|
70
|
+
* @param {QueryOptions} [options] - Optional query configuration
|
|
71
|
+
* @param {ApiRequestOptions} [requestOptions] - Optional API request configuration
|
|
72
|
+
* @returns A promise resolving to `{ format: "json", results: Array<TRow> }`
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* // Basic query with defaults (environment scope, json format)
|
|
77
|
+
* const result = await query.execute("SELECT run_id, status FROM runs LIMIT 10");
|
|
78
|
+
* console.log(result.results); // Array<Record<string, any>>
|
|
79
|
+
*
|
|
80
|
+
* // Type-safe query using QueryTable with specific columns
|
|
81
|
+
* const typedResult = await query.execute<QueryTable<"runs", "run_id" | "status" | "triggered_at">>(
|
|
82
|
+
* "SELECT run_id, status, triggered_at FROM runs LIMIT 10"
|
|
83
|
+
* );
|
|
84
|
+
* typedResult.results.forEach(row => {
|
|
85
|
+
* console.log(row.run_id, row.status); // Fully typed!
|
|
86
|
+
* });
|
|
87
|
+
*
|
|
88
|
+
* // Inline type for aggregation queries
|
|
89
|
+
* const stats = await query.execute<{ status: string; count: number }>(
|
|
90
|
+
* "SELECT status, COUNT(*) as count FROM runs GROUP BY status"
|
|
91
|
+
* );
|
|
92
|
+
* stats.results.forEach(row => {
|
|
93
|
+
* console.log(row.status, row.count); // Fully type-safe
|
|
94
|
+
* });
|
|
95
|
+
*
|
|
96
|
+
* // Query with a custom time period
|
|
97
|
+
* const recent = await query.execute(
|
|
98
|
+
* "SELECT COUNT(*) as count FROM runs",
|
|
99
|
+
* { period: "3d" }
|
|
100
|
+
* );
|
|
101
|
+
* console.log(recent.results[0].count);
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
declare function execute<TRow extends Record<string, any> = Record<string, any>>(query: string, options?: Omit<QueryOptions, "format"> | (QueryOptions & {
|
|
105
|
+
format?: "json";
|
|
106
|
+
}), requestOptions?: ApiRequestOptions): Promise<{
|
|
107
|
+
format: "json";
|
|
108
|
+
results: Array<Prettify<TRow>>;
|
|
109
|
+
}>;
|
|
110
|
+
export declare const query: {
|
|
111
|
+
execute: typeof execute;
|
|
112
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.query = void 0;
|
|
4
|
+
const v3_1 = require("@trigger.dev/core/v3");
|
|
5
|
+
const tracer_js_1 = require("./tracer.js");
|
|
6
|
+
// Implementation
|
|
7
|
+
function execute(query, options, requestOptions) {
|
|
8
|
+
const apiClient = v3_1.apiClientManager.clientOrThrow();
|
|
9
|
+
const from = dateToISOString(options?.from);
|
|
10
|
+
const to = dateToISOString(options?.to);
|
|
11
|
+
const $requestOptions = (0, v3_1.mergeRequestOptions)({
|
|
12
|
+
tracer: tracer_js_1.tracer,
|
|
13
|
+
name: "query.execute()",
|
|
14
|
+
icon: "query",
|
|
15
|
+
attributes: {
|
|
16
|
+
scope: options?.scope ?? "environment",
|
|
17
|
+
format: options?.format ?? "json",
|
|
18
|
+
query,
|
|
19
|
+
period: options?.period,
|
|
20
|
+
from,
|
|
21
|
+
to,
|
|
22
|
+
},
|
|
23
|
+
}, requestOptions);
|
|
24
|
+
return apiClient
|
|
25
|
+
.executeQuery(query, {
|
|
26
|
+
scope: options?.scope,
|
|
27
|
+
period: options?.period,
|
|
28
|
+
from,
|
|
29
|
+
to,
|
|
30
|
+
format: options?.format,
|
|
31
|
+
}, $requestOptions)
|
|
32
|
+
.then((response) => {
|
|
33
|
+
return response;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
function dateToISOString(date) {
|
|
37
|
+
if (date === undefined) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
if (date instanceof Date) {
|
|
41
|
+
return date.toISOString();
|
|
42
|
+
}
|
|
43
|
+
return new Date(date).toISOString();
|
|
44
|
+
}
|
|
45
|
+
exports.query = {
|
|
46
|
+
execute,
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../../src/v3/query.ts"],"names":[],"mappings":";;;AAMA,6CAA6E;AAC7E,2CAAqC;AAqHrC,iBAAiB;AACjB,SAAS,OAAO,CACd,KAAa,EACb,OAAsB,EACtB,cAAkC;IAElC,MAAM,SAAS,GAAG,qBAAgB,CAAC,aAAa,EAAE,CAAC;IAEnD,MAAM,IAAI,GAAG,eAAe,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAC5C,MAAM,EAAE,GAAG,eAAe,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAExC,MAAM,eAAe,GAAG,IAAA,wBAAmB,EACzC;QACE,MAAM,EAAN,kBAAM;QACN,IAAI,EAAE,iBAAiB;QACvB,IAAI,EAAE,OAAO;QACb,UAAU,EAAE;YACV,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,aAAa;YACtC,MAAM,EAAE,OAAO,EAAE,MAAM,IAAI,MAAM;YACjC,KAAK;YACL,MAAM,EAAE,OAAO,EAAE,MAAM;YACvB,IAAI;YACJ,EAAE;SACH;KACF,EACD,cAAc,CACf,CAAC;IAEF,OAAO,SAAS;SACb,YAAY,CACX,KAAK,EACL;QACE,KAAK,EAAE,OAAO,EAAE,KAAK;QACrB,MAAM,EAAE,OAAO,EAAE,MAAM;QACvB,IAAI;QACJ,EAAE;QACF,MAAM,EAAE,OAAO,EAAE,MAAM;KACxB,EACD,eAAe,CAChB;SACA,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE;QACjB,OAAO,QAAQ,CAAC;IAClB,CAAC,CAA2F,CAAC;AACjG,CAAC;AAED,SAAS,eAAe,CAAC,IAA+B;IACtD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,IAAI,YAAY,IAAI,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;IAED,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;AACtC,CAAC;AAEY,QAAA,KAAK,GAAG;IACnB,OAAO;CACR,CAAC"}
|
|
@@ -646,6 +646,7 @@ async function executeBatchTwoPhase(apiClient, items, options, requestOptions) {
|
|
|
646
646
|
parentRunId: options.parentRunId,
|
|
647
647
|
resumeParentOnCompletion: options.resumeParentOnCompletion,
|
|
648
648
|
idempotencyKey: options.idempotencyKey,
|
|
649
|
+
idempotencyKeyOptions: options.idempotencyKeyOptions,
|
|
649
650
|
}, { spanParentAsLink: options.spanParentAsLink }, requestOptions);
|
|
650
651
|
}
|
|
651
652
|
catch (error) {
|
|
@@ -1037,6 +1038,12 @@ async function* transformSingleTaskBatchItemsStreamForWait(taskIdentifier, items
|
|
|
1037
1038
|
const parsedPayload = parsePayload ? await parsePayload(item.payload) : item.payload;
|
|
1038
1039
|
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
1039
1040
|
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
1041
|
+
// Process item-specific idempotency key and extract options
|
|
1042
|
+
const itemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey);
|
|
1043
|
+
const finalIdempotencyKey = itemIdempotencyKey ?? batchItemIdempotencyKey;
|
|
1044
|
+
const idempotencyKeyOptions = itemIdempotencyKey
|
|
1045
|
+
? (0, v3_1.getIdempotencyKeyOptions)(itemIdempotencyKey)
|
|
1046
|
+
: undefined;
|
|
1040
1047
|
yield {
|
|
1041
1048
|
index: index++,
|
|
1042
1049
|
task: taskIdentifier,
|
|
@@ -1057,8 +1064,9 @@ async function* transformSingleTaskBatchItemsStreamForWait(taskIdentifier, items
|
|
|
1057
1064
|
maxAttempts: item.options?.maxAttempts,
|
|
1058
1065
|
metadata: item.options?.metadata,
|
|
1059
1066
|
maxDuration: item.options?.maxDuration,
|
|
1060
|
-
idempotencyKey: (
|
|
1067
|
+
idempotencyKey: finalIdempotencyKey?.toString(),
|
|
1061
1068
|
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
1069
|
+
idempotencyKeyOptions,
|
|
1062
1070
|
machine: item.options?.machine,
|
|
1063
1071
|
priority: item.options?.priority,
|
|
1064
1072
|
region: item.options?.region,
|
|
@@ -1071,6 +1079,11 @@ async function trigger_internal(name, id, payload, parsePayload, options, reques
|
|
|
1071
1079
|
const apiClient = v3_1.apiClientManager.clientOrThrow(requestOptions?.clientConfig);
|
|
1072
1080
|
const parsedPayload = parsePayload ? await parsePayload(payload) : payload;
|
|
1073
1081
|
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
1082
|
+
// Process idempotency key and extract options for storage
|
|
1083
|
+
const processedIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey);
|
|
1084
|
+
const idempotencyKeyOptions = processedIdempotencyKey
|
|
1085
|
+
? (0, v3_1.getIdempotencyKeyOptions)(processedIdempotencyKey)
|
|
1086
|
+
: undefined;
|
|
1074
1087
|
const handle = await apiClient.triggerTask(id, {
|
|
1075
1088
|
payload: payloadPacket.data,
|
|
1076
1089
|
options: {
|
|
@@ -1078,8 +1091,9 @@ async function trigger_internal(name, id, payload, parsePayload, options, reques
|
|
|
1078
1091
|
concurrencyKey: options?.concurrencyKey,
|
|
1079
1092
|
test: v3_1.taskContext.ctx?.run.isTest,
|
|
1080
1093
|
payloadType: payloadPacket.dataType,
|
|
1081
|
-
idempotencyKey:
|
|
1094
|
+
idempotencyKey: processedIdempotencyKey?.toString(),
|
|
1082
1095
|
idempotencyKeyTTL: options?.idempotencyKeyTTL,
|
|
1096
|
+
idempotencyKeyOptions,
|
|
1083
1097
|
delay: options?.delay,
|
|
1084
1098
|
ttl: options?.ttl,
|
|
1085
1099
|
tags: options?.tags,
|
|
@@ -1120,6 +1134,12 @@ async function batchTrigger_internal(name, taskIdentifier, items, options, parse
|
|
|
1120
1134
|
const parsedPayload = parsePayload ? await parsePayload(item.payload) : item.payload;
|
|
1121
1135
|
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
1122
1136
|
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
1137
|
+
// Process item-specific idempotency key and extract options
|
|
1138
|
+
const itemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey);
|
|
1139
|
+
const finalIdempotencyKey = itemIdempotencyKey ?? batchItemIdempotencyKey;
|
|
1140
|
+
const idempotencyKeyOptions = itemIdempotencyKey
|
|
1141
|
+
? (0, v3_1.getIdempotencyKeyOptions)(itemIdempotencyKey)
|
|
1142
|
+
: undefined;
|
|
1123
1143
|
return {
|
|
1124
1144
|
index,
|
|
1125
1145
|
task: taskIdentifier,
|
|
@@ -1139,8 +1159,9 @@ async function batchTrigger_internal(name, taskIdentifier, items, options, parse
|
|
|
1139
1159
|
maxAttempts: item.options?.maxAttempts,
|
|
1140
1160
|
metadata: item.options?.metadata,
|
|
1141
1161
|
maxDuration: item.options?.maxDuration,
|
|
1142
|
-
idempotencyKey: (
|
|
1162
|
+
idempotencyKey: finalIdempotencyKey?.toString(),
|
|
1143
1163
|
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
1164
|
+
idempotencyKeyOptions,
|
|
1144
1165
|
machine: item.options?.machine,
|
|
1145
1166
|
priority: item.options?.priority,
|
|
1146
1167
|
region: item.options?.region,
|
|
@@ -1149,10 +1170,16 @@ async function batchTrigger_internal(name, taskIdentifier, items, options, parse
|
|
|
1149
1170
|
};
|
|
1150
1171
|
}));
|
|
1151
1172
|
// Execute 2-phase batch
|
|
1173
|
+
// Process batch-level idempotency key
|
|
1174
|
+
const batchIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey);
|
|
1175
|
+
const batchIdempotencyKeyOptions = batchIdempotencyKey
|
|
1176
|
+
? (0, v3_1.getIdempotencyKeyOptions)(batchIdempotencyKey)
|
|
1177
|
+
: undefined;
|
|
1152
1178
|
const response = await tracer_js_1.tracer.startActiveSpan(name, async (span) => {
|
|
1153
1179
|
const result = await executeBatchTwoPhase(apiClient, ndJsonItems, {
|
|
1154
1180
|
parentRunId: ctx?.run.id,
|
|
1155
|
-
idempotencyKey:
|
|
1181
|
+
idempotencyKey: batchIdempotencyKey?.toString(),
|
|
1182
|
+
idempotencyKeyOptions: batchIdempotencyKeyOptions,
|
|
1156
1183
|
spanParentAsLink: true, // Fire-and-forget: child runs get separate trace IDs
|
|
1157
1184
|
}, requestOptions);
|
|
1158
1185
|
span.setAttribute("batchId", result.id);
|
|
@@ -1185,10 +1212,16 @@ async function batchTrigger_internal(name, taskIdentifier, items, options, parse
|
|
|
1185
1212
|
const asyncItems = normalizeToAsyncIterable(items);
|
|
1186
1213
|
const transformedItems = transformSingleTaskBatchItemsStream(taskIdentifier, asyncItems, parsePayload, options, queue);
|
|
1187
1214
|
// Execute streaming 2-phase batch
|
|
1215
|
+
// Process batch-level idempotency key
|
|
1216
|
+
const streamBatchIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey);
|
|
1217
|
+
const streamBatchIdempotencyKeyOptions = streamBatchIdempotencyKey
|
|
1218
|
+
? (0, v3_1.getIdempotencyKeyOptions)(streamBatchIdempotencyKey)
|
|
1219
|
+
: undefined;
|
|
1188
1220
|
const response = await tracer_js_1.tracer.startActiveSpan(name, async (span) => {
|
|
1189
1221
|
const result = await executeBatchTwoPhaseStreaming(apiClient, transformedItems, {
|
|
1190
1222
|
parentRunId: ctx?.run.id,
|
|
1191
|
-
idempotencyKey:
|
|
1223
|
+
idempotencyKey: streamBatchIdempotencyKey?.toString(),
|
|
1224
|
+
idempotencyKeyOptions: streamBatchIdempotencyKeyOptions,
|
|
1192
1225
|
spanParentAsLink: true, // Fire-and-forget: child runs get separate trace IDs
|
|
1193
1226
|
}, requestOptions);
|
|
1194
1227
|
span.setAttribute("batchId", result.id);
|
|
@@ -1225,6 +1258,11 @@ async function triggerAndWait_internal(name, id, payload, parsePayload, options,
|
|
|
1225
1258
|
const apiClient = v3_1.apiClientManager.clientOrThrow(requestOptions?.clientConfig);
|
|
1226
1259
|
const parsedPayload = parsePayload ? await parsePayload(payload) : payload;
|
|
1227
1260
|
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
1261
|
+
// Process idempotency key and extract options for storage
|
|
1262
|
+
const processedIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey);
|
|
1263
|
+
const idempotencyKeyOptions = processedIdempotencyKey
|
|
1264
|
+
? (0, v3_1.getIdempotencyKeyOptions)(processedIdempotencyKey)
|
|
1265
|
+
: undefined;
|
|
1228
1266
|
return await tracer_js_1.tracer.startActiveSpan(name, async (span) => {
|
|
1229
1267
|
const response = await apiClient.triggerTask(id, {
|
|
1230
1268
|
payload: payloadPacket.data,
|
|
@@ -1242,8 +1280,9 @@ async function triggerAndWait_internal(name, id, payload, parsePayload, options,
|
|
|
1242
1280
|
maxDuration: options?.maxDuration,
|
|
1243
1281
|
resumeParentOnCompletion: true,
|
|
1244
1282
|
parentRunId: ctx.run.id,
|
|
1245
|
-
idempotencyKey:
|
|
1283
|
+
idempotencyKey: processedIdempotencyKey?.toString(),
|
|
1246
1284
|
idempotencyKeyTTL: options?.idempotencyKeyTTL,
|
|
1285
|
+
idempotencyKeyOptions,
|
|
1247
1286
|
machine: options?.machine,
|
|
1248
1287
|
priority: options?.priority,
|
|
1249
1288
|
region: options?.region,
|
|
@@ -1285,6 +1324,12 @@ async function batchTriggerAndWait_internal(name, id, items, parsePayload, optio
|
|
|
1285
1324
|
const parsedPayload = parsePayload ? await parsePayload(item.payload) : item.payload;
|
|
1286
1325
|
const payloadPacket = await (0, v3_1.stringifyIO)(parsedPayload);
|
|
1287
1326
|
const batchItemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)((0, v3_1.flattenIdempotencyKey)([options?.idempotencyKey, `${index}`]));
|
|
1327
|
+
// Process item-specific idempotency key and extract options
|
|
1328
|
+
const itemIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(item.options?.idempotencyKey);
|
|
1329
|
+
const finalIdempotencyKey = itemIdempotencyKey ?? batchItemIdempotencyKey;
|
|
1330
|
+
const idempotencyKeyOptions = itemIdempotencyKey
|
|
1331
|
+
? (0, v3_1.getIdempotencyKeyOptions)(itemIdempotencyKey)
|
|
1332
|
+
: undefined;
|
|
1288
1333
|
return {
|
|
1289
1334
|
index,
|
|
1290
1335
|
task: id,
|
|
@@ -1305,20 +1350,27 @@ async function batchTriggerAndWait_internal(name, id, items, parsePayload, optio
|
|
|
1305
1350
|
maxAttempts: item.options?.maxAttempts,
|
|
1306
1351
|
metadata: item.options?.metadata,
|
|
1307
1352
|
maxDuration: item.options?.maxDuration,
|
|
1308
|
-
idempotencyKey: (
|
|
1353
|
+
idempotencyKey: finalIdempotencyKey?.toString(),
|
|
1309
1354
|
idempotencyKeyTTL: item.options?.idempotencyKeyTTL ?? options?.idempotencyKeyTTL,
|
|
1355
|
+
idempotencyKeyOptions,
|
|
1310
1356
|
machine: item.options?.machine,
|
|
1311
1357
|
priority: item.options?.priority,
|
|
1312
1358
|
region: item.options?.region,
|
|
1313
1359
|
},
|
|
1314
1360
|
};
|
|
1315
1361
|
}));
|
|
1362
|
+
// Process batch-level idempotency key
|
|
1363
|
+
const batchIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey);
|
|
1364
|
+
const batchIdempotencyKeyOptions = batchIdempotencyKey
|
|
1365
|
+
? (0, v3_1.getIdempotencyKeyOptions)(batchIdempotencyKey)
|
|
1366
|
+
: undefined;
|
|
1316
1367
|
return await tracer_js_1.tracer.startActiveSpan(name, async (span) => {
|
|
1317
1368
|
// Execute 2-phase batch
|
|
1318
1369
|
const response = await executeBatchTwoPhase(apiClient, ndJsonItems, {
|
|
1319
1370
|
parentRunId: ctx.run.id,
|
|
1320
1371
|
resumeParentOnCompletion: true,
|
|
1321
|
-
idempotencyKey:
|
|
1372
|
+
idempotencyKey: batchIdempotencyKey?.toString(),
|
|
1373
|
+
idempotencyKeyOptions: batchIdempotencyKeyOptions,
|
|
1322
1374
|
spanParentAsLink: false, // Waiting: child runs share parent's trace ID
|
|
1323
1375
|
}, requestOptions);
|
|
1324
1376
|
span.setAttribute("batchId", response.id);
|
|
@@ -1353,12 +1405,18 @@ async function batchTriggerAndWait_internal(name, id, items, parsePayload, optio
|
|
|
1353
1405
|
// Stream path: convert to AsyncIterable and transform
|
|
1354
1406
|
const asyncItems = normalizeToAsyncIterable(items);
|
|
1355
1407
|
const transformedItems = transformSingleTaskBatchItemsStreamForWait(id, asyncItems, parsePayload, options, queue);
|
|
1408
|
+
// Process batch-level idempotency key for streaming path
|
|
1409
|
+
const streamBatchIdempotencyKey = await (0, v3_1.makeIdempotencyKey)(options?.idempotencyKey);
|
|
1410
|
+
const streamBatchIdempotencyKeyOptions = streamBatchIdempotencyKey
|
|
1411
|
+
? (0, v3_1.getIdempotencyKeyOptions)(streamBatchIdempotencyKey)
|
|
1412
|
+
: undefined;
|
|
1356
1413
|
return await tracer_js_1.tracer.startActiveSpan(name, async (span) => {
|
|
1357
1414
|
// Execute streaming 2-phase batch
|
|
1358
1415
|
const response = await executeBatchTwoPhaseStreaming(apiClient, transformedItems, {
|
|
1359
1416
|
parentRunId: ctx.run.id,
|
|
1360
1417
|
resumeParentOnCompletion: true,
|
|
1361
|
-
idempotencyKey:
|
|
1418
|
+
idempotencyKey: streamBatchIdempotencyKey?.toString(),
|
|
1419
|
+
idempotencyKeyOptions: streamBatchIdempotencyKeyOptions,
|
|
1362
1420
|
spanParentAsLink: false, // Waiting: child runs share parent's trace ID
|
|
1363
1421
|
}, requestOptions);
|
|
1364
1422
|
span.setAttribute("batchId", response.id);
|