@graphprotocol/grc-20 0.11.5 → 0.12.1
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 +7 -48
- 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/index.d.ts +1 -25
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -25
- package/dist/index.js.map +1 -1
- package/dist/proto.d.ts +0 -4
- package/dist/proto.d.ts.map +1 -1
- package/dist/proto.js +0 -4
- 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/src/blocks.d.ts +0 -7
- package/dist/src/blocks.d.ts.map +1 -1
- package/dist/src/blocks.js +0 -7
- package/dist/src/blocks.js.map +1 -1
- 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 +27 -38
- package/dist/src/core/account.js.map +1 -1
- package/dist/src/core/account.test.js +25 -17
- package/dist/src/core/account.test.js.map +1 -1
- package/dist/src/core/blocks/data.d.ts +2 -2
- package/dist/src/core/blocks/data.d.ts.map +1 -1
- package/dist/src/core/blocks/data.js +25 -24
- package/dist/src/core/blocks/data.js.map +1 -1
- package/dist/src/core/blocks/data.test.js +20 -20
- package/dist/src/core/blocks/data.test.js.map +1 -1
- package/dist/src/core/blocks/text.d.ts.map +1 -1
- package/dist/src/core/blocks/text.js +22 -22
- package/dist/src/core/blocks/text.js.map +1 -1
- package/dist/src/core/blocks/text.test.js +11 -11
- package/dist/src/core/blocks/text.test.js.map +1 -1
- package/dist/src/core/ids/content.d.ts +0 -36
- package/dist/src/core/ids/content.d.ts.map +1 -1
- package/dist/src/core/ids/content.js +54 -198
- package/dist/src/core/ids/content.js.map +1 -1
- package/dist/src/core/ids/network.d.ts.map +1 -1
- package/dist/src/core/ids/network.js +3 -3
- package/dist/src/core/ids/network.js.map +1 -1
- package/dist/src/core/ids/system.d.ts +6 -51
- package/dist/src/core/ids/system.d.ts.map +1 -1
- package/dist/src/core/ids/system.js +142 -310
- package/dist/src/core/ids/system.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/scheme.d.ts +1 -1
- package/dist/src/core/scheme.d.ts.map +1 -1
- package/dist/src/graph/create-entity.d.ts +21 -18
- package/dist/src/graph/create-entity.d.ts.map +1 -1
- package/dist/src/graph/create-entity.js +96 -27
- package/dist/src/graph/create-entity.js.map +1 -1
- package/dist/src/graph/create-entity.test.js +101 -245
- package/dist/src/graph/create-entity.test.js.map +1 -1
- package/dist/src/graph/create-image.d.ts +1 -14
- package/dist/src/graph/create-image.d.ts.map +1 -1
- package/dist/src/graph/create-image.js +34 -7
- package/dist/src/graph/create-image.js.map +1 -1
- package/dist/src/graph/create-image.test.js +38 -47
- package/dist/src/graph/create-image.test.js.map +1 -1
- package/dist/src/graph/create-property.d.ts +1 -9
- package/dist/src/graph/create-property.d.ts.map +1 -1
- package/dist/src/graph/create-property.js +52 -36
- package/dist/src/graph/create-property.js.map +1 -1
- package/dist/src/graph/create-property.test.js +10 -12
- package/dist/src/graph/create-property.test.js.map +1 -1
- package/dist/src/graph/create-relation.d.ts +33 -0
- package/dist/src/graph/create-relation.d.ts.map +1 -0
- package/dist/src/graph/create-relation.js +66 -0
- package/dist/src/graph/create-relation.js.map +1 -0
- package/dist/src/graph/create-relation.test.d.ts +2 -0
- package/dist/src/graph/create-relation.test.d.ts.map +1 -0
- package/dist/src/graph/create-relation.test.js +208 -0
- package/dist/src/graph/create-relation.test.js.map +1 -0
- package/dist/src/graph/create-type.d.ts +3 -8
- package/dist/src/graph/create-type.d.ts.map +1 -1
- package/dist/src/graph/create-type.js +29 -17
- package/dist/src/graph/create-type.js.map +1 -1
- package/dist/src/graph/create-type.test.js +37 -35
- package/dist/src/graph/create-type.test.js.map +1 -1
- package/dist/src/graph/delete-entity.d.ts +4 -10
- package/dist/src/graph/delete-entity.d.ts.map +1 -1
- package/dist/src/graph/delete-entity.js +10 -35
- package/dist/src/graph/delete-entity.js.map +1 -1
- package/dist/src/graph/delete-entity.test.js +17 -35
- package/dist/src/graph/delete-entity.test.js.map +1 -1
- package/dist/src/graph/delete-relation.d.ts +14 -0
- package/dist/src/graph/delete-relation.d.ts.map +1 -0
- package/dist/src/graph/delete-relation.js +21 -0
- package/dist/src/graph/delete-relation.js.map +1 -0
- package/dist/src/graph/delete-relation.test.d.ts +2 -0
- package/dist/src/graph/delete-relation.test.d.ts.map +1 -0
- package/dist/src/graph/delete-relation.test.js +24 -0
- package/dist/src/graph/delete-relation.test.js.map +1 -0
- package/dist/src/graph/index.d.ts +5 -0
- package/dist/src/graph/index.d.ts.map +1 -1
- package/dist/src/graph/index.js +5 -0
- package/dist/src/graph/index.js.map +1 -1
- package/dist/src/graph/unset-entity-values.d.ts +21 -0
- package/dist/src/graph/unset-entity-values.d.ts.map +1 -0
- package/dist/src/graph/unset-entity-values.js +26 -0
- package/dist/src/graph/unset-entity-values.js.map +1 -0
- package/dist/src/graph/unset-entity-values.test.d.ts +2 -0
- package/dist/src/graph/unset-entity-values.test.d.ts.map +1 -0
- package/dist/src/graph/unset-entity-values.test.js +40 -0
- package/dist/src/graph/unset-entity-values.test.js.map +1 -0
- package/dist/src/graph/unset-relation-fields.d.ts +25 -0
- package/dist/src/graph/unset-relation-fields.d.ts.map +1 -0
- package/dist/src/graph/unset-relation-fields.js +34 -0
- package/dist/src/graph/unset-relation-fields.js.map +1 -0
- package/dist/src/graph/unset-relation-fields.test.d.ts +2 -0
- package/dist/src/graph/unset-relation-fields.test.d.ts.map +1 -0
- package/dist/src/graph/unset-relation-fields.test.js +64 -0
- package/dist/src/graph/unset-relation-fields.test.js.map +1 -0
- package/dist/src/graph/update-entity.d.ts +28 -0
- package/dist/src/graph/update-entity.d.ts.map +1 -0
- package/dist/src/graph/update-entity.js +73 -0
- package/dist/src/graph/update-entity.js.map +1 -0
- package/dist/src/graph/update-entity.test.d.ts +2 -0
- package/dist/src/graph/update-entity.test.d.ts.map +1 -0
- package/dist/src/graph/update-entity.test.js +116 -0
- package/dist/src/graph/update-entity.test.js.map +1 -0
- package/dist/src/graph/update-relation.d.ts +21 -0
- package/dist/src/graph/update-relation.d.ts.map +1 -0
- package/dist/src/graph/update-relation.js +37 -0
- package/dist/src/graph/update-relation.js.map +1 -0
- 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.d.ts +9 -2
- package/dist/src/id.d.ts.map +1 -1
- package/dist/src/id.js +55 -22
- package/dist/src/id.js.map +1 -1
- package/dist/src/id.test.js +13 -10
- package/dist/src/id.test.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/ipfs.d.ts +2 -2
- package/dist/src/ipfs.d.ts.map +1 -1
- package/dist/src/ipfs.js +2 -2
- package/dist/src/ipfs.js.map +1 -1
- package/dist/src/ipfs.test.d.ts +2 -0
- package/dist/src/ipfs.test.d.ts.map +1 -0
- package/dist/src/ipfs.test.js +22 -0
- package/dist/src/ipfs.test.js.map +1 -0
- 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/edit.d.ts +4 -2
- package/dist/src/proto/edit.d.ts.map +1 -1
- package/dist/src/proto/edit.js +53 -32
- package/dist/src/proto/edit.js.map +1 -1
- package/dist/src/proto/edit.test.js +139 -152
- package/dist/src/proto/edit.test.js.map +1 -1
- 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/ipfs_pb.d.ts +249 -369
- package/dist/src/proto/gen/src/proto/ipfs_pb.d.ts.map +1 -1
- package/dist/src/proto/gen/src/proto/ipfs_pb.js +244 -484
- package/dist/src/proto/gen/src/proto/ipfs_pb.js.map +1 -1
- 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/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/system-ids.d.ts +0 -2
- package/dist/src/system-ids.d.ts.map +1 -1
- package/dist/src/system-ids.js +0 -2
- package/dist/src/system-ids.js.map +1 -1
- 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 +126 -103
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +0 -5
- 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/package.json +1 -1
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import type { CreateResult,
|
|
2
|
-
type CreateEntityParams = DefaultProperties & {
|
|
3
|
-
properties?: PropertiesParam;
|
|
4
|
-
types?: Array<string>;
|
|
5
|
-
};
|
|
1
|
+
import type { CreateResult, EntityParams } from '../types.js';
|
|
6
2
|
/**
|
|
7
3
|
* Creates an entity with the given name, description, cover, properties, and types.
|
|
8
4
|
* All IDs passed to this function (cover, types, property IDs, relation IDs, etc.) are validated.
|
|
@@ -11,39 +7,46 @@ type CreateEntityParams = DefaultProperties & {
|
|
|
11
7
|
* @example
|
|
12
8
|
* ```ts
|
|
13
9
|
* const { id, ops } = createEntity({
|
|
10
|
+
* id: entityId, // optional and will be generated if not provided
|
|
14
11
|
* name: 'name of the entity',
|
|
15
12
|
* description: 'description of the entity',
|
|
16
13
|
* cover: imageEntityId,
|
|
17
14
|
* types: [typeEntityId1, typeEntityId2],
|
|
18
|
-
*
|
|
19
|
-
* properties: {
|
|
15
|
+
* values: {
|
|
20
16
|
* // value property like text, number, url, time, point, checkbox
|
|
21
17
|
* [propertyId]: {
|
|
22
|
-
* type: 'TEXT', // TEXT | NUMBER | URL | TIME | POINT | CHECKBOX,
|
|
23
18
|
* value: 'value of the property',
|
|
24
|
-
* }
|
|
25
|
-
*
|
|
26
|
-
*
|
|
19
|
+
* }
|
|
20
|
+
* },
|
|
21
|
+
* relations: {
|
|
22
|
+
* [relationId]: {
|
|
27
23
|
* to: 'id of the entity',
|
|
28
|
-
*
|
|
24
|
+
* id: 'id of the relation', // optional
|
|
25
|
+
* toSpace: 'id of the to space', // optional
|
|
29
26
|
* position: positionString, // optional
|
|
30
|
-
*
|
|
27
|
+
* entityId: 'id of the relation entity', // optional and will be generated if not provided
|
|
28
|
+
* entityName: 'name of the relation entity', // optional
|
|
29
|
+
* entityDescription: 'description of the relation entity', // optional
|
|
30
|
+
* entityCover: 'id of the cover', // optional
|
|
31
|
+
* entityValues: { // optional values for the relation entity
|
|
31
32
|
* [propertyId]: {
|
|
32
|
-
* type: 'TEXT', // TEXT | NUMBER | URL | TIME | POINT | CHECKBOX,
|
|
33
33
|
* value: 'value of the property',
|
|
34
34
|
* },
|
|
35
|
-
*
|
|
35
|
+
* },
|
|
36
|
+
* entityRelations: {
|
|
37
|
+
* [relationId]: {
|
|
36
38
|
* to: 'id of the entity',
|
|
39
|
+
* id: 'id of the relation', // optional
|
|
40
|
+
* position: positionString, // optional
|
|
37
41
|
* },
|
|
38
42
|
* },
|
|
39
43
|
* },
|
|
40
44
|
* },
|
|
41
45
|
* });
|
|
42
46
|
* ```
|
|
43
|
-
* @param params – {@link
|
|
47
|
+
* @param params – {@link EntityParams}
|
|
44
48
|
* @returns – {@link CreateResult}
|
|
45
49
|
* @throws Will throw an error if any provided ID is invalid
|
|
46
50
|
*/
|
|
47
|
-
export declare const createEntity: ({ id: providedId, name, description, cover,
|
|
48
|
-
export {};
|
|
51
|
+
export declare const createEntity: ({ id: providedId, name, description, cover, values, relations, types, }: EntityParams) => CreateResult;
|
|
49
52
|
//# sourceMappingURL=create-entity.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-entity.d.ts","sourceRoot":"","sources":["../../../src/graph/create-entity.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-entity.d.ts","sourceRoot":"","sources":["../../../src/graph/create-entity.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAA6B,MAAM,aAAa,CAAC;AAGzF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,eAAO,MAAM,YAAY,GAAI,yEAQ1B,YAAY,KAAG,YA4FjB,CAAC"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import { TYPES_PROPERTY } from '../core/ids/system.js';
|
|
2
|
-
import { assertValid, generate } from '../id.js';
|
|
3
|
-
import {
|
|
4
|
-
import { createDefaultProperties } from './helpers/create-default-properties.js';
|
|
5
|
-
import { createProperties } from './helpers/create-properties.js';
|
|
1
|
+
import { COVER_PROPERTY, DESCRIPTION_PROPERTY, NAME_PROPERTY, TYPES_PROPERTY } from '../core/ids/system.js';
|
|
2
|
+
import { Id, assertValid, generate, toBase64 } from '../id.js';
|
|
3
|
+
import { createRelation } from './create-relation.js';
|
|
6
4
|
/**
|
|
7
5
|
* Creates an entity with the given name, description, cover, properties, and types.
|
|
8
6
|
* All IDs passed to this function (cover, types, property IDs, relation IDs, etc.) are validated.
|
|
@@ -11,60 +9,131 @@ import { createProperties } from './helpers/create-properties.js';
|
|
|
11
9
|
* @example
|
|
12
10
|
* ```ts
|
|
13
11
|
* const { id, ops } = createEntity({
|
|
12
|
+
* id: entityId, // optional and will be generated if not provided
|
|
14
13
|
* name: 'name of the entity',
|
|
15
14
|
* description: 'description of the entity',
|
|
16
15
|
* cover: imageEntityId,
|
|
17
16
|
* types: [typeEntityId1, typeEntityId2],
|
|
18
|
-
*
|
|
19
|
-
* properties: {
|
|
17
|
+
* values: {
|
|
20
18
|
* // value property like text, number, url, time, point, checkbox
|
|
21
19
|
* [propertyId]: {
|
|
22
|
-
* type: 'TEXT', // TEXT | NUMBER | URL | TIME | POINT | CHECKBOX,
|
|
23
20
|
* value: 'value of the property',
|
|
24
|
-
* }
|
|
25
|
-
*
|
|
26
|
-
*
|
|
21
|
+
* }
|
|
22
|
+
* },
|
|
23
|
+
* relations: {
|
|
24
|
+
* [relationId]: {
|
|
27
25
|
* to: 'id of the entity',
|
|
28
|
-
*
|
|
26
|
+
* id: 'id of the relation', // optional
|
|
27
|
+
* toSpace: 'id of the to space', // optional
|
|
29
28
|
* position: positionString, // optional
|
|
30
|
-
*
|
|
29
|
+
* entityId: 'id of the relation entity', // optional and will be generated if not provided
|
|
30
|
+
* entityName: 'name of the relation entity', // optional
|
|
31
|
+
* entityDescription: 'description of the relation entity', // optional
|
|
32
|
+
* entityCover: 'id of the cover', // optional
|
|
33
|
+
* entityValues: { // optional values for the relation entity
|
|
31
34
|
* [propertyId]: {
|
|
32
|
-
* type: 'TEXT', // TEXT | NUMBER | URL | TIME | POINT | CHECKBOX,
|
|
33
35
|
* value: 'value of the property',
|
|
34
36
|
* },
|
|
35
|
-
*
|
|
37
|
+
* },
|
|
38
|
+
* entityRelations: {
|
|
39
|
+
* [relationId]: {
|
|
36
40
|
* to: 'id of the entity',
|
|
41
|
+
* id: 'id of the relation', // optional
|
|
42
|
+
* position: positionString, // optional
|
|
37
43
|
* },
|
|
38
44
|
* },
|
|
39
45
|
* },
|
|
40
46
|
* },
|
|
41
47
|
* });
|
|
42
48
|
* ```
|
|
43
|
-
* @param params – {@link
|
|
49
|
+
* @param params – {@link EntityParams}
|
|
44
50
|
* @returns – {@link CreateResult}
|
|
45
51
|
* @throws Will throw an error if any provided ID is invalid
|
|
46
52
|
*/
|
|
47
|
-
export const createEntity = ({ id: providedId, name, description, cover,
|
|
53
|
+
export const createEntity = ({ id: providedId, name, description, cover, values, relations, types, }) => {
|
|
48
54
|
if (providedId) {
|
|
49
55
|
assertValid(providedId, '`id` in `createEntity`');
|
|
50
56
|
}
|
|
51
57
|
const id = providedId ?? generate();
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
58
|
+
let ops = [];
|
|
59
|
+
const newValues = [];
|
|
60
|
+
if (name) {
|
|
61
|
+
newValues.push({
|
|
62
|
+
propertyId: toBase64(NAME_PROPERTY),
|
|
63
|
+
value: name,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (description) {
|
|
67
|
+
newValues.push({
|
|
68
|
+
propertyId: toBase64(DESCRIPTION_PROPERTY),
|
|
69
|
+
value: description,
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
for (const [key, value] of Object.entries(values ?? {})) {
|
|
73
|
+
newValues.push({
|
|
74
|
+
propertyId: toBase64(Id(key)),
|
|
75
|
+
value: value.value,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const op = {
|
|
79
|
+
type: 'UPDATE_ENTITY',
|
|
80
|
+
entity: {
|
|
81
|
+
id: toBase64(id),
|
|
82
|
+
values: newValues,
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
ops.push(op);
|
|
86
|
+
if (cover) {
|
|
87
|
+
assertValid(cover);
|
|
88
|
+
ops.push({
|
|
89
|
+
type: 'CREATE_RELATION',
|
|
90
|
+
relation: {
|
|
91
|
+
id: toBase64(generate()),
|
|
92
|
+
entity: toBase64(generate()),
|
|
93
|
+
fromEntity: toBase64(id),
|
|
94
|
+
toEntity: toBase64(cover),
|
|
95
|
+
type: toBase64(COVER_PROPERTY),
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
}
|
|
55
99
|
if (types) {
|
|
56
100
|
for (const typeId of types) {
|
|
57
101
|
assertValid(typeId);
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
102
|
+
ops.push({
|
|
103
|
+
type: 'CREATE_RELATION',
|
|
104
|
+
relation: {
|
|
105
|
+
id: toBase64(generate()),
|
|
106
|
+
entity: toBase64(generate()),
|
|
107
|
+
fromEntity: toBase64(id),
|
|
108
|
+
toEntity: toBase64(typeId),
|
|
109
|
+
type: toBase64(TYPES_PROPERTY),
|
|
110
|
+
},
|
|
62
111
|
});
|
|
63
|
-
ops.push(typeRelationOp);
|
|
64
112
|
}
|
|
65
113
|
}
|
|
66
|
-
|
|
67
|
-
|
|
114
|
+
for (const [typeId, value] of Object.entries(relations ?? {})) {
|
|
115
|
+
const relationsEntries = Array.isArray(value) ? value : [value];
|
|
116
|
+
for (const relation of relationsEntries) {
|
|
117
|
+
const relationId = relation.relationId ?? generate();
|
|
118
|
+
assertValid(relationId);
|
|
119
|
+
const relationEntityId = relation.id ?? generate();
|
|
120
|
+
assertValid(relationEntityId);
|
|
121
|
+
const { ops: relationOps } = createRelation({
|
|
122
|
+
fromEntity: id,
|
|
123
|
+
toEntity: relation.toEntity,
|
|
124
|
+
type: Id(typeId),
|
|
125
|
+
position: relation.position,
|
|
126
|
+
toSpace: relation.toSpace,
|
|
127
|
+
entityId: relationEntityId,
|
|
128
|
+
entityName: relation.entityName,
|
|
129
|
+
entityDescription: relation.entityDescription,
|
|
130
|
+
entityCover: relation.entityCover,
|
|
131
|
+
entityValues: relation.entityValues,
|
|
132
|
+
entityRelations: relation.entityRelations,
|
|
133
|
+
entityTypes: relation.entityTypes,
|
|
134
|
+
});
|
|
135
|
+
ops = ops.concat(relationOps);
|
|
136
|
+
}
|
|
68
137
|
}
|
|
69
138
|
return { id, ops };
|
|
70
139
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-entity.js","sourceRoot":"","sources":["../../../src/graph/create-entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"create-entity.js","sourceRoot":"","sources":["../../../src/graph/create-entity.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
import { NAME_PROPERTY, TYPES_PROPERTY } from '../core/ids/system.js';
|
|
4
|
-
import { Id,
|
|
2
|
+
import { CLAIM_TYPE, NEWS_STORY_TYPE } from '../core/ids/content.js';
|
|
3
|
+
import { COVER_PROPERTY, DESCRIPTION_PROPERTY, NAME_PROPERTY, TYPES_PROPERTY } from '../core/ids/system.js';
|
|
4
|
+
import { Id, toBase64 } from '../id.js';
|
|
5
5
|
import { createEntity } from './create-entity.js';
|
|
6
6
|
describe('createEntity', () => {
|
|
7
|
-
const
|
|
8
|
-
const someRoleId = Id('GscJ2GELQjmLoaVrYyR3xm');
|
|
9
|
-
const someRoleId2 = Id('VdTsW1mGiy1XSooJaBBLc4');
|
|
10
|
-
const coverId = Id('6wMJ7P1AHpu8EWFX3roMye');
|
|
7
|
+
const coverId = Id('30145d36-d5a5-4244-be59-3d111d879ba5');
|
|
11
8
|
it('creates a basic entity without properties', async () => {
|
|
12
9
|
const entity = createEntity({});
|
|
13
10
|
expect(entity).toBeDefined();
|
|
14
11
|
expect(typeof entity.id).toBe('string');
|
|
15
12
|
expect(entity.ops).toBeDefined();
|
|
16
|
-
expect(entity.ops).toHaveLength(
|
|
13
|
+
expect(entity.ops).toHaveLength(1); // One UPDATE_ENTITY op
|
|
14
|
+
expect(entity.ops[0]).toMatchObject({
|
|
15
|
+
type: 'UPDATE_ENTITY',
|
|
16
|
+
entity: {
|
|
17
|
+
id: toBase64(entity.id),
|
|
18
|
+
values: [],
|
|
19
|
+
},
|
|
20
|
+
});
|
|
17
21
|
});
|
|
18
22
|
it('creates an entity with types', async () => {
|
|
19
23
|
const entity = createEntity({
|
|
@@ -21,276 +25,128 @@ describe('createEntity', () => {
|
|
|
21
25
|
});
|
|
22
26
|
expect(entity).toBeDefined();
|
|
23
27
|
expect(typeof entity.id).toBe('string');
|
|
24
|
-
expect(entity.ops).toHaveLength(
|
|
25
|
-
// Check
|
|
26
|
-
expect(entity.ops[0]?.type).toBe('CREATE_RELATION');
|
|
27
|
-
if (entity.ops[0]?.type === 'CREATE_RELATION') {
|
|
28
|
-
expect(entity.ops[0]).toMatchObject({
|
|
29
|
-
relation: {
|
|
30
|
-
fromEntity: entity.id,
|
|
31
|
-
id: entity.ops[0].relation?.id,
|
|
32
|
-
index: entity.ops[0].relation?.index,
|
|
33
|
-
toEntity: CLAIM_TYPE,
|
|
34
|
-
type: TYPES_PROPERTY,
|
|
35
|
-
},
|
|
36
|
-
type: 'CREATE_RELATION',
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
// Check second type relation
|
|
40
|
-
expect(entity.ops[1]?.type).toBe('CREATE_RELATION');
|
|
41
|
-
if (entity.ops[1]?.type === 'CREATE_RELATION') {
|
|
42
|
-
expect(entity.ops[1]).toMatchObject({
|
|
43
|
-
relation: {
|
|
44
|
-
fromEntity: entity.id,
|
|
45
|
-
id: entity.ops[1]?.relation?.id,
|
|
46
|
-
index: entity.ops[1]?.relation?.index,
|
|
47
|
-
toEntity: NEWS_STORY_TYPE,
|
|
48
|
-
type: TYPES_PROPERTY,
|
|
49
|
-
},
|
|
50
|
-
type: 'CREATE_RELATION',
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
it('creates an entity with only triple attributes', async () => {
|
|
55
|
-
const entity = createEntity({
|
|
56
|
-
name: 'Test Entity',
|
|
57
|
-
properties: {
|
|
58
|
-
[DISCLAIMER_PROPERTY]: { value: 'Test Entity', type: 'TEXT' },
|
|
59
|
-
[WEB_URL_PROPERTY]: { value: 'https://example.com', type: 'URL' },
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
expect(entity).toBeDefined();
|
|
63
|
-
expect(typeof entity.id).toBe('string');
|
|
64
|
-
expect(entity.ops).toHaveLength(3);
|
|
65
|
-
// Check triples
|
|
66
|
-
expect(entity.ops[0]?.type).toBe('SET_TRIPLE');
|
|
28
|
+
expect(entity.ops).toHaveLength(3); // One UPDATE_ENTITY + two CREATE_RELATION ops
|
|
29
|
+
// Check UPDATE_ENTITY op
|
|
67
30
|
expect(entity.ops[0]).toMatchObject({
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
type: 'TEXT',
|
|
73
|
-
value: 'Test Entity',
|
|
74
|
-
},
|
|
31
|
+
type: 'UPDATE_ENTITY',
|
|
32
|
+
entity: {
|
|
33
|
+
id: toBase64(entity.id),
|
|
34
|
+
values: [],
|
|
75
35
|
},
|
|
76
|
-
type: 'SET_TRIPLE',
|
|
77
36
|
});
|
|
78
|
-
|
|
37
|
+
// Check first type relation
|
|
79
38
|
expect(entity.ops[1]).toMatchObject({
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
39
|
+
type: 'CREATE_RELATION',
|
|
40
|
+
relation: {
|
|
41
|
+
fromEntity: toBase64(entity.id),
|
|
42
|
+
toEntity: toBase64(CLAIM_TYPE),
|
|
43
|
+
type: toBase64(TYPES_PROPERTY),
|
|
84
44
|
},
|
|
85
|
-
type: 'SET_TRIPLE',
|
|
86
45
|
});
|
|
87
|
-
|
|
46
|
+
// Check second type relation
|
|
88
47
|
expect(entity.ops[2]).toMatchObject({
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
48
|
+
type: 'CREATE_RELATION',
|
|
49
|
+
relation: {
|
|
50
|
+
fromEntity: toBase64(entity.id),
|
|
51
|
+
toEntity: toBase64(NEWS_STORY_TYPE),
|
|
52
|
+
type: toBase64(TYPES_PROPERTY),
|
|
93
53
|
},
|
|
94
|
-
type: 'SET_TRIPLE',
|
|
95
54
|
});
|
|
96
55
|
});
|
|
97
|
-
it('creates an entity with
|
|
56
|
+
it('creates an entity with name and description', async () => {
|
|
98
57
|
const entity = createEntity({
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
[ROLES_PROPERTY]: [{ to: someRoleId }, { to: someRoleId2 }],
|
|
102
|
-
},
|
|
58
|
+
name: 'Test Entity',
|
|
59
|
+
description: 'Test Description',
|
|
103
60
|
});
|
|
104
61
|
expect(entity).toBeDefined();
|
|
105
62
|
expect(typeof entity.id).toBe('string');
|
|
106
|
-
expect(entity.ops).toHaveLength(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
expect(entity.ops[1]?.type).toBe('CREATE_RELATION');
|
|
122
|
-
if (entity.ops[1]?.type === 'CREATE_RELATION') {
|
|
123
|
-
expect(entity.ops[1]).toMatchObject({
|
|
124
|
-
relation: {
|
|
125
|
-
fromEntity: entity.id,
|
|
126
|
-
id: entity.ops[1]?.relation?.id,
|
|
127
|
-
index: entity.ops[1]?.relation?.index,
|
|
128
|
-
toEntity: someRoleId,
|
|
129
|
-
type: ROLES_PROPERTY,
|
|
130
|
-
},
|
|
131
|
-
type: 'CREATE_RELATION',
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
expect(entity.ops[2]?.type).toBe('CREATE_RELATION');
|
|
135
|
-
if (entity.ops[2]?.type === 'CREATE_RELATION') {
|
|
136
|
-
expect(entity.ops[2]).toMatchObject({
|
|
137
|
-
relation: {
|
|
138
|
-
fromEntity: entity.id,
|
|
139
|
-
id: entity.ops[2]?.relation?.id,
|
|
140
|
-
index: entity.ops[2]?.relation?.index,
|
|
141
|
-
toEntity: someRoleId2,
|
|
142
|
-
type: ROLES_PROPERTY,
|
|
143
|
-
},
|
|
144
|
-
type: 'CREATE_RELATION',
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
it('creates an entity with custom relation ids', async () => {
|
|
149
|
-
const authorRelationId = generate();
|
|
150
|
-
const firstRoleRelationId = generate();
|
|
151
|
-
const entity = createEntity({
|
|
152
|
-
properties: {
|
|
153
|
-
[AUTHORS_PROPERTY]: { to: someAuthorId, relationId: authorRelationId },
|
|
154
|
-
[ROLES_PROPERTY]: [{ to: someRoleId, relationId: firstRoleRelationId }, { to: someRoleId2 }],
|
|
63
|
+
expect(entity.ops).toHaveLength(1);
|
|
64
|
+
expect(entity.ops[0]).toMatchObject({
|
|
65
|
+
type: 'UPDATE_ENTITY',
|
|
66
|
+
entity: {
|
|
67
|
+
id: toBase64(entity.id),
|
|
68
|
+
values: [
|
|
69
|
+
{
|
|
70
|
+
propertyId: toBase64(NAME_PROPERTY),
|
|
71
|
+
value: 'Test Entity',
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
propertyId: toBase64(DESCRIPTION_PROPERTY),
|
|
75
|
+
value: 'Test Description',
|
|
76
|
+
},
|
|
77
|
+
],
|
|
155
78
|
},
|
|
156
79
|
});
|
|
157
|
-
expect(entity.ops[0]?.type).toBe('CREATE_RELATION');
|
|
158
|
-
if (entity.ops[0]?.type === 'CREATE_RELATION') {
|
|
159
|
-
expect(entity.ops[0]).toMatchObject({
|
|
160
|
-
relation: {
|
|
161
|
-
fromEntity: entity.id,
|
|
162
|
-
id: authorRelationId,
|
|
163
|
-
index: entity.ops[0]?.relation?.index,
|
|
164
|
-
toEntity: someAuthorId,
|
|
165
|
-
type: AUTHORS_PROPERTY,
|
|
166
|
-
},
|
|
167
|
-
type: 'CREATE_RELATION',
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
expect(entity.ops[1]?.type).toBe('CREATE_RELATION');
|
|
171
|
-
if (entity.ops[1]?.type === 'CREATE_RELATION') {
|
|
172
|
-
expect(entity.ops[1]).toMatchObject({
|
|
173
|
-
relation: {
|
|
174
|
-
fromEntity: entity.id,
|
|
175
|
-
id: firstRoleRelationId,
|
|
176
|
-
index: entity.ops[1]?.relation?.index,
|
|
177
|
-
toEntity: someRoleId,
|
|
178
|
-
type: ROLES_PROPERTY,
|
|
179
|
-
},
|
|
180
|
-
type: 'CREATE_RELATION',
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
80
|
});
|
|
184
|
-
it('creates an entity with
|
|
185
|
-
const authorRelationId = generate();
|
|
186
|
-
const roleRelationId = generate();
|
|
187
|
-
const newsStoryRelationId = generate();
|
|
81
|
+
it('creates an entity with cover', async () => {
|
|
188
82
|
const entity = createEntity({
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
},
|
|
83
|
+
cover: coverId,
|
|
84
|
+
});
|
|
85
|
+
expect(entity).toBeDefined();
|
|
86
|
+
expect(typeof entity.id).toBe('string');
|
|
87
|
+
expect(entity.ops).toHaveLength(2);
|
|
88
|
+
// Check UPDATE_ENTITY op
|
|
89
|
+
expect(entity.ops[0]).toMatchObject({
|
|
90
|
+
type: 'UPDATE_ENTITY',
|
|
91
|
+
entity: {
|
|
92
|
+
id: toBase64(entity.id),
|
|
93
|
+
values: [],
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
// Check cover relation
|
|
97
|
+
expect(entity.ops[1]).toMatchObject({
|
|
98
|
+
type: 'CREATE_RELATION',
|
|
99
|
+
relation: {
|
|
100
|
+
fromEntity: toBase64(entity.id),
|
|
101
|
+
toEntity: toBase64(coverId),
|
|
102
|
+
type: toBase64(COVER_PROPERTY),
|
|
210
103
|
},
|
|
211
104
|
});
|
|
212
|
-
expect(entity.ops[0]?.type).toBe('CREATE_RELATION');
|
|
213
|
-
if (entity.ops[0]?.type === 'CREATE_RELATION') {
|
|
214
|
-
expect(entity.ops[0]).toMatchObject({
|
|
215
|
-
relation: {
|
|
216
|
-
fromEntity: entity.id,
|
|
217
|
-
id: authorRelationId,
|
|
218
|
-
index: entity.ops[0]?.relation?.index,
|
|
219
|
-
toEntity: someAuthorId,
|
|
220
|
-
type: AUTHORS_PROPERTY,
|
|
221
|
-
},
|
|
222
|
-
type: 'CREATE_RELATION',
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
expect(entity.ops[1]?.type).toBe('CREATE_RELATION');
|
|
226
|
-
if (entity.ops[1]?.type === 'CREATE_RELATION') {
|
|
227
|
-
expect(entity.ops[1]).toMatchObject({
|
|
228
|
-
relation: {
|
|
229
|
-
fromEntity: entity.id,
|
|
230
|
-
id: roleRelationId,
|
|
231
|
-
index: entity.ops[1]?.relation?.index,
|
|
232
|
-
toEntity: someRoleId,
|
|
233
|
-
type: ROLES_PROPERTY,
|
|
234
|
-
},
|
|
235
|
-
type: 'CREATE_RELATION',
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
expect(entity.ops[2]?.type).toBe('CREATE_RELATION');
|
|
239
|
-
if (entity.ops[2]?.type === 'CREATE_RELATION') {
|
|
240
|
-
expect(entity.ops[2]).toMatchObject({
|
|
241
|
-
relation: {
|
|
242
|
-
fromEntity: entity.id,
|
|
243
|
-
id: newsStoryRelationId,
|
|
244
|
-
index: entity.ops[2]?.relation?.index,
|
|
245
|
-
toEntity: someRoleId2,
|
|
246
|
-
type: NEWS_STORY_TYPE,
|
|
247
|
-
},
|
|
248
|
-
type: 'CREATE_RELATION',
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
expect(entity.ops[3]?.type).toBe('SET_TRIPLE');
|
|
252
|
-
if (entity.ops[3]?.type === 'SET_TRIPLE') {
|
|
253
|
-
expect(entity.ops[3]).toMatchObject({
|
|
254
|
-
triple: {
|
|
255
|
-
attribute: WEB_URL_PROPERTY,
|
|
256
|
-
entity: entity.id,
|
|
257
|
-
value: { type: 'URL', value: 'https://example.com' },
|
|
258
|
-
},
|
|
259
|
-
type: 'SET_TRIPLE',
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
105
|
});
|
|
263
|
-
it('creates an entity with
|
|
106
|
+
it('creates an entity with custom values', async () => {
|
|
107
|
+
const customPropertyId = Id('fa269fd3-de98-49cf-90c4-4235d905a67c');
|
|
264
108
|
const entity = createEntity({
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
properties: {
|
|
270
|
-
[DISCLAIMER_PROPERTY]: { value: 'Test Entity', type: 'TEXT' },
|
|
271
|
-
[WEB_URL_PROPERTY]: { value: 'https://example.com', type: 'URL' },
|
|
272
|
-
[AUTHORS_PROPERTY]: { to: someAuthorId },
|
|
273
|
-
[ROLES_PROPERTY]: { to: someRoleId },
|
|
109
|
+
values: {
|
|
110
|
+
[customPropertyId]: {
|
|
111
|
+
value: 'custom value',
|
|
112
|
+
},
|
|
274
113
|
},
|
|
275
114
|
});
|
|
276
115
|
expect(entity).toBeDefined();
|
|
277
116
|
expect(typeof entity.id).toBe('string');
|
|
278
|
-
expect(entity.ops).toHaveLength(
|
|
117
|
+
expect(entity.ops).toHaveLength(1);
|
|
118
|
+
expect(entity.ops[0]).toMatchObject({
|
|
119
|
+
type: 'UPDATE_ENTITY',
|
|
120
|
+
entity: {
|
|
121
|
+
id: toBase64(entity.id),
|
|
122
|
+
values: [
|
|
123
|
+
{
|
|
124
|
+
propertyId: toBase64(customPropertyId),
|
|
125
|
+
value: 'custom value',
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
},
|
|
129
|
+
});
|
|
279
130
|
});
|
|
280
131
|
it('creates an entity with a provided id', async () => {
|
|
132
|
+
const providedId = Id('b1dc6e5c-63e1-43ba-b3d4-755b251a4ea1');
|
|
281
133
|
const entity = createEntity({
|
|
282
|
-
id:
|
|
283
|
-
name: '
|
|
134
|
+
id: providedId,
|
|
135
|
+
name: 'Test Entity',
|
|
284
136
|
});
|
|
285
137
|
expect(entity).toBeDefined();
|
|
286
|
-
expect(entity.id).toBe(
|
|
138
|
+
expect(entity.id).toBe(providedId);
|
|
287
139
|
expect(entity.ops).toHaveLength(1);
|
|
288
140
|
expect(entity.ops[0]).toMatchObject({
|
|
289
|
-
type: '
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
141
|
+
type: 'UPDATE_ENTITY',
|
|
142
|
+
entity: {
|
|
143
|
+
id: toBase64(providedId),
|
|
144
|
+
values: [
|
|
145
|
+
{
|
|
146
|
+
propertyId: toBase64(NAME_PROPERTY),
|
|
147
|
+
value: 'Test Entity',
|
|
148
|
+
},
|
|
149
|
+
],
|
|
294
150
|
},
|
|
295
151
|
});
|
|
296
152
|
});
|