@mastra/pg 1.24.0 → 1.24.1-alpha.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.
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/index.cjs +97 -81
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +97 -81
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/datasets/index.d.ts.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/v-next/helpers.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -6298,23 +6298,6 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6298
6298
|
}
|
|
6299
6299
|
async _doUpdateItem(args) {
|
|
6300
6300
|
try {
|
|
6301
|
-
const existing = await this.#getItemById(this.#db.client, { id: args.id });
|
|
6302
|
-
if (!existing) throw new _mastra_core_error.MastraError({
|
|
6303
|
-
id: (0, _mastra_core_storage.createStorageErrorId)("PG", "UPDATE_ITEM", "NOT_FOUND"),
|
|
6304
|
-
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
6305
|
-
category: _mastra_core_error.ErrorCategory.USER,
|
|
6306
|
-
details: { itemId: args.id }
|
|
6307
|
-
});
|
|
6308
|
-
if (existing.datasetId !== args.datasetId) throw new _mastra_core_error.MastraError({
|
|
6309
|
-
id: (0, _mastra_core_storage.createStorageErrorId)("PG", "UPDATE_ITEM", "DATASET_MISMATCH"),
|
|
6310
|
-
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
6311
|
-
category: _mastra_core_error.ErrorCategory.USER,
|
|
6312
|
-
details: {
|
|
6313
|
-
itemId: args.id,
|
|
6314
|
-
expectedDatasetId: args.datasetId,
|
|
6315
|
-
actualDatasetId: existing.datasetId
|
|
6316
|
-
}
|
|
6317
|
-
});
|
|
6318
6301
|
const datasetsTable = getTableName$5({
|
|
6319
6302
|
indexName: _mastra_core_storage.TABLE_DATASETS,
|
|
6320
6303
|
schemaName: getSchemaName$5(this.#schema)
|
|
@@ -6330,23 +6313,49 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6330
6313
|
const versionId = crypto.randomUUID();
|
|
6331
6314
|
const now = /* @__PURE__ */ new Date();
|
|
6332
6315
|
const nowIso = now.toISOString();
|
|
6333
|
-
|
|
6334
|
-
const mergedGroundTruth = args.groundTruth !== void 0 ? args.groundTruth : existing.groundTruth;
|
|
6335
|
-
const mergedExpectedTrajectory = args.expectedTrajectory !== void 0 ? args.expectedTrajectory : existing.expectedTrajectory;
|
|
6336
|
-
const mergedToolMocks = args.toolMocks !== void 0 ? args.toolMocks : existing.toolMocks;
|
|
6337
|
-
const mergedUnmockedToolPolicy = args.unmockedToolPolicy !== void 0 ? args.unmockedToolPolicy : existing.unmockedToolPolicy;
|
|
6338
|
-
const mergedScorerIds = args.scorerIds !== void 0 ? args.scorerIds ?? void 0 : existing.scorerIds;
|
|
6339
|
-
const mergedRequestContext = args.requestContext !== void 0 ? args.requestContext : existing.requestContext;
|
|
6340
|
-
const mergedMetadata = args.metadata !== void 0 ? args.metadata : existing.metadata;
|
|
6341
|
-
const mergedSource = args.source !== void 0 ? args.source : existing.source;
|
|
6342
|
-
let newVersion;
|
|
6343
|
-
let parentOrganizationId = null;
|
|
6344
|
-
let parentProjectId = null;
|
|
6316
|
+
let updated;
|
|
6345
6317
|
await this.#db.client.tx(async (t) => {
|
|
6318
|
+
await t.oneOrNone(`SELECT "id" FROM ${datasetsTable} WHERE "id" = $1 FOR UPDATE`, [args.datasetId]);
|
|
6319
|
+
const existing = await this.#getItemById(t, { id: args.id });
|
|
6320
|
+
if (!existing) throw new _mastra_core_error.MastraError({
|
|
6321
|
+
id: (0, _mastra_core_storage.createStorageErrorId)("PG", "UPDATE_ITEM", "NOT_FOUND"),
|
|
6322
|
+
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
6323
|
+
category: _mastra_core_error.ErrorCategory.USER,
|
|
6324
|
+
details: { itemId: args.id }
|
|
6325
|
+
});
|
|
6326
|
+
if (existing.datasetId !== args.datasetId) throw new _mastra_core_error.MastraError({
|
|
6327
|
+
id: (0, _mastra_core_storage.createStorageErrorId)("PG", "UPDATE_ITEM", "DATASET_MISMATCH"),
|
|
6328
|
+
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
6329
|
+
category: _mastra_core_error.ErrorCategory.USER,
|
|
6330
|
+
details: {
|
|
6331
|
+
itemId: args.id,
|
|
6332
|
+
expectedDatasetId: args.datasetId,
|
|
6333
|
+
actualDatasetId: existing.datasetId
|
|
6334
|
+
}
|
|
6335
|
+
});
|
|
6336
|
+
if (existing.metadata?.__purged === true) throw new _mastra_core_error.MastraError({
|
|
6337
|
+
id: "DATASET_ITEM_PURGED",
|
|
6338
|
+
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
6339
|
+
category: _mastra_core_error.ErrorCategory.USER,
|
|
6340
|
+
details: {
|
|
6341
|
+
datasetId: args.datasetId,
|
|
6342
|
+
itemId: args.id
|
|
6343
|
+
},
|
|
6344
|
+
text: `Purged dataset item cannot be updated: ${args.id}`
|
|
6345
|
+
});
|
|
6346
|
+
const mergedInput = args.input !== void 0 ? args.input : existing.input;
|
|
6347
|
+
const mergedGroundTruth = args.groundTruth !== void 0 ? args.groundTruth : existing.groundTruth;
|
|
6348
|
+
const mergedExpectedTrajectory = args.expectedTrajectory !== void 0 ? args.expectedTrajectory : existing.expectedTrajectory;
|
|
6349
|
+
const mergedToolMocks = args.toolMocks !== void 0 ? args.toolMocks : existing.toolMocks;
|
|
6350
|
+
const mergedUnmockedToolPolicy = args.unmockedToolPolicy !== void 0 ? args.unmockedToolPolicy : existing.unmockedToolPolicy;
|
|
6351
|
+
const mergedScorerIds = args.scorerIds !== void 0 ? args.scorerIds ?? void 0 : existing.scorerIds;
|
|
6352
|
+
const mergedRequestContext = args.requestContext !== void 0 ? args.requestContext : existing.requestContext;
|
|
6353
|
+
const mergedMetadata = args.metadata !== void 0 ? args.metadata : existing.metadata;
|
|
6354
|
+
const mergedSource = args.source !== void 0 ? args.source : existing.source;
|
|
6346
6355
|
const row = await t.one(`UPDATE ${datasetsTable} SET "version" = "version" + 1 WHERE "id" = $1 RETURNING "version", "organizationId", "projectId"`, [args.datasetId]);
|
|
6347
|
-
newVersion = row.version;
|
|
6348
|
-
parentOrganizationId = row.organizationId ?? null;
|
|
6349
|
-
parentProjectId = row.projectId ?? null;
|
|
6356
|
+
const newVersion = row.version;
|
|
6357
|
+
const parentOrganizationId = row.organizationId ?? null;
|
|
6358
|
+
const parentProjectId = row.projectId ?? null;
|
|
6350
6359
|
await t.none(`UPDATE ${itemsTable} SET "validTo" = $1 WHERE "id" = $2 AND "validTo" IS NULL AND "isDeleted" = false`, [newVersion, args.id]);
|
|
6351
6360
|
await t.none(`INSERT INTO ${itemsTable} ("id","datasetId","datasetVersion","externalId","organizationId","projectId","validTo","isDeleted","input","groundTruth","expectedTrajectory","toolMocks","unmockedToolPolicy","scorerIds","requestContext","metadata","source","createdAt","createdAtZ","updatedAt","updatedAtZ") VALUES ($1,$2,$3,$4,$5,$6,NULL,false,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19)`, [
|
|
6352
6361
|
args.id,
|
|
@@ -6376,23 +6385,24 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6376
6385
|
nowIso,
|
|
6377
6386
|
nowIso
|
|
6378
6387
|
]);
|
|
6388
|
+
updated = {
|
|
6389
|
+
...existing,
|
|
6390
|
+
datasetVersion: newVersion,
|
|
6391
|
+
organizationId: parentOrganizationId,
|
|
6392
|
+
projectId: parentProjectId,
|
|
6393
|
+
input: mergedInput,
|
|
6394
|
+
groundTruth: mergedGroundTruth,
|
|
6395
|
+
expectedTrajectory: mergedExpectedTrajectory,
|
|
6396
|
+
toolMocks: mergedToolMocks,
|
|
6397
|
+
unmockedToolPolicy: mergedUnmockedToolPolicy,
|
|
6398
|
+
scorerIds: mergedScorerIds,
|
|
6399
|
+
requestContext: mergedRequestContext,
|
|
6400
|
+
metadata: mergedMetadata,
|
|
6401
|
+
source: mergedSource,
|
|
6402
|
+
updatedAt: now
|
|
6403
|
+
};
|
|
6379
6404
|
});
|
|
6380
|
-
return
|
|
6381
|
-
...existing,
|
|
6382
|
-
datasetVersion: newVersion,
|
|
6383
|
-
organizationId: parentOrganizationId,
|
|
6384
|
-
projectId: parentProjectId,
|
|
6385
|
-
input: mergedInput,
|
|
6386
|
-
groundTruth: mergedGroundTruth,
|
|
6387
|
-
expectedTrajectory: mergedExpectedTrajectory,
|
|
6388
|
-
toolMocks: mergedToolMocks,
|
|
6389
|
-
unmockedToolPolicy: mergedUnmockedToolPolicy,
|
|
6390
|
-
scorerIds: mergedScorerIds,
|
|
6391
|
-
requestContext: mergedRequestContext,
|
|
6392
|
-
metadata: mergedMetadata,
|
|
6393
|
-
source: mergedSource,
|
|
6394
|
-
updatedAt: now
|
|
6395
|
-
};
|
|
6405
|
+
return updated;
|
|
6396
6406
|
} catch (error) {
|
|
6397
6407
|
if (error instanceof _mastra_core_error.MastraError) throw error;
|
|
6398
6408
|
throw new _mastra_core_error.MastraError({
|
|
@@ -6404,18 +6414,6 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6404
6414
|
}
|
|
6405
6415
|
async _doDeleteItem({ id, datasetId }) {
|
|
6406
6416
|
try {
|
|
6407
|
-
const existing = await this.#getItemById(this.#db.client, { id });
|
|
6408
|
-
if (!existing) return;
|
|
6409
|
-
if (existing.datasetId !== datasetId) throw new _mastra_core_error.MastraError({
|
|
6410
|
-
id: (0, _mastra_core_storage.createStorageErrorId)("PG", "DELETE_ITEM", "DATASET_MISMATCH"),
|
|
6411
|
-
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
6412
|
-
category: _mastra_core_error.ErrorCategory.USER,
|
|
6413
|
-
details: {
|
|
6414
|
-
itemId: id,
|
|
6415
|
-
expectedDatasetId: datasetId,
|
|
6416
|
-
actualDatasetId: existing.datasetId
|
|
6417
|
-
}
|
|
6418
|
-
});
|
|
6419
6417
|
const datasetsTable = getTableName$5({
|
|
6420
6418
|
indexName: _mastra_core_storage.TABLE_DATASETS,
|
|
6421
6419
|
schemaName: getSchemaName$5(this.#schema)
|
|
@@ -6431,6 +6429,19 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6431
6429
|
const versionId = crypto.randomUUID();
|
|
6432
6430
|
const nowIso = (/* @__PURE__ */ new Date()).toISOString();
|
|
6433
6431
|
await this.#db.client.tx(async (t) => {
|
|
6432
|
+
await t.oneOrNone(`SELECT "id" FROM ${datasetsTable} WHERE "id" = $1 FOR UPDATE`, [datasetId]);
|
|
6433
|
+
const existing = await this.#getItemById(t, { id });
|
|
6434
|
+
if (!existing) return;
|
|
6435
|
+
if (existing.datasetId !== datasetId) throw new _mastra_core_error.MastraError({
|
|
6436
|
+
id: (0, _mastra_core_storage.createStorageErrorId)("PG", "DELETE_ITEM", "DATASET_MISMATCH"),
|
|
6437
|
+
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
6438
|
+
category: _mastra_core_error.ErrorCategory.USER,
|
|
6439
|
+
details: {
|
|
6440
|
+
itemId: id,
|
|
6441
|
+
expectedDatasetId: datasetId,
|
|
6442
|
+
actualDatasetId: existing.datasetId
|
|
6443
|
+
}
|
|
6444
|
+
});
|
|
6434
6445
|
const row = await t.one(`UPDATE ${datasetsTable} SET "version" = "version" + 1 WHERE "id" = $1 RETURNING "version", "organizationId", "projectId"`, [datasetId]);
|
|
6435
6446
|
const newVersion = row.version;
|
|
6436
6447
|
const parentOrganizationId = row.organizationId ?? null;
|
|
@@ -6617,19 +6628,6 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6617
6628
|
}
|
|
6618
6629
|
async _doBatchDeleteItems(input) {
|
|
6619
6630
|
try {
|
|
6620
|
-
const dataset = await this.#getDatasetById(this.#db.client, { id: input.datasetId });
|
|
6621
|
-
if (!dataset) throw new _mastra_core_error.MastraError({
|
|
6622
|
-
id: (0, _mastra_core_storage.createStorageErrorId)("PG", "BULK_DELETE_ITEMS", "DATASET_NOT_FOUND"),
|
|
6623
|
-
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
6624
|
-
category: _mastra_core_error.ErrorCategory.USER,
|
|
6625
|
-
details: { datasetId: input.datasetId }
|
|
6626
|
-
});
|
|
6627
|
-
const currentItems = [];
|
|
6628
|
-
for (const itemId of input.itemIds) {
|
|
6629
|
-
const item = await this.#getItemById(this.#db.client, { id: itemId });
|
|
6630
|
-
if (item && item.datasetId === input.datasetId) currentItems.push(item);
|
|
6631
|
-
}
|
|
6632
|
-
if (currentItems.length === 0) return;
|
|
6633
6631
|
const datasetsTable = getTableName$5({
|
|
6634
6632
|
indexName: _mastra_core_storage.TABLE_DATASETS,
|
|
6635
6633
|
schemaName: getSchemaName$5(this.#schema)
|
|
@@ -6644,9 +6642,19 @@ var DatasetsPG = class DatasetsPG extends _mastra_core_storage.DatasetsStorage {
|
|
|
6644
6642
|
});
|
|
6645
6643
|
const nowIso = (/* @__PURE__ */ new Date()).toISOString();
|
|
6646
6644
|
const versionId = crypto.randomUUID();
|
|
6647
|
-
const parentOrganizationId = dataset.organizationId ?? null;
|
|
6648
|
-
const parentProjectId = dataset.projectId ?? null;
|
|
6649
6645
|
await this.#db.client.tx(async (t) => {
|
|
6646
|
+
await t.oneOrNone(`SELECT "id" FROM ${datasetsTable} WHERE "id" = $1 FOR UPDATE`, [input.datasetId]);
|
|
6647
|
+
const dataset = await this.#getDatasetById(t, { id: input.datasetId });
|
|
6648
|
+
if (!dataset) throw new _mastra_core_error.MastraError({
|
|
6649
|
+
id: (0, _mastra_core_storage.createStorageErrorId)("PG", "BULK_DELETE_ITEMS", "DATASET_NOT_FOUND"),
|
|
6650
|
+
domain: _mastra_core_error.ErrorDomain.STORAGE,
|
|
6651
|
+
category: _mastra_core_error.ErrorCategory.USER,
|
|
6652
|
+
details: { datasetId: input.datasetId }
|
|
6653
|
+
});
|
|
6654
|
+
const currentItems = (await t.manyOrNone(`SELECT * FROM ${itemsTable} WHERE "id" = ANY($1::text[]) AND "datasetId" = $2 AND "validTo" IS NULL AND "isDeleted" = false`, [input.itemIds, input.datasetId])).map((row) => this.transformItemRow(row));
|
|
6655
|
+
if (currentItems.length === 0) return;
|
|
6656
|
+
const parentOrganizationId = dataset.organizationId ?? null;
|
|
6657
|
+
const parentProjectId = dataset.projectId ?? null;
|
|
6650
6658
|
const newVersion = (await t.one(`UPDATE ${datasetsTable} SET "version" = "version" + 1 WHERE "id" = $1 RETURNING "version"`, [input.datasetId])).version;
|
|
6651
6659
|
for (const item of currentItems) {
|
|
6652
6660
|
await t.none(`UPDATE ${itemsTable} SET "validTo" = $1 WHERE "id" = $2 AND "validTo" IS NULL AND "isDeleted" = false`, [newVersion, item.id]);
|
|
@@ -11714,9 +11722,10 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
|
|
|
11714
11722
|
indexName: _mastra_core_storage.TABLE_MESSAGES,
|
|
11715
11723
|
schemaName: getSchemaName$3(this.#schema)
|
|
11716
11724
|
});
|
|
11725
|
+
const hydrateMessages = options?.hydrateMessages ?? true;
|
|
11717
11726
|
try {
|
|
11718
11727
|
return await this.#db.client.tx(async (t) => {
|
|
11719
|
-
let messageQuery = `SELECT id, content, role, type, "createdAt", "createdAtZ", thread_id AS "threadId", "resourceId"
|
|
11728
|
+
let messageQuery = `SELECT ${hydrateMessages ? `id, content, role, type, "createdAt", "createdAtZ", thread_id AS "threadId", "resourceId"` : `id, "createdAt"`}
|
|
11720
11729
|
FROM ${messageTableName} WHERE thread_id = $1`;
|
|
11721
11730
|
const messageParams = [sourceThreadId];
|
|
11722
11731
|
let paramIndex = 2;
|
|
@@ -11783,6 +11792,18 @@ var MemoryPG = class MemoryPG extends _mastra_core_storage.MemoryStorage {
|
|
|
11783
11792
|
for (const sourceMsg of sourceMessages) {
|
|
11784
11793
|
const newMessageId = crypto.randomUUID();
|
|
11785
11794
|
messageIdMap[sourceMsg.id] = newMessageId;
|
|
11795
|
+
if (!hydrateMessages) {
|
|
11796
|
+
const insertResult = await t.query(`INSERT INTO ${messageTableName} (id, thread_id, content, "createdAt", "createdAtZ", role, type, "resourceId")
|
|
11797
|
+
SELECT $1, $2, content, "createdAt", "createdAtZ", role, type, $3
|
|
11798
|
+
FROM ${messageTableName} WHERE id = $4`, [
|
|
11799
|
+
newMessageId,
|
|
11800
|
+
newThreadId,
|
|
11801
|
+
targetResourceId,
|
|
11802
|
+
sourceMsg.id
|
|
11803
|
+
]);
|
|
11804
|
+
if (insertResult.rowCount !== 1) throw new Error(`Failed to clone message ${sourceMsg.id}: expected 1 row copied but got ${insertResult.rowCount}`);
|
|
11805
|
+
continue;
|
|
11806
|
+
}
|
|
11786
11807
|
const normalizedMsg = this.normalizeMessageRow(sourceMsg);
|
|
11787
11808
|
let parsedContent = normalizedMsg.content;
|
|
11788
11809
|
try {
|
|
@@ -15300,11 +15321,6 @@ function jsonField(value) {
|
|
|
15300
15321
|
}
|
|
15301
15322
|
function parsedJson(value) {
|
|
15302
15323
|
if (value == null) return void 0;
|
|
15303
|
-
if (typeof value === "string") try {
|
|
15304
|
-
return JSON.parse(value);
|
|
15305
|
-
} catch {
|
|
15306
|
-
return;
|
|
15307
|
-
}
|
|
15308
15324
|
return value;
|
|
15309
15325
|
}
|
|
15310
15326
|
function rowToCommonContext(row) {
|