@enbox/dwn-sdk-js 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.mjs +8 -8
- package/dist/browser.mjs.map +4 -4
- package/dist/esm/generated/precompiled-validators.js +762 -911
- package/dist/esm/generated/precompiled-validators.js.map +1 -1
- package/dist/esm/src/core/abstract-message.js +4 -0
- package/dist/esm/src/core/abstract-message.js.map +1 -1
- package/dist/esm/src/core/auth.js +22 -33
- package/dist/esm/src/core/auth.js.map +1 -1
- package/dist/esm/src/core/constants.js +11 -0
- package/dist/esm/src/core/constants.js.map +1 -0
- package/dist/esm/src/core/core-protocol.js +44 -0
- package/dist/esm/src/core/core-protocol.js.map +1 -0
- package/dist/esm/src/core/dwn-constant.js +7 -7
- package/dist/esm/src/core/dwn-constant.js.map +1 -1
- package/dist/esm/src/core/dwn-error.js +10 -12
- package/dist/esm/src/core/dwn-error.js.map +1 -1
- package/dist/esm/src/core/grant-authorization.js +50 -52
- package/dist/esm/src/core/grant-authorization.js.map +1 -1
- package/dist/esm/src/core/message.js +85 -116
- package/dist/esm/src/core/message.js.map +1 -1
- package/dist/esm/src/core/messages-grant-authorization.js +63 -78
- package/dist/esm/src/core/messages-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/protocol-authorization-action.js +266 -0
- package/dist/esm/src/core/protocol-authorization-action.js.map +1 -0
- package/dist/esm/src/core/protocol-authorization-validation.js +321 -0
- package/dist/esm/src/core/protocol-authorization-validation.js.map +1 -0
- package/dist/esm/src/core/protocol-authorization.js +144 -741
- package/dist/esm/src/core/protocol-authorization.js.map +1 -1
- package/dist/esm/src/core/protocols-grant-authorization.js +24 -38
- package/dist/esm/src/core/protocols-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/record-chain.js +64 -0
- package/dist/esm/src/core/record-chain.js.map +1 -0
- package/dist/esm/src/core/records-grant-authorization.js +53 -72
- package/dist/esm/src/core/records-grant-authorization.js.map +1 -1
- package/dist/esm/src/core/resumable-task-manager.js +50 -65
- package/dist/esm/src/core/resumable-task-manager.js.map +1 -1
- package/dist/esm/src/core/tenant-gate.js +2 -13
- package/dist/esm/src/core/tenant-gate.js.map +1 -1
- package/dist/esm/src/dwn.js +108 -101
- package/dist/esm/src/dwn.js.map +1 -1
- package/dist/esm/src/event-stream/event-emitter-event-log.js +204 -0
- package/dist/esm/src/event-stream/event-emitter-event-log.js.map +1 -0
- package/dist/esm/src/handlers/messages-read.js +67 -81
- package/dist/esm/src/handlers/messages-read.js.map +1 -1
- package/dist/esm/src/handlers/messages-subscribe.js +51 -63
- package/dist/esm/src/handlers/messages-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/messages-sync.js +75 -89
- package/dist/esm/src/handlers/messages-sync.js.map +1 -1
- package/dist/esm/src/handlers/protocols-configure.js +153 -163
- package/dist/esm/src/handlers/protocols-configure.js.map +1 -1
- package/dist/esm/src/handlers/protocols-query.js +52 -55
- package/dist/esm/src/handlers/protocols-query.js.map +1 -1
- package/dist/esm/src/handlers/records-count.js +97 -85
- package/dist/esm/src/handlers/records-count.js.map +1 -1
- package/dist/esm/src/handlers/records-delete.js +75 -93
- package/dist/esm/src/handlers/records-delete.js.map +1 -1
- package/dist/esm/src/handlers/records-query.js +116 -105
- package/dist/esm/src/handlers/records-query.js.map +1 -1
- package/dist/esm/src/handlers/records-read.js +130 -132
- package/dist/esm/src/handlers/records-read.js.map +1 -1
- package/dist/esm/src/handlers/records-subscribe.js +164 -104
- package/dist/esm/src/handlers/records-subscribe.js.map +1 -1
- package/dist/esm/src/handlers/records-write.js +213 -280
- package/dist/esm/src/handlers/records-write.js.map +1 -1
- package/dist/esm/src/index.js +5 -2
- package/dist/esm/src/index.js.map +1 -1
- package/dist/esm/src/interfaces/messages-read.js +24 -32
- package/dist/esm/src/interfaces/messages-read.js.map +1 -1
- package/dist/esm/src/interfaces/messages-subscribe.js +28 -41
- package/dist/esm/src/interfaces/messages-subscribe.js.map +1 -1
- package/dist/esm/src/interfaces/messages-sync.js +26 -40
- package/dist/esm/src/interfaces/messages-sync.js.map +1 -1
- package/dist/esm/src/interfaces/protocols-configure.js +87 -65
- package/dist/esm/src/interfaces/protocols-configure.js.map +1 -1
- package/dist/esm/src/interfaces/protocols-query.js +55 -68
- package/dist/esm/src/interfaces/protocols-query.js.map +1 -1
- package/dist/esm/src/interfaces/records-count.js +50 -66
- package/dist/esm/src/interfaces/records-count.js.map +1 -1
- package/dist/esm/src/interfaces/records-delete.js +45 -55
- package/dist/esm/src/interfaces/records-delete.js.map +1 -1
- package/dist/esm/src/interfaces/records-query.js +60 -76
- package/dist/esm/src/interfaces/records-query.js.map +1 -1
- package/dist/esm/src/interfaces/records-read.js +51 -67
- package/dist/esm/src/interfaces/records-read.js.map +1 -1
- package/dist/esm/src/interfaces/records-subscribe.js +53 -68
- package/dist/esm/src/interfaces/records-subscribe.js.map +1 -1
- package/dist/esm/src/interfaces/records-write-query.js +102 -0
- package/dist/esm/src/interfaces/records-write-query.js.map +1 -0
- package/dist/esm/src/interfaces/records-write-signing.js +81 -0
- package/dist/esm/src/interfaces/records-write-signing.js.map +1 -0
- package/dist/esm/src/interfaces/records-write.js +396 -610
- package/dist/esm/src/interfaces/records-write.js.map +1 -1
- package/dist/esm/src/jose/algorithms/signing/ed25519.js +10 -19
- package/dist/esm/src/jose/algorithms/signing/ed25519.js.map +1 -1
- package/dist/esm/src/jose/jws/general/builder.js +23 -35
- package/dist/esm/src/jose/jws/general/builder.js.map +1 -1
- package/dist/esm/src/jose/jws/general/verifier.js +56 -69
- package/dist/esm/src/jose/jws/general/verifier.js.map +1 -1
- package/dist/esm/src/protocols/permission-grant.js +43 -14
- package/dist/esm/src/protocols/permission-grant.js.map +1 -1
- package/dist/esm/src/protocols/permission-request.js +28 -14
- package/dist/esm/src/protocols/permission-request.js.map +1 -1
- package/dist/esm/src/protocols/permissions.js +325 -227
- package/dist/esm/src/protocols/permissions.js.map +1 -1
- package/dist/esm/src/smt/smt-store-level.js +42 -64
- package/dist/esm/src/smt/smt-store-level.js.map +1 -1
- package/dist/esm/src/smt/smt-store-memory.js +19 -45
- package/dist/esm/src/smt/smt-store-memory.js.map +1 -1
- package/dist/esm/src/smt/smt-utils.js +28 -45
- package/dist/esm/src/smt/smt-utils.js.map +1 -1
- package/dist/esm/src/smt/sparse-merkle-tree.js +426 -471
- package/dist/esm/src/smt/sparse-merkle-tree.js.map +1 -1
- package/dist/esm/src/state-index/state-index-level.js +113 -150
- package/dist/esm/src/state-index/state-index-level.js.map +1 -1
- package/dist/esm/src/store/blockstore-level.js +54 -156
- package/dist/esm/src/store/blockstore-level.js.map +1 -1
- package/dist/esm/src/store/blockstore-mock.js +48 -153
- package/dist/esm/src/store/blockstore-mock.js.map +1 -1
- package/dist/esm/src/store/data-store-level.js +137 -100
- package/dist/esm/src/store/data-store-level.js.map +1 -1
- package/dist/esm/src/store/index-level-compound.js +246 -0
- package/dist/esm/src/store/index-level-compound.js.map +1 -0
- package/dist/esm/src/store/index-level.js +307 -715
- package/dist/esm/src/store/index-level.js.map +1 -1
- package/dist/esm/src/store/level-wrapper.js +143 -244
- package/dist/esm/src/store/level-wrapper.js.map +1 -1
- package/dist/esm/src/store/message-store-level.js +71 -94
- package/dist/esm/src/store/message-store-level.js.map +1 -1
- package/dist/esm/src/store/resumable-task-store-level.js +62 -101
- package/dist/esm/src/store/resumable-task-store-level.js.map +1 -1
- package/dist/esm/src/store/storage-controller.js +131 -146
- package/dist/esm/src/store/storage-controller.js.map +1 -1
- package/dist/esm/src/types/permission-types.js.map +1 -1
- package/dist/esm/src/types/protocols-types.js +10 -0
- package/dist/esm/src/types/protocols-types.js.map +1 -1
- package/dist/esm/src/types/records-types.js.map +1 -1
- package/dist/esm/src/utils/abort.js +8 -19
- package/dist/esm/src/utils/abort.js.map +1 -1
- package/dist/esm/src/utils/array.js +15 -49
- package/dist/esm/src/utils/array.js.map +1 -1
- package/dist/esm/src/utils/cid.js +29 -77
- package/dist/esm/src/utils/cid.js.map +1 -1
- package/dist/esm/src/utils/data-stream.js +37 -65
- package/dist/esm/src/utils/data-stream.js.map +1 -1
- package/dist/esm/src/utils/encryption.js +136 -162
- package/dist/esm/src/utils/encryption.js.map +1 -1
- package/dist/esm/src/utils/filter.js +1 -12
- package/dist/esm/src/utils/filter.js.map +1 -1
- package/dist/esm/src/utils/hd-key.js +45 -71
- package/dist/esm/src/utils/hd-key.js.map +1 -1
- package/dist/esm/src/utils/jws.js +9 -20
- package/dist/esm/src/utils/jws.js.map +1 -1
- package/dist/esm/src/utils/memory-cache.js +12 -23
- package/dist/esm/src/utils/memory-cache.js.map +1 -1
- package/dist/esm/src/utils/messages.js +21 -33
- package/dist/esm/src/utils/messages.js.map +1 -1
- package/dist/esm/src/utils/private-key-signer.js +9 -17
- package/dist/esm/src/utils/private-key-signer.js.map +1 -1
- package/dist/esm/src/utils/protocols.js +62 -70
- package/dist/esm/src/utils/protocols.js.map +1 -1
- package/dist/esm/src/utils/records.js +103 -166
- package/dist/esm/src/utils/records.js.map +1 -1
- package/dist/esm/src/utils/secp256k1.js +60 -96
- package/dist/esm/src/utils/secp256k1.js.map +1 -1
- package/dist/esm/src/utils/secp256r1.js +54 -71
- package/dist/esm/src/utils/secp256r1.js.map +1 -1
- package/dist/esm/src/utils/time.js +5 -18
- package/dist/esm/src/utils/time.js.map +1 -1
- package/dist/esm/src/utils/url.js +3 -3
- package/dist/esm/src/utils/url.js.map +1 -1
- package/dist/esm/tests/core/auth.spec.js +3 -12
- package/dist/esm/tests/core/auth.spec.js.map +1 -1
- package/dist/esm/tests/core/message.spec.js +50 -59
- package/dist/esm/tests/core/message.spec.js.map +1 -1
- package/dist/esm/tests/core/protocol-authorization.spec.js +10 -18
- package/dist/esm/tests/core/protocol-authorization.spec.js.map +1 -1
- package/dist/esm/tests/dwn.spec.js +65 -89
- package/dist/esm/tests/dwn.spec.js.map +1 -1
- package/dist/esm/tests/event-emitter-event-log.spec.js +305 -0
- package/dist/esm/tests/event-emitter-event-log.spec.js.map +1 -0
- package/dist/esm/tests/features/author-delegated-grant.spec.js +337 -347
- package/dist/esm/tests/features/author-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-delegated-grant.spec.js +160 -172
- package/dist/esm/tests/features/owner-delegated-grant.spec.js.map +1 -1
- package/dist/esm/tests/features/owner-signature.spec.js +78 -82
- package/dist/esm/tests/features/owner-signature.spec.js.map +1 -1
- package/dist/esm/tests/features/permissions.spec.js +449 -184
- package/dist/esm/tests/features/permissions.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-composition.spec.js +981 -360
- package/dist/esm/tests/features/protocol-composition.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-create-action.spec.js +45 -54
- package/dist/esm/tests/features/protocol-create-action.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-delete-action.spec.js +99 -108
- package/dist/esm/tests/features/protocol-delete-action.spec.js.map +1 -1
- package/dist/esm/tests/features/protocol-update-action.spec.js +108 -117
- package/dist/esm/tests/features/protocol-update-action.spec.js.map +1 -1
- package/dist/esm/tests/features/records-immutable.spec.js +315 -0
- package/dist/esm/tests/features/records-immutable.spec.js.map +1 -0
- package/dist/esm/tests/features/records-prune.spec.js +178 -194
- package/dist/esm/tests/features/records-prune.spec.js.map +1 -1
- package/dist/esm/tests/features/records-record-limit.spec.js +542 -0
- package/dist/esm/tests/features/records-record-limit.spec.js.map +1 -0
- package/dist/esm/tests/features/records-tags.spec.js +456 -463
- package/dist/esm/tests/features/records-tags.spec.js.map +1 -1
- package/dist/esm/tests/features/resumable-tasks.spec.js +88 -98
- package/dist/esm/tests/features/resumable-tasks.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-read.spec.js +215 -210
- package/dist/esm/tests/handlers/messages-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-subscribe.spec.js +309 -171
- package/dist/esm/tests/handlers/messages-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/messages-sync.spec.js +272 -199
- package/dist/esm/tests/handlers/messages-sync.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-configure.spec.js +247 -241
- package/dist/esm/tests/handlers/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/handlers/protocols-query.spec.js +159 -172
- package/dist/esm/tests/handlers/protocols-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-count.spec.js +101 -105
- package/dist/esm/tests/handlers/records-count.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-delete.spec.js +266 -279
- package/dist/esm/tests/handlers/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-query.spec.js +984 -996
- package/dist/esm/tests/handlers/records-query.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-read.spec.js +542 -671
- package/dist/esm/tests/handlers/records-read.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-subscribe.spec.js +433 -302
- package/dist/esm/tests/handlers/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/handlers/records-write.spec.js +1216 -1140
- package/dist/esm/tests/handlers/records-write.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/messages-get.spec.js +39 -48
- package/dist/esm/tests/interfaces/messages-get.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/messages-subscribe.spec.js +4 -13
- package/dist/esm/tests/interfaces/messages-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/protocols-configure.spec.js +212 -88
- package/dist/esm/tests/interfaces/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/protocols-query.spec.js +8 -17
- package/dist/esm/tests/interfaces/protocols-query.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-delete.spec.js +8 -17
- package/dist/esm/tests/interfaces/records-delete.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-query.spec.js +20 -29
- package/dist/esm/tests/interfaces/records-query.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-read.spec.js +42 -51
- package/dist/esm/tests/interfaces/records-read.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-subscribe.spec.js +16 -25
- package/dist/esm/tests/interfaces/records-subscribe.spec.js.map +1 -1
- package/dist/esm/tests/interfaces/records-write.spec.js +190 -219
- package/dist/esm/tests/interfaces/records-write.spec.js.map +1 -1
- package/dist/esm/tests/jose/jws/general.spec.js +36 -45
- package/dist/esm/tests/jose/jws/general.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permission-grant.spec.js +44 -50
- package/dist/esm/tests/protocols/permission-grant.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permission-request.spec.js +23 -32
- package/dist/esm/tests/protocols/permission-request.spec.js.map +1 -1
- package/dist/esm/tests/protocols/permissions.spec.js +49 -55
- package/dist/esm/tests/protocols/permissions.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/aggregator.spec.js +127 -138
- package/dist/esm/tests/scenarios/aggregator.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/deleted-record.spec.js +372 -36
- package/dist/esm/tests/scenarios/deleted-record.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js +55 -64
- package/dist/esm/tests/scenarios/end-to-end-tests.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/nested-roles.spec.js +66 -76
- package/dist/esm/tests/scenarios/nested-roles.spec.js.map +1 -1
- package/dist/esm/tests/scenarios/subscriptions.spec.js +451 -354
- package/dist/esm/tests/scenarios/subscriptions.spec.js.map +1 -1
- package/dist/esm/tests/smt/smt-store-level.spec.js +76 -87
- package/dist/esm/tests/smt/smt-store-level.spec.js.map +1 -1
- package/dist/esm/tests/smt/sparse-merkle-tree.spec.js +344 -353
- package/dist/esm/tests/smt/sparse-merkle-tree.spec.js.map +1 -1
- package/dist/esm/tests/state-index/state-index-level.spec.js +117 -126
- package/dist/esm/tests/state-index/state-index-level.spec.js.map +1 -1
- package/dist/esm/tests/store/blockstore-level.spec.js +44 -99
- package/dist/esm/tests/store/blockstore-level.spec.js.map +1 -1
- package/dist/esm/tests/store/blockstore-mock.spec.js +40 -120
- package/dist/esm/tests/store/blockstore-mock.spec.js.map +1 -1
- package/dist/esm/tests/store/data-store-level.spec.js +160 -108
- package/dist/esm/tests/store/data-store-level.spec.js.map +1 -1
- package/dist/esm/tests/store/index-level.spec.js +404 -414
- package/dist/esm/tests/store/index-level.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store-level.spec.js +13 -22
- package/dist/esm/tests/store/message-store-level.spec.js.map +1 -1
- package/dist/esm/tests/store/message-store.spec.js +229 -238
- package/dist/esm/tests/store/message-store.spec.js.map +1 -1
- package/dist/esm/tests/test-event-stream.js +12 -13
- package/dist/esm/tests/test-event-stream.js.map +1 -1
- package/dist/esm/tests/test-stores.js +16 -13
- package/dist/esm/tests/test-stores.js.map +1 -1
- package/dist/esm/tests/test-suite.js +8 -15
- package/dist/esm/tests/test-suite.js.map +1 -1
- package/dist/esm/tests/utils/cid.spec.js +24 -33
- package/dist/esm/tests/utils/cid.spec.js.map +1 -1
- package/dist/esm/tests/utils/data-stream.spec.js +48 -57
- package/dist/esm/tests/utils/data-stream.spec.js.map +1 -1
- package/dist/esm/tests/utils/encryption-callbacks.spec.js +45 -54
- package/dist/esm/tests/utils/encryption-callbacks.spec.js.map +1 -1
- package/dist/esm/tests/utils/encryption.spec.js +229 -82
- package/dist/esm/tests/utils/encryption.spec.js.map +1 -1
- package/dist/esm/tests/utils/filters.spec.js +46 -55
- package/dist/esm/tests/utils/filters.spec.js.map +1 -1
- package/dist/esm/tests/utils/hd-key.spec.js +10 -19
- package/dist/esm/tests/utils/hd-key.spec.js.map +1 -1
- package/dist/esm/tests/utils/jws.spec.js +3 -12
- package/dist/esm/tests/utils/jws.spec.js.map +1 -1
- package/dist/esm/tests/utils/memory-cache.spec.js +9 -18
- package/dist/esm/tests/utils/memory-cache.spec.js.map +1 -1
- package/dist/esm/tests/utils/messages.spec.js +18 -20
- package/dist/esm/tests/utils/messages.spec.js.map +1 -1
- package/dist/esm/tests/utils/poller.js +22 -33
- package/dist/esm/tests/utils/poller.js.map +1 -1
- package/dist/esm/tests/utils/private-key-signer.spec.js +15 -24
- package/dist/esm/tests/utils/private-key-signer.spec.js.map +1 -1
- package/dist/esm/tests/utils/records.spec.js +14 -27
- package/dist/esm/tests/utils/records.spec.js.map +1 -1
- package/dist/esm/tests/utils/secp256k1.spec.js +16 -25
- package/dist/esm/tests/utils/secp256k1.spec.js.map +1 -1
- package/dist/esm/tests/utils/secp256r1.spec.js +18 -27
- package/dist/esm/tests/utils/secp256r1.spec.js.map +1 -1
- package/dist/esm/tests/utils/test-data-generator.js +446 -467
- package/dist/esm/tests/utils/test-data-generator.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/definitions.spec.js +2 -11
- package/dist/esm/tests/validation/json-schemas/definitions.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js +4 -13
- package/dist/esm/tests/validation/json-schemas/jwk/general-jwk.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js +8 -17
- package/dist/esm/tests/validation/json-schemas/jwk/public-jwk.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js +3 -12
- package/dist/esm/tests/validation/json-schemas/jwk-verification-method.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js +4 -13
- package/dist/esm/tests/validation/json-schemas/protocols/protocols-configure.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js +2 -11
- package/dist/esm/tests/validation/json-schemas/records/records-query.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/records/records-read.spec.js +2 -11
- package/dist/esm/tests/validation/json-schemas/records/records-read.spec.js.map +1 -1
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js +44 -24
- package/dist/esm/tests/validation/json-schemas/records/records-write.spec.js.map +1 -1
- package/dist/types/generated/precompiled-validators.d.ts +49 -40
- package/dist/types/generated/precompiled-validators.d.ts.map +1 -1
- package/dist/types/src/core/constants.d.ts +11 -0
- package/dist/types/src/core/constants.d.ts.map +1 -0
- package/dist/types/src/core/core-protocol.d.ts +89 -0
- package/dist/types/src/core/core-protocol.d.ts.map +1 -0
- package/dist/types/src/core/dwn-error.d.ts +9 -12
- package/dist/types/src/core/dwn-error.d.ts.map +1 -1
- package/dist/types/src/core/grant-authorization.d.ts +6 -2
- package/dist/types/src/core/grant-authorization.d.ts.map +1 -1
- package/dist/types/src/core/protocol-authorization-action.d.ts +42 -0
- package/dist/types/src/core/protocol-authorization-action.d.ts.map +1 -0
- package/dist/types/src/core/protocol-authorization-validation.d.ts +81 -0
- package/dist/types/src/core/protocol-authorization-validation.d.ts.map +1 -0
- package/dist/types/src/core/protocol-authorization.d.ts +24 -106
- package/dist/types/src/core/protocol-authorization.d.ts.map +1 -1
- package/dist/types/src/core/record-chain.d.ts +24 -0
- package/dist/types/src/core/record-chain.d.ts.map +1 -0
- package/dist/types/src/core/records-grant-authorization.d.ts.map +1 -1
- package/dist/types/src/dwn.d.ts +19 -7
- package/dist/types/src/dwn.d.ts.map +1 -1
- package/dist/types/src/event-stream/event-emitter-event-log.d.ts +50 -0
- package/dist/types/src/event-stream/event-emitter-event-log.d.ts.map +1 -0
- package/dist/types/src/handlers/messages-read.d.ts +3 -8
- package/dist/types/src/handlers/messages-read.d.ts.map +1 -1
- package/dist/types/src/handlers/messages-subscribe.d.ts +6 -10
- package/dist/types/src/handlers/messages-subscribe.d.ts.map +1 -1
- package/dist/types/src/handlers/messages-sync.d.ts +3 -8
- package/dist/types/src/handlers/messages-sync.d.ts.map +1 -1
- package/dist/types/src/handlers/protocols-configure.d.ts +3 -10
- package/dist/types/src/handlers/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/handlers/protocols-query.d.ts +3 -8
- package/dist/types/src/handlers/protocols-query.d.ts.map +1 -1
- package/dist/types/src/handlers/records-count.d.ts +3 -6
- package/dist/types/src/handlers/records-count.d.ts.map +1 -1
- package/dist/types/src/handlers/records-delete.d.ts +3 -8
- package/dist/types/src/handlers/records-delete.d.ts.map +1 -1
- package/dist/types/src/handlers/records-query.d.ts +3 -8
- package/dist/types/src/handlers/records-query.d.ts.map +1 -1
- package/dist/types/src/handlers/records-read.d.ts +3 -8
- package/dist/types/src/handlers/records-read.d.ts.map +1 -1
- package/dist/types/src/handlers/records-subscribe.d.ts +8 -10
- package/dist/types/src/handlers/records-subscribe.d.ts.map +1 -1
- package/dist/types/src/handlers/records-write.d.ts +4 -24
- package/dist/types/src/handlers/records-write.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +8 -4
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/interfaces/messages-subscribe.d.ts +5 -0
- package/dist/types/src/interfaces/messages-subscribe.d.ts.map +1 -1
- package/dist/types/src/interfaces/protocols-configure.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-subscribe.d.ts +5 -0
- package/dist/types/src/interfaces/records-subscribe.d.ts.map +1 -1
- package/dist/types/src/interfaces/records-write-query.d.ts +33 -0
- package/dist/types/src/interfaces/records-write-query.d.ts.map +1 -0
- package/dist/types/src/interfaces/records-write-signing.d.ts +34 -0
- package/dist/types/src/interfaces/records-write-signing.d.ts.map +1 -0
- package/dist/types/src/interfaces/records-write.d.ts +13 -53
- package/dist/types/src/interfaces/records-write.d.ts.map +1 -1
- package/dist/types/src/protocols/permission-grant.d.ts +1 -1
- package/dist/types/src/protocols/permission-grant.d.ts.map +1 -1
- package/dist/types/src/protocols/permission-request.d.ts +1 -1
- package/dist/types/src/protocols/permission-request.d.ts.map +1 -1
- package/dist/types/src/protocols/permissions.d.ts +40 -3
- package/dist/types/src/protocols/permissions.d.ts.map +1 -1
- package/dist/types/src/state-index/state-index-level.d.ts.map +1 -1
- package/dist/types/src/store/data-store-level.d.ts +20 -4
- package/dist/types/src/store/data-store-level.d.ts.map +1 -1
- package/dist/types/src/store/index-level-compound.d.ts +70 -0
- package/dist/types/src/store/index-level-compound.d.ts.map +1 -0
- package/dist/types/src/store/index-level.d.ts +4 -58
- package/dist/types/src/store/index-level.d.ts.map +1 -1
- package/dist/types/src/store/storage-controller.d.ts +4 -4
- package/dist/types/src/store/storage-controller.d.ts.map +1 -1
- package/dist/types/src/types/message-types.d.ts +3 -3
- package/dist/types/src/types/message-types.d.ts.map +1 -1
- package/dist/types/src/types/messages-types.d.ts +12 -3
- package/dist/types/src/types/messages-types.d.ts.map +1 -1
- package/dist/types/src/types/method-handler.d.ts +24 -3
- package/dist/types/src/types/method-handler.d.ts.map +1 -1
- package/dist/types/src/types/permission-types.d.ts +7 -0
- package/dist/types/src/types/permission-types.d.ts.map +1 -1
- package/dist/types/src/types/protocols-types.d.ts +41 -1
- package/dist/types/src/types/protocols-types.d.ts.map +1 -1
- package/dist/types/src/types/records-types.d.ts +16 -6
- package/dist/types/src/types/records-types.d.ts.map +1 -1
- package/dist/types/src/types/subscriptions.d.ts +151 -13
- package/dist/types/src/types/subscriptions.d.ts.map +1 -1
- package/dist/types/src/utils/hd-key.d.ts +1 -9
- package/dist/types/src/utils/hd-key.d.ts.map +1 -1
- package/dist/types/src/utils/messages.d.ts +7 -5
- package/dist/types/src/utils/messages.d.ts.map +1 -1
- package/dist/types/src/utils/protocols.d.ts +5 -0
- package/dist/types/src/utils/protocols.d.ts.map +1 -1
- package/dist/types/src/utils/records.d.ts +1 -11
- package/dist/types/src/utils/records.d.ts.map +1 -1
- package/dist/types/tests/dwn.spec.d.ts.map +1 -1
- package/dist/types/tests/event-emitter-event-log.spec.d.ts +2 -0
- package/dist/types/tests/event-emitter-event-log.spec.d.ts.map +1 -0
- package/dist/types/tests/features/author-delegated-grant.spec.d.ts.map +1 -1
- package/dist/types/tests/features/owner-delegated-grant.spec.d.ts.map +1 -1
- package/dist/types/tests/features/owner-signature.spec.d.ts.map +1 -1
- package/dist/types/tests/features/permissions.spec.d.ts.map +1 -1
- package/dist/types/tests/features/protocol-composition.spec.d.ts.map +1 -1
- package/dist/types/tests/features/records-immutable.spec.d.ts +2 -0
- package/dist/types/tests/features/records-immutable.spec.d.ts.map +1 -0
- package/dist/types/tests/features/records-record-limit.spec.d.ts +2 -0
- package/dist/types/tests/features/records-record-limit.spec.d.ts.map +1 -0
- package/dist/types/tests/features/records-tags.spec.d.ts.map +1 -1
- package/dist/types/tests/features/resumable-tasks.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-read.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-subscribe.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/messages-sync.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-count.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-delete.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-query.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-read.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-subscribe.spec.d.ts.map +1 -1
- package/dist/types/tests/handlers/records-write.spec.d.ts.map +1 -1
- package/dist/types/tests/scenarios/deleted-record.spec.d.ts.map +1 -1
- package/dist/types/tests/scenarios/subscriptions.spec.d.ts.map +1 -1
- package/dist/types/tests/test-event-stream.d.ts +11 -12
- package/dist/types/tests/test-event-stream.d.ts.map +1 -1
- package/dist/types/tests/test-suite.d.ts +2 -2
- package/dist/types/tests/test-suite.d.ts.map +1 -1
- package/dist/types/tests/utils/test-data-generator.d.ts +18 -0
- package/dist/types/tests/utils/test-data-generator.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/core/constants.ts +11 -0
- package/src/core/core-protocol.ts +129 -0
- package/src/core/dwn-error.ts +15 -12
- package/src/core/grant-authorization.ts +20 -3
- package/src/core/protocol-authorization-action.ts +377 -0
- package/src/core/protocol-authorization-validation.ts +487 -0
- package/src/core/protocol-authorization.ts +111 -856
- package/src/core/record-chain.ts +99 -0
- package/src/core/records-grant-authorization.ts +6 -8
- package/src/dwn.ts +58 -73
- package/src/event-stream/event-emitter-event-log.ts +283 -0
- package/src/handlers/messages-read.ts +8 -9
- package/src/handlers/messages-subscribe.ts +24 -28
- package/src/handlers/messages-sync.ts +10 -16
- package/src/handlers/protocols-configure.ts +47 -32
- package/src/handlers/protocols-query.ts +6 -9
- package/src/handlers/records-count.ts +11 -10
- package/src/handlers/records-delete.ts +12 -21
- package/src/handlers/records-query.ts +12 -12
- package/src/handlers/records-read.ts +34 -22
- package/src/handlers/records-subscribe.ts +47 -26
- package/src/handlers/records-write.ts +47 -104
- package/src/index.ts +9 -5
- package/src/interfaces/messages-subscribe.ts +7 -1
- package/src/interfaces/protocols-configure.ts +73 -8
- package/src/interfaces/records-count.ts +1 -1
- package/src/interfaces/records-delete.ts +1 -1
- package/src/interfaces/records-query.ts +1 -1
- package/src/interfaces/records-read.ts +1 -1
- package/src/interfaces/records-subscribe.ts +8 -1
- package/src/interfaces/records-write-query.ts +139 -0
- package/src/interfaces/records-write-signing.ts +123 -0
- package/src/interfaces/records-write.ts +66 -261
- package/src/protocols/permission-grant.ts +1 -1
- package/src/protocols/permission-request.ts +1 -1
- package/src/protocols/permissions.ts +148 -6
- package/src/state-index/state-index-level.ts +5 -7
- package/src/store/data-store-level.ts +124 -34
- package/src/store/index-level-compound.ts +324 -0
- package/src/store/index-level.ts +68 -341
- package/src/store/storage-controller.ts +11 -11
- package/src/types/message-types.ts +3 -3
- package/src/types/messages-types.ts +12 -3
- package/src/types/method-handler.ts +26 -4
- package/src/types/mitt.d.ts +28 -0
- package/src/types/permission-types.ts +7 -0
- package/src/types/protocols-types.ts +46 -0
- package/src/types/records-types.ts +16 -6
- package/src/types/subscriptions.ts +178 -14
- package/src/utils/hd-key.ts +0 -9
- package/src/utils/messages.ts +17 -37
- package/src/utils/protocols.ts +8 -0
- package/src/utils/records.ts +8 -59
- package/dist/esm/src/event-stream/event-emitter-stream.js +0 -60
- package/dist/esm/src/event-stream/event-emitter-stream.js.map +0 -1
- package/dist/esm/tests/event-stream/event-emitter-stream.spec.js +0 -77
- package/dist/esm/tests/event-stream/event-emitter-stream.spec.js.map +0 -1
- package/dist/esm/tests/event-stream/event-stream.spec.js +0 -123
- package/dist/esm/tests/event-stream/event-stream.spec.js.map +0 -1
- package/dist/types/src/event-stream/event-emitter-stream.d.ts +0 -23
- package/dist/types/src/event-stream/event-emitter-stream.d.ts.map +0 -1
- package/dist/types/tests/event-stream/event-emitter-stream.spec.d.ts +0 -2
- package/dist/types/tests/event-stream/event-emitter-stream.spec.d.ts.map +0 -1
- package/dist/types/tests/event-stream/event-stream.spec.d.ts +0 -2
- package/dist/types/tests/event-stream/event-stream.spec.d.ts.map +0 -1
- package/src/event-stream/event-emitter-stream.ts +0 -69
|
@@ -1,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';
|
|
@@ -16,7 +7,7 @@ import { Records } from '../../src/utils/records.js';
|
|
|
16
7
|
import { RecordsRead } from '../../src/interfaces/records-read.js';
|
|
17
8
|
import { RecordsWrite } from '../../src/interfaces/records-write.js';
|
|
18
9
|
import { TestDataGenerator } from '../utils/test-data-generator.js';
|
|
19
|
-
import {
|
|
10
|
+
import { TestEventLog } from '../test-event-stream.js';
|
|
20
11
|
import { TestStores } from '../test-stores.js';
|
|
21
12
|
import { UniversalResolver } from '@enbox/dids';
|
|
22
13
|
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'bun:test';
|
|
@@ -28,36 +19,36 @@ export function testRecordsTags() {
|
|
|
28
19
|
let dataStore;
|
|
29
20
|
let resumableTaskStore;
|
|
30
21
|
let stateIndex;
|
|
31
|
-
let
|
|
22
|
+
let eventLog;
|
|
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;
|
|
39
30
|
dataStore = stores.dataStore;
|
|
40
31
|
resumableTaskStore = stores.resumableTaskStore;
|
|
41
32
|
stateIndex = stores.stateIndex;
|
|
42
|
-
|
|
43
|
-
dwn =
|
|
44
|
-
})
|
|
45
|
-
beforeEach(() =>
|
|
33
|
+
eventLog = TestEventLog.get();
|
|
34
|
+
dwn = await Dwn.create({ didResolver, messageStore, dataStore, stateIndex, eventLog, 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,21 @@ 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();
|
|
1792
|
+
await TestDataGenerator.installDefaultTestProtocol(dwn, alice);
|
|
1801
1793
|
// create tags that represent `string[]`, `number[]`, `string`, `number`, or `boolean` values.
|
|
1802
1794
|
const stringTag = 'string-value';
|
|
1803
1795
|
const stringArrayTag = ['string-value', 'string-value2'];
|
|
1804
1796
|
const numberTag = 54566975;
|
|
1805
1797
|
const numberArrayTag = [0, 1, 2];
|
|
1806
1798
|
const booleanTag = false;
|
|
1807
|
-
const tagsRecord1 =
|
|
1799
|
+
const tagsRecord1 = await TestDataGenerator.generateRecordsWrite({
|
|
1808
1800
|
author: alice,
|
|
1809
1801
|
published: true,
|
|
1810
1802
|
schema: 'post',
|
|
@@ -1816,25 +1808,25 @@ export function testRecordsTags() {
|
|
|
1816
1808
|
numberArrayTag,
|
|
1817
1809
|
}
|
|
1818
1810
|
});
|
|
1819
|
-
const tagsRecord1Reply =
|
|
1811
|
+
const tagsRecord1Reply = await dwn.processMessage(alice.did, tagsRecord1.message, { dataStream: tagsRecord1.dataStream });
|
|
1820
1812
|
expect(tagsRecord1Reply.status.code).toBe(202);
|
|
1821
1813
|
// verify the record was written
|
|
1822
|
-
const tagsRecord1Read =
|
|
1814
|
+
const tagsRecord1Read = await RecordsRead.create({
|
|
1823
1815
|
filter: {
|
|
1824
1816
|
recordId: tagsRecord1.message.recordId,
|
|
1825
1817
|
},
|
|
1826
1818
|
signer: Jws.createSigner(alice)
|
|
1827
1819
|
});
|
|
1828
|
-
const tagsRecord1ReadReply =
|
|
1820
|
+
const tagsRecord1ReadReply = await dwn.processMessage(alice.did, tagsRecord1Read.message);
|
|
1829
1821
|
expect(tagsRecord1ReadReply.status.code).toBe(200);
|
|
1830
1822
|
expect(tagsRecord1ReadReply.entry.recordsWrite).toBeDefined();
|
|
1831
1823
|
expect(tagsRecord1ReadReply.entry.recordsWrite.descriptor.tags)
|
|
1832
1824
|
.toEqual({ stringTag, numberTag, booleanTag, stringArrayTag, numberArrayTag });
|
|
1833
|
-
})
|
|
1834
|
-
it('should overwrite tags when updating a Record', () =>
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
const tagsRecord1 =
|
|
1825
|
+
});
|
|
1826
|
+
it('should overwrite tags when updating a Record', async () => {
|
|
1827
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1828
|
+
await TestDataGenerator.installDefaultTestProtocol(dwn, alice);
|
|
1829
|
+
const tagsRecord1 = await TestDataGenerator.generateRecordsWrite({
|
|
1838
1830
|
author: alice,
|
|
1839
1831
|
published: true,
|
|
1840
1832
|
schema: 'post',
|
|
@@ -1847,16 +1839,16 @@ export function testRecordsTags() {
|
|
|
1847
1839
|
}
|
|
1848
1840
|
});
|
|
1849
1841
|
// write the record
|
|
1850
|
-
const tagsRecord1Reply =
|
|
1842
|
+
const tagsRecord1Reply = await dwn.processMessage(alice.did, tagsRecord1.message, { dataStream: tagsRecord1.dataStream });
|
|
1851
1843
|
expect(tagsRecord1Reply.status.code).toBe(202);
|
|
1852
1844
|
// verify the record was written
|
|
1853
|
-
const tagsRecord1Read =
|
|
1845
|
+
const tagsRecord1Read = await RecordsRead.create({
|
|
1854
1846
|
filter: {
|
|
1855
1847
|
recordId: tagsRecord1.message.recordId,
|
|
1856
1848
|
},
|
|
1857
1849
|
signer: Jws.createSigner(alice)
|
|
1858
1850
|
});
|
|
1859
|
-
const tagsRecord1ReadReply =
|
|
1851
|
+
const tagsRecord1ReadReply = await dwn.processMessage(alice.did, tagsRecord1Read.message);
|
|
1860
1852
|
expect(tagsRecord1ReadReply.status.code).toBe(200);
|
|
1861
1853
|
expect(tagsRecord1ReadReply.entry.recordsWrite).toBeDefined();
|
|
1862
1854
|
expect(tagsRecord1ReadReply.entry.recordsWrite.descriptor.tags).toEqual({
|
|
@@ -1867,7 +1859,7 @@ export function testRecordsTags() {
|
|
|
1867
1859
|
numberArrayTag: [0, 1, 2],
|
|
1868
1860
|
});
|
|
1869
1861
|
// Sanity: Query for a tag value
|
|
1870
|
-
const tagsQueryMatch =
|
|
1862
|
+
const tagsQueryMatch = await TestDataGenerator.generateRecordsQuery({
|
|
1871
1863
|
author: alice,
|
|
1872
1864
|
filter: {
|
|
1873
1865
|
tags: {
|
|
@@ -1875,33 +1867,34 @@ export function testRecordsTags() {
|
|
|
1875
1867
|
}
|
|
1876
1868
|
}
|
|
1877
1869
|
});
|
|
1878
|
-
const tagsQueryMatchReply =
|
|
1870
|
+
const tagsQueryMatchReply = await dwn.processMessage(alice.did, tagsQueryMatch.message);
|
|
1879
1871
|
expect(tagsQueryMatchReply.status.code).toBe(200);
|
|
1880
|
-
expect(
|
|
1872
|
+
expect(tagsQueryMatchReply.entries?.length).toBe(1);
|
|
1881
1873
|
expect(tagsQueryMatchReply.entries[0].recordId).toBe(tagsRecord1.message.recordId);
|
|
1882
1874
|
// update the record with new tags
|
|
1883
|
-
const updatedRecord =
|
|
1875
|
+
const updatedRecord = await TestDataGenerator.generateFromRecordsWrite({
|
|
1884
1876
|
author: alice,
|
|
1885
1877
|
existingWrite: tagsRecord1.recordsWrite,
|
|
1886
1878
|
tags: { newTag: 'new-value' }
|
|
1887
1879
|
});
|
|
1888
|
-
const updatedRecordReply =
|
|
1880
|
+
const updatedRecordReply = await dwn.processMessage(alice.did, updatedRecord.message, { dataStream: updatedRecord.dataStream });
|
|
1889
1881
|
expect(updatedRecordReply.status.code).toBe(202, updatedRecordReply.status.detail);
|
|
1890
|
-
const updatedRecordReadReply =
|
|
1882
|
+
const updatedRecordReadReply = await dwn.processMessage(alice.did, tagsRecord1Read.message);
|
|
1891
1883
|
expect(updatedRecordReadReply.status.code).toBe(200);
|
|
1892
1884
|
expect(updatedRecordReadReply.entry.recordsWrite).toBeDefined();
|
|
1893
1885
|
expect(updatedRecordReadReply.entry.recordsWrite.descriptor.tags).toEqual({ newTag: 'new-value' });
|
|
1894
1886
|
// Sanity: Query for the old tag value should return no results
|
|
1895
|
-
const tagsQueryMatchReply2 =
|
|
1887
|
+
const tagsQueryMatchReply2 = await dwn.processMessage(alice.did, tagsQueryMatch.message);
|
|
1896
1888
|
expect(tagsQueryMatchReply2.status.code).toBe(200);
|
|
1897
|
-
expect(
|
|
1898
|
-
})
|
|
1899
|
-
it('should not index tags when the record is not `latestBaseState`', () =>
|
|
1889
|
+
expect(tagsQueryMatchReply2.entries?.length).toBe(0);
|
|
1890
|
+
});
|
|
1891
|
+
it('should not index tags when the record is not `latestBaseState`', async () => {
|
|
1900
1892
|
const buildTagIndexSpy = sinon.spy(Records, 'buildTagIndexes');
|
|
1901
1893
|
const constructIndexesSpy = sinon.spy(RecordsWrite.prototype, 'constructIndexes');
|
|
1902
|
-
const alice =
|
|
1894
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1895
|
+
await TestDataGenerator.installDefaultTestProtocol(dwn, alice);
|
|
1903
1896
|
// write a record with tags, this should trigger the `buildTagIndexes` method
|
|
1904
|
-
const tagsRecord1 =
|
|
1897
|
+
const tagsRecord1 = await TestDataGenerator.generateRecordsWrite({
|
|
1905
1898
|
author: alice,
|
|
1906
1899
|
published: true,
|
|
1907
1900
|
schema: 'post',
|
|
@@ -1914,7 +1907,7 @@ export function testRecordsTags() {
|
|
|
1914
1907
|
}
|
|
1915
1908
|
});
|
|
1916
1909
|
// write the record
|
|
1917
|
-
const tagsRecord1Reply =
|
|
1910
|
+
const tagsRecord1Reply = await dwn.processMessage(alice.did, tagsRecord1.message, { dataStream: tagsRecord1.dataStream });
|
|
1918
1911
|
expect(tagsRecord1Reply.status.code).toBe(202);
|
|
1919
1912
|
// verify that construct Indexes was called
|
|
1920
1913
|
expect(constructIndexesSpy.callCount).toBe(1);
|
|
@@ -1924,24 +1917,24 @@ export function testRecordsTags() {
|
|
|
1924
1917
|
constructIndexesSpy.resetHistory();
|
|
1925
1918
|
buildTagIndexSpy.resetHistory();
|
|
1926
1919
|
// update the record without any tags this time
|
|
1927
|
-
const updatedRecord =
|
|
1920
|
+
const updatedRecord = await TestDataGenerator.generateFromRecordsWrite({
|
|
1928
1921
|
author: alice,
|
|
1929
1922
|
existingWrite: tagsRecord1.recordsWrite,
|
|
1930
1923
|
});
|
|
1931
|
-
const updatedRecordReply =
|
|
1924
|
+
const updatedRecordReply = await dwn.processMessage(alice.did, updatedRecord.message, { dataStream: updatedRecord.dataStream });
|
|
1932
1925
|
expect(updatedRecordReply.status.code).toBe(202);
|
|
1933
1926
|
// construct Indexes should be called once for the `initialWrite` and once for the updated write
|
|
1934
1927
|
expect(constructIndexesSpy.callCount).toBe(2);
|
|
1935
1928
|
// verify that buildTagIndexes was not called at all
|
|
1936
1929
|
expect(buildTagIndexSpy.callCount).toBe(0);
|
|
1937
|
-
})
|
|
1930
|
+
});
|
|
1938
1931
|
});
|
|
1939
1932
|
describe('RecordsQuery filter for tags', () => {
|
|
1940
|
-
it('should be able to filter by string match', () =>
|
|
1941
|
-
|
|
1942
|
-
|
|
1933
|
+
it('should be able to filter by string match', async () => {
|
|
1934
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1935
|
+
await TestDataGenerator.installDefaultTestProtocol(dwn, alice);
|
|
1943
1936
|
const stringTag = 'string-value';
|
|
1944
|
-
const tagsRecord1 =
|
|
1937
|
+
const tagsRecord1 = await TestDataGenerator.generateRecordsWrite({
|
|
1945
1938
|
author: alice,
|
|
1946
1939
|
published: true,
|
|
1947
1940
|
schema: 'post',
|
|
@@ -1949,9 +1942,9 @@ export function testRecordsTags() {
|
|
|
1949
1942
|
stringTag,
|
|
1950
1943
|
}
|
|
1951
1944
|
});
|
|
1952
|
-
const tagsRecord1Reply =
|
|
1945
|
+
const tagsRecord1Reply = await dwn.processMessage(alice.did, tagsRecord1.message, { dataStream: tagsRecord1.dataStream });
|
|
1953
1946
|
expect(tagsRecord1Reply.status.code).toBe(202);
|
|
1954
|
-
const tagsQueryMatch =
|
|
1947
|
+
const tagsQueryMatch = await TestDataGenerator.generateRecordsQuery({
|
|
1955
1948
|
author: alice,
|
|
1956
1949
|
filter: {
|
|
1957
1950
|
tags: {
|
|
@@ -1959,12 +1952,12 @@ export function testRecordsTags() {
|
|
|
1959
1952
|
}
|
|
1960
1953
|
}
|
|
1961
1954
|
});
|
|
1962
|
-
const tagsQueryMatchReply =
|
|
1955
|
+
const tagsQueryMatchReply = await dwn.processMessage(alice.did, tagsQueryMatch.message);
|
|
1963
1956
|
expect(tagsQueryMatchReply.status.code).toBe(200);
|
|
1964
|
-
expect(
|
|
1957
|
+
expect(tagsQueryMatchReply.entries?.length).toBe(1);
|
|
1965
1958
|
expect(tagsQueryMatchReply.entries[0].recordId).toBe(tagsRecord1.message.recordId);
|
|
1966
1959
|
// negative result same tag different value
|
|
1967
|
-
let tagsQueryNegative =
|
|
1960
|
+
let tagsQueryNegative = await TestDataGenerator.generateRecordsQuery({
|
|
1968
1961
|
author: alice,
|
|
1969
1962
|
filter: {
|
|
1970
1963
|
tags: {
|
|
@@ -1972,11 +1965,11 @@ export function testRecordsTags() {
|
|
|
1972
1965
|
}
|
|
1973
1966
|
}
|
|
1974
1967
|
});
|
|
1975
|
-
let tagsQueryNegativeReply =
|
|
1968
|
+
let tagsQueryNegativeReply = await dwn.processMessage(alice.did, tagsQueryNegative.message);
|
|
1976
1969
|
expect(tagsQueryNegativeReply.status.code).toBe(200);
|
|
1977
|
-
expect(
|
|
1970
|
+
expect(tagsQueryNegativeReply.entries?.length).toBe(0);
|
|
1978
1971
|
// negative result different tag same value
|
|
1979
|
-
tagsQueryNegative =
|
|
1972
|
+
tagsQueryNegative = await TestDataGenerator.generateRecordsQuery({
|
|
1980
1973
|
author: alice,
|
|
1981
1974
|
filter: {
|
|
1982
1975
|
tags: {
|
|
@@ -1984,16 +1977,16 @@ export function testRecordsTags() {
|
|
|
1984
1977
|
}
|
|
1985
1978
|
}
|
|
1986
1979
|
});
|
|
1987
|
-
tagsQueryNegativeReply =
|
|
1980
|
+
tagsQueryNegativeReply = await dwn.processMessage(alice.did, tagsQueryNegative.message);
|
|
1988
1981
|
expect(tagsQueryNegativeReply.status.code).toBe(200);
|
|
1989
|
-
expect(
|
|
1990
|
-
})
|
|
1991
|
-
it('should be able to filter by number match', () =>
|
|
1992
|
-
|
|
1993
|
-
|
|
1982
|
+
expect(tagsQueryNegativeReply.entries?.length).toBe(0);
|
|
1983
|
+
});
|
|
1984
|
+
it('should be able to filter by number match', async () => {
|
|
1985
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
1986
|
+
await TestDataGenerator.installDefaultTestProtocol(dwn, alice);
|
|
1994
1987
|
const numberTag = 54566975;
|
|
1995
1988
|
// write a record with a numerical value tag
|
|
1996
|
-
const tagsRecord1 =
|
|
1989
|
+
const tagsRecord1 = await TestDataGenerator.generateRecordsWrite({
|
|
1997
1990
|
author: alice,
|
|
1998
1991
|
published: true,
|
|
1999
1992
|
schema: 'post',
|
|
@@ -2001,10 +1994,10 @@ export function testRecordsTags() {
|
|
|
2001
1994
|
numberTag,
|
|
2002
1995
|
}
|
|
2003
1996
|
});
|
|
2004
|
-
const tagsRecord1Reply =
|
|
1997
|
+
const tagsRecord1Reply = await dwn.processMessage(alice.did, tagsRecord1.message, { dataStream: tagsRecord1.dataStream });
|
|
2005
1998
|
expect(tagsRecord1Reply.status.code).toBe(202);
|
|
2006
1999
|
// do an exact match for the tag value
|
|
2007
|
-
const tagsQueryMatch =
|
|
2000
|
+
const tagsQueryMatch = await TestDataGenerator.generateRecordsQuery({
|
|
2008
2001
|
author: alice,
|
|
2009
2002
|
filter: {
|
|
2010
2003
|
tags: {
|
|
@@ -2012,12 +2005,12 @@ export function testRecordsTags() {
|
|
|
2012
2005
|
}
|
|
2013
2006
|
}
|
|
2014
2007
|
});
|
|
2015
|
-
const tagsQueryMatchReply =
|
|
2008
|
+
const tagsQueryMatchReply = await dwn.processMessage(alice.did, tagsQueryMatch.message);
|
|
2016
2009
|
expect(tagsQueryMatchReply.status.code).toBe(200);
|
|
2017
|
-
expect(
|
|
2010
|
+
expect(tagsQueryMatchReply.entries?.length).toBe(1);
|
|
2018
2011
|
expect(tagsQueryMatchReply.entries[0].recordId).toBe(tagsRecord1.message.recordId);
|
|
2019
2012
|
// negative result same tag different value
|
|
2020
|
-
let tagsQueryNegative =
|
|
2013
|
+
let tagsQueryNegative = await TestDataGenerator.generateRecordsQuery({
|
|
2021
2014
|
author: alice,
|
|
2022
2015
|
filter: {
|
|
2023
2016
|
tags: {
|
|
@@ -2025,11 +2018,11 @@ export function testRecordsTags() {
|
|
|
2025
2018
|
}
|
|
2026
2019
|
}
|
|
2027
2020
|
});
|
|
2028
|
-
let tagsQueryNegativeReply =
|
|
2021
|
+
let tagsQueryNegativeReply = await dwn.processMessage(alice.did, tagsQueryNegative.message);
|
|
2029
2022
|
expect(tagsQueryNegativeReply.status.code).toBe(200);
|
|
2030
|
-
expect(
|
|
2023
|
+
expect(tagsQueryNegativeReply.entries?.length).toBe(0);
|
|
2031
2024
|
// negative result different tag same value
|
|
2032
|
-
tagsQueryNegative =
|
|
2025
|
+
tagsQueryNegative = await TestDataGenerator.generateRecordsQuery({
|
|
2033
2026
|
author: alice,
|
|
2034
2027
|
filter: {
|
|
2035
2028
|
tags: {
|
|
@@ -2037,20 +2030,20 @@ export function testRecordsTags() {
|
|
|
2037
2030
|
}
|
|
2038
2031
|
}
|
|
2039
2032
|
});
|
|
2040
|
-
tagsQueryNegativeReply =
|
|
2033
|
+
tagsQueryNegativeReply = await dwn.processMessage(alice.did, tagsQueryNegative.message);
|
|
2041
2034
|
expect(tagsQueryNegativeReply.status.code).toBe(200);
|
|
2042
|
-
expect(
|
|
2043
|
-
})
|
|
2044
|
-
it('should be able to filter by boolean match', () =>
|
|
2035
|
+
expect(tagsQueryNegativeReply.entries?.length).toBe(0);
|
|
2036
|
+
});
|
|
2037
|
+
it('should be able to filter by boolean match', async () => {
|
|
2045
2038
|
// 1. Write a record with a boolean tag `booleanTag` set to true
|
|
2046
2039
|
// 2. Write a record with a boolean tag `booleanTag` set to false.
|
|
2047
2040
|
// 3. Query for records with a `booleanTag` set to true, and validate the result.
|
|
2048
2041
|
// 4. Query for records with a `booleanTag` set to false, and validate the result.
|
|
2049
2042
|
// 5. Query for records with a non existent boolean tag, should not return a result.
|
|
2050
|
-
|
|
2051
|
-
|
|
2043
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
2044
|
+
await TestDataGenerator.installDefaultTestProtocol(dwn, alice);
|
|
2052
2045
|
// write a record with a true boolean value tag
|
|
2053
|
-
const tagsRecordTrue =
|
|
2046
|
+
const tagsRecordTrue = await TestDataGenerator.generateRecordsWrite({
|
|
2054
2047
|
author: alice,
|
|
2055
2048
|
published: true,
|
|
2056
2049
|
schema: 'post',
|
|
@@ -2058,10 +2051,10 @@ export function testRecordsTags() {
|
|
|
2058
2051
|
booleanTag: true,
|
|
2059
2052
|
}
|
|
2060
2053
|
});
|
|
2061
|
-
const tagsRecordTrueReply =
|
|
2054
|
+
const tagsRecordTrueReply = await dwn.processMessage(alice.did, tagsRecordTrue.message, { dataStream: tagsRecordTrue.dataStream });
|
|
2062
2055
|
expect(tagsRecordTrueReply.status.code).toBe(202);
|
|
2063
2056
|
// write a record with a false boolean value tag
|
|
2064
|
-
const tagsRecordFalse =
|
|
2057
|
+
const tagsRecordFalse = await TestDataGenerator.generateRecordsWrite({
|
|
2065
2058
|
author: alice,
|
|
2066
2059
|
published: true,
|
|
2067
2060
|
schema: 'post',
|
|
@@ -2069,10 +2062,10 @@ export function testRecordsTags() {
|
|
|
2069
2062
|
booleanTag: false,
|
|
2070
2063
|
}
|
|
2071
2064
|
});
|
|
2072
|
-
const tagsRecordFalseReply =
|
|
2065
|
+
const tagsRecordFalseReply = await dwn.processMessage(alice.did, tagsRecordFalse.message, { dataStream: tagsRecordFalse.dataStream });
|
|
2073
2066
|
expect(tagsRecordFalseReply.status.code).toBe(202);
|
|
2074
2067
|
// query for records with a `booleanTag` set to true, should return the record with the true tag
|
|
2075
|
-
const tagsQueryMatchTrue =
|
|
2068
|
+
const tagsQueryMatchTrue = await TestDataGenerator.generateRecordsQuery({
|
|
2076
2069
|
author: alice,
|
|
2077
2070
|
filter: {
|
|
2078
2071
|
tags: {
|
|
@@ -2080,12 +2073,12 @@ export function testRecordsTags() {
|
|
|
2080
2073
|
}
|
|
2081
2074
|
}
|
|
2082
2075
|
});
|
|
2083
|
-
const tagsQueryMatchTrueReply =
|
|
2076
|
+
const tagsQueryMatchTrueReply = await dwn.processMessage(alice.did, tagsQueryMatchTrue.message);
|
|
2084
2077
|
expect(tagsQueryMatchTrueReply.status.code).toBe(200);
|
|
2085
|
-
expect(
|
|
2078
|
+
expect(tagsQueryMatchTrueReply.entries?.length).toBe(1);
|
|
2086
2079
|
expect(tagsQueryMatchTrueReply.entries[0].recordId).toBe(tagsRecordTrue.message.recordId);
|
|
2087
2080
|
// query for records with a `booleanTag` set to false, should return the record with the false tag
|
|
2088
|
-
const tagsQueryMatchFalse =
|
|
2081
|
+
const tagsQueryMatchFalse = await TestDataGenerator.generateRecordsQuery({
|
|
2089
2082
|
author: alice,
|
|
2090
2083
|
filter: {
|
|
2091
2084
|
tags: {
|
|
@@ -2093,12 +2086,12 @@ export function testRecordsTags() {
|
|
|
2093
2086
|
}
|
|
2094
2087
|
}
|
|
2095
2088
|
});
|
|
2096
|
-
const tagsQueryMatchFalseReply =
|
|
2089
|
+
const tagsQueryMatchFalseReply = await dwn.processMessage(alice.did, tagsQueryMatchFalse.message);
|
|
2097
2090
|
expect(tagsQueryMatchFalseReply.status.code).toBe(200);
|
|
2098
|
-
expect(
|
|
2091
|
+
expect(tagsQueryMatchFalseReply.entries?.length).toBe(1);
|
|
2099
2092
|
expect(tagsQueryMatchFalseReply.entries[0].recordId).toBe(tagsRecordFalse.message.recordId);
|
|
2100
2093
|
// negative result for a non existent boolean tag.
|
|
2101
|
-
const tagsQueryNegative =
|
|
2094
|
+
const tagsQueryNegative = await TestDataGenerator.generateRecordsQuery({
|
|
2102
2095
|
author: alice,
|
|
2103
2096
|
filter: {
|
|
2104
2097
|
tags: {
|
|
@@ -2106,15 +2099,15 @@ export function testRecordsTags() {
|
|
|
2106
2099
|
}
|
|
2107
2100
|
}
|
|
2108
2101
|
});
|
|
2109
|
-
const tagsQueryNegativeReply =
|
|
2102
|
+
const tagsQueryNegativeReply = await dwn.processMessage(alice.did, tagsQueryNegative.message);
|
|
2110
2103
|
expect(tagsQueryNegativeReply.status.code).toBe(200);
|
|
2111
|
-
expect(
|
|
2112
|
-
})
|
|
2113
|
-
it('should be able to range filter by string value', () =>
|
|
2114
|
-
|
|
2115
|
-
|
|
2104
|
+
expect(tagsQueryNegativeReply.entries?.length).toBe(0);
|
|
2105
|
+
});
|
|
2106
|
+
it('should be able to range filter by string value', async () => {
|
|
2107
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
2108
|
+
await TestDataGenerator.installDefaultTestProtocol(dwn, alice);
|
|
2116
2109
|
// create four records with different first names
|
|
2117
|
-
const aliceRecord =
|
|
2110
|
+
const aliceRecord = await TestDataGenerator.generateRecordsWrite({
|
|
2118
2111
|
author: alice,
|
|
2119
2112
|
published: true,
|
|
2120
2113
|
schema: 'post',
|
|
@@ -2122,7 +2115,7 @@ export function testRecordsTags() {
|
|
|
2122
2115
|
firstName: 'alice'
|
|
2123
2116
|
}
|
|
2124
2117
|
});
|
|
2125
|
-
const bobRecord =
|
|
2118
|
+
const bobRecord = await TestDataGenerator.generateRecordsWrite({
|
|
2126
2119
|
author: alice,
|
|
2127
2120
|
published: true,
|
|
2128
2121
|
schema: 'post',
|
|
@@ -2130,7 +2123,7 @@ export function testRecordsTags() {
|
|
|
2130
2123
|
firstName: 'bob',
|
|
2131
2124
|
}
|
|
2132
2125
|
});
|
|
2133
|
-
const carolRecord =
|
|
2126
|
+
const carolRecord = await TestDataGenerator.generateRecordsWrite({
|
|
2134
2127
|
author: alice,
|
|
2135
2128
|
published: true,
|
|
2136
2129
|
schema: 'post',
|
|
@@ -2138,7 +2131,7 @@ export function testRecordsTags() {
|
|
|
2138
2131
|
firstName: 'carol',
|
|
2139
2132
|
}
|
|
2140
2133
|
});
|
|
2141
|
-
const danielRecord =
|
|
2134
|
+
const danielRecord = await TestDataGenerator.generateRecordsWrite({
|
|
2142
2135
|
author: alice,
|
|
2143
2136
|
published: true,
|
|
2144
2137
|
schema: 'post',
|
|
@@ -2146,26 +2139,26 @@ export function testRecordsTags() {
|
|
|
2146
2139
|
firstName: 'daniel',
|
|
2147
2140
|
}
|
|
2148
2141
|
});
|
|
2149
|
-
const aliceReply =
|
|
2142
|
+
const aliceReply = await dwn.processMessage(alice.did, aliceRecord.message, { dataStream: aliceRecord.dataStream });
|
|
2150
2143
|
expect(aliceReply.status.code).toBe(202);
|
|
2151
|
-
const bobReply =
|
|
2144
|
+
const bobReply = await dwn.processMessage(alice.did, bobRecord.message, { dataStream: bobRecord.dataStream });
|
|
2152
2145
|
expect(bobReply.status.code).toBe(202);
|
|
2153
|
-
const carolReply =
|
|
2146
|
+
const carolReply = await dwn.processMessage(alice.did, carolRecord.message, { dataStream: carolRecord.dataStream });
|
|
2154
2147
|
expect(carolReply.status.code).toBe(202);
|
|
2155
|
-
const danielReply =
|
|
2148
|
+
const danielReply = await dwn.processMessage(alice.did, danielRecord.message, { dataStream: danielRecord.dataStream });
|
|
2156
2149
|
expect(danielReply.status.code).toBe(202);
|
|
2157
2150
|
// sanity query for all
|
|
2158
|
-
const queryForAll =
|
|
2151
|
+
const queryForAll = await TestDataGenerator.generateRecordsQuery({
|
|
2159
2152
|
author: alice,
|
|
2160
2153
|
filter: {
|
|
2161
2154
|
schema: 'post'
|
|
2162
2155
|
}
|
|
2163
2156
|
});
|
|
2164
|
-
const queryForAllReply =
|
|
2157
|
+
const queryForAllReply = await dwn.processMessage(alice.did, queryForAll.message);
|
|
2165
2158
|
expect(queryForAllReply.status.code).toBe(200);
|
|
2166
|
-
expect(
|
|
2159
|
+
expect(queryForAllReply.entries?.length).toBe(4); // all 4 records
|
|
2167
2160
|
// query for first names that begin with 'a' and 'b'
|
|
2168
|
-
const queryForAtoB =
|
|
2161
|
+
const queryForAtoB = await TestDataGenerator.generateRecordsQuery({
|
|
2169
2162
|
author: alice,
|
|
2170
2163
|
filter: {
|
|
2171
2164
|
schema: 'post',
|
|
@@ -2174,13 +2167,13 @@ export function testRecordsTags() {
|
|
|
2174
2167
|
}
|
|
2175
2168
|
}
|
|
2176
2169
|
});
|
|
2177
|
-
const queryForAtoBReply =
|
|
2170
|
+
const queryForAtoBReply = await dwn.processMessage(alice.did, queryForAtoB.message);
|
|
2178
2171
|
expect(queryForAtoBReply.status.code).toBe(200);
|
|
2179
|
-
expect(
|
|
2172
|
+
expect(queryForAtoBReply.entries?.length).toBe(2);
|
|
2180
2173
|
const atobRecordIds = queryForAtoBReply.entries.map(entry => entry.recordId);
|
|
2181
2174
|
expect(atobRecordIds).toEqual(expect.arrayContaining([aliceRecord.message.recordId, bobRecord.message.recordId]));
|
|
2182
2175
|
// query for first names greater than 'bob'(exclusive of), and less than but inclusive of 'daniel'
|
|
2183
|
-
const queryForBtoD =
|
|
2176
|
+
const queryForBtoD = await TestDataGenerator.generateRecordsQuery({
|
|
2184
2177
|
author: alice,
|
|
2185
2178
|
filter: {
|
|
2186
2179
|
schema: 'post',
|
|
@@ -2189,13 +2182,13 @@ export function testRecordsTags() {
|
|
|
2189
2182
|
}
|
|
2190
2183
|
}
|
|
2191
2184
|
});
|
|
2192
|
-
const queryForBtoDReply =
|
|
2185
|
+
const queryForBtoDReply = await dwn.processMessage(alice.did, queryForBtoD.message);
|
|
2193
2186
|
expect(queryForBtoDReply.status.code).toBe(200);
|
|
2194
|
-
expect(
|
|
2187
|
+
expect(queryForBtoDReply.entries?.length).toBe(2);
|
|
2195
2188
|
const btodRecordIds = queryForBtoDReply.entries.map(entry => entry.recordId);
|
|
2196
2189
|
expect(btodRecordIds).toEqual(expect.arrayContaining([carolRecord.message.recordId, danielRecord.message.recordId]));
|
|
2197
2190
|
// query for first names that begin with 'carol' onward (inclusive).
|
|
2198
|
-
const queryForCarolOnward =
|
|
2191
|
+
const queryForCarolOnward = await TestDataGenerator.generateRecordsQuery({
|
|
2199
2192
|
author: alice,
|
|
2200
2193
|
filter: {
|
|
2201
2194
|
schema: 'post',
|
|
@@ -2204,17 +2197,17 @@ export function testRecordsTags() {
|
|
|
2204
2197
|
}
|
|
2205
2198
|
}
|
|
2206
2199
|
});
|
|
2207
|
-
const queryForCarolOnwardReply =
|
|
2200
|
+
const queryForCarolOnwardReply = await dwn.processMessage(alice.did, queryForCarolOnward.message);
|
|
2208
2201
|
expect(queryForCarolOnwardReply.status.code).toBe(200);
|
|
2209
|
-
expect(
|
|
2202
|
+
expect(queryForCarolOnwardReply.entries?.length).toBe(2);
|
|
2210
2203
|
const onwardResults = queryForCarolOnwardReply.entries.map(entry => entry.recordId);
|
|
2211
2204
|
expect(onwardResults).toEqual(expect.arrayContaining([carolRecord.message.recordId, danielRecord.message.recordId]));
|
|
2212
|
-
})
|
|
2213
|
-
it('should be able to filter by string prefix', () =>
|
|
2214
|
-
|
|
2215
|
-
|
|
2205
|
+
});
|
|
2206
|
+
it('should be able to filter by string prefix', async () => {
|
|
2207
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
2208
|
+
await TestDataGenerator.installDefaultTestProtocol(dwn, alice);
|
|
2216
2209
|
// create two records that match the prefix 'string-'
|
|
2217
|
-
const tagsRecord1 =
|
|
2210
|
+
const tagsRecord1 = await TestDataGenerator.generateRecordsWrite({
|
|
2218
2211
|
author: alice,
|
|
2219
2212
|
published: true,
|
|
2220
2213
|
schema: 'post',
|
|
@@ -2222,7 +2215,7 @@ export function testRecordsTags() {
|
|
|
2222
2215
|
stringTag: 'string-foo',
|
|
2223
2216
|
}
|
|
2224
2217
|
});
|
|
2225
|
-
const tagsRecord2 =
|
|
2218
|
+
const tagsRecord2 = await TestDataGenerator.generateRecordsWrite({
|
|
2226
2219
|
author: alice,
|
|
2227
2220
|
published: true,
|
|
2228
2221
|
schema: 'post',
|
|
@@ -2230,12 +2223,12 @@ export function testRecordsTags() {
|
|
|
2230
2223
|
stringTag: 'string-bar',
|
|
2231
2224
|
}
|
|
2232
2225
|
});
|
|
2233
|
-
const tagsRecord1Reply =
|
|
2226
|
+
const tagsRecord1Reply = await dwn.processMessage(alice.did, tagsRecord1.message, { dataStream: tagsRecord1.dataStream });
|
|
2234
2227
|
expect(tagsRecord1Reply.status.code).toBe(202);
|
|
2235
|
-
const tagsRecord2Reply =
|
|
2228
|
+
const tagsRecord2Reply = await dwn.processMessage(alice.did, tagsRecord2.message, { dataStream: tagsRecord2.dataStream });
|
|
2236
2229
|
expect(tagsRecord2Reply.status.code).toBe(202);
|
|
2237
2230
|
// control record that has a different prefix
|
|
2238
|
-
const tagsRecord3 =
|
|
2231
|
+
const tagsRecord3 = await TestDataGenerator.generateRecordsWrite({
|
|
2239
2232
|
author: alice,
|
|
2240
2233
|
published: true,
|
|
2241
2234
|
schema: 'post',
|
|
@@ -2243,10 +2236,10 @@ export function testRecordsTags() {
|
|
|
2243
2236
|
stringTag: 'zaz-string', // comes after `string-` lexicographically
|
|
2244
2237
|
}
|
|
2245
2238
|
});
|
|
2246
|
-
const tagsRecord3Reply =
|
|
2239
|
+
const tagsRecord3Reply = await dwn.processMessage(alice.did, tagsRecord3.message, { dataStream: tagsRecord3.dataStream });
|
|
2247
2240
|
expect(tagsRecord3Reply.status.code).toBe(202);
|
|
2248
2241
|
// a prefix search will return only the records matching the prefix
|
|
2249
|
-
const tagsQueryMatch =
|
|
2242
|
+
const tagsQueryMatch = await TestDataGenerator.generateRecordsQuery({
|
|
2250
2243
|
author: alice,
|
|
2251
2244
|
filter: {
|
|
2252
2245
|
tags: {
|
|
@@ -2254,14 +2247,14 @@ export function testRecordsTags() {
|
|
|
2254
2247
|
}
|
|
2255
2248
|
}
|
|
2256
2249
|
});
|
|
2257
|
-
const tagsQueryMatchReply =
|
|
2250
|
+
const tagsQueryMatchReply = await dwn.processMessage(alice.did, tagsQueryMatch.message);
|
|
2258
2251
|
expect(tagsQueryMatchReply.status.code).toBe(200);
|
|
2259
|
-
expect(
|
|
2252
|
+
expect(tagsQueryMatchReply.entries?.length).toBe(2);
|
|
2260
2253
|
const matchedRecords = tagsQueryMatchReply.entries.map(entry => entry.recordId);
|
|
2261
2254
|
expect(matchedRecords).toEqual(expect.arrayContaining([tagsRecord1.message.recordId, tagsRecord2.message.recordId]));
|
|
2262
2255
|
// sanity/control: a regular range query will return all
|
|
2263
2256
|
// since `zaz-string` comes lexicographically after `string-` it will appear in the result set
|
|
2264
|
-
const tagsQueryRange =
|
|
2257
|
+
const tagsQueryRange = await TestDataGenerator.generateRecordsQuery({
|
|
2265
2258
|
author: alice,
|
|
2266
2259
|
filter: {
|
|
2267
2260
|
tags: {
|
|
@@ -2269,15 +2262,15 @@ export function testRecordsTags() {
|
|
|
2269
2262
|
}
|
|
2270
2263
|
}
|
|
2271
2264
|
});
|
|
2272
|
-
const tagsQueryRangeReply =
|
|
2265
|
+
const tagsQueryRangeReply = await dwn.processMessage(alice.did, tagsQueryRange.message);
|
|
2273
2266
|
expect(tagsQueryRangeReply.status.code).toBe(200);
|
|
2274
|
-
expect(
|
|
2275
|
-
})
|
|
2276
|
-
it('should be able to range filter by number value', () =>
|
|
2277
|
-
|
|
2278
|
-
|
|
2267
|
+
expect(tagsQueryRangeReply.entries?.length).toBe(3); // returned all 3 records
|
|
2268
|
+
});
|
|
2269
|
+
it('should be able to range filter by number value', async () => {
|
|
2270
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
2271
|
+
await TestDataGenerator.installDefaultTestProtocol(dwn, alice);
|
|
2279
2272
|
// create four records with different test scores
|
|
2280
|
-
const aliceRecord =
|
|
2273
|
+
const aliceRecord = await TestDataGenerator.generateRecordsWrite({
|
|
2281
2274
|
author: alice,
|
|
2282
2275
|
published: true,
|
|
2283
2276
|
schema: 'test',
|
|
@@ -2286,7 +2279,7 @@ export function testRecordsTags() {
|
|
|
2286
2279
|
score: 75,
|
|
2287
2280
|
}
|
|
2288
2281
|
});
|
|
2289
|
-
const bobRecord =
|
|
2282
|
+
const bobRecord = await TestDataGenerator.generateRecordsWrite({
|
|
2290
2283
|
author: alice,
|
|
2291
2284
|
published: true,
|
|
2292
2285
|
schema: 'test',
|
|
@@ -2295,7 +2288,7 @@ export function testRecordsTags() {
|
|
|
2295
2288
|
score: 80,
|
|
2296
2289
|
}
|
|
2297
2290
|
});
|
|
2298
|
-
const carolRecord =
|
|
2291
|
+
const carolRecord = await TestDataGenerator.generateRecordsWrite({
|
|
2299
2292
|
author: alice,
|
|
2300
2293
|
published: true,
|
|
2301
2294
|
schema: 'test',
|
|
@@ -2304,7 +2297,7 @@ export function testRecordsTags() {
|
|
|
2304
2297
|
score: 65,
|
|
2305
2298
|
}
|
|
2306
2299
|
});
|
|
2307
|
-
const danielRecord =
|
|
2300
|
+
const danielRecord = await TestDataGenerator.generateRecordsWrite({
|
|
2308
2301
|
author: alice,
|
|
2309
2302
|
published: true,
|
|
2310
2303
|
schema: 'test',
|
|
@@ -2313,27 +2306,27 @@ export function testRecordsTags() {
|
|
|
2313
2306
|
score: 100,
|
|
2314
2307
|
}
|
|
2315
2308
|
});
|
|
2316
|
-
const aliceReply =
|
|
2309
|
+
const aliceReply = await dwn.processMessage(alice.did, aliceRecord.message, { dataStream: aliceRecord.dataStream });
|
|
2317
2310
|
expect(aliceReply.status.code).toBe(202);
|
|
2318
|
-
const bobReply =
|
|
2311
|
+
const bobReply = await dwn.processMessage(alice.did, bobRecord.message, { dataStream: bobRecord.dataStream });
|
|
2319
2312
|
expect(bobReply.status.code).toBe(202);
|
|
2320
|
-
const carolReply =
|
|
2313
|
+
const carolReply = await dwn.processMessage(alice.did, carolRecord.message, { dataStream: carolRecord.dataStream });
|
|
2321
2314
|
expect(carolReply.status.code).toBe(202);
|
|
2322
|
-
const danielReply =
|
|
2315
|
+
const danielReply = await dwn.processMessage(alice.did, danielRecord.message, { dataStream: danielRecord.dataStream });
|
|
2323
2316
|
expect(danielReply.status.code).toBe(202);
|
|
2324
2317
|
// sanity query for all
|
|
2325
|
-
const queryForAll =
|
|
2318
|
+
const queryForAll = await TestDataGenerator.generateRecordsQuery({
|
|
2326
2319
|
author: alice,
|
|
2327
2320
|
filter: {
|
|
2328
2321
|
schema: 'test'
|
|
2329
2322
|
}
|
|
2330
2323
|
});
|
|
2331
|
-
const queryForAllReply =
|
|
2324
|
+
const queryForAllReply = await dwn.processMessage(alice.did, queryForAll.message);
|
|
2332
2325
|
expect(queryForAllReply.status.code).toBe(200);
|
|
2333
|
-
expect(
|
|
2326
|
+
expect(queryForAllReply.entries?.length).toBe(4); // all 4 records
|
|
2334
2327
|
// query for all records that received higher than(not including) an 80
|
|
2335
2328
|
// only one record should match
|
|
2336
|
-
const queryForHighGrade =
|
|
2329
|
+
const queryForHighGrade = await TestDataGenerator.generateRecordsQuery({
|
|
2337
2330
|
author: alice,
|
|
2338
2331
|
filter: {
|
|
2339
2332
|
schema: 'test',
|
|
@@ -2342,13 +2335,13 @@ export function testRecordsTags() {
|
|
|
2342
2335
|
}
|
|
2343
2336
|
}
|
|
2344
2337
|
});
|
|
2345
|
-
const queryForHighReply =
|
|
2338
|
+
const queryForHighReply = await dwn.processMessage(alice.did, queryForHighGrade.message);
|
|
2346
2339
|
expect(queryForHighReply.status.code).toBe(200);
|
|
2347
|
-
expect(
|
|
2340
|
+
expect(queryForHighReply.entries?.length).toBe(1);
|
|
2348
2341
|
expect(queryForHighReply.entries[0].recordId).toBe(danielRecord.message.recordId);
|
|
2349
2342
|
// query for all records that received higher (and including) a 75
|
|
2350
2343
|
// three records should match
|
|
2351
|
-
const queryForPassingGrade =
|
|
2344
|
+
const queryForPassingGrade = await TestDataGenerator.generateRecordsQuery({
|
|
2352
2345
|
author: alice,
|
|
2353
2346
|
filter: {
|
|
2354
2347
|
schema: 'test',
|
|
@@ -2357,15 +2350,15 @@ export function testRecordsTags() {
|
|
|
2357
2350
|
}
|
|
2358
2351
|
}
|
|
2359
2352
|
});
|
|
2360
|
-
const queryForPassingGradeReply =
|
|
2353
|
+
const queryForPassingGradeReply = await dwn.processMessage(alice.did, queryForPassingGrade.message);
|
|
2361
2354
|
expect(queryForPassingGradeReply.status.code).toBe(200);
|
|
2362
|
-
expect(
|
|
2355
|
+
expect(queryForPassingGradeReply.entries?.length).toBe(3);
|
|
2363
2356
|
const passingRecords = queryForPassingGradeReply.entries.map(entry => entry.recordId);
|
|
2364
2357
|
expect(passingRecords).toEqual(expect.arrayContaining([
|
|
2365
2358
|
danielRecord.message.recordId, bobRecord.message.recordId, aliceRecord.message.recordId
|
|
2366
2359
|
]));
|
|
2367
2360
|
// query for poorly performing grades (65 and below, inclusive)
|
|
2368
|
-
const queryForPoorGrades =
|
|
2361
|
+
const queryForPoorGrades = await TestDataGenerator.generateRecordsQuery({
|
|
2369
2362
|
author: alice,
|
|
2370
2363
|
filter: {
|
|
2371
2364
|
schema: 'test',
|
|
@@ -2374,12 +2367,12 @@ export function testRecordsTags() {
|
|
|
2374
2367
|
}
|
|
2375
2368
|
}
|
|
2376
2369
|
});
|
|
2377
|
-
const queryForPoorGradesReply =
|
|
2370
|
+
const queryForPoorGradesReply = await dwn.processMessage(alice.did, queryForPoorGrades.message);
|
|
2378
2371
|
expect(queryForPoorGradesReply.status.code).toBe(200);
|
|
2379
|
-
expect(
|
|
2372
|
+
expect(queryForPoorGradesReply.entries?.length).toBe(1);
|
|
2380
2373
|
expect(queryForPoorGradesReply.entries[0].recordId).toBe(carolRecord.message.recordId);
|
|
2381
2374
|
// query for passing grades that were not perfect scores
|
|
2382
|
-
const queryForRange =
|
|
2375
|
+
const queryForRange = await TestDataGenerator.generateRecordsQuery({
|
|
2383
2376
|
author: alice,
|
|
2384
2377
|
filter: {
|
|
2385
2378
|
schema: 'test',
|
|
@@ -2388,16 +2381,16 @@ export function testRecordsTags() {
|
|
|
2388
2381
|
}
|
|
2389
2382
|
}
|
|
2390
2383
|
});
|
|
2391
|
-
const queryForRangeReply =
|
|
2384
|
+
const queryForRangeReply = await dwn.processMessage(alice.did, queryForRange.message);
|
|
2392
2385
|
expect(queryForRangeReply.status.code).toBe(200);
|
|
2393
|
-
expect(
|
|
2386
|
+
expect(queryForRangeReply.entries?.length).toBe(2);
|
|
2394
2387
|
const rangeRecords = queryForRangeReply.entries.map(entry => entry.recordId);
|
|
2395
2388
|
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
|
-
|
|
2400
|
-
const tagsRecord1 =
|
|
2389
|
+
});
|
|
2390
|
+
it('should return results based on the latest tag values', async () => {
|
|
2391
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
2392
|
+
await TestDataGenerator.installDefaultTestProtocol(dwn, alice);
|
|
2393
|
+
const tagsRecord1 = await TestDataGenerator.generateRecordsWrite({
|
|
2401
2394
|
author: alice,
|
|
2402
2395
|
published: true,
|
|
2403
2396
|
schema: 'post',
|
|
@@ -2405,9 +2398,9 @@ export function testRecordsTags() {
|
|
|
2405
2398
|
stringTag: 'string-value',
|
|
2406
2399
|
}
|
|
2407
2400
|
});
|
|
2408
|
-
const tagsRecord1Reply =
|
|
2401
|
+
const tagsRecord1Reply = await dwn.processMessage(alice.did, tagsRecord1.message, { dataStream: tagsRecord1.dataStream });
|
|
2409
2402
|
expect(tagsRecord1Reply.status.code).toBe(202);
|
|
2410
|
-
const tagsQueryMatch =
|
|
2403
|
+
const tagsQueryMatch = await TestDataGenerator.generateRecordsQuery({
|
|
2411
2404
|
author: alice,
|
|
2412
2405
|
filter: {
|
|
2413
2406
|
tags: {
|
|
@@ -2415,27 +2408,27 @@ export function testRecordsTags() {
|
|
|
2415
2408
|
}
|
|
2416
2409
|
}
|
|
2417
2410
|
});
|
|
2418
|
-
const tagsQueryMatchReply =
|
|
2411
|
+
const tagsQueryMatchReply = await dwn.processMessage(alice.did, tagsQueryMatch.message);
|
|
2419
2412
|
expect(tagsQueryMatchReply.status.code).toBe(200);
|
|
2420
|
-
expect(
|
|
2413
|
+
expect(tagsQueryMatchReply.entries?.length).toBe(1);
|
|
2421
2414
|
expect(tagsQueryMatchReply.entries[0].recordId).toBe(tagsRecord1.message.recordId);
|
|
2422
2415
|
// update the record with new tags
|
|
2423
|
-
const updatedRecord =
|
|
2416
|
+
const updatedRecord = await TestDataGenerator.generateFromRecordsWrite({
|
|
2424
2417
|
author: alice,
|
|
2425
2418
|
existingWrite: tagsRecord1.recordsWrite,
|
|
2426
2419
|
tags: { otherTag: 'other-value' } // new tags
|
|
2427
2420
|
});
|
|
2428
|
-
const updatedRecordReply =
|
|
2421
|
+
const updatedRecordReply = await dwn.processMessage(alice.did, updatedRecord.message, { dataStream: updatedRecord.dataStream });
|
|
2429
2422
|
expect(updatedRecordReply.status.code).toBe(202);
|
|
2430
2423
|
// issuing the same query should return no results
|
|
2431
|
-
const tagsQueryMatchReply2 =
|
|
2424
|
+
const tagsQueryMatchReply2 = await dwn.processMessage(alice.did, tagsQueryMatch.message);
|
|
2432
2425
|
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
|
-
|
|
2438
|
-
const tagsRecord1 =
|
|
2426
|
+
expect(tagsQueryMatchReply2.entries?.length).toBe(0);
|
|
2427
|
+
});
|
|
2428
|
+
it('should not return results if the record was updated with empty tags', async () => {
|
|
2429
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
2430
|
+
await TestDataGenerator.installDefaultTestProtocol(dwn, alice);
|
|
2431
|
+
const tagsRecord1 = await TestDataGenerator.generateRecordsWrite({
|
|
2439
2432
|
author: alice,
|
|
2440
2433
|
published: true,
|
|
2441
2434
|
schema: 'post',
|
|
@@ -2443,9 +2436,9 @@ export function testRecordsTags() {
|
|
|
2443
2436
|
stringTag: 'string-value',
|
|
2444
2437
|
}
|
|
2445
2438
|
});
|
|
2446
|
-
const tagsRecord1Reply =
|
|
2439
|
+
const tagsRecord1Reply = await dwn.processMessage(alice.did, tagsRecord1.message, { dataStream: tagsRecord1.dataStream });
|
|
2447
2440
|
expect(tagsRecord1Reply.status.code).toBe(202);
|
|
2448
|
-
const tagsQueryMatch =
|
|
2441
|
+
const tagsQueryMatch = await TestDataGenerator.generateRecordsQuery({
|
|
2449
2442
|
author: alice,
|
|
2450
2443
|
filter: {
|
|
2451
2444
|
tags: {
|
|
@@ -2453,29 +2446,29 @@ export function testRecordsTags() {
|
|
|
2453
2446
|
}
|
|
2454
2447
|
}
|
|
2455
2448
|
});
|
|
2456
|
-
const tagsQueryMatchReply =
|
|
2449
|
+
const tagsQueryMatchReply = await dwn.processMessage(alice.did, tagsQueryMatch.message);
|
|
2457
2450
|
expect(tagsQueryMatchReply.status.code).toBe(200);
|
|
2458
|
-
expect(
|
|
2451
|
+
expect(tagsQueryMatchReply.entries?.length).toBe(1);
|
|
2459
2452
|
expect(tagsQueryMatchReply.entries[0].recordId).toBe(tagsRecord1.message.recordId);
|
|
2460
2453
|
// update the record without any tags
|
|
2461
|
-
const updatedRecord =
|
|
2454
|
+
const updatedRecord = await TestDataGenerator.generateFromRecordsWrite({
|
|
2462
2455
|
author: alice,
|
|
2463
2456
|
existingWrite: tagsRecord1.recordsWrite,
|
|
2464
2457
|
});
|
|
2465
|
-
const updatedRecordReply =
|
|
2458
|
+
const updatedRecordReply = await dwn.processMessage(alice.did, updatedRecord.message, { dataStream: updatedRecord.dataStream });
|
|
2466
2459
|
expect(updatedRecordReply.status.code).toBe(202);
|
|
2467
2460
|
// issuing the same query should return no results
|
|
2468
|
-
const tagsQueryMatchReply2 =
|
|
2461
|
+
const tagsQueryMatchReply2 = await dwn.processMessage(alice.did, tagsQueryMatch.message);
|
|
2469
2462
|
expect(tagsQueryMatchReply2.status.code).toBe(200);
|
|
2470
|
-
expect(
|
|
2471
|
-
})
|
|
2463
|
+
expect(tagsQueryMatchReply2.entries?.length).toBe(0);
|
|
2464
|
+
});
|
|
2472
2465
|
});
|
|
2473
2466
|
describe('RecordsDelete with tags', () => {
|
|
2474
|
-
it('should delete record with tags', () =>
|
|
2475
|
-
|
|
2476
|
-
|
|
2467
|
+
it('should delete record with tags', async () => {
|
|
2468
|
+
const alice = await TestDataGenerator.generateDidKeyPersona();
|
|
2469
|
+
await TestDataGenerator.installDefaultTestProtocol(dwn, alice);
|
|
2477
2470
|
// create a record with a tag
|
|
2478
|
-
const tagsRecord1 =
|
|
2471
|
+
const tagsRecord1 = await TestDataGenerator.generateRecordsWrite({
|
|
2479
2472
|
author: alice,
|
|
2480
2473
|
published: true,
|
|
2481
2474
|
schema: 'post',
|
|
@@ -2483,10 +2476,10 @@ export function testRecordsTags() {
|
|
|
2483
2476
|
stringTag: 'string-value',
|
|
2484
2477
|
}
|
|
2485
2478
|
});
|
|
2486
|
-
const tagsRecord1Reply =
|
|
2479
|
+
const tagsRecord1Reply = await dwn.processMessage(alice.did, tagsRecord1.message, { dataStream: tagsRecord1.dataStream });
|
|
2487
2480
|
expect(tagsRecord1Reply.status.code).toBe(202);
|
|
2488
2481
|
//sanity: query for the record
|
|
2489
|
-
const tagsQueryMatch =
|
|
2482
|
+
const tagsQueryMatch = await TestDataGenerator.generateRecordsQuery({
|
|
2490
2483
|
author: alice,
|
|
2491
2484
|
filter: {
|
|
2492
2485
|
tags: {
|
|
@@ -2494,22 +2487,22 @@ export function testRecordsTags() {
|
|
|
2494
2487
|
}
|
|
2495
2488
|
}
|
|
2496
2489
|
});
|
|
2497
|
-
const tagsQueryMatchReply =
|
|
2490
|
+
const tagsQueryMatchReply = await dwn.processMessage(alice.did, tagsQueryMatch.message);
|
|
2498
2491
|
expect(tagsQueryMatchReply.status.code).toBe(200);
|
|
2499
|
-
expect(
|
|
2492
|
+
expect(tagsQueryMatchReply.entries?.length).toBe(1);
|
|
2500
2493
|
expect(tagsQueryMatchReply.entries[0].recordId).toBe(tagsRecord1.message.recordId);
|
|
2501
2494
|
// delete the record
|
|
2502
|
-
const recordDelete =
|
|
2495
|
+
const recordDelete = await TestDataGenerator.generateRecordsDelete({
|
|
2503
2496
|
author: alice,
|
|
2504
2497
|
recordId: tagsRecord1.message.recordId,
|
|
2505
2498
|
});
|
|
2506
|
-
const recordDeleteReply =
|
|
2499
|
+
const recordDeleteReply = await dwn.processMessage(alice.did, recordDelete.message);
|
|
2507
2500
|
expect(recordDeleteReply.status.code).toBe(202);
|
|
2508
2501
|
// issue the the same query should return no results
|
|
2509
|
-
const tagsQueryMatchReply2 =
|
|
2502
|
+
const tagsQueryMatchReply2 = await dwn.processMessage(alice.did, tagsQueryMatch.message);
|
|
2510
2503
|
expect(tagsQueryMatchReply2.status.code).toBe(200);
|
|
2511
|
-
expect(
|
|
2512
|
-
})
|
|
2504
|
+
expect(tagsQueryMatchReply2.entries?.length).toBe(0);
|
|
2505
|
+
});
|
|
2513
2506
|
});
|
|
2514
2507
|
});
|
|
2515
2508
|
}
|