atom.io 0.15.3 → 0.15.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 (70) hide show
  1. package/data/dist/index.cjs +9 -0
  2. package/data/dist/index.cjs.map +1 -1
  3. package/data/dist/index.js +9 -0
  4. package/data/dist/index.js.map +1 -1
  5. package/data/src/join.ts +9 -0
  6. package/dist/{chunk-K22LR3V6.js → chunk-RLZQ6IIY.js} +11 -2
  7. package/dist/chunk-RLZQ6IIY.js.map +1 -0
  8. package/dist/index.cjs +11 -0
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.ts +89 -72
  11. package/dist/index.js +1 -1
  12. package/internal/dist/index.cjs +16 -16
  13. package/internal/dist/index.cjs.map +1 -1
  14. package/internal/dist/index.d.ts +18 -18
  15. package/internal/dist/index.js +17 -17
  16. package/internal/dist/index.js.map +1 -1
  17. package/internal/src/atom/create-regular-atom.ts +1 -1
  18. package/internal/src/mutable/tracker.ts +3 -3
  19. package/internal/src/operation.ts +1 -1
  20. package/internal/src/selector/create-read-write-selector.ts +1 -1
  21. package/internal/src/selector/create-readonly-selector.ts +1 -1
  22. package/internal/src/store/store.ts +4 -4
  23. package/internal/src/store/withdraw.ts +7 -9
  24. package/internal/src/subscribe/subscribe-to-timeline.ts +4 -4
  25. package/internal/src/timeline/add-atom-to-timeline.ts +7 -7
  26. package/internal/src/timeline/create-timeline.ts +29 -21
  27. package/internal/src/timeline/time-travel.ts +1 -1
  28. package/internal/src/transaction/apply-transaction.ts +2 -2
  29. package/internal/src/transaction/build-transaction.ts +1 -1
  30. package/internal/src/transaction/create-transaction.ts +1 -1
  31. package/introspection/dist/index.cjs +9 -9
  32. package/introspection/dist/index.cjs.map +1 -1
  33. package/introspection/dist/index.d.ts +2 -2
  34. package/introspection/dist/index.js +9 -9
  35. package/introspection/dist/index.js.map +1 -1
  36. package/introspection/src/attach-atom-index.ts +2 -2
  37. package/introspection/src/attach-introspection-states.ts +2 -2
  38. package/introspection/src/attach-selector-index.ts +2 -2
  39. package/introspection/src/attach-timeline-family.ts +6 -6
  40. package/introspection/src/attach-timeline-index.ts +6 -4
  41. package/introspection/src/attach-transaction-index.ts +1 -1
  42. package/package.json +8 -9
  43. package/react/dist/index.cjs.map +1 -1
  44. package/react/dist/index.d.ts +1 -1
  45. package/react/dist/index.js.map +1 -1
  46. package/react/src/store-hooks.ts +1 -1
  47. package/react-devtools/dist/index.cjs +7 -9
  48. package/react-devtools/dist/index.cjs.map +1 -1
  49. package/react-devtools/dist/index.d.ts +7 -262
  50. package/react-devtools/dist/index.js +7 -9
  51. package/react-devtools/dist/index.js.map +1 -1
  52. package/react-devtools/src/TimelineIndex.tsx +2 -2
  53. package/react-devtools/src/Updates.tsx +1 -1
  54. package/realtime-client/dist/index.cjs +1 -1
  55. package/realtime-client/dist/index.cjs.map +1 -1
  56. package/realtime-client/dist/index.d.ts +2 -2
  57. package/realtime-client/dist/index.js +1 -1
  58. package/realtime-client/dist/index.js.map +1 -1
  59. package/realtime-client/src/realtime-state.ts +3 -3
  60. package/realtime-react/dist/index.cjs +2 -4
  61. package/realtime-react/dist/index.cjs.map +1 -1
  62. package/realtime-react/dist/index.js +2 -4
  63. package/realtime-react/dist/index.js.map +1 -1
  64. package/realtime-react/src/realtime-context.tsx +2 -4
  65. package/src/index.ts +10 -0
  66. package/src/subscribe.ts +7 -11
  67. package/src/timeline.ts +18 -10
  68. package/src/validators.ts +74 -0
  69. package/dist/chunk-K22LR3V6.js.map +0 -1
  70. package/internal/src/set-state/copy-mutable-into-new-store.ts +0 -34
@@ -328,6 +328,15 @@ var Join = class {
328
328
  nextRelationsOfA.clear();
329
329
  for (const newRelationB of newRelationsOfA) {
330
330
  const relationsOfB = getRelatedKeys(transactors, newRelationB);
331
+ if (this.relations.cardinality === `1:n`) {
332
+ for (const a3 of relationsOfB) {
333
+ const relationsOfA = getRelatedKeys(transactors, a3);
334
+ relationsOfA.delete(newRelationB);
335
+ }
336
+ if (relationsOfB.size > 0) {
337
+ relationsOfB.clear();
338
+ }
339
+ }
331
340
  relationsOfB.add(a2);
332
341
  nextRelationsOfA.add(newRelationB);
333
342
  }
@@ -1 +1 @@
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","createRegularAtomFamily","createSelectorFamily"],"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;;;ACrBA,SAAS,SAAS,UAAU,gBAAgB;AAE5C;AAAA,EACC,YAAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAGP,SAAS,cAAc;;;ACgChB,IAAM,WAAN,MAIL;AAAA,EA0FM,YACN,MACA,QACC;AAzFF,SAAgB,YAAY,oBAAI,IAAyB;AACzD,SAAgB,WAAW,oBAAI,IAAqB;AAGpD,SAAO,iBAAiB,CAAC,GAAW,MAAsB,GAAG,CAAC,IAAI,CAAC;AAhEpE;AAsJE,SAAK,IAAI,KAAK,QAAQ,CAAC;AACvB,SAAK,IAAI,KAAK,QAAQ,CAAC;AAEvB,SAAK,cAAc,KAAK;AACxB,QAAI,EAAC,iCAAQ,gBAAe;AAC3B,WAAK,YAAY,IAAI,KAAI,UAAK,cAAL,mBAAgB,IAAI,CAAC,CAAC,GAAG,CAAC,MAA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tE,IAAM,aAAa,CAAC,QAAgB,WACnC,SAASA,YAAW,MAAM,IAAIA,YAAW,MAAM,IAAI;AAE7C,SAAS,aAGd,SAUA;AACD,QAAM,QAIF,OAAO,KAAK,QAAQ,OAAO,EAAE,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\tMutableAtomFamily,\n\tRead,\n\tReadonlySelectorFamily,\n\tTransactors,\n\tWrite,\n} from \"atom.io\"\nimport { dispose, getState, setState } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tcreateMutableAtomFamily,\n\tcreateRegularAtomFamily,\n\tcreateSelectorFamily,\n\tgetJsonFamily,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { SetRTXJson } from \"atom.io/transceivers/set-rtx\"\nimport { SetRTX } from \"atom.io/transceivers/set-rtx\"\n\nimport type {\n\tBaseExternalStoreConfiguration,\n\tExternalStoreConfiguration,\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>}`]: ReadonlySelectorFamily<\n\t\t\t\t\t\t[string, Content] | null,\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>}`]: ReadonlySelectorFamily<\n\t\t\t\tstring | null,\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>}`]: ReadonlySelectorFamily<\n\t\t\t\t\t\t\t[string, Content] | null,\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>}`]: ReadonlySelectorFamily<\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>}`]: ReadonlySelectorFamily<\n\t\t\t\t\tstring | null,\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>}`]: ReadonlySelectorFamily<\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>}`]: ReadonlySelectorFamily<\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>}`]: ReadonlySelectorFamily<\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 class Join<\n\tconst ASide extends string,\n\tconst BSide extends string,\n\tconst Cardinality extends `1:1` | `1:n` | `n:n`,\n\tconst Content extends Json.Object | null = null,\n> {\n\tprivate transactors: Transactors = TRANSACTORS\n\tpublic relations: Junction<ASide, BSide, Content>\n\tpublic findState: JoinState<ASide, BSide, Cardinality, Content>\n\tpublic core: {\n\t\tfindRelatedKeysState: MutableAtomFamily<\n\t\t\tSetRTX<string>,\n\t\t\tSetRTXJson<string>,\n\t\t\tstring\n\t\t>\n\t}\n\tpublic transact(\n\t\ttransactors: Transactors,\n\t\trun: (join: Join<ASide, BSide, Cardinality, Content>) => void,\n\t): void {\n\t\tthis.transactors = transactors\n\t\trun(this)\n\t\tthis.transactors = TRANSACTORS\n\t}\n\tpublic constructor(\n\t\toptions: JoinOptions<ASide, BSide, Cardinality, Content>,\n\t\tdefaultContent: Content | undefined,\n\t\tstore: Store = IMPLICIT.STORE,\n\t) {\n\t\tconst a: ASide = options.between[0]\n\t\tconst b: BSide = options.between[1]\n\t\tconst findRelatedKeysState = createMutableAtomFamily<\n\t\t\tSetRTX<string>,\n\t\t\tSetRTXJson<string>,\n\t\t\tstring\n\t\t>(\n\t\t\t{\n\t\t\t\tkey: `${options.key}/relatedKeys`,\n\t\t\t\tdefault: () => new SetRTX(),\n\t\t\t\tmutable: true,\n\t\t\t\tfromJson: (json) => SetRTX.fromJSON(json),\n\t\t\t\ttoJson: (set) => set.toJSON(),\n\t\t\t},\n\t\t\tstore,\n\t\t)\n\t\tthis.core = { findRelatedKeysState }\n\t\tconst getRelatedKeys: Read<(key: string) => SetRTX<string>> = (\n\t\t\t{ get },\n\t\t\tkey,\n\t\t) => get(findRelatedKeysState(key))\n\t\tconst addRelation: Write<(a: string, b: string) => void> = (\n\t\t\ttransactors,\n\t\t\ta,\n\t\t\tb,\n\t\t) => {\n\t\t\tconst aKeysState = findRelatedKeysState(a)\n\t\t\tconst bKeysState = findRelatedKeysState(b)\n\t\t\ttransactors.set(aKeysState, (aKeys) => aKeys.add(b))\n\t\t\ttransactors.set(bKeysState, (bKeys) => bKeys.add(a))\n\t\t}\n\t\tconst deleteRelation: Write<(a: string, b: string) => void> = (\n\t\t\ttransactors,\n\t\t\ta,\n\t\t\tb,\n\t\t) => {\n\t\t\tconst aKeys = getRelatedKeys(transactors, a)\n\t\t\taKeys.delete(b)\n\t\t\tconst bKeys = getRelatedKeys(transactors, b)\n\t\t\tbKeys.delete(a)\n\t\t}\n\t\tconst replaceRelationsSafely: Write<\n\t\t\t(a: string, newRelationsOfA: string[]) => void\n\t\t> = (transactors, a, newRelationsOfA) => {\n\t\t\tconst currentRelationsOfA = getRelatedKeys(transactors, a)\n\t\t\tfor (const currentRelationB of currentRelationsOfA) {\n\t\t\t\tconst remainsRelated = newRelationsOfA.includes(currentRelationB)\n\t\t\t\tif (remainsRelated) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst relationsOfB = getRelatedKeys(transactors, currentRelationB)\n\t\t\t\trelationsOfB.delete(a)\n\t\t\t}\n\t\t\tcurrentRelationsOfA.transaction((nextRelationsOfA) => {\n\t\t\t\tnextRelationsOfA.clear()\n\t\t\t\tfor (const newRelationB of newRelationsOfA) {\n\t\t\t\t\tconst relationsOfB = getRelatedKeys(transactors, newRelationB)\n\t\t\t\t\trelationsOfB.add(a)\n\t\t\t\t\tnextRelationsOfA.add(newRelationB)\n\t\t\t\t}\n\t\t\t\treturn true\n\t\t\t})\n\t\t}\n\t\tconst replaceRelationsUnsafely: Write<\n\t\t\t(a: string, newRelationsOfA: string[]) => void\n\t\t> = (transactors, a, newRelationsOfA) => {\n\t\t\tconst relationsOfA = getRelatedKeys(transactors, a)\n\t\t\tfor (const newRelationB of newRelationsOfA) {\n\t\t\t\tconst relationsOfB = getRelatedKeys(transactors, newRelationB)\n\t\t\t\trelationsOfA.add(newRelationB)\n\t\t\t\trelationsOfB.add(a)\n\t\t\t}\n\t\t\treturn true\n\t\t}\n\t\tconst has: Read<(a: string, b?: string) => boolean> = (\n\t\t\ttransactors,\n\t\t\ta,\n\t\t\tb,\n\t\t) => {\n\t\t\tconst aKeys = getRelatedKeys(transactors, a)\n\t\t\treturn b ? aKeys.has(b) : aKeys.size > 0\n\t\t}\n\t\tconst baseExternalStoreConfiguration: BaseExternalStoreConfiguration = {\n\t\t\tgetRelatedKeys: (key) => getRelatedKeys(this.transactors, key),\n\t\t\taddRelation: (a, b) => addRelation(this.transactors, a, b),\n\t\t\tdeleteRelation: (a, b) => deleteRelation(this.transactors, a, b),\n\t\t\treplaceRelationsSafely: (a, bs) =>\n\t\t\t\treplaceRelationsSafely(this.transactors, a, bs),\n\t\t\treplaceRelationsUnsafely: (a, bs) =>\n\t\t\t\treplaceRelationsUnsafely(this.transactors, a, bs),\n\t\t\thas: (a, b) => has(this.transactors, a, b),\n\t\t}\n\t\tlet externalStore: ExternalStoreConfiguration<Content>\n\t\tlet findContentState: AtomFamily<Content, string>\n\t\tif (defaultContent) {\n\t\t\tfindContentState = createRegularAtomFamily<Content, string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/content`,\n\t\t\t\t\tdefault: defaultContent,\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\t\t\tconst getContent: Read<(key: string) => Content | null> = ({ get }, key) =>\n\t\t\t\tget(findContentState(key))\n\t\t\tconst setContent: Write<(key: string, content: Content) => void> = (\n\t\t\t\ttransactors,\n\t\t\t\tkey,\n\t\t\t\tcontent,\n\t\t\t) => transactors.set(findContentState(key), content)\n\t\t\tconst deleteContent: Write<(key: string) => void> = (_, key) =>\n\t\t\t\tdispose(findContentState(key))\n\t\t\tconst externalStoreWithContentConfiguration = {\n\t\t\t\tgetContent: (contentKey: string) => {\n\t\t\t\t\tconst content = getContent(this.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(this.transactors, contentKey, content)\n\t\t\t\t},\n\t\t\t\tdeleteContent: (contentKey: string) => {\n\t\t\t\t\tdeleteContent(this.transactors, contentKey)\n\t\t\t\t},\n\t\t\t}\n\t\t\texternalStore = Object.assign(\n\t\t\t\tbaseExternalStoreConfiguration,\n\t\t\t\texternalStoreWithContentConfiguration,\n\t\t\t) as ExternalStoreConfiguration<Content>\n\t\t} else {\n\t\t\texternalStore =\n\t\t\t\tbaseExternalStoreConfiguration as ExternalStoreConfiguration<Content>\n\t\t}\n\t\tconst relations = new Junction<ASide, BSide, Content>(options, {\n\t\t\texternalStore,\n\t\t\tmakeContentKey: (...args) => args.sort().join(`:`),\n\t\t})\n\n\t\tconst createSingleKeyStateFamily = () =>\n\t\t\tcreateSelectorFamily<string | null, string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/singleRelatedKey`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst relatedKeys = get(findRelatedKeysState(key))\n\t\t\t\t\t\t\tfor (const relatedKey of relatedKeys) {\n\t\t\t\t\t\t\t\treturn relatedKey\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn null\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\t\tconst getMultipleKeyStateFamily = () => {\n\t\t\treturn createSelectorFamily<string[], string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/multipleRelatedKeys`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst jsonFamily = getJsonFamily(findRelatedKeysState, store)\n\t\t\t\t\t\t\tconst json = get(jsonFamily(key))\n\t\t\t\t\t\t\treturn json.members\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\t\t}\n\t\tconst createSingleEntryStateFamily = () =>\n\t\t\tcreateSelectorFamily<[string, Content] | null, string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/singleRelatedEntry`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst relatedKeys = get(findRelatedKeysState(key))\n\t\t\t\t\t\t\tfor (const relatedKey of relatedKeys) {\n\t\t\t\t\t\t\t\tconst contentKey = relations.makeContentKey(key, relatedKey)\n\t\t\t\t\t\t\t\treturn [relatedKey, get(findContentState(contentKey))]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn null\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\t\tconst getMultipleEntryStateFamily = () =>\n\t\t\tcreateSelectorFamily<[string, Content][], string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/multipleRelatedEntries`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst jsonFamily = getJsonFamily(findRelatedKeysState, store)\n\t\t\t\t\t\t\tconst json = get(jsonFamily(key))\n\t\t\t\t\t\t\treturn json.members.map((relatedKey) => {\n\t\t\t\t\t\t\t\tconst contentKey = relations.makeContentKey(key, relatedKey)\n\t\t\t\t\t\t\t\treturn [relatedKey, get(findContentState(contentKey))]\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\n\t\tswitch (options.cardinality) {\n\t\t\tcase `1:1`: {\n\t\t\t\tconst findSingleRelatedKeyState = createSingleKeyStateFamily()\n\t\t\t\tconst stateKeyA = `${a}KeyOf${capitalize(b)}` as const\n\t\t\t\tconst stateKeyB = `${b}KeyOf${capitalize(a)}` as const\n\t\t\t\tconst findStateBase = {\n\t\t\t\t\t[stateKeyA]: findSingleRelatedKeyState,\n\t\t\t\t\t[stateKeyB]: findSingleRelatedKeyState,\n\t\t\t\t} as JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tlet findState: JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tif (defaultContent) {\n\t\t\t\t\tconst findSingleRelatedEntryState = createSingleEntryStateFamily()\n\t\t\t\t\tconst entriesStateKeyA = `${a}EntryOf${capitalize(b)}` as const\n\t\t\t\t\tconst entriesStateKeyB = `${b}EntryOf${capitalize(a)}` as const\n\t\t\t\t\tconst findStateWithContent = {\n\t\t\t\t\t\t[entriesStateKeyA]: findSingleRelatedEntryState,\n\t\t\t\t\t\t[entriesStateKeyB]: findSingleRelatedEntryState,\n\t\t\t\t\t}\n\t\t\t\t\tfindState = Object.assign(findStateBase, findStateWithContent)\n\t\t\t\t} else {\n\t\t\t\t\tfindState = findStateBase\n\t\t\t\t}\n\t\t\t\tthis.relations = relations\n\t\t\t\tthis.findState = findState\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase `1:n`: {\n\t\t\t\tconst findSingleRelatedKeyState = createSingleKeyStateFamily()\n\t\t\t\tconst findMultipleRelatedKeysState = getMultipleKeyStateFamily()\n\t\t\t\tconst stateKeyA = `${a}KeyOf${capitalize(b)}` as const\n\t\t\t\tconst stateKeyB = `${b}KeysOf${capitalize(a)}` as const\n\t\t\t\tconst findStateBase = {\n\t\t\t\t\t[stateKeyA]: findSingleRelatedKeyState,\n\t\t\t\t\t[stateKeyB]: findMultipleRelatedKeysState,\n\t\t\t\t} as JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tlet findState: JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tif (defaultContent) {\n\t\t\t\t\tconst findSingleRelatedEntryState = createSingleEntryStateFamily()\n\t\t\t\t\tconst findMultipleRelatedEntriesState = getMultipleEntryStateFamily()\n\t\t\t\t\tconst entriesStateKeyA = `${a}EntryOf${capitalize(b)}` as const\n\t\t\t\t\tconst entriesStateKeyB = `${b}EntriesOf${capitalize(a)}` as const\n\t\t\t\t\tconst findStateWithContent = {\n\t\t\t\t\t\t[entriesStateKeyA]: findSingleRelatedEntryState,\n\t\t\t\t\t\t[entriesStateKeyB]: findMultipleRelatedEntriesState,\n\t\t\t\t\t}\n\t\t\t\t\tfindState = Object.assign(findStateBase, findStateWithContent)\n\t\t\t\t} else {\n\t\t\t\t\tfindState = findStateBase\n\t\t\t\t}\n\t\t\t\tthis.relations = relations\n\t\t\t\tthis.findState = findState\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tconst findMultipleRelatedKeysState = getMultipleKeyStateFamily()\n\t\t\t\tconst stateKeyA = `${a}KeysOf${capitalize(b)}` as const\n\t\t\t\tconst stateKeyB = `${b}KeysOf${capitalize(a)}` as const\n\t\t\t\tconst findStateBase = {\n\t\t\t\t\t[stateKeyA]: findMultipleRelatedKeysState,\n\t\t\t\t\t[stateKeyB]: findMultipleRelatedKeysState,\n\t\t\t\t} as JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tlet findState: JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tif (defaultContent) {\n\t\t\t\t\tconst findMultipleRelatedEntriesState = getMultipleEntryStateFamily()\n\t\t\t\t\tconst entriesStateKeyA = `${a}EntriesOf${capitalize(b)}` as const\n\t\t\t\t\tconst entriesStateKeyB = `${b}EntriesOf${capitalize(a)}` as const\n\t\t\t\t\tconst findStateWithContent = {\n\t\t\t\t\t\t[entriesStateKeyA]: findMultipleRelatedEntriesState,\n\t\t\t\t\t\t[entriesStateKeyB]: findMultipleRelatedEntriesState,\n\t\t\t\t\t}\n\t\t\t\t\tfindState = Object.assign(findStateBase, findStateWithContent)\n\t\t\t\t} else {\n\t\t\t\t\tfindState = findStateBase\n\t\t\t\t}\n\t\t\t\tthis.relations = relations\n\t\t\t\tthis.findState = findState\n\t\t\t}\n\t\t}\n\t}\n}\nexport function join<\n\tconst ASide extends string,\n\tconst BSide extends string,\n\tconst Cardinality extends `1:1` | `1:n` | `n:n`,\n>(\n\toptions: JoinOptions<ASide, BSide, Cardinality, null>,\n\tdefaultContent?: undefined,\n\tstore?: Store,\n): {\n\treadonly relations: Junction<ASide, BSide, null>\n\treadonly findState: JoinState<ASide, BSide, Cardinality, null>\n\treadonly transact: (\n\t\ttransactors: Transactors,\n\t\trun: (join: Join<ASide, BSide, Cardinality, null>) => void,\n\t) => void\n\treadonly core: {\n\t\treadonly findRelatedKeysState: MutableAtomFamily<\n\t\t\tSetRTX<string>,\n\t\t\tSetRTXJson<string>,\n\t\t\tstring\n\t\t>\n\t}\n}\nexport function join<\n\tconst ASide extends string,\n\tconst BSide extends string,\n\tconst Cardinality extends `1:1` | `1:n` | `n:n`,\n\tconst Content extends Json.Object,\n>(\n\toptions: JoinOptions<ASide, BSide, Cardinality, Content>,\n\tdefaultContent: Content,\n\tstore?: Store,\n): {\n\treadonly relations: Junction<ASide, BSide, Content>\n\treadonly findState: JoinState<ASide, BSide, Cardinality, Content>\n\treadonly transact: (\n\t\ttransactors: Transactors,\n\t\trun: (join: Join<ASide, BSide, Cardinality, Content>) => void,\n\t) => void\n\treadonly core: {\n\t\treadonly findRelatedKeysState: MutableAtomFamily<\n\t\t\tSetRTX<string>,\n\t\t\tSetRTXJson<string>,\n\t\t\tstring\n\t\t>\n\t}\n}\nexport function join<\n\tASide extends string,\n\tBSide extends string,\n\tCardinality extends `1:1` | `1:n` | `n:n`,\n\tContent extends Json.Object,\n>(\n\toptions: JoinOptions<ASide, BSide, Cardinality, Content>,\n\tdefaultContent: Content | undefined,\n\tstore: Store = IMPLICIT.STORE,\n): Join<ASide, BSide, Cardinality, Content> {\n\treturn new Join(options, defaultContent, store)\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 { createRegularAtom, 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] = createRegularAtom(\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\tcreateRegularAtomFamily,\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] = createRegularAtomFamily(\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"]}
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","createRegularAtomFamily","createSelectorFamily"],"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;;;ACrBA,SAAS,SAAS,UAAU,gBAAgB;AAE5C;AAAA,EACC,YAAA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,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\tMutableAtomFamily,\n\tRead,\n\tReadonlySelectorFamily,\n\tTransactors,\n\tWrite,\n} from \"atom.io\"\nimport { dispose, getState, setState } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tcreateMutableAtomFamily,\n\tcreateRegularAtomFamily,\n\tcreateSelectorFamily,\n\tgetJsonFamily,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { SetRTXJson } from \"atom.io/transceivers/set-rtx\"\nimport { SetRTX } from \"atom.io/transceivers/set-rtx\"\n\nimport type {\n\tBaseExternalStoreConfiguration,\n\tExternalStoreConfiguration,\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>}`]: ReadonlySelectorFamily<\n\t\t\t\t\t\t[string, Content] | null,\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>}`]: ReadonlySelectorFamily<\n\t\t\t\tstring | null,\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>}`]: ReadonlySelectorFamily<\n\t\t\t\t\t\t\t[string, Content] | null,\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>}`]: ReadonlySelectorFamily<\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>}`]: ReadonlySelectorFamily<\n\t\t\t\t\tstring | null,\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>}`]: ReadonlySelectorFamily<\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>}`]: ReadonlySelectorFamily<\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>}`]: ReadonlySelectorFamily<\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 class Join<\n\tconst ASide extends string,\n\tconst BSide extends string,\n\tconst Cardinality extends `1:1` | `1:n` | `n:n`,\n\tconst Content extends Json.Object | null = null,\n> {\n\tprivate transactors: Transactors = TRANSACTORS\n\tpublic relations: Junction<ASide, BSide, Content>\n\tpublic findState: JoinState<ASide, BSide, Cardinality, Content>\n\tpublic core: {\n\t\tfindRelatedKeysState: MutableAtomFamily<\n\t\t\tSetRTX<string>,\n\t\t\tSetRTXJson<string>,\n\t\t\tstring\n\t\t>\n\t}\n\tpublic transact(\n\t\ttransactors: Transactors,\n\t\trun: (join: Join<ASide, BSide, Cardinality, Content>) => void,\n\t): void {\n\t\tthis.transactors = transactors\n\t\trun(this)\n\t\tthis.transactors = TRANSACTORS\n\t}\n\tpublic constructor(\n\t\toptions: JoinOptions<ASide, BSide, Cardinality, Content>,\n\t\tdefaultContent: Content | undefined,\n\t\tstore: Store = IMPLICIT.STORE,\n\t) {\n\t\tconst a: ASide = options.between[0]\n\t\tconst b: BSide = options.between[1]\n\t\tconst findRelatedKeysState = createMutableAtomFamily<\n\t\t\tSetRTX<string>,\n\t\t\tSetRTXJson<string>,\n\t\t\tstring\n\t\t>(\n\t\t\t{\n\t\t\t\tkey: `${options.key}/relatedKeys`,\n\t\t\t\tdefault: () => new SetRTX(),\n\t\t\t\tmutable: true,\n\t\t\t\tfromJson: (json) => SetRTX.fromJSON(json),\n\t\t\t\ttoJson: (set) => set.toJSON(),\n\t\t\t},\n\t\t\tstore,\n\t\t)\n\t\tthis.core = { findRelatedKeysState }\n\t\tconst getRelatedKeys: Read<(key: string) => SetRTX<string>> = (\n\t\t\t{ get },\n\t\t\tkey,\n\t\t) => get(findRelatedKeysState(key))\n\t\tconst addRelation: Write<(a: string, b: string) => void> = (\n\t\t\ttransactors,\n\t\t\ta,\n\t\t\tb,\n\t\t) => {\n\t\t\tconst aKeysState = findRelatedKeysState(a)\n\t\t\tconst bKeysState = findRelatedKeysState(b)\n\t\t\ttransactors.set(aKeysState, (aKeys) => aKeys.add(b))\n\t\t\ttransactors.set(bKeysState, (bKeys) => bKeys.add(a))\n\t\t}\n\t\tconst deleteRelation: Write<(a: string, b: string) => void> = (\n\t\t\ttransactors,\n\t\t\ta,\n\t\t\tb,\n\t\t) => {\n\t\t\tconst aKeys = getRelatedKeys(transactors, a)\n\t\t\taKeys.delete(b)\n\t\t\tconst bKeys = getRelatedKeys(transactors, b)\n\t\t\tbKeys.delete(a)\n\t\t}\n\t\tconst replaceRelationsSafely: Write<\n\t\t\t(a: string, newRelationsOfA: string[]) => void\n\t\t> = (transactors, a, newRelationsOfA) => {\n\t\t\tconst currentRelationsOfA = getRelatedKeys(transactors, a)\n\t\t\tfor (const currentRelationB of currentRelationsOfA) {\n\t\t\t\tconst remainsRelated = newRelationsOfA.includes(currentRelationB)\n\t\t\t\tif (remainsRelated) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst relationsOfB = getRelatedKeys(transactors, currentRelationB)\n\t\t\t\trelationsOfB.delete(a)\n\t\t\t}\n\t\t\tcurrentRelationsOfA.transaction((nextRelationsOfA) => {\n\t\t\t\tnextRelationsOfA.clear()\n\t\t\t\tfor (const newRelationB of newRelationsOfA) {\n\t\t\t\t\tconst relationsOfB = getRelatedKeys(transactors, newRelationB)\n\t\t\t\t\tif (this.relations.cardinality === `1:n`) {\n\t\t\t\t\t\tfor (const a of relationsOfB) {\n\t\t\t\t\t\t\tconst relationsOfA = getRelatedKeys(transactors, a)\n\t\t\t\t\t\t\trelationsOfA.delete(newRelationB)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (relationsOfB.size > 0) {\n\t\t\t\t\t\t\trelationsOfB.clear()\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\trelationsOfB.add(a)\n\t\t\t\t\tnextRelationsOfA.add(newRelationB)\n\t\t\t\t}\n\t\t\t\treturn true\n\t\t\t})\n\t\t}\n\t\tconst replaceRelationsUnsafely: Write<\n\t\t\t(a: string, newRelationsOfA: string[]) => void\n\t\t> = (transactors, a, newRelationsOfA) => {\n\t\t\tconst relationsOfA = getRelatedKeys(transactors, a)\n\t\t\tfor (const newRelationB of newRelationsOfA) {\n\t\t\t\tconst relationsOfB = getRelatedKeys(transactors, newRelationB)\n\t\t\t\trelationsOfA.add(newRelationB)\n\t\t\t\trelationsOfB.add(a)\n\t\t\t}\n\t\t\treturn true\n\t\t}\n\t\tconst has: Read<(a: string, b?: string) => boolean> = (\n\t\t\ttransactors,\n\t\t\ta,\n\t\t\tb,\n\t\t) => {\n\t\t\tconst aKeys = getRelatedKeys(transactors, a)\n\t\t\treturn b ? aKeys.has(b) : aKeys.size > 0\n\t\t}\n\t\tconst baseExternalStoreConfiguration: BaseExternalStoreConfiguration = {\n\t\t\tgetRelatedKeys: (key) => getRelatedKeys(this.transactors, key),\n\t\t\taddRelation: (a, b) => addRelation(this.transactors, a, b),\n\t\t\tdeleteRelation: (a, b) => deleteRelation(this.transactors, a, b),\n\t\t\treplaceRelationsSafely: (a, bs) =>\n\t\t\t\treplaceRelationsSafely(this.transactors, a, bs),\n\t\t\treplaceRelationsUnsafely: (a, bs) =>\n\t\t\t\treplaceRelationsUnsafely(this.transactors, a, bs),\n\t\t\thas: (a, b) => has(this.transactors, a, b),\n\t\t}\n\t\tlet externalStore: ExternalStoreConfiguration<Content>\n\t\tlet findContentState: AtomFamily<Content, string>\n\t\tif (defaultContent) {\n\t\t\tfindContentState = createRegularAtomFamily<Content, string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/content`,\n\t\t\t\t\tdefault: defaultContent,\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\t\t\tconst getContent: Read<(key: string) => Content | null> = ({ get }, key) =>\n\t\t\t\tget(findContentState(key))\n\t\t\tconst setContent: Write<(key: string, content: Content) => void> = (\n\t\t\t\ttransactors,\n\t\t\t\tkey,\n\t\t\t\tcontent,\n\t\t\t) => transactors.set(findContentState(key), content)\n\t\t\tconst deleteContent: Write<(key: string) => void> = (_, key) =>\n\t\t\t\tdispose(findContentState(key))\n\t\t\tconst externalStoreWithContentConfiguration = {\n\t\t\t\tgetContent: (contentKey: string) => {\n\t\t\t\t\tconst content = getContent(this.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(this.transactors, contentKey, content)\n\t\t\t\t},\n\t\t\t\tdeleteContent: (contentKey: string) => {\n\t\t\t\t\tdeleteContent(this.transactors, contentKey)\n\t\t\t\t},\n\t\t\t}\n\t\t\texternalStore = Object.assign(\n\t\t\t\tbaseExternalStoreConfiguration,\n\t\t\t\texternalStoreWithContentConfiguration,\n\t\t\t) as ExternalStoreConfiguration<Content>\n\t\t} else {\n\t\t\texternalStore =\n\t\t\t\tbaseExternalStoreConfiguration as ExternalStoreConfiguration<Content>\n\t\t}\n\t\tconst relations = new Junction<ASide, BSide, Content>(options, {\n\t\t\texternalStore,\n\t\t\tmakeContentKey: (...args) => args.sort().join(`:`),\n\t\t})\n\n\t\tconst createSingleKeyStateFamily = () =>\n\t\t\tcreateSelectorFamily<string | null, string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/singleRelatedKey`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst relatedKeys = get(findRelatedKeysState(key))\n\t\t\t\t\t\t\tfor (const relatedKey of relatedKeys) {\n\t\t\t\t\t\t\t\treturn relatedKey\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn null\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\t\tconst getMultipleKeyStateFamily = () => {\n\t\t\treturn createSelectorFamily<string[], string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/multipleRelatedKeys`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst jsonFamily = getJsonFamily(findRelatedKeysState, store)\n\t\t\t\t\t\t\tconst json = get(jsonFamily(key))\n\t\t\t\t\t\t\treturn json.members\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\t\t}\n\t\tconst createSingleEntryStateFamily = () =>\n\t\t\tcreateSelectorFamily<[string, Content] | null, string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/singleRelatedEntry`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst relatedKeys = get(findRelatedKeysState(key))\n\t\t\t\t\t\t\tfor (const relatedKey of relatedKeys) {\n\t\t\t\t\t\t\t\tconst contentKey = relations.makeContentKey(key, relatedKey)\n\t\t\t\t\t\t\t\treturn [relatedKey, get(findContentState(contentKey))]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn null\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\t\tconst getMultipleEntryStateFamily = () =>\n\t\t\tcreateSelectorFamily<[string, Content][], string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/multipleRelatedEntries`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst jsonFamily = getJsonFamily(findRelatedKeysState, store)\n\t\t\t\t\t\t\tconst json = get(jsonFamily(key))\n\t\t\t\t\t\t\treturn json.members.map((relatedKey) => {\n\t\t\t\t\t\t\t\tconst contentKey = relations.makeContentKey(key, relatedKey)\n\t\t\t\t\t\t\t\treturn [relatedKey, get(findContentState(contentKey))]\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\n\t\tswitch (options.cardinality) {\n\t\t\tcase `1:1`: {\n\t\t\t\tconst findSingleRelatedKeyState = createSingleKeyStateFamily()\n\t\t\t\tconst stateKeyA = `${a}KeyOf${capitalize(b)}` as const\n\t\t\t\tconst stateKeyB = `${b}KeyOf${capitalize(a)}` as const\n\t\t\t\tconst findStateBase = {\n\t\t\t\t\t[stateKeyA]: findSingleRelatedKeyState,\n\t\t\t\t\t[stateKeyB]: findSingleRelatedKeyState,\n\t\t\t\t} as JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tlet findState: JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tif (defaultContent) {\n\t\t\t\t\tconst findSingleRelatedEntryState = createSingleEntryStateFamily()\n\t\t\t\t\tconst entriesStateKeyA = `${a}EntryOf${capitalize(b)}` as const\n\t\t\t\t\tconst entriesStateKeyB = `${b}EntryOf${capitalize(a)}` as const\n\t\t\t\t\tconst findStateWithContent = {\n\t\t\t\t\t\t[entriesStateKeyA]: findSingleRelatedEntryState,\n\t\t\t\t\t\t[entriesStateKeyB]: findSingleRelatedEntryState,\n\t\t\t\t\t}\n\t\t\t\t\tfindState = Object.assign(findStateBase, findStateWithContent)\n\t\t\t\t} else {\n\t\t\t\t\tfindState = findStateBase\n\t\t\t\t}\n\t\t\t\tthis.relations = relations\n\t\t\t\tthis.findState = findState\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase `1:n`: {\n\t\t\t\tconst findSingleRelatedKeyState = createSingleKeyStateFamily()\n\t\t\t\tconst findMultipleRelatedKeysState = getMultipleKeyStateFamily()\n\t\t\t\tconst stateKeyA = `${a}KeyOf${capitalize(b)}` as const\n\t\t\t\tconst stateKeyB = `${b}KeysOf${capitalize(a)}` as const\n\t\t\t\tconst findStateBase = {\n\t\t\t\t\t[stateKeyA]: findSingleRelatedKeyState,\n\t\t\t\t\t[stateKeyB]: findMultipleRelatedKeysState,\n\t\t\t\t} as JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tlet findState: JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tif (defaultContent) {\n\t\t\t\t\tconst findSingleRelatedEntryState = createSingleEntryStateFamily()\n\t\t\t\t\tconst findMultipleRelatedEntriesState = getMultipleEntryStateFamily()\n\t\t\t\t\tconst entriesStateKeyA = `${a}EntryOf${capitalize(b)}` as const\n\t\t\t\t\tconst entriesStateKeyB = `${b}EntriesOf${capitalize(a)}` as const\n\t\t\t\t\tconst findStateWithContent = {\n\t\t\t\t\t\t[entriesStateKeyA]: findSingleRelatedEntryState,\n\t\t\t\t\t\t[entriesStateKeyB]: findMultipleRelatedEntriesState,\n\t\t\t\t\t}\n\t\t\t\t\tfindState = Object.assign(findStateBase, findStateWithContent)\n\t\t\t\t} else {\n\t\t\t\t\tfindState = findStateBase\n\t\t\t\t}\n\t\t\t\tthis.relations = relations\n\t\t\t\tthis.findState = findState\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tconst findMultipleRelatedKeysState = getMultipleKeyStateFamily()\n\t\t\t\tconst stateKeyA = `${a}KeysOf${capitalize(b)}` as const\n\t\t\t\tconst stateKeyB = `${b}KeysOf${capitalize(a)}` as const\n\t\t\t\tconst findStateBase = {\n\t\t\t\t\t[stateKeyA]: findMultipleRelatedKeysState,\n\t\t\t\t\t[stateKeyB]: findMultipleRelatedKeysState,\n\t\t\t\t} as JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tlet findState: JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tif (defaultContent) {\n\t\t\t\t\tconst findMultipleRelatedEntriesState = getMultipleEntryStateFamily()\n\t\t\t\t\tconst entriesStateKeyA = `${a}EntriesOf${capitalize(b)}` as const\n\t\t\t\t\tconst entriesStateKeyB = `${b}EntriesOf${capitalize(a)}` as const\n\t\t\t\t\tconst findStateWithContent = {\n\t\t\t\t\t\t[entriesStateKeyA]: findMultipleRelatedEntriesState,\n\t\t\t\t\t\t[entriesStateKeyB]: findMultipleRelatedEntriesState,\n\t\t\t\t\t}\n\t\t\t\t\tfindState = Object.assign(findStateBase, findStateWithContent)\n\t\t\t\t} else {\n\t\t\t\t\tfindState = findStateBase\n\t\t\t\t}\n\t\t\t\tthis.relations = relations\n\t\t\t\tthis.findState = findState\n\t\t\t}\n\t\t}\n\t}\n}\nexport function join<\n\tconst ASide extends string,\n\tconst BSide extends string,\n\tconst Cardinality extends `1:1` | `1:n` | `n:n`,\n>(\n\toptions: JoinOptions<ASide, BSide, Cardinality, null>,\n\tdefaultContent?: undefined,\n\tstore?: Store,\n): {\n\treadonly relations: Junction<ASide, BSide, null>\n\treadonly findState: JoinState<ASide, BSide, Cardinality, null>\n\treadonly transact: (\n\t\ttransactors: Transactors,\n\t\trun: (join: Join<ASide, BSide, Cardinality, null>) => void,\n\t) => void\n\treadonly core: {\n\t\treadonly findRelatedKeysState: MutableAtomFamily<\n\t\t\tSetRTX<string>,\n\t\t\tSetRTXJson<string>,\n\t\t\tstring\n\t\t>\n\t}\n}\nexport function join<\n\tconst ASide extends string,\n\tconst BSide extends string,\n\tconst Cardinality extends `1:1` | `1:n` | `n:n`,\n\tconst Content extends Json.Object,\n>(\n\toptions: JoinOptions<ASide, BSide, Cardinality, Content>,\n\tdefaultContent: Content,\n\tstore?: Store,\n): {\n\treadonly relations: Junction<ASide, BSide, Content>\n\treadonly findState: JoinState<ASide, BSide, Cardinality, Content>\n\treadonly transact: (\n\t\ttransactors: Transactors,\n\t\trun: (join: Join<ASide, BSide, Cardinality, Content>) => void,\n\t) => void\n\treadonly core: {\n\t\treadonly findRelatedKeysState: MutableAtomFamily<\n\t\t\tSetRTX<string>,\n\t\t\tSetRTXJson<string>,\n\t\t\tstring\n\t\t>\n\t}\n}\nexport function join<\n\tASide extends string,\n\tBSide extends string,\n\tCardinality extends `1:1` | `1:n` | `n:n`,\n\tContent extends Json.Object,\n>(\n\toptions: JoinOptions<ASide, BSide, Cardinality, Content>,\n\tdefaultContent: Content | undefined,\n\tstore: Store = IMPLICIT.STORE,\n): Join<ASide, BSide, Cardinality, Content> {\n\treturn new Join(options, defaultContent, store)\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 { createRegularAtom, 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] = createRegularAtom(\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\tcreateRegularAtomFamily,\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] = createRegularAtomFamily(\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"]}
@@ -67,6 +67,15 @@ var Join = class {
67
67
  nextRelationsOfA.clear();
68
68
  for (const newRelationB of newRelationsOfA) {
69
69
  const relationsOfB = getRelatedKeys(transactors, newRelationB);
70
+ if (this.relations.cardinality === `1:n`) {
71
+ for (const a3 of relationsOfB) {
72
+ const relationsOfA = getRelatedKeys(transactors, a3);
73
+ relationsOfA.delete(newRelationB);
74
+ }
75
+ if (relationsOfB.size > 0) {
76
+ relationsOfB.clear();
77
+ }
78
+ }
70
79
  relationsOfB.add(a2);
71
80
  nextRelationsOfA.add(newRelationB);
72
81
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/dict.ts","../src/join.ts","../src/struct.ts","../src/struct-family.ts","../src/until.ts"],"names":["IMPLICIT","a","b","createSelector","capitalize","createRegularAtomFamily","createSelectorFamily"],"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;A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;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\tMutableAtomFamily,\n\tRead,\n\tReadonlySelectorFamily,\n\tTransactors,\n\tWrite,\n} from \"atom.io\"\nimport { dispose, getState, setState } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tcreateMutableAtomFamily,\n\tcreateRegularAtomFamily,\n\tcreateSelectorFamily,\n\tgetJsonFamily,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { SetRTXJson } from \"atom.io/transceivers/set-rtx\"\nimport { SetRTX } from \"atom.io/transceivers/set-rtx\"\n\nimport type {\n\tBaseExternalStoreConfiguration,\n\tExternalStoreConfiguration,\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>}`]: ReadonlySelectorFamily<\n\t\t\t\t\t\t[string, Content] | null,\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>}`]: ReadonlySelectorFamily<\n\t\t\t\tstring | null,\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>}`]: ReadonlySelectorFamily<\n\t\t\t\t\t\t\t[string, Content] | null,\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>}`]: ReadonlySelectorFamily<\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>}`]: ReadonlySelectorFamily<\n\t\t\t\t\tstring | null,\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>}`]: ReadonlySelectorFamily<\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>}`]: ReadonlySelectorFamily<\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>}`]: ReadonlySelectorFamily<\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 class Join<\n\tconst ASide extends string,\n\tconst BSide extends string,\n\tconst Cardinality extends `1:1` | `1:n` | `n:n`,\n\tconst Content extends Json.Object | null = null,\n> {\n\tprivate transactors: Transactors = TRANSACTORS\n\tpublic relations: Junction<ASide, BSide, Content>\n\tpublic findState: JoinState<ASide, BSide, Cardinality, Content>\n\tpublic core: {\n\t\tfindRelatedKeysState: MutableAtomFamily<\n\t\t\tSetRTX<string>,\n\t\t\tSetRTXJson<string>,\n\t\t\tstring\n\t\t>\n\t}\n\tpublic transact(\n\t\ttransactors: Transactors,\n\t\trun: (join: Join<ASide, BSide, Cardinality, Content>) => void,\n\t): void {\n\t\tthis.transactors = transactors\n\t\trun(this)\n\t\tthis.transactors = TRANSACTORS\n\t}\n\tpublic constructor(\n\t\toptions: JoinOptions<ASide, BSide, Cardinality, Content>,\n\t\tdefaultContent: Content | undefined,\n\t\tstore: Store = IMPLICIT.STORE,\n\t) {\n\t\tconst a: ASide = options.between[0]\n\t\tconst b: BSide = options.between[1]\n\t\tconst findRelatedKeysState = createMutableAtomFamily<\n\t\t\tSetRTX<string>,\n\t\t\tSetRTXJson<string>,\n\t\t\tstring\n\t\t>(\n\t\t\t{\n\t\t\t\tkey: `${options.key}/relatedKeys`,\n\t\t\t\tdefault: () => new SetRTX(),\n\t\t\t\tmutable: true,\n\t\t\t\tfromJson: (json) => SetRTX.fromJSON(json),\n\t\t\t\ttoJson: (set) => set.toJSON(),\n\t\t\t},\n\t\t\tstore,\n\t\t)\n\t\tthis.core = { findRelatedKeysState }\n\t\tconst getRelatedKeys: Read<(key: string) => SetRTX<string>> = (\n\t\t\t{ get },\n\t\t\tkey,\n\t\t) => get(findRelatedKeysState(key))\n\t\tconst addRelation: Write<(a: string, b: string) => void> = (\n\t\t\ttransactors,\n\t\t\ta,\n\t\t\tb,\n\t\t) => {\n\t\t\tconst aKeysState = findRelatedKeysState(a)\n\t\t\tconst bKeysState = findRelatedKeysState(b)\n\t\t\ttransactors.set(aKeysState, (aKeys) => aKeys.add(b))\n\t\t\ttransactors.set(bKeysState, (bKeys) => bKeys.add(a))\n\t\t}\n\t\tconst deleteRelation: Write<(a: string, b: string) => void> = (\n\t\t\ttransactors,\n\t\t\ta,\n\t\t\tb,\n\t\t) => {\n\t\t\tconst aKeys = getRelatedKeys(transactors, a)\n\t\t\taKeys.delete(b)\n\t\t\tconst bKeys = getRelatedKeys(transactors, b)\n\t\t\tbKeys.delete(a)\n\t\t}\n\t\tconst replaceRelationsSafely: Write<\n\t\t\t(a: string, newRelationsOfA: string[]) => void\n\t\t> = (transactors, a, newRelationsOfA) => {\n\t\t\tconst currentRelationsOfA = getRelatedKeys(transactors, a)\n\t\t\tfor (const currentRelationB of currentRelationsOfA) {\n\t\t\t\tconst remainsRelated = newRelationsOfA.includes(currentRelationB)\n\t\t\t\tif (remainsRelated) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst relationsOfB = getRelatedKeys(transactors, currentRelationB)\n\t\t\t\trelationsOfB.delete(a)\n\t\t\t}\n\t\t\tcurrentRelationsOfA.transaction((nextRelationsOfA) => {\n\t\t\t\tnextRelationsOfA.clear()\n\t\t\t\tfor (const newRelationB of newRelationsOfA) {\n\t\t\t\t\tconst relationsOfB = getRelatedKeys(transactors, newRelationB)\n\t\t\t\t\trelationsOfB.add(a)\n\t\t\t\t\tnextRelationsOfA.add(newRelationB)\n\t\t\t\t}\n\t\t\t\treturn true\n\t\t\t})\n\t\t}\n\t\tconst replaceRelationsUnsafely: Write<\n\t\t\t(a: string, newRelationsOfA: string[]) => void\n\t\t> = (transactors, a, newRelationsOfA) => {\n\t\t\tconst relationsOfA = getRelatedKeys(transactors, a)\n\t\t\tfor (const newRelationB of newRelationsOfA) {\n\t\t\t\tconst relationsOfB = getRelatedKeys(transactors, newRelationB)\n\t\t\t\trelationsOfA.add(newRelationB)\n\t\t\t\trelationsOfB.add(a)\n\t\t\t}\n\t\t\treturn true\n\t\t}\n\t\tconst has: Read<(a: string, b?: string) => boolean> = (\n\t\t\ttransactors,\n\t\t\ta,\n\t\t\tb,\n\t\t) => {\n\t\t\tconst aKeys = getRelatedKeys(transactors, a)\n\t\t\treturn b ? aKeys.has(b) : aKeys.size > 0\n\t\t}\n\t\tconst baseExternalStoreConfiguration: BaseExternalStoreConfiguration = {\n\t\t\tgetRelatedKeys: (key) => getRelatedKeys(this.transactors, key),\n\t\t\taddRelation: (a, b) => addRelation(this.transactors, a, b),\n\t\t\tdeleteRelation: (a, b) => deleteRelation(this.transactors, a, b),\n\t\t\treplaceRelationsSafely: (a, bs) =>\n\t\t\t\treplaceRelationsSafely(this.transactors, a, bs),\n\t\t\treplaceRelationsUnsafely: (a, bs) =>\n\t\t\t\treplaceRelationsUnsafely(this.transactors, a, bs),\n\t\t\thas: (a, b) => has(this.transactors, a, b),\n\t\t}\n\t\tlet externalStore: ExternalStoreConfiguration<Content>\n\t\tlet findContentState: AtomFamily<Content, string>\n\t\tif (defaultContent) {\n\t\t\tfindContentState = createRegularAtomFamily<Content, string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/content`,\n\t\t\t\t\tdefault: defaultContent,\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\t\t\tconst getContent: Read<(key: string) => Content | null> = ({ get }, key) =>\n\t\t\t\tget(findContentState(key))\n\t\t\tconst setContent: Write<(key: string, content: Content) => void> = (\n\t\t\t\ttransactors,\n\t\t\t\tkey,\n\t\t\t\tcontent,\n\t\t\t) => transactors.set(findContentState(key), content)\n\t\t\tconst deleteContent: Write<(key: string) => void> = (_, key) =>\n\t\t\t\tdispose(findContentState(key))\n\t\t\tconst externalStoreWithContentConfiguration = {\n\t\t\t\tgetContent: (contentKey: string) => {\n\t\t\t\t\tconst content = getContent(this.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(this.transactors, contentKey, content)\n\t\t\t\t},\n\t\t\t\tdeleteContent: (contentKey: string) => {\n\t\t\t\t\tdeleteContent(this.transactors, contentKey)\n\t\t\t\t},\n\t\t\t}\n\t\t\texternalStore = Object.assign(\n\t\t\t\tbaseExternalStoreConfiguration,\n\t\t\t\texternalStoreWithContentConfiguration,\n\t\t\t) as ExternalStoreConfiguration<Content>\n\t\t} else {\n\t\t\texternalStore =\n\t\t\t\tbaseExternalStoreConfiguration as ExternalStoreConfiguration<Content>\n\t\t}\n\t\tconst relations = new Junction<ASide, BSide, Content>(options, {\n\t\t\texternalStore,\n\t\t\tmakeContentKey: (...args) => args.sort().join(`:`),\n\t\t})\n\n\t\tconst createSingleKeyStateFamily = () =>\n\t\t\tcreateSelectorFamily<string | null, string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/singleRelatedKey`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst relatedKeys = get(findRelatedKeysState(key))\n\t\t\t\t\t\t\tfor (const relatedKey of relatedKeys) {\n\t\t\t\t\t\t\t\treturn relatedKey\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn null\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\t\tconst getMultipleKeyStateFamily = () => {\n\t\t\treturn createSelectorFamily<string[], string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/multipleRelatedKeys`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst jsonFamily = getJsonFamily(findRelatedKeysState, store)\n\t\t\t\t\t\t\tconst json = get(jsonFamily(key))\n\t\t\t\t\t\t\treturn json.members\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\t\t}\n\t\tconst createSingleEntryStateFamily = () =>\n\t\t\tcreateSelectorFamily<[string, Content] | null, string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/singleRelatedEntry`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst relatedKeys = get(findRelatedKeysState(key))\n\t\t\t\t\t\t\tfor (const relatedKey of relatedKeys) {\n\t\t\t\t\t\t\t\tconst contentKey = relations.makeContentKey(key, relatedKey)\n\t\t\t\t\t\t\t\treturn [relatedKey, get(findContentState(contentKey))]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn null\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\t\tconst getMultipleEntryStateFamily = () =>\n\t\t\tcreateSelectorFamily<[string, Content][], string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/multipleRelatedEntries`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst jsonFamily = getJsonFamily(findRelatedKeysState, store)\n\t\t\t\t\t\t\tconst json = get(jsonFamily(key))\n\t\t\t\t\t\t\treturn json.members.map((relatedKey) => {\n\t\t\t\t\t\t\t\tconst contentKey = relations.makeContentKey(key, relatedKey)\n\t\t\t\t\t\t\t\treturn [relatedKey, get(findContentState(contentKey))]\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\n\t\tswitch (options.cardinality) {\n\t\t\tcase `1:1`: {\n\t\t\t\tconst findSingleRelatedKeyState = createSingleKeyStateFamily()\n\t\t\t\tconst stateKeyA = `${a}KeyOf${capitalize(b)}` as const\n\t\t\t\tconst stateKeyB = `${b}KeyOf${capitalize(a)}` as const\n\t\t\t\tconst findStateBase = {\n\t\t\t\t\t[stateKeyA]: findSingleRelatedKeyState,\n\t\t\t\t\t[stateKeyB]: findSingleRelatedKeyState,\n\t\t\t\t} as JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tlet findState: JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tif (defaultContent) {\n\t\t\t\t\tconst findSingleRelatedEntryState = createSingleEntryStateFamily()\n\t\t\t\t\tconst entriesStateKeyA = `${a}EntryOf${capitalize(b)}` as const\n\t\t\t\t\tconst entriesStateKeyB = `${b}EntryOf${capitalize(a)}` as const\n\t\t\t\t\tconst findStateWithContent = {\n\t\t\t\t\t\t[entriesStateKeyA]: findSingleRelatedEntryState,\n\t\t\t\t\t\t[entriesStateKeyB]: findSingleRelatedEntryState,\n\t\t\t\t\t}\n\t\t\t\t\tfindState = Object.assign(findStateBase, findStateWithContent)\n\t\t\t\t} else {\n\t\t\t\t\tfindState = findStateBase\n\t\t\t\t}\n\t\t\t\tthis.relations = relations\n\t\t\t\tthis.findState = findState\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase `1:n`: {\n\t\t\t\tconst findSingleRelatedKeyState = createSingleKeyStateFamily()\n\t\t\t\tconst findMultipleRelatedKeysState = getMultipleKeyStateFamily()\n\t\t\t\tconst stateKeyA = `${a}KeyOf${capitalize(b)}` as const\n\t\t\t\tconst stateKeyB = `${b}KeysOf${capitalize(a)}` as const\n\t\t\t\tconst findStateBase = {\n\t\t\t\t\t[stateKeyA]: findSingleRelatedKeyState,\n\t\t\t\t\t[stateKeyB]: findMultipleRelatedKeysState,\n\t\t\t\t} as JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tlet findState: JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tif (defaultContent) {\n\t\t\t\t\tconst findSingleRelatedEntryState = createSingleEntryStateFamily()\n\t\t\t\t\tconst findMultipleRelatedEntriesState = getMultipleEntryStateFamily()\n\t\t\t\t\tconst entriesStateKeyA = `${a}EntryOf${capitalize(b)}` as const\n\t\t\t\t\tconst entriesStateKeyB = `${b}EntriesOf${capitalize(a)}` as const\n\t\t\t\t\tconst findStateWithContent = {\n\t\t\t\t\t\t[entriesStateKeyA]: findSingleRelatedEntryState,\n\t\t\t\t\t\t[entriesStateKeyB]: findMultipleRelatedEntriesState,\n\t\t\t\t\t}\n\t\t\t\t\tfindState = Object.assign(findStateBase, findStateWithContent)\n\t\t\t\t} else {\n\t\t\t\t\tfindState = findStateBase\n\t\t\t\t}\n\t\t\t\tthis.relations = relations\n\t\t\t\tthis.findState = findState\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tconst findMultipleRelatedKeysState = getMultipleKeyStateFamily()\n\t\t\t\tconst stateKeyA = `${a}KeysOf${capitalize(b)}` as const\n\t\t\t\tconst stateKeyB = `${b}KeysOf${capitalize(a)}` as const\n\t\t\t\tconst findStateBase = {\n\t\t\t\t\t[stateKeyA]: findMultipleRelatedKeysState,\n\t\t\t\t\t[stateKeyB]: findMultipleRelatedKeysState,\n\t\t\t\t} as JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tlet findState: JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tif (defaultContent) {\n\t\t\t\t\tconst findMultipleRelatedEntriesState = getMultipleEntryStateFamily()\n\t\t\t\t\tconst entriesStateKeyA = `${a}EntriesOf${capitalize(b)}` as const\n\t\t\t\t\tconst entriesStateKeyB = `${b}EntriesOf${capitalize(a)}` as const\n\t\t\t\t\tconst findStateWithContent = {\n\t\t\t\t\t\t[entriesStateKeyA]: findMultipleRelatedEntriesState,\n\t\t\t\t\t\t[entriesStateKeyB]: findMultipleRelatedEntriesState,\n\t\t\t\t\t}\n\t\t\t\t\tfindState = Object.assign(findStateBase, findStateWithContent)\n\t\t\t\t} else {\n\t\t\t\t\tfindState = findStateBase\n\t\t\t\t}\n\t\t\t\tthis.relations = relations\n\t\t\t\tthis.findState = findState\n\t\t\t}\n\t\t}\n\t}\n}\nexport function join<\n\tconst ASide extends string,\n\tconst BSide extends string,\n\tconst Cardinality extends `1:1` | `1:n` | `n:n`,\n>(\n\toptions: JoinOptions<ASide, BSide, Cardinality, null>,\n\tdefaultContent?: undefined,\n\tstore?: Store,\n): {\n\treadonly relations: Junction<ASide, BSide, null>\n\treadonly findState: JoinState<ASide, BSide, Cardinality, null>\n\treadonly transact: (\n\t\ttransactors: Transactors,\n\t\trun: (join: Join<ASide, BSide, Cardinality, null>) => void,\n\t) => void\n\treadonly core: {\n\t\treadonly findRelatedKeysState: MutableAtomFamily<\n\t\t\tSetRTX<string>,\n\t\t\tSetRTXJson<string>,\n\t\t\tstring\n\t\t>\n\t}\n}\nexport function join<\n\tconst ASide extends string,\n\tconst BSide extends string,\n\tconst Cardinality extends `1:1` | `1:n` | `n:n`,\n\tconst Content extends Json.Object,\n>(\n\toptions: JoinOptions<ASide, BSide, Cardinality, Content>,\n\tdefaultContent: Content,\n\tstore?: Store,\n): {\n\treadonly relations: Junction<ASide, BSide, Content>\n\treadonly findState: JoinState<ASide, BSide, Cardinality, Content>\n\treadonly transact: (\n\t\ttransactors: Transactors,\n\t\trun: (join: Join<ASide, BSide, Cardinality, Content>) => void,\n\t) => void\n\treadonly core: {\n\t\treadonly findRelatedKeysState: MutableAtomFamily<\n\t\t\tSetRTX<string>,\n\t\t\tSetRTXJson<string>,\n\t\t\tstring\n\t\t>\n\t}\n}\nexport function join<\n\tASide extends string,\n\tBSide extends string,\n\tCardinality extends `1:1` | `1:n` | `n:n`,\n\tContent extends Json.Object,\n>(\n\toptions: JoinOptions<ASide, BSide, Cardinality, Content>,\n\tdefaultContent: Content | undefined,\n\tstore: Store = IMPLICIT.STORE,\n): Join<ASide, BSide, Cardinality, Content> {\n\treturn new Join(options, defaultContent, store)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\n\nimport { createRegularAtom, 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] = createRegularAtom(\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\tcreateRegularAtomFamily,\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] = createRegularAtomFamily(\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"]}
1
+ {"version":3,"sources":["../src/dict.ts","../src/join.ts","../src/struct.ts","../src/struct-family.ts","../src/until.ts"],"names":["IMPLICIT","a","b","createSelector","capitalize","createRegularAtomFamily","createSelectorFamily"],"mappings":";;;;;;AAEA,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AC3B;;;ACtDA;AAAA,EACC,YAAAJ;AAAA,EACA,2BAAAK;AAAA,EACA,wBAAAC;AAAA,OACM;AAEP,IAAMF,cAAa,CAAC,QAAgB,IAAI,CAAC,EAAE,YAAY,IAAI,IAAI,MAAM,CAAC;AACtE,IAAM,aAAa,CAAC,QAAgB,WACnC,SAASA,YAAW,MAAM,IAAIA,YAAW,MAAM,IAAI;AAE7C,SAAS,aAGd,SAUA;AACD,QAAM,QAIF,OAAO,KAAK,QAAQ,OAAO,EAAE,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\tMutableAtomFamily,\n\tRead,\n\tReadonlySelectorFamily,\n\tTransactors,\n\tWrite,\n} from \"atom.io\"\nimport { dispose, getState, setState } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tcreateMutableAtomFamily,\n\tcreateRegularAtomFamily,\n\tcreateSelectorFamily,\n\tgetJsonFamily,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { SetRTXJson } from \"atom.io/transceivers/set-rtx\"\nimport { SetRTX } from \"atom.io/transceivers/set-rtx\"\n\nimport type {\n\tBaseExternalStoreConfiguration,\n\tExternalStoreConfiguration,\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>}`]: ReadonlySelectorFamily<\n\t\t\t\t\t\t[string, Content] | null,\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>}`]: ReadonlySelectorFamily<\n\t\t\t\tstring | null,\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>}`]: ReadonlySelectorFamily<\n\t\t\t\t\t\t\t[string, Content] | null,\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>}`]: ReadonlySelectorFamily<\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>}`]: ReadonlySelectorFamily<\n\t\t\t\t\tstring | null,\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>}`]: ReadonlySelectorFamily<\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>}`]: ReadonlySelectorFamily<\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>}`]: ReadonlySelectorFamily<\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 class Join<\n\tconst ASide extends string,\n\tconst BSide extends string,\n\tconst Cardinality extends `1:1` | `1:n` | `n:n`,\n\tconst Content extends Json.Object | null = null,\n> {\n\tprivate transactors: Transactors = TRANSACTORS\n\tpublic relations: Junction<ASide, BSide, Content>\n\tpublic findState: JoinState<ASide, BSide, Cardinality, Content>\n\tpublic core: {\n\t\tfindRelatedKeysState: MutableAtomFamily<\n\t\t\tSetRTX<string>,\n\t\t\tSetRTXJson<string>,\n\t\t\tstring\n\t\t>\n\t}\n\tpublic transact(\n\t\ttransactors: Transactors,\n\t\trun: (join: Join<ASide, BSide, Cardinality, Content>) => void,\n\t): void {\n\t\tthis.transactors = transactors\n\t\trun(this)\n\t\tthis.transactors = TRANSACTORS\n\t}\n\tpublic constructor(\n\t\toptions: JoinOptions<ASide, BSide, Cardinality, Content>,\n\t\tdefaultContent: Content | undefined,\n\t\tstore: Store = IMPLICIT.STORE,\n\t) {\n\t\tconst a: ASide = options.between[0]\n\t\tconst b: BSide = options.between[1]\n\t\tconst findRelatedKeysState = createMutableAtomFamily<\n\t\t\tSetRTX<string>,\n\t\t\tSetRTXJson<string>,\n\t\t\tstring\n\t\t>(\n\t\t\t{\n\t\t\t\tkey: `${options.key}/relatedKeys`,\n\t\t\t\tdefault: () => new SetRTX(),\n\t\t\t\tmutable: true,\n\t\t\t\tfromJson: (json) => SetRTX.fromJSON(json),\n\t\t\t\ttoJson: (set) => set.toJSON(),\n\t\t\t},\n\t\t\tstore,\n\t\t)\n\t\tthis.core = { findRelatedKeysState }\n\t\tconst getRelatedKeys: Read<(key: string) => SetRTX<string>> = (\n\t\t\t{ get },\n\t\t\tkey,\n\t\t) => get(findRelatedKeysState(key))\n\t\tconst addRelation: Write<(a: string, b: string) => void> = (\n\t\t\ttransactors,\n\t\t\ta,\n\t\t\tb,\n\t\t) => {\n\t\t\tconst aKeysState = findRelatedKeysState(a)\n\t\t\tconst bKeysState = findRelatedKeysState(b)\n\t\t\ttransactors.set(aKeysState, (aKeys) => aKeys.add(b))\n\t\t\ttransactors.set(bKeysState, (bKeys) => bKeys.add(a))\n\t\t}\n\t\tconst deleteRelation: Write<(a: string, b: string) => void> = (\n\t\t\ttransactors,\n\t\t\ta,\n\t\t\tb,\n\t\t) => {\n\t\t\tconst aKeys = getRelatedKeys(transactors, a)\n\t\t\taKeys.delete(b)\n\t\t\tconst bKeys = getRelatedKeys(transactors, b)\n\t\t\tbKeys.delete(a)\n\t\t}\n\t\tconst replaceRelationsSafely: Write<\n\t\t\t(a: string, newRelationsOfA: string[]) => void\n\t\t> = (transactors, a, newRelationsOfA) => {\n\t\t\tconst currentRelationsOfA = getRelatedKeys(transactors, a)\n\t\t\tfor (const currentRelationB of currentRelationsOfA) {\n\t\t\t\tconst remainsRelated = newRelationsOfA.includes(currentRelationB)\n\t\t\t\tif (remainsRelated) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\tconst relationsOfB = getRelatedKeys(transactors, currentRelationB)\n\t\t\t\trelationsOfB.delete(a)\n\t\t\t}\n\t\t\tcurrentRelationsOfA.transaction((nextRelationsOfA) => {\n\t\t\t\tnextRelationsOfA.clear()\n\t\t\t\tfor (const newRelationB of newRelationsOfA) {\n\t\t\t\t\tconst relationsOfB = getRelatedKeys(transactors, newRelationB)\n\t\t\t\t\tif (this.relations.cardinality === `1:n`) {\n\t\t\t\t\t\tfor (const a of relationsOfB) {\n\t\t\t\t\t\t\tconst relationsOfA = getRelatedKeys(transactors, a)\n\t\t\t\t\t\t\trelationsOfA.delete(newRelationB)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (relationsOfB.size > 0) {\n\t\t\t\t\t\t\trelationsOfB.clear()\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\trelationsOfB.add(a)\n\t\t\t\t\tnextRelationsOfA.add(newRelationB)\n\t\t\t\t}\n\t\t\t\treturn true\n\t\t\t})\n\t\t}\n\t\tconst replaceRelationsUnsafely: Write<\n\t\t\t(a: string, newRelationsOfA: string[]) => void\n\t\t> = (transactors, a, newRelationsOfA) => {\n\t\t\tconst relationsOfA = getRelatedKeys(transactors, a)\n\t\t\tfor (const newRelationB of newRelationsOfA) {\n\t\t\t\tconst relationsOfB = getRelatedKeys(transactors, newRelationB)\n\t\t\t\trelationsOfA.add(newRelationB)\n\t\t\t\trelationsOfB.add(a)\n\t\t\t}\n\t\t\treturn true\n\t\t}\n\t\tconst has: Read<(a: string, b?: string) => boolean> = (\n\t\t\ttransactors,\n\t\t\ta,\n\t\t\tb,\n\t\t) => {\n\t\t\tconst aKeys = getRelatedKeys(transactors, a)\n\t\t\treturn b ? aKeys.has(b) : aKeys.size > 0\n\t\t}\n\t\tconst baseExternalStoreConfiguration: BaseExternalStoreConfiguration = {\n\t\t\tgetRelatedKeys: (key) => getRelatedKeys(this.transactors, key),\n\t\t\taddRelation: (a, b) => addRelation(this.transactors, a, b),\n\t\t\tdeleteRelation: (a, b) => deleteRelation(this.transactors, a, b),\n\t\t\treplaceRelationsSafely: (a, bs) =>\n\t\t\t\treplaceRelationsSafely(this.transactors, a, bs),\n\t\t\treplaceRelationsUnsafely: (a, bs) =>\n\t\t\t\treplaceRelationsUnsafely(this.transactors, a, bs),\n\t\t\thas: (a, b) => has(this.transactors, a, b),\n\t\t}\n\t\tlet externalStore: ExternalStoreConfiguration<Content>\n\t\tlet findContentState: AtomFamily<Content, string>\n\t\tif (defaultContent) {\n\t\t\tfindContentState = createRegularAtomFamily<Content, string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/content`,\n\t\t\t\t\tdefault: defaultContent,\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\t\t\tconst getContent: Read<(key: string) => Content | null> = ({ get }, key) =>\n\t\t\t\tget(findContentState(key))\n\t\t\tconst setContent: Write<(key: string, content: Content) => void> = (\n\t\t\t\ttransactors,\n\t\t\t\tkey,\n\t\t\t\tcontent,\n\t\t\t) => transactors.set(findContentState(key), content)\n\t\t\tconst deleteContent: Write<(key: string) => void> = (_, key) =>\n\t\t\t\tdispose(findContentState(key))\n\t\t\tconst externalStoreWithContentConfiguration = {\n\t\t\t\tgetContent: (contentKey: string) => {\n\t\t\t\t\tconst content = getContent(this.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(this.transactors, contentKey, content)\n\t\t\t\t},\n\t\t\t\tdeleteContent: (contentKey: string) => {\n\t\t\t\t\tdeleteContent(this.transactors, contentKey)\n\t\t\t\t},\n\t\t\t}\n\t\t\texternalStore = Object.assign(\n\t\t\t\tbaseExternalStoreConfiguration,\n\t\t\t\texternalStoreWithContentConfiguration,\n\t\t\t) as ExternalStoreConfiguration<Content>\n\t\t} else {\n\t\t\texternalStore =\n\t\t\t\tbaseExternalStoreConfiguration as ExternalStoreConfiguration<Content>\n\t\t}\n\t\tconst relations = new Junction<ASide, BSide, Content>(options, {\n\t\t\texternalStore,\n\t\t\tmakeContentKey: (...args) => args.sort().join(`:`),\n\t\t})\n\n\t\tconst createSingleKeyStateFamily = () =>\n\t\t\tcreateSelectorFamily<string | null, string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/singleRelatedKey`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst relatedKeys = get(findRelatedKeysState(key))\n\t\t\t\t\t\t\tfor (const relatedKey of relatedKeys) {\n\t\t\t\t\t\t\t\treturn relatedKey\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn null\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\t\tconst getMultipleKeyStateFamily = () => {\n\t\t\treturn createSelectorFamily<string[], string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/multipleRelatedKeys`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst jsonFamily = getJsonFamily(findRelatedKeysState, store)\n\t\t\t\t\t\t\tconst json = get(jsonFamily(key))\n\t\t\t\t\t\t\treturn json.members\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\t\t}\n\t\tconst createSingleEntryStateFamily = () =>\n\t\t\tcreateSelectorFamily<[string, Content] | null, string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/singleRelatedEntry`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst relatedKeys = get(findRelatedKeysState(key))\n\t\t\t\t\t\t\tfor (const relatedKey of relatedKeys) {\n\t\t\t\t\t\t\t\tconst contentKey = relations.makeContentKey(key, relatedKey)\n\t\t\t\t\t\t\t\treturn [relatedKey, get(findContentState(contentKey))]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn null\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\t\tconst getMultipleEntryStateFamily = () =>\n\t\t\tcreateSelectorFamily<[string, Content][], string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/multipleRelatedEntries`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst jsonFamily = getJsonFamily(findRelatedKeysState, store)\n\t\t\t\t\t\t\tconst json = get(jsonFamily(key))\n\t\t\t\t\t\t\treturn json.members.map((relatedKey) => {\n\t\t\t\t\t\t\t\tconst contentKey = relations.makeContentKey(key, relatedKey)\n\t\t\t\t\t\t\t\treturn [relatedKey, get(findContentState(contentKey))]\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\n\t\tswitch (options.cardinality) {\n\t\t\tcase `1:1`: {\n\t\t\t\tconst findSingleRelatedKeyState = createSingleKeyStateFamily()\n\t\t\t\tconst stateKeyA = `${a}KeyOf${capitalize(b)}` as const\n\t\t\t\tconst stateKeyB = `${b}KeyOf${capitalize(a)}` as const\n\t\t\t\tconst findStateBase = {\n\t\t\t\t\t[stateKeyA]: findSingleRelatedKeyState,\n\t\t\t\t\t[stateKeyB]: findSingleRelatedKeyState,\n\t\t\t\t} as JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tlet findState: JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tif (defaultContent) {\n\t\t\t\t\tconst findSingleRelatedEntryState = createSingleEntryStateFamily()\n\t\t\t\t\tconst entriesStateKeyA = `${a}EntryOf${capitalize(b)}` as const\n\t\t\t\t\tconst entriesStateKeyB = `${b}EntryOf${capitalize(a)}` as const\n\t\t\t\t\tconst findStateWithContent = {\n\t\t\t\t\t\t[entriesStateKeyA]: findSingleRelatedEntryState,\n\t\t\t\t\t\t[entriesStateKeyB]: findSingleRelatedEntryState,\n\t\t\t\t\t}\n\t\t\t\t\tfindState = Object.assign(findStateBase, findStateWithContent)\n\t\t\t\t} else {\n\t\t\t\t\tfindState = findStateBase\n\t\t\t\t}\n\t\t\t\tthis.relations = relations\n\t\t\t\tthis.findState = findState\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase `1:n`: {\n\t\t\t\tconst findSingleRelatedKeyState = createSingleKeyStateFamily()\n\t\t\t\tconst findMultipleRelatedKeysState = getMultipleKeyStateFamily()\n\t\t\t\tconst stateKeyA = `${a}KeyOf${capitalize(b)}` as const\n\t\t\t\tconst stateKeyB = `${b}KeysOf${capitalize(a)}` as const\n\t\t\t\tconst findStateBase = {\n\t\t\t\t\t[stateKeyA]: findSingleRelatedKeyState,\n\t\t\t\t\t[stateKeyB]: findMultipleRelatedKeysState,\n\t\t\t\t} as JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tlet findState: JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tif (defaultContent) {\n\t\t\t\t\tconst findSingleRelatedEntryState = createSingleEntryStateFamily()\n\t\t\t\t\tconst findMultipleRelatedEntriesState = getMultipleEntryStateFamily()\n\t\t\t\t\tconst entriesStateKeyA = `${a}EntryOf${capitalize(b)}` as const\n\t\t\t\t\tconst entriesStateKeyB = `${b}EntriesOf${capitalize(a)}` as const\n\t\t\t\t\tconst findStateWithContent = {\n\t\t\t\t\t\t[entriesStateKeyA]: findSingleRelatedEntryState,\n\t\t\t\t\t\t[entriesStateKeyB]: findMultipleRelatedEntriesState,\n\t\t\t\t\t}\n\t\t\t\t\tfindState = Object.assign(findStateBase, findStateWithContent)\n\t\t\t\t} else {\n\t\t\t\t\tfindState = findStateBase\n\t\t\t\t}\n\t\t\t\tthis.relations = relations\n\t\t\t\tthis.findState = findState\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tconst findMultipleRelatedKeysState = getMultipleKeyStateFamily()\n\t\t\t\tconst stateKeyA = `${a}KeysOf${capitalize(b)}` as const\n\t\t\t\tconst stateKeyB = `${b}KeysOf${capitalize(a)}` as const\n\t\t\t\tconst findStateBase = {\n\t\t\t\t\t[stateKeyA]: findMultipleRelatedKeysState,\n\t\t\t\t\t[stateKeyB]: findMultipleRelatedKeysState,\n\t\t\t\t} as JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tlet findState: JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tif (defaultContent) {\n\t\t\t\t\tconst findMultipleRelatedEntriesState = getMultipleEntryStateFamily()\n\t\t\t\t\tconst entriesStateKeyA = `${a}EntriesOf${capitalize(b)}` as const\n\t\t\t\t\tconst entriesStateKeyB = `${b}EntriesOf${capitalize(a)}` as const\n\t\t\t\t\tconst findStateWithContent = {\n\t\t\t\t\t\t[entriesStateKeyA]: findMultipleRelatedEntriesState,\n\t\t\t\t\t\t[entriesStateKeyB]: findMultipleRelatedEntriesState,\n\t\t\t\t\t}\n\t\t\t\t\tfindState = Object.assign(findStateBase, findStateWithContent)\n\t\t\t\t} else {\n\t\t\t\t\tfindState = findStateBase\n\t\t\t\t}\n\t\t\t\tthis.relations = relations\n\t\t\t\tthis.findState = findState\n\t\t\t}\n\t\t}\n\t}\n}\nexport function join<\n\tconst ASide extends string,\n\tconst BSide extends string,\n\tconst Cardinality extends `1:1` | `1:n` | `n:n`,\n>(\n\toptions: JoinOptions<ASide, BSide, Cardinality, null>,\n\tdefaultContent?: undefined,\n\tstore?: Store,\n): {\n\treadonly relations: Junction<ASide, BSide, null>\n\treadonly findState: JoinState<ASide, BSide, Cardinality, null>\n\treadonly transact: (\n\t\ttransactors: Transactors,\n\t\trun: (join: Join<ASide, BSide, Cardinality, null>) => void,\n\t) => void\n\treadonly core: {\n\t\treadonly findRelatedKeysState: MutableAtomFamily<\n\t\t\tSetRTX<string>,\n\t\t\tSetRTXJson<string>,\n\t\t\tstring\n\t\t>\n\t}\n}\nexport function join<\n\tconst ASide extends string,\n\tconst BSide extends string,\n\tconst Cardinality extends `1:1` | `1:n` | `n:n`,\n\tconst Content extends Json.Object,\n>(\n\toptions: JoinOptions<ASide, BSide, Cardinality, Content>,\n\tdefaultContent: Content,\n\tstore?: Store,\n): {\n\treadonly relations: Junction<ASide, BSide, Content>\n\treadonly findState: JoinState<ASide, BSide, Cardinality, Content>\n\treadonly transact: (\n\t\ttransactors: Transactors,\n\t\trun: (join: Join<ASide, BSide, Cardinality, Content>) => void,\n\t) => void\n\treadonly core: {\n\t\treadonly findRelatedKeysState: MutableAtomFamily<\n\t\t\tSetRTX<string>,\n\t\t\tSetRTXJson<string>,\n\t\t\tstring\n\t\t>\n\t}\n}\nexport function join<\n\tASide extends string,\n\tBSide extends string,\n\tCardinality extends `1:1` | `1:n` | `n:n`,\n\tContent extends Json.Object,\n>(\n\toptions: JoinOptions<ASide, BSide, Cardinality, Content>,\n\tdefaultContent: Content | undefined,\n\tstore: Store = IMPLICIT.STORE,\n): Join<ASide, BSide, Cardinality, Content> {\n\treturn new Join(options, defaultContent, store)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\n\nimport { createRegularAtom, 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] = createRegularAtom(\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\tcreateRegularAtomFamily,\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] = createRegularAtomFamily(\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"]}
package/data/src/join.ts CHANGED
@@ -200,6 +200,15 @@ export class Join<
200
200
  nextRelationsOfA.clear()
201
201
  for (const newRelationB of newRelationsOfA) {
202
202
  const relationsOfB = getRelatedKeys(transactors, newRelationB)
203
+ if (this.relations.cardinality === `1:n`) {
204
+ for (const a of relationsOfB) {
205
+ const relationsOfA = getRelatedKeys(transactors, a)
206
+ relationsOfA.delete(newRelationB)
207
+ }
208
+ if (relationsOfB.size > 0) {
209
+ relationsOfB.clear()
210
+ }
211
+ }
203
212
  relationsOfB.add(a)
204
213
  nextRelationsOfA.add(newRelationB)
205
214
  }
@@ -133,6 +133,15 @@ var runTransaction = (token, store = IMPLICIT.STORE) => (...parameters) => {
133
133
  );
134
134
  };
135
135
 
136
- export { AtomIOLogger, LOG_LEVELS, Silo, atom, atomFamily, dispose, getState, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
136
+ // src/validators.ts
137
+ function isToken(knownToken, unknownToken) {
138
+ return knownToken.key === unknownToken.key;
139
+ }
140
+ function belongsTo(family, unknownToken) {
141
+ var _a;
142
+ return family.key === ((_a = unknownToken.family) == null ? void 0 : _a.key);
143
+ }
144
+
145
+ export { AtomIOLogger, LOG_LEVELS, Silo, atom, atomFamily, belongsTo, dispose, getState, isToken, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
137
146
  //# sourceMappingURL=out.js.map
138
- //# sourceMappingURL=chunk-K22LR3V6.js.map
147
+ //# sourceMappingURL=chunk-RLZQ6IIY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/atom.ts","../src/dispose.ts","../src/get-state.ts","../src/logger.ts","../src/selector.ts","../src/set-state.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts","../src/validators.ts"],"names":["Internal","IMPLICIT","createAtom","createAtomFamily","createSelector","createSelectorFamily","createTimeline","timeTravel","timeline","createTransaction","withdraw"],"mappings":";AACA,SAAS,UAAU,YAAY,wBAAwB;AA8BhD,SAAS,KACf,SACiB;AACjB,SAAO,WAAW,SAAS,QAAW,SAAS,KAAK;AACrD;AAoDO,SAAS,WACf,SACsD;AACtD,SAAO,iBAAiB,SAAS,SAAS,KAAK;AAChD;;;AC3FA,YAAY,cAAc;AAInB,SAAS,QACf,OACA,QAAiC,kBAAS,OACnC;AACP,UAAQ,MAAM,MAAM;AAAA,IACnB,KAAK;AACJ,MAAS,oBAAW,OAAO,KAAK;AAChC;AAAA,IACD,KAAK;AAAA,IACL,KAAK;AACJ,MAAS,wBAAe,OAAO,KAAK;AACpC;AAAA,EACF;AACD;;;ACjBA,YAAYA,eAAc;AAInB,SAAS,SACf,OACA,QAAiC,mBAAS,OACtC;AAPL;AAQC,QAAM,SACL,KAAS,mBAAS,OAAO,KAAK,MAA9B,YACS,kCAAwB,OAAO,KAAK;A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S,QACf,YACA,cACuD;AACvD,SAAO,WAAW,QAAQ,aAAa;AACxC;AAsBO,SAAS,UACf,QACA,cACmD;AAvEpD;AAwEC,SAAO,OAAO,UAAQ,kBAAa,WAAb,mBAAqB;AAC5C","sourcesContent":["import type { Store, Subject, Transceiver } from \"atom.io/internal\"\nimport { IMPLICIT, createAtom, createAtomFamily } from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken } from \".\"\n\nexport type Effectors<T> = {\n\tsetSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void\n\tonSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void\n}\n\nexport type AtomEffect<T> = (tools: Effectors<T>) => (() => void) | void\n\nexport type AtomOptions<T> = {\n\tkey: string\n\tdefault: T | (() => T)\n\teffects?: AtomEffect<T>[]\n}\n// biome-ignore format: complex intersection\nexport type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = \n\t& JsonInterface<T, J>\n\t& Omit<AtomOptions<T>, `default`> \n\t& { \n\t\t\tdefault: ()\t=> T\n\t\t\tmutable: true\n\t\t}\n\nexport function atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\toptions: MutableAtomOptions<T, J>,\n): MutableAtomToken<T, J>\nexport function atom<T>(options: AtomOptions<T>): AtomToken<T>\nexport function atom(\n\toptions: AtomOptions<any> | MutableAtomOptions<any, any>,\n): AtomToken<any> {\n\treturn createAtom(options, undefined, IMPLICIT.STORE)\n}\n\nexport type AtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((\n\tkey: K,\n) => AtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<AtomToken<T>>\n\tmutable?: boolean\n\tinstall: (store: Store) => void\n}\n\n// biome-ignore format: intersection\nexport type MutableAtomFamilyOptions<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& AtomFamilyOptions<T, K>\n\t& JsonInterface<T, J>\n\t& { mutable: true }\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends Json.Serializable,\n> = \n\t& JsonInterface<Core, SerializableCore>\n\t& ((key: Key) => MutableAtomToken<Core, SerializableCore>) \n\t& {\n\t\t\tkey: `${string}`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\n\t\t\tmutable: true\n\t\t\tinstall: (store: Store) => void\n\t\t}\n\nexport function atomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K>,\n): AtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K> | MutableAtomFamilyOptions<any, any, any>,\n): AtomFamily<T, K> | MutableAtomFamily<any, any, any> {\n\treturn createAtomFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport function dispose(\n\ttoken: ReadonlySelectorToken<any> | StateToken<any>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\t\tInternal.deleteAtom(token, store)\n\t\t\tbreak\n\t\tcase `selector`:\n\t\tcase `readonly_selector`:\n\t\t\tInternal.deleteSelector(token, store)\n\t\t\tbreak\n\t}\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport function getState<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): T {\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\treturn Internal.readOrComputeValue(state, store)\n}\n","const LoggerIconDictionary = {\n\t\"⌛\": `Timeline event fully captured`,\n\t\"⏩\": `Timeline redo`,\n\t\"⏪\": `Timeline undo`,\n\t\"⏭️\": `Transaction redo`,\n\t\"⏮️\": `Transaction undo`,\n\t\"⏳\": `Timeline event partially captured`,\n\t\"⏹️\": `Time-travel complete`,\n\t\"💁\": `Notice`,\n\t\"🔄\": `Realtime transaction synchronized`,\n\t\"✅\": `Realtime transaction success`,\n\t\"✨\": `Computation complete`,\n\t\"❌\": `Conflict prevents attempted action`,\n\t\"⭕\": `Operation start`,\n\t\"🐞\": `Possible bug in AtomIO`,\n\t\"👀\": `Subscription added`,\n\t\"👪\": `Family member added`,\n\t\"📁\": `Stow update`,\n\t\"📃\": `Copy mutable`,\n\t\"📖\": `Read state`,\n\t\"📝\": `Write state`,\n\t\"📢\": `Notify subscribers`,\n\t\"🔌\": `Register dependency`,\n\t\"🔍\": `Discover root`,\n\t\"🔥\": `Delete state`,\n\t\"🔧\": `Create mutable atom`,\n\t\"🔨\": `Create immutable atom`,\n\t\"🔴\": `Operation complete`,\n\t\"🗑\": `Evict cached value`,\n\t\"💥\": `Caught`,\n\t\"🙈\": `Subscription canceled`,\n\t\"🛄\": `Apply transaction`,\n\t\"🛠️\": `Install atom into store`,\n\t\"🛫\": `Begin transaction`,\n\t\"🛬\": `Complete transaction`,\n\t\"🧮\": `Computing selector`,\n\t\"🧹\": `Prepare to evict`,\n\t\"🪂\": `Abort transaction`,\n} as const\nexport type LoggerIcon = keyof typeof LoggerIconDictionary\n\nexport const LOG_LEVELS = [`info`, `warn`, `error`] as const\nexport type LogLevel = (typeof LOG_LEVELS)[number]\n\nexport type LogFn = (\n\ticon: LoggerIcon,\n\ttokenType:\n\t\t| `atom`\n\t\t| `readonly_selector`\n\t\t| `selector`\n\t\t| `state`\n\t\t| `timeline`\n\t\t| `transaction`\n\t\t| `unknown`,\n\ttokenKey: string,\n\tmessage: string,\n\t...rest: unknown[]\n) => void\nexport type LogFilter = (...params: Parameters<LogFn>) => boolean\n\nexport type Logger = Record<LogLevel, LogFn>\n\nexport const simpleLog =\n\t(logLevel: keyof Logger): LogFn =>\n\t(icon, tokenType, tokenKey, message, ...rest) => {\n\t\tconsole[logLevel](`${icon} ${tokenType} \"${tokenKey}\" ${message}`, ...rest)\n\t}\nexport const simpleLogger: Logger = {\n\terror: simpleLog(`error`),\n\tinfo: simpleLog(`info`),\n\twarn: simpleLog(`warn`),\n}\n\nexport class AtomIOLogger implements Logger {\n\tpublic constructor(\n\t\tpublic logLevel: `error` | `info` | `warn` | null,\n\t\tprivate readonly filter?: LogFilter,\n\t\tprivate readonly logger: Logger = simpleLogger,\n\t) {}\n\n\tpublic error: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel !== null) {\n\t\t\tthis.logger.error(...args)\n\t\t}\n\t}\n\tpublic info: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel === `info`) {\n\t\t\tthis.logger.info(...args)\n\t\t}\n\t}\n\tpublic warn: LogFn = (...args) => {\n\t\tif (\n\t\t\t(this.filter?.(...args) ?? true) &&\n\t\t\tthis.logLevel !== `error` &&\n\t\t\tthis.logLevel !== null\n\t\t) {\n\t\t\tthis.logger.warn(...args)\n\t\t}\n\t}\n}\n","import type { Store, Subject } from \"atom.io/internal\"\nimport { IMPLICIT, createSelector, createSelectorFamily } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, SelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type SelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n\tset: Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n}\n\nexport function selector<T>(options: SelectorOptions<T>): SelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | SelectorOptions<T>,\n): ReadonlySelectorToken<T> | SelectorToken<T> {\n\treturn createSelector(options, undefined, IMPLICIT.STORE)\n}\n\nexport type SelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n\tset: (key: K) => Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n}\n\nexport type SelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => SelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<SelectorToken<T>>\n\tinstall: (store: Store) => void\n}\n\nexport type ReadonlySelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => ReadonlySelectorToken<T>) & {\n\tkey: string\n\ttype: `readonly_selector_family`\n\tsubject: Subject<ReadonlySelectorToken<T>>\n\tinstall: (store: Store) => void\n}\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: SelectorFamilyOptions<T, K>,\n): SelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {\n\treturn createSelectorFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { StateToken } from \".\"\n\nexport function setState<T, New extends T>(\n\ttoken: StateToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tconst rejection = Internal.openOperation(token, store)\n\tif (rejection) {\n\t\treturn\n\t}\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\tInternal.setAtomOrSelector(state, value, store)\n\tInternal.closeOperation(store)\n}\n","import {\n\tStore,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateSelector,\n\tcreateSelectorFamily,\n\tcreateTimeline,\n\tcreateTransaction,\n\ttimeTravel,\n} from \"atom.io/internal\"\n\nimport type { redo, timeline, undo } from \".\"\nimport { getState, setState, subscribe } from \".\"\nimport type { atom, atomFamily } from \"./atom\"\nimport type { selector, selectorFamily } from \"./selector\"\nimport type { transaction } from \"./transaction\"\n\nexport class Silo {\n\tpublic store: Store\n\tpublic atom: typeof atom\n\tpublic atomFamily: typeof atomFamily\n\tpublic selector: typeof selector\n\tpublic selectorFamily: typeof selectorFamily\n\tpublic transaction: typeof transaction\n\tpublic timeline: typeof timeline\n\tpublic getState: typeof getState\n\tpublic setState: typeof setState\n\tpublic subscribe: typeof subscribe\n\tpublic undo: typeof undo\n\tpublic redo: typeof redo\n\tpublic constructor(name: string, fromStore: Store | null = null) {\n\t\tconst s = new Store(name, fromStore)\n\t\tthis.store = s\n\t\tthis.atom = (options) => createAtom(options, undefined, s)\n\t\tthis.atomFamily = (options) => createAtomFamily(options, s)\n\t\tthis.selector = (options) => createSelector(options, undefined, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => createTransaction(options, s)\n\t\tthis.timeline = (options) => createTimeline(options, s)\n\t\tthis.getState = (token) => getState(token, s)\n\t\tthis.setState = (token, newValue) => setState(token, newValue, s)\n\t\tthis.subscribe = (token, handler, key) => subscribe(token, handler, key, s)\n\t\tthis.undo = (token) => timeTravel(`backward`, token, s)\n\t\tthis.redo = (token) => timeTravel(`forward`, token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadableToken,\n\tTimelineManageable,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionToken,\n\tTransactionUpdate,\n\tƒn,\n} from \".\"\n\nexport type StateUpdate<T> = { newValue: T; oldValue: T }\nexport type KeyedStateUpdate<T> = StateUpdate<T> & {\n\tkey: string\n\tfamily?: FamilyMetadata\n}\nexport type UpdateHandler<T> = (update: StateUpdate<T>) => void\n\nexport type TransactionUpdateHandler<ƒ extends ƒn> = (\n\tdata: TransactionUpdate<ƒ>,\n) => void\n\nexport function subscribe<T>(\n\ttoken: ReadableToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<ƒ extends ƒn>(\n\ttoken: TransactionToken<ƒ>,\n\thandleUpdate: TransactionUpdateHandler<ƒ>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<M extends TimelineManageable>(\n\ttoken: TimelineToken<M>,\n\thandleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe(\n\ttoken: ReadableToken<any> | TimelineToken<any> | TransactionToken<any>,\n\thandleUpdate: (update: any) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): () => void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\tcase `readonly_selector`:\n\t\tcase `selector`:\n\t\t\treturn subscribeToState(token, handleUpdate, key, store)\n\t\tcase `transaction`:\n\t\t\treturn subscribeToTransaction(token, handleUpdate, key, store)\n\t\tcase `timeline`:\n\t\t\treturn subscribeToTimeline(token, handleUpdate, key, store)\n\t}\n}\n","import type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport { IMPLICIT, createTimeline, timeTravel } from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineManageable = AtomFamily<any, any> | AtomToken<any>\n\nexport type TimelineToken<_> = {\n\tkey: string\n\ttype: `timeline`\n\t__brand?: _\n}\n\nexport type TimelineOptions<ManagedAtom extends TimelineManageable> = {\n\tkey: string\n\tatoms: ManagedAtom[]\n\tshouldCapture?: (\n\t\tupdate: TimelineUpdate<ManagedAtom>,\n\t\ttimeline: Timeline<TimelineManageable>,\n\t) => boolean\n}\n\nexport type TimelineUpdate<ManagedAtom extends TimelineManageable> =\n\t| TimelineAtomUpdate<ManagedAtom>\n\t| TimelineSelectorUpdate<ManagedAtom>\n\t| TimelineTransactionUpdate\n\nexport const timeline = <ManagedAtom extends TimelineManageable>(\n\toptions: TimelineOptions<ManagedAtom>,\n): TimelineToken<ManagedAtom> => {\n\treturn createTimeline(options, IMPLICIT.STORE)\n}\n\nexport const redo = (timeline: TimelineToken<any>): void => {\n\ttimeTravel(`forward`, timeline, IMPLICIT.STORE)\n}\n\nexport const undo = (timeline: TimelineToken<any>): void => {\n\ttimeTravel(`backward`, timeline, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, createTransaction, withdraw } from \"atom.io/internal\"\n\nimport type { KeyedStateUpdate, ReadonlySelectorToken, StateToken, ƒn } from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tupdates: (KeyedStateUpdate<unknown> | TransactionUpdate<ƒn>)[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: StateToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n}>\nexport type TransactorsWithRun = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: StateToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n\trun: typeof runTransaction\n}>\nexport type ReadonlyTransactors = Pick<Transactors, `get`>\n\nexport type Read<ƒ extends ƒn> = (\n\ttransactors: ReadonlyTransactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Write<ƒ extends ƒn> = (\n\ttransactors: Transactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Transact<ƒ extends ƒn> = (\n\ttransactors: TransactorsWithRun,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Transact<ƒ>\n}\n\nexport type TransactionIO<Token extends TransactionToken<any>> =\n\tToken extends TransactionToken<infer ƒ> ? ƒ : never\n\nexport function transaction<ƒ extends ƒn>(\n\toptions: TransactionOptions<ƒ>,\n): TransactionToken<ƒ> {\n\treturn createTransaction(options, IMPLICIT.STORE)\n}\n\nexport const runTransaction =\n\t<ƒ extends ƒn>(token: TransactionToken<ƒ>, store: Store = IMPLICIT.STORE) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(...parameters)\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Cannot run transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n","import type {\n\tAtomFamily,\n\tAtomToken,\n\tReadableFamily,\n\tReadableToken,\n\tReadonlySelectorFamily,\n\tReadonlySelectorToken,\n\tSelectorFamily,\n\tSelectorToken,\n\tWritableFamily,\n\tWritableToken,\n} from \"atom.io\"\n\nexport type TokenType<\n\tComparison extends ReadableFamily<any, any> | ReadableToken<any>,\n> = Comparison extends ReadableToken<infer RepresentedValue>\n\t? RepresentedValue\n\t: Comparison extends ReadableFamily<infer RepresentedValue, any>\n\t ? RepresentedValue\n\t : never\n\nexport function isToken<KnownToken extends AtomToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is AtomToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends SelectorToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is SelectorToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadonlySelectorToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadonlySelectorToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends WritableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is WritableToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends WritableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadableToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadableToken<TokenType<KnownToken>> {\n\treturn knownToken.key === unknownToken.key\n}\n\nexport function belongsTo<Family extends AtomFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is AtomToken<TokenType<Family>>\nexport function belongsTo<Family extends SelectorFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is SelectorToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadonlySelectorFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadonlySelectorToken<TokenType<Family>>\nexport function belongsTo<Family extends WritableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is WritableToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadableToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadableToken<TokenType<Family>> {\n\treturn family.key === unknownToken.family?.key\n}\n"]}
package/dist/index.cjs CHANGED
@@ -154,13 +154,24 @@ var runTransaction = (token, store = Internal3.IMPLICIT.STORE) => (...parameters
154
154
  );
155
155
  };
156
156
 
157
+ // src/validators.ts
158
+ function isToken(knownToken, unknownToken) {
159
+ return knownToken.key === unknownToken.key;
160
+ }
161
+ function belongsTo(family, unknownToken) {
162
+ var _a;
163
+ return family.key === ((_a = unknownToken.family) == null ? void 0 : _a.key);
164
+ }
165
+
157
166
  exports.AtomIOLogger = AtomIOLogger;
158
167
  exports.LOG_LEVELS = LOG_LEVELS;
159
168
  exports.Silo = Silo;
160
169
  exports.atom = atom;
161
170
  exports.atomFamily = atomFamily;
171
+ exports.belongsTo = belongsTo;
162
172
  exports.dispose = dispose;
163
173
  exports.getState = getState;
174
+ exports.isToken = isToken;
164
175
  exports.redo = redo;
165
176
  exports.runTransaction = runTransaction;
166
177
  exports.selector = selector;