@mastra/pg 1.36.0-alpha.0 → 1.36.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.
- package/dist/docs/SKILL.md +2 -13
- package/dist/docs/assets/SOURCE_MAP.json +30 -30
- package/dist/docs/references/integrations-databases-neon.md +37 -1
- package/dist/docs/references/integrations-databases-postgresql.md +46 -0
- package/dist/docs/references/reference-memory-memory-class.md +1 -1
- package/dist/docs/references/reference-processors-semantic-recall-processor.md +5 -3
- package/dist/index.cjs +50 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +50 -33
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts +5 -0
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/db/schema-snapshot.d.ts +8 -0
- package/dist/storage/db/schema-snapshot.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/feedback.d.ts +1 -0
- package/dist/storage/domains/observability/v-next/feedback.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/index.d.ts +1 -0
- package/dist/storage/domains/observability/v-next/index.d.ts.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/docs/references/docs-deployment-workers.md +0 -404
- package/dist/docs/references/docs-memory-semantic-recall.md +0 -485
- package/dist/docs/references/docs-memory-working-memory.md +0 -450
- package/dist/docs/references/docs-storage.md +0 -224
- package/dist/docs/references/reference-rag-retrieval.md +0 -672
- package/dist/docs/references/reference-rag-vector-databases.md +0 -808
- package/dist/docs/references/reference-storage-composite.md +0 -433
- package/dist/docs/references/reference-storage-retention.md +0 -310
package/dist/index.js
CHANGED
|
@@ -2696,7 +2696,8 @@ async function loadSchemaSnapshot(client, schemaName) {
|
|
|
2696
2696
|
notNullColumns,
|
|
2697
2697
|
indexes,
|
|
2698
2698
|
replicaIdentityIndexes,
|
|
2699
|
-
primaryKeyIndexes
|
|
2699
|
+
primaryKeyIndexes,
|
|
2700
|
+
createdTables: /* @__PURE__ */ new Set()
|
|
2700
2701
|
};
|
|
2701
2702
|
}
|
|
2702
2703
|
// src/storage/db/index.ts
|
|
@@ -2856,26 +2857,30 @@ function generateTableSQL({ tableName, schema, schemaName, compositePrimaryKey,
|
|
|
2856
2857
|
` : ""}
|
|
2857
2858
|
`;
|
|
2858
2859
|
}
|
|
2860
|
+
function indexColumnsSQL(columns, opclass) {
|
|
2861
|
+
return columns.map((col) => {
|
|
2862
|
+
const [colName, ...modifiers] = col.includes(" DESC") || col.includes(" ASC") ? col.split(" ") : [col];
|
|
2863
|
+
if (!colName) throw new Error(`Invalid column specification: ${col}`);
|
|
2864
|
+
return [
|
|
2865
|
+
`"${parseSqlIdentifier(colName, "column name")}"`,
|
|
2866
|
+
opclass,
|
|
2867
|
+
...modifiers
|
|
2868
|
+
].filter(Boolean).join(" ");
|
|
2869
|
+
}).join(", ");
|
|
2870
|
+
}
|
|
2859
2871
|
/**
|
|
2860
2872
|
* Generates a CREATE INDEX SQL statement from index options.
|
|
2861
2873
|
* Used by exportSchemas to produce index DDL without a database connection.
|
|
2862
2874
|
*/
|
|
2863
2875
|
function generateIndexSQL(options, schemaName) {
|
|
2864
|
-
const { name, table, columns, unique = false, where, method = "btree" } = options;
|
|
2876
|
+
const { name, table, columns, unique = false, where, method = "btree", opclass } = options;
|
|
2865
2877
|
const fullTableName = getTableName$6({
|
|
2866
2878
|
indexName: table,
|
|
2867
2879
|
schemaName: getSchemaName$6(schemaName)
|
|
2868
2880
|
});
|
|
2869
2881
|
const uniqueStr = unique ? "UNIQUE " : "";
|
|
2870
2882
|
const methodStr = method !== "btree" ? `USING ${method} ` : "";
|
|
2871
|
-
const columnsStr = columns
|
|
2872
|
-
if (col.includes(" DESC") || col.includes(" ASC")) {
|
|
2873
|
-
const [colName, ...modifiers] = col.split(" ");
|
|
2874
|
-
if (!colName) throw new Error(`Invalid column specification: ${col}`);
|
|
2875
|
-
return `"${parseSqlIdentifier(colName, "column name")}" ${modifiers.join(" ")}`;
|
|
2876
|
-
}
|
|
2877
|
-
return `"${parseSqlIdentifier(col, "column name")}"`;
|
|
2878
|
-
}).join(", ");
|
|
2883
|
+
const columnsStr = indexColumnsSQL(columns, opclass);
|
|
2879
2884
|
const whereStr = where ? ` WHERE ${where}` : "";
|
|
2880
2885
|
return `CREATE ${uniqueStr}INDEX IF NOT EXISTS ${`"${parseSqlIdentifier(name, "index name")}"`} ON ${fullTableName} ${methodStr}(${columnsStr})${whereStr};`;
|
|
2881
2886
|
}
|
|
@@ -3386,6 +3391,7 @@ var PgDB = class extends MastraBase {
|
|
|
3386
3391
|
if (this.schemaName) await this.setupSchema();
|
|
3387
3392
|
const snapshot = this.schemaSnapshot;
|
|
3388
3393
|
if (!snapshot || !this.snapshotShowsTableConverged(snapshot, tableName)) {
|
|
3394
|
+
const isNewTable = snapshot ? !snapshot.tables.has(tableName) : false;
|
|
3389
3395
|
const sql = generateTableSQL({
|
|
3390
3396
|
tableName,
|
|
3391
3397
|
schema,
|
|
@@ -3399,6 +3405,7 @@ var PgDB = class extends MastraBase {
|
|
|
3399
3405
|
}
|
|
3400
3406
|
if (snapshot) {
|
|
3401
3407
|
snapshot.tables.add(tableName);
|
|
3408
|
+
if (isNewTable) snapshot.createdTables.add(tableName);
|
|
3402
3409
|
const created = this.snapshotColumns(snapshot, tableName);
|
|
3403
3410
|
for (const [name, def] of Object.entries(schema)) {
|
|
3404
3411
|
const parsedName = parseSqlIdentifier(name, "column name");
|
|
@@ -3867,18 +3874,9 @@ MIGRATION REQUIRED: Duplicate spans detected in ${duplicateInfo.tableName}\n====
|
|
|
3867
3874
|
const snapshot = this.schemaSnapshot;
|
|
3868
3875
|
if (snapshot?.indexes.has(name)) return;
|
|
3869
3876
|
const uniqueStr = unique ? "UNIQUE " : "";
|
|
3870
|
-
const concurrentStr = concurrent ? "CONCURRENTLY " : "";
|
|
3877
|
+
const concurrentStr = concurrent && !this.isTableCreatedInThisInit(table) ? "CONCURRENTLY " : "";
|
|
3871
3878
|
const methodStr = method !== "btree" ? `USING ${method} ` : "";
|
|
3872
|
-
const columnsStr = columns
|
|
3873
|
-
if (col.includes(" DESC") || col.includes(" ASC")) {
|
|
3874
|
-
const [colName, ...modifiers] = col.split(" ");
|
|
3875
|
-
if (!colName) throw new Error(`Invalid column specification: ${col}`);
|
|
3876
|
-
const quotedCol = `"${parseSqlIdentifier(colName, "column name")}" ${modifiers.join(" ")}`;
|
|
3877
|
-
return opclass ? `${quotedCol} ${opclass}` : quotedCol;
|
|
3878
|
-
}
|
|
3879
|
-
const quotedCol = `"${parseSqlIdentifier(col, "column name")}"`;
|
|
3880
|
-
return opclass ? `${quotedCol} ${opclass}` : quotedCol;
|
|
3881
|
-
}).join(", ");
|
|
3879
|
+
const columnsStr = indexColumnsSQL(columns, opclass);
|
|
3882
3880
|
const whereStr = where ? ` WHERE ${where}` : "";
|
|
3883
3881
|
const tablespaceStr = tablespace ? ` TABLESPACE ${tablespace}` : "";
|
|
3884
3882
|
let withStr = "";
|
|
@@ -3911,6 +3909,13 @@ MIGRATION REQUIRED: Duplicate spans detected in ${duplicateInfo.tableName}\n====
|
|
|
3911
3909
|
if (snapshot?.indexes.has(indexName)) return;
|
|
3912
3910
|
if (await buildIndex(this.client, this.schemaName || "public", indexName, () => this.timedIndexBuild(indexName, sql), this.logger)) snapshot?.indexes.add(indexName);
|
|
3913
3911
|
}
|
|
3912
|
+
/**
|
|
3913
|
+
* Whether `tableName` was absent when this init's snapshot was read and this
|
|
3914
|
+
* init created it, so its indexes can be built without CONCURRENTLY.
|
|
3915
|
+
*/
|
|
3916
|
+
isTableCreatedInThisInit(tableName) {
|
|
3917
|
+
return this.schemaSnapshot?.createdTables.has(tableName) ?? false;
|
|
3918
|
+
}
|
|
3914
3919
|
async timedIndexBuild(indexName, sql) {
|
|
3915
3920
|
const startedAt = Date.now();
|
|
3916
3921
|
this.logger.info(`Creating index ${indexName}`);
|
|
@@ -18314,6 +18319,11 @@ async function batchCreateFeedback(client, schema, args, partitioning) {
|
|
|
18314
18319
|
const rows = [...new Map(args.feedbacks.map((feedback) => [feedback.feedbackId, feedback])).values()].map(feedbackRecordToRow);
|
|
18315
18320
|
await insertRows(client, schema, TABLE_FEEDBACK_EVENTS, rows, partitioning, FEEDBACK_UPSERT_CLAUSE);
|
|
18316
18321
|
}
|
|
18322
|
+
async function getFeedbackById(client, schema, feedbackId) {
|
|
18323
|
+
const row = await client.oneOrNone(`SELECT ${FEEDBACK_SELECT_COLUMNS} FROM ${qualifiedTable(schema, TABLE_FEEDBACK_EVENTS)}
|
|
18324
|
+
WHERE "feedbackId" = $1 ORDER BY "cursorId" DESC LIMIT 1`, [feedbackId]);
|
|
18325
|
+
return row ? rowToFeedbackRecord(row) : null;
|
|
18326
|
+
}
|
|
18317
18327
|
async function updateFeedbackReviewStatus(client, schema, args) {
|
|
18318
18328
|
const { feedbackId, reviewStatus } = parseUpdateFeedbackReviewStatusArgs(args);
|
|
18319
18329
|
const row = await client.oneOrNone(`UPDATE ${qualifiedTable(schema, TABLE_FEEDBACK_EVENTS)}
|
|
@@ -22149,6 +22159,9 @@ var ObservabilityStoragePostgresVNext = class ObservabilityStoragePostgresVNext
|
|
|
22149
22159
|
async getScoreById(scoreId) {
|
|
22150
22160
|
return this.#run("GET_SCORE_BY_ID", () => getScoreById(this.#readClient, this.#schema, scoreId), { scoreId });
|
|
22151
22161
|
}
|
|
22162
|
+
async getFeedbackById(feedbackId) {
|
|
22163
|
+
return this.#run("GET_FEEDBACK_BY_ID", () => getFeedbackById(this.#readClient, this.#schema, feedbackId), { feedbackId });
|
|
22164
|
+
}
|
|
22152
22165
|
async listFeedback(args) {
|
|
22153
22166
|
return this.#run("LIST_FEEDBACK", () => listFeedback(this.#readClient, this.#schema, args));
|
|
22154
22167
|
}
|
|
@@ -25933,15 +25946,16 @@ var WorkflowsPG = class WorkflowsPG extends WorkflowsStorage {
|
|
|
25933
25946
|
this.logger?.warn?.(`Failed to create index ${stateBaseIndexName}:`, error);
|
|
25934
25947
|
}
|
|
25935
25948
|
if (await this.#db.getColumnType(TABLE_WORKFLOW_SNAPSHOT, "snapshot") !== "jsonb") return;
|
|
25949
|
+
const concurrently = !this.#db.isTableCreatedInThisInit(TABLE_WORKFLOW_SNAPSHOT);
|
|
25936
25950
|
const indexName = workflowSnapshotStatusIndexName(this.#schema);
|
|
25937
25951
|
try {
|
|
25938
|
-
await this.#db.createIndexFromStatement(indexName, workflowSnapshotStatusIndexSQL(indexName, this.#schema,
|
|
25952
|
+
await this.#db.createIndexFromStatement(indexName, workflowSnapshotStatusIndexSQL(indexName, this.#schema, concurrently));
|
|
25939
25953
|
} catch (error) {
|
|
25940
25954
|
this.logger?.warn?.(`Failed to create index ${indexName}:`, error);
|
|
25941
25955
|
}
|
|
25942
25956
|
const threadIdIndexName = workflowSnapshotThreadIdIndexName(this.#schema);
|
|
25943
25957
|
try {
|
|
25944
|
-
await this.#db.createIndexFromStatement(threadIdIndexName, workflowSnapshotThreadIdIndexSQL(threadIdIndexName, this.#schema,
|
|
25958
|
+
await this.#db.createIndexFromStatement(threadIdIndexName, workflowSnapshotThreadIdIndexSQL(threadIdIndexName, this.#schema, concurrently));
|
|
25945
25959
|
} catch (error) {
|
|
25946
25960
|
this.logger?.warn?.(`Failed to create index ${threadIdIndexName}:`, error);
|
|
25947
25961
|
}
|
|
@@ -26989,18 +27003,9 @@ var WorkflowsPG = class WorkflowsPG extends WorkflowsStorage {
|
|
|
26989
27003
|
}
|
|
26990
27004
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
26991
27005
|
const v2WhereClause = v2Conditions.length > 0 ? `WHERE ${v2Conditions.join(" AND ")}` : "";
|
|
26992
|
-
let total = 0;
|
|
26993
27006
|
const usePagination = typeof perPage === "number" && typeof page === "number";
|
|
26994
|
-
if (usePagination) {
|
|
26995
|
-
const countResult = await this.#db.client.one(`SELECT (SELECT COUNT(*) FROM ${getTableName({
|
|
26996
|
-
indexName: TABLE_WORKFLOW_SNAPSHOT,
|
|
26997
|
-
schemaName: getSchemaName(this.#schema)
|
|
26998
|
-
})} ${whereClause})
|
|
26999
|
-
+ (SELECT COUNT(*) FROM ${this.#runsTable()} ${v2WhereClause}) AS count`, values);
|
|
27000
|
-
total = Number(countResult.count);
|
|
27001
|
-
}
|
|
27002
27007
|
const normalizedPerPage = usePagination ? normalizePerPage(perPage, Number.MAX_SAFE_INTEGER) : 0;
|
|
27003
|
-
const offset = usePagination ? page * normalizedPerPage :
|
|
27008
|
+
const offset = usePagination ? page * normalizedPerPage : 0;
|
|
27004
27009
|
let v1Snapshot = "snapshot";
|
|
27005
27010
|
if (summary) {
|
|
27006
27011
|
const snapshotJson = await this.#db.getColumnType(TABLE_WORKFLOW_SNAPSHOT, "snapshot") === "jsonb" ? "snapshot" : `regexp_replace(snapshot::text, '\\\\u(0000|[Dd][89A-Fa-f][0-9A-Fa-f]{2})', '', 'g')::jsonb`;
|
|
@@ -27020,6 +27025,18 @@ var WorkflowsPG = class WorkflowsPG extends WorkflowsStorage {
|
|
|
27020
27025
|
] : values;
|
|
27021
27026
|
const result = await this.#db.client.manyOrNone(query, queryValues);
|
|
27022
27027
|
const runs = await Promise.all((result || []).map((row) => this.#parseRun(this.#db.client, row)));
|
|
27028
|
+
let total = 0;
|
|
27029
|
+
if (usePagination) {
|
|
27030
|
+
total = offset + runs.length;
|
|
27031
|
+
if (runs.length === normalizedPerPage || runs.length === 0 && offset > 0) {
|
|
27032
|
+
const countResult = await this.#db.client.one(`SELECT (SELECT COUNT(*) FROM ${getTableName({
|
|
27033
|
+
indexName: TABLE_WORKFLOW_SNAPSHOT,
|
|
27034
|
+
schemaName: getSchemaName(this.#schema)
|
|
27035
|
+
})} ${whereClause})
|
|
27036
|
+
+ (SELECT COUNT(*) FROM ${this.#runsTable()} ${v2WhereClause}) AS count`, values);
|
|
27037
|
+
total = Number(countResult.count);
|
|
27038
|
+
}
|
|
27039
|
+
}
|
|
27023
27040
|
return {
|
|
27024
27041
|
runs,
|
|
27025
27042
|
total: total || runs.length
|