@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.
- package/AGENTS.md +4 -0
- package/CHANGELOG.md +47 -4
- package/CLAUDE.md +2 -0
- package/dist/cjs/change-event-buffer.js +2 -1
- package/dist/cjs/change-event-buffer.js.map +1 -1
- package/dist/cjs/custom-index.js +85 -12
- package/dist/cjs/custom-index.js.map +1 -1
- package/dist/cjs/doc-cache.js +117 -35
- package/dist/cjs/doc-cache.js.map +1 -1
- package/dist/cjs/event-reduce.js +10 -1
- package/dist/cjs/event-reduce.js.map +1 -1
- package/dist/cjs/plugin-helpers.js +16 -0
- package/dist/cjs/plugin-helpers.js.map +1 -1
- package/dist/cjs/plugins/attachments/index.js +3 -3
- package/dist/cjs/plugins/attachments/index.js.map +1 -1
- package/dist/cjs/plugins/cleanup/cleanup.js +5 -3
- package/dist/cjs/plugins/cleanup/cleanup.js.map +1 -1
- package/dist/cjs/plugins/crdt/index.js +52 -0
- package/dist/cjs/plugins/crdt/index.js.map +1 -1
- package/dist/cjs/plugins/dev-mode/check-query.js +7 -1
- package/dist/cjs/plugins/dev-mode/check-query.js.map +1 -1
- package/dist/cjs/plugins/dev-mode/check-schema.js +2 -1
- package/dist/cjs/plugins/dev-mode/check-schema.js.map +1 -1
- package/dist/cjs/plugins/dev-mode/error-messages.js +43 -5
- package/dist/cjs/plugins/dev-mode/error-messages.js.map +1 -1
- package/dist/cjs/plugins/encryption-crypto-js/index.js +22 -6
- package/dist/cjs/plugins/encryption-crypto-js/index.js.map +1 -1
- package/dist/cjs/plugins/leader-election/index.js +5 -5
- package/dist/cjs/plugins/leader-election/index.js.map +1 -1
- package/dist/cjs/plugins/local-documents/local-documents.js +20 -13
- package/dist/cjs/plugins/local-documents/local-documents.js.map +1 -1
- package/dist/cjs/plugins/migration-schema/migration-helpers.js +3 -0
- package/dist/cjs/plugins/migration-schema/migration-helpers.js.map +1 -1
- package/dist/cjs/plugins/migration-schema/rx-migration-state.js +1 -1
- package/dist/cjs/plugins/migration-schema/rx-migration-state.js.map +1 -1
- package/dist/cjs/plugins/pipeline/rx-pipeline.js +5 -1
- package/dist/cjs/plugins/pipeline/rx-pipeline.js.map +1 -1
- package/dist/cjs/plugins/query-builder/mquery/nosql-query-builder.js +4 -2
- package/dist/cjs/plugins/query-builder/mquery/nosql-query-builder.js.map +1 -1
- package/dist/cjs/plugins/replication/index.js +40 -2
- package/dist/cjs/plugins/replication/index.js.map +1 -1
- package/dist/cjs/plugins/replication-google-drive/document-handling.js +17 -6
- package/dist/cjs/plugins/replication-google-drive/document-handling.js.map +1 -1
- package/dist/cjs/plugins/replication-google-drive/google-drive-helper.js +1 -1
- package/dist/cjs/plugins/replication-google-drive/google-drive-helper.js.map +1 -1
- package/dist/cjs/plugins/replication-google-drive/google-drive-types.js.map +1 -1
- package/dist/cjs/plugins/replication-google-drive/signaling.js +4 -1
- package/dist/cjs/plugins/replication-google-drive/signaling.js.map +1 -1
- package/dist/cjs/plugins/replication-google-drive/upstream.js +7 -4
- package/dist/cjs/plugins/replication-google-drive/upstream.js.map +1 -1
- package/dist/cjs/plugins/replication-microsoft-onedrive/signaling.js +4 -1
- package/dist/cjs/plugins/replication-microsoft-onedrive/signaling.js.map +1 -1
- package/dist/cjs/plugins/state/rx-state.js +14 -3
- package/dist/cjs/plugins/state/rx-state.js.map +1 -1
- package/dist/cjs/plugins/storage-dexie/rx-storage-instance-dexie.js +0 -7
- package/dist/cjs/plugins/storage-dexie/rx-storage-instance-dexie.js.map +1 -1
- package/dist/cjs/plugins/storage-memory/binary-search-bounds.js +112 -40
- package/dist/cjs/plugins/storage-memory/binary-search-bounds.js.map +1 -1
- package/dist/cjs/plugins/storage-memory/memory-helper.js +127 -40
- package/dist/cjs/plugins/storage-memory/memory-helper.js.map +1 -1
- package/dist/cjs/plugins/storage-memory/memory-indexes.js +1 -0
- package/dist/cjs/plugins/storage-memory/memory-indexes.js.map +1 -1
- package/dist/cjs/plugins/storage-memory/memory-types.js.map +1 -1
- package/dist/cjs/plugins/storage-memory/rx-storage-instance-memory.js +97 -37
- package/dist/cjs/plugins/storage-memory/rx-storage-instance-memory.js.map +1 -1
- package/dist/cjs/plugins/storage-mongodb/mongodb-helper.js +42 -1
- package/dist/cjs/plugins/storage-mongodb/mongodb-helper.js.map +1 -1
- package/dist/cjs/plugins/storage-mongodb/rx-storage-instance-mongodb.js +7 -7
- package/dist/cjs/plugins/storage-mongodb/rx-storage-instance-mongodb.js.map +1 -1
- package/dist/cjs/plugins/test-utils/config.js +1 -1
- package/dist/cjs/plugins/test-utils/config.js.map +1 -1
- package/dist/cjs/plugins/test-utils/performance.js +122 -92
- package/dist/cjs/plugins/test-utils/performance.js.map +1 -1
- package/dist/cjs/plugins/test-utils/schema-objects.js +1 -1
- package/dist/cjs/plugins/test-utils/schema-objects.js.map +1 -1
- package/dist/cjs/plugins/test-utils/test-util.js +62 -0
- package/dist/cjs/plugins/test-utils/test-util.js.map +1 -1
- package/dist/cjs/plugins/utils/utils-map.js +2 -2
- package/dist/cjs/plugins/utils/utils-map.js.map +1 -1
- package/dist/cjs/plugins/utils/utils-object-deep-equal.js +3 -2
- package/dist/cjs/plugins/utils/utils-object-deep-equal.js.map +1 -1
- package/dist/cjs/plugins/utils/utils-object-dot-prop.js +25 -0
- package/dist/cjs/plugins/utils/utils-object-dot-prop.js.map +1 -1
- package/dist/cjs/plugins/utils/utils-object.js +102 -27
- package/dist/cjs/plugins/utils/utils-object.js.map +1 -1
- package/dist/cjs/plugins/utils/utils-other.js +9 -4
- package/dist/cjs/plugins/utils/utils-other.js.map +1 -1
- package/dist/cjs/plugins/utils/utils-premium.js +5 -23
- package/dist/cjs/plugins/utils/utils-premium.js.map +1 -1
- package/dist/cjs/plugins/utils/utils-revision.js +20 -10
- package/dist/cjs/plugins/utils/utils-revision.js.map +1 -1
- package/dist/cjs/plugins/utils/utils-rxdb-version.js +1 -1
- package/dist/cjs/plugins/utils/utils-rxdb-version.js.map +1 -1
- package/dist/cjs/plugins/utils/utils-string.js +11 -8
- package/dist/cjs/plugins/utils/utils-string.js.map +1 -1
- package/dist/cjs/plugins/utils/utils-time.js +21 -16
- package/dist/cjs/plugins/utils/utils-time.js.map +1 -1
- package/dist/cjs/query-cache.js +6 -4
- package/dist/cjs/query-cache.js.map +1 -1
- package/dist/cjs/query-planner.js +2 -2
- package/dist/cjs/query-planner.js.map +1 -1
- package/dist/cjs/replication-protocol/downstream.js +1 -1
- package/dist/cjs/replication-protocol/downstream.js.map +1 -1
- package/dist/cjs/rx-collection-helper.js +11 -6
- package/dist/cjs/rx-collection-helper.js.map +1 -1
- package/dist/cjs/rx-collection.js +34 -6
- package/dist/cjs/rx-collection.js.map +1 -1
- package/dist/cjs/rx-database.js +40 -7
- package/dist/cjs/rx-database.js.map +1 -1
- package/dist/cjs/rx-document.js +10 -3
- package/dist/cjs/rx-document.js.map +1 -1
- package/dist/cjs/rx-query-helper.js +35 -12
- package/dist/cjs/rx-query-helper.js.map +1 -1
- package/dist/cjs/rx-query-single-result.js +9 -2
- package/dist/cjs/rx-query-single-result.js.map +1 -1
- package/dist/cjs/rx-query.js +72 -29
- package/dist/cjs/rx-query.js.map +1 -1
- package/dist/cjs/rx-schema-helper.js +9 -3
- package/dist/cjs/rx-schema-helper.js.map +1 -1
- package/dist/cjs/rx-schema.js +1 -0
- package/dist/cjs/rx-schema.js.map +1 -1
- package/dist/cjs/rx-storage-helper.js +212 -129
- package/dist/cjs/rx-storage-helper.js.map +1 -1
- package/dist/cjs/types/rx-error.d.js.map +1 -1
- package/dist/cjs/types/rx-schema.d.js.map +1 -1
- package/dist/esm/change-event-buffer.js +2 -1
- package/dist/esm/change-event-buffer.js.map +1 -1
- package/dist/esm/custom-index.js +85 -12
- package/dist/esm/custom-index.js.map +1 -1
- package/dist/esm/doc-cache.js +118 -36
- package/dist/esm/doc-cache.js.map +1 -1
- package/dist/esm/event-reduce.js +10 -1
- package/dist/esm/event-reduce.js.map +1 -1
- package/dist/esm/plugin-helpers.js +16 -0
- package/dist/esm/plugin-helpers.js.map +1 -1
- package/dist/esm/plugins/attachments/index.js +3 -3
- package/dist/esm/plugins/attachments/index.js.map +1 -1
- package/dist/esm/plugins/cleanup/cleanup.js +5 -3
- package/dist/esm/plugins/cleanup/cleanup.js.map +1 -1
- package/dist/esm/plugins/crdt/index.js +52 -0
- package/dist/esm/plugins/crdt/index.js.map +1 -1
- package/dist/esm/plugins/dev-mode/check-query.js +7 -1
- package/dist/esm/plugins/dev-mode/check-query.js.map +1 -1
- package/dist/esm/plugins/dev-mode/check-schema.js +2 -1
- package/dist/esm/plugins/dev-mode/check-schema.js.map +1 -1
- package/dist/esm/plugins/dev-mode/error-messages.js +43 -5
- package/dist/esm/plugins/dev-mode/error-messages.js.map +1 -1
- package/dist/esm/plugins/encryption-crypto-js/index.js +22 -6
- package/dist/esm/plugins/encryption-crypto-js/index.js.map +1 -1
- package/dist/esm/plugins/leader-election/index.js +4 -4
- package/dist/esm/plugins/leader-election/index.js.map +1 -1
- package/dist/esm/plugins/local-documents/local-documents.js +20 -13
- package/dist/esm/plugins/local-documents/local-documents.js.map +1 -1
- package/dist/esm/plugins/migration-schema/migration-helpers.js +3 -0
- package/dist/esm/plugins/migration-schema/migration-helpers.js.map +1 -1
- package/dist/esm/plugins/migration-schema/rx-migration-state.js +1 -1
- package/dist/esm/plugins/migration-schema/rx-migration-state.js.map +1 -1
- package/dist/esm/plugins/pipeline/rx-pipeline.js +5 -1
- package/dist/esm/plugins/pipeline/rx-pipeline.js.map +1 -1
- package/dist/esm/plugins/query-builder/mquery/nosql-query-builder.js +4 -2
- package/dist/esm/plugins/query-builder/mquery/nosql-query-builder.js.map +1 -1
- package/dist/esm/plugins/replication/index.js +40 -2
- package/dist/esm/plugins/replication/index.js.map +1 -1
- package/dist/esm/plugins/replication-google-drive/document-handling.js +17 -6
- package/dist/esm/plugins/replication-google-drive/document-handling.js.map +1 -1
- package/dist/esm/plugins/replication-google-drive/google-drive-helper.js +1 -1
- package/dist/esm/plugins/replication-google-drive/google-drive-helper.js.map +1 -1
- package/dist/esm/plugins/replication-google-drive/google-drive-types.js.map +1 -1
- package/dist/esm/plugins/replication-google-drive/signaling.js +4 -1
- package/dist/esm/plugins/replication-google-drive/signaling.js.map +1 -1
- package/dist/esm/plugins/replication-google-drive/upstream.js +7 -4
- package/dist/esm/plugins/replication-google-drive/upstream.js.map +1 -1
- package/dist/esm/plugins/replication-microsoft-onedrive/signaling.js +4 -1
- package/dist/esm/plugins/replication-microsoft-onedrive/signaling.js.map +1 -1
- package/dist/esm/plugins/state/rx-state.js +15 -4
- package/dist/esm/plugins/state/rx-state.js.map +1 -1
- package/dist/esm/plugins/storage-dexie/rx-storage-instance-dexie.js +1 -8
- package/dist/esm/plugins/storage-dexie/rx-storage-instance-dexie.js.map +1 -1
- package/dist/esm/plugins/storage-memory/binary-search-bounds.js +107 -40
- package/dist/esm/plugins/storage-memory/binary-search-bounds.js.map +1 -1
- package/dist/esm/plugins/storage-memory/memory-helper.js +128 -41
- package/dist/esm/plugins/storage-memory/memory-helper.js.map +1 -1
- package/dist/esm/plugins/storage-memory/memory-indexes.js +1 -0
- package/dist/esm/plugins/storage-memory/memory-indexes.js.map +1 -1
- package/dist/esm/plugins/storage-memory/memory-types.js.map +1 -1
- package/dist/esm/plugins/storage-memory/rx-storage-instance-memory.js +90 -30
- package/dist/esm/plugins/storage-memory/rx-storage-instance-memory.js.map +1 -1
- package/dist/esm/plugins/storage-mongodb/mongodb-helper.js +39 -0
- package/dist/esm/plugins/storage-mongodb/mongodb-helper.js.map +1 -1
- package/dist/esm/plugins/storage-mongodb/rx-storage-instance-mongodb.js +8 -8
- package/dist/esm/plugins/storage-mongodb/rx-storage-instance-mongodb.js.map +1 -1
- package/dist/esm/plugins/test-utils/config.js +1 -1
- package/dist/esm/plugins/test-utils/config.js.map +1 -1
- package/dist/esm/plugins/test-utils/performance.js +122 -92
- package/dist/esm/plugins/test-utils/performance.js.map +1 -1
- package/dist/esm/plugins/test-utils/schema-objects.js +1 -1
- package/dist/esm/plugins/test-utils/schema-objects.js.map +1 -1
- package/dist/esm/plugins/test-utils/test-util.js +59 -0
- package/dist/esm/plugins/test-utils/test-util.js.map +1 -1
- package/dist/esm/plugins/utils/utils-map.js +2 -2
- package/dist/esm/plugins/utils/utils-map.js.map +1 -1
- package/dist/esm/plugins/utils/utils-object-deep-equal.js +3 -2
- package/dist/esm/plugins/utils/utils-object-deep-equal.js.map +1 -1
- package/dist/esm/plugins/utils/utils-object-dot-prop.js +25 -0
- package/dist/esm/plugins/utils/utils-object-dot-prop.js.map +1 -1
- package/dist/esm/plugins/utils/utils-object.js +102 -27
- package/dist/esm/plugins/utils/utils-object.js.map +1 -1
- package/dist/esm/plugins/utils/utils-other.js +9 -4
- package/dist/esm/plugins/utils/utils-other.js.map +1 -1
- package/dist/esm/plugins/utils/utils-premium.js +5 -23
- package/dist/esm/plugins/utils/utils-premium.js.map +1 -1
- package/dist/esm/plugins/utils/utils-revision.js +20 -10
- package/dist/esm/plugins/utils/utils-revision.js.map +1 -1
- package/dist/esm/plugins/utils/utils-rxdb-version.js +1 -1
- package/dist/esm/plugins/utils/utils-rxdb-version.js.map +1 -1
- package/dist/esm/plugins/utils/utils-string.js +11 -8
- package/dist/esm/plugins/utils/utils-string.js.map +1 -1
- package/dist/esm/plugins/utils/utils-time.js +21 -16
- package/dist/esm/plugins/utils/utils-time.js.map +1 -1
- package/dist/esm/query-cache.js +7 -5
- package/dist/esm/query-cache.js.map +1 -1
- package/dist/esm/query-planner.js +2 -2
- package/dist/esm/query-planner.js.map +1 -1
- package/dist/esm/replication-protocol/downstream.js +1 -1
- package/dist/esm/replication-protocol/downstream.js.map +1 -1
- package/dist/esm/rx-collection-helper.js +12 -7
- package/dist/esm/rx-collection-helper.js.map +1 -1
- package/dist/esm/rx-collection.js +35 -7
- package/dist/esm/rx-collection.js.map +1 -1
- package/dist/esm/rx-database.js +40 -7
- package/dist/esm/rx-database.js.map +1 -1
- package/dist/esm/rx-document.js +11 -4
- package/dist/esm/rx-document.js.map +1 -1
- package/dist/esm/rx-query-helper.js +35 -12
- package/dist/esm/rx-query-helper.js.map +1 -1
- package/dist/esm/rx-query-single-result.js +10 -3
- package/dist/esm/rx-query-single-result.js.map +1 -1
- package/dist/esm/rx-query.js +72 -29
- package/dist/esm/rx-query.js.map +1 -1
- package/dist/esm/rx-schema-helper.js +9 -3
- package/dist/esm/rx-schema-helper.js.map +1 -1
- package/dist/esm/rx-schema.js +1 -0
- package/dist/esm/rx-schema.js.map +1 -1
- package/dist/esm/rx-storage-helper.js +176 -94
- package/dist/esm/rx-storage-helper.js.map +1 -1
- package/dist/esm/types/rx-error.d.js.map +1 -1
- package/dist/esm/types/rx-schema.d.js.map +1 -1
- package/dist/types/custom-index.d.ts +5 -0
- package/dist/types/doc-cache.d.ts +1 -1
- package/dist/types/plugins/dev-mode/error-messages.d.ts +36 -0
- package/dist/types/plugins/leader-election/index.d.ts +1 -0
- package/dist/types/plugins/replication-google-drive/document-handling.d.ts +4 -1
- package/dist/types/plugins/replication-google-drive/google-drive-types.d.ts +1 -0
- package/dist/types/plugins/state/rx-state.d.ts +1 -1
- package/dist/types/plugins/storage-denokv/index.d.ts +1 -1
- package/dist/types/plugins/storage-dexie/rx-storage-dexie.d.ts +1 -1
- package/dist/types/plugins/storage-localstorage/index.d.ts +1 -1
- package/dist/types/plugins/storage-memory/binary-search-bounds.d.ts +21 -10
- package/dist/types/plugins/storage-memory/memory-helper.d.ts +7 -3
- package/dist/types/plugins/storage-memory/memory-types.d.ts +5 -0
- package/dist/types/plugins/storage-mongodb/mongodb-helper.d.ts +9 -1
- package/dist/types/plugins/storage-mongodb/rx-storage-instance-mongodb.d.ts +2 -2
- package/dist/types/plugins/storage-mongodb/rx-storage-mongodb.d.ts +1 -1
- package/dist/types/plugins/storage-remote/rx-storage-remote.d.ts +1 -1
- package/dist/types/plugins/storage-sqlite/index.d.ts +1 -1
- package/dist/types/plugins/test-utils/performance.d.ts +36 -0
- package/dist/types/plugins/test-utils/test-util.d.ts +17 -0
- package/dist/types/plugins/utils/utils-object.d.ts +8 -3
- package/dist/types/plugins/utils/utils-premium.d.ts +0 -2
- package/dist/types/plugins/utils/utils-rxdb-version.d.ts +1 -1
- package/dist/types/rx-database.d.ts +1 -1
- package/dist/types/rx-query-single-result.d.ts +1 -1
- package/dist/types/rx-query.d.ts +3 -2
- package/dist/types/rx-storage-helper.d.ts +15 -0
- package/dist/types/types/rx-error.d.ts +3 -0
- package/dist/types/types/rx-schema.d.ts +5 -0
- package/eslint.config.mjs +2 -1
- package/package.json +38 -35
- package/scripts/check-code-block-line-length.js +91 -0
- package/scripts/check-em-dashes.js +53 -0
- package/scripts/copy-path.mjs +20 -0
- package/scripts/docs-fetch-git-history.mjs +36 -0
- package/scripts/fix-types.mjs +15 -8
- package/scripts/install-foundationdb.sh +0 -6
- package/scripts/notify-indexnow.mjs +171 -0
- package/scripts/start-foundationdb-docker.sh +73 -0
- package/src/change-event-buffer.ts +4 -1
- package/src/custom-index.ts +93 -16
- package/src/doc-cache.ts +117 -41
- package/src/event-reduce.ts +10 -1
- package/src/plugin-helpers.ts +10 -0
- package/src/plugins/attachments/index.ts +10 -12
- package/src/plugins/cleanup/cleanup.ts +5 -3
- package/src/plugins/crdt/index.ts +55 -0
- package/src/plugins/dev-mode/check-query.ts +7 -1
- package/src/plugins/dev-mode/check-schema.ts +2 -1
- package/src/plugins/dev-mode/error-messages.ts +45 -5
- package/src/plugins/encryption-crypto-js/index.ts +18 -6
- package/src/plugins/leader-election/index.ts +9 -8
- package/src/plugins/local-documents/local-documents.ts +21 -12
- package/src/plugins/migration-schema/migration-helpers.ts +3 -0
- package/src/plugins/migration-schema/rx-migration-state.ts +1 -1
- package/src/plugins/pipeline/rx-pipeline.ts +5 -1
- package/src/plugins/query-builder/mquery/nosql-query-builder.ts +8 -2
- package/src/plugins/replication/index.ts +41 -3
- package/src/plugins/replication-google-drive/document-handling.ts +17 -5
- package/src/plugins/replication-google-drive/google-drive-helper.ts +1 -1
- package/src/plugins/replication-google-drive/google-drive-types.ts +1 -0
- package/src/plugins/replication-google-drive/signaling.ts +4 -1
- package/src/plugins/replication-google-drive/upstream.ts +7 -4
- package/src/plugins/replication-microsoft-onedrive/signaling.ts +4 -1
- package/src/plugins/state/rx-state.ts +17 -5
- package/src/plugins/storage-dexie/rx-storage-instance-dexie.ts +0 -27
- package/src/plugins/storage-memory/binary-search-bounds.ts +105 -40
- package/src/plugins/storage-memory/memory-helper.ts +158 -67
- package/src/plugins/storage-memory/memory-indexes.ts +1 -0
- package/src/plugins/storage-memory/memory-types.ts +5 -0
- package/src/plugins/storage-memory/rx-storage-instance-memory.ts +104 -53
- package/src/plugins/storage-mongodb/mongodb-helper.ts +43 -1
- package/src/plugins/storage-mongodb/rx-storage-instance-mongodb.ts +11 -9
- package/src/plugins/test-utils/config.ts +2 -1
- package/src/plugins/test-utils/performance.ts +159 -85
- package/src/plugins/test-utils/schema-objects.ts +1 -1
- package/src/plugins/test-utils/test-util.ts +71 -0
- package/src/plugins/utils/utils-map.ts +2 -2
- package/src/plugins/utils/utils-object-deep-equal.ts +2 -4
- package/src/plugins/utils/utils-object-dot-prop.ts +25 -0
- package/src/plugins/utils/utils-object.ts +103 -28
- package/src/plugins/utils/utils-other.ts +9 -4
- package/src/plugins/utils/utils-premium.ts +11 -37
- package/src/plugins/utils/utils-revision.ts +20 -9
- package/src/plugins/utils/utils-rxdb-version.ts +1 -1
- package/src/plugins/utils/utils-string.ts +11 -9
- package/src/plugins/utils/utils-time.ts +21 -17
- package/src/query-cache.ts +6 -5
- package/src/query-planner.ts +2 -2
- package/src/replication-protocol/downstream.ts +1 -1
- package/src/rx-collection-helper.ts +12 -6
- package/src/rx-collection.ts +39 -8
- package/src/rx-database.ts +49 -17
- package/src/rx-document.ts +12 -3
- package/src/rx-query-helper.ts +36 -15
- package/src/rx-query-single-result.ts +10 -3
- package/src/rx-query.ts +48 -8
- package/src/rx-schema-helper.ts +7 -4
- package/src/rx-schema.ts +1 -0
- package/src/rx-storage-helper.ts +210 -139
- package/src/types/rx-error.d.ts +3 -0
- package/src/types/rx-schema.d.ts +5 -0
package/AGENTS.md
CHANGED
|
@@ -40,6 +40,10 @@
|
|
|
40
40
|
- AVOID rhetorical questions.
|
|
41
41
|
- AVOID specific words like: very, really, literally, actually, certainly, probably, basically, delve, embark, enlightening, esteemed, shed light, craft, creative, imagine, realm, game-changer, unlock, discover, skyrocket, abyss, not alone, in a world where, revolutionize, disruptive, utilize, utilizing, dive deep, tapestry, illuminate, unveil, pivotal, intricate, elucidate, hence, furthermore, realm, however, harness, exciting, groundbreaking, cutting-edge, remarkable, it remains to be seen, glimpse into, navigating, landscape, stark, testament, in summary, in conclusion, moreover, boost, skyrocket, opened up, powerful, inquiries, ever-evolving.
|
|
42
42
|
- Review your response and ensure no em dashes.
|
|
43
|
+
- MUST format FAQ sections using HTML `<details>` and `<summary>` tags. Ensure there is an empty line before and after the inner markdown content so it parses correctly.
|
|
44
|
+
- SHOULD try to use components from the `docs-src/src/components` folder when writing docs.
|
|
45
|
+
|
|
46
|
+
|
|
43
47
|
|
|
44
48
|
## Development Workflow
|
|
45
49
|
1. Make changes
|
package/CHANGELOG.md
CHANGED
|
@@ -5,14 +5,57 @@
|
|
|
5
5
|
|
|
6
6
|
<!-- ADD new changes here! -->
|
|
7
7
|
|
|
8
|
-
### 17.0.0-beta.17 (11 March 2026)
|
|
9
|
-
|
|
10
|
-
- A list of changes for RxDB v17 can be found [here](https://rxdb.info/releases/17.0.0.html)
|
|
11
|
-
|
|
12
8
|
<!-- /CHANGELOG NEWEST -->
|
|
13
9
|
|
|
14
10
|
<!-- RELEASE BELOW -->
|
|
15
11
|
|
|
12
|
+
### 17.1.0 (2 April 2026)
|
|
13
|
+
|
|
14
|
+
- FIX CRDT plugin `bulkInsert` hook not including schema default values in CRDT operations, causing data loss during conflict resolution rebuild when fields rely on schema defaults
|
|
15
|
+
- FIX `RxDocument.get$()` on nested object/array paths emitting spurious values when unrelated document fields changed, because `distinctUntilChanged()` used reference equality which always fails for non-primitive values across document revisions
|
|
16
|
+
- FIX `incrementalUpsert()` throwing a CONFLICT error when a concurrent `upsert()`/`insert()` creates the same document between the internal `findOne()` and `insert()` calls
|
|
17
|
+
- FIX `upsertLocal()` on a previously removed local document keeping the document in deleted state instead of un-deleting it
|
|
18
|
+
- FIX push-only replication losing local writes that occur during a pause because `reSync()` events were filtered out when no pull handler was configured
|
|
19
|
+
- FIX `getStartIndexStringFromUpperBound()` incorrectly mapping `INDEX_MIN` to `'1'` for boolean index fields, causing queries with exclusive bounds (`$gt`/`$lt`) on a field preceding a boolean index field to include boundary documents in the results
|
|
20
|
+
- FIX leader-election plugin not calling `die()` on the LeaderElector when the database is closed, because `LEADER_ELECTORS_OF_DB` was never populated due to a dead code branch
|
|
21
|
+
- FIX encryption plugin schema transformation not correctly handling nested dot-notation encrypted paths (e.g. `'nested.field'`), causing validation failures when using a validator storage with non-string nested encrypted fields
|
|
22
|
+
- FIX dev-mode `checkSchema()` not validating composite primary key fields for encryption (SC15), index (SC13), unique (SC14), and type (SC16) constraints because it compared property names against the primaryKey object instead of resolving the primary field path
|
|
23
|
+
- FIX `findOne().remove()` crashing with `TypeError: Cannot read properties of null` when no document matches the query, instead of returning `null`
|
|
24
|
+
- ADD `findOne().remove(true)` to throw when no document matches, consistent with `findOne().exec(true)`
|
|
25
|
+
- FIX schema migration losing `_deleted` state when migration strategy returns a new object, causing deleted documents to be resurrected after migration
|
|
26
|
+
- FIX `RxPipeline.remove()` not properly cleaning up checkpoint when called during active processing, causing a re-added pipeline with the same identifier to skip already-processed documents instead of starting fresh
|
|
27
|
+
- FIX cleanup plugin prematurely exiting its retry loop when `storageInstance.cleanup()` returns `false` (batched cleanup), because `Array.find()` returns the found value `false` and `!false` evaluates to `true`, causing `isDone` to be set incorrectly
|
|
28
|
+
- FIX encryption plugin `validatePassword()` leaking the plaintext password in `RxError` parameters and error messages when password validation fails
|
|
29
|
+
- FIX `database.remove()` not calling collection `onRemove` handlers, because `close()` unsubscribed all listeners before the remove operation could trigger them
|
|
30
|
+
- FIX query-builder `eq()`/`equals()` silently overwriting other operator conditions on the same field because the value was stored as a raw primitive instead of using the `$eq` operator form
|
|
31
|
+
- FIX `deleted$` observable emitting on every document revision instead of only when the deleted state changes, by adding `distinctUntilChanged()`
|
|
32
|
+
- FIX `postSave` collection hook not receiving the RxDocument instance as the second argument, unlike `postInsert` and `postRemove` which correctly pass it
|
|
33
|
+
- FIX `getJsonSchemaWithoutMeta()` not removing `_rev` from schema properties, while correctly removing other internal meta properties (`_deleted`, `_meta`, `_attachments`)
|
|
34
|
+
- FIX `allAttachments$` observable emitting attachments with a stale document reference, causing `attachment.doc` to point to an outdated document version instead of the latest one
|
|
35
|
+
- FIX RxState not correctly recovering full-state replacements (via `set('', modifier)`) from disk on database reopen, causing corrupted state
|
|
36
|
+
|
|
37
|
+
- FIX memory storage `count()` returning incorrect results when the selector is not fully satisfied by the index and the query has a `limit` set
|
|
38
|
+
|
|
39
|
+
- FIX `replicateRxCollection().remove()` on a never-started replication now creates the meta instance and deletes its data instead of skipping cleanup
|
|
40
|
+
- FIX `REPLICATION_STATE_BY_COLLECTION` not cleaned up on `cancel()`/`remove()`, leaking replication state references
|
|
41
|
+
- FIX floating-point rounding overflow in index string decimal generation, where `Math.round` could produce a value equal to the multiplier (e.g. 10 instead of max 9), creating a string one character too long and breaking sort order in compound indexes
|
|
42
|
+
- FIX `normalizeMangoQuery()` skipped fully-matching indexes when choosing default sort order, falling back to the first index instead of using the best match
|
|
43
|
+
- FIX RxState `set('', modifier)` passed `undefined` to the modifier instead of the current state
|
|
44
|
+
- FIX `RxMigrationStatus.count.percent` returning `NaN` instead of `100` when migrating a collection with 0 documents
|
|
45
|
+
- FIX `fillWithDefaultSettings()` index deduplication was broken because `Array.filter()` return value was discarded, causing duplicate indexes in schemas when user-defined indexes become identical after adding `_deleted` prefix and primary key suffix
|
|
46
|
+
- FIX encryption plugin not stripping type-specific schema keywords (`maxLength`, `required`, `items`, etc.) from encrypted fields, causing validation errors when using a validator storage with encryption
|
|
47
|
+
- FIX incorrect index string generation for negative decimal numbers causing wrong sort order and query results
|
|
48
|
+
- FIX `rateQueryPlan()` evaluated `startKeys` twice instead of `endKeys`, causing suboptimal index selection for `$lt`/`$lte` queries.
|
|
49
|
+
- FIX event-reduce mutating cached `docsDataMap` causing missing documents after insert-delete cycles
|
|
50
|
+
- FIX `modify()` not deep-cloning document data, allowing the modifier to corrupt internal state via shared nested references
|
|
51
|
+
- FIX `fillObjectWithDefaults` shared mutable references for non-primitive schema defaults (arrays/objects) causing corrupted values on subsequent inserts
|
|
52
|
+
|
|
53
|
+
### 17.0.0 (30 March 2026)
|
|
54
|
+
|
|
55
|
+
🚀 **RxDB v17 is released**
|
|
56
|
+
|
|
57
|
+
- A list of changes for RxDB v17 can be found [here](https://rxdb.info/releases/17.0.0.html)
|
|
58
|
+
|
|
16
59
|
### 16.21.1 (2 December 2025)
|
|
17
60
|
|
|
18
61
|
- feat: replication-supabase querybuilder [#7566](https://github.com/pubkey/rxdb/pull/7566)
|
package/CLAUDE.md
CHANGED
|
@@ -61,3 +61,5 @@ npm run check-types
|
|
|
61
61
|
- AVOID rhetorical questions.
|
|
62
62
|
- AVOID specific words like: very, really, literally, actually, certainly, probably, basically, delve, embark, enlightening, esteemed, shed light, craft, creative, imagine, realm, game-changer, unlock, discover, skyrocket, abyss, not alone, in a world where, revolutionize, disruptive, utilize, utilizing, dive deep, tapestry, illuminate, unveil, pivotal, intricate, elucidate, hence, furthermore, realm, however, harness, exciting, groundbreaking, cutting-edge, remarkable, it remains to be seen, glimpse into, navigating, landscape, stark, testament, in summary, in conclusion, moreover, boost, skyrocket, opened up, powerful, inquiries, ever-evolving.
|
|
63
63
|
- Review your response and ensure no em dashes.
|
|
64
|
+
- MUST format FAQ sections using HTML `<details>` and `<summary>` tags. Ensure there is an empty line before and after the inner markdown content so it parses correctly.
|
|
65
|
+
- SHOULD try to use components from the `docs-src/src/components` folder when writing docs.
|
|
@@ -7,6 +7,7 @@ exports.ChangeEventBuffer = void 0;
|
|
|
7
7
|
exports.createChangeEventBuffer = createChangeEventBuffer;
|
|
8
8
|
var _operators = require("rxjs/operators");
|
|
9
9
|
var _index = require("./plugins/utils/index.js");
|
|
10
|
+
var _rxError = require("./rx-error.js");
|
|
10
11
|
/**
|
|
11
12
|
* a buffer-cache which holds the last X changeEvents of the collection
|
|
12
13
|
*/
|
|
@@ -117,7 +118,7 @@ var ChangeEventBuffer = exports.ChangeEventBuffer = /*#__PURE__*/function () {
|
|
|
117
118
|
this.processTasks();
|
|
118
119
|
var ret = this.getFrom(pointer);
|
|
119
120
|
if (ret === null) {
|
|
120
|
-
throw
|
|
121
|
+
throw (0, _rxError.newRxError)('COB1');
|
|
121
122
|
} else {
|
|
122
123
|
ret.forEach(cE => fn(cE));
|
|
123
124
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"change-event-buffer.js","names":["_operators","require","_index","ChangeEventBuffer","exports","collection","subs","counter","eventCounterMap","WeakMap","buffer","limit","tasks","Set","push","eventBulks$","pipe","filter","bulk","isLocal","subscribe","eventBulk","add","_handleChangeEvents","events","size","requestIdlePromiseNoQueue","then","processTasks","_proto","prototype","Array","from","forEach","task","clear","counterBefore","length","slice","concat","counterBase","index","event","set","getCounter","getBuffer","getArrayIndexByPointer","pointer","oldestEvent","oldestCounter","get","rest","getFrom","ret","currentIndex","nextEvent","runFrom","fn","Error","cE","reduceByLastOfDoc","changeEvents","close","sub","unsubscribe","createChangeEventBuffer"],"sources":["../../src/change-event-buffer.ts"],"sourcesContent":["/**\r\n * a buffer-cache which holds the last X changeEvents of the collection\r\n */\r\nimport {\r\n Subscription\r\n} from 'rxjs';\r\nimport { filter } from 'rxjs/operators';\r\nimport type {\r\n RxChangeEventBulk,\r\n RxCollection,\r\n RxStorageChangeEvent\r\n} from './types/index.d.ts';\r\nimport {\r\n requestIdlePromiseNoQueue\r\n} from './plugins/utils/index.ts';\r\n\r\n\r\n/**\r\n * This buffer rembemers previous change events\r\n * so that queries can use them on .exec()\r\n * to calculate the new result set via event-reduce instead\r\n * of running the query against the storage.\r\n */\r\nexport class ChangeEventBuffer<RxDocType> {\r\n /**\r\n * These properties are private to ensure they cannot\r\n * be read without first processing the lazy tasks.\r\n */\r\n private subs: Subscription[] = [];\r\n private counter: number = 0;\r\n private eventCounterMap: WeakMap<\r\n RxStorageChangeEvent<RxDocType>,\r\n number\r\n > = new WeakMap();\r\n /**\r\n * array with changeEvents\r\n * starts with oldest known event, ends with newest\r\n */\r\n private buffer: RxStorageChangeEvent<RxDocType>[] = [];\r\n\r\n public limit: number = 100;\r\n\r\n\r\n\r\n private tasks = new Set<Function>();\r\n\r\n constructor(\r\n public collection: RxCollection\r\n ) {\r\n this.subs.push(\r\n this.collection.eventBulks$.pipe(\r\n filter((bulk: RxChangeEventBulk<RxDocType>) => !bulk.isLocal)\r\n ).subscribe((eventBulk: RxChangeEventBulk<RxDocType>) => {\r\n this.tasks.add(() => this._handleChangeEvents(eventBulk.events));\r\n if (this.tasks.size <= 1) {\r\n requestIdlePromiseNoQueue().then(() => {\r\n this.processTasks();\r\n });\r\n }\r\n })\r\n );\r\n }\r\n\r\n private processTasks() {\r\n if (this.tasks.size === 0) {\r\n return;\r\n }\r\n const tasks = Array.from(this.tasks);\r\n tasks.forEach(task => task());\r\n this.tasks.clear();\r\n }\r\n\r\n private _handleChangeEvents(events: RxStorageChangeEvent<RxDocType>[]) {\r\n const counterBefore = this.counter;\r\n this.counter = this.counter + events.length;\r\n if (events.length > this.limit) {\r\n this.buffer = events.slice(events.length * -1);\r\n } else {\r\n this.buffer = this.buffer.concat(events);\r\n this.buffer = this.buffer.slice(this.limit * -1);\r\n }\r\n const counterBase = counterBefore + 1;\r\n const eventCounterMap = this.eventCounterMap;\r\n for (let index = 0; index < events.length; index++) {\r\n const event = events[index];\r\n eventCounterMap.set(event, counterBase + index);\r\n }\r\n }\r\n\r\n getCounter() {\r\n this.processTasks();\r\n return this.counter;\r\n }\r\n getBuffer() {\r\n this.processTasks();\r\n return this.buffer;\r\n }\r\n\r\n /**\r\n * gets the array-index for the given pointer\r\n * @return arrayIndex which can be used to iterate from there. If null, pointer is out of lower bound\r\n */\r\n getArrayIndexByPointer(pointer: number): number | null {\r\n this.processTasks();\r\n const oldestEvent = this.buffer[0];\r\n const oldestCounter = this.eventCounterMap.get(\r\n oldestEvent\r\n ) as number;\r\n\r\n if (pointer < oldestCounter)\r\n return null; // out of bounds\r\n\r\n const rest = pointer - oldestCounter;\r\n return rest;\r\n }\r\n\r\n /**\r\n * get all changeEvents which came in later than the pointer-event\r\n * @return array with change-events. If null, pointer out of bounds\r\n */\r\n getFrom(pointer: number): RxStorageChangeEvent<RxDocType>[] | null {\r\n this.processTasks();\r\n const ret = [];\r\n let currentIndex = this.getArrayIndexByPointer(pointer);\r\n if (currentIndex === null) // out of bounds\r\n return null;\r\n\r\n while (true) {\r\n const nextEvent = this.buffer[currentIndex];\r\n currentIndex++;\r\n if (!nextEvent) {\r\n return ret;\r\n } else {\r\n ret.push(nextEvent);\r\n }\r\n }\r\n }\r\n\r\n runFrom(pointer: number, fn: Function) {\r\n this.processTasks();\r\n const ret = this.getFrom(pointer);\r\n if (ret === null) {\r\n throw new Error('out of bounds');\r\n } else {\r\n ret.forEach(cE => fn(cE));\r\n }\r\n }\r\n\r\n /**\r\n * no matter how many operations are done on one document,\r\n * only the last operation has to be checked to calculate the new state\r\n * this function reduces the events to the last ChangeEvent of each doc.\r\n * This functionality is currently disabled. It is questionable if\r\n * pre-merging the events would really be faster or actually slower.\r\n */\r\n reduceByLastOfDoc(changeEvents: RxStorageChangeEvent<RxDocType>[]): RxStorageChangeEvent<RxDocType>[] {\r\n this.processTasks();\r\n return changeEvents.slice(0);\r\n }\r\n\r\n close() {\r\n this.tasks.clear();\r\n this.subs.forEach(sub => sub.unsubscribe());\r\n }\r\n}\r\n\r\nexport function createChangeEventBuffer<RxdocType>(\r\n collection: RxCollection<RxdocType, any>\r\n) {\r\n return new ChangeEventBuffer<RxdocType>(collection);\r\n}\r\n"],"mappings":";;;;;;;AAMA,IAAAA,UAAA,GAAAC,OAAA;AAMA,IAAAC,MAAA,GAAAD,OAAA;AAZA;AACA;AACA;AAeA;AACA;AACA;AACA;AACA;AACA;AALA,IAMaE,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA;EAC1B;AACJ;AACA;AACA;;EAOI;AACJ;AACA;AACA;;EASI,SAAAA,kBACWE,UAAwB,EACjC;IAAA,KApBMC,IAAI,GAAmB,EAAE;IAAA,KACzBC,OAAO,GAAW,CAAC;IAAA,KACnBC,eAAe,GAGnB,IAAIC,OAAO,CAAC,CAAC;IAAA,KAKTC,MAAM,GAAsC,EAAE;IAAA,KAE/CC,KAAK,GAAW,GAAG;IAAA,KAIlBC,KAAK,GAAG,IAAIC,GAAG,CAAW,CAAC;IAAA,KAGxBR,UAAwB,GAAxBA,UAAwB;IAE/B,IAAI,CAACC,IAAI,CAACQ,IAAI,CACV,IAAI,CAACT,UAAU,CAACU,WAAW,CAACC,IAAI,CAC5B,IAAAC,iBAAM,EAAEC,IAAkC,IAAK,CAACA,IAAI,CAACC,OAAO,CAChE,CAAC,CAACC,SAAS,CAAEC,SAAuC,IAAK;MACrD,IAAI,CAACT,KAAK,CAACU,GAAG,CAAC,MAAM,IAAI,CAACC,mBAAmB,CAACF,SAAS,CAACG,MAAM,CAAC,CAAC;MAChE,IAAI,IAAI,CAACZ,KAAK,CAACa,IAAI,IAAI,CAAC,EAAE;QACtB,IAAAC,gCAAyB,EAAC,CAAC,CAACC,IAAI,CAAC,MAAM;UACnC,IAAI,CAACC,YAAY,CAAC,CAAC;QACvB,CAAC,CAAC;MACN;IACJ,CAAC,CACL,CAAC;EACL;EAAC,IAAAC,MAAA,GAAA1B,iBAAA,CAAA2B,SAAA;EAAAD,MAAA,CAEOD,YAAY,GAApB,SAAQA,Y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AP,SAAAA,OAAOA,CAACT,OAAe,EAAEU,EAAY,EAAE;IACnC,IAAI,CAAC7B,YAAY,CAAC,CAAC;IACnB,IAAMyB,GAAG,GAAG,IAAI,CAACD,OAAO,CAACL,OAAO,CAAC;IACjC,IAAIM,GAAG,KAAK,IAAI,EAAE;MACd,MAAM,IAAIK,KAAK,CAAC,eAAe,CAAC;IACpC,CAAC,MAAM;MACHL,GAAG,CAACpB,OAAO,CAAC0B,EAAE,IAAIF,EAAE,CAACE,EAAE,CAAC,CAAC;IAC7B;EACJ;;EAEA;AACJ;AACA;AACA;AACA;AACA;AACA,KANI;EAAA9B,MAAA,CAOA+B,iBAAiB,GAAjB,SAAAA,iBAAiBA,CAACC,YAA+C,EAAqC;IAClG,IAAI,CAACjC,YAAY,CAAC,CAAC;IACnB,OAAOiC,YAAY,CAACvB,KAAK,CAAC,CAAC,CAAC;EAChC,CAAC;EAAAT,MAAA,CAEDiC,KAAK,GAAL,SAAAA,KAAKA,CAAA,EAAG;IACJ,IAAI,CAAClD,KAAK,CAACuB,KAAK,CAAC,CAAC;IAClB,IAAI,CAAC7B,IAAI,CAAC2B,OAAO,CAAC8B,GAAG,IAAIA,GAAG,CAACC,WAAW,CAAC,CAAC,CAAC;EAC/C,CAAC;EAAA,OAAA7D,iBAAA;AAAA;AAGE,SAAS8D,uBAAuBA,CACnC5D,UAAwC,EAC1C;EACE,OAAO,IAAIF,iBAAiB,CAAYE,UAAU,CAAC;AACvD","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"change-event-buffer.js","names":["_operators","require","_index","_rxError","ChangeEventBuffer","exports","collection","subs","counter","eventCounterMap","WeakMap","buffer","limit","tasks","Set","push","eventBulks$","pipe","filter","bulk","isLocal","subscribe","eventBulk","add","_handleChangeEvents","events","size","requestIdlePromiseNoQueue","then","processTasks","_proto","prototype","Array","from","forEach","task","clear","counterBefore","length","slice","concat","counterBase","index","event","set","getCounter","getBuffer","getArrayIndexByPointer","pointer","oldestEvent","oldestCounter","get","rest","getFrom","ret","currentIndex","nextEvent","runFrom","fn","newRxError","cE","reduceByLastOfDoc","changeEvents","close","sub","unsubscribe","createChangeEventBuffer"],"sources":["../../src/change-event-buffer.ts"],"sourcesContent":["/**\r\n * a buffer-cache which holds the last X changeEvents of the collection\r\n */\r\nimport {\r\n Subscription\r\n} from 'rxjs';\r\nimport { filter } from 'rxjs/operators';\r\nimport type {\r\n RxChangeEventBulk,\r\n RxCollection,\r\n RxStorageChangeEvent\r\n} from './types/index.d.ts';\r\nimport {\r\n requestIdlePromiseNoQueue\r\n} from './plugins/utils/index.ts';\r\nimport {\r\n newRxError\r\n} from './rx-error.ts';\r\n\r\n\r\n/**\r\n * This buffer rembemers previous change events\r\n * so that queries can use them on .exec()\r\n * to calculate the new result set via event-reduce instead\r\n * of running the query against the storage.\r\n */\r\nexport class ChangeEventBuffer<RxDocType> {\r\n /**\r\n * These properties are private to ensure they cannot\r\n * be read without first processing the lazy tasks.\r\n */\r\n private subs: Subscription[] = [];\r\n private counter: number = 0;\r\n private eventCounterMap: WeakMap<\r\n RxStorageChangeEvent<RxDocType>,\r\n number\r\n > = new WeakMap();\r\n /**\r\n * array with changeEvents\r\n * starts with oldest known event, ends with newest\r\n */\r\n private buffer: RxStorageChangeEvent<RxDocType>[] = [];\r\n\r\n public limit: number = 100;\r\n\r\n\r\n\r\n private tasks = new Set<Function>();\r\n\r\n constructor(\r\n public collection: RxCollection\r\n ) {\r\n this.subs.push(\r\n this.collection.eventBulks$.pipe(\r\n filter((bulk: RxChangeEventBulk<RxDocType>) => !bulk.isLocal)\r\n ).subscribe((eventBulk: RxChangeEventBulk<RxDocType>) => {\r\n this.tasks.add(() => this._handleChangeEvents(eventBulk.events));\r\n if (this.tasks.size <= 1) {\r\n requestIdlePromiseNoQueue().then(() => {\r\n this.processTasks();\r\n });\r\n }\r\n })\r\n );\r\n }\r\n\r\n private processTasks() {\r\n if (this.tasks.size === 0) {\r\n return;\r\n }\r\n const tasks = Array.from(this.tasks);\r\n tasks.forEach(task => task());\r\n this.tasks.clear();\r\n }\r\n\r\n private _handleChangeEvents(events: RxStorageChangeEvent<RxDocType>[]) {\r\n const counterBefore = this.counter;\r\n this.counter = this.counter + events.length;\r\n if (events.length > this.limit) {\r\n this.buffer = events.slice(events.length * -1);\r\n } else {\r\n this.buffer = this.buffer.concat(events);\r\n this.buffer = this.buffer.slice(this.limit * -1);\r\n }\r\n const counterBase = counterBefore + 1;\r\n const eventCounterMap = this.eventCounterMap;\r\n for (let index = 0; index < events.length; index++) {\r\n const event = events[index];\r\n eventCounterMap.set(event, counterBase + index);\r\n }\r\n }\r\n\r\n getCounter() {\r\n this.processTasks();\r\n return this.counter;\r\n }\r\n getBuffer() {\r\n this.processTasks();\r\n return this.buffer;\r\n }\r\n\r\n /**\r\n * gets the array-index for the given pointer\r\n * @return arrayIndex which can be used to iterate from there. If null, pointer is out of lower bound\r\n */\r\n getArrayIndexByPointer(pointer: number): number | null {\r\n this.processTasks();\r\n const oldestEvent = this.buffer[0];\r\n const oldestCounter = this.eventCounterMap.get(\r\n oldestEvent\r\n ) as number;\r\n\r\n if (pointer < oldestCounter)\r\n return null; // out of bounds\r\n\r\n const rest = pointer - oldestCounter;\r\n return rest;\r\n }\r\n\r\n /**\r\n * get all changeEvents which came in later than the pointer-event\r\n * @return array with change-events. If null, pointer out of bounds\r\n */\r\n getFrom(pointer: number): RxStorageChangeEvent<RxDocType>[] | null {\r\n this.processTasks();\r\n const ret = [];\r\n let currentIndex = this.getArrayIndexByPointer(pointer);\r\n if (currentIndex === null) // out of bounds\r\n return null;\r\n\r\n while (true) {\r\n const nextEvent = this.buffer[currentIndex];\r\n currentIndex++;\r\n if (!nextEvent) {\r\n return ret;\r\n } else {\r\n ret.push(nextEvent);\r\n }\r\n }\r\n }\r\n\r\n runFrom(pointer: number, fn: Function) {\r\n this.processTasks();\r\n const ret = this.getFrom(pointer);\r\n if (ret === null) {\r\n throw newRxError('COB1');\r\n } else {\r\n ret.forEach(cE => fn(cE));\r\n }\r\n }\r\n\r\n /**\r\n * no matter how many operations are done on one document,\r\n * only the last operation has to be checked to calculate the new state\r\n * this function reduces the events to the last ChangeEvent of each doc.\r\n * This functionality is currently disabled. It is questionable if\r\n * pre-merging the events would really be faster or actually slower.\r\n */\r\n reduceByLastOfDoc(changeEvents: RxStorageChangeEvent<RxDocType>[]): RxStorageChangeEvent<RxDocType>[] {\r\n this.processTasks();\r\n return changeEvents.slice(0);\r\n }\r\n\r\n close() {\r\n this.tasks.clear();\r\n this.subs.forEach(sub => sub.unsubscribe());\r\n }\r\n}\r\n\r\nexport function createChangeEventBuffer<RxdocType>(\r\n collection: RxCollection<RxdocType, any>\r\n) {\r\n return new ChangeEventBuffer<RxdocType>(collection);\r\n}\r\n"],"mappings":";;;;;;;AAMA,IAAAA,UAAA,GAAAC,OAAA;AAMA,IAAAC,MAAA,GAAAD,OAAA;AAGA,IAAAE,QAAA,GAAAF,OAAA;AAfA;AACA;AACA;AAkBA;AACA;AACA;AACA;AACA;AACA;AALA,IAMaG,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA;EAC1B;AACJ;AACA;AACA;;EAOI;AACJ;AACA;AACA;;EASI,SAAAA,kBACWE,UAAwB,EACjC;IAAA,KApBMC,IAAI,GAAmB,EAAE;IAAA,KACzBC,OAAO,GAAW,CAAC;IAAA,KACnBC,eAAe,GAGnB,IAAIC,OAAO,CAAC,CAAC;IAAA,KAKTC,MAAM,GAAsC,EAAE;IAAA,KAE/CC,KAAK,GAAW,GAAG;IAAA,KAIlBC,KAAK,GAAG,IAAIC,GAAG,CAAW,CAAC;IAAA,KAGxBR,UAAwB,GAAxBA,UAAwB;IAE/B,IAAI,CAACC,IAAI,CAACQ,IAAI,CACV,IAAI,CAACT,UAAU,CAACU,WAAW,CAACC,IAAI,CAC5B,IAAAC,iBAAM,EAAEC,IAAkC,IAAK,CAACA,IAAI,CAACC,OAAO,CAChE,CAAC,CAACC,SAAS,CAAEC,SAAuC,IAAK;MACrD,IAAI,CAAC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C,EAC1C;EACE,OAAO,IAAIF,iBAAiB,CAAYE,UAAU,CAAC;AACvD","ignoreList":[]}
|
package/dist/cjs/custom-index.js
CHANGED
|
@@ -15,6 +15,7 @@ exports.getStringLengthOfIndexNumber = getStringLengthOfIndexNumber;
|
|
|
15
15
|
var _rxSchemaHelper = require("./rx-schema-helper.js");
|
|
16
16
|
var _index = require("./plugins/utils/index.js");
|
|
17
17
|
var _queryPlanner = require("./query-planner.js");
|
|
18
|
+
var _rxError = require("./rx-error.js");
|
|
18
19
|
/**
|
|
19
20
|
* For some RxStorage implementations,
|
|
20
21
|
* we need to use our custom crafted indexes
|
|
@@ -38,7 +39,9 @@ function getIndexMeta(schema, index) {
|
|
|
38
39
|
var fieldNameProperties = index.map(fieldName => {
|
|
39
40
|
var schemaPart = (0, _rxSchemaHelper.getSchemaByObjectPath)(schema, fieldName);
|
|
40
41
|
if (!schemaPart) {
|
|
41
|
-
throw
|
|
42
|
+
throw (0, _rxError.newRxError)('CI1', {
|
|
43
|
+
fieldName
|
|
44
|
+
});
|
|
42
45
|
}
|
|
43
46
|
var type = schemaPart.type;
|
|
44
47
|
var parsedLengths;
|
|
@@ -63,10 +66,51 @@ function getIndexMeta(schema, index) {
|
|
|
63
66
|
};
|
|
64
67
|
} else {
|
|
65
68
|
// number
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
/**
|
|
70
|
+
* @performance
|
|
71
|
+
* Inline the number index string generation to avoid
|
|
72
|
+
* function call overhead and redundant boundary checks.
|
|
73
|
+
* Document data in the hot path is assumed to be valid.
|
|
74
|
+
*/
|
|
75
|
+
var pLengths = parsedLengths;
|
|
76
|
+
var pMin = pLengths.minimum;
|
|
77
|
+
var pMax = pLengths.maximum;
|
|
78
|
+
var pRoundedMin = pLengths.roundedMinimum;
|
|
79
|
+
var pNonDecimals = pLengths.nonDecimals;
|
|
80
|
+
var pDecimals = pLengths.decimals;
|
|
81
|
+
var pMultiplier = pLengths.multiplier;
|
|
82
|
+
if (pDecimals === 0) {
|
|
83
|
+
getIndexStringPart = docData => {
|
|
84
|
+
var fieldValue = getValue(docData);
|
|
85
|
+
if (typeof fieldValue === 'undefined') {
|
|
86
|
+
fieldValue = 0;
|
|
87
|
+
}
|
|
88
|
+
if (fieldValue < pMin) {
|
|
89
|
+
fieldValue = pMin;
|
|
90
|
+
}
|
|
91
|
+
if (fieldValue > pMax) {
|
|
92
|
+
fieldValue = pMax;
|
|
93
|
+
}
|
|
94
|
+
return (Math.floor(fieldValue) - pRoundedMin).toString().padStart(pNonDecimals, '0');
|
|
95
|
+
};
|
|
96
|
+
} else {
|
|
97
|
+
getIndexStringPart = docData => {
|
|
98
|
+
var fieldValue = getValue(docData);
|
|
99
|
+
if (typeof fieldValue === 'undefined') {
|
|
100
|
+
fieldValue = 0;
|
|
101
|
+
}
|
|
102
|
+
if (fieldValue < pMin) {
|
|
103
|
+
fieldValue = pMin;
|
|
104
|
+
}
|
|
105
|
+
if (fieldValue > pMax) {
|
|
106
|
+
fieldValue = pMax;
|
|
107
|
+
}
|
|
108
|
+
var flooredValue = Math.floor(fieldValue);
|
|
109
|
+
var shifted = Math.min(Math.round((fieldValue - flooredValue) * pMultiplier), pMultiplier - 1);
|
|
110
|
+
var str = (flooredValue - pRoundedMin).toString().padStart(pNonDecimals, '0');
|
|
111
|
+
return str + shifted.toString().padStart(pDecimals, '0');
|
|
112
|
+
};
|
|
113
|
+
}
|
|
70
114
|
}
|
|
71
115
|
var ret = {
|
|
72
116
|
fieldName,
|
|
@@ -98,7 +142,22 @@ function getIndexableStringMonad(schema, index) {
|
|
|
98
142
|
|
|
99
143
|
/**
|
|
100
144
|
* @hotPath Performance of this function is very critical!
|
|
145
|
+
* Specialize for common field counts to avoid loop overhead.
|
|
101
146
|
*/
|
|
147
|
+
if (fieldNamePropertiesAmount === 1) {
|
|
148
|
+
return indexPartsFunctions[0];
|
|
149
|
+
}
|
|
150
|
+
if (fieldNamePropertiesAmount === 2) {
|
|
151
|
+
var fn0 = indexPartsFunctions[0];
|
|
152
|
+
var fn1 = indexPartsFunctions[1];
|
|
153
|
+
return docData => fn0(docData) + fn1(docData);
|
|
154
|
+
}
|
|
155
|
+
if (fieldNamePropertiesAmount === 3) {
|
|
156
|
+
var _fn = indexPartsFunctions[0];
|
|
157
|
+
var _fn2 = indexPartsFunctions[1];
|
|
158
|
+
var fn2 = indexPartsFunctions[2];
|
|
159
|
+
return docData => _fn(docData) + _fn2(docData) + fn2(docData);
|
|
160
|
+
}
|
|
102
161
|
var ret = function (docData) {
|
|
103
162
|
var str = '';
|
|
104
163
|
for (var i = 0; i < fieldNamePropertiesAmount; ++i) {
|
|
@@ -124,7 +183,8 @@ function getStringLengthOfIndexNumber(schemaPart) {
|
|
|
124
183
|
maximum,
|
|
125
184
|
nonDecimals,
|
|
126
185
|
decimals,
|
|
127
|
-
roundedMinimum: minimum
|
|
186
|
+
roundedMinimum: minimum,
|
|
187
|
+
multiplier: Math.pow(10, decimals)
|
|
128
188
|
};
|
|
129
189
|
}
|
|
130
190
|
function getIndexStringLength(schema, index) {
|
|
@@ -172,9 +232,16 @@ function getNumberIndexString(parsedLengths, fieldValue) {
|
|
|
172
232
|
var nonDecimalsValueAsString = (Math.floor(fieldValue) - parsedLengths.roundedMinimum).toString();
|
|
173
233
|
var str = nonDecimalsValueAsString.padStart(parsedLengths.nonDecimals, '0');
|
|
174
234
|
if (parsedLengths.decimals > 0) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
235
|
+
/**
|
|
236
|
+
* @performance
|
|
237
|
+
* Use math to extract decimal digits instead of toString().split('.')
|
|
238
|
+
* which creates intermediate strings and arrays.
|
|
239
|
+
* multiplier is pre-computed in ParsedLengths to avoid Math.pow() per call.
|
|
240
|
+
*/
|
|
241
|
+
var multiplier = parsedLengths.multiplier;
|
|
242
|
+
var shifted = Math.min(Math.round((fieldValue - Math.floor(fieldValue)) * multiplier), multiplier - 1);
|
|
243
|
+
var decimalPart = shifted.toString();
|
|
244
|
+
str += decimalPart.padStart(parsedLengths.decimals, '0');
|
|
178
245
|
}
|
|
179
246
|
return str;
|
|
180
247
|
}
|
|
@@ -220,7 +287,9 @@ function getStartIndexStringFromLowerBound(schema, index, lowerBound) {
|
|
|
220
287
|
}
|
|
221
288
|
break;
|
|
222
289
|
default:
|
|
223
|
-
throw
|
|
290
|
+
throw (0, _rxError.newRxError)('CI2', {
|
|
291
|
+
type: type
|
|
292
|
+
});
|
|
224
293
|
}
|
|
225
294
|
});
|
|
226
295
|
return str;
|
|
@@ -243,8 +312,10 @@ function getStartIndexStringFromUpperBound(schema, index, upperBound) {
|
|
|
243
312
|
}
|
|
244
313
|
break;
|
|
245
314
|
case 'boolean':
|
|
246
|
-
if (bound === null) {
|
|
315
|
+
if (bound === null || bound === _queryPlanner.INDEX_MAX) {
|
|
247
316
|
str += '1';
|
|
317
|
+
} else if (bound === _queryPlanner.INDEX_MIN) {
|
|
318
|
+
str += '0';
|
|
248
319
|
} else {
|
|
249
320
|
var boolToStr = bound ? '1' : '0';
|
|
250
321
|
str += boolToStr;
|
|
@@ -264,7 +335,9 @@ function getStartIndexStringFromUpperBound(schema, index, upperBound) {
|
|
|
264
335
|
}
|
|
265
336
|
break;
|
|
266
337
|
default:
|
|
267
|
-
throw
|
|
338
|
+
throw (0, _rxError.newRxError)('CI2', {
|
|
339
|
+
type: type
|
|
340
|
+
});
|
|
268
341
|
}
|
|
269
342
|
});
|
|
270
343
|
return str;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-index.js","names":["_rxSchemaHelper","require","_index","_queryPlanner","getIndexMeta","schema","index","fieldNameProperties","map","fieldName","schemaPart","getSchemaByObjectPath","Error","type","parsedLengths","getStringLengthOfIndexNumber","getValue","objectPathMonad","maxLength","getIndexStringPart","docData","fieldValue","padEnd","getNumberIndexString","ret","getIndexableStringMonad","fieldNamePropertiesAmount","length","indexPartsFunctions","r","str","i","minimum","Math","floor","maximum","ceil","multipleOf","valueSpan","nonDecimals","toString","multipleOfParts","split","decimals","roundedMinimum","getIndexStringLength","forEach","props","getPrimaryKeyFromIndexableString","indexableString","primaryKeyLength","paddedPrimaryKey","slice","primaryKey","trim","nonDecimalsValueAsString","padStart","splitByDecimalPoint","decimalValueAsString","getStartIndexStringFromLowerBound","lowerBound","idx","bound","ensureNotFalsy","INDEX_MIN","INDEX_MAX","boolToStr","fillChar","repeat","add","getStartIndexStringFromUpperBound","upperBound","changeIndexableStringByOneQuantum","direction","lastChar","charCode","charCodeAt","withoutLastChar","String","fromCharCode"],"sources":["../../src/custom-index.ts"],"sourcesContent":["/**\r\n * For some RxStorage implementations,\r\n * we need to use our custom crafted indexes\r\n * so we can easily iterate over them. And sort plain arrays of document data.\r\n *\r\n * We really often have to craft an index string for a given document.\r\n * Performance of everything in this file is very important\r\n * which is why the code sometimes looks strange.\r\n * Run performance tests before and after you touch anything here!\r\n */\r\n\r\nimport {\r\n getSchemaByObjectPath\r\n} from './rx-schema-helper.ts';\r\nimport type {\r\n JsonSchema,\r\n RxDocumentData,\r\n RxJsonSchema\r\n} from './types/index.d.ts';\r\nimport {\r\n ensureNotFalsy,\r\n objectPathMonad,\r\n ObjectPathMonadFunction\r\n} from './plugins/utils/index.ts';\r\nimport {\r\n INDEX_MAX,\r\n INDEX_MIN\r\n} from './query-planner.ts';\r\n\r\n\r\n/**\r\n * Prepare all relevant information\r\n * outside of the returned function\r\n * from getIndexableStringMonad()\r\n * to save performance when the returned\r\n * function is called many times.\r\n */\r\ntype IndexMetaField<RxDocType> = {\r\n fieldName: string;\r\n schemaPart: JsonSchema;\r\n /*\r\n * Only in number fields.\r\n */\r\n parsedLengths?: ParsedLengths;\r\n getValue: ObjectPathMonadFunction<RxDocType>;\r\n getIndexStringPart: (docData: RxDocumentData<RxDocType>) => string;\r\n};\r\n\r\nexport function getIndexMeta<RxDocType>(\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>,\r\n index: string[]\r\n): IndexMetaField<RxDocType>[] {\r\n const fieldNameProperties: IndexMetaField<RxDocType>[] = index.map(fieldName => {\r\n const schemaPart = getSchemaByObjectPath(\r\n schema,\r\n fieldName\r\n );\r\n if (!schemaPart) {\r\n throw new Error('not in schema: ' + fieldName);\r\n }\r\n const type = schemaPart.type;\r\n let parsedLengths: ParsedLengths | undefined;\r\n if (type === 'number' || type === 'integer') {\r\n parsedLengths = getStringLengthOfIndexNumber(\r\n schemaPart\r\n );\r\n }\r\n\r\n const getValue = objectPathMonad(fieldName);\r\n const maxLength = schemaPart.maxLength ? schemaPart.maxLength : 0;\r\n\r\n let getIndexStringPart: (docData: RxDocumentData<RxDocType>) => string;\r\n if (type === 'string') {\r\n getIndexStringPart = docData => {\r\n let fieldValue = getValue(docData);\r\n if (!fieldValue) {\r\n fieldValue = '';\r\n }\r\n return fieldValue.padEnd(maxLength, ' ');\r\n };\r\n } else if (type === 'boolean') {\r\n getIndexStringPart = docData => {\r\n const fieldValue = getValue(docData);\r\n return fieldValue ? '1' : '0';\r\n };\r\n } else { // number\r\n getIndexStringPart = docData => {\r\n const fieldValue = getValue(docData);\r\n return getNumberIndexString(\r\n parsedLengths as any,\r\n fieldValue\r\n );\r\n };\r\n }\r\n\r\n const ret: IndexMetaField<RxDocType> = {\r\n fieldName,\r\n schemaPart,\r\n parsedLengths,\r\n getValue,\r\n getIndexStringPart\r\n };\r\n return ret;\r\n });\r\n return fieldNameProperties;\r\n}\r\n\r\n\r\n/**\r\n * Crafts an indexable string that can be used\r\n * to check if a document would be sorted below or above\r\n * another documents, dependent on the index values.\r\n * @monad for better performance\r\n *\r\n * IMPORTANT: Performance is really important here\r\n * which is why we code so 'strange'.\r\n * Always run performance tests when you want to\r\n * change something in this method.\r\n */\r\nexport function getIndexableStringMonad<RxDocType>(\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>,\r\n index: string[]\r\n): (docData: RxDocumentData<RxDocType>) => string {\r\n const fieldNameProperties = getIndexMeta(schema, index);\r\n const fieldNamePropertiesAmount = fieldNameProperties.length;\r\n const indexPartsFunctions = fieldNameProperties.map(r => r.getIndexStringPart);\r\n\r\n\r\n /**\r\n * @hotPath Performance of this function is very critical!\r\n */\r\n const ret = function (docData: RxDocumentData<RxDocType>): string {\r\n let str = '';\r\n for (let i = 0; i < fieldNamePropertiesAmount; ++i) {\r\n str += indexPartsFunctions[i](docData);\r\n }\r\n return str;\r\n };\r\n return ret;\r\n}\r\n\r\n\r\ndeclare type ParsedLengths = {\r\n minimum: number;\r\n maximum: number;\r\n nonDecimals: number;\r\n decimals: number;\r\n roundedMinimum: number;\r\n};\r\nexport function getStringLengthOfIndexNumber(\r\n schemaPart: JsonSchema\r\n): ParsedLengths {\r\n const minimum = Math.floor(schemaPart.minimum as number);\r\n const maximum = Math.ceil(schemaPart.maximum as number);\r\n const multipleOf: number = schemaPart.multipleOf as number;\r\n\r\n const valueSpan = maximum - minimum;\r\n const nonDecimals = valueSpan.toString().length;\r\n\r\n const multipleOfParts = multipleOf.toString().split('.');\r\n let decimals = 0;\r\n if (multipleOfParts.length > 1) {\r\n decimals = multipleOfParts[1].length;\r\n }\r\n return {\r\n minimum,\r\n maximum,\r\n nonDecimals,\r\n decimals,\r\n roundedMinimum: minimum\r\n };\r\n}\r\n\r\nexport function getIndexStringLength<RxDocType>(\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>,\r\n index: string[]\r\n): number {\r\n const fieldNameProperties = getIndexMeta(schema, index);\r\n let length = 0;\r\n fieldNameProperties.forEach(props => {\r\n const schemaPart = props.schemaPart;\r\n const type = schemaPart.type;\r\n\r\n if (type === 'string') {\r\n length += schemaPart.maxLength as number;\r\n } else if (type === 'boolean') {\r\n length += 1;\r\n } else {\r\n const parsedLengths = props.parsedLengths as ParsedLengths;\r\n length = length + parsedLengths.nonDecimals + parsedLengths.decimals;\r\n }\r\n\r\n });\r\n return length;\r\n}\r\n\r\n\r\nexport function getPrimaryKeyFromIndexableString(\r\n indexableString: string,\r\n primaryKeyLength: number\r\n): string {\r\n const paddedPrimaryKey = indexableString.slice(primaryKeyLength * -1);\r\n // we can safely trim here because the primary key is not allowed to start or end with a space char.\r\n const primaryKey = paddedPrimaryKey.trim();\r\n return primaryKey;\r\n}\r\n\r\n\r\nexport function getNumberIndexString(\r\n parsedLengths: ParsedLengths,\r\n fieldValue: number\r\n): string {\r\n /**\r\n * Ensure that the given value is in the boundaries\r\n * of the schema, otherwise it would create a broken index string.\r\n * This can happen for example if you have a minimum of 0\r\n * and run a query like\r\n * selector {\r\n * numField: { $gt: -1000 }\r\n * }\r\n */\r\n if (typeof fieldValue === 'undefined') {\r\n fieldValue = 0;\r\n }\r\n if (fieldValue < parsedLengths.minimum) {\r\n fieldValue = parsedLengths.minimum;\r\n }\r\n if (fieldValue > parsedLengths.maximum) {\r\n fieldValue = parsedLengths.maximum;\r\n }\r\n\r\n const nonDecimalsValueAsString = (Math.floor(fieldValue) - parsedLengths.roundedMinimum).toString();\r\n let str = nonDecimalsValueAsString.padStart(parsedLengths.nonDecimals, '0');\r\n\r\n if (parsedLengths.decimals > 0) {\r\n const splitByDecimalPoint = fieldValue.toString().split('.');\r\n const decimalValueAsString = splitByDecimalPoint.length > 1 ? splitByDecimalPoint[1] : '0';\r\n str += decimalValueAsString.padEnd(parsedLengths.decimals, '0');\r\n }\r\n return str;\r\n}\r\n\r\nexport function getStartIndexStringFromLowerBound(\r\n schema: RxJsonSchema<any>,\r\n index: string[],\r\n lowerBound: (string | boolean | number | null | undefined)[]\r\n): string {\r\n let str = '';\r\n index.forEach((fieldName, idx) => {\r\n const schemaPart = getSchemaByObjectPath(\r\n schema,\r\n fieldName\r\n );\r\n const bound = lowerBound[idx];\r\n const type = schemaPart.type;\r\n\r\n switch (type) {\r\n case 'string':\r\n const maxLength = ensureNotFalsy(schemaPart.maxLength, 'maxLength not set');\r\n if (typeof bound === 'string') {\r\n str += (bound as string).padEnd(maxLength, ' ');\r\n } else {\r\n // str += ''.padStart(maxLength, inclusiveStart ? ' ' : INDEX_MAX);\r\n str += ''.padEnd(maxLength, ' ');\r\n }\r\n break;\r\n case 'boolean':\r\n if (bound === null) {\r\n str += '0';\r\n } else if (bound === INDEX_MIN) {\r\n str += '0';\r\n } else if (bound === INDEX_MAX) {\r\n str += '1';\r\n } else {\r\n const boolToStr = bound ? '1' : '0';\r\n str += boolToStr;\r\n }\r\n break;\r\n case 'number':\r\n case 'integer':\r\n const parsedLengths = getStringLengthOfIndexNumber(\r\n schemaPart\r\n );\r\n if (bound === null || bound === INDEX_MIN) {\r\n const fillChar = '0';\r\n str += fillChar.repeat(parsedLengths.nonDecimals + parsedLengths.decimals);\r\n } else if (bound === INDEX_MAX) {\r\n str += getNumberIndexString(\r\n parsedLengths,\r\n parsedLengths.maximum\r\n );\r\n } else {\r\n const add = getNumberIndexString(\r\n parsedLengths,\r\n bound as number\r\n );\r\n str += add;\r\n }\r\n break;\r\n default:\r\n throw new Error('unknown index type ' + type);\r\n }\r\n });\r\n return str;\r\n}\r\n\r\n\r\nexport function getStartIndexStringFromUpperBound(\r\n schema: RxJsonSchema<any>,\r\n index: string[],\r\n upperBound: (string | boolean | number | null | undefined)[]\r\n): string {\r\n let str = '';\r\n index.forEach((fieldName, idx) => {\r\n const schemaPart = getSchemaByObjectPath(\r\n schema,\r\n fieldName\r\n );\r\n const bound = upperBound[idx];\r\n const type = schemaPart.type;\r\n\r\n switch (type) {\r\n case 'string':\r\n const maxLength = ensureNotFalsy(schemaPart.maxLength, 'maxLength not set');\r\n if (typeof bound === 'string' && bound !== INDEX_MAX) {\r\n str += (bound as string).padEnd(maxLength, ' ');\r\n } else if (bound === INDEX_MIN) {\r\n str += ''.padEnd(maxLength, ' ');\r\n } else {\r\n str += ''.padEnd(maxLength, INDEX_MAX);\r\n }\r\n break;\r\n case 'boolean':\r\n if (bound === null) {\r\n str += '1';\r\n } else {\r\n const boolToStr = bound ? '1' : '0';\r\n str += boolToStr;\r\n }\r\n break;\r\n case 'number':\r\n case 'integer':\r\n const parsedLengths = getStringLengthOfIndexNumber(\r\n schemaPart\r\n );\r\n if (bound === null || bound === INDEX_MAX) {\r\n const fillChar = '9';\r\n str += fillChar.repeat(parsedLengths.nonDecimals + parsedLengths.decimals);\r\n } else if (bound === INDEX_MIN) {\r\n const fillChar = '0';\r\n str += fillChar.repeat(parsedLengths.nonDecimals + parsedLengths.decimals);\r\n } else {\r\n str += getNumberIndexString(\r\n parsedLengths,\r\n bound as number\r\n );\r\n }\r\n break;\r\n default:\r\n throw new Error('unknown index type ' + type);\r\n }\r\n });\r\n return str;\r\n}\r\n\r\n/**\r\n * Used in storages where it is not possible\r\n * to define inclusiveEnd/inclusiveStart\r\n */\r\nexport function changeIndexableStringByOneQuantum(str: string, direction: 1 | -1): string {\r\n const lastChar = str.slice(-1);\r\n let charCode = lastChar.charCodeAt(0);\r\n charCode = charCode + direction;\r\n const withoutLastChar = str.slice(0, -1);\r\n return withoutLastChar + String.fromCharCode(charCode);\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;AAWA,IAAAA,eAAA,GAAAC,OAAA;AAQA,IAAAC,MAAA,GAAAD,OAAA;AAKA,IAAAE,aAAA,GAAAF,OAAA;AAxBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAqBA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYO,SAASG,YAAYA,CACxBC,MAA+C,EAC/CC,KAAe,EACY;EAC3B,IAAMC,mBAAgD,GAAGD,KAAK,CAACE,GAAG,CAACC,SAAS,IAAI;IAC5E,IAAMC,UAAU,GAAG,IAAAC,qCAAqB,EACpCN,MAAM,EACNI,SACJ,CAAC;IACD,IAAI,CAACC,UAAU,EAAE;MACb,MAAM,IAAIE,KAAK,CAAC,iBAAiB,GAAGH,SAAS,CAAC;IAClD;IACA,IAAMI,IAAI,GAAGH,UAAU,CAACG,IAAI;IAC5B,IAAIC,aAAwC;IAC5C,IAAID,IAAI,KAAK,QAAQ,IAAIA,IAAI,KAAK,SAAS,EAAE;MACzCC,aAAa,GAAGC,4BAA4B,CACxCL,UACJ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C6B,QAAQ,CAAC;QAC9E,CAAC,MAAM;UACHb,GAAG,IAAIP,oBAAoB,CACvBT,aAAa,EACbgD,KACJ,CAAC;QACL;QACA;MACJ;QACI,MAAM,IAAIlD,KAAK,CAAC,qBAAqB,GAAGC,IAAI,CAAC;IACrD;EACJ,CAAC,CAAC;EACF,OAAOiB,GAAG;AACd;;AAEA;AACA;AACA;AACA;AACO,SAAS0C,iCAAiCA,CAAC1C,GAAW,EAAE2C,SAAiB,EAAU;EACtF,IAAMC,QAAQ,GAAG5C,GAAG,CAACsB,KAAK,CAAC,CAAC,CAAC,CAAC;EAC9B,IAAIuB,QAAQ,GAAGD,QAAQ,CAACE,UAAU,CAAC,CAAC,CAAC;EACrCD,QAAQ,GAAGA,QAAQ,GAAGF,SAAS;EAC/B,IAAMI,eAAe,GAAG/C,GAAG,CAACsB,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;EACxC,OAAOyB,eAAe,GAAGC,MAAM,CAACC,YAAY,CAACJ,QAAQ,CAAC;AAC1D","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"custom-index.js","names":["_rxSchemaHelper","require","_index","_queryPlanner","_rxError","getIndexMeta","schema","index","fieldNameProperties","map","fieldName","schemaPart","getSchemaByObjectPath","newRxError","type","parsedLengths","getStringLengthOfIndexNumber","getValue","objectPathMonad","maxLength","getIndexStringPart","docData","fieldValue","padEnd","pLengths","pMin","minimum","pMax","maximum","pRoundedMin","roundedMinimum","pNonDecimals","nonDecimals","pDecimals","decimals","pMultiplier","multiplier","Math","floor","toString","padStart","flooredValue","shifted","min","round","str","ret","getIndexableStringMonad","fieldNamePropertiesAmount","length","indexPartsFunctions","r","fn0","fn1","fn2","i","ceil","multipleOf","valueSpan","multipleOfParts","split","pow","getIndexStringLength","forEach","props","getPrimaryKeyFromIndexableString","indexableString","primaryKeyLength","paddedPrimaryKey","slice","primaryKey","trim","getNumberIndexString","nonDecimalsValueAsString","decimalPart","getStartIndexStringFromLowerBound","lowerBound","idx","bound","ensureNotFalsy","INDEX_MIN","INDEX_MAX","boolToStr","fillChar","repeat","add","getStartIndexStringFromUpperBound","upperBound","changeIndexableStringByOneQuantum","direction","lastChar","charCode","charCodeAt","withoutLastChar","String","fromCharCode"],"sources":["../../src/custom-index.ts"],"sourcesContent":["/**\r\n * For some RxStorage implementations,\r\n * we need to use our custom crafted indexes\r\n * so we can easily iterate over them. And sort plain arrays of document data.\r\n *\r\n * We really often have to craft an index string for a given document.\r\n * Performance of everything in this file is very important\r\n * which is why the code sometimes looks strange.\r\n * Run performance tests before and after you touch anything here!\r\n */\r\n\r\nimport {\r\n getSchemaByObjectPath\r\n} from './rx-schema-helper.ts';\r\nimport type {\r\n JsonSchema,\r\n RxDocumentData,\r\n RxJsonSchema\r\n} from './types/index.d.ts';\r\nimport {\r\n ensureNotFalsy,\r\n objectPathMonad,\r\n ObjectPathMonadFunction\r\n} from './plugins/utils/index.ts';\r\nimport {\r\n INDEX_MAX,\r\n INDEX_MIN\r\n} from './query-planner.ts';\r\nimport {\r\n newRxError\r\n} from './rx-error.ts';\r\n\r\n\r\n/**\r\n * Prepare all relevant information\r\n * outside of the returned function\r\n * from getIndexableStringMonad()\r\n * to save performance when the returned\r\n * function is called many times.\r\n */\r\ntype IndexMetaField<RxDocType> = {\r\n fieldName: string;\r\n schemaPart: JsonSchema;\r\n /*\r\n * Only in number fields.\r\n */\r\n parsedLengths?: ParsedLengths;\r\n getValue: ObjectPathMonadFunction<RxDocType>;\r\n getIndexStringPart: (docData: RxDocumentData<RxDocType>) => string;\r\n};\r\n\r\nexport function getIndexMeta<RxDocType>(\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>,\r\n index: string[]\r\n): IndexMetaField<RxDocType>[] {\r\n const fieldNameProperties: IndexMetaField<RxDocType>[] = index.map(fieldName => {\r\n const schemaPart = getSchemaByObjectPath(\r\n schema,\r\n fieldName\r\n );\r\n if (!schemaPart) {\r\n throw newRxError('CI1', { fieldName });\r\n }\r\n const type = schemaPart.type;\r\n let parsedLengths: ParsedLengths | undefined;\r\n if (type === 'number' || type === 'integer') {\r\n parsedLengths = getStringLengthOfIndexNumber(\r\n schemaPart\r\n );\r\n }\r\n\r\n const getValue = objectPathMonad(fieldName);\r\n const maxLength = schemaPart.maxLength ? schemaPart.maxLength : 0;\r\n\r\n let getIndexStringPart: (docData: RxDocumentData<RxDocType>) => string;\r\n if (type === 'string') {\r\n getIndexStringPart = docData => {\r\n let fieldValue = getValue(docData);\r\n if (!fieldValue) {\r\n fieldValue = '';\r\n }\r\n return fieldValue.padEnd(maxLength, ' ');\r\n };\r\n } else if (type === 'boolean') {\r\n getIndexStringPart = docData => {\r\n const fieldValue = getValue(docData);\r\n return fieldValue ? '1' : '0';\r\n };\r\n } else { // number\r\n /**\r\n * @performance\r\n * Inline the number index string generation to avoid\r\n * function call overhead and redundant boundary checks.\r\n * Document data in the hot path is assumed to be valid.\r\n */\r\n const pLengths = parsedLengths as ParsedLengths;\r\n const pMin = pLengths.minimum;\r\n const pMax = pLengths.maximum;\r\n const pRoundedMin = pLengths.roundedMinimum;\r\n const pNonDecimals = pLengths.nonDecimals;\r\n const pDecimals = pLengths.decimals;\r\n const pMultiplier = pLengths.multiplier;\r\n if (pDecimals === 0) {\r\n getIndexStringPart = docData => {\r\n let fieldValue = getValue(docData);\r\n if (typeof fieldValue === 'undefined') {\r\n fieldValue = 0;\r\n }\r\n if (fieldValue < pMin) {\r\n fieldValue = pMin;\r\n }\r\n if (fieldValue > pMax) {\r\n fieldValue = pMax;\r\n }\r\n return (Math.floor(fieldValue) - pRoundedMin).toString().padStart(pNonDecimals, '0');\r\n };\r\n } else {\r\n getIndexStringPart = docData => {\r\n let fieldValue = getValue(docData);\r\n if (typeof fieldValue === 'undefined') {\r\n fieldValue = 0;\r\n }\r\n if (fieldValue < pMin) {\r\n fieldValue = pMin;\r\n }\r\n if (fieldValue > pMax) {\r\n fieldValue = pMax;\r\n }\r\n const flooredValue = Math.floor(fieldValue);\r\n const shifted = Math.min(\r\n Math.round((fieldValue - flooredValue) * pMultiplier),\r\n pMultiplier - 1\r\n );\r\n const str = (flooredValue - pRoundedMin).toString().padStart(pNonDecimals, '0');\r\n return str + shifted.toString().padStart(pDecimals, '0');\r\n };\r\n }\r\n }\r\n\r\n const ret: IndexMetaField<RxDocType> = {\r\n fieldName,\r\n schemaPart,\r\n parsedLengths,\r\n getValue,\r\n getIndexStringPart\r\n };\r\n return ret;\r\n });\r\n return fieldNameProperties;\r\n}\r\n\r\n\r\n/**\r\n * Crafts an indexable string that can be used\r\n * to check if a document would be sorted below or above\r\n * another documents, dependent on the index values.\r\n * @monad for better performance\r\n *\r\n * IMPORTANT: Performance is really important here\r\n * which is why we code so 'strange'.\r\n * Always run performance tests when you want to\r\n * change something in this method.\r\n */\r\nexport function getIndexableStringMonad<RxDocType>(\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>,\r\n index: string[]\r\n): (docData: RxDocumentData<RxDocType>) => string {\r\n const fieldNameProperties = getIndexMeta(schema, index);\r\n const fieldNamePropertiesAmount = fieldNameProperties.length;\r\n const indexPartsFunctions = fieldNameProperties.map(r => r.getIndexStringPart);\r\n\r\n /**\r\n * @hotPath Performance of this function is very critical!\r\n * Specialize for common field counts to avoid loop overhead.\r\n */\r\n if (fieldNamePropertiesAmount === 1) {\r\n return indexPartsFunctions[0];\r\n }\r\n if (fieldNamePropertiesAmount === 2) {\r\n const fn0 = indexPartsFunctions[0];\r\n const fn1 = indexPartsFunctions[1];\r\n return (docData: RxDocumentData<RxDocType>): string => fn0(docData) + fn1(docData);\r\n }\r\n if (fieldNamePropertiesAmount === 3) {\r\n const fn0 = indexPartsFunctions[0];\r\n const fn1 = indexPartsFunctions[1];\r\n const fn2 = indexPartsFunctions[2];\r\n return (docData: RxDocumentData<RxDocType>): string => fn0(docData) + fn1(docData) + fn2(docData);\r\n }\r\n\r\n const ret = function (docData: RxDocumentData<RxDocType>): string {\r\n let str = '';\r\n for (let i = 0; i < fieldNamePropertiesAmount; ++i) {\r\n str += indexPartsFunctions[i](docData);\r\n }\r\n return str;\r\n };\r\n return ret;\r\n}\r\n\r\n\r\ndeclare type ParsedLengths = {\r\n minimum: number;\r\n maximum: number;\r\n nonDecimals: number;\r\n decimals: number;\r\n roundedMinimum: number;\r\n /**\r\n * Pre-computed Math.pow(10, decimals) to avoid\r\n * recomputing on every getNumberIndexString call.\r\n */\r\n multiplier: number;\r\n};\r\nexport function getStringLengthOfIndexNumber(\r\n schemaPart: JsonSchema\r\n): ParsedLengths {\r\n const minimum = Math.floor(schemaPart.minimum as number);\r\n const maximum = Math.ceil(schemaPart.maximum as number);\r\n const multipleOf: number = schemaPart.multipleOf as number;\r\n\r\n const valueSpan = maximum - minimum;\r\n const nonDecimals = valueSpan.toString().length;\r\n\r\n const multipleOfParts = multipleOf.toString().split('.');\r\n let decimals = 0;\r\n if (multipleOfParts.length > 1) {\r\n decimals = multipleOfParts[1].length;\r\n }\r\n return {\r\n minimum,\r\n maximum,\r\n nonDecimals,\r\n decimals,\r\n roundedMinimum: minimum,\r\n multiplier: Math.pow(10, decimals)\r\n };\r\n}\r\n\r\nexport function getIndexStringLength<RxDocType>(\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>,\r\n index: string[]\r\n): number {\r\n const fieldNameProperties = getIndexMeta(schema, index);\r\n let length = 0;\r\n fieldNameProperties.forEach(props => {\r\n const schemaPart = props.schemaPart;\r\n const type = schemaPart.type;\r\n\r\n if (type === 'string') {\r\n length += schemaPart.maxLength as number;\r\n } else if (type === 'boolean') {\r\n length += 1;\r\n } else {\r\n const parsedLengths = props.parsedLengths as ParsedLengths;\r\n length = length + parsedLengths.nonDecimals + parsedLengths.decimals;\r\n }\r\n\r\n });\r\n return length;\r\n}\r\n\r\n\r\nexport function getPrimaryKeyFromIndexableString(\r\n indexableString: string,\r\n primaryKeyLength: number\r\n): string {\r\n const paddedPrimaryKey = indexableString.slice(primaryKeyLength * -1);\r\n // we can safely trim here because the primary key is not allowed to start or end with a space char.\r\n const primaryKey = paddedPrimaryKey.trim();\r\n return primaryKey;\r\n}\r\n\r\n\r\nexport function getNumberIndexString(\r\n parsedLengths: ParsedLengths,\r\n fieldValue: number\r\n): string {\r\n /**\r\n * Ensure that the given value is in the boundaries\r\n * of the schema, otherwise it would create a broken index string.\r\n * This can happen for example if you have a minimum of 0\r\n * and run a query like\r\n * selector {\r\n * numField: { $gt: -1000 }\r\n * }\r\n */\r\n if (typeof fieldValue === 'undefined') {\r\n fieldValue = 0;\r\n }\r\n if (fieldValue < parsedLengths.minimum) {\r\n fieldValue = parsedLengths.minimum;\r\n }\r\n if (fieldValue > parsedLengths.maximum) {\r\n fieldValue = parsedLengths.maximum;\r\n }\r\n\r\n const nonDecimalsValueAsString = (Math.floor(fieldValue) - parsedLengths.roundedMinimum).toString();\r\n let str = nonDecimalsValueAsString.padStart(parsedLengths.nonDecimals, '0');\r\n\r\n if (parsedLengths.decimals > 0) {\r\n /**\r\n * @performance\r\n * Use math to extract decimal digits instead of toString().split('.')\r\n * which creates intermediate strings and arrays.\r\n * multiplier is pre-computed in ParsedLengths to avoid Math.pow() per call.\r\n */\r\n const multiplier = parsedLengths.multiplier;\r\n const shifted = Math.min(\r\n Math.round((fieldValue - Math.floor(fieldValue)) * multiplier),\r\n multiplier - 1\r\n );\r\n const decimalPart = shifted.toString();\r\n str += decimalPart.padStart(parsedLengths.decimals, '0');\r\n }\r\n return str;\r\n}\r\n\r\nexport function getStartIndexStringFromLowerBound(\r\n schema: RxJsonSchema<any>,\r\n index: string[],\r\n lowerBound: (string | boolean | number | null | undefined)[]\r\n): string {\r\n let str = '';\r\n index.forEach((fieldName, idx) => {\r\n const schemaPart = getSchemaByObjectPath(\r\n schema,\r\n fieldName\r\n );\r\n const bound = lowerBound[idx];\r\n const type = schemaPart.type;\r\n\r\n switch (type) {\r\n case 'string':\r\n const maxLength = ensureNotFalsy(schemaPart.maxLength, 'maxLength not set');\r\n if (typeof bound === 'string') {\r\n str += (bound as string).padEnd(maxLength, ' ');\r\n } else {\r\n // str += ''.padStart(maxLength, inclusiveStart ? ' ' : INDEX_MAX);\r\n str += ''.padEnd(maxLength, ' ');\r\n }\r\n break;\r\n case 'boolean':\r\n if (bound === null) {\r\n str += '0';\r\n } else if (bound === INDEX_MIN) {\r\n str += '0';\r\n } else if (bound === INDEX_MAX) {\r\n str += '1';\r\n } else {\r\n const boolToStr = bound ? '1' : '0';\r\n str += boolToStr;\r\n }\r\n break;\r\n case 'number':\r\n case 'integer':\r\n const parsedLengths = getStringLengthOfIndexNumber(\r\n schemaPart\r\n );\r\n if (bound === null || bound === INDEX_MIN) {\r\n const fillChar = '0';\r\n str += fillChar.repeat(parsedLengths.nonDecimals + parsedLengths.decimals);\r\n } else if (bound === INDEX_MAX) {\r\n str += getNumberIndexString(\r\n parsedLengths,\r\n parsedLengths.maximum\r\n );\r\n } else {\r\n const add = getNumberIndexString(\r\n parsedLengths,\r\n bound as number\r\n );\r\n str += add;\r\n }\r\n break;\r\n default:\r\n throw newRxError('CI2', { type: type as string });\r\n }\r\n });\r\n return str;\r\n}\r\n\r\n\r\nexport function getStartIndexStringFromUpperBound(\r\n schema: RxJsonSchema<any>,\r\n index: string[],\r\n upperBound: (string | boolean | number | null | undefined)[]\r\n): string {\r\n let str = '';\r\n index.forEach((fieldName, idx) => {\r\n const schemaPart = getSchemaByObjectPath(\r\n schema,\r\n fieldName\r\n );\r\n const bound = upperBound[idx];\r\n const type = schemaPart.type;\r\n\r\n switch (type) {\r\n case 'string':\r\n const maxLength = ensureNotFalsy(schemaPart.maxLength, 'maxLength not set');\r\n if (typeof bound === 'string' && bound !== INDEX_MAX) {\r\n str += (bound as string).padEnd(maxLength, ' ');\r\n } else if (bound === INDEX_MIN) {\r\n str += ''.padEnd(maxLength, ' ');\r\n } else {\r\n str += ''.padEnd(maxLength, INDEX_MAX);\r\n }\r\n break;\r\n case 'boolean':\r\n if (bound === null || bound === INDEX_MAX) {\r\n str += '1';\r\n } else if (bound === INDEX_MIN) {\r\n str += '0';\r\n } else {\r\n const boolToStr = bound ? '1' : '0';\r\n str += boolToStr;\r\n }\r\n break;\r\n case 'number':\r\n case 'integer':\r\n const parsedLengths = getStringLengthOfIndexNumber(\r\n schemaPart\r\n );\r\n if (bound === null || bound === INDEX_MAX) {\r\n const fillChar = '9';\r\n str += fillChar.repeat(parsedLengths.nonDecimals + parsedLengths.decimals);\r\n } else if (bound === INDEX_MIN) {\r\n const fillChar = '0';\r\n str += fillChar.repeat(parsedLengths.nonDecimals + parsedLengths.decimals);\r\n } else {\r\n str += getNumberIndexString(\r\n parsedLengths,\r\n bound as number\r\n );\r\n }\r\n break;\r\n default:\r\n throw newRxError('CI2', { type: type as string });\r\n }\r\n });\r\n return str;\r\n}\r\n\r\n/**\r\n * Used in storages where it is not possible\r\n * to define inclusiveEnd/inclusiveStart\r\n */\r\nexport function changeIndexableStringByOneQuantum(str: string, direction: 1 | -1): string {\r\n const lastChar = str.slice(-1);\r\n let charCode = lastChar.charCodeAt(0);\r\n charCode = charCode + direction;\r\n const withoutLastChar = str.slice(0, -1);\r\n return withoutLastChar + String.fromCharCode(charCode);\r\n}\r\n"],"mappings":";;;;;;;;;;;;;;AAWA,IAAAA,eAAA,GAAAC,OAAA;AAQA,IAAAC,MAAA,GAAAD,OAAA;AAKA,IAAAE,aAAA,GAAAF,OAAA;AAIA,IAAAG,QAAA,GAAAH,OAAA;AA5BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAwBA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYO,SAASI,YAAYA,CACxBC,MAA+C,EAC/CC,KAAe,EACY;EAC3B,IAAMC,mBAAgD,GAAGD,KAAK,CAACE,GAAG,CAACC,SAAS,IAAI;IAC5E,IAAMC,UAAU,GAAG,IAAAC,qCAAqB,EACpCN,MAAM,EACNI,SACJ,CAAC;IACD,IAAI,CAACC,UAAU,EAAE;MACb,MAAM,IAAAE,mBAAU,EAAC,KAAK,EAAE;QAAEH;MAAU,CAAC,CAAC;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AAQ,CAAC;QAC9E,CAAC,MAAM,IAAI4C,KAAK,KAAKE,uBAAS,EAAE;UAC5B,IAAMG,SAAQ,GAAG,GAAG;UACpBtC,GAAG,IAAIsC,SAAQ,CAACC,MAAM,CAACrE,aAAa,CAACiB,WAAW,GAAGjB,aAAa,CAACmB,QAAQ,CAAC;QAC9E,CAAC,MAAM;UACHW,GAAG,IAAI2B,oBAAoB,CACvBzD,aAAa,EACb+D,KACJ,CAAC;QACL;QACA;MACJ;QACI,MAAM,IAAAjE,mBAAU,EAAC,KAAK,EAAE;UAAEC,IAAI,EAAEA;QAAe,CAAC,CAAC;IACzD;EACJ,CAAC,CAAC;EACF,OAAO+B,GAAG;AACd;;AAEA;AACA;AACA;AACA;AACO,SAAS2C,iCAAiCA,CAAC3C,GAAW,EAAE4C,SAAiB,EAAU;EACtF,IAAMC,QAAQ,GAAG7C,GAAG,CAACwB,KAAK,CAAC,CAAC,CAAC,CAAC;EAC9B,IAAIsB,QAAQ,GAAGD,QAAQ,CAACE,UAAU,CAAC,CAAC,CAAC;EACrCD,QAAQ,GAAGA,QAAQ,GAAGF,SAAS;EAC/B,IAAMI,eAAe,GAAGhD,GAAG,CAACwB,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;EACxC,OAAOwB,eAAe,GAAGC,MAAM,CAACC,YAAY,CAACJ,QAAQ,CAAC;AAC1D","ignoreList":[]}
|
package/dist/cjs/doc-cache.js
CHANGED
|
@@ -52,7 +52,7 @@ var DocumentCache = exports.DocumentCache = /*#__PURE__*/function () {
|
|
|
52
52
|
var docId = docMeta.docId;
|
|
53
53
|
var cacheItem = this.cacheItemByDocId.get(docId);
|
|
54
54
|
if (cacheItem) {
|
|
55
|
-
cacheItem[0].delete(docMeta.
|
|
55
|
+
cacheItem[0].delete(docMeta.rev + docMeta.lwt);
|
|
56
56
|
if (cacheItem[0].size === 0) {
|
|
57
57
|
/**
|
|
58
58
|
* No state of the document is cached anymore,
|
|
@@ -92,8 +92,7 @@ var DocumentCache = exports.DocumentCache = /*#__PURE__*/function () {
|
|
|
92
92
|
if (this.tasks.size === 0) {
|
|
93
93
|
return;
|
|
94
94
|
}
|
|
95
|
-
|
|
96
|
-
tasks.forEach(task => task());
|
|
95
|
+
this.tasks.forEach(task => task());
|
|
97
96
|
this.tasks.clear();
|
|
98
97
|
}
|
|
99
98
|
|
|
@@ -128,11 +127,76 @@ var DocumentCache = exports.DocumentCache = /*#__PURE__*/function () {
|
|
|
128
127
|
}, {
|
|
129
128
|
key: "getCachedRxDocument",
|
|
130
129
|
get: function () {
|
|
131
|
-
var fn =
|
|
132
|
-
return (0, _index2.overwriteGetterForCaching)(this, 'getCachedRxDocument',
|
|
130
|
+
var fn = getCachedRxDocumentSingle(this);
|
|
131
|
+
return (0, _index2.overwriteGetterForCaching)(this, 'getCachedRxDocument', fn);
|
|
133
132
|
}
|
|
134
133
|
}]);
|
|
135
134
|
}();
|
|
135
|
+
/**
|
|
136
|
+
* @hotPath Dedicated single-document function that avoids array allocations.
|
|
137
|
+
* Used by getCachedRxDocument which is called from many call sites.
|
|
138
|
+
*/
|
|
139
|
+
function getCachedRxDocumentSingle(docCache) {
|
|
140
|
+
var primaryPath = docCache.primaryPath;
|
|
141
|
+
var cacheItemByDocId = docCache.cacheItemByDocId;
|
|
142
|
+
var registry = docCache.registry;
|
|
143
|
+
var deepFreezeWhenDevMode = _overwritable.overwritable.deepFreezeWhenDevMode;
|
|
144
|
+
var documentCreator = docCache.documentCreator;
|
|
145
|
+
return docData => {
|
|
146
|
+
var docId = docData[primaryPath];
|
|
147
|
+
var rev = docData._rev;
|
|
148
|
+
var lwt = docData._meta.lwt;
|
|
149
|
+
var cacheKey = rev + lwt;
|
|
150
|
+
var cacheItem = cacheItemByDocId.get(docId);
|
|
151
|
+
if (!cacheItem) {
|
|
152
|
+
docData = deepFreezeWhenDevMode(docData);
|
|
153
|
+
var newDoc = documentCreator(docData);
|
|
154
|
+
var newByRev = new Map();
|
|
155
|
+
newByRev.set(cacheKey, createWeakRefWithFallback(newDoc));
|
|
156
|
+
cacheItemByDocId.set(docId, [newByRev, docData]);
|
|
157
|
+
if (registry) {
|
|
158
|
+
docCache.tasks.add(() => {
|
|
159
|
+
registry.register(newDoc, {
|
|
160
|
+
docId: newDoc.primary,
|
|
161
|
+
rev,
|
|
162
|
+
lwt
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
if (docCache.tasks.size <= 1) {
|
|
166
|
+
(0, _index2.requestIdlePromiseNoQueue)().then(() => {
|
|
167
|
+
docCache.processTasks();
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return newDoc;
|
|
172
|
+
}
|
|
173
|
+
var byRev = cacheItem[0];
|
|
174
|
+
var cachedRxDocumentWeakRef = byRev.get(cacheKey);
|
|
175
|
+
var cachedRxDocument = cachedRxDocumentWeakRef ? cachedRxDocumentWeakRef.deref() : undefined;
|
|
176
|
+
if (!cachedRxDocument) {
|
|
177
|
+
docData = deepFreezeWhenDevMode(docData);
|
|
178
|
+
cachedRxDocument = documentCreator(docData);
|
|
179
|
+
byRev.set(cacheKey, createWeakRefWithFallback(cachedRxDocument));
|
|
180
|
+
if (registry) {
|
|
181
|
+
var registeredDoc = cachedRxDocument;
|
|
182
|
+
docCache.tasks.add(() => {
|
|
183
|
+
registry.register(registeredDoc, {
|
|
184
|
+
docId: registeredDoc.primary,
|
|
185
|
+
rev,
|
|
186
|
+
lwt
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
if (docCache.tasks.size <= 1) {
|
|
190
|
+
(0, _index2.requestIdlePromiseNoQueue)().then(() => {
|
|
191
|
+
docCache.processTasks();
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return cachedRxDocument;
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
136
200
|
/**
|
|
137
201
|
* This function is called very very often.
|
|
138
202
|
* @hotPath This is one of the most important methods for performance.
|
|
@@ -146,53 +210,71 @@ function getCachedRxDocumentMonad(docCache) {
|
|
|
146
210
|
var documentCreator = docCache.documentCreator;
|
|
147
211
|
var fn = docsData => {
|
|
148
212
|
var ret = new Array(docsData.length);
|
|
149
|
-
var registryTasks
|
|
213
|
+
var registryTasks;
|
|
150
214
|
for (var index = 0; index < docsData.length; index++) {
|
|
151
215
|
var docData = docsData[index];
|
|
152
216
|
var docId = docData[primaryPath];
|
|
153
|
-
var
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
* @performance
|
|
157
|
-
* Compute the byRev cache key once and reuse it
|
|
158
|
-
* for both the Map.get() and Map.set() calls.
|
|
159
|
-
*/
|
|
160
|
-
var cacheKey = revisionHeight + docData._meta.lwt + '';
|
|
161
|
-
var byRev = void 0;
|
|
162
|
-
var cachedRxDocumentWeakRef = void 0;
|
|
217
|
+
var rev = docData._rev;
|
|
218
|
+
var lwt = docData._meta.lwt;
|
|
219
|
+
var cacheKey = rev + lwt;
|
|
163
220
|
var cacheItem = cacheItemByDocId.get(docId);
|
|
164
221
|
if (!cacheItem) {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
byRev = cacheItem[0];
|
|
170
|
-
cachedRxDocumentWeakRef = byRev.get(cacheKey);
|
|
171
|
-
}
|
|
172
|
-
var cachedRxDocument = cachedRxDocumentWeakRef ? cachedRxDocumentWeakRef.deref() : undefined;
|
|
173
|
-
if (!cachedRxDocument) {
|
|
222
|
+
/**
|
|
223
|
+
* New document - no need for WeakRef lookup.
|
|
224
|
+
* Create cache item directly.
|
|
225
|
+
*/
|
|
174
226
|
docData = deepFreezeWhenDevMode(docData);
|
|
175
|
-
cachedRxDocument = documentCreator(docData);
|
|
227
|
+
var cachedRxDocument = documentCreator(docData);
|
|
228
|
+
var byRev = new Map();
|
|
176
229
|
byRev.set(cacheKey, createWeakRefWithFallback(cachedRxDocument));
|
|
230
|
+
cacheItemByDocId.set(docId, [byRev, docData]);
|
|
231
|
+
ret[index] = cachedRxDocument;
|
|
177
232
|
if (registry) {
|
|
178
|
-
registryTasks
|
|
233
|
+
if (!registryTasks) {
|
|
234
|
+
registryTasks = [];
|
|
235
|
+
}
|
|
236
|
+
registryTasks.push({
|
|
237
|
+
doc: cachedRxDocument,
|
|
238
|
+
rev,
|
|
239
|
+
lwt
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
} else {
|
|
243
|
+
var _byRev = cacheItem[0];
|
|
244
|
+
var cachedRxDocumentWeakRef = _byRev.get(cacheKey);
|
|
245
|
+
var _cachedRxDocument = cachedRxDocumentWeakRef ? cachedRxDocumentWeakRef.deref() : undefined;
|
|
246
|
+
if (!_cachedRxDocument) {
|
|
247
|
+
docData = deepFreezeWhenDevMode(docData);
|
|
248
|
+
_cachedRxDocument = documentCreator(docData);
|
|
249
|
+
_byRev.set(cacheKey, createWeakRefWithFallback(_cachedRxDocument));
|
|
250
|
+
if (registry) {
|
|
251
|
+
if (!registryTasks) {
|
|
252
|
+
registryTasks = [];
|
|
253
|
+
}
|
|
254
|
+
registryTasks.push({
|
|
255
|
+
doc: _cachedRxDocument,
|
|
256
|
+
rev,
|
|
257
|
+
lwt
|
|
258
|
+
});
|
|
259
|
+
}
|
|
179
260
|
}
|
|
261
|
+
ret[index] = _cachedRxDocument;
|
|
180
262
|
}
|
|
181
|
-
ret[index] = cachedRxDocument;
|
|
182
263
|
}
|
|
183
|
-
if (registryTasks
|
|
264
|
+
if (registryTasks && registry) {
|
|
184
265
|
/**
|
|
185
266
|
* Calling registry.register() has shown to have
|
|
186
267
|
* really bad performance. So we add the cached documents
|
|
187
268
|
* lazily.
|
|
188
269
|
*/
|
|
270
|
+
var tasks = registryTasks;
|
|
189
271
|
docCache.tasks.add(() => {
|
|
190
|
-
for (var _index = 0; _index <
|
|
191
|
-
var
|
|
192
|
-
registry.register(doc, {
|
|
193
|
-
docId: doc.primary,
|
|
194
|
-
|
|
195
|
-
lwt:
|
|
272
|
+
for (var _index = 0; _index < tasks.length; _index++) {
|
|
273
|
+
var task = tasks[_index];
|
|
274
|
+
registry.register(task.doc, {
|
|
275
|
+
docId: task.doc.primary,
|
|
276
|
+
rev: task.rev,
|
|
277
|
+
lwt: task.lwt
|
|
196
278
|
});
|
|
197
279
|
}
|
|
198
280
|
});
|