@mastra/clickhouse 1.30.0-alpha.0 → 1.30.0-alpha.2

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.
@@ -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.30.0-alpha.0"
6
+ version: "1.30.0-alpha.2"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -18,10 +18,5 @@ Read the individual reference documents for detailed explanations and code examp
18
18
 
19
19
  - [ClickHouse](references/integrations-databases-clickhouse.md) - Use ClickHouse as a Mastra analytical storage backend for observability, scores, and metrics with vNext or legacy storage domain configuration.
20
20
 
21
- ### Reference
22
-
23
- - [Reference: Composite storage](references/reference-storage-composite.md) - MastraCompositeStore can compose storage domains from different providers. Use it when you need different databases for different purposes.
24
- - [Reference: Storage retention (prune)](references/reference-storage-retention.md) - prune() deletes rows. It caps growth and is safe to run against large tables (batched, bounded, resumable, cancellable).
25
-
26
21
 
27
22
  Read [assets/SOURCE_MAP.json](assets/SOURCE_MAP.json) for source code references.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.30.0-alpha.0",
2
+ "version": "1.30.0-alpha.2",
3
3
  "package": "@mastra/clickhouse",
4
4
  "exports": {
5
5
  "COLUMN_TYPES": {
@@ -10,12 +10,12 @@
10
10
  "ClickhouseStore": {
11
11
  "types": "dist/storage/index.d.ts",
12
12
  "implementation": "dist/index.js",
13
- "line": 11892
13
+ "line": 11920
14
14
  },
15
15
  "ClickhouseStoreVNext": {
16
16
  "types": "dist/storage/index.d.ts",
17
17
  "implementation": "dist/index.js",
18
- "line": 12008
18
+ "line": 12036
19
19
  },
20
20
  "MemoryStorageClickhouse": {
21
21
  "types": "dist/storage/domains/memory/index.d.ts",
@@ -30,12 +30,12 @@
30
30
  "ObservabilityStorageClickhouseVNext": {
31
31
  "types": "dist/storage/domains/observability/v-next/index.d.ts",
32
32
  "implementation": "dist/index.js",
33
- "line": 10325
33
+ "line": 10338
34
34
  },
35
35
  "ScoresStorageClickhouse": {
36
36
  "types": "dist/storage/domains/scores/index.d.ts",
37
37
  "implementation": "dist/index.js",
38
- "line": 11196
38
+ "line": 11224
39
39
  },
40
40
  "TABLE_DELETION_REQUESTS": {
41
41
  "types": "dist/storage/domains/observability/v-next/ddl.d.ts",
@@ -50,12 +50,12 @@
50
50
  "WorkflowsStorageClickhouse": {
51
51
  "types": "dist/storage/domains/workflows/index.d.ts",
52
52
  "implementation": "dist/index.js",
53
- "line": 11597
53
+ "line": 11625
54
54
  },
55
55
  "applyClickHouseRetention": {
56
56
  "types": "dist/storage/domains/observability/v-next/index.d.ts",
57
57
  "implementation": "dist/index.js",
58
- "line": 10150
58
+ "line": 10163
59
59
  },
60
60
  "markDeletionRequestApplied": {
61
61
  "types": "dist/storage/domains/observability/v-next/deletion-requests.d.ts",
package/dist/index.cjs CHANGED
@@ -5092,7 +5092,7 @@ async function queryJson$2(client, query, params, settings = {}) {
5092
5092
  }
5093
5093
  })).json();
5094
5094
  }
5095
- async function feedbackRowsWithWriteVersions(client, feedbacks) {
5095
+ async function feedbackRowsWithWriteVersions(client, feedbacks, onConflict) {
5096
5096
  const identifiedFeedback = feedbacks.map((feedback) => ({
5097
5097
  ...feedback,
5098
5098
  feedbackId: feedback.feedbackId ?? ""
@@ -5103,23 +5103,29 @@ async function feedbackRowsWithWriteVersions(client, feedbacks) {
5103
5103
  WHERE feedbackId IN ({feedbackIds:Array(String)})
5104
5104
  GROUP BY feedbackId`, { feedbackIds });
5105
5105
  const versions = new Map(existingVersions.map((row) => [row.feedbackId, BigInt(row.writeVersion)]));
5106
- return identifiedFeedback.map((feedback) => {
5106
+ return identifiedFeedback.flatMap((feedback) => {
5107
+ if (onConflict === "ignore" && versions.has(feedback.feedbackId)) return [];
5107
5108
  const writeVersion = (versions.get(feedback.feedbackId) ?? 0n) + 1n;
5108
5109
  versions.set(feedback.feedbackId, writeVersion);
5109
- return {
5110
+ return [{
5110
5111
  ...feedbackRecordToRow(feedback),
5111
5112
  writeVersion: writeVersion.toString()
5112
- };
5113
+ }];
5113
5114
  });
5114
5115
  }
5115
5116
  async function createFeedback(client, args) {
5116
- await batchCreateFeedback(client, { feedbacks: [args.feedback] });
5117
+ await batchCreateFeedback(client, {
5118
+ feedbacks: [args.feedback],
5119
+ onConflict: args.onConflict
5120
+ });
5117
5121
  }
5118
5122
  async function batchCreateFeedback(client, args) {
5119
5123
  if (args.feedbacks.length === 0) return;
5124
+ const values = await feedbackRowsWithWriteVersions(client, args.feedbacks, args.onConflict);
5125
+ if (values.length === 0) return;
5120
5126
  await client.insert({
5121
5127
  table: TABLE_FEEDBACK_EVENTS,
5122
- values: await feedbackRowsWithWriteVersions(client, args.feedbacks),
5128
+ values,
5123
5129
  format: "JSONEachRow",
5124
5130
  clickhouse_settings: CH_INSERT_SETTINGS
5125
5131
  });
@@ -5200,6 +5206,13 @@ async function hasFeedbackDeletionRequest(client, feedbackId, organizationId, re
5200
5206
  resourceId: resourceId ?? ""
5201
5207
  }, FINAL_SKIP_INDEX_SETTINGS)).length > 0;
5202
5208
  }
5209
+ /** Retrieves the latest feedback record with this ID, or null when missing. */
5210
+ async function getFeedbackById(client, feedbackId) {
5211
+ const rows = await queryJson$2(client, `SELECT * FROM ${TABLE_FEEDBACK_EVENTS} FINAL
5212
+ WHERE feedbackId = {feedbackId:String}
5213
+ ORDER BY writeVersion DESC, timestamp DESC LIMIT 1`, { feedbackId }, FINAL_SKIP_INDEX_SETTINGS);
5214
+ return rows[0] ? rowToFeedbackRecord(rows[0]) : null;
5215
+ }
5203
5216
  /**
5204
5217
  * Review updates insert a replacement row, so they need only `INSERT` and the
5205
5218
  * insert materialized view publishes the delta cursor.
@@ -10490,6 +10503,7 @@ var ObservabilityStorageClickhouseVNext = class extends _mastra_core_storage.Obs
10490
10503
  "thread-query",
10491
10504
  "trace-query-tenant-scope",
10492
10505
  "feedback",
10506
+ "feedback-replacement",
10493
10507
  "trace-query-context-ids",
10494
10508
  ...contextFieldFeatures,
10495
10509
  ...timingFeatures,
@@ -10518,6 +10532,7 @@ var ObservabilityStorageClickhouseVNext = class extends _mastra_core_storage.Obs
10518
10532
  "thread-query",
10519
10533
  "trace-query-tenant-scope",
10520
10534
  "feedback",
10535
+ "feedback-replacement",
10521
10536
  "trace-query-context-ids",
10522
10537
  ...contextFieldFeatures,
10523
10538
  ...timingFeatures,
@@ -10865,6 +10880,19 @@ var ObservabilityStorageClickhouseVNext = class extends _mastra_core_storage.Obs
10865
10880
  }, error);
10866
10881
  }
10867
10882
  }
10883
+ async getFeedbackById(feedbackId) {
10884
+ try {
10885
+ return await getFeedbackById(this.#client, feedbackId);
10886
+ } catch (error) {
10887
+ if (error instanceof _mastra_core_error.MastraError) throw error;
10888
+ throw new _mastra_core_error.MastraError({
10889
+ id: (0, _mastra_core_storage.createStorageErrorId)("CLICKHOUSE", "GET_FEEDBACK_BY_ID", "FAILED"),
10890
+ domain: _mastra_core_error.ErrorDomain.STORAGE,
10891
+ category: _mastra_core_error.ErrorCategory.THIRD_PARTY,
10892
+ details: { feedbackId }
10893
+ }, error);
10894
+ }
10895
+ }
10868
10896
  async createFeedback(args) {
10869
10897
  try {
10870
10898
  await createFeedback(this.#client, args);