@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,671 @@
1
+ import * as h from '@ibgib/helper-gib';
2
+ import { HashAlgorithm, groupBy } from '@ibgib/helper-gib';
3
+ import * as cTsGib from '@ibgib/ts-gib/dist/V1/constants.mjs';
4
+ import { Ib, IbGibAddr, getIbAndGib, getIbGibAddr, } from '@ibgib/ts-gib';
5
+ import {
6
+ IbGib_V1, IbGibRel8ns_V1, GIB,
7
+ Factory_V1 as factory, IbGibData_V1,
8
+ } from '@ibgib/ts-gib/dist/V1/index.mjs';
9
+ import { validateIb } from '@ibgib/ts-gib/dist/V1/validate-helper.mjs';
10
+ import { getGib, getGibInfo } from '@ibgib/ts-gib/dist/V1/transforms/transform-helper.mjs';
11
+
12
+ import { GLOBAL_LOG_A_LOT, IB_REGEXP_DEFAULT } from '../../core-constants.mjs';
13
+ import { SpecialIbGibType } from './other-types.mjs';
14
+
15
+ const logalot = GLOBAL_LOG_A_LOT || false;
16
+
17
+ /**
18
+ * Utility function to generate hard-coded ibgibs to use at runtime "on-chain" but
19
+ * written at compile-time in (for now) "off-chain" source code.
20
+ *
21
+ * Because this is supposed to create and re-create deterministically the equivalent
22
+ * of a non-primitive ibgib "constant", this function creates a single ibgib with...
23
+ * * one ancestor
24
+ * * no past, dna, or tjp rel8ns
25
+ * * no tjp timestamp or uuid
26
+ * * no nCounter
27
+ *
28
+ * ## validation
29
+ *
30
+ * * validates the given `ib` against `ibRegExpPattern` or default regexp.
31
+ * * validates that rel8ns doesn't include default forbidden rel8n names or
32
+ * atow `'tjp'`.
33
+ *
34
+ * ## intent
35
+ *
36
+ * I want to be able to create deterministic ibGibs that I can reference at
37
+ * runtime, similar to an ibgib primitive (e.g. "root^gib"), but with the
38
+ * integrity of the `gib` hash. This way, I can reference a deterministic ibgib
39
+ * from code at compile time, and at runtime this will have a corresponding
40
+ * ibgib datum with gib-hashed integrity.
41
+ *
42
+ * ## example
43
+ *
44
+ * I want to create a "hard-coded" schema ibgib that I rel8 to some protocol
45
+ * ibgib. So I'll create the data here, which lives in source control in a text file,
46
+ * and then I'll render that as an ibgib that verifies integrity. If I as a coder change
47
+ * it at all, then the `gib` of course will be different.
48
+ *
49
+ * @param param0
50
+ */
51
+ export async function constantIbGib<
52
+ TData extends IbGibData_V1 = any,
53
+ TRel8ns extends IbGibRel8ns_V1 = IbGibRel8ns_V1
54
+ >({
55
+ parentPrimitiveIb,
56
+ ib,
57
+ ibRegExpPattern,
58
+ data,
59
+ rel8ns,
60
+ }: {
61
+ parentPrimitiveIb: Ib,
62
+ ib: Ib,
63
+ ibRegExpPattern?: string,
64
+ data?: TData,
65
+ rel8ns?: TRel8ns,
66
+ }): Promise<IbGib_V1<TData, TRel8ns>> {
67
+ const lc = `[${constantIbGib.name}]`;
68
+ try {
69
+ // validation
70
+ // parentPrimitiveIb
71
+ if (!parentPrimitiveIb) { throw new Error(`parentPrimitiveIb required. (E: 88ddf188cc5a4340b597abefba1481e2)`); }
72
+ if (validateIb({ ib: parentPrimitiveIb }) !== null) { throw new Error(`Invalid parentPrimitiveIb: ${parentPrimitiveIb}. (E:5aec0320956d492ebeeaca41eb1fe1c6)`); }
73
+
74
+ // ib
75
+ if (!ib) { throw new Error(`ib required. (E: 7bbc88f4f2e842d6b00126e55b1783e4)`); }
76
+ const regExp = ibRegExpPattern ? new RegExp(ibRegExpPattern) : IB_REGEXP_DEFAULT;
77
+ if (!ib.match(regExp)) { throw new Error(`invalid ib. does not match regexp (${regExp})`); }
78
+
79
+ // rel8ns
80
+ const incomingRel8nNames = Object.keys(rel8ns ?? {});
81
+ const forbiddenRel8nNames = [...cTsGib.FORBIDDEN_ADD_RENAME_REMOVE_REL8N_NAMES, 'tjp'];
82
+ const rel8nsIsInvalid = incomingRel8nNames.some(x => {
83
+ // we don't want constants trying to look like they have/are descendants/tjps/etc.
84
+ return forbiddenRel8nNames.includes(x);
85
+ });
86
+ if (rel8nsIsInvalid) { throw new Error(`Invalid rel8ns. forbiddenRel8nNames: ${forbiddenRel8nNames}. rel8ns keys: ${Object.keys(rel8ns ?? {})}. (E: 837a993c265c4362b6aa0b1a234ea5f8)`); }
87
+
88
+
89
+ // create the constant
90
+ const resFirstGen = await factory.firstGen({
91
+ ib,
92
+ parentIbGib: factory.primitive({ ib: parentPrimitiveIb }),
93
+ data,
94
+ rel8ns,
95
+ dna: false,
96
+ noTimestamp: true,
97
+ nCounter: false,
98
+ });
99
+ const constantIbGib = resFirstGen.newIbGib as IbGib_V1<TData, TRel8ns>;
100
+
101
+ // remove any extraneous stuff
102
+ if (constantIbGib?.rel8ns?.past) { delete constantIbGib.rel8ns.past; }
103
+ if (constantIbGib?.rel8ns?.tjp) { delete constantIbGib.rel8ns.tjp; }
104
+ if (constantIbGib?.rel8ns?.identity) { delete constantIbGib.rel8ns.identity; }
105
+
106
+ // recalculate the gib hash
107
+ // constantIbGib.gib = await sha256v1({
108
+ constantIbGib.gib = await getGib({
109
+ ibGib: {
110
+ ib: constantIbGib.ib,
111
+ data: constantIbGib.data,
112
+ rel8ns: constantIbGib.rel8ns,
113
+ },
114
+ hasTjp: false,
115
+ });
116
+
117
+ return constantIbGib;
118
+ } catch (error) {
119
+ console.error(`${lc} ${error.message}`);
120
+ throw error;
121
+ }
122
+ }
123
+
124
+ /**
125
+ * Binaries require special handling, since they do not conform to the
126
+ * "normal" IbGib_V1 data structure per se. This stems from wanting to
127
+ * be able to have binaries (jpgs, gifs, etc. especially) able to
128
+ * sit on a server and be served as regular files.
129
+ *
130
+ * @returns string in expected template for binaries in this app.
131
+ */
132
+ export function getBinIb({ binHash, binExt }: { binHash: string, binExt?: string }): IbGibAddr {
133
+ return binExt ? `bin ${binHash} ${binExt}` : `bin ${binHash}`;
134
+ }
135
+ export function getBinHashAndExt({ addr }: { addr: IbGibAddr }): { binHash: string, binExt: string } {
136
+ const lc = `[${getBinHashAndExt.name}]`;
137
+ try {
138
+ if (!isBinary({ addr })) { throw new Error(`not a bin address (E: df0804d129bc4888bd6939cb76c5e0f6)`); }
139
+ const { ib } = getIbAndGib({ ibGibAddr: addr });
140
+ const ibPieces = ib.split(' ');
141
+ const binHash = ibPieces[1];
142
+ const binExt = ibPieces[2];
143
+ return { binHash, binExt };
144
+ } catch (error) {
145
+ console.error(`${lc} ${error.message}`);
146
+ throw error;
147
+ }
148
+ }
149
+
150
+ export function isBinary({
151
+ ibGib,
152
+ addr,
153
+ }: {
154
+ ibGib?: IbGib_V1,
155
+ addr?: IbGibAddr,
156
+ }): boolean {
157
+ const lc = `[${isBinary.name}]`;
158
+ try {
159
+ // probably overkill here, but...
160
+ if (!ibGib && !addr) { throw new Error(`either ibGib or addr required. (E: c935b51e773f41a2a547c556e9dc16c6)`); }
161
+ addr = addr || getIbGibAddr({ ibGib });
162
+ const { ib, gib } = getIbAndGib({ ibGibAddr: addr });
163
+ if (!ib) { return false; }
164
+ if (!gib) { return false; }
165
+ if (!ib.startsWith('bin ')) { return false; }
166
+ if (gib.length !== 64) {
167
+ console.warn(`${lc} gib length is not 64, so return false. But this may not be true if using another hash algorithm.`);
168
+ return false;
169
+ }
170
+ const ibPieces = ib.split(' ');
171
+ if (ibPieces.length !== 3) { return false; }
172
+ if (ibPieces[1] === "") { return false; }
173
+ return true;
174
+ } catch (error) {
175
+ console.error(`${lc} ${error.message}`);
176
+ throw error;
177
+ }
178
+ }
179
+
180
+ export async function hash16816({
181
+ s,
182
+ algorithm,
183
+ }: {
184
+ s: string,
185
+ algorithm: HashAlgorithm,
186
+ }): Promise<string> {
187
+ const lc = `[${hash16816.name}]`;
188
+ try {
189
+ let hashed: string = '';
190
+ for (let i = 0; i < 168; i++) {
191
+ hashed = await h.hash({ s, algorithm });
192
+ }
193
+ return hashed.slice(0, 16);
194
+ } catch (error) {
195
+ console.error(`${lc} ${error.message}`);
196
+ throw error;
197
+ }
198
+ }
199
+
200
+ export function getSpecialIbGibIb({ type }: { type: SpecialIbGibType }): Ib {
201
+ return `meta special ${type}`;
202
+ }
203
+
204
+ export function getSpecialTypeFromIb({ ib }: { ib: Ib }): SpecialIbGibType {
205
+ const lc = `[${getSpecialTypeFromIb.name}]`;
206
+ try {
207
+ if (logalot) { console.log(`${lc} starting... (I: c82ba222bd345ee6b695df4d63a23322)`); }
208
+ if (!ib) { throw new Error(`ib required (E: 08897145f7138e644fe01c4a59353322)`); }
209
+ if (!isSpecial({ ib })) { throw new Error(`ib is not special (E: 174aff63b992adff3ac2394643735922)`); }
210
+ const pieces = ib.split(' ');
211
+ if (pieces.length < 3) { throw new Error(`invalid ib. should be space-delimited in form of "meta special [type]" (E: ffd89e2cbe63427f98634ab897aab222)`); }
212
+ const specialType = pieces[2];
213
+ if (!Object.values(SpecialIbGibType).some(x => x === specialType)) {
214
+ console.warn(`unknown special type (${specialType}). This may be expected, but atow I am adding special types to the SpecialIbGibType enum-like. (W: f4e26c3ebb57fe49d69014a4ba32a922)`);
215
+ }
216
+ return (specialType as SpecialIbGibType);
217
+ } catch (error) {
218
+ console.error(`${lc} ${error.message}`);
219
+ throw error;
220
+ } finally {
221
+ if (logalot) { console.log(`${lc} complete.`); }
222
+ }
223
+ }
224
+
225
+ export function getSpecialIbGibAddr({ type }: { type: SpecialIbGibType }): string {
226
+ const ib = getSpecialIbGibIb({ type });
227
+ return `${ib}^${GIB}`;
228
+ }
229
+
230
+ export function getSpecialConfigKey({ type }: { type: SpecialIbGibType }): string {
231
+ return `config_key ${getSpecialIbGibAddr({ type })}`;
232
+ }
233
+
234
+ export function isSpecial({ ib, ibGib }: { ib?: Ib, ibGib?: IbGib_V1 }): boolean {
235
+ if (!ib && !ibGib?.ib) { throw new Error(`either ib or ibGib.ib required (E: b4cf539638d7966c2e351987f55e1a23)`); }
236
+ return (ib ?? ibGib?.ib)?.startsWith('meta special')!;
237
+ }
238
+
239
+ /**
240
+ * returns ib for a given root. ATOW this is simply "root {text}"
241
+ *
242
+ * @returns ib for the given rootText
243
+ */
244
+ export function getRootIb(rootText: string): string {
245
+ const lc = `[${getRootIb.name}]`;
246
+ if (!rootText) { throw new Error(`${lc} text required.`) }
247
+ return `root ${rootText}`;
248
+ }
249
+
250
+ /**
251
+ * Tags for this app have the form: tag [tagText]
252
+ *
253
+ * @param tagText e.g. "Favorites"
254
+ *
255
+ * @example
256
+ * For the Favorites tag, the ib would be "tag Favorites"
257
+ */
258
+ export function tagTextToIb(tagText: string): string {
259
+ const lc = `[${tagTextToIb.name}]`;
260
+ if (!tagText) { throw new Error(`${lc} tag required.`) }
261
+ return `tag ${tagText}`;
262
+ }
263
+
264
+ /**
265
+ * Living: has tjp and dna.
266
+ * Stones: does not have Dna, maybe has tjp.
267
+ *
268
+ * Splits the given `ibGibs` into two maps, one that includes the ibgibs that
269
+ * have a tjp (temporal junction point) AND dna ("living") and those that do not
270
+ * have both tjp AND dna ("stones").
271
+ *
272
+ * ## notes
273
+ *
274
+ * Having dna implies having a tjp, but the reverse is not necessarily true.
275
+ * Sometimes you want an ibgib that has a tjp so you can, e.g., reference the
276
+ * entire timeline easily. But at the same time you don't want to keep track of
277
+ * the transforms, perhaps this is because you don't want to be able to merge
278
+ * timelines.
279
+ */
280
+ export function splitPerTjpAndOrDna({
281
+ ibGibs,
282
+ filterPrimitives,
283
+ }: {
284
+ ibGibs: IbGib_V1[],
285
+ filterPrimitives?: boolean,
286
+ }): {
287
+ /** ibgibs have both tjp and dna */
288
+ mapWithTjp_YesDna: { [gib: string]: IbGib_V1 },
289
+ /** ibgibs have tjp but NO dna */
290
+ mapWithTjp_NoDna: { [gib: string]: IbGib_V1 },
291
+ /** ibgibs that have no tjp (and implicitly no dna) */
292
+ mapWithoutTjps: { [gib: string]: IbGib_V1 }
293
+ } {
294
+ const lc = `[${splitPerTjpAndOrDna.name}]`;
295
+ try {
296
+ const mapWithTjp_YesDna: { [gib: string]: IbGib_V1 } = {};
297
+ const mapWithTjp_NoDna: { [gib: string]: IbGib_V1 } = {};
298
+ const mapWithoutTjps: { [gib: string]: IbGib_V1 } = {};
299
+ // const mapLivingIbGibs: { [gib: string]: IbGib_V1 } = {};
300
+ // const mapStoneIbGibs: { [gib: string]: IbGib_V1 } = {};
301
+ const ibGibsTodo = filterPrimitives ?
302
+ ibGibs.filter(ibGib => ibGib.gib ?? ibGib.gib !== GIB) :
303
+ ibGibs;
304
+ ibGibsTodo.forEach(ibGib => {
305
+ if (hasTjp({ ibGib })) {
306
+ if ((ibGib.rel8ns?.dna ?? []).length > 0) {
307
+ mapWithTjp_YesDna[ibGib.gib!] = ibGib;
308
+ } else {
309
+ mapWithTjp_NoDna[ibGib.gib!] = ibGib;
310
+ }
311
+ } else {
312
+ mapWithoutTjps[ibGib.gib!] = ibGib;
313
+ }
314
+ });
315
+ return { mapWithTjp_YesDna, mapWithTjp_NoDna, mapWithoutTjps };
316
+ } catch (error) {
317
+ console.error(`${lc} ${error.message}`);
318
+ throw error;
319
+ }
320
+ }
321
+
322
+ /**
323
+ * Takes incoming `ibGibs`, filters out those that do
324
+ * not have tjps( i.e. non-timelines), and groups
325
+ * the timeline ibgibs by tjp in ascending order.
326
+ *
327
+ * This means that each map entry will be in the form:
328
+ * `[tjpAddr] => [ibgib0 (tjp), ibgib1, ibgib2, ..., ibgibN (latest)]`
329
+ *
330
+ * ## notes
331
+ *
332
+ * * sorts by `ibgib.data.n`. If this is undefined, will not sort in ascending
333
+ * order properly.
334
+ *
335
+ * @returns filtered, sorted map of incoming `ibGibs` [tjpAddr] => timeline [ibgib0 (tjp), ibgib1, ibgib2, ..., ibgibN (latest)]
336
+ */
337
+ export function getTimelinesGroupedByTjp({
338
+ ibGibs,
339
+ }: {
340
+ /**
341
+ * group of source ibGibs to filter/group/sort by tjp.
342
+ */
343
+ ibGibs: IbGib_V1[],
344
+ }): { [tjpAddr: string]: IbGib_V1[] } {
345
+ const lc = `[${getTimelinesGroupedByTjp.name}]`;
346
+ try {
347
+ if (logalot) { console.log(`${lc} starting...`); }
348
+
349
+ // pull out only the ibgibs in timelines (either is tjp or has tjp)
350
+ let { mapWithTjp_YesDna, mapWithTjp_NoDna } =
351
+ splitPerTjpAndOrDna({ ibGibs, filterPrimitives: true });
352
+ const mapIbGibsWithTjp = { ...mapWithTjp_YesDna, ...mapWithTjp_NoDna };
353
+ const ibGibsWithTjp = Object.values(mapIbGibsWithTjp);
354
+
355
+ const mapTjpTimelines_Ascending = groupBy({
356
+ items: ibGibsWithTjp,
357
+ keyFn: x => {
358
+ // x.data?.isTjp ? getIbGibAddr({ ibGib: x }) : (x.rel8ns?.tjp[0] ?? '') // converting this untested...hmm
359
+ if (x.data?.isTjp) {
360
+ return getIbGibAddr({ ibGib: x });
361
+ } else if (x.rel8ns?.tjp) {
362
+ return x.rel8ns?.tjp[0] ?? '';
363
+ } else {
364
+ if (logalot) { console.log(`${lc} neither isTjp nor x.rel8ns.tjp truthy (I: ec9a5597bf53dec1bd3d83350abbf823)`); }
365
+ return '';
366
+ }
367
+
368
+ }
369
+ });
370
+
371
+ if (logalot) { console.log(`${lc} sorting (ascending) ibGibsWithTjpGroupedByTjpAddr: ${h.pretty(mapTjpTimelines_Ascending)} (I: 9b9fff5ce61444a6cb06d62db9a99422)`); }
372
+ Object.entries(mapTjpTimelines_Ascending).forEach(([_tjpAddr, timeline]) => {
373
+ if (timeline.some(ibGib => ibGib.data?.n === undefined)) {
374
+ console.warn(`${lc} timeline includes ibgibs with ibGib.data?.n === undefined (W: cab9a6b64a38c4279fe82c3569bbab22)`);
375
+ }
376
+ // sort mutates array in place
377
+ timeline.sort((a, b) => (a.data?.n ?? -1) > (b.data?.n ?? -1) ? 1 : -1); // sorts ascending, e.g., 0,1,2...[Highest]
378
+ });
379
+ if (logalot) { console.log(`${lc} after sort ibGibsWithTjpGroupedByTjpAddr: ${h.pretty(mapTjpTimelines_Ascending)} (I: 9b9fff5ce61444a6cb06d62db9a99422)`); }
380
+
381
+ return mapTjpTimelines_Ascending; // ascending
382
+ } catch (error) {
383
+ console.error(`${lc} ${error.message}`);
384
+ throw error;
385
+ } finally {
386
+ if (logalot) { console.log(`${lc} complete.`); }
387
+ }
388
+ }
389
+
390
+ /**
391
+ * Helper function that checks the given `ibGib` to see if it
392
+ * either has a tjp or is a tjp itself.
393
+ *
394
+ * ## notes
395
+ *
396
+ * Only unique ibGibs are meant to have tjps, or rather, if an
397
+ * ibGib timeline is expected to be unique over "time", then the
398
+ * tjp is an extremely convenient mechanism that provides a
399
+ * "name" for that timeline.
400
+ *
401
+ * Otherwise, if they are not unique, then successive "different"
402
+ * timelines cannot be easily referenced by their first unique
403
+ * frame in time, making it much harder to pub/sub updates among
404
+ * other things. (If there are no unique frames, then they are
405
+ * the same ibGib.)
406
+ *
407
+ * ## tjp = temporal junction point
408
+ *
409
+ * I've written elsewhere on this as well. Refer to B2tF2.
410
+ *
411
+ * @returns true if the ibGib has/is a tjp, else false
412
+ */
413
+ export function hasTjp({ ibGib }: { ibGib: IbGib_V1 }): boolean {
414
+ const lc = `[${hasTjp.name}]`;
415
+
416
+ if (!ibGib) {
417
+ console.warn(`${lc} ibGib falsy. (W: 884178562f5b4f15933ac4d98db74cc6)`);
418
+ return false;
419
+ }
420
+
421
+ if (ibGib.data?.isTjp || (ibGib.rel8ns?.tjp?.length ?? 0) > 0) {
422
+ return true;
423
+ }
424
+
425
+ // dna transforms do not have tjp
426
+ const dnaPrimitives = ['fork^gib', 'mut8^gib', 'rel8^gib'];
427
+ if ((ibGib.rel8ns?.ancestor ?? []).some(x => dnaPrimitives.includes(x))) {
428
+ return false;
429
+ }
430
+
431
+ if (!ibGib.gib) {
432
+ console.warn(`${lc} ibGib.gib falsy. (W: 6400d780822b44d992846f1196509be3)`);
433
+ return false;
434
+ }
435
+ if (ibGib.gib.includes(cTsGib.GIB_DELIMITER)) {
436
+ return true;
437
+ }
438
+
439
+ if (ibGib.gib === cTsGib.GIB) {
440
+ // primitive
441
+ return false;
442
+ }
443
+
444
+ // use more expensive getGibInfo call.
445
+ // could possibly just return false at this point, but since gib info
446
+ // would change if we change our standards for gib, this is nicer.
447
+ const gibInfo = getGibInfo({ ibGibAddr: getIbGibAddr({ ibGib }) });
448
+ return gibInfo.tjpGib ? true : false;
449
+ }
450
+
451
+ export function hasDna({ ibGib }: { ibGib: IbGib_V1 }): boolean {
452
+ const lc = `[${hasDna.name}]`;
453
+
454
+ if (!ibGib) {
455
+ console.warn(`${lc} ibGib falsy. (W: 5fd19751f5c84da59d83dd33487ed859)`);
456
+ return false;
457
+ }
458
+
459
+ return (ibGib.rel8ns?.dna ?? []).length > 0;
460
+ }
461
+
462
+ /**
463
+ * Extracts the tjp addr from the ibgib record. If there is no tjp addr found,
464
+ * then refers to `defaultIfNone` arg to determine if it returns undefined or
465
+ * the incoming ibgib's addr.
466
+ * @returns extracted tjp addr or undefined, depending on if found and defaultIfNone value
467
+ */
468
+ export function getTjpAddr({
469
+ ibGib,
470
+ defaultIfNone = 'undefined',
471
+ }: {
472
+ ibGib: IbGib_V1,
473
+ defaultIfNone?: 'incomingAddr' | 'undefined',
474
+ }): IbGibAddr | undefined {
475
+ const lc = `[${getTjpAddr.name}]`;
476
+ try {
477
+ const tjpMap = getTjpAddrs({ ibGibs: [ibGib], defaultIfNone });
478
+ return tjpMap && Object.keys(tjpMap).length === 1 ? Object.values(tjpMap)[0] : undefined;
479
+ } catch (error) {
480
+ console.error(`${lc} ${error.message}`);
481
+ throw error;
482
+ }
483
+ }
484
+
485
+ /**
486
+ * builds a map of the given ibgib's addrs to each's corresponding tjp addr.
487
+ *
488
+ * @returns a map of ibgib addr -> tjp addr
489
+ */
490
+ export function getTjpAddrs({
491
+ ibGibs,
492
+ defaultIfNone = 'undefined',
493
+ }: {
494
+ ibGibs: IbGib_V1[],
495
+ defaultIfNone?: 'incomingAddr' | 'undefined',
496
+ }): { [ibGibAddr: IbGibAddr]: IbGibAddr | undefined } {
497
+ const lc = `[${getTjpAddrs.name}]`;
498
+ try {
499
+ const resultMap: { [ibGibAddr: IbGibAddr]: IbGibAddr | undefined } = {};
500
+
501
+ ibGibs.forEach(ibGib => {
502
+ let ibGibAddr = getIbGibAddr({ ibGib });
503
+ let tjpAddr: IbGibAddr | undefined;
504
+ if (ibGib.rel8ns?.tjp?.length ?? 0 > 0) {
505
+ // get the last tjp addr atow
506
+ tjpAddr = ibGib.rel8ns!.tjp![ibGib.rel8ns!.tjp!.length - 1];
507
+ } else if (ibGib.data?.isTjp || defaultIfNone === 'incomingAddr') {
508
+ // either the incoming addr is the tjp or we're defaulting to it per defaultIfNone arg
509
+ tjpAddr = ibGibAddr;
510
+ } else {
511
+ // explicitly set to undefined per defaultIfNone arg
512
+ tjpAddr = undefined;
513
+ }
514
+ resultMap[ibGibAddr] = tjpAddr;
515
+ });
516
+
517
+ return resultMap;
518
+ } catch (error) {
519
+ console.error(`${lc} ${error.message}`);
520
+ throw error;
521
+ }
522
+ }
523
+
524
+
525
+ /**
526
+ * Combines two maps/arrays into a single one with some very basic, naive merge rules:
527
+ *
528
+ * 1. If a key exists in only one map, then it will be included in the output map.
529
+ * 2. If a key exists in both maps and the type is array or map, then these will be recursively merged.
530
+ * 3. If a key exists in both maps but is not an array or map, the dominant map's value wins.
531
+ *
532
+ * ## future
533
+ *
534
+ * In the future, if we want to keep these kinds of things around and be more
535
+ * specific about mergers, we can always rel8 a merge strategy ibgib to be
536
+ * referred to when performing merger.
537
+ */
538
+ export function mergeMapsOrArrays_Naive<T extends {} | any[]>({
539
+ dominant,
540
+ recessive,
541
+ }: {
542
+ /**
543
+ * when two keys are not arrays or maps themselves, this one's value is
544
+ * chosen for output.
545
+ */
546
+ dominant: T,
547
+ /**
548
+ * when two keys are not arrays or maps themselves, this one's value is NOT
549
+ * chosen for output.
550
+ */
551
+ recessive: T,
552
+ }): T {
553
+ const lc = `[${mergeMapsOrArrays_Naive.name}]`;
554
+ try {
555
+ if (Array.isArray(dominant) && Array.isArray(recessive)) {
556
+ // arrays
557
+ const output: any[] = h.clone(dominant) as any[];
558
+ let warned = false;
559
+ (recessive as []).forEach((recessiveItem: any) => {
560
+ if (typeof (recessiveItem) === 'string') {
561
+ if (!output.includes(recessiveItem)) { output.push(recessiveItem); }
562
+ } else {
563
+ if (!warned) {
564
+ console.warn(`${lc} merging arrays of non-string elements. (W: d8ab113064834abc8eb5fe6c4cf87ba3)`);
565
+ warned = true;
566
+ }
567
+ // we'll check the stringified version of recessive item against
568
+ // the stringified dominant item.
569
+ const xString = JSON.stringify(recessiveItem);
570
+ if (!output.some(o => JSON.stringify(o) === xString)) {
571
+ output.push(recessiveItem);
572
+ }
573
+ }
574
+ });
575
+ return (output as T);
576
+ } else if (typeof (dominant) === 'object' && typeof (recessive) === 'object') {
577
+ // maps
578
+ const output: { [key: string]: any } = {};
579
+ const dominantKeys: string[] = Object.keys(dominant);
580
+ const recessiveKeys: string[] = Object.keys(recessive);
581
+ dominantKeys.forEach((key: string) => {
582
+ if (recessiveKeys.includes(key)) {
583
+
584
+ // naive merge for key that exists in both dominant & recessive
585
+ if (Array.isArray((dominant as any)[key]) && Array.isArray((recessive as any)[key])) {
586
+ // recursive call if both arrays
587
+ output[key] = mergeMapsOrArrays_Naive<any[]>({
588
+ dominant: (dominant as any)[key],
589
+ recessive: (recessive as any)[key],
590
+ });
591
+ } else if (
592
+ !!(dominant as any)[key] && !Array.isArray((dominant as any)[key]) && typeof ((dominant as any)[key]) === 'object' &&
593
+ !!(recessive as any)[key] && !!Array.isArray((recessive as any)[key]) && typeof ((recessive as any)[key]) === 'object'
594
+ ) {
595
+ // recursive call if both objects
596
+ output[key] = mergeMapsOrArrays_Naive<{}>({
597
+ dominant: (dominant as any)[key],
598
+ recessive: (recessive as any)[key],
599
+ });
600
+ } else {
601
+ (output as any)[key] = (dominant as any)[key];
602
+ }
603
+ } else {
604
+ output[key] = (dominant as any)[key];
605
+ }
606
+ });
607
+
608
+ return output as T;
609
+ } else {
610
+ // ? unknown matching of dominant and recessive
611
+ console.warn(`${lc} unknown values or value types do not match. Both should either be an array or map. Dominant one wins categorically without any merging. (W: 3690ea19b81a4b89b98c1940637df62c)`);
612
+ return (dominant as T);
613
+ }
614
+ } catch (error) {
615
+ console.error(`${lc} ${error.message}`);
616
+ throw error;
617
+ }
618
+ };
619
+
620
+ /**
621
+ * Returns true if the given {@param ibGib} is the temporal junction
622
+ * point for a given ibGib timeline.
623
+ */
624
+ export async function isTjp_Naive({
625
+ ibGib,
626
+ naive = true,
627
+ }: {
628
+ ibGib: IbGib_V1<any>,
629
+ naive?: boolean,
630
+ }): Promise<boolean> {
631
+ const lc = `[${isTjp_Naive.name}]`;
632
+ try {
633
+ if (!ibGib) { throw new Error('ibGib required.'); }
634
+ if (naive) {
635
+ if (ibGib.data) {
636
+ if (ibGib.data.isTjp) { return true; }
637
+ if (!ibGib.rel8ns) {
638
+ if (logalot) { console.log(`${lc} ibGib.rel8ns falsy (I: c69c9e78b34845311ce7c674d7195622)`); }
639
+ return false;
640
+ }
641
+ if (ibGib.rel8ns.past && ibGib.rel8ns.past.length > 0) { return false; }
642
+ if (ibGib.rel8ns.past && ibGib.rel8ns.past.length === 0) { return true; }
643
+ return false;
644
+ } else {
645
+ throw new Error('loaded ibGib required (data).');
646
+ }
647
+ } else {
648
+ throw new Error('only naive implemented right now.');
649
+ }
650
+ } catch (error) {
651
+ console.error(`${lc} ${error.message}`);
652
+ throw error;
653
+ }
654
+ }
655
+
656
+ export function toDto<TData, TRel8ns extends IbGibRel8ns_V1 = IbGibRel8ns_V1>({
657
+ ibGib,
658
+ }: {
659
+ ibGib: IbGib_V1,
660
+ }): IbGib_V1<TData, TRel8ns> {
661
+ const lc = `[${toDto.name}]`;
662
+ if (!ibGib.ib) { console.warn(`${lc} ibGib.ib is falsy. (W: e60e41c2a1fc48268379d88ce13cb77b)`); }
663
+ if (!ibGib.gib) { console.warn(`${lc} ibGib.gib is falsy. (W: fb3889cbf0684ae4ac51e48f28570377)`); }
664
+
665
+ let dtoIbGib: IbGib_V1<TData, TRel8ns> = { ib: (ibGib.ib || '').slice() };
666
+ if (ibGib.gib) { dtoIbGib.gib = ibGib.gib.slice(); };
667
+ if (ibGib.data) { dtoIbGib.data = h.clone(ibGib.data); }
668
+ if (ibGib.rel8ns) { dtoIbGib.rel8ns = h.clone(ibGib.rel8ns); }
669
+
670
+ return dtoIbGib;
671
+ }