atom.io 0.23.5 → 0.24.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 (72) hide show
  1. package/data/dist/index.cjs +51 -27
  2. package/data/dist/index.d.ts +5 -4
  3. package/data/dist/index.js +625 -9
  4. package/data/src/join.ts +74 -46
  5. package/dist/chunk-BF4MVQF6.js +44 -0
  6. package/dist/index.cjs +27 -0
  7. package/dist/index.d.ts +63 -18
  8. package/dist/index.js +27 -3
  9. package/immortal/dist/index.cjs +4 -262
  10. package/immortal/dist/index.d.ts +4 -94
  11. package/immortal/dist/index.js +3 -215
  12. package/immortal/src/index.ts +0 -2
  13. package/immortal/src/seek-state.ts +10 -11
  14. package/internal/dist/index.cjs +279 -111
  15. package/internal/dist/index.d.ts +63 -93
  16. package/internal/dist/index.js +273 -88
  17. package/internal/src/families/dispose-from-store.ts +11 -7
  18. package/internal/src/families/find-in-store.ts +2 -2
  19. package/internal/src/families/init-family-member.ts +37 -25
  20. package/internal/src/families/seek-in-store.ts +11 -15
  21. package/internal/src/get-environment-data.ts +0 -4
  22. package/internal/src/index.ts +1 -0
  23. package/internal/src/ingest-updates/ingest-creation-disposal.ts +8 -8
  24. package/internal/src/molecule/create-molecule-family.ts +30 -0
  25. package/internal/src/molecule/dispose-molecule.ts +76 -0
  26. package/internal/src/molecule/grow-molecule-in-store.ts +89 -0
  27. package/internal/src/molecule/index.ts +5 -0
  28. package/internal/src/molecule/make-molecule-in-store.ts +122 -0
  29. package/internal/src/molecule/molecule-internal.ts +48 -0
  30. package/internal/src/not-found-error.ts +4 -3
  31. package/internal/src/set-state/emit-update.ts +1 -2
  32. package/internal/src/store/deposit.ts +16 -30
  33. package/internal/src/store/store.ts +7 -12
  34. package/internal/src/store/withdraw.ts +30 -19
  35. package/internal/src/timeline/create-timeline.ts +7 -6
  36. package/internal/src/transaction/build-transaction.ts +2 -1
  37. package/introspection/dist/index.cjs +29 -33
  38. package/introspection/dist/index.js +1 -1
  39. package/introspection/src/auditor.ts +6 -6
  40. package/json/dist/index.cjs +4 -4
  41. package/json/dist/index.js +7 -8
  42. package/json/src/select-json-family.ts +6 -5
  43. package/package.json +6 -6
  44. package/react-devtools/dist/index.js +2 -3
  45. package/realtime-client/dist/index.js +362 -15
  46. package/realtime-react/dist/index.cjs +1 -326
  47. package/realtime-react/dist/index.d.ts +1 -14
  48. package/realtime-react/dist/index.js +1 -1
  49. package/realtime-react/src/use-sync-continuity.ts +2 -2
  50. package/realtime-server/dist/index.cjs +3 -151
  51. package/realtime-server/dist/index.d.ts +1 -3
  52. package/realtime-server/dist/index.js +2 -18
  53. package/realtime-server/src/index.ts +0 -2
  54. package/realtime-server/src/realtime-continuity-synchronizer.ts +1 -1
  55. package/realtime-testing/dist/index.cjs +4 -82
  56. package/realtime-testing/dist/index.js +2 -4
  57. package/realtime-testing/src/setup-realtime-test.tsx +2 -3
  58. package/src/dispose-state.ts +2 -2
  59. package/src/index.ts +1 -0
  60. package/src/logger.ts +2 -0
  61. package/src/molecule.ts +133 -0
  62. package/src/timeline.ts +3 -3
  63. package/src/transaction.ts +15 -13
  64. package/dist/chunk-6MLFYN32.js +0 -18
  65. package/dist/chunk-7DT3PVS3.js +0 -598
  66. package/dist/chunk-GVHKIJ3G.js +0 -329
  67. package/dist/chunk-O47EQUM6.js +0 -29
  68. package/dist/chunk-OAYGID5B.js +0 -27
  69. package/dist/chunk-PNIHPILQ.js +0 -8
  70. package/immortal/src/make-molecule.ts +0 -234
  71. package/immortal/src/molecule.ts +0 -167
  72. package/realtime-server/src/realtime-state-synchronizer.ts +0 -23
@@ -1,7 +1,8 @@
1
- export { Join, editRelations, editRelationsInStore, findRelations, findRelationsInStore, getInternalRelations, getInternalRelationsFromStore, getJoin, getJoinMap, join } from '../../dist/chunk-7DT3PVS3.js';
2
- import '../../dist/chunk-FTONNX2R.js';
1
+ import { Junction } from '../../dist/chunk-FTONNX2R.js';
3
2
  import '../../dist/chunk-F2X4B4VY.js';
4
- import { createStandaloneSelector, findInStore, IMPLICIT, createRegularAtom, createRegularAtomFamily, createSelectorFamily } from 'atom.io/internal';
3
+ import { createStandaloneSelector, findInStore, IMPLICIT, getFromStore, setIntoStore, seekInStore, getJsonToken, disposeFromStore, withdraw, growMoleculeInStore, initFamilyMemberInStore, createMutableAtomFamily, createRegularAtomFamily, createMoleculeFamily, newest, makeMoleculeInStore, isChildStore, createRegularAtom, createSelectorFamily, getJsonFamily } from 'atom.io/internal';
4
+ import { stringifyJson } from 'atom.io/json';
5
+ import { SetRTX } from 'atom.io/transceivers/set-rtx';
5
6
 
6
7
  function dict(findState, index, store = IMPLICIT.STORE) {
7
8
  return createStandaloneSelector(
@@ -18,10 +19,625 @@ function dict(findState, index, store = IMPLICIT.STORE) {
18
19
  store
19
20
  );
20
21
  }
21
- var capitalize = (str) => str[0].toUpperCase() + str.slice(1);
22
+ function capitalize(string) {
23
+ return string[0].toUpperCase() + string.slice(1);
24
+ }
25
+ var Join = class _Join {
26
+ constructor(options, defaultContent, store = IMPLICIT.STORE) {
27
+ this.molecules = /* @__PURE__ */ new Map();
28
+ this.store = store;
29
+ this.options = options;
30
+ this.defaultContent = defaultContent;
31
+ this.alternates = /* @__PURE__ */ new Map();
32
+ this.alternates.set(store.config.name, this);
33
+ this.store.miscResources.set(`join:${options.key}`, this);
34
+ this.transactors = {
35
+ get: (token) => getFromStore(token, store),
36
+ set: (token, value) => {
37
+ setIntoStore(token, value, store);
38
+ },
39
+ find: (token, key) => findInStore(token, key, store),
40
+ seek: (token, key) => seekInStore(token, key, store),
41
+ json: (token) => getJsonToken(token, store),
42
+ dispose: (token) => {
43
+ disposeFromStore(token, store);
44
+ }
45
+ };
46
+ this.retrieve = (token, key) => {
47
+ const maybeToken = this.transactors.seek(token, key);
48
+ if (maybeToken) {
49
+ return maybeToken;
50
+ }
51
+ const molecule = this.molecules.get(stringifyJson(key));
52
+ if (molecule) {
53
+ const family = withdraw(token, store);
54
+ return growMoleculeInStore(molecule, family, store);
55
+ }
56
+ if (store.config.lifespan === `immortal`) {
57
+ throw new Error(`No molecule found for key "${stringifyJson(key)}"`);
58
+ }
59
+ return initFamilyMemberInStore(token, key, store);
60
+ };
61
+ const aSide = options.between[0];
62
+ const bSide = options.between[1];
63
+ const relatedKeysAtoms = createMutableAtomFamily(
64
+ {
65
+ key: `${options.key}/relatedKeys`,
66
+ default: () => new SetRTX(),
67
+ mutable: true,
68
+ fromJson: (json) => SetRTX.fromJSON(json),
69
+ toJson: (set) => set.toJSON()
70
+ },
71
+ store
72
+ );
73
+ this.core = { findRelatedKeysState: relatedKeysAtoms };
74
+ const getRelatedKeys = ({ get }, key) => get(this.retrieve(relatedKeysAtoms, key));
75
+ const addRelation = (transactors, a, b) => {
76
+ const { set } = transactors;
77
+ const aKeysState = this.retrieve(relatedKeysAtoms, a);
78
+ const bKeysState = this.retrieve(relatedKeysAtoms, b);
79
+ set(aKeysState, (aKeys) => aKeys.add(b));
80
+ set(bKeysState, (bKeys) => bKeys.add(a));
81
+ };
82
+ const deleteRelation = (transactors, a, b) => {
83
+ const { set } = transactors;
84
+ const aKeysState = this.retrieve(relatedKeysAtoms, a);
85
+ const bKeysState = this.retrieve(relatedKeysAtoms, b);
86
+ let stringA;
87
+ let stringB;
88
+ set(aKeysState, (aKeys) => {
89
+ aKeys.delete(b);
90
+ if (aKeys.size === 0) {
91
+ stringA = `"${a}"`;
92
+ }
93
+ return aKeys;
94
+ });
95
+ set(bKeysState, (bKeys) => {
96
+ bKeys.delete(a);
97
+ if (bKeys.size === 0) {
98
+ stringB = `"${b}"`;
99
+ }
100
+ return bKeys;
101
+ });
102
+ if (stringA) {
103
+ const molecule = this.molecules.get(stringA);
104
+ if (molecule) {
105
+ this.transactors.dispose(molecule);
106
+ }
107
+ }
108
+ if (stringB) {
109
+ const molecule = this.molecules.get(stringB);
110
+ if (molecule) {
111
+ this.transactors.dispose(molecule);
112
+ }
113
+ }
114
+ };
115
+ const replaceRelationsSafely = (transactors, a, newRelationsOfA) => {
116
+ const { get, set } = transactors;
117
+ const relationsOfAState = this.retrieve(relatedKeysAtoms, a);
118
+ const currentRelationsOfA = get(relationsOfAState);
119
+ for (const currentRelationB of currentRelationsOfA) {
120
+ const remainsRelated = newRelationsOfA.includes(currentRelationB);
121
+ if (remainsRelated) {
122
+ continue;
123
+ }
124
+ const relationsOfBState = this.retrieve(
125
+ relatedKeysAtoms,
126
+ currentRelationB
127
+ );
128
+ set(relationsOfBState, (relationsOfB) => {
129
+ relationsOfB.delete(a);
130
+ return relationsOfB;
131
+ });
132
+ }
133
+ set(relationsOfAState, (relationsOfA) => {
134
+ relationsOfA.transaction((nextRelationsOfA) => {
135
+ nextRelationsOfA.clear();
136
+ for (const newRelationB of newRelationsOfA) {
137
+ const relationsOfB = getRelatedKeys(transactors, newRelationB);
138
+ const newRelationBIsAlreadyRelated = relationsOfB.has(a);
139
+ if (this.relations.cardinality === `1:n`) {
140
+ const previousOwnersToDispose = [];
141
+ for (const previousOwner of relationsOfB) {
142
+ if (previousOwner === a) {
143
+ continue;
144
+ }
145
+ const previousOwnerRelations = getRelatedKeys(
146
+ transactors,
147
+ previousOwner
148
+ );
149
+ previousOwnerRelations.delete(newRelationB);
150
+ if (previousOwnerRelations.size === 0) {
151
+ previousOwnersToDispose.push(previousOwner);
152
+ }
153
+ }
154
+ if (!newRelationBIsAlreadyRelated && relationsOfB.size > 0) {
155
+ relationsOfB.clear();
156
+ }
157
+ for (const previousOwner of previousOwnersToDispose) {
158
+ const molecule = this.molecules.get(previousOwner);
159
+ if (molecule) {
160
+ this.transactors.dispose(molecule);
161
+ }
162
+ const sorted = [newRelationB, previousOwner].sort();
163
+ const compositeKey = `"${sorted[0]}:${sorted[1]}"`;
164
+ this.molecules.delete(compositeKey);
165
+ }
166
+ }
167
+ if (!newRelationBIsAlreadyRelated) {
168
+ relationsOfB.add(a);
169
+ }
170
+ nextRelationsOfA.add(newRelationB);
171
+ }
172
+ return true;
173
+ });
174
+ return relationsOfA;
175
+ });
176
+ };
177
+ const replaceRelationsUnsafely = (transactors, a, newRelationsOfA) => {
178
+ const { set } = transactors;
179
+ const relationsOfAState = this.retrieve(relatedKeysAtoms, a);
180
+ set(relationsOfAState, (relationsOfA) => {
181
+ relationsOfA.transaction((nextRelationsOfA) => {
182
+ for (const newRelationB of newRelationsOfA) {
183
+ nextRelationsOfA.add(newRelationB);
184
+ }
185
+ return true;
186
+ });
187
+ return relationsOfA;
188
+ });
189
+ for (const newRelationB of newRelationsOfA) {
190
+ const newRelationsBState = this.retrieve(relatedKeysAtoms, newRelationB);
191
+ set(newRelationsBState, (newRelationsB) => {
192
+ newRelationsB.add(a);
193
+ return newRelationsB;
194
+ });
195
+ }
196
+ return true;
197
+ };
198
+ const has = (transactors, a, b) => {
199
+ const aKeys = getRelatedKeys(transactors, a);
200
+ return b ? aKeys.has(b) : aKeys.size > 0;
201
+ };
202
+ const baseExternalStoreConfiguration = {
203
+ getRelatedKeys: (key) => getRelatedKeys(this.transactors, key),
204
+ addRelation: (a, b) => {
205
+ addRelation(this.transactors, a, b);
206
+ },
207
+ deleteRelation: (a, b) => {
208
+ deleteRelation(this.transactors, a, b);
209
+ },
210
+ replaceRelationsSafely: (a, bs) => {
211
+ replaceRelationsSafely(this.transactors, a, bs);
212
+ },
213
+ replaceRelationsUnsafely: (a, bs) => {
214
+ replaceRelationsUnsafely(this.transactors, a, bs);
215
+ },
216
+ has: (a, b) => has(this.transactors, a, b)
217
+ };
218
+ let externalStore;
219
+ let contentAtoms;
220
+ let contentMolecules;
221
+ if (defaultContent) {
222
+ contentAtoms = createRegularAtomFamily(
223
+ {
224
+ key: `${options.key}/content`,
225
+ default: defaultContent
226
+ },
227
+ store
228
+ );
229
+ const joinToken = {
230
+ key: options.key,
231
+ type: `join`,
232
+ a: options.between[0],
233
+ b: options.between[1],
234
+ cardinality: options.cardinality
235
+ };
236
+ contentMolecules = createMoleculeFamily(
237
+ {
238
+ key: `${options.key}/content-molecules`,
239
+ new: class ContentMolecule {
240
+ constructor(transactors, key) {
241
+ this.key = key;
242
+ transactors.join(joinToken);
243
+ }
244
+ }
245
+ },
246
+ store
247
+ );
248
+ const getContent = ({ get }, key) => get(this.retrieve(contentAtoms, key));
249
+ const setContent = ({ set }, key, content) => {
250
+ set(this.retrieve(contentAtoms, key), content);
251
+ };
252
+ const deleteContent = (_, compositeKey) => {
253
+ const contentMolecule = store.molecules.get(`"${compositeKey}"`);
254
+ if (contentMolecule) {
255
+ this.transactors.dispose(contentMolecule);
256
+ this.molecules.delete(`"${compositeKey}"`);
257
+ }
258
+ };
259
+ const externalStoreWithContentConfiguration = {
260
+ getContent: (contentKey) => {
261
+ const content = getContent(this.transactors, contentKey);
262
+ return content;
263
+ },
264
+ setContent: (contentKey, content) => {
265
+ setContent(this.transactors, contentKey, content);
266
+ },
267
+ deleteContent: (contentKey) => {
268
+ deleteContent(this.transactors, contentKey);
269
+ }
270
+ };
271
+ externalStore = Object.assign(
272
+ baseExternalStoreConfiguration,
273
+ externalStoreWithContentConfiguration
274
+ );
275
+ } else {
276
+ externalStore = baseExternalStoreConfiguration;
277
+ }
278
+ const relations = new Junction(options, {
279
+ externalStore,
280
+ makeContentKey: (...args) => {
281
+ const sorted = args.sort();
282
+ const compositeKey = `${sorted[0]}:${sorted[1]}`;
283
+ const [m0, m1] = sorted.map(
284
+ (key) => this.molecules.get(stringifyJson(key))
285
+ );
286
+ if (store.config.lifespan === `immortal` && m0 && m1) {
287
+ const target = newest(store);
288
+ const moleculeToken = makeMoleculeInStore(
289
+ target,
290
+ [m0, m1],
291
+ contentMolecules,
292
+ compositeKey
293
+ );
294
+ this.molecules.set(
295
+ `"${compositeKey}"`,
296
+ withdraw(moleculeToken, target)
297
+ );
298
+ }
299
+ return compositeKey;
300
+ }
301
+ });
302
+ const createSingleKeyStateFamily = () => createSelectorFamily(
303
+ {
304
+ key: `${options.key}/singleRelatedKey`,
305
+ get: (key) => ({ get }) => {
306
+ const relatedKeysState = this.retrieve(relatedKeysAtoms, key);
307
+ const relatedKeys = get(relatedKeysState);
308
+ for (const relatedKey of relatedKeys) {
309
+ return relatedKey;
310
+ }
311
+ return null;
312
+ }
313
+ },
314
+ store
315
+ );
316
+ const getMultipleKeyStateFamily = () => {
317
+ return createSelectorFamily(
318
+ {
319
+ key: `${options.key}/multipleRelatedKeys`,
320
+ get: (key) => ({ get }) => {
321
+ const jsonFamily = getJsonFamily(relatedKeysAtoms, store);
322
+ const jsonState = this.retrieve(jsonFamily, key);
323
+ const json = get(jsonState);
324
+ return json.members;
325
+ }
326
+ },
327
+ store
328
+ );
329
+ };
330
+ const createSingleEntryStateFamily = () => createSelectorFamily(
331
+ {
332
+ key: `${options.key}/singleRelatedEntry`,
333
+ get: (key) => ({ get }) => {
334
+ const relatedKeysState = this.retrieve(relatedKeysAtoms, key);
335
+ const relatedKeys = get(relatedKeysState);
336
+ for (const relatedKey of relatedKeys) {
337
+ const contentKey = relations.makeContentKey(key, relatedKey);
338
+ const contentState = this.retrieve(contentAtoms, contentKey);
339
+ const content = get(contentState);
340
+ return [relatedKey, content];
341
+ }
342
+ return null;
343
+ }
344
+ },
345
+ store
346
+ );
347
+ const getMultipleEntryStateFamily = () => createSelectorFamily(
348
+ {
349
+ key: `${options.key}/multipleRelatedEntries`,
350
+ get: (key) => ({ get }) => {
351
+ const jsonFamily = getJsonFamily(relatedKeysAtoms, store);
352
+ const jsonState = this.retrieve(jsonFamily, key);
353
+ const json = get(jsonState);
354
+ return json.members.map((relatedKey) => {
355
+ const contentKey = relations.makeContentKey(key, relatedKey);
356
+ const contentState = this.retrieve(contentAtoms, contentKey);
357
+ const content = get(contentState);
358
+ return [relatedKey, content];
359
+ });
360
+ }
361
+ },
362
+ store
363
+ );
364
+ switch (options.cardinality) {
365
+ case `1:1`: {
366
+ const findSingleRelatedKeyState = createSingleKeyStateFamily();
367
+ const stateKeyA = `${aSide}KeyOf${capitalize(bSide)}`;
368
+ const stateKeyB = `${bSide}KeyOf${capitalize(aSide)}`;
369
+ const baseStates = {
370
+ [stateKeyA]: findSingleRelatedKeyState,
371
+ [stateKeyB]: findSingleRelatedKeyState
372
+ };
373
+ let states;
374
+ if (defaultContent) {
375
+ const findSingleRelatedEntryState = createSingleEntryStateFamily();
376
+ const entriesStateKeyA = `${aSide}EntryOf${capitalize(bSide)}`;
377
+ const entriesStateKeyB = `${bSide}EntryOf${capitalize(aSide)}`;
378
+ const contentStates = {
379
+ [entriesStateKeyA]: findSingleRelatedEntryState,
380
+ [entriesStateKeyB]: findSingleRelatedEntryState
381
+ };
382
+ states = Object.assign(baseStates, contentStates);
383
+ } else {
384
+ states = baseStates;
385
+ }
386
+ this.relations = relations;
387
+ this.states = states;
388
+ break;
389
+ }
390
+ case `1:n`: {
391
+ const findSingleRelatedKeyState = createSingleKeyStateFamily();
392
+ const findMultipleRelatedKeysState = getMultipleKeyStateFamily();
393
+ const stateKeyA = `${aSide}KeyOf${capitalize(bSide)}`;
394
+ const stateKeyB = `${bSide}KeysOf${capitalize(aSide)}`;
395
+ const baseStates = {
396
+ [stateKeyA]: findSingleRelatedKeyState,
397
+ [stateKeyB]: findMultipleRelatedKeysState
398
+ };
399
+ let states;
400
+ if (defaultContent) {
401
+ const findSingleRelatedEntryState = createSingleEntryStateFamily();
402
+ const findMultipleRelatedEntriesState = getMultipleEntryStateFamily();
403
+ const entriesStateKeyA = `${aSide}EntryOf${capitalize(bSide)}`;
404
+ const entriesStateKeyB = `${bSide}EntriesOf${capitalize(
405
+ aSide
406
+ )}`;
407
+ const contentStates = {
408
+ [entriesStateKeyA]: findSingleRelatedEntryState,
409
+ [entriesStateKeyB]: findMultipleRelatedEntriesState
410
+ };
411
+ states = Object.assign(baseStates, contentStates);
412
+ } else {
413
+ states = baseStates;
414
+ }
415
+ this.relations = relations;
416
+ this.states = states;
417
+ break;
418
+ }
419
+ default: {
420
+ const findMultipleRelatedKeysState = getMultipleKeyStateFamily();
421
+ const stateKeyA = `${aSide}KeysOf${capitalize(bSide)}`;
422
+ const stateKeyB = `${bSide}KeysOf${capitalize(aSide)}`;
423
+ const baseStates = {
424
+ [stateKeyA]: findMultipleRelatedKeysState,
425
+ [stateKeyB]: findMultipleRelatedKeysState
426
+ };
427
+ let states;
428
+ if (defaultContent) {
429
+ const findMultipleRelatedEntriesState = getMultipleEntryStateFamily();
430
+ const entriesStateKeyA = `${aSide}EntriesOf${capitalize(
431
+ bSide
432
+ )}`;
433
+ const entriesStateKeyB = `${bSide}EntriesOf${capitalize(
434
+ aSide
435
+ )}`;
436
+ const contentStates = {
437
+ [entriesStateKeyA]: findMultipleRelatedEntriesState,
438
+ [entriesStateKeyB]: findMultipleRelatedEntriesState
439
+ };
440
+ states = Object.assign(baseStates, contentStates);
441
+ } else {
442
+ states = baseStates;
443
+ }
444
+ this.relations = relations;
445
+ this.states = states;
446
+ }
447
+ }
448
+ }
449
+ transact(transactors, run) {
450
+ const originalTransactors = this.transactors;
451
+ this.transactors = transactors;
452
+ run(this);
453
+ this.transactors = originalTransactors;
454
+ }
455
+ [Symbol.dispose]() {
456
+ this.alternates.delete(this.store.config.name);
457
+ }
458
+ in(store) {
459
+ const key = store.config.name;
460
+ const alternate = this.alternates.get(key);
461
+ if (alternate) {
462
+ return alternate;
463
+ }
464
+ const join2 = new _Join(this.options, this.defaultContent, store);
465
+ this.alternates.set(key, join2);
466
+ join2.alternates = this.alternates;
467
+ return join2;
468
+ }
469
+ };
470
+ function join(options, defaultContent, store = IMPLICIT.STORE) {
471
+ const joins = getJoinMap(store);
472
+ joins.set(options.key, new Join(options, defaultContent, store));
473
+ const token = {
474
+ key: options.key,
475
+ type: `join`,
476
+ a: options.between[0],
477
+ b: options.between[1],
478
+ cardinality: options.cardinality
479
+ };
480
+ return token;
481
+ }
482
+ function getJoinMap(store) {
483
+ if (`joins` in store && store.joins instanceof Map) {
484
+ return store.joins;
485
+ }
486
+ const joins = /* @__PURE__ */ new Map();
487
+ store.joins = joins;
488
+ return joins;
489
+ }
490
+ function getJoin(token, store) {
491
+ var _a;
492
+ const joinMap = getJoinMap(store);
493
+ let myJoin = joinMap.get(token.key);
494
+ if (myJoin === void 0) {
495
+ const rootJoinMap = getJoinMap(IMPLICIT.STORE);
496
+ myJoin = (_a = rootJoinMap.get(token.key)) == null ? void 0 : _a.in(store);
497
+ if (myJoin === void 0) {
498
+ throw new Error(
499
+ `Join "${token.key}" not found in store "${store.config.name}"`
500
+ );
501
+ }
502
+ joinMap.set(token.key, myJoin);
503
+ }
504
+ return myJoin;
505
+ }
506
+ function findRelationsInStore(token, key, store) {
507
+ const myJoin = getJoin(token, store);
508
+ let relations;
509
+ switch (token.cardinality) {
510
+ case `1:1`: {
511
+ const keyAB = `${token.a}KeyOf${capitalize(token.b)}`;
512
+ const keyBA = `${token.b}KeyOf${capitalize(token.a)}`;
513
+ relations = {
514
+ get [keyAB]() {
515
+ const familyAB = myJoin.states[keyAB];
516
+ const state = myJoin.retrieve(familyAB, key);
517
+ return state;
518
+ },
519
+ get [keyBA]() {
520
+ const familyBA = myJoin.states[keyBA];
521
+ const state = myJoin.retrieve(familyBA, key);
522
+ return state;
523
+ }
524
+ };
525
+ const entryAB = `${token.a}EntryOf${capitalize(token.b)}`;
526
+ if (entryAB in myJoin.states) {
527
+ const entryBA = `${token.b}EntryOf${capitalize(token.a)}`;
528
+ Object.assign(relations, {
529
+ get [entryAB]() {
530
+ const familyAB = myJoin.states[entryAB];
531
+ const state = myJoin.retrieve(familyAB, key);
532
+ return state;
533
+ },
534
+ get [entryBA]() {
535
+ const familyBA = myJoin.states[entryBA];
536
+ const state = myJoin.retrieve(familyBA, key);
537
+ return state;
538
+ }
539
+ });
540
+ }
541
+ break;
542
+ }
543
+ case `1:n`: {
544
+ const keyAB = `${token.a}KeyOf${capitalize(token.b)}`;
545
+ const keysBA = `${token.b}KeysOf${capitalize(token.a)}`;
546
+ relations = {
547
+ get [keyAB]() {
548
+ const familyAB = myJoin.states[keyAB];
549
+ const state = myJoin.retrieve(familyAB, key);
550
+ return state;
551
+ },
552
+ get [keysBA]() {
553
+ const familyBA = myJoin.states[keysBA];
554
+ const state = myJoin.retrieve(familyBA, key);
555
+ return state;
556
+ }
557
+ };
558
+ const entryAB = `${token.a}EntryOf${capitalize(token.b)}`;
559
+ if (entryAB in myJoin.states) {
560
+ const entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`;
561
+ Object.assign(relations, {
562
+ get [entryAB]() {
563
+ const familyAB = myJoin.states[entryAB];
564
+ const state = myJoin.retrieve(familyAB, key);
565
+ return state;
566
+ },
567
+ get [entriesBA]() {
568
+ const familyBA = myJoin.states[entriesBA];
569
+ const state = myJoin.retrieve(familyBA, key);
570
+ return state;
571
+ }
572
+ });
573
+ }
574
+ break;
575
+ }
576
+ case `n:n`: {
577
+ const keysAB = `${token.a}KeysOf${capitalize(token.b)}`;
578
+ const keysBA = `${token.b}KeysOf${capitalize(token.a)}`;
579
+ relations = {
580
+ get [keysAB]() {
581
+ const familyAB = myJoin.states[keysAB];
582
+ const state = myJoin.retrieve(familyAB, key);
583
+ return state;
584
+ },
585
+ get [keysBA]() {
586
+ const familyBA = myJoin.states[keysBA];
587
+ const state = myJoin.retrieve(familyBA, key);
588
+ return state;
589
+ }
590
+ };
591
+ const entriesAB = `${token.a}EntriesOf${capitalize(token.b)}`;
592
+ if (entriesAB in myJoin.states) {
593
+ const entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`;
594
+ Object.assign(relations, {
595
+ get [entriesAB]() {
596
+ const familyAB = myJoin.states[entriesAB];
597
+ const state = myJoin.retrieve(familyAB, key);
598
+ return state;
599
+ },
600
+ get [entriesBA]() {
601
+ const familyBA = myJoin.states[entriesBA];
602
+ const state = myJoin.retrieve(familyBA, key);
603
+ return state;
604
+ }
605
+ });
606
+ }
607
+ }
608
+ }
609
+ return relations;
610
+ }
611
+ function findRelations(token, key) {
612
+ return findRelationsInStore(token, key, IMPLICIT.STORE);
613
+ }
614
+ function editRelationsInStore(token, change, store) {
615
+ const myJoin = getJoin(token, store);
616
+ const target = newest(store);
617
+ if (isChildStore(target)) {
618
+ const { transactors } = target.transactionMeta;
619
+ myJoin.transact(transactors, ({ relations }) => {
620
+ change(relations);
621
+ });
622
+ } else {
623
+ change(myJoin.relations);
624
+ }
625
+ }
626
+ function editRelations(token, change) {
627
+ editRelationsInStore(token, change, IMPLICIT.STORE);
628
+ }
629
+ function getInternalRelationsFromStore(token, store) {
630
+ const myJoin = getJoin(token, store);
631
+ const family = myJoin.core.findRelatedKeysState;
632
+ return family;
633
+ }
634
+ function getInternalRelations(token) {
635
+ return getInternalRelationsFromStore(token, IMPLICIT.STORE);
636
+ }
637
+ var capitalize2 = (str) => str[0].toUpperCase() + str.slice(1);
22
638
  function struct(options, store = IMPLICIT.STORE) {
23
639
  const atoms = Object.keys(options.default).reduce((acc, key) => {
24
- const atomName = options.key + capitalize(key) + `State`;
640
+ const atomName = options.key + capitalize2(key) + `State`;
25
641
  acc[atomName] = createRegularAtom(
26
642
  {
27
643
  key: `${options.key}.${key}`,
@@ -37,7 +653,7 @@ function struct(options, store = IMPLICIT.STORE) {
37
653
  key: options.key,
38
654
  get: ({ get }) => {
39
655
  return Object.keys(options.default).reduce((acc, key) => {
40
- acc[key] = get(atoms[options.key + capitalize(key) + `State`]);
656
+ acc[key] = get(atoms[options.key + capitalize2(key) + `State`]);
41
657
  return acc;
42
658
  }, {});
43
659
  }
@@ -46,8 +662,8 @@ function struct(options, store = IMPLICIT.STORE) {
46
662
  );
47
663
  return [atoms, structState];
48
664
  }
49
- var capitalize2 = (str) => str[0].toUpperCase() + str.slice(1);
50
- var nameFamily = (topKey, subKey) => `find` + capitalize2(topKey) + capitalize2(subKey) + `State`;
665
+ var capitalize3 = (str) => str[0].toUpperCase() + str.slice(1);
666
+ var nameFamily = (topKey, subKey) => `find` + capitalize3(topKey) + capitalize3(subKey) + `State`;
51
667
  function structFamily(options) {
52
668
  const atoms = Object.keys(options.default).reduce((acc, subKey) => {
53
669
  const atomFamilyName = nameFamily(options.key, subKey);
@@ -85,4 +701,4 @@ function until(loadable, fallback) {
85
701
  return loadable;
86
702
  }
87
703
 
88
- export { dict, struct, structFamily, until };
704
+ export { Join, dict, editRelations, editRelationsInStore, findRelations, findRelationsInStore, getInternalRelations, getInternalRelationsFromStore, getJoin, getJoinMap, join, struct, structFamily, until };