@graphprotocol/grc-20 0.31.0 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/constants.d.ts +7 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +8 -0
- package/dist/constants.js.map +1 -0
- package/dist/convert-ids.d.ts +2 -0
- package/dist/convert-ids.d.ts.map +1 -0
- package/dist/convert-ids.js +42 -0
- package/dist/convert-ids.js.map +1 -0
- package/dist/examples/ranks/create-ordinal-rank.js +4 -4
- package/dist/examples/ranks/create-ordinal-rank.js.map +1 -1
- package/dist/examples/ranks/create-weighted-rank.js +4 -4
- package/dist/examples/ranks/create-weighted-rank.js.map +1 -1
- package/dist/proto.d.ts +4 -8
- package/dist/proto.d.ts.map +1 -1
- package/dist/proto.js +4 -8
- package/dist/proto.js.map +1 -1
- package/dist/protov2.d.ts +11 -0
- package/dist/protov2.d.ts.map +1 -0
- package/dist/protov2.js +11 -0
- package/dist/protov2.js.map +1 -0
- package/dist/scripts/setup-rank-types.d.ts +2 -2
- package/dist/scripts/setup-rank-types.d.ts.map +1 -1
- package/dist/scripts/setup-rank-types.js.map +1 -1
- package/dist/src/codec/convert.d.ts +18 -0
- package/dist/src/codec/convert.d.ts.map +1 -0
- package/dist/src/codec/convert.js +188 -0
- package/dist/src/codec/convert.js.map +1 -0
- package/dist/src/core/account.d.ts +2 -2
- package/dist/src/core/account.d.ts.map +1 -1
- package/dist/src/core/account.js +2 -0
- package/dist/src/core/account.js.map +1 -1
- package/dist/src/core/account.test.js +69 -22
- package/dist/src/core/account.test.js.map +1 -1
- package/dist/src/core/blocks/data.d.ts +3 -3
- package/dist/src/core/blocks/data.d.ts.map +1 -1
- package/dist/src/core/blocks/data.js +2 -1
- package/dist/src/core/blocks/data.js.map +1 -1
- package/dist/src/core/blocks/data.test.js +74 -36
- package/dist/src/core/blocks/data.test.js.map +1 -1
- package/dist/src/core/blocks/image.d.ts +15 -0
- package/dist/src/core/blocks/image.d.ts.map +1 -0
- package/dist/src/core/blocks/image.js +15 -0
- package/dist/src/core/blocks/image.js.map +1 -0
- package/dist/src/core/blocks/text.d.ts +3 -3
- package/dist/src/core/blocks/text.d.ts.map +1 -1
- package/dist/src/core/blocks/text.js +2 -1
- package/dist/src/core/blocks/text.js.map +1 -1
- package/dist/src/core/blocks/text.test.js +79 -15
- package/dist/src/core/blocks/text.test.js.map +1 -1
- package/dist/src/core/idsv2/content.d.ts +59 -0
- package/dist/src/core/idsv2/content.d.ts.map +1 -0
- package/dist/src/core/idsv2/content.js +59 -0
- package/dist/src/core/idsv2/content.js.map +1 -0
- package/dist/src/core/idsv2/network.d.ts +5 -0
- package/dist/src/core/idsv2/network.d.ts.map +1 -0
- package/dist/src/core/idsv2/network.js +5 -0
- package/dist/src/core/idsv2/network.js.map +1 -0
- package/dist/src/core/idsv2/system.d.ts +222 -0
- package/dist/src/core/idsv2/system.d.ts.map +1 -0
- package/dist/src/core/idsv2/system.js +230 -0
- package/dist/src/core/idsv2/system.js.map +1 -0
- package/dist/src/core/image.d.ts +40 -0
- package/dist/src/core/image.d.ts.map +1 -0
- package/dist/src/core/image.js +76 -0
- package/dist/src/core/image.js.map +1 -0
- package/dist/src/core/image.test.d.ts +2 -0
- package/dist/src/core/image.test.d.ts.map +1 -0
- package/dist/src/core/image.test.js +52 -0
- package/dist/src/core/image.test.js.map +1 -0
- package/dist/src/core/relation.d.ts +88 -0
- package/dist/src/core/relation.d.ts.map +1 -0
- package/dist/src/core/relation.js +89 -0
- package/dist/src/core/relation.js.map +1 -0
- package/dist/src/core/relation.test.d.ts +2 -0
- package/dist/src/core/relation.test.d.ts.map +1 -0
- package/dist/src/core/relation.test.js +45 -0
- package/dist/src/core/relation.test.js.map +1 -0
- package/dist/src/core/triple.d.ts +50 -0
- package/dist/src/core/triple.d.ts.map +1 -0
- package/dist/src/core/triple.js +56 -0
- package/dist/src/core/triple.js.map +1 -0
- package/dist/src/core/triple.test.d.ts +2 -0
- package/dist/src/core/triple.test.d.ts.map +1 -0
- package/dist/src/core/triple.test.js +37 -0
- package/dist/src/core/triple.test.js.map +1 -0
- package/dist/src/encoding.d.ts +2 -1
- package/dist/src/encoding.d.ts.map +1 -1
- package/dist/src/encoding.js +2 -2
- package/dist/src/encoding.js.map +1 -1
- package/dist/src/encoding.test.d.ts +2 -0
- package/dist/src/encoding.test.d.ts.map +1 -0
- package/dist/src/encoding.test.js +644 -0
- package/dist/src/encoding.test.js.map +1 -0
- package/dist/src/encodings/get-register-space-calldata.d.ts +32 -0
- package/dist/src/encodings/get-register-space-calldata.d.ts.map +1 -0
- package/dist/src/encodings/get-register-space-calldata.js +39 -0
- package/dist/src/encodings/get-register-space-calldata.js.map +1 -0
- package/dist/src/encodings/get-register-space-calldata.test.d.ts +2 -0
- package/dist/src/encodings/get-register-space-calldata.test.d.ts.map +1 -0
- package/dist/src/encodings/get-register-space-calldata.test.js +15 -0
- package/dist/src/encodings/get-register-space-calldata.test.js.map +1 -0
- package/dist/src/full-flow-test.test.js +125 -37
- package/dist/src/full-flow-test.test.js.map +1 -1
- package/dist/src/graph/constants.d.ts +4 -0
- package/dist/src/graph/constants.d.ts.map +1 -1
- package/dist/src/graph/constants.js +14 -0
- package/dist/src/graph/constants.js.map +1 -1
- package/dist/src/graph/create-entity.d.ts +0 -1
- package/dist/src/graph/create-entity.d.ts.map +1 -1
- package/dist/src/graph/create-entity.js +155 -111
- package/dist/src/graph/create-entity.js.map +1 -1
- package/dist/src/graph/create-entity.test.js +339 -206
- package/dist/src/graph/create-entity.test.js.map +1 -1
- package/dist/src/graph/create-image.d.ts.map +1 -1
- package/dist/src/graph/create-image.js +15 -14
- package/dist/src/graph/create-image.js.map +1 -1
- package/dist/src/graph/create-image.test.js +109 -50
- package/dist/src/graph/create-image.test.js.map +1 -1
- package/dist/src/graph/create-property.d.ts.map +1 -1
- package/dist/src/graph/create-property.js +10 -19
- package/dist/src/graph/create-property.js.map +1 -1
- package/dist/src/graph/create-property.test.js +129 -19
- package/dist/src/graph/create-property.test.js.map +1 -1
- package/dist/src/graph/create-relation.d.ts +1 -3
- package/dist/src/graph/create-relation.d.ts.map +1 -1
- package/dist/src/graph/create-relation.js +21 -37
- package/dist/src/graph/create-relation.js.map +1 -1
- package/dist/src/graph/create-relation.test.js +186 -200
- package/dist/src/graph/create-relation.test.js.map +1 -1
- package/dist/src/graph/create-space.d.ts +4 -3
- package/dist/src/graph/create-space.d.ts.map +1 -1
- package/dist/src/graph/create-space.js +2 -2
- package/dist/src/graph/create-space.js.map +1 -1
- package/dist/src/graph/create-type.d.ts.map +1 -1
- package/dist/src/graph/create-type.js +16 -21
- package/dist/src/graph/create-type.js.map +1 -1
- package/dist/src/graph/create-type.test.js +76 -67
- package/dist/src/graph/create-type.test.js.map +1 -1
- package/dist/src/graph/delete-entity.d.ts +14 -0
- package/dist/src/graph/delete-entity.d.ts.map +1 -0
- package/dist/src/graph/delete-entity.js +21 -0
- package/dist/src/graph/delete-entity.js.map +1 -0
- package/dist/src/graph/delete-entity.test.d.ts +2 -0
- package/dist/src/graph/delete-entity.test.d.ts.map +1 -0
- package/dist/src/graph/delete-entity.test.js +23 -0
- package/dist/src/graph/delete-entity.test.js.map +1 -0
- package/dist/src/graph/delete-relation.d.ts.map +1 -1
- package/dist/src/graph/delete-relation.js +3 -6
- package/dist/src/graph/delete-relation.js.map +1 -1
- package/dist/src/graph/delete-relation.test.js +6 -8
- package/dist/src/graph/delete-relation.test.js.map +1 -1
- package/dist/src/graph/graph.test.d.ts +2 -0
- package/dist/src/graph/graph.test.d.ts.map +1 -0
- package/dist/src/graph/graph.test.js +46 -0
- package/dist/src/graph/graph.test.js.map +1 -0
- package/dist/src/graph/helpers/create-default-properties.d.ts +5 -0
- package/dist/src/graph/helpers/create-default-properties.d.ts.map +1 -0
- package/dist/src/graph/helpers/create-default-properties.js +44 -0
- package/dist/src/graph/helpers/create-default-properties.js.map +1 -0
- package/dist/src/graph/helpers/create-properties.d.ts +8 -0
- package/dist/src/graph/helpers/create-properties.d.ts.map +1 -0
- package/dist/src/graph/helpers/create-properties.js +53 -0
- package/dist/src/graph/helpers/create-properties.js.map +1 -0
- package/dist/src/graph/index.d.ts +1 -4
- package/dist/src/graph/index.d.ts.map +1 -1
- package/dist/src/graph/index.js +1 -4
- package/dist/src/graph/index.js.map +1 -1
- package/dist/src/graph/update-entity.d.ts.map +1 -1
- package/dist/src/graph/update-entity.js +109 -57
- package/dist/src/graph/update-entity.js.map +1 -1
- package/dist/src/graph/update-entity.test.js +167 -40
- package/dist/src/graph/update-entity.test.js.map +1 -1
- package/dist/src/graph/update-relation.d.ts +1 -2
- package/dist/src/graph/update-relation.d.ts.map +1 -1
- package/dist/src/graph/update-relation.js +12 -16
- package/dist/src/graph/update-relation.js.map +1 -1
- package/dist/src/graph/update-relation.test.js +75 -109
- package/dist/src/graph/update-relation.test.js.map +1 -1
- package/dist/src/graphv2/constants.d.ts +2 -0
- package/dist/src/graphv2/constants.d.ts.map +1 -0
- package/dist/src/graphv2/constants.js +2 -0
- package/dist/src/graphv2/constants.js.map +1 -0
- package/dist/src/graphv2/create-entity.d.ts +52 -0
- package/dist/src/graphv2/create-entity.d.ts.map +1 -0
- package/dist/src/graphv2/create-entity.js +140 -0
- package/dist/src/graphv2/create-entity.js.map +1 -0
- package/dist/src/graphv2/create-entity.test.d.ts +2 -0
- package/dist/src/graphv2/create-entity.test.d.ts.map +1 -0
- package/dist/src/graphv2/create-entity.test.js +158 -0
- package/dist/src/graphv2/create-entity.test.js.map +1 -0
- package/dist/src/graphv2/create-image.d.ts +28 -0
- package/dist/src/graphv2/create-image.d.ts.map +1 -0
- package/dist/src/graphv2/create-image.js +71 -0
- package/dist/src/graphv2/create-image.js.map +1 -0
- package/dist/src/graphv2/create-image.test.d.ts +2 -0
- package/dist/src/graphv2/create-image.test.d.ts.map +1 -0
- package/dist/src/graphv2/create-image.test.js +142 -0
- package/dist/src/graphv2/create-image.test.js.map +1 -0
- package/dist/src/graphv2/create-property.d.ts +22 -0
- package/dist/src/graphv2/create-property.d.ts.map +1 -0
- package/dist/src/graphv2/create-property.js +129 -0
- package/dist/src/graphv2/create-property.js.map +1 -0
- package/dist/src/graphv2/create-property.test.d.ts +2 -0
- package/dist/src/graphv2/create-property.test.d.ts.map +1 -0
- package/dist/src/graphv2/create-property.test.js +82 -0
- package/dist/src/graphv2/create-property.test.js.map +1 -0
- package/dist/src/graphv2/create-relation.d.ts +33 -0
- package/dist/src/graphv2/create-relation.d.ts.map +1 -0
- package/dist/src/graphv2/create-relation.js +66 -0
- package/dist/src/graphv2/create-relation.js.map +1 -0
- package/dist/src/graphv2/create-relation.test.d.ts +2 -0
- package/dist/src/graphv2/create-relation.test.d.ts.map +1 -0
- package/dist/src/graphv2/create-relation.test.js +208 -0
- package/dist/src/graphv2/create-relation.test.js.map +1 -0
- package/dist/src/graphv2/create-space.d.ts +13 -0
- package/dist/src/graphv2/create-space.d.ts.map +1 -0
- package/dist/src/graphv2/create-space.js +21 -0
- package/dist/src/graphv2/create-space.js.map +1 -0
- package/dist/src/graphv2/create-type.d.ts +22 -0
- package/dist/src/graphv2/create-type.d.ts.map +1 -0
- package/dist/src/graphv2/create-type.js +64 -0
- package/dist/src/graphv2/create-type.js.map +1 -0
- package/dist/src/graphv2/create-type.test.d.ts +2 -0
- package/dist/src/graphv2/create-type.test.d.ts.map +1 -0
- package/dist/src/graphv2/create-type.test.js +109 -0
- package/dist/src/graphv2/create-type.test.js.map +1 -0
- package/dist/src/graphv2/delete-entity.d.ts +14 -0
- package/dist/src/graphv2/delete-entity.d.ts.map +1 -0
- package/dist/src/graphv2/delete-entity.js +21 -0
- package/dist/src/graphv2/delete-entity.js.map +1 -0
- package/dist/src/graphv2/delete-entity.test.d.ts +2 -0
- package/dist/src/graphv2/delete-entity.test.d.ts.map +1 -0
- package/dist/src/graphv2/delete-entity.test.js +24 -0
- package/dist/src/graphv2/delete-entity.test.js.map +1 -0
- package/dist/src/graphv2/delete-relation.d.ts +14 -0
- package/dist/src/graphv2/delete-relation.d.ts.map +1 -0
- package/dist/src/graphv2/delete-relation.js +21 -0
- package/dist/src/graphv2/delete-relation.js.map +1 -0
- package/dist/src/graphv2/delete-relation.test.d.ts +2 -0
- package/dist/src/graphv2/delete-relation.test.d.ts.map +1 -0
- package/dist/src/graphv2/delete-relation.test.js +24 -0
- package/dist/src/graphv2/delete-relation.test.js.map +1 -0
- package/dist/src/graphv2/index.d.ts +12 -0
- package/dist/src/graphv2/index.d.ts.map +1 -0
- package/dist/src/graphv2/index.js +12 -0
- package/dist/src/graphv2/index.js.map +1 -0
- package/dist/src/graphv2/remove-entity-properties.d.ts +25 -0
- package/dist/src/graphv2/remove-entity-properties.d.ts.map +1 -0
- package/dist/src/graphv2/remove-entity-properties.js +24 -0
- package/dist/src/graphv2/remove-entity-properties.js.map +1 -0
- package/dist/src/graphv2/unset-entity-values.d.ts +21 -0
- package/dist/src/graphv2/unset-entity-values.d.ts.map +1 -0
- package/dist/src/graphv2/unset-entity-values.js +26 -0
- package/dist/src/graphv2/unset-entity-values.js.map +1 -0
- package/dist/src/graphv2/unset-entity-values.test.d.ts +2 -0
- package/dist/src/graphv2/unset-entity-values.test.d.ts.map +1 -0
- package/dist/src/graphv2/unset-entity-values.test.js +40 -0
- package/dist/src/graphv2/unset-entity-values.test.js.map +1 -0
- package/dist/src/graphv2/unset-relation-fields.d.ts +25 -0
- package/dist/src/graphv2/unset-relation-fields.d.ts.map +1 -0
- package/dist/src/graphv2/unset-relation-fields.js +34 -0
- package/dist/src/graphv2/unset-relation-fields.js.map +1 -0
- package/dist/src/graphv2/unset-relation-fields.test.d.ts +2 -0
- package/dist/src/graphv2/unset-relation-fields.test.d.ts.map +1 -0
- package/dist/src/graphv2/unset-relation-fields.test.js +64 -0
- package/dist/src/graphv2/unset-relation-fields.test.js.map +1 -0
- package/dist/src/graphv2/update-entity.d.ts +28 -0
- package/dist/src/graphv2/update-entity.d.ts.map +1 -0
- package/dist/src/graphv2/update-entity.js +73 -0
- package/dist/src/graphv2/update-entity.js.map +1 -0
- package/dist/src/graphv2/update-entity.test.d.ts +2 -0
- package/dist/src/graphv2/update-entity.test.d.ts.map +1 -0
- package/dist/src/graphv2/update-entity.test.js +116 -0
- package/dist/src/graphv2/update-entity.test.js.map +1 -0
- package/dist/src/graphv2/update-relation.d.ts +21 -0
- package/dist/src/graphv2/update-relation.d.ts.map +1 -0
- package/dist/src/graphv2/update-relation.js +37 -0
- package/dist/src/graphv2/update-relation.js.map +1 -0
- package/dist/src/id-utils.d.ts +6 -0
- package/dist/src/id-utils.d.ts.map +1 -1
- package/dist/src/id-utils.js +13 -0
- package/dist/src/id-utils.js.map +1 -1
- package/dist/src/idv2.d.ts +27 -0
- package/dist/src/idv2.d.ts.map +1 -0
- package/dist/src/idv2.js +88 -0
- package/dist/src/idv2.js.map +1 -0
- package/dist/src/idv2.test.d.ts +2 -0
- package/dist/src/idv2.test.d.ts.map +1 -0
- package/dist/src/idv2.test.js +26 -0
- package/dist/src/idv2.test.js.map +1 -0
- package/dist/src/image.d.ts +8 -0
- package/dist/src/image.d.ts.map +1 -0
- package/dist/src/image.js +8 -0
- package/dist/src/image.js.map +1 -0
- package/dist/src/ipfs.d.ts +7 -6
- package/dist/src/ipfs.d.ts.map +1 -1
- package/dist/src/ipfs.js +31 -11
- package/dist/src/ipfs.js.map +1 -1
- package/dist/src/ipfs.test.js +130 -17
- package/dist/src/ipfs.test.js.map +1 -1
- package/dist/src/ipfsv2.d.ts +96 -0
- package/dist/src/ipfsv2.d.ts.map +1 -0
- package/dist/src/ipfsv2.js +163 -0
- package/dist/src/ipfsv2.js.map +1 -0
- package/dist/src/ipfsv2.test.d.ts +2 -0
- package/dist/src/ipfsv2.test.d.ts.map +1 -0
- package/dist/src/ipfsv2.test.js +22 -0
- package/dist/src/ipfsv2.test.js.map +1 -0
- package/dist/src/proto/editv2.d.ts +11 -0
- package/dist/src/proto/editv2.d.ts.map +1 -0
- package/dist/src/proto/editv2.js +81 -0
- package/dist/src/proto/editv2.js.map +1 -0
- package/dist/src/proto/editv2.test.d.ts +2 -0
- package/dist/src/proto/editv2.test.d.ts.map +1 -0
- package/dist/src/proto/editv2.test.js +211 -0
- package/dist/src/proto/editv2.test.js.map +1 -0
- package/dist/src/proto/gen/src/proto/ipfsv2_pb.d.ts +410 -0
- package/dist/src/proto/gen/src/proto/ipfsv2_pb.d.ts.map +1 -0
- package/dist/src/proto/gen/src/proto/ipfsv2_pb.js +536 -0
- package/dist/src/proto/gen/src/proto/ipfsv2_pb.js.map +1 -0
- package/dist/src/proto/index.d.ts +7 -1
- package/dist/src/proto/index.d.ts.map +1 -1
- package/dist/src/proto/index.js +6 -1
- package/dist/src/proto/index.js.map +1 -1
- package/dist/src/ranks/create-rank.d.ts.map +1 -1
- package/dist/src/ranks/create-rank.js +54 -47
- package/dist/src/ranks/create-rank.js.map +1 -1
- package/dist/src/ranks/create-rank.test.js +181 -94
- package/dist/src/ranks/create-rank.test.js.map +1 -1
- package/dist/src/relation.d.ts +7 -0
- package/dist/src/relation.d.ts.map +1 -0
- package/dist/src/relation.js +7 -0
- package/dist/src/relation.js.map +1 -0
- package/dist/src/smart-wallet-2.test-invalid.d.ts +2 -0
- package/dist/src/smart-wallet-2.test-invalid.d.ts.map +1 -0
- package/dist/src/smart-wallet-2.test-invalid.js +49 -0
- package/dist/src/smart-wallet-2.test-invalid.js.map +1 -0
- package/dist/src/smart-wallet-2.test.d.ts +2 -0
- package/dist/src/smart-wallet-2.test.d.ts.map +1 -0
- package/dist/src/smart-wallet-2.test.js +49 -0
- package/dist/src/smart-wallet-2.test.js.map +1 -0
- package/dist/src/system-ids-v2.d.ts +7 -0
- package/dist/src/system-ids-v2.d.ts.map +1 -0
- package/dist/src/system-ids-v2.js +7 -0
- package/dist/src/system-ids-v2.js.map +1 -0
- package/dist/src/triple.d.ts +7 -0
- package/dist/src/triple.d.ts.map +1 -0
- package/dist/src/triple.js +7 -0
- package/dist/src/triple.js.map +1 -0
- package/dist/src/types-backup.d.ts +134 -0
- package/dist/src/types-backup.d.ts.map +1 -0
- package/dist/src/types-backup.js +13 -0
- package/dist/src/types-backup.js.map +1 -0
- package/dist/src/types.d.ts +52 -89
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/dist/src/typesv2.d.ts +173 -0
- package/dist/src/typesv2.d.ts.map +1 -0
- package/dist/src/typesv2.js +8 -0
- package/dist/src/typesv2.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +2 -5
|
@@ -2,8 +2,8 @@ import { describe, expect, it } from 'vitest';
|
|
|
2
2
|
import { CLAIM_TYPE, NEWS_STORY_TYPE } from '../core/ids/content.js';
|
|
3
3
|
import { COVER_PROPERTY, DESCRIPTION_PROPERTY, NAME_PROPERTY, TYPES_PROPERTY } from '../core/ids/system.js';
|
|
4
4
|
import { Id } from '../id.js';
|
|
5
|
+
import { toGrcId } from '../id-utils.js';
|
|
5
6
|
import { createEntity } from './create-entity.js';
|
|
6
|
-
import { serializeNumber } from './serialize.js';
|
|
7
7
|
describe('createEntity', () => {
|
|
8
8
|
const coverId = Id('30145d36d5a54244be593d111d879ba5');
|
|
9
9
|
it('creates a basic entity without properties', () => {
|
|
@@ -11,14 +11,12 @@ describe('createEntity', () => {
|
|
|
11
11
|
expect(entity).toBeDefined();
|
|
12
12
|
expect(typeof entity.id).toBe('string');
|
|
13
13
|
expect(entity.ops).toBeDefined();
|
|
14
|
-
expect(entity.ops).toHaveLength(1); // One
|
|
15
|
-
expect(entity.ops[0]).
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
},
|
|
21
|
-
});
|
|
14
|
+
expect(entity.ops).toHaveLength(1); // One createEntity op
|
|
15
|
+
expect(entity.ops[0]?.type).toBe('createEntity');
|
|
16
|
+
// Verify the entity op structure
|
|
17
|
+
const entityOp = entity.ops[0];
|
|
18
|
+
expect(entityOp.id).toEqual(toGrcId(entity.id));
|
|
19
|
+
expect(entityOp.values).toEqual([]);
|
|
22
20
|
});
|
|
23
21
|
it('creates an entity with types', () => {
|
|
24
22
|
const entity = createEntity({
|
|
@@ -26,33 +24,24 @@ describe('createEntity', () => {
|
|
|
26
24
|
});
|
|
27
25
|
expect(entity).toBeDefined();
|
|
28
26
|
expect(typeof entity.id).toBe('string');
|
|
29
|
-
expect(entity.ops).toHaveLength(3); // One
|
|
30
|
-
// Check
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
values: [],
|
|
36
|
-
},
|
|
37
|
-
});
|
|
27
|
+
expect(entity.ops).toHaveLength(3); // One createEntity + two createRelation ops
|
|
28
|
+
// Check createEntity op
|
|
29
|
+
const entityOp = entity.ops[0];
|
|
30
|
+
expect(entityOp.type).toBe('createEntity');
|
|
31
|
+
expect(entityOp.id).toEqual(toGrcId(entity.id));
|
|
32
|
+
expect(entityOp.values).toEqual([]);
|
|
38
33
|
// Check first type relation
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
type: TYPES_PROPERTY,
|
|
45
|
-
},
|
|
46
|
-
});
|
|
34
|
+
const typeRel1 = entity.ops[1];
|
|
35
|
+
expect(typeRel1.type).toBe('createRelation');
|
|
36
|
+
expect(typeRel1.from).toEqual(toGrcId(entity.id));
|
|
37
|
+
expect(typeRel1.to).toEqual(toGrcId(CLAIM_TYPE));
|
|
38
|
+
expect(typeRel1.relationType).toEqual(toGrcId(TYPES_PROPERTY));
|
|
47
39
|
// Check second type relation
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
type: TYPES_PROPERTY,
|
|
54
|
-
},
|
|
55
|
-
});
|
|
40
|
+
const typeRel2 = entity.ops[2];
|
|
41
|
+
expect(typeRel2.type).toBe('createRelation');
|
|
42
|
+
expect(typeRel2.from).toEqual(toGrcId(entity.id));
|
|
43
|
+
expect(typeRel2.to).toEqual(toGrcId(NEWS_STORY_TYPE));
|
|
44
|
+
expect(typeRel2.relationType).toEqual(toGrcId(TYPES_PROPERTY));
|
|
56
45
|
});
|
|
57
46
|
it('creates an entity with name and description', () => {
|
|
58
47
|
const entity = createEntity({
|
|
@@ -62,22 +51,29 @@ describe('createEntity', () => {
|
|
|
62
51
|
expect(entity).toBeDefined();
|
|
63
52
|
expect(typeof entity.id).toBe('string');
|
|
64
53
|
expect(entity.ops).toHaveLength(1);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
54
|
+
const entityOp = entity.ops[0];
|
|
55
|
+
expect(entityOp.type).toBe('createEntity');
|
|
56
|
+
expect(entityOp.id).toEqual(toGrcId(entity.id));
|
|
57
|
+
// Verify name property
|
|
58
|
+
const nameValue = entityOp.values.find(v => {
|
|
59
|
+
const propBytes = v.property;
|
|
60
|
+
return propBytes.every((b, i) => b === toGrcId(NAME_PROPERTY)[i]);
|
|
61
|
+
});
|
|
62
|
+
expect(nameValue).toBeDefined();
|
|
63
|
+
expect(nameValue?.value.type).toBe('text');
|
|
64
|
+
if (nameValue?.value.type === 'text') {
|
|
65
|
+
expect(nameValue.value.value).toBe('Test Entity');
|
|
66
|
+
}
|
|
67
|
+
// Verify description property
|
|
68
|
+
const descValue = entityOp.values.find(v => {
|
|
69
|
+
const propBytes = v.property;
|
|
70
|
+
return propBytes.every((b, i) => b === toGrcId(DESCRIPTION_PROPERTY)[i]);
|
|
80
71
|
});
|
|
72
|
+
expect(descValue).toBeDefined();
|
|
73
|
+
expect(descValue?.value.type).toBe('text');
|
|
74
|
+
if (descValue?.value.type === 'text') {
|
|
75
|
+
expect(descValue.value.value).toBe('Test Description');
|
|
76
|
+
}
|
|
81
77
|
});
|
|
82
78
|
it('creates an entity with cover', () => {
|
|
83
79
|
const entity = createEntity({
|
|
@@ -86,241 +82,378 @@ describe('createEntity', () => {
|
|
|
86
82
|
expect(entity).toBeDefined();
|
|
87
83
|
expect(typeof entity.id).toBe('string');
|
|
88
84
|
expect(entity.ops).toHaveLength(2);
|
|
89
|
-
// Check
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
id: entity.id,
|
|
94
|
-
values: [],
|
|
95
|
-
},
|
|
96
|
-
});
|
|
85
|
+
// Check createEntity op
|
|
86
|
+
const entityOp = entity.ops[0];
|
|
87
|
+
expect(entityOp.type).toBe('createEntity');
|
|
88
|
+
expect(entityOp.id).toEqual(toGrcId(entity.id));
|
|
97
89
|
// Check cover relation
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
type: COVER_PROPERTY,
|
|
104
|
-
},
|
|
105
|
-
});
|
|
90
|
+
const coverRel = entity.ops[1];
|
|
91
|
+
expect(coverRel.type).toBe('createRelation');
|
|
92
|
+
expect(coverRel.from).toEqual(toGrcId(entity.id));
|
|
93
|
+
expect(coverRel.to).toEqual(toGrcId(coverId));
|
|
94
|
+
expect(coverRel.relationType).toEqual(toGrcId(COVER_PROPERTY));
|
|
106
95
|
});
|
|
107
|
-
it('creates an entity with custom values', () => {
|
|
96
|
+
it('creates an entity with custom text values', () => {
|
|
108
97
|
const customPropertyId = Id('fa269fd3de9849cf90c44235d905a67c');
|
|
109
98
|
const entity = createEntity({
|
|
110
|
-
values: [{ property: customPropertyId, value: 'custom value' }],
|
|
99
|
+
values: [{ property: customPropertyId, type: 'text', value: 'custom value' }],
|
|
111
100
|
});
|
|
112
101
|
expect(entity).toBeDefined();
|
|
113
102
|
expect(typeof entity.id).toBe('string');
|
|
114
103
|
expect(entity.ops).toHaveLength(1);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
],
|
|
125
|
-
},
|
|
126
|
-
});
|
|
104
|
+
const entityOp = entity.ops[0];
|
|
105
|
+
expect(entityOp.type).toBe('createEntity');
|
|
106
|
+
expect(entityOp.values).toHaveLength(1);
|
|
107
|
+
const customValue = entityOp.values[0];
|
|
108
|
+
expect(customValue?.property).toEqual(toGrcId(customPropertyId));
|
|
109
|
+
expect(customValue?.value.type).toBe('text');
|
|
110
|
+
if (customValue?.value.type === 'text') {
|
|
111
|
+
expect(customValue.value.value).toBe('custom value');
|
|
112
|
+
}
|
|
127
113
|
});
|
|
128
|
-
it('creates an entity with a text value with
|
|
114
|
+
it('creates an entity with a text value with language', () => {
|
|
115
|
+
const languageId = Id('0a4e9810f78f429ea4ceb1904a43251d');
|
|
129
116
|
const entity = createEntity({
|
|
130
117
|
values: [
|
|
131
118
|
{
|
|
132
119
|
property: '295c8bc61ae342cbb2a65b61080906ff',
|
|
120
|
+
type: 'text',
|
|
133
121
|
value: 'test',
|
|
134
|
-
|
|
122
|
+
language: languageId,
|
|
135
123
|
},
|
|
136
124
|
],
|
|
137
125
|
});
|
|
138
126
|
expect(entity).toBeDefined();
|
|
139
127
|
expect(typeof entity.id).toBe('string');
|
|
140
128
|
expect(entity.ops).toHaveLength(1);
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
text: {
|
|
151
|
-
language: '0a4e9810f78f429ea4ceb1904a43251d',
|
|
152
|
-
},
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
],
|
|
156
|
-
},
|
|
157
|
-
});
|
|
129
|
+
const entityOp = entity.ops[0];
|
|
130
|
+
expect(entityOp.type).toBe('createEntity');
|
|
131
|
+
expect(entityOp.values).toHaveLength(1);
|
|
132
|
+
const textValue = entityOp.values[0];
|
|
133
|
+
expect(textValue?.value.type).toBe('text');
|
|
134
|
+
if (textValue?.value.type === 'text') {
|
|
135
|
+
expect(textValue.value.value).toBe('test');
|
|
136
|
+
expect(textValue.value.language).toEqual(toGrcId(languageId));
|
|
137
|
+
}
|
|
158
138
|
});
|
|
159
139
|
it('creates an entity with a text value in two different languages', () => {
|
|
140
|
+
const englishLangId = Id('0a4e9810f78f429ea4ceb1904a43251d');
|
|
141
|
+
const spanishLangId = Id('dad6e52a5e944e559411cfe3a3c3ea64');
|
|
160
142
|
const entity = createEntity({
|
|
161
143
|
values: [
|
|
162
144
|
{
|
|
163
145
|
property: '295c8bc61ae342cbb2a65b61080906ff',
|
|
146
|
+
type: 'text',
|
|
164
147
|
value: 'test',
|
|
165
|
-
|
|
148
|
+
language: englishLangId,
|
|
166
149
|
},
|
|
167
150
|
{
|
|
168
151
|
property: '295c8bc61ae342cbb2a65b61080906ff',
|
|
152
|
+
type: 'text',
|
|
169
153
|
value: 'prueba',
|
|
170
|
-
|
|
154
|
+
language: spanishLangId,
|
|
171
155
|
},
|
|
172
156
|
],
|
|
173
157
|
});
|
|
174
158
|
expect(entity).toBeDefined();
|
|
175
159
|
expect(typeof entity.id).toBe('string');
|
|
176
160
|
expect(entity.ops).toHaveLength(1);
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
],
|
|
201
|
-
},
|
|
161
|
+
const entityOp = entity.ops[0];
|
|
162
|
+
expect(entityOp.type).toBe('createEntity');
|
|
163
|
+
expect(entityOp.values).toHaveLength(2);
|
|
164
|
+
// Find English value
|
|
165
|
+
const englishValue = entityOp.values.find(v => {
|
|
166
|
+
if (v.value.type === 'text' && v.value.language) {
|
|
167
|
+
return v.value.language.every((b, i) => b === toGrcId(englishLangId)[i]);
|
|
168
|
+
}
|
|
169
|
+
return false;
|
|
170
|
+
});
|
|
171
|
+
expect(englishValue?.value.type).toBe('text');
|
|
172
|
+
if (englishValue?.value.type === 'text') {
|
|
173
|
+
expect(englishValue.value.value).toBe('test');
|
|
174
|
+
}
|
|
175
|
+
// Find Spanish value
|
|
176
|
+
const spanishValue = entityOp.values.find(v => {
|
|
177
|
+
if (v.value.type === 'text' && v.value.language) {
|
|
178
|
+
return v.value.language.every((b, i) => b === toGrcId(spanishLangId)[i]);
|
|
179
|
+
}
|
|
180
|
+
return false;
|
|
202
181
|
});
|
|
182
|
+
expect(spanishValue?.value.type).toBe('text');
|
|
183
|
+
if (spanishValue?.value.type === 'text') {
|
|
184
|
+
expect(spanishValue.value.value).toBe('prueba');
|
|
185
|
+
}
|
|
203
186
|
});
|
|
204
|
-
it('creates an entity with a
|
|
187
|
+
it('creates an entity with a float64 value', () => {
|
|
188
|
+
const propertyId = Id('295c8bc61ae342cbb2a65b61080906ff');
|
|
205
189
|
const entity = createEntity({
|
|
206
190
|
values: [
|
|
207
191
|
{
|
|
208
|
-
property:
|
|
209
|
-
|
|
192
|
+
property: propertyId,
|
|
193
|
+
type: 'float64',
|
|
194
|
+
value: 42,
|
|
210
195
|
},
|
|
211
196
|
],
|
|
212
197
|
});
|
|
213
198
|
expect(entity).toBeDefined();
|
|
214
199
|
expect(typeof entity.id).toBe('string');
|
|
215
200
|
expect(entity.ops).toHaveLength(1);
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
],
|
|
226
|
-
},
|
|
227
|
-
});
|
|
201
|
+
const entityOp = entity.ops[0];
|
|
202
|
+
expect(entityOp.type).toBe('createEntity');
|
|
203
|
+
expect(entityOp.values).toHaveLength(1);
|
|
204
|
+
const floatValue = entityOp.values[0];
|
|
205
|
+
expect(floatValue?.property).toEqual(toGrcId(propertyId));
|
|
206
|
+
expect(floatValue?.value.type).toBe('float64');
|
|
207
|
+
if (floatValue?.value.type === 'float64') {
|
|
208
|
+
expect(floatValue.value.value).toBe(42);
|
|
209
|
+
}
|
|
228
210
|
});
|
|
229
|
-
it('creates an entity with a
|
|
211
|
+
it('creates an entity with a float64 value with unit', () => {
|
|
212
|
+
const propertyId = Id('295c8bc61ae342cbb2a65b61080906ff');
|
|
213
|
+
const unitId = Id('016c9b1cd8a84e4d9e844e40878bb235');
|
|
230
214
|
const entity = createEntity({
|
|
231
215
|
values: [
|
|
232
216
|
{
|
|
233
|
-
property:
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
unit: '016c9b1cd8a84e4d9e844e40878bb235',
|
|
238
|
-
},
|
|
217
|
+
property: propertyId,
|
|
218
|
+
type: 'float64',
|
|
219
|
+
value: 42,
|
|
220
|
+
unit: unitId,
|
|
239
221
|
},
|
|
240
222
|
],
|
|
241
223
|
});
|
|
242
224
|
expect(entity).toBeDefined();
|
|
243
225
|
expect(typeof entity.id).toBe('string');
|
|
244
226
|
expect(entity.ops).toHaveLength(1);
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
227
|
+
const entityOp = entity.ops[0];
|
|
228
|
+
expect(entityOp.type).toBe('createEntity');
|
|
229
|
+
expect(entityOp.values).toHaveLength(1);
|
|
230
|
+
const floatValue = entityOp.values[0];
|
|
231
|
+
expect(floatValue?.property).toEqual(toGrcId(propertyId));
|
|
232
|
+
expect(floatValue?.value.type).toBe('float64');
|
|
233
|
+
if (floatValue?.value.type === 'float64') {
|
|
234
|
+
expect(floatValue.value.value).toBe(42);
|
|
235
|
+
expect(floatValue.value.unit).toEqual(toGrcId(unitId));
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
it('creates an entity with a boolean value', () => {
|
|
239
|
+
const propertyId = Id('295c8bc61ae342cbb2a65b61080906ff');
|
|
240
|
+
const entity = createEntity({
|
|
241
|
+
values: [
|
|
242
|
+
{
|
|
243
|
+
property: propertyId,
|
|
244
|
+
type: 'bool',
|
|
245
|
+
value: true,
|
|
246
|
+
},
|
|
247
|
+
],
|
|
261
248
|
});
|
|
249
|
+
expect(entity).toBeDefined();
|
|
250
|
+
const entityOp = entity.ops[0];
|
|
251
|
+
expect(entityOp.type).toBe('createEntity');
|
|
252
|
+
expect(entityOp.values).toHaveLength(1);
|
|
253
|
+
const boolValue = entityOp.values[0];
|
|
254
|
+
expect(boolValue?.property).toEqual(toGrcId(propertyId));
|
|
255
|
+
expect(boolValue?.value.type).toBe('bool');
|
|
256
|
+
if (boolValue?.value.type === 'bool') {
|
|
257
|
+
expect(boolValue.value.value).toBe(true);
|
|
258
|
+
}
|
|
262
259
|
});
|
|
263
|
-
it('creates an entity with
|
|
264
|
-
const
|
|
260
|
+
it('creates an entity with a point value', () => {
|
|
261
|
+
const propertyId = Id('295c8bc61ae342cbb2a65b61080906ff');
|
|
265
262
|
const entity = createEntity({
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
263
|
+
values: [
|
|
264
|
+
{
|
|
265
|
+
property: propertyId,
|
|
266
|
+
type: 'point',
|
|
267
|
+
lon: -122.4194,
|
|
268
|
+
lat: 37.7749,
|
|
270
269
|
},
|
|
271
|
-
|
|
270
|
+
],
|
|
272
271
|
});
|
|
273
272
|
expect(entity).toBeDefined();
|
|
274
|
-
|
|
275
|
-
expect(
|
|
276
|
-
expect(
|
|
277
|
-
|
|
273
|
+
const entityOp = entity.ops[0];
|
|
274
|
+
expect(entityOp.type).toBe('createEntity');
|
|
275
|
+
expect(entityOp.values).toHaveLength(1);
|
|
276
|
+
const pointValue = entityOp.values[0];
|
|
277
|
+
expect(pointValue?.property).toEqual(toGrcId(propertyId));
|
|
278
|
+
expect(pointValue?.value.type).toBe('point');
|
|
279
|
+
if (pointValue?.value.type === 'point') {
|
|
280
|
+
expect(pointValue.value.lon).toBe(-122.4194);
|
|
281
|
+
expect(pointValue.value.lat).toBe(37.7749);
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
it('creates an entity with a point value with altitude', () => {
|
|
285
|
+
const propertyId = Id('295c8bc61ae342cbb2a65b61080906ff');
|
|
286
|
+
const entity = createEntity({
|
|
287
|
+
values: [
|
|
288
|
+
{
|
|
289
|
+
property: propertyId,
|
|
290
|
+
type: 'point',
|
|
291
|
+
lon: -122.4194,
|
|
292
|
+
lat: 37.7749,
|
|
293
|
+
alt: 100.5,
|
|
294
|
+
},
|
|
295
|
+
],
|
|
278
296
|
});
|
|
279
|
-
expect(entity
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
297
|
+
expect(entity).toBeDefined();
|
|
298
|
+
const entityOp = entity.ops[0];
|
|
299
|
+
expect(entityOp.type).toBe('createEntity');
|
|
300
|
+
const pointValue = entityOp.values[0];
|
|
301
|
+
expect(pointValue?.value.type).toBe('point');
|
|
302
|
+
if (pointValue?.value.type === 'point') {
|
|
303
|
+
expect(pointValue.value.lon).toBe(-122.4194);
|
|
304
|
+
expect(pointValue.value.lat).toBe(37.7749);
|
|
305
|
+
expect(pointValue.value.alt).toBe(100.5);
|
|
306
|
+
}
|
|
307
|
+
});
|
|
308
|
+
it('creates an entity with a date value', () => {
|
|
309
|
+
const propertyId = Id('295c8bc61ae342cbb2a65b61080906ff');
|
|
310
|
+
const entity = createEntity({
|
|
311
|
+
values: [
|
|
312
|
+
{
|
|
313
|
+
property: propertyId,
|
|
314
|
+
type: 'date',
|
|
315
|
+
value: '2024-03-20',
|
|
316
|
+
},
|
|
317
|
+
],
|
|
286
318
|
});
|
|
319
|
+
expect(entity).toBeDefined();
|
|
320
|
+
const entityOp = entity.ops[0];
|
|
321
|
+
expect(entityOp.type).toBe('createEntity');
|
|
322
|
+
expect(entityOp.values).toHaveLength(1);
|
|
323
|
+
const dateValue = entityOp.values[0];
|
|
324
|
+
expect(dateValue?.property).toEqual(toGrcId(propertyId));
|
|
325
|
+
expect(dateValue?.value.type).toBe('date');
|
|
326
|
+
if (dateValue?.value.type === 'date') {
|
|
327
|
+
expect(dateValue.value.value).toBe('2024-03-20');
|
|
328
|
+
}
|
|
287
329
|
});
|
|
288
|
-
it('creates an entity with
|
|
330
|
+
it('creates an entity with a time value', () => {
|
|
331
|
+
const propertyId = Id('295c8bc61ae342cbb2a65b61080906ff');
|
|
289
332
|
const entity = createEntity({
|
|
290
|
-
|
|
333
|
+
values: [
|
|
334
|
+
{
|
|
335
|
+
property: propertyId,
|
|
336
|
+
type: 'time',
|
|
337
|
+
value: '14:30:00Z',
|
|
338
|
+
},
|
|
339
|
+
],
|
|
291
340
|
});
|
|
292
341
|
expect(entity).toBeDefined();
|
|
293
|
-
|
|
294
|
-
expect(
|
|
295
|
-
|
|
296
|
-
expect(
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
342
|
+
const entityOp = entity.ops[0];
|
|
343
|
+
expect(entityOp.type).toBe('createEntity');
|
|
344
|
+
const timeValue = entityOp.values[0];
|
|
345
|
+
expect(timeValue?.property).toEqual(toGrcId(propertyId));
|
|
346
|
+
expect(timeValue?.value.type).toBe('time');
|
|
347
|
+
if (timeValue?.value.type === 'time') {
|
|
348
|
+
expect(timeValue.value.value).toBe('14:30:00Z');
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
it('creates an entity with a datetime value', () => {
|
|
352
|
+
const propertyId = Id('295c8bc61ae342cbb2a65b61080906ff');
|
|
353
|
+
const entity = createEntity({
|
|
354
|
+
values: [
|
|
355
|
+
{
|
|
356
|
+
property: propertyId,
|
|
357
|
+
type: 'datetime',
|
|
358
|
+
value: '2024-03-20T14:30:00Z',
|
|
359
|
+
},
|
|
360
|
+
],
|
|
302
361
|
});
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
362
|
+
expect(entity).toBeDefined();
|
|
363
|
+
const entityOp = entity.ops[0];
|
|
364
|
+
expect(entityOp.type).toBe('createEntity');
|
|
365
|
+
const datetimeValue = entityOp.values[0];
|
|
366
|
+
expect(datetimeValue?.property).toEqual(toGrcId(propertyId));
|
|
367
|
+
expect(datetimeValue?.value.type).toBe('datetime');
|
|
368
|
+
if (datetimeValue?.value.type === 'datetime') {
|
|
369
|
+
expect(datetimeValue.value.value).toBe('2024-03-20T14:30:00Z');
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
it('creates an entity with a schedule value', () => {
|
|
373
|
+
const propertyId = Id('295c8bc61ae342cbb2a65b61080906ff');
|
|
374
|
+
const entity = createEntity({
|
|
375
|
+
values: [
|
|
376
|
+
{
|
|
377
|
+
property: propertyId,
|
|
378
|
+
type: 'schedule',
|
|
379
|
+
value: 'FREQ=WEEKLY;BYDAY=MO,WE,FR',
|
|
380
|
+
},
|
|
381
|
+
],
|
|
382
|
+
});
|
|
383
|
+
expect(entity).toBeDefined();
|
|
384
|
+
const entityOp = entity.ops[0];
|
|
385
|
+
expect(entityOp.type).toBe('createEntity');
|
|
386
|
+
const scheduleValue = entityOp.values[0];
|
|
387
|
+
expect(scheduleValue?.property).toEqual(toGrcId(propertyId));
|
|
388
|
+
expect(scheduleValue?.value.type).toBe('schedule');
|
|
389
|
+
if (scheduleValue?.value.type === 'schedule') {
|
|
390
|
+
expect(scheduleValue.value.value).toBe('FREQ=WEEKLY;BYDAY=MO,WE,FR');
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
it('creates an entity with relations', () => {
|
|
394
|
+
const providedId = Id('b1dc6e5c63e143bab3d4755b251a4ea1');
|
|
395
|
+
const relationTypeId = Id('295c8bc61ae342cbb2a65b61080906ff');
|
|
396
|
+
const toEntityId = Id('d8fd9b48e090430db52c6b33d897d0f3');
|
|
397
|
+
const entity = createEntity({
|
|
398
|
+
id: providedId,
|
|
399
|
+
relations: {
|
|
400
|
+
[relationTypeId]: {
|
|
401
|
+
toEntity: toEntityId,
|
|
402
|
+
},
|
|
310
403
|
},
|
|
311
404
|
});
|
|
312
|
-
|
|
313
|
-
expect(entity.
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
405
|
+
expect(entity).toBeDefined();
|
|
406
|
+
expect(entity.id).toBe(providedId);
|
|
407
|
+
expect(entity.ops).toHaveLength(2);
|
|
408
|
+
// Check createEntity op
|
|
409
|
+
const entityOp = entity.ops[0];
|
|
410
|
+
expect(entityOp.type).toBe('createEntity');
|
|
411
|
+
expect(entityOp.id).toEqual(toGrcId(providedId));
|
|
412
|
+
// Check createRelation op
|
|
413
|
+
const relationOp = entity.ops[1];
|
|
414
|
+
expect(relationOp.type).toBe('createRelation');
|
|
415
|
+
expect(relationOp.from).toEqual(toGrcId(entity.id));
|
|
416
|
+
expect(relationOp.relationType).toEqual(toGrcId(relationTypeId));
|
|
417
|
+
expect(relationOp.to).toEqual(toGrcId(toEntityId));
|
|
418
|
+
});
|
|
419
|
+
it('creates an entity with multiple relations of the same type', () => {
|
|
420
|
+
const providedId = Id('b1dc6e5c63e143bab3d4755b251a4ea1');
|
|
421
|
+
const relationTypeId = Id('295c8bc61ae342cbb2a65b61080906ff');
|
|
422
|
+
const toEntityId1 = Id('d8fd9b48e090430db52c6b33d897d0f3');
|
|
423
|
+
const toEntityId2 = Id('e8fd9b48e090430db52c6b33d897d0f4');
|
|
424
|
+
const entity = createEntity({
|
|
425
|
+
id: providedId,
|
|
426
|
+
relations: {
|
|
427
|
+
[relationTypeId]: [{ toEntity: toEntityId1 }, { toEntity: toEntityId2 }],
|
|
319
428
|
},
|
|
320
429
|
});
|
|
430
|
+
expect(entity).toBeDefined();
|
|
431
|
+
expect(entity.id).toBe(providedId);
|
|
432
|
+
expect(entity.ops).toHaveLength(3); // 1 createEntity + 2 createRelation
|
|
433
|
+
// Check first relation
|
|
434
|
+
const rel1 = entity.ops[1];
|
|
435
|
+
expect(rel1.type).toBe('createRelation');
|
|
436
|
+
expect(rel1.from).toEqual(toGrcId(entity.id));
|
|
437
|
+
expect(rel1.to).toEqual(toGrcId(toEntityId1));
|
|
438
|
+
expect(rel1.relationType).toEqual(toGrcId(relationTypeId));
|
|
439
|
+
// Check second relation
|
|
440
|
+
const rel2 = entity.ops[2];
|
|
441
|
+
expect(rel2.type).toBe('createRelation');
|
|
442
|
+
expect(rel2.from).toEqual(toGrcId(entity.id));
|
|
443
|
+
expect(rel2.to).toEqual(toGrcId(toEntityId2));
|
|
444
|
+
expect(rel2.relationType).toEqual(toGrcId(relationTypeId));
|
|
321
445
|
});
|
|
322
446
|
it('throws an error if the provided id is invalid', () => {
|
|
323
447
|
expect(() => createEntity({ id: 'invalid' })).toThrow('Invalid id: "invalid" for `id` in `createEntity`');
|
|
324
448
|
});
|
|
449
|
+
it('throws an error if the cover id is invalid', () => {
|
|
450
|
+
expect(() => createEntity({ cover: 'invalid-cover' })).toThrow('Invalid id: "invalid-cover" for `cover` in `createEntity`');
|
|
451
|
+
});
|
|
452
|
+
it('throws an error if a type id is invalid', () => {
|
|
453
|
+
expect(() => createEntity({ types: ['invalid-type'] })).toThrow('Invalid id: "invalid-type" for `types` in `createEntity`');
|
|
454
|
+
});
|
|
455
|
+
it('throws an error if a property id in values is invalid', () => {
|
|
456
|
+
expect(() => createEntity({ values: [{ property: 'invalid-prop', type: 'text', value: 'test' }] })).toThrow('Invalid id: "invalid-prop" for `values` in `createEntity`');
|
|
457
|
+
});
|
|
325
458
|
});
|
|
326
459
|
//# sourceMappingURL=create-entity.test.js.map
|