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.
- package/data/dist/index.d.ts +867 -101
- package/data/dist/index.js +10 -558
- package/data/src/index.ts +0 -2
- package/data/src/struct-family.ts +1 -1
- package/data/src/struct.ts +1 -2
- package/dist/chunk-354XQWHH.js +153 -0
- package/dist/chunk-4LWKCEW3.js +14 -0
- package/dist/chunk-5F2V7S3B.js +83 -0
- package/dist/chunk-ECOMOMUN.js +631 -0
- package/dist/{chunk-Y5MBNTVU.js → chunk-GY2XQYZY.js} +1791 -703
- package/dist/chunk-NF7FJKJD.js +107 -0
- package/dist/chunk-R3ZUK5EH.js +1024 -0
- package/dist/chunk-Z2UJW4NQ.js +523 -0
- package/dist/index.d.ts +622 -26
- package/dist/index.js +1 -228
- package/eslint-plugin/dist/index.d.ts +1 -30
- package/eslint-plugin/dist/index.js +0 -146
- package/eslint-plugin/src/index.ts +0 -1
- package/eslint-plugin/src/rules/index.ts +0 -1
- package/internal/dist/index.d.ts +783 -64
- package/internal/dist/index.js +1 -1
- package/internal/src/atom/create-regular-atom.ts +3 -3
- package/internal/src/atom/dispose-atom.ts +4 -13
- package/internal/src/atom/is-default.ts +3 -3
- package/internal/src/caching.ts +5 -5
- package/internal/src/capitalize.ts +3 -0
- package/internal/src/families/create-readonly-selector-family.ts +5 -6
- package/internal/src/families/create-writable-selector-family.ts +1 -4
- package/internal/src/families/dispose-from-store.ts +3 -13
- package/internal/src/get-state/get-from-store.ts +2 -2
- package/internal/src/get-state/read-or-compute-value.ts +1 -1
- package/internal/src/index.ts +2 -0
- package/internal/src/install-into-store.ts +1 -1
- package/internal/src/join/edit-relations-in-store.ts +32 -0
- package/internal/src/join/find-relations-in-store.ts +124 -0
- package/internal/src/join/get-internal-relations-from-store.ts +14 -0
- package/internal/src/join/get-join.ts +31 -0
- package/internal/src/join/index.ts +5 -0
- package/{data/src/join.ts → internal/src/join/join-internal.ts} +20 -429
- package/internal/src/keys.ts +7 -7
- package/internal/src/mutable/create-mutable-atom-family.ts +1 -1
- package/internal/src/mutable/create-mutable-atom.ts +3 -3
- package/internal/src/mutable/get-json-token.ts +1 -1
- package/internal/src/mutable/tracker-family.ts +19 -17
- package/internal/src/mutable/tracker.ts +8 -8
- package/internal/src/pretty-print.ts +1 -1
- package/internal/src/selector/create-readonly-selector.ts +3 -7
- package/internal/src/selector/create-writable-selector.ts +4 -4
- package/internal/src/selector/dispose-selector.ts +20 -11
- package/internal/src/selector/get-selector-dependency-keys.ts +1 -1
- package/internal/src/selector/register-selector.ts +6 -9
- package/internal/src/selector/trace-selector-atoms.ts +2 -2
- package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
- package/internal/src/set-state/emit-update.ts +1 -1
- package/internal/src/set-state/evict-downstream.ts +1 -1
- package/internal/src/set-state/set-atom-or-selector.ts +1 -1
- package/internal/src/set-state/set-atom.ts +10 -10
- package/internal/src/set-state/set-into-store.ts +2 -2
- package/internal/src/set-state/stow-update.ts +1 -1
- package/internal/src/store/store.ts +1 -1
- package/internal/src/store/withdraw.ts +22 -22
- package/internal/src/subscribe/recall-state.ts +1 -1
- package/internal/src/subscribe/subscribe-in-store.ts +3 -3
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +3 -3
- package/internal/src/subscribe/subscribe-to-state.ts +5 -5
- package/internal/src/subscribe/subscribe-to-timeline.ts +3 -3
- package/internal/src/subscribe/subscribe-to-transaction.ts +3 -3
- package/internal/src/timeline/create-timeline.ts +17 -37
- package/internal/src/transaction/act-upon-store.ts +2 -2
- package/internal/src/transaction/apply-transaction.ts +5 -5
- package/internal/src/transaction/assign-transaction-to-continuity.ts +1 -1
- package/internal/src/transaction/build-transaction.ts +5 -8
- package/internal/src/transaction/create-transaction.ts +3 -3
- package/internal/src/transaction/get-epoch-number.ts +3 -3
- package/internal/src/transaction/set-epoch-number.ts +2 -2
- package/introspection/dist/index.d.ts +922 -6
- package/introspection/dist/index.js +2 -620
- package/json/dist/index.d.ts +899 -5
- package/json/dist/index.js +1 -80
- package/json/src/select-json-family.ts +3 -14
- package/package.json +24 -42
- package/react/dist/index.d.ts +921 -3
- package/react/dist/index.js +2 -82
- package/react/src/use-o.ts +1 -1
- package/react/src/use-tl.ts +2 -2
- package/react-devtools/dist/index.css +16 -14
- package/react-devtools/dist/index.d.ts +26 -1
- package/react-devtools/dist/index.js +6 -6
- package/react-devtools/src/devtools.scss +16 -14
- package/realtime/dist/index.d.ts +202 -8
- package/realtime/dist/index.js +2 -107
- package/realtime/src/realtime-continuity.ts +2 -2
- package/realtime/src/shared-room-store.ts +1 -2
- package/realtime-client/dist/index.d.ts +960 -22
- package/realtime-client/dist/index.js +3 -509
- package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +3 -3
- package/realtime-client/src/continuity/use-conceal-state.ts +1 -1
- package/realtime-client/src/pull-atom-family-member.ts +2 -2
- package/realtime-client/src/pull-atom.ts +2 -2
- package/realtime-client/src/pull-mutable-atom-family-member.ts +2 -2
- package/realtime-client/src/pull-mutable-atom.ts +2 -2
- package/realtime-client/src/pull-selector-family-member.ts +4 -4
- package/realtime-client/src/pull-selector.ts +4 -4
- package/realtime-client/src/push-state.ts +5 -10
- package/realtime-client/src/server-action.ts +4 -4
- package/realtime-client/src/sync-continuity.ts +6 -6
- package/realtime-react/dist/index.d.ts +166 -12
- package/realtime-react/dist/index.js +5 -154
- package/realtime-react/src/use-pull-atom-family-member.ts +1 -1
- package/realtime-react/src/use-pull-atom.ts +1 -1
- package/realtime-react/src/use-pull-mutable-atom.ts +1 -1
- package/realtime-react/src/use-pull-mutable-family-member.ts +1 -1
- package/realtime-react/src/use-pull-selector-family-member.ts +1 -1
- package/realtime-react/src/use-pull-selector.ts +1 -1
- package/realtime-react/src/use-push.ts +1 -1
- package/realtime-react/src/use-server-action.ts +2 -2
- package/realtime-react/src/use-sync-continuity.ts +1 -1
- package/realtime-server/dist/index.d.ts +971 -28
- package/realtime-server/dist/index.js +3 -1001
- package/realtime-server/src/continuity/prepare-to-serve-transaction-request.ts +1 -1
- package/realtime-server/src/continuity/prepare-to-sync-realtime-continuity.ts +3 -3
- package/realtime-server/src/continuity/subscribe-to-continuity-actions.ts +2 -2
- package/realtime-server/src/continuity/subscribe-to-continuity-perpectives.ts +2 -2
- package/realtime-server/src/realtime-action-receiver.ts +1 -1
- package/realtime-server/src/realtime-family-provider.ts +2 -2
- package/realtime-server/src/realtime-mutable-family-provider.ts +2 -2
- package/realtime-server/src/realtime-mutable-provider.ts +2 -2
- package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +2 -1
- package/realtime-server/src/realtime-server-stores/server-room-external-store.ts +1 -1
- package/realtime-server/src/realtime-server-stores/server-user-store.ts +1 -2
- package/realtime-server/src/realtime-state-provider.ts +2 -2
- package/realtime-testing/dist/index.d.ts +1091 -3
- package/realtime-testing/dist/index.js +20 -22
- package/realtime-testing/src/setup-realtime-test.tsx +2 -1
- package/src/index.ts +4 -0
- package/src/join.ts +218 -0
- package/src/silo.ts +4 -4
- package/src/timeline.ts +1 -1
- package/src/transaction.ts +4 -8
- package/transceivers/set-rtx/dist/index.d.ts +37 -2
- package/transceivers/set-rtx/dist/index.js +1 -215
- package/web/dist/index.d.ts +30 -1
- package/web/dist/index.js +1 -15
- package/data/src/until.ts +0 -15
- package/ephemeral/dist/index.d.ts +0 -67
- package/ephemeral/dist/index.js +0 -9
- package/ephemeral/package.json +0 -13
- package/ephemeral/src/index.ts +0 -1
- package/eslint-plugin/src/rules/lifespan.ts +0 -203
- package/immortal/dist/index.d.ts +0 -12
- package/immortal/dist/index.js +0 -9
- package/immortal/package.json +0 -13
- package/immortal/src/index.ts +0 -1
- package/immortal/src/seek-state.ts +0 -60
- /package/{ephemeral/src → src}/find-state.ts +0 -0
package/data/dist/index.js
CHANGED
|
@@ -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
|
-
|
|
20
|
-
|
|
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 +
|
|
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 +
|
|
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
|
-
|
|
585
|
-
|
|
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
|
-
|
|
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,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
|
|
package/data/src/struct.ts
CHANGED
|
@@ -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,
|