@mastra/pg 1.17.0-alpha.1 → 1.17.0-alpha.3

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,39 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 1.17.0-alpha.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed a missing semicolon in the SQL generated by exportSchemas(). The CREATE INDEX statement for the favorites table ran into the next CREATE TABLE statement, so applying the exported schema as a single query (for example with pg's client.query() or a Supabase migration) failed with a Postgres syntax error. Fixes https://github.com/mastra-ai/mastra/issues/19942 ([#19944](https://github.com/mastra-ai/mastra/pull/19944))
8
+
9
+ ## 1.17.0-alpha.2
10
+
11
+ ### Patch Changes
12
+
13
+ - Replaced GitHub-specific Mastra Code session state with Factory project and linked-repository identities. This lets SDK consumers represent sessions independently of a source-control provider and select a repository explicitly when sandbox execution is required. ([#19849](https://github.com/mastra-ai/mastra/pull/19849))
14
+
15
+ Updated Mastra Code onboarding to be Factory-first: create a Factory by name, then link repositories from your connected source-control installations in a separate step. A Factory is valid with zero linked repositories, and the Board, Metrics, and Audit pages stay available for any server-backed Factory. Factory pages keep project-scoped data separate from repository-scoped intake and provide a repository selector when a Factory has multiple linked repositories. Creating a Factory from a local folder remains available as a secondary option.
16
+
17
+ **Before**
18
+
19
+ ```ts
20
+ const state = { githubProjectId: 'project-1', sandboxId, sandboxWorkdir };
21
+ ```
22
+
23
+ **After**
24
+
25
+ ```ts
26
+ const state = {
27
+ factoryProjectId: 'factory-project-1',
28
+ projectRepositoryId: 'project-repository-1',
29
+ sandboxId,
30
+ sandboxWorkdir,
31
+ };
32
+ ```
33
+
34
+ - Updated dependencies [[`41a5392`](https://github.com/mastra-ai/mastra/commit/41a5392d9f6c5e18d6b227f0fc0ddf49c50774e9), [`675fbff`](https://github.com/mastra-ai/mastra/commit/675fbff84d3274391b33e852f76083c38a5514e5), [`da009e1`](https://github.com/mastra-ai/mastra/commit/da009e1aacd89ed94b8d1b2af09c9d4fe7c4db49), [`35c2181`](https://github.com/mastra-ai/mastra/commit/35c2181e6a50e47c90ba36260db7c9723d54696f), [`b4b7ea8`](https://github.com/mastra-ai/mastra/commit/b4b7ea8733f033fc441ea47ed03f6afb17ec2248), [`675fbff`](https://github.com/mastra-ai/mastra/commit/675fbff84d3274391b33e852f76083c38a5514e5), [`c328769`](https://github.com/mastra-ai/mastra/commit/c3287698ff8ef98dba86d415faa566fa3e5f4d56), [`232fcbc`](https://github.com/mastra-ai/mastra/commit/232fcbc14fce625dd672ba043329c0b732c62be2), [`3491666`](https://github.com/mastra-ai/mastra/commit/34916663c4fdd43b48c21f4ab2d5fb6dcccc94f9)]:
35
+ - @mastra/core@1.52.0-alpha.10
36
+
3
37
  ## 1.17.0-alpha.1
4
38
 
5
39
  ### Minor Changes
@@ -3,7 +3,7 @@ name: mastra-pg
3
3
  description: Documentation for @mastra/pg. Use when working with @mastra/pg APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/pg"
6
- version: "1.17.0-alpha.1"
6
+ version: "1.17.0-alpha.3"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.17.0-alpha.1",
2
+ "version": "1.17.0-alpha.3",
3
3
  "package": "@mastra/pg",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -7326,7 +7326,7 @@ var FavoritesPG = class _FavoritesPG extends storage.FavoritesStorage {
7326
7326
  }
7327
7327
  const fullFavoritesTable = getTableName2({ indexName: storage.TABLE_FAVORITES, schemaName: getSchemaName2(schemaName) });
7328
7328
  statements.push(
7329
- `CREATE INDEX IF NOT EXISTS idx_favorites_entity ON ${fullFavoritesTable} ("entityType", "entityId")`
7329
+ `CREATE INDEX IF NOT EXISTS idx_favorites_entity ON ${fullFavoritesTable} ("entityType", "entityId");`
7330
7330
  );
7331
7331
  return statements;
7332
7332
  }
@@ -20255,10 +20255,12 @@ function hashAdvisoryLockKey(key) {
20255
20255
  return [digest.readInt32BE(0), digest.readInt32BE(4)];
20256
20256
  }
20257
20257
  var PgFactoryStorageOps = class {
20258
- #pool;
20258
+ #queryable;
20259
+ #transactionClient;
20259
20260
  #schemas;
20260
- constructor(pool, schemas) {
20261
- this.#pool = pool;
20261
+ constructor(queryable, schemas, transactionClient) {
20262
+ this.#queryable = queryable;
20263
+ this.#transactionClient = transactionClient;
20262
20264
  this.#schemas = schemas;
20263
20265
  }
20264
20266
  #schema(collection) {
@@ -20406,11 +20408,11 @@ var PgFactoryStorageOps = class {
20406
20408
  return result.rows.map((raw) => this.#deserializeRow(schema, raw));
20407
20409
  }
20408
20410
  async findOne(collection, where) {
20409
- const rows = await this.#select(this.#pool, collection, where, { limit: 1 });
20411
+ const rows = await this.#select(this.#queryable, collection, where, { limit: 1 });
20410
20412
  return rows[0] ?? null;
20411
20413
  }
20412
20414
  async findMany(collection, where, opts) {
20413
- return this.#select(this.#pool, collection, where, opts);
20415
+ return this.#select(this.#queryable, collection, where, opts);
20414
20416
  }
20415
20417
  async insertOne(collection, row) {
20416
20418
  const schema = this.#schema(collection);
@@ -20424,7 +20426,7 @@ var PgFactoryStorageOps = class {
20424
20426
  const sql = `INSERT INTO "${schema.name}" (${columns.map((c) => `"${c}"`).join(", ")}) VALUES (${columns.map((_, i) => `$${i + 1}`).join(", ")}) RETURNING *`;
20425
20427
  const args = columns.map((column) => this.#serialize(this.#column(schema, column), values[column]));
20426
20428
  try {
20427
- const result = await this.#pool.query(sql, args);
20429
+ const result = await this.#queryable.query(sql, args);
20428
20430
  return this.#deserializeRow(schema, result.rows[0]);
20429
20431
  } catch (error) {
20430
20432
  if (isUniqueViolation(error)) throw new storage.UniqueViolationError(collection, { cause: error });
@@ -20462,7 +20464,7 @@ var PgFactoryStorageOps = class {
20462
20464
  throw lastError ?? new Error(`PgFactoryStorage: upsert into '${collection}' did not converge`);
20463
20465
  }
20464
20466
  async updateMany(collection, where, set) {
20465
- return this.#updateMany(this.#pool, collection, where, set);
20467
+ return this.#updateMany(this.#queryable, collection, where, set);
20466
20468
  }
20467
20469
  async #updateMany(queryable, collection, where, set) {
20468
20470
  const schema = this.#schema(collection);
@@ -20477,30 +20479,30 @@ var PgFactoryStorageOps = class {
20477
20479
  async deleteMany(collection, where) {
20478
20480
  const schema = this.#schema(collection);
20479
20481
  const filter = this.#buildWhere(schema, where);
20480
- const result = await this.#pool.query(`DELETE FROM "${schema.name}" WHERE ${filter.sql}`, filter.args);
20482
+ const result = await this.#queryable.query(`DELETE FROM "${schema.name}" WHERE ${filter.sql}`, filter.args);
20481
20483
  return result.rowCount ?? 0;
20482
20484
  }
20483
20485
  async updateAtomic(collection, where, fn) {
20484
- const schema = this.#schema(collection);
20485
- const pk = primaryKeyOf(schema);
20486
- const client = await this.#pool.connect();
20486
+ const run = async (client2) => {
20487
+ const schema = this.#schema(collection);
20488
+ const pk = primaryKeyOf(schema);
20489
+ const rows = await this.#select(client2, collection, where, { limit: 1 }, true);
20490
+ const row = rows[0];
20491
+ if (!row) return null;
20492
+ const patch = await fn(row);
20493
+ if (patch === null) return row;
20494
+ const pkWhere = { [pk]: row[pk] };
20495
+ await this.#updateMany(client2, collection, pkWhere, patch);
20496
+ const updated = await this.#select(client2, collection, pkWhere, { limit: 1 });
20497
+ return updated[0] ?? null;
20498
+ };
20499
+ if (this.#transactionClient) return run(this.#transactionClient);
20500
+ const pool = this.#queryable;
20501
+ const client = await pool.connect();
20487
20502
  try {
20488
20503
  await client.query("BEGIN");
20489
20504
  try {
20490
- const rows = await this.#select(client, collection, where, { limit: 1 }, true);
20491
- const row = rows[0];
20492
- if (!row) {
20493
- await client.query("COMMIT");
20494
- return null;
20495
- }
20496
- const patch = await fn(row);
20497
- let result = row;
20498
- if (patch !== null) {
20499
- const pkWhere = { [pk]: row[pk] };
20500
- await this.#updateMany(client, collection, pkWhere, patch);
20501
- const updated = await this.#select(client, collection, pkWhere, { limit: 1 });
20502
- result = updated[0] ?? null;
20503
- }
20505
+ const result = await run(client);
20504
20506
  await client.query("COMMIT");
20505
20507
  return result;
20506
20508
  } catch (error) {
@@ -20546,6 +20548,22 @@ var PgFactoryStorage = class extends storage.FactoryStorage {
20546
20548
  async initStorage() {
20547
20549
  await this.#pool.query("SELECT 1");
20548
20550
  }
20551
+ async withTransaction(fn) {
20552
+ const client = await this.#pool.connect();
20553
+ try {
20554
+ await client.query("BEGIN");
20555
+ try {
20556
+ const result = await fn(new PgFactoryStorageOps(client, this.#schemas, client));
20557
+ await client.query("COMMIT");
20558
+ return result;
20559
+ } catch (error) {
20560
+ await client.query("ROLLBACK");
20561
+ throw error;
20562
+ }
20563
+ } finally {
20564
+ client.release();
20565
+ }
20566
+ }
20549
20567
  async ensureCollections(schemas) {
20550
20568
  for (const schema of schemas) {
20551
20569
  await this.#ensureCollection(schema);