atom.io 0.40.7 → 0.40.8

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 (73) hide show
  1. package/dist/data/index.js +1 -2
  2. package/dist/data/index.js.map +1 -1
  3. package/dist/employ-socket-D6wgByWh.js.map +1 -1
  4. package/dist/eslint-plugin/index.js.map +1 -1
  5. package/dist/{has-role-hv4-hJMw.js → has-role-CMlaUlaf.js} +30 -46
  6. package/dist/has-role-CMlaUlaf.js.map +1 -0
  7. package/dist/internal/index.d.ts.map +1 -1
  8. package/dist/internal/index.js +103 -174
  9. package/dist/internal/index.js.map +1 -1
  10. package/dist/introspection/index.d.ts.map +1 -1
  11. package/dist/introspection/index.js +13 -32
  12. package/dist/introspection/index.js.map +1 -1
  13. package/dist/is-fn-DY1wZ-md.js.map +1 -1
  14. package/dist/json/index.d.ts.map +1 -1
  15. package/dist/json/index.js.map +1 -1
  16. package/dist/main/index.d.ts.map +1 -1
  17. package/dist/main/index.js +1 -2
  18. package/dist/main/index.js.map +1 -1
  19. package/dist/mutex-store-CSvxY9i3.js.map +1 -1
  20. package/dist/react/index.d.ts.map +1 -1
  21. package/dist/react/index.js.map +1 -1
  22. package/dist/react-devtools/index.d.ts.map +1 -1
  23. package/dist/react-devtools/index.js +2 -4
  24. package/dist/react-devtools/index.js.map +1 -1
  25. package/dist/realtime/index.d.ts.map +1 -1
  26. package/dist/realtime/index.js +2 -3
  27. package/dist/realtime/index.js.map +1 -1
  28. package/dist/realtime-client/index.d.ts +1 -4
  29. package/dist/realtime-client/index.d.ts.map +1 -1
  30. package/dist/realtime-client/index.js +5 -20
  31. package/dist/realtime-client/index.js.map +1 -1
  32. package/dist/realtime-react/index.d.ts +2 -5
  33. package/dist/realtime-react/index.d.ts.map +1 -1
  34. package/dist/realtime-react/index.js +4 -15
  35. package/dist/realtime-react/index.js.map +1 -1
  36. package/dist/realtime-server/index.d.ts +36 -44
  37. package/dist/realtime-server/index.d.ts.map +1 -1
  38. package/dist/realtime-server/index.js +125 -171
  39. package/dist/realtime-server/index.js.map +1 -1
  40. package/dist/realtime-testing/index.d.ts +4 -2
  41. package/dist/realtime-testing/index.d.ts.map +1 -1
  42. package/dist/realtime-testing/index.js +13 -7
  43. package/dist/realtime-testing/index.js.map +1 -1
  44. package/dist/{shared-room-store-COGGKqes.js → shared-room-store-BfW3nWif.js} +2 -3
  45. package/dist/{shared-room-store-COGGKqes.js.map → shared-room-store-BfW3nWif.js.map} +1 -1
  46. package/dist/shared-room-store-D2o4ZLjC.d.ts.map +1 -1
  47. package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
  48. package/dist/transceivers/set-rtx/index.js +4 -8
  49. package/dist/transceivers/set-rtx/index.js.map +1 -1
  50. package/dist/web/index.js.map +1 -1
  51. package/package.json +11 -11
  52. package/src/internal/mutable/tracker.ts +66 -51
  53. package/src/internal/subscribe/subscribe-to-state.ts +9 -0
  54. package/src/realtime-client/index.ts +0 -1
  55. package/src/realtime-react/index.ts +0 -1
  56. package/src/realtime-server/continuity/continuity-store.ts +1 -26
  57. package/src/realtime-server/continuity/provide-continuity.ts +50 -0
  58. package/src/realtime-server/continuity/{subscribe-to-continuity-actions.ts → provide-outcomes.ts} +14 -12
  59. package/src/realtime-server/continuity/{subscribe-to-continuity-perpectives.ts → provide-perspectives.ts} +10 -8
  60. package/src/realtime-server/continuity/{prepare-to-send-initial-payload.ts → provide-startup-payloads.ts} +6 -4
  61. package/src/realtime-server/continuity/receive-action-requests.ts +68 -0
  62. package/src/realtime-server/continuity/{prepare-to-track-client-acknowledgement.ts → track-acknowledgements.ts} +15 -8
  63. package/src/realtime-server/index.ts +1 -2
  64. package/src/realtime-server/ipc-sockets/custom-socket.ts +3 -3
  65. package/src/realtime-server/ipc-sockets/parent-socket.ts +19 -13
  66. package/src/realtime-server/server-config.ts +0 -1
  67. package/src/realtime-testing/setup-realtime-test.tsx +20 -14
  68. package/dist/has-role-hv4-hJMw.js.map +0 -1
  69. package/src/realtime-client/server-action.ts +0 -23
  70. package/src/realtime-react/use-server-action.ts +0 -19
  71. package/src/realtime-server/continuity/prepare-to-serve-transaction-request.ts +0 -59
  72. package/src/realtime-server/continuity/prepare-to-sync-realtime-continuity.ts +0 -145
  73. package/src/realtime-server/realtime-action-receiver.ts +0 -40
@@ -5,8 +5,7 @@ function dict(family, index, store = IMPLICIT.STORE) {
5
5
  return createStandaloneSelector(store, {
6
6
  key: `${family.key}Dict`,
7
7
  get: ({ get }) => {
8
- const keys = get(index);
9
- return keys.reduce((acc, key) => {
8
+ return get(index).reduce((acc, key) => {
10
9
  acc[key] = get(findInStore(store, family, key));
11
10
  return acc;
12
11
  }, {});
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["atoms: {\n\t\t[K in keyof Struct as `${Key}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.RegularAtomToken<Struct[K]>\n\t}","atoms: {\n\t\t[K in keyof Struct as `find${Capitalize<Key & string>}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.RegularAtomFamilyToken<Struct[K], string>\n\t}","findStructState: AtomIO.ReadonlyPureSelectorFamilyToken<Struct, string>"],"sources":["../../src/data/dict.ts","../../src/data/struct.ts","../../src/data/struct-family.ts"],"sourcesContent":["import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport {\n\tcreateStandaloneSelector,\n\tfindInStore,\n\tIMPLICIT,\n} from \"atom.io/internal\"\nimport type { Canonical, stringified } from \"atom.io/json\"\n\nexport function dict<State, Key extends Canonical>(\n\tfamily:\n\t\t| AtomIO.ReadonlyPureSelectorFamilyToken<State, Key>\n\t\t| AtomIO.RegularAtomFamilyToken<State, Key>\n\t\t| AtomIO.WritablePureSelectorFamilyToken<State, Key>,\n\tindex:\n\t\t| AtomIO.ReadonlyPureSelectorToken<Key[]>\n\t\t| AtomIO.RegularAtomToken<Key[]>\n\t\t| AtomIO.WritablePureSelectorToken<Key[]>,\n\tstore: Store = IMPLICIT.STORE,\n): AtomIO.ReadonlyPureSelectorToken<{ [K in stringified<Key>]: State }> {\n\treturn createStandaloneSelector(store, {\n\t\tkey: `${family.key}Dict`,\n\t\tget: ({ get }) => {\n\t\t\tconst keys = get(index)\n\t\t\treturn keys.reduce((acc, key) => {\n\t\t\t\tacc[key] = get(findInStore(store, family, key))\n\t\t\t\treturn acc\n\t\t\t}, {} as any)\n\t\t},\n\t})\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport {\n\tcapitalize,\n\tcreateRegularAtom,\n\tcreateStandaloneSelector,\n\tIMPLICIT,\n} from \"atom.io/internal\"\n\nexport function struct<\n\tStruct extends { [key: string]: unknown },\n\tKey extends string,\n>(\n\toptions: {\n\t\tkey: Key\n\t\tdefault: Struct\n\t},\n\tstore: Store = IMPLICIT.STORE,\n): [\n\t{\n\t\t[K in keyof Struct as `${Key}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.RegularAtomToken<Struct[K]>\n\t},\n\tAtomIO.ReadonlyPureSelectorToken<Struct, any, never>,\n] {\n\tconst atoms: {\n\t\t[K in keyof Struct as `${Key}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.RegularAtomToken<Struct[K]>\n\t} = Object.keys(options.default).reduce((acc, key) => {\n\t\tconst atomName = options.key + capitalize(key) + `State`\n\t\tacc[atomName] = createRegularAtom(\n\t\t\tstore,\n\t\t\t{\n\t\t\t\tkey: `${options.key}.${key}`,\n\t\t\t\tdefault: options.default[key],\n\t\t\t},\n\t\t\tundefined,\n\t\t)\n\t\treturn acc\n\t}, {} as any)\n\tconst structState = createStandaloneSelector<Struct, never>(store, {\n\t\tkey: options.key,\n\t\tget: ({ get }) => {\n\t\t\treturn Object.keys(options.default).reduce((acc, key) => {\n\t\t\t\t// @ts-expect-error finicky\n\t\t\t\tacc[key] = get(atoms[options.key + capitalize(key) + `State`])\n\t\t\t\treturn acc\n\t\t\t}, {} as any)\n\t\t},\n\t})\n\treturn [atoms, structState]\n}\n","import type * as AtomIO from \"atom.io\"\nimport {\n\tcapitalize,\n\tcreateRegularAtomFamily,\n\tcreateSelectorFamily,\n\tIMPLICIT,\n} from \"atom.io/internal\"\n\nconst nameFamily = (topKey: string, subKey: string) =>\n\t`find` + capitalize(topKey) + capitalize(subKey) + `State`\n\nexport function structFamily<\n\tStruct extends object,\n\tKey extends string,\n>(options: {\n\tkey: Key\n\tdefault: Struct\n}): [\n\t{\n\t\t[K in keyof Struct as `find${Capitalize<Key & string>}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.RegularAtomFamilyToken<Struct[K], string>\n\t},\n\tAtomIO.ReadonlyPureSelectorFamilyToken<Struct, string>,\n] {\n\tconst atoms: {\n\t\t[K in keyof Struct as `find${Capitalize<Key & string>}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.RegularAtomFamilyToken<Struct[K], string>\n\t} = Object.keys(options.default).reduce((acc, subKey) => {\n\t\tconst atomFamilyName = nameFamily(options.key, subKey)\n\t\tacc[atomFamilyName] = createRegularAtomFamily(IMPLICIT.STORE, {\n\t\t\tkey: `${options.key}.${subKey}`,\n\t\t\tdefault: (options.default as any)[subKey],\n\t\t})\n\t\treturn acc\n\t}, {} as any)\n\tconst findStructState: AtomIO.ReadonlyPureSelectorFamilyToken<Struct, string> =\n\t\tcreateSelectorFamily(IMPLICIT.STORE, {\n\t\t\tkey: options.key,\n\t\t\tget:\n\t\t\t\t(id) =>\n\t\t\t\t({ find, get }) => {\n\t\t\t\t\treturn Object.keys(options.default).reduce((acc, subKey) => {\n\t\t\t\t\t\tacc[subKey] = get(\n\t\t\t\t\t\t\tfind((atoms as any)[nameFamily(options.key, subKey)], id),\n\t\t\t\t\t\t)\n\t\t\t\t\t\treturn acc\n\t\t\t\t\t}, {} as any)\n\t\t\t\t},\n\t\t})\n\treturn [atoms, findStructState]\n}\n"],"mappings":";;;AASA,SAAgB,KACf,QAIA,OAIA,QAAe,SAAS,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,KAAK,UAAU;AAEvD,WAAO;MACL;;;AAGP,QAAO,CAAC,OAAO"}
1
+ {"version":3,"file":"index.js","names":["atoms: {\n\t\t[K in keyof Struct as `${Key}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.RegularAtomToken<Struct[K]>\n\t}","atoms: {\n\t\t[K in keyof Struct as `find${Capitalize<Key & string>}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.RegularAtomFamilyToken<Struct[K], string>\n\t}","findStructState: AtomIO.ReadonlyPureSelectorFamilyToken<Struct, string>"],"sources":["../../src/data/dict.ts","../../src/data/struct.ts","../../src/data/struct-family.ts"],"sourcesContent":["import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport {\n\tcreateStandaloneSelector,\n\tfindInStore,\n\tIMPLICIT,\n} from \"atom.io/internal\"\nimport type { Canonical, stringified } from \"atom.io/json\"\n\nexport function dict<State, Key extends Canonical>(\n\tfamily:\n\t\t| AtomIO.ReadonlyPureSelectorFamilyToken<State, Key>\n\t\t| AtomIO.RegularAtomFamilyToken<State, Key>\n\t\t| AtomIO.WritablePureSelectorFamilyToken<State, Key>,\n\tindex:\n\t\t| AtomIO.ReadonlyPureSelectorToken<Key[]>\n\t\t| AtomIO.RegularAtomToken<Key[]>\n\t\t| AtomIO.WritablePureSelectorToken<Key[]>,\n\tstore: Store = IMPLICIT.STORE,\n): AtomIO.ReadonlyPureSelectorToken<{ [K in stringified<Key>]: State }> {\n\treturn createStandaloneSelector(store, {\n\t\tkey: `${family.key}Dict`,\n\t\tget: ({ get }) => {\n\t\t\tconst keys = get(index)\n\t\t\treturn keys.reduce((acc, key) => {\n\t\t\t\tacc[key] = get(findInStore(store, family, key))\n\t\t\t\treturn acc\n\t\t\t}, {} as any)\n\t\t},\n\t})\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport {\n\tcapitalize,\n\tcreateRegularAtom,\n\tcreateStandaloneSelector,\n\tIMPLICIT,\n} from \"atom.io/internal\"\n\nexport function struct<\n\tStruct extends { [key: string]: unknown },\n\tKey extends string,\n>(\n\toptions: {\n\t\tkey: Key\n\t\tdefault: Struct\n\t},\n\tstore: Store = IMPLICIT.STORE,\n): [\n\t{\n\t\t[K in keyof Struct as `${Key}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.RegularAtomToken<Struct[K]>\n\t},\n\tAtomIO.ReadonlyPureSelectorToken<Struct, any, never>,\n] {\n\tconst atoms: {\n\t\t[K in keyof Struct as `${Key}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.RegularAtomToken<Struct[K]>\n\t} = Object.keys(options.default).reduce((acc, key) => {\n\t\tconst atomName = options.key + capitalize(key) + `State`\n\t\tacc[atomName] = createRegularAtom(\n\t\t\tstore,\n\t\t\t{\n\t\t\t\tkey: `${options.key}.${key}`,\n\t\t\t\tdefault: options.default[key],\n\t\t\t},\n\t\t\tundefined,\n\t\t)\n\t\treturn acc\n\t}, {} as any)\n\tconst structState = createStandaloneSelector<Struct, never>(store, {\n\t\tkey: options.key,\n\t\tget: ({ get }) => {\n\t\t\treturn Object.keys(options.default).reduce((acc, key) => {\n\t\t\t\t// @ts-expect-error finicky\n\t\t\t\tacc[key] = get(atoms[options.key + capitalize(key) + `State`])\n\t\t\t\treturn acc\n\t\t\t}, {} as any)\n\t\t},\n\t})\n\treturn [atoms, structState]\n}\n","import type * as AtomIO from \"atom.io\"\nimport {\n\tcapitalize,\n\tcreateRegularAtomFamily,\n\tcreateSelectorFamily,\n\tIMPLICIT,\n} from \"atom.io/internal\"\n\nconst nameFamily = (topKey: string, subKey: string) =>\n\t`find` + capitalize(topKey) + capitalize(subKey) + `State`\n\nexport function structFamily<\n\tStruct extends object,\n\tKey extends string,\n>(options: {\n\tkey: Key\n\tdefault: Struct\n}): [\n\t{\n\t\t[K in keyof Struct as `find${Capitalize<Key & string>}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.RegularAtomFamilyToken<Struct[K], string>\n\t},\n\tAtomIO.ReadonlyPureSelectorFamilyToken<Struct, string>,\n] {\n\tconst atoms: {\n\t\t[K in keyof Struct as `find${Capitalize<Key & string>}${Capitalize<\n\t\t\tK & string\n\t\t>}State`]: AtomIO.RegularAtomFamilyToken<Struct[K], string>\n\t} = Object.keys(options.default).reduce((acc, subKey) => {\n\t\tconst atomFamilyName = nameFamily(options.key, subKey)\n\t\tacc[atomFamilyName] = createRegularAtomFamily(IMPLICIT.STORE, {\n\t\t\tkey: `${options.key}.${subKey}`,\n\t\t\tdefault: (options.default as any)[subKey],\n\t\t})\n\t\treturn acc\n\t}, {} as any)\n\tconst findStructState: AtomIO.ReadonlyPureSelectorFamilyToken<Struct, string> =\n\t\tcreateSelectorFamily(IMPLICIT.STORE, {\n\t\t\tkey: options.key,\n\t\t\tget:\n\t\t\t\t(id) =>\n\t\t\t\t({ find, get }) => {\n\t\t\t\t\treturn Object.keys(options.default).reduce((acc, subKey) => {\n\t\t\t\t\t\tacc[subKey] = get(\n\t\t\t\t\t\t\tfind((atoms as any)[nameFamily(options.key, subKey)], id),\n\t\t\t\t\t\t)\n\t\t\t\t\t\treturn acc\n\t\t\t\t\t}, {} as any)\n\t\t\t\t},\n\t\t})\n\treturn [atoms, findStructState]\n}\n"],"mappings":";;;AASA,SAAgB,KACf,QAIA,OAIA,QAAe,SAAS,OAC+C;AACvE,QAAO,yBAAyB,OAAO;EACtC,KAAK,GAAG,OAAO,IAAI;EACnB,MAAM,EAAE,UAAU;AAEjB,UADa,IAAI,MAAM,CACX,QAAQ,KAAK,QAAQ;AAChC,QAAI,OAAO,IAAI,YAAY,OAAO,QAAQ,IAAI,CAAC;AAC/C,WAAO;MACL,EAAE,CAAQ;;EAEd,CAAC;;;;;ACpBH,SAAgB,OAIf,SAIA,QAAe,SAAS,OAQvB;CACD,MAAMA,QAIF,OAAO,KAAK,QAAQ,QAAQ,CAAC,QAAQ,KAAK,QAAQ;EACrD,MAAM,WAAW,QAAQ,MAAM,WAAW,IAAI,GAAG;AACjD,MAAI,YAAY,kBACf,OACA;GACC,KAAK,GAAG,QAAQ,IAAI,GAAG;GACvB,SAAS,QAAQ,QAAQ;GACzB,EACD,OACA;AACD,SAAO;IACL,EAAE,CAAQ;CACb,MAAM,cAAc,yBAAwC,OAAO;EAClE,KAAK,QAAQ;EACb,MAAM,EAAE,UAAU;AACjB,UAAO,OAAO,KAAK,QAAQ,QAAQ,CAAC,QAAQ,KAAK,QAAQ;AAExD,QAAI,OAAO,IAAI,MAAM,QAAQ,MAAM,WAAW,IAAI,GAAG,SAAS;AAC9D,WAAO;MACL,EAAE,CAAQ;;EAEd,CAAC;AACF,QAAO,CAAC,OAAO,YAAY;;;;;AC5C5B,MAAM,cAAc,QAAgB,WACnC,SAAS,WAAW,OAAO,GAAG,WAAW,OAAO,GAAG;AAEpD,SAAgB,aAGd,SAUA;CACD,MAAMC,QAIF,OAAO,KAAK,QAAQ,QAAQ,CAAC,QAAQ,KAAK,WAAW;EACxD,MAAM,iBAAiB,WAAW,QAAQ,KAAK,OAAO;AACtD,MAAI,kBAAkB,wBAAwB,SAAS,OAAO;GAC7D,KAAK,GAAG,QAAQ,IAAI,GAAG;GACvB,SAAU,QAAQ,QAAgB;GAClC,CAAC;AACF,SAAO;IACL,EAAE,CAAQ;CACb,MAAMC,kBACL,qBAAqB,SAAS,OAAO;EACpC,KAAK,QAAQ;EACb,MACE,QACA,EAAE,MAAM,UAAU;AAClB,UAAO,OAAO,KAAK,QAAQ,QAAQ,CAAC,QAAQ,KAAK,WAAW;AAC3D,QAAI,UAAU,IACb,KAAM,MAAc,WAAW,QAAQ,KAAK,OAAO,GAAG,GAAG,CACzD;AACD,WAAO;MACL,EAAE,CAAQ;;EAEf,CAAC;AACH,QAAO,CAAC,OAAO,gBAAgB"}
@@ -1 +1 @@
1
- {"version":3,"file":"employ-socket-D6wgByWh.js","names":[],"sources":["../src/realtime-server/employ-socket.ts"],"sourcesContent":["import type { Events } from \"./ipc-sockets\"\nimport type { Socket } from \"./socket-interface\"\n\nexport function employSocket<I extends Events, K extends string & keyof I>(\n\tsocket: Socket,\n\tevent: K,\n\thandleEvent: (...data: I[K]) => void,\n): () => void {\n\tsocket.on(event, handleEvent)\n\tconst retireSocket = () => {\n\t\tsocket.off(event, handleEvent)\n\t}\n\treturn retireSocket\n}\n"],"mappings":";AAGA,SAAgB,aACf,QACA,OACA,aACa;AACb,QAAO,GAAG,OAAO;CACjB,MAAM,qBAAqB;AAC1B,SAAO,IAAI,OAAO;;AAEnB,QAAO"}
1
+ {"version":3,"file":"employ-socket-D6wgByWh.js","names":[],"sources":["../src/realtime-server/employ-socket.ts"],"sourcesContent":["import type { Events } from \"./ipc-sockets\"\nimport type { Socket } from \"./socket-interface\"\n\nexport function employSocket<I extends Events, K extends string & keyof I>(\n\tsocket: Socket,\n\tevent: K,\n\thandleEvent: (...data: I[K]) => void,\n): () => void {\n\tsocket.on(event, handleEvent)\n\tconst retireSocket = () => {\n\t\tsocket.off(event, handleEvent)\n\t}\n\treturn retireSocket\n}\n"],"mappings":";AAGA,SAAgB,aACf,QACA,OACA,aACa;AACb,QAAO,GAAG,OAAO,YAAY;CAC7B,MAAM,qBAAqB;AAC1B,SAAO,IAAI,OAAO,YAAY;;AAE/B,QAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["explicitStateTypes: ESLintUtils.RuleModule<\n\t`noTypeArgument`,\n\t[],\n\tunknown,\n\tESLintUtils.RuleListener\n>","plugin: ESLint.Plugin"],"sources":["../../src/eslint-plugin/rules/explicit-state-types.ts","../../src/eslint-plugin/rules/index.ts","../../src/eslint-plugin/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/switch-exhaustiveness-check */\nimport { ESLintUtils } from \"@typescript-eslint/utils\"\n\nconst createRule = ESLintUtils.RuleCreator(\n\t(name) => `https://atom.io.fyi/docs/eslint-plugin#${name}`,\n)\n\nconst STATE_FUNCTIONS = [\n\t`atom`,\n\t`atomFamily`,\n\t`mutableAtom`,\n\t`mutableAtomFamily`,\n\t`selector`,\n\t`selectorFamily`,\n]\n\nexport const explicitStateTypes: ESLintUtils.RuleModule<\n\t`noTypeArgument`,\n\t[],\n\tunknown,\n\tESLintUtils.RuleListener\n> = createRule({\n\tname: `explicit-state-types`,\n\tmeta: {\n\t\ttype: `problem`,\n\t\tdocs: {\n\t\t\tdescription: `State declarations must have generic type arguments directly passed to them`,\n\t\t},\n\t\tmessages: {\n\t\t\tnoTypeArgument: `State declarations must have generic type arguments directly passed to them.`,\n\t\t},\n\t\tschema: [], // no options\n\t},\n\tdefaultOptions: [],\n\tcreate(context) {\n\t\treturn {\n\t\t\tCallExpression(node) {\n\t\t\t\tconst { callee } = node\n\t\t\t\tswitch (callee.type) {\n\t\t\t\t\tcase `Identifier`: {\n\t\t\t\t\t\tif (STATE_FUNCTIONS.includes(callee.name)) {\n\t\t\t\t\t\t\tif (!node.typeArguments) {\n\t\t\t\t\t\t\t\tcontext.report({\n\t\t\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\t\t\tmessageId: `noTypeArgument`,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase `MemberExpression`: {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tcallee.property.type === `Identifier` &&\n\t\t\t\t\t\t\tSTATE_FUNCTIONS.includes(callee.property.name)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tif (!node.typeArguments) {\n\t\t\t\t\t\t\t\tcontext.report({\n\t\t\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\t\t\tmessageId: `noTypeArgument`,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t}\n\t},\n})\n","export * from \"./explicit-state-types\"\n","import type { ESLint } from \"eslint\"\n\nimport * as Rules from \"./rules\"\n\nexport { Rules }\n\nconst plugin: ESLint.Plugin = {\n\trules: {\n\t\t\"explicit-state-types\": Rules.explicitStateTypes as any,\n\t},\n} satisfies ESLint.Plugin\n\nexport default plugin\n"],"mappings":";;;;AAGA,MAAM,aAAa,YAAY,aAC7B,SAAS,0CAA0C;AAGrD,MAAM,kBAAkB;CACvB;CACA;CACA;CACA;CACA;CACA;;AAGD,MAAaA,qBAKT,WAAW;CACd,MAAM;CACN,MAAM;EACL,MAAM;EACN,MAAM,EACL,aAAa;EAEd,UAAU,EACT,gBAAgB;EAEjB,QAAQ;;CAET,gBAAgB;CAChB,OAAO,SAAS;AACf,SAAO,EACN,eAAe,MAAM;GACpB,MAAM,EAAE,WAAW;AACnB,WAAQ,OAAO,MAAf;IACC,KAAK;AACJ,SAAI,gBAAgB,SAAS,OAAO,OACnC;UAAI,CAAC,KAAK,cACT,SAAQ,OAAO;OACd;OACA,WAAW;;;AAId;IAED,KAAK,mBACJ,KACC,OAAO,SAAS,SAAS,gBACzB,gBAAgB,SAAS,OAAO,SAAS,OAEzC;SAAI,CAAC,KAAK,cACT,SAAQ,OAAO;MACd;MACA,WAAW;;;;;;;;;;;;;;;AEpDpB,MAAMC,SAAwB,EAC7B,OAAO,EACN;AAIF,4BAAe"}
1
+ {"version":3,"file":"index.js","names":["explicitStateTypes: ESLintUtils.RuleModule<\n\t`noTypeArgument`,\n\t[],\n\tunknown,\n\tESLintUtils.RuleListener\n>","plugin: ESLint.Plugin"],"sources":["../../src/eslint-plugin/rules/explicit-state-types.ts","../../src/eslint-plugin/rules/index.ts","../../src/eslint-plugin/index.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/switch-exhaustiveness-check */\nimport { ESLintUtils } from \"@typescript-eslint/utils\"\n\nconst createRule = ESLintUtils.RuleCreator(\n\t(name) => `https://atom.io.fyi/docs/eslint-plugin#${name}`,\n)\n\nconst STATE_FUNCTIONS = [\n\t`atom`,\n\t`atomFamily`,\n\t`mutableAtom`,\n\t`mutableAtomFamily`,\n\t`selector`,\n\t`selectorFamily`,\n]\n\nexport const explicitStateTypes: ESLintUtils.RuleModule<\n\t`noTypeArgument`,\n\t[],\n\tunknown,\n\tESLintUtils.RuleListener\n> = createRule({\n\tname: `explicit-state-types`,\n\tmeta: {\n\t\ttype: `problem`,\n\t\tdocs: {\n\t\t\tdescription: `State declarations must have generic type arguments directly passed to them`,\n\t\t},\n\t\tmessages: {\n\t\t\tnoTypeArgument: `State declarations must have generic type arguments directly passed to them.`,\n\t\t},\n\t\tschema: [], // no options\n\t},\n\tdefaultOptions: [],\n\tcreate(context) {\n\t\treturn {\n\t\t\tCallExpression(node) {\n\t\t\t\tconst { callee } = node\n\t\t\t\tswitch (callee.type) {\n\t\t\t\t\tcase `Identifier`: {\n\t\t\t\t\t\tif (STATE_FUNCTIONS.includes(callee.name)) {\n\t\t\t\t\t\t\tif (!node.typeArguments) {\n\t\t\t\t\t\t\t\tcontext.report({\n\t\t\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\t\t\tmessageId: `noTypeArgument`,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t\tcase `MemberExpression`: {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tcallee.property.type === `Identifier` &&\n\t\t\t\t\t\t\tSTATE_FUNCTIONS.includes(callee.property.name)\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tif (!node.typeArguments) {\n\t\t\t\t\t\t\t\tcontext.report({\n\t\t\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\t\t\tmessageId: `noTypeArgument`,\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t}\n\t},\n})\n","export * from \"./explicit-state-types\"\n","import type { ESLint } from \"eslint\"\n\nimport * as Rules from \"./rules\"\n\nexport { Rules }\n\nconst plugin: ESLint.Plugin = {\n\trules: {\n\t\t\"explicit-state-types\": Rules.explicitStateTypes as any,\n\t},\n} satisfies ESLint.Plugin\n\nexport default plugin\n"],"mappings":";;;;AAGA,MAAM,aAAa,YAAY,aAC7B,SAAS,0CAA0C,OACpD;AAED,MAAM,kBAAkB;CACvB;CACA;CACA;CACA;CACA;CACA;CACA;AAED,MAAaA,qBAKT,WAAW;CACd,MAAM;CACN,MAAM;EACL,MAAM;EACN,MAAM,EACL,aAAa,+EACb;EACD,UAAU,EACT,gBAAgB,gFAChB;EACD,QAAQ,EAAE;EACV;CACD,gBAAgB,EAAE;CAClB,OAAO,SAAS;AACf,SAAO,EACN,eAAe,MAAM;GACpB,MAAM,EAAE,WAAW;AACnB,WAAQ,OAAO,MAAf;IACC,KAAK;AACJ,SAAI,gBAAgB,SAAS,OAAO,KAAK,EACxC;UAAI,CAAC,KAAK,cACT,SAAQ,OAAO;OACd;OACA,WAAW;OACX,CAAC;;AAGJ;IAED,KAAK,mBACJ,KACC,OAAO,SAAS,SAAS,gBACzB,gBAAgB,SAAS,OAAO,SAAS,KAAK,EAE9C;SAAI,CAAC,KAAK,cACT,SAAQ,OAAO;MACd;MACA,WAAW;MACX,CAAC;;;KAMP;;CAEF,CAAC;;;;;;;;;AE7DF,MAAMC,SAAwB,EAC7B,OAAO,EACN,4CACA,EACD;AAED,4BAAe"}
@@ -231,8 +231,7 @@ function safeCompute(target, state) {
231
231
  }
232
232
  throw e;
233
233
  }
234
- const cachedValue = writeToCache(target, state, val);
235
- return cachedValue;
234
+ return writeToCache(target, state, val);
236
235
  }
237
236
  case `atom`: {
238
237
  let def;
@@ -260,8 +259,7 @@ function safeCompute(target, state) {
260
259
  def = state.default;
261
260
  target.logger.info(`✨`, state.type, key, `using static default`, def);
262
261
  }
263
- const cachedValue = writeToCache(target, state, def);
264
- return cachedValue;
262
+ return writeToCache(target, state, def);
265
263
  }
266
264
  }
267
265
  }
@@ -283,8 +281,7 @@ function readOrComputeValue(target, state, mut) {
283
281
  case `mutable_atom`: {
284
282
  const instance = new state.class();
285
283
  target.logger.info(`✨`, state.type, key, `created new instance`, instance);
286
- const cachedValue = writeToCache(target, state, instance);
287
- return cachedValue;
284
+ return writeToCache(target, state, instance);
288
285
  }
289
286
  }
290
287
  }
@@ -314,13 +311,12 @@ const DO_NOT_CREATE = Symbol(`DO_NOT_CREATE`);
314
311
  function mintInStore(mustCreate, store, family, key) {
315
312
  const stringKey = stringifyJson(key);
316
313
  const molecule = store.molecules.get(stringKey);
317
- const cannotCreate = !molecule && store.config.lifespan === `immortal`;
318
- if (cannotCreate) {
314
+ if (!molecule && store.config.lifespan === `immortal`) {
319
315
  const { type: familyType, key: familyKey } = family;
320
316
  store.logger.warn(`💣`, `key`, stringKey, `was used to mint a counterfeit token for`, familyType, `"${familyKey}"`);
321
317
  const fullKey = `${familyKey}(${stringKey})`;
322
318
  const type = FAMILY_MEMBER_TOKEN_TYPES[familyType];
323
- const stateToken = {
319
+ return {
324
320
  counterfeit: true,
325
321
  key: fullKey,
326
322
  type,
@@ -329,7 +325,6 @@ function mintInStore(mustCreate, store, family, key) {
329
325
  subKey: stringKey
330
326
  }
331
327
  };
332
- return stateToken;
333
328
  }
334
329
  let token;
335
330
  if (mustCreate === MUST_CREATE) {
@@ -340,7 +335,7 @@ function mintInStore(mustCreate, store, family, key) {
340
335
  const { type: familyType, key: familyKey } = family;
341
336
  const fullKey = `${familyKey}(${stringKey})`;
342
337
  const type = FAMILY_MEMBER_TOKEN_TYPES[familyType];
343
- const stateToken = {
338
+ return {
344
339
  key: fullKey,
345
340
  type,
346
341
  family: {
@@ -348,7 +343,6 @@ function mintInStore(mustCreate, store, family, key) {
348
343
  subKey: stringKey
349
344
  }
350
345
  };
351
- return stateToken;
352
346
  }
353
347
  return token;
354
348
  }
@@ -389,8 +383,7 @@ function reduceReference(store, ...params) {
389
383
  } else token = existingToken;
390
384
  }
391
385
  const isCounterfeit = `counterfeit` in token;
392
- const isNewlyCreated = Boolean(brandNewToken) && isCounterfeit === false;
393
- if (isNewlyCreated && family) {
386
+ if (Boolean(brandNewToken) && isCounterfeit === false && family) {
394
387
  let subType;
395
388
  switch (token.type) {
396
389
  case `readonly_pure_selector`:
@@ -410,8 +403,7 @@ function reduceReference(store, ...params) {
410
403
  token,
411
404
  timestamp: Date.now()
412
405
  };
413
- const familySubject = family.subject;
414
- familySubject.next(stateCreationEvent);
406
+ family.subject.next(stateCreationEvent);
415
407
  const target = newest(store);
416
408
  if (token.family) {
417
409
  if (isRootStore(target)) switch (token.type) {
@@ -525,8 +517,7 @@ function dispatchOrDeferStateUpdate(target, state, { oldValue, newValue }, state
525
517
  value: newValue
526
518
  };
527
519
  target.operation.subEvents.push(stateCreationEvent);
528
- const familySubject = family.subject;
529
- familySubject.next(stateCreationEvent);
520
+ family.subject.next(stateCreationEvent);
530
521
  const innerTarget = newest(target);
531
522
  if (token.family) {
532
523
  if (isRootStore(innerTarget)) switch (token.type) {
@@ -576,9 +567,7 @@ function dispatchOrDeferStateUpdate(target, state, { oldValue, newValue }, state
576
567
  if (hasRole(state, `tracker:signal`)) {
577
568
  const keyOfMutable = key.slice(1);
578
569
  const mutable = target.atoms.get(keyOfMutable);
579
- const transceiver = readOrComputeValue(target, mutable, `mut`);
580
- const accepted = transceiver.do(update.newValue) === null;
581
- if (accepted === true) evictDownstreamFromAtom(target, mutable);
570
+ if (readOrComputeValue(target, mutable, `mut`).do(update.newValue) === null === true) evictDownstreamFromAtom(target, mutable);
582
571
  }
583
572
  }
584
573
  }
@@ -743,8 +732,7 @@ function operateOnStore(opMode, store, ...params) {
743
732
  let target;
744
733
  if (opMode === OWN_OP) {
745
734
  const result = openOperation(store, token);
746
- const rejected = typeof result === `number`;
747
- if (rejected) {
735
+ if (typeof result === `number`) {
748
736
  const rejectionTime = result;
749
737
  const unsubscribe = store.on.operationClose.subscribe(`waiting to ${action} "${token.key}" at T-${rejectionTime}`, function waitUntilOperationCloseToSetState() {
750
738
  unsubscribe();
@@ -765,8 +753,7 @@ function operateOnStore(opMode, store, ...params) {
765
753
  let protoUpdate;
766
754
  if (value === RESET_STATE) protoUpdate = resetAtomOrSelector(target, state);
767
755
  else protoUpdate = setAtomOrSelector(target, state, value);
768
- const isNewlyCreated = Boolean(brandNewToken);
769
- dispatchOrDeferStateUpdate(target, state, protoUpdate, isNewlyCreated, family);
756
+ dispatchOrDeferStateUpdate(target, state, protoUpdate, Boolean(brandNewToken), family);
770
757
  if (opMode === OWN_OP) closeOperation(target);
771
758
  }
772
759
 
@@ -780,8 +767,7 @@ const isStateKey = (store, key) => isAtomKey(store, key) || isSelectorKey(store,
780
767
  //#endregion
781
768
  //#region src/internal/selector/get-selector-dependency-keys.ts
782
769
  function getSelectorDependencyKeys(store, key) {
783
- const sources = newest(store).selectorGraph.getRelationEntries({ downstreamSelectorKey: key }).filter(([_, { source }]) => source !== key).map(([_, { source }]) => source).filter((source) => isStateKey(store, source));
784
- return sources;
770
+ return newest(store).selectorGraph.getRelationEntries({ downstreamSelectorKey: key }).filter(([_, { source }]) => source !== key).map(([_, { source }]) => source).filter((source) => isStateKey(store, source));
785
771
  }
786
772
 
787
773
  //#endregion
@@ -829,6 +815,7 @@ const subscribeToRootDependency = (target, selector, atom) => {
829
815
  function subscribeToState(store, token, key, handleUpdate) {
830
816
  function safelyHandleUpdate(update) {
831
817
  if (store.operation.open) {
818
+ if (state?.type === `atom` && hasRole(state, `tracker:signal`) && `*` + store.operation.token.key === token.key && `inboundTracker` in handleUpdate) return;
832
819
  const unsubscribe$1 = store.on.operationClose.subscribe(`state subscription ${key}`, () => {
833
820
  unsubscribe$1();
834
821
  handleUpdate(update);
@@ -846,13 +833,10 @@ function subscribeToState(store, token, key, handleUpdate) {
846
833
  for (const [atomKey, atom] of traceRootSelectorAtoms(store, state.key)) rootSubs.set(atomKey, subscribeToRootDependency(store, state, atom));
847
834
  updateHandler = function updateRootsBeforeHandlingUpdate(update) {
848
835
  const dependencies = traceRootSelectorAtoms(store, state.key);
849
- for (const [previousRootKey, unsub] of rootSubs) {
850
- const currentRoot = dependencies.get(previousRootKey);
851
- if (currentRoot) dependencies.delete(previousRootKey);
852
- else {
853
- unsub();
854
- rootSubs.delete(previousRootKey);
855
- }
836
+ for (const [previousRootKey, unsub] of rootSubs) if (dependencies.get(previousRootKey)) dependencies.delete(previousRootKey);
837
+ else {
838
+ unsub();
839
+ rootSubs.delete(previousRootKey);
856
840
  }
857
841
  for (const [atomKey, atom] of dependencies) rootSubs.set(atomKey, subscribeToRootDependency(store, state, atom));
858
842
  safelyHandleUpdate(update);
@@ -911,12 +895,11 @@ var Tracker = class {
911
895
  const stateKey = mutableState.key;
912
896
  const storeName = target.config.name;
913
897
  const storeStatus = isChildStore(target) ? target.transactionMeta.update.token.key : `main`;
914
- const subscriptionKey = `tracker:${storeName}:${storeStatus}:${stateKey}`;
898
+ const subscriptionKey = `tracker-from-core:${storeName}:${storeStatus}:${stateKey}`;
915
899
  const trackerCapturesOutboundSignal = (update) => {
916
- setIntoStore(target, latestSignalState, update);
900
+ operateOnStore(JOIN_OP, target, latestSignalState, update);
917
901
  };
918
- const originalInnerValue = getFromStore(target, mutableState);
919
- this.unsubscribeFromInnerValue = originalInnerValue.subscribe(subscriptionKey, trackerCapturesOutboundSignal);
902
+ this.unsubscribeFromInnerValue = getFromStore(target, mutableState).subscribe(subscriptionKey, trackerCapturesOutboundSignal);
920
903
  this.unsubscribeFromState = subscribeToState(target, mutableState, subscriptionKey, function trackerLooksForNewReference(update) {
921
904
  if (update.newValue !== update.oldValue) {
922
905
  this.unsubscribeFromInnerValue();
@@ -925,8 +908,11 @@ var Tracker = class {
925
908
  }.bind(this));
926
909
  }
927
910
  supplySignalsToCore(mutableState, latestSignalState, target) {
928
- const subscriptionKey = `tracker:${target.config.name}:${isChildStore(target) ? target.transactionMeta.update.token.key : `main`}:${mutableState.key}`;
929
- subscribeToState(target, latestSignalState, subscriptionKey, function trackerCapturesInboundSignal({ newValue, oldValue }) {
911
+ const stateKey = mutableState.key;
912
+ const storeName = target.config.name;
913
+ const storeStatus = isChildStore(target) ? target.transactionMeta.update.token.key : `main`;
914
+ const subscriptionKey = `tracker-to-core:${storeName}:${storeStatus}:${stateKey}`;
915
+ subscribeToState(target, latestSignalState, subscriptionKey, Object.assign(function trackerCapturesInboundSignal({ newValue, oldValue }) {
930
916
  const timelineId = target.timelineTopics.getRelatedKey(latestSignalState.key);
931
917
  if (timelineId && target.timelines.get(timelineId)?.timeTraveling) {
932
918
  const unsubscribe = subscribeToTimeline(target, {
@@ -950,7 +936,7 @@ var Tracker = class {
950
936
  const expected = mutable.cacheUpdateNumber + 1;
951
937
  target.logger.info(`❌`, `mutable_atom`, mutableState.key, `could not be updated. Expected update number`, expected, `but got`, updateNumber);
952
938
  }
953
- });
939
+ }, { inboundTracker: true }));
954
940
  }
955
941
  mutableAtomToken;
956
942
  latestSignalToken;
@@ -995,8 +981,7 @@ function writeToCache(target, state, value) {
995
981
  const future = new Future(value);
996
982
  target.valueMap.set(key, future);
997
983
  future.then(function handleResolvedFuture(resolved) {
998
- const current = target.valueMap.get(key);
999
- if (current === future) {
984
+ if (target.valueMap.get(key) === future) {
1000
985
  openOperation(target, state);
1001
986
  writeToCache(target, state, resolved);
1002
987
  switch (type) {
@@ -1032,8 +1017,7 @@ function writeToCache(target, state, value) {
1032
1017
  function readFromCache(target, state, mut) {
1033
1018
  target.logger.info(`📖`, state.type, state.key, `reading cached value`);
1034
1019
  let value = target.valueMap.get(state.key);
1035
- const mayNeedToBeCopied = mut === `mut` && state.type === `mutable_atom` && isChildStore(target);
1036
- if (mayNeedToBeCopied) {
1020
+ if (mut === `mut` && state.type === `mutable_atom` && isChildStore(target)) {
1037
1021
  const mutableAtom$1 = state;
1038
1022
  const { parent } = target;
1039
1023
  if (target.valueMap.hasOwn(mutableAtom$1.key)) return value;
@@ -1146,4 +1130,4 @@ function hasRole(atom, role) {
1146
1130
 
1147
1131
  //#endregion
1148
1132
  export { DO_NOT_CREATE, Future, INTERNAL_ROLES, JOIN_OP, NotFoundError, OWN_OP, RESET_STATE, StatefulSubject, Subject, Tracker, become, closeOperation, createRegularAtom, deposit, eldest, evictCachedValue, evictDownstreamFromAtom, evictDownstreamFromSelector, getFallback, getFamilyOfToken, getFromStore, getSelectorDependencyKeys, hasRole, isAtomKey, isChildStore, isDone, isReadonlySelectorKey, isRootStore, isSelectorKey, isStateKey, isTransceiver, markDone, mintInStore, newest, openOperation, operateOnStore, readFromCache, readOrComputeValue, recallState, reduceReference, resetAtomOrSelector, resetInStore, seekInStore, setAtomOrSelector, setIntoStore, subscribeToRootDependency, subscribeToState, subscribeToTimeline, traceRootSelectorAtoms, withdraw, writeToCache };
1149
- //# sourceMappingURL=has-role-hv4-hJMw.js.map
1133
+ //# sourceMappingURL=has-role-CMlaUlaf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"has-role-CMlaUlaf.js","names":["superResolve: ((value: T) => void) | undefined","superReject: ((reason?: any) => void) | undefined","withdrawn: AtomIOInternalResource | undefined","target: Store | null","val: E | T","def: E | T","MUST_CREATE: unique symbol","DO_NOT_CREATE: unique symbol","token: ReadableToken<T, KK, E>","existingToken: ReadableToken<T, K, E> | undefined","brandNewToken: ReadableToken<T, K, E> | undefined","family: ReadableFamily<T, K, E> | undefined","subKey: K | undefined","token: ReadableToken<T, K, E>","subType: `readable` | `writable`","stateCreationEvent: StateCreationEvent<any>","state: ReadableState<any, any> | undefined","stateCreationEvent: StateCreationEvent<any> & TimelineEvent<any>","update: StateUpdate<T>","atomUpdate: AtomUpdateEvent<any>","def: E | T","protoUpdate: ProtoUpdate<E | T>","RESET_STATE: unique symbol","oldValue: T","newValue: T","constant: T","protoUpdate: ProtoUpdate<T>","OWN_OP: unique symbol","JOIN_OP: unique symbol","existingToken: WritableToken<T, K, E> | undefined","brandNewToken: WritableToken<T, K, E> | undefined","token: WritableToken<T, K, E>","family: WritableFamily<T, K, E> | undefined","key: K | null","value: Setter<TT> | TT | typeof RESET_STATE","target: Store & { operation: OpenOperation }","protoUpdate: ProtoUpdate<E | T>","unsubscribe","updateHandler: UpdateHandler<E | T>","familyMetaData: FamilyMetadata | undefined","mutableAtom","newAtom: RegularAtom<T, E>","cleanupFunctions: (() => void)[]"],"sources":["../src/internal/lineage.ts","../src/internal/set-state/become.ts","../src/internal/future.ts","../src/internal/subject.ts","../src/internal/store/deposit.ts","../src/internal/transaction/is-root-store.ts","../src/internal/not-found-error.ts","../src/internal/store/withdraw.ts","../src/internal/get-state/get-fallback.ts","../src/internal/safe-compute.ts","../src/internal/get-state/read-or-compute-value.ts","../src/internal/families/get-family-of-token.ts","../src/internal/families/mint-in-store.ts","../src/internal/get-state/reduce-reference.ts","../src/internal/get-state/get-from-store.ts","../src/internal/families/seek-in-store.ts","../src/internal/operation.ts","../src/internal/set-state/dispatch-state-update.ts","../src/internal/set-state/set-atom.ts","../src/internal/set-state/reset-atom-or-selector.ts","../src/internal/set-state/set-into-store.ts","../src/internal/set-state/reset-in-store.ts","../src/internal/set-state/set-selector.ts","../src/internal/set-state/set-atom-or-selector.ts","../src/internal/set-state/operate-on-store.ts","../src/internal/keys.ts","../src/internal/selector/get-selector-dependency-keys.ts","../src/internal/selector/trace-selector-atoms.ts","../src/internal/subscribe/recall-state.ts","../src/internal/subscribe/subscribe-to-root-atoms.ts","../src/internal/subscribe/subscribe-to-state.ts","../src/internal/subscribe/subscribe-to-timeline.ts","../src/internal/mutable/tracker.ts","../src/internal/mutable/transceiver.ts","../src/internal/caching.ts","../src/internal/set-state/evict-downstream.ts","../src/internal/atom/create-regular-atom.ts","../src/internal/atom/has-role.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-redundant-type-constituents */\nexport interface Lineage {\n\tparent: typeof this | null\n\tchild: typeof this | null\n}\n\nexport function newest<T extends Lineage>(\n\tscion: T,\n): Exclude<T[`child`], null> | T {\n\twhile (scion.child !== null) {\n\t\tscion = scion.child\n\t}\n\treturn scion\n}\n\nexport function eldest<T extends Lineage>(\n\tscion: T,\n): Exclude<T[`parent`], T[`child`] | null> {\n\twhile (scion.parent !== null) {\n\t\tscion = scion.parent\n\t}\n\treturn scion as Exclude<T[`parent`], T[`child`] | null>\n}\n","import { isFn } from \"../is-fn\"\n\nexport function become<T>(\n\tnextVersionOfThing: T | ((prev: T) => T),\n\toriginalThing: T,\n): T {\n\tif (isFn(nextVersionOfThing)) {\n\t\treturn nextVersionOfThing(originalThing)\n\t}\n\treturn nextVersionOfThing\n}\n","/**\n * A Promise whose incoming value can be hot swapped.\n * @internal\n * @private\n * @typeParam T The type of the value that the promise will resolve to.\n *\n * @remarks\n * Can be constructed like a Promise, or from an existing Promise.\n */\nexport class Future<T> extends Promise<T> {\n\tprivate fate: Promise<T> | undefined\n\tprivate resolve: (value: T) => void\n\tprivate reject: (reason?: any) => void\n\n\tpublic done = false\n\n\tpublic constructor(\n\t\texecutor:\n\t\t\t| Promise<T>\n\t\t\t| ((resolve: (value: T) => void, reject: (reason?: any) => void) => void),\n\t) {\n\t\tlet superResolve: ((value: T) => void) | undefined\n\t\tlet superReject: ((reason?: any) => void) | undefined\n\t\tsuper((resolve, reject) => {\n\t\t\tsuperResolve = resolve\n\t\t\tsuperReject = reject\n\t\t})\n\t\tthis.resolve = superResolve as (value: T) => void\n\t\tthis.reject = superReject as (reason?: any) => void\n\t\tthis.use(executor instanceof Promise ? executor : new Promise(executor))\n\t}\n\n\tprivate pass(promise: Promise<T>, value: T) {\n\t\tif (promise === this.fate) {\n\t\t\tthis.resolve(value)\n\t\t\tthis.done = true\n\t\t}\n\t}\n\tprivate fail(promise: Promise<T>, reason: any) {\n\t\tif (promise === this.fate) {\n\t\t\tthis.reject(reason)\n\t\t\tthis.done = true\n\t\t}\n\t}\n\n\tpublic use(value: Promise<T> | T): void {\n\t\tif (this === value) {\n\t\t\treturn\n\t\t}\n\t\tif (value instanceof Promise) {\n\t\t\tconst promise = value\n\t\t\tthis.fate = promise\n\t\t\tpromise.then(\n\t\t\t\t(resolved) => {\n\t\t\t\t\tthis.pass(promise, resolved)\n\t\t\t\t},\n\t\t\t\t(reason) => {\n\t\t\t\t\tthis.fail(promise, reason)\n\t\t\t\t},\n\t\t\t)\n\t\t} else {\n\t\t\tthis.resolve(value)\n\t\t\tthis.fate = undefined\n\t\t}\n\t}\n}\n","export class Subject<T> {\n\tpublic Subscriber!: (value: T) => void\n\n\tpublic subscribers: Map<string, this[`Subscriber`]> = new Map()\n\n\tpublic subscribe(key: string, subscriber: this[`Subscriber`]): () => void {\n\t\tthis.subscribers.set(key, subscriber)\n\t\tconst unsubscribe = () => {\n\t\t\tthis.unsubscribe(key)\n\t\t}\n\t\treturn unsubscribe\n\t}\n\n\tprivate unsubscribe(key: string) {\n\t\tthis.subscribers.delete(key)\n\t}\n\n\tpublic next(value: T): void {\n\t\tconst subscribers = this.subscribers.values()\n\t\tfor (const subscriber of subscribers) {\n\t\t\tsubscriber(value)\n\t\t}\n\t}\n}\n\nexport class StatefulSubject<T> extends Subject<T> {\n\tpublic state: T\n\n\tpublic constructor(initialState: T) {\n\t\tsuper()\n\t\tthis.state = initialState\n\t}\n\n\tpublic next(value: T): void {\n\t\tthis.state = value\n\t\tsuper.next(value)\n\t}\n}\n","import type {\n\tAtomFamilyToken,\n\tAtomIOToken,\n\tAtomToken,\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlyPureSelectorFamilyToken,\n\tReadonlyPureSelectorToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tSelectorFamilyToken,\n\tSelectorToken,\n\tTimelineManageable,\n\tTimelineToken,\n\tTransactionToken,\n\tWritableFamilyToken,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport type { Transceiver } from \"../mutable\"\nimport type {\n\tAtom,\n\tAtomFamily,\n\tAtomIOInternalResource,\n\tMutableAtom,\n\tMutableAtomFamily,\n\tReadableFamily,\n\tReadableState,\n\tReadonlyPureSelector,\n\tReadonlyPureSelectorFamily,\n\tRegularAtom,\n\tRegularAtomFamily,\n\tSelector,\n\tSelectorFamily,\n\tWritableFamily,\n\tWritablePureSelector,\n\tWritablePureSelectorFamily,\n\tWritableState,\n} from \"../state-types\"\nimport type { Timeline } from \"../timeline\"\nimport type { Transaction } from \"../transaction\"\nimport type { Fn } from \"../utility-types\"\n\nexport function deposit<T, E>(\n\tstate: RegularAtom<T, E>,\n): RegularAtomToken<T, Canonical, E>\nexport function deposit<T extends Transceiver<any, any, any>>(\n\tstate: MutableAtom<T>,\n): MutableAtomToken<T>\nexport function deposit<T, E>(state: Atom<T, E>): AtomToken<T, Canonical, E>\nexport function deposit<T, E>(\n\tstate: WritablePureSelector<T, E>,\n): WritablePureSelectorToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: ReadonlyPureSelector<T, E>,\n): ReadonlyPureSelectorToken<T, any, E>\nexport function deposit<T, E>(state: Selector<T, E>): SelectorToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: WritableState<T, E>,\n): WritableToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: ReadableState<T, E>,\n): ReadableToken<T, any, E>\n\nexport function deposit<T, K extends Canonical, E>(\n\tstate: RegularAtomFamily<T, K, E>,\n): RegularAtomFamilyToken<T, K, E>\nexport function deposit<\n\tT extends Transceiver<any, any, any>,\n\tK extends Canonical,\n>(state: MutableAtomFamily<T, K>): MutableAtomFamilyToken<T, K>\nexport function deposit<T, E>(\n\tstate: AtomFamily<T, any, E>,\n): AtomFamilyToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: WritablePureSelectorFamily<T, any, E>,\n): WritablePureSelectorFamilyToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: ReadonlyPureSelectorFamily<T, any, E>,\n): ReadonlyPureSelectorFamilyToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: SelectorFamily<T, any, E>,\n): SelectorFamilyToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: WritableFamily<T, any, E>,\n): WritableFamilyToken<T, any, E>\nexport function deposit<T, E>(\n\tstate: ReadableFamily<T, any, E>,\n): ReadableFamilyToken<T, any, E>\n\nexport function deposit<T extends Fn>(state: Transaction<T>): TransactionToken<T>\nexport function deposit<M extends TimelineManageable>(\n\tstate: Timeline<M>,\n): TimelineToken<M>\n\nexport function deposit(resource: AtomIOInternalResource): AtomIOToken\n\nexport function deposit(state: AtomIOInternalResource): AtomIOToken {\n\tconst token = {\n\t\tkey: state.key,\n\t\ttype: state.type,\n\t} as any\n\tif (`family` in state) {\n\t\ttoken.family = state.family\n\t}\n\treturn token\n}\n","import type { MapOverlay } from \"../overlays/map-overlay\"\nimport type { Store } from \"../store\"\nimport type { Fn } from \"../utility-types\"\nimport type {\n\tTransactionEpoch,\n\tTransactionProgress,\n} from \"./transaction-meta-progress\"\n\nexport interface RootStore extends Store {\n\ttransactionMeta: TransactionEpoch\n\tparent: null\n\tchild: ChildStore | null\n}\nexport interface ChildStore extends Store {\n\ttransactionMeta: TransactionProgress<Fn>\n\tparent: ChildStore | RootStore\n\tchild: ChildStore | null\n\tvalueMap: MapOverlay<string, any>\n}\n\nexport function isRootStore(store: Store): store is RootStore {\n\treturn `epoch` in store.transactionMeta\n}\n\nexport function isChildStore(store: Store): store is ChildStore {\n\treturn `phase` in store.transactionMeta\n}\n","import { type AtomIOToken, PRETTY_TOKEN_TYPES } from \"atom.io\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport type { Store } from \"./store\"\n\nexport class NotFoundError extends Error {\n\tpublic constructor(token: AtomIOToken, store: Store) {\n\t\tsuper(\n\t\t\t`${PRETTY_TOKEN_TYPES[token.type]} ${stringifyJson(token.key)} not found in store \"${\n\t\t\t\tstore.config.name\n\t\t\t}\".`,\n\t\t)\n\t}\n}\n","import type {\n\tAtomFamilyToken,\n\tAtomIOToken,\n\tAtomToken,\n\tHeldSelectorFamilyToken,\n\tHeldSelectorToken,\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tPureSelectorFamilyToken,\n\tPureSelectorToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlyHeldSelectorFamilyToken,\n\tReadonlyHeldSelectorToken,\n\tReadonlyPureSelectorFamilyToken,\n\tReadonlyPureSelectorToken,\n\tReadonlySelectorFamilyToken,\n\tReadonlySelectorToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tSelectorFamilyToken,\n\tSelectorToken,\n\tTimelineManageable,\n\tTimelineToken,\n\tTransactionToken,\n\tWritableFamilyToken,\n\tWritableHeldSelectorFamilyToken,\n\tWritableHeldSelectorToken,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n\tWritableSelectorFamilyToken,\n\tWritableSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport type { Transceiver } from \"../mutable\"\nimport { NotFoundError } from \"../not-found-error\"\nimport type {\n\tAtom,\n\tAtomFamily,\n\tAtomIOInternalResource,\n\tHeldSelector,\n\tHeldSelectorFamily,\n\tMutableAtom,\n\tMutableAtomFamily,\n\tPureSelector,\n\tPureSelectorFamily,\n\tReadableFamily,\n\tReadableState,\n\tReadonlyHeldSelector,\n\tReadonlyHeldSelectorFamily,\n\tReadonlyPureSelector,\n\tReadonlyPureSelectorFamily,\n\tReadonlySelector,\n\tReadonlySelectorFamily,\n\tRegularAtom,\n\tRegularAtomFamily,\n\tSelector,\n\tSelectorFamily,\n\tWritableFamily,\n\tWritableHeldSelector,\n\tWritableHeldSelectorFamily,\n\tWritablePureSelector,\n\tWritablePureSelectorFamily,\n\tWritableSelector,\n\tWritableSelectorFamily,\n\tWritableState,\n} from \"../state-types\"\nimport type { Timeline } from \"../timeline\"\nimport type { Transaction } from \"../transaction\"\nimport type { Fn } from \"../utility-types\"\nimport type { Store } from \"./store\"\n\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: RegularAtomToken<T, any, E>,\n): RegularAtom<T, E>\nexport function withdraw<T extends Transceiver<any, any, any>>(\n\tstore: Store,\n\ttoken: MutableAtomToken<T, any>,\n): MutableAtom<T>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: AtomToken<T, any, E>,\n): Atom<T, E>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: WritableHeldSelectorToken<T>,\n): WritableHeldSelector<T>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: ReadonlyHeldSelectorToken<T>,\n): ReadonlyHeldSelector<T>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: WritablePureSelectorToken<T, any, E>,\n): WritablePureSelector<T, E>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorToken<T, any, E>,\n): ReadonlyPureSelector<T, E>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: ReadonlySelectorToken<T, any, E>,\n): ReadonlySelector<T, E>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: WritableSelectorToken<T, any, E>,\n): WritableSelector<T, E>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: HeldSelectorToken<T>,\n): HeldSelector<T>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: PureSelectorToken<T, any, E>,\n): PureSelector<T, E>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: SelectorToken<T, any, E>,\n): Selector<T, E>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: WritableToken<T, any, E>,\n): WritableState<T, E>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: ReadableToken<T, any, E>,\n): ReadableState<T, E>\n\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: RegularAtomFamilyToken<T, K, E>,\n): RegularAtomFamily<T, K, E>\nexport function withdraw<\n\tT extends Transceiver<any, any, any>,\n\tK extends Canonical,\n>(store: Store, token: MutableAtomFamilyToken<T, K>): MutableAtomFamily<T, K>\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: AtomFamilyToken<T, K, E>,\n): AtomFamily<T, K, E>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: ReadonlyHeldSelectorFamilyToken<T, K>,\n): ReadonlyHeldSelectorFamily<T, K>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: WritableHeldSelectorFamilyToken<T, K>,\n): WritableHeldSelectorFamily<T, K>\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorFamilyToken<T, K, E>,\n): ReadonlyPureSelectorFamily<T, K, E>\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: WritablePureSelectorFamilyToken<T, K, E>,\n): WritablePureSelectorFamily<T, K, E>\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: ReadonlySelectorFamilyToken<T, K, E>,\n): ReadonlySelectorFamily<T, K, E>\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: WritableSelectorFamilyToken<T, K, E>,\n): WritableSelectorFamily<T, K, E>\nexport function withdraw<T, K extends Canonical>(\n\tstore: Store,\n\ttoken: HeldSelectorFamilyToken<T, K>,\n): HeldSelectorFamily<T, K>\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: PureSelectorFamilyToken<T, K, E>,\n): PureSelectorFamily<T, K, E>\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: SelectorFamilyToken<T, K, E>,\n): SelectorFamily<T, K, E>\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<T, K, E>,\n): WritableFamily<T, K, E>\nexport function withdraw<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<T, K, E>,\n): ReadableFamily<T, K, E>\n\nexport function withdraw<T extends Fn>(\n\tstore: Store,\n\ttoken: TransactionToken<T>,\n): Transaction<T extends Fn ? T : never>\nexport function withdraw<T>(\n\tstore: Store,\n\ttoken: TimelineToken<T>,\n): Timeline<T extends TimelineManageable ? T : never>\n\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: WritableToken<T, any, E>,\n): WritableState<T, E>\nexport function withdraw<T, E>(\n\tstore: Store,\n\ttoken: ReadableToken<T, any, E>,\n): ReadableState<T, E>\n\nexport function withdraw(\n\tstore: Store,\n\ttoken: AtomIOToken,\n): AtomIOInternalResource\n\nexport function withdraw(\n\tstore: Store,\n\ttoken: AtomIOToken,\n): AtomIOInternalResource {\n\tlet withdrawn: AtomIOInternalResource | undefined\n\tlet target: Store | null = store\n\twhile (target !== null) {\n\t\tswitch (token.type) {\n\t\t\tcase `atom`:\n\t\t\tcase `mutable_atom`:\n\t\t\t\twithdrawn = target.atoms.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `writable_pure_selector`:\n\t\t\tcase `writable_held_selector`:\n\t\t\t\twithdrawn = target.writableSelectors.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `readonly_pure_selector`:\n\t\t\tcase `readonly_held_selector`:\n\t\t\t\twithdrawn = target.readonlySelectors.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `atom_family`:\n\t\t\tcase `mutable_atom_family`:\n\t\t\tcase `writable_pure_selector_family`:\n\t\t\tcase `readonly_pure_selector_family`:\n\t\t\tcase `writable_held_selector_family`:\n\t\t\tcase `readonly_held_selector_family`:\n\t\t\t\twithdrawn = target.families.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `timeline`:\n\t\t\t\twithdrawn = target.timelines.get(token.key)\n\t\t\t\tbreak\n\t\t\tcase `transaction`:\n\t\t\t\twithdrawn = target.transactions.get(token.key)\n\t\t\t\tbreak\n\t\t}\n\t\tif (withdrawn) {\n\t\t\treturn withdrawn\n\t\t}\n\t\ttarget = target.child\n\t}\n\tthrow new NotFoundError(token, store)\n}\n","import type { ReadableToken, ViewOf } from \"atom.io\"\nimport { type Canonical, stringifyJson } from \"atom.io/json\"\n\nimport type { ReadableFamily } from \"../state-types\"\nimport type { Store } from \"../store\"\n\nexport function getFallback<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: ReadableToken<T, K, E>,\n\tfamily: ReadableFamily<T, K, E>,\n\tsubKey: NoInfer<K>,\n): ViewOf<E | T> {\n\tconst disposal = store.disposalTraces.buffer.find(\n\t\t(item) => item?.key === stringifyJson(subKey),\n\t)\n\tstore.logger.error(\n\t\t`❌`,\n\t\ttoken.type,\n\t\ttoken.key,\n\t\t`gets a fallback value because key`,\n\t\tsubKey,\n\t\t`is not allocated`,\n\t\tdisposal\n\t\t\t? `This key was previously disposed:\\n${disposal.trace}`\n\t\t\t: `(no previous disposal trace found)`,\n\t)\n\tswitch (family.type) {\n\t\tcase `mutable_atom_family`: {\n\t\t\tif (store.defaults.has(family.key)) {\n\t\t\t\treturn store.defaults.get(family.key)\n\t\t\t}\n\t\t\tconst defaultValue = new family.class()\n\t\t\tstore.defaults.set(family.key, defaultValue)\n\t\t\treturn defaultValue.READONLY_VIEW\n\t\t}\n\t\tcase `atom_family`: {\n\t\t\tif (store.defaults.has(family.key)) {\n\t\t\t\treturn store.defaults.get(family.key)\n\t\t\t}\n\t\t\tconst def = family.default as (key: K) => T\n\t\t\tconst defaultValue = def(subKey)\n\t\t\tstore.defaults.set(family.key, defaultValue)\n\t\t\treturn defaultValue as ViewOf<T>\n\t\t}\n\t\tcase `readonly_pure_selector_family`:\n\t\tcase `writable_pure_selector_family`:\n\t\tcase `readonly_held_selector_family`:\n\t\tcase `writable_held_selector_family`: {\n\t\t\tif (store.defaults.has(family.key)) {\n\t\t\t\treturn store.defaults.get(family.key)\n\t\t\t}\n\t\t\tconst defaultValue = family.default(subKey)\n\t\t\tstore.defaults.set(family.key, defaultValue)\n\t\t\treturn defaultValue as ViewOf<T>\n\t\t}\n\t}\n}\n","import { writeToCache } from \"./caching\"\nimport { isFn } from \"./is-fn\"\nimport type { PureSelector, RegularAtom } from \"./state-types\"\nimport type { Store } from \"./store\"\n\nexport function safeCompute<T, E>(\n\ttarget: Store,\n\tstate: PureSelector<T, E> | RegularAtom<T, E>,\n): E | T {\n\tconst { type, key, catch: canCatch } = state\n\tswitch (type) {\n\t\tcase `readonly_pure_selector`:\n\t\tcase `writable_pure_selector`: {\n\t\t\tlet val: E | T\n\t\t\ttarget.logger.info(`🧮`, type, key, `computing value`)\n\t\t\ttry {\n\t\t\t\tval = state.getFrom(target)\n\t\t\t\tif (val instanceof Promise) {\n\t\t\t\t\treturn (val as Promise<E & T>).catch((thrown) => {\n\t\t\t\t\t\ttarget.logger.error(`💥`, type, key, `rejected:`, thrown)\n\t\t\t\t\t\tif (canCatch) {\n\t\t\t\t\t\t\tfor (const Class of canCatch) {\n\t\t\t\t\t\t\t\tif (thrown instanceof Class) {\n\t\t\t\t\t\t\t\t\treturn thrown\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tthrow thrown\n\t\t\t\t\t}) as E | T\n\t\t\t\t}\n\t\t\t} catch (e) {\n\t\t\t\ttarget.logger.error(`💥`, type, key, `rejected:`, e)\n\t\t\t\tif (canCatch) {\n\t\t\t\t\tfor (const Class of canCatch) {\n\t\t\t\t\t\tif (e instanceof Class) {\n\t\t\t\t\t\t\treturn writeToCache(target, state, e)\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthrow e\n\t\t\t}\n\t\t\tconst cachedValue = writeToCache(target, state, val)\n\t\t\treturn cachedValue\n\t\t}\n\t\tcase `atom`: {\n\t\t\tlet def: E | T\n\t\t\tif (isFn(state.default)) {\n\t\t\t\ttry {\n\t\t\t\t\tdef = state.default()\n\t\t\t\t\tif (def instanceof Promise) {\n\t\t\t\t\t\tdef = (def as Promise<T> & T).catch<E | T>((thrown) => {\n\t\t\t\t\t\t\ttarget.logger.error(`💥`, type, key, `rejected:`, thrown)\n\t\t\t\t\t\t\tif (canCatch) {\n\t\t\t\t\t\t\t\tfor (const Class of canCatch) {\n\t\t\t\t\t\t\t\t\tif (thrown instanceof Class) {\n\t\t\t\t\t\t\t\t\t\treturn thrown\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tthrow thrown\n\t\t\t\t\t\t}) as E | T\n\t\t\t\t\t}\n\t\t\t\t} catch (e) {\n\t\t\t\t\ttarget.logger.error(`💥`, type, key, `rejected:`, e)\n\t\t\t\t\tif (canCatch) {\n\t\t\t\t\t\tfor (const Class of canCatch) {\n\t\t\t\t\t\t\tif (e instanceof Class) {\n\t\t\t\t\t\t\t\tdef = writeToCache(target, state, e)\n\t\t\t\t\t\t\t\ttarget.logger.info(\n\t\t\t\t\t\t\t\t\t`✨`,\n\t\t\t\t\t\t\t\t\tstate.type,\n\t\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\t\t`computed default`,\n\t\t\t\t\t\t\t\t\tdef,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\treturn def\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tthrow e\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tdef = state.default\n\t\t\t\ttarget.logger.info(`✨`, state.type, key, `using static default`, def)\n\t\t\t}\n\t\t\tconst cachedValue = writeToCache(target, state, def)\n\t\t\treturn cachedValue\n\t\t}\n\t}\n}\n","import type { ViewOf } from \"atom.io\"\n\nimport { readFromCache, writeToCache } from \"../caching\"\nimport { safeCompute } from \"../safe-compute\"\nimport type { ReadableState } from \"../state-types\"\nimport type { Store } from \"../store\"\n\nexport function readOrComputeValue<T, E>(\n\ttarget: Store,\n\tstate: ReadableState<T, E>,\n\tmut?: undefined,\n): ViewOf<E | T>\nexport function readOrComputeValue<T, E>(\n\ttarget: Store,\n\tstate: ReadableState<T, E>,\n\tmut: `mut`,\n): E | T\nexport function readOrComputeValue<T, E>(\n\ttarget: Store,\n\tstate: ReadableState<T, E>,\n\tmut: `mut` | undefined,\n): E | T {\n\tif (target.valueMap.has(state.key)) {\n\t\treturn readFromCache(target, state, mut)\n\t}\n\ttarget.logger.info(`❔`, state.type, state.key, `value not found in cache`)\n\tconst { key } = state\n\tswitch (state.type) {\n\t\tcase `readonly_held_selector`:\n\t\tcase `writable_held_selector`:\n\t\t\ttarget.logger.info(`🧮`, state.type, key, `computing value`)\n\t\t\treturn state.getFrom(target)\n\t\tcase `writable_pure_selector`:\n\t\tcase `readonly_pure_selector`:\n\t\tcase `atom`:\n\t\t\treturn safeCompute(target, state)\n\t\tcase `mutable_atom`: {\n\t\t\tconst instance = new state.class()\n\t\t\ttarget.logger.info(`✨`, state.type, key, `created new instance`, instance)\n\t\t\tconst cachedValue = writeToCache(target, state, instance)\n\t\t\treturn cachedValue\n\t\t}\n\t}\n}\n","import type {\n\tMutableAtomToken,\n\tReadableToken,\n\tReadonlyPureSelectorToken,\n\tRegularAtomToken,\n\tWritablePureSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport type { Transceiver } from \"../mutable\"\nimport type {\n\tMutableAtomFamily,\n\tReadableFamily,\n\tReadonlyPureSelectorFamily,\n\tRegularAtomFamily,\n\tWritableFamily,\n\tWritablePureSelectorFamily,\n} from \"../state-types\"\nimport { type Store, withdraw } from \"../store\"\n\nexport function getFamilyOfToken<\n\tT extends Transceiver<any, any, any>,\n\tK extends Canonical,\n>(store: Store, token: MutableAtomToken<T, K>): MutableAtomFamily<T, K>\n\nexport function getFamilyOfToken<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: RegularAtomToken<T, K, E>,\n): RegularAtomFamily<T, K, E>\n\nexport function getFamilyOfToken<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: WritablePureSelectorToken<T, K, E>,\n): WritablePureSelectorFamily<T, K, E>\n\nexport function getFamilyOfToken<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorToken<T, K, E>,\n): ReadonlyPureSelectorFamily<T, K, E>\n\nexport function getFamilyOfToken<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: WritableToken<T, K, E>,\n): WritableFamily<T, K, E>\n\nexport function getFamilyOfToken<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: ReadableToken<T, K, E>,\n): ReadableFamily<T, K, E>\n\nexport function getFamilyOfToken(\n\tstore: Store,\n\ttoken: ReadableToken<any, any, any>,\n): ReadableFamily<any, any, any> {\n\treturn withdraw(store, {\n\t\t// biome-ignore lint/style/noNonNullAssertion: family is required\n\t\tkey: token.family!.key,\n\t\ttype: `${token.type}_family`,\n\t})\n}\n","import type { ReadableToken, WritableToken } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport type { ReadableFamily } from \"../state-types\"\nimport type { Store } from \"../store\"\n\nexport const FAMILY_MEMBER_TOKEN_TYPES = {\n\tatom_family: `atom`,\n\tmolecule_family: `molecule`,\n\tmutable_atom_family: `mutable_atom`,\n\treadonly_held_selector_family: `readonly_held_selector`,\n\treadonly_pure_selector_family: `readonly_pure_selector`,\n\twritable_held_selector_family: `writable_held_selector`,\n\twritable_pure_selector_family: `writable_pure_selector`,\n} as const\n\nexport const MUST_CREATE: unique symbol = Symbol(`MUST_CREATE`)\nexport const DO_NOT_CREATE: unique symbol = Symbol(`DO_NOT_CREATE`)\n\nexport function mintInStore<T, K extends Canonical, KK extends K, E>(\n\tmustCreate: typeof DO_NOT_CREATE | typeof MUST_CREATE,\n\tstore: Store,\n\tfamily: ReadableFamily<T, K, E>,\n\tkey: KK,\n): WritableToken<T, KK, E>\nexport function mintInStore<T, K extends Canonical, KK extends K, E>(\n\tmustCreate: typeof DO_NOT_CREATE | typeof MUST_CREATE,\n\tstore: Store,\n\tfamily: ReadableFamily<T, K, E>,\n\tkey: KK,\n): ReadableToken<T, KK, E>\nexport function mintInStore<T, K extends Canonical, KK extends K, E>(\n\tmustCreate: typeof DO_NOT_CREATE | typeof MUST_CREATE,\n\tstore: Store,\n\tfamily: ReadableFamily<T, K, E>,\n\tkey: KK,\n): ReadableToken<T, KK, E> {\n\tconst stringKey = stringifyJson(key)\n\tconst molecule = store.molecules.get(stringKey)\n\n\tconst cannotCreate = !molecule && store.config.lifespan === `immortal`\n\n\tif (cannotCreate) {\n\t\tconst { type: familyType, key: familyKey } = family\n\t\tstore.logger.warn(\n\t\t\t`💣`,\n\t\t\t`key`,\n\t\t\tstringKey,\n\t\t\t`was used to mint a counterfeit token for`,\n\t\t\tfamilyType,\n\t\t\t`\"${familyKey}\"`,\n\t\t)\n\t\tconst fullKey = `${familyKey}(${stringKey})`\n\t\tconst type = FAMILY_MEMBER_TOKEN_TYPES[familyType]\n\t\tconst stateToken: ReadableToken<T, KK, E> & { counterfeit: true } = {\n\t\t\tcounterfeit: true,\n\t\t\tkey: fullKey,\n\t\t\ttype,\n\t\t\tfamily: {\n\t\t\t\tkey: familyKey,\n\t\t\t\tsubKey: stringKey,\n\t\t\t},\n\t\t}\n\n\t\treturn stateToken\n\t}\n\n\tlet token: ReadableToken<T, KK, E>\n\tif (mustCreate === MUST_CREATE) {\n\t\tstore.logger.info(\n\t\t\t`👪`,\n\t\t\tfamily.type,\n\t\t\tfamily.key,\n\t\t\t`adds member`,\n\t\t\ttypeof key === `string` ? `\\`${key}\\`` : key,\n\t\t)\n\t\ttoken = family.create(key)\n\t\tif (molecule) {\n\t\t\tstore.moleculeData.set(stringKey, family.key)\n\t\t}\n\t} else {\n\t\tconst { type: familyType, key: familyKey } = family\n\t\tconst fullKey = `${familyKey}(${stringKey})`\n\t\tconst type = FAMILY_MEMBER_TOKEN_TYPES[familyType]\n\t\tconst stateToken: ReadableToken<T, KK, E> = {\n\t\t\tkey: fullKey,\n\t\t\ttype,\n\t\t\tfamily: {\n\t\t\t\tkey: familyKey,\n\t\t\t\tsubKey: stringKey,\n\t\t\t},\n\t\t}\n\n\t\treturn stateToken\n\t}\n\n\treturn token\n}\n","import type {\n\tReadableFamilyToken,\n\tReadableToken,\n\tStateCreationEvent,\n} from \"atom.io\"\nimport { type Canonical, parseJson } from \"atom.io/json\"\n\nimport { seekInStore } from \"../families\"\nimport { getFamilyOfToken } from \"../families/get-family-of-token\"\nimport { mintInStore, MUST_CREATE } from \"../families/mint-in-store\"\nimport { newest } from \"../lineage\"\nimport type { ReadableFamily } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport type { Subject } from \"../subject\"\nimport { isChildStore, isRootStore } from \"../transaction\"\n\nexport function reduceReference<T, K extends Canonical, E>(\n\tstore: Store,\n\t...params:\n\t\t| [token: ReadableFamilyToken<T, K, E>, key: NoInfer<K>]\n\t\t| [token: ReadableToken<T, K, E>]\n): {\n\ttoken: ReadableToken<T, K, E>\n\tfamily: ReadableFamily<T, K, E> | undefined\n\tsubKey: NoInfer<K> | undefined\n\tisNew: boolean\n} {\n\tlet existingToken: ReadableToken<T, K, E> | undefined\n\tlet brandNewToken: ReadableToken<T, K, E> | undefined\n\tlet family: ReadableFamily<T, K, E> | undefined\n\tlet subKey: K | undefined\n\tlet token: ReadableToken<T, K, E>\n\tif (params.length === 1) {\n\t\ttoken = params[0]\n\t\tif (`family` in token) {\n\t\t\tconst familyToken = getFamilyOfToken(store, token)\n\t\t\tfamily = withdraw(store, familyToken) as ReadableFamily<T, K, E>\n\t\t\tsubKey = parseJson(token.family.subKey)\n\t\t\texistingToken = seekInStore(store, familyToken, subKey)\n\t\t\tif (`counterfeit` in token) {\n\t\t\t\treturn {\n\t\t\t\t\ttoken,\n\t\t\t\t\tfamily,\n\t\t\t\t\tsubKey,\n\t\t\t\t\tisNew: false,\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!existingToken) {\n\t\t\t\tbrandNewToken = mintInStore(MUST_CREATE, store, familyToken, subKey)\n\t\t\t\ttoken = brandNewToken\n\t\t\t} else {\n\t\t\t\ttoken = existingToken\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfamily = withdraw(store, params[0])\n\t\tsubKey = params[1]\n\t\texistingToken = seekInStore(store, family, subKey)\n\t\tif (!existingToken) {\n\t\t\tbrandNewToken = mintInStore(MUST_CREATE, store, family, subKey)\n\t\t\ttoken = brandNewToken\n\t\t} else {\n\t\t\ttoken = existingToken\n\t\t}\n\t}\n\n\tconst isCounterfeit = `counterfeit` in token\n\tconst isNewlyCreated = Boolean(brandNewToken) && isCounterfeit === false\n\tif (isNewlyCreated && family) {\n\t\tlet subType: `readable` | `writable`\n\t\tswitch (token.type) {\n\t\t\tcase `readonly_pure_selector`:\n\t\t\tcase `readonly_held_selector`:\n\t\t\t\tsubType = `readable`\n\t\t\t\tbreak\n\t\t\tcase `atom`:\n\t\t\tcase `mutable_atom`:\n\t\t\tcase `writable_pure_selector`:\n\t\t\tcase `writable_held_selector`:\n\t\t\t\tsubType = `writable`\n\t\t\t\tbreak\n\t\t}\n\t\tconst stateCreationEvent: StateCreationEvent<any> = {\n\t\t\ttype: `state_creation`,\n\t\t\tsubType,\n\t\t\ttoken,\n\t\t\ttimestamp: Date.now(),\n\t\t}\n\t\tconst familySubject = family.subject as Subject<StateCreationEvent<any>>\n\t\tfamilySubject.next(stateCreationEvent)\n\t\tconst target = newest(store)\n\t\tif (token.family) {\n\t\t\tif (isRootStore(target)) {\n\t\t\t\tswitch (token.type) {\n\t\t\t\t\tcase `atom`:\n\t\t\t\t\tcase `mutable_atom`:\n\t\t\t\t\t\tstore.on.atomCreation.next(token)\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase `writable_pure_selector`:\n\t\t\t\t\tcase `readonly_pure_selector`:\n\t\t\t\t\tcase `writable_held_selector`:\n\t\t\t\t\tcase `readonly_held_selector`:\n\t\t\t\t\t\tstore.on.selectorCreation.next(token)\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisChildStore(target) &&\n\t\t\t\ttarget.on.transactionApplying.state === null\n\t\t\t) {\n\t\t\t\ttarget.transactionMeta.update.subEvents.push(stateCreationEvent)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn {\n\t\ttoken,\n\t\tfamily,\n\t\tsubKey,\n\t\tisNew: Boolean(brandNewToken),\n\t}\n}\n","import type { ReadableFamilyToken, ReadableToken, ViewOf } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport { type Store, withdraw } from \"../store\"\nimport { getFallback } from \"./get-fallback\"\nimport { readOrComputeValue } from \"./read-or-compute-value\"\nimport { reduceReference } from \"./reduce-reference\"\n\nexport function getFromStore<T>(store: Store, token: ReadableToken<T>): T\n\nexport function getFromStore<T, E>(\n\tstore: Store,\n\ttoken: ReadableToken<T, any, E>,\n): E | T\n\nexport function getFromStore<T, K extends Canonical, E>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<T, K, E>,\n\tkey: NoInfer<K>,\n): ViewOf<E | T>\n\nexport function getFromStore<T, K extends Canonical, E>(\n\tstore: Store,\n\t...params:\n\t\t| [token: ReadableFamilyToken<T, K, E>, key: NoInfer<K>]\n\t\t| [token: ReadableToken<T, any, E>]\n): ViewOf<E | T>\n\nexport function getFromStore<T, K extends Canonical, E>(\n\tstore: Store,\n\t...params:\n\t\t| [token: ReadableFamilyToken<T, K, E>, key: NoInfer<K>]\n\t\t| [token: ReadableToken<T, any, E>]\n): ViewOf<E | T> {\n\tconst { token, family, subKey } = reduceReference(store, ...params)\n\n\tif (`counterfeit` in token && family && subKey) {\n\t\treturn getFallback(store, token, family, subKey)\n\t}\n\tconst state = withdraw(store, token)\n\n\treturn readOrComputeValue(store, state)\n}\n","import type {\n\tAtomFamilyToken,\n\tAtomToken,\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableFamilyToken,\n\tReadableToken,\n\tReadonlyPureSelectorFamilyToken,\n\tReadonlyPureSelectorToken,\n\tRegularAtomFamilyToken,\n\tRegularAtomToken,\n\tSelectorFamilyToken,\n\tSelectorToken,\n\tWritableFamilyToken,\n\tWritablePureSelectorFamilyToken,\n\tWritablePureSelectorToken,\n\tWritableToken,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\nimport { stringifyJson } from \"atom.io/json\"\n\nimport { newest } from \"../lineage\"\nimport type { Transceiver } from \"../mutable\"\nimport type { ReadableState } from \"../state-types\"\nimport { deposit, type Store } from \"../store\"\n\nexport function seekInStore<\n\tT extends Transceiver<any, any, any>,\n\tK extends Canonical,\n\tKey extends K,\n>(\n\tstore: Store,\n\ttoken: MutableAtomFamilyToken<T, K>,\n\tkey: Key,\n): MutableAtomToken<T, Key> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\ttoken: RegularAtomFamilyToken<T, K, E>,\n\tkey: Key,\n): RegularAtomToken<T, Key, E> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\ttoken: AtomFamilyToken<T, K, E>,\n\tkey: Key,\n): AtomToken<T, Key, E> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\ttoken: WritablePureSelectorFamilyToken<T, K, E>,\n\tkey: Key,\n): WritablePureSelectorToken<T, Key, E> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\ttoken: ReadonlyPureSelectorFamilyToken<T, K, E>,\n\tkey: Key,\n): ReadonlyPureSelectorToken<T, Key, E> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\ttoken: SelectorFamilyToken<T, K, E>,\n\tkey: Key,\n): SelectorToken<T, Key, E> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<T, K, E>,\n\tkey: Key,\n): WritableToken<T, Key, E> | undefined\n\nexport function seekInStore<T, K extends Canonical, Key extends K, E>(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<T, K, E>,\n\tkey: Key,\n): ReadableToken<T, Key, E> | undefined\n\nexport function seekInStore(\n\tstore: Store,\n\ttoken: ReadableFamilyToken<any, any, any>,\n\tkey: Canonical,\n): ReadableToken<any, any, any> | undefined {\n\tconst subKey = stringifyJson(key)\n\tconst fullKey = `${token.key}(${subKey})`\n\tconst target = newest(store)\n\tlet state: ReadableState<any, any> | undefined\n\tswitch (token.type) {\n\t\tcase `atom_family`:\n\t\tcase `mutable_atom_family`:\n\t\t\tstate = target.atoms.get(fullKey)\n\t\t\tbreak\n\t\tcase `writable_held_selector_family`:\n\t\tcase `writable_pure_selector_family`:\n\t\t\tstate = target.writableSelectors.get(fullKey)\n\t\t\tbreak\n\t\tcase `readonly_held_selector_family`:\n\t\tcase `readonly_pure_selector_family`:\n\t\t\tstate = target.readonlySelectors.get(fullKey)\n\t\t\tbreak\n\t}\n\tif (state) {\n\t\treturn deposit(state)\n\t}\n\treturn state\n}\n","import type { AtomUpdateEvent, ReadableToken, StateCreationEvent } from \"atom.io\"\n\nimport type { Store } from \"./store\"\nimport { isChildStore } from \"./transaction/is-root-store\"\n\nexport type OperationProgress =\n\t| OpenOperation<any>\n\t| {\n\t\t\topen: false\n\t }\nexport type OpenOperation<\n\tR extends ReadableToken<any, any> = ReadableToken<any, any>,\n> = {\n\topen: true\n\ttoken: R\n\tdone: Set<string>\n\tprev: Map<string, any>\n\ttimestamp: number\n\tsubEvents: (AtomUpdateEvent<any> | StateCreationEvent<any>)[]\n}\n\nexport function openOperation(\n\tstore: Store,\n\ttoken: ReadableToken<any, any, any>,\n): number | (Store & { operation: OpenOperation }) {\n\tif (store.operation.open) {\n\t\tconst rejectionTime = performance.now()\n\t\tstore.logger.info(\n\t\t\t`🚫`,\n\t\t\ttoken.type,\n\t\t\ttoken.key,\n\t\t\t`deferring setState at T-${rejectionTime} until setState for \"${store.operation.token.key}\" is done`,\n\t\t)\n\t\treturn rejectionTime\n\t}\n\tstore.operation = {\n\t\topen: true,\n\t\tdone: new Set(),\n\t\tprev: new Map(),\n\t\ttimestamp: Date.now(),\n\t\ttoken,\n\t\tsubEvents: [],\n\t}\n\tstore.logger.info(\n\t\t`⭕`,\n\t\ttoken.type,\n\t\ttoken.key,\n\t\t`operation start in store \"${store.config.name}\"${\n\t\t\tisChildStore(store)\n\t\t\t\t? ` ${store.transactionMeta.phase} \"${store.transactionMeta.update.token.key}\"`\n\t\t\t\t: ``\n\t\t}`,\n\t)\n\treturn store as Store & { operation: OpenOperation }\n}\n\nexport function closeOperation(store: Store): void {\n\tif (store.operation.open) {\n\t\tstore.logger.info(\n\t\t\t`🔴`,\n\t\t\tstore.operation.token.type,\n\t\t\tstore.operation.token.key,\n\t\t\t`operation done in store \"${store.config.name}\"`,\n\t\t)\n\t}\n\tstore.operation = { open: false }\n\tstore.on.operationClose.next(store.operation)\n}\n\nexport const isDone = (store: Store, key: string): boolean => {\n\tif (!store.operation.open) {\n\t\tstore.logger.error(\n\t\t\t`🐞`,\n\t\t\t`unknown`,\n\t\t\tkey,\n\t\t\t`isDone called outside of an operation. This is probably a bug in AtomIO.`,\n\t\t)\n\t\treturn true\n\t}\n\treturn store.operation.done.has(key)\n}\nexport const markDone = (store: Store, key: string): void => {\n\tif (!store.operation.open) {\n\t\tstore.logger.error(\n\t\t\t`🐞`,\n\t\t\t`unknown`,\n\t\t\tkey,\n\t\t\t`markDone called outside of an operation. This is probably a bug in AtomIO.`,\n\t\t)\n\t\treturn\n\t}\n\tstore.operation.done.add(key)\n}\n","import type {\n\tAtomUpdateEvent,\n\tStateCreationEvent,\n\tStateUpdate,\n\tTimelineEvent,\n} from \"atom.io\"\n\nimport { hasRole } from \"../atom\"\nimport { readOrComputeValue } from \"../get-state\"\nimport { newest } from \"../lineage\"\nimport type { Transceiver } from \"../mutable\"\nimport { isTransceiver } from \"../mutable\"\nimport type { OpenOperation } from \"../operation\"\nimport type { MutableAtom, WritableFamily, WritableState } from \"../state-types\"\nimport { deposit, type Store } from \"../store\"\nimport type { Subject } from \"../subject\"\nimport { isChildStore, isRootStore } from \"../transaction\"\nimport { evictDownstreamFromAtom } from \"./evict-downstream\"\nimport type { ProtoUpdate } from \"./operate-on-store\"\n\nexport function dispatchOrDeferStateUpdate<T, E>(\n\ttarget: Store & { operation: OpenOperation<any> },\n\tstate: WritableState<T, E>,\n\t{ oldValue, newValue }: ProtoUpdate<E | T>,\n\tstateIsNewlyCreated: boolean,\n\tfamily?: WritableFamily<T, any, E>,\n): void {\n\tconst token = deposit(state)\n\tif (stateIsNewlyCreated && family) {\n\t\tstate.subject.next({ newValue })\n\t\tconst stateCreationEvent: StateCreationEvent<any> & TimelineEvent<any> = {\n\t\t\tcheckpoint: true,\n\t\t\ttype: `state_creation`,\n\t\t\tsubType: `writable`,\n\t\t\ttoken,\n\t\t\ttimestamp: Date.now(),\n\t\t\tvalue: newValue,\n\t\t}\n\t\ttarget.operation.subEvents.push(stateCreationEvent)\n\t\tconst familySubject = family.subject as Subject<StateCreationEvent<any>>\n\t\tfamilySubject.next(stateCreationEvent)\n\t\tconst innerTarget = newest(target)\n\t\tif (token.family) {\n\t\t\tif (isRootStore(innerTarget)) {\n\t\t\t\tswitch (token.type) {\n\t\t\t\t\tcase `atom`:\n\t\t\t\t\tcase `mutable_atom`:\n\t\t\t\t\t\ttarget.on.atomCreation.next(token)\n\t\t\t\t\t\tbreak\n\t\t\t\t\tcase `writable_pure_selector`:\n\t\t\t\t\tcase `writable_held_selector`:\n\t\t\t\t\t\ttarget.on.selectorCreation.next(token)\n\t\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tisChildStore(innerTarget) &&\n\t\t\t\tinnerTarget.on.transactionApplying.state === null\n\t\t\t) {\n\t\t\t\tinnerTarget.transactionMeta.update.subEvents.push(stateCreationEvent)\n\t\t\t}\n\t\t}\n\t\treturn /* bailing early here to avoid redundant update */\n\t}\n\tconst { key, subject, type } = state\n\n\tconst update: StateUpdate<T> = {\n\t\toldValue: isTransceiver(oldValue) ? oldValue.READONLY_VIEW : oldValue,\n\t\tnewValue: isTransceiver(newValue) ? newValue.READONLY_VIEW : newValue,\n\t}\n\n\tif (isRootStore(target)) {\n\t\tswitch (type) {\n\t\t\tcase `mutable_atom`:\n\t\t\t\ttarget.logger.info(\n\t\t\t\t\t`📢`,\n\t\t\t\t\ttype,\n\t\t\t\t\tkey,\n\t\t\t\t\t`is now (`,\n\t\t\t\t\tnewValue,\n\t\t\t\t\t`) subscribers:`,\n\t\t\t\t\tsubject.subscribers.keys(),\n\t\t\t\t)\n\t\t\t\tbreak\n\t\t\tcase `atom`:\n\t\t\tcase `writable_pure_selector`:\n\t\t\tcase `writable_held_selector`:\n\t\t\t\ttarget.logger.info(\n\t\t\t\t\t`📢`,\n\t\t\t\t\ttype,\n\t\t\t\t\tkey,\n\t\t\t\t\t`went (`,\n\t\t\t\t\toldValue,\n\t\t\t\t\t`->`,\n\t\t\t\t\tnewValue,\n\t\t\t\t\t`) subscribers:`,\n\t\t\t\t\tsubject.subscribers.keys(),\n\t\t\t\t)\n\t\t}\n\t\tsubject.next(update)\n\t}\n\n\tif (isChildStore(target) && (type === `mutable_atom` || type === `atom`)) {\n\t\tif (target.on.transactionApplying.state === null) {\n\t\t\tif (isTransceiver(newValue)) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst { timestamp } = target.operation\n\t\t\tconst atomUpdate: AtomUpdateEvent<any> = {\n\t\t\t\ttype: `atom_update`,\n\t\t\t\ttoken,\n\t\t\t\ttimestamp,\n\t\t\t\tupdate,\n\t\t\t}\n\t\t\ttarget.transactionMeta.update.subEvents.push(atomUpdate)\n\t\t\ttarget.logger.info(\n\t\t\t\t`📁`,\n\t\t\t\t`atom`,\n\t\t\t\tkey,\n\t\t\t\t`stowed (`,\n\t\t\t\toldValue,\n\t\t\t\t`->`,\n\t\t\t\tnewValue,\n\t\t\t\t`)`,\n\t\t\t)\n\t\t\treturn\n\t\t}\n\t\tif (hasRole(state, `tracker:signal`)) {\n\t\t\tconst keyOfMutable = key.slice(1)\n\t\t\tconst mutable = target.atoms.get(keyOfMutable) as MutableAtom<\n\t\t\t\tTransceiver<unknown, any, any>\n\t\t\t>\n\t\t\tconst transceiver = readOrComputeValue<Transceiver<any, any, any>, never>(\n\t\t\t\ttarget,\n\t\t\t\tmutable,\n\t\t\t\t`mut`,\n\t\t\t)\n\t\t\tconst accepted = transceiver.do(update.newValue) === null\n\t\t\tif (accepted === true) {\n\t\t\t\tevictDownstreamFromAtom(target, mutable)\n\t\t\t}\n\t\t}\n\t}\n}\n","import { writeToCache } from \"../caching\"\nimport { readOrComputeValue } from \"../get-state/read-or-compute-value\"\nimport type { OpenOperation } from \"../operation\"\nimport { markDone } from \"../operation\"\nimport type { Atom } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { become } from \"./become\"\nimport { evictDownstreamFromAtom } from \"./evict-downstream\"\nimport type { ProtoUpdate } from \"./operate-on-store\"\n\nexport const setAtom = <T>(\n\ttarget: Store & { operation: OpenOperation<any> },\n\tatom: Atom<T, any>,\n\tnext: NoInfer<T> | ((oldValue: T) => NoInfer<T>),\n): ProtoUpdate<T> => {\n\tconst oldValue = readOrComputeValue(target, atom, `mut`)\n\tlet newValue = become(next, oldValue)\n\ttarget.logger.info(`⭐`, `atom`, atom.key, `setting value`, newValue)\n\tnewValue = writeToCache(target, atom, newValue)\n\tmarkDone(target, atom.key)\n\tevictDownstreamFromAtom(target, atom)\n\treturn { oldValue, newValue }\n}\n","import { isFn } from \"../is-fn\"\nimport type { OpenOperation } from \"../operation\"\nimport { safeCompute } from \"../safe-compute\"\nimport { traceRootSelectorAtoms } from \"../selector\"\nimport type { Atom, WritableState } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { dispatchOrDeferStateUpdate } from \"./dispatch-state-update\"\nimport type { ProtoUpdate } from \"./operate-on-store\"\nimport { setAtom } from \"./set-atom\"\n\nfunction resetAtom<T, E>(\n\ttarget: Store & { operation: OpenOperation },\n\tatom: Atom<T, E>,\n): ProtoUpdate<E | T> {\n\tswitch (atom.type) {\n\t\tcase `mutable_atom`:\n\t\t\treturn setAtom(target, atom, new atom.class())\n\t\tcase `atom`: {\n\t\t\tlet def: E | T\n\t\t\tif (isFn(atom.default)) def = safeCompute(target, atom)\n\t\t\telse def = atom.default\n\t\t\treturn setAtom<E | T>(target, atom, def)\n\t\t}\n\t}\n}\n\nexport function resetAtomOrSelector<T, E>(\n\ttarget: Store & { operation: OpenOperation },\n\tstate: WritableState<T, E>,\n): ProtoUpdate<E | T> {\n\tlet protoUpdate: ProtoUpdate<E | T>\n\tswitch (state.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\t\tprotoUpdate = resetAtom(target, state)\n\t\t\tbreak\n\t\tcase `writable_held_selector`:\n\t\t\t{\n\t\t\t\tconst atoms = traceRootSelectorAtoms(target, state.key)\n\t\t\t\tfor (const atom of atoms.values()) {\n\t\t\t\t\tconst rootProtoUpdate = resetAtom(target, atom)\n\t\t\t\t\tdispatchOrDeferStateUpdate(target, state, rootProtoUpdate, false)\n\t\t\t\t}\n\t\t\t\tconst value = state.getFrom(target)\n\t\t\t\tprotoUpdate = { oldValue: value, newValue: value }\n\t\t\t}\n\t\t\tbreak\n\t\tcase `writable_pure_selector`:\n\t\t\t{\n\t\t\t\tconst oldValue = safeCompute(target, state)\n\t\t\t\tconst atoms = traceRootSelectorAtoms(target, state.key)\n\t\t\t\tfor (const atom of atoms.values()) {\n\t\t\t\t\tconst rootProtoUpdate = resetAtom(target, atom)\n\t\t\t\t\tdispatchOrDeferStateUpdate(target, state, rootProtoUpdate, false)\n\t\t\t\t}\n\t\t\t\tconst newValue = safeCompute(target, state)\n\t\t\t\tprotoUpdate = { oldValue, newValue }\n\t\t\t}\n\t\t\tbreak\n\t}\n\n\treturn protoUpdate\n}\n","import type { Setter, WritableFamilyToken, WritableToken } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport type { Store } from \"../store\"\nimport { operateOnStore, OWN_OP } from \"./operate-on-store\"\nimport type { RESET_STATE } from \"./reset-in-store\"\n\nexport function setIntoStore<T, TT extends T>(\n\tstore: Store,\n\ttoken: WritableToken<T, any, any>,\n\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n): void\n\nexport function setIntoStore<T, TT extends T, K extends Canonical>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<T, K, any>,\n\tkey: NoInfer<K>,\n\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n): void\n\nexport function setIntoStore<T, TT extends T, K extends Canonical>(\n\tstore: Store,\n\t...params:\n\t\t| [\n\t\t\t\ttoken: WritableFamilyToken<T, K, any>,\n\t\t\t\tkey: NoInfer<K>,\n\t\t\t\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n\t\t ]\n\t\t| [\n\t\t\t\ttoken: WritableToken<T, any, any>,\n\t\t\t\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n\t\t ]\n): void\n\nexport function setIntoStore<T, TT extends T, K extends Canonical>(\n\tstore: Store,\n\t...params:\n\t\t| [\n\t\t\t\ttoken: WritableFamilyToken<T, K, any>,\n\t\t\t\tkey: NoInfer<K>,\n\t\t\t\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n\t\t ]\n\t\t| [\n\t\t\t\ttoken: WritableToken<T, any, any>,\n\t\t\t\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n\t\t ]\n): void {\n\toperateOnStore(OWN_OP, store, ...params)\n}\n","import type { WritableFamilyToken, WritableToken } from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport type { Store } from \"../store\"\nimport { setIntoStore } from \"./set-into-store\"\n\nexport const RESET_STATE: unique symbol = Symbol(`RESET`)\n\nexport function resetInStore(\n\tstore: Store,\n\ttoken: WritableToken<any, any, any>,\n): void\n\nexport function resetInStore<K extends Canonical>(\n\tstore: Store,\n\ttoken: WritableFamilyToken<any, K, any>,\n\tkey: NoInfer<K>,\n): void\n\nexport function resetInStore<T, K extends Canonical>(\n\tstore: Store,\n\t...params:\n\t\t| [token: WritableFamilyToken<T, K, any>, key: NoInfer<K>]\n\t\t| [token: WritableToken<T, any, any>]\n): void\n\nexport function resetInStore<T, K extends Canonical>(\n\tstore: Store,\n\t...params:\n\t\t| [token: WritableFamilyToken<T, K, any>, key: NoInfer<K>]\n\t\t| [token: WritableToken<T, any, any>]\n): void {\n\tconst subParams = [...params, RESET_STATE] as const\n\tsetIntoStore(store, ...subParams)\n}\n","import { writeToCache } from \"../caching\"\nimport { readOrComputeValue } from \"../get-state\"\nimport { markDone, type OpenOperation } from \"../operation\"\nimport type { WritableSelector } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { become } from \"./become\"\nimport type { ProtoUpdate } from \"./operate-on-store\"\n\nexport function setSelector<T>(\n\ttarget: Store & { operation: OpenOperation<any> },\n\tselector: WritableSelector<T, any>,\n\tnext: NoInfer<T> | ((oldValue: T) => NoInfer<T>),\n): ProtoUpdate<T> {\n\tlet oldValue: T\n\tlet newValue: T\n\tlet constant: T\n\n\tconst { type, key } = selector\n\n\tswitch (selector.type) {\n\t\tcase `writable_pure_selector`:\n\t\t\toldValue = readOrComputeValue(target, selector, `mut`)\n\t\t\tnewValue = become(next, oldValue)\n\t\t\tnewValue = writeToCache(target, selector, newValue)\n\t\t\tbreak\n\t\tcase `writable_held_selector`:\n\t\t\tconstant = selector.const\n\t\t\tbecome(next, constant)\n\t\t\toldValue = constant\n\t\t\tnewValue = constant\n\t}\n\n\ttarget.logger.info(`⭐`, type, key, `setting to`, newValue)\n\tmarkDone(target, key)\n\tselector.setSelf(newValue)\n\treturn { oldValue, newValue }\n}\n","import type { OpenOperation } from \"../operation\"\nimport type { WritableState } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport type { ProtoUpdate } from \"./operate-on-store\"\nimport { setAtom } from \"./set-atom\"\nimport { setSelector } from \"./set-selector\"\n\nexport const setAtomOrSelector = <T>(\n\ttarget: Store & { operation: OpenOperation },\n\tstate: WritableState<T, any>,\n\tvalue: NoInfer<T> | ((oldValue: T) => NoInfer<T>),\n): ProtoUpdate<T> => {\n\tlet protoUpdate: ProtoUpdate<T>\n\tswitch (state.type) {\n\t\tcase `atom`:\n\t\tcase `mutable_atom`:\n\t\t\tprotoUpdate = setAtom(target, state, value)\n\t\t\tbreak\n\t\tcase `writable_pure_selector`:\n\t\tcase `writable_held_selector`:\n\t\t\tprotoUpdate = setSelector(target, state, value)\n\t\t\tbreak\n\t}\n\n\treturn protoUpdate\n}\n","import type { Setter, WritableFamilyToken, WritableToken } from \"atom.io\"\nimport { type Canonical, parseJson } from \"atom.io/json\"\n\nimport { seekInStore } from \"../families\"\nimport { getFamilyOfToken } from \"../families/get-family-of-token\"\nimport { mintInStore, MUST_CREATE } from \"../families/mint-in-store\"\nimport type { OpenOperation } from \"../operation\"\nimport { closeOperation, openOperation } from \"../operation\"\nimport type { WritableFamily } from \"../state-types\"\nimport { type Store, withdraw } from \"../store\"\nimport { dispatchOrDeferStateUpdate } from \"./dispatch-state-update\"\nimport { resetAtomOrSelector } from \"./reset-atom-or-selector\"\nimport { RESET_STATE } from \"./reset-in-store\"\nimport { setAtomOrSelector } from \"./set-atom-or-selector\"\n\nexport type ProtoUpdate<T> = { oldValue: T; newValue: T }\n\nexport const OWN_OP: unique symbol = Symbol(`OWN_OP`)\nexport const JOIN_OP: unique symbol = Symbol(`JOIN_OP`)\n\nexport function operateOnStore<T, TT extends T, K extends Canonical, E>(\n\topMode: typeof JOIN_OP | typeof OWN_OP,\n\tstore: Store,\n\t...params:\n\t\t| [\n\t\t\t\ttoken: WritableFamilyToken<T, K, E>,\n\t\t\t\tkey: NoInfer<K>,\n\t\t\t\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n\t\t ]\n\t\t| [\n\t\t\t\ttoken: WritableToken<T, any, E>,\n\t\t\t\tvalue: Setter<TT> | TT | typeof RESET_STATE,\n\t\t ]\n): void {\n\tlet existingToken: WritableToken<T, K, E> | undefined\n\tlet brandNewToken: WritableToken<T, K, E> | undefined\n\tlet token: WritableToken<T, K, E>\n\tlet family: WritableFamily<T, K, E> | undefined\n\tlet key: K | null\n\tlet value: Setter<TT> | TT | typeof RESET_STATE\n\tif (params.length === 2) {\n\t\ttoken = params[0]\n\t\tvalue = params[1]\n\t\tif (`family` in token) {\n\t\t\tfamily = getFamilyOfToken(store, token)\n\t\t\tkey = parseJson(token.family.subKey)\n\t\t\texistingToken = seekInStore(store, family, key)\n\t\t\tif (!existingToken) {\n\t\t\t\ttoken = brandNewToken = mintInStore(MUST_CREATE, store, family, key)\n\t\t\t} else {\n\t\t\t\ttoken = existingToken\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfamily = withdraw(store, params[0])\n\t\tkey = params[1]\n\t\tvalue = params[2]\n\t\texistingToken = seekInStore(store, family, key)\n\t\tif (!existingToken) {\n\t\t\ttoken = brandNewToken = mintInStore(MUST_CREATE, store, family, key)\n\t\t} else {\n\t\t\ttoken = existingToken\n\t\t}\n\t}\n\n\tconst action = value === RESET_STATE ? `reset` : `set`\n\n\tlet target: Store & { operation: OpenOperation }\n\n\tif (opMode === OWN_OP) {\n\t\tconst result = openOperation(store, token)\n\t\tconst rejected = typeof result === `number`\n\t\tif (rejected) {\n\t\t\tconst rejectionTime = result\n\t\t\tconst unsubscribe = store.on.operationClose.subscribe(\n\t\t\t\t`waiting to ${action} \"${token.key}\" at T-${rejectionTime}`,\n\t\t\t\tfunction waitUntilOperationCloseToSetState() {\n\t\t\t\t\tunsubscribe()\n\t\t\t\t\tstore.logger.info(\n\t\t\t\t\t\t`🟢`,\n\t\t\t\t\t\ttoken.type,\n\t\t\t\t\t\ttoken.key,\n\t\t\t\t\t\t`resuming deferred`,\n\t\t\t\t\t\taction,\n\t\t\t\t\t\t`from T-${rejectionTime}`,\n\t\t\t\t\t)\n\t\t\t\t\toperateOnStore(opMode, store, token, value)\n\t\t\t\t},\n\t\t\t)\n\t\t\treturn\n\t\t}\n\t\ttarget = result\n\t} else {\n\t\ttarget = store as Store & { operation: OpenOperation }\n\t}\n\n\tif (`counterfeit` in token && `family` in token) {\n\t\tconst subKey = token.family.subKey\n\t\tconst disposal = store.disposalTraces.buffer.find(\n\t\t\t(item) => item?.key === subKey,\n\t\t)\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\ttoken.type,\n\t\t\ttoken.key,\n\t\t\t`could not be`,\n\t\t\taction,\n\t\t\t`because key`,\n\t\t\tsubKey,\n\t\t\t`is not allocated.`,\n\t\t\tdisposal\n\t\t\t\t? `this key was previously disposed:${disposal.trace}`\n\t\t\t\t: `(no previous disposal trace found)`,\n\t\t)\n\t\treturn\n\t}\n\n\tconst state = withdraw(target, token)\n\tlet protoUpdate: ProtoUpdate<E | T>\n\tif (value === RESET_STATE) {\n\t\tprotoUpdate = resetAtomOrSelector(target, state)\n\t} else {\n\t\tprotoUpdate = setAtomOrSelector(target, state, value)\n\t}\n\n\tconst isNewlyCreated = Boolean(brandNewToken)\n\tdispatchOrDeferStateUpdate(target, state, protoUpdate, isNewlyCreated, family)\n\n\tif (opMode === OWN_OP) {\n\t\tcloseOperation(target)\n\t}\n}\n","import { newest } from \"./lineage\"\nimport type { Store } from \"./store\"\n\nexport type AtomKey<T> = string & { __atomKey?: never; __brand?: T }\nexport type SelectorKey<T> = string & { __selectorKey?: never; __brand?: T }\nexport type ReadonlySelectorKey<T> = string & {\n\t__readonlySelectorKey?: never\n\t__brand?: T\n}\n\nexport const isAtomKey = (store: Store, key: string): key is AtomKey<unknown> =>\n\tnewest(store).atoms.has(key)\nexport const isSelectorKey = (\n\tstore: Store,\n\tkey: string,\n): key is SelectorKey<unknown> => newest(store).writableSelectors.has(key)\nexport const isReadonlySelectorKey = (\n\tstore: Store,\n\tkey: string,\n): key is ReadonlySelectorKey<unknown> =>\n\tnewest(store).readonlySelectors.has(key)\n\nexport type StateKey<T> = AtomKey<T> | ReadonlySelectorKey<T> | SelectorKey<T>\nexport const isStateKey = (\n\tstore: Store,\n\tkey: string,\n): key is StateKey<unknown> =>\n\tisAtomKey(store, key) ||\n\tisSelectorKey(store, key) ||\n\tisReadonlySelectorKey(store, key)\n","import type { AtomKey, ReadonlySelectorKey, SelectorKey } from \"../keys\"\nimport { isStateKey } from \"../keys\"\nimport { newest } from \"../lineage\"\nimport type { Store } from \"../store\"\n\nexport function getSelectorDependencyKeys(\n\tstore: Store,\n\tkey: string,\n): (AtomKey<unknown> | ReadonlySelectorKey<unknown> | SelectorKey<unknown>)[] {\n\tconst sources = newest(store)\n\t\t.selectorGraph.getRelationEntries({ downstreamSelectorKey: key })\n\t\t.filter(([_, { source }]) => source !== key)\n\t\t.map(([_, { source }]) => source)\n\t\t.filter((source) => isStateKey(store, source))\n\treturn sources\n}\n","import { isAtomKey } from \"../keys\"\nimport type { Atom } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { getSelectorDependencyKeys } from \"./get-selector-dependency-keys\"\n\nexport function traceRootSelectorAtoms(\n\tstore: Store,\n\tselectorKey: string,\n\tcovered: Set<string> = new Set<string>(),\n): Map<string, Atom<any, any>> {\n\tconst dependencies = getSelectorDependencyKeys(store, selectorKey)\n\n\tconst roots = new Map<string, Atom<unknown, unknown>>()\n\n\twhile (dependencies.length > 0) {\n\t\t// biome-ignore lint/style/noNonNullAssertion: just checked length ^^^\n\t\tconst dependencyKey = dependencies.pop()!\n\t\tif (covered.has(dependencyKey)) {\n\t\t\tcontinue\n\t\t}\n\t\tcovered.add(dependencyKey)\n\t\tif (isAtomKey(store, dependencyKey)) {\n\t\t\tconst atom = store.atoms.get(dependencyKey) as Atom<unknown, unknown>\n\t\t\troots.set(atom.key, atom)\n\t\t} else {\n\t\t\tdependencies.push(...getSelectorDependencyKeys(store, dependencyKey))\n\t\t}\n\t}\n\treturn roots\n}\n","import { newest } from \"../lineage\"\nimport type { ReadableState } from \"../state-types\"\nimport type { Store } from \"../store\"\n\nexport const recallState = <T, E>(\n\tstore: Store,\n\tstate: ReadableState<T, E>,\n): T => {\n\tconst target = newest(store)\n\tif (target.operation.open) {\n\t\treturn target.operation.prev.get(state.key)\n\t}\n\treturn target.valueMap.get(state.key)\n}\n","import { readOrComputeValue } from \"../get-state/read-or-compute-value\"\nimport type { Atom, Selector } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { recallState } from \"./recall-state\"\n\nexport const subscribeToRootDependency = (\n\ttarget: Store,\n\tselector: Selector<any, any>,\n\tatom: Atom<any, any>,\n): (() => void) => {\n\treturn atom.subject.subscribe(\n\t\t`${selector.type}:${selector.key}`,\n\t\t(atomChange) => {\n\t\t\ttarget.logger.info(\n\t\t\t\t`📢`,\n\t\t\t\tselector.type,\n\t\t\t\tselector.key,\n\t\t\t\t`root`,\n\t\t\t\tatom.key,\n\t\t\t\t`went`,\n\t\t\t\tatomChange.oldValue,\n\t\t\t\t`->`,\n\t\t\t\tatomChange.newValue,\n\t\t\t)\n\t\t\tconst oldValue = recallState(target, selector)\n\t\t\tconst newValue = readOrComputeValue(target, selector)\n\t\t\ttarget.logger.info(\n\t\t\t\t`✨`,\n\t\t\t\tselector.type,\n\t\t\t\tselector.key,\n\t\t\t\t`went`,\n\t\t\t\toldValue,\n\t\t\t\t`->`,\n\t\t\t\tnewValue,\n\t\t\t)\n\t\t\tselector.subject.next({ newValue, oldValue })\n\t\t},\n\t)\n}\n","import type { ReadableToken, StateUpdate, UpdateHandler } from \"atom.io\"\n\nimport { hasRole } from \"../atom\"\nimport { readOrComputeValue } from \"../get-state\"\nimport { reduceReference } from \"../get-state/reduce-reference\"\nimport { traceRootSelectorAtoms } from \"../selector\"\nimport type { Store } from \"../store\"\nimport { withdraw } from \"../store\"\nimport { subscribeToRootDependency } from \"./subscribe-to-root-atoms\"\n\nexport function subscribeToState<T, E>(\n\tstore: Store,\n\ttoken: ReadableToken<T, any, E>,\n\tkey: string,\n\thandleUpdate: UpdateHandler<E | T>,\n): () => void {\n\tfunction safelyHandleUpdate(update: StateUpdate<any>): void {\n\t\tif (store.operation.open) {\n\t\t\tif (\n\t\t\t\tstate?.type === `atom` &&\n\t\t\t\thasRole(state, `tracker:signal`) &&\n\t\t\t\t`*` + store.operation.token.key === token.key &&\n\t\t\t\t`inboundTracker` in handleUpdate\n\t\t\t) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst unsubscribe = store.on.operationClose.subscribe(\n\t\t\t\t`state subscription ${key}`,\n\t\t\t\t() => {\n\t\t\t\t\tunsubscribe()\n\t\t\t\t\thandleUpdate(update)\n\t\t\t\t},\n\t\t\t)\n\t\t} else {\n\t\t\thandleUpdate(update)\n\t\t}\n\t}\n\treduceReference(store, token)\n\tconst state = withdraw(store, token)\n\tstore.logger.info(`👀`, state.type, state.key, `Adding subscription \"${key}\"`)\n\tconst isSelector =\n\t\tstate.type === `writable_pure_selector` ||\n\t\tstate.type === `readonly_pure_selector`\n\tconst rootSubs = new Map<string, () => void>()\n\tlet updateHandler: UpdateHandler<E | T> = safelyHandleUpdate\n\tif (isSelector) {\n\t\treadOrComputeValue(store, state)\n\t\tfor (const [atomKey, atom] of traceRootSelectorAtoms(store, state.key)) {\n\t\t\trootSubs.set(atomKey, subscribeToRootDependency(store, state, atom))\n\t\t}\n\t\tupdateHandler = function updateRootsBeforeHandlingUpdate(update) {\n\t\t\tconst dependencies = traceRootSelectorAtoms(store, state.key)\n\t\t\tfor (const [previousRootKey, unsub] of rootSubs) {\n\t\t\t\tconst currentRoot = dependencies.get(previousRootKey)\n\t\t\t\tif (currentRoot) {\n\t\t\t\t\tdependencies.delete(previousRootKey)\n\t\t\t\t} else {\n\t\t\t\t\tunsub()\n\t\t\t\t\trootSubs.delete(previousRootKey)\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const [atomKey, atom] of dependencies) {\n\t\t\t\trootSubs.set(atomKey, subscribeToRootDependency(store, state, atom))\n\t\t\t}\n\t\t\tsafelyHandleUpdate(update)\n\t\t}\n\t}\n\tconst mainUnsubFunction = state.subject.subscribe(key, updateHandler)\n\tconst unsubscribe = () => {\n\t\tstore.logger.info(\n\t\t\t`🙈`,\n\t\t\tstate.type,\n\t\t\tstate.key,\n\t\t\t`Removing subscription \"${key}\"`,\n\t\t)\n\t\tmainUnsubFunction()\n\t\tfor (const unsubFromDependency of rootSubs.values()) {\n\t\t\tunsubFromDependency()\n\t\t}\n\t}\n\n\treturn unsubscribe\n}\n","import type { TimelineEvent, TimelineManageable, TimelineToken } from \"atom.io\"\n\nimport type { Store } from \"../store/store\"\nimport { withdraw } from \"../store/withdraw\"\n\nexport const subscribeToTimeline = <ManagedAtom extends TimelineManageable>(\n\tstore: Store,\n\ttoken: TimelineToken<ManagedAtom>,\n\tkey: string,\n\thandleUpdate: (update: TimelineEvent<any> | `redo` | `undo`) => void,\n): (() => void) => {\n\tconst tl = withdraw(store, token)\n\tstore.logger.info(`👀`, `timeline`, token.key, `Adding subscription \"${key}\"`)\n\tconst unsubscribe = tl.subject.subscribe(key, handleUpdate)\n\treturn () => {\n\t\tstore.logger.info(\n\t\t\t`🙈`,\n\t\t\t`timeline`,\n\t\t\ttoken.key,\n\t\t\t`Removing subscription \"${key}\" from timeline`,\n\t\t)\n\t\tunsubscribe()\n\t}\n}\n","import type {\n\tFamilyMetadata,\n\tMutableAtomToken,\n\tRegularAtomToken,\n\tStateUpdate,\n} from \"atom.io\"\n\nimport { createRegularAtom } from \"../atom\"\nimport { getFromStore } from \"../get-state\"\nimport { newest } from \"../lineage\"\nimport { setIntoStore } from \"../set-state\"\nimport { JOIN_OP, operateOnStore } from \"../set-state/operate-on-store\"\nimport type { Store } from \"../store\"\nimport { subscribeToState, subscribeToTimeline } from \"../subscribe\"\nimport { isChildStore } from \"../transaction/is-root-store\"\nimport type { SignalFrom, Transceiver } from \"./transceiver\"\n\n/**\n * @internal Give the tracker a transceiver state and a store, and it will\n * subscribe to the transceiver's inner value. When the inner value changes,\n * the tracker will update its own state to reflect the change.\n */\nexport class Tracker<T extends Transceiver<any, any, any>> {\n\tprivate initializeSignalAtom(\n\t\tmutableState: MutableAtomToken<T>,\n\t\tstore: Store,\n\t): RegularAtomToken<SignalFrom<T> | null> {\n\t\tconst latestSignalStateKey = `*${mutableState.key}`\n\t\tstore.atoms.delete(latestSignalStateKey)\n\t\tstore.valueMap.delete(latestSignalStateKey)\n\t\tconst familyMetaData: FamilyMetadata | undefined = mutableState.family\n\t\t\t? {\n\t\t\t\t\tkey: `*${mutableState.family.key}`,\n\t\t\t\t\tsubKey: mutableState.family.subKey,\n\t\t\t\t}\n\t\t\t: undefined\n\t\tconst latestSignalState = createRegularAtom<\n\t\t\tSignalFrom<T> | null,\n\t\t\tany,\n\t\t\tnever\n\t\t>(\n\t\t\tstore,\n\t\t\t{\n\t\t\t\tkey: latestSignalStateKey,\n\t\t\t\tdefault: null,\n\t\t\t},\n\t\t\tfamilyMetaData,\n\t\t\t[`tracker:signal`],\n\t\t)\n\t\tif (store.parent?.valueMap.has(latestSignalStateKey)) {\n\t\t\tconst parentValue = store.parent.valueMap.get(latestSignalStateKey)\n\t\t\tstore.valueMap.set(latestSignalStateKey, parentValue)\n\t\t}\n\n\t\treturn latestSignalState\n\t}\n\n\tprivate unsubscribeFromInnerValue!: () => void\n\tprivate unsubscribeFromState!: () => void\n\tprivate captureSignalsFromCore(\n\t\tmutableState: MutableAtomToken<T, any>,\n\t\tlatestSignalState: RegularAtomToken<SignalFrom<T> | null>,\n\t\ttarget: Store,\n\t): void {\n\t\tconst stateKey = mutableState.key\n\t\tconst storeName = target.config.name\n\t\tconst storeStatus = isChildStore(target)\n\t\t\t? target.transactionMeta.update.token.key\n\t\t\t: `main`\n\t\tconst subscriptionKey = `tracker-from-core:${storeName}:${storeStatus}:${stateKey}`\n\t\tconst trackerCapturesOutboundSignal = (update: SignalFrom<T>) => {\n\t\t\toperateOnStore(JOIN_OP, target, latestSignalState, update)\n\t\t}\n\t\tconst originalInnerValue = getFromStore(target, mutableState)\n\t\tthis.unsubscribeFromInnerValue = originalInnerValue.subscribe(\n\t\t\tsubscriptionKey,\n\t\t\ttrackerCapturesOutboundSignal,\n\t\t)\n\t\tthis.unsubscribeFromState = subscribeToState(\n\t\t\ttarget,\n\t\t\tmutableState,\n\t\t\tsubscriptionKey,\n\t\t\tfunction trackerLooksForNewReference(update: SignalFrom<T>) {\n\t\t\t\tif (update.newValue !== update.oldValue) {\n\t\t\t\t\tthis.unsubscribeFromInnerValue()\n\t\t\t\t\tthis.unsubscribeFromInnerValue = update.newValue.subscribe(\n\t\t\t\t\t\tsubscriptionKey,\n\t\t\t\t\t\ttrackerCapturesOutboundSignal,\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t}.bind(this),\n\t\t)\n\t}\n\n\tprivate supplySignalsToCore(\n\t\tmutableState: MutableAtomToken<T>,\n\t\tlatestSignalState: RegularAtomToken<SignalFrom<T> | null>,\n\t\ttarget: Store,\n\t): void {\n\t\tconst stateKey = mutableState.key\n\t\tconst storeName = target.config.name\n\t\tconst storeStatus = isChildStore(target)\n\t\t\t? target.transactionMeta.update.token.key\n\t\t\t: `main`\n\t\tconst subscriptionKey = `tracker-to-core:${storeName}:${storeStatus}:${stateKey}`\n\t\tsubscribeToState(\n\t\t\ttarget,\n\t\t\tlatestSignalState,\n\t\t\tsubscriptionKey,\n\t\t\tObject.assign(\n\t\t\t\tfunction trackerCapturesInboundSignal({\n\t\t\t\t\tnewValue,\n\t\t\t\t\toldValue,\n\t\t\t\t}: StateUpdate<SignalFrom<T> | null>) {\n\t\t\t\t\tconst timelineId = target.timelineTopics.getRelatedKey(\n\t\t\t\t\t\tlatestSignalState.key,\n\t\t\t\t\t)\n\n\t\t\t\t\tif (timelineId && target.timelines.get(timelineId)?.timeTraveling) {\n\t\t\t\t\t\tconst unsubscribe = subscribeToTimeline(\n\t\t\t\t\t\t\ttarget,\n\t\t\t\t\t\t\t{ key: timelineId, type: `timeline` },\n\t\t\t\t\t\t\tsubscriptionKey,\n\t\t\t\t\t\t\tfunction trackerWaitsForTimeTravelToFinish(update) {\n\t\t\t\t\t\t\t\tunsubscribe()\n\t\t\t\t\t\t\t\tsetIntoStore(target, mutableState, (transceiver) => {\n\t\t\t\t\t\t\t\t\tif (update === `redo` && newValue) {\n\t\t\t\t\t\t\t\t\t\ttransceiver.do(newValue)\n\t\t\t\t\t\t\t\t\t} else if (update === `undo` && oldValue) {\n\t\t\t\t\t\t\t\t\t\ttransceiver.undo(oldValue)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn transceiver\n\t\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t)\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\n\t\t\t\t\tconst mutable = getFromStore(target, mutableState)\n\t\t\t\t\tconst updateNumber = mutable.getUpdateNumber(newValue)\n\t\t\t\t\tconst eventOffset = updateNumber - mutable.cacheUpdateNumber\n\t\t\t\t\tif (newValue && eventOffset === 1) {\n\t\t\t\t\t\tsetIntoStore(\n\t\t\t\t\t\t\ttarget,\n\t\t\t\t\t\t\tmutableState,\n\t\t\t\t\t\t\t(transceiver) => (transceiver.do(newValue), transceiver),\n\t\t\t\t\t\t)\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconst expected = mutable.cacheUpdateNumber + 1\n\t\t\t\t\t\ttarget.logger.info(\n\t\t\t\t\t\t\t`❌`,\n\t\t\t\t\t\t\t`mutable_atom`,\n\t\t\t\t\t\t\tmutableState.key,\n\t\t\t\t\t\t\t`could not be updated. Expected update number`,\n\t\t\t\t\t\t\texpected,\n\t\t\t\t\t\t\t`but got`,\n\t\t\t\t\t\t\tupdateNumber,\n\t\t\t\t\t\t)\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t{ inboundTracker: true },\n\t\t\t),\n\t\t)\n\t}\n\n\tpublic mutableAtomToken: MutableAtomToken<T>\n\tpublic latestSignalToken: RegularAtomToken<SignalFrom<T> | null>\n\n\tpublic [Symbol.dispose]!: () => void\n\n\tpublic constructor(mutableAtomToken: MutableAtomToken<T>, store: Store) {\n\t\tconst target = newest(store)\n\t\tconst latestSignalToken = this.initializeSignalAtom(mutableAtomToken, target)\n\t\tthis.mutableAtomToken = mutableAtomToken\n\t\tthis.latestSignalToken = latestSignalToken\n\t\tthis.captureSignalsFromCore(mutableAtomToken, latestSignalToken, target)\n\t\tthis.supplySignalsToCore(mutableAtomToken, latestSignalToken, target)\n\t\ttarget.trackers.set(mutableAtomToken.key, this)\n\t\tthis[Symbol.dispose] = () => {\n\t\t\tthis.unsubscribeFromInnerValue()\n\t\t\tthis.unsubscribeFromState()\n\t\t\ttarget.trackers.delete(mutableAtomToken.key)\n\t\t}\n\t}\n}\n","import type { Json } from \"atom.io/json\"\n\nexport interface Transceiver<\n\tV,\n\tS extends Json.Serializable,\n\tJ extends Json.Serializable,\n> {\n\tREADONLY_VIEW: V\n\tdo: (update: S) => number | `OUT_OF_RANGE` | null\n\tundo: (update: S) => void\n\tsubscribe: (key: string, fn: (update: S) => void) => () => void\n\tcacheUpdateNumber: number\n\tgetUpdateNumber: (update: S) => number\n\ttoJSON: () => J\n}\n\n// biome-ignore format: intersection\nexport type TransceiverConstructor<\n J extends Json.Serializable,\n T extends Transceiver<any, any, J>\n> =\n\t& ( new () => T )\n\t& { fromJSON: (json: J) => T }\n\nexport function isTransceiver(\n\tvalue: unknown,\n): value is Transceiver<any, Json.Serializable, Json.Serializable> {\n\treturn (\n\t\ttypeof value === `object` &&\n\t\tvalue !== null &&\n\t\t`do` in value &&\n\t\t`undo` in value &&\n\t\t`subscribe` in value &&\n\t\t`cacheUpdateNumber` in value &&\n\t\t`getUpdateNumber` in value &&\n\t\t`READONLY_VIEW` in value &&\n\t\t`toJSON` in value\n\t)\n}\n\nexport type TransceiverMode = `playback` | `record` | `transaction`\n\nexport type SignalFrom<T extends Transceiver<any, any, any>> =\n\tT extends Transceiver<any, infer S, any> ? S : never\n\nexport type AsJSON<T extends Transceiver<any, any, any>> = T extends Transceiver<\n\tany,\n\tany,\n\tinfer J\n>\n\t? J\n\t: never\n\nexport type ConstructorOf<T extends Transceiver<any, any, any>> =\n\tTransceiverConstructor<AsJSON<T>, T>\n\n/*\nA transceiver may also keep a list of updates that have been applied to it.\nThis is useful for undo/redo functionality, especially in the context of\nrevising history. It is a good idea to accept a cache limit in your\nconstructor, and overwrite old updates. Here's an example of how we\nmight set that up:\n\nmyTransceiver = Transceiver {\n\tcacheUpdateNumber: number = 27\n\tcacheIdx: number = 1\n\tcacheLimit: number = 3\n\tcache: Array<Update> = [\n\t\t26=add:\"x\"\n\t\t27=del:\"x\" (current)\n\t\t25=add:\"y\"\n\t]\n}\n\nCONFIRM/NO-OP\nUpdate `27=del:\"x\"` is passed to myTransceiver.do:\n- [updateNumber = 27, update = `del:\"x\"`]\n- updateOffset = updateNumber - cacheUpdateNumber // 0\n- eventOffset < 1 // true (we're validating the past)\n- |eventOffset| < cacheLimit // true (we remember this update)\n- eventIdx = cacheIdx + updateOffset // 1\n- update === cache.get(eventIdx) // true\n- return null // 👍\n\nEXPECTED UPDATE\nUpdate `28=add:\"x\"` is passed to myTransceiver.do:\n- [updateNumber = 28, update = `add:\"x\"`]\n- updateOffset = updateNumber - cacheUpdateNumber // 1\n- eventOffset < 1 // false (we're in the future)\n- eventOffset === 1 // true (we're ready to apply this update)\n- cacheIdx += eventOffset // 2\n- cacheIdx %= cacheLimit // 2\n- cache[cacheIdx] = update // cache = <{ 0 => add:\"x\" }>\n- return null // 👍\n\nUNEXPECTED UPDATE\nUpdate `29=del:\"x\"` is passed to myTransceiver.do:\n- [updateNumber = 29, update = `del:\"x\"`]\n- updateOffset = updateNumber - cacheUpdateNumber // 2\n- eventOffset < 1 // false (we're in the future)\n- eventOffset === 1 // false (we're NOT ready to apply this update)\n- updateIdx := cacheIdx + updateOffset // 3\n- updateIdx %= cacheLimit // 0\n- cache[updateIdx] = update // cache = <{ 0 => del:\"x\" }>\n- expectedUpdateNumber = cacheUpdateNumber + 1 // 28\n- return expectedUpdateNumber // 🤨👂\n\nSUCCESSFUL ROLLBACK UPDATE\nUpdate `25=add:\"z\"` is passed to myTransceiver.do:\n- [updateNumber = 25, update = `add:\"z\"`]\n- updateOffset = updateNumber - cacheUpdateNumber // -2\n- eventOffset < 1 // true (we're validating the past)\n- |eventOffset| < cacheLimit // true (we remember this update)\n- eventIdx = cacheIdx + updateOffset // -1\n- eventIdx %= cacheLimit // 2\n- update === cache[eventIdx] // false (we're rolling back)\n- done := false\n- update := cache[cacheIdx] // update = `del:\"x\"`\n- undo(update) // myTransceiver.undo(`del:\"x\"`)\n- while (!done) {\n- \tcacheIdx -= 1 // 0, -1\n- \tcacheIdx %= cacheLimit // 0, 2\n- \tupdate = cache[cacheIdx] // update = `add:\"y\"`, `add:\"x\"`\n- \tundo(update) // myTransceiver.undo(`add:\"y\"`), myTransceiver.undo(`add:\"x\"`)\n- \tdone = cacheIdx === eventIdx // false, true\n- }\n- do(update) // myTransceiver.do(`add:\"z\"`)\n- return null // 👍\n\nUNSUCCESSFUL ROLLBACK UPDATE\nUpdate `24=add:\"z\"` is passed to myTransceiver.do:\n- [updateNumber = 24, update = `add:\"z\"`]\n- updateOffset = updateNumber - cacheUpdateNumber // -3\n- eventOffset < 1 // true (we're validating the past)\n- |eventOffset| < cacheLimit // 3 < 3 // false (we don't remember this update)\n- return `OUT_OF_RANGE` // 😵‍💫👂\n\n*/\n\n// The function wants a constructor C\n// - that has a static fromJSON(json) returning an instance of C\n// - and whose instances have toJSON() whose return type matches fromJSON's param\n","import { Future } from \"./future\"\nimport { Tracker, type Transceiver } from \"./mutable\"\nimport { closeOperation, openOperation } from \"./operation\"\nimport {\n\tevictDownstreamFromAtom,\n\tevictDownstreamFromSelector,\n} from \"./set-state/evict-downstream\"\nimport type { ReadableState } from \"./state-types\"\nimport type { Store } from \"./store\"\nimport { isChildStore } from \"./transaction\"\n\nexport function writeToCache<T, E>(\n\ttarget: Store,\n\tstate: ReadableState<T, E>,\n\tvalue: E | T,\n): E | T\nexport function writeToCache<T extends Promise<any>, E>(\n\ttarget: Store,\n\tstate: ReadableState<T, E>,\n\tvalue: T,\n): Future<Awaited<E | T>>\nexport function writeToCache<T, E>(\n\ttarget: Store,\n\tstate: ReadableState<T, E>,\n\tvalue: E | T,\n): E | Future<E | T> | T {\n\tconst { key, subject, type } = state\n\tconst currentValue = target.valueMap.get(key)\n\tif (currentValue instanceof Future && !currentValue.done) {\n\t\tconst future = currentValue\n\t\tif (value instanceof Promise) {\n\t\t\tfuture.use(value)\n\t\t\treturn future\n\t\t}\n\t\ttarget.valueMap.set(key, value)\n\t\treturn value\n\t}\n\tif (value instanceof Promise) {\n\t\tconst future = new Future<T>(value)\n\t\ttarget.valueMap.set(key, future)\n\t\tfuture\n\t\t\t.then(function handleResolvedFuture(resolved) {\n\t\t\t\tconst current = target.valueMap.get(key)\n\t\t\t\tif (current === future) {\n\t\t\t\t\topenOperation(target, state)\n\t\t\t\t\twriteToCache(target, state, resolved)\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check\n\t\t\t\t\tswitch (type) {\n\t\t\t\t\t\tcase `atom`:\n\t\t\t\t\t\t\tevictDownstreamFromAtom(target, state)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\tcase `readonly_pure_selector`:\n\t\t\t\t\t\tcase `writable_pure_selector`:\n\t\t\t\t\t\t\tevictDownstreamFromSelector(target, key)\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t// held selectors, by definition, don't become promises\n\t\t\t\t\t}\n\t\t\t\t\tcloseOperation(target)\n\t\t\t\t\tsubject.next({ newValue: resolved, oldValue: future })\n\t\t\t\t}\n\t\t\t})\n\t\t\t.catch((thrown) => {\n\t\t\t\ttarget.logger.error(`💥`, state.type, key, `rejected:`, thrown)\n\t\t\t})\n\t\treturn future\n\t}\n\ttarget.logger.info(`📝`, state.type, state.key, `writing to cache`, value)\n\ttarget.valueMap.set(key, value)\n\treturn value\n}\n\n/**\n * @param target - the newest layer of the store\n * @param state - the state to read from cache\n * @param mut - whether the value is intended to be mutable\n * @returns the state's current value\n */\nexport function readFromCache<T, E>(\n\ttarget: Store,\n\tstate: ReadableState<T, E>,\n\tmut: `mut` | undefined,\n): E | T {\n\ttarget.logger.info(`📖`, state.type, state.key, `reading cached value`)\n\tlet value = target.valueMap.get(state.key) as E | T\n\n\tconst mayNeedToBeCopied =\n\t\tmut === `mut` && state.type === `mutable_atom` && isChildStore(target)\n\tif (mayNeedToBeCopied) {\n\t\tconst mutableAtom = state\n\t\tconst { parent } = target\n\n\t\tif (target.valueMap.hasOwn(mutableAtom.key)) {\n\t\t\treturn value\n\t\t}\n\n\t\tconst parentValue = parent.valueMap.get(mutableAtom.key) as T &\n\t\t\tTransceiver<any, any, any>\n\n\t\ttarget.logger.info(`📃`, `atom`, mutableAtom.key, `copying`)\n\t\tconst jsonValue = parentValue.toJSON()\n\t\tconst copiedValue = mutableAtom.class.fromJSON(jsonValue)\n\t\ttarget.valueMap.set(mutableAtom.key, copiedValue)\n\t\tnew Tracker(mutableAtom, parent)\n\t\tvalue = copiedValue\n\t}\n\treturn value\n}\n\nexport function evictCachedValue(target: Store, key: string): void {\n\tconst currentValue = target.valueMap.get(key)\n\tif (currentValue instanceof Future) {\n\t\tconst selector =\n\t\t\ttarget.writableSelectors.get(key) ?? target.readonlySelectors.get(key)\n\t\tif (selector) {\n\t\t\tselector.getFrom(target)\n\t\t}\n\t\treturn\n\t}\n\tif (target.operation.open) {\n\t\ttarget.operation.prev.set(key, currentValue)\n\t}\n\ttarget.valueMap.delete(key)\n\ttarget.logger.info(`🗑`, `state`, key, `evicted`)\n}\n","import { evictCachedValue } from \"../caching\"\nimport { newest } from \"../lineage\"\nimport { isDone, markDone } from \"../operation\"\nimport type { Atom } from \"../state-types\"\nimport type { Store } from \"../store\"\n\nexport function evictDownstreamFromAtom(\n\tstore: Store,\n\tatom: Atom<any, any>,\n): void {\n\tconst target = newest(store)\n\tconst { key, type } = atom\n\tconst downstreamKeys = target.selectorAtoms.getRelatedKeys(key)\n\ttarget.logger.info(\n\t\t`🧹`,\n\t\ttype,\n\t\tkey,\n\t\tdownstreamKeys\n\t\t\t? `evicting ${downstreamKeys.size} states downstream:`\n\t\t\t: `no downstream states`,\n\t\tdownstreamKeys ?? `to evict`,\n\t)\n\tif (downstreamKeys) {\n\t\tif (target.operation.open) {\n\t\t\ttarget.logger.info(\n\t\t\t\t`🧹`,\n\t\t\t\ttype,\n\t\t\t\tkey,\n\t\t\t\t`[ ${[...target.operation.done].join(`, `)} ] already done`,\n\t\t\t)\n\t\t}\n\t\tfor (const downstreamKey of downstreamKeys) {\n\t\t\tif (isDone(target, downstreamKey)) {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tevictCachedValue(target, downstreamKey)\n\t\t\tmarkDone(target, downstreamKey)\n\t\t}\n\t}\n}\n\nexport function evictDownstreamFromSelector(\n\tstore: Store,\n\tselectorKey: string,\n): void {\n\tconst target = newest(store)\n\tconst relationEntries = target.selectorGraph\n\t\t.getRelationEntries({\n\t\t\tupstreamSelectorKey: selectorKey,\n\t\t})\n\t\t.filter(([_, { source }]) => source === selectorKey)\n\tfor (const [downstreamSelectorKey] of relationEntries) {\n\t\tif (isDone(target, downstreamSelectorKey)) {\n\t\t\tcontinue\n\t\t}\n\t\tevictCachedValue(target, downstreamSelectorKey)\n\t\tmarkDone(target, downstreamSelectorKey)\n\t\tevictDownstreamFromSelector(store, downstreamSelectorKey)\n\t}\n}\n","import type {\n\tFamilyMetadata,\n\tRegularAtomOptions,\n\tRegularAtomToken,\n\tUpdateHandler,\n} from \"atom.io\"\nimport type { Canonical } from \"atom.io/json\"\n\nimport { newest } from \"../lineage\"\nimport { resetInStore, setIntoStore } from \"../set-state\"\nimport type { RegularAtom } from \"../state-types\"\nimport type { Store } from \"../store\"\nimport { deposit } from \"../store\"\nimport { Subject } from \"../subject\"\nimport { subscribeToState } from \"../subscribe\"\nimport type { RootStore } from \"../transaction\"\nimport type { InternalRole } from \"./has-role\"\n\nexport function createRegularAtom<T, K extends Canonical, E>(\n\tstore: Store,\n\toptions: RegularAtomOptions<T, E>,\n\tfamily: FamilyMetadata<K> | undefined,\n\tinternalRoles?: InternalRole[],\n): RegularAtomToken<T, K, E> {\n\tconst type = `atom`\n\tconst { key } = options\n\tstore.logger.info(`🔨`, type, key, `is being created`)\n\n\tconst target = newest(store)\n\tconst existing = target.atoms.get(key)\n\tif (existing && existing.type === type) {\n\t\tstore.logger.error(\n\t\t\t`❌`,\n\t\t\t`atom`,\n\t\t\tkey,\n\t\t\t`Tried to create atom, but it already exists in the store.`,\n\t\t)\n\t\treturn deposit(existing) as RegularAtomToken<T, K, E>\n\t}\n\tconst subject = new Subject<{ newValue: T; oldValue: T }>()\n\tconst newAtom: RegularAtom<T, E> = {\n\t\t...options,\n\t\ttype,\n\t\tinstall: (s: RootStore) => {\n\t\t\ts.logger.info(`🛠️`, type, key, `installing in store \"${s.config.name}\"`)\n\t\t\treturn createRegularAtom(s, options, family)\n\t\t},\n\t\tsubject,\n\t} as const\n\tif (family) {\n\t\tnewAtom.family = family\n\t}\n\tif (internalRoles) {\n\t\tnewAtom.internalRoles = internalRoles\n\t}\n\ttarget.atoms.set(key, newAtom)\n\tconst token = deposit(newAtom) as RegularAtomToken<T, K, E>\n\tif (options.effects) {\n\t\tlet effectIndex = 0\n\t\tconst cleanupFunctions: (() => void)[] = []\n\t\tfor (const effect of options.effects) {\n\t\t\tconst cleanup = effect({\n\t\t\t\tresetSelf: () => {\n\t\t\t\t\tresetInStore(store, token)\n\t\t\t\t},\n\t\t\t\tsetSelf: (next) => {\n\t\t\t\t\tsetIntoStore(store, token, next)\n\t\t\t\t},\n\t\t\t\tonSet: (handle: UpdateHandler<T>) =>\n\t\t\t\t\tsubscribeToState(store, token, `effect[${effectIndex}]`, handle),\n\t\t\t})\n\t\t\tif (cleanup) {\n\t\t\t\tcleanupFunctions.push(cleanup)\n\t\t\t}\n\t\t\t++effectIndex\n\t\t}\n\t\tnewAtom.cleanup = () => {\n\t\t\tfor (const cleanup of cleanupFunctions) {\n\t\t\t\tcleanup()\n\t\t\t}\n\t\t}\n\t}\n\tstore.on.atomCreation.next(token)\n\treturn token\n}\n","import type { Atom } from \"../state-types\"\n\nexport const INTERNAL_ROLES = [`tracker:signal`] as const\nexport type InternalRole = (typeof INTERNAL_ROLES)[number]\n\nexport function hasRole(atom: Atom<any, any>, role: InternalRole): boolean {\n\tif (`internalRoles` in atom === false) {\n\t\treturn false\n\t}\n\n\treturn atom.internalRoles.includes(role)\n}\n"],"mappings":";;;;;AAMA,SAAgB,OACf,OACgC;AAChC,QAAO,MAAM,UAAU,KACtB,SAAQ,MAAM;AAEf,QAAO;;AAGR,SAAgB,OACf,OAC0C;AAC1C,QAAO,MAAM,WAAW,KACvB,SAAQ,MAAM;AAEf,QAAO;;;;;ACnBR,SAAgB,OACf,oBACA,eACI;AACJ,KAAI,KAAK,mBAAmB,CAC3B,QAAO,mBAAmB,cAAc;AAEzC,QAAO;;;;;;;;;;;;;;ACAR,IAAa,SAAb,cAA+B,QAAW;CACzC,AAAQ;CACR,AAAQ;CACR,AAAQ;CAER,AAAO,OAAO;CAEd,AAAO,YACN,UAGC;EACD,IAAIA;EACJ,IAAIC;AACJ,SAAO,SAAS,WAAW;AAC1B,kBAAe;AACf,iBAAc;IACb;AACF,OAAK,UAAU;AACf,OAAK,SAAS;AACd,OAAK,IAAI,oBAAoB,UAAU,WAAW,IAAI,QAAQ,SAAS,CAAC;;CAGzE,AAAQ,KAAK,SAAqB,OAAU;AAC3C,MAAI,YAAY,KAAK,MAAM;AAC1B,QAAK,QAAQ,MAAM;AACnB,QAAK,OAAO;;;CAGd,AAAQ,KAAK,SAAqB,QAAa;AAC9C,MAAI,YAAY,KAAK,MAAM;AAC1B,QAAK,OAAO,OAAO;AACnB,QAAK,OAAO;;;CAId,AAAO,IAAI,OAA6B;AACvC,MAAI,SAAS,MACZ;AAED,MAAI,iBAAiB,SAAS;GAC7B,MAAM,UAAU;AAChB,QAAK,OAAO;AACZ,WAAQ,MACN,aAAa;AACb,SAAK,KAAK,SAAS,SAAS;OAE5B,WAAW;AACX,SAAK,KAAK,SAAS,OAAO;KAE3B;SACK;AACN,QAAK,QAAQ,MAAM;AACnB,QAAK,OAAO;;;;;;;AC9Df,IAAa,UAAb,MAAwB;CACv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