atom.io 0.14.7 → 0.15.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 (81) hide show
  1. package/README.md +5 -0
  2. package/data/dist/index.cjs +200 -218
  3. package/data/dist/index.cjs.map +1 -1
  4. package/data/dist/index.d.ts +16 -7
  5. package/data/dist/index.js +202 -221
  6. package/data/dist/index.js.map +1 -1
  7. package/data/src/join.ts +295 -292
  8. package/data/src/struct-family.ts +2 -2
  9. package/data/src/struct.ts +2 -2
  10. package/dist/chunk-S7R5MU6A.js +137 -0
  11. package/dist/chunk-S7R5MU6A.js.map +1 -0
  12. package/dist/index.cjs +3 -20
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.ts +15 -8
  15. package/dist/index.js +1 -151
  16. package/dist/index.js.map +1 -1
  17. package/internal/dist/index.cjs +275 -200
  18. package/internal/dist/index.cjs.map +1 -1
  19. package/internal/dist/index.d.ts +43 -36
  20. package/internal/dist/index.js +221 -193
  21. package/internal/dist/index.js.map +1 -1
  22. package/internal/src/atom/create-atom.ts +5 -86
  23. package/internal/src/atom/create-regular-atom.ts +92 -0
  24. package/internal/src/atom/index.ts +16 -0
  25. package/internal/src/atom/is-default.ts +0 -5
  26. package/internal/src/caching.ts +14 -16
  27. package/internal/src/families/create-atom-family.ts +20 -46
  28. package/internal/src/families/create-readonly-selector-family.ts +1 -0
  29. package/internal/src/families/create-regular-atom-family.ts +72 -0
  30. package/internal/src/families/create-selector-family.ts +2 -0
  31. package/internal/src/families/index.ts +1 -0
  32. package/internal/src/mutable/create-mutable-atom-family.ts +2 -2
  33. package/internal/src/mutable/create-mutable-atom.ts +8 -3
  34. package/internal/src/mutable/get-update-family.ts +1 -1
  35. package/internal/src/mutable/is-mutable.ts +3 -30
  36. package/internal/src/mutable/tracker-family.ts +2 -2
  37. package/internal/src/mutable/tracker.ts +5 -5
  38. package/internal/src/operation.ts +14 -18
  39. package/internal/src/selector/create-read-write-selector.ts +2 -3
  40. package/internal/src/selector/create-selector.ts +1 -1
  41. package/internal/src/selector/register-selector.ts +9 -14
  42. package/internal/src/set-state/evict-downstream.ts +3 -5
  43. package/internal/src/set-state/set-atom.ts +14 -17
  44. package/internal/src/store/store.ts +23 -19
  45. package/internal/src/store/withdraw.ts +32 -70
  46. package/internal/src/subscribe/subscribe-to-root-atoms.ts +5 -3
  47. package/internal/src/subscribe/subscribe-to-state.ts +5 -3
  48. package/internal/src/transaction/apply-transaction.ts +20 -2
  49. package/internal/src/transaction/build-transaction.ts +19 -11
  50. package/internal/src/transaction/create-transaction.ts +6 -11
  51. package/internal/src/transaction/index.ts +2 -3
  52. package/introspection/dist/index.cjs +6 -6
  53. package/introspection/dist/index.cjs.map +1 -1
  54. package/introspection/dist/index.d.ts +3 -3
  55. package/introspection/dist/index.js +7 -7
  56. package/introspection/dist/index.js.map +1 -1
  57. package/introspection/src/attach-atom-index.ts +7 -2
  58. package/introspection/src/attach-selector-index.ts +7 -2
  59. package/introspection/src/attach-timeline-family.ts +5 -2
  60. package/introspection/src/attach-timeline-index.ts +2 -2
  61. package/introspection/src/attach-transaction-index.ts +2 -2
  62. package/introspection/src/attach-transaction-logs.ts +2 -2
  63. package/package.json +10 -8
  64. package/react/dist/index.cjs +9 -12
  65. package/react/dist/index.cjs.map +1 -1
  66. package/react/dist/index.js +9 -12
  67. package/react/dist/index.js.map +1 -1
  68. package/react/src/store-hooks.ts +10 -12
  69. package/react-devtools/dist/index.d.ts +17 -11
  70. package/src/atom.ts +8 -17
  71. package/src/selector.ts +3 -1
  72. package/src/set-state.ts +1 -3
  73. package/src/silo.ts +2 -14
  74. package/src/transaction.ts +17 -6
  75. package/transceivers/set-rtx/dist/index.cjs +2 -1
  76. package/transceivers/set-rtx/dist/index.cjs.map +1 -1
  77. package/transceivers/set-rtx/dist/index.js +2 -1
  78. package/transceivers/set-rtx/dist/index.js.map +1 -1
  79. package/transceivers/set-rtx/src/set-rtx.ts +2 -1
  80. package/internal/src/transaction/redo-transaction.ts +0 -27
  81. package/internal/src/transaction/undo-transaction.ts +0 -27
@@ -1,7 +1,7 @@
1
1
  import { Junction } from '../../dist/chunk-NYTGCPHB.js';
2
2
  import '../../dist/chunk-PZLG2HP3.js';
3
- import { createSelector, IMPLICIT, createMutableAtomFamily, createAtomFamily, createAtom, createSelectorFamily, getJsonFamily } from 'atom.io/internal';
4
- import { getState, setState } from 'atom.io';
3
+ import { createSelector, IMPLICIT, createMutableAtomFamily, createRegularAtomFamily, createRegularAtom, createSelectorFamily, getJsonFamily } from 'atom.io/internal';
4
+ import { getState, setState, dispose } from 'atom.io';
5
5
  import { SetRTX } from 'atom.io/transceivers/set-rtx';
6
6
 
7
7
  function dict(findState, index, store = IMPLICIT.STORE) {
@@ -24,263 +24,244 @@ var TRANSACTORS = { get: getState, set: setState };
24
24
  function capitalize(string) {
25
25
  return string[0].toUpperCase() + string.slice(1);
26
26
  }
27
- function join(options, defaultContent, store = IMPLICIT.STORE) {
28
- const a = options.between[0];
29
- const b = options.between[1];
30
- const findRelatedKeysState = createMutableAtomFamily(
31
- {
32
- key: `${options.key}/relatedKeys`,
33
- default: () => new SetRTX(),
34
- mutable: true,
35
- fromJson: (json) => new SetRTX(json),
36
- toJson: (set) => [...set]
37
- },
38
- store
39
- );
40
- const getRelatedKeys = ({ get }, key) => get(findRelatedKeysState(key));
41
- const addRelation = (transactors, a2, b2) => {
42
- const aKeys = getRelatedKeys(transactors, a2);
43
- const bKeys = getRelatedKeys(transactors, b2);
44
- if (aKeys) {
27
+ var Join = class {
28
+ constructor(options, defaultContent, store = IMPLICIT.STORE) {
29
+ this.transactors = TRANSACTORS;
30
+ const a = options.between[0];
31
+ const b = options.between[1];
32
+ const findRelatedKeysState = createMutableAtomFamily(
33
+ {
34
+ key: `${options.key}/relatedKeys`,
35
+ default: () => new SetRTX(),
36
+ mutable: true,
37
+ fromJson: (json) => new SetRTX(json),
38
+ toJson: (set) => [...set]
39
+ },
40
+ store
41
+ );
42
+ const getRelatedKeys = ({ get }, key) => get(findRelatedKeysState(key));
43
+ const addRelation = (transactors, a2, b2) => {
44
+ const aKeys = getRelatedKeys(transactors, a2);
45
+ const bKeys = getRelatedKeys(transactors, b2);
45
46
  transactors.set(findRelatedKeysState(a2), aKeys.add(b2));
46
- } else {
47
- transactors.set(findRelatedKeysState(a2), new SetRTX([b2]));
48
- }
49
- if (bKeys) {
50
47
  transactors.set(findRelatedKeysState(b2), bKeys.add(a2));
51
- } else {
52
- transactors.set(findRelatedKeysState(b2), new SetRTX([a2]));
53
- }
54
- };
55
- const deleteRelation = (transactors, a2, b2) => {
56
- const aKeys = getRelatedKeys(transactors, a2);
57
- if (aKeys) {
48
+ };
49
+ const deleteRelation = (transactors, a2, b2) => {
50
+ const aKeys = getRelatedKeys(transactors, a2);
58
51
  aKeys.delete(b2);
59
52
  if (aKeys.size === 0) {
60
- transactors.set(findRelatedKeysState(a2), void 0);
53
+ dispose(findRelatedKeysState(a2));
61
54
  }
62
55
  const bKeys = getRelatedKeys(transactors, b2);
63
- if (bKeys) {
64
- bKeys.delete(a2);
65
- if (bKeys.size === 0) {
66
- transactors.set(findRelatedKeysState(b2), void 0);
67
- }
56
+ bKeys.delete(a2);
57
+ if (bKeys.size === 0) {
58
+ dispose(findRelatedKeysState(b2));
68
59
  }
69
- }
70
- };
71
- const replaceRelationsSafely = (transactors, a2, bs) => {
72
- const aRelations = getRelatedKeys(transactors, a2);
73
- if (aRelations) {
60
+ };
61
+ const replaceRelationsSafely = (transactors, a2, bs) => {
62
+ const aRelations = getRelatedKeys(transactors, a2);
74
63
  for (const b2 of aRelations) {
75
64
  const bKeys = getRelatedKeys(transactors, b2);
76
65
  if (bKeys) {
77
66
  bKeys.delete(a2);
78
67
  if (bKeys.size === 0) {
79
- transactors.set(findRelatedKeysState(b2), void 0);
68
+ dispose(findRelatedKeysState(b2));
80
69
  }
81
70
  }
82
71
  }
83
- }
84
- transactors.set(findRelatedKeysState(a2), new SetRTX(bs));
85
- for (const b2 of bs) {
86
- const bKeys = getRelatedKeys(transactors, b2);
87
- if (bKeys) {
72
+ transactors.set(findRelatedKeysState(a2), new SetRTX(bs));
73
+ for (const b2 of bs) {
74
+ const bKeys = getRelatedKeys(transactors, b2);
88
75
  bKeys.add(a2);
89
- } else {
90
- transactors.set(findRelatedKeysState(b2), new SetRTX([a2]));
91
76
  }
92
- }
93
- };
94
- const replaceRelationsUnsafely = (transactors, a2, bs) => {
95
- transactors.set(findRelatedKeysState(a2), new SetRTX(bs));
96
- for (const b2 of bs) {
97
- let bKeys = getRelatedKeys(transactors, b2);
98
- if (bKeys) {
77
+ };
78
+ const replaceRelationsUnsafely = (transactors, a2, bs) => {
79
+ transactors.set(findRelatedKeysState(a2), new SetRTX(bs));
80
+ for (const b2 of bs) {
81
+ const bKeys = getRelatedKeys(transactors, b2);
99
82
  bKeys.add(a2);
100
- } else {
101
- bKeys = new SetRTX([a2]);
102
- transactors.set(findRelatedKeysState(b2), bKeys);
103
83
  }
84
+ };
85
+ const has = (transactors, a2, b2) => {
86
+ const aKeys = getRelatedKeys(transactors, a2);
87
+ return b2 ? aKeys.has(b2) : aKeys.size > 0;
88
+ };
89
+ const baseExternalStoreConfiguration = {
90
+ getRelatedKeys: (key) => getRelatedKeys(this.transactors, key),
91
+ addRelation: (a2, b2) => addRelation(this.transactors, a2, b2),
92
+ deleteRelation: (a2, b2) => deleteRelation(this.transactors, a2, b2),
93
+ replaceRelationsSafely: (a2, bs) => replaceRelationsSafely(this.transactors, a2, bs),
94
+ replaceRelationsUnsafely: (a2, bs) => replaceRelationsUnsafely(this.transactors, a2, bs),
95
+ has: (a2, b2) => has(this.transactors, a2, b2)
96
+ };
97
+ let externalStore;
98
+ let findContentState;
99
+ if (defaultContent) {
100
+ findContentState = createRegularAtomFamily(
101
+ {
102
+ key: `${options.key}/content`,
103
+ default: defaultContent
104
+ },
105
+ store
106
+ );
107
+ const getContent = ({ get }, key) => get(findContentState(key));
108
+ const setContent = (transactors, key, content) => transactors.set(findContentState(key), content);
109
+ const deleteContent = (_, key) => dispose(findContentState(key));
110
+ const externalStoreWithContentConfiguration = {
111
+ getContent: (contentKey) => {
112
+ const content = getContent(this.transactors, contentKey);
113
+ return content;
114
+ },
115
+ setContent: (contentKey, content) => {
116
+ setContent(this.transactors, contentKey, content);
117
+ },
118
+ deleteContent: (contentKey) => {
119
+ deleteContent(this.transactors, contentKey);
120
+ }
121
+ };
122
+ externalStore = Object.assign(
123
+ baseExternalStoreConfiguration,
124
+ externalStoreWithContentConfiguration
125
+ );
126
+ } else {
127
+ externalStore = baseExternalStoreConfiguration;
104
128
  }
105
- };
106
- const has = (transactors, a2, b2) => {
107
- var _a, _b;
108
- const aKeys = getRelatedKeys(transactors, a2);
109
- return b2 ? (_a = aKeys == null ? void 0 : aKeys.has(b2)) != null ? _a : false : ((_b = aKeys == null ? void 0 : aKeys.size) != null ? _b : 0) > 0;
110
- };
111
- const baseExternalStoreConfiguration = {
112
- getRelatedKeys: (key) => getRelatedKeys(TRANSACTORS, key),
113
- addRelation: (a2, b2) => addRelation(TRANSACTORS, a2, b2),
114
- deleteRelation: (a2, b2) => deleteRelation(TRANSACTORS, a2, b2),
115
- replaceRelationsSafely: (a2, bs) => replaceRelationsSafely(TRANSACTORS, a2, bs),
116
- replaceRelationsUnsafely: (a2, bs) => replaceRelationsUnsafely(TRANSACTORS, a2, bs),
117
- has: (a2, b2) => has(TRANSACTORS, a2, b2)
118
- };
119
- let externalStore;
120
- let findContentState;
121
- if (defaultContent) {
122
- findContentState = createAtomFamily(
129
+ const relations = new Junction(options, {
130
+ externalStore,
131
+ makeContentKey: (...args) => args.sort().join(`:`)
132
+ });
133
+ const createSingleKeyStateFamily = () => createSelectorFamily(
123
134
  {
124
- key: `${options.key}/content`,
125
- default: defaultContent
135
+ key: `${options.key}/singleRelatedKey`,
136
+ get: (key) => ({ get }) => {
137
+ const relatedKeys = get(findRelatedKeysState(key));
138
+ for (const relatedKey of relatedKeys) {
139
+ return relatedKey;
140
+ }
141
+ }
126
142
  },
127
143
  store
128
144
  );
129
- const getContent = ({ get }, key) => get(findContentState(key));
130
- const setContent = (transactors, key, content) => transactors.set(findContentState(key), content);
131
- const deleteContent = (transactors, key) => transactors.set(findContentState(key), void 0);
132
- const externalStoreWithContentConfiguration = {
133
- getContent: (contentKey) => {
134
- const content = getContent(TRANSACTORS, contentKey);
135
- return content;
136
- },
137
- setContent: (contentKey, content) => {
138
- setContent(TRANSACTORS, contentKey, content);
145
+ const getMultipleKeyStateFamily = () => getJsonFamily(findRelatedKeysState, store);
146
+ const createSingleEntryStateFamily = () => createSelectorFamily(
147
+ {
148
+ key: `${options.key}/singleRelatedEntry`,
149
+ get: (key) => ({ get }) => {
150
+ const relatedKeys = get(findRelatedKeysState(key));
151
+ for (const relatedKey of relatedKeys) {
152
+ const contentKey = relations.makeContentKey(key, relatedKey);
153
+ return [relatedKey, get(findContentState(contentKey))];
154
+ }
155
+ }
139
156
  },
140
- deleteContent: (contentKey) => {
141
- deleteContent(TRANSACTORS, contentKey);
142
- }
143
- };
144
- externalStore = Object.assign(
145
- baseExternalStoreConfiguration,
146
- externalStoreWithContentConfiguration
157
+ store
147
158
  );
148
- } else {
149
- externalStore = baseExternalStoreConfiguration;
150
- }
151
- const relations = new Junction(options, {
152
- externalStore,
153
- makeContentKey: (...args) => args.sort().join(`:`)
154
- });
155
- const createSingleKeyStateFamily = () => createSelectorFamily(
156
- {
157
- key: `${options.key}/singleRelatedKey`,
158
- get: (key) => ({ get }) => {
159
- const relatedKeys = get(findRelatedKeysState(key));
160
- for (const relatedKey of relatedKeys) {
161
- return relatedKey;
162
- }
163
- }
164
- },
165
- store
166
- );
167
- const getMultipleKeyStateFamily = () => getJsonFamily(findRelatedKeysState, store);
168
- const createSingleEntryStateFamily = () => createSelectorFamily(
169
- {
170
- key: `${options.key}/singleRelatedEntry`,
171
- get: (key) => ({ get }) => {
172
- const relatedKeys = get(findRelatedKeysState(key));
173
- for (const relatedKey of relatedKeys) {
174
- const contentKey = relations.makeContentKey(key, relatedKey);
175
- return [relatedKey, get(findContentState(contentKey))];
159
+ const getMultipleEntryStateFamily = () => createSelectorFamily(
160
+ {
161
+ key: `${options.key}/multipleRelatedEntries`,
162
+ get: (key) => ({ get }) => {
163
+ const relatedKeys = get(findRelatedKeysState(key));
164
+ return [...relatedKeys].map((relatedKey) => {
165
+ const contentKey = relations.makeContentKey(key, relatedKey);
166
+ return [relatedKey, get(findContentState(contentKey))];
167
+ });
176
168
  }
177
- }
178
- },
179
- store
180
- );
181
- const getMultipleEntryStateFamily = () => createSelectorFamily(
182
- {
183
- key: `${options.key}/multipleRelatedEntries`,
184
- get: (key) => ({ get }) => {
185
- const relatedKeys = get(findRelatedKeysState(key));
186
- return [...relatedKeys].map((relatedKey) => {
187
- const contentKey = relations.makeContentKey(key, relatedKey);
188
- return [relatedKey, get(findContentState(contentKey))];
189
- });
190
- }
191
- },
192
- store
193
- );
194
- switch (options.cardinality) {
195
- case `1:1`: {
196
- const findSingleRelatedKeyState = createSingleKeyStateFamily();
197
- const stateKeyA = `${a}KeyOf${capitalize(b)}`;
198
- const stateKeyB = `${b}KeyOf${capitalize(a)}`;
199
- const findStateBase = {
200
- [stateKeyA]: findSingleRelatedKeyState,
201
- [stateKeyB]: findSingleRelatedKeyState
202
- };
203
- let findState;
204
- if (defaultContent) {
205
- const findSingleRelatedEntryState = createSingleEntryStateFamily();
206
- const entriesStateKeyA = `${a}EntryOf${capitalize(b)}`;
207
- const entriesStateKeyB = `${b}EntryOf${capitalize(a)}`;
208
- const findStateWithContent = {
209
- [entriesStateKeyA]: findSingleRelatedEntryState,
210
- [entriesStateKeyB]: findSingleRelatedEntryState
169
+ },
170
+ store
171
+ );
172
+ switch (options.cardinality) {
173
+ case `1:1`: {
174
+ const findSingleRelatedKeyState = createSingleKeyStateFamily();
175
+ const stateKeyA = `${a}KeyOf${capitalize(b)}`;
176
+ const stateKeyB = `${b}KeyOf${capitalize(a)}`;
177
+ const findStateBase = {
178
+ [stateKeyA]: findSingleRelatedKeyState,
179
+ [stateKeyB]: findSingleRelatedKeyState
211
180
  };
212
- findState = Object.assign(findStateBase, findStateWithContent);
213
- } else {
214
- findState = findStateBase;
181
+ let findState;
182
+ if (defaultContent) {
183
+ const findSingleRelatedEntryState = createSingleEntryStateFamily();
184
+ const entriesStateKeyA = `${a}EntryOf${capitalize(b)}`;
185
+ const entriesStateKeyB = `${b}EntryOf${capitalize(a)}`;
186
+ const findStateWithContent = {
187
+ [entriesStateKeyA]: findSingleRelatedEntryState,
188
+ [entriesStateKeyB]: findSingleRelatedEntryState
189
+ };
190
+ findState = Object.assign(findStateBase, findStateWithContent);
191
+ } else {
192
+ findState = findStateBase;
193
+ }
194
+ this.relations = relations;
195
+ this.findState = findState;
196
+ break;
215
197
  }
216
- return {
217
- relations,
218
- findState
219
- };
220
- }
221
- case `1:n`: {
222
- const findSingleRelatedKeyState = createSingleKeyStateFamily();
223
- const findMultipleRelatedKeysState = getMultipleKeyStateFamily();
224
- const stateKeyA = `${a}KeyOf${capitalize(b)}`;
225
- const stateKeyB = `${b}KeysOf${capitalize(a)}`;
226
- const findStateBase = {
227
- [stateKeyA]: findSingleRelatedKeyState,
228
- [stateKeyB]: findMultipleRelatedKeysState
229
- };
230
- let findState;
231
- if (defaultContent) {
232
- const findSingleRelatedEntryState = createSingleEntryStateFamily();
233
- const findMultipleRelatedEntriesState = getMultipleEntryStateFamily();
234
- const entriesStateKeyA = `${a}EntryOf${capitalize(b)}`;
235
- const entriesStateKeyB = `${b}EntriesOf${capitalize(a)}`;
236
- const findStateWithContent = {
237
- [entriesStateKeyA]: findSingleRelatedEntryState,
238
- [entriesStateKeyB]: findMultipleRelatedEntriesState
198
+ case `1:n`: {
199
+ const findSingleRelatedKeyState = createSingleKeyStateFamily();
200
+ const findMultipleRelatedKeysState = getMultipleKeyStateFamily();
201
+ const stateKeyA = `${a}KeyOf${capitalize(b)}`;
202
+ const stateKeyB = `${b}KeysOf${capitalize(a)}`;
203
+ const findStateBase = {
204
+ [stateKeyA]: findSingleRelatedKeyState,
205
+ [stateKeyB]: findMultipleRelatedKeysState
239
206
  };
240
- findState = Object.assign(findStateBase, findStateWithContent);
241
- } else {
242
- findState = findStateBase;
207
+ let findState;
208
+ if (defaultContent) {
209
+ const findSingleRelatedEntryState = createSingleEntryStateFamily();
210
+ const findMultipleRelatedEntriesState = getMultipleEntryStateFamily();
211
+ const entriesStateKeyA = `${a}EntryOf${capitalize(b)}`;
212
+ const entriesStateKeyB = `${b}EntriesOf${capitalize(a)}`;
213
+ const findStateWithContent = {
214
+ [entriesStateKeyA]: findSingleRelatedEntryState,
215
+ [entriesStateKeyB]: findMultipleRelatedEntriesState
216
+ };
217
+ findState = Object.assign(findStateBase, findStateWithContent);
218
+ } else {
219
+ findState = findStateBase;
220
+ }
221
+ this.relations = relations;
222
+ this.findState = findState;
223
+ break;
243
224
  }
244
- return {
245
- relations,
246
- findState
247
- };
248
- }
249
- case `n:n`: {
250
- const findMultipleRelatedKeysState = getMultipleKeyStateFamily();
251
- const stateKeyA = `${a}KeysOf${capitalize(b)}`;
252
- const stateKeyB = `${b}KeysOf${capitalize(a)}`;
253
- const findStateBase = {
254
- [stateKeyA]: findMultipleRelatedKeysState,
255
- [stateKeyB]: findMultipleRelatedKeysState
256
- };
257
- let findState;
258
- if (defaultContent) {
259
- const findMultipleRelatedEntriesState = getMultipleEntryStateFamily();
260
- const entriesStateKeyA = `${a}EntriesOf${capitalize(b)}`;
261
- const entriesStateKeyB = `${b}EntriesOf${capitalize(a)}`;
262
- const findStateWithContent = {
263
- [entriesStateKeyA]: findMultipleRelatedEntriesState,
264
- [entriesStateKeyB]: findMultipleRelatedEntriesState
225
+ default: {
226
+ const findMultipleRelatedKeysState = getMultipleKeyStateFamily();
227
+ const stateKeyA = `${a}KeysOf${capitalize(b)}`;
228
+ const stateKeyB = `${b}KeysOf${capitalize(a)}`;
229
+ const findStateBase = {
230
+ [stateKeyA]: findMultipleRelatedKeysState,
231
+ [stateKeyB]: findMultipleRelatedKeysState
265
232
  };
266
- findState = Object.assign(findStateBase, findStateWithContent);
267
- } else {
268
- findState = findStateBase;
233
+ let findState;
234
+ if (defaultContent) {
235
+ const findMultipleRelatedEntriesState = getMultipleEntryStateFamily();
236
+ const entriesStateKeyA = `${a}EntriesOf${capitalize(b)}`;
237
+ const entriesStateKeyB = `${b}EntriesOf${capitalize(a)}`;
238
+ const findStateWithContent = {
239
+ [entriesStateKeyA]: findMultipleRelatedEntriesState,
240
+ [entriesStateKeyB]: findMultipleRelatedEntriesState
241
+ };
242
+ findState = Object.assign(findStateBase, findStateWithContent);
243
+ } else {
244
+ findState = findStateBase;
245
+ }
246
+ this.relations = relations;
247
+ this.findState = findState;
269
248
  }
270
- return {
271
- relations,
272
- findState
273
- };
274
249
  }
275
- default:
276
- throw new Error(`Invalid cardinality: ${options.cardinality}`);
277
250
  }
251
+ transact(transactors, run) {
252
+ this.transactors = transactors;
253
+ run(this);
254
+ this.transactors = TRANSACTORS;
255
+ }
256
+ };
257
+ function join(options, defaultContent, store = IMPLICIT.STORE) {
258
+ return new Join(options, defaultContent, store);
278
259
  }
279
260
  var capitalize2 = (str) => str[0].toUpperCase() + str.slice(1);
280
261
  function struct(options, store = IMPLICIT.STORE) {
281
262
  const atoms = Object.keys(options.default).reduce((acc, key) => {
282
263
  const atomName = options.key + capitalize2(key) + `State`;
283
- acc[atomName] = createAtom(
264
+ acc[atomName] = createRegularAtom(
284
265
  {
285
266
  key: `${options.key}.${key}`,
286
267
  default: options.default[key]
@@ -310,7 +291,7 @@ var nameFamily = (topKey, subKey) => `find` + capitalize3(topKey) + capitalize3(
310
291
  function structFamily(options) {
311
292
  const atoms = Object.keys(options.default).reduce((acc, subKey) => {
312
293
  const atomFamilyName = nameFamily(options.key, subKey);
313
- acc[atomFamilyName] = createAtomFamily(
294
+ acc[atomFamilyName] = createRegularAtomFamily(
314
295
  {
315
296
  key: `${options.key}.${subKey}`,
316
297
  default: options.default[subKey]
@@ -344,6 +325,6 @@ function until(loadable, fallback) {
344
325
  return loadable;
345
326
  }
346
327
 
347
- export { dict, join, struct, structFamily, until };
328
+ export { Join, dict, join, struct, structFamily, until };
348
329
  //# sourceMappingURL=out.js.map
349
330
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/dict.ts","../src/join.ts","../src/struct.ts","../src/struct-family.ts","../src/until.ts"],"names":["IMPLICIT","a","b","createSelector","capitalize","createAtomFamily","createSelectorFamily"],"mappings":";;;;;;AAEA,SAAS,UAAU,sBAAsB;AAGlC,SAAS,KACf,WAIA,OAIA,QAAe,SAAS,OAC2C;AACnE,SAAO;AAAA,IACN;AAAA,MACC,KAAK,GAAG,UAAU,GAAG;AAAA,MACrB,KAAK,CAAC,EAAE,IAAI,MAAM;AACjB,cAAM,OAAO,IAAI,KAAK;AACtB,eAAO,KAAK,OAAO,CAAC,KAAK,QAAQ;AAChC,cAAI,GAAG,IAAI,IAAI,UAAU,GAAG,CAAC;AAC7B,iBAAO;AAAA,QACR,GAAG,CAAC,CAAQ;AAAA,MACb;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;;;ACtBA,SAAS,UAAU,gBAAgB;AAEnC;AAAA,EACC,YAAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAEP,SAAS,cAAc;AAYvB,IAAM,cAA2B,EAAE,KAAK,UAAU,KAAK,SAAS;AAEhE,SAAS,WAA6B,QAA0B;AAC/D,SAAQ,OAAO,CAAC,EAAE,YAAY,IAAI,OAAO,MAAM,CAAC;AACjD;AA0GO,SAAS,KAMf,SACA,gBACA,QAAeA,UAAS,OAIvB;AACD,QAAM,IAAW,QAAQ,QAAQ,CAAC;AAClC,QAAM,IAAW,QAAQ,QAAQ,CAAC;AAClC,QAAM,uBAAuB;AAAA,IAK5B;AAAA,MACC,KAAK,GAAG,QAAQ,GAAG;AAAA,MACnB,SAAS,MAAM,IAAI,OAAO;AAAA,MAC1B,SAAS;A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UAAS;AAAA,EACV;AACA,SAAO,CAAC,OAAO,eAAe;AAC/B;;;AChDO,SAAS,MAAS,UAAuB,UAAgB;AAC/D,MAAI,oBAAoB,SAAS;AAChC,WAAO;AAAA,EACR;AACA,SAAO;AACR","sourcesContent":["import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, createSelector } from \"atom.io/internal\"\nimport type { Json, Stringified } from \"atom.io/json\"\n\nexport function dict<State, Key extends Json.Serializable>(\n\tfindState:\n\t\t| AtomIO.AtomFamily<State, Key>\n\t\t| AtomIO.ReadonlySelectorFamily<State, Key>\n\t\t| AtomIO.SelectorFamily<State, Key>,\n\tindex:\n\t\t| AtomIO.AtomToken<Key[]>\n\t\t| AtomIO.ReadonlySelectorToken<Key[]>\n\t\t| AtomIO.SelectorToken<Key[]>,\n\tstore: Store = IMPLICIT.STORE,\n): AtomIO.ReadonlySelectorToken<{ [K in Stringified<Key>]: State }> {\n\treturn createSelector(\n\t\t{\n\t\t\tkey: `${findState.key}Dict`,\n\t\t\tget: ({ get }) => {\n\t\t\t\tconst keys = get(index)\n\t\t\t\treturn keys.reduce((acc, key) => {\n\t\t\t\t\tacc[key] = get(findState(key))\n\t\t\t\t\treturn acc\n\t\t\t\t}, {} as any)\n\t\t\t},\n\t\t},\n\t\tundefined,\n\t\tstore,\n\t)\n}\n","/* eslint-disable @typescript-eslint/ban-types */\nimport type {\n\tAtomFamily,\n\tRead,\n\tSelectorFamily,\n\tTransactors,\n\tWrite,\n} from \"atom.io\"\nimport { getState, setState } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tcreateAtomFamily,\n\tcreateMutableAtomFamily,\n\tcreateSelectorFamily,\n\tgetJsonFamily,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { SetRTX } from \"atom.io/transceivers/set-rtx\"\n\nimport type {\n\tBaseExternalStoreConfiguration,\n\tExternalStoreConfiguration,\n\tExternalStoreWithContentConfiguration,\n\tJunctionEntries,\n\tJunctionSchema,\n} from \"~/packages/rel8/junction/src\"\nimport { Junction } from \"~/packages/rel8/junction/src\"\nimport type * as Rel8 from \"~/packages/rel8/types/src\"\n\nconst TRANSACTORS: Transactors = { get: getState, set: setState }\n\nfunction capitalize<S extends string>(string: S): Capitalize<S> {\n\treturn (string[0].toUpperCase() + string.slice(1)) as Capitalize<S>\n}\n\nexport interface JoinOptions<\n\tASide extends string,\n\tBSide extends string,\n\tCardinality extends Rel8.Cardinality,\n\tContent extends Json.Object | null,\n> extends Json.Object,\n\t\tJunctionSchema<ASide, BSide>,\n\t\tPartial<JunctionEntries<Content>> {\n\treadonly key: string\n\treadonly cardinality: Cardinality\n}\n\nexport type JoinState<\n\tASide extends string,\n\tBSide extends string,\n\tCardinality extends Rel8.Cardinality,\n\tContent extends Json.Object | null,\n> = Cardinality extends `1:1`\n\t? (Content extends Json.Object\n\t\t\t? {\n\t\t\t\t\treadonly [AB in ASide | BSide as AB extends ASide\n\t\t\t\t\t\t? `${AB}EntryOf${Capitalize<BSide>}`\n\t\t\t\t\t\t: `${AB}EntryOf${Capitalize<ASide>}`]: SelectorFamily<\n\t\t\t\t\t\t[string, Content] | undefined,\n\t\t\t\t\t\tstring\n\t\t\t\t\t>\n\t\t\t }\n\t\t\t: {}) & {\n\t\t\treadonly [AB in ASide | BSide as AB extends ASide\n\t\t\t\t? `${AB}KeyOf${Capitalize<BSide>}`\n\t\t\t\t: `${AB}KeyOf${Capitalize<ASide>}`]: SelectorFamily<\n\t\t\t\tstring | undefined,\n\t\t\t\tstring\n\t\t\t>\n\t }\n\t: Cardinality extends `1:n`\n\t ? (Content extends Json.Object\n\t\t\t\t? {\n\t\t\t\t\t\treadonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: SelectorFamily<\n\t\t\t\t\t\t\t[string, Content] | undefined,\n\t\t\t\t\t\t\tstring\n\t\t\t\t\t\t>\n\t\t\t\t } & {\n\t\t\t\t\t\treadonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: SelectorFamily<\n\t\t\t\t\t\t\t[string, Content][],\n\t\t\t\t\t\t\tstring\n\t\t\t\t\t\t>\n\t\t\t\t }\n\t\t\t\t: {}) & {\n\t\t\t\treadonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: SelectorFamily<\n\t\t\t\t\tstring | undefined,\n\t\t\t\t\tstring\n\t\t\t\t>\n\t\t } & {\n\t\t\t\treadonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: SelectorFamily<\n\t\t\t\t\tstring[],\n\t\t\t\t\tstring\n\t\t\t\t>\n\t\t }\n\t : Cardinality extends `n:n`\n\t\t ? (Content extends Json.Object\n\t\t\t\t\t? {\n\t\t\t\t\t\t\treadonly [AB in ASide | BSide as AB extends ASide\n\t\t\t\t\t\t\t\t? `${AB}EntriesOf${Capitalize<BSide>}`\n\t\t\t\t\t\t\t\t: `${AB}EntriesOf${Capitalize<ASide>}`]: SelectorFamily<\n\t\t\t\t\t\t\t\t[string, Content][],\n\t\t\t\t\t\t\t\tstring\n\t\t\t\t\t\t\t>\n\t\t\t\t\t }\n\t\t\t\t\t: {}) & {\n\t\t\t\t\treadonly [AB in ASide | BSide as AB extends ASide\n\t\t\t\t\t\t? `${AB}KeysOf${Capitalize<BSide>}`\n\t\t\t\t\t\t: `${AB}KeysOf${Capitalize<ASide>}`]: SelectorFamily<\n\t\t\t\t\t\tstring[],\n\t\t\t\t\t\tstring\n\t\t\t\t\t>\n\t\t\t }\n\t\t : never\n\nexport function join<\n\tconst ASide extends string,\n\tconst BSide extends string,\n\tconst Cardinality extends Rel8.Cardinality,\n>(\n\toptions: JoinOptions<ASide, BSide, Cardinality, null>,\n\tdefaultContent?: undefined,\n\tstore?: Store,\n): {\n\trelations: Junction<ASide, BSide>\n\tfindState: JoinState<ASide, BSide, Cardinality, null>\n}\nexport function join<\n\tconst ASide extends string,\n\tconst Cardinality extends `1:1` | `1:n` | `n:n`,\n\tconst BSide extends string,\n\tconst Content extends Json.Object,\n>(\n\toptions: JoinOptions<ASide, BSide, Cardinality, Content>,\n\tdefaultContent: Content,\n\tstore?: Store,\n): {\n\trelations: Junction<ASide, BSide, Content>\n\tfindState: JoinState<ASide, BSide, Cardinality, Content>\n}\nexport function join<\n\tASide extends string,\n\tBSide extends string,\n\tCardinality extends Rel8.Cardinality,\n\tContent extends Json.Object,\n>(\n\toptions: JoinOptions<ASide, BSide, Cardinality, Content>,\n\tdefaultContent: Content | undefined,\n\tstore: Store = IMPLICIT.STORE,\n): {\n\trelations: Junction<ASide, BSide, Content>\n\tfindState: JoinState<ASide, BSide, Cardinality, Content>\n} {\n\tconst a: ASide = options.between[0]\n\tconst b: BSide = options.between[1]\n\tconst findRelatedKeysState = createMutableAtomFamily<\n\t\tSetRTX<string>,\n\t\tstring[],\n\t\tstring\n\t>(\n\t\t{\n\t\t\tkey: `${options.key}/relatedKeys`,\n\t\t\tdefault: () => new SetRTX(),\n\t\t\tmutable: true,\n\t\t\tfromJson: (json) => new SetRTX(json),\n\t\t\ttoJson: (set) => [...set],\n\t\t},\n\t\tstore,\n\t)\n\tconst getRelatedKeys: Read<(key: string) => Set<string> | undefined> = (\n\t\t{ get },\n\t\tkey,\n\t) => get(findRelatedKeysState(key))\n\tconst addRelation: Write<(a: string, b: string) => void> = (\n\t\ttransactors,\n\t\ta,\n\t\tb,\n\t) => {\n\t\tconst aKeys = getRelatedKeys(transactors, a)\n\t\tconst bKeys = getRelatedKeys(transactors, b)\n\t\tif (aKeys) {\n\t\t\ttransactors.set(findRelatedKeysState(a), aKeys.add(b))\n\t\t} else {\n\t\t\ttransactors.set(findRelatedKeysState(a), new SetRTX([b]))\n\t\t}\n\t\tif (bKeys) {\n\t\t\ttransactors.set(findRelatedKeysState(b), bKeys.add(a))\n\t\t} else {\n\t\t\ttransactors.set(findRelatedKeysState(b), new SetRTX([a]))\n\t\t}\n\t}\n\tconst deleteRelation: Write<(a: string, b: string) => void> = (\n\t\ttransactors,\n\t\ta,\n\t\tb,\n\t) => {\n\t\tconst aKeys = getRelatedKeys(transactors, a)\n\t\tif (aKeys) {\n\t\t\taKeys.delete(b)\n\t\t\tif (aKeys.size === 0) {\n\t\t\t\ttransactors.set(findRelatedKeysState(a), undefined)\n\t\t\t}\n\t\t\tconst bKeys = getRelatedKeys(transactors, b)\n\t\t\tif (bKeys) {\n\t\t\t\tbKeys.delete(a)\n\t\t\t\tif (bKeys.size === 0) {\n\t\t\t\t\ttransactors.set(findRelatedKeysState(b), undefined)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tconst replaceRelationsSafely: Write<(a: string, bs: string[]) => void> = (\n\t\ttransactors,\n\t\ta,\n\t\tbs,\n\t) => {\n\t\tconst aRelations = getRelatedKeys(transactors, a)\n\t\tif (aRelations) {\n\t\t\tfor (const b of aRelations) {\n\t\t\t\tconst bKeys = getRelatedKeys(transactors, b)\n\t\t\t\tif (bKeys) {\n\t\t\t\t\tbKeys.delete(a)\n\t\t\t\t\tif (bKeys.size === 0) {\n\t\t\t\t\t\ttransactors.set(findRelatedKeysState(b), undefined)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\ttransactors.set(findRelatedKeysState(a), new SetRTX(bs))\n\t\tfor (const b of bs) {\n\t\t\tconst bKeys = getRelatedKeys(transactors, b)\n\t\t\tif (bKeys) {\n\t\t\t\tbKeys.add(a)\n\t\t\t} else {\n\t\t\t\ttransactors.set(findRelatedKeysState(b), new SetRTX([a]))\n\t\t\t}\n\t\t}\n\t}\n\tconst replaceRelationsUnsafely: Write<(a: string, bs: string[]) => void> = (\n\t\ttransactors,\n\t\ta,\n\t\tbs,\n\t) => {\n\t\ttransactors.set(findRelatedKeysState(a), new SetRTX(bs))\n\t\tfor (const b of bs) {\n\t\t\tlet bKeys = getRelatedKeys(transactors, b)\n\t\t\tif (bKeys) {\n\t\t\t\tbKeys.add(a)\n\t\t\t} else {\n\t\t\t\tbKeys = new SetRTX([a])\n\t\t\t\ttransactors.set(findRelatedKeysState(b), bKeys)\n\t\t\t}\n\t\t}\n\t}\n\tconst has: Read<(a: string, b?: string) => boolean> = (transactors, a, b) => {\n\t\tconst aKeys = getRelatedKeys(transactors, a)\n\t\treturn b ? aKeys?.has(b) ?? false : (aKeys?.size ?? 0) > 0 ?? false\n\t}\n\tconst baseExternalStoreConfiguration: BaseExternalStoreConfiguration = {\n\t\tgetRelatedKeys: (key) => getRelatedKeys(TRANSACTORS, key),\n\t\taddRelation: (a, b) => addRelation(TRANSACTORS, a, b),\n\t\tdeleteRelation: (a, b) => deleteRelation(TRANSACTORS, a, b),\n\t\treplaceRelationsSafely: (a, bs) =>\n\t\t\treplaceRelationsSafely(TRANSACTORS, a, bs),\n\t\treplaceRelationsUnsafely: (a, bs) =>\n\t\t\treplaceRelationsUnsafely(TRANSACTORS, a, bs),\n\t\thas: (a, b) => has(TRANSACTORS, a, b),\n\t}\n\tlet externalStore: ExternalStoreConfiguration<Content>\n\tlet findContentState: AtomFamily<Content, string>\n\tif (defaultContent) {\n\t\tfindContentState = createAtomFamily<Content, string>(\n\t\t\t{\n\t\t\t\tkey: `${options.key}/content`,\n\t\t\t\tdefault: defaultContent,\n\t\t\t},\n\t\t\tstore,\n\t\t)\n\t\tconst getContent: Read<(key: string) => Content | undefined> = (\n\t\t\t{ get },\n\t\t\tkey,\n\t\t) => get(findContentState(key))\n\t\tconst setContent: Write<(key: string, content: Content) => void> = (\n\t\t\ttransactors,\n\t\t\tkey,\n\t\t\tcontent,\n\t\t) => transactors.set(findContentState(key), content)\n\t\tconst deleteContent: Write<(key: string) => void> = (transactors, key) =>\n\t\t\ttransactors.set(findContentState(key), undefined)\n\t\tconst externalStoreWithContentConfiguration: ExternalStoreWithContentConfiguration<Content> =\n\t\t\t{\n\t\t\t\tgetContent: (contentKey: string) => {\n\t\t\t\t\tconst content = getContent(TRANSACTORS, contentKey)\n\t\t\t\t\treturn content\n\t\t\t\t},\n\t\t\t\tsetContent: (contentKey: string, content: Content) => {\n\t\t\t\t\tsetContent(TRANSACTORS, contentKey, content)\n\t\t\t\t},\n\t\t\t\tdeleteContent: (contentKey: string) => {\n\t\t\t\t\tdeleteContent(TRANSACTORS, contentKey)\n\t\t\t\t},\n\t\t\t}\n\t\texternalStore = Object.assign(\n\t\t\tbaseExternalStoreConfiguration,\n\t\t\texternalStoreWithContentConfiguration,\n\t\t) as ExternalStoreConfiguration<Content>\n\t} else {\n\t\texternalStore =\n\t\t\tbaseExternalStoreConfiguration as ExternalStoreConfiguration<Content>\n\t}\n\tconst relations = new Junction<ASide, BSide, Content>(options, {\n\t\texternalStore,\n\t\tmakeContentKey: (...args) => args.sort().join(`:`),\n\t})\n\n\tconst createSingleKeyStateFamily = () =>\n\t\tcreateSelectorFamily<string | undefined, string>(\n\t\t\t{\n\t\t\t\tkey: `${options.key}/singleRelatedKey`,\n\t\t\t\tget:\n\t\t\t\t\t(key) =>\n\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\tconst relatedKeys = get(findRelatedKeysState(key))\n\t\t\t\t\t\tfor (const relatedKey of relatedKeys) {\n\t\t\t\t\t\t\treturn relatedKey\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t},\n\t\t\tstore,\n\t\t)\n\tconst getMultipleKeyStateFamily = () =>\n\t\tgetJsonFamily(findRelatedKeysState, store)\n\tconst createSingleEntryStateFamily = () =>\n\t\tcreateSelectorFamily<[string, Content] | undefined, string>(\n\t\t\t{\n\t\t\t\tkey: `${options.key}/singleRelatedEntry`,\n\t\t\t\tget:\n\t\t\t\t\t(key) =>\n\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\tconst relatedKeys = get(findRelatedKeysState(key))\n\t\t\t\t\t\tfor (const relatedKey of relatedKeys) {\n\t\t\t\t\t\t\tconst contentKey = relations.makeContentKey(key, relatedKey)\n\t\t\t\t\t\t\treturn [relatedKey, get(findContentState(contentKey))]\n\t\t\t\t\t\t}\n\t\t\t\t\t},\n\t\t\t},\n\t\t\tstore,\n\t\t)\n\tconst getMultipleEntryStateFamily = () =>\n\t\tcreateSelectorFamily<[string, Content][], string>(\n\t\t\t{\n\t\t\t\tkey: `${options.key}/multipleRelatedEntries`,\n\t\t\t\tget:\n\t\t\t\t\t(key) =>\n\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\tconst relatedKeys = get(findRelatedKeysState(key))\n\t\t\t\t\t\treturn [...relatedKeys].map((relatedKey) => {\n\t\t\t\t\t\t\tconst contentKey = relations.makeContentKey(key, relatedKey)\n\t\t\t\t\t\t\treturn [relatedKey, get(findContentState(contentKey))]\n\t\t\t\t\t\t})\n\t\t\t\t\t},\n\t\t\t},\n\t\t\tstore,\n\t\t)\n\n\tswitch (options.cardinality) {\n\t\tcase `1:1`: {\n\t\t\tconst findSingleRelatedKeyState = createSingleKeyStateFamily()\n\t\t\tconst stateKeyA = `${a}KeyOf${capitalize(b)}` as const\n\t\t\tconst stateKeyB = `${b}KeyOf${capitalize(a)}` as const\n\t\t\tconst findStateBase = {\n\t\t\t\t[stateKeyA]: findSingleRelatedKeyState,\n\t\t\t\t[stateKeyB]: findSingleRelatedKeyState,\n\t\t\t} as JoinState<ASide, BSide, Cardinality, Content>\n\t\t\tlet findState: JoinState<ASide, BSide, Cardinality, Content>\n\t\t\tif (defaultContent) {\n\t\t\t\tconst findSingleRelatedEntryState = createSingleEntryStateFamily()\n\t\t\t\tconst entriesStateKeyA = `${a}EntryOf${capitalize(b)}` as const\n\t\t\t\tconst entriesStateKeyB = `${b}EntryOf${capitalize(a)}` as const\n\t\t\t\tconst findStateWithContent = {\n\t\t\t\t\t[entriesStateKeyA]: findSingleRelatedEntryState,\n\t\t\t\t\t[entriesStateKeyB]: findSingleRelatedEntryState,\n\t\t\t\t}\n\t\t\t\tfindState = Object.assign(findStateBase, findStateWithContent)\n\t\t\t} else {\n\t\t\t\tfindState = findStateBase\n\t\t\t}\n\t\t\treturn {\n\t\t\t\trelations,\n\t\t\t\tfindState,\n\t\t\t}\n\t\t}\n\t\tcase `1:n`: {\n\t\t\tconst findSingleRelatedKeyState = createSingleKeyStateFamily()\n\t\t\tconst findMultipleRelatedKeysState = getMultipleKeyStateFamily()\n\t\t\tconst stateKeyA = `${a}KeyOf${capitalize(b)}` as const\n\t\t\tconst stateKeyB = `${b}KeysOf${capitalize(a)}` as const\n\t\t\tconst findStateBase = {\n\t\t\t\t[stateKeyA]: findSingleRelatedKeyState,\n\t\t\t\t[stateKeyB]: findMultipleRelatedKeysState,\n\t\t\t} as JoinState<ASide, BSide, Cardinality, Content>\n\t\t\tlet findState: JoinState<ASide, BSide, Cardinality, Content>\n\t\t\tif (defaultContent) {\n\t\t\t\tconst findSingleRelatedEntryState = createSingleEntryStateFamily()\n\t\t\t\tconst findMultipleRelatedEntriesState = getMultipleEntryStateFamily()\n\t\t\t\tconst entriesStateKeyA = `${a}EntryOf${capitalize(b)}` as const\n\t\t\t\tconst entriesStateKeyB = `${b}EntriesOf${capitalize(a)}` as const\n\t\t\t\tconst findStateWithContent = {\n\t\t\t\t\t[entriesStateKeyA]: findSingleRelatedEntryState,\n\t\t\t\t\t[entriesStateKeyB]: findMultipleRelatedEntriesState,\n\t\t\t\t}\n\t\t\t\tfindState = Object.assign(findStateBase, findStateWithContent)\n\t\t\t} else {\n\t\t\t\tfindState = findStateBase\n\t\t\t}\n\t\t\treturn {\n\t\t\t\trelations,\n\t\t\t\tfindState,\n\t\t\t}\n\t\t}\n\t\tcase `n:n`: {\n\t\t\tconst findMultipleRelatedKeysState = getMultipleKeyStateFamily()\n\t\t\tconst stateKeyA = `${a}KeysOf${capitalize(b)}` as const\n\t\t\tconst stateKeyB = `${b}KeysOf${capitalize(a)}` as const\n\t\t\tconst findStateBase = {\n\t\t\t\t[stateKeyA]: findMultipleRelatedKeysState,\n\t\t\t\t[stateKeyB]: findMultipleRelatedKeysState,\n\t\t\t} as JoinState<ASide, BSide, Cardinality, Content>\n\t\t\tlet findState: JoinState<ASide, BSide, Cardinality, Content>\n\t\t\tif (defaultContent) {\n\t\t\t\tconst findMultipleRelatedEntriesState = getMultipleEntryStateFamily()\n\t\t\t\tconst entriesStateKeyA = `${a}EntriesOf${capitalize(b)}` as const\n\t\t\t\tconst entriesStateKeyB = `${b}EntriesOf${capitalize(a)}` as const\n\t\t\t\tconst findStateWithContent = {\n\t\t\t\t\t[entriesStateKeyA]: findMultipleRelatedEntriesState,\n\t\t\t\t\t[entriesStateKeyB]: findMultipleRelatedEntriesState,\n\t\t\t\t}\n\t\t\t\tfindState = Object.assign(findStateBase, findStateWithContent)\n\t\t\t} else {\n\t\t\t\tfindState = findStateBase\n\t\t\t}\n\t\t\treturn {\n\t\t\t\trelations,\n\t\t\t\tfindState,\n\t\t\t}\n\t\t}\n\t\tdefault:\n\t\t\tthrow new Error(`Invalid cardinality: ${options.cardinality}`)\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\n\nimport { createAtom, createSelector } from \"atom.io/internal\"\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\n\nexport function struct<\n\tStruct extends { [key: string]: unknown },\n\tKey extends string,\n>(\n\toptions: {\n\t\tkey: Key\n\t\tdefault: Struct\n\t},\n\tstore: Store = IMPLICIT.STORE,\n): [\n\t{\n\t\t[K in keyof Struct as `${Key}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.AtomToken<Struct[K]>\n\t},\n\tAtomIO.ReadonlySelectorToken<Struct>,\n] {\n\tconst atoms: {\n\t\t[K in keyof Struct as `${Key}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.AtomToken<Struct[K]>\n\t} = Object.keys(options.default).reduce((acc, key) => {\n\t\tconst atomName = options.key + capitalize(key) + `State`\n\t\tacc[atomName] = createAtom(\n\t\t\t{\n\t\t\t\tkey: `${options.key}.${key}`,\n\t\t\t\tdefault: options.default[key],\n\t\t\t},\n\t\t\tundefined,\n\t\t\tstore,\n\t\t)\n\t\treturn acc\n\t}, {} as any)\n\tconst structState = createSelector(\n\t\t{\n\t\t\tkey: options.key,\n\t\t\tget: ({ get }) => {\n\t\t\t\treturn Object.keys(options.default).reduce((acc, key) => {\n\t\t\t\t\tacc[key] = get(atoms[options.key + capitalize(key) + `State`])\n\t\t\t\t\treturn acc\n\t\t\t\t}, {} as any)\n\t\t\t},\n\t\t},\n\t\tundefined,\n\t\tstore,\n\t)\n\treturn [atoms, structState]\n}\n","import type * as AtomIO from \"atom.io\"\nimport {\n\tIMPLICIT,\n\tcreateAtomFamily,\n\tcreateSelectorFamily,\n} from \"atom.io/internal\"\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\nconst nameFamily = (topKey: string, subKey: string) =>\n\t`find` + capitalize(topKey) + capitalize(subKey) + `State`\n\nexport function structFamily<\n\tStruct extends object,\n\tKey extends string,\n>(options: {\n\tkey: Key\n\tdefault: Struct\n}): [\n\t{\n\t\t[K in keyof Struct as `find${Capitalize<Key & string>}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.AtomFamily<Struct[K], string>\n\t},\n\tAtomIO.ReadonlySelectorFamily<Struct>,\n] {\n\tconst atoms: {\n\t\t[K in keyof Struct as `find${Capitalize<Key & string>}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.AtomFamily<Struct[K], string>\n\t} = Object.keys(options.default).reduce((acc, subKey) => {\n\t\tconst atomFamilyName = nameFamily(options.key, subKey)\n\t\tacc[atomFamilyName] = createAtomFamily(\n\t\t\t{\n\t\t\t\tkey: `${options.key}.${subKey}`,\n\t\t\t\tdefault: (options.default as any)[subKey],\n\t\t\t},\n\t\t\tIMPLICIT.STORE,\n\t\t)\n\t\treturn acc\n\t}, {} as any)\n\tconst findStructState = createSelectorFamily(\n\t\t{\n\t\t\tkey: options.key,\n\t\t\tget:\n\t\t\t\t(id) =>\n\t\t\t\t({ get }) => {\n\t\t\t\t\treturn Object.keys(options.default).reduce((acc, subKey) => {\n\t\t\t\t\t\tacc[subKey] = get(\n\t\t\t\t\t\t\t(atoms as any)[nameFamily(options.key, subKey)](id),\n\t\t\t\t\t\t)\n\t\t\t\t\t\treturn acc\n\t\t\t\t\t}, {} as any)\n\t\t\t\t},\n\t\t},\n\t\tIMPLICIT.STORE,\n\t)\n\treturn [atoms, findStructState]\n}\n","export type Loadable<T> = Promise<T> | T\nexport type Fated<T, E extends Error = Error> = Loadable<E | T>\n\n/**\n * Utility for handling loadable values\n * @param loadable Loadable value\n * @param fallback Fallback value until Loadable is resolved\n * @returns Fallback value if your loadable is a promise, otherwise the loadable's resolved value\n */\nexport function until<T>(loadable: Loadable<T>, fallback: T): T {\n\tif (loadable instanceof Promise) {\n\t\treturn fallback\n\t}\n\treturn loadable\n}\n"]}
1
+ {"version":3,"sources":["../src/dict.ts","../src/join.ts","../src/struct.ts","../src/struct-family.ts","../src/until.ts"],"names":["IMPLICIT","a","b","createSelector","capitalize","createRegularAtomFamily","createSelectorFamily"],"mappings":";;;;;;AAEA,SAAS,UAAU,sBAAsB;AAGlC,SAAS,KACf,WAIA,OAIA,QAAe,SAAS,OAC2C;AACnE,SAAO;AAAA,IACN;AAAA,MACC,KAAK,GAAG,UAAU,GAAG;AAAA,MACrB,KAAK,CAAC,EAAE,IAAI,MAAM;AACjB,cAAM,OAAO,IAAI,KAAK;AACtB,eAAO,KAAK,OAAO,CAAC,KAAK,QAAQ;AAChC,cAAI,GAAG,IAAI,IAAI,UAAU,GAAG,CAAC;AAC7B,iBAAO;AAAA,QACR,GAAG,CAAC,CAAQ;AAAA,MACb;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;;;ACtBA,SAAS,SAAS,UAAU,gBAAgB;AAE5C;AAAA,EACC,YAAAA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAEP,SAAS,cAAc;AAWvB,IAAM,cAA2B,EAAE,KAAK,UAAU,KAAK,SAAS;AAEhE,SAAS,WAA6B,QAA0B;AAC/D,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C/D,MAAI,oBAAoB,SAAS;AAChC,WAAO;AAAA,EACR;AACA,SAAO;AACR","sourcesContent":["import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, createSelector } from \"atom.io/internal\"\nimport type { Json, Stringified } from \"atom.io/json\"\n\nexport function dict<State, Key extends Json.Serializable>(\n\tfindState:\n\t\t| AtomIO.AtomFamily<State, Key>\n\t\t| AtomIO.ReadonlySelectorFamily<State, Key>\n\t\t| AtomIO.SelectorFamily<State, Key>,\n\tindex:\n\t\t| AtomIO.AtomToken<Key[]>\n\t\t| AtomIO.ReadonlySelectorToken<Key[]>\n\t\t| AtomIO.SelectorToken<Key[]>,\n\tstore: Store = IMPLICIT.STORE,\n): AtomIO.ReadonlySelectorToken<{ [K in Stringified<Key>]: State }> {\n\treturn createSelector(\n\t\t{\n\t\t\tkey: `${findState.key}Dict`,\n\t\t\tget: ({ get }) => {\n\t\t\t\tconst keys = get(index)\n\t\t\t\treturn keys.reduce((acc, key) => {\n\t\t\t\t\tacc[key] = get(findState(key))\n\t\t\t\t\treturn acc\n\t\t\t\t}, {} as any)\n\t\t\t},\n\t\t},\n\t\tundefined,\n\t\tstore,\n\t)\n}\n","/* eslint-disable @typescript-eslint/ban-types */\nimport type {\n\tAtomFamily,\n\tRead,\n\tSelectorFamily,\n\tTransactors,\n\tWrite,\n} from \"atom.io\"\nimport { dispose, getState, setState } from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tcreateMutableAtomFamily,\n\tcreateRegularAtomFamily,\n\tcreateSelectorFamily,\n\tgetJsonFamily,\n} from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { SetRTX } from \"atom.io/transceivers/set-rtx\"\n\nimport type {\n\tBaseExternalStoreConfiguration,\n\tExternalStoreConfiguration,\n\tJunctionEntries,\n\tJunctionSchema,\n} from \"~/packages/rel8/junction/src\"\nimport { Junction } from \"~/packages/rel8/junction/src\"\nimport type * as Rel8 from \"~/packages/rel8/types/src\"\n\nconst TRANSACTORS: Transactors = { get: getState, set: setState }\n\nfunction capitalize<S extends string>(string: S): Capitalize<S> {\n\treturn (string[0].toUpperCase() + string.slice(1)) as Capitalize<S>\n}\n\nexport interface JoinOptions<\n\tASide extends string,\n\tBSide extends string,\n\tCardinality extends Rel8.Cardinality,\n\tContent extends Json.Object | null,\n> extends Json.Object,\n\t\tJunctionSchema<ASide, BSide>,\n\t\tPartial<JunctionEntries<Content>> {\n\treadonly key: string\n\treadonly cardinality: Cardinality\n}\n\nexport type JoinState<\n\tASide extends string,\n\tBSide extends string,\n\tCardinality extends Rel8.Cardinality,\n\tContent extends Json.Object | null,\n> = Cardinality extends `1:1`\n\t? (Content extends Json.Object\n\t\t\t? {\n\t\t\t\t\treadonly [AB in ASide | BSide as AB extends ASide\n\t\t\t\t\t\t? `${AB}EntryOf${Capitalize<BSide>}`\n\t\t\t\t\t\t: `${AB}EntryOf${Capitalize<ASide>}`]: SelectorFamily<\n\t\t\t\t\t\t[string, Content] | undefined,\n\t\t\t\t\t\tstring\n\t\t\t\t\t>\n\t\t\t }\n\t\t\t: {}) & {\n\t\t\treadonly [AB in ASide | BSide as AB extends ASide\n\t\t\t\t? `${AB}KeyOf${Capitalize<BSide>}`\n\t\t\t\t: `${AB}KeyOf${Capitalize<ASide>}`]: SelectorFamily<\n\t\t\t\tstring | undefined,\n\t\t\t\tstring\n\t\t\t>\n\t }\n\t: Cardinality extends `1:n`\n\t ? (Content extends Json.Object\n\t\t\t\t? {\n\t\t\t\t\t\treadonly [A in ASide as `${A}EntryOf${Capitalize<BSide>}`]: SelectorFamily<\n\t\t\t\t\t\t\t[string, Content] | undefined,\n\t\t\t\t\t\t\tstring\n\t\t\t\t\t\t>\n\t\t\t\t } & {\n\t\t\t\t\t\treadonly [B in BSide as `${B}EntriesOf${Capitalize<ASide>}`]: SelectorFamily<\n\t\t\t\t\t\t\t[string, Content][],\n\t\t\t\t\t\t\tstring\n\t\t\t\t\t\t>\n\t\t\t\t }\n\t\t\t\t: {}) & {\n\t\t\t\treadonly [A in ASide as `${A}KeyOf${Capitalize<BSide>}`]: SelectorFamily<\n\t\t\t\t\tstring | undefined,\n\t\t\t\t\tstring\n\t\t\t\t>\n\t\t } & {\n\t\t\t\treadonly [B in BSide as `${B}KeysOf${Capitalize<ASide>}`]: SelectorFamily<\n\t\t\t\t\tstring[],\n\t\t\t\t\tstring\n\t\t\t\t>\n\t\t }\n\t : Cardinality extends `n:n`\n\t\t ? (Content extends Json.Object\n\t\t\t\t\t? {\n\t\t\t\t\t\t\treadonly [AB in ASide | BSide as AB extends ASide\n\t\t\t\t\t\t\t\t? `${AB}EntriesOf${Capitalize<BSide>}`\n\t\t\t\t\t\t\t\t: `${AB}EntriesOf${Capitalize<ASide>}`]: SelectorFamily<\n\t\t\t\t\t\t\t\t[string, Content][],\n\t\t\t\t\t\t\t\tstring\n\t\t\t\t\t\t\t>\n\t\t\t\t\t }\n\t\t\t\t\t: {}) & {\n\t\t\t\t\treadonly [AB in ASide | BSide as AB extends ASide\n\t\t\t\t\t\t? `${AB}KeysOf${Capitalize<BSide>}`\n\t\t\t\t\t\t: `${AB}KeysOf${Capitalize<ASide>}`]: SelectorFamily<\n\t\t\t\t\t\tstring[],\n\t\t\t\t\t\tstring\n\t\t\t\t\t>\n\t\t\t }\n\t\t : never\n\nexport class Join<\n\tconst ASide extends string,\n\tconst BSide extends string,\n\tconst Cardinality extends `1:1` | `1:n` | `n:n`,\n\tconst Content extends Json.Object | null = null,\n> {\n\tprivate transactors: Transactors = TRANSACTORS\n\tpublic relations: Junction<ASide, BSide, Content>\n\tpublic findState: JoinState<ASide, BSide, Cardinality, Content>\n\tpublic transact(\n\t\ttransactors: Transactors,\n\t\trun: (join: Join<ASide, BSide, Cardinality, Content>) => void,\n\t): void {\n\t\tthis.transactors = transactors\n\t\trun(this)\n\t\tthis.transactors = TRANSACTORS\n\t}\n\tpublic constructor(\n\t\toptions: JoinOptions<ASide, BSide, Cardinality, Content>,\n\t\tdefaultContent: Content | undefined,\n\t\tstore: Store = IMPLICIT.STORE,\n\t) {\n\t\tconst a: ASide = options.between[0]\n\t\tconst b: BSide = options.between[1]\n\t\tconst findRelatedKeysState = createMutableAtomFamily<\n\t\t\tSetRTX<string>,\n\t\t\tstring[],\n\t\t\tstring\n\t\t>(\n\t\t\t{\n\t\t\t\tkey: `${options.key}/relatedKeys`,\n\t\t\t\tdefault: () => new SetRTX(),\n\t\t\t\tmutable: true,\n\t\t\t\tfromJson: (json) => new SetRTX(json),\n\t\t\t\ttoJson: (set) => [...set],\n\t\t\t},\n\t\t\tstore,\n\t\t)\n\t\tconst getRelatedKeys: Read<(key: string) => SetRTX<string>> = (\n\t\t\t{ get },\n\t\t\tkey,\n\t\t) => get(findRelatedKeysState(key))\n\t\tconst addRelation: Write<(a: string, b: string) => void> = (\n\t\t\ttransactors,\n\t\t\ta,\n\t\t\tb,\n\t\t) => {\n\t\t\tconst aKeys = getRelatedKeys(transactors, a)\n\t\t\tconst bKeys = getRelatedKeys(transactors, b)\n\t\t\ttransactors.set(findRelatedKeysState(a), aKeys.add(b))\n\t\t\ttransactors.set(findRelatedKeysState(b), bKeys.add(a))\n\t\t}\n\t\tconst deleteRelation: Write<(a: string, b: string) => void> = (\n\t\t\ttransactors,\n\t\t\ta,\n\t\t\tb,\n\t\t) => {\n\t\t\tconst aKeys = getRelatedKeys(transactors, a)\n\t\t\taKeys.delete(b)\n\t\t\tif (aKeys.size === 0) {\n\t\t\t\tdispose(findRelatedKeysState(a))\n\t\t\t}\n\t\t\tconst bKeys = getRelatedKeys(transactors, b)\n\t\t\tbKeys.delete(a)\n\t\t\tif (bKeys.size === 0) {\n\t\t\t\tdispose(findRelatedKeysState(b))\n\t\t\t}\n\t\t}\n\t\tconst replaceRelationsSafely: Write<(a: string, bs: string[]) => void> = (\n\t\t\ttransactors,\n\t\t\ta,\n\t\t\tbs,\n\t\t) => {\n\t\t\tconst aRelations = getRelatedKeys(transactors, a)\n\t\t\tfor (const b of aRelations) {\n\t\t\t\tconst bKeys = getRelatedKeys(transactors, b)\n\t\t\t\tif (bKeys) {\n\t\t\t\t\tbKeys.delete(a)\n\t\t\t\t\tif (bKeys.size === 0) {\n\t\t\t\t\t\tdispose(findRelatedKeysState(b))\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\ttransactors.set(findRelatedKeysState(a), new SetRTX(bs))\n\t\t\tfor (const b of bs) {\n\t\t\t\tconst bKeys = getRelatedKeys(transactors, b)\n\t\t\t\tbKeys.add(a)\n\t\t\t}\n\t\t}\n\t\tconst replaceRelationsUnsafely: Write<(a: string, bs: string[]) => void> = (\n\t\t\ttransactors,\n\t\t\ta,\n\t\t\tbs,\n\t\t) => {\n\t\t\ttransactors.set(findRelatedKeysState(a), new SetRTX(bs))\n\t\t\tfor (const b of bs) {\n\t\t\t\tconst bKeys = getRelatedKeys(transactors, b)\n\t\t\t\tbKeys.add(a)\n\t\t\t}\n\t\t}\n\t\tconst has: Read<(a: string, b?: string) => boolean> = (\n\t\t\ttransactors,\n\t\t\ta,\n\t\t\tb,\n\t\t) => {\n\t\t\tconst aKeys = getRelatedKeys(transactors, a)\n\t\t\treturn b ? aKeys.has(b) : aKeys.size > 0\n\t\t}\n\t\tconst baseExternalStoreConfiguration: BaseExternalStoreConfiguration = {\n\t\t\tgetRelatedKeys: (key) => getRelatedKeys(this.transactors, key),\n\t\t\taddRelation: (a, b) => addRelation(this.transactors, a, b),\n\t\t\tdeleteRelation: (a, b) => deleteRelation(this.transactors, a, b),\n\t\t\treplaceRelationsSafely: (a, bs) =>\n\t\t\t\treplaceRelationsSafely(this.transactors, a, bs),\n\t\t\treplaceRelationsUnsafely: (a, bs) =>\n\t\t\t\treplaceRelationsUnsafely(this.transactors, a, bs),\n\t\t\thas: (a, b) => has(this.transactors, a, b),\n\t\t}\n\t\tlet externalStore: ExternalStoreConfiguration<Content>\n\t\tlet findContentState: AtomFamily<Content, string>\n\t\tif (defaultContent) {\n\t\t\tfindContentState = createRegularAtomFamily<Content, string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/content`,\n\t\t\t\t\tdefault: defaultContent,\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\t\t\tconst getContent: Read<(key: string) => Content | undefined> = (\n\t\t\t\t{ get },\n\t\t\t\tkey,\n\t\t\t) => get(findContentState(key))\n\t\t\tconst setContent: Write<(key: string, content: Content) => void> = (\n\t\t\t\ttransactors,\n\t\t\t\tkey,\n\t\t\t\tcontent,\n\t\t\t) => transactors.set(findContentState(key), content)\n\t\t\tconst deleteContent: Write<(key: string) => void> = (_, key) =>\n\t\t\t\tdispose(findContentState(key))\n\t\t\tconst externalStoreWithContentConfiguration = {\n\t\t\t\tgetContent: (contentKey: string) => {\n\t\t\t\t\tconst content = getContent(this.transactors, contentKey)\n\t\t\t\t\treturn content\n\t\t\t\t},\n\t\t\t\tsetContent: (contentKey: string, content: Content) => {\n\t\t\t\t\tsetContent(this.transactors, contentKey, content)\n\t\t\t\t},\n\t\t\t\tdeleteContent: (contentKey: string) => {\n\t\t\t\t\tdeleteContent(this.transactors, contentKey)\n\t\t\t\t},\n\t\t\t}\n\t\t\texternalStore = Object.assign(\n\t\t\t\tbaseExternalStoreConfiguration,\n\t\t\t\texternalStoreWithContentConfiguration,\n\t\t\t) as ExternalStoreConfiguration<Content>\n\t\t} else {\n\t\t\texternalStore =\n\t\t\t\tbaseExternalStoreConfiguration as ExternalStoreConfiguration<Content>\n\t\t}\n\t\tconst relations = new Junction<ASide, BSide, Content>(options, {\n\t\t\texternalStore,\n\t\t\tmakeContentKey: (...args) => args.sort().join(`:`),\n\t\t})\n\n\t\tconst createSingleKeyStateFamily = () =>\n\t\t\tcreateSelectorFamily<string | undefined, string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/singleRelatedKey`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst relatedKeys = get(findRelatedKeysState(key))\n\t\t\t\t\t\t\tfor (const relatedKey of relatedKeys) {\n\t\t\t\t\t\t\t\treturn relatedKey\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\t\tconst getMultipleKeyStateFamily = () =>\n\t\t\tgetJsonFamily(findRelatedKeysState, store)\n\t\tconst createSingleEntryStateFamily = () =>\n\t\t\tcreateSelectorFamily<[string, Content] | undefined, string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/singleRelatedEntry`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst relatedKeys = get(findRelatedKeysState(key))\n\t\t\t\t\t\t\tfor (const relatedKey of relatedKeys) {\n\t\t\t\t\t\t\t\tconst contentKey = relations.makeContentKey(key, relatedKey)\n\t\t\t\t\t\t\t\treturn [relatedKey, get(findContentState(contentKey))]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\t\tconst getMultipleEntryStateFamily = () =>\n\t\t\tcreateSelectorFamily<[string, Content][], string>(\n\t\t\t\t{\n\t\t\t\t\tkey: `${options.key}/multipleRelatedEntries`,\n\t\t\t\t\tget:\n\t\t\t\t\t\t(key) =>\n\t\t\t\t\t\t({ get }) => {\n\t\t\t\t\t\t\tconst relatedKeys = get(findRelatedKeysState(key))\n\t\t\t\t\t\t\treturn [...relatedKeys].map((relatedKey) => {\n\t\t\t\t\t\t\t\tconst contentKey = relations.makeContentKey(key, relatedKey)\n\t\t\t\t\t\t\t\treturn [relatedKey, get(findContentState(contentKey))]\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\n\t\tswitch (options.cardinality) {\n\t\t\tcase `1:1`: {\n\t\t\t\tconst findSingleRelatedKeyState = createSingleKeyStateFamily()\n\t\t\t\tconst stateKeyA = `${a}KeyOf${capitalize(b)}` as const\n\t\t\t\tconst stateKeyB = `${b}KeyOf${capitalize(a)}` as const\n\t\t\t\tconst findStateBase = {\n\t\t\t\t\t[stateKeyA]: findSingleRelatedKeyState,\n\t\t\t\t\t[stateKeyB]: findSingleRelatedKeyState,\n\t\t\t\t} as JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tlet findState: JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tif (defaultContent) {\n\t\t\t\t\tconst findSingleRelatedEntryState = createSingleEntryStateFamily()\n\t\t\t\t\tconst entriesStateKeyA = `${a}EntryOf${capitalize(b)}` as const\n\t\t\t\t\tconst entriesStateKeyB = `${b}EntryOf${capitalize(a)}` as const\n\t\t\t\t\tconst findStateWithContent = {\n\t\t\t\t\t\t[entriesStateKeyA]: findSingleRelatedEntryState,\n\t\t\t\t\t\t[entriesStateKeyB]: findSingleRelatedEntryState,\n\t\t\t\t\t}\n\t\t\t\t\tfindState = Object.assign(findStateBase, findStateWithContent)\n\t\t\t\t} else {\n\t\t\t\t\tfindState = findStateBase\n\t\t\t\t}\n\t\t\t\tthis.relations = relations\n\t\t\t\tthis.findState = findState\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase `1:n`: {\n\t\t\t\tconst findSingleRelatedKeyState = createSingleKeyStateFamily()\n\t\t\t\tconst findMultipleRelatedKeysState = getMultipleKeyStateFamily()\n\t\t\t\tconst stateKeyA = `${a}KeyOf${capitalize(b)}` as const\n\t\t\t\tconst stateKeyB = `${b}KeysOf${capitalize(a)}` as const\n\t\t\t\tconst findStateBase = {\n\t\t\t\t\t[stateKeyA]: findSingleRelatedKeyState,\n\t\t\t\t\t[stateKeyB]: findMultipleRelatedKeysState,\n\t\t\t\t} as JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tlet findState: JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tif (defaultContent) {\n\t\t\t\t\tconst findSingleRelatedEntryState = createSingleEntryStateFamily()\n\t\t\t\t\tconst findMultipleRelatedEntriesState = getMultipleEntryStateFamily()\n\t\t\t\t\tconst entriesStateKeyA = `${a}EntryOf${capitalize(b)}` as const\n\t\t\t\t\tconst entriesStateKeyB = `${b}EntriesOf${capitalize(a)}` as const\n\t\t\t\t\tconst findStateWithContent = {\n\t\t\t\t\t\t[entriesStateKeyA]: findSingleRelatedEntryState,\n\t\t\t\t\t\t[entriesStateKeyB]: findMultipleRelatedEntriesState,\n\t\t\t\t\t}\n\t\t\t\t\tfindState = Object.assign(findStateBase, findStateWithContent)\n\t\t\t\t} else {\n\t\t\t\t\tfindState = findStateBase\n\t\t\t\t}\n\t\t\t\tthis.relations = relations\n\t\t\t\tthis.findState = findState\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tconst findMultipleRelatedKeysState = getMultipleKeyStateFamily()\n\t\t\t\tconst stateKeyA = `${a}KeysOf${capitalize(b)}` as const\n\t\t\t\tconst stateKeyB = `${b}KeysOf${capitalize(a)}` as const\n\t\t\t\tconst findStateBase = {\n\t\t\t\t\t[stateKeyA]: findMultipleRelatedKeysState,\n\t\t\t\t\t[stateKeyB]: findMultipleRelatedKeysState,\n\t\t\t\t} as JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tlet findState: JoinState<ASide, BSide, Cardinality, Content>\n\t\t\t\tif (defaultContent) {\n\t\t\t\t\tconst findMultipleRelatedEntriesState = getMultipleEntryStateFamily()\n\t\t\t\t\tconst entriesStateKeyA = `${a}EntriesOf${capitalize(b)}` as const\n\t\t\t\t\tconst entriesStateKeyB = `${b}EntriesOf${capitalize(a)}` as const\n\t\t\t\t\tconst findStateWithContent = {\n\t\t\t\t\t\t[entriesStateKeyA]: findMultipleRelatedEntriesState,\n\t\t\t\t\t\t[entriesStateKeyB]: findMultipleRelatedEntriesState,\n\t\t\t\t\t}\n\t\t\t\t\tfindState = Object.assign(findStateBase, findStateWithContent)\n\t\t\t\t} else {\n\t\t\t\t\tfindState = findStateBase\n\t\t\t\t}\n\t\t\t\tthis.relations = relations\n\t\t\t\tthis.findState = findState\n\t\t\t}\n\t\t}\n\t}\n}\nexport function join<\n\tconst ASide extends string,\n\tconst BSide extends string,\n\tconst Cardinality extends `1:1` | `1:n` | `n:n`,\n>(\n\toptions: JoinOptions<ASide, BSide, Cardinality, null>,\n\tdefaultContent?: undefined,\n\tstore?: Store,\n): {\n\trelations: Junction<ASide, BSide, null>\n\tfindState: JoinState<ASide, BSide, Cardinality, null>\n\ttransact: (\n\t\ttransactors: Transactors,\n\t\trun: (join: Join<ASide, BSide, Cardinality, null>) => void,\n\t) => void\n}\nexport function join<\n\tconst ASide extends string,\n\tconst BSide extends string,\n\tconst Cardinality extends `1:1` | `1:n` | `n:n`,\n\tconst Content extends Json.Object,\n>(\n\toptions: JoinOptions<ASide, BSide, Cardinality, Content>,\n\tdefaultContent: Content,\n\tstore?: Store,\n): {\n\treadonly relations: Junction<ASide, BSide, Content>\n\treadonly findState: JoinState<ASide, BSide, Cardinality, Content>\n\treadonly transact: (\n\t\ttransactors: Transactors,\n\t\trun: (join: Join<ASide, BSide, Cardinality, Content>) => void,\n\t) => void\n}\nexport function join<\n\tASide extends string,\n\tBSide extends string,\n\tCardinality extends `1:1` | `1:n` | `n:n`,\n\tContent extends Json.Object,\n>(\n\toptions: JoinOptions<ASide, BSide, Cardinality, Content>,\n\tdefaultContent: Content | undefined,\n\tstore: Store = IMPLICIT.STORE,\n): Join<ASide, BSide, Cardinality, Content> {\n\treturn new Join(options, defaultContent, store)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\n\nimport { createRegularAtom, createSelector } from \"atom.io/internal\"\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\n\nexport function struct<\n\tStruct extends { [key: string]: unknown },\n\tKey extends string,\n>(\n\toptions: {\n\t\tkey: Key\n\t\tdefault: Struct\n\t},\n\tstore: Store = IMPLICIT.STORE,\n): [\n\t{\n\t\t[K in keyof Struct as `${Key}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.AtomToken<Struct[K]>\n\t},\n\tAtomIO.ReadonlySelectorToken<Struct>,\n] {\n\tconst atoms: {\n\t\t[K in keyof Struct as `${Key}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.AtomToken<Struct[K]>\n\t} = Object.keys(options.default).reduce((acc, key) => {\n\t\tconst atomName = options.key + capitalize(key) + `State`\n\t\tacc[atomName] = createRegularAtom(\n\t\t\t{\n\t\t\t\tkey: `${options.key}.${key}`,\n\t\t\t\tdefault: options.default[key],\n\t\t\t},\n\t\t\tundefined,\n\t\t\tstore,\n\t\t)\n\t\treturn acc\n\t}, {} as any)\n\tconst structState = createSelector(\n\t\t{\n\t\t\tkey: options.key,\n\t\t\tget: ({ get }) => {\n\t\t\t\treturn Object.keys(options.default).reduce((acc, key) => {\n\t\t\t\t\tacc[key] = get(atoms[options.key + capitalize(key) + `State`])\n\t\t\t\t\treturn acc\n\t\t\t\t}, {} as any)\n\t\t\t},\n\t\t},\n\t\tundefined,\n\t\tstore,\n\t)\n\treturn [atoms, structState]\n}\n","import type * as AtomIO from \"atom.io\"\nimport {\n\tIMPLICIT,\n\tcreateRegularAtomFamily,\n\tcreateSelectorFamily,\n} from \"atom.io/internal\"\n\nconst capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)\nconst nameFamily = (topKey: string, subKey: string) =>\n\t`find` + capitalize(topKey) + capitalize(subKey) + `State`\n\nexport function structFamily<\n\tStruct extends object,\n\tKey extends string,\n>(options: {\n\tkey: Key\n\tdefault: Struct\n}): [\n\t{\n\t\t[K in keyof Struct as `find${Capitalize<Key & string>}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.AtomFamily<Struct[K], string>\n\t},\n\tAtomIO.ReadonlySelectorFamily<Struct>,\n] {\n\tconst atoms: {\n\t\t[K in keyof Struct as `find${Capitalize<Key & string>}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.AtomFamily<Struct[K], string>\n\t} = Object.keys(options.default).reduce((acc, subKey) => {\n\t\tconst atomFamilyName = nameFamily(options.key, subKey)\n\t\tacc[atomFamilyName] = createRegularAtomFamily(\n\t\t\t{\n\t\t\t\tkey: `${options.key}.${subKey}`,\n\t\t\t\tdefault: (options.default as any)[subKey],\n\t\t\t},\n\t\t\tIMPLICIT.STORE,\n\t\t)\n\t\treturn acc\n\t}, {} as any)\n\tconst findStructState = createSelectorFamily(\n\t\t{\n\t\t\tkey: options.key,\n\t\t\tget:\n\t\t\t\t(id) =>\n\t\t\t\t({ get }) => {\n\t\t\t\t\treturn Object.keys(options.default).reduce((acc, subKey) => {\n\t\t\t\t\t\tacc[subKey] = get(\n\t\t\t\t\t\t\t(atoms as any)[nameFamily(options.key, subKey)](id),\n\t\t\t\t\t\t)\n\t\t\t\t\t\treturn acc\n\t\t\t\t\t}, {} as any)\n\t\t\t\t},\n\t\t},\n\t\tIMPLICIT.STORE,\n\t)\n\treturn [atoms, findStructState]\n}\n","export type Loadable<T> = Promise<T> | T\nexport type Fated<T, E extends Error = Error> = Loadable<E | T>\n\n/**\n * Utility for handling loadable values\n * @param loadable Loadable value\n * @param fallback Fallback value until Loadable is resolved\n * @returns Fallback value if your loadable is a promise, otherwise the loadable's resolved value\n */\nexport function until<T>(loadable: Loadable<T>, fallback: T): T {\n\tif (loadable instanceof Promise) {\n\t\treturn fallback\n\t}\n\treturn loadable\n}\n"]}