@ibgib/core-gib 0.0.4

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 (330) hide show
  1. package/.vscode/core-gib-snippets.code-snippets +189 -0
  2. package/.vscode/launch.json +24 -0
  3. package/.vscode/settings.json +56 -0
  4. package/.vscode/tasks.json +37 -0
  5. package/CHANGELOG.md +11 -0
  6. package/README.md +215 -0
  7. package/dist/common/aws-constants.d.mts +7 -0
  8. package/dist/common/aws-constants.d.mts.map +1 -0
  9. package/dist/common/aws-constants.mjs +7 -0
  10. package/dist/common/aws-constants.mjs.map +1 -0
  11. package/dist/common/bin/bin-types.d.mts +17 -0
  12. package/dist/common/bin/bin-types.d.mts.map +1 -0
  13. package/dist/common/bin/bin-types.mjs +3 -0
  14. package/dist/common/bin/bin-types.mjs.map +1 -0
  15. package/dist/common/cache/cache-types.d.mts +57 -0
  16. package/dist/common/cache/cache-types.d.mts.map +1 -0
  17. package/dist/common/cache/cache-types.mjs +2 -0
  18. package/dist/common/cache/cache-types.mjs.map +1 -0
  19. package/dist/common/comment/comment-constants.d.mts +11 -0
  20. package/dist/common/comment/comment-constants.d.mts.map +1 -0
  21. package/dist/common/comment/comment-constants.mjs +11 -0
  22. package/dist/common/comment/comment-constants.mjs.map +1 -0
  23. package/dist/common/comment/comment-helper.d.mts +59 -0
  24. package/dist/common/comment/comment-helper.d.mts.map +1 -0
  25. package/dist/common/comment/comment-helper.mjs +173 -0
  26. package/dist/common/comment/comment-helper.mjs.map +1 -0
  27. package/dist/common/comment/comment-types.d.mts +16 -0
  28. package/dist/common/comment/comment-types.d.mts.map +1 -0
  29. package/dist/common/comment/comment-types.mjs +2 -0
  30. package/dist/common/comment/comment-types.mjs.map +1 -0
  31. package/dist/common/display/display-helper.d.mts +19 -0
  32. package/dist/common/display/display-helper.d.mts.map +1 -0
  33. package/dist/common/display/display-helper.mjs +68 -0
  34. package/dist/common/display/display-helper.mjs.map +1 -0
  35. package/dist/common/display/display-types.d.mts +97 -0
  36. package/dist/common/display/display-types.d.mts.map +1 -0
  37. package/dist/common/display/display-types.mjs +37 -0
  38. package/dist/common/display/display-types.mjs.map +1 -0
  39. package/dist/common/encrypt/encrypt-constants.d.mts +27 -0
  40. package/dist/common/encrypt/encrypt-constants.d.mts.map +1 -0
  41. package/dist/common/encrypt/encrypt-constants.mjs +27 -0
  42. package/dist/common/encrypt/encrypt-constants.mjs.map +1 -0
  43. package/dist/common/encrypt/encrypt-types.d.mts +116 -0
  44. package/dist/common/encrypt/encrypt-types.d.mts.map +1 -0
  45. package/dist/common/encrypt/encrypt-types.mjs +9 -0
  46. package/dist/common/encrypt/encrypt-types.mjs.map +1 -0
  47. package/dist/common/error/error-constants.d.mts +9 -0
  48. package/dist/common/error/error-constants.d.mts.map +1 -0
  49. package/dist/common/error/error-constants.mjs +9 -0
  50. package/dist/common/error/error-constants.mjs.map +1 -0
  51. package/dist/common/error/error-helper.d.mts +43 -0
  52. package/dist/common/error/error-helper.d.mts.map +1 -0
  53. package/dist/common/error/error-helper.mjs +167 -0
  54. package/dist/common/error/error-helper.mjs.map +1 -0
  55. package/dist/common/error/error-types.d.mts +58 -0
  56. package/dist/common/error/error-types.d.mts.map +1 -0
  57. package/dist/common/error/error-types.mjs +2 -0
  58. package/dist/common/error/error-types.mjs.map +1 -0
  59. package/dist/common/form/form-helper.d.mts +97 -0
  60. package/dist/common/form/form-helper.d.mts.map +1 -0
  61. package/dist/common/form/form-helper.mjs +185 -0
  62. package/dist/common/form/form-helper.mjs.map +1 -0
  63. package/dist/common/form/form-items.d.mts +229 -0
  64. package/dist/common/form/form-items.d.mts.map +1 -0
  65. package/dist/common/form/form-items.mjs +63 -0
  66. package/dist/common/form/form-items.mjs.map +1 -0
  67. package/dist/common/import-export/import-export-types.d.mts +18 -0
  68. package/dist/common/import-export/import-export-types.d.mts.map +1 -0
  69. package/dist/common/import-export/import-export-types.mjs +2 -0
  70. package/dist/common/import-export/import-export-types.mjs.map +1 -0
  71. package/dist/common/legacy/legacy-types.d.mts +2 -0
  72. package/dist/common/legacy/legacy-types.d.mts.map +1 -0
  73. package/dist/common/legacy/legacy-types.mjs +2 -0
  74. package/dist/common/legacy/legacy-types.mjs.map +1 -0
  75. package/dist/common/link/link-constants.d.mts +2 -0
  76. package/dist/common/link/link-constants.d.mts.map +1 -0
  77. package/dist/common/link/link-constants.mjs +2 -0
  78. package/dist/common/link/link-constants.mjs.map +1 -0
  79. package/dist/common/link/link-helper.d.mts +37 -0
  80. package/dist/common/link/link-helper.d.mts.map +1 -0
  81. package/dist/common/link/link-helper.mjs +143 -0
  82. package/dist/common/link/link-helper.mjs.map +1 -0
  83. package/dist/common/link/link-types.d.mts +14 -0
  84. package/dist/common/link/link-types.d.mts.map +1 -0
  85. package/dist/common/link/link-types.mjs +2 -0
  86. package/dist/common/link/link-types.mjs.map +1 -0
  87. package/dist/common/other/graph-helper.d.mts +166 -0
  88. package/dist/common/other/graph-helper.d.mts.map +1 -0
  89. package/dist/common/other/graph-helper.mjs +710 -0
  90. package/dist/common/other/graph-helper.mjs.map +1 -0
  91. package/dist/common/other/ibgib-helper.d.mts +245 -0
  92. package/dist/common/other/ibgib-helper.d.mts.map +1 -0
  93. package/dist/common/other/ibgib-helper.mjs +641 -0
  94. package/dist/common/other/ibgib-helper.mjs.map +1 -0
  95. package/dist/common/other/other-constants.d.mts +53 -0
  96. package/dist/common/other/other-constants.d.mts.map +1 -0
  97. package/dist/common/other/other-constants.mjs +67 -0
  98. package/dist/common/other/other-constants.mjs.map +1 -0
  99. package/dist/common/other/other-types.d.mts +166 -0
  100. package/dist/common/other/other-types.d.mts.map +1 -0
  101. package/dist/common/other/other-types.mjs +30 -0
  102. package/dist/common/other/other-types.mjs.map +1 -0
  103. package/dist/common/other/svg-constants.d.mts +2 -0
  104. package/dist/common/other/svg-constants.d.mts.map +1 -0
  105. package/dist/common/other/svg-constants.mjs +2 -0
  106. package/dist/common/other/svg-constants.mjs.map +1 -0
  107. package/dist/common/other/svg-helper.d.mts +54 -0
  108. package/dist/common/other/svg-helper.d.mts.map +1 -0
  109. package/dist/common/other/svg-helper.mjs +170 -0
  110. package/dist/common/other/svg-helper.mjs.map +1 -0
  111. package/dist/common/pic/pic-constants.d.mts +13 -0
  112. package/dist/common/pic/pic-constants.d.mts.map +1 -0
  113. package/dist/common/pic/pic-constants.mjs +13 -0
  114. package/dist/common/pic/pic-constants.mjs.map +1 -0
  115. package/dist/common/pic/pic-helper.d.mts +70 -0
  116. package/dist/common/pic/pic-helper.d.mts.map +1 -0
  117. package/dist/common/pic/pic-helper.mjs +235 -0
  118. package/dist/common/pic/pic-helper.mjs.map +1 -0
  119. package/dist/common/pic/pic-types.d.mts +23 -0
  120. package/dist/common/pic/pic-types.d.mts.map +1 -0
  121. package/dist/common/pic/pic-types.mjs +2 -0
  122. package/dist/common/pic/pic-types.mjs.map +1 -0
  123. package/dist/common/root/root-constants.d.mts +40 -0
  124. package/dist/common/root/root-constants.d.mts.map +1 -0
  125. package/dist/common/root/root-constants.mjs +40 -0
  126. package/dist/common/root/root-constants.mjs.map +1 -0
  127. package/dist/common/root/root-types.d.mts +9 -0
  128. package/dist/common/root/root-types.d.mts.map +1 -0
  129. package/dist/common/root/root-types.mjs +2 -0
  130. package/dist/common/root/root-types.mjs.map +1 -0
  131. package/dist/common/tag/tag-constants.d.mts +21 -0
  132. package/dist/common/tag/tag-constants.d.mts.map +1 -0
  133. package/dist/common/tag/tag-constants.mjs +28 -0
  134. package/dist/common/tag/tag-constants.mjs.map +1 -0
  135. package/dist/common/tag/tag-types.d.mts +14 -0
  136. package/dist/common/tag/tag-types.d.mts.map +1 -0
  137. package/dist/common/tag/tag-types.mjs +2 -0
  138. package/dist/common/tag/tag-types.mjs.map +1 -0
  139. package/dist/core-constants.d.mts +89 -0
  140. package/dist/core-constants.d.mts.map +1 -0
  141. package/dist/core-constants.mjs +484 -0
  142. package/dist/core-constants.mjs.map +1 -0
  143. package/dist/core-helper.d.mts +6 -0
  144. package/dist/core-helper.d.mts.map +1 -0
  145. package/dist/core-helper.mjs +28 -0
  146. package/dist/core-helper.mjs.map +1 -0
  147. package/dist/core-types.d.mts +520 -0
  148. package/dist/core-types.d.mts.map +1 -0
  149. package/dist/core-types.mjs +2 -0
  150. package/dist/core-types.mjs.map +1 -0
  151. package/dist/index.d.mts +2 -0
  152. package/dist/index.d.mts.map +1 -0
  153. package/dist/index.mjs +3 -0
  154. package/dist/index.mjs.map +1 -0
  155. package/dist/witness/app/app-base-v1.d.mts +130 -0
  156. package/dist/witness/app/app-base-v1.d.mts.map +1 -0
  157. package/dist/witness/app/app-base-v1.mjs +462 -0
  158. package/dist/witness/app/app-base-v1.mjs.map +1 -0
  159. package/dist/witness/app/app-constants.d.mts +10 -0
  160. package/dist/witness/app/app-constants.d.mts.map +1 -0
  161. package/dist/witness/app/app-constants.mjs +13 -0
  162. package/dist/witness/app/app-constants.mjs.map +1 -0
  163. package/dist/witness/app/app-helper.d.mts +85 -0
  164. package/dist/witness/app/app-helper.d.mts.map +1 -0
  165. package/dist/witness/app/app-helper.mjs +258 -0
  166. package/dist/witness/app/app-helper.mjs.map +1 -0
  167. package/dist/witness/app/app-types.d.mts +211 -0
  168. package/dist/witness/app/app-types.d.mts.map +1 -0
  169. package/dist/witness/app/app-types.mjs +49 -0
  170. package/dist/witness/app/app-types.mjs.map +1 -0
  171. package/dist/witness/app/chat-app/chat-app-types.d.mts +18 -0
  172. package/dist/witness/app/chat-app/chat-app-types.d.mts.map +1 -0
  173. package/dist/witness/app/chat-app/chat-app-types.mjs +25 -0
  174. package/dist/witness/app/chat-app/chat-app-types.mjs.map +1 -0
  175. package/dist/witness/app/flash-app/flash-app-types.d.mts +16 -0
  176. package/dist/witness/app/flash-app/flash-app-types.d.mts.map +1 -0
  177. package/dist/witness/app/flash-app/flash-app-types.mjs +23 -0
  178. package/dist/witness/app/flash-app/flash-app-types.mjs.map +1 -0
  179. package/dist/witness/app/raw-app/raw-app-types.d.mts +18 -0
  180. package/dist/witness/app/raw-app/raw-app-types.d.mts.map +1 -0
  181. package/dist/witness/app/raw-app/raw-app-types.mjs +25 -0
  182. package/dist/witness/app/raw-app/raw-app-types.mjs.map +1 -0
  183. package/dist/witness/app/todo-app/todo-app-types.d.ts +33 -0
  184. package/dist/witness/app/todo-app/todo-app-types.d.ts.map +1 -0
  185. package/dist/witness/app/todo-app/todo-app-types.js +31 -0
  186. package/dist/witness/app/todo-app/todo-app-types.js.map +1 -0
  187. package/dist/witness/robbot/robbot-base-v1.d.ts +432 -0
  188. package/dist/witness/robbot/robbot-base-v1.d.ts.map +1 -0
  189. package/dist/witness/robbot/robbot-base-v1.js +1407 -0
  190. package/dist/witness/robbot/robbot-base-v1.js.map +1 -0
  191. package/dist/witness/robbot/robbot-constants.d.mts +24 -0
  192. package/dist/witness/robbot/robbot-constants.d.mts.map +1 -0
  193. package/dist/witness/robbot/robbot-constants.mjs +24 -0
  194. package/dist/witness/robbot/robbot-constants.mjs.map +1 -0
  195. package/dist/witness/robbot/robbot-helper.d.mts +152 -0
  196. package/dist/witness/robbot/robbot-helper.d.mts.map +1 -0
  197. package/dist/witness/robbot/robbot-helper.mjs +609 -0
  198. package/dist/witness/robbot/robbot-helper.mjs.map +1 -0
  199. package/dist/witness/robbot/robbot-types.d.mts +539 -0
  200. package/dist/witness/robbot/robbot-types.d.mts.map +1 -0
  201. package/dist/witness/robbot/robbot-types.mjs +294 -0
  202. package/dist/witness/robbot/robbot-types.mjs.map +1 -0
  203. package/dist/witness/space/bootstrap/bootstrap-constants.d.mts +14 -0
  204. package/dist/witness/space/bootstrap/bootstrap-constants.d.mts.map +1 -0
  205. package/dist/witness/space/bootstrap/bootstrap-constants.mjs +15 -0
  206. package/dist/witness/space/bootstrap/bootstrap-constants.mjs.map +1 -0
  207. package/dist/witness/space/inner-space-v1.d.ts +63 -0
  208. package/dist/witness/space/inner-space-v1.d.ts.map +1 -0
  209. package/dist/witness/space/inner-space-v1.js +356 -0
  210. package/dist/witness/space/inner-space-v1.js.map +1 -0
  211. package/dist/witness/space/outer-space/outer-space-constants.d.mts +2 -0
  212. package/dist/witness/space/outer-space/outer-space-constants.d.mts.map +1 -0
  213. package/dist/witness/space/outer-space/outer-space-constants.mjs +2 -0
  214. package/dist/witness/space/outer-space/outer-space-constants.mjs.map +1 -0
  215. package/dist/witness/space/outer-space/outer-space-helper.d.mts +28 -0
  216. package/dist/witness/space/outer-space/outer-space-helper.d.mts.map +1 -0
  217. package/dist/witness/space/outer-space/outer-space-helper.mjs +87 -0
  218. package/dist/witness/space/outer-space/outer-space-helper.mjs.map +1 -0
  219. package/dist/witness/space/outer-space/outer-space-types.d.mts +548 -0
  220. package/dist/witness/space/outer-space/outer-space-types.d.mts.map +1 -0
  221. package/dist/witness/space/outer-space/outer-space-types.mjs +118 -0
  222. package/dist/witness/space/outer-space/outer-space-types.mjs.map +1 -0
  223. package/dist/witness/space/space-base-v1.d.mts +147 -0
  224. package/dist/witness/space/space-base-v1.d.mts.map +1 -0
  225. package/dist/witness/space/space-base-v1.mjs +350 -0
  226. package/dist/witness/space/space-base-v1.mjs.map +1 -0
  227. package/dist/witness/space/space-constants.d.mts +181 -0
  228. package/dist/witness/space/space-constants.d.mts.map +1 -0
  229. package/dist/witness/space/space-constants.mjs +192 -0
  230. package/dist/witness/space/space-constants.mjs.map +1 -0
  231. package/dist/witness/space/space-helper.d.mts +666 -0
  232. package/dist/witness/space/space-helper.d.mts.map +1 -0
  233. package/dist/witness/space/space-helper.mjs +2830 -0
  234. package/dist/witness/space/space-helper.mjs.map +1 -0
  235. package/dist/witness/space/space-types.d.mts +422 -0
  236. package/dist/witness/space/space-types.d.mts.map +1 -0
  237. package/dist/witness/space/space-types.mjs +52 -0
  238. package/dist/witness/space/space-types.mjs.map +1 -0
  239. package/dist/witness/witness-base-v1.d.ts +144 -0
  240. package/dist/witness/witness-base-v1.d.ts.map +1 -0
  241. package/dist/witness/witness-base-v1.js +300 -0
  242. package/dist/witness/witness-base-v1.js.map +1 -0
  243. package/dist/witness/witness-constants.d.mts +3 -0
  244. package/dist/witness/witness-constants.d.mts.map +1 -0
  245. package/dist/witness/witness-constants.mjs +3 -0
  246. package/dist/witness/witness-constants.mjs.map +1 -0
  247. package/dist/witness/witness-form-builder.d.mts +45 -0
  248. package/dist/witness/witness-form-builder.d.mts.map +1 -0
  249. package/dist/witness/witness-form-builder.mjs +95 -0
  250. package/dist/witness/witness-form-builder.mjs.map +1 -0
  251. package/dist/witness/witness-helper.d.mts +89 -0
  252. package/dist/witness/witness-helper.d.mts.map +1 -0
  253. package/dist/witness/witness-helper.mjs +229 -0
  254. package/dist/witness/witness-helper.mjs.map +1 -0
  255. package/dist/witness/witness-types.d.mts +211 -0
  256. package/dist/witness/witness-types.d.mts.map +1 -0
  257. package/dist/witness/witness-types.mjs +2 -0
  258. package/dist/witness/witness-types.mjs.map +1 -0
  259. package/jasmine-browser.json +18 -0
  260. package/jasmine.json +6 -0
  261. package/package.json +67 -0
  262. package/src/assumptions.spec.mts +45 -0
  263. package/src/common/aws-constants.mts +5 -0
  264. package/src/common/bin/bin-types.mts +17 -0
  265. package/src/common/cache/cache-types.mts +53 -0
  266. package/src/common/comment/comment-constants.mts +10 -0
  267. package/src/common/comment/comment-helper.mts +211 -0
  268. package/src/common/comment/comment-types.mts +19 -0
  269. package/src/common/display/display-helper.mts +88 -0
  270. package/src/common/display/display-types.mts +108 -0
  271. package/src/common/encrypt/encrypt-constants.mts +28 -0
  272. package/src/common/encrypt/encrypt-types.mts +130 -0
  273. package/src/common/error/error-constants.mts +8 -0
  274. package/src/common/error/error-helper.mts +155 -0
  275. package/src/common/error/error-types.mts +62 -0
  276. package/src/common/form/form-helper.mts +253 -0
  277. package/src/common/form/form-items.mts +236 -0
  278. package/src/common/import-export/import-export-types.mts +18 -0
  279. package/src/common/legacy/about-legacy.md +0 -0
  280. package/src/common/legacy/legacy-types.mts +0 -0
  281. package/src/common/link/link-constants.mts +1 -0
  282. package/src/common/link/link-helper.mts +155 -0
  283. package/src/common/link/link-types.mts +16 -0
  284. package/src/common/other/graph-helper.mts +853 -0
  285. package/src/common/other/ibgib-helper.mts +671 -0
  286. package/src/common/other/other-constants.mts +76 -0
  287. package/src/common/other/other-types.mts +186 -0
  288. package/src/common/other/svg-constants.mts +1 -0
  289. package/src/common/other/svg-helper.mts +238 -0
  290. package/src/common/pic/pic-constants.mts +13 -0
  291. package/src/common/pic/pic-helper.mts +295 -0
  292. package/src/common/pic/pic-types.mts +29 -0
  293. package/src/common/root/root-constants.mts +41 -0
  294. package/src/common/root/root-types.mts +8 -0
  295. package/src/common/tag/tag-constants.mts +34 -0
  296. package/src/common/tag/tag-types.mts +19 -0
  297. package/src/core-constants.mts +506 -0
  298. package/src/core-helper.mts +33 -0
  299. package/src/core-types.mts +519 -0
  300. package/src/helper.spec.mts +64 -0
  301. package/src/index.mts +1 -0
  302. package/src/witness/app/app-base-v1.mts +584 -0
  303. package/src/witness/app/app-constants.mts +16 -0
  304. package/src/witness/app/app-helper.mts +322 -0
  305. package/src/witness/app/app-types.mts +252 -0
  306. package/src/witness/app/chat-app/chat-app-types.mts +40 -0
  307. package/src/witness/app/flash-app/flash-app-types.mts +38 -0
  308. package/src/witness/app/raw-app/raw-app-types.mts +40 -0
  309. package/src/witness/app/todo-app/todo-app-types.ts +59 -0
  310. package/src/witness/robbot/robbot-base-v1.ts +1531 -0
  311. package/src/witness/robbot/robbot-constants.mts +25 -0
  312. package/src/witness/robbot/robbot-helper.mts +676 -0
  313. package/src/witness/robbot/robbot-helper.spec.mts +135 -0
  314. package/src/witness/robbot/robbot-types.mts +797 -0
  315. package/src/witness/space/bootstrap/bootstrap-constants.mts +15 -0
  316. package/src/witness/space/inner-space-v1.ts +372 -0
  317. package/src/witness/space/outer-space/outer-space-constants.mts +1 -0
  318. package/src/witness/space/outer-space/outer-space-helper.mts +91 -0
  319. package/src/witness/space/outer-space/outer-space-types.mts +627 -0
  320. package/src/witness/space/space-base-v1.mts +414 -0
  321. package/src/witness/space/space-constants.mts +208 -0
  322. package/src/witness/space/space-helper.mts +3242 -0
  323. package/src/witness/space/space-types.mts +476 -0
  324. package/src/witness/witness-base-v1.ts +325 -0
  325. package/src/witness/witness-constants.mts +2 -0
  326. package/src/witness/witness-form-builder.mts +128 -0
  327. package/src/witness/witness-helper.mts +256 -0
  328. package/src/witness/witness-types.mts +249 -0
  329. package/tsconfig.json +15 -0
  330. package/tsconfig.test.json +10 -0
@@ -0,0 +1,710 @@
1
+ import { getIbAndGib, getIbGibAddr, } from '@ibgib/ts-gib';
2
+ import { GIB, isPrimitive, IBGIB_DELIMITER, } from '@ibgib/ts-gib/dist/V1/index.mjs';
3
+ import { GLOBAL_LOG_A_LOT } from '../../core-constants.mjs';
4
+ import { getFromSpace, getLatestAddrs } from '../../witness/space/space-helper.mjs';
5
+ import { getTimelinesGroupedByTjp } from './ibgib-helper.mjs';
6
+ import { validateIbGibAddr } from '@ibgib/ts-gib/dist/V1/validate-helper.mjs';
7
+ import { delay, pretty, unique } from '@ibgib/helper-gib';
8
+ const logalot = GLOBAL_LOG_A_LOT || false;
9
+ /**
10
+ *
11
+ * @returns dependency graph, live or non-live depending on {@link GetDependencyGraphOptions}
12
+ *
13
+ * Getting a `live` dependency graph means that we will be looking in the given
14
+ * @see {@link GetDependencyGraphOptions.space} for updates to ibGibs' timelines
15
+ * (those ibGibs that have timelines/tjps). This is more costly computationally
16
+ * in the short-term, but often cheaper in the long-term.
17
+ */
18
+ export async function getDependencyGraph({ ibGib, ibGibs, ibGibAddr, ibGibAddrs, live, gotten, tjpAddrsAlreadyAnalyzed, skipAddrs, skipRel8nNames, onlyRel8nNames, maxRetries, msBetweenRetries, space, timeLogName, mapTjpAddrToLatestAddrsInSpace, }) {
19
+ const lc = `[${getGraphProjection.name}]`;
20
+ try {
21
+ if (logalot) {
22
+ console.log(`${lc} starting... (I: c2a4426c22e849611ca0cedabe683a22)`);
23
+ }
24
+ const graph = await getGraphProjection({
25
+ ibGib, ibGibs, ibGibAddr, ibGibAddrs,
26
+ live,
27
+ gotten, tjpAddrsAlreadyAnalyzed,
28
+ skipAddrs, skipRel8nNames, onlyRel8nNames,
29
+ maxRetries, msBetweenRetries,
30
+ space,
31
+ timeLogName,
32
+ mapTjpAddrToLatestAddrsInSpace,
33
+ });
34
+ Object.values(graph).filter(ibGib => ibGib.ib.startsWith('comment ')).forEach(ibGib => { console.table(ibGib); });
35
+ if (logalot) {
36
+ console.log(`${lc} graph size: ${Object.keys(graph).length} (I: c6cb5e7e1e2611d35b9006fac6503d22)`);
37
+ const ibs = Object.values(graph).filter(ibGib => ibGib.ib.startsWith('comment ') || ibGib.ib.startsWith('pic '))
38
+ .map(ibGib => ibGib.ib);
39
+ unique(ibs).forEach(ib => console.log(ib));
40
+ }
41
+ return graph;
42
+ }
43
+ catch (error) {
44
+ console.error(`${lc} ${error.message}`);
45
+ throw error;
46
+ }
47
+ finally {
48
+ if (logalot) {
49
+ console.log(`${lc} complete.`);
50
+ }
51
+ }
52
+ }
53
+ async function getGraphProjection_initializeOpts({ ibGib, ibGibs, ibGibAddr, ibGibAddrs, live, gotten, tjpAddrsAlreadyAnalyzed, skipAddrs, skipRel8nNames, onlyRel8nNames, maxRetries, msBetweenRetries, space, timeLogName, mapTjpAddrToLatestAddrsInSpace, }) {
54
+ const lc = `[${getGraphProjection_initializeOpts.name}]`;
55
+ try {
56
+ if (logalot) {
57
+ console.log(`${lc} starting... (I: bd6807477f679345df9dddefe0b4e922)`);
58
+ }
59
+ if (!space) {
60
+ throw new Error(`space required. (E: 9f38166ab70340cb919174f8d26af909)`);
61
+ }
62
+ if (!ibGib && !ibGibAddr && (ibGibs ?? []).length === 0 && (ibGibAddrs ?? []).length === 0) {
63
+ throw new Error(`either ibGib/s or ibGibAddr/s required. (E: b6d08699651f455697f0d05a41edb039)`);
64
+ }
65
+ skipRel8nNames = skipRel8nNames || [];
66
+ // do NOT initialize onlyRel8nNames because we do logic based on falsy value
67
+ skipAddrs = skipAddrs || [];
68
+ gotten = gotten || {};
69
+ tjpAddrsAlreadyAnalyzed = tjpAddrsAlreadyAnalyzed || [];
70
+ // convert single args (ibGib, ibGibAddr) into the array args, filtering
71
+ // out primitives that we don't want. The `filter` function creates the
72
+ // copy here, so we won't mutate the incoming arrays. (The ibgibs and
73
+ // addrs themselves are immutable).
74
+ ibGibAddrs = (ibGibAddrs ?? [])
75
+ .filter(x => !isPrimitive({ gib: getIbAndGib({ ibGibAddr: x }).gib })) // no primitives
76
+ .filter(x => !skipAddrs.includes(x));
77
+ ibGibs =
78
+ (ibGibs ?? [])
79
+ .filter(x => !isPrimitive({ ibGib: x })) // no primitives
80
+ .filter(x => !skipAddrs.includes(getIbGibAddr({ ibGib: x })));
81
+ // if we're passed in a single ibGib, add it to the ibGibs array because
82
+ // we're going to work off of that.
83
+ if (ibGib &&
84
+ !isPrimitive({ ibGib }) &&
85
+ !ibGibs.some(x => x.gib === ibGib.gib) &&
86
+ !skipAddrs.includes(getIbGibAddr({ ibGib }))) {
87
+ ibGibs.push(ibGib);
88
+ }
89
+ // if we're passed in a single ibGibAddr, add it to the ibGibAddrs array because
90
+ // we're going to work off of that.
91
+ if (ibGibAddr &&
92
+ !isPrimitive({ gib: getIbAndGib({ ibGibAddr }).gib }) &&
93
+ !ibGibAddrs.includes(ibGibAddr) &&
94
+ !skipAddrs.includes(ibGibAddr)) {
95
+ ibGibAddrs.push(ibGibAddr);
96
+ }
97
+ return {
98
+ ibGib, ibGibs, ibGibAddr, ibGibAddrs,
99
+ live,
100
+ gotten, tjpAddrsAlreadyAnalyzed,
101
+ skipAddrs, skipRel8nNames, onlyRel8nNames,
102
+ maxRetries, msBetweenRetries,
103
+ space,
104
+ timeLogName,
105
+ mapTjpAddrToLatestAddrsInSpace,
106
+ };
107
+ }
108
+ catch (error) {
109
+ console.error(`${lc} ${error.message}`);
110
+ throw error;
111
+ }
112
+ finally {
113
+ if (logalot) {
114
+ console.log(`${lc} complete.`);
115
+ }
116
+ }
117
+ }
118
+ async function getGraphProjection_getIbGibsInIbGibAddrs({ ibGibs, ibGibAddrs, gotten, skipAddrs, maxRetries, msBetweenRetries, timeLogName, space, }) {
119
+ const lc = `[${getGraphProjection_getIbGibsInIbGibAddrs.name}]`;
120
+ try {
121
+ if (logalot) {
122
+ console.log(`${lc} starting... (I: 67b2be37ff24393fff56e229304da122)`);
123
+ }
124
+ /**
125
+ * ibgibs that we'll return
126
+ */
127
+ const resIbGibs = [];
128
+ ibGibs ?? (ibGibs = []);
129
+ ibGibAddrs ?? (ibGibAddrs = []);
130
+ skipAddrs ?? (skipAddrs = []);
131
+ gotten ?? (gotten = {});
132
+ const addrsToGetFromSpace = [];
133
+ const gottenAddrs = Object.keys(gotten ?? {}); // compute once in this closure
134
+ const incomingIbGibAddrs = ibGibs.map(x => getIbGibAddr({ ibGib: x }));
135
+ // const noNeedAddrs = [...gottenAddrs, ...incomingIbGibAddrs, ...skipAddrs,];
136
+ for (let i = 0; i < ibGibAddrs.length; i++) {
137
+ const addr = ibGibAddrs[i];
138
+ if (skipAddrs.includes(addr) || incomingIbGibAddrs.includes(addr)) {
139
+ continue;
140
+ }
141
+ else if (gottenAddrs.includes(addr)) {
142
+ // we've already gotten this addr previously and put it into the
143
+ // gotten object, so we don't need to retrieve it from space
144
+ resIbGibs.push(gotten[addr]);
145
+ }
146
+ else {
147
+ // if (!noNeedAddrs.includes(ibGibAddrs[i])) {
148
+ addrsToGetFromSpace.push(ibGibAddrs[i]);
149
+ }
150
+ }
151
+ if (logalot) {
152
+ console.log(`${lc}[analyze debugging] addrsToGetFromSpace (${addrsToGetFromSpace.length}):\n${addrsToGetFromSpace.join('\n')} (I: b45a2614184b48b694becfd377c789f5)`);
153
+ }
154
+ if (addrsToGetFromSpace.length > 0) {
155
+ // get from space, with retries if applicable
156
+ let addrsToGet = addrsToGetFromSpace.concat();
157
+ let retryCount = 0;
158
+ maxRetries = maxRetries ?? 0;
159
+ while (retryCount <= maxRetries && addrsToGet.length > 0) {
160
+ if (timeLogName && retryCount === 0) {
161
+ console.timeLog(timeLogName, `${lc} FIRST try starting...`);
162
+ }
163
+ if (timeLogName && retryCount > 0) {
164
+ console.timeLog(timeLogName, `${lc} RETRY starting...`);
165
+ }
166
+ // delay if applicable
167
+ if (retryCount > 0 && msBetweenRetries) {
168
+ if (timeLogName) {
169
+ console.timeLog(timeLogName, `${lc} delaying ${msBetweenRetries}ms for retry`);
170
+ }
171
+ if (logalot) {
172
+ console.log(`${lc} retrying. addrsToGet (${addrsToGet.length}): ${addrsToGet} (I: 8460694cdd5518472680784c3b96a822)`);
173
+ }
174
+ await delay(msBetweenRetries);
175
+ }
176
+ // do the get
177
+ if (timeLogName) {
178
+ console.timeLog(timeLogName, `${lc} getFromSpace (${addrsToGet?.length}) starting...`);
179
+ }
180
+ if (!space) {
181
+ throw new Error(`(UNEXPECTED) space falsy? (E: aa9f657695717034b3581066932d7d23)`);
182
+ }
183
+ let resGetThese = await getFromSpace({ addrs: addrsToGet, space });
184
+ if (timeLogName) {
185
+ console.timeLog(timeLogName, `${lc} getFromSpace complete.`);
186
+ }
187
+ if (resGetThese.success && (resGetThese.ibGibs?.length ?? 0) > 0) {
188
+ resGetThese.ibGibs.forEach(x => resIbGibs.push(x));
189
+ // resGetThese.ibGibs.forEach(x => ibGibs.push(x));
190
+ const gottenAddrs = resGetThese.ibGibs.map(x => getIbGibAddr({ ibGib: x }));
191
+ if (gottenAddrs.length === addrsToGet.length) {
192
+ if (timeLogName) {
193
+ console.timeLog(timeLogName, `${lc} got all.`);
194
+ }
195
+ // got them all, so we're done
196
+ addrsToGet = [];
197
+ break;
198
+ }
199
+ else {
200
+ if (timeLogName) {
201
+ console.timeLog(timeLogName, `${lc} got some.`);
202
+ }
203
+ // got only some, prune addrsToGet for next retry (if any)
204
+ addrsToGet = addrsToGet.filter(x => !gottenAddrs.includes(x));
205
+ }
206
+ }
207
+ else {
208
+ // failed, addrsToGet stays the same
209
+ if (timeLogName) {
210
+ console.timeLog(timeLogName, `${lc} failed. addrs: ${addrsToGet?.join(',')}`);
211
+ }
212
+ }
213
+ retryCount++;
214
+ }
215
+ if (addrsToGet?.length > 0) {
216
+ // console.dir(primaryKeysDebug);
217
+ throw new Error(`unable to retrieve dependency ibgibs from space.\n\nThis is often because downloading failed due to the sync space's server getting temporarily overloaded, OR...it sometimes happens when an ibgib doesn't get fully published to the sync space in the first place.\n\nYou could retry immediately or later, but if the problem persists, then retry from the publishers end (have the publisher sync again). (E: 8413594b6c1b447988781cf3f3e1729d)`);
218
+ }
219
+ }
220
+ return resIbGibs;
221
+ }
222
+ catch (error) {
223
+ console.error(`${lc} ${error.message}`);
224
+ throw error;
225
+ }
226
+ finally {
227
+ if (logalot) {
228
+ console.log(`${lc} complete.`);
229
+ }
230
+ }
231
+ }
232
+ export async function getGraphProjection(opts) {
233
+ const lc = `[${getGraphProjection.name}]`;
234
+ try {
235
+ if (logalot) {
236
+ console.log(`${lc} starting... (I: 70508d7a5c63eae1f22ae851b32b3d22)`);
237
+ }
238
+ if (!opts.ibGib && !opts.ibGibAddr && (opts.ibGibs ?? []).length === 0 && (opts.ibGibAddrs ?? []).length === 0) {
239
+ // no ibgibs/addrs, return empty - don't throw
240
+ return {}; /* <<<< returns early */
241
+ }
242
+ // ibGib and ibGibAddr get condensed into ibGibs and ibGibAddrs
243
+ let {
244
+ /*ibGib,*/ ibGibs, /*ibGibAddr,*/ ibGibAddrs, live, gotten, tjpAddrsAlreadyAnalyzed, skipAddrs, skipRel8nNames, onlyRel8nNames, maxRetries, msBetweenRetries, space, timeLogName, mapTjpAddrToLatestAddrsInSpace, } = await getGraphProjection_initializeOpts(opts);
245
+ if (timeLogName) {
246
+ console.timeLog(timeLogName, `${lc} starting...`);
247
+ }
248
+ // retrieve ibgibs listed in incoming ibGibAddrs (if any) and put them
249
+ // in our incoming ibGibs array
250
+ if (ibGibAddrs?.length ?? 0 > 0) {
251
+ const supplementalIbGibs = await getGraphProjection_getIbGibsInIbGibAddrs({
252
+ ibGibs, ibGibAddrs,
253
+ gotten,
254
+ skipAddrs,
255
+ maxRetries, msBetweenRetries,
256
+ timeLogName,
257
+ space,
258
+ });
259
+ ibGibs = ibGibs ?
260
+ [...ibGibs, ...supplementalIbGibs] :
261
+ [...supplementalIbGibs];
262
+ }
263
+ ibGibAddrs = ibGibs.map(x => getIbGibAddr({ ibGib: x }));
264
+ // at this point, there are two different strategies for diving deeper,
265
+ // depending on if we are building a `live` graph or not.
266
+ let commentIbs = unique(ibGibs.map(x => x.ib).filter(x => x.startsWith('comment ')));
267
+ if (logalot) {
268
+ console.log(`${lc}[analyze debugging] ibGibs commentIbs: ${commentIbs.join('\n')} (I: c89dc951315f746954f9bddbe8941122)`);
269
+ }
270
+ if (live) {
271
+ return getGraphProjection_Live({
272
+ ibGibs, ibGibAddrs,
273
+ gotten, tjpAddrsAlreadyAnalyzed,
274
+ skipAddrs, skipRel8nNames, onlyRel8nNames,
275
+ maxRetries, msBetweenRetries,
276
+ space, timeLogName,
277
+ mapTjpAddrToLatestAddrsInSpace,
278
+ });
279
+ }
280
+ else {
281
+ return getGraphProjection_NonLive({
282
+ ibGibs, ibGibAddrs,
283
+ gotten,
284
+ skipAddrs, skipRel8nNames, onlyRel8nNames,
285
+ maxRetries, msBetweenRetries,
286
+ space, timeLogName,
287
+ });
288
+ }
289
+ }
290
+ catch (error) {
291
+ console.error(`${lc} ${error.message}`);
292
+ throw error;
293
+ }
294
+ finally {
295
+ if (logalot) {
296
+ console.log(`${lc} complete.`);
297
+ }
298
+ }
299
+ }
300
+ /**
301
+ *
302
+ * live dependency graph searching requires a timeline-centric approach.
303
+ * for each incoming ibGib, we must first determine if it has a
304
+ * timeline. if it does, then we get the latest in that timeline and
305
+ * get all ibgibs in that lineage only. we do NOT YET go through any
306
+ * rel8d ibgibs that also have timelines
307
+ *
308
+ * what we can do is compile our list of ibGib addrs according to each
309
+ * timeline and then call the nonlive version of the dependency graph.
310
+ * but we must get the latest in the timeline, then get all associated
311
+ * timelines and get the latest of those. Then we can call get
312
+ * dependency graph on the non-live version, passing in all of those
313
+ * latest ibgibs in the timelines (and everything we've gotten in the
314
+ * interim so we don't waste time getting more).
315
+ *
316
+ * @see {@link getGraphProjection}
317
+ * @see {@link getDependencyGraph}
318
+ */
319
+ async function getGraphProjection_Live({ ibGibs, ibGibAddrs, gotten, tjpAddrsAlreadyAnalyzed, mapTjpAddrToLatestAddrsInSpace, skipAddrs, skipRel8nNames, onlyRel8nNames, maxRetries, msBetweenRetries, space, timeLogName, }) {
320
+ const lc = `[${getGraphProjection_Live.name}]`;
321
+ try {
322
+ mapTjpAddrToLatestAddrsInSpace = mapTjpAddrToLatestAddrsInSpace ?? {};
323
+ tjpAddrsAlreadyAnalyzed = tjpAddrsAlreadyAnalyzed ?? [];
324
+ // ibGibs contains the ones we explicitly are still working on getting
325
+ // projections within, gotten are the ones we have completed. so we want
326
+ // to get all of them together so we have a complete (up to this point)
327
+ // picture of timelines, because we're looking for timelines that we
328
+ // haven't yet analyzed
329
+ let allIbGibsSoFar = { ...gotten };
330
+ (ibGibs ?? []).forEach(x => allIbGibsSoFar[getIbGibAddr({ ibGib: x })] = x);
331
+ const allKnownTimelinesAtThisPoint = getTimelinesGroupedByTjp({
332
+ ibGibs: Object.values(allIbGibsSoFar),
333
+ });
334
+ if (logalot) {
335
+ console.log(`${lc}[analyze debugging] timeline tjps(${Object.keys(allKnownTimelinesAtThisPoint).length}): ${Object.keys(allKnownTimelinesAtThisPoint)} (I: 509f04ac15ca08c5a3f0777b48934622)`);
336
+ }
337
+ const timelinesNotAnalyzed = {};
338
+ Object.keys(allKnownTimelinesAtThisPoint).forEach(tjpAddr => {
339
+ if (!tjpAddrsAlreadyAnalyzed.includes(tjpAddr)) {
340
+ timelinesNotAnalyzed[tjpAddr] = allKnownTimelinesAtThisPoint[tjpAddr];
341
+ }
342
+ });
343
+ if (logalot) {
344
+ console.log(`${lc}[analyze debugging] timelinesNotAnalyzed: ${pretty(timelinesNotAnalyzed)} (I: a4b67d95fdd6b98d3241c0a7d0a93c22)`);
345
+ }
346
+ const mapTjpAddrToLatestIbGibInTimelineThatWeHaventAlreadyAnalyzed = {};
347
+ /**
348
+ * Convience mapping back from latest addr already gotten back to the tjp addr.
349
+ * Convenience = not strictly necessary, but makes it easier later.
350
+ */
351
+ const mapLatestAddrAlreadyGottenToTjpAddr = {};
352
+ Object.keys(allKnownTimelinesAtThisPoint)
353
+ .filter(tjpAddr => !tjpAddrsAlreadyAnalyzed.includes(tjpAddr))
354
+ .forEach(tjpAddr => {
355
+ const timeline = allKnownTimelinesAtThisPoint[tjpAddr];
356
+ // add to the array we'll send below
357
+ const latestIbGibAlreadyGotten = timeline[timeline.length - 1];
358
+ mapTjpAddrToLatestIbGibInTimelineThatWeHaventAlreadyAnalyzed[tjpAddr] = latestIbGibAlreadyGotten;
359
+ // add to mapping back from addr to tjpaddr for convenience below
360
+ const latestAddrAlreadyGotten = getIbGibAddr({ ibGib: latestIbGibAlreadyGotten });
361
+ mapLatestAddrAlreadyGottenToTjpAddr[latestAddrAlreadyGotten] = tjpAddr;
362
+ });
363
+ let countOfTimelinesNotYetGotten = Object.keys(mapTjpAddrToLatestIbGibInTimelineThatWeHaventAlreadyAnalyzed).length;
364
+ if (countOfTimelinesNotYetGotten > 0) {
365
+ // we have more timelines still to do. get the latest ibGib in each timeline,
366
+ // add it, check for more timelines. But we may have already gotten a latestAddrsMap
367
+ // in a previous call, so account for this.
368
+ // query only latest ibgibs that we haven't already gotten AND whose
369
+ // timelines we've not already analyzed, per
370
+ // mapTjpAddrToLatestAddrsInSpace.
371
+ /**
372
+ * build this map of latest addr given -> latest addr in space (per timeline/tjp).
373
+ */
374
+ let latestAddrsMap = {};
375
+ Object.keys(mapTjpAddrToLatestAddrsInSpace)
376
+ .filter(tjpAddr => !tjpAddrsAlreadyAnalyzed.includes(tjpAddr))
377
+ .forEach(tjpAddr => {
378
+ const latestIbGibCorrespondingToTjpAddr = mapTjpAddrToLatestIbGibInTimelineThatWeHaventAlreadyAnalyzed[tjpAddr];
379
+ if (latestIbGibCorrespondingToTjpAddr) {
380
+ const latestAddrCorrespondingToTjpAddr = getIbGibAddr({ ibGib: latestIbGibCorrespondingToTjpAddr });
381
+ latestAddrsMap[latestAddrCorrespondingToTjpAddr] = mapTjpAddrToLatestAddrsInSpace[tjpAddr];
382
+ }
383
+ else {
384
+ console.error(`${lc} latestIbGibCorrespondingToTjpAddr is falsy`);
385
+ }
386
+ });
387
+ if (logalot) {
388
+ console.log(`${lc} latestAddrsMap *before* getLatestAddrs: ${pretty(latestAddrsMap)} (I: 427b4bb78595e9e521ecf2c5e5c80722)`);
389
+ }
390
+ const ibGibsToQuery = Object.values(mapTjpAddrToLatestIbGibInTimelineThatWeHaventAlreadyAnalyzed);
391
+ // .filter(x => !Object.keys(latestAddrsMap).includes(getIbGibAddr({ ibGib: x })));
392
+ let queriedLatestAddrsMap = {};
393
+ if (ibGibsToQuery.length > 0) {
394
+ if (!space) {
395
+ throw new Error(`(UNEXPECTED) space falsy? (E: 8e878975e3561df9a8dc4c628b0abc23)`);
396
+ }
397
+ /** This is result with the map of the latest addrs in the space */
398
+ const resLatestAddrsMapInEntireSpace = await getLatestAddrs({
399
+ ibGibs: ibGibsToQuery,
400
+ space,
401
+ });
402
+ if (!resLatestAddrsMapInEntireSpace?.data?.latestAddrsMap) {
403
+ throw new Error(`(UNEXPECTED) getLatestAddrs result latestAddrsMap falsy (E: 088caa1fc95fd3b079108ab63ef33422)`);
404
+ }
405
+ queriedLatestAddrsMap = resLatestAddrsMapInEntireSpace?.data?.latestAddrsMap;
406
+ if (Object.keys(queriedLatestAddrsMap).length !== countOfTimelinesNotYetGotten) {
407
+ // this happens when the space does not have the address, sometimes because of
408
+ // not pushing the most recent changes to the sync space...hmmm
409
+ throw new Error(`(UNEXPECTED) latestAddrsMap is not the same size as the incoming map (E: 666af512bbd44534983bb28ee8d43fed)`);
410
+ }
411
+ if (logalot) {
412
+ console.log(`${lc} queriedLatestAddrsMap: ${pretty(queriedLatestAddrsMap)} (I: 7b39a5f7ce9e9d9fabae4be98ed44522)`);
413
+ }
414
+ latestAddrsMap = {
415
+ ...queriedLatestAddrsMap,
416
+ ...latestAddrsMap
417
+ };
418
+ }
419
+ if (logalot) {
420
+ console.log(`${lc} combined latestAddrsMap: ${pretty(latestAddrsMap)} (I: e3aedea63f29c5b06a79632f691aa522)`);
421
+ }
422
+ /**
423
+ * these addrs are those whose timelines we did not yet have the latest.
424
+ * this means that we will have to work off of these ibgibs.
425
+ */
426
+ const newerAddrsFound = [];
427
+ Object.values(mapTjpAddrToLatestIbGibInTimelineThatWeHaventAlreadyAnalyzed)
428
+ .forEach(latestIbGibAlreadyGotten => {
429
+ const latestAddrAlreadyGotten = getIbGibAddr({ ibGib: latestIbGibAlreadyGotten });
430
+ const tjpAddr = mapLatestAddrAlreadyGottenToTjpAddr[latestAddrAlreadyGotten];
431
+ const latestAddrInSpace = latestAddrsMap[latestAddrAlreadyGotten];
432
+ if (!latestAddrInSpace) {
433
+ throw new Error(`(UNEXPECTED) latestAddrInSpace not found in latestAddrsMap (E: 095d2b3f88e3e8a2c3e7d3de4c6d5622)`);
434
+ }
435
+ if (latestAddrInSpace === latestAddrAlreadyGotten) {
436
+ // we've already got the latest for this timeline. This
437
+ // means that we must have already at least queued all
438
+ // timelines possible, so nothing else to do.
439
+ if (logalot) {
440
+ console.log(`${lc} analyzed ${tjpAddr}(I: afb7960900f04b8a87538f4c7bd903b7)`);
441
+ }
442
+ tjpAddrsAlreadyAnalyzed.push(tjpAddr);
443
+ }
444
+ else {
445
+ // there is a newer "latest" in this timeline that we
446
+ // haven't gotten yet, so add that addr to the
447
+ newerAddrsFound.push(latestAddrInSpace);
448
+ }
449
+ });
450
+ let rel8dAddrsNotYetGotten = [];
451
+ for (let i = 0; i < (ibGibs ?? []).length; i++) {
452
+ const ibGib = ibGibs[i];
453
+ const rel8ns = ibGib.rel8ns ?? {};
454
+ const rel8nNames = Object.keys(rel8ns)
455
+ .filter(x => !(skipRel8nNames ?? []).includes(x))
456
+ .filter(x => onlyRel8nNames ? onlyRel8nNames.includes(x) : true);
457
+ rel8nNames.forEach(rel8nName => {
458
+ const rel8dAddrs = rel8ns[rel8nName] ?? [];
459
+ rel8dAddrs.forEach(rel8dAddr => {
460
+ // only add todo if we don't already have the ibgib
461
+ if (!rel8dAddrsNotYetGotten.includes(rel8dAddr) &&
462
+ !ibGibs.some(x => getIbGibAddr({ ibGib: x }) === rel8dAddr)) {
463
+ rel8dAddrsNotYetGotten.push(rel8dAddr);
464
+ }
465
+ });
466
+ });
467
+ }
468
+ ibGibAddrs = unique([...(ibGibAddrs ?? []), ...rel8dAddrsNotYetGotten]);
469
+ if (newerAddrsFound.length === 0) {
470
+ // there were no newer addrs found, necessitating that we have
471
+ // no additional ibgibs that we don't know about.
472
+ return await getGraphProjection({
473
+ ibGibs, ibGibAddrs,
474
+ gotten, tjpAddrsAlreadyAnalyzed,
475
+ // gotten, /* tjpAddrsAlreadyAnalyzed not used */
476
+ skipAddrs, skipRel8nNames, onlyRel8nNames,
477
+ maxRetries, msBetweenRetries,
478
+ space,
479
+ timeLogName,
480
+ live: true,
481
+ });
482
+ }
483
+ else {
484
+ // there are still newer ibgibs that must be included in the analysis, without yet
485
+ // going into the direct rel8ns of
486
+ // need to call recursively this _Live function, passing in
487
+ // the already computated latest map in mapTjpAddrToLatestAddrsInSpace
488
+ // I need to also adjust preceding code to use this map.
489
+ // leaving off here
490
+ // getDependencyGraph_Live({...})
491
+ Object.keys(queriedLatestAddrsMap).forEach(latestAddrNotGotten => {
492
+ const tjpAddr = mapLatestAddrAlreadyGottenToTjpAddr[latestAddrNotGotten];
493
+ mapTjpAddrToLatestAddrsInSpace[tjpAddr] = latestAddrNotGotten;
494
+ if (queriedLatestAddrsMap[latestAddrNotGotten]) {
495
+ ibGibAddrs.push();
496
+ }
497
+ });
498
+ ibGibAddrs = unique(ibGibAddrs);
499
+ // ibGibAddrs = unique([...ibGibAddrs, ...rel8dAddrsNotYetGotten]);
500
+ return await getGraphProjection({
501
+ ibGibs, ibGibAddrs,
502
+ gotten, tjpAddrsAlreadyAnalyzed,
503
+ skipAddrs, skipRel8nNames, onlyRel8nNames,
504
+ maxRetries, msBetweenRetries,
505
+ space,
506
+ timeLogName,
507
+ live: true,
508
+ mapTjpAddrToLatestAddrsInSpace,
509
+ });
510
+ }
511
+ }
512
+ else {
513
+ // we have no more timelines that we haven't already gotten, so we
514
+ // can pass off to the non-live version
515
+ if (!ibGibs) {
516
+ ibGibs = [];
517
+ }
518
+ Object.values(gotten ?? {}).forEach(x => {
519
+ const addr = getIbGibAddr({ ibGib: x });
520
+ if (!ibGibs.some(y => getIbGibAddr({ ibGib: x }) === addr)) {
521
+ ibGibs.push(x);
522
+ }
523
+ });
524
+ return await getGraphProjection({
525
+ ibGibs, ibGibAddrs,
526
+ gotten,
527
+ skipAddrs, skipRel8nNames, onlyRel8nNames,
528
+ maxRetries, msBetweenRetries,
529
+ space,
530
+ timeLogName,
531
+ live: false,
532
+ });
533
+ }
534
+ }
535
+ catch (error) {
536
+ const emsg = `${lc} ${error.message}`;
537
+ console.error(emsg);
538
+ if (timeLogName) {
539
+ console.timeLog(timeLogName, `${lc} error: ${emsg}`);
540
+ }
541
+ throw error;
542
+ }
543
+ finally {
544
+ if (timeLogName) {
545
+ console.timeLog(timeLogName, `${lc} complete.`);
546
+ }
547
+ }
548
+ }
549
+ /**
550
+ * NOT EXPORTED
551
+ *
552
+ * @see {@link getGraphProjection}
553
+ * @see {@link getDependencyGraph}
554
+ */
555
+ async function getGraphProjection_NonLive({ ibGibs, ibGibAddrs, gotten, /* tjpAddrsAlreadyAnalyzed not used */ skipAddrs, skipRel8nNames, onlyRel8nNames, maxRetries, msBetweenRetries, space, timeLogName, }) {
556
+ const lc = `[${getGraphProjection_NonLive.name}]`;
557
+ try {
558
+ // next, compile what could be a rather large list of rel8d ibgibAddrs
559
+ // which must necessarily be in the past of the futuremost incoming
560
+ // ibGib/ibGibAddr/s as rel8ns only work backwards (whereas tjp's can
561
+ // refer to future timelines, the DAG substrate only looks backwards)
562
+ const addrsWeDontHaveAlready_Rel8dAddrs = [];
563
+ ibGibs ?? (ibGibs = []);
564
+ gotten ?? (gotten = {});
565
+ skipAddrs ?? (skipAddrs = []);
566
+ skipRel8nNames ?? (skipRel8nNames = []);
567
+ // so, we will iterate through all of our given and loaded ibGibs (not
568
+ // the ones in gotten map though), look through all of their rel8ns, and
569
+ // add any that haven't already been gotten
570
+ if (timeLogName) {
571
+ console.timeLog(timeLogName, `${lc} analyzing next step starting...`);
572
+ }
573
+ for (let i = 0; i < ibGibs.length; i++) {
574
+ const ibGib = ibGibs[i];
575
+ const ibGibAddr = getIbGibAddr({ ibGib });
576
+ // do i need this?
577
+ const { gib } = getIbAndGib({ ibGib });
578
+ if (gib === GIB) {
579
+ throw new Error(`cannot get dependency graph of primitive.`);
580
+ }
581
+ // ?
582
+ // I believe I have this so we don't try to do this ibgib again on recursive call.
583
+ // but should I be adding it at this point? hmm...
584
+ if (!Object.keys(gotten).includes(ibGibAddr)) {
585
+ gotten[ibGibAddr] = ibGib;
586
+ }
587
+ // iterate through rel8ns and compile list of ibgib addrs not yet gotten
588
+ /** map of addr to validation errors array */
589
+ const invalidAddrs = {};
590
+ const rel8ns = ibGib.rel8ns || {};
591
+ let rel8nNames = (Object.keys(rel8ns) || []).filter(x => !skipRel8nNames.includes(x));
592
+ if (onlyRel8nNames) {
593
+ rel8nNames = rel8nNames.filter(x => onlyRel8nNames.includes(x));
594
+ }
595
+ const gottenKeys = Object.keys(gotten);
596
+ for (let i = 0; i < rel8nNames.length; i++) {
597
+ const rel8nName = rel8nNames[i];
598
+ const rel8dAddrs = rel8ns[rel8nName] ?? [];
599
+ const falsyAddrs = rel8dAddrs.filter(addr => addr === '' ||
600
+ addr === undefined ||
601
+ addr === null ||
602
+ !addr.includes(IBGIB_DELIMITER));
603
+ if (falsyAddrs.length > 0) {
604
+ console.warn(`${lc} (UNEXPECTED) has falsyAddrs: ${falsyAddrs} (W: da9505cb0a4db68a4aff7f279ad2d322)`);
605
+ }
606
+ const rel8dAddrsNotGottenYetThisRel8n = rel8dAddrs
607
+ .filter(addr => !!addr)
608
+ .filter(addr => !gottenKeys.includes(addr))
609
+ .filter(addr => !skipAddrs.includes(addr))
610
+ .filter(addr => getIbAndGib({ ibGibAddr: addr }).gib !== GIB)
611
+ .filter(addr => !addrsWeDontHaveAlready_Rel8dAddrs.includes(addr));
612
+ rel8dAddrsNotGottenYetThisRel8n.forEach(rel8dAddr => {
613
+ const validationErrors = validateIbGibAddr({ addr: rel8dAddr });
614
+ if ((validationErrors || []).length === 0) {
615
+ // valid addr. add it if we haven't gotten/queued it yet
616
+ addrsWeDontHaveAlready_Rel8dAddrs.push(rel8dAddr);
617
+ }
618
+ else {
619
+ // invalid address
620
+ invalidAddrs[rel8dAddr] = validationErrors;
621
+ }
622
+ });
623
+ }
624
+ if (Object.keys(invalidAddrs).length > 0) {
625
+ throw new Error(`invalid addresses found in dependency graph. Errors (clipped to 1kB): ${JSON.stringify(invalidAddrs).substring(0, 1024)}`);
626
+ }
627
+ }
628
+ if (timeLogName) {
629
+ console.timeLog(timeLogName, `${lc} analyzing next step complete.`);
630
+ }
631
+ if (addrsWeDontHaveAlready_Rel8dAddrs.length > 0) {
632
+ if (timeLogName) {
633
+ console.timeLog(timeLogName, `${lc} get addrsWeDontHaveAlready_Rel8dAddrs starting...`);
634
+ }
635
+ // execute the get on those addrs
636
+ if (!space) {
637
+ throw new Error(`(UNEXPECTED) space falsy? (E: 0ce327cf5d521bd798340333460f3423)`);
638
+ }
639
+ const resGet = await getFromSpace({ addrs: addrsWeDontHaveAlready_Rel8dAddrs, space });
640
+ if (timeLogName) {
641
+ console.timeLog(timeLogName, `${lc} get addrsWeDontHaveAlready_Rel8dAddrs complete.`);
642
+ }
643
+ if (resGet.success) {
644
+ if (resGet.ibGibs?.length === addrsWeDontHaveAlready_Rel8dAddrs.length) {
645
+ if (logalot) {
646
+ console.log(`${lc} got ALL of them (happy path)`);
647
+ }
648
+ resGet.ibGibs.forEach(x => gotten[getIbGibAddr({ ibGib: x })] = x);
649
+ // return a recursive call for the newly-gotten ibgibs'
650
+ // dependencies, passing in the now-larger accumulating
651
+ // `gotten` map of ibgibs already processed.
652
+ if (timeLogName) {
653
+ console.timeLog(timeLogName, `${lc} call getGraphProjection recursively starting...`);
654
+ }
655
+ const result = await getGraphProjection({
656
+ ibGibs: resGet.ibGibs,
657
+ live: false,
658
+ gotten,
659
+ skipAddrs, skipRel8nNames, onlyRel8nNames,
660
+ maxRetries, msBetweenRetries,
661
+ space,
662
+ });
663
+ if (timeLogName) {
664
+ console.timeLog(timeLogName, `${lc} call getGraphProjection recursively complete.`);
665
+ }
666
+ return result; // <<<< returns early
667
+ }
668
+ else if ((resGet.ibGibs?.length ?? 0) > 0 && resGet.ibGibs.length < addrsWeDontHaveAlready_Rel8dAddrs.length) {
669
+ if (logalot) {
670
+ console.warn(`${lc} got SOME of them (happy-ish path?). not sure what to do here... (W: e3458f61a1ae4979af9e6b18ac935c14)`);
671
+ }
672
+ throw new Error(`trouble getting dependency ibgibs (E: 8156bf65fd084ae4a4e8a0669db28b07)`);
673
+ }
674
+ else if ((resGet.ibGibs?.length ?? 0 > 0) && resGet.ibGibs.length > addrsWeDontHaveAlready_Rel8dAddrs.length) {
675
+ // got more than our original list? not a good space behavior...
676
+ throw new Error(`(UNEXPECTED) got more ibGibs than addrs that we asked for. space not working properly. (E: 352219b3d18543bcbda957f2d60b78f3)`);
677
+ }
678
+ else {
679
+ // didn't get any...hmm...
680
+ throw new Error(`couldn't get dependency ibgibs from space. (E: 225f26b7d7f84911bb033753a062209b)`);
681
+ }
682
+ }
683
+ else {
684
+ // resGet.success falsy indicates an error in the space. If it wasn't found
685
+ // then resGet.success would (should) still be truthy.
686
+ throw new Error(`failure getting addrs in space ${space?.data?.name || '[no name?]'} (id: ${space?.data?.uuid || '[no uuid?]'}). (E: 60404e6e389249d9bbecf0039cd51878) addrs:\n${addrsWeDontHaveAlready_Rel8dAddrs.join('\n')} `);
687
+ }
688
+ }
689
+ else {
690
+ // no other rel8d addrs to get, so our job is done and the `gotten`
691
+ // map of dependency ibgibs is complete (no need for another
692
+ // recursive call).
693
+ return gotten;
694
+ }
695
+ }
696
+ catch (error) {
697
+ const emsg = `${lc} ${error.message}`;
698
+ console.error(emsg);
699
+ if (timeLogName) {
700
+ console.timeLog(timeLogName, `${lc} error: ${emsg}`);
701
+ }
702
+ throw error;
703
+ }
704
+ finally {
705
+ if (timeLogName) {
706
+ console.timeLog(timeLogName, `${lc} complete.`);
707
+ }
708
+ }
709
+ }
710
+ //# sourceMappingURL=graph-helper.mjs.map