@graphprotocol/grc-20 0.11.4 → 0.12.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.
Files changed (322) hide show
  1. package/README.md +7 -48
  2. package/dist/convert-ids.d.ts +2 -0
  3. package/dist/convert-ids.d.ts.map +1 -0
  4. package/dist/convert-ids.js +42 -0
  5. package/dist/convert-ids.js.map +1 -0
  6. package/dist/index.d.ts +1 -25
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +1 -25
  9. package/dist/index.js.map +1 -1
  10. package/dist/proto.d.ts +0 -4
  11. package/dist/proto.d.ts.map +1 -1
  12. package/dist/proto.js +0 -4
  13. package/dist/proto.js.map +1 -1
  14. package/dist/protov2.d.ts +11 -0
  15. package/dist/protov2.d.ts.map +1 -0
  16. package/dist/protov2.js +11 -0
  17. package/dist/protov2.js.map +1 -0
  18. package/dist/src/blocks.d.ts +0 -7
  19. package/dist/src/blocks.d.ts.map +1 -1
  20. package/dist/src/blocks.js +0 -7
  21. package/dist/src/blocks.js.map +1 -1
  22. package/dist/src/core/account.d.ts +2 -2
  23. package/dist/src/core/account.d.ts.map +1 -1
  24. package/dist/src/core/account.js +27 -38
  25. package/dist/src/core/account.js.map +1 -1
  26. package/dist/src/core/account.test.js +25 -17
  27. package/dist/src/core/account.test.js.map +1 -1
  28. package/dist/src/core/blocks/data.d.ts +2 -2
  29. package/dist/src/core/blocks/data.d.ts.map +1 -1
  30. package/dist/src/core/blocks/data.js +25 -24
  31. package/dist/src/core/blocks/data.js.map +1 -1
  32. package/dist/src/core/blocks/data.test.js +20 -20
  33. package/dist/src/core/blocks/data.test.js.map +1 -1
  34. package/dist/src/core/blocks/text.d.ts.map +1 -1
  35. package/dist/src/core/blocks/text.js +22 -22
  36. package/dist/src/core/blocks/text.js.map +1 -1
  37. package/dist/src/core/blocks/text.test.js +11 -11
  38. package/dist/src/core/blocks/text.test.js.map +1 -1
  39. package/dist/src/core/ids/content.d.ts +1 -37
  40. package/dist/src/core/ids/content.d.ts.map +1 -1
  41. package/dist/src/core/ids/content.js +55 -199
  42. package/dist/src/core/ids/content.js.map +1 -1
  43. package/dist/src/core/ids/network.d.ts.map +1 -1
  44. package/dist/src/core/ids/network.js +3 -3
  45. package/dist/src/core/ids/network.js.map +1 -1
  46. package/dist/src/core/ids/system.d.ts +6 -51
  47. package/dist/src/core/ids/system.d.ts.map +1 -1
  48. package/dist/src/core/ids/system.js +142 -310
  49. package/dist/src/core/ids/system.js.map +1 -1
  50. package/dist/src/core/idsv2/content.d.ts +59 -0
  51. package/dist/src/core/idsv2/content.d.ts.map +1 -0
  52. package/dist/src/core/idsv2/content.js +59 -0
  53. package/dist/src/core/idsv2/content.js.map +1 -0
  54. package/dist/src/core/idsv2/network.d.ts +5 -0
  55. package/dist/src/core/idsv2/network.d.ts.map +1 -0
  56. package/dist/src/core/idsv2/network.js +5 -0
  57. package/dist/src/core/idsv2/network.js.map +1 -0
  58. package/dist/src/core/idsv2/system.d.ts +222 -0
  59. package/dist/src/core/idsv2/system.d.ts.map +1 -0
  60. package/dist/src/core/idsv2/system.js +230 -0
  61. package/dist/src/core/idsv2/system.js.map +1 -0
  62. package/dist/src/core/scheme.d.ts +1 -1
  63. package/dist/src/core/scheme.d.ts.map +1 -1
  64. package/dist/src/graph/create-entity.d.ts +21 -18
  65. package/dist/src/graph/create-entity.d.ts.map +1 -1
  66. package/dist/src/graph/create-entity.js +96 -27
  67. package/dist/src/graph/create-entity.js.map +1 -1
  68. package/dist/src/graph/create-entity.test.js +101 -245
  69. package/dist/src/graph/create-entity.test.js.map +1 -1
  70. package/dist/src/graph/create-image.d.ts +1 -14
  71. package/dist/src/graph/create-image.d.ts.map +1 -1
  72. package/dist/src/graph/create-image.js +34 -7
  73. package/dist/src/graph/create-image.js.map +1 -1
  74. package/dist/src/graph/create-image.test.js +38 -47
  75. package/dist/src/graph/create-image.test.js.map +1 -1
  76. package/dist/src/graph/create-property.d.ts +1 -9
  77. package/dist/src/graph/create-property.d.ts.map +1 -1
  78. package/dist/src/graph/create-property.js +52 -36
  79. package/dist/src/graph/create-property.js.map +1 -1
  80. package/dist/src/graph/create-property.test.js +10 -12
  81. package/dist/src/graph/create-property.test.js.map +1 -1
  82. package/dist/src/graph/create-relation.d.ts +33 -0
  83. package/dist/src/graph/create-relation.d.ts.map +1 -0
  84. package/dist/src/graph/create-relation.js +66 -0
  85. package/dist/src/graph/create-relation.js.map +1 -0
  86. package/dist/src/graph/create-relation.test.d.ts +2 -0
  87. package/dist/src/graph/create-relation.test.d.ts.map +1 -0
  88. package/dist/src/graph/create-relation.test.js +208 -0
  89. package/dist/src/graph/create-relation.test.js.map +1 -0
  90. package/dist/src/graph/create-type.d.ts +3 -8
  91. package/dist/src/graph/create-type.d.ts.map +1 -1
  92. package/dist/src/graph/create-type.js +29 -17
  93. package/dist/src/graph/create-type.js.map +1 -1
  94. package/dist/src/graph/create-type.test.js +37 -35
  95. package/dist/src/graph/create-type.test.js.map +1 -1
  96. package/dist/src/graph/delete-entity.d.ts +4 -10
  97. package/dist/src/graph/delete-entity.d.ts.map +1 -1
  98. package/dist/src/graph/delete-entity.js +10 -35
  99. package/dist/src/graph/delete-entity.js.map +1 -1
  100. package/dist/src/graph/delete-entity.test.js +17 -35
  101. package/dist/src/graph/delete-entity.test.js.map +1 -1
  102. package/dist/src/graph/delete-relation.d.ts +14 -0
  103. package/dist/src/graph/delete-relation.d.ts.map +1 -0
  104. package/dist/src/graph/delete-relation.js +21 -0
  105. package/dist/src/graph/delete-relation.js.map +1 -0
  106. package/dist/src/graph/delete-relation.test.d.ts +2 -0
  107. package/dist/src/graph/delete-relation.test.d.ts.map +1 -0
  108. package/dist/src/graph/delete-relation.test.js +24 -0
  109. package/dist/src/graph/delete-relation.test.js.map +1 -0
  110. package/dist/src/graph/index.d.ts +5 -0
  111. package/dist/src/graph/index.d.ts.map +1 -1
  112. package/dist/src/graph/index.js +5 -0
  113. package/dist/src/graph/index.js.map +1 -1
  114. package/dist/src/graph/unset-entity-values.d.ts +21 -0
  115. package/dist/src/graph/unset-entity-values.d.ts.map +1 -0
  116. package/dist/src/graph/unset-entity-values.js +26 -0
  117. package/dist/src/graph/unset-entity-values.js.map +1 -0
  118. package/dist/src/graph/unset-entity-values.test.d.ts +2 -0
  119. package/dist/src/graph/unset-entity-values.test.d.ts.map +1 -0
  120. package/dist/src/graph/unset-entity-values.test.js +40 -0
  121. package/dist/src/graph/unset-entity-values.test.js.map +1 -0
  122. package/dist/src/graph/unset-relation-fields.d.ts +25 -0
  123. package/dist/src/graph/unset-relation-fields.d.ts.map +1 -0
  124. package/dist/src/graph/unset-relation-fields.js +34 -0
  125. package/dist/src/graph/unset-relation-fields.js.map +1 -0
  126. package/dist/src/graph/unset-relation-fields.test.d.ts +2 -0
  127. package/dist/src/graph/unset-relation-fields.test.d.ts.map +1 -0
  128. package/dist/src/graph/unset-relation-fields.test.js +64 -0
  129. package/dist/src/graph/unset-relation-fields.test.js.map +1 -0
  130. package/dist/src/graph/update-entity.d.ts +28 -0
  131. package/dist/src/graph/update-entity.d.ts.map +1 -0
  132. package/dist/src/graph/update-entity.js +73 -0
  133. package/dist/src/graph/update-entity.js.map +1 -0
  134. package/dist/src/graph/update-entity.test.d.ts +2 -0
  135. package/dist/src/graph/update-entity.test.d.ts.map +1 -0
  136. package/dist/src/graph/update-entity.test.js +116 -0
  137. package/dist/src/graph/update-entity.test.js.map +1 -0
  138. package/dist/src/graph/update-relation.d.ts +21 -0
  139. package/dist/src/graph/update-relation.d.ts.map +1 -0
  140. package/dist/src/graph/update-relation.js +37 -0
  141. package/dist/src/graph/update-relation.js.map +1 -0
  142. package/dist/src/graphv2/constants.d.ts +2 -0
  143. package/dist/src/graphv2/constants.d.ts.map +1 -0
  144. package/dist/src/graphv2/constants.js +2 -0
  145. package/dist/src/graphv2/constants.js.map +1 -0
  146. package/dist/src/graphv2/create-entity.d.ts +52 -0
  147. package/dist/src/graphv2/create-entity.d.ts.map +1 -0
  148. package/dist/src/graphv2/create-entity.js +140 -0
  149. package/dist/src/graphv2/create-entity.js.map +1 -0
  150. package/dist/src/graphv2/create-entity.test.d.ts +2 -0
  151. package/dist/src/graphv2/create-entity.test.d.ts.map +1 -0
  152. package/dist/src/graphv2/create-entity.test.js +158 -0
  153. package/dist/src/graphv2/create-entity.test.js.map +1 -0
  154. package/dist/src/graphv2/create-image.d.ts +28 -0
  155. package/dist/src/graphv2/create-image.d.ts.map +1 -0
  156. package/dist/src/graphv2/create-image.js +71 -0
  157. package/dist/src/graphv2/create-image.js.map +1 -0
  158. package/dist/src/graphv2/create-image.test.d.ts +2 -0
  159. package/dist/src/graphv2/create-image.test.d.ts.map +1 -0
  160. package/dist/src/graphv2/create-image.test.js +142 -0
  161. package/dist/src/graphv2/create-image.test.js.map +1 -0
  162. package/dist/src/graphv2/create-property.d.ts +22 -0
  163. package/dist/src/graphv2/create-property.d.ts.map +1 -0
  164. package/dist/src/graphv2/create-property.js +129 -0
  165. package/dist/src/graphv2/create-property.js.map +1 -0
  166. package/dist/src/graphv2/create-property.test.d.ts +2 -0
  167. package/dist/src/graphv2/create-property.test.d.ts.map +1 -0
  168. package/dist/src/graphv2/create-property.test.js +82 -0
  169. package/dist/src/graphv2/create-property.test.js.map +1 -0
  170. package/dist/src/graphv2/create-relation.d.ts +33 -0
  171. package/dist/src/graphv2/create-relation.d.ts.map +1 -0
  172. package/dist/src/graphv2/create-relation.js +66 -0
  173. package/dist/src/graphv2/create-relation.js.map +1 -0
  174. package/dist/src/graphv2/create-relation.test.d.ts +2 -0
  175. package/dist/src/graphv2/create-relation.test.d.ts.map +1 -0
  176. package/dist/src/graphv2/create-relation.test.js +208 -0
  177. package/dist/src/graphv2/create-relation.test.js.map +1 -0
  178. package/dist/src/graphv2/create-space.d.ts +13 -0
  179. package/dist/src/graphv2/create-space.d.ts.map +1 -0
  180. package/dist/src/graphv2/create-space.js +21 -0
  181. package/dist/src/graphv2/create-space.js.map +1 -0
  182. package/dist/src/graphv2/create-type.d.ts +22 -0
  183. package/dist/src/graphv2/create-type.d.ts.map +1 -0
  184. package/dist/src/graphv2/create-type.js +64 -0
  185. package/dist/src/graphv2/create-type.js.map +1 -0
  186. package/dist/src/graphv2/create-type.test.d.ts +2 -0
  187. package/dist/src/graphv2/create-type.test.d.ts.map +1 -0
  188. package/dist/src/graphv2/create-type.test.js +109 -0
  189. package/dist/src/graphv2/create-type.test.js.map +1 -0
  190. package/dist/src/graphv2/delete-entity.d.ts +14 -0
  191. package/dist/src/graphv2/delete-entity.d.ts.map +1 -0
  192. package/dist/src/graphv2/delete-entity.js +21 -0
  193. package/dist/src/graphv2/delete-entity.js.map +1 -0
  194. package/dist/src/graphv2/delete-entity.test.d.ts +2 -0
  195. package/dist/src/graphv2/delete-entity.test.d.ts.map +1 -0
  196. package/dist/src/graphv2/delete-entity.test.js +24 -0
  197. package/dist/src/graphv2/delete-entity.test.js.map +1 -0
  198. package/dist/src/graphv2/delete-relation.d.ts +14 -0
  199. package/dist/src/graphv2/delete-relation.d.ts.map +1 -0
  200. package/dist/src/graphv2/delete-relation.js +21 -0
  201. package/dist/src/graphv2/delete-relation.js.map +1 -0
  202. package/dist/src/graphv2/delete-relation.test.d.ts +2 -0
  203. package/dist/src/graphv2/delete-relation.test.d.ts.map +1 -0
  204. package/dist/src/graphv2/delete-relation.test.js +24 -0
  205. package/dist/src/graphv2/delete-relation.test.js.map +1 -0
  206. package/dist/src/graphv2/index.d.ts +12 -0
  207. package/dist/src/graphv2/index.d.ts.map +1 -0
  208. package/dist/src/graphv2/index.js +12 -0
  209. package/dist/src/graphv2/index.js.map +1 -0
  210. package/dist/src/graphv2/remove-entity-properties.d.ts +25 -0
  211. package/dist/src/graphv2/remove-entity-properties.d.ts.map +1 -0
  212. package/dist/src/graphv2/remove-entity-properties.js +24 -0
  213. package/dist/src/graphv2/remove-entity-properties.js.map +1 -0
  214. package/dist/src/graphv2/unset-entity-values.d.ts +21 -0
  215. package/dist/src/graphv2/unset-entity-values.d.ts.map +1 -0
  216. package/dist/src/graphv2/unset-entity-values.js +26 -0
  217. package/dist/src/graphv2/unset-entity-values.js.map +1 -0
  218. package/dist/src/graphv2/unset-entity-values.test.d.ts +2 -0
  219. package/dist/src/graphv2/unset-entity-values.test.d.ts.map +1 -0
  220. package/dist/src/graphv2/unset-entity-values.test.js +40 -0
  221. package/dist/src/graphv2/unset-entity-values.test.js.map +1 -0
  222. package/dist/src/graphv2/unset-relation-fields.d.ts +25 -0
  223. package/dist/src/graphv2/unset-relation-fields.d.ts.map +1 -0
  224. package/dist/src/graphv2/unset-relation-fields.js +34 -0
  225. package/dist/src/graphv2/unset-relation-fields.js.map +1 -0
  226. package/dist/src/graphv2/unset-relation-fields.test.d.ts +2 -0
  227. package/dist/src/graphv2/unset-relation-fields.test.d.ts.map +1 -0
  228. package/dist/src/graphv2/unset-relation-fields.test.js +64 -0
  229. package/dist/src/graphv2/unset-relation-fields.test.js.map +1 -0
  230. package/dist/src/graphv2/update-entity.d.ts +28 -0
  231. package/dist/src/graphv2/update-entity.d.ts.map +1 -0
  232. package/dist/src/graphv2/update-entity.js +73 -0
  233. package/dist/src/graphv2/update-entity.js.map +1 -0
  234. package/dist/src/graphv2/update-entity.test.d.ts +2 -0
  235. package/dist/src/graphv2/update-entity.test.d.ts.map +1 -0
  236. package/dist/src/graphv2/update-entity.test.js +116 -0
  237. package/dist/src/graphv2/update-entity.test.js.map +1 -0
  238. package/dist/src/graphv2/update-relation.d.ts +21 -0
  239. package/dist/src/graphv2/update-relation.d.ts.map +1 -0
  240. package/dist/src/graphv2/update-relation.js +37 -0
  241. package/dist/src/graphv2/update-relation.js.map +1 -0
  242. package/dist/src/id.d.ts +9 -2
  243. package/dist/src/id.d.ts.map +1 -1
  244. package/dist/src/id.js +55 -22
  245. package/dist/src/id.js.map +1 -1
  246. package/dist/src/id.test.js +13 -10
  247. package/dist/src/id.test.js.map +1 -1
  248. package/dist/src/idv2.d.ts +27 -0
  249. package/dist/src/idv2.d.ts.map +1 -0
  250. package/dist/src/idv2.js +88 -0
  251. package/dist/src/idv2.js.map +1 -0
  252. package/dist/src/idv2.test.d.ts +2 -0
  253. package/dist/src/idv2.test.d.ts.map +1 -0
  254. package/dist/src/idv2.test.js +26 -0
  255. package/dist/src/idv2.test.js.map +1 -0
  256. package/dist/src/ipfs.d.ts +2 -2
  257. package/dist/src/ipfs.d.ts.map +1 -1
  258. package/dist/src/ipfs.js +2 -2
  259. package/dist/src/ipfs.js.map +1 -1
  260. package/dist/src/ipfs.test.d.ts +2 -0
  261. package/dist/src/ipfs.test.d.ts.map +1 -0
  262. package/dist/src/ipfs.test.js +22 -0
  263. package/dist/src/ipfs.test.js.map +1 -0
  264. package/dist/src/ipfsv2.d.ts +96 -0
  265. package/dist/src/ipfsv2.d.ts.map +1 -0
  266. package/dist/src/ipfsv2.js +163 -0
  267. package/dist/src/ipfsv2.js.map +1 -0
  268. package/dist/src/ipfsv2.test.d.ts +2 -0
  269. package/dist/src/ipfsv2.test.d.ts.map +1 -0
  270. package/dist/src/ipfsv2.test.js +22 -0
  271. package/dist/src/ipfsv2.test.js.map +1 -0
  272. package/dist/src/proto/edit.d.ts +4 -2
  273. package/dist/src/proto/edit.d.ts.map +1 -1
  274. package/dist/src/proto/edit.js +53 -32
  275. package/dist/src/proto/edit.js.map +1 -1
  276. package/dist/src/proto/edit.test.js +139 -152
  277. package/dist/src/proto/edit.test.js.map +1 -1
  278. package/dist/src/proto/editv2.d.ts +11 -0
  279. package/dist/src/proto/editv2.d.ts.map +1 -0
  280. package/dist/src/proto/editv2.js +81 -0
  281. package/dist/src/proto/editv2.js.map +1 -0
  282. package/dist/src/proto/editv2.test.d.ts +2 -0
  283. package/dist/src/proto/editv2.test.d.ts.map +1 -0
  284. package/dist/src/proto/editv2.test.js +211 -0
  285. package/dist/src/proto/editv2.test.js.map +1 -0
  286. package/dist/src/proto/gen/src/proto/ipfs_pb.d.ts +249 -369
  287. package/dist/src/proto/gen/src/proto/ipfs_pb.d.ts.map +1 -1
  288. package/dist/src/proto/gen/src/proto/ipfs_pb.js +244 -484
  289. package/dist/src/proto/gen/src/proto/ipfs_pb.js.map +1 -1
  290. package/dist/src/proto/gen/src/proto/ipfsv2_pb.d.ts +410 -0
  291. package/dist/src/proto/gen/src/proto/ipfsv2_pb.d.ts.map +1 -0
  292. package/dist/src/proto/gen/src/proto/ipfsv2_pb.js +536 -0
  293. package/dist/src/proto/gen/src/proto/ipfsv2_pb.js.map +1 -0
  294. package/dist/src/smart-wallet-2.test-invalid.d.ts +2 -0
  295. package/dist/src/smart-wallet-2.test-invalid.d.ts.map +1 -0
  296. package/dist/src/smart-wallet-2.test-invalid.js +49 -0
  297. package/dist/src/smart-wallet-2.test-invalid.js.map +1 -0
  298. package/dist/src/smart-wallet-2.test.d.ts +2 -0
  299. package/dist/src/smart-wallet-2.test.d.ts.map +1 -0
  300. package/dist/src/smart-wallet-2.test.js +49 -0
  301. package/dist/src/smart-wallet-2.test.js.map +1 -0
  302. package/dist/src/system-ids-v2.d.ts +7 -0
  303. package/dist/src/system-ids-v2.d.ts.map +1 -0
  304. package/dist/src/system-ids-v2.js +7 -0
  305. package/dist/src/system-ids-v2.js.map +1 -0
  306. package/dist/src/system-ids.d.ts +0 -2
  307. package/dist/src/system-ids.d.ts.map +1 -1
  308. package/dist/src/system-ids.js +0 -2
  309. package/dist/src/system-ids.js.map +1 -1
  310. package/dist/src/types-backup.d.ts +134 -0
  311. package/dist/src/types-backup.d.ts.map +1 -0
  312. package/dist/src/types-backup.js +13 -0
  313. package/dist/src/types-backup.js.map +1 -0
  314. package/dist/src/types.d.ts +126 -103
  315. package/dist/src/types.d.ts.map +1 -1
  316. package/dist/src/types.js +0 -5
  317. package/dist/src/types.js.map +1 -1
  318. package/dist/src/typesv2.d.ts +173 -0
  319. package/dist/src/typesv2.d.ts.map +1 -0
  320. package/dist/src/typesv2.js +8 -0
  321. package/dist/src/typesv2.js.map +1 -0
  322. package/package.json +1 -1
@@ -1,8 +1,4 @@
1
- import type { CreateResult, DefaultProperties, PropertiesParam } from '../types.js';
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
- * id: entityId, // optional and will be generated if not provided
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
- * // relation property
26
- * [propertyId]: {
19
+ * }
20
+ * },
21
+ * relations: {
22
+ * [relationId]: {
27
23
  * to: 'id of the entity',
28
- * relationId: 'id of the relation', // optional
24
+ * id: 'id of the relation', // optional
25
+ * toSpace: 'id of the to space', // optional
29
26
  * position: positionString, // optional
30
- * properties: { // optional properties for the relation
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
- * [propertyId]: {
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 CreateEntityParams}
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, properties, types }: CreateEntityParams) => CreateResult;
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":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAM,eAAe,EAAE,MAAM,aAAa,CAAC;AAGxF,KAAK,kBAAkB,GAAG,iBAAiB,GAAG;IAC5C,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B,KAAK,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;CACvB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,eAAO,MAAM,YAAY,GAAI,iEAAiE,kBAAkB,KAAG,YA2BlH,CAAC"}
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 { Relation } from '../relation.js';
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
- * id: entityId, // optional and will be generated if not provided
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
- * // relation property
26
- * [propertyId]: {
21
+ * }
22
+ * },
23
+ * relations: {
24
+ * [relationId]: {
27
25
  * to: 'id of the entity',
28
- * relationId: 'id of the relation', // optional
26
+ * id: 'id of the relation', // optional
27
+ * toSpace: 'id of the to space', // optional
29
28
  * position: positionString, // optional
30
- * properties: { // optional properties for the relation
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
- * [propertyId]: {
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 CreateEntityParams}
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, properties, types }) => {
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
- const ops = [];
53
- ops.push(...createDefaultProperties({ entityId: id, name, description, cover }));
54
- // add property "Types" to the provided types
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
- const typeRelationOp = Relation.make({
59
- fromId: id,
60
- relationTypeId: TYPES_PROPERTY,
61
- toId: typeId,
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
- if (properties) {
67
- ops.push(...createProperties({ entityId: id, properties }));
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,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE1C,OAAO,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAMlE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAsB,EAAgB,EAAE;IAChI,IAAI,UAAU,EAAE,CAAC;QACf,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AC,EAAE,IAAI,QAAQ,EAAE,CAAC;YACnD,WAAW,CAAC,gBAAgB,CAAC,CAAC;YAC9B,MAAM,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,cAAc,CAAC;gBAC1C,UAAU,EAAE,EAAE;gBACd,QAAQ,EAAE,QAAQ,CAAC,QAAQ;gBAC3B,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC;gBAChB,QAAQ,EAAE,QAAQ,CAAC,QAAQ;gBAC3B,OAAO,EAAE,QAAQ,CAAC,OAAO;gBACzB,QAAQ,EAAE,gBAAgB;gBAC1B,UAAU,EAAE,QAAQ,CAAC,UAAU;gBAC/B,iBAAiB,EAAE,QAAQ,CAAC,iBAAiB;gBAC7C,WAAW,EAAE,QAAQ,CAAC,WAAW;gBACjC,YAAY,EAAE,QAAQ,CAAC,YAAY;gBACnC,eAAe,EAAE,QAAQ,CAAC,eAAe;gBACzC,WAAW,EAAE,QAAQ,CAAC,WAAW;aAClC,CAAC,CAAC;YACH,GAAG,GAAG,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;QAChC,CAAC;IACH,CAAC;IAED,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC;AACrB,CAAC,CAAC"}
@@ -1,19 +1,23 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { AUTHORS_PROPERTY, CLAIM_TYPE, DISCLAIMER_PROPERTY, NEWS_STORY_TYPE, ROLES_PROPERTY, WEB_URL_PROPERTY, } from '../core/ids/content.js';
3
- import { NAME_PROPERTY, TYPES_PROPERTY } from '../core/ids/system.js';
4
- import { Id, generate } from '../id.js';
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 someAuthorId = Id('M5uDP7nCw3nvfQPUryn9gx');
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(0);
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(2);
25
- // Check first type relation
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
- triple: {
69
- attribute: NAME_PROPERTY,
70
- entity: entity.id,
71
- value: {
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
- expect(entity.ops[1]?.type).toBe('SET_TRIPLE');
37
+ // Check first type relation
79
38
  expect(entity.ops[1]).toMatchObject({
80
- triple: {
81
- attribute: DISCLAIMER_PROPERTY,
82
- entity: entity.id,
83
- value: { type: 'TEXT', value: 'Test Entity' },
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
- expect(entity.ops[2]?.type).toBe('SET_TRIPLE');
46
+ // Check second type relation
88
47
  expect(entity.ops[2]).toMatchObject({
89
- triple: {
90
- attribute: WEB_URL_PROPERTY,
91
- entity: entity.id,
92
- value: { type: 'URL', value: 'https://example.com' },
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 relations', async () => {
56
+ it('creates an entity with name and description', async () => {
98
57
  const entity = createEntity({
99
- properties: {
100
- [AUTHORS_PROPERTY]: { to: someAuthorId },
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(3);
107
- // Check relations
108
- expect(entity.ops[0]?.type).toBe('CREATE_RELATION');
109
- if (entity.ops[0]?.type === 'CREATE_RELATION') {
110
- expect(entity.ops[0]).toMatchObject({
111
- relation: {
112
- fromEntity: entity.id,
113
- id: entity.ops[0]?.relation?.id,
114
- index: entity.ops[0]?.relation?.index,
115
- toEntity: someAuthorId,
116
- type: AUTHORS_PROPERTY,
117
- },
118
- type: 'CREATE_RELATION',
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 a nested properties', async () => {
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
- properties: {
190
- [AUTHORS_PROPERTY]: {
191
- to: someAuthorId,
192
- relationId: authorRelationId,
193
- properties: {
194
- [ROLES_PROPERTY]: {
195
- to: someRoleId,
196
- relationId: roleRelationId,
197
- properties: {
198
- [NEWS_STORY_TYPE]: {
199
- to: someRoleId2,
200
- relationId: newsStoryRelationId,
201
- },
202
- [WEB_URL_PROPERTY]: {
203
- value: 'https://example.com',
204
- type: 'URL',
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 types, triples, and relations', async () => {
106
+ it('creates an entity with custom values', async () => {
107
+ const customPropertyId = Id('fa269fd3-de98-49cf-90c4-4235d905a67c');
264
108
  const entity = createEntity({
265
- name: 'Yummy Coffee',
266
- description: 'A delicious coffee shop with great food and great coffee',
267
- cover: coverId,
268
- types: [CLAIM_TYPE, NEWS_STORY_TYPE],
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(9);
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: Id('WeUPYRkhnQLmHPH4S1ioc4'),
283
- name: 'Yummy Coffee',
134
+ id: providedId,
135
+ name: 'Test Entity',
284
136
  });
285
137
  expect(entity).toBeDefined();
286
- expect(entity.id).toBe('WeUPYRkhnQLmHPH4S1ioc4');
138
+ expect(entity.id).toBe(providedId);
287
139
  expect(entity.ops).toHaveLength(1);
288
140
  expect(entity.ops[0]).toMatchObject({
289
- type: 'SET_TRIPLE',
290
- triple: {
291
- attribute: NAME_PROPERTY,
292
- entity: entity.id,
293
- value: { type: 'TEXT', value: 'Yummy Coffee' },
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
  });