@mastra/pg 0.15.2 → 0.15.3-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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 0.15.3-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Add resource id to workflow run snapshots ([#7740](https://github.com/mastra-ai/mastra/pull/7740))
8
+
9
+ - Updated dependencies [[`547c621`](https://github.com/mastra-ai/mastra/commit/547c62104af3f7a551b3754e9cbdf0a3fbba15e4)]:
10
+ - @mastra/core@0.16.4-alpha.1
11
+
3
12
  ## 0.15.2
4
13
 
5
14
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -2808,16 +2808,17 @@ var WorkflowsPG = class extends storage.WorkflowsStorage {
2808
2808
  async persistWorkflowSnapshot({
2809
2809
  workflowName,
2810
2810
  runId,
2811
+ resourceId,
2811
2812
  snapshot
2812
2813
  }) {
2813
2814
  try {
2814
2815
  const now = (/* @__PURE__ */ new Date()).toISOString();
2815
2816
  await this.client.none(
2816
- `INSERT INTO ${getTableName({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: this.schema })} (workflow_name, run_id, snapshot, "createdAt", "updatedAt")
2817
- VALUES ($1, $2, $3, $4, $5)
2817
+ `INSERT INTO ${getTableName({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: this.schema })} (workflow_name, run_id, "resourceId", snapshot, "createdAt", "updatedAt")
2818
+ VALUES ($1, $2, $3, $4, $5, $6)
2818
2819
  ON CONFLICT (workflow_name, run_id) DO UPDATE
2819
- SET snapshot = $3, "updatedAt" = $5`,
2820
- [workflowName, runId, JSON.stringify(snapshot), now, now]
2820
+ SET "resourceId" = $3, snapshot = $4, "updatedAt" = $6`,
2821
+ [workflowName, runId, resourceId, JSON.stringify(snapshot), now, now]
2821
2822
  );
2822
2823
  } catch (error$1) {
2823
2824
  throw new error.MastraError(
@@ -2979,37 +2980,68 @@ var PostgresStore = class extends storage.MastraStorage {
2979
2980
  isConnected = false;
2980
2981
  stores;
2981
2982
  constructor(config) {
2983
+ const isConnectionStringConfig = (cfg) => {
2984
+ return "connectionString" in cfg;
2985
+ };
2986
+ const isHostConfig = (cfg) => {
2987
+ return "host" in cfg && "database" in cfg && "user" in cfg && "password" in cfg;
2988
+ };
2989
+ const isCloudSqlConfig = (cfg) => {
2990
+ return "stream" in cfg || "password" in cfg && typeof cfg.password === "function";
2991
+ };
2982
2992
  try {
2983
- if ("connectionString" in config) {
2993
+ if (isConnectionStringConfig(config)) {
2984
2994
  if (!config.connectionString || typeof config.connectionString !== "string" || config.connectionString.trim() === "") {
2985
2995
  throw new Error(
2986
2996
  "PostgresStore: connectionString must be provided and cannot be empty. Passing an empty string may cause fallback to local Postgres defaults."
2987
2997
  );
2988
2998
  }
2989
- } else {
2999
+ } else if (isCloudSqlConfig(config)) ; else if (isHostConfig(config)) {
2990
3000
  const required = ["host", "database", "user", "password"];
2991
3001
  for (const key of required) {
2992
- if (!(key in config) || typeof config[key] !== "string" || config[key].trim() === "") {
3002
+ if (!config[key] || typeof config[key] !== "string" || config[key].trim() === "") {
2993
3003
  throw new Error(
2994
3004
  `PostgresStore: ${key} must be provided and cannot be empty. Passing an empty string may cause fallback to local Postgres defaults.`
2995
3005
  );
2996
3006
  }
2997
3007
  }
3008
+ } else {
3009
+ throw new Error(
3010
+ "PostgresStore: invalid config. Provide either {connectionString}, {host,port,database,user,password}, or a pg ClientConfig (e.g., Cloud SQL connector with `stream`)."
3011
+ );
2998
3012
  }
2999
3013
  super({ name: "PostgresStore" });
3000
3014
  this.schema = config.schemaName || "public";
3001
- this.#config = {
3002
- max: config.max,
3003
- idleTimeoutMillis: config.idleTimeoutMillis,
3004
- ...`connectionString` in config ? { connectionString: config.connectionString } : {
3015
+ if (isConnectionStringConfig(config)) {
3016
+ this.#config = {
3017
+ connectionString: config.connectionString,
3018
+ max: config.max,
3019
+ idleTimeoutMillis: config.idleTimeoutMillis
3020
+ };
3021
+ } else if (isCloudSqlConfig(config)) {
3022
+ this.#config = {
3023
+ ...config,
3024
+ max: config.max,
3025
+ idleTimeoutMillis: config.idleTimeoutMillis
3026
+ };
3027
+ } else if (isHostConfig(config)) {
3028
+ this.#config = {
3005
3029
  host: config.host,
3006
3030
  port: config.port,
3007
3031
  database: config.database,
3008
3032
  user: config.user,
3009
3033
  password: config.password,
3010
- ssl: config.ssl
3011
- }
3012
- };
3034
+ ssl: config.ssl,
3035
+ max: config.max,
3036
+ idleTimeoutMillis: config.idleTimeoutMillis
3037
+ };
3038
+ } else {
3039
+ this.#config = {
3040
+ ...config,
3041
+ max: config.max,
3042
+ idleTimeoutMillis: config.idleTimeoutMillis
3043
+ };
3044
+ }
3013
3045
  this.stores = {};
3014
3046
  } catch (e) {
3015
3047
  throw new error.MastraError(
@@ -3211,9 +3243,10 @@ var PostgresStore = class extends storage.MastraStorage {
3211
3243
  async persistWorkflowSnapshot({
3212
3244
  workflowName,
3213
3245
  runId,
3246
+ resourceId,
3214
3247
  snapshot
3215
3248
  }) {
3216
- return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, snapshot });
3249
+ return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
3217
3250
  }
3218
3251
  async loadWorkflowSnapshot({
3219
3252
  workflowName,