atom.io 0.30.7 → 0.31.1

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 (92) hide show
  1. package/data/dist/index.d.ts +20 -18
  2. package/data/dist/index.js +104 -172
  3. package/data/src/join.ts +138 -210
  4. package/dist/{chunk-UDHCFTYT.js → chunk-Y5MBNTVU.js} +582 -762
  5. package/dist/index.d.ts +254 -173
  6. package/dist/index.js +91 -14
  7. package/ephemeral/dist/index.d.ts +35 -25
  8. package/ephemeral/src/find-state.ts +35 -25
  9. package/eslint-plugin/dist/index.d.ts +22 -3
  10. package/eslint-plugin/dist/index.js +7 -7
  11. package/immortal/dist/index.d.ts +1 -2
  12. package/immortal/dist/index.js +0 -3
  13. package/immortal/src/seek-state.ts +2 -14
  14. package/internal/dist/index.d.ts +57 -88
  15. package/internal/dist/index.js +1 -2
  16. package/internal/src/atom/dispose-atom.ts +31 -15
  17. package/internal/src/families/dispose-from-store.ts +15 -44
  18. package/internal/src/families/find-in-store.ts +9 -7
  19. package/internal/src/families/init-family-member.ts +1 -1
  20. package/internal/src/families/seek-in-store.ts +2 -14
  21. package/internal/src/get-state/get-from-store.ts +13 -79
  22. package/internal/src/get-trace.ts +7 -0
  23. package/internal/src/index.ts +17 -8
  24. package/internal/src/ingest-updates/ingest-creation-disposal.ts +65 -73
  25. package/internal/src/ingest-updates/ingest-transaction-update.ts +4 -0
  26. package/internal/src/install-into-store.ts +48 -0
  27. package/internal/src/junction.ts +52 -12
  28. package/internal/src/lineage.ts +0 -7
  29. package/internal/src/molecule.ts +306 -0
  30. package/internal/src/mutable/transceiver.ts +5 -5
  31. package/internal/src/not-found-error.ts +8 -30
  32. package/internal/src/pretty-print.ts +1 -16
  33. package/internal/src/selector/dispose-selector.ts +3 -5
  34. package/internal/src/selector/register-selector.ts +3 -34
  35. package/internal/src/set-state/set-into-store.ts +3 -2
  36. package/internal/src/store/counterfeit.ts +11 -25
  37. package/internal/src/store/deposit.ts +10 -42
  38. package/internal/src/store/store.ts +51 -12
  39. package/internal/src/store/withdraw.ts +18 -60
  40. package/internal/src/timeline/create-timeline.ts +133 -237
  41. package/internal/src/timeline/time-travel.ts +1 -8
  42. package/internal/src/transaction/build-transaction.ts +10 -5
  43. package/internal/src/transaction/index.ts +1 -1
  44. package/internal/src/utility-types.ts +2 -0
  45. package/introspection/dist/index.d.ts +2 -3
  46. package/introspection/dist/index.js +9 -9
  47. package/introspection/src/refinery.ts +1 -3
  48. package/json/dist/index.js +8 -40
  49. package/json/src/index.ts +2 -0
  50. package/json/src/select-json-family.ts +7 -44
  51. package/package.json +33 -28
  52. package/react/dist/index.js +2 -10
  53. package/react/src/parse-state-overloads.ts +3 -11
  54. package/react-devtools/dist/index.js +13 -13
  55. package/react-devtools/src/Updates.tsx +2 -0
  56. package/realtime-client/dist/index.d.ts +20 -12
  57. package/realtime-client/dist/index.js +241 -244
  58. package/realtime-client/src/continuity/index.ts +3 -0
  59. package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +231 -0
  60. package/realtime-client/src/continuity/use-conceal-state.ts +11 -0
  61. package/realtime-client/src/continuity/use-reveal-state.ts +19 -0
  62. package/realtime-client/src/index.ts +1 -0
  63. package/realtime-client/src/sync-continuity.ts +18 -262
  64. package/realtime-react/dist/index.js +2 -2
  65. package/realtime-server/dist/index.d.ts +1 -1
  66. package/realtime-server/dist/index.js +2 -2
  67. package/realtime-server/src/index.ts +1 -1
  68. package/realtime-server/src/ipc-sockets/child-socket.ts +0 -1
  69. package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +1 -1
  70. package/realtime-testing/dist/index.js +5 -7
  71. package/realtime-testing/src/setup-realtime-test.tsx +5 -6
  72. package/src/atom.ts +53 -29
  73. package/src/dispose-state.ts +17 -23
  74. package/src/get-state.ts +19 -21
  75. package/src/index.ts +73 -3
  76. package/src/realm.ts +169 -0
  77. package/src/selector.ts +20 -0
  78. package/src/set-state.ts +16 -8
  79. package/src/silo.ts +9 -14
  80. package/src/timeline.ts +2 -3
  81. package/src/transaction.ts +25 -38
  82. package/transceivers/set-rtx/dist/index.js +4 -1
  83. package/transceivers/set-rtx/src/set-rtx.ts +4 -1
  84. package/dist/chunk-ADMEAXYU.js +0 -167
  85. package/internal/src/molecule/create-molecule-family.ts +0 -30
  86. package/internal/src/molecule/dispose-molecule.ts +0 -79
  87. package/internal/src/molecule/grow-molecule-in-store.ts +0 -95
  88. package/internal/src/molecule/index.ts +0 -5
  89. package/internal/src/molecule/make-molecule-in-store.ts +0 -191
  90. package/internal/src/molecule/molecule-internal.ts +0 -52
  91. package/src/allocate.ts +0 -277
  92. package/src/molecule.ts +0 -138
@@ -1,9 +1,7 @@
1
1
  import * as AtomIO from 'atom.io';
2
- import { ReadonlySelectorFamilyToken, MutableAtomFamilyToken, SetterToolkit, disposeState, ReadonlySelectorToken } from 'atom.io';
3
- import { Store, JunctionSchemaBase, JunctionEntriesBase, Molecule, Junction } from 'atom.io/internal';
2
+ import { ReadonlySelectorFamilyToken, SingularTypedKey, Hierarchy, CompoundTypedKey, MutableAtomFamilyToken, SetterToolkit, Anarchy, ReadonlySelectorToken } from 'atom.io';
3
+ import { Store, JunctionSchemaBase, JunctionEntriesBase, Refinement, Molecule, Junction } from 'atom.io/internal';
4
4
  import { Canonical, stringified, Json } from 'atom.io/json';
5
- import { findState } from 'atom.io/ephemeral';
6
- import { Refinement } from 'atom.io/introspection';
7
5
  import { SetRTX, SetRTXJson } from 'atom.io/transceivers/set-rtx';
8
6
 
9
7
  declare function dict<State, Key extends Canonical>(family: AtomIO.ReadonlySelectorFamilyToken<State, Key> | AtomIO.RegularAtomFamilyToken<State, Key> | AtomIO.WritableSelectorFamilyToken<State, Key>, index: AtomIO.ReadonlySelectorToken<Key[]> | AtomIO.RegularAtomToken<Key[]> | AtomIO.WritableSelectorToken<Key[]>, store?: Store): AtomIO.ReadonlySelectorToken<{
@@ -59,24 +57,31 @@ type JoinStateFamilies<ASide extends string, AType extends string, BSide extends
59
57
  } & {
60
58
  readonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: ReadonlySelectorFamilyToken<BType[], AType>;
61
59
  } : never;
62
- declare class Join<const ASide extends string, const AType extends string, const BSide extends string, const BType extends string, const Cardinality extends `1:1` | `1:n` | `n:n`, const Content extends Json.Object | null = null> {
63
- private options;
64
- private defaultContent;
60
+ type JoinHierarchy<AType extends SingularTypedKey, BType extends SingularTypedKey> = Hierarchy<[
61
+ {
62
+ above: `root`;
63
+ below: [AType, BType];
64
+ },
65
+ {
66
+ above: [AType, BType];
67
+ style: `all`;
68
+ below: CompoundTypedKey<`content`, AType, BType>;
69
+ }
70
+ ]>;
71
+ declare class Join<const ASide extends string, const AType extends string, const BSide extends string, const BType extends string, const Cardinality extends `1:1` | `1:n` | `n:n`, const Content extends Json.Object | null = null, const ContentKey extends CompoundTypedKey<`content`, ASide, BSide> = CompoundTypedKey<`content`, ASide, BSide>> {
65
72
  private toolkit;
66
- retrieve: typeof findState;
73
+ options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>;
74
+ defaultContent: Content | undefined;
67
75
  molecules: Map<string, Molecule<any>>;
68
76
  relations: Junction<ASide, AType, BSide, BType, Content>;
69
77
  states: JoinStateFamilies<ASide, AType, BSide, BType, Cardinality, Content>;
70
78
  core: {
71
- findRelatedKeysState: MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string>;
79
+ relatedKeysAtoms: MutableAtomFamilyToken<SetRTX<string>, SetRTXJson<string>, string>;
72
80
  };
73
- transact(toolkit: SetterToolkit & {
74
- dispose: typeof disposeState;
75
- }, run: (join: Join<ASide, AType, BSide, BType, Cardinality, Content>) => void): void;
81
+ transact(toolkit: SetterToolkit, run: (join: Join<ASide, AType, BSide, BType, Cardinality, Content>) => void): void;
76
82
  store: Store;
77
- alternates: Map<string, Join<ASide, AType, BSide, BType, Cardinality, Content>>;
83
+ realm: Anarchy;
78
84
  [Symbol.dispose](): void;
79
- in(store: Store): Join<ASide, AType, BSide, BType, Cardinality, Content>;
80
85
  constructor(options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>, defaultContent: Content | undefined, store?: Store);
81
86
  }
82
87
  type JoinToken<ASide extends string, AType extends string, BSide extends string, BType extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null = null> = {
@@ -91,9 +96,6 @@ type JoinToken<ASide extends string, AType extends string, BSide extends string,
91
96
  };
92
97
  declare function join<const ASide extends string, const AType extends string, const BSide extends string, const BType extends string, const Cardinality extends `1:1` | `1:n` | `n:n`>(options: JoinOptions<ASide, AType, BSide, BType, Cardinality, null>, defaultContent?: undefined, store?: Store): JoinToken<ASide, AType, BSide, BType, Cardinality, null>;
93
98
  declare function join<const ASide extends string, const AType extends string, const BSide extends string, const BType extends string, const Cardinality extends `1:1` | `1:n` | `n:n`, const Content extends Json.Object>(options: JoinOptions<ASide, AType, BSide, BType, Cardinality, Content>, defaultContent: Content, store?: Store): JoinToken<ASide, AType, BSide, BType, Cardinality, Content>;
94
- declare function getJoinMap(store: Store & {
95
- joins?: Map<string, Join<any, any, any, any, any, any>>;
96
- }): Map<string, Join<any, any, any, any, any, any>>;
97
99
  declare function getJoin<ASide extends string, AType extends string, BSide extends string, BType extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null>(token: JoinToken<ASide, AType, BSide, BType, Cardinality, Content>, store: Store): Join<ASide, AType, BSide, BType, Cardinality, Content>;
98
100
  type JoinStates<ASide extends string, AType extends string, BSide extends string, BType extends string, Cardinality extends `1:1` | `1:n` | `n:n`, Content extends Json.Object | null> = Cardinality extends `1:1` ? (Content extends Json.Object ? {
99
101
  readonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: ReadonlySelectorToken<[
@@ -177,4 +179,4 @@ type Fated<T, E extends Error = Error> = Loadable<E | T>;
177
179
  */
178
180
  declare function until<T>(loadable: Loadable<T>, fallback: T): T;
179
181
 
180
- 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 };
182
+ export { type Fated, Join, type JoinHierarchy, type JoinOptions, type JoinStateFamilies, type JoinStates, type JoinToken, type Loadable, dict, editRelations, editRelationsInStore, findRelations, findRelationsInStore, getInternalRelations, getInternalRelationsFromStore, getJoin, join, struct, structFamily, until };
@@ -1,5 +1,6 @@
1
1
  import '../../dist/chunk-XWL6SNVU.js';
2
- import { createStandaloneSelector, findInStore, IMPLICIT, withdraw, growMoleculeInStore, NotFoundError, initFamilyMemberInStore, getFromStore, setIntoStore, seekInStore, getJsonToken, disposeFromStore, createMutableAtomFamily, createRegularAtomFamily, createMoleculeFamily, Junction, newest, makeMoleculeInStore, isChildStore, createRegularAtom, createSelectorFamily, createReadonlySelectorFamily, getJsonFamily } from 'atom.io/internal';
2
+ import { createStandaloneSelector, findInStore, IMPLICIT, getFromStore, setIntoStore, seekInStore, getJsonToken, createMutableAtomFamily, createRegularAtomFamily, Junction, newest, isChildStore, createRegularAtom, createSelectorFamily, createReadonlySelectorFamily, getJsonFamily } from 'atom.io/internal';
3
+ import { Anarchy } from 'atom.io';
3
4
  import { stringifyJson } from 'atom.io/json';
4
5
  import { SetRTX } from 'atom.io/transceivers/set-rtx';
5
6
 
@@ -18,11 +19,10 @@ function dict(family, index, store = IMPLICIT.STORE) {
18
19
  function capitalize(string) {
19
20
  return string[0].toUpperCase() + string.slice(1);
20
21
  }
21
- var Join = class _Join {
22
+ var Join = class {
23
+ toolkit;
22
24
  options;
23
25
  defaultContent;
24
- toolkit;
25
- retrieve;
26
26
  molecules = /* @__PURE__ */ new Map();
27
27
  relations;
28
28
  states;
@@ -34,54 +34,24 @@ var Join = class _Join {
34
34
  this.toolkit = originalToolkit;
35
35
  }
36
36
  store;
37
- alternates;
37
+ realm;
38
38
  [Symbol.dispose]() {
39
- this.alternates.delete(this.store.config.name);
40
- }
41
- in(store) {
42
- const key = store.config.name;
43
- const alternate = this.alternates.get(key);
44
- if (alternate) {
45
- return alternate;
46
- }
47
- const join2 = new _Join(this.options, this.defaultContent, store);
48
- this.alternates.set(key, join2);
49
- join2.alternates = this.alternates;
50
- return join2;
51
39
  }
52
40
  constructor(options, defaultContent, store = IMPLICIT.STORE) {
53
41
  this.store = store;
42
+ this.realm = new Anarchy(store);
54
43
  this.options = options;
55
44
  this.defaultContent = defaultContent;
56
- this.alternates = /* @__PURE__ */ new Map();
57
- this.alternates.set(store.config.name, this);
58
45
  this.store.miscResources.set(`join:${options.key}`, this);
59
- this.retrieve = (token, key) => {
60
- const maybeToken = this.toolkit.seek(token, key);
61
- if (maybeToken) {
62
- return maybeToken;
63
- }
64
- const molecule = this.store.molecules.get(stringifyJson(key));
65
- if (molecule) {
66
- const family = withdraw(token, store);
67
- return growMoleculeInStore(molecule, family, store);
68
- }
69
- if (store.config.lifespan === `immortal`) {
70
- throw new NotFoundError(token, key, store);
71
- }
72
- return initFamilyMemberInStore(store, token, key);
73
- };
46
+ this.realm.allocate(`root`, options.key);
74
47
  this.toolkit = {
75
48
  get: (...ps) => getFromStore(store, ...ps),
76
49
  set: (...ps) => {
77
50
  setIntoStore(store, ...ps);
78
51
  },
79
- find: this.retrieve,
52
+ find: (...ps) => findInStore(store, ...ps),
80
53
  seek: (...ps) => seekInStore(store, ...ps),
81
- json: (token) => getJsonToken(store, token),
82
- dispose: (...ps) => {
83
- disposeFromStore(store, ...ps);
84
- }
54
+ json: (token) => getJsonToken(store, token)
85
55
  };
86
56
  const aSide = options.between[0];
87
57
  const bSide = options.between[1];
@@ -96,44 +66,35 @@ var Join = class _Join {
96
66
  },
97
67
  [`join`, `relations`]
98
68
  );
99
- this.core = { findRelatedKeysState: relatedKeysAtoms };
100
- const getRelatedKeys = ({ get }, key) => get(this.retrieve(relatedKeysAtoms, key));
101
- const addRelation = (toolkit, a, b) => {
102
- const { set } = toolkit;
103
- const aKeysState = this.retrieve(relatedKeysAtoms, a);
104
- const bKeysState = this.retrieve(relatedKeysAtoms, b);
105
- set(aKeysState, (aKeys) => aKeys.add(b));
106
- set(bKeysState, (bKeys) => bKeys.add(a));
69
+ this.core = { relatedKeysAtoms };
70
+ const getRelatedKeys = ({ get }, key) => get(relatedKeysAtoms, key);
71
+ const addRelation = ({ set }, a, b) => {
72
+ if (!this.store.molecules.has(stringifyJson(a))) {
73
+ this.realm.allocate(options.key, a);
74
+ }
75
+ set(relatedKeysAtoms, a, (aKeys) => aKeys.add(b));
76
+ set(relatedKeysAtoms, b, (bKeys) => bKeys.add(a));
107
77
  };
108
- const deleteRelation = (toolkit, a, b) => {
109
- const { set } = toolkit;
110
- const aKeysState = this.retrieve(relatedKeysAtoms, a);
111
- const bKeysState = this.retrieve(relatedKeysAtoms, b);
112
- set(aKeysState, (aKeys) => {
78
+ const deleteRelation = ({ set }, a, b) => {
79
+ set(relatedKeysAtoms, a, (aKeys) => {
113
80
  aKeys.delete(b);
114
- if (aKeys.size === 0) ;
115
81
  return aKeys;
116
82
  });
117
- set(bKeysState, (bKeys) => {
83
+ set(relatedKeysAtoms, b, (bKeys) => {
118
84
  bKeys.delete(a);
119
- if (bKeys.size === 0) ;
120
85
  return bKeys;
121
86
  });
122
87
  };
123
88
  const replaceRelationsSafely = (toolkit, a, newRelationsOfA) => {
124
- const { get, set } = toolkit;
125
- const relationsOfAState = this.retrieve(relatedKeysAtoms, a);
89
+ const { find, get, set } = toolkit;
90
+ const relationsOfAState = find(relatedKeysAtoms, a);
126
91
  const currentRelationsOfA = get(relationsOfAState);
127
92
  for (const currentRelationB of currentRelationsOfA) {
128
93
  const remainsRelated = newRelationsOfA.includes(currentRelationB);
129
94
  if (remainsRelated) {
130
95
  continue;
131
96
  }
132
- const relationsOfBState = this.retrieve(
133
- relatedKeysAtoms,
134
- currentRelationB
135
- );
136
- set(relationsOfBState, (relationsOfB) => {
97
+ set(relatedKeysAtoms, currentRelationB, (relationsOfB) => {
137
98
  relationsOfB.delete(a);
138
99
  return relationsOfB;
139
100
  });
@@ -180,8 +141,7 @@ var Join = class _Join {
180
141
  };
181
142
  const replaceRelationsUnsafely = (toolkit, a, newRelationsOfA) => {
182
143
  const { set } = toolkit;
183
- const relationsOfAState = this.retrieve(relatedKeysAtoms, a);
184
- set(relationsOfAState, (relationsOfA) => {
144
+ set(relatedKeysAtoms, a, (relationsOfA) => {
185
145
  relationsOfA.transaction((nextRelationsOfA) => {
186
146
  for (const newRelationB of newRelationsOfA) {
187
147
  nextRelationsOfA.add(newRelationB);
@@ -191,8 +151,7 @@ var Join = class _Join {
191
151
  return relationsOfA;
192
152
  });
193
153
  for (const newRelationB of newRelationsOfA) {
194
- const newRelationsBState = this.retrieve(relatedKeysAtoms, newRelationB);
195
- set(newRelationsBState, (newRelationsB) => {
154
+ set(relatedKeysAtoms, newRelationB, (newRelationsB) => {
196
155
  newRelationsB.add(a);
197
156
  return newRelationsB;
198
157
  });
@@ -206,6 +165,14 @@ var Join = class _Join {
206
165
  const baseExternalStoreConfiguration = {
207
166
  getRelatedKeys: (key) => getRelatedKeys(this.toolkit, key),
208
167
  addRelation: (a, b) => {
168
+ this.store.moleculeJoins.set(
169
+ a,
170
+ options.key
171
+ );
172
+ this.store.moleculeJoins.set(
173
+ b,
174
+ options.key
175
+ );
209
176
  addRelation(this.toolkit, a, b);
210
177
  },
211
178
  deleteRelation: (a, b) => {
@@ -221,7 +188,6 @@ var Join = class _Join {
221
188
  };
222
189
  let externalStore;
223
190
  let contentAtoms;
224
- let contentMolecules;
225
191
  if (defaultContent) {
226
192
  contentAtoms = createRegularAtomFamily(
227
193
  store,
@@ -231,24 +197,9 @@ var Join = class _Join {
231
197
  },
232
198
  [`join`, `content`]
233
199
  );
234
- contentMolecules = createMoleculeFamily(store, {
235
- key: `${options.key}/content-molecules`,
236
- new: class ContentMolecule {
237
- constructor(_, key) {
238
- this.key = key;
239
- }
240
- }
241
- });
242
- const getContent = ({ get }, key) => get(this.retrieve(contentAtoms, key));
200
+ const getContent = ({ get }, key) => get(contentAtoms, key);
243
201
  const setContent = ({ set }, key, content) => {
244
- set(this.retrieve(contentAtoms, key), content);
245
- };
246
- const deleteContent = (_, compositeKey) => {
247
- const contentMolecule = store.molecules.get(`"${compositeKey}"`);
248
- if (contentMolecule) {
249
- this.toolkit.dispose(contentMolecule);
250
- this.molecules.delete(`"${compositeKey}"`);
251
- }
202
+ set(contentAtoms, key, content);
252
203
  };
253
204
  const externalStoreWithContentConfiguration = {
254
205
  getContent: (contentKey) => {
@@ -259,7 +210,7 @@ var Join = class _Join {
259
210
  setContent(this.toolkit, contentKey, content);
260
211
  },
261
212
  deleteContent: (contentKey) => {
262
- deleteContent(this.toolkit, contentKey);
213
+ this.realm.deallocate(contentKey);
263
214
  }
264
215
  };
265
216
  externalStore = Object.assign(
@@ -276,35 +227,30 @@ var Join = class _Join {
276
227
  isAType: options.isAType,
277
228
  isBType: options.isBType,
278
229
  makeContentKey: (...args) => {
230
+ const [a, b] = args;
279
231
  const sorted = args.sort();
280
232
  const compositeKey = `${sorted[0]}:${sorted[1]}`;
281
- const [m0, m1] = sorted.map(
282
- (key) => this.molecules.get(stringifyJson(key))
283
- );
284
- if (store.config.lifespan === `immortal` && m0 && m1) {
285
- const target = newest(store);
286
- const moleculeToken = makeMoleculeInStore(
287
- target,
288
- [m0, m1],
289
- contentMolecules,
290
- compositeKey
291
- );
292
- this.molecules.set(
293
- `"${compositeKey}"`,
294
- withdraw(moleculeToken, target)
295
- );
233
+ const aMolecule = store.molecules.get(stringifyJson(a));
234
+ const bMolecule = store.molecules.get(stringifyJson(b));
235
+ if (!aMolecule) {
236
+ this.realm.allocate(options.key, a);
296
237
  }
238
+ if (!bMolecule) {
239
+ this.realm.allocate(options.key, b);
240
+ }
241
+ this.realm.allocate(a, compositeKey, `all`);
242
+ this.realm.claim(b, compositeKey);
243
+ this.store.moleculeJoins.set(compositeKey, options.key);
297
244
  return compositeKey;
298
245
  }
299
246
  }
300
247
  );
301
- const createSingleKeyStateFamily = () => createReadonlySelectorFamily(
248
+ const createSingleKeySelectorFamily = () => createReadonlySelectorFamily(
302
249
  store,
303
250
  {
304
251
  key: `${options.key}/singleRelatedKey`,
305
252
  get: (key) => ({ get }) => {
306
- const relatedKeysState = this.retrieve(relatedKeysAtoms, key);
307
- const relatedKeys = get(relatedKeysState);
253
+ const relatedKeys = get(relatedKeysAtoms, key);
308
254
  for (const relatedKey of relatedKeys) {
309
255
  return relatedKey;
310
256
  }
@@ -313,36 +259,33 @@ var Join = class _Join {
313
259
  },
314
260
  [`join`, `keys`]
315
261
  );
316
- const getMultipleKeyStateFamily = () => {
262
+ const getMultipleKeySelectorFamily = () => {
317
263
  return createReadonlySelectorFamily(
318
264
  store,
319
265
  {
320
266
  key: `${options.key}/multipleRelatedKeys`,
321
267
  get: (key) => ({ get }) => {
322
268
  const jsonFamily = getJsonFamily(relatedKeysAtoms, store);
323
- const jsonState = this.retrieve(jsonFamily, key);
324
- const json = get(jsonState);
269
+ const json = get(jsonFamily, key);
325
270
  return json.members;
326
271
  }
327
272
  },
328
273
  [`join`, `keys`]
329
274
  );
330
275
  };
331
- const createSingleEntryStateFamily = () => createReadonlySelectorFamily(
276
+ const createSingleEntrySelectorFamily = () => createReadonlySelectorFamily(
332
277
  store,
333
278
  {
334
279
  key: `${options.key}/singleRelatedEntry`,
335
280
  get: (x) => ({ get }) => {
336
- const relatedKeysState = this.retrieve(relatedKeysAtoms, x);
337
- const relatedKeys = get(relatedKeysState);
281
+ const relatedKeys = get(relatedKeysAtoms, x);
338
282
  for (const y of relatedKeys) {
339
- let a = relations.isAType?.(x) ? x : void 0;
340
- let b = a === void 0 ? x : void 0;
283
+ let a = relations.isAType?.(x) ? x : undefined;
284
+ let b = a === undefined ? x : undefined;
341
285
  a ??= y;
342
286
  b ??= y;
343
287
  const contentKey = relations.makeContentKey(a, b);
344
- const contentState = this.retrieve(contentAtoms, contentKey);
345
- const content = get(contentState);
288
+ const content = get(contentAtoms, contentKey);
346
289
  return [y, content];
347
290
  }
348
291
  return null;
@@ -350,22 +293,20 @@ var Join = class _Join {
350
293
  },
351
294
  [`join`, `entries`]
352
295
  );
353
- const getMultipleEntryStateFamily = () => createReadonlySelectorFamily(
296
+ const getMultipleEntrySelectorFamily = () => createReadonlySelectorFamily(
354
297
  store,
355
298
  {
356
299
  key: `${options.key}/multipleRelatedEntries`,
357
300
  get: (x) => ({ get }) => {
358
301
  const jsonFamily = getJsonFamily(relatedKeysAtoms, store);
359
- const jsonState = this.retrieve(jsonFamily, x);
360
- const json = get(jsonState);
302
+ const json = get(jsonFamily, x);
361
303
  return json.members.map((y) => {
362
- let a = relations.isAType?.(x) ? x : void 0;
363
- let b = a === void 0 ? x : void 0;
304
+ let a = relations.isAType?.(x) ? x : undefined;
305
+ let b = a === undefined ? x : undefined;
364
306
  a ??= y;
365
307
  b ??= y;
366
308
  const contentKey = relations.makeContentKey(a, b);
367
- const contentState = this.retrieve(contentAtoms, contentKey);
368
- const content = get(contentState);
309
+ const content = get(contentAtoms, contentKey);
369
310
  return [y, content];
370
311
  });
371
312
  }
@@ -374,21 +315,21 @@ var Join = class _Join {
374
315
  );
375
316
  switch (options.cardinality) {
376
317
  case `1:1`: {
377
- const findSingleRelatedKeyState = createSingleKeyStateFamily();
318
+ const singleRelatedKeySelectors = createSingleKeySelectorFamily();
378
319
  const stateKeyA = `${aSide}KeyOf${capitalize(bSide)}`;
379
320
  const stateKeyB = `${bSide}KeyOf${capitalize(aSide)}`;
380
321
  const baseStates = {
381
- [stateKeyA]: findSingleRelatedKeyState,
382
- [stateKeyB]: findSingleRelatedKeyState
322
+ [stateKeyA]: singleRelatedKeySelectors,
323
+ [stateKeyB]: singleRelatedKeySelectors
383
324
  };
384
325
  let states;
385
326
  if (defaultContent) {
386
- const findSingleRelatedEntryState = createSingleEntryStateFamily();
327
+ const singleEntrySelectors = createSingleEntrySelectorFamily();
387
328
  const entriesStateKeyA = `${aSide}EntryOf${capitalize(bSide)}`;
388
329
  const entriesStateKeyB = `${bSide}EntryOf${capitalize(aSide)}`;
389
330
  const contentStates = {
390
- [entriesStateKeyA]: findSingleRelatedEntryState,
391
- [entriesStateKeyB]: findSingleRelatedEntryState
331
+ [entriesStateKeyA]: singleEntrySelectors,
332
+ [entriesStateKeyB]: singleEntrySelectors
392
333
  };
393
334
  states = Object.assign(baseStates, contentStates);
394
335
  } else {
@@ -399,25 +340,25 @@ var Join = class _Join {
399
340
  break;
400
341
  }
401
342
  case `1:n`: {
402
- const findSingleRelatedKeyState = createSingleKeyStateFamily();
403
- const findMultipleRelatedKeysState = getMultipleKeyStateFamily();
343
+ const singleRelatedKeySelectors = createSingleKeySelectorFamily();
344
+ const multipleRelatedKeysSelectors = getMultipleKeySelectorFamily();
404
345
  const stateKeyA = `${aSide}KeyOf${capitalize(bSide)}`;
405
346
  const stateKeyB = `${bSide}KeysOf${capitalize(aSide)}`;
406
347
  const baseStates = {
407
- [stateKeyA]: findSingleRelatedKeyState,
408
- [stateKeyB]: findMultipleRelatedKeysState
348
+ [stateKeyA]: singleRelatedKeySelectors,
349
+ [stateKeyB]: multipleRelatedKeysSelectors
409
350
  };
410
351
  let states;
411
352
  if (defaultContent) {
412
- const findSingleRelatedEntryState = createSingleEntryStateFamily();
413
- const findMultipleRelatedEntriesState = getMultipleEntryStateFamily();
353
+ const singleRelatedEntrySelectors = createSingleEntrySelectorFamily();
354
+ const multipleRelatedEntriesSelectors = getMultipleEntrySelectorFamily();
414
355
  const entriesStateKeyA = `${aSide}EntryOf${capitalize(bSide)}`;
415
356
  const entriesStateKeyB = `${bSide}EntriesOf${capitalize(
416
357
  aSide
417
358
  )}`;
418
359
  const contentStates = {
419
- [entriesStateKeyA]: findSingleRelatedEntryState,
420
- [entriesStateKeyB]: findMultipleRelatedEntriesState
360
+ [entriesStateKeyA]: singleRelatedEntrySelectors,
361
+ [entriesStateKeyB]: multipleRelatedEntriesSelectors
421
362
  };
422
363
  states = Object.assign(baseStates, contentStates);
423
364
  } else {
@@ -428,16 +369,16 @@ var Join = class _Join {
428
369
  break;
429
370
  }
430
371
  default: {
431
- const findMultipleRelatedKeysState = getMultipleKeyStateFamily();
372
+ const multipleRelatedKeysSelectors = getMultipleKeySelectorFamily();
432
373
  const stateKeyA = `${aSide}KeysOf${capitalize(bSide)}`;
433
374
  const stateKeyB = `${bSide}KeysOf${capitalize(aSide)}`;
434
375
  const baseStates = {
435
- [stateKeyA]: findMultipleRelatedKeysState,
436
- [stateKeyB]: findMultipleRelatedKeysState
376
+ [stateKeyA]: multipleRelatedKeysSelectors,
377
+ [stateKeyB]: multipleRelatedKeysSelectors
437
378
  };
438
379
  let states;
439
380
  if (defaultContent) {
440
- const findMultipleRelatedEntriesState = getMultipleEntryStateFamily();
381
+ const multipleRelatedEntriesSelectors = getMultipleEntrySelectorFamily();
441
382
  const entriesStateKeyA = `${aSide}EntriesOf${capitalize(
442
383
  bSide
443
384
  )}`;
@@ -445,8 +386,8 @@ var Join = class _Join {
445
386
  aSide
446
387
  )}`;
447
388
  const contentStates = {
448
- [entriesStateKeyA]: findMultipleRelatedEntriesState,
449
- [entriesStateKeyB]: findMultipleRelatedEntriesState
389
+ [entriesStateKeyA]: multipleRelatedEntriesSelectors,
390
+ [entriesStateKeyB]: multipleRelatedEntriesSelectors
450
391
  };
451
392
  states = Object.assign(baseStates, contentStates);
452
393
  } else {
@@ -459,8 +400,7 @@ var Join = class _Join {
459
400
  }
460
401
  };
461
402
  function join(options, defaultContent, store = IMPLICIT.STORE) {
462
- const joins = getJoinMap(store);
463
- joins.set(options.key, new Join(options, defaultContent, store));
403
+ store.joins.set(options.key, new Join(options, defaultContent, store));
464
404
  const token = {
465
405
  key: options.key,
466
406
  type: `join`,
@@ -470,26 +410,18 @@ function join(options, defaultContent, store = IMPLICIT.STORE) {
470
410
  };
471
411
  return token;
472
412
  }
473
- function getJoinMap(store) {
474
- if (`joins` in store && store.joins instanceof Map) {
475
- return store.joins;
476
- }
477
- const joins = /* @__PURE__ */ new Map();
478
- store.joins = joins;
479
- return joins;
480
- }
481
413
  function getJoin(token, store) {
482
- const joinMap = getJoinMap(store);
483
- let myJoin = joinMap.get(token.key);
484
- if (myJoin === void 0) {
485
- const rootJoinMap = getJoinMap(IMPLICIT.STORE);
486
- myJoin = rootJoinMap.get(token.key)?.in(store);
487
- if (myJoin === void 0) {
414
+ let myJoin = store.joins.get(token.key);
415
+ if (myJoin === undefined) {
416
+ const rootJoinMap = IMPLICIT.STORE.joins;
417
+ const rootJoin = rootJoinMap.get(token.key);
418
+ if (rootJoin === undefined) {
488
419
  throw new Error(
489
420
  `Join "${token.key}" not found in store "${store.config.name}"`
490
421
  );
491
422
  }
492
- joinMap.set(token.key, myJoin);
423
+ myJoin = new Join(rootJoin.options, rootJoin.defaultContent, store);
424
+ store.joins.set(token.key, myJoin);
493
425
  }
494
426
  return myJoin;
495
427
  }
@@ -503,12 +435,12 @@ function findRelationsInStore(token, key, store) {
503
435
  relations = {
504
436
  get [keyAB]() {
505
437
  const familyAB = myJoin.states[keyAB];
506
- const state = myJoin.retrieve(familyAB, key);
438
+ const state = findInStore(store, familyAB, key);
507
439
  return state;
508
440
  },
509
441
  get [keyBA]() {
510
442
  const familyBA = myJoin.states[keyBA];
511
- const state = myJoin.retrieve(familyBA, key);
443
+ const state = findInStore(store, familyBA, key);
512
444
  return state;
513
445
  }
514
446
  };
@@ -518,12 +450,12 @@ function findRelationsInStore(token, key, store) {
518
450
  Object.assign(relations, {
519
451
  get [entryAB]() {
520
452
  const familyAB = myJoin.states[entryAB];
521
- const state = myJoin.retrieve(familyAB, key);
453
+ const state = findInStore(store, familyAB, key);
522
454
  return state;
523
455
  },
524
456
  get [entryBA]() {
525
457
  const familyBA = myJoin.states[entryBA];
526
- const state = myJoin.retrieve(familyBA, key);
458
+ const state = findInStore(store, familyBA, key);
527
459
  return state;
528
460
  }
529
461
  });
@@ -536,12 +468,12 @@ function findRelationsInStore(token, key, store) {
536
468
  relations = {
537
469
  get [keyAB]() {
538
470
  const familyAB = myJoin.states[keyAB];
539
- const state = myJoin.retrieve(familyAB, key);
471
+ const state = findInStore(store, familyAB, key);
540
472
  return state;
541
473
  },
542
474
  get [keysBA]() {
543
475
  const familyBA = myJoin.states[keysBA];
544
- const state = myJoin.retrieve(familyBA, key);
476
+ const state = findInStore(store, familyBA, key);
545
477
  return state;
546
478
  }
547
479
  };
@@ -551,12 +483,12 @@ function findRelationsInStore(token, key, store) {
551
483
  Object.assign(relations, {
552
484
  get [entryAB]() {
553
485
  const familyAB = myJoin.states[entryAB];
554
- const state = myJoin.retrieve(familyAB, key);
486
+ const state = findInStore(store, familyAB, key);
555
487
  return state;
556
488
  },
557
489
  get [entriesBA]() {
558
490
  const familyBA = myJoin.states[entriesBA];
559
- const state = myJoin.retrieve(familyBA, key);
491
+ const state = findInStore(store, familyBA, key);
560
492
  return state;
561
493
  }
562
494
  });
@@ -569,12 +501,12 @@ function findRelationsInStore(token, key, store) {
569
501
  relations = {
570
502
  get [keysAB]() {
571
503
  const familyAB = myJoin.states[keysAB];
572
- const state = myJoin.retrieve(familyAB, key);
504
+ const state = findInStore(store, familyAB, key);
573
505
  return state;
574
506
  },
575
507
  get [keysBA]() {
576
508
  const familyBA = myJoin.states[keysBA];
577
- const state = myJoin.retrieve(familyBA, key);
509
+ const state = findInStore(store, familyBA, key);
578
510
  return state;
579
511
  }
580
512
  };
@@ -584,12 +516,12 @@ function findRelationsInStore(token, key, store) {
584
516
  Object.assign(relations, {
585
517
  get [entriesAB]() {
586
518
  const familyAB = myJoin.states[entriesAB];
587
- const state = myJoin.retrieve(familyAB, key);
519
+ const state = findInStore(store, familyAB, key);
588
520
  return state;
589
521
  },
590
522
  get [entriesBA]() {
591
523
  const familyBA = myJoin.states[entriesBA];
592
- const state = myJoin.retrieve(familyBA, key);
524
+ const state = findInStore(store, familyBA, key);
593
525
  return state;
594
526
  }
595
527
  });
@@ -618,7 +550,7 @@ function editRelations(token, change) {
618
550
  }
619
551
  function getInternalRelationsFromStore(token, store) {
620
552
  const myJoin = getJoin(token, store);
621
- const family = myJoin.core.findRelatedKeysState;
553
+ const family = myJoin.core.relatedKeysAtoms;
622
554
  return family;
623
555
  }
624
556
  function getInternalRelations(token) {
@@ -634,7 +566,7 @@ function struct(options, store = IMPLICIT.STORE) {
634
566
  key: `${options.key}.${key}`,
635
567
  default: options.default[key]
636
568
  },
637
- void 0
569
+ undefined
638
570
  );
639
571
  return acc;
640
572
  }, {});
@@ -682,4 +614,4 @@ function until(loadable, fallback) {
682
614
  return loadable;
683
615
  }
684
616
 
685
- export { Join, dict, editRelations, editRelationsInStore, findRelations, findRelationsInStore, getInternalRelations, getInternalRelationsFromStore, getJoin, getJoinMap, join, struct, structFamily, until };
617
+ export { Join, dict, editRelations, editRelationsInStore, findRelations, findRelationsInStore, getInternalRelations, getInternalRelationsFromStore, getJoin, join, struct, structFamily, until };