@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/dist/index.js CHANGED
@@ -3711,15 +3711,15 @@ var ScoresPG = class extends ScoresStorage {
3711
3711
  } catch (error) {
3712
3712
  throw new MastraError(
3713
3713
  {
3714
- id: createStorageErrorId("PG", "SAVE_SCORE", "INVALID_PAYLOAD"),
3714
+ id: createStorageErrorId("PG", "SAVE_SCORE", "VALIDATION_FAILED"),
3715
3715
  domain: ErrorDomain.STORAGE,
3716
3716
  category: ErrorCategory.USER,
3717
3717
  details: {
3718
- scorer: score.scorer.id,
3719
- entityId: score.entityId,
3720
- entityType: score.entityType,
3721
- traceId: score.traceId || "",
3722
- spanId: score.spanId || ""
3718
+ scorer: score.scorer?.id ?? "unknown",
3719
+ entityId: score.entityId ?? "unknown",
3720
+ entityType: score.entityType ?? "unknown",
3721
+ traceId: score.traceId ?? "",
3722
+ spanId: score.spanId ?? ""
3723
3723
  }
3724
3724
  },
3725
3725
  error
@@ -3727,6 +3727,7 @@ var ScoresPG = class extends ScoresStorage {
3727
3727
  }
3728
3728
  try {
3729
3729
  const id = crypto.randomUUID();
3730
+ const now = /* @__PURE__ */ new Date();
3730
3731
  const {
3731
3732
  scorer,
3732
3733
  preprocessStepResult,
@@ -3749,14 +3750,15 @@ var ScoresPG = class extends ScoresStorage {
3749
3750
  scorer: scorer ? JSON.stringify(scorer) : null,
3750
3751
  preprocessStepResult: preprocessStepResult ? JSON.stringify(preprocessStepResult) : null,
3751
3752
  analyzeStepResult: analyzeStepResult ? JSON.stringify(analyzeStepResult) : null,
3753
+ metadata: metadata ? JSON.stringify(metadata) : null,
3754
+ additionalContext: additionalContext ? JSON.stringify(additionalContext) : null,
3752
3755
  requestContext: requestContext ? JSON.stringify(requestContext) : null,
3753
3756
  entity: entity ? JSON.stringify(entity) : null,
3754
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3755
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
3757
+ createdAt: now.toISOString(),
3758
+ updatedAt: now.toISOString()
3756
3759
  }
3757
3760
  });
3758
- const scoreFromDb = await this.getScoreById({ id });
3759
- return { score: scoreFromDb };
3761
+ return { score: { ...parsedScore, id, createdAt: now, updatedAt: now } };
3760
3762
  } catch (error) {
3761
3763
  throw new MastraError(
3762
3764
  {
@@ -4138,17 +4140,17 @@ var WorkflowsPG = class extends WorkflowsStorage {
4138
4140
  var PostgresStore = class extends MastraStorage {
4139
4141
  #db;
4140
4142
  #pgp;
4141
- #config;
4142
4143
  schema;
4143
- isConnected = false;
4144
+ isInitialized = false;
4144
4145
  stores;
4145
4146
  constructor(config) {
4146
4147
  try {
4147
4148
  validateConfig("PostgresStore", config);
4148
4149
  super({ id: config.id, name: "PostgresStore", disableInit: config.disableInit });
4149
4150
  this.schema = config.schemaName || "public";
4151
+ let pgConfig;
4150
4152
  if (isConnectionStringConfig(config)) {
4151
- this.#config = {
4153
+ pgConfig = {
4152
4154
  id: config.id,
4153
4155
  connectionString: config.connectionString,
4154
4156
  max: config.max,
@@ -4156,14 +4158,14 @@ var PostgresStore = class extends MastraStorage {
4156
4158
  ssl: config.ssl
4157
4159
  };
4158
4160
  } else if (isCloudSqlConfig(config)) {
4159
- this.#config = {
4161
+ pgConfig = {
4160
4162
  ...config,
4161
4163
  id: config.id,
4162
4164
  max: config.max,
4163
4165
  idleTimeoutMillis: config.idleTimeoutMillis
4164
4166
  };
4165
4167
  } else if (isHostConfig(config)) {
4166
- this.#config = {
4168
+ pgConfig = {
4167
4169
  id: config.id,
4168
4170
  host: config.host,
4169
4171
  port: config.port,
@@ -4179,7 +4181,20 @@ var PostgresStore = class extends MastraStorage {
4179
4181
  "PostgresStore: invalid config. Provide either {connectionString}, {host,port,database,user,password}, or a pg ClientConfig (e.g., Cloud SQL connector with `stream`)."
4180
4182
  );
4181
4183
  }
4182
- this.stores = {};
4184
+ this.#pgp = pgPromise();
4185
+ this.#db = this.#pgp(pgConfig);
4186
+ const operations = new StoreOperationsPG({ client: this.#db, schemaName: this.schema });
4187
+ const scores = new ScoresPG({ client: this.#db, operations, schema: this.schema });
4188
+ const workflows = new WorkflowsPG({ client: this.#db, operations, schema: this.schema });
4189
+ const memory = new MemoryPG({ client: this.#db, schema: this.schema, operations });
4190
+ const observability = new ObservabilityPG({ client: this.#db, operations, schema: this.schema });
4191
+ this.stores = {
4192
+ operations,
4193
+ scores,
4194
+ workflows,
4195
+ memory,
4196
+ observability
4197
+ };
4183
4198
  } catch (e) {
4184
4199
  throw new MastraError(
4185
4200
  {
@@ -4192,33 +4207,19 @@ var PostgresStore = class extends MastraStorage {
4192
4207
  }
4193
4208
  }
4194
4209
  async init() {
4195
- if (this.isConnected) {
4210
+ if (this.isInitialized) {
4196
4211
  return;
4197
4212
  }
4198
4213
  try {
4199
- this.isConnected = true;
4200
- this.#pgp = pgPromise();
4201
- this.#db = this.#pgp(this.#config);
4202
- const operations = new StoreOperationsPG({ client: this.#db, schemaName: this.schema });
4203
- const scores = new ScoresPG({ client: this.#db, operations, schema: this.schema });
4204
- const workflows = new WorkflowsPG({ client: this.#db, operations, schema: this.schema });
4205
- const memory = new MemoryPG({ client: this.#db, schema: this.schema, operations });
4206
- const observability = new ObservabilityPG({ client: this.#db, operations, schema: this.schema });
4207
- this.stores = {
4208
- operations,
4209
- scores,
4210
- workflows,
4211
- memory,
4212
- observability
4213
- };
4214
+ this.isInitialized = true;
4214
4215
  await super.init();
4215
4216
  try {
4216
- await operations.createAutomaticIndexes();
4217
+ await this.stores.operations.createAutomaticIndexes();
4217
4218
  } catch (indexError) {
4218
4219
  console.warn("Failed to create indexes:", indexError);
4219
4220
  }
4220
4221
  } catch (error) {
4221
- this.isConnected = false;
4222
+ this.isInitialized = false;
4222
4223
  throw new MastraError(
4223
4224
  {
4224
4225
  id: createStorageErrorId("PG", "INIT", "FAILED"),
@@ -4230,15 +4231,9 @@ var PostgresStore = class extends MastraStorage {
4230
4231
  }
4231
4232
  }
4232
4233
  get db() {
4233
- if (!this.#db) {
4234
- throw new Error(`PostgresStore: Store is not initialized, please call "init()" first.`);
4235
- }
4236
4234
  return this.#db;
4237
4235
  }
4238
4236
  get pgp() {
4239
- if (!this.#pgp) {
4240
- throw new Error(`PostgresStore: Store is not initialized, please call "init()" first.`);
4241
- }
4242
4237
  return this.#pgp;
4243
4238
  }
4244
4239
  get supports() {