atom.io 0.15.4 → 0.15.6

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 (108) hide show
  1. package/data/dist/index.cjs +20 -16
  2. package/data/dist/index.cjs.map +1 -1
  3. package/data/dist/index.js +21 -17
  4. package/data/dist/index.js.map +1 -1
  5. package/data/src/join.ts +6 -2
  6. package/dist/index.cjs +21 -6
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.ts +69 -18
  9. package/dist/index.js +157 -1
  10. package/dist/index.js.map +1 -1
  11. package/internal/dist/index.cjs +88 -146
  12. package/internal/dist/index.cjs.map +1 -1
  13. package/internal/dist/index.d.ts +29 -17
  14. package/internal/dist/index.js +79 -92
  15. package/internal/dist/index.js.map +1 -1
  16. package/internal/src/get-environment-data.ts +18 -0
  17. package/internal/src/index.ts +2 -0
  18. package/internal/src/ingest-updates/index.ts +3 -0
  19. package/internal/src/ingest-updates/ingest-atom-update.ts +14 -0
  20. package/internal/src/ingest-updates/ingest-selector-update.ts +17 -0
  21. package/internal/src/ingest-updates/ingest-transaction-update.ts +22 -0
  22. package/internal/src/mutable/tracker.ts +1 -1
  23. package/internal/src/not-found-error.ts +3 -8
  24. package/internal/src/operation.ts +3 -3
  25. package/internal/src/selector/create-read-write-selector.ts +5 -3
  26. package/internal/src/selector/create-readonly-selector.ts +2 -2
  27. package/internal/src/selector/register-selector.ts +6 -4
  28. package/internal/src/selector/update-selector-atoms.ts +2 -2
  29. package/internal/src/set-state/set-atom.ts +8 -3
  30. package/internal/src/store/deposit.ts +5 -5
  31. package/internal/src/store/withdraw-new-family-member.ts +8 -11
  32. package/internal/src/store/withdraw.ts +4 -3
  33. package/internal/src/subscribe/subscribe-to-state.ts +2 -2
  34. package/internal/src/timeline/time-travel.ts +18 -44
  35. package/internal/src/transaction/apply-transaction.ts +3 -49
  36. package/internal/src/transaction/build-transaction.ts +8 -1
  37. package/internal/src/transaction/create-transaction.ts +3 -3
  38. package/internal/src/transaction/index.ts +2 -2
  39. package/introspection/dist/index.cjs.map +1 -1
  40. package/introspection/dist/index.d.ts +4 -4
  41. package/introspection/dist/index.js.map +1 -1
  42. package/introspection/src/attach-atom-index.ts +2 -2
  43. package/introspection/src/attach-selector-index.ts +2 -2
  44. package/introspection/src/index.ts +1 -1
  45. package/package.json +8 -8
  46. package/react/dist/index.cjs.map +1 -1
  47. package/react/dist/index.d.ts +3 -3
  48. package/react/dist/index.js.map +1 -1
  49. package/react/src/store-hooks.ts +4 -4
  50. package/react-devtools/dist/index.cjs.map +1 -1
  51. package/react-devtools/dist/index.d.ts +3 -3
  52. package/react-devtools/dist/index.js.map +1 -1
  53. package/react-devtools/src/StateEditor.tsx +3 -3
  54. package/react-devtools/src/StateIndex.tsx +3 -3
  55. package/realtime-client/dist/index.cjs +67 -65
  56. package/realtime-client/dist/index.cjs.map +1 -1
  57. package/realtime-client/dist/index.d.ts +6 -5
  58. package/realtime-client/dist/index.js +62 -61
  59. package/realtime-client/dist/index.js.map +1 -1
  60. package/realtime-client/src/pull-family-member.ts +1 -1
  61. package/realtime-client/src/pull.ts +1 -1
  62. package/realtime-client/src/push.ts +2 -3
  63. package/realtime-client/src/realtime-state.ts +8 -0
  64. package/realtime-client/src/server-action.ts +65 -65
  65. package/realtime-react/dist/index.cjs +88 -52
  66. package/realtime-react/dist/index.cjs.map +1 -1
  67. package/realtime-react/dist/index.d.ts +11 -6
  68. package/realtime-react/dist/index.js +87 -51
  69. package/realtime-react/dist/index.js.map +1 -1
  70. package/realtime-react/src/on-mount.ts +23 -0
  71. package/realtime-react/src/realtime-context.tsx +12 -2
  72. package/realtime-react/src/use-pull-family-member.ts +5 -8
  73. package/realtime-react/src/use-pull-mutable-family-member.ts +4 -7
  74. package/realtime-react/src/use-pull-mutable.ts +4 -7
  75. package/realtime-react/src/use-pull.ts +5 -8
  76. package/realtime-react/src/use-push.ts +5 -9
  77. package/realtime-react/src/use-realtime-service.ts +30 -0
  78. package/realtime-react/src/use-server-action.ts +8 -8
  79. package/realtime-server/dist/index.cjs +109 -40
  80. package/realtime-server/dist/index.cjs.map +1 -1
  81. package/realtime-server/dist/index.d.ts +7 -6
  82. package/realtime-server/dist/index.js +90 -39
  83. package/realtime-server/dist/index.js.map +1 -1
  84. package/realtime-server/src/hook-composition/expose-family.ts +2 -2
  85. package/realtime-server/src/hook-composition/expose-mutable-family.ts +1 -1
  86. package/realtime-server/src/hook-composition/expose-single.ts +1 -1
  87. package/realtime-server/src/hook-composition/index.ts +2 -1
  88. package/realtime-server/src/hook-composition/receive-state.ts +2 -2
  89. package/realtime-server/src/hook-composition/receive-transaction.ts +13 -32
  90. package/realtime-server/src/hook-composition/sync-transaction.ts +92 -0
  91. package/realtime-testing/dist/index.cjs +3 -3
  92. package/realtime-testing/dist/index.cjs.map +1 -1
  93. package/realtime-testing/dist/index.js +2 -2
  94. package/realtime-testing/dist/index.js.map +1 -1
  95. package/realtime-testing/src/setup-realtime-test.tsx +4 -3
  96. package/src/atom.ts +30 -7
  97. package/src/dispose.ts +2 -2
  98. package/src/find-state.ts +64 -0
  99. package/src/get-state.ts +2 -2
  100. package/src/index.ts +15 -2
  101. package/src/logger.ts +1 -0
  102. package/src/selector.ts +16 -0
  103. package/src/set-state.ts +2 -2
  104. package/src/silo.ts +2 -2
  105. package/src/timeline.ts +2 -2
  106. package/src/transaction.ts +31 -12
  107. package/dist/chunk-RLZQ6IIY.js +0 -147
  108. package/dist/chunk-RLZQ6IIY.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/setup-realtime-test.tsx"],"names":["clients"],"mappings":";;;;;;;;;AAAA,YAAY,UAAU;AAEtB,SAA4B,WAAW,cAAc;AACrD,YAAY,YAAY;AACxB,YAAY,cAAc;AAC1B,YAAY,QAAQ;AACpB,YAAY,SAAS;AACrB,YAAY,WAAW;AAEvB,YAAY,cAAc;AAE1B,SAAS,UAAU;AAoFf;AAxCG,IAAM,0BAA0B,CACtC,YACwB;AACxB,QAAM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AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEO,IAAM,eAAe,CAC3B,YACmC;AACnC,QAAM,SAAS,wBAAwB,OAAO;AAC9C,QAAM,SAAS,wBAAwB,SAAS,UAAU,OAAO,IAAI;AAErE,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA,UAAU,MAAM;AACf,aAAO,QAAQ;AACf,aAAO,QAAQ;AAAA,IAChB;AAAA,EACD;AACD;AAEO,IAAM,cAAc,CAC1B,YAC+C;AAC/C,QAAM,SAAS,wBAAwB,OAAO;AAC9C,QAAM,UAAU,gBAAgB,QAAQ,OAAO,EAAE;AAAA,IAChD,CAACA,UAAS,CAAC,MAAM,MAAM,MAAM;AAC5B,MAAAA,SAAQ,IAAI,IAAI;AAAA,QACf,iCAAK,UAAL,EAAc,OAAO;AAAA,QACrB;AAAA,QACA,OAAO;AAAA,MACR;AACA,aAAOA;AAAA,IACR;AAAA,IACA,CAAC;AAAA,EACF;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA,UAAU,MAAM;AACf,iBAAW,CAAC,EAAE,MAAM,KAAK,gBAAgB,OAAO,GAAG;AAClD,eAAO,QAAQ;AAAA,MAChB;AACA,aAAO,QAAQ;AAAA,IAChB;AAAA,EACD;AACD","sourcesContent":["import * as http from \"http\"\n\nimport { type RenderResult, prettyDOM, render } from \"@testing-library/react\"\nimport * as AtomIO from \"atom.io\"\nimport * as Internal from \"atom.io/internal\"\nimport * as AR from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-react\"\nimport * as Happy from \"happy-dom\"\nimport * as React from \"react\"\nimport * as SocketIO from \"socket.io\"\nimport type { Socket as ClientSocket } from \"socket.io-client\"\nimport { io } from \"socket.io-client\"\n\nimport { recordToEntries } from \"~/packages/anvl/src/object\"\n\nexport type TestSetupOptions = {\n\tserver: (tools: { socket: SocketIO.Socket; silo: AtomIO.Silo }) => void\n}\nexport type TestSetupOptions__SingleClient = TestSetupOptions & {\n\tclient: React.FC\n}\nexport type TestSetupOptions__MultiClient<ClientNames extends string> =\n\tTestSetupOptions & {\n\t\tclients: {\n\t\t\t[K in ClientNames]: React.FC\n\t\t}\n\t}\n\nexport type RealtimeTestTools = {\n\tname: string\n\tsilo: AtomIO.Silo\n\tdispose: () => void\n}\nexport type RealtimeTestClient = RealtimeTestTools & {\n\trenderResult: RenderResult\n\tprettyPrint: () => void\n\treconnect: () => void\n\tdisconnect: () => void\n}\nexport type RealtimeTestServer = RealtimeTestTools & {\n\tport: number\n}\n\nexport type RealtimeTestAPI = {\n\tserver: RealtimeTestServer\n\tteardown: () => void\n}\nexport type RealtimeTestAPI__SingleClient = RealtimeTestAPI & {\n\tclient: RealtimeTestClient\n}\nexport type RealtimeTestAPI__MultiClient<ClientNames extends string> =\n\tRealtimeTestAPI & {\n\t\tclients: Record<ClientNames, RealtimeTestClient>\n\t}\n\nexport const setupRealtimeTestServer = (\n\toptions: TestSetupOptions,\n): RealtimeTestServer => {\n\tconst httpServer = http.createServer((_, res) => res.end(`Hello World!`))\n\tconst address = httpServer.listen().address()\n\tconst port =\n\t\ttypeof address === `string` ? 80 : address === null ? null : address.port\n\tif (port === null) throw new Error(`Could not determine port for test server`)\n\tconst server = new SocketIO.Server(httpServer)\n\tconst silo = new AtomIO.Silo(`SERVER`, Internal.IMPLICIT.STORE)\n\n\tserver.on(`connection`, (socket: SocketIO.Socket) => {\n\t\toptions.server({ socket, silo })\n\t})\n\n\tconst dispose = () => {\n\t\tserver.close()\n\t\tInternal.clearStore(silo.store)\n\t}\n\n\treturn {\n\t\tname: `SERVER`,\n\t\tsilo,\n\t\tdispose,\n\t\tport,\n\t}\n}\nexport const setupRealtimeTestClient = (\n\toptions: TestSetupOptions__SingleClient,\n\tname: string,\n\tport: number,\n): RealtimeTestClient => {\n\tconst socket: ClientSocket = io(`http://localhost:${port}/`)\n\tconst silo = new AtomIO.Silo(name, Internal.IMPLICIT.STORE)\n\n\tconst { document } = new Happy.Window()\n\tdocument.body.innerHTML = `<div id=\"app\"></div>`\n\tconst renderResult = render(\n\t\t<AR.StoreProvider store={silo.store}>\n\t\t\t<RTC.RealtimeProvider socket={socket}>\n\t\t\t\t<options.client />\n\t\t\t</RTC.RealtimeProvider>\n\t\t</AR.StoreProvider>,\n\t\t{\n\t\t\tcontainer: document.querySelector(`#app`) as unknown as HTMLElement,\n\t\t},\n\t)\n\n\tconst prettyPrint = () => console.log(prettyDOM(renderResult.container))\n\n\tconst disconnect = () => socket.disconnect()\n\tconst reconnect = () => socket.connect()\n\n\tconst dispose = () => {\n\t\tsocket.disconnect()\n\t\tInternal.clearStore(silo.store)\n\t}\n\n\treturn {\n\t\tname,\n\t\tsilo,\n\t\trenderResult,\n\t\tprettyPrint,\n\t\tdisconnect,\n\t\treconnect,\n\t\tdispose,\n\t}\n}\n\nexport const singleClient = (\n\toptions: TestSetupOptions__SingleClient,\n): RealtimeTestAPI__SingleClient => {\n\tconst server = setupRealtimeTestServer(options)\n\tconst client = setupRealtimeTestClient(options, `CLIENT`, server.port)\n\n\treturn {\n\t\tclient,\n\t\tserver,\n\t\tteardown: () => {\n\t\t\tclient.dispose()\n\t\t\tserver.dispose()\n\t\t},\n\t}\n}\n\nexport const multiClient = <ClientNames extends string>(\n\toptions: TestSetupOptions__MultiClient<ClientNames>,\n): RealtimeTestAPI__MultiClient<ClientNames> => {\n\tconst server = setupRealtimeTestServer(options)\n\tconst clients = recordToEntries(options.clients).reduce(\n\t\t(clients, [name, client]) => {\n\t\t\tclients[name] = setupRealtimeTestClient(\n\t\t\t\t{ ...options, client },\n\t\t\t\tname,\n\t\t\t\tserver.port,\n\t\t\t)\n\t\t\treturn clients\n\t\t},\n\t\t{} as Record<ClientNames, RealtimeTestClient>,\n\t)\n\n\treturn {\n\t\tclients,\n\t\tserver,\n\t\tteardown: () => {\n\t\t\tfor (const [, client] of recordToEntries(clients)) {\n\t\t\t\tclient.dispose()\n\t\t\t}\n\t\t\tserver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B,GACD;AAAA,IACA;AAAA,MACC,WAAW,SAAS,cAAc,MAAM;AAAA,IACzC;AAAA,EACD;AAEA,QAAM,cAAc,MAAM,QAAQ,IAAI,UAAU,aAAa,SAAS,CAAC;AAEvE,QAAM,aAAa,MAAM,OAAO,WAAW;AAC3C,QAAM,YAAY,MAAM,OAAO,QAAQ;AAEvC,QAAM,UAAU,MAAM;AACrB,WAAO,WAAW;AAClB,IAAS,oBAAW,KAAK,KAAK;AAAA,EAC/B;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;AAEO,IAAM,eAAe,CAC3B,YACmC;AACnC,QAAM,SAAS,wBAAwB,OAAO;AAC9C,QAAM,SAAS,wBAAwB,SAAS,UAAU,OAAO,IAAI;AAErE,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA,UAAU,MAAM;AACf,aAAO,QAAQ;AACf,aAAO,QAAQ;AAAA,IAChB;AAAA,EACD;AACD;AAEO,IAAM,cAAc,CAC1B,YAC+C;AAC/C,QAAM,SAAS,wBAAwB,OAAO;AAC9C,QAAM,UAAU,gBAAgB,QAAQ,OAAO,EAAE;AAAA,IAChD,CAACA,UAAS,CAAC,MAAM,MAAM,MAAM;AAC5B,MAAAA,SAAQ,IAAI,IAAI;AAAA,QACf,iCAAK,UAAL,EAAc,OAAO;AAAA,QACrB;AAAA,QACA,OAAO;AAAA,MACR;AACA,aAAOA;AAAA,IACR;AAAA,IACA,CAAC;AAAA,EACF;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA,UAAU,MAAM;AACf,iBAAW,CAAC,EAAE,MAAM,KAAK,gBAAgB,OAAO,GAAG;AAClD,eAAO,QAAQ;AAAA,MAChB;AACA,aAAO,QAAQ;AAAA,IAChB;AAAA,EACD;AACD","sourcesContent":["import * as http from \"http\"\n\nimport { type RenderResult, prettyDOM, render } from \"@testing-library/react\"\nimport * as AtomIO from \"atom.io\"\nimport * as Internal from \"atom.io/internal\"\nimport * as AR from \"atom.io/react\"\nimport * as RTR from \"atom.io/realtime-react\"\nimport * as Happy from \"happy-dom\"\nimport * as React from \"react\"\nimport * as SocketIO from \"socket.io\"\nimport type { Socket as ClientSocket } from \"socket.io-client\"\nimport { io } from \"socket.io-client\"\n\nimport { recordToEntries } from \"~/packages/anvl/src/object\"\n\nexport type TestSetupOptions = {\n\tserver: (tools: { socket: SocketIO.Socket; silo: AtomIO.Silo }) => void\n}\nexport type TestSetupOptions__SingleClient = TestSetupOptions & {\n\tclient: React.FC\n}\nexport type TestSetupOptions__MultiClient<ClientNames extends string> =\n\tTestSetupOptions & {\n\t\tclients: {\n\t\t\t[K in ClientNames]: React.FC\n\t\t}\n\t}\n\nexport type RealtimeTestTools = {\n\tname: string\n\tsilo: AtomIO.Silo\n\tdispose: () => void\n}\nexport type RealtimeTestClient = RealtimeTestTools & {\n\trenderResult: RenderResult\n\tprettyPrint: () => void\n\treconnect: () => void\n\tdisconnect: () => void\n}\nexport type RealtimeTestServer = RealtimeTestTools & {\n\tport: number\n}\n\nexport type RealtimeTestAPI = {\n\tserver: RealtimeTestServer\n\tteardown: () => void\n}\nexport type RealtimeTestAPI__SingleClient = RealtimeTestAPI & {\n\tclient: RealtimeTestClient\n}\nexport type RealtimeTestAPI__MultiClient<ClientNames extends string> =\n\tRealtimeTestAPI & {\n\t\tclients: Record<ClientNames, RealtimeTestClient>\n\t}\n\nexport const setupRealtimeTestServer = (\n\toptions: TestSetupOptions,\n): RealtimeTestServer => {\n\tconst httpServer = http.createServer((_, res) => res.end(`Hello World!`))\n\tconst address = httpServer.listen().address()\n\tconst port =\n\t\ttypeof address === `string` ? 80 : address === null ? null : address.port\n\tif (port === null) throw new Error(`Could not determine port for test server`)\n\tconst server = new SocketIO.Server(httpServer)\n\n\tconst silo = new AtomIO.Silo(`SERVER`, Internal.IMPLICIT.STORE)\n\n\tserver.on(`connection`, (socket: SocketIO.Socket) => {\n\t\toptions.server({ socket, silo })\n\t})\n\n\tconst dispose = () => {\n\t\tserver.close()\n\t\tInternal.clearStore(silo.store)\n\t}\n\n\treturn {\n\t\tname: `SERVER`,\n\t\tsilo,\n\t\tdispose,\n\t\tport,\n\t}\n}\nexport const setupRealtimeTestClient = (\n\toptions: TestSetupOptions__SingleClient,\n\tname: string,\n\tport: number,\n): RealtimeTestClient => {\n\tconst socket: ClientSocket = io(`http://localhost:${port}/`)\n\tconst silo = new AtomIO.Silo(name, Internal.IMPLICIT.STORE)\n\n\tconst { document } = new Happy.Window()\n\tdocument.body.innerHTML = `<div id=\"app\"></div>`\n\tconst renderResult = render(\n\t\t<AR.StoreProvider store={silo.store}>\n\t\t\t<RTR.RealtimeProvider socket={socket}>\n\t\t\t\t<options.client />\n\t\t\t</RTR.RealtimeProvider>\n\t\t</AR.StoreProvider>,\n\t\t{\n\t\t\tcontainer: document.querySelector(`#app`) as unknown as HTMLElement,\n\t\t},\n\t)\n\n\tconst prettyPrint = () => console.log(prettyDOM(renderResult.container))\n\n\tconst disconnect = () => socket.disconnect()\n\tconst reconnect = () => socket.connect()\n\n\tconst dispose = () => {\n\t\tsocket.disconnect()\n\t\tInternal.clearStore(silo.store)\n\t}\n\n\treturn {\n\t\tname,\n\t\tsilo,\n\t\trenderResult,\n\t\tprettyPrint,\n\t\tdisconnect,\n\t\treconnect,\n\t\tdispose,\n\t}\n}\n\nexport const singleClient = (\n\toptions: TestSetupOptions__SingleClient,\n): RealtimeTestAPI__SingleClient => {\n\tconst server = setupRealtimeTestServer(options)\n\tconst client = setupRealtimeTestClient(options, `CLIENT`, server.port)\n\n\treturn {\n\t\tclient,\n\t\tserver,\n\t\tteardown: () => {\n\t\t\tclient.dispose()\n\t\t\tserver.dispose()\n\t\t},\n\t}\n}\n\nexport const multiClient = <ClientNames extends string>(\n\toptions: TestSetupOptions__MultiClient<ClientNames>,\n): RealtimeTestAPI__MultiClient<ClientNames> => {\n\tconst server = setupRealtimeTestServer(options)\n\tconst clients = recordToEntries(options.clients).reduce(\n\t\t(clients, [name, client]) => {\n\t\t\tclients[name] = setupRealtimeTestClient(\n\t\t\t\t{ ...options, client },\n\t\t\t\tname,\n\t\t\t\tserver.port,\n\t\t\t)\n\t\t\treturn clients\n\t\t},\n\t\t{} as Record<ClientNames, RealtimeTestClient>,\n\t)\n\n\treturn {\n\t\tclients,\n\t\tserver,\n\t\tteardown: () => {\n\t\t\tfor (const [, client] of recordToEntries(clients)) {\n\t\t\t\tclient.dispose()\n\t\t\t}\n\t\t\tserver.dispose()\n\t\t},\n\t}\n}\n"]}
@@ -4,7 +4,7 @@ import { type RenderResult, prettyDOM, render } from "@testing-library/react"
4
4
  import * as AtomIO from "atom.io"
5
5
  import * as Internal from "atom.io/internal"
6
6
  import * as AR from "atom.io/react"
7
- import * as RTC from "atom.io/realtime-react"
7
+ import * as RTR from "atom.io/realtime-react"
8
8
  import * as Happy from "happy-dom"
9
9
  import * as React from "react"
10
10
  import * as SocketIO from "socket.io"
@@ -62,6 +62,7 @@ export const setupRealtimeTestServer = (
62
62
  typeof address === `string` ? 80 : address === null ? null : address.port
63
63
  if (port === null) throw new Error(`Could not determine port for test server`)
64
64
  const server = new SocketIO.Server(httpServer)
65
+
65
66
  const silo = new AtomIO.Silo(`SERVER`, Internal.IMPLICIT.STORE)
66
67
 
67
68
  server.on(`connection`, (socket: SocketIO.Socket) => {
@@ -92,9 +93,9 @@ export const setupRealtimeTestClient = (
92
93
  document.body.innerHTML = `<div id="app"></div>`
93
94
  const renderResult = render(
94
95
  <AR.StoreProvider store={silo.store}>
95
- <RTC.RealtimeProvider socket={socket}>
96
+ <RTR.RealtimeProvider socket={socket}>
96
97
  <options.client />
97
- </RTC.RealtimeProvider>
98
+ </RTR.RealtimeProvider>
98
99
  </AR.StoreProvider>,
99
100
  {
100
101
  container: document.querySelector(`#app`) as unknown as HTMLElement,
package/src/atom.ts CHANGED
@@ -49,6 +49,14 @@ export type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((
49
49
  subject: Subject<AtomToken<T>>
50
50
  mutable?: boolean
51
51
  install: (store: Store) => void
52
+ __T?: T
53
+ __K?: K
54
+ }
55
+ export type AtomFamilyToken<T, K extends Json.Serializable> = {
56
+ key: string
57
+ type: `atom_family`
58
+ __T?: T
59
+ __K?: K
52
60
  }
53
61
 
54
62
  // biome-ignore format: intersection
@@ -63,19 +71,34 @@ export type MutableAtomFamilyOptions<
63
71
 
64
72
  // biome-ignore format: intersection
65
73
  export type MutableAtomFamily<
66
- Core extends Transceiver<any>,
67
- SerializableCore extends Json.Serializable,
68
- Key extends Json.Serializable,
74
+ T extends Transceiver<any>,
75
+ J extends Json.Serializable,
76
+ K extends Json.Serializable,
69
77
  > =
70
- & JsonInterface<Core, SerializableCore>
71
- & ((key: Key) => MutableAtomToken<Core, SerializableCore>)
78
+ & JsonInterface<T, J>
79
+ & ((key: K) => MutableAtomToken<T, J>)
72
80
  & {
73
- key: `${string}`
81
+ key: string
74
82
  type: `atom_family`
75
- subject: Subject<MutableAtomToken<Core, SerializableCore>>
83
+ subject: Subject<MutableAtomToken<T, J>>
76
84
  mutable: true
77
85
  install: (store: Store) => void
86
+ __T?: T
87
+ __J?: J
88
+ __K?: K
78
89
  }
90
+ export type MutableAtomFamilyToken<
91
+ T extends Transceiver<any>,
92
+ J extends Json.Serializable,
93
+ K extends Json.Serializable,
94
+ > = {
95
+ key: string
96
+ type: `atom_family`
97
+ mutable: true
98
+ __T?: T
99
+ __J?: J
100
+ __K?: K
101
+ }
79
102
 
80
103
  export function atomFamily<
81
104
  T extends Transceiver<any>,
package/src/dispose.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as Internal from "atom.io/internal"
2
2
 
3
- import type { ReadonlySelectorToken, StateToken } from "."
3
+ import type { ReadableToken } from "."
4
4
 
5
5
  export function dispose(
6
- token: ReadonlySelectorToken<any> | StateToken<any>,
6
+ token: ReadableToken<any>,
7
7
  store: Internal.Store = Internal.IMPLICIT.STORE,
8
8
  ): void {
9
9
  switch (token.type) {
@@ -0,0 +1,64 @@
1
+ import type {
2
+ AtomFamilyToken,
3
+ AtomToken,
4
+ MutableAtomFamilyToken,
5
+ MutableAtomToken,
6
+ ReadableFamilyToken,
7
+ ReadableToken,
8
+ ReadonlySelectorFamilyToken,
9
+ ReadonlySelectorToken,
10
+ SelectorFamilyToken,
11
+ SelectorToken,
12
+ WritableFamilyToken,
13
+ WritableToken,
14
+ } from "atom.io"
15
+ import type { Store, Transceiver } from "atom.io/internal"
16
+ import { IMPLICIT } from "atom.io/internal"
17
+ import type { Json } from "atom.io/json"
18
+
19
+ export function findInStore(
20
+ token: ReadableFamilyToken<any, any>,
21
+ key: Json.Serializable,
22
+ store: Store,
23
+ ): ReadableToken<any> {
24
+ const familyKey = token.key
25
+ const family = store.families.get(familyKey)
26
+ if (family === undefined) {
27
+ throw new Error(`Family ${familyKey} not found`)
28
+ }
29
+ const state = family(key)
30
+ return state
31
+ }
32
+
33
+ export function findState<
34
+ T extends Transceiver<any>,
35
+ J extends Json.Serializable,
36
+ K extends Json.Serializable,
37
+ >(token: MutableAtomFamilyToken<T, J, K>, key: K): MutableAtomToken<T, J>
38
+ export function findState<T, K extends Json.Serializable>(
39
+ token: AtomFamilyToken<T, K>,
40
+ key: K,
41
+ ): AtomToken<T>
42
+ export function findState<T, K extends Json.Serializable>(
43
+ token: SelectorFamilyToken<T, K>,
44
+ key: K,
45
+ ): SelectorToken<T>
46
+ export function findState<T, K extends Json.Serializable>(
47
+ token: ReadonlySelectorFamilyToken<T, K>,
48
+ key: K,
49
+ ): ReadonlySelectorToken<T>
50
+ export function findState<T, K extends Json.Serializable>(
51
+ token: WritableFamilyToken<T, K>,
52
+ key: K,
53
+ ): WritableToken<T>
54
+ export function findState<T, K extends Json.Serializable>(
55
+ token: ReadableFamilyToken<T, K>,
56
+ key: K,
57
+ ): ReadableToken<T>
58
+ export function findState(
59
+ token: ReadableFamilyToken<any, any>,
60
+ key: Json.Serializable,
61
+ ): ReadableToken<any> {
62
+ const state = findInStore(token, key, IMPLICIT.STORE)
63
+ return state
64
+ }
package/src/get-state.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as Internal from "atom.io/internal"
2
2
 
3
- import type { ReadonlySelectorToken, StateToken } from "."
3
+ import type { ReadableToken } from "."
4
4
 
5
5
  export function getState<T>(
6
- token: ReadonlySelectorToken<T> | StateToken<T>,
6
+ token: ReadableToken<T>,
7
7
  store: Internal.Store = Internal.IMPLICIT.STORE,
8
8
  ): T {
9
9
  const state =
package/src/index.ts CHANGED
@@ -1,10 +1,16 @@
1
1
  import type { Transceiver } from "atom.io/internal"
2
2
  import type { Json } from "atom.io/json"
3
- import type { AtomFamily } from "./atom"
4
- import type { ReadonlySelectorFamily, SelectorFamily } from "./selector"
3
+ import type { AtomFamily, AtomFamilyToken } from "./atom"
4
+ import type {
5
+ ReadonlySelectorFamily,
6
+ ReadonlySelectorFamilyToken,
7
+ SelectorFamily,
8
+ SelectorFamilyToken,
9
+ } from "./selector"
5
10
 
6
11
  export * from "./atom"
7
12
  export * from "./dispose"
13
+ export * from "./find-state"
8
14
  export * from "./get-state"
9
15
  export * from "./logger"
10
16
  export * from "./selector"
@@ -50,6 +56,13 @@ export type ReadableFamily<T, K extends Json.Serializable> =
50
56
  | ReadonlySelectorFamily<T, K>
51
57
  | WritableFamily<T, K>
52
58
 
59
+ export type WritableFamilyToken<T, K extends Json.Serializable> =
60
+ | AtomFamilyToken<T, K>
61
+ | SelectorFamilyToken<T, K>
62
+ export type ReadableFamilyToken<T, K extends Json.Serializable> =
63
+ | ReadonlySelectorFamilyToken<T, K>
64
+ | WritableFamilyToken<T, K>
65
+
53
66
  export type ReadonlySelectorToken<_> = {
54
67
  key: string
55
68
  type: `readonly_selector`
package/src/logger.ts CHANGED
@@ -36,6 +36,7 @@ const LoggerIconDictionary = {
36
36
  "🧮": `Computing selector`,
37
37
  "🧹": `Prepare to evict`,
38
38
  "🪂": `Abort transaction`,
39
+ "🚀": `Performance measure`,
39
40
  } as const
40
41
  export type LoggerIcon = keyof typeof LoggerIconDictionary
41
42
 
package/src/selector.ts CHANGED
@@ -43,6 +43,14 @@ export type SelectorFamily<
43
43
  type: `selector_family`
44
44
  subject: Subject<SelectorToken<T>>
45
45
  install: (store: Store) => void
46
+ __T?: T
47
+ __K?: K
48
+ }
49
+ export type SelectorFamilyToken<T, K extends Json.Serializable> = {
50
+ key: string
51
+ type: `selector_family`
52
+ __T?: T
53
+ __K?: K
46
54
  }
47
55
 
48
56
  export type ReadonlySelectorFamily<
@@ -53,6 +61,14 @@ export type ReadonlySelectorFamily<
53
61
  type: `readonly_selector_family`
54
62
  subject: Subject<ReadonlySelectorToken<T>>
55
63
  install: (store: Store) => void
64
+ __T?: T
65
+ __K?: K
66
+ }
67
+ export type ReadonlySelectorFamilyToken<T, K extends Json.Serializable> = {
68
+ key: string
69
+ type: `readonly_selector_family`
70
+ __T?: T
71
+ __K?: K
56
72
  }
57
73
 
58
74
  export function selectorFamily<T, K extends Json.Serializable>(
package/src/set-state.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import * as Internal from "atom.io/internal"
2
2
 
3
- import type { StateToken } from "."
3
+ import type { WritableToken } from "."
4
4
 
5
5
  export function setState<T, New extends T>(
6
- token: StateToken<T>,
6
+ token: WritableToken<T>,
7
7
  value: New | ((oldValue: T) => New),
8
8
  store: Internal.Store = Internal.IMPLICIT.STORE,
9
9
  ): void {
package/src/silo.ts CHANGED
@@ -40,7 +40,7 @@ export class Silo {
40
40
  this.getState = (token) => getState(token, s)
41
41
  this.setState = (token, newValue) => setState(token, newValue, s)
42
42
  this.subscribe = (token, handler, key) => subscribe(token, handler, key, s)
43
- this.undo = (token) => timeTravel(`backward`, token, s)
44
- this.redo = (token) => timeTravel(`forward`, token, s)
43
+ this.undo = (token) => timeTravel(`undo`, token, s)
44
+ this.redo = (token) => timeTravel(`redo`, token, s)
45
45
  }
46
46
  }
package/src/timeline.ts CHANGED
@@ -37,9 +37,9 @@ export const timeline = <ManagedAtom extends TimelineManageable>(
37
37
  }
38
38
 
39
39
  export const redo = (timeline: TimelineToken<any>): void => {
40
- timeTravel(`forward`, timeline, IMPLICIT.STORE)
40
+ timeTravel(`redo`, timeline, IMPLICIT.STORE)
41
41
  }
42
42
 
43
43
  export const undo = (timeline: TimelineToken<any>): void => {
44
- timeTravel(`backward`, timeline, IMPLICIT.STORE)
44
+ timeTravel(`undo`, timeline, IMPLICIT.STORE)
45
45
  }
@@ -1,7 +1,14 @@
1
- import type { Store } from "atom.io/internal"
1
+ import type { EnvironmentData, Store } from "atom.io/internal"
2
2
  import { IMPLICIT, createTransaction, withdraw } from "atom.io/internal"
3
+ import type { Json } from "atom.io/json"
3
4
 
4
- import type { KeyedStateUpdate, ReadonlySelectorToken, StateToken, ƒn } from "."
5
+ import type {
6
+ KeyedStateUpdate,
7
+ ReadonlySelectorToken,
8
+ WritableToken,
9
+ findState,
10
+ ƒn,
11
+ } from "."
5
12
 
6
13
  export type TransactionToken<_> = {
7
14
  key: string
@@ -9,29 +16,37 @@ export type TransactionToken<_> = {
9
16
  __brand?: _
10
17
  }
11
18
 
19
+ export type TransactionUpdateContent =
20
+ | KeyedStateUpdate<unknown>
21
+ | TransactionUpdate<ƒn>
22
+
12
23
  export type TransactionUpdate<ƒ extends ƒn> = {
13
24
  key: string
14
- updates: (KeyedStateUpdate<unknown> | TransactionUpdate<ƒn>)[]
25
+ id: string
26
+ updates: TransactionUpdateContent[]
15
27
  params: Parameters<ƒ>
16
28
  output: ReturnType<ƒ>
17
29
  }
18
30
 
19
31
  export type Transactors = Readonly<{
20
- get: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S
32
+ get: <S>(state: ReadonlySelectorToken<S> | WritableToken<S>) => S
21
33
  set: <S, New extends S>(
22
- state: StateToken<S>,
34
+ state: WritableToken<S>,
23
35
  newValue: New | ((oldValue: S) => New),
24
36
  ) => void
37
+ find: typeof findState
25
38
  }>
26
- export type TransactorsWithRun = Readonly<{
27
- get: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S
39
+ export type TransactorsWithRunAndEnv = Readonly<{
40
+ get: <S>(state: ReadonlySelectorToken<S> | WritableToken<S>) => S
28
41
  set: <S, New extends S>(
29
- state: StateToken<S>,
42
+ state: WritableToken<S>,
30
43
  newValue: New | ((oldValue: S) => New),
31
44
  ) => void
45
+ find: typeof findState
32
46
  run: typeof runTransaction
47
+ env: () => EnvironmentData
33
48
  }>
34
- export type ReadonlyTransactors = Pick<Transactors, `get`>
49
+ export type ReadonlyTransactors = Pick<Transactors, `find` | `get`>
35
50
 
36
51
  export type Read<ƒ extends ƒn> = (
37
52
  transactors: ReadonlyTransactors,
@@ -44,7 +59,7 @@ export type Write<ƒ extends ƒn> = (
44
59
  ) => ReturnType<ƒ>
45
60
 
46
61
  export type Transact<ƒ extends ƒn> = (
47
- transactors: TransactorsWithRun,
62
+ transactors: TransactorsWithRunAndEnv,
48
63
  ...parameters: Parameters<ƒ>
49
64
  ) => ReturnType<ƒ>
50
65
 
@@ -63,11 +78,15 @@ export function transaction<ƒ extends ƒn>(
63
78
  }
64
79
 
65
80
  export const runTransaction =
66
- <ƒ extends ƒn>(token: TransactionToken<ƒ>, store: Store = IMPLICIT.STORE) =>
81
+ <ƒ extends ƒn>(
82
+ token: TransactionToken<ƒ>,
83
+ store: Store = IMPLICIT.STORE,
84
+ id?: string,
85
+ ) =>
67
86
  (...parameters: Parameters<ƒ>): ReturnType<ƒ> => {
68
87
  const tx = withdraw(token, store)
69
88
  if (tx) {
70
- return tx.run(...parameters)
89
+ return tx.run(parameters, id)
71
90
  }
72
91
  throw new Error(
73
92
  `Cannot run transaction "${token.key}": transaction not found in store "${store.config.name}".`,
@@ -1,147 +0,0 @@
1
- import * as Internal3 from 'atom.io/internal';
2
- import { createAtom, IMPLICIT, createAtomFamily, createSelector, createSelectorFamily, Store, createTransaction, createTimeline, timeTravel, subscribeToTimeline, subscribeToTransaction, subscribeToState, withdraw } from 'atom.io/internal';
3
-
4
- // src/atom.ts
5
- function atom(options) {
6
- return createAtom(options, void 0, IMPLICIT.STORE);
7
- }
8
- function atomFamily(options) {
9
- return createAtomFamily(options, IMPLICIT.STORE);
10
- }
11
- function dispose(token, store = Internal3.IMPLICIT.STORE) {
12
- switch (token.type) {
13
- case `atom`:
14
- Internal3.deleteAtom(token, store);
15
- break;
16
- case `selector`:
17
- case `readonly_selector`:
18
- Internal3.deleteSelector(token, store);
19
- break;
20
- }
21
- }
22
- function getState(token, store = Internal3.IMPLICIT.STORE) {
23
- var _a;
24
- const state = (_a = Internal3.withdraw(token, store)) != null ? _a : Internal3.withdrawNewFamilyMember(token, store);
25
- if (state === void 0) {
26
- throw new Internal3.NotFoundError(token, store);
27
- }
28
- return Internal3.readOrComputeValue(state, store);
29
- }
30
-
31
- // src/logger.ts
32
- var LOG_LEVELS = [`info`, `warn`, `error`];
33
- var simpleLog = (logLevel) => (icon, tokenType, tokenKey, message, ...rest) => {
34
- console[logLevel](`${icon} ${tokenType} "${tokenKey}" ${message}`, ...rest);
35
- };
36
- var simpleLogger = {
37
- error: simpleLog(`error`),
38
- info: simpleLog(`info`),
39
- warn: simpleLog(`warn`)
40
- };
41
- var AtomIOLogger = class {
42
- constructor(logLevel, filter, logger = simpleLogger) {
43
- this.logLevel = logLevel;
44
- this.filter = filter;
45
- this.logger = logger;
46
- this.error = (...args) => {
47
- var _a, _b;
48
- if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel !== null) {
49
- this.logger.error(...args);
50
- }
51
- };
52
- this.info = (...args) => {
53
- var _a, _b;
54
- if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel === `info`) {
55
- this.logger.info(...args);
56
- }
57
- };
58
- this.warn = (...args) => {
59
- var _a, _b;
60
- if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel !== `error` && this.logLevel !== null) {
61
- this.logger.warn(...args);
62
- }
63
- };
64
- }
65
- };
66
- function selector(options) {
67
- return createSelector(options, void 0, IMPLICIT.STORE);
68
- }
69
- function selectorFamily(options) {
70
- return createSelectorFamily(options, IMPLICIT.STORE);
71
- }
72
- function setState(token, value, store = Internal3.IMPLICIT.STORE) {
73
- var _a;
74
- const rejection = Internal3.openOperation(token, store);
75
- if (rejection) {
76
- return;
77
- }
78
- const state = (_a = Internal3.withdraw(token, store)) != null ? _a : Internal3.withdrawNewFamilyMember(token, store);
79
- if (state === void 0) {
80
- throw new Internal3.NotFoundError(token, store);
81
- }
82
- Internal3.setAtomOrSelector(state, value, store);
83
- Internal3.closeOperation(store);
84
- }
85
- var Silo = class {
86
- constructor(name, fromStore = null) {
87
- const s = new Store(name, fromStore);
88
- this.store = s;
89
- this.atom = (options) => createAtom(options, void 0, s);
90
- this.atomFamily = (options) => createAtomFamily(options, s);
91
- this.selector = (options) => createSelector(options, void 0, s);
92
- this.selectorFamily = (options) => createSelectorFamily(options, s);
93
- this.transaction = (options) => createTransaction(options, s);
94
- this.timeline = (options) => createTimeline(options, s);
95
- this.getState = (token) => getState(token, s);
96
- this.setState = (token, newValue) => setState(token, newValue, s);
97
- this.subscribe = (token, handler, key) => subscribe(token, handler, key, s);
98
- this.undo = (token) => timeTravel(`backward`, token, s);
99
- this.redo = (token) => timeTravel(`forward`, token, s);
100
- }
101
- };
102
- function subscribe(token, handleUpdate, key = Math.random().toString(36).slice(2), store = IMPLICIT.STORE) {
103
- switch (token.type) {
104
- case `atom`:
105
- case `readonly_selector`:
106
- case `selector`:
107
- return subscribeToState(token, handleUpdate, key, store);
108
- case `transaction`:
109
- return subscribeToTransaction(token, handleUpdate, key, store);
110
- case `timeline`:
111
- return subscribeToTimeline(token, handleUpdate, key, store);
112
- }
113
- }
114
- var timeline = (options) => {
115
- return createTimeline(options, IMPLICIT.STORE);
116
- };
117
- var redo = (timeline2) => {
118
- timeTravel(`forward`, timeline2, IMPLICIT.STORE);
119
- };
120
- var undo = (timeline2) => {
121
- timeTravel(`backward`, timeline2, IMPLICIT.STORE);
122
- };
123
- function transaction(options) {
124
- return createTransaction(options, IMPLICIT.STORE);
125
- }
126
- var runTransaction = (token, store = IMPLICIT.STORE) => (...parameters) => {
127
- const tx = withdraw(token, store);
128
- if (tx) {
129
- return tx.run(...parameters);
130
- }
131
- throw new Error(
132
- `Cannot run transaction "${token.key}": transaction not found in store "${store.config.name}".`
133
- );
134
- };
135
-
136
- // src/validators.ts
137
- function isToken(knownToken, unknownToken) {
138
- return knownToken.key === unknownToken.key;
139
- }
140
- function belongsTo(family, unknownToken) {
141
- var _a;
142
- return family.key === ((_a = unknownToken.family) == null ? void 0 : _a.key);
143
- }
144
-
145
- export { AtomIOLogger, LOG_LEVELS, Silo, atom, atomFamily, belongsTo, dispose, getState, isToken, redo, runTransaction, selector, selectorFamily, setState, simpleLog, simpleLogger, subscribe, timeline, transaction, undo };
146
- //# sourceMappingURL=out.js.map
147
- //# sourceMappingURL=chunk-RLZQ6IIY.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/atom.ts","../src/dispose.ts","../src/get-state.ts","../src/logger.ts","../src/selector.ts","../src/set-state.ts","../src/silo.ts","../src/subscribe.ts","../src/timeline.ts","../src/transaction.ts","../src/validators.ts"],"names":["Internal","IMPLICIT","createAtom","createAtomFamily","createSelector","createSelectorFamily","createTimeline","timeTravel","timeline","createTransaction","withdraw"],"mappings":";AACA,SAAS,UAAU,YAAY,wBAAwB;AA8BhD,SAAS,KACf,SACiB;AACjB,SAAO,WAAW,SAAS,QAAW,SAAS,KAAK;AACrD;AAoDO,SAAS,WACf,SACsD;AACtD,SAAO,iBAAiB,SAAS,SAAS,KAAK;AAChD;;;AC3FA,YAAY,cAAc;AAInB,SAAS,QACf,OACA,QAAiC,kBAAS,OACnC;AACP,UAAQ,MAAM,MAAM;AAAA,IACnB,KAAK;AACJ,MAAS,oBAAW,OAAO,KAAK;AAChC;AAAA,IACD,KAAK;AAAA,IACL,KAAK;AACJ,MAAS,wBAAe,OAAO,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K;AAChC,MAAI,IAAI;AACP,WAAO,GAAG,IAAI,GAAG,UAAU;AAAA,EAC5B;AACA,QAAM,IAAI;AAAA,IACT,2BAA2B,MAAM,GAAG,sCAAsC,MAAM,OAAO,IAAI;AAAA,EAC5F;AACD;;;ACjCM,SAAS,QACf,YACA,cACuD;AACvD,SAAO,WAAW,QAAQ,aAAa;AACxC;AAsBO,SAAS,UACf,QACA,cACmD;AAvEpD;AAwEC,SAAO,OAAO,UAAQ,kBAAa,WAAb,mBAAqB;AAC5C","sourcesContent":["import type { Store, Subject, Transceiver } from \"atom.io/internal\"\nimport { IMPLICIT, createAtom, createAtomFamily } from \"atom.io/internal\"\nimport type { Json, JsonInterface } from \"atom.io/json\"\n\nimport type { AtomToken, MutableAtomToken } from \".\"\n\nexport type Effectors<T> = {\n\tsetSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void\n\tonSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void\n}\n\nexport type AtomEffect<T> = (tools: Effectors<T>) => (() => void) | void\n\nexport type AtomOptions<T> = {\n\tkey: string\n\tdefault: T | (() => T)\n\teffects?: AtomEffect<T>[]\n}\n// biome-ignore format: complex intersection\nexport type MutableAtomOptions<T extends Transceiver<any>, J extends Json.Serializable> = \n\t& JsonInterface<T, J>\n\t& Omit<AtomOptions<T>, `default`> \n\t& { \n\t\t\tdefault: ()\t=> T\n\t\t\tmutable: true\n\t\t}\n\nexport function atom<T extends Transceiver<any>, J extends Json.Serializable>(\n\toptions: MutableAtomOptions<T, J>,\n): MutableAtomToken<T, J>\nexport function atom<T>(options: AtomOptions<T>): AtomToken<T>\nexport function atom(\n\toptions: AtomOptions<any> | MutableAtomOptions<any, any>,\n): AtomToken<any> {\n\treturn createAtom(options, undefined, IMPLICIT.STORE)\n}\n\nexport type AtomFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tdefault: T | ((key: K) => T)\n\teffects?: (key: K) => AtomEffect<T>[]\n}\n\nexport type AtomFamily<T, K extends Json.Serializable = Json.Serializable> = ((\n\tkey: K,\n) => AtomToken<T>) & {\n\tkey: string\n\ttype: `atom_family`\n\tsubject: Subject<AtomToken<T>>\n\tmutable?: boolean\n\tinstall: (store: Store) => void\n}\n\n// biome-ignore format: intersection\nexport type MutableAtomFamilyOptions<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n> = \n\t& AtomFamilyOptions<T, K>\n\t& JsonInterface<T, J>\n\t& { mutable: true }\n\n// biome-ignore format: intersection\nexport type MutableAtomFamily<\n\tCore extends Transceiver<any>,\n\tSerializableCore extends Json.Serializable,\n\tKey extends Json.Serializable,\n> = \n\t& JsonInterface<Core, SerializableCore>\n\t& ((key: Key) => MutableAtomToken<Core, SerializableCore>) \n\t& {\n\t\t\tkey: `${string}`\n\t\t\ttype: `atom_family`\n\t\t\tsubject: Subject<MutableAtomToken<Core, SerializableCore>>\n\t\t\tmutable: true\n\t\t\tinstall: (store: Store) => void\n\t\t}\n\nexport function atomFamily<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n\tK extends Json.Serializable,\n>(options: MutableAtomFamilyOptions<T, J, K>): MutableAtomFamily<T, J, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K>,\n): AtomFamily<T, K>\nexport function atomFamily<T, K extends Json.Serializable>(\n\toptions: AtomFamilyOptions<T, K> | MutableAtomFamilyOptions<any, any, any>,\n): AtomFamily<T, K> | MutableAtomFamily<any, any, any> {\n\treturn createAtomFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport function dispose(\n\ttoken: ReadonlySelectorToken<any> | StateToken<any>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\t\tInternal.deleteAtom(token, store)\n\t\t\tbreak\n\t\tcase `selector`:\n\t\tcase `readonly_selector`:\n\t\t\tInternal.deleteSelector(token, store)\n\t\t\tbreak\n\t}\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { ReadonlySelectorToken, StateToken } from \".\"\n\nexport function getState<T>(\n\ttoken: ReadonlySelectorToken<T> | StateToken<T>,\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): T {\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\treturn Internal.readOrComputeValue(state, store)\n}\n","const LoggerIconDictionary = {\n\t\"⌛\": `Timeline event fully captured`,\n\t\"⏩\": `Timeline redo`,\n\t\"⏪\": `Timeline undo`,\n\t\"⏭️\": `Transaction redo`,\n\t\"⏮️\": `Transaction undo`,\n\t\"⏳\": `Timeline event partially captured`,\n\t\"⏹️\": `Time-travel complete`,\n\t\"💁\": `Notice`,\n\t\"🔄\": `Realtime transaction synchronized`,\n\t\"✅\": `Realtime transaction success`,\n\t\"✨\": `Computation complete`,\n\t\"❌\": `Conflict prevents attempted action`,\n\t\"⭕\": `Operation start`,\n\t\"🐞\": `Possible bug in AtomIO`,\n\t\"👀\": `Subscription added`,\n\t\"👪\": `Family member added`,\n\t\"📁\": `Stow update`,\n\t\"📃\": `Copy mutable`,\n\t\"📖\": `Read state`,\n\t\"📝\": `Write state`,\n\t\"📢\": `Notify subscribers`,\n\t\"🔌\": `Register dependency`,\n\t\"🔍\": `Discover root`,\n\t\"🔥\": `Delete state`,\n\t\"🔧\": `Create mutable atom`,\n\t\"🔨\": `Create immutable atom`,\n\t\"🔴\": `Operation complete`,\n\t\"🗑\": `Evict cached value`,\n\t\"💥\": `Caught`,\n\t\"🙈\": `Subscription canceled`,\n\t\"🛄\": `Apply transaction`,\n\t\"🛠️\": `Install atom into store`,\n\t\"🛫\": `Begin transaction`,\n\t\"🛬\": `Complete transaction`,\n\t\"🧮\": `Computing selector`,\n\t\"🧹\": `Prepare to evict`,\n\t\"🪂\": `Abort transaction`,\n} as const\nexport type LoggerIcon = keyof typeof LoggerIconDictionary\n\nexport const LOG_LEVELS = [`info`, `warn`, `error`] as const\nexport type LogLevel = (typeof LOG_LEVELS)[number]\n\nexport type LogFn = (\n\ticon: LoggerIcon,\n\ttokenType:\n\t\t| `atom`\n\t\t| `readonly_selector`\n\t\t| `selector`\n\t\t| `state`\n\t\t| `timeline`\n\t\t| `transaction`\n\t\t| `unknown`,\n\ttokenKey: string,\n\tmessage: string,\n\t...rest: unknown[]\n) => void\nexport type LogFilter = (...params: Parameters<LogFn>) => boolean\n\nexport type Logger = Record<LogLevel, LogFn>\n\nexport const simpleLog =\n\t(logLevel: keyof Logger): LogFn =>\n\t(icon, tokenType, tokenKey, message, ...rest) => {\n\t\tconsole[logLevel](`${icon} ${tokenType} \"${tokenKey}\" ${message}`, ...rest)\n\t}\nexport const simpleLogger: Logger = {\n\terror: simpleLog(`error`),\n\tinfo: simpleLog(`info`),\n\twarn: simpleLog(`warn`),\n}\n\nexport class AtomIOLogger implements Logger {\n\tpublic constructor(\n\t\tpublic logLevel: `error` | `info` | `warn` | null,\n\t\tprivate readonly filter?: LogFilter,\n\t\tprivate readonly logger: Logger = simpleLogger,\n\t) {}\n\n\tpublic error: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel !== null) {\n\t\t\tthis.logger.error(...args)\n\t\t}\n\t}\n\tpublic info: LogFn = (...args) => {\n\t\tif ((this.filter?.(...args) ?? true) && this.logLevel === `info`) {\n\t\t\tthis.logger.info(...args)\n\t\t}\n\t}\n\tpublic warn: LogFn = (...args) => {\n\t\tif (\n\t\t\t(this.filter?.(...args) ?? true) &&\n\t\t\tthis.logLevel !== `error` &&\n\t\t\tthis.logLevel !== null\n\t\t) {\n\t\t\tthis.logger.warn(...args)\n\t\t}\n\t}\n}\n","import type { Store, Subject } from \"atom.io/internal\"\nimport { IMPLICIT, createSelector, createSelectorFamily } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\n\nimport type { ReadonlySelectorToken, SelectorToken } from \".\"\nimport type { Read, Write } from \"./transaction\"\n\nexport type SelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n\tset: Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorOptions<T> = {\n\tkey: string\n\tget: Read<() => T>\n}\n\nexport function selector<T>(options: SelectorOptions<T>): SelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T>,\n): ReadonlySelectorToken<T>\nexport function selector<T>(\n\toptions: ReadonlySelectorOptions<T> | SelectorOptions<T>,\n): ReadonlySelectorToken<T> | SelectorToken<T> {\n\treturn createSelector(options, undefined, IMPLICIT.STORE)\n}\n\nexport type SelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n\tset: (key: K) => Write<(newValue: T) => void>\n}\nexport type ReadonlySelectorFamilyOptions<T, K extends Json.Serializable> = {\n\tkey: string\n\tget: (key: K) => Read<() => T>\n}\n\nexport type SelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => SelectorToken<T>) & {\n\tkey: string\n\ttype: `selector_family`\n\tsubject: Subject<SelectorToken<T>>\n\tinstall: (store: Store) => void\n}\n\nexport type ReadonlySelectorFamily<\n\tT,\n\tK extends Json.Serializable = Json.Serializable,\n> = ((key: K) => ReadonlySelectorToken<T>) & {\n\tkey: string\n\ttype: `readonly_selector_family`\n\tsubject: Subject<ReadonlySelectorToken<T>>\n\tinstall: (store: Store) => void\n}\n\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: SelectorFamilyOptions<T, K>,\n): SelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K>\nexport function selectorFamily<T, K extends Json.Serializable>(\n\toptions: ReadonlySelectorFamilyOptions<T, K> | SelectorFamilyOptions<T, K>,\n): ReadonlySelectorFamily<T, K> | SelectorFamily<T, K> {\n\treturn createSelectorFamily(options, IMPLICIT.STORE)\n}\n","import * as Internal from \"atom.io/internal\"\n\nimport type { StateToken } from \".\"\n\nexport function setState<T, New extends T>(\n\ttoken: StateToken<T>,\n\tvalue: New | ((oldValue: T) => New),\n\tstore: Internal.Store = Internal.IMPLICIT.STORE,\n): void {\n\tconst rejection = Internal.openOperation(token, store)\n\tif (rejection) {\n\t\treturn\n\t}\n\tconst state =\n\t\tInternal.withdraw(token, store) ??\n\t\tInternal.withdrawNewFamilyMember(token, store)\n\tif (state === undefined) {\n\t\tthrow new Internal.NotFoundError(token, store)\n\t}\n\tInternal.setAtomOrSelector(state, value, store)\n\tInternal.closeOperation(store)\n}\n","import {\n\tStore,\n\tcreateAtom,\n\tcreateAtomFamily,\n\tcreateSelector,\n\tcreateSelectorFamily,\n\tcreateTimeline,\n\tcreateTransaction,\n\ttimeTravel,\n} from \"atom.io/internal\"\n\nimport type { redo, timeline, undo } from \".\"\nimport { getState, setState, subscribe } from \".\"\nimport type { atom, atomFamily } from \"./atom\"\nimport type { selector, selectorFamily } from \"./selector\"\nimport type { transaction } from \"./transaction\"\n\nexport class Silo {\n\tpublic store: Store\n\tpublic atom: typeof atom\n\tpublic atomFamily: typeof atomFamily\n\tpublic selector: typeof selector\n\tpublic selectorFamily: typeof selectorFamily\n\tpublic transaction: typeof transaction\n\tpublic timeline: typeof timeline\n\tpublic getState: typeof getState\n\tpublic setState: typeof setState\n\tpublic subscribe: typeof subscribe\n\tpublic undo: typeof undo\n\tpublic redo: typeof redo\n\tpublic constructor(name: string, fromStore: Store | null = null) {\n\t\tconst s = new Store(name, fromStore)\n\t\tthis.store = s\n\t\tthis.atom = (options) => createAtom(options, undefined, s)\n\t\tthis.atomFamily = (options) => createAtomFamily(options, s)\n\t\tthis.selector = (options) => createSelector(options, undefined, s) as any\n\t\tthis.selectorFamily = (options) => createSelectorFamily(options, s) as any\n\t\tthis.transaction = (options) => createTransaction(options, s)\n\t\tthis.timeline = (options) => createTimeline(options, s)\n\t\tthis.getState = (token) => getState(token, s)\n\t\tthis.setState = (token, newValue) => setState(token, newValue, s)\n\t\tthis.subscribe = (token, handler, key) => subscribe(token, handler, key, s)\n\t\tthis.undo = (token) => timeTravel(`backward`, token, s)\n\t\tthis.redo = (token) => timeTravel(`forward`, token, s)\n\t}\n}\n","import type { Store } from \"atom.io/internal\"\nimport {\n\tIMPLICIT,\n\tsubscribeToState,\n\tsubscribeToTimeline,\n\tsubscribeToTransaction,\n} from \"atom.io/internal\"\n\nimport type {\n\tFamilyMetadata,\n\tReadableToken,\n\tTimelineManageable,\n\tTimelineToken,\n\tTimelineUpdate,\n\tTransactionToken,\n\tTransactionUpdate,\n\tƒn,\n} from \".\"\n\nexport type StateUpdate<T> = { newValue: T; oldValue: T }\nexport type KeyedStateUpdate<T> = StateUpdate<T> & {\n\tkey: string\n\tfamily?: FamilyMetadata\n}\nexport type UpdateHandler<T> = (update: StateUpdate<T>) => void\n\nexport type TransactionUpdateHandler<ƒ extends ƒn> = (\n\tdata: TransactionUpdate<ƒ>,\n) => void\n\nexport function subscribe<T>(\n\ttoken: ReadableToken<T>,\n\thandleUpdate: UpdateHandler<T>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<ƒ extends ƒn>(\n\ttoken: TransactionToken<ƒ>,\n\thandleUpdate: TransactionUpdateHandler<ƒ>,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe<M extends TimelineManageable>(\n\ttoken: TimelineToken<M>,\n\thandleUpdate: (update: TimelineUpdate<M> | `redo` | `undo`) => void,\n\tkey?: string,\n\tstore?: Store,\n): () => void\nexport function subscribe(\n\ttoken: ReadableToken<any> | TimelineToken<any> | TransactionToken<any>,\n\thandleUpdate: (update: any) => void,\n\tkey: string = Math.random().toString(36).slice(2),\n\tstore = IMPLICIT.STORE,\n): () => void {\n\tswitch (token.type) {\n\t\tcase `atom`:\n\t\tcase `readonly_selector`:\n\t\tcase `selector`:\n\t\t\treturn subscribeToState(token, handleUpdate, key, store)\n\t\tcase `transaction`:\n\t\t\treturn subscribeToTransaction(token, handleUpdate, key, store)\n\t\tcase `timeline`:\n\t\t\treturn subscribeToTimeline(token, handleUpdate, key, store)\n\t}\n}\n","import type {\n\tTimeline,\n\tTimelineAtomUpdate,\n\tTimelineSelectorUpdate,\n\tTimelineTransactionUpdate,\n} from \"atom.io/internal\"\nimport { IMPLICIT, createTimeline, timeTravel } from \"atom.io/internal\"\n\nimport type { AtomFamily, AtomToken } from \".\"\n\nexport type TimelineManageable = AtomFamily<any, any> | AtomToken<any>\n\nexport type TimelineToken<_> = {\n\tkey: string\n\ttype: `timeline`\n\t__brand?: _\n}\n\nexport type TimelineOptions<ManagedAtom extends TimelineManageable> = {\n\tkey: string\n\tatoms: ManagedAtom[]\n\tshouldCapture?: (\n\t\tupdate: TimelineUpdate<ManagedAtom>,\n\t\ttimeline: Timeline<TimelineManageable>,\n\t) => boolean\n}\n\nexport type TimelineUpdate<ManagedAtom extends TimelineManageable> =\n\t| TimelineAtomUpdate<ManagedAtom>\n\t| TimelineSelectorUpdate<ManagedAtom>\n\t| TimelineTransactionUpdate\n\nexport const timeline = <ManagedAtom extends TimelineManageable>(\n\toptions: TimelineOptions<ManagedAtom>,\n): TimelineToken<ManagedAtom> => {\n\treturn createTimeline(options, IMPLICIT.STORE)\n}\n\nexport const redo = (timeline: TimelineToken<any>): void => {\n\ttimeTravel(`forward`, timeline, IMPLICIT.STORE)\n}\n\nexport const undo = (timeline: TimelineToken<any>): void => {\n\ttimeTravel(`backward`, timeline, IMPLICIT.STORE)\n}\n","import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT, createTransaction, withdraw } from \"atom.io/internal\"\n\nimport type { KeyedStateUpdate, ReadonlySelectorToken, StateToken, ƒn } from \".\"\n\nexport type TransactionToken<_> = {\n\tkey: string\n\ttype: `transaction`\n\t__brand?: _\n}\n\nexport type TransactionUpdate<ƒ extends ƒn> = {\n\tkey: string\n\tupdates: (KeyedStateUpdate<unknown> | TransactionUpdate<ƒn>)[]\n\tparams: Parameters<ƒ>\n\toutput: ReturnType<ƒ>\n}\n\nexport type Transactors = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: StateToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n}>\nexport type TransactorsWithRun = Readonly<{\n\tget: <S>(state: ReadonlySelectorToken<S> | StateToken<S>) => S\n\tset: <S, New extends S>(\n\t\tstate: StateToken<S>,\n\t\tnewValue: New | ((oldValue: S) => New),\n\t) => void\n\trun: typeof runTransaction\n}>\nexport type ReadonlyTransactors = Pick<Transactors, `get`>\n\nexport type Read<ƒ extends ƒn> = (\n\ttransactors: ReadonlyTransactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Write<ƒ extends ƒn> = (\n\ttransactors: Transactors,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type Transact<ƒ extends ƒn> = (\n\ttransactors: TransactorsWithRun,\n\t...parameters: Parameters<ƒ>\n) => ReturnType<ƒ>\n\nexport type TransactionOptions<ƒ extends ƒn> = {\n\tkey: string\n\tdo: Transact<ƒ>\n}\n\nexport type TransactionIO<Token extends TransactionToken<any>> =\n\tToken extends TransactionToken<infer ƒ> ? ƒ : never\n\nexport function transaction<ƒ extends ƒn>(\n\toptions: TransactionOptions<ƒ>,\n): TransactionToken<ƒ> {\n\treturn createTransaction(options, IMPLICIT.STORE)\n}\n\nexport const runTransaction =\n\t<ƒ extends ƒn>(token: TransactionToken<ƒ>, store: Store = IMPLICIT.STORE) =>\n\t(...parameters: Parameters<ƒ>): ReturnType<ƒ> => {\n\t\tconst tx = withdraw(token, store)\n\t\tif (tx) {\n\t\t\treturn tx.run(...parameters)\n\t\t}\n\t\tthrow new Error(\n\t\t\t`Cannot run transaction \"${token.key}\": transaction not found in store \"${store.config.name}\".`,\n\t\t)\n\t}\n","import type {\n\tAtomFamily,\n\tAtomToken,\n\tReadableFamily,\n\tReadableToken,\n\tReadonlySelectorFamily,\n\tReadonlySelectorToken,\n\tSelectorFamily,\n\tSelectorToken,\n\tWritableFamily,\n\tWritableToken,\n} from \"atom.io\"\n\nexport type TokenType<\n\tComparison extends ReadableFamily<any, any> | ReadableToken<any>,\n> = Comparison extends ReadableToken<infer RepresentedValue>\n\t? RepresentedValue\n\t: Comparison extends ReadableFamily<infer RepresentedValue, any>\n\t ? RepresentedValue\n\t : never\n\nexport function isToken<KnownToken extends AtomToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is AtomToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends SelectorToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is SelectorToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadonlySelectorToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadonlySelectorToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends WritableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is WritableToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends WritableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadableToken<TokenType<KnownToken>>\nexport function isToken<KnownToken extends ReadableToken<any>>(\n\tknownToken: KnownToken,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadableToken<TokenType<KnownToken>> {\n\treturn knownToken.key === unknownToken.key\n}\n\nexport function belongsTo<Family extends AtomFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is AtomToken<TokenType<Family>>\nexport function belongsTo<Family extends SelectorFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is SelectorToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadonlySelectorFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadonlySelectorToken<TokenType<Family>>\nexport function belongsTo<Family extends WritableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is WritableToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadableToken<TokenType<Family>>\nexport function belongsTo<Family extends ReadableFamily<any, any>>(\n\tfamily: Family,\n\tunknownToken: ReadableToken<unknown>,\n): unknownToken is ReadableToken<TokenType<Family>> {\n\treturn family.key === unknownToken.family?.key\n}\n"]}