@enbox/dwn-sdk-js 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +352 -0
- package/dist/bundles/dwn.js +153 -0
- package/dist/cjs/index.js +36749 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/generated/precompiled-validators.js +11973 -0
- package/dist/esm/generated/precompiled-validators.js.map +1 -0
- package/dist/esm/json-schemas/definitions.json +23 -0
- package/dist/esm/src/core/abstract-message.js +47 -0
- package/dist/esm/src/core/abstract-message.js.map +1 -0
- package/dist/esm/src/core/auth.js +39 -0
- package/dist/esm/src/core/auth.js.map +1 -0
- package/dist/esm/src/core/dwn-constant.js +10 -0
- package/dist/esm/src/core/dwn-constant.js.map +1 -0
- package/dist/esm/src/core/dwn-error.js +169 -0
- package/dist/esm/src/core/dwn-error.js.map +1 -0
- package/dist/esm/src/core/grant-authorization.js +97 -0
- package/dist/esm/src/core/grant-authorization.js.map +1 -0
- package/dist/esm/src/core/message-reply.js +5 -0
- package/dist/esm/src/core/message-reply.js.map +1 -0
- package/dist/esm/src/core/message.js +233 -0
- package/dist/esm/src/core/message.js.map +1 -0
- package/dist/esm/src/core/messages-grant-authorization.js +101 -0
- package/dist/esm/src/core/messages-grant-authorization.js.map +1 -0
- package/dist/esm/src/core/protocol-authorization.js +608 -0
- package/dist/esm/src/core/protocol-authorization.js.map +1 -0
- package/dist/esm/src/core/protocols-grant-authorization.js +66 -0
- package/dist/esm/src/core/protocols-grant-authorization.js.map +1 -0
- package/dist/esm/src/core/records-grant-authorization.js +132 -0
- package/dist/esm/src/core/records-grant-authorization.js.map +1 -0
- package/dist/esm/src/core/resumable-task-manager.js +109 -0
- package/dist/esm/src/core/resumable-task-manager.js.map +1 -0
- package/dist/esm/src/core/tenant-gate.js +20 -0
- package/dist/esm/src/core/tenant-gate.js.map +1 -0
- package/dist/esm/src/dwn.js +164 -0
- package/dist/esm/src/dwn.js.map +1 -0
- package/dist/esm/src/enums/dwn-interface-method.js +16 -0
- package/dist/esm/src/enums/dwn-interface-method.js.map +1 -0
- package/dist/esm/src/event-log/event-emitter-stream.js +60 -0
- package/dist/esm/src/event-log/event-emitter-stream.js.map +1 -0
- package/dist/esm/src/event-log/event-log-level.js +63 -0
- package/dist/esm/src/event-log/event-log-level.js.map +1 -0
- package/dist/esm/src/handlers/messages-query.js +71 -0
- package/dist/esm/src/handlers/messages-query.js.map +1 -0
- package/dist/esm/src/handlers/messages-read.js +102 -0
- package/dist/esm/src/handlers/messages-read.js.map +1 -0
- package/dist/esm/src/handlers/messages-subscribe.js +81 -0
- package/dist/esm/src/handlers/messages-subscribe.js.map +1 -0
- package/dist/esm/src/handlers/protocols-configure.js +133 -0
- package/dist/esm/src/handlers/protocols-configure.js.map +1 -0
- package/dist/esm/src/handlers/protocols-query.js +73 -0
- package/dist/esm/src/handlers/protocols-query.js.map +1 -0
- package/dist/esm/src/handlers/records-delete.js +107 -0
- package/dist/esm/src/handlers/records-delete.js.map +1 -0
- package/dist/esm/src/handlers/records-query.js +210 -0
- package/dist/esm/src/handlers/records-query.js.map +1 -0
- package/dist/esm/src/handlers/records-read.js +169 -0
- package/dist/esm/src/handlers/records-read.js.map +1 -0
- package/dist/esm/src/handlers/records-subscribe.js +172 -0
- package/dist/esm/src/handlers/records-subscribe.js.map +1 -0
- package/dist/esm/src/handlers/records-write.js +344 -0
- package/dist/esm/src/handlers/records-write.js.map +1 -0
- package/dist/esm/src/index.js +49 -0
- package/dist/esm/src/index.js.map +1 -0
- package/dist/esm/src/interfaces/messages-query.js +53 -0
- package/dist/esm/src/interfaces/messages-query.js.map +1 -0
- package/dist/esm/src/interfaces/messages-read.js +61 -0
- package/dist/esm/src/interfaces/messages-read.js.map +1 -0
- package/dist/esm/src/interfaces/messages-subscribe.js +58 -0
- package/dist/esm/src/interfaces/messages-subscribe.js.map +1 -0
- package/dist/esm/src/interfaces/protocols-configure.js +271 -0
- package/dist/esm/src/interfaces/protocols-configure.js.map +1 -0
- package/dist/esm/src/interfaces/protocols-query.js +84 -0
- package/dist/esm/src/interfaces/protocols-query.js.map +1 -0
- package/dist/esm/src/interfaces/records-delete.js +89 -0
- package/dist/esm/src/interfaces/records-delete.js.map +1 -0
- package/dist/esm/src/interfaces/records-query.js +104 -0
- package/dist/esm/src/interfaces/records-query.js.map +1 -0
- package/dist/esm/src/interfaces/records-read.js +84 -0
- package/dist/esm/src/interfaces/records-read.js.map +1 -0
- package/dist/esm/src/interfaces/records-subscribe.js +91 -0
- package/dist/esm/src/interfaces/records-subscribe.js.map +1 -0
- package/dist/esm/src/interfaces/records-write.js +795 -0
- package/dist/esm/src/interfaces/records-write.js.map +1 -0
- package/dist/esm/src/jose/algorithms/signing/ed25519.js +51 -0
- package/dist/esm/src/jose/algorithms/signing/ed25519.js.map +1 -0
- package/dist/esm/src/jose/algorithms/signing/signature-algorithms.js +20 -0
- package/dist/esm/src/jose/algorithms/signing/signature-algorithms.js.map +1 -0
- package/dist/esm/src/jose/jws/general/builder.js +47 -0
- package/dist/esm/src/jose/jws/general/builder.js.map +1 -0
- package/dist/esm/src/jose/jws/general/verifier.js +97 -0
- package/dist/esm/src/jose/jws/general/verifier.js.map +1 -0
- package/dist/esm/src/protocols/permission-grant.js +39 -0
- package/dist/esm/src/protocols/permission-grant.js.map +1 -0
- package/dist/esm/src/protocols/permission-request.js +35 -0
- package/dist/esm/src/protocols/permission-request.js.map +1 -0
- package/dist/esm/src/protocols/permissions.js +357 -0
- package/dist/esm/src/protocols/permissions.js.map +1 -0
- package/dist/esm/src/schema-validator.js +37 -0
- package/dist/esm/src/schema-validator.js.map +1 -0
- package/dist/esm/src/store/blockstore-level.js +187 -0
- package/dist/esm/src/store/blockstore-level.js.map +1 -0
- package/dist/esm/src/store/blockstore-mock.js +168 -0
- package/dist/esm/src/store/blockstore-mock.js.map +1 -0
- package/dist/esm/src/store/data-store-level.js +136 -0
- package/dist/esm/src/store/data-store-level.js.map +1 -0
- package/dist/esm/src/store/index-level.js +660 -0
- package/dist/esm/src/store/index-level.js.map +1 -0
- package/dist/esm/src/store/level-wrapper.js +305 -0
- package/dist/esm/src/store/level-wrapper.js.map +1 -0
- package/dist/esm/src/store/message-store-level.js +159 -0
- package/dist/esm/src/store/message-store-level.js.map +1 -0
- package/dist/esm/src/store/resumable-task-store-level.js +131 -0
- package/dist/esm/src/store/resumable-task-store-level.js.map +1 -0
- package/dist/esm/src/store/storage-controller.js +184 -0
- package/dist/esm/src/store/storage-controller.js.map +1 -0
- package/dist/esm/src/types/cache.js +2 -0
- package/dist/esm/src/types/cache.js.map +1 -0
- package/dist/esm/src/types/data-store.js +2 -0
- package/dist/esm/src/types/data-store.js.map +1 -0
- package/dist/esm/src/types/event-log.js +2 -0
- package/dist/esm/src/types/event-log.js.map +1 -0
- package/dist/esm/src/types/jose-types.js +2 -0
- package/dist/esm/src/types/jose-types.js.map +1 -0
- package/dist/esm/src/types/jws-types.js +2 -0
- package/dist/esm/src/types/jws-types.js.map +1 -0
- package/dist/esm/src/types/message-interface.js +2 -0
- package/dist/esm/src/types/message-interface.js.map +1 -0
- package/dist/esm/src/types/message-store.js +2 -0
- package/dist/esm/src/types/message-store.js.map +1 -0
- package/dist/esm/src/types/message-types.js +3 -0
- package/dist/esm/src/types/message-types.js.map +1 -0
- package/dist/esm/src/types/messages-types.js +2 -0
- package/dist/esm/src/types/messages-types.js.map +1 -0
- package/dist/esm/src/types/method-handler.js +2 -0
- package/dist/esm/src/types/method-handler.js.map +1 -0
- package/dist/esm/src/types/permission-types.js +6 -0
- package/dist/esm/src/types/permission-types.js.map +1 -0
- package/dist/esm/src/types/protocols-types.js +20 -0
- package/dist/esm/src/types/protocols-types.js.map +1 -0
- package/dist/esm/src/types/query-types.js +6 -0
- package/dist/esm/src/types/query-types.js.map +1 -0
- package/dist/esm/src/types/records-types.js +8 -0
- package/dist/esm/src/types/records-types.js.map +1 -0
- package/dist/esm/src/types/resumable-task-store.js +2 -0
- package/dist/esm/src/types/resumable-task-store.js.map +1 -0
- package/dist/esm/src/types/signer.js +2 -0
- package/dist/esm/src/types/signer.js.map +1 -0
- package/dist/esm/src/types/subscriptions.js +2 -0
- package/dist/esm/src/types/subscriptions.js.map +1 -0
- package/dist/esm/src/utils/abort.js +40 -0
- package/dist/esm/src/utils/abort.js.map +1 -0
- package/dist/esm/src/utils/array.js +72 -0
- package/dist/esm/src/utils/array.js.map +1 -0
- package/dist/esm/src/utils/cid.js +130 -0
- package/dist/esm/src/utils/cid.js.map +1 -0
- package/dist/esm/src/utils/data-stream.js +100 -0
- package/dist/esm/src/utils/data-stream.js.map +1 -0
- package/dist/esm/src/utils/encoder.js +45 -0
- package/dist/esm/src/utils/encoder.js.map +1 -0
- package/dist/esm/src/utils/encryption.js +128 -0
- package/dist/esm/src/utils/encryption.js.map +1 -0
- package/dist/esm/src/utils/filter.js +229 -0
- package/dist/esm/src/utils/filter.js.map +1 -0
- package/dist/esm/src/utils/hd-key.js +114 -0
- package/dist/esm/src/utils/hd-key.js.map +1 -0
- package/dist/esm/src/utils/jws.js +89 -0
- package/dist/esm/src/utils/jws.js.map +1 -0
- package/dist/esm/src/utils/memory-cache.js +41 -0
- package/dist/esm/src/utils/memory-cache.js.map +1 -0
- package/dist/esm/src/utils/messages.js +84 -0
- package/dist/esm/src/utils/messages.js.map +1 -0
- package/dist/esm/src/utils/object.js +40 -0
- package/dist/esm/src/utils/object.js.map +1 -0
- package/dist/esm/src/utils/private-key-signer.js +43 -0
- package/dist/esm/src/utils/private-key-signer.js.map +1 -0
- package/dist/esm/src/utils/protocols.js +51 -0
- package/dist/esm/src/utils/protocols.js.map +1 -0
- package/dist/esm/src/utils/records.js +454 -0
- package/dist/esm/src/utils/records.js.map +1 -0
- package/dist/esm/src/utils/secp256k1.js +166 -0
- package/dist/esm/src/utils/secp256k1.js.map +1 -0
- package/dist/esm/src/utils/secp256r1.js +120 -0
- package/dist/esm/src/utils/secp256r1.js.map +1 -0
- package/dist/esm/src/utils/string.js +16 -0
- package/dist/esm/src/utils/string.js.map +1 -0
- package/dist/esm/src/utils/time.js +85 -0
- package/dist/esm/src/utils/time.js.map +1 -0
- package/dist/esm/src/utils/url.js +62 -0
- package/dist/esm/src/utils/url.js.map +1 -0
- package/dist/esm/tests/core/auth.spec.js +22 -0
- package/dist/esm/tests/core/auth.spec.js.map +1 -0
- package/dist/esm/tests/core/message-reply.spec.js +16 -0
- package/dist/esm/tests/core/message-reply.spec.js.map +1 -0
- package/dist/esm/tests/core/message.spec.js +146 -0
- package/dist/esm/tests/core/message.spec.js.map +1 -0
- package/dist/esm/tests/core/protocol-authorization.spec.js +48 -0
- package/dist/esm/tests/core/protocol-authorization.spec.js.map +1 -0
- package/dist/esm/tests/dwn.spec.js +166 -0
- package/dist/esm/tests/dwn.spec.js.map +1 -0
- package/dist/esm/tests/event-log/event-emitter-stream.spec.js +78 -0
- package/dist/esm/tests/event-log/event-emitter-stream.spec.js.map +1 -0
- package/dist/esm/tests/event-log/event-log-level.spec.js +44 -0
- package/dist/esm/tests/event-log/event-log-level.spec.js.map +1 -0
- package/dist/esm/tests/event-log/event-log.spec.js +236 -0
- package/dist/esm/tests/event-log/event-log.spec.js.map +1 -0
- package/dist/esm/tests/event-log/event-stream.spec.js +125 -0
- package/dist/esm/tests/event-log/event-stream.spec.js.map +1 -0
- package/dist/esm/tests/features/author-delegated-grant.spec.js +1273 -0
- package/dist/esm/tests/features/author-delegated-grant.spec.js.map +1 -0
- package/dist/esm/tests/features/owner-delegated-grant.spec.js +584 -0
- package/dist/esm/tests/features/owner-delegated-grant.spec.js.map +1 -0
- package/dist/esm/tests/features/owner-signature.spec.js +192 -0
- package/dist/esm/tests/features/owner-signature.spec.js.map +1 -0
- package/dist/esm/tests/features/permissions.spec.js +815 -0
- package/dist/esm/tests/features/permissions.spec.js.map +1 -0
- package/dist/esm/tests/features/protocol-create-action.spec.js +248 -0
- package/dist/esm/tests/features/protocol-create-action.spec.js.map +1 -0
- package/dist/esm/tests/features/protocol-delete-action.spec.js +492 -0
- package/dist/esm/tests/features/protocol-delete-action.spec.js.map +1 -0
- package/dist/esm/tests/features/protocol-update-action.spec.js +572 -0
- package/dist/esm/tests/features/protocol-update-action.spec.js.map +1 -0
- package/dist/esm/tests/features/records-prune.spec.js +812 -0
- package/dist/esm/tests/features/records-prune.spec.js.map +1 -0
- package/dist/esm/tests/features/records-tags.spec.js +2516 -0
- package/dist/esm/tests/features/records-tags.spec.js.map +1 -0
- package/dist/esm/tests/features/resumable-tasks.spec.js +349 -0
- package/dist/esm/tests/features/resumable-tasks.spec.js.map +1 -0
- package/dist/esm/tests/handlers/messages-query.spec.js +349 -0
- package/dist/esm/tests/handlers/messages-query.spec.js.map +1 -0
- package/dist/esm/tests/handlers/messages-read.spec.js +647 -0
- package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -0
- package/dist/esm/tests/handlers/messages-subscribe.spec.js +432 -0
- package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -0
- package/dist/esm/tests/handlers/protocols-configure.spec.js +608 -0
- package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -0
- package/dist/esm/tests/handlers/protocols-query.spec.js +454 -0
- package/dist/esm/tests/handlers/protocols-query.spec.js.map +1 -0
- package/dist/esm/tests/handlers/records-delete.spec.js +662 -0
- package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -0
- package/dist/esm/tests/handlers/records-query.spec.js +2695 -0
- package/dist/esm/tests/handlers/records-query.spec.js.map +1 -0
- package/dist/esm/tests/handlers/records-read.spec.js +1724 -0
- package/dist/esm/tests/handlers/records-read.spec.js.map +1 -0
- package/dist/esm/tests/handlers/records-subscribe.spec.js +684 -0
- package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -0
- package/dist/esm/tests/handlers/records-write.spec.js +3637 -0
- package/dist/esm/tests/handlers/records-write.spec.js.map +1 -0
- package/dist/esm/tests/interfaces/messages-get.spec.js +78 -0
- package/dist/esm/tests/interfaces/messages-get.spec.js.map +1 -0
- package/dist/esm/tests/interfaces/messages-subscribe.spec.js +30 -0
- package/dist/esm/tests/interfaces/messages-subscribe.spec.js.map +1 -0
- package/dist/esm/tests/interfaces/messagess-query.spec.js +127 -0
- package/dist/esm/tests/interfaces/messagess-query.spec.js.map +1 -0
- package/dist/esm/tests/interfaces/protocols-configure.spec.js +489 -0
- package/dist/esm/tests/interfaces/protocols-configure.spec.js.map +1 -0
- package/dist/esm/tests/interfaces/protocols-query.spec.js +46 -0
- package/dist/esm/tests/interfaces/protocols-query.spec.js.map +1 -0
- package/dist/esm/tests/interfaces/records-delete.spec.js +39 -0
- package/dist/esm/tests/interfaces/records-delete.spec.js.map +1 -0
- package/dist/esm/tests/interfaces/records-query.spec.js +85 -0
- package/dist/esm/tests/interfaces/records-query.spec.js.map +1 -0
- package/dist/esm/tests/interfaces/records-read.spec.js +62 -0
- package/dist/esm/tests/interfaces/records-read.spec.js.map +1 -0
- package/dist/esm/tests/interfaces/records-subscribe.spec.js +72 -0
- package/dist/esm/tests/interfaces/records-subscribe.spec.js.map +1 -0
- package/dist/esm/tests/interfaces/records-write.spec.js +423 -0
- package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -0
- package/dist/esm/tests/jose/jws/general.spec.js +243 -0
- package/dist/esm/tests/jose/jws/general.spec.js.map +1 -0
- package/dist/esm/tests/protocols/permission-request.spec.js +40 -0
- package/dist/esm/tests/protocols/permission-request.spec.js.map +1 -0
- package/dist/esm/tests/protocols/permissions.spec.js +123 -0
- package/dist/esm/tests/protocols/permissions.spec.js.map +1 -0
- package/dist/esm/tests/scenarios/aggregator.spec.js +670 -0
- package/dist/esm/tests/scenarios/aggregator.spec.js.map +1 -0
- package/dist/esm/tests/scenarios/deleted-record.spec.js +102 -0
- package/dist/esm/tests/scenarios/deleted-record.spec.js.map +1 -0
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +220 -0
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -0
- package/dist/esm/tests/scenarios/messages-query.spec.js +395 -0
- package/dist/esm/tests/scenarios/messages-query.spec.js.map +1 -0
- package/dist/esm/tests/scenarios/nested-roles.spec.js +300 -0
- package/dist/esm/tests/scenarios/nested-roles.spec.js.map +1 -0
- package/dist/esm/tests/scenarios/subscriptions.spec.js +886 -0
- package/dist/esm/tests/scenarios/subscriptions.spec.js.map +1 -0
- package/dist/esm/tests/store/blockstore-mock.spec.js +192 -0
- package/dist/esm/tests/store/blockstore-mock.spec.js.map +1 -0
- package/dist/esm/tests/store/data-store-level.spec.js +146 -0
- package/dist/esm/tests/store/data-store-level.spec.js.map +1 -0
- package/dist/esm/tests/store/index-level.spec.js +1208 -0
- package/dist/esm/tests/store/index-level.spec.js.map +1 -0
- package/dist/esm/tests/store/message-store-level.spec.js +48 -0
- package/dist/esm/tests/store/message-store-level.spec.js.map +1 -0
- package/dist/esm/tests/store/message-store.spec.js +404 -0
- package/dist/esm/tests/store/message-store.spec.js.map +1 -0
- package/dist/esm/tests/store-dependent-tests.spec.js +5 -0
- package/dist/esm/tests/store-dependent-tests.spec.js.map +1 -0
- package/dist/esm/tests/test-event-stream.js +25 -0
- package/dist/esm/tests/test-event-stream.js.map +1 -0
- package/dist/esm/tests/test-stores.js +45 -0
- package/dist/esm/tests/test-stores.js.map +1 -0
- package/dist/esm/tests/test-suite.js +88 -0
- package/dist/esm/tests/test-suite.js.map +1 -0
- package/dist/esm/tests/utils/cid.spec.js +80 -0
- package/dist/esm/tests/utils/cid.spec.js.map +1 -0
- package/dist/esm/tests/utils/data-stream.spec.js +27 -0
- package/dist/esm/tests/utils/data-stream.spec.js.map +1 -0
- package/dist/esm/tests/utils/encryption.spec.js +148 -0
- package/dist/esm/tests/utils/encryption.spec.js.map +1 -0
- package/dist/esm/tests/utils/filters.spec.js +295 -0
- package/dist/esm/tests/utils/filters.spec.js.map +1 -0
- package/dist/esm/tests/utils/hd-key.spec.js +35 -0
- package/dist/esm/tests/utils/hd-key.spec.js.map +1 -0
- package/dist/esm/tests/utils/jws.spec.js +8 -0
- package/dist/esm/tests/utils/jws.spec.js.map +1 -0
- package/dist/esm/tests/utils/memory-cache.spec.js +35 -0
- package/dist/esm/tests/utils/memory-cache.spec.js.map +1 -0
- package/dist/esm/tests/utils/messages.spec.js +101 -0
- package/dist/esm/tests/utils/messages.spec.js.map +1 -0
- package/dist/esm/tests/utils/object.spec.js +36 -0
- package/dist/esm/tests/utils/object.spec.js.map +1 -0
- package/dist/esm/tests/utils/poller.js +49 -0
- package/dist/esm/tests/utils/poller.js.map +1 -0
- package/dist/esm/tests/utils/private-key-signer.spec.js +44 -0
- package/dist/esm/tests/utils/private-key-signer.spec.js.map +1 -0
- package/dist/esm/tests/utils/records.spec.js +53 -0
- package/dist/esm/tests/utils/records.spec.js.map +1 -0
- package/dist/esm/tests/utils/secp256k1.spec.js +50 -0
- package/dist/esm/tests/utils/secp256k1.spec.js.map +1 -0
- package/dist/esm/tests/utils/secp256r1.spec.js +56 -0
- package/dist/esm/tests/utils/secp256r1.spec.js.map +1 -0
- package/dist/esm/tests/utils/test-data-generator.js +643 -0
- package/dist/esm/tests/utils/test-data-generator.js.map +1 -0
- package/dist/esm/tests/utils/test-stub-generator.js +39 -0
- package/dist/esm/tests/utils/test-stub-generator.js.map +1 -0
- package/dist/esm/tests/utils/time.spec.js +64 -0
- package/dist/esm/tests/utils/time.spec.js.map +1 -0
- package/dist/esm/tests/utils/url.spec.js +43 -0
- package/dist/esm/tests/utils/url.spec.js.map +1 -0
- package/dist/esm/tests/validation/json-schemas/definitions.spec.js +33 -0
- package/dist/esm/tests/validation/json-schemas/definitions.spec.js.map +1 -0
- package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js +50 -0
- package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js.map +1 -0
- package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js +36 -0
- package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js.map +1 -0
- package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js +82 -0
- package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js.map +1 -0
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js +75 -0
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js.map +1 -0
- package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js +148 -0
- package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js.map +1 -0
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js +421 -0
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js.map +1 -0
- package/dist/esm/tests/vectors/protocol-definitions/anyone-collaborate.json +21 -0
- package/dist/esm/tests/vectors/protocol-definitions/author-can.json +33 -0
- package/dist/esm/tests/vectors/protocol-definitions/chat.json +70 -0
- package/dist/esm/tests/vectors/protocol-definitions/credential-issuance.json +41 -0
- package/dist/esm/tests/vectors/protocol-definitions/dex.json +58 -0
- package/dist/esm/tests/vectors/protocol-definitions/email.json +62 -0
- package/dist/esm/tests/vectors/protocol-definitions/free-for-all.json +45 -0
- package/dist/esm/tests/vectors/protocol-definitions/friend-role.json +48 -0
- package/dist/esm/tests/vectors/protocol-definitions/message.json +37 -0
- package/dist/esm/tests/vectors/protocol-definitions/minimal.json +10 -0
- package/dist/esm/tests/vectors/protocol-definitions/nested.json +31 -0
- package/dist/esm/tests/vectors/protocol-definitions/private-protocol.json +15 -0
- package/dist/esm/tests/vectors/protocol-definitions/recipient-can.json +33 -0
- package/dist/esm/tests/vectors/protocol-definitions/slack.json +242 -0
- package/dist/esm/tests/vectors/protocol-definitions/social-media.json +106 -0
- package/dist/esm/tests/vectors/protocol-definitions/thread-role.json +70 -0
- package/dist/types/generated/precompiled-validators.d.ts +597 -0
- package/dist/types/generated/precompiled-validators.d.ts.map +1 -0
- package/dist/types/src/core/abstract-message.d.ts +25 -0
- package/dist/types/src/core/abstract-message.d.ts.map +1 -0
- package/dist/types/src/core/auth.d.ts +9 -0
- package/dist/types/src/core/auth.d.ts.map +1 -0
- package/dist/types/src/core/dwn-constant.d.ts +10 -0
- package/dist/types/src/core/dwn-constant.d.ts.map +1 -0
- package/dist/types/src/core/dwn-error.d.ts +164 -0
- package/dist/types/src/core/dwn-error.d.ts.map +1 -0
- package/dist/types/src/core/grant-authorization.d.ts +43 -0
- package/dist/types/src/core/grant-authorization.d.ts.map +1 -0
- package/dist/types/src/core/message-reply.d.ts +32 -0
- package/dist/types/src/core/message-reply.d.ts.map +1 -0
- package/dist/types/src/core/message.d.ts +94 -0
- package/dist/types/src/core/message.d.ts.map +1 -0
- package/dist/types/src/core/messages-grant-authorization.d.ts +34 -0
- package/dist/types/src/core/messages-grant-authorization.d.ts.map +1 -0
- package/dist/types/src/core/protocol-authorization.d.ts +103 -0
- package/dist/types/src/core/protocol-authorization.d.ts.map +1 -0
- package/dist/types/src/core/protocols-grant-authorization.d.ts +31 -0
- package/dist/types/src/core/protocols-grant-authorization.d.ts.map +1 -0
- package/dist/types/src/core/records-grant-authorization.d.ts +60 -0
- package/dist/types/src/core/records-grant-authorization.d.ts.map +1 -0
- package/dist/types/src/core/resumable-task-manager.d.ts +43 -0
- package/dist/types/src/core/resumable-task-manager.d.ts.map +1 -0
- package/dist/types/src/core/tenant-gate.d.ts +29 -0
- package/dist/types/src/core/tenant-gate.d.ts.map +1 -0
- package/dist/types/src/dwn.d.ts +85 -0
- package/dist/types/src/dwn.d.ts.map +1 -0
- package/dist/types/src/enums/dwn-interface-method.d.ts +14 -0
- package/dist/types/src/enums/dwn-interface-method.d.ts.map +1 -0
- package/dist/types/src/event-log/event-emitter-stream.d.ts +23 -0
- package/dist/types/src/event-log/event-emitter-stream.d.ts.map +1 -0
- package/dist/types/src/event-log/event-log-level.d.ts +35 -0
- package/dist/types/src/event-log/event-log-level.d.ts.map +1 -0
- package/dist/types/src/handlers/messages-query.d.ts +17 -0
- package/dist/types/src/handlers/messages-query.d.ts.map +1 -0
- package/dist/types/src/handlers/messages-read.d.ts +22 -0
- package/dist/types/src/handlers/messages-read.d.ts.map +1 -0
- package/dist/types/src/handlers/messages-subscribe.d.ts +18 -0
- package/dist/types/src/handlers/messages-subscribe.d.ts.map +1 -0
- package/dist/types/src/handlers/protocols-configure.d.ts +24 -0
- package/dist/types/src/handlers/protocols-configure.d.ts.map +1 -0
- package/dist/types/src/handlers/protocols-query.d.ts +20 -0
- package/dist/types/src/handlers/protocols-query.d.ts.map +1 -0
- package/dist/types/src/handlers/records-delete.d.ts +23 -0
- package/dist/types/src/handlers/records-delete.d.ts.map +1 -0
- package/dist/types/src/handlers/records-query.d.ts +70 -0
- package/dist/types/src/handlers/records-query.d.ts.map +1 -0
- package/dist/types/src/handlers/records-read.d.ts +20 -0
- package/dist/types/src/handlers/records-read.d.ts.map +1 -0
- package/dist/types/src/handlers/records-subscribe.d.ts +62 -0
- package/dist/types/src/handlers/records-subscribe.d.ts.map +1 -0
- package/dist/types/src/handlers/records-write.d.ts +51 -0
- package/dist/types/src/handlers/records-write.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +63 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/interfaces/messages-query.d.ts +16 -0
- package/dist/types/src/interfaces/messages-query.d.ts.map +1 -0
- package/dist/types/src/interfaces/messages-read.d.ts +20 -0
- package/dist/types/src/interfaces/messages-read.d.ts.map +1 -0
- package/dist/types/src/interfaces/messages-subscribe.d.ts +20 -0
- package/dist/types/src/interfaces/messages-subscribe.d.ts.map +1 -0
- package/dist/types/src/interfaces/protocols-configure.d.ts +40 -0
- package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -0
- package/dist/types/src/interfaces/protocols-query.d.ts +17 -0
- package/dist/types/src/interfaces/protocols-query.d.ts.map +1 -0
- package/dist/types/src/interfaces/records-delete.d.ts +34 -0
- package/dist/types/src/interfaces/records-delete.d.ts.map +1 -0
- package/dist/types/src/interfaces/records-query.d.ts +31 -0
- package/dist/types/src/interfaces/records-query.d.ts.map +1 -0
- package/dist/types/src/interfaces/records-read.d.ts +36 -0
- package/dist/types/src/interfaces/records-read.d.ts.map +1 -0
- package/dist/types/src/interfaces/records-subscribe.d.ts +27 -0
- package/dist/types/src/interfaces/records-subscribe.d.ts.map +1 -0
- package/dist/types/src/interfaces/records-write.d.ts +309 -0
- package/dist/types/src/interfaces/records-write.d.ts.map +1 -0
- package/dist/types/src/jose/algorithms/signing/ed25519.d.ts +3 -0
- package/dist/types/src/jose/algorithms/signing/ed25519.d.ts.map +1 -0
- package/dist/types/src/jose/algorithms/signing/signature-algorithms.d.ts +3 -0
- package/dist/types/src/jose/algorithms/signing/signature-algorithms.d.ts.map +1 -0
- package/dist/types/src/jose/jws/general/builder.d.ts +10 -0
- package/dist/types/src/jose/jws/general/builder.d.ts.map +1 -0
- package/dist/types/src/jose/jws/general/verifier.d.ts +32 -0
- package/dist/types/src/jose/jws/general/verifier.d.ts.map +1 -0
- package/dist/types/src/protocols/permission-grant.d.ts +50 -0
- package/dist/types/src/protocols/permission-grant.d.ts.map +1 -0
- package/dist/types/src/protocols/permission-request.d.ts +35 -0
- package/dist/types/src/protocols/permission-request.d.ts.map +1 -0
- package/dist/types/src/protocols/permissions.d.ts +150 -0
- package/dist/types/src/protocols/permissions.d.ts.map +1 -0
- package/dist/types/src/schema-validator.d.ts +8 -0
- package/dist/types/src/schema-validator.d.ts.map +1 -0
- package/dist/types/src/store/blockstore-level.d.ts +34 -0
- package/dist/types/src/store/blockstore-level.d.ts.map +1 -0
- package/dist/types/src/store/blockstore-mock.d.ts +27 -0
- package/dist/types/src/store/blockstore-mock.d.ts.map +1 -0
- package/dist/types/src/store/data-store-level.d.ts +34 -0
- package/dist/types/src/store/data-store-level.d.ts.map +1 -0
- package/dist/types/src/store/index-level.d.ts +171 -0
- package/dist/types/src/store/index-level.d.ts.map +1 -0
- package/dist/types/src/store/level-wrapper.d.ts +48 -0
- package/dist/types/src/store/level-wrapper.d.ts.map +1 -0
- package/dist/types/src/store/message-store-level.d.ts +46 -0
- package/dist/types/src/store/message-store-level.d.ts.map +1 -0
- package/dist/types/src/store/resumable-task-store-level.d.ts +28 -0
- package/dist/types/src/store/resumable-task-store-level.d.ts.map +1 -0
- package/dist/types/src/store/storage-controller.d.ts +46 -0
- package/dist/types/src/store/storage-controller.d.ts.map +1 -0
- package/dist/types/src/types/cache.d.ts +16 -0
- package/dist/types/src/types/cache.d.ts.map +1 -0
- package/dist/types/src/types/data-store.d.ts +57 -0
- package/dist/types/src/types/data-store.d.ts.map +1 -0
- package/dist/types/src/types/event-log.d.ts +52 -0
- package/dist/types/src/types/event-log.d.ts.map +1 -0
- package/dist/types/src/types/jose-types.d.ts +75 -0
- package/dist/types/src/types/jose-types.d.ts.map +1 -0
- package/dist/types/src/types/jws-types.d.ts +27 -0
- package/dist/types/src/types/jws-types.d.ts.map +1 -0
- package/dist/types/src/types/message-interface.d.ts +27 -0
- package/dist/types/src/types/message-interface.d.ts.map +1 -0
- package/dist/types/src/types/message-store.d.ts +42 -0
- package/dist/types/src/types/message-store.d.ts.map +1 -0
- package/dist/types/src/types/message-types.d.ts +116 -0
- package/dist/types/src/types/message-types.d.ts.map +1 -0
- package/dist/types/src/types/messages-types.d.ts +65 -0
- package/dist/types/src/types/messages-types.d.ts.map +1 -0
- package/dist/types/src/types/method-handler.d.ts +19 -0
- package/dist/types/src/types/method-handler.d.ts.map +1 -0
- package/dist/types/src/types/permission-types.d.ts +93 -0
- package/dist/types/src/types/permission-types.d.ts.map +1 -0
- package/dist/types/src/types/protocols-types.d.ts +154 -0
- package/dist/types/src/types/protocols-types.d.ts.map +1 -0
- package/dist/types/src/types/query-types.d.ts +66 -0
- package/dist/types/src/types/query-types.d.ts.map +1 -0
- package/dist/types/src/types/records-types.d.ts +230 -0
- package/dist/types/src/types/records-types.d.ts.map +1 -0
- package/dist/types/src/types/resumable-task-store.d.ts +89 -0
- package/dist/types/src/types/resumable-task-store.d.ts.map +1 -0
- package/dist/types/src/types/signer.d.ts +26 -0
- package/dist/types/src/types/signer.d.ts.map +1 -0
- package/dist/types/src/types/subscriptions.d.ts +30 -0
- package/dist/types/src/types/subscriptions.d.ts.map +1 -0
- package/dist/types/src/utils/abort.d.ts +5 -0
- package/dist/types/src/utils/abort.d.ts.map +1 -0
- package/dist/types/src/utils/array.d.ts +18 -0
- package/dist/types/src/utils/array.d.ts.map +1 -0
- package/dist/types/src/utils/cid.d.ts +30 -0
- package/dist/types/src/utils/cid.d.ts.map +1 -0
- package/dist/types/src/utils/data-stream.d.ts +31 -0
- package/dist/types/src/utils/data-stream.d.ts.map +1 -0
- package/dist/types/src/utils/encoder.d.ts +14 -0
- package/dist/types/src/utils/encoder.d.ts.map +1 -0
- package/dist/types/src/utils/encryption.d.ts +44 -0
- package/dist/types/src/utils/encryption.d.ts.map +1 -0
- package/dist/types/src/utils/filter.d.ts +60 -0
- package/dist/types/src/utils/filter.d.ts.map +1 -0
- package/dist/types/src/utils/hd-key.d.ts +54 -0
- package/dist/types/src/utils/hd-key.d.ts.map +1 -0
- package/dist/types/src/utils/jws.d.ts +39 -0
- package/dist/types/src/utils/jws.d.ts.map +1 -0
- package/dist/types/src/utils/memory-cache.d.ts +15 -0
- package/dist/types/src/utils/memory-cache.d.ts.map +1 -0
- package/dist/types/src/utils/messages.d.ts +27 -0
- package/dist/types/src/utils/messages.d.ts.map +1 -0
- package/dist/types/src/utils/object.d.ts +13 -0
- package/dist/types/src/utils/object.d.ts.map +1 -0
- package/dist/types/src/utils/private-key-signer.d.ts +34 -0
- package/dist/types/src/utils/private-key-signer.d.ts.map +1 -0
- package/dist/types/src/utils/protocols.d.ts +14 -0
- package/dist/types/src/utils/protocols.d.ts.map +1 -0
- package/dist/types/src/utils/records.d.ts +122 -0
- package/dist/types/src/utils/records.d.ts.map +1 -0
- package/dist/types/src/utils/secp256k1.d.ts +59 -0
- package/dist/types/src/utils/secp256k1.d.ts.map +1 -0
- package/dist/types/src/utils/secp256r1.d.ts +39 -0
- package/dist/types/src/utils/secp256r1.d.ts.map +1 -0
- package/dist/types/src/utils/string.d.ts +6 -0
- package/dist/types/src/utils/string.d.ts.map +1 -0
- package/dist/types/src/utils/time.d.ts +50 -0
- package/dist/types/src/utils/time.d.ts.map +1 -0
- package/dist/types/src/utils/url.d.ts +5 -0
- package/dist/types/src/utils/url.d.ts.map +1 -0
- package/dist/types/tests/core/auth.spec.d.ts +2 -0
- package/dist/types/tests/core/auth.spec.d.ts.map +1 -0
- package/dist/types/tests/core/message-reply.spec.d.ts +2 -0
- package/dist/types/tests/core/message-reply.spec.d.ts.map +1 -0
- package/dist/types/tests/core/message.spec.d.ts +2 -0
- package/dist/types/tests/core/message.spec.d.ts.map +1 -0
- package/dist/types/tests/core/protocol-authorization.spec.d.ts +2 -0
- package/dist/types/tests/core/protocol-authorization.spec.d.ts.map +1 -0
- package/dist/types/tests/dwn.spec.d.ts +2 -0
- package/dist/types/tests/dwn.spec.d.ts.map +1 -0
- package/dist/types/tests/event-log/event-emitter-stream.spec.d.ts +2 -0
- package/dist/types/tests/event-log/event-emitter-stream.spec.d.ts.map +1 -0
- package/dist/types/tests/event-log/event-log-level.spec.d.ts +2 -0
- package/dist/types/tests/event-log/event-log-level.spec.d.ts.map +1 -0
- package/dist/types/tests/event-log/event-log.spec.d.ts +2 -0
- package/dist/types/tests/event-log/event-log.spec.d.ts.map +1 -0
- package/dist/types/tests/event-log/event-stream.spec.d.ts +2 -0
- package/dist/types/tests/event-log/event-stream.spec.d.ts.map +1 -0
- package/dist/types/tests/features/author-delegated-grant.spec.d.ts +2 -0
- package/dist/types/tests/features/author-delegated-grant.spec.d.ts.map +1 -0
- package/dist/types/tests/features/owner-delegated-grant.spec.d.ts +2 -0
- package/dist/types/tests/features/owner-delegated-grant.spec.d.ts.map +1 -0
- package/dist/types/tests/features/owner-signature.spec.d.ts +2 -0
- package/dist/types/tests/features/owner-signature.spec.d.ts.map +1 -0
- package/dist/types/tests/features/permissions.spec.d.ts +2 -0
- package/dist/types/tests/features/permissions.spec.d.ts.map +1 -0
- package/dist/types/tests/features/protocol-create-action.spec.d.ts +2 -0
- package/dist/types/tests/features/protocol-create-action.spec.d.ts.map +1 -0
- package/dist/types/tests/features/protocol-delete-action.spec.d.ts +2 -0
- package/dist/types/tests/features/protocol-delete-action.spec.d.ts.map +1 -0
- package/dist/types/tests/features/protocol-update-action.spec.d.ts +2 -0
- package/dist/types/tests/features/protocol-update-action.spec.d.ts.map +1 -0
- package/dist/types/tests/features/records-prune.spec.d.ts +2 -0
- package/dist/types/tests/features/records-prune.spec.d.ts.map +1 -0
- package/dist/types/tests/features/records-tags.spec.d.ts +2 -0
- package/dist/types/tests/features/records-tags.spec.d.ts.map +1 -0
- package/dist/types/tests/features/resumable-tasks.spec.d.ts +2 -0
- package/dist/types/tests/features/resumable-tasks.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/messages-query.spec.d.ts +2 -0
- package/dist/types/tests/handlers/messages-query.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/messages-read.spec.d.ts +2 -0
- package/dist/types/tests/handlers/messages-read.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/messages-subscribe.spec.d.ts +2 -0
- package/dist/types/tests/handlers/messages-subscribe.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/protocols-configure.spec.d.ts +2 -0
- package/dist/types/tests/handlers/protocols-configure.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/protocols-query.spec.d.ts +2 -0
- package/dist/types/tests/handlers/protocols-query.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/records-delete.spec.d.ts +2 -0
- package/dist/types/tests/handlers/records-delete.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/records-query.spec.d.ts +2 -0
- package/dist/types/tests/handlers/records-query.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/records-read.spec.d.ts +2 -0
- package/dist/types/tests/handlers/records-read.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/records-subscribe.spec.d.ts +2 -0
- package/dist/types/tests/handlers/records-subscribe.spec.d.ts.map +1 -0
- package/dist/types/tests/handlers/records-write.spec.d.ts +2 -0
- package/dist/types/tests/handlers/records-write.spec.d.ts.map +1 -0
- package/dist/types/tests/interfaces/messages-get.spec.d.ts +2 -0
- package/dist/types/tests/interfaces/messages-get.spec.d.ts.map +1 -0
- package/dist/types/tests/interfaces/messages-subscribe.spec.d.ts +2 -0
- package/dist/types/tests/interfaces/messages-subscribe.spec.d.ts.map +1 -0
- package/dist/types/tests/interfaces/messagess-query.spec.d.ts +2 -0
- package/dist/types/tests/interfaces/messagess-query.spec.d.ts.map +1 -0
- package/dist/types/tests/interfaces/protocols-configure.spec.d.ts +2 -0
- package/dist/types/tests/interfaces/protocols-configure.spec.d.ts.map +1 -0
- package/dist/types/tests/interfaces/protocols-query.spec.d.ts +2 -0
- package/dist/types/tests/interfaces/protocols-query.spec.d.ts.map +1 -0
- package/dist/types/tests/interfaces/records-delete.spec.d.ts +2 -0
- package/dist/types/tests/interfaces/records-delete.spec.d.ts.map +1 -0
- package/dist/types/tests/interfaces/records-query.spec.d.ts +2 -0
- package/dist/types/tests/interfaces/records-query.spec.d.ts.map +1 -0
- package/dist/types/tests/interfaces/records-read.spec.d.ts +2 -0
- package/dist/types/tests/interfaces/records-read.spec.d.ts.map +1 -0
- package/dist/types/tests/interfaces/records-subscribe.spec.d.ts +2 -0
- package/dist/types/tests/interfaces/records-subscribe.spec.d.ts.map +1 -0
- package/dist/types/tests/interfaces/records-write.spec.d.ts +2 -0
- package/dist/types/tests/interfaces/records-write.spec.d.ts.map +1 -0
- package/dist/types/tests/jose/jws/general.spec.d.ts +2 -0
- package/dist/types/tests/jose/jws/general.spec.d.ts.map +1 -0
- package/dist/types/tests/protocols/permission-request.spec.d.ts +2 -0
- package/dist/types/tests/protocols/permission-request.spec.d.ts.map +1 -0
- package/dist/types/tests/protocols/permissions.spec.d.ts +2 -0
- package/dist/types/tests/protocols/permissions.spec.d.ts.map +1 -0
- package/dist/types/tests/scenarios/aggregator.spec.d.ts +2 -0
- package/dist/types/tests/scenarios/aggregator.spec.d.ts.map +1 -0
- package/dist/types/tests/scenarios/deleted-record.spec.d.ts +2 -0
- package/dist/types/tests/scenarios/deleted-record.spec.d.ts.map +1 -0
- package/dist/types/tests/scenarios/end-to-end-tests.spec.d.ts +2 -0
- package/dist/types/tests/scenarios/end-to-end-tests.spec.d.ts.map +1 -0
- package/dist/types/tests/scenarios/messages-query.spec.d.ts +2 -0
- package/dist/types/tests/scenarios/messages-query.spec.d.ts.map +1 -0
- package/dist/types/tests/scenarios/nested-roles.spec.d.ts +2 -0
- package/dist/types/tests/scenarios/nested-roles.spec.d.ts.map +1 -0
- package/dist/types/tests/scenarios/subscriptions.spec.d.ts +2 -0
- package/dist/types/tests/scenarios/subscriptions.spec.d.ts.map +1 -0
- package/dist/types/tests/store/blockstore-mock.spec.d.ts +2 -0
- package/dist/types/tests/store/blockstore-mock.spec.d.ts.map +1 -0
- package/dist/types/tests/store/data-store-level.spec.d.ts +2 -0
- package/dist/types/tests/store/data-store-level.spec.d.ts.map +1 -0
- package/dist/types/tests/store/index-level.spec.d.ts +2 -0
- package/dist/types/tests/store/index-level.spec.d.ts.map +1 -0
- package/dist/types/tests/store/message-store-level.spec.d.ts +2 -0
- package/dist/types/tests/store/message-store-level.spec.d.ts.map +1 -0
- package/dist/types/tests/store/message-store.spec.d.ts +2 -0
- package/dist/types/tests/store/message-store.spec.d.ts.map +1 -0
- package/dist/types/tests/store-dependent-tests.spec.d.ts +2 -0
- package/dist/types/tests/store-dependent-tests.spec.d.ts.map +1 -0
- package/dist/types/tests/test-event-stream.d.ts +22 -0
- package/dist/types/tests/test-event-stream.d.ts.map +1 -0
- package/dist/types/tests/test-stores.d.ts +33 -0
- package/dist/types/tests/test-stores.d.ts.map +1 -0
- package/dist/types/tests/test-suite.d.ts +18 -0
- package/dist/types/tests/test-suite.d.ts.map +1 -0
- package/dist/types/tests/utils/cid.spec.d.ts +2 -0
- package/dist/types/tests/utils/cid.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/data-stream.spec.d.ts +2 -0
- package/dist/types/tests/utils/data-stream.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/encryption.spec.d.ts +2 -0
- package/dist/types/tests/utils/encryption.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/filters.spec.d.ts +2 -0
- package/dist/types/tests/utils/filters.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/hd-key.spec.d.ts +2 -0
- package/dist/types/tests/utils/hd-key.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/jws.spec.d.ts +2 -0
- package/dist/types/tests/utils/jws.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/memory-cache.spec.d.ts +2 -0
- package/dist/types/tests/utils/memory-cache.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/messages.spec.d.ts +2 -0
- package/dist/types/tests/utils/messages.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/object.spec.d.ts +2 -0
- package/dist/types/tests/utils/object.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/poller.d.ts +21 -0
- package/dist/types/tests/utils/poller.d.ts.map +1 -0
- package/dist/types/tests/utils/private-key-signer.spec.d.ts +2 -0
- package/dist/types/tests/utils/private-key-signer.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/records.spec.d.ts +2 -0
- package/dist/types/tests/utils/records.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/secp256k1.spec.d.ts +2 -0
- package/dist/types/tests/utils/secp256k1.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/secp256r1.spec.d.ts +2 -0
- package/dist/types/tests/utils/secp256r1.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/test-data-generator.d.ts +342 -0
- package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -0
- package/dist/types/tests/utils/test-stub-generator.d.ts +16 -0
- package/dist/types/tests/utils/test-stub-generator.d.ts.map +1 -0
- package/dist/types/tests/utils/time.spec.d.ts +2 -0
- package/dist/types/tests/utils/time.spec.d.ts.map +1 -0
- package/dist/types/tests/utils/url.spec.d.ts +2 -0
- package/dist/types/tests/utils/url.spec.d.ts.map +1 -0
- package/dist/types/tests/validation/json-schemas/definitions.spec.d.ts +2 -0
- package/dist/types/tests/validation/json-schemas/definitions.spec.d.ts.map +1 -0
- package/dist/types/tests/validation/json-schemas/jwk/general-jwk.spec.d.ts +2 -0
- package/dist/types/tests/validation/json-schemas/jwk/general-jwk.spec.d.ts.map +1 -0
- package/dist/types/tests/validation/json-schemas/jwk/public-jwk.spec.d.ts +2 -0
- package/dist/types/tests/validation/json-schemas/jwk/public-jwk.spec.d.ts.map +1 -0
- package/dist/types/tests/validation/json-schemas/jwk-verification-method.spec.d.ts +2 -0
- package/dist/types/tests/validation/json-schemas/jwk-verification-method.spec.d.ts.map +1 -0
- package/dist/types/tests/validation/json-schemas/protocols/protocols-configure.spec.d.ts +2 -0
- package/dist/types/tests/validation/json-schemas/protocols/protocols-configure.spec.d.ts.map +1 -0
- package/dist/types/tests/validation/json-schemas/records/records-query.spec.d.ts +2 -0
- package/dist/types/tests/validation/json-schemas/records/records-query.spec.d.ts.map +1 -0
- package/dist/types/tests/validation/json-schemas/records/records-write.spec.d.ts +2 -0
- package/dist/types/tests/validation/json-schemas/records/records-write.spec.d.ts.map +1 -0
- package/package.json +167 -0
- package/src/core/abstract-message.ts +62 -0
- package/src/core/auth.ts +36 -0
- package/src/core/dwn-constant.ts +9 -0
- package/src/core/dwn-error.ts +167 -0
- package/src/core/grant-authorization.ts +148 -0
- package/src/core/message-reply.ts +41 -0
- package/src/core/message.ts +259 -0
- package/src/core/messages-grant-authorization.ts +134 -0
- package/src/core/protocol-authorization.ts +903 -0
- package/src/core/protocols-grant-authorization.ts +88 -0
- package/src/core/records-grant-authorization.ts +197 -0
- package/src/core/resumable-task-manager.ts +114 -0
- package/src/core/tenant-gate.ts +33 -0
- package/src/dwn.ts +264 -0
- package/src/enums/dwn-interface-method.ts +14 -0
- package/src/event-log/event-emitter-stream.ts +69 -0
- package/src/event-log/event-log-level.ts +72 -0
- package/src/handlers/messages-query.ts +67 -0
- package/src/handlers/messages-read.ts +103 -0
- package/src/handlers/messages-subscribe.ts +89 -0
- package/src/handlers/protocols-configure.ts +137 -0
- package/src/handlers/protocols-query.ts +82 -0
- package/src/handlers/records-delete.ts +124 -0
- package/src/handlers/records-query.ts +262 -0
- package/src/handlers/records-read.ts +187 -0
- package/src/handlers/records-subscribe.ts +218 -0
- package/src/handlers/records-write.ts +404 -0
- package/src/index.ts +67 -0
- package/src/interfaces/messages-query.ts +60 -0
- package/src/interfaces/messages-read.ts +63 -0
- package/src/interfaces/messages-subscribe.ts +64 -0
- package/src/interfaces/protocols-configure.ts +340 -0
- package/src/interfaces/protocols-query.ts +96 -0
- package/src/interfaces/records-delete.ts +117 -0
- package/src/interfaces/records-query.ts +131 -0
- package/src/interfaces/records-read.ts +100 -0
- package/src/interfaces/records-subscribe.ts +104 -0
- package/src/interfaces/records-write.ts +1072 -0
- package/src/jose/algorithms/signing/ed25519.ts +58 -0
- package/src/jose/algorithms/signing/signature-algorithms.ts +22 -0
- package/src/jose/jws/general/builder.ts +48 -0
- package/src/jose/jws/general/verifier.ts +112 -0
- package/src/protocols/permission-grant.ts +86 -0
- package/src/protocols/permission-request.ts +63 -0
- package/src/protocols/permissions.ts +508 -0
- package/src/schema-validator.ts +46 -0
- package/src/store/blockstore-level.ts +113 -0
- package/src/store/blockstore-mock.ts +80 -0
- package/src/store/data-store-level.ts +120 -0
- package/src/store/index-level.ts +691 -0
- package/src/store/level-wrapper.ts +272 -0
- package/src/store/message-store-level.ts +195 -0
- package/src/store/resumable-task-store-level.ts +120 -0
- package/src/store/storage-controller.ts +240 -0
- package/src/types/cache.ts +16 -0
- package/src/types/data-store.ts +64 -0
- package/src/types/event-log.ts +52 -0
- package/src/types/jose-types.ts +76 -0
- package/src/types/jws-types.ts +28 -0
- package/src/types/message-interface.ts +30 -0
- package/src/types/message-store.ts +57 -0
- package/src/types/message-types.ts +132 -0
- package/src/types/messages-types.ts +77 -0
- package/src/types/method-handler.ts +19 -0
- package/src/types/permission-types.ts +110 -0
- package/src/types/protocols-types.ts +177 -0
- package/src/types/query-types.ts +61 -0
- package/src/types/records-types.ts +263 -0
- package/src/types/resumable-task-store.ts +96 -0
- package/src/types/signer.ts +27 -0
- package/src/types/subscriptions.ts +34 -0
- package/src/utils/abort.ts +31 -0
- package/src/utils/array.ts +39 -0
- package/src/utils/cid.ts +101 -0
- package/src/utils/data-stream.ts +99 -0
- package/src/utils/encoder.ts +54 -0
- package/src/utils/encryption.ts +145 -0
- package/src/utils/filter.ts +245 -0
- package/src/utils/hd-key.ts +126 -0
- package/src/utils/jws.ts +95 -0
- package/src/utils/memory-cache.ts +31 -0
- package/src/utils/messages.ts +109 -0
- package/src/utils/object.ts +43 -0
- package/src/utils/private-key-signer.ts +72 -0
- package/src/utils/protocols.ts +50 -0
- package/src/utils/records.ts +559 -0
- package/src/utils/secp256k1.ts +157 -0
- package/src/utils/secp256r1.ts +142 -0
- package/src/utils/string.ts +13 -0
- package/src/utils/time.ts +78 -0
- package/src/utils/url.ts +65 -0
|
@@ -0,0 +1,2695 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
11
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
12
|
+
var m = o[Symbol.asyncIterator], i;
|
|
13
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
14
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
15
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
16
|
+
};
|
|
17
|
+
import chaiAsPromised from 'chai-as-promised';
|
|
18
|
+
import sinon from 'sinon';
|
|
19
|
+
import chai, { expect } from 'chai';
|
|
20
|
+
import freeForAll from '../vectors/protocol-definitions/free-for-all.json' assert { type: 'json' };
|
|
21
|
+
import friendRoleProtocolDefinition from '../vectors/protocol-definitions/friend-role.json' assert { type: 'json' };
|
|
22
|
+
import nestedProtocol from '../vectors/protocol-definitions/nested.json' assert { type: 'json' };
|
|
23
|
+
import threadRoleProtocolDefinition from '../vectors/protocol-definitions/thread-role.json' assert { type: 'json' };
|
|
24
|
+
import { ArrayUtility } from '../../src/utils/array.js';
|
|
25
|
+
import { DateSort } from '../../src/types/records-types.js';
|
|
26
|
+
import { DwnConstant } from '../../src/core/dwn-constant.js';
|
|
27
|
+
import { DwnErrorCode } from '../../src/core/dwn-error.js';
|
|
28
|
+
import { Encoder } from '../../src/utils/encoder.js';
|
|
29
|
+
import { Jws } from '../../src/utils/jws.js';
|
|
30
|
+
import { Message } from '../../src/core/message.js';
|
|
31
|
+
import { RecordsQuery } from '../../src/interfaces/records-query.js';
|
|
32
|
+
import { RecordsQueryHandler } from '../../src/handlers/records-query.js';
|
|
33
|
+
import { RecordsWriteHandler } from '../../src/handlers/records-write.js';
|
|
34
|
+
import { TestDataGenerator } from '../utils/test-data-generator.js';
|
|
35
|
+
import { TestEventStream } from '../test-event-stream.js';
|
|
36
|
+
import { TestStores } from '../test-stores.js';
|
|
37
|
+
import { TestStubGenerator } from '../utils/test-stub-generator.js';
|
|
38
|
+
import { DataStoreLevel, Dwn, MessageStoreLevel, RecordsWrite, Time } from '../../src/index.js';
|
|
39
|
+
import { DidKey, UniversalResolver } from '@enbox/dids';
|
|
40
|
+
chai.use(chaiAsPromised);
|
|
41
|
+
export function testRecordsQueryHandler() {
|
|
42
|
+
describe('RecordsQueryHandler.handle()', () => {
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
sinon.restore(); // wipe all previous stubs/spies/mocks/fakes
|
|
45
|
+
});
|
|
46
|
+
describe('functional tests', () => {
|
|
47
|
+
let didResolver;
|
|
48
|
+
let messageStore;
|
|
49
|
+
let dataStore;
|
|
50
|
+
let resumableTaskStore;
|
|
51
|
+
let eventLog;
|
|
52
|
+
let eventStream;
|
|
53
|
+
let dwn;
|
|
54
|
+
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
|
|
55
|
+
// so that different test suites can reuse the same backend store for testing
|
|
56
|
+
before(() => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
didResolver = new UniversalResolver({ didResolvers: [DidKey] });
|
|
58
|
+
const stores = TestStores.get();
|
|
59
|
+
messageStore = stores.messageStore;
|
|
60
|
+
dataStore = stores.dataStore;
|
|
61
|
+
resumableTaskStore = stores.resumableTaskStore;
|
|
62
|
+
eventLog = stores.eventLog;
|
|
63
|
+
eventStream = TestEventStream.get();
|
|
64
|
+
dwn = yield Dwn.create({ didResolver, messageStore, dataStore, eventLog, eventStream, resumableTaskStore });
|
|
65
|
+
}));
|
|
66
|
+
beforeEach(() => __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
// clean up before each test rather than after so that a test does not depend on other tests to do the clean up
|
|
68
|
+
yield messageStore.clear();
|
|
69
|
+
yield dataStore.clear();
|
|
70
|
+
yield resumableTaskStore.clear();
|
|
71
|
+
yield eventLog.clear();
|
|
72
|
+
}));
|
|
73
|
+
after(() => __awaiter(this, void 0, void 0, function* () {
|
|
74
|
+
yield dwn.close();
|
|
75
|
+
}));
|
|
76
|
+
it('should reject when published is set to false with a dateSort set to sorting by `PublishedAscending` or `PublishedDescending`', () => __awaiter(this, void 0, void 0, function* () {
|
|
77
|
+
const alice = yield TestDataGenerator.generatePersona();
|
|
78
|
+
TestStubGenerator.stubDidResolver(didResolver, [alice]);
|
|
79
|
+
const query = yield TestDataGenerator.generateRecordsQuery({ author: alice, filter: { published: false } });
|
|
80
|
+
//control
|
|
81
|
+
let reply = yield dwn.processMessage(alice.did, query.message);
|
|
82
|
+
expect(reply.status.code).to.equal(200);
|
|
83
|
+
// modify dateSort to publishedAscending
|
|
84
|
+
query.message.descriptor.dateSort = DateSort.PublishedAscending;
|
|
85
|
+
reply = yield dwn.processMessage(alice.did, query.message);
|
|
86
|
+
expect(reply.status.code).to.equal(400);
|
|
87
|
+
expect(reply.status.detail).to.include('queries must not filter for `published:false` and sort');
|
|
88
|
+
// modify dateSort to publishedDescending
|
|
89
|
+
query.message.descriptor.dateSort = DateSort.PublishedDescending;
|
|
90
|
+
reply = yield dwn.processMessage(alice.did, query.message);
|
|
91
|
+
expect(reply.status.code).to.equal(400);
|
|
92
|
+
expect(reply.status.detail).to.include('queries must not filter for `published:false` and sort');
|
|
93
|
+
}));
|
|
94
|
+
it('should return recordId, descriptor, authorization and attestation', () => __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
var _a;
|
|
96
|
+
const alice = yield TestDataGenerator.generatePersona();
|
|
97
|
+
const bob = yield TestDataGenerator.generatePersona();
|
|
98
|
+
TestStubGenerator.stubDidResolver(didResolver, [alice, bob]);
|
|
99
|
+
const dataFormat = 'myAwesomeDataFormat';
|
|
100
|
+
const write = yield TestDataGenerator.generateRecordsWrite({ author: alice, attesters: [bob], dataFormat });
|
|
101
|
+
const writeReply = yield dwn.processMessage(alice.did, write.message, { dataStream: write.dataStream });
|
|
102
|
+
expect(writeReply.status.code).to.equal(202);
|
|
103
|
+
const query = yield TestDataGenerator.generateRecordsQuery({ author: alice, filter: { dataFormat } });
|
|
104
|
+
const reply = yield dwn.processMessage(alice.did, query.message);
|
|
105
|
+
expect((_a = reply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(1);
|
|
106
|
+
const entry = reply.entries[0];
|
|
107
|
+
expect(entry.authorization).to.deep.equal(write.message.authorization);
|
|
108
|
+
expect(entry.attestation).to.deep.equal(write.message.attestation);
|
|
109
|
+
expect(entry.descriptor).to.deep.equal(write.message.descriptor);
|
|
110
|
+
expect(entry.recordId).to.equal(write.message.recordId);
|
|
111
|
+
}));
|
|
112
|
+
it('should return records matching the query', () => __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
var _a, _b;
|
|
114
|
+
// insert three messages into DB, two with matching protocol
|
|
115
|
+
const alice = yield TestDataGenerator.generatePersona();
|
|
116
|
+
const dataFormat = 'myAwesomeDataFormat';
|
|
117
|
+
const write1 = yield TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
118
|
+
const write2 = yield TestDataGenerator.generateRecordsWrite({ author: alice, dataFormat, schema: 'schema1' });
|
|
119
|
+
const write3 = yield TestDataGenerator.generateRecordsWrite({ author: alice, dataFormat, schema: 'schema2' });
|
|
120
|
+
// setting up a stub resolver
|
|
121
|
+
const mockResolution = TestDataGenerator.createDidResolutionResult(alice);
|
|
122
|
+
;
|
|
123
|
+
sinon.stub(didResolver, 'resolve').resolves(mockResolution);
|
|
124
|
+
// insert data
|
|
125
|
+
const writeReply1 = yield dwn.processMessage(alice.did, write1.message, { dataStream: write1.dataStream });
|
|
126
|
+
const writeReply2 = yield dwn.processMessage(alice.did, write2.message, { dataStream: write2.dataStream });
|
|
127
|
+
const writeReply3 = yield dwn.processMessage(alice.did, write3.message, { dataStream: write3.dataStream });
|
|
128
|
+
expect(writeReply1.status.code).to.equal(202);
|
|
129
|
+
expect(writeReply2.status.code).to.equal(202);
|
|
130
|
+
expect(writeReply3.status.code).to.equal(202);
|
|
131
|
+
// testing singular conditional query
|
|
132
|
+
const messageData = yield TestDataGenerator.generateRecordsQuery({ author: alice, filter: { dataFormat } });
|
|
133
|
+
const reply = yield dwn.processMessage(alice.did, messageData.message);
|
|
134
|
+
expect(reply.status.code).to.equal(200);
|
|
135
|
+
expect((_a = reply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(2); // only 2 entries should match the query on protocol
|
|
136
|
+
// testing multi-conditional query, reuse data generated above for bob
|
|
137
|
+
const messageData2 = yield TestDataGenerator.generateRecordsQuery({
|
|
138
|
+
author: alice,
|
|
139
|
+
filter: {
|
|
140
|
+
dataFormat,
|
|
141
|
+
schema: 'schema1'
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
const reply2 = yield dwn.processMessage(alice.did, messageData2.message);
|
|
145
|
+
expect(reply2.status.code).to.equal(200);
|
|
146
|
+
expect((_b = reply2.entries) === null || _b === void 0 ? void 0 : _b.length).to.equal(1); // only 1 entry should match the query
|
|
147
|
+
}));
|
|
148
|
+
it('should return `encodedData` if data size is within the spec threshold', () => __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
var _a;
|
|
150
|
+
const data = TestDataGenerator.randomBytes(DwnConstant.maxDataSizeAllowedToBeEncoded); // within/on threshold
|
|
151
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
152
|
+
const write = yield TestDataGenerator.generateRecordsWrite({ author: alice, data });
|
|
153
|
+
const writeReply = yield dwn.processMessage(alice.did, write.message, { dataStream: write.dataStream });
|
|
154
|
+
expect(writeReply.status.code).to.equal(202);
|
|
155
|
+
const messageData = yield TestDataGenerator.generateRecordsQuery({ author: alice, filter: { recordId: write.message.recordId } });
|
|
156
|
+
const reply = yield dwn.processMessage(alice.did, messageData.message);
|
|
157
|
+
expect(reply.status.code).to.equal(200);
|
|
158
|
+
expect((_a = reply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(1);
|
|
159
|
+
expect(reply.entries[0].encodedData).to.equal(Encoder.bytesToBase64Url(data));
|
|
160
|
+
}));
|
|
161
|
+
it('should not return `encodedData` if data size is greater then spec threshold', () => __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
var _a;
|
|
163
|
+
const data = TestDataGenerator.randomBytes(DwnConstant.maxDataSizeAllowedToBeEncoded + 1); // exceeding threshold
|
|
164
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
165
|
+
const write = yield TestDataGenerator.generateRecordsWrite({ author: alice, data });
|
|
166
|
+
const writeReply = yield dwn.processMessage(alice.did, write.message, { dataStream: write.dataStream });
|
|
167
|
+
expect(writeReply.status.code).to.equal(202);
|
|
168
|
+
const messageData = yield TestDataGenerator.generateRecordsQuery({ author: alice, filter: { recordId: write.message.recordId } });
|
|
169
|
+
const reply = yield dwn.processMessage(alice.did, messageData.message);
|
|
170
|
+
expect(reply.status.code).to.equal(200);
|
|
171
|
+
expect((_a = reply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(1);
|
|
172
|
+
expect(reply.entries[0].encodedData).to.be.undefined;
|
|
173
|
+
}));
|
|
174
|
+
it('should include `initialWrite` property if RecordsWrite is not initial write', () => __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
var _a, _b;
|
|
176
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
177
|
+
const write = yield TestDataGenerator.generateRecordsWrite({ author: alice, published: false });
|
|
178
|
+
const writeReply = yield dwn.processMessage(alice.did, write.message, { dataStream: write.dataStream });
|
|
179
|
+
expect(writeReply.status.code).to.equal(202);
|
|
180
|
+
// write an update to the record
|
|
181
|
+
const write2 = yield RecordsWrite.createFrom({ recordsWriteMessage: write.message, published: true, signer: Jws.createSigner(alice) });
|
|
182
|
+
const write2Reply = yield dwn.processMessage(alice.did, write2.message);
|
|
183
|
+
expect(write2Reply.status.code).to.equal(202);
|
|
184
|
+
// make sure result returned now has `initialWrite` property
|
|
185
|
+
const messageData = yield TestDataGenerator.generateRecordsQuery({ author: alice, filter: { recordId: write.message.recordId } });
|
|
186
|
+
const reply = yield dwn.processMessage(alice.did, messageData.message);
|
|
187
|
+
expect(reply.status.code).to.equal(200);
|
|
188
|
+
expect((_a = reply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(1);
|
|
189
|
+
expect(reply.entries[0].initialWrite).to.exist;
|
|
190
|
+
expect((_b = reply.entries[0].initialWrite) === null || _b === void 0 ? void 0 : _b.recordId).to.equal(write.message.recordId);
|
|
191
|
+
}));
|
|
192
|
+
it('should be able to query by attester', () => __awaiter(this, void 0, void 0, function* () {
|
|
193
|
+
var _a, _b, _c;
|
|
194
|
+
// scenario: 2 records authored by alice, 1st attested by alice, 2nd attested by bob
|
|
195
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
196
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
197
|
+
const recordsWrite1 = yield TestDataGenerator.generateRecordsWrite({ author: alice, attesters: [alice] });
|
|
198
|
+
const recordsWrite2 = yield TestDataGenerator.generateRecordsWrite({ author: alice, attesters: [bob] });
|
|
199
|
+
// insert data
|
|
200
|
+
const writeReply1 = yield dwn.processMessage(alice.did, recordsWrite1.message, { dataStream: recordsWrite1.dataStream });
|
|
201
|
+
const writeReply2 = yield dwn.processMessage(alice.did, recordsWrite2.message, { dataStream: recordsWrite2.dataStream });
|
|
202
|
+
expect(writeReply1.status.code).to.equal(202);
|
|
203
|
+
expect(writeReply2.status.code).to.equal(202);
|
|
204
|
+
// testing attester filter
|
|
205
|
+
const recordsQuery1 = yield TestDataGenerator.generateRecordsQuery({ author: alice, filter: { attester: alice.did } });
|
|
206
|
+
const reply1 = yield dwn.processMessage(alice.did, recordsQuery1.message);
|
|
207
|
+
expect((_a = reply1.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(1);
|
|
208
|
+
const reply1Attester = Jws.getSignerDid(reply1.entries[0].attestation.signatures[0]);
|
|
209
|
+
expect(reply1Attester).to.equal(alice.did);
|
|
210
|
+
// testing attester + another filter
|
|
211
|
+
const recordsQuery2 = yield TestDataGenerator.generateRecordsQuery({
|
|
212
|
+
author: alice,
|
|
213
|
+
filter: { attester: bob.did, schema: recordsWrite2.message.descriptor.schema }
|
|
214
|
+
});
|
|
215
|
+
const reply2 = yield dwn.processMessage(alice.did, recordsQuery2.message);
|
|
216
|
+
expect((_b = reply2.entries) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
217
|
+
const reply2Attester = Jws.getSignerDid(reply2.entries[0].attestation.signatures[0]);
|
|
218
|
+
expect(reply2Attester).to.equal(bob.did);
|
|
219
|
+
// testing attester filter that yields no results
|
|
220
|
+
const carol = yield TestDataGenerator.generateDidKeyPersona();
|
|
221
|
+
const recordsQuery3 = yield TestDataGenerator.generateRecordsQuery({ author: alice, filter: { attester: carol.did } });
|
|
222
|
+
const reply3 = yield dwn.processMessage(alice.did, recordsQuery3.message);
|
|
223
|
+
expect((_c = reply3.entries) === null || _c === void 0 ? void 0 : _c.length).to.equal(0);
|
|
224
|
+
}));
|
|
225
|
+
it('should be able to query by author', () => __awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
var _a, _b, _c, _d;
|
|
227
|
+
// scenario alice and bob both author records into alice's DWN.
|
|
228
|
+
// alice is able to filter for records authored by bob.
|
|
229
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
230
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
231
|
+
const protocolDefinition = freeForAll;
|
|
232
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
233
|
+
author: alice,
|
|
234
|
+
protocolDefinition
|
|
235
|
+
});
|
|
236
|
+
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
237
|
+
expect(protocolsConfigureReply.status.code).to.equal(202);
|
|
238
|
+
const aliceAuthorWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
239
|
+
author: alice,
|
|
240
|
+
protocol: protocolDefinition.protocol,
|
|
241
|
+
schema: protocolDefinition.types.post.schema,
|
|
242
|
+
dataFormat: protocolDefinition.types.post.dataFormats[0],
|
|
243
|
+
protocolPath: 'post'
|
|
244
|
+
});
|
|
245
|
+
const aliceAuthorReply = yield dwn.processMessage(alice.did, aliceAuthorWrite.message, { dataStream: aliceAuthorWrite.dataStream });
|
|
246
|
+
expect(aliceAuthorReply.status.code).to.equal(202);
|
|
247
|
+
const bobAuthorWrite = yield TestDataGenerator.generateRecordsWrite({
|
|
248
|
+
author: bob,
|
|
249
|
+
protocol: protocolDefinition.protocol,
|
|
250
|
+
schema: protocolDefinition.types.post.schema,
|
|
251
|
+
dataFormat: protocolDefinition.types.post.dataFormats[0],
|
|
252
|
+
protocolPath: 'post'
|
|
253
|
+
});
|
|
254
|
+
const bobAuthorReply = yield dwn.processMessage(alice.did, bobAuthorWrite.message, { dataStream: bobAuthorWrite.dataStream });
|
|
255
|
+
expect(bobAuthorReply.status.code).to.equal(202);
|
|
256
|
+
// alice queries with an empty filter, gets both
|
|
257
|
+
let recordsQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
258
|
+
author: alice,
|
|
259
|
+
filter: {
|
|
260
|
+
protocol: protocolDefinition.protocol,
|
|
261
|
+
schema: protocolDefinition.types.post.schema,
|
|
262
|
+
dataFormat: protocolDefinition.types.post.dataFormats[0],
|
|
263
|
+
protocolPath: 'post'
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
let queryReply = yield dwn.processMessage(alice.did, recordsQuery.message);
|
|
267
|
+
expect(queryReply.status.code).to.equal(200);
|
|
268
|
+
expect((_a = queryReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(2);
|
|
269
|
+
// filter for bob as author
|
|
270
|
+
recordsQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
271
|
+
author: alice,
|
|
272
|
+
filter: {
|
|
273
|
+
author: bob.did,
|
|
274
|
+
protocol: protocolDefinition.protocol,
|
|
275
|
+
schema: protocolDefinition.types.post.schema,
|
|
276
|
+
dataFormat: protocolDefinition.types.post.dataFormats[0],
|
|
277
|
+
protocolPath: 'post'
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
queryReply = yield dwn.processMessage(alice.did, recordsQuery.message);
|
|
281
|
+
expect(queryReply.status.code).to.equal(200);
|
|
282
|
+
expect((_b = queryReply.entries) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
283
|
+
expect(queryReply.entries[0].recordId).to.equal(bobAuthorWrite.message.recordId);
|
|
284
|
+
// empty array for author should return all same as undefined author field
|
|
285
|
+
recordsQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
286
|
+
author: alice,
|
|
287
|
+
filter: {
|
|
288
|
+
author: [],
|
|
289
|
+
protocol: protocolDefinition.protocol,
|
|
290
|
+
schema: protocolDefinition.types.post.schema,
|
|
291
|
+
dataFormat: protocolDefinition.types.post.dataFormats[0],
|
|
292
|
+
protocolPath: 'post'
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
queryReply = yield dwn.processMessage(alice.did, recordsQuery.message);
|
|
296
|
+
expect(queryReply.status.code).to.equal(200);
|
|
297
|
+
expect((_c = queryReply.entries) === null || _c === void 0 ? void 0 : _c.length).to.equal(2);
|
|
298
|
+
// query for both authors explicitly
|
|
299
|
+
recordsQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
300
|
+
author: alice,
|
|
301
|
+
filter: {
|
|
302
|
+
author: [alice.did, bob.did],
|
|
303
|
+
protocol: protocolDefinition.protocol,
|
|
304
|
+
schema: protocolDefinition.types.post.schema,
|
|
305
|
+
dataFormat: protocolDefinition.types.post.dataFormats[0],
|
|
306
|
+
protocolPath: 'post'
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
queryReply = yield dwn.processMessage(alice.did, recordsQuery.message);
|
|
310
|
+
expect(queryReply.status.code).to.equal(200);
|
|
311
|
+
expect((_d = queryReply.entries) === null || _d === void 0 ? void 0 : _d.length).to.equal(2);
|
|
312
|
+
}));
|
|
313
|
+
it('should be able to query by recipient', () => __awaiter(this, void 0, void 0, function* () {
|
|
314
|
+
var _a, _b, _c, _d, _e;
|
|
315
|
+
// scenario alice authors records for bob and carol into alice's DWN.
|
|
316
|
+
// bob and carol are able to filter for records for them.
|
|
317
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
318
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
319
|
+
const carol = yield TestDataGenerator.generateDidKeyPersona();
|
|
320
|
+
const protocolDefinition = freeForAll;
|
|
321
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
322
|
+
author: alice,
|
|
323
|
+
protocolDefinition
|
|
324
|
+
});
|
|
325
|
+
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
326
|
+
expect(protocolsConfigureReply.status.code).to.equal(202);
|
|
327
|
+
const aliceToBob = yield TestDataGenerator.generateRecordsWrite({
|
|
328
|
+
author: alice,
|
|
329
|
+
recipient: bob.did,
|
|
330
|
+
protocol: protocolDefinition.protocol,
|
|
331
|
+
schema: protocolDefinition.types.post.schema,
|
|
332
|
+
dataFormat: protocolDefinition.types.post.dataFormats[0],
|
|
333
|
+
protocolPath: 'post'
|
|
334
|
+
});
|
|
335
|
+
const aliceToBobReply = yield dwn.processMessage(alice.did, aliceToBob.message, { dataStream: aliceToBob.dataStream });
|
|
336
|
+
expect(aliceToBobReply.status.code).to.equal(202);
|
|
337
|
+
const aliceToCarol = yield TestDataGenerator.generateRecordsWrite({
|
|
338
|
+
author: alice,
|
|
339
|
+
recipient: carol.did,
|
|
340
|
+
protocol: protocolDefinition.protocol,
|
|
341
|
+
schema: protocolDefinition.types.post.schema,
|
|
342
|
+
dataFormat: protocolDefinition.types.post.dataFormats[0],
|
|
343
|
+
protocolPath: 'post'
|
|
344
|
+
});
|
|
345
|
+
const aliceToCarolReply = yield dwn.processMessage(alice.did, aliceToCarol.message, { dataStream: aliceToCarol.dataStream });
|
|
346
|
+
expect(aliceToCarolReply.status.code).to.equal(202);
|
|
347
|
+
// alice queries with an empty filter, gets both
|
|
348
|
+
let recordsQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
349
|
+
author: alice,
|
|
350
|
+
filter: {
|
|
351
|
+
protocol: protocolDefinition.protocol,
|
|
352
|
+
schema: protocolDefinition.types.post.schema,
|
|
353
|
+
dataFormat: protocolDefinition.types.post.dataFormats[0],
|
|
354
|
+
protocolPath: 'post'
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
let queryReply = yield dwn.processMessage(alice.did, recordsQuery.message);
|
|
358
|
+
expect(queryReply.status.code).to.equal(200);
|
|
359
|
+
expect((_a = queryReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(2);
|
|
360
|
+
// filter for bob as recipient
|
|
361
|
+
recordsQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
362
|
+
author: alice,
|
|
363
|
+
filter: {
|
|
364
|
+
recipient: bob.did,
|
|
365
|
+
protocol: protocolDefinition.protocol,
|
|
366
|
+
schema: protocolDefinition.types.post.schema,
|
|
367
|
+
dataFormat: protocolDefinition.types.post.dataFormats[0],
|
|
368
|
+
protocolPath: 'post'
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
queryReply = yield dwn.processMessage(alice.did, recordsQuery.message);
|
|
372
|
+
expect(queryReply.status.code).to.equal(200);
|
|
373
|
+
expect((_b = queryReply.entries) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
374
|
+
expect(queryReply.entries[0].recordId).to.equal(aliceToBob.message.recordId);
|
|
375
|
+
// filter for carol as recipient
|
|
376
|
+
recordsQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
377
|
+
author: alice,
|
|
378
|
+
filter: {
|
|
379
|
+
recipient: carol.did,
|
|
380
|
+
protocol: protocolDefinition.protocol,
|
|
381
|
+
schema: protocolDefinition.types.post.schema,
|
|
382
|
+
dataFormat: protocolDefinition.types.post.dataFormats[0],
|
|
383
|
+
protocolPath: 'post'
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
queryReply = yield dwn.processMessage(alice.did, recordsQuery.message);
|
|
387
|
+
expect(queryReply.status.code).to.equal(200);
|
|
388
|
+
expect((_c = queryReply.entries) === null || _c === void 0 ? void 0 : _c.length).to.equal(1);
|
|
389
|
+
expect(queryReply.entries[0].recordId).to.equal(aliceToCarol.message.recordId);
|
|
390
|
+
// empty array for recipient should return all same as undefined recipient field
|
|
391
|
+
recordsQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
392
|
+
author: alice,
|
|
393
|
+
filter: {
|
|
394
|
+
recipient: [],
|
|
395
|
+
protocol: protocolDefinition.protocol,
|
|
396
|
+
schema: protocolDefinition.types.post.schema,
|
|
397
|
+
dataFormat: protocolDefinition.types.post.dataFormats[0],
|
|
398
|
+
protocolPath: 'post'
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
queryReply = yield dwn.processMessage(alice.did, recordsQuery.message);
|
|
402
|
+
expect(queryReply.status.code).to.equal(200);
|
|
403
|
+
expect((_d = queryReply.entries) === null || _d === void 0 ? void 0 : _d.length).to.equal(2);
|
|
404
|
+
// query for both recipients explicitly
|
|
405
|
+
recordsQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
406
|
+
author: alice,
|
|
407
|
+
filter: {
|
|
408
|
+
recipient: [bob.did, carol.did],
|
|
409
|
+
protocol: protocolDefinition.protocol,
|
|
410
|
+
schema: protocolDefinition.types.post.schema,
|
|
411
|
+
dataFormat: protocolDefinition.types.post.dataFormats[0],
|
|
412
|
+
protocolPath: 'post'
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
queryReply = yield dwn.processMessage(alice.did, recordsQuery.message);
|
|
416
|
+
expect(queryReply.status.code).to.equal(200);
|
|
417
|
+
expect((_e = queryReply.entries) === null || _e === void 0 ? void 0 : _e.length).to.equal(2);
|
|
418
|
+
}));
|
|
419
|
+
it('should be able to query for published records', () => __awaiter(this, void 0, void 0, function* () {
|
|
420
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
421
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
422
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
423
|
+
// create a published record
|
|
424
|
+
const publishedWrite = yield TestDataGenerator.generateRecordsWrite({ author: alice, published: true, schema: 'post' });
|
|
425
|
+
const publishedWriteReply = yield dwn.processMessage(alice.did, publishedWrite.message, { dataStream: publishedWrite.dataStream });
|
|
426
|
+
expect(publishedWriteReply.status.code).to.equal(202);
|
|
427
|
+
// create an unpublished record
|
|
428
|
+
const draftWrite = yield TestDataGenerator.generateRecordsWrite({ author: alice, schema: 'post' });
|
|
429
|
+
const draftWriteReply = yield dwn.processMessage(alice.did, draftWrite.message, { dataStream: draftWrite.dataStream });
|
|
430
|
+
expect(draftWriteReply.status.code).to.equal(202);
|
|
431
|
+
// query for only published records
|
|
432
|
+
const publishedPostQuery = yield TestDataGenerator.generateRecordsQuery({ author: alice, filter: { schema: 'post', published: true } });
|
|
433
|
+
let publishedPostReply = yield dwn.processMessage(alice.did, publishedPostQuery.message);
|
|
434
|
+
expect(publishedPostReply.status.code).to.equal(200);
|
|
435
|
+
expect((_a = publishedPostReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(1);
|
|
436
|
+
expect(publishedPostReply.entries[0].recordId).to.equal(publishedWrite.message.recordId);
|
|
437
|
+
// make an query for published records from non owner
|
|
438
|
+
const notOwnerPostQuery = yield TestDataGenerator.generateRecordsQuery({ author: bob, filter: { schema: 'post', published: true } });
|
|
439
|
+
let notOwnerPublishedPostReply = yield dwn.processMessage(alice.did, notOwnerPostQuery.message);
|
|
440
|
+
expect(notOwnerPublishedPostReply.status.code).to.equal(200);
|
|
441
|
+
expect((_b = notOwnerPublishedPostReply.entries) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
442
|
+
expect(notOwnerPublishedPostReply.entries[0].recordId).to.equal(publishedWrite.message.recordId);
|
|
443
|
+
// anonymous query for published records
|
|
444
|
+
const anonymousPostQuery = yield RecordsQuery.create({ filter: { schema: 'post', published: true } });
|
|
445
|
+
let anonymousPublishedPostReply = yield dwn.processMessage(alice.did, anonymousPostQuery.message);
|
|
446
|
+
expect(anonymousPublishedPostReply.status.code).to.equal(200);
|
|
447
|
+
expect((_c = anonymousPublishedPostReply.entries) === null || _c === void 0 ? void 0 : _c.length).to.equal(1);
|
|
448
|
+
expect(anonymousPublishedPostReply.entries[0].recordId).to.equal(publishedWrite.message.recordId);
|
|
449
|
+
// publish the unpublished record
|
|
450
|
+
const publishedDraftWrite = yield RecordsWrite.createFrom({
|
|
451
|
+
recordsWriteMessage: draftWrite.message,
|
|
452
|
+
published: true,
|
|
453
|
+
signer: Jws.createSigner(alice)
|
|
454
|
+
});
|
|
455
|
+
const publishedDraftReply = yield dwn.processMessage(alice.did, publishedDraftWrite.message);
|
|
456
|
+
expect(publishedDraftReply.status.code).to.equal(202);
|
|
457
|
+
// issue the same query for published records
|
|
458
|
+
publishedPostReply = yield dwn.processMessage(alice.did, publishedPostQuery.message);
|
|
459
|
+
expect(publishedPostReply.status.code).to.equal(200);
|
|
460
|
+
expect((_d = publishedPostReply.entries) === null || _d === void 0 ? void 0 : _d.length).to.equal(2);
|
|
461
|
+
const returnedRecordIds = (_e = publishedPostReply.entries) === null || _e === void 0 ? void 0 : _e.map(e => e.recordId);
|
|
462
|
+
// ensure that both records now exist in results
|
|
463
|
+
expect(returnedRecordIds).to.have.members([publishedWrite.message.recordId, draftWrite.message.recordId]);
|
|
464
|
+
// query after publishing from non owner
|
|
465
|
+
notOwnerPublishedPostReply = yield dwn.processMessage(alice.did, anonymousPostQuery.message);
|
|
466
|
+
expect(notOwnerPublishedPostReply.status.code).to.equal(200);
|
|
467
|
+
expect((_f = notOwnerPublishedPostReply.entries) === null || _f === void 0 ? void 0 : _f.length).to.equal(2);
|
|
468
|
+
const nonOwnerReturnedRecordIds = (_g = notOwnerPublishedPostReply.entries) === null || _g === void 0 ? void 0 : _g.map(e => e.recordId);
|
|
469
|
+
expect(nonOwnerReturnedRecordIds).to.have.members([publishedWrite.message.recordId, draftWrite.message.recordId]);
|
|
470
|
+
// anonymous query after publishing
|
|
471
|
+
anonymousPublishedPostReply = yield dwn.processMessage(alice.did, anonymousPostQuery.message);
|
|
472
|
+
expect(anonymousPublishedPostReply.status.code).to.equal(200);
|
|
473
|
+
expect((_h = anonymousPublishedPostReply.entries) === null || _h === void 0 ? void 0 : _h.length).to.equal(2);
|
|
474
|
+
const anonymousReturnedRecordIds = (_j = anonymousPublishedPostReply.entries) === null || _j === void 0 ? void 0 : _j.map(e => e.recordId);
|
|
475
|
+
expect(anonymousReturnedRecordIds).to.have.members([publishedWrite.message.recordId, draftWrite.message.recordId]);
|
|
476
|
+
}));
|
|
477
|
+
it('should be able to query for unpublished records', () => __awaiter(this, void 0, void 0, function* () {
|
|
478
|
+
var _a, _b;
|
|
479
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
480
|
+
// create a published record
|
|
481
|
+
const publishedWrite = yield TestDataGenerator.generateRecordsWrite({ author: alice, published: true, schema: 'post' });
|
|
482
|
+
const publishedWriteReply = yield dwn.processMessage(alice.did, publishedWrite.message, { dataStream: publishedWrite.dataStream });
|
|
483
|
+
expect(publishedWriteReply.status.code).to.equal(202);
|
|
484
|
+
// create an unpublished record
|
|
485
|
+
const draftWrite = yield TestDataGenerator.generateRecordsWrite({ author: alice, schema: 'post' });
|
|
486
|
+
const draftWriteReply = yield dwn.processMessage(alice.did, draftWrite.message, { dataStream: draftWrite.dataStream });
|
|
487
|
+
expect(draftWriteReply.status.code).to.equal(202);
|
|
488
|
+
// query for only unpublished records
|
|
489
|
+
const unpublishedPostQuery = yield TestDataGenerator.generateRecordsQuery({ author: alice, filter: { schema: 'post', published: false } });
|
|
490
|
+
let unpublishedPostReply = yield dwn.processMessage(alice.did, unpublishedPostQuery.message);
|
|
491
|
+
expect(unpublishedPostReply.status.code).to.equal(200);
|
|
492
|
+
expect((_a = unpublishedPostReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(1);
|
|
493
|
+
expect(unpublishedPostReply.entries[0].recordId).to.equal(draftWrite.message.recordId);
|
|
494
|
+
// publish the unpublished record
|
|
495
|
+
const publishedDraftWrite = yield RecordsWrite.createFrom({
|
|
496
|
+
recordsWriteMessage: draftWrite.message,
|
|
497
|
+
published: true,
|
|
498
|
+
signer: Jws.createSigner(alice)
|
|
499
|
+
});
|
|
500
|
+
const publishedDraftReply = yield dwn.processMessage(alice.did, publishedDraftWrite.message);
|
|
501
|
+
expect(publishedDraftReply.status.code).to.equal(202);
|
|
502
|
+
// issue the same query for unpublished records
|
|
503
|
+
unpublishedPostReply = yield dwn.processMessage(alice.did, unpublishedPostQuery.message);
|
|
504
|
+
expect(unpublishedPostReply.status.code).to.equal(200);
|
|
505
|
+
expect((_b = unpublishedPostReply.entries) === null || _b === void 0 ? void 0 : _b.length).to.equal(0);
|
|
506
|
+
}));
|
|
507
|
+
it('should not be able to query for unpublished records if unauthorized', () => __awaiter(this, void 0, void 0, function* () {
|
|
508
|
+
var _a, _b, _c, _d;
|
|
509
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
510
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
511
|
+
// create a published record
|
|
512
|
+
const publishedWrite = yield TestDataGenerator.generateRecordsWrite({ author: alice, published: true, schema: 'post' });
|
|
513
|
+
const publishedWriteReply = yield dwn.processMessage(alice.did, publishedWrite.message, { dataStream: publishedWrite.dataStream });
|
|
514
|
+
expect(publishedWriteReply.status.code).to.equal(202);
|
|
515
|
+
// create an unpublished record
|
|
516
|
+
const draftWrite = yield TestDataGenerator.generateRecordsWrite({ author: alice, schema: 'post' });
|
|
517
|
+
const draftWriteReply = yield dwn.processMessage(alice.did, draftWrite.message, { dataStream: draftWrite.dataStream });
|
|
518
|
+
expect(draftWriteReply.status.code).to.equal(202);
|
|
519
|
+
// bob queries for unpublished records returns zero
|
|
520
|
+
const unpublishedNotOwner = yield TestDataGenerator.generateRecordsQuery({ author: bob, filter: { schema: 'post', published: false } });
|
|
521
|
+
let notOwnerPostReply = yield dwn.processMessage(alice.did, unpublishedNotOwner.message);
|
|
522
|
+
expect(notOwnerPostReply.status.code).to.equal(200);
|
|
523
|
+
expect((_a = notOwnerPostReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(0);
|
|
524
|
+
// publish the unpublished record
|
|
525
|
+
const publishedDraftWrite = yield RecordsWrite.createFrom({
|
|
526
|
+
recordsWriteMessage: draftWrite.message,
|
|
527
|
+
published: true,
|
|
528
|
+
signer: Jws.createSigner(alice)
|
|
529
|
+
});
|
|
530
|
+
const publishedDraftReply = yield dwn.processMessage(alice.did, publishedDraftWrite.message);
|
|
531
|
+
expect(publishedDraftReply.status.code).to.equal(202);
|
|
532
|
+
// without published filter
|
|
533
|
+
let publishedNotOwner = yield TestDataGenerator.generateRecordsQuery({ author: bob, filter: { schema: 'post' } });
|
|
534
|
+
let publishedNotOwnerReply = yield dwn.processMessage(alice.did, publishedNotOwner.message);
|
|
535
|
+
expect(publishedNotOwnerReply.status.code).to.equal(200);
|
|
536
|
+
expect((_b = publishedNotOwnerReply.entries) === null || _b === void 0 ? void 0 : _b.length).to.equal(2);
|
|
537
|
+
// with explicit published true
|
|
538
|
+
publishedNotOwner = yield TestDataGenerator.generateRecordsQuery({ author: bob, filter: { schema: 'post', published: true } });
|
|
539
|
+
publishedNotOwnerReply = yield dwn.processMessage(alice.did, publishedNotOwner.message);
|
|
540
|
+
expect(publishedNotOwnerReply.status.code).to.equal(200);
|
|
541
|
+
expect((_c = publishedNotOwnerReply.entries) === null || _c === void 0 ? void 0 : _c.length).to.equal(2);
|
|
542
|
+
// with explicit published false after publishing should still return nothing
|
|
543
|
+
notOwnerPostReply = yield dwn.processMessage(alice.did, unpublishedNotOwner.message);
|
|
544
|
+
expect(notOwnerPostReply.status.code).to.equal(200);
|
|
545
|
+
expect((_d = notOwnerPostReply.entries) === null || _d === void 0 ? void 0 : _d.length).to.equal(0);
|
|
546
|
+
}));
|
|
547
|
+
it('should be able to query for a record by a dataCid', () => __awaiter(this, void 0, void 0, function* () {
|
|
548
|
+
var _a;
|
|
549
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
550
|
+
// create a record
|
|
551
|
+
const writeRecord = yield TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
552
|
+
const writeRecordReply = yield dwn.processMessage(alice.did, writeRecord.message, { dataStream: writeRecord.dataStream });
|
|
553
|
+
expect(writeRecordReply.status.code).to.equal(202);
|
|
554
|
+
const recordDataCid = writeRecord.message.descriptor.dataCid;
|
|
555
|
+
// query for the record by it's dataCid
|
|
556
|
+
const dataCidQuery = yield TestDataGenerator.generateRecordsQuery({ author: alice, filter: { dataCid: recordDataCid } });
|
|
557
|
+
const dataCidQueryReply = yield dwn.processMessage(alice.did, dataCidQuery.message);
|
|
558
|
+
expect(dataCidQueryReply.status.code).to.equal(200);
|
|
559
|
+
expect((_a = dataCidQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(1);
|
|
560
|
+
expect(dataCidQueryReply.entries[0].recordId).to.equal(writeRecord.message.recordId);
|
|
561
|
+
}));
|
|
562
|
+
it('should be able to query with `dataSize` filter (half-open range)', () => __awaiter(this, void 0, void 0, function* () {
|
|
563
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
564
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
565
|
+
const write1 = yield TestDataGenerator.generateRecordsWrite({ author: alice, data: TestDataGenerator.randomBytes(10) });
|
|
566
|
+
const write2 = yield TestDataGenerator.generateRecordsWrite({ author: alice, data: TestDataGenerator.randomBytes(50) });
|
|
567
|
+
const write3 = yield TestDataGenerator.generateRecordsWrite({ author: alice, data: TestDataGenerator.randomBytes(100) });
|
|
568
|
+
// insert data
|
|
569
|
+
const writeReply1 = yield dwn.processMessage(alice.did, write1.message, { dataStream: write1.dataStream });
|
|
570
|
+
const writeReply2 = yield dwn.processMessage(alice.did, write2.message, { dataStream: write2.dataStream });
|
|
571
|
+
const writeReply3 = yield dwn.processMessage(alice.did, write3.message, { dataStream: write3.dataStream });
|
|
572
|
+
expect(writeReply1.status.code).to.equal(202);
|
|
573
|
+
expect(writeReply2.status.code).to.equal(202);
|
|
574
|
+
expect(writeReply3.status.code).to.equal(202);
|
|
575
|
+
// testing gt
|
|
576
|
+
const recordsQuery1 = yield TestDataGenerator.generateRecordsQuery({
|
|
577
|
+
author: alice,
|
|
578
|
+
filter: { dataSize: { gt: 10 } },
|
|
579
|
+
});
|
|
580
|
+
const reply1 = yield dwn.processMessage(alice.did, recordsQuery1.message);
|
|
581
|
+
expect((_a = reply1.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(2);
|
|
582
|
+
expect((_b = reply1.entries) === null || _b === void 0 ? void 0 : _b.map((entry) => entry.encodedData)).to.have.members([
|
|
583
|
+
Encoder.bytesToBase64Url(write2.dataBytes),
|
|
584
|
+
Encoder.bytesToBase64Url(write3.dataBytes)
|
|
585
|
+
]);
|
|
586
|
+
// testing lt
|
|
587
|
+
const recordsQuery2 = yield TestDataGenerator.generateRecordsQuery({
|
|
588
|
+
author: alice,
|
|
589
|
+
filter: { dataSize: { lt: 100 } },
|
|
590
|
+
});
|
|
591
|
+
const reply2 = yield dwn.processMessage(alice.did, recordsQuery2.message);
|
|
592
|
+
expect((_c = reply2.entries) === null || _c === void 0 ? void 0 : _c.length).to.equal(2);
|
|
593
|
+
expect((_d = reply2.entries) === null || _d === void 0 ? void 0 : _d.map((entry) => entry.encodedData)).to.have.members([
|
|
594
|
+
Encoder.bytesToBase64Url(write1.dataBytes),
|
|
595
|
+
Encoder.bytesToBase64Url(write2.dataBytes)
|
|
596
|
+
]);
|
|
597
|
+
// testing gte
|
|
598
|
+
const recordsQuery3 = yield TestDataGenerator.generateRecordsQuery({
|
|
599
|
+
author: alice,
|
|
600
|
+
filter: { dataSize: { gte: 10 } },
|
|
601
|
+
});
|
|
602
|
+
const reply3 = yield dwn.processMessage(alice.did, recordsQuery3.message);
|
|
603
|
+
expect((_e = reply3.entries) === null || _e === void 0 ? void 0 : _e.length).to.equal(3);
|
|
604
|
+
expect((_f = reply3.entries) === null || _f === void 0 ? void 0 : _f.map((entry) => entry.encodedData)).to.have.members([
|
|
605
|
+
Encoder.bytesToBase64Url(write1.dataBytes),
|
|
606
|
+
Encoder.bytesToBase64Url(write2.dataBytes),
|
|
607
|
+
Encoder.bytesToBase64Url(write3.dataBytes)
|
|
608
|
+
]);
|
|
609
|
+
// testing lte
|
|
610
|
+
const recordsQuery4 = yield TestDataGenerator.generateRecordsQuery({
|
|
611
|
+
author: alice,
|
|
612
|
+
filter: { dataSize: { lte: 100 } },
|
|
613
|
+
});
|
|
614
|
+
const reply4 = yield dwn.processMessage(alice.did, recordsQuery4.message);
|
|
615
|
+
expect((_g = reply4.entries) === null || _g === void 0 ? void 0 : _g.length).to.equal(3);
|
|
616
|
+
expect((_h = reply4.entries) === null || _h === void 0 ? void 0 : _h.map((entry) => entry.encodedData)).to.have.members([
|
|
617
|
+
Encoder.bytesToBase64Url(write1.dataBytes),
|
|
618
|
+
Encoder.bytesToBase64Url(write2.dataBytes),
|
|
619
|
+
Encoder.bytesToBase64Url(write3.dataBytes)
|
|
620
|
+
]);
|
|
621
|
+
}));
|
|
622
|
+
it('should be able to range query with `dataSize` filter (open & closed range)', () => __awaiter(this, void 0, void 0, function* () {
|
|
623
|
+
var _a, _b, _c, _d, _e, _f;
|
|
624
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
625
|
+
const write1 = yield TestDataGenerator.generateRecordsWrite({ author: alice, data: TestDataGenerator.randomBytes(10) });
|
|
626
|
+
const write2 = yield TestDataGenerator.generateRecordsWrite({ author: alice, data: TestDataGenerator.randomBytes(50) });
|
|
627
|
+
const write3 = yield TestDataGenerator.generateRecordsWrite({ author: alice, data: TestDataGenerator.randomBytes(100) });
|
|
628
|
+
// insert data
|
|
629
|
+
const writeReply1 = yield dwn.processMessage(alice.did, write1.message, { dataStream: write1.dataStream });
|
|
630
|
+
const writeReply2 = yield dwn.processMessage(alice.did, write2.message, { dataStream: write2.dataStream });
|
|
631
|
+
const writeReply3 = yield dwn.processMessage(alice.did, write3.message, { dataStream: write3.dataStream });
|
|
632
|
+
expect(writeReply1.status.code).to.equal(202);
|
|
633
|
+
expect(writeReply2.status.code).to.equal(202);
|
|
634
|
+
expect(writeReply3.status.code).to.equal(202);
|
|
635
|
+
// testing range using gt & lt
|
|
636
|
+
const recordsQuery1 = yield TestDataGenerator.generateRecordsQuery({
|
|
637
|
+
author: alice,
|
|
638
|
+
filter: { dataSize: { gt: 10, lt: 60 } },
|
|
639
|
+
});
|
|
640
|
+
const reply1 = yield dwn.processMessage(alice.did, recordsQuery1.message);
|
|
641
|
+
expect((_a = reply1.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(1);
|
|
642
|
+
expect(reply1.entries[0].recordId).to.equal(write2.message.recordId);
|
|
643
|
+
// testing range using gte & lt
|
|
644
|
+
const recordsQuery2 = yield TestDataGenerator.generateRecordsQuery({
|
|
645
|
+
author: alice,
|
|
646
|
+
filter: { dataSize: { gte: 10, lt: 60 } },
|
|
647
|
+
});
|
|
648
|
+
const reply2 = yield dwn.processMessage(alice.did, recordsQuery2.message);
|
|
649
|
+
expect((_b = reply2.entries) === null || _b === void 0 ? void 0 : _b.length).to.equal(2);
|
|
650
|
+
const reply2RecordIds = (_c = reply2.entries) === null || _c === void 0 ? void 0 : _c.map(e => e.recordId);
|
|
651
|
+
expect(reply2RecordIds).to.have.members([write1.message.recordId, write2.message.recordId]);
|
|
652
|
+
// testing range using gt & lte
|
|
653
|
+
const recordsQuery3 = yield TestDataGenerator.generateRecordsQuery({
|
|
654
|
+
author: alice,
|
|
655
|
+
filter: { dataSize: { gt: 50, lte: 100 } },
|
|
656
|
+
});
|
|
657
|
+
const reply3 = yield dwn.processMessage(alice.did, recordsQuery3.message);
|
|
658
|
+
expect((_d = reply3.entries) === null || _d === void 0 ? void 0 : _d.length).to.equal(1);
|
|
659
|
+
expect(reply3.entries[0].recordId).to.equal(write3.message.recordId);
|
|
660
|
+
// testing range using gte & lte
|
|
661
|
+
const recordsQuery4 = yield TestDataGenerator.generateRecordsQuery({
|
|
662
|
+
author: alice,
|
|
663
|
+
filter: { dataSize: { gte: 10, lte: 100 } },
|
|
664
|
+
});
|
|
665
|
+
const reply4 = yield dwn.processMessage(alice.did, recordsQuery4.message);
|
|
666
|
+
expect((_e = reply4.entries) === null || _e === void 0 ? void 0 : _e.length).to.equal(3);
|
|
667
|
+
const reply4RecordIds = (_f = reply4.entries) === null || _f === void 0 ? void 0 : _f.map(e => e.recordId);
|
|
668
|
+
expect(reply4RecordIds).to.have.members([write1.message.recordId, write2.message.recordId, write3.message.recordId]);
|
|
669
|
+
}));
|
|
670
|
+
it('should be able to range query by `dateCreated`', () => __awaiter(this, void 0, void 0, function* () {
|
|
671
|
+
var _a, _b, _c, _d;
|
|
672
|
+
// scenario: 3 records authored by alice, created on first of 2021, 2022, and 2023 respectively
|
|
673
|
+
// only the first 2 records share the same schema
|
|
674
|
+
const firstDayOf2021 = Time.createTimestamp({ year: 2021, month: 1, day: 1 });
|
|
675
|
+
const firstDayOf2022 = Time.createTimestamp({ year: 2022, month: 1, day: 1 });
|
|
676
|
+
const firstDayOf2023 = Time.createTimestamp({ year: 2023, month: 1, day: 1 });
|
|
677
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
678
|
+
const write1 = yield TestDataGenerator.generateRecordsWrite({ author: alice, dateCreated: firstDayOf2021, messageTimestamp: firstDayOf2021 });
|
|
679
|
+
const write2 = yield TestDataGenerator.generateRecordsWrite({ author: alice, dateCreated: firstDayOf2022, messageTimestamp: firstDayOf2022 });
|
|
680
|
+
const write3 = yield TestDataGenerator.generateRecordsWrite({ author: alice, dateCreated: firstDayOf2023, messageTimestamp: firstDayOf2023 });
|
|
681
|
+
// insert data
|
|
682
|
+
const writeReply1 = yield dwn.processMessage(alice.did, write1.message, { dataStream: write1.dataStream });
|
|
683
|
+
const writeReply2 = yield dwn.processMessage(alice.did, write2.message, { dataStream: write2.dataStream });
|
|
684
|
+
const writeReply3 = yield dwn.processMessage(alice.did, write3.message, { dataStream: write3.dataStream });
|
|
685
|
+
expect(writeReply1.status.code).to.equal(202);
|
|
686
|
+
expect(writeReply2.status.code).to.equal(202);
|
|
687
|
+
expect(writeReply3.status.code).to.equal(202);
|
|
688
|
+
// testing `from` range
|
|
689
|
+
const lastDayOf2021 = Time.createTimestamp({ year: 2021, month: 12, day: 31 });
|
|
690
|
+
const recordsQuery1 = yield TestDataGenerator.generateRecordsQuery({
|
|
691
|
+
author: alice,
|
|
692
|
+
filter: { dateCreated: { from: lastDayOf2021 } },
|
|
693
|
+
dateSort: DateSort.CreatedAscending
|
|
694
|
+
});
|
|
695
|
+
const reply1 = yield dwn.processMessage(alice.did, recordsQuery1.message);
|
|
696
|
+
expect((_a = reply1.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(2);
|
|
697
|
+
expect(reply1.entries[0].encodedData).to.equal(Encoder.bytesToBase64Url(write2.dataBytes));
|
|
698
|
+
expect(reply1.entries[1].encodedData).to.equal(Encoder.bytesToBase64Url(write3.dataBytes));
|
|
699
|
+
// testing `to` range
|
|
700
|
+
const lastDayOf2022 = Time.createTimestamp({ year: 2022, month: 12, day: 31 });
|
|
701
|
+
const recordsQuery2 = yield TestDataGenerator.generateRecordsQuery({
|
|
702
|
+
author: alice,
|
|
703
|
+
filter: { dateCreated: { to: lastDayOf2022 } },
|
|
704
|
+
dateSort: DateSort.CreatedAscending
|
|
705
|
+
});
|
|
706
|
+
const reply2 = yield dwn.processMessage(alice.did, recordsQuery2.message);
|
|
707
|
+
expect((_b = reply2.entries) === null || _b === void 0 ? void 0 : _b.length).to.equal(2);
|
|
708
|
+
expect(reply2.entries[0].encodedData).to.equal(Encoder.bytesToBase64Url(write1.dataBytes));
|
|
709
|
+
expect(reply2.entries[1].encodedData).to.equal(Encoder.bytesToBase64Url(write2.dataBytes));
|
|
710
|
+
// testing `from` and `to` range
|
|
711
|
+
const lastDayOf2023 = Time.createTimestamp({ year: 2023, month: 12, day: 31 });
|
|
712
|
+
const recordsQuery3 = yield TestDataGenerator.generateRecordsQuery({
|
|
713
|
+
author: alice,
|
|
714
|
+
filter: { dateCreated: { from: lastDayOf2022, to: lastDayOf2023 } },
|
|
715
|
+
dateSort: DateSort.CreatedAscending
|
|
716
|
+
});
|
|
717
|
+
const reply3 = yield dwn.processMessage(alice.did, recordsQuery3.message);
|
|
718
|
+
expect((_c = reply3.entries) === null || _c === void 0 ? void 0 : _c.length).to.equal(1);
|
|
719
|
+
expect(reply3.entries[0].encodedData).to.equal(Encoder.bytesToBase64Url(write3.dataBytes));
|
|
720
|
+
// testing edge case where value equals `from` and `to`
|
|
721
|
+
const recordsQuery4 = yield TestDataGenerator.generateRecordsQuery({
|
|
722
|
+
author: alice,
|
|
723
|
+
filter: { dateCreated: { from: firstDayOf2022, to: firstDayOf2023 } },
|
|
724
|
+
dateSort: DateSort.CreatedAscending
|
|
725
|
+
});
|
|
726
|
+
const reply4 = yield dwn.processMessage(alice.did, recordsQuery4.message);
|
|
727
|
+
expect((_d = reply4.entries) === null || _d === void 0 ? void 0 : _d.length).to.equal(1);
|
|
728
|
+
expect(reply4.entries[0].encodedData).to.equal(Encoder.bytesToBase64Url(write2.dataBytes));
|
|
729
|
+
}));
|
|
730
|
+
it('should not return records that were published and then unpublished ', () => __awaiter(this, void 0, void 0, function* () {
|
|
731
|
+
// scenario: 3 records authored by alice, published on first of 2021, 2022, and 2023 respectively
|
|
732
|
+
// then the records are unpublished and tested to not return when filtering for published records
|
|
733
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
734
|
+
const firstDayOf2020 = Time.createTimestamp({ year: 2020, month: 1, day: 1 });
|
|
735
|
+
const firstDayOf2021 = Time.createTimestamp({ year: 2021, month: 1, day: 1 });
|
|
736
|
+
const firstDayOf2022 = Time.createTimestamp({ year: 2022, month: 1, day: 1 });
|
|
737
|
+
const firstDayOf2023 = Time.createTimestamp({ year: 2023, month: 1, day: 1 });
|
|
738
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
739
|
+
const write1 = yield TestDataGenerator.generateRecordsWrite({
|
|
740
|
+
author: alice, published: true, dateCreated: firstDayOf2020, datePublished: firstDayOf2021, messageTimestamp: firstDayOf2020
|
|
741
|
+
});
|
|
742
|
+
const write2 = yield TestDataGenerator.generateRecordsWrite({
|
|
743
|
+
author: alice, published: true, dateCreated: firstDayOf2020, datePublished: firstDayOf2022, messageTimestamp: firstDayOf2020
|
|
744
|
+
});
|
|
745
|
+
const write3 = yield TestDataGenerator.generateRecordsWrite({
|
|
746
|
+
author: alice, published: true, dateCreated: firstDayOf2020, datePublished: firstDayOf2023, messageTimestamp: firstDayOf2020
|
|
747
|
+
});
|
|
748
|
+
// insert data
|
|
749
|
+
const writeReply1 = yield dwn.processMessage(alice.did, write1.message, { dataStream: write1.dataStream });
|
|
750
|
+
const writeReply2 = yield dwn.processMessage(alice.did, write2.message, { dataStream: write2.dataStream });
|
|
751
|
+
const writeReply3 = yield dwn.processMessage(alice.did, write3.message, { dataStream: write3.dataStream });
|
|
752
|
+
expect(writeReply1.status.code).to.equal(202);
|
|
753
|
+
expect(writeReply2.status.code).to.equal(202);
|
|
754
|
+
expect(writeReply3.status.code).to.equal(202);
|
|
755
|
+
// confirm range before un-publishing.
|
|
756
|
+
const lastDayOf2021 = Time.createTimestamp({ year: 2021, month: 12, day: 31 });
|
|
757
|
+
const ownerRangeQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
758
|
+
author: alice,
|
|
759
|
+
filter: { datePublished: { from: lastDayOf2021 } },
|
|
760
|
+
dateSort: DateSort.CreatedAscending
|
|
761
|
+
});
|
|
762
|
+
const reply1 = yield dwn.processMessage(alice.did, ownerRangeQuery.message);
|
|
763
|
+
expect((_a = reply1.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(2);
|
|
764
|
+
const reply1RecordIds = (_b = reply1.entries) === null || _b === void 0 ? void 0 : _b.map(e => e.recordId);
|
|
765
|
+
expect(reply1RecordIds).to.have.members([write2.message.recordId, write3.message.recordId]);
|
|
766
|
+
// confirm published true filter before un-publishing
|
|
767
|
+
const ownerPublishedQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
768
|
+
author: alice,
|
|
769
|
+
filter: { published: true },
|
|
770
|
+
dateSort: DateSort.CreatedAscending
|
|
771
|
+
});
|
|
772
|
+
let ownerPublishedReply = yield dwn.processMessage(alice.did, ownerPublishedQuery.message);
|
|
773
|
+
expect(ownerPublishedReply.status.code).to.equal(200);
|
|
774
|
+
expect((_c = ownerPublishedReply.entries) === null || _c === void 0 ? void 0 : _c.length).to.equal(3);
|
|
775
|
+
const ownerPublishedIds = (_d = ownerPublishedReply.entries) === null || _d === void 0 ? void 0 : _d.map(e => e.recordId);
|
|
776
|
+
expect(ownerPublishedIds).to.have.members([write1.message.recordId, write2.message.recordId, write3.message.recordId]);
|
|
777
|
+
// confirm for anonymous query before un-publishing
|
|
778
|
+
const anonymousRangeQuery = yield RecordsQuery.create({
|
|
779
|
+
filter: { datePublished: { from: lastDayOf2021 } },
|
|
780
|
+
dateSort: DateSort.CreatedAscending
|
|
781
|
+
});
|
|
782
|
+
let anonymousRangeReply = yield dwn.processMessage(alice.did, anonymousRangeQuery.message);
|
|
783
|
+
expect(anonymousRangeReply.status.code).to.equal(200);
|
|
784
|
+
expect((_e = anonymousRangeReply.entries) === null || _e === void 0 ? void 0 : _e.length).to.equal(2);
|
|
785
|
+
const anonymousReplyIds = (_f = anonymousRangeReply.entries) === null || _f === void 0 ? void 0 : _f.map(e => e.recordId);
|
|
786
|
+
expect(anonymousReplyIds).to.have.members([write2.message.recordId, write3.message.recordId]);
|
|
787
|
+
// confirm anonymous published true filter before un-publishing
|
|
788
|
+
const anonymousPublishedQuery = yield RecordsQuery.create({
|
|
789
|
+
filter: { published: true },
|
|
790
|
+
dateSort: DateSort.CreatedAscending
|
|
791
|
+
});
|
|
792
|
+
let anonymousPublishedReply = yield dwn.processMessage(alice.did, anonymousPublishedQuery.message);
|
|
793
|
+
expect(anonymousPublishedReply.status.code).to.equal(200);
|
|
794
|
+
expect((_g = anonymousPublishedReply.entries) === null || _g === void 0 ? void 0 : _g.length).to.equal(3);
|
|
795
|
+
const anonymousPublishedIds = (_h = anonymousPublishedReply.entries) === null || _h === void 0 ? void 0 : _h.map(e => e.recordId);
|
|
796
|
+
expect(anonymousPublishedIds).to.have.members([write1.message.recordId, write2.message.recordId, write3.message.recordId]);
|
|
797
|
+
//unpublish records
|
|
798
|
+
const write1Unpublish = yield RecordsWrite.createFrom({
|
|
799
|
+
signer: Jws.createSigner(alice),
|
|
800
|
+
recordsWriteMessage: write1.message,
|
|
801
|
+
published: false
|
|
802
|
+
});
|
|
803
|
+
const write2Unpublish = yield RecordsWrite.createFrom({
|
|
804
|
+
signer: Jws.createSigner(alice),
|
|
805
|
+
recordsWriteMessage: write2.message,
|
|
806
|
+
published: false
|
|
807
|
+
});
|
|
808
|
+
const write3Unpublish = yield RecordsWrite.createFrom({
|
|
809
|
+
signer: Jws.createSigner(alice),
|
|
810
|
+
recordsWriteMessage: write3.message,
|
|
811
|
+
published: false
|
|
812
|
+
});
|
|
813
|
+
const unpublished1Response = yield dwn.processMessage(alice.did, write1Unpublish.message);
|
|
814
|
+
const unpublished2Response = yield dwn.processMessage(alice.did, write2Unpublish.message);
|
|
815
|
+
const unpublished3Response = yield dwn.processMessage(alice.did, write3Unpublish.message);
|
|
816
|
+
expect(unpublished1Response.status.code).to.equal(202);
|
|
817
|
+
expect(unpublished2Response.status.code).to.equal(202);
|
|
818
|
+
expect(unpublished3Response.status.code).to.equal(202);
|
|
819
|
+
// try datePublished range query as an anonymous user after unpublish
|
|
820
|
+
anonymousRangeReply = yield dwn.processMessage(alice.did, anonymousRangeQuery.message);
|
|
821
|
+
expect(anonymousRangeReply.status.code).to.equal(200);
|
|
822
|
+
expect((_j = anonymousRangeReply.entries) === null || _j === void 0 ? void 0 : _j.length).to.equal(0);
|
|
823
|
+
// try published:true filter as an anonymous user after unpublish
|
|
824
|
+
anonymousPublishedReply = yield dwn.processMessage(alice.did, anonymousPublishedQuery.message);
|
|
825
|
+
expect(anonymousPublishedReply.status.code).to.equal(200);
|
|
826
|
+
expect((_k = anonymousPublishedReply.entries) === null || _k === void 0 ? void 0 : _k.length).to.equal(0);
|
|
827
|
+
// try datePublished range query as owner after unpublish
|
|
828
|
+
const ownerRangeReply = yield dwn.processMessage(alice.did, ownerRangeQuery.message);
|
|
829
|
+
expect(ownerRangeReply.status.code).to.equal(200);
|
|
830
|
+
expect((_l = ownerRangeReply.entries) === null || _l === void 0 ? void 0 : _l.length).to.equal(0);
|
|
831
|
+
// try published:true filter as owner after unpublish
|
|
832
|
+
ownerPublishedReply = yield dwn.processMessage(alice.did, ownerPublishedQuery.message);
|
|
833
|
+
expect(ownerPublishedReply.status.code).to.equal(200);
|
|
834
|
+
expect((_m = ownerPublishedReply.entries) === null || _m === void 0 ? void 0 : _m.length).to.equal(0);
|
|
835
|
+
}));
|
|
836
|
+
it('should be able to range query by `datePublished`', () => __awaiter(this, void 0, void 0, function* () {
|
|
837
|
+
// scenario: 3 records authored by alice, published on first of 2021, 2022, and 2023 respectively
|
|
838
|
+
// all 3 records are created on first of 2020
|
|
839
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
840
|
+
const firstDayOf2020 = Time.createTimestamp({ year: 2020, month: 1, day: 1 });
|
|
841
|
+
const firstDayOf2021 = Time.createTimestamp({ year: 2021, month: 1, day: 1 });
|
|
842
|
+
const firstDayOf2022 = Time.createTimestamp({ year: 2022, month: 1, day: 1 });
|
|
843
|
+
const firstDayOf2023 = Time.createTimestamp({ year: 2023, month: 1, day: 1 });
|
|
844
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
845
|
+
const write1 = yield TestDataGenerator.generateRecordsWrite({
|
|
846
|
+
author: alice, published: true, dateCreated: firstDayOf2020, datePublished: firstDayOf2021, messageTimestamp: firstDayOf2020
|
|
847
|
+
});
|
|
848
|
+
const write2 = yield TestDataGenerator.generateRecordsWrite({
|
|
849
|
+
author: alice, published: true, dateCreated: firstDayOf2020, datePublished: firstDayOf2022, messageTimestamp: firstDayOf2020
|
|
850
|
+
});
|
|
851
|
+
const write3 = yield TestDataGenerator.generateRecordsWrite({
|
|
852
|
+
author: alice, published: true, dateCreated: firstDayOf2020, datePublished: firstDayOf2023, messageTimestamp: firstDayOf2020
|
|
853
|
+
});
|
|
854
|
+
// insert data
|
|
855
|
+
const writeReply1 = yield dwn.processMessage(alice.did, write1.message, { dataStream: write1.dataStream });
|
|
856
|
+
const writeReply2 = yield dwn.processMessage(alice.did, write2.message, { dataStream: write2.dataStream });
|
|
857
|
+
const writeReply3 = yield dwn.processMessage(alice.did, write3.message, { dataStream: write3.dataStream });
|
|
858
|
+
expect(writeReply1.status.code).to.equal(202);
|
|
859
|
+
expect(writeReply2.status.code).to.equal(202);
|
|
860
|
+
expect(writeReply3.status.code).to.equal(202);
|
|
861
|
+
// testing `from` range
|
|
862
|
+
const lastDayOf2021 = Time.createTimestamp({ year: 2021, month: 12, day: 31 });
|
|
863
|
+
const recordsQuery1 = yield TestDataGenerator.generateRecordsQuery({
|
|
864
|
+
author: alice,
|
|
865
|
+
filter: { datePublished: { from: lastDayOf2021 } },
|
|
866
|
+
dateSort: DateSort.CreatedAscending
|
|
867
|
+
});
|
|
868
|
+
const reply1 = yield dwn.processMessage(alice.did, recordsQuery1.message);
|
|
869
|
+
expect((_a = reply1.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(2);
|
|
870
|
+
const reply1RecordIds = (_b = reply1.entries) === null || _b === void 0 ? void 0 : _b.map(e => e.recordId);
|
|
871
|
+
expect(reply1RecordIds).to.have.members([write2.message.recordId, write3.message.recordId]);
|
|
872
|
+
// testing `to` range
|
|
873
|
+
const lastDayOf2022 = Time.createTimestamp({ year: 2022, month: 12, day: 31 });
|
|
874
|
+
const recordsQuery2 = yield TestDataGenerator.generateRecordsQuery({
|
|
875
|
+
author: alice,
|
|
876
|
+
filter: { datePublished: { to: lastDayOf2022 } },
|
|
877
|
+
dateSort: DateSort.CreatedAscending
|
|
878
|
+
});
|
|
879
|
+
const reply2 = yield dwn.processMessage(alice.did, recordsQuery2.message);
|
|
880
|
+
expect((_c = reply2.entries) === null || _c === void 0 ? void 0 : _c.length).to.equal(2);
|
|
881
|
+
const reply2RecordIds = (_d = reply2.entries) === null || _d === void 0 ? void 0 : _d.map(e => e.recordId);
|
|
882
|
+
expect(reply2RecordIds).to.have.members([write1.message.recordId, write2.message.recordId]);
|
|
883
|
+
// testing `from` and `to` range
|
|
884
|
+
const lastDayOf2023 = Time.createTimestamp({ year: 2023, month: 12, day: 31 });
|
|
885
|
+
const recordsQuery3 = yield TestDataGenerator.generateRecordsQuery({
|
|
886
|
+
author: alice,
|
|
887
|
+
filter: { datePublished: { from: lastDayOf2022, to: lastDayOf2023 } },
|
|
888
|
+
dateSort: DateSort.CreatedAscending
|
|
889
|
+
});
|
|
890
|
+
const reply3 = yield dwn.processMessage(alice.did, recordsQuery3.message);
|
|
891
|
+
expect((_e = reply3.entries) === null || _e === void 0 ? void 0 : _e.length).to.equal(1);
|
|
892
|
+
expect(reply3.entries[0].recordId).to.equal(write3.message.recordId);
|
|
893
|
+
// testing edge case where value equals `from` and `to`
|
|
894
|
+
const recordsQuery4 = yield TestDataGenerator.generateRecordsQuery({
|
|
895
|
+
author: alice,
|
|
896
|
+
filter: { datePublished: { from: firstDayOf2022, to: firstDayOf2023 } },
|
|
897
|
+
dateSort: DateSort.CreatedAscending
|
|
898
|
+
});
|
|
899
|
+
const reply4 = yield dwn.processMessage(alice.did, recordsQuery4.message);
|
|
900
|
+
expect((_f = reply4.entries) === null || _f === void 0 ? void 0 : _f.length).to.equal(1);
|
|
901
|
+
expect(reply4.entries[0].recordId).to.equal(write2.message.recordId);
|
|
902
|
+
// check for anonymous range query
|
|
903
|
+
const anonymousRecordQuery = yield RecordsQuery.create({
|
|
904
|
+
filter: { datePublished: { from: lastDayOf2021 } },
|
|
905
|
+
dateSort: DateSort.CreatedAscending
|
|
906
|
+
});
|
|
907
|
+
const anonymousReply = yield dwn.processMessage(alice.did, anonymousRecordQuery.message);
|
|
908
|
+
expect(anonymousReply.status.code).to.equal(200);
|
|
909
|
+
expect((_g = anonymousReply.entries) === null || _g === void 0 ? void 0 : _g.length).to.equal(2);
|
|
910
|
+
const anonymousReplyIds = (_h = anonymousReply.entries) === null || _h === void 0 ? void 0 : _h.map(e => e.recordId);
|
|
911
|
+
expect(anonymousReplyIds).to.have.members([write2.message.recordId, write3.message.recordId]);
|
|
912
|
+
// check for non owner range query
|
|
913
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
914
|
+
const nonOwnerRange = yield TestDataGenerator.generateRecordsQuery({
|
|
915
|
+
author: bob,
|
|
916
|
+
filter: { datePublished: { from: lastDayOf2021 } },
|
|
917
|
+
dateSort: DateSort.CreatedAscending
|
|
918
|
+
});
|
|
919
|
+
const nonOwnerReply = yield dwn.processMessage(alice.did, nonOwnerRange.message);
|
|
920
|
+
expect(nonOwnerReply.status.code).to.equal(200);
|
|
921
|
+
expect((_j = nonOwnerReply.entries) === null || _j === void 0 ? void 0 : _j.length).to.equal(2);
|
|
922
|
+
const nonOwnerReplyIds = (_k = nonOwnerReply.entries) === null || _k === void 0 ? void 0 : _k.map(e => e.recordId);
|
|
923
|
+
expect(nonOwnerReplyIds).to.have.members([write2.message.recordId, write3.message.recordId]);
|
|
924
|
+
}));
|
|
925
|
+
it('should be able to range query by `dateUpdated`', () => __awaiter(this, void 0, void 0, function* () {
|
|
926
|
+
// scenario: alice creates 3 records on the first day of 2020.
|
|
927
|
+
// alice then updates these records to published on first of 2021, 2022, and 2023 respectively
|
|
928
|
+
// this should update the messageTimestamp on the respective messages
|
|
929
|
+
var _a, _b, _c, _d, _e, _f;
|
|
930
|
+
const firstDayOf2020 = Time.createTimestamp({ year: 2020, month: 1, day: 1 });
|
|
931
|
+
const firstDayOf2021 = Time.createTimestamp({ year: 2021, month: 1, day: 1 });
|
|
932
|
+
const firstDayOf2022 = Time.createTimestamp({ year: 2022, month: 1, day: 1 });
|
|
933
|
+
const firstDayOf2023 = Time.createTimestamp({ year: 2023, month: 1, day: 1 });
|
|
934
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
935
|
+
const write1 = yield TestDataGenerator.generateRecordsWrite({
|
|
936
|
+
author: alice, dateCreated: firstDayOf2020, messageTimestamp: firstDayOf2020
|
|
937
|
+
});
|
|
938
|
+
const write2 = yield TestDataGenerator.generateRecordsWrite({
|
|
939
|
+
author: alice, dateCreated: firstDayOf2020, messageTimestamp: firstDayOf2020
|
|
940
|
+
});
|
|
941
|
+
const write3 = yield TestDataGenerator.generateRecordsWrite({
|
|
942
|
+
author: alice, dateCreated: firstDayOf2020, messageTimestamp: firstDayOf2020
|
|
943
|
+
});
|
|
944
|
+
// insert data
|
|
945
|
+
const writeReply1 = yield dwn.processMessage(alice.did, write1.message, { dataStream: write1.dataStream });
|
|
946
|
+
const writeReply2 = yield dwn.processMessage(alice.did, write2.message, { dataStream: write2.dataStream });
|
|
947
|
+
const writeReply3 = yield dwn.processMessage(alice.did, write3.message, { dataStream: write3.dataStream });
|
|
948
|
+
expect(writeReply1.status.code).to.equal(202);
|
|
949
|
+
expect(writeReply2.status.code).to.equal(202);
|
|
950
|
+
expect(writeReply3.status.code).to.equal(202);
|
|
951
|
+
// update to published
|
|
952
|
+
const write1Update = yield RecordsWrite.createFrom({
|
|
953
|
+
recordsWriteMessage: write1.message,
|
|
954
|
+
published: true,
|
|
955
|
+
messageTimestamp: firstDayOf2021,
|
|
956
|
+
datePublished: firstDayOf2021,
|
|
957
|
+
signer: Jws.createSigner(alice)
|
|
958
|
+
});
|
|
959
|
+
const write2Update = yield RecordsWrite.createFrom({
|
|
960
|
+
recordsWriteMessage: write2.message,
|
|
961
|
+
published: true,
|
|
962
|
+
messageTimestamp: firstDayOf2022,
|
|
963
|
+
datePublished: firstDayOf2022,
|
|
964
|
+
signer: Jws.createSigner(alice)
|
|
965
|
+
});
|
|
966
|
+
const write3Update = yield RecordsWrite.createFrom({
|
|
967
|
+
recordsWriteMessage: write3.message,
|
|
968
|
+
published: true,
|
|
969
|
+
messageTimestamp: firstDayOf2023,
|
|
970
|
+
datePublished: firstDayOf2023,
|
|
971
|
+
signer: Jws.createSigner(alice)
|
|
972
|
+
});
|
|
973
|
+
const writeReplyUpdate1 = yield dwn.processMessage(alice.did, write1Update.message);
|
|
974
|
+
const writeReplyUpdate2 = yield dwn.processMessage(alice.did, write2Update.message);
|
|
975
|
+
const writeReplyUpdate3 = yield dwn.processMessage(alice.did, write3Update.message);
|
|
976
|
+
expect(writeReplyUpdate1.status.code).to.equal(202);
|
|
977
|
+
expect(writeReplyUpdate2.status.code).to.equal(202);
|
|
978
|
+
expect(writeReplyUpdate3.status.code).to.equal(202);
|
|
979
|
+
// testing `from` range
|
|
980
|
+
const lastDayOf2021 = Time.createTimestamp({ year: 2021, month: 12, day: 31 });
|
|
981
|
+
const recordsQuery1 = yield TestDataGenerator.generateRecordsQuery({
|
|
982
|
+
author: alice,
|
|
983
|
+
filter: { dateUpdated: { from: lastDayOf2021 } },
|
|
984
|
+
dateSort: DateSort.CreatedAscending
|
|
985
|
+
});
|
|
986
|
+
const reply1 = yield dwn.processMessage(alice.did, recordsQuery1.message);
|
|
987
|
+
expect((_a = reply1.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(2);
|
|
988
|
+
const reply1RecordIds = (_b = reply1.entries) === null || _b === void 0 ? void 0 : _b.map(e => e.recordId);
|
|
989
|
+
expect(reply1RecordIds).to.have.members([write2.message.recordId, write3.message.recordId]);
|
|
990
|
+
// testing `to` range
|
|
991
|
+
const lastDayOf2022 = Time.createTimestamp({ year: 2022, month: 12, day: 31 });
|
|
992
|
+
const recordsQuery2 = yield TestDataGenerator.generateRecordsQuery({
|
|
993
|
+
author: alice,
|
|
994
|
+
filter: { dateUpdated: { to: lastDayOf2022 } },
|
|
995
|
+
dateSort: DateSort.CreatedAscending
|
|
996
|
+
});
|
|
997
|
+
const reply2 = yield dwn.processMessage(alice.did, recordsQuery2.message);
|
|
998
|
+
expect((_c = reply2.entries) === null || _c === void 0 ? void 0 : _c.length).to.equal(2);
|
|
999
|
+
const reply2RecordIds = (_d = reply2.entries) === null || _d === void 0 ? void 0 : _d.map(e => e.recordId);
|
|
1000
|
+
expect(reply2RecordIds).to.have.members([write1.message.recordId, write2.message.recordId]);
|
|
1001
|
+
// testing `from` and `to` range
|
|
1002
|
+
const lastDayOf2023 = Time.createTimestamp({ year: 2023, month: 12, day: 31 });
|
|
1003
|
+
const recordsQuery3 = yield TestDataGenerator.generateRecordsQuery({
|
|
1004
|
+
author: alice,
|
|
1005
|
+
filter: { dateUpdated: { from: lastDayOf2022, to: lastDayOf2023 } },
|
|
1006
|
+
dateSort: DateSort.CreatedAscending
|
|
1007
|
+
});
|
|
1008
|
+
const reply3 = yield dwn.processMessage(alice.did, recordsQuery3.message);
|
|
1009
|
+
expect((_e = reply3.entries) === null || _e === void 0 ? void 0 : _e.length).to.equal(1);
|
|
1010
|
+
expect(reply3.entries[0].recordId).to.equal(write3.message.recordId);
|
|
1011
|
+
// testing edge case where value equals `from` and `to`
|
|
1012
|
+
const recordsQuery4 = yield TestDataGenerator.generateRecordsQuery({
|
|
1013
|
+
author: alice,
|
|
1014
|
+
filter: { dateUpdated: { from: firstDayOf2022, to: firstDayOf2023 } },
|
|
1015
|
+
dateSort: DateSort.CreatedAscending
|
|
1016
|
+
});
|
|
1017
|
+
const reply4 = yield dwn.processMessage(alice.did, recordsQuery4.message);
|
|
1018
|
+
expect((_f = reply4.entries) === null || _f === void 0 ? void 0 : _f.length).to.equal(1);
|
|
1019
|
+
expect(reply4.entries[0].recordId).to.equal(write2.message.recordId);
|
|
1020
|
+
}));
|
|
1021
|
+
it('should be able use range and exact match queries at the same time', () => __awaiter(this, void 0, void 0, function* () {
|
|
1022
|
+
var _a;
|
|
1023
|
+
// scenario: 3 records authored by alice, created on first of 2021, 2022, and 2023 respectively
|
|
1024
|
+
// only the first 2 records share the same schema
|
|
1025
|
+
const firstDayOf2021 = Time.createTimestamp({ year: 2021, month: 1, day: 1 });
|
|
1026
|
+
const firstDayOf2022 = Time.createTimestamp({ year: 2022, month: 1, day: 1 });
|
|
1027
|
+
const firstDayOf2023 = Time.createTimestamp({ year: 2023, month: 1, day: 1 });
|
|
1028
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
1029
|
+
const schema = '2021And2022Schema';
|
|
1030
|
+
const write1 = yield TestDataGenerator.generateRecordsWrite({
|
|
1031
|
+
author: alice, dateCreated: firstDayOf2021, messageTimestamp: firstDayOf2021, schema
|
|
1032
|
+
});
|
|
1033
|
+
const write2 = yield TestDataGenerator.generateRecordsWrite({
|
|
1034
|
+
author: alice, dateCreated: firstDayOf2022, messageTimestamp: firstDayOf2022, schema
|
|
1035
|
+
});
|
|
1036
|
+
const write3 = yield TestDataGenerator.generateRecordsWrite({
|
|
1037
|
+
author: alice, dateCreated: firstDayOf2023, messageTimestamp: firstDayOf2023
|
|
1038
|
+
});
|
|
1039
|
+
// insert data
|
|
1040
|
+
const writeReply1 = yield dwn.processMessage(alice.did, write1.message, { dataStream: write1.dataStream });
|
|
1041
|
+
const writeReply2 = yield dwn.processMessage(alice.did, write2.message, { dataStream: write2.dataStream });
|
|
1042
|
+
const writeReply3 = yield dwn.processMessage(alice.did, write3.message, { dataStream: write3.dataStream });
|
|
1043
|
+
expect(writeReply1.status.code).to.equal(202);
|
|
1044
|
+
expect(writeReply2.status.code).to.equal(202);
|
|
1045
|
+
expect(writeReply3.status.code).to.equal(202);
|
|
1046
|
+
// testing range criterion with another exact match
|
|
1047
|
+
const lastDayOf2021 = Time.createTimestamp({ year: 2021, month: 12, day: 31 });
|
|
1048
|
+
const lastDayOf2023 = Time.createTimestamp({ year: 2023, month: 12, day: 31 });
|
|
1049
|
+
const recordsQuery5 = yield TestDataGenerator.generateRecordsQuery({
|
|
1050
|
+
author: alice,
|
|
1051
|
+
filter: {
|
|
1052
|
+
schema, // by itself selects the first 2 records
|
|
1053
|
+
dateCreated: { from: lastDayOf2021, to: lastDayOf2023 } // by itself selects the last 2 records
|
|
1054
|
+
},
|
|
1055
|
+
dateSort: DateSort.CreatedAscending
|
|
1056
|
+
});
|
|
1057
|
+
const reply = yield dwn.processMessage(alice.did, recordsQuery5.message);
|
|
1058
|
+
expect((_a = reply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(1);
|
|
1059
|
+
expect(reply.entries[0].encodedData).to.equal(Encoder.bytesToBase64Url(write2.dataBytes));
|
|
1060
|
+
}));
|
|
1061
|
+
it('should include `authorization` in returned records', () => __awaiter(this, void 0, void 0, function* () {
|
|
1062
|
+
var _a;
|
|
1063
|
+
const alice = yield TestDataGenerator.generatePersona();
|
|
1064
|
+
const { message, dataStream } = yield TestDataGenerator.generateRecordsWrite({ author: alice });
|
|
1065
|
+
// setting up a stub method resolver
|
|
1066
|
+
const mockResolution = TestDataGenerator.createDidResolutionResult(alice);
|
|
1067
|
+
sinon.stub(didResolver, 'resolve').resolves(mockResolution);
|
|
1068
|
+
const writeReply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
1069
|
+
expect(writeReply.status.code).to.equal(202);
|
|
1070
|
+
const queryData = yield TestDataGenerator.generateRecordsQuery({
|
|
1071
|
+
author: alice,
|
|
1072
|
+
filter: { schema: message.descriptor.schema }
|
|
1073
|
+
});
|
|
1074
|
+
const queryReply = yield dwn.processMessage(alice.did, queryData.message);
|
|
1075
|
+
expect(queryReply.status.code).to.equal(200);
|
|
1076
|
+
expect((_a = queryReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(1);
|
|
1077
|
+
expect(queryReply.entries[0].authorization).to.deep.equal(message.authorization);
|
|
1078
|
+
}));
|
|
1079
|
+
it('should include `attestation` in returned records', () => __awaiter(this, void 0, void 0, function* () {
|
|
1080
|
+
// scenario: alice and bob attest to a message alice authored
|
|
1081
|
+
var _a, _b, _c;
|
|
1082
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
1083
|
+
const { message, dataStream } = yield TestDataGenerator.generateRecordsWrite({ author: alice, attesters: [alice] });
|
|
1084
|
+
const writeReply = yield dwn.processMessage(alice.did, message, { dataStream });
|
|
1085
|
+
expect(writeReply.status.code).to.equal(202);
|
|
1086
|
+
const queryData = yield TestDataGenerator.generateRecordsQuery({
|
|
1087
|
+
author: alice,
|
|
1088
|
+
filter: { schema: message.descriptor.schema }
|
|
1089
|
+
});
|
|
1090
|
+
const queryReply = yield dwn.processMessage(alice.did, queryData.message);
|
|
1091
|
+
expect(queryReply.status.code).to.equal(200);
|
|
1092
|
+
expect((_a = queryReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(1);
|
|
1093
|
+
const recordsWriteMessage = queryReply.entries[0];
|
|
1094
|
+
expect((_c = (_b = recordsWriteMessage.attestation) === null || _b === void 0 ? void 0 : _b.signatures) === null || _c === void 0 ? void 0 : _c.length).to.equal(1);
|
|
1095
|
+
}));
|
|
1096
|
+
it('should omit records that are not published if `dateSort` sorts on `datePublished`', () => __awaiter(this, void 0, void 0, function* () {
|
|
1097
|
+
var _a, _b;
|
|
1098
|
+
// setup: 2 records in DWN: 1 published and 1 unpublished
|
|
1099
|
+
const alice = yield TestDataGenerator.generatePersona();
|
|
1100
|
+
const schema = 'aSchema';
|
|
1101
|
+
const publishedWriteData = yield TestDataGenerator.generateRecordsWrite({
|
|
1102
|
+
author: alice, schema, published: true
|
|
1103
|
+
});
|
|
1104
|
+
const unpublishedWriteData = yield TestDataGenerator.generateRecordsWrite({
|
|
1105
|
+
author: alice, schema
|
|
1106
|
+
});
|
|
1107
|
+
// setting up a stub method resolver
|
|
1108
|
+
const mockResolution = TestDataGenerator.createDidResolutionResult(alice);
|
|
1109
|
+
;
|
|
1110
|
+
sinon.stub(didResolver, 'resolve').resolves(mockResolution);
|
|
1111
|
+
// insert data
|
|
1112
|
+
const publishedWriteReply = yield dwn.processMessage(alice.did, publishedWriteData.message, { dataStream: publishedWriteData.dataStream });
|
|
1113
|
+
const unpublishedWriteReply = yield dwn.processMessage(alice.did, unpublishedWriteData.message, { dataStream: unpublishedWriteData.dataStream });
|
|
1114
|
+
expect(publishedWriteReply.status.code).to.equal(202);
|
|
1115
|
+
expect(unpublishedWriteReply.status.code).to.equal(202);
|
|
1116
|
+
// test published date ascending sort does not include any records that are not published
|
|
1117
|
+
const publishedAscendingQueryData = yield TestDataGenerator.generateRecordsQuery({
|
|
1118
|
+
author: alice,
|
|
1119
|
+
dateSort: DateSort.PublishedAscending,
|
|
1120
|
+
filter: { schema }
|
|
1121
|
+
});
|
|
1122
|
+
const publishedAscendingQueryReply = yield dwn.processMessage(alice.did, publishedAscendingQueryData.message);
|
|
1123
|
+
expect((_a = publishedAscendingQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(1);
|
|
1124
|
+
expect(publishedAscendingQueryReply.entries[0].recordId).to.equal(publishedWriteData.message.recordId);
|
|
1125
|
+
// test published date scending sort does not include any records that are not published
|
|
1126
|
+
const publishedDescendingQueryData = yield TestDataGenerator.generateRecordsQuery({
|
|
1127
|
+
author: alice,
|
|
1128
|
+
dateSort: DateSort.PublishedDescending,
|
|
1129
|
+
filter: { schema }
|
|
1130
|
+
});
|
|
1131
|
+
const publishedDescendingQueryReply = yield dwn.processMessage(alice.did, publishedDescendingQueryData.message);
|
|
1132
|
+
expect((_b = publishedDescendingQueryReply.entries) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
1133
|
+
expect(publishedDescendingQueryReply.entries[0].recordId).to.equal(publishedWriteData.message.recordId);
|
|
1134
|
+
}));
|
|
1135
|
+
it('should sort records if `dateSort` is specified with and without a cursor', () => __awaiter(this, void 0, void 0, function* () {
|
|
1136
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
1137
|
+
// insert three messages into DB
|
|
1138
|
+
const alice = yield TestDataGenerator.generatePersona();
|
|
1139
|
+
const schema = 'aSchema';
|
|
1140
|
+
const published = true;
|
|
1141
|
+
const write1Data = yield TestDataGenerator.generateRecordsWrite({ author: alice, schema, published });
|
|
1142
|
+
yield Time.minimalSleep();
|
|
1143
|
+
const write2Data = yield TestDataGenerator.generateRecordsWrite({ author: alice, schema, published });
|
|
1144
|
+
yield Time.minimalSleep();
|
|
1145
|
+
const write3Data = yield TestDataGenerator.generateRecordsWrite({ author: alice, schema, published });
|
|
1146
|
+
// setting up a stub method resolver
|
|
1147
|
+
const mockResolution = TestDataGenerator.createDidResolutionResult(alice);
|
|
1148
|
+
;
|
|
1149
|
+
sinon.stub(didResolver, 'resolve').resolves(mockResolution);
|
|
1150
|
+
// insert data, intentionally out of order
|
|
1151
|
+
const writeReply2 = yield dwn.processMessage(alice.did, write2Data.message, { dataStream: write2Data.dataStream });
|
|
1152
|
+
const writeReply1 = yield dwn.processMessage(alice.did, write1Data.message, { dataStream: write1Data.dataStream });
|
|
1153
|
+
const writeReply3 = yield dwn.processMessage(alice.did, write3Data.message, { dataStream: write3Data.dataStream });
|
|
1154
|
+
expect(writeReply1.status.code).to.equal(202);
|
|
1155
|
+
expect(writeReply2.status.code).to.equal(202);
|
|
1156
|
+
expect(writeReply3.status.code).to.equal(202);
|
|
1157
|
+
// createdAscending test
|
|
1158
|
+
let createdAscendingQueryData = yield TestDataGenerator.generateRecordsQuery({
|
|
1159
|
+
author: alice,
|
|
1160
|
+
dateSort: DateSort.CreatedAscending,
|
|
1161
|
+
filter: { schema }
|
|
1162
|
+
});
|
|
1163
|
+
let createdAscendingQueryReply = yield dwn.processMessage(alice.did, createdAscendingQueryData.message);
|
|
1164
|
+
expect(createdAscendingQueryReply.entries.length).to.equal(3);
|
|
1165
|
+
expect((_a = createdAscendingQueryReply.entries) === null || _a === void 0 ? void 0 : _a[0].recordId).to.equal(write1Data.message.recordId);
|
|
1166
|
+
expect((_b = createdAscendingQueryReply.entries) === null || _b === void 0 ? void 0 : _b[1].recordId).to.equal(write2Data.message.recordId);
|
|
1167
|
+
expect((_c = createdAscendingQueryReply.entries) === null || _c === void 0 ? void 0 : _c[2].recordId).to.equal(write3Data.message.recordId);
|
|
1168
|
+
// to test with a cursor we first get a single record
|
|
1169
|
+
createdAscendingQueryData = yield TestDataGenerator.generateRecordsQuery({
|
|
1170
|
+
author: alice,
|
|
1171
|
+
dateSort: DateSort.CreatedAscending,
|
|
1172
|
+
filter: { schema },
|
|
1173
|
+
pagination: { limit: 1 }
|
|
1174
|
+
});
|
|
1175
|
+
createdAscendingQueryReply = yield dwn.processMessage(alice.did, createdAscendingQueryData.message);
|
|
1176
|
+
expect(createdAscendingQueryReply.entries.length).to.equal(1);
|
|
1177
|
+
// we then use the single record query's cursor to get the rest of the records
|
|
1178
|
+
createdAscendingQueryData = yield TestDataGenerator.generateRecordsQuery({
|
|
1179
|
+
author: alice,
|
|
1180
|
+
dateSort: DateSort.CreatedAscending,
|
|
1181
|
+
filter: { schema },
|
|
1182
|
+
pagination: { cursor: createdAscendingQueryReply.cursor }
|
|
1183
|
+
});
|
|
1184
|
+
createdAscendingQueryReply = yield dwn.processMessage(alice.did, createdAscendingQueryData.message);
|
|
1185
|
+
expect(createdAscendingQueryReply.entries.length).to.equal(2);
|
|
1186
|
+
expect(createdAscendingQueryReply.entries[0].recordId).to.equal(write2Data.message.recordId);
|
|
1187
|
+
expect(createdAscendingQueryReply.entries[1].recordId).to.equal(write3Data.message.recordId);
|
|
1188
|
+
// createdDescending test
|
|
1189
|
+
let createdDescendingQueryData = yield TestDataGenerator.generateRecordsQuery({
|
|
1190
|
+
author: alice,
|
|
1191
|
+
dateSort: DateSort.CreatedDescending,
|
|
1192
|
+
filter: { schema }
|
|
1193
|
+
});
|
|
1194
|
+
let createdDescendingQueryReply = yield dwn.processMessage(alice.did, createdDescendingQueryData.message);
|
|
1195
|
+
expect(createdDescendingQueryReply.entries.length).to.equal(3);
|
|
1196
|
+
expect((_d = createdDescendingQueryReply.entries) === null || _d === void 0 ? void 0 : _d[0].recordId).to.equal(write3Data.message.recordId);
|
|
1197
|
+
expect((_e = createdDescendingQueryReply.entries) === null || _e === void 0 ? void 0 : _e[1].recordId).to.equal(write2Data.message.recordId);
|
|
1198
|
+
expect((_f = createdDescendingQueryReply.entries) === null || _f === void 0 ? void 0 : _f[2].recordId).to.equal(write1Data.message.recordId);
|
|
1199
|
+
// to test with a cursor we first get a single record
|
|
1200
|
+
createdDescendingQueryData = yield TestDataGenerator.generateRecordsQuery({
|
|
1201
|
+
author: alice,
|
|
1202
|
+
dateSort: DateSort.CreatedDescending,
|
|
1203
|
+
filter: { schema },
|
|
1204
|
+
pagination: { limit: 1 }
|
|
1205
|
+
});
|
|
1206
|
+
createdDescendingQueryReply = yield dwn.processMessage(alice.did, createdDescendingQueryData.message);
|
|
1207
|
+
expect(createdDescendingQueryReply.entries.length).to.equal(1);
|
|
1208
|
+
// we then use the single record query's cursor to get the rest of the records
|
|
1209
|
+
createdDescendingQueryData = yield TestDataGenerator.generateRecordsQuery({
|
|
1210
|
+
author: alice,
|
|
1211
|
+
dateSort: DateSort.CreatedDescending,
|
|
1212
|
+
filter: { schema },
|
|
1213
|
+
pagination: { cursor: createdDescendingQueryReply.cursor }
|
|
1214
|
+
});
|
|
1215
|
+
createdDescendingQueryReply = yield dwn.processMessage(alice.did, createdDescendingQueryData.message);
|
|
1216
|
+
expect(createdDescendingQueryReply.entries.length).to.equal(2);
|
|
1217
|
+
expect(createdDescendingQueryReply.entries[0].recordId).to.equal(write2Data.message.recordId);
|
|
1218
|
+
expect(createdDescendingQueryReply.entries[1].recordId).to.equal(write1Data.message.recordId);
|
|
1219
|
+
// publishedAscending test
|
|
1220
|
+
let publishedAscendingQueryData = yield TestDataGenerator.generateRecordsQuery({
|
|
1221
|
+
author: alice,
|
|
1222
|
+
dateSort: DateSort.PublishedAscending,
|
|
1223
|
+
filter: { schema }
|
|
1224
|
+
});
|
|
1225
|
+
let publishedAscendingQueryReply = yield dwn.processMessage(alice.did, publishedAscendingQueryData.message);
|
|
1226
|
+
expect(publishedAscendingQueryReply.entries.length).to.equal(3);
|
|
1227
|
+
expect((_g = publishedAscendingQueryReply.entries) === null || _g === void 0 ? void 0 : _g[0].recordId).to.equal(write1Data.message.recordId);
|
|
1228
|
+
expect((_h = publishedAscendingQueryReply.entries) === null || _h === void 0 ? void 0 : _h[1].recordId).to.equal(write2Data.message.recordId);
|
|
1229
|
+
expect((_j = publishedAscendingQueryReply.entries) === null || _j === void 0 ? void 0 : _j[2].recordId).to.equal(write3Data.message.recordId);
|
|
1230
|
+
// to test with a cursor we first get a single record
|
|
1231
|
+
publishedAscendingQueryData = yield TestDataGenerator.generateRecordsQuery({
|
|
1232
|
+
author: alice,
|
|
1233
|
+
dateSort: DateSort.PublishedAscending,
|
|
1234
|
+
filter: { schema },
|
|
1235
|
+
pagination: { limit: 1 }
|
|
1236
|
+
});
|
|
1237
|
+
publishedAscendingQueryReply = yield dwn.processMessage(alice.did, publishedAscendingQueryData.message);
|
|
1238
|
+
expect(publishedAscendingQueryReply.entries.length).to.equal(1);
|
|
1239
|
+
publishedAscendingQueryData = yield TestDataGenerator.generateRecordsQuery({
|
|
1240
|
+
author: alice,
|
|
1241
|
+
dateSort: DateSort.PublishedAscending,
|
|
1242
|
+
filter: { schema },
|
|
1243
|
+
pagination: { cursor: publishedAscendingQueryReply.cursor }
|
|
1244
|
+
});
|
|
1245
|
+
publishedAscendingQueryReply = yield dwn.processMessage(alice.did, publishedAscendingQueryData.message);
|
|
1246
|
+
expect(publishedAscendingQueryReply.entries.length).to.equal(2);
|
|
1247
|
+
expect(publishedAscendingQueryReply.entries[0].recordId).to.equal(write2Data.message.recordId);
|
|
1248
|
+
expect(publishedAscendingQueryReply.entries[1].recordId).to.equal(write3Data.message.recordId);
|
|
1249
|
+
// publishedDescending test
|
|
1250
|
+
let publishedDescendingQueryData = yield TestDataGenerator.generateRecordsQuery({
|
|
1251
|
+
author: alice,
|
|
1252
|
+
dateSort: DateSort.PublishedDescending,
|
|
1253
|
+
filter: { schema }
|
|
1254
|
+
});
|
|
1255
|
+
let publishedDescendingQueryReply = yield dwn.processMessage(alice.did, publishedDescendingQueryData.message);
|
|
1256
|
+
expect(publishedDescendingQueryReply.entries.length).to.equal(3);
|
|
1257
|
+
expect((_k = publishedDescendingQueryReply.entries) === null || _k === void 0 ? void 0 : _k[0].recordId).to.equal(write3Data.message.recordId);
|
|
1258
|
+
expect((_l = publishedDescendingQueryReply.entries) === null || _l === void 0 ? void 0 : _l[1].recordId).to.equal(write2Data.message.recordId);
|
|
1259
|
+
expect((_m = publishedDescendingQueryReply.entries) === null || _m === void 0 ? void 0 : _m[2].recordId).to.equal(write1Data.message.recordId);
|
|
1260
|
+
publishedDescendingQueryData = yield TestDataGenerator.generateRecordsQuery({
|
|
1261
|
+
author: alice,
|
|
1262
|
+
dateSort: DateSort.PublishedDescending,
|
|
1263
|
+
filter: { schema },
|
|
1264
|
+
pagination: { limit: 1 }
|
|
1265
|
+
});
|
|
1266
|
+
publishedDescendingQueryReply = yield dwn.processMessage(alice.did, publishedDescendingQueryData.message);
|
|
1267
|
+
expect(publishedDescendingQueryReply.entries.length).to.equal(1);
|
|
1268
|
+
publishedDescendingQueryData = yield TestDataGenerator.generateRecordsQuery({
|
|
1269
|
+
author: alice,
|
|
1270
|
+
dateSort: DateSort.PublishedDescending,
|
|
1271
|
+
filter: { schema },
|
|
1272
|
+
pagination: { cursor: publishedDescendingQueryReply.cursor }
|
|
1273
|
+
});
|
|
1274
|
+
publishedDescendingQueryReply = yield dwn.processMessage(alice.did, publishedDescendingQueryData.message);
|
|
1275
|
+
expect(publishedDescendingQueryReply.entries.length).to.equal(2);
|
|
1276
|
+
expect(publishedDescendingQueryReply.entries[0].recordId).to.equal(write2Data.message.recordId);
|
|
1277
|
+
expect(publishedDescendingQueryReply.entries[1].recordId).to.equal(write1Data.message.recordId);
|
|
1278
|
+
}));
|
|
1279
|
+
it('should tiebreak using `messageCid` when sorting encounters identical values', () => __awaiter(this, void 0, void 0, function* () {
|
|
1280
|
+
var _a;
|
|
1281
|
+
// setup: 3 messages with the same `dateCreated` value
|
|
1282
|
+
const dateCreated = Time.getCurrentTimestamp();
|
|
1283
|
+
const messageTimestamp = dateCreated;
|
|
1284
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
1285
|
+
const schema = 'aSchema';
|
|
1286
|
+
const published = true;
|
|
1287
|
+
const write1Data = yield TestDataGenerator.generateRecordsWrite({ messageTimestamp, dateCreated, author: alice, schema, published });
|
|
1288
|
+
const write2Data = yield TestDataGenerator.generateRecordsWrite({ messageTimestamp, dateCreated, author: alice, schema, published });
|
|
1289
|
+
const write3Data = yield TestDataGenerator.generateRecordsWrite({ messageTimestamp, dateCreated, author: alice, schema, published });
|
|
1290
|
+
// sort the messages in lexicographical order against `messageCid`
|
|
1291
|
+
const [oldestWrite, middleWrite, newestWrite] = yield ArrayUtility.asyncSort([write1Data, write2Data, write3Data], (messageDataA, messageDataB) => { return Message.compareCid(messageDataA.message, messageDataB.message); });
|
|
1292
|
+
// intentionally write the RecordsWrite of out lexicographical order to avoid the test query below accidentally having the correct order
|
|
1293
|
+
const reply2 = yield dwn.processMessage(alice.did, middleWrite.message, { dataStream: middleWrite.dataStream });
|
|
1294
|
+
expect(reply2.status.code).to.equal(202);
|
|
1295
|
+
const reply3 = yield dwn.processMessage(alice.did, newestWrite.message, { dataStream: newestWrite.dataStream });
|
|
1296
|
+
expect(reply3.status.code).to.equal(202);
|
|
1297
|
+
const reply1 = yield dwn.processMessage(alice.did, oldestWrite.message, { dataStream: oldestWrite.dataStream });
|
|
1298
|
+
expect(reply1.status.code).to.equal(202);
|
|
1299
|
+
const queryMessageData = yield TestDataGenerator.generateRecordsQuery({
|
|
1300
|
+
author: alice,
|
|
1301
|
+
filter: { schema },
|
|
1302
|
+
dateSort: DateSort.CreatedAscending
|
|
1303
|
+
});
|
|
1304
|
+
const queryReply = yield dwn.processMessage(alice.did, queryMessageData.message);
|
|
1305
|
+
// verify that messages returned are sorted/tiebreak by `messageCid`
|
|
1306
|
+
expect(queryReply.status.code).to.equal(200);
|
|
1307
|
+
expect((_a = queryReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(3);
|
|
1308
|
+
expect((queryReply.entries[0]).recordId).to.equal(oldestWrite.message.recordId);
|
|
1309
|
+
expect((queryReply.entries[1]).recordId).to.equal(middleWrite.message.recordId);
|
|
1310
|
+
expect((queryReply.entries[2]).recordId).to.equal(newestWrite.message.recordId);
|
|
1311
|
+
// sort descending should be reversed
|
|
1312
|
+
const queryMessageDescending = yield TestDataGenerator.generateRecordsQuery({
|
|
1313
|
+
author: alice,
|
|
1314
|
+
filter: { schema },
|
|
1315
|
+
dateSort: DateSort.CreatedDescending
|
|
1316
|
+
});
|
|
1317
|
+
const descendingReply = yield dwn.processMessage(alice.did, queryMessageDescending.message);
|
|
1318
|
+
expect((descendingReply.entries[0]).recordId).to.equal(newestWrite.message.recordId);
|
|
1319
|
+
expect((descendingReply.entries[1]).recordId).to.equal(middleWrite.message.recordId);
|
|
1320
|
+
expect((descendingReply.entries[2]).recordId).to.equal(oldestWrite.message.recordId);
|
|
1321
|
+
}));
|
|
1322
|
+
it('should paginate all records in ascending order', () => __awaiter(this, void 0, void 0, function* () {
|
|
1323
|
+
var _a;
|
|
1324
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
1325
|
+
const messages = yield Promise.all(Array(12).fill({}).map(_ => TestDataGenerator.generateRecordsWrite({
|
|
1326
|
+
author: alice,
|
|
1327
|
+
schema: 'https://schema'
|
|
1328
|
+
})));
|
|
1329
|
+
for (const message of messages) {
|
|
1330
|
+
const result = yield dwn.processMessage(alice.did, message.message, { dataStream: message.dataStream });
|
|
1331
|
+
expect(result.status.code).to.equal(202);
|
|
1332
|
+
}
|
|
1333
|
+
const limit = 5;
|
|
1334
|
+
const results = [];
|
|
1335
|
+
let cursor;
|
|
1336
|
+
while (true) {
|
|
1337
|
+
const pageQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
1338
|
+
author: alice,
|
|
1339
|
+
filter: {
|
|
1340
|
+
schema: 'https://schema'
|
|
1341
|
+
},
|
|
1342
|
+
pagination: {
|
|
1343
|
+
limit: limit,
|
|
1344
|
+
cursor,
|
|
1345
|
+
},
|
|
1346
|
+
dateSort: DateSort.CreatedAscending
|
|
1347
|
+
});
|
|
1348
|
+
const pageReply = yield dwn.processMessage(alice.did, pageQuery.message);
|
|
1349
|
+
expect(pageReply.status.code).to.equal(200);
|
|
1350
|
+
cursor = pageReply.cursor;
|
|
1351
|
+
expect((_a = pageReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.be.lte(limit);
|
|
1352
|
+
results.push(...pageReply.entries);
|
|
1353
|
+
if (cursor === undefined) {
|
|
1354
|
+
break;
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
expect(results.length).to.equal(messages.length);
|
|
1358
|
+
expect(messages.every(({ message }) => results.map(e => e.recordId).includes(message.recordId)));
|
|
1359
|
+
}));
|
|
1360
|
+
it('should paginate all records in descending order', () => __awaiter(this, void 0, void 0, function* () {
|
|
1361
|
+
var _a;
|
|
1362
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
1363
|
+
const messages = yield Promise.all(Array(12).fill({}).map(_ => TestDataGenerator.generateRecordsWrite({
|
|
1364
|
+
author: alice,
|
|
1365
|
+
schema: 'https://schema'
|
|
1366
|
+
})));
|
|
1367
|
+
for (const message of messages) {
|
|
1368
|
+
const result = yield dwn.processMessage(alice.did, message.message, { dataStream: message.dataStream });
|
|
1369
|
+
expect(result.status.code).to.equal(202);
|
|
1370
|
+
}
|
|
1371
|
+
const limit = 5;
|
|
1372
|
+
const results = [];
|
|
1373
|
+
let cursor;
|
|
1374
|
+
while (true) {
|
|
1375
|
+
const pageQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
1376
|
+
author: alice,
|
|
1377
|
+
filter: {
|
|
1378
|
+
schema: 'https://schema'
|
|
1379
|
+
},
|
|
1380
|
+
pagination: {
|
|
1381
|
+
limit: limit,
|
|
1382
|
+
cursor,
|
|
1383
|
+
},
|
|
1384
|
+
dateSort: DateSort.CreatedDescending,
|
|
1385
|
+
});
|
|
1386
|
+
const pageReply = yield dwn.processMessage(alice.did, pageQuery.message);
|
|
1387
|
+
expect(pageReply.status.code).to.equal(200);
|
|
1388
|
+
cursor = pageReply.cursor;
|
|
1389
|
+
expect((_a = pageReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.be.lte(limit);
|
|
1390
|
+
results.push(...pageReply.entries);
|
|
1391
|
+
if (cursor === undefined) {
|
|
1392
|
+
break;
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
expect(results.length).to.equal(messages.length);
|
|
1396
|
+
expect(messages.every(({ message }) => results.map(e => e.recordId).includes(message.recordId)));
|
|
1397
|
+
}));
|
|
1398
|
+
it('should allow an anonymous unauthenticated query to return published records', () => __awaiter(this, void 0, void 0, function* () {
|
|
1399
|
+
var _a, _b;
|
|
1400
|
+
// write 2 records into Alice's DB:
|
|
1401
|
+
// 1st is unpublished
|
|
1402
|
+
// 2nd is published
|
|
1403
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
1404
|
+
const record1Data = yield TestDataGenerator.generateRecordsWrite({ author: alice, schema: 'https://schema1', published: false });
|
|
1405
|
+
const record2Data = yield TestDataGenerator.generateRecordsWrite({ author: alice, schema: 'https://schema2', published: true });
|
|
1406
|
+
const recordsWrite1Reply = yield dwn.processMessage(alice.did, record1Data.message, { dataStream: record1Data.dataStream });
|
|
1407
|
+
expect(recordsWrite1Reply.status.code).to.equal(202);
|
|
1408
|
+
const recordsWrite2Reply = yield dwn.processMessage(alice.did, record2Data.message, { dataStream: record2Data.dataStream });
|
|
1409
|
+
expect(recordsWrite2Reply.status.code).to.equal(202);
|
|
1410
|
+
// test correctness for anonymous query
|
|
1411
|
+
const anonymousQueryMessageData = yield TestDataGenerator.generateRecordsQuery({
|
|
1412
|
+
anonymous: true,
|
|
1413
|
+
filter: { dateCreated: { from: '2000-01-01T10:20:30.123456Z' } }
|
|
1414
|
+
});
|
|
1415
|
+
// sanity check
|
|
1416
|
+
expect(anonymousQueryMessageData.message.authorization).to.not.exist;
|
|
1417
|
+
const replyToQuery = yield dwn.processMessage(alice.did, anonymousQueryMessageData.message);
|
|
1418
|
+
expect(replyToQuery.status.code).to.equal(200);
|
|
1419
|
+
expect((_a = replyToQuery.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(1);
|
|
1420
|
+
expect(replyToQuery.entries[0].descriptor.schema).to.equal('https://schema2');
|
|
1421
|
+
// explicitly for published records
|
|
1422
|
+
const anonymousQueryPublished = yield TestDataGenerator.generateRecordsQuery({
|
|
1423
|
+
anonymous: true,
|
|
1424
|
+
filter: { dateCreated: { from: '2000-01-01T10:20:30.123456Z' }, published: true }
|
|
1425
|
+
});
|
|
1426
|
+
// sanity check
|
|
1427
|
+
expect(anonymousQueryPublished.message.authorization).to.not.exist;
|
|
1428
|
+
// should return the published records
|
|
1429
|
+
const publishedReply = yield dwn.processMessage(alice.did, anonymousQueryPublished.message);
|
|
1430
|
+
expect(publishedReply.status.code).to.equal(200);
|
|
1431
|
+
expect((_b = publishedReply.entries) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
1432
|
+
expect(publishedReply.entries[0].descriptor.schema).to.equal('https://schema2');
|
|
1433
|
+
}));
|
|
1434
|
+
it('should only return published records and unpublished records that are meant for specific recipient(s)', () => __awaiter(this, void 0, void 0, function* () {
|
|
1435
|
+
// scenario: Alice installs a free-for-all protocol on her DWN
|
|
1436
|
+
// She writes both private and public messages for bob and carol, carol and bob also write public and privet messages for alice and each other
|
|
1437
|
+
// Bob, Alice and Carol should only be able to see private messages pertaining to themselves, and any public messages filtered by a recipient
|
|
1438
|
+
// Bob, Alice and Carol should be able to filter for ONLY public messages or ONLY private messages
|
|
1439
|
+
var _a, _b, _c, _d;
|
|
1440
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
1441
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
1442
|
+
const carol = yield TestDataGenerator.generateDidKeyPersona();
|
|
1443
|
+
// install the free-for-all protocol on Alice's DWN
|
|
1444
|
+
const protocolConfigure = yield TestDataGenerator.generateProtocolsConfigure({
|
|
1445
|
+
author: alice,
|
|
1446
|
+
protocolDefinition: freeForAll
|
|
1447
|
+
});
|
|
1448
|
+
const protocolConfigureReply = yield dwn.processMessage(alice.did, protocolConfigure.message);
|
|
1449
|
+
expect(protocolConfigureReply.status.code).to.equal(202);
|
|
1450
|
+
// write private records for bob and carol
|
|
1451
|
+
const alicePrivateToBob = yield TestDataGenerator.generateRecordsWrite({
|
|
1452
|
+
author: alice,
|
|
1453
|
+
recipient: bob.did,
|
|
1454
|
+
protocol: freeForAll.protocol,
|
|
1455
|
+
protocolPath: 'post',
|
|
1456
|
+
schema: freeForAll.types.post.schema,
|
|
1457
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1458
|
+
});
|
|
1459
|
+
const alicePrivateToBobReply = yield dwn.processMessage(alice.did, alicePrivateToBob.message, { dataStream: alicePrivateToBob.dataStream });
|
|
1460
|
+
expect(alicePrivateToBobReply.status.code).to.equal(202);
|
|
1461
|
+
const alicePrivateToCarol = yield TestDataGenerator.generateRecordsWrite({
|
|
1462
|
+
author: alice,
|
|
1463
|
+
recipient: carol.did,
|
|
1464
|
+
protocol: freeForAll.protocol,
|
|
1465
|
+
protocolPath: 'post',
|
|
1466
|
+
schema: freeForAll.types.post.schema,
|
|
1467
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1468
|
+
});
|
|
1469
|
+
const alicePrivateToCarolReply = yield dwn.processMessage(alice.did, alicePrivateToCarol.message, {
|
|
1470
|
+
dataStream: alicePrivateToCarol.dataStream
|
|
1471
|
+
});
|
|
1472
|
+
expect(alicePrivateToCarolReply.status.code).to.equal(202);
|
|
1473
|
+
// write private records from carol to alice and bob
|
|
1474
|
+
const carolPrivateToAlice = yield TestDataGenerator.generateRecordsWrite({
|
|
1475
|
+
author: carol,
|
|
1476
|
+
recipient: alice.did,
|
|
1477
|
+
protocol: freeForAll.protocol,
|
|
1478
|
+
protocolPath: 'post',
|
|
1479
|
+
schema: freeForAll.types.post.schema,
|
|
1480
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1481
|
+
});
|
|
1482
|
+
const carolPrivateToAliceReply = yield dwn.processMessage(alice.did, carolPrivateToAlice.message, {
|
|
1483
|
+
dataStream: carolPrivateToAlice.dataStream
|
|
1484
|
+
});
|
|
1485
|
+
expect(carolPrivateToAliceReply.status.code).to.equal(202);
|
|
1486
|
+
const carolPrivateToBob = yield TestDataGenerator.generateRecordsWrite({
|
|
1487
|
+
author: carol,
|
|
1488
|
+
recipient: bob.did,
|
|
1489
|
+
protocol: freeForAll.protocol,
|
|
1490
|
+
protocolPath: 'post',
|
|
1491
|
+
schema: freeForAll.types.post.schema,
|
|
1492
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1493
|
+
});
|
|
1494
|
+
const carolPrivateToBobReply = yield dwn.processMessage(alice.did, carolPrivateToBob.message, {
|
|
1495
|
+
dataStream: carolPrivateToBob.dataStream
|
|
1496
|
+
});
|
|
1497
|
+
expect(carolPrivateToBobReply.status.code).to.equal(202);
|
|
1498
|
+
// write private records from bob to alice and carol
|
|
1499
|
+
const bobPrivateToAlice = yield TestDataGenerator.generateRecordsWrite({
|
|
1500
|
+
author: bob,
|
|
1501
|
+
recipient: alice.did,
|
|
1502
|
+
protocol: freeForAll.protocol,
|
|
1503
|
+
protocolPath: 'post',
|
|
1504
|
+
schema: freeForAll.types.post.schema,
|
|
1505
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1506
|
+
});
|
|
1507
|
+
const bobPrivateToAliceReply = yield dwn.processMessage(alice.did, bobPrivateToAlice.message, {
|
|
1508
|
+
dataStream: bobPrivateToAlice.dataStream
|
|
1509
|
+
});
|
|
1510
|
+
expect(bobPrivateToAliceReply.status.code).to.equal(202);
|
|
1511
|
+
const bobPrivateToCarol = yield TestDataGenerator.generateRecordsWrite({
|
|
1512
|
+
author: bob,
|
|
1513
|
+
recipient: carol.did,
|
|
1514
|
+
protocol: freeForAll.protocol,
|
|
1515
|
+
protocolPath: 'post',
|
|
1516
|
+
schema: freeForAll.types.post.schema,
|
|
1517
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1518
|
+
});
|
|
1519
|
+
const bobPrivateToCarolReply = yield dwn.processMessage(alice.did, bobPrivateToCarol.message, {
|
|
1520
|
+
dataStream: bobPrivateToCarol.dataStream
|
|
1521
|
+
});
|
|
1522
|
+
expect(bobPrivateToCarolReply.status.code).to.equal(202);
|
|
1523
|
+
// write public records from alice to bob and carol
|
|
1524
|
+
const alicePublicToBob = yield TestDataGenerator.generateRecordsWrite({
|
|
1525
|
+
author: alice,
|
|
1526
|
+
recipient: bob.did,
|
|
1527
|
+
protocol: freeForAll.protocol,
|
|
1528
|
+
protocolPath: 'post',
|
|
1529
|
+
schema: freeForAll.types.post.schema,
|
|
1530
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1531
|
+
published: true
|
|
1532
|
+
});
|
|
1533
|
+
const alicePublicToBobReply = yield dwn.processMessage(alice.did, alicePublicToBob.message, {
|
|
1534
|
+
dataStream: alicePublicToBob.dataStream
|
|
1535
|
+
});
|
|
1536
|
+
expect(alicePublicToBobReply.status.code).to.equal(202);
|
|
1537
|
+
const alicePublicToCarol = yield TestDataGenerator.generateRecordsWrite({
|
|
1538
|
+
author: alice,
|
|
1539
|
+
recipient: carol.did,
|
|
1540
|
+
protocol: freeForAll.protocol,
|
|
1541
|
+
protocolPath: 'post',
|
|
1542
|
+
schema: freeForAll.types.post.schema,
|
|
1543
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1544
|
+
published: true
|
|
1545
|
+
});
|
|
1546
|
+
const alicePublicToCarolReply = yield dwn.processMessage(alice.did, alicePublicToCarol.message, {
|
|
1547
|
+
dataStream: alicePublicToCarol.dataStream
|
|
1548
|
+
});
|
|
1549
|
+
expect(alicePublicToCarolReply.status.code).to.equal(202);
|
|
1550
|
+
// write public records from bob to alice and carol
|
|
1551
|
+
const bobPublicToAlice = yield TestDataGenerator.generateRecordsWrite({
|
|
1552
|
+
author: bob,
|
|
1553
|
+
recipient: alice.did,
|
|
1554
|
+
protocol: freeForAll.protocol,
|
|
1555
|
+
protocolPath: 'post',
|
|
1556
|
+
schema: freeForAll.types.post.schema,
|
|
1557
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1558
|
+
published: true
|
|
1559
|
+
});
|
|
1560
|
+
const bobPublicToAliceReply = yield dwn.processMessage(alice.did, bobPublicToAlice.message, {
|
|
1561
|
+
dataStream: bobPublicToAlice.dataStream
|
|
1562
|
+
});
|
|
1563
|
+
expect(bobPublicToAliceReply.status.code).to.equal(202);
|
|
1564
|
+
const bobPublicToCarol = yield TestDataGenerator.generateRecordsWrite({
|
|
1565
|
+
author: bob,
|
|
1566
|
+
recipient: carol.did,
|
|
1567
|
+
protocol: freeForAll.protocol,
|
|
1568
|
+
protocolPath: 'post',
|
|
1569
|
+
schema: freeForAll.types.post.schema,
|
|
1570
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1571
|
+
published: true
|
|
1572
|
+
});
|
|
1573
|
+
const bobPublicToCarolReply = yield dwn.processMessage(alice.did, bobPublicToCarol.message, {
|
|
1574
|
+
dataStream: bobPublicToCarol.dataStream
|
|
1575
|
+
});
|
|
1576
|
+
expect(bobPublicToCarolReply.status.code).to.equal(202);
|
|
1577
|
+
// write public records from carol to alice and bob
|
|
1578
|
+
const carolPublicToAlice = yield TestDataGenerator.generateRecordsWrite({
|
|
1579
|
+
author: carol,
|
|
1580
|
+
recipient: alice.did,
|
|
1581
|
+
protocol: freeForAll.protocol,
|
|
1582
|
+
protocolPath: 'post',
|
|
1583
|
+
schema: freeForAll.types.post.schema,
|
|
1584
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1585
|
+
published: true
|
|
1586
|
+
});
|
|
1587
|
+
const carolPublicToAliceReply = yield dwn.processMessage(alice.did, carolPublicToAlice.message, {
|
|
1588
|
+
dataStream: carolPublicToAlice.dataStream
|
|
1589
|
+
});
|
|
1590
|
+
expect(carolPublicToAliceReply.status.code).to.equal(202);
|
|
1591
|
+
const carolPublicToBob = yield TestDataGenerator.generateRecordsWrite({
|
|
1592
|
+
author: carol,
|
|
1593
|
+
recipient: bob.did,
|
|
1594
|
+
protocol: freeForAll.protocol,
|
|
1595
|
+
protocolPath: 'post',
|
|
1596
|
+
schema: freeForAll.types.post.schema,
|
|
1597
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1598
|
+
published: true
|
|
1599
|
+
});
|
|
1600
|
+
const carolPublicToBobReply = yield dwn.processMessage(alice.did, carolPublicToBob.message, {
|
|
1601
|
+
dataStream: carolPublicToBob.dataStream
|
|
1602
|
+
});
|
|
1603
|
+
expect(carolPublicToBobReply.status.code).to.equal(202);
|
|
1604
|
+
// bob queries for records with himself and alice as recipients
|
|
1605
|
+
const bobQueryMessagesForBobAlice = yield TestDataGenerator.generateRecordsQuery({
|
|
1606
|
+
author: bob,
|
|
1607
|
+
filter: { protocol: freeForAll.protocol, protocolPath: 'post', recipient: [bob.did, alice.did] }
|
|
1608
|
+
});
|
|
1609
|
+
const bobQueryMessagesForBobAliceReply = yield dwn.processMessage(alice.did, bobQueryMessagesForBobAlice.message);
|
|
1610
|
+
expect(bobQueryMessagesForBobAliceReply.status.code).to.equal(200);
|
|
1611
|
+
expect((_a = bobQueryMessagesForBobAliceReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(7);
|
|
1612
|
+
// Since Bob is the author if the query, we expect for him to be able to see:
|
|
1613
|
+
// Private Messages THAT ANYONE sent to Bob
|
|
1614
|
+
// Private Messages THAT ONLY HE sent to Alice
|
|
1615
|
+
// Public Messages THAT ANYONE sent to Alice
|
|
1616
|
+
// Public Messages THAT ANYONE sent to Bob
|
|
1617
|
+
expect(bobQueryMessagesForBobAliceReply.entries.map(e => e.recordId)).to.have.members([
|
|
1618
|
+
alicePrivateToBob.message.recordId,
|
|
1619
|
+
carolPrivateToBob.message.recordId,
|
|
1620
|
+
bobPrivateToAlice.message.recordId,
|
|
1621
|
+
alicePublicToBob.message.recordId,
|
|
1622
|
+
bobPublicToAlice.message.recordId,
|
|
1623
|
+
carolPublicToAlice.message.recordId,
|
|
1624
|
+
carolPublicToBob.message.recordId,
|
|
1625
|
+
]);
|
|
1626
|
+
// carol queries for records with herself as the recipient
|
|
1627
|
+
const carolQueryMessagesForCarolAlice = yield TestDataGenerator.generateRecordsQuery({
|
|
1628
|
+
author: carol,
|
|
1629
|
+
filter: { protocol: freeForAll.protocol, protocolPath: 'post', recipient: carol.did }
|
|
1630
|
+
});
|
|
1631
|
+
const carolQueryMessagesForCarolAliceReply = yield dwn.processMessage(alice.did, carolQueryMessagesForCarolAlice.message);
|
|
1632
|
+
expect(carolQueryMessagesForCarolAliceReply.status.code).to.equal(200);
|
|
1633
|
+
expect((_b = carolQueryMessagesForCarolAliceReply.entries) === null || _b === void 0 ? void 0 : _b.length).to.equal(4);
|
|
1634
|
+
// Since Carol is the author if the query, we expect for her to be able to see:
|
|
1635
|
+
// Private Messages THAT ANYONE sent to Carol
|
|
1636
|
+
// Private Messages THAT ONLY SHE sent to Alice
|
|
1637
|
+
// Public Messages THAT ANYONE sent to Alice
|
|
1638
|
+
// Public Messages THAT ANYONE sent to Carol
|
|
1639
|
+
expect(carolQueryMessagesForCarolAliceReply.entries.map(e => e.recordId)).to.have.members([
|
|
1640
|
+
alicePrivateToCarol.message.recordId,
|
|
1641
|
+
bobPrivateToCarol.message.recordId,
|
|
1642
|
+
alicePublicToCarol.message.recordId,
|
|
1643
|
+
bobPublicToCarol.message.recordId,
|
|
1644
|
+
]);
|
|
1645
|
+
// alice queries for ONLY published records with herself and bob as recipients
|
|
1646
|
+
const aliceQueryPublished = yield TestDataGenerator.generateRecordsQuery({
|
|
1647
|
+
author: alice,
|
|
1648
|
+
filter: { protocol: freeForAll.protocol, protocolPath: 'post', recipient: [alice.did, bob.did], published: true }
|
|
1649
|
+
});
|
|
1650
|
+
const aliceQueryPublishedReply = yield dwn.processMessage(alice.did, aliceQueryPublished.message);
|
|
1651
|
+
expect(aliceQueryPublishedReply.status.code).to.equal(200);
|
|
1652
|
+
expect((_c = aliceQueryPublishedReply.entries) === null || _c === void 0 ? void 0 : _c.length).to.equal(4);
|
|
1653
|
+
expect(aliceQueryPublishedReply.entries.map(e => e.recordId)).to.have.members([
|
|
1654
|
+
alicePublicToBob.message.recordId,
|
|
1655
|
+
carolPublicToBob.message.recordId,
|
|
1656
|
+
bobPublicToAlice.message.recordId,
|
|
1657
|
+
carolPublicToAlice.message.recordId,
|
|
1658
|
+
]);
|
|
1659
|
+
// carol queries for ONLY private records with herself and alice as the recipients
|
|
1660
|
+
const carolQueryPrivate = yield TestDataGenerator.generateRecordsQuery({
|
|
1661
|
+
author: carol,
|
|
1662
|
+
filter: { protocol: freeForAll.protocol, protocolPath: 'post', recipient: [carol.did, alice.did], published: false }
|
|
1663
|
+
});
|
|
1664
|
+
const carolQueryPrivateReply = yield dwn.processMessage(alice.did, carolQueryPrivate.message);
|
|
1665
|
+
expect(carolQueryPrivateReply.status.code).to.equal(200);
|
|
1666
|
+
expect((_d = carolQueryPrivateReply.entries) === null || _d === void 0 ? void 0 : _d.length).to.equal(3);
|
|
1667
|
+
// Carol can query for private messages she authored to alice, and her own private messages with herself as the recipient
|
|
1668
|
+
expect(carolQueryPrivateReply.entries.map(e => e.recordId)).to.have.members([
|
|
1669
|
+
alicePrivateToCarol.message.recordId,
|
|
1670
|
+
bobPrivateToCarol.message.recordId,
|
|
1671
|
+
carolPrivateToAlice.message.recordId,
|
|
1672
|
+
]);
|
|
1673
|
+
}));
|
|
1674
|
+
it('should only return published records and unpublished records that are authored by specific author(s)', () => __awaiter(this, void 0, void 0, function* () {
|
|
1675
|
+
// scenario: Alice installs a free-for-all protocol on her DWN
|
|
1676
|
+
// She writes both private and public messages for bob and carol, carol and bob also write public and privet messages for alice and each other
|
|
1677
|
+
// Bob, Alice and Carol should only be able to see private messages pertaining to themselves, and any public messages filtered by an author
|
|
1678
|
+
// Bob, Alice and Carol should be able to filter for ONLY public messages or ONLY private messages
|
|
1679
|
+
var _a, _b, _c, _d;
|
|
1680
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
1681
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
1682
|
+
const carol = yield TestDataGenerator.generateDidKeyPersona();
|
|
1683
|
+
// install the free-for-all protocol on Alice's DWN
|
|
1684
|
+
const protocolConfigure = yield TestDataGenerator.generateProtocolsConfigure({
|
|
1685
|
+
author: alice,
|
|
1686
|
+
protocolDefinition: freeForAll
|
|
1687
|
+
});
|
|
1688
|
+
const protocolConfigureReply = yield dwn.processMessage(alice.did, protocolConfigure.message);
|
|
1689
|
+
expect(protocolConfigureReply.status.code).to.equal(202);
|
|
1690
|
+
// write private records for bob and carol
|
|
1691
|
+
const alicePrivateToBob = yield TestDataGenerator.generateRecordsWrite({
|
|
1692
|
+
author: alice,
|
|
1693
|
+
recipient: bob.did,
|
|
1694
|
+
protocol: freeForAll.protocol,
|
|
1695
|
+
protocolPath: 'post',
|
|
1696
|
+
schema: freeForAll.types.post.schema,
|
|
1697
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1698
|
+
});
|
|
1699
|
+
const alicePrivateToBobReply = yield dwn.processMessage(alice.did, alicePrivateToBob.message, { dataStream: alicePrivateToBob.dataStream });
|
|
1700
|
+
expect(alicePrivateToBobReply.status.code).to.equal(202);
|
|
1701
|
+
const alicePrivateToCarol = yield TestDataGenerator.generateRecordsWrite({
|
|
1702
|
+
author: alice,
|
|
1703
|
+
recipient: carol.did,
|
|
1704
|
+
protocol: freeForAll.protocol,
|
|
1705
|
+
protocolPath: 'post',
|
|
1706
|
+
schema: freeForAll.types.post.schema,
|
|
1707
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1708
|
+
});
|
|
1709
|
+
const alicePrivateToCarolReply = yield dwn.processMessage(alice.did, alicePrivateToCarol.message, {
|
|
1710
|
+
dataStream: alicePrivateToCarol.dataStream
|
|
1711
|
+
});
|
|
1712
|
+
expect(alicePrivateToCarolReply.status.code).to.equal(202);
|
|
1713
|
+
// write private records from carol to alice and bob
|
|
1714
|
+
const carolPrivateToAlice = yield TestDataGenerator.generateRecordsWrite({
|
|
1715
|
+
author: carol,
|
|
1716
|
+
recipient: alice.did,
|
|
1717
|
+
protocol: freeForAll.protocol,
|
|
1718
|
+
protocolPath: 'post',
|
|
1719
|
+
schema: freeForAll.types.post.schema,
|
|
1720
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1721
|
+
});
|
|
1722
|
+
const carolPrivateToAliceReply = yield dwn.processMessage(alice.did, carolPrivateToAlice.message, {
|
|
1723
|
+
dataStream: carolPrivateToAlice.dataStream
|
|
1724
|
+
});
|
|
1725
|
+
expect(carolPrivateToAliceReply.status.code).to.equal(202);
|
|
1726
|
+
const carolPrivateToBob = yield TestDataGenerator.generateRecordsWrite({
|
|
1727
|
+
author: carol,
|
|
1728
|
+
recipient: bob.did,
|
|
1729
|
+
protocol: freeForAll.protocol,
|
|
1730
|
+
protocolPath: 'post',
|
|
1731
|
+
schema: freeForAll.types.post.schema,
|
|
1732
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1733
|
+
});
|
|
1734
|
+
const carolPrivateToBobReply = yield dwn.processMessage(alice.did, carolPrivateToBob.message, {
|
|
1735
|
+
dataStream: carolPrivateToBob.dataStream
|
|
1736
|
+
});
|
|
1737
|
+
expect(carolPrivateToBobReply.status.code).to.equal(202);
|
|
1738
|
+
// write private records from bob to alice and carol
|
|
1739
|
+
const bobPrivateToAlice = yield TestDataGenerator.generateRecordsWrite({
|
|
1740
|
+
author: bob,
|
|
1741
|
+
recipient: alice.did,
|
|
1742
|
+
protocol: freeForAll.protocol,
|
|
1743
|
+
protocolPath: 'post',
|
|
1744
|
+
schema: freeForAll.types.post.schema,
|
|
1745
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1746
|
+
});
|
|
1747
|
+
const bobPrivateToAliceReply = yield dwn.processMessage(alice.did, bobPrivateToAlice.message, {
|
|
1748
|
+
dataStream: bobPrivateToAlice.dataStream
|
|
1749
|
+
});
|
|
1750
|
+
expect(bobPrivateToAliceReply.status.code).to.equal(202);
|
|
1751
|
+
const bobPrivateToCarol = yield TestDataGenerator.generateRecordsWrite({
|
|
1752
|
+
author: bob,
|
|
1753
|
+
recipient: carol.did,
|
|
1754
|
+
protocol: freeForAll.protocol,
|
|
1755
|
+
protocolPath: 'post',
|
|
1756
|
+
schema: freeForAll.types.post.schema,
|
|
1757
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1758
|
+
});
|
|
1759
|
+
const bobPrivateToCarolReply = yield dwn.processMessage(alice.did, bobPrivateToCarol.message, {
|
|
1760
|
+
dataStream: bobPrivateToCarol.dataStream
|
|
1761
|
+
});
|
|
1762
|
+
expect(bobPrivateToCarolReply.status.code).to.equal(202);
|
|
1763
|
+
// write public records from alice to bob and carol
|
|
1764
|
+
const alicePublicToBob = yield TestDataGenerator.generateRecordsWrite({
|
|
1765
|
+
author: alice,
|
|
1766
|
+
recipient: bob.did,
|
|
1767
|
+
protocol: freeForAll.protocol,
|
|
1768
|
+
protocolPath: 'post',
|
|
1769
|
+
schema: freeForAll.types.post.schema,
|
|
1770
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1771
|
+
published: true
|
|
1772
|
+
});
|
|
1773
|
+
const alicePublicToBobReply = yield dwn.processMessage(alice.did, alicePublicToBob.message, {
|
|
1774
|
+
dataStream: alicePublicToBob.dataStream
|
|
1775
|
+
});
|
|
1776
|
+
expect(alicePublicToBobReply.status.code).to.equal(202);
|
|
1777
|
+
const alicePublicToCarol = yield TestDataGenerator.generateRecordsWrite({
|
|
1778
|
+
author: alice,
|
|
1779
|
+
recipient: carol.did,
|
|
1780
|
+
protocol: freeForAll.protocol,
|
|
1781
|
+
protocolPath: 'post',
|
|
1782
|
+
schema: freeForAll.types.post.schema,
|
|
1783
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1784
|
+
published: true
|
|
1785
|
+
});
|
|
1786
|
+
const alicePublicToCarolReply = yield dwn.processMessage(alice.did, alicePublicToCarol.message, {
|
|
1787
|
+
dataStream: alicePublicToCarol.dataStream
|
|
1788
|
+
});
|
|
1789
|
+
expect(alicePublicToCarolReply.status.code).to.equal(202);
|
|
1790
|
+
// write public records from bob to alice and carol
|
|
1791
|
+
const bobPublicToAlice = yield TestDataGenerator.generateRecordsWrite({
|
|
1792
|
+
author: bob,
|
|
1793
|
+
recipient: alice.did,
|
|
1794
|
+
protocol: freeForAll.protocol,
|
|
1795
|
+
protocolPath: 'post',
|
|
1796
|
+
schema: freeForAll.types.post.schema,
|
|
1797
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1798
|
+
published: true
|
|
1799
|
+
});
|
|
1800
|
+
const bobPublicToAliceReply = yield dwn.processMessage(alice.did, bobPublicToAlice.message, {
|
|
1801
|
+
dataStream: bobPublicToAlice.dataStream
|
|
1802
|
+
});
|
|
1803
|
+
expect(bobPublicToAliceReply.status.code).to.equal(202);
|
|
1804
|
+
const bobPublicToCarol = yield TestDataGenerator.generateRecordsWrite({
|
|
1805
|
+
author: bob,
|
|
1806
|
+
recipient: carol.did,
|
|
1807
|
+
protocol: freeForAll.protocol,
|
|
1808
|
+
protocolPath: 'post',
|
|
1809
|
+
schema: freeForAll.types.post.schema,
|
|
1810
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1811
|
+
published: true
|
|
1812
|
+
});
|
|
1813
|
+
const bobPublicToCarolReply = yield dwn.processMessage(alice.did, bobPublicToCarol.message, {
|
|
1814
|
+
dataStream: bobPublicToCarol.dataStream
|
|
1815
|
+
});
|
|
1816
|
+
expect(bobPublicToCarolReply.status.code).to.equal(202);
|
|
1817
|
+
// write public records from carol to alice and bob
|
|
1818
|
+
const carolPublicToAlice = yield TestDataGenerator.generateRecordsWrite({
|
|
1819
|
+
author: carol,
|
|
1820
|
+
recipient: alice.did,
|
|
1821
|
+
protocol: freeForAll.protocol,
|
|
1822
|
+
protocolPath: 'post',
|
|
1823
|
+
schema: freeForAll.types.post.schema,
|
|
1824
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1825
|
+
published: true
|
|
1826
|
+
});
|
|
1827
|
+
const carolPublicToAliceReply = yield dwn.processMessage(alice.did, carolPublicToAlice.message, {
|
|
1828
|
+
dataStream: carolPublicToAlice.dataStream
|
|
1829
|
+
});
|
|
1830
|
+
expect(carolPublicToAliceReply.status.code).to.equal(202);
|
|
1831
|
+
const carolPublicToBob = yield TestDataGenerator.generateRecordsWrite({
|
|
1832
|
+
author: carol,
|
|
1833
|
+
recipient: bob.did,
|
|
1834
|
+
protocol: freeForAll.protocol,
|
|
1835
|
+
protocolPath: 'post',
|
|
1836
|
+
schema: freeForAll.types.post.schema,
|
|
1837
|
+
dataFormat: freeForAll.types.post.dataFormats[0],
|
|
1838
|
+
published: true
|
|
1839
|
+
});
|
|
1840
|
+
const carolPublicToBobReply = yield dwn.processMessage(alice.did, carolPublicToBob.message, {
|
|
1841
|
+
dataStream: carolPublicToBob.dataStream
|
|
1842
|
+
});
|
|
1843
|
+
expect(carolPublicToBobReply.status.code).to.equal(202);
|
|
1844
|
+
// bob queries for records with himself and alice as authors
|
|
1845
|
+
const bobQueryMessagesForBobAlice = yield TestDataGenerator.generateRecordsQuery({
|
|
1846
|
+
author: bob,
|
|
1847
|
+
filter: { protocol: freeForAll.protocol, protocolPath: 'post', author: [bob.did, alice.did] }
|
|
1848
|
+
});
|
|
1849
|
+
const bobQueryMessagesForBobAliceReply = yield dwn.processMessage(alice.did, bobQueryMessagesForBobAlice.message);
|
|
1850
|
+
expect(bobQueryMessagesForBobAliceReply.status.code).to.equal(200);
|
|
1851
|
+
expect((_a = bobQueryMessagesForBobAliceReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(7);
|
|
1852
|
+
// Since Bob is the author if the query, we expect for him to be able to see:
|
|
1853
|
+
// Private Messages Bob authored TO ANYONE
|
|
1854
|
+
// Private Messages Alice authored To Bob
|
|
1855
|
+
// Public Messages Alice authored
|
|
1856
|
+
// Public Messages Bob authored
|
|
1857
|
+
expect(bobQueryMessagesForBobAliceReply.entries.map(e => e.recordId)).to.have.members([
|
|
1858
|
+
alicePrivateToBob.message.recordId,
|
|
1859
|
+
bobPrivateToAlice.message.recordId,
|
|
1860
|
+
bobPrivateToCarol.message.recordId,
|
|
1861
|
+
alicePublicToBob.message.recordId,
|
|
1862
|
+
alicePublicToCarol.message.recordId,
|
|
1863
|
+
bobPublicToAlice.message.recordId,
|
|
1864
|
+
bobPublicToCarol.message.recordId
|
|
1865
|
+
]);
|
|
1866
|
+
// carol queries for records with herself as the author
|
|
1867
|
+
const carolQueryMessagesForCarolAlice = yield TestDataGenerator.generateRecordsQuery({
|
|
1868
|
+
author: carol,
|
|
1869
|
+
filter: { protocol: freeForAll.protocol, protocolPath: 'post', author: carol.did }
|
|
1870
|
+
});
|
|
1871
|
+
const carolQueryMessagesForCarolAliceReply = yield dwn.processMessage(alice.did, carolQueryMessagesForCarolAlice.message);
|
|
1872
|
+
expect(carolQueryMessagesForCarolAliceReply.status.code).to.equal(200);
|
|
1873
|
+
expect((_b = carolQueryMessagesForCarolAliceReply.entries) === null || _b === void 0 ? void 0 : _b.length).to.equal(4);
|
|
1874
|
+
// Since Carol is the author if the query, we expect for her to be able to see:
|
|
1875
|
+
// All messages that Carol sent to anyone, private or public
|
|
1876
|
+
expect(carolQueryMessagesForCarolAliceReply.entries.map(e => e.recordId)).to.have.members([
|
|
1877
|
+
carolPrivateToAlice.message.recordId,
|
|
1878
|
+
carolPrivateToBob.message.recordId,
|
|
1879
|
+
carolPublicToAlice.message.recordId,
|
|
1880
|
+
carolPublicToBob.message.recordId
|
|
1881
|
+
]);
|
|
1882
|
+
// alice queries for ONLY published records with herself and bob as authors
|
|
1883
|
+
const aliceQueryPublished = yield TestDataGenerator.generateRecordsQuery({
|
|
1884
|
+
author: alice,
|
|
1885
|
+
filter: { protocol: freeForAll.protocol, protocolPath: 'post', author: [alice.did, bob.did], published: true }
|
|
1886
|
+
});
|
|
1887
|
+
const aliceQueryPublishedReply = yield dwn.processMessage(alice.did, aliceQueryPublished.message);
|
|
1888
|
+
expect(aliceQueryPublishedReply.status.code).to.equal(200);
|
|
1889
|
+
expect((_c = aliceQueryPublishedReply.entries) === null || _c === void 0 ? void 0 : _c.length).to.equal(4);
|
|
1890
|
+
expect(aliceQueryPublishedReply.entries.map(e => e.recordId)).to.have.members([
|
|
1891
|
+
alicePublicToBob.message.recordId,
|
|
1892
|
+
alicePublicToCarol.message.recordId,
|
|
1893
|
+
bobPublicToAlice.message.recordId,
|
|
1894
|
+
bobPublicToCarol.message.recordId
|
|
1895
|
+
]);
|
|
1896
|
+
// carol queries for ONLY private records with herself and alice as the authors
|
|
1897
|
+
const carolQueryPrivate = yield TestDataGenerator.generateRecordsQuery({
|
|
1898
|
+
author: carol,
|
|
1899
|
+
filter: { protocol: freeForAll.protocol, protocolPath: 'post', author: [carol.did, alice.did], published: false }
|
|
1900
|
+
});
|
|
1901
|
+
const carolQueryPrivateReply = yield dwn.processMessage(alice.did, carolQueryPrivate.message);
|
|
1902
|
+
expect(carolQueryPrivateReply.status.code).to.equal(200);
|
|
1903
|
+
expect((_d = carolQueryPrivateReply.entries) === null || _d === void 0 ? void 0 : _d.length).to.equal(3);
|
|
1904
|
+
expect(carolQueryPrivateReply.entries.map(e => e.recordId)).to.have.members([
|
|
1905
|
+
alicePrivateToCarol.message.recordId,
|
|
1906
|
+
carolPrivateToAlice.message.recordId,
|
|
1907
|
+
carolPrivateToBob.message.recordId
|
|
1908
|
+
]);
|
|
1909
|
+
}));
|
|
1910
|
+
it('should paginate correctly for fetchRecordsAsNonOwner()', () => __awaiter(this, void 0, void 0, function* () {
|
|
1911
|
+
var _a, e_1, _b, _c;
|
|
1912
|
+
var _d, _e, _f, _g, _h;
|
|
1913
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
1914
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
1915
|
+
const schema = 'schema1';
|
|
1916
|
+
// published messages bob
|
|
1917
|
+
const bobPublishedPromise = Array(5).fill({}).map(_ => TestDataGenerator.generateRecordsWrite({
|
|
1918
|
+
author: bob, schema, data: TestDataGenerator.randomBytes(10), published: true,
|
|
1919
|
+
}));
|
|
1920
|
+
// published messages alice
|
|
1921
|
+
const alicePublishedPromise = Array(5).fill({}).map(_ => TestDataGenerator.generateRecordsWrite({
|
|
1922
|
+
author: alice, schema, data: TestDataGenerator.randomBytes(10), published: true,
|
|
1923
|
+
}));
|
|
1924
|
+
// alice non public messages
|
|
1925
|
+
const aliceMessagesPromise = Array(5).fill({}).map(_ => TestDataGenerator.generateRecordsWrite({
|
|
1926
|
+
author: alice, schema, data: TestDataGenerator.randomBytes(10)
|
|
1927
|
+
}));
|
|
1928
|
+
// bob non public messages
|
|
1929
|
+
const bobMessagesPromise = Array(5).fill({}).map(_ => TestDataGenerator.generateRecordsWrite({
|
|
1930
|
+
author: bob, schema, data: TestDataGenerator.randomBytes(10)
|
|
1931
|
+
}));
|
|
1932
|
+
// non public messages intended for bob
|
|
1933
|
+
const aliceMessagesForBobPromise = Array(5).fill({}).map(_ => TestDataGenerator.generateRecordsWrite({
|
|
1934
|
+
author: alice, schema, data: TestDataGenerator.randomBytes(10), recipient: bob.did,
|
|
1935
|
+
}));
|
|
1936
|
+
const messagePromises = [
|
|
1937
|
+
...bobPublishedPromise,
|
|
1938
|
+
...aliceMessagesPromise,
|
|
1939
|
+
...bobMessagesPromise,
|
|
1940
|
+
...alicePublishedPromise,
|
|
1941
|
+
...aliceMessagesForBobPromise,
|
|
1942
|
+
];
|
|
1943
|
+
const recordsWriteHandler = new RecordsWriteHandler(didResolver, messageStore, dataStore, eventLog, eventStream);
|
|
1944
|
+
const messages = [];
|
|
1945
|
+
try {
|
|
1946
|
+
for (var _j = true, messagePromises_1 = __asyncValues(messagePromises), messagePromises_1_1; messagePromises_1_1 = yield messagePromises_1.next(), _a = messagePromises_1_1.done, !_a; _j = true) {
|
|
1947
|
+
_c = messagePromises_1_1.value;
|
|
1948
|
+
_j = false;
|
|
1949
|
+
const { recordsWrite, message, dataBytes } = _c;
|
|
1950
|
+
const indexes = yield recordsWrite.constructIndexes(true);
|
|
1951
|
+
const processedMessage = yield recordsWriteHandler.cloneAndAddEncodedData(message, dataBytes);
|
|
1952
|
+
yield messageStore.put(alice.did, processedMessage, indexes);
|
|
1953
|
+
yield eventLog.append(alice.did, yield Message.getCid(processedMessage), indexes);
|
|
1954
|
+
messages.push(processedMessage);
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
1958
|
+
finally {
|
|
1959
|
+
try {
|
|
1960
|
+
if (!_j && !_a && (_b = messagePromises_1.return)) yield _b.call(messagePromises_1);
|
|
1961
|
+
}
|
|
1962
|
+
finally { if (e_1) throw e_1.error; }
|
|
1963
|
+
}
|
|
1964
|
+
const sortedMessages = yield ArrayUtility.asyncSort(messages, (a, b) => __awaiter(this, void 0, void 0, function* () { return Message.compareMessageTimestamp(a, b); }));
|
|
1965
|
+
const aliceRetrieved = [];
|
|
1966
|
+
// fetch all from alice for sanity, alice should get all of the records
|
|
1967
|
+
// page1 alice
|
|
1968
|
+
const aliceQueryMessageDataPage1 = yield TestDataGenerator.generateRecordsQuery({
|
|
1969
|
+
author: alice,
|
|
1970
|
+
filter: { schema },
|
|
1971
|
+
dateSort: DateSort.CreatedAscending,
|
|
1972
|
+
pagination: { limit: 10 },
|
|
1973
|
+
});
|
|
1974
|
+
let results = yield dwn.processMessage(alice.did, aliceQueryMessageDataPage1.message);
|
|
1975
|
+
expect(results.status.code).to.equal(200);
|
|
1976
|
+
expect((_d = results.entries) === null || _d === void 0 ? void 0 : _d.length).to.equal(10, 'alice page 1');
|
|
1977
|
+
expect(results.cursor, 'alice page 1 cursor').to.not.be.undefined;
|
|
1978
|
+
aliceRetrieved.push(...results.entries);
|
|
1979
|
+
// page2 alice
|
|
1980
|
+
const aliceQueryMessageDataPage2 = yield TestDataGenerator.generateRecordsQuery({
|
|
1981
|
+
author: alice,
|
|
1982
|
+
filter: { schema },
|
|
1983
|
+
dateSort: DateSort.CreatedAscending,
|
|
1984
|
+
pagination: { limit: 10, cursor: results.cursor },
|
|
1985
|
+
});
|
|
1986
|
+
results = yield dwn.processMessage(alice.did, aliceQueryMessageDataPage2.message);
|
|
1987
|
+
expect(results.status.code).to.equal(200);
|
|
1988
|
+
expect((_e = results.entries) === null || _e === void 0 ? void 0 : _e.length).to.equal(10, 'alice page 2');
|
|
1989
|
+
expect(results.cursor, 'alice page 2 cursor').to.not.be.undefined;
|
|
1990
|
+
aliceRetrieved.push(...results.entries);
|
|
1991
|
+
// page3 alice
|
|
1992
|
+
const aliceQueryMessageDataPage3 = yield TestDataGenerator.generateRecordsQuery({
|
|
1993
|
+
author: alice,
|
|
1994
|
+
filter: { schema },
|
|
1995
|
+
dateSort: DateSort.CreatedAscending,
|
|
1996
|
+
pagination: { limit: 10, cursor: results.cursor },
|
|
1997
|
+
});
|
|
1998
|
+
results = yield dwn.processMessage(alice.did, aliceQueryMessageDataPage3.message);
|
|
1999
|
+
expect(results.status.code).to.equal(200);
|
|
2000
|
+
expect((_f = results.entries) === null || _f === void 0 ? void 0 : _f.length).to.equal(5, 'alice page 3');
|
|
2001
|
+
expect(results.cursor, 'alice page 3 cursor').to.not.exist;
|
|
2002
|
+
aliceRetrieved.push(...results.entries);
|
|
2003
|
+
const compareRecordId = (a, b) => {
|
|
2004
|
+
return a.recordId === b.recordId;
|
|
2005
|
+
};
|
|
2006
|
+
expect(sortedMessages.every((m, i) => compareRecordId(aliceRetrieved.at(i), m)));
|
|
2007
|
+
const bobs = (m) => {
|
|
2008
|
+
return m.descriptor.recipient === bob.did || m.descriptor.published === true || Message.getSigner(m) === bob.did;
|
|
2009
|
+
};
|
|
2010
|
+
// all records from alice have been validated
|
|
2011
|
+
// now we prepare to test records that only bob should get
|
|
2012
|
+
const bobSorted = sortedMessages.filter(m => bobs(m));
|
|
2013
|
+
const bobRetrieved = [];
|
|
2014
|
+
const bobQueryMessagePage1 = yield TestDataGenerator.generateRecordsQuery({
|
|
2015
|
+
author: bob,
|
|
2016
|
+
filter: { schema },
|
|
2017
|
+
dateSort: DateSort.CreatedAscending,
|
|
2018
|
+
pagination: { limit: 10 },
|
|
2019
|
+
});
|
|
2020
|
+
results = yield dwn.processMessage(alice.did, bobQueryMessagePage1.message);
|
|
2021
|
+
expect(results.status.code).to.equal(200);
|
|
2022
|
+
expect((_g = results.entries) === null || _g === void 0 ? void 0 : _g.length).to.equal(10, 'bob page 1');
|
|
2023
|
+
expect(results.cursor, 'bob page 1 cursor').to.not.be.undefined;
|
|
2024
|
+
bobRetrieved.push(...results.entries);
|
|
2025
|
+
const bobQueryMessagePage2 = yield TestDataGenerator.generateRecordsQuery({
|
|
2026
|
+
author: bob,
|
|
2027
|
+
filter: { schema },
|
|
2028
|
+
dateSort: DateSort.CreatedAscending,
|
|
2029
|
+
pagination: { limit: 10, cursor: results.cursor },
|
|
2030
|
+
});
|
|
2031
|
+
results = yield dwn.processMessage(alice.did, bobQueryMessagePage2.message);
|
|
2032
|
+
expect(results.status.code).to.equal(200);
|
|
2033
|
+
expect((_h = results.entries) === null || _h === void 0 ? void 0 : _h.length).to.equal(10, 'bob page 2');
|
|
2034
|
+
expect(results.cursor, 'bob page 2 cursor').to.not.exist;
|
|
2035
|
+
bobRetrieved.push(...results.entries);
|
|
2036
|
+
expect(bobSorted.every((m, i) => compareRecordId(bobRetrieved.at(i), m)));
|
|
2037
|
+
}));
|
|
2038
|
+
// https://github.com/TBD54566975/dwn-sdk-js/issues/170
|
|
2039
|
+
it('#170 - should treat records with `published` explicitly set to `false` as unpublished', () => __awaiter(this, void 0, void 0, function* () {
|
|
2040
|
+
var _a, _b;
|
|
2041
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
2042
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
2043
|
+
const schema = 'schema1';
|
|
2044
|
+
const unpublishedRecordsWrite = yield TestDataGenerator.generateRecordsWrite({ author: alice, schema, data: Encoder.stringToBytes('1'), published: false } // explicitly setting `published` to `false`
|
|
2045
|
+
);
|
|
2046
|
+
const result1 = yield dwn.processMessage(alice.did, unpublishedRecordsWrite.message, { dataStream: unpublishedRecordsWrite.dataStream });
|
|
2047
|
+
expect(result1.status.code).to.equal(202);
|
|
2048
|
+
// alice should be able to see the unpublished record
|
|
2049
|
+
const queryByAlice = yield TestDataGenerator.generateRecordsQuery({
|
|
2050
|
+
author: alice,
|
|
2051
|
+
filter: { schema }
|
|
2052
|
+
});
|
|
2053
|
+
const replyToAliceQuery = yield dwn.processMessage(alice.did, queryByAlice.message);
|
|
2054
|
+
expect(replyToAliceQuery.status.code).to.equal(200);
|
|
2055
|
+
expect((_a = replyToAliceQuery.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(1);
|
|
2056
|
+
// actual test: bob should not be able to see unpublished record
|
|
2057
|
+
const queryByBob = yield TestDataGenerator.generateRecordsQuery({
|
|
2058
|
+
author: bob,
|
|
2059
|
+
filter: { schema }
|
|
2060
|
+
});
|
|
2061
|
+
const replyToBobQuery = yield dwn.processMessage(alice.did, queryByBob.message);
|
|
2062
|
+
expect(replyToBobQuery.status.code).to.equal(200);
|
|
2063
|
+
expect((_b = replyToBobQuery.entries) === null || _b === void 0 ? void 0 : _b.length).to.equal(0);
|
|
2064
|
+
}));
|
|
2065
|
+
it('should allow DWN owner to use `recipient` as a filter in queries', () => __awaiter(this, void 0, void 0, function* () {
|
|
2066
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
2067
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
2068
|
+
const bobQueryMessageData = yield TestDataGenerator.generateRecordsQuery({
|
|
2069
|
+
author: alice,
|
|
2070
|
+
filter: { recipient: bob.did } // alice as the DWN owner querying bob's records
|
|
2071
|
+
});
|
|
2072
|
+
const replyToBobQuery = yield dwn.processMessage(alice.did, bobQueryMessageData.message);
|
|
2073
|
+
expect(replyToBobQuery.status.code).to.equal(200);
|
|
2074
|
+
}));
|
|
2075
|
+
it('should not fetch entries across tenants', () => __awaiter(this, void 0, void 0, function* () {
|
|
2076
|
+
var _a;
|
|
2077
|
+
// insert three messages into DB, two with matching schema
|
|
2078
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
2079
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
2080
|
+
const schema = 'myAwesomeSchema';
|
|
2081
|
+
const recordsWriteMessage1Data = yield TestDataGenerator.generateRecordsWrite({ author: alice, schema });
|
|
2082
|
+
const recordsWriteMessage2Data = yield TestDataGenerator.generateRecordsWrite({ author: bob, schema });
|
|
2083
|
+
const aliceQueryMessageData = yield TestDataGenerator.generateRecordsQuery({
|
|
2084
|
+
author: alice,
|
|
2085
|
+
filter: { schema }
|
|
2086
|
+
});
|
|
2087
|
+
// insert data into 2 different tenants
|
|
2088
|
+
yield dwn.processMessage(alice.did, recordsWriteMessage1Data.message, { dataStream: recordsWriteMessage1Data.dataStream });
|
|
2089
|
+
yield dwn.processMessage(bob.did, recordsWriteMessage2Data.message, { dataStream: recordsWriteMessage2Data.dataStream });
|
|
2090
|
+
const reply = yield dwn.processMessage(alice.did, aliceQueryMessageData.message);
|
|
2091
|
+
expect(reply.status.code).to.equal(200);
|
|
2092
|
+
expect((_a = reply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(1);
|
|
2093
|
+
}));
|
|
2094
|
+
it('should return 400 if protocol is not normalized', () => __awaiter(this, void 0, void 0, function* () {
|
|
2095
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
2096
|
+
// query for non-normalized protocol
|
|
2097
|
+
const recordsQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
2098
|
+
author: alice,
|
|
2099
|
+
filter: { protocol: 'example.com/' },
|
|
2100
|
+
});
|
|
2101
|
+
// overwrite protocol because #create auto-normalizes protocol
|
|
2102
|
+
recordsQuery.message.descriptor.filter.protocol = 'example.com/';
|
|
2103
|
+
// Re-create auth because we altered the descriptor after signing
|
|
2104
|
+
recordsQuery.message.authorization = yield Message.createAuthorization({
|
|
2105
|
+
descriptor: recordsQuery.message.descriptor,
|
|
2106
|
+
signer: Jws.createSigner(alice)
|
|
2107
|
+
});
|
|
2108
|
+
// Send records write message
|
|
2109
|
+
const reply = yield dwn.processMessage(alice.did, recordsQuery.message);
|
|
2110
|
+
expect(reply.status.code).to.equal(400);
|
|
2111
|
+
expect(reply.status.detail).to.contain(DwnErrorCode.UrlProtocolNotNormalized);
|
|
2112
|
+
}));
|
|
2113
|
+
it('should return 400 if schema is not normalized', () => __awaiter(this, void 0, void 0, function* () {
|
|
2114
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
2115
|
+
// query for non-normalized schema
|
|
2116
|
+
const recordsQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
2117
|
+
author: alice,
|
|
2118
|
+
filter: { schema: 'example.com/' },
|
|
2119
|
+
});
|
|
2120
|
+
// overwrite schema because #create auto-normalizes schema
|
|
2121
|
+
recordsQuery.message.descriptor.filter.schema = 'example.com/';
|
|
2122
|
+
// Re-create auth because we altered the descriptor after signing
|
|
2123
|
+
recordsQuery.message.authorization = yield Message.createAuthorization({
|
|
2124
|
+
descriptor: recordsQuery.message.descriptor,
|
|
2125
|
+
signer: Jws.createSigner(alice)
|
|
2126
|
+
});
|
|
2127
|
+
// Send records write message
|
|
2128
|
+
const reply = yield dwn.processMessage(alice.did, recordsQuery.message);
|
|
2129
|
+
expect(reply.status.code).to.equal(400);
|
|
2130
|
+
expect(reply.status.detail).to.contain(DwnErrorCode.UrlSchemaNotNormalized);
|
|
2131
|
+
}));
|
|
2132
|
+
it('should return 400 if published is set to false and a datePublished range is provided', () => __awaiter(this, void 0, void 0, function* () {
|
|
2133
|
+
const fromDatePublished = Time.getCurrentTimestamp();
|
|
2134
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
2135
|
+
// set to true so create does not fail
|
|
2136
|
+
const recordQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
2137
|
+
author: alice,
|
|
2138
|
+
filter: { datePublished: { from: fromDatePublished }, published: true }
|
|
2139
|
+
});
|
|
2140
|
+
// set to false
|
|
2141
|
+
recordQuery.message.descriptor.filter.published = false;
|
|
2142
|
+
const queryResponse = yield dwn.processMessage(alice.did, recordQuery.message);
|
|
2143
|
+
expect(queryResponse.status.code).to.equal(400);
|
|
2144
|
+
expect(queryResponse.status.detail).to.contain('descriptor/filter/published: must be equal to one of the allowed values');
|
|
2145
|
+
}));
|
|
2146
|
+
it('should return 401 for anonymous queries that filter explicitly for unpublished records', () => __awaiter(this, void 0, void 0, function* () {
|
|
2147
|
+
var _a;
|
|
2148
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
2149
|
+
// create an unpublished record
|
|
2150
|
+
const draftWrite = yield TestDataGenerator.generateRecordsWrite({ author: alice, schema: 'post' });
|
|
2151
|
+
const draftWriteReply = yield dwn.processMessage(alice.did, draftWrite.message, { dataStream: draftWrite.dataStream });
|
|
2152
|
+
expect(draftWriteReply.status.code).to.equal(202);
|
|
2153
|
+
// validate that alice can query
|
|
2154
|
+
const unpublishedPostQuery = yield TestDataGenerator.generateRecordsQuery({ author: alice, filter: { schema: 'post', published: false } });
|
|
2155
|
+
const unpublishedPostReply = yield dwn.processMessage(alice.did, unpublishedPostQuery.message);
|
|
2156
|
+
expect(unpublishedPostReply.status.code).to.equal(200);
|
|
2157
|
+
expect((_a = unpublishedPostReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(1);
|
|
2158
|
+
expect(unpublishedPostReply.entries[0].recordId).to.equal(draftWrite.message.recordId);
|
|
2159
|
+
// anonymous query for unpublished records
|
|
2160
|
+
const unpublishedAnonymous = yield RecordsQuery.create({ filter: { schema: 'post', published: false } });
|
|
2161
|
+
const anonymousPostReply = yield dwn.processMessage(alice.did, unpublishedAnonymous.message);
|
|
2162
|
+
expect(anonymousPostReply.status.code).to.equal(401);
|
|
2163
|
+
expect(anonymousPostReply.status.detail).contains('Missing JWS');
|
|
2164
|
+
}));
|
|
2165
|
+
describe('protocol based queries', () => {
|
|
2166
|
+
it('should return message scoped to the given `contextId`', () => __awaiter(this, void 0, void 0, function* () {
|
|
2167
|
+
// scenario:
|
|
2168
|
+
// 0. Alice installs a nested protocol foo -> bar -> baz
|
|
2169
|
+
// 1. Alice writes 2 foos, 2 bars under foo1, and 2 bazes under bar1
|
|
2170
|
+
// 2. Alice should be able to query for all messages under foo1
|
|
2171
|
+
// 3. Alice should be able to query for all messages under bar1
|
|
2172
|
+
// 4. Alice should be able to query for all messages under baz1
|
|
2173
|
+
var _a, _b, _c;
|
|
2174
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
2175
|
+
const protocolDefinition = nestedProtocol;
|
|
2176
|
+
// 0. Alice installs a nested protocol foo -> bar -> baz
|
|
2177
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
2178
|
+
author: alice,
|
|
2179
|
+
protocolDefinition
|
|
2180
|
+
});
|
|
2181
|
+
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
2182
|
+
expect(protocolsConfigureReply.status.code).to.equal(202);
|
|
2183
|
+
// 1. Alice writes 2 foos, 2 bars under foo1, and 2 bazes under bar1
|
|
2184
|
+
// write 2 foos
|
|
2185
|
+
const fooOptions = {
|
|
2186
|
+
author: alice,
|
|
2187
|
+
protocol: nestedProtocol.protocol,
|
|
2188
|
+
protocolPath: 'foo',
|
|
2189
|
+
schema: nestedProtocol.types.foo.schema,
|
|
2190
|
+
dataFormat: nestedProtocol.types.foo.dataFormats[0],
|
|
2191
|
+
};
|
|
2192
|
+
const foo1 = yield TestDataGenerator.generateRecordsWrite(fooOptions);
|
|
2193
|
+
const foo1WriteResponse = yield dwn.processMessage(alice.did, foo1.message, { dataStream: foo1.dataStream });
|
|
2194
|
+
expect(foo1WriteResponse.status.code).equals(202);
|
|
2195
|
+
const foo2 = yield TestDataGenerator.generateRecordsWrite(fooOptions);
|
|
2196
|
+
const foo2WriteResponse = yield dwn.processMessage(alice.did, foo2.message, { dataStream: foo2.dataStream });
|
|
2197
|
+
expect(foo2WriteResponse.status.code).equals(202);
|
|
2198
|
+
// write 2 bars under foo1
|
|
2199
|
+
const barOptions = {
|
|
2200
|
+
author: alice,
|
|
2201
|
+
protocol: nestedProtocol.protocol,
|
|
2202
|
+
protocolPath: 'foo/bar',
|
|
2203
|
+
schema: nestedProtocol.types.bar.schema,
|
|
2204
|
+
dataFormat: nestedProtocol.types.bar.dataFormats[0],
|
|
2205
|
+
parentContextId: foo1.message.contextId
|
|
2206
|
+
};
|
|
2207
|
+
const bar1 = yield TestDataGenerator.generateRecordsWrite(barOptions);
|
|
2208
|
+
const bar1WriteResponse = yield dwn.processMessage(alice.did, bar1.message, { dataStream: bar1.dataStream });
|
|
2209
|
+
expect(bar1WriteResponse.status.code).equals(202);
|
|
2210
|
+
const bar2 = yield TestDataGenerator.generateRecordsWrite(barOptions);
|
|
2211
|
+
const bar2WriteResponse = yield dwn.processMessage(alice.did, bar2.message, { dataStream: bar2.dataStream });
|
|
2212
|
+
expect(bar2WriteResponse.status.code).equals(202);
|
|
2213
|
+
// write 2 bazes under bar1
|
|
2214
|
+
const bazOptions = {
|
|
2215
|
+
author: alice,
|
|
2216
|
+
protocol: nestedProtocol.protocol,
|
|
2217
|
+
protocolPath: 'foo/bar/baz',
|
|
2218
|
+
schema: nestedProtocol.types.baz.schema,
|
|
2219
|
+
dataFormat: nestedProtocol.types.baz.dataFormats[0],
|
|
2220
|
+
parentContextId: bar1.message.contextId
|
|
2221
|
+
};
|
|
2222
|
+
const baz1 = yield TestDataGenerator.generateRecordsWrite(bazOptions);
|
|
2223
|
+
const baz1WriteResponse = yield dwn.processMessage(alice.did, baz1.message, { dataStream: baz1.dataStream });
|
|
2224
|
+
expect(baz1WriteResponse.status.code).equals(202);
|
|
2225
|
+
const baz2 = yield TestDataGenerator.generateRecordsWrite(bazOptions);
|
|
2226
|
+
const baz2WriteResponse = yield dwn.processMessage(alice.did, baz2.message, { dataStream: baz2.dataStream });
|
|
2227
|
+
expect(baz2WriteResponse.status.code).equals(202);
|
|
2228
|
+
// 2. Alice should be able to query for all messages under foo1
|
|
2229
|
+
const foo1ContextIdQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
2230
|
+
author: alice,
|
|
2231
|
+
filter: { contextId: foo1.message.contextId }
|
|
2232
|
+
});
|
|
2233
|
+
const foo1ContextIdQueryReply = yield dwn.processMessage(alice.did, foo1ContextIdQuery.message);
|
|
2234
|
+
expect(foo1ContextIdQueryReply.status.code).to.equal(200);
|
|
2235
|
+
expect((_a = foo1ContextIdQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(5);
|
|
2236
|
+
expect(foo1ContextIdQueryReply.entries.map((entry) => entry.recordId)).to.include.members([
|
|
2237
|
+
foo1.message.recordId,
|
|
2238
|
+
bar1.message.recordId,
|
|
2239
|
+
bar2.message.recordId,
|
|
2240
|
+
baz1.message.recordId,
|
|
2241
|
+
baz2.message.recordId
|
|
2242
|
+
]);
|
|
2243
|
+
// 3. Alice should be able to query for all messages under bar1
|
|
2244
|
+
const bar1ContextIdQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
2245
|
+
author: alice,
|
|
2246
|
+
filter: { contextId: bar1.message.contextId }
|
|
2247
|
+
});
|
|
2248
|
+
const bar1ContextIdQueryReply = yield dwn.processMessage(alice.did, bar1ContextIdQuery.message);
|
|
2249
|
+
expect(bar1ContextIdQueryReply.status.code).to.equal(200);
|
|
2250
|
+
expect((_b = bar1ContextIdQueryReply.entries) === null || _b === void 0 ? void 0 : _b.length).to.equal(3);
|
|
2251
|
+
expect(bar1ContextIdQueryReply.entries.map((entry) => entry.recordId)).to.include.members([
|
|
2252
|
+
bar1.message.recordId,
|
|
2253
|
+
baz1.message.recordId,
|
|
2254
|
+
baz2.message.recordId
|
|
2255
|
+
]);
|
|
2256
|
+
// 4. Alice should be able to query for all messages under baz1
|
|
2257
|
+
const baz1ContextIdQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
2258
|
+
author: alice,
|
|
2259
|
+
filter: { contextId: baz1.message.contextId }
|
|
2260
|
+
});
|
|
2261
|
+
const baz1ContextIdQueryReply = yield dwn.processMessage(alice.did, baz1ContextIdQuery.message);
|
|
2262
|
+
expect(baz1ContextIdQueryReply.status.code).to.equal(200);
|
|
2263
|
+
expect((_c = baz1ContextIdQueryReply.entries) === null || _c === void 0 ? void 0 : _c.length).to.equal(1);
|
|
2264
|
+
expect(baz1ContextIdQueryReply.entries.map((entry) => entry.recordId)).to.include.members([baz1.message.recordId]);
|
|
2265
|
+
}));
|
|
2266
|
+
it('does not try protocol authorization if protocolRole is not invoked', () => __awaiter(this, void 0, void 0, function* () {
|
|
2267
|
+
// scenario: Alice creates a thread and writes some chat messages. Alice addresses
|
|
2268
|
+
// only one chat message to Bob. Bob queries by protocol URI without invoking a protocolRole,
|
|
2269
|
+
// and he is able to receive the message addressed to him.
|
|
2270
|
+
var _a, _b;
|
|
2271
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
2272
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
2273
|
+
const protocolDefinition = threadRoleProtocolDefinition;
|
|
2274
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
2275
|
+
author: alice,
|
|
2276
|
+
protocolDefinition
|
|
2277
|
+
});
|
|
2278
|
+
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
2279
|
+
expect(protocolsConfigureReply.status.code).to.equal(202);
|
|
2280
|
+
// Alice writes a 'thread' record
|
|
2281
|
+
const threadRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
2282
|
+
author: alice,
|
|
2283
|
+
protocol: protocolDefinition.protocol,
|
|
2284
|
+
protocolPath: 'thread',
|
|
2285
|
+
});
|
|
2286
|
+
const threadRoleReply = yield dwn.processMessage(alice.did, threadRecord.message, { dataStream: threadRecord.dataStream });
|
|
2287
|
+
expect(threadRoleReply.status.code).to.equal(202);
|
|
2288
|
+
// Alice writes one 'chat' record addressed to Bob
|
|
2289
|
+
const chatRecordForBob = yield TestDataGenerator.generateRecordsWrite({
|
|
2290
|
+
author: alice,
|
|
2291
|
+
recipient: bob.did,
|
|
2292
|
+
protocol: protocolDefinition.protocol,
|
|
2293
|
+
protocolPath: 'thread/chat',
|
|
2294
|
+
published: false,
|
|
2295
|
+
parentContextId: threadRecord.message.contextId,
|
|
2296
|
+
data: new TextEncoder().encode('Bob can read this cuz he is my friend'),
|
|
2297
|
+
});
|
|
2298
|
+
const chatRecordForBobReply = yield dwn.processMessage(alice.did, chatRecordForBob.message, { dataStream: chatRecordForBob.dataStream });
|
|
2299
|
+
expect(chatRecordForBobReply.status.code).to.equal(202);
|
|
2300
|
+
// Alice writes two 'chat' records NOT addressed to Bob
|
|
2301
|
+
for (let i = 0; i < 2; i++) {
|
|
2302
|
+
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
2303
|
+
author: alice,
|
|
2304
|
+
recipient: alice.did,
|
|
2305
|
+
protocol: protocolDefinition.protocol,
|
|
2306
|
+
protocolPath: 'thread/chat',
|
|
2307
|
+
published: false,
|
|
2308
|
+
parentContextId: threadRecord.message.contextId,
|
|
2309
|
+
data: new TextEncoder().encode('Bob cannot read this'),
|
|
2310
|
+
});
|
|
2311
|
+
const chatReply = yield dwn.processMessage(alice.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
2312
|
+
expect(chatReply.status.code).to.equal(202);
|
|
2313
|
+
}
|
|
2314
|
+
// Bob queries without invoking any protocolRole
|
|
2315
|
+
const chatQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
2316
|
+
author: bob,
|
|
2317
|
+
filter: {
|
|
2318
|
+
protocol: protocolDefinition.protocol,
|
|
2319
|
+
},
|
|
2320
|
+
});
|
|
2321
|
+
const chatQueryReply = yield dwn.processMessage(alice.did, chatQuery.message);
|
|
2322
|
+
expect(chatQueryReply.status.code).to.equal(200);
|
|
2323
|
+
expect((_a = chatQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(1);
|
|
2324
|
+
expect(chatQueryReply.entries[0].recordId).to.eq(chatRecordForBob.message.recordId);
|
|
2325
|
+
// bob queries without invoking any protocolRole and filters for unpublished records
|
|
2326
|
+
const unpublishedChatQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
2327
|
+
author: bob,
|
|
2328
|
+
filter: {
|
|
2329
|
+
published: false,
|
|
2330
|
+
protocol: protocolDefinition.protocol,
|
|
2331
|
+
},
|
|
2332
|
+
});
|
|
2333
|
+
const unpublishedChatReply = yield dwn.processMessage(alice.did, unpublishedChatQuery.message);
|
|
2334
|
+
expect(unpublishedChatReply.status.code).to.equal(200);
|
|
2335
|
+
expect((_b = unpublishedChatReply.entries) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
|
|
2336
|
+
expect(unpublishedChatReply.entries[0].recordId).to.equal(chatRecordForBob.message.recordId);
|
|
2337
|
+
}));
|
|
2338
|
+
it('allows root-level role authorized queries', () => __awaiter(this, void 0, void 0, function* () {
|
|
2339
|
+
// scenario: Alice creates a thread and writes some chat messages writes a chat message. Bob invokes his
|
|
2340
|
+
// thread member role in order to query the chat messages.
|
|
2341
|
+
var _a, _b;
|
|
2342
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
2343
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
2344
|
+
const protocolDefinition = friendRoleProtocolDefinition;
|
|
2345
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
2346
|
+
author: alice,
|
|
2347
|
+
protocolDefinition
|
|
2348
|
+
});
|
|
2349
|
+
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
2350
|
+
expect(protocolsConfigureReply.status.code).to.equal(202);
|
|
2351
|
+
// Alice writes a 'friend' root-level role record with Bob as recipient
|
|
2352
|
+
const friendRoleRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
2353
|
+
author: alice,
|
|
2354
|
+
recipient: bob.did,
|
|
2355
|
+
protocol: protocolDefinition.protocol,
|
|
2356
|
+
protocolPath: 'friend',
|
|
2357
|
+
data: new TextEncoder().encode('Bob is my friend'),
|
|
2358
|
+
});
|
|
2359
|
+
const friendRoleReply = yield dwn.processMessage(alice.did, friendRoleRecord.message, { dataStream: friendRoleRecord.dataStream });
|
|
2360
|
+
expect(friendRoleReply.status.code).to.equal(202);
|
|
2361
|
+
// Alice writes three 'chat' records
|
|
2362
|
+
const chatRecordIds = [];
|
|
2363
|
+
for (let i = 0; i < 3; i++) {
|
|
2364
|
+
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
2365
|
+
author: alice,
|
|
2366
|
+
recipient: alice.did,
|
|
2367
|
+
protocol: protocolDefinition.protocol,
|
|
2368
|
+
protocolPath: 'chat',
|
|
2369
|
+
published: false,
|
|
2370
|
+
data: new TextEncoder().encode('Bob can read this cuz he is my friend'),
|
|
2371
|
+
});
|
|
2372
|
+
const chatReply = yield dwn.processMessage(alice.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
2373
|
+
expect(chatReply.status.code).to.equal(202);
|
|
2374
|
+
chatRecordIds.push(chatRecord.message.recordId);
|
|
2375
|
+
}
|
|
2376
|
+
// Bob invokes his friendRole to query that records
|
|
2377
|
+
const chatQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
2378
|
+
author: bob,
|
|
2379
|
+
filter: {
|
|
2380
|
+
protocol: protocolDefinition.protocol,
|
|
2381
|
+
protocolPath: 'chat',
|
|
2382
|
+
},
|
|
2383
|
+
protocolRole: 'friend',
|
|
2384
|
+
});
|
|
2385
|
+
const chatQueryReply = yield dwn.processMessage(alice.did, chatQuery.message);
|
|
2386
|
+
expect(chatQueryReply.status.code).to.equal(200);
|
|
2387
|
+
expect((_a = chatQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(3);
|
|
2388
|
+
expect(chatQueryReply.entries.map((record) => record.recordId)).to.have.all.members(chatRecordIds);
|
|
2389
|
+
// Bob invokes his friendRole along with an explicit filter for unpublished records
|
|
2390
|
+
const unpublishedChatQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
2391
|
+
author: bob,
|
|
2392
|
+
filter: {
|
|
2393
|
+
published: false,
|
|
2394
|
+
protocol: protocolDefinition.protocol,
|
|
2395
|
+
protocolPath: 'chat',
|
|
2396
|
+
},
|
|
2397
|
+
protocolRole: 'friend',
|
|
2398
|
+
});
|
|
2399
|
+
const unpublishedChatReply = yield dwn.processMessage(alice.did, unpublishedChatQuery.message);
|
|
2400
|
+
expect(unpublishedChatReply.status.code).to.equal(200);
|
|
2401
|
+
expect((_b = unpublishedChatReply.entries) === null || _b === void 0 ? void 0 : _b.length).to.equal(3);
|
|
2402
|
+
expect(unpublishedChatReply.entries.map((record) => record.recordId)).to.have.all.members(chatRecordIds);
|
|
2403
|
+
}));
|
|
2404
|
+
it('can authorize queries using a context role.', () => __awaiter(this, void 0, void 0, function* () {
|
|
2405
|
+
// scenario: Alice writes some chat messages. Bob invokes his friend role in order to query the chat messages.
|
|
2406
|
+
var _a;
|
|
2407
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
2408
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
2409
|
+
const protocolDefinition = threadRoleProtocolDefinition;
|
|
2410
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
2411
|
+
author: alice,
|
|
2412
|
+
protocolDefinition
|
|
2413
|
+
});
|
|
2414
|
+
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
2415
|
+
expect(protocolsConfigureReply.status.code).to.equal(202);
|
|
2416
|
+
// Alice writes a 'thread' record
|
|
2417
|
+
const threadRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
2418
|
+
author: alice,
|
|
2419
|
+
protocol: protocolDefinition.protocol,
|
|
2420
|
+
protocolPath: 'thread',
|
|
2421
|
+
});
|
|
2422
|
+
const threadRoleReply = yield dwn.processMessage(alice.did, threadRecord.message, { dataStream: threadRecord.dataStream });
|
|
2423
|
+
expect(threadRoleReply.status.code).to.equal(202);
|
|
2424
|
+
// Alice writes a 'participant' role record with Bob as recipient
|
|
2425
|
+
const participantRoleRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
2426
|
+
author: alice,
|
|
2427
|
+
recipient: bob.did,
|
|
2428
|
+
protocol: protocolDefinition.protocol,
|
|
2429
|
+
protocolPath: 'thread/participant',
|
|
2430
|
+
parentContextId: threadRecord.message.contextId,
|
|
2431
|
+
data: new TextEncoder().encode('Bob is my friend'),
|
|
2432
|
+
});
|
|
2433
|
+
const participantRoleReply = yield dwn.processMessage(alice.did, participantRoleRecord.message, { dataStream: participantRoleRecord.dataStream });
|
|
2434
|
+
expect(participantRoleReply.status.code).to.equal(202);
|
|
2435
|
+
// Alice writes three 'chat' records
|
|
2436
|
+
const chatRecordIds = [];
|
|
2437
|
+
for (let i = 0; i < 3; i++) {
|
|
2438
|
+
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
2439
|
+
author: alice,
|
|
2440
|
+
recipient: alice.did,
|
|
2441
|
+
protocol: protocolDefinition.protocol,
|
|
2442
|
+
protocolPath: 'thread/chat',
|
|
2443
|
+
published: false,
|
|
2444
|
+
parentContextId: threadRecord.message.contextId,
|
|
2445
|
+
data: new TextEncoder().encode('Bob can read this cuz he is my friend'),
|
|
2446
|
+
});
|
|
2447
|
+
const chatReply = yield dwn.processMessage(alice.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
2448
|
+
expect(chatReply.status.code).to.equal(202);
|
|
2449
|
+
chatRecordIds.push(chatRecord.message.recordId);
|
|
2450
|
+
}
|
|
2451
|
+
// Bob invokes his friendRole to query that records
|
|
2452
|
+
const chatQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
2453
|
+
author: bob,
|
|
2454
|
+
filter: {
|
|
2455
|
+
protocol: protocolDefinition.protocol,
|
|
2456
|
+
protocolPath: 'thread/chat',
|
|
2457
|
+
contextId: threadRecord.message.contextId,
|
|
2458
|
+
},
|
|
2459
|
+
protocolRole: 'thread/participant',
|
|
2460
|
+
});
|
|
2461
|
+
const chatQueryReply = yield dwn.processMessage(alice.did, chatQuery.message);
|
|
2462
|
+
expect(chatQueryReply.status.code).to.equal(200);
|
|
2463
|
+
expect((_a = chatQueryReply.entries) === null || _a === void 0 ? void 0 : _a.length).to.equal(3);
|
|
2464
|
+
expect(chatQueryReply.entries.map((record) => record.recordId)).to.have.all.members(chatRecordIds);
|
|
2465
|
+
}));
|
|
2466
|
+
it('does not execute protocol queries where protocolPath is missing from the filter', () => __awaiter(this, void 0, void 0, function* () {
|
|
2467
|
+
// scenario: Alice gives Bob a root-level role and writes some chat messages. Bob invokes his root-level role to query those messages,
|
|
2468
|
+
// but his query filter does not include protocolPath.
|
|
2469
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
2470
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
2471
|
+
const protocolDefinition = friendRoleProtocolDefinition;
|
|
2472
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
2473
|
+
author: alice,
|
|
2474
|
+
protocolDefinition
|
|
2475
|
+
});
|
|
2476
|
+
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
2477
|
+
expect(protocolsConfigureReply.status.code).to.equal(202);
|
|
2478
|
+
// Alice writes a 'friend' root-level role record with Bob as recipient
|
|
2479
|
+
const friendRoleRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
2480
|
+
author: alice,
|
|
2481
|
+
recipient: bob.did,
|
|
2482
|
+
protocol: protocolDefinition.protocol,
|
|
2483
|
+
protocolPath: 'friend',
|
|
2484
|
+
data: new TextEncoder().encode('Bob is my friend'),
|
|
2485
|
+
});
|
|
2486
|
+
const friendRoleReply = yield dwn.processMessage(alice.did, friendRoleRecord.message, { dataStream: friendRoleRecord.dataStream });
|
|
2487
|
+
expect(friendRoleReply.status.code).to.equal(202);
|
|
2488
|
+
// Alice writes three 'chat' records
|
|
2489
|
+
const chatRecordIds = [];
|
|
2490
|
+
for (let i = 0; i < 3; i++) {
|
|
2491
|
+
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
2492
|
+
author: alice,
|
|
2493
|
+
recipient: alice.did,
|
|
2494
|
+
protocol: protocolDefinition.protocol,
|
|
2495
|
+
protocolPath: 'chat',
|
|
2496
|
+
published: false,
|
|
2497
|
+
data: new TextEncoder().encode('Bob can read this cuz he is my friend'),
|
|
2498
|
+
});
|
|
2499
|
+
const chatReply = yield dwn.processMessage(alice.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
2500
|
+
expect(chatReply.status.code).to.equal(202);
|
|
2501
|
+
chatRecordIds.push(chatRecord.message.recordId);
|
|
2502
|
+
}
|
|
2503
|
+
// Bob invokes his friendRole to query but does not have `protocolPath` in the filter
|
|
2504
|
+
const chatQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
2505
|
+
author: bob,
|
|
2506
|
+
filter: {
|
|
2507
|
+
protocol: protocolDefinition.protocol,
|
|
2508
|
+
// protocolPath deliberately omitted
|
|
2509
|
+
},
|
|
2510
|
+
protocolRole: 'friend',
|
|
2511
|
+
});
|
|
2512
|
+
const chatQueryReply = yield dwn.processMessage(alice.did, chatQuery.message);
|
|
2513
|
+
expect(chatQueryReply.status.code).to.equal(400);
|
|
2514
|
+
expect(chatQueryReply.status.detail).to.contain(DwnErrorCode.RecordsQueryFilterMissingRequiredProperties);
|
|
2515
|
+
}));
|
|
2516
|
+
it('does not execute context role authorized queries where contextId is missing from the filter', () => __awaiter(this, void 0, void 0, function* () {
|
|
2517
|
+
// scenario: Alice writes some chat messages and gives Bob a role allowing him to access them. But Bob's filter
|
|
2518
|
+
// does not contain a contextId so the query fails.
|
|
2519
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
2520
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
2521
|
+
const protocolDefinition = threadRoleProtocolDefinition;
|
|
2522
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
2523
|
+
author: alice,
|
|
2524
|
+
protocolDefinition
|
|
2525
|
+
});
|
|
2526
|
+
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
2527
|
+
expect(protocolsConfigureReply.status.code).to.equal(202);
|
|
2528
|
+
// Alice writes a 'thread' record
|
|
2529
|
+
const threadRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
2530
|
+
author: alice,
|
|
2531
|
+
protocol: protocolDefinition.protocol,
|
|
2532
|
+
protocolPath: 'thread',
|
|
2533
|
+
});
|
|
2534
|
+
const threadRoleReply = yield dwn.processMessage(alice.did, threadRecord.message, { dataStream: threadRecord.dataStream });
|
|
2535
|
+
expect(threadRoleReply.status.code).to.equal(202);
|
|
2536
|
+
// Alice writes a 'friend' root-level role record with Bob as recipient
|
|
2537
|
+
const participantRoleRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
2538
|
+
author: alice,
|
|
2539
|
+
recipient: bob.did,
|
|
2540
|
+
protocol: protocolDefinition.protocol,
|
|
2541
|
+
protocolPath: 'thread/participant',
|
|
2542
|
+
parentContextId: threadRecord.message.contextId,
|
|
2543
|
+
data: new TextEncoder().encode('Bob is my friend'),
|
|
2544
|
+
});
|
|
2545
|
+
const participantRoleReply = yield dwn.processMessage(alice.did, participantRoleRecord.message, { dataStream: participantRoleRecord.dataStream });
|
|
2546
|
+
expect(participantRoleReply.status.code).to.equal(202);
|
|
2547
|
+
// Alice writes three 'chat' records
|
|
2548
|
+
const chatRecordIds = [];
|
|
2549
|
+
for (let i = 0; i < 3; i++) {
|
|
2550
|
+
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
2551
|
+
author: alice,
|
|
2552
|
+
recipient: alice.did,
|
|
2553
|
+
protocol: protocolDefinition.protocol,
|
|
2554
|
+
protocolPath: 'thread/chat',
|
|
2555
|
+
published: false,
|
|
2556
|
+
parentContextId: threadRecord.message.contextId,
|
|
2557
|
+
data: new TextEncoder().encode('Bob can read this cuz he is my friend'),
|
|
2558
|
+
});
|
|
2559
|
+
const chatReply = yield dwn.processMessage(alice.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
2560
|
+
expect(chatReply.status.code).to.equal(202);
|
|
2561
|
+
chatRecordIds.push(chatRecord.message.recordId);
|
|
2562
|
+
}
|
|
2563
|
+
// Bob invokes his thread participant role to query
|
|
2564
|
+
const chatQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
2565
|
+
author: bob,
|
|
2566
|
+
filter: {
|
|
2567
|
+
protocol: protocolDefinition.protocol,
|
|
2568
|
+
protocolPath: 'thread/chat',
|
|
2569
|
+
// contextId deliberately omitted
|
|
2570
|
+
},
|
|
2571
|
+
protocolRole: 'thread/participant',
|
|
2572
|
+
});
|
|
2573
|
+
const chatQueryReply = yield dwn.processMessage(alice.did, chatQuery.message);
|
|
2574
|
+
expect(chatQueryReply.status.code).to.eq(401);
|
|
2575
|
+
expect(chatQueryReply.status.detail).to.contain(DwnErrorCode.ProtocolAuthorizationMissingContextId);
|
|
2576
|
+
}));
|
|
2577
|
+
it('should reject root-level role authorized queries if a matching root-level role record is not found for the message author', () => __awaiter(this, void 0, void 0, function* () {
|
|
2578
|
+
// scenario: Alice creates a thread and writes some chat messages writes a chat message.
|
|
2579
|
+
// Bob invokes a root-level role but fails because he does not actually have a role.
|
|
2580
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
2581
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
2582
|
+
const protocolDefinition = friendRoleProtocolDefinition;
|
|
2583
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
2584
|
+
author: alice,
|
|
2585
|
+
protocolDefinition
|
|
2586
|
+
});
|
|
2587
|
+
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
2588
|
+
expect(protocolsConfigureReply.status.code).to.equal(202);
|
|
2589
|
+
// Alice writes three 'chat' records
|
|
2590
|
+
const chatRecordIds = [];
|
|
2591
|
+
for (let i = 0; i < 3; i++) {
|
|
2592
|
+
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
2593
|
+
author: alice,
|
|
2594
|
+
recipient: alice.did,
|
|
2595
|
+
protocol: protocolDefinition.protocol,
|
|
2596
|
+
protocolPath: 'chat',
|
|
2597
|
+
published: false,
|
|
2598
|
+
data: new TextEncoder().encode('Bob can read this cuz he is my friend'),
|
|
2599
|
+
});
|
|
2600
|
+
const chatReply = yield dwn.processMessage(alice.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
2601
|
+
expect(chatReply.status.code).to.equal(202);
|
|
2602
|
+
chatRecordIds.push(chatRecord.message.recordId);
|
|
2603
|
+
}
|
|
2604
|
+
// Bob invokes his friendRole to query that records
|
|
2605
|
+
const chatQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
2606
|
+
author: bob,
|
|
2607
|
+
filter: {
|
|
2608
|
+
protocol: protocolDefinition.protocol,
|
|
2609
|
+
protocolPath: 'chat',
|
|
2610
|
+
},
|
|
2611
|
+
protocolRole: 'friend',
|
|
2612
|
+
});
|
|
2613
|
+
const chatQueryReply = yield dwn.processMessage(alice.did, chatQuery.message);
|
|
2614
|
+
expect(chatQueryReply.status.code).to.eq(401);
|
|
2615
|
+
expect(chatQueryReply.status.detail).to.contain(DwnErrorCode.ProtocolAuthorizationMatchingRoleRecordNotFound);
|
|
2616
|
+
}));
|
|
2617
|
+
it('should reject context role authorized queries if a matching context role record is not found for the message author', () => __awaiter(this, void 0, void 0, function* () {
|
|
2618
|
+
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
2619
|
+
const bob = yield TestDataGenerator.generateDidKeyPersona();
|
|
2620
|
+
const protocolDefinition = threadRoleProtocolDefinition;
|
|
2621
|
+
const protocolsConfig = yield TestDataGenerator.generateProtocolsConfigure({
|
|
2622
|
+
author: alice,
|
|
2623
|
+
protocolDefinition
|
|
2624
|
+
});
|
|
2625
|
+
const protocolsConfigureReply = yield dwn.processMessage(alice.did, protocolsConfig.message);
|
|
2626
|
+
expect(protocolsConfigureReply.status.code).to.equal(202);
|
|
2627
|
+
// Alice writes a 'thread' record
|
|
2628
|
+
const threadRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
2629
|
+
author: alice,
|
|
2630
|
+
protocol: protocolDefinition.protocol,
|
|
2631
|
+
protocolPath: 'thread',
|
|
2632
|
+
});
|
|
2633
|
+
const threadRoleReply = yield dwn.processMessage(alice.did, threadRecord.message, { dataStream: threadRecord.dataStream });
|
|
2634
|
+
expect(threadRoleReply.status.code).to.equal(202);
|
|
2635
|
+
// Alice writes three 'chat' records
|
|
2636
|
+
const chatRecordIds = [];
|
|
2637
|
+
for (let i = 0; i < 3; i++) {
|
|
2638
|
+
const chatRecord = yield TestDataGenerator.generateRecordsWrite({
|
|
2639
|
+
author: alice,
|
|
2640
|
+
recipient: alice.did,
|
|
2641
|
+
protocol: protocolDefinition.protocol,
|
|
2642
|
+
protocolPath: 'thread/chat',
|
|
2643
|
+
published: false,
|
|
2644
|
+
parentContextId: threadRecord.message.contextId,
|
|
2645
|
+
data: new TextEncoder().encode('Bob can read this cuz he is my friend'),
|
|
2646
|
+
});
|
|
2647
|
+
const chatReply = yield dwn.processMessage(alice.did, chatRecord.message, { dataStream: chatRecord.dataStream });
|
|
2648
|
+
expect(chatReply.status.code).to.equal(202);
|
|
2649
|
+
chatRecordIds.push(chatRecord.message.recordId);
|
|
2650
|
+
}
|
|
2651
|
+
// Bob invokes his friendRole to query that records
|
|
2652
|
+
const chatQuery = yield TestDataGenerator.generateRecordsQuery({
|
|
2653
|
+
author: bob,
|
|
2654
|
+
filter: {
|
|
2655
|
+
protocol: protocolDefinition.protocol,
|
|
2656
|
+
protocolPath: 'thread/chat',
|
|
2657
|
+
contextId: threadRecord.message.contextId,
|
|
2658
|
+
},
|
|
2659
|
+
protocolRole: 'thread/participant',
|
|
2660
|
+
});
|
|
2661
|
+
const chatQueryReply = yield dwn.processMessage(alice.did, chatQuery.message);
|
|
2662
|
+
expect(chatQueryReply.status.code).to.eq(401);
|
|
2663
|
+
expect(chatQueryReply.status.detail).to.contain(DwnErrorCode.ProtocolAuthorizationMatchingRoleRecordNotFound);
|
|
2664
|
+
}));
|
|
2665
|
+
});
|
|
2666
|
+
});
|
|
2667
|
+
it('should return 401 if signature check fails', () => __awaiter(this, void 0, void 0, function* () {
|
|
2668
|
+
const { author, message } = yield TestDataGenerator.generateRecordsQuery();
|
|
2669
|
+
const tenant = author.did;
|
|
2670
|
+
// setting up a stub did resolver & message store
|
|
2671
|
+
// intentionally not supplying the public key so a different public key is generated to simulate invalid signature
|
|
2672
|
+
const mismatchingPersona = yield TestDataGenerator.generatePersona({ did: author.did, keyId: author.keyId });
|
|
2673
|
+
const didResolver = TestStubGenerator.createDidResolverStub(mismatchingPersona);
|
|
2674
|
+
const messageStoreStub = sinon.createStubInstance(MessageStoreLevel);
|
|
2675
|
+
const dataStoreStub = sinon.createStubInstance(DataStoreLevel);
|
|
2676
|
+
const recordsQueryHandler = new RecordsQueryHandler(didResolver, messageStoreStub, dataStoreStub);
|
|
2677
|
+
const reply = yield recordsQueryHandler.handle({ tenant, message });
|
|
2678
|
+
expect(reply.status.code).to.equal(401);
|
|
2679
|
+
}));
|
|
2680
|
+
it('should return 400 if fail parsing the message', () => __awaiter(this, void 0, void 0, function* () {
|
|
2681
|
+
const { author, message } = yield TestDataGenerator.generateRecordsQuery();
|
|
2682
|
+
const tenant = author.did;
|
|
2683
|
+
// setting up a stub method resolver & message store
|
|
2684
|
+
const didResolver = TestStubGenerator.createDidResolverStub(author);
|
|
2685
|
+
const messageStoreStub = sinon.createStubInstance(MessageStoreLevel);
|
|
2686
|
+
const dataStoreStub = sinon.createStubInstance(DataStoreLevel);
|
|
2687
|
+
const recordsQueryHandler = new RecordsQueryHandler(didResolver, messageStoreStub, dataStoreStub);
|
|
2688
|
+
// stub the `parse()` function to throw an error
|
|
2689
|
+
sinon.stub(RecordsQuery, 'parse').throws('anyError');
|
|
2690
|
+
const reply = yield recordsQueryHandler.handle({ tenant, message });
|
|
2691
|
+
expect(reply.status.code).to.equal(400);
|
|
2692
|
+
}));
|
|
2693
|
+
});
|
|
2694
|
+
}
|
|
2695
|
+
//# sourceMappingURL=records-query.spec.js.map
|