@graphprotocol/grc-20 0.31.0 → 0.32.0

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