atom.io 0.10.0 → 0.10.2

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.
@@ -35,7 +35,9 @@ export const openOperation = (
35
35
  token,
36
36
  }
37
37
  store.logger.info(
38
- `⭕ operation start from "${token.key}" in store "${store.config.name}"${
38
+ `⭕ Operation start from ${token.type} "${token.key}" in store "${
39
+ store.config.name
40
+ }"${
39
41
  store.transactionStatus.phase === `idle`
40
42
  ? ``
41
43
  : ` ${store.transactionStatus.phase} "${store.transactionStatus.key}"`
@@ -44,8 +46,12 @@ export const openOperation = (
44
46
  }
45
47
  export const closeOperation = (store: Store): void => {
46
48
  const core = target(store)
49
+ if (core.operation.open) {
50
+ store.logger.info(
51
+ `🔴 Operation done for ${core.operation.token.type} "${core.operation.token.key}" in store ${store.config.name}`,
52
+ )
53
+ }
47
54
  core.operation = { open: false }
48
- store.logger.info(`🔴 operation done`)
49
55
  store.subject.operationStatus.next(core.operation)
50
56
  }
51
57
 
@@ -53,7 +59,7 @@ export const isDone = (key: string, store: Store = IMPLICIT.STORE): boolean => {
53
59
  const core = target(store)
54
60
  if (!core.operation.open) {
55
61
  store.logger.warn(
56
- `isDone called outside of an operation. This is probably a bug.`,
62
+ `🐞 isDone called outside of an operation. This is probably a bug.`,
57
63
  )
58
64
  return true
59
65
  }
@@ -11,13 +11,16 @@ export const emitUpdate = <T>(
11
11
  ): void => {
12
12
  const { key } = state
13
13
  const { logger } = store
14
- logger?.info(
14
+ logger.info(
15
15
  `📢 ${state.type} "${key}" went (`,
16
16
  update.oldValue,
17
17
  `->`,
18
18
  update.newValue,
19
19
  `)`,
20
20
  )
21
- logger?.info(`📢 notifying subscribers:`, state.subject.subscribers)
21
+ logger.info(
22
+ `📢 notifying subscribers to "${state.key}"`,
23
+ state.subject.subscribers,
24
+ )
22
25
  state.subject.next(update)
23
26
  }
@@ -12,13 +12,17 @@ export const evictDownStream = <T>(
12
12
  const core = target(store)
13
13
  const downstreamKeys = core.selectorAtoms.getRelatedKeys(state.key)
14
14
  store.logger.info(
15
- `🧹 evicting ${downstreamKeys?.size} states downstream from ${state.type} "${state.key}":`,
15
+ `🧹 evicting ${downstreamKeys?.size ?? 0} states downstream from ${
16
+ state.type
17
+ } "${state.key}":`,
16
18
  downstreamKeys,
17
19
  )
18
- if (core.operation.open) {
19
- store.logger.info(`🧹`, [...core.operation.done], `already done`)
20
- }
21
- if (downstreamKeys) {
20
+ if (downstreamKeys !== undefined) {
21
+ if (core.operation.open) {
22
+ store.logger.info(
23
+ `🧹 [ ${[...core.operation.done].join(`, `)} ] already done`,
24
+ )
25
+ }
22
26
  for (const key of downstreamKeys) {
23
27
  if (isDone(key, store)) {
24
28
  continue
@@ -22,7 +22,6 @@ export const stowUpdate = <T>(
22
22
  store: Store,
23
23
  ): void => {
24
24
  const { key } = state
25
- const { logger } = store
26
25
  if (store.transactionStatus.phase !== `building`) {
27
26
  store.logger.warn(
28
27
  `🐞 stowUpdate called outside of a transaction. This is probably a bug.`,
@@ -107,19 +107,19 @@ export class Store {
107
107
  ),
108
108
  ]
109
109
  public logger: Logger = {
110
- error: (message: string) => {
110
+ error: (...messages: unknown[]) => {
111
111
  for (const logger of this.loggers) {
112
- logger.error(message)
112
+ logger.error(...messages)
113
113
  }
114
114
  },
115
- info: (message: string) => {
115
+ info: (...messages: unknown[]) => {
116
116
  for (const logger of this.loggers) {
117
- logger.info(message)
117
+ logger.info(...messages)
118
118
  }
119
119
  },
120
- warn: (message: string) => {
120
+ warn: (...messages: unknown[]) => {
121
121
  for (const logger of this.loggers) {
122
- logger.warn(message)
122
+ logger.warn(...messages)
123
123
  }
124
124
  },
125
125
  }
@@ -11,7 +11,7 @@ export const recallState = <T>(
11
11
  const core = target(store)
12
12
  if (!core.operation.open) {
13
13
  store.logger.warn(
14
- `🐞recall called outside of an operation. This is probably a bug.`,
14
+ `🐞 recall called outside of an operation. This is probably a bug.`,
15
15
  )
16
16
  return core.valueMap.get(state.key)
17
17
  }
@@ -7,6 +7,9 @@ export const abortTransaction = (store: Store): void => {
7
7
  )
8
8
  return
9
9
  }
10
+ store.logger.info(
11
+ `🪂`,
12
+ `Aborting transaction "${store.transactionStatus.key}"`,
13
+ )
10
14
  store.transactionStatus = { phase: `idle` }
11
- store.logger.info(`🪂`, `transaction fail`)
12
15
  }
@@ -20,7 +20,10 @@ export const applyTransaction = <ƒ extends ƒn>(
20
20
  store.logger.info(
21
21
  `🛃 applying transaction "${store.transactionStatus.key}" with ${atomUpdates.length} updates.`,
22
22
  )
23
- store.logger.info(`🛃 the updates are:`, atomUpdates)
23
+ store.logger.info(
24
+ `🛃 the updates from "${store.transactionStatus.key}" are:`,
25
+ atomUpdates,
26
+ )
24
27
  for (const { key, newValue } of atomUpdates) {
25
28
  const token: AtomToken<unknown> = { key, type: `atom` }
26
29
  if (!store.valueMap.has(token.key)) {
@@ -38,7 +41,7 @@ export const applyTransaction = <ƒ extends ƒn>(
38
41
  }
39
42
  store.atoms.set(newAtom.key, newAtom)
40
43
  store.valueMap.set(newAtom.key, newAtom.default)
41
- store.logger.info(`🔧 add atom "${newAtom.key}"`)
44
+ store.logger.info(`🔧 Add atom "${newAtom.key}"`)
42
45
  }
43
46
  }
44
47
  // if (store.transactionStatus.key === `dealCards`) debugger
@@ -60,5 +63,5 @@ export const applyTransaction = <ƒ extends ƒn>(
60
63
  params: store.transactionStatus.params as Parameters<ƒ>,
61
64
  })
62
65
  store.transactionStatus = { phase: `idle` }
63
- store.logger.info(`🛬 transaction "${myTransaction.key}" applied`)
66
+ store.logger.info(`🛬 Successfully applied transaction "${myTransaction.key}"`)
64
67
  }
@@ -33,6 +33,6 @@ export const buildTransaction = (
33
33
  output: undefined,
34
34
  }
35
35
  store.logger.info(
36
- `🛫 transaction "${key}" building in store "${store.config.name}"`,
36
+ `🛫 Building transaction "${key}" in store "${store.config.name}"`,
37
37
  )
38
38
  }
@@ -8,7 +8,7 @@ export const redoTransactionUpdate = <ƒ extends ƒn>(
8
8
  update: TransactionUpdate<ƒ>,
9
9
  store: Store,
10
10
  ): void => {
11
- store.logger.info(` ⏭ redo transaction "${update.key}" (redo)`)
11
+ store.logger.info(` ⏭ Redo transaction "${update.key}"`)
12
12
  for (const { key, newValue } of update.atomUpdates) {
13
13
  const token: AtomToken<unknown> = { key, type: `atom` }
14
14
  const state = withdraw(token, store)
@@ -8,7 +8,7 @@ export const undoTransactionUpdate = <ƒ extends ƒn>(
8
8
  update: TransactionUpdate<ƒ>,
9
9
  store: Store,
10
10
  ): void => {
11
- store.logger.info(` ⏮ undo transaction "${update.key}" (undo)`)
11
+ store.logger.info(` ⏮ Undo transaction "${update.key}"`)
12
12
  for (const { key, oldValue } of update.atomUpdates) {
13
13
  const token: AtomToken<unknown> = { key, type: `atom` }
14
14
  const state = withdraw(token, store)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atom.io",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
4
4
  "description": "Composable and testable reactive data library.",
5
5
  "homepage": "https://atom.io.fyi",
6
6
  "sideEffects": false,
@@ -14,7 +14,6 @@
14
14
  "url": "git+https://github.com/jeremybanka/wayforge.git",
15
15
  "directory": "packages/atom.io"
16
16
  },
17
- "dependencies": {},
18
17
  "peerDependencies": {
19
18
  "@floating-ui/react": ">=0.25.0",
20
19
  "@floating-ui/react-dom": ">=2.0.0",
@@ -50,15 +49,20 @@
50
49
  "devDependencies": {
51
50
  "@emotion/react": "11.11.1",
52
51
  "@testing-library/react": "14.1.2",
52
+ "@types/http-proxy": "1.17.14",
53
53
  "@types/npmlog": "4.1.6",
54
54
  "@types/react": "18.2.37",
55
55
  "@types/tmp": "0.2.6",
56
56
  "@vitest/coverage-v8": "0.34.6",
57
57
  "concurrently": "8.2.2",
58
+ "drizzle-kit": "0.20.4",
59
+ "drizzle-orm": "0.29.0",
58
60
  "eslint": "8.54.0",
59
61
  "framer-motion": "10.16.5",
60
62
  "happy-dom": "12.10.3",
63
+ "http-proxy": "1.18.1",
61
64
  "npmlog": "7.0.1",
65
+ "postgres": "3.4.3",
62
66
  "preact": "10.19.2",
63
67
  "react": "18.2.0",
64
68
  "react-dom": "18.2.0",
@@ -67,7 +71,7 @@
67
71
  "socket.io-client": "4.7.2",
68
72
  "tmp": "0.2.1",
69
73
  "tsup": "8.0.0",
70
- "typescript": "5.2.2",
74
+ "typescript": "5.3.2",
71
75
  "vite": "4.5.0",
72
76
  "vite-tsconfig-paths": "4.2.1",
73
77
  "vitest": "0.34.6"
@@ -199,7 +203,7 @@
199
203
  }
200
204
  },
201
205
  "scripts": {
202
- "integrity": "tsx __scripts__/integrity-build.node",
206
+ "manifest": "tsx __scripts__/manifest-build.node",
203
207
  "build": "concurrently \"npm:build:*\"",
204
208
  "build:main": "tsup",
205
209
  "build:data": "cd data && tsup",
@@ -217,7 +221,7 @@
217
221
  "lint:eslint": "eslint .",
218
222
  "lint": "npm run lint:biome && npm run lint:eslint",
219
223
  "test": "vitest",
220
- "test:once": "npm run test:integrity && cross-env IMPORT=dist vitest run",
221
- "test:integrity": "tsx __scripts__/integrity-test.node"
224
+ "test:once": "npm run test:manifest && cross-env IMPORT=dist vitest run",
225
+ "test:manifest": "tsx __scripts__/manifest-test.node"
222
226
  }
223
227
  }
@@ -138,10 +138,16 @@ function synchronizeTransactionResults(token, socket, store) {
138
138
  store.logger.error(
139
139
  `\u2757 Transaction "${token.key}" produced different results on client and server`
140
140
  );
141
- store.logger.error(`\u2757 Client:`, clientResult);
142
- store.logger.error(`\u2757 Server:`, serverResult);
141
+ store.logger.error(
142
+ `\u2757 Client result for "${token.key}":`,
143
+ clientResult
144
+ );
145
+ store.logger.error(
146
+ `\u2757 Server result for "${token.key}:`,
147
+ serverResult
148
+ );
143
149
  } else {
144
- store.logger.info(`\u2705 Transaction ${token.key} results match`);
150
+ store.logger.info(`\u2705 Transaction "${token.key}" results match`);
145
151
  }
146
152
  };
147
153
  socket.on(topic, sync);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/realtime-state.ts","../src/use-pull.ts","../src/use-pull-family-member.ts","../src/use-pull-mutable.ts","../src/use-pull-mutable-family-member.ts","../src/use-push.ts","../src/use-server-action.ts"],"names":["AtomIO","getJsonToken","getUpdateToken","parseJson","_a"],"mappings":";AAAA,YAAY,YAAY;AAEjB,IAAM,sBAA6B,YAAoB;AAAA,EAC7D,KAAK;AAAA,EACL,SAAS;AACV,CAAC;AACM,IAAM,YAAmB,gBAAwB;AAAA,EACvD,KAAK;AAAA,EACL,KAAK,CAAC,EAAE,IAAI,MAAM,IAAI,mBAAmB;AAC1C,CAAC;;;ACTD,YAAYA,aAAY;AAKjB,SAAS,UACf,OACA,QACA,OACa;AACb,SAAO,GAAG,SAAS,MAAM,GAAG,IAAI,CAAC,SAAS;AACzC,IAAO,iBAAS,OAAO,MAAM,KAAK;AAAA,EACnC,CAAC;AACD,SAAO,KAAK,OAAO,MAAM,GAAG,EAAE;AAC9B,SAAO,MAAM;AACZ,WAAO,IAAI,SAAS,MAAM,GAAG,EAAE;AAC/B,WAAO,KAAK,SAAS,MAAM,GAAG,EAAE;AAAA,EACjC;AACD;;;AClBA,YAAYA,aAAY;AAGxB,SAAS,iBAAiB;AAGnB,SAAS,iBACf,OACA,QACA,OACa;AACb,MAAI,EAAE,YAAY,QAAQ;AACzB,YAAQ,MAAM,iCAAiC,KAAK;AACpD,WAAO,MAAM;AAAA,IAAC;AAAA,EACf;AACA,QAAM,EAAE,KAAK,WAAW,QAAQ,iBAAiB,IAAI,MAAM;AAC3D,QAAM,SAAS,UAAU,gBAAgB;AACzC,mCAAQ,GAAG,SAAS,MAAM,GAAG,IAAI,CAAC,SAAY;AAC7C,IAAO,iBAAS,OAAO,MAAM,KAAK;AAAA,EACnC;AACA,mCAAQ,KAAK,OAAO,SAAS,IAAI;AACjC,SAAO,MAAM;AACZ,qCAAQ,IAAI,SAAS,MAAM,GAAG;AAC9B,qCAAQ,KAAK,SAAS,MAAM,GAAG;AAAA,EAChC;AACD;;;ACzBA,YA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AM,OAAO,KAAK,sBAAiB,MAAM,GAAG,gBAAgB;AAAA,QAC7D;AAAA,MACD;AACA,aAAO,GAAG,OAAO,IAAI;AACrB,aAAO,KAAK,MAAM,MAAM,GAAG,IAAI,cAAc,aAAa;AAAA,IAC3D;AAAA,IACA;AAAA,IACA;AAAA,EACA,IACA,MAAM;AACV,SAAO,MAAM;AAzCd,QAAAI;AA0CE,UAAM,YAAWA,MAAA,QAAQ,IAAI,MAAM,GAAG,MAArB,OAAAA,MAA0B;AAC3C,YAAQ,IAAI,MAAM,KAAK,WAAW,CAAC;AACnC,gBAAY;AAAA,EACb;AACD","sourcesContent":["import * as AtomIO from \"atom.io\"\n\nexport const myIdState__INTERNAL = AtomIO.atom<string | null>({\n\tkey: `myId__INTERNAL`,\n\tdefault: null,\n})\nexport const myIdState = AtomIO.selector<string | null>({\n\tkey: `myId`,\n\tget: ({ get }) => get(myIdState__INTERNAL),\n})\n","import * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullState<J extends Json.Serializable>(\n\ttoken: AtomIO.StateToken<J>,\n\tsocket: Socket,\n\tstore: Store,\n): () => void {\n\tsocket.on(`serve:${token.key}`, (data) => {\n\t\tAtomIO.setState(token, data, store)\n\t})\n\tsocket.emit(`sub:${token.key}`)\n\treturn () => {\n\t\tsocket.off(`serve:${token.key}`)\n\t\tsocket.emit(`unsub:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { parseJson } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullFamilyMember<J extends Json.Serializable>(\n\ttoken: AtomIO.AtomToken<J>,\n\tsocket: Socket,\n\tstore: Store,\n): () => void {\n\tif (!(`family` in token)) {\n\t\tconsole.error(`Token is not a family member:`, token)\n\t\treturn () => {}\n\t}\n\tconst { key: familyKey, subKey: serializedSubKey } = token.family\n\tconst subKey = parseJson(serializedSubKey)\n\tsocket?.on(`serve:${token.key}`, (data: J) => {\n\t\tAtomIO.setState(token, data, store)\n\t})\n\tsocket?.emit(`sub:${familyKey}`, subKey)\n\treturn () => {\n\t\tsocket?.off(`serve:${token.key}`)\n\t\tsocket?.emit(`unsub:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport type { Store, Transceiver } from \"atom.io/internal\"\nimport { getJsonToken, getUpdateToken } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullMutableState<\n\tT extends Transceiver<Json.Serializable>,\n\tJ extends Json.Serializable,\n>(\n\ttoken: AtomIO.MutableAtomToken<T, J>,\n\tsocket: Socket,\n\tstore: Store,\n): () => void {\n\tconst jsonToken = getJsonToken(token)\n\tconst updateToken = getUpdateToken(token)\n\tsocket.on(`init:${token.key}`, (data: J) => {\n\t\tAtomIO.setState(jsonToken, data, store)\n\t})\n\tsocket.on(\n\t\t`next:${token.key}`,\n\t\t(data: T extends Transceiver<infer Update> ? Update : never) => {\n\t\t\tAtomIO.setState(updateToken, data, store)\n\t\t},\n\t)\n\tsocket.emit(`sub:${token.key}`)\n\treturn () => {\n\t\tsocket.off(`init:${token.key}`)\n\t\tsocket.off(`next:${token.key}`)\n\t\tsocket.emit(`unsub:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport { getJsonToken, getUpdateToken } from \"atom.io/internal\"\nimport type { Store, Transceiver } from \"atom.io/internal\"\nimport { parseJson } from \"atom.io/json\"\nimport type { Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullMutableFamilyMember<\n\tT extends Transceiver<Json.Serializable>,\n\tJ extends Json.Serializable,\n>(\n\ttoken: AtomIO.MutableAtomToken<T, J>,\n\tsocket: Socket,\n\tstore: Store,\n): () => void {\n\tif (!(`family` in token)) {\n\t\tconsole.error(`Token is not a family member:`, token)\n\t\treturn () => {}\n\t}\n\tconst { key: familyKey, subKey: serializedSubKey } = token.family\n\tconst subKey = parseJson(serializedSubKey)\n\tsocket?.on(`init:${token.key}`, (data: J) => {\n\t\tconst jsonToken = getJsonToken(token)\n\t\tAtomIO.setState(jsonToken, data, store)\n\t})\n\tsocket?.on(\n\t\t`next:${token.key}`,\n\t\t(data: T extends Transceiver<infer Signal> ? Signal : never) => {\n\t\t\tconst trackerToken = getUpdateToken(token)\n\t\t\tAtomIO.setState(trackerToken, data, store)\n\t\t},\n\t)\n\tsocket?.emit(`sub:${familyKey}`, subKey)\n\treturn () => {\n\t\tsocket?.off(`serve:${token.key}`)\n\t\tsocket?.emit(`unsub:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pushState<J extends Json.Serializable>(\n\ttoken: AtomIO.StateToken<J>,\n\tsocket: Socket,\n\tsubscriptionKey: string,\n\tstore: Store,\n): () => void {\n\tsocket.emit(`claim:${token.key}`)\n\tAtomIO.subscribe(\n\t\ttoken,\n\t\t({ newValue }) => {\n\t\t\tsocket.emit(`pub:${token.key}`, newValue)\n\t\t},\n\t\tsubscriptionKey,\n\t\tstore,\n\t)\n\treturn () => {\n\t\tsocket.off(`pub:${token.key}`)\n\t\tsocket.emit(`unclaim:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport type { Socket } from \"socket.io-client\"\n\nconst TX_SUBS = new Map<string, number>()\nexport function synchronizeTransactionResults(\n\ttoken: AtomIO.TransactionToken<any>,\n\tsocket: Socket,\n\tstore: Store,\n): () => void {\n\tconst count = TX_SUBS.get(token.key) ?? 0\n\tTX_SUBS.set(token.key, count + 1)\n\tconst unsubscribe =\n\t\tcount === 0\n\t\t\t? AtomIO.subscribeToTransaction(\n\t\t\t\t\ttoken,\n\t\t\t\t\t(clientUpdate) => {\n\t\t\t\t\t\tconst transactionId = Math.random().toString(36).slice(2)\n\t\t\t\t\t\tconst clientResult = JSON.stringify(clientUpdate)\n\t\t\t\t\t\tconst topic = `tx:sync:${transactionId}`\n\t\t\t\t\t\tconst sync = (serverUpdate: typeof clientUpdate) => {\n\t\t\t\t\t\t\tstore.logger.info(`♻️ Transaction \"${token.key}\" synced`)\n\t\t\t\t\t\t\tsocket.off(topic, sync)\n\t\t\t\t\t\t\tconst serverResult = JSON.stringify(serverUpdate)\n\t\t\t\t\t\t\tif (clientResult !== serverResult) {\n\t\t\t\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t\t\t\t`❗ Transaction \"${token.key}\" produced different results on client and server`,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tstore.logger.error(`❗ Client:`, clientResult)\n\t\t\t\t\t\t\t\tstore.logger.error(`❗ Server:`, serverResult)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tstore.logger.info(`✅ Transaction ${token.key} results match`)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsocket.on(topic, sync)\n\t\t\t\t\t\tsocket.emit(`tx:${token.key}`, clientUpdate, transactionId)\n\t\t\t\t\t},\n\t\t\t\t\t`use-server-action`,\n\t\t\t\t\tstore,\n\t\t\t )\n\t\t\t: () => null\n\treturn () => {\n\t\tconst newCount = TX_SUBS.get(token.key) ?? 0\n\t\tTX_SUBS.set(token.key, newCount - 1)\n\t\tunsubscribe()\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../src/realtime-state.ts","../src/use-pull.ts","../src/use-pull-family-member.ts","../src/use-pull-mutable.ts","../src/use-pull-mutable-family-member.ts","../src/use-push.ts","../src/use-server-action.ts"],"names":["AtomIO","getJsonToken","getUpdateToken","parseJson","_a"],"mappings":";AAAA,YAAY,YAAY;AAEjB,IAAM,sBAA6B,YAAoB;AAAA,EAC7D,KAAK;AAAA,EACL,SAAS;AACV,CAAC;AAC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AAA,EACA,IACA,MAAM;AACV,SAAO,MAAM;AA/Cd,QAAAI;AAgDE,UAAM,YAAWA,MAAA,QAAQ,IAAI,MAAM,GAAG,MAArB,OAAAA,MAA0B;AAC3C,YAAQ,IAAI,MAAM,KAAK,WAAW,CAAC;AACnC,gBAAY;AAAA,EACb;AACD","sourcesContent":["import * as AtomIO from \"atom.io\"\n\nexport const myIdState__INTERNAL = AtomIO.atom<string | null>({\n\tkey: `myId__INTERNAL`,\n\tdefault: null,\n})\nexport const myIdState = AtomIO.selector<string | null>({\n\tkey: `myId`,\n\tget: ({ get }) => get(myIdState__INTERNAL),\n})\n","import * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullState<J extends Json.Serializable>(\n\ttoken: AtomIO.StateToken<J>,\n\tsocket: Socket,\n\tstore: Store,\n): () => void {\n\tsocket.on(`serve:${token.key}`, (data) => {\n\t\tAtomIO.setState(token, data, store)\n\t})\n\tsocket.emit(`sub:${token.key}`)\n\treturn () => {\n\t\tsocket.off(`serve:${token.key}`)\n\t\tsocket.emit(`unsub:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { parseJson } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullFamilyMember<J extends Json.Serializable>(\n\ttoken: AtomIO.AtomToken<J>,\n\tsocket: Socket,\n\tstore: Store,\n): () => void {\n\tif (!(`family` in token)) {\n\t\tconsole.error(`Token is not a family member:`, token)\n\t\treturn () => {}\n\t}\n\tconst { key: familyKey, subKey: serializedSubKey } = token.family\n\tconst subKey = parseJson(serializedSubKey)\n\tsocket?.on(`serve:${token.key}`, (data: J) => {\n\t\tAtomIO.setState(token, data, store)\n\t})\n\tsocket?.emit(`sub:${familyKey}`, subKey)\n\treturn () => {\n\t\tsocket?.off(`serve:${token.key}`)\n\t\tsocket?.emit(`unsub:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport type { Store, Transceiver } from \"atom.io/internal\"\nimport { getJsonToken, getUpdateToken } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullMutableState<\n\tT extends Transceiver<Json.Serializable>,\n\tJ extends Json.Serializable,\n>(\n\ttoken: AtomIO.MutableAtomToken<T, J>,\n\tsocket: Socket,\n\tstore: Store,\n): () => void {\n\tconst jsonToken = getJsonToken(token)\n\tconst updateToken = getUpdateToken(token)\n\tsocket.on(`init:${token.key}`, (data: J) => {\n\t\tAtomIO.setState(jsonToken, data, store)\n\t})\n\tsocket.on(\n\t\t`next:${token.key}`,\n\t\t(data: T extends Transceiver<infer Update> ? Update : never) => {\n\t\t\tAtomIO.setState(updateToken, data, store)\n\t\t},\n\t)\n\tsocket.emit(`sub:${token.key}`)\n\treturn () => {\n\t\tsocket.off(`init:${token.key}`)\n\t\tsocket.off(`next:${token.key}`)\n\t\tsocket.emit(`unsub:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport { getJsonToken, getUpdateToken } from \"atom.io/internal\"\nimport type { Store, Transceiver } from \"atom.io/internal\"\nimport { parseJson } from \"atom.io/json\"\nimport type { Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullMutableFamilyMember<\n\tT extends Transceiver<Json.Serializable>,\n\tJ extends Json.Serializable,\n>(\n\ttoken: AtomIO.MutableAtomToken<T, J>,\n\tsocket: Socket,\n\tstore: Store,\n): () => void {\n\tif (!(`family` in token)) {\n\t\tconsole.error(`Token is not a family member:`, token)\n\t\treturn () => {}\n\t}\n\tconst { key: familyKey, subKey: serializedSubKey } = token.family\n\tconst subKey = parseJson(serializedSubKey)\n\tsocket?.on(`init:${token.key}`, (data: J) => {\n\t\tconst jsonToken = getJsonToken(token)\n\t\tAtomIO.setState(jsonToken, data, store)\n\t})\n\tsocket?.on(\n\t\t`next:${token.key}`,\n\t\t(data: T extends Transceiver<infer Signal> ? Signal : never) => {\n\t\t\tconst trackerToken = getUpdateToken(token)\n\t\t\tAtomIO.setState(trackerToken, data, store)\n\t\t},\n\t)\n\tsocket?.emit(`sub:${familyKey}`, subKey)\n\treturn () => {\n\t\tsocket?.off(`serve:${token.key}`)\n\t\tsocket?.emit(`unsub:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pushState<J extends Json.Serializable>(\n\ttoken: AtomIO.StateToken<J>,\n\tsocket: Socket,\n\tsubscriptionKey: string,\n\tstore: Store,\n): () => void {\n\tsocket.emit(`claim:${token.key}`)\n\tAtomIO.subscribe(\n\t\ttoken,\n\t\t({ newValue }) => {\n\t\t\tsocket.emit(`pub:${token.key}`, newValue)\n\t\t},\n\t\tsubscriptionKey,\n\t\tstore,\n\t)\n\treturn () => {\n\t\tsocket.off(`pub:${token.key}`)\n\t\tsocket.emit(`unclaim:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport type { Socket } from \"socket.io-client\"\n\nconst TX_SUBS = new Map<string, number>()\nexport function synchronizeTransactionResults(\n\ttoken: AtomIO.TransactionToken<any>,\n\tsocket: Socket,\n\tstore: Store,\n): () => void {\n\tconst count = TX_SUBS.get(token.key) ?? 0\n\tTX_SUBS.set(token.key, count + 1)\n\tconst unsubscribe =\n\t\tcount === 0\n\t\t\t? AtomIO.subscribeToTransaction(\n\t\t\t\t\ttoken,\n\t\t\t\t\t(clientUpdate) => {\n\t\t\t\t\t\tconst transactionId = Math.random().toString(36).slice(2)\n\t\t\t\t\t\tconst clientResult = JSON.stringify(clientUpdate)\n\t\t\t\t\t\tconst topic = `tx:sync:${transactionId}`\n\t\t\t\t\t\tconst sync = (serverUpdate: typeof clientUpdate) => {\n\t\t\t\t\t\t\tstore.logger.info(`♻️ Transaction \"${token.key}\" synced`)\n\t\t\t\t\t\t\tsocket.off(topic, sync)\n\t\t\t\t\t\t\tconst serverResult = JSON.stringify(serverUpdate)\n\t\t\t\t\t\t\tif (clientResult !== serverResult) {\n\t\t\t\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t\t\t\t`❗ Transaction \"${token.key}\" produced different results on client and server`,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t\t\t\t`❗ Client result for \"${token.key}\":`,\n\t\t\t\t\t\t\t\t\tclientResult,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t\t\t\t`❗ Server result for \"${token.key}:`,\n\t\t\t\t\t\t\t\t\tserverResult,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tstore.logger.info(`✅ Transaction \"${token.key}\" results match`)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsocket.on(topic, sync)\n\t\t\t\t\t\tsocket.emit(`tx:${token.key}`, clientUpdate, transactionId)\n\t\t\t\t\t},\n\t\t\t\t\t`use-server-action`,\n\t\t\t\t\tstore,\n\t\t\t )\n\t\t\t: () => null\n\treturn () => {\n\t\tconst newCount = TX_SUBS.get(token.key) ?? 0\n\t\tTX_SUBS.set(token.key, newCount - 1)\n\t\tunsubscribe()\n\t}\n}\n"]}
@@ -116,10 +116,16 @@ function synchronizeTransactionResults(token, socket, store) {
116
116
  store.logger.error(
117
117
  `\u2757 Transaction "${token.key}" produced different results on client and server`
118
118
  );
119
- store.logger.error(`\u2757 Client:`, clientResult);
120
- store.logger.error(`\u2757 Server:`, serverResult);
119
+ store.logger.error(
120
+ `\u2757 Client result for "${token.key}":`,
121
+ clientResult
122
+ );
123
+ store.logger.error(
124
+ `\u2757 Server result for "${token.key}:`,
125
+ serverResult
126
+ );
121
127
  } else {
122
- store.logger.info(`\u2705 Transaction ${token.key} results match`);
128
+ store.logger.info(`\u2705 Transaction "${token.key}" results match`);
123
129
  }
124
130
  };
125
131
  socket.on(topic, sync);
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/realtime-state.ts","../src/use-pull.ts","../src/use-pull-family-member.ts","../src/use-pull-mutable.ts","../src/use-pull-mutable-family-member.ts","../src/use-push.ts","../src/use-server-action.ts"],"names":["AtomIO","getJsonToken","getUpdateToken","parseJson","_a"],"mappings":";AAAA,YAAY,YAAY;AAEjB,IAAM,sBAA6B,YAAoB;AAAA,EAC7D,KAAK;AAAA,EACL,SAAS;AACV,CAAC;AACM,IAAM,YAAmB,gBAAwB;AAAA,EACvD,KAAK;AAAA,EACL,KAAK,CAAC,EAAE,IAAI,MAAM,IAAI,mBAAmB;AAC1C,CAAC;;;ACTD,YAAYA,aAAY;AAKjB,SAAS,UACf,OACA,QACA,OACa;AACb,SAAO,GAAG,SAAS,MAAM,GAAG,IAAI,CAAC,SAAS;AACzC,IAAO,iBAAS,OAAO,MAAM,KAAK;AAAA,EACnC,CAAC;AACD,SAAO,KAAK,OAAO,MAAM,GAAG,EAAE;AAC9B,SAAO,MAAM;AACZ,WAAO,IAAI,SAAS,MAAM,GAAG,EAAE;AAC/B,WAAO,KAAK,SAAS,MAAM,GAAG,EAAE;AAAA,EACjC;AACD;;;AClBA,YAAYA,aAAY;AAGxB,SAAS,iBAAiB;AAGnB,SAAS,iBACf,OACA,QACA,OACa;AACb,MAAI,EAAE,YAAY,QAAQ;AACzB,YAAQ,MAAM,iCAAiC,KAAK;AACpD,WAAO,MAAM;AAAA,IAAC;AAAA,EACf;AACA,QAAM,EAAE,KAAK,WAAW,QAAQ,iBAAiB,IAAI,MAAM;AAC3D,QAAM,SAAS,UAAU,gBAAgB;AACzC,mCAAQ,GAAG,SAAS,MAAM,GAAG,IAAI,CAAC,SAAY;AAC7C,IAAO,iBAAS,OAAO,MAAM,KAAK;AAAA,EACnC;A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AAM,OAAO;AAAA,YACZ,uBAAkB,MAAM,GAAG;AAAA,UAC5B;AACA,gBAAM,OAAO,MAAM,kBAAa,YAAY;AAC5C,gBAAM,OAAO,MAAM,kBAAa,YAAY;AAAA,QAC7C,OAAO;AACN,gBAAM,OAAO,KAAK,sBAAiB,MAAM,GAAG,gBAAgB;AAAA,QAC7D;AAAA,MACD;AACA,aAAO,GAAG,OAAO,IAAI;AACrB,aAAO,KAAK,MAAM,MAAM,GAAG,IAAI,cAAc,aAAa;AAAA,IAC3D;AAAA,IACA;AAAA,IACA;AAAA,EACA,IACA,MAAM;AACV,SAAO,MAAM;AAzCd,QAAAI;AA0CE,UAAM,YAAWA,MAAA,QAAQ,IAAI,MAAM,GAAG,MAArB,OAAAA,MAA0B;AAC3C,YAAQ,IAAI,MAAM,KAAK,WAAW,CAAC;AACnC,gBAAY;AAAA,EACb;AACD","sourcesContent":["import * as AtomIO from \"atom.io\"\n\nexport const myIdState__INTERNAL = AtomIO.atom<string | null>({\n\tkey: `myId__INTERNAL`,\n\tdefault: null,\n})\nexport const myIdState = AtomIO.selector<string | null>({\n\tkey: `myId`,\n\tget: ({ get }) => get(myIdState__INTERNAL),\n})\n","import * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullState<J extends Json.Serializable>(\n\ttoken: AtomIO.StateToken<J>,\n\tsocket: Socket,\n\tstore: Store,\n): () => void {\n\tsocket.on(`serve:${token.key}`, (data) => {\n\t\tAtomIO.setState(token, data, store)\n\t})\n\tsocket.emit(`sub:${token.key}`)\n\treturn () => {\n\t\tsocket.off(`serve:${token.key}`)\n\t\tsocket.emit(`unsub:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { parseJson } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullFamilyMember<J extends Json.Serializable>(\n\ttoken: AtomIO.AtomToken<J>,\n\tsocket: Socket,\n\tstore: Store,\n): () => void {\n\tif (!(`family` in token)) {\n\t\tconsole.error(`Token is not a family member:`, token)\n\t\treturn () => {}\n\t}\n\tconst { key: familyKey, subKey: serializedSubKey } = token.family\n\tconst subKey = parseJson(serializedSubKey)\n\tsocket?.on(`serve:${token.key}`, (data: J) => {\n\t\tAtomIO.setState(token, data, store)\n\t})\n\tsocket?.emit(`sub:${familyKey}`, subKey)\n\treturn () => {\n\t\tsocket?.off(`serve:${token.key}`)\n\t\tsocket?.emit(`unsub:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport type { Store, Transceiver } from \"atom.io/internal\"\nimport { getJsonToken, getUpdateToken } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullMutableState<\n\tT extends Transceiver<Json.Serializable>,\n\tJ extends Json.Serializable,\n>(\n\ttoken: AtomIO.MutableAtomToken<T, J>,\n\tsocket: Socket,\n\tstore: Store,\n): () => void {\n\tconst jsonToken = getJsonToken(token)\n\tconst updateToken = getUpdateToken(token)\n\tsocket.on(`init:${token.key}`, (data: J) => {\n\t\tAtomIO.setState(jsonToken, data, store)\n\t})\n\tsocket.on(\n\t\t`next:${token.key}`,\n\t\t(data: T extends Transceiver<infer Update> ? Update : never) => {\n\t\t\tAtomIO.setState(updateToken, data, store)\n\t\t},\n\t)\n\tsocket.emit(`sub:${token.key}`)\n\treturn () => {\n\t\tsocket.off(`init:${token.key}`)\n\t\tsocket.off(`next:${token.key}`)\n\t\tsocket.emit(`unsub:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport { getJsonToken, getUpdateToken } from \"atom.io/internal\"\nimport type { Store, Transceiver } from \"atom.io/internal\"\nimport { parseJson } from \"atom.io/json\"\nimport type { Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullMutableFamilyMember<\n\tT extends Transceiver<Json.Serializable>,\n\tJ extends Json.Serializable,\n>(\n\ttoken: AtomIO.MutableAtomToken<T, J>,\n\tsocket: Socket,\n\tstore: Store,\n): () => void {\n\tif (!(`family` in token)) {\n\t\tconsole.error(`Token is not a family member:`, token)\n\t\treturn () => {}\n\t}\n\tconst { key: familyKey, subKey: serializedSubKey } = token.family\n\tconst subKey = parseJson(serializedSubKey)\n\tsocket?.on(`init:${token.key}`, (data: J) => {\n\t\tconst jsonToken = getJsonToken(token)\n\t\tAtomIO.setState(jsonToken, data, store)\n\t})\n\tsocket?.on(\n\t\t`next:${token.key}`,\n\t\t(data: T extends Transceiver<infer Signal> ? Signal : never) => {\n\t\t\tconst trackerToken = getUpdateToken(token)\n\t\t\tAtomIO.setState(trackerToken, data, store)\n\t\t},\n\t)\n\tsocket?.emit(`sub:${familyKey}`, subKey)\n\treturn () => {\n\t\tsocket?.off(`serve:${token.key}`)\n\t\tsocket?.emit(`unsub:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pushState<J extends Json.Serializable>(\n\ttoken: AtomIO.StateToken<J>,\n\tsocket: Socket,\n\tsubscriptionKey: string,\n\tstore: Store,\n): () => void {\n\tsocket.emit(`claim:${token.key}`)\n\tAtomIO.subscribe(\n\t\ttoken,\n\t\t({ newValue }) => {\n\t\t\tsocket.emit(`pub:${token.key}`, newValue)\n\t\t},\n\t\tsubscriptionKey,\n\t\tstore,\n\t)\n\treturn () => {\n\t\tsocket.off(`pub:${token.key}`)\n\t\tsocket.emit(`unclaim:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport type { Socket } from \"socket.io-client\"\n\nconst TX_SUBS = new Map<string, number>()\nexport function synchronizeTransactionResults(\n\ttoken: AtomIO.TransactionToken<any>,\n\tsocket: Socket,\n\tstore: Store,\n): () => void {\n\tconst count = TX_SUBS.get(token.key) ?? 0\n\tTX_SUBS.set(token.key, count + 1)\n\tconst unsubscribe =\n\t\tcount === 0\n\t\t\t? AtomIO.subscribeToTransaction(\n\t\t\t\t\ttoken,\n\t\t\t\t\t(clientUpdate) => {\n\t\t\t\t\t\tconst transactionId = Math.random().toString(36).slice(2)\n\t\t\t\t\t\tconst clientResult = JSON.stringify(clientUpdate)\n\t\t\t\t\t\tconst topic = `tx:sync:${transactionId}`\n\t\t\t\t\t\tconst sync = (serverUpdate: typeof clientUpdate) => {\n\t\t\t\t\t\t\tstore.logger.info(`♻️ Transaction \"${token.key}\" synced`)\n\t\t\t\t\t\t\tsocket.off(topic, sync)\n\t\t\t\t\t\t\tconst serverResult = JSON.stringify(serverUpdate)\n\t\t\t\t\t\t\tif (clientResult !== serverResult) {\n\t\t\t\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t\t\t\t`❗ Transaction \"${token.key}\" produced different results on client and server`,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tstore.logger.error(`❗ Client:`, clientResult)\n\t\t\t\t\t\t\t\tstore.logger.error(`❗ Server:`, serverResult)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tstore.logger.info(`✅ Transaction ${token.key} results match`)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsocket.on(topic, sync)\n\t\t\t\t\t\tsocket.emit(`tx:${token.key}`, clientUpdate, transactionId)\n\t\t\t\t\t},\n\t\t\t\t\t`use-server-action`,\n\t\t\t\t\tstore,\n\t\t\t )\n\t\t\t: () => null\n\treturn () => {\n\t\tconst newCount = TX_SUBS.get(token.key) ?? 0\n\t\tTX_SUBS.set(token.key, newCount - 1)\n\t\tunsubscribe()\n\t}\n}\n"]}
1
+ {"version":3,"sources":["../src/realtime-state.ts","../src/use-pull.ts","../src/use-pull-family-member.ts","../src/use-pull-mutable.ts","../src/use-pull-mutable-family-member.ts","../src/use-push.ts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AM,GAAG,iBAAiB;AAAA,QAC/D;AAAA,MACD;AACA,aAAO,GAAG,OAAO,IAAI;AACrB,aAAO,KAAK,MAAM,MAAM,GAAG,IAAI,cAAc,aAAa;AAAA,IAC3D;AAAA,IACA;AAAA,IACA;AAAA,EACA,IACA,MAAM;AACV,SAAO,MAAM;AA/Cd,QAAAI;AAgDE,UAAM,YAAWA,MAAA,QAAQ,IAAI,MAAM,GAAG,MAArB,OAAAA,MAA0B;AAC3C,YAAQ,IAAI,MAAM,KAAK,WAAW,CAAC;AACnC,gBAAY;AAAA,EACb;AACD","sourcesContent":["import * as AtomIO from \"atom.io\"\n\nexport const myIdState__INTERNAL = AtomIO.atom<string | null>({\n\tkey: `myId__INTERNAL`,\n\tdefault: null,\n})\nexport const myIdState = AtomIO.selector<string | null>({\n\tkey: `myId`,\n\tget: ({ get }) => get(myIdState__INTERNAL),\n})\n","import * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullState<J extends Json.Serializable>(\n\ttoken: AtomIO.StateToken<J>,\n\tsocket: Socket,\n\tstore: Store,\n): () => void {\n\tsocket.on(`serve:${token.key}`, (data) => {\n\t\tAtomIO.setState(token, data, store)\n\t})\n\tsocket.emit(`sub:${token.key}`)\n\treturn () => {\n\t\tsocket.off(`serve:${token.key}`)\n\t\tsocket.emit(`unsub:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { parseJson } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullFamilyMember<J extends Json.Serializable>(\n\ttoken: AtomIO.AtomToken<J>,\n\tsocket: Socket,\n\tstore: Store,\n): () => void {\n\tif (!(`family` in token)) {\n\t\tconsole.error(`Token is not a family member:`, token)\n\t\treturn () => {}\n\t}\n\tconst { key: familyKey, subKey: serializedSubKey } = token.family\n\tconst subKey = parseJson(serializedSubKey)\n\tsocket?.on(`serve:${token.key}`, (data: J) => {\n\t\tAtomIO.setState(token, data, store)\n\t})\n\tsocket?.emit(`sub:${familyKey}`, subKey)\n\treturn () => {\n\t\tsocket?.off(`serve:${token.key}`)\n\t\tsocket?.emit(`unsub:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport type { Store, Transceiver } from \"atom.io/internal\"\nimport { getJsonToken, getUpdateToken } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullMutableState<\n\tT extends Transceiver<Json.Serializable>,\n\tJ extends Json.Serializable,\n>(\n\ttoken: AtomIO.MutableAtomToken<T, J>,\n\tsocket: Socket,\n\tstore: Store,\n): () => void {\n\tconst jsonToken = getJsonToken(token)\n\tconst updateToken = getUpdateToken(token)\n\tsocket.on(`init:${token.key}`, (data: J) => {\n\t\tAtomIO.setState(jsonToken, data, store)\n\t})\n\tsocket.on(\n\t\t`next:${token.key}`,\n\t\t(data: T extends Transceiver<infer Update> ? Update : never) => {\n\t\t\tAtomIO.setState(updateToken, data, store)\n\t\t},\n\t)\n\tsocket.emit(`sub:${token.key}`)\n\treturn () => {\n\t\tsocket.off(`init:${token.key}`)\n\t\tsocket.off(`next:${token.key}`)\n\t\tsocket.emit(`unsub:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport { getJsonToken, getUpdateToken } from \"atom.io/internal\"\nimport type { Store, Transceiver } from \"atom.io/internal\"\nimport { parseJson } from \"atom.io/json\"\nimport type { Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pullMutableFamilyMember<\n\tT extends Transceiver<Json.Serializable>,\n\tJ extends Json.Serializable,\n>(\n\ttoken: AtomIO.MutableAtomToken<T, J>,\n\tsocket: Socket,\n\tstore: Store,\n): () => void {\n\tif (!(`family` in token)) {\n\t\tconsole.error(`Token is not a family member:`, token)\n\t\treturn () => {}\n\t}\n\tconst { key: familyKey, subKey: serializedSubKey } = token.family\n\tconst subKey = parseJson(serializedSubKey)\n\tsocket?.on(`init:${token.key}`, (data: J) => {\n\t\tconst jsonToken = getJsonToken(token)\n\t\tAtomIO.setState(jsonToken, data, store)\n\t})\n\tsocket?.on(\n\t\t`next:${token.key}`,\n\t\t(data: T extends Transceiver<infer Signal> ? Signal : never) => {\n\t\t\tconst trackerToken = getUpdateToken(token)\n\t\t\tAtomIO.setState(trackerToken, data, store)\n\t\t},\n\t)\n\tsocket?.emit(`sub:${familyKey}`, subKey)\n\treturn () => {\n\t\tsocket?.off(`serve:${token.key}`)\n\t\tsocket?.emit(`unsub:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport type { Socket } from \"socket.io-client\"\n\nexport function pushState<J extends Json.Serializable>(\n\ttoken: AtomIO.StateToken<J>,\n\tsocket: Socket,\n\tsubscriptionKey: string,\n\tstore: Store,\n): () => void {\n\tsocket.emit(`claim:${token.key}`)\n\tAtomIO.subscribe(\n\t\ttoken,\n\t\t({ newValue }) => {\n\t\t\tsocket.emit(`pub:${token.key}`, newValue)\n\t\t},\n\t\tsubscriptionKey,\n\t\tstore,\n\t)\n\treturn () => {\n\t\tsocket.off(`pub:${token.key}`)\n\t\tsocket.emit(`unclaim:${token.key}`)\n\t}\n}\n","import * as AtomIO from \"atom.io\"\nimport type { Store } from \"atom.io/internal\"\nimport type { Socket } from \"socket.io-client\"\n\nconst TX_SUBS = new Map<string, number>()\nexport function synchronizeTransactionResults(\n\ttoken: AtomIO.TransactionToken<any>,\n\tsocket: Socket,\n\tstore: Store,\n): () => void {\n\tconst count = TX_SUBS.get(token.key) ?? 0\n\tTX_SUBS.set(token.key, count + 1)\n\tconst unsubscribe =\n\t\tcount === 0\n\t\t\t? AtomIO.subscribeToTransaction(\n\t\t\t\t\ttoken,\n\t\t\t\t\t(clientUpdate) => {\n\t\t\t\t\t\tconst transactionId = Math.random().toString(36).slice(2)\n\t\t\t\t\t\tconst clientResult = JSON.stringify(clientUpdate)\n\t\t\t\t\t\tconst topic = `tx:sync:${transactionId}`\n\t\t\t\t\t\tconst sync = (serverUpdate: typeof clientUpdate) => {\n\t\t\t\t\t\t\tstore.logger.info(`♻️ Transaction \"${token.key}\" synced`)\n\t\t\t\t\t\t\tsocket.off(topic, sync)\n\t\t\t\t\t\t\tconst serverResult = JSON.stringify(serverUpdate)\n\t\t\t\t\t\t\tif (clientResult !== serverResult) {\n\t\t\t\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t\t\t\t`❗ Transaction \"${token.key}\" produced different results on client and server`,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t\t\t\t`❗ Client result for \"${token.key}\":`,\n\t\t\t\t\t\t\t\t\tclientResult,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\tstore.logger.error(\n\t\t\t\t\t\t\t\t\t`❗ Server result for \"${token.key}:`,\n\t\t\t\t\t\t\t\t\tserverResult,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tstore.logger.info(`✅ Transaction \"${token.key}\" results match`)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsocket.on(topic, sync)\n\t\t\t\t\t\tsocket.emit(`tx:${token.key}`, clientUpdate, transactionId)\n\t\t\t\t\t},\n\t\t\t\t\t`use-server-action`,\n\t\t\t\t\tstore,\n\t\t\t )\n\t\t\t: () => null\n\treturn () => {\n\t\tconst newCount = TX_SUBS.get(token.key) ?? 0\n\t\tTX_SUBS.set(token.key, newCount - 1)\n\t\tunsubscribe()\n\t}\n}\n"]}
@@ -26,10 +26,16 @@ export function synchronizeTransactionResults(
26
26
  store.logger.error(
27
27
  `❗ Transaction "${token.key}" produced different results on client and server`,
28
28
  )
29
- store.logger.error(`❗ Client:`, clientResult)
30
- store.logger.error(`❗ Server:`, serverResult)
29
+ store.logger.error(
30
+ `❗ Client result for "${token.key}":`,
31
+ clientResult,
32
+ )
33
+ store.logger.error(
34
+ `❗ Server result for "${token.key}:`,
35
+ serverResult,
36
+ )
31
37
  } else {
32
- store.logger.info(`✅ Transaction ${token.key} results match`)
38
+ store.logger.info(`✅ Transaction "${token.key}" results match`)
33
39
  }
34
40
  }
35
41
  socket.on(topic, sync)
package/src/subscribe.ts CHANGED
@@ -32,19 +32,21 @@ export function subscribe<T>(
32
32
  )
33
33
  }
34
34
  const unsubFunction = state.subject.subscribe(key, handleUpdate)
35
- store.logger.info(`👀 adding subscription "${key}" to "${state.key}"`)
35
+ store.logger.info(`👀 Adding subscription "${key}" to "${state.key}"`)
36
36
  const dependencyUnsubFunctions =
37
37
  state.type !== `atom` ? subscribeToRootAtoms(state, store) : null
38
38
 
39
39
  const unsubscribe =
40
40
  dependencyUnsubFunctions === null
41
41
  ? () => {
42
- store.logger.info(`🙈 unsubscribe from "${state.key}"`)
42
+ store.logger.info(
43
+ `🙈 Removing subscription "${key}" from "${state.key}"`,
44
+ )
43
45
  unsubFunction()
44
46
  }
45
47
  : () => {
46
48
  store.logger.info(
47
- `🙈 unsubscribe from "${state.key}" and its dependencies`,
49
+ `🙈 Removing subscription ${key} from "${state.key}" and its dependencies`,
48
50
  )
49
51
  unsubFunction()
50
52
  for (const unsubFromDependency of dependencyUnsubFunctions) {
@@ -71,10 +73,14 @@ export const subscribeToTransaction = <ƒ extends ƒn>(
71
73
  `Cannot subscribe to transaction "${token.key}": transaction not found in store "${store.config.name}".`,
72
74
  )
73
75
  }
74
- store.logger.info(`👀 subscribe to transaction "${token.key}"`)
76
+ store.logger.info(
77
+ `👀 Adding subscription "${key}" to transaction "${token.key}"`,
78
+ )
75
79
  const unsubscribe = tx.subject.subscribe(key, handleUpdate)
76
80
  return () => {
77
- store.logger.info(`🙈 unsubscribe from transaction "${token.key}"`)
81
+ store.logger.info(
82
+ `🙈 Removing subscription "${key}" from transaction "${token.key}"`,
83
+ )
78
84
  unsubscribe()
79
85
  }
80
86
  }
@@ -91,10 +97,12 @@ export const subscribeToTimeline = (
91
97
  `Cannot subscribe to timeline "${token.key}": timeline not found in store "${store.config.name}".`,
92
98
  )
93
99
  }
94
- store.logger.info(`👀 subscribe to timeline "${token.key}"`)
100
+ store.logger.info(`👀 Adding subscription "${key}" to timeline "${token.key}"`)
95
101
  const unsubscribe = tl.subject.subscribe(key, handleUpdate)
96
102
  return () => {
97
- store.logger.info(`🙈 unsubscribe from timeline "${token.key}"`)
103
+ store.logger.info(
104
+ `🙈 Removing subscription "${key}" from timeline "${token.key}"`,
105
+ )
98
106
  unsubscribe()
99
107
  }
100
108
  }