@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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["newRxError","clone","deepEqual","ensureNotFalsy","getProperty","now","objectPathMonad","setProperty","toArray","getQueryMatcher","META_LWT_UNIX_TIME_MAX","overwritable","mingoUpdater","updateCRDT","entry","deepFreezeWhenDevMode","jsonSchema","collection","schema","crdt","queryObj","crdtOptions","storageToken","database","incrementalModify","docData","crdtDocField","field","operation","body","creator","time","lastAr","operations","push","hash","hashCRDTOperations","hashFunction","runOperationOnDocument","RX_CRDT_CONTEXT","insertCRDT","Array","isArray","insertData","result","insert","catch","err","code","doc","findOne","parameters","id","exec","sortOperationComparator","a","b","entryParts","forEach","entryPart","isMatching","selector","query","sort","skip","matcher","ifMatch","ifNotMatch","crdts","hashObj","map","op","JSON","stringify","getCRDTSchemaPart","operationSchema","type","properties","items","additionalProperties","minItems","minimum","maximum","multipleOf","required","minLength","mergeCRDTFields","crdtsA","crdtsB","length","ret","row","index","mergedOps","ids","Set","add","has","rebuildFromCRDT","base","_deleted","getCRDTConflictHandler","crdtField","getCRDTValue","conflictHandler","isEqual","ctx","resolve","i","newDocCrdt","newDocumentState","masterDocCrdt","realMasterState","mergedCrdt","mergedDoc","RxDBcrdtPlugin","name","rxdb","prototypes","RxDocument","proto","oldRemove","remove","bind","$set","oldincrementalPatch","incrementalPatch","patch","oldincrementalModify","fn","context","primary","args","RxCollection","hooks","preCreateRxCollection","after","data","createRxCollection","getCrdt","isDevMode","bulkWriteBefore","storageInstance","bulkWrite","writes","Promise","all","write","newDocState","document","rebuild","docWithoutMeta","Object","entries","k","v","startsWith","recalculatedHash","bulkInsertBefore","bulkInsert","docsData","useDocsData","setMe","key","value","crdtOperations"],"sources":["../../../../src/plugins/crdt/index.ts"],"sourcesContent":["import { newRxError } from '../../rx-error.ts';\r\nimport type {\r\n CRDTDocumentField,\r\n CRDTEntry,\r\n CRDTOperation,\r\n FilledMangoQuery,\r\n HashFunction,\r\n JsonSchema,\r\n RxConflictHandler,\r\n RxConflictHandlerInput,\r\n RxDocument,\r\n RxDocumentData,\r\n RxJsonSchema,\r\n RxPlugin,\r\n WithDeleted\r\n} from '../../types/index.d.ts';\r\nimport {\r\n clone,\r\n deepEqual,\r\n ensureNotFalsy,\r\n getProperty,\r\n now,\r\n objectPathMonad,\r\n setProperty,\r\n toArray\r\n} from '../../plugins/utils/index.ts';\r\nimport {\r\n getQueryMatcher,\r\n META_LWT_UNIX_TIME_MAX,\r\n overwritable,\r\n RxCollection,\r\n RxDocumentWriteData,\r\n RxError\r\n} from '../../index.ts';\r\nimport { mingoUpdater } from '../update/mingo-updater.ts';\r\n\r\n\r\n\r\nexport async function updateCRDT<RxDocType>(\r\n this: RxDocument<RxDocType>,\r\n entry: CRDTEntry<RxDocType> | CRDTEntry<RxDocType>[]\r\n) {\r\n entry = overwritable.deepFreezeWhenDevMode(entry) as any;\r\n\r\n const jsonSchema = this.collection.schema.jsonSchema;\r\n if (!jsonSchema.crdt) {\r\n throw newRxError('CRDT1', {\r\n schema: jsonSchema,\r\n queryObj: entry\r\n });\r\n }\r\n const crdtOptions = ensureNotFalsy(jsonSchema.crdt);\r\n const storageToken = await this.collection.database.storageToken;\r\n\r\n return this.incrementalModify(async (docData) => {\r\n const crdtDocField: CRDTDocumentField<RxDocType> = clone(getProperty(docData as any, crdtOptions.field));\r\n const operation: CRDTOperation<RxDocType> = {\r\n body: toArray(entry),\r\n creator: storageToken,\r\n time: now()\r\n };\r\n\r\n /**\r\n * A new write will ALWAYS be an operation in the last\r\n * array which was non existing before.\r\n */\r\n const lastAr: CRDTOperation<RxDocType>[] = [operation];\r\n crdtDocField.operations.push(lastAr);\r\n crdtDocField.hash = await hashCRDTOperations(this.collection.database.hashFunction, crdtDocField);\r\n\r\n docData = runOperationOnDocument(\r\n this.collection.schema.jsonSchema,\r\n docData,\r\n operation\r\n );\r\n setProperty(docData, crdtOptions.field, crdtDocField);\r\n return docData;\r\n }, RX_CRDT_CONTEXT);\r\n}\r\n\r\n\r\nexport async function insertCRDT<RxDocType>(\r\n this: RxCollection<RxDocType>,\r\n entry: CRDTEntry<RxDocType> | CRDTEntry<RxDocType>[]\r\n) {\r\n entry = overwritable.deepFreezeWhenDevMode(entry) as any;\r\n\r\n const jsonSchema = this.schema.jsonSchema;\r\n if (!jsonSchema.crdt) {\r\n throw newRxError('CRDT1', {\r\n schema: jsonSchema,\r\n queryObj: entry\r\n });\r\n }\r\n const crdtOptions = ensureNotFalsy(jsonSchema.crdt);\r\n const storageToken = await this.database.storageToken;\r\n const operation: CRDTOperation<RxDocType> = {\r\n body: Array.isArray(entry) ? entry : [entry],\r\n creator: storageToken,\r\n time: now()\r\n };\r\n\r\n let insertData: RxDocumentWriteData<RxDocType> = {} as any;\r\n insertData = runOperationOnDocument(\r\n this.schema.jsonSchema,\r\n insertData as any,\r\n operation\r\n ) as any;\r\n const crdtDocField: CRDTDocumentField<RxDocType> = {\r\n operations: [],\r\n hash: ''\r\n };\r\n setProperty(insertData as any, crdtOptions.field, crdtDocField);\r\n\r\n const lastAr: CRDTOperation<RxDocType>[] = [operation];\r\n crdtDocField.operations.push(lastAr);\r\n crdtDocField.hash = await hashCRDTOperations(this.database.hashFunction, crdtDocField);\r\n\r\n const result = await this.insert(insertData).catch(async (err: RxError) => {\r\n if (err.code === 'CONFLICT') {\r\n // was a conflict, update document instead of inserting\r\n const doc = await this.findOne(err.parameters.id).exec(true);\r\n return doc.updateCRDT(entry);\r\n } else {\r\n throw err;\r\n }\r\n });\r\n return result;\r\n}\r\n\r\n\r\nexport function sortOperationComparator<RxDocType>(a: CRDTOperation<RxDocType>, b: CRDTOperation<RxDocType>) {\r\n return a.creator > b.creator ? 1 : -1;\r\n}\r\n\r\n\r\nfunction runOperationOnDocument<RxDocType>(\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>,\r\n docData: WithDeleted<RxDocType>,\r\n operation: CRDTOperation<RxDocType>\r\n): WithDeleted<RxDocType> {\r\n const entryParts = operation.body;\r\n entryParts.forEach(entryPart => {\r\n let isMatching: boolean;\r\n if (entryPart.selector) {\r\n const query: FilledMangoQuery<RxDocType> = {\r\n selector: ensureNotFalsy(entryPart.selector as any),\r\n sort: [],\r\n skip: 0\r\n };\r\n const matcher = getQueryMatcher(schema, query);\r\n isMatching = matcher(docData as any);\r\n } else {\r\n isMatching = true;\r\n }\r\n if (isMatching) {\r\n if (entryPart.ifMatch) {\r\n docData = mingoUpdater<WithDeleted<RxDocType>>(docData, entryPart.ifMatch);\r\n }\r\n } else {\r\n if (entryPart.ifNotMatch) {\r\n docData = mingoUpdater<WithDeleted<RxDocType>>(docData, entryPart.ifNotMatch);\r\n }\r\n }\r\n });\r\n return docData;\r\n}\r\n\r\nexport async function hashCRDTOperations(\r\n hashFunction: HashFunction,\r\n crdts: CRDTDocumentField<any>\r\n): Promise<string> {\r\n const hashObj = crdts.operations.map((operations) => {\r\n return operations.map(op => op.creator);\r\n });\r\n const hash = await hashFunction(JSON.stringify(hashObj));\r\n return hash;\r\n}\r\n\r\nexport function getCRDTSchemaPart<RxDocType>(): JsonSchema<CRDTDocumentField<RxDocType>> {\r\n const operationSchema: JsonSchema<CRDTOperation<RxDocType>> = {\r\n type: 'object',\r\n properties: {\r\n body: {\r\n type: 'array',\r\n items: {\r\n type: 'object',\r\n properties: {\r\n selector: {\r\n type: 'object'\r\n },\r\n ifMatch: {\r\n type: 'object'\r\n },\r\n ifNotMatch: {\r\n type: 'object'\r\n }\r\n },\r\n additionalProperties: false\r\n },\r\n minItems: 1\r\n },\r\n creator: {\r\n type: 'string'\r\n },\r\n time: {\r\n type: 'number',\r\n minimum: 1,\r\n maximum: META_LWT_UNIX_TIME_MAX,\r\n multipleOf: 0.01\r\n }\r\n },\r\n additionalProperties: false,\r\n required: [\r\n 'body',\r\n 'creator',\r\n 'time'\r\n ]\r\n };\r\n return {\r\n type: 'object',\r\n properties: {\r\n operations: {\r\n type: 'array',\r\n items: {\r\n type: 'array',\r\n items: operationSchema\r\n }\r\n },\r\n hash: {\r\n type: 'string',\r\n // set a minLength to not accidentally store an empty string\r\n minLength: 2\r\n }\r\n },\r\n additionalProperties: false,\r\n required: ['operations', 'hash']\r\n };\r\n}\r\n\r\n\r\nexport async function mergeCRDTFields<RxDocType>(\r\n hashFunction: HashFunction,\r\n crdtsA: CRDTDocumentField<RxDocType>,\r\n crdtsB: CRDTDocumentField<RxDocType>\r\n): Promise<CRDTDocumentField<RxDocType>> {\r\n\r\n // the value with most operations must be A to\r\n // ensure we not miss out rows when iterating over both fields.\r\n if (crdtsA.operations.length < crdtsB.operations.length) {\r\n [crdtsA, crdtsB] = [crdtsB, crdtsA];\r\n }\r\n\r\n const ret: CRDTDocumentField<RxDocType> = {\r\n operations: [],\r\n hash: ''\r\n };\r\n crdtsA.operations.forEach((row, index) => {\r\n let mergedOps: CRDTOperation<RxDocType>[] = [];\r\n const ids = new Set<string>(); // used to deduplicate\r\n\r\n row.forEach(op => {\r\n ids.add(op.creator);\r\n mergedOps.push(op);\r\n });\r\n if (crdtsB.operations[index]) {\r\n crdtsB.operations[index].forEach(op => {\r\n if (!ids.has(op.creator)) {\r\n mergedOps.push(op);\r\n }\r\n });\r\n }\r\n mergedOps = mergedOps.sort(sortOperationComparator);\r\n ret.operations[index] = mergedOps;\r\n });\r\n\r\n\r\n ret.hash = await hashCRDTOperations(hashFunction, ret);\r\n return ret;\r\n}\r\n\r\nexport function rebuildFromCRDT<RxDocType>(\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>,\r\n docData: WithDeleted<RxDocType> | RxDocType,\r\n crdts: CRDTDocumentField<RxDocType>\r\n): WithDeleted<RxDocType> {\r\n let base: WithDeleted<RxDocType> = {\r\n _deleted: false\r\n } as any;\r\n setProperty(base, ensureNotFalsy(schema.crdt).field, crdts);\r\n crdts.operations.forEach(operations => {\r\n operations.forEach(op => {\r\n base = runOperationOnDocument(\r\n schema,\r\n base,\r\n op\r\n );\r\n });\r\n });\r\n return base;\r\n}\r\n\r\n\r\nexport function getCRDTConflictHandler<RxDocType>(\r\n hashFunction: HashFunction,\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>\r\n): RxConflictHandler<RxDocType> {\r\n const crdtOptions = ensureNotFalsy(schema.crdt);\r\n const crdtField = crdtOptions.field;\r\n const getCRDTValue = objectPathMonad<WithDeleted<RxDocType> | RxDocType, CRDTDocumentField<RxDocType>>(crdtField);\r\n\r\n const conflictHandler: RxConflictHandler<RxDocType> = {\r\n isEqual(a, b, ctx) {\r\n return getCRDTValue(a).hash === getCRDTValue(b).hash;\r\n },\r\n async resolve(i) {\r\n const newDocCrdt = getCRDTValue(i.newDocumentState);\r\n const masterDocCrdt = getCRDTValue(i.realMasterState);\r\n const mergedCrdt = await mergeCRDTFields(hashFunction, newDocCrdt, masterDocCrdt);\r\n const mergedDoc = rebuildFromCRDT(\r\n schema,\r\n i.newDocumentState,\r\n mergedCrdt\r\n );\r\n return mergedDoc;\r\n }\r\n }\r\n return conflictHandler;\r\n}\r\n\r\n\r\nexport const RX_CRDT_CONTEXT = 'rx-crdt';\r\n\r\nexport const RxDBcrdtPlugin: RxPlugin = {\r\n name: 'crdt',\r\n rxdb: true,\r\n prototypes: {\r\n RxDocument: (proto: any) => {\r\n proto.updateCRDT = updateCRDT;\r\n\r\n const oldRemove = proto.remove;\r\n proto.remove = function (this: RxDocument) {\r\n if (!this.collection.schema.jsonSchema.crdt) {\r\n return oldRemove.bind(this)();\r\n }\r\n return this.updateCRDT({\r\n ifMatch: {\r\n $set: {\r\n _deleted: true\r\n }\r\n }\r\n });\r\n };\r\n\r\n const oldincrementalPatch = proto.incrementalPatch;\r\n proto.incrementalPatch = function (this: RxDocument, patch: any) {\r\n if (!this.collection.schema.jsonSchema.crdt) {\r\n return oldincrementalPatch.bind(this)(patch);\r\n }\r\n return this.updateCRDT({\r\n ifMatch: {\r\n $set: patch\r\n }\r\n });\r\n };\r\n const oldincrementalModify = proto.incrementalModify;\r\n proto.incrementalModify = function (fn: any, context: string) {\r\n if (!this.collection.schema.jsonSchema.crdt) {\r\n return oldincrementalModify.bind(this)(fn);\r\n }\r\n if (context === RX_CRDT_CONTEXT) {\r\n return oldincrementalModify.bind(this)(fn);\r\n } else {\r\n throw newRxError('CRDT2', {\r\n id: this.primary,\r\n args: { context }\r\n });\r\n }\r\n };\r\n },\r\n RxCollection: (proto: any) => {\r\n proto.insertCRDT = insertCRDT;\r\n }\r\n },\r\n overwritable: {},\r\n hooks: {\r\n preCreateRxCollection: {\r\n after: (data) => {\r\n if (!data.schema.crdt) {\r\n return;\r\n }\r\n if (data.conflictHandler) {\r\n throw newRxError('CRDT3', {\r\n collection: data.name,\r\n schema: data.schema\r\n });\r\n }\r\n data.conflictHandler = getCRDTConflictHandler(\r\n data.database.hashFunction,\r\n data.schema\r\n );\r\n }\r\n },\r\n createRxCollection: {\r\n after: ({ collection }) => {\r\n if (!collection.schema.jsonSchema.crdt) {\r\n return;\r\n }\r\n\r\n const crdtOptions = ensureNotFalsy(collection.schema.jsonSchema.crdt);\r\n const crdtField = crdtOptions.field;\r\n const getCrdt = objectPathMonad<any, CRDTDocumentField<any>>(crdtOptions.field);\r\n\r\n /**\r\n * In dev-mode we have to ensure that all document writes\r\n * have the correct crdt state so that nothing is missed out\r\n * or could accidentally do non-crdt writes to the document.\r\n */\r\n if (overwritable.isDevMode()) {\r\n const bulkWriteBefore = collection.storageInstance.bulkWrite.bind(collection.storageInstance);\r\n collection.storageInstance.bulkWrite = async function (writes, context) {\r\n\r\n await Promise.all(\r\n writes.map(async (write) => {\r\n const newDocState: typeof write.document = clone(write.document);\r\n const crdts = getCrdt(newDocState);\r\n\r\n const rebuild = rebuildFromCRDT(\r\n collection.schema.jsonSchema,\r\n newDocState,\r\n crdts\r\n );\r\n\r\n function docWithoutMeta(doc: any) {\r\n const ret: any = {};\r\n Object.entries(doc).forEach(([k, v]) => {\r\n if (\r\n !k.startsWith('_') &&\r\n typeof v !== 'undefined'\r\n ) {\r\n ret[k] = v;\r\n }\r\n });\r\n return ret;\r\n }\r\n if (!deepEqual(docWithoutMeta(newDocState), docWithoutMeta(rebuild))) {\r\n throw newRxError('SNH', {\r\n document: newDocState\r\n });\r\n }\r\n const recalculatedHash = await hashCRDTOperations(collection.database.hashFunction, crdts);\r\n if (crdts.hash !== recalculatedHash) {\r\n throw newRxError('SNH', {\r\n document: newDocState,\r\n args: { hash: crdts.hash, recalculatedHash }\r\n });\r\n }\r\n })\r\n );\r\n\r\n return bulkWriteBefore(writes, context);\r\n };\r\n }\r\n\r\n\r\n const bulkInsertBefore = collection.bulkInsert.bind(collection);\r\n collection.bulkInsert = async function (docsData: any[]) {\r\n const storageToken = await collection.database.storageToken;\r\n const useDocsData = await Promise.all(\r\n docsData.map(async (docData) => {\r\n const setMe: Partial<RxDocumentData<any>> = {};\r\n Object.entries(docData).forEach(([key, value]) => {\r\n if (\r\n !key.startsWith('_') &&\r\n key !== crdtField\r\n ) {\r\n setMe[key] = value;\r\n }\r\n });\r\n\r\n const crdtOperations: CRDTDocumentField<any> = {\r\n operations: [\r\n [{\r\n creator: storageToken,\r\n body: [{\r\n ifMatch: {\r\n $set: setMe\r\n }\r\n }],\r\n time: now()\r\n }]\r\n ],\r\n hash: ''\r\n };\r\n crdtOperations.hash = await hashCRDTOperations(collection.database.hashFunction, crdtOperations);\r\n setProperty(docData, crdtOptions.field, crdtOperations);\r\n return docData;\r\n })\r\n );\r\n return bulkInsertBefore(useDocsData);\r\n };\r\n }\r\n }\r\n }\r\n};\r\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,mBAAmB;AAgB9C,SACIC,KAAK,EACLC,SAAS,EACTC,cAAc,EACdC,WAAW,EACXC,GAAG,EACHC,eAAe,EACfC,WAAW,EACXC,OAAO,QACJ,8BAA8B;AACrC,SACIC,eAAe,EACfC,sBAAsB,EACtBC,YAAY,QAIT,gBAAgB;AACvB,SAASC,YAAY,QAAQ,4BAA4B;AAIzD,OAAO,eAAeC,UAAUA,CAE5BC,KAAoD,EACtD;EACEA,KAAK,GAAGH,YAAY,CAACI,qBAAqB,CAACD,KAAK,CAAQ;EAExD,IAAME,UAAU,GAAG,IAAI,CAACC,UAAU,CAACC,MAAM,CAACF,UAAU;EACpD,IAAI,CAACA,UAAU,CAACG,IAAI,EAAE;IAClB,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CAAC;kBACHqC,OAAO,EAAE;oBACL0D,IAAI,EAAEsC;kBACV;gBACJ,CAAC,CAAC;gBACFnI,IAAI,EAAE1B,GAAG,CAAC;cACd,CAAC,CAAC,CACL;cACD8B,IAAI,EAAE;YACV,CAAC;YACDkI,cAAc,CAAClI,IAAI,GAAG,MAAMC,kBAAkB,CAACnB,UAAU,CAACM,QAAQ,CAACc,YAAY,EAAEgI,cAAc,CAAC;YAChG9J,WAAW,CAACkB,OAAO,EAAEJ,WAAW,CAACM,KAAK,EAAE0I,cAAc,CAAC;YACvD,OAAO5I,OAAO;UAClB,CAAC,CACL,CAAC;UACD,OAAOqI,gBAAgB,CAACG,WAAW,CAAC;QACxC,CAAC;MACL;IACJ;EACJ;AACJ,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["newRxError","clone","deepEqual","ensureNotFalsy","getProperty","now","objectPathMonad","setProperty","toArray","getQueryMatcher","META_LWT_UNIX_TIME_MAX","overwritable","mingoUpdater","fillObjectWithDefaults","updateCRDT","entry","deepFreezeWhenDevMode","jsonSchema","collection","schema","crdt","queryObj","crdtOptions","storageToken","database","incrementalModify","docData","crdtDocField","field","operation","body","creator","time","lastAr","operations","push","hash","hashCRDTOperations","hashFunction","runOperationOnDocument","RX_CRDT_CONTEXT","insertCRDT","Array","isArray","insertData","result","insert","catch","err","code","doc","findOne","parameters","id","exec","sortOperationComparator","a","b","entryParts","forEach","entryPart","isMatching","selector","query","sort","skip","matcher","ifMatch","ifNotMatch","crdts","hashObj","map","op","JSON","stringify","getCRDTSchemaPart","operationSchema","type","properties","items","additionalProperties","minItems","minimum","maximum","multipleOf","required","minLength","mergeCRDTFields","crdtsA","crdtsB","length","ret","row","index","mergedOps","ids","Set","add","has","rebuildFromCRDT","base","_deleted","getCRDTConflictHandler","crdtField","getCRDTValue","conflictHandler","isEqual","ctx","resolve","i","newDocCrdt","newDocumentState","masterDocCrdt","realMasterState","mergedCrdt","mergedDoc","RxDBcrdtPlugin","name","rxdb","prototypes","RxDocument","proto","oldRemove","remove","bind","$set","oldincrementalRemove","incrementalRemove","call","oldModify","modify","fn","context","primary","args","method","oldPatch","patch","oldincrementalPatch","incrementalPatch","oldincrementalModify","oldUpdate","update","updateObj","RxCollection","hooks","preCreateRxCollection","after","data","createRxCollection","getCrdt","isDevMode","bulkWriteBefore","storageInstance","bulkWrite","writes","Promise","all","write","newDocState","document","rebuild","docWithoutMeta","Object","entries","k","v","startsWith","recalculatedHash","bulkInsertBefore","bulkInsert","docsData","useDocsData","setMe","key","value","crdtOperations"],"sources":["../../../../src/plugins/crdt/index.ts"],"sourcesContent":["import { newRxError } from '../../rx-error.ts';\r\nimport type {\r\n CRDTDocumentField,\r\n CRDTEntry,\r\n CRDTOperation,\r\n FilledMangoQuery,\r\n HashFunction,\r\n JsonSchema,\r\n RxConflictHandler,\r\n RxConflictHandlerInput,\r\n RxDocument,\r\n RxDocumentData,\r\n RxJsonSchema,\r\n RxPlugin,\r\n WithDeleted\r\n} from '../../types/index.d.ts';\r\nimport {\r\n clone,\r\n deepEqual,\r\n ensureNotFalsy,\r\n getProperty,\r\n now,\r\n objectPathMonad,\r\n setProperty,\r\n toArray\r\n} from '../../plugins/utils/index.ts';\r\nimport {\r\n getQueryMatcher,\r\n META_LWT_UNIX_TIME_MAX,\r\n overwritable,\r\n RxCollection,\r\n RxDocumentWriteData,\r\n RxError\r\n} from '../../index.ts';\r\nimport { mingoUpdater } from '../update/mingo-updater.ts';\r\nimport { fillObjectWithDefaults } from '../../rx-schema-helper.ts';\r\n\r\n\r\n\r\nexport async function updateCRDT<RxDocType>(\r\n this: RxDocument<RxDocType>,\r\n entry: CRDTEntry<RxDocType> | CRDTEntry<RxDocType>[]\r\n) {\r\n entry = overwritable.deepFreezeWhenDevMode(entry) as any;\r\n\r\n const jsonSchema = this.collection.schema.jsonSchema;\r\n if (!jsonSchema.crdt) {\r\n throw newRxError('CRDT1', {\r\n schema: jsonSchema,\r\n queryObj: entry\r\n });\r\n }\r\n const crdtOptions = ensureNotFalsy(jsonSchema.crdt);\r\n const storageToken = await this.collection.database.storageToken;\r\n\r\n return this.incrementalModify(async (docData) => {\r\n const crdtDocField: CRDTDocumentField<RxDocType> = clone(getProperty(docData as any, crdtOptions.field));\r\n const operation: CRDTOperation<RxDocType> = {\r\n body: toArray(entry),\r\n creator: storageToken,\r\n time: now()\r\n };\r\n\r\n /**\r\n * A new write will ALWAYS be an operation in the last\r\n * array which was non existing before.\r\n */\r\n const lastAr: CRDTOperation<RxDocType>[] = [operation];\r\n crdtDocField.operations.push(lastAr);\r\n crdtDocField.hash = await hashCRDTOperations(this.collection.database.hashFunction, crdtDocField);\r\n\r\n docData = runOperationOnDocument(\r\n this.collection.schema.jsonSchema,\r\n docData,\r\n operation\r\n );\r\n setProperty(docData, crdtOptions.field, crdtDocField);\r\n return docData;\r\n }, RX_CRDT_CONTEXT);\r\n}\r\n\r\n\r\nexport async function insertCRDT<RxDocType>(\r\n this: RxCollection<RxDocType>,\r\n entry: CRDTEntry<RxDocType> | CRDTEntry<RxDocType>[]\r\n) {\r\n entry = overwritable.deepFreezeWhenDevMode(entry) as any;\r\n\r\n const jsonSchema = this.schema.jsonSchema;\r\n if (!jsonSchema.crdt) {\r\n throw newRxError('CRDT1', {\r\n schema: jsonSchema,\r\n queryObj: entry\r\n });\r\n }\r\n const crdtOptions = ensureNotFalsy(jsonSchema.crdt);\r\n const storageToken = await this.database.storageToken;\r\n const operation: CRDTOperation<RxDocType> = {\r\n body: Array.isArray(entry) ? entry : [entry],\r\n creator: storageToken,\r\n time: now()\r\n };\r\n\r\n let insertData: RxDocumentWriteData<RxDocType> = {} as any;\r\n insertData = runOperationOnDocument(\r\n this.schema.jsonSchema,\r\n insertData as any,\r\n operation\r\n ) as any;\r\n const crdtDocField: CRDTDocumentField<RxDocType> = {\r\n operations: [],\r\n hash: ''\r\n };\r\n setProperty(insertData as any, crdtOptions.field, crdtDocField);\r\n\r\n const lastAr: CRDTOperation<RxDocType>[] = [operation];\r\n crdtDocField.operations.push(lastAr);\r\n crdtDocField.hash = await hashCRDTOperations(this.database.hashFunction, crdtDocField);\r\n\r\n const result = await this.insert(insertData).catch(async (err: RxError) => {\r\n if (err.code === 'CONFLICT') {\r\n // was a conflict, update document instead of inserting\r\n const doc = await this.findOne(err.parameters.id).exec(true);\r\n return doc.updateCRDT(entry);\r\n } else {\r\n throw err;\r\n }\r\n });\r\n return result;\r\n}\r\n\r\n\r\nexport function sortOperationComparator<RxDocType>(a: CRDTOperation<RxDocType>, b: CRDTOperation<RxDocType>) {\r\n return a.creator > b.creator ? 1 : -1;\r\n}\r\n\r\n\r\nfunction runOperationOnDocument<RxDocType>(\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>,\r\n docData: WithDeleted<RxDocType>,\r\n operation: CRDTOperation<RxDocType>\r\n): WithDeleted<RxDocType> {\r\n const entryParts = operation.body;\r\n entryParts.forEach(entryPart => {\r\n let isMatching: boolean;\r\n if (entryPart.selector) {\r\n const query: FilledMangoQuery<RxDocType> = {\r\n selector: ensureNotFalsy(entryPart.selector as any),\r\n sort: [],\r\n skip: 0\r\n };\r\n const matcher = getQueryMatcher(schema, query);\r\n isMatching = matcher(docData as any);\r\n } else {\r\n isMatching = true;\r\n }\r\n if (isMatching) {\r\n if (entryPart.ifMatch) {\r\n docData = mingoUpdater<WithDeleted<RxDocType>>(docData, entryPart.ifMatch);\r\n }\r\n } else {\r\n if (entryPart.ifNotMatch) {\r\n docData = mingoUpdater<WithDeleted<RxDocType>>(docData, entryPart.ifNotMatch);\r\n }\r\n }\r\n });\r\n return docData;\r\n}\r\n\r\nexport async function hashCRDTOperations(\r\n hashFunction: HashFunction,\r\n crdts: CRDTDocumentField<any>\r\n): Promise<string> {\r\n const hashObj = crdts.operations.map((operations) => {\r\n return operations.map(op => op.creator);\r\n });\r\n const hash = await hashFunction(JSON.stringify(hashObj));\r\n return hash;\r\n}\r\n\r\nexport function getCRDTSchemaPart<RxDocType>(): JsonSchema<CRDTDocumentField<RxDocType>> {\r\n const operationSchema: JsonSchema<CRDTOperation<RxDocType>> = {\r\n type: 'object',\r\n properties: {\r\n body: {\r\n type: 'array',\r\n items: {\r\n type: 'object',\r\n properties: {\r\n selector: {\r\n type: 'object'\r\n },\r\n ifMatch: {\r\n type: 'object'\r\n },\r\n ifNotMatch: {\r\n type: 'object'\r\n }\r\n },\r\n additionalProperties: false\r\n },\r\n minItems: 1\r\n },\r\n creator: {\r\n type: 'string'\r\n },\r\n time: {\r\n type: 'number',\r\n minimum: 1,\r\n maximum: META_LWT_UNIX_TIME_MAX,\r\n multipleOf: 0.01\r\n }\r\n },\r\n additionalProperties: false,\r\n required: [\r\n 'body',\r\n 'creator',\r\n 'time'\r\n ]\r\n };\r\n return {\r\n type: 'object',\r\n properties: {\r\n operations: {\r\n type: 'array',\r\n items: {\r\n type: 'array',\r\n items: operationSchema\r\n }\r\n },\r\n hash: {\r\n type: 'string',\r\n // set a minLength to not accidentally store an empty string\r\n minLength: 2\r\n }\r\n },\r\n additionalProperties: false,\r\n required: ['operations', 'hash']\r\n };\r\n}\r\n\r\n\r\nexport async function mergeCRDTFields<RxDocType>(\r\n hashFunction: HashFunction,\r\n crdtsA: CRDTDocumentField<RxDocType>,\r\n crdtsB: CRDTDocumentField<RxDocType>\r\n): Promise<CRDTDocumentField<RxDocType>> {\r\n\r\n // the value with most operations must be A to\r\n // ensure we not miss out rows when iterating over both fields.\r\n if (crdtsA.operations.length < crdtsB.operations.length) {\r\n [crdtsA, crdtsB] = [crdtsB, crdtsA];\r\n }\r\n\r\n const ret: CRDTDocumentField<RxDocType> = {\r\n operations: [],\r\n hash: ''\r\n };\r\n crdtsA.operations.forEach((row, index) => {\r\n let mergedOps: CRDTOperation<RxDocType>[] = [];\r\n const ids = new Set<string>(); // used to deduplicate\r\n\r\n row.forEach(op => {\r\n ids.add(op.creator);\r\n mergedOps.push(op);\r\n });\r\n if (crdtsB.operations[index]) {\r\n crdtsB.operations[index].forEach(op => {\r\n if (!ids.has(op.creator)) {\r\n mergedOps.push(op);\r\n }\r\n });\r\n }\r\n mergedOps = mergedOps.sort(sortOperationComparator);\r\n ret.operations[index] = mergedOps;\r\n });\r\n\r\n\r\n ret.hash = await hashCRDTOperations(hashFunction, ret);\r\n return ret;\r\n}\r\n\r\nexport function rebuildFromCRDT<RxDocType>(\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>,\r\n docData: WithDeleted<RxDocType> | RxDocType,\r\n crdts: CRDTDocumentField<RxDocType>\r\n): WithDeleted<RxDocType> {\r\n let base: WithDeleted<RxDocType> = {\r\n _deleted: false\r\n } as any;\r\n setProperty(base, ensureNotFalsy(schema.crdt).field, crdts);\r\n crdts.operations.forEach(operations => {\r\n operations.forEach(op => {\r\n base = runOperationOnDocument(\r\n schema,\r\n base,\r\n op\r\n );\r\n });\r\n });\r\n return base;\r\n}\r\n\r\n\r\nexport function getCRDTConflictHandler<RxDocType>(\r\n hashFunction: HashFunction,\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>\r\n): RxConflictHandler<RxDocType> {\r\n const crdtOptions = ensureNotFalsy(schema.crdt);\r\n const crdtField = crdtOptions.field;\r\n const getCRDTValue = objectPathMonad<WithDeleted<RxDocType> | RxDocType, CRDTDocumentField<RxDocType>>(crdtField);\r\n\r\n const conflictHandler: RxConflictHandler<RxDocType> = {\r\n isEqual(a, b, ctx) {\r\n return getCRDTValue(a).hash === getCRDTValue(b).hash;\r\n },\r\n async resolve(i) {\r\n const newDocCrdt = getCRDTValue(i.newDocumentState);\r\n const masterDocCrdt = getCRDTValue(i.realMasterState);\r\n const mergedCrdt = await mergeCRDTFields(hashFunction, newDocCrdt, masterDocCrdt);\r\n const mergedDoc = rebuildFromCRDT(\r\n schema,\r\n i.newDocumentState,\r\n mergedCrdt\r\n );\r\n return mergedDoc;\r\n }\r\n }\r\n return conflictHandler;\r\n}\r\n\r\n\r\nexport const RX_CRDT_CONTEXT = 'rx-crdt';\r\n\r\nexport const RxDBcrdtPlugin: RxPlugin = {\r\n name: 'crdt',\r\n rxdb: true,\r\n prototypes: {\r\n RxDocument: (proto: any) => {\r\n proto.updateCRDT = updateCRDT;\r\n\r\n const oldRemove = proto.remove;\r\n proto.remove = function (this: RxDocument) {\r\n if (!this.collection.schema.jsonSchema.crdt) {\r\n return oldRemove.bind(this)();\r\n }\r\n return this.updateCRDT({\r\n ifMatch: {\r\n $set: {\r\n _deleted: true\r\n }\r\n }\r\n });\r\n };\r\n\r\n const oldincrementalRemove = proto.incrementalRemove;\r\n proto.incrementalRemove = function (this: RxDocument) {\r\n if (!this.collection.schema.jsonSchema.crdt) {\r\n return oldincrementalRemove.call(this);\r\n }\r\n return this.updateCRDT({\r\n ifMatch: {\r\n $set: {\r\n _deleted: true\r\n }\r\n }\r\n });\r\n };\r\n\r\n const oldModify = proto.modify;\r\n proto.modify = function (this: RxDocument, fn: any, context?: string) {\r\n if (!this.collection.schema.jsonSchema.crdt) {\r\n return oldModify.call(this, fn, context);\r\n }\r\n throw newRxError('CRDT4', {\r\n id: this.primary,\r\n args: { method: 'modify' }\r\n });\r\n };\r\n\r\n const oldPatch = proto.patch;\r\n proto.patch = function (this: RxDocument, patch: any) {\r\n if (!this.collection.schema.jsonSchema.crdt) {\r\n return oldPatch.call(this, patch);\r\n }\r\n return this.updateCRDT({\r\n ifMatch: {\r\n $set: patch\r\n }\r\n });\r\n };\r\n\r\n const oldincrementalPatch = proto.incrementalPatch;\r\n proto.incrementalPatch = function (this: RxDocument, patch: any) {\r\n if (!this.collection.schema.jsonSchema.crdt) {\r\n return oldincrementalPatch.bind(this)(patch);\r\n }\r\n return this.updateCRDT({\r\n ifMatch: {\r\n $set: patch\r\n }\r\n });\r\n };\r\n const oldincrementalModify = proto.incrementalModify;\r\n proto.incrementalModify = function (fn: any, context: string) {\r\n if (!this.collection.schema.jsonSchema.crdt) {\r\n return oldincrementalModify.bind(this)(fn);\r\n }\r\n if (context === RX_CRDT_CONTEXT) {\r\n return oldincrementalModify.bind(this)(fn);\r\n } else {\r\n throw newRxError('CRDT2', {\r\n id: this.primary,\r\n args: { context }\r\n });\r\n }\r\n };\r\n\r\n const oldUpdate = proto.update;\r\n proto.update = function (this: RxDocument, updateObj: any) {\r\n if (!this.collection.schema.jsonSchema.crdt) {\r\n return oldUpdate.call(this, updateObj);\r\n }\r\n return this.updateCRDT({\r\n ifMatch: updateObj\r\n });\r\n };\r\n },\r\n RxCollection: (proto: any) => {\r\n proto.insertCRDT = insertCRDT;\r\n }\r\n },\r\n overwritable: {},\r\n hooks: {\r\n preCreateRxCollection: {\r\n after: (data) => {\r\n if (!data.schema.crdt) {\r\n return;\r\n }\r\n if (data.conflictHandler) {\r\n throw newRxError('CRDT3', {\r\n collection: data.name,\r\n schema: data.schema\r\n });\r\n }\r\n data.conflictHandler = getCRDTConflictHandler(\r\n data.database.hashFunction,\r\n data.schema\r\n );\r\n }\r\n },\r\n createRxCollection: {\r\n after: ({ collection }) => {\r\n if (!collection.schema.jsonSchema.crdt) {\r\n return;\r\n }\r\n\r\n const crdtOptions = ensureNotFalsy(collection.schema.jsonSchema.crdt);\r\n const crdtField = crdtOptions.field;\r\n const getCrdt = objectPathMonad<any, CRDTDocumentField<any>>(crdtOptions.field);\r\n\r\n /**\r\n * In dev-mode we have to ensure that all document writes\r\n * have the correct crdt state so that nothing is missed out\r\n * or could accidentally do non-crdt writes to the document.\r\n */\r\n if (overwritable.isDevMode()) {\r\n const bulkWriteBefore = collection.storageInstance.bulkWrite.bind(collection.storageInstance);\r\n collection.storageInstance.bulkWrite = async function (writes, context) {\r\n\r\n await Promise.all(\r\n writes.map(async (write) => {\r\n const newDocState: typeof write.document = clone(write.document);\r\n const crdts = getCrdt(newDocState);\r\n\r\n const rebuild = rebuildFromCRDT(\r\n collection.schema.jsonSchema,\r\n newDocState,\r\n crdts\r\n );\r\n\r\n function docWithoutMeta(doc: any) {\r\n const ret: any = {};\r\n Object.entries(doc).forEach(([k, v]) => {\r\n if (\r\n !k.startsWith('_') &&\r\n typeof v !== 'undefined'\r\n ) {\r\n ret[k] = v;\r\n }\r\n });\r\n return ret;\r\n }\r\n if (!deepEqual(docWithoutMeta(newDocState), docWithoutMeta(rebuild))) {\r\n throw newRxError('SNH', {\r\n document: newDocState\r\n });\r\n }\r\n const recalculatedHash = await hashCRDTOperations(collection.database.hashFunction, crdts);\r\n if (crdts.hash !== recalculatedHash) {\r\n throw newRxError('SNH', {\r\n document: newDocState,\r\n args: { hash: crdts.hash, recalculatedHash }\r\n });\r\n }\r\n })\r\n );\r\n\r\n return bulkWriteBefore(writes, context);\r\n };\r\n }\r\n\r\n\r\n const bulkInsertBefore = collection.bulkInsert.bind(collection);\r\n collection.bulkInsert = async function (docsData: any[]) {\r\n const storageToken = await collection.database.storageToken;\r\n const useDocsData = await Promise.all(\r\n docsData.map(async (docData) => {\r\n /**\r\n * Fill schema default values before creating CRDT operations,\r\n * so that default values are captured in the operations and\r\n * will be preserved during rebuildFromCRDT (conflict resolution).\r\n */\r\n fillObjectWithDefaults(collection.schema, docData);\r\n\r\n const setMe: Partial<RxDocumentData<any>> = {};\r\n Object.entries(docData).forEach(([key, value]) => {\r\n if (\r\n !key.startsWith('_') &&\r\n key !== crdtField\r\n ) {\r\n setMe[key] = value;\r\n }\r\n });\r\n\r\n const crdtOperations: CRDTDocumentField<any> = {\r\n operations: [\r\n [{\r\n creator: storageToken,\r\n body: [{\r\n ifMatch: {\r\n $set: setMe\r\n }\r\n }],\r\n time: now()\r\n }]\r\n ],\r\n hash: ''\r\n };\r\n crdtOperations.hash = await hashCRDTOperations(collection.database.hashFunction, crdtOperations);\r\n setProperty(docData, crdtOptions.field, crdtOperations);\r\n return docData;\r\n })\r\n );\r\n return bulkInsertBefore(useDocsData);\r\n };\r\n }\r\n }\r\n }\r\n};\r\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ,mBAAmB;AAgB9C,SACIC,KAAK,EACLC,SAAS,EACTC,cAAc,EACdC,WAAW,EACXC,GAAG,EACHC,eAAe,EACfC,WAAW,EACX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]}
|
|
@@ -31,7 +31,13 @@ export function checkQuery(args) {
|
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Count queries cannot use skip or limit.
|
|
36
|
+
* The storage.count() method returns the total number of matching documents
|
|
37
|
+
* and is designed to ignore skip/limit (see rx-storage.interface.d.ts).
|
|
38
|
+
* This is intentional by design - count should always return the total.
|
|
39
|
+
* @intentional This is correct behavior, not a bug.
|
|
40
|
+
*/
|
|
35
41
|
if (args.op === 'count' && (args.queryObj.limit || args.queryObj.skip)) {
|
|
36
42
|
throw newRxError('QU15', {
|
|
37
43
|
collection: args.collection.name,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-query.js","names":["newRxError","newRxTypeError","deepEqual","findUndefinedPath","prepareQuery","checkQuery","args","isPlainObject","Object","prototype","toString","call","queryObj","op","collection","name","validKeys","keys","forEach","key","includes","limit","skip","query","ensureObjectDoesNotContainRegExp","checkMangoQuery","schema","rxQuery","jsonSchema","undefinedFieldPath","mangoQuery","field","massagedSelector","selector","schemaTopLevelFields","properties","filter","fieldOrOperator","startsWith","schemaIndexes","indexes","index","isInSchema","find","schemaIndex","areSelectorsSatisfiedByIndex","database","allowSlowCount","sort","map","sortPart","preparedQuery","queryPlan","selectorSatisfiedByIndex","value","RegExp","Array","isArray","item","isQueryAllowed"],"sources":["../../../../src/plugins/dev-mode/check-query.ts"],"sourcesContent":["import type {\r\n RxPluginPreCreateRxQueryArgs,\r\n MangoQuery,\r\n RxPluginPrePrepareQueryArgs,\r\n FilledMangoQuery,\r\n RxJsonSchema,\r\n RxDocumentData,\r\n MangoQuerySelector,\r\n PreparedQuery,\r\n RxQueryOP,\r\n RxPluginPrePrepareRxQueryArgs\r\n} from '../../types/index.d.ts';\r\nimport { newRxError, newRxTypeError } from '../../rx-error.ts';\r\nimport { deepEqual, findUndefinedPath } from '../utils/index.ts';\r\nimport { prepareQuery } from '../../rx-query-helper.ts';\r\n\r\n/**\r\n * accidentally passing a non-valid object into the query params\r\n * is very hard to debug especially when queries are observed\r\n * This is why we do some checks here in dev-mode\r\n */\r\nexport function checkQuery(args: RxPluginPreCreateRxQueryArgs) {\r\n const isPlainObject = Object.prototype.toString.call(args.queryObj) === '[object Object]';\r\n if (!isPlainObject) {\r\n throw newRxTypeError('QU11', {\r\n op: args.op,\r\n collection: args.collection.name,\r\n queryObj: args.queryObj\r\n });\r\n }\r\n\r\n const validKeys: (keyof MangoQuery)[] = [\r\n 'selector',\r\n 'limit',\r\n 'skip',\r\n 'sort',\r\n 'index'\r\n ];\r\n Object.keys(args.queryObj).forEach(key => {\r\n if (!(validKeys as string[]).includes(key)) {\r\n throw newRxTypeError('QU11', {\r\n op: args.op,\r\n collection: args.collection.name,\r\n queryObj: args.queryObj,\r\n key,\r\n args: {\r\n validKeys\r\n }\r\n });\r\n }\r\n });\r\n\r\n // do not allow skip or limit for count queries\r\n if (\r\n args.op === 'count' &&\r\n (\r\n args.queryObj.limit ||\r\n args.queryObj.skip\r\n )\r\n ) {\r\n throw newRxError(\r\n 'QU15',\r\n {\r\n collection: args.collection.name,\r\n query: args.queryObj\r\n }\r\n );\r\n }\r\n\r\n ensureObjectDoesNotContainRegExp(args.queryObj);\r\n}\r\n\r\n\r\nexport function checkMangoQuery(args: RxPluginPrePrepareQueryArgs) {\r\n const schema = args.rxQuery.collection.schema.jsonSchema;\r\n\r\n const undefinedFieldPath = findUndefinedPath(args.mangoQuery);\r\n if (undefinedFieldPath) {\r\n throw newRxError('QU19', {\r\n field: undefinedFieldPath,\r\n query: args.mangoQuery,\r\n });\r\n }\r\n\r\n /**\r\n * Ensure that all top level fields are included in the schema.\r\n * TODO this check can be augmented to also check sub-fields.\r\n */\r\n const massagedSelector: MangoQuerySelector<any> = args.mangoQuery.selector;\r\n const schemaTopLevelFields = Object.keys(schema.properties);\r\n Object.keys(massagedSelector)\r\n // do not check operators\r\n .filter(fieldOrOperator => !fieldOrOperator.startsWith('$'))\r\n // skip this check on non-top-level fields\r\n .filter(field => !field.includes('.'))\r\n .forEach(field => {\r\n if (!schemaTopLevelFields.includes(field)) {\r\n throw newRxError('QU13', {\r\n schema,\r\n field,\r\n query: args.mangoQuery,\r\n });\r\n }\r\n });\r\n\r\n /**\r\n * ensure if custom index is set,\r\n * it is also defined in the schema\r\n */\r\n const schemaIndexes = schema.indexes ? schema.indexes : [];\r\n const index = args.mangoQuery.index;\r\n if (index) {\r\n const isInSchema = schemaIndexes.find(schemaIndex => deepEqual(schemaIndex, index));\r\n if (!isInSchema) {\r\n throw newRxError(\r\n 'QU12',\r\n {\r\n collection: args.rxQuery.collection.name,\r\n query: args.mangoQuery,\r\n schema\r\n }\r\n );\r\n }\r\n }\r\n\r\n\r\n /**\r\n * Ensure that a count() query can only be used\r\n * with selectors that are fully satisfied by the used index.\r\n */\r\n if (args.rxQuery.op === 'count') {\r\n if (\r\n !areSelectorsSatisfiedByIndex(\r\n args.rxQuery.collection.schema.jsonSchema,\r\n args.mangoQuery\r\n ) &&\r\n !args.rxQuery.collection.database.allowSlowCount\r\n ) {\r\n throw newRxError('QU14', {\r\n collection: args.rxQuery.collection,\r\n query: args.mangoQuery\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Ensure that sort only runs on known fields\r\n * TODO also check nested fields\r\n */\r\n if (args.mangoQuery.sort) {\r\n args.mangoQuery.sort\r\n .map(sortPart => Object.keys(sortPart)[0])\r\n .filter(field => !field.includes('.'))\r\n .forEach(field => {\r\n if (!schemaTopLevelFields.includes(field)) {\r\n throw newRxError('QU13', {\r\n schema,\r\n field,\r\n query: args.mangoQuery,\r\n });\r\n }\r\n });\r\n }\r\n\r\n // Do not allow RexExp instances\r\n ensureObjectDoesNotContainRegExp(args.mangoQuery);\r\n}\r\n\r\n\r\nexport function areSelectorsSatisfiedByIndex<RxDocType>(\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>,\r\n query: FilledMangoQuery<RxDocType>\r\n): boolean {\r\n const preparedQuery: PreparedQuery<any> = prepareQuery(\r\n schema,\r\n query\r\n );\r\n return preparedQuery.queryPlan.selectorSatisfiedByIndex;\r\n}\r\n\r\n/**\r\n * Ensures that the selector does not contain any RegExp instance.\r\n * @recursive\r\n */\r\nexport function ensureObjectDoesNotContainRegExp(selector: any) {\r\n if (typeof selector !== 'object' || selector === null) {\r\n return;\r\n }\r\n const keys = Object.keys(selector);\r\n keys.forEach(key => {\r\n const value: any = selector[key];\r\n if (value instanceof RegExp) {\r\n throw newRxError('QU16', {\r\n field: key,\r\n query: selector,\r\n });\r\n } else if (Array.isArray(value)) {\r\n value.forEach(item => ensureObjectDoesNotContainRegExp(item));\r\n } else {\r\n ensureObjectDoesNotContainRegExp(value);\r\n }\r\n });\r\n}\r\n\r\n\r\n/**\r\n * People often use queries wrong\r\n * so we have some checks here.\r\n * For example people use numbers as primary keys\r\n * which is not allowed.\r\n */\r\nexport function isQueryAllowed(args: RxPluginPrePrepareRxQueryArgs) {\r\n if (args.op === 'findOne') {\r\n if (\r\n typeof args.queryObj === 'number' ||\r\n Array.isArray(args.queryObj)\r\n ) {\r\n throw newRxTypeError('COL6', {\r\n collection: args.collection.name,\r\n queryObj: args.queryObj\r\n });\r\n }\r\n } else if (args.op === 'find') {\r\n if (typeof args.queryObj === 'string') {\r\n throw newRxError('COL5', {\r\n collection: args.collection.name,\r\n queryObj: args.queryObj\r\n });\r\n }\r\n }\r\n}\r\n"],"mappings":"AAYA,SAASA,UAAU,EAAEC,cAAc,QAAQ,mBAAmB;AAC9D,SAASC,SAAS,EAAEC,iBAAiB,QAAQ,mBAAmB;AAChE,SAASC,YAAY,QAAQ,0BAA0B;;AAEvD;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAACC,IAAkC,EAAE;EAC3D,IAAMC,aAAa,GAAGC,MAAM,CAACC,SAAS,CAACC,QAAQ,CAACC,IAAI,CAACL,IAAI,CAACM,QAAQ,CAAC,KAAK,iBAAiB;EACzF,IAAI,CAACL,aAAa,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EAAE;QACrBc,UAAU,EAAER,IAAI,CAACQ,UAAU,CAACC,IAAI;QAChCH,QAAQ,EAAEN,IAAI,CAACM;MACnB,CAAC,CAAC;IACN;EACJ;AACJ","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"check-query.js","names":["newRxError","newRxTypeError","deepEqual","findUndefinedPath","prepareQuery","checkQuery","args","isPlainObject","Object","prototype","toString","call","queryObj","op","collection","name","validKeys","keys","forEach","key","includes","limit","skip","query","ensureObjectDoesNotContainRegExp","checkMangoQuery","schema","rxQuery","jsonSchema","undefinedFieldPath","mangoQuery","field","massagedSelector","selector","schemaTopLevelFields","properties","filter","fieldOrOperator","startsWith","schemaIndexes","indexes","index","isInSchema","find","schemaIndex","areSelectorsSatisfiedByIndex","database","allowSlowCount","sort","map","sortPart","preparedQuery","queryPlan","selectorSatisfiedByIndex","value","RegExp","Array","isArray","item","isQueryAllowed"],"sources":["../../../../src/plugins/dev-mode/check-query.ts"],"sourcesContent":["import type {\r\n RxPluginPreCreateRxQueryArgs,\r\n MangoQuery,\r\n RxPluginPrePrepareQueryArgs,\r\n FilledMangoQuery,\r\n RxJsonSchema,\r\n RxDocumentData,\r\n MangoQuerySelector,\r\n PreparedQuery,\r\n RxQueryOP,\r\n RxPluginPrePrepareRxQueryArgs\r\n} from '../../types/index.d.ts';\r\nimport { newRxError, newRxTypeError } from '../../rx-error.ts';\r\nimport { deepEqual, findUndefinedPath } from '../utils/index.ts';\r\nimport { prepareQuery } from '../../rx-query-helper.ts';\r\n\r\n/**\r\n * accidentally passing a non-valid object into the query params\r\n * is very hard to debug especially when queries are observed\r\n * This is why we do some checks here in dev-mode\r\n */\r\nexport function checkQuery(args: RxPluginPreCreateRxQueryArgs) {\r\n const isPlainObject = Object.prototype.toString.call(args.queryObj) === '[object Object]';\r\n if (!isPlainObject) {\r\n throw newRxTypeError('QU11', {\r\n op: args.op,\r\n collection: args.collection.name,\r\n queryObj: args.queryObj\r\n });\r\n }\r\n\r\n const validKeys: (keyof MangoQuery)[] = [\r\n 'selector',\r\n 'limit',\r\n 'skip',\r\n 'sort',\r\n 'index'\r\n ];\r\n Object.keys(args.queryObj).forEach(key => {\r\n if (!(validKeys as string[]).includes(key)) {\r\n throw newRxTypeError('QU11', {\r\n op: args.op,\r\n collection: args.collection.name,\r\n queryObj: args.queryObj,\r\n key,\r\n args: {\r\n validKeys\r\n }\r\n });\r\n }\r\n });\r\n\r\n /**\r\n * Count queries cannot use skip or limit.\r\n * The storage.count() method returns the total number of matching documents\r\n * and is designed to ignore skip/limit (see rx-storage.interface.d.ts).\r\n * This is intentional by design - count should always return the total.\r\n * @intentional This is correct behavior, not a bug.\r\n */\r\n if (\r\n args.op === 'count' &&\r\n (\r\n args.queryObj.limit ||\r\n args.queryObj.skip\r\n )\r\n ) {\r\n throw newRxError(\r\n 'QU15',\r\n {\r\n collection: args.collection.name,\r\n query: args.queryObj\r\n }\r\n );\r\n }\r\n\r\n ensureObjectDoesNotContainRegExp(args.queryObj);\r\n}\r\n\r\n\r\nexport function checkMangoQuery(args: RxPluginPrePrepareQueryArgs) {\r\n const schema = args.rxQuery.collection.schema.jsonSchema;\r\n\r\n const undefinedFieldPath = findUndefinedPath(args.mangoQuery);\r\n if (undefinedFieldPath) {\r\n throw newRxError('QU19', {\r\n field: undefinedFieldPath,\r\n query: args.mangoQuery,\r\n });\r\n }\r\n\r\n /**\r\n * Ensure that all top level fields are included in the schema.\r\n * TODO this check can be augmented to also check sub-fields.\r\n */\r\n const massagedSelector: MangoQuerySelector<any> = args.mangoQuery.selector;\r\n const schemaTopLevelFields = Object.keys(schema.properties);\r\n Object.keys(massagedSelector)\r\n // do not check operators\r\n .filter(fieldOrOperator => !fieldOrOperator.startsWith('$'))\r\n // skip this check on non-top-level fields\r\n .filter(field => !field.includes('.'))\r\n .forEach(field => {\r\n if (!schemaTopLevelFields.includes(field)) {\r\n throw newRxError('QU13', {\r\n schema,\r\n field,\r\n query: args.mangoQuery,\r\n });\r\n }\r\n });\r\n\r\n /**\r\n * ensure if custom index is set,\r\n * it is also defined in the schema\r\n */\r\n const schemaIndexes = schema.indexes ? schema.indexes : [];\r\n const index = args.mangoQuery.index;\r\n if (index) {\r\n const isInSchema = schemaIndexes.find(schemaIndex => deepEqual(schemaIndex, index));\r\n if (!isInSchema) {\r\n throw newRxError(\r\n 'QU12',\r\n {\r\n collection: args.rxQuery.collection.name,\r\n query: args.mangoQuery,\r\n schema\r\n }\r\n );\r\n }\r\n }\r\n\r\n\r\n /**\r\n * Ensure that a count() query can only be used\r\n * with selectors that are fully satisfied by the used index.\r\n */\r\n if (args.rxQuery.op === 'count') {\r\n if (\r\n !areSelectorsSatisfiedByIndex(\r\n args.rxQuery.collection.schema.jsonSchema,\r\n args.mangoQuery\r\n ) &&\r\n !args.rxQuery.collection.database.allowSlowCount\r\n ) {\r\n throw newRxError('QU14', {\r\n collection: args.rxQuery.collection,\r\n query: args.mangoQuery\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Ensure that sort only runs on known fields\r\n * TODO also check nested fields\r\n */\r\n if (args.mangoQuery.sort) {\r\n args.mangoQuery.sort\r\n .map(sortPart => Object.keys(sortPart)[0])\r\n .filter(field => !field.includes('.'))\r\n .forEach(field => {\r\n if (!schemaTopLevelFields.includes(field)) {\r\n throw newRxError('QU13', {\r\n schema,\r\n field,\r\n query: args.mangoQuery,\r\n });\r\n }\r\n });\r\n }\r\n\r\n // Do not allow RexExp instances\r\n ensureObjectDoesNotContainRegExp(args.mangoQuery);\r\n}\r\n\r\n\r\nexport function areSelectorsSatisfiedByIndex<RxDocType>(\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>,\r\n query: FilledMangoQuery<RxDocType>\r\n): boolean {\r\n const preparedQuery: PreparedQuery<any> = prepareQuery(\r\n schema,\r\n query\r\n );\r\n return preparedQuery.queryPlan.selectorSatisfiedByIndex;\r\n}\r\n\r\n/**\r\n * Ensures that the selector does not contain any RegExp instance.\r\n * @recursive\r\n */\r\nexport function ensureObjectDoesNotContainRegExp(selector: any) {\r\n if (typeof selector !== 'object' || selector === null) {\r\n return;\r\n }\r\n const keys = Object.keys(selector);\r\n keys.forEach(key => {\r\n const value: any = selector[key];\r\n if (value instanceof RegExp) {\r\n throw newRxError('QU16', {\r\n field: key,\r\n query: selector,\r\n });\r\n } else if (Array.isArray(value)) {\r\n value.forEach(item => ensureObjectDoesNotContainRegExp(item));\r\n } else {\r\n ensureObjectDoesNotContainRegExp(value);\r\n }\r\n });\r\n}\r\n\r\n\r\n/**\r\n * People often use queries wrong\r\n * so we have some checks here.\r\n * For example people use numbers as primary keys\r\n * which is not allowed.\r\n */\r\nexport function isQueryAllowed(args: RxPluginPrePrepareRxQueryArgs) {\r\n if (args.op === 'findOne') {\r\n if (\r\n typeof args.queryObj === 'number' ||\r\n Array.isArray(args.queryObj)\r\n ) {\r\n throw newRxTypeError('COL6', {\r\n collection: args.collection.name,\r\n queryObj: args.queryObj\r\n });\r\n }\r\n } else if (args.op === 'find') {\r\n if (typeof args.queryObj === 'string') {\r\n throw newRxError('COL5', {\r\n collection: args.collection.name,\r\n queryObj: args.queryObj\r\n });\r\n }\r\n }\r\n}\r\n"],"mappings":"AAYA,SAASA,UAAU,EAAEC,cAAc,QAAQ,mBAAmB;AAC9D,SAASC,SAAS,EAAEC,iBAAiB,QAAQ,mBAAmB;AAChE,SAASC,YAAY,QAAQ,0BAA0B;;AAEvD;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAACC,IAAkC,EAAE;EAC3D,IAAMC,aAAa,GAAGC,MAAM,CAACC,SAAS,CAACC,QAAQ,CAACC,IAAI,CAACL,IAAI,CAACM,QAAQ,CAAC,KAAK,iBAAiB;EACzF,IAAI,CAACL,aAAa,EAAE;IAChB,MAAMN,cAAc,CAAC,MAAM,EAAE;MACzBY,EAAE,EAAEP,IAAI,CAACO,EAAE;MACXC,UAAU,EAAER,IAAI,CAACQ,UAAU,CAACC,IAAI;MAChCH,QAAQ,EAAEN,IAAI,CAACM;IACnB,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
@@ -253,10 +253,11 @@ export function checkSchema(jsonSchema) {
|
|
|
253
253
|
}
|
|
254
254
|
validateFieldsDeep(jsonSchema);
|
|
255
255
|
checkPrimaryKey(jsonSchema);
|
|
256
|
+
var primaryPath = getPrimaryFieldOfPrimaryKey(jsonSchema.primaryKey);
|
|
256
257
|
Object.keys(jsonSchema.properties).forEach(key => {
|
|
257
258
|
var value = jsonSchema.properties[key];
|
|
258
259
|
// check primary
|
|
259
|
-
if (key ===
|
|
260
|
+
if (key === primaryPath) {
|
|
260
261
|
if (jsonSchema.indexes && jsonSchema.indexes.includes(key)) {
|
|
261
262
|
throw newRxError('SC13', {
|
|
262
263
|
value,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-schema.js","names":["newRxError","getPrimaryFieldOfPrimaryKey","getSchemaByObjectPath","flattenObject","getProperty","isMaybeReadonlyArray","trimDots","rxDocumentProperties","checkFieldNameRegex","fieldName","includes","regexStr","regex","RegExp","match","validateFieldsDeep","rxJsonSchema","primaryPath","primaryKey","checkField","schemaObj","path","Array","isArray","split","pop","Object","prototype","hasOwnProperty","call","type","required","length","items","isNested","default","charAt","traverse","currentObj","currentPath","keys","forEach","attributeName","properties","nextPath","checkPrimaryKey","jsonSchema","schema","validatePrimarySchemaPart","schemaPart","args","key","compositePrimaryKey","keySchemaPart","fields","field","primaryPathSchemaPart","maxLength","isFinite","getSchemaPropertyRealPath","shortPath","pathParts","realPath","i","concat","checkSchema","_rev","version","value","indexes","unique","encrypted","index","indexAsArray","multipleOf","maximum","minimum","parentPath","lastPathPart","partParts","join","parentSchemaPart","map","filter","elem","pos","arr","indexOf","replace","reduce","indexPaths","currentIndex","push","indexPath","propPath"],"sources":["../../../../src/plugins/dev-mode/check-schema.ts"],"sourcesContent":["/**\r\n * does additional checks over the schema-json\r\n * to ensure nothing is broken or not supported\r\n */\r\nimport {\r\n newRxError\r\n} from '../../rx-error.ts';\r\nimport {\r\n getPrimaryFieldOfPrimaryKey,\r\n getSchemaByObjectPath\r\n} from '../../rx-schema-helper.ts';\r\nimport type {\r\n CompositePrimaryKey,\r\n JsonSchema,\r\n JsonSchemaTypes,\r\n RxJsonSchema,\r\n TopLevelProperty\r\n} from '../../types/index.d.ts';\r\nimport {\r\n flattenObject,\r\n getProperty,\r\n isMaybeReadonlyArray,\r\n trimDots\r\n} from '../../plugins/utils/index.ts';\r\nimport { rxDocumentProperties } from './entity-properties.ts';\r\n\r\n/**\r\n * checks if the fieldname is allowed\r\n * this makes sure that the fieldnames can be transformed into javascript-vars\r\n * and does not conquer the observe$ and populate_ fields\r\n * @throws {Error}\r\n */\r\nexport function checkFieldNameRegex(fieldName: string) {\r\n if (fieldName === '_deleted') {\r\n return;\r\n }\r\n\r\n if (['properties'].includes(fieldName)) {\r\n throw newRxError('SC23', {\r\n fieldName\r\n });\r\n }\r\n\r\n const regexStr = '^[a-zA-Z](?:[[a-zA-Z0-9_]*]?[a-zA-Z0-9])?$';\r\n const regex = new RegExp(regexStr);\r\n if (\r\n /**\r\n * It must be allowed to set _id as primaryKey.\r\n * This makes it sometimes easier to work with RxDB+CouchDB\r\n * @link https://github.com/pubkey/rxdb/issues/681\r\n */\r\n fieldName !== '_id' &&\r\n !fieldName.match(regex)\r\n ) {\r\n throw newRxError('SC1', {\r\n regex: regexStr,\r\n fieldName\r\n });\r\n }\r\n}\r\n\r\n/**\r\n * validate that all schema-related things are ok\r\n */\r\nexport function validateFieldsDeep(rxJsonSchema: RxJsonSchema<any>): true {\r\n\r\n const primaryPath = getPrimaryFieldOfPrimaryKey(rxJsonSchema.primaryKey);\r\n\r\n function checkField(\r\n fieldName: string,\r\n schemaObj: JsonSchema<any>,\r\n path: string\r\n ) {\r\n if (\r\n typeof fieldName === 'string' &&\r\n typeof schemaObj === 'object' &&\r\n !Array.isArray(schemaObj) &&\r\n path.split('.').pop() !== 'patternProperties'\r\n ) checkFieldNameRegex(fieldName);\r\n\r\n // 'item' only allowed it type=='array'\r\n if (Object.prototype.hasOwnProperty.call(schemaObj, 'item') && schemaObj.type !== 'array') {\r\n throw newRxError('SC2', {\r\n fieldName\r\n });\r\n }\r\n\r\n /**\r\n * required fields cannot be set via 'required: true',\r\n * but must be set via required: []\r\n */\r\n if (\r\n Object.prototype.hasOwnProperty.call(schemaObj, 'required') &&\r\n typeof schemaObj.required === 'boolean'\r\n ) {\r\n throw newRxError('SC24', {\r\n fieldName\r\n });\r\n }\r\n\r\n // $ref is not allowed\r\n if (Object.prototype.hasOwnProperty.call(schemaObj, '$ref')) {\r\n throw newRxError('SC40', {\r\n fieldName\r\n });\r\n }\r\n\r\n\r\n // if ref given, must be type=='string', type=='array' with string-items or type==['string','null']\r\n if (Object.prototype.hasOwnProperty.call(schemaObj, 'ref')) {\r\n if (Array.isArray(schemaObj.type)) {\r\n if (schemaObj.type.length > 2 || !schemaObj.type.includes('string') || !schemaObj.type.includes('null')) {\r\n throw newRxError('SC4', {\r\n fieldName\r\n });\r\n }\r\n } else {\r\n switch (schemaObj.type) {\r\n case 'string':\r\n break;\r\n case 'array':\r\n if (\r\n !schemaObj.items ||\r\n !(schemaObj.items as any).type ||\r\n (schemaObj.items as any).type !== 'string'\r\n ) {\r\n throw newRxError('SC3', {\r\n fieldName\r\n });\r\n }\r\n break;\r\n default:\r\n throw newRxError('SC4', {\r\n fieldName\r\n });\r\n }\r\n }\r\n }\r\n\r\n const isNested = path.split('.').length >= 2;\r\n\r\n // nested only\r\n if (isNested) {\r\n if ((schemaObj as any).default) {\r\n throw newRxError('SC7', {\r\n path\r\n });\r\n }\r\n }\r\n\r\n // first level\r\n if (!isNested) {\r\n\r\n // if _id is used, it must be primaryKey\r\n if (\r\n fieldName === '_id' &&\r\n primaryPath !== '_id'\r\n ) {\r\n throw newRxError('COL2', {\r\n fieldName\r\n });\r\n }\r\n\r\n // check underscore fields\r\n if (fieldName.charAt(0) === '_') {\r\n if (\r\n // exceptional allow underscore on these fields.\r\n fieldName === '_id' ||\r\n fieldName === '_deleted'\r\n ) {\r\n return;\r\n }\r\n throw newRxError('SC8', {\r\n fieldName\r\n });\r\n }\r\n }\r\n }\r\n\r\n function traverse(currentObj: any, currentPath: any) {\r\n if (!currentObj || typeof currentObj !== 'object') {\r\n return;\r\n }\r\n Object.keys(currentObj).forEach(attributeName => {\r\n const schemaObj = currentObj[attributeName];\r\n if (\r\n !currentObj.properties &&\r\n schemaObj &&\r\n typeof schemaObj === 'object' &&\r\n !Array.isArray(currentObj)\r\n ) {\r\n checkField(\r\n attributeName,\r\n schemaObj,\r\n currentPath\r\n );\r\n }\r\n let nextPath = currentPath;\r\n if (attributeName !== 'properties') nextPath = nextPath + '.' + attributeName;\r\n traverse(schemaObj, nextPath);\r\n });\r\n }\r\n traverse(rxJsonSchema, '');\r\n return true;\r\n}\r\n\r\nexport function checkPrimaryKey(\r\n jsonSchema: RxJsonSchema<any>\r\n) {\r\n if (!jsonSchema.primaryKey) {\r\n throw newRxError('SC30', { schema: jsonSchema });\r\n }\r\n\r\n\r\n\r\n function validatePrimarySchemaPart(\r\n schemaPart: JsonSchema | TopLevelProperty\r\n ) {\r\n if (!schemaPart) {\r\n throw newRxError('SC33', { schema: jsonSchema });\r\n }\r\n\r\n const type: string = schemaPart.type as any;\r\n if (\r\n !type ||\r\n !['string', 'number', 'integer'].includes(type)\r\n ) {\r\n throw newRxError('SC32', { schema: jsonSchema, args: { schemaPart } });\r\n }\r\n }\r\n\r\n if (typeof jsonSchema.primaryKey === 'string') {\r\n const key = jsonSchema.primaryKey;\r\n const schemaPart = jsonSchema.properties[key];\r\n validatePrimarySchemaPart(schemaPart);\r\n } else {\r\n const compositePrimaryKey: CompositePrimaryKey<any> = jsonSchema.primaryKey as any;\r\n\r\n const keySchemaPart = getSchemaByObjectPath(jsonSchema, compositePrimaryKey.key);\r\n validatePrimarySchemaPart(keySchemaPart);\r\n\r\n compositePrimaryKey.fields.forEach(field => {\r\n const schemaPart = getSchemaByObjectPath(jsonSchema, field);\r\n validatePrimarySchemaPart(schemaPart);\r\n });\r\n }\r\n\r\n\r\n /**\r\n * The primary key must have a maxLength set\r\n * which is required by some RxStorage implementations\r\n * to ensure we can craft custom index strings.\r\n */\r\n const primaryPath = getPrimaryFieldOfPrimaryKey(jsonSchema.primaryKey);\r\n const primaryPathSchemaPart = jsonSchema.properties[primaryPath];\r\n if (!primaryPathSchemaPart.maxLength) {\r\n throw newRxError('SC39', { schema: jsonSchema, args: { primaryPathSchemaPart } });\r\n } else if (!isFinite(primaryPathSchemaPart.maxLength)) {\r\n throw newRxError('SC41', { schema: jsonSchema, args: { primaryPathSchemaPart } });\r\n }\r\n}\r\n\r\n/**\r\n * computes real path of the object path in the collection schema\r\n */\r\nfunction getSchemaPropertyRealPath(shortPath: string) {\r\n const pathParts = shortPath.split('.');\r\n let realPath = '';\r\n for (let i = 0; i < pathParts.length; i += 1) {\r\n if (pathParts[i] !== '[]') {\r\n realPath = realPath.concat('.properties.'.concat(pathParts[i]));\r\n } else {\r\n realPath = realPath.concat('.items');\r\n }\r\n }\r\n return trimDots(realPath);\r\n}\r\n\r\n/**\r\n * does the checking\r\n * @throws {Error} if something is not ok\r\n */\r\nexport function checkSchema(jsonSchema: RxJsonSchema<any>) {\r\n\r\n if (!jsonSchema.primaryKey) {\r\n throw newRxError('SC30', {\r\n schema: jsonSchema\r\n });\r\n }\r\n\r\n if (!Object.prototype.hasOwnProperty.call(jsonSchema, 'properties')) {\r\n throw newRxError('SC29', {\r\n schema: jsonSchema\r\n });\r\n }\r\n\r\n // _rev MUST NOT exist, it is added by RxDB\r\n if (jsonSchema.properties._rev) {\r\n throw newRxError('SC10', {\r\n schema: jsonSchema\r\n });\r\n }\r\n\r\n // check version\r\n if (!Object.prototype.hasOwnProperty.call(jsonSchema, 'version') ||\r\n typeof jsonSchema.version !== 'number' ||\r\n jsonSchema.version < 0\r\n ) {\r\n throw newRxError('SC11', {\r\n version: jsonSchema.version\r\n });\r\n }\r\n\r\n validateFieldsDeep(jsonSchema);\r\n checkPrimaryKey(jsonSchema);\r\n\r\n Object.keys(jsonSchema.properties).forEach(key => {\r\n const value: any = jsonSchema.properties[key];\r\n // check primary\r\n if (key === jsonSchema.primaryKey) {\r\n if (jsonSchema.indexes && jsonSchema.indexes.includes(key)) {\r\n throw newRxError('SC13', {\r\n value,\r\n schema: jsonSchema\r\n });\r\n }\r\n if (value.unique) {\r\n throw newRxError('SC14', {\r\n value,\r\n schema: jsonSchema\r\n });\r\n }\r\n if (jsonSchema.encrypted && jsonSchema.encrypted.includes(key)) {\r\n throw newRxError('SC15', {\r\n value,\r\n schema: jsonSchema\r\n });\r\n }\r\n if (value.type !== 'string') {\r\n throw newRxError('SC16', {\r\n value,\r\n schema: jsonSchema\r\n });\r\n }\r\n }\r\n\r\n // check if RxDocument-property\r\n if (rxDocumentProperties().includes(key)) {\r\n throw newRxError('SC17', {\r\n key,\r\n schema: jsonSchema\r\n });\r\n }\r\n });\r\n\r\n // check format of jsonSchema.indexes\r\n if (jsonSchema.indexes) {\r\n // should be an array\r\n if (!isMaybeReadonlyArray(jsonSchema.indexes)) {\r\n throw newRxError('SC18', {\r\n indexes: jsonSchema.indexes,\r\n schema: jsonSchema\r\n });\r\n }\r\n\r\n jsonSchema.indexes.forEach(index => {\r\n // should contain strings or array of strings\r\n if (!(typeof index === 'string' || Array.isArray(index))) {\r\n throw newRxError('SC19', { index, schema: jsonSchema });\r\n }\r\n // if is a compound index it must contain strings\r\n if (Array.isArray(index)) {\r\n for (let i = 0; i < index.length; i += 1) {\r\n if (typeof index[i] !== 'string') {\r\n throw newRxError('SC20', { index, schema: jsonSchema });\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * To be able to craft custom indexable string with compound fields,\r\n * we need to know the maximum fieldlength of the fields values\r\n * when they are transformed to strings.\r\n * Therefore we need to enforce some properties inside of the schema.\r\n */\r\n const indexAsArray = isMaybeReadonlyArray(index) ? index : [index];\r\n indexAsArray.forEach(fieldName => {\r\n const schemaPart = getSchemaByObjectPath(\r\n jsonSchema,\r\n fieldName\r\n );\r\n\r\n\r\n const type: JsonSchemaTypes = schemaPart.type as any;\r\n switch (type) {\r\n case 'string':\r\n const maxLength = schemaPart.maxLength;\r\n if (!maxLength) {\r\n throw newRxError('SC34', {\r\n index,\r\n field: fieldName,\r\n schema: jsonSchema\r\n });\r\n }\r\n if (maxLength > 2048) {\r\n throw newRxError('SC42', {\r\n index,\r\n field: fieldName,\r\n schema: jsonSchema\r\n });\r\n }\r\n break;\r\n case 'number':\r\n case 'integer':\r\n const multipleOf = schemaPart.multipleOf;\r\n if (!multipleOf) {\r\n throw newRxError('SC35', {\r\n index,\r\n field: fieldName,\r\n schema: jsonSchema\r\n });\r\n }\r\n const maximum = schemaPart.maximum;\r\n const minimum = schemaPart.minimum;\r\n if (\r\n typeof maximum === 'undefined' ||\r\n typeof minimum === 'undefined'\r\n ) {\r\n throw newRxError('SC37', {\r\n index,\r\n field: fieldName,\r\n schema: jsonSchema\r\n });\r\n }\r\n\r\n if (\r\n !isFinite(maximum) ||\r\n !isFinite(minimum)\r\n ) {\r\n throw newRxError('SC41', {\r\n index,\r\n field: fieldName,\r\n schema: jsonSchema\r\n });\r\n }\r\n\r\n break;\r\n case 'boolean':\r\n /**\r\n * If a boolean field is used as an index,\r\n * it must be required.\r\n */\r\n let parentPath = '';\r\n let lastPathPart = fieldName;\r\n if (fieldName.includes('.')) {\r\n const partParts = fieldName.split('.');\r\n lastPathPart = partParts.pop();\r\n parentPath = partParts.join('.');\r\n }\r\n const parentSchemaPart = parentPath === '' ? jsonSchema : getSchemaByObjectPath(\r\n jsonSchema,\r\n parentPath\r\n );\r\n\r\n if (\r\n !parentSchemaPart.required ||\r\n !parentSchemaPart.required.includes(lastPathPart)\r\n ) {\r\n throw newRxError('SC38', {\r\n index,\r\n field: fieldName,\r\n schema: jsonSchema\r\n });\r\n }\r\n break;\r\n\r\n default:\r\n throw newRxError('SC36', {\r\n fieldName,\r\n type: schemaPart.type as any,\r\n schema: jsonSchema,\r\n });\r\n }\r\n });\r\n\r\n });\r\n }\r\n\r\n // remove backward-compatibility for index: true\r\n Object.keys(flattenObject(jsonSchema))\r\n .map(key => {\r\n // flattenObject returns only ending paths, we need all paths pointing to an object\r\n const split = key.split('.');\r\n split.pop(); // all but last\r\n return split.join('.');\r\n })\r\n .filter(key => key !== '')\r\n .filter((elem, pos, arr) => arr.indexOf(elem) === pos) // unique\r\n .filter(key => { // check if this path defines an index\r\n const value = getProperty(jsonSchema, key);\r\n return value && !!value.index;\r\n })\r\n .forEach(key => { // replace inner properties\r\n key = key.replace('properties.', ''); // first\r\n key = key.replace(/\\.properties\\./g, '.'); // middle\r\n throw newRxError('SC26', {\r\n index: trimDots(key),\r\n schema: jsonSchema\r\n });\r\n });\r\n\r\n /* check types of the indexes */\r\n (jsonSchema.indexes || [])\r\n .reduce((indexPaths: string[], currentIndex) => {\r\n if (isMaybeReadonlyArray(currentIndex)) {\r\n indexPaths = indexPaths.concat(currentIndex);\r\n } else {\r\n indexPaths.push(currentIndex);\r\n }\r\n return indexPaths;\r\n }, [])\r\n .filter((elem, pos, arr) => arr.indexOf(elem) === pos) // from now on working only with unique indexes\r\n .map(indexPath => {\r\n const realPath = getSchemaPropertyRealPath(indexPath); // real path in the collection schema\r\n const schemaObj = getProperty(jsonSchema, realPath); // get the schema of the indexed property\r\n if (!schemaObj || typeof schemaObj !== 'object') {\r\n throw newRxError('SC21', {\r\n index: indexPath,\r\n schema: jsonSchema\r\n });\r\n }\r\n return { indexPath, schemaObj };\r\n })\r\n .filter(index =>\r\n index.schemaObj.type !== 'string' &&\r\n index.schemaObj.type !== 'integer' &&\r\n index.schemaObj.type !== 'number' &&\r\n index.schemaObj.type !== 'boolean'\r\n )\r\n .forEach(index => {\r\n throw newRxError('SC22', {\r\n key: index.indexPath,\r\n type: index.schemaObj.type,\r\n schema: jsonSchema\r\n });\r\n });\r\n\r\n /* ensure encrypted fields exist in the schema */\r\n if (jsonSchema.encrypted) {\r\n jsonSchema.encrypted\r\n .forEach(propPath => {\r\n // real path in the collection schema\r\n const realPath = getSchemaPropertyRealPath(propPath);\r\n // get the schema of the indexed property\r\n const schemaObj = getProperty(jsonSchema, realPath);\r\n if (!schemaObj || typeof schemaObj !== 'object') {\r\n throw newRxError('SC28', {\r\n field: propPath,\r\n schema: jsonSchema\r\n });\r\n }\r\n });\r\n }\r\n}\r\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA,SACIA,UAAU,QACP,mBAAmB;AAC1B,SACIC,2BAA2B,EAC3BC,qBAAqB,QAClB,2BAA2B;AAQlC,SACIC,aAAa,EACbC,WAAW,EACXC,oBAAoB,EACpBC,QAAQ,QACL,8BAA8B;AACrC,SAASC,oBAAoB,QAAQ,wBAAwB;;AAE7D;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,mBAAmBA,CAACC,SAAiB,EAAE;EACnD,IAAIA,SAAS,KAAK,UAAU,EAAE;IAC1B;EACJ;EAEA,IAAI,CAAC,YAAY,CAAC,CAACC,QAAQ,CAACD,SAAS,CAAC,EAAE;IACpC,MAAMT,UAAU,CAAC,MAAM,EAAE;MACrBS;IACJ,CAAC,CAAC;EACN;EAEA,IAAME,QAAQ,GAAG,4CAA4C;EAC7D,IAAMC,KAAK,GAAG,IAAIC,MAAM,CAACF,QAAQ,CAAC;EAClC;EACI;AACR;AACA;AACA;AACA;EACQF,SAAS,KAAK,KAAK,IACnB,CAACA,SAAS,CAACK,KAAK,CAACF,KAAK,CAAC,EACzB;IACE,MAAMZ,UAAU,CAAC,KAAK,EAAE;MACpBY,KAAK,EAAED,QAAQ;MACfF;IACJ,CAAC,CAAC;EACN;AACJ;;AAEA;AACA;AACA;AACA,OAAO,SAASM,kBAAkBA,CAACC,YAA+B,EAAQ;EAEtE,IAAMC,WAAW,GAAGhB,2BAA2B,CAACe,YAAY,CAACE,UAAU,CAAC;EAExE,SAASC,UAAUA,CACfV,SAAiB,EACjBW,SAA0B,EAC1BC,IAAY,EACd;IACE,IACI,OAAOZ,SAAS,KAAK,QAAQ,IAC7B,OAAOW,SAAS,KAA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AACX,KAAK,IACTA,KAAK,CAACpD,SAAS,CAACU,IAAI,KAAK,QAAQ,IACjC0C,KAAK,CAACpD,SAAS,CAACU,IAAI,KAAK,SAAS,IAClC0C,KAAK,CAACpD,SAAS,CAACU,IAAI,KAAK,QAAQ,IACjC0C,KAAK,CAACpD,SAAS,CAACU,IAAI,KAAK,SAC7B,CAAC,CACAW,OAAO,CAAC+B,KAAK,IAAI;IACd,MAAMxE,UAAU,CAAC,MAAM,EAAE;MACrBmD,GAAG,EAAEqB,KAAK,CAACqB,SAAS;MACpB/D,IAAI,EAAE0C,KAAK,CAACpD,SAAS,CAACU,IAAI;MAC1BiB,MAAM,EAAED;IACZ,CAAC,CAAC;EACN,CAAC,CAAC;;EAEN;EACA,IAAIA,UAAU,CAACyB,SAAS,EAAE;IACtBzB,UAAU,CAACyB,SAAS,CACf9B,OAAO,CAACqD,QAAQ,IAAI;MACjB;MACA,IAAMhC,QAAQ,GAAGH,yBAAyB,CAACmC,QAAQ,CAAC;MACpD;MACA,IAAM1E,SAAS,GAAGhB,WAAW,CAAC0C,UAAU,EAAEgB,QAAQ,CAAC;MACnD,IAAI,CAAC1C,SAAS,IAAI,OAAOA,SAAS,KAAK,QAAQ,EAAE;QAC7C,MAAMpB,UAAU,CAAC,MAAM,EAAE;UACrBuD,KAAK,EAAEuC,QAAQ;UACf/C,MAAM,EAAED;QACZ,CAAC,CAAC;MACN;IACJ,CAAC,CAAC;EACV;AACJ","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"check-schema.js","names":["newRxError","getPrimaryFieldOfPrimaryKey","getSchemaByObjectPath","flattenObject","getProperty","isMaybeReadonlyArray","trimDots","rxDocumentProperties","checkFieldNameRegex","fieldName","includes","regexStr","regex","RegExp","match","validateFieldsDeep","rxJsonSchema","primaryPath","primaryKey","checkField","schemaObj","path","Array","isArray","split","pop","Object","prototype","hasOwnProperty","call","type","required","length","items","isNested","default","charAt","traverse","currentObj","currentPath","keys","forEach","attributeName","properties","nextPath","checkPrimaryKey","jsonSchema","schema","validatePrimarySchemaPart","schemaPart","args","key","compositePrimaryKey","keySchemaPart","fields","field","primaryPathSchemaPart","maxLength","isFinite","getSchemaPropertyRealPath","shortPath","pathParts","realPath","i","concat","checkSchema","_rev","version","value","indexes","unique","encrypted","index","indexAsArray","multipleOf","maximum","minimum","parentPath","lastPathPart","partParts","join","parentSchemaPart","map","filter","elem","pos","arr","indexOf","replace","reduce","indexPaths","currentIndex","push","indexPath","propPath"],"sources":["../../../../src/plugins/dev-mode/check-schema.ts"],"sourcesContent":["/**\r\n * does additional checks over the schema-json\r\n * to ensure nothing is broken or not supported\r\n */\r\nimport {\r\n newRxError\r\n} from '../../rx-error.ts';\r\nimport {\r\n getPrimaryFieldOfPrimaryKey,\r\n getSchemaByObjectPath\r\n} from '../../rx-schema-helper.ts';\r\nimport type {\r\n CompositePrimaryKey,\r\n JsonSchema,\r\n JsonSchemaTypes,\r\n RxJsonSchema,\r\n TopLevelProperty\r\n} from '../../types/index.d.ts';\r\nimport {\r\n flattenObject,\r\n getProperty,\r\n isMaybeReadonlyArray,\r\n trimDots\r\n} from '../../plugins/utils/index.ts';\r\nimport { rxDocumentProperties } from './entity-properties.ts';\r\n\r\n/**\r\n * checks if the fieldname is allowed\r\n * this makes sure that the fieldnames can be transformed into javascript-vars\r\n * and does not conquer the observe$ and populate_ fields\r\n * @throws {Error}\r\n */\r\nexport function checkFieldNameRegex(fieldName: string) {\r\n if (fieldName === '_deleted') {\r\n return;\r\n }\r\n\r\n if (['properties'].includes(fieldName)) {\r\n throw newRxError('SC23', {\r\n fieldName\r\n });\r\n }\r\n\r\n const regexStr = '^[a-zA-Z](?:[[a-zA-Z0-9_]*]?[a-zA-Z0-9])?$';\r\n const regex = new RegExp(regexStr);\r\n if (\r\n /**\r\n * It must be allowed to set _id as primaryKey.\r\n * This makes it sometimes easier to work with RxDB+CouchDB\r\n * @link https://github.com/pubkey/rxdb/issues/681\r\n */\r\n fieldName !== '_id' &&\r\n !fieldName.match(regex)\r\n ) {\r\n throw newRxError('SC1', {\r\n regex: regexStr,\r\n fieldName\r\n });\r\n }\r\n}\r\n\r\n/**\r\n * validate that all schema-related things are ok\r\n */\r\nexport function validateFieldsDeep(rxJsonSchema: RxJsonSchema<any>): true {\r\n\r\n const primaryPath = getPrimaryFieldOfPrimaryKey(rxJsonSchema.primaryKey);\r\n\r\n function checkField(\r\n fieldName: string,\r\n schemaObj: JsonSchema<any>,\r\n path: string\r\n ) {\r\n if (\r\n typeof fieldName === 'string' &&\r\n typeof schemaObj === 'object' &&\r\n !Array.isArray(schemaObj) &&\r\n path.split('.').pop() !== 'patternProperties'\r\n ) checkFieldNameRegex(fieldName);\r\n\r\n // 'item' only allowed it type=='array'\r\n if (Object.prototype.hasOwnProperty.call(schemaObj, 'item') && schemaObj.type !== 'array') {\r\n throw newRxError('SC2', {\r\n fieldName\r\n });\r\n }\r\n\r\n /**\r\n * required fields cannot be set via 'required: true',\r\n * but must be set via required: []\r\n */\r\n if (\r\n Object.prototype.hasOwnProperty.call(schemaObj, 'required') &&\r\n typeof schemaObj.required === 'boolean'\r\n ) {\r\n throw newRxError('SC24', {\r\n fieldName\r\n });\r\n }\r\n\r\n // $ref is not allowed\r\n if (Object.prototype.hasOwnProperty.call(schemaObj, '$ref')) {\r\n throw newRxError('SC40', {\r\n fieldName\r\n });\r\n }\r\n\r\n\r\n // if ref given, must be type=='string', type=='array' with string-items or type==['string','null']\r\n if (Object.prototype.hasOwnProperty.call(schemaObj, 'ref')) {\r\n if (Array.isArray(schemaObj.type)) {\r\n if (schemaObj.type.length > 2 || !schemaObj.type.includes('string') || !schemaObj.type.includes('null')) {\r\n throw newRxError('SC4', {\r\n fieldName\r\n });\r\n }\r\n } else {\r\n switch (schemaObj.type) {\r\n case 'string':\r\n break;\r\n case 'array':\r\n if (\r\n !schemaObj.items ||\r\n !(schemaObj.items as any).type ||\r\n (schemaObj.items as any).type !== 'string'\r\n ) {\r\n throw newRxError('SC3', {\r\n fieldName\r\n });\r\n }\r\n break;\r\n default:\r\n throw newRxError('SC4', {\r\n fieldName\r\n });\r\n }\r\n }\r\n }\r\n\r\n const isNested = path.split('.').length >= 2;\r\n\r\n // nested only\r\n if (isNested) {\r\n if ((schemaObj as any).default) {\r\n throw newRxError('SC7', {\r\n path\r\n });\r\n }\r\n }\r\n\r\n // first level\r\n if (!isNested) {\r\n\r\n // if _id is used, it must be primaryKey\r\n if (\r\n fieldName === '_id' &&\r\n primaryPath !== '_id'\r\n ) {\r\n throw newRxError('COL2', {\r\n fieldName\r\n });\r\n }\r\n\r\n // check underscore fields\r\n if (fieldName.charAt(0) === '_') {\r\n if (\r\n // exceptional allow underscore on these fields.\r\n fieldName === '_id' ||\r\n fieldName === '_deleted'\r\n ) {\r\n return;\r\n }\r\n throw newRxError('SC8', {\r\n fieldName\r\n });\r\n }\r\n }\r\n }\r\n\r\n function traverse(currentObj: any, currentPath: any) {\r\n if (!currentObj || typeof currentObj !== 'object') {\r\n return;\r\n }\r\n Object.keys(currentObj).forEach(attributeName => {\r\n const schemaObj = currentObj[attributeName];\r\n if (\r\n !currentObj.properties &&\r\n schemaObj &&\r\n typeof schemaObj === 'object' &&\r\n !Array.isArray(currentObj)\r\n ) {\r\n checkField(\r\n attributeName,\r\n schemaObj,\r\n currentPath\r\n );\r\n }\r\n let nextPath = currentPath;\r\n if (attributeName !== 'properties') nextPath = nextPath + '.' + attributeName;\r\n traverse(schemaObj, nextPath);\r\n });\r\n }\r\n traverse(rxJsonSchema, '');\r\n return true;\r\n}\r\n\r\nexport function checkPrimaryKey(\r\n jsonSchema: RxJsonSchema<any>\r\n) {\r\n if (!jsonSchema.primaryKey) {\r\n throw newRxError('SC30', { schema: jsonSchema });\r\n }\r\n\r\n\r\n\r\n function validatePrimarySchemaPart(\r\n schemaPart: JsonSchema | TopLevelProperty\r\n ) {\r\n if (!schemaPart) {\r\n throw newRxError('SC33', { schema: jsonSchema });\r\n }\r\n\r\n const type: string = schemaPart.type as any;\r\n if (\r\n !type ||\r\n !['string', 'number', 'integer'].includes(type)\r\n ) {\r\n throw newRxError('SC32', { schema: jsonSchema, args: { schemaPart } });\r\n }\r\n }\r\n\r\n if (typeof jsonSchema.primaryKey === 'string') {\r\n const key = jsonSchema.primaryKey;\r\n const schemaPart = jsonSchema.properties[key];\r\n validatePrimarySchemaPart(schemaPart);\r\n } else {\r\n const compositePrimaryKey: CompositePrimaryKey<any> = jsonSchema.primaryKey as any;\r\n\r\n const keySchemaPart = getSchemaByObjectPath(jsonSchema, compositePrimaryKey.key);\r\n validatePrimarySchemaPart(keySchemaPart);\r\n\r\n compositePrimaryKey.fields.forEach(field => {\r\n const schemaPart = getSchemaByObjectPath(jsonSchema, field);\r\n validatePrimarySchemaPart(schemaPart);\r\n });\r\n }\r\n\r\n\r\n /**\r\n * The primary key must have a maxLength set\r\n * which is required by some RxStorage implementations\r\n * to ensure we can craft custom index strings.\r\n */\r\n const primaryPath = getPrimaryFieldOfPrimaryKey(jsonSchema.primaryKey);\r\n const primaryPathSchemaPart = jsonSchema.properties[primaryPath];\r\n if (!primaryPathSchemaPart.maxLength) {\r\n throw newRxError('SC39', { schema: jsonSchema, args: { primaryPathSchemaPart } });\r\n } else if (!isFinite(primaryPathSchemaPart.maxLength)) {\r\n throw newRxError('SC41', { schema: jsonSchema, args: { primaryPathSchemaPart } });\r\n }\r\n}\r\n\r\n/**\r\n * computes real path of the object path in the collection schema\r\n */\r\nfunction getSchemaPropertyRealPath(shortPath: string) {\r\n const pathParts = shortPath.split('.');\r\n let realPath = '';\r\n for (let i = 0; i < pathParts.length; i += 1) {\r\n if (pathParts[i] !== '[]') {\r\n realPath = realPath.concat('.properties.'.concat(pathParts[i]));\r\n } else {\r\n realPath = realPath.concat('.items');\r\n }\r\n }\r\n return trimDots(realPath);\r\n}\r\n\r\n/**\r\n * does the checking\r\n * @throws {Error} if something is not ok\r\n */\r\nexport function checkSchema(jsonSchema: RxJsonSchema<any>) {\r\n\r\n if (!jsonSchema.primaryKey) {\r\n throw newRxError('SC30', {\r\n schema: jsonSchema\r\n });\r\n }\r\n\r\n if (!Object.prototype.hasOwnProperty.call(jsonSchema, 'properties')) {\r\n throw newRxError('SC29', {\r\n schema: jsonSchema\r\n });\r\n }\r\n\r\n // _rev MUST NOT exist, it is added by RxDB\r\n if (jsonSchema.properties._rev) {\r\n throw newRxError('SC10', {\r\n schema: jsonSchema\r\n });\r\n }\r\n\r\n // check version\r\n if (!Object.prototype.hasOwnProperty.call(jsonSchema, 'version') ||\r\n typeof jsonSchema.version !== 'number' ||\r\n jsonSchema.version < 0\r\n ) {\r\n throw newRxError('SC11', {\r\n version: jsonSchema.version\r\n });\r\n }\r\n\r\n validateFieldsDeep(jsonSchema);\r\n checkPrimaryKey(jsonSchema);\r\n\r\n const primaryPath = getPrimaryFieldOfPrimaryKey(jsonSchema.primaryKey);\r\n Object.keys(jsonSchema.properties).forEach(key => {\r\n const value: any = jsonSchema.properties[key];\r\n // check primary\r\n if (key === primaryPath) {\r\n if (jsonSchema.indexes && jsonSchema.indexes.includes(key)) {\r\n throw newRxError('SC13', {\r\n value,\r\n schema: jsonSchema\r\n });\r\n }\r\n if (value.unique) {\r\n throw newRxError('SC14', {\r\n value,\r\n schema: jsonSchema\r\n });\r\n }\r\n if (jsonSchema.encrypted && jsonSchema.encrypted.includes(key)) {\r\n throw newRxError('SC15', {\r\n value,\r\n schema: jsonSchema\r\n });\r\n }\r\n if (value.type !== 'string') {\r\n throw newRxError('SC16', {\r\n value,\r\n schema: jsonSchema\r\n });\r\n }\r\n }\r\n\r\n // check if RxDocument-property\r\n if (rxDocumentProperties().includes(key)) {\r\n throw newRxError('SC17', {\r\n key,\r\n schema: jsonSchema\r\n });\r\n }\r\n });\r\n\r\n // check format of jsonSchema.indexes\r\n if (jsonSchema.indexes) {\r\n // should be an array\r\n if (!isMaybeReadonlyArray(jsonSchema.indexes)) {\r\n throw newRxError('SC18', {\r\n indexes: jsonSchema.indexes,\r\n schema: jsonSchema\r\n });\r\n }\r\n\r\n jsonSchema.indexes.forEach(index => {\r\n // should contain strings or array of strings\r\n if (!(typeof index === 'string' || Array.isArray(index))) {\r\n throw newRxError('SC19', { index, schema: jsonSchema });\r\n }\r\n // if is a compound index it must contain strings\r\n if (Array.isArray(index)) {\r\n for (let i = 0; i < index.length; i += 1) {\r\n if (typeof index[i] !== 'string') {\r\n throw newRxError('SC20', { index, schema: jsonSchema });\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * To be able to craft custom indexable string with compound fields,\r\n * we need to know the maximum fieldlength of the fields values\r\n * when they are transformed to strings.\r\n * Therefore we need to enforce some properties inside of the schema.\r\n */\r\n const indexAsArray = isMaybeReadonlyArray(index) ? index : [index];\r\n indexAsArray.forEach(fieldName => {\r\n const schemaPart = getSchemaByObjectPath(\r\n jsonSchema,\r\n fieldName\r\n );\r\n\r\n\r\n const type: JsonSchemaTypes = schemaPart.type as any;\r\n switch (type) {\r\n case 'string':\r\n const maxLength = schemaPart.maxLength;\r\n if (!maxLength) {\r\n throw newRxError('SC34', {\r\n index,\r\n field: fieldName,\r\n schema: jsonSchema\r\n });\r\n }\r\n if (maxLength > 2048) {\r\n throw newRxError('SC42', {\r\n index,\r\n field: fieldName,\r\n schema: jsonSchema\r\n });\r\n }\r\n break;\r\n case 'number':\r\n case 'integer':\r\n const multipleOf = schemaPart.multipleOf;\r\n if (!multipleOf) {\r\n throw newRxError('SC35', {\r\n index,\r\n field: fieldName,\r\n schema: jsonSchema\r\n });\r\n }\r\n const maximum = schemaPart.maximum;\r\n const minimum = schemaPart.minimum;\r\n if (\r\n typeof maximum === 'undefined' ||\r\n typeof minimum === 'undefined'\r\n ) {\r\n throw newRxError('SC37', {\r\n index,\r\n field: fieldName,\r\n schema: jsonSchema\r\n });\r\n }\r\n\r\n if (\r\n !isFinite(maximum) ||\r\n !isFinite(minimum)\r\n ) {\r\n throw newRxError('SC41', {\r\n index,\r\n field: fieldName,\r\n schema: jsonSchema\r\n });\r\n }\r\n\r\n break;\r\n case 'boolean':\r\n /**\r\n * If a boolean field is used as an index,\r\n * it must be required.\r\n */\r\n let parentPath = '';\r\n let lastPathPart = fieldName;\r\n if (fieldName.includes('.')) {\r\n const partParts = fieldName.split('.');\r\n lastPathPart = partParts.pop();\r\n parentPath = partParts.join('.');\r\n }\r\n const parentSchemaPart = parentPath === '' ? jsonSchema : getSchemaByObjectPath(\r\n jsonSchema,\r\n parentPath\r\n );\r\n\r\n if (\r\n !parentSchemaPart.required ||\r\n !parentSchemaPart.required.includes(lastPathPart)\r\n ) {\r\n throw newRxError('SC38', {\r\n index,\r\n field: fieldName,\r\n schema: jsonSchema\r\n });\r\n }\r\n break;\r\n\r\n default:\r\n throw newRxError('SC36', {\r\n fieldName,\r\n type: schemaPart.type as any,\r\n schema: jsonSchema,\r\n });\r\n }\r\n });\r\n\r\n });\r\n }\r\n\r\n // remove backward-compatibility for index: true\r\n Object.keys(flattenObject(jsonSchema))\r\n .map(key => {\r\n // flattenObject returns only ending paths, we need all paths pointing to an object\r\n const split = key.split('.');\r\n split.pop(); // all but last\r\n return split.join('.');\r\n })\r\n .filter(key => key !== '')\r\n .filter((elem, pos, arr) => arr.indexOf(elem) === pos) // unique\r\n .filter(key => { // check if this path defines an index\r\n const value = getProperty(jsonSchema, key);\r\n return value && !!value.index;\r\n })\r\n .forEach(key => { // replace inner properties\r\n key = key.replace('properties.', ''); // first\r\n key = key.replace(/\\.properties\\./g, '.'); // middle\r\n throw newRxError('SC26', {\r\n index: trimDots(key),\r\n schema: jsonSchema\r\n });\r\n });\r\n\r\n /* check types of the indexes */\r\n (jsonSchema.indexes || [])\r\n .reduce((indexPaths: string[], currentIndex) => {\r\n if (isMaybeReadonlyArray(currentIndex)) {\r\n indexPaths = indexPaths.concat(currentIndex);\r\n } else {\r\n indexPaths.push(currentIndex);\r\n }\r\n return indexPaths;\r\n }, [])\r\n .filter((elem, pos, arr) => arr.indexOf(elem) === pos) // from now on working only with unique indexes\r\n .map(indexPath => {\r\n const realPath = getSchemaPropertyRealPath(indexPath); // real path in the collection schema\r\n const schemaObj = getProperty(jsonSchema, realPath); // get the schema of the indexed property\r\n if (!schemaObj || typeof schemaObj !== 'object') {\r\n throw newRxError('SC21', {\r\n index: indexPath,\r\n schema: jsonSchema\r\n });\r\n }\r\n return { indexPath, schemaObj };\r\n })\r\n .filter(index =>\r\n index.schemaObj.type !== 'string' &&\r\n index.schemaObj.type !== 'integer' &&\r\n index.schemaObj.type !== 'number' &&\r\n index.schemaObj.type !== 'boolean'\r\n )\r\n .forEach(index => {\r\n throw newRxError('SC22', {\r\n key: index.indexPath,\r\n type: index.schemaObj.type,\r\n schema: jsonSchema\r\n });\r\n });\r\n\r\n /* ensure encrypted fields exist in the schema */\r\n if (jsonSchema.encrypted) {\r\n jsonSchema.encrypted\r\n .forEach(propPath => {\r\n // real path in the collection schema\r\n const realPath = getSchemaPropertyRealPath(propPath);\r\n // get the schema of the indexed property\r\n const schemaObj = getProperty(jsonSchema, realPath);\r\n if (!schemaObj || typeof schemaObj !== 'object') {\r\n throw newRxError('SC28', {\r\n field: propPath,\r\n schema: jsonSchema\r\n });\r\n }\r\n });\r\n }\r\n}\r\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA,SACIA,UAAU,QACP,mBAAmB;AAC1B,SACIC,2BAA2B,EAC3BC,qBAAqB,QAClB,2BAA2B;AAQlC,SACIC,aAAa,EACbC,WAAW,EACXC,oBAAoB,EACpBC,QAAQ,QACL,8BAA8B;AACrC,SAASC,oBAAoB,QAAQ,wBAAwB;;AAE7D;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,mBAAmBA,CAACC,SAAiB,EAAE;EACnD,IAAIA,SAAS,KAAK,UAAU,EAAE;IAC1B;EACJ;EAEA,IAAI,CAAC,YAAY,CAAC,CAACC,QAAQ,CAACD,SAAS,CAAC,EAAE;IACpC,MAAMT,UAAU,CAAC,MAAM,EAAE;MACrBS;IACJ,CAAC,CAAC;EACN;EAEA,IAAME,QAAQ,GAAG,4CAA4C;EAC7D,I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AC0C,UAAU,EAAEgB,QAAQ,CAAC;MACnD,IAAI,CAAC1C,SAAS,IAAI,OAAOA,SAAS,KAAK,QAAQ,EAAE;QAC7C,MAAMpB,UAAU,CAAC,MAAM,EAAE;UACrBuD,KAAK,EAAEuC,QAAQ;UACf/C,MAAM,EAAED;QACZ,CAAC,CAAC;MACN;IACJ,CAAC,CAAC;EACV;AACJ","ignoreList":[]}
|
|
@@ -116,7 +116,7 @@ export var ERROR_MESSAGES = {
|
|
|
116
116
|
},
|
|
117
117
|
QU10: {
|
|
118
118
|
message: 'result empty and throwIfMissing: true',
|
|
119
|
-
cause: 'exec(true) was called but the document was not found.',
|
|
119
|
+
cause: 'exec(true) or remove(true) was called on a findOne() query but the document was not found.',
|
|
120
120
|
fix: 'Ensure the document exists or do not use the throwIfMissing flag.',
|
|
121
121
|
docs: ''
|
|
122
122
|
},
|
|
@@ -435,7 +435,7 @@ export var ERROR_MESSAGES = {
|
|
|
435
435
|
docs: 'https://rxdb.info/transactions-conflicts-revisions.html?console=errors&code=CONFLICT'
|
|
436
436
|
},
|
|
437
437
|
COL22: {
|
|
438
|
-
message: '.bulkInsert() and .bulkUpsert() cannot be run with multiple documents that have the same primary key',
|
|
438
|
+
message: '.bulkInsert() and .bulkUpsert() cannot be run with multiple documents that have the same primary key. Conflicting primary key(s) are in the error parameters (duplicateIds)',
|
|
439
439
|
cause: 'You provided multiple documents with the same primary key in a bulk write.',
|
|
440
440
|
fix: 'Ensure all documents in a bulk write have unique primary keys.',
|
|
441
441
|
docs: ''
|
|
@@ -673,6 +673,12 @@ export var ERROR_MESSAGES = {
|
|
|
673
673
|
fix: 'Check the password.',
|
|
674
674
|
docs: 'https://rxdb.info/encryption.html?console=errors&code=EN4'
|
|
675
675
|
},
|
|
676
|
+
EN5: {
|
|
677
|
+
message: 'Storage wrapper received a string instead of an array from the storage. This happens when a storage like OPFS is used inside of a worker and the usesRxDatabaseInWorker option is not set.',
|
|
678
|
+
cause: 'Some RxStorage implementations (like OPFS) return JSON strings instead of arrays for performance. When you wrap such a storage with encryption (or other plugins) inside of a worker, the wrapper receives the raw string and cannot process it.',
|
|
679
|
+
fix: 'Set usesRxDatabaseInWorker: true in your storage options. For example: getRxStorageOPFS({ usesRxDatabaseInWorker: true }).',
|
|
680
|
+
docs: 'https://rxdb.info/encryption.html?console=errors&code=EN5'
|
|
681
|
+
},
|
|
676
682
|
// plugins/json-dump.js
|
|
677
683
|
JD1: {
|
|
678
684
|
message: 'You must create the collections before you can import their data',
|
|
@@ -1133,6 +1139,12 @@ export var ERROR_MESSAGES = {
|
|
|
1133
1139
|
fix: 'Remove the custom conflict handler.',
|
|
1134
1140
|
docs: 'https://rxdb.info/crdt.html?console=errors&code=CRDT3'
|
|
1135
1141
|
},
|
|
1142
|
+
CRDT4: {
|
|
1143
|
+
message: 'RxDocument.modify() cannot be used when CRDTs are activated.',
|
|
1144
|
+
cause: 'modify() takes an arbitrary function that cannot be converted to a CRDT operation.',
|
|
1145
|
+
fix: 'Use updateCRDT() instead of modify().',
|
|
1146
|
+
docs: 'https://rxdb.info/crdt.html?console=errors&code=CRDT4'
|
|
1147
|
+
},
|
|
1136
1148
|
// plugins/storage-dexie/
|
|
1137
1149
|
DXE1: {
|
|
1138
1150
|
message: 'non-required index fields are not possible with the dexie.js RxStorage: https://github.com/pubkey/rxdb/pull/6643#issuecomment-2505310082',
|
|
@@ -1231,6 +1243,12 @@ export var ERROR_MESSAGES = {
|
|
|
1231
1243
|
fix: 'Try to reproduce the error in a unit test and make a PR with a test case.',
|
|
1232
1244
|
docs: 'https://rxdb.info/replication-google-drive.html?console=errors&code=GDR19'
|
|
1233
1245
|
},
|
|
1246
|
+
GDR20: {
|
|
1247
|
+
message: 'Document file update conflict',
|
|
1248
|
+
cause: 'Another client modified the document file during the transaction. This indicates a transaction timeout overlap.',
|
|
1249
|
+
fix: 'Increase the transactionTimeout or investigate why two clients are writing to the same document concurrently.',
|
|
1250
|
+
docs: 'https://rxdb.info/replication-google-drive.html?console=errors&code=GDR20'
|
|
1251
|
+
},
|
|
1234
1252
|
// plugins/replication-microsoft-onedrive
|
|
1235
1253
|
ODR1: {
|
|
1236
1254
|
message: 'Microsoft OneDrive: folderPath must not be the root folder or undefined',
|
|
@@ -1274,6 +1292,26 @@ export var ERROR_MESSAGES = {
|
|
|
1274
1292
|
fix: 'Check the network connection and the server logs.',
|
|
1275
1293
|
docs: ''
|
|
1276
1294
|
},
|
|
1295
|
+
// custom-index errors
|
|
1296
|
+
CI1: {
|
|
1297
|
+
message: 'Field not in schema',
|
|
1298
|
+
cause: 'The given field is not defined in the RxJsonSchema.',
|
|
1299
|
+
fix: 'Make sure the field name is spelled correctly and exists in the schema.',
|
|
1300
|
+
docs: ''
|
|
1301
|
+
},
|
|
1302
|
+
CI2: {
|
|
1303
|
+
message: 'Unknown index type',
|
|
1304
|
+
cause: 'The schema field type is not supported for indexing.',
|
|
1305
|
+
fix: 'Use a supported type (string, boolean, number, integer) for the indexed field.',
|
|
1306
|
+
docs: ''
|
|
1307
|
+
},
|
|
1308
|
+
// change-event-buffer errors
|
|
1309
|
+
COB1: {
|
|
1310
|
+
message: 'ChangeEventBuffer out of bounds',
|
|
1311
|
+
cause: 'The requested pointer is out of the change event buffer bounds.',
|
|
1312
|
+
fix: 'This means something in RxDB itself behaves wrong because any access to the api should not make an out of bounds request.',
|
|
1313
|
+
docs: ''
|
|
1314
|
+
},
|
|
1277
1315
|
/**
|
|
1278
1316
|
* Should never be thrown, use this for
|
|
1279
1317
|
* null checks etc. so you do not have to increase the
|
|
@@ -1281,9 +1319,9 @@ export var ERROR_MESSAGES = {
|
|
|
1281
1319
|
*/
|
|
1282
1320
|
SNH: {
|
|
1283
1321
|
message: 'This should never happen',
|
|
1284
|
-
cause: '',
|
|
1285
|
-
fix: '',
|
|
1286
|
-
docs: ''
|
|
1322
|
+
cause: 'Should never be thrown. This error code is used for internal things like null-checks etc.',
|
|
1323
|
+
fix: 'If this throws, you likely found a bug and should make a PR with a test case to the RxDB repo, so we can reproduce it.',
|
|
1324
|
+
docs: 'https://rxdb.info/contribution.html'
|
|
1287
1325
|
}
|
|
1288
1326
|
};
|
|
1289
1327
|
//# sourceMappingURL=error-messages.js.map
|