atom.io 0.18.2 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/data/dist/index.cjs +173 -3
  2. package/data/dist/index.d.ts +52 -21
  3. package/data/dist/index.js +13 -334
  4. package/data/src/join.ts +309 -41
  5. package/dist/chunk-7ZR244C2.js +489 -0
  6. package/dist/{chunk-A4ZCNKWQ.js → chunk-BWWVY5O5.js} +0 -2
  7. package/dist/{chunk-NYCVSXQB.js → chunk-CVBEVTM5.js} +0 -2
  8. package/dist/{chunk-3J2EGSBE.js → chunk-O47EQUM6.js} +1 -3
  9. package/dist/{chunk-PZLG2HP3.js → chunk-U2IICNHQ.js} +0 -2
  10. package/dist/{chunk-XACXFU3B.js → chunk-VAE5OCKN.js} +0 -2
  11. package/dist/{chunk-NYTGCPHB.js → chunk-WX2NCOZR.js} +0 -2
  12. package/dist/{chunk-IZHOMSXA.js → chunk-YDOGCZ53.js} +0 -2
  13. package/dist/index.cjs +0 -2
  14. package/dist/index.js +1 -3
  15. package/internal/dist/index.cjs +0 -2
  16. package/internal/dist/index.js +2 -4
  17. package/introspection/dist/index.cjs +0 -2
  18. package/introspection/dist/index.js +1 -3
  19. package/json/dist/index.cjs +0 -2
  20. package/json/dist/index.js +3 -5
  21. package/package.json +3 -3
  22. package/react/dist/index.cjs +0 -2
  23. package/react/dist/index.js +1 -3
  24. package/react-devtools/dist/index.cjs +0 -2
  25. package/react-devtools/dist/index.css +0 -1
  26. package/react-devtools/dist/index.js +4 -6
  27. package/realtime/dist/index.cjs +4 -4
  28. package/realtime/dist/index.d.ts +1 -96
  29. package/realtime/dist/index.js +6 -6
  30. package/realtime/src/shared-room-store.ts +5 -3
  31. package/realtime-client/dist/index.cjs +0 -2
  32. package/realtime-client/dist/index.js +4 -6
  33. package/realtime-react/dist/index.cjs +0 -2
  34. package/realtime-react/dist/index.js +2 -4
  35. package/realtime-server/dist/index.cjs +162 -20
  36. package/realtime-server/dist/index.d.ts +1 -91
  37. package/realtime-server/dist/index.js +32 -20
  38. package/realtime-server/src/realtime-continuity-synchronizer.ts +8 -6
  39. package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +22 -10
  40. package/realtime-testing/dist/index.cjs +48 -8
  41. package/realtime-testing/dist/index.js +13 -8
  42. package/realtime-testing/src/setup-realtime-test.tsx +8 -2
  43. package/transceivers/set-rtx/dist/index.cjs +0 -2
  44. package/transceivers/set-rtx/dist/index.js +1 -3
  45. package/data/dist/index.cjs.map +0 -1
  46. package/data/dist/index.js.map +0 -1
  47. package/dist/chunk-3J2EGSBE.js.map +0 -1
  48. package/dist/chunk-A4ZCNKWQ.js.map +0 -1
  49. package/dist/chunk-IZHOMSXA.js.map +0 -1
  50. package/dist/chunk-NYCVSXQB.js.map +0 -1
  51. package/dist/chunk-NYTGCPHB.js.map +0 -1
  52. package/dist/chunk-PZLG2HP3.js.map +0 -1
  53. package/dist/chunk-XACXFU3B.js.map +0 -1
  54. package/dist/index.cjs.map +0 -1
  55. package/dist/index.js.map +0 -1
  56. package/internal/dist/index.cjs.map +0 -1
  57. package/internal/dist/index.js.map +0 -1
  58. package/introspection/dist/index.cjs.map +0 -1
  59. package/introspection/dist/index.js.map +0 -1
  60. package/json/dist/index.cjs.map +0 -1
  61. package/json/dist/index.js.map +0 -1
  62. package/react/dist/index.cjs.map +0 -1
  63. package/react/dist/index.js.map +0 -1
  64. package/react-devtools/dist/index.cjs.map +0 -1
  65. package/react-devtools/dist/index.css.map +0 -1
  66. package/react-devtools/dist/index.js.map +0 -1
  67. package/realtime/dist/index.cjs.map +0 -1
  68. package/realtime/dist/index.js.map +0 -1
  69. package/realtime-client/dist/index.cjs.map +0 -1
  70. package/realtime-client/dist/index.js.map +0 -1
  71. package/realtime-react/dist/index.cjs.map +0 -1
  72. package/realtime-react/dist/index.js.map +0 -1
  73. package/realtime-server/dist/index.cjs.map +0 -1
  74. package/realtime-server/dist/index.js.map +0 -1
  75. package/realtime-testing/dist/index.cjs.map +0 -1
  76. package/realtime-testing/dist/index.js.map +0 -1
  77. package/transceivers/set-rtx/dist/index.cjs.map +0 -1
  78. package/transceivers/set-rtx/dist/index.js.map +0 -1
@@ -596,7 +596,171 @@ var Join = class _Join {
596
596
  }
597
597
  };
598
598
  function join(options, defaultContent, store = internal.IMPLICIT.STORE) {
599
- return new Join(options, defaultContent, store);
599
+ const joins = getJoinMap(store);
600
+ joins.set(options.key, new Join(options, defaultContent, store));
601
+ const token = {
602
+ key: options.key,
603
+ type: `join`,
604
+ a: options.between[0],
605
+ b: options.between[1],
606
+ cardinality: options.cardinality
607
+ };
608
+ return token;
609
+ }
610
+ function getJoinMap(store) {
611
+ if (`joins` in store && store.joins instanceof Map) {
612
+ return store.joins;
613
+ }
614
+ const joins = /* @__PURE__ */ new Map();
615
+ store.joins = joins;
616
+ return joins;
617
+ }
618
+ function getJoin(token, store) {
619
+ var _a;
620
+ const joinMap = getJoinMap(store);
621
+ let join2 = joinMap.get(token.key);
622
+ if (join2 === void 0) {
623
+ const rootJoinMap = getJoinMap(internal.IMPLICIT.STORE);
624
+ join2 = (_a = rootJoinMap.get(token.key)) == null ? void 0 : _a.in(store);
625
+ if (join2 === void 0) {
626
+ throw new Error(
627
+ `Join "${token.key}" not found in store "${store.config.name}"`
628
+ );
629
+ }
630
+ joinMap.set(token.key, join2);
631
+ }
632
+ return join2;
633
+ }
634
+ function findRelationsInStore(token, key, store) {
635
+ const join2 = getJoin(token, store);
636
+ let relations;
637
+ switch (token.cardinality) {
638
+ case `1:1`: {
639
+ const keyAB = `${token.a}KeyOf${capitalize(token.b)}`;
640
+ const keyBA = `${token.b}KeyOf${capitalize(token.a)}`;
641
+ relations = {
642
+ get [keyAB]() {
643
+ const familyAB = join2.states[keyAB];
644
+ const state = internal.findInStore(familyAB, key, store);
645
+ return state;
646
+ },
647
+ get [keyBA]() {
648
+ const familyBA = join2.states[keyBA];
649
+ const state = internal.findInStore(familyBA, key, store);
650
+ return state;
651
+ }
652
+ };
653
+ const entryAB = `${token.a}EntryOf${capitalize(token.b)}`;
654
+ if (entryAB in join2.states) {
655
+ const entryBA = `${token.b}EntryOf${capitalize(token.a)}`;
656
+ Object.assign(relations, {
657
+ get [entryAB]() {
658
+ const familyAB = join2.states[entryAB];
659
+ const state = internal.findInStore(familyAB, key, store);
660
+ return state;
661
+ },
662
+ get [entryBA]() {
663
+ const familyBA = join2.states[entryBA];
664
+ const state = internal.findInStore(familyBA, key, store);
665
+ return state;
666
+ }
667
+ });
668
+ }
669
+ break;
670
+ }
671
+ case `1:n`: {
672
+ const keyAB = `${token.a}KeyOf${capitalize(token.b)}`;
673
+ const keysBA = `${token.b}KeysOf${capitalize(token.a)}`;
674
+ relations = {
675
+ get [keyAB]() {
676
+ const familyAB = join2.states[keyAB];
677
+ const state = internal.findInStore(familyAB, key, store);
678
+ return state;
679
+ },
680
+ get [keysBA]() {
681
+ const familyBA = join2.states[keysBA];
682
+ const state = internal.findInStore(familyBA, key, store);
683
+ return state;
684
+ }
685
+ };
686
+ const entryAB = `${token.a}EntryOf${capitalize(token.b)}`;
687
+ if (entryAB in join2.states) {
688
+ const entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`;
689
+ Object.assign(relations, {
690
+ get [entryAB]() {
691
+ const familyAB = join2.states[entryAB];
692
+ const state = internal.findInStore(familyAB, key, store);
693
+ return state;
694
+ },
695
+ get [entriesBA]() {
696
+ const familyBA = join2.states[entriesBA];
697
+ const state = internal.findInStore(familyBA, key, store);
698
+ return state;
699
+ }
700
+ });
701
+ }
702
+ break;
703
+ }
704
+ case `n:n`: {
705
+ const keysAB = `${token.a}KeysOf${capitalize(token.b)}`;
706
+ const keysBA = `${token.b}KeysOf${capitalize(token.a)}`;
707
+ relations = {
708
+ get [keysAB]() {
709
+ const familyAB = join2.states[keysAB];
710
+ const state = internal.findInStore(familyAB, key, store);
711
+ return state;
712
+ },
713
+ get [keysBA]() {
714
+ const familyBA = join2.states[keysBA];
715
+ const state = internal.findInStore(familyBA, key, store);
716
+ return state;
717
+ }
718
+ };
719
+ const entriesAB = `${token.a}EntriesOf${capitalize(token.b)}`;
720
+ if (entriesAB in join2.states) {
721
+ const entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`;
722
+ Object.assign(relations, {
723
+ get [entriesAB]() {
724
+ const familyAB = join2.states[entriesAB];
725
+ const state = internal.findInStore(familyAB, key, store);
726
+ return state;
727
+ },
728
+ get [entriesBA]() {
729
+ const familyBA = join2.states[entriesBA];
730
+ const state = internal.findInStore(familyBA, key, store);
731
+ return state;
732
+ }
733
+ });
734
+ }
735
+ }
736
+ }
737
+ return relations;
738
+ }
739
+ function findRelations(token, key) {
740
+ return findRelationsInStore(token, key, internal.IMPLICIT.STORE);
741
+ }
742
+ function editRelationsInStore(token, change, store) {
743
+ const join2 = getJoin(token, store);
744
+ const target = internal.newest(store);
745
+ if (internal.isChildStore(target)) {
746
+ const { transactors } = target.transactionMeta;
747
+ join2.transact(transactors, ({ relations }) => {
748
+ change(relations);
749
+ });
750
+ } else {
751
+ change(join2.relations);
752
+ }
753
+ }
754
+ function editRelations(token, change) {
755
+ editRelationsInStore(token, change, internal.IMPLICIT.STORE);
756
+ }
757
+ function getInternalRelationsFromStore(token, store) {
758
+ const join2 = getJoin(token, store);
759
+ const family = join2.core.findRelatedKeysState;
760
+ return family;
761
+ }
762
+ function getInternalRelations(token) {
763
+ return getInternalRelationsFromStore(token, internal.IMPLICIT.STORE);
600
764
  }
601
765
  var capitalize2 = (str) => str[0].toUpperCase() + str.slice(1);
602
766
  function struct(options, store = internal.IMPLICIT.STORE) {
@@ -667,9 +831,15 @@ function until(loadable, fallback) {
667
831
 
668
832
  exports.Join = Join;
669
833
  exports.dict = dict;
834
+ exports.editRelations = editRelations;
835
+ exports.editRelationsInStore = editRelationsInStore;
836
+ exports.findRelations = findRelations;
837
+ exports.findRelationsInStore = findRelationsInStore;
838
+ exports.getInternalRelations = getInternalRelations;
839
+ exports.getInternalRelationsFromStore = getInternalRelationsFromStore;
840
+ exports.getJoin = getJoin;
841
+ exports.getJoinMap = getJoinMap;
670
842
  exports.join = join;
671
843
  exports.struct = struct;
672
844
  exports.structFamily = structFamily;
673
845
  exports.until = until;
674
- //# sourceMappingURL=out.js.map
675
- //# sourceMappingURL=index.cjs.map
@@ -1,5 +1,5 @@
1
1
  import * as AtomIO from 'atom.io';
2
- import { ReadonlySelectorFamily, MutableAtomFamily, Transactors } from 'atom.io';
2
+ import { ReadonlySelectorFamily, MutableAtomFamily, Transactors, ReadonlySelectorToken, MutableAtomFamilyToken } from 'atom.io';
3
3
  import { Store } from 'atom.io/internal';
4
4
  import { Json, Stringified } from 'atom.io/json';
5
5
  import { SetRTX, SetRTXJson } from 'atom.io/transceivers/set-rtx';
@@ -86,7 +86,7 @@ interface JoinOptions<ASide extends string, BSide extends string, Cardinality ex
86
86
  readonly key: string;
87
87
  readonly cardinality: Cardinality;
88
88
  }
89
- type JoinState<ASide extends string, BSide extends string, Cardinality extends Cardinality, Content extends Json.Object | null> = Cardinality extends `1:1` ? (Content extends Json.Object ? {
89
+ type JoinStateFamilies<ASide extends string, BSide extends string, Cardinality extends Cardinality, Content extends Json.Object | null> = Cardinality extends `1:1` ? (Content extends Json.Object ? {
90
90
  readonly [AB in ASide | BSide as AB extends ASide ? `${AB}EntryOf${Capitalize<BSide>}` : `${AB}EntryOf${Capitalize<ASide>}`]: ReadonlySelectorFamily<[
91
91
  string,
92
92
  Content
@@ -120,7 +120,7 @@ declare class Join<const ASide extends string, const BSide extends string, const
120
120
  private defaultContent;
121
121
  private transactors;
122
122
  relations: Junction<ASide, BSide, Content>;
123
- states: JoinState<ASide, BSide, Cardinality, Content>;
123
+ states: JoinStateFamilies<ASide, BSide, Cardinality, Content>;
124
124
  core: {
125
125
  findRelatedKeysState: MutableAtomFamily<SetRTX<string>, SetRTXJson<string>, string>;
126
126
  };
@@ -129,24 +129,55 @@ declare class Join<const ASide extends string, const BSide extends string, const
129
129
  in(store: Store): Join<ASide, BSide, Cardinality, Content>;
130
130
  constructor(options: JoinOptions<ASide, BSide, Cardinality, Content>, defaultContent: Content | undefined, store?: Store);
131
131
  }
132
- declare function join<const ASide extends string, const BSide extends string, const Cardinality extends `1:1` | `1:n` | `n:n`>(options: JoinOptions<ASide, BSide, Cardinality, null>, defaultContent?: undefined, store?: Store): {
133
- readonly relations: Junction<ASide, BSide, null>;
134
- readonly states: JoinState<ASide, BSide, Cardinality, null>;
135
- readonly in: (store: Store) => Join<ASide, BSide, Cardinality>;
136
- readonly transact: (transactors: Transactors, run: (join: Join<ASide, BSide, Cardinality, null>) => void) => void;
137
- readonly core: {
138
- readonly findRelatedKeysState: MutableAtomFamily<SetRTX<string>, SetRTXJson<string>, string>;
139
- };
140
- };
141
- declare function join<const ASide extends string, const BSide extends string, const Cardinality extends `1:1` | `1:n` | `n:n`, const Content extends Json.Object>(options: JoinOptions<ASide, BSide, Cardinality, Content>, defaultContent: Content, store?: Store): {
142
- readonly relations: Junction<ASide, BSide, Content>;
143
- readonly states: JoinState<ASide, BSide, Cardinality, Content>;
144
- readonly in: (store: Store) => Join<ASide, BSide, Cardinality, Content>;
145
- readonly transact: (transactors: Transactors, run: (join: Join<ASide, BSide, Cardinality, Content>) => void) => void;
146
- readonly core: {
147
- readonly findRelatedKeysState: MutableAtomFamily<SetRTX<string>, SetRTXJson<string>, string>;
148
- };
132
+ type JoinToken<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null = null> = {
133
+ key: string;
134
+ type: `join`;
135
+ cardinality: Cardinality;
136
+ a: ASide;
137
+ b: BSide;
138
+ __content?: Content;
149
139
  };
140
+ declare function join<const ASide extends string, const BSide extends string, const Cardinality extends `1:1` | `1:n` | `n:n`>(options: JoinOptions<ASide, BSide, Cardinality, null>, defaultContent?: undefined, store?: Store): JoinToken<ASide, BSide, Cardinality, null>;
141
+ declare function join<const ASide extends string, const BSide extends string, const Cardinality extends `1:1` | `1:n` | `n:n`, const Content extends Json.Object>(options: JoinOptions<ASide, BSide, Cardinality, Content>, defaultContent: Content, store?: Store): JoinToken<ASide, BSide, Cardinality, Content>;
142
+ declare function getJoinMap(store: Store & {
143
+ joins?: Map<string, Join<any, any, any, any>>;
144
+ }): Map<string, Join<any, any, any, any>>;
145
+ declare function getJoin<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null>(token: JoinToken<ASide, BSide, Cardinality, Content>, store: Store): Join<ASide, BSide, Cardinality, Content>;
146
+ type JoinStates<ASide extends string, BSide extends string, Cardinality extends Cardinality, Content extends Json.Object | null> = Cardinality extends `1:1` ? (Content extends Json.Object ? {
147
+ readonly [AB in ASide | BSide as AB extends ASide ? `${AB}EntryOf${Capitalize<BSide>}` : `${AB}EntryOf${Capitalize<ASide>}`]: ReadonlySelectorToken<[
148
+ string,
149
+ Content
150
+ ] | null>;
151
+ } : {}) & {
152
+ readonly [AB in ASide | BSide as AB extends ASide ? `${AB}KeyOf${Capitalize<BSide>}` : `${AB}KeyOf${Capitalize<ASide>}`]: ReadonlySelectorToken<string | null>;
153
+ } : Cardinality extends `1:n` ? (Content extends Json.Object ? {
154
+ readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorToken<[
155
+ string,
156
+ Content
157
+ ] | null>;
158
+ } & {
159
+ readonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorToken<[
160
+ string,
161
+ Content
162
+ ][]>;
163
+ } : {}) & {
164
+ readonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: ReadonlySelectorToken<string | null>;
165
+ } & {
166
+ readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorToken<string[]>;
167
+ } : Cardinality extends `n:n` ? (Content extends Json.Object ? {
168
+ readonly [AB in ASide | BSide as AB extends ASide ? `${AB}EntriesOf${Capitalize<BSide>}` : `${AB}EntriesOf${Capitalize<ASide>}`]: ReadonlySelectorToken<[
169
+ string,
170
+ Content
171
+ ][]>;
172
+ } : {}) & {
173
+ readonly [AB in ASide | BSide as AB extends ASide ? `${AB}KeysOf${Capitalize<BSide>}` : `${AB}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorToken<string[]>;
174
+ } : never;
175
+ declare function findRelationsInStore<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null>(token: JoinToken<ASide, BSide, Cardinality, Content>, key: string, store: Store): JoinStates<ASide, BSide, Cardinality, Content>;
176
+ declare function findRelations<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null>(token: JoinToken<ASide, BSide, Cardinality, Content>, key: string): JoinStates<ASide, BSide, Cardinality, Content>;
177
+ declare function editRelationsInStore<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null>(token: JoinToken<ASide, BSide, Cardinality, Content>, change: (relations: Junction<ASide, BSide, Content>) => void, store: Store): void;
178
+ declare function editRelations<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null>(token: JoinToken<ASide, BSide, Cardinality, Content>, change: (relations: Junction<ASide, BSide, Content>) => void): void;
179
+ declare function getInternalRelationsFromStore(token: JoinToken<any, any, any, any>, store: Store): MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string>;
180
+ declare function getInternalRelations<ASide extends string, BSide extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null>(token: JoinToken<ASide, BSide, Cardinality, Content>): MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string>;
150
181
 
151
182
  declare function struct<Struct extends {
152
183
  [key: string]: unknown;
@@ -180,4 +211,4 @@ type Fated<T, E extends Error = Error> = Loadable<E | T>;
180
211
  */
181
212
  declare function until<T>(loadable: Loadable<T>, fallback: T): T;
182
213
 
183
- export { type Fated, Join, type JoinOptions, type JoinState, type Loadable, dict, join, struct, structFamily, until };
214
+ export { type Fated, Join, type JoinOptions, type JoinStateFamilies, type JoinStates, type JoinToken, type Loadable, dict, editRelations, editRelationsInStore, findRelations, findRelationsInStore, getInternalRelations, getInternalRelationsFromStore, getJoin, getJoinMap, join, struct, structFamily, until };
@@ -1,17 +1,16 @@
1
- import { Junction } from '../../dist/chunk-NYTGCPHB.js';
2
- import '../../dist/chunk-PZLG2HP3.js';
3
- import { createStandaloneSelector, findInStore, IMPLICIT, getFromStore, setIntoStore, createMutableAtomFamily, createRegularAtomFamily, createRegularAtom, createSelectorFamily, getJsonFamily } from 'atom.io/internal';
4
- import { dispose } from 'atom.io';
5
- import { SetRTX } from 'atom.io/transceivers/set-rtx';
1
+ export { Join, editRelations, editRelationsInStore, findRelations, findRelationsInStore, getInternalRelations, getInternalRelationsFromStore, getJoin, getJoinMap, join } from '../../dist/chunk-7ZR244C2.js';
2
+ import '../../dist/chunk-WX2NCOZR.js';
3
+ import '../../dist/chunk-U2IICNHQ.js';
4
+ import { createStandaloneSelector, findInStore, IMPLICIT, createRegularAtom, createRegularAtomFamily, createSelectorFamily } from 'atom.io/internal';
6
5
 
7
- function dict(findState2, index, store = IMPLICIT.STORE) {
6
+ function dict(findState, index, store = IMPLICIT.STORE) {
8
7
  return createStandaloneSelector(
9
8
  {
10
- key: `${findState2.key}Dict`,
9
+ key: `${findState.key}Dict`,
11
10
  get: ({ get }) => {
12
11
  const keys = get(index);
13
12
  return keys.reduce((acc, key) => {
14
- acc[key] = get(findInStore(findState2, key, store));
13
+ acc[key] = get(findInStore(findState, key, store));
15
14
  return acc;
16
15
  }, {});
17
16
  }
@@ -19,328 +18,10 @@ function dict(findState2, index, store = IMPLICIT.STORE) {
19
18
  store
20
19
  );
21
20
  }
22
- function capitalize(string) {
23
- return string[0].toUpperCase() + string.slice(1);
24
- }
25
- var Join = class _Join {
26
- transact(transactors, run) {
27
- const originalTransactors = this.transactors;
28
- this.transactors = transactors;
29
- run(this);
30
- this.transactors = originalTransactors;
31
- }
32
- in(store) {
33
- const key = store.config.name;
34
- const alternate = this.alternates.get(key);
35
- if (alternate) {
36
- return alternate;
37
- }
38
- const join2 = new _Join(this.options, this.defaultContent, store);
39
- this.alternates.set(key, join2);
40
- join2.alternates = this.alternates;
41
- return join2;
42
- }
43
- constructor(options, defaultContent, store = IMPLICIT.STORE) {
44
- this.options = options;
45
- this.defaultContent = defaultContent;
46
- this.alternates = /* @__PURE__ */ new Map();
47
- this.alternates.set(store.config.name, this);
48
- this.transactors = {
49
- get: (token) => getFromStore(token, store),
50
- set: (token, value) => setIntoStore(token, value, store),
51
- find: (token, key) => findInStore(token, key, store)
52
- };
53
- const a = options.between[0];
54
- const b = options.between[1];
55
- const relatedKeysAtoms = createMutableAtomFamily(
56
- {
57
- key: `${options.key}/relatedKeys`,
58
- default: () => new SetRTX(),
59
- mutable: true,
60
- fromJson: (json) => SetRTX.fromJSON(json),
61
- toJson: (set) => set.toJSON()
62
- },
63
- store
64
- );
65
- this.core = { findRelatedKeysState: relatedKeysAtoms };
66
- const getRelatedKeys = ({ find, get }, key) => get(find(relatedKeysAtoms, key));
67
- const addRelation = (transactors, a2, b2) => {
68
- const { set, find } = transactors;
69
- const aKeysState = find(relatedKeysAtoms, a2);
70
- const bKeysState = find(relatedKeysAtoms, b2);
71
- set(aKeysState, (aKeys) => aKeys.add(b2));
72
- set(bKeysState, (bKeys) => bKeys.add(a2));
73
- };
74
- const deleteRelation = (transactors, a2, b2) => {
75
- const { find, set } = transactors;
76
- const aKeysState = find(relatedKeysAtoms, a2);
77
- const bKeysState = find(relatedKeysAtoms, b2);
78
- set(aKeysState, (aKeys) => (aKeys.delete(b2), aKeys));
79
- set(bKeysState, (bKeys) => (bKeys.delete(a2), bKeys));
80
- };
81
- const replaceRelationsSafely = (transactors, a2, newRelationsOfA) => {
82
- const { find, get, set } = transactors;
83
- const relationsOfAState = find(relatedKeysAtoms, a2);
84
- const currentRelationsOfA = get(relationsOfAState);
85
- for (const currentRelationB of currentRelationsOfA) {
86
- const remainsRelated = newRelationsOfA.includes(currentRelationB);
87
- if (remainsRelated) {
88
- continue;
89
- }
90
- const relationsOfBState = find(relatedKeysAtoms, currentRelationB);
91
- set(relationsOfBState, (relationsOfB) => {
92
- relationsOfB.delete(a2);
93
- return relationsOfB;
94
- });
95
- }
96
- set(relationsOfAState, (relationsOfA) => {
97
- relationsOfA.transaction((nextRelationsOfA) => {
98
- nextRelationsOfA.clear();
99
- for (const newRelationB of newRelationsOfA) {
100
- const relationsOfB = getRelatedKeys(transactors, newRelationB);
101
- const newRelationBIsAlreadyRelated = relationsOfB.has(a2);
102
- if (this.relations.cardinality === `1:n`) {
103
- for (const previousOwner of relationsOfB) {
104
- if (previousOwner === a2) {
105
- continue;
106
- }
107
- const previousOwnerRelations = getRelatedKeys(
108
- transactors,
109
- previousOwner
110
- );
111
- previousOwnerRelations.delete(newRelationB);
112
- }
113
- if (!newRelationBIsAlreadyRelated && relationsOfB.size > 0) {
114
- relationsOfB.clear();
115
- }
116
- }
117
- if (!newRelationBIsAlreadyRelated) {
118
- relationsOfB.add(a2);
119
- }
120
- nextRelationsOfA.add(newRelationB);
121
- }
122
- return true;
123
- });
124
- return relationsOfA;
125
- });
126
- };
127
- const replaceRelationsUnsafely = (transactors, a2, newRelationsOfA) => {
128
- const { find, set } = transactors;
129
- const relationsOfAState = find(relatedKeysAtoms, a2);
130
- set(relationsOfAState, (relationsOfA) => {
131
- relationsOfA.transaction((nextRelationsOfA) => {
132
- for (const newRelationB of newRelationsOfA) {
133
- nextRelationsOfA.add(newRelationB);
134
- }
135
- return true;
136
- });
137
- return relationsOfA;
138
- });
139
- for (const newRelationB of newRelationsOfA) {
140
- const newRelationsBState = find(relatedKeysAtoms, newRelationB);
141
- set(newRelationsBState, (newRelationsB) => {
142
- newRelationsB.add(a2);
143
- return newRelationsB;
144
- });
145
- }
146
- return true;
147
- };
148
- const has = (transactors, a2, b2) => {
149
- const aKeys = getRelatedKeys(transactors, a2);
150
- return b2 ? aKeys.has(b2) : aKeys.size > 0;
151
- };
152
- const baseExternalStoreConfiguration = {
153
- getRelatedKeys: (key) => getRelatedKeys(this.transactors, key),
154
- addRelation: (a2, b2) => addRelation(this.transactors, a2, b2),
155
- deleteRelation: (a2, b2) => deleteRelation(this.transactors, a2, b2),
156
- replaceRelationsSafely: (a2, bs) => replaceRelationsSafely(this.transactors, a2, bs),
157
- replaceRelationsUnsafely: (a2, bs) => replaceRelationsUnsafely(this.transactors, a2, bs),
158
- has: (a2, b2) => has(this.transactors, a2, b2)
159
- };
160
- let externalStore;
161
- let contentAtoms;
162
- if (defaultContent) {
163
- contentAtoms = createRegularAtomFamily(
164
- {
165
- key: `${options.key}/content`,
166
- default: defaultContent
167
- },
168
- store
169
- );
170
- const getContent = ({ find, get }, key) => get(find(contentAtoms, key));
171
- const setContent = ({ find, set }, key, content) => set(find(contentAtoms, key), content);
172
- const deleteContent = ({ find }, key) => dispose(find(contentAtoms, key));
173
- const externalStoreWithContentConfiguration = {
174
- getContent: (contentKey) => {
175
- const content = getContent(this.transactors, contentKey);
176
- return content;
177
- },
178
- setContent: (contentKey, content) => {
179
- setContent(this.transactors, contentKey, content);
180
- },
181
- deleteContent: (contentKey) => {
182
- deleteContent(this.transactors, contentKey);
183
- }
184
- };
185
- externalStore = Object.assign(
186
- baseExternalStoreConfiguration,
187
- externalStoreWithContentConfiguration
188
- );
189
- } else {
190
- externalStore = baseExternalStoreConfiguration;
191
- }
192
- const relations = new Junction(options, {
193
- externalStore,
194
- makeContentKey: (...args) => args.sort().join(`:`)
195
- });
196
- const createSingleKeyStateFamily = () => createSelectorFamily(
197
- {
198
- key: `${options.key}/singleRelatedKey`,
199
- get: (key) => ({ find, get }) => {
200
- const relatedKeysState = find(relatedKeysAtoms, key);
201
- const relatedKeys = get(relatedKeysState);
202
- for (const relatedKey of relatedKeys) {
203
- return relatedKey;
204
- }
205
- return null;
206
- }
207
- },
208
- store
209
- );
210
- const getMultipleKeyStateFamily = () => {
211
- return createSelectorFamily(
212
- {
213
- key: `${options.key}/multipleRelatedKeys`,
214
- get: (key) => ({ find, get }) => {
215
- const jsonFamily = getJsonFamily(relatedKeysAtoms, store);
216
- const jsonState = find(jsonFamily, key);
217
- const json = get(jsonState);
218
- return json.members;
219
- }
220
- },
221
- store
222
- );
223
- };
224
- const createSingleEntryStateFamily = () => createSelectorFamily(
225
- {
226
- key: `${options.key}/singleRelatedEntry`,
227
- get: (key) => ({ find, get }) => {
228
- const relatedKeysState = find(relatedKeysAtoms, key);
229
- const relatedKeys = get(relatedKeysState);
230
- for (const relatedKey of relatedKeys) {
231
- const contentKey = relations.makeContentKey(key, relatedKey);
232
- const contentState = find(contentAtoms, contentKey);
233
- const content = get(contentState);
234
- return [relatedKey, content];
235
- }
236
- return null;
237
- }
238
- },
239
- store
240
- );
241
- const getMultipleEntryStateFamily = () => createSelectorFamily(
242
- {
243
- key: `${options.key}/multipleRelatedEntries`,
244
- get: (key) => ({ find, get }) => {
245
- const jsonFamily = getJsonFamily(relatedKeysAtoms, store);
246
- const json = get(jsonFamily(key));
247
- return json.members.map((relatedKey) => {
248
- const contentKey = relations.makeContentKey(key, relatedKey);
249
- const contentState = find(contentAtoms, contentKey);
250
- const content = get(contentState);
251
- return [relatedKey, content];
252
- });
253
- }
254
- },
255
- store
256
- );
257
- switch (options.cardinality) {
258
- case `1:1`: {
259
- const findSingleRelatedKeyState = createSingleKeyStateFamily();
260
- const stateKeyA = `${a}KeyOf${capitalize(b)}`;
261
- const stateKeyB = `${b}KeyOf${capitalize(a)}`;
262
- const baseStates = {
263
- [stateKeyA]: findSingleRelatedKeyState,
264
- [stateKeyB]: findSingleRelatedKeyState
265
- };
266
- let states;
267
- if (defaultContent) {
268
- const findSingleRelatedEntryState = createSingleEntryStateFamily();
269
- const entriesStateKeyA = `${a}EntryOf${capitalize(b)}`;
270
- const entriesStateKeyB = `${b}EntryOf${capitalize(a)}`;
271
- const contentStates = {
272
- [entriesStateKeyA]: findSingleRelatedEntryState,
273
- [entriesStateKeyB]: findSingleRelatedEntryState
274
- };
275
- states = Object.assign(baseStates, contentStates);
276
- } else {
277
- states = baseStates;
278
- }
279
- this.relations = relations;
280
- this.states = states;
281
- break;
282
- }
283
- case `1:n`: {
284
- const findSingleRelatedKeyState = createSingleKeyStateFamily();
285
- const findMultipleRelatedKeysState = getMultipleKeyStateFamily();
286
- const stateKeyA = `${a}KeyOf${capitalize(b)}`;
287
- const stateKeyB = `${b}KeysOf${capitalize(a)}`;
288
- const baseStates = {
289
- [stateKeyA]: findSingleRelatedKeyState,
290
- [stateKeyB]: findMultipleRelatedKeysState
291
- };
292
- let states;
293
- if (defaultContent) {
294
- const findSingleRelatedEntryState = createSingleEntryStateFamily();
295
- const findMultipleRelatedEntriesState = getMultipleEntryStateFamily();
296
- const entriesStateKeyA = `${a}EntryOf${capitalize(b)}`;
297
- const entriesStateKeyB = `${b}EntriesOf${capitalize(a)}`;
298
- const contentStates = {
299
- [entriesStateKeyA]: findSingleRelatedEntryState,
300
- [entriesStateKeyB]: findMultipleRelatedEntriesState
301
- };
302
- states = Object.assign(baseStates, contentStates);
303
- } else {
304
- states = baseStates;
305
- }
306
- this.relations = relations;
307
- this.states = states;
308
- break;
309
- }
310
- default: {
311
- const findMultipleRelatedKeysState = getMultipleKeyStateFamily();
312
- const stateKeyA = `${a}KeysOf${capitalize(b)}`;
313
- const stateKeyB = `${b}KeysOf${capitalize(a)}`;
314
- const baseStates = {
315
- [stateKeyA]: findMultipleRelatedKeysState,
316
- [stateKeyB]: findMultipleRelatedKeysState
317
- };
318
- let states;
319
- if (defaultContent) {
320
- const findMultipleRelatedEntriesState = getMultipleEntryStateFamily();
321
- const entriesStateKeyA = `${a}EntriesOf${capitalize(b)}`;
322
- const entriesStateKeyB = `${b}EntriesOf${capitalize(a)}`;
323
- const contentStates = {
324
- [entriesStateKeyA]: findMultipleRelatedEntriesState,
325
- [entriesStateKeyB]: findMultipleRelatedEntriesState
326
- };
327
- states = Object.assign(baseStates, contentStates);
328
- } else {
329
- states = baseStates;
330
- }
331
- this.relations = relations;
332
- this.states = states;
333
- }
334
- }
335
- }
336
- };
337
- function join(options, defaultContent, store = IMPLICIT.STORE) {
338
- return new Join(options, defaultContent, store);
339
- }
340
- var capitalize2 = (str) => str[0].toUpperCase() + str.slice(1);
21
+ var capitalize = (str) => str[0].toUpperCase() + str.slice(1);
341
22
  function struct(options, store = IMPLICIT.STORE) {
342
23
  const atoms = Object.keys(options.default).reduce((acc, key) => {
343
- const atomName = options.key + capitalize2(key) + `State`;
24
+ const atomName = options.key + capitalize(key) + `State`;
344
25
  acc[atomName] = createRegularAtom(
345
26
  {
346
27
  key: `${options.key}.${key}`,
@@ -356,7 +37,7 @@ function struct(options, store = IMPLICIT.STORE) {
356
37
  key: options.key,
357
38
  get: ({ get }) => {
358
39
  return Object.keys(options.default).reduce((acc, key) => {
359
- acc[key] = get(atoms[options.key + capitalize2(key) + `State`]);
40
+ acc[key] = get(atoms[options.key + capitalize(key) + `State`]);
360
41
  return acc;
361
42
  }, {});
362
43
  }
@@ -365,8 +46,8 @@ function struct(options, store = IMPLICIT.STORE) {
365
46
  );
366
47
  return [atoms, structState];
367
48
  }
368
- var capitalize3 = (str) => str[0].toUpperCase() + str.slice(1);
369
- var nameFamily = (topKey, subKey) => `find` + capitalize3(topKey) + capitalize3(subKey) + `State`;
49
+ var capitalize2 = (str) => str[0].toUpperCase() + str.slice(1);
50
+ var nameFamily = (topKey, subKey) => `find` + capitalize2(topKey) + capitalize2(subKey) + `State`;
370
51
  function structFamily(options) {
371
52
  const atoms = Object.keys(options.default).reduce((acc, subKey) => {
372
53
  const atomFamilyName = nameFamily(options.key, subKey);
@@ -404,6 +85,4 @@ function until(loadable, fallback) {
404
85
  return loadable;
405
86
  }
406
87
 
407
- export { Join, dict, join, struct, structFamily, until };
408
- //# sourceMappingURL=out.js.map
409
- //# sourceMappingURL=index.js.map
88
+ export { dict, struct, structFamily, until };