@mastra/clickhouse 1.27.0-alpha.0 → 1.27.0-alpha.1
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/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-storage-retention.md +1 -1
- package/dist/index.cjs +31 -62
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +30 -60
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-clickhouse
|
|
|
3
3
|
description: Documentation for @mastra/clickhouse. Use when working with @mastra/clickhouse APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/clickhouse"
|
|
6
|
-
version: "1.27.0-alpha.
|
|
6
|
+
version: "1.27.0-alpha.1"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -294,7 +294,7 @@ const storage = new MongoDBStore({
|
|
|
294
294
|
|
|
295
295
|
## Reclaiming disk
|
|
296
296
|
|
|
297
|
-
`prune()` deletes rows but doesn't shrink the database file. On SQLite/libSQL the freed pages go on a freelist
|
|
297
|
+
`prune()` deletes rows but doesn't shrink the database file. On SQLite/libSQL the freed pages go on a freelist for reuse by future writes. Reusing these pages prevents unbounded file growth for most users.
|
|
298
298
|
|
|
299
299
|
Handing that free space back to the OS is a separate concern that Mastra doesn't manage. If you specifically need to shrink the file, run the underlying database's compaction (for example `VACUUM` on self-hosted libSQL) yourself in a maintenance window. A full `VACUUM` locks the file and needs roughly twice the file size in free disk. On PostgreSQL, autovacuum reclaims dead tuples for reuse automatically. A manual `VACUUM FULL` is only needed if you must return disk to the OS.
|
|
300
300
|
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
2
|
+
// \0rolldown/runtime.js
|
|
3
3
|
var __create = Object.create;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -20,7 +20,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
20
20
|
value: mod,
|
|
21
21
|
enumerable: true
|
|
22
22
|
}) : target, mod));
|
|
23
|
-
//#endregion
|
|
24
23
|
let _clickhouse_client = require("@clickhouse/client");
|
|
25
24
|
let _mastra_core_error = require("@mastra/core/error");
|
|
26
25
|
let _mastra_core_storage = require("@mastra/core/storage");
|
|
@@ -31,7 +30,7 @@ let _mastra_core_utils = require("@mastra/core/utils");
|
|
|
31
30
|
let _mastra_core_features = require("@mastra/core/features");
|
|
32
31
|
let zod_v4 = require("zod/v4");
|
|
33
32
|
let _mastra_core_evals = require("@mastra/core/evals");
|
|
34
|
-
|
|
33
|
+
// src/storage/db/replication.ts
|
|
35
34
|
const DEFAULT_ZOOKEEPER_PATH = "/clickhouse/tables/{shard}/{database}/{table}";
|
|
36
35
|
const DEFAULT_REPLICA_NAME = "{replica}";
|
|
37
36
|
const SUPPORTED_ENGINE_NAMES = /* @__PURE__ */ new Set([
|
|
@@ -231,8 +230,7 @@ function rewriteEngineClauses(sql, replication) {
|
|
|
231
230
|
function applyReplicationToDDL(sql, replication) {
|
|
232
231
|
return addOnClusterToDDL(replication ? rewriteEngineClauses(sql, replication) : sql, replication);
|
|
233
232
|
}
|
|
234
|
-
|
|
235
|
-
//#region src/storage/db/utils.ts
|
|
233
|
+
// src/storage/db/utils.ts
|
|
236
234
|
const TABLE_ENGINES = {
|
|
237
235
|
[_mastra_core_storage.TABLE_MESSAGES]: `MergeTree()`,
|
|
238
236
|
[_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT]: `ReplacingMergeTree()`,
|
|
@@ -341,8 +339,7 @@ function transformRow(row) {
|
|
|
341
339
|
function transformRows(rows) {
|
|
342
340
|
return rows.map((row) => transformRow(row));
|
|
343
341
|
}
|
|
344
|
-
|
|
345
|
-
//#region src/storage/db/index.ts
|
|
342
|
+
// src/storage/db/index.ts
|
|
346
343
|
/**
|
|
347
344
|
* Resolves ClickhouseDomainConfig to a ClickHouse client and ttl config.
|
|
348
345
|
* Handles creating a new client if config is provided.
|
|
@@ -868,8 +865,7 @@ var ClickhouseDB = class extends _mastra_core_base.MastraBase {
|
|
|
868
865
|
}
|
|
869
866
|
}
|
|
870
867
|
};
|
|
871
|
-
|
|
872
|
-
//#region src/storage/domains/memory/index.ts
|
|
868
|
+
// src/storage/domains/memory/index.ts
|
|
873
869
|
/**
|
|
874
870
|
* Serialize metadata object to JSON string for storage in ClickHouse.
|
|
875
871
|
* Ensures we always store valid JSON, defaulting to '{}' for null/undefined.
|
|
@@ -2012,8 +2008,7 @@ var MemoryStorageClickhouse = class extends _mastra_core_storage.MemoryStorage {
|
|
|
2012
2008
|
}
|
|
2013
2009
|
}
|
|
2014
2010
|
};
|
|
2015
|
-
|
|
2016
|
-
//#region src/storage/domains/observability/index.ts
|
|
2011
|
+
// src/storage/domains/observability/index.ts
|
|
2017
2012
|
var ObservabilityStorageClickhouse = class extends _mastra_core_storage.ObservabilityStorage {
|
|
2018
2013
|
client;
|
|
2019
2014
|
#db;
|
|
@@ -2618,8 +2613,7 @@ var ObservabilityStorageClickhouse = class extends _mastra_core_storage.Observab
|
|
|
2618
2613
|
}
|
|
2619
2614
|
}
|
|
2620
2615
|
};
|
|
2621
|
-
|
|
2622
|
-
//#region src/storage/domains/observability/v-next/ddl.ts
|
|
2616
|
+
// src/storage/domains/observability/v-next/ddl.ts
|
|
2623
2617
|
const TABLE_SPAN_EVENTS = "mastra_span_events";
|
|
2624
2618
|
const TABLE_TRACE_ROOTS = "mastra_trace_roots";
|
|
2625
2619
|
const TABLE_TRACE_BRANCHES = "mastra_trace_branches";
|
|
@@ -3822,8 +3816,7 @@ function parseTtlExpression(expr) {
|
|
|
3822
3816
|
days
|
|
3823
3817
|
};
|
|
3824
3818
|
}
|
|
3825
|
-
|
|
3826
|
-
//#region src/storage/domains/observability/v-next/preview-compat.ts
|
|
3819
|
+
// src/storage/domains/observability/v-next/preview-compat.ts
|
|
3827
3820
|
const generator = _mastra_core_storage.buildStoredPreview;
|
|
3828
3821
|
const canGeneratePreviews = typeof generator === "function";
|
|
3829
3822
|
function needsPreview(value) {
|
|
@@ -3876,8 +3869,7 @@ function buildSpanQueryResponse(...args) {
|
|
|
3876
3869
|
}
|
|
3877
3870
|
return response;
|
|
3878
3871
|
}
|
|
3879
|
-
|
|
3880
|
-
//#region src/storage/domains/observability/v-next/previews.ts
|
|
3872
|
+
// src/storage/domains/observability/v-next/previews.ts
|
|
3881
3873
|
/**
|
|
3882
3874
|
* Stored span previews (`inputPreview` / `outputPreview` / `errorPreview`).
|
|
3883
3875
|
*
|
|
@@ -3912,8 +3904,7 @@ function resolveStoredPreviews(row, payloads = row) {
|
|
|
3912
3904
|
}
|
|
3913
3905
|
return previews;
|
|
3914
3906
|
}
|
|
3915
|
-
|
|
3916
|
-
//#region src/storage/domains/observability/v-next/review-status.ts
|
|
3907
|
+
// src/storage/domains/observability/v-next/review-status.ts
|
|
3917
3908
|
const FEEDBACK_REVIEW_STATUSES = ["needs-review", "reviewed"];
|
|
3918
3909
|
function isFeedbackReviewStatus(value) {
|
|
3919
3910
|
return FEEDBACK_REVIEW_STATUSES.some((status) => status === value);
|
|
@@ -3937,8 +3928,7 @@ function parseUpdateFeedbackReviewStatusArgs(args) {
|
|
|
3937
3928
|
reviewStatus: args.reviewStatus
|
|
3938
3929
|
};
|
|
3939
3930
|
}
|
|
3940
|
-
|
|
3941
|
-
//#region src/storage/domains/observability/v-next/helpers.ts
|
|
3931
|
+
// src/storage/domains/observability/v-next/helpers.ts
|
|
3942
3932
|
const CH_SETTINGS = {
|
|
3943
3933
|
date_time_input_format: "best_effort",
|
|
3944
3934
|
date_time_output_format: "iso",
|
|
@@ -4508,8 +4498,7 @@ function feedbackRecordToRow(feedback) {
|
|
|
4508
4498
|
scope: jsonEncode(feedback.scope)
|
|
4509
4499
|
};
|
|
4510
4500
|
}
|
|
4511
|
-
|
|
4512
|
-
//#region src/storage/domains/observability/v-next/deletion-requests.ts
|
|
4501
|
+
// src/storage/domains/observability/v-next/deletion-requests.ts
|
|
4513
4502
|
const EPOCH = "1970-01-01T00:00:00.000Z";
|
|
4514
4503
|
async function recordDeletionRequest(client, args) {
|
|
4515
4504
|
const row = {
|
|
@@ -4566,8 +4555,7 @@ async function insertDeletionRequest(client, row, replication) {
|
|
|
4566
4555
|
} : CH_INSERT_SETTINGS
|
|
4567
4556
|
});
|
|
4568
4557
|
}
|
|
4569
|
-
|
|
4570
|
-
//#region src/storage/domains/observability/v-next/discovery.ts
|
|
4558
|
+
// src/storage/domains/observability/v-next/discovery.ts
|
|
4571
4559
|
async function queryJson$3(client, query, params = {}) {
|
|
4572
4560
|
return await (await client.query({
|
|
4573
4561
|
query,
|
|
@@ -4607,8 +4595,7 @@ async function getTags(client, args) {
|
|
|
4607
4595
|
}
|
|
4608
4596
|
return { tags: (await queryJson$3(client, `SELECT DISTINCT value FROM ${TABLE_DISCOVERY_VALUES} WHERE ${conditions.join(" AND ")} ORDER BY value`, params)).map((r) => r.value) };
|
|
4609
4597
|
}
|
|
4610
|
-
|
|
4611
|
-
//#region src/storage/domains/observability/v-next/filters.ts
|
|
4598
|
+
// src/storage/domains/observability/v-next/filters.ts
|
|
4612
4599
|
/**
|
|
4613
4600
|
* ClickHouse v-next filter builders.
|
|
4614
4601
|
*
|
|
@@ -4880,8 +4867,7 @@ function buildPaginationClause(pagination) {
|
|
|
4880
4867
|
offset: page * perPage
|
|
4881
4868
|
};
|
|
4882
4869
|
}
|
|
4883
|
-
|
|
4884
|
-
//#region src/storage/domains/observability/v-next/polling.ts
|
|
4870
|
+
// src/storage/domains/observability/v-next/polling.ts
|
|
4885
4871
|
const OBSERVABILITY_DELTA_POLLING_FEATURE = "observability-delta-polling";
|
|
4886
4872
|
function deltaPollingFeatureEnabled() {
|
|
4887
4873
|
return _mastra_core_features.coreFeatures.has(OBSERVABILITY_DELTA_POLLING_FEATURE);
|
|
@@ -4912,8 +4898,7 @@ function appendWhere(whereClause, ...conditions) {
|
|
|
4912
4898
|
const parts = [whereClause.replace(/^\s*WHERE\s+/i, ""), ...conditions].filter(Boolean);
|
|
4913
4899
|
return parts.length > 0 ? `WHERE ${parts.join(" AND ")}` : "";
|
|
4914
4900
|
}
|
|
4915
|
-
|
|
4916
|
-
//#region src/storage/domains/observability/v-next/feedback.ts
|
|
4901
|
+
// src/storage/domains/observability/v-next/feedback.ts
|
|
4917
4902
|
const FEEDBACK_TYPED_COLUMNS = /* @__PURE__ */ new Set([
|
|
4918
4903
|
"timestamp",
|
|
4919
4904
|
"traceId",
|
|
@@ -5415,8 +5400,7 @@ async function getFeedbackPercentiles(client, args) {
|
|
|
5415
5400
|
}))
|
|
5416
5401
|
})) };
|
|
5417
5402
|
}
|
|
5418
|
-
|
|
5419
|
-
//#region src/storage/domains/observability/v-next/logs.ts
|
|
5403
|
+
// src/storage/domains/observability/v-next/logs.ts
|
|
5420
5404
|
async function batchCreateLogs(client, args) {
|
|
5421
5405
|
if (args.logs.length === 0) return;
|
|
5422
5406
|
await client.insert({
|
|
@@ -5555,8 +5539,7 @@ async function getStreamHeadCursor$4(client) {
|
|
|
5555
5539
|
function buildLogsCursor(row) {
|
|
5556
5540
|
return row.cursorId ?? "0";
|
|
5557
5541
|
}
|
|
5558
|
-
|
|
5559
|
-
//#region src/storage/domains/observability/v-next/metrics.ts
|
|
5542
|
+
// src/storage/domains/observability/v-next/metrics.ts
|
|
5560
5543
|
/** Map typed columns to their ClickHouse column names. */
|
|
5561
5544
|
const METRIC_TYPED_COLUMNS = /* @__PURE__ */ new Set([
|
|
5562
5545
|
"timestamp",
|
|
@@ -6053,8 +6036,7 @@ async function getMetricLabelValues(client, args) {
|
|
|
6053
6036
|
if (args.limit) params.valLimit = args.limit;
|
|
6054
6037
|
return { values: (await queryJson$1(client, `SELECT DISTINCT value FROM ${TABLE_DISCOVERY_PAIRS} WHERE ${conditions.join(" AND ")} ORDER BY value ${limitClause}`, params)).map((r) => r.value) };
|
|
6055
6038
|
}
|
|
6056
|
-
|
|
6057
|
-
//#region src/storage/domains/observability/v-next/migration.ts
|
|
6039
|
+
// src/storage/domains/observability/v-next/migration.ts
|
|
6058
6040
|
const SIGNAL_MIGRATIONS = [
|
|
6059
6041
|
{
|
|
6060
6042
|
table: TABLE_METRIC_EVENTS,
|
|
@@ -6370,8 +6352,7 @@ async function migrateSignalTables(client, logger) {
|
|
|
6370
6352
|
}
|
|
6371
6353
|
}
|
|
6372
6354
|
}
|
|
6373
|
-
|
|
6374
|
-
//#region src/storage/domains/observability/v-next/score-current.ts
|
|
6355
|
+
// src/storage/domains/observability/v-next/score-current.ts
|
|
6375
6356
|
const SCORE_CURRENT_BACKFILL_MARKER = "v1";
|
|
6376
6357
|
async function backfillCurrentScores(client) {
|
|
6377
6358
|
const markerRows = await (await client.query({
|
|
@@ -6400,8 +6381,7 @@ async function backfillCurrentScores(client) {
|
|
|
6400
6381
|
query_params: { marker: SCORE_CURRENT_BACKFILL_MARKER }
|
|
6401
6382
|
});
|
|
6402
6383
|
}
|
|
6403
|
-
|
|
6404
|
-
//#region src/storage/domains/observability/v-next/scores.ts
|
|
6384
|
+
// src/storage/domains/observability/v-next/scores.ts
|
|
6405
6385
|
const SCORE_TYPED_COLUMNS = /* @__PURE__ */ new Set([
|
|
6406
6386
|
"timestamp",
|
|
6407
6387
|
"traceId",
|
|
@@ -6868,8 +6848,7 @@ async function getScorePercentiles(client, args) {
|
|
|
6868
6848
|
}))
|
|
6869
6849
|
})) };
|
|
6870
6850
|
}
|
|
6871
|
-
|
|
6872
|
-
//#region src/storage/domains/observability/v-next/trace-query.ts
|
|
6851
|
+
// src/storage/domains/observability/v-next/trace-query.ts
|
|
6873
6852
|
const TRACE_STATUS_SQL = `if(isNotNull(r.error), 'error', 'success')`;
|
|
6874
6853
|
/**
|
|
6875
6854
|
* Core versions without the field reject it in strict query results, so it is only returned when core knows it.
|
|
@@ -8031,8 +8010,7 @@ function compileThreadQueryPredicate(predicate, parameters = new ParameterBuilde
|
|
|
8031
8010
|
params: parameters.params
|
|
8032
8011
|
};
|
|
8033
8012
|
}
|
|
8034
|
-
|
|
8035
|
-
//#region src/storage/domains/observability/v-next/span-query.ts
|
|
8013
|
+
// src/storage/domains/observability/v-next/span-query.ts
|
|
8036
8014
|
const identityFields = [
|
|
8037
8015
|
"organizationId",
|
|
8038
8016
|
"resourceId",
|
|
@@ -8389,8 +8367,7 @@ async function querySpans(client, plan, timeoutMs) {
|
|
|
8389
8367
|
}) : null;
|
|
8390
8368
|
return result;
|
|
8391
8369
|
}
|
|
8392
|
-
|
|
8393
|
-
//#region src/storage/domains/observability/v-next/thread-query.ts
|
|
8370
|
+
// src/storage/domains/observability/v-next/thread-query.ts
|
|
8394
8371
|
const contextFields = [
|
|
8395
8372
|
"resourceId",
|
|
8396
8373
|
"userId",
|
|
@@ -8684,8 +8661,7 @@ async function queryThreadRows(client, plan, timeoutMs, strategy = "auto") {
|
|
|
8684
8661
|
}) : null }
|
|
8685
8662
|
};
|
|
8686
8663
|
}
|
|
8687
|
-
|
|
8688
|
-
//#region src/storage/domains/observability/v-next/trace-aggregate.ts
|
|
8664
|
+
// src/storage/domains/observability/v-next/trace-aggregate.ts
|
|
8689
8665
|
/** Trace-root column expressions (alias `r`) for each groupable dimension; same values `where` sees. */
|
|
8690
8666
|
const DIMENSION_SQL = {
|
|
8691
8667
|
entityType: "r.entityType",
|
|
@@ -9018,8 +8994,7 @@ async function runAggregate(client, plan, compiled, timeoutMs) {
|
|
|
9018
8994
|
truncated
|
|
9019
8995
|
};
|
|
9020
8996
|
}
|
|
9021
|
-
|
|
9022
|
-
//#region src/storage/domains/observability/v-next/trace-roots.ts
|
|
8997
|
+
// src/storage/domains/observability/v-next/trace-roots.ts
|
|
9023
8998
|
/**
|
|
9024
8999
|
* Get the root span for a trace, reading from trace_roots as compatibility path.
|
|
9025
9000
|
* Uses ordinary LIMIT 1 (duplicates are byte-identical per design).
|
|
@@ -9296,8 +9271,7 @@ async function getStreamHeadCursor$1(client) {
|
|
|
9296
9271
|
function buildTraceCursor(row) {
|
|
9297
9272
|
return row.cursorId ?? "0";
|
|
9298
9273
|
}
|
|
9299
|
-
|
|
9300
|
-
//#region src/storage/domains/observability/v-next/tracing.ts
|
|
9274
|
+
// src/storage/domains/observability/v-next/tracing.ts
|
|
9301
9275
|
const BRANCH_SPAN_TYPE_SQL_LIST = _mastra_core_storage.BRANCH_SPAN_TYPES.map((t) => `'${t}'`).join(", ");
|
|
9302
9276
|
/** Insert a single completed span. */
|
|
9303
9277
|
async function createSpan(client, args) {
|
|
@@ -9887,8 +9861,7 @@ async function getStreamHeadCursor(client) {
|
|
|
9887
9861
|
function buildBranchCursor(row) {
|
|
9888
9862
|
return row.cursorId ?? "0";
|
|
9889
9863
|
}
|
|
9890
|
-
|
|
9891
|
-
//#region src/storage/domains/observability/v-next/index.ts
|
|
9864
|
+
// src/storage/domains/observability/v-next/index.ts
|
|
9892
9865
|
const spanQueryFeatures = typeof _mastra_core_storage.planSpanQuery === "function" ? ["span-query", "span-query-context-fields"] : [];
|
|
9893
9866
|
const spanAggregateFeatures = typeof _mastra_core_storage.planSpanAggregate === "function" ? ["span-aggregate"] : [];
|
|
9894
9867
|
const threadQueryFeatures = typeof _mastra_core_storage.planThreadRowsQuery === "function" ? ["thread-query-rows"] : [];
|
|
@@ -11026,8 +10999,7 @@ var ObservabilityStorageClickhouseVNext = class extends _mastra_core_storage.Obs
|
|
|
11026
10999
|
}
|
|
11027
11000
|
}
|
|
11028
11001
|
};
|
|
11029
|
-
|
|
11030
|
-
//#region src/storage/domains/scores/index.ts
|
|
11002
|
+
// src/storage/domains/scores/index.ts
|
|
11031
11003
|
/**
|
|
11032
11004
|
* Builds a multi-tenant scope SQL fragment and its named query params.
|
|
11033
11005
|
* Returns a clause prefixed with ` AND ` (empty when no filters) plus params.
|
|
@@ -11448,8 +11420,7 @@ var ScoresStorageClickhouse = class extends _mastra_core_storage.ScoresStorage {
|
|
|
11448
11420
|
}
|
|
11449
11421
|
}
|
|
11450
11422
|
};
|
|
11451
|
-
|
|
11452
|
-
//#region src/storage/domains/workflows/index.ts
|
|
11423
|
+
// src/storage/domains/workflows/index.ts
|
|
11453
11424
|
var WorkflowsStorageClickhouse = class extends _mastra_core_storage.WorkflowsStorage {
|
|
11454
11425
|
client;
|
|
11455
11426
|
#db;
|
|
@@ -11716,8 +11687,7 @@ var WorkflowsStorageClickhouse = class extends _mastra_core_storage.WorkflowsSto
|
|
|
11716
11687
|
}
|
|
11717
11688
|
}
|
|
11718
11689
|
};
|
|
11719
|
-
|
|
11720
|
-
//#region src/storage/index.ts
|
|
11690
|
+
// src/storage/index.ts
|
|
11721
11691
|
/**
|
|
11722
11692
|
* Type guard for pre-configured client config
|
|
11723
11693
|
*/
|
|
@@ -11880,7 +11850,6 @@ var ClickhouseStoreVNext = class extends ClickhouseStore {
|
|
|
11880
11850
|
};
|
|
11881
11851
|
}
|
|
11882
11852
|
};
|
|
11883
|
-
//#endregion
|
|
11884
11853
|
exports.COLUMN_TYPES = COLUMN_TYPES;
|
|
11885
11854
|
exports.ClickhouseStore = ClickhouseStore;
|
|
11886
11855
|
exports.ClickhouseStoreVNext = ClickhouseStoreVNext;
|