atom.io 0.27.1 → 0.27.3

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.
Files changed (45) hide show
  1. package/data/dist/index.d.ts +12 -12
  2. package/data/dist/index.js +20 -14
  3. package/data/src/dict.ts +4 -4
  4. package/data/src/join.ts +23 -18
  5. package/data/src/struct-family.ts +2 -2
  6. package/dist/chunk-ETCFHO7J.js +3087 -0
  7. package/dist/index.d.ts +4 -31
  8. package/eslint-plugin/dist/index.js +8 -0
  9. package/eslint-plugin/src/walk.ts +8 -0
  10. package/internal/dist/index.d.ts +52 -19
  11. package/internal/dist/index.js +2 -3044
  12. package/internal/src/families/create-atom-family.ts +6 -5
  13. package/internal/src/families/create-readonly-selector-family.ts +38 -29
  14. package/internal/src/families/create-regular-atom-family.ts +40 -31
  15. package/internal/src/families/create-selector-family.ts +6 -5
  16. package/internal/src/families/create-writable-selector-family.ts +39 -30
  17. package/internal/src/families/throw-in-case-of-conflicting-family.ts +18 -0
  18. package/internal/src/index.ts +76 -2
  19. package/internal/src/ingest-updates/ingest-creation-disposal.ts +0 -1
  20. package/internal/src/ingest-updates/ingest-selector-update.ts +1 -1
  21. package/internal/src/molecule/dispose-molecule.ts +0 -1
  22. package/internal/src/molecule/grow-molecule-in-store.ts +27 -17
  23. package/internal/src/mutable/create-mutable-atom-family.ts +41 -32
  24. package/internal/src/mutable/get-json-family.ts +2 -1
  25. package/internal/src/mutable/get-update-family.ts +23 -0
  26. package/internal/src/mutable/index.ts +1 -0
  27. package/internal/src/mutable/tracker-family.ts +5 -3
  28. package/internal/src/not-found-error.ts +2 -35
  29. package/internal/src/pretty-print.ts +37 -0
  30. package/internal/src/store/store.ts +10 -4
  31. package/internal/src/store/withdraw.ts +8 -8
  32. package/introspection/dist/index.js +3 -3
  33. package/introspection/src/attach-timeline-family.ts +1 -1
  34. package/introspection/src/attach-transaction-logs.ts +2 -2
  35. package/json/dist/index.d.ts +2 -2
  36. package/json/dist/index.js +16 -12
  37. package/json/src/select-json-family.ts +21 -18
  38. package/package.json +4 -4
  39. package/realtime-server/dist/index.d.ts +1 -1
  40. package/src/atom.ts +2 -32
  41. package/src/get-state.ts +2 -2
  42. package/src/index.ts +1 -10
  43. package/src/selector.ts +1 -26
  44. package/src/set-state.ts +2 -2
  45. package/src/silo.ts +7 -5
@@ -1,7 +1,7 @@
1
1
  import type {
2
2
  FamilyMetadata,
3
- MutableAtomFamily,
4
3
  MutableAtomFamilyOptions,
4
+ MutableAtomFamilyToken,
5
5
  MutableAtomOptions,
6
6
  MutableAtomToken,
7
7
  StateCreation,
@@ -10,6 +10,8 @@ import type {
10
10
  import type { Json } from "atom.io/json"
11
11
  import { selectJsonFamily, stringifyJson } from "atom.io/json"
12
12
 
13
+ import type { MutableAtomFamily } from ".."
14
+ import { throwInCaseOfConflictingFamily } from "../families/throw-in-case-of-conflicting-family"
13
15
  import { newest } from "../lineage"
14
16
  import { createMutableAtom } from "../mutable"
15
17
  import type { Store } from "../store"
@@ -24,45 +26,52 @@ export function createMutableAtomFamily<
24
26
  >(
25
27
  options: MutableAtomFamilyOptions<T, J, K>,
26
28
  store: Store,
27
- ): MutableAtomFamily<T, J, K> {
29
+ internalRoles?: string[],
30
+ ): MutableAtomFamilyToken<T, J, K> {
31
+ const familyToken = {
32
+ key: options.key,
33
+ type: `mutable_atom_family`,
34
+ } as const satisfies MutableAtomFamilyToken<T, J, K>
35
+
36
+ throwInCaseOfConflictingFamily(familyToken, store)
37
+
28
38
  const subject = new Subject<
29
39
  StateCreation<MutableAtomToken<T, J>> | StateDisposal<MutableAtomToken<T, J>>
30
40
  >()
31
41
 
32
- const atomFamily = Object.assign(
33
- (key: K): MutableAtomToken<T, J> => {
34
- const subKey = stringifyJson(key)
35
- const family: FamilyMetadata = { key: options.key, subKey }
36
- const fullKey = `${options.key}(${subKey})`
37
- const target = newest(store)
38
-
39
- const individualOptions: MutableAtomOptions<T, J> = {
40
- key: fullKey,
41
- default: () => options.default(key),
42
- toJson: options.toJson,
43
- fromJson: options.fromJson,
44
- mutable: true,
45
- }
46
- if (options.effects) {
47
- individualOptions.effects = options.effects(key)
48
- }
49
-
50
- const token = createMutableAtom(individualOptions, family, target)
42
+ const familyFunction = (key: K): MutableAtomToken<T, J> => {
43
+ const subKey = stringifyJson(key)
44
+ const family: FamilyMetadata = { key: options.key, subKey }
45
+ const fullKey = `${options.key}(${subKey})`
46
+ const target = newest(store)
51
47
 
52
- subject.next({ type: `state_creation`, token })
53
- return token
54
- },
55
- {
56
- key: options.key,
57
- type: `mutable_atom_family`,
58
- subject,
59
- install: (s: Store) => createMutableAtomFamily(options, s),
48
+ const individualOptions: MutableAtomOptions<T, J> = {
49
+ key: fullKey,
50
+ default: () => options.default(key),
60
51
  toJson: options.toJson,
61
52
  fromJson: options.fromJson,
62
- } as const,
63
- ) satisfies MutableAtomFamily<T, J, K>
53
+ mutable: true,
54
+ }
55
+ if (options.effects) {
56
+ individualOptions.effects = options.effects(key)
57
+ }
58
+
59
+ const token = createMutableAtom(individualOptions, family, target)
60
+
61
+ subject.next({ type: `state_creation`, token })
62
+ return token
63
+ }
64
+
65
+ const atomFamily = Object.assign(familyFunction, familyToken, {
66
+ subject,
67
+ install: (s: Store) => createMutableAtomFamily(options, s),
68
+ toJson: options.toJson,
69
+ fromJson: options.fromJson,
70
+ internalRoles,
71
+ }) satisfies MutableAtomFamily<T, J, K>
72
+
64
73
  store.families.set(options.key, atomFamily)
65
74
  selectJsonFamily(atomFamily, options, store)
66
75
  new FamilyTracker(atomFamily, store)
67
- return atomFamily
76
+ return familyToken
68
77
  }
@@ -1,6 +1,7 @@
1
- import type { MutableAtomFamilyToken, WritableSelectorFamily } from "atom.io"
1
+ import type { MutableAtomFamilyToken } from "atom.io"
2
2
  import type { Json } from "atom.io/json"
3
3
 
4
+ import type { WritableSelectorFamily } from ".."
4
5
  import { newest } from "../lineage"
5
6
  import type { Store } from "../store"
6
7
  import type { Transceiver } from "./transceiver"
@@ -0,0 +1,23 @@
1
+ import type { MutableAtomFamilyToken } from "atom.io"
2
+ import type { Json } from "atom.io/json"
3
+
4
+ import type { AtomFamily } from ".."
5
+ import { newest } from "../lineage"
6
+ import type { Store } from "../store"
7
+ import type { Signal, Transceiver } from "./transceiver"
8
+
9
+ export const getUpdateFamily = <
10
+ Core extends Transceiver<Json.Serializable>,
11
+ SerializableCore extends Json.Serializable,
12
+ Key extends string,
13
+ >(
14
+ mutableAtomFamily: MutableAtomFamilyToken<Core, SerializableCore, Key>,
15
+ store: Store,
16
+ ): AtomFamily<Signal<Core>, Key> => {
17
+ const target = newest(store)
18
+ const key = `*${mutableAtomFamily.key}`
19
+ const updateFamily: AtomFamily<Signal<Core>, Key> = target.families.get(
20
+ key,
21
+ ) as AtomFamily<Signal<Core>, Key>
22
+ return updateFamily
23
+ }
@@ -2,6 +2,7 @@ export * from "./create-mutable-atom"
2
2
  export * from "./create-mutable-atom-family"
3
3
  export * from "./get-json-family"
4
4
  export * from "./get-json-token"
5
+ export * from "./get-update-family"
5
6
  export * from "./get-update-token"
6
7
  export * from "./tracker"
7
8
  export * from "./tracker-family"
@@ -1,9 +1,9 @@
1
- import type { MutableAtomFamily, RegularAtomFamily } from "atom.io"
2
1
  import type { Canonical } from "atom.io/json"
3
2
  import { parseJson } from "atom.io/json"
4
3
 
4
+ import type { MutableAtomFamily, RegularAtomFamily } from ".."
5
5
  import { createRegularAtomFamily, seekInStore } from "../families"
6
- import type { Store } from "../store"
6
+ import { type Store, withdraw } from "../store"
7
7
  import { Tracker } from "./tracker"
8
8
  import type { Transceiver } from "./transceiver"
9
9
 
@@ -25,7 +25,7 @@ export class FamilyTracker<
25
25
  mutableAtoms: MutableAtomFamily<Core, any, FamilyMemberKey>,
26
26
  store: Store,
27
27
  ) {
28
- this.latestUpdateAtoms = createRegularAtomFamily<
28
+ const updateAtoms = createRegularAtomFamily<
29
29
  typeof this.Update | null,
30
30
  FamilyMemberKey
31
31
  >(
@@ -34,7 +34,9 @@ export class FamilyTracker<
34
34
  default: null,
35
35
  },
36
36
  store,
37
+ [`mutable`, `updates`],
37
38
  )
39
+ this.latestUpdateAtoms = withdraw(updateAtoms, store)
38
40
  this.mutableAtoms = mutableAtoms
39
41
  this.mutableAtoms.subject.subscribe(
40
42
  `store=${store.config.name}::tracker-atom-family`,
@@ -1,42 +1,9 @@
1
- import type {
2
- MoleculeFamilyToken,
3
- MoleculeToken,
4
- ReadableFamilyToken,
5
- ReadableToken,
6
- TimelineToken,
7
- TransactionToken,
8
- } from "atom.io"
9
1
  import { type Json, stringifyJson } from "atom.io/json"
10
2
 
3
+ import type { AtomIOToken } from "./pretty-print"
4
+ import { prettyPrintTokenType } from "./pretty-print"
11
5
  import type { Store } from "./store"
12
6
 
13
- const capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)
14
-
15
- type AtomIOToken =
16
- | MoleculeFamilyToken<any>
17
- | MoleculeToken<any>
18
- | ReadableFamilyToken<any, any>
19
- | ReadableToken<any>
20
- | TimelineToken<any>
21
- | TransactionToken<any>
22
-
23
- function prettyPrintTokenType(token: AtomIOToken) {
24
- switch (token.type) {
25
- case `atom_family`:
26
- return `Atom Family`
27
- case `molecule_family`:
28
- return `Molecule Family`
29
- case `readonly_selector`:
30
- return `Readonly Selector`
31
- case `readonly_selector_family`:
32
- return `Readonly Selector Family`
33
- case `selector_family`:
34
- return `Selector Family`
35
- default:
36
- return capitalize(token.type)
37
- }
38
- }
39
-
40
7
  export class NotFoundError extends Error {
41
8
  public constructor(token: AtomIOToken, store: Store)
42
9
  public constructor(
@@ -0,0 +1,37 @@
1
+ import type {
2
+ MoleculeFamilyToken,
3
+ MoleculeToken,
4
+ ReadableFamilyToken,
5
+ ReadableToken,
6
+ TimelineToken,
7
+ TransactionToken,
8
+ } from "atom.io"
9
+
10
+ const capitalize = (str: string) => str[0].toUpperCase() + str.slice(1)
11
+
12
+ export type AtomIOToken =
13
+ | MoleculeFamilyToken<any>
14
+ | MoleculeToken<any>
15
+ | ReadableFamilyToken<any, any>
16
+ | ReadableToken<any>
17
+ | TimelineToken<any>
18
+ | TransactionToken<any>
19
+
20
+ export function prettyPrintTokenType(token: AtomIOToken): string {
21
+ switch (token.type) {
22
+ case `atom_family`:
23
+ return `Atom Family`
24
+ case `molecule_family`:
25
+ return `Molecule Family`
26
+ case `mutable_atom_family`:
27
+ return `Mutable Atom Family`
28
+ case `readonly_selector`:
29
+ return `Readonly Selector`
30
+ case `readonly_selector_family`:
31
+ return `Readonly Selector Family`
32
+ case `selector_family`:
33
+ return `Selector Family`
34
+ default:
35
+ return capitalize(token.type)
36
+ }
37
+ }
@@ -3,13 +3,9 @@ import type {
3
3
  Logger,
4
4
  MoleculeFamily,
5
5
  MoleculeToken,
6
- MutableAtomFamily,
7
- ReadonlySelectorFamily,
8
6
  ReadonlySelectorToken,
9
- RegularAtomFamily,
10
7
  TimelineToken,
11
8
  TransactionToken,
12
- WritableSelectorFamily,
13
9
  WritableSelectorToken,
14
10
  } from "atom.io"
15
11
  import { AtomIOLogger } from "atom.io"
@@ -20,10 +16,14 @@ import type {
20
16
  Atom,
21
17
  Func,
22
18
  Molecule,
19
+ MutableAtomFamily,
23
20
  ReadonlySelector,
21
+ ReadonlySelectorFamily,
22
+ RegularAtomFamily,
24
23
  Tracker,
25
24
  Transceiver,
26
25
  WritableSelector,
26
+ WritableSelectorFamily,
27
27
  } from ".."
28
28
  import type { Lineage } from "../lineage"
29
29
  import { getJsonToken, getUpdateToken } from "../mutable"
@@ -160,6 +160,12 @@ export class Store implements Lineage {
160
160
  }
161
161
 
162
162
  for (const [, family] of store.families) {
163
+ if (
164
+ family.internalRoles?.includes(`mutable`) ||
165
+ family.internalRoles?.includes(`join`)
166
+ ) {
167
+ continue
168
+ }
163
169
  family.install(this)
164
170
  }
165
171
  const mutableHelpers = new Set<string>()
@@ -1,32 +1,24 @@
1
1
  import type {
2
- AtomFamily,
3
2
  AtomFamilyToken,
4
3
  AtomToken,
5
4
  MoleculeConstructor,
6
5
  MoleculeFamily,
7
6
  MoleculeFamilyToken,
8
7
  MoleculeToken,
9
- MutableAtomFamily,
10
8
  MutableAtomFamilyToken,
11
9
  MutableAtomToken,
12
- ReadableFamily,
13
10
  ReadableFamilyToken,
14
11
  ReadableToken,
15
- ReadonlySelectorFamily,
16
12
  ReadonlySelectorFamilyToken,
17
13
  ReadonlySelectorToken,
18
- RegularAtomFamily,
19
14
  RegularAtomFamilyToken,
20
15
  RegularAtomToken,
21
- SelectorFamily,
22
16
  SelectorFamilyToken,
23
17
  SelectorToken,
24
18
  TimelineManageable,
25
19
  TimelineToken,
26
20
  TransactionToken,
27
- WritableFamily,
28
21
  WritableFamilyToken,
29
- WritableSelectorFamily,
30
22
  WritableSelectorFamilyToken,
31
23
  WritableSelectorToken,
32
24
  WritableToken,
@@ -36,15 +28,23 @@ import { stringifyJson } from "atom.io/json"
36
28
 
37
29
  import type {
38
30
  Atom,
31
+ AtomFamily,
39
32
  Func,
40
33
  Molecule,
41
34
  MutableAtom,
35
+ MutableAtomFamily,
36
+ ReadableFamily,
42
37
  ReadableState,
43
38
  ReadonlySelector,
39
+ ReadonlySelectorFamily,
44
40
  RegularAtom,
41
+ RegularAtomFamily,
45
42
  Selector,
43
+ SelectorFamily,
46
44
  Transceiver,
45
+ WritableFamily,
47
46
  WritableSelector,
47
+ WritableSelectorFamily,
48
48
  WritableState,
49
49
  } from ".."
50
50
  import { NotFoundError } from ".."
@@ -204,7 +204,7 @@ var attachTimelineFamily = (store = IMPLICIT.STORE) => {
204
204
  const findTimelineLogState = createSelectorFamily(
205
205
  {
206
206
  key: `\u{1F441}\u200D\u{1F5E8} Timeline Update Log`,
207
- get: (key) => ({ get }) => get(findTimelineLogState__INTERNAL(key))
207
+ get: (key) => ({ get }) => get(findTimelineLogState__INTERNAL, key)
208
208
  },
209
209
  store
210
210
  );
@@ -271,7 +271,7 @@ var attachTransactionIndex = (store = IMPLICIT.STORE) => {
271
271
  return transactionTokenIndex;
272
272
  };
273
273
  var attachTransactionLogs = (store = IMPLICIT.STORE) => {
274
- const findTransactionUpdateLog = createRegularAtomFamily(
274
+ const transactionUpdateLogAtoms = createRegularAtomFamily(
275
275
  {
276
276
  key: `\u{1F441}\u200D\u{1F5E8} Transaction Update Log (Internal)`,
277
277
  default: () => [],
@@ -291,7 +291,7 @@ var attachTransactionLogs = (store = IMPLICIT.STORE) => {
291
291
  const findTransactionUpdateLogState = createSelectorFamily(
292
292
  {
293
293
  key: `\u{1F441}\u200D\u{1F5E8} Transaction Update Log`,
294
- get: (key) => ({ get }) => get(findTransactionUpdateLog(key))
294
+ get: (key) => ({ get }) => get(transactionUpdateLogAtoms, key)
295
295
  },
296
296
  store
297
297
  );
@@ -46,7 +46,7 @@ export const attachTimelineFamily = (
46
46
  get:
47
47
  (key) =>
48
48
  ({ get }) =>
49
- get(findTimelineLogState__INTERNAL(key)),
49
+ get(findTimelineLogState__INTERNAL, key),
50
50
  },
51
51
  store,
52
52
  )
@@ -9,7 +9,7 @@ import {
9
9
  export const attachTransactionLogs = (
10
10
  store: Store = IMPLICIT.STORE,
11
11
  ): ReadonlySelectorFamilyToken<TransactionUpdate<Func>[], string> => {
12
- const findTransactionUpdateLog = createRegularAtomFamily<
12
+ const transactionUpdateLogAtoms = createRegularAtomFamily<
13
13
  TransactionUpdate<Func>[],
14
14
  string
15
15
  >(
@@ -38,7 +38,7 @@ export const attachTransactionLogs = (
38
38
  get:
39
39
  (key) =>
40
40
  ({ get }) =>
41
- get(findTransactionUpdateLog(key)),
41
+ get(transactionUpdateLogAtoms, key),
42
42
  },
43
43
  store,
44
44
  )
@@ -38,8 +38,8 @@ declare function fromEntries<E extends Entries>(entries: E): FromEntries<E>;
38
38
 
39
39
  declare const selectJson: <T, J extends Serializable>(atom: AtomIO.AtomToken<T>, transform: JsonInterface<T, J>, store?: Store) => AtomIO.WritableSelectorToken<J>;
40
40
 
41
- declare function selectJsonFamily<T extends Transceiver<any>, J extends Serializable, K extends Canonical>(atomFamily: AtomIO.MutableAtomFamily<T, J, K>, transform: JsonInterface<T, J>, store: Store): AtomIO.WritableSelectorFamily<J, K>;
42
- declare function selectJsonFamily<T, J extends Serializable, K extends Canonical>(atomFamily: AtomIO.RegularAtomFamily<T, K>, transform: JsonInterface<T, J>, store: Store): AtomIO.WritableSelectorFamily<J, K>;
41
+ declare function selectJsonFamily<T extends Transceiver<any>, J extends Serializable, K extends Canonical>(atomFamilyToken: AtomIO.MutableAtomFamilyToken<T, J, K>, transform: JsonInterface<T, J>, store: Store): AtomIO.WritableSelectorFamilyToken<J, K>;
42
+ declare function selectJsonFamily<T, J extends Serializable, K extends Canonical>(atomFamilyToken: AtomIO.RegularAtomFamilyToken<T, K>, transform: JsonInterface<T, J>, store: Store): AtomIO.WritableSelectorFamilyToken<J, K>;
43
43
 
44
44
  type Canonical = primitive | ReadonlyArray<Canonical>;
45
45
  type JsonIO = (...params: Serializable[]) => Serializable | void;
@@ -1,7 +1,9 @@
1
1
  import { stringifyJson, parseJson } from '../../dist/chunk-AK23DRMD.js';
2
2
  export { parseJson, stringifyJson } from '../../dist/chunk-AK23DRMD.js';
3
+ import { createWritableSelectorFamily } from '../../dist/chunk-ETCFHO7J.js';
4
+ import '../../dist/chunk-IBTHB2PI.js';
3
5
  import '../../dist/chunk-XWL6SNVU.js';
4
- import { createStandaloneSelector, IMPLICIT, createSelectorFamily, growMoleculeInStore, initFamilyMemberInStore, seekInStore } from 'atom.io/internal';
6
+ import { createStandaloneSelector, IMPLICIT, growMoleculeInStore, initFamilyMemberInStore, withdraw, seekInStore } from 'atom.io/internal';
5
7
 
6
8
  // json/src/entries.ts
7
9
  function fromEntries(entries) {
@@ -19,52 +21,54 @@ var selectJson = (atom, transform, store = IMPLICIT.STORE) => {
19
21
  store
20
22
  );
21
23
  };
22
- function selectJsonFamily(family, transform, store = IMPLICIT.STORE) {
23
- const jsonFamily = createSelectorFamily(
24
+ function selectJsonFamily(atomFamilyToken, transform, store = IMPLICIT.STORE) {
25
+ const jsonFamily = createWritableSelectorFamily(
24
26
  {
25
- key: `${family.key}:JSON`,
27
+ key: `${atomFamilyToken.key}:JSON`,
26
28
  get: (key) => ({ seek, get }) => {
27
- const existingState = seek(family, key);
29
+ const existingState = seek(atomFamilyToken, key);
28
30
  if (existingState) {
29
31
  return transform.toJson(get(existingState));
30
32
  }
31
33
  const stringKey = stringifyJson(key);
32
34
  const molecule = store.molecules.get(stringKey);
33
35
  if (molecule) {
34
- const atom = growMoleculeInStore(molecule, family, store);
36
+ const atom = growMoleculeInStore(molecule, atomFamilyToken, store);
35
37
  return transform.toJson(get(atom));
36
38
  }
37
39
  if (store.config.lifespan === `immortal`) {
38
40
  throw new Error(`No molecule found for key "${stringKey}"`);
39
41
  }
40
- const newToken = initFamilyMemberInStore(family, key, store);
42
+ const newToken = initFamilyMemberInStore(atomFamilyToken, key, store);
41
43
  return transform.toJson(get(newToken));
42
44
  },
43
45
  set: (key) => ({ seek, set }, newValue) => {
44
- const existingState = seek(family, key);
46
+ const existingState = seek(atomFamilyToken, key);
45
47
  if (existingState) {
46
48
  set(existingState, transform.fromJson(newValue));
47
49
  } else {
48
50
  const stringKey = stringifyJson(key);
49
51
  const molecule = store.molecules.get(stringKey);
50
52
  if (molecule) {
51
- const atom = growMoleculeInStore(molecule, family, store);
53
+ const atom = growMoleculeInStore(molecule, atomFamilyToken, store);
52
54
  set(atom, transform.fromJson(newValue));
53
55
  } else {
54
56
  if (store.config.lifespan === `immortal`) {
55
57
  throw new Error(`No molecule found for key "${stringKey}"`);
56
58
  }
57
59
  set(
58
- initFamilyMemberInStore(family, key, store),
60
+ initFamilyMemberInStore(atomFamilyToken, key, store),
59
61
  transform.fromJson(newValue)
60
62
  );
61
63
  }
62
64
  }
63
65
  }
64
66
  },
65
- store
67
+ store,
68
+ [`mutable`, `json`]
66
69
  );
67
- family.subject.subscribe(
70
+ const atomFamily = withdraw(atomFamilyToken, store);
71
+ atomFamily.subject.subscribe(
68
72
  `store=${store.config.name}::json-selector-family`,
69
73
  (event) => {
70
74
  if (event.token.family) {
@@ -1,13 +1,14 @@
1
1
  import type * as AtomIO from "atom.io"
2
2
  import type { Store, Transceiver } from "atom.io/internal"
3
3
  import {
4
- createSelectorFamily,
5
4
  growMoleculeInStore,
6
5
  IMPLICIT,
7
6
  initFamilyMemberInStore,
8
7
  seekInStore,
8
+ withdraw,
9
9
  } from "atom.io/internal"
10
10
 
11
+ import { createWritableSelectorFamily } from "../../internal/src/families/create-writable-selector-family"
11
12
  import type { Canonical, Json, JsonInterface } from "."
12
13
  import { parseJson, stringifyJson } from "."
13
14
 
@@ -16,70 +17,70 @@ export function selectJsonFamily<
16
17
  J extends Json.Serializable,
17
18
  K extends Canonical,
18
19
  >(
19
- atomFamily: AtomIO.MutableAtomFamily<T, J, K>,
20
+ atomFamilyToken: AtomIO.MutableAtomFamilyToken<T, J, K>,
20
21
  transform: JsonInterface<T, J>,
21
22
  store: Store,
22
- ): AtomIO.WritableSelectorFamily<J, K>
23
+ ): AtomIO.WritableSelectorFamilyToken<J, K>
23
24
  export function selectJsonFamily<
24
25
  T,
25
26
  J extends Json.Serializable,
26
27
  K extends Canonical,
27
28
  >(
28
- atomFamily: AtomIO.RegularAtomFamily<T, K>,
29
+ atomFamilyToken: AtomIO.RegularAtomFamilyToken<T, K>,
29
30
  transform: JsonInterface<T, J>,
30
31
  store: Store,
31
- ): AtomIO.WritableSelectorFamily<J, K>
32
+ ): AtomIO.WritableSelectorFamilyToken<J, K>
32
33
  export function selectJsonFamily<
33
34
  T,
34
35
  J extends Json.Serializable,
35
36
  K extends Canonical,
36
37
  >(
37
- family:
38
- | AtomIO.MutableAtomFamily<T extends Transceiver<any> ? T : never, J, K>
39
- | AtomIO.RegularAtomFamily<T, K>,
38
+ atomFamilyToken:
39
+ | AtomIO.MutableAtomFamilyToken<T extends Transceiver<any> ? T : never, J, K>
40
+ | AtomIO.RegularAtomFamilyToken<T, K>,
40
41
  transform: JsonInterface<T, J>,
41
42
  store: Store = IMPLICIT.STORE,
42
- ): AtomIO.WritableSelectorFamily<J, K> {
43
- const jsonFamily = createSelectorFamily<J, K>(
43
+ ): AtomIO.WritableSelectorFamilyToken<J, K> {
44
+ const jsonFamily = createWritableSelectorFamily<J, K>(
44
45
  {
45
- key: `${family.key}:JSON`,
46
+ key: `${atomFamilyToken.key}:JSON`,
46
47
  get:
47
48
  (key) =>
48
49
  ({ seek, get }) => {
49
- const existingState = seek(family, key)
50
+ const existingState = seek(atomFamilyToken, key)
50
51
  if (existingState) {
51
52
  return transform.toJson(get(existingState))
52
53
  }
53
54
  const stringKey = stringifyJson(key)
54
55
  const molecule = store.molecules.get(stringKey)
55
56
  if (molecule) {
56
- const atom = growMoleculeInStore(molecule, family, store)
57
+ const atom = growMoleculeInStore(molecule, atomFamilyToken, store)
57
58
  return transform.toJson(get(atom))
58
59
  }
59
60
  if (store.config.lifespan === `immortal`) {
60
61
  throw new Error(`No molecule found for key "${stringKey}"`)
61
62
  }
62
- const newToken = initFamilyMemberInStore(family, key, store)
63
+ const newToken = initFamilyMemberInStore(atomFamilyToken, key, store)
63
64
  return transform.toJson(get(newToken))
64
65
  },
65
66
  set:
66
67
  (key) =>
67
68
  ({ seek, set }, newValue) => {
68
- const existingState = seek(family, key)
69
+ const existingState = seek(atomFamilyToken, key)
69
70
  if (existingState) {
70
71
  set(existingState, transform.fromJson(newValue))
71
72
  } else {
72
73
  const stringKey = stringifyJson(key)
73
74
  const molecule = store.molecules.get(stringKey)
74
75
  if (molecule) {
75
- const atom = growMoleculeInStore(molecule, family, store)
76
+ const atom = growMoleculeInStore(molecule, atomFamilyToken, store)
76
77
  set(atom, transform.fromJson(newValue))
77
78
  } else {
78
79
  if (store.config.lifespan === `immortal`) {
79
80
  throw new Error(`No molecule found for key "${stringKey}"`)
80
81
  }
81
82
  set(
82
- initFamilyMemberInStore(family, key, store),
83
+ initFamilyMemberInStore(atomFamilyToken, key, store),
83
84
  transform.fromJson(newValue),
84
85
  )
85
86
  }
@@ -87,8 +88,10 @@ export function selectJsonFamily<
87
88
  },
88
89
  },
89
90
  store,
91
+ [`mutable`, `json`],
90
92
  )
91
- family.subject.subscribe(
93
+ const atomFamily = withdraw(atomFamilyToken, store)
94
+ atomFamily.subject.subscribe(
92
95
  `store=${store.config.name}::json-selector-family`,
93
96
  (event) => {
94
97
  if (event.token.family) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atom.io",
3
- "version": "0.27.1",
3
+ "version": "0.27.3",
4
4
  "description": "Composable and testable reactive data library.",
5
5
  "homepage": "https://atom.io.fyi",
6
6
  "sideEffects": false,
@@ -59,8 +59,8 @@
59
59
  "@types/npmlog": "7.0.0",
60
60
  "@types/react": "18.3.3",
61
61
  "@types/tmp": "0.2.6",
62
- "@typescript-eslint/parser": "8.0.1",
63
- "@typescript-eslint/rule-tester": "8.0.1",
62
+ "@typescript-eslint/parser": "8.1.0",
63
+ "@typescript-eslint/rule-tester": "8.1.0",
64
64
  "@vitest/coverage-v8": "2.0.5",
65
65
  "@vitest/ui": "2.0.5",
66
66
  "concurrently": "8.2.2",
@@ -72,7 +72,7 @@
72
72
  "http-proxy": "1.18.1",
73
73
  "npmlog": "7.0.1",
74
74
  "postgres": "3.4.4",
75
- "preact": "10.23.1",
75
+ "preact": "10.23.2",
76
76
  "react": "18.3.1",
77
77
  "react-dom": "18.3.1",
78
78
  "react-router-dom": "6.26.0",
@@ -112,7 +112,7 @@ declare function redactTransactionUpdateContent(visibleStateKeys: string[], upda
112
112
  declare const actionOcclusionAtoms: AtomIO.RegularAtomFamilyToken<{
113
113
  occlude: (updates: TransactionUpdateContent[]) => TransactionUpdateContent[];
114
114
  }, string>;
115
- declare const userUnacknowledgedQueues: AtomIO.RegularAtomFamilyToken<Pick<TransactionUpdate<any>, "key" | "id" | "epoch" | "updates" | "output">[], string>;
115
+ declare const userUnacknowledgedQueues: AtomIO.RegularAtomFamilyToken<Pick<TransactionUpdate<any>, "key" | "epoch" | "id" | "updates" | "output">[], string>;
116
116
 
117
117
  declare const socketAtoms: AtomIO.RegularAtomFamilyToken<Socket | null, string>;
118
118
  declare const socketIndex: AtomIO.MutableAtomToken<SetRTX<string>, SetRTXJson<string>>;