atom.io 0.29.5 → 0.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/dist/index.d.ts +84 -51
- package/data/dist/index.js +35 -31
- package/data/src/join.ts +240 -134
- package/dist/chunk-ADMEAXYU.js +167 -0
- package/dist/{chunk-TCINPEYE.js → chunk-SMKF3ZNG.js} +221 -137
- package/dist/index.d.ts +75 -10
- package/dist/index.js +3 -17
- package/internal/dist/index.d.ts +76 -41
- package/internal/dist/index.js +2 -1
- package/internal/src/atom/dispose-atom.ts +4 -8
- package/internal/src/index.ts +1 -1
- package/internal/src/ingest-updates/ingest-creation-disposal.ts +71 -27
- package/internal/src/junction.ts +152 -84
- package/internal/src/molecule/create-molecule-family.ts +2 -2
- package/internal/src/molecule/dispose-molecule.ts +4 -2
- package/internal/src/molecule/make-molecule-in-store.ts +11 -9
- package/internal/src/molecule/molecule-internal.ts +12 -8
- package/internal/src/mutable/create-mutable-atom-family.ts +2 -2
- package/internal/src/mutable/get-json-family.ts +2 -2
- package/internal/src/store/store.ts +10 -2
- package/internal/src/timeline/create-timeline.ts +99 -71
- package/internal/src/transaction/index.ts +1 -1
- package/internal/src/utility-types.ts +9 -2
- package/json/dist/index.d.ts +3 -3
- package/json/dist/index.js +2 -1
- package/json/src/entries.ts +3 -3
- package/package.json +15 -15
- package/react-devtools/dist/index.js +9 -5
- package/react-devtools/src/TimelineIndex.tsx +4 -1
- package/react-devtools/src/Updates.tsx +18 -3
- package/realtime/dist/index.d.ts +1 -1
- package/realtime/dist/index.js +3 -1
- package/realtime/src/shared-room-store.ts +2 -0
- package/realtime-server/dist/index.d.ts +13 -4
- package/realtime-server/dist/index.js +4 -2
- package/realtime-server/src/realtime-continuity-synchronizer.ts +2 -2
- package/realtime-server/src/realtime-server-stores/server-user-store.ts +17 -1
- package/realtime-testing/dist/index.d.ts +3 -0
- package/realtime-testing/dist/index.js +11 -4
- package/realtime-testing/src/setup-realtime-test.tsx +12 -4
- package/src/allocate.ts +277 -0
- package/src/index.ts +1 -0
- package/src/molecule.ts +9 -5
- package/src/transaction.ts +22 -4
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { deallocateFromStore, allocateIntoStore } from './chunk-ADMEAXYU.js';
|
|
1
2
|
import { stringifyJson, parseJson, selectJson, selectJsonFamily } from 'atom.io/json';
|
|
2
3
|
import { AtomIOLogger } from 'atom.io';
|
|
3
4
|
import { getJoin, findRelations } from 'atom.io/data';
|
|
@@ -158,36 +159,36 @@ var Junction = class {
|
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
161
|
}
|
|
161
|
-
replaceRelationsUnsafely(
|
|
162
|
-
this.relations.set(
|
|
163
|
-
for (const
|
|
164
|
-
const
|
|
165
|
-
this.relations.set(
|
|
162
|
+
replaceRelationsUnsafely(x, ys) {
|
|
163
|
+
this.relations.set(x, new Set(ys));
|
|
164
|
+
for (const y of ys) {
|
|
165
|
+
const yRelations = (/* @__PURE__ */ new Set()).add(x);
|
|
166
|
+
this.relations.set(y, yRelations);
|
|
166
167
|
}
|
|
167
168
|
}
|
|
168
|
-
replaceRelationsSafely(
|
|
169
|
-
const
|
|
170
|
-
if (
|
|
171
|
-
for (const
|
|
172
|
-
const
|
|
173
|
-
if (
|
|
174
|
-
if (
|
|
175
|
-
this.relations.delete(
|
|
169
|
+
replaceRelationsSafely(x, ys) {
|
|
170
|
+
const xRelationsPrev = this.relations.get(x);
|
|
171
|
+
if (xRelationsPrev) {
|
|
172
|
+
for (const y of xRelationsPrev) {
|
|
173
|
+
const yRelations = this.relations.get(y);
|
|
174
|
+
if (yRelations) {
|
|
175
|
+
if (yRelations.size === 1) {
|
|
176
|
+
this.relations.delete(y);
|
|
176
177
|
} else {
|
|
177
|
-
|
|
178
|
+
yRelations.delete(x);
|
|
178
179
|
}
|
|
179
|
-
this.contents.delete(this.makeContentKey(
|
|
180
|
+
this.contents.delete(this.makeContentKey(x, y));
|
|
180
181
|
}
|
|
181
182
|
}
|
|
182
183
|
}
|
|
183
|
-
this.relations.set(
|
|
184
|
-
for (const
|
|
185
|
-
let
|
|
186
|
-
if (
|
|
187
|
-
|
|
184
|
+
this.relations.set(x, new Set(ys));
|
|
185
|
+
for (const y of ys) {
|
|
186
|
+
let yRelations = this.relations.get(y);
|
|
187
|
+
if (yRelations) {
|
|
188
|
+
yRelations.add(x);
|
|
188
189
|
} else {
|
|
189
|
-
|
|
190
|
-
this.relations.set(
|
|
190
|
+
yRelations = (/* @__PURE__ */ new Set()).add(x);
|
|
191
|
+
this.relations.set(y, yRelations);
|
|
191
192
|
}
|
|
192
193
|
}
|
|
193
194
|
}
|
|
@@ -205,7 +206,9 @@ var Junction = class {
|
|
|
205
206
|
this.b = data.between[1];
|
|
206
207
|
this.cardinality = data.cardinality;
|
|
207
208
|
if (!config?.externalStore) {
|
|
208
|
-
this.relations = new Map(
|
|
209
|
+
this.relations = new Map(
|
|
210
|
+
data.relations?.map(([x, ys]) => [x, new Set(ys)])
|
|
211
|
+
);
|
|
209
212
|
this.contents = new Map(data.contents);
|
|
210
213
|
}
|
|
211
214
|
this.isContent = config?.isContent ?? null;
|
|
@@ -227,7 +230,9 @@ var Junction = class {
|
|
|
227
230
|
this.replaceRelationsUnsafely = (a, bs) => {
|
|
228
231
|
externalStore.replaceRelationsUnsafely(a, bs);
|
|
229
232
|
};
|
|
230
|
-
this.getRelatedKeys = (key) => externalStore.getRelatedKeys(
|
|
233
|
+
this.getRelatedKeys = (key) => externalStore.getRelatedKeys(
|
|
234
|
+
key
|
|
235
|
+
);
|
|
231
236
|
if (externalStore.getContent) {
|
|
232
237
|
this.getContentInternal = (contentKey) => {
|
|
233
238
|
return externalStore.getContent(contentKey);
|
|
@@ -254,7 +259,9 @@ var Junction = class {
|
|
|
254
259
|
return {
|
|
255
260
|
between: [this.a, this.b],
|
|
256
261
|
cardinality: this.cardinality,
|
|
257
|
-
relations: [...this.relations.entries()].map(
|
|
262
|
+
relations: [...this.relations.entries()].map(
|
|
263
|
+
([a, b]) => [a, [...b]]
|
|
264
|
+
),
|
|
258
265
|
contents: [...this.contents.entries()]
|
|
259
266
|
};
|
|
260
267
|
}
|
|
@@ -266,7 +273,7 @@ var Junction = class {
|
|
|
266
273
|
// biome-ignore lint/suspicious/noFallthroughSwitchClause: perfect here
|
|
267
274
|
case `1:1`: {
|
|
268
275
|
const bPrev = this.getRelatedKey(a);
|
|
269
|
-
if (bPrev && bPrev !== b) this.delete(
|
|
276
|
+
if (bPrev && bPrev !== b) this.delete(a, bPrev);
|
|
270
277
|
}
|
|
271
278
|
case `1:n`: {
|
|
272
279
|
const aPrev = this.getRelatedKey(b);
|
|
@@ -282,7 +289,10 @@ var Junction = class {
|
|
|
282
289
|
}
|
|
283
290
|
delete(x, b) {
|
|
284
291
|
b = typeof b === `string` ? b : x[this.b];
|
|
285
|
-
const a =
|
|
292
|
+
const a = (
|
|
293
|
+
// @ts-expect-error we deduce that this.a may index x
|
|
294
|
+
typeof x === `string` ? x : x[this.a]
|
|
295
|
+
);
|
|
286
296
|
if (a === void 0 && typeof b === `string`) {
|
|
287
297
|
const bRelations = this.getRelatedKeys(b);
|
|
288
298
|
if (bRelations) {
|
|
@@ -321,18 +331,18 @@ var Junction = class {
|
|
|
321
331
|
}
|
|
322
332
|
}
|
|
323
333
|
}
|
|
324
|
-
replaceRelations(
|
|
334
|
+
replaceRelations(x, relations, config) {
|
|
325
335
|
const hasContent = !Array.isArray(relations);
|
|
326
|
-
const
|
|
336
|
+
const ys = hasContent ? Object.keys(relations) : relations;
|
|
327
337
|
if (config?.reckless) {
|
|
328
|
-
this.replaceRelationsUnsafely(
|
|
338
|
+
this.replaceRelationsUnsafely(x, ys);
|
|
329
339
|
} else {
|
|
330
|
-
this.replaceRelationsSafely(
|
|
340
|
+
this.replaceRelationsSafely(x, ys);
|
|
331
341
|
}
|
|
332
342
|
if (hasContent) {
|
|
333
|
-
for (const
|
|
334
|
-
const contentKey = this.makeContentKey(
|
|
335
|
-
const content = relations[
|
|
343
|
+
for (const y of ys) {
|
|
344
|
+
const contentKey = this.makeContentKey(x, y);
|
|
345
|
+
const content = relations[y];
|
|
336
346
|
this.setContent(contentKey, content);
|
|
337
347
|
}
|
|
338
348
|
}
|
|
@@ -1304,6 +1314,7 @@ function disposeMolecule(token, store) {
|
|
|
1304
1314
|
const Formula = withdraw(family, store);
|
|
1305
1315
|
const disposalEvent = {
|
|
1306
1316
|
type: `molecule_disposal`,
|
|
1317
|
+
subType: `classic`,
|
|
1307
1318
|
token,
|
|
1308
1319
|
family,
|
|
1309
1320
|
context,
|
|
@@ -1316,7 +1327,7 @@ function disposeMolecule(token, store) {
|
|
|
1316
1327
|
disposeFromStore(store, state);
|
|
1317
1328
|
}
|
|
1318
1329
|
for (const child of molecule.below.values()) {
|
|
1319
|
-
if (child.
|
|
1330
|
+
if (child.dependsOn === `all`) {
|
|
1320
1331
|
disposeMolecule(child, store);
|
|
1321
1332
|
} else {
|
|
1322
1333
|
child.above.delete(molecule.stringKey);
|
|
@@ -1380,20 +1391,24 @@ var Molecule = class {
|
|
|
1380
1391
|
this.stringKey = stringifyJson(key);
|
|
1381
1392
|
if (family) {
|
|
1382
1393
|
this.family = family;
|
|
1394
|
+
this._dependsOn = family.dependsOn;
|
|
1383
1395
|
}
|
|
1384
1396
|
if (ctx) {
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
this.above.set(molecule.stringKey, molecule);
|
|
1388
|
-
}
|
|
1389
|
-
} else {
|
|
1390
|
-
this.above.set(ctx.stringKey, ctx);
|
|
1397
|
+
for (const molecule of ctx) {
|
|
1398
|
+
this.above.set(molecule.stringKey, molecule);
|
|
1391
1399
|
}
|
|
1392
1400
|
}
|
|
1393
1401
|
}
|
|
1394
1402
|
type = `molecule`;
|
|
1395
1403
|
stringKey;
|
|
1396
1404
|
family;
|
|
1405
|
+
_dependsOn;
|
|
1406
|
+
get dependsOn() {
|
|
1407
|
+
if (this.family) {
|
|
1408
|
+
return this.family.dependsOn;
|
|
1409
|
+
}
|
|
1410
|
+
return this._dependsOn;
|
|
1411
|
+
}
|
|
1397
1412
|
subject = new Subject();
|
|
1398
1413
|
tokens = /* @__PURE__ */ new Map();
|
|
1399
1414
|
above = /* @__PURE__ */ new Map();
|
|
@@ -1452,9 +1467,11 @@ function makeMoleculeInStore(store, context, familyToken, key, ...params) {
|
|
|
1452
1467
|
const unsubFromFamily = family.subject.subscribe(
|
|
1453
1468
|
`join:${token2.key}-${stringKey}`,
|
|
1454
1469
|
(event) => {
|
|
1455
|
-
if (event.type === `molecule_disposal`
|
|
1456
|
-
|
|
1457
|
-
|
|
1470
|
+
if (event.type === `molecule_disposal`) {
|
|
1471
|
+
if (stringifyJson(event.token.key) === stringKey) {
|
|
1472
|
+
unsubFromFamily();
|
|
1473
|
+
join.molecules.delete(stringKey);
|
|
1474
|
+
}
|
|
1458
1475
|
}
|
|
1459
1476
|
}
|
|
1460
1477
|
);
|
|
@@ -1512,6 +1529,7 @@ function makeMoleculeInStore(store, context, familyToken, key, ...params) {
|
|
|
1512
1529
|
};
|
|
1513
1530
|
const update = {
|
|
1514
1531
|
type: `molecule_creation`,
|
|
1532
|
+
subType: `classic`,
|
|
1515
1533
|
token,
|
|
1516
1534
|
family: familyToken,
|
|
1517
1535
|
context: contextArray,
|
|
@@ -1758,41 +1776,83 @@ function createInStore(update, store) {
|
|
|
1758
1776
|
function ingestMoleculeCreationEvent(update, applying, store) {
|
|
1759
1777
|
switch (applying) {
|
|
1760
1778
|
case `newValue`:
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1779
|
+
switch (update.subType) {
|
|
1780
|
+
case `classic`:
|
|
1781
|
+
makeMoleculeInStore(
|
|
1782
|
+
store,
|
|
1783
|
+
update.context,
|
|
1784
|
+
update.family,
|
|
1785
|
+
update.token.key,
|
|
1786
|
+
...update.params
|
|
1787
|
+
);
|
|
1788
|
+
break;
|
|
1789
|
+
case `modern`:
|
|
1790
|
+
allocateIntoStore(store, update.provenance, update.key);
|
|
1791
|
+
break;
|
|
1792
|
+
}
|
|
1768
1793
|
break;
|
|
1769
1794
|
case `oldValue`:
|
|
1770
|
-
|
|
1795
|
+
switch (update.subType) {
|
|
1796
|
+
case `classic`:
|
|
1797
|
+
disposeFromStore(store, update.token);
|
|
1798
|
+
break;
|
|
1799
|
+
case `modern`:
|
|
1800
|
+
deallocateFromStore(store, update.key);
|
|
1801
|
+
break;
|
|
1802
|
+
}
|
|
1771
1803
|
break;
|
|
1772
1804
|
}
|
|
1773
1805
|
}
|
|
1774
1806
|
function ingestMoleculeDisposalEvent(update, applying, store) {
|
|
1775
1807
|
switch (applying) {
|
|
1776
1808
|
case `newValue`:
|
|
1777
|
-
|
|
1809
|
+
switch (update.subType) {
|
|
1810
|
+
case `classic`:
|
|
1811
|
+
disposeFromStore(store, update.token);
|
|
1812
|
+
break;
|
|
1813
|
+
case `modern`:
|
|
1814
|
+
deallocateFromStore(store, update.key);
|
|
1815
|
+
break;
|
|
1816
|
+
}
|
|
1778
1817
|
break;
|
|
1779
1818
|
case `oldValue`:
|
|
1780
1819
|
{
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1820
|
+
switch (update.subType) {
|
|
1821
|
+
case `classic`:
|
|
1822
|
+
{
|
|
1823
|
+
const moleculeToken = makeMoleculeInStore(
|
|
1824
|
+
store,
|
|
1825
|
+
update.context,
|
|
1826
|
+
update.family,
|
|
1827
|
+
update.token.key
|
|
1828
|
+
);
|
|
1829
|
+
for (const [familyKey, value] of update.values) {
|
|
1830
|
+
const memberKey = `${familyKey}(${stringifyJson(moleculeToken.key)})`;
|
|
1831
|
+
const molecule = withdraw(moleculeToken, store);
|
|
1832
|
+
const alreadyCreated = molecule.tokens.has(memberKey);
|
|
1833
|
+
const family = store.families.get(familyKey);
|
|
1834
|
+
if (family && !alreadyCreated) {
|
|
1835
|
+
growMoleculeInStore(molecule, family, store);
|
|
1836
|
+
}
|
|
1837
|
+
store.valueMap.set(memberKey, value);
|
|
1838
|
+
}
|
|
1839
|
+
}
|
|
1840
|
+
break;
|
|
1841
|
+
case `modern`: {
|
|
1842
|
+
allocateIntoStore(
|
|
1843
|
+
store,
|
|
1844
|
+
update.provenance,
|
|
1845
|
+
update.key
|
|
1846
|
+
);
|
|
1847
|
+
for (const [familyKey, value] of update.values) {
|
|
1848
|
+
const family = store.families.get(familyKey);
|
|
1849
|
+
if (family) {
|
|
1850
|
+
findInStore(store, family, update.key);
|
|
1851
|
+
const memberKey = `${familyKey}(${stringifyJson(update.key)})`;
|
|
1852
|
+
store.valueMap.set(memberKey, value);
|
|
1853
|
+
}
|
|
1854
|
+
}
|
|
1794
1855
|
}
|
|
1795
|
-
store.valueMap.set(memberKey, value);
|
|
1796
1856
|
}
|
|
1797
1857
|
}
|
|
1798
1858
|
break;
|
|
@@ -2976,7 +3036,7 @@ function disposeAtom(atomToken, store) {
|
|
|
2976
3036
|
target.valueMap.delete(key);
|
|
2977
3037
|
target.selectorAtoms.delete(key);
|
|
2978
3038
|
target.atomsThatAreDefault.delete(key);
|
|
2979
|
-
|
|
3039
|
+
store.timelineTopics.delete(key);
|
|
2980
3040
|
if (atomToken.type === `mutable_atom`) {
|
|
2981
3041
|
const updateToken = getUpdateToken(atomToken);
|
|
2982
3042
|
disposeAtom(updateToken, store);
|
|
@@ -3243,71 +3303,77 @@ function addMoleculeFamilyToTimeline(familyToken, tl, store) {
|
|
|
3243
3303
|
`got a molecule creation or disposal`,
|
|
3244
3304
|
creationOrDisposal
|
|
3245
3305
|
);
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
const molecule = withdraw(creationOrDisposal.token, store);
|
|
3268
|
-
for (const token of molecule.tokens.values()) {
|
|
3269
|
-
switch (token.type) {
|
|
3270
|
-
case `atom`:
|
|
3271
|
-
case `mutable_atom`:
|
|
3272
|
-
addAtomToTimeline(token, tl, store);
|
|
3273
|
-
break;
|
|
3306
|
+
if (creationOrDisposal.subType === `classic`) {
|
|
3307
|
+
switch (creationOrDisposal.type) {
|
|
3308
|
+
case `molecule_creation`:
|
|
3309
|
+
{
|
|
3310
|
+
store.timelineTopics.set(
|
|
3311
|
+
{
|
|
3312
|
+
topicKey: creationOrDisposal.token.key,
|
|
3313
|
+
timelineKey: tl.key
|
|
3314
|
+
},
|
|
3315
|
+
{ topicType: `molecule` }
|
|
3316
|
+
);
|
|
3317
|
+
const txUpdateInProgress = newest(store).on.transactionApplying.state?.update;
|
|
3318
|
+
if (txUpdateInProgress) {
|
|
3319
|
+
joinTransaction(tl, txUpdateInProgress, store);
|
|
3320
|
+
} else if (tl.timeTraveling === null) {
|
|
3321
|
+
const event = Object.assign(creationOrDisposal, {
|
|
3322
|
+
timestamp: Date.now()
|
|
3323
|
+
});
|
|
3324
|
+
tl.history.push(event);
|
|
3325
|
+
tl.at = tl.history.length;
|
|
3326
|
+
tl.subject.next(event);
|
|
3274
3327
|
}
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3328
|
+
const molecule = withdraw(creationOrDisposal.token, store);
|
|
3329
|
+
for (const token of molecule.tokens.values()) {
|
|
3330
|
+
switch (token.type) {
|
|
3331
|
+
case `atom`:
|
|
3332
|
+
case `mutable_atom`:
|
|
3333
|
+
addAtomToTimeline(token, tl, store);
|
|
3334
|
+
break;
|
|
3282
3335
|
}
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
tl.at = tl.history.length;
|
|
3298
|
-
tl.subject.next(event);
|
|
3336
|
+
}
|
|
3337
|
+
tl.subscriptions.set(
|
|
3338
|
+
molecule.key,
|
|
3339
|
+
molecule.subject.subscribe(
|
|
3340
|
+
`timeline:${tl.key}`,
|
|
3341
|
+
(stateCreationOrDisposal) => {
|
|
3342
|
+
handleStateLifecycleEvent(
|
|
3343
|
+
stateCreationOrDisposal,
|
|
3344
|
+
tl,
|
|
3345
|
+
store
|
|
3346
|
+
);
|
|
3347
|
+
}
|
|
3348
|
+
)
|
|
3349
|
+
);
|
|
3299
3350
|
}
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
tl.
|
|
3307
|
-
|
|
3351
|
+
break;
|
|
3352
|
+
case `molecule_disposal`:
|
|
3353
|
+
{
|
|
3354
|
+
const txUpdateInProgress = newest(store).on.transactionApplying.state?.update;
|
|
3355
|
+
if (txUpdateInProgress) {
|
|
3356
|
+
joinTransaction(tl, txUpdateInProgress, store);
|
|
3357
|
+
} else if (tl.timeTraveling === null) {
|
|
3358
|
+
const event = Object.assign(creationOrDisposal, {
|
|
3359
|
+
timestamp: Date.now()
|
|
3360
|
+
});
|
|
3361
|
+
tl.history.push(event);
|
|
3362
|
+
tl.at = tl.history.length;
|
|
3363
|
+
tl.subject.next(event);
|
|
3364
|
+
}
|
|
3365
|
+
const moleculeKey = stringifyJson(creationOrDisposal.token.key);
|
|
3366
|
+
tl.subscriptions.get(moleculeKey)?.();
|
|
3367
|
+
tl.subscriptions.delete(moleculeKey);
|
|
3368
|
+
for (const [familyKey] of creationOrDisposal.values) {
|
|
3369
|
+
const stateKey = `${familyKey}(${stringifyJson(moleculeKey)})`;
|
|
3370
|
+
tl.subscriptions.get(stateKey)?.();
|
|
3371
|
+
tl.subscriptions.delete(stateKey);
|
|
3372
|
+
store.timelineTopics.delete(stateKey);
|
|
3373
|
+
}
|
|
3308
3374
|
}
|
|
3309
|
-
|
|
3310
|
-
|
|
3375
|
+
break;
|
|
3376
|
+
}
|
|
3311
3377
|
}
|
|
3312
3378
|
})
|
|
3313
3379
|
);
|
|
@@ -3359,17 +3425,32 @@ function filterTransactionUpdates(updates, timelineTopics) {
|
|
|
3359
3425
|
return true;
|
|
3360
3426
|
}
|
|
3361
3427
|
let key;
|
|
3428
|
+
let familyKey;
|
|
3362
3429
|
switch (updateFromTx.type) {
|
|
3363
3430
|
case `state_creation`:
|
|
3364
3431
|
case `state_disposal`:
|
|
3432
|
+
key = updateFromTx.token.key;
|
|
3433
|
+
familyKey = updateFromTx.token.family?.key;
|
|
3434
|
+
break;
|
|
3365
3435
|
case `molecule_creation`:
|
|
3366
3436
|
case `molecule_disposal`:
|
|
3367
|
-
|
|
3437
|
+
switch (updateFromTx.subType) {
|
|
3438
|
+
case `classic`:
|
|
3439
|
+
key = updateFromTx.token.key;
|
|
3440
|
+
break;
|
|
3441
|
+
case `modern`:
|
|
3442
|
+
return true;
|
|
3443
|
+
}
|
|
3368
3444
|
break;
|
|
3369
3445
|
default:
|
|
3370
3446
|
key = updateFromTx.key;
|
|
3447
|
+
familyKey = updateFromTx.family?.key;
|
|
3371
3448
|
break;
|
|
3372
3449
|
}
|
|
3450
|
+
timelineTopics.has(key);
|
|
3451
|
+
if (familyKey && timelineTopics.has(familyKey)) {
|
|
3452
|
+
return true;
|
|
3453
|
+
}
|
|
3373
3454
|
return timelineTopics.has(key);
|
|
3374
3455
|
}).map((updateFromTx) => {
|
|
3375
3456
|
if (`updates` in updateFromTx) {
|
|
@@ -3390,13 +3471,16 @@ function handleStateLifecycleEvent(event, tl, store) {
|
|
|
3390
3471
|
timestamp
|
|
3391
3472
|
});
|
|
3392
3473
|
if (!tl.timeTraveling) {
|
|
3393
|
-
const
|
|
3394
|
-
if (
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3399
|
-
|
|
3474
|
+
const target = newest(store);
|
|
3475
|
+
if (isChildStore(target)) ; else {
|
|
3476
|
+
const txUpdateInProgress = target.on.transactionApplying.state;
|
|
3477
|
+
if (txUpdateInProgress) {
|
|
3478
|
+
joinTransaction(tl, txUpdateInProgress.update, store);
|
|
3479
|
+
} else {
|
|
3480
|
+
tl.history.push(timelineEvent);
|
|
3481
|
+
tl.at = tl.history.length;
|
|
3482
|
+
tl.subject.next(timelineEvent);
|
|
3483
|
+
}
|
|
3400
3484
|
}
|
|
3401
3485
|
}
|
|
3402
3486
|
switch (event.type) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Transceiver, Func, EnvironmentData, Flat, Subject, Store, Timeline, TimelineAtomUpdate, TimelineMoleculeCreation, TimelineMoleculeDisposal, TimelineSelectorUpdate, TimelineStateCreation, TimelineStateDisposal, TimelineTransactionUpdate } from 'atom.io/internal';
|
|
1
|
+
import { Transceiver, Func, EnvironmentData, Flat, Subject, Store, Each, Timeline, TimelineAtomUpdate, TimelineMoleculeCreation, TimelineMoleculeDisposal, TimelineSelectorUpdate, TimelineStateCreation, TimelineStateDisposal, TimelineTransactionUpdate } from 'atom.io/internal';
|
|
2
2
|
import { Json, JsonInterface, Canonical, stringified } from 'atom.io/json';
|
|
3
|
-
import { MoleculeConstructor as MoleculeConstructor$1, MoleculeToken as MoleculeToken$1, MoleculeFamilyToken as MoleculeFamilyToken$1, MoleculeParams as MoleculeParams$1, getState as getState$1, setState as setState$1, makeMolecule as makeMolecule$1, ActorToolkit as ActorToolkit$1, MutableAtomFamilyToken as MutableAtomFamilyToken$1, MutableAtomToken as MutableAtomToken$1, RegularAtomFamilyToken as RegularAtomFamilyToken$1, RegularAtomToken as RegularAtomToken$1, WritableSelectorFamilyToken as WritableSelectorFamilyToken$1, WritableSelectorToken as WritableSelectorToken$1, ReadonlySelectorFamilyToken as ReadonlySelectorFamilyToken$1, ReadonlySelectorToken as ReadonlySelectorToken$1, WritableFamilyToken as WritableFamilyToken$1, WritableToken as WritableToken$1, ReadableFamilyToken as ReadableFamilyToken$1, ReadableToken as ReadableToken$1,
|
|
3
|
+
import { MoleculeConstructor as MoleculeConstructor$1, MoleculeToken as MoleculeToken$1, MoleculeFamilyToken as MoleculeFamilyToken$1, MoleculeParams as MoleculeParams$1, getState as getState$1, setState as setState$1, makeMolecule as makeMolecule$1, ActorToolkit as ActorToolkit$1, MutableAtomFamilyToken as MutableAtomFamilyToken$1, MutableAtomToken as MutableAtomToken$1, RegularAtomFamilyToken as RegularAtomFamilyToken$1, RegularAtomToken as RegularAtomToken$1, WritableSelectorFamilyToken as WritableSelectorFamilyToken$1, WritableSelectorToken as WritableSelectorToken$1, ReadonlySelectorFamilyToken as ReadonlySelectorFamilyToken$1, ReadonlySelectorToken as ReadonlySelectorToken$1, WritableFamilyToken as WritableFamilyToken$1, WritableToken as WritableToken$1, ReadableFamilyToken as ReadableFamilyToken$1, ReadableToken as ReadableToken$1, MoleculeCreationClassic as MoleculeCreationClassic$1, MoleculeDisposalClassic as MoleculeDisposalClassic$1 } from 'atom.io';
|
|
4
4
|
import { findState } from 'atom.io/ephemeral';
|
|
5
5
|
import { seekState } from 'atom.io/immortal';
|
|
6
6
|
import { JoinToken } from 'atom.io/data';
|
|
@@ -82,20 +82,37 @@ type StateDisposal<Token extends ReadableToken<any>> = {
|
|
|
82
82
|
token: Token;
|
|
83
83
|
value?: TokenType<Token>;
|
|
84
84
|
};
|
|
85
|
-
type
|
|
85
|
+
type MoleculeCreationClassic<M extends MoleculeConstructor$1> = {
|
|
86
86
|
type: `molecule_creation`;
|
|
87
|
+
subType: `classic`;
|
|
87
88
|
token: MoleculeToken$1<M>;
|
|
88
89
|
family: MoleculeFamilyToken$1<M>;
|
|
89
90
|
context: MoleculeToken$1<any>[];
|
|
90
91
|
params: MoleculeParams$1<M>;
|
|
91
92
|
};
|
|
92
|
-
type
|
|
93
|
+
type MoleculeCreationModern = {
|
|
94
|
+
type: `molecule_creation`;
|
|
95
|
+
subType: `modern`;
|
|
96
|
+
key: Canonical;
|
|
97
|
+
provenance: Canonical;
|
|
98
|
+
};
|
|
99
|
+
type MoleculeCreation<M extends MoleculeConstructor$1> = MoleculeCreationClassic<M> | MoleculeCreationModern;
|
|
100
|
+
type MoleculeDisposalClassic = {
|
|
93
101
|
type: `molecule_disposal`;
|
|
102
|
+
subType: `classic`;
|
|
94
103
|
token: MoleculeToken$1<any>;
|
|
95
104
|
family: MoleculeFamilyToken$1<any>;
|
|
96
105
|
context: MoleculeToken$1<any>[];
|
|
97
106
|
values: [key: string, value: any][];
|
|
98
107
|
};
|
|
108
|
+
type MoleculeDisposalModern = {
|
|
109
|
+
type: `molecule_disposal`;
|
|
110
|
+
subType: `modern`;
|
|
111
|
+
key: Canonical;
|
|
112
|
+
provenance: Canonical;
|
|
113
|
+
values: [key: string, value: any][];
|
|
114
|
+
};
|
|
115
|
+
type MoleculeDisposal = MoleculeDisposalClassic | MoleculeDisposalModern;
|
|
99
116
|
type TransactionUpdateContent = KeyedStateUpdate<unknown> | MoleculeCreation<any> | MoleculeDisposal | StateCreation<ReadableToken<unknown>> | StateDisposal<ReadableToken<unknown>> | TransactionUpdate<Func>;
|
|
100
117
|
type TransactionUpdate<F extends Func> = {
|
|
101
118
|
type: `transaction_update`;
|
|
@@ -179,9 +196,9 @@ type CtorToolkit<K extends Canonical> = Flat<Omit<ActorToolkit$1, `find`> & {
|
|
|
179
196
|
bond<T>(family: ReadonlySelectorFamilyToken$1<T, K>): ReadonlySelectorToken$1<T>;
|
|
180
197
|
bond<T>(family: WritableFamilyToken$1<T, K>): WritableToken$1<T>;
|
|
181
198
|
bond<T>(family: ReadableFamilyToken$1<T, K>): ReadableToken$1<T>;
|
|
182
|
-
bond<J extends JoinToken<any, any, any, any>>(joinToken: J, role: {
|
|
183
|
-
as: J extends JoinToken<infer A, infer B, any, any> ? A | B : never;
|
|
184
|
-
}): J extends JoinToken<any, any, any, infer Content> ? Content extends null ? {
|
|
199
|
+
bond<J extends JoinToken<any, any, any, any, any, any>>(joinToken: J, role: {
|
|
200
|
+
as: J extends JoinToken<infer A, string, infer B, string, any, any> ? A | B : never;
|
|
201
|
+
}): J extends JoinToken<any, any, any, any, any, infer Content> ? Content extends null ? {
|
|
185
202
|
relatedKeys: ReadonlySelectorToken$1<string[]>;
|
|
186
203
|
} : {
|
|
187
204
|
relatedKeys: ReadonlySelectorToken$1<string[]>;
|
|
@@ -210,7 +227,7 @@ type MoleculeFamilyToken<M extends MoleculeConstructor> = {
|
|
|
210
227
|
__M?: M;
|
|
211
228
|
};
|
|
212
229
|
type MoleculeFamily<M extends MoleculeConstructor> = Flat<MoleculeFamilyToken<M> & {
|
|
213
|
-
subject: Subject<
|
|
230
|
+
subject: Subject<MoleculeCreationClassic$1<M> | MoleculeDisposalClassic$1>;
|
|
214
231
|
dependsOn: `all` | `any`;
|
|
215
232
|
new: M;
|
|
216
233
|
}>;
|
|
@@ -224,7 +241,55 @@ declare function moleculeFamily<M extends MoleculeConstructor>(options: Molecule
|
|
|
224
241
|
declare function makeMolecule<M extends MoleculeConstructor>(context: MoleculeToken<any> | MoleculeToken<any>[], family: MoleculeFamilyToken<M>, key: MoleculeKey<M>, ...params: MoleculeParams<M>): MoleculeToken<M>;
|
|
225
242
|
type MoleculeType<T extends MoleculeFamilyToken<any>> = T extends MoleculeFamilyToken<infer M> ? M : T extends MoleculeToken<infer M> ? M : never;
|
|
226
243
|
type MoleculeKey<M extends MoleculeConstructor> = InstanceType<M>[`key`];
|
|
227
|
-
declare function
|
|
244
|
+
declare function makeRootMoleculeInStore(key: string, store?: Store): MoleculeToken<ObjectConstructor>;
|
|
245
|
+
|
|
246
|
+
declare const $provenance: unique symbol;
|
|
247
|
+
type Claim<H extends Hierarchy, V extends Vassal<H>, A extends Above<V, H>> = V & {
|
|
248
|
+
[$provenance]?: A;
|
|
249
|
+
};
|
|
250
|
+
declare function allocateIntoStore<H extends Hierarchy, V extends Vassal<H>, A extends Above<V, H>>(store: Store, provenance: A, key: V): Claim<H, V, A>;
|
|
251
|
+
declare function deallocateFromStore<H extends Hierarchy, V extends Vassal<H>, A extends Above<V, H>>(store: Store, claim: Claim<H, V, A>): void;
|
|
252
|
+
declare function realm<H extends Hierarchy>(store: Store): {
|
|
253
|
+
root: MoleculeToken<ObjectConstructor>;
|
|
254
|
+
allocate: <V extends Vassal<H>, A extends Above<V, H>>(provenance: A, key: V) => Claim<H, V, A>;
|
|
255
|
+
deallocate: <V extends Vassal<H>, A extends Above<V, H>>(claim: Claim<H, V, A>) => void;
|
|
256
|
+
};
|
|
257
|
+
declare const T$ = "T$";
|
|
258
|
+
type T$ = typeof T$;
|
|
259
|
+
type TypeTag<T extends string> = `${T$}--${T}`;
|
|
260
|
+
type SingularTypedKey<T extends string = string> = `${T}::${string}`;
|
|
261
|
+
type CompoundTypedKey<A extends string = string, B extends string = string, C extends string = string> = `${TypeTag<A>}==${SingularTypedKey<B>}++${SingularTypedKey<C>}`;
|
|
262
|
+
type TypedKey<A extends string = string, B extends string = string, C extends string = string> = CompoundTypedKey<A, B, C> | SingularTypedKey<A>;
|
|
263
|
+
type Scope = SingularTypedKey[];
|
|
264
|
+
type MutualFealty = {
|
|
265
|
+
above: Scope;
|
|
266
|
+
below: CompoundTypedKey;
|
|
267
|
+
style: `all` | `any`;
|
|
268
|
+
};
|
|
269
|
+
type ExclusiveFealty = {
|
|
270
|
+
above: TypedKey | `root`;
|
|
271
|
+
below: Scope;
|
|
272
|
+
};
|
|
273
|
+
type Fealty = ExclusiveFealty | MutualFealty;
|
|
274
|
+
type Hierarchy<F extends Fealty[] = Fealty[]> = Each<F>;
|
|
275
|
+
type Vassal<H extends Hierarchy> = {
|
|
276
|
+
[K in keyof H]: H[K] extends MutualFealty ? H[K][`below`] : H[K] extends {
|
|
277
|
+
below: Array<infer V>;
|
|
278
|
+
} ? V extends TypedKey ? V : never : never;
|
|
279
|
+
}[keyof H];
|
|
280
|
+
type Above<TK extends TypedKey, H extends Hierarchy> = {
|
|
281
|
+
[K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`below`] ? H[K][`above`] : never : H[K] extends {
|
|
282
|
+
below: Array<infer V>;
|
|
283
|
+
} ? TK extends V ? H[K] extends ExclusiveFealty ? H[K][`above`] : never : never : never;
|
|
284
|
+
}[keyof H];
|
|
285
|
+
type Below<TK extends TypedKey | TypedKey[], H extends Hierarchy> = {
|
|
286
|
+
[K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`above`] ? H[K][`below`] : TK extends H[K][`above`][number] ? H[K][`below`] : never : H[K] extends {
|
|
287
|
+
above: infer V;
|
|
288
|
+
} ? TK extends V ? H[K] extends ExclusiveFealty ? H[K][`below`][number] : never : never : never;
|
|
289
|
+
}[keyof H];
|
|
290
|
+
type Mutuals<TK extends TypedKey | TypedKey[], H extends Hierarchy> = {
|
|
291
|
+
[K in keyof H]: H[K] extends MutualFealty ? TK extends H[K][`above`][number] ? [mutual: Exclude<H[K][`above`][number], TK>, below: H[K][`below`]] : never : never;
|
|
292
|
+
}[keyof H];
|
|
228
293
|
|
|
229
294
|
declare function disposeState(token: MoleculeToken<any> | ReadableToken<any>): void;
|
|
230
295
|
declare function disposeState<K extends Canonical>(token: ReadableFamilyToken<any, K>, key: K): void;
|
|
@@ -427,4 +492,4 @@ type FamilyMetadata<K extends Canonical = any> = {
|
|
|
427
492
|
subKey: stringified<K>;
|
|
428
493
|
};
|
|
429
494
|
|
|
430
|
-
export { type ActorToolkit, type AtomEffect, type AtomFamilyToken, AtomIOLogger, type AtomOnly, type AtomToken, type CtorToolkit, type Effectors, type FamilyMetadata, type GetterToolkit, type KeyedStateUpdate, LOG_LEVELS, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerIcon, type MoleculeConstructor, type MoleculeCreation, type MoleculeDisposal, type MoleculeFamily, type MoleculeFamilyOptions, type MoleculeFamilyToken, type MoleculeKey, type MoleculeParams, type MoleculeToken, type MoleculeType, type MutableAtomFamilyOptions, type MutableAtomFamilyToken, type MutableAtomOptions, type MutableAtomToken, type Read, type ReadableFamilyToken, type ReadableToken, type ReadonlySelectorFamilyOptions, type ReadonlySelectorFamilyToken, type ReadonlySelectorOptions, type ReadonlySelectorToken, type RegularAtomFamilyOptions, type RegularAtomFamilyToken, type RegularAtomOptions, type RegularAtomToken, type SelectorFamilyToken, type SelectorToken, type SetterToolkit, Silo, type StateCreation, type StateDisposal, type StateUpdate, type TimelineManageable, type TimelineOptions, type TimelineToken, type TimelineUpdate, type TokenDenomination, type TokenType, type Transact, type TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateContent, type TransactionUpdateHandler, type UpdateHandler, type WritableFamilyToken, type WritableSelectorFamilyOptions, type WritableSelectorFamilyToken, type WritableSelectorOptions, type WritableSelectorToken, type WritableToken, type Write, atom, atomFamily, belongsTo, disposeState, getState, isToken, makeMolecule,
|
|
495
|
+
export { $provenance, type Above, type ActorToolkit, type AtomEffect, type AtomFamilyToken, AtomIOLogger, type AtomOnly, type AtomToken, type Below, type Claim, type CompoundTypedKey, type CtorToolkit, type Effectors, type FamilyMetadata, type GetterToolkit, type Hierarchy, type KeyedStateUpdate, LOG_LEVELS, type LogFilter, type LogFn, type LogLevel, type Logger, type LoggerIcon, type MoleculeConstructor, type MoleculeCreation, type MoleculeCreationClassic, type MoleculeCreationModern, type MoleculeDisposal, type MoleculeDisposalClassic, type MoleculeDisposalModern, type MoleculeFamily, type MoleculeFamilyOptions, type MoleculeFamilyToken, type MoleculeKey, type MoleculeParams, type MoleculeToken, type MoleculeType, type MutableAtomFamilyOptions, type MutableAtomFamilyToken, type MutableAtomOptions, type MutableAtomToken, type Mutuals, type Read, type ReadableFamilyToken, type ReadableToken, type ReadonlySelectorFamilyOptions, type ReadonlySelectorFamilyToken, type ReadonlySelectorOptions, type ReadonlySelectorToken, type RegularAtomFamilyOptions, type RegularAtomFamilyToken, type RegularAtomOptions, type RegularAtomToken, type SelectorFamilyToken, type SelectorToken, type SetterToolkit, Silo, type SingularTypedKey, type StateCreation, type StateDisposal, type StateUpdate, T$, type TimelineManageable, type TimelineOptions, type TimelineToken, type TimelineUpdate, type TokenDenomination, type TokenType, type Transact, type TransactionIO, type TransactionOptions, type TransactionToken, type TransactionUpdate, type TransactionUpdateContent, type TransactionUpdateHandler, type TypeTag, type TypedKey, type UpdateHandler, type Vassal, type WritableFamilyToken, type WritableSelectorFamilyOptions, type WritableSelectorFamilyToken, type WritableSelectorOptions, type WritableSelectorToken, type WritableToken, type Write, allocateIntoStore, atom, atomFamily, belongsTo, deallocateFromStore, disposeState, getState, isToken, makeMolecule, makeRootMoleculeInStore, moleculeFamily, realm, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
|