@mastra/pg 0.3.0-alpha.3 → 0.3.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.
@@ -1,23 +1,23 @@
1
1
 
2
- > @mastra/pg@0.3.0-alpha.3 build /home/runner/work/mastra/mastra/stores/pg
2
+ > @mastra/pg@0.3.0-alpha.5 build /home/runner/work/mastra/mastra/stores/pg
3
3
  > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
4
4
 
5
5
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.4.0
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 10982ms
9
+ TSC ⚡️ Build success in 10144ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
12
  Analysis will use the bundled TypeScript version 5.8.2
13
13
  Writing package typings: /home/runner/work/mastra/mastra/stores/pg/dist/_tsup-dts-rollup.d.ts
14
14
  Analysis will use the bundled TypeScript version 5.8.2
15
15
  Writing package typings: /home/runner/work/mastra/mastra/stores/pg/dist/_tsup-dts-rollup.d.cts
16
- DTS ⚡️ Build success in 12779ms
16
+ DTS ⚡️ Build success in 12459ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- ESM dist/index.js 45.68 KB
21
- ESM ⚡️ Build success in 1276ms
22
- CJS dist/index.cjs 46.10 KB
23
- CJS ⚡️ Build success in 1276ms
20
+ CJS dist/index.cjs 47.42 KB
21
+ CJS ⚡️ Build success in 1401ms
22
+ ESM dist/index.js 46.99 KB
23
+ ESM ⚡️ Build success in 1404ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 0.3.0-alpha.5
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [08bb78e]
8
+ - @mastra/core@0.9.0-alpha.5
9
+
10
+ ## 0.3.0-alpha.4
11
+
12
+ ### Patch Changes
13
+
14
+ - 373458f: updated schema for storage config to align with pgvector and added validation for pg connections
15
+ - Updated dependencies [7e92011]
16
+ - @mastra/core@0.9.0-alpha.4
17
+
3
18
  ## 0.3.0-alpha.3
4
19
 
5
20
  ### Minor Changes
@@ -246,6 +246,10 @@ export { PgVector }
246
246
  export { PgVector as PgVector_alias_1 }
247
247
 
248
248
  declare type PostgresConfig = {
249
+ schemaName?: string;
250
+ /**
251
+ * @deprecated Use `schemaName` instead. Support for `schema` will be removed in a future release.
252
+ */
249
253
  schema?: string;
250
254
  } & ({
251
255
  host: string;
@@ -246,6 +246,10 @@ export { PgVector }
246
246
  export { PgVector as PgVector_alias_1 }
247
247
 
248
248
  declare type PostgresConfig = {
249
+ schemaName?: string;
250
+ /**
251
+ * @deprecated Use `schemaName` instead. Support for `schema` will be removed in a future release.
252
+ */
249
253
  schema?: string;
250
254
  } & ({
251
255
  host: string;
package/dist/index.cjs CHANGED
@@ -305,8 +305,13 @@ var PgVector = class extends vector.MastraVector {
305
305
  vectorExtensionInstalled = void 0;
306
306
  schemaSetupComplete = void 0;
307
307
  constructor(config) {
308
- super();
309
308
  const connectionString = typeof config === "string" ? config : config.connectionString;
309
+ if (!connectionString || typeof connectionString !== "string" || connectionString.trim() === "") {
310
+ throw new Error(
311
+ "PgVector: connectionString must be provided and cannot be empty. Passing an empty string may cause fallback to local Postgres defaults."
312
+ );
313
+ }
314
+ super();
310
315
  this.schema = typeof config === "string" ? void 0 : config.schemaName;
311
316
  const basePool = new pg__default.default.Pool({
312
317
  connectionString,
@@ -793,9 +798,30 @@ var PostgresStore = class extends storage.MastraStorage {
793
798
  setupSchemaPromise = null;
794
799
  schemaSetupComplete = void 0;
795
800
  constructor(config) {
801
+ if ("connectionString" in config) {
802
+ if (!config.connectionString || typeof config.connectionString !== "string" || config.connectionString.trim() === "") {
803
+ throw new Error(
804
+ "PostgresStore: connectionString must be provided and cannot be empty. Passing an empty string may cause fallback to local Postgres defaults."
805
+ );
806
+ }
807
+ } else {
808
+ const required = ["host", "database", "user", "password"];
809
+ for (const key of required) {
810
+ if (!(key in config) || typeof config[key] !== "string" || config[key].trim() === "") {
811
+ throw new Error(
812
+ `PostgresStore: ${key} must be provided and cannot be empty. Passing an empty string may cause fallback to local Postgres defaults.`
813
+ );
814
+ }
815
+ }
816
+ }
796
817
  super({ name: "PostgresStore" });
797
818
  this.pgp = pgPromise__default.default();
798
- this.schema = config.schema;
819
+ if ("schema" in config && config.schema) {
820
+ console.warn(
821
+ '[DEPRECATION NOTICE] The "schema" option in PostgresStore is deprecated. Please use "schemaName" instead. Support for "schema" will be removed in a future release.'
822
+ );
823
+ }
824
+ this.schema = config.schemaName ?? config.schema;
799
825
  this.db = this.pgp(
800
826
  `connectionString` in config ? { connectionString: config.connectionString } : {
801
827
  host: config.host,
package/dist/index.js CHANGED
@@ -297,8 +297,13 @@ var PgVector = class extends MastraVector {
297
297
  vectorExtensionInstalled = void 0;
298
298
  schemaSetupComplete = void 0;
299
299
  constructor(config) {
300
- super();
301
300
  const connectionString = typeof config === "string" ? config : config.connectionString;
301
+ if (!connectionString || typeof connectionString !== "string" || connectionString.trim() === "") {
302
+ throw new Error(
303
+ "PgVector: connectionString must be provided and cannot be empty. Passing an empty string may cause fallback to local Postgres defaults."
304
+ );
305
+ }
306
+ super();
302
307
  this.schema = typeof config === "string" ? void 0 : config.schemaName;
303
308
  const basePool = new pg.Pool({
304
309
  connectionString,
@@ -785,9 +790,30 @@ var PostgresStore = class extends MastraStorage {
785
790
  setupSchemaPromise = null;
786
791
  schemaSetupComplete = void 0;
787
792
  constructor(config) {
793
+ if ("connectionString" in config) {
794
+ if (!config.connectionString || typeof config.connectionString !== "string" || config.connectionString.trim() === "") {
795
+ throw new Error(
796
+ "PostgresStore: connectionString must be provided and cannot be empty. Passing an empty string may cause fallback to local Postgres defaults."
797
+ );
798
+ }
799
+ } else {
800
+ const required = ["host", "database", "user", "password"];
801
+ for (const key of required) {
802
+ if (!(key in config) || typeof config[key] !== "string" || config[key].trim() === "") {
803
+ throw new Error(
804
+ `PostgresStore: ${key} must be provided and cannot be empty. Passing an empty string may cause fallback to local Postgres defaults.`
805
+ );
806
+ }
807
+ }
808
+ }
788
809
  super({ name: "PostgresStore" });
789
810
  this.pgp = pgPromise();
790
- this.schema = config.schema;
811
+ if ("schema" in config && config.schema) {
812
+ console.warn(
813
+ '[DEPRECATION NOTICE] The "schema" option in PostgresStore is deprecated. Please use "schemaName" instead. Support for "schema" will be removed in a future release.'
814
+ );
815
+ }
816
+ this.schema = config.schemaName ?? config.schema;
791
817
  this.db = this.pgp(
792
818
  `connectionString` in config ? { connectionString: config.connectionString } : {
793
819
  host: config.host,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/pg",
3
- "version": "0.3.0-alpha.3",
3
+ "version": "0.3.0-alpha.5",
4
4
  "description": "Postgres provider for Mastra - includes both vector and db storage capabilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -24,7 +24,7 @@
24
24
  "pg": "^8.13.3",
25
25
  "pg-promise": "^11.11.0",
26
26
  "xxhash-wasm": "^1.1.0",
27
- "@mastra/core": "^0.9.0-alpha.3"
27
+ "@mastra/core": "^0.9.0-alpha.5"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@microsoft/api-extractor": "^7.52.1",
@@ -104,6 +104,50 @@ describe('PostgresStore', () => {
104
104
  }
105
105
  });
106
106
 
107
+ // --- Validation tests ---
108
+ describe('Validation', () => {
109
+ const validConfig = TEST_CONFIG;
110
+ it('throws if connectionString is empty', () => {
111
+ expect(() => new PostgresStore({ connectionString: '' })).toThrow(
112
+ /connectionString must be provided and cannot be empty/,
113
+ );
114
+ });
115
+ it('throws if host is missing or empty', () => {
116
+ expect(() => new PostgresStore({ ...validConfig, host: '' })).toThrow(
117
+ /host must be provided and cannot be empty/,
118
+ );
119
+ const { host, ...rest } = validConfig;
120
+ expect(() => new PostgresStore(rest as any)).toThrow(/host must be provided and cannot be empty/);
121
+ });
122
+ it('throws if user is missing or empty', () => {
123
+ expect(() => new PostgresStore({ ...validConfig, user: '' })).toThrow(
124
+ /user must be provided and cannot be empty/,
125
+ );
126
+ const { user, ...rest } = validConfig;
127
+ expect(() => new PostgresStore(rest as any)).toThrow(/user must be provided and cannot be empty/);
128
+ });
129
+ it('throws if database is missing or empty', () => {
130
+ expect(() => new PostgresStore({ ...validConfig, database: '' })).toThrow(
131
+ /database must be provided and cannot be empty/,
132
+ );
133
+ const { database, ...rest } = validConfig;
134
+ expect(() => new PostgresStore(rest as any)).toThrow(/database must be provided and cannot be empty/);
135
+ });
136
+ it('throws if password is missing or empty', () => {
137
+ expect(() => new PostgresStore({ ...validConfig, password: '' })).toThrow(
138
+ /password must be provided and cannot be empty/,
139
+ );
140
+ const { password, ...rest } = validConfig;
141
+ expect(() => new PostgresStore(rest as any)).toThrow(/password must be provided and cannot be empty/);
142
+ });
143
+ it('does not throw on valid config (host-based)', () => {
144
+ expect(() => new PostgresStore(validConfig)).not.toThrow();
145
+ });
146
+ it('does not throw on non-empty connection string', () => {
147
+ expect(() => new PostgresStore({ connectionString })).not.toThrow();
148
+ });
149
+ });
150
+
107
151
  describe('Thread Operations', () => {
108
152
  it('should create and retrieve a thread', async () => {
109
153
  const thread = createSampleThread();
@@ -662,7 +706,7 @@ describe('PostgresStore', () => {
662
706
  beforeAll(async () => {
663
707
  customSchemaStore = new PostgresStore({
664
708
  ...TEST_CONFIG,
665
- schema: customSchema,
709
+ schemaName: customSchema,
666
710
  });
667
711
 
668
712
  await customSchemaStore.init();
@@ -844,7 +888,7 @@ describe('PostgresStore', () => {
844
888
  ...TEST_CONFIG,
845
889
  user: schemaRestrictedUser,
846
890
  password: restrictedPassword,
847
- schema: testSchema,
891
+ schemaName: testSchema,
848
892
  });
849
893
 
850
894
  // Create a fresh connection for verification
@@ -876,7 +920,7 @@ describe('PostgresStore', () => {
876
920
  ...TEST_CONFIG,
877
921
  user: schemaRestrictedUser,
878
922
  password: restrictedPassword,
879
- schema: testSchema,
923
+ schemaName: testSchema,
880
924
  });
881
925
 
882
926
  // Create a fresh connection for verification
@@ -13,7 +13,13 @@ import type { WorkflowRunState } from '@mastra/core/workflows';
13
13
  import pgPromise from 'pg-promise';
14
14
  import type { ISSLConfig } from 'pg-promise/typescript/pg-subset';
15
15
 
16
- export type PostgresConfig = { schema?: string } & (
16
+ export type PostgresConfig = {
17
+ schemaName?: string;
18
+ /**
19
+ * @deprecated Use `schemaName` instead. Support for `schema` will be removed in a future release.
20
+ */
21
+ schema?: string;
22
+ } & (
17
23
  | {
18
24
  host: string;
19
25
  port: number;
@@ -35,9 +41,36 @@ export class PostgresStore extends MastraStorage {
35
41
  private schemaSetupComplete: boolean | undefined = undefined;
36
42
 
37
43
  constructor(config: PostgresConfig) {
44
+ // Validation: connectionString or host/database/user/password must not be empty
45
+ if ('connectionString' in config) {
46
+ if (
47
+ !config.connectionString ||
48
+ typeof config.connectionString !== 'string' ||
49
+ config.connectionString.trim() === ''
50
+ ) {
51
+ throw new Error(
52
+ 'PostgresStore: connectionString must be provided and cannot be empty. Passing an empty string may cause fallback to local Postgres defaults.',
53
+ );
54
+ }
55
+ } else {
56
+ const required = ['host', 'database', 'user', 'password'];
57
+ for (const key of required) {
58
+ if (!(key in config) || typeof (config as any)[key] !== 'string' || (config as any)[key].trim() === '') {
59
+ throw new Error(
60
+ `PostgresStore: ${key} must be provided and cannot be empty. Passing an empty string may cause fallback to local Postgres defaults.`,
61
+ );
62
+ }
63
+ }
64
+ }
38
65
  super({ name: 'PostgresStore' });
39
66
  this.pgp = pgPromise();
40
- this.schema = config.schema;
67
+ // Deprecation notice for schema (old option)
68
+ if ('schema' in config && config.schema) {
69
+ console.warn(
70
+ '[DEPRECATION NOTICE] The "schema" option in PostgresStore is deprecated. Please use "schemaName" instead. Support for "schema" will be removed in a future release.',
71
+ );
72
+ }
73
+ this.schema = config.schemaName ?? config.schema;
41
74
  this.db = this.pgp(
42
75
  `connectionString` in config
43
76
  ? { connectionString: config.connectionString }
@@ -21,6 +21,24 @@ describe('PgVector', () => {
21
21
  await vectorDB.disconnect();
22
22
  });
23
23
 
24
+ // --- Validation tests ---
25
+ describe('Validation', () => {
26
+ it('throws if connectionString is empty (string)', () => {
27
+ expect(() => new PgVector('')).toThrow(/connectionString must be provided and cannot be empty/);
28
+ });
29
+ it('throws if connectionString is empty (object)', () => {
30
+ expect(() => new PgVector({ connectionString: '' })).toThrow(
31
+ /connectionString must be provided and cannot be empty/,
32
+ );
33
+ });
34
+ it('does not throw on non-empty connection string (string)', () => {
35
+ expect(() => new PgVector(connectionString)).not.toThrow();
36
+ });
37
+ it('does not throw on non-empty connection string (object)', () => {
38
+ expect(() => new PgVector({ connectionString })).not.toThrow();
39
+ });
40
+ });
41
+
24
42
  // Index Management Tests
25
43
  describe('Index Management', () => {
26
44
  describe('createIndex', () => {
@@ -329,8 +347,8 @@ describe('PgVector', () => {
329
347
  expect(results[0]?.vector).toEqual(newVector);
330
348
  });
331
349
 
332
- it('should throw exception when no updates are given', () => {
333
- expect(vectorDB.updateIndexById(testIndexName, 'id', {})).rejects.toThrow('No updates provided');
350
+ it('should throw exception when no updates are given', async () => {
351
+ await expect(vectorDB.updateIndexById(testIndexName, 'id', {})).rejects.toThrow('No updates provided');
334
352
  });
335
353
  });
336
354
 
@@ -73,9 +73,14 @@ export class PgVector extends MastraVector {
73
73
  constructor(connectionString: string);
74
74
  constructor(config: { connectionString: string; schemaName?: string });
75
75
  constructor(config: string | { connectionString: string; schemaName?: string }) {
76
+ const connectionString = typeof config === 'string' ? config : config.connectionString;
77
+ if (!connectionString || typeof connectionString !== 'string' || connectionString.trim() === '') {
78
+ throw new Error(
79
+ 'PgVector: connectionString must be provided and cannot be empty. Passing an empty string may cause fallback to local Postgres defaults.',
80
+ );
81
+ }
76
82
  super();
77
83
 
78
- const connectionString = typeof config === 'string' ? config : config.connectionString;
79
84
  this.schema = typeof config === 'string' ? undefined : config.schemaName;
80
85
 
81
86
  const basePool = new pg.Pool({