From 3758427067bf20fbf47acea76d49ab49190e7e03 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 15:36:32 +0000 Subject: [PATCH] 16.0.0-beta.10 --- CHANGELOG.md | 2 +- dist/cjs/plugins/utils/utils-rxdb-version.js | 2 +- dist/cjs/plugins/utils/utils-rxdb-version.js.map | 2 +- dist/cjs/replication-protocol/downstream.js | 10 ++++++++-- dist/cjs/replication-protocol/downstream.js.map | 2 +- dist/esm/plugins/utils/utils-rxdb-version.js | 2 +- dist/esm/plugins/utils/utils-rxdb-version.js.map | 2 +- dist/esm/replication-protocol/downstream.js | 10 ++++++++-- dist/esm/replication-protocol/downstream.js.map | 2 +- dist/types/plugins/storage-denokv/index.d.ts | 2 +- dist/types/plugins/storage-dexie/rx-storage-dexie.d.ts | 2 +- .../plugins/storage-mongodb/rx-storage-mongodb.d.ts | 2 +- .../plugins/storage-remote/rx-storage-remote.d.ts | 2 +- dist/types/plugins/utils/utils-rxdb-version.d.ts | 2 +- dist/types/rx-database.d.ts | 2 +- package.json | 2 +- src/plugins/utils/utils-rxdb-version.ts | 2 +- 17 files changed, 31 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26ff06f0c6c..6be2c9a52c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ -### 16.0.0-beta.9 (10 December 2024) +### 16.0.0-beta.10 (16 December 2024) 🚀 **RxDB v16 is released** diff --git a/dist/cjs/plugins/utils/utils-rxdb-version.js b/dist/cjs/plugins/utils/utils-rxdb-version.js index 85ae05bd8ee..38168ba5261 100644 --- a/dist/cjs/plugins/utils/utils-rxdb-version.js +++ b/dist/cjs/plugins/utils/utils-rxdb-version.js @@ -7,5 +7,5 @@ exports.RXDB_VERSION = void 0; /** * This file is replaced in the 'npm run build:version' script. */ -var RXDB_VERSION = exports.RXDB_VERSION = '16.0.0-beta.9'; +var RXDB_VERSION = exports.RXDB_VERSION = '16.0.0-beta.10'; //# sourceMappingURL=utils-rxdb-version.js.map \ No newline at end of file diff --git a/dist/cjs/plugins/utils/utils-rxdb-version.js.map b/dist/cjs/plugins/utils/utils-rxdb-version.js.map index ce8bb8da704..38a1c08614d 100644 --- a/dist/cjs/plugins/utils/utils-rxdb-version.js.map +++ b/dist/cjs/plugins/utils/utils-rxdb-version.js.map @@ -1 +1 @@ -{"version":3,"file":"utils-rxdb-version.js","names":["RXDB_VERSION","exports"],"sources":["../../../../src/plugins/utils/utils-rxdb-version.ts"],"sourcesContent":["/**\n * This file is replaced in the 'npm run build:version' script.\n */\nexport const RXDB_VERSION = '16.0.0-beta.9';\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACO,IAAMA,YAAY,GAAAC,OAAA,CAAAD,YAAA,GAAG,eAAe","ignoreList":[]} \ No newline at end of file +{"version":3,"file":"utils-rxdb-version.js","names":["RXDB_VERSION","exports"],"sources":["../../../../src/plugins/utils/utils-rxdb-version.ts"],"sourcesContent":["/**\n * This file is replaced in the 'npm run build:version' script.\n */\nexport const RXDB_VERSION = '16.0.0-beta.10';\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACO,IAAMA,YAAY,GAAAC,OAAA,CAAAD,YAAA,GAAG,gBAAgB","ignoreList":[]} \ No newline at end of file diff --git a/dist/cjs/replication-protocol/downstream.js b/dist/cjs/replication-protocol/downstream.js index be326882ce9..a5e717d3213 100644 --- a/dist/cjs/replication-protocol/downstream.js +++ b/dist/cjs/replication-protocol/downstream.js @@ -284,6 +284,7 @@ async function startReplicationDownstream(state) { state.events.processed.down.next(writeRowsToForkById[docId]); useMetaWriteRows.push(writeRowsToMeta[docId]); }); + var mustThrow; forkWriteResult.error.forEach(error => { /** * We do not have to care about downstream conflict errors here @@ -293,10 +294,15 @@ async function startReplicationDownstream(state) { return; } // other non-conflict errors must be handled - state.events.error.next((0, _rxError.newRxError)('RC_PULL', { + var throwMe = (0, _rxError.newRxError)('RC_PULL', { writeError: error - })); + }); + state.events.error.next(throwMe); + mustThrow = mustThrow = throwMe; }); + if (mustThrow) { + throw mustThrow; + } }); } }).then(() => { diff --git a/dist/cjs/replication-protocol/downstream.js.map b/dist/cjs/replication-protocol/downstream.js.map index 92fb56d89ca..f160e623135 100644 --- a/dist/cjs/replication-protocol/downstream.js.map +++ b/dist/cjs/replication-protocol/downstream.js.map @@ -1 +1 @@ -{"version":3,"file":"downstream.js","names":["_rxjs","require","_rxError","_rxStorageHelper","_index","_checkpoint","_helper","_metaInstance","startReplicationDownstream","state","input","initialCheckpoint","downstream","checkpointDoc","getLastCheckpointDoc","setCheckpoint","identifierHash","hashFunction","identifier","replicationHandler","timer","openTasks","addNewTask","task","stats","down","taskWithTime","time","push","streamQueue","then","useTasks","length","events","active","next","innerTaskWithTime","ensureNotFalsy","shift","lastTimeMasterChangesRequested","downstreamResyncOnce","downstreamProcessChanges","firstSyncDone","getValue","canceled","sub","masterChangeStream$","pipe","mergeMap","ev","firstValueFrom","up","filter","s","subscribe","masterChangeStreamEmit","unsubscribe","checkpointQueue","lastCheckpoint","promises","downResult","masterChangesSince","pullBatchSize","documents","stackCheckpoints","checkpoint","persistFromMaster","Promise","all","tasks","docsOfAllTasks","forEach","Error","appendToArray","persistenceQueue","PROMISE_RESOLVE_VOID","nonPersistedFromMaster","docs","primaryPath","docData","docId","downDocsById","useCheckpoint","docIds","Object","keys","writeRowsToFork","writeRowsToForkById","writeRowsToMeta","useMetaWriteRows","forkInstance","findDocumentsById","getAssumedMasterState","currentForkStateList","assumedMasterState","currentForkState","Map","doc","set","map","forkStateFullDoc","get","forkStateDocData","writeDocToDocState","hasAttachments","undefined","masterState","assumedMaster","metaDocument","isResolvedConflict","_rev","isAssumedMasterEqualToForkState","conflictHandler","isEqual","_meta","getHeightOfRevision","areStatesExactlyEqual","getMetaWriteRow","newForkState","assign","flatClone","_attachments","getDefaultRevision","lwt","now","nextRevisionHeight","keepMeta","forkWriteRow","previous","document","createRevision","bulkWrite","downstreamBulkWriteFlag","forkWriteResult","success","getWrittenDocumentsFromBulkWriteResponse","processed","error","status","newRxError","writeError","metaInstance","stripAttachmentsDataFromMetaWriteRows","metaWriteResult","id","documentId","catch","unhandledError"],"sources":["../../../src/replication-protocol/downstream.ts"],"sourcesContent":["import {\n firstValueFrom,\n filter,\n mergeMap\n} from 'rxjs';\nimport { newRxError } from '../rx-error.ts';\nimport { getWrittenDocumentsFromBulkWriteResponse, stackCheckpoints } from '../rx-storage-helper.ts';\nimport type {\n RxStorageInstanceReplicationState,\n BulkWriteRow,\n BulkWriteRowById,\n RxStorageReplicationMeta,\n RxDocumentData,\n ById,\n WithDeleted,\n DocumentsWithCheckpoint,\n WithDeletedAndAttachments\n} from '../types/index.d.ts';\nimport {\n appendToArray,\n createRevision,\n ensureNotFalsy,\n flatClone,\n getDefaultRevision,\n getHeightOfRevision,\n now,\n PROMISE_RESOLVE_VOID\n} from '../plugins/utils/index.ts';\nimport {\n getLastCheckpointDoc,\n setCheckpoint\n} from './checkpoint.ts';\nimport {\n stripAttachmentsDataFromMetaWriteRows,\n writeDocToDocState\n} from './helper.ts';\nimport {\n getAssumedMasterState,\n getMetaWriteRow\n} from './meta-instance.ts';\n\n/**\n * Writes all documents from the master to the fork.\n * The downstream has two operation modes\n * - Sync by iterating over the checkpoints via downstreamResyncOnce()\n * - Sync by listening to the changestream via downstreamProcessChanges()\n * We need this to be able to do initial syncs\n * and still can have fast event based sync when the client is not offline.\n */\nexport async function startReplicationDownstream(\n state: RxStorageInstanceReplicationState\n) {\n if (\n state.input.initialCheckpoint &&\n state.input.initialCheckpoint.downstream\n ) {\n const checkpointDoc = await getLastCheckpointDoc(state, 'down');\n if (!checkpointDoc) {\n await setCheckpoint(\n state,\n 'down',\n state.input.initialCheckpoint.downstream\n );\n }\n }\n\n const identifierHash = await state.input.hashFunction(state.input.identifier);\n const replicationHandler = state.input.replicationHandler;\n\n // used to detect which tasks etc can in it at which order.\n let timer = 0;\n\n\n type Task = DocumentsWithCheckpoint | 'RESYNC';\n type TaskWithTime = {\n time: number;\n task: Task;\n };\n const openTasks: TaskWithTime[] = [];\n\n\n function addNewTask(task: Task): void {\n state.stats.down.addNewTask = state.stats.down.addNewTask + 1;\n const taskWithTime = {\n time: timer++,\n task\n };\n openTasks.push(taskWithTime);\n state.streamQueue.down = state.streamQueue.down\n .then(() => {\n const useTasks: Task[] = [];\n while (openTasks.length > 0) {\n state.events.active.down.next(true);\n const innerTaskWithTime = ensureNotFalsy(openTasks.shift());\n\n /**\n * If the task came in before the last time we started the pull\n * from the master, then we can drop the task.\n */\n if (innerTaskWithTime.time < lastTimeMasterChangesRequested) {\n continue;\n }\n\n if (innerTaskWithTime.task === 'RESYNC') {\n if (useTasks.length === 0) {\n useTasks.push(innerTaskWithTime.task);\n break;\n } else {\n break;\n }\n }\n\n useTasks.push(innerTaskWithTime.task);\n }\n if (useTasks.length === 0) {\n return;\n }\n\n if (useTasks[0] === 'RESYNC') {\n return downstreamResyncOnce();\n } else {\n return downstreamProcessChanges(useTasks);\n }\n }).then(() => {\n state.events.active.down.next(false);\n if (\n !state.firstSyncDone.down.getValue() &&\n !state.events.canceled.getValue()\n ) {\n state.firstSyncDone.down.next(true);\n }\n });\n }\n addNewTask('RESYNC');\n\n /**\n * If a write on the master happens, we have to trigger the downstream.\n * Only do this if not canceled yet, otherwise firstValueFrom errors\n * when running on a completed observable.\n */\n if (!state.events.canceled.getValue()) {\n const sub = replicationHandler\n .masterChangeStream$\n .pipe(\n mergeMap(async (ev) => {\n /**\n * While a push is running, we have to delay all incoming\n * events from the server to not mix up the replication state.\n */\n await firstValueFrom(\n state.events.active.up.pipe(filter(s => !s))\n );\n return ev;\n })\n )\n .subscribe((task: Task) => {\n state.stats.down.masterChangeStreamEmit = state.stats.down.masterChangeStreamEmit + 1;\n addNewTask(task);\n });\n firstValueFrom(\n state.events.canceled.pipe(\n filter(canceled => !!canceled)\n )\n ).then(() => sub.unsubscribe());\n }\n\n\n /**\n * For faster performance, we directly start each write\n * and then await all writes at the end.\n */\n let lastTimeMasterChangesRequested: number = -1;\n async function downstreamResyncOnce() {\n state.stats.down.downstreamResyncOnce = state.stats.down.downstreamResyncOnce + 1;\n if (state.events.canceled.getValue()) {\n return;\n }\n\n state.checkpointQueue = state.checkpointQueue.then(() => getLastCheckpointDoc(state, 'down'));\n let lastCheckpoint: CheckpointType = await state.checkpointQueue;\n\n\n const promises: Promise[] = [];\n while (!state.events.canceled.getValue()) {\n lastTimeMasterChangesRequested = timer++;\n const downResult = await replicationHandler.masterChangesSince(\n lastCheckpoint,\n state.input.pullBatchSize\n );\n\n if (downResult.documents.length === 0) {\n break;\n }\n\n lastCheckpoint = stackCheckpoints([lastCheckpoint, downResult.checkpoint]);\n\n promises.push(\n persistFromMaster(\n downResult.documents,\n lastCheckpoint\n )\n );\n\n /**\n * By definition we stop pull when the pulled documents\n * do not fill up the pullBatchSize because we\n * can assume that the remote has no more documents.\n */\n if (downResult.documents.length < state.input.pullBatchSize) {\n break;\n }\n\n }\n await Promise.all(promises);\n }\n\n\n function downstreamProcessChanges(tasks: Task[]) {\n state.stats.down.downstreamProcessChanges = state.stats.down.downstreamProcessChanges + 1;\n const docsOfAllTasks: WithDeleted[] = [];\n let lastCheckpoint: CheckpointType | undefined = null as any;\n\n tasks.forEach(task => {\n if (task === 'RESYNC') {\n throw new Error('SNH');\n }\n appendToArray(docsOfAllTasks, task.documents);\n lastCheckpoint = stackCheckpoints([lastCheckpoint, task.checkpoint]);\n });\n return persistFromMaster(\n docsOfAllTasks,\n ensureNotFalsy(lastCheckpoint)\n );\n }\n\n\n /**\n * It can happen that the calls to masterChangesSince() or the changeStream()\n * are way faster then how fast the documents can be persisted.\n * Therefore we merge all incoming downResults into the nonPersistedFromMaster object\n * and process them together if possible.\n * This often bundles up single writes and improves performance\n * by processing the documents in bulks.\n */\n let persistenceQueue = PROMISE_RESOLVE_VOID;\n const nonPersistedFromMaster: {\n checkpoint?: CheckpointType;\n docs: ById>;\n } = {\n docs: {}\n };\n\n function persistFromMaster(\n docs: WithDeleted[],\n checkpoint: CheckpointType\n ): Promise {\n const primaryPath = state.primaryPath;\n state.stats.down.persistFromMaster = state.stats.down.persistFromMaster + 1;\n\n /**\n * Add the new docs to the non-persistent list\n */\n docs.forEach(docData => {\n const docId: string = (docData as any)[primaryPath];\n nonPersistedFromMaster.docs[docId] = docData;\n });\n nonPersistedFromMaster.checkpoint = checkpoint;\n\n /**\n * Run in the queue\n * with all open documents from nonPersistedFromMaster.\n */\n persistenceQueue = persistenceQueue.then(() => {\n\n const downDocsById: ById> = nonPersistedFromMaster.docs;\n nonPersistedFromMaster.docs = {};\n const useCheckpoint = nonPersistedFromMaster.checkpoint;\n const docIds = Object.keys(downDocsById);\n\n if (\n state.events.canceled.getValue() ||\n docIds.length === 0\n ) {\n return PROMISE_RESOLVE_VOID;\n }\n\n const writeRowsToFork: BulkWriteRow[] = [];\n const writeRowsToForkById: ById> = {};\n const writeRowsToMeta: BulkWriteRowById> = {};\n const useMetaWriteRows: BulkWriteRow>[] = [];\n\n return Promise.all([\n state.input.forkInstance.findDocumentsById(docIds, true),\n getAssumedMasterState(\n state,\n docIds\n )\n ]).then(([\n currentForkStateList,\n assumedMasterState\n ]) => {\n const currentForkState = new Map>();\n currentForkStateList.forEach(doc => currentForkState.set((doc as any)[primaryPath], doc));\n return Promise.all(\n docIds.map(async (docId) => {\n const forkStateFullDoc: RxDocumentData | undefined = currentForkState.get(docId);\n const forkStateDocData: WithDeletedAndAttachments | undefined = forkStateFullDoc\n ? writeDocToDocState(forkStateFullDoc, state.hasAttachments, false)\n : undefined\n ;\n const masterState = downDocsById[docId];\n const assumedMaster = assumedMasterState[docId];\n\n if (\n assumedMaster &&\n forkStateFullDoc &&\n assumedMaster.metaDocument.isResolvedConflict === forkStateFullDoc._rev\n ) {\n /**\n * The current fork state represents a resolved conflict\n * that first must be send to the master in the upstream.\n * All conflicts are resolved by the upstream.\n */\n // return PROMISE_RESOLVE_VOID;\n await state.streamQueue.up;\n }\n\n let isAssumedMasterEqualToForkState = !assumedMaster || !forkStateDocData ?\n false :\n state.input.conflictHandler.isEqual(\n assumedMaster.docData,\n forkStateDocData,\n 'downstream-check-if-equal-0'\n );\n if (\n !isAssumedMasterEqualToForkState &&\n (\n assumedMaster &&\n (assumedMaster.docData as any)._rev &&\n forkStateFullDoc &&\n forkStateFullDoc._meta[state.input.identifier] &&\n getHeightOfRevision(forkStateFullDoc._rev) === forkStateFullDoc._meta[state.input.identifier]\n )\n ) {\n isAssumedMasterEqualToForkState = true;\n }\n if (\n (\n forkStateFullDoc &&\n assumedMaster &&\n isAssumedMasterEqualToForkState === false\n ) ||\n (\n forkStateFullDoc && !assumedMaster\n )\n ) {\n /**\n * We have a non-upstream-replicated\n * local write to the fork.\n * This means we ignore the downstream of this document\n * because anyway the upstream will first resolve the conflict.\n */\n return PROMISE_RESOLVE_VOID;\n }\n\n const areStatesExactlyEqual = !forkStateDocData\n ? false\n : state.input.conflictHandler.isEqual(\n masterState,\n forkStateDocData,\n 'downstream-check-if-equal-1'\n );\n if (\n forkStateDocData &&\n areStatesExactlyEqual\n ) {\n /**\n * Document states are exactly equal.\n * This can happen when the replication is shut down\n * unexpected like when the user goes offline.\n *\n * Only when the assumedMaster is different from the forkState,\n * we have to patch the document in the meta instance.\n */\n if (\n !assumedMaster ||\n isAssumedMasterEqualToForkState === false\n ) {\n useMetaWriteRows.push(\n await getMetaWriteRow(\n state,\n forkStateDocData,\n assumedMaster ? assumedMaster.metaDocument : undefined\n )\n );\n }\n return PROMISE_RESOLVE_VOID;\n }\n\n /**\n * All other master states need to be written to the forkInstance\n * and metaInstance.\n */\n const newForkState = Object.assign(\n {},\n masterState,\n forkStateFullDoc ? {\n _meta: flatClone(forkStateFullDoc._meta),\n _attachments: state.hasAttachments && masterState._attachments ? masterState._attachments : {},\n _rev: getDefaultRevision()\n } : {\n _meta: {\n lwt: now()\n },\n _rev: getDefaultRevision(),\n _attachments: state.hasAttachments && masterState._attachments ? masterState._attachments : {}\n }\n );\n /**\n * If the remote works with revisions,\n * we store the height of the next fork-state revision\n * inside of the documents meta data.\n * By doing so we can filter it out in the upstream\n * and detect the document as being equal to master or not.\n * This is used for example in the CouchDB replication plugin.\n */\n if ((masterState as any)._rev) {\n const nextRevisionHeight = !forkStateFullDoc ? 1 : getHeightOfRevision(forkStateFullDoc._rev) + 1;\n newForkState._meta[state.input.identifier] = nextRevisionHeight;\n if (state.input.keepMeta) {\n newForkState._rev = (masterState as any)._rev;\n }\n }\n if (\n state.input.keepMeta &&\n (masterState as any)._meta\n ) {\n newForkState._meta = (masterState as any)._meta;\n }\n\n const forkWriteRow = {\n previous: forkStateFullDoc,\n document: newForkState\n };\n\n forkWriteRow.document._rev = forkWriteRow.document._rev ? forkWriteRow.document._rev : createRevision(\n identifierHash,\n forkWriteRow.previous\n );\n writeRowsToFork.push(forkWriteRow);\n writeRowsToForkById[docId] = forkWriteRow;\n writeRowsToMeta[docId] = await getMetaWriteRow(\n state,\n masterState,\n assumedMaster ? assumedMaster.metaDocument : undefined\n );\n })\n );\n }).then(async () => {\n if (writeRowsToFork.length > 0) {\n return state.input.forkInstance.bulkWrite(\n writeRowsToFork,\n await state.downstreamBulkWriteFlag\n ).then((forkWriteResult) => {\n const success = getWrittenDocumentsFromBulkWriteResponse(\n state.primaryPath,\n writeRowsToFork,\n forkWriteResult\n );\n success.forEach(doc => {\n const docId = (doc as any)[primaryPath];\n state.events.processed.down.next(writeRowsToForkById[docId]);\n useMetaWriteRows.push(writeRowsToMeta[docId]);\n });\n forkWriteResult.error.forEach(error => {\n /**\n * We do not have to care about downstream conflict errors here\n * because on conflict, it will be solved locally and result in another write.\n */\n if (error.status === 409) {\n return;\n }\n // other non-conflict errors must be handled\n state.events.error.next(newRxError('RC_PULL', {\n writeError: error\n }));\n });\n });\n }\n }).then(() => {\n if (useMetaWriteRows.length > 0) {\n return state.input.metaInstance.bulkWrite(\n stripAttachmentsDataFromMetaWriteRows(state, useMetaWriteRows),\n 'replication-down-write-meta'\n ).then(metaWriteResult => {\n metaWriteResult.error\n .forEach(writeError => {\n state.events.error.next(newRxError('RC_PULL', {\n id: writeError.documentId,\n writeError\n }));\n });\n });\n }\n }).then(() => {\n /**\n * For better performance we do not await checkpoint writes,\n * but to ensure order on parallel checkpoint writes,\n * we have to use a queue.\n */\n setCheckpoint(\n state,\n 'down',\n useCheckpoint\n );\n });\n }).catch(unhandledError => state.events.error.next(unhandledError));\n return persistenceQueue;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AAYA,IAAAG,MAAA,GAAAH,OAAA;AAUA,IAAAI,WAAA,GAAAJ,OAAA;AAIA,IAAAK,OAAA,GAAAL,OAAA;AAIA,IAAAM,aAAA,GAAAN,OAAA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeO,0BAA0BA,CAC5CC,KAAmD,EACrD;EACE,IACIA,KAAK,CAACC,KAAK,CAACC,iBAAiB,IAC7BF,KAAK,CAACC,KAAK,CAACC,iBAAiB,CAACC,UAAU,EAC1C;IACE,IAAMC,aAAa,GAAG,MAAM,IAAAC,gCAAoB,EAACL,KAAK,EAAE,MAAM,CAAC;IAC/D,IAAI,CAACI,aAAa,EAAE;MAChB,MAAM,IAAAE,yBAAa,EACfN,KAAK,EACL,MAAM,EACNA,KAAK,CAACC,KAAK,CAACC,iBAAiB,CAACC,UAClC,CAAC;IACL;EACJ;EAEA,IAAMI,cAAc,GAAG,MAAMP,KAAK,CAACC,KAAK,CAACO,YAAY,CAACR,KAAK,CAACC,KAAK,CAACQ,UAAU,CAAC;EAC7E,IAAMC,kBAAkB,GAAGV,KAAK,CAACC,KAAK,CAACS,kBAAkB;;EAEzD;EACA,IAAIC,KAAK,GAAG,CAAC;EAQb,IAAMC,SAAyB,GAAG,EAAE;EAGpC,SAASC,UAAUA,CAACC,IAAU,EAAQ;IAClC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G,IAAI,CAACgH,cAAc,CAAC,CAAC;IACnE,OAAOzE,gBAAgB;EAC3B;AACJ","ignoreList":[]} \ No newline at end of file +{"version":3,"file":"downstream.js","names":["_rxjs","require","_rxError","_rxStorageHelper","_index","_checkpoint","_helper","_metaInstance","startReplicationDownstream","state","input","initialCheckpoint","downstream","checkpointDoc","getLastCheckpointDoc","setCheckpoint","identifierHash","hashFunction","identifier","replicationHandler","timer","openTasks","addNewTask","task","stats","down","taskWithTime","time","push","streamQueue","then","useTasks","length","events","active","next","innerTaskWithTime","ensureNotFalsy","shift","lastTimeMasterChangesRequested","downstreamResyncOnce","downstreamProcessChanges","firstSyncDone","getValue","canceled","sub","masterChangeStream$","pipe","mergeMap","ev","firstValueFrom","up","filter","s","subscribe","masterChangeStreamEmit","unsubscribe","checkpointQueue","lastCheckpoint","promises","downResult","masterChangesSince","pullBatchSize","documents","stackCheckpoints","checkpoint","persistFromMaster","Promise","all","tasks","docsOfAllTasks","forEach","Error","appendToArray","persistenceQueue","PROMISE_RESOLVE_VOID","nonPersistedFromMaster","docs","primaryPath","docData","docId","downDocsById","useCheckpoint","docIds","Object","keys","writeRowsToFork","writeRowsToForkById","writeRowsToMeta","useMetaWriteRows","forkInstance","findDocumentsById","getAssumedMasterState","currentForkStateList","assumedMasterState","currentForkState","Map","doc","set","map","forkStateFullDoc","get","forkStateDocData","writeDocToDocState","hasAttachments","undefined","masterState","assumedMaster","metaDocument","isResolvedConflict","_rev","isAssumedMasterEqualToForkState","conflictHandler","isEqual","_meta","getHeightOfRevision","areStatesExactlyEqual","getMetaWriteRow","newForkState","assign","flatClone","_attachments","getDefaultRevision","lwt","now","nextRevisionHeight","keepMeta","forkWriteRow","previous","document","createRevision","bulkWrite","downstreamBulkWriteFlag","forkWriteResult","success","getWrittenDocumentsFromBulkWriteResponse","processed","mustThrow","error","status","throwMe","newRxError","writeError","metaInstance","stripAttachmentsDataFromMetaWriteRows","metaWriteResult","id","documentId","catch","unhandledError"],"sources":["../../../src/replication-protocol/downstream.ts"],"sourcesContent":["import {\n firstValueFrom,\n filter,\n mergeMap\n} from 'rxjs';\nimport { newRxError } from '../rx-error.ts';\nimport { getWrittenDocumentsFromBulkWriteResponse, stackCheckpoints } from '../rx-storage-helper.ts';\nimport type {\n RxStorageInstanceReplicationState,\n BulkWriteRow,\n BulkWriteRowById,\n RxStorageReplicationMeta,\n RxDocumentData,\n ById,\n WithDeleted,\n DocumentsWithCheckpoint,\n WithDeletedAndAttachments,\n RxError\n} from '../types/index.d.ts';\nimport {\n appendToArray,\n createRevision,\n ensureNotFalsy,\n flatClone,\n getDefaultRevision,\n getHeightOfRevision,\n now,\n PROMISE_RESOLVE_VOID\n} from '../plugins/utils/index.ts';\nimport {\n getLastCheckpointDoc,\n setCheckpoint\n} from './checkpoint.ts';\nimport {\n stripAttachmentsDataFromMetaWriteRows,\n writeDocToDocState\n} from './helper.ts';\nimport {\n getAssumedMasterState,\n getMetaWriteRow\n} from './meta-instance.ts';\n\n/**\n * Writes all documents from the master to the fork.\n * The downstream has two operation modes\n * - Sync by iterating over the checkpoints via downstreamResyncOnce()\n * - Sync by listening to the changestream via downstreamProcessChanges()\n * We need this to be able to do initial syncs\n * and still can have fast event based sync when the client is not offline.\n */\nexport async function startReplicationDownstream(\n state: RxStorageInstanceReplicationState\n) {\n if (\n state.input.initialCheckpoint &&\n state.input.initialCheckpoint.downstream\n ) {\n const checkpointDoc = await getLastCheckpointDoc(state, 'down');\n if (!checkpointDoc) {\n await setCheckpoint(\n state,\n 'down',\n state.input.initialCheckpoint.downstream\n );\n }\n }\n\n const identifierHash = await state.input.hashFunction(state.input.identifier);\n const replicationHandler = state.input.replicationHandler;\n\n // used to detect which tasks etc can in it at which order.\n let timer = 0;\n\n\n type Task = DocumentsWithCheckpoint | 'RESYNC';\n type TaskWithTime = {\n time: number;\n task: Task;\n };\n const openTasks: TaskWithTime[] = [];\n\n\n function addNewTask(task: Task): void {\n state.stats.down.addNewTask = state.stats.down.addNewTask + 1;\n const taskWithTime = {\n time: timer++,\n task\n };\n openTasks.push(taskWithTime);\n state.streamQueue.down = state.streamQueue.down\n .then(() => {\n const useTasks: Task[] = [];\n while (openTasks.length > 0) {\n state.events.active.down.next(true);\n const innerTaskWithTime = ensureNotFalsy(openTasks.shift());\n\n /**\n * If the task came in before the last time we started the pull\n * from the master, then we can drop the task.\n */\n if (innerTaskWithTime.time < lastTimeMasterChangesRequested) {\n continue;\n }\n\n if (innerTaskWithTime.task === 'RESYNC') {\n if (useTasks.length === 0) {\n useTasks.push(innerTaskWithTime.task);\n break;\n } else {\n break;\n }\n }\n\n useTasks.push(innerTaskWithTime.task);\n }\n if (useTasks.length === 0) {\n return;\n }\n\n if (useTasks[0] === 'RESYNC') {\n return downstreamResyncOnce();\n } else {\n return downstreamProcessChanges(useTasks);\n }\n }).then(() => {\n state.events.active.down.next(false);\n if (\n !state.firstSyncDone.down.getValue() &&\n !state.events.canceled.getValue()\n ) {\n state.firstSyncDone.down.next(true);\n }\n });\n }\n addNewTask('RESYNC');\n\n /**\n * If a write on the master happens, we have to trigger the downstream.\n * Only do this if not canceled yet, otherwise firstValueFrom errors\n * when running on a completed observable.\n */\n if (!state.events.canceled.getValue()) {\n const sub = replicationHandler\n .masterChangeStream$\n .pipe(\n mergeMap(async (ev) => {\n /**\n * While a push is running, we have to delay all incoming\n * events from the server to not mix up the replication state.\n */\n await firstValueFrom(\n state.events.active.up.pipe(filter(s => !s))\n );\n return ev;\n })\n )\n .subscribe((task: Task) => {\n state.stats.down.masterChangeStreamEmit = state.stats.down.masterChangeStreamEmit + 1;\n addNewTask(task);\n });\n firstValueFrom(\n state.events.canceled.pipe(\n filter(canceled => !!canceled)\n )\n ).then(() => sub.unsubscribe());\n }\n\n\n /**\n * For faster performance, we directly start each write\n * and then await all writes at the end.\n */\n let lastTimeMasterChangesRequested: number = -1;\n async function downstreamResyncOnce() {\n state.stats.down.downstreamResyncOnce = state.stats.down.downstreamResyncOnce + 1;\n if (state.events.canceled.getValue()) {\n return;\n }\n\n state.checkpointQueue = state.checkpointQueue.then(() => getLastCheckpointDoc(state, 'down'));\n let lastCheckpoint: CheckpointType = await state.checkpointQueue;\n\n\n const promises: Promise[] = [];\n while (!state.events.canceled.getValue()) {\n lastTimeMasterChangesRequested = timer++;\n const downResult = await replicationHandler.masterChangesSince(\n lastCheckpoint,\n state.input.pullBatchSize\n );\n\n if (downResult.documents.length === 0) {\n break;\n }\n\n lastCheckpoint = stackCheckpoints([lastCheckpoint, downResult.checkpoint]);\n\n promises.push(\n persistFromMaster(\n downResult.documents,\n lastCheckpoint\n )\n );\n\n /**\n * By definition we stop pull when the pulled documents\n * do not fill up the pullBatchSize because we\n * can assume that the remote has no more documents.\n */\n if (downResult.documents.length < state.input.pullBatchSize) {\n break;\n }\n\n }\n await Promise.all(promises);\n }\n\n\n function downstreamProcessChanges(tasks: Task[]) {\n state.stats.down.downstreamProcessChanges = state.stats.down.downstreamProcessChanges + 1;\n const docsOfAllTasks: WithDeleted[] = [];\n let lastCheckpoint: CheckpointType | undefined = null as any;\n\n tasks.forEach(task => {\n if (task === 'RESYNC') {\n throw new Error('SNH');\n }\n appendToArray(docsOfAllTasks, task.documents);\n lastCheckpoint = stackCheckpoints([lastCheckpoint, task.checkpoint]);\n });\n return persistFromMaster(\n docsOfAllTasks,\n ensureNotFalsy(lastCheckpoint)\n );\n }\n\n\n /**\n * It can happen that the calls to masterChangesSince() or the changeStream()\n * are way faster then how fast the documents can be persisted.\n * Therefore we merge all incoming downResults into the nonPersistedFromMaster object\n * and process them together if possible.\n * This often bundles up single writes and improves performance\n * by processing the documents in bulks.\n */\n let persistenceQueue = PROMISE_RESOLVE_VOID;\n const nonPersistedFromMaster: {\n checkpoint?: CheckpointType;\n docs: ById>;\n } = {\n docs: {}\n };\n\n function persistFromMaster(\n docs: WithDeleted[],\n checkpoint: CheckpointType\n ): Promise {\n const primaryPath = state.primaryPath;\n state.stats.down.persistFromMaster = state.stats.down.persistFromMaster + 1;\n\n /**\n * Add the new docs to the non-persistent list\n */\n docs.forEach(docData => {\n const docId: string = (docData as any)[primaryPath];\n nonPersistedFromMaster.docs[docId] = docData;\n });\n nonPersistedFromMaster.checkpoint = checkpoint;\n\n /**\n * Run in the queue\n * with all open documents from nonPersistedFromMaster.\n */\n persistenceQueue = persistenceQueue.then(() => {\n\n const downDocsById: ById> = nonPersistedFromMaster.docs;\n nonPersistedFromMaster.docs = {};\n const useCheckpoint = nonPersistedFromMaster.checkpoint;\n const docIds = Object.keys(downDocsById);\n\n if (\n state.events.canceled.getValue() ||\n docIds.length === 0\n ) {\n return PROMISE_RESOLVE_VOID;\n }\n\n const writeRowsToFork: BulkWriteRow[] = [];\n const writeRowsToForkById: ById> = {};\n const writeRowsToMeta: BulkWriteRowById> = {};\n const useMetaWriteRows: BulkWriteRow>[] = [];\n\n return Promise.all([\n state.input.forkInstance.findDocumentsById(docIds, true),\n getAssumedMasterState(\n state,\n docIds\n )\n ]).then(([\n currentForkStateList,\n assumedMasterState\n ]) => {\n const currentForkState = new Map>();\n currentForkStateList.forEach(doc => currentForkState.set((doc as any)[primaryPath], doc));\n return Promise.all(\n docIds.map(async (docId) => {\n const forkStateFullDoc: RxDocumentData | undefined = currentForkState.get(docId);\n const forkStateDocData: WithDeletedAndAttachments | undefined = forkStateFullDoc\n ? writeDocToDocState(forkStateFullDoc, state.hasAttachments, false)\n : undefined\n ;\n const masterState = downDocsById[docId];\n const assumedMaster = assumedMasterState[docId];\n\n if (\n assumedMaster &&\n forkStateFullDoc &&\n assumedMaster.metaDocument.isResolvedConflict === forkStateFullDoc._rev\n ) {\n /**\n * The current fork state represents a resolved conflict\n * that first must be send to the master in the upstream.\n * All conflicts are resolved by the upstream.\n */\n // return PROMISE_RESOLVE_VOID;\n await state.streamQueue.up;\n }\n\n let isAssumedMasterEqualToForkState = !assumedMaster || !forkStateDocData ?\n false :\n state.input.conflictHandler.isEqual(\n assumedMaster.docData,\n forkStateDocData,\n 'downstream-check-if-equal-0'\n );\n if (\n !isAssumedMasterEqualToForkState &&\n (\n assumedMaster &&\n (assumedMaster.docData as any)._rev &&\n forkStateFullDoc &&\n forkStateFullDoc._meta[state.input.identifier] &&\n getHeightOfRevision(forkStateFullDoc._rev) === forkStateFullDoc._meta[state.input.identifier]\n )\n ) {\n isAssumedMasterEqualToForkState = true;\n }\n if (\n (\n forkStateFullDoc &&\n assumedMaster &&\n isAssumedMasterEqualToForkState === false\n ) ||\n (\n forkStateFullDoc && !assumedMaster\n )\n ) {\n /**\n * We have a non-upstream-replicated\n * local write to the fork.\n * This means we ignore the downstream of this document\n * because anyway the upstream will first resolve the conflict.\n */\n return PROMISE_RESOLVE_VOID;\n }\n\n const areStatesExactlyEqual = !forkStateDocData\n ? false\n : state.input.conflictHandler.isEqual(\n masterState,\n forkStateDocData,\n 'downstream-check-if-equal-1'\n );\n if (\n forkStateDocData &&\n areStatesExactlyEqual\n ) {\n /**\n * Document states are exactly equal.\n * This can happen when the replication is shut down\n * unexpected like when the user goes offline.\n *\n * Only when the assumedMaster is different from the forkState,\n * we have to patch the document in the meta instance.\n */\n if (\n !assumedMaster ||\n isAssumedMasterEqualToForkState === false\n ) {\n useMetaWriteRows.push(\n await getMetaWriteRow(\n state,\n forkStateDocData,\n assumedMaster ? assumedMaster.metaDocument : undefined\n )\n );\n }\n return PROMISE_RESOLVE_VOID;\n }\n\n /**\n * All other master states need to be written to the forkInstance\n * and metaInstance.\n */\n const newForkState = Object.assign(\n {},\n masterState,\n forkStateFullDoc ? {\n _meta: flatClone(forkStateFullDoc._meta),\n _attachments: state.hasAttachments && masterState._attachments ? masterState._attachments : {},\n _rev: getDefaultRevision()\n } : {\n _meta: {\n lwt: now()\n },\n _rev: getDefaultRevision(),\n _attachments: state.hasAttachments && masterState._attachments ? masterState._attachments : {}\n }\n );\n /**\n * If the remote works with revisions,\n * we store the height of the next fork-state revision\n * inside of the documents meta data.\n * By doing so we can filter it out in the upstream\n * and detect the document as being equal to master or not.\n * This is used for example in the CouchDB replication plugin.\n */\n if ((masterState as any)._rev) {\n const nextRevisionHeight = !forkStateFullDoc ? 1 : getHeightOfRevision(forkStateFullDoc._rev) + 1;\n newForkState._meta[state.input.identifier] = nextRevisionHeight;\n if (state.input.keepMeta) {\n newForkState._rev = (masterState as any)._rev;\n }\n }\n if (\n state.input.keepMeta &&\n (masterState as any)._meta\n ) {\n newForkState._meta = (masterState as any)._meta;\n }\n\n const forkWriteRow = {\n previous: forkStateFullDoc,\n document: newForkState\n };\n\n forkWriteRow.document._rev = forkWriteRow.document._rev ? forkWriteRow.document._rev : createRevision(\n identifierHash,\n forkWriteRow.previous\n );\n writeRowsToFork.push(forkWriteRow);\n writeRowsToForkById[docId] = forkWriteRow;\n writeRowsToMeta[docId] = await getMetaWriteRow(\n state,\n masterState,\n assumedMaster ? assumedMaster.metaDocument : undefined\n );\n })\n );\n }).then(async () => {\n if (writeRowsToFork.length > 0) {\n return state.input.forkInstance.bulkWrite(\n writeRowsToFork,\n await state.downstreamBulkWriteFlag\n ).then((forkWriteResult) => {\n const success = getWrittenDocumentsFromBulkWriteResponse(\n state.primaryPath,\n writeRowsToFork,\n forkWriteResult\n );\n success.forEach(doc => {\n const docId = (doc as any)[primaryPath];\n state.events.processed.down.next(writeRowsToForkById[docId]);\n useMetaWriteRows.push(writeRowsToMeta[docId]);\n });\n let mustThrow: RxError | undefined;\n forkWriteResult.error.forEach(error => {\n /**\n * We do not have to care about downstream conflict errors here\n * because on conflict, it will be solved locally and result in another write.\n */\n if (error.status === 409) {\n return;\n }\n // other non-conflict errors must be handled\n const throwMe = newRxError('RC_PULL', {\n writeError: error\n });\n state.events.error.next(throwMe);\n mustThrow =\n mustThrow = throwMe;\n });\n if (mustThrow) {\n throw mustThrow;\n }\n });\n }\n }).then(() => {\n if (useMetaWriteRows.length > 0) {\n return state.input.metaInstance.bulkWrite(\n stripAttachmentsDataFromMetaWriteRows(state, useMetaWriteRows),\n 'replication-down-write-meta'\n ).then(metaWriteResult => {\n metaWriteResult.error\n .forEach(writeError => {\n state.events.error.next(newRxError('RC_PULL', {\n id: writeError.documentId,\n writeError\n }));\n });\n });\n }\n }).then(() => {\n /**\n * For better performance we do not await checkpoint writes,\n * but to ensure order on parallel checkpoint writes,\n * we have to use a queue.\n */\n setCheckpoint(\n state,\n 'down',\n useCheckpoint\n );\n });\n }).catch(unhandledError => state.events.error.next(unhandledError));\n return persistenceQueue;\n }\n}\n"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AAaA,IAAAG,MAAA,GAAAH,OAAA;AAUA,IAAAI,WAAA,GAAAJ,OAAA;AAIA,IAAAK,OAAA,GAAAL,OAAA;AAIA,IAAAM,aAAA,GAAAN,OAAA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAeO,0BAA0BA,CAC5CC,KAAmD,EACrD;EACE,IACIA,KAAK,CAACC,KAAK,CAACC,iBAAiB,IAC7BF,KAAK,CAACC,KAAK,CAACC,iBAAiB,CAACC,UAAU,EAC1C;IACE,IAAMC,aAAa,GAAG,MAAM,IAAAC,gCAAoB,EAACL,KAAK,EAAE,MAAM,CAAC;IAC/D,IAAI,CAACI,aAAa,EAAE;MAChB,MAAM,IAAAE,yBAAa,EACfN,KAAK,EACL,MAAM,EACNA,KAAK,CAACC,KAAK,CAACC,iBAAiB,CAACC,UAClC,CAAC;IACL;EACJ;EAEA,IAAMI,cAAc,GAAG,MAAMP,KAAK,CAACC,KAAK,CAACO,YAAY,CAACR,KAAK,CAACC,KAAK,CAACQ,UAAU,CAAC;EAC7E,IAAMC,kBAAkB,GAAGV,KAAK,CAACC,KAAK,CAACS,kBAAkB;;EAEzD;EACA,IAAIC,KAAK,GAAG,CAAC;EAQb,IAAMC,SAAyB,GAAG,EAAE;EAGpC,SAASC,UAAUA,CAACC,IAAU,EAAQ;IAClCd,KAAK,CAACe,KAAK,CAACC,IAAI,CAACH,UAAU,GAAGb,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C;IACN,CAAC,CAAC,CAACkE,KAAK,CAACC,cAAc,IAAI5I,KAAK,CAACwB,MAAM,CAACyG,KAAK,CAACvG,IAAI,CAACkH,cAAc,CAAC,CAAC;IACnE,OAAO3E,gBAAgB;EAC3B;AACJ","ignoreList":[]} \ No newline at end of file diff --git a/dist/esm/plugins/utils/utils-rxdb-version.js b/dist/esm/plugins/utils/utils-rxdb-version.js index 250251cf5ed..8251a729a2d 100644 --- a/dist/esm/plugins/utils/utils-rxdb-version.js +++ b/dist/esm/plugins/utils/utils-rxdb-version.js @@ -1,5 +1,5 @@ /** * This file is replaced in the 'npm run build:version' script. */ -export var RXDB_VERSION = '16.0.0-beta.9'; +export var RXDB_VERSION = '16.0.0-beta.10'; //# sourceMappingURL=utils-rxdb-version.js.map \ No newline at end of file diff --git a/dist/esm/plugins/utils/utils-rxdb-version.js.map b/dist/esm/plugins/utils/utils-rxdb-version.js.map index 31c588592c0..9e3044f69eb 100644 --- a/dist/esm/plugins/utils/utils-rxdb-version.js.map +++ b/dist/esm/plugins/utils/utils-rxdb-version.js.map @@ -1 +1 @@ -{"version":3,"file":"utils-rxdb-version.js","names":["RXDB_VERSION"],"sources":["../../../../src/plugins/utils/utils-rxdb-version.ts"],"sourcesContent":["/**\n * This file is replaced in the 'npm run build:version' script.\n */\nexport const RXDB_VERSION = '16.0.0-beta.9';\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,IAAMA,YAAY,GAAG,eAAe","ignoreList":[]} \ No newline at end of file +{"version":3,"file":"utils-rxdb-version.js","names":["RXDB_VERSION"],"sources":["../../../../src/plugins/utils/utils-rxdb-version.ts"],"sourcesContent":["/**\n * This file is replaced in the 'npm run build:version' script.\n */\nexport const RXDB_VERSION = '16.0.0-beta.10';\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,IAAMA,YAAY,GAAG,gBAAgB","ignoreList":[]} \ No newline at end of file diff --git a/dist/esm/replication-protocol/downstream.js b/dist/esm/replication-protocol/downstream.js index 5cdb68e476e..03d4fa3eed8 100644 --- a/dist/esm/replication-protocol/downstream.js +++ b/dist/esm/replication-protocol/downstream.js @@ -279,6 +279,7 @@ export async function startReplicationDownstream(state) { state.events.processed.down.next(writeRowsToForkById[docId]); useMetaWriteRows.push(writeRowsToMeta[docId]); }); + var mustThrow; forkWriteResult.error.forEach(error => { /** * We do not have to care about downstream conflict errors here @@ -288,10 +289,15 @@ export async function startReplicationDownstream(state) { return; } // other non-conflict errors must be handled - state.events.error.next(newRxError('RC_PULL', { + var throwMe = newRxError('RC_PULL', { writeError: error - })); + }); + state.events.error.next(throwMe); + mustThrow = mustThrow = throwMe; }); + if (mustThrow) { + throw mustThrow; + } }); } }).then(() => { diff --git a/dist/esm/replication-protocol/downstream.js.map b/dist/esm/replication-protocol/downstream.js.map index ba8de062c91..c54543ff5be 100644 --- a/dist/esm/replication-protocol/downstream.js.map +++ b/dist/esm/replication-protocol/downstream.js.map @@ -1 +1 @@ -{"version":3,"file":"downstream.js","names":["firstValueFrom","filter","mergeMap","newRxError","getWrittenDocumentsFromBulkWriteResponse","stackCheckpoints","appendToArray","createRevision","ensureNotFalsy","flatClone","getDefaultRevision","getHeightOfRevision","now","PROMISE_RESOLVE_VOID","getLastCheckpointDoc","setCheckpoint","stripAttachmentsDataFromMetaWriteRows","writeDocToDocState","getAssumedMasterState","getMetaWriteRow","startReplicationDownstream","state","input","initialCheckpoint","downstream","checkpointDoc","identifierHash","hashFunction","identifier","replicationHandler","timer","openTasks","addNewTask","task","stats","down","taskWithTime","time","push","streamQueue","then","useTasks","length","events","active","next","innerTaskWithTime","shift","lastTimeMasterChangesRequested","downstreamResyncOnce","downstreamProcessChanges","firstSyncDone","getValue","canceled","sub","masterChangeStream$","pipe","ev","up","s","subscribe","masterChangeStreamEmit","unsubscribe","checkpointQueue","lastCheckpoint","promises","downResult","masterChangesSince","pullBatchSize","documents","checkpoint","persistFromMaster","Promise","all","tasks","docsOfAllTasks","forEach","Error","persistenceQueue","nonPersistedFromMaster","docs","primaryPath","docData","docId","downDocsById","useCheckpoint","docIds","Object","keys","writeRowsToFork","writeRowsToForkById","writeRowsToMeta","useMetaWriteRows","forkInstance","findDocumentsById","currentForkStateList","assumedMasterState","currentForkState","Map","doc","set","map","forkStateFullDoc","get","forkStateDocData","hasAttachments","undefined","masterState","assumedMaster","metaDocument","isResolvedConflict","_rev","isAssumedMasterEqualToForkState","conflictHandler","isEqual","_meta","areStatesExactlyEqual","newForkState","assign","_attachments","lwt","nextRevisionHeight","keepMeta","forkWriteRow","previous","document","bulkWrite","downstreamBulkWriteFlag","forkWriteResult","success","processed","error","status","writeError","metaInstance","metaWriteResult","id","documentId","catch","unhandledError"],"sources":["../../../src/replication-protocol/downstream.ts"],"sourcesContent":["import {\n firstValueFrom,\n filter,\n mergeMap\n} from 'rxjs';\nimport { newRxError } from '../rx-error.ts';\nimport { getWrittenDocumentsFromBulkWriteResponse, stackCheckpoints } from '../rx-storage-helper.ts';\nimport type {\n RxStorageInstanceReplicationState,\n BulkWriteRow,\n BulkWriteRowById,\n RxStorageReplicationMeta,\n RxDocumentData,\n ById,\n WithDeleted,\n DocumentsWithCheckpoint,\n WithDeletedAndAttachments\n} from '../types/index.d.ts';\nimport {\n appendToArray,\n createRevision,\n ensureNotFalsy,\n flatClone,\n getDefaultRevision,\n getHeightOfRevision,\n now,\n PROMISE_RESOLVE_VOID\n} from '../plugins/utils/index.ts';\nimport {\n getLastCheckpointDoc,\n setCheckpoint\n} from './checkpoint.ts';\nimport {\n stripAttachmentsDataFromMetaWriteRows,\n writeDocToDocState\n} from './helper.ts';\nimport {\n getAssumedMasterState,\n getMetaWriteRow\n} from './meta-instance.ts';\n\n/**\n * Writes all documents from the master to the fork.\n * The downstream has two operation modes\n * - Sync by iterating over the checkpoints via downstreamResyncOnce()\n * - Sync by listening to the changestream via downstreamProcessChanges()\n * We need this to be able to do initial syncs\n * and still can have fast event based sync when the client is not offline.\n */\nexport async function startReplicationDownstream(\n state: RxStorageInstanceReplicationState\n) {\n if (\n state.input.initialCheckpoint &&\n state.input.initialCheckpoint.downstream\n ) {\n const checkpointDoc = await getLastCheckpointDoc(state, 'down');\n if (!checkpointDoc) {\n await setCheckpoint(\n state,\n 'down',\n state.input.initialCheckpoint.downstream\n );\n }\n }\n\n const identifierHash = await state.input.hashFunction(state.input.identifier);\n const replicationHandler = state.input.replicationHandler;\n\n // used to detect which tasks etc can in it at which order.\n let timer = 0;\n\n\n type Task = DocumentsWithCheckpoint | 'RESYNC';\n type TaskWithTime = {\n time: number;\n task: Task;\n };\n const openTasks: TaskWithTime[] = [];\n\n\n function addNewTask(task: Task): void {\n state.stats.down.addNewTask = state.stats.down.addNewTask + 1;\n const taskWithTime = {\n time: timer++,\n task\n };\n openTasks.push(taskWithTime);\n state.streamQueue.down = state.streamQueue.down\n .then(() => {\n const useTasks: Task[] = [];\n while (openTasks.length > 0) {\n state.events.active.down.next(true);\n const innerTaskWithTime = ensureNotFalsy(openTasks.shift());\n\n /**\n * If the task came in before the last time we started the pull\n * from the master, then we can drop the task.\n */\n if (innerTaskWithTime.time < lastTimeMasterChangesRequested) {\n continue;\n }\n\n if (innerTaskWithTime.task === 'RESYNC') {\n if (useTasks.length === 0) {\n useTasks.push(innerTaskWithTime.task);\n break;\n } else {\n break;\n }\n }\n\n useTasks.push(innerTaskWithTime.task);\n }\n if (useTasks.length === 0) {\n return;\n }\n\n if (useTasks[0] === 'RESYNC') {\n return downstreamResyncOnce();\n } else {\n return downstreamProcessChanges(useTasks);\n }\n }).then(() => {\n state.events.active.down.next(false);\n if (\n !state.firstSyncDone.down.getValue() &&\n !state.events.canceled.getValue()\n ) {\n state.firstSyncDone.down.next(true);\n }\n });\n }\n addNewTask('RESYNC');\n\n /**\n * If a write on the master happens, we have to trigger the downstream.\n * Only do this if not canceled yet, otherwise firstValueFrom errors\n * when running on a completed observable.\n */\n if (!state.events.canceled.getValue()) {\n const sub = replicationHandler\n .masterChangeStream$\n .pipe(\n mergeMap(async (ev) => {\n /**\n * While a push is running, we have to delay all incoming\n * events from the server to not mix up the replication state.\n */\n await firstValueFrom(\n state.events.active.up.pipe(filter(s => !s))\n );\n return ev;\n })\n )\n .subscribe((task: Task) => {\n state.stats.down.masterChangeStreamEmit = state.stats.down.masterChangeStreamEmit + 1;\n addNewTask(task);\n });\n firstValueFrom(\n state.events.canceled.pipe(\n filter(canceled => !!canceled)\n )\n ).then(() => sub.unsubscribe());\n }\n\n\n /**\n * For faster performance, we directly start each write\n * and then await all writes at the end.\n */\n let lastTimeMasterChangesRequested: number = -1;\n async function downstreamResyncOnce() {\n state.stats.down.downstreamResyncOnce = state.stats.down.downstreamResyncOnce + 1;\n if (state.events.canceled.getValue()) {\n return;\n }\n\n state.checkpointQueue = state.checkpointQueue.then(() => getLastCheckpointDoc(state, 'down'));\n let lastCheckpoint: CheckpointType = await state.checkpointQueue;\n\n\n const promises: Promise[] = [];\n while (!state.events.canceled.getValue()) {\n lastTimeMasterChangesRequested = timer++;\n const downResult = await replicationHandler.masterChangesSince(\n lastCheckpoint,\n state.input.pullBatchSize\n );\n\n if (downResult.documents.length === 0) {\n break;\n }\n\n lastCheckpoint = stackCheckpoints([lastCheckpoint, downResult.checkpoint]);\n\n promises.push(\n persistFromMaster(\n downResult.documents,\n lastCheckpoint\n )\n );\n\n /**\n * By definition we stop pull when the pulled documents\n * do not fill up the pullBatchSize because we\n * can assume that the remote has no more documents.\n */\n if (downResult.documents.length < state.input.pullBatchSize) {\n break;\n }\n\n }\n await Promise.all(promises);\n }\n\n\n function downstreamProcessChanges(tasks: Task[]) {\n state.stats.down.downstreamProcessChanges = state.stats.down.downstreamProcessChanges + 1;\n const docsOfAllTasks: WithDeleted[] = [];\n let lastCheckpoint: CheckpointType | undefined = null as any;\n\n tasks.forEach(task => {\n if (task === 'RESYNC') {\n throw new Error('SNH');\n }\n appendToArray(docsOfAllTasks, task.documents);\n lastCheckpoint = stackCheckpoints([lastCheckpoint, task.checkpoint]);\n });\n return persistFromMaster(\n docsOfAllTasks,\n ensureNotFalsy(lastCheckpoint)\n );\n }\n\n\n /**\n * It can happen that the calls to masterChangesSince() or the changeStream()\n * are way faster then how fast the documents can be persisted.\n * Therefore we merge all incoming downResults into the nonPersistedFromMaster object\n * and process them together if possible.\n * This often bundles up single writes and improves performance\n * by processing the documents in bulks.\n */\n let persistenceQueue = PROMISE_RESOLVE_VOID;\n const nonPersistedFromMaster: {\n checkpoint?: CheckpointType;\n docs: ById>;\n } = {\n docs: {}\n };\n\n function persistFromMaster(\n docs: WithDeleted[],\n checkpoint: CheckpointType\n ): Promise {\n const primaryPath = state.primaryPath;\n state.stats.down.persistFromMaster = state.stats.down.persistFromMaster + 1;\n\n /**\n * Add the new docs to the non-persistent list\n */\n docs.forEach(docData => {\n const docId: string = (docData as any)[primaryPath];\n nonPersistedFromMaster.docs[docId] = docData;\n });\n nonPersistedFromMaster.checkpoint = checkpoint;\n\n /**\n * Run in the queue\n * with all open documents from nonPersistedFromMaster.\n */\n persistenceQueue = persistenceQueue.then(() => {\n\n const downDocsById: ById> = nonPersistedFromMaster.docs;\n nonPersistedFromMaster.docs = {};\n const useCheckpoint = nonPersistedFromMaster.checkpoint;\n const docIds = Object.keys(downDocsById);\n\n if (\n state.events.canceled.getValue() ||\n docIds.length === 0\n ) {\n return PROMISE_RESOLVE_VOID;\n }\n\n const writeRowsToFork: BulkWriteRow[] = [];\n const writeRowsToForkById: ById> = {};\n const writeRowsToMeta: BulkWriteRowById> = {};\n const useMetaWriteRows: BulkWriteRow>[] = [];\n\n return Promise.all([\n state.input.forkInstance.findDocumentsById(docIds, true),\n getAssumedMasterState(\n state,\n docIds\n )\n ]).then(([\n currentForkStateList,\n assumedMasterState\n ]) => {\n const currentForkState = new Map>();\n currentForkStateList.forEach(doc => currentForkState.set((doc as any)[primaryPath], doc));\n return Promise.all(\n docIds.map(async (docId) => {\n const forkStateFullDoc: RxDocumentData | undefined = currentForkState.get(docId);\n const forkStateDocData: WithDeletedAndAttachments | undefined = forkStateFullDoc\n ? writeDocToDocState(forkStateFullDoc, state.hasAttachments, false)\n : undefined\n ;\n const masterState = downDocsById[docId];\n const assumedMaster = assumedMasterState[docId];\n\n if (\n assumedMaster &&\n forkStateFullDoc &&\n assumedMaster.metaDocument.isResolvedConflict === forkStateFullDoc._rev\n ) {\n /**\n * The current fork state represents a resolved conflict\n * that first must be send to the master in the upstream.\n * All conflicts are resolved by the upstream.\n */\n // return PROMISE_RESOLVE_VOID;\n await state.streamQueue.up;\n }\n\n let isAssumedMasterEqualToForkState = !assumedMaster || !forkStateDocData ?\n false :\n state.input.conflictHandler.isEqual(\n assumedMaster.docData,\n forkStateDocData,\n 'downstream-check-if-equal-0'\n );\n if (\n !isAssumedMasterEqualToForkState &&\n (\n assumedMaster &&\n (assumedMaster.docData as any)._rev &&\n forkStateFullDoc &&\n forkStateFullDoc._meta[state.input.identifier] &&\n getHeightOfRevision(forkStateFullDoc._rev) === forkStateFullDoc._meta[state.input.identifier]\n )\n ) {\n isAssumedMasterEqualToForkState = true;\n }\n if (\n (\n forkStateFullDoc &&\n assumedMaster &&\n isAssumedMasterEqualToForkState === false\n ) ||\n (\n forkStateFullDoc && !assumedMaster\n )\n ) {\n /**\n * We have a non-upstream-replicated\n * local write to the fork.\n * This means we ignore the downstream of this document\n * because anyway the upstream will first resolve the conflict.\n */\n return PROMISE_RESOLVE_VOID;\n }\n\n const areStatesExactlyEqual = !forkStateDocData\n ? false\n : state.input.conflictHandler.isEqual(\n masterState,\n forkStateDocData,\n 'downstream-check-if-equal-1'\n );\n if (\n forkStateDocData &&\n areStatesExactlyEqual\n ) {\n /**\n * Document states are exactly equal.\n * This can happen when the replication is shut down\n * unexpected like when the user goes offline.\n *\n * Only when the assumedMaster is different from the forkState,\n * we have to patch the document in the meta instance.\n */\n if (\n !assumedMaster ||\n isAssumedMasterEqualToForkState === false\n ) {\n useMetaWriteRows.push(\n await getMetaWriteRow(\n state,\n forkStateDocData,\n assumedMaster ? assumedMaster.metaDocument : undefined\n )\n );\n }\n return PROMISE_RESOLVE_VOID;\n }\n\n /**\n * All other master states need to be written to the forkInstance\n * and metaInstance.\n */\n const newForkState = Object.assign(\n {},\n masterState,\n forkStateFullDoc ? {\n _meta: flatClone(forkStateFullDoc._meta),\n _attachments: state.hasAttachments && masterState._attachments ? masterState._attachments : {},\n _rev: getDefaultRevision()\n } : {\n _meta: {\n lwt: now()\n },\n _rev: getDefaultRevision(),\n _attachments: state.hasAttachments && masterState._attachments ? masterState._attachments : {}\n }\n );\n /**\n * If the remote works with revisions,\n * we store the height of the next fork-state revision\n * inside of the documents meta data.\n * By doing so we can filter it out in the upstream\n * and detect the document as being equal to master or not.\n * This is used for example in the CouchDB replication plugin.\n */\n if ((masterState as any)._rev) {\n const nextRevisionHeight = !forkStateFullDoc ? 1 : getHeightOfRevision(forkStateFullDoc._rev) + 1;\n newForkState._meta[state.input.identifier] = nextRevisionHeight;\n if (state.input.keepMeta) {\n newForkState._rev = (masterState as any)._rev;\n }\n }\n if (\n state.input.keepMeta &&\n (masterState as any)._meta\n ) {\n newForkState._meta = (masterState as any)._meta;\n }\n\n const forkWriteRow = {\n previous: forkStateFullDoc,\n document: newForkState\n };\n\n forkWriteRow.document._rev = forkWriteRow.document._rev ? forkWriteRow.document._rev : createRevision(\n identifierHash,\n forkWriteRow.previous\n );\n writeRowsToFork.push(forkWriteRow);\n writeRowsToForkById[docId] = forkWriteRow;\n writeRowsToMeta[docId] = await getMetaWriteRow(\n state,\n masterState,\n assumedMaster ? assumedMaster.metaDocument : undefined\n );\n })\n );\n }).then(async () => {\n if (writeRowsToFork.length > 0) {\n return state.input.forkInstance.bulkWrite(\n writeRowsToFork,\n await state.downstreamBulkWriteFlag\n ).then((forkWriteResult) => {\n const success = getWrittenDocumentsFromBulkWriteResponse(\n state.primaryPath,\n writeRowsToFork,\n forkWriteResult\n );\n success.forEach(doc => {\n const docId = (doc as any)[primaryPath];\n state.events.processed.down.next(writeRowsToForkById[docId]);\n useMetaWriteRows.push(writeRowsToMeta[docId]);\n });\n forkWriteResult.error.forEach(error => {\n /**\n * We do not have to care about downstream conflict errors here\n * because on conflict, it will be solved locally and result in another write.\n */\n if (error.status === 409) {\n return;\n }\n // other non-conflict errors must be handled\n state.events.error.next(newRxError('RC_PULL', {\n writeError: error\n }));\n });\n });\n }\n }).then(() => {\n if (useMetaWriteRows.length > 0) {\n return state.input.metaInstance.bulkWrite(\n stripAttachmentsDataFromMetaWriteRows(state, useMetaWriteRows),\n 'replication-down-write-meta'\n ).then(metaWriteResult => {\n metaWriteResult.error\n .forEach(writeError => {\n state.events.error.next(newRxError('RC_PULL', {\n id: writeError.documentId,\n writeError\n }));\n });\n });\n }\n }).then(() => {\n /**\n * For better performance we do not await checkpoint writes,\n * but to ensure order on parallel checkpoint writes,\n * we have to use a queue.\n */\n setCheckpoint(\n state,\n 'down',\n useCheckpoint\n );\n });\n }).catch(unhandledError => state.events.error.next(unhandledError));\n return persistenceQueue;\n }\n}\n"],"mappings":"AAAA,SACIA,cAAc,EACdC,MAAM,EACNC,QAAQ,QACL,MAAM;AACb,SAASC,UAAU,QAAQ,gBAAgB;AAC3C,SAASC,wCAAwC,EAAEC,gBAAgB,QAAQ,yBAAyB;AAYpG,SACIC,aAAa,EACbC,cAAc,EACdC,cAAc,EACdC,SAAS,EACTC,kBAAkB,EAClBC,mBAAmB,EACnBC,GAAG,EACHC,oBAAoB,QACjB,2BAA2B;AAClC,SACIC,oBAAoB,EACpBC,aAAa,QACV,iBAAiB;AACxB,SACIC,qCAAqC,EACrCC,kBAAkB,QACf,aAAa;AACpB,SACIC,qBAAqB,EACrBC,eAAe,QACZ,oBAAoB;;AAE3B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,0BAA0BA,CAC5CC,KAAmD,EACrD;EACE,IACIA,KAAK,CAACC,KAAK,CAACC,iBAAiB,IAC7BF,KAAK,CAACC,KAAK,CAACC,iBAAiB,CAACC,UAAU,EAC1C;IACE,IAAMC,aAAa,GAAG,MAAMX,oBAAoB,CAACO,K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;cACJ,CAAC,CAAC,CAAC;YACP,CAAC,CAAC;UACV,CAAC,CAAC;QACN;MACJ,CAAC,CAAC,CAAC7F,IAAI,CAAC,MAAM;QACV;AAChB;AACA;AACA;AACA;QACgBzB,aAAa,CACTM,KAAK,EACL,MAAM,EACNgE,aACJ,CAAC;MACL,CAAC,CAAC;IACN,CAAC,CAAC,CAACqD,KAAK,CAACC,cAAc,IAAItH,KAAK,CAACsB,MAAM,CAACwF,KAAK,CAACtF,IAAI,CAAC8F,cAAc,CAAC,CAAC;IACnE,OAAO7D,gBAAgB;EAC3B;AACJ","ignoreList":[]} \ No newline at end of file +{"version":3,"file":"downstream.js","names":["firstValueFrom","filter","mergeMap","newRxError","getWrittenDocumentsFromBulkWriteResponse","stackCheckpoints","appendToArray","createRevision","ensureNotFalsy","flatClone","getDefaultRevision","getHeightOfRevision","now","PROMISE_RESOLVE_VOID","getLastCheckpointDoc","setCheckpoint","stripAttachmentsDataFromMetaWriteRows","writeDocToDocState","getAssumedMasterState","getMetaWriteRow","startReplicationDownstream","state","input","initialCheckpoint","downstream","checkpointDoc","identifierHash","hashFunction","identifier","replicationHandler","timer","openTasks","addNewTask","task","stats","down","taskWithTime","time","push","streamQueue","then","useTasks","length","events","active","next","innerTaskWithTime","shift","lastTimeMasterChangesRequested","downstreamResyncOnce","downstreamProcessChanges","firstSyncDone","getValue","canceled","sub","masterChangeStream$","pipe","ev","up","s","subscribe","masterChangeStreamEmit","unsubscribe","checkpointQueue","lastCheckpoint","promises","downResult","masterChangesSince","pullBatchSize","documents","checkpoint","persistFromMaster","Promise","all","tasks","docsOfAllTasks","forEach","Error","persistenceQueue","nonPersistedFromMaster","docs","primaryPath","docData","docId","downDocsById","useCheckpoint","docIds","Object","keys","writeRowsToFork","writeRowsToForkById","writeRowsToMeta","useMetaWriteRows","forkInstance","findDocumentsById","currentForkStateList","assumedMasterState","currentForkState","Map","doc","set","map","forkStateFullDoc","get","forkStateDocData","hasAttachments","undefined","masterState","assumedMaster","metaDocument","isResolvedConflict","_rev","isAssumedMasterEqualToForkState","conflictHandler","isEqual","_meta","areStatesExactlyEqual","newForkState","assign","_attachments","lwt","nextRevisionHeight","keepMeta","forkWriteRow","previous","document","bulkWrite","downstreamBulkWriteFlag","forkWriteResult","success","processed","mustThrow","error","status","throwMe","writeError","metaInstance","metaWriteResult","id","documentId","catch","unhandledError"],"sources":["../../../src/replication-protocol/downstream.ts"],"sourcesContent":["import {\n firstValueFrom,\n filter,\n mergeMap\n} from 'rxjs';\nimport { newRxError } from '../rx-error.ts';\nimport { getWrittenDocumentsFromBulkWriteResponse, stackCheckpoints } from '../rx-storage-helper.ts';\nimport type {\n RxStorageInstanceReplicationState,\n BulkWriteRow,\n BulkWriteRowById,\n RxStorageReplicationMeta,\n RxDocumentData,\n ById,\n WithDeleted,\n DocumentsWithCheckpoint,\n WithDeletedAndAttachments,\n RxError\n} from '../types/index.d.ts';\nimport {\n appendToArray,\n createRevision,\n ensureNotFalsy,\n flatClone,\n getDefaultRevision,\n getHeightOfRevision,\n now,\n PROMISE_RESOLVE_VOID\n} from '../plugins/utils/index.ts';\nimport {\n getLastCheckpointDoc,\n setCheckpoint\n} from './checkpoint.ts';\nimport {\n stripAttachmentsDataFromMetaWriteRows,\n writeDocToDocState\n} from './helper.ts';\nimport {\n getAssumedMasterState,\n getMetaWriteRow\n} from './meta-instance.ts';\n\n/**\n * Writes all documents from the master to the fork.\n * The downstream has two operation modes\n * - Sync by iterating over the checkpoints via downstreamResyncOnce()\n * - Sync by listening to the changestream via downstreamProcessChanges()\n * We need this to be able to do initial syncs\n * and still can have fast event based sync when the client is not offline.\n */\nexport async function startReplicationDownstream(\n state: RxStorageInstanceReplicationState\n) {\n if (\n state.input.initialCheckpoint &&\n state.input.initialCheckpoint.downstream\n ) {\n const checkpointDoc = await getLastCheckpointDoc(state, 'down');\n if (!checkpointDoc) {\n await setCheckpoint(\n state,\n 'down',\n state.input.initialCheckpoint.downstream\n );\n }\n }\n\n const identifierHash = await state.input.hashFunction(state.input.identifier);\n const replicationHandler = state.input.replicationHandler;\n\n // used to detect which tasks etc can in it at which order.\n let timer = 0;\n\n\n type Task = DocumentsWithCheckpoint | 'RESYNC';\n type TaskWithTime = {\n time: number;\n task: Task;\n };\n const openTasks: TaskWithTime[] = [];\n\n\n function addNewTask(task: Task): void {\n state.stats.down.addNewTask = state.stats.down.addNewTask + 1;\n const taskWithTime = {\n time: timer++,\n task\n };\n openTasks.push(taskWithTime);\n state.streamQueue.down = state.streamQueue.down\n .then(() => {\n const useTasks: Task[] = [];\n while (openTasks.length > 0) {\n state.events.active.down.next(true);\n const innerTaskWithTime = ensureNotFalsy(openTasks.shift());\n\n /**\n * If the task came in before the last time we started the pull\n * from the master, then we can drop the task.\n */\n if (innerTaskWithTime.time < lastTimeMasterChangesRequested) {\n continue;\n }\n\n if (innerTaskWithTime.task === 'RESYNC') {\n if (useTasks.length === 0) {\n useTasks.push(innerTaskWithTime.task);\n break;\n } else {\n break;\n }\n }\n\n useTasks.push(innerTaskWithTime.task);\n }\n if (useTasks.length === 0) {\n return;\n }\n\n if (useTasks[0] === 'RESYNC') {\n return downstreamResyncOnce();\n } else {\n return downstreamProcessChanges(useTasks);\n }\n }).then(() => {\n state.events.active.down.next(false);\n if (\n !state.firstSyncDone.down.getValue() &&\n !state.events.canceled.getValue()\n ) {\n state.firstSyncDone.down.next(true);\n }\n });\n }\n addNewTask('RESYNC');\n\n /**\n * If a write on the master happens, we have to trigger the downstream.\n * Only do this if not canceled yet, otherwise firstValueFrom errors\n * when running on a completed observable.\n */\n if (!state.events.canceled.getValue()) {\n const sub = replicationHandler\n .masterChangeStream$\n .pipe(\n mergeMap(async (ev) => {\n /**\n * While a push is running, we have to delay all incoming\n * events from the server to not mix up the replication state.\n */\n await firstValueFrom(\n state.events.active.up.pipe(filter(s => !s))\n );\n return ev;\n })\n )\n .subscribe((task: Task) => {\n state.stats.down.masterChangeStreamEmit = state.stats.down.masterChangeStreamEmit + 1;\n addNewTask(task);\n });\n firstValueFrom(\n state.events.canceled.pipe(\n filter(canceled => !!canceled)\n )\n ).then(() => sub.unsubscribe());\n }\n\n\n /**\n * For faster performance, we directly start each write\n * and then await all writes at the end.\n */\n let lastTimeMasterChangesRequested: number = -1;\n async function downstreamResyncOnce() {\n state.stats.down.downstreamResyncOnce = state.stats.down.downstreamResyncOnce + 1;\n if (state.events.canceled.getValue()) {\n return;\n }\n\n state.checkpointQueue = state.checkpointQueue.then(() => getLastCheckpointDoc(state, 'down'));\n let lastCheckpoint: CheckpointType = await state.checkpointQueue;\n\n\n const promises: Promise[] = [];\n while (!state.events.canceled.getValue()) {\n lastTimeMasterChangesRequested = timer++;\n const downResult = await replicationHandler.masterChangesSince(\n lastCheckpoint,\n state.input.pullBatchSize\n );\n\n if (downResult.documents.length === 0) {\n break;\n }\n\n lastCheckpoint = stackCheckpoints([lastCheckpoint, downResult.checkpoint]);\n\n promises.push(\n persistFromMaster(\n downResult.documents,\n lastCheckpoint\n )\n );\n\n /**\n * By definition we stop pull when the pulled documents\n * do not fill up the pullBatchSize because we\n * can assume that the remote has no more documents.\n */\n if (downResult.documents.length < state.input.pullBatchSize) {\n break;\n }\n\n }\n await Promise.all(promises);\n }\n\n\n function downstreamProcessChanges(tasks: Task[]) {\n state.stats.down.downstreamProcessChanges = state.stats.down.downstreamProcessChanges + 1;\n const docsOfAllTasks: WithDeleted[] = [];\n let lastCheckpoint: CheckpointType | undefined = null as any;\n\n tasks.forEach(task => {\n if (task === 'RESYNC') {\n throw new Error('SNH');\n }\n appendToArray(docsOfAllTasks, task.documents);\n lastCheckpoint = stackCheckpoints([lastCheckpoint, task.checkpoint]);\n });\n return persistFromMaster(\n docsOfAllTasks,\n ensureNotFalsy(lastCheckpoint)\n );\n }\n\n\n /**\n * It can happen that the calls to masterChangesSince() or the changeStream()\n * are way faster then how fast the documents can be persisted.\n * Therefore we merge all incoming downResults into the nonPersistedFromMaster object\n * and process them together if possible.\n * This often bundles up single writes and improves performance\n * by processing the documents in bulks.\n */\n let persistenceQueue = PROMISE_RESOLVE_VOID;\n const nonPersistedFromMaster: {\n checkpoint?: CheckpointType;\n docs: ById>;\n } = {\n docs: {}\n };\n\n function persistFromMaster(\n docs: WithDeleted[],\n checkpoint: CheckpointType\n ): Promise {\n const primaryPath = state.primaryPath;\n state.stats.down.persistFromMaster = state.stats.down.persistFromMaster + 1;\n\n /**\n * Add the new docs to the non-persistent list\n */\n docs.forEach(docData => {\n const docId: string = (docData as any)[primaryPath];\n nonPersistedFromMaster.docs[docId] = docData;\n });\n nonPersistedFromMaster.checkpoint = checkpoint;\n\n /**\n * Run in the queue\n * with all open documents from nonPersistedFromMaster.\n */\n persistenceQueue = persistenceQueue.then(() => {\n\n const downDocsById: ById> = nonPersistedFromMaster.docs;\n nonPersistedFromMaster.docs = {};\n const useCheckpoint = nonPersistedFromMaster.checkpoint;\n const docIds = Object.keys(downDocsById);\n\n if (\n state.events.canceled.getValue() ||\n docIds.length === 0\n ) {\n return PROMISE_RESOLVE_VOID;\n }\n\n const writeRowsToFork: BulkWriteRow[] = [];\n const writeRowsToForkById: ById> = {};\n const writeRowsToMeta: BulkWriteRowById> = {};\n const useMetaWriteRows: BulkWriteRow>[] = [];\n\n return Promise.all([\n state.input.forkInstance.findDocumentsById(docIds, true),\n getAssumedMasterState(\n state,\n docIds\n )\n ]).then(([\n currentForkStateList,\n assumedMasterState\n ]) => {\n const currentForkState = new Map>();\n currentForkStateList.forEach(doc => currentForkState.set((doc as any)[primaryPath], doc));\n return Promise.all(\n docIds.map(async (docId) => {\n const forkStateFullDoc: RxDocumentData | undefined = currentForkState.get(docId);\n const forkStateDocData: WithDeletedAndAttachments | undefined = forkStateFullDoc\n ? writeDocToDocState(forkStateFullDoc, state.hasAttachments, false)\n : undefined\n ;\n const masterState = downDocsById[docId];\n const assumedMaster = assumedMasterState[docId];\n\n if (\n assumedMaster &&\n forkStateFullDoc &&\n assumedMaster.metaDocument.isResolvedConflict === forkStateFullDoc._rev\n ) {\n /**\n * The current fork state represents a resolved conflict\n * that first must be send to the master in the upstream.\n * All conflicts are resolved by the upstream.\n */\n // return PROMISE_RESOLVE_VOID;\n await state.streamQueue.up;\n }\n\n let isAssumedMasterEqualToForkState = !assumedMaster || !forkStateDocData ?\n false :\n state.input.conflictHandler.isEqual(\n assumedMaster.docData,\n forkStateDocData,\n 'downstream-check-if-equal-0'\n );\n if (\n !isAssumedMasterEqualToForkState &&\n (\n assumedMaster &&\n (assumedMaster.docData as any)._rev &&\n forkStateFullDoc &&\n forkStateFullDoc._meta[state.input.identifier] &&\n getHeightOfRevision(forkStateFullDoc._rev) === forkStateFullDoc._meta[state.input.identifier]\n )\n ) {\n isAssumedMasterEqualToForkState = true;\n }\n if (\n (\n forkStateFullDoc &&\n assumedMaster &&\n isAssumedMasterEqualToForkState === false\n ) ||\n (\n forkStateFullDoc && !assumedMaster\n )\n ) {\n /**\n * We have a non-upstream-replicated\n * local write to the fork.\n * This means we ignore the downstream of this document\n * because anyway the upstream will first resolve the conflict.\n */\n return PROMISE_RESOLVE_VOID;\n }\n\n const areStatesExactlyEqual = !forkStateDocData\n ? false\n : state.input.conflictHandler.isEqual(\n masterState,\n forkStateDocData,\n 'downstream-check-if-equal-1'\n );\n if (\n forkStateDocData &&\n areStatesExactlyEqual\n ) {\n /**\n * Document states are exactly equal.\n * This can happen when the replication is shut down\n * unexpected like when the user goes offline.\n *\n * Only when the assumedMaster is different from the forkState,\n * we have to patch the document in the meta instance.\n */\n if (\n !assumedMaster ||\n isAssumedMasterEqualToForkState === false\n ) {\n useMetaWriteRows.push(\n await getMetaWriteRow(\n state,\n forkStateDocData,\n assumedMaster ? assumedMaster.metaDocument : undefined\n )\n );\n }\n return PROMISE_RESOLVE_VOID;\n }\n\n /**\n * All other master states need to be written to the forkInstance\n * and metaInstance.\n */\n const newForkState = Object.assign(\n {},\n masterState,\n forkStateFullDoc ? {\n _meta: flatClone(forkStateFullDoc._meta),\n _attachments: state.hasAttachments && masterState._attachments ? masterState._attachments : {},\n _rev: getDefaultRevision()\n } : {\n _meta: {\n lwt: now()\n },\n _rev: getDefaultRevision(),\n _attachments: state.hasAttachments && masterState._attachments ? masterState._attachments : {}\n }\n );\n /**\n * If the remote works with revisions,\n * we store the height of the next fork-state revision\n * inside of the documents meta data.\n * By doing so we can filter it out in the upstream\n * and detect the document as being equal to master or not.\n * This is used for example in the CouchDB replication plugin.\n */\n if ((masterState as any)._rev) {\n const nextRevisionHeight = !forkStateFullDoc ? 1 : getHeightOfRevision(forkStateFullDoc._rev) + 1;\n newForkState._meta[state.input.identifier] = nextRevisionHeight;\n if (state.input.keepMeta) {\n newForkState._rev = (masterState as any)._rev;\n }\n }\n if (\n state.input.keepMeta &&\n (masterState as any)._meta\n ) {\n newForkState._meta = (masterState as any)._meta;\n }\n\n const forkWriteRow = {\n previous: forkStateFullDoc,\n document: newForkState\n };\n\n forkWriteRow.document._rev = forkWriteRow.document._rev ? forkWriteRow.document._rev : createRevision(\n identifierHash,\n forkWriteRow.previous\n );\n writeRowsToFork.push(forkWriteRow);\n writeRowsToForkById[docId] = forkWriteRow;\n writeRowsToMeta[docId] = await getMetaWriteRow(\n state,\n masterState,\n assumedMaster ? assumedMaster.metaDocument : undefined\n );\n })\n );\n }).then(async () => {\n if (writeRowsToFork.length > 0) {\n return state.input.forkInstance.bulkWrite(\n writeRowsToFork,\n await state.downstreamBulkWriteFlag\n ).then((forkWriteResult) => {\n const success = getWrittenDocumentsFromBulkWriteResponse(\n state.primaryPath,\n writeRowsToFork,\n forkWriteResult\n );\n success.forEach(doc => {\n const docId = (doc as any)[primaryPath];\n state.events.processed.down.next(writeRowsToForkById[docId]);\n useMetaWriteRows.push(writeRowsToMeta[docId]);\n });\n let mustThrow: RxError | undefined;\n forkWriteResult.error.forEach(error => {\n /**\n * We do not have to care about downstream conflict errors here\n * because on conflict, it will be solved locally and result in another write.\n */\n if (error.status === 409) {\n return;\n }\n // other non-conflict errors must be handled\n const throwMe = newRxError('RC_PULL', {\n writeError: error\n });\n state.events.error.next(throwMe);\n mustThrow =\n mustThrow = throwMe;\n });\n if (mustThrow) {\n throw mustThrow;\n }\n });\n }\n }).then(() => {\n if (useMetaWriteRows.length > 0) {\n return state.input.metaInstance.bulkWrite(\n stripAttachmentsDataFromMetaWriteRows(state, useMetaWriteRows),\n 'replication-down-write-meta'\n ).then(metaWriteResult => {\n metaWriteResult.error\n .forEach(writeError => {\n state.events.error.next(newRxError('RC_PULL', {\n id: writeError.documentId,\n writeError\n }));\n });\n });\n }\n }).then(() => {\n /**\n * For better performance we do not await checkpoint writes,\n * but to ensure order on parallel checkpoint writes,\n * we have to use a queue.\n */\n setCheckpoint(\n state,\n 'down',\n useCheckpoint\n );\n });\n }).catch(unhandledError => state.events.error.next(unhandledError));\n return persistenceQueue;\n }\n}\n"],"mappings":"AAAA,SACIA,cAAc,EACdC,MAAM,EACNC,QAAQ,QACL,MAAM;AACb,SAASC,UAAU,QAAQ,gBAAgB;AAC3C,SAASC,wCAAwC,EAAEC,gBAAgB,QAAQ,yBAAyB;AAapG,SACIC,aAAa,EACbC,cAAc,EACdC,cAAc,EACdC,SAAS,EACTC,kBAAkB,EAClBC,mBAAmB,EACnBC,GAAG,EACHC,oBAAoB,QACjB,2BAA2B;AAClC,SACIC,oBAAoB,EACpBC,aAAa,QACV,iBAAiB;AACxB,SACIC,qCAAqC,EACrCC,kBAAkB,QACf,aAAa;AACpB,SACIC,qBAAqB,EACrBC,eAAe,QACZ,oBAAoB;;AAE3B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAeC,0BAA0BA,CAC5CC,KAAmD,EACrD;EACE,IACIA,KAAK,CAACC,KAAK,CAACC,iBAAiB,IAC7BF,KAAK,CAACC,KAAK,CAACC,iBAAiB,CAACC,UAAU,EAC1C;IACE,IAAMC,aAAa,GAAG,MAAMX,oBAAoB,CAACO,KAAK,EAAE,MAAM,CAAC;IAC/D,IAAI,CAACI,aAAa,EAAE;MAChB,MAAMV,aAAa,CACfM,KAAK,EACL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gBAC1CuI,EAAE,EAAEH,UAAU,CAACI,UAAU;gBACzBJ;cACJ,CAAC,CAAC,CAAC;YACP,CAAC,CAAC;UACV,CAAC,CAAC;QACN;MACJ,CAAC,CAAC,CAAC/F,IAAI,CAAC,MAAM;QACV;AAChB;AACA;AACA;AACA;QACgBzB,aAAa,CACTM,KAAK,EACL,MAAM,EACNgE,aACJ,CAAC;MACL,CAAC,CAAC;IACN,CAAC,CAAC,CAACuD,KAAK,CAACC,cAAc,IAAIxH,KAAK,CAACsB,MAAM,CAACyF,KAAK,CAACvF,IAAI,CAACgG,cAAc,CAAC,CAAC;IACnE,OAAO/D,gBAAgB;EAC3B;AACJ","ignoreList":[]} \ No newline at end of file diff --git a/dist/types/plugins/storage-denokv/index.d.ts b/dist/types/plugins/storage-denokv/index.d.ts index 227fb177f8d..029444674a7 100644 --- a/dist/types/plugins/storage-denokv/index.d.ts +++ b/dist/types/plugins/storage-denokv/index.d.ts @@ -4,7 +4,7 @@ import { RxStorageInstanceDenoKV } from "./rx-storage-instance-denokv.ts"; export declare class RxStorageDenoKV implements RxStorage, DenoKVSettings> { settings: DenoKVSettings; name: string; - readonly rxdbVersion = "16.0.0-beta.9"; + readonly rxdbVersion = "16.0.0-beta.10"; constructor(settings: DenoKVSettings); createStorageInstance(params: RxStorageInstanceCreationParams): Promise>; } diff --git a/dist/types/plugins/storage-dexie/rx-storage-dexie.d.ts b/dist/types/plugins/storage-dexie/rx-storage-dexie.d.ts index 5f45366bf09..b221bf28aac 100644 --- a/dist/types/plugins/storage-dexie/rx-storage-dexie.d.ts +++ b/dist/types/plugins/storage-dexie/rx-storage-dexie.d.ts @@ -4,7 +4,7 @@ import { RxStorageInstanceDexie } from './rx-storage-instance-dexie.ts'; export declare class RxStorageDexie implements RxStorage { settings: DexieSettings; name: string; - readonly rxdbVersion = "16.0.0-beta.9"; + readonly rxdbVersion = "16.0.0-beta.10"; constructor(settings: DexieSettings); createStorageInstance(params: RxStorageInstanceCreationParams): Promise>; } diff --git a/dist/types/plugins/storage-mongodb/rx-storage-mongodb.d.ts b/dist/types/plugins/storage-mongodb/rx-storage-mongodb.d.ts index 04706f0386b..66934ba607c 100644 --- a/dist/types/plugins/storage-mongodb/rx-storage-mongodb.d.ts +++ b/dist/types/plugins/storage-mongodb/rx-storage-mongodb.d.ts @@ -4,7 +4,7 @@ import { RxStorageInstanceMongoDB } from './rx-storage-instance-mongodb.ts'; export declare class RxStorageMongoDB implements RxStorage { databaseSettings: MongoDBDatabaseSettings; name: string; - readonly rxdbVersion = "16.0.0-beta.9"; + readonly rxdbVersion = "16.0.0-beta.10"; constructor(databaseSettings: MongoDBDatabaseSettings); createStorageInstance(params: RxStorageInstanceCreationParams): Promise>; } diff --git a/dist/types/plugins/storage-remote/rx-storage-remote.d.ts b/dist/types/plugins/storage-remote/rx-storage-remote.d.ts index 5b422995db7..1323b3c0b96 100644 --- a/dist/types/plugins/storage-remote/rx-storage-remote.d.ts +++ b/dist/types/plugins/storage-remote/rx-storage-remote.d.ts @@ -4,7 +4,7 @@ import type { MessageFromRemote, RemoteMessageChannel, RxStorageRemoteInternals, export declare class RxStorageRemote implements RxStorage { readonly settings: RxStorageRemoteSettings; readonly name: string; - readonly rxdbVersion = "16.0.0-beta.9"; + readonly rxdbVersion = "16.0.0-beta.10"; private seed; private lastRequestId; messageChannelIfOneMode?: Promise; diff --git a/dist/types/plugins/utils/utils-rxdb-version.d.ts b/dist/types/plugins/utils/utils-rxdb-version.d.ts index f04d37383f9..050b09fcd48 100644 --- a/dist/types/plugins/utils/utils-rxdb-version.d.ts +++ b/dist/types/plugins/utils/utils-rxdb-version.d.ts @@ -1,4 +1,4 @@ /** * This file is replaced in the 'npm run build:version' script. */ -export declare const RXDB_VERSION = "16.0.0-beta.9"; +export declare const RXDB_VERSION = "16.0.0-beta.10"; diff --git a/dist/types/rx-database.d.ts b/dist/types/rx-database.d.ts index 30a7b0fc3d4..9e96c3411fe 100644 --- a/dist/types/rx-database.d.ts +++ b/dist/types/rx-database.d.ts @@ -29,7 +29,7 @@ export declare class RxDatabaseBase | undefined; readonly idleQueue: IdleQueue; - readonly rxdbVersion = "16.0.0-beta.9"; + readonly rxdbVersion = "16.0.0-beta.10"; /** * Contains all known non-closed storage instances * that belong to this database. diff --git a/package.json b/package.json index 732e519772a..6ab343340fd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "rxdb", "description": "A local-first realtime NoSQL Database for JavaScript applications - https://rxdb.info/", - "version": "16.0.0-beta.9", + "version": "16.0.0-beta.10", "author": "pubkey", "repository": { "type": "git", diff --git a/src/plugins/utils/utils-rxdb-version.ts b/src/plugins/utils/utils-rxdb-version.ts index b0ffdd01bd1..1b09a8b900a 100644 --- a/src/plugins/utils/utils-rxdb-version.ts +++ b/src/plugins/utils/utils-rxdb-version.ts @@ -1,4 +1,4 @@ /** * This file is replaced in the 'npm run build:version' script. */ -export const RXDB_VERSION = '16.0.0-beta.9'; +export const RXDB_VERSION = '16.0.0-beta.10';