@graphprotocol/grc-20 0.28.0 → 0.29.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/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.d.ts +8 -0
- package/dist/examples/ranks/create-ordinal-rank.d.ts.map +1 -0
- package/dist/examples/ranks/create-ordinal-rank.js +42 -0
- package/dist/examples/ranks/create-ordinal-rank.js.map +1 -0
- package/dist/examples/ranks/create-weighted-rank.d.ts +8 -0
- package/dist/examples/ranks/create-weighted-rank.d.ts.map +1 -0
- package/dist/examples/ranks/create-weighted-rank.js +42 -0
- package/dist/examples/ranks/create-weighted-rank.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.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 +15 -0
- package/dist/scripts/setup-rank-types.d.ts.map +1 -0
- package/dist/scripts/setup-rank-types.js +62 -0
- package/dist/scripts/setup-rank-types.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/ids/system.d.ts +6 -0
- package/dist/src/core/ids/system.d.ts.map +1 -1
- package/dist/src/core/ids/system.js +6 -0
- 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/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/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/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/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/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/ranks/create-rank.d.ts +42 -0
- package/dist/src/ranks/create-rank.d.ts.map +1 -0
- package/dist/src/ranks/create-rank.js +139 -0
- package/dist/src/ranks/create-rank.js.map +1 -0
- package/dist/src/ranks/create-rank.test.d.ts +2 -0
- package/dist/src/ranks/create-rank.test.d.ts.map +1 -0
- package/dist/src/ranks/create-rank.test.js +246 -0
- package/dist/src/ranks/create-rank.test.js.map +1 -0
- package/dist/src/ranks/index.d.ts +3 -0
- package/dist/src/ranks/index.d.ts.map +1 -0
- package/dist/src/ranks/index.js +3 -0
- package/dist/src/ranks/index.js.map +1 -0
- package/dist/src/ranks/types.d.ts +30 -0
- package/dist/src/ranks/types.d.ts.map +1 -0
- package/dist/src/ranks/types.js +2 -0
- package/dist/src/ranks/types.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/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { generateNJitteredKeysBetween } from 'fractional-indexing-jittered';
|
|
2
|
+
import { DESCRIPTION_PROPERTY, NAME_PROPERTY, RANK_TYPE, RANK_TYPE_PROPERTY, RANK_VOTES_RELATION_TYPE, TYPES_PROPERTY, VOTE_ORDINAL_VALUE_PROPERTY, VOTE_WEIGHTED_VALUE_PROPERTY, } from '../core/ids/system.js';
|
|
3
|
+
import { serializeNumber } from '../graph/serialize.js';
|
|
4
|
+
import { Id } from '../id.js';
|
|
5
|
+
import { assertValid, generate } from '../id-utils.js';
|
|
6
|
+
/**
|
|
7
|
+
* Creates a rank entity with the given name, description, rankType, and votes.
|
|
8
|
+
* All IDs passed to this function are validated. If any invalid ID is provided,
|
|
9
|
+
* the function will throw an error.
|
|
10
|
+
*
|
|
11
|
+
* For ORDINAL ranks, the position is derived from the array order and fractional
|
|
12
|
+
* indexing strings are generated internally.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* // Create an ordinal rank (ordered list) - position derived from array order
|
|
17
|
+
* const { id, ops, voteIds } = createRank({
|
|
18
|
+
* id: rankId, // optional, will be generated if not provided
|
|
19
|
+
* name: 'My Favorite Movies',
|
|
20
|
+
* description: 'A ranked list of my favorite movies', // optional
|
|
21
|
+
* rankType: 'ORDINAL',
|
|
22
|
+
* votes: [
|
|
23
|
+
* { entityId: movie1Id }, // 1st place
|
|
24
|
+
* { entityId: movie2Id }, // 2nd place
|
|
25
|
+
* { entityId: movie3Id }, // 3rd place
|
|
26
|
+
* ],
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Create a weighted rank (scored list)
|
|
30
|
+
* const { id, ops, voteIds } = createRank({
|
|
31
|
+
* name: 'Restaurant Ratings',
|
|
32
|
+
* rankType: 'WEIGHTED',
|
|
33
|
+
* votes: [
|
|
34
|
+
* { entityId: restaurant1Id, value: 4.5 }, // numeric score
|
|
35
|
+
* { entityId: restaurant2Id, value: 3.8 },
|
|
36
|
+
* ],
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @param params – {@link CreateRankParams}
|
|
41
|
+
* @returns – {@link CreateRankResult}
|
|
42
|
+
* @throws Will throw an error if any provided ID is invalid
|
|
43
|
+
* @throws Will throw an error if any entityId is duplicated in votes
|
|
44
|
+
*/
|
|
45
|
+
export const createRank = ({ id: providedId, name, description, rankType, votes, }) => {
|
|
46
|
+
// Validate all input IDs
|
|
47
|
+
if (providedId) {
|
|
48
|
+
assertValid(providedId, '`id` in `createRank`');
|
|
49
|
+
}
|
|
50
|
+
for (const vote of votes) {
|
|
51
|
+
assertValid(vote.entityId, '`entityId` in `votes` in `createRank`');
|
|
52
|
+
}
|
|
53
|
+
// Validate no duplicate entity IDs in votes
|
|
54
|
+
const seenEntityIds = new Set();
|
|
55
|
+
for (const vote of votes) {
|
|
56
|
+
const entityId = String(vote.entityId);
|
|
57
|
+
if (seenEntityIds.has(entityId)) {
|
|
58
|
+
throw new Error(`Duplicate entityId in votes: "${entityId}". Each entity can only be voted once per rank.`);
|
|
59
|
+
}
|
|
60
|
+
seenEntityIds.add(entityId);
|
|
61
|
+
}
|
|
62
|
+
const id = providedId ?? generate();
|
|
63
|
+
const ops = [];
|
|
64
|
+
const voteIds = [];
|
|
65
|
+
// Create rank entity values
|
|
66
|
+
const rankValues = [
|
|
67
|
+
{
|
|
68
|
+
property: NAME_PROPERTY,
|
|
69
|
+
value: name,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
property: RANK_TYPE_PROPERTY,
|
|
73
|
+
value: rankType,
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
if (description) {
|
|
77
|
+
rankValues.push({
|
|
78
|
+
property: DESCRIPTION_PROPERTY,
|
|
79
|
+
value: description,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
// Create UPDATE_ENTITY op for the rank
|
|
83
|
+
ops.push({
|
|
84
|
+
type: 'UPDATE_ENTITY',
|
|
85
|
+
entity: {
|
|
86
|
+
id: Id(id),
|
|
87
|
+
values: rankValues,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
// Create relation linking rank to RANK_TYPE (type relation)
|
|
91
|
+
ops.push({
|
|
92
|
+
type: 'CREATE_RELATION',
|
|
93
|
+
relation: {
|
|
94
|
+
id: generate(),
|
|
95
|
+
entity: generate(),
|
|
96
|
+
fromEntity: Id(id),
|
|
97
|
+
toEntity: RANK_TYPE,
|
|
98
|
+
type: TYPES_PROPERTY,
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
// Generate fractional indices for ordinal ranks
|
|
102
|
+
const fractionalIndices = rankType === 'ORDINAL' ? generateNJitteredKeysBetween(null, null, votes.length) : [];
|
|
103
|
+
// Create votes
|
|
104
|
+
votes.forEach((vote, i) => {
|
|
105
|
+
const voteEntityId = generate();
|
|
106
|
+
const relationId = generate();
|
|
107
|
+
voteIds.push(voteEntityId);
|
|
108
|
+
// Create relation from rank to voted entity
|
|
109
|
+
ops.push({
|
|
110
|
+
type: 'CREATE_RELATION',
|
|
111
|
+
relation: {
|
|
112
|
+
id: relationId,
|
|
113
|
+
entity: voteEntityId,
|
|
114
|
+
fromEntity: Id(id),
|
|
115
|
+
toEntity: Id(vote.entityId),
|
|
116
|
+
type: RANK_VOTES_RELATION_TYPE,
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
// Create vote entity with the appropriate value property
|
|
120
|
+
const voteValue = rankType === 'ORDINAL'
|
|
121
|
+
? {
|
|
122
|
+
property: VOTE_ORDINAL_VALUE_PROPERTY,
|
|
123
|
+
value: fractionalIndices[i],
|
|
124
|
+
}
|
|
125
|
+
: {
|
|
126
|
+
property: VOTE_WEIGHTED_VALUE_PROPERTY,
|
|
127
|
+
value: serializeNumber(vote.value),
|
|
128
|
+
};
|
|
129
|
+
ops.push({
|
|
130
|
+
type: 'UPDATE_ENTITY',
|
|
131
|
+
entity: {
|
|
132
|
+
id: voteEntityId,
|
|
133
|
+
values: [voteValue],
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
return { id: Id(id), ops, voteIds };
|
|
138
|
+
};
|
|
139
|
+
//# sourceMappingURL=create-rank.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-rank.js","sourceRoot":"","sources":["../../../src/ranks/create-rank.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,SAAS,EACT,kBAAkB,EAClB,wBAAwB,EACxB,cAAc,EACd,2BAA2B,EAC3B,4BAA4B,GAC7B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAIvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,EACzB,EAAE,EAAE,UAAU,EACd,IAAI,EACJ,WAAW,EACX,QAAQ,EACR,KAAK,GACY,EAAoB,EAAE;IACvC,yBAAyB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AE,eAAe;YACrB,MAAM,EAAE;gBACN,EAAE,EAAE,YAAY;gBAChB,MAAM,EAAE,CAAC,SAAS,CAAC;aACpB;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC;AACtC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-rank.test.d.ts","sourceRoot":"","sources":["../../../src/ranks/create-rank.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { DESCRIPTION_PROPERTY, NAME_PROPERTY, RANK_TYPE, RANK_TYPE_PROPERTY, RANK_VOTES_RELATION_TYPE, TYPES_PROPERTY, VOTE_ORDINAL_VALUE_PROPERTY, VOTE_WEIGHTED_VALUE_PROPERTY, } from '../core/ids/system.js';
|
|
3
|
+
import { Id, isValid } from '../id.js';
|
|
4
|
+
import { createRank } from './create-rank.js';
|
|
5
|
+
describe('createRank', () => {
|
|
6
|
+
const movie1Id = Id('f47ac10b-58cc-4372-a567-0e02b2c3d479');
|
|
7
|
+
const movie2Id = Id('550e8400-e29b-41d4-a716-446655440000');
|
|
8
|
+
const movie3Id = Id('6ba7b810-9dad-11d1-80b4-00c04fd430c8');
|
|
9
|
+
describe('ordinal ranks', () => {
|
|
10
|
+
it('creates a basic ordinal rank with one vote', () => {
|
|
11
|
+
const rank = createRank({
|
|
12
|
+
name: 'My Favorite Movie',
|
|
13
|
+
rankType: 'ORDINAL',
|
|
14
|
+
votes: [{ entityId: movie1Id }],
|
|
15
|
+
});
|
|
16
|
+
expect(rank).toBeDefined();
|
|
17
|
+
expect(typeof rank.id).toBe('string');
|
|
18
|
+
expect(rank.ops).toBeDefined();
|
|
19
|
+
expect(rank.voteIds).toHaveLength(1);
|
|
20
|
+
// 1 UPDATE_ENTITY (rank) + 1 CREATE_RELATION (type) + 1 CREATE_RELATION (vote) + 1 UPDATE_ENTITY (vote value)
|
|
21
|
+
expect(rank.ops).toHaveLength(4);
|
|
22
|
+
// Check rank entity creation
|
|
23
|
+
expect(rank.ops[0]).toMatchObject({
|
|
24
|
+
type: 'UPDATE_ENTITY',
|
|
25
|
+
entity: {
|
|
26
|
+
id: rank.id,
|
|
27
|
+
values: expect.arrayContaining([
|
|
28
|
+
{ property: NAME_PROPERTY, value: 'My Favorite Movie' },
|
|
29
|
+
{ property: RANK_TYPE_PROPERTY, value: 'ORDINAL' },
|
|
30
|
+
]),
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
// Check type relation to RANK_TYPE
|
|
34
|
+
expect(rank.ops[1]).toMatchObject({
|
|
35
|
+
type: 'CREATE_RELATION',
|
|
36
|
+
relation: {
|
|
37
|
+
fromEntity: rank.id,
|
|
38
|
+
toEntity: RANK_TYPE,
|
|
39
|
+
type: TYPES_PROPERTY,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
// Check vote relation
|
|
43
|
+
expect(rank.ops[2]).toMatchObject({
|
|
44
|
+
type: 'CREATE_RELATION',
|
|
45
|
+
relation: {
|
|
46
|
+
fromEntity: rank.id,
|
|
47
|
+
toEntity: movie1Id,
|
|
48
|
+
type: RANK_VOTES_RELATION_TYPE,
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
// Check vote entity with ordinal value
|
|
52
|
+
expect(rank.ops[3]).toMatchObject({
|
|
53
|
+
type: 'UPDATE_ENTITY',
|
|
54
|
+
entity: {
|
|
55
|
+
id: rank.voteIds[0],
|
|
56
|
+
values: [
|
|
57
|
+
{
|
|
58
|
+
property: VOTE_ORDINAL_VALUE_PROPERTY,
|
|
59
|
+
value: expect.any(String), // fractional index
|
|
60
|
+
},
|
|
61
|
+
],
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
it('creates an ordinal rank with multiple votes in order', () => {
|
|
66
|
+
const rank = createRank({
|
|
67
|
+
name: 'Top 3 Movies',
|
|
68
|
+
rankType: 'ORDINAL',
|
|
69
|
+
votes: [{ entityId: movie1Id }, { entityId: movie2Id }, { entityId: movie3Id }],
|
|
70
|
+
});
|
|
71
|
+
expect(rank.voteIds).toHaveLength(3);
|
|
72
|
+
// 1 UPDATE_ENTITY + 1 type relation + 3 vote relations + 3 vote entities = 8 ops
|
|
73
|
+
expect(rank.ops).toHaveLength(8);
|
|
74
|
+
// Verify fractional indices are in ascending order
|
|
75
|
+
const ordinalValue1 = rank.ops[3].entity.values[0]?.value;
|
|
76
|
+
const ordinalValue2 = rank.ops[5].entity.values[0]?.value;
|
|
77
|
+
const ordinalValue3 = rank.ops[7].entity.values[0]?.value;
|
|
78
|
+
expect(ordinalValue1 && ordinalValue2 && ordinalValue1 < ordinalValue2).toBe(true);
|
|
79
|
+
expect(ordinalValue2 && ordinalValue3 && ordinalValue2 < ordinalValue3).toBe(true);
|
|
80
|
+
});
|
|
81
|
+
it('creates an ordinal rank with optional description', () => {
|
|
82
|
+
const rank = createRank({
|
|
83
|
+
name: 'My Movies',
|
|
84
|
+
description: 'A ranked list of my favorite movies',
|
|
85
|
+
rankType: 'ORDINAL',
|
|
86
|
+
votes: [{ entityId: movie1Id }],
|
|
87
|
+
});
|
|
88
|
+
expect(rank.ops[0]).toMatchObject({
|
|
89
|
+
type: 'UPDATE_ENTITY',
|
|
90
|
+
entity: {
|
|
91
|
+
id: rank.id,
|
|
92
|
+
values: expect.arrayContaining([
|
|
93
|
+
{ property: NAME_PROPERTY, value: 'My Movies' },
|
|
94
|
+
{ property: RANK_TYPE_PROPERTY, value: 'ORDINAL' },
|
|
95
|
+
{ property: DESCRIPTION_PROPERTY, value: 'A ranked list of my favorite movies' },
|
|
96
|
+
]),
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
describe('weighted ranks', () => {
|
|
102
|
+
it('creates a basic weighted rank with one vote', () => {
|
|
103
|
+
const rank = createRank({
|
|
104
|
+
name: 'Restaurant Rating',
|
|
105
|
+
rankType: 'WEIGHTED',
|
|
106
|
+
votes: [{ entityId: movie1Id, value: 4.5 }],
|
|
107
|
+
});
|
|
108
|
+
expect(rank).toBeDefined();
|
|
109
|
+
expect(rank.voteIds).toHaveLength(1);
|
|
110
|
+
expect(rank.ops).toHaveLength(4);
|
|
111
|
+
// Check rank entity has WEIGHTED type
|
|
112
|
+
expect(rank.ops[0]).toMatchObject({
|
|
113
|
+
type: 'UPDATE_ENTITY',
|
|
114
|
+
entity: {
|
|
115
|
+
values: expect.arrayContaining([{ property: RANK_TYPE_PROPERTY, value: 'WEIGHTED' }]),
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
// Check vote entity with weighted value (serialized as string)
|
|
119
|
+
expect(rank.ops[3]).toMatchObject({
|
|
120
|
+
type: 'UPDATE_ENTITY',
|
|
121
|
+
entity: {
|
|
122
|
+
id: rank.voteIds[0],
|
|
123
|
+
values: [
|
|
124
|
+
{
|
|
125
|
+
property: VOTE_WEIGHTED_VALUE_PROPERTY,
|
|
126
|
+
value: '4.5', // serialized number
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
it('creates a weighted rank with multiple votes', () => {
|
|
133
|
+
const rank = createRank({
|
|
134
|
+
name: 'Movie Scores',
|
|
135
|
+
rankType: 'WEIGHTED',
|
|
136
|
+
votes: [
|
|
137
|
+
{ entityId: movie1Id, value: 9.2 },
|
|
138
|
+
{ entityId: movie2Id, value: 8.5 },
|
|
139
|
+
{ entityId: movie3Id, value: 7.8 },
|
|
140
|
+
],
|
|
141
|
+
});
|
|
142
|
+
expect(rank.voteIds).toHaveLength(3);
|
|
143
|
+
expect(rank.ops).toHaveLength(8);
|
|
144
|
+
// Verify weighted values are correct
|
|
145
|
+
expect(rank.ops[3]).toMatchObject({
|
|
146
|
+
type: 'UPDATE_ENTITY',
|
|
147
|
+
entity: {
|
|
148
|
+
values: [{ property: VOTE_WEIGHTED_VALUE_PROPERTY, value: '9.2' }],
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
expect(rank.ops[5]).toMatchObject({
|
|
152
|
+
type: 'UPDATE_ENTITY',
|
|
153
|
+
entity: {
|
|
154
|
+
values: [{ property: VOTE_WEIGHTED_VALUE_PROPERTY, value: '8.5' }],
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
expect(rank.ops[7]).toMatchObject({
|
|
158
|
+
type: 'UPDATE_ENTITY',
|
|
159
|
+
entity: {
|
|
160
|
+
values: [{ property: VOTE_WEIGHTED_VALUE_PROPERTY, value: '7.8' }],
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
it('handles integer weighted values', () => {
|
|
165
|
+
const rank = createRank({
|
|
166
|
+
name: 'Star Ratings',
|
|
167
|
+
rankType: 'WEIGHTED',
|
|
168
|
+
votes: [{ entityId: movie1Id, value: 5 }],
|
|
169
|
+
});
|
|
170
|
+
expect(rank.ops[3]).toMatchObject({
|
|
171
|
+
type: 'UPDATE_ENTITY',
|
|
172
|
+
entity: {
|
|
173
|
+
values: [{ property: VOTE_WEIGHTED_VALUE_PROPERTY, value: '5' }],
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
describe('provided id', () => {
|
|
179
|
+
it('uses provided id when specified', () => {
|
|
180
|
+
const providedId = Id('b1dc6e5c-63e1-43ba-b3d4-755b251a4ea1');
|
|
181
|
+
const rank = createRank({
|
|
182
|
+
id: providedId,
|
|
183
|
+
name: 'My Rank',
|
|
184
|
+
rankType: 'ORDINAL',
|
|
185
|
+
votes: [{ entityId: movie1Id }],
|
|
186
|
+
});
|
|
187
|
+
expect(rank.id).toBe(providedId);
|
|
188
|
+
});
|
|
189
|
+
it('generates id when not provided', () => {
|
|
190
|
+
const rank = createRank({
|
|
191
|
+
name: 'My Rank',
|
|
192
|
+
rankType: 'ORDINAL',
|
|
193
|
+
votes: [{ entityId: movie1Id }],
|
|
194
|
+
});
|
|
195
|
+
expect(typeof rank.id).toBe('string');
|
|
196
|
+
expect(isValid(rank.id)).toBe(true);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
describe('error handling', () => {
|
|
200
|
+
it('throws an error if the provided id is invalid', () => {
|
|
201
|
+
expect(() => createRank({
|
|
202
|
+
id: 'invalid',
|
|
203
|
+
name: 'My Rank',
|
|
204
|
+
rankType: 'ORDINAL',
|
|
205
|
+
votes: [{ entityId: movie1Id }],
|
|
206
|
+
})).toThrow('Invalid id: "invalid" for `id` in `createRank`');
|
|
207
|
+
});
|
|
208
|
+
it('throws an error if a vote entityId is invalid', () => {
|
|
209
|
+
expect(() => createRank({
|
|
210
|
+
name: 'My Rank',
|
|
211
|
+
rankType: 'ORDINAL',
|
|
212
|
+
votes: [{ entityId: 'invalid-entity-id' }],
|
|
213
|
+
})).toThrow('Invalid id: "invalid-entity-id" for `entityId` in `votes` in `createRank`');
|
|
214
|
+
});
|
|
215
|
+
it('throws an error if duplicate entity IDs are in votes', () => {
|
|
216
|
+
expect(() => createRank({
|
|
217
|
+
name: 'My Rank',
|
|
218
|
+
rankType: 'ORDINAL',
|
|
219
|
+
votes: [{ entityId: movie1Id }, { entityId: movie2Id }, { entityId: movie1Id }],
|
|
220
|
+
})).toThrow(`Duplicate entityId in votes: "${movie1Id}". Each entity can only be voted once per rank.`);
|
|
221
|
+
});
|
|
222
|
+
it('throws an error for duplicate entity IDs in weighted ranks', () => {
|
|
223
|
+
expect(() => createRank({
|
|
224
|
+
name: 'My Scores',
|
|
225
|
+
rankType: 'WEIGHTED',
|
|
226
|
+
votes: [
|
|
227
|
+
{ entityId: movie1Id, value: 5 },
|
|
228
|
+
{ entityId: movie1Id, value: 3 },
|
|
229
|
+
],
|
|
230
|
+
})).toThrow(`Duplicate entityId in votes: "${movie1Id}". Each entity can only be voted once per rank.`);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
describe('empty votes', () => {
|
|
234
|
+
it('creates a rank with no votes', () => {
|
|
235
|
+
const rank = createRank({
|
|
236
|
+
name: 'Empty Rank',
|
|
237
|
+
rankType: 'ORDINAL',
|
|
238
|
+
votes: [],
|
|
239
|
+
});
|
|
240
|
+
expect(rank.voteIds).toHaveLength(0);
|
|
241
|
+
// Only UPDATE_ENTITY (rank) + CREATE_RELATION (type)
|
|
242
|
+
expect(rank.ops).toHaveLength(2);
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
//# sourceMappingURL=create-rank.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-rank.test.js","sourceRoot":"","sources":["../../../src/ranks/create-rank.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,oBAAoB,EACpB,aAAa,EACb,SAAS,EACT,kBAAkB,EAClB,wBAAwB,EACxB,cAAc,EACd,2BAA2B,EAC3B,4BAA4B,GAC7B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,MAAM,QAAQ,GAAG,EAAE,CAAC,sCAAsC,CAAC,CAAC;IAC5D,MAAM,QAAQ,GAAG,EAAE,CAAC,sCAAsC,CAAC,CAAC;IAC5D,MAAM,QAAQ,GAAG,EAAE,CAAC,sCAAsC,CAAC,CAAC;IAE5D,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;QAC7B,EAAE,CAAC,4CAA4C,EAAE,GAAG,EAAE;YACpD,MAAM,IAAI,GAAG,UAAU,CAAC;gBACtB,IAAI,EAAE,mBAAmB;gBACzB,QAAQ,EAA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CAAC,EAAE;iBACjC;aACF,CAAC,CACH,CAAC,OAAO,CAAC,iCAAiC,QAAQ,iDAAiD,CAAC,CAAC;QACxG,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;QAC3B,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;YACtC,MAAM,IAAI,GAAG,UAAU,CAAC;gBACtB,IAAI,EAAE,YAAY;gBAClB,QAAQ,EAAE,SAAS;gBACnB,KAAK,EAAE,EAAE;aACV,CAAC,CAAC;YAEH,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YACrC,qDAAqD;YACrD,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QACnC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ranks/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/ranks/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Id } from '../id.js';
|
|
2
|
+
import type { CreateResult } from '../types.js';
|
|
3
|
+
export type RankType = 'ORDINAL' | 'WEIGHTED';
|
|
4
|
+
/**
|
|
5
|
+
* Vote with ordinal positioning.
|
|
6
|
+
* Position is derived from the array order; fractional indexing is generated internally.
|
|
7
|
+
*/
|
|
8
|
+
export type VoteOrdinal = {
|
|
9
|
+
entityId: Id | string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Vote with weighted numeric scoring.
|
|
13
|
+
* Used for ranked lists where the magnitude of the score matters.
|
|
14
|
+
*/
|
|
15
|
+
export type VoteWeighted = {
|
|
16
|
+
entityId: Id | string;
|
|
17
|
+
value: number;
|
|
18
|
+
};
|
|
19
|
+
export type Vote = VoteOrdinal | VoteWeighted;
|
|
20
|
+
export type CreateRankParams = {
|
|
21
|
+
id?: Id | string;
|
|
22
|
+
name: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
rankType: RankType;
|
|
25
|
+
votes: Vote[];
|
|
26
|
+
};
|
|
27
|
+
export type CreateRankResult = CreateResult & {
|
|
28
|
+
voteIds: Id[];
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/ranks/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,UAAU,CAAC;AAE9C;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,EAAE,EAAE,GAAG,MAAM,CAAC;CACvB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,EAAE,EAAE,GAAG,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,IAAI,GAAG,WAAW,GAAG,YAAY,CAAC;AAE9C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,EAAE,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,QAAQ,CAAC;IACnB,KAAK,EAAE,IAAI,EAAE,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG;IAC5C,OAAO,EAAE,EAAE,EAAE,CAAC;CACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/ranks/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relation.d.ts","sourceRoot":"","sources":["../../src/relation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,QAAQ,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relation.js","sourceRoot":"","sources":["../../src/relation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,QAAQ,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smart-wallet-2.test-invalid.d.ts","sourceRoot":"","sources":["../../src/smart-wallet-2.test-invalid.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { Graph, Ipfs } from '~/index.js';
|
|
3
|
+
import { getSmartAccountWalletClient } from './smart-wallet.js';
|
|
4
|
+
describe('getSmartAccountWalletClient', { timeout: 6000000 }, () => {
|
|
5
|
+
it('should create a client with the default RPC URL when no RPC URL is provided', async () => {
|
|
6
|
+
const address = '0x7fd1BF705f4202C76434A494b88E7E1515D7688A';
|
|
7
|
+
const spaceId = '0f3aa347-efa3-4919-91d1-bb63a382553d';
|
|
8
|
+
const client = await getSmartAccountWalletClient({
|
|
9
|
+
privateKey: '0x9054bbced0e1a05a5dea2ff9446ea30fc98eb1934342bd2232b8753ffc46894d',
|
|
10
|
+
// rpcUrl: 'https://geo.rpc.pinax.network/v1/b970125fc31219b50e40d56c345496157b71ad1d9ee0016b/',
|
|
11
|
+
});
|
|
12
|
+
console.log('Your spaceId is:', spaceId);
|
|
13
|
+
// Once you have a personal space you can write data to it. Generate
|
|
14
|
+
// ops for your data using Triple.make or Relation.make accordingly.
|
|
15
|
+
const testEntity = await Graph.createEntity({
|
|
16
|
+
name: 'Test Entity 4 by Nik',
|
|
17
|
+
});
|
|
18
|
+
console.log('Test Entity Id:', testEntity.id);
|
|
19
|
+
console.log('Test Entity Ops:', testEntity.ops);
|
|
20
|
+
const { cid } = await Ipfs.publishEdit({
|
|
21
|
+
name: 'creating a test entity',
|
|
22
|
+
author: address,
|
|
23
|
+
ops: testEntity.ops,
|
|
24
|
+
});
|
|
25
|
+
console.log('CID:', cid);
|
|
26
|
+
// This returns the correct contract address and calldata depending on the space id
|
|
27
|
+
// Make sure you use the correct space id in the URL below and the correct network.
|
|
28
|
+
const result = await fetch(`https://api-testnet.grc-20.thegraph.com/space/${spaceId}/edit/calldata`, {
|
|
29
|
+
method: 'POST',
|
|
30
|
+
body: JSON.stringify({
|
|
31
|
+
cid: cid,
|
|
32
|
+
// Optionally specify TESTNET or MAINNET. Defaults to MAINNET
|
|
33
|
+
// network: "TESTNET",
|
|
34
|
+
network: 'MAINNET',
|
|
35
|
+
}),
|
|
36
|
+
});
|
|
37
|
+
const { to, data } = await result.json();
|
|
38
|
+
console.log('To:', to);
|
|
39
|
+
console.log('Data:', data);
|
|
40
|
+
const transaction = await client.sendTransaction({
|
|
41
|
+
to: to,
|
|
42
|
+
value: 0n,
|
|
43
|
+
data: data,
|
|
44
|
+
});
|
|
45
|
+
console.log('Transaction hash:', transaction);
|
|
46
|
+
expect(client).toBeDefined();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=smart-wallet-2.test-invalid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smart-wallet-2.test-invalid.js","sourceRoot":"","sources":["../../src/smart-wallet-2.test-invalid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE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6D;gBAC7D,sBAAsB;gBACtB,OAAO,EAAE,SAAS;aACnB,CAAC;SACH,CAAC,CAAC;QAEH,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAEzC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACvB,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAE3B,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC;YAC/C,EAAE,EAAE,EAAE;YACN,KAAK,EAAE,EAAE;YACT,IAAI,EAAE,IAAI;SACX,CAAC,CAAC;QAEH,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,WAAW,CAAC,CAAC;QAE9C,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smart-wallet-2.test.d.ts","sourceRoot":"","sources":["../../src/smart-wallet-2.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { GraphV2, IpfsV2 } from '~/index.js';
|
|
3
|
+
import { getSmartAccountWalletClient } from './smart-wallet.js';
|
|
4
|
+
describe('getSmartAccountWalletClient', { timeout: 6000000 }, () => {
|
|
5
|
+
it('should create a client with the default RPC URL when no RPC URL is provided', async () => {
|
|
6
|
+
const address = '0x7fd1BF705f4202C76434A494b88E7E1515D7688A';
|
|
7
|
+
const spaceId = '0f3aa347-efa3-4919-91d1-bb63a382553d';
|
|
8
|
+
const client = await getSmartAccountWalletClient({
|
|
9
|
+
privateKey: '0x9054bbced0e1a05a5dea2ff9446ea30fc98eb1934342bd2232b8753ffc46894d',
|
|
10
|
+
// rpcUrl: 'https://geo.rpc.pinax.network/v1/b970125fc31219b50e40d56c345496157b71ad1d9ee0016b/',
|
|
11
|
+
});
|
|
12
|
+
console.log('Your spaceId is:', spaceId);
|
|
13
|
+
// Once you have a personal space you can write data to it. Generate
|
|
14
|
+
// ops for your data using Triple.make or Relation.make accordingly.
|
|
15
|
+
const testEntity = await GraphV2.createEntity({
|
|
16
|
+
name: 'Test Entity 4 by Nik',
|
|
17
|
+
});
|
|
18
|
+
console.log('Test Entity Id:', testEntity.id);
|
|
19
|
+
console.log('Test Entity Ops:', testEntity.ops);
|
|
20
|
+
const { cid } = await IpfsV2.publishEdit({
|
|
21
|
+
name: 'creating a test entity',
|
|
22
|
+
author: address,
|
|
23
|
+
ops: testEntity.ops,
|
|
24
|
+
});
|
|
25
|
+
console.log('CID:', cid);
|
|
26
|
+
// This returns the correct contract address and calldata depending on the space id
|
|
27
|
+
// Make sure you use the correct space id in the URL below and the correct network.
|
|
28
|
+
const result = await fetch(`https://api-testnet.grc-20.thegraph.com/space/${spaceId}/edit/calldata`, {
|
|
29
|
+
method: 'POST',
|
|
30
|
+
body: JSON.stringify({
|
|
31
|
+
cid: cid,
|
|
32
|
+
// Optionally specify TESTNET or MAINNET. Defaults to MAINNET
|
|
33
|
+
// network: "TESTNET",
|
|
34
|
+
network: 'MAINNET',
|
|
35
|
+
}),
|
|
36
|
+
});
|
|
37
|
+
const { to, data } = await result.json();
|
|
38
|
+
console.log('To:', to);
|
|
39
|
+
console.log('Data:', data);
|
|
40
|
+
const transaction = await client.sendTransaction({
|
|
41
|
+
to: to,
|
|
42
|
+
value: 0n,
|
|
43
|
+
data: data,
|
|
44
|
+
});
|
|
45
|
+
console.log('Transaction hash:', transaction);
|
|
46
|
+
expect(client).toBeDefined();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=smart-wallet-2.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smart-wallet-2.test.js","sourceRoot":"","sources":["../../src/smart-wallet-2.test.ts"],"names":[],"mappings":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I,CAAC,SAAS,CAAC;gBACnB,GAAG,EAAE,GAAG;gBACR,6DAA6D;gBAC7D,sBAAsB;gBACtB,OAAO,EAAE,SAAS;aACnB,CAAC;SACH,CAAC,CAAC;QAEH,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAEzC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACvB,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAE3B,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC;YAC/C,EAAE,EAAE,EAAE;YACN,KAAK,EAAE,EAAE;YACT,IAAI,EAAE,IAAI;SACX,CAAC,CAAC;QAEH,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,WAAW,CAAC,CAAC;QAE9C,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module provides ids for commonly used entities across the Knowledge Graph.
|
|
3
|
+
*/
|
|
4
|
+
export * as ContentIds from './core/idsv2/content.js';
|
|
5
|
+
export * as NetworkIds from './core/idsv2/network.js';
|
|
6
|
+
export * as SystemIds from './core/idsv2/system.js';
|
|
7
|
+
//# sourceMappingURL=system-ids-v2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"system-ids-v2.d.ts","sourceRoot":"","sources":["../../src/system-ids-v2.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,UAAU,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,UAAU,MAAM,yBAAyB,CAAC;AACtD,OAAO,KAAK,SAAS,MAAM,wBAAwB,CAAC"}
|