atom.io 0.37.1 → 0.38.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.
Files changed (42) hide show
  1. package/dist/internal/index.d.ts +22 -24
  2. package/dist/internal/index.d.ts.map +1 -1
  3. package/dist/internal/index.js +193 -138
  4. package/dist/internal/index.js.map +1 -1
  5. package/dist/json/index.d.ts +1 -1
  6. package/dist/json/index.d.ts.map +1 -1
  7. package/dist/json/index.js.map +1 -1
  8. package/dist/main/index.d.ts +6 -3
  9. package/dist/main/index.d.ts.map +1 -1
  10. package/dist/main/index.js +22 -2
  11. package/dist/main/index.js.map +1 -1
  12. package/package.json +1 -1
  13. package/src/internal/atom/dispose-atom.ts +1 -2
  14. package/src/internal/families/create-readonly-held-selector-family.ts +2 -4
  15. package/src/internal/families/create-readonly-pure-selector-family.ts +2 -4
  16. package/src/internal/families/create-regular-atom-family.ts +3 -4
  17. package/src/internal/families/create-writable-held-selector-family.ts +3 -4
  18. package/src/internal/families/create-writable-pure-selector-family.ts +2 -4
  19. package/src/internal/families/find-in-store.ts +7 -1
  20. package/src/internal/families/get-family-of-token.ts +21 -24
  21. package/src/internal/families/mint-in-store.ts +59 -35
  22. package/src/internal/get-state/get-fallback.ts +57 -0
  23. package/src/internal/get-state/get-from-store.ts +11 -61
  24. package/src/internal/get-state/reduce-reference.ts +66 -0
  25. package/src/internal/index.ts +0 -1
  26. package/src/internal/ingest-updates/ingest-creation-disposal.ts +4 -3
  27. package/src/internal/molecule.ts +5 -5
  28. package/src/internal/mutable/create-mutable-atom-family.ts +3 -8
  29. package/src/internal/mutable/get-json-token.ts +2 -1
  30. package/src/internal/not-found-error.ts +2 -3
  31. package/src/internal/operation.ts +1 -1
  32. package/src/internal/selector/register-selector.ts +17 -24
  33. package/src/internal/selector/update-selector-atoms.ts +2 -2
  34. package/src/internal/set-state/operate-on-store.ts +17 -13
  35. package/src/internal/set-state/set-into-store.ts +2 -2
  36. package/src/internal/store/index.ts +1 -1
  37. package/src/internal/store/{counterfeit.ts → mint-or-counterfeit.ts} +27 -15
  38. package/src/internal/subscribe/subscribe-to-state.ts +2 -0
  39. package/src/internal/timeline/create-timeline.ts +2 -0
  40. package/src/json/index.ts +3 -3
  41. package/src/main/logger.ts +26 -4
  42. package/src/internal/pretty-print.ts +0 -7
@@ -2,7 +2,7 @@ import type { WritableFamilyToken, WritableToken } from "atom.io"
2
2
  import type { Canonical } from "atom.io/json"
3
3
 
4
4
  import type { Store } from "../store"
5
- import { operateOnStore } from "./operate-on-store"
5
+ import { operateOnStore, OWN_OP } from "./operate-on-store"
6
6
  import type { RESET_STATE } from "./reset-in-store"
7
7
 
8
8
  export function setIntoStore<T, New extends T>(
@@ -36,5 +36,5 @@ export function setIntoStore<T, New extends T>(
36
36
  value: New | typeof RESET_STATE | ((oldValue: T) => New),
37
37
  ]
38
38
  ): void {
39
- operateOnStore(store, true, ...params)
39
+ operateOnStore(store, OWN_OP, ...params)
40
40
  }
@@ -1,5 +1,5 @@
1
1
  export * from "./circular-buffer"
2
- export * from "./counterfeit"
3
2
  export * from "./deposit"
3
+ export * from "./mint-or-counterfeit"
4
4
  export * from "./store"
5
5
  export * from "./withdraw"
@@ -21,6 +21,8 @@ import { stringifyJson } from "atom.io/json"
21
21
 
22
22
  import type { Transceiver } from "../mutable"
23
23
 
24
+ export const COUNTERFEIT: unique symbol = Symbol(`counterfeit`)
25
+
24
26
  export const FAMILY_MEMBER_TOKEN_TYPES = {
25
27
  atom_family: `atom`,
26
28
  molecule_family: `molecule`,
@@ -31,66 +33,76 @@ export const FAMILY_MEMBER_TOKEN_TYPES = {
31
33
  writable_pure_selector_family: `writable_pure_selector`,
32
34
  } as const
33
35
 
34
- export function counterfeit<
36
+ export function mint<
35
37
  T extends Transceiver<any, any, any>,
36
38
  K extends Canonical,
37
39
  Key extends K,
38
40
  >(token: MutableAtomFamilyToken<T, K>, key: Key): MutableAtomToken<T>
39
41
 
40
- export function counterfeit<T, K extends Canonical, Key extends K>(
42
+ export function mint<T, K extends Canonical, Key extends K>(
41
43
  token: RegularAtomFamilyToken<T, K>,
42
44
  key: Key,
45
+ counterfeit?: typeof COUNTERFEIT,
43
46
  ): RegularAtomToken<T>
44
47
 
45
- export function counterfeit<T, K extends Canonical, Key extends K>(
48
+ export function mint<T, K extends Canonical, Key extends K>(
46
49
  token: AtomFamilyToken<T, K>,
47
50
  key: Key,
51
+ counterfeit?: typeof COUNTERFEIT,
48
52
  ): AtomToken<T>
49
53
 
50
- export function counterfeit<T, K extends Canonical, Key extends K>(
54
+ export function mint<T, K extends Canonical, Key extends K>(
51
55
  token: WritablePureSelectorFamilyToken<T, K>,
52
56
  key: Key,
57
+ counterfeit?: typeof COUNTERFEIT,
53
58
  ): WritablePureSelectorToken<T>
54
59
 
55
- export function counterfeit<T, K extends Canonical, Key extends K>(
60
+ export function mint<T, K extends Canonical, Key extends K>(
56
61
  token: ReadonlyPureSelectorFamilyToken<T, K>,
57
62
  key: Key,
63
+ counterfeit?: typeof COUNTERFEIT,
58
64
  ): ReadonlyPureSelectorToken<T>
59
65
 
60
- export function counterfeit<T, K extends Canonical, Key extends K>(
66
+ export function mint<T, K extends Canonical, Key extends K>(
61
67
  token: SelectorFamilyToken<T, K>,
62
68
  key: Key,
69
+ counterfeit?: typeof COUNTERFEIT,
63
70
  ): SelectorToken<T>
64
71
 
65
- export function counterfeit<T, K extends Canonical, Key extends K>(
72
+ export function mint<T, K extends Canonical, Key extends K>(
66
73
  token: WritableFamilyToken<T, K>,
67
74
  key: Key,
75
+ counterfeit?: typeof COUNTERFEIT,
68
76
  ): WritableToken<T>
69
77
 
70
- export function counterfeit<T, K extends Canonical, Key extends K>(
78
+ export function mint<T, K extends Canonical, Key extends K>(
71
79
  token: ReadableFamilyToken<T, K>,
72
80
  key: Key,
81
+ counterfeit?: typeof COUNTERFEIT,
73
82
  ): ReadableToken<T>
74
83
 
75
- export function counterfeit(
84
+ export function mint(
76
85
  token: ReadableFamilyToken<any, any>,
77
86
  key: Canonical,
87
+ counterfeit?: typeof COUNTERFEIT,
78
88
  ): ReadableToken<any> {
79
89
  const subKey = stringifyJson(key)
80
90
  const fullKey = `${token.key}(${subKey})`
81
91
  const type = FAMILY_MEMBER_TOKEN_TYPES[token.type]
82
- const stateToken = {
92
+ const stateToken: ReadableToken<any> & {
93
+ counterfeit?: boolean
94
+ } = {
83
95
  key: fullKey,
84
96
  type,
85
- } satisfies ReadableToken<any>
86
-
87
- Object.assign(stateToken, {
88
97
  family: {
89
98
  key: token.key,
90
99
  subKey,
91
100
  },
92
- })
101
+ }
102
+
103
+ if (counterfeit) {
104
+ stateToken.counterfeit = true
105
+ }
93
106
 
94
- Object.assign(stateToken, { counterfeit: true })
95
107
  return stateToken
96
108
  }
@@ -1,6 +1,7 @@
1
1
  import type { ReadableToken, StateUpdate, UpdateHandler } from "atom.io"
2
2
 
3
3
  import { readOrComputeValue } from "../get-state"
4
+ import { reduceReference } from "../get-state/reduce-reference"
4
5
  import { traceRootSelectorAtoms } from "../selector"
5
6
  import type { Store } from "../store"
6
7
  import { withdraw } from "../store"
@@ -25,6 +26,7 @@ export function subscribeToState<T>(
25
26
  handleUpdate(update)
26
27
  }
27
28
  }
29
+ reduceReference(store, token)
28
30
  const state = withdraw(store, token)
29
31
  store.logger.info(`👀`, state.type, state.key, `Adding subscription "${key}"`)
30
32
  const isSelector =
@@ -13,6 +13,7 @@ import type {
13
13
  TransactionToken,
14
14
  } from "atom.io"
15
15
 
16
+ import { reduceReference } from "../get-state/reduce-reference"
16
17
  import { newest } from "../lineage"
17
18
  import { getUpdateToken } from "../mutable"
18
19
  import { deposit, type Store, withdraw } from "../store"
@@ -130,6 +131,7 @@ function addAtomToTimeline(
130
131
  atomToken: AtomToken<any>,
131
132
  tl: Timeline<any>,
132
133
  ): void {
134
+ reduceReference(store, atomToken)
133
135
  let maybeAtom = withdraw(store, atomToken)
134
136
  if (maybeAtom.type === `mutable_atom`) {
135
137
  const updateToken = getUpdateToken(maybeAtom)
package/src/json/index.ts CHANGED
@@ -66,9 +66,9 @@ export type stringified<J extends Json.Serializable> = (
66
66
  )
67
67
 
68
68
  /** Type-safe wrapper for {@link JSON.parse} */
69
- export const parseJson = <S extends stringified<Json.Serializable>>(
70
- str: S | string,
71
- ): S extends stringified<infer J> ? J : Json.Serializable => JSON.parse(str)
69
+ export const parseJson = <J extends Json.Serializable>(
70
+ str: stringified<J> | string,
71
+ ): J => JSON.parse(str)
72
72
 
73
73
  /** Type-safe wrapper for {@link JSON.stringify} */
74
74
  export const stringifyJson = <J extends Json.Serializable>(
@@ -8,10 +8,12 @@ const LOGGER_ICON_DICTIONARY = {
8
8
  "⏹️": `Time-travel complete`,
9
9
  "✅": `Realtime transaction success`,
10
10
  "✨": `Computation complete`,
11
+ "💣": `Dangerous action likely to cause bad errors`,
12
+ "❗": `Dangerous action unless in development mode`,
11
13
  "❌": `Conflict prevents attempted action`,
12
14
  "⭕": `Operation start`,
13
15
  "🔴": `Operation complete`,
14
- "": `Operation blocked`,
16
+ "🚫": `Operation blocked`,
15
17
  "🟢": `Operation unblocked`,
16
18
  "🐞": `Possible bug in AtomIO`,
17
19
  "👀": `Subscription added`,
@@ -55,8 +57,7 @@ export type TokenDenomination =
55
57
  | `atom_family`
56
58
  | `atom`
57
59
  | `continuity`
58
- | `molecule_family`
59
- | `molecule`
60
+ | `key`
60
61
  | `mutable_atom_family`
61
62
  | `mutable_atom`
62
63
  | `readonly_held_selector_family`
@@ -72,6 +73,27 @@ export type TokenDenomination =
72
73
  | `writable_pure_selector_family`
73
74
  | `writable_pure_selector`
74
75
 
76
+ export const PRETTY_TOKEN_TYPES: Record<TokenDenomination, string> = {
77
+ atom_family: `atom family`,
78
+ atom: `atom`,
79
+ continuity: `continuity`,
80
+ key: `key`,
81
+ mutable_atom_family: `atom family [m]`,
82
+ mutable_atom: `atom [m]`,
83
+ readonly_held_selector_family: `selector family [h]`,
84
+ readonly_held_selector: `selector [h]`,
85
+ readonly_pure_selector_family: `selector family`,
86
+ readonly_pure_selector: `selector`,
87
+ state: `state`,
88
+ timeline: `timeline`,
89
+ transaction: `transaction`,
90
+ unknown: `unknown`,
91
+ writable_held_selector_family: `selector family [wh]`,
92
+ writable_held_selector: `selector [wh]`,
93
+ writable_pure_selector_family: `selector family [w]`,
94
+ writable_pure_selector: `selector [w]`,
95
+ }
96
+
75
97
  export const LOG_LEVELS = [`info`, `warn`, `error`] as const
76
98
  export type LogLevel = (typeof LOG_LEVELS)[number]
77
99
 
@@ -93,7 +115,7 @@ export const simpleLog =
93
115
  (icon, denomination, tokenKey, message, ...rest) => {
94
116
  /* eslint-disable-next-line no-console */
95
117
  console[logLevel](
96
- `${icon} ${denomination} "${tokenKey}" ${message}`,
118
+ `${icon} ${PRETTY_TOKEN_TYPES[denomination]} \`${tokenKey}\` ${message}`,
97
119
  ...rest,
98
120
  )
99
121
  }
@@ -1,7 +0,0 @@
1
- import type { AtomIOToken } from "atom.io"
2
-
3
- import { capitalize } from "./capitalize"
4
-
5
- export function prettyPrintTokenType(token: AtomIOToken): string {
6
- return token.type.split(`_`).map(capitalize).join(` `)
7
- }