-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathNodeRemote.ts
More file actions
47 lines (41 loc) · 1.07 KB
/
NodeRemote.ts
File metadata and controls
47 lines (41 loc) · 1.07 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
import * as os from 'node:os';
import {
type ILogger,
AbstractRemote,
AbstractRemoteOptions,
BSONImplementation,
DEFAULT_REMOTE_LOGGER,
FetchImplementation,
FetchImplementationProvider,
RemoteConnector
} from '@powersync/common';
import { BSON } from 'bson';
export const STREAMING_POST_TIMEOUT_MS = 30_000;
class NodeFetchProvider extends FetchImplementationProvider {
getFetch(): FetchImplementation {
return fetch.bind(globalThis);
}
}
export class NodeRemote extends AbstractRemote {
constructor(
protected connector: RemoteConnector,
protected logger: ILogger = DEFAULT_REMOTE_LOGGER,
options?: Partial<AbstractRemoteOptions>
) {
super(connector, logger, {
...(options ?? {}),
fetchImplementation: options?.fetchImplementation ?? new NodeFetchProvider()
});
}
getUserAgent(): string {
return [
super.getUserAgent(),
`powersync-node`,
`node/${process.versions.node}`,
`${os.platform()}/${os.release()}`
].join(' ');
}
async getBSON(): Promise<BSONImplementation> {
return BSON;
}
}