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