rxdb-server 15.28.1 → 15.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_utils","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_rxjs","_eventsource","_interopRequireDefault","RxRestClient","endpointUrl","headers","eventSource","EventSource","_proto","setHeaders","handleError","response","error","Error","JSON","stringify","query","postRequest","observeQuery","result","Subject","queryAsBase64","btoa","withCredentials","onmessage","event","eventData","parse","data","next","asObservable","ids","set","docs","delete","_delete","createRestClient"],"sources":["../../../../src/plugins/client-rest/index.ts"],"sourcesContent":["import { ById, MangoQuery, newRxError } from 'rxdb/plugins/core';\nimport { postRequest } from './utils.ts';\nimport { Observable, Subject } from 'rxjs';\nimport EventSource from 'eventsource';\n\nexport class RxRestClient<RxDocType> {\n constructor(\n public readonly endpointUrl: string,\n public headers: ById<string> = {},\n public readonly eventSource: typeof EventSource | any = EventSource\n ) { }\n\n setHeaders(headers: ById<string>) {\n this.headers = headers;\n }\n\n handleError(response: any) {\n if (response.error) {\n throw new Error('Server returned an error ' + JSON.stringify(response));\n }\n }\n\n async query(query: MangoQuery<RxDocType>): Promise<{ documents: RxDocType[] }> {\n const response = await postRequest(\n this.endpointUrl + '/query',\n query,\n this.headers\n );\n this.handleError(response);\n return response;\n }\n\n observeQuery(query: MangoQuery<RxDocType>): Observable<RxDocType[]> {\n const result = new Subject<RxDocType[]>;\n const queryAsBase64 = btoa(JSON.stringify(query));\n const eventSource: EventSource = new this.eventSource(\n this.endpointUrl + '/query/observe?query=' + queryAsBase64,\n {\n withCredentials: true,\n /**\n * Sending headers is not supported by the Browser EventSource API,\n * only by the npm module we use. In react-native you might have\n * to set another EventSource implementation.\n * @link https://www.npmjs.com/package/eventsource\n */\n headers: this.headers\n });\n eventSource.onmessage = event => {\n const eventData = JSON.parse(event.data);\n result.next(eventData);\n };\n return result.asObservable();\n }\n\n get(ids: string[]): Promise<{ documents: RxDocType[] }> {\n const response = postRequest(\n this.endpointUrl + '/get',\n ids,\n this.headers\n );\n this.handleError(response);\n return response;\n }\n\n set(docs: RxDocType[]) {\n const response = postRequest(\n this.endpointUrl + '/set',\n docs,\n this.headers\n );\n this.handleError(response);\n return response;\n }\n\n delete(ids: string[]) {\n const response = postRequest(\n this.endpointUrl + '/delete',\n ids,\n this.headers\n );\n this.handleError(response);\n return response;\n }\n}\n\nexport function createRestClient<RxDocType>(\n endpointUrl: string,\n headers: ById<string>,\n eventSource: typeof EventSource | any = EventSource\n) {\n\n return new RxRestClient<RxDocType>(\n endpointUrl,\n headers,\n eventSource\n );\n}\n\n\nexport * from './utils.ts';\n"],"mappings":";;;;;;;;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAkGAC,MAAA,CAAAC,IAAA,CAAAH,MAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAL,MAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAb,MAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AAjGA,IAAAS,KAAA,GAAAb,OAAA;AACA,IAAAc,YAAA,GAAAC,sBAAA,CAAAf,OAAA;AAAsC,IAEzBgB,YAAY,GAAAP,OAAA,CAAAO,YAAA;EACrB,SAAAA,aACoBC,WAAmB,EAC5BC,OAAqB,GAAG,CAAC,CAAC,EACjBC,WAAqC,GAAGC,oBAAW,EACrE;IAAA,KAHkBH,WAAmB,GAAnBA,WAAmB;IAAA,KAC5BC,OAAqB,GAArBA,OAAqB;I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H,SAAS,CAAC;IAC1B,CAAC;IACD,OAAOP,MAAM,CAACW,YAAY,CAAC,CAAC;EAChC,CAAC;EAAAtB,MAAA,CAEDT,GAAG,GAAH,SAAAA,IAAIgC,GAAa,EAAuC;IACpD,IAAMpB,QAAQ,GAAG,IAAAM,kBAAW,EACxB,IAAI,CAACb,WAAW,GAAG,MAAM,EACzB2B,GAAG,EACH,IAAI,CAAC1B,OACT,CAAC;IACD,IAAI,CAACK,WAAW,CAACC,QAAQ,CAAC;IAC1B,OAAOA,QAAQ;EACnB,CAAC;EAAAH,MAAA,CAEDwB,GAAG,GAAH,SAAAA,IAAIC,IAAiB,EAAE;IACnB,IAAMtB,QAAQ,GAAG,IAAAM,kBAAW,EACxB,IAAI,CAACb,WAAW,GAAG,MAAM,EACzB6B,IAAI,EACJ,IAAI,CAAC5B,OACT,CAAC;IACD,IAAI,CAACK,WAAW,CAACC,QAAQ,CAAC;IAC1B,OAAOA,QAAQ;EACnB,CAAC;EAAAH,MAAA,CAED0B,MAAM,GAAN,SAAAC,QAAOJ,GAAa,EAAE;IAClB,IAAMpB,QAAQ,GAAG,IAAAM,kBAAW,EACxB,IAAI,CAACb,WAAW,GAAG,SAAS,EAC5B2B,GAAG,EACH,IAAI,CAAC1B,OACT,CAAC;IACD,IAAI,CAACK,WAAW,CAACC,QAAQ,CAAC;IAC1B,OAAOA,QAAQ;EACnB,CAAC;EAAA,OAAAR,YAAA;AAAA;AAGE,SAASiC,gBAAgBA,CAC5BhC,WAAmB,EACnBC,OAAqB,EACrBC,WAAqC,GAAGC,oBAAW,EACrD;EAEE,OAAO,IAAIJ,YAAY,CACnBC,WAAW,EACXC,OAAO,EACPC,WACJ,CAAC;AACL","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["_utils","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_rxjs","_eventsource","_interopRequireDefault","RxRestClient","endpointUrl","headers","eventSource","EventSource","_proto","setHeaders","handleError","response","error","Error","JSON","stringify","query","postRequest","observeQuery","result","Subject","queryAsBase64","btoa","withCredentials","onmessage","event","eventData","parse","data","next","asObservable","ids","set","docs","delete","createRestClient"],"sources":["../../../../src/plugins/client-rest/index.ts"],"sourcesContent":["import { ById, MangoQuery, newRxError } from 'rxdb/plugins/core';\nimport { postRequest } from './utils.ts';\nimport { Observable, Subject } from 'rxjs';\nimport EventSource from 'eventsource';\n\nexport class RxRestClient<RxDocType> {\n constructor(\n public readonly endpointUrl: string,\n public headers: ById<string> = {},\n public readonly eventSource: typeof EventSource | any = EventSource\n ) { }\n\n setHeaders(headers: ById<string>) {\n this.headers = headers;\n }\n\n handleError(response: any) {\n if (response.error) {\n throw new Error('Server returned an error ' + JSON.stringify(response));\n }\n }\n\n async query(query: MangoQuery<RxDocType>): Promise<{ documents: RxDocType[] }> {\n const response = await postRequest(\n this.endpointUrl + '/query',\n query,\n this.headers\n );\n this.handleError(response);\n return response;\n }\n\n observeQuery(query: MangoQuery<RxDocType>): Observable<RxDocType[]> {\n const result = new Subject<RxDocType[]>;\n const queryAsBase64 = btoa(JSON.stringify(query));\n const eventSource: EventSource = new this.eventSource(\n this.endpointUrl + '/query/observe?query=' + queryAsBase64,\n {\n withCredentials: true,\n /**\n * Sending headers is not supported by the Browser EventSource API,\n * only by the npm module we use. In react-native you might have\n * to set another EventSource implementation.\n * @link https://www.npmjs.com/package/eventsource\n */\n headers: this.headers\n });\n eventSource.onmessage = event => {\n const eventData = JSON.parse(event.data);\n result.next(eventData);\n };\n return result.asObservable();\n }\n\n get(ids: string[]): Promise<{ documents: RxDocType[] }> {\n const response = postRequest(\n this.endpointUrl + '/get',\n ids,\n this.headers\n );\n this.handleError(response);\n return response;\n }\n\n set(docs: RxDocType[]) {\n const response = postRequest(\n this.endpointUrl + '/set',\n docs,\n this.headers\n );\n this.handleError(response);\n return response;\n }\n\n delete(ids: string[]) {\n const response = postRequest(\n this.endpointUrl + '/delete',\n ids,\n this.headers\n );\n this.handleError(response);\n return response;\n }\n}\n\nexport function createRestClient<RxDocType>(\n endpointUrl: string,\n headers: ById<string>,\n eventSource: typeof EventSource | any = EventSource\n) {\n\n return new RxRestClient<RxDocType>(\n endpointUrl,\n headers,\n eventSource\n );\n}\n\n\nexport * from './utils.ts';\n"],"mappings":";;;;;;;;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAkGAC,MAAA,CAAAC,IAAA,CAAAH,MAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAL,MAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAb,MAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AAjGA,IAAAS,KAAA,GAAAb,OAAA;AACA,IAAAc,YAAA,GAAAC,sBAAA,CAAAf,OAAA;AAAsC,IAEzBgB,YAAY,GAAAP,OAAA,CAAAO,YAAA;EACrB,SAAAA,aACoBC,WAAmB,EAC5BC,OAAqB,GAAG,CAAC,CAAC,EACjBC,WAAqC,GAAGC,oBAAW,EACrE;IAAA,KAHkBH,WAAmB,GAAnBA,WAAmB;IAAA,KAC5BC,OAAqB,GAArBA,OAAqB;IAAA,KACZC,WAAqC,GAArCA,WAAqC;EACrD;EAAC,IAAAE,MAAA,GAAAL,YAAA,CAAAX,SAAA;EAAAgB,MAAA,CAELC,UAAU,GAAV,SAAAA,UAAUA,CAACJ,OAAqB,EAAE;IAC9B,IAAI,CAACA,OAAO,GAAGA,OAAO;EAC1B,CAAC;EAAAG,MAAA,CAEDE,WAAW,GAAX,SAAAA,WAAWA,CAACC,QAAa,EAAE;IACvB,IAAIA,QAAQ,CAACC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AC;IACD,IAAI,CAACK,WAAW,CAACC,QAAQ,CAAC;IAC1B,OAAOA,QAAQ;EACnB,CAAC;EAAAH,MAAA,CAEDwB,GAAG,GAAH,SAAAA,GAAGA,CAACC,IAAiB,EAAE;IACnB,IAAMtB,QAAQ,GAAG,IAAAM,kBAAW,EACxB,IAAI,CAACb,WAAW,GAAG,MAAM,EACzB6B,IAAI,EACJ,IAAI,CAAC5B,OACT,CAAC;IACD,IAAI,CAACK,WAAW,CAACC,QAAQ,CAAC;IAC1B,OAAOA,QAAQ;EACnB,CAAC;EAAAH,MAAA,CAED0B,MAAM,GAAN,SAAAA,OAAMA,CAACH,GAAa,EAAE;IAClB,IAAMpB,QAAQ,GAAG,IAAAM,kBAAW,EACxB,IAAI,CAACb,WAAW,GAAG,SAAS,EAC5B2B,GAAG,EACH,IAAI,CAAC1B,OACT,CAAC;IACD,IAAI,CAACK,WAAW,CAACC,QAAQ,CAAC;IAC1B,OAAOA,QAAQ;EACnB,CAAC;EAAA,OAAAR,YAAA;AAAA;AAGE,SAASgC,gBAAgBA,CAC5B/B,WAAmB,EACnBC,OAAqB,EACrBC,WAAqC,GAAGC,oBAAW,EACrD;EAEE,OAAO,IAAIJ,YAAY,CACnBC,WAAW,EACXC,OAAO,EACPC,WACJ,CAAC;AACL","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_core","require","_leaderElection","_replication","_rxjs","_helpers","_eventsource","_interopRequireDefault","_types","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","RxServerReplicationState","_RxReplicationState","replicationIdentifier","collection","pull","push","live","retryTime","autoStart","headers","_this","outdatedClient$","Subject","unauthorized$","forbidden$","onCancel","complete","_inheritsLoose2","default","_proto","setHeaders","flatClone","RxReplicationState","replicateServer","options","newRxError","name","args","waitForLeadership","addRxPlugin","RxDBLeaderElectionPlugin","pullStream$","replicationPrimitivesPull","handler","checkpointOrNull","batchSize","lwt","id","url","response","fetch","method","assign","replicationState","data","parseResponse","documents","checkpoint","ensureNotFalsy","modifier","stream$","asObservable","replicationPrimitivesPush","changeRows","body","JSON","stringify","conflictsArray","startBefore","start","bind","useEventSource","eventSource","EventSource","refreshEventSource","withCredentials","onerror","err","status","next","close","promiseWait","then","onopen","x","onmessage","event","eventData","parse","startReplicationOnLeaderShip"],"sources":["../../../../src/plugins/replication-server/index.ts"],"sourcesContent":["import {\n ensureNotFalsy,\n flatClone,\n promiseWait,\n RxCollection,\n ReplicationPullOptions,\n ReplicationPushOptions,\n RxReplicationPullStreamItem,\n ById,\n addRxPlugin,\n newRxError,\n WithDeletedAndAttachments\n} from 'rxdb/plugins/core';\nimport { RxDBLeaderElectionPlugin } from 'rxdb/plugins/leader-election';\nimport {\n RxReplicationState,\n startReplicationOnLeaderShip\n} from 'rxdb/plugins/replication';\n\nimport { Subject } from 'rxjs';\nimport type {\n RxServerCheckpoint,\n ServerSyncOptions\n} from './types.ts';\nimport { parseResponse } from './helpers.ts';\nimport EventSource from 'eventsource';\n\nexport * from './types.ts';\n\nexport class RxServerReplicationState<RxDocType> extends RxReplicationState<RxDocType, RxServerCheckpoint> {\n public readonly outdatedClient$ = new Subject<void>();\n public readonly unauthorized$ = new Subject<void>();\n public readonly forbidden$ = new Subject<void>();\n\n constructor(\n public readonly replicationIdentifier: string,\n public readonly collection: RxCollection<RxDocType>,\n public readonly pull?: ReplicationPullOptions<RxDocType, RxServerCheckpoint>,\n public readonly push?: ReplicationPushOptions<RxDocType>,\n public readonly live: boolean = true,\n public retryTime: number = 1000 * 5,\n public autoStart: boolean = true,\n public headers: ById<string> = {}\n ) {\n super(\n replicationIdentifier,\n collection,\n '_deleted',\n pull,\n push,\n live,\n retryTime,\n autoStart\n );\n\n this.onCancel.push(() => {\n this.outdatedClient$.complete();\n this.unauthorized$.complete();\n this.forbidden$.complete();\n });\n }\n\n setHeaders(headers: ById<string>): void {\n this.headers = flatClone(headers);\n }\n}\n\nexport function replicateServer<RxDocType>(\n options: ServerSyncOptions<RxDocType>\n): RxServerReplicationState<RxDocType> {\n\n if (!options.pull && !options.push) {\n throw newRxError('UT3', {\n collection: options.collection.name,\n args: {\n replicationIdentifier: options.replicationIdentifier\n }\n });\n }\n\n options.live = typeof options.live === 'undefined' ? true : options.live;\n options.waitForLeadership = typeof options.waitForLeadership === 'undefined' ? true : options.waitForLeadership;\n\n const collection = options.collection;\n addRxPlugin(RxDBLeaderElectionPlugin);\n\n const pullStream$: Subject<RxReplicationPullStreamItem<RxDocType, RxServerCheckpoint>> = new Subject();\n\n let replicationPrimitivesPull: ReplicationPullOptions<RxDocType, RxServerCheckpoint> | undefined;\n if (options.pull) {\n replicationPrimitivesPull = {\n async handler(checkpointOrNull, batchSize) {\n const lwt = checkpointOrNull && checkpointOrNull.lwt ? checkpointOrNull.lwt : 0;\n const id = checkpointOrNull && checkpointOrNull.id ? checkpointOrNull.id : '';\n const url = options.url + `/pull?lwt=${lwt}&id=${id}&limit=${batchSize}`;\n const response = await fetch(url, {\n method: 'GET',\n headers: Object.assign({\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n }, replicationState.headers),\n });\n const data = await parseResponse(replicationState, response);\n return {\n documents: data.documents,\n checkpoint: data.checkpoint\n };\n },\n batchSize: ensureNotFalsy(options.pull).batchSize,\n modifier: ensureNotFalsy(options.pull).modifier,\n stream$: pullStream$.asObservable()\n };\n }\n\n let replicationPrimitivesPush: ReplicationPushOptions<RxDocType> | undefined;\n if (options.push) {\n replicationPrimitivesPush = {\n async handler(changeRows) {\n const response = await fetch(options.url + '/push', {\n method: 'POST',\n headers: Object.assign({\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n }, replicationState.headers),\n body: JSON.stringify(changeRows)\n });\n const conflictsArray = await parseResponse(replicationState, response);\n return conflictsArray;\n },\n batchSize: options.push.batchSize,\n modifier: options.push.modifier\n };\n }\n\n const replicationState = new RxServerReplicationState<RxDocType>(\n options.replicationIdentifier,\n collection,\n replicationPrimitivesPull,\n replicationPrimitivesPush,\n options.live,\n options.retryTime,\n options.autoStart,\n options.headers\n );\n\n /**\n * Use long polling to get live changes for the pull.stream$\n */\n if (options.live && options.pull) {\n const startBefore = replicationState.start.bind(replicationState);\n replicationState.start = async () => {\n const useEventSource: typeof EventSource = options.eventSource ? options.eventSource : EventSource;\n let eventSource: EventSource;\n const refreshEventSource = () => {\n eventSource = new useEventSource(options.url + '/pullStream', {\n withCredentials: true,\n /**\n * Sending headers is not supported by the Browser EventSource API,\n * only by the npm module we use. In react-native you might have\n * to set another EventSource implementation.\n * @link https://www.npmjs.com/package/eventsource\n */\n headers: replicationState.headers\n });\n // TODO check for 426 errors and handle them\n eventSource.onerror = (err) => {\n if (err.status === 401) {\n replicationState.unauthorized$.next();\n eventSource.close();\n promiseWait(replicationState.retryTime).then(() => refreshEventSource());\n } else {\n pullStream$.next('RESYNC');\n }\n };\n eventSource.onopen = (x) => {\n pullStream$.next('RESYNC');\n }\n eventSource.onmessage = event => {\n const eventData: { documents: WithDeletedAndAttachments<RxDocType>[]; checkpoint: RxServerCheckpoint; } = JSON.parse(event.data);\n pullStream$.next({\n documents: eventData.documents,\n checkpoint: eventData.checkpoint\n });\n };\n }\n refreshEventSource();\n\n replicationState.onCancel.push(() => eventSource && eventSource.close());\n return startBefore();\n };\n }\n\n startReplicationOnLeaderShip(options.waitForLeadership, replicationState);\n\n return replicationState;\n}\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAaA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAKA,IAAAG,KAAA,GAAAH,OAAA;AAKA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,YAAA,GAAAC,sBAAA,CAAAN,OAAA;AAEA,IAAAO,MAAA,GAAAP,OAAA;AAAAQ,MAAA,CAAAC,IAAA,CAAAF,MAAA,EAAAG,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,M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_replication","_rxjs","_helpers","_eventsource","_interopRequireDefault","_types","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","RxServerReplicationState","_RxReplicationState","replicationIdentifier","collection","pull","push","live","retryTime","autoStart","headers","_this","outdatedClient$","Subject","unauthorized$","forbidden$","onCancel","complete","_inheritsLoose2","default","_proto","setHeaders","flatClone","RxReplicationState","replicateServer","options","newRxError","name","args","waitForLeadership","addRxPlugin","RxDBLeaderElectionPlugin","pullStream$","replicationPrimitivesPull","handler","checkpointOrNull","batchSize","lwt","id","url","response","fetch","method","assign","replicationState","data","parseResponse","documents","checkpoint","ensureNotFalsy","modifier","stream$","asObservable","replicationPrimitivesPush","changeRows","body","JSON","stringify","conflictsArray","startBefore","start","bind","useEventSource","eventSource","EventSource","refreshEventSource","withCredentials","onerror","err","status","next","close","promiseWait","then","onopen","x","onmessage","event","eventData","parse","startReplicationOnLeaderShip"],"sources":["../../../../src/plugins/replication-server/index.ts"],"sourcesContent":["import {\n ensureNotFalsy,\n flatClone,\n promiseWait,\n RxCollection,\n ReplicationPullOptions,\n ReplicationPushOptions,\n RxReplicationPullStreamItem,\n ById,\n addRxPlugin,\n newRxError,\n WithDeletedAndAttachments\n} from 'rxdb/plugins/core';\nimport { RxDBLeaderElectionPlugin } from 'rxdb/plugins/leader-election';\nimport {\n RxReplicationState,\n startReplicationOnLeaderShip\n} from 'rxdb/plugins/replication';\n\nimport { Subject } from 'rxjs';\nimport type {\n RxServerCheckpoint,\n ServerSyncOptions\n} from './types.ts';\nimport { parseResponse } from './helpers.ts';\nimport EventSource from 'eventsource';\n\nexport * from './types.ts';\n\nexport class RxServerReplicationState<RxDocType> extends RxReplicationState<RxDocType, RxServerCheckpoint> {\n public readonly outdatedClient$ = new Subject<void>();\n public readonly unauthorized$ = new Subject<void>();\n public readonly forbidden$ = new Subject<void>();\n\n constructor(\n public readonly replicationIdentifier: string,\n public readonly collection: RxCollection<RxDocType>,\n public readonly pull?: ReplicationPullOptions<RxDocType, RxServerCheckpoint>,\n public readonly push?: ReplicationPushOptions<RxDocType>,\n public readonly live: boolean = true,\n public retryTime: number = 1000 * 5,\n public autoStart: boolean = true,\n public headers: ById<string> = {}\n ) {\n super(\n replicationIdentifier,\n collection,\n '_deleted',\n pull,\n push,\n live,\n retryTime,\n autoStart\n );\n\n this.onCancel.push(() => {\n this.outdatedClient$.complete();\n this.unauthorized$.complete();\n this.forbidden$.complete();\n });\n }\n\n setHeaders(headers: ById<string>): void {\n this.headers = flatClone(headers);\n }\n}\n\nexport function replicateServer<RxDocType>(\n options: ServerSyncOptions<RxDocType>\n): RxServerReplicationState<RxDocType> {\n\n if (!options.pull && !options.push) {\n throw newRxError('UT3', {\n collection: options.collection.name,\n args: {\n replicationIdentifier: options.replicationIdentifier\n }\n });\n }\n\n options.live = typeof options.live === 'undefined' ? true : options.live;\n options.waitForLeadership = typeof options.waitForLeadership === 'undefined' ? true : options.waitForLeadership;\n\n const collection = options.collection;\n addRxPlugin(RxDBLeaderElectionPlugin);\n\n const pullStream$: Subject<RxReplicationPullStreamItem<RxDocType, RxServerCheckpoint>> = new Subject();\n\n let replicationPrimitivesPull: ReplicationPullOptions<RxDocType, RxServerCheckpoint> | undefined;\n if (options.pull) {\n replicationPrimitivesPull = {\n async handler(checkpointOrNull, batchSize) {\n const lwt = checkpointOrNull && checkpointOrNull.lwt ? checkpointOrNull.lwt : 0;\n const id = checkpointOrNull && checkpointOrNull.id ? checkpointOrNull.id : '';\n const url = options.url + `/pull?lwt=${lwt}&id=${id}&limit=${batchSize}`;\n const response = await fetch(url, {\n method: 'GET',\n headers: Object.assign({\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n }, replicationState.headers),\n });\n const data = await parseResponse(replicationState, response);\n return {\n documents: data.documents,\n checkpoint: data.checkpoint\n };\n },\n batchSize: ensureNotFalsy(options.pull).batchSize,\n modifier: ensureNotFalsy(options.pull).modifier,\n stream$: pullStream$.asObservable()\n };\n }\n\n let replicationPrimitivesPush: ReplicationPushOptions<RxDocType> | undefined;\n if (options.push) {\n replicationPrimitivesPush = {\n async handler(changeRows) {\n const response = await fetch(options.url + '/push', {\n method: 'POST',\n headers: Object.assign({\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n }, replicationState.headers),\n body: JSON.stringify(changeRows)\n });\n const conflictsArray = await parseResponse(replicationState, response);\n return conflictsArray;\n },\n batchSize: options.push.batchSize,\n modifier: options.push.modifier\n };\n }\n\n const replicationState = new RxServerReplicationState<RxDocType>(\n options.replicationIdentifier,\n collection,\n replicationPrimitivesPull,\n replicationPrimitivesPush,\n options.live,\n options.retryTime,\n options.autoStart,\n options.headers\n );\n\n /**\n * Use long polling to get live changes for the pull.stream$\n */\n if (options.live && options.pull) {\n const startBefore = replicationState.start.bind(replicationState);\n replicationState.start = async () => {\n const useEventSource: typeof EventSource = options.eventSource ? options.eventSource : EventSource;\n let eventSource: EventSource;\n const refreshEventSource = () => {\n eventSource = new useEventSource(options.url + '/pullStream', {\n withCredentials: true,\n /**\n * Sending headers is not supported by the Browser EventSource API,\n * only by the npm module we use. In react-native you might have\n * to set another EventSource implementation.\n * @link https://www.npmjs.com/package/eventsource\n */\n headers: replicationState.headers\n });\n // TODO check for 426 errors and handle them\n eventSource.onerror = (err) => {\n if (err.status === 401) {\n replicationState.unauthorized$.next();\n eventSource.close();\n promiseWait(replicationState.retryTime).then(() => refreshEventSource());\n } else {\n pullStream$.next('RESYNC');\n }\n };\n eventSource.onopen = (x) => {\n pullStream$.next('RESYNC');\n }\n eventSource.onmessage = event => {\n const eventData: { documents: WithDeletedAndAttachments<RxDocType>[]; checkpoint: RxServerCheckpoint; } = JSON.parse(event.data);\n pullStream$.next({\n documents: eventData.documents,\n checkpoint: eventData.checkpoint\n });\n };\n }\n refreshEventSource();\n\n replicationState.onCancel.push(() => eventSource && eventSource.close());\n return startBefore();\n };\n }\n\n startReplicationOnLeaderShip(options.waitForLeadership, replicationState);\n\n return replicationState;\n}\n"],"mappings":";;;;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AC,CAAC;QACN,CAAC;MACL,CAAC;MACDiB,kBAAkB,CAAC,CAAC;MAEpBrB,gBAAgB,CAAC5B,QAAQ,CAACV,IAAI,CAAC,MAAMyD,WAAW,IAAIA,WAAW,CAACQ,KAAK,CAAC,CAAC,CAAC;MACxE,OAAOZ,WAAW,CAAC,CAAC;IACxB,CAAC;EACL;EAEA,IAAAqB,yCAA4B,EAACvD,OAAO,CAACI,iBAAiB,EAAEe,gBAAgB,CAAC;EAEzE,OAAOA,gBAAgB;AAC3B","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"rx-server.js","names":["_endpointReplication","require","_endpointRest","RxServer","exports","options","authHandler","serverApp","cors","endpoints","closeFn","close","bind","database","adapter","onDestroy","push","_proto","prototype","ensureNotStarted","listenPromise","Error","addReplicationEndpoint","opts","endpoint","RxServerReplicationEndpoint","name","collection","queryModifier","_a","q","changeValidator","serverOnlyFields","addRestEndpoint","RxServerRestEndpoint","start","hostname","listen","port","filter","fn"],"sources":["../../../../src/plugins/server/rx-server.ts"],"sourcesContent":["import type {\n RxCollection,\n RxDatabase\n} from 'rxdb/plugins/core';\nimport { RxServerReplicationEndpoint } from './endpoint-replication.ts';\nimport type {\n RxServerAdapter,\n RxServerAuthHandler,\n RxServerChangeValidator,\n RxServerEndpoint,\n RxServerOptions,\n RxServerQueryModifier\n} from './types.ts';\nimport { RxServerRestEndpoint } from './endpoint-rest.ts';\n\nexport class RxServer<ServerAppType, AuthType> {\n public readonly endpoints: RxServerEndpoint<AuthType, any>[] = [];\n\n private closeFn = (() => this.close()).bind(this);\n public listenPromise?: Promise<void>;\n\n public readonly database: RxDatabase;\n public readonly adapter: RxServerAdapter<ServerAppType>;\n\n constructor(\n public readonly options: RxServerOptions<ServerAppType, AuthType>,\n public readonly authHandler: RxServerAuthHandler<AuthType>,\n public readonly serverApp: ServerAppType,\n public readonly cors: string = '*'\n ) {\n this.database = options.database;\n this.adapter = options.adapter;\n options.database.onDestroy.push(this.closeFn);\n }\n\n private ensureNotStarted() {\n if (this.listenPromise) {\n throw new Error('This operation cannot be run after the RxServer has been started already');\n }\n\n }\n\n public addReplicationEndpoint<RxDocType>(opts: {\n name: string,\n collection: RxCollection<RxDocType>,\n queryModifier?: RxServerQueryModifier<AuthType, RxDocType>,\n changeValidator?: RxServerChangeValidator<AuthType, RxDocType>,\n /**\n * Set a origin for allowed CORS requests.\n * Overwrites the cors option of the server.\n * [default='*']\n */\n cors?: '*' | string,\n serverOnlyFields?: string[]\n }) {\n this.ensureNotStarted();\n const endpoint = new RxServerReplicationEndpoint(\n this,\n opts.name,\n opts.collection,\n opts.queryModifier ? opts.queryModifier : (_a, q) => q,\n opts.changeValidator ? opts.changeValidator : () => true,\n opts.serverOnlyFields ? opts.serverOnlyFields : [],\n opts.cors\n );\n this.endpoints.push(endpoint);\n return endpoint;\n }\n\n public addRestEndpoint<RxDocType>(opts: {\n name: string,\n collection: RxCollection<RxDocType>,\n queryModifier?: RxServerQueryModifier<AuthType, RxDocType>,\n changeValidator?: RxServerChangeValidator<AuthType, RxDocType>,\n /**\n * Set a origin for allowed CORS requests.\n * Overwrites the cors option of the server.\n * [default='*']\n */\n cors?: '*' | string,\n serverOnlyFields?: string[]\n }) {\n this.ensureNotStarted();\n const endpoint = new RxServerRestEndpoint(\n this,\n opts.name,\n opts.collection,\n opts.queryModifier ? opts.queryModifier : (_a, q) => q,\n opts.changeValidator ? opts.changeValidator : () => true,\n opts.serverOnlyFields ? opts.serverOnlyFields : [],\n opts.cors\n );\n this.endpoints.push(endpoint);\n return endpoint;\n }\n\n async start() {\n this.ensureNotStarted();\n const hostname = this.options.hostname ? this.options.hostname : 'localhost';\n this.listenPromise = this.options.adapter.listen(this.serverApp, this.options.port, hostname);\n return this.listenPromise;\n }\n\n async close() {\n this.database.onDestroy = this.database.onDestroy.filter(fn => fn !== this.closeFn);\n if (this.listenPromise) {\n await this.listenPromise;\n await this.options.adapter.close(this.serverApp);\n }\n }\n}\n"],"mappings":";;;;;;AAIA,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AAI,CAACE,QAAQ,CAACE,SAAS,GAAG,IAAI,CAACF,QAAQ,CAACE,SAAS,CAACwB,MAAM,CAACC,EAAE,IAAIA,EAAE,KAAK,IAAI,CAAC9B,OAAO,CAAC;IACnF,IAAI,IAAI,CAACU,aAAa,EAAE;MACpB,MAAM,IAAI,CAACA,aAAa;MACxB,MAAM,IAAI,CAACf,OAAO,CAACS,OAAO,CAACH,KAAK,CAAC,IAAI,CAACJ,SAAS,CAAC;IACpD;EACJ,CAAC;EAAA,OAAAJ,QAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"rx-server.js","names":["_endpointReplication","require","_endpointRest","RxServer","exports","options","authHandler","serverApp","cors","endpoints","closeFn","close","bind","database","adapter","onDestroy","push","_proto","prototype","ensureNotStarted","listenPromise","Error","addReplicationEndpoint","opts","endpoint","RxServerReplicationEndpoint","name","collection","queryModifier","_a","q","changeValidator","serverOnlyFields","addRestEndpoint","RxServerRestEndpoint","start","hostname","listen","port","filter","fn"],"sources":["../../../../src/plugins/server/rx-server.ts"],"sourcesContent":["import type {\n RxCollection,\n RxDatabase\n} from 'rxdb/plugins/core';\nimport { RxServerReplicationEndpoint } from './endpoint-replication.ts';\nimport type {\n RxServerAdapter,\n RxServerAuthHandler,\n RxServerChangeValidator,\n RxServerEndpoint,\n RxServerOptions,\n RxServerQueryModifier\n} from './types.ts';\nimport { RxServerRestEndpoint } from './endpoint-rest.ts';\n\nexport class RxServer<ServerAppType, AuthType> {\n public readonly endpoints: RxServerEndpoint<AuthType, any>[] = [];\n\n private closeFn = (() => this.close()).bind(this);\n public listenPromise?: Promise<void>;\n\n public readonly database: RxDatabase;\n public readonly adapter: RxServerAdapter<ServerAppType>;\n\n constructor(\n public readonly options: RxServerOptions<ServerAppType, AuthType>,\n public readonly authHandler: RxServerAuthHandler<AuthType>,\n public readonly serverApp: ServerAppType,\n public readonly cors: string = '*'\n ) {\n this.database = options.database;\n this.adapter = options.adapter;\n options.database.onDestroy.push(this.closeFn);\n }\n\n private ensureNotStarted() {\n if (this.listenPromise) {\n throw new Error('This operation cannot be run after the RxServer has been started already');\n }\n\n }\n\n public addReplicationEndpoint<RxDocType>(opts: {\n name: string,\n collection: RxCollection<RxDocType>,\n queryModifier?: RxServerQueryModifier<AuthType, RxDocType>,\n changeValidator?: RxServerChangeValidator<AuthType, RxDocType>,\n /**\n * Set a origin for allowed CORS requests.\n * Overwrites the cors option of the server.\n * [default='*']\n */\n cors?: '*' | string,\n serverOnlyFields?: string[]\n }) {\n this.ensureNotStarted();\n const endpoint = new RxServerReplicationEndpoint(\n this,\n opts.name,\n opts.collection,\n opts.queryModifier ? opts.queryModifier : (_a, q) => q,\n opts.changeValidator ? opts.changeValidator : () => true,\n opts.serverOnlyFields ? opts.serverOnlyFields : [],\n opts.cors\n );\n this.endpoints.push(endpoint);\n return endpoint;\n }\n\n public addRestEndpoint<RxDocType>(opts: {\n name: string,\n collection: RxCollection<RxDocType>,\n queryModifier?: RxServerQueryModifier<AuthType, RxDocType>,\n changeValidator?: RxServerChangeValidator<AuthType, RxDocType>,\n /**\n * Set a origin for allowed CORS requests.\n * Overwrites the cors option of the server.\n * [default='*']\n */\n cors?: '*' | string,\n serverOnlyFields?: string[]\n }) {\n this.ensureNotStarted();\n const endpoint = new RxServerRestEndpoint(\n this,\n opts.name,\n opts.collection,\n opts.queryModifier ? opts.queryModifier : (_a, q) => q,\n opts.changeValidator ? opts.changeValidator : () => true,\n opts.serverOnlyFields ? opts.serverOnlyFields : [],\n opts.cors\n );\n this.endpoints.push(endpoint);\n return endpoint;\n }\n\n async start() {\n this.ensureNotStarted();\n const hostname = this.options.hostname ? this.options.hostname : 'localhost';\n this.listenPromise = this.options.adapter.listen(this.serverApp, this.options.port, hostname);\n return this.listenPromise;\n }\n\n async close() {\n this.database.onDestroy = this.database.onDestroy.filter(fn => fn !== this.closeFn);\n if (this.listenPromise) {\n await this.listenPromise;\n await this.options.adapter.close(this.serverApp);\n }\n }\n}\n"],"mappings":";;;;;;AAIA,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,eAAMA,KAAKA,CAAA,EAAG;IACV,IAAI,CAACE,QAAQ,CAACE,SAAS,GAAG,IAAI,CAACF,QAAQ,CAACE,SAAS,CAACwB,MAAM,CAACC,EAAE,IAAIA,EAAE,KAAK,IAAI,CAAC9B,OAAO,CAAC;IACnF,IAAI,IAAI,CAACU,aAAa,EAAE;MACpB,MAAM,IAAI,CAACA,aAAa;MACxB,MAAM,IAAI,CAACf,OAAO,CAACS,OAAO,CAACH,KAAK,CAAC,IAAI,CAACJ,SAAS,CAAC;IACpD;EACJ,CAAC;EAAA,OAAAJ,QAAA;AAAA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["postRequest","Subject","EventSource","RxRestClient","endpointUrl","headers","eventSource","_proto","prototype","setHeaders","handleError","response","error","Error","JSON","stringify","query","observeQuery","result","queryAsBase64","btoa","withCredentials","onmessage","event","eventData","parse","data","next","asObservable","get","ids","set","docs","delete","_delete","createRestClient"],"sources":["../../../../src/plugins/client-rest/index.ts"],"sourcesContent":["import { ById, MangoQuery, newRxError } from 'rxdb/plugins/core';\nimport { postRequest } from './utils.ts';\nimport { Observable, Subject } from 'rxjs';\nimport EventSource from 'eventsource';\n\nexport class RxRestClient<RxDocType> {\n constructor(\n public readonly endpointUrl: string,\n public headers: ById<string> = {},\n public readonly eventSource: typeof EventSource | any = EventSource\n ) { }\n\n setHeaders(headers: ById<string>) {\n this.headers = headers;\n }\n\n handleError(response: any) {\n if (response.error) {\n throw new Error('Server returned an error ' + JSON.stringify(response));\n }\n }\n\n async query(query: MangoQuery<RxDocType>): Promise<{ documents: RxDocType[] }> {\n const response = await postRequest(\n this.endpointUrl + '/query',\n query,\n this.headers\n );\n this.handleError(response);\n return response;\n }\n\n observeQuery(query: MangoQuery<RxDocType>): Observable<RxDocType[]> {\n const result = new Subject<RxDocType[]>;\n const queryAsBase64 = btoa(JSON.stringify(query));\n const eventSource: EventSource = new this.eventSource(\n this.endpointUrl + '/query/observe?query=' + queryAsBase64,\n {\n withCredentials: true,\n /**\n * Sending headers is not supported by the Browser EventSource API,\n * only by the npm module we use. In react-native you might have\n * to set another EventSource implementation.\n * @link https://www.npmjs.com/package/eventsource\n */\n headers: this.headers\n });\n eventSource.onmessage = event => {\n const eventData = JSON.parse(event.data);\n result.next(eventData);\n };\n return result.asObservable();\n }\n\n get(ids: string[]): Promise<{ documents: RxDocType[] }> {\n const response = postRequest(\n this.endpointUrl + '/get',\n ids,\n this.headers\n );\n this.handleError(response);\n return response;\n }\n\n set(docs: RxDocType[]) {\n const response = postRequest(\n this.endpointUrl + '/set',\n docs,\n this.headers\n );\n this.handleError(response);\n return response;\n }\n\n delete(ids: string[]) {\n const response = postRequest(\n this.endpointUrl + '/delete',\n ids,\n this.headers\n );\n this.handleError(response);\n return response;\n }\n}\n\nexport function createRestClient<RxDocType>(\n endpointUrl: string,\n headers: ById<string>,\n eventSource: typeof EventSource | any = EventSource\n) {\n\n return new RxRestClient<RxDocType>(\n endpointUrl,\n headers,\n eventSource\n );\n}\n\n\nexport * from './utils.ts';\n"],"mappings":"AACA,SAASA,WAAW,QAAQ,YAAY;AACxC,SAAqBC,OAAO,QAAQ,MAAM;AAC1C,OAAOC,WAAW,MAAM,aAAa;AAErC,WAAaC,YAAY;EACrB,SAAAA,aACoBC,WAAmB,EAC5BC,OAAqB,GAAG,CAAC,CAAC,EACjBC,WAAqC,GAAGJ,WAAW,EACrE;IAAA,KAHkBE,WAAmB,GAAnBA,WAAmB;IAAA,KAC5BC,OAAqB,GAArBA,OAAqB;IAAA,KACZC,WAAqC,GAArCA,WAAqC;EACrD;EAAC,IAAAC,MAAA,GAAAJ,YAAA,CAAAK,SAAA;EAAAD,MAAA,CAELE,UAAU,GAAV,SAAAA,WAAWJ,OAAqB,EAAE;IAC9B,IAAI,CAACA,OAAO,GAAGA,OAAO;EAC1B,CAAC;EAAAE,MAAA,CAEDG,WAAW,GAAX,SAAAA,YAAYC,QAAa,EAAE;IACvB,IAAIA,QAAQ,CAACC,KAAK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AC;IAC1B,OAAOA,QAAQ;EACnB,CAAC;EAAAJ,MAAA,CAEDwB,GAAG,GAAH,SAAAA,IAAIC,IAAiB,EAAE;IACnB,IAAMrB,QAAQ,GAAGX,WAAW,CACxB,IAAI,CAACI,WAAW,GAAG,MAAM,EACzB4B,IAAI,EACJ,IAAI,CAAC3B,OACT,CAAC;IACD,IAAI,CAACK,WAAW,CAACC,QAAQ,CAAC;IAC1B,OAAOA,QAAQ;EACnB,CAAC;EAAAJ,MAAA,CAED0B,MAAM,GAAN,SAAAC,QAAOJ,GAAa,EAAE;IAClB,IAAMnB,QAAQ,GAAGX,WAAW,CACxB,IAAI,CAACI,WAAW,GAAG,SAAS,EAC5B0B,GAAG,EACH,IAAI,CAACzB,OACT,CAAC;IACD,IAAI,CAACK,WAAW,CAACC,QAAQ,CAAC;IAC1B,OAAOA,QAAQ;EACnB,CAAC;EAAA,OAAAR,YAAA;AAAA;AAGL,OAAO,SAASgC,gBAAgBA,CAC5B/B,WAAmB,EACnBC,OAAqB,EACrBC,WAAqC,GAAGJ,WAAW,EACrD;EAEE,OAAO,IAAIC,YAAY,CACnBC,WAAW,EACXC,OAAO,EACPC,WACJ,CAAC;AACL;AAGA,cAAc,YAAY","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["postRequest","Subject","EventSource","RxRestClient","endpointUrl","headers","eventSource","_proto","prototype","setHeaders","handleError","response","error","Error","JSON","stringify","query","observeQuery","result","queryAsBase64","btoa","withCredentials","onmessage","event","eventData","parse","data","next","asObservable","get","ids","set","docs","delete","createRestClient"],"sources":["../../../../src/plugins/client-rest/index.ts"],"sourcesContent":["import { ById, MangoQuery, newRxError } from 'rxdb/plugins/core';\nimport { postRequest } from './utils.ts';\nimport { Observable, Subject } from 'rxjs';\nimport EventSource from 'eventsource';\n\nexport class RxRestClient<RxDocType> {\n constructor(\n public readonly endpointUrl: string,\n public headers: ById<string> = {},\n public readonly eventSource: typeof EventSource | any = EventSource\n ) { }\n\n setHeaders(headers: ById<string>) {\n this.headers = headers;\n }\n\n handleError(response: any) {\n if (response.error) {\n throw new Error('Server returned an error ' + JSON.stringify(response));\n }\n }\n\n async query(query: MangoQuery<RxDocType>): Promise<{ documents: RxDocType[] }> {\n const response = await postRequest(\n this.endpointUrl + '/query',\n query,\n this.headers\n );\n this.handleError(response);\n return response;\n }\n\n observeQuery(query: MangoQuery<RxDocType>): Observable<RxDocType[]> {\n const result = new Subject<RxDocType[]>;\n const queryAsBase64 = btoa(JSON.stringify(query));\n const eventSource: EventSource = new this.eventSource(\n this.endpointUrl + '/query/observe?query=' + queryAsBase64,\n {\n withCredentials: true,\n /**\n * Sending headers is not supported by the Browser EventSource API,\n * only by the npm module we use. In react-native you might have\n * to set another EventSource implementation.\n * @link https://www.npmjs.com/package/eventsource\n */\n headers: this.headers\n });\n eventSource.onmessage = event => {\n const eventData = JSON.parse(event.data);\n result.next(eventData);\n };\n return result.asObservable();\n }\n\n get(ids: string[]): Promise<{ documents: RxDocType[] }> {\n const response = postRequest(\n this.endpointUrl + '/get',\n ids,\n this.headers\n );\n this.handleError(response);\n return response;\n }\n\n set(docs: RxDocType[]) {\n const response = postRequest(\n this.endpointUrl + '/set',\n docs,\n this.headers\n );\n this.handleError(response);\n return response;\n }\n\n delete(ids: string[]) {\n const response = postRequest(\n this.endpointUrl + '/delete',\n ids,\n this.headers\n );\n this.handleError(response);\n return response;\n }\n}\n\nexport function createRestClient<RxDocType>(\n endpointUrl: string,\n headers: ById<string>,\n eventSource: typeof EventSource | any = EventSource\n) {\n\n return new RxRestClient<RxDocType>(\n endpointUrl,\n headers,\n eventSource\n );\n}\n\n\nexport * from './utils.ts';\n"],"mappings":"AACA,SAASA,WAAW,QAAQ,YAAY;AACxC,SAAqBC,OAAO,QAAQ,MAAM;AAC1C,OAAOC,WAAW,MAAM,aAAa;AAErC,WAAaC,YAAY;EACrB,SAAAA,aACoBC,WAAmB,EAC5BC,OAAqB,GAAG,CAAC,CAAC,EACjBC,WAAqC,GAAGJ,WAA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flatClone","promiseWait","addRxPlugin","newRxError","RxDBLeaderElectionPlugin","RxReplicationState","startReplicationOnLeaderShip","Subject","parseResponse","EventSource","RxServerReplicationState","_RxReplicationState","replicationIdentifier","collection","pull","push","live","retryTime","autoStart","headers","_this","call","outdatedClient$","unauthorized$","forbidden$","onCancel","complete","_inheritsLoose","_proto","prototype","setHeaders","replicateServer","options","name","args","waitForLeadership","pullStream$","replicationPrimitivesPull","handler","checkpointOrNull","batchSize","lwt","id","url","response","fetch","method","Object","assign","replicationState","data","documents","checkpoint","modifier","stream$","asObservable","replicationPrimitivesPush","changeRows","body","JSON","stringify","conflictsArray","startBefore","start","bind","useEventSource","eventSource","refreshEventSource","withCredentials","onerror","err","status","next","close","then","onopen","x","onmessage","event","eventData","parse"],"sources":["../../../../src/plugins/replication-server/index.ts"],"sourcesContent":["import {\n ensureNotFalsy,\n flatClone,\n promiseWait,\n RxCollection,\n ReplicationPullOptions,\n ReplicationPushOptions,\n RxReplicationPullStreamItem,\n ById,\n addRxPlugin,\n newRxError,\n WithDeletedAndAttachments\n} from 'rxdb/plugins/core';\nimport { RxDBLeaderElectionPlugin } from 'rxdb/plugins/leader-election';\nimport {\n RxReplicationState,\n startReplicationOnLeaderShip\n} from 'rxdb/plugins/replication';\n\nimport { Subject } from 'rxjs';\nimport type {\n RxServerCheckpoint,\n ServerSyncOptions\n} from './types.ts';\nimport { parseResponse } from './helpers.ts';\nimport EventSource from 'eventsource';\n\nexport * from './types.ts';\n\nexport class RxServerReplicationState<RxDocType> extends RxReplicationState<RxDocType, RxServerCheckpoint> {\n public readonly outdatedClient$ = new Subject<void>();\n public readonly unauthorized$ = new Subject<void>();\n public readonly forbidden$ = new Subject<void>();\n\n constructor(\n public readonly replicationIdentifier: string,\n public readonly collection: RxCollection<RxDocType>,\n public readonly pull?: ReplicationPullOptions<RxDocType, RxServerCheckpoint>,\n public readonly push?: ReplicationPushOptions<RxDocType>,\n public readonly live: boolean = true,\n public retryTime: number = 1000 * 5,\n public autoStart: boolean = true,\n public headers: ById<string> = {}\n ) {\n super(\n replicationIdentifier,\n collection,\n '_deleted',\n pull,\n push,\n live,\n retryTime,\n autoStart\n );\n\n this.onCancel.push(() => {\n this.outdatedClient$.complete();\n this.unauthorized$.complete();\n this.forbidden$.complete();\n });\n }\n\n setHeaders(headers: ById<string>): void {\n this.headers = flatClone(headers);\n }\n}\n\nexport function replicateServer<RxDocType>(\n options: ServerSyncOptions<RxDocType>\n): RxServerReplicationState<RxDocType> {\n\n if (!options.pull && !options.push) {\n throw newRxError('UT3', {\n collection: options.collection.name,\n args: {\n replicationIdentifier: options.replicationIdentifier\n }\n });\n }\n\n options.live = typeof options.live === 'undefined' ? true : options.live;\n options.waitForLeadership = typeof options.waitForLeadership === 'undefined' ? true : options.waitForLeadership;\n\n const collection = options.collection;\n addRxPlugin(RxDBLeaderElectionPlugin);\n\n const pullStream$: Subject<RxReplicationPullStreamItem<RxDocType, RxServerCheckpoint>> = new Subject();\n\n let replicationPrimitivesPull: ReplicationPullOptions<RxDocType, RxServerCheckpoint> | undefined;\n if (options.pull) {\n replicationPrimitivesPull = {\n async handler(checkpointOrNull, batchSize) {\n const lwt = checkpointOrNull && checkpointOrNull.lwt ? checkpointOrNull.lwt : 0;\n const id = checkpointOrNull && checkpointOrNull.id ? checkpointOrNull.id : '';\n const url = options.url + `/pull?lwt=${lwt}&id=${id}&limit=${batchSize}`;\n const response = await fetch(url, {\n method: 'GET',\n headers: Object.assign({\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n }, replicationState.headers),\n });\n const data = await parseResponse(replicationState, response);\n return {\n documents: data.documents,\n checkpoint: data.checkpoint\n };\n },\n batchSize: ensureNotFalsy(options.pull).batchSize,\n modifier: ensureNotFalsy(options.pull).modifier,\n stream$: pullStream$.asObservable()\n };\n }\n\n let replicationPrimitivesPush: ReplicationPushOptions<RxDocType> | undefined;\n if (options.push) {\n replicationPrimitivesPush = {\n async handler(changeRows) {\n const response = await fetch(options.url + '/push', {\n method: 'POST',\n headers: Object.assign({\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n }, replicationState.headers),\n body: JSON.stringify(changeRows)\n });\n const conflictsArray = await parseResponse(replicationState, response);\n return conflictsArray;\n },\n batchSize: options.push.batchSize,\n modifier: options.push.modifier\n };\n }\n\n const replicationState = new RxServerReplicationState<RxDocType>(\n options.replicationIdentifier,\n collection,\n replicationPrimitivesPull,\n replicationPrimitivesPush,\n options.live,\n options.retryTime,\n options.autoStart,\n options.headers\n );\n\n /**\n * Use long polling to get live changes for the pull.stream$\n */\n if (options.live && options.pull) {\n const startBefore = replicationState.start.bind(replicationState);\n replicationState.start = async () => {\n const useEventSource: typeof EventSource = options.eventSource ? options.eventSource : EventSource;\n let eventSource: EventSource;\n const refreshEventSource = () => {\n eventSource = new useEventSource(options.url + '/pullStream', {\n withCredentials: true,\n /**\n * Sending headers is not supported by the Browser EventSource API,\n * only by the npm module we use. In react-native you might have\n * to set another EventSource implementation.\n * @link https://www.npmjs.com/package/eventsource\n */\n headers: replicationState.headers\n });\n // TODO check for 426 errors and handle them\n eventSource.onerror = (err) => {\n if (err.status === 401) {\n replicationState.unauthorized$.next();\n eventSource.close();\n promiseWait(replicationState.retryTime).then(() => refreshEventSource());\n } else {\n pullStream$.next('RESYNC');\n }\n };\n eventSource.onopen = (x) => {\n pullStream$.next('RESYNC');\n }\n eventSource.onmessage = event => {\n const eventData: { documents: WithDeletedAndAttachments<RxDocType>[]; checkpoint: RxServerCheckpoint; } = JSON.parse(event.data);\n pullStream$.next({\n documents: eventData.documents,\n checkpoint: eventData.checkpoint\n });\n };\n }\n refreshEventSource();\n\n replicationState.onCancel.push(() => eventSource && eventSource.close());\n return startBefore();\n };\n }\n\n startReplicationOnLeaderShip(options.waitForLeadership, replicationState);\n\n return replicationState;\n}\n"],"mappings":";AAAA,SACIA,cAAc,EACdC,SAAS,EACTC,WAAW,EAMXC,WAAW,EACXC,UAAU,QAEP,mBAAmB;AAC1B,SAASC,wBAAwB,QAAQ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pBtB,gBAAgB,CAAC1B,aAAa,CAACiD,IAAI,CAAC,CAAC;YACrCN,WAAW,CAACO,KAAK,CAAC,CAAC;YACnBxE,WAAW,CAACgD,gBAAgB,CAAChC,SAAS,CAAC,CAACyD,IAAI,CAAC,MAAMP,kBAAkB,CAAC,CAAC,CAAC;UAC5E,CAAC,MAAM;YACH/B,WAAW,CAACoC,IAAI,CAAC,QAAQ,CAAC;UAC9B;QACJ,CAAC;QACDN,WAAW,CAACS,MAAM,GAAIC,CAAC,IAAK;UACxBxC,WAAW,CAACoC,IAAI,CAAC,QAAQ,CAAC;QAC9B,CAAC;QACDN,WAAW,CAACW,SAAS,GAAGC,KAAK,IAAI;UAC7B,IAAMC,SAAiG,GAAGpB,IAAI,CAACqB,KAAK,CAACF,KAAK,CAAC5B,IAAI,CAAC;UAChId,WAAW,CAACoC,IAAI,CAAC;YACbrB,SAAS,EAAE4B,SAAS,CAAC5B,SAAS;YAC9BC,UAAU,EAAE2B,SAAS,CAAC3B;UAC1B,CAAC,CAAC;QACN,CAAC;MACL,CAAC;MACDe,kBAAkB,CAAC,CAAC;MAEpBlB,gBAAgB,CAACxB,QAAQ,CAACV,IAAI,CAAC,MAAMmD,WAAW,IAAIA,WAAW,CAACO,KAAK,CAAC,CAAC,CAAC;MACxE,OAAOX,WAAW,CAAC,CAAC;IACxB,CAAC;EACL;EAEAxD,4BAA4B,CAAC0B,OAAO,CAACG,iBAAiB,EAAEc,gBAAgB,CAAC;EAEzE,OAAOA,gBAAgB;AAC3B","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["ensureNotFalsy","flatClone","promiseWait","addRxPlugin","newRxError","RxDBLeaderElectionPlugin","RxReplicationState","startReplicationOnLeaderShip","Subject","parseResponse","EventSource","RxServerReplicationState","_RxReplicationState","replicationIdentifier","collection","pull","push","live","retryTime","autoStart","headers","_this","call","outdatedClient$","unauthorized$","forbidden$","onCancel","complete","_inheritsLoose","_proto","prototype","setHeaders","replicateServer","options","name","args","waitForLeadership","pullStream$","replicationPrimitivesPull","handler","checkpointOrNull","batchSize","lwt","id","url","response","fetch","method","Object","assign","replicationState","data","documents","checkpoint","modifier","stream$","asObservable","replicationPrimitivesPush","changeRows","body","JSON","stringify","conflictsArray","startBefore","start","bind","useEventSource","eventSource","refreshEventSource","withCredentials","onerror","err","status","next","close","then","onopen","x","onmessage","event","eventData","parse"],"sources":["../../../../src/plugins/replication-server/index.ts"],"sourcesContent":["import {\n ensureNotFalsy,\n flatClone,\n promiseWait,\n RxCollection,\n ReplicationPullOptions,\n ReplicationPushOptions,\n RxReplicationPullStreamItem,\n ById,\n addRxPlugin,\n newRxError,\n WithDeletedAndAttachments\n} from 'rxdb/plugins/core';\nimport { RxDBLeaderElectionPlugin } from 'rxdb/plugins/leader-election';\nimport {\n RxReplicationState,\n startReplicationOnLeaderShip\n} from 'rxdb/plugins/replication';\n\nimport { Subject } from 'rxjs';\nimport type {\n RxServerCheckpoint,\n ServerSyncOptions\n} from './types.ts';\nimport { parseResponse } from './helpers.ts';\nimport EventSource from 'eventsource';\n\nexport * from './types.ts';\n\nexport class RxServerReplicationState<RxDocType> extends RxReplicationState<RxDocType, RxServerCheckpoint> {\n public readonly outdatedClient$ = new Subject<void>();\n public readonly unauthorized$ = new Subject<void>();\n public readonly forbidden$ = new Subject<void>();\n\n constructor(\n public readonly replicationIdentifier: string,\n public readonly collection: RxCollection<RxDocType>,\n public readonly pull?: ReplicationPullOptions<RxDocType, RxServerCheckpoint>,\n public readonly push?: ReplicationPushOptions<RxDocType>,\n public readonly live: boolean = true,\n public retryTime: number = 1000 * 5,\n public autoStart: boolean = true,\n public headers: ById<string> = {}\n ) {\n super(\n replicationIdentifier,\n collection,\n '_deleted',\n pull,\n push,\n live,\n retryTime,\n autoStart\n );\n\n this.onCancel.push(() => {\n this.outdatedClient$.complete();\n this.unauthorized$.complete();\n this.forbidden$.complete();\n });\n }\n\n setHeaders(headers: ById<string>): void {\n this.headers = flatClone(headers);\n }\n}\n\nexport function replicateServer<RxDocType>(\n options: ServerSyncOptions<RxDocType>\n): RxServerReplicationState<RxDocType> {\n\n if (!options.pull && !options.push) {\n throw newRxError('UT3', {\n collection: options.collection.name,\n args: {\n replicationIdentifier: options.replicationIdentifier\n }\n });\n }\n\n options.live = typeof options.live === 'undefined' ? true : options.live;\n options.waitForLeadership = typeof options.waitForLeadership === 'undefined' ? true : options.waitForLeadership;\n\n const collection = options.collection;\n addRxPlugin(RxDBLeaderElectionPlugin);\n\n const pullStream$: Subject<RxReplicationPullStreamItem<RxDocType, RxServerCheckpoint>> = new Subject();\n\n let replicationPrimitivesPull: ReplicationPullOptions<RxDocType, RxServerCheckpoint> | undefined;\n if (options.pull) {\n replicationPrimitivesPull = {\n async handler(checkpointOrNull, batchSize) {\n const lwt = checkpointOrNull && checkpointOrNull.lwt ? checkpointOrNull.lwt : 0;\n const id = checkpointOrNull && checkpointOrNull.id ? checkpointOrNull.id : '';\n const url = options.url + `/pull?lwt=${lwt}&id=${id}&limit=${batchSize}`;\n const response = await fetch(url, {\n method: 'GET',\n headers: Object.assign({\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n }, replicationState.headers),\n });\n const data = await parseResponse(replicationState, response);\n return {\n documents: data.documents,\n checkpoint: data.checkpoint\n };\n },\n batchSize: ensureNotFalsy(options.pull).batchSize,\n modifier: ensureNotFalsy(options.pull).modifier,\n stream$: pullStream$.asObservable()\n };\n }\n\n let replicationPrimitivesPush: ReplicationPushOptions<RxDocType> | undefined;\n if (options.push) {\n replicationPrimitivesPush = {\n async handler(changeRows) {\n const response = await fetch(options.url + '/push', {\n method: 'POST',\n headers: Object.assign({\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n }, replicationState.headers),\n body: JSON.stringify(changeRows)\n });\n const conflictsArray = await parseResponse(replicationState, response);\n return conflictsArray;\n },\n batchSize: options.push.batchSize,\n modifier: options.push.modifier\n };\n }\n\n const replicationState = new RxServerReplicationState<RxDocType>(\n options.replicationIdentifier,\n collection,\n replicationPrimitivesPull,\n replicationPrimitivesPush,\n options.live,\n options.retryTime,\n options.autoStart,\n options.headers\n );\n\n /**\n * Use long polling to get live changes for the pull.stream$\n */\n if (options.live && options.pull) {\n const startBefore = replicationState.start.bind(replicationState);\n replicationState.start = async () => {\n const useEventSource: typeof EventSource = options.eventSource ? options.eventSource : EventSource;\n let eventSource: EventSource;\n const refreshEventSource = () => {\n eventSource = new useEventSource(options.url + '/pullStream', {\n withCredentials: true,\n /**\n * Sending headers is not supported by the Browser EventSource API,\n * only by the npm module we use. In react-native you might have\n * to set another EventSource implementation.\n * @link https://www.npmjs.com/package/eventsource\n */\n headers: replicationState.headers\n });\n // TODO check for 426 errors and handle them\n eventSource.onerror = (err) => {\n if (err.status === 401) {\n replicationState.unauthorized$.next();\n eventSource.close();\n promiseWait(replicationState.retryTime).then(() => refreshEventSource());\n } else {\n pullStream$.next('RESYNC');\n }\n };\n eventSource.onopen = (x) => {\n pullStream$.next('RESYNC');\n }\n eventSource.onmessage = event => {\n const eventData: { documents: WithDeletedAndAttachments<RxDocType>[]; checkpoint: RxServerCheckpoint; } = JSON.parse(event.data);\n pullStream$.next({\n documents: eventData.documents,\n checkpoint: eventData.checkpoint\n });\n };\n }\n refreshEventSource();\n\n replicationState.onCancel.push(() => eventSource && eventSource.close());\n return startBefore();\n };\n }\n\n startReplicationOnLeaderShip(options.waitForLeadership, replicationState);\n\n return replicationState;\n}\n"],"mappings":";AAAA,SACIA,cAAc,EACdC,SAAS,EACTC,WAAW,EAMXC,WAAW,EACXC,UAAU,QAEP,mBAAmB;AAC1B,SAASC,wBAAwB,QAAQ,8BAA8B;AACvE,SACIC,kBAAkB,EAClBC,4BAA4B,QACzB,0BAA0B;AAEjC,SAASC,OAAO,QAAQ,MAAM;AAK9B,SAASC,aAAa,QAAQ,cAAc;AAC5C,OAAOC,WAAW,MAAM,aAAa;AAErC,cAAc,YAAY;AAE1B,WAAaC,wBAAwB,0BAAAC,mBAAA;EAKjC,SAAAD,yBACoBE,qBAA6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,CAAC,QAAQ,CAAC;UAC9B;QACJ,CAAC;QACDN,WAAW,CAACS,MAAM,GAAIC,CAAC,IAAK;UACxBxC,WAAW,CAACoC,IAAI,CAAC,QAAQ,CAAC;QAC9B,CAAC;QACDN,WAAW,CAACW,SAAS,GAAGC,KAAK,IAAI;UAC7B,IAAMC,SAAiG,GAAGpB,IAAI,CAACqB,KAAK,CAACF,KAAK,CAAC5B,IAAI,CAAC;UAChId,WAAW,CAACoC,IAAI,CAAC;YACbrB,SAAS,EAAE4B,SAAS,CAAC5B,SAAS;YAC9BC,UAAU,EAAE2B,SAAS,CAAC3B;UAC1B,CAAC,CAAC;QACN,CAAC;MACL,CAAC;MACDe,kBAAkB,CAAC,CAAC;MAEpBlB,gBAAgB,CAACxB,QAAQ,CAACV,IAAI,CAAC,MAAMmD,WAAW,IAAIA,WAAW,CAACO,KAAK,CAAC,CAAC,CAAC;MACxE,OAAOX,WAAW,CAAC,CAAC;IACxB,CAAC;EACL;EAEAxD,4BAA4B,CAAC0B,OAAO,CAACG,iBAAiB,EAAEc,gBAAgB,CAAC;EAEzE,OAAOA,gBAAgB;AAC3B","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"rx-server.js","names":["RxServerReplicationEndpoint","RxServerRestEndpoint","RxServer","options","authHandler","serverApp","cors","endpoints","closeFn","close","bind","database","adapter","onDestroy","push","_proto","prototype","ensureNotStarted","listenPromise","Error","addReplicationEndpoint","opts","endpoint","name","collection","queryModifier","_a","q","changeValidator","serverOnlyFields","addRestEndpoint","start","hostname","listen","port","filter","fn"],"sources":["../../../../src/plugins/server/rx-server.ts"],"sourcesContent":["import type {\n RxCollection,\n RxDatabase\n} from 'rxdb/plugins/core';\nimport { RxServerReplicationEndpoint } from './endpoint-replication.ts';\nimport type {\n RxServerAdapter,\n RxServerAuthHandler,\n RxServerChangeValidator,\n RxServerEndpoint,\n RxServerOptions,\n RxServerQueryModifier\n} from './types.ts';\nimport { RxServerRestEndpoint } from './endpoint-rest.ts';\n\nexport class RxServer<ServerAppType, AuthType> {\n public readonly endpoints: RxServerEndpoint<AuthType, any>[] = [];\n\n private closeFn = (() => this.close()).bind(this);\n public listenPromise?: Promise<void>;\n\n public readonly database: RxDatabase;\n public readonly adapter: RxServerAdapter<ServerAppType>;\n\n constructor(\n public readonly options: RxServerOptions<ServerAppType, AuthType>,\n public readonly authHandler: RxServerAuthHandler<AuthType>,\n public readonly serverApp: ServerAppType,\n public readonly cors: string = '*'\n ) {\n this.database = options.database;\n this.adapter = options.adapter;\n options.database.onDestroy.push(this.closeFn);\n }\n\n private ensureNotStarted() {\n if (this.listenPromise) {\n throw new Error('This operation cannot be run after the RxServer has been started already');\n }\n\n }\n\n public addReplicationEndpoint<RxDocType>(opts: {\n name: string,\n collection: RxCollection<RxDocType>,\n queryModifier?: RxServerQueryModifier<AuthType, RxDocType>,\n changeValidator?: RxServerChangeValidator<AuthType, RxDocType>,\n /**\n * Set a origin for allowed CORS requests.\n * Overwrites the cors option of the server.\n * [default='*']\n */\n cors?: '*' | string,\n serverOnlyFields?: string[]\n }) {\n this.ensureNotStarted();\n const endpoint = new RxServerReplicationEndpoint(\n this,\n opts.name,\n opts.collection,\n opts.queryModifier ? opts.queryModifier : (_a, q) => q,\n opts.changeValidator ? opts.changeValidator : () => true,\n opts.serverOnlyFields ? opts.serverOnlyFields : [],\n opts.cors\n );\n this.endpoints.push(endpoint);\n return endpoint;\n }\n\n public addRestEndpoint<RxDocType>(opts: {\n name: string,\n collection: RxCollection<RxDocType>,\n queryModifier?: RxServerQueryModifier<AuthType, RxDocType>,\n changeValidator?: RxServerChangeValidator<AuthType, RxDocType>,\n /**\n * Set a origin for allowed CORS requests.\n * Overwrites the cors option of the server.\n * [default='*']\n */\n cors?: '*' | string,\n serverOnlyFields?: string[]\n }) {\n this.ensureNotStarted();\n const endpoint = new RxServerRestEndpoint(\n this,\n opts.name,\n opts.collection,\n opts.queryModifier ? opts.queryModifier : (_a, q) => q,\n opts.changeValidator ? opts.changeValidator : () => true,\n opts.serverOnlyFields ? opts.serverOnlyFields : [],\n opts.cors\n );\n this.endpoints.push(endpoint);\n return endpoint;\n }\n\n async start() {\n this.ensureNotStarted();\n const hostname = this.options.hostname ? this.options.hostname : 'localhost';\n this.listenPromise = this.options.adapter.listen(this.serverApp, this.options.port, hostname);\n return this.listenPromise;\n }\n\n async close() {\n this.database.onDestroy = this.database.onDestroy.filter(fn => fn !== this.closeFn);\n if (this.listenPromise) {\n await this.listenPromise;\n await this.options.adapter.close(this.serverApp);\n }\n }\n}\n"],"mappings":"AAIA,SAASA,2BAA2B,QAAQ,2BAA2B;AASvE,SAASC,oBAAoB,QAAQ,oBAAoB;AAEzD,WAAaC,QAAQ;EASjB,SAAAA,SACoBC,OAAiD,EACjDC,WAA0C,EAC1CC,SAAwB,EACxBC,IAAY,GAAG,GAAG,EACpC;IAAA,KAbcC,SAAS,GAAsC,EAAE;IAAA,KAEzDC,OAAO,GAAG,CAAC,MAAM,IAAI,CAACC,KAAK,CAAC,CAAC,EAAEC,IAAI,CAAC,IAAI,CAAC;IAAA,KAO7BP,OAAiD,GAAjDA,OAAiD;IAAA,KACjDC,WAA0C,GAA1CA,WAA0C;IAAA,KAC1CC,SAAwB,GAAxBA,SAAwB;IAAA,KACxBC,IAAY,GAAZA,IAAY;IAE5B,IAAI,CAACK,QAAQ,GAAGR,OAAO,CAACQ,QAAQ;IAChC,IAAI,CAACC,OAAO,GAAGT,OAAO,CAACS,OAAO;IAC9BT,OAAO,CAACQ,QAAQ,CAACE,SAAS,CAACC,IAAI,CAAC,IAAI,CAACN,OAAO,CAAC;EACjD;EAAC,IAAAO,MAAA,GAAAb,QAAA,CAAAc,SAAA;EAAAD,MAAA,CAEOE,gBAAgB,GAAxB,SAAAA,iBAAA,EAA2B;IACvB,IAAI,IAAI,CAACC,aAAa,EAAE;MACpB,MAAM,IAAIC,KAAK,CAAC,0EAA0E,CAAC;IAC/F;EAEJ,CAAC;EAAAJ,MAAA,CAEMK,sBAAsB,GA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6B,QAAQ,GAAG,IAAI,CAAC7B,OAAO,CAAC6B,QAAQ,GAAG,WAAW;IAC5E,IAAI,CAACd,aAAa,GAAG,IAAI,CAACf,OAAO,CAACS,OAAO,CAACqB,MAAM,CAAC,IAAI,CAAC5B,SAAS,EAAE,IAAI,CAACF,OAAO,CAAC+B,IAAI,EAAEF,QAAQ,CAAC;IAC7F,OAAO,IAAI,CAACd,aAAa;EAC7B,CAAC;EAAAH,MAAA,CAEKN,KAAK,GAAX,eAAAA,MAAA,EAAc;IACV,IAAI,CAACE,QAAQ,CAACE,SAAS,GAAG,IAAI,CAACF,QAAQ,CAACE,SAAS,CAACsB,MAAM,CAACC,EAAE,IAAIA,EAAE,KAAK,IAAI,CAAC5B,OAAO,CAAC;IACnF,IAAI,IAAI,CAACU,aAAa,EAAE;MACpB,MAAM,IAAI,CAACA,aAAa;MACxB,MAAM,IAAI,CAACf,OAAO,CAACS,OAAO,CAACH,KAAK,CAAC,IAAI,CAACJ,SAAS,CAAC;IACpD;EACJ,CAAC;EAAA,OAAAH,QAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"rx-server.js","names":["RxServerReplicationEndpoint","RxServerRestEndpoint","RxServer","options","authHandler","serverApp","cors","endpoints","closeFn","close","bind","database","adapter","onDestroy","push","_proto","prototype","ensureNotStarted","listenPromise","Error","addReplicationEndpoint","opts","endpoint","name","collection","queryModifier","_a","q","changeValidator","serverOnlyFields","addRestEndpoint","start","hostname","listen","port","filter","fn"],"sources":["../../../../src/plugins/server/rx-server.ts"],"sourcesContent":["import type {\n RxCollection,\n RxDatabase\n} from 'rxdb/plugins/core';\nimport { RxServerReplicationEndpoint } from './endpoint-replication.ts';\nimport type {\n RxServerAdapter,\n RxServerAuthHandler,\n RxServerChangeValidator,\n RxServerEndpoint,\n RxServerOptions,\n RxServerQueryModifier\n} from './types.ts';\nimport { RxServerRestEndpoint } from './endpoint-rest.ts';\n\nexport class RxServer<ServerAppType, AuthType> {\n public readonly endpoints: RxServerEndpoint<AuthType, any>[] = [];\n\n private closeFn = (() => this.close()).bind(this);\n public listenPromise?: Promise<void>;\n\n public readonly database: RxDatabase;\n public readonly adapter: RxServerAdapter<ServerAppType>;\n\n constructor(\n public readonly options: RxServerOptions<ServerAppType, AuthType>,\n public readonly authHandler: RxServerAuthHandler<AuthType>,\n public readonly serverApp: ServerAppType,\n public readonly cors: string = '*'\n ) {\n this.database = options.database;\n this.adapter = options.adapter;\n options.database.onDestroy.push(this.closeFn);\n }\n\n private ensureNotStarted() {\n if (this.listenPromise) {\n throw new Error('This operation cannot be run after the RxServer has been started already');\n }\n\n }\n\n public addReplicationEndpoint<RxDocType>(opts: {\n name: string,\n collection: RxCollection<RxDocType>,\n queryModifier?: RxServerQueryModifier<AuthType, RxDocType>,\n changeValidator?: RxServerChangeValidator<AuthType, RxDocType>,\n /**\n * Set a origin for allowed CORS requests.\n * Overwrites the cors option of the server.\n * [default='*']\n */\n cors?: '*' | string,\n serverOnlyFields?: string[]\n }) {\n this.ensureNotStarted();\n const endpoint = new RxServerReplicationEndpoint(\n this,\n opts.name,\n opts.collection,\n opts.queryModifier ? opts.queryModifier : (_a, q) => q,\n opts.changeValidator ? opts.changeValidator : () => true,\n opts.serverOnlyFields ? opts.serverOnlyFields : [],\n opts.cors\n );\n this.endpoints.push(endpoint);\n return endpoint;\n }\n\n public addRestEndpoint<RxDocType>(opts: {\n name: string,\n collection: RxCollection<RxDocType>,\n queryModifier?: RxServerQueryModifier<AuthType, RxDocType>,\n changeValidator?: RxServerChangeValidator<AuthType, RxDocType>,\n /**\n * Set a origin for allowed CORS requests.\n * Overwrites the cors option of the server.\n * [default='*']\n */\n cors?: '*' | string,\n serverOnlyFields?: string[]\n }) {\n this.ensureNotStarted();\n const endpoint = new RxServerRestEndpoint(\n this,\n opts.name,\n opts.collection,\n opts.queryModifier ? opts.queryModifier : (_a, q) => q,\n opts.changeValidator ? opts.changeValidator : () => true,\n opts.serverOnlyFields ? opts.serverOnlyFields : [],\n opts.cors\n );\n this.endpoints.push(endpoint);\n return endpoint;\n }\n\n async start() {\n this.ensureNotStarted();\n const hostname = this.options.hostname ? this.options.hostname : 'localhost';\n this.listenPromise = this.options.adapter.listen(this.serverApp, this.options.port, hostname);\n return this.listenPromise;\n }\n\n async close() {\n this.database.onDestroy = this.database.onDestroy.filter(fn => fn !== this.closeFn);\n if (this.listenPromise) {\n await this.listenPromise;\n await this.options.adapter.close(this.serverApp);\n }\n }\n}\n"],"mappings":"AAIA,SAASA,2BAA2B,QAAQ,2BAA2B;AASvE,SAASC,oBAAoB,QAAQ,oBAAoB;AAEzD,WAAaC,QAAQ;EASjB,SAAAA,SACoBC,OAAiD,EACjDC,WAA0C,EAC1CC,SAAwB,EACxBC,IAAY,GAAG,GAAG,EACpC;IAAA,KAbcC,SAAS,GAAsC,EAAE;IAAA,KAEzDC,OAAO,GAAG,CAAC,MAAM,IAAI,CAACC,KAAK,CAAC,CAAC,EAAEC,IAAI,CAAC,IAAI,CAAC;IAAA,KAO7BP,OAAiD,GAAjDA,OAAiD;IAAA,KACjDC,WAA0C,GAA1CA,WAA0C;IAAA,KAC1CC,SAAwB,GAAxBA,SAAwB;IAAA,KACxBC,IAAY,GAAZA,IAAY;IAE5B,IAAI,CAACK,QAAQ,GAAGR,OAAO,CAACQ,QAAQ;IAChC,IAAI,CAACC,OAAO,GAAGT,OAAO,CAACS,OAAO;IAC9BT,OAAO,CAACQ,QAAQ,CAACE,SAAS,CAACC,IAAI,CAAC,IAAI,CAACN,OAAO,CAAC;EACjD;EAAC,IAAAO,MAAA,GAAAb,QAAA,CAAAc,SAAA;EAAAD,MAAA,CAEOE,gBAAgB,GAAxB,SAAQA,gBAAgBA,CAAA,EAAG;IACvB,IAAI,IAAI,CAACC,aAAa,EAAE;MACpB,MAAM,IAAIC,KAAK,CAAC,0EAA0E,CAAC;IAC/F;EAEJ,CAAC;EAAAJ,MAAA,CAEMK,sBAAsB,GAA7B,SAAOA,sBAAsBA,CAAYC,IAYxC,EAAE;IACC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C7B,OAAO,CAAC6B,QAAQ,GAAG,WAAW;IAC5E,IAAI,CAACd,aAAa,GAAG,IAAI,CAACf,OAAO,CAACS,OAAO,CAACqB,MAAM,CAAC,IAAI,CAAC5B,SAAS,EAAE,IAAI,CAACF,OAAO,CAAC+B,IAAI,EAAEF,QAAQ,CAAC;IAC7F,OAAO,IAAI,CAACd,aAAa;EAC7B,CAAC;EAAAH,MAAA,CAEKN,KAAK,GAAX,eAAMA,KAAKA,CAAA,EAAG;IACV,IAAI,CAACE,QAAQ,CAACE,SAAS,GAAG,IAAI,CAACF,QAAQ,CAACE,SAAS,CAACsB,MAAM,CAACC,EAAE,IAAIA,EAAE,KAAK,IAAI,CAAC5B,OAAO,CAAC;IACnF,IAAI,IAAI,CAACU,aAAa,EAAE;MACpB,MAAM,IAAI,CAACA,aAAa;MACxB,MAAM,IAAI,CAACf,OAAO,CAACS,OAAO,CAACH,KAAK,CAAC,IAAI,CAACJ,SAAS,CAAC;IACpD;EACJ,CAAC;EAAA,OAAAH,QAAA;AAAA","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rxdb-server",
3
- "version": "15.28.1",
3
+ "version": "15.29.0",
4
4
  "description": "RxDB Server Plugin",
5
5
  "license": "SSPL",
6
6
  "author": "pubkey",
@@ -100,14 +100,14 @@
100
100
  "@babel/plugin-transform-runtime": "7.24.7",
101
101
  "@babel/plugin-transform-spread": "7.24.7",
102
102
  "@babel/plugin-transform-template-literals": "7.24.7",
103
- "@babel/plugin-transform-typescript": "7.24.8",
103
+ "@babel/plugin-transform-typescript": "7.25.0",
104
104
  "@babel/polyfill": "7.12.1",
105
- "@babel/preset-env": "7.24.8",
105
+ "@babel/preset-env": "7.25.0",
106
106
  "@babel/preset-typescript": "7.24.7",
107
- "@babel/types": "7.24.9",
107
+ "@babel/types": "7.25.0",
108
108
  "@faker-js/faker": "8.4.1",
109
109
  "@types/mocha": "10.0.7",
110
- "@types/node": "20.14.11",
110
+ "@types/node": "20.14.13",
111
111
  "@types/sqlite3": "3.1.11",
112
112
  "@types/websql": "0.0.30",
113
113
  "babel-loader": "9.1.3",
@@ -129,14 +129,14 @@
129
129
  "karma-webpack": "5.0.1",
130
130
  "mini-css-extract-plugin": "2.9.0",
131
131
  "minify-all-js": "0.1.9",
132
- "mocha": "10.6.0",
132
+ "mocha": "10.7.0",
133
133
  "rimraf": "6.0.1",
134
- "rxdb": "15.28.1",
134
+ "rxdb": "15.29.0",
135
135
  "rxjs": "7.8.1",
136
136
  "ts-loader": "9.5.1",
137
137
  "ts-mocha": "10.0.0",
138
138
  "ts-node": "10.9.2",
139
- "typescript": "5.5.3",
139
+ "typescript": "5.5.4",
140
140
  "webpack": "5.93.0",
141
141
  "webpack-bundle-analyzer": "4.10.2",
142
142
  "webpack-cli": "5.1.4",