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