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