@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
|
@@ -247,7 +247,7 @@ function fillWithDefaultSettings(schemaObj) {
|
|
|
247
247
|
|
|
248
248
|
// make indexes unique
|
|
249
249
|
var hasIndex = new Set();
|
|
250
|
-
useIndexes.filter(index => {
|
|
250
|
+
schemaObj.indexes = useIndexes.filter(index => {
|
|
251
251
|
var indexStr = index.join(',');
|
|
252
252
|
if (hasIndex.has(indexStr)) {
|
|
253
253
|
return false;
|
|
@@ -256,7 +256,6 @@ function fillWithDefaultSettings(schemaObj) {
|
|
|
256
256
|
return true;
|
|
257
257
|
}
|
|
258
258
|
});
|
|
259
|
-
schemaObj.indexes = useIndexes;
|
|
260
259
|
return schemaObj;
|
|
261
260
|
}
|
|
262
261
|
var META_LWT_UNIX_TIME_MAX = exports.META_LWT_UNIX_TIME_MAX = 1000000000000000;
|
|
@@ -312,7 +311,14 @@ function fillObjectWithDefaults(rxSchema, obj) {
|
|
|
312
311
|
for (var i = 0; i < defaultKeys.length; ++i) {
|
|
313
312
|
var key = defaultKeys[i];
|
|
314
313
|
if (obj[key] === undefined) {
|
|
315
|
-
|
|
314
|
+
var val = rxSchema.defaultValues[key];
|
|
315
|
+
if (typeof val === 'object' && val !== null) {
|
|
316
|
+
obj[key] = Array.isArray(val) ? val.slice() : {
|
|
317
|
+
...val
|
|
318
|
+
};
|
|
319
|
+
} else {
|
|
320
|
+
obj[key] = val;
|
|
321
|
+
}
|
|
316
322
|
}
|
|
317
323
|
}
|
|
318
324
|
return obj;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rx-schema-helper.js","names":["_rxError","require","_index","getPseudoSchemaForVersion","version","primaryKey","pseudoSchema","fillWithDefaultSettings","type","properties","maxLength","value","indexes","required","SCHEMA_PATH_CACHE","WeakMap","getSchemaByObjectPath","rxJsonSchema","path","pathCache","get","pathStr","cached","Map","set","usePath","replace","REGEX_ALL_DOTS","trimDots","ret","getProperty","fillPrimaryKey","primaryPath","jsonSchema","documentData","newPrimary","getComposedPrimaryKeyOfDocumentData","existingPrimary","newRxError","args","schema","getPrimaryFieldOfPrimaryKey","key","getLengthOfPrimaryKey","schemaPart","ensureNotFalsy","compositePrimary","fields","map","field","join","separator","normalizeRxJsonSchema","normalizedSchema","sortObject","getDefaultIndex","schemaObj","flatClone","additionalProperties","Object","prototype","hasOwnProperty","call","keyCompression","slice","encrypted","_rev","minLength","_attachments","_deleted","_meta","RX_META_SCHEMA","push","filter","includes","elem","pos","arr","indexOf","useIndexes","index","arIndex","isMaybeReadonlyArray","unshift","length","internalIndexes","idx","hasIndex","Set","indexStr","has","add","META_LWT_UNIX_TIME_MAX","exports","lwt","minimum","RX_META_LWT_MINIMUM","maximum","multipleOf","getFinalFields","keys","final","forEach","fillObjectWithDefaults","rxSchema","obj","defaultKeys","defaultValues","i","undefined","DEFAULT_CHECKPOINT_SCHEMA","id"],"sources":["../../src/rx-schema-helper.ts"],"sourcesContent":["import { newRxError } from './rx-error.ts';\r\nimport type {\r\n CompositePrimaryKey,\r\n DeepReadonly,\r\n JsonSchema,\r\n PrimaryKey,\r\n RxDocumentData,\r\n RxJsonSchema,\r\n RxStorageDefaultCheckpoint,\r\n StringKeys\r\n} from './types/index.d.ts';\r\nimport {\r\n ensureNotFalsy,\r\n flatClone,\r\n getProperty,\r\n isMaybeReadonlyArray,\r\n REGEX_ALL_DOTS,\r\n RX_META_LWT_MINIMUM,\r\n sortObject,\r\n trimDots\r\n} from './plugins/utils/index.ts';\r\nimport type { RxSchema } from './rx-schema.ts';\r\n\r\n/**\r\n * Helper function to create a valid RxJsonSchema\r\n * with a given version.\r\n */\r\nexport function getPseudoSchemaForVersion<T = any>(\r\n version: number,\r\n primaryKey: StringKeys<T>\r\n): RxJsonSchema<RxDocumentData<T>> {\r\n const pseudoSchema: RxJsonSchema<RxDocumentData<T>> = fillWithDefaultSettings({\r\n version,\r\n type: 'object',\r\n primaryKey: primaryKey as any,\r\n properties: {\r\n [primaryKey]: {\r\n type: 'string',\r\n maxLength: 100\r\n },\r\n value: {\r\n type: 'string'\r\n }\r\n } as any,\r\n indexes: [\r\n [primaryKey]\r\n ],\r\n required: [primaryKey]\r\n });\r\n return pseudoSchema;\r\n}\r\n\r\n/**\r\n * Cache for getSchemaByObjectPath results.\r\n * Uses a WeakMap keyed by the schema object reference\r\n * so the cache is automatically cleaned up when schemas are garbage collected.\r\n */\r\nconst SCHEMA_PATH_CACHE = new WeakMap<object, Map<string, JsonSchema>>();\r\n\r\n/**\r\n * Returns the sub-schema for a given path.\r\n * Results are cached per schema reference and path\r\n * to avoid redundant string operations and property lookups.\r\n */\r\nexport function getSchemaByObjectPath<T = any>(\r\n rxJsonSchema: RxJsonSchema<T>,\r\n path: keyof T | string\r\n): JsonSchema {\r\n let pathCache = SCHEMA_PATH_CACHE.get(rxJsonSchema as any);\r\n const pathStr = path as string;\r\n if (pathCache) {\r\n const cached = pathCache.get(pathStr);\r\n if (cached) {\r\n return cached;\r\n }\r\n } else {\r\n pathCache = new Map();\r\n SCHEMA_PATH_CACHE.set(rxJsonSchema as any, pathCache);\r\n }\r\n\r\n let usePath: string = pathStr;\r\n usePath = usePath.replace(REGEX_ALL_DOTS, '.properties.');\r\n usePath = 'properties.' + usePath;\r\n usePath = trimDots(usePath);\r\n\r\n const ret = getProperty(rxJsonSchema, usePath);\r\n pathCache.set(pathStr, ret);\r\n return ret;\r\n}\r\n\r\nexport function fillPrimaryKey<T>(\r\n primaryPath: keyof T,\r\n jsonSchema: RxJsonSchema<T>,\r\n documentData: RxDocumentData<T>\r\n): RxDocumentData<T> {\r\n // optimization shortcut.\r\n if (typeof jsonSchema.primaryKey === 'string') {\r\n return documentData;\r\n }\r\n\r\n const newPrimary = getComposedPrimaryKeyOfDocumentData<T>(\r\n jsonSchema,\r\n documentData\r\n );\r\n const existingPrimary: string | undefined = documentData[primaryPath] as any;\r\n if (\r\n existingPrimary &&\r\n existingPrimary !== newPrimary\r\n ) {\r\n throw newRxError(\r\n 'DOC19',\r\n {\r\n args: {\r\n documentData,\r\n existingPrimary,\r\n newPrimary,\r\n },\r\n schema: jsonSchema\r\n });\r\n }\r\n\r\n (documentData as any)[primaryPath] = newPrimary;\r\n return documentData;\r\n}\r\n\r\nexport function getPrimaryFieldOfPrimaryKey<RxDocType>(\r\n primaryKey: PrimaryKey<RxDocType>\r\n): StringKeys<RxDocType> {\r\n if (typeof primaryKey === 'string') {\r\n return primaryKey as any;\r\n } else {\r\n return (primaryKey as CompositePrimaryKey<RxDocType>).key;\r\n }\r\n}\r\n\r\nexport function getLengthOfPrimaryKey<RxDocType>(\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>\r\n): number {\r\n const primaryPath = getPrimaryFieldOfPrimaryKey(schema.primaryKey);\r\n const schemaPart = getSchemaByObjectPath(schema, primaryPath);\r\n return ensureNotFalsy(schemaPart.maxLength);\r\n}\r\n\r\n/**\r\n * Returns the composed primaryKey of a document by its data.\r\n */\r\nexport function getComposedPrimaryKeyOfDocumentData<RxDocType>(\r\n jsonSchema: RxJsonSchema<RxDocType> | RxJsonSchema<RxDocumentData<RxDocType>>,\r\n documentData: Partial<RxDocType>\r\n): string {\r\n if (typeof jsonSchema.primaryKey === 'string') {\r\n return (documentData as any)[jsonSchema.primaryKey];\r\n }\r\n\r\n const compositePrimary: CompositePrimaryKey<RxDocType> = jsonSchema.primaryKey as any;\r\n return compositePrimary.fields.map(field => {\r\n const value = getProperty(documentData as any, field as string);\r\n if (typeof value === 'undefined') {\r\n throw newRxError('DOC18', { args: { field, documentData } });\r\n }\r\n return value;\r\n }).join(compositePrimary.separator);\r\n}\r\n\r\n\r\n/**\r\n * Normalize the RxJsonSchema.\r\n * We need this to ensure everything is set up properly\r\n * and we have the same hash on schemas that represent the same value but\r\n * have different json.\r\n *\r\n * - Orders the schemas attributes by alphabetical order\r\n * - Adds the primaryKey to all indexes that do not contain the primaryKey\r\n * - We need this for deterministic sort order on all queries, which is required for event-reduce to work.\r\n *\r\n * @return RxJsonSchema - ordered and filled\r\n */\r\nexport function normalizeRxJsonSchema<T>(jsonSchema: RxJsonSchema<T>): RxJsonSchema<T> {\r\n const normalizedSchema: RxJsonSchema<T> = sortObject(jsonSchema, true);\r\n return normalizedSchema;\r\n}\r\n\r\n/**\r\n * If the schema does not specify any index,\r\n * we add this index so we at least can run RxQuery()\r\n * and only select non-deleted fields.\r\n */\r\nexport function getDefaultIndex(primaryPath: string) {\r\n return ['_deleted', primaryPath];\r\n}\r\n\r\n/**\r\n * fills the schema-json with default-settings\r\n * @return cloned schemaObj\r\n */\r\nexport function fillWithDefaultSettings<T = any>(\r\n schemaObj: RxJsonSchema<T>\r\n): RxJsonSchema<RxDocumentData<T>> {\r\n schemaObj = flatClone(schemaObj);\r\n const primaryPath: string = getPrimaryFieldOfPrimaryKey(schemaObj.primaryKey);\r\n schemaObj.properties = flatClone(schemaObj.properties);\r\n\r\n // additionalProperties is always false\r\n schemaObj.additionalProperties = false;\r\n\r\n // fill with key-compression-state ()\r\n if (!Object.prototype.hasOwnProperty.call(schemaObj, 'keyCompression')) {\r\n schemaObj.keyCompression = false;\r\n }\r\n\r\n // indexes must be array\r\n schemaObj.indexes = schemaObj.indexes ? schemaObj.indexes.slice(0) : [];\r\n\r\n // required must be array\r\n schemaObj.required = schemaObj.required ? schemaObj.required.slice(0) : [];\r\n\r\n // encrypted must be array\r\n schemaObj.encrypted = schemaObj.encrypted ? schemaObj.encrypted.slice(0) : [];\r\n\r\n // add _rev\r\n (schemaObj.properties as any)._rev = {\r\n type: 'string',\r\n minLength: 1\r\n };\r\n\r\n // add attachments\r\n (schemaObj.properties as any)._attachments = {\r\n type: 'object'\r\n };\r\n\r\n // add deleted flag\r\n (schemaObj.properties as any)._deleted = {\r\n type: 'boolean'\r\n };\r\n\r\n // add meta property\r\n (schemaObj.properties as any)._meta = RX_META_SCHEMA;\r\n\r\n /**\r\n * meta fields are all required\r\n */\r\n schemaObj.required = schemaObj.required ? schemaObj.required.slice(0) : [];\r\n (schemaObj.required as string[]).push('_deleted');\r\n (schemaObj.required as string[]).push('_rev');\r\n (schemaObj.required as string[]).push('_meta');\r\n (schemaObj.required as string[]).push('_attachments');\r\n\r\n // primaryKey is always required\r\n (schemaObj.required as any).push(primaryPath);\r\n\r\n schemaObj.required = schemaObj.required\r\n .filter((field: string) => !field.includes('.'))\r\n .filter((elem: any, pos: any, arr: any) => arr.indexOf(elem) === pos); // unique;\r\n\r\n\r\n // version is 0 by default\r\n schemaObj.version = schemaObj.version || 0;\r\n\r\n const useIndexes: string[][] = schemaObj.indexes.map(index => {\r\n const arIndex = isMaybeReadonlyArray(index) ? index.slice(0) : [index];\r\n /**\r\n * Append primary key to indexes that do not contain the primaryKey.\r\n * All indexes must have the primaryKey to ensure a deterministic sort order.\r\n */\r\n if (!arIndex.includes(primaryPath)) {\r\n arIndex.push(primaryPath);\r\n }\r\n\r\n // add _deleted flag to all indexes so we can query only non-deleted fields\r\n // in RxDB itself\r\n if (arIndex[0] !== '_deleted') {\r\n arIndex.unshift('_deleted');\r\n }\r\n\r\n return arIndex;\r\n });\r\n\r\n if (useIndexes.length === 0) {\r\n useIndexes.push(getDefaultIndex(primaryPath));\r\n }\r\n\r\n // we need this index for the getChangedDocumentsSince() method\r\n useIndexes.push(['_meta.lwt', primaryPath]);\r\n\r\n // also add the internalIndexes\r\n if (schemaObj.internalIndexes) {\r\n schemaObj.internalIndexes.map(idx => {\r\n useIndexes.push(idx);\r\n });\r\n }\r\n\r\n // make indexes unique\r\n const hasIndex = new Set<string>();\r\n useIndexes.filter(index => {\r\n const indexStr = index.join(',');\r\n if (hasIndex.has(indexStr)) {\r\n return false;\r\n } else {\r\n hasIndex.add(indexStr);\r\n return true;\r\n }\r\n });\r\n\r\n schemaObj.indexes = useIndexes;\r\n\r\n return schemaObj as any;\r\n}\r\n\r\nexport const META_LWT_UNIX_TIME_MAX = 1000000000000000;\r\nexport const RX_META_SCHEMA: JsonSchema = {\r\n type: 'object',\r\n properties: {\r\n /**\r\n * The last-write time.\r\n * Unix time in milliseconds.\r\n */\r\n lwt: {\r\n type: 'number',\r\n /**\r\n * We use 1 as minimum so that the value is never falsy.\r\n */\r\n minimum: RX_META_LWT_MINIMUM,\r\n maximum: META_LWT_UNIX_TIME_MAX,\r\n multipleOf: 0.01\r\n }\r\n },\r\n /**\r\n * Additional properties are allowed\r\n * and can be used by plugins to set various flags.\r\n */\r\n additionalProperties: true as any,\r\n required: [\r\n 'lwt'\r\n ]\r\n};\r\n\r\n\r\n/**\r\n * returns the final-fields of the schema\r\n * @return field-names of the final-fields\r\n */\r\nexport function getFinalFields<T = any>(\r\n jsonSchema: RxJsonSchema<T>\r\n): string[] {\r\n const ret = Object.keys(jsonSchema.properties)\r\n .filter(key => (jsonSchema as any).properties[key].final);\r\n\r\n // primary is also final\r\n const primaryPath = getPrimaryFieldOfPrimaryKey(jsonSchema.primaryKey);\r\n ret.push(primaryPath);\r\n\r\n // fields of composite primary are final\r\n if (typeof jsonSchema.primaryKey !== 'string') {\r\n (jsonSchema.primaryKey as CompositePrimaryKey<T>).fields\r\n .forEach(field => ret.push(field as string));\r\n }\r\n\r\n return ret;\r\n}\r\n\r\n/**\r\n * fills all unset fields with default-values if set\r\n * @hotPath\r\n */\r\nexport function fillObjectWithDefaults(rxSchema: RxSchema<any>, obj: any): any {\r\n const defaultKeys = Object.keys(rxSchema.defaultValues);\r\n for (let i = 0; i < defaultKeys.length; ++i) {\r\n const key = defaultKeys[i];\r\n if (obj[key] === undefined) {\r\n obj[key] = rxSchema.defaultValues[key];\r\n }\r\n }\r\n return obj;\r\n}\r\n\r\nexport const DEFAULT_CHECKPOINT_SCHEMA: DeepReadonly<JsonSchema<RxStorageDefaultCheckpoint>> = {\r\n type: 'object',\r\n properties: {\r\n id: {\r\n type: 'string'\r\n },\r\n lwt: {\r\n type: 'number'\r\n }\r\n },\r\n required: [\r\n 'id',\r\n 'lwt'\r\n ],\r\n additionalProperties: false\r\n} as const;\r\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAWA,IAAAC,MAAA,GAAAD,OAAA;AAYA;AACA;AACA;AACA;AACO,SAASE,yBAAyBA,CACrCC,OAAe,EACfC,UAAyB,EACM;EAC/B,IAAMC,YAA6C,GAAGC,uBAAuB,CAAC;IAC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rD,KAAK,IAAIpB,GAAG,CAAC2C,IAAI,CAACvB,KAAe,CAAC,CAAC;EACpD;EAEA,OAAOpB,GAAG;AACd;;AAEA;AACA;AACA;AACA;AACO,SAAS0E,sBAAsBA,CAACC,QAAuB,EAAEC,GAAQ,EAAO;EAC3E,IAAMC,WAAW,GAAG/C,MAAM,CAACyC,IAAI,CAACI,QAAQ,CAACG,aAAa,CAAC;EACvD,KAAK,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGF,WAAW,CAACtB,MAAM,EAAE,EAAEwB,CAAC,EAAE;IACzC,IAAMlE,GAAG,GAAGgE,WAAW,CAACE,CAAC,CAAC;IAC1B,IAAIH,GAAG,CAAC/D,GAAG,CAAC,KAAKmE,SAAS,EAAE;MACxBJ,GAAG,CAAC/D,GAAG,CAAC,GAAG8D,QAAQ,CAACG,aAAa,CAACjE,GAAG,CAAC;IAC1C;EACJ;EACA,OAAO+D,GAAG;AACd;AAEO,IAAMK,yBAA+E,GAAAjB,OAAA,CAAAiB,yBAAA,GAAG;EAC3FtG,IAAI,EAAE,QAAQ;EACdC,UAAU,EAAE;IACRsG,EAAE,EAAE;MACAvG,IAAI,EAAE;IACV,CAAC;IACDsF,GAAG,EAAE;MACDtF,IAAI,EAAE;IACV;EACJ,CAAC;EACDK,QAAQ,EAAE,CACN,IAAI,EACJ,KAAK,CACR;EACD6C,oBAAoB,EAAE;AAC1B,CAAU","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"rx-schema-helper.js","names":["_rxError","require","_index","getPseudoSchemaForVersion","version","primaryKey","pseudoSchema","fillWithDefaultSettings","type","properties","maxLength","value","indexes","required","SCHEMA_PATH_CACHE","WeakMap","getSchemaByObjectPath","rxJsonSchema","path","pathCache","get","pathStr","cached","Map","set","usePath","replace","REGEX_ALL_DOTS","trimDots","ret","getProperty","fillPrimaryKey","primaryPath","jsonSchema","documentData","newPrimary","getComposedPrimaryKeyOfDocumentData","existingPrimary","newRxError","args","schema","getPrimaryFieldOfPrimaryKey","key","getLengthOfPrimaryKey","schemaPart","ensureNotFalsy","compositePrimary","fields","map","field","join","separator","normalizeRxJsonSchema","normalizedSchema","sortObject","getDefaultIndex","schemaObj","flatClone","additionalProperties","Object","prototype","hasOwnProperty","call","keyCompression","slice","encrypted","_rev","minLength","_attachments","_deleted","_meta","RX_META_SCHEMA","push","filter","includes","elem","pos","arr","indexOf","useIndexes","index","arIndex","isMaybeReadonlyArray","unshift","length","internalIndexes","idx","hasIndex","Set","indexStr","has","add","META_LWT_UNIX_TIME_MAX","exports","lwt","minimum","RX_META_LWT_MINIMUM","maximum","multipleOf","getFinalFields","keys","final","forEach","fillObjectWithDefaults","rxSchema","obj","defaultKeys","defaultValues","i","undefined","val","Array","isArray","DEFAULT_CHECKPOINT_SCHEMA","id"],"sources":["../../src/rx-schema-helper.ts"],"sourcesContent":["import { newRxError } from './rx-error.ts';\r\nimport type {\r\n CompositePrimaryKey,\r\n DeepReadonly,\r\n JsonSchema,\r\n PrimaryKey,\r\n RxDocumentData,\r\n RxJsonSchema,\r\n RxStorageDefaultCheckpoint,\r\n StringKeys\r\n} from './types/index.d.ts';\r\nimport {\r\n ensureNotFalsy,\r\n flatClone,\r\n getProperty,\r\n isMaybeReadonlyArray,\r\n REGEX_ALL_DOTS,\r\n RX_META_LWT_MINIMUM,\r\n sortObject,\r\n trimDots\r\n} from './plugins/utils/index.ts';\r\nimport type { RxSchema } from './rx-schema.ts';\r\n\r\n/**\r\n * Helper function to create a valid RxJsonSchema\r\n * with a given version.\r\n */\r\nexport function getPseudoSchemaForVersion<T = any>(\r\n version: number,\r\n primaryKey: StringKeys<T>\r\n): RxJsonSchema<RxDocumentData<T>> {\r\n const pseudoSchema: RxJsonSchema<RxDocumentData<T>> = fillWithDefaultSettings({\r\n version,\r\n type: 'object',\r\n primaryKey: primaryKey as any,\r\n properties: {\r\n [primaryKey]: {\r\n type: 'string',\r\n maxLength: 100\r\n },\r\n value: {\r\n type: 'string'\r\n }\r\n } as any,\r\n indexes: [\r\n [primaryKey]\r\n ],\r\n required: [primaryKey]\r\n });\r\n return pseudoSchema;\r\n}\r\n\r\n/**\r\n * Cache for getSchemaByObjectPath results.\r\n * Uses a WeakMap keyed by the schema object reference\r\n * so the cache is automatically cleaned up when schemas are garbage collected.\r\n */\r\nconst SCHEMA_PATH_CACHE = new WeakMap<object, Map<string, JsonSchema>>();\r\n\r\n/**\r\n * Returns the sub-schema for a given path.\r\n * Results are cached per schema reference and path\r\n * to avoid redundant string operations and property lookups.\r\n */\r\nexport function getSchemaByObjectPath<T = any>(\r\n rxJsonSchema: RxJsonSchema<T>,\r\n path: keyof T | string\r\n): JsonSchema {\r\n let pathCache = SCHEMA_PATH_CACHE.get(rxJsonSchema as any);\r\n const pathStr = path as string;\r\n if (pathCache) {\r\n const cached = pathCache.get(pathStr);\r\n if (cached) {\r\n return cached;\r\n }\r\n } else {\r\n pathCache = new Map();\r\n SCHEMA_PATH_CACHE.set(rxJsonSchema as any, pathCache);\r\n }\r\n\r\n let usePath: string = pathStr;\r\n usePath = usePath.replace(REGEX_ALL_DOTS, '.properties.');\r\n usePath = 'properties.' + usePath;\r\n usePath = trimDots(usePath);\r\n\r\n const ret = getProperty(rxJsonSchema, usePath);\r\n pathCache.set(pathStr, ret);\r\n return ret;\r\n}\r\n\r\nexport function fillPrimaryKey<T>(\r\n primaryPath: keyof T,\r\n jsonSchema: RxJsonSchema<T>,\r\n documentData: RxDocumentData<T>\r\n): RxDocumentData<T> {\r\n // optimization shortcut.\r\n if (typeof jsonSchema.primaryKey === 'string') {\r\n return documentData;\r\n }\r\n\r\n const newPrimary = getComposedPrimaryKeyOfDocumentData<T>(\r\n jsonSchema,\r\n documentData\r\n );\r\n const existingPrimary: string | undefined = documentData[primaryPath] as any;\r\n if (\r\n existingPrimary &&\r\n existingPrimary !== newPrimary\r\n ) {\r\n throw newRxError(\r\n 'DOC19',\r\n {\r\n args: {\r\n documentData,\r\n existingPrimary,\r\n newPrimary,\r\n },\r\n schema: jsonSchema\r\n });\r\n }\r\n\r\n (documentData as any)[primaryPath] = newPrimary;\r\n return documentData;\r\n}\r\n\r\nexport function getPrimaryFieldOfPrimaryKey<RxDocType>(\r\n primaryKey: PrimaryKey<RxDocType>\r\n): StringKeys<RxDocType> {\r\n if (typeof primaryKey === 'string') {\r\n return primaryKey as any;\r\n } else {\r\n return (primaryKey as CompositePrimaryKey<RxDocType>).key;\r\n }\r\n}\r\n\r\nexport function getLengthOfPrimaryKey<RxDocType>(\r\n schema: RxJsonSchema<RxDocumentData<RxDocType>>\r\n): number {\r\n const primaryPath = getPrimaryFieldOfPrimaryKey(schema.primaryKey);\r\n const schemaPart = getSchemaByObjectPath(schema, primaryPath);\r\n return ensureNotFalsy(schemaPart.maxLength);\r\n}\r\n\r\n/**\r\n * Returns the composed primaryKey of a document by its data.\r\n */\r\nexport function getComposedPrimaryKeyOfDocumentData<RxDocType>(\r\n jsonSchema: RxJsonSchema<RxDocType> | RxJsonSchema<RxDocumentData<RxDocType>>,\r\n documentData: Partial<RxDocType>\r\n): string {\r\n if (typeof jsonSchema.primaryKey === 'string') {\r\n return (documentData as any)[jsonSchema.primaryKey];\r\n }\r\n\r\n const compositePrimary: CompositePrimaryKey<RxDocType> = jsonSchema.primaryKey as any;\r\n return compositePrimary.fields.map(field => {\r\n const value = getProperty(documentData as any, field as string);\r\n if (typeof value === 'undefined') {\r\n throw newRxError('DOC18', { args: { field, documentData } });\r\n }\r\n return value;\r\n }).join(compositePrimary.separator);\r\n}\r\n\r\n\r\n/**\r\n * Normalize the RxJsonSchema.\r\n * We need this to ensure everything is set up properly\r\n * and we have the same hash on schemas that represent the same value but\r\n * have different json.\r\n *\r\n * - Orders the schemas attributes by alphabetical order\r\n * - Adds the primaryKey to all indexes that do not contain the primaryKey\r\n * - We need this for deterministic sort order on all queries, which is required for event-reduce to work.\r\n *\r\n * @return RxJsonSchema - ordered and filled\r\n */\r\nexport function normalizeRxJsonSchema<T>(jsonSchema: RxJsonSchema<T>): RxJsonSchema<T> {\r\n const normalizedSchema: RxJsonSchema<T> = sortObject(jsonSchema, true);\r\n return normalizedSchema;\r\n}\r\n\r\n/**\r\n * If the schema does not specify any index,\r\n * we add this index so we at least can run RxQuery()\r\n * and only select non-deleted fields.\r\n */\r\nexport function getDefaultIndex(primaryPath: string) {\r\n return ['_deleted', primaryPath];\r\n}\r\n\r\n/**\r\n * fills the schema-json with default-settings\r\n * @return cloned schemaObj\r\n */\r\nexport function fillWithDefaultSettings<T = any>(\r\n schemaObj: RxJsonSchema<T>\r\n): RxJsonSchema<RxDocumentData<T>> {\r\n schemaObj = flatClone(schemaObj);\r\n const primaryPath: string = getPrimaryFieldOfPrimaryKey(schemaObj.primaryKey);\r\n schemaObj.properties = flatClone(schemaObj.properties);\r\n\r\n // additionalProperties is always false\r\n schemaObj.additionalProperties = false;\r\n\r\n // fill with key-compression-state ()\r\n if (!Object.prototype.hasOwnProperty.call(schemaObj, 'keyCompression')) {\r\n schemaObj.keyCompression = false;\r\n }\r\n\r\n // indexes must be array\r\n schemaObj.indexes = schemaObj.indexes ? schemaObj.indexes.slice(0) : [];\r\n\r\n // required must be array\r\n schemaObj.required = schemaObj.required ? schemaObj.required.slice(0) : [];\r\n\r\n // encrypted must be array\r\n schemaObj.encrypted = schemaObj.encrypted ? schemaObj.encrypted.slice(0) : [];\r\n\r\n // add _rev\r\n (schemaObj.properties as any)._rev = {\r\n type: 'string',\r\n minLength: 1\r\n };\r\n\r\n // add attachments\r\n (schemaObj.properties as any)._attachments = {\r\n type: 'object'\r\n };\r\n\r\n // add deleted flag\r\n (schemaObj.properties as any)._deleted = {\r\n type: 'boolean'\r\n };\r\n\r\n // add meta property\r\n (schemaObj.properties as any)._meta = RX_META_SCHEMA;\r\n\r\n /**\r\n * meta fields are all required\r\n */\r\n schemaObj.required = schemaObj.required ? schemaObj.required.slice(0) : [];\r\n (schemaObj.required as string[]).push('_deleted');\r\n (schemaObj.required as string[]).push('_rev');\r\n (schemaObj.required as string[]).push('_meta');\r\n (schemaObj.required as string[]).push('_attachments');\r\n\r\n // primaryKey is always required\r\n (schemaObj.required as any).push(primaryPath);\r\n\r\n schemaObj.required = schemaObj.required\r\n .filter((field: string) => !field.includes('.'))\r\n .filter((elem: any, pos: any, arr: any) => arr.indexOf(elem) === pos); // unique;\r\n\r\n\r\n // version is 0 by default\r\n schemaObj.version = schemaObj.version || 0;\r\n\r\n const useIndexes: string[][] = schemaObj.indexes.map(index => {\r\n const arIndex = isMaybeReadonlyArray(index) ? index.slice(0) : [index];\r\n /**\r\n * Append primary key to indexes that do not contain the primaryKey.\r\n * All indexes must have the primaryKey to ensure a deterministic sort order.\r\n */\r\n if (!arIndex.includes(primaryPath)) {\r\n arIndex.push(primaryPath);\r\n }\r\n\r\n // add _deleted flag to all indexes so we can query only non-deleted fields\r\n // in RxDB itself\r\n if (arIndex[0] !== '_deleted') {\r\n arIndex.unshift('_deleted');\r\n }\r\n\r\n return arIndex;\r\n });\r\n\r\n if (useIndexes.length === 0) {\r\n useIndexes.push(getDefaultIndex(primaryPath));\r\n }\r\n\r\n // we need this index for the getChangedDocumentsSince() method\r\n useIndexes.push(['_meta.lwt', primaryPath]);\r\n\r\n // also add the internalIndexes\r\n if (schemaObj.internalIndexes) {\r\n schemaObj.internalIndexes.map(idx => {\r\n useIndexes.push(idx);\r\n });\r\n }\r\n\r\n // make indexes unique\r\n const hasIndex = new Set<string>();\r\n schemaObj.indexes = useIndexes.filter(index => {\r\n const indexStr = index.join(',');\r\n if (hasIndex.has(indexStr)) {\r\n return false;\r\n } else {\r\n hasIndex.add(indexStr);\r\n return true;\r\n }\r\n });\r\n\r\n return schemaObj as any;\r\n}\r\n\r\nexport const META_LWT_UNIX_TIME_MAX = 1000000000000000;\r\nexport const RX_META_SCHEMA: JsonSchema = {\r\n type: 'object',\r\n properties: {\r\n /**\r\n * The last-write time.\r\n * Unix time in milliseconds.\r\n */\r\n lwt: {\r\n type: 'number',\r\n /**\r\n * We use 1 as minimum so that the value is never falsy.\r\n */\r\n minimum: RX_META_LWT_MINIMUM,\r\n maximum: META_LWT_UNIX_TIME_MAX,\r\n multipleOf: 0.01\r\n }\r\n },\r\n /**\r\n * Additional properties are allowed\r\n * and can be used by plugins to set various flags.\r\n */\r\n additionalProperties: true as any,\r\n required: [\r\n 'lwt'\r\n ]\r\n};\r\n\r\n\r\n/**\r\n * returns the final-fields of the schema\r\n * @return field-names of the final-fields\r\n */\r\nexport function getFinalFields<T = any>(\r\n jsonSchema: RxJsonSchema<T>\r\n): string[] {\r\n const ret = Object.keys(jsonSchema.properties)\r\n .filter(key => (jsonSchema as any).properties[key].final);\r\n\r\n // primary is also final\r\n const primaryPath = getPrimaryFieldOfPrimaryKey(jsonSchema.primaryKey);\r\n ret.push(primaryPath);\r\n\r\n // fields of composite primary are final\r\n if (typeof jsonSchema.primaryKey !== 'string') {\r\n (jsonSchema.primaryKey as CompositePrimaryKey<T>).fields\r\n .forEach(field => ret.push(field as string));\r\n }\r\n\r\n return ret;\r\n}\r\n\r\n/**\r\n * fills all unset fields with default-values if set\r\n * @hotPath\r\n */\r\nexport function fillObjectWithDefaults(rxSchema: RxSchema<any>, obj: any): any {\r\n const defaultKeys = Object.keys(rxSchema.defaultValues);\r\n for (let i = 0; i < defaultKeys.length; ++i) {\r\n const key = defaultKeys[i];\r\n if (obj[key] === undefined) {\r\n const val = rxSchema.defaultValues[key];\r\n if (typeof val === 'object' && val !== null) {\r\n obj[key] = Array.isArray(val) ? val.slice() : { ...val };\r\n } else {\r\n obj[key] = val;\r\n }\r\n }\r\n }\r\n return obj;\r\n}\r\n\r\nexport const DEFAULT_CHECKPOINT_SCHEMA: DeepReadonly<JsonSchema<RxStorageDefaultCheckpoint>> = {\r\n type: 'object',\r\n properties: {\r\n id: {\r\n type: 'string'\r\n },\r\n lwt: {\r\n type: 'number'\r\n }\r\n },\r\n required: [\r\n 'id',\r\n 'lwt'\r\n ],\r\n additionalProperties: false\r\n} as const;\r\n"],"mappings":";;;;;;;;;;;;;;;;;A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J,CAAC;EACDK,QAAQ,EAAE,CACN,IAAI,EACJ,KAAK,CACR;EACD6C,oBAAoB,EAAE;AAC1B,CAAU","ignoreList":[]}
|
package/dist/cjs/rx-schema.js
CHANGED
|
@@ -43,6 +43,7 @@ var RxSchema = exports.RxSchema = /*#__PURE__*/function () {
|
|
|
43
43
|
var jsonSchema = (0, _eventReduceJs.flatClone)(this.jsonSchema);
|
|
44
44
|
jsonSchema.properties = (0, _eventReduceJs.flatClone)(jsonSchema.properties);
|
|
45
45
|
delete jsonSchema.properties._deleted;
|
|
46
|
+
delete jsonSchema.properties._rev;
|
|
46
47
|
delete jsonSchema.properties._meta;
|
|
47
48
|
delete jsonSchema.properties._attachments;
|
|
48
49
|
if (jsonSchema.required) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rx-schema.js","names":["_index","require","_rxError","_hooks","_rxSchemaHelper","_overwritable","_eventReduceJs","RxSchema","exports","jsonSchema","hashFunction","indexes","getIndexes","primaryPath","getPrimaryFieldOfPrimaryKey","primaryKey","properties","maxLength","newRxError","schema","finalFields","getFinalFields","_proto","prototype","getJsonSchemaWithoutMeta","flatClone","_deleted","_meta","_attachments","required","filter","r","startsWith","validateChange","dataBefore","dataAfter","forEach","fieldName","deepEqual","getDocumentPrototype","proto","pathProperties","getSchemaByObjectPath","Object","keys","key","fullPath","__defineGetter__","get","undefined","ret","defineProperty","get$","enumerable","configurable","get$$","populate","overwriteGetterForCaching","getPrimaryOfDocumentData","documentData","getComposedPrimaryKeyOfDocumentData","_createClass2","default","version","values","entries","v","hasOwnProperty","call","k","JSON","stringify","map","index","isMaybeReadonlyArray","getPreviousVersions","c","Array","fill","createRxSchema","runPreCreateHooks","runPluginHooks","useJsonSchema","fillWithDefaultSettings","normalizeRxJsonSchema","overwritable","deepFreezeWhenDevMode","isRxSchema","obj","toTypedRxJsonSchema"],"sources":["../../src/rx-schema.ts"],"sourcesContent":["import {\r\n overwriteGetterForCaching,\r\n isMaybeReadonlyArray,\r\n deepEqual\r\n} from './plugins/utils/index.ts';\r\nimport {\r\n newRxError,\r\n} from './rx-error.ts';\r\nimport {\r\n runPluginHooks\r\n} from './hooks.ts';\r\n\r\nimport type {\r\n DeepMutable,\r\n DeepReadonly,\r\n HashFunction,\r\n MaybeReadonly,\r\n RxDocument,\r\n RxDocumentData,\r\n RxJsonSchema,\r\n StringKeys\r\n} from './types/index.d.ts';\r\nimport {\r\n fillWithDefaultSettings,\r\n getComposedPrimaryKeyOfDocumentData,\r\n getFinalFields,\r\n getPrimaryFieldOfPrimaryKey,\r\n getSchemaByObjectPath,\r\n normalizeRxJsonSchema\r\n} from './rx-schema-helper.ts';\r\nimport { overwritable } from './overwritable.ts';\r\nimport { flatClone } from 'event-reduce-js';\r\n\r\nexport class RxSchema<RxDocType = any> {\r\n public indexes: MaybeReadonly<string[]>[];\r\n public readonly primaryPath: StringKeys<RxDocumentData<RxDocType>>;\r\n public finalFields: string[];\r\n\r\n constructor(\r\n public readonly jsonSchema: RxJsonSchema<RxDocumentData<RxDocType>>,\r\n public readonly hashFunction: HashFunction\r\n ) {\r\n this.indexes = getIndexes(this.jsonSchema);\r\n\r\n // primary is always required\r\n this.primaryPath = getPrimaryFieldOfPrimaryKey(this.jsonSchema.primaryKey);\r\n\r\n /**\r\n * Many people accidentally put in wrong schema state\r\n * without the dev-mode plugin, so we need this check here\r\n * even in non-dev-mode.\r\n */\r\n if (!jsonSchema.properties[this.primaryPath].maxLength) {\r\n throw newRxError('SC39', { schema: jsonSchema });\r\n }\r\n\r\n this.finalFields = getFinalFields(this.jsonSchema);\r\n }\r\n\r\n public get version(): number {\r\n return this.jsonSchema.version;\r\n }\r\n\r\n public get defaultValues(): { [P in keyof RxDocType]: RxDocType[P] } {\r\n const values = {} as { [P in keyof RxDocType]: RxDocType[P] };\r\n Object\r\n .entries(this.jsonSchema.properties)\r\n .filter(([, v]) => Object.prototype.hasOwnProperty.call(v, 'default'))\r\n .forEach(([k, v]) => (values as any)[k] = (v as any).default);\r\n return overwriteGetterForCaching(\r\n this,\r\n 'defaultValues',\r\n values\r\n );\r\n }\r\n\r\n public getJsonSchemaWithoutMeta(): RxJsonSchema<RxDocumentData<RxDocType>> {\r\n const jsonSchema: any = flatClone(this.jsonSchema);\r\n jsonSchema.properties = flatClone(jsonSchema.properties);\r\n delete jsonSchema.properties._deleted;\r\n delete jsonSchema.properties._meta;\r\n delete jsonSchema.properties._attachments;\r\n\r\n if (jsonSchema.required) {\r\n jsonSchema.required = jsonSchema.required.filter((r: string) => !r.startsWith('_'));\r\n }\r\n\r\n return jsonSchema as RxJsonSchema<RxDocumentData<RxDocType>>;\r\n }\r\n\r\n /**\r\n * @overrides itself on the first call\r\n */\r\n public get hash(): Promise<string> {\r\n return overwriteGetterForCaching(\r\n this,\r\n 'hash',\r\n this.hashFunction(JSON.stringify(this.jsonSchema))\r\n );\r\n }\r\n\r\n /**\r\n * checks if a given change on a document is allowed\r\n * Ensures that:\r\n * - final fields are not modified\r\n * @throws {Error} if not valid\r\n */\r\n validateChange(dataBefore: any, dataAfter: any): void {\r\n this.finalFields.forEach(fieldName => {\r\n if (!deepEqual(dataBefore[fieldName], dataAfter[fieldName])) {\r\n throw newRxError('DOC9', {\r\n dataBefore,\r\n dataAfter,\r\n fieldName,\r\n schema: this.jsonSchema\r\n });\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * creates the schema-based document-prototype,\r\n * see RxCollection.getDocumentPrototype()\r\n */\r\n public getDocumentPrototype(): any {\r\n const proto: any = {};\r\n\r\n /**\r\n * On the top level, we know all keys\r\n * and therefore do not have to create a new Proxy object\r\n * for each document. Instead we define the getter in the prototype once.\r\n */\r\n const pathProperties = getSchemaByObjectPath(\r\n this.jsonSchema,\r\n ''\r\n );\r\n Object.keys(pathProperties)\r\n .forEach(key => {\r\n const fullPath = key;\r\n\r\n // getter - value\r\n proto.__defineGetter__(\r\n key,\r\n function (this: RxDocument) {\r\n if (!this.get || typeof this.get !== 'function') {\r\n /**\r\n * When an object gets added to the state of a vuejs-component,\r\n * it happens that this getter is called with another scope.\r\n * To prevent errors, we have to return undefined in this case\r\n */\r\n return undefined;\r\n }\r\n const ret = this.get(fullPath);\r\n return ret;\r\n }\r\n );\r\n // getter - observable$\r\n Object.defineProperty(proto, key + '$', {\r\n get: function () {\r\n return this.get$(fullPath);\r\n },\r\n enumerable: false,\r\n configurable: false\r\n });\r\n // getter - reactivity$$\r\n Object.defineProperty(proto, key + '$$', {\r\n get: function () {\r\n return this.get$$(fullPath);\r\n },\r\n enumerable: false,\r\n configurable: false\r\n });\r\n // getter - populate_\r\n Object.defineProperty(proto, key + '_', {\r\n get: function () {\r\n return this.populate(fullPath);\r\n },\r\n enumerable: false,\r\n configurable: false\r\n });\r\n });\r\n\r\n overwriteGetterForCaching(\r\n this,\r\n 'getDocumentPrototype',\r\n () => proto\r\n );\r\n return proto;\r\n }\r\n\r\n\r\n getPrimaryOfDocumentData(\r\n documentData: Partial<RxDocType>\r\n ): string {\r\n return getComposedPrimaryKeyOfDocumentData(\r\n this.jsonSchema,\r\n documentData\r\n );\r\n }\r\n}\r\n\r\nexport function getIndexes<RxDocType = any>(\r\n jsonSchema: RxJsonSchema<RxDocType>\r\n): MaybeReadonly<string[]>[] {\r\n return (jsonSchema.indexes || []).map(index => isMaybeReadonlyArray(index) ? index : [index]);\r\n}\r\n\r\n/**\r\n * array with previous version-numbers\r\n */\r\nexport function getPreviousVersions(schema: RxJsonSchema<any>): number[] {\r\n const version = schema.version ? schema.version : 0;\r\n let c = 0;\r\n return new Array(version)\r\n .fill(0)\r\n .map(() => c++);\r\n}\r\n\r\nexport function createRxSchema<T>(\r\n jsonSchema: RxJsonSchema<T>,\r\n hashFunction: HashFunction,\r\n runPreCreateHooks = true\r\n): RxSchema<T> {\r\n if (runPreCreateHooks) {\r\n runPluginHooks('preCreateRxSchema', jsonSchema);\r\n }\r\n\r\n let useJsonSchema = fillWithDefaultSettings(jsonSchema);\r\n useJsonSchema = normalizeRxJsonSchema(useJsonSchema);\r\n overwritable.deepFreezeWhenDevMode(useJsonSchema);\r\n\r\n const schema = new RxSchema(useJsonSchema, hashFunction);\r\n runPluginHooks('createRxSchema', schema);\r\n return schema;\r\n}\r\n\r\nexport function isRxSchema(obj: any): boolean {\r\n return obj instanceof RxSchema;\r\n}\r\n\r\n/**\r\n * Used as helper function the generate the document type out of the schema via typescript.\r\n * @link https://github.com/pubkey/rxdb/discussions/3467\r\n */\r\nexport function toTypedRxJsonSchema<T extends DeepReadonly<RxJsonSchema<any>>>(schema: T): DeepMutable<T> {\r\n return schema as any;\r\n}\r\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA;AAGA,IAAAE,MAAA,GAAAF,OAAA;AAcA,IAAAG,eAAA,GAAAH,OAAA;AAQA,IAAAI,aAAA,GAAAJ,OAAA;AACA,IAAAK,cAAA,GAAAL,OAAA;AAA4C,IAE/BM,QAAQ,GAAAC,OAAA,CAAAD,QAAA;EAKjB,SAAAA,SACoBE,UAAmD,EACnDC,YAA0B,EAC5C;IAAA,KAFkBD,UAAmD,GAAnDA,UAAmD;IAAA,KACnDC,YAA0B,GAA1BA,YAA0B;IAE1C,IAAI,CAACC,OAAO,GAAGC,UAAU,CAAC,IAAI,CAACH,UAAU,CAAC;;IAE1C;IACA,IAAI,CAACI,WAAW,GAAG,IAAAC,2CAA2B,EAAC,IAAI,CAACL,UAAU,CAACM,UAAU,CAAC;;IAE1E;AACR;AACA;AACA;AACA;IACQ,IAAI,CAACN,UAAU,CAACO,UAAU,CAAC,IAAI,CAACH,WAAW,CAAC,CAACI,SAAS,EAAE;MACpD,MAAM,IAAAC,mBAAU,EAAC,MAAM,EAAE;QAAEC,MAAM,EAAEV;MAAW,CAAC,CAAC;IACpD;IAEA,IAAI,CAACW,WAAW,GAAG,IAAAC,8BAAc,EAAC,IAAI,CAACZ,UAAU,CAAC;EACtD;EAAC,IAAAa,MAAA,GAAAf,QAAA,C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AK,CAAC,GAAGA,KAAK,GAAG,CAACA,KAAK,CAAC,CAAC;AACjG;;AAEA;AACA;AACA;AACO,SAASE,mBAAmBA,CAACxD,MAAyB,EAAY;EACrE,IAAM4C,OAAO,GAAG5C,MAAM,CAAC4C,OAAO,GAAG5C,MAAM,CAAC4C,OAAO,GAAG,CAAC;EACnD,IAAIa,CAAC,GAAG,CAAC;EACT,OAAO,IAAIC,KAAK,CAACd,OAAO,CAAC,CACpBe,IAAI,CAAC,CAAC,CAAC,CACPN,GAAG,CAAC,MAAMI,CAAC,EAAE,CAAC;AACvB;AAEO,SAASG,cAAcA,CAC1BtE,UAA2B,EAC3BC,YAA0B,EAC1BsE,iBAAiB,GAAG,IAAI,EACb;EACX,IAAIA,iBAAiB,EAAE;IACnB,IAAAC,qBAAc,EAAC,mBAAmB,EAAExE,UAAU,CAAC;EACnD;EAEA,IAAIyE,aAAa,GAAG,IAAAC,uCAAuB,EAAC1E,UAAU,CAAC;EACvDyE,aAAa,GAAG,IAAAE,qCAAqB,EAACF,aAAa,CAAC;EACpDG,0BAAY,CAACC,qBAAqB,CAACJ,aAAa,CAAC;EAEjD,IAAM/D,MAAM,GAAG,IAAIZ,QAAQ,CAAC2E,aAAa,EAAExE,YAAY,CAAC;EACxD,IAAAuE,qBAAc,EAAC,gBAAgB,EAAE9D,MAAM,CAAC;EACxC,OAAOA,MAAM;AACjB;AAEO,SAASoE,UAAUA,CAACC,GAAQ,EAAW;EAC1C,OAAOA,GAAG,YAAYjF,QAAQ;AAClC;;AAEA;AACA;AACA;AACA;AACO,SAASkF,mBAAmBA,CAA4CtE,MAAS,EAAkB;EACtG,OAAOA,MAAM;AACjB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"rx-schema.js","names":["_index","require","_rxError","_hooks","_rxSchemaHelper","_overwritable","_eventReduceJs","RxSchema","exports","jsonSchema","hashFunction","indexes","getIndexes","primaryPath","getPrimaryFieldOfPrimaryKey","primaryKey","properties","maxLength","newRxError","schema","finalFields","getFinalFields","_proto","prototype","getJsonSchemaWithoutMeta","flatClone","_deleted","_rev","_meta","_attachments","required","filter","r","startsWith","validateChange","dataBefore","dataAfter","forEach","fieldName","deepEqual","getDocumentPrototype","proto","pathProperties","getSchemaByObjectPath","Object","keys","key","fullPath","__defineGetter__","get","undefined","ret","defineProperty","get$","enumerable","configurable","get$$","populate","overwriteGetterForCaching","getPrimaryOfDocumentData","documentData","getComposedPrimaryKeyOfDocumentData","_createClass2","default","version","values","entries","v","hasOwnProperty","call","k","JSON","stringify","map","index","isMaybeReadonlyArray","getPreviousVersions","c","Array","fill","createRxSchema","runPreCreateHooks","runPluginHooks","useJsonSchema","fillWithDefaultSettings","normalizeRxJsonSchema","overwritable","deepFreezeWhenDevMode","isRxSchema","obj","toTypedRxJsonSchema"],"sources":["../../src/rx-schema.ts"],"sourcesContent":["import {\r\n overwriteGetterForCaching,\r\n isMaybeReadonlyArray,\r\n deepEqual\r\n} from './plugins/utils/index.ts';\r\nimport {\r\n newRxError,\r\n} from './rx-error.ts';\r\nimport {\r\n runPluginHooks\r\n} from './hooks.ts';\r\n\r\nimport type {\r\n DeepMutable,\r\n DeepReadonly,\r\n HashFunction,\r\n MaybeReadonly,\r\n RxDocument,\r\n RxDocumentData,\r\n RxJsonSchema,\r\n StringKeys\r\n} from './types/index.d.ts';\r\nimport {\r\n fillWithDefaultSettings,\r\n getComposedPrimaryKeyOfDocumentData,\r\n getFinalFields,\r\n getPrimaryFieldOfPrimaryKey,\r\n getSchemaByObjectPath,\r\n normalizeRxJsonSchema\r\n} from './rx-schema-helper.ts';\r\nimport { overwritable } from './overwritable.ts';\r\nimport { flatClone } from 'event-reduce-js';\r\n\r\nexport class RxSchema<RxDocType = any> {\r\n public indexes: MaybeReadonly<string[]>[];\r\n public readonly primaryPath: StringKeys<RxDocumentData<RxDocType>>;\r\n public finalFields: string[];\r\n\r\n constructor(\r\n public readonly jsonSchema: RxJsonSchema<RxDocumentData<RxDocType>>,\r\n public readonly hashFunction: HashFunction\r\n ) {\r\n this.indexes = getIndexes(this.jsonSchema);\r\n\r\n // primary is always required\r\n this.primaryPath = getPrimaryFieldOfPrimaryKey(this.jsonSchema.primaryKey);\r\n\r\n /**\r\n * Many people accidentally put in wrong schema state\r\n * without the dev-mode plugin, so we need this check here\r\n * even in non-dev-mode.\r\n */\r\n if (!jsonSchema.properties[this.primaryPath].maxLength) {\r\n throw newRxError('SC39', { schema: jsonSchema });\r\n }\r\n\r\n this.finalFields = getFinalFields(this.jsonSchema);\r\n }\r\n\r\n public get version(): number {\r\n return this.jsonSchema.version;\r\n }\r\n\r\n public get defaultValues(): { [P in keyof RxDocType]: RxDocType[P] } {\r\n const values = {} as { [P in keyof RxDocType]: RxDocType[P] };\r\n Object\r\n .entries(this.jsonSchema.properties)\r\n .filter(([, v]) => Object.prototype.hasOwnProperty.call(v, 'default'))\r\n .forEach(([k, v]) => (values as any)[k] = (v as any).default);\r\n return overwriteGetterForCaching(\r\n this,\r\n 'defaultValues',\r\n values\r\n );\r\n }\r\n\r\n public getJsonSchemaWithoutMeta(): RxJsonSchema<RxDocumentData<RxDocType>> {\r\n const jsonSchema: any = flatClone(this.jsonSchema);\r\n jsonSchema.properties = flatClone(jsonSchema.properties);\r\n delete jsonSchema.properties._deleted;\r\n delete jsonSchema.properties._rev;\r\n delete jsonSchema.properties._meta;\r\n delete jsonSchema.properties._attachments;\r\n\r\n if (jsonSchema.required) {\r\n jsonSchema.required = jsonSchema.required.filter((r: string) => !r.startsWith('_'));\r\n }\r\n\r\n return jsonSchema as RxJsonSchema<RxDocumentData<RxDocType>>;\r\n }\r\n\r\n /**\r\n * @overrides itself on the first call\r\n */\r\n public get hash(): Promise<string> {\r\n return overwriteGetterForCaching(\r\n this,\r\n 'hash',\r\n this.hashFunction(JSON.stringify(this.jsonSchema))\r\n );\r\n }\r\n\r\n /**\r\n * checks if a given change on a document is allowed\r\n * Ensures that:\r\n * - final fields are not modified\r\n * @throws {Error} if not valid\r\n */\r\n validateChange(dataBefore: any, dataAfter: any): void {\r\n this.finalFields.forEach(fieldName => {\r\n if (!deepEqual(dataBefore[fieldName], dataAfter[fieldName])) {\r\n throw newRxError('DOC9', {\r\n dataBefore,\r\n dataAfter,\r\n fieldName,\r\n schema: this.jsonSchema\r\n });\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * creates the schema-based document-prototype,\r\n * see RxCollection.getDocumentPrototype()\r\n */\r\n public getDocumentPrototype(): any {\r\n const proto: any = {};\r\n\r\n /**\r\n * On the top level, we know all keys\r\n * and therefore do not have to create a new Proxy object\r\n * for each document. Instead we define the getter in the prototype once.\r\n */\r\n const pathProperties = getSchemaByObjectPath(\r\n this.jsonSchema,\r\n ''\r\n );\r\n Object.keys(pathProperties)\r\n .forEach(key => {\r\n const fullPath = key;\r\n\r\n // getter - value\r\n proto.__defineGetter__(\r\n key,\r\n function (this: RxDocument) {\r\n if (!this.get || typeof this.get !== 'function') {\r\n /**\r\n * When an object gets added to the state of a vuejs-component,\r\n * it happens that this getter is called with another scope.\r\n * To prevent errors, we have to return undefined in this case\r\n */\r\n return undefined;\r\n }\r\n const ret = this.get(fullPath);\r\n return ret;\r\n }\r\n );\r\n // getter - observable$\r\n Object.defineProperty(proto, key + '$', {\r\n get: function () {\r\n return this.get$(fullPath);\r\n },\r\n enumerable: false,\r\n configurable: false\r\n });\r\n // getter - reactivity$$\r\n Object.defineProperty(proto, key + '$$', {\r\n get: function () {\r\n return this.get$$(fullPath);\r\n },\r\n enumerable: false,\r\n configurable: false\r\n });\r\n // getter - populate_\r\n Object.defineProperty(proto, key + '_', {\r\n get: function () {\r\n return this.populate(fullPath);\r\n },\r\n enumerable: false,\r\n configurable: false\r\n });\r\n });\r\n\r\n overwriteGetterForCaching(\r\n this,\r\n 'getDocumentPrototype',\r\n () => proto\r\n );\r\n return proto;\r\n }\r\n\r\n\r\n getPrimaryOfDocumentData(\r\n documentData: Partial<RxDocType>\r\n ): string {\r\n return getComposedPrimaryKeyOfDocumentData(\r\n this.jsonSchema,\r\n documentData\r\n );\r\n }\r\n}\r\n\r\nexport function getIndexes<RxDocType = any>(\r\n jsonSchema: RxJsonSchema<RxDocType>\r\n): MaybeReadonly<string[]>[] {\r\n return (jsonSchema.indexes || []).map(index => isMaybeReadonlyArray(index) ? index : [index]);\r\n}\r\n\r\n/**\r\n * array with previous version-numbers\r\n */\r\nexport function getPreviousVersions(schema: RxJsonSchema<any>): number[] {\r\n const version = schema.version ? schema.version : 0;\r\n let c = 0;\r\n return new Array(version)\r\n .fill(0)\r\n .map(() => c++);\r\n}\r\n\r\nexport function createRxSchema<T>(\r\n jsonSchema: RxJsonSchema<T>,\r\n hashFunction: HashFunction,\r\n runPreCreateHooks = true\r\n): RxSchema<T> {\r\n if (runPreCreateHooks) {\r\n runPluginHooks('preCreateRxSchema', jsonSchema);\r\n }\r\n\r\n let useJsonSchema = fillWithDefaultSettings(jsonSchema);\r\n useJsonSchema = normalizeRxJsonSchema(useJsonSchema);\r\n overwritable.deepFreezeWhenDevMode(useJsonSchema);\r\n\r\n const schema = new RxSchema(useJsonSchema, hashFunction);\r\n runPluginHooks('createRxSchema', schema);\r\n return schema;\r\n}\r\n\r\nexport function isRxSchema(obj: any): boolean {\r\n return obj instanceof RxSchema;\r\n}\r\n\r\n/**\r\n * Used as helper function the generate the document type out of the schema via typescript.\r\n * @link https://github.com/pubkey/rxdb/discussions/3467\r\n */\r\nexport function toTypedRxJsonSchema<T extends DeepReadonly<RxJsonSchema<any>>>(schema: T): DeepMutable<T> {\r\n return schema as any;\r\n}\r\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA;AAGA,IAAAE,MAAA,GAAAF,OAAA;AAcA,IAAAG,eAAA,GAAAH,OAAA;AAQA,IAAAI,aAAA,GAAAJ,OAAA;AACA,IAAAK,cAAA,GAAAL,OAAA;AAA4C,IAE/BM,QAAQ,GAAAC,OAAA,CAAAD,QAAA;EAKjB,SAAAA,SACo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