cloudflare
Version:
The official TypeScript library for the Cloudflare API
74 lines • 3.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Query = exports.BaseQuery = void 0;
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
const resource_1 = require("../../../core/resource.js");
const error_1 = require("../../../core/error.js");
const pagination_1 = require("../../../core/pagination.js");
const headers_1 = require("../../../internal/headers.js");
const path_1 = require("../../../internal/utils/path.js");
var BaseQuery = /* @__PURE__ */ (() => {
class BaseQuery extends resource_1.APIResource {
/**
* Run a SQL query against account or zone-level datasets.
*
* Timestamp fields are RFC3339 strings. Filter with: WHERE {timestamp_field} >=
* now() - INTERVAL '30' DAY WHERE {timestamp_field} >= '2026-04-01T00:00:00Z'
* WHERE {timestamp_field} BETWEEN '2026-04-01T00:00:00Z' AND
* '2026-04-30T23:59:59Z'
*
* List configured account or zone datasets to see enabled account or zone-level
* datasets. Zone-level datasets will not appear here. List available account or
* zone datasets to inspect their schemas and timestamp fields.
*
* For more information about the datasets, and the meaning of each field, check
* out https://developers.cloudflare.com/logs/logpush/logpush-job/datasets/
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const querySqlResponse of client.logs.logExplorer.query.sql(
* fs.createReadStream('path/to/file'),
* { account_id: 'account_id' },
* )) {
* // ...
* }
* ```
*/
sql(body, params, options) {
const { account_id, zone_id } = params;
if (!account_id && !zone_id) {
throw new error_1.CloudflareError('You must provide either account_id or zone_id.');
}
if (account_id && zone_id) {
throw new error_1.CloudflareError('You cannot provide both account_id and zone_id.');
}
const { accountOrZone, accountOrZoneId } = account_id ?
{
accountOrZone: 'accounts',
accountOrZoneId: account_id,
}
: {
accountOrZone: 'zones',
accountOrZoneId: zone_id,
};
return this._client.getAPIList((0, path_1.path) `/${accountOrZone}/${accountOrZoneId}/logs/explorer/query/sql`, (pagination_1.SinglePage), {
body: body,
method: 'post',
...options,
headers: (0, headers_1.buildHeaders)([{ 'Content-Type': 'text/plain' }, options?.headers]),
});
}
}
BaseQuery._key = Object.freeze([
'logs',
'logExplorer',
'query',
]);
return BaseQuery;
})();
exports.BaseQuery = BaseQuery;
class Query extends BaseQuery {
}
exports.Query = Query;
//# sourceMappingURL=query.js.map