@mastra/pg 1.36.0-alpha.4 → 1.36.0-alpha.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/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +30 -30
- package/dist/index.cjs +64 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +64 -16
- package/dist/index.js.map +1 -1
- package/dist/storage/client.d.ts +5 -2
- package/dist/storage/client.d.ts.map +1 -1
- package/dist/storage/factory-storage.d.ts.map +1 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/docs/SKILL.md
CHANGED
|
@@ -1,86 +1,86 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.36.0-alpha.
|
|
2
|
+
"version": "1.36.0-alpha.5",
|
|
3
3
|
"package": "@mastra/pg",
|
|
4
4
|
"exports": {
|
|
5
5
|
"AgentsPG": {
|
|
6
6
|
"types": "dist/storage/domains/agents/index.d.ts",
|
|
7
7
|
"implementation": "dist/index.js",
|
|
8
|
-
"line":
|
|
8
|
+
"line": 4404
|
|
9
9
|
},
|
|
10
10
|
"BackgroundTasksPG": {
|
|
11
11
|
"types": "dist/storage/domains/background-tasks/index.d.ts",
|
|
12
12
|
"implementation": "dist/index.js",
|
|
13
|
-
"line":
|
|
13
|
+
"line": 5335
|
|
14
14
|
},
|
|
15
15
|
"BlobsPG": {
|
|
16
16
|
"types": "dist/storage/domains/blobs/index.d.ts",
|
|
17
17
|
"implementation": "dist/index.js",
|
|
18
|
-
"line":
|
|
18
|
+
"line": 5726
|
|
19
19
|
},
|
|
20
20
|
"ChannelsPG": {
|
|
21
21
|
"types": "dist/storage/domains/channels/index.d.ts",
|
|
22
22
|
"implementation": "dist/index.js",
|
|
23
|
-
"line":
|
|
23
|
+
"line": 5828
|
|
24
24
|
},
|
|
25
25
|
"DatasetsPG": {
|
|
26
26
|
"types": "dist/storage/domains/datasets/index.d.ts",
|
|
27
27
|
"implementation": "dist/index.js",
|
|
28
|
-
"line":
|
|
28
|
+
"line": 6070
|
|
29
29
|
},
|
|
30
30
|
"ExperimentsPG": {
|
|
31
31
|
"types": "dist/storage/domains/experiments/index.d.ts",
|
|
32
32
|
"implementation": "dist/index.js",
|
|
33
|
-
"line":
|
|
33
|
+
"line": 7327
|
|
34
34
|
},
|
|
35
35
|
"FavoritesPG": {
|
|
36
36
|
"types": "dist/storage/domains/favorites/index.d.ts",
|
|
37
37
|
"implementation": "dist/index.js",
|
|
38
|
-
"line":
|
|
38
|
+
"line": 8299
|
|
39
39
|
},
|
|
40
40
|
"KnowledgePG": {
|
|
41
41
|
"types": "dist/storage/domains/knowledge/index.d.ts",
|
|
42
42
|
"implementation": "dist/index.js",
|
|
43
|
-
"line":
|
|
43
|
+
"line": 10177
|
|
44
44
|
},
|
|
45
45
|
"MCPClientsPG": {
|
|
46
46
|
"types": "dist/storage/domains/mcp-clients/index.d.ts",
|
|
47
47
|
"implementation": "dist/index.js",
|
|
48
|
-
"line":
|
|
48
|
+
"line": 10334
|
|
49
49
|
},
|
|
50
50
|
"MCPServersPG": {
|
|
51
51
|
"types": "dist/storage/domains/mcp-servers/index.d.ts",
|
|
52
52
|
"implementation": "dist/index.js",
|
|
53
|
-
"line":
|
|
53
|
+
"line": 10903
|
|
54
54
|
},
|
|
55
55
|
"MemoryPG": {
|
|
56
56
|
"types": "dist/storage/domains/memory/index.d.ts",
|
|
57
57
|
"implementation": "dist/index.js",
|
|
58
|
-
"line":
|
|
58
|
+
"line": 11698
|
|
59
59
|
},
|
|
60
60
|
"NotificationsPG": {
|
|
61
61
|
"types": "dist/storage/domains/notifications/index.d.ts",
|
|
62
62
|
"implementation": "dist/index.js",
|
|
63
|
-
"line":
|
|
63
|
+
"line": 14605
|
|
64
64
|
},
|
|
65
65
|
"ObservabilityPG": {
|
|
66
66
|
"types": "dist/storage/domains/observability/index.d.ts",
|
|
67
67
|
"implementation": "dist/index.js",
|
|
68
|
-
"line":
|
|
68
|
+
"line": 15027
|
|
69
69
|
},
|
|
70
70
|
"ObservabilityStoragePostgresVNext": {
|
|
71
71
|
"types": "dist/storage/domains/observability/v-next/index.d.ts",
|
|
72
72
|
"implementation": "dist/index.js",
|
|
73
|
-
"line":
|
|
73
|
+
"line": 21985
|
|
74
74
|
},
|
|
75
75
|
"PGVECTOR_PROMPT": {
|
|
76
76
|
"types": "dist/vector/prompt.d.ts",
|
|
77
77
|
"implementation": "dist/index.js",
|
|
78
|
-
"line":
|
|
78
|
+
"line": 28689
|
|
79
79
|
},
|
|
80
80
|
"PgFactoryStorage": {
|
|
81
81
|
"types": "dist/storage/factory-storage.d.ts",
|
|
82
82
|
"implementation": "dist/index.js",
|
|
83
|
-
"line":
|
|
83
|
+
"line": 28169
|
|
84
84
|
},
|
|
85
85
|
"PgVector": {
|
|
86
86
|
"types": "dist/vector/index.d.ts",
|
|
@@ -95,67 +95,67 @@
|
|
|
95
95
|
"PostgresStore": {
|
|
96
96
|
"types": "dist/storage/index.d.ts",
|
|
97
97
|
"implementation": "dist/index.js",
|
|
98
|
-
"line":
|
|
98
|
+
"line": 28389
|
|
99
99
|
},
|
|
100
100
|
"PostgresStoreVNext": {
|
|
101
101
|
"types": "dist/storage/index.d.ts",
|
|
102
102
|
"implementation": "dist/index.js",
|
|
103
|
-
"line":
|
|
103
|
+
"line": 28608
|
|
104
104
|
},
|
|
105
105
|
"PromptBlocksPG": {
|
|
106
106
|
"types": "dist/storage/domains/prompt-blocks/index.d.ts",
|
|
107
107
|
"implementation": "dist/index.js",
|
|
108
|
-
"line":
|
|
108
|
+
"line": 22435
|
|
109
109
|
},
|
|
110
110
|
"SchedulesPG": {
|
|
111
111
|
"types": "dist/storage/domains/schedules/index.d.ts",
|
|
112
112
|
"implementation": "dist/index.js",
|
|
113
|
-
"line":
|
|
113
|
+
"line": 23064
|
|
114
114
|
},
|
|
115
115
|
"ScorerDefinitionsPG": {
|
|
116
116
|
"types": "dist/storage/domains/scorer-definitions/index.d.ts",
|
|
117
117
|
"implementation": "dist/index.js",
|
|
118
|
-
"line":
|
|
118
|
+
"line": 23394
|
|
119
119
|
},
|
|
120
120
|
"ScoresPG": {
|
|
121
121
|
"types": "dist/storage/domains/scores/index.d.ts",
|
|
122
122
|
"implementation": "dist/index.js",
|
|
123
|
-
"line":
|
|
123
|
+
"line": 24017
|
|
124
124
|
},
|
|
125
125
|
"SkillsPG": {
|
|
126
126
|
"types": "dist/storage/domains/skills/index.d.ts",
|
|
127
127
|
"implementation": "dist/index.js",
|
|
128
|
-
"line":
|
|
128
|
+
"line": 24460
|
|
129
129
|
},
|
|
130
130
|
"ThreadStatePG": {
|
|
131
131
|
"types": "dist/storage/domains/thread-state/index.d.ts",
|
|
132
132
|
"implementation": "dist/index.js",
|
|
133
|
-
"line":
|
|
133
|
+
"line": 25151
|
|
134
134
|
},
|
|
135
135
|
"ToolProviderConnectionsPG": {
|
|
136
136
|
"types": "dist/storage/domains/tool-provider-connections/index.d.ts",
|
|
137
137
|
"implementation": "dist/index.js",
|
|
138
|
-
"line":
|
|
138
|
+
"line": 25325
|
|
139
139
|
},
|
|
140
140
|
"WorkflowDefinitionsPG": {
|
|
141
141
|
"types": "dist/storage/domains/workflow-definitions/index.d.ts",
|
|
142
142
|
"implementation": "dist/index.js",
|
|
143
|
-
"line":
|
|
143
|
+
"line": 25589
|
|
144
144
|
},
|
|
145
145
|
"WorkflowsPG": {
|
|
146
146
|
"types": "dist/storage/domains/workflows/index.d.ts",
|
|
147
147
|
"implementation": "dist/index.js",
|
|
148
|
-
"line":
|
|
148
|
+
"line": 25972
|
|
149
149
|
},
|
|
150
150
|
"WorkspacesPG": {
|
|
151
151
|
"types": "dist/storage/domains/workspaces/index.d.ts",
|
|
152
152
|
"implementation": "dist/index.js",
|
|
153
|
-
"line":
|
|
153
|
+
"line": 27258
|
|
154
154
|
},
|
|
155
155
|
"exportSchemas": {
|
|
156
156
|
"types": "dist/storage/index.d.ts",
|
|
157
157
|
"implementation": "dist/index.js",
|
|
158
|
-
"line":
|
|
158
|
+
"line": 28356
|
|
159
159
|
}
|
|
160
160
|
},
|
|
161
161
|
"modules": {}
|
package/dist/index.cjs
CHANGED
|
@@ -2089,8 +2089,10 @@ function truncateQuery(query, maxLength = 100) {
|
|
|
2089
2089
|
*/
|
|
2090
2090
|
var PoolAdapter = class {
|
|
2091
2091
|
$pool;
|
|
2092
|
-
|
|
2092
|
+
onRollbackError;
|
|
2093
|
+
constructor($pool, onRollbackError) {
|
|
2093
2094
|
this.$pool = $pool;
|
|
2095
|
+
this.onRollbackError = onRollbackError;
|
|
2094
2096
|
}
|
|
2095
2097
|
connect() {
|
|
2096
2098
|
return this.$pool.connect();
|
|
@@ -2127,8 +2129,14 @@ var PoolAdapter = class {
|
|
|
2127
2129
|
}
|
|
2128
2130
|
async tx(callback) {
|
|
2129
2131
|
const client = await this.$pool.connect();
|
|
2132
|
+
let destroyClient = false;
|
|
2130
2133
|
try {
|
|
2131
|
-
|
|
2134
|
+
try {
|
|
2135
|
+
await client.query("BEGIN");
|
|
2136
|
+
} catch (error) {
|
|
2137
|
+
destroyClient = true;
|
|
2138
|
+
throw error;
|
|
2139
|
+
}
|
|
2132
2140
|
const txClient = new TransactionClient(client);
|
|
2133
2141
|
try {
|
|
2134
2142
|
const result = await callback(txClient);
|
|
@@ -2140,12 +2148,16 @@ var PoolAdapter = class {
|
|
|
2140
2148
|
try {
|
|
2141
2149
|
await client.query("ROLLBACK");
|
|
2142
2150
|
} catch (rollbackError) {
|
|
2143
|
-
|
|
2151
|
+
destroyClient = true;
|
|
2152
|
+
try {
|
|
2153
|
+
if (this.onRollbackError) await this.onRollbackError(rollbackError);
|
|
2154
|
+
else console.error("Failed to rollback transaction:", rollbackError);
|
|
2155
|
+
} catch {}
|
|
2144
2156
|
}
|
|
2145
2157
|
throw error;
|
|
2146
2158
|
}
|
|
2147
2159
|
} finally {
|
|
2148
|
-
client.release();
|
|
2160
|
+
client.release(destroyClient || void 0);
|
|
2149
2161
|
}
|
|
2150
2162
|
}
|
|
2151
2163
|
};
|
|
@@ -2252,6 +2264,7 @@ var TransactionClient = class {
|
|
|
2252
2264
|
var PinnedClientAdapter = class {
|
|
2253
2265
|
$pool;
|
|
2254
2266
|
pinnedClient;
|
|
2267
|
+
onRollbackError;
|
|
2255
2268
|
/**
|
|
2256
2269
|
* Serialization tail. Domain init() methods fire via Promise.all in
|
|
2257
2270
|
* MastraCompositeStore.#runInit(), so without our own gate every domain's
|
|
@@ -2262,9 +2275,14 @@ var PinnedClientAdapter = class {
|
|
|
2262
2275
|
* the reliance on pg's internal queue.
|
|
2263
2276
|
*/
|
|
2264
2277
|
#tail = Promise.resolve();
|
|
2265
|
-
|
|
2278
|
+
#rollbackError;
|
|
2279
|
+
constructor($pool, pinnedClient, onRollbackError) {
|
|
2266
2280
|
this.$pool = $pool;
|
|
2267
2281
|
this.pinnedClient = pinnedClient;
|
|
2282
|
+
this.onRollbackError = onRollbackError;
|
|
2283
|
+
}
|
|
2284
|
+
get shouldDestroyClient() {
|
|
2285
|
+
return this.#rollbackError !== void 0;
|
|
2268
2286
|
}
|
|
2269
2287
|
/**
|
|
2270
2288
|
* Run `fn` after any previously enqueued work on this pinned client has
|
|
@@ -2272,7 +2290,11 @@ var PinnedClientAdapter = class {
|
|
|
2272
2290
|
* resume on the next caller's turn.
|
|
2273
2291
|
*/
|
|
2274
2292
|
#enqueue(fn) {
|
|
2275
|
-
const
|
|
2293
|
+
const run = async () => {
|
|
2294
|
+
if (this.shouldDestroyClient) throw this.#rollbackError;
|
|
2295
|
+
return fn();
|
|
2296
|
+
};
|
|
2297
|
+
const next = this.#tail.then(run, run);
|
|
2276
2298
|
this.#tail = next.catch(() => void 0);
|
|
2277
2299
|
return next;
|
|
2278
2300
|
}
|
|
@@ -2324,7 +2346,12 @@ var PinnedClientAdapter = class {
|
|
|
2324
2346
|
}
|
|
2325
2347
|
tx(callback) {
|
|
2326
2348
|
return this.#enqueue(async () => {
|
|
2327
|
-
|
|
2349
|
+
try {
|
|
2350
|
+
await this.pinnedClient.query("BEGIN");
|
|
2351
|
+
} catch (error) {
|
|
2352
|
+
this.#rollbackError = error;
|
|
2353
|
+
throw error;
|
|
2354
|
+
}
|
|
2328
2355
|
const txClient = new TransactionClient(this.pinnedClient);
|
|
2329
2356
|
try {
|
|
2330
2357
|
const result = await callback(txClient);
|
|
@@ -2336,7 +2363,11 @@ var PinnedClientAdapter = class {
|
|
|
2336
2363
|
try {
|
|
2337
2364
|
await this.pinnedClient.query("ROLLBACK");
|
|
2338
2365
|
} catch (rollbackError) {
|
|
2339
|
-
|
|
2366
|
+
this.#rollbackError = rollbackError;
|
|
2367
|
+
try {
|
|
2368
|
+
if (this.onRollbackError) await this.onRollbackError(rollbackError);
|
|
2369
|
+
else console.error("Failed to rollback transaction:", rollbackError);
|
|
2370
|
+
} catch {}
|
|
2340
2371
|
}
|
|
2341
2372
|
throw error;
|
|
2342
2373
|
}
|
|
@@ -28124,18 +28155,29 @@ var PgFactoryStorageOps = class {
|
|
|
28124
28155
|
};
|
|
28125
28156
|
if (this.#transactionClient) return run(this.#transactionClient);
|
|
28126
28157
|
const client = await this.#queryable.connect();
|
|
28158
|
+
let releaseError;
|
|
28127
28159
|
try {
|
|
28128
|
-
|
|
28160
|
+
try {
|
|
28161
|
+
await client.query("BEGIN");
|
|
28162
|
+
} catch (error) {
|
|
28163
|
+
releaseError = error instanceof Error ? error : new Error(String(error));
|
|
28164
|
+
throw error;
|
|
28165
|
+
}
|
|
28129
28166
|
try {
|
|
28130
28167
|
const result = await run(client);
|
|
28131
28168
|
await client.query("COMMIT");
|
|
28132
28169
|
return result;
|
|
28133
28170
|
} catch (error) {
|
|
28134
|
-
|
|
28171
|
+
try {
|
|
28172
|
+
await client.query("ROLLBACK");
|
|
28173
|
+
} catch (rollbackError) {
|
|
28174
|
+
releaseError = rollbackError instanceof Error ? rollbackError : new Error(String(rollbackError));
|
|
28175
|
+
throw new AggregateError([error, rollbackError], "Factory transaction and rollback both failed");
|
|
28176
|
+
}
|
|
28135
28177
|
throw error;
|
|
28136
28178
|
}
|
|
28137
28179
|
} finally {
|
|
28138
|
-
client.release();
|
|
28180
|
+
client.release(releaseError);
|
|
28139
28181
|
}
|
|
28140
28182
|
}
|
|
28141
28183
|
};
|
|
@@ -28192,7 +28234,12 @@ var PgFactoryStorage = class extends _mastra_core_storage.FactoryStorage {
|
|
|
28192
28234
|
let transactionOpen = false;
|
|
28193
28235
|
let releaseError;
|
|
28194
28236
|
try {
|
|
28195
|
-
|
|
28237
|
+
try {
|
|
28238
|
+
await client.query(options?.isolationLevel === "serializable" ? "BEGIN ISOLATION LEVEL SERIALIZABLE" : "BEGIN");
|
|
28239
|
+
} catch (error) {
|
|
28240
|
+
releaseError = error instanceof Error ? error : new Error(String(error));
|
|
28241
|
+
throw error;
|
|
28242
|
+
}
|
|
28196
28243
|
transactionOpen = true;
|
|
28197
28244
|
const result = await fn(new PgFactoryStorageOps(client, this.#schemas, client));
|
|
28198
28245
|
await client.query("COMMIT");
|
|
@@ -28394,8 +28441,9 @@ var PostgresStore = class extends _mastra_core_storage.MastraCompositeStore {
|
|
|
28394
28441
|
this.#ownsWritePool = true;
|
|
28395
28442
|
}
|
|
28396
28443
|
this.#readPool = config.readPool ?? this.#writePool;
|
|
28397
|
-
|
|
28398
|
-
this.#
|
|
28444
|
+
const onRollbackError = (error) => this.logger?.error?.("Transaction rollback failed", { error });
|
|
28445
|
+
this.#db = new RoutingDbClient(new PoolAdapter(this.#writePool, onRollbackError));
|
|
28446
|
+
this.#readDb = this.#readPool === this.#writePool ? this.#db : new PoolAdapter(this.#readPool, onRollbackError);
|
|
28399
28447
|
const domainConfig = {
|
|
28400
28448
|
client: this.#db,
|
|
28401
28449
|
readClient: this.#readDb,
|
|
@@ -28464,7 +28512,7 @@ var PostgresStore = class extends _mastra_core_storage.MastraCompositeStore {
|
|
|
28464
28512
|
let pinned;
|
|
28465
28513
|
try {
|
|
28466
28514
|
pinnedClient = await this.#writePool.connect();
|
|
28467
|
-
pinned = new PinnedClientAdapter(this.#writePool, pinnedClient);
|
|
28515
|
+
pinned = new PinnedClientAdapter(this.#writePool, pinnedClient, (error) => this.logger?.error?.("Transaction rollback failed", { error }));
|
|
28468
28516
|
this.#db.pin(pinned);
|
|
28469
28517
|
for (let attempt = 1; attempt <= 3; attempt++) {
|
|
28470
28518
|
this.#db.setSchemaSnapshot(await loadSchemaSnapshot(pinned, this.schema));
|
|
@@ -28489,7 +28537,7 @@ var PostgresStore = class extends _mastra_core_storage.MastraCompositeStore {
|
|
|
28489
28537
|
this.#db.setSchemaSnapshot(null);
|
|
28490
28538
|
if (pinnedClient) {
|
|
28491
28539
|
this.#db.unpin();
|
|
28492
|
-
pinnedClient.release();
|
|
28540
|
+
pinnedClient.release(pinned?.shouldDestroyClient || void 0);
|
|
28493
28541
|
}
|
|
28494
28542
|
}
|
|
28495
28543
|
}
|