atom.io 0.29.5 → 0.30.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.
@@ -1,7 +1,7 @@
1
1
  import { stringifyJson, parseJson, selectJson, selectJsonFamily } from 'atom.io/json';
2
2
  import { AtomIOLogger } from 'atom.io';
3
3
  import { getJoin, findRelations } from 'atom.io/data';
4
- import { subscribeToTimeline, subscribeToTransaction, subscribeToState, arbitrary as arbitrary$1 } from 'atom.io/internal';
4
+ import { subscribeToTimeline, subscribeToTransaction, subscribeToState, arbitrary as arbitrary$1, Molecule as Molecule$1, newest as newest$1, isChildStore as isChildStore$1, disposeFromStore as disposeFromStore$1 } from 'atom.io/internal';
5
5
 
6
6
  // internal/src/arbitrary.ts
7
7
  function arbitrary(random = Math.random) {
@@ -1304,6 +1304,7 @@ function disposeMolecule(token, store) {
1304
1304
  const Formula = withdraw(family, store);
1305
1305
  const disposalEvent = {
1306
1306
  type: `molecule_disposal`,
1307
+ subType: `classic`,
1307
1308
  token,
1308
1309
  family,
1309
1310
  context,
@@ -1316,7 +1317,7 @@ function disposeMolecule(token, store) {
1316
1317
  disposeFromStore(store, state);
1317
1318
  }
1318
1319
  for (const child of molecule.below.values()) {
1319
- if (child.family?.dependsOn === `all`) {
1320
+ if (child.dependsOn === `all`) {
1320
1321
  disposeMolecule(child, store);
1321
1322
  } else {
1322
1323
  child.above.delete(molecule.stringKey);
@@ -1380,20 +1381,24 @@ var Molecule = class {
1380
1381
  this.stringKey = stringifyJson(key);
1381
1382
  if (family) {
1382
1383
  this.family = family;
1384
+ this._dependsOn = family.dependsOn;
1383
1385
  }
1384
1386
  if (ctx) {
1385
- if (Array.isArray(ctx)) {
1386
- for (const molecule of ctx) {
1387
- this.above.set(molecule.stringKey, molecule);
1388
- }
1389
- } else {
1390
- this.above.set(ctx.stringKey, ctx);
1387
+ for (const molecule of ctx) {
1388
+ this.above.set(molecule.stringKey, molecule);
1391
1389
  }
1392
1390
  }
1393
1391
  }
1394
1392
  type = `molecule`;
1395
1393
  stringKey;
1396
1394
  family;
1395
+ _dependsOn;
1396
+ get dependsOn() {
1397
+ if (this.family) {
1398
+ return this.family.dependsOn;
1399
+ }
1400
+ return this._dependsOn;
1401
+ }
1397
1402
  subject = new Subject();
1398
1403
  tokens = /* @__PURE__ */ new Map();
1399
1404
  above = /* @__PURE__ */ new Map();
@@ -1452,9 +1457,11 @@ function makeMoleculeInStore(store, context, familyToken, key, ...params) {
1452
1457
  const unsubFromFamily = family.subject.subscribe(
1453
1458
  `join:${token2.key}-${stringKey}`,
1454
1459
  (event) => {
1455
- if (event.type === `molecule_disposal` && stringifyJson(event.token.key) === stringKey) {
1456
- unsubFromFamily();
1457
- join.molecules.delete(stringKey);
1460
+ if (event.type === `molecule_disposal`) {
1461
+ if (stringifyJson(event.token.key) === stringKey) {
1462
+ unsubFromFamily();
1463
+ join.molecules.delete(stringKey);
1464
+ }
1458
1465
  }
1459
1466
  }
1460
1467
  );
@@ -1512,6 +1519,7 @@ function makeMoleculeInStore(store, context, familyToken, key, ...params) {
1512
1519
  };
1513
1520
  const update = {
1514
1521
  type: `molecule_creation`,
1522
+ subType: `classic`,
1515
1523
  token,
1516
1524
  family: familyToken,
1517
1525
  context: contextArray,
@@ -1721,6 +1729,142 @@ function ingestAtomUpdate(applying, atomUpdate, store) {
1721
1729
  }
1722
1730
  setIntoStore(store, token, value);
1723
1731
  }
1732
+ function allocateIntoStore(store, provenance, key) {
1733
+ const stringKey = stringifyJson(key);
1734
+ try {
1735
+ const above = [];
1736
+ let allocationAttachmentStyle;
1737
+ if (provenance === `root`) {
1738
+ above.push(store.molecules.get(`"root"`));
1739
+ allocationAttachmentStyle = `all`;
1740
+ } else if (provenance[0][0] === T$) {
1741
+ allocationAttachmentStyle = `any`;
1742
+ const provenanceKey = stringifyJson(provenance);
1743
+ const provenanceMolecule = store.molecules.get(provenanceKey);
1744
+ if (!provenanceMolecule) {
1745
+ throw new Error(
1746
+ `Molecule ${provenanceKey} not found in store "${store.config.name}"`
1747
+ );
1748
+ }
1749
+ above.push(provenanceMolecule);
1750
+ } else {
1751
+ const allocationIsCompound = key[0][0] === T$;
1752
+ if (allocationIsCompound) {
1753
+ allocationAttachmentStyle = `all`;
1754
+ for (const claim of provenance) {
1755
+ const provenanceKey = stringifyJson(claim);
1756
+ const provenanceMolecule = store.molecules.get(provenanceKey);
1757
+ if (!provenanceMolecule) {
1758
+ throw new Error(
1759
+ `Molecule ${provenanceKey} not found in store "${store.config.name}"`
1760
+ );
1761
+ }
1762
+ above.push(provenanceMolecule);
1763
+ }
1764
+ } else {
1765
+ allocationAttachmentStyle = `any`;
1766
+ const provenanceKey = stringifyJson(provenance);
1767
+ const provenanceMolecule = store.molecules.get(provenanceKey);
1768
+ if (!provenanceMolecule) {
1769
+ throw new Error(
1770
+ `Molecule ${provenanceKey} not found in store "${store.config.name}"`
1771
+ );
1772
+ }
1773
+ above.push(provenanceMolecule);
1774
+ }
1775
+ }
1776
+ const molecule = new Molecule$1(above, key);
1777
+ molecule._dependsOn = allocationAttachmentStyle;
1778
+ store.molecules.set(stringKey, molecule);
1779
+ for (const aboveMolecule of above) {
1780
+ aboveMolecule.below.set(molecule.stringKey, molecule);
1781
+ }
1782
+ const creationEvent = {
1783
+ type: `molecule_creation`,
1784
+ subType: `modern`,
1785
+ key: molecule.key,
1786
+ provenance
1787
+ };
1788
+ const target = newest$1(store);
1789
+ const isTransaction = isChildStore$1(target) && target.transactionMeta.phase === `building`;
1790
+ if (isTransaction) {
1791
+ target.transactionMeta.update.updates.push(creationEvent);
1792
+ } else {
1793
+ target.on.moleculeCreationStart.next(creationEvent);
1794
+ }
1795
+ } catch (thrown) {
1796
+ if (thrown instanceof Error) {
1797
+ store.logger.error(
1798
+ `\u274C`,
1799
+ `molecule`,
1800
+ stringKey,
1801
+ `allocation failed:`,
1802
+ thrown.message
1803
+ );
1804
+ }
1805
+ }
1806
+ return key;
1807
+ }
1808
+ function deallocateFromStore(store, claim) {
1809
+ const stringKey = stringifyJson(claim);
1810
+ const molecule = store.molecules.get(stringKey);
1811
+ if (!molecule) {
1812
+ throw new Error(
1813
+ `Molecule ${stringKey} not found in store "${store.config.name}"`
1814
+ );
1815
+ }
1816
+ for (const join of molecule.joins.values()) {
1817
+ join.relations.delete(molecule.key);
1818
+ join.molecules.delete(molecule.stringKey);
1819
+ }
1820
+ let provenance;
1821
+ if (molecule.above.size === 1) {
1822
+ const above = molecule.above.values().next().value;
1823
+ provenance = above.key;
1824
+ } else {
1825
+ provenance = [...molecule.above.values()].map(({ key }) => key);
1826
+ }
1827
+ const values = [];
1828
+ for (const stateToken of molecule.tokens.values()) {
1829
+ const tokenFamily = stateToken.family;
1830
+ values.push([tokenFamily.key, store.valueMap.get(stateToken.key)]);
1831
+ }
1832
+ for (const state of molecule.tokens.values()) {
1833
+ disposeFromStore$1(store, state);
1834
+ }
1835
+ for (const child of molecule.below.values()) {
1836
+ if (child.dependsOn === `all`) {
1837
+ deallocateFromStore(store, child.key);
1838
+ } else {
1839
+ child.above.delete(molecule.stringKey);
1840
+ if (child.above.size === 0) {
1841
+ deallocateFromStore(store, child.key);
1842
+ }
1843
+ }
1844
+ }
1845
+ molecule.below.clear();
1846
+ const disposalEvent = {
1847
+ type: `molecule_disposal`,
1848
+ subType: `modern`,
1849
+ key: molecule.key,
1850
+ values,
1851
+ provenance
1852
+ };
1853
+ const target = newest$1(store);
1854
+ const isTransaction = isChildStore$1(target) && target.transactionMeta.phase === `building`;
1855
+ if (isTransaction) {
1856
+ target.transactionMeta.update.updates.push(disposalEvent);
1857
+ } else {
1858
+ target.on.moleculeDisposal.next(disposalEvent);
1859
+ }
1860
+ target.molecules.delete(molecule.stringKey);
1861
+ for (const parent of molecule.above.values()) {
1862
+ parent.below.delete(molecule.stringKey);
1863
+ }
1864
+ }
1865
+ var T$ = `T$`;
1866
+
1867
+ // internal/src/ingest-updates/ingest-creation-disposal.ts
1724
1868
  function ingestCreationEvent(update, applying, store) {
1725
1869
  switch (applying) {
1726
1870
  case `newValue`: {
@@ -1758,41 +1902,83 @@ function createInStore(update, store) {
1758
1902
  function ingestMoleculeCreationEvent(update, applying, store) {
1759
1903
  switch (applying) {
1760
1904
  case `newValue`:
1761
- makeMoleculeInStore(
1762
- store,
1763
- update.context,
1764
- update.family,
1765
- update.token.key,
1766
- ...update.params
1767
- );
1905
+ switch (update.subType) {
1906
+ case `classic`:
1907
+ makeMoleculeInStore(
1908
+ store,
1909
+ update.context,
1910
+ update.family,
1911
+ update.token.key,
1912
+ ...update.params
1913
+ );
1914
+ break;
1915
+ case `modern`:
1916
+ allocateIntoStore(store, update.provenance, update.key);
1917
+ break;
1918
+ }
1768
1919
  break;
1769
1920
  case `oldValue`:
1770
- disposeFromStore(store, update.token);
1921
+ switch (update.subType) {
1922
+ case `classic`:
1923
+ disposeFromStore(store, update.token);
1924
+ break;
1925
+ case `modern`:
1926
+ deallocateFromStore(store, update.key);
1927
+ break;
1928
+ }
1771
1929
  break;
1772
1930
  }
1773
1931
  }
1774
1932
  function ingestMoleculeDisposalEvent(update, applying, store) {
1775
1933
  switch (applying) {
1776
1934
  case `newValue`:
1777
- disposeFromStore(store, update.token);
1935
+ switch (update.subType) {
1936
+ case `classic`:
1937
+ disposeFromStore(store, update.token);
1938
+ break;
1939
+ case `modern`:
1940
+ deallocateFromStore(store, update.key);
1941
+ break;
1942
+ }
1778
1943
  break;
1779
1944
  case `oldValue`:
1780
1945
  {
1781
- const moleculeToken = makeMoleculeInStore(
1782
- store,
1783
- update.context,
1784
- update.family,
1785
- update.token.key
1786
- );
1787
- for (const [familyKey, value] of update.values) {
1788
- const memberKey = `${familyKey}(${stringifyJson(moleculeToken.key)})`;
1789
- const molecule = withdraw(moleculeToken, store);
1790
- const alreadyCreated = molecule.tokens.has(memberKey);
1791
- const family = store.families.get(familyKey);
1792
- if (family && !alreadyCreated) {
1793
- growMoleculeInStore(molecule, family, store);
1946
+ switch (update.subType) {
1947
+ case `classic`:
1948
+ {
1949
+ const moleculeToken = makeMoleculeInStore(
1950
+ store,
1951
+ update.context,
1952
+ update.family,
1953
+ update.token.key
1954
+ );
1955
+ for (const [familyKey, value] of update.values) {
1956
+ const memberKey = `${familyKey}(${stringifyJson(moleculeToken.key)})`;
1957
+ const molecule = withdraw(moleculeToken, store);
1958
+ const alreadyCreated = molecule.tokens.has(memberKey);
1959
+ const family = store.families.get(familyKey);
1960
+ if (family && !alreadyCreated) {
1961
+ growMoleculeInStore(molecule, family, store);
1962
+ }
1963
+ store.valueMap.set(memberKey, value);
1964
+ }
1965
+ }
1966
+ break;
1967
+ case `modern`: {
1968
+ allocateIntoStore(
1969
+ store,
1970
+ update.provenance,
1971
+ update.key
1972
+ );
1973
+ for (const [familyKey, value] of update.values) {
1974
+ const family = store.families.get(familyKey);
1975
+ if (family) {
1976
+ findInStore(store, family, update.key);
1977
+ const memberKey = `${familyKey}(${stringifyJson(update.key)})`;
1978
+ store.valueMap.set(memberKey, value);
1979
+ }
1980
+ }
1794
1981
  }
1795
- store.valueMap.set(memberKey, value);
1796
1982
  }
1797
1983
  }
1798
1984
  break;
@@ -2976,7 +3162,7 @@ function disposeAtom(atomToken, store) {
2976
3162
  target.valueMap.delete(key);
2977
3163
  target.selectorAtoms.delete(key);
2978
3164
  target.atomsThatAreDefault.delete(key);
2979
- target.timelineTopics.delete(key);
3165
+ store.timelineTopics.delete(key);
2980
3166
  if (atomToken.type === `mutable_atom`) {
2981
3167
  const updateToken = getUpdateToken(atomToken);
2982
3168
  disposeAtom(updateToken, store);
@@ -3243,71 +3429,77 @@ function addMoleculeFamilyToTimeline(familyToken, tl, store) {
3243
3429
  `got a molecule creation or disposal`,
3244
3430
  creationOrDisposal
3245
3431
  );
3246
- switch (creationOrDisposal.type) {
3247
- case `molecule_creation`:
3248
- {
3249
- store.timelineTopics.set(
3250
- {
3251
- topicKey: creationOrDisposal.token.key,
3252
- timelineKey: tl.key
3253
- },
3254
- { topicType: `molecule` }
3255
- );
3256
- const txUpdateInProgress = newest(store).on.transactionApplying.state?.update;
3257
- if (txUpdateInProgress) {
3258
- joinTransaction(tl, txUpdateInProgress, store);
3259
- } else if (tl.timeTraveling === null) {
3260
- const event = Object.assign(creationOrDisposal, {
3261
- timestamp: Date.now()
3262
- });
3263
- tl.history.push(event);
3264
- tl.at = tl.history.length;
3265
- tl.subject.next(event);
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;
3432
+ if (creationOrDisposal.subType === `classic`) {
3433
+ switch (creationOrDisposal.type) {
3434
+ case `molecule_creation`:
3435
+ {
3436
+ store.timelineTopics.set(
3437
+ {
3438
+ topicKey: creationOrDisposal.token.key,
3439
+ timelineKey: tl.key
3440
+ },
3441
+ { topicType: `molecule` }
3442
+ );
3443
+ const txUpdateInProgress = newest(store).on.transactionApplying.state?.update;
3444
+ if (txUpdateInProgress) {
3445
+ joinTransaction(tl, txUpdateInProgress, store);
3446
+ } else if (tl.timeTraveling === null) {
3447
+ const event = Object.assign(creationOrDisposal, {
3448
+ timestamp: Date.now()
3449
+ });
3450
+ tl.history.push(event);
3451
+ tl.at = tl.history.length;
3452
+ tl.subject.next(event);
3274
3453
  }
3275
- }
3276
- tl.subscriptions.set(
3277
- molecule.key,
3278
- molecule.subject.subscribe(
3279
- `timeline:${tl.key}`,
3280
- (stateCreationOrDisposal) => {
3281
- handleStateLifecycleEvent(stateCreationOrDisposal, tl, store);
3454
+ const molecule = withdraw(creationOrDisposal.token, store);
3455
+ for (const token of molecule.tokens.values()) {
3456
+ switch (token.type) {
3457
+ case `atom`:
3458
+ case `mutable_atom`:
3459
+ addAtomToTimeline(token, tl, store);
3460
+ break;
3282
3461
  }
3283
- )
3284
- );
3285
- }
3286
- break;
3287
- case `molecule_disposal`:
3288
- {
3289
- const txUpdateInProgress = newest(store).on.transactionApplying.state?.update;
3290
- if (txUpdateInProgress) {
3291
- joinTransaction(tl, txUpdateInProgress, store);
3292
- } else if (tl.timeTraveling === null) {
3293
- const event = Object.assign(creationOrDisposal, {
3294
- timestamp: Date.now()
3295
- });
3296
- tl.history.push(event);
3297
- tl.at = tl.history.length;
3298
- tl.subject.next(event);
3462
+ }
3463
+ tl.subscriptions.set(
3464
+ molecule.key,
3465
+ molecule.subject.subscribe(
3466
+ `timeline:${tl.key}`,
3467
+ (stateCreationOrDisposal) => {
3468
+ handleStateLifecycleEvent(
3469
+ stateCreationOrDisposal,
3470
+ tl,
3471
+ store
3472
+ );
3473
+ }
3474
+ )
3475
+ );
3299
3476
  }
3300
- const moleculeKey = creationOrDisposal.token.key;
3301
- tl.subscriptions.get(moleculeKey)?.();
3302
- tl.subscriptions.delete(moleculeKey);
3303
- for (const [familyKey] of creationOrDisposal.values) {
3304
- const stateKey = `${familyKey}(${stringifyJson(moleculeKey)})`;
3305
- tl.subscriptions.get(stateKey)?.();
3306
- tl.subscriptions.delete(stateKey);
3307
- store.timelineTopics.delete(stateKey);
3477
+ break;
3478
+ case `molecule_disposal`:
3479
+ {
3480
+ const txUpdateInProgress = newest(store).on.transactionApplying.state?.update;
3481
+ if (txUpdateInProgress) {
3482
+ joinTransaction(tl, txUpdateInProgress, store);
3483
+ } else if (tl.timeTraveling === null) {
3484
+ const event = Object.assign(creationOrDisposal, {
3485
+ timestamp: Date.now()
3486
+ });
3487
+ tl.history.push(event);
3488
+ tl.at = tl.history.length;
3489
+ tl.subject.next(event);
3490
+ }
3491
+ const moleculeKey = stringifyJson(creationOrDisposal.token.key);
3492
+ tl.subscriptions.get(moleculeKey)?.();
3493
+ tl.subscriptions.delete(moleculeKey);
3494
+ for (const [familyKey] of creationOrDisposal.values) {
3495
+ const stateKey = `${familyKey}(${stringifyJson(moleculeKey)})`;
3496
+ tl.subscriptions.get(stateKey)?.();
3497
+ tl.subscriptions.delete(stateKey);
3498
+ store.timelineTopics.delete(stateKey);
3499
+ }
3308
3500
  }
3309
- }
3310
- break;
3501
+ break;
3502
+ }
3311
3503
  }
3312
3504
  })
3313
3505
  );
@@ -3359,17 +3551,32 @@ function filterTransactionUpdates(updates, timelineTopics) {
3359
3551
  return true;
3360
3552
  }
3361
3553
  let key;
3554
+ let familyKey;
3362
3555
  switch (updateFromTx.type) {
3363
3556
  case `state_creation`:
3364
3557
  case `state_disposal`:
3558
+ key = updateFromTx.token.key;
3559
+ familyKey = updateFromTx.token.family?.key;
3560
+ break;
3365
3561
  case `molecule_creation`:
3366
3562
  case `molecule_disposal`:
3367
- key = updateFromTx.token.key;
3563
+ switch (updateFromTx.subType) {
3564
+ case `classic`:
3565
+ key = updateFromTx.token.key;
3566
+ break;
3567
+ case `modern`:
3568
+ return true;
3569
+ }
3368
3570
  break;
3369
3571
  default:
3370
3572
  key = updateFromTx.key;
3573
+ familyKey = updateFromTx.family?.key;
3371
3574
  break;
3372
3575
  }
3576
+ timelineTopics.has(key);
3577
+ if (familyKey && timelineTopics.has(familyKey)) {
3578
+ return true;
3579
+ }
3373
3580
  return timelineTopics.has(key);
3374
3581
  }).map((updateFromTx) => {
3375
3582
  if (`updates` in updateFromTx) {
@@ -3390,13 +3597,16 @@ function handleStateLifecycleEvent(event, tl, store) {
3390
3597
  timestamp
3391
3598
  });
3392
3599
  if (!tl.timeTraveling) {
3393
- const txUpdateInProgress = newest(store).on.transactionApplying.state?.update;
3394
- if (txUpdateInProgress) {
3395
- joinTransaction(tl, txUpdateInProgress, store);
3396
- } else {
3397
- tl.history.push(timelineEvent);
3398
- tl.at = tl.history.length;
3399
- tl.subject.next(timelineEvent);
3600
+ const target = newest(store);
3601
+ if (isChildStore(target)) ; else {
3602
+ const txUpdateInProgress = target.on.transactionApplying.state;
3603
+ if (txUpdateInProgress) {
3604
+ joinTransaction(tl, txUpdateInProgress.update, store);
3605
+ } else {
3606
+ tl.history.push(timelineEvent);
3607
+ tl.at = tl.history.length;
3608
+ tl.subject.next(timelineEvent);
3609
+ }
3400
3610
  }
3401
3611
  }
3402
3612
  switch (event.type) {
@@ -0,0 +1,20 @@
1
+ import { createMoleculeFamily, IMPLICIT, makeMoleculeInStore, Molecule } from 'atom.io/internal';
2
+ import { stringifyJson } from 'atom.io/json';
3
+
4
+ // src/molecule.ts
5
+ function moleculeFamily(options) {
6
+ return createMoleculeFamily(IMPLICIT.STORE, options);
7
+ }
8
+ function makeMolecule(context, family, key, ...params) {
9
+ return makeMoleculeInStore(IMPLICIT.STORE, context, family, key, ...params);
10
+ }
11
+ function makeRootMoleculeInStore(key, store = IMPLICIT.STORE) {
12
+ const molecule = new Molecule(void 0, key);
13
+ store.molecules.set(stringifyJson(key), molecule);
14
+ return {
15
+ key,
16
+ type: `molecule`
17
+ };
18
+ }
19
+
20
+ export { makeMolecule, makeRootMoleculeInStore, moleculeFamily };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Transceiver, Func, EnvironmentData, Flat, Subject, Store, 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, MoleculeCreation as MoleculeCreation$1, MoleculeDisposal as MoleculeDisposal$1 } from 'atom.io';
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 MoleculeCreation<M extends MoleculeConstructor$1> = {
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 MoleculeDisposal = {
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`;
@@ -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<MoleculeCreation$1<M> | MoleculeDisposal$1>;
230
+ subject: Subject<MoleculeCreationClassic$1<M> | MoleculeDisposalClassic$1>;
214
231
  dependsOn: `all` | `any`;
215
232
  new: M;
216
233
  }>;
@@ -224,7 +241,7 @@ 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 makeRootMolecule(key: string, store?: Store): MoleculeToken<ObjectConstructor>;
244
+ declare function makeRootMoleculeInStore(key: string, store?: Store): MoleculeToken<ObjectConstructor>;
228
245
 
229
246
  declare function disposeState(token: MoleculeToken<any> | ReadableToken<any>): void;
230
247
  declare function disposeState<K extends Canonical>(token: ReadableFamilyToken<any, K>, key: K): void;
@@ -427,4 +444,4 @@ type FamilyMetadata<K extends Canonical = any> = {
427
444
  subKey: stringified<K>;
428
445
  };
429
446
 
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, makeRootMolecule, moleculeFamily, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
447
+ 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 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 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, makeRootMoleculeInStore, moleculeFamily, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
+ export { makeMolecule, makeRootMoleculeInStore, moleculeFamily } from './chunk-ZKG6ZA4I.js';
1
2
  import './chunk-XWL6SNVU.js';
2
3
  import * as Internal from 'atom.io/internal';
3
- import { createStandaloneAtom, IMPLICIT, createAtomFamily, createMoleculeFamily, makeMoleculeInStore, Molecule, createStandaloneSelector, createSelectorFamily, Store, createTransaction, createTimeline, findInStore, getFromStore, setIntoStore, disposeFromStore, subscribeInStore, timeTravel, actUponStore, arbitrary } from 'atom.io/internal';
4
- import { stringifyJson } from 'atom.io/json';
4
+ import { createStandaloneAtom, IMPLICIT, createAtomFamily, createStandaloneSelector, createSelectorFamily, Store, createTransaction, createTimeline, findInStore, getFromStore, setIntoStore, disposeFromStore, subscribeInStore, timeTravel, createMoleculeFamily, makeMoleculeInStore, actUponStore, arbitrary } from 'atom.io/internal';
5
5
 
6
6
  function atom(options) {
7
7
  return createStandaloneAtom(IMPLICIT.STORE, options);
@@ -58,20 +58,6 @@ var AtomIOLogger = class {
58
58
  }
59
59
  };
60
60
  };
61
- function moleculeFamily(options) {
62
- return createMoleculeFamily(IMPLICIT.STORE, options);
63
- }
64
- function makeMolecule(context, family, key, ...params) {
65
- return makeMoleculeInStore(IMPLICIT.STORE, context, family, key, ...params);
66
- }
67
- function makeRootMolecule(key, store = IMPLICIT.STORE) {
68
- const molecule = new Molecule(void 0, key);
69
- store.molecules.set(stringifyJson(key), molecule);
70
- return {
71
- key,
72
- type: `molecule`
73
- };
74
- }
75
61
  function selector(options) {
76
62
  return createStandaloneSelector(IMPLICIT.STORE, options);
77
63
  }
@@ -163,4 +149,4 @@ function belongsTo(family, unknownToken) {
163
149
  return family.key === unknownToken.family?.key;
164
150
  }
165
151
 
166
- export { AtomIOLogger, LOG_LEVELS, Silo, atom, atomFamily, belongsTo, disposeState, getState, isToken, makeMolecule, makeRootMolecule, moleculeFamily, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
152
+ export { AtomIOLogger, LOG_LEVELS, Silo, atom, atomFamily, belongsTo, disposeState, getState, isToken, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };