@staff0rd/assist 0.165.1 → 0.166.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.
Files changed (2) hide show
  1. package/dist/index.js +54 -9
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import { Command } from "commander";
6
6
  // package.json
7
7
  var package_default = {
8
8
  name: "@staff0rd/assist",
9
- version: "0.165.1",
9
+ version: "0.166.0",
10
10
  type: "module",
11
11
  main: "dist/index.js",
12
12
  bin: {
@@ -9092,10 +9092,10 @@ var seqAuth = createConnectionAuth({
9092
9092
  // src/commands/seq/seqQuery.ts
9093
9093
  import chalk111 from "chalk";
9094
9094
 
9095
- // src/commands/seq/fetchSeqEvents.ts
9095
+ // src/commands/seq/fetchSeq.ts
9096
9096
  import chalk108 from "chalk";
9097
- async function fetchSeqEvents(conn, params) {
9098
- const url = `${conn.url}/api/events?${params}`;
9097
+ async function fetchSeq(conn, path50, params) {
9098
+ const url = `${conn.url}${path50}?${params}`;
9099
9099
  const response = await fetch(url, {
9100
9100
  headers: {
9101
9101
  Accept: "application/json",
@@ -9107,6 +9107,52 @@ async function fetchSeqEvents(conn, params) {
9107
9107
  console.error(chalk108.red(`Seq returned ${response.status}: ${body}`));
9108
9108
  process.exit(1);
9109
9109
  }
9110
+ return response;
9111
+ }
9112
+
9113
+ // src/commands/seq/filterToSql.ts
9114
+ function filterToSql(filter) {
9115
+ return filter.replace(/==/g, "=").replace(/"([^"]*)"/g, "'$1'");
9116
+ }
9117
+
9118
+ // src/commands/seq/fetchSeqData.ts
9119
+ async function fetchSeqData(conn, filter, count, from) {
9120
+ const sqlFilter = filterToSql(filter);
9121
+ const sql = `select @Timestamp, @Level, @Exception, @Message from stream where ${sqlFilter} order by @Timestamp desc limit ${count}`;
9122
+ const params = new URLSearchParams({ q: sql, fromDateUtc: from });
9123
+ const response = await fetchSeq(conn, "/api/data", params);
9124
+ const data = await response.json();
9125
+ return mapDataToEvents(data);
9126
+ }
9127
+ function ticksToIso(value) {
9128
+ if (typeof value === "string") return value;
9129
+ const ticks = Number(value);
9130
+ const epochTicks = 621355968e9;
9131
+ return new Date((ticks - epochTicks) / 1e4).toISOString();
9132
+ }
9133
+ function mapDataToEvents(data) {
9134
+ const colIndex = new Map(data.Columns.map((c, i) => [c, i]));
9135
+ function col(name) {
9136
+ const idx = colIndex.get(name) ?? colIndex.get(`@${name}`);
9137
+ if (idx === void 0) throw new Error(`Missing column: ${name}`);
9138
+ return idx;
9139
+ }
9140
+ const tsIdx = col("Timestamp");
9141
+ const levelIdx = col("Level");
9142
+ const exIdx = col("Exception");
9143
+ const msgIdx = col("Message");
9144
+ return data.Rows.map((row) => ({
9145
+ Timestamp: ticksToIso(row[tsIdx]),
9146
+ Level: String(row[levelIdx] ?? ""),
9147
+ Exception: row[exIdx] != null ? String(row[exIdx]) : void 0,
9148
+ Properties: [],
9149
+ MessageTemplateTokens: [{ Text: String(row[msgIdx] ?? "") }]
9150
+ }));
9151
+ }
9152
+
9153
+ // src/commands/seq/fetchSeqEvents.ts
9154
+ async function fetchSeqEvents(conn, params) {
9155
+ const response = await fetchSeq(conn, "/api/events", params);
9110
9156
  return response.json();
9111
9157
  }
9112
9158
 
@@ -9202,11 +9248,10 @@ function resolveConnection2(name) {
9202
9248
  async function seqQuery(filter, options2) {
9203
9249
  const conn = resolveConnection2(options2.connection);
9204
9250
  const count = Number.parseInt(options2.count ?? "1000", 10);
9205
- const params = new URLSearchParams({ filter, count: String(count) });
9206
- if (options2.from) {
9207
- params.set("fromDateUtc", options2.from);
9208
- }
9209
- const events = await fetchSeqEvents(conn, params);
9251
+ const events = options2.from ? await fetchSeqData(conn, filter, count, options2.from) : await fetchSeqEvents(
9252
+ conn,
9253
+ new URLSearchParams({ filter, count: String(count) })
9254
+ );
9210
9255
  if (events.length === 0) {
9211
9256
  console.log(chalk111.yellow("No events found."));
9212
9257
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@staff0rd/assist",
3
- "version": "0.165.1",
3
+ "version": "0.166.0",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "bin": {