Skip to content

Commit e334994

Browse files
WIP
1 parent baabc68 commit e334994

277 files changed

Lines changed: 1287 additions & 735 deletions

File tree

Some content is hidden

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

.eslintrc.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@
186186
{
187187
"patterns": [
188188
"**/../lib/**",
189+
"**/../src/**",
189190
"mongodb-mock-server"
190191
]
191192
}
@@ -331,6 +332,15 @@
331332
"disallowTypeAnnotations": false,
332333
"fixStyle": "separate-type-imports"
333334
}
335+
],
336+
"no-restricted-imports": [
337+
"error",
338+
{
339+
"patterns": [
340+
"**/../lib/**",
341+
"**/../src/**"
342+
]
343+
}
334344
]
335345
}
336346
}

generate.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
2+
3+
import * as fs from 'fs';
4+
import * as path from 'path';
5+
6+
const SRC_DIR = path.join(__dirname, 'src');
7+
const OUTPUT_FILE = path.join(__dirname, 'test', 'mongodb.ts');
8+
9+
/**
10+
* Recursively get all TypeScript files in a directory
11+
*/
12+
function getTsFiles(dir: string, fileList: string[] = []): string[] {
13+
const files = fs.readdirSync(dir);
14+
15+
for (const file of files) {
16+
const filePath = path.join(dir, file);
17+
const stat = fs.statSync(filePath);
18+
19+
if (stat.isDirectory()) {
20+
getTsFiles(filePath, fileList);
21+
} else if (file.endsWith('.ts') && !file.endsWith('.d.ts')) {
22+
fileList.push(filePath);
23+
}
24+
}
25+
26+
return fileList;
27+
}
28+
29+
/**
30+
* Convert absolute path to relative import path
31+
*/
32+
function toImportPath(filePath: string): string {
33+
// Get relative path from output file to source file
34+
const relativePath = path.relative(path.dirname(OUTPUT_FILE), filePath);
35+
// Remove .ts extension and normalize path separators
36+
const importPath = relativePath.replace(/\.ts$/, '').replace(/\\/g, '/');
37+
// Ensure it starts with ./
38+
return importPath.startsWith('.') ? importPath : `../src/${importPath}`;
39+
}
40+
41+
/**
42+
* Generate the mongodb.ts file with all exports
43+
*/
44+
function generateExportFile(): void {
45+
const tsFiles = getTsFiles(SRC_DIR);
46+
47+
// Sort files for consistent output
48+
tsFiles.sort();
49+
50+
const exports: string[] = [
51+
'/**',
52+
' * Auto-generated file that exports everything from src/',
53+
' * Generated on: ' + new Date().toISOString(),
54+
' */',
55+
''
56+
];
57+
58+
for (const file of tsFiles) {
59+
const importPath = toImportPath(file);
60+
exports.push(`export * from '${importPath}';`);
61+
}
62+
63+
const content = exports.join('\n') + '\n';
64+
65+
fs.writeFileSync(OUTPUT_FILE, content, 'utf-8');
66+
67+
console.log(`✓ Generated ${OUTPUT_FILE}`);
68+
console.log(`✓ Exported ${tsFiles.length} files`);
69+
}
70+
71+
// Run the generator
72+
try {
73+
generateExportFile();
74+
} catch (error) {
75+
console.error('Error generating export file:', error);
76+
process.exit(1);
77+
}

test/action/dependency.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as path from 'node:path';
55
import { expect } from 'chai';
66

77
import { dependencies, peerDependencies, peerDependenciesMeta } from '../../package.json';
8-
import { setDifference } from '../../src/utils';
8+
import { setDifference } from '../mongodb';
99
import { alphabetically, itInNodeProcess, sorted } from '../tools/utils';
1010

1111
const EXPECTED_DEPENDENCIES = sorted(
@@ -139,6 +139,7 @@ describe('package.json', function () {
139139

140140
beforeEach(async function () {
141141
for (const key of Object.keys(require.cache)) delete require.cache[key];
142+
// Intentionally import from `src` because we are testing the package's exports (index.ts)
142143
// eslint-disable-next-line @typescript-eslint/no-require-imports
143144
require('../../src');
144145
imports = Array.from(

test/benchmarks/unitBench/list.bench.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const chalk = require('chalk');
2-
const { List } = require('../../../src/utils');
2+
const { List } = require('../../mongodb');
33
const { createHistogram } = require('perf_hooks');
44
const { process } = require('process');
55

test/csfle-kms-providers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as process from 'process';
22

3-
import { type KMSProviders } from './../src';
3+
import { type KMSProviders } from './mongodb';
44

55
const csfleKMSProviders = {
66
aws: {

test/integration/auth/auth.prose.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ import { expect } from 'chai';
22
import * as process from 'process';
33
import * as sinon from 'sinon';
44

5-
import { type MongoClient } from '../../../src';
6-
import { ScramSHA256 } from '../../../src/cmap/auth/scram';
7-
import { Connection } from '../../../src/cmap/connection';
8-
import { LEGACY_HELLO_COMMAND } from '../../../src/constants';
5+
import { type MongoClient } from '../../mongodb';
6+
import { Connection, LEGACY_HELLO_COMMAND, ScramSHA256 } from '../../mongodb';
97
import { type TestConfiguration } from '../../tools/runner/config';
108

119
function makeConnectionString(config, username, password) {

test/integration/auth/mongodb_aws.prose.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect } from 'chai';
22
import * as process from 'process';
33

4-
import { type MongoClient, MongoServerError } from '../../../src';
5-
import { AWSSDKCredentialProvider } from '../../../src/cmap/auth/aws_temporary_credentials';
4+
import { type MongoClient, MongoServerError } from '../../mongodb';
5+
import { AWSSDKCredentialProvider } from '../../mongodb';
66

77
const isMongoDBAWSAuthEnvironment = (process.env.MONGODB_URI ?? '').includes('MONGODB-AWS');
88

test/integration/auth/mongodb_aws.test.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ import {
1515
MongoMissingCredentialsError,
1616
MongoMissingDependencyError,
1717
MongoServerError
18-
} from '../../../src';
19-
import { refreshKMSCredentials } from '../../../src/client-side-encryption/providers';
20-
import { AWSSDKCredentialProvider } from '../../../src/cmap/auth/aws_temporary_credentials';
21-
import { aws4Sign } from '../../../src/cmap/auth/aws4';
22-
import { MongoDBAWS } from '../../../src/cmap/auth/mongodb_aws';
23-
import { Connection } from '../../../src/cmap/connection';
24-
import { setDifference } from '../../../src/utils';
18+
} from '../../mongodb';
19+
import {
20+
aws4Sign,
21+
AWSSDKCredentialProvider,
22+
Connection,
23+
MongoDBAWS,
24+
refreshKMSCredentials,
25+
setDifference
26+
} from '../../mongodb';
2527

2628
const isMongoDBAWSAuthEnvironment = (process.env.MONGODB_URI ?? '').includes('MONGODB-AWS');
2729

test/integration/auth/mongodb_oidc.prose.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import {
1212
type MongoClientOptions,
1313
type OIDCCallbackParams,
1414
type OIDCResponse
15-
} from '../../../src';
16-
import { type MongoDBOIDC, type OIDCCallbackFunction } from '../../../src/cmap/auth/mongodb_oidc';
15+
} from '../../mongodb';
16+
import { type MongoDBOIDC, type OIDCCallbackFunction } from '../../mongodb';
1717

1818
const createCallback = (tokenFile = 'test_user1', expiresInSeconds?: number, extraFields?: any) => {
1919
return async (params: OIDCCallbackParams) => {

test/integration/bson-decimal128/decimal128.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from 'chai';
22

3-
import { type Collection, Decimal128, type MongoClient } from '../../../src';
3+
import { type Collection, Decimal128, type MongoClient } from '../../mongodb';
44

55
describe('Decimal128', function () {
66
let client: MongoClient;

0 commit comments

Comments
 (0)