@graphprotocol/grc-20 0.25.1 → 0.25.3
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/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/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/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/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/graph/create-space.d.ts +2 -1
- package/dist/src/graph/create-space.d.ts.map +1 -1
- package/dist/src/graph/create-space.js +6 -2
- package/dist/src/graph/create-space.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/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/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.map +1 -1
- 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.map +1 -1
- package/dist/src/ipfs.js +4 -2
- package/dist/src/ipfs.js.map +1 -1
- package/dist/src/ipfs.test.js +1 -1
- 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/edit.d.ts +2 -2
- package/dist/src/proto/edit.d.ts.map +1 -1
- package/dist/src/proto/edit.js +27 -25
- package/dist/src/proto/edit.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/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/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/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 +10 -10
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { expect, it } from 'vitest';
|
|
2
|
+
import { RELATION_INDEX } from './ids/system.js';
|
|
3
|
+
import { Position, PositionRange } from './position.js';
|
|
4
|
+
import { make, remove, reorder } from './relation.js';
|
|
5
|
+
it('should generate CreateRelationOp for CREATE_RELATION', () => {
|
|
6
|
+
const op = make({
|
|
7
|
+
relationId: 'test-relation-id',
|
|
8
|
+
fromId: 'test-entity-id',
|
|
9
|
+
relationTypeId: 'test-relation-type-id',
|
|
10
|
+
toId: 'test-entity-id',
|
|
11
|
+
position: 'test-position',
|
|
12
|
+
});
|
|
13
|
+
expect(op).toEqual({
|
|
14
|
+
type: 'CREATE_RELATION',
|
|
15
|
+
relation: {
|
|
16
|
+
id: 'test-relation-id',
|
|
17
|
+
type: 'test-relation-type-id',
|
|
18
|
+
fromEntity: 'test-entity-id',
|
|
19
|
+
toEntity: 'test-entity-id',
|
|
20
|
+
index: 'test-position',
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
it('should generate DeleteRelationOp for DELETE_RELATION', () => {
|
|
25
|
+
const op = remove('test-relation-id');
|
|
26
|
+
expect(op).toEqual({
|
|
27
|
+
type: 'DELETE_RELATION',
|
|
28
|
+
relation: {
|
|
29
|
+
id: 'test-relation-id',
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
it('should generate Op that places the fractional indexer between the two provided values', () => {
|
|
34
|
+
const op = reorder({
|
|
35
|
+
relationId: 'test-relation-id',
|
|
36
|
+
beforeIndex: PositionRange.FIRST,
|
|
37
|
+
afterIndex: PositionRange.LAST,
|
|
38
|
+
});
|
|
39
|
+
expect(op.type).toBe('SET_TRIPLE');
|
|
40
|
+
expect(op.triple.attribute).toBe(RELATION_INDEX);
|
|
41
|
+
expect(op.triple.entity).toBe('test-relation-id');
|
|
42
|
+
expect(op.triple.value.type).toBe('TEXT');
|
|
43
|
+
// @TODO how do we test that the resulting value is in-between the two indexes?
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=relation.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relation.test.js","sourceRoot":"","sources":["../../../src/core/relation.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAEtD,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;IAC9D,MAAM,EAAE,GAAG,IAAI,CAAC;QACd,UAAU,EAAE,kBAAkB;QAC9B,MAAM,EAAE,gBAAgB;QACxB,cAAc,EAAE,uBAAuB;QACvC,IAAI,EAAE,gBAAgB;QACtB,QAAQ,EAAE,eAAe;KAC1B,CAAC,CAAC;IAEH,MAAM,CAAC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4
|
+
* @since 0.0.6
|
|
5
|
+
*/
|
|
6
|
+
import type { DeleteTripleOp, SetTripleOp, Value } from '../types.js';
|
|
7
|
+
type CreateTripleParams = {
|
|
8
|
+
attributeId: string;
|
|
9
|
+
entityId: string;
|
|
10
|
+
value: Value;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Generates op for creating a new Triple.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* const op = Triple.make({
|
|
18
|
+
* attributeId: 'attribute-id',
|
|
19
|
+
* entityId: 'entity-id',
|
|
20
|
+
* value: {
|
|
21
|
+
* type: 'TEXT',
|
|
22
|
+
* value: 'value',
|
|
23
|
+
* },
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
* @param args – {@link CreateTripleParams}
|
|
27
|
+
* @returns – {@link SetTripleOp}
|
|
28
|
+
*/
|
|
29
|
+
export declare function make(args: CreateTripleParams): SetTripleOp;
|
|
30
|
+
type DeleteTripleParams = {
|
|
31
|
+
attributeId: string;
|
|
32
|
+
entityId: string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Generates op for deleting a Triple.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* const op = Triple.remove({
|
|
40
|
+
* attributeId: 'attribute-id',
|
|
41
|
+
* entityId: 'entity-id',
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @param args – {@link DeleteTripleParams}
|
|
46
|
+
* @returns – {@link DeleteTripleOp}
|
|
47
|
+
*/
|
|
48
|
+
export declare function remove(args: DeleteTripleParams): DeleteTripleOp;
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=triple.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"triple.d.ts","sourceRoot":"","sources":["../../../src/core/triple.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEtE,KAAK,kBAAkB,GAAG;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,IAAI,CAAC,IAAI,EAAE,kBAAkB,GAAG,WAAW,CAS1D;AAED,KAAK,kBAAkB,GAAG;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,kBAAkB,GAAG,cAAc,CAQ/D"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module provides utility functions for working with Triples in TypeScript.
|
|
3
|
+
*
|
|
4
|
+
* @since 0.0.6
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Generates op for creating a new Triple.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* const op = Triple.make({
|
|
12
|
+
* attributeId: 'attribute-id',
|
|
13
|
+
* entityId: 'entity-id',
|
|
14
|
+
* value: {
|
|
15
|
+
* type: 'TEXT',
|
|
16
|
+
* value: 'value',
|
|
17
|
+
* },
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
* @param args – {@link CreateTripleParams}
|
|
21
|
+
* @returns – {@link SetTripleOp}
|
|
22
|
+
*/
|
|
23
|
+
export function make(args) {
|
|
24
|
+
return {
|
|
25
|
+
type: 'SET_TRIPLE',
|
|
26
|
+
triple: {
|
|
27
|
+
attribute: args.attributeId,
|
|
28
|
+
entity: args.entityId,
|
|
29
|
+
value: args.value,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Generates op for deleting a Triple.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* const op = Triple.remove({
|
|
39
|
+
* attributeId: 'attribute-id',
|
|
40
|
+
* entityId: 'entity-id',
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @param args – {@link DeleteTripleParams}
|
|
45
|
+
* @returns – {@link DeleteTripleOp}
|
|
46
|
+
*/
|
|
47
|
+
export function remove(args) {
|
|
48
|
+
return {
|
|
49
|
+
type: 'DELETE_TRIPLE',
|
|
50
|
+
triple: {
|
|
51
|
+
attribute: args.attributeId,
|
|
52
|
+
entity: args.entityId,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=triple.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"triple.js","sourceRoot":"","sources":["../../../src/core/triple.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,IAAI,CAAC,IAAwB;IAC3C,OAAO;QACL,IAAI,EAAE,YAAY;QAClB,MAAM,EAAE;YACN,SAAS,EAAE,IAAI,CAAC,WAAW;YAC3B,MAAM,EAAE,IAAI,CAAC,QAAQ;YACrB,KAAK,EAAE,IAAI,CAAC,KAAK;SAClB;KACF,CAAC;AACJ,CAAC;AAOD;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,MAAM,CAAC,IAAwB;IAC7C,OAAO;QACL,IAAI,EAAE,eAAe;QACrB,MAAM,EAAE;YACN,SAAS,EAAE,IAAI,CAAC,WAAW;YAC3B,MAAM,EAAE,IAAI,CAAC,QAAQ;SACtB;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"triple.test.d.ts","sourceRoot":"","sources":["../../../src/core/triple.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { expect, it } from 'vitest';
|
|
2
|
+
import { make, remove } from './triple.js';
|
|
3
|
+
it('should generate SetTripleOp for SET_TRIPLE', () => {
|
|
4
|
+
const op = make({
|
|
5
|
+
attributeId: 'test-attribute-id',
|
|
6
|
+
entityId: 'test-entity-id',
|
|
7
|
+
value: {
|
|
8
|
+
type: 'TEXT',
|
|
9
|
+
value: 'test value',
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
expect(op).toEqual({
|
|
13
|
+
type: 'SET_TRIPLE',
|
|
14
|
+
triple: {
|
|
15
|
+
attribute: 'test-attribute-id',
|
|
16
|
+
entity: 'test-entity-id',
|
|
17
|
+
value: {
|
|
18
|
+
type: 'TEXT',
|
|
19
|
+
value: 'test value',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
it('should generate DeleteTripleOp for DELETE_TRIPLE', () => {
|
|
25
|
+
const op = remove({
|
|
26
|
+
attributeId: 'test-attribute-id',
|
|
27
|
+
entityId: 'test-entity-id',
|
|
28
|
+
});
|
|
29
|
+
expect(op).toEqual({
|
|
30
|
+
type: 'DELETE_TRIPLE',
|
|
31
|
+
triple: {
|
|
32
|
+
attribute: 'test-attribute-id',
|
|
33
|
+
entity: 'test-entity-id',
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
//# sourceMappingURL=triple.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"triple.test.js","sourceRoot":"","sources":["../../../src/core/triple.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE3C,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;IACpD,MAAM,EAAE,GAAG,IAAI,CAAC;QACd,WAAW,EAAE,mBAAmB;QAChC,QAAQ,EAAE,gBAAgB;QAC1B,KAAK,EAAE;YACL,IAAI,EAAE,MAAM;YACZ,KAAK,EAAE,YAAY;SACpB;KACF,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC;QACjB,IAAI,EAAE,YAAY;QAClB,MAAM,EAAE;YACN,SAAS,EAAE,mBAAmB;YAC9B,MAAM,EAAE,gBAAgB;YACxB,KAAK,EAAE;gBACL,IAAI,EAAE,MAAM;gBACZ,KAAK,EAAE,YAAY;aACpB;SACF;KACF,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAEH,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;IAC1D,MAAM,EAAE,GAAG,MAAM,CAAC;QAChB,WAAW,EAAE,mBAAmB;QAChC,QAAQ,EAAE,gBAAgB;KAC3B,CAAC,CAAC;IAEH,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC;QACjB,IAAI,EAAE,eAAe;QACrB,MAAM,EAAE;YACN,SAAS,EAAE,mBAAmB;YAC9B,MAAM,EAAE,gBAAgB;SACzB;KACF,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Id } from '../id.js';
|
|
1
2
|
import type { Op } from '../types.js';
|
|
2
3
|
type CreateSpaceParams = {
|
|
3
4
|
editorAddress: string;
|
|
@@ -29,7 +30,7 @@ type CreateSpaceParams = {
|
|
|
29
30
|
* @returns – {@link Id}
|
|
30
31
|
*/
|
|
31
32
|
export declare const createSpace: (params: CreateSpaceParams) => Promise<{
|
|
32
|
-
id:
|
|
33
|
+
id: Id;
|
|
33
34
|
}>;
|
|
34
35
|
export {};
|
|
35
36
|
//# sourceMappingURL=create-space.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-space.d.ts","sourceRoot":"","sources":["../../../src/graph/create-space.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-space.d.ts","sourceRoot":"","sources":["../../../src/graph/create-space.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAC9B,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAGtC,KAAK,iBAAiB,GAAG;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,SAAS,GAAG,SAAS,CAAC;IAChC,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC;IACX,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;;OAGG;IACH,cAAc,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAC;CACxC,CAAC;AAkBF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,WAAW,GAAU,QAAQ,iBAAiB;;EAqD1D,CAAC"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { IdUtils } from '../../index.js';
|
|
2
|
+
import { Id } from '../id.js';
|
|
1
3
|
import { MAINNET_API_ORIGIN, TESTNET_API_ORIGIN } from './constants.js';
|
|
2
4
|
/**
|
|
3
5
|
* Creates a space with the given name and editor address.
|
|
@@ -19,7 +21,6 @@ import { MAINNET_API_ORIGIN, TESTNET_API_ORIGIN } from './constants.js';
|
|
|
19
21
|
export const createSpace = async (params) => {
|
|
20
22
|
const governanceType = params.governanceType ?? 'PERSONAL';
|
|
21
23
|
const apiHost = params.network === 'TESTNET' ? TESTNET_API_ORIGIN : MAINNET_API_ORIGIN;
|
|
22
|
-
console.log('apiHost', apiHost);
|
|
23
24
|
const formData = new FormData();
|
|
24
25
|
formData.append('name', params.name);
|
|
25
26
|
formData.append('editorAddress', params.editorAddress);
|
|
@@ -57,6 +58,9 @@ export const createSpace = async (params) => {
|
|
|
57
58
|
},
|
|
58
59
|
});
|
|
59
60
|
const jsonResult = await result.json();
|
|
60
|
-
|
|
61
|
+
if (!jsonResult || !jsonResult.spaceId || !IdUtils.isValid(jsonResult.spaceId)) {
|
|
62
|
+
throw new Error(`Failed to create space: ${JSON.stringify(jsonResult)}`);
|
|
63
|
+
}
|
|
64
|
+
return { id: Id(jsonResult.spaceId) };
|
|
61
65
|
};
|
|
62
66
|
//# sourceMappingURL=create-space.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-space.js","sourceRoot":"","sources":["../../../src/graph/create-space.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-space.js","sourceRoot":"","sources":["../../../src/graph/create-space.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAE9B,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAgCxE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAAE,MAAyB,EAAE,EAAE;IAC7D,MAAM,cAAc,GAAG,MAAM,CAAC,cAAc,IAAI,UAAU,CAAC;IAC3D,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,kBAAkB,CAAC;IAEvF,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;IAChC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;IACrC,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;IACvD,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;QACzB,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;IACzD,CAAC;IAED,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;QACf,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC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;AACxC,CAAC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CreateResult, DeleteEntityParams } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Deletes an entity from a space.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const { ops } = await deleteEntity({ id: entityId });
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* @param params – {@link DeleteEntityParams}
|
|
11
|
+
* @returns The operations to delete the entity.
|
|
12
|
+
*/
|
|
13
|
+
export declare const deleteEntity: ({ id }: DeleteEntityParams) => CreateResult;
|
|
14
|
+
//# sourceMappingURL=delete-entity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-entity.d.ts","sourceRoot":"","sources":["../../../src/graph/delete-entity.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAkB,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEpF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,kBAAkB,KAAG,YAQzD,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Id, assertValid } from '../id.js';
|
|
2
|
+
/**
|
|
3
|
+
* Deletes an entity from a space.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const { ops } = await deleteEntity({ id: entityId });
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* @param params – {@link DeleteEntityParams}
|
|
11
|
+
* @returns The operations to delete the entity.
|
|
12
|
+
*/
|
|
13
|
+
export const deleteEntity = ({ id }) => {
|
|
14
|
+
assertValid(id, '`id` in `deleteEntity`');
|
|
15
|
+
const op = {
|
|
16
|
+
type: 'DELETE_ENTITY',
|
|
17
|
+
id: Id(id),
|
|
18
|
+
};
|
|
19
|
+
return { id: Id(id), ops: [op] };
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=delete-entity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-entity.js","sourceRoot":"","sources":["../../../src/graph/delete-entity.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAG3C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAAE,EAAE,EAAsB,EAAgB,EAAE;IACvE,WAAW,CAAC,EAAE,EAAE,wBAAwB,CAAC,CAAC;IAC1C,MAAM,EAAE,GAAmB;QACzB,IAAI,EAAE,eAAe;QACrB,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;KACX,CAAC;IAEF,OAAO,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;AACnC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-entity.test.d.ts","sourceRoot":"","sources":["../../../src/graph/delete-entity.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { Id } from '../id.js';
|
|
3
|
+
import { deleteEntity } from './delete-entity.js';
|
|
4
|
+
describe('deleteEntity', () => {
|
|
5
|
+
it('should create a delete entity operation with valid ID', () => {
|
|
6
|
+
const id = Id('5cade575-7ecd-41ae-8348-1b22ffc2f94e');
|
|
7
|
+
const result = deleteEntity({ id });
|
|
8
|
+
expect(result).toEqual({
|
|
9
|
+
id,
|
|
10
|
+
ops: [
|
|
11
|
+
{
|
|
12
|
+
type: 'DELETE_ENTITY',
|
|
13
|
+
id: id,
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
it('should throw an error when ID validation fails', () => {
|
|
19
|
+
const id = 'invalid-id';
|
|
20
|
+
expect(() => deleteEntity({ id })).toThrow('Invalid id: "invalid-id"');
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=delete-entity.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-entity.test.js","sourceRoot":"","sources":["../../../src/graph/delete-entity.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,uDAAuD,EAAE,GAAG,EAAE;QAC/D,MAAM,EAAE,GAAG,EAAE,CAAC,sCAAsC,CAAC,CAAC;QACtD,MAAM,MAAM,GAAG,YAAY,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;QAEpC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;YACrB,EAAE;YACF,GAAG,EAAE;gBACH;oBACE,IAAI,EAAE,eAAe;oBACrB,EAAE,EAAE,EAAE;iBACP;aACF;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE;QACxD,MAAM,EAAE,GAAG,YAAY,CAAC;QAExB,MAAM,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAC;IACzE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.test.d.ts","sourceRoot":"","sources":["../../../src/graph/graph.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { createEntity } from './create-entity.js';
|
|
3
|
+
import { createProperty } from './create-property.js';
|
|
4
|
+
import { createType } from './create-type.js';
|
|
5
|
+
describe('Graph', () => {
|
|
6
|
+
it('creates types, entities and relations', async () => {
|
|
7
|
+
const ops = [];
|
|
8
|
+
// create age property
|
|
9
|
+
const { id: agePropertyId, ops: createAgePropertyOps } = createProperty({
|
|
10
|
+
type: 'NUMBER',
|
|
11
|
+
name: 'Age',
|
|
12
|
+
});
|
|
13
|
+
ops.push(...createAgePropertyOps);
|
|
14
|
+
// create likes property
|
|
15
|
+
const { id: likesPropertyId, ops: createLikesPropertyOps } = createProperty({
|
|
16
|
+
type: 'RELATION',
|
|
17
|
+
name: 'Likes',
|
|
18
|
+
});
|
|
19
|
+
ops.push(...createLikesPropertyOps);
|
|
20
|
+
// create person type
|
|
21
|
+
const { id: personTypeId, ops: createPersonTypeOps } = createType({
|
|
22
|
+
name: 'Person',
|
|
23
|
+
properties: [agePropertyId],
|
|
24
|
+
});
|
|
25
|
+
ops.push(...createPersonTypeOps);
|
|
26
|
+
// create restaurant entity
|
|
27
|
+
const { id: restaurantId, ops: createRestaurantOps } = createEntity({
|
|
28
|
+
name: 'Restaurant',
|
|
29
|
+
types: [personTypeId],
|
|
30
|
+
});
|
|
31
|
+
ops.push(...createRestaurantOps);
|
|
32
|
+
// create person entity
|
|
33
|
+
const { id: personId, ops: createPersonOps } = createEntity({
|
|
34
|
+
name: 'Jane Doe',
|
|
35
|
+
types: [personTypeId],
|
|
36
|
+
properties: {
|
|
37
|
+
[likesPropertyId]: {
|
|
38
|
+
to: restaurantId,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
ops.push(...createPersonOps);
|
|
43
|
+
expect(ops.length).toBe(16);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=graph.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.test.js","sourceRoot":"","sources":["../../../src/graph/graph.test.ts"],"names":[],"mappings":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AG,CAAC,IAAI,CAAC,GAAG,mBAAmB,CAAC,CAAC;QAEjC,uBAAuB;QACvB,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,eAAe,EAAE,GAAG,YAAY,CAAC;YAC1D,IAAI,EAAE,UAAU;YAChB,KAAK,EAAE,CAAC,YAAY,CAAC;YACrB,UAAU,EAAE;gBACV,CAAC,eAAe,CAAC,EAAE;oBACjB,EAAE,EAAE,YAAY;iBACjB;aACF;SACF,CAAC,CAAC;QACH,GAAG,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,CAAC;QAE7B,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-default-properties.d.ts","sourceRoot":"","sources":["../../../../src/graph/helpers/create-default-properties.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AAE5D,eAAO,MAAM,uBAAuB,GAAI,QAAQ,iBAAiB,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,SA0CvF,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { COVER_PROPERTY, DESCRIPTION_PROPERTY, NAME_PROPERTY } from '../../core/ids/system.js';
|
|
2
|
+
import { assertValid } from '../../id.js';
|
|
3
|
+
import { Relation } from '../../relation.js';
|
|
4
|
+
import { Triple } from '../../triple.js';
|
|
5
|
+
export const createDefaultProperties = (params) => {
|
|
6
|
+
const { entityId, name, description, cover } = params;
|
|
7
|
+
const ops = [];
|
|
8
|
+
if (name) {
|
|
9
|
+
// set property "Name" to the provided name
|
|
10
|
+
const nameTripleOp = Triple.make({
|
|
11
|
+
entityId,
|
|
12
|
+
attributeId: NAME_PROPERTY,
|
|
13
|
+
value: {
|
|
14
|
+
type: 'TEXT',
|
|
15
|
+
value: name,
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
ops.push(nameTripleOp);
|
|
19
|
+
}
|
|
20
|
+
if (description) {
|
|
21
|
+
// set property "Description" to the provided description
|
|
22
|
+
const descriptionTripleOp = Triple.make({
|
|
23
|
+
entityId,
|
|
24
|
+
attributeId: DESCRIPTION_PROPERTY,
|
|
25
|
+
value: {
|
|
26
|
+
type: 'TEXT',
|
|
27
|
+
value: description,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
ops.push(descriptionTripleOp);
|
|
31
|
+
}
|
|
32
|
+
if (cover) {
|
|
33
|
+
// add ID of cover "Image" to property "Cover"
|
|
34
|
+
assertValid(cover);
|
|
35
|
+
const relationOp = Relation.make({
|
|
36
|
+
fromId: entityId,
|
|
37
|
+
relationTypeId: COVER_PROPERTY,
|
|
38
|
+
toId: cover,
|
|
39
|
+
});
|
|
40
|
+
ops.push(relationOp);
|
|
41
|
+
}
|
|
42
|
+
return ops;
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=create-default-properties.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-default-properties.js","sourceRoot":"","sources":["../../../../src/graph/helpers/create-default-properties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC/F,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGzC,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,MAAgD,EAAE,EAAE;IAC1F,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IACtD,MAAM,GAAG,GAAS,EAAE,CAAC;IAErB,IAAI,IAAI,EAAE,CAAC;QACT,2CAA2C;QAC3C,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC;YAC/B,QAAQ;YACR,WAAW,EAAE,aAAa;YAC1B,KAAK,EAAE;gBACL,IAAI,EAAE,MAAM;gBACZ,KAAK,EAAE,IAAI;aACZ;SACF,CAAC,CAAC;QACH,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACzB,CAAC;IAED,IAAI,WAAW,EAAE,CAAC;QAChB,yDAAyD;QACzD,MAAM,mBAAmB,GAAG,MAAM,CAAC,IAAI,CAAC;YACtC,QAAQ;YACR,WAAW,EAAE,oBAAoB;YACjC,KAAK,EAAE;gBACL,IAAI,EAAE,MAAM;gBACZ,KAAK,EAAE,WAAW;aACnB;SACF,CAAC,CAAC;QACH,GAAG,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IAChC,CAAC;IAED,IAAI,KAAK,EAAE,CAAC;QACV,8CAA8C;QAC9C,WAAW,CAAC,KAAK,CAAC,CAAC;QACnB,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC;YAC/B,MAAM,EAAE,QAAQ;YAChB,cAAc,EAAE,cAAc;YAC9B,IAAI,EAAE,KAAK;SACZ,CAAC,CAAC;QACH,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACvB,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Op, PropertiesParam } from '../../types.js';
|
|
2
|
+
type CreatePropertiesParams = {
|
|
3
|
+
entityId: string;
|
|
4
|
+
properties: PropertiesParam;
|
|
5
|
+
};
|
|
6
|
+
export declare const createProperties: (params: CreatePropertiesParams) => Op[];
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=create-properties.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-properties.d.ts","sourceRoot":"","sources":["../../../../src/graph/helpers/create-properties.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,EAAE,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAE1D,KAAK,sBAAsB,GAAG;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,eAAe,CAAC;CAC7B,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,QAAQ,sBAAsB,SAgD9D,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { assertValid, generate } from '../../id.js';
|
|
2
|
+
import { Relation } from '../../relation.js';
|
|
3
|
+
import { Triple } from '../../triple.js';
|
|
4
|
+
export const createProperties = (params) => {
|
|
5
|
+
const { entityId, properties } = params;
|
|
6
|
+
const ops = [];
|
|
7
|
+
for (const [attributeId, property] of Object.entries(properties)) {
|
|
8
|
+
assertValid(attributeId);
|
|
9
|
+
if ('type' in property) {
|
|
10
|
+
const propertyTripleOp = Triple.make({
|
|
11
|
+
entityId,
|
|
12
|
+
attributeId,
|
|
13
|
+
value: property,
|
|
14
|
+
});
|
|
15
|
+
ops.push(propertyTripleOp);
|
|
16
|
+
}
|
|
17
|
+
else if ('to' in property) {
|
|
18
|
+
const relationId = property.relationId ?? generate();
|
|
19
|
+
assertValid(relationId);
|
|
20
|
+
assertValid(property.to);
|
|
21
|
+
const propertyRelationOp = Relation.make({
|
|
22
|
+
relationId,
|
|
23
|
+
fromId: entityId,
|
|
24
|
+
relationTypeId: attributeId,
|
|
25
|
+
toId: property.to,
|
|
26
|
+
position: property.position,
|
|
27
|
+
});
|
|
28
|
+
ops.push(propertyRelationOp);
|
|
29
|
+
if (property.properties) {
|
|
30
|
+
ops.push(...createProperties({ entityId, properties: property.properties }));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else if (Array.isArray(property)) {
|
|
34
|
+
for (const relation of property) {
|
|
35
|
+
const relationId = relation.relationId ?? generate();
|
|
36
|
+
assertValid(relationId);
|
|
37
|
+
assertValid(relation.to);
|
|
38
|
+
const propertyRelationOp = Relation.make({
|
|
39
|
+
relationId,
|
|
40
|
+
fromId: entityId,
|
|
41
|
+
relationTypeId: attributeId,
|
|
42
|
+
toId: relation.to,
|
|
43
|
+
});
|
|
44
|
+
ops.push(propertyRelationOp);
|
|
45
|
+
if (relation.properties) {
|
|
46
|
+
ops.push(...createProperties({ entityId, properties: relation.properties }));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return ops;
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=create-properties.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-properties.js","sourceRoot":"","sources":["../../../../src/graph/helpers/create-properties.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAQzC,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAA8B,EAAE,EAAE;IACjE,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IACxC,MAAM,GAAG,GAAS,EAAE,CAAC;IAErB,KAAK,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QACjE,WAAW,CAAC,WAAW,CAAC,CAAC;QACzB,IAAI,MAAM,IAAI,QAAQ,EAAE,CAAC;YACvB,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC;gBACnC,QAAQ;gBACR,WAAW;gBACX,KAAK,EAAE,QAAQ;aAChB,CAAC,CAAC;YACH,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAC7B,CAAC;aAAM,IAAI,IAAI,IAAI,QAAQ,EAAE,CAAC;YAC5B,MAAM,UAAU,GAAG,QAAQ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,CAAC,CAAC,CAAC;gBAC/E,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,GAAG,CAAC;AACb,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/graphv2/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,gBAAgB,4CAA4C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/graphv2/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gBAAgB,GAAG,yCAAyC,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { CreateResult, EntityParams } from '../typesv2.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates an entity with the given name, description, cover, properties, and types.
|
|
4
|
+
* All IDs passed to this function (cover, types, property IDs, relation IDs, etc.) are validated.
|
|
5
|
+
* If any invalid ID is provided, the function will throw an error.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* const { id, ops } = createEntity({
|
|
10
|
+
* id: entityId, // optional and will be generated if not provided
|
|
11
|
+
* name: 'name of the entity',
|
|
12
|
+
* description: 'description of the entity',
|
|
13
|
+
* cover: imageEntityId,
|
|
14
|
+
* types: [typeEntityId1, typeEntityId2],
|
|
15
|
+
* values: {
|
|
16
|
+
* // value property like text, number, url, time, point, checkbox
|
|
17
|
+
* [propertyId]: {
|
|
18
|
+
* value: 'value of the property',
|
|
19
|
+
* }
|
|
20
|
+
* },
|
|
21
|
+
* relations: {
|
|
22
|
+
* [relationId]: {
|
|
23
|
+
* to: 'id of the entity',
|
|
24
|
+
* id: 'id of the relation', // optional
|
|
25
|
+
* toSpace: 'id of the to space', // optional
|
|
26
|
+
* position: positionString, // optional
|
|
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
|
|
32
|
+
* [propertyId]: {
|
|
33
|
+
* value: 'value of the property',
|
|
34
|
+
* },
|
|
35
|
+
* },
|
|
36
|
+
* entityRelations: {
|
|
37
|
+
* [relationId]: {
|
|
38
|
+
* to: 'id of the entity',
|
|
39
|
+
* id: 'id of the relation', // optional
|
|
40
|
+
* position: positionString, // optional
|
|
41
|
+
* },
|
|
42
|
+
* },
|
|
43
|
+
* },
|
|
44
|
+
* },
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
* @param params – {@link EntityParams}
|
|
48
|
+
* @returns – {@link CreateResult}
|
|
49
|
+
* @throws Will throw an error if any provided ID is invalid
|
|
50
|
+
*/
|
|
51
|
+
export declare const createEntity: ({ id: providedId, name, description, cover, values, relations, types, }: EntityParams) => CreateResult;
|
|
52
|
+
//# sourceMappingURL=create-entity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-entity.d.ts","sourceRoot":"","sources":["../../../src/graphv2/create-entity.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAA6B,MAAM,eAAe,CAAC;AAG3F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,eAAO,MAAM,YAAY,GAAI,yEAQ1B,YAAY,KAAG,YA4FjB,CAAC"}
|