Skip to content

Commit

Permalink
RacerBackend type-only export and serverRequire backend in createBackend
Browse files Browse the repository at this point in the history
  • Loading branch information
craigbeck committed May 1, 2024
1 parent 4a2d06f commit d106e83
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/Backend.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Model } from './Model';
import * as path from 'path';
import * as util from './util';
import { ModelOptions, RootModel } from './Model/Model';
Expand Down
8 changes: 6 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Racer } from './Racer';
import * as util from './util';
import type { ShareDBOptions } from 'sharedb';

import { RacerBackend } from './Backend';
import { type RacerBackend } from './Backend';
import { RootModel, type ModelOptions } from './Model';

export { Query } from './Model/Query';
Expand Down Expand Up @@ -37,5 +37,9 @@ export function createModel(data?) {
}

export function createBackend(options?: BackendOptions) {
return new RacerBackend(racer, options);
const backendModule = util.serverRequire(module, './Backend');
if (backendModule == null) {
throw new Error('racer.createBackend can only be called in server node process');
}
return new backendModule.RacerBackend(racer, options);
}

0 comments on commit d106e83

Please sign in to comment.