@connecttomahdi/rxdb 17.0.0-beta.17 → 17.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +10 -17
- 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 +1 -19
- 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 +11 -18
- 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 +1 -19
- 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/index.d.ts +25 -26
- 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/eslint.config.mjs +2 -1
- package/package.json +732 -729
- package/scripts/check-code-block-line-length.js +91 -0
- package/scripts/check-em-dashes.js +53 -0
- package/scripts/docs-fetch-git-history.mjs +36 -0
- 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/dist/esm/package.json +0 -1
- package/dist/types/types/conflict-handling.d.ts +0 -48
- package/dist/types/types/couchdb.d.ts +0 -293
- package/dist/types/types/index.d.ts +0 -32
- package/dist/types/types/modules/index.d.ts +0 -0
- package/dist/types/types/modules/mocha.parallel.d.ts +0 -1
- package/dist/types/types/plugins/backup.d.ts +0 -35
- package/dist/types/types/plugins/cleanup.d.ts +0 -38
- package/dist/types/types/plugins/crdt.d.ts +0 -76
- package/dist/types/types/plugins/dexie.d.ts +0 -30
- package/dist/types/types/plugins/local-documents.d.ts +0 -49
- package/dist/types/types/plugins/migration.d.ts +0 -14
- package/dist/types/types/plugins/reactivity.d.ts +0 -40
- package/dist/types/types/plugins/replication-graphql.d.ts +0 -98
- package/dist/types/types/plugins/replication.d.ts +0 -175
- package/dist/types/types/plugins/state.d.ts +0 -4
- package/dist/types/types/plugins/update.d.ts +0 -23
- package/dist/types/types/plugins/webmcp.d.ts +0 -40
- package/dist/types/types/query-planner.d.ts +0 -47
- package/dist/types/types/replication-protocol.d.ts +0 -296
- package/dist/types/types/rx-attachment.d.ts +0 -46
- package/dist/types/types/rx-change-event.d.ts +0 -85
- package/dist/types/types/rx-collection.d.ts +0 -117
- package/dist/types/types/rx-database-internal-store.d.ts +0 -54
- package/dist/types/types/rx-database.d.ts +0 -124
- package/dist/types/types/rx-document.d.ts +0 -160
- package/dist/types/types/rx-error.d.ts +0 -222
- package/dist/types/types/rx-plugin.d.ts +0 -167
- package/dist/types/types/rx-query.d.ts +0 -144
- package/dist/types/types/rx-schema.d.ts +0 -209
- package/dist/types/types/rx-storage.d.ts +0 -347
- package/dist/types/types/rx-storage.interface.d.ts +0 -312
- package/dist/types/types/util.d.ts +0 -180
|
@@ -230,7 +230,7 @@ export function fillWithDefaultSettings(schemaObj) {
|
|
|
230
230
|
|
|
231
231
|
// make indexes unique
|
|
232
232
|
var hasIndex = new Set();
|
|
233
|
-
useIndexes.filter(index => {
|
|
233
|
+
schemaObj.indexes = useIndexes.filter(index => {
|
|
234
234
|
var indexStr = index.join(',');
|
|
235
235
|
if (hasIndex.has(indexStr)) {
|
|
236
236
|
return false;
|
|
@@ -239,7 +239,6 @@ export function fillWithDefaultSettings(schemaObj) {
|
|
|
239
239
|
return true;
|
|
240
240
|
}
|
|
241
241
|
});
|
|
242
|
-
schemaObj.indexes = useIndexes;
|
|
243
242
|
return schemaObj;
|
|
244
243
|
}
|
|
245
244
|
export var META_LWT_UNIX_TIME_MAX = 1000000000000000;
|
|
@@ -295,7 +294,14 @@ export function fillObjectWithDefaults(rxSchema, obj) {
|
|
|
295
294
|
for (var i = 0; i < defaultKeys.length; ++i) {
|
|
296
295
|
var key = defaultKeys[i];
|
|
297
296
|
if (obj[key] === undefined) {
|
|
298
|
-
|
|
297
|
+
var val = rxSchema.defaultValues[key];
|
|
298
|
+
if (typeof val === 'object' && val !== null) {
|
|
299
|
+
obj[key] = Array.isArray(val) ? val.slice() : {
|
|
300
|
+
...val
|
|
301
|
+
};
|
|
302
|
+
} else {
|
|
303
|
+
obj[key] = val;
|
|
304
|
+
}
|
|
299
305
|
}
|
|
300
306
|
}
|
|
301
307
|
return obj;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rx-schema-helper.js","names":["newRxError","ensureNotFalsy","flatClone","getProperty","isMaybeReadonlyArray","REGEX_ALL_DOTS","RX_META_LWT_MINIMUM","sortObject","trimDots","getPseudoSchemaForVersion","version","primaryKey","pseudoSchema","fillWithDefaultSettings","type","properties","maxLength","value","indexes","required","SCHEMA_PATH_CACHE","WeakMap","getSchemaByObjectPath","rxJsonSchema","path","pathCache","get","pathStr","cached","Map","set","usePath","replace","ret","fillPrimaryKey","primaryPath","jsonSchema","documentData","newPrimary","getComposedPrimaryKeyOfDocumentData","existingPrimary","args","schema","getPrimaryFieldOfPrimaryKey","key","getLengthOfPrimaryKey","schemaPart","compositePrimary","fields","map","field","join","separator","normalizeRxJsonSchema","normalizedSchema","getDefaultIndex","schemaObj","additionalProperties","Object","prototype","hasOwnProperty","call","keyCompression","slice","encrypted","_rev","minLength","_attachments","_deleted","_meta","RX_META_SCHEMA","push","filter","includes","elem","pos","arr","indexOf","useIndexes","index","arIndex","unshift","length","internalIndexes","idx","hasIndex","Set","indexStr","has","add","META_LWT_UNIX_TIME_MAX","lwt","minimum","maximum","multipleOf","getFinalFields","keys","final","forEach","fillObjectWithDefaults","rxSchema","obj","defaultKeys","defaultValues","i","undefined","DEFAULT_CHECKPOINT_SCHEMA","id"],"sources":["../../src/rx-schema-helper.ts"],"sourcesContent":["import { newRxError } from './rx-error.ts';\r\nimport type {\r\n CompositePrimaryKey,\r\n DeepReadonly,\r\n JsonSchema,\r\n PrimaryKey,\r\n RxDocumentData,\r\n RxJsonSchema,\r\n RxStorageDefaultCheckpoint,\r\n StringKeys\r\n} from './types/index.d.ts';\r\nimport {\r\n ensureNotFalsy,\r\n flatClone,\r\n getProperty,\r\n isMaybeReadonlyArray,\r\n REGEX_ALL_DOTS,\r\n RX_META_LWT_MINIMUM,\r\n sortObject,\r\n trimDots\r\n} from './plugins/utils/index.ts';\r\nimport type { RxSchema } from './rx-schema.ts';\r\n\r\n/**\r\n * Helper function to create a valid RxJsonSchema\r\n * with a given version.\r\n */\r\nexport function getPseudoSchemaForVersion<T = any>(\r\n version: number,\r\n primaryKey: StringKeys<T>\r\n): RxJsonSchema<RxDocumentData<T>> {\r\n const pseudoSchema: RxJsonSchema<RxDocumentData<T>> = fillWithDefaultSettings({\r\n version,\r\n type: 'object',\r\n primaryKey: primaryKey as any,\r\n properties: {\r\n [primaryKey]: {\r\n type: 'string',\r\n maxLength: 100\r\n },\r\n value: {\r\n type: 'string'\r\n }\r\n } as any,\r\n indexes: [\r\n [primaryKey]\r\n ],\r\n required: [primaryKey]\r\n });\r\n return pseudoSchema;\r\n}\r\n\r\n/**\r\n * Cache for getSchemaByObjectPath results.\r\n * Uses a WeakMap keyed by the schema object reference\r\n * so the cache is automatically cleaned up when schemas are garbage collected.\r\n */\r\nconst SCHEMA_PATH_CACHE = new WeakMap<object, Map<string, JsonSchema>>();\r\n\r\n/**\r\n * Returns the sub-schema for a given path.\r\n * Results are cached per schema reference and path\r\n * to avoid redundant string operations and property lookups.\r\n */\r\nexport function getSchemaByObjectPath<T = any>(\r\n rxJsonSchema: RxJsonSchema<T>,\r\n path: keyof T | string\r\n): JsonSchema {\r\n let pathCache = SCHEMA_PATH_CACHE.get(rxJsonSchema as any);\r\n const pathStr = path as string;\r\n if (pathCache) {\r\n const cached = pathCache.get(pathStr);\r\n if (cached) {\r\n return cached;\r\n }\r\n } else {\r\n pathCache = new Map();\r\n SCHEMA_PATH_CACHE.set(rxJsonSchema as any, pathCache);\r\n }\r\n\r\n let usePath: string = pathStr;\r\n usePath = usePath.replace(REGEX_ALL_DOTS, '.properties.');\r\n usePath = 'properties.' + usePath;\r\n usePath = trimDots(usePath);\r\n\r\n const ret = getProperty(rxJsonSchema, usePath);\r\n pathCache.set(pathStr, ret);\r\n return ret;\r\n}\r\n\r\nexport function fillPrimaryKey<T>(\r\n primaryPath: keyof T,\r\n jsonSchema: RxJsonSchema<T>,\r\n documentData: RxDocumentData<T>\r\n): RxDocumentData<T> {\r\n // optimization shortcut.\r\n if (typeof jsonSchema.primaryKey === 'string') {\r\n return documentData;\r\n }\r\n\r\n const newPrimary = getComposedPrimaryKeyOfDocumentData<T>(\r\n jsonSchema,\r\n documentData\r\n );\r\n const existingPrimary: string | undefined = documentData[primaryPath] as any;\r\n if (\r\n existingPrimary &&\r\n existingPrimary !== newPrimary\r\n ) {\r\n throw newRxError(\r\n 'DOC19',\r\n {\r\n args: {\r\n documentData,\r\n existingPrimary,\r\n newPrimary,\r\n },\r\n schema: jsonSchema\r\n });\r\n }\r\n\r\n (documentData as any)[primaryPath] = newPrimary;\r\n return documentData;\r\n}\r\n\r\nexport function getPrimaryFieldOfPrimaryKey<RxDocType>(\r\n primaryKey: PrimaryKey<RxDocType>\r\n): StringKeys<RxDocType> {\r\n if (typeof primaryKey === 'string') {\r\n return primaryKey as any;\r\n } else {\r\n return (primaryKey as CompositePrimaryKey<RxDocType>).key;\r\n }\r\n}\r\n\r\nexport function getLengthOfPrimaryKey<RxDocType>(\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>\r\n): number {\r\n const primaryPath = getPrimaryFieldOfPrimaryKey(schema.primaryKey);\r\n const schemaPart = getSchemaByObjectPath(schema, primaryPath);\r\n return ensureNotFalsy(schemaPart.maxLength);\r\n}\r\n\r\n/**\r\n * Returns the composed primaryKey of a document by its data.\r\n */\r\nexport function getComposedPrimaryKeyOfDocumentData<RxDocType>(\r\n jsonSchema: RxJsonSchema<RxDocType> | RxJsonSchema<RxDocumentData<RxDocType>>,\r\n documentData: Partial<RxDocType>\r\n): string {\r\n if (typeof jsonSchema.primaryKey === 'string') {\r\n return (documentData as any)[jsonSchema.primaryKey];\r\n }\r\n\r\n const compositePrimary: CompositePrimaryKey<RxDocType> = jsonSchema.primaryKey as any;\r\n return compositePrimary.fields.map(field => {\r\n const value = getProperty(documentData as any, field as string);\r\n if (typeof value === 'undefined') {\r\n throw newRxError('DOC18', { args: { field, documentData } });\r\n }\r\n return value;\r\n }).join(compositePrimary.separator);\r\n}\r\n\r\n\r\n/**\r\n * Normalize the RxJsonSchema.\r\n * We need this to ensure everything is set up properly\r\n * and we have the same hash on schemas that represent the same value but\r\n * have different json.\r\n *\r\n * - Orders the schemas attributes by alphabetical order\r\n * - Adds the primaryKey to all indexes that do not contain the primaryKey\r\n * - We need this for deterministic sort order on all queries, which is required for event-reduce to work.\r\n *\r\n * @return RxJsonSchema - ordered and filled\r\n */\r\nexport function normalizeRxJsonSchema<T>(jsonSchema: RxJsonSchema<T>): RxJsonSchema<T> {\r\n const normalizedSchema: RxJsonSchema<T> = sortObject(jsonSchema, true);\r\n return normalizedSchema;\r\n}\r\n\r\n/**\r\n * If the schema does not specify any index,\r\n * we add this index so we at least can run RxQuery()\r\n * and only select non-deleted fields.\r\n */\r\nexport function getDefaultIndex(primaryPath: string) {\r\n return ['_deleted', primaryPath];\r\n}\r\n\r\n/**\r\n * fills the schema-json with default-settings\r\n * @return cloned schemaObj\r\n */\r\nexport function fillWithDefaultSettings<T = any>(\r\n schemaObj: RxJsonSchema<T>\r\n): RxJsonSchema<RxDocumentData<T>> {\r\n schemaObj = flatClone(schemaObj);\r\n const primaryPath: string = getPrimaryFieldOfPrimaryKey(schemaObj.primaryKey);\r\n schemaObj.properties = flatClone(schemaObj.properties);\r\n\r\n // additionalProperties is always false\r\n schemaObj.additionalProperties = false;\r\n\r\n // fill with key-compression-state ()\r\n if (!Object.prototype.hasOwnProperty.call(schemaObj, 'keyCompression')) {\r\n schemaObj.keyCompression = false;\r\n }\r\n\r\n // indexes must be array\r\n schemaObj.indexes = schemaObj.indexes ? schemaObj.indexes.slice(0) : [];\r\n\r\n // required must be array\r\n schemaObj.required = schemaObj.required ? schemaObj.required.slice(0) : [];\r\n\r\n // encrypted must be array\r\n schemaObj.encrypted = schemaObj.encrypted ? schemaObj.encrypted.slice(0) : [];\r\n\r\n // add _rev\r\n (schemaObj.properties as any)._rev = {\r\n type: 'string',\r\n minLength: 1\r\n };\r\n\r\n // add attachments\r\n (schemaObj.properties as any)._attachments = {\r\n type: 'object'\r\n };\r\n\r\n // add deleted flag\r\n (schemaObj.properties as any)._deleted = {\r\n type: 'boolean'\r\n };\r\n\r\n // add meta property\r\n (schemaObj.properties as any)._meta = RX_META_SCHEMA;\r\n\r\n /**\r\n * meta fields are all required\r\n */\r\n schemaObj.required = schemaObj.required ? schemaObj.required.slice(0) : [];\r\n (schemaObj.required as string[]).push('_deleted');\r\n (schemaObj.required as string[]).push('_rev');\r\n (schemaObj.required as string[]).push('_meta');\r\n (schemaObj.required as string[]).push('_attachments');\r\n\r\n // primaryKey is always required\r\n (schemaObj.required as any).push(primaryPath);\r\n\r\n schemaObj.required = schemaObj.required\r\n .filter((field: string) => !field.includes('.'))\r\n .filter((elem: any, pos: any, arr: any) => arr.indexOf(elem) === pos); // unique;\r\n\r\n\r\n // version is 0 by default\r\n schemaObj.version = schemaObj.version || 0;\r\n\r\n const useIndexes: string[][] = schemaObj.indexes.map(index => {\r\n const arIndex = isMaybeReadonlyArray(index) ? index.slice(0) : [index];\r\n /**\r\n * Append primary key to indexes that do not contain the primaryKey.\r\n * All indexes must have the primaryKey to ensure a deterministic sort order.\r\n */\r\n if (!arIndex.includes(primaryPath)) {\r\n arIndex.push(primaryPath);\r\n }\r\n\r\n // add _deleted flag to all indexes so we can query only non-deleted fields\r\n // in RxDB itself\r\n if (arIndex[0] !== '_deleted') {\r\n arIndex.unshift('_deleted');\r\n }\r\n\r\n return arIndex;\r\n });\r\n\r\n if (useIndexes.length === 0) {\r\n useIndexes.push(getDefaultIndex(primaryPath));\r\n }\r\n\r\n // we need this index for the getChangedDocumentsSince() method\r\n useIndexes.push(['_meta.lwt', primaryPath]);\r\n\r\n // also add the internalIndexes\r\n if (schemaObj.internalIndexes) {\r\n schemaObj.internalIndexes.map(idx => {\r\n useIndexes.push(idx);\r\n });\r\n }\r\n\r\n // make indexes unique\r\n const hasIndex = new Set<string>();\r\n useIndexes.filter(index => {\r\n const indexStr = index.join(',');\r\n if (hasIndex.has(indexStr)) {\r\n return false;\r\n } else {\r\n hasIndex.add(indexStr);\r\n return true;\r\n }\r\n });\r\n\r\n schemaObj.indexes = useIndexes;\r\n\r\n return schemaObj as any;\r\n}\r\n\r\nexport const META_LWT_UNIX_TIME_MAX = 1000000000000000;\r\nexport const RX_META_SCHEMA: JsonSchema = {\r\n type: 'object',\r\n properties: {\r\n /**\r\n * The last-write time.\r\n * Unix time in milliseconds.\r\n */\r\n lwt: {\r\n type: 'number',\r\n /**\r\n * We use 1 as minimum so that the value is never falsy.\r\n */\r\n minimum: RX_META_LWT_MINIMUM,\r\n maximum: META_LWT_UNIX_TIME_MAX,\r\n multipleOf: 0.01\r\n }\r\n },\r\n /**\r\n * Additional properties are allowed\r\n * and can be used by plugins to set various flags.\r\n */\r\n additionalProperties: true as any,\r\n required: [\r\n 'lwt'\r\n ]\r\n};\r\n\r\n\r\n/**\r\n * returns the final-fields of the schema\r\n * @return field-names of the final-fields\r\n */\r\nexport function getFinalFields<T = any>(\r\n jsonSchema: RxJsonSchema<T>\r\n): string[] {\r\n const ret = Object.keys(jsonSchema.properties)\r\n .filter(key => (jsonSchema as any).properties[key].final);\r\n\r\n // primary is also final\r\n const primaryPath = getPrimaryFieldOfPrimaryKey(jsonSchema.primaryKey);\r\n ret.push(primaryPath);\r\n\r\n // fields of composite primary are final\r\n if (typeof jsonSchema.primaryKey !== 'string') {\r\n (jsonSchema.primaryKey as CompositePrimaryKey<T>).fields\r\n .forEach(field => ret.push(field as string));\r\n }\r\n\r\n return ret;\r\n}\r\n\r\n/**\r\n * fills all unset fields with default-values if set\r\n * @hotPath\r\n */\r\nexport function fillObjectWithDefaults(rxSchema: RxSchema<any>, obj: any): any {\r\n const defaultKeys = Object.keys(rxSchema.defaultValues);\r\n for (let i = 0; i < defaultKeys.length; ++i) {\r\n const key = defaultKeys[i];\r\n if (obj[key] === undefined) {\r\n obj[key] = rxSchema.defaultValues[key];\r\n }\r\n }\r\n return obj;\r\n}\r\n\r\nexport const DEFAULT_CHECKPOINT_SCHEMA: DeepReadonly<JsonSchema<RxStorageDefaultCheckpoint>> = {\r\n type: 'object',\r\n properties: {\r\n id: {\r\n type: 'string'\r\n },\r\n lwt: {\r\n type: 'number'\r\n }\r\n },\r\n required: [\r\n 'id',\r\n 'lwt'\r\n ],\r\n additionalProperties: false\r\n} as const;\r\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,eAAe;AAW1C,SACIC,cAAc,EACdC,SAAS,EACTC,WAAW,EACXC,oBAAoB,EACpBC,cAAc,EACdC,mBAAmB,EACnBC,UAAU,EACVC,QAAQ,QACL,0BAA0B;AAGjC;AACA;AACA;AACA;AACA,OAAO,SAASC,yBAAyBA,CACrCC,OAAe,EACfC,UAAyB,EACM;EAC/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jB,GAAG,CAACsC,IAAI,CAACrB,KAAe,CAAC,CAAC;EACpD;EAEA,OAAOjB,GAAG;AACd;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASkE,sBAAsBA,CAACC,QAAuB,EAAEC,GAAQ,EAAO;EAC3E,IAAMC,WAAW,GAAG5C,MAAM,CAACsC,IAAI,CAACI,QAAQ,CAACG,aAAa,CAAC;EACvD,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,WAAW,CAACpB,MAAM,EAAE,EAAEsB,CAAC,EAAE;IACzC,IAAM5D,GAAG,GAAG0D,WAAW,CAACE,CAAC,CAAC;IAC1B,IAAIH,GAAG,CAACzD,GAAG,CAAC,KAAK6D,SAAS,EAAE;MACxBJ,GAAG,CAACzD,GAAG,CAAC,GAAGwD,QAAQ,CAACG,aAAa,CAAC3D,GAAG,CAAC;IAC1C;EACJ;EACA,OAAOyD,GAAG;AACd;AAEA,OAAO,IAAMK,yBAA+E,GAAG;EAC3F5F,IAAI,EAAE,QAAQ;EACdC,UAAU,EAAE;IACR4F,EAAE,EAAE;MACA7F,IAAI,EAAE;IACV,CAAC;IACD6E,GAAG,EAAE;MACD7E,IAAI,EAAE;IACV;EACJ,CAAC;EACDK,QAAQ,EAAE,CACN,IAAI,EACJ,KAAK,CACR;EACDsC,oBAAoB,EAAE;AAC1B,CAAU","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"rx-schema-helper.js","names":["newRxError","ensureNotFalsy","flatClone","getProperty","isMaybeReadonlyArray","REGEX_ALL_DOTS","RX_META_LWT_MINIMUM","sortObject","trimDots","getPseudoSchemaForVersion","version","primaryKey","pseudoSchema","fillWithDefaultSettings","type","properties","maxLength","value","indexes","required","SCHEMA_PATH_CACHE","WeakMap","getSchemaByObjectPath","rxJsonSchema","path","pathCache","get","pathStr","cached","Map","set","usePath","replace","ret","fillPrimaryKey","primaryPath","jsonSchema","documentData","newPrimary","getComposedPrimaryKeyOfDocumentData","existingPrimary","args","schema","getPrimaryFieldOfPrimaryKey","key","getLengthOfPrimaryKey","schemaPart","compositePrimary","fields","map","field","join","separator","normalizeRxJsonSchema","normalizedSchema","getDefaultIndex","schemaObj","additionalProperties","Object","prototype","hasOwnProperty","call","keyCompression","slice","encrypted","_rev","minLength","_attachments","_deleted","_meta","RX_META_SCHEMA","push","filter","includes","elem","pos","arr","indexOf","useIndexes","index","arIndex","unshift","length","internalIndexes","idx","hasIndex","Set","indexStr","has","add","META_LWT_UNIX_TIME_MAX","lwt","minimum","maximum","multipleOf","getFinalFields","keys","final","forEach","fillObjectWithDefaults","rxSchema","obj","defaultKeys","defaultValues","i","undefined","val","Array","isArray","DEFAULT_CHECKPOINT_SCHEMA","id"],"sources":["../../src/rx-schema-helper.ts"],"sourcesContent":["import { newRxError } from './rx-error.ts';\r\nimport type {\r\n CompositePrimaryKey,\r\n DeepReadonly,\r\n JsonSchema,\r\n PrimaryKey,\r\n RxDocumentData,\r\n RxJsonSchema,\r\n RxStorageDefaultCheckpoint,\r\n StringKeys\r\n} from './types/index.d.ts';\r\nimport {\r\n ensureNotFalsy,\r\n flatClone,\r\n getProperty,\r\n isMaybeReadonlyArray,\r\n REGEX_ALL_DOTS,\r\n RX_META_LWT_MINIMUM,\r\n sortObject,\r\n trimDots\r\n} from './plugins/utils/index.ts';\r\nimport type { RxSchema } from './rx-schema.ts';\r\n\r\n/**\r\n * Helper function to create a valid RxJsonSchema\r\n * with a given version.\r\n */\r\nexport function getPseudoSchemaForVersion<T = any>(\r\n version: number,\r\n primaryKey: StringKeys<T>\r\n): RxJsonSchema<RxDocumentData<T>> {\r\n const pseudoSchema: RxJsonSchema<RxDocumentData<T>> = fillWithDefaultSettings({\r\n version,\r\n type: 'object',\r\n primaryKey: primaryKey as any,\r\n properties: {\r\n [primaryKey]: {\r\n type: 'string',\r\n maxLength: 100\r\n },\r\n value: {\r\n type: 'string'\r\n }\r\n } as any,\r\n indexes: [\r\n [primaryKey]\r\n ],\r\n required: [primaryKey]\r\n });\r\n return pseudoSchema;\r\n}\r\n\r\n/**\r\n * Cache for getSchemaByObjectPath results.\r\n * Uses a WeakMap keyed by the schema object reference\r\n * so the cache is automatically cleaned up when schemas are garbage collected.\r\n */\r\nconst SCHEMA_PATH_CACHE = new WeakMap<object, Map<string, JsonSchema>>();\r\n\r\n/**\r\n * Returns the sub-schema for a given path.\r\n * Results are cached per schema reference and path\r\n * to avoid redundant string operations and property lookups.\r\n */\r\nexport function getSchemaByObjectPath<T = any>(\r\n rxJsonSchema: RxJsonSchema<T>,\r\n path: keyof T | string\r\n): JsonSchema {\r\n let pathCache = SCHEMA_PATH_CACHE.get(rxJsonSchema as any);\r\n const pathStr = path as string;\r\n if (pathCache) {\r\n const cached = pathCache.get(pathStr);\r\n if (cached) {\r\n return cached;\r\n }\r\n } else {\r\n pathCache = new Map();\r\n SCHEMA_PATH_CACHE.set(rxJsonSchema as any, pathCache);\r\n }\r\n\r\n let usePath: string = pathStr;\r\n usePath = usePath.replace(REGEX_ALL_DOTS, '.properties.');\r\n usePath = 'properties.' + usePath;\r\n usePath = trimDots(usePath);\r\n\r\n const ret = getProperty(rxJsonSchema, usePath);\r\n pathCache.set(pathStr, ret);\r\n return ret;\r\n}\r\n\r\nexport function fillPrimaryKey<T>(\r\n primaryPath: keyof T,\r\n jsonSchema: RxJsonSchema<T>,\r\n documentData: RxDocumentData<T>\r\n): RxDocumentData<T> {\r\n // optimization shortcut.\r\n if (typeof jsonSchema.primaryKey === 'string') {\r\n return documentData;\r\n }\r\n\r\n const newPrimary = getComposedPrimaryKeyOfDocumentData<T>(\r\n jsonSchema,\r\n documentData\r\n );\r\n const existingPrimary: string | undefined = documentData[primaryPath] as any;\r\n if (\r\n existingPrimary &&\r\n existingPrimary !== newPrimary\r\n ) {\r\n throw newRxError(\r\n 'DOC19',\r\n {\r\n args: {\r\n documentData,\r\n existingPrimary,\r\n newPrimary,\r\n },\r\n schema: jsonSchema\r\n });\r\n }\r\n\r\n (documentData as any)[primaryPath] = newPrimary;\r\n return documentData;\r\n}\r\n\r\nexport function getPrimaryFieldOfPrimaryKey<RxDocType>(\r\n primaryKey: PrimaryKey<RxDocType>\r\n): StringKeys<RxDocType> {\r\n if (typeof primaryKey === 'string') {\r\n return primaryKey as any;\r\n } else {\r\n return (primaryKey as CompositePrimaryKey<RxDocType>).key;\r\n }\r\n}\r\n\r\nexport function getLengthOfPrimaryKey<RxDocType>(\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>\r\n): number {\r\n const primaryPath = getPrimaryFieldOfPrimaryKey(schema.primaryKey);\r\n const schemaPart = getSchemaByObjectPath(schema, primaryPath);\r\n return ensureNotFalsy(schemaPart.maxLength);\r\n}\r\n\r\n/**\r\n * Returns the composed primaryKey of a document by its data.\r\n */\r\nexport function getComposedPrimaryKeyOfDocumentData<RxDocType>(\r\n jsonSchema: RxJsonSchema<RxDocType> | RxJsonSchema<RxDocumentData<RxDocType>>,\r\n documentData: Partial<RxDocType>\r\n): string {\r\n if (typeof jsonSchema.primaryKey === 'string') {\r\n return (documentData as any)[jsonSchema.primaryKey];\r\n }\r\n\r\n const compositePrimary: CompositePrimaryKey<RxDocType> = jsonSchema.primaryKey as any;\r\n return compositePrimary.fields.map(field => {\r\n const value = getProperty(documentData as any, field as string);\r\n if (typeof value === 'undefined') {\r\n throw newRxError('DOC18', { args: { field, documentData } });\r\n }\r\n return value;\r\n }).join(compositePrimary.separator);\r\n}\r\n\r\n\r\n/**\r\n * Normalize the RxJsonSchema.\r\n * We need this to ensure everything is set up properly\r\n * and we have the same hash on schemas that represent the same value but\r\n * have different json.\r\n *\r\n * - Orders the schemas attributes by alphabetical order\r\n * - Adds the primaryKey to all indexes that do not contain the primaryKey\r\n * - We need this for deterministic sort order on all queries, which is required for event-reduce to work.\r\n *\r\n * @return RxJsonSchema - ordered and filled\r\n */\r\nexport function normalizeRxJsonSchema<T>(jsonSchema: RxJsonSchema<T>): RxJsonSchema<T> {\r\n const normalizedSchema: RxJsonSchema<T> = sortObject(jsonSchema, true);\r\n return normalizedSchema;\r\n}\r\n\r\n/**\r\n * If the schema does not specify any index,\r\n * we add this index so we at least can run RxQuery()\r\n * and only select non-deleted fields.\r\n */\r\nexport function getDefaultIndex(primaryPath: string) {\r\n return ['_deleted', primaryPath];\r\n}\r\n\r\n/**\r\n * fills the schema-json with default-settings\r\n * @return cloned schemaObj\r\n */\r\nexport function fillWithDefaultSettings<T = any>(\r\n schemaObj: RxJsonSchema<T>\r\n): RxJsonSchema<RxDocumentData<T>> {\r\n schemaObj = flatClone(schemaObj);\r\n const primaryPath: string = getPrimaryFieldOfPrimaryKey(schemaObj.primaryKey);\r\n schemaObj.properties = flatClone(schemaObj.properties);\r\n\r\n // additionalProperties is always false\r\n schemaObj.additionalProperties = false;\r\n\r\n // fill with key-compression-state ()\r\n if (!Object.prototype.hasOwnProperty.call(schemaObj, 'keyCompression')) {\r\n schemaObj.keyCompression = false;\r\n }\r\n\r\n // indexes must be array\r\n schemaObj.indexes = schemaObj.indexes ? schemaObj.indexes.slice(0) : [];\r\n\r\n // required must be array\r\n schemaObj.required = schemaObj.required ? schemaObj.required.slice(0) : [];\r\n\r\n // encrypted must be array\r\n schemaObj.encrypted = schemaObj.encrypted ? schemaObj.encrypted.slice(0) : [];\r\n\r\n // add _rev\r\n (schemaObj.properties as any)._rev = {\r\n type: 'string',\r\n minLength: 1\r\n };\r\n\r\n // add attachments\r\n (schemaObj.properties as any)._attachments = {\r\n type: 'object'\r\n };\r\n\r\n // add deleted flag\r\n (schemaObj.properties as any)._deleted = {\r\n type: 'boolean'\r\n };\r\n\r\n // add meta property\r\n (schemaObj.properties as any)._meta = RX_META_SCHEMA;\r\n\r\n /**\r\n * meta fields are all required\r\n */\r\n schemaObj.required = schemaObj.required ? schemaObj.required.slice(0) : [];\r\n (schemaObj.required as string[]).push('_deleted');\r\n (schemaObj.required as string[]).push('_rev');\r\n (schemaObj.required as string[]).push('_meta');\r\n (schemaObj.required as string[]).push('_attachments');\r\n\r\n // primaryKey is always required\r\n (schemaObj.required as any).push(primaryPath);\r\n\r\n schemaObj.required = schemaObj.required\r\n .filter((field: string) => !field.includes('.'))\r\n .filter((elem: any, pos: any, arr: any) => arr.indexOf(elem) === pos); // unique;\r\n\r\n\r\n // version is 0 by default\r\n schemaObj.version = schemaObj.version || 0;\r\n\r\n const useIndexes: string[][] = schemaObj.indexes.map(index => {\r\n const arIndex = isMaybeReadonlyArray(index) ? index.slice(0) : [index];\r\n /**\r\n * Append primary key to indexes that do not contain the primaryKey.\r\n * All indexes must have the primaryKey to ensure a deterministic sort order.\r\n */\r\n if (!arIndex.includes(primaryPath)) {\r\n arIndex.push(primaryPath);\r\n }\r\n\r\n // add _deleted flag to all indexes so we can query only non-deleted fields\r\n // in RxDB itself\r\n if (arIndex[0] !== '_deleted') {\r\n arIndex.unshift('_deleted');\r\n }\r\n\r\n return arIndex;\r\n });\r\n\r\n if (useIndexes.length === 0) {\r\n useIndexes.push(getDefaultIndex(primaryPath));\r\n }\r\n\r\n // we need this index for the getChangedDocumentsSince() method\r\n useIndexes.push(['_meta.lwt', primaryPath]);\r\n\r\n // also add the internalIndexes\r\n if (schemaObj.internalIndexes) {\r\n schemaObj.internalIndexes.map(idx => {\r\n useIndexes.push(idx);\r\n });\r\n }\r\n\r\n // make indexes unique\r\n const hasIndex = new Set<string>();\r\n schemaObj.indexes = useIndexes.filter(index => {\r\n const indexStr = index.join(',');\r\n if (hasIndex.has(indexStr)) {\r\n return false;\r\n } else {\r\n hasIndex.add(indexStr);\r\n return true;\r\n }\r\n });\r\n\r\n return schemaObj as any;\r\n}\r\n\r\nexport const META_LWT_UNIX_TIME_MAX = 1000000000000000;\r\nexport const RX_META_SCHEMA: JsonSchema = {\r\n type: 'object',\r\n properties: {\r\n /**\r\n * The last-write time.\r\n * Unix time in milliseconds.\r\n */\r\n lwt: {\r\n type: 'number',\r\n /**\r\n * We use 1 as minimum so that the value is never falsy.\r\n */\r\n minimum: RX_META_LWT_MINIMUM,\r\n maximum: META_LWT_UNIX_TIME_MAX,\r\n multipleOf: 0.01\r\n }\r\n },\r\n /**\r\n * Additional properties are allowed\r\n * and can be used by plugins to set various flags.\r\n */\r\n additionalProperties: true as any,\r\n required: [\r\n 'lwt'\r\n ]\r\n};\r\n\r\n\r\n/**\r\n * returns the final-fields of the schema\r\n * @return field-names of the final-fields\r\n */\r\nexport function getFinalFields<T = any>(\r\n jsonSchema: RxJsonSchema<T>\r\n): string[] {\r\n const ret = Object.keys(jsonSchema.properties)\r\n .filter(key => (jsonSchema as any).properties[key].final);\r\n\r\n // primary is also final\r\n const primaryPath = getPrimaryFieldOfPrimaryKey(jsonSchema.primaryKey);\r\n ret.push(primaryPath);\r\n\r\n // fields of composite primary are final\r\n if (typeof jsonSchema.primaryKey !== 'string') {\r\n (jsonSchema.primaryKey as CompositePrimaryKey<T>).fields\r\n .forEach(field => ret.push(field as string));\r\n }\r\n\r\n return ret;\r\n}\r\n\r\n/**\r\n * fills all unset fields with default-values if set\r\n * @hotPath\r\n */\r\nexport function fillObjectWithDefaults(rxSchema: RxSchema<any>, obj: any): any {\r\n const defaultKeys = Object.keys(rxSchema.defaultValues);\r\n for (let i = 0; i < defaultKeys.length; ++i) {\r\n const key = defaultKeys[i];\r\n if (obj[key] === undefined) {\r\n const val = rxSchema.defaultValues[key];\r\n if (typeof val === 'object' && val !== null) {\r\n obj[key] = Array.isArray(val) ? val.slice() : { ...val };\r\n } else {\r\n obj[key] = val;\r\n }\r\n }\r\n }\r\n return obj;\r\n}\r\n\r\nexport const DEFAULT_CHECKPOINT_SCHEMA: DeepReadonly<JsonSchema<RxStorageDefaultCheckpoint>> = {\r\n type: 'object',\r\n properties: {\r\n id: {\r\n type: 'string'\r\n },\r\n lwt: {\r\n type: 'number'\r\n }\r\n },\r\n required: [\r\n 'id',\r\n 'lwt'\r\n ],\r\n additionalProperties: false\r\n} as const;\r\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,eAAe;AAW1C,SACIC,cAAc,EACdC,SAAS,EACTC,WAA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K,CACR;EACDsC,oBAAoB,EAAE;AAC1B,CAAU","ignoreList":[]}
|
package/dist/esm/rx-schema.js
CHANGED
|
@@ -31,6 +31,7 @@ export var RxSchema = /*#__PURE__*/function () {
|
|
|
31
31
|
var jsonSchema = flatClone(this.jsonSchema);
|
|
32
32
|
jsonSchema.properties = flatClone(jsonSchema.properties);
|
|
33
33
|
delete jsonSchema.properties._deleted;
|
|
34
|
+
delete jsonSchema.properties._rev;
|
|
34
35
|
delete jsonSchema.properties._meta;
|
|
35
36
|
delete jsonSchema.properties._attachments;
|
|
36
37
|
if (jsonSchema.required) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rx-schema.js","names":["overwriteGetterForCaching","isMaybeReadonlyArray","deepEqual","newRxError","runPluginHooks","fillWithDefaultSettings","getComposedPrimaryKeyOfDocumentData","getFinalFields","getPrimaryFieldOfPrimaryKey","getSchemaByObjectPath","normalizeRxJsonSchema","overwritable","flatClone","RxSchema","jsonSchema","hashFunction","indexes","getIndexes","primaryPath","primaryKey","properties","maxLength","schema","finalFields","_proto","prototype","getJsonSchemaWithoutMeta","_deleted","_meta","_attachments","required","filter","r","startsWith","validateChange","dataBefore","dataAfter","forEach","fieldName","getDocumentPrototype","proto","pathProperties","Object","keys","key","fullPath","__defineGetter__","get","undefined","ret","defineProperty","get$","enumerable","configurable","get$$","populate","getPrimaryOfDocumentData","documentData","_createClass","version","values","entries","v","hasOwnProperty","call","k","default","JSON","stringify","map","index","getPreviousVersions","c","Array","fill","createRxSchema","runPreCreateHooks","useJsonSchema","deepFreezeWhenDevMode","isRxSchema","obj","toTypedRxJsonSchema"],"sources":["../../src/rx-schema.ts"],"sourcesContent":["import {\r\n overwriteGetterForCaching,\r\n isMaybeReadonlyArray,\r\n deepEqual\r\n} from './plugins/utils/index.ts';\r\nimport {\r\n newRxError,\r\n} from './rx-error.ts';\r\nimport {\r\n runPluginHooks\r\n} from './hooks.ts';\r\n\r\nimport type {\r\n DeepMutable,\r\n DeepReadonly,\r\n HashFunction,\r\n MaybeReadonly,\r\n RxDocument,\r\n RxDocumentData,\r\n RxJsonSchema,\r\n StringKeys\r\n} from './types/index.d.ts';\r\nimport {\r\n fillWithDefaultSettings,\r\n getComposedPrimaryKeyOfDocumentData,\r\n getFinalFields,\r\n getPrimaryFieldOfPrimaryKey,\r\n getSchemaByObjectPath,\r\n normalizeRxJsonSchema\r\n} from './rx-schema-helper.ts';\r\nimport { overwritable } from './overwritable.ts';\r\nimport { flatClone } from 'event-reduce-js';\r\n\r\nexport class RxSchema<RxDocType = any> {\r\n public indexes: MaybeReadonly<string[]>[];\r\n public readonly primaryPath: StringKeys<RxDocumentData<RxDocType>>;\r\n public finalFields: string[];\r\n\r\n constructor(\r\n public readonly jsonSchema: RxJsonSchema<RxDocumentData<RxDocType>>,\r\n public readonly hashFunction: HashFunction\r\n ) {\r\n this.indexes = getIndexes(this.jsonSchema);\r\n\r\n // primary is always required\r\n this.primaryPath = getPrimaryFieldOfPrimaryKey(this.jsonSchema.primaryKey);\r\n\r\n /**\r\n * Many people accidentally put in wrong schema state\r\n * without the dev-mode plugin, so we need this check here\r\n * even in non-dev-mode.\r\n */\r\n if (!jsonSchema.properties[this.primaryPath].maxLength) {\r\n throw newRxError('SC39', { schema: jsonSchema });\r\n }\r\n\r\n this.finalFields = getFinalFields(this.jsonSchema);\r\n }\r\n\r\n public get version(): number {\r\n return this.jsonSchema.version;\r\n }\r\n\r\n public get defaultValues(): { [P in keyof RxDocType]: RxDocType[P] } {\r\n const values = {} as { [P in keyof RxDocType]: RxDocType[P] };\r\n Object\r\n .entries(this.jsonSchema.properties)\r\n .filter(([, v]) => Object.prototype.hasOwnProperty.call(v, 'default'))\r\n .forEach(([k, v]) => (values as any)[k] = (v as any).default);\r\n return overwriteGetterForCaching(\r\n this,\r\n 'defaultValues',\r\n values\r\n );\r\n }\r\n\r\n public getJsonSchemaWithoutMeta(): RxJsonSchema<RxDocumentData<RxDocType>> {\r\n const jsonSchema: any = flatClone(this.jsonSchema);\r\n jsonSchema.properties = flatClone(jsonSchema.properties);\r\n delete jsonSchema.properties._deleted;\r\n delete jsonSchema.properties._meta;\r\n delete jsonSchema.properties._attachments;\r\n\r\n if (jsonSchema.required) {\r\n jsonSchema.required = jsonSchema.required.filter((r: string) => !r.startsWith('_'));\r\n }\r\n\r\n return jsonSchema as RxJsonSchema<RxDocumentData<RxDocType>>;\r\n }\r\n\r\n /**\r\n * @overrides itself on the first call\r\n */\r\n public get hash(): Promise<string> {\r\n return overwriteGetterForCaching(\r\n this,\r\n 'hash',\r\n this.hashFunction(JSON.stringify(this.jsonSchema))\r\n );\r\n }\r\n\r\n /**\r\n * checks if a given change on a document is allowed\r\n * Ensures that:\r\n * - final fields are not modified\r\n * @throws {Error} if not valid\r\n */\r\n validateChange(dataBefore: any, dataAfter: any): void {\r\n this.finalFields.forEach(fieldName => {\r\n if (!deepEqual(dataBefore[fieldName], dataAfter[fieldName])) {\r\n throw newRxError('DOC9', {\r\n dataBefore,\r\n dataAfter,\r\n fieldName,\r\n schema: this.jsonSchema\r\n });\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * creates the schema-based document-prototype,\r\n * see RxCollection.getDocumentPrototype()\r\n */\r\n public getDocumentPrototype(): any {\r\n const proto: any = {};\r\n\r\n /**\r\n * On the top level, we know all keys\r\n * and therefore do not have to create a new Proxy object\r\n * for each document. Instead we define the getter in the prototype once.\r\n */\r\n const pathProperties = getSchemaByObjectPath(\r\n this.jsonSchema,\r\n ''\r\n );\r\n Object.keys(pathProperties)\r\n .forEach(key => {\r\n const fullPath = key;\r\n\r\n // getter - value\r\n proto.__defineGetter__(\r\n key,\r\n function (this: RxDocument) {\r\n if (!this.get || typeof this.get !== 'function') {\r\n /**\r\n * When an object gets added to the state of a vuejs-component,\r\n * it happens that this getter is called with another scope.\r\n * To prevent errors, we have to return undefined in this case\r\n */\r\n return undefined;\r\n }\r\n const ret = this.get(fullPath);\r\n return ret;\r\n }\r\n );\r\n // getter - observable$\r\n Object.defineProperty(proto, key + '$', {\r\n get: function () {\r\n return this.get$(fullPath);\r\n },\r\n enumerable: false,\r\n configurable: false\r\n });\r\n // getter - reactivity$$\r\n Object.defineProperty(proto, key + '$$', {\r\n get: function () {\r\n return this.get$$(fullPath);\r\n },\r\n enumerable: false,\r\n configurable: false\r\n });\r\n // getter - populate_\r\n Object.defineProperty(proto, key + '_', {\r\n get: function () {\r\n return this.populate(fullPath);\r\n },\r\n enumerable: false,\r\n configurable: false\r\n });\r\n });\r\n\r\n overwriteGetterForCaching(\r\n this,\r\n 'getDocumentPrototype',\r\n () => proto\r\n );\r\n return proto;\r\n }\r\n\r\n\r\n getPrimaryOfDocumentData(\r\n documentData: Partial<RxDocType>\r\n ): string {\r\n return getComposedPrimaryKeyOfDocumentData(\r\n this.jsonSchema,\r\n documentData\r\n );\r\n }\r\n}\r\n\r\nexport function getIndexes<RxDocType = any>(\r\n jsonSchema: RxJsonSchema<RxDocType>\r\n): MaybeReadonly<string[]>[] {\r\n return (jsonSchema.indexes || []).map(index => isMaybeReadonlyArray(index) ? index : [index]);\r\n}\r\n\r\n/**\r\n * array with previous version-numbers\r\n */\r\nexport function getPreviousVersions(schema: RxJsonSchema<any>): number[] {\r\n const version = schema.version ? schema.version : 0;\r\n let c = 0;\r\n return new Array(version)\r\n .fill(0)\r\n .map(() => c++);\r\n}\r\n\r\nexport function createRxSchema<T>(\r\n jsonSchema: RxJsonSchema<T>,\r\n hashFunction: HashFunction,\r\n runPreCreateHooks = true\r\n): RxSchema<T> {\r\n if (runPreCreateHooks) {\r\n runPluginHooks('preCreateRxSchema', jsonSchema);\r\n }\r\n\r\n let useJsonSchema = fillWithDefaultSettings(jsonSchema);\r\n useJsonSchema = normalizeRxJsonSchema(useJsonSchema);\r\n overwritable.deepFreezeWhenDevMode(useJsonSchema);\r\n\r\n const schema = new RxSchema(useJsonSchema, hashFunction);\r\n runPluginHooks('createRxSchema', schema);\r\n return schema;\r\n}\r\n\r\nexport function isRxSchema(obj: any): boolean {\r\n return obj instanceof RxSchema;\r\n}\r\n\r\n/**\r\n * Used as helper function the generate the document type out of the schema via typescript.\r\n * @link https://github.com/pubkey/rxdb/discussions/3467\r\n */\r\nexport function toTypedRxJsonSchema<T extends DeepReadonly<RxJsonSchema<any>>>(schema: T): DeepMutable<T> {\r\n return schema as any;\r\n}\r\n"],"mappings":";AAAA,SACIA,yBAAyB,EACzBC,oBAAoB,EACpBC,SAAS,QACN,0BAA0B;AACjC,SACIC,UAAU,QACP,eAAe;AACtB,SACIC,cAAc,QACX,YAAY;AAYnB,SACIC,uBAAuB,EACvBC,mCAAmC,EACnCC,cAAc,EACdC,2BAA2B,EAC3BC,qBAAqB,EACrBC,qBAAqB,QAClB,uBAAuB;AAC9B,SAASC,YAAY,QAAQ,mBAAmB;AAChD,SAASC,SAAS,QAAQ,iBAAiB;AAE3C,WAAaC,QAAQ;EAKjB,SAAAA,SACoBC,UAAmD,EACnDC,YAA0B,EAC5C;IAAA,KAFkBD,UAAmD,GAAnDA,UAAmD;IAAA,KACnDC,YAA0B,GAA1BA,YAA0B;IAE1C,IAAI,CAACC,OAAO,GAAGC,UAAU,CAAC,IAAI,CAACH,UAAU,CAAC;;IAE1C;IACA,IAAI,CAACI,WAAW,GAAGV,2BAA2B,CAAC,IAAI,CAACM,UAAU,CAACK,UAAU,CAAC;;IAE1E;AACR;AACA;AACA;AACA;IACQ,IAAI,CAACL,UAAU,CAACM,UAAU,CAAC,IAAI,CAACF,WAAW,CAAC,CAACG,SAAS,EAAE;MACpD,MAAMlB,UAAU,CAAC,MAAM,EAAE;QAAEmB,MAAM,EAAER;MAAW,CAAC,CAAC;IACpD;IAEA,IAAI,CAACS,WAAW,GAAGhB,cAAc,CAAC,IAAI,CAACO,UAAU,CAAC;EACtD;EAAC,IAAAU,MAAA,GAAAX,QAAA,CAAAY,SAAA;EAAAD,MAAA,CAmBME,wBAAwB,GAA/B,SAAOA,wBAAwBA,CAAA,EAA4C;IACvE,IAAMZ,UAAe,GA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MAAM,CAACqC,OAAO,GAAG,CAAC;EACnD,IAAIa,CAAC,GAAG,CAAC;EACT,OAAO,IAAIC,KAAK,CAACd,OAAO,CAAC,CACpBe,IAAI,CAAC,CAAC,CAAC,CACPL,GAAG,CAAC,MAAMG,CAAC,EAAE,CAAC;AACvB;AAEA,OAAO,SAASG,cAAcA,CAC1B7D,UAA2B,EAC3BC,YAA0B,EAC1B6D,iBAAiB,GAAG,IAAI,EACb;EACX,IAAIA,iBAAiB,EAAE;IACnBxE,cAAc,CAAC,mBAAmB,EAAEU,UAAU,CAAC;EACnD;EAEA,IAAI+D,aAAa,GAAGxE,uBAAuB,CAACS,UAAU,CAAC;EACvD+D,aAAa,GAAGnE,qBAAqB,CAACmE,aAAa,CAAC;EACpDlE,YAAY,CAACmE,qBAAqB,CAACD,aAAa,CAAC;EAEjD,IAAMvD,MAAM,GAAG,IAAIT,QAAQ,CAACgE,aAAa,EAAE9D,YAAY,CAAC;EACxDX,cAAc,CAAC,gBAAgB,EAAEkB,MAAM,CAAC;EACxC,OAAOA,MAAM;AACjB;AAEA,OAAO,SAASyD,UAAUA,CAACC,GAAQ,EAAW;EAC1C,OAAOA,GAAG,YAAYnE,QAAQ;AAClC;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASoE,mBAAmBA,CAA4C3D,MAAS,EAAkB;EACtG,OAAOA,MAAM;AACjB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"rx-schema.js","names":["overwriteGetterForCaching","isMaybeReadonlyArray","deepEqual","newRxError","runPluginHooks","fillWithDefaultSettings","getComposedPrimaryKeyOfDocumentData","getFinalFields","getPrimaryFieldOfPrimaryKey","getSchemaByObjectPath","normalizeRxJsonSchema","overwritable","flatClone","RxSchema","jsonSchema","hashFunction","indexes","getIndexes","primaryPath","primaryKey","properties","maxLength","schema","finalFields","_proto","prototype","getJsonSchemaWithoutMeta","_deleted","_rev","_meta","_attachments","required","filter","r","startsWith","validateChange","dataBefore","dataAfter","forEach","fieldName","getDocumentPrototype","proto","pathProperties","Object","keys","key","fullPath","__defineGetter__","get","undefined","ret","defineProperty","get$","enumerable","configurable","get$$","populate","getPrimaryOfDocumentData","documentData","_createClass","version","values","entries","v","hasOwnProperty","call","k","default","JSON","stringify","map","index","getPreviousVersions","c","Array","fill","createRxSchema","runPreCreateHooks","useJsonSchema","deepFreezeWhenDevMode","isRxSchema","obj","toTypedRxJsonSchema"],"sources":["../../src/rx-schema.ts"],"sourcesContent":["import {\r\n overwriteGetterForCaching,\r\n isMaybeReadonlyArray,\r\n deepEqual\r\n} from './plugins/utils/index.ts';\r\nimport {\r\n newRxError,\r\n} from './rx-error.ts';\r\nimport {\r\n runPluginHooks\r\n} from './hooks.ts';\r\n\r\nimport type {\r\n DeepMutable,\r\n DeepReadonly,\r\n HashFunction,\r\n MaybeReadonly,\r\n RxDocument,\r\n RxDocumentData,\r\n RxJsonSchema,\r\n StringKeys\r\n} from './types/index.d.ts';\r\nimport {\r\n fillWithDefaultSettings,\r\n getComposedPrimaryKeyOfDocumentData,\r\n getFinalFields,\r\n getPrimaryFieldOfPrimaryKey,\r\n getSchemaByObjectPath,\r\n normalizeRxJsonSchema\r\n} from './rx-schema-helper.ts';\r\nimport { overwritable } from './overwritable.ts';\r\nimport { flatClone } from 'event-reduce-js';\r\n\r\nexport class RxSchema<RxDocType = any> {\r\n public indexes: MaybeReadonly<string[]>[];\r\n public readonly primaryPath: StringKeys<RxDocumentData<RxDocType>>;\r\n public finalFields: string[];\r\n\r\n constructor(\r\n public readonly jsonSchema: RxJsonSchema<RxDocumentData<RxDocType>>,\r\n public readonly hashFunction: HashFunction\r\n ) {\r\n this.indexes = getIndexes(this.jsonSchema);\r\n\r\n // primary is always required\r\n this.primaryPath = getPrimaryFieldOfPrimaryKey(this.jsonSchema.primaryKey);\r\n\r\n /**\r\n * Many people accidentally put in wrong schema state\r\n * without the dev-mode plugin, so we need this check here\r\n * even in non-dev-mode.\r\n */\r\n if (!jsonSchema.properties[this.primaryPath].maxLength) {\r\n throw newRxError('SC39', { schema: jsonSchema });\r\n }\r\n\r\n this.finalFields = getFinalFields(this.jsonSchema);\r\n }\r\n\r\n public get version(): number {\r\n return this.jsonSchema.version;\r\n }\r\n\r\n public get defaultValues(): { [P in keyof RxDocType]: RxDocType[P] } {\r\n const values = {} as { [P in keyof RxDocType]: RxDocType[P] };\r\n Object\r\n .entries(this.jsonSchema.properties)\r\n .filter(([, v]) => Object.prototype.hasOwnProperty.call(v, 'default'))\r\n .forEach(([k, v]) => (values as any)[k] = (v as any).default);\r\n return overwriteGetterForCaching(\r\n this,\r\n 'defaultValues',\r\n values\r\n );\r\n }\r\n\r\n public getJsonSchemaWithoutMeta(): RxJsonSchema<RxDocumentData<RxDocType>> {\r\n const jsonSchema: any = flatClone(this.jsonSchema);\r\n jsonSchema.properties = flatClone(jsonSchema.properties);\r\n delete jsonSchema.properties._deleted;\r\n delete jsonSchema.properties._rev;\r\n delete jsonSchema.properties._meta;\r\n delete jsonSchema.properties._attachments;\r\n\r\n if (jsonSchema.required) {\r\n jsonSchema.required = jsonSchema.required.filter((r: string) => !r.startsWith('_'));\r\n }\r\n\r\n return jsonSchema as RxJsonSchema<RxDocumentData<RxDocType>>;\r\n }\r\n\r\n /**\r\n * @overrides itself on the first call\r\n */\r\n public get hash(): Promise<string> {\r\n return overwriteGetterForCaching(\r\n this,\r\n 'hash',\r\n this.hashFunction(JSON.stringify(this.jsonSchema))\r\n );\r\n }\r\n\r\n /**\r\n * checks if a given change on a document is allowed\r\n * Ensures that:\r\n * - final fields are not modified\r\n * @throws {Error} if not valid\r\n */\r\n validateChange(dataBefore: any, dataAfter: any): void {\r\n this.finalFields.forEach(fieldName => {\r\n if (!deepEqual(dataBefore[fieldName], dataAfter[fieldName])) {\r\n throw newRxError('DOC9', {\r\n dataBefore,\r\n dataAfter,\r\n fieldName,\r\n schema: this.jsonSchema\r\n });\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * creates the schema-based document-prototype,\r\n * see RxCollection.getDocumentPrototype()\r\n */\r\n public getDocumentPrototype(): any {\r\n const proto: any = {};\r\n\r\n /**\r\n * On the top level, we know all keys\r\n * and therefore do not have to create a new Proxy object\r\n * for each document. Instead we define the getter in the prototype once.\r\n */\r\n const pathProperties = getSchemaByObjectPath(\r\n this.jsonSchema,\r\n ''\r\n );\r\n Object.keys(pathProperties)\r\n .forEach(key => {\r\n const fullPath = key;\r\n\r\n // getter - value\r\n proto.__defineGetter__(\r\n key,\r\n function (this: RxDocument) {\r\n if (!this.get || typeof this.get !== 'function') {\r\n /**\r\n * When an object gets added to the state of a vuejs-component,\r\n * it happens that this getter is called with another scope.\r\n * To prevent errors, we have to return undefined in this case\r\n */\r\n return undefined;\r\n }\r\n const ret = this.get(fullPath);\r\n return ret;\r\n }\r\n );\r\n // getter - observable$\r\n Object.defineProperty(proto, key + '$', {\r\n get: function () {\r\n return this.get$(fullPath);\r\n },\r\n enumerable: false,\r\n configurable: false\r\n });\r\n // getter - reactivity$$\r\n Object.defineProperty(proto, key + '$$', {\r\n get: function () {\r\n return this.get$$(fullPath);\r\n },\r\n enumerable: false,\r\n configurable: false\r\n });\r\n // getter - populate_\r\n Object.defineProperty(proto, key + '_', {\r\n get: function () {\r\n return this.populate(fullPath);\r\n },\r\n enumerable: false,\r\n configurable: false\r\n });\r\n });\r\n\r\n overwriteGetterForCaching(\r\n this,\r\n 'getDocumentPrototype',\r\n () => proto\r\n );\r\n return proto;\r\n }\r\n\r\n\r\n getPrimaryOfDocumentData(\r\n documentData: Partial<RxDocType>\r\n ): string {\r\n return getComposedPrimaryKeyOfDocumentData(\r\n this.jsonSchema,\r\n documentData\r\n );\r\n }\r\n}\r\n\r\nexport function getIndexes<RxDocType = any>(\r\n jsonSchema: RxJsonSchema<RxDocType>\r\n): MaybeReadonly<string[]>[] {\r\n return (jsonSchema.indexes || []).map(index => isMaybeReadonlyArray(index) ? index : [index]);\r\n}\r\n\r\n/**\r\n * array with previous version-numbers\r\n */\r\nexport function getPreviousVersions(schema: RxJsonSchema<any>): number[] {\r\n const version = schema.version ? schema.version : 0;\r\n let c = 0;\r\n return new Array(version)\r\n .fill(0)\r\n .map(() => c++);\r\n}\r\n\r\nexport function createRxSchema<T>(\r\n jsonSchema: RxJsonSchema<T>,\r\n hashFunction: HashFunction,\r\n runPreCreateHooks = true\r\n): RxSchema<T> {\r\n if (runPreCreateHooks) {\r\n runPluginHooks('preCreateRxSchema', jsonSchema);\r\n }\r\n\r\n let useJsonSchema = fillWithDefaultSettings(jsonSchema);\r\n useJsonSchema = normalizeRxJsonSchema(useJsonSchema);\r\n overwritable.deepFreezeWhenDevMode(useJsonSchema);\r\n\r\n const schema = new RxSchema(useJsonSchema, hashFunction);\r\n runPluginHooks('createRxSchema', schema);\r\n return schema;\r\n}\r\n\r\nexport function isRxSchema(obj: any): boolean {\r\n return obj instanceof RxSchema;\r\n}\r\n\r\n/**\r\n * Used as helper function the generate the document type out of the schema via typescript.\r\n * @link https://github.com/pubkey/rxdb/discussions/3467\r\n */\r\nexport function toTypedRxJsonSchema<T extends DeepReadonly<RxJsonSchema<any>>>(schema: T): DeepMutable<T> {\r\n return schema as any;\r\n}\r\n"],"mappings":";AAAA,SACIA,yBAAyB,EACzBC,oBAAoB,EACpBC,SAAS,QACN,0BAA0B;AACjC,SACIC,UAAU,QACP,eAAe;AACtB,SACIC,cAAc,QACX,YAAY;AAYnB,SACIC,uBAAuB,EACvBC,mCAAmC,EACnCC,cAAc,EACdC,2BAA2B,EAC3BC,qBAAqB,EACrBC,qBAAqB,QAClB,uBAAuB;AAC9B,SAASC,YAAY,QAAQ,mBAAmB;AAChD,SAASC,SAAS,QAAQ,iBAAiB;AAE3C,WAAaC,QAAQ;EAKjB,SAAAA,SACoBC,UAAmD,EACnDC,YAA0B,EAC5C;IAAA,KAFkBD,UAAmD,GAAnDA,UAAmD;IAAA,KACnDC,YAA0B,GAA1BA,YAA0B;IAE1C,IAAI,CAACC,OAAO,GAAGC,UAAU,CAAC,IAAI,CAACH,UAAU,CAAC;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,GAAQ,EAAW;EAC1C,OAAOA,GAAG,YAAYpE,QAAQ;AAClC;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAASqE,mBAAmBA,CAA4C5D,MAAS,EAAkB;EACtG,OAAOA,MAAM;AACjB","ignoreList":[]}
|
|
@@ -11,6 +11,35 @@ import { normalizeMangoQuery, prepareQuery } from "./rx-query-helper.js";
|
|
|
11
11
|
import { HOOKS, runPluginHooks } from "./hooks.js";
|
|
12
12
|
export var INTERNAL_STORAGE_NAME = '_rxdb_internal';
|
|
13
13
|
export var RX_DATABASE_LOCAL_DOCS_STORAGE_NAME = 'rxdatabase_storage_local';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Context string used by RxCollection.bulkInsert().
|
|
17
|
+
* Documents written with this context are already cloned
|
|
18
|
+
* by fillObjectDataBeforeInsert(), so the wrapped storage
|
|
19
|
+
* can safely mutate them in place instead of cloning again.
|
|
20
|
+
*/
|
|
21
|
+
export var RX_COLLECTION_BULK_INSERT_CONTEXT = 'rx-collection-bulk-insert';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Set of bulkWrite context strings whose documents
|
|
25
|
+
* are already cloned by the caller and can be safely
|
|
26
|
+
* mutated in place (skip flatClone in the insert path).
|
|
27
|
+
*
|
|
28
|
+
* Plugins can register additional contexts via
|
|
29
|
+
* registerMutableWriteContext().
|
|
30
|
+
*/
|
|
31
|
+
var MUTABLE_DOCUMENT_WRITE_CONTEXTS = new Set([RX_COLLECTION_BULK_INSERT_CONTEXT]);
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Register a bulkWrite context string as "mutable",
|
|
35
|
+
* meaning the caller guarantees that insert documents
|
|
36
|
+
* are already cloned and safe to mutate in place.
|
|
37
|
+
* This allows the wrapped storage to skip a redundant
|
|
38
|
+
* flatClone() call on the insert hot path.
|
|
39
|
+
*/
|
|
40
|
+
export function registerMutableWriteContext(context) {
|
|
41
|
+
MUTABLE_DOCUMENT_WRITE_CONTEXTS.add(context);
|
|
42
|
+
}
|
|
14
43
|
export async function getSingleDocument(storageInstance, documentId) {
|
|
15
44
|
var results = await storageInstance.findDocumentsById([documentId], false);
|
|
16
45
|
var doc = results[0];
|
|
@@ -137,7 +166,7 @@ onInsert, onUpdate) {
|
|
|
137
166
|
* @performance is really important in this loop!
|
|
138
167
|
*/
|
|
139
168
|
var rowAmount = bulkWriteRows.length;
|
|
140
|
-
var
|
|
169
|
+
for (var rowId = 0; rowId < rowAmount; rowId++) {
|
|
141
170
|
var writeRow = bulkWriteRows[rowId];
|
|
142
171
|
|
|
143
172
|
// use these variables to have less property accesses
|
|
@@ -150,15 +179,18 @@ onInsert, onUpdate) {
|
|
|
150
179
|
if (hasDocsInDb) {
|
|
151
180
|
documentInDb = docsInDb.get(docId);
|
|
152
181
|
}
|
|
153
|
-
var attachmentError;
|
|
182
|
+
var attachmentError = void 0;
|
|
154
183
|
if (!documentInDb) {
|
|
155
184
|
/**
|
|
156
185
|
* It is possible to insert already deleted documents,
|
|
157
186
|
* this can happen on replication.
|
|
158
187
|
*/
|
|
159
|
-
var insertedIsDeleted = documentDeleted ? true : false;
|
|
160
188
|
if (hasAttachments) {
|
|
161
|
-
|
|
189
|
+
var atts = document._attachments;
|
|
190
|
+
var attKeys = Object.keys(atts);
|
|
191
|
+
for (var a = 0; a < attKeys.length; a++) {
|
|
192
|
+
var attachmentId = attKeys[a];
|
|
193
|
+
var attachmentData = atts[attachmentId];
|
|
162
194
|
if (!attachmentData.data) {
|
|
163
195
|
attachmentError = {
|
|
164
196
|
documentId: docId,
|
|
@@ -177,27 +209,27 @@ onInsert, onUpdate) {
|
|
|
177
209
|
digest: attachmentData.digest
|
|
178
210
|
});
|
|
179
211
|
}
|
|
180
|
-
}
|
|
212
|
+
}
|
|
181
213
|
}
|
|
214
|
+
var insertedRow = void 0;
|
|
182
215
|
if (!attachmentError) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
} else {
|
|
189
|
-
bulkInsertDocs.push(writeRow);
|
|
190
|
-
if (onInsert) {
|
|
191
|
-
onInsert(document);
|
|
192
|
-
}
|
|
216
|
+
var row = hasAttachments ? stripAttachmentsDataFromRow(writeRow) : writeRow;
|
|
217
|
+
insertedRow = row;
|
|
218
|
+
bulkInsertDocs.push(row);
|
|
219
|
+
if (onInsert) {
|
|
220
|
+
onInsert(document);
|
|
193
221
|
}
|
|
194
|
-
newestRow =
|
|
222
|
+
newestRow = row;
|
|
195
223
|
}
|
|
196
|
-
if (!
|
|
224
|
+
if (!documentDeleted) {
|
|
225
|
+
var eventDocData = document;
|
|
226
|
+
if (hasAttachments) {
|
|
227
|
+
eventDocData = insertedRow ? insertedRow.document : stripAttachmentsDataFromDocument(document);
|
|
228
|
+
}
|
|
197
229
|
var event = {
|
|
198
230
|
documentId: docId,
|
|
199
231
|
operation: 'INSERT',
|
|
200
|
-
documentData:
|
|
232
|
+
documentData: eventDocData,
|
|
201
233
|
previousDocumentData: hasAttachments && previous ? stripAttachmentsDataFromDocument(previous) : previous
|
|
202
234
|
};
|
|
203
235
|
eventBulkEvents.push(event);
|
|
@@ -220,7 +252,7 @@ onInsert, onUpdate) {
|
|
|
220
252
|
context
|
|
221
253
|
};
|
|
222
254
|
errors.push(err);
|
|
223
|
-
|
|
255
|
+
continue;
|
|
224
256
|
}
|
|
225
257
|
|
|
226
258
|
// handle attachments data
|
|
@@ -232,86 +264,96 @@ onInsert, onUpdate) {
|
|
|
232
264
|
* Deleted documents must have cleared all their attachments.
|
|
233
265
|
*/
|
|
234
266
|
if (previous) {
|
|
235
|
-
|
|
267
|
+
var prevAtts = previous._attachments;
|
|
268
|
+
var prevAttKeys = Object.keys(prevAtts);
|
|
269
|
+
for (var _a = 0; _a < prevAttKeys.length; _a++) {
|
|
270
|
+
var _attachmentId = prevAttKeys[_a];
|
|
236
271
|
attachmentsRemove.push({
|
|
237
272
|
documentId: docId,
|
|
238
|
-
attachmentId,
|
|
239
|
-
digest:
|
|
273
|
+
attachmentId: _attachmentId,
|
|
274
|
+
digest: prevAtts[_attachmentId].digest
|
|
240
275
|
});
|
|
241
|
-
}
|
|
276
|
+
}
|
|
242
277
|
}
|
|
243
278
|
} else {
|
|
244
279
|
// first check for errors
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
280
|
+
var docAtts = document._attachments;
|
|
281
|
+
var docAttKeys = Object.keys(docAtts);
|
|
282
|
+
for (var _a2 = 0; _a2 < docAttKeys.length; _a2++) {
|
|
283
|
+
var _attachmentId2 = docAttKeys[_a2];
|
|
284
|
+
var _attachmentData = docAtts[_attachmentId2];
|
|
285
|
+
var previousAttachmentData = previous ? previous._attachments[_attachmentId2] : undefined;
|
|
286
|
+
if (!previousAttachmentData && !_attachmentData.data) {
|
|
248
287
|
attachmentError = {
|
|
249
288
|
documentId: docId,
|
|
250
289
|
documentInDb: documentInDb,
|
|
251
290
|
isError: true,
|
|
252
291
|
status: 510,
|
|
253
292
|
writeRow,
|
|
254
|
-
attachmentId,
|
|
293
|
+
attachmentId: _attachmentId2,
|
|
255
294
|
context
|
|
256
295
|
};
|
|
296
|
+
break;
|
|
257
297
|
}
|
|
258
|
-
|
|
259
|
-
});
|
|
298
|
+
}
|
|
260
299
|
if (!attachmentError) {
|
|
261
|
-
|
|
262
|
-
var
|
|
263
|
-
|
|
300
|
+
for (var _a3 = 0; _a3 < docAttKeys.length; _a3++) {
|
|
301
|
+
var _attachmentId3 = docAttKeys[_a3];
|
|
302
|
+
var _attachmentData2 = docAtts[_attachmentId3];
|
|
303
|
+
var _previousAttachmentData = previous ? previous._attachments[_attachmentId3] : undefined;
|
|
304
|
+
if (!_previousAttachmentData) {
|
|
264
305
|
attachmentsAdd.push({
|
|
265
306
|
documentId: docId,
|
|
266
|
-
attachmentId,
|
|
267
|
-
attachmentData:
|
|
268
|
-
digest:
|
|
307
|
+
attachmentId: _attachmentId3,
|
|
308
|
+
attachmentData: _attachmentData2,
|
|
309
|
+
digest: _attachmentData2.digest
|
|
269
310
|
});
|
|
270
311
|
} else {
|
|
271
|
-
var newDigest = updatedRow.document._attachments[
|
|
272
|
-
if (
|
|
312
|
+
var newDigest = updatedRow.document._attachments[_attachmentId3].digest;
|
|
313
|
+
if (_attachmentData2.data &&
|
|
273
314
|
/**
|
|
274
315
|
* Performance shortcut,
|
|
275
316
|
* do not update the attachment data if it did not change.
|
|
276
317
|
*/
|
|
277
|
-
|
|
318
|
+
_previousAttachmentData.digest !== newDigest) {
|
|
278
319
|
attachmentsUpdate.push({
|
|
279
320
|
documentId: docId,
|
|
280
|
-
attachmentId,
|
|
281
|
-
attachmentData:
|
|
282
|
-
digest:
|
|
321
|
+
attachmentId: _attachmentId3,
|
|
322
|
+
attachmentData: _attachmentData2,
|
|
323
|
+
digest: _attachmentData2.digest
|
|
283
324
|
});
|
|
284
325
|
}
|
|
285
326
|
}
|
|
286
|
-
}
|
|
327
|
+
}
|
|
287
328
|
}
|
|
288
329
|
}
|
|
289
330
|
}
|
|
290
331
|
if (attachmentError) {
|
|
291
332
|
errors.push(attachmentError);
|
|
292
333
|
} else {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
if (onUpdate) {
|
|
301
|
-
onUpdate(document);
|
|
302
|
-
}
|
|
334
|
+
/**
|
|
335
|
+
* updatedRow already has attachments stripped (line above),
|
|
336
|
+
* so push it directly without stripping again.
|
|
337
|
+
*/
|
|
338
|
+
bulkUpdateDocs.push(updatedRow);
|
|
339
|
+
if (onUpdate) {
|
|
340
|
+
onUpdate(document);
|
|
303
341
|
}
|
|
304
342
|
newestRow = updatedRow;
|
|
305
343
|
}
|
|
306
|
-
var eventDocumentData;
|
|
344
|
+
var eventDocumentData = void 0;
|
|
307
345
|
var previousEventDocumentData = null;
|
|
308
|
-
var operation;
|
|
346
|
+
var operation = void 0;
|
|
309
347
|
if (previousDeleted && !documentDeleted) {
|
|
310
348
|
operation = 'INSERT';
|
|
311
|
-
|
|
349
|
+
/**
|
|
350
|
+
* Reuse the already-stripped document from updatedRow
|
|
351
|
+
* instead of calling stripAttachmentsDataFromDocument() again.
|
|
352
|
+
*/
|
|
353
|
+
eventDocumentData = hasAttachments ? updatedRow.document : document;
|
|
312
354
|
} else if (previous && !previousDeleted && !documentDeleted) {
|
|
313
355
|
operation = 'UPDATE';
|
|
314
|
-
eventDocumentData = hasAttachments ?
|
|
356
|
+
eventDocumentData = hasAttachments ? updatedRow.document : document;
|
|
315
357
|
previousEventDocumentData = previous;
|
|
316
358
|
} else if (documentDeleted) {
|
|
317
359
|
operation = 'DELETE';
|
|
@@ -332,9 +374,6 @@ onInsert, onUpdate) {
|
|
|
332
374
|
};
|
|
333
375
|
eventBulkEvents.push(_event);
|
|
334
376
|
}
|
|
335
|
-
};
|
|
336
|
-
for (var rowId = 0; rowId < rowAmount; rowId++) {
|
|
337
|
-
if (_loop()) continue;
|
|
338
377
|
}
|
|
339
378
|
return {
|
|
340
379
|
bulkInsertDocs,
|
|
@@ -387,10 +426,13 @@ export function stripAttachmentsDataFromDocument(doc) {
|
|
|
387
426
|
return doc;
|
|
388
427
|
}
|
|
389
428
|
var useDoc = flatClone(doc);
|
|
390
|
-
|
|
391
|
-
Object.
|
|
392
|
-
|
|
393
|
-
|
|
429
|
+
var destAtts = {};
|
|
430
|
+
var attKeys = Object.keys(atts);
|
|
431
|
+
for (var i = 0; i < attKeys.length; i++) {
|
|
432
|
+
var attachmentId = attKeys[i];
|
|
433
|
+
destAtts[attachmentId] = attachmentWriteDataToNormalData(atts[attachmentId]);
|
|
434
|
+
}
|
|
435
|
+
useDoc._attachments = destAtts;
|
|
394
436
|
return useDoc;
|
|
395
437
|
}
|
|
396
438
|
|
|
@@ -401,9 +443,12 @@ export function stripAttachmentsDataFromDocument(doc) {
|
|
|
401
443
|
* during replication etc.
|
|
402
444
|
*/
|
|
403
445
|
export function flatCloneDocWithMeta(doc) {
|
|
404
|
-
return
|
|
405
|
-
|
|
406
|
-
|
|
446
|
+
return {
|
|
447
|
+
...doc,
|
|
448
|
+
_meta: {
|
|
449
|
+
...doc._meta
|
|
450
|
+
}
|
|
451
|
+
};
|
|
407
452
|
}
|
|
408
453
|
/**
|
|
409
454
|
* Wraps the normal storageInstance of a RxCollection
|
|
@@ -428,7 +473,6 @@ rxJsonSchema) {
|
|
|
428
473
|
options: storageInstance.options,
|
|
429
474
|
async bulkWrite(rows, context) {
|
|
430
475
|
var databaseToken = database.token;
|
|
431
|
-
var toStorageWriteRows = new Array(rows.length);
|
|
432
476
|
/**
|
|
433
477
|
* Use the same timestamp for all docs of this rows-set.
|
|
434
478
|
* This improves performance because calling Date.now() inside of the now() function
|
|
@@ -441,30 +485,68 @@ rxJsonSchema) {
|
|
|
441
485
|
* inside the hot loop.
|
|
442
486
|
*/
|
|
443
487
|
var firstRevision = '1-' + databaseToken;
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
488
|
+
/**
|
|
489
|
+
* Share a single _meta object for all insert rows in this batch.
|
|
490
|
+
* All inserts in the same bulkWrite share the same timestamp,
|
|
491
|
+
* so we avoid creating a new { lwt: time } object per row.
|
|
492
|
+
* This shared reference is safe because:
|
|
493
|
+
* - All documents in one batch receive identical metadata values.
|
|
494
|
+
* - When a document is later updated, flatCloneDocWithMeta() creates
|
|
495
|
+
* a new _meta object, so the shared reference is never mutated.
|
|
496
|
+
*/
|
|
497
|
+
var insertMeta = {
|
|
498
|
+
lwt: time
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* When the caller has already cloned the documents (registered
|
|
503
|
+
* via MUTABLE_DOCUMENT_WRITE_CONTEXTS), we can mutate them
|
|
504
|
+
* in place and reuse the input array, avoiding redundant
|
|
505
|
+
* flatClone() and wrapper-object allocations on every insert row.
|
|
506
|
+
*/
|
|
507
|
+
var isMutableContext = MUTABLE_DOCUMENT_WRITE_CONTEXTS.has(context);
|
|
508
|
+
var toStorageWriteRows;
|
|
509
|
+
if (isMutableContext) {
|
|
510
|
+
/**
|
|
511
|
+
* Fast path: documents are already cloned by the caller.
|
|
512
|
+
* Set _meta/_rev directly on the document and reuse the
|
|
513
|
+
* input rows array without allocating wrapper objects.
|
|
514
|
+
*/
|
|
515
|
+
for (var index = 0; index < rows.length; index++) {
|
|
516
|
+
var document = rows[index].document;
|
|
517
|
+
document._meta = insertMeta;
|
|
462
518
|
document._rev = firstRevision;
|
|
463
519
|
}
|
|
464
|
-
toStorageWriteRows
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
520
|
+
toStorageWriteRows = rows;
|
|
521
|
+
} else {
|
|
522
|
+
toStorageWriteRows = new Array(rows.length);
|
|
523
|
+
for (var _index = 0; _index < rows.length; _index++) {
|
|
524
|
+
var writeRow = rows[_index];
|
|
525
|
+
var previous = writeRow.previous;
|
|
526
|
+
var _document = void 0;
|
|
527
|
+
if (previous) {
|
|
528
|
+
_document = flatCloneDocWithMeta(writeRow.document);
|
|
529
|
+
_document._meta.lwt = time;
|
|
530
|
+
_document._rev = createRevision(databaseToken, previous);
|
|
531
|
+
} else {
|
|
532
|
+
/**
|
|
533
|
+
* Insert path: flatClone is required because the input document
|
|
534
|
+
* may be a direct reference to another storage's internal data
|
|
535
|
+
* (e.g., during migration, query results from the old storage are
|
|
536
|
+
* passed directly as insert rows to the new storage).
|
|
537
|
+
*
|
|
538
|
+
* Use a shared insertMeta object instead of allocating { lwt: time }
|
|
539
|
+
* per row, since all inserts in the same batch share the same timestamp.
|
|
540
|
+
*/
|
|
541
|
+
_document = flatClone(writeRow.document);
|
|
542
|
+
_document._meta = insertMeta;
|
|
543
|
+
_document._rev = firstRevision;
|
|
544
|
+
}
|
|
545
|
+
toStorageWriteRows[_index] = {
|
|
546
|
+
document: _document,
|
|
547
|
+
previous
|
|
548
|
+
};
|
|
549
|
+
}
|
|
468
550
|
}
|
|
469
551
|
if (HOOKS.preStorageWrite.length > 0) {
|
|
470
552
|
runPluginHooks('preStorageWrite', {
|
|
@@ -676,8 +758,8 @@ export function getWrittenDocumentsFromBulkWriteResponse(primaryPath, writeRows,
|
|
|
676
758
|
var error = response.error[index];
|
|
677
759
|
errorIds.add(error.documentId);
|
|
678
760
|
}
|
|
679
|
-
for (var
|
|
680
|
-
var doc = realWriteRows[
|
|
761
|
+
for (var _index2 = 0; _index2 < realWriteRows.length; _index2++) {
|
|
762
|
+
var doc = realWriteRows[_index2].document;
|
|
681
763
|
if (!errorIds.has(doc[primaryPath])) {
|
|
682
764
|
ret.push(stripAttachmentsDataFromDocument(doc));
|
|
683
765
|
}
|
|
@@ -685,9 +767,9 @@ export function getWrittenDocumentsFromBulkWriteResponse(primaryPath, writeRows,
|
|
|
685
767
|
} else {
|
|
686
768
|
// pre-set array size for better performance
|
|
687
769
|
ret.length = writeRows.length - response.error.length;
|
|
688
|
-
for (var
|
|
689
|
-
var _doc = realWriteRows[
|
|
690
|
-
ret[
|
|
770
|
+
for (var _index3 = 0; _index3 < realWriteRows.length; _index3++) {
|
|
771
|
+
var _doc = realWriteRows[_index3].document;
|
|
772
|
+
ret[_index3] = stripAttachmentsDataFromDocument(_doc);
|
|
691
773
|
}
|
|
692
774
|
}
|
|
693
775
|
return ret;
|