@trigger.dev/sdk 0.0.0-prerelease-20260130124932 → 0.0.0-prerelease-20260220143958

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.
@@ -17,6 +17,7 @@ export * 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;AAS7B,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"}
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"}
@@ -1,3 +1,4 @@
1
1
  export declare const otel: {
2
2
  withExternalTrace: <T>(fn: () => T) => T;
3
+ metrics: import("@opentelemetry/api").MetricsAPI;
3
4
  };
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.otel = void 0;
4
+ const api_1 = require("@opentelemetry/api");
4
5
  const v3_1 = require("@trigger.dev/core/v3");
5
6
  exports.otel = {
6
7
  withExternalTrace: (fn) => {
7
8
  return v3_1.traceContext.withExternalTrace(fn);
8
9
  },
10
+ metrics: api_1.metrics,
9
11
  };
10
12
  //# sourceMappingURL=otel.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"otel.js","sourceRoot":"","sources":["../../../src/v3/otel.ts"],"names":[],"mappings":";;;AAAA,6CAAoD;AAEvC,QAAA,IAAI,GAAG;IAClB,iBAAiB,EAAE,CAAI,EAAW,EAAK,EAAE;QACvC,OAAO,iBAAY,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC;IAC5C,CAAC;CACF,CAAC"}
1
+ {"version":3,"file":"otel.js","sourceRoot":"","sources":["../../../src/v3/otel.ts"],"names":[],"mappings":";;;AAAA,4CAA6C;AAC7C,6CAAoD;AAEvC,QAAA,IAAI,GAAG;IAClB,iBAAiB,EAAE,CAAI,EAAW,EAAK,EAAE;QACvC,OAAO,iBAAY,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,EAAP,aAAO;CACR,CAAC"}
@@ -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"}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = "0.0.0-prerelease-20260130124932";
4
+ exports.VERSION = "0.0.0-prerelease-20260220143958";
5
5
  //# sourceMappingURL=version.js.map
@@ -17,6 +17,7 @@ export * 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";
@@ -17,6 +17,7 @@ export * 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 { ApiError, AuthenticationError, BadRequestError, ConflictError, InternalServerError, NotFoundError, PermissionDeniedError, RateLimitError, UnprocessableEntityError, AbortTaskRunError, OutOfMemoryError, CompleteTaskWithOutput, logger, } from "@trigger.dev/core/v3";
21
22
  export { runs, } from "./runs.js";
22
23
  export * as schedules from "./schedules/index.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v3/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAqB,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACvD,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAS7B,OAAO,EACL,QAAQ,EACR,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,qBAAqB,EACrB,cAAc,EACd,wBAAwB,EACxB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,EACtB,MAAM,GAEP,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,IAAI,GAQL,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAGtC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/v3/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,KAAK,EAAqB,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACvD,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,sBAAsB,CAAC;AACrC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAS3B,OAAO,EACL,QAAQ,EACR,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,mBAAmB,EACnB,aAAa,EACb,qBAAqB,EACrB,cAAc,EACd,wBAAwB,EACxB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,EACtB,MAAM,GAEP,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,IAAI,GAQL,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,SAAS,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,OAAO,MAAM,cAAc,CAAC;AACxC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC;AAGtC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC"}
@@ -1,3 +1,4 @@
1
1
  export declare const otel: {
2
2
  withExternalTrace: <T>(fn: () => T) => T;
3
+ metrics: import("@opentelemetry/api").MetricsAPI;
3
4
  };
@@ -1,7 +1,9 @@
1
+ import { metrics } from "@opentelemetry/api";
1
2
  import { traceContext } from "@trigger.dev/core/v3";
2
3
  export const otel = {
3
4
  withExternalTrace: (fn) => {
4
5
  return traceContext.withExternalTrace(fn);
5
6
  },
7
+ metrics,
6
8
  };
7
9
  //# sourceMappingURL=otel.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"otel.js","sourceRoot":"","sources":["../../../src/v3/otel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,iBAAiB,EAAE,CAAI,EAAW,EAAK,EAAE;QACvC,OAAO,YAAY,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC;IAC5C,CAAC;CACF,CAAC"}
1
+ {"version":3,"file":"otel.js","sourceRoot":"","sources":["../../../src/v3/otel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,iBAAiB,EAAE,CAAI,EAAW,EAAK,EAAE;QACvC,OAAO,YAAY,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO;CACR,CAAC"}
@@ -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,45 @@
1
+ import { apiClientManager, mergeRequestOptions } from "@trigger.dev/core/v3";
2
+ import { tracer } from "./tracer.js";
3
+ // Implementation
4
+ function execute(query, options, requestOptions) {
5
+ const apiClient = apiClientManager.clientOrThrow();
6
+ const from = dateToISOString(options?.from);
7
+ const to = dateToISOString(options?.to);
8
+ const $requestOptions = mergeRequestOptions({
9
+ tracer,
10
+ name: "query.execute()",
11
+ icon: "query",
12
+ attributes: {
13
+ scope: options?.scope ?? "environment",
14
+ format: options?.format ?? "json",
15
+ query,
16
+ period: options?.period,
17
+ from,
18
+ to,
19
+ },
20
+ }, requestOptions);
21
+ return apiClient
22
+ .executeQuery(query, {
23
+ scope: options?.scope,
24
+ period: options?.period,
25
+ from,
26
+ to,
27
+ format: options?.format,
28
+ }, $requestOptions)
29
+ .then((response) => {
30
+ return response;
31
+ });
32
+ }
33
+ function dateToISOString(date) {
34
+ if (date === undefined) {
35
+ return undefined;
36
+ }
37
+ if (date instanceof Date) {
38
+ return date.toISOString();
39
+ }
40
+ return new Date(date).toISOString();
41
+ }
42
+ export const query = {
43
+ execute,
44
+ };
45
+ //# sourceMappingURL=query.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query.js","sourceRoot":"","sources":["../../../src/v3/query.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAqHrC,iBAAiB;AACjB,SAAS,OAAO,CACd,KAAa,EACb,OAAsB,EACtB,cAAkC;IAElC,MAAM,SAAS,GAAG,gBAAgB,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,mBAAmB,CACzC;QACE,MAAM;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;AAED,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,OAAO;CACR,CAAC"}
@@ -1,2 +1,2 @@
1
- export const VERSION = "0.0.0-prerelease-20260130124932";
1
+ export const VERSION = "0.0.0-prerelease-20260220143958";
2
2
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trigger.dev/sdk",
3
- "version": "0.0.0-prerelease-20260130124932",
3
+ "version": "0.0.0-prerelease-20260220143958",
4
4
  "description": "trigger.dev Node.JS SDK",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -43,7 +43,7 @@
43
43
  "dependencies": {
44
44
  "@opentelemetry/api": "1.9.0",
45
45
  "@opentelemetry/semantic-conventions": "1.36.0",
46
- "@trigger.dev/core": "0.0.0-prerelease-20260130124932",
46
+ "@trigger.dev/core": "0.0.0-prerelease-20260220143958",
47
47
  "chalk": "^5.2.0",
48
48
  "cronstrue": "^2.21.0",
49
49
  "debug": "^4.3.4",