atom.io 0.31.0 → 0.31.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/dist/{chunk-42UH5F5Q.js → chunk-Y5MBNTVU.js} +240 -32
- package/dist/index.d.ts +236 -104
- package/dist/index.js +90 -5
- package/ephemeral/dist/index.d.ts +35 -25
- package/ephemeral/src/find-state.ts +35 -25
- package/internal/dist/index.d.ts +15 -10
- package/internal/dist/index.js +1 -2
- package/internal/src/families/find-in-store.ts +1 -6
- package/internal/src/index.ts +17 -9
- package/internal/src/ingest-updates/ingest-creation-disposal.ts +2 -3
- package/internal/src/install-into-store.ts +48 -0
- package/internal/src/molecule.ts +299 -0
- package/internal/src/not-found-error.ts +8 -30
- package/internal/src/pretty-print.ts +1 -12
- package/internal/src/selector/register-selector.ts +1 -8
- package/internal/src/store/deposit.ts +10 -8
- package/internal/src/store/withdraw.ts +15 -34
- package/json/dist/index.js +1 -2
- package/package.json +5 -5
- package/realtime-server/src/ipc-sockets/child-socket.ts +0 -1
- package/realtime-server/src/realtime-server-stores/server-room-external-actions.ts +1 -1
- package/realtime-testing/dist/index.js +3 -4
- package/realtime-testing/src/setup-realtime-test.tsx +4 -4
- package/src/atom.ts +53 -29
- package/src/dispose-state.ts +12 -2
- package/src/get-state.ts +16 -0
- package/src/index.ts +73 -3
- package/src/realm.ts +169 -0
- package/src/selector.ts +20 -0
- package/src/set-state.ts +16 -8
- package/src/silo.ts +9 -3
- package/transceivers/set-rtx/dist/index.js +4 -1
- package/transceivers/set-rtx/src/set-rtx.ts +4 -1
- package/dist/chunk-ICGFFQ3H.js +0 -272
- package/src/allocate.ts +0 -443
- package/src/molecule.ts +0 -16
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { deallocateFromStore, allocateIntoStore, claimWithinStore } from './chunk-ICGFFQ3H.js';
|
|
2
1
|
import { stringifyJson, parseJson, selectJson, selectJsonFamily } from 'atom.io/json';
|
|
3
2
|
import { AtomIOLogger } from 'atom.io';
|
|
4
3
|
import { subscribeToTimeline, subscribeToTransaction, subscribeToState, arbitrary as arbitrary$1 } from 'atom.io/internal';
|
|
@@ -511,19 +510,10 @@ function prettyPrintTokenType(token) {
|
|
|
511
510
|
|
|
512
511
|
// internal/src/not-found-error.ts
|
|
513
512
|
var NotFoundError = class extends Error {
|
|
514
|
-
constructor(
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
super(
|
|
519
|
-
`${prettyPrintTokenType(token)} ${stringifyJson(token.key)} not found in store "${store.config.name}".`
|
|
520
|
-
);
|
|
521
|
-
} else {
|
|
522
|
-
const key = params[1];
|
|
523
|
-
super(
|
|
524
|
-
`${prettyPrintTokenType(token)} "${token.key}" member ${stringifyJson(key)} not found in store "${store.config.name}".`
|
|
525
|
-
);
|
|
526
|
-
}
|
|
513
|
+
constructor(token, store) {
|
|
514
|
+
super(
|
|
515
|
+
`${prettyPrintTokenType(token)} ${stringifyJson(token.key)} not found in store "${store.config.name}".`
|
|
516
|
+
);
|
|
527
517
|
}
|
|
528
518
|
};
|
|
529
519
|
|
|
@@ -954,11 +944,7 @@ var registerSelector = (selectorKey, covered, store) => ({
|
|
|
954
944
|
const family = params[0];
|
|
955
945
|
const key = params[1];
|
|
956
946
|
value = params[2];
|
|
957
|
-
|
|
958
|
-
if (!maybeToken) {
|
|
959
|
-
throw new NotFoundError(family, key, store);
|
|
960
|
-
}
|
|
961
|
-
token = maybeToken;
|
|
947
|
+
token = findInStore(store, family, key);
|
|
962
948
|
}
|
|
963
949
|
const target = newest(store);
|
|
964
950
|
const state = withdraw(token, target);
|
|
@@ -1444,6 +1430,240 @@ function ingestAtomUpdate(applying, atomUpdate, store) {
|
|
|
1444
1430
|
}
|
|
1445
1431
|
setIntoStore(store, token, value);
|
|
1446
1432
|
}
|
|
1433
|
+
|
|
1434
|
+
// internal/src/get-trace.ts
|
|
1435
|
+
function getTrace(error) {
|
|
1436
|
+
const { stack } = error;
|
|
1437
|
+
if (stack) {
|
|
1438
|
+
return `
|
|
1439
|
+
` + stack.split(`
|
|
1440
|
+
`)?.slice(1)?.join(`
|
|
1441
|
+
`);
|
|
1442
|
+
}
|
|
1443
|
+
return ``;
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
// internal/src/molecule.ts
|
|
1447
|
+
function makeRootMoleculeInStore(key, store = IMPLICIT.STORE) {
|
|
1448
|
+
const molecule = {
|
|
1449
|
+
key,
|
|
1450
|
+
stringKey: stringifyJson(key),
|
|
1451
|
+
dependsOn: `any`
|
|
1452
|
+
};
|
|
1453
|
+
store.molecules.set(stringifyJson(key), molecule);
|
|
1454
|
+
return key;
|
|
1455
|
+
}
|
|
1456
|
+
function allocateIntoStore(store, provenance, key, dependsOn = `any`) {
|
|
1457
|
+
const origin = provenance;
|
|
1458
|
+
const stringKey = stringifyJson(key);
|
|
1459
|
+
const invalidKeys = [];
|
|
1460
|
+
const target = newest(store);
|
|
1461
|
+
if (Array.isArray(origin)) {
|
|
1462
|
+
for (const formerClaim of origin) {
|
|
1463
|
+
const claimString = stringifyJson(formerClaim);
|
|
1464
|
+
const claim = target.molecules.get(claimString);
|
|
1465
|
+
if (claim) {
|
|
1466
|
+
store.moleculeGraph.set(claimString, stringKey, { source: claimString });
|
|
1467
|
+
} else {
|
|
1468
|
+
invalidKeys.push(claimString);
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
} else {
|
|
1472
|
+
const claimString = stringifyJson(origin);
|
|
1473
|
+
const claim = target.molecules.get(claimString);
|
|
1474
|
+
if (claim) {
|
|
1475
|
+
store.moleculeGraph.set(claimString, stringKey, { source: claimString });
|
|
1476
|
+
} else {
|
|
1477
|
+
invalidKeys.push(claimString);
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
if (invalidKeys.length === 0) {
|
|
1481
|
+
target.molecules.set(stringKey, { key, stringKey, dependsOn });
|
|
1482
|
+
}
|
|
1483
|
+
const creationEvent = {
|
|
1484
|
+
type: `molecule_creation`,
|
|
1485
|
+
key,
|
|
1486
|
+
provenance: origin
|
|
1487
|
+
};
|
|
1488
|
+
const isTransaction = isChildStore(target) && target.transactionMeta.phase === `building`;
|
|
1489
|
+
if (isTransaction) {
|
|
1490
|
+
target.transactionMeta.update.updates.push(creationEvent);
|
|
1491
|
+
} else {
|
|
1492
|
+
target.on.moleculeCreation.next(creationEvent);
|
|
1493
|
+
}
|
|
1494
|
+
for (const claim of invalidKeys) {
|
|
1495
|
+
const disposal = store.disposalTraces.buffer.find(
|
|
1496
|
+
(item) => item?.key === claim
|
|
1497
|
+
);
|
|
1498
|
+
store.logger.error(
|
|
1499
|
+
`\u274C`,
|
|
1500
|
+
`molecule`,
|
|
1501
|
+
key,
|
|
1502
|
+
`allocation failed:`,
|
|
1503
|
+
`Could not allocate to ${claim} in store "${store.config.name}".`,
|
|
1504
|
+
disposal ? `
|
|
1505
|
+
${claim} was most recently disposed
|
|
1506
|
+
${disposal.trace}` : `No previous disposal trace for ${claim} was found.`
|
|
1507
|
+
);
|
|
1508
|
+
}
|
|
1509
|
+
return key;
|
|
1510
|
+
}
|
|
1511
|
+
function fuseWithinStore(store, type, sideA, sideB) {
|
|
1512
|
+
const compoundKey = `T$--${type}==${sideA}++${sideB}`;
|
|
1513
|
+
const above = [sideA, sideB];
|
|
1514
|
+
allocateIntoStore(
|
|
1515
|
+
store,
|
|
1516
|
+
above,
|
|
1517
|
+
compoundKey,
|
|
1518
|
+
`all`
|
|
1519
|
+
);
|
|
1520
|
+
return compoundKey;
|
|
1521
|
+
}
|
|
1522
|
+
function deallocateFromStore(store, claim) {
|
|
1523
|
+
const stringKey = stringifyJson(claim);
|
|
1524
|
+
const molecule = store.molecules.get(stringKey);
|
|
1525
|
+
if (!molecule) {
|
|
1526
|
+
const disposal = store.disposalTraces.buffer.find(
|
|
1527
|
+
(item) => item?.key === stringKey
|
|
1528
|
+
);
|
|
1529
|
+
store.logger.error(
|
|
1530
|
+
`\u274C`,
|
|
1531
|
+
`molecule`,
|
|
1532
|
+
claim,
|
|
1533
|
+
`deallocation failed:`,
|
|
1534
|
+
`Could not find allocation for ${stringKey} in store "${store.config.name}".`,
|
|
1535
|
+
disposal ? `
|
|
1536
|
+
This state was most recently deallocated
|
|
1537
|
+
${disposal.trace}` : `No previous disposal trace for ${stringKey} was found.`
|
|
1538
|
+
);
|
|
1539
|
+
return;
|
|
1540
|
+
}
|
|
1541
|
+
const joinKeys = store.moleculeJoins.getRelatedKeys(
|
|
1542
|
+
molecule.key
|
|
1543
|
+
);
|
|
1544
|
+
if (joinKeys) {
|
|
1545
|
+
for (const joinKey of joinKeys) {
|
|
1546
|
+
const join = store.joins.get(joinKey);
|
|
1547
|
+
if (join) {
|
|
1548
|
+
join.relations.delete(molecule.key);
|
|
1549
|
+
join.molecules.delete(molecule.stringKey);
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
}
|
|
1553
|
+
store.moleculeJoins.delete(molecule.stringKey);
|
|
1554
|
+
const provenance = [];
|
|
1555
|
+
const values = [];
|
|
1556
|
+
const disposalEvent = {
|
|
1557
|
+
type: `molecule_disposal`,
|
|
1558
|
+
key: molecule.key,
|
|
1559
|
+
values,
|
|
1560
|
+
provenance
|
|
1561
|
+
};
|
|
1562
|
+
const target = newest(store);
|
|
1563
|
+
target.molecules.delete(stringKey);
|
|
1564
|
+
const isTransaction = isChildStore(target) && target.transactionMeta.phase === `building`;
|
|
1565
|
+
if (isTransaction) {
|
|
1566
|
+
target.transactionMeta.update.updates.push(disposalEvent);
|
|
1567
|
+
}
|
|
1568
|
+
const relatedMolecules = store.moleculeGraph.getRelationEntries({
|
|
1569
|
+
downstreamMoleculeKey: molecule.stringKey
|
|
1570
|
+
});
|
|
1571
|
+
if (relatedMolecules) {
|
|
1572
|
+
for (const [relatedStringKey, { source }] of relatedMolecules) {
|
|
1573
|
+
if (source === molecule.stringKey) {
|
|
1574
|
+
const relatedKey = parseJson(relatedStringKey);
|
|
1575
|
+
deallocateFromStore(store, relatedKey);
|
|
1576
|
+
} else {
|
|
1577
|
+
provenance.push(source);
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
}
|
|
1581
|
+
const familyKeys = target.moleculeData.getRelatedKeys(molecule.stringKey);
|
|
1582
|
+
if (familyKeys) {
|
|
1583
|
+
for (const familyKey of familyKeys) {
|
|
1584
|
+
const family = target.families.get(familyKey);
|
|
1585
|
+
const token = findInStore(store, family, molecule.key);
|
|
1586
|
+
values.push([family.key, token]);
|
|
1587
|
+
disposeFromStore(store, token);
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
target.moleculeGraph.delete(molecule.stringKey);
|
|
1591
|
+
target.moleculeJoins.delete(molecule.stringKey);
|
|
1592
|
+
target.moleculeData.delete(molecule.stringKey);
|
|
1593
|
+
if (!isTransaction) {
|
|
1594
|
+
target.on.moleculeDisposal.next(disposalEvent);
|
|
1595
|
+
}
|
|
1596
|
+
target.molecules.delete(molecule.stringKey);
|
|
1597
|
+
const trace = getTrace(new Error());
|
|
1598
|
+
store.disposalTraces.add({ key: stringKey, trace });
|
|
1599
|
+
}
|
|
1600
|
+
function claimWithinStore(store, newProvenance, claim, exclusive) {
|
|
1601
|
+
const stringKey = stringifyJson(claim);
|
|
1602
|
+
const target = newest(store);
|
|
1603
|
+
const molecule = target.molecules.get(stringKey);
|
|
1604
|
+
if (!molecule) {
|
|
1605
|
+
const disposal = store.disposalTraces.buffer.find(
|
|
1606
|
+
(item) => item?.key === stringKey
|
|
1607
|
+
);
|
|
1608
|
+
store.logger.error(
|
|
1609
|
+
`\u274C`,
|
|
1610
|
+
`molecule`,
|
|
1611
|
+
claim,
|
|
1612
|
+
`claim failed:`,
|
|
1613
|
+
`Could not allocate to ${stringKey} in store "${store.config.name}".`,
|
|
1614
|
+
disposal ? `
|
|
1615
|
+
${stringKey} was most recently disposed
|
|
1616
|
+
${disposal.trace}` : `No previous disposal trace for ${stringKey} was found.`
|
|
1617
|
+
);
|
|
1618
|
+
return claim;
|
|
1619
|
+
}
|
|
1620
|
+
const newProvenanceKey = stringifyJson(newProvenance);
|
|
1621
|
+
const newProvenanceMolecule = target.molecules.get(newProvenanceKey);
|
|
1622
|
+
if (!newProvenanceMolecule) {
|
|
1623
|
+
const disposal = store.disposalTraces.buffer.find(
|
|
1624
|
+
(item) => item?.key === newProvenanceKey
|
|
1625
|
+
);
|
|
1626
|
+
store.logger.error(
|
|
1627
|
+
`\u274C`,
|
|
1628
|
+
`molecule`,
|
|
1629
|
+
claim,
|
|
1630
|
+
`claim failed:`,
|
|
1631
|
+
`Could not allocate to ${newProvenanceKey} in store "${store.config.name}".`,
|
|
1632
|
+
disposal ? `
|
|
1633
|
+
${newProvenanceKey} was most recently disposed
|
|
1634
|
+
${disposal.trace}` : `No previous disposal trace for ${newProvenanceKey} was found.`
|
|
1635
|
+
);
|
|
1636
|
+
return claim;
|
|
1637
|
+
}
|
|
1638
|
+
const priorProvenance = store.moleculeGraph.getRelationEntries({
|
|
1639
|
+
downstreamMoleculeKey: molecule.stringKey
|
|
1640
|
+
}).filter(([, { source }]) => source !== stringKey).map(([key]) => parseJson(key));
|
|
1641
|
+
if (exclusive) {
|
|
1642
|
+
target.moleculeGraph.delete(stringKey);
|
|
1643
|
+
}
|
|
1644
|
+
target.moleculeGraph.set(
|
|
1645
|
+
{
|
|
1646
|
+
upstreamMoleculeKey: newProvenanceMolecule.stringKey,
|
|
1647
|
+
downstreamMoleculeKey: molecule.stringKey
|
|
1648
|
+
},
|
|
1649
|
+
{
|
|
1650
|
+
source: newProvenanceMolecule.stringKey
|
|
1651
|
+
}
|
|
1652
|
+
);
|
|
1653
|
+
const transferEvent = {
|
|
1654
|
+
type: `molecule_transfer`,
|
|
1655
|
+
key: molecule.key,
|
|
1656
|
+
from: priorProvenance,
|
|
1657
|
+
to: [newProvenanceMolecule.key]
|
|
1658
|
+
};
|
|
1659
|
+
const isTransaction = isChildStore(target) && target.transactionMeta.phase === `building`;
|
|
1660
|
+
if (isTransaction) {
|
|
1661
|
+
target.transactionMeta.update.updates.push(transferEvent);
|
|
1662
|
+
}
|
|
1663
|
+
return claim;
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
// internal/src/ingest-updates/ingest-creation-disposal.ts
|
|
1447
1667
|
function ingestCreationEvent(update, applying, store) {
|
|
1448
1668
|
switch (applying) {
|
|
1449
1669
|
case `newValue`: {
|
|
@@ -2786,18 +3006,6 @@ function disposeAtom(atomToken, store) {
|
|
|
2786
3006
|
}
|
|
2787
3007
|
}
|
|
2788
3008
|
|
|
2789
|
-
// internal/src/get-trace.ts
|
|
2790
|
-
function getTrace(error) {
|
|
2791
|
-
const { stack } = error;
|
|
2792
|
-
if (stack) {
|
|
2793
|
-
return `
|
|
2794
|
-
` + stack.split(`
|
|
2795
|
-
`)?.slice(1)?.join(`
|
|
2796
|
-
`);
|
|
2797
|
-
}
|
|
2798
|
-
return ``;
|
|
2799
|
-
}
|
|
2800
|
-
|
|
2801
3009
|
// internal/src/timeline/create-timeline.ts
|
|
2802
3010
|
function createTimeline(options, store, data) {
|
|
2803
3011
|
const tl = {
|
|
@@ -3199,4 +3407,4 @@ var timeTravel = (store, action, token) => {
|
|
|
3199
3407
|
);
|
|
3200
3408
|
};
|
|
3201
3409
|
|
|
3202
|
-
export { CircularBuffer, FAMILY_MEMBER_TOKEN_TYPES, FamilyTracker, Future, IMPLICIT, Junction, LazyMap, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, actUponStore, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, cacheValue, clearStore, closeOperation, counterfeit, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelector, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneAtom, createStandaloneSelector, createTimeline, createTransaction, createWritableSelector, createWritableSelectorFamily, deposit, disposeAtom, disposeFromStore, disposeSelector, evictCachedValue, findInStore, getContinuityKey, getEnvironmentData, getEpochNumberOfAction, getEpochNumberOfContinuity, getFromStore, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getTrace, getUpdateFamily, getUpdateToken, ingestAtomUpdate, ingestCreationEvent, ingestDisposalEvent, ingestMoleculeCreationEvent, ingestMoleculeDisposalEvent, ingestMoleculeTransferEvent, ingestSelectorUpdate, ingestTransactionUpdate, initFamilyMemberInStore, isAtomDefault, isAtomKey, isChildStore, isDone, isReadonlySelectorKey, isRootStore, isSelectorKey, isStateKey, isTransceiver, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, prettyPrintTokenType, readCachedValue, readOrComputeValue, recallState, registerSelector, seekInStore, setAtomOrSelector, setEpochNumberOfAction, setEpochNumberOfContinuity, setIntoStore, subscribeInStore, subscribeToRootAtoms, subscribeToState2 as subscribeToState, subscribeToTimeline2 as subscribeToTimeline, subscribeToTransaction2 as subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw };
|
|
3410
|
+
export { CircularBuffer, FAMILY_MEMBER_TOKEN_TYPES, FamilyTracker, Future, IMPLICIT, Junction, LazyMap, NotFoundError, StatefulSubject, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, actUponStore, allocateIntoStore, applyTransaction, arbitrary, assignTransactionToContinuity, become, buildTransaction, cacheValue, claimWithinStore, clearStore, closeOperation, counterfeit, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelector, createReadonlySelectorFamily, createRegularAtom, createRegularAtomFamily, createSelectorFamily, createStandaloneAtom, createStandaloneSelector, createTimeline, createTransaction, createWritableSelector, createWritableSelectorFamily, deallocateFromStore, deposit, disposeAtom, disposeFromStore, disposeSelector, evictCachedValue, findInStore, fuseWithinStore, getContinuityKey, getEnvironmentData, getEpochNumberOfAction, getEpochNumberOfContinuity, getFromStore, getJsonFamily, getJsonToken, getSelectorDependencyKeys, getTrace, getUpdateFamily, getUpdateToken, ingestAtomUpdate, ingestCreationEvent, ingestDisposalEvent, ingestMoleculeCreationEvent, ingestMoleculeDisposalEvent, ingestMoleculeTransferEvent, ingestSelectorUpdate, ingestTransactionUpdate, initFamilyMemberInStore, isAtomDefault, isAtomKey, isChildStore, isDone, isReadonlySelectorKey, isRootStore, isSelectorKey, isStateKey, isTransceiver, makeRootMoleculeInStore, markAtomAsDefault, markAtomAsNotDefault, markDone, newest, openOperation, prettyPrintTokenType, readCachedValue, readOrComputeValue, recallState, registerSelector, seekInStore, setAtomOrSelector, setEpochNumberOfAction, setEpochNumberOfContinuity, setIntoStore, subscribeInStore, subscribeToRootAtoms, subscribeToState2 as subscribeToState, subscribeToTimeline2 as subscribeToTimeline, subscribeToTransaction2 as subscribeToTransaction, timeTravel, traceAllSelectorAtoms, traceSelectorAtoms, updateSelectorAtoms, withdraw };
|