@mastra/pg 0.3.5-alpha.0 → 0.10.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/dist/index.js CHANGED
@@ -362,27 +362,11 @@ var PgVector = class extends MastraVector {
362
362
  installVectorExtensionPromise = null;
363
363
  vectorExtensionInstalled = void 0;
364
364
  schemaSetupComplete = void 0;
365
- constructor(config) {
366
- let connectionString;
367
- let pgPoolOptions;
368
- let schemaName;
369
- if (typeof config === "string") {
370
- console.warn(
371
- `DEPRECATION WARNING: Passing connectionString as a string to PgVector constructor is deprecated.
372
-
373
- Please use an object parameter instead:
374
- new PgVector({ connectionString })
375
-
376
- The string signature will be removed on May 20th, 2025.`
377
- );
378
- connectionString = config;
379
- schemaName = void 0;
380
- pgPoolOptions = void 0;
381
- } else {
382
- connectionString = config.connectionString;
383
- schemaName = config.schemaName;
384
- pgPoolOptions = config.pgPoolOptions;
385
- }
365
+ constructor({
366
+ connectionString,
367
+ schemaName,
368
+ pgPoolOptions
369
+ }) {
386
370
  if (!connectionString || connectionString.trim() === "") {
387
371
  throw new Error(
388
372
  "PgVector: connectionString must be provided and cannot be empty. Passing an empty string may cause fallback to local Postgres defaults."
@@ -434,21 +418,22 @@ var PgVector = class extends MastraVector {
434
418
  const translator = new PGFilterTranslator();
435
419
  return translator.translate(filter);
436
420
  }
437
- async getIndexInfo(...args) {
438
- const params = this.normalizeArgs("getIndexInfo", args);
439
- const { indexName } = params;
421
+ async getIndexInfo({ indexName }) {
440
422
  if (!this.describeIndexCache.has(indexName)) {
441
423
  this.describeIndexCache.set(indexName, await this.describeIndex({ indexName }));
442
424
  }
443
425
  return this.describeIndexCache.get(indexName);
444
426
  }
445
- async query(...args) {
446
- const params = this.normalizeArgs("query", args, [
447
- "minScore",
448
- "ef",
449
- "probes"
450
- ]);
451
- const { indexName, queryVector, topK = 10, filter, includeVector = false, minScore = 0, ef, probes } = params;
427
+ async query({
428
+ indexName,
429
+ queryVector,
430
+ topK = 10,
431
+ filter,
432
+ includeVector = false,
433
+ minScore = 0,
434
+ ef,
435
+ probes
436
+ }) {
452
437
  if (!Number.isInteger(topK) || topK <= 0) {
453
438
  throw new Error("topK must be a positive integer");
454
439
  }
@@ -496,9 +481,7 @@ var PgVector = class extends MastraVector {
496
481
  client.release();
497
482
  }
498
483
  }
499
- async upsert(...args) {
500
- const params = this.normalizeArgs("upsert", args);
501
- const { indexName, vectors, metadata, ids } = params;
484
+ async upsert({ indexName, vectors, metadata, ids }) {
502
485
  const tableName = this.getTableName(indexName);
503
486
  const client = await this.pool.connect();
504
487
  try {
@@ -525,7 +508,7 @@ var PgVector = class extends MastraVector {
525
508
  if (match) {
526
509
  const [, expected, actual] = match;
527
510
  throw new Error(
528
- `Vector dimension mismatch: Index "${params.indexName}" expects ${expected} dimensions but got ${actual} dimensions. Either use a matching embedding model or delete and recreate the index with the new dimension.`
511
+ `Vector dimension mismatch: Index "${indexName}" expects ${expected} dimensions but got ${actual} dimensions. Either use a matching embedding model or delete and recreate the index with the new dimension.`
529
512
  );
530
513
  }
531
514
  }
@@ -535,8 +518,13 @@ var PgVector = class extends MastraVector {
535
518
  }
536
519
  }
537
520
  hasher = xxhash();
538
- async getIndexCacheKey(params) {
539
- const input = params.indexName + params.dimension + params.metric + (params.type || "ivfflat");
521
+ async getIndexCacheKey({
522
+ indexName,
523
+ dimension,
524
+ metric,
525
+ type
526
+ }) {
527
+ const input = indexName + dimension + metric + (type || "ivfflat");
540
528
  return (await this.hasher).h32(input);
541
529
  }
542
530
  cachedIndexExists(indexName, newKey) {
@@ -584,12 +572,13 @@ var PgVector = class extends MastraVector {
584
572
  }
585
573
  await this.setupSchemaPromise;
586
574
  }
587
- async createIndex(...args) {
588
- const params = this.normalizeArgs("createIndex", args, [
589
- "indexConfig",
590
- "buildIndex"
591
- ]);
592
- const { indexName, dimension, metric = "cosine", indexConfig = {}, buildIndex = true } = params;
575
+ async createIndex({
576
+ indexName,
577
+ dimension,
578
+ metric = "cosine",
579
+ indexConfig = {},
580
+ buildIndex = true
581
+ }) {
593
582
  const tableName = this.getTableName(indexName);
594
583
  if (!indexName.match(/^[a-zA-Z_][a-zA-Z0-9_]*$/)) {
595
584
  throw new Error("Invalid index name format");
@@ -630,20 +619,7 @@ var PgVector = class extends MastraVector {
630
619
  }
631
620
  });
632
621
  }
633
- /**
634
- * @deprecated This function is deprecated. Use buildIndex instead
635
- * This function will be removed on May 20th, 2025
636
- */
637
- async defineIndex(indexName, metric = "cosine", indexConfig) {
638
- console.warn("defineIndex is deprecated. Use buildIndex instead. This function will be removed on May 20th, 2025");
639
- return this.buildIndex({ indexName, metric, indexConfig });
640
- }
641
- async buildIndex(...args) {
642
- const params = this.normalizeArgs("buildIndex", args, [
643
- "metric",
644
- "indexConfig"
645
- ]);
646
- const { indexName, metric = "cosine", indexConfig } = params;
622
+ async buildIndex({ indexName, metric = "cosine", indexConfig }) {
647
623
  const client = await this.pool.connect();
648
624
  try {
649
625
  await this.setupIndex({ indexName, metric, indexConfig }, client);
@@ -750,13 +726,10 @@ var PgVector = class extends MastraVector {
750
726
  /**
751
727
  * Retrieves statistics about a vector index.
752
728
  *
753
- * @param params - The parameters for describing an index
754
- * @param params.indexName - The name of the index to describe
729
+ * @param {string} indexName - The name of the index to describe
755
730
  * @returns A promise that resolves to the index statistics including dimension, count and metric
756
731
  */
757
- async describeIndex(...args) {
758
- const params = this.normalizeArgs("describeIndex", args);
759
- const { indexName } = params;
732
+ async describeIndex({ indexName }) {
760
733
  const client = await this.pool.connect();
761
734
  try {
762
735
  const tableName = this.getTableName(indexName);
@@ -830,9 +803,7 @@ var PgVector = class extends MastraVector {
830
803
  client.release();
831
804
  }
832
805
  }
833
- async deleteIndex(...args) {
834
- const params = this.normalizeArgs("deleteIndex", args);
835
- const { indexName } = params;
806
+ async deleteIndex({ indexName }) {
836
807
  const client = await this.pool.connect();
837
808
  try {
838
809
  const tableName = this.getTableName(indexName);
@@ -845,9 +816,7 @@ var PgVector = class extends MastraVector {
845
816
  client.release();
846
817
  }
847
818
  }
848
- async truncateIndex(...args) {
849
- const params = this.normalizeArgs("truncateIndex", args);
850
- const { indexName } = params;
819
+ async truncateIndex({ indexName }) {
851
820
  const client = await this.pool.connect();
852
821
  try {
853
822
  const tableName = this.getTableName(indexName);
@@ -862,26 +831,6 @@ var PgVector = class extends MastraVector {
862
831
  async disconnect() {
863
832
  await this.pool.end();
864
833
  }
865
- /**
866
- * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
867
- *
868
- * Updates a vector by its ID with the provided vector and/or metadata.
869
- * @param indexName - The name of the index containing the vector.
870
- * @param id - The ID of the vector to update.
871
- * @param update - An object containing the vector and/or metadata to update.
872
- * @param update.vector - An optional array of numbers representing the new vector.
873
- * @param update.metadata - An optional record containing the new metadata.
874
- * @returns A promise that resolves when the update is complete.
875
- * @throws Will throw an error if no updates are provided or if the update operation fails.
876
- */
877
- async updateIndexById(indexName, id, update) {
878
- this.logger.warn(
879
- `Deprecation Warning: updateIndexById() is deprecated.
880
- Please use updateVector() instead.
881
- updateIndexById() will be removed on May 20th, 2025.`
882
- );
883
- await this.updateVector({ indexName, id, update });
884
- }
885
834
  /**
886
835
  * Updates a vector by its ID with the provided vector and/or metadata.
887
836
  * @param indexName - The name of the index containing the vector.
@@ -892,9 +841,7 @@ var PgVector = class extends MastraVector {
892
841
  * @returns A promise that resolves when the update is complete.
893
842
  * @throws Will throw an error if no updates are provided or if the update operation fails.
894
843
  */
895
- async updateVector(...args) {
896
- const params = this.normalizeArgs("updateVector", args);
897
- const { indexName, id, update } = params;
844
+ async updateVector({ indexName, id, update }) {
898
845
  if (!update.vector && !update.metadata) {
899
846
  throw new Error("No updates provided");
900
847
  }
@@ -929,32 +876,13 @@ var PgVector = class extends MastraVector {
929
876
  }
930
877
  }
931
878
  /**
932
- * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
933
- *
934
879
  * Deletes a vector by its ID.
935
880
  * @param indexName - The name of the index containing the vector.
936
881
  * @param id - The ID of the vector to delete.
937
882
  * @returns A promise that resolves when the deletion is complete.
938
883
  * @throws Will throw an error if the deletion operation fails.
939
884
  */
940
- async deleteIndexById(indexName, id) {
941
- this.logger.warn(
942
- `Deprecation Warning: deleteIndexById() is deprecated.
943
- Please use deleteVector() instead.
944
- deleteIndexById() will be removed on May 20th, 2025.`
945
- );
946
- await this.deleteVector({ indexName, id });
947
- }
948
- /**
949
- * Deletes a vector by its ID.
950
- * @param indexName - The name of the index containing the vector.
951
- * @param id - The ID of the vector to delete.
952
- * @returns A promise that resolves when the deletion is complete.
953
- * @throws Will throw an error if the deletion operation fails.
954
- */
955
- async deleteVector(...args) {
956
- const params = this.normalizeArgs("deleteVector", args);
957
- const { indexName, id } = params;
885
+ async deleteVector({ indexName, id }) {
958
886
  const client = await this.pool.connect();
959
887
  try {
960
888
  const tableName = this.getTableName(indexName);
@@ -995,12 +923,7 @@ var PostgresStore = class extends MastraStorage {
995
923
  }
996
924
  super({ name: "PostgresStore" });
997
925
  this.pgp = pgPromise();
998
- if ("schema" in config && config.schema) {
999
- console.warn(
1000
- '[DEPRECATION NOTICE] The "schema" option in PostgresStore is deprecated. Please use "schemaName" instead. Support for "schema" will be removed on May 20th, 2025.'
1001
- );
1002
- }
1003
- this.schema = config.schemaName ?? config.schema;
926
+ this.schema = config.schemaName;
1004
927
  this.db = this.pgp(
1005
928
  `connectionString` in config ? { connectionString: config.connectionString } : {
1006
929
  host: config.host,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/pg",
3
- "version": "0.3.5-alpha.0",
3
+ "version": "0.10.0",
4
4
  "description": "Postgres provider for Mastra - includes both vector and db storage capabilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -23,8 +23,7 @@
23
23
  "async-mutex": "^0.5.0",
24
24
  "pg": "^8.13.3",
25
25
  "pg-promise": "^11.11.0",
26
- "xxhash-wasm": "^1.1.0",
27
- "@mastra/core": "^0.9.5-alpha.0"
26
+ "xxhash-wasm": "^1.1.0"
28
27
  },
29
28
  "devDependencies": {
30
29
  "@microsoft/api-extractor": "^7.52.5",
@@ -34,7 +33,11 @@
34
33
  "tsup": "^8.4.0",
35
34
  "typescript": "^5.8.2",
36
35
  "vitest": "^3.1.2",
37
- "@internal/lint": "0.0.5"
36
+ "@internal/lint": "0.0.6",
37
+ "@mastra/core": "0.10.0"
38
+ },
39
+ "peerDependencies": {
40
+ "@mastra/core": "^0.10.0"
38
41
  },
39
42
  "scripts": {
40
43
  "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
@@ -41,10 +41,7 @@ const createSampleMessage = (threadId: string): MessageType => ({
41
41
  createdAt: new Date(),
42
42
  });
43
43
 
44
- const createSampleWorkflowSnapshot = (
45
- status: WorkflowRunState['context']['steps'][string]['status'],
46
- createdAt?: Date,
47
- ) => {
44
+ const createSampleWorkflowSnapshot = (status: WorkflowRunState['context'][string]['status'], createdAt?: Date) => {
48
45
  const runId = `run-${randomUUID()}`;
49
46
  const stepId = `step-${randomUUID()}`;
50
47
  const timestamp = createdAt || new Date();
@@ -52,21 +49,18 @@ const createSampleWorkflowSnapshot = (
52
49
  result: { success: true },
53
50
  value: {},
54
51
  context: {
55
- steps: {
56
- [stepId]: {
57
- status,
58
- payload: {},
59
- error: undefined,
60
- },
52
+ [stepId]: {
53
+ status,
54
+ payload: {},
55
+ error: undefined,
61
56
  },
62
- triggerData: {},
63
- attempts: {},
57
+ input: {},
64
58
  },
65
59
  activePaths: [],
66
60
  suspendedPaths: {},
67
61
  runId,
68
62
  timestamp: timestamp.getTime(),
69
- };
63
+ } as unknown as WorkflowRunState;
70
64
  return { snapshot, runId, stepId };
71
65
  };
72
66
 
@@ -92,7 +86,7 @@ const checkWorkflowSnapshot = (snapshot: WorkflowRunState | string, stepId: stri
92
86
  if (typeof snapshot === 'string') {
93
87
  throw new Error('Expected WorkflowRunState, got string');
94
88
  }
95
- expect(snapshot.context?.steps[stepId]?.status).toBe(status);
89
+ expect(snapshot.context?.[stepId]?.status).toBe(status);
96
90
  };
97
91
 
98
92
  describe('PostgresStore', () => {
@@ -356,17 +350,15 @@ describe('PostgresStore', () => {
356
350
  const snapshot = {
357
351
  status: 'running',
358
352
  context: {
359
- steps: {},
360
- stepResults: {},
361
- attempts: {},
362
- triggerData: { type: 'manual' },
353
+ input: { type: 'manual' },
354
+ step1: { status: 'success', output: { data: 'test' } },
363
355
  },
364
356
  value: {},
365
357
  activePaths: [],
366
358
  suspendedPaths: {},
367
359
  runId,
368
360
  timestamp: new Date().getTime(),
369
- };
361
+ } as unknown as WorkflowRunState;
370
362
 
371
363
  await store.persistWorkflowSnapshot({
372
364
  workflowName,
@@ -397,10 +389,7 @@ describe('PostgresStore', () => {
397
389
  const initialSnapshot = {
398
390
  status: 'running',
399
391
  context: {
400
- steps: {},
401
- stepResults: {},
402
- attempts: {},
403
- triggerData: { type: 'manual' },
392
+ input: { type: 'manual' },
404
393
  },
405
394
  value: {},
406
395
  activePaths: [],
@@ -412,18 +401,14 @@ describe('PostgresStore', () => {
412
401
  await store.persistWorkflowSnapshot({
413
402
  workflowName,
414
403
  runId,
415
- snapshot: initialSnapshot,
404
+ snapshot: initialSnapshot as unknown as WorkflowRunState,
416
405
  });
417
406
 
418
407
  const updatedSnapshot = {
419
- status: 'completed',
408
+ status: 'success',
420
409
  context: {
421
- steps: {},
422
- stepResults: {
423
- 'step-1': { status: 'success', result: { data: 'test' } },
424
- },
425
- attempts: { 'step-1': 1 },
426
- triggerData: { type: 'manual' },
410
+ input: { type: 'manual' },
411
+ 'step-1': { status: 'success', result: { data: 'test' } },
427
412
  },
428
413
  value: {},
429
414
  activePaths: [],
@@ -435,7 +420,7 @@ describe('PostgresStore', () => {
435
420
  await store.persistWorkflowSnapshot({
436
421
  workflowName,
437
422
  runId,
438
- snapshot: updatedSnapshot,
423
+ snapshot: updatedSnapshot as unknown as WorkflowRunState,
439
424
  });
440
425
 
441
426
  const loadedSnapshot = await store.loadWorkflowSnapshot({
@@ -452,25 +437,21 @@ describe('PostgresStore', () => {
452
437
  const complexSnapshot = {
453
438
  value: { currentState: 'running' },
454
439
  context: {
455
- stepResults: {
456
- 'step-1': {
457
- status: 'success',
458
- result: {
459
- nestedData: {
460
- array: [1, 2, 3],
461
- object: { key: 'value' },
462
- date: new Date().toISOString(),
463
- },
440
+ 'step-1': {
441
+ status: 'success',
442
+ output: {
443
+ nestedData: {
444
+ array: [1, 2, 3],
445
+ object: { key: 'value' },
446
+ date: new Date().toISOString(),
464
447
  },
465
448
  },
466
- 'step-2': {
467
- status: 'waiting',
468
- dependencies: ['step-3', 'step-4'],
469
- },
470
449
  },
471
- steps: {},
472
- attempts: { 'step-1': 1, 'step-2': 0 },
473
- triggerData: {
450
+ 'step-2': {
451
+ status: 'waiting',
452
+ dependencies: ['step-3', 'step-4'],
453
+ },
454
+ input: {
474
455
  type: 'scheduled',
475
456
  metadata: {
476
457
  schedule: '0 0 * * *',
@@ -498,7 +479,7 @@ describe('PostgresStore', () => {
498
479
  await store.persistWorkflowSnapshot({
499
480
  workflowName,
500
481
  runId,
501
- snapshot: complexSnapshot,
482
+ snapshot: complexSnapshot as unknown as WorkflowRunState,
502
483
  });
503
484
 
504
485
  const loadedSnapshot = await store.loadWorkflowSnapshot({
@@ -704,7 +685,7 @@ describe('PostgresStore', () => {
704
685
  // Insert multiple workflow runs for the same resourceId
705
686
  resourceId = 'resource-shared';
706
687
  for (const status of ['success', 'failed']) {
707
- const sample = createSampleWorkflowSnapshot(status as WorkflowRunState['context']['steps'][string]['status']);
688
+ const sample = createSampleWorkflowSnapshot(status as WorkflowRunState['context'][string]['status']);
708
689
  runIds.push(sample.runId);
709
690
  await store.insert({
710
691
  tableName: TABLE_WORKFLOW_SNAPSHOT,
@@ -719,7 +700,7 @@ describe('PostgresStore', () => {
719
700
  });
720
701
  }
721
702
  // Insert a run with a different resourceId
722
- const other = createSampleWorkflowSnapshot('waiting');
703
+ const other = createSampleWorkflowSnapshot('suspended');
723
704
  await store.insert({
724
705
  tableName: TABLE_WORKFLOW_SNAPSHOT,
725
706
  record: {
@@ -23,10 +23,6 @@ import type { ISSLConfig } from 'pg-promise/typescript/pg-subset';
23
23
 
24
24
  export type PostgresConfig = {
25
25
  schemaName?: string;
26
- /**
27
- * @deprecated Use `schemaName` instead. Support for `schema` will be removed on May 20th, 2025.
28
- */
29
- schema?: string;
30
26
  } & (
31
27
  | {
32
28
  host: string;
@@ -72,13 +68,7 @@ export class PostgresStore extends MastraStorage {
72
68
  }
73
69
  super({ name: 'PostgresStore' });
74
70
  this.pgp = pgPromise();
75
- // Deprecation notice for schema (old option)
76
- if ('schema' in config && config.schema) {
77
- console.warn(
78
- '[DEPRECATION NOTICE] The "schema" option in PostgresStore is deprecated. Please use "schemaName" instead. Support for "schema" will be removed on May 20th, 2025.',
79
- );
80
- }
81
- this.schema = config.schemaName ?? config.schema;
71
+ this.schema = config.schemaName;
82
72
  this.db = this.pgp(
83
73
  `connectionString` in config
84
74
  ? { connectionString: config.connectionString }
@@ -23,18 +23,12 @@ describe('PgVector', () => {
23
23
 
24
24
  // --- Validation tests ---
25
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)', () => {
26
+ it('throws if connectionString is empty', () => {
30
27
  expect(() => new PgVector({ connectionString: '' })).toThrow(
31
28
  /connectionString must be provided and cannot be empty/,
32
29
  );
33
30
  });
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)', () => {
31
+ it('does not throw on non-empty connection string', () => {
38
32
  expect(() => new PgVector({ connectionString })).not.toThrow();
39
33
  });
40
34
  });
@@ -152,7 +146,7 @@ describe('PgVector', () => {
152
146
  });
153
147
 
154
148
  it('should throw error for non-existent index', async () => {
155
- await expect(vectorDB.describeIndex('non_existent')).rejects.toThrow();
149
+ await expect(vectorDB.describeIndex({ indexName: 'non_existent' })).rejects.toThrow();
156
150
  });
157
151
  });
158
152
 
@@ -1839,124 +1833,6 @@ describe('PgVector', () => {
1839
1833
  });
1840
1834
  });
1841
1835
  });
1842
- describe('Deprecation Warnings', () => {
1843
- const indexName = 'testdeprecationwarnings';
1844
-
1845
- const indexName2 = 'testdeprecationwarnings2';
1846
-
1847
- let warnSpy;
1848
-
1849
- beforeAll(async () => {
1850
- await vectorDB.createIndex({ indexName, dimension: 3 });
1851
- });
1852
-
1853
- afterAll(async () => {
1854
- await vectorDB.deleteIndex({ indexName });
1855
- await vectorDB.deleteIndex({ indexName: indexName2 });
1856
- });
1857
-
1858
- beforeEach(async () => {
1859
- warnSpy = vi.spyOn(vectorDB['logger'], 'warn');
1860
- });
1861
-
1862
- afterEach(async () => {
1863
- warnSpy.mockRestore();
1864
- await vectorDB.deleteIndex({ indexName: indexName2 });
1865
- });
1866
-
1867
- it('should show deprecation warning when using individual args for createIndex', async () => {
1868
- await vectorDB.createIndex(indexName2, 3, 'cosine');
1869
-
1870
- expect(warnSpy).toHaveBeenCalledWith(
1871
- expect.stringContaining('Deprecation Warning: Passing individual arguments to createIndex() is deprecated'),
1872
- );
1873
- });
1874
-
1875
- it('should show deprecation warning when using individual args for upsert', async () => {
1876
- await vectorDB.upsert(indexName, [[1, 2, 3]], [{ test: 'data' }]);
1877
-
1878
- expect(warnSpy).toHaveBeenCalledWith(
1879
- expect.stringContaining('Deprecation Warning: Passing individual arguments to upsert() is deprecated'),
1880
- );
1881
- });
1882
-
1883
- it('should show deprecation warning when using individual args for query', async () => {
1884
- await vectorDB.query(indexName, [1, 2, 3], 5);
1885
-
1886
- expect(warnSpy).toHaveBeenCalledWith(
1887
- expect.stringContaining('Deprecation Warning: Passing individual arguments to query() is deprecated'),
1888
- );
1889
- });
1890
-
1891
- it('should show deprecation warning when using individual args for buildIndex', async () => {
1892
- await vectorDB.buildIndex(indexName, 'cosine', { type: 'flat' });
1893
-
1894
- expect(warnSpy).toHaveBeenCalledWith(
1895
- expect.stringContaining('Deprecation Warning: Passing individual arguments to buildIndex() is deprecated'),
1896
- );
1897
- });
1898
-
1899
- it('should not show deprecation warning when using object param for buildIndex', async () => {
1900
- await vectorDB.buildIndex({
1901
- indexName: indexName,
1902
- metric: 'cosine',
1903
- indexConfig: { type: 'flat' },
1904
- });
1905
-
1906
- expect(warnSpy).not.toHaveBeenCalled();
1907
- });
1908
-
1909
- it('should not show deprecation warning when using object param for query', async () => {
1910
- await vectorDB.query({
1911
- indexName,
1912
- queryVector: [1, 2, 3],
1913
- topK: 5,
1914
- });
1915
-
1916
- expect(warnSpy).not.toHaveBeenCalled();
1917
- });
1918
-
1919
- it('should not show deprecation warning when using object param for createIndex', async () => {
1920
- await vectorDB.createIndex({
1921
- indexName: indexName2,
1922
- dimension: 3,
1923
- metric: 'cosine',
1924
- });
1925
-
1926
- expect(warnSpy).not.toHaveBeenCalled();
1927
- });
1928
-
1929
- it('should not show deprecation warning when using object param for upsert', async () => {
1930
- await vectorDB.upsert({
1931
- indexName,
1932
- vectors: [[1, 2, 3]],
1933
- metadata: [{ test: 'data' }],
1934
- });
1935
-
1936
- expect(warnSpy).not.toHaveBeenCalled();
1937
- });
1938
-
1939
- it('should maintain backward compatibility with individual args', async () => {
1940
- // Query
1941
- const queryResults = await vectorDB.query(indexName, [1, 2, 3], 5);
1942
- expect(Array.isArray(queryResults)).toBe(true);
1943
-
1944
- // CreateIndex
1945
- await expect(vectorDB.createIndex(indexName2, 3, 'cosine')).resolves.not.toThrow();
1946
-
1947
- // Upsert
1948
- const upsertResults = await vectorDB.upsert({
1949
- indexName,
1950
- vectors: [[1, 2, 3]],
1951
- metadata: [{ test: 'data' }],
1952
- });
1953
- expect(Array.isArray(upsertResults)).toBe(true);
1954
- expect(upsertResults).toHaveLength(1);
1955
-
1956
- // BuildIndex
1957
- await expect(vectorDB.buildIndex(indexName, 'cosine', { type: 'flat' })).resolves.not.toThrow();
1958
- });
1959
- });
1960
1836
 
1961
1837
  describe('Concurrent Operations', () => {
1962
1838
  it('should handle concurrent index creation attempts', async () => {
@@ -2055,11 +1931,6 @@ describe('PgVector', () => {
2055
1931
  });
2056
1932
 
2057
1933
  describe('Constructor', () => {
2058
- it('should accept connectionString directly', () => {
2059
- const db = new PgVector(connectionString);
2060
- expect(db).toBeInstanceOf(PgVector);
2061
- });
2062
-
2063
1934
  it('should accept config object with connectionString', () => {
2064
1935
  const db = new PgVector({ connectionString });
2065
1936
  expect(db).toBeInstanceOf(PgVector);