atom.io 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/data/dist/index.cjs +614 -0
  2. package/data/dist/index.cjs.map +1 -0
  3. package/data/dist/index.d.cts +158 -0
  4. package/data/dist/index.d.ts +118 -1
  5. package/data/dist/index.js +551 -30
  6. package/data/dist/index.js.map +1 -1
  7. package/data/dist/metafile-cjs.json +1 -0
  8. package/data/dist/metafile-esm.json +1 -0
  9. package/data/package.json +4 -3
  10. package/data/src/index.ts +1 -0
  11. package/data/src/join.ts +450 -0
  12. package/data/src/struct-family.ts +34 -24
  13. package/data/src/struct.ts +6 -8
  14. package/dist/index.cjs +257 -0
  15. package/dist/index.cjs.map +1 -0
  16. package/dist/{index.d.mts → index.d.cts} +10 -11
  17. package/dist/index.d.ts +10 -11
  18. package/dist/index.js +63 -104
  19. package/dist/index.js.map +1 -1
  20. package/dist/metafile-cjs.json +1 -0
  21. package/dist/metafile-esm.json +1 -0
  22. package/internal/dist/{index.mjs → index.cjs} +692 -503
  23. package/internal/dist/index.cjs.map +1 -0
  24. package/internal/dist/{index.d.mts → index.d.cts} +114 -105
  25. package/internal/dist/index.d.ts +114 -105
  26. package/internal/dist/index.js +628 -563
  27. package/internal/dist/index.js.map +1 -1
  28. package/internal/dist/metafile-cjs.json +1 -0
  29. package/internal/dist/metafile-esm.json +1 -0
  30. package/internal/package.json +4 -3
  31. package/internal/src/atom/create-atom.ts +29 -16
  32. package/internal/src/atom/delete-atom.ts +25 -6
  33. package/internal/src/atom/is-default.ts +4 -17
  34. package/internal/src/caching.ts +28 -23
  35. package/internal/src/families/create-atom-family.ts +3 -2
  36. package/internal/src/families/create-readonly-selector-family.ts +1 -1
  37. package/internal/src/families/create-selector-family.ts +4 -4
  38. package/internal/src/index.ts +2 -1
  39. package/internal/src/mutable/create-mutable-atom-family.ts +2 -2
  40. package/internal/src/mutable/create-mutable-atom.ts +1 -2
  41. package/internal/src/mutable/get-json-family.ts +22 -0
  42. package/internal/src/mutable/get-json-token.ts +1 -0
  43. package/internal/src/mutable/index.ts +1 -0
  44. package/internal/src/mutable/tracker-family.ts +1 -2
  45. package/internal/src/mutable/tracker.ts +8 -6
  46. package/internal/src/mutable/transceiver.ts +2 -0
  47. package/internal/src/not-found-error.ts +27 -0
  48. package/internal/src/operation.ts +2 -3
  49. package/internal/src/{get-state-internal.ts → read-or-compute-value.ts} +13 -6
  50. package/internal/src/selector/create-selector.ts +6 -7
  51. package/internal/src/selector/delete-selector.ts +37 -0
  52. package/internal/src/selector/index.ts +2 -1
  53. package/internal/src/selector/register-selector.ts +7 -7
  54. package/internal/src/set-state/copy-mutable-in-transaction.ts +3 -2
  55. package/internal/src/set-state/emit-update.ts +1 -3
  56. package/internal/src/set-state/evict-downstream.ts +6 -8
  57. package/internal/src/set-state/index.ts +1 -1
  58. package/internal/src/set-state/{set-state-internal.ts → set-atom-or-selector.ts} +2 -3
  59. package/internal/src/set-state/set-atom.ts +5 -6
  60. package/internal/src/store/store.ts +1 -1
  61. package/internal/src/store/withdraw-new-family-member.ts +6 -6
  62. package/internal/src/subscribe/recall-state.ts +1 -2
  63. package/internal/src/subscribe/subscribe-to-root-atoms.ts +2 -2
  64. package/internal/src/timeline/add-atom-to-timeline.ts +5 -16
  65. package/internal/src/timeline/{timeline-internal.ts → create-timeline.ts} +4 -5
  66. package/internal/src/timeline/index.ts +2 -2
  67. package/internal/src/timeline/time-travel.ts +89 -0
  68. package/internal/src/transaction/{transaction-internal.ts → create-transaction.ts} +6 -5
  69. package/internal/src/transaction/index.ts +2 -3
  70. package/introspection/dist/{index.mjs → index.cjs} +54 -29
  71. package/introspection/dist/index.cjs.map +1 -0
  72. package/introspection/dist/{index.d.mts → index.d.cts} +2 -2
  73. package/introspection/dist/index.d.ts +2 -2
  74. package/introspection/dist/index.js +32 -49
  75. package/introspection/dist/index.js.map +1 -1
  76. package/introspection/dist/metafile-cjs.json +1 -0
  77. package/introspection/dist/metafile-esm.json +1 -0
  78. package/introspection/package.json +4 -3
  79. package/introspection/src/attach-introspection-states.ts +2 -2
  80. package/introspection/src/attach-selector-index.ts +8 -4
  81. package/json/dist/{index.mjs → index.cjs} +20 -7
  82. package/json/dist/{index.mjs.map → index.cjs.map} +1 -1
  83. package/json/dist/{index.d.mts → index.d.cts} +1 -1
  84. package/json/dist/index.d.ts +1 -1
  85. package/json/dist/index.js +6 -19
  86. package/json/dist/index.js.map +1 -1
  87. package/json/dist/metafile-cjs.json +1 -0
  88. package/json/dist/metafile-esm.json +1 -0
  89. package/json/package.json +4 -3
  90. package/package.json +48 -47
  91. package/react/dist/index.cjs +59 -0
  92. package/react/dist/index.cjs.map +1 -0
  93. package/react/dist/index.js +20 -42
  94. package/react/dist/index.js.map +1 -1
  95. package/react/dist/metafile-cjs.json +1 -0
  96. package/react/dist/metafile-esm.json +1 -0
  97. package/react/package.json +4 -3
  98. package/react/src/store-hooks.ts +8 -2
  99. package/react-devtools/dist/{index.mjs → index.cjs} +286 -240
  100. package/react-devtools/dist/index.cjs.map +1 -0
  101. package/react-devtools/dist/{index.d.mts → index.d.cts} +29 -17
  102. package/react-devtools/dist/index.d.ts +29 -17
  103. package/react-devtools/dist/index.js +251 -273
  104. package/react-devtools/dist/index.js.map +1 -1
  105. package/react-devtools/dist/metafile-cjs.json +1 -0
  106. package/react-devtools/dist/metafile-esm.json +1 -0
  107. package/react-devtools/package.json +4 -3
  108. package/react-devtools/src/StateEditor.tsx +8 -8
  109. package/realtime-client/dist/{index.mjs → index.cjs} +50 -21
  110. package/realtime-client/dist/index.js +20 -49
  111. package/realtime-client/dist/metafile-cjs.json +1 -0
  112. package/realtime-client/dist/metafile-esm.json +1 -0
  113. package/realtime-client/package.json +4 -3
  114. package/realtime-react/dist/index.cjs +99 -0
  115. package/realtime-react/dist/index.js +35 -66
  116. package/realtime-react/dist/metafile-cjs.json +1 -0
  117. package/realtime-react/dist/metafile-esm.json +1 -0
  118. package/realtime-react/package.json +4 -3
  119. package/realtime-server/dist/{index.mjs → index.cjs} +67 -40
  120. package/realtime-server/dist/index.js +39 -66
  121. package/realtime-server/dist/metafile-cjs.json +1 -0
  122. package/realtime-server/dist/metafile-esm.json +1 -0
  123. package/realtime-server/package.json +4 -3
  124. package/realtime-testing/dist/{index.mjs → index.cjs} +54 -23
  125. package/realtime-testing/dist/index.js +22 -53
  126. package/realtime-testing/dist/metafile-cjs.json +1 -0
  127. package/realtime-testing/dist/metafile-esm.json +1 -0
  128. package/realtime-testing/package.json +4 -3
  129. package/src/atom.ts +6 -8
  130. package/src/dispose.ts +18 -0
  131. package/src/get-state.ts +16 -0
  132. package/src/index.ts +3 -1
  133. package/src/logger.ts +1 -1
  134. package/src/selector.ts +3 -3
  135. package/src/set-state.ts +22 -0
  136. package/src/silo.ts +7 -8
  137. package/src/timeline.ts +6 -11
  138. package/src/transaction.ts +2 -2
  139. package/transceivers/set-rtx/dist/{index.mjs → index.cjs} +40 -36
  140. package/transceivers/set-rtx/dist/index.cjs.map +1 -0
  141. package/transceivers/set-rtx/dist/{index.d.mts → index.d.cts} +2 -1
  142. package/transceivers/set-rtx/dist/index.d.ts +2 -1
  143. package/transceivers/set-rtx/dist/index.js +37 -37
  144. package/transceivers/set-rtx/dist/index.js.map +1 -1
  145. package/transceivers/set-rtx/dist/metafile-cjs.json +1 -0
  146. package/transceivers/set-rtx/dist/metafile-esm.json +1 -0
  147. package/transceivers/set-rtx/package.json +4 -3
  148. package/transceivers/set-rtx/src/set-rtx.ts +29 -26
  149. package/data/dist/index.d.mts +0 -41
  150. package/data/dist/index.mjs +0 -82
  151. package/data/dist/index.mjs.map +0 -1
  152. package/dist/index.mjs +0 -215
  153. package/dist/index.mjs.map +0 -1
  154. package/internal/dist/index.mjs.map +0 -1
  155. package/internal/src/set-state/set-selector-state.ts +0 -8
  156. package/internal/src/timeline/time-travel-internal.ts +0 -109
  157. package/introspection/dist/index.mjs.map +0 -1
  158. package/react/dist/index.mjs +0 -29
  159. package/react/dist/index.mjs.map +0 -1
  160. package/react-devtools/dist/index.mjs.map +0 -1
  161. package/realtime-react/dist/index.mjs +0 -68
  162. package/src/get-set.ts +0 -48
  163. package/transceivers/set-rtx/dist/index.mjs.map +0 -1
  164. /package/react/dist/{index.d.mts → index.d.cts} +0 -0
  165. /package/realtime-client/dist/{index.mjs.map → index.cjs.map} +0 -0
  166. /package/realtime-client/dist/{index.d.mts → index.d.cts} +0 -0
  167. /package/realtime-react/dist/{index.mjs.map → index.cjs.map} +0 -0
  168. /package/realtime-react/dist/{index.d.mts → index.d.cts} +0 -0
  169. /package/realtime-server/dist/{index.mjs.map → index.cjs.map} +0 -0
  170. /package/realtime-server/dist/{index.d.mts → index.d.cts} +0 -0
  171. /package/realtime-testing/dist/{index.mjs.map → index.cjs.map} +0 -0
  172. /package/realtime-testing/dist/{index.d.mts → index.d.cts} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/dict.ts","../src/struct.ts","../src/struct-family.ts","../src/until.ts"],"names":["IMPLICIT","createSelector","capitalize"],"mappings":";AAEA,SAAS,UAAU,sBAAsB;AAGlC,SAAS,KACf,WAIA,OAIA,QAAe,SAAS,OAC2C;AACnE,SAAO;AAAA,IACN;AAAA,MACC,KAAK,GAAG,UAAU,GAAG;AAAA,MACrB,KAAK,CAAC,EAAE,IAAI,MAAM;AACjB,cAAM,OAAO,IAAI,KAAK;AACtB,eAAO,KAAK,OAAO,CAAC,KAAK,QAAQ;AAChC,cAAI,GAAG,IAAI,IAAI,UAAU,GAAG,CAAC;AAC7B,iBAAO;AAAA,QACR,GAAG,CAAC,CAAQ;AAAA,MACb;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;;;AC5BA,SAAS,YAAAA,iBAAgB;AAEzB,SAAS,YAAY,kBAAAC,uBAAsB;AAE3C,IAAM,aAAa,CAAC,QAAgB,IAAI,CAAC,EAAE,YAAY,IAAI,IAAI,MAAM,CAAC;AAE/D,SAAS,OAI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A,EACR,GAAG,CAAC,CAAQ;AACZ,QAAM,kBAAkB,qBAAqB;AAAA,IAC5C,KAAK,QAAQ;AAAA,IACb,KACC,CAAC,OACD,CAAC,EAAE,IAAI,MAAM;AACZ,aAAO,OAAO,KAAK,QAAQ,OAAO,EAAE,OAAO,CAAC,KAAK,WAAW;AAC3D,YAAI,MAAM,IAAI,IAAK,MAAc,WAAW,QAAQ,KAAK,MAAM,CAAC,EAAE,EAAE,CAAC;AACrE,eAAO;AAAA,MACR,GAAG,CAAC,CAAQ;AAAA,IACb;AAAA,EACF,CAAC;AACD,SAAO,CAAC,OAAO,eAAe;AAC/B;;;ACtCO,SAAS,MAAS,UAAuB,UAAgB;AAC/D,MAAI,oBAAoB,SAAS;AAChC,WAAO;AAAA,EACR;AACA,SAAO;AACR","sourcesContent":["import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, createSelector } from \"atom.io/internal\"\nimport type { Json, Stringified } from \"atom.io/json\"\n\nexport function dict<State, Key extends Json.Serializable>(\n\tfindState:\n\t\t| AtomIO.AtomFamily<State, Key>\n\t\t| AtomIO.ReadonlySelectorFamily<State, Key>\n\t\t| AtomIO.SelectorFamily<State, Key>,\n\tindex:\n\t\t| AtomIO.AtomToken<Key[]>\n\t\t| AtomIO.ReadonlySelectorToken<Key[]>\n\t\t| AtomIO.SelectorToken<Key[]>,\n\tstore: Store = IMPLICIT.STORE,\n): AtomIO.ReadonlySelectorToken<{ [K in Stringified<Key>]: State }> {\n\treturn createSelector(\n\t\t{\n\t\t\tkey: `${findState.key}Dict`,\n\t\t\tget: ({ get }) => {\n\t\t\t\tconst keys = get(index)\n\t\t\t\treturn keys.reduce((acc, key) => {\n\t\t\t\t\tacc[key] = get(findState(key))\n\t\t\t\t\treturn acc\n\t\t\t\t}, {} as any)\n\t\t\t},\n\t\t},\n\t\tundefined,\n\t\tstore,\n\t)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\n\nimport { createAtom, createSelector } from \"atom.io/internal\"\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\n\nexport function struct<\n\tStruct extends { [key: string]: unknown },\n\tKey extends string,\n>(\n\toptions: {\n\t\tkey: Key\n\t\tdefault: Struct\n\t},\n\tstore: Store = IMPLICIT.STORE,\n): [\n\t{\n\t\t[K in\n\t\t\tkeyof Struct as `${Key}${Capitalize<K & string>}State`]: AtomIO.AtomToken<\n\t\t\tStruct[K]\n\t\t>\n\t},\n\tAtomIO.ReadonlySelectorToken<Struct>,\n] {\n\tconst atoms: {\n\t\t[K in\n\t\t\tkeyof Struct as `${Key}${Capitalize<K & string>}State`]: AtomIO.AtomToken<\n\t\t\tStruct[K]\n\t\t>\n\t} = Object.keys(options.default).reduce((acc, key) => {\n\t\tconst atomName = options.key + capitalize(key) + `State`\n\t\tacc[atomName] = createAtom(\n\t\t\t{\n\t\t\t\tkey: `${options.key}.${key}`,\n\t\t\t\tdefault: options.default[key],\n\t\t\t},\n\t\t\tundefined,\n\t\t\tstore,\n\t\t)\n\t\treturn acc\n\t}, {} as any)\n\tconst structState = createSelector(\n\t\t{\n\t\t\tkey: options.key,\n\t\t\tget: ({ get }) => {\n\t\t\t\treturn Object.keys(options.default).reduce((acc, key) => {\n\t\t\t\t\tacc[key] = get(atoms[options.key + capitalize(key) + `State`])\n\t\t\t\t\treturn acc\n\t\t\t\t}, {} as any)\n\t\t\t},\n\t\t},\n\t\tundefined,\n\t\tstore,\n\t)\n\treturn [atoms, structState]\n}\n","import type * as AtomIO from \"atom.io\"\nimport { createAtomFamily, createSelectorFamily } from \"atom.io/internal\"\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\nconst nameFamily = (topKey: string, subKey: string) =>\n\t`find` + capitalize(topKey) + capitalize(subKey) + `State`\n\nexport function structFamily<\n\tStruct extends object,\n\tKey extends string,\n>(options: {\n\tkey: Key\n\tdefault: Struct\n}): [\n\t{\n\t\t[K in\n\t\t\tkeyof Struct as `find${Capitalize<Key & string>}${Capitalize<\n\t\t\t\tK & string\n\t\t\t>}State`]: AtomIO.AtomFamily<Struct[K], string>\n\t},\n\tAtomIO.ReadonlySelectorFamily<Struct>,\n] {\n\tconst atoms: {\n\t\t[K in\n\t\t\tkeyof Struct as `find${Capitalize<Key & string>}${Capitalize<\n\t\t\t\tK & string\n\t\t\t>}State`]: AtomIO.AtomFamily<Struct[K], string>\n\t} = Object.keys(options.default).reduce((acc, subKey) => {\n\t\tconst atomFamilyName = nameFamily(options.key, subKey)\n\t\tacc[atomFamilyName] = createAtomFamily({\n\t\t\tkey: `${options.key}.${subKey}`,\n\t\t\tdefault: (options.default as any)[subKey],\n\t\t})\n\t\treturn acc\n\t}, {} as any)\n\tconst findStructState = createSelectorFamily({\n\t\tkey: options.key,\n\t\tget:\n\t\t\t(id) =>\n\t\t\t({ get }) => {\n\t\t\t\treturn Object.keys(options.default).reduce((acc, subKey) => {\n\t\t\t\t\tacc[subKey] = get((atoms as any)[nameFamily(options.key, subKey)](id))\n\t\t\t\t\treturn acc\n\t\t\t\t}, {} as any)\n\t\t\t},\n\t})\n\treturn [atoms, findStructState]\n}\n","export type Loadable<T> = Promise<T> | T\nexport type Fated<T, E extends Error = Error> = Loadable<E | T>\n\n/**\n * Utility for handling loadable values\n * @param loadable Loadable value\n * @param fallback Fallback value until Loadable is resolved\n * @returns Fallback value if your loadable is a promise, otherwise the loadable's resolved value\n */\nexport function until<T>(loadable: Loadable<T>, fallback: T): T {\n\tif (loadable instanceof Promise) {\n\t\treturn fallback\n\t}\n\treturn loadable\n}\n"]}
1
+ {"version":3,"sources":["../src/dict.ts","../src/join.ts","../../../rel8/junction/src/junction.ts","../src/struct.ts","../src/struct-family.ts","../src/until.ts"],"names":["IMPLICIT","a","b","createSelector","capitalize","createAtomFamily","createSelectorFamily"],"mappings":";AAEA,SAAS,UAAU,sBAAsB;AAGlC,SAAS,KACf,WAIA,OAIA,QAA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AAE,OAAO,CAAC,KAAK,WAAW;AACxD,UAAM,iBAAiB,WAAW,QAAQ,KAAK,MAAM;AACrD,QAAI,cAAc,IAAIC;AAAA,MACrB;AAAA,QACC,KAAK,GAAG,QAAQ,GAAG,IAAI,MAAM;AAAA,QAC7B,SAAU,QAAQ,QAAgB,MAAM;AAAA,MACzC;AAAA,MACAL,UAAS;AAAA,IACV;AACA,WAAO;AAAA,EACR,GAAG,CAAC,CAAQ;AACZ,QAAM,kBAAkBM;AAAA,IACvB;AAAA,MACC,KAAK,QAAQ;AAAA,MACb,KACC,CAAC,OACD,CAAC,EAAE,IAAI,MAAM;AACZ,eAAO,OAAO,KAAK,QAAQ,OAAO,EAAE,OAAO,CAAC,KAAK,WAAW;AAC3D,cAAI,MAAM,IAAI;AAAA,YACZ,MAAc,WAAW,QAAQ,KAAK,MAAM,CAAC,EAAE,EAAE;AAAA,UACnD;AACA,iBAAO;AAAA,QACR,GAAG,CAAC,CAAQ;AAAA,MACb;AAAA,IACF;AAAA,IACAN,UAAS;AAAA,EACV;AACA,SAAO,CAAC,OAAO,eAAe;AAC/B;;;AChDO,SAAS,MAAS,UAAuB,UAAgB;AAC/D,MAAI,oBAAoB,SAAS;AAChC,WAAO;AAAA,EACR;AACA,SAAO;AACR","sourcesContent":["import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, createSelector } from \"atom.io/internal\"\nimport type { Json, Stringified } from \"atom.io/json\"\n\nexport function dict<State, Key extends Json.Serializable>(\n\tfindState:\n\t\t| AtomIO.AtomFamily<State, Key>\n\t\t| AtomIO.ReadonlySelectorFamily<State, Key>\n\t\t| AtomIO.SelectorFamily<State, Key>,\n\tindex:\n\t\t| AtomIO.AtomToken<Key[]>\n\t\t| AtomIO.ReadonlySelectorToken<Key[]>\n\t\t| AtomIO.SelectorToken<Key[]>,\n\tstore: Store = IMPLICIT.STORE,\n): AtomIO.ReadonlySelectorToken<{ [K in Stringified<Key>]: State }> {\n\treturn createSelector(\n\t\t{\n\t\t\tkey: `${findState.key}Dict`,\n\t\t\tget: ({ get }) => {\n\t\t\t\tconst keys = get(index)\n\t\t\t\treturn keys.reduce((acc, key) => {\n\t\t\t\t\tacc[key] = get(findState(key))\n\t\t\t\t\treturn acc\n\t\t\t\t}, {} as any)\n\t\t\t},\n\t\t},\n\t\tundefined,\n\t\tstore,\n\t)\n}\n","/* eslint-disable @typescript-eslint/ban-types */\nimport type {\n\tAtomFamily,\n\tRead,\n\tSelectorFamily,\n\tTransactors,\n\tWrite,\n} from \"atom.io\"\nimport { getState, setState } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tcreateAtomFamily,\n\tcreateMutableAtomFamily,\n\tcreateSelectorFamily,\n\tgetJsonFamily,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { SetRTX } from \"atom.io/transceivers/set-rtx\"\n\nimport type {\n\tBaseExternalStoreConfiguration,\n\tExternalStoreConfiguration,\n\tExternalStoreWithContentConfiguration,\n\tJunctionEntries,\n\tJunctionSchema,\n} from \"~/packages/rel8/junction/src\"\nimport { Junction } from \"~/packages/rel8/junction/src\"\nimport type * as Rel8 from \"~/packages/rel8/types/src\"\n\nconst TRANSACTORS: Transactors = { get: getState, set: setState }\n\nfunction capitalize<S extends string>(string: S): Capitalize<S> {\n\treturn (string[0].toUpperCase() + string.slice(1)) as Capitalize<S>\n}\n\nexport interface JoinOptions<\n\tASide extends string,\n\tBSide extends string,\n\tCardinality extends Rel8.Cardinality,\n\tContent extends Json.Object | null,\n> extends Json.Object,\n\t\tJunctionSchema<ASide, BSide>,\n\t\tPartial<JunctionEntries<Content>> {\n\treadonly key: string\n\treadonly cardinality: Cardinality\n}\n\nexport type JoinState<\n\tASide extends string,\n\tBSide extends string,\n\tCardinality extends Rel8.Cardinality,\n\tContent extends Json.Object | null,\n> = Cardinality extends `1:1`\n\t? (Content extends Json.Object\n\t\t\t? {\n\t\t\t\t\treadonly [AB in ASide | BSide as AB extends ASide\n\t\t\t\t\t\t? `${AB}EntryOf${Capitalize<BSide>}`\n\t\t\t\t\t\t: `${AB}EntryOf${Capitalize<ASide>}`]: SelectorFamily<\n\t\t\t\t\t\t[string, Content] | undefined,\n\t\t\t\t\t\tstring\n\t\t\t\t\t>\n\t\t\t }\n\t\t\t: {}) & {\n\t\t\treadonly [AB in ASide | BSide as AB extends ASide\n\t\t\t\t? `${AB}KeyOf${Capitalize<BSide>}`\n\t\t\t\t: `${AB}KeyOf${Capitalize<ASide>}`]: SelectorFamily<\n\t\t\t\tstring | undefined,\n\t\t\t\tstring\n\t\t\t>\n\t }\n\t: Cardinality extends `1:n`\n\t ? (Content extends Json.Object\n\t\t\t\t? {\n\t\t\t\t\t\treadonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: SelectorFamily<\n\t\t\t\t\t\t\t[string, Content] | undefined,\n\t\t\t\t\t\t\tstring\n\t\t\t\t\t\t>\n\t\t\t\t } & {\n\t\t\t\t\t\treadonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: SelectorFamily<\n\t\t\t\t\t\t\t[string, Content][],\n\t\t\t\t\t\t\tstring\n\t\t\t\t\t\t>\n\t\t\t\t }\n\t\t\t\t: {}) & {\n\t\t\t\treadonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: SelectorFamily<\n\t\t\t\t\tstring | undefined,\n\t\t\t\t\tstring\n\t\t\t\t>\n\t\t } & {\n\t\t\t\treadonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: SelectorFamily<\n\t\t\t\t\tstring[],\n\t\t\t\t\tstring\n\t\t\t\t>\n\t\t }\n\t : Cardinality extends `n:n`\n\t\t ? (Content extends Json.Object\n\t\t\t\t\t? {\n\t\t\t\t\t\t\treadonly [AB in ASide | BSide as AB extends ASide\n\t\t\t\t\t\t\t\t? `${AB}EntriesOf${Capitalize<BSide>}`\n\t\t\t\t\t\t\t\t: `${AB}EntriesOf${Capitalize<ASide>}`]: SelectorFamily<\n\t\t\t\t\t\t\t\t[string, Content][],\n\t\t\t\t\t\t\t\tstring\n\t\t\t\t\t\t\t>\n\t\t\t\t\t }\n\t\t\t\t\t: {}) & {\n\t\t\t\t\treadonly [AB in ASide | BSide as AB extends ASide\n\t\t\t\t\t\t? `${AB}KeysOf${Capitalize<BSide>}`\n\t\t\t\t\t\t: `${AB}KeysOf${Capitalize<ASide>}`]: SelectorFamily<\n\t\t\t\t\t\tstring[],\n\t\t\t\t\t\tstring\n\t\t\t\t\t>\n\t\t\t }\n\t\t : never\n\nexport function join<\n\tconst ASide extends string,\n\tconst BSide extends string,\n\tconst Cardinality extends Rel8.Cardinality,\n>(\n\toptions: JoinOptions<ASide, BSide, Cardinality, null>,\n\tdefaultContent?: undefined,\n\tstore?: Store,\n): {\n\trelations: Junction<ASide, BSide>\n\tfindState: JoinState<ASide, BSide, Cardinality, null>\n}\nexport function join<\n\tconst ASide extends string,\n\tconst Cardinality extends `1:1` | `1:n` | `n:n`,\n\tconst BSide extends string,\n\tconst Content extends Json.Object,\n>(\n\toptions: JoinOptions<ASide, BSide, Cardinality, Content>,\n\tdefaultContent: Content,\n\tstore?: Store,\n): {\n\trelations: Junction<ASide, BSide, Content>\n\tfindState: JoinState<ASide, BSide, Cardinality, Content>\n}\nexport function join<\n\tASide extends string,\n\tBSide extends string,\n\tCardinality extends Rel8.Cardinality,\n\tContent extends Json.Object,\n>(\n\toptions: JoinOptions<ASide, BSide, Cardinality, Content>,\n\tdefaultContent: Content | undefined,\n\tstore: Store = IMPLICIT.STORE,\n): {\n\trelations: Junction<ASide, BSide, Content>\n\tfindState: JoinState<ASide, BSide, Cardinality, Content>\n} {\n\tconst a: ASide = options.between[0]\n\tconst b: BSide = options.between[1]\n\tconst findRelatedKeysState = createMutableAtomFamily<\n\t\tSetRTX<string>,\n\t\tstring[],\n\t\tstring\n\t>(\n\t\t{\n\t\t\tkey: `${options.key}/relatedKeys`,\n\t\t\tdefault: () => new SetRTX(),\n\t\t\tmutable: true,\n\t\t\tfromJson: (json) => new SetRTX(json),\n\t\t\ttoJson: (set) => [...set],\n\t\t},\n\t\tstore,\n\t)\n\tconst getRelatedKeys: Read<(key: string) => Set<string> | undefined> = (\n\t\t{ get },\n\t\tkey,\n\t) => get(findRelatedKeysState(key))\n\tconst addRelation: Write<(a: string, b: string) => void> = (\n\t\ttransactors,\n\t\ta,\n\t\tb,\n\t) => {\n\t\tconst aKeys = getRelatedKeys(transactors, a)\n\t\tconst bKeys = getRelatedKeys(transactors, b)\n\t\tif (aKeys) {\n\t\t\ttransactors.set(findRelatedKeysState(a), aKeys.add(b))\n\t\t} else {\n\t\t\ttransactors.set(findRelatedKeysState(a), new SetRTX([b]))\n\t\t}\n\t\tif (bKeys) {\n\t\t\ttransactors.set(findRelatedKeysState(b), bKeys.add(a))\n\t\t} else {\n\t\t\ttransactors.set(findRelatedKeysState(b), new SetRTX([a]))\n\t\t}\n\t}\n\tconst deleteRelation: Write<(a: string, b: string) => void> = (\n\t\ttransactors,\n\t\ta,\n\t\tb,\n\t) => {\n\t\tconst aKeys = getRelatedKeys(transactors, a)\n\t\tif (aKeys) {\n\t\t\taKeys.delete(b)\n\t\t\tif (aKeys.size === 0) {\n\t\t\t\ttransactors.set(findRelatedKeysState(a), undefined)\n\t\t\t}\n\t\t\tconst bKeys = getRelatedKeys(transactors, b)\n\t\t\tif (bKeys) {\n\t\t\t\tbKeys.delete(a)\n\t\t\t\tif (bKeys.size === 0) {\n\t\t\t\t\ttransactors.set(findRelatedKeysState(b), undefined)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tconst replaceRelationsSafely: Write<(a: string, bs: string[]) => void> = (\n\t\ttransactors,\n\t\ta,\n\t\tbs,\n\t) => {\n\t\tconst aKeys = getRelatedKeys(transactors, a)\n\t\tif (aKeys) {\n\t\t\tfor (const b of aKeys) {\n\t\t\t\tconst bKeys = getRelatedKeys(transactors, b)\n\t\t\t\tif (bKeys) {\n\t\t\t\t\tbKeys.delete(a)\n\t\t\t\t\tif (bKeys.size === 0) {\n\t\t\t\t\t\ttransactors.set(findRelatedKeysState(b), undefined)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\ttransactors.set(findRelatedKeysState(a), new SetRTX(bs))\n\t\tfor (const b of bs) {\n\t\t\tconst bKeys = getRelatedKeys(transactors, b)\n\t\t\tif (bKeys) {\n\t\t\t\tbKeys.add(a)\n\t\t\t} else {\n\t\t\t\ttransactors.set(findRelatedKeysState(b), new SetRTX([a]))\n\t\t\t}\n\t\t}\n\t}\n\tconst replaceRelationsUnsafely: Write<(a: string, bs: string[]) => void> = (\n\t\ttransactors,\n\t\ta,\n\t\tbs,\n\t) => {\n\t\ttransactors.set(findRelatedKeysState(a), new SetRTX(bs))\n\t\tfor (const b of bs) {\n\t\t\tlet bKeys = getRelatedKeys(transactors, b)\n\t\t\tif (bKeys) {\n\t\t\t\tbKeys.add(a)\n\t\t\t} else {\n\t\t\t\tbKeys = new SetRTX([a])\n\t\t\t\ttransactors.set(findRelatedKeysState(b), bKeys)\n\t\t\t}\n\t\t}\n\t}\n\tconst has: Read<(a: string, b?: string) => boolean> = (transactors, a, b) => {\n\t\tconst aKeys = getRelatedKeys(transactors, a)\n\t\treturn b ? aKeys?.has(b) ?? false : (aKeys?.size ?? 0) > 0 ?? false\n\t}\n\tconst baseExternalStoreConfiguration: BaseExternalStoreConfiguration = {\n\t\tgetRelatedKeys: (key) => getRelatedKeys(TRANSACTORS, key),\n\t\taddRelation: (a, b) => addRelation(TRANSACTORS, a, b),\n\t\tdeleteRelation: (a, b) => deleteRelation(TRANSACTORS, a, b),\n\t\treplaceRelationsSafely: (a, bs) =>\n\t\t\treplaceRelationsSafely(TRANSACTORS, a, bs),\n\t\treplaceRelationsUnsafely: (a, bs) =>\n\t\t\treplaceRelationsUnsafely(TRANSACTORS, a, bs),\n\t\thas: (a, b) => has(TRANSACTORS, a, b),\n\t}\n\tlet externalStore: ExternalStoreConfiguration<Content>\n\tlet findContentState: AtomFamily<Content, string>\n\tif (defaultContent) {\n\t\tfindContentState = createAtomFamily<Content, string>(\n\t\t\t{\n\t\t\t\tkey: `${options.key}/content`,\n\t\t\t\tdefault: defaultContent,\n\t\t\t},\n\t\t\tstore,\n\t\t)\n\t\tconst getContent: Read<(key: string) => Content | undefined> = (\n\t\t\t{ get },\n\t\t\tkey,\n\t\t) => get(findContentState(key))\n\t\tconst setContent: Write<(key: string, content: Content) => void> = (\n\t\t\ttransactors,\n\t\t\tkey,\n\t\t\tcontent,\n\t\t) => transactors.set(findContentState(key), content)\n\t\tconst deleteContent: Write<(key: string) => void> = (transactors, key) =>\n\t\t\ttransactors.set(findContentState(key), undefined)\n\t\tconst externalStoreWithContentConfiguration: ExternalStoreWithContentConfiguration<Content> =\n\t\t\t{\n\t\t\t\tgetContent: (contentKey: string) => {\n\t\t\t\t\tconst content = getContent(TRANSACTORS, contentKey)\n\t\t\t\t\treturn content\n\t\t\t\t},\n\t\t\t\tsetContent: (contentKey: string, content: Content) => {\n\t\t\t\t\tsetContent(TRANSACTORS, contentKey, content)\n\t\t\t\t},\n\t\t\t\tdeleteContent: (contentKey: string) => {\n\t\t\t\t\tdeleteContent(TRANSACTORS, contentKey)\n\t\t\t\t},\n\t\t\t}\n\t\texternalStore = Object.assign(\n\t\t\tbaseExternalStoreConfiguration,\n\t\t\texternalStoreWithContentConfiguration,\n\t\t) as ExternalStoreConfiguration<Content>\n\t} else {\n\t\texternalStore =\n\t\t\tbaseExternalStoreConfiguration as ExternalStoreConfiguration<Content>\n\t}\n\tconst relations = new Junction<ASide, BSide, Content>(options, {\n\t\texternalStore,\n\t\tmakeContentKey: (...args) => args.sort().join(`:`),\n\t})\n\n\tconst createSingleKeyStateFamily = () =>\n\t\tcreateSelectorFamily<string | undefined, string>(\n\t\t\t{\n\t\t\t\tkey: `${options.key}/singleRelatedKey`,\n\t\t\t\tget:\n\t\t\t\t\t(key) =>\n\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\tconst relatedKeys = get(findRelatedKeysState(key))\n\t\t\t\t\t\tfor (const relatedKey of relatedKeys) {\n\t\t\t\t\t\t\treturn relatedKey\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t},\n\t\t\tstore,\n\t\t)\n\tconst getMultipleKeyStateFamily = () =>\n\t\tgetJsonFamily(findRelatedKeysState, store)\n\tconst createSingleEntryStateFamily = () =>\n\t\tcreateSelectorFamily<[string, Content] | undefined, string>(\n\t\t\t{\n\t\t\t\tkey: `${options.key}/singleRelatedEntry`,\n\t\t\t\tget:\n\t\t\t\t\t(key) =>\n\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\tconst relatedKeys = get(findRelatedKeysState(key))\n\t\t\t\t\t\tfor (const relatedKey of relatedKeys) {\n\t\t\t\t\t\t\tconst contentKey = relations.makeContentKey(key, relatedKey)\n\t\t\t\t\t\t\treturn [relatedKey, get(findContentState(contentKey))]\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t},\n\t\t\tstore,\n\t\t)\n\tconst getMultipleEntryStateFamily = () =>\n\t\tcreateSelectorFamily<[string, Content][], string>(\n\t\t\t{\n\t\t\t\tkey: `${options.key}/multipleRelatedEntries`,\n\t\t\t\tget:\n\t\t\t\t\t(key) =>\n\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\tconst relatedKeys = get(findRelatedKeysState(key))\n\t\t\t\t\t\treturn [...relatedKeys].map((relatedKey) => {\n\t\t\t\t\t\t\tconst contentKey = relations.makeContentKey(key, relatedKey)\n\t\t\t\t\t\t\treturn [relatedKey, get(findContentState(contentKey))]\n\t\t\t\t\t\t})\n\t\t\t\t\t},\n\t\t\t},\n\t\t\tstore,\n\t\t)\n\n\tswitch (options.cardinality) {\n\t\tcase `1:1`: {\n\t\t\tconst findSingleRelatedKeyState = createSingleKeyStateFamily()\n\t\t\tconst stateKeyA = `${a}KeyOf${capitalize(b)}` as const\n\t\t\tconst stateKeyB = `${b}KeyOf${capitalize(a)}` as const\n\t\t\tconst findStateBase = {\n\t\t\t\t[stateKeyA]: findSingleRelatedKeyState,\n\t\t\t\t[stateKeyB]: findSingleRelatedKeyState,\n\t\t\t} as JoinState<ASide, BSide, Cardinality, Content>\n\t\t\tlet findState: JoinState<ASide, BSide, Cardinality, Content>\n\t\t\tif (defaultContent) {\n\t\t\t\tconst findSingleRelatedEntryState = createSingleEntryStateFamily()\n\t\t\t\tconst entriesStateKeyA = `${a}EntryOf${capitalize(b)}` as const\n\t\t\t\tconst entriesStateKeyB = `${b}EntryOf${capitalize(a)}` as const\n\t\t\t\tconst findStateWithContent = {\n\t\t\t\t\t[entriesStateKeyA]: findSingleRelatedEntryState,\n\t\t\t\t\t[entriesStateKeyB]: findSingleRelatedEntryState,\n\t\t\t\t}\n\t\t\t\tfindState = Object.assign(findStateBase, findStateWithContent)\n\t\t\t} else {\n\t\t\t\tfindState = findStateBase\n\t\t\t}\n\t\t\treturn {\n\t\t\t\trelations,\n\t\t\t\tfindState,\n\t\t\t}\n\t\t}\n\t\tcase `1:n`: {\n\t\t\tconst findSingleRelatedKeyState = createSingleKeyStateFamily()\n\t\t\tconst findMultipleRelatedKeysState = getMultipleKeyStateFamily()\n\t\t\tconst stateKeyA = `${a}KeyOf${capitalize(b)}` as const\n\t\t\tconst stateKeyB = `${b}KeysOf${capitalize(a)}` as const\n\t\t\tconst findStateBase = {\n\t\t\t\t[stateKeyA]: findSingleRelatedKeyState,\n\t\t\t\t[stateKeyB]: findMultipleRelatedKeysState,\n\t\t\t} as JoinState<ASide, BSide, Cardinality, Content>\n\t\t\tlet findState: JoinState<ASide, BSide, Cardinality, Content>\n\t\t\tif (defaultContent) {\n\t\t\t\tconst findSingleRelatedEntryState = createSingleEntryStateFamily()\n\t\t\t\tconst findMultipleRelatedEntriesState = getMultipleEntryStateFamily()\n\t\t\t\tconst entriesStateKeyA = `${a}EntryOf${capitalize(b)}` as const\n\t\t\t\tconst entriesStateKeyB = `${b}EntriesOf${capitalize(a)}` as const\n\t\t\t\tconst findStateWithContent = {\n\t\t\t\t\t[entriesStateKeyA]: findSingleRelatedEntryState,\n\t\t\t\t\t[entriesStateKeyB]: findMultipleRelatedEntriesState,\n\t\t\t\t}\n\t\t\t\tfindState = Object.assign(findStateBase, findStateWithContent)\n\t\t\t} else {\n\t\t\t\tfindState = findStateBase\n\t\t\t}\n\t\t\treturn {\n\t\t\t\trelations,\n\t\t\t\tfindState,\n\t\t\t}\n\t\t}\n\t\tcase `n:n`: {\n\t\t\tconst findMultipleRelatedKeysState = getMultipleKeyStateFamily()\n\t\t\tconst stateKeyA = `${a}KeysOf${capitalize(b)}` as const\n\t\t\tconst stateKeyB = `${b}KeysOf${capitalize(a)}` as const\n\t\t\tconst findStateBase = {\n\t\t\t\t[stateKeyA]: findMultipleRelatedKeysState,\n\t\t\t\t[stateKeyB]: findMultipleRelatedKeysState,\n\t\t\t} as JoinState<ASide, BSide, Cardinality, Content>\n\t\t\tlet findState: JoinState<ASide, BSide, Cardinality, Content>\n\t\t\tif (defaultContent) {\n\t\t\t\tconst findMultipleRelatedEntriesState = getMultipleEntryStateFamily()\n\t\t\t\tconst entriesStateKeyA = `${a}EntriesOf${capitalize(b)}` as const\n\t\t\t\tconst entriesStateKeyB = `${b}EntriesOf${capitalize(a)}` as const\n\t\t\t\tconst findStateWithContent = {\n\t\t\t\t\t[entriesStateKeyA]: findMultipleRelatedEntriesState,\n\t\t\t\t\t[entriesStateKeyB]: findMultipleRelatedEntriesState,\n\t\t\t\t}\n\t\t\t\tfindState = Object.assign(findStateBase, findStateWithContent)\n\t\t\t} else {\n\t\t\t\tfindState = findStateBase\n\t\t\t}\n\t\t\treturn {\n\t\t\t\trelations,\n\t\t\t\tfindState,\n\t\t\t}\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error(`Invalid cardinality: ${options.cardinality}`)\n\t}\n}\n","import type { Cardinality, Json, Refinement } from \"rel8\"\n\nexport interface JunctionEntries<Content extends Json.Object | null>\n\textends Json.Object {\n\treadonly relations: [string, string[]][]\n\treadonly contents: [string, Content][]\n}\nexport interface JunctionSchema<ASide extends string, BSide extends string>\n\textends Json.Object {\n\treadonly between: [a: ASide, b: BSide]\n\treadonly cardinality: Cardinality\n}\n\nexport type BaseExternalStoreConfiguration = {\n\taddRelation: (a: string, b: string) => void\n\tdeleteRelation: (a: string, b: string) => void\n\treplaceRelationsSafely: (a: string, bs: string[]) => void\n\treplaceRelationsUnsafely: (a: string, bs: string[]) => void\n\tgetRelatedKeys: (key: string) => Set<string> | undefined\n\thas: (a: string, b?: string) => boolean\n}\n\nexport type ExternalStoreWithContentConfiguration<Content extends Json.Object> =\n\t{\n\t\tgetContent: (contentKey: string) => Content | undefined\n\t\tsetContent: (contentKey: string, content: Content) => void\n\t\tdeleteContent: (contentKey: string) => void\n\t}\n\nexport type Empty<Obj extends object> = {\n\t[Key in keyof Obj]?: undefined\n}\n\nexport type ExternalStoreConfiguration<Content extends Json.Object | null> =\n\tContent extends Json.Object\n\t\t? BaseExternalStoreConfiguration &\n\t\t\t\tExternalStoreWithContentConfiguration<Content>\n\t\t: BaseExternalStoreConfiguration &\n\t\t\t\tEmpty<ExternalStoreWithContentConfiguration<Json.Object>>\n\nexport type JunctionAdvancedConfiguration<Content extends Json.Object | null> = {\n\texternalStore?: ExternalStoreConfiguration<Content>\n\tisContent?: Refinement<unknown, Content>\n\tmakeContentKey?: (a: string, b: string) => string\n}\n\nexport type JunctionJSON<\n\tASide extends string,\n\tBSide extends string,\n\tContent extends Json.Object | null,\n> = JunctionEntries<Content> & JunctionSchema<ASide, BSide>\n\nexport class Junction<\n\tconst ASide extends string,\n\tconst BSide extends string,\n\tconst Content extends Json.Object | null = null,\n> {\n\tpublic readonly a: ASide\n\tpublic readonly b: BSide\n\tpublic readonly cardinality: Cardinality\n\tpublic readonly relations = new Map<string, Set<string>>()\n\tpublic readonly contents = new Map<string, Content>()\n\n\tpublic isContent: Refinement<unknown, Content> | null\n\tpublic makeContentKey = (a: string, b: string): string => `${a}:${b}`\n\n\tpublic getRelatedKeys(key: string): Set<string> | undefined {\n\t\treturn this.relations.get(key)\n\t}\n\tprotected addRelation(a: string, b: string): void {\n\t\tlet aRelations = this.relations.get(a)\n\t\tlet bRelations = this.relations.get(b)\n\t\tif (aRelations) {\n\t\t\taRelations.add(b)\n\t\t} else {\n\t\t\taRelations = new Set([b])\n\t\t\tthis.relations.set(a, aRelations)\n\t\t}\n\t\tif (bRelations) {\n\t\t\tbRelations.add(a)\n\t\t} else {\n\t\t\tbRelations = new Set([a])\n\t\t\tthis.relations.set(b, bRelations)\n\t\t}\n\t}\n\tprotected deleteRelation(a: string, b: string): void {\n\t\tconst aRelations = this.relations.get(a)\n\t\tif (aRelations) {\n\t\t\taRelations.delete(b)\n\t\t\tif (aRelations.size === 0) {\n\t\t\t\tthis.relations.delete(a)\n\t\t\t}\n\t\t\tconst bRelations = this.relations.get(b)\n\t\t\tif (bRelations) {\n\t\t\t\tbRelations.delete(a)\n\t\t\t\tif (bRelations.size === 0) {\n\t\t\t\t\tthis.relations.delete(b)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected replaceRelationsUnsafely(a: string, bs: string[]): void {\n\t\tthis.relations.set(a, new Set(bs))\n\t\tfor (const b of bs) {\n\t\t\tconst bRelations = new Set([a])\n\t\t\tthis.relations.set(b, bRelations)\n\t\t}\n\t}\n\tprotected replaceRelationsSafely(a: string, bs: string[]): void {\n\t\tconst aRelationsPrev = this.relations.get(a)\n\t\tif (aRelationsPrev) {\n\t\t\tfor (const b of aRelationsPrev) {\n\t\t\t\tconst bRelations = this.relations.get(b)\n\t\t\t\tif (bRelations) {\n\t\t\t\t\tif (bRelations.size === 1) {\n\t\t\t\t\t\tthis.relations.delete(b)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tbRelations.delete(a)\n\t\t\t\t\t}\n\t\t\t\t\tthis.contents.delete(this.makeContentKey(a, b))\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tthis.relations.set(a, new Set(bs))\n\t\tfor (const b of bs) {\n\t\t\tlet bRelations = this.relations.get(b)\n\t\t\tif (bRelations) {\n\t\t\t\tbRelations.add(a)\n\t\t\t} else {\n\t\t\t\tbRelations = new Set([a])\n\t\t\t\tthis.relations.set(b, bRelations)\n\t\t\t}\n\t\t}\n\t}\n\n\tprotected getContentInternal(contentKey: string): Content | undefined {\n\t\treturn this.contents.get(contentKey)\n\t}\n\tprotected setContent(contentKey: string, content: Content): void {\n\t\tthis.contents.set(contentKey, content)\n\t}\n\tprotected deleteContent(contentKey: string): void {\n\t\tthis.contents.delete(contentKey)\n\t}\n\n\tpublic constructor(\n\t\tdata: JunctionSchema<ASide, BSide> & Partial<JunctionEntries<Content>>,\n\t\tconfig?: JunctionAdvancedConfiguration<Content>,\n\t) {\n\t\tthis.a = data.between[0]\n\t\tthis.b = data.between[1]\n\n\t\tthis.cardinality = data.cardinality\n\t\tif (!config?.externalStore) {\n\t\t\tthis.relations = new Map(data.relations?.map(([a, b]) => [a, new Set(b)]))\n\t\t\tthis.contents = new Map(data.contents)\n\t\t}\n\t\tthis.isContent = config?.isContent ?? null\n\t\tif (config?.makeContentKey) {\n\t\t\tthis.makeContentKey = config.makeContentKey\n\t\t}\n\t\tif (config?.externalStore) {\n\t\t\tconst externalStore = config.externalStore\n\t\t\tthis.has = (a, b) => externalStore.has(a, b)\n\t\t\tthis.addRelation = (a, b) => {\n\t\t\t\texternalStore.addRelation(a, b)\n\t\t\t}\n\t\t\tthis.deleteRelation = (a, b) => {\n\t\t\t\texternalStore.deleteRelation(a, b)\n\t\t\t}\n\t\t\tthis.replaceRelationsSafely = (a, bs) => {\n\t\t\t\texternalStore.replaceRelationsSafely(a, bs)\n\t\t\t}\n\t\t\tthis.replaceRelationsUnsafely = (a, bs) => {\n\t\t\t\texternalStore.replaceRelationsUnsafely(a, bs)\n\t\t\t}\n\t\t\tthis.getRelatedKeys = (key) => externalStore.getRelatedKeys(key)\n\t\t\tif (externalStore.getContent) {\n\t\t\t\tthis.getContentInternal = (contentKey) => {\n\t\t\t\t\treturn externalStore.getContent(contentKey) as any\n\t\t\t\t}\n\t\t\t\tthis.setContent = (contentKey, content) => {\n\t\t\t\t\texternalStore.setContent(contentKey, content as any)\n\t\t\t\t}\n\t\t\t\tthis.deleteContent = (contentKey) => {\n\t\t\t\t\texternalStore.deleteContent(contentKey)\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const [x, ys] of data.relations ?? []) {\n\t\t\t\tfor (const y of ys) this.addRelation(x, y)\n\t\t\t}\n\t\t\tfor (const [contentKey, content] of data.contents ?? []) {\n\t\t\t\tthis.setContent(contentKey, content)\n\t\t\t}\n\t\t}\n\t}\n\tpublic toJSON(): JunctionJSON<ASide, BSide, Content> {\n\t\treturn {\n\t\t\tbetween: [this.a, this.b],\n\t\t\tcardinality: this.cardinality,\n\t\t\trelations: [...this.relations.entries()].map(([a, b]) => [a, [...b]]),\n\t\t\tcontents: [...this.contents.entries()],\n\t\t}\n\t}\n\n\tpublic set(\n\t\ta: string,\n\t\t...rest: Content extends null ? [b: string] : [b: string, content: Content]\n\t): this\n\tpublic set(\n\t\trelation: { [Key in ASide | BSide]: string },\n\t\t...rest: Content extends null ? [] | [b?: undefined] : [content: Content]\n\t): this\n\tpublic set(\n\t\ta: string | { [Key in ASide | BSide]: string },\n\t\t...rest: Content extends null\n\t\t\t? [] | [b?: string | undefined]\n\t\t\t: [b: string, content: Content] | [content: Content]\n\t): this {\n\t\tconst b: string =\n\t\t\ttypeof rest[0] === `string`\n\t\t\t\t? rest[0]\n\t\t\t\t: (a[this.b as keyof typeof a] as string)\n\t\tconst content: Content | undefined =\n\t\t\trest[1] ?? typeof rest[0] === `string` ? undefined : (rest[0] as Content)\n\t\ta = typeof a === `string` ? a : a[this.a]\n\t\tswitch (this.cardinality) {\n\t\t\t// biome-ignore lint/suspicious/noFallthroughSwitchClause: perfect here\n\t\t\tcase `1:1`: {\n\t\t\t\tconst bPrev = this.getRelatedKey(a)\n\t\t\t\tif (bPrev && bPrev !== b) this.delete(bPrev, a)\n\t\t\t}\n\t\t\tcase `1:n`: {\n\t\t\t\tconst aPrev = this.getRelatedKey(b)\n\t\t\t\tif (aPrev && aPrev !== a) this.delete(aPrev, b)\n\t\t\t}\n\t\t}\n\t\tif (content) {\n\t\t\tconst contentKey = this.makeContentKey(a, b)\n\t\t\tthis.setContent(contentKey, content)\n\t\t}\n\t\tthis.addRelation(a, b)\n\t\treturn this\n\t}\n\n\tpublic delete(a: string, b?: string): this\n\tpublic delete(\n\t\trelation:\n\t\t\t| Record<ASide | BSide, string>\n\t\t\t| Record<ASide, string>\n\t\t\t| Record<BSide, string>,\n\t\tb?: undefined,\n\t): this\n\tpublic delete(\n\t\tx:\n\t\t\t| Record<ASide | BSide, string>\n\t\t\t| Record<ASide, string>\n\t\t\t| Record<BSide, string>\n\t\t\t| string,\n\t\tb?: string | undefined,\n\t): this {\n\t\t// @ts-expect-error we deduce that this.b may index x\n\t\tb = typeof b === `string` ? b : (x[this.b] as string | undefined)\n\t\t// @ts-expect-error we deduce that this.a may index x\n\t\tconst a = typeof x === `string` ? x : (x[this.a] as string | undefined)\n\n\t\tif (a === undefined && typeof b === `string`) {\n\t\t\tconst bRelations = this.getRelatedKeys(b)\n\t\t\tif (bRelations) {\n\t\t\t\tfor (const a of bRelations) {\n\t\t\t\t\tthis.delete(a, b)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (typeof a === `string` && b === undefined) {\n\t\t\tconst aRelations = this.getRelatedKeys(a)\n\t\t\tif (aRelations) {\n\t\t\t\tfor (const b of aRelations) {\n\t\t\t\t\tthis.delete(a, b)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (typeof a === `string` && typeof b === `string`) {\n\t\t\tthis.deleteRelation(a, b)\n\t\t\tconst contentKey = this.makeContentKey(a, b)\n\t\t\tthis.deleteContent(contentKey)\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic getRelatedKey(key: string): string | undefined {\n\t\tconst relations = this.getRelatedKeys(key)\n\t\tif (relations) {\n\t\t\tif (relations.size > 1) {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`${relations.size} related keys were found for key \"${key}\": (${[\n\t\t\t\t\t\t...relations,\n\t\t\t\t\t]\n\t\t\t\t\t\t.map((k) => `\"${k}\"`)\n\t\t\t\t\t\t.join(`, `)}). Only one related key was expected.`,\n\t\t\t\t)\n\t\t\t}\n\t\t\tfor (const relation of relations) {\n\t\t\t\treturn relation\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic replaceRelations(\n\t\ta: string,\n\t\trelations: Content extends null ? string[] : Record<string, Content>,\n\t\tconfig?: { reckless: boolean },\n\t): this {\n\t\tconst hasContent = !Array.isArray(relations)\n\t\tconst bs = hasContent ? Object.keys(relations) : relations\n\t\tif (config?.reckless) {\n\t\t\tthis.replaceRelationsUnsafely(a, bs)\n\t\t} else {\n\t\t\tthis.replaceRelationsSafely(a, bs)\n\t\t}\n\t\tif (hasContent) {\n\t\t\tfor (const b of bs) {\n\t\t\t\tconst contentKey = this.makeContentKey(a, b)\n\t\t\t\tconst content = relations[b] as Content\n\t\t\t\tthis.setContent(contentKey, content)\n\t\t\t}\n\t\t}\n\t\treturn this\n\t}\n\n\tpublic getContent(a: string, b: string): Content | undefined {\n\t\tconst contentKey = this.makeContentKey(a, b)\n\t\treturn this.getContentInternal(contentKey)\n\t}\n\n\tpublic getRelationEntries(\n\t\tinput: Record<ASide, string> | Record<BSide, string>,\n\t): [string, Content][] {\n\t\tconst a: string | undefined = (input as any)[this.a]\n\t\tconst b: string | undefined = (input as any)[this.b]\n\t\tif (a !== undefined && b === undefined) {\n\t\t\tconst aRelations = this.getRelatedKeys(a)\n\t\t\tif (aRelations) {\n\t\t\t\treturn [...aRelations].map((b) => {\n\t\t\t\t\treturn [b, this.getContent(a, b) ?? (null as Content)]\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\tif (a === undefined && b !== undefined) {\n\t\t\tconst bRelations = this.getRelatedKeys(b)\n\t\t\tif (bRelations) {\n\t\t\t\treturn [...bRelations].map((a) => {\n\t\t\t\t\treturn [a, this.getContent(a, b) ?? (null as Content)]\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\t\treturn []\n\t}\n\n\tpublic has(a: string, b?: string): boolean {\n\t\tif (b) {\n\t\t\tconst setA = this.getRelatedKeys(a)\n\t\t\treturn setA?.has(b) ?? false\n\t\t}\n\t\treturn this.relations.has(a)\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\n\nimport { createAtom, createSelector } from \"atom.io/internal\"\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\n\nexport function struct<\n\tStruct extends { [key: string]: unknown },\n\tKey extends string,\n>(\n\toptions: {\n\t\tkey: Key\n\t\tdefault: Struct\n\t},\n\tstore: Store = IMPLICIT.STORE,\n): [\n\t{\n\t\t[K in keyof Struct as `${Key}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.AtomToken<Struct[K]>\n\t},\n\tAtomIO.ReadonlySelectorToken<Struct>,\n] {\n\tconst atoms: {\n\t\t[K in keyof Struct as `${Key}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.AtomToken<Struct[K]>\n\t} = Object.keys(options.default).reduce((acc, key) => {\n\t\tconst atomName = options.key + capitalize(key) + `State`\n\t\tacc[atomName] = createAtom(\n\t\t\t{\n\t\t\t\tkey: `${options.key}.${key}`,\n\t\t\t\tdefault: options.default[key],\n\t\t\t},\n\t\t\tundefined,\n\t\t\tstore,\n\t\t)\n\t\treturn acc\n\t}, {} as any)\n\tconst structState = createSelector(\n\t\t{\n\t\t\tkey: options.key,\n\t\t\tget: ({ get }) => {\n\t\t\t\treturn Object.keys(options.default).reduce((acc, key) => {\n\t\t\t\t\tacc[key] = get(atoms[options.key + capitalize(key) + `State`])\n\t\t\t\t\treturn acc\n\t\t\t\t}, {} as any)\n\t\t\t},\n\t\t},\n\t\tundefined,\n\t\tstore,\n\t)\n\treturn [atoms, structState]\n}\n","import type * as AtomIO from \"atom.io\"\nimport {\n\tIMPLICIT,\n\tcreateAtomFamily,\n\tcreateSelectorFamily,\n} from \"atom.io/internal\"\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\nconst nameFamily = (topKey: string, subKey: string) =>\n\t`find` + capitalize(topKey) + capitalize(subKey) + `State`\n\nexport function structFamily<\n\tStruct extends object,\n\tKey extends string,\n>(options: {\n\tkey: Key\n\tdefault: Struct\n}): [\n\t{\n\t\t[K in keyof Struct as `find${Capitalize<Key & string>}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.AtomFamily<Struct[K], string>\n\t},\n\tAtomIO.ReadonlySelectorFamily<Struct>,\n] {\n\tconst atoms: {\n\t\t[K in keyof Struct as `find${Capitalize<Key & string>}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.AtomFamily<Struct[K], string>\n\t} = Object.keys(options.default).reduce((acc, subKey) => {\n\t\tconst atomFamilyName = nameFamily(options.key, subKey)\n\t\tacc[atomFamilyName] = createAtomFamily(\n\t\t\t{\n\t\t\t\tkey: `${options.key}.${subKey}`,\n\t\t\t\tdefault: (options.default as any)[subKey],\n\t\t\t},\n\t\t\tIMPLICIT.STORE,\n\t\t)\n\t\treturn acc\n\t}, {} as any)\n\tconst findStructState = createSelectorFamily(\n\t\t{\n\t\t\tkey: options.key,\n\t\t\tget:\n\t\t\t\t(id) =>\n\t\t\t\t({ get }) => {\n\t\t\t\t\treturn Object.keys(options.default).reduce((acc, subKey) => {\n\t\t\t\t\t\tacc[subKey] = get(\n\t\t\t\t\t\t\t(atoms as any)[nameFamily(options.key, subKey)](id),\n\t\t\t\t\t\t)\n\t\t\t\t\t\treturn acc\n\t\t\t\t\t}, {} as any)\n\t\t\t\t},\n\t\t},\n\t\tIMPLICIT.STORE,\n\t)\n\treturn [atoms, findStructState]\n}\n","export type Loadable<T> = Promise<T> | T\nexport type Fated<T, E extends Error = Error> = Loadable<E | T>\n\n/**\n * Utility for handling loadable values\n * @param loadable Loadable value\n * @param fallback Fallback value until Loadable is resolved\n * @returns Fallback value if your loadable is a promise, otherwise the loadable's resolved value\n */\nexport function until<T>(loadable: Loadable<T>, fallback: T): T {\n\tif (loadable instanceof Promise) {\n\t\treturn fallback\n\t}\n\treturn loadable\n}\n"]}
@@ -0,0 +1 @@
1
+ {"inputs":{"src/dict.ts":{"bytes":860,"imports":[{"path":"atom.io/internal","kind":"import-statement","external":true}],"format":"esm"},"../../rel8/junction/src/junction.ts":{"bytes":10655,"imports":[],"format":"esm"},"../../rel8/junction/src/index.ts":{"bytes":27,"imports":[{"path":"../../rel8/junction/src/junction.ts","kind":"import-statement","original":"./junction"}],"format":"esm"},"src/join.ts":{"bytes":13411,"imports":[{"path":"atom.io","kind":"import-statement","external":true},{"path":"atom.io/internal","kind":"import-statement","external":true},{"path":"atom.io/transceivers/set-rtx","kind":"import-statement","external":true},{"path":"../../rel8/junction/src/index.ts","kind":"import-statement","original":"~/packages/rel8/junction/src"}],"format":"esm"},"src/struct.ts":{"bytes":1305,"imports":[{"path":"atom.io/internal","kind":"import-statement","external":true},{"path":"atom.io/internal","kind":"import-statement","external":true}],"format":"esm"},"src/struct-family.ts":{"bytes":1452,"imports":[{"path":"atom.io/internal","kind":"import-statement","external":true}],"format":"esm"},"src/until.ts":{"bytes":489,"imports":[],"format":"esm"},"src/index.ts":{"bytes":127,"imports":[{"path":"src/dict.ts","kind":"import-statement","original":"./dict"},{"path":"src/join.ts","kind":"import-statement","original":"./join"},{"path":"src/struct.ts","kind":"import-statement","original":"./struct"},{"path":"src/struct-family.ts","kind":"import-statement","original":"./struct-family"},{"path":"src/until.ts","kind":"import-statement","original":"./until"}],"format":"esm"}},"outputs":{"dist/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":46388},"dist/index.cjs":{"imports":[{"path":"atom.io/internal","kind":"import-statement","external":true},{"path":"atom.io","kind":"import-statement","external":true},{"path":"atom.io/internal","kind":"import-statement","external":true},{"path":"atom.io/transceivers/set-rtx","kind":"import-statement","external":true},{"path":"atom.io/internal","kind":"import-statement","external":true},{"path":"atom.io/internal","kind":"import-statement","external":true},{"path":"atom.io/internal","kind":"import-statement","external":true}],"exports":["dict","join","struct","structFamily","until"],"entryPoint":"src/index.ts","inputs":{"src/dict.ts":{"bytesInOutput":411},"src/index.ts":{"bytesInOutput":0},"src/join.ts":{"bytesInOutput":9227},"../../rel8/junction/src/junction.ts":{"bytesInOutput":7828},"../../rel8/junction/src/index.ts":{"bytesInOutput":0},"src/struct.ts":{"bytesInOutput":921},"src/struct-family.ts":{"bytesInOutput":1071},"src/until.ts":{"bytesInOutput":120}},"bytes":19787}}}
@@ -0,0 +1 @@
1
+ {"inputs":{"src/dict.ts":{"bytes":860,"imports":[{"path":"atom.io/internal","kind":"import-statement","external":true}],"format":"esm"},"../../rel8/junction/src/junction.ts":{"bytes":10655,"imports":[],"format":"esm"},"../../rel8/junction/src/index.ts":{"bytes":27,"imports":[{"path":"../../rel8/junction/src/junction.ts","kind":"import-statement","original":"./junction"}],"format":"esm"},"src/join.ts":{"bytes":13411,"imports":[{"path":"atom.io","kind":"import-statement","external":true},{"path":"atom.io/internal","kind":"import-statement","external":true},{"path":"atom.io/transceivers/set-rtx","kind":"import-statement","external":true},{"path":"../../rel8/junction/src/index.ts","kind":"import-statement","original":"~/packages/rel8/junction/src"}],"format":"esm"},"src/struct.ts":{"bytes":1305,"imports":[{"path":"atom.io/internal","kind":"import-statement","external":true},{"path":"atom.io/internal","kind":"import-statement","external":true}],"format":"esm"},"src/struct-family.ts":{"bytes":1452,"imports":[{"path":"atom.io/internal","kind":"import-statement","external":true}],"format":"esm"},"src/until.ts":{"bytes":489,"imports":[],"format":"esm"},"src/index.ts":{"bytes":127,"imports":[{"path":"src/dict.ts","kind":"import-statement","original":"./dict"},{"path":"src/join.ts","kind":"import-statement","original":"./join"},{"path":"src/struct.ts","kind":"import-statement","original":"./struct"},{"path":"src/struct-family.ts","kind":"import-statement","original":"./struct-family"},{"path":"src/until.ts","kind":"import-statement","original":"./until"}],"format":"esm"}},"outputs":{"dist/index.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":46388},"dist/index.js":{"imports":[{"path":"atom.io/internal","kind":"import-statement","external":true},{"path":"atom.io","kind":"import-statement","external":true},{"path":"atom.io/internal","kind":"import-statement","external":true},{"path":"atom.io/transceivers/set-rtx","kind":"import-statement","external":true},{"path":"atom.io/internal","kind":"import-statement","external":true},{"path":"atom.io/internal","kind":"import-statement","external":true},{"path":"atom.io/internal","kind":"import-statement","external":true}],"exports":["dict","join","struct","structFamily","until"],"entryPoint":"src/index.ts","inputs":{"src/dict.ts":{"bytesInOutput":411},"src/index.ts":{"bytesInOutput":0},"src/join.ts":{"bytesInOutput":9227},"../../rel8/junction/src/junction.ts":{"bytesInOutput":7828},"../../rel8/junction/src/index.ts":{"bytesInOutput":0},"src/struct.ts":{"bytesInOutput":921},"src/struct-family.ts":{"bytesInOutput":1071},"src/until.ts":{"bytesInOutput":120}},"bytes":19787}}}
package/data/package.json CHANGED
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "name": "atom.io-data",
3
+ "type": "module",
3
4
  "private": true,
4
5
  "main": "dist/index.js",
5
6
  "types": "dist/index.d.ts",
@@ -7,9 +8,9 @@
7
8
  "exports": {
8
9
  ".": {
9
10
  "types": "./dist/index.d.ts",
10
- "browser": "./dist/index.mjs",
11
- "import": "./dist/index.mjs",
12
- "require": "./dist/index.js"
11
+ "browser": "./dist/index.js",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
13
14
  }
14
15
  }
15
16
  }
package/data/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./dict"
2
+ export * from "./join"
2
3
  export * from "./struct"
3
4
  export * from "./struct-family"
4
5
  export * from "./until"
@@ -0,0 +1,450 @@
1
+ /* eslint-disable @typescript-eslint/ban-types */
2
+ import type {
3
+ AtomFamily,
4
+ Read,
5
+ SelectorFamily,
6
+ Transactors,
7
+ Write,
8
+ } from "atom.io"
9
+ import { getState, setState } from "atom.io"
10
+ import type { Store } from "atom.io/internal"
11
+ import {
12
+ IMPLICIT,
13
+ createAtomFamily,
14
+ createMutableAtomFamily,
15
+ createSelectorFamily,
16
+ getJsonFamily,
17
+ } from "atom.io/internal"
18
+ import type { Json } from "atom.io/json"
19
+ import { SetRTX } from "atom.io/transceivers/set-rtx"
20
+
21
+ import type {
22
+ BaseExternalStoreConfiguration,
23
+ ExternalStoreConfiguration,
24
+ ExternalStoreWithContentConfiguration,
25
+ JunctionEntries,
26
+ JunctionSchema,
27
+ } from "~/packages/rel8/junction/src"
28
+ import { Junction } from "~/packages/rel8/junction/src"
29
+ import type * as Rel8 from "~/packages/rel8/types/src"
30
+
31
+ const TRANSACTORS: Transactors = { get: getState, set: setState }
32
+
33
+ function capitalize<S extends string>(string: S): Capitalize<S> {
34
+ return (string[0].toUpperCase() + string.slice(1)) as Capitalize<S>
35
+ }
36
+
37
+ export interface JoinOptions<
38
+ ASide extends string,
39
+ BSide extends string,
40
+ Cardinality extends Rel8.Cardinality,
41
+ Content extends Json.Object | null,
42
+ > extends Json.Object,
43
+ JunctionSchema<ASide, BSide>,
44
+ Partial<JunctionEntries<Content>> {
45
+ readonly key: string
46
+ readonly cardinality: Cardinality
47
+ }
48
+
49
+ export type JoinState<
50
+ ASide extends string,
51
+ BSide extends string,
52
+ Cardinality extends Rel8.Cardinality,
53
+ Content extends Json.Object | null,
54
+ > = Cardinality extends `1:1`
55
+ ? (Content extends Json.Object
56
+ ? {
57
+ readonly [AB in ASide | BSide as AB extends ASide
58
+ ? `${AB}EntryOf${Capitalize<BSide>}`
59
+ : `${AB}EntryOf${Capitalize<ASide>}`]: SelectorFamily<
60
+ [string, Content] | undefined,
61
+ string
62
+ >
63
+ }
64
+ : {}) & {
65
+ readonly [AB in ASide | BSide as AB extends ASide
66
+ ? `${AB}KeyOf${Capitalize<BSide>}`
67
+ : `${AB}KeyOf${Capitalize<ASide>}`]: SelectorFamily<
68
+ string | undefined,
69
+ string
70
+ >
71
+ }
72
+ : Cardinality extends `1:n`
73
+ ? (Content extends Json.Object
74
+ ? {
75
+ readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: SelectorFamily<
76
+ [string, Content] | undefined,
77
+ string
78
+ >
79
+ } & {
80
+ readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: SelectorFamily<
81
+ [string, Content][],
82
+ string
83
+ >
84
+ }
85
+ : {}) & {
86
+ readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: SelectorFamily<
87
+ string | undefined,
88
+ string
89
+ >
90
+ } & {
91
+ readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: SelectorFamily<
92
+ string[],
93
+ string
94
+ >
95
+ }
96
+ : Cardinality extends `n:n`
97
+ ? (Content extends Json.Object
98
+ ? {
99
+ readonly [AB in ASide | BSide as AB extends ASide
100
+ ? `${AB}EntriesOf${Capitalize<BSide>}`
101
+ : `${AB}EntriesOf${Capitalize<ASide>}`]: SelectorFamily<
102
+ [string, Content][],
103
+ string
104
+ >
105
+ }
106
+ : {}) & {
107
+ readonly [AB in ASide | BSide as AB extends ASide
108
+ ? `${AB}KeysOf${Capitalize<BSide>}`
109
+ : `${AB}KeysOf${Capitalize<ASide>}`]: SelectorFamily<
110
+ string[],
111
+ string
112
+ >
113
+ }
114
+ : never
115
+
116
+ export function join<
117
+ const ASide extends string,
118
+ const BSide extends string,
119
+ const Cardinality extends Rel8.Cardinality,
120
+ >(
121
+ options: JoinOptions<ASide, BSide, Cardinality, null>,
122
+ defaultContent?: undefined,
123
+ store?: Store,
124
+ ): {
125
+ relations: Junction<ASide, BSide>
126
+ findState: JoinState<ASide, BSide, Cardinality, null>
127
+ }
128
+ export function join<
129
+ const ASide extends string,
130
+ const Cardinality extends `1:1` | `1:n` | `n:n`,
131
+ const BSide extends string,
132
+ const Content extends Json.Object,
133
+ >(
134
+ options: JoinOptions<ASide, BSide, Cardinality, Content>,
135
+ defaultContent: Content,
136
+ store?: Store,
137
+ ): {
138
+ relations: Junction<ASide, BSide, Content>
139
+ findState: JoinState<ASide, BSide, Cardinality, Content>
140
+ }
141
+ export function join<
142
+ ASide extends string,
143
+ BSide extends string,
144
+ Cardinality extends Rel8.Cardinality,
145
+ Content extends Json.Object,
146
+ >(
147
+ options: JoinOptions<ASide, BSide, Cardinality, Content>,
148
+ defaultContent: Content | undefined,
149
+ store: Store = IMPLICIT.STORE,
150
+ ): {
151
+ relations: Junction<ASide, BSide, Content>
152
+ findState: JoinState<ASide, BSide, Cardinality, Content>
153
+ } {
154
+ const a: ASide = options.between[0]
155
+ const b: BSide = options.between[1]
156
+ const findRelatedKeysState = createMutableAtomFamily<
157
+ SetRTX<string>,
158
+ string[],
159
+ string
160
+ >(
161
+ {
162
+ key: `${options.key}/relatedKeys`,
163
+ default: () => new SetRTX(),
164
+ mutable: true,
165
+ fromJson: (json) => new SetRTX(json),
166
+ toJson: (set) => [...set],
167
+ },
168
+ store,
169
+ )
170
+ const getRelatedKeys: Read<(key: string) => Set<string> | undefined> = (
171
+ { get },
172
+ key,
173
+ ) => get(findRelatedKeysState(key))
174
+ const addRelation: Write<(a: string, b: string) => void> = (
175
+ transactors,
176
+ a,
177
+ b,
178
+ ) => {
179
+ const aKeys = getRelatedKeys(transactors, a)
180
+ const bKeys = getRelatedKeys(transactors, b)
181
+ if (aKeys) {
182
+ transactors.set(findRelatedKeysState(a), aKeys.add(b))
183
+ } else {
184
+ transactors.set(findRelatedKeysState(a), new SetRTX([b]))
185
+ }
186
+ if (bKeys) {
187
+ transactors.set(findRelatedKeysState(b), bKeys.add(a))
188
+ } else {
189
+ transactors.set(findRelatedKeysState(b), new SetRTX([a]))
190
+ }
191
+ }
192
+ const deleteRelation: Write<(a: string, b: string) => void> = (
193
+ transactors,
194
+ a,
195
+ b,
196
+ ) => {
197
+ const aKeys = getRelatedKeys(transactors, a)
198
+ if (aKeys) {
199
+ aKeys.delete(b)
200
+ if (aKeys.size === 0) {
201
+ transactors.set(findRelatedKeysState(a), undefined)
202
+ }
203
+ const bKeys = getRelatedKeys(transactors, b)
204
+ if (bKeys) {
205
+ bKeys.delete(a)
206
+ if (bKeys.size === 0) {
207
+ transactors.set(findRelatedKeysState(b), undefined)
208
+ }
209
+ }
210
+ }
211
+ }
212
+ const replaceRelationsSafely: Write<(a: string, bs: string[]) => void> = (
213
+ transactors,
214
+ a,
215
+ bs,
216
+ ) => {
217
+ const aKeys = getRelatedKeys(transactors, a)
218
+ if (aKeys) {
219
+ for (const b of aKeys) {
220
+ const bKeys = getRelatedKeys(transactors, b)
221
+ if (bKeys) {
222
+ bKeys.delete(a)
223
+ if (bKeys.size === 0) {
224
+ transactors.set(findRelatedKeysState(b), undefined)
225
+ }
226
+ }
227
+ }
228
+ }
229
+ transactors.set(findRelatedKeysState(a), new SetRTX(bs))
230
+ for (const b of bs) {
231
+ const bKeys = getRelatedKeys(transactors, b)
232
+ if (bKeys) {
233
+ bKeys.add(a)
234
+ } else {
235
+ transactors.set(findRelatedKeysState(b), new SetRTX([a]))
236
+ }
237
+ }
238
+ }
239
+ const replaceRelationsUnsafely: Write<(a: string, bs: string[]) => void> = (
240
+ transactors,
241
+ a,
242
+ bs,
243
+ ) => {
244
+ transactors.set(findRelatedKeysState(a), new SetRTX(bs))
245
+ for (const b of bs) {
246
+ let bKeys = getRelatedKeys(transactors, b)
247
+ if (bKeys) {
248
+ bKeys.add(a)
249
+ } else {
250
+ bKeys = new SetRTX([a])
251
+ transactors.set(findRelatedKeysState(b), bKeys)
252
+ }
253
+ }
254
+ }
255
+ const has: Read<(a: string, b?: string) => boolean> = (transactors, a, b) => {
256
+ const aKeys = getRelatedKeys(transactors, a)
257
+ return b ? aKeys?.has(b) ?? false : (aKeys?.size ?? 0) > 0 ?? false
258
+ }
259
+ const baseExternalStoreConfiguration: BaseExternalStoreConfiguration = {
260
+ getRelatedKeys: (key) => getRelatedKeys(TRANSACTORS, key),
261
+ addRelation: (a, b) => addRelation(TRANSACTORS, a, b),
262
+ deleteRelation: (a, b) => deleteRelation(TRANSACTORS, a, b),
263
+ replaceRelationsSafely: (a, bs) =>
264
+ replaceRelationsSafely(TRANSACTORS, a, bs),
265
+ replaceRelationsUnsafely: (a, bs) =>
266
+ replaceRelationsUnsafely(TRANSACTORS, a, bs),
267
+ has: (a, b) => has(TRANSACTORS, a, b),
268
+ }
269
+ let externalStore: ExternalStoreConfiguration<Content>
270
+ let findContentState: AtomFamily<Content, string>
271
+ if (defaultContent) {
272
+ findContentState = createAtomFamily<Content, string>(
273
+ {
274
+ key: `${options.key}/content`,
275
+ default: defaultContent,
276
+ },
277
+ store,
278
+ )
279
+ const getContent: Read<(key: string) => Content | undefined> = (
280
+ { get },
281
+ key,
282
+ ) => get(findContentState(key))
283
+ const setContent: Write<(key: string, content: Content) => void> = (
284
+ transactors,
285
+ key,
286
+ content,
287
+ ) => transactors.set(findContentState(key), content)
288
+ const deleteContent: Write<(key: string) => void> = (transactors, key) =>
289
+ transactors.set(findContentState(key), undefined)
290
+ const externalStoreWithContentConfiguration: ExternalStoreWithContentConfiguration<Content> =
291
+ {
292
+ getContent: (contentKey: string) => {
293
+ const content = getContent(TRANSACTORS, contentKey)
294
+ return content
295
+ },
296
+ setContent: (contentKey: string, content: Content) => {
297
+ setContent(TRANSACTORS, contentKey, content)
298
+ },
299
+ deleteContent: (contentKey: string) => {
300
+ deleteContent(TRANSACTORS, contentKey)
301
+ },
302
+ }
303
+ externalStore = Object.assign(
304
+ baseExternalStoreConfiguration,
305
+ externalStoreWithContentConfiguration,
306
+ ) as ExternalStoreConfiguration<Content>
307
+ } else {
308
+ externalStore =
309
+ baseExternalStoreConfiguration as ExternalStoreConfiguration<Content>
310
+ }
311
+ const relations = new Junction<ASide, BSide, Content>(options, {
312
+ externalStore,
313
+ makeContentKey: (...args) => args.sort().join(`:`),
314
+ })
315
+
316
+ const createSingleKeyStateFamily = () =>
317
+ createSelectorFamily<string | undefined, string>(
318
+ {
319
+ key: `${options.key}/singleRelatedKey`,
320
+ get:
321
+ (key) =>
322
+ ({ get }) => {
323
+ const relatedKeys = get(findRelatedKeysState(key))
324
+ for (const relatedKey of relatedKeys) {
325
+ return relatedKey
326
+ }
327
+ },
328
+ },
329
+ store,
330
+ )
331
+ const getMultipleKeyStateFamily = () =>
332
+ getJsonFamily(findRelatedKeysState, store)
333
+ const createSingleEntryStateFamily = () =>
334
+ createSelectorFamily<[string, Content] | undefined, string>(
335
+ {
336
+ key: `${options.key}/singleRelatedEntry`,
337
+ get:
338
+ (key) =>
339
+ ({ get }) => {
340
+ const relatedKeys = get(findRelatedKeysState(key))
341
+ for (const relatedKey of relatedKeys) {
342
+ const contentKey = relations.makeContentKey(key, relatedKey)
343
+ return [relatedKey, get(findContentState(contentKey))]
344
+ }
345
+ },
346
+ },
347
+ store,
348
+ )
349
+ const getMultipleEntryStateFamily = () =>
350
+ createSelectorFamily<[string, Content][], string>(
351
+ {
352
+ key: `${options.key}/multipleRelatedEntries`,
353
+ get:
354
+ (key) =>
355
+ ({ get }) => {
356
+ const relatedKeys = get(findRelatedKeysState(key))
357
+ return [...relatedKeys].map((relatedKey) => {
358
+ const contentKey = relations.makeContentKey(key, relatedKey)
359
+ return [relatedKey, get(findContentState(contentKey))]
360
+ })
361
+ },
362
+ },
363
+ store,
364
+ )
365
+
366
+ switch (options.cardinality) {
367
+ case `1:1`: {
368
+ const findSingleRelatedKeyState = createSingleKeyStateFamily()
369
+ const stateKeyA = `${a}KeyOf${capitalize(b)}` as const
370
+ const stateKeyB = `${b}KeyOf${capitalize(a)}` as const
371
+ const findStateBase = {
372
+ [stateKeyA]: findSingleRelatedKeyState,
373
+ [stateKeyB]: findSingleRelatedKeyState,
374
+ } as JoinState<ASide, BSide, Cardinality, Content>
375
+ let findState: JoinState<ASide, BSide, Cardinality, Content>
376
+ if (defaultContent) {
377
+ const findSingleRelatedEntryState = createSingleEntryStateFamily()
378
+ const entriesStateKeyA = `${a}EntryOf${capitalize(b)}` as const
379
+ const entriesStateKeyB = `${b}EntryOf${capitalize(a)}` as const
380
+ const findStateWithContent = {
381
+ [entriesStateKeyA]: findSingleRelatedEntryState,
382
+ [entriesStateKeyB]: findSingleRelatedEntryState,
383
+ }
384
+ findState = Object.assign(findStateBase, findStateWithContent)
385
+ } else {
386
+ findState = findStateBase
387
+ }
388
+ return {
389
+ relations,
390
+ findState,
391
+ }
392
+ }
393
+ case `1:n`: {
394
+ const findSingleRelatedKeyState = createSingleKeyStateFamily()
395
+ const findMultipleRelatedKeysState = getMultipleKeyStateFamily()
396
+ const stateKeyA = `${a}KeyOf${capitalize(b)}` as const
397
+ const stateKeyB = `${b}KeysOf${capitalize(a)}` as const
398
+ const findStateBase = {
399
+ [stateKeyA]: findSingleRelatedKeyState,
400
+ [stateKeyB]: findMultipleRelatedKeysState,
401
+ } as JoinState<ASide, BSide, Cardinality, Content>
402
+ let findState: JoinState<ASide, BSide, Cardinality, Content>
403
+ if (defaultContent) {
404
+ const findSingleRelatedEntryState = createSingleEntryStateFamily()
405
+ const findMultipleRelatedEntriesState = getMultipleEntryStateFamily()
406
+ const entriesStateKeyA = `${a}EntryOf${capitalize(b)}` as const
407
+ const entriesStateKeyB = `${b}EntriesOf${capitalize(a)}` as const
408
+ const findStateWithContent = {
409
+ [entriesStateKeyA]: findSingleRelatedEntryState,
410
+ [entriesStateKeyB]: findMultipleRelatedEntriesState,
411
+ }
412
+ findState = Object.assign(findStateBase, findStateWithContent)
413
+ } else {
414
+ findState = findStateBase
415
+ }
416
+ return {
417
+ relations,
418
+ findState,
419
+ }
420
+ }
421
+ case `n:n`: {
422
+ const findMultipleRelatedKeysState = getMultipleKeyStateFamily()
423
+ const stateKeyA = `${a}KeysOf${capitalize(b)}` as const
424
+ const stateKeyB = `${b}KeysOf${capitalize(a)}` as const
425
+ const findStateBase = {
426
+ [stateKeyA]: findMultipleRelatedKeysState,
427
+ [stateKeyB]: findMultipleRelatedKeysState,
428
+ } as JoinState<ASide, BSide, Cardinality, Content>
429
+ let findState: JoinState<ASide, BSide, Cardinality, Content>
430
+ if (defaultContent) {
431
+ const findMultipleRelatedEntriesState = getMultipleEntryStateFamily()
432
+ const entriesStateKeyA = `${a}EntriesOf${capitalize(b)}` as const
433
+ const entriesStateKeyB = `${b}EntriesOf${capitalize(a)}` as const
434
+ const findStateWithContent = {
435
+ [entriesStateKeyA]: findMultipleRelatedEntriesState,
436
+ [entriesStateKeyB]: findMultipleRelatedEntriesState,
437
+ }
438
+ findState = Object.assign(findStateBase, findStateWithContent)
439
+ } else {
440
+ findState = findStateBase
441
+ }
442
+ return {
443
+ relations,
444
+ findState,
445
+ }
446
+ }
447
+ default:
448
+ throw new Error(`Invalid cardinality: ${options.cardinality}`)
449
+ }
450
+ }