@mastra/pg 0.13.0 → 0.13.1-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.
Files changed (50) hide show
  1. package/.turbo/turbo-build.log +2 -21
  2. package/CHANGELOG.md +11 -0
  3. package/dist/index.cjs +29 -17
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.ts +4 -5
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +29 -17
  8. package/dist/index.js.map +1 -0
  9. package/dist/storage/domains/legacy-evals/index.d.ts +20 -0
  10. package/dist/storage/domains/legacy-evals/index.d.ts.map +1 -0
  11. package/dist/storage/domains/memory/index.d.ts +88 -0
  12. package/dist/storage/domains/memory/index.d.ts.map +1 -0
  13. package/dist/storage/domains/operations/index.d.ts +50 -0
  14. package/dist/storage/domains/operations/index.d.ts.map +1 -0
  15. package/dist/storage/domains/scores/index.d.ts +44 -0
  16. package/dist/storage/domains/scores/index.d.ts.map +1 -0
  17. package/dist/storage/domains/traces/index.d.ts +23 -0
  18. package/dist/storage/domains/traces/index.d.ts.map +1 -0
  19. package/dist/storage/domains/utils.d.ts +6 -0
  20. package/dist/storage/domains/utils.d.ts.map +1 -0
  21. package/dist/storage/domains/workflows/index.d.ts +36 -0
  22. package/dist/storage/domains/workflows/index.d.ts.map +1 -0
  23. package/dist/storage/index.d.ts +211 -0
  24. package/dist/storage/index.d.ts.map +1 -0
  25. package/dist/storage/test-utils.d.ts +5 -0
  26. package/dist/storage/test-utils.d.ts.map +1 -0
  27. package/dist/vector/filter.d.ts +32 -0
  28. package/dist/vector/filter.d.ts.map +1 -0
  29. package/dist/vector/index.d.ts +99 -0
  30. package/dist/vector/index.d.ts.map +1 -0
  31. package/dist/vector/performance.helpers.d.ts +95 -0
  32. package/dist/vector/performance.helpers.d.ts.map +1 -0
  33. package/dist/vector/prompt.d.ts +6 -0
  34. package/dist/vector/prompt.d.ts.map +1 -0
  35. package/dist/vector/sql-builder.d.ts +8 -0
  36. package/dist/vector/sql-builder.d.ts.map +1 -0
  37. package/dist/vector/types.d.ts +15 -0
  38. package/dist/vector/types.d.ts.map +1 -0
  39. package/package.json +3 -3
  40. package/src/storage/domains/operations/index.ts +5 -3
  41. package/src/storage/domains/scores/index.ts +22 -8
  42. package/src/storage/domains/workflows/index.ts +5 -5
  43. package/src/storage/index.test.ts +1 -0
  44. package/src/storage/index.ts +1 -1
  45. package/tsconfig.build.json +9 -0
  46. package/tsconfig.json +1 -1
  47. package/tsup.config.ts +22 -0
  48. package/dist/_tsup-dts-rollup.d.cts +0 -786
  49. package/dist/_tsup-dts-rollup.d.ts +0 -786
  50. package/dist/index.d.cts +0 -5
@@ -1,23 +1,4 @@
1
1
 
2
- > @mastra/pg@0.13.0-alpha.1 build /home/runner/work/mastra/mastra/stores/pg
3
- > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
2
+ > @mastra/pg@0.13.1-alpha.0 build /home/runner/work/mastra/mastra/stores/pg
3
+ > tsup --silent --config tsup.config.ts
4
4
 
5
- CLI Building entry: src/index.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v8.5.0
8
- TSC Build start
9
- TSC ⚡️ Build success in 17702ms
10
- DTS Build start
11
- CLI Target: es2022
12
- Analysis will use the bundled TypeScript version 5.8.3
13
- Writing package typings: /home/runner/work/mastra/mastra/stores/pg/dist/_tsup-dts-rollup.d.ts
14
- Analysis will use the bundled TypeScript version 5.8.3
15
- Writing package typings: /home/runner/work/mastra/mastra/stores/pg/dist/_tsup-dts-rollup.d.cts
16
- DTS ⚡️ Build success in 14252ms
17
- CLI Cleaning output folder
18
- ESM Build start
19
- CJS Build start
20
- CJS dist/index.cjs 106.34 KB
21
- CJS ⚡️ Build success in 2113ms
22
- ESM dist/index.js 104.78 KB
23
- ESM ⚡️ Build success in 2113ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 0.13.1-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - bf6c955: fix: Fix schema support to PostgreSQL scores and workflows storage
8
+ - Updated dependencies [33dcb07]
9
+ - Updated dependencies [d30b1a0]
10
+ - Updated dependencies [bff87f7]
11
+ - Updated dependencies [b4a8df0]
12
+ - @mastra/core@0.12.1-alpha.0
13
+
3
14
  ## 0.13.0
4
15
 
5
16
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -2025,7 +2025,7 @@ var StoreOperationsPG = class extends storage.StoreOperations {
2025
2025
  const schemaExists = await this.client.oneOrNone(
2026
2026
  `
2027
2027
  SELECT EXISTS (
2028
- SELECT 1 FROM information_schema.schemata
2028
+ SELECT 1 FROM information_schema.schemata
2029
2029
  WHERE schema_name = $1
2030
2030
  )
2031
2031
  `,
@@ -2138,6 +2138,7 @@ var StoreOperationsPG = class extends storage.StoreOperations {
2138
2138
  await this.setupSchema();
2139
2139
  }
2140
2140
  const finalColumns = [...columns, ...timeZColumns].join(",\n");
2141
+ const constraintPrefix = this.schemaName ? `${this.schemaName}_` : "";
2141
2142
  const sql = `
2142
2143
  CREATE TABLE IF NOT EXISTS ${getTableName({ indexName: tableName, schemaName: getSchemaName(this.schemaName) })} (
2143
2144
  ${finalColumns}
@@ -2145,10 +2146,10 @@ var StoreOperationsPG = class extends storage.StoreOperations {
2145
2146
  ${tableName === storage.TABLE_WORKFLOW_SNAPSHOT ? `
2146
2147
  DO $$ BEGIN
2147
2148
  IF NOT EXISTS (
2148
- SELECT 1 FROM pg_constraint WHERE conname = 'mastra_workflow_snapshot_workflow_name_run_id_key'
2149
+ SELECT 1 FROM pg_constraint WHERE conname = '${constraintPrefix}mastra_workflow_snapshot_workflow_name_run_id_key'
2149
2150
  ) THEN
2150
2151
  ALTER TABLE ${getTableName({ indexName: tableName, schemaName: getSchemaName(this.schemaName) })}
2151
- ADD CONSTRAINT mastra_workflow_snapshot_workflow_name_run_id_key
2152
+ ADD CONSTRAINT ${constraintPrefix}mastra_workflow_snapshot_workflow_name_run_id_key
2152
2153
  UNIQUE (workflow_name, run_id);
2153
2154
  END IF;
2154
2155
  END $$;
@@ -2315,14 +2316,23 @@ function transformScoreRow(row) {
2315
2316
  var ScoresPG = class extends storage.ScoresStorage {
2316
2317
  client;
2317
2318
  operations;
2318
- constructor({ client, operations }) {
2319
+ schema;
2320
+ constructor({
2321
+ client,
2322
+ operations,
2323
+ schema
2324
+ }) {
2319
2325
  super();
2320
2326
  this.client = client;
2321
2327
  this.operations = operations;
2328
+ this.schema = schema;
2322
2329
  }
2323
2330
  async getScoreById({ id }) {
2324
2331
  try {
2325
- const result = await this.client.oneOrNone(`SELECT * FROM ${storage.TABLE_SCORERS} WHERE id = $1`, [id]);
2332
+ const result = await this.client.oneOrNone(
2333
+ `SELECT * FROM ${getTableName({ indexName: storage.TABLE_SCORERS, schemaName: this.schema })} WHERE id = $1`,
2334
+ [id]
2335
+ );
2326
2336
  return transformScoreRow(result);
2327
2337
  } catch (error$1) {
2328
2338
  throw new error.MastraError(
@@ -2341,7 +2351,7 @@ var ScoresPG = class extends storage.ScoresStorage {
2341
2351
  }) {
2342
2352
  try {
2343
2353
  const total = await this.client.oneOrNone(
2344
- `SELECT COUNT(*) FROM ${storage.TABLE_SCORERS} WHERE "scorerId" = $1`,
2354
+ `SELECT COUNT(*) FROM ${getTableName({ indexName: storage.TABLE_SCORERS, schemaName: this.schema })} WHERE "scorerId" = $1`,
2345
2355
  [scorerId]
2346
2356
  );
2347
2357
  if (total?.count === "0" || !total?.count) {
@@ -2356,7 +2366,7 @@ var ScoresPG = class extends storage.ScoresStorage {
2356
2366
  };
2357
2367
  }
2358
2368
  const result = await this.client.manyOrNone(
2359
- `SELECT * FROM ${storage.TABLE_SCORERS} WHERE "scorerId" = $1 LIMIT $2 OFFSET $3`,
2369
+ `SELECT * FROM ${getTableName({ indexName: storage.TABLE_SCORERS, schemaName: this.schema })} WHERE "scorerId" = $1 LIMIT $2 OFFSET $3`,
2360
2370
  [scorerId, pagination.perPage, pagination.page * pagination.perPage]
2361
2371
  );
2362
2372
  return {
@@ -2410,7 +2420,7 @@ var ScoresPG = class extends storage.ScoresStorage {
2410
2420
  }) {
2411
2421
  try {
2412
2422
  const total = await this.client.oneOrNone(
2413
- `SELECT COUNT(*) FROM ${storage.TABLE_SCORERS} WHERE "runId" = $1`,
2423
+ `SELECT COUNT(*) FROM ${getTableName({ indexName: storage.TABLE_SCORERS, schemaName: this.schema })} WHERE "runId" = $1`,
2414
2424
  [runId]
2415
2425
  );
2416
2426
  console.log(`total: ${total?.count}`);
@@ -2427,7 +2437,7 @@ var ScoresPG = class extends storage.ScoresStorage {
2427
2437
  };
2428
2438
  }
2429
2439
  const result = await this.client.manyOrNone(
2430
- `SELECT * FROM ${storage.TABLE_SCORERS} WHERE "runId" = $1 LIMIT $2 OFFSET $3`,
2440
+ `SELECT * FROM ${getTableName({ indexName: storage.TABLE_SCORERS, schemaName: this.schema })} WHERE "runId" = $1 LIMIT $2 OFFSET $3`,
2431
2441
  [runId, pagination.perPage, pagination.page * pagination.perPage]
2432
2442
  );
2433
2443
  return {
@@ -2457,7 +2467,7 @@ var ScoresPG = class extends storage.ScoresStorage {
2457
2467
  }) {
2458
2468
  try {
2459
2469
  const total = await this.client.oneOrNone(
2460
- `SELECT COUNT(*) FROM ${storage.TABLE_SCORERS} WHERE "entityId" = $1 AND "entityType" = $2`,
2470
+ `SELECT COUNT(*) FROM ${getTableName({ indexName: storage.TABLE_SCORERS, schemaName: this.schema })} WHERE "entityId" = $1 AND "entityType" = $2`,
2461
2471
  [entityId, entityType]
2462
2472
  );
2463
2473
  if (total?.count === "0" || !total?.count) {
@@ -2472,7 +2482,7 @@ var ScoresPG = class extends storage.ScoresStorage {
2472
2482
  };
2473
2483
  }
2474
2484
  const result = await this.client.manyOrNone(
2475
- `SELECT * FROM ${storage.TABLE_SCORERS} WHERE "entityId" = $1 AND "entityType" = $2 LIMIT $3 OFFSET $4`,
2485
+ `SELECT * FROM ${getTableName({ indexName: storage.TABLE_SCORERS, schemaName: this.schema })} WHERE "entityId" = $1 AND "entityType" = $2 LIMIT $3 OFFSET $4`,
2476
2486
  [entityId, entityType, pagination.perPage, pagination.page * pagination.perPage]
2477
2487
  );
2478
2488
  return {
@@ -2671,7 +2681,7 @@ var WorkflowsPG = class extends storage.WorkflowsStorage {
2671
2681
  try {
2672
2682
  const now = (/* @__PURE__ */ new Date()).toISOString();
2673
2683
  await this.client.none(
2674
- `INSERT INTO ${storage.TABLE_WORKFLOW_SNAPSHOT} (workflow_name, run_id, snapshot, "createdAt", "updatedAt")
2684
+ `INSERT INTO ${getTableName({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: this.schema })} (workflow_name, run_id, snapshot, "createdAt", "updatedAt")
2675
2685
  VALUES ($1, $2, $3, $4, $5)
2676
2686
  ON CONFLICT (workflow_name, run_id) DO UPDATE
2677
2687
  SET snapshot = $3, "updatedAt" = $5`,
@@ -2729,8 +2739,8 @@ var WorkflowsPG = class extends storage.WorkflowsStorage {
2729
2739
  }
2730
2740
  const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
2731
2741
  const query = `
2732
- SELECT * FROM ${getTableName({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: this.schema })}
2733
- ${whereClause}
2742
+ SELECT * FROM ${getTableName({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: this.schema })}
2743
+ ${whereClause}
2734
2744
  `;
2735
2745
  const queryValues = values;
2736
2746
  const result = await this.client.oneOrNone(query, queryValues);
@@ -2800,8 +2810,8 @@ var WorkflowsPG = class extends storage.WorkflowsStorage {
2800
2810
  total = Number(countResult.count);
2801
2811
  }
2802
2812
  const query = `
2803
- SELECT * FROM ${getTableName({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: this.schema })}
2804
- ${whereClause}
2813
+ SELECT * FROM ${getTableName({ indexName: storage.TABLE_WORKFLOW_SNAPSHOT, schemaName: this.schema })}
2814
+ ${whereClause}
2805
2815
  ORDER BY "createdAt" DESC
2806
2816
  ${limit !== void 0 && offset !== void 0 ? ` LIMIT $${paramIndex} OFFSET $${paramIndex + 1}` : ""}
2807
2817
  `;
@@ -2867,7 +2877,7 @@ var PostgresStore = class extends storage.MastraStorage {
2867
2877
  );
2868
2878
  this.client = this.db;
2869
2879
  const operations = new StoreOperationsPG({ client: this.client, schemaName: this.schema });
2870
- const scores = new ScoresPG({ client: this.client, operations });
2880
+ const scores = new ScoresPG({ client: this.client, operations, schema: this.schema });
2871
2881
  const traces = new TracesPG({ client: this.client, operations, schema: this.schema });
2872
2882
  const workflows = new WorkflowsPG({ client: this.client, operations, schema: this.schema });
2873
2883
  const legacyEvals = new LegacyEvalsPG({ client: this.client, schema: this.schema });
@@ -3176,3 +3186,5 @@ Example Complex Query:
3176
3186
  exports.PGVECTOR_PROMPT = PGVECTOR_PROMPT;
3177
3187
  exports.PgVector = PgVector;
3178
3188
  exports.PostgresStore = PostgresStore;
3189
+ //# sourceMappingURL=index.cjs.map
3190
+ //# sourceMappingURL=index.cjs.map