@connecttomahdi/rxdb 17.0.0-beta.17 → 17.1.1

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.
Files changed (349) hide show
  1. package/AGENTS.md +4 -0
  2. package/CHANGELOG.md +47 -4
  3. package/CLAUDE.md +2 -0
  4. package/dist/cjs/change-event-buffer.js +2 -1
  5. package/dist/cjs/change-event-buffer.js.map +1 -1
  6. package/dist/cjs/custom-index.js +85 -12
  7. package/dist/cjs/custom-index.js.map +1 -1
  8. package/dist/cjs/doc-cache.js +117 -35
  9. package/dist/cjs/doc-cache.js.map +1 -1
  10. package/dist/cjs/event-reduce.js +10 -1
  11. package/dist/cjs/event-reduce.js.map +1 -1
  12. package/dist/cjs/plugin-helpers.js +16 -0
  13. package/dist/cjs/plugin-helpers.js.map +1 -1
  14. package/dist/cjs/plugins/attachments/index.js +3 -3
  15. package/dist/cjs/plugins/attachments/index.js.map +1 -1
  16. package/dist/cjs/plugins/cleanup/cleanup.js +5 -3
  17. package/dist/cjs/plugins/cleanup/cleanup.js.map +1 -1
  18. package/dist/cjs/plugins/crdt/index.js +52 -0
  19. package/dist/cjs/plugins/crdt/index.js.map +1 -1
  20. package/dist/cjs/plugins/dev-mode/check-query.js +7 -1
  21. package/dist/cjs/plugins/dev-mode/check-query.js.map +1 -1
  22. package/dist/cjs/plugins/dev-mode/check-schema.js +2 -1
  23. package/dist/cjs/plugins/dev-mode/check-schema.js.map +1 -1
  24. package/dist/cjs/plugins/dev-mode/error-messages.js +43 -5
  25. package/dist/cjs/plugins/dev-mode/error-messages.js.map +1 -1
  26. package/dist/cjs/plugins/encryption-crypto-js/index.js +22 -6
  27. package/dist/cjs/plugins/encryption-crypto-js/index.js.map +1 -1
  28. package/dist/cjs/plugins/leader-election/index.js +5 -5
  29. package/dist/cjs/plugins/leader-election/index.js.map +1 -1
  30. package/dist/cjs/plugins/local-documents/local-documents.js +20 -13
  31. package/dist/cjs/plugins/local-documents/local-documents.js.map +1 -1
  32. package/dist/cjs/plugins/migration-schema/migration-helpers.js +3 -0
  33. package/dist/cjs/plugins/migration-schema/migration-helpers.js.map +1 -1
  34. package/dist/cjs/plugins/migration-schema/rx-migration-state.js +1 -1
  35. package/dist/cjs/plugins/migration-schema/rx-migration-state.js.map +1 -1
  36. package/dist/cjs/plugins/pipeline/rx-pipeline.js +5 -1
  37. package/dist/cjs/plugins/pipeline/rx-pipeline.js.map +1 -1
  38. package/dist/cjs/plugins/query-builder/mquery/nosql-query-builder.js +4 -2
  39. package/dist/cjs/plugins/query-builder/mquery/nosql-query-builder.js.map +1 -1
  40. package/dist/cjs/plugins/replication/index.js +40 -2
  41. package/dist/cjs/plugins/replication/index.js.map +1 -1
  42. package/dist/cjs/plugins/replication-google-drive/document-handling.js +17 -6
  43. package/dist/cjs/plugins/replication-google-drive/document-handling.js.map +1 -1
  44. package/dist/cjs/plugins/replication-google-drive/google-drive-helper.js +1 -1
  45. package/dist/cjs/plugins/replication-google-drive/google-drive-helper.js.map +1 -1
  46. package/dist/cjs/plugins/replication-google-drive/google-drive-types.js.map +1 -1
  47. package/dist/cjs/plugins/replication-google-drive/signaling.js +4 -1
  48. package/dist/cjs/plugins/replication-google-drive/signaling.js.map +1 -1
  49. package/dist/cjs/plugins/replication-google-drive/upstream.js +7 -4
  50. package/dist/cjs/plugins/replication-google-drive/upstream.js.map +1 -1
  51. package/dist/cjs/plugins/replication-microsoft-onedrive/signaling.js +4 -1
  52. package/dist/cjs/plugins/replication-microsoft-onedrive/signaling.js.map +1 -1
  53. package/dist/cjs/plugins/state/rx-state.js +14 -3
  54. package/dist/cjs/plugins/state/rx-state.js.map +1 -1
  55. package/dist/cjs/plugins/storage-dexie/rx-storage-instance-dexie.js +0 -7
  56. package/dist/cjs/plugins/storage-dexie/rx-storage-instance-dexie.js.map +1 -1
  57. package/dist/cjs/plugins/storage-memory/binary-search-bounds.js +112 -40
  58. package/dist/cjs/plugins/storage-memory/binary-search-bounds.js.map +1 -1
  59. package/dist/cjs/plugins/storage-memory/memory-helper.js +127 -40
  60. package/dist/cjs/plugins/storage-memory/memory-helper.js.map +1 -1
  61. package/dist/cjs/plugins/storage-memory/memory-indexes.js +1 -0
  62. package/dist/cjs/plugins/storage-memory/memory-indexes.js.map +1 -1
  63. package/dist/cjs/plugins/storage-memory/memory-types.js.map +1 -1
  64. package/dist/cjs/plugins/storage-memory/rx-storage-instance-memory.js +97 -37
  65. package/dist/cjs/plugins/storage-memory/rx-storage-instance-memory.js.map +1 -1
  66. package/dist/cjs/plugins/storage-mongodb/mongodb-helper.js +42 -1
  67. package/dist/cjs/plugins/storage-mongodb/mongodb-helper.js.map +1 -1
  68. package/dist/cjs/plugins/storage-mongodb/rx-storage-instance-mongodb.js +7 -7
  69. package/dist/cjs/plugins/storage-mongodb/rx-storage-instance-mongodb.js.map +1 -1
  70. package/dist/cjs/plugins/test-utils/config.js +1 -1
  71. package/dist/cjs/plugins/test-utils/config.js.map +1 -1
  72. package/dist/cjs/plugins/test-utils/performance.js +122 -92
  73. package/dist/cjs/plugins/test-utils/performance.js.map +1 -1
  74. package/dist/cjs/plugins/test-utils/schema-objects.js +1 -1
  75. package/dist/cjs/plugins/test-utils/schema-objects.js.map +1 -1
  76. package/dist/cjs/plugins/test-utils/test-util.js +62 -0
  77. package/dist/cjs/plugins/test-utils/test-util.js.map +1 -1
  78. package/dist/cjs/plugins/utils/utils-map.js +2 -2
  79. package/dist/cjs/plugins/utils/utils-map.js.map +1 -1
  80. package/dist/cjs/plugins/utils/utils-object-deep-equal.js +3 -2
  81. package/dist/cjs/plugins/utils/utils-object-deep-equal.js.map +1 -1
  82. package/dist/cjs/plugins/utils/utils-object-dot-prop.js +25 -0
  83. package/dist/cjs/plugins/utils/utils-object-dot-prop.js.map +1 -1
  84. package/dist/cjs/plugins/utils/utils-object.js +102 -27
  85. package/dist/cjs/plugins/utils/utils-object.js.map +1 -1
  86. package/dist/cjs/plugins/utils/utils-other.js +9 -4
  87. package/dist/cjs/plugins/utils/utils-other.js.map +1 -1
  88. package/dist/cjs/plugins/utils/utils-premium.js +5 -23
  89. package/dist/cjs/plugins/utils/utils-premium.js.map +1 -1
  90. package/dist/cjs/plugins/utils/utils-revision.js +20 -10
  91. package/dist/cjs/plugins/utils/utils-revision.js.map +1 -1
  92. package/dist/cjs/plugins/utils/utils-rxdb-version.js +1 -1
  93. package/dist/cjs/plugins/utils/utils-rxdb-version.js.map +1 -1
  94. package/dist/cjs/plugins/utils/utils-string.js +11 -8
  95. package/dist/cjs/plugins/utils/utils-string.js.map +1 -1
  96. package/dist/cjs/plugins/utils/utils-time.js +21 -16
  97. package/dist/cjs/plugins/utils/utils-time.js.map +1 -1
  98. package/dist/cjs/query-cache.js +6 -4
  99. package/dist/cjs/query-cache.js.map +1 -1
  100. package/dist/cjs/query-planner.js +2 -2
  101. package/dist/cjs/query-planner.js.map +1 -1
  102. package/dist/cjs/replication-protocol/downstream.js +1 -1
  103. package/dist/cjs/replication-protocol/downstream.js.map +1 -1
  104. package/dist/cjs/rx-collection-helper.js +11 -6
  105. package/dist/cjs/rx-collection-helper.js.map +1 -1
  106. package/dist/cjs/rx-collection.js +34 -6
  107. package/dist/cjs/rx-collection.js.map +1 -1
  108. package/dist/cjs/rx-database.js +40 -7
  109. package/dist/cjs/rx-database.js.map +1 -1
  110. package/dist/cjs/rx-document.js +10 -3
  111. package/dist/cjs/rx-document.js.map +1 -1
  112. package/dist/cjs/rx-query-helper.js +35 -12
  113. package/dist/cjs/rx-query-helper.js.map +1 -1
  114. package/dist/cjs/rx-query-single-result.js +9 -2
  115. package/dist/cjs/rx-query-single-result.js.map +1 -1
  116. package/dist/cjs/rx-query.js +72 -29
  117. package/dist/cjs/rx-query.js.map +1 -1
  118. package/dist/cjs/rx-schema-helper.js +9 -3
  119. package/dist/cjs/rx-schema-helper.js.map +1 -1
  120. package/dist/cjs/rx-schema.js +1 -0
  121. package/dist/cjs/rx-schema.js.map +1 -1
  122. package/dist/cjs/rx-storage-helper.js +212 -129
  123. package/dist/cjs/rx-storage-helper.js.map +1 -1
  124. package/dist/cjs/types/rx-error.d.js.map +1 -1
  125. package/dist/cjs/types/rx-schema.d.js.map +1 -1
  126. package/dist/esm/change-event-buffer.js +2 -1
  127. package/dist/esm/change-event-buffer.js.map +1 -1
  128. package/dist/esm/custom-index.js +85 -12
  129. package/dist/esm/custom-index.js.map +1 -1
  130. package/dist/esm/doc-cache.js +118 -36
  131. package/dist/esm/doc-cache.js.map +1 -1
  132. package/dist/esm/event-reduce.js +10 -1
  133. package/dist/esm/event-reduce.js.map +1 -1
  134. package/dist/esm/plugin-helpers.js +16 -0
  135. package/dist/esm/plugin-helpers.js.map +1 -1
  136. package/dist/esm/plugins/attachments/index.js +3 -3
  137. package/dist/esm/plugins/attachments/index.js.map +1 -1
  138. package/dist/esm/plugins/cleanup/cleanup.js +5 -3
  139. package/dist/esm/plugins/cleanup/cleanup.js.map +1 -1
  140. package/dist/esm/plugins/crdt/index.js +52 -0
  141. package/dist/esm/plugins/crdt/index.js.map +1 -1
  142. package/dist/esm/plugins/dev-mode/check-query.js +7 -1
  143. package/dist/esm/plugins/dev-mode/check-query.js.map +1 -1
  144. package/dist/esm/plugins/dev-mode/check-schema.js +2 -1
  145. package/dist/esm/plugins/dev-mode/check-schema.js.map +1 -1
  146. package/dist/esm/plugins/dev-mode/error-messages.js +43 -5
  147. package/dist/esm/plugins/dev-mode/error-messages.js.map +1 -1
  148. package/dist/esm/plugins/encryption-crypto-js/index.js +22 -6
  149. package/dist/esm/plugins/encryption-crypto-js/index.js.map +1 -1
  150. package/dist/esm/plugins/leader-election/index.js +4 -4
  151. package/dist/esm/plugins/leader-election/index.js.map +1 -1
  152. package/dist/esm/plugins/local-documents/local-documents.js +20 -13
  153. package/dist/esm/plugins/local-documents/local-documents.js.map +1 -1
  154. package/dist/esm/plugins/migration-schema/migration-helpers.js +3 -0
  155. package/dist/esm/plugins/migration-schema/migration-helpers.js.map +1 -1
  156. package/dist/esm/plugins/migration-schema/rx-migration-state.js +1 -1
  157. package/dist/esm/plugins/migration-schema/rx-migration-state.js.map +1 -1
  158. package/dist/esm/plugins/pipeline/rx-pipeline.js +5 -1
  159. package/dist/esm/plugins/pipeline/rx-pipeline.js.map +1 -1
  160. package/dist/esm/plugins/query-builder/mquery/nosql-query-builder.js +4 -2
  161. package/dist/esm/plugins/query-builder/mquery/nosql-query-builder.js.map +1 -1
  162. package/dist/esm/plugins/replication/index.js +40 -2
  163. package/dist/esm/plugins/replication/index.js.map +1 -1
  164. package/dist/esm/plugins/replication-google-drive/document-handling.js +17 -6
  165. package/dist/esm/plugins/replication-google-drive/document-handling.js.map +1 -1
  166. package/dist/esm/plugins/replication-google-drive/google-drive-helper.js +1 -1
  167. package/dist/esm/plugins/replication-google-drive/google-drive-helper.js.map +1 -1
  168. package/dist/esm/plugins/replication-google-drive/google-drive-types.js.map +1 -1
  169. package/dist/esm/plugins/replication-google-drive/signaling.js +4 -1
  170. package/dist/esm/plugins/replication-google-drive/signaling.js.map +1 -1
  171. package/dist/esm/plugins/replication-google-drive/upstream.js +7 -4
  172. package/dist/esm/plugins/replication-google-drive/upstream.js.map +1 -1
  173. package/dist/esm/plugins/replication-microsoft-onedrive/signaling.js +4 -1
  174. package/dist/esm/plugins/replication-microsoft-onedrive/signaling.js.map +1 -1
  175. package/dist/esm/plugins/state/rx-state.js +15 -4
  176. package/dist/esm/plugins/state/rx-state.js.map +1 -1
  177. package/dist/esm/plugins/storage-dexie/rx-storage-instance-dexie.js +1 -8
  178. package/dist/esm/plugins/storage-dexie/rx-storage-instance-dexie.js.map +1 -1
  179. package/dist/esm/plugins/storage-memory/binary-search-bounds.js +107 -40
  180. package/dist/esm/plugins/storage-memory/binary-search-bounds.js.map +1 -1
  181. package/dist/esm/plugins/storage-memory/memory-helper.js +128 -41
  182. package/dist/esm/plugins/storage-memory/memory-helper.js.map +1 -1
  183. package/dist/esm/plugins/storage-memory/memory-indexes.js +1 -0
  184. package/dist/esm/plugins/storage-memory/memory-indexes.js.map +1 -1
  185. package/dist/esm/plugins/storage-memory/memory-types.js.map +1 -1
  186. package/dist/esm/plugins/storage-memory/rx-storage-instance-memory.js +90 -30
  187. package/dist/esm/plugins/storage-memory/rx-storage-instance-memory.js.map +1 -1
  188. package/dist/esm/plugins/storage-mongodb/mongodb-helper.js +39 -0
  189. package/dist/esm/plugins/storage-mongodb/mongodb-helper.js.map +1 -1
  190. package/dist/esm/plugins/storage-mongodb/rx-storage-instance-mongodb.js +8 -8
  191. package/dist/esm/plugins/storage-mongodb/rx-storage-instance-mongodb.js.map +1 -1
  192. package/dist/esm/plugins/test-utils/config.js +1 -1
  193. package/dist/esm/plugins/test-utils/config.js.map +1 -1
  194. package/dist/esm/plugins/test-utils/performance.js +122 -92
  195. package/dist/esm/plugins/test-utils/performance.js.map +1 -1
  196. package/dist/esm/plugins/test-utils/schema-objects.js +1 -1
  197. package/dist/esm/plugins/test-utils/schema-objects.js.map +1 -1
  198. package/dist/esm/plugins/test-utils/test-util.js +59 -0
  199. package/dist/esm/plugins/test-utils/test-util.js.map +1 -1
  200. package/dist/esm/plugins/utils/utils-map.js +2 -2
  201. package/dist/esm/plugins/utils/utils-map.js.map +1 -1
  202. package/dist/esm/plugins/utils/utils-object-deep-equal.js +3 -2
  203. package/dist/esm/plugins/utils/utils-object-deep-equal.js.map +1 -1
  204. package/dist/esm/plugins/utils/utils-object-dot-prop.js +25 -0
  205. package/dist/esm/plugins/utils/utils-object-dot-prop.js.map +1 -1
  206. package/dist/esm/plugins/utils/utils-object.js +102 -27
  207. package/dist/esm/plugins/utils/utils-object.js.map +1 -1
  208. package/dist/esm/plugins/utils/utils-other.js +9 -4
  209. package/dist/esm/plugins/utils/utils-other.js.map +1 -1
  210. package/dist/esm/plugins/utils/utils-premium.js +5 -23
  211. package/dist/esm/plugins/utils/utils-premium.js.map +1 -1
  212. package/dist/esm/plugins/utils/utils-revision.js +20 -10
  213. package/dist/esm/plugins/utils/utils-revision.js.map +1 -1
  214. package/dist/esm/plugins/utils/utils-rxdb-version.js +1 -1
  215. package/dist/esm/plugins/utils/utils-rxdb-version.js.map +1 -1
  216. package/dist/esm/plugins/utils/utils-string.js +11 -8
  217. package/dist/esm/plugins/utils/utils-string.js.map +1 -1
  218. package/dist/esm/plugins/utils/utils-time.js +21 -16
  219. package/dist/esm/plugins/utils/utils-time.js.map +1 -1
  220. package/dist/esm/query-cache.js +7 -5
  221. package/dist/esm/query-cache.js.map +1 -1
  222. package/dist/esm/query-planner.js +2 -2
  223. package/dist/esm/query-planner.js.map +1 -1
  224. package/dist/esm/replication-protocol/downstream.js +1 -1
  225. package/dist/esm/replication-protocol/downstream.js.map +1 -1
  226. package/dist/esm/rx-collection-helper.js +12 -7
  227. package/dist/esm/rx-collection-helper.js.map +1 -1
  228. package/dist/esm/rx-collection.js +35 -7
  229. package/dist/esm/rx-collection.js.map +1 -1
  230. package/dist/esm/rx-database.js +40 -7
  231. package/dist/esm/rx-database.js.map +1 -1
  232. package/dist/esm/rx-document.js +11 -4
  233. package/dist/esm/rx-document.js.map +1 -1
  234. package/dist/esm/rx-query-helper.js +35 -12
  235. package/dist/esm/rx-query-helper.js.map +1 -1
  236. package/dist/esm/rx-query-single-result.js +10 -3
  237. package/dist/esm/rx-query-single-result.js.map +1 -1
  238. package/dist/esm/rx-query.js +72 -29
  239. package/dist/esm/rx-query.js.map +1 -1
  240. package/dist/esm/rx-schema-helper.js +9 -3
  241. package/dist/esm/rx-schema-helper.js.map +1 -1
  242. package/dist/esm/rx-schema.js +1 -0
  243. package/dist/esm/rx-schema.js.map +1 -1
  244. package/dist/esm/rx-storage-helper.js +176 -94
  245. package/dist/esm/rx-storage-helper.js.map +1 -1
  246. package/dist/esm/types/rx-error.d.js.map +1 -1
  247. package/dist/esm/types/rx-schema.d.js.map +1 -1
  248. package/dist/types/custom-index.d.ts +5 -0
  249. package/dist/types/doc-cache.d.ts +1 -1
  250. package/dist/types/plugins/dev-mode/error-messages.d.ts +36 -0
  251. package/dist/types/plugins/leader-election/index.d.ts +1 -0
  252. package/dist/types/plugins/replication-google-drive/document-handling.d.ts +4 -1
  253. package/dist/types/plugins/replication-google-drive/google-drive-types.d.ts +1 -0
  254. package/dist/types/plugins/state/rx-state.d.ts +1 -1
  255. package/dist/types/plugins/storage-denokv/index.d.ts +1 -1
  256. package/dist/types/plugins/storage-dexie/rx-storage-dexie.d.ts +1 -1
  257. package/dist/types/plugins/storage-localstorage/index.d.ts +1 -1
  258. package/dist/types/plugins/storage-memory/binary-search-bounds.d.ts +21 -10
  259. package/dist/types/plugins/storage-memory/memory-helper.d.ts +7 -3
  260. package/dist/types/plugins/storage-memory/memory-types.d.ts +5 -0
  261. package/dist/types/plugins/storage-mongodb/mongodb-helper.d.ts +9 -1
  262. package/dist/types/plugins/storage-mongodb/rx-storage-instance-mongodb.d.ts +2 -2
  263. package/dist/types/plugins/storage-mongodb/rx-storage-mongodb.d.ts +1 -1
  264. package/dist/types/plugins/storage-remote/rx-storage-remote.d.ts +1 -1
  265. package/dist/types/plugins/storage-sqlite/index.d.ts +1 -1
  266. package/dist/types/plugins/test-utils/performance.d.ts +36 -0
  267. package/dist/types/plugins/test-utils/test-util.d.ts +17 -0
  268. package/dist/types/plugins/utils/utils-object.d.ts +8 -3
  269. package/dist/types/plugins/utils/utils-premium.d.ts +0 -2
  270. package/dist/types/plugins/utils/utils-rxdb-version.d.ts +1 -1
  271. package/dist/types/rx-database.d.ts +1 -1
  272. package/dist/types/rx-query-single-result.d.ts +1 -1
  273. package/dist/types/rx-query.d.ts +3 -2
  274. package/dist/types/rx-storage-helper.d.ts +15 -0
  275. package/dist/types/types/rx-error.d.ts +3 -0
  276. package/dist/types/types/rx-schema.d.ts +5 -0
  277. package/eslint.config.mjs +2 -1
  278. package/package.json +38 -35
  279. package/scripts/check-code-block-line-length.js +91 -0
  280. package/scripts/check-em-dashes.js +53 -0
  281. package/scripts/copy-path.mjs +20 -0
  282. package/scripts/docs-fetch-git-history.mjs +36 -0
  283. package/scripts/fix-types.mjs +15 -8
  284. package/scripts/install-foundationdb.sh +0 -6
  285. package/scripts/notify-indexnow.mjs +171 -0
  286. package/scripts/start-foundationdb-docker.sh +73 -0
  287. package/src/change-event-buffer.ts +4 -1
  288. package/src/custom-index.ts +93 -16
  289. package/src/doc-cache.ts +117 -41
  290. package/src/event-reduce.ts +10 -1
  291. package/src/plugin-helpers.ts +10 -0
  292. package/src/plugins/attachments/index.ts +10 -12
  293. package/src/plugins/cleanup/cleanup.ts +5 -3
  294. package/src/plugins/crdt/index.ts +55 -0
  295. package/src/plugins/dev-mode/check-query.ts +7 -1
  296. package/src/plugins/dev-mode/check-schema.ts +2 -1
  297. package/src/plugins/dev-mode/error-messages.ts +45 -5
  298. package/src/plugins/encryption-crypto-js/index.ts +18 -6
  299. package/src/plugins/leader-election/index.ts +9 -8
  300. package/src/plugins/local-documents/local-documents.ts +21 -12
  301. package/src/plugins/migration-schema/migration-helpers.ts +3 -0
  302. package/src/plugins/migration-schema/rx-migration-state.ts +1 -1
  303. package/src/plugins/pipeline/rx-pipeline.ts +5 -1
  304. package/src/plugins/query-builder/mquery/nosql-query-builder.ts +8 -2
  305. package/src/plugins/replication/index.ts +41 -3
  306. package/src/plugins/replication-google-drive/document-handling.ts +17 -5
  307. package/src/plugins/replication-google-drive/google-drive-helper.ts +1 -1
  308. package/src/plugins/replication-google-drive/google-drive-types.ts +1 -0
  309. package/src/plugins/replication-google-drive/signaling.ts +4 -1
  310. package/src/plugins/replication-google-drive/upstream.ts +7 -4
  311. package/src/plugins/replication-microsoft-onedrive/signaling.ts +4 -1
  312. package/src/plugins/state/rx-state.ts +17 -5
  313. package/src/plugins/storage-dexie/rx-storage-instance-dexie.ts +0 -27
  314. package/src/plugins/storage-memory/binary-search-bounds.ts +105 -40
  315. package/src/plugins/storage-memory/memory-helper.ts +158 -67
  316. package/src/plugins/storage-memory/memory-indexes.ts +1 -0
  317. package/src/plugins/storage-memory/memory-types.ts +5 -0
  318. package/src/plugins/storage-memory/rx-storage-instance-memory.ts +104 -53
  319. package/src/plugins/storage-mongodb/mongodb-helper.ts +43 -1
  320. package/src/plugins/storage-mongodb/rx-storage-instance-mongodb.ts +11 -9
  321. package/src/plugins/test-utils/config.ts +2 -1
  322. package/src/plugins/test-utils/performance.ts +159 -85
  323. package/src/plugins/test-utils/schema-objects.ts +1 -1
  324. package/src/plugins/test-utils/test-util.ts +71 -0
  325. package/src/plugins/utils/utils-map.ts +2 -2
  326. package/src/plugins/utils/utils-object-deep-equal.ts +2 -4
  327. package/src/plugins/utils/utils-object-dot-prop.ts +25 -0
  328. package/src/plugins/utils/utils-object.ts +103 -28
  329. package/src/plugins/utils/utils-other.ts +9 -4
  330. package/src/plugins/utils/utils-premium.ts +11 -37
  331. package/src/plugins/utils/utils-revision.ts +20 -9
  332. package/src/plugins/utils/utils-rxdb-version.ts +1 -1
  333. package/src/plugins/utils/utils-string.ts +11 -9
  334. package/src/plugins/utils/utils-time.ts +21 -17
  335. package/src/query-cache.ts +6 -5
  336. package/src/query-planner.ts +2 -2
  337. package/src/replication-protocol/downstream.ts +1 -1
  338. package/src/rx-collection-helper.ts +12 -6
  339. package/src/rx-collection.ts +39 -8
  340. package/src/rx-database.ts +49 -17
  341. package/src/rx-document.ts +12 -3
  342. package/src/rx-query-helper.ts +36 -15
  343. package/src/rx-query-single-result.ts +10 -3
  344. package/src/rx-query.ts +48 -8
  345. package/src/rx-schema-helper.ts +7 -4
  346. package/src/rx-schema.ts +1 -0
  347. package/src/rx-storage-helper.ts +210 -139
  348. package/src/types/rx-error.d.ts +3 -0
  349. package/src/types/rx-schema.d.ts +5 -0
@@ -1 +1 @@
1
- {"version":3,"file":"binary-search-bounds.js","names":["ge","a","y","c","l","h","i","m","x","p","undefined","gt","lt","le","eq","norm","f","length","boundGE","boundGT","boundLT","boundLE","boundEQ"],"sources":["../../../../src/plugins/storage-memory/binary-search-bounds.ts"],"sourcesContent":["/**\r\n * Everything in this file was copied and adapted from\r\n * @link https://github.com/mikolalysenko/binary-search-bounds\r\n *\r\n * We should use the original npm module instead when this bug is fixed:\r\n * @link https://github.com/mikolalysenko/binary-search-bounds/pull/14\r\n */\r\n\r\n\r\n\r\ntype Compare<T> = ((a: T, b: T) => number | null | undefined);\r\n\r\nfunction ge<T>(a: T[], y: T, c: Compare<T>, l?: any, h?: any): number {\r\n let i: number = h + 1;\r\n while (l <= h) {\r\n const m = (l + h) >>> 1;\r\n const x: any = a[m];\r\n const p: any = (c !== undefined) ? c(x, y) : (x - (y as any));\r\n if (p >= 0) {\r\n i = m; h = m - 1;\r\n } else {\r\n l = m + 1;\r\n }\r\n }\r\n return i;\r\n}\r\n\r\nfunction gt<T>(a: T[], y: T, c: Compare<T>, l?: any, h?: any): number {\r\n let i = h + 1;\r\n while (l <= h) {\r\n const m = (l + h) >>> 1;\r\n const x = a[m];\r\n const p: any = (c !== undefined) ? c(x, y) : ((x as any) - (y as any));\r\n if (p > 0) {\r\n i = m; h = m - 1;\r\n } else {\r\n l = m + 1;\r\n }\r\n }\r\n return i;\r\n}\r\n\r\nfunction lt<T>(a: T[], y: T, c: Compare<T>, l?: any, h?: any): number {\r\n let i = l - 1;\r\n while (l <= h) {\r\n const m = (l + h) >>> 1, x = a[m];\r\n const p: any = (c !== undefined) ? c(x, y) : ((x as any) - (y as any));\r\n if (p < 0) {\r\n i = m; l = m + 1;\r\n } else {\r\n h = m - 1;\r\n }\r\n }\r\n return i;\r\n}\r\n\r\nfunction le<T>(a: T[], y: T, c: Compare<T>, l?: any, h?: any): number {\r\n let i = l - 1;\r\n while (l <= h) {\r\n const m = (l + h) >>> 1, x = a[m];\r\n const p: any = (c !== undefined) ? c(x, y) : ((x as any) - (y as any));\r\n if (p <= 0) {\r\n i = m; l = m + 1;\r\n } else {\r\n h = m - 1;\r\n }\r\n }\r\n return i;\r\n}\r\n\r\nfunction eq<T>(a: T[], y: T, c: Compare<T>, l?: any, h?: any): number {\r\n while (l <= h) {\r\n const m = (l + h) >>> 1, x = a[m];\r\n const p: any = (c !== undefined) ? c(x, y) : ((x as any) - (y as any));\r\n if (p === 0) {\r\n return m;\r\n }\r\n if (p <= 0) {\r\n l = m + 1;\r\n } else {\r\n h = m - 1;\r\n }\r\n }\r\n return -1;\r\n}\r\n\r\nfunction norm<T>(a: T[], y: T, c: Compare<T>, l: any, h: any, f: any) {\r\n return f(a, y, c, (l === undefined) ? 0 : l | 0, (h === undefined) ? a.length - 1 : h | 0);\r\n}\r\n\r\n\r\nexport function boundGE<T>(a: T[], y: T, c: Compare<T>, l?: any, h?: any) {\r\n return norm(a, y, c, l, h, ge);\r\n}\r\nexport function boundGT<T>(a: T[], y: T, c: Compare<T>, l?: any, h?: any) {\r\n return norm(a, y, c, l, h, gt);\r\n}\r\nexport function boundLT<T>(a: T[], y: T, c: Compare<T>, l?: any, h?: any) {\r\n return norm(a, y, c, l, h, lt);\r\n}\r\nexport function boundLE<T>(a: T[], y: T, c: Compare<T>, l?: any, h?: any) {\r\n return norm(a, y, c, l, h, le);\r\n}\r\nexport function boundEQ<T>(a: T[], y: T, c: Compare<T>, l?: any, h?: any) {\r\n return norm(a, y, c, l, h, eq);\r\n}\r\n"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA,SAASA,EAAEA,CAAIC,CAAM,EAAEC,CAAI,EAAEC,CAAa,EAAEC,CAAO,EAAEC,CAAO,EAAU;EAClE,IAAIC,CAAS,GAAGD,CAAC,GAAG,CAAC;EACrB,OAAOD,CAAC,IAAIC,CAAC,EAAE;IACX,IAAME,CAAC,GAAIH,CAAC,GAAGC,CAAC,KAAM,CAAC;IACvB,IAAMG,CAAM,GAAGP,CAAC,CAACM,CAAC,CAAC;IACnB,IAAME,CAAM,GAAIN,CAAC,KAAKO,SAAS,GAAIP,CAAC,CAACK,CAAC,EAAEN,CAAC,CAAC,GAAIM,CAAC,GAAIN,CAAU;IAC7D,IAAIO,CAAC,IAAI,CAAC,EAAE;MACRH,CAAC,GAAGC,CAAC;MAAEF,CAAC,GAAGE,C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AC,EAAEC,CAAC,EAAEC,CAAC,EAAEC,CAAC,EAAES,EAAE,CAAC;AAClC","ignoreList":[]}
1
+ {"version":3,"file":"binary-search-bounds.js","names":["boundGE","a","y","c","lo","hi","l","undefined","h","length","i","m","boundGT","boundLT","boundLE","boundEQ","p","boundGEByIndexString","indexString","boundGTByIndexString","boundEQByIndexString","s","boundLTByIndexString","boundLEByIndexString"],"sources":["../../../../src/plugins/storage-memory/binary-search-bounds.ts"],"sourcesContent":["/**\r\n * Optimized binary search functions for the memory storage.\r\n * Based on https://github.com/mikolalysenko/binary-search-bounds\r\n * but with performance improvements:\r\n * - Removed unnecessary undefined checks for comparator\r\n * - Inlined the norm() wrapper to avoid extra function calls\r\n * - Added string-specialized variants to avoid temporary array allocations\r\n */\r\n\r\ntype Compare<T> = ((a: T, b: T) => number | null | undefined);\r\n\r\nexport function boundGE<T>(a: T[], y: T, c: Compare<T>, lo?: any, hi?: any): number {\r\n let l: number = lo === undefined ? 0 : lo | 0;\r\n let h: number = hi === undefined ? a.length - 1 : hi | 0;\r\n let i: number = h + 1;\r\n while (l <= h) {\r\n const m = (l + h) >>> 1;\r\n if ((c(a[m], y) as number) >= 0) {\r\n i = m; h = m - 1;\r\n } else {\r\n l = m + 1;\r\n }\r\n }\r\n return i;\r\n}\r\n\r\nexport function boundGT<T>(a: T[], y: T, c: Compare<T>, lo?: any, hi?: any): number {\r\n let l: number = lo === undefined ? 0 : lo | 0;\r\n let h: number = hi === undefined ? a.length - 1 : hi | 0;\r\n let i = h + 1;\r\n while (l <= h) {\r\n const m = (l + h) >>> 1;\r\n if ((c(a[m], y) as number) > 0) {\r\n i = m; h = m - 1;\r\n } else {\r\n l = m + 1;\r\n }\r\n }\r\n return i;\r\n}\r\n\r\nexport function boundLT<T>(a: T[], y: T, c: Compare<T>, lo?: any, hi?: any): number {\r\n let l: number = lo === undefined ? 0 : lo | 0;\r\n let h: number = hi === undefined ? a.length - 1 : hi | 0;\r\n let i = l - 1;\r\n while (l <= h) {\r\n const m = (l + h) >>> 1;\r\n if ((c(a[m], y) as number) < 0) {\r\n i = m; l = m + 1;\r\n } else {\r\n h = m - 1;\r\n }\r\n }\r\n return i;\r\n}\r\n\r\nexport function boundLE<T>(a: T[], y: T, c: Compare<T>, lo?: any, hi?: any): number {\r\n let l: number = lo === undefined ? 0 : lo | 0;\r\n let h: number = hi === undefined ? a.length - 1 : hi | 0;\r\n let i = l - 1;\r\n while (l <= h) {\r\n const m = (l + h) >>> 1;\r\n if ((c(a[m], y) as number) <= 0) {\r\n i = m; l = m + 1;\r\n } else {\r\n h = m - 1;\r\n }\r\n }\r\n return i;\r\n}\r\n\r\nexport function boundEQ<T>(a: T[], y: T, c: Compare<T>, lo?: any, hi?: any): number {\r\n let l: number = lo === undefined ? 0 : lo | 0;\r\n let h: number = hi === undefined ? a.length - 1 : hi | 0;\r\n while (l <= h) {\r\n const m = (l + h) >>> 1;\r\n const p = c(a[m], y) as number;\r\n if (p === 0) {\r\n return m;\r\n }\r\n if (p <= 0) {\r\n l = m + 1;\r\n } else {\r\n h = m - 1;\r\n }\r\n }\r\n return -1;\r\n}\r\n\r\n/**\r\n * Specialized binary search functions that compare DocWithIndexString\r\n * entries directly against an index string, avoiding temporary array allocations.\r\n * Used in query() and count() hot paths.\r\n */\r\nexport function boundGEByIndexString<T extends [string, ...any[]]>(a: T[], indexString: string): number {\r\n let l = 0;\r\n let h = a.length - 1;\r\n let i: number = h + 1;\r\n while (l <= h) {\r\n const m = (l + h) >>> 1;\r\n if (a[m][0] >= indexString) {\r\n i = m; h = m - 1;\r\n } else {\r\n l = m + 1;\r\n }\r\n }\r\n return i;\r\n}\r\n\r\nexport function boundGTByIndexString<T extends [string, ...any[]]>(a: T[], indexString: string): number {\r\n let l = 0;\r\n let h = a.length - 1;\r\n let i = h + 1;\r\n while (l <= h) {\r\n const m = (l + h) >>> 1;\r\n if (a[m][0] > indexString) {\r\n i = m; h = m - 1;\r\n } else {\r\n l = m + 1;\r\n }\r\n }\r\n return i;\r\n}\r\n\r\nexport function boundEQByIndexString<T extends [string, ...any[]]>(a: T[], indexString: string): number {\r\n let l = 0;\r\n let h = a.length - 1;\r\n while (l <= h) {\r\n const m = (l + h) >>> 1;\r\n const s = a[m][0];\r\n if (s === indexString) {\r\n return m;\r\n }\r\n if (s < indexString) {\r\n l = m + 1;\r\n } else {\r\n h = m - 1;\r\n }\r\n }\r\n return -1;\r\n}\r\n\r\nexport function boundLTByIndexString<T extends [string, ...any[]]>(a: T[], indexString: string): number {\r\n let l = 0;\r\n let h = a.length - 1;\r\n let i = l - 1;\r\n while (l <= h) {\r\n const m = (l + h) >>> 1;\r\n if (a[m][0] < indexString) {\r\n i = m; l = m + 1;\r\n } else {\r\n h = m - 1;\r\n }\r\n }\r\n return i;\r\n}\r\n\r\nexport function boundLEByIndexString<T extends [string, ...any[]]>(a: T[], indexString: string): number {\r\n let l = 0;\r\n let h = a.length - 1;\r\n let i = l - 1;\r\n while (l <= h) {\r\n const m = (l + h) >>> 1;\r\n if (a[m][0] <= indexString) {\r\n i = m; l = m + 1;\r\n } else {\r\n h = m - 1;\r\n }\r\n }\r\n return i;\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIO,SAASA,OAAOA,CAAIC,CAAM,EAAEC,CAAI,EAAEC,CAAa,EAAEC,EAAQ,EAAEC,EAAQ,EAAU;EAChF,IAAIC,CAAS,GAAGF,EAAE,KAAKG,SAAS,GAAG,CAAC,GAAGH,EAAE,GAAG,CAAC;EAC7C,IAAII,CAAS,GAAGH,EAAE,KAAKE,SAAS,GAAGN,CAAC,CAACQ,MAAM,GAAG,CAAC,GAAGJ,EAAE,GAAG,CAAC;EACxD,IAAIK,CAAS,GAAGF,CAAC,GAAG,CAAC;EACrB,OAAOF,CAAC,IAAIE,CAAC,EAAE;IACX,IAAMG,CAAC,GAAIL,CAAC,GAAGE,CAAC,KAAM,CAAC;IACvB,IAAKL,CAAC,CAACF,C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AGK,CAAC,GAAG,CAAC;IACpB,CAAC,MAAM;MACHH,CAAC,GAAGG,CAAC,GAAG,CAAC;IACb;EACJ;EACA,OAAOD,CAAC;AACZ;AAEO,SAASa,oBAAoBA,CAA+BtB,CAAM,EAAEiB,WAAmB,EAAU;EACpG,IAAIZ,CAAC,GAAG,CAAC;EACT,IAAIE,CAAC,GAAGP,CAAC,CAACQ,MAAM,GAAG,CAAC;EACpB,IAAIC,CAAC,GAAGJ,CAAC,GAAG,CAAC;EACb,OAAOA,CAAC,IAAIE,CAAC,EAAE;IACX,IAAMG,CAAC,GAAIL,CAAC,GAAGE,CAAC,KAAM,CAAC;IACvB,IAAIP,CAAC,CAACU,CAAC,CAAC,CAAC,CAAC,CAAC,IAAIO,WAAW,EAAE;MACxBR,CAAC,GAAGC,CAAC;MAAEL,CAAC,GAAGK,CAAC,GAAG,CAAC;IACpB,CAAC,MAAM;MACHH,CAAC,GAAGG,CAAC,GAAG,CAAC;IACb;EACJ;EACA,OAAOD,CAAC;AACZ","ignoreList":[]}
@@ -24,6 +24,14 @@ function ensureNotRemoved(instance) {
24
24
  function attachmentMapKey(documentId, attachmentId) {
25
25
  return documentId + '||' + attachmentId;
26
26
  }
27
+
28
+ /**
29
+ * @performance
30
+ * Threshold for using in-place splice vs. full merge-sort when inserting
31
+ * documents into indexes. Below this batch size, in-place binary search + splice
32
+ * is faster because it avoids allocating a new full-size array and copying all elements.
33
+ */
34
+ var IN_PLACE_INSERT_THRESHOLD = 64;
27
35
  function sortByIndexStringComparator(a, b) {
28
36
  if (a[0] < b[0]) {
29
37
  return -1;
@@ -37,29 +45,57 @@ function sortByIndexStringComparator(a, b) {
37
45
  */
38
46
  function putWriteRowToState(docId, state, stateByIndex, document, docInState) {
39
47
  state.documents.set(docId, document);
40
- for (var i = 0; i < stateByIndex.length; ++i) {
48
+ var stateByIndexLength = stateByIndex.length;
49
+ for (var i = 0; i < stateByIndexLength; ++i) {
41
50
  var byIndex = stateByIndex[i];
42
51
  var docsWithIndex = byIndex.docsWithIndex;
43
52
  var getIndexableString = byIndex.getIndexableString;
44
53
  var newIndexString = getIndexableString(document);
45
- var insertPosition = (0, _arrayPushAtSortPosition.pushAtSortPosition)(docsWithIndex, [newIndexString, document, docId], sortByIndexStringComparator, 0);
46
54
 
47
55
  /**
48
- * Remove previous if it was in the state
56
+ * @performance
57
+ * When updating a document, first compute whether the index changed.
58
+ * If it did not change, we only need to update the document reference
59
+ * in-place without any splice operations.
49
60
  */
50
61
  if (docInState) {
51
62
  var previousIndexString = getIndexableString(docInState);
52
63
  if (previousIndexString === newIndexString) {
53
64
  /**
54
65
  * Performance shortcut.
55
- * If index was not changed -> The old doc must be before or after the new one.
66
+ * Index did not change, so the old entry is at the same position.
67
+ * We can find it by string-specialized binary search and update in-place.
56
68
  */
57
- var prev = docsWithIndex[insertPosition - 1];
58
- if (prev && prev[2] === docId) {
69
+ var eqPos = (0, _binarySearchBounds.boundEQByIndexString)(docsWithIndex, previousIndexString);
70
+ if (eqPos !== -1) {
71
+ /**
72
+ * There might be multiple entries with the same index string
73
+ * (e.g. different documents). Search around eqPos for ours.
74
+ */
75
+ if (docsWithIndex[eqPos][2] === docId) {
76
+ docsWithIndex[eqPos][1] = document;
77
+ continue;
78
+ }
79
+ // Check neighbors
80
+ var prev = docsWithIndex[eqPos - 1];
81
+ if (prev && prev[0] === previousIndexString && prev[2] === docId) {
82
+ docsWithIndex[eqPos - 1][1] = document;
83
+ continue;
84
+ }
85
+ var next = docsWithIndex[eqPos + 1];
86
+ if (next && next[0] === previousIndexString && next[2] === docId) {
87
+ docsWithIndex[eqPos + 1][1] = document;
88
+ continue;
89
+ }
90
+ }
91
+ // Fallback: use the old insert+remove approach
92
+ var insertPosition = (0, _arrayPushAtSortPosition.pushAtSortPosition)(docsWithIndex, [newIndexString, document, docId], sortByIndexStringComparator, 0);
93
+ var prevEntry = docsWithIndex[insertPosition - 1];
94
+ if (prevEntry && prevEntry[2] === docId) {
59
95
  docsWithIndex.splice(insertPosition - 1, 1);
60
96
  } else {
61
- var next = docsWithIndex[insertPosition + 1];
62
- if (next[2] === docId) {
97
+ var nextEntry = docsWithIndex[insertPosition + 1];
98
+ if (nextEntry[2] === docId) {
63
99
  docsWithIndex.splice(insertPosition + 1, 1);
64
100
  } else {
65
101
  throw (0, _rxError.newRxError)('SNH', {
@@ -70,26 +106,35 @@ function putWriteRowToState(docId, state, stateByIndex, document, docInState) {
70
106
  });
71
107
  }
72
108
  }
109
+ continue;
73
110
  } else {
74
111
  /**
75
- * Index changed, we must search for the old one and remove it.
112
+ * Index changed, we must remove the old entry and insert the new one.
76
113
  */
77
- var indexBefore = (0, _binarySearchBounds.boundEQ)(docsWithIndex, [previousIndexString], compareDocsWithIndex);
78
- docsWithIndex.splice(indexBefore, 1);
114
+ var indexBefore = (0, _binarySearchBounds.boundEQByIndexString)(docsWithIndex, previousIndexString);
115
+ if (indexBefore !== -1) {
116
+ docsWithIndex.splice(indexBefore, 1);
117
+ }
79
118
  }
80
119
  }
120
+ (0, _arrayPushAtSortPosition.pushAtSortPosition)(docsWithIndex, [newIndexString, document, docId], sortByIndexStringComparator, 0);
81
121
  }
82
122
  }
83
123
 
84
124
  /**
85
125
  * @hotPath
86
126
  * Efficiently inserts multiple documents into the state at once.
87
- * Instead of inserting one-by-one with Array.splice() (O(n) per insert),
88
- * this pre-computes all index entries, sorts them, and merges them into
89
- * the existing sorted arrays in a single pass (O(n log n + n + m)).
127
+ *
128
+ * Uses two strategies based on batch size:
129
+ * - For small batches (relative to existing index size), uses in-place
130
+ * binary search + splice per document. This avoids allocating a new
131
+ * full-size array and copying all elements, reducing GC pressure.
132
+ * - For large batches (or empty indexes), pre-computes all index entries,
133
+ * sorts them, and merges into the existing sorted arrays in a single pass.
90
134
  */
91
135
  function bulkInsertToState(primaryPath, state, stateByIndex, docs) {
92
136
  var docsLength = docs.length;
137
+ var stateByIndexLength = stateByIndex.length;
93
138
 
94
139
  // Extract documents and docIds once, store in Map
95
140
  var documents = new Array(docsLength);
@@ -102,36 +147,74 @@ function bulkInsertToState(primaryPath, state, stateByIndex, docs) {
102
147
  state.documents.set(docId, doc);
103
148
  }
104
149
 
105
- // For each index, batch-compute entries, sort, and merge
106
- for (var indexI = 0; indexI < stateByIndex.length; ++indexI) {
107
- var byIndex = stateByIndex[indexI];
108
- var docsWithIndex = byIndex.docsWithIndex;
109
- var getIndexableString = byIndex.getIndexableString;
110
-
111
- // Build new entries
112
- var newEntries = new Array(docsLength);
113
- for (var _i = 0; _i < docsLength; ++_i) {
114
- var _doc = documents[_i];
115
- newEntries[_i] = [getIndexableString(_doc), _doc, docIds[_i]];
150
+ /**
151
+ * @performance
152
+ * For small batch sizes, use in-place binary search + splice
153
+ * instead of creating a full merged array copy. This is faster
154
+ * for serial inserts and small bulk inserts because it avoids:
155
+ * - Allocating a new array of size n+m
156
+ * - Copying all n existing elements
157
+ * - GC pressure from discarding the old array
158
+ *
159
+ * The threshold is based on when the merge approach becomes more
160
+ * efficient than individual splices.
161
+ */
162
+ var useInPlaceInsert = docsLength < IN_PLACE_INSERT_THRESHOLD;
163
+ if (useInPlaceInsert) {
164
+ for (var indexI = 0; indexI < stateByIndexLength; ++indexI) {
165
+ var byIndex = stateByIndex[indexI];
166
+ var docsWithIndex = byIndex.docsWithIndex;
167
+ var getIndexableString = byIndex.getIndexableString;
168
+ if (docsWithIndex.length === 0) {
169
+ for (var _i = 0; _i < docsLength; ++_i) {
170
+ var _doc = documents[_i];
171
+ var indexString = getIndexableString(_doc);
172
+ docsWithIndex.push([indexString, _doc, docIds[_i]]);
173
+ }
174
+ docsWithIndex.sort(sortByIndexStringComparator);
175
+ } else {
176
+ for (var _i2 = 0; _i2 < docsLength; ++_i2) {
177
+ var _doc2 = documents[_i2];
178
+ var _indexString = getIndexableString(_doc2);
179
+ var newEntry = [_indexString, _doc2, docIds[_i2]];
180
+ (0, _arrayPushAtSortPosition.pushAtSortPosition)(docsWithIndex, newEntry, sortByIndexStringComparator, 0);
181
+ }
182
+ }
116
183
  }
184
+ } else {
185
+ // For each index, batch-compute entries, sort, and merge
186
+ for (var _indexI = 0; _indexI < stateByIndexLength; ++_indexI) {
187
+ var _byIndex = stateByIndex[_indexI];
188
+ var _docsWithIndex = _byIndex.docsWithIndex;
189
+ var _getIndexableString = _byIndex.getIndexableString;
117
190
 
118
- // Sort by index string
119
- newEntries.sort(sortByIndexStringComparator);
120
- if (docsWithIndex.length === 0) {
121
- // Index is empty, just assign sorted entries
122
- byIndex.docsWithIndex = newEntries;
123
- } else {
124
- // Merge sorted arrays
125
- byIndex.docsWithIndex = mergeSortedArrays(docsWithIndex, newEntries, sortByIndexStringComparator);
191
+ // Build new entries
192
+ var newEntries = new Array(docsLength);
193
+ for (var _i3 = 0; _i3 < docsLength; ++_i3) {
194
+ var _doc3 = documents[_i3];
195
+ newEntries[_i3] = [_getIndexableString(_doc3), _doc3, docIds[_i3]];
196
+ }
197
+
198
+ // Sort by index string
199
+ newEntries.sort(sortByIndexStringComparator);
200
+ if (_docsWithIndex.length === 0) {
201
+ // Index is empty, just assign sorted entries
202
+ _byIndex.docsWithIndex = newEntries;
203
+ } else {
204
+ // Merge sorted arrays
205
+ _byIndex.docsWithIndex = mergeSortedArrays(_docsWithIndex, newEntries);
206
+ }
126
207
  }
127
208
  }
128
209
  }
129
210
 
130
211
  /**
131
- * Merges two sorted arrays into a single sorted array.
212
+ * Merges two sorted DocWithIndexString arrays into a single sorted array.
132
213
  * Runs in O(n + m) where n and m are the lengths of the input arrays.
214
+ * @performance Comparator is inlined to avoid function call overhead
215
+ * per comparison, which is significant for large arrays.
133
216
  */
134
- function mergeSortedArrays(a, b, comparator) {
217
+ function mergeSortedArrays(a, b) {
135
218
  var aLen = a.length;
136
219
  var bLen = b.length;
137
220
  var result = new Array(aLen + bLen);
@@ -139,7 +222,7 @@ function mergeSortedArrays(a, b, comparator) {
139
222
  var bi = 0;
140
223
  var ri = 0;
141
224
  while (ai < aLen && bi < bLen) {
142
- if (comparator(a[ai], b[bi]) <= 0) {
225
+ if (a[ai][0] <= b[bi][0]) {
143
226
  result[ri++] = a[ai++];
144
227
  } else {
145
228
  result[ri++] = b[bi++];
@@ -156,12 +239,16 @@ function mergeSortedArrays(a, b, comparator) {
156
239
  function removeDocFromState(primaryPath, schema, state, doc) {
157
240
  var docId = doc[primaryPath];
158
241
  state.documents.delete(docId);
159
- Object.values(state.byIndex).forEach(byIndex => {
242
+ var stateByIndex = state.byIndexArray;
243
+ for (var i = 0; i < stateByIndex.length; ++i) {
244
+ var byIndex = stateByIndex[i];
160
245
  var docsWithIndex = byIndex.docsWithIndex;
161
246
  var indexString = byIndex.getIndexableString(doc);
162
- var positionInIndex = (0, _binarySearchBounds.boundEQ)(docsWithIndex, [indexString], compareDocsWithIndex);
163
- docsWithIndex.splice(positionInIndex, 1);
164
- });
247
+ var positionInIndex = (0, _binarySearchBounds.boundEQByIndexString)(docsWithIndex, indexString);
248
+ if (positionInIndex !== -1) {
249
+ docsWithIndex.splice(positionInIndex, 1);
250
+ }
251
+ }
165
252
  }
166
253
  function compareDocsWithIndex(a, b) {
167
254
  var indexStringA = a[0];
@@ -1 +1 @@
1
- {"version":3,"file":"memory-helper.js","names":["_arrayPushAtSortPosition","require","_rxError","_binarySearchBounds","getMemoryCollectionKey","databaseName","collectionName","schemaVersion","join","ensureNotRemoved","instance","internals","removed","Error","schema","version","attachmentMapKey","documentId","attachmentId","sortByIndexStringComparator","a","b","putWriteRowToState","docId","state","stateByIndex","document","docInState","documents","set","i","length","byIndex","docsWithIndex","getIndexableString","newIndexString","insertPosition","pushAtSortPosition","previousIndexString","prev","splice","next","newRxError","args","indexBefore","boundEQ","compareDocsWithIndex","bulkInsertToState","primaryPath","docs","docsLength","Array","docIds","doc","indexI","newEntries","sort","mergeSortedArrays","comparator","aLen","bLen","result","ai","bi","ri","removeDocFromState","delete","Object","values","forEach","indexString","positionInIndex","indexStringA","indexStringB"],"sources":["../../../../src/plugins/storage-memory/memory-helper.ts"],"sourcesContent":["import type {\r\n BulkWriteRow,\r\n RxDocumentData,\r\n RxJsonSchema\r\n} from '../../types/index.d.ts';\r\nimport type {\r\n DocWithIndexString,\r\n MemoryStorageInternals,\r\n MemoryStorageInternalsByIndex\r\n} from './memory-types.ts';\r\nimport type { RxStorageInstanceMemory } from './rx-storage-instance-memory.ts';\r\nimport {\r\n pushAtSortPosition\r\n} from 'array-push-at-sort-position';\r\nimport { newRxError } from '../../rx-error.ts';\r\nimport { boundEQ } from './binary-search-bounds.ts';\r\n\r\n\r\nexport function getMemoryCollectionKey(\r\n databaseName: string,\r\n collectionName: string,\r\n schemaVersion: number\r\n): string {\r\n return [\r\n databaseName,\r\n collectionName,\r\n schemaVersion\r\n ].join('--memory--');\r\n}\r\n\r\n\r\nexport function ensureNotRemoved(\r\n instance: RxStorageInstanceMemory<any>\r\n) {\r\n if (instance.internals.removed) {\r\n throw new Error(\r\n 'removed already ' +\r\n instance.databaseName + ' - ' + instance.collectionName +\r\n ' - ' + instance.schema.version\r\n );\r\n }\r\n}\r\n\r\nexport function attachmentMapKey(documentId: string, attachmentId: string): string {\r\n return documentId + '||' + attachmentId;\r\n}\r\n\r\n\r\nfunction sortByIndexStringComparator<RxDocType>(a: DocWithIndexString<RxDocType>, b: DocWithIndexString<RxDocType>) {\r\n if (a[0] < b[0]) {\r\n return -1;\r\n } else {\r\n return 1;\r\n }\r\n}\r\n\r\n\r\n\r\n/**\r\n * @hotPath\r\n */\r\nexport function putWriteRowToState<RxDocType>(\r\n docId: string,\r\n state: MemoryStorageInternals<RxDocType>,\r\n stateByIndex: MemoryStorageInternalsByIndex<RxDocType>[],\r\n document: RxDocumentData<RxDocType>,\r\n docInState?: RxDocumentData<RxDocType>\r\n) {\r\n state.documents.set(docId, document as any);\r\n for (let i = 0; i < stateByIndex.length; ++i) {\r\n const byIndex = stateByIndex[i];\r\n const docsWithIndex = byIndex.docsWithIndex;\r\n const getIndexableString = byIndex.getIndexableString;\r\n const newIndexString = getIndexableString(document as any);\r\n const insertPosition = pushAtSortPosition(\r\n docsWithIndex,\r\n [\r\n newIndexString,\r\n document,\r\n docId,\r\n ],\r\n sortByIndexStringComparator,\r\n 0\r\n );\r\n\r\n /**\r\n * Remove previous if it was in the state\r\n */\r\n if (docInState) {\r\n const previousIndexString = getIndexableString(docInState);\r\n if (previousIndexString === newIndexString) {\r\n /**\r\n * Performance shortcut.\r\n * If index was not changed -> The old doc must be before or after the new one.\r\n */\r\n const prev = docsWithIndex[insertPosition - 1];\r\n if (prev && prev[2] === docId) {\r\n docsWithIndex.splice(insertPosition - 1, 1);\r\n } else {\r\n const next = docsWithIndex[insertPosition + 1];\r\n if (next[2] === docId) {\r\n docsWithIndex.splice(insertPosition + 1, 1);\r\n } else {\r\n throw newRxError('SNH', {\r\n document,\r\n args: {\r\n byIndex\r\n }\r\n });\r\n }\r\n }\r\n } else {\r\n /**\r\n * Index changed, we must search for the old one and remove it.\r\n */\r\n const indexBefore = boundEQ(\r\n docsWithIndex,\r\n [\r\n previousIndexString\r\n ] as any,\r\n compareDocsWithIndex\r\n );\r\n docsWithIndex.splice(indexBefore, 1);\r\n }\r\n }\r\n }\r\n}\r\n\r\n\r\n/**\r\n * @hotPath\r\n * Efficiently inserts multiple documents into the state at once.\r\n * Instead of inserting one-by-one with Array.splice() (O(n) per insert),\r\n * this pre-computes all index entries, sorts them, and merges them into\r\n * the existing sorted arrays in a single pass (O(n log n + n + m)).\r\n */\r\nexport function bulkInsertToState<RxDocType>(\r\n primaryPath: string,\r\n state: MemoryStorageInternals<RxDocType>,\r\n stateByIndex: MemoryStorageInternalsByIndex<RxDocType>[],\r\n docs: { document: RxDocumentData<RxDocType> }[]\r\n) {\r\n const docsLength = docs.length;\r\n\r\n // Extract documents and docIds once, store in Map\r\n const documents: RxDocumentData<RxDocType>[] = new Array(docsLength);\r\n const docIds: string[] = new Array(docsLength);\r\n for (let i = 0; i < docsLength; ++i) {\r\n const doc = docs[i].document;\r\n const docId: string = (doc as any)[primaryPath];\r\n documents[i] = doc;\r\n docIds[i] = docId;\r\n state.documents.set(docId, doc as any);\r\n }\r\n\r\n // For each index, batch-compute entries, sort, and merge\r\n for (let indexI = 0; indexI < stateByIndex.length; ++indexI) {\r\n const byIndex = stateByIndex[indexI];\r\n const docsWithIndex = byIndex.docsWithIndex;\r\n const getIndexableString = byIndex.getIndexableString;\r\n\r\n // Build new entries\r\n const newEntries: DocWithIndexString<RxDocType>[] = new Array(docsLength);\r\n for (let i = 0; i < docsLength; ++i) {\r\n const doc = documents[i];\r\n newEntries[i] = [\r\n getIndexableString(doc as any),\r\n doc,\r\n docIds[i]\r\n ];\r\n }\r\n\r\n // Sort by index string\r\n newEntries.sort(sortByIndexStringComparator);\r\n\r\n if (docsWithIndex.length === 0) {\r\n // Index is empty, just assign sorted entries\r\n byIndex.docsWithIndex = newEntries;\r\n } else {\r\n // Merge sorted arrays\r\n byIndex.docsWithIndex = mergeSortedArrays(docsWithIndex, newEntries, sortByIndexStringComparator);\r\n }\r\n }\r\n}\r\n\r\n\r\n/**\r\n * Merges two sorted arrays into a single sorted array.\r\n * Runs in O(n + m) where n and m are the lengths of the input arrays.\r\n */\r\nfunction mergeSortedArrays<T>(\r\n a: T[],\r\n b: T[],\r\n comparator: (x: T, y: T) => number\r\n): T[] {\r\n const aLen = a.length;\r\n const bLen = b.length;\r\n const result: T[] = new Array(aLen + bLen);\r\n let ai = 0;\r\n let bi = 0;\r\n let ri = 0;\r\n\r\n while (ai < aLen && bi < bLen) {\r\n if (comparator(a[ai], b[bi]) <= 0) {\r\n result[ri++] = a[ai++];\r\n } else {\r\n result[ri++] = b[bi++];\r\n }\r\n }\r\n\r\n while (ai < aLen) {\r\n result[ri++] = a[ai++];\r\n }\r\n while (bi < bLen) {\r\n result[ri++] = b[bi++];\r\n }\r\n\r\n return result;\r\n}\r\n\r\nexport function removeDocFromState<RxDocType>(\r\n primaryPath: string,\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>,\r\n state: MemoryStorageInternals<RxDocType>,\r\n doc: RxDocumentData<RxDocType>\r\n) {\r\n const docId: string = (doc as any)[primaryPath];\r\n state.documents.delete(docId);\r\n\r\n Object.values(state.byIndex).forEach(byIndex => {\r\n const docsWithIndex = byIndex.docsWithIndex;\r\n const indexString = byIndex.getIndexableString(doc);\r\n\r\n const positionInIndex = boundEQ(\r\n docsWithIndex,\r\n [\r\n indexString\r\n ] as any,\r\n compareDocsWithIndex\r\n );\r\n docsWithIndex.splice(positionInIndex, 1);\r\n });\r\n}\r\n\r\n\r\nexport function compareDocsWithIndex<RxDocType>(\r\n a: DocWithIndexString<RxDocType>,\r\n b: DocWithIndexString<RxDocType>\r\n): 1 | 0 | -1 {\r\n const indexStringA = a[0];\r\n const indexStringB = b[0];\r\n if (indexStringA < indexStringB) {\r\n return -1;\r\n } else if (indexStringA === indexStringB) {\r\n return 0;\r\n } else {\r\n return 1;\r\n }\r\n}\r\n"],"mappings":";;;;;;;;;;;;AAWA,IAAAA,wBAAA,GAAAC,OAAA;AAGA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AAGO,SAASG,sBAAsBA,CAClCC,YAAoB,EACpBC,cAAsB,EACtBC,aAAqB,EACf;EACN,OAAO,CACHF,YAAY,EACZC,cAAc,EACdC,aAAa,CAChB,CAACC,IAAI,CAAC,YAAY,CAAC;AACxB;AAGO,SAASC,gBAAgBA,CAC5BC,QAAsC,EACxC;EACE,IAAIA,QAAQ,CAACC,SAAS,CAACC,OAAO,EAAE;IAC5B,MAAM,IAAIC,KAAK,CACX,kBAAkB,GAClBH,QAAQ,CAACL,YAAY,GAAG,KAAK,GAAGK,QAAQ,CAACJ,cAAc,GACvD,KAAK,GAAGI,QAAQ,CAACI,MAAM,CAACC,OAC5B,CAAC;EACL;AACJ;AAEO,SAASC,gBAAgBA,CAACC,UAAkB,EAAEC,YAAoB,EAAU;EAC/E,OAAOD,UAAU,GAAG,IAAI,GAAGC,YAAY;AAC3C;AAGA,SAASC,2BAA2BA,CAAYC,CAAgC,EA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GpD,CAAC,CAAC,CAAC,CAAC;EACzB,IAAMqD,YAAY,GAAGpD,CAAC,CAAC,CAAC,CAAC;EACzB,IAAImD,YAAY,GAAGC,YAAY,EAAE;IAC7B,OAAO,CAAC,CAAC;EACb,CAAC,MAAM,IAAID,YAAY,KAAKC,YAAY,EAAE;IACtC,OAAO,CAAC;EACZ,CAAC,MAAM;IACH,OAAO,CAAC;EACZ;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"memory-helper.js","names":["_arrayPushAtSortPosition","require","_rxError","_binarySearchBounds","getMemoryCollectionKey","databaseName","collectionName","schemaVersion","join","ensureNotRemoved","instance","internals","removed","Error","schema","version","attachmentMapKey","documentId","attachmentId","IN_PLACE_INSERT_THRESHOLD","sortByIndexStringComparator","a","b","putWriteRowToState","docId","state","stateByIndex","document","docInState","documents","set","stateByIndexLength","length","i","byIndex","docsWithIndex","getIndexableString","newIndexString","previousIndexString","eqPos","boundEQByIndexString","prev","next","insertPosition","pushAtSortPosition","prevEntry","splice","nextEntry","newRxError","args","indexBefore","bulkInsertToState","primaryPath","docs","docsLength","Array","docIds","doc","useInPlaceInsert","indexI","indexString","push","sort","newEntry","newEntries","mergeSortedArrays","aLen","bLen","result","ai","bi","ri","removeDocFromState","delete","byIndexArray","positionInIndex","compareDocsWithIndex","indexStringA","indexStringB"],"sources":["../../../../src/plugins/storage-memory/memory-helper.ts"],"sourcesContent":["import type {\r\n RxDocumentData,\r\n RxJsonSchema\r\n} from '../../types/index.d.ts';\r\nimport type {\r\n DocWithIndexString,\r\n MemoryStorageInternals,\r\n MemoryStorageInternalsByIndex\r\n} from './memory-types.ts';\r\nimport type { RxStorageInstanceMemory } from './rx-storage-instance-memory.ts';\r\nimport {\r\n pushAtSortPosition\r\n} from 'array-push-at-sort-position';\r\nimport { newRxError } from '../../rx-error.ts';\r\nimport { boundEQByIndexString } from './binary-search-bounds.ts';\r\n\r\n\r\nexport function getMemoryCollectionKey(\r\n databaseName: string,\r\n collectionName: string,\r\n schemaVersion: number\r\n): string {\r\n return [\r\n databaseName,\r\n collectionName,\r\n schemaVersion\r\n ].join('--memory--');\r\n}\r\n\r\n\r\nexport function ensureNotRemoved(\r\n instance: RxStorageInstanceMemory<any>\r\n) {\r\n if (instance.internals.removed) {\r\n throw new Error(\r\n 'removed already ' +\r\n instance.databaseName + ' - ' + instance.collectionName +\r\n ' - ' + instance.schema.version\r\n );\r\n }\r\n}\r\n\r\nexport function attachmentMapKey(documentId: string, attachmentId: string): string {\r\n return documentId + '||' + attachmentId;\r\n}\r\n\r\n\r\n/**\r\n * @performance\r\n * Threshold for using in-place splice vs. full merge-sort when inserting\r\n * documents into indexes. Below this batch size, in-place binary search + splice\r\n * is faster because it avoids allocating a new full-size array and copying all elements.\r\n */\r\nconst IN_PLACE_INSERT_THRESHOLD = 64;\r\n\r\nfunction sortByIndexStringComparator<RxDocType>(a: DocWithIndexString<RxDocType>, b: DocWithIndexString<RxDocType>) {\r\n if (a[0] < b[0]) {\r\n return -1;\r\n } else {\r\n return 1;\r\n }\r\n}\r\n\r\n\r\n\r\n/**\r\n * @hotPath\r\n */\r\nexport function putWriteRowToState<RxDocType>(\r\n docId: string,\r\n state: MemoryStorageInternals<RxDocType>,\r\n stateByIndex: MemoryStorageInternalsByIndex<RxDocType>[],\r\n document: RxDocumentData<RxDocType>,\r\n docInState?: RxDocumentData<RxDocType>\r\n) {\r\n state.documents.set(docId, document as any);\r\n const stateByIndexLength = stateByIndex.length;\r\n for (let i = 0; i < stateByIndexLength; ++i) {\r\n const byIndex = stateByIndex[i];\r\n const docsWithIndex = byIndex.docsWithIndex;\r\n const getIndexableString = byIndex.getIndexableString;\r\n const newIndexString = getIndexableString(document as any);\r\n\r\n /**\r\n * @performance\r\n * When updating a document, first compute whether the index changed.\r\n * If it did not change, we only need to update the document reference\r\n * in-place without any splice operations.\r\n */\r\n if (docInState) {\r\n const previousIndexString = getIndexableString(docInState);\r\n if (previousIndexString === newIndexString) {\r\n /**\r\n * Performance shortcut.\r\n * Index did not change, so the old entry is at the same position.\r\n * We can find it by string-specialized binary search and update in-place.\r\n */\r\n const eqPos = boundEQByIndexString(\r\n docsWithIndex,\r\n previousIndexString\r\n );\r\n if (eqPos !== -1) {\r\n /**\r\n * There might be multiple entries with the same index string\r\n * (e.g. different documents). Search around eqPos for ours.\r\n */\r\n if (docsWithIndex[eqPos][2] === docId) {\r\n docsWithIndex[eqPos][1] = document;\r\n continue;\r\n }\r\n // Check neighbors\r\n const prev = docsWithIndex[eqPos - 1];\r\n if (prev && prev[0] === previousIndexString && prev[2] === docId) {\r\n docsWithIndex[eqPos - 1][1] = document;\r\n continue;\r\n }\r\n const next = docsWithIndex[eqPos + 1];\r\n if (next && next[0] === previousIndexString && next[2] === docId) {\r\n docsWithIndex[eqPos + 1][1] = document;\r\n continue;\r\n }\r\n }\r\n // Fallback: use the old insert+remove approach\r\n const insertPosition = pushAtSortPosition(\r\n docsWithIndex,\r\n [newIndexString, document, docId],\r\n sortByIndexStringComparator,\r\n 0\r\n );\r\n const prevEntry = docsWithIndex[insertPosition - 1];\r\n if (prevEntry && prevEntry[2] === docId) {\r\n docsWithIndex.splice(insertPosition - 1, 1);\r\n } else {\r\n const nextEntry = docsWithIndex[insertPosition + 1];\r\n if (nextEntry[2] === docId) {\r\n docsWithIndex.splice(insertPosition + 1, 1);\r\n } else {\r\n throw newRxError('SNH', {\r\n document,\r\n args: {\r\n byIndex\r\n }\r\n });\r\n }\r\n }\r\n continue;\r\n } else {\r\n /**\r\n * Index changed, we must remove the old entry and insert the new one.\r\n */\r\n const indexBefore = boundEQByIndexString(\r\n docsWithIndex,\r\n previousIndexString\r\n );\r\n if (indexBefore !== -1) {\r\n docsWithIndex.splice(indexBefore, 1);\r\n }\r\n }\r\n }\r\n\r\n pushAtSortPosition(\r\n docsWithIndex,\r\n [newIndexString, document, docId],\r\n sortByIndexStringComparator,\r\n 0\r\n );\r\n }\r\n}\r\n\r\n\r\n/**\r\n * @hotPath\r\n * Efficiently inserts multiple documents into the state at once.\r\n *\r\n * Uses two strategies based on batch size:\r\n * - For small batches (relative to existing index size), uses in-place\r\n * binary search + splice per document. This avoids allocating a new\r\n * full-size array and copying all elements, reducing GC pressure.\r\n * - For large batches (or empty indexes), pre-computes all index entries,\r\n * sorts them, and merges into the existing sorted arrays in a single pass.\r\n */\r\nexport function bulkInsertToState<RxDocType>(\r\n primaryPath: string,\r\n state: MemoryStorageInternals<RxDocType>,\r\n stateByIndex: MemoryStorageInternalsByIndex<RxDocType>[],\r\n docs: { document: RxDocumentData<RxDocType> }[]\r\n) {\r\n const docsLength = docs.length;\r\n const stateByIndexLength = stateByIndex.length;\r\n\r\n // Extract documents and docIds once, store in Map\r\n const documents: RxDocumentData<RxDocType>[] = new Array(docsLength);\r\n const docIds: string[] = new Array(docsLength);\r\n for (let i = 0; i < docsLength; ++i) {\r\n const doc = docs[i].document;\r\n const docId: string = (doc as any)[primaryPath];\r\n documents[i] = doc;\r\n docIds[i] = docId;\r\n state.documents.set(docId, doc as any);\r\n }\r\n\r\n /**\r\n * @performance\r\n * For small batch sizes, use in-place binary search + splice\r\n * instead of creating a full merged array copy. This is faster\r\n * for serial inserts and small bulk inserts because it avoids:\r\n * - Allocating a new array of size n+m\r\n * - Copying all n existing elements\r\n * - GC pressure from discarding the old array\r\n *\r\n * The threshold is based on when the merge approach becomes more\r\n * efficient than individual splices.\r\n */\r\n const useInPlaceInsert = docsLength < IN_PLACE_INSERT_THRESHOLD;\r\n\r\n if (useInPlaceInsert) {\r\n for (let indexI = 0; indexI < stateByIndexLength; ++indexI) {\r\n const byIndex = stateByIndex[indexI];\r\n const docsWithIndex = byIndex.docsWithIndex;\r\n const getIndexableString = byIndex.getIndexableString;\r\n\r\n if (docsWithIndex.length === 0) {\r\n for (let i = 0; i < docsLength; ++i) {\r\n const doc = documents[i];\r\n const indexString = getIndexableString(doc as any);\r\n docsWithIndex.push([indexString, doc, docIds[i]]);\r\n }\r\n docsWithIndex.sort(sortByIndexStringComparator);\r\n } else {\r\n for (let i = 0; i < docsLength; ++i) {\r\n const doc = documents[i];\r\n const indexString = getIndexableString(doc as any);\r\n const newEntry: DocWithIndexString<RxDocType> = [indexString, doc, docIds[i]];\r\n pushAtSortPosition(\r\n docsWithIndex,\r\n newEntry,\r\n sortByIndexStringComparator,\r\n 0\r\n );\r\n }\r\n }\r\n }\r\n } else {\r\n // For each index, batch-compute entries, sort, and merge\r\n for (let indexI = 0; indexI < stateByIndexLength; ++indexI) {\r\n const byIndex = stateByIndex[indexI];\r\n const docsWithIndex = byIndex.docsWithIndex;\r\n const getIndexableString = byIndex.getIndexableString;\r\n\r\n // Build new entries\r\n const newEntries: DocWithIndexString<RxDocType>[] = new Array(docsLength);\r\n for (let i = 0; i < docsLength; ++i) {\r\n const doc = documents[i];\r\n newEntries[i] = [\r\n getIndexableString(doc as any),\r\n doc,\r\n docIds[i]\r\n ];\r\n }\r\n\r\n // Sort by index string\r\n newEntries.sort(sortByIndexStringComparator);\r\n\r\n if (docsWithIndex.length === 0) {\r\n // Index is empty, just assign sorted entries\r\n byIndex.docsWithIndex = newEntries;\r\n } else {\r\n // Merge sorted arrays\r\n byIndex.docsWithIndex = mergeSortedArrays(docsWithIndex, newEntries);\r\n }\r\n }\r\n }\r\n}\r\n\r\n\r\n/**\r\n * Merges two sorted DocWithIndexString arrays into a single sorted array.\r\n * Runs in O(n + m) where n and m are the lengths of the input arrays.\r\n * @performance Comparator is inlined to avoid function call overhead\r\n * per comparison, which is significant for large arrays.\r\n */\r\nfunction mergeSortedArrays<RxDocType>(\r\n a: DocWithIndexString<RxDocType>[],\r\n b: DocWithIndexString<RxDocType>[]\r\n): DocWithIndexString<RxDocType>[] {\r\n const aLen = a.length;\r\n const bLen = b.length;\r\n const result: DocWithIndexString<RxDocType>[] = new Array(aLen + bLen);\r\n let ai = 0;\r\n let bi = 0;\r\n let ri = 0;\r\n\r\n while (ai < aLen && bi < bLen) {\r\n if (a[ai][0] <= b[bi][0]) {\r\n result[ri++] = a[ai++];\r\n } else {\r\n result[ri++] = b[bi++];\r\n }\r\n }\r\n\r\n while (ai < aLen) {\r\n result[ri++] = a[ai++];\r\n }\r\n while (bi < bLen) {\r\n result[ri++] = b[bi++];\r\n }\r\n\r\n return result;\r\n}\r\n\r\nexport function removeDocFromState<RxDocType>(\r\n primaryPath: string,\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>,\r\n state: MemoryStorageInternals<RxDocType>,\r\n doc: RxDocumentData<RxDocType>\r\n) {\r\n const docId: string = (doc as any)[primaryPath];\r\n state.documents.delete(docId);\r\n\r\n const stateByIndex = state.byIndexArray;\r\n for (let i = 0; i < stateByIndex.length; ++i) {\r\n const byIndex = stateByIndex[i];\r\n const docsWithIndex = byIndex.docsWithIndex;\r\n const indexString = byIndex.getIndexableString(doc);\r\n\r\n const positionInIndex = boundEQByIndexString(\r\n docsWithIndex,\r\n indexString\r\n );\r\n if (positionInIndex !== -1) {\r\n docsWithIndex.splice(positionInIndex, 1);\r\n }\r\n }\r\n}\r\n\r\n\r\nexport function compareDocsWithIndex<RxDocType>(\r\n a: DocWithIndexString<RxDocType>,\r\n b: DocWithIndexString<RxDocType>\r\n): 1 | 0 | -1 {\r\n const indexStringA = a[0];\r\n const indexStringB = b[0];\r\n if (indexStringA < indexStringB) {\r\n return -1;\r\n } else if (indexStringA === indexStringB) {\r\n return 0;\r\n } else {\r\n return 1;\r\n }\r\n}\r\n"],"mappings":";;;;;;;;;;;;AAUA,IAAAA,wBAAA,GAAAC,OAAA;AAGA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,mBAAA,GAAAF,OAAA;AAGO,SAASG,sBAAsBA,CAClCC,YAAoB,EACpBC,cAAsB,EACtBC,aAAqB,EACf;EACN,OAAO,CACHF,YAAY,EACZC,cAAc,EACdC,aAAa,CAChB,CAACC,IAAI,CAAC,YAAY,CAAC;AACxB;AAGO,SAASC,gBAAgBA,CAC5BC,QAAsC,EACxC;EACE,IAAIA,QAAQ,CAACC,SAAS,CAACC,OAAO,EA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aAAa;IAC3C,IAAMyB,WAAW,GAAG1B,OAAO,CAACE,kBAAkB,CAACqB,GAAG,CAAC;IAEnD,IAAMkB,eAAe,GAAG,IAAAnC,wCAAoB,EACxCL,aAAa,EACbyB,WACJ,CAAC;IACD,IAAIe,eAAe,KAAK,CAAC,CAAC,EAAE;MACxBxC,aAAa,CAACW,MAAM,CAAC6B,eAAe,EAAE,CAAC,CAAC;IAC5C;EACJ;AACJ;AAGO,SAASC,oBAAoBA,CAChCvD,CAAgC,EAChCC,CAAgC,EACtB;EACV,IAAMuD,YAAY,GAAGxD,CAAC,CAAC,CAAC,CAAC;EACzB,IAAMyD,YAAY,GAAGxD,CAAC,CAAC,CAAC,CAAC;EACzB,IAAIuD,YAAY,GAAGC,YAAY,EAAE;IAC7B,OAAO,CAAC,CAAC;EACb,CAAC,MAAM,IAAID,YAAY,KAAKC,YAAY,EAAE;IACtC,OAAO,CAAC;EACZ,CAAC,MAAM;IACH,OAAO,CAAC;EACZ;AACJ","ignoreList":[]}
@@ -21,6 +21,7 @@ function addIndexesToInternalsState(state, schema) {
21
21
  getIndexableString: (0, _customIndex.getIndexableStringMonad)(schema, indexAr)
22
22
  };
23
23
  });
24
+ state.byIndexArray = Object.values(state.byIndex);
24
25
  }
25
26
  function getMemoryIndexName(index) {
26
27
  return index.join(',');
@@ -1 +1 @@
1
- {"version":3,"file":"memory-indexes.js","names":["_customIndex","require","_rxSchemaHelper","_index","addIndexesToInternalsState","state","schema","primaryPath","getPrimaryFieldOfPrimaryKey","primaryKey","useIndexes","indexes","map","row","toArray","push","forEach","indexAr","byIndex","getMemoryIndexName","index","docsWithIndex","getIndexableString","getIndexableStringMonad","join"],"sources":["../../../../src/plugins/storage-memory/memory-indexes.ts"],"sourcesContent":["import { getIndexableStringMonad } from '../../custom-index.ts';\r\nimport { getPrimaryFieldOfPrimaryKey } from '../../rx-schema-helper.ts';\r\nimport type { RxDocumentData, RxJsonSchema } from '../../types/index.d.ts';\r\nimport { toArray } from '../../plugins/utils/index.ts';\r\nimport type { MemoryStorageInternals } from './memory-types.ts';\r\n\r\nexport function addIndexesToInternalsState<RxDocType>(\r\n state: MemoryStorageInternals<RxDocType>,\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>\r\n) {\r\n const primaryPath = getPrimaryFieldOfPrimaryKey(schema.primaryKey);\r\n const useIndexes: string[][] = !schema.indexes ? [] : schema.indexes.map(row => toArray(row)) as any;\r\n\r\n // we need this index for running cleanup()\r\n useIndexes.push([\r\n '_deleted',\r\n '_meta.lwt',\r\n primaryPath\r\n ]);\r\n\r\n\r\n useIndexes.forEach(indexAr => {\r\n state.byIndex[getMemoryIndexName(indexAr)] = {\r\n index: indexAr,\r\n docsWithIndex: [],\r\n getIndexableString: getIndexableStringMonad(schema, indexAr)\r\n };\r\n });\r\n}\r\n\r\n\r\nexport function getMemoryIndexName(index: string[]): string {\r\n return index.join(',');\r\n}\r\n"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AAGO,SAASG,0BAA0BA,CACtCC,KAAwC,EACxCC,MAA+C,EACjD;EACE,IAAMC,WAAW,GAAG,IAAAC,2CAA2B,EAACF,MAAM,CAACG,UAAU,CAAC;EAClE,IAAMC,UAAsB,GAAG,CAACJ,MAAM,CAACK,OAAO,GAAG,EAAE,GAAGL,MAAM,CAACK,OAAO,CAACC,GAAG,CAACC,GAAG,IAAI,IAAAC,cAAO,EAACD,GAAG,CAAC,CAAQ;;EAEpG;EACAH,UAAU,CAACK,IAAI,CAAC,CACZ,UAAU,EACV,WAAW,EACXR,WAAW,CACd,CAAC;EAGFG,UAAU,CAACM,OAAO,CAACC,OAAO,IAAI;IAC1BZ,KAAK,CAACa,OAAO,CAACC,kBAAkB,CAACF,OAAO,CAAC,CAAC,GAAG;MACzCG,KAAK,EAAEH,OAAO;MACdI,aAAa,EAAE,EAAE;MACjBC,kBAAkB,EAAE,IAAAC,oCAAuB,EAACjB,MAAM,EAAEW,OAAO;IAC/D,CAAC;EACL,CAAC,CAAC;AACN;AAGO,SAASE,kBAAkBA,CAACC,KAAe,EAAU;EACxD,OAAOA,KAAK,CAACI,IAAI,CAAC,GAAG,CAAC;AAC1B","ignoreList":[]}
1
+ {"version":3,"file":"memory-indexes.js","names":["_customIndex","require","_rxSchemaHelper","_index","addIndexesToInternalsState","state","schema","primaryPath","getPrimaryFieldOfPrimaryKey","primaryKey","useIndexes","indexes","map","row","toArray","push","forEach","indexAr","byIndex","getMemoryIndexName","index","docsWithIndex","getIndexableString","getIndexableStringMonad","byIndexArray","Object","values","join"],"sources":["../../../../src/plugins/storage-memory/memory-indexes.ts"],"sourcesContent":["import { getIndexableStringMonad } from '../../custom-index.ts';\r\nimport { getPrimaryFieldOfPrimaryKey } from '../../rx-schema-helper.ts';\r\nimport type { RxDocumentData, RxJsonSchema } from '../../types/index.d.ts';\r\nimport { toArray } from '../../plugins/utils/index.ts';\r\nimport type { MemoryStorageInternals } from './memory-types.ts';\r\n\r\nexport function addIndexesToInternalsState<RxDocType>(\r\n state: MemoryStorageInternals<RxDocType>,\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>\r\n) {\r\n const primaryPath = getPrimaryFieldOfPrimaryKey(schema.primaryKey);\r\n const useIndexes: string[][] = !schema.indexes ? [] : schema.indexes.map(row => toArray(row)) as any;\r\n\r\n // we need this index for running cleanup()\r\n useIndexes.push([\r\n '_deleted',\r\n '_meta.lwt',\r\n primaryPath\r\n ]);\r\n\r\n\r\n useIndexes.forEach(indexAr => {\r\n state.byIndex[getMemoryIndexName(indexAr)] = {\r\n index: indexAr,\r\n docsWithIndex: [],\r\n getIndexableString: getIndexableStringMonad(schema, indexAr)\r\n };\r\n });\r\n state.byIndexArray = Object.values(state.byIndex);\r\n}\r\n\r\n\r\nexport function getMemoryIndexName(index: string[]): string {\r\n return index.join(',');\r\n}\r\n"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AAGO,SAASG,0BAA0BA,CACtCC,KAAwC,EACxCC,MAA+C,EACjD;EACE,IAAMC,WAAW,GAAG,IAAAC,2CAA2B,EAACF,MAAM,CAACG,UAAU,CAAC;EAClE,IAAMC,UAAsB,GAAG,CAACJ,MAAM,CAACK,OAAO,GAAG,EAAE,GAAGL,MAAM,CAACK,OAAO,CAACC,GAAG,CAACC,GAAG,IAAI,IAAAC,cAAO,EAACD,GAAG,CAAC,CAAQ;;EAEpG;EACAH,UAAU,CAACK,IAAI,CAAC,CACZ,UAAU,EACV,WAAW,EACXR,WAAW,CACd,CAAC;EAGFG,UAAU,CAACM,OAAO,CAACC,OAAO,IAAI;IAC1BZ,KAAK,CAACa,OAAO,CAACC,kBAAkB,CAACF,OAAO,CAAC,CAAC,GAAG;MACzCG,KAAK,EAAEH,OAAO;MACdI,aAAa,EAAE,EAAE;MACjBC,kBAAkB,EAAE,IAAAC,oCAAuB,EAACjB,MAAM,EAAEW,OAAO;IAC/D,CAAC;EACL,CAAC,CAAC;EACFZ,KAAK,CAACmB,YAAY,GAAGC,MAAM,CAACC,MAAM,CAACrB,KAAK,CAACa,OAAO,CAAC;AACrD;AAGO,SAASC,kBAAkBA,CAACC,KAAe,EAAU;EACxD,OAAOA,KAAK,CAACO,IAAI,CAAC,GAAG,CAAC;AAC1B","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"memory-types.js","names":[],"sources":["../../../../src/plugins/storage-memory/memory-types.ts"],"sourcesContent":["import { Subject } from 'rxjs';\r\nimport type {\r\n CategorizeBulkWriteRowsOutput,\r\n EventBulk,\r\n RxAttachmentWriteData,\r\n RxDocumentData,\r\n RxJsonSchema,\r\n RxStorage,\r\n RxStorageChangeEvent,\r\n RxStorageDefaultCheckpoint\r\n} from '../../types/index.d.ts';\r\n\r\nexport type RxStorageMemorySettings = {};\r\nexport type RxStorageMemoryInstanceCreationOptions = {};\r\nexport type RxStorageMemory = RxStorage<MemoryStorageInternals<any>, RxStorageMemoryInstanceCreationOptions> & {\r\n /**\r\n * State by collectionKey\r\n */\r\n collectionStates: Map<string, MemoryStorageInternals<any>>;\r\n};\r\n\r\nexport type MemoryStorageInternalsByIndex<RxDocType> = {\r\n index: string[];\r\n docsWithIndex: DocWithIndexString<RxDocType>[];\r\n getIndexableString: (docData: RxDocumentData<RxDocType>) => string;\r\n};\r\n\r\n/**\r\n * The internals are shared between multiple storage instances\r\n * that have been created with the same [databaseName+collectionName] combination.\r\n */\r\nexport type MemoryStorageInternals<RxDocType> = {\r\n // used to debug stuff and identify instances\r\n id: string;\r\n\r\n /**\r\n * Schema of the first instance created with the given settings.\r\n * Used to ensure that the same storage is not re-created with\r\n * a different schema.\r\n */\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>;\r\n\r\n /**\r\n * We reuse the memory state when multiple instances\r\n * are created with the same params.\r\n * If refCount becomes 0, we can delete the state.\r\n */\r\n refCount: number;\r\n /**\r\n * If this becomes true,\r\n * it means that an instance has called remove()\r\n * so all other instances should also not work anymore.\r\n */\r\n removed: boolean;\r\n documents: Map<string, RxDocumentData<RxDocType>>;\r\n /**\r\n * Attachments data, indexed by a combined string\r\n * consisting of [documentId + '||' + attachmentId]\r\n */\r\n attachments: Map<string, {\r\n writeData: RxAttachmentWriteData;\r\n digest: string;\r\n }>;\r\n byIndex: {\r\n /**\r\n * Because RxDB requires a deterministic sorting\r\n * on all indexes, we can be sure that the composed index key\r\n * of each document is unique, because it contains the primaryKey\r\n * as last index part.\r\n * So we do not have to store the index-position when we want to do fast\r\n * writes. Instead we can do a binary search over the existing array\r\n * because RxDB also knows the previous state of the document when we do a bulkWrite().\r\n */\r\n [indexName: string]: MemoryStorageInternalsByIndex<RxDocType>;\r\n };\r\n\r\n /**\r\n * We need these to do lazy writes.\r\n */\r\n ensurePersistenceTask?: CategorizeBulkWriteRowsOutput<RxDocType>;\r\n ensurePersistenceIdlePromise?: Promise<void>;\r\n\r\n changes$: Subject<EventBulk<RxStorageChangeEvent<RxDocumentData<RxDocType>>, RxStorageDefaultCheckpoint>>;\r\n};\r\n\r\nexport type DocWithIndexString<RxDocType> = [\r\n string, // indexString, must be first because often we only need that one.\r\n RxDocumentData<RxDocType>, // document\r\n string, // id\r\n];\r\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"file":"memory-types.js","names":[],"sources":["../../../../src/plugins/storage-memory/memory-types.ts"],"sourcesContent":["import { Subject } from 'rxjs';\r\nimport type {\r\n CategorizeBulkWriteRowsOutput,\r\n EventBulk,\r\n RxAttachmentWriteData,\r\n RxDocumentData,\r\n RxJsonSchema,\r\n RxStorage,\r\n RxStorageChangeEvent,\r\n RxStorageDefaultCheckpoint\r\n} from '../../types/index.d.ts';\r\n\r\nexport type RxStorageMemorySettings = {};\r\nexport type RxStorageMemoryInstanceCreationOptions = {};\r\nexport type RxStorageMemory = RxStorage<MemoryStorageInternals<any>, RxStorageMemoryInstanceCreationOptions> & {\r\n /**\r\n * State by collectionKey\r\n */\r\n collectionStates: Map<string, MemoryStorageInternals<any>>;\r\n};\r\n\r\nexport type MemoryStorageInternalsByIndex<RxDocType> = {\r\n index: string[];\r\n docsWithIndex: DocWithIndexString<RxDocType>[];\r\n getIndexableString: (docData: RxDocumentData<RxDocType>) => string;\r\n};\r\n\r\n/**\r\n * The internals are shared between multiple storage instances\r\n * that have been created with the same [databaseName+collectionName] combination.\r\n */\r\nexport type MemoryStorageInternals<RxDocType> = {\r\n // used to debug stuff and identify instances\r\n id: string;\r\n\r\n /**\r\n * Schema of the first instance created with the given settings.\r\n * Used to ensure that the same storage is not re-created with\r\n * a different schema.\r\n */\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>;\r\n\r\n /**\r\n * We reuse the memory state when multiple instances\r\n * are created with the same params.\r\n * If refCount becomes 0, we can delete the state.\r\n */\r\n refCount: number;\r\n /**\r\n * If this becomes true,\r\n * it means that an instance has called remove()\r\n * so all other instances should also not work anymore.\r\n */\r\n removed: boolean;\r\n documents: Map<string, RxDocumentData<RxDocType>>;\r\n /**\r\n * Attachments data, indexed by a combined string\r\n * consisting of [documentId + '||' + attachmentId]\r\n */\r\n attachments: Map<string, {\r\n writeData: RxAttachmentWriteData;\r\n digest: string;\r\n }>;\r\n byIndex: {\r\n /**\r\n * Because RxDB requires a deterministic sorting\r\n * on all indexes, we can be sure that the composed index key\r\n * of each document is unique, because it contains the primaryKey\r\n * as last index part.\r\n * So we do not have to store the index-position when we want to do fast\r\n * writes. Instead we can do a binary search over the existing array\r\n * because RxDB also knows the previous state of the document when we do a bulkWrite().\r\n */\r\n [indexName: string]: MemoryStorageInternalsByIndex<RxDocType>;\r\n };\r\n /**\r\n * Cached array of all MemoryStorageInternalsByIndex values.\r\n * Avoids calling Object.values(byIndex) on every write operation.\r\n */\r\n byIndexArray: MemoryStorageInternalsByIndex<RxDocType>[];\r\n\r\n /**\r\n * We need these to do lazy writes.\r\n */\r\n ensurePersistenceTask?: CategorizeBulkWriteRowsOutput<RxDocType>;\r\n ensurePersistenceIdlePromise?: Promise<void>;\r\n\r\n changes$: Subject<EventBulk<RxStorageChangeEvent<RxDocumentData<RxDocType>>, RxStorageDefaultCheckpoint>>;\r\n};\r\n\r\nexport type DocWithIndexString<RxDocType> = [\r\n string, // indexString, must be first because often we only need that one.\r\n RxDocumentData<RxDocType>, // document\r\n string, // id\r\n];\r\n"],"mappings":"","ignoreList":[]}