atom.io 0.31.1 → 0.32.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 (155) hide show
  1. package/data/dist/index.d.ts +867 -101
  2. package/data/dist/index.js +10 -558
  3. package/data/src/index.ts +0 -2
  4. package/data/src/struct-family.ts +1 -1
  5. package/data/src/struct.ts +1 -2
  6. package/dist/chunk-354XQWHH.js +153 -0
  7. package/dist/chunk-4LWKCEW3.js +14 -0
  8. package/dist/chunk-5F2V7S3B.js +83 -0
  9. package/dist/chunk-ECOMOMUN.js +631 -0
  10. package/dist/{chunk-Y5MBNTVU.js → chunk-GY2XQYZY.js} +1791 -703
  11. package/dist/chunk-NF7FJKJD.js +107 -0
  12. package/dist/chunk-R3ZUK5EH.js +1024 -0
  13. package/dist/chunk-Z2UJW4NQ.js +523 -0
  14. package/dist/index.d.ts +622 -26
  15. package/dist/index.js +1 -228
  16. package/eslint-plugin/dist/index.d.ts +1 -30
  17. package/eslint-plugin/dist/index.js +0 -146
  18. package/eslint-plugin/src/index.ts +0 -1
  19. package/eslint-plugin/src/rules/index.ts +0 -1
  20. package/internal/dist/index.d.ts +783 -64
  21. package/internal/dist/index.js +1 -1
  22. package/internal/src/atom/create-regular-atom.ts +3 -3
  23. package/internal/src/atom/dispose-atom.ts +4 -13
  24. package/internal/src/atom/is-default.ts +3 -3
  25. package/internal/src/caching.ts +5 -5
  26. package/internal/src/capitalize.ts +3 -0
  27. package/internal/src/families/create-readonly-selector-family.ts +5 -6
  28. package/internal/src/families/create-writable-selector-family.ts +1 -4
  29. package/internal/src/families/dispose-from-store.ts +3 -13
  30. package/internal/src/get-state/get-from-store.ts +2 -2
  31. package/internal/src/get-state/read-or-compute-value.ts +1 -1
  32. package/internal/src/index.ts +2 -0
  33. package/internal/src/install-into-store.ts +1 -1
  34. package/internal/src/join/edit-relations-in-store.ts +32 -0
  35. package/internal/src/join/find-relations-in-store.ts +124 -0
  36. package/internal/src/join/get-internal-relations-from-store.ts +14 -0
  37. package/internal/src/join/get-join.ts +31 -0
  38. package/internal/src/join/index.ts +5 -0
  39. package/{data/src/join.ts → internal/src/join/join-internal.ts} +20 -429
  40. package/internal/src/keys.ts +7 -7
  41. package/internal/src/mutable/create-mutable-atom-family.ts +1 -1
  42. package/internal/src/mutable/create-mutable-atom.ts +3 -3
  43. package/internal/src/mutable/get-json-token.ts +1 -1
  44. package/internal/src/mutable/tracker-family.ts +19 -17
  45. package/internal/src/mutable/tracker.ts +8 -8
  46. package/internal/src/pretty-print.ts +1 -1
  47. package/internal/src/selector/create-readonly-selector.ts +3 -7
  48. package/internal/src/selector/create-writable-selector.ts +4 -4
  49. package/internal/src/selector/dispose-selector.ts +20 -11
  50. package/internal/src/selector/get-selector-dependency-keys.ts +1 -1
  51. package/internal/src/selector/register-selector.ts +6 -9
  52. package/internal/src/selector/trace-selector-atoms.ts +2 -2
  53. package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
  54. package/internal/src/set-state/emit-update.ts +1 -1
  55. package/internal/src/set-state/evict-downstream.ts +1 -1
  56. package/internal/src/set-state/set-atom-or-selector.ts +1 -1
  57. package/internal/src/set-state/set-atom.ts +10 -10
  58. package/internal/src/set-state/set-into-store.ts +2 -2
  59. package/internal/src/set-state/stow-update.ts +1 -1
  60. package/internal/src/store/store.ts +1 -1
  61. package/internal/src/store/withdraw.ts +22 -22
  62. package/internal/src/subscribe/recall-state.ts +1 -1
  63. package/internal/src/subscribe/subscribe-in-store.ts +3 -3
  64. package/internal/src/subscribe/subscribe-to-root-atoms.ts +3 -3
  65. package/internal/src/subscribe/subscribe-to-state.ts +5 -5
  66. package/internal/src/subscribe/subscribe-to-timeline.ts +3 -3
  67. package/internal/src/subscribe/subscribe-to-transaction.ts +3 -3
  68. package/internal/src/timeline/create-timeline.ts +17 -37
  69. package/internal/src/transaction/act-upon-store.ts +2 -2
  70. package/internal/src/transaction/apply-transaction.ts +5 -5
  71. package/internal/src/transaction/assign-transaction-to-continuity.ts +1 -1
  72. package/internal/src/transaction/build-transaction.ts +5 -8
  73. package/internal/src/transaction/create-transaction.ts +3 -3
  74. package/internal/src/transaction/get-epoch-number.ts +3 -3
  75. package/internal/src/transaction/set-epoch-number.ts +2 -2
  76. package/introspection/dist/index.d.ts +922 -6
  77. package/introspection/dist/index.js +2 -620
  78. package/json/dist/index.d.ts +899 -5
  79. package/json/dist/index.js +1 -80
  80. package/json/src/select-json-family.ts +3 -14
  81. package/package.json +24 -42
  82. package/react/dist/index.d.ts +921 -3
  83. package/react/dist/index.js +2 -82
  84. package/react/src/use-o.ts +1 -1
  85. package/react/src/use-tl.ts +2 -2
  86. package/react-devtools/dist/index.css +16 -14
  87. package/react-devtools/dist/index.d.ts +26 -1
  88. package/react-devtools/dist/index.js +6 -6
  89. package/react-devtools/src/devtools.scss +16 -14
  90. package/realtime/dist/index.d.ts +202 -8
  91. package/realtime/dist/index.js +2 -107
  92. package/realtime/src/realtime-continuity.ts +2 -2
  93. package/realtime/src/shared-room-store.ts +1 -2
  94. package/realtime-client/dist/index.d.ts +960 -22
  95. package/realtime-client/dist/index.js +3 -509
  96. package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +3 -3
  97. package/realtime-client/src/continuity/use-conceal-state.ts +1 -1
  98. package/realtime-client/src/pull-atom-family-member.ts +2 -2
  99. package/realtime-client/src/pull-atom.ts +2 -2
  100. package/realtime-client/src/pull-mutable-atom-family-member.ts +2 -2
  101. package/realtime-client/src/pull-mutable-atom.ts +2 -2
  102. package/realtime-client/src/pull-selector-family-member.ts +4 -4
  103. package/realtime-client/src/pull-selector.ts +4 -4
  104. package/realtime-client/src/push-state.ts +5 -10
  105. package/realtime-client/src/server-action.ts +4 -4
  106. package/realtime-client/src/sync-continuity.ts +6 -6
  107. package/realtime-react/dist/index.d.ts +166 -12
  108. package/realtime-react/dist/index.js +5 -154
  109. package/realtime-react/src/use-pull-atom-family-member.ts +1 -1
  110. package/realtime-react/src/use-pull-atom.ts +1 -1
  111. package/realtime-react/src/use-pull-mutable-atom.ts +1 -1
  112. package/realtime-react/src/use-pull-mutable-family-member.ts +1 -1
  113. package/realtime-react/src/use-pull-selector-family-member.ts +1 -1
  114. package/realtime-react/src/use-pull-selector.ts +1 -1
  115. package/realtime-react/src/use-push.ts +1 -1
  116. package/realtime-react/src/use-server-action.ts +2 -2
  117. package/realtime-react/src/use-sync-continuity.ts +1 -1
  118. package/realtime-server/dist/index.d.ts +971 -28
  119. package/realtime-server/dist/index.js +3 -1001
  120. package/realtime-server/src/continuity/prepare-to-serve-transaction-request.ts +1 -1
  121. package/realtime-server/src/continuity/prepare-to-sync-realtime-continuity.ts +3 -3
  122. package/realtime-server/src/continuity/subscribe-to-continuity-actions.ts +2 -2
  123. package/realtime-server/src/continuity/subscribe-to-continuity-perpectives.ts +2 -2
  124. package/realtime-server/src/realtime-action-receiver.ts +1 -1
  125. package/realtime-server/src/realtime-family-provider.ts +2 -2
  126. package/realtime-server/src/realtime-mutable-family-provider.ts +2 -2
  127. package/realtime-server/src/realtime-mutable-provider.ts +2 -2
  128. package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +2 -1
  129. package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +1 -1
  130. package/realtime-server/src/realtime-server-stores/server-user-store.ts +1 -2
  131. package/realtime-server/src/realtime-state-provider.ts +2 -2
  132. package/realtime-testing/dist/index.d.ts +1091 -3
  133. package/realtime-testing/dist/index.js +20 -22
  134. package/realtime-testing/src/setup-realtime-test.tsx +2 -1
  135. package/src/index.ts +4 -0
  136. package/src/join.ts +218 -0
  137. package/src/silo.ts +4 -4
  138. package/src/timeline.ts +1 -1
  139. package/src/transaction.ts +4 -8
  140. package/transceivers/set-rtx/dist/index.d.ts +37 -2
  141. package/transceivers/set-rtx/dist/index.js +1 -215
  142. package/web/dist/index.d.ts +30 -1
  143. package/web/dist/index.js +1 -15
  144. package/data/src/until.ts +0 -15
  145. package/ephemeral/dist/index.d.ts +0 -67
  146. package/ephemeral/dist/index.js +0 -9
  147. package/ephemeral/package.json +0 -13
  148. package/ephemeral/src/index.ts +0 -1
  149. package/eslint-plugin/src/rules/lifespan.ts +0 -203
  150. package/immortal/dist/index.d.ts +0 -12
  151. package/immortal/dist/index.js +0 -9
  152. package/immortal/package.json +0 -13
  153. package/immortal/src/index.ts +0 -1
  154. package/immortal/src/seek-state.ts +0 -60
  155. /package/{ephemeral/src → src}/find-state.ts +0 -0
@@ -1,9 +1,7 @@
1
+ import { createStandaloneSelector, findInStore, IMPLICIT, capitalize, createRegularAtom, createRegularAtomFamily, createSelectorFamily } from '../../dist/chunk-GY2XQYZY.js';
1
2
  import '../../dist/chunk-XWL6SNVU.js';
2
- import { createStandaloneSelector, findInStore, IMPLICIT, getFromStore, setIntoStore, seekInStore, getJsonToken, createMutableAtomFamily, createRegularAtomFamily, Junction, newest, isChildStore, createRegularAtom, createSelectorFamily, createReadonlySelectorFamily, getJsonFamily } from 'atom.io/internal';
3
- import { Anarchy } from 'atom.io';
4
- import { stringifyJson } from 'atom.io/json';
5
- import { SetRTX } from 'atom.io/transceivers/set-rtx';
6
3
 
4
+ // data/src/dict.ts
7
5
  function dict(family, index, store = IMPLICIT.STORE) {
8
6
  return createStandaloneSelector(store, {
9
7
  key: `${family.key}Dict`,
@@ -16,550 +14,11 @@ function dict(family, index, store = IMPLICIT.STORE) {
16
14
  }
17
15
  });
18
16
  }
19
- function capitalize(string) {
20
- return string[0].toUpperCase() + string.slice(1);
21
- }
22
- var Join = class {
23
- toolkit;
24
- options;
25
- defaultContent;
26
- molecules = /* @__PURE__ */ new Map();
27
- relations;
28
- states;
29
- core;
30
- transact(toolkit, run) {
31
- const originalToolkit = this.toolkit;
32
- this.toolkit = toolkit;
33
- run(this);
34
- this.toolkit = originalToolkit;
35
- }
36
- store;
37
- realm;
38
- [Symbol.dispose]() {
39
- }
40
- constructor(options, defaultContent, store = IMPLICIT.STORE) {
41
- this.store = store;
42
- this.realm = new Anarchy(store);
43
- this.options = options;
44
- this.defaultContent = defaultContent;
45
- this.store.miscResources.set(`join:${options.key}`, this);
46
- this.realm.allocate(`root`, options.key);
47
- this.toolkit = {
48
- get: (...ps) => getFromStore(store, ...ps),
49
- set: (...ps) => {
50
- setIntoStore(store, ...ps);
51
- },
52
- find: (...ps) => findInStore(store, ...ps),
53
- seek: (...ps) => seekInStore(store, ...ps),
54
- json: (token) => getJsonToken(store, token)
55
- };
56
- const aSide = options.between[0];
57
- const bSide = options.between[1];
58
- const relatedKeysAtoms = createMutableAtomFamily(
59
- store,
60
- {
61
- key: `${options.key}/relatedKeys`,
62
- default: () => new SetRTX(),
63
- mutable: true,
64
- fromJson: (json) => SetRTX.fromJSON(json),
65
- toJson: (set) => set.toJSON()
66
- },
67
- [`join`, `relations`]
68
- );
69
- this.core = { relatedKeysAtoms };
70
- const getRelatedKeys = ({ get }, key) => get(relatedKeysAtoms, key);
71
- const addRelation = ({ set }, a, b) => {
72
- if (!this.store.molecules.has(stringifyJson(a))) {
73
- this.realm.allocate(options.key, a);
74
- }
75
- set(relatedKeysAtoms, a, (aKeys) => aKeys.add(b));
76
- set(relatedKeysAtoms, b, (bKeys) => bKeys.add(a));
77
- };
78
- const deleteRelation = ({ set }, a, b) => {
79
- set(relatedKeysAtoms, a, (aKeys) => {
80
- aKeys.delete(b);
81
- return aKeys;
82
- });
83
- set(relatedKeysAtoms, b, (bKeys) => {
84
- bKeys.delete(a);
85
- return bKeys;
86
- });
87
- };
88
- const replaceRelationsSafely = (toolkit, a, newRelationsOfA) => {
89
- const { find, get, set } = toolkit;
90
- const relationsOfAState = find(relatedKeysAtoms, a);
91
- const currentRelationsOfA = get(relationsOfAState);
92
- for (const currentRelationB of currentRelationsOfA) {
93
- const remainsRelated = newRelationsOfA.includes(currentRelationB);
94
- if (remainsRelated) {
95
- continue;
96
- }
97
- set(relatedKeysAtoms, currentRelationB, (relationsOfB) => {
98
- relationsOfB.delete(a);
99
- return relationsOfB;
100
- });
101
- }
102
- set(relationsOfAState, (relationsOfA) => {
103
- relationsOfA.transaction((nextRelationsOfA) => {
104
- nextRelationsOfA.clear();
105
- for (const newRelationB of newRelationsOfA) {
106
- const relationsOfB = getRelatedKeys(toolkit, newRelationB);
107
- const newRelationBIsAlreadyRelated = relationsOfB.has(a);
108
- if (this.relations.cardinality === `1:n`) {
109
- const previousOwnersToDispose = [];
110
- for (const previousOwner of relationsOfB) {
111
- if (previousOwner === a) {
112
- continue;
113
- }
114
- const previousOwnerRelations = getRelatedKeys(
115
- toolkit,
116
- previousOwner
117
- );
118
- previousOwnerRelations.delete(newRelationB);
119
- if (previousOwnerRelations.size === 0) {
120
- previousOwnersToDispose.push(previousOwner);
121
- }
122
- }
123
- if (!newRelationBIsAlreadyRelated && relationsOfB.size > 0) {
124
- relationsOfB.clear();
125
- }
126
- for (const previousOwner of previousOwnersToDispose) {
127
- const sorted = [newRelationB, previousOwner].sort();
128
- const compositeKey = `"${sorted[0]}:${sorted[1]}"`;
129
- this.molecules.delete(compositeKey);
130
- }
131
- }
132
- if (!newRelationBIsAlreadyRelated) {
133
- relationsOfB.add(a);
134
- }
135
- nextRelationsOfA.add(newRelationB);
136
- }
137
- return true;
138
- });
139
- return relationsOfA;
140
- });
141
- };
142
- const replaceRelationsUnsafely = (toolkit, a, newRelationsOfA) => {
143
- const { set } = toolkit;
144
- set(relatedKeysAtoms, a, (relationsOfA) => {
145
- relationsOfA.transaction((nextRelationsOfA) => {
146
- for (const newRelationB of newRelationsOfA) {
147
- nextRelationsOfA.add(newRelationB);
148
- }
149
- return true;
150
- });
151
- return relationsOfA;
152
- });
153
- for (const newRelationB of newRelationsOfA) {
154
- set(relatedKeysAtoms, newRelationB, (newRelationsB) => {
155
- newRelationsB.add(a);
156
- return newRelationsB;
157
- });
158
- }
159
- return true;
160
- };
161
- const has = (toolkit, a, b) => {
162
- const aKeys = getRelatedKeys(toolkit, a);
163
- return b ? aKeys.has(b) : aKeys.size > 0;
164
- };
165
- const baseExternalStoreConfiguration = {
166
- getRelatedKeys: (key) => getRelatedKeys(this.toolkit, key),
167
- addRelation: (a, b) => {
168
- this.store.moleculeJoins.set(
169
- a,
170
- options.key
171
- );
172
- this.store.moleculeJoins.set(
173
- b,
174
- options.key
175
- );
176
- addRelation(this.toolkit, a, b);
177
- },
178
- deleteRelation: (a, b) => {
179
- deleteRelation(this.toolkit, a, b);
180
- },
181
- replaceRelationsSafely: (a, bs) => {
182
- replaceRelationsSafely(this.toolkit, a, bs);
183
- },
184
- replaceRelationsUnsafely: (a, bs) => {
185
- replaceRelationsUnsafely(this.toolkit, a, bs);
186
- },
187
- has: (a, b) => has(this.toolkit, a, b)
188
- };
189
- let externalStore;
190
- let contentAtoms;
191
- if (defaultContent) {
192
- contentAtoms = createRegularAtomFamily(
193
- store,
194
- {
195
- key: `${options.key}/content`,
196
- default: defaultContent
197
- },
198
- [`join`, `content`]
199
- );
200
- const getContent = ({ get }, key) => get(contentAtoms, key);
201
- const setContent = ({ set }, key, content) => {
202
- set(contentAtoms, key, content);
203
- };
204
- const externalStoreWithContentConfiguration = {
205
- getContent: (contentKey) => {
206
- const content = getContent(this.toolkit, contentKey);
207
- return content;
208
- },
209
- setContent: (contentKey, content) => {
210
- setContent(this.toolkit, contentKey, content);
211
- },
212
- deleteContent: (contentKey) => {
213
- this.realm.deallocate(contentKey);
214
- }
215
- };
216
- externalStore = Object.assign(
217
- baseExternalStoreConfiguration,
218
- externalStoreWithContentConfiguration
219
- );
220
- } else {
221
- externalStore = baseExternalStoreConfiguration;
222
- }
223
- const relations = new Junction(
224
- options,
225
- {
226
- externalStore,
227
- isAType: options.isAType,
228
- isBType: options.isBType,
229
- makeContentKey: (...args) => {
230
- const [a, b] = args;
231
- const sorted = args.sort();
232
- const compositeKey = `${sorted[0]}:${sorted[1]}`;
233
- const aMolecule = store.molecules.get(stringifyJson(a));
234
- const bMolecule = store.molecules.get(stringifyJson(b));
235
- if (!aMolecule) {
236
- this.realm.allocate(options.key, a);
237
- }
238
- if (!bMolecule) {
239
- this.realm.allocate(options.key, b);
240
- }
241
- this.realm.allocate(a, compositeKey, `all`);
242
- this.realm.claim(b, compositeKey);
243
- this.store.moleculeJoins.set(compositeKey, options.key);
244
- return compositeKey;
245
- }
246
- }
247
- );
248
- const createSingleKeySelectorFamily = () => createReadonlySelectorFamily(
249
- store,
250
- {
251
- key: `${options.key}/singleRelatedKey`,
252
- get: (key) => ({ get }) => {
253
- const relatedKeys = get(relatedKeysAtoms, key);
254
- for (const relatedKey of relatedKeys) {
255
- return relatedKey;
256
- }
257
- return null;
258
- }
259
- },
260
- [`join`, `keys`]
261
- );
262
- const getMultipleKeySelectorFamily = () => {
263
- return createReadonlySelectorFamily(
264
- store,
265
- {
266
- key: `${options.key}/multipleRelatedKeys`,
267
- get: (key) => ({ get }) => {
268
- const jsonFamily = getJsonFamily(relatedKeysAtoms, store);
269
- const json = get(jsonFamily, key);
270
- return json.members;
271
- }
272
- },
273
- [`join`, `keys`]
274
- );
275
- };
276
- const createSingleEntrySelectorFamily = () => createReadonlySelectorFamily(
277
- store,
278
- {
279
- key: `${options.key}/singleRelatedEntry`,
280
- get: (x) => ({ get }) => {
281
- const relatedKeys = get(relatedKeysAtoms, x);
282
- for (const y of relatedKeys) {
283
- let a = relations.isAType?.(x) ? x : undefined;
284
- let b = a === undefined ? x : undefined;
285
- a ??= y;
286
- b ??= y;
287
- const contentKey = relations.makeContentKey(a, b);
288
- const content = get(contentAtoms, contentKey);
289
- return [y, content];
290
- }
291
- return null;
292
- }
293
- },
294
- [`join`, `entries`]
295
- );
296
- const getMultipleEntrySelectorFamily = () => createReadonlySelectorFamily(
297
- store,
298
- {
299
- key: `${options.key}/multipleRelatedEntries`,
300
- get: (x) => ({ get }) => {
301
- const jsonFamily = getJsonFamily(relatedKeysAtoms, store);
302
- const json = get(jsonFamily, x);
303
- return json.members.map((y) => {
304
- let a = relations.isAType?.(x) ? x : undefined;
305
- let b = a === undefined ? x : undefined;
306
- a ??= y;
307
- b ??= y;
308
- const contentKey = relations.makeContentKey(a, b);
309
- const content = get(contentAtoms, contentKey);
310
- return [y, content];
311
- });
312
- }
313
- },
314
- [`join`, `entries`]
315
- );
316
- switch (options.cardinality) {
317
- case `1:1`: {
318
- const singleRelatedKeySelectors = createSingleKeySelectorFamily();
319
- const stateKeyA = `${aSide}KeyOf${capitalize(bSide)}`;
320
- const stateKeyB = `${bSide}KeyOf${capitalize(aSide)}`;
321
- const baseStates = {
322
- [stateKeyA]: singleRelatedKeySelectors,
323
- [stateKeyB]: singleRelatedKeySelectors
324
- };
325
- let states;
326
- if (defaultContent) {
327
- const singleEntrySelectors = createSingleEntrySelectorFamily();
328
- const entriesStateKeyA = `${aSide}EntryOf${capitalize(bSide)}`;
329
- const entriesStateKeyB = `${bSide}EntryOf${capitalize(aSide)}`;
330
- const contentStates = {
331
- [entriesStateKeyA]: singleEntrySelectors,
332
- [entriesStateKeyB]: singleEntrySelectors
333
- };
334
- states = Object.assign(baseStates, contentStates);
335
- } else {
336
- states = baseStates;
337
- }
338
- this.relations = relations;
339
- this.states = states;
340
- break;
341
- }
342
- case `1:n`: {
343
- const singleRelatedKeySelectors = createSingleKeySelectorFamily();
344
- const multipleRelatedKeysSelectors = getMultipleKeySelectorFamily();
345
- const stateKeyA = `${aSide}KeyOf${capitalize(bSide)}`;
346
- const stateKeyB = `${bSide}KeysOf${capitalize(aSide)}`;
347
- const baseStates = {
348
- [stateKeyA]: singleRelatedKeySelectors,
349
- [stateKeyB]: multipleRelatedKeysSelectors
350
- };
351
- let states;
352
- if (defaultContent) {
353
- const singleRelatedEntrySelectors = createSingleEntrySelectorFamily();
354
- const multipleRelatedEntriesSelectors = getMultipleEntrySelectorFamily();
355
- const entriesStateKeyA = `${aSide}EntryOf${capitalize(bSide)}`;
356
- const entriesStateKeyB = `${bSide}EntriesOf${capitalize(
357
- aSide
358
- )}`;
359
- const contentStates = {
360
- [entriesStateKeyA]: singleRelatedEntrySelectors,
361
- [entriesStateKeyB]: multipleRelatedEntriesSelectors
362
- };
363
- states = Object.assign(baseStates, contentStates);
364
- } else {
365
- states = baseStates;
366
- }
367
- this.relations = relations;
368
- this.states = states;
369
- break;
370
- }
371
- default: {
372
- const multipleRelatedKeysSelectors = getMultipleKeySelectorFamily();
373
- const stateKeyA = `${aSide}KeysOf${capitalize(bSide)}`;
374
- const stateKeyB = `${bSide}KeysOf${capitalize(aSide)}`;
375
- const baseStates = {
376
- [stateKeyA]: multipleRelatedKeysSelectors,
377
- [stateKeyB]: multipleRelatedKeysSelectors
378
- };
379
- let states;
380
- if (defaultContent) {
381
- const multipleRelatedEntriesSelectors = getMultipleEntrySelectorFamily();
382
- const entriesStateKeyA = `${aSide}EntriesOf${capitalize(
383
- bSide
384
- )}`;
385
- const entriesStateKeyB = `${bSide}EntriesOf${capitalize(
386
- aSide
387
- )}`;
388
- const contentStates = {
389
- [entriesStateKeyA]: multipleRelatedEntriesSelectors,
390
- [entriesStateKeyB]: multipleRelatedEntriesSelectors
391
- };
392
- states = Object.assign(baseStates, contentStates);
393
- } else {
394
- states = baseStates;
395
- }
396
- this.relations = relations;
397
- this.states = states;
398
- }
399
- }
400
- }
401
- };
402
- function join(options, defaultContent, store = IMPLICIT.STORE) {
403
- store.joins.set(options.key, new Join(options, defaultContent, store));
404
- const token = {
405
- key: options.key,
406
- type: `join`,
407
- a: options.between[0],
408
- b: options.between[1],
409
- cardinality: options.cardinality
410
- };
411
- return token;
412
- }
413
- function getJoin(token, store) {
414
- let myJoin = store.joins.get(token.key);
415
- if (myJoin === undefined) {
416
- const rootJoinMap = IMPLICIT.STORE.joins;
417
- const rootJoin = rootJoinMap.get(token.key);
418
- if (rootJoin === undefined) {
419
- throw new Error(
420
- `Join "${token.key}" not found in store "${store.config.name}"`
421
- );
422
- }
423
- myJoin = new Join(rootJoin.options, rootJoin.defaultContent, store);
424
- store.joins.set(token.key, myJoin);
425
- }
426
- return myJoin;
427
- }
428
- function findRelationsInStore(token, key, store) {
429
- const myJoin = getJoin(token, store);
430
- let relations;
431
- switch (token.cardinality) {
432
- case `1:1`: {
433
- const keyAB = `${token.a}KeyOf${capitalize(token.b)}`;
434
- const keyBA = `${token.b}KeyOf${capitalize(token.a)}`;
435
- relations = {
436
- get [keyAB]() {
437
- const familyAB = myJoin.states[keyAB];
438
- const state = findInStore(store, familyAB, key);
439
- return state;
440
- },
441
- get [keyBA]() {
442
- const familyBA = myJoin.states[keyBA];
443
- const state = findInStore(store, familyBA, key);
444
- return state;
445
- }
446
- };
447
- const entryAB = `${token.a}EntryOf${capitalize(token.b)}`;
448
- if (entryAB in myJoin.states) {
449
- const entryBA = `${token.b}EntryOf${capitalize(token.a)}`;
450
- Object.assign(relations, {
451
- get [entryAB]() {
452
- const familyAB = myJoin.states[entryAB];
453
- const state = findInStore(store, familyAB, key);
454
- return state;
455
- },
456
- get [entryBA]() {
457
- const familyBA = myJoin.states[entryBA];
458
- const state = findInStore(store, familyBA, key);
459
- return state;
460
- }
461
- });
462
- }
463
- break;
464
- }
465
- case `1:n`: {
466
- const keyAB = `${token.a}KeyOf${capitalize(token.b)}`;
467
- const keysBA = `${token.b}KeysOf${capitalize(token.a)}`;
468
- relations = {
469
- get [keyAB]() {
470
- const familyAB = myJoin.states[keyAB];
471
- const state = findInStore(store, familyAB, key);
472
- return state;
473
- },
474
- get [keysBA]() {
475
- const familyBA = myJoin.states[keysBA];
476
- const state = findInStore(store, familyBA, key);
477
- return state;
478
- }
479
- };
480
- const entryAB = `${token.a}EntryOf${capitalize(token.b)}`;
481
- if (entryAB in myJoin.states) {
482
- const entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`;
483
- Object.assign(relations, {
484
- get [entryAB]() {
485
- const familyAB = myJoin.states[entryAB];
486
- const state = findInStore(store, familyAB, key);
487
- return state;
488
- },
489
- get [entriesBA]() {
490
- const familyBA = myJoin.states[entriesBA];
491
- const state = findInStore(store, familyBA, key);
492
- return state;
493
- }
494
- });
495
- }
496
- break;
497
- }
498
- case `n:n`: {
499
- const keysAB = `${token.a}KeysOf${capitalize(token.b)}`;
500
- const keysBA = `${token.b}KeysOf${capitalize(token.a)}`;
501
- relations = {
502
- get [keysAB]() {
503
- const familyAB = myJoin.states[keysAB];
504
- const state = findInStore(store, familyAB, key);
505
- return state;
506
- },
507
- get [keysBA]() {
508
- const familyBA = myJoin.states[keysBA];
509
- const state = findInStore(store, familyBA, key);
510
- return state;
511
- }
512
- };
513
- const entriesAB = `${token.a}EntriesOf${capitalize(token.b)}`;
514
- if (entriesAB in myJoin.states) {
515
- const entriesBA = `${token.b}EntriesOf${capitalize(token.a)}`;
516
- Object.assign(relations, {
517
- get [entriesAB]() {
518
- const familyAB = myJoin.states[entriesAB];
519
- const state = findInStore(store, familyAB, key);
520
- return state;
521
- },
522
- get [entriesBA]() {
523
- const familyBA = myJoin.states[entriesBA];
524
- const state = findInStore(store, familyBA, key);
525
- return state;
526
- }
527
- });
528
- }
529
- }
530
- }
531
- return relations;
532
- }
533
- function findRelations(token, key) {
534
- return findRelationsInStore(token, key, IMPLICIT.STORE);
535
- }
536
- function editRelationsInStore(token, change, store) {
537
- const myJoin = getJoin(token, store);
538
- const target = newest(store);
539
- if (isChildStore(target)) {
540
- const { toolkit } = target.transactionMeta;
541
- myJoin.transact(toolkit, ({ relations }) => {
542
- change(relations);
543
- });
544
- } else {
545
- change(myJoin.relations);
546
- }
547
- }
548
- function editRelations(token, change) {
549
- editRelationsInStore(token, change, IMPLICIT.STORE);
550
- }
551
- function getInternalRelationsFromStore(token, store) {
552
- const myJoin = getJoin(token, store);
553
- const family = myJoin.core.relatedKeysAtoms;
554
- return family;
555
- }
556
- function getInternalRelations(token) {
557
- return getInternalRelationsFromStore(token, IMPLICIT.STORE);
558
- }
559
- var capitalize2 = (str) => str[0].toUpperCase() + str.slice(1);
17
+
18
+ // data/src/struct.ts
560
19
  function struct(options, store = IMPLICIT.STORE) {
561
20
  const atoms = Object.keys(options.default).reduce((acc, key) => {
562
- const atomName = options.key + capitalize2(key) + `State`;
21
+ const atomName = options.key + capitalize(key) + `State`;
563
22
  acc[atomName] = createRegularAtom(
564
23
  store,
565
24
  {
@@ -574,15 +33,16 @@ function struct(options, store = IMPLICIT.STORE) {
574
33
  key: options.key,
575
34
  get: ({ get }) => {
576
35
  return Object.keys(options.default).reduce((acc, key) => {
577
- acc[key] = get(atoms[options.key + capitalize2(key) + `State`]);
36
+ acc[key] = get(atoms[options.key + capitalize(key) + `State`]);
578
37
  return acc;
579
38
  }, {});
580
39
  }
581
40
  });
582
41
  return [atoms, structState];
583
42
  }
584
- var capitalize3 = (str) => str[0].toUpperCase() + str.slice(1);
585
- var nameFamily = (topKey, subKey) => `find` + capitalize3(topKey) + capitalize3(subKey) + `State`;
43
+
44
+ // data/src/struct-family.ts
45
+ var nameFamily = (topKey, subKey) => `find` + capitalize(topKey) + capitalize(subKey) + `State`;
586
46
  function structFamily(options) {
587
47
  const atoms = Object.keys(options.default).reduce((acc, subKey) => {
588
48
  const atomFamilyName = nameFamily(options.key, subKey);
@@ -606,12 +66,4 @@ function structFamily(options) {
606
66
  return [atoms, findStructState];
607
67
  }
608
68
 
609
- // data/src/until.ts
610
- function until(loadable, fallback) {
611
- if (loadable instanceof Promise) {
612
- return fallback;
613
- }
614
- return loadable;
615
- }
616
-
617
- export { Join, dict, editRelations, editRelationsInStore, findRelations, findRelationsInStore, getInternalRelations, getInternalRelationsFromStore, getJoin, join, struct, structFamily, until };
69
+ export { dict, struct, structFamily };
package/data/src/index.ts CHANGED
@@ -1,5 +1,3 @@
1
1
  export * from "./dict"
2
- export * from "./join"
3
2
  export * from "./struct"
4
3
  export * from "./struct-family"
5
- export * from "./until"
@@ -1,11 +1,11 @@
1
1
  import type * as AtomIO from "atom.io"
2
2
  import {
3
+ capitalize,
3
4
  createRegularAtomFamily,
4
5
  createSelectorFamily,
5
6
  IMPLICIT,
6
7
  } from "atom.io/internal"
7
8
 
8
- const capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)
9
9
  const nameFamily = (topKey: string, subKey: string) =>
10
10
  `find` + capitalize(topKey) + capitalize(subKey) + `State`
11
11
 
@@ -1,13 +1,12 @@
1
1
  import type * as AtomIO from "atom.io"
2
2
  import type { Store } from "atom.io/internal"
3
3
  import {
4
+ capitalize,
4
5
  createRegularAtom,
5
6
  createStandaloneSelector,
6
7
  IMPLICIT,
7
8
  } from "atom.io/internal"
8
9
 
9
- const capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)
10
-
11
10
  export function struct<
12
11
  Struct extends { [key: string]: unknown },
13
12
  Key extends string,