Skip to content

Commit 8dadd66

Browse files
committed
Switched to ESM and dropped support for Node < 22
1 parent 5acbc49 commit 8dadd66

46 files changed

Lines changed: 206 additions & 227 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 0.3.0 (unreleased)
2+
3+
- Switched to ESM
4+
- Dropped support for Node < 22
5+
16
## 0.2.1 (2025-05-20)
27

38
- Improved support for migrations with Sequelize

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"type": "git",
1212
"url": "https://github.com/pgvector/pgvector-node"
1313
},
14+
"type": "module",
1415
"exports": {
1516
".": {
1617
"types": "./types/index.d.ts",
@@ -86,7 +87,7 @@
8687
"types"
8788
],
8889
"engines": {
89-
"node": ">=18"
90+
"node": ">=22"
9091
},
9192
"scripts": {
9293
"build": "tsc",

src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
const { fromSql, toSql, SparseVector } = require('./utils');
1+
import { fromSql, toSql, SparseVector } from './utils/index.js';
22

3-
module.exports = {fromSql, toSql, SparseVector};
3+
export { fromSql, toSql, SparseVector };
4+
5+
export default { fromSql, toSql };

src/knex/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const knex = require('knex');
2-
const { fromSql, toSql, vectorType, halfvecType, sparsevecType } = require('../utils');
1+
import knex from 'knex';
2+
import { fromSql, toSql, vectorType, halfvecType, sparsevecType } from '../utils/index.js';
33

44
knex.SchemaBuilder.extend('enableExtension', function (name) {
55
return this.raw('CREATE EXTENSION IF NOT EXISTS ??', [name]);
@@ -44,4 +44,6 @@ knex.QueryBuilder.extend('jaccardDistance', function (column, value) {
4444
return this.client.raw('?? <%> ?', [column, value]);
4545
});
4646

47-
module.exports = {fromSql, toSql};
47+
export { fromSql, toSql };
48+
49+
export default { fromSql, toSql };

src/kysely/index.js

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,30 @@
1-
const { sql } = require('kysely');
2-
const { fromSql, toSql } = require('..');
1+
import { sql } from 'kysely';
2+
import { fromSql, toSql } from '../utils/index.js';
33

4-
function l2Distance(column, value) {
4+
export function l2Distance(column, value) {
55
return sql`${sql.ref(column)} <-> ${toSql(value)}`;
66
}
77

8-
function maxInnerProduct(column, value) {
8+
export function maxInnerProduct(column, value) {
99
return sql`${sql.ref(column)} <#> ${toSql(value)}`;
1010
}
1111

12-
function cosineDistance(column, value) {
12+
export function cosineDistance(column, value) {
1313
return sql`${sql.ref(column)} <=> ${toSql(value)}`;
1414
}
1515

16-
function l1Distance(column, value) {
16+
export function l1Distance(column, value) {
1717
return sql`${sql.ref(column)} <+> ${toSql(value)}`;
1818
}
1919

20-
function hammingDistance(column, value) {
20+
export function hammingDistance(column, value) {
2121
return sql`${sql.ref(column)} <~> ${value}`;
2222
}
2323

24-
function jaccardDistance(column, value) {
24+
export function jaccardDistance(column, value) {
2525
return sql`${sql.ref(column)} <%> ${value}`;
2626
}
2727

28-
module.exports = {
29-
fromSql,
30-
toSql,
31-
l2Distance,
32-
maxInnerProduct,
33-
cosineDistance,
34-
l1Distance,
35-
hammingDistance,
36-
jaccardDistance
37-
};
28+
export { fromSql, toSql };
29+
30+
export default { fromSql, toSql };

src/mikro-orm/bit.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
const { Type } = require('@mikro-orm/core');
2-
const utils = require('../utils');
1+
import { Type } from '@mikro-orm/core';
2+
import { bitType } from '../utils/index.js';
33

4-
class BitType extends Type {
4+
export class BitType extends Type {
55
getColumnType(prop, platform) {
6-
return utils.bitType(prop.length);
6+
return bitType(prop.length);
77
}
88
}
9-
10-
module.exports = {BitType};

src/mikro-orm/halfvec.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
const { Type } = require('@mikro-orm/core');
2-
const utils = require('../utils');
1+
import { Type } from '@mikro-orm/core';
2+
import { halfvecFromSql, halfvecToSql, halfvecType } from '../utils/index.js';
33

4-
class HalfvecType extends Type {
4+
export class HalfvecType extends Type {
55
convertToDatabaseValue(value, platform) {
66
if (value === null) {
77
return null;
88
}
9-
return utils.halfvecToSql(value);
9+
return halfvecToSql(value);
1010
}
1111

1212
convertToJSValue(value, platform) {
1313
if (value === null) {
1414
return null;
1515
}
16-
return utils.halfvecFromSql(value);
16+
return halfvecFromSql(value);
1717
}
1818

1919
getColumnType(prop, platform) {
20-
return utils.halfvecType(prop.dimensions);
20+
return halfvecType(prop.dimensions);
2121
}
2222
}
23-
24-
module.exports = {HalfvecType};

src/mikro-orm/index.js

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
const { raw } = require('@mikro-orm/core');
2-
const { BitType } = require('./bit');
3-
const { HalfvecType } = require('./halfvec');
4-
const { SparsevecType } = require('./sparsevec');
5-
const { VectorType } = require('./vector');
6-
const { toSql } = require('../utils');
1+
import { raw } from '@mikro-orm/core';
2+
import { toSql } from '../utils/index.js';
3+
4+
export { BitType } from './bit.js';
5+
export { HalfvecType } from './halfvec.js';
6+
export { SparsevecType } from './sparsevec.js';
7+
export { VectorType } from './vector.js';
78

89
function distance(op, column, value, em, binary) {
910
if (raw) {
@@ -13,39 +14,26 @@ function distance(op, column, value, em, binary) {
1314
}
1415
}
1516

16-
function l2Distance(column, value, em) {
17+
export function l2Distance(column, value, em) {
1718
return distance('<->', column, value, em);
1819
}
1920

20-
function maxInnerProduct(column, value, em) {
21+
export function maxInnerProduct(column, value, em) {
2122
return distance('<#>', column, value, em);
2223
}
2324

24-
function cosineDistance(column, value, em) {
25+
export function cosineDistance(column, value, em) {
2526
return distance('<=>', column, value, em);
2627
}
2728

28-
function l1Distance(column, value, em) {
29+
export function l1Distance(column, value, em) {
2930
return distance('<+>', column, value, em);
3031
}
3132

32-
function hammingDistance(column, value, em) {
33+
export function hammingDistance(column, value, em) {
3334
return distance('<~>', column, value, em, true);
3435
}
3536

36-
function jaccardDistance(column, value, em) {
37+
export function jaccardDistance(column, value, em) {
3738
return distance('<%>', column, value, em, true);
3839
}
39-
40-
module.exports = {
41-
VectorType,
42-
HalfvecType,
43-
BitType,
44-
SparsevecType,
45-
l2Distance,
46-
maxInnerProduct,
47-
cosineDistance,
48-
l1Distance,
49-
hammingDistance,
50-
jaccardDistance
51-
};

src/mikro-orm/sparsevec.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
const { Type } = require('@mikro-orm/core');
2-
const utils = require('../utils');
1+
import { Type } from '@mikro-orm/core';
2+
import { sparsevecFromSql, sparsevecToSql, sparsevecType } from '../utils/index.js';
33

4-
class SparsevecType extends Type {
4+
export class SparsevecType extends Type {
55
convertToDatabaseValue(value, platform) {
66
if (value === null) {
77
return null;
88
}
9-
return utils.sparsevecToSql(value);
9+
return sparsevecToSql(value);
1010
}
1111

1212
convertToJSValue(value, platform) {
1313
if (value === null) {
1414
return null;
1515
}
16-
return utils.sparsevecFromSql(value);
16+
return sparsevecFromSql(value);
1717
}
1818

1919
getColumnType(prop, platform) {
20-
return utils.sparsevecType(prop.dimensions);
20+
return sparsevecType(prop.dimensions);
2121
}
2222
}
23-
24-
module.exports = {SparsevecType};

src/mikro-orm/vector.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
const { Type } = require('@mikro-orm/core');
2-
const utils = require('../utils');
1+
import { Type } from '@mikro-orm/core';
2+
import { vectorFromSql, vectorToSql, vectorType } from '../utils/index.js';
33

4-
class VectorType extends Type {
4+
export class VectorType extends Type {
55
convertToDatabaseValue(value, platform) {
66
if (value === null) {
77
return null;
88
}
9-
return utils.vectorToSql(value);
9+
return vectorToSql(value);
1010
}
1111

1212
convertToJSValue(value, platform) {
1313
if (value === null) {
1414
return null;
1515
}
16-
return utils.vectorFromSql(value);
16+
return vectorFromSql(value);
1717
}
1818

1919
getColumnType(prop, platform) {
20-
return utils.vectorType(prop.dimensions);
20+
return vectorType(prop.dimensions);
2121
}
2222
}
23-
24-
module.exports = {VectorType};

0 commit comments

Comments
 (0)