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