-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathruntime_adapters.ts
More file actions
49 lines (42 loc) · 1.51 KB
/
runtime_adapters.ts
File metadata and controls
49 lines (42 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* eslint-disable no-restricted-imports, @typescript-eslint/no-require-imports */
// We squash the restricted import errors here because we are using type-only imports, which
// do not impact the driver's actual runtime dependencies.
// We also allow restricted imports in this file, because we expect this file to be the only place actually importing restricted Node APIs.
import type * as os from 'os';
import { type MongoClientOptions } from './mongo_client';
/**
* @public
* @experimental
*
* Represents the set of dependencies that the driver uses from the [Node.js OS module](https://nodejs.org/api/os.html).
*/
export type OsAdapter = Pick<typeof os, 'release' | 'platform' | 'arch' | 'type'>;
/**
* @public
* @experimental
*
* This type represents the set of dependencies that the driver needs from the Javascript runtime in order to function.
*/
export interface RuntimeAdapters {
os?: OsAdapter;
}
/**
* @internal
*
* Represents a complete, parsed set of runtime adapters. After options parsing, all adapters
* are always present (either using the user's provided adapter, or defaulting to the Node.js module).
*/
export interface Runtime {
os: OsAdapter;
}
/**
* @internal
*
* Given a MongoClientOptions, this function resolves the set of runtime options, providing Nodejs implementations if
* not provided by in `options`, and returns a `Runtime`.
*/
export function resolveRuntimeAdapters(options: MongoClientOptions): Runtime {
return {
os: options.runtimeAdapters?.os ?? require('os')
};
}