@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 +9 -0
- package/dist/index.cjs +48 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +48 -15
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +2 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +4 -2
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/test-utils.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -2800,16 +2800,17 @@ var WorkflowsPG = class extends WorkflowsStorage {
|
|
|
2800
2800
|
async persistWorkflowSnapshot({
|
|
2801
2801
|
workflowName,
|
|
2802
2802
|
runId,
|
|
2803
|
+
resourceId,
|
|
2803
2804
|
snapshot
|
|
2804
2805
|
}) {
|
|
2805
2806
|
try {
|
|
2806
2807
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
2807
2808
|
await this.client.none(
|
|
2808
|
-
`INSERT INTO ${getTableName({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: this.schema })} (workflow_name, run_id, snapshot, "createdAt", "updatedAt")
|
|
2809
|
-
VALUES ($1, $2, $3, $4, $5)
|
|
2809
|
+
`INSERT INTO ${getTableName({ indexName: TABLE_WORKFLOW_SNAPSHOT, schemaName: this.schema })} (workflow_name, run_id, "resourceId", snapshot, "createdAt", "updatedAt")
|
|
2810
|
+
VALUES ($1, $2, $3, $4, $5, $6)
|
|
2810
2811
|
ON CONFLICT (workflow_name, run_id) DO UPDATE
|
|
2811
|
-
SET
|
|
2812
|
-
[workflowName, runId, JSON.stringify(snapshot), now, now]
|
|
2812
|
+
SET "resourceId" = $3, snapshot = $4, "updatedAt" = $6`,
|
|
2813
|
+
[workflowName, runId, resourceId, JSON.stringify(snapshot), now, now]
|
|
2813
2814
|
);
|
|
2814
2815
|
} catch (error) {
|
|
2815
2816
|
throw new MastraError(
|
|
@@ -2971,37 +2972,68 @@ var PostgresStore = class extends MastraStorage {
|
|
|
2971
2972
|
isConnected = false;
|
|
2972
2973
|
stores;
|
|
2973
2974
|
constructor(config) {
|
|
2975
|
+
const isConnectionStringConfig = (cfg) => {
|
|
2976
|
+
return "connectionString" in cfg;
|
|
2977
|
+
};
|
|
2978
|
+
const isHostConfig = (cfg) => {
|
|
2979
|
+
return "host" in cfg && "database" in cfg && "user" in cfg && "password" in cfg;
|
|
2980
|
+
};
|
|
2981
|
+
const isCloudSqlConfig = (cfg) => {
|
|
2982
|
+
return "stream" in cfg || "password" in cfg && typeof cfg.password === "function";
|
|
2983
|
+
};
|
|
2974
2984
|
try {
|
|
2975
|
-
if (
|
|
2985
|
+
if (isConnectionStringConfig(config)) {
|
|
2976
2986
|
if (!config.connectionString || typeof config.connectionString !== "string" || config.connectionString.trim() === "") {
|
|
2977
2987
|
throw new Error(
|
|
2978
2988
|
"PostgresStore: connectionString must be provided and cannot be empty. Passing an empty string may cause fallback to local Postgres defaults."
|
|
2979
2989
|
);
|
|
2980
2990
|
}
|
|
2981
|
-
} else {
|
|
2991
|
+
} else if (isCloudSqlConfig(config)) ; else if (isHostConfig(config)) {
|
|
2982
2992
|
const required = ["host", "database", "user", "password"];
|
|
2983
2993
|
for (const key of required) {
|
|
2984
|
-
if (!
|
|
2994
|
+
if (!config[key] || typeof config[key] !== "string" || config[key].trim() === "") {
|
|
2985
2995
|
throw new Error(
|
|
2986
2996
|
`PostgresStore: ${key} must be provided and cannot be empty. Passing an empty string may cause fallback to local Postgres defaults.`
|
|
2987
2997
|
);
|
|
2988
2998
|
}
|
|
2989
2999
|
}
|
|
3000
|
+
} else {
|
|
3001
|
+
throw new Error(
|
|
3002
|
+
"PostgresStore: invalid config. Provide either {connectionString}, {host,port,database,user,password}, or a pg ClientConfig (e.g., Cloud SQL connector with `stream`)."
|
|
3003
|
+
);
|
|
2990
3004
|
}
|
|
2991
3005
|
super({ name: "PostgresStore" });
|
|
2992
3006
|
this.schema = config.schemaName || "public";
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
3007
|
+
if (isConnectionStringConfig(config)) {
|
|
3008
|
+
this.#config = {
|
|
3009
|
+
connectionString: config.connectionString,
|
|
3010
|
+
max: config.max,
|
|
3011
|
+
idleTimeoutMillis: config.idleTimeoutMillis
|
|
3012
|
+
};
|
|
3013
|
+
} else if (isCloudSqlConfig(config)) {
|
|
3014
|
+
this.#config = {
|
|
3015
|
+
...config,
|
|
3016
|
+
max: config.max,
|
|
3017
|
+
idleTimeoutMillis: config.idleTimeoutMillis
|
|
3018
|
+
};
|
|
3019
|
+
} else if (isHostConfig(config)) {
|
|
3020
|
+
this.#config = {
|
|
2997
3021
|
host: config.host,
|
|
2998
3022
|
port: config.port,
|
|
2999
3023
|
database: config.database,
|
|
3000
3024
|
user: config.user,
|
|
3001
3025
|
password: config.password,
|
|
3002
|
-
ssl: config.ssl
|
|
3003
|
-
|
|
3004
|
-
|
|
3026
|
+
ssl: config.ssl,
|
|
3027
|
+
max: config.max,
|
|
3028
|
+
idleTimeoutMillis: config.idleTimeoutMillis
|
|
3029
|
+
};
|
|
3030
|
+
} else {
|
|
3031
|
+
this.#config = {
|
|
3032
|
+
...config,
|
|
3033
|
+
max: config.max,
|
|
3034
|
+
idleTimeoutMillis: config.idleTimeoutMillis
|
|
3035
|
+
};
|
|
3036
|
+
}
|
|
3005
3037
|
this.stores = {};
|
|
3006
3038
|
} catch (e) {
|
|
3007
3039
|
throw new MastraError(
|
|
@@ -3203,9 +3235,10 @@ var PostgresStore = class extends MastraStorage {
|
|
|
3203
3235
|
async persistWorkflowSnapshot({
|
|
3204
3236
|
workflowName,
|
|
3205
3237
|
runId,
|
|
3238
|
+
resourceId,
|
|
3206
3239
|
snapshot
|
|
3207
3240
|
}) {
|
|
3208
|
-
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, snapshot });
|
|
3241
|
+
return this.stores.workflows.persistWorkflowSnapshot({ workflowName, runId, resourceId, snapshot });
|
|
3209
3242
|
}
|
|
3210
3243
|
async loadWorkflowSnapshot({
|
|
3211
3244
|
workflowName,
|