@mastra/pg 1.0.0-beta.4 → 1.0.0-beta.5
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/CHANGELOG.md +20 -0
- package/dist/index.cjs +35 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +35 -40
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/scores/index.d.ts +2 -2
- package/dist/storage/domains/scores/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +3 -3
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/test-utils.d.ts.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @mastra/pg
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fix saveScore not persisting ID correctly, breaking getScoreById retrieval ([#10915](https://github.com/mastra-ai/mastra/pull/10915))
|
|
8
|
+
|
|
9
|
+
**What Changed**
|
|
10
|
+
- saveScore now correctly returns scores that can be retrieved with getScoreById
|
|
11
|
+
- Validation errors now include contextual information (scorer, entity, trace details) for easier debugging
|
|
12
|
+
|
|
13
|
+
**Impact**
|
|
14
|
+
Previously, calling getScoreById after saveScore would return null because the generated ID wasn't persisted to the database. This is now fixed across all store implementations, ensuring consistent behavior and data integrity.
|
|
15
|
+
|
|
16
|
+
- PostgresStore was setting `this.stores = {}` in the constructor and only populating it in the async `init()` method. This broke Memory because it checks `storage.stores.memory` synchronously in `getInputProcessors()` before `init()` is called. ([#10943](https://github.com/mastra-ai/mastra/pull/10943))
|
|
17
|
+
|
|
18
|
+
The fix moves domain instance creation to the constructor. This is safe because pg-promise creates database connections lazily when queries are executed.
|
|
19
|
+
|
|
20
|
+
- Updated dependencies [[`0d41fe2`](https://github.com/mastra-ai/mastra/commit/0d41fe245355dfc66d61a0d9c85d9400aac351ff), [`6b3ba91`](https://github.com/mastra-ai/mastra/commit/6b3ba91494cc10394df96782f349a4f7b1e152cc), [`7907fd1`](https://github.com/mastra-ai/mastra/commit/7907fd1c5059813b7b870b81ca71041dc807331b)]:
|
|
21
|
+
- @mastra/core@1.0.0-beta.8
|
|
22
|
+
|
|
3
23
|
## 1.0.0-beta.4
|
|
4
24
|
|
|
5
25
|
### Minor Changes
|
package/dist/index.cjs
CHANGED
|
@@ -3737,15 +3737,15 @@ var ScoresPG = class extends storage.ScoresStorage {
|
|
|
3737
3737
|
} catch (error$1) {
|
|
3738
3738
|
throw new error.MastraError(
|
|
3739
3739
|
{
|
|
3740
|
-
id: storage.createStorageErrorId("PG", "SAVE_SCORE", "
|
|
3740
|
+
id: storage.createStorageErrorId("PG", "SAVE_SCORE", "VALIDATION_FAILED"),
|
|
3741
3741
|
domain: error.ErrorDomain.STORAGE,
|
|
3742
3742
|
category: error.ErrorCategory.USER,
|
|
3743
3743
|
details: {
|
|
3744
|
-
scorer: score.scorer
|
|
3745
|
-
entityId: score.entityId,
|
|
3746
|
-
entityType: score.entityType,
|
|
3747
|
-
traceId: score.traceId
|
|
3748
|
-
spanId: score.spanId
|
|
3744
|
+
scorer: score.scorer?.id ?? "unknown",
|
|
3745
|
+
entityId: score.entityId ?? "unknown",
|
|
3746
|
+
entityType: score.entityType ?? "unknown",
|
|
3747
|
+
traceId: score.traceId ?? "",
|
|
3748
|
+
spanId: score.spanId ?? ""
|
|
3749
3749
|
}
|
|
3750
3750
|
},
|
|
3751
3751
|
error$1
|
|
@@ -3753,6 +3753,7 @@ var ScoresPG = class extends storage.ScoresStorage {
|
|
|
3753
3753
|
}
|
|
3754
3754
|
try {
|
|
3755
3755
|
const id = crypto.randomUUID();
|
|
3756
|
+
const now = /* @__PURE__ */ new Date();
|
|
3756
3757
|
const {
|
|
3757
3758
|
scorer,
|
|
3758
3759
|
preprocessStepResult,
|
|
@@ -3775,14 +3776,15 @@ var ScoresPG = class extends storage.ScoresStorage {
|
|
|
3775
3776
|
scorer: scorer ? JSON.stringify(scorer) : null,
|
|
3776
3777
|
preprocessStepResult: preprocessStepResult ? JSON.stringify(preprocessStepResult) : null,
|
|
3777
3778
|
analyzeStepResult: analyzeStepResult ? JSON.stringify(analyzeStepResult) : null,
|
|
3779
|
+
metadata: metadata ? JSON.stringify(metadata) : null,
|
|
3780
|
+
additionalContext: additionalContext ? JSON.stringify(additionalContext) : null,
|
|
3778
3781
|
requestContext: requestContext ? JSON.stringify(requestContext) : null,
|
|
3779
3782
|
entity: entity ? JSON.stringify(entity) : null,
|
|
3780
|
-
createdAt:
|
|
3781
|
-
updatedAt:
|
|
3783
|
+
createdAt: now.toISOString(),
|
|
3784
|
+
updatedAt: now.toISOString()
|
|
3782
3785
|
}
|
|
3783
3786
|
});
|
|
3784
|
-
|
|
3785
|
-
return { score: scoreFromDb };
|
|
3787
|
+
return { score: { ...parsedScore, id, createdAt: now, updatedAt: now } };
|
|
3786
3788
|
} catch (error$1) {
|
|
3787
3789
|
throw new error.MastraError(
|
|
3788
3790
|
{
|
|
@@ -4164,17 +4166,17 @@ var WorkflowsPG = class extends storage.WorkflowsStorage {
|
|
|
4164
4166
|
var PostgresStore = class extends storage.MastraStorage {
|
|
4165
4167
|
#db;
|
|
4166
4168
|
#pgp;
|
|
4167
|
-
#config;
|
|
4168
4169
|
schema;
|
|
4169
|
-
|
|
4170
|
+
isInitialized = false;
|
|
4170
4171
|
stores;
|
|
4171
4172
|
constructor(config) {
|
|
4172
4173
|
try {
|
|
4173
4174
|
validateConfig("PostgresStore", config);
|
|
4174
4175
|
super({ id: config.id, name: "PostgresStore", disableInit: config.disableInit });
|
|
4175
4176
|
this.schema = config.schemaName || "public";
|
|
4177
|
+
let pgConfig;
|
|
4176
4178
|
if (isConnectionStringConfig(config)) {
|
|
4177
|
-
|
|
4179
|
+
pgConfig = {
|
|
4178
4180
|
id: config.id,
|
|
4179
4181
|
connectionString: config.connectionString,
|
|
4180
4182
|
max: config.max,
|
|
@@ -4182,14 +4184,14 @@ var PostgresStore = class extends storage.MastraStorage {
|
|
|
4182
4184
|
ssl: config.ssl
|
|
4183
4185
|
};
|
|
4184
4186
|
} else if (isCloudSqlConfig(config)) {
|
|
4185
|
-
|
|
4187
|
+
pgConfig = {
|
|
4186
4188
|
...config,
|
|
4187
4189
|
id: config.id,
|
|
4188
4190
|
max: config.max,
|
|
4189
4191
|
idleTimeoutMillis: config.idleTimeoutMillis
|
|
4190
4192
|
};
|
|
4191
4193
|
} else if (isHostConfig(config)) {
|
|
4192
|
-
|
|
4194
|
+
pgConfig = {
|
|
4193
4195
|
id: config.id,
|
|
4194
4196
|
host: config.host,
|
|
4195
4197
|
port: config.port,
|
|
@@ -4205,7 +4207,20 @@ var PostgresStore = class extends storage.MastraStorage {
|
|
|
4205
4207
|
"PostgresStore: invalid config. Provide either {connectionString}, {host,port,database,user,password}, or a pg ClientConfig (e.g., Cloud SQL connector with `stream`)."
|
|
4206
4208
|
);
|
|
4207
4209
|
}
|
|
4208
|
-
this
|
|
4210
|
+
this.#pgp = pgPromise__default.default();
|
|
4211
|
+
this.#db = this.#pgp(pgConfig);
|
|
4212
|
+
const operations = new StoreOperationsPG({ client: this.#db, schemaName: this.schema });
|
|
4213
|
+
const scores = new ScoresPG({ client: this.#db, operations, schema: this.schema });
|
|
4214
|
+
const workflows = new WorkflowsPG({ client: this.#db, operations, schema: this.schema });
|
|
4215
|
+
const memory = new MemoryPG({ client: this.#db, schema: this.schema, operations });
|
|
4216
|
+
const observability = new ObservabilityPG({ client: this.#db, operations, schema: this.schema });
|
|
4217
|
+
this.stores = {
|
|
4218
|
+
operations,
|
|
4219
|
+
scores,
|
|
4220
|
+
workflows,
|
|
4221
|
+
memory,
|
|
4222
|
+
observability
|
|
4223
|
+
};
|
|
4209
4224
|
} catch (e) {
|
|
4210
4225
|
throw new error.MastraError(
|
|
4211
4226
|
{
|
|
@@ -4218,33 +4233,19 @@ var PostgresStore = class extends storage.MastraStorage {
|
|
|
4218
4233
|
}
|
|
4219
4234
|
}
|
|
4220
4235
|
async init() {
|
|
4221
|
-
if (this.
|
|
4236
|
+
if (this.isInitialized) {
|
|
4222
4237
|
return;
|
|
4223
4238
|
}
|
|
4224
4239
|
try {
|
|
4225
|
-
this.
|
|
4226
|
-
this.#pgp = pgPromise__default.default();
|
|
4227
|
-
this.#db = this.#pgp(this.#config);
|
|
4228
|
-
const operations = new StoreOperationsPG({ client: this.#db, schemaName: this.schema });
|
|
4229
|
-
const scores = new ScoresPG({ client: this.#db, operations, schema: this.schema });
|
|
4230
|
-
const workflows = new WorkflowsPG({ client: this.#db, operations, schema: this.schema });
|
|
4231
|
-
const memory = new MemoryPG({ client: this.#db, schema: this.schema, operations });
|
|
4232
|
-
const observability = new ObservabilityPG({ client: this.#db, operations, schema: this.schema });
|
|
4233
|
-
this.stores = {
|
|
4234
|
-
operations,
|
|
4235
|
-
scores,
|
|
4236
|
-
workflows,
|
|
4237
|
-
memory,
|
|
4238
|
-
observability
|
|
4239
|
-
};
|
|
4240
|
+
this.isInitialized = true;
|
|
4240
4241
|
await super.init();
|
|
4241
4242
|
try {
|
|
4242
|
-
await operations.createAutomaticIndexes();
|
|
4243
|
+
await this.stores.operations.createAutomaticIndexes();
|
|
4243
4244
|
} catch (indexError) {
|
|
4244
4245
|
console.warn("Failed to create indexes:", indexError);
|
|
4245
4246
|
}
|
|
4246
4247
|
} catch (error$1) {
|
|
4247
|
-
this.
|
|
4248
|
+
this.isInitialized = false;
|
|
4248
4249
|
throw new error.MastraError(
|
|
4249
4250
|
{
|
|
4250
4251
|
id: storage.createStorageErrorId("PG", "INIT", "FAILED"),
|
|
@@ -4256,15 +4257,9 @@ var PostgresStore = class extends storage.MastraStorage {
|
|
|
4256
4257
|
}
|
|
4257
4258
|
}
|
|
4258
4259
|
get db() {
|
|
4259
|
-
if (!this.#db) {
|
|
4260
|
-
throw new Error(`PostgresStore: Store is not initialized, please call "init()" first.`);
|
|
4261
|
-
}
|
|
4262
4260
|
return this.#db;
|
|
4263
4261
|
}
|
|
4264
4262
|
get pgp() {
|
|
4265
|
-
if (!this.#pgp) {
|
|
4266
|
-
throw new Error(`PostgresStore: Store is not initialized, please call "init()" first.`);
|
|
4267
|
-
}
|
|
4268
4263
|
return this.#pgp;
|
|
4269
4264
|
}
|
|
4270
4265
|
get supports() {
|