UNPKG

rxdb-server

Version:
48 lines 2.24 kB
import { RxServerReplicationEndpoint } from "./endpoint-replication.js"; import { RxServerRestEndpoint } from "./endpoint-rest.js"; export var RxServer = /*#__PURE__*/function () { function RxServer(options, authHandler, serverApp, cors = '*') { this.endpoints = []; this.closeFn = (() => this.close()).bind(this); this.options = options; this.authHandler = authHandler; this.serverApp = serverApp; this.cors = cors; this.database = options.database; this.adapter = options.adapter; options.database.onClose.push(this.closeFn); } var _proto = RxServer.prototype; _proto.ensureNotStarted = function ensureNotStarted() { if (this.listenPromise) { throw new Error('This operation cannot be run after the RxServer has been started already'); } }; _proto.addReplicationEndpoint = function addReplicationEndpoint(opts) { this.ensureNotStarted(); var endpoint = new RxServerReplicationEndpoint(this, opts.name, opts.collection, opts.queryModifier ? opts.queryModifier : (_a, q) => q, opts.changeValidator ? opts.changeValidator : () => true, opts.serverOnlyFields ? opts.serverOnlyFields : [], opts.cors); this.endpoints.push(endpoint); return endpoint; }; _proto.addRestEndpoint = function addRestEndpoint(opts) { this.ensureNotStarted(); var endpoint = new RxServerRestEndpoint(this, opts.name, opts.collection, opts.queryModifier ? opts.queryModifier : (_a, q) => q, opts.changeValidator ? opts.changeValidator : () => true, opts.serverOnlyFields ? opts.serverOnlyFields : [], opts.cors); this.endpoints.push(endpoint); return endpoint; }; _proto.start = async function start() { this.ensureNotStarted(); var hostname = this.options.hostname ? this.options.hostname : 'localhost'; this.listenPromise = this.options.adapter.listen(this.serverApp, this.options.port, hostname); return this.listenPromise; }; _proto.close = async function close() { this.database.onClose = this.database.onClose.filter(fn => fn !== this.closeFn); if (this.listenPromise) { await this.listenPromise; await this.options.adapter.close(this.serverApp); } }; return RxServer; }(); //# sourceMappingURL=rx-server.js.map