@mastra/pg 1.32.0-alpha.4 → 1.32.0-alpha.6
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/docs-memory-semantic-recall.md +20 -0
- package/dist/docs/references/reference-memory-memory-class.md +2 -0
- package/dist/index.cjs +123 -95
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +122 -94
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/index.d.ts +1 -1
- package/dist/storage/domains/observability/v-next/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/trace-aggregate.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/trace-query.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -161,12 +161,14 @@ var PGFilterTranslator = class extends BaseFilterTranslator {
|
|
|
161
161
|
if (key === "$options") continue;
|
|
162
162
|
const newPath = currentPath ? `${currentPath}.${key}` : key;
|
|
163
163
|
if (this.isLogicalOperator(key)) result[key] = Array.isArray(value) ? value.map((filter) => this.translateNode(filter)) : this.translateNode(value);
|
|
164
|
-
else if (this.isOperator(key))
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
else
|
|
169
|
-
|
|
164
|
+
else if (this.isOperator(key)) {
|
|
165
|
+
if (this.isArrayOperator(key) && !Array.isArray(value) && key !== "$elemMatch") result[key] = [value];
|
|
166
|
+
else if (this.isBasicOperator(key) && Array.isArray(value)) result[key] = JSON.stringify(value);
|
|
167
|
+
else result[key] = value;
|
|
168
|
+
} else if (typeof value === "object" && value !== null) {
|
|
169
|
+
if (Object.keys(value).some((k) => this.isOperator(k))) result[newPath] = this.translateNode(value);
|
|
170
|
+
else Object.assign(result, this.translateNode(value, newPath));
|
|
171
|
+
} else result[newPath] = this.translateNode(value);
|
|
170
172
|
}
|
|
171
173
|
return result;
|
|
172
174
|
}
|
|
@@ -1427,19 +1429,21 @@ var PgVector = class extends MastraVector {
|
|
|
1427
1429
|
try {
|
|
1428
1430
|
existingIndexInfo = await this.describeIndexMetadata({ indexName }, client);
|
|
1429
1431
|
dimension = existingIndexInfo.dimension;
|
|
1430
|
-
if (isConfigEmpty && existingIndexInfo.metric === metric)
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1432
|
+
if (isConfigEmpty && existingIndexInfo.metric === metric) {
|
|
1433
|
+
if (existingIndexInfo.type === "flat") this.logger?.debug(`No index exists for ${vectorIndexName}, will create default ivfflat index`);
|
|
1434
|
+
else {
|
|
1435
|
+
this.logger?.debug(`Index ${vectorIndexName} already exists (type: ${existingIndexInfo.type}, metric: ${existingIndexInfo.metric}), preserving existing configuration`);
|
|
1436
|
+
const cacheKey = await this.getIndexCacheKey({
|
|
1437
|
+
indexName,
|
|
1438
|
+
dimension,
|
|
1439
|
+
type: existingIndexInfo.type,
|
|
1440
|
+
metric: existingIndexInfo.metric,
|
|
1441
|
+
vectorType: existingIndexInfo.vectorType
|
|
1442
|
+
});
|
|
1443
|
+
this.createdIndexes.set(indexName, cacheKey);
|
|
1444
|
+
this.indexVectorTypes.set(indexName, existingIndexInfo.vectorType);
|
|
1445
|
+
return;
|
|
1446
|
+
}
|
|
1443
1447
|
}
|
|
1444
1448
|
let configMatches = existingIndexInfo.metric === metric && existingIndexInfo.type === indexType;
|
|
1445
1449
|
if (indexType === "hnsw") configMatches = configMatches && existingIndexInfo.config.m === (indexConfig.hnsw?.m ?? 8) && existingIndexInfo.config.efConstruction === (indexConfig.hnsw?.efConstruction ?? 32);
|
|
@@ -2945,19 +2949,13 @@ var PgDB = class extends MastraBase {
|
|
|
2945
2949
|
return filtered;
|
|
2946
2950
|
}
|
|
2947
2951
|
async hasColumn(table, column) {
|
|
2948
|
-
const schema = this.schemaName || "public";
|
|
2949
2952
|
const snapshot = this.schemaSnapshot;
|
|
2950
2953
|
if (snapshot) {
|
|
2951
2954
|
const columns = snapshot.columns.get(table);
|
|
2952
2955
|
if (!columns) return false;
|
|
2953
2956
|
return columns.has(column) || columns.has(column.toLowerCase());
|
|
2954
2957
|
}
|
|
2955
|
-
return
|
|
2956
|
-
schema,
|
|
2957
|
-
table,
|
|
2958
|
-
column,
|
|
2959
|
-
column.toLowerCase()
|
|
2960
|
-
]);
|
|
2958
|
+
return await this.getColumnType(table, column) !== null;
|
|
2961
2959
|
}
|
|
2962
2960
|
/**
|
|
2963
2961
|
* Returns the Postgres data type of a column (e.g. `jsonb`, `json`, `text`),
|
|
@@ -2979,7 +2977,7 @@ var PgDB = class extends MastraBase {
|
|
|
2979
2977
|
const cached = this.columnTypeCache.get(table)?.get(column);
|
|
2980
2978
|
if (cached !== void 0) return cached;
|
|
2981
2979
|
const schema = this.schemaName || "public";
|
|
2982
|
-
const dataType = (await this.client.oneOrNone(`SELECT data_type FROM information_schema.columns WHERE table_schema = $1 AND table_name = $2 AND (column_name = $3 OR column_name = $4)`, [
|
|
2980
|
+
const dataType = (await this.client.oneOrNone(`SELECT data_type FROM information_schema.columns WHERE table_schema = $1 AND table_name = $2 AND (column_name = $3 OR column_name = $4) ORDER BY (column_name = $3) DESC LIMIT 1`, [
|
|
2983
2981
|
schema,
|
|
2984
2982
|
table,
|
|
2985
2983
|
column,
|
|
@@ -5368,15 +5366,19 @@ var BackgroundTasksPG = class BackgroundTasksPG extends BackgroundTasksStorage {
|
|
|
5368
5366
|
where += ` AND "status" = $${paramIdx++}`;
|
|
5369
5367
|
params.push(options.expectedStatus);
|
|
5370
5368
|
}
|
|
5371
|
-
if (options?.expectedOwnerId !== void 0)
|
|
5372
|
-
|
|
5373
|
-
|
|
5374
|
-
|
|
5369
|
+
if (options?.expectedOwnerId !== void 0) {
|
|
5370
|
+
if (options.expectedOwnerId === null) where += ` AND "ownerId" IS NULL`;
|
|
5371
|
+
else {
|
|
5372
|
+
where += ` AND "ownerId" = $${paramIdx++}`;
|
|
5373
|
+
params.push(options.expectedOwnerId);
|
|
5374
|
+
}
|
|
5375
5375
|
}
|
|
5376
|
-
if (options?.expectedLeaseExpiresAt !== void 0)
|
|
5377
|
-
|
|
5378
|
-
|
|
5379
|
-
|
|
5376
|
+
if (options?.expectedLeaseExpiresAt !== void 0) {
|
|
5377
|
+
if (options.expectedLeaseExpiresAt === null) where += ` AND "leaseExpiresAtZ" IS NULL`;
|
|
5378
|
+
else {
|
|
5379
|
+
where += ` AND "leaseExpiresAtZ" = $${paramIdx++}`;
|
|
5380
|
+
params.push(options.expectedLeaseExpiresAt.toISOString());
|
|
5381
|
+
}
|
|
5380
5382
|
}
|
|
5381
5383
|
return ((await this.#db.client.query(`UPDATE ${table} SET ${setClauses.join(", ")} WHERE ${where}`, params)).rowCount ?? 0) > 0;
|
|
5382
5384
|
}
|
|
@@ -5674,9 +5676,10 @@ var ChannelsPG = class ChannelsPG extends ChannelsStorage {
|
|
|
5674
5676
|
await this.#db.clearTable({ tableName: TABLE_CHANNEL_CONFIG });
|
|
5675
5677
|
}
|
|
5676
5678
|
async saveInstallation(installation) {
|
|
5679
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
5677
5680
|
const tableName = getTableName$5({
|
|
5678
5681
|
indexName: TABLE_CHANNEL_INSTALLATIONS,
|
|
5679
|
-
schemaName
|
|
5682
|
+
schemaName
|
|
5680
5683
|
});
|
|
5681
5684
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
5682
5685
|
const createdAt = installation.createdAt?.toISOString() ?? now;
|
|
@@ -5707,47 +5710,53 @@ var ChannelsPG = class ChannelsPG extends ChannelsStorage {
|
|
|
5707
5710
|
]);
|
|
5708
5711
|
}
|
|
5709
5712
|
async getInstallation(id) {
|
|
5713
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
5710
5714
|
const tableName = getTableName$5({
|
|
5711
5715
|
indexName: TABLE_CHANNEL_INSTALLATIONS,
|
|
5712
|
-
schemaName
|
|
5716
|
+
schemaName
|
|
5713
5717
|
});
|
|
5714
5718
|
const row = await this.#db.readClient.oneOrNone(`SELECT * FROM ${tableName} WHERE "id" = $1`, [id]);
|
|
5715
5719
|
return row ? this.#parseInstallationRow(row) : null;
|
|
5716
5720
|
}
|
|
5717
5721
|
async getInstallationByAgent(platform, agentId) {
|
|
5722
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
5718
5723
|
const tableName = getTableName$5({
|
|
5719
5724
|
indexName: TABLE_CHANNEL_INSTALLATIONS,
|
|
5720
|
-
schemaName
|
|
5725
|
+
schemaName
|
|
5721
5726
|
});
|
|
5722
5727
|
const row = await this.#db.readClient.oneOrNone(`SELECT * FROM ${tableName} WHERE "platform" = $1 AND "agentId" = $2 ORDER BY CASE "status" WHEN 'active' THEN 0 WHEN 'pending' THEN 1 ELSE 2 END, "updatedAt" DESC LIMIT 1`, [platform, agentId]);
|
|
5723
5728
|
return row ? this.#parseInstallationRow(row) : null;
|
|
5724
5729
|
}
|
|
5725
5730
|
async getInstallationByWebhookId(webhookId) {
|
|
5731
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
5726
5732
|
const tableName = getTableName$5({
|
|
5727
5733
|
indexName: TABLE_CHANNEL_INSTALLATIONS,
|
|
5728
|
-
schemaName
|
|
5734
|
+
schemaName
|
|
5729
5735
|
});
|
|
5730
5736
|
const row = await this.#db.readClient.oneOrNone(`SELECT * FROM ${tableName} WHERE "webhookId" = $1`, [webhookId]);
|
|
5731
5737
|
return row ? this.#parseInstallationRow(row) : null;
|
|
5732
5738
|
}
|
|
5733
5739
|
async listInstallations(platform) {
|
|
5740
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
5734
5741
|
const tableName = getTableName$5({
|
|
5735
5742
|
indexName: TABLE_CHANNEL_INSTALLATIONS,
|
|
5736
|
-
schemaName
|
|
5743
|
+
schemaName
|
|
5737
5744
|
});
|
|
5738
5745
|
return (await this.#db.readClient.manyOrNone(`SELECT * FROM ${tableName} WHERE "platform" = $1 ORDER BY "createdAt" DESC`, [platform])).map((row) => this.#parseInstallationRow(row));
|
|
5739
5746
|
}
|
|
5740
5747
|
async deleteInstallation(id) {
|
|
5748
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
5741
5749
|
const tableName = getTableName$5({
|
|
5742
5750
|
indexName: TABLE_CHANNEL_INSTALLATIONS,
|
|
5743
|
-
schemaName
|
|
5751
|
+
schemaName
|
|
5744
5752
|
});
|
|
5745
5753
|
await this.#db.client.none(`DELETE FROM ${tableName} WHERE "id" = $1`, [id]);
|
|
5746
5754
|
}
|
|
5747
5755
|
async saveConfig(config) {
|
|
5756
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
5748
5757
|
const tableName = getTableName$5({
|
|
5749
5758
|
indexName: TABLE_CHANNEL_CONFIG,
|
|
5750
|
-
schemaName
|
|
5759
|
+
schemaName
|
|
5751
5760
|
});
|
|
5752
5761
|
const now = config.updatedAt.toISOString();
|
|
5753
5762
|
await this.#db.client.none(`INSERT INTO ${tableName} ("platform", "data", "updatedAt", "updatedAtZ")
|
|
@@ -5763,9 +5772,10 @@ var ChannelsPG = class ChannelsPG extends ChannelsStorage {
|
|
|
5763
5772
|
]);
|
|
5764
5773
|
}
|
|
5765
5774
|
async getConfig(platform) {
|
|
5775
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
5766
5776
|
const tableName = getTableName$5({
|
|
5767
5777
|
indexName: TABLE_CHANNEL_CONFIG,
|
|
5768
|
-
schemaName
|
|
5778
|
+
schemaName
|
|
5769
5779
|
});
|
|
5770
5780
|
const row = await this.#db.readClient.oneOrNone(`SELECT * FROM ${tableName} WHERE "platform" = $1`, [platform]);
|
|
5771
5781
|
if (!row) return null;
|
|
@@ -5776,9 +5786,10 @@ var ChannelsPG = class ChannelsPG extends ChannelsStorage {
|
|
|
5776
5786
|
};
|
|
5777
5787
|
}
|
|
5778
5788
|
async deleteConfig(platform) {
|
|
5789
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
5779
5790
|
const tableName = getTableName$5({
|
|
5780
5791
|
indexName: TABLE_CHANNEL_CONFIG,
|
|
5781
|
-
schemaName
|
|
5792
|
+
schemaName
|
|
5782
5793
|
});
|
|
5783
5794
|
await this.#db.client.none(`DELETE FROM ${tableName} WHERE "platform" = $1`, [platform]);
|
|
5784
5795
|
}
|
|
@@ -11696,10 +11707,11 @@ const DB_NOW_MS = `(EXTRACT(EPOCH FROM clock_timestamp()) * 1000)::bigint`;
|
|
|
11696
11707
|
*/
|
|
11697
11708
|
async function assertRunFence(t, claimsTable, fence, operation) {
|
|
11698
11709
|
const row = await t.oneOrNone(`SELECT generation, "ownerId" FROM ${claimsTable} WHERE "runId" = $1 FOR SHARE`, [fence.runId]);
|
|
11699
|
-
|
|
11710
|
+
const current = row && {
|
|
11700
11711
|
generation: Number(row.generation),
|
|
11701
11712
|
ownerId: row.ownerId
|
|
11702
|
-
}
|
|
11713
|
+
};
|
|
11714
|
+
if (!matchesRunFence(current, fence)) throw new RunFenceConflictError(fence, operation);
|
|
11703
11715
|
}
|
|
11704
11716
|
/**
|
|
11705
11717
|
* Runs `write` directly when it carries no fence, or in a transaction behind
|
|
@@ -14826,9 +14838,10 @@ var NotificationsPG = class NotificationsPG extends NotificationsStorage {
|
|
|
14826
14838
|
async updateNotificationRow(threadId, id, data) {
|
|
14827
14839
|
const entries = Object.entries(data).filter(([, value]) => value !== void 0);
|
|
14828
14840
|
if (entries.length === 0) return;
|
|
14841
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
14829
14842
|
const tableName = getTableName$5({
|
|
14830
14843
|
indexName: TABLE_NOTIFICATIONS,
|
|
14831
|
-
schemaName
|
|
14844
|
+
schemaName
|
|
14832
14845
|
});
|
|
14833
14846
|
const setColumns = entries.map(([key], index) => `"${parseSqlIdentifier(key, "column name")}" = $${index + 1}`);
|
|
14834
14847
|
const values = entries.map(([key, value]) => {
|
|
@@ -14927,9 +14940,10 @@ var NotificationsPG = class NotificationsPG extends NotificationsStorage {
|
|
|
14927
14940
|
}
|
|
14928
14941
|
const limit = input.limit ? ` LIMIT $${args.length + 1}` : "";
|
|
14929
14942
|
if (input.limit) args.push(input.limit);
|
|
14943
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
14930
14944
|
const tableName = getTableName$5({
|
|
14931
14945
|
indexName: TABLE_NOTIFICATIONS,
|
|
14932
|
-
schemaName
|
|
14946
|
+
schemaName
|
|
14933
14947
|
});
|
|
14934
14948
|
return (await this.#db.readClient.manyOrNone(`SELECT * FROM ${tableName} WHERE ${conditions.join(" AND ")} ORDER BY "updatedAt" DESC${limit}`, args)).map((row) => rowToNotification(row));
|
|
14935
14949
|
}
|
|
@@ -14950,9 +14964,10 @@ var NotificationsPG = class NotificationsPG extends NotificationsStorage {
|
|
|
14950
14964
|
}
|
|
14951
14965
|
const limit = input.limit ? ` LIMIT $${args.length + 1}` : "";
|
|
14952
14966
|
if (input.limit) args.push(input.limit);
|
|
14967
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
14953
14968
|
const tableName = getTableName$5({
|
|
14954
14969
|
indexName: TABLE_NOTIFICATIONS,
|
|
14955
|
-
schemaName
|
|
14970
|
+
schemaName
|
|
14956
14971
|
});
|
|
14957
14972
|
return (await this.#db.readClient.manyOrNone(`SELECT * FROM ${tableName} WHERE ${conditions.join(" AND ")} ORDER BY CASE WHEN "deliverAt" IS NULL THEN "summaryAt" WHEN "summaryAt" IS NULL THEN "deliverAt" WHEN "deliverAt" <= "summaryAt" THEN "deliverAt" ELSE "summaryAt" END ASC, "updatedAt" ASC${limit}`, args)).map((row) => rowToNotification(row));
|
|
14958
14973
|
}
|
|
@@ -14964,9 +14979,10 @@ var NotificationsPG = class NotificationsPG extends NotificationsStorage {
|
|
|
14964
14979
|
* lagging read replica cannot yield stale or missing rows mid-update.
|
|
14965
14980
|
*/
|
|
14966
14981
|
async #getNotification(client, input) {
|
|
14982
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
14967
14983
|
const tableName = getTableName$5({
|
|
14968
14984
|
indexName: TABLE_NOTIFICATIONS,
|
|
14969
|
-
schemaName
|
|
14985
|
+
schemaName
|
|
14970
14986
|
});
|
|
14971
14987
|
const row = await client.oneOrNone(`SELECT * FROM ${tableName} WHERE "threadId" = $1 AND "id" = $2 LIMIT 1`, [input.threadId, input.id]);
|
|
14972
14988
|
return row ? rowToNotification(row) : null;
|
|
@@ -15014,9 +15030,10 @@ var NotificationsPG = class NotificationsPG extends NotificationsStorage {
|
|
|
15014
15030
|
};
|
|
15015
15031
|
const columns = Object.keys(assignments);
|
|
15016
15032
|
const setClause = columns.map((column, index) => `"${parseSqlIdentifier(column, "column name")}" = $${index + 1}`).join(", ");
|
|
15033
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
15017
15034
|
const tableName = getTableName$5({
|
|
15018
15035
|
indexName: TABLE_NOTIFICATIONS,
|
|
15019
|
-
schemaName
|
|
15036
|
+
schemaName
|
|
15020
15037
|
});
|
|
15021
15038
|
return (await this.#db.client.manyOrNone(`UPDATE ${tableName} SET ${setClause} WHERE "threadId" = $${columns.length + 1} AND "id" = ANY($${columns.length + 2}::text[]) RETURNING *`, [
|
|
15022
15039
|
...Object.values(assignments),
|
|
@@ -15026,9 +15043,10 @@ var NotificationsPG = class NotificationsPG extends NotificationsStorage {
|
|
|
15026
15043
|
}
|
|
15027
15044
|
async findCoalescable(input) {
|
|
15028
15045
|
if (!input.dedupeKey && !input.coalesceKey) return void 0;
|
|
15046
|
+
const schemaName = getSchemaName$5(this.#schema);
|
|
15029
15047
|
const tableName = getTableName$5({
|
|
15030
15048
|
indexName: TABLE_NOTIFICATIONS,
|
|
15031
|
-
schemaName
|
|
15049
|
+
schemaName
|
|
15032
15050
|
});
|
|
15033
15051
|
const row = await this.#db.client.oneOrNone(`SELECT * FROM ${tableName} WHERE "threadId" = $1 AND "source" = $2 AND "kind" = $3 AND "status" = $4 AND (("agentId" = $5::text) OR ("agentId" IS NULL AND $5::text IS NULL)) AND (("resourceId" = $6::text) OR ("resourceId" IS NULL AND $6::text IS NULL)) AND (($7::text IS NOT NULL AND "dedupeKey" = $7::text) OR ($8::text IS NOT NULL AND "coalesceKey" = $8::text)) ORDER BY "updatedAt" DESC LIMIT 1`, [
|
|
15034
15052
|
input.threadId,
|
|
@@ -15570,18 +15588,18 @@ var ObservabilityPG = class ObservabilityPG extends ObservabilityStorage {
|
|
|
15570
15588
|
case TraceStatus.RUNNING:
|
|
15571
15589
|
conditions.push(`r."endedAtZ" IS NULL AND r."error" IS NULL`);
|
|
15572
15590
|
break;
|
|
15573
|
-
case TraceStatus.SUCCESS:
|
|
15574
|
-
conditions.push(`r."endedAtZ" IS NOT NULL AND r."error" IS NULL`);
|
|
15575
|
-
break;
|
|
15591
|
+
case TraceStatus.SUCCESS: conditions.push(`r."endedAtZ" IS NOT NULL AND r."error" IS NULL`);
|
|
15576
15592
|
}
|
|
15577
|
-
if (filters.hasChildError !== void 0)
|
|
15593
|
+
if (filters.hasChildError !== void 0) {
|
|
15594
|
+
if (filters.hasChildError) conditions.push(`EXISTS (
|
|
15578
15595
|
SELECT 1 FROM ${tableName} c
|
|
15579
15596
|
WHERE c."traceId" = r."traceId" AND c."error" IS NOT NULL
|
|
15580
15597
|
)`);
|
|
15581
|
-
|
|
15598
|
+
else conditions.push(`NOT EXISTS (
|
|
15582
15599
|
SELECT 1 FROM ${tableName} c
|
|
15583
15600
|
WHERE c."traceId" = r."traceId" AND c."error" IS NOT NULL
|
|
15584
15601
|
)`);
|
|
15602
|
+
}
|
|
15585
15603
|
}
|
|
15586
15604
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
15587
15605
|
const orderField = orderBy?.field ?? "startedAt";
|
|
@@ -16761,9 +16779,6 @@ function additiveColumns(schema) {
|
|
|
16761
16779
|
}
|
|
16762
16780
|
];
|
|
16763
16781
|
}
|
|
16764
|
-
/** Existence probe for an additive column. Params: schema, table, column. */
|
|
16765
|
-
const columnExistsSQL = `SELECT 1 FROM information_schema.columns
|
|
16766
|
-
WHERE table_schema = $1 AND table_name = $2 AND column_name = $3`;
|
|
16767
16782
|
/** Index CREATEs. Safe to run repeatedly. */
|
|
16768
16783
|
function allIndexDDL(schema) {
|
|
16769
16784
|
return tableIndexes().map((spec) => indexDDL(schema, spec));
|
|
@@ -16771,7 +16786,7 @@ function allIndexDDL(schema) {
|
|
|
16771
16786
|
//#endregion
|
|
16772
16787
|
//#region src/storage/domains/observability/v-next/discovery.ts
|
|
16773
16788
|
const DEFAULT_TTL_SECONDS = 300;
|
|
16774
|
-
const DEFAULT_LOOKBACK_SECONDS =
|
|
16789
|
+
const DEFAULT_LOOKBACK_SECONDS = 2592e3;
|
|
16775
16790
|
/** All signal tables that contain a column. Used by cross-signal discovery. */
|
|
16776
16791
|
const SIGNAL_TABLES_WITH_CONTEXT = [
|
|
16777
16792
|
TABLE_SPAN_EVENTS,
|
|
@@ -18016,7 +18031,7 @@ function shiftRange(range, period) {
|
|
|
18016
18031
|
offset = 864e5;
|
|
18017
18032
|
break;
|
|
18018
18033
|
case "previous_week":
|
|
18019
|
-
offset =
|
|
18034
|
+
offset = 6048e5;
|
|
18020
18035
|
break;
|
|
18021
18036
|
default: offset = duration;
|
|
18022
18037
|
}
|
|
@@ -18136,12 +18151,14 @@ function pushFeedbackIdentity(acc, feedbackType, feedbackSource) {
|
|
|
18136
18151
|
acc.conditions.push(`"valueNumber" IS NOT NULL`);
|
|
18137
18152
|
}
|
|
18138
18153
|
async function createFeedback(client, schema, args) {
|
|
18139
|
-
const
|
|
18154
|
+
const row = feedbackRecordToRow(args.feedback);
|
|
18155
|
+
const insert = buildInsert(schema, TABLE_FEEDBACK_EVENTS, [row], FEEDBACK_UPSERT_CLAUSE);
|
|
18140
18156
|
if (insert) await client.query(insert.text, insert.values);
|
|
18141
18157
|
}
|
|
18142
18158
|
async function batchCreateFeedback(client, schema, args) {
|
|
18143
18159
|
if (args.feedbacks.length === 0) return;
|
|
18144
|
-
const
|
|
18160
|
+
const rows = [...new Map(args.feedbacks.map((feedback) => [feedback.feedbackId, feedback])).values()].map(feedbackRecordToRow);
|
|
18161
|
+
const insert = buildInsert(schema, TABLE_FEEDBACK_EVENTS, rows, FEEDBACK_UPSERT_CLAUSE);
|
|
18145
18162
|
if (insert) await client.query(insert.text, insert.values);
|
|
18146
18163
|
}
|
|
18147
18164
|
async function updateFeedbackReviewStatus(client, schema, args) {
|
|
@@ -18343,7 +18360,8 @@ function applyLogFilters(acc, filters) {
|
|
|
18343
18360
|
}
|
|
18344
18361
|
async function batchCreateLogs(client, schema, args) {
|
|
18345
18362
|
if (args.logs.length === 0) return;
|
|
18346
|
-
const
|
|
18363
|
+
const rows = args.logs.map(logRecordToRow);
|
|
18364
|
+
const insert = buildInsert(schema, TABLE_LOG_EVENTS, rows);
|
|
18347
18365
|
if (insert) await client.query(insert.text, insert.values);
|
|
18348
18366
|
}
|
|
18349
18367
|
async function listLogs(client, schema, args) {
|
|
@@ -18418,7 +18436,8 @@ function pushMetricNameFilter(acc, names) {
|
|
|
18418
18436
|
}
|
|
18419
18437
|
async function batchCreateMetrics(client, schema, args) {
|
|
18420
18438
|
if (args.metrics.length === 0) return;
|
|
18421
|
-
const
|
|
18439
|
+
const rows = args.metrics.map(metricRecordToRow);
|
|
18440
|
+
const insert = buildInsert(schema, TABLE_METRIC_EVENTS, rows);
|
|
18422
18441
|
if (insert) await client.query(insert.text, insert.values);
|
|
18423
18442
|
}
|
|
18424
18443
|
async function listMetrics(client, schema, args) {
|
|
@@ -19222,6 +19241,7 @@ const TRACE_FIELDS = {
|
|
|
19222
19241
|
endedAt: "r.\"endedAt\"",
|
|
19223
19242
|
durationMs: durationMsSql("r.\"startedAt\"", "r.\"endedAt\""),
|
|
19224
19243
|
timeToFirstChunkMs: "r.\"timeToFirstChunkMs\"",
|
|
19244
|
+
entityId: "r.\"entityId\"",
|
|
19225
19245
|
entityName: "r.\"entityName\"",
|
|
19226
19246
|
entityType: "r.\"entityType\"",
|
|
19227
19247
|
name: "r.\"name\"",
|
|
@@ -19523,6 +19543,7 @@ const ROOT_PUSHDOWN_FIELDS = /* @__PURE__ */ new Set([
|
|
|
19523
19543
|
"organizationId",
|
|
19524
19544
|
"startedAt",
|
|
19525
19545
|
"endedAt",
|
|
19546
|
+
"entityId",
|
|
19526
19547
|
"entityName",
|
|
19527
19548
|
"entityType",
|
|
19528
19549
|
"name",
|
|
@@ -20393,7 +20414,7 @@ function predicateFields(predicate, fields = /* @__PURE__ */ new Set()) {
|
|
|
20393
20414
|
return fields;
|
|
20394
20415
|
}
|
|
20395
20416
|
function canUseThreadCandidates(probe) {
|
|
20396
|
-
return Number(probe.threadCount) <= 16384 && Number(probe.traceCount) <= 1e5 && Number(probe.threadBytes) + Number(probe.traceBytes) <=
|
|
20417
|
+
return Number(probe.threadCount) <= 16384 && Number(probe.traceCount) <= 1e5 && Number(probe.threadBytes) + Number(probe.traceBytes) <= 4194304;
|
|
20397
20418
|
}
|
|
20398
20419
|
function compilePostgresThreadRowsQuery(schema, plan, strategy = "full") {
|
|
20399
20420
|
const values = [plan.timeRange.from, plan.timeRange.to];
|
|
@@ -20608,6 +20629,7 @@ const DIMENSION_SQL = {
|
|
|
20608
20629
|
entityName: "r.\"entityName\"",
|
|
20609
20630
|
name: "r.\"name\"",
|
|
20610
20631
|
spanType: "r.\"spanType\"",
|
|
20632
|
+
entityId: "r.\"entityId\"",
|
|
20611
20633
|
environment: "r.\"environment\"",
|
|
20612
20634
|
status: TRACE_STATUS_SQL,
|
|
20613
20635
|
serviceName: "r.\"serviceName\"",
|
|
@@ -21035,9 +21057,7 @@ function buildListTracesFilters(filters, spanTable, nextParamIdx) {
|
|
|
21035
21057
|
case TraceStatus.RUNNING:
|
|
21036
21058
|
conditions.push(`r."isPending"`);
|
|
21037
21059
|
break;
|
|
21038
|
-
case TraceStatus.SUCCESS:
|
|
21039
|
-
conditions.push(`r."error" IS NULL AND NOT r."isPending"`);
|
|
21040
|
-
break;
|
|
21060
|
+
case TraceStatus.SUCCESS: conditions.push(`r."error" IS NULL AND NOT r."isPending"`);
|
|
21041
21061
|
}
|
|
21042
21062
|
if (filters.hasChildError !== void 0) {
|
|
21043
21063
|
const sub = `EXISTS (
|
|
@@ -21373,9 +21393,7 @@ function buildListBranchesFilters(filters, spanType, spanTable, nextParamIdx) {
|
|
|
21373
21393
|
case TraceStatus.RUNNING:
|
|
21374
21394
|
conditions.push(`r."isPending"`);
|
|
21375
21395
|
break;
|
|
21376
|
-
case TraceStatus.SUCCESS:
|
|
21377
|
-
conditions.push(`r."error" IS NULL AND NOT r."isPending"`);
|
|
21378
|
-
break;
|
|
21396
|
+
case TraceStatus.SUCCESS: conditions.push(`r."error" IS NULL AND NOT r."isPending"`);
|
|
21379
21397
|
}
|
|
21380
21398
|
return {
|
|
21381
21399
|
conditions,
|
|
@@ -21716,7 +21734,7 @@ var ObservabilityStoragePostgresVNext = class ObservabilityStoragePostgresVNext
|
|
|
21716
21734
|
} catch (error) {
|
|
21717
21735
|
if (!isDuplicateRelationError(error)) throw error;
|
|
21718
21736
|
}
|
|
21719
|
-
for (const { table, column, ddl } of additiveColumns(this.#schema)) if (!await this.#client.oneOrNone(
|
|
21737
|
+
for (const { table, column, ddl } of additiveColumns(this.#schema)) if (!await this.#client.oneOrNone("SELECT 1 FROM information_schema.columns\n WHERE table_schema = $1 AND table_name = $2 AND column_name = $3", [
|
|
21720
21738
|
this.#schema,
|
|
21721
21739
|
table,
|
|
21722
21740
|
column
|
|
@@ -21842,7 +21860,8 @@ var ObservabilityStoragePostgresVNext = class ObservabilityStoragePostgresVNext
|
|
|
21842
21860
|
"feedback",
|
|
21843
21861
|
"trace-query-context-ids",
|
|
21844
21862
|
...timeToFirstChunkFeatures,
|
|
21845
|
-
"trace-query-root-span-fields"
|
|
21863
|
+
"trace-query-root-span-fields",
|
|
21864
|
+
"trace-query-root-entity-id"
|
|
21846
21865
|
];
|
|
21847
21866
|
return [
|
|
21848
21867
|
"metrics",
|
|
@@ -21865,7 +21884,8 @@ var ObservabilityStoragePostgresVNext = class ObservabilityStoragePostgresVNext
|
|
|
21865
21884
|
"feedback",
|
|
21866
21885
|
"trace-query-context-ids",
|
|
21867
21886
|
...timeToFirstChunkFeatures,
|
|
21868
|
-
"trace-query-root-span-fields"
|
|
21887
|
+
"trace-query-root-span-fields",
|
|
21888
|
+
"trace-query-root-entity-id"
|
|
21869
21889
|
];
|
|
21870
21890
|
}
|
|
21871
21891
|
async #run(op, fn, details) {
|
|
@@ -22882,15 +22902,19 @@ var SchedulesPG = class SchedulesPG extends SchedulesStorage {
|
|
|
22882
22902
|
params.push(filter.workflowId);
|
|
22883
22903
|
conditions.push(`target->>'workflowId' = $${params.length}`);
|
|
22884
22904
|
}
|
|
22885
|
-
if (filter?.ownerType !== void 0)
|
|
22886
|
-
|
|
22887
|
-
|
|
22888
|
-
|
|
22905
|
+
if (filter?.ownerType !== void 0) {
|
|
22906
|
+
if (filter.ownerType === null) conditions.push("owner_type IS NULL");
|
|
22907
|
+
else {
|
|
22908
|
+
params.push(filter.ownerType);
|
|
22909
|
+
conditions.push(`owner_type = $${params.length}`);
|
|
22910
|
+
}
|
|
22889
22911
|
}
|
|
22890
|
-
if (filter?.ownerId !== void 0)
|
|
22891
|
-
|
|
22892
|
-
|
|
22893
|
-
|
|
22912
|
+
if (filter?.ownerId !== void 0) {
|
|
22913
|
+
if (filter.ownerId === null) conditions.push("owner_id IS NULL");
|
|
22914
|
+
else {
|
|
22915
|
+
params.push(filter.ownerId);
|
|
22916
|
+
conditions.push(`owner_id = $${params.length}`);
|
|
22917
|
+
}
|
|
22894
22918
|
}
|
|
22895
22919
|
const where = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
22896
22920
|
return (await this.#readClient.manyOrNone(`SELECT * FROM ${this.#table(TABLE_SCHEDULES)} ${where} ORDER BY created_at ASC`, params)).map(rowToSchedule);
|
|
@@ -26000,16 +26024,20 @@ var WorkflowsPG = class WorkflowsPG extends WorkflowsStorage {
|
|
|
26000
26024
|
values.push(status);
|
|
26001
26025
|
paramIndex++;
|
|
26002
26026
|
}
|
|
26003
|
-
if (resourceId)
|
|
26004
|
-
|
|
26005
|
-
|
|
26006
|
-
|
|
26007
|
-
|
|
26008
|
-
|
|
26009
|
-
|
|
26010
|
-
|
|
26011
|
-
|
|
26012
|
-
|
|
26027
|
+
if (resourceId) {
|
|
26028
|
+
if (await this.#db.hasColumn(TABLE_WORKFLOW_SNAPSHOT, "resourceId")) {
|
|
26029
|
+
conditions.push(`"resourceId" = $${paramIndex}`);
|
|
26030
|
+
values.push(resourceId);
|
|
26031
|
+
paramIndex++;
|
|
26032
|
+
} else this.logger?.warn?.(`[${TABLE_WORKFLOW_SNAPSHOT}] resourceId column not found. Skipping resourceId filter.`);
|
|
26033
|
+
}
|
|
26034
|
+
if (threadId) {
|
|
26035
|
+
if (await this.#db.getColumnType(TABLE_WORKFLOW_SNAPSHOT, "snapshot") === "jsonb") {
|
|
26036
|
+
conditions.push(`${WORKFLOW_SNAPSHOT_THREAD_ID_EXPR} = $${paramIndex}`);
|
|
26037
|
+
values.push(threadId);
|
|
26038
|
+
paramIndex++;
|
|
26039
|
+
} else this.logger?.warn?.(`[${TABLE_WORKFLOW_SNAPSHOT}] snapshot column is not jsonb. Skipping threadId filter.`);
|
|
26040
|
+
}
|
|
26013
26041
|
if (fromDate) {
|
|
26014
26042
|
conditions.push(`"createdAt" >= $${paramIndex}`);
|
|
26015
26043
|
values.push(fromDate);
|