@enbox/dwn-sdk-js 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.mjs +8 -8
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/generated/precompiled-validators.js +1 -2
- package/dist/esm/generated/precompiled-validators.js.map +1 -1
- package/dist/esm/src/core/abstract-message.js +4 -0
- package/dist/esm/src/core/abstract-message.js.map +1 -1
- package/dist/esm/src/core/auth.js +22 -33
- package/dist/esm/src/core/auth.js.map +1 -1
- package/dist/esm/src/core/dwn-constant.js +7 -7
- package/dist/esm/src/core/dwn-constant.js.map +1 -1
- package/dist/esm/src/core/dwn-error.js +1 -0
- package/dist/esm/src/core/dwn-error.js.map +1 -1
- package/dist/esm/src/core/grant-authorization.js +37 -52
- package/dist/esm/src/core/grant-authorization.js.map +1 -1
- package/dist/esm/src/core/message.js +85 -116
- package/dist/esm/src/core/message.js.map +1 -1
- package/dist/esm/src/core/messages-grant-authorization.js +63 -78
- package/dist/esm/src/core/messages-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization-action.js +266 -0
- package/dist/esm/src/core/protocol-authorization-action.js.map +1 -0
- package/dist/esm/src/core/protocol-authorization-validation.js +254 -0
- package/dist/esm/src/core/protocol-authorization-validation.js.map +1 -0
- package/dist/esm/src/core/protocol-authorization.js +122 -740
- package/dist/esm/src/core/protocol-authorization.js.map +1 -1
- package/dist/esm/src/core/protocols-grant-authorization.js +24 -38
- package/dist/esm/src/core/protocols-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/record-chain.js +64 -0
- package/dist/esm/src/core/record-chain.js.map +1 -0
- package/dist/esm/src/core/records-grant-authorization.js +55 -72
- package/dist/esm/src/core/records-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/resumable-task-manager.js +50 -65
- package/dist/esm/src/core/resumable-task-manager.js.map +1 -1
- package/dist/esm/src/core/tenant-gate.js +2 -13
- package/dist/esm/src/core/tenant-gate.js.map +1 -1
- package/dist/esm/src/dwn.js +69 -86
- package/dist/esm/src/dwn.js.map +1 -1
- package/dist/esm/src/event-stream/event-emitter-stream.js +17 -31
- package/dist/esm/src/event-stream/event-emitter-stream.js.map +1 -1
- package/dist/esm/src/handlers/messages-read.js +67 -77
- package/dist/esm/src/handlers/messages-read.js.map +1 -1
- package/dist/esm/src/handlers/messages-subscribe.js +51 -61
- package/dist/esm/src/handlers/messages-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/messages-sync.js +75 -85
- package/dist/esm/src/handlers/messages-sync.js.map +1 -1
- package/dist/esm/src/handlers/protocols-configure.js +135 -155
- package/dist/esm/src/handlers/protocols-configure.js.map +1 -1
- package/dist/esm/src/handlers/protocols-query.js +52 -51
- package/dist/esm/src/handlers/protocols-query.js.map +1 -1
- package/dist/esm/src/handlers/records-count.js +96 -82
- package/dist/esm/src/handlers/records-count.js.map +1 -1
- package/dist/esm/src/handlers/records-delete.js +78 -88
- package/dist/esm/src/handlers/records-delete.js.map +1 -1
- package/dist/esm/src/handlers/records-query.js +116 -101
- package/dist/esm/src/handlers/records-query.js.map +1 -1
- package/dist/esm/src/handlers/records-read.js +124 -131
- package/dist/esm/src/handlers/records-read.js.map +1 -1
- package/dist/esm/src/handlers/records-subscribe.js +150 -103
- package/dist/esm/src/handlers/records-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/records-write.js +250 -259
- package/dist/esm/src/handlers/records-write.js.map +1 -1
- package/dist/esm/src/interfaces/messages-read.js +24 -32
- package/dist/esm/src/interfaces/messages-read.js.map +1 -1
- package/dist/esm/src/interfaces/messages-subscribe.js +27 -41
- package/dist/esm/src/interfaces/messages-subscribe.js.map +1 -1
- package/dist/esm/src/interfaces/messages-sync.js +26 -40
- package/dist/esm/src/interfaces/messages-sync.js.map +1 -1
- package/dist/esm/src/interfaces/protocols-configure.js +63 -63
- package/dist/esm/src/interfaces/protocols-configure.js.map +1 -1
- package/dist/esm/src/interfaces/protocols-query.js +55 -68
- package/dist/esm/src/interfaces/protocols-query.js.map +1 -1
- package/dist/esm/src/interfaces/records-count.js +50 -66
- package/dist/esm/src/interfaces/records-count.js.map +1 -1
- package/dist/esm/src/interfaces/records-delete.js +45 -55
- package/dist/esm/src/interfaces/records-delete.js.map +1 -1
- package/dist/esm/src/interfaces/records-query.js +60 -76
- package/dist/esm/src/interfaces/records-query.js.map +1 -1
- package/dist/esm/src/interfaces/records-read.js +51 -67
- package/dist/esm/src/interfaces/records-read.js.map +1 -1
- package/dist/esm/src/interfaces/records-subscribe.js +52 -68
- package/dist/esm/src/interfaces/records-subscribe.js.map +1 -1
- package/dist/esm/src/interfaces/records-write-query.js +102 -0
- package/dist/esm/src/interfaces/records-write-query.js.map +1 -0
- package/dist/esm/src/interfaces/records-write-signing.js +92 -0
- package/dist/esm/src/interfaces/records-write-signing.js.map +1 -0
- package/dist/esm/src/interfaces/records-write.js +407 -602
- package/dist/esm/src/interfaces/records-write.js.map +1 -1
- package/dist/esm/src/jose/algorithms/signing/ed25519.js +10 -19
- package/dist/esm/src/jose/algorithms/signing/ed25519.js.map +1 -1
- package/dist/esm/src/jose/jws/general/builder.js +23 -35
- package/dist/esm/src/jose/jws/general/builder.js.map +1 -1
- package/dist/esm/src/jose/jws/general/verifier.js +56 -69
- package/dist/esm/src/jose/jws/general/verifier.js.map +1 -1
- package/dist/esm/src/protocols/permission-grant.js +44 -15
- package/dist/esm/src/protocols/permission-grant.js.map +1 -1
- package/dist/esm/src/protocols/permission-request.js +29 -15
- package/dist/esm/src/protocols/permission-request.js.map +1 -1
- package/dist/esm/src/protocols/permissions.js +216 -226
- package/dist/esm/src/protocols/permissions.js.map +1 -1
- package/dist/esm/src/smt/smt-store-level.js +42 -64
- package/dist/esm/src/smt/smt-store-level.js.map +1 -1
- package/dist/esm/src/smt/smt-store-memory.js +19 -45
- package/dist/esm/src/smt/smt-store-memory.js.map +1 -1
- package/dist/esm/src/smt/smt-utils.js +28 -45
- package/dist/esm/src/smt/smt-utils.js.map +1 -1
- package/dist/esm/src/smt/sparse-merkle-tree.js +426 -471
- package/dist/esm/src/smt/sparse-merkle-tree.js.map +1 -1
- package/dist/esm/src/state-index/state-index-level.js +115 -150
- package/dist/esm/src/state-index/state-index-level.js.map +1 -1
- package/dist/esm/src/store/blockstore-level.js +54 -156
- package/dist/esm/src/store/blockstore-level.js.map +1 -1
- package/dist/esm/src/store/blockstore-mock.js +48 -153
- package/dist/esm/src/store/blockstore-mock.js.map +1 -1
- package/dist/esm/src/store/data-store-level.js +59 -99
- package/dist/esm/src/store/data-store-level.js.map +1 -1
- package/dist/esm/src/store/index-level-compound.js +246 -0
- package/dist/esm/src/store/index-level-compound.js.map +1 -0
- package/dist/esm/src/store/index-level.js +295 -713
- package/dist/esm/src/store/index-level.js.map +1 -1
- package/dist/esm/src/store/level-wrapper.js +143 -244
- package/dist/esm/src/store/level-wrapper.js.map +1 -1
- package/dist/esm/src/store/message-store-level.js +71 -94
- package/dist/esm/src/store/message-store-level.js.map +1 -1
- package/dist/esm/src/store/resumable-task-store-level.js +62 -101
- package/dist/esm/src/store/resumable-task-store-level.js.map +1 -1
- package/dist/esm/src/store/storage-controller.js +129 -144
- package/dist/esm/src/store/storage-controller.js.map +1 -1
- package/dist/esm/src/utils/abort.js +8 -19
- package/dist/esm/src/utils/abort.js.map +1 -1
- package/dist/esm/src/utils/array.js +15 -49
- package/dist/esm/src/utils/array.js.map +1 -1
- package/dist/esm/src/utils/cid.js +29 -77
- package/dist/esm/src/utils/cid.js.map +1 -1
- package/dist/esm/src/utils/data-stream.js +37 -65
- package/dist/esm/src/utils/data-stream.js.map +1 -1
- package/dist/esm/src/utils/encryption.js +136 -162
- package/dist/esm/src/utils/encryption.js.map +1 -1
- package/dist/esm/src/utils/filter.js +1 -12
- package/dist/esm/src/utils/filter.js.map +1 -1
- package/dist/esm/src/utils/hd-key.js +45 -63
- package/dist/esm/src/utils/hd-key.js.map +1 -1
- package/dist/esm/src/utils/jws.js +9 -20
- package/dist/esm/src/utils/jws.js.map +1 -1
- package/dist/esm/src/utils/memory-cache.js +12 -23
- package/dist/esm/src/utils/memory-cache.js.map +1 -1
- package/dist/esm/src/utils/messages.js +9 -3
- package/dist/esm/src/utils/messages.js.map +1 -1
- package/dist/esm/src/utils/private-key-signer.js +9 -17
- package/dist/esm/src/utils/private-key-signer.js.map +1 -1
- package/dist/esm/src/utils/protocols.js +62 -70
- package/dist/esm/src/utils/protocols.js.map +1 -1
- package/dist/esm/src/utils/records.js +108 -140
- package/dist/esm/src/utils/records.js.map +1 -1
- package/dist/esm/src/utils/secp256k1.js +60 -96
- package/dist/esm/src/utils/secp256k1.js.map +1 -1
- package/dist/esm/src/utils/secp256r1.js +54 -71
- package/dist/esm/src/utils/secp256r1.js.map +1 -1
- package/dist/esm/src/utils/time.js +5 -18
- package/dist/esm/src/utils/time.js.map +1 -1
- package/dist/esm/src/utils/url.js +3 -3
- package/dist/esm/src/utils/url.js.map +1 -1
- package/dist/esm/tests/core/auth.spec.js +3 -12
- package/dist/esm/tests/core/auth.spec.js.map +1 -1
- package/dist/esm/tests/core/message.spec.js +50 -59
- package/dist/esm/tests/core/message.spec.js.map +1 -1
- package/dist/esm/tests/core/protocol-authorization.spec.js +9 -18
- package/dist/esm/tests/core/protocol-authorization.spec.js.map +1 -1
- package/dist/esm/tests/dwn.spec.js +45 -58
- package/dist/esm/tests/dwn.spec.js.map +1 -1
- package/dist/esm/tests/event-stream/event-emitter-stream.spec.js +24 -33
- package/dist/esm/tests/event-stream/event-emitter-stream.spec.js.map +1 -1
- package/dist/esm/tests/event-stream/event-stream.spec.js +46 -55
- package/dist/esm/tests/event-stream/event-stream.spec.js.map +1 -1
- package/dist/esm/tests/features/author-delegated-grant.spec.js +326 -343
- package/dist/esm/tests/features/author-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-delegated-grant.spec.js +153 -169
- package/dist/esm/tests/features/owner-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-signature.spec.js +67 -78
- package/dist/esm/tests/features/owner-signature.spec.js.map +1 -1
- package/dist/esm/tests/features/permissions.spec.js +446 -181
- package/dist/esm/tests/features/permissions.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-composition.spec.js +346 -356
- package/dist/esm/tests/features/protocol-composition.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-create-action.spec.js +42 -51
- package/dist/esm/tests/features/protocol-create-action.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-delete-action.spec.js +94 -103
- package/dist/esm/tests/features/protocol-delete-action.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-update-action.spec.js +105 -114
- package/dist/esm/tests/features/protocol-update-action.spec.js.map +1 -1
- package/dist/esm/tests/features/records-prune.spec.js +175 -191
- package/dist/esm/tests/features/records-prune.spec.js.map +1 -1
- package/dist/esm/tests/features/records-tags.spec.js +441 -460
- package/dist/esm/tests/features/records-tags.spec.js.map +1 -1
- package/dist/esm/tests/features/resumable-tasks.spec.js +82 -91
- package/dist/esm/tests/features/resumable-tasks.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-read.spec.js +206 -207
- package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-subscribe.spec.js +145 -154
- package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-sync.spec.js +174 -183
- package/dist/esm/tests/handlers/messages-sync.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-configure.spec.js +244 -238
- package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-query.spec.js +156 -169
- package/dist/esm/tests/handlers/protocols-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-count.spec.js +93 -102
- package/dist/esm/tests/handlers/records-count.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-delete.spec.js +252 -264
- package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-query.spec.js +917 -988
- package/dist/esm/tests/handlers/records-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-read.spec.js +553 -568
- package/dist/esm/tests/handlers/records-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-subscribe.spec.js +269 -278
- package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-write.spec.js +1057 -1082
- package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/messages-get.spec.js +39 -48
- package/dist/esm/tests/interfaces/messages-get.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/messages-subscribe.spec.js +4 -13
- package/dist/esm/tests/interfaces/messages-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/protocols-configure.spec.js +212 -88
- package/dist/esm/tests/interfaces/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/protocols-query.spec.js +8 -17
- package/dist/esm/tests/interfaces/protocols-query.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-delete.spec.js +8 -17
- package/dist/esm/tests/interfaces/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-query.spec.js +20 -29
- package/dist/esm/tests/interfaces/records-query.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-read.spec.js +42 -51
- package/dist/esm/tests/interfaces/records-read.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-subscribe.spec.js +16 -25
- package/dist/esm/tests/interfaces/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-write.spec.js +152 -165
- package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
- package/dist/esm/tests/jose/jws/general.spec.js +36 -45
- package/dist/esm/tests/jose/jws/general.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permission-grant.spec.js +44 -50
- package/dist/esm/tests/protocols/permission-grant.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permission-request.spec.js +23 -32
- package/dist/esm/tests/protocols/permission-request.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permissions.spec.js +49 -55
- package/dist/esm/tests/protocols/permissions.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/aggregator.spec.js +124 -135
- package/dist/esm/tests/scenarios/aggregator.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/deleted-record.spec.js +23 -32
- package/dist/esm/tests/scenarios/deleted-record.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +52 -61
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/nested-roles.spec.js +63 -73
- package/dist/esm/tests/scenarios/nested-roles.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/subscriptions.spec.js +377 -333
- package/dist/esm/tests/scenarios/subscriptions.spec.js.map +1 -1
- package/dist/esm/tests/smt/smt-store-level.spec.js +76 -87
- package/dist/esm/tests/smt/smt-store-level.spec.js.map +1 -1
- package/dist/esm/tests/smt/sparse-merkle-tree.spec.js +344 -353
- package/dist/esm/tests/smt/sparse-merkle-tree.spec.js.map +1 -1
- package/dist/esm/tests/state-index/state-index-level.spec.js +117 -126
- package/dist/esm/tests/state-index/state-index-level.spec.js.map +1 -1
- package/dist/esm/tests/store/blockstore-level.spec.js +44 -99
- package/dist/esm/tests/store/blockstore-level.spec.js.map +1 -1
- package/dist/esm/tests/store/blockstore-mock.spec.js +40 -120
- package/dist/esm/tests/store/blockstore-mock.spec.js.map +1 -1
- package/dist/esm/tests/store/data-store-level.spec.js +86 -95
- package/dist/esm/tests/store/data-store-level.spec.js.map +1 -1
- package/dist/esm/tests/store/index-level.spec.js +404 -414
- package/dist/esm/tests/store/index-level.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store-level.spec.js +13 -22
- package/dist/esm/tests/store/message-store-level.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store.spec.js +229 -238
- package/dist/esm/tests/store/message-store.spec.js.map +1 -1
- package/dist/esm/tests/test-event-stream.js +3 -3
- package/dist/esm/tests/test-event-stream.js.map +1 -1
- package/dist/esm/tests/test-stores.js +16 -13
- package/dist/esm/tests/test-stores.js.map +1 -1
- package/dist/esm/tests/test-suite.js +2 -11
- package/dist/esm/tests/test-suite.js.map +1 -1
- package/dist/esm/tests/utils/cid.spec.js +24 -33
- package/dist/esm/tests/utils/cid.spec.js.map +1 -1
- package/dist/esm/tests/utils/data-stream.spec.js +48 -57
- package/dist/esm/tests/utils/data-stream.spec.js.map +1 -1
- package/dist/esm/tests/utils/encryption-callbacks.spec.js +45 -54
- package/dist/esm/tests/utils/encryption-callbacks.spec.js.map +1 -1
- package/dist/esm/tests/utils/encryption.spec.js +291 -44
- package/dist/esm/tests/utils/encryption.spec.js.map +1 -1
- package/dist/esm/tests/utils/filters.spec.js +46 -55
- package/dist/esm/tests/utils/filters.spec.js.map +1 -1
- package/dist/esm/tests/utils/hd-key.spec.js +10 -19
- package/dist/esm/tests/utils/hd-key.spec.js.map +1 -1
- package/dist/esm/tests/utils/jws.spec.js +3 -12
- package/dist/esm/tests/utils/jws.spec.js.map +1 -1
- package/dist/esm/tests/utils/memory-cache.spec.js +9 -18
- package/dist/esm/tests/utils/memory-cache.spec.js.map +1 -1
- package/dist/esm/tests/utils/messages.spec.js +6 -15
- package/dist/esm/tests/utils/messages.spec.js.map +1 -1
- package/dist/esm/tests/utils/poller.js +22 -33
- package/dist/esm/tests/utils/poller.js.map +1 -1
- package/dist/esm/tests/utils/private-key-signer.spec.js +15 -24
- package/dist/esm/tests/utils/private-key-signer.spec.js.map +1 -1
- package/dist/esm/tests/utils/records.spec.js +10 -19
- package/dist/esm/tests/utils/records.spec.js.map +1 -1
- package/dist/esm/tests/utils/secp256k1.spec.js +16 -25
- package/dist/esm/tests/utils/secp256k1.spec.js.map +1 -1
- package/dist/esm/tests/utils/secp256r1.spec.js +18 -27
- package/dist/esm/tests/utils/secp256r1.spec.js.map +1 -1
- package/dist/esm/tests/utils/test-data-generator.js +414 -468
- package/dist/esm/tests/utils/test-data-generator.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/definitions.spec.js +2 -11
- package/dist/esm/tests/validation/json-schemas/definitions.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js +4 -13
- package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js +8 -17
- package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js +3 -12
- package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js +4 -13
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js +2 -11
- package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/records/records-read.spec.js +2 -11
- package/dist/esm/tests/validation/json-schemas/records/records-read.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js +7 -16
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js.map +1 -1
- package/dist/types/src/core/protocol-authorization-action.d.ts +42 -0
- package/dist/types/src/core/protocol-authorization-action.d.ts.map +1 -0
- package/dist/types/src/core/protocol-authorization-validation.d.ts +60 -0
- package/dist/types/src/core/protocol-authorization-validation.d.ts.map +1 -0
- package/dist/types/src/core/protocol-authorization.d.ts +10 -100
- package/dist/types/src/core/protocol-authorization.d.ts.map +1 -1
- package/dist/types/src/core/record-chain.d.ts +24 -0
- package/dist/types/src/core/record-chain.d.ts.map +1 -0
- package/dist/types/src/handlers/records-write.d.ts +2 -1
- package/dist/types/src/handlers/records-write.d.ts.map +1 -1
- package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-write-query.d.ts +33 -0
- package/dist/types/src/interfaces/records-write-query.d.ts.map +1 -0
- package/dist/types/src/interfaces/records-write-signing.d.ts +35 -0
- package/dist/types/src/interfaces/records-write-signing.d.ts.map +1 -0
- package/dist/types/src/interfaces/records-write.d.ts +10 -44
- package/dist/types/src/interfaces/records-write.d.ts.map +1 -1
- package/dist/types/src/store/index-level-compound.d.ts +70 -0
- package/dist/types/src/store/index-level-compound.d.ts.map +1 -0
- package/dist/types/src/store/index-level.d.ts +0 -58
- package/dist/types/src/store/index-level.d.ts.map +1 -1
- package/dist/types/src/utils/protocols.d.ts +5 -0
- package/dist/types/src/utils/protocols.d.ts.map +1 -1
- package/dist/types/src/utils/records.d.ts +3 -1
- package/dist/types/src/utils/records.d.ts.map +1 -1
- package/dist/types/tests/features/permissions.spec.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/core/protocol-authorization-action.ts +377 -0
- package/src/core/protocol-authorization-validation.ts +391 -0
- package/src/core/protocol-authorization.ts +60 -849
- package/src/core/record-chain.ts +99 -0
- package/src/handlers/records-read.ts +1 -1
- package/src/handlers/records-write.ts +37 -21
- package/src/interfaces/protocols-configure.ts +33 -5
- package/src/interfaces/records-write-query.ts +139 -0
- package/src/interfaces/records-write-signing.ts +143 -0
- package/src/interfaces/records-write.ts +49 -221
- package/src/store/index-level-compound.ts +324 -0
- package/src/store/index-level.ts +24 -306
- package/src/utils/protocols.ts +8 -0
- package/src/utils/records.ts +9 -15
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
1
|
import sinon from 'sinon';
|
|
11
2
|
import { DidKey } from '@enbox/dids';
|
|
12
3
|
import { Dwn } from '../../src/dwn.js';
|
|
@@ -32,7 +23,7 @@ export function testRecordsTags() {
|
|
|
32
23
|
let dwn;
|
|
33
24
|
// important to follow the `before` and `after` pattern to initialize and clean the stores in tests
|
|
34
25
|
// so that different test suites can reuse the same backend store for testing
|
|
35
|
-
beforeAll(() =>
|
|
26
|
+
beforeAll(async () => {
|
|
36
27
|
didResolver = new UniversalResolver({ didResolvers: [DidKey] });
|
|
37
28
|
const stores = TestStores.get();
|
|
38
29
|
messageStore = stores.messageStore;
|
|
@@ -40,24 +31,24 @@ export function testRecordsTags() {
|
|
|
40
31
|
resumableTaskStore = stores.resumableTaskStore;
|
|
41
32
|
stateIndex = stores.stateIndex;
|
|
42
33
|
eventStream = TestEventStream.get();
|
|
43
|
-
dwn =
|
|
44
|
-
})
|
|
45
|
-
beforeEach(() =>
|
|
34
|
+
dwn = await Dwn.create({ didResolver, messageStore, dataStore, stateIndex, eventStream, resumableTaskStore });
|
|
35
|
+
});
|
|
36
|
+
beforeEach(async () => {
|
|
46
37
|
sinon.restore(); // wipe all previous stubs/spies/mocks/fakes
|
|
47
38
|
// clean up before each test rather than after so that a test does not depend on other tests to do the clean up
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
})
|
|
53
|
-
afterAll(() =>
|
|
54
|
-
|
|
55
|
-
})
|
|
39
|
+
await messageStore.clear();
|
|
40
|
+
await dataStore.clear();
|
|
41
|
+
await resumableTaskStore.clear();
|
|
42
|
+
await stateIndex.clear();
|
|
43
|
+
});
|
|
44
|
+
afterAll(async () => {
|
|
45
|
+
await dwn.close();
|
|
46
|
+
});
|
|
56
47
|
describe('RecordsWrite with tags', () => {
|
|
57
48
|
describe('protocol rules', () => {
|
|
58
49
|
describe('ProtocolsConfigure', () => {
|
|
59
|
-
it('should support protocol tag types of string, number, integer, boolean and array types of numbers, integers and strings', () =>
|
|
60
|
-
const alice =
|
|
50
|
+
it('should support protocol tag types of string, number, integer, boolean and array types of numbers, integers and strings', async () => {
|
|
51
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
61
52
|
// configure a protocol with tags of string, number, boolean and array types of numbers and strings
|
|
62
53
|
const protocolDefinition = {
|
|
63
54
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -102,15 +93,15 @@ export function testRecordsTags() {
|
|
|
102
93
|
}
|
|
103
94
|
},
|
|
104
95
|
};
|
|
105
|
-
const protocolConfigure =
|
|
96
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
106
97
|
author: alice,
|
|
107
98
|
protocolDefinition,
|
|
108
99
|
});
|
|
109
|
-
const configureReply =
|
|
100
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
110
101
|
expect(configureReply.status.code).toBe(202);
|
|
111
|
-
})
|
|
112
|
-
it('should reject tags that have invalid schema definitions during create', () =>
|
|
113
|
-
const alice =
|
|
102
|
+
});
|
|
103
|
+
it('should reject tags that have invalid schema definitions during create', async () => {
|
|
104
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
114
105
|
// protocol definition with an invalid schema
|
|
115
106
|
const invalidSchemaProtocol = {
|
|
116
107
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -139,10 +130,10 @@ export function testRecordsTags() {
|
|
|
139
130
|
author: alice,
|
|
140
131
|
protocolDefinition: invalidSchemaProtocol,
|
|
141
132
|
});
|
|
142
|
-
|
|
143
|
-
})
|
|
144
|
-
it('should reject tags that have invalid schema definitions during process', () =>
|
|
145
|
-
const alice =
|
|
133
|
+
await expect(protocolConfigure).rejects.toThrow(DwnErrorCode.ProtocolsConfigureInvalidTagSchema);
|
|
134
|
+
});
|
|
135
|
+
it('should reject tags that have invalid schema definitions during process', async () => {
|
|
136
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
146
137
|
// protocol definition with an invalid schema
|
|
147
138
|
const invalidSchemaProtocol = {
|
|
148
139
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -174,19 +165,19 @@ export function testRecordsTags() {
|
|
|
174
165
|
messageTimestamp: Time.getCurrentTimestamp(),
|
|
175
166
|
definition: invalidSchemaProtocol
|
|
176
167
|
};
|
|
177
|
-
const authorization =
|
|
168
|
+
const authorization = await Message.createAuthorization({
|
|
178
169
|
descriptor,
|
|
179
170
|
signer: Jws.createSigner(alice)
|
|
180
171
|
});
|
|
181
172
|
const protocolsConfigureMessage = { descriptor, authorization };
|
|
182
|
-
const protocolsConfigureReply =
|
|
173
|
+
const protocolsConfigureReply = await dwn.processMessage(alice.did, protocolsConfigureMessage);
|
|
183
174
|
expect(protocolsConfigureReply.status.code).toBe(400);
|
|
184
175
|
expect(protocolsConfigureReply.status.detail).toContain(DwnErrorCode.ProtocolsConfigureInvalidTagSchema);
|
|
185
176
|
expect(protocolsConfigureReply.status.detail).toContain(`foo/$tags/invalidTag/contains/minimum must be number`);
|
|
186
|
-
})
|
|
177
|
+
});
|
|
187
178
|
describe('should reject invalid tag types', () => {
|
|
188
|
-
it('object', () =>
|
|
189
|
-
const alice =
|
|
179
|
+
it('object', async () => {
|
|
180
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
190
181
|
// protocol definition with unsupported tag type of object
|
|
191
182
|
const objectTagsType = {
|
|
192
183
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -211,16 +202,16 @@ export function testRecordsTags() {
|
|
|
211
202
|
messageTimestamp: Time.getCurrentTimestamp(),
|
|
212
203
|
definition: objectTagsType
|
|
213
204
|
};
|
|
214
|
-
const authorization =
|
|
205
|
+
const authorization = await Message.createAuthorization({
|
|
215
206
|
descriptor,
|
|
216
207
|
signer: Jws.createSigner(alice)
|
|
217
208
|
});
|
|
218
209
|
const protocolsConfigureMessage = { descriptor, authorization };
|
|
219
|
-
const objectTagsTypeConfigureReply =
|
|
210
|
+
const objectTagsTypeConfigureReply = await dwn.processMessage(alice.did, protocolsConfigureMessage);
|
|
220
211
|
expect(objectTagsTypeConfigureReply.status.code).toBe(400);
|
|
221
|
-
})
|
|
222
|
-
it('array of objects', () =>
|
|
223
|
-
const alice =
|
|
212
|
+
});
|
|
213
|
+
it('array of objects', async () => {
|
|
214
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
224
215
|
// protocol definition with unsupported tag type array of objects
|
|
225
216
|
const objectArrayTagsType = {
|
|
226
217
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -248,16 +239,16 @@ export function testRecordsTags() {
|
|
|
248
239
|
messageTimestamp: Time.getCurrentTimestamp(),
|
|
249
240
|
definition: objectArrayTagsType
|
|
250
241
|
};
|
|
251
|
-
const authorization =
|
|
242
|
+
const authorization = await Message.createAuthorization({
|
|
252
243
|
descriptor,
|
|
253
244
|
signer: Jws.createSigner(alice)
|
|
254
245
|
});
|
|
255
246
|
const protocolsConfigureMessage = { descriptor, authorization };
|
|
256
|
-
const objectArrayTagsTypeConfigureReply =
|
|
247
|
+
const objectArrayTagsTypeConfigureReply = await dwn.processMessage(alice.did, protocolsConfigureMessage);
|
|
257
248
|
expect(objectArrayTagsTypeConfigureReply.status.code).toBe(400);
|
|
258
|
-
})
|
|
259
|
-
it('array of booleans', () =>
|
|
260
|
-
const alice =
|
|
249
|
+
});
|
|
250
|
+
it('array of booleans', async () => {
|
|
251
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
261
252
|
// protocol definition with unsupported tag type array of booleans
|
|
262
253
|
const booleanArrayTagsType = {
|
|
263
254
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -284,18 +275,18 @@ export function testRecordsTags() {
|
|
|
284
275
|
messageTimestamp: Time.getCurrentTimestamp(),
|
|
285
276
|
definition: booleanArrayTagsType
|
|
286
277
|
};
|
|
287
|
-
const authorization =
|
|
278
|
+
const authorization = await Message.createAuthorization({
|
|
288
279
|
descriptor,
|
|
289
280
|
signer: Jws.createSigner(alice)
|
|
290
281
|
});
|
|
291
282
|
const protocolsConfigureMessage = { descriptor, authorization };
|
|
292
|
-
const booleanArrayTagsTypeConfigureReply =
|
|
283
|
+
const booleanArrayTagsTypeConfigureReply = await dwn.processMessage(alice.did, protocolsConfigureMessage);
|
|
293
284
|
expect(booleanArrayTagsTypeConfigureReply.status.code).toBe(400);
|
|
294
|
-
})
|
|
285
|
+
});
|
|
295
286
|
});
|
|
296
287
|
});
|
|
297
|
-
it('should reject a record with a tag property that does not match the protocol definition tags', () =>
|
|
298
|
-
const alice =
|
|
288
|
+
it('should reject a record with a tag property that does not match the protocol definition tags', async () => {
|
|
289
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
299
290
|
// has a `knownTag` tag in the protocol definition
|
|
300
291
|
const protocolDefinition = {
|
|
301
292
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -314,14 +305,14 @@ export function testRecordsTags() {
|
|
|
314
305
|
},
|
|
315
306
|
};
|
|
316
307
|
// configure tags protocol
|
|
317
|
-
const protocolConfigure =
|
|
308
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
318
309
|
author: alice,
|
|
319
310
|
protocolDefinition,
|
|
320
311
|
});
|
|
321
|
-
const configureReply =
|
|
312
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
322
313
|
expect(configureReply.status.code).toBe(202);
|
|
323
314
|
// write a foo record with an `unknownTag` tag.
|
|
324
|
-
const fooRecord =
|
|
315
|
+
const fooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
325
316
|
author: alice,
|
|
326
317
|
published: true,
|
|
327
318
|
protocol: protocolDefinition.protocol,
|
|
@@ -330,13 +321,13 @@ export function testRecordsTags() {
|
|
|
330
321
|
unknownTag: 'some-value'
|
|
331
322
|
}
|
|
332
323
|
});
|
|
333
|
-
const fooRecordReply =
|
|
324
|
+
const fooRecordReply = await dwn.processMessage(alice.did, fooRecord.message, { dataStream: fooRecord.dataStream });
|
|
334
325
|
expect(fooRecordReply.status.code).toBe(400);
|
|
335
326
|
expect(fooRecordReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
336
327
|
// ensure the correct tag descriptor is in the error message
|
|
337
328
|
expect(fooRecordReply.status.detail).toContain(`${protocolDefinition.protocol}/foo/$tags must NOT have additional properties`);
|
|
338
329
|
// write a foo record with a `knownTag` tag.
|
|
339
|
-
const validFooRecord =
|
|
330
|
+
const validFooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
340
331
|
author: alice,
|
|
341
332
|
published: true,
|
|
342
333
|
protocol: protocolDefinition.protocol,
|
|
@@ -346,11 +337,11 @@ export function testRecordsTags() {
|
|
|
346
337
|
}
|
|
347
338
|
});
|
|
348
339
|
// should pass
|
|
349
|
-
const validFooRecordReply =
|
|
340
|
+
const validFooRecordReply = await dwn.processMessage(alice.did, validFooRecord.message, { dataStream: validFooRecord.dataStream });
|
|
350
341
|
expect(validFooRecordReply.status.code).toBe(202);
|
|
351
|
-
})
|
|
352
|
-
it('should reject a tag value that does not match the boolean type', () =>
|
|
353
|
-
const alice =
|
|
342
|
+
});
|
|
343
|
+
it('should reject a tag value that does not match the boolean type', async () => {
|
|
344
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
354
345
|
// protocol with a boolean type for a tag
|
|
355
346
|
const protocolDefinition = {
|
|
356
347
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -369,14 +360,14 @@ export function testRecordsTags() {
|
|
|
369
360
|
},
|
|
370
361
|
};
|
|
371
362
|
// configure tags protocol
|
|
372
|
-
const protocolConfigure =
|
|
363
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
373
364
|
author: alice,
|
|
374
365
|
protocolDefinition
|
|
375
366
|
});
|
|
376
|
-
const configureReply =
|
|
367
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
377
368
|
expect(configureReply.status.code).toBe(202);
|
|
378
369
|
// `draft` should be a boolean type, but we are passing a string
|
|
379
|
-
const fooRecord =
|
|
370
|
+
const fooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
380
371
|
author: alice,
|
|
381
372
|
published: true,
|
|
382
373
|
protocol: protocolDefinition.protocol,
|
|
@@ -385,12 +376,12 @@ export function testRecordsTags() {
|
|
|
385
376
|
draft: 'true'
|
|
386
377
|
}
|
|
387
378
|
});
|
|
388
|
-
const fooRecordReply =
|
|
379
|
+
const fooRecordReply = await dwn.processMessage(alice.did, fooRecord.message, { dataStream: fooRecord.dataStream });
|
|
389
380
|
expect(fooRecordReply.status.code).toBe(400);
|
|
390
381
|
expect(fooRecordReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
391
382
|
expect(fooRecordReply.status.detail).toContain(`${protocolDefinition.protocol}/foo/$tags/draft must be boolean`);
|
|
392
383
|
// positive test with a boolean
|
|
393
|
-
const fooRecord2 =
|
|
384
|
+
const fooRecord2 = await TestDataGenerator.generateRecordsWrite({
|
|
394
385
|
author: alice,
|
|
395
386
|
published: true,
|
|
396
387
|
protocol: protocolDefinition.protocol,
|
|
@@ -399,11 +390,11 @@ export function testRecordsTags() {
|
|
|
399
390
|
draft: true
|
|
400
391
|
}
|
|
401
392
|
});
|
|
402
|
-
const fooRecord2Reply =
|
|
393
|
+
const fooRecord2Reply = await dwn.processMessage(alice.did, fooRecord2.message, { dataStream: fooRecord2.dataStream });
|
|
403
394
|
expect(fooRecord2Reply.status.code).toBe(202);
|
|
404
|
-
})
|
|
405
|
-
it('should reject a tag value that does not match the number type', () =>
|
|
406
|
-
const alice =
|
|
395
|
+
});
|
|
396
|
+
it('should reject a tag value that does not match the number type', async () => {
|
|
397
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
407
398
|
// protocol with a number type for a tag
|
|
408
399
|
const protocolDefinition = {
|
|
409
400
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -422,14 +413,14 @@ export function testRecordsTags() {
|
|
|
422
413
|
},
|
|
423
414
|
};
|
|
424
415
|
// configure tags protocol
|
|
425
|
-
const protocolConfigure =
|
|
416
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
426
417
|
author: alice,
|
|
427
418
|
protocolDefinition
|
|
428
419
|
});
|
|
429
|
-
const configureReply =
|
|
420
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
430
421
|
expect(configureReply.status.code).toBe(202);
|
|
431
422
|
// `numberType` should be a number type, but we are passing a string
|
|
432
|
-
const fooRecord =
|
|
423
|
+
const fooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
433
424
|
author: alice,
|
|
434
425
|
published: true,
|
|
435
426
|
protocol: protocolDefinition.protocol,
|
|
@@ -438,12 +429,12 @@ export function testRecordsTags() {
|
|
|
438
429
|
numberType: '1'
|
|
439
430
|
}
|
|
440
431
|
});
|
|
441
|
-
const fooRecordReply =
|
|
432
|
+
const fooRecordReply = await dwn.processMessage(alice.did, fooRecord.message, { dataStream: fooRecord.dataStream });
|
|
442
433
|
expect(fooRecordReply.status.code).toBe(400);
|
|
443
434
|
expect(fooRecordReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
444
435
|
expect(fooRecordReply.status.detail).toContain(`${protocolDefinition.protocol}/foo/$tags/numberType must be number`);
|
|
445
436
|
// positive tests with an integer number
|
|
446
|
-
const fooRecord2 =
|
|
437
|
+
const fooRecord2 = await TestDataGenerator.generateRecordsWrite({
|
|
447
438
|
author: alice,
|
|
448
439
|
published: true,
|
|
449
440
|
protocol: protocolDefinition.protocol,
|
|
@@ -452,10 +443,10 @@ export function testRecordsTags() {
|
|
|
452
443
|
numberType: 1
|
|
453
444
|
}
|
|
454
445
|
});
|
|
455
|
-
const fooRecord2Reply =
|
|
446
|
+
const fooRecord2Reply = await dwn.processMessage(alice.did, fooRecord2.message, { dataStream: fooRecord2.dataStream });
|
|
456
447
|
expect(fooRecord2Reply.status.code).toBe(202);
|
|
457
448
|
// positive tests with a decimal number
|
|
458
|
-
const fooRecord3 =
|
|
449
|
+
const fooRecord3 = await TestDataGenerator.generateRecordsWrite({
|
|
459
450
|
author: alice,
|
|
460
451
|
published: true,
|
|
461
452
|
protocol: protocolDefinition.protocol,
|
|
@@ -464,11 +455,11 @@ export function testRecordsTags() {
|
|
|
464
455
|
numberType: 1.5
|
|
465
456
|
}
|
|
466
457
|
});
|
|
467
|
-
const fooRecord3Reply =
|
|
458
|
+
const fooRecord3Reply = await dwn.processMessage(alice.did, fooRecord3.message, { dataStream: fooRecord3.dataStream });
|
|
468
459
|
expect(fooRecord3Reply.status.code).toBe(202);
|
|
469
|
-
})
|
|
470
|
-
it('should reject a tag value that does not match the integer type', () =>
|
|
471
|
-
const alice =
|
|
460
|
+
});
|
|
461
|
+
it('should reject a tag value that does not match the integer type', async () => {
|
|
462
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
472
463
|
// protocol with an integer type for a tag
|
|
473
464
|
const protocolDefinition = {
|
|
474
465
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -487,14 +478,14 @@ export function testRecordsTags() {
|
|
|
487
478
|
},
|
|
488
479
|
};
|
|
489
480
|
// configure tags protocol
|
|
490
|
-
const protocolConfigure =
|
|
481
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
491
482
|
author: alice,
|
|
492
483
|
protocolDefinition
|
|
493
484
|
});
|
|
494
|
-
const configureReply =
|
|
485
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
495
486
|
expect(configureReply.status.code).toBe(202);
|
|
496
487
|
// `count` should be an integer type, but we are passing decimal number
|
|
497
|
-
const fooRecord =
|
|
488
|
+
const fooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
498
489
|
author: alice,
|
|
499
490
|
published: true,
|
|
500
491
|
protocol: protocolDefinition.protocol,
|
|
@@ -503,12 +494,12 @@ export function testRecordsTags() {
|
|
|
503
494
|
count: 1.5
|
|
504
495
|
}
|
|
505
496
|
});
|
|
506
|
-
const fooRecordReply =
|
|
497
|
+
const fooRecordReply = await dwn.processMessage(alice.did, fooRecord.message, { dataStream: fooRecord.dataStream });
|
|
507
498
|
expect(fooRecordReply.status.code).toBe(400);
|
|
508
499
|
expect(fooRecordReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
509
500
|
expect(fooRecordReply.status.detail).toContain(`${protocolDefinition.protocol}/foo/$tags/count must be integer`);
|
|
510
501
|
// positive test with an integer
|
|
511
|
-
const fooRecord2 =
|
|
502
|
+
const fooRecord2 = await TestDataGenerator.generateRecordsWrite({
|
|
512
503
|
author: alice,
|
|
513
504
|
published: true,
|
|
514
505
|
protocol: protocolDefinition.protocol,
|
|
@@ -517,11 +508,11 @@ export function testRecordsTags() {
|
|
|
517
508
|
count: 1
|
|
518
509
|
}
|
|
519
510
|
});
|
|
520
|
-
const fooRecord2Reply =
|
|
511
|
+
const fooRecord2Reply = await dwn.processMessage(alice.did, fooRecord2.message, { dataStream: fooRecord2.dataStream });
|
|
521
512
|
expect(fooRecord2Reply.status.code).toBe(202);
|
|
522
|
-
})
|
|
523
|
-
it('should reject a record with a tag value that does not match a given enum in the protocol definition', () =>
|
|
524
|
-
const alice =
|
|
513
|
+
});
|
|
514
|
+
it('should reject a record with a tag value that does not match a given enum in the protocol definition', async () => {
|
|
515
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
525
516
|
// protocol with an enum for a tag
|
|
526
517
|
const protocolDefinition = {
|
|
527
518
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -541,14 +532,14 @@ export function testRecordsTags() {
|
|
|
541
532
|
},
|
|
542
533
|
};
|
|
543
534
|
// configure tags protocol
|
|
544
|
-
const protocolConfigure =
|
|
535
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
545
536
|
author: alice,
|
|
546
537
|
protocolDefinition,
|
|
547
538
|
});
|
|
548
|
-
const configureReply =
|
|
539
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
549
540
|
expect(configureReply.status.code).toBe(202);
|
|
550
541
|
// write a foo record with an `unknown_status` tag value.
|
|
551
|
-
const fooRecord =
|
|
542
|
+
const fooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
552
543
|
author: alice,
|
|
553
544
|
published: true,
|
|
554
545
|
protocol: protocolDefinition.protocol,
|
|
@@ -557,7 +548,7 @@ export function testRecordsTags() {
|
|
|
557
548
|
status: 'unknown_status'
|
|
558
549
|
}
|
|
559
550
|
});
|
|
560
|
-
const fooRecordReply =
|
|
551
|
+
const fooRecordReply = await dwn.processMessage(alice.did, fooRecord.message, { dataStream: fooRecord.dataStream });
|
|
561
552
|
expect(fooRecordReply.status.code).toBe(400);
|
|
562
553
|
expect(fooRecordReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
563
554
|
const expectedStatusMsg = `${protocolDefinition.protocol}/foo/$tags/status must be equal to one of the allowed values`;
|
|
@@ -565,7 +556,7 @@ export function testRecordsTags() {
|
|
|
565
556
|
// ensure the correct tag descriptor path is in the error message
|
|
566
557
|
expect(fooRecordReply.status.detail).toContain(`${protocolDefinition.protocol}/foo/$tags/status`);
|
|
567
558
|
// write a foo record with a valid `status` tag value.
|
|
568
|
-
const validFooRecord =
|
|
559
|
+
const validFooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
569
560
|
author: alice,
|
|
570
561
|
published: true,
|
|
571
562
|
protocol: protocolDefinition.protocol,
|
|
@@ -575,11 +566,11 @@ export function testRecordsTags() {
|
|
|
575
566
|
}
|
|
576
567
|
});
|
|
577
568
|
// should pass
|
|
578
|
-
const validFooRecordReply =
|
|
569
|
+
const validFooRecordReply = await dwn.processMessage(alice.did, validFooRecord.message, { dataStream: validFooRecord.dataStream });
|
|
579
570
|
expect(validFooRecordReply.status.code).toBe(202);
|
|
580
|
-
})
|
|
581
|
-
it('should reject a record with a tag value that is not within the `minimum` and `maximum` range', () =>
|
|
582
|
-
const alice =
|
|
571
|
+
});
|
|
572
|
+
it('should reject a record with a tag value that is not within the `minimum` and `maximum` range', async () => {
|
|
573
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
583
574
|
// protocol with minimum and maximum for a number
|
|
584
575
|
const protocolDefinition = {
|
|
585
576
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -600,14 +591,14 @@ export function testRecordsTags() {
|
|
|
600
591
|
},
|
|
601
592
|
};
|
|
602
593
|
// configure tags protocol
|
|
603
|
-
const protocolConfigure =
|
|
594
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
604
595
|
author: alice,
|
|
605
596
|
protocolDefinition,
|
|
606
597
|
});
|
|
607
|
-
const configureReply =
|
|
598
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
608
599
|
expect(configureReply.status.code).toBe(202);
|
|
609
600
|
// write a foo record with an `score` value less than 0.
|
|
610
|
-
const fooRecord =
|
|
601
|
+
const fooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
611
602
|
author: alice,
|
|
612
603
|
published: true,
|
|
613
604
|
protocol: protocolDefinition.protocol,
|
|
@@ -617,12 +608,12 @@ export function testRecordsTags() {
|
|
|
617
608
|
}
|
|
618
609
|
});
|
|
619
610
|
// should fail
|
|
620
|
-
const fooRecordReply =
|
|
611
|
+
const fooRecordReply = await dwn.processMessage(alice.did, fooRecord.message, { dataStream: fooRecord.dataStream });
|
|
621
612
|
expect(fooRecordReply.status.code).toBe(400);
|
|
622
613
|
expect(fooRecordReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
623
614
|
expect(fooRecordReply.status.detail).toContain(`${protocolDefinition.protocol}/foo/$tags/score must be >= 0`);
|
|
624
615
|
// write a foo record with an `score` value greater than 100.
|
|
625
|
-
const fooRecord2 =
|
|
616
|
+
const fooRecord2 = await TestDataGenerator.generateRecordsWrite({
|
|
626
617
|
author: alice,
|
|
627
618
|
published: true,
|
|
628
619
|
protocol: protocolDefinition.protocol,
|
|
@@ -632,12 +623,12 @@ export function testRecordsTags() {
|
|
|
632
623
|
}
|
|
633
624
|
});
|
|
634
625
|
// should fail
|
|
635
|
-
const fooRecord2Reply =
|
|
626
|
+
const fooRecord2Reply = await dwn.processMessage(alice.did, fooRecord2.message, { dataStream: fooRecord2.dataStream });
|
|
636
627
|
expect(fooRecord2Reply.status.code).toBe(400);
|
|
637
628
|
expect(fooRecord2Reply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
638
629
|
expect(fooRecord2Reply.status.detail).toContain(`${protocolDefinition.protocol}/foo/$tags/score must be <= 100`);
|
|
639
630
|
// write a foo record with a maximum `score` of 100.
|
|
640
|
-
const validFooMaxRecord =
|
|
631
|
+
const validFooMaxRecord = await TestDataGenerator.generateRecordsWrite({
|
|
641
632
|
author: alice,
|
|
642
633
|
published: true,
|
|
643
634
|
protocol: protocolDefinition.protocol,
|
|
@@ -647,10 +638,10 @@ export function testRecordsTags() {
|
|
|
647
638
|
}
|
|
648
639
|
});
|
|
649
640
|
// should pass
|
|
650
|
-
const validFooMaxRecordReply =
|
|
641
|
+
const validFooMaxRecordReply = await dwn.processMessage(alice.did, validFooMaxRecord.message, { dataStream: validFooMaxRecord.dataStream });
|
|
651
642
|
expect(validFooMaxRecordReply.status.code).toBe(202);
|
|
652
643
|
// write a foo record with a maximum `score` of 0.
|
|
653
|
-
const validFooMinRecord =
|
|
644
|
+
const validFooMinRecord = await TestDataGenerator.generateRecordsWrite({
|
|
654
645
|
author: alice,
|
|
655
646
|
published: true,
|
|
656
647
|
protocol: protocolDefinition.protocol,
|
|
@@ -660,10 +651,10 @@ export function testRecordsTags() {
|
|
|
660
651
|
}
|
|
661
652
|
});
|
|
662
653
|
// should pass
|
|
663
|
-
const validFooMinRecordReply =
|
|
654
|
+
const validFooMinRecordReply = await dwn.processMessage(alice.did, validFooMinRecord.message, { dataStream: validFooMinRecord.dataStream });
|
|
664
655
|
expect(validFooMinRecordReply.status.code).toBe(202);
|
|
665
656
|
// write a foo record within the range
|
|
666
|
-
const validFooRecord =
|
|
657
|
+
const validFooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
667
658
|
author: alice,
|
|
668
659
|
published: true,
|
|
669
660
|
protocol: protocolDefinition.protocol,
|
|
@@ -673,11 +664,11 @@ export function testRecordsTags() {
|
|
|
673
664
|
}
|
|
674
665
|
});
|
|
675
666
|
// should pass
|
|
676
|
-
const validFooRecordReply =
|
|
667
|
+
const validFooRecordReply = await dwn.processMessage(alice.did, validFooRecord.message, { dataStream: validFooRecord.dataStream });
|
|
677
668
|
expect(validFooRecordReply.status.code).toBe(202);
|
|
678
|
-
})
|
|
679
|
-
it('should reject a record with a tag value that is not within the `exclusiveMinimum` and `exclusiveMaximum` range', () =>
|
|
680
|
-
const alice =
|
|
669
|
+
});
|
|
670
|
+
it('should reject a record with a tag value that is not within the `exclusiveMinimum` and `exclusiveMaximum` range', async () => {
|
|
671
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
681
672
|
// protocol with exclusiveMinimum and exclusiveMaximum for a number
|
|
682
673
|
const protocolDefinition = {
|
|
683
674
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -698,14 +689,14 @@ export function testRecordsTags() {
|
|
|
698
689
|
},
|
|
699
690
|
};
|
|
700
691
|
// configure tags protocol
|
|
701
|
-
const protocolConfigure =
|
|
692
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
702
693
|
author: alice,
|
|
703
694
|
protocolDefinition,
|
|
704
695
|
});
|
|
705
|
-
const configureReply =
|
|
696
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
706
697
|
expect(configureReply.status.code).toBe(202);
|
|
707
698
|
// write a foo record with an hour at the exclusiveMaximum
|
|
708
|
-
const exclusiveMaxRecord =
|
|
699
|
+
const exclusiveMaxRecord = await TestDataGenerator.generateRecordsWrite({
|
|
709
700
|
author: alice,
|
|
710
701
|
published: true,
|
|
711
702
|
protocol: protocolDefinition.protocol,
|
|
@@ -715,12 +706,12 @@ export function testRecordsTags() {
|
|
|
715
706
|
}
|
|
716
707
|
});
|
|
717
708
|
// should fail
|
|
718
|
-
const exclusiveMaxReply =
|
|
709
|
+
const exclusiveMaxReply = await dwn.processMessage(alice.did, exclusiveMaxRecord.message, { dataStream: exclusiveMaxRecord.dataStream });
|
|
719
710
|
expect(exclusiveMaxReply.status.code).toBe(400);
|
|
720
711
|
expect(exclusiveMaxReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
721
712
|
expect(exclusiveMaxReply.status.detail).toContain(`${protocolDefinition.protocol}/foo/$tags/hours must be < 24`);
|
|
722
713
|
// write a foo record with an hour at the exclusiveMinimum
|
|
723
|
-
const exclusiveMinRecord =
|
|
714
|
+
const exclusiveMinRecord = await TestDataGenerator.generateRecordsWrite({
|
|
724
715
|
author: alice,
|
|
725
716
|
published: true,
|
|
726
717
|
protocol: protocolDefinition.protocol,
|
|
@@ -730,12 +721,12 @@ export function testRecordsTags() {
|
|
|
730
721
|
}
|
|
731
722
|
});
|
|
732
723
|
// should fail
|
|
733
|
-
const exclusiveMinReply =
|
|
724
|
+
const exclusiveMinReply = await dwn.processMessage(alice.did, exclusiveMinRecord.message, { dataStream: exclusiveMinRecord.dataStream });
|
|
734
725
|
expect(exclusiveMinReply.status.code).toBe(400);
|
|
735
726
|
expect(exclusiveMinReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
736
727
|
expect(exclusiveMinReply.status.detail).toContain(`${protocolDefinition.protocol}/foo/$tags/hours must be > 0`);
|
|
737
728
|
// write a foo record with an `hour` value within the range.
|
|
738
|
-
const validFooRecord =
|
|
729
|
+
const validFooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
739
730
|
author: alice,
|
|
740
731
|
published: true,
|
|
741
732
|
protocol: protocolDefinition.protocol,
|
|
@@ -745,11 +736,11 @@ export function testRecordsTags() {
|
|
|
745
736
|
}
|
|
746
737
|
});
|
|
747
738
|
// should pass
|
|
748
|
-
const validFooRecordReply =
|
|
739
|
+
const validFooRecordReply = await dwn.processMessage(alice.did, validFooRecord.message, { dataStream: validFooRecord.dataStream });
|
|
749
740
|
expect(validFooRecordReply.status.code).toBe(202);
|
|
750
|
-
})
|
|
751
|
-
it('should reject tag values that are not within the `minLength` and `maxLength` values', () =>
|
|
752
|
-
const alice =
|
|
741
|
+
});
|
|
742
|
+
it('should reject tag values that are not within the `minLength` and `maxLength` values', async () => {
|
|
743
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
753
744
|
// protocol with minLength and maxLength for a string
|
|
754
745
|
const protocolDefinition = {
|
|
755
746
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -770,14 +761,14 @@ export function testRecordsTags() {
|
|
|
770
761
|
},
|
|
771
762
|
};
|
|
772
763
|
// configure tags protocol
|
|
773
|
-
const protocolConfigure =
|
|
764
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
774
765
|
author: alice,
|
|
775
766
|
protocolDefinition,
|
|
776
767
|
});
|
|
777
|
-
const configureReply =
|
|
768
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
778
769
|
expect(configureReply.status.code).toBe(202);
|
|
779
770
|
// write a foo record with a `stringWithLimit` value less than the minimum length
|
|
780
|
-
const minLengthRecord =
|
|
771
|
+
const minLengthRecord = await TestDataGenerator.generateRecordsWrite({
|
|
781
772
|
author: alice,
|
|
782
773
|
published: true,
|
|
783
774
|
protocol: protocolDefinition.protocol,
|
|
@@ -787,13 +778,13 @@ export function testRecordsTags() {
|
|
|
787
778
|
}
|
|
788
779
|
});
|
|
789
780
|
// should fail
|
|
790
|
-
const minLengthReply =
|
|
781
|
+
const minLengthReply = await dwn.processMessage(alice.did, minLengthRecord.message, { dataStream: minLengthRecord.dataStream });
|
|
791
782
|
expect(minLengthReply.status.code).toBe(400);
|
|
792
783
|
expect(minLengthReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
793
784
|
const expectedMinMsg = `${protocolDefinition.protocol}/foo/$tags/stringWithLimit must NOT have fewer than 5 characters`;
|
|
794
785
|
expect(minLengthReply.status.detail).toContain(expectedMinMsg);
|
|
795
786
|
// write a foo record with a `stringWithLimit` value greater than the maximum length
|
|
796
|
-
const maxLengthRecord =
|
|
787
|
+
const maxLengthRecord = await TestDataGenerator.generateRecordsWrite({
|
|
797
788
|
author: alice,
|
|
798
789
|
published: true,
|
|
799
790
|
protocol: protocolDefinition.protocol,
|
|
@@ -803,13 +794,13 @@ export function testRecordsTags() {
|
|
|
803
794
|
}
|
|
804
795
|
});
|
|
805
796
|
// should fail
|
|
806
|
-
const maxLengthReply =
|
|
797
|
+
const maxLengthReply = await dwn.processMessage(alice.did, maxLengthRecord.message, { dataStream: maxLengthRecord.dataStream });
|
|
807
798
|
expect(maxLengthReply.status.code).toBe(400);
|
|
808
799
|
expect(maxLengthReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
809
800
|
const expectedMaxMsg = `${protocolDefinition.protocol}/foo/$tags/stringWithLimit must NOT have more than 10 characters`;
|
|
810
801
|
expect(maxLengthReply.status.detail).toContain(expectedMaxMsg);
|
|
811
802
|
// write a foo record with a `stringWithLimit` value within the range
|
|
812
|
-
const validFooRecord =
|
|
803
|
+
const validFooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
813
804
|
author: alice,
|
|
814
805
|
published: true,
|
|
815
806
|
protocol: protocolDefinition.protocol,
|
|
@@ -819,11 +810,11 @@ export function testRecordsTags() {
|
|
|
819
810
|
}
|
|
820
811
|
});
|
|
821
812
|
// should pass
|
|
822
|
-
const validFooRecordReply =
|
|
813
|
+
const validFooRecordReply = await dwn.processMessage(alice.did, validFooRecord.message, { dataStream: validFooRecord.dataStream });
|
|
823
814
|
expect(validFooRecordReply.status.code).toBe(202);
|
|
824
|
-
})
|
|
825
|
-
it('should reject tag values that do not contain the number of items within the `minItems` and `maxItems` values', () =>
|
|
826
|
-
const alice =
|
|
815
|
+
});
|
|
816
|
+
it('should reject tag values that do not contain the number of items within the `minItems` and `maxItems` values', async () => {
|
|
817
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
827
818
|
// protocol with minItems and maxItems for an array of numbers
|
|
828
819
|
const protocolDefinition = {
|
|
829
820
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -847,14 +838,14 @@ export function testRecordsTags() {
|
|
|
847
838
|
},
|
|
848
839
|
};
|
|
849
840
|
// configure tags protocol
|
|
850
|
-
const protocolConfigure =
|
|
841
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
851
842
|
author: alice,
|
|
852
843
|
protocolDefinition,
|
|
853
844
|
});
|
|
854
|
-
const configureReply =
|
|
845
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
855
846
|
expect(configureReply.status.code).toBe(202);
|
|
856
847
|
// write a foo record with a `numberArray` value with only 1 item, less than the `minItems` specified of 2
|
|
857
|
-
const minLengthRecord =
|
|
848
|
+
const minLengthRecord = await TestDataGenerator.generateRecordsWrite({
|
|
858
849
|
author: alice,
|
|
859
850
|
published: true,
|
|
860
851
|
protocol: protocolDefinition.protocol,
|
|
@@ -864,12 +855,12 @@ export function testRecordsTags() {
|
|
|
864
855
|
}
|
|
865
856
|
});
|
|
866
857
|
// should fail
|
|
867
|
-
const minLengthReply =
|
|
858
|
+
const minLengthReply = await dwn.processMessage(alice.did, minLengthRecord.message, { dataStream: minLengthRecord.dataStream });
|
|
868
859
|
expect(minLengthReply.status.code).toBe(400);
|
|
869
860
|
expect(minLengthReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
870
861
|
expect(minLengthReply.status.detail).toContain(`${protocolDefinition.protocol}/foo/$tags/numberArray must NOT have fewer than 2 items`);
|
|
871
862
|
// write a foo record with a `numberArray` value with 4 items, more than the `maxItems` specified of 3
|
|
872
|
-
const maxLengthRecord =
|
|
863
|
+
const maxLengthRecord = await TestDataGenerator.generateRecordsWrite({
|
|
873
864
|
author: alice,
|
|
874
865
|
published: true,
|
|
875
866
|
protocol: protocolDefinition.protocol,
|
|
@@ -879,12 +870,12 @@ export function testRecordsTags() {
|
|
|
879
870
|
}
|
|
880
871
|
});
|
|
881
872
|
// should fail
|
|
882
|
-
const maxLengthReply =
|
|
873
|
+
const maxLengthReply = await dwn.processMessage(alice.did, maxLengthRecord.message, { dataStream: maxLengthRecord.dataStream });
|
|
883
874
|
expect(maxLengthReply.status.code).toBe(400);
|
|
884
875
|
expect(maxLengthReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
885
876
|
expect(maxLengthReply.status.detail).toContain(`${protocolDefinition.protocol}/foo/$tags/numberArray must NOT have more than 3 items`);
|
|
886
877
|
// write a foo record with a `numberArray` value with 3 items, within the range
|
|
887
|
-
const validFooRecord =
|
|
878
|
+
const validFooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
888
879
|
author: alice,
|
|
889
880
|
published: true,
|
|
890
881
|
protocol: protocolDefinition.protocol,
|
|
@@ -894,11 +885,11 @@ export function testRecordsTags() {
|
|
|
894
885
|
}
|
|
895
886
|
});
|
|
896
887
|
// should pass
|
|
897
|
-
const validFooRecordReply =
|
|
888
|
+
const validFooRecordReply = await dwn.processMessage(alice.did, validFooRecord.message, { dataStream: validFooRecord.dataStream });
|
|
898
889
|
expect(validFooRecordReply.status.code).toBe(202);
|
|
899
|
-
})
|
|
900
|
-
it('should reject a value within an array that should only include numbers', () =>
|
|
901
|
-
const alice =
|
|
890
|
+
});
|
|
891
|
+
it('should reject a value within an array that should only include numbers', async () => {
|
|
892
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
902
893
|
// protocol with an array of numbers
|
|
903
894
|
const protocolDefinition = {
|
|
904
895
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -920,14 +911,14 @@ export function testRecordsTags() {
|
|
|
920
911
|
},
|
|
921
912
|
};
|
|
922
913
|
// configure tags protocol
|
|
923
|
-
const protocolConfigure =
|
|
914
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
924
915
|
author: alice,
|
|
925
916
|
protocolDefinition
|
|
926
917
|
});
|
|
927
|
-
const configureReply =
|
|
918
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
928
919
|
expect(configureReply.status.code).toBe(202);
|
|
929
920
|
// write a foo record with a `numberArray` value with a string
|
|
930
|
-
const fooRecord =
|
|
921
|
+
const fooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
931
922
|
author: alice,
|
|
932
923
|
published: true,
|
|
933
924
|
protocol: protocolDefinition.protocol,
|
|
@@ -937,12 +928,12 @@ export function testRecordsTags() {
|
|
|
937
928
|
}
|
|
938
929
|
});
|
|
939
930
|
// should fail
|
|
940
|
-
const fooRecordReply =
|
|
931
|
+
const fooRecordReply = await dwn.processMessage(alice.did, fooRecord.message, { dataStream: fooRecord.dataStream });
|
|
941
932
|
expect(fooRecordReply.status.code).toBe(400);
|
|
942
933
|
expect(fooRecordReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
943
934
|
expect(fooRecordReply.status.detail).toContain(`${protocolDefinition.protocol}/foo/$tags/numberArray/0 must be number`);
|
|
944
935
|
// write a foo record with a `numberArray` value with a number (both integer and decimal)
|
|
945
|
-
const validFooRecord =
|
|
936
|
+
const validFooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
946
937
|
author: alice,
|
|
947
938
|
published: true,
|
|
948
939
|
protocol: protocolDefinition.protocol,
|
|
@@ -952,11 +943,11 @@ export function testRecordsTags() {
|
|
|
952
943
|
}
|
|
953
944
|
});
|
|
954
945
|
// should pass
|
|
955
|
-
const validFooRecordReply =
|
|
946
|
+
const validFooRecordReply = await dwn.processMessage(alice.did, validFooRecord.message, { dataStream: validFooRecord.dataStream });
|
|
956
947
|
expect(validFooRecordReply.status.code).toBe(202);
|
|
957
|
-
})
|
|
958
|
-
it('should reject a value within an array that should only include integers', () =>
|
|
959
|
-
const alice =
|
|
948
|
+
});
|
|
949
|
+
it('should reject a value within an array that should only include integers', async () => {
|
|
950
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
960
951
|
// protocol with an array of numbers
|
|
961
952
|
const protocolDefinition = {
|
|
962
953
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -978,14 +969,14 @@ export function testRecordsTags() {
|
|
|
978
969
|
},
|
|
979
970
|
};
|
|
980
971
|
// configure tags protocol
|
|
981
|
-
const protocolConfigure =
|
|
972
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
982
973
|
author: alice,
|
|
983
974
|
protocolDefinition
|
|
984
975
|
});
|
|
985
|
-
const configureReply =
|
|
976
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
986
977
|
expect(configureReply.status.code).toBe(202);
|
|
987
978
|
// write a foo record with a `numberArray` value with a decimal
|
|
988
|
-
const fooRecord =
|
|
979
|
+
const fooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
989
980
|
author: alice,
|
|
990
981
|
published: true,
|
|
991
982
|
protocol: protocolDefinition.protocol,
|
|
@@ -995,12 +986,12 @@ export function testRecordsTags() {
|
|
|
995
986
|
}
|
|
996
987
|
});
|
|
997
988
|
// should fail
|
|
998
|
-
const fooRecordReply =
|
|
989
|
+
const fooRecordReply = await dwn.processMessage(alice.did, fooRecord.message, { dataStream: fooRecord.dataStream });
|
|
999
990
|
expect(fooRecordReply.status.code).toBe(400);
|
|
1000
991
|
expect(fooRecordReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
1001
992
|
expect(fooRecordReply.status.detail).toContain(`${protocolDefinition.protocol}/foo/$tags/numberArray/1 must be integer`);
|
|
1002
993
|
// write a foo record with a `numberArray` value with values of integers
|
|
1003
|
-
const validFooRecord =
|
|
994
|
+
const validFooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1004
995
|
author: alice,
|
|
1005
996
|
published: true,
|
|
1006
997
|
protocol: protocolDefinition.protocol,
|
|
@@ -1010,11 +1001,11 @@ export function testRecordsTags() {
|
|
|
1010
1001
|
}
|
|
1011
1002
|
});
|
|
1012
1003
|
// should pass
|
|
1013
|
-
const validFooRecordReply =
|
|
1004
|
+
const validFooRecordReply = await dwn.processMessage(alice.did, validFooRecord.message, { dataStream: validFooRecord.dataStream });
|
|
1014
1005
|
expect(validFooRecordReply.status.code).toBe(202);
|
|
1015
|
-
})
|
|
1016
|
-
it('should reject tag values that do not contain the number of items within the `minContains` and `maxContains` values', () =>
|
|
1017
|
-
const alice =
|
|
1006
|
+
});
|
|
1007
|
+
it('should reject tag values that do not contain the number of items within the `minContains` and `maxContains` values', async () => {
|
|
1008
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1018
1009
|
// protocol with minContains and maxContains for an array of numbers
|
|
1019
1010
|
const protocolDefinition = {
|
|
1020
1011
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -1043,15 +1034,15 @@ export function testRecordsTags() {
|
|
|
1043
1034
|
},
|
|
1044
1035
|
};
|
|
1045
1036
|
// configure tags protocol
|
|
1046
|
-
const protocolConfigure =
|
|
1037
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
1047
1038
|
author: alice,
|
|
1048
1039
|
protocolDefinition,
|
|
1049
1040
|
});
|
|
1050
|
-
const configureReply =
|
|
1041
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
1051
1042
|
expect(configureReply.status.code).toBe(202);
|
|
1052
1043
|
// write a foo record with a `numberArray` value with only 1 item that matches contains contraint, less than the `minContains` of 2
|
|
1053
1044
|
// but additional items that would equal more than 2 items
|
|
1054
|
-
const minLengthRecord =
|
|
1045
|
+
const minLengthRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1055
1046
|
author: alice,
|
|
1056
1047
|
published: true,
|
|
1057
1048
|
protocol: protocolDefinition.protocol,
|
|
@@ -1061,13 +1052,13 @@ export function testRecordsTags() {
|
|
|
1061
1052
|
}
|
|
1062
1053
|
});
|
|
1063
1054
|
// should fail
|
|
1064
|
-
const minLengthReply =
|
|
1055
|
+
const minLengthReply = await dwn.processMessage(alice.did, minLengthRecord.message, { dataStream: minLengthRecord.dataStream });
|
|
1065
1056
|
expect(minLengthReply.status.code).toBe(400);
|
|
1066
1057
|
expect(minLengthReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
1067
1058
|
expect(minLengthReply.status.detail)
|
|
1068
1059
|
.toContain(`${protocolDefinition.protocol}/foo/$tags/numberArray must contain at least 2 and no more than 4 valid item(s)`);
|
|
1069
1060
|
// write a foo record with a `numberArray` value with 4 items, more than the `maxItems` specified of 3
|
|
1070
|
-
const maxLengthRecord =
|
|
1061
|
+
const maxLengthRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1071
1062
|
author: alice,
|
|
1072
1063
|
published: true,
|
|
1073
1064
|
protocol: protocolDefinition.protocol,
|
|
@@ -1077,13 +1068,13 @@ export function testRecordsTags() {
|
|
|
1077
1068
|
}
|
|
1078
1069
|
});
|
|
1079
1070
|
// should fail
|
|
1080
|
-
const maxLengthReply =
|
|
1071
|
+
const maxLengthReply = await dwn.processMessage(alice.did, maxLengthRecord.message, { dataStream: maxLengthRecord.dataStream });
|
|
1081
1072
|
expect(maxLengthReply.status.code).toBe(400);
|
|
1082
1073
|
expect(maxLengthReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
1083
1074
|
expect(maxLengthReply.status.detail)
|
|
1084
1075
|
.toContain(`${protocolDefinition.protocol}/foo/$tags/numberArray must contain at least 2 and no more than 4 valid item(s)`);
|
|
1085
1076
|
// write a foo record with a `numberArray` value with 3 items, within the range
|
|
1086
|
-
const validFooRecord =
|
|
1077
|
+
const validFooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1087
1078
|
author: alice,
|
|
1088
1079
|
published: true,
|
|
1089
1080
|
protocol: protocolDefinition.protocol,
|
|
@@ -1093,11 +1084,11 @@ export function testRecordsTags() {
|
|
|
1093
1084
|
}
|
|
1094
1085
|
});
|
|
1095
1086
|
// should pass
|
|
1096
|
-
const validFooRecordReply =
|
|
1087
|
+
const validFooRecordReply = await dwn.processMessage(alice.did, validFooRecord.message, { dataStream: validFooRecord.dataStream });
|
|
1097
1088
|
expect(validFooRecordReply.status.code).toBe(202);
|
|
1098
|
-
})
|
|
1099
|
-
it('should reject tag values that do not follow the constraints of the `uniqueItems` value', () =>
|
|
1100
|
-
const alice =
|
|
1089
|
+
});
|
|
1090
|
+
it('should reject tag values that do not follow the constraints of the `uniqueItems` value', async () => {
|
|
1091
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1101
1092
|
// protocol with uniqueItems for an array of strings
|
|
1102
1093
|
const protocolDefinition = {
|
|
1103
1094
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -1120,14 +1111,14 @@ export function testRecordsTags() {
|
|
|
1120
1111
|
},
|
|
1121
1112
|
};
|
|
1122
1113
|
// configure tags protocol
|
|
1123
|
-
const protocolConfigure =
|
|
1114
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
1124
1115
|
author: alice,
|
|
1125
1116
|
protocolDefinition,
|
|
1126
1117
|
});
|
|
1127
|
-
const configureReply =
|
|
1118
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
1128
1119
|
expect(configureReply.status.code).toBe(202);
|
|
1129
1120
|
// write a foo record with a `uniqueStrings` value with duplicate items
|
|
1130
|
-
const duplicateItemsRecord =
|
|
1121
|
+
const duplicateItemsRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1131
1122
|
author: alice,
|
|
1132
1123
|
published: true,
|
|
1133
1124
|
protocol: protocolDefinition.protocol,
|
|
@@ -1137,10 +1128,10 @@ export function testRecordsTags() {
|
|
|
1137
1128
|
}
|
|
1138
1129
|
});
|
|
1139
1130
|
// should fail
|
|
1140
|
-
const duplicateItemsReply =
|
|
1131
|
+
const duplicateItemsReply = await dwn.processMessage(alice.did, duplicateItemsRecord.message, { dataStream: duplicateItemsRecord.dataStream });
|
|
1141
1132
|
expect(duplicateItemsReply.status.code).toBe(400);
|
|
1142
1133
|
// write a foo record with a `uniqueStrings` value with unique items
|
|
1143
|
-
const uniqueItemsRecord =
|
|
1134
|
+
const uniqueItemsRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1144
1135
|
author: alice,
|
|
1145
1136
|
published: true,
|
|
1146
1137
|
protocol: protocolDefinition.protocol,
|
|
@@ -1150,11 +1141,11 @@ export function testRecordsTags() {
|
|
|
1150
1141
|
}
|
|
1151
1142
|
});
|
|
1152
1143
|
// should pass
|
|
1153
|
-
const uniqueItemsReply =
|
|
1144
|
+
const uniqueItemsReply = await dwn.processMessage(alice.did, uniqueItemsRecord.message, { dataStream: uniqueItemsRecord.dataStream });
|
|
1154
1145
|
expect(uniqueItemsReply.status.code).toBe(202);
|
|
1155
|
-
})
|
|
1156
|
-
it('should only accept a record containing tags required by $requiredTags', () =>
|
|
1157
|
-
const alice =
|
|
1146
|
+
});
|
|
1147
|
+
it('should only accept a record containing tags required by $requiredTags', async () => {
|
|
1148
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1158
1149
|
// protocol with a required tag
|
|
1159
1150
|
const protocolDefinition = {
|
|
1160
1151
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -1174,25 +1165,25 @@ export function testRecordsTags() {
|
|
|
1174
1165
|
},
|
|
1175
1166
|
};
|
|
1176
1167
|
// configure tags protocol
|
|
1177
|
-
const protocolConfigure =
|
|
1168
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
1178
1169
|
author: alice,
|
|
1179
1170
|
protocolDefinition,
|
|
1180
1171
|
});
|
|
1181
|
-
const configureReply =
|
|
1172
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
1182
1173
|
expect(configureReply.status.code).toBe(202);
|
|
1183
1174
|
// write a foo record without the required tag
|
|
1184
|
-
const fooRecord =
|
|
1175
|
+
const fooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1185
1176
|
author: alice,
|
|
1186
1177
|
published: true,
|
|
1187
1178
|
protocol: protocolDefinition.protocol,
|
|
1188
1179
|
protocolPath: 'foo',
|
|
1189
1180
|
});
|
|
1190
|
-
const fooRecordReply =
|
|
1181
|
+
const fooRecordReply = await dwn.processMessage(alice.did, fooRecord.message, { dataStream: fooRecord.dataStream });
|
|
1191
1182
|
expect(fooRecordReply.status.code).toBe(400);
|
|
1192
1183
|
expect(fooRecordReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
1193
1184
|
expect(fooRecordReply.status.detail).toContain(`${protocolDefinition.protocol}/foo/$tags must have required property 'someRequiredTag'`);
|
|
1194
1185
|
// write a foo record with the required tag
|
|
1195
|
-
const validFooRecord =
|
|
1186
|
+
const validFooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1196
1187
|
author: alice,
|
|
1197
1188
|
published: true,
|
|
1198
1189
|
protocol: protocolDefinition.protocol,
|
|
@@ -1202,11 +1193,11 @@ export function testRecordsTags() {
|
|
|
1202
1193
|
}
|
|
1203
1194
|
});
|
|
1204
1195
|
// should pass
|
|
1205
|
-
const validFooRecordReply =
|
|
1196
|
+
const validFooRecordReply = await dwn.processMessage(alice.did, validFooRecord.message, { dataStream: validFooRecord.dataStream });
|
|
1206
1197
|
expect(validFooRecordReply.status.code).toBe(202);
|
|
1207
|
-
})
|
|
1208
|
-
it('should accept any tag if $allowUndefinedTags is set to true', () =>
|
|
1209
|
-
const alice =
|
|
1198
|
+
});
|
|
1199
|
+
it('should accept any tag if $allowUndefinedTags is set to true', async () => {
|
|
1200
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1210
1201
|
// protocol with no required tags
|
|
1211
1202
|
const protocolDefinition = {
|
|
1212
1203
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -1226,14 +1217,14 @@ export function testRecordsTags() {
|
|
|
1226
1217
|
},
|
|
1227
1218
|
};
|
|
1228
1219
|
// configure tags protocol
|
|
1229
|
-
const protocolConfigure =
|
|
1220
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
1230
1221
|
author: alice,
|
|
1231
1222
|
protocolDefinition,
|
|
1232
1223
|
});
|
|
1233
|
-
const configureReply =
|
|
1224
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
1234
1225
|
expect(configureReply.status.code).toBe(202);
|
|
1235
1226
|
// write a foo record without the required tag
|
|
1236
|
-
const fooRecord =
|
|
1227
|
+
const fooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1237
1228
|
author: alice,
|
|
1238
1229
|
published: true,
|
|
1239
1230
|
protocol: protocolDefinition.protocol,
|
|
@@ -1242,12 +1233,12 @@ export function testRecordsTags() {
|
|
|
1242
1233
|
randomTag: 'some-value'
|
|
1243
1234
|
}
|
|
1244
1235
|
});
|
|
1245
|
-
const fooRecordReply =
|
|
1236
|
+
const fooRecordReply = await dwn.processMessage(alice.did, fooRecord.message, { dataStream: fooRecord.dataStream });
|
|
1246
1237
|
expect(fooRecordReply.status.code).toBe(202);
|
|
1247
|
-
})
|
|
1238
|
+
});
|
|
1248
1239
|
describe('contains', () => {
|
|
1249
|
-
it('should reject a record tag that does not contain a value specified within the `enum` definition', () =>
|
|
1250
|
-
const alice =
|
|
1240
|
+
it('should reject a record tag that does not contain a value specified within the `enum` definition', async () => {
|
|
1241
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1251
1242
|
// protocol with `enum` definition within `contains`
|
|
1252
1243
|
const protocolDefinition = {
|
|
1253
1244
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -1273,14 +1264,14 @@ export function testRecordsTags() {
|
|
|
1273
1264
|
},
|
|
1274
1265
|
};
|
|
1275
1266
|
// configure tags protocol
|
|
1276
|
-
const protocolConfigure =
|
|
1267
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
1277
1268
|
author: alice,
|
|
1278
1269
|
protocolDefinition,
|
|
1279
1270
|
});
|
|
1280
|
-
const configureReply =
|
|
1271
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
1281
1272
|
expect(configureReply.status.code).toBe(202);
|
|
1282
1273
|
// write a foo record with a `status` value that is not represented in the `enum`
|
|
1283
|
-
const invalidEnumRecord =
|
|
1274
|
+
const invalidEnumRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1284
1275
|
author: alice,
|
|
1285
1276
|
published: true,
|
|
1286
1277
|
protocol: protocolDefinition.protocol,
|
|
@@ -1290,13 +1281,13 @@ export function testRecordsTags() {
|
|
|
1290
1281
|
}
|
|
1291
1282
|
});
|
|
1292
1283
|
// should fail
|
|
1293
|
-
const invalidEnumReply =
|
|
1284
|
+
const invalidEnumReply = await dwn.processMessage(alice.did, invalidEnumRecord.message, { dataStream: invalidEnumRecord.dataStream });
|
|
1294
1285
|
expect(invalidEnumReply.status.code).toBe(400);
|
|
1295
1286
|
expect(invalidEnumReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
1296
1287
|
expect(invalidEnumReply.status.detail)
|
|
1297
1288
|
.toContain(`${protocolDefinition.protocol}/foo/$tags/status must contain at least 1 valid item(s)`);
|
|
1298
1289
|
// write a foo record that now adds a valid `status` value to the array
|
|
1299
|
-
const validEnumRecord =
|
|
1290
|
+
const validEnumRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1300
1291
|
author: alice,
|
|
1301
1292
|
published: true,
|
|
1302
1293
|
protocol: protocolDefinition.protocol,
|
|
@@ -1306,11 +1297,11 @@ export function testRecordsTags() {
|
|
|
1306
1297
|
}
|
|
1307
1298
|
});
|
|
1308
1299
|
// should pass
|
|
1309
|
-
const validEnumReply =
|
|
1300
|
+
const validEnumReply = await dwn.processMessage(alice.did, validEnumRecord.message, { dataStream: validEnumRecord.dataStream });
|
|
1310
1301
|
expect(validEnumReply.status.code).toBe(202);
|
|
1311
|
-
})
|
|
1312
|
-
it('should reject a record tag that does not contain a value within the `minimum` and `maximum` range ', () =>
|
|
1313
|
-
const alice =
|
|
1302
|
+
});
|
|
1303
|
+
it('should reject a record tag that does not contain a value within the `minimum` and `maximum` range ', async () => {
|
|
1304
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1314
1305
|
// protocol with `minimum` and `maximum` definitions within `contains`
|
|
1315
1306
|
const protocolDefinition = {
|
|
1316
1307
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -1337,14 +1328,14 @@ export function testRecordsTags() {
|
|
|
1337
1328
|
},
|
|
1338
1329
|
};
|
|
1339
1330
|
// configure tags protocol
|
|
1340
|
-
const protocolConfigure =
|
|
1331
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
1341
1332
|
author: alice,
|
|
1342
1333
|
protocolDefinition,
|
|
1343
1334
|
});
|
|
1344
|
-
const configureReply =
|
|
1335
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
1345
1336
|
expect(configureReply.status.code).toBe(202);
|
|
1346
1337
|
// write a foo record with a `containsNumbers` value that does not have a number within the range
|
|
1347
|
-
const minContainsRecord =
|
|
1338
|
+
const minContainsRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1348
1339
|
author: alice,
|
|
1349
1340
|
published: true,
|
|
1350
1341
|
protocol: protocolDefinition.protocol,
|
|
@@ -1354,13 +1345,13 @@ export function testRecordsTags() {
|
|
|
1354
1345
|
}
|
|
1355
1346
|
});
|
|
1356
1347
|
// should fail
|
|
1357
|
-
const minContainsReply =
|
|
1348
|
+
const minContainsReply = await dwn.processMessage(alice.did, minContainsRecord.message, { dataStream: minContainsRecord.dataStream });
|
|
1358
1349
|
expect(minContainsReply.status.code).toBe(400);
|
|
1359
1350
|
expect(minContainsReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
1360
1351
|
expect(minContainsReply.status.detail)
|
|
1361
1352
|
.toContain(`${protocolDefinition.protocol}/foo/$tags/containsNumbers must contain at least 1 valid item(s)`);
|
|
1362
1353
|
// write a foo record with a `containsNumbers` value that has a number within the range
|
|
1363
|
-
const validFooRecord =
|
|
1354
|
+
const validFooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1364
1355
|
author: alice,
|
|
1365
1356
|
published: true,
|
|
1366
1357
|
protocol: protocolDefinition.protocol,
|
|
@@ -1370,11 +1361,11 @@ export function testRecordsTags() {
|
|
|
1370
1361
|
}
|
|
1371
1362
|
});
|
|
1372
1363
|
// should pass
|
|
1373
|
-
const validFooRecordReply =
|
|
1364
|
+
const validFooRecordReply = await dwn.processMessage(alice.did, validFooRecord.message, { dataStream: validFooRecord.dataStream });
|
|
1374
1365
|
expect(validFooRecordReply.status.code).toBe(202);
|
|
1375
|
-
})
|
|
1376
|
-
it('should reject a record tag that does not contain a value within the `exclusiveMinimum` and `exclusiveMaximum` range ', () =>
|
|
1377
|
-
const alice =
|
|
1366
|
+
});
|
|
1367
|
+
it('should reject a record tag that does not contain a value within the `exclusiveMinimum` and `exclusiveMaximum` range ', async () => {
|
|
1368
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1378
1369
|
// protocol with `minimum` and `maximum` definitions within `contains`
|
|
1379
1370
|
const protocolDefinition = {
|
|
1380
1371
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -1401,14 +1392,14 @@ export function testRecordsTags() {
|
|
|
1401
1392
|
},
|
|
1402
1393
|
};
|
|
1403
1394
|
// configure tags protocol
|
|
1404
|
-
const protocolConfigure =
|
|
1395
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
1405
1396
|
author: alice,
|
|
1406
1397
|
protocolDefinition,
|
|
1407
1398
|
});
|
|
1408
|
-
const configureReply =
|
|
1399
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
1409
1400
|
expect(configureReply.status.code).toBe(202);
|
|
1410
1401
|
// write a foo record with a `containsNumbers` value that does not have a number within the range
|
|
1411
|
-
const minContainsRecord =
|
|
1402
|
+
const minContainsRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1412
1403
|
author: alice,
|
|
1413
1404
|
published: true,
|
|
1414
1405
|
protocol: protocolDefinition.protocol,
|
|
@@ -1418,13 +1409,13 @@ export function testRecordsTags() {
|
|
|
1418
1409
|
}
|
|
1419
1410
|
});
|
|
1420
1411
|
// should fail
|
|
1421
|
-
const minContainsReply =
|
|
1412
|
+
const minContainsReply = await dwn.processMessage(alice.did, minContainsRecord.message, { dataStream: minContainsRecord.dataStream });
|
|
1422
1413
|
expect(minContainsReply.status.code).toBe(400);
|
|
1423
1414
|
expect(minContainsReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
1424
1415
|
expect(minContainsReply.status.detail)
|
|
1425
1416
|
.toContain(`${protocolDefinition.protocol}/foo/$tags/containsNumbers must contain at least 1 valid item(s)`);
|
|
1426
1417
|
// write a foo record with a `containsNumbers` value that has a number within the range
|
|
1427
|
-
const validFooRecord =
|
|
1418
|
+
const validFooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1428
1419
|
author: alice,
|
|
1429
1420
|
published: true,
|
|
1430
1421
|
protocol: protocolDefinition.protocol,
|
|
@@ -1434,11 +1425,11 @@ export function testRecordsTags() {
|
|
|
1434
1425
|
}
|
|
1435
1426
|
});
|
|
1436
1427
|
// should pass
|
|
1437
|
-
const validFooRecordReply =
|
|
1428
|
+
const validFooRecordReply = await dwn.processMessage(alice.did, validFooRecord.message, { dataStream: validFooRecord.dataStream });
|
|
1438
1429
|
expect(validFooRecordReply.status.code).toBe(202);
|
|
1439
|
-
})
|
|
1440
|
-
it('should reject a record tag that does not contain a value within the `minLength` and `maxLength` range ', () =>
|
|
1441
|
-
const alice =
|
|
1430
|
+
});
|
|
1431
|
+
it('should reject a record tag that does not contain a value within the `minLength` and `maxLength` range ', async () => {
|
|
1432
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1442
1433
|
// protocol with `minLength` and `maxLength` definitions within `contains`
|
|
1443
1434
|
const protocolDefinition = {
|
|
1444
1435
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -1465,14 +1456,14 @@ export function testRecordsTags() {
|
|
|
1465
1456
|
},
|
|
1466
1457
|
};
|
|
1467
1458
|
// configure tags protocol
|
|
1468
|
-
const protocolConfigure =
|
|
1459
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
1469
1460
|
author: alice,
|
|
1470
1461
|
protocolDefinition,
|
|
1471
1462
|
});
|
|
1472
|
-
const configureReply =
|
|
1463
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
1473
1464
|
expect(configureReply.status.code).toBe(202);
|
|
1474
1465
|
// write a foo record with a `firstName` value that does not have a string within the range
|
|
1475
|
-
const minContainsRecord =
|
|
1466
|
+
const minContainsRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1476
1467
|
author: alice,
|
|
1477
1468
|
published: true,
|
|
1478
1469
|
protocol: protocolDefinition.protocol,
|
|
@@ -1482,13 +1473,13 @@ export function testRecordsTags() {
|
|
|
1482
1473
|
}
|
|
1483
1474
|
});
|
|
1484
1475
|
// should fail
|
|
1485
|
-
const minContainsReply =
|
|
1476
|
+
const minContainsReply = await dwn.processMessage(alice.did, minContainsRecord.message, { dataStream: minContainsRecord.dataStream });
|
|
1486
1477
|
expect(minContainsReply.status.code).toBe(400);
|
|
1487
1478
|
expect(minContainsReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
1488
1479
|
const expectedContainsMsg = `${protocolDefinition.protocol}/foo/$tags/nickNames must contain at least 1 valid item(s)`;
|
|
1489
1480
|
expect(minContainsReply.status.detail).toContain(expectedContainsMsg);
|
|
1490
1481
|
// write a foo record with a `nickNames` value that has a string within the range
|
|
1491
|
-
const validFooRecord =
|
|
1482
|
+
const validFooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1492
1483
|
author: alice,
|
|
1493
1484
|
published: true,
|
|
1494
1485
|
protocol: protocolDefinition.protocol,
|
|
@@ -1498,13 +1489,13 @@ export function testRecordsTags() {
|
|
|
1498
1489
|
}
|
|
1499
1490
|
});
|
|
1500
1491
|
// should pass
|
|
1501
|
-
const validFooRecordReply =
|
|
1492
|
+
const validFooRecordReply = await dwn.processMessage(alice.did, validFooRecord.message, { dataStream: validFooRecord.dataStream });
|
|
1502
1493
|
expect(validFooRecordReply.status.code).toBe(202);
|
|
1503
|
-
})
|
|
1494
|
+
});
|
|
1504
1495
|
});
|
|
1505
1496
|
describe('items', () => {
|
|
1506
|
-
it('should reject a record tag that includes a value not specified within the `enum` definition', () =>
|
|
1507
|
-
const alice =
|
|
1497
|
+
it('should reject a record tag that includes a value not specified within the `enum` definition', async () => {
|
|
1498
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1508
1499
|
// protocol with `enum` definition within `items`
|
|
1509
1500
|
const protocolDefinition = {
|
|
1510
1501
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -1527,14 +1518,14 @@ export function testRecordsTags() {
|
|
|
1527
1518
|
},
|
|
1528
1519
|
};
|
|
1529
1520
|
// configure tags protocol
|
|
1530
|
-
const protocolConfigure =
|
|
1521
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
1531
1522
|
author: alice,
|
|
1532
1523
|
protocolDefinition,
|
|
1533
1524
|
});
|
|
1534
|
-
const configureReply =
|
|
1525
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
1535
1526
|
expect(configureReply.status.code).toBe(202);
|
|
1536
1527
|
// write a foo record with a `status` value that is not represented in the `enum`
|
|
1537
|
-
const invalidEnumRecord =
|
|
1528
|
+
const invalidEnumRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1538
1529
|
author: alice,
|
|
1539
1530
|
published: true,
|
|
1540
1531
|
protocol: protocolDefinition.protocol,
|
|
@@ -1544,13 +1535,13 @@ export function testRecordsTags() {
|
|
|
1544
1535
|
}
|
|
1545
1536
|
});
|
|
1546
1537
|
// should fail
|
|
1547
|
-
const invalidEnumReply =
|
|
1538
|
+
const invalidEnumReply = await dwn.processMessage(alice.did, invalidEnumRecord.message, { dataStream: invalidEnumRecord.dataStream });
|
|
1548
1539
|
expect(invalidEnumReply.status.code).toBe(400);
|
|
1549
1540
|
expect(invalidEnumReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
1550
1541
|
expect(invalidEnumReply.status.detail)
|
|
1551
1542
|
.toContain(`${protocolDefinition.protocol}/foo/$tags/status/1 must be equal to one of the allowed values`);
|
|
1552
1543
|
// write a foo record that now includes only valid `status` values
|
|
1553
|
-
const validEnumRecord =
|
|
1544
|
+
const validEnumRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1554
1545
|
author: alice,
|
|
1555
1546
|
published: true,
|
|
1556
1547
|
protocol: protocolDefinition.protocol,
|
|
@@ -1560,11 +1551,11 @@ export function testRecordsTags() {
|
|
|
1560
1551
|
}
|
|
1561
1552
|
});
|
|
1562
1553
|
// should pass
|
|
1563
|
-
const validEnumReply =
|
|
1554
|
+
const validEnumReply = await dwn.processMessage(alice.did, validEnumRecord.message, { dataStream: validEnumRecord.dataStream });
|
|
1564
1555
|
expect(validEnumReply.status.code).toBe(202);
|
|
1565
|
-
})
|
|
1566
|
-
it('should reject a record tag which all items do not have a value within the `minimum` and `maximum` range ', () =>
|
|
1567
|
-
const alice =
|
|
1556
|
+
});
|
|
1557
|
+
it('should reject a record tag which all items do not have a value within the `minimum` and `maximum` range ', async () => {
|
|
1558
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1568
1559
|
// protocol with minContains and maxContains for an array of numbers
|
|
1569
1560
|
const protocolDefinition = {
|
|
1570
1561
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -1588,14 +1579,14 @@ export function testRecordsTags() {
|
|
|
1588
1579
|
},
|
|
1589
1580
|
};
|
|
1590
1581
|
// configure tags protocol
|
|
1591
|
-
const protocolConfigure =
|
|
1582
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
1592
1583
|
author: alice,
|
|
1593
1584
|
protocolDefinition,
|
|
1594
1585
|
});
|
|
1595
|
-
const configureReply =
|
|
1586
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
1596
1587
|
expect(configureReply.status.code).toBe(202);
|
|
1597
1588
|
// write a foo record with a `numbers` value that is less than the minimum
|
|
1598
|
-
const minItemssRecord =
|
|
1589
|
+
const minItemssRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1599
1590
|
author: alice,
|
|
1600
1591
|
published: true,
|
|
1601
1592
|
protocol: protocolDefinition.protocol,
|
|
@@ -1605,13 +1596,13 @@ export function testRecordsTags() {
|
|
|
1605
1596
|
}
|
|
1606
1597
|
});
|
|
1607
1598
|
// should fail
|
|
1608
|
-
const minItemsReply =
|
|
1599
|
+
const minItemsReply = await dwn.processMessage(alice.did, minItemssRecord.message, { dataStream: minItemssRecord.dataStream });
|
|
1609
1600
|
expect(minItemsReply.status.code).toBe(400);
|
|
1610
1601
|
expect(minItemsReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
1611
1602
|
expect(minItemsReply.status.detail)
|
|
1612
1603
|
.toContain(`${protocolDefinition.protocol}/foo/$tags/numbers/0 must be >= 80`);
|
|
1613
1604
|
// write a foo record with a `numbers` value that is more than the maximum
|
|
1614
|
-
const maxItemssRecord =
|
|
1605
|
+
const maxItemssRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1615
1606
|
author: alice,
|
|
1616
1607
|
published: true,
|
|
1617
1608
|
protocol: protocolDefinition.protocol,
|
|
@@ -1621,13 +1612,13 @@ export function testRecordsTags() {
|
|
|
1621
1612
|
}
|
|
1622
1613
|
});
|
|
1623
1614
|
// should fail
|
|
1624
|
-
const maxItemsReply =
|
|
1615
|
+
const maxItemsReply = await dwn.processMessage(alice.did, maxItemssRecord.message, { dataStream: maxItemssRecord.dataStream });
|
|
1625
1616
|
expect(maxItemsReply.status.code).toBe(400);
|
|
1626
1617
|
expect(maxItemsReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
1627
1618
|
expect(maxItemsReply.status.detail)
|
|
1628
1619
|
.toContain(`${protocolDefinition.protocol}/foo/$tags/numbers/1 must be <= 100`);
|
|
1629
1620
|
// write a foo record with a `numbers` value that are within the range
|
|
1630
|
-
const validFooRecord =
|
|
1621
|
+
const validFooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1631
1622
|
author: alice,
|
|
1632
1623
|
published: true,
|
|
1633
1624
|
protocol: protocolDefinition.protocol,
|
|
@@ -1637,11 +1628,11 @@ export function testRecordsTags() {
|
|
|
1637
1628
|
}
|
|
1638
1629
|
});
|
|
1639
1630
|
// should pass
|
|
1640
|
-
const validFooRecordReply =
|
|
1631
|
+
const validFooRecordReply = await dwn.processMessage(alice.did, validFooRecord.message, { dataStream: validFooRecord.dataStream });
|
|
1641
1632
|
expect(validFooRecordReply.status.code).toBe(202);
|
|
1642
|
-
})
|
|
1643
|
-
it('should reject a record tag which all items do not have a value within the `exclusiveMinimum` and `exclusiveMaximum` range ', () =>
|
|
1644
|
-
const alice =
|
|
1633
|
+
});
|
|
1634
|
+
it('should reject a record tag which all items do not have a value within the `exclusiveMinimum` and `exclusiveMaximum` range ', async () => {
|
|
1635
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1645
1636
|
// protocol with minContains and maxContains for an array of numbers
|
|
1646
1637
|
const protocolDefinition = {
|
|
1647
1638
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -1665,14 +1656,14 @@ export function testRecordsTags() {
|
|
|
1665
1656
|
},
|
|
1666
1657
|
};
|
|
1667
1658
|
// configure tags protocol
|
|
1668
|
-
const protocolConfigure =
|
|
1659
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
1669
1660
|
author: alice,
|
|
1670
1661
|
protocolDefinition,
|
|
1671
1662
|
});
|
|
1672
|
-
const configureReply =
|
|
1663
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
1673
1664
|
expect(configureReply.status.code).toBe(202);
|
|
1674
1665
|
// write a foo record with a `numbers` value that is equal to than the exclusive minimum
|
|
1675
|
-
const minItemsRecord =
|
|
1666
|
+
const minItemsRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1676
1667
|
author: alice,
|
|
1677
1668
|
published: true,
|
|
1678
1669
|
protocol: protocolDefinition.protocol,
|
|
@@ -1682,13 +1673,13 @@ export function testRecordsTags() {
|
|
|
1682
1673
|
}
|
|
1683
1674
|
});
|
|
1684
1675
|
// should fail
|
|
1685
|
-
const minItemsReply =
|
|
1676
|
+
const minItemsReply = await dwn.processMessage(alice.did, minItemsRecord.message, { dataStream: minItemsRecord.dataStream });
|
|
1686
1677
|
expect(minItemsReply.status.code).toBe(400);
|
|
1687
1678
|
expect(minItemsReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
1688
1679
|
expect(minItemsReply.status.detail)
|
|
1689
1680
|
.toContain(`${protocolDefinition.protocol}/foo/$tags/numbers/0 must be > 80`);
|
|
1690
1681
|
// write a foo record with a `numbers` value that is equal to than the exclusive maximum
|
|
1691
|
-
const maxContainsRecord =
|
|
1682
|
+
const maxContainsRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1692
1683
|
author: alice,
|
|
1693
1684
|
published: true,
|
|
1694
1685
|
protocol: protocolDefinition.protocol,
|
|
@@ -1698,13 +1689,13 @@ export function testRecordsTags() {
|
|
|
1698
1689
|
}
|
|
1699
1690
|
});
|
|
1700
1691
|
// should fail
|
|
1701
|
-
const maxItemsReply =
|
|
1692
|
+
const maxItemsReply = await dwn.processMessage(alice.did, maxContainsRecord.message, { dataStream: maxContainsRecord.dataStream });
|
|
1702
1693
|
expect(maxItemsReply.status.code).toBe(400);
|
|
1703
1694
|
expect(maxItemsReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
1704
1695
|
expect(maxItemsReply.status.detail)
|
|
1705
1696
|
.toContain(`${protocolDefinition.protocol}/foo/$tags/numbers/1 must be < 100`);
|
|
1706
1697
|
// write a foo record with a `numbers` value that are within the range
|
|
1707
|
-
const validFooRecord =
|
|
1698
|
+
const validFooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1708
1699
|
author: alice,
|
|
1709
1700
|
published: true,
|
|
1710
1701
|
protocol: protocolDefinition.protocol,
|
|
@@ -1714,11 +1705,11 @@ export function testRecordsTags() {
|
|
|
1714
1705
|
}
|
|
1715
1706
|
});
|
|
1716
1707
|
// should pass
|
|
1717
|
-
const validFooRecordReply =
|
|
1708
|
+
const validFooRecordReply = await dwn.processMessage(alice.did, validFooRecord.message, { dataStream: validFooRecord.dataStream });
|
|
1718
1709
|
expect(validFooRecordReply.status.code).toBe(202);
|
|
1719
|
-
})
|
|
1720
|
-
it('should reject a record tag that does not contain a value within the `minLength` and `maxLength` range ', () =>
|
|
1721
|
-
const alice =
|
|
1710
|
+
});
|
|
1711
|
+
it('should reject a record tag that does not contain a value within the `minLength` and `maxLength` range ', async () => {
|
|
1712
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1722
1713
|
// protocol with `minLength` and `maxLength` definitions within `contains`
|
|
1723
1714
|
const protocolDefinition = {
|
|
1724
1715
|
protocol: 'http://example.com/protocol/withTags',
|
|
@@ -1742,14 +1733,14 @@ export function testRecordsTags() {
|
|
|
1742
1733
|
},
|
|
1743
1734
|
};
|
|
1744
1735
|
// configure tags protocol
|
|
1745
|
-
const protocolConfigure =
|
|
1736
|
+
const protocolConfigure = await TestDataGenerator.generateProtocolsConfigure({
|
|
1746
1737
|
author: alice,
|
|
1747
1738
|
protocolDefinition,
|
|
1748
1739
|
});
|
|
1749
|
-
const configureReply =
|
|
1740
|
+
const configureReply = await dwn.processMessage(alice.did, protocolConfigure.message);
|
|
1750
1741
|
expect(configureReply.status.code).toBe(202);
|
|
1751
1742
|
// write a foo record with a `firstName` value that does not have a string within the range
|
|
1752
|
-
const minItemsRecord =
|
|
1743
|
+
const minItemsRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1753
1744
|
author: alice,
|
|
1754
1745
|
published: true,
|
|
1755
1746
|
protocol: protocolDefinition.protocol,
|
|
@@ -1759,13 +1750,13 @@ export function testRecordsTags() {
|
|
|
1759
1750
|
}
|
|
1760
1751
|
});
|
|
1761
1752
|
// should fail
|
|
1762
|
-
const minItemsReply =
|
|
1753
|
+
const minItemsReply = await dwn.processMessage(alice.did, minItemsRecord.message, { dataStream: minItemsRecord.dataStream });
|
|
1763
1754
|
expect(minItemsReply.status.code).toBe(400);
|
|
1764
1755
|
expect(minItemsReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
1765
1756
|
const expectedMinItemsMsg = `${protocolDefinition.protocol}/foo/$tags/nickNames/1 must NOT have fewer than 2 characters`;
|
|
1766
1757
|
expect(minItemsReply.status.detail).toContain(expectedMinItemsMsg);
|
|
1767
1758
|
// write a foo record with a `nickname` value this is too long
|
|
1768
|
-
const maxItemsRecord =
|
|
1759
|
+
const maxItemsRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1769
1760
|
author: alice,
|
|
1770
1761
|
published: true,
|
|
1771
1762
|
protocol: protocolDefinition.protocol,
|
|
@@ -1775,13 +1766,13 @@ export function testRecordsTags() {
|
|
|
1775
1766
|
}
|
|
1776
1767
|
});
|
|
1777
1768
|
// should fail
|
|
1778
|
-
const maxItemsReply =
|
|
1769
|
+
const maxItemsReply = await dwn.processMessage(alice.did, maxItemsRecord.message, { dataStream: maxItemsRecord.dataStream });
|
|
1779
1770
|
expect(maxItemsReply.status.code).toBe(400);
|
|
1780
1771
|
expect(maxItemsReply.status.detail).toContain(DwnErrorCode.ProtocolAuthorizationTagsInvalidSchema);
|
|
1781
1772
|
const expectedMaxItemsMsg = `${protocolDefinition.protocol}/foo/$tags/nickNames/1 must NOT have more than 10 characters`;
|
|
1782
1773
|
expect(maxItemsReply.status.detail).toContain(expectedMaxItemsMsg);
|
|
1783
1774
|
// write a foo record with a `nickNames` value that has a string within the range
|
|
1784
|
-
const validFooRecord =
|
|
1775
|
+
const validFooRecord = await TestDataGenerator.generateRecordsWrite({
|
|
1785
1776
|
author: alice,
|
|
1786
1777
|
published: true,
|
|
1787
1778
|
protocol: protocolDefinition.protocol,
|
|
@@ -1791,20 +1782,20 @@ export function testRecordsTags() {
|
|
|
1791
1782
|
}
|
|
1792
1783
|
});
|
|
1793
1784
|
// should pass
|
|
1794
|
-
const validFooRecordReply =
|
|
1785
|
+
const validFooRecordReply = await dwn.processMessage(alice.did, validFooRecord.message, { dataStream: validFooRecord.dataStream });
|
|
1795
1786
|
expect(validFooRecordReply.status.code).toBe(202);
|
|
1796
|
-
})
|
|
1787
|
+
});
|
|
1797
1788
|
});
|
|
1798
1789
|
});
|
|
1799
|
-
it('should be able to write a Record with tags', () =>
|
|
1800
|
-
const alice =
|
|
1790
|
+
it('should be able to write a Record with tags', async () => {
|
|
1791
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1801
1792
|
// create tags that represent `string[]`, `number[]`, `string`, `number`, or `boolean` values.
|
|
1802
1793
|
const stringTag = 'string-value';
|
|
1803
1794
|
const stringArrayTag = ['string-value', 'string-value2'];
|
|
1804
1795
|
const numberTag = 54566975;
|
|
1805
1796
|
const numberArrayTag = [0, 1, 2];
|
|
1806
1797
|
const booleanTag = false;
|
|
1807
|
-
const tagsRecord1 =
|
|
1798
|
+
const tagsRecord1 = await TestDataGenerator.generateRecordsWrite({
|
|
1808
1799
|
author: alice,
|
|
1809
1800
|
published: true,
|
|
1810
1801
|
schema: 'post',
|
|
@@ -1816,25 +1807,24 @@ export function testRecordsTags() {
|
|
|
1816
1807
|
numberArrayTag,
|
|
1817
1808
|
}
|
|
1818
1809
|
});
|
|
1819
|
-
const tagsRecord1Reply =
|
|
1810
|
+
const tagsRecord1Reply = await dwn.processMessage(alice.did, tagsRecord1.message, { dataStream: tagsRecord1.dataStream });
|
|
1820
1811
|
expect(tagsRecord1Reply.status.code).toBe(202);
|
|
1821
1812
|
// verify the record was written
|
|
1822
|
-
const tagsRecord1Read =
|
|
1813
|
+
const tagsRecord1Read = await RecordsRead.create({
|
|
1823
1814
|
filter: {
|
|
1824
1815
|
recordId: tagsRecord1.message.recordId,
|
|
1825
1816
|
},
|
|
1826
1817
|
signer: Jws.createSigner(alice)
|
|
1827
1818
|
});
|
|
1828
|
-
const tagsRecord1ReadReply =
|
|
1819
|
+
const tagsRecord1ReadReply = await dwn.processMessage(alice.did, tagsRecord1Read.message);
|
|
1829
1820
|
expect(tagsRecord1ReadReply.status.code).toBe(200);
|
|
1830
1821
|
expect(tagsRecord1ReadReply.entry.recordsWrite).toBeDefined();
|
|
1831
1822
|
expect(tagsRecord1ReadReply.entry.recordsWrite.descriptor.tags)
|
|
1832
1823
|
.toEqual({ stringTag, numberTag, booleanTag, stringArrayTag, numberArrayTag });
|
|
1833
|
-
})
|
|
1834
|
-
it('should overwrite tags when updating a Record', () =>
|
|
1835
|
-
|
|
1836
|
-
const
|
|
1837
|
-
const tagsRecord1 = yield TestDataGenerator.generateRecordsWrite({
|
|
1824
|
+
});
|
|
1825
|
+
it('should overwrite tags when updating a Record', async () => {
|
|
1826
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1827
|
+
const tagsRecord1 = await TestDataGenerator.generateRecordsWrite({
|
|
1838
1828
|
author: alice,
|
|
1839
1829
|
published: true,
|
|
1840
1830
|
schema: 'post',
|
|
@@ -1847,16 +1837,16 @@ export function testRecordsTags() {
|
|
|
1847
1837
|
}
|
|
1848
1838
|
});
|
|
1849
1839
|
// write the record
|
|
1850
|
-
const tagsRecord1Reply =
|
|
1840
|
+
const tagsRecord1Reply = await dwn.processMessage(alice.did, tagsRecord1.message, { dataStream: tagsRecord1.dataStream });
|
|
1851
1841
|
expect(tagsRecord1Reply.status.code).toBe(202);
|
|
1852
1842
|
// verify the record was written
|
|
1853
|
-
const tagsRecord1Read =
|
|
1843
|
+
const tagsRecord1Read = await RecordsRead.create({
|
|
1854
1844
|
filter: {
|
|
1855
1845
|
recordId: tagsRecord1.message.recordId,
|
|
1856
1846
|
},
|
|
1857
1847
|
signer: Jws.createSigner(alice)
|
|
1858
1848
|
});
|
|
1859
|
-
const tagsRecord1ReadReply =
|
|
1849
|
+
const tagsRecord1ReadReply = await dwn.processMessage(alice.did, tagsRecord1Read.message);
|
|
1860
1850
|
expect(tagsRecord1ReadReply.status.code).toBe(200);
|
|
1861
1851
|
expect(tagsRecord1ReadReply.entry.recordsWrite).toBeDefined();
|
|
1862
1852
|
expect(tagsRecord1ReadReply.entry.recordsWrite.descriptor.tags).toEqual({
|
|
@@ -1867,7 +1857,7 @@ export function testRecordsTags() {
|
|
|
1867
1857
|
numberArrayTag: [0, 1, 2],
|
|
1868
1858
|
});
|
|
1869
1859
|
// Sanity: Query for a tag value
|
|
1870
|
-
const tagsQueryMatch =
|
|
1860
|
+
const tagsQueryMatch = await TestDataGenerator.generateRecordsQuery({
|
|
1871
1861
|
author: alice,
|
|
1872
1862
|
filter: {
|
|
1873
1863
|
tags: {
|
|
@@ -1875,33 +1865,33 @@ export function testRecordsTags() {
|
|
|
1875
1865
|
}
|
|
1876
1866
|
}
|
|
1877
1867
|
});
|
|
1878
|
-
const tagsQueryMatchReply =
|
|
1868
|
+
const tagsQueryMatchReply = await dwn.processMessage(alice.did, tagsQueryMatch.message);
|
|
1879
1869
|
expect(tagsQueryMatchReply.status.code).toBe(200);
|
|
1880
|
-
expect(
|
|
1870
|
+
expect(tagsQueryMatchReply.entries?.length).toBe(1);
|
|
1881
1871
|
expect(tagsQueryMatchReply.entries[0].recordId).toBe(tagsRecord1.message.recordId);
|
|
1882
1872
|
// update the record with new tags
|
|
1883
|
-
const updatedRecord =
|
|
1873
|
+
const updatedRecord = await TestDataGenerator.generateFromRecordsWrite({
|
|
1884
1874
|
author: alice,
|
|
1885
1875
|
existingWrite: tagsRecord1.recordsWrite,
|
|
1886
1876
|
tags: { newTag: 'new-value' }
|
|
1887
1877
|
});
|
|
1888
|
-
const updatedRecordReply =
|
|
1878
|
+
const updatedRecordReply = await dwn.processMessage(alice.did, updatedRecord.message, { dataStream: updatedRecord.dataStream });
|
|
1889
1879
|
expect(updatedRecordReply.status.code).toBe(202, updatedRecordReply.status.detail);
|
|
1890
|
-
const updatedRecordReadReply =
|
|
1880
|
+
const updatedRecordReadReply = await dwn.processMessage(alice.did, tagsRecord1Read.message);
|
|
1891
1881
|
expect(updatedRecordReadReply.status.code).toBe(200);
|
|
1892
1882
|
expect(updatedRecordReadReply.entry.recordsWrite).toBeDefined();
|
|
1893
1883
|
expect(updatedRecordReadReply.entry.recordsWrite.descriptor.tags).toEqual({ newTag: 'new-value' });
|
|
1894
1884
|
// Sanity: Query for the old tag value should return no results
|
|
1895
|
-
const tagsQueryMatchReply2 =
|
|
1885
|
+
const tagsQueryMatchReply2 = await dwn.processMessage(alice.did, tagsQueryMatch.message);
|
|
1896
1886
|
expect(tagsQueryMatchReply2.status.code).toBe(200);
|
|
1897
|
-
expect(
|
|
1898
|
-
})
|
|
1899
|
-
it('should not index tags when the record is not `latestBaseState`', () =>
|
|
1887
|
+
expect(tagsQueryMatchReply2.entries?.length).toBe(0);
|
|
1888
|
+
});
|
|
1889
|
+
it('should not index tags when the record is not `latestBaseState`', async () => {
|
|
1900
1890
|
const buildTagIndexSpy = sinon.spy(Records, 'buildTagIndexes');
|
|
1901
1891
|
const constructIndexesSpy = sinon.spy(RecordsWrite.prototype, 'constructIndexes');
|
|
1902
|
-
const alice =
|
|
1892
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1903
1893
|
// write a record with tags, this should trigger the `buildTagIndexes` method
|
|
1904
|
-
const tagsRecord1 =
|
|
1894
|
+
const tagsRecord1 = await TestDataGenerator.generateRecordsWrite({
|
|
1905
1895
|
author: alice,
|
|
1906
1896
|
published: true,
|
|
1907
1897
|
schema: 'post',
|
|
@@ -1914,7 +1904,7 @@ export function testRecordsTags() {
|
|
|
1914
1904
|
}
|
|
1915
1905
|
});
|
|
1916
1906
|
// write the record
|
|
1917
|
-
const tagsRecord1Reply =
|
|
1907
|
+
const tagsRecord1Reply = await dwn.processMessage(alice.did, tagsRecord1.message, { dataStream: tagsRecord1.dataStream });
|
|
1918
1908
|
expect(tagsRecord1Reply.status.code).toBe(202);
|
|
1919
1909
|
// verify that construct Indexes was called
|
|
1920
1910
|
expect(constructIndexesSpy.callCount).toBe(1);
|
|
@@ -1924,24 +1914,23 @@ export function testRecordsTags() {
|
|
|
1924
1914
|
constructIndexesSpy.resetHistory();
|
|
1925
1915
|
buildTagIndexSpy.resetHistory();
|
|
1926
1916
|
// update the record without any tags this time
|
|
1927
|
-
const updatedRecord =
|
|
1917
|
+
const updatedRecord = await TestDataGenerator.generateFromRecordsWrite({
|
|
1928
1918
|
author: alice,
|
|
1929
1919
|
existingWrite: tagsRecord1.recordsWrite,
|
|
1930
1920
|
});
|
|
1931
|
-
const updatedRecordReply =
|
|
1921
|
+
const updatedRecordReply = await dwn.processMessage(alice.did, updatedRecord.message, { dataStream: updatedRecord.dataStream });
|
|
1932
1922
|
expect(updatedRecordReply.status.code).toBe(202);
|
|
1933
1923
|
// construct Indexes should be called once for the `initialWrite` and once for the updated write
|
|
1934
1924
|
expect(constructIndexesSpy.callCount).toBe(2);
|
|
1935
1925
|
// verify that buildTagIndexes was not called at all
|
|
1936
1926
|
expect(buildTagIndexSpy.callCount).toBe(0);
|
|
1937
|
-
})
|
|
1927
|
+
});
|
|
1938
1928
|
});
|
|
1939
1929
|
describe('RecordsQuery filter for tags', () => {
|
|
1940
|
-
it('should be able to filter by string match', () =>
|
|
1941
|
-
|
|
1942
|
-
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
1930
|
+
it('should be able to filter by string match', async () => {
|
|
1931
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1943
1932
|
const stringTag = 'string-value';
|
|
1944
|
-
const tagsRecord1 =
|
|
1933
|
+
const tagsRecord1 = await TestDataGenerator.generateRecordsWrite({
|
|
1945
1934
|
author: alice,
|
|
1946
1935
|
published: true,
|
|
1947
1936
|
schema: 'post',
|
|
@@ -1949,9 +1938,9 @@ export function testRecordsTags() {
|
|
|
1949
1938
|
stringTag,
|
|
1950
1939
|
}
|
|
1951
1940
|
});
|
|
1952
|
-
const tagsRecord1Reply =
|
|
1941
|
+
const tagsRecord1Reply = await dwn.processMessage(alice.did, tagsRecord1.message, { dataStream: tagsRecord1.dataStream });
|
|
1953
1942
|
expect(tagsRecord1Reply.status.code).toBe(202);
|
|
1954
|
-
const tagsQueryMatch =
|
|
1943
|
+
const tagsQueryMatch = await TestDataGenerator.generateRecordsQuery({
|
|
1955
1944
|
author: alice,
|
|
1956
1945
|
filter: {
|
|
1957
1946
|
tags: {
|
|
@@ -1959,12 +1948,12 @@ export function testRecordsTags() {
|
|
|
1959
1948
|
}
|
|
1960
1949
|
}
|
|
1961
1950
|
});
|
|
1962
|
-
const tagsQueryMatchReply =
|
|
1951
|
+
const tagsQueryMatchReply = await dwn.processMessage(alice.did, tagsQueryMatch.message);
|
|
1963
1952
|
expect(tagsQueryMatchReply.status.code).toBe(200);
|
|
1964
|
-
expect(
|
|
1953
|
+
expect(tagsQueryMatchReply.entries?.length).toBe(1);
|
|
1965
1954
|
expect(tagsQueryMatchReply.entries[0].recordId).toBe(tagsRecord1.message.recordId);
|
|
1966
1955
|
// negative result same tag different value
|
|
1967
|
-
let tagsQueryNegative =
|
|
1956
|
+
let tagsQueryNegative = await TestDataGenerator.generateRecordsQuery({
|
|
1968
1957
|
author: alice,
|
|
1969
1958
|
filter: {
|
|
1970
1959
|
tags: {
|
|
@@ -1972,11 +1961,11 @@ export function testRecordsTags() {
|
|
|
1972
1961
|
}
|
|
1973
1962
|
}
|
|
1974
1963
|
});
|
|
1975
|
-
let tagsQueryNegativeReply =
|
|
1964
|
+
let tagsQueryNegativeReply = await dwn.processMessage(alice.did, tagsQueryNegative.message);
|
|
1976
1965
|
expect(tagsQueryNegativeReply.status.code).toBe(200);
|
|
1977
|
-
expect(
|
|
1966
|
+
expect(tagsQueryNegativeReply.entries?.length).toBe(0);
|
|
1978
1967
|
// negative result different tag same value
|
|
1979
|
-
tagsQueryNegative =
|
|
1968
|
+
tagsQueryNegative = await TestDataGenerator.generateRecordsQuery({
|
|
1980
1969
|
author: alice,
|
|
1981
1970
|
filter: {
|
|
1982
1971
|
tags: {
|
|
@@ -1984,16 +1973,15 @@ export function testRecordsTags() {
|
|
|
1984
1973
|
}
|
|
1985
1974
|
}
|
|
1986
1975
|
});
|
|
1987
|
-
tagsQueryNegativeReply =
|
|
1976
|
+
tagsQueryNegativeReply = await dwn.processMessage(alice.did, tagsQueryNegative.message);
|
|
1988
1977
|
expect(tagsQueryNegativeReply.status.code).toBe(200);
|
|
1989
|
-
expect(
|
|
1990
|
-
})
|
|
1991
|
-
it('should be able to filter by number match', () =>
|
|
1992
|
-
|
|
1993
|
-
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
1978
|
+
expect(tagsQueryNegativeReply.entries?.length).toBe(0);
|
|
1979
|
+
});
|
|
1980
|
+
it('should be able to filter by number match', async () => {
|
|
1981
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1994
1982
|
const numberTag = 54566975;
|
|
1995
1983
|
// write a record with a numerical value tag
|
|
1996
|
-
const tagsRecord1 =
|
|
1984
|
+
const tagsRecord1 = await TestDataGenerator.generateRecordsWrite({
|
|
1997
1985
|
author: alice,
|
|
1998
1986
|
published: true,
|
|
1999
1987
|
schema: 'post',
|
|
@@ -2001,10 +1989,10 @@ export function testRecordsTags() {
|
|
|
2001
1989
|
numberTag,
|
|
2002
1990
|
}
|
|
2003
1991
|
});
|
|
2004
|
-
const tagsRecord1Reply =
|
|
1992
|
+
const tagsRecord1Reply = await dwn.processMessage(alice.did, tagsRecord1.message, { dataStream: tagsRecord1.dataStream });
|
|
2005
1993
|
expect(tagsRecord1Reply.status.code).toBe(202);
|
|
2006
1994
|
// do an exact match for the tag value
|
|
2007
|
-
const tagsQueryMatch =
|
|
1995
|
+
const tagsQueryMatch = await TestDataGenerator.generateRecordsQuery({
|
|
2008
1996
|
author: alice,
|
|
2009
1997
|
filter: {
|
|
2010
1998
|
tags: {
|
|
@@ -2012,12 +2000,12 @@ export function testRecordsTags() {
|
|
|
2012
2000
|
}
|
|
2013
2001
|
}
|
|
2014
2002
|
});
|
|
2015
|
-
const tagsQueryMatchReply =
|
|
2003
|
+
const tagsQueryMatchReply = await dwn.processMessage(alice.did, tagsQueryMatch.message);
|
|
2016
2004
|
expect(tagsQueryMatchReply.status.code).toBe(200);
|
|
2017
|
-
expect(
|
|
2005
|
+
expect(tagsQueryMatchReply.entries?.length).toBe(1);
|
|
2018
2006
|
expect(tagsQueryMatchReply.entries[0].recordId).toBe(tagsRecord1.message.recordId);
|
|
2019
2007
|
// negative result same tag different value
|
|
2020
|
-
let tagsQueryNegative =
|
|
2008
|
+
let tagsQueryNegative = await TestDataGenerator.generateRecordsQuery({
|
|
2021
2009
|
author: alice,
|
|
2022
2010
|
filter: {
|
|
2023
2011
|
tags: {
|
|
@@ -2025,11 +2013,11 @@ export function testRecordsTags() {
|
|
|
2025
2013
|
}
|
|
2026
2014
|
}
|
|
2027
2015
|
});
|
|
2028
|
-
let tagsQueryNegativeReply =
|
|
2016
|
+
let tagsQueryNegativeReply = await dwn.processMessage(alice.did, tagsQueryNegative.message);
|
|
2029
2017
|
expect(tagsQueryNegativeReply.status.code).toBe(200);
|
|
2030
|
-
expect(
|
|
2018
|
+
expect(tagsQueryNegativeReply.entries?.length).toBe(0);
|
|
2031
2019
|
// negative result different tag same value
|
|
2032
|
-
tagsQueryNegative =
|
|
2020
|
+
tagsQueryNegative = await TestDataGenerator.generateRecordsQuery({
|
|
2033
2021
|
author: alice,
|
|
2034
2022
|
filter: {
|
|
2035
2023
|
tags: {
|
|
@@ -2037,20 +2025,19 @@ export function testRecordsTags() {
|
|
|
2037
2025
|
}
|
|
2038
2026
|
}
|
|
2039
2027
|
});
|
|
2040
|
-
tagsQueryNegativeReply =
|
|
2028
|
+
tagsQueryNegativeReply = await dwn.processMessage(alice.did, tagsQueryNegative.message);
|
|
2041
2029
|
expect(tagsQueryNegativeReply.status.code).toBe(200);
|
|
2042
|
-
expect(
|
|
2043
|
-
})
|
|
2044
|
-
it('should be able to filter by boolean match', () =>
|
|
2030
|
+
expect(tagsQueryNegativeReply.entries?.length).toBe(0);
|
|
2031
|
+
});
|
|
2032
|
+
it('should be able to filter by boolean match', async () => {
|
|
2045
2033
|
// 1. Write a record with a boolean tag `booleanTag` set to true
|
|
2046
2034
|
// 2. Write a record with a boolean tag `booleanTag` set to false.
|
|
2047
2035
|
// 3. Query for records with a `booleanTag` set to true, and validate the result.
|
|
2048
2036
|
// 4. Query for records with a `booleanTag` set to false, and validate the result.
|
|
2049
2037
|
// 5. Query for records with a non existent boolean tag, should not return a result.
|
|
2050
|
-
|
|
2051
|
-
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
2038
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
2052
2039
|
// write a record with a true boolean value tag
|
|
2053
|
-
const tagsRecordTrue =
|
|
2040
|
+
const tagsRecordTrue = await TestDataGenerator.generateRecordsWrite({
|
|
2054
2041
|
author: alice,
|
|
2055
2042
|
published: true,
|
|
2056
2043
|
schema: 'post',
|
|
@@ -2058,10 +2045,10 @@ export function testRecordsTags() {
|
|
|
2058
2045
|
booleanTag: true,
|
|
2059
2046
|
}
|
|
2060
2047
|
});
|
|
2061
|
-
const tagsRecordTrueReply =
|
|
2048
|
+
const tagsRecordTrueReply = await dwn.processMessage(alice.did, tagsRecordTrue.message, { dataStream: tagsRecordTrue.dataStream });
|
|
2062
2049
|
expect(tagsRecordTrueReply.status.code).toBe(202);
|
|
2063
2050
|
// write a record with a false boolean value tag
|
|
2064
|
-
const tagsRecordFalse =
|
|
2051
|
+
const tagsRecordFalse = await TestDataGenerator.generateRecordsWrite({
|
|
2065
2052
|
author: alice,
|
|
2066
2053
|
published: true,
|
|
2067
2054
|
schema: 'post',
|
|
@@ -2069,10 +2056,10 @@ export function testRecordsTags() {
|
|
|
2069
2056
|
booleanTag: false,
|
|
2070
2057
|
}
|
|
2071
2058
|
});
|
|
2072
|
-
const tagsRecordFalseReply =
|
|
2059
|
+
const tagsRecordFalseReply = await dwn.processMessage(alice.did, tagsRecordFalse.message, { dataStream: tagsRecordFalse.dataStream });
|
|
2073
2060
|
expect(tagsRecordFalseReply.status.code).toBe(202);
|
|
2074
2061
|
// query for records with a `booleanTag` set to true, should return the record with the true tag
|
|
2075
|
-
const tagsQueryMatchTrue =
|
|
2062
|
+
const tagsQueryMatchTrue = await TestDataGenerator.generateRecordsQuery({
|
|
2076
2063
|
author: alice,
|
|
2077
2064
|
filter: {
|
|
2078
2065
|
tags: {
|
|
@@ -2080,12 +2067,12 @@ export function testRecordsTags() {
|
|
|
2080
2067
|
}
|
|
2081
2068
|
}
|
|
2082
2069
|
});
|
|
2083
|
-
const tagsQueryMatchTrueReply =
|
|
2070
|
+
const tagsQueryMatchTrueReply = await dwn.processMessage(alice.did, tagsQueryMatchTrue.message);
|
|
2084
2071
|
expect(tagsQueryMatchTrueReply.status.code).toBe(200);
|
|
2085
|
-
expect(
|
|
2072
|
+
expect(tagsQueryMatchTrueReply.entries?.length).toBe(1);
|
|
2086
2073
|
expect(tagsQueryMatchTrueReply.entries[0].recordId).toBe(tagsRecordTrue.message.recordId);
|
|
2087
2074
|
// query for records with a `booleanTag` set to false, should return the record with the false tag
|
|
2088
|
-
const tagsQueryMatchFalse =
|
|
2075
|
+
const tagsQueryMatchFalse = await TestDataGenerator.generateRecordsQuery({
|
|
2089
2076
|
author: alice,
|
|
2090
2077
|
filter: {
|
|
2091
2078
|
tags: {
|
|
@@ -2093,12 +2080,12 @@ export function testRecordsTags() {
|
|
|
2093
2080
|
}
|
|
2094
2081
|
}
|
|
2095
2082
|
});
|
|
2096
|
-
const tagsQueryMatchFalseReply =
|
|
2083
|
+
const tagsQueryMatchFalseReply = await dwn.processMessage(alice.did, tagsQueryMatchFalse.message);
|
|
2097
2084
|
expect(tagsQueryMatchFalseReply.status.code).toBe(200);
|
|
2098
|
-
expect(
|
|
2085
|
+
expect(tagsQueryMatchFalseReply.entries?.length).toBe(1);
|
|
2099
2086
|
expect(tagsQueryMatchFalseReply.entries[0].recordId).toBe(tagsRecordFalse.message.recordId);
|
|
2100
2087
|
// negative result for a non existent boolean tag.
|
|
2101
|
-
const tagsQueryNegative =
|
|
2088
|
+
const tagsQueryNegative = await TestDataGenerator.generateRecordsQuery({
|
|
2102
2089
|
author: alice,
|
|
2103
2090
|
filter: {
|
|
2104
2091
|
tags: {
|
|
@@ -2106,15 +2093,14 @@ export function testRecordsTags() {
|
|
|
2106
2093
|
}
|
|
2107
2094
|
}
|
|
2108
2095
|
});
|
|
2109
|
-
const tagsQueryNegativeReply =
|
|
2096
|
+
const tagsQueryNegativeReply = await dwn.processMessage(alice.did, tagsQueryNegative.message);
|
|
2110
2097
|
expect(tagsQueryNegativeReply.status.code).toBe(200);
|
|
2111
|
-
expect(
|
|
2112
|
-
})
|
|
2113
|
-
it('should be able to range filter by string value', () =>
|
|
2114
|
-
|
|
2115
|
-
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
2098
|
+
expect(tagsQueryNegativeReply.entries?.length).toBe(0);
|
|
2099
|
+
});
|
|
2100
|
+
it('should be able to range filter by string value', async () => {
|
|
2101
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
2116
2102
|
// create four records with different first names
|
|
2117
|
-
const aliceRecord =
|
|
2103
|
+
const aliceRecord = await TestDataGenerator.generateRecordsWrite({
|
|
2118
2104
|
author: alice,
|
|
2119
2105
|
published: true,
|
|
2120
2106
|
schema: 'post',
|
|
@@ -2122,7 +2108,7 @@ export function testRecordsTags() {
|
|
|
2122
2108
|
firstName: 'alice'
|
|
2123
2109
|
}
|
|
2124
2110
|
});
|
|
2125
|
-
const bobRecord =
|
|
2111
|
+
const bobRecord = await TestDataGenerator.generateRecordsWrite({
|
|
2126
2112
|
author: alice,
|
|
2127
2113
|
published: true,
|
|
2128
2114
|
schema: 'post',
|
|
@@ -2130,7 +2116,7 @@ export function testRecordsTags() {
|
|
|
2130
2116
|
firstName: 'bob',
|
|
2131
2117
|
}
|
|
2132
2118
|
});
|
|
2133
|
-
const carolRecord =
|
|
2119
|
+
const carolRecord = await TestDataGenerator.generateRecordsWrite({
|
|
2134
2120
|
author: alice,
|
|
2135
2121
|
published: true,
|
|
2136
2122
|
schema: 'post',
|
|
@@ -2138,7 +2124,7 @@ export function testRecordsTags() {
|
|
|
2138
2124
|
firstName: 'carol',
|
|
2139
2125
|
}
|
|
2140
2126
|
});
|
|
2141
|
-
const danielRecord =
|
|
2127
|
+
const danielRecord = await TestDataGenerator.generateRecordsWrite({
|
|
2142
2128
|
author: alice,
|
|
2143
2129
|
published: true,
|
|
2144
2130
|
schema: 'post',
|
|
@@ -2146,26 +2132,26 @@ export function testRecordsTags() {
|
|
|
2146
2132
|
firstName: 'daniel',
|
|
2147
2133
|
}
|
|
2148
2134
|
});
|
|
2149
|
-
const aliceReply =
|
|
2135
|
+
const aliceReply = await dwn.processMessage(alice.did, aliceRecord.message, { dataStream: aliceRecord.dataStream });
|
|
2150
2136
|
expect(aliceReply.status.code).toBe(202);
|
|
2151
|
-
const bobReply =
|
|
2137
|
+
const bobReply = await dwn.processMessage(alice.did, bobRecord.message, { dataStream: bobRecord.dataStream });
|
|
2152
2138
|
expect(bobReply.status.code).toBe(202);
|
|
2153
|
-
const carolReply =
|
|
2139
|
+
const carolReply = await dwn.processMessage(alice.did, carolRecord.message, { dataStream: carolRecord.dataStream });
|
|
2154
2140
|
expect(carolReply.status.code).toBe(202);
|
|
2155
|
-
const danielReply =
|
|
2141
|
+
const danielReply = await dwn.processMessage(alice.did, danielRecord.message, { dataStream: danielRecord.dataStream });
|
|
2156
2142
|
expect(danielReply.status.code).toBe(202);
|
|
2157
2143
|
// sanity query for all
|
|
2158
|
-
const queryForAll =
|
|
2144
|
+
const queryForAll = await TestDataGenerator.generateRecordsQuery({
|
|
2159
2145
|
author: alice,
|
|
2160
2146
|
filter: {
|
|
2161
2147
|
schema: 'post'
|
|
2162
2148
|
}
|
|
2163
2149
|
});
|
|
2164
|
-
const queryForAllReply =
|
|
2150
|
+
const queryForAllReply = await dwn.processMessage(alice.did, queryForAll.message);
|
|
2165
2151
|
expect(queryForAllReply.status.code).toBe(200);
|
|
2166
|
-
expect(
|
|
2152
|
+
expect(queryForAllReply.entries?.length).toBe(4); // all 4 records
|
|
2167
2153
|
// query for first names that begin with 'a' and 'b'
|
|
2168
|
-
const queryForAtoB =
|
|
2154
|
+
const queryForAtoB = await TestDataGenerator.generateRecordsQuery({
|
|
2169
2155
|
author: alice,
|
|
2170
2156
|
filter: {
|
|
2171
2157
|
schema: 'post',
|
|
@@ -2174,13 +2160,13 @@ export function testRecordsTags() {
|
|
|
2174
2160
|
}
|
|
2175
2161
|
}
|
|
2176
2162
|
});
|
|
2177
|
-
const queryForAtoBReply =
|
|
2163
|
+
const queryForAtoBReply = await dwn.processMessage(alice.did, queryForAtoB.message);
|
|
2178
2164
|
expect(queryForAtoBReply.status.code).toBe(200);
|
|
2179
|
-
expect(
|
|
2165
|
+
expect(queryForAtoBReply.entries?.length).toBe(2);
|
|
2180
2166
|
const atobRecordIds = queryForAtoBReply.entries.map(entry => entry.recordId);
|
|
2181
2167
|
expect(atobRecordIds).toEqual(expect.arrayContaining([aliceRecord.message.recordId, bobRecord.message.recordId]));
|
|
2182
2168
|
// query for first names greater than 'bob'(exclusive of), and less than but inclusive of 'daniel'
|
|
2183
|
-
const queryForBtoD =
|
|
2169
|
+
const queryForBtoD = await TestDataGenerator.generateRecordsQuery({
|
|
2184
2170
|
author: alice,
|
|
2185
2171
|
filter: {
|
|
2186
2172
|
schema: 'post',
|
|
@@ -2189,13 +2175,13 @@ export function testRecordsTags() {
|
|
|
2189
2175
|
}
|
|
2190
2176
|
}
|
|
2191
2177
|
});
|
|
2192
|
-
const queryForBtoDReply =
|
|
2178
|
+
const queryForBtoDReply = await dwn.processMessage(alice.did, queryForBtoD.message);
|
|
2193
2179
|
expect(queryForBtoDReply.status.code).toBe(200);
|
|
2194
|
-
expect(
|
|
2180
|
+
expect(queryForBtoDReply.entries?.length).toBe(2);
|
|
2195
2181
|
const btodRecordIds = queryForBtoDReply.entries.map(entry => entry.recordId);
|
|
2196
2182
|
expect(btodRecordIds).toEqual(expect.arrayContaining([carolRecord.message.recordId, danielRecord.message.recordId]));
|
|
2197
2183
|
// query for first names that begin with 'carol' onward (inclusive).
|
|
2198
|
-
const queryForCarolOnward =
|
|
2184
|
+
const queryForCarolOnward = await TestDataGenerator.generateRecordsQuery({
|
|
2199
2185
|
author: alice,
|
|
2200
2186
|
filter: {
|
|
2201
2187
|
schema: 'post',
|
|
@@ -2204,17 +2190,16 @@ export function testRecordsTags() {
|
|
|
2204
2190
|
}
|
|
2205
2191
|
}
|
|
2206
2192
|
});
|
|
2207
|
-
const queryForCarolOnwardReply =
|
|
2193
|
+
const queryForCarolOnwardReply = await dwn.processMessage(alice.did, queryForCarolOnward.message);
|
|
2208
2194
|
expect(queryForCarolOnwardReply.status.code).toBe(200);
|
|
2209
|
-
expect(
|
|
2195
|
+
expect(queryForCarolOnwardReply.entries?.length).toBe(2);
|
|
2210
2196
|
const onwardResults = queryForCarolOnwardReply.entries.map(entry => entry.recordId);
|
|
2211
2197
|
expect(onwardResults).toEqual(expect.arrayContaining([carolRecord.message.recordId, danielRecord.message.recordId]));
|
|
2212
|
-
})
|
|
2213
|
-
it('should be able to filter by string prefix', () =>
|
|
2214
|
-
|
|
2215
|
-
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
2198
|
+
});
|
|
2199
|
+
it('should be able to filter by string prefix', async () => {
|
|
2200
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
2216
2201
|
// create two records that match the prefix 'string-'
|
|
2217
|
-
const tagsRecord1 =
|
|
2202
|
+
const tagsRecord1 = await TestDataGenerator.generateRecordsWrite({
|
|
2218
2203
|
author: alice,
|
|
2219
2204
|
published: true,
|
|
2220
2205
|
schema: 'post',
|
|
@@ -2222,7 +2207,7 @@ export function testRecordsTags() {
|
|
|
2222
2207
|
stringTag: 'string-foo',
|
|
2223
2208
|
}
|
|
2224
2209
|
});
|
|
2225
|
-
const tagsRecord2 =
|
|
2210
|
+
const tagsRecord2 = await TestDataGenerator.generateRecordsWrite({
|
|
2226
2211
|
author: alice,
|
|
2227
2212
|
published: true,
|
|
2228
2213
|
schema: 'post',
|
|
@@ -2230,12 +2215,12 @@ export function testRecordsTags() {
|
|
|
2230
2215
|
stringTag: 'string-bar',
|
|
2231
2216
|
}
|
|
2232
2217
|
});
|
|
2233
|
-
const tagsRecord1Reply =
|
|
2218
|
+
const tagsRecord1Reply = await dwn.processMessage(alice.did, tagsRecord1.message, { dataStream: tagsRecord1.dataStream });
|
|
2234
2219
|
expect(tagsRecord1Reply.status.code).toBe(202);
|
|
2235
|
-
const tagsRecord2Reply =
|
|
2220
|
+
const tagsRecord2Reply = await dwn.processMessage(alice.did, tagsRecord2.message, { dataStream: tagsRecord2.dataStream });
|
|
2236
2221
|
expect(tagsRecord2Reply.status.code).toBe(202);
|
|
2237
2222
|
// control record that has a different prefix
|
|
2238
|
-
const tagsRecord3 =
|
|
2223
|
+
const tagsRecord3 = await TestDataGenerator.generateRecordsWrite({
|
|
2239
2224
|
author: alice,
|
|
2240
2225
|
published: true,
|
|
2241
2226
|
schema: 'post',
|
|
@@ -2243,10 +2228,10 @@ export function testRecordsTags() {
|
|
|
2243
2228
|
stringTag: 'zaz-string', // comes after `string-` lexicographically
|
|
2244
2229
|
}
|
|
2245
2230
|
});
|
|
2246
|
-
const tagsRecord3Reply =
|
|
2231
|
+
const tagsRecord3Reply = await dwn.processMessage(alice.did, tagsRecord3.message, { dataStream: tagsRecord3.dataStream });
|
|
2247
2232
|
expect(tagsRecord3Reply.status.code).toBe(202);
|
|
2248
2233
|
// a prefix search will return only the records matching the prefix
|
|
2249
|
-
const tagsQueryMatch =
|
|
2234
|
+
const tagsQueryMatch = await TestDataGenerator.generateRecordsQuery({
|
|
2250
2235
|
author: alice,
|
|
2251
2236
|
filter: {
|
|
2252
2237
|
tags: {
|
|
@@ -2254,14 +2239,14 @@ export function testRecordsTags() {
|
|
|
2254
2239
|
}
|
|
2255
2240
|
}
|
|
2256
2241
|
});
|
|
2257
|
-
const tagsQueryMatchReply =
|
|
2242
|
+
const tagsQueryMatchReply = await dwn.processMessage(alice.did, tagsQueryMatch.message);
|
|
2258
2243
|
expect(tagsQueryMatchReply.status.code).toBe(200);
|
|
2259
|
-
expect(
|
|
2244
|
+
expect(tagsQueryMatchReply.entries?.length).toBe(2);
|
|
2260
2245
|
const matchedRecords = tagsQueryMatchReply.entries.map(entry => entry.recordId);
|
|
2261
2246
|
expect(matchedRecords).toEqual(expect.arrayContaining([tagsRecord1.message.recordId, tagsRecord2.message.recordId]));
|
|
2262
2247
|
// sanity/control: a regular range query will return all
|
|
2263
2248
|
// since `zaz-string` comes lexicographically after `string-` it will appear in the result set
|
|
2264
|
-
const tagsQueryRange =
|
|
2249
|
+
const tagsQueryRange = await TestDataGenerator.generateRecordsQuery({
|
|
2265
2250
|
author: alice,
|
|
2266
2251
|
filter: {
|
|
2267
2252
|
tags: {
|
|
@@ -2269,15 +2254,14 @@ export function testRecordsTags() {
|
|
|
2269
2254
|
}
|
|
2270
2255
|
}
|
|
2271
2256
|
});
|
|
2272
|
-
const tagsQueryRangeReply =
|
|
2257
|
+
const tagsQueryRangeReply = await dwn.processMessage(alice.did, tagsQueryRange.message);
|
|
2273
2258
|
expect(tagsQueryRangeReply.status.code).toBe(200);
|
|
2274
|
-
expect(
|
|
2275
|
-
})
|
|
2276
|
-
it('should be able to range filter by number value', () =>
|
|
2277
|
-
|
|
2278
|
-
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
2259
|
+
expect(tagsQueryRangeReply.entries?.length).toBe(3); // returned all 3 records
|
|
2260
|
+
});
|
|
2261
|
+
it('should be able to range filter by number value', async () => {
|
|
2262
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
2279
2263
|
// create four records with different test scores
|
|
2280
|
-
const aliceRecord =
|
|
2264
|
+
const aliceRecord = await TestDataGenerator.generateRecordsWrite({
|
|
2281
2265
|
author: alice,
|
|
2282
2266
|
published: true,
|
|
2283
2267
|
schema: 'test',
|
|
@@ -2286,7 +2270,7 @@ export function testRecordsTags() {
|
|
|
2286
2270
|
score: 75,
|
|
2287
2271
|
}
|
|
2288
2272
|
});
|
|
2289
|
-
const bobRecord =
|
|
2273
|
+
const bobRecord = await TestDataGenerator.generateRecordsWrite({
|
|
2290
2274
|
author: alice,
|
|
2291
2275
|
published: true,
|
|
2292
2276
|
schema: 'test',
|
|
@@ -2295,7 +2279,7 @@ export function testRecordsTags() {
|
|
|
2295
2279
|
score: 80,
|
|
2296
2280
|
}
|
|
2297
2281
|
});
|
|
2298
|
-
const carolRecord =
|
|
2282
|
+
const carolRecord = await TestDataGenerator.generateRecordsWrite({
|
|
2299
2283
|
author: alice,
|
|
2300
2284
|
published: true,
|
|
2301
2285
|
schema: 'test',
|
|
@@ -2304,7 +2288,7 @@ export function testRecordsTags() {
|
|
|
2304
2288
|
score: 65,
|
|
2305
2289
|
}
|
|
2306
2290
|
});
|
|
2307
|
-
const danielRecord =
|
|
2291
|
+
const danielRecord = await TestDataGenerator.generateRecordsWrite({
|
|
2308
2292
|
author: alice,
|
|
2309
2293
|
published: true,
|
|
2310
2294
|
schema: 'test',
|
|
@@ -2313,27 +2297,27 @@ export function testRecordsTags() {
|
|
|
2313
2297
|
score: 100,
|
|
2314
2298
|
}
|
|
2315
2299
|
});
|
|
2316
|
-
const aliceReply =
|
|
2300
|
+
const aliceReply = await dwn.processMessage(alice.did, aliceRecord.message, { dataStream: aliceRecord.dataStream });
|
|
2317
2301
|
expect(aliceReply.status.code).toBe(202);
|
|
2318
|
-
const bobReply =
|
|
2302
|
+
const bobReply = await dwn.processMessage(alice.did, bobRecord.message, { dataStream: bobRecord.dataStream });
|
|
2319
2303
|
expect(bobReply.status.code).toBe(202);
|
|
2320
|
-
const carolReply =
|
|
2304
|
+
const carolReply = await dwn.processMessage(alice.did, carolRecord.message, { dataStream: carolRecord.dataStream });
|
|
2321
2305
|
expect(carolReply.status.code).toBe(202);
|
|
2322
|
-
const danielReply =
|
|
2306
|
+
const danielReply = await dwn.processMessage(alice.did, danielRecord.message, { dataStream: danielRecord.dataStream });
|
|
2323
2307
|
expect(danielReply.status.code).toBe(202);
|
|
2324
2308
|
// sanity query for all
|
|
2325
|
-
const queryForAll =
|
|
2309
|
+
const queryForAll = await TestDataGenerator.generateRecordsQuery({
|
|
2326
2310
|
author: alice,
|
|
2327
2311
|
filter: {
|
|
2328
2312
|
schema: 'test'
|
|
2329
2313
|
}
|
|
2330
2314
|
});
|
|
2331
|
-
const queryForAllReply =
|
|
2315
|
+
const queryForAllReply = await dwn.processMessage(alice.did, queryForAll.message);
|
|
2332
2316
|
expect(queryForAllReply.status.code).toBe(200);
|
|
2333
|
-
expect(
|
|
2317
|
+
expect(queryForAllReply.entries?.length).toBe(4); // all 4 records
|
|
2334
2318
|
// query for all records that received higher than(not including) an 80
|
|
2335
2319
|
// only one record should match
|
|
2336
|
-
const queryForHighGrade =
|
|
2320
|
+
const queryForHighGrade = await TestDataGenerator.generateRecordsQuery({
|
|
2337
2321
|
author: alice,
|
|
2338
2322
|
filter: {
|
|
2339
2323
|
schema: 'test',
|
|
@@ -2342,13 +2326,13 @@ export function testRecordsTags() {
|
|
|
2342
2326
|
}
|
|
2343
2327
|
}
|
|
2344
2328
|
});
|
|
2345
|
-
const queryForHighReply =
|
|
2329
|
+
const queryForHighReply = await dwn.processMessage(alice.did, queryForHighGrade.message);
|
|
2346
2330
|
expect(queryForHighReply.status.code).toBe(200);
|
|
2347
|
-
expect(
|
|
2331
|
+
expect(queryForHighReply.entries?.length).toBe(1);
|
|
2348
2332
|
expect(queryForHighReply.entries[0].recordId).toBe(danielRecord.message.recordId);
|
|
2349
2333
|
// query for all records that received higher (and including) a 75
|
|
2350
2334
|
// three records should match
|
|
2351
|
-
const queryForPassingGrade =
|
|
2335
|
+
const queryForPassingGrade = await TestDataGenerator.generateRecordsQuery({
|
|
2352
2336
|
author: alice,
|
|
2353
2337
|
filter: {
|
|
2354
2338
|
schema: 'test',
|
|
@@ -2357,15 +2341,15 @@ export function testRecordsTags() {
|
|
|
2357
2341
|
}
|
|
2358
2342
|
}
|
|
2359
2343
|
});
|
|
2360
|
-
const queryForPassingGradeReply =
|
|
2344
|
+
const queryForPassingGradeReply = await dwn.processMessage(alice.did, queryForPassingGrade.message);
|
|
2361
2345
|
expect(queryForPassingGradeReply.status.code).toBe(200);
|
|
2362
|
-
expect(
|
|
2346
|
+
expect(queryForPassingGradeReply.entries?.length).toBe(3);
|
|
2363
2347
|
const passingRecords = queryForPassingGradeReply.entries.map(entry => entry.recordId);
|
|
2364
2348
|
expect(passingRecords).toEqual(expect.arrayContaining([
|
|
2365
2349
|
danielRecord.message.recordId, bobRecord.message.recordId, aliceRecord.message.recordId
|
|
2366
2350
|
]));
|
|
2367
2351
|
// query for poorly performing grades (65 and below, inclusive)
|
|
2368
|
-
const queryForPoorGrades =
|
|
2352
|
+
const queryForPoorGrades = await TestDataGenerator.generateRecordsQuery({
|
|
2369
2353
|
author: alice,
|
|
2370
2354
|
filter: {
|
|
2371
2355
|
schema: 'test',
|
|
@@ -2374,12 +2358,12 @@ export function testRecordsTags() {
|
|
|
2374
2358
|
}
|
|
2375
2359
|
}
|
|
2376
2360
|
});
|
|
2377
|
-
const queryForPoorGradesReply =
|
|
2361
|
+
const queryForPoorGradesReply = await dwn.processMessage(alice.did, queryForPoorGrades.message);
|
|
2378
2362
|
expect(queryForPoorGradesReply.status.code).toBe(200);
|
|
2379
|
-
expect(
|
|
2363
|
+
expect(queryForPoorGradesReply.entries?.length).toBe(1);
|
|
2380
2364
|
expect(queryForPoorGradesReply.entries[0].recordId).toBe(carolRecord.message.recordId);
|
|
2381
2365
|
// query for passing grades that were not perfect scores
|
|
2382
|
-
const queryForRange =
|
|
2366
|
+
const queryForRange = await TestDataGenerator.generateRecordsQuery({
|
|
2383
2367
|
author: alice,
|
|
2384
2368
|
filter: {
|
|
2385
2369
|
schema: 'test',
|
|
@@ -2388,16 +2372,15 @@ export function testRecordsTags() {
|
|
|
2388
2372
|
}
|
|
2389
2373
|
}
|
|
2390
2374
|
});
|
|
2391
|
-
const queryForRangeReply =
|
|
2375
|
+
const queryForRangeReply = await dwn.processMessage(alice.did, queryForRange.message);
|
|
2392
2376
|
expect(queryForRangeReply.status.code).toBe(200);
|
|
2393
|
-
expect(
|
|
2377
|
+
expect(queryForRangeReply.entries?.length).toBe(2);
|
|
2394
2378
|
const rangeRecords = queryForRangeReply.entries.map(entry => entry.recordId);
|
|
2395
2379
|
expect(rangeRecords).toEqual(expect.arrayContaining([bobRecord.message.recordId, aliceRecord.message.recordId]));
|
|
2396
|
-
})
|
|
2397
|
-
it('should return results based on the latest tag values', () =>
|
|
2398
|
-
|
|
2399
|
-
const
|
|
2400
|
-
const tagsRecord1 = yield TestDataGenerator.generateRecordsWrite({
|
|
2380
|
+
});
|
|
2381
|
+
it('should return results based on the latest tag values', async () => {
|
|
2382
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
2383
|
+
const tagsRecord1 = await TestDataGenerator.generateRecordsWrite({
|
|
2401
2384
|
author: alice,
|
|
2402
2385
|
published: true,
|
|
2403
2386
|
schema: 'post',
|
|
@@ -2405,9 +2388,9 @@ export function testRecordsTags() {
|
|
|
2405
2388
|
stringTag: 'string-value',
|
|
2406
2389
|
}
|
|
2407
2390
|
});
|
|
2408
|
-
const tagsRecord1Reply =
|
|
2391
|
+
const tagsRecord1Reply = await dwn.processMessage(alice.did, tagsRecord1.message, { dataStream: tagsRecord1.dataStream });
|
|
2409
2392
|
expect(tagsRecord1Reply.status.code).toBe(202);
|
|
2410
|
-
const tagsQueryMatch =
|
|
2393
|
+
const tagsQueryMatch = await TestDataGenerator.generateRecordsQuery({
|
|
2411
2394
|
author: alice,
|
|
2412
2395
|
filter: {
|
|
2413
2396
|
tags: {
|
|
@@ -2415,27 +2398,26 @@ export function testRecordsTags() {
|
|
|
2415
2398
|
}
|
|
2416
2399
|
}
|
|
2417
2400
|
});
|
|
2418
|
-
const tagsQueryMatchReply =
|
|
2401
|
+
const tagsQueryMatchReply = await dwn.processMessage(alice.did, tagsQueryMatch.message);
|
|
2419
2402
|
expect(tagsQueryMatchReply.status.code).toBe(200);
|
|
2420
|
-
expect(
|
|
2403
|
+
expect(tagsQueryMatchReply.entries?.length).toBe(1);
|
|
2421
2404
|
expect(tagsQueryMatchReply.entries[0].recordId).toBe(tagsRecord1.message.recordId);
|
|
2422
2405
|
// update the record with new tags
|
|
2423
|
-
const updatedRecord =
|
|
2406
|
+
const updatedRecord = await TestDataGenerator.generateFromRecordsWrite({
|
|
2424
2407
|
author: alice,
|
|
2425
2408
|
existingWrite: tagsRecord1.recordsWrite,
|
|
2426
2409
|
tags: { otherTag: 'other-value' } // new tags
|
|
2427
2410
|
});
|
|
2428
|
-
const updatedRecordReply =
|
|
2411
|
+
const updatedRecordReply = await dwn.processMessage(alice.did, updatedRecord.message, { dataStream: updatedRecord.dataStream });
|
|
2429
2412
|
expect(updatedRecordReply.status.code).toBe(202);
|
|
2430
2413
|
// issuing the same query should return no results
|
|
2431
|
-
const tagsQueryMatchReply2 =
|
|
2414
|
+
const tagsQueryMatchReply2 = await dwn.processMessage(alice.did, tagsQueryMatch.message);
|
|
2432
2415
|
expect(tagsQueryMatchReply2.status.code).toBe(200);
|
|
2433
|
-
expect(
|
|
2434
|
-
})
|
|
2435
|
-
it('should not return results if the record was updated with empty tags', () =>
|
|
2436
|
-
|
|
2437
|
-
const
|
|
2438
|
-
const tagsRecord1 = yield TestDataGenerator.generateRecordsWrite({
|
|
2416
|
+
expect(tagsQueryMatchReply2.entries?.length).toBe(0);
|
|
2417
|
+
});
|
|
2418
|
+
it('should not return results if the record was updated with empty tags', async () => {
|
|
2419
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
2420
|
+
const tagsRecord1 = await TestDataGenerator.generateRecordsWrite({
|
|
2439
2421
|
author: alice,
|
|
2440
2422
|
published: true,
|
|
2441
2423
|
schema: 'post',
|
|
@@ -2443,9 +2425,9 @@ export function testRecordsTags() {
|
|
|
2443
2425
|
stringTag: 'string-value',
|
|
2444
2426
|
}
|
|
2445
2427
|
});
|
|
2446
|
-
const tagsRecord1Reply =
|
|
2428
|
+
const tagsRecord1Reply = await dwn.processMessage(alice.did, tagsRecord1.message, { dataStream: tagsRecord1.dataStream });
|
|
2447
2429
|
expect(tagsRecord1Reply.status.code).toBe(202);
|
|
2448
|
-
const tagsQueryMatch =
|
|
2430
|
+
const tagsQueryMatch = await TestDataGenerator.generateRecordsQuery({
|
|
2449
2431
|
author: alice,
|
|
2450
2432
|
filter: {
|
|
2451
2433
|
tags: {
|
|
@@ -2453,29 +2435,28 @@ export function testRecordsTags() {
|
|
|
2453
2435
|
}
|
|
2454
2436
|
}
|
|
2455
2437
|
});
|
|
2456
|
-
const tagsQueryMatchReply =
|
|
2438
|
+
const tagsQueryMatchReply = await dwn.processMessage(alice.did, tagsQueryMatch.message);
|
|
2457
2439
|
expect(tagsQueryMatchReply.status.code).toBe(200);
|
|
2458
|
-
expect(
|
|
2440
|
+
expect(tagsQueryMatchReply.entries?.length).toBe(1);
|
|
2459
2441
|
expect(tagsQueryMatchReply.entries[0].recordId).toBe(tagsRecord1.message.recordId);
|
|
2460
2442
|
// update the record without any tags
|
|
2461
|
-
const updatedRecord =
|
|
2443
|
+
const updatedRecord = await TestDataGenerator.generateFromRecordsWrite({
|
|
2462
2444
|
author: alice,
|
|
2463
2445
|
existingWrite: tagsRecord1.recordsWrite,
|
|
2464
2446
|
});
|
|
2465
|
-
const updatedRecordReply =
|
|
2447
|
+
const updatedRecordReply = await dwn.processMessage(alice.did, updatedRecord.message, { dataStream: updatedRecord.dataStream });
|
|
2466
2448
|
expect(updatedRecordReply.status.code).toBe(202);
|
|
2467
2449
|
// issuing the same query should return no results
|
|
2468
|
-
const tagsQueryMatchReply2 =
|
|
2450
|
+
const tagsQueryMatchReply2 = await dwn.processMessage(alice.did, tagsQueryMatch.message);
|
|
2469
2451
|
expect(tagsQueryMatchReply2.status.code).toBe(200);
|
|
2470
|
-
expect(
|
|
2471
|
-
})
|
|
2452
|
+
expect(tagsQueryMatchReply2.entries?.length).toBe(0);
|
|
2453
|
+
});
|
|
2472
2454
|
});
|
|
2473
2455
|
describe('RecordsDelete with tags', () => {
|
|
2474
|
-
it('should delete record with tags', () =>
|
|
2475
|
-
|
|
2476
|
-
const alice = yield TestDataGenerator.generateDidKeyPersona();
|
|
2456
|
+
it('should delete record with tags', async () => {
|
|
2457
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
2477
2458
|
// create a record with a tag
|
|
2478
|
-
const tagsRecord1 =
|
|
2459
|
+
const tagsRecord1 = await TestDataGenerator.generateRecordsWrite({
|
|
2479
2460
|
author: alice,
|
|
2480
2461
|
published: true,
|
|
2481
2462
|
schema: 'post',
|
|
@@ -2483,10 +2464,10 @@ export function testRecordsTags() {
|
|
|
2483
2464
|
stringTag: 'string-value',
|
|
2484
2465
|
}
|
|
2485
2466
|
});
|
|
2486
|
-
const tagsRecord1Reply =
|
|
2467
|
+
const tagsRecord1Reply = await dwn.processMessage(alice.did, tagsRecord1.message, { dataStream: tagsRecord1.dataStream });
|
|
2487
2468
|
expect(tagsRecord1Reply.status.code).toBe(202);
|
|
2488
2469
|
//sanity: query for the record
|
|
2489
|
-
const tagsQueryMatch =
|
|
2470
|
+
const tagsQueryMatch = await TestDataGenerator.generateRecordsQuery({
|
|
2490
2471
|
author: alice,
|
|
2491
2472
|
filter: {
|
|
2492
2473
|
tags: {
|
|
@@ -2494,22 +2475,22 @@ export function testRecordsTags() {
|
|
|
2494
2475
|
}
|
|
2495
2476
|
}
|
|
2496
2477
|
});
|
|
2497
|
-
const tagsQueryMatchReply =
|
|
2478
|
+
const tagsQueryMatchReply = await dwn.processMessage(alice.did, tagsQueryMatch.message);
|
|
2498
2479
|
expect(tagsQueryMatchReply.status.code).toBe(200);
|
|
2499
|
-
expect(
|
|
2480
|
+
expect(tagsQueryMatchReply.entries?.length).toBe(1);
|
|
2500
2481
|
expect(tagsQueryMatchReply.entries[0].recordId).toBe(tagsRecord1.message.recordId);
|
|
2501
2482
|
// delete the record
|
|
2502
|
-
const recordDelete =
|
|
2483
|
+
const recordDelete = await TestDataGenerator.generateRecordsDelete({
|
|
2503
2484
|
author: alice,
|
|
2504
2485
|
recordId: tagsRecord1.message.recordId,
|
|
2505
2486
|
});
|
|
2506
|
-
const recordDeleteReply =
|
|
2487
|
+
const recordDeleteReply = await dwn.processMessage(alice.did, recordDelete.message);
|
|
2507
2488
|
expect(recordDeleteReply.status.code).toBe(202);
|
|
2508
2489
|
// issue the the same query should return no results
|
|
2509
|
-
const tagsQueryMatchReply2 =
|
|
2490
|
+
const tagsQueryMatchReply2 = await dwn.processMessage(alice.did, tagsQueryMatch.message);
|
|
2510
2491
|
expect(tagsQueryMatchReply2.status.code).toBe(200);
|
|
2511
|
-
expect(
|
|
2512
|
-
})
|
|
2492
|
+
expect(tagsQueryMatchReply2.entries?.length).toBe(0);
|
|
2493
|
+
});
|
|
2513
2494
|
});
|
|
2514
2495
|
});
|
|
2515
2496
|
}
|