atom.io 0.14.0 → 0.14.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.
Files changed (133) hide show
  1. package/data/dist/index.cjs +1421 -52
  2. package/data/dist/index.cjs.map +1 -1
  3. package/data/dist/index.d.cts +317 -16
  4. package/data/dist/index.js +10 -267
  5. package/data/dist/index.js.map +1 -1
  6. package/data/package.json +5 -5
  7. package/data/src/join.ts +3 -3
  8. package/dist/chunk-C4YZZNRH.js +67 -0
  9. package/dist/chunk-C4YZZNRH.js.map +1 -0
  10. package/dist/chunk-CWKKQKVQ.js +68 -0
  11. package/dist/chunk-CWKKQKVQ.js.map +1 -0
  12. package/dist/chunk-GMN5KH6A.js +309 -0
  13. package/dist/chunk-GMN5KH6A.js.map +1 -0
  14. package/dist/chunk-N7ADBQJG.js +176 -0
  15. package/dist/chunk-N7ADBQJG.js.map +1 -0
  16. package/dist/chunk-NYCVSXQB.js +181 -0
  17. package/dist/chunk-NYCVSXQB.js.map +1 -0
  18. package/dist/chunk-PURABO5G.js +2581 -0
  19. package/dist/chunk-PURABO5G.js.map +1 -0
  20. package/dist/index.cjs +2330 -55
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.cts +272 -22
  23. package/dist/index.js +1 -152
  24. package/dist/index.js.map +1 -1
  25. package/dist/metafile-cjs.json +1 -1
  26. package/internal/dist/index.cjs +299 -106
  27. package/internal/dist/index.cjs.map +1 -1
  28. package/internal/dist/index.d.cts +231 -30
  29. package/internal/dist/index.js +1 -2240
  30. package/internal/dist/index.js.map +1 -1
  31. package/internal/package.json +5 -5
  32. package/internal/src/atom/create-atom.ts +3 -1
  33. package/internal/src/families/create-atom-family.ts +3 -4
  34. package/internal/src/mutable/get-update-family.ts +23 -0
  35. package/internal/src/mutable/index.ts +1 -4
  36. package/internal/src/mutable/is-mutable.ts +44 -0
  37. package/internal/src/mutable/tracker.ts +9 -2
  38. package/internal/src/subject.ts +2 -1
  39. package/internal/src/timeline/add-atom-to-timeline.ts +10 -1
  40. package/internal/src/timeline/create-timeline.ts +44 -16
  41. package/introspection/dist/index.cjs +1566 -46
  42. package/introspection/dist/index.cjs.map +1 -1
  43. package/introspection/dist/index.d.cts +376 -4
  44. package/introspection/dist/index.js +2 -316
  45. package/introspection/dist/index.js.map +1 -1
  46. package/introspection/package.json +5 -5
  47. package/json/dist/index.cjs +1505 -8
  48. package/json/dist/index.cjs.map +1 -1
  49. package/json/dist/index.d.cts +373 -7
  50. package/json/dist/index.js +1 -76
  51. package/json/dist/index.js.map +1 -1
  52. package/json/package.json +5 -5
  53. package/package.json +5 -4
  54. package/react/dist/index.cjs +1549 -14
  55. package/react/dist/index.cjs.map +1 -1
  56. package/react/dist/index.d.cts +377 -4
  57. package/react/dist/index.js +2 -68
  58. package/react/dist/index.js.map +1 -1
  59. package/react/package.json +5 -5
  60. package/react-devtools/dist/index.cjs +2216 -198
  61. package/react-devtools/dist/index.cjs.map +1 -1
  62. package/react-devtools/dist/index.css +2 -2
  63. package/react-devtools/dist/index.d.cts +150 -24
  64. package/react-devtools/dist/index.js +57 -297
  65. package/react-devtools/dist/index.js.map +1 -1
  66. package/react-devtools/package.json +5 -5
  67. package/realtime-client/dist/index.cjs +1530 -35
  68. package/realtime-client/dist/index.cjs.map +1 -1
  69. package/realtime-client/dist/index.d.cts +384 -12
  70. package/realtime-client/dist/index.js +2 -165
  71. package/realtime-client/dist/index.js.map +1 -1
  72. package/realtime-client/package.json +5 -5
  73. package/realtime-react/dist/index.cjs +1727 -35
  74. package/realtime-react/dist/index.cjs.map +1 -1
  75. package/realtime-react/dist/index.d.cts +49 -9
  76. package/realtime-react/dist/index.js +4 -66
  77. package/realtime-react/dist/index.js.map +1 -1
  78. package/realtime-react/package.json +5 -5
  79. package/realtime-server/dist/index.cjs +1549 -58
  80. package/realtime-server/dist/index.cjs.map +1 -1
  81. package/realtime-server/dist/index.d.cts +394 -11
  82. package/realtime-server/dist/index.js +27 -21
  83. package/realtime-server/dist/index.js.map +1 -1
  84. package/realtime-server/package.json +6 -6
  85. package/realtime-testing/dist/index.cjs +2377 -16
  86. package/realtime-testing/dist/index.cjs.map +1 -1
  87. package/realtime-testing/dist/index.d.cts +489 -3
  88. package/realtime-testing/dist/index.js +10 -31
  89. package/realtime-testing/dist/index.js.map +1 -1
  90. package/realtime-testing/package.json +5 -5
  91. package/src/atom.ts +3 -1
  92. package/transceivers/set-rtx/dist/index.cjs +32 -10
  93. package/transceivers/set-rtx/dist/index.cjs.map +1 -1
  94. package/transceivers/set-rtx/dist/index.d.cts +29 -3
  95. package/transceivers/set-rtx/dist/index.js +2 -3
  96. package/transceivers/set-rtx/dist/index.js.map +1 -1
  97. package/transceivers/set-rtx/package.json +6 -6
  98. package/data/dist/index.d.ts +0 -158
  99. package/data/dist/metafile-cjs.json +0 -1
  100. package/data/dist/metafile-esm.json +0 -1
  101. package/dist/index.d.ts +0 -243
  102. package/dist/metafile-esm.json +0 -1
  103. package/internal/dist/index.d.ts +0 -421
  104. package/internal/dist/metafile-cjs.json +0 -1
  105. package/internal/dist/metafile-esm.json +0 -1
  106. package/internal/src/mutable/is-atom-token-mutable.ts +0 -7
  107. package/introspection/dist/index.d.ts +0 -24
  108. package/introspection/dist/metafile-cjs.json +0 -1
  109. package/introspection/dist/metafile-esm.json +0 -1
  110. package/json/dist/index.d.ts +0 -51
  111. package/json/dist/metafile-cjs.json +0 -1
  112. package/json/dist/metafile-esm.json +0 -1
  113. package/react/dist/index.d.ts +0 -23
  114. package/react/dist/metafile-cjs.json +0 -1
  115. package/react/dist/metafile-esm.json +0 -1
  116. package/react-devtools/dist/index.d.ts +0 -341
  117. package/react-devtools/dist/metafile-cjs.json +0 -1
  118. package/react-devtools/dist/metafile-esm.json +0 -1
  119. package/realtime-client/dist/index.d.ts +0 -22
  120. package/realtime-client/dist/metafile-cjs.json +0 -1
  121. package/realtime-client/dist/metafile-esm.json +0 -1
  122. package/realtime-react/dist/index.d.ts +0 -27
  123. package/realtime-react/dist/metafile-cjs.json +0 -1
  124. package/realtime-react/dist/metafile-esm.json +0 -1
  125. package/realtime-server/dist/index.d.ts +0 -25
  126. package/realtime-server/dist/metafile-cjs.json +0 -1
  127. package/realtime-server/dist/metafile-esm.json +0 -1
  128. package/realtime-testing/dist/index.d.ts +0 -49
  129. package/realtime-testing/dist/metafile-cjs.json +0 -1
  130. package/realtime-testing/dist/metafile-esm.json +0 -1
  131. package/transceivers/set-rtx/dist/index.d.ts +0 -40
  132. package/transceivers/set-rtx/dist/metafile-cjs.json +0 -1
  133. package/transceivers/set-rtx/dist/metafile-esm.json +0 -1
@@ -1,34 +1,1515 @@
1
1
  'use strict';
2
2
 
3
- var AtomIO4 = require('atom.io');
4
- var Internal = require('atom.io/internal');
5
- var json = require('atom.io/json');
6
-
7
- function _interopNamespace(e) {
8
- if (e && e.__esModule) return e;
9
- var n = Object.create(null);
10
- if (e) {
11
- Object.keys(e).forEach(function (k) {
12
- if (k !== 'default') {
13
- var d = Object.getOwnPropertyDescriptor(e, k);
14
- Object.defineProperty(n, k, d.get ? d : {
15
- enumerable: true,
16
- get: function () { return e[k]; }
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
+
23
+ // internal/src/future.ts
24
+ var Future = class extends Promise {
25
+ constructor(executor) {
26
+ super((resolve, reject) => {
27
+ const pass = (value) => this.isCanceled ? reject(`canceled`) : resolve(value);
28
+ const fail = (reason) => this.isCanceled ? reject(`canceled`) : reject(reason);
29
+ if (typeof executor === `function`) {
30
+ executor(pass, fail);
31
+ } else {
32
+ executor.then(pass, fail);
33
+ }
34
+ });
35
+ this.isCanceled = false;
36
+ }
37
+ cancel() {
38
+ this.isCanceled = true;
39
+ }
40
+ };
41
+
42
+ // internal/src/lineage.ts
43
+ function newest(scion) {
44
+ while (scion.child !== null) {
45
+ scion = scion.child;
46
+ }
47
+ return scion;
48
+ }
49
+
50
+ // internal/src/caching.ts
51
+ function cacheValue(key, value, subject, store) {
52
+ const target = newest(store);
53
+ const currentValue = target.valueMap.get(key);
54
+ if (currentValue instanceof Future) {
55
+ currentValue.cancel();
56
+ }
57
+ if (value instanceof Promise) {
58
+ const future = new Future(value);
59
+ newest(store).valueMap.set(key, future);
60
+ future.then((resolved) => {
61
+ if (future.isCanceled) {
62
+ return;
63
+ }
64
+ cacheValue(key, resolved, subject, store);
65
+ subject.next({ newValue: resolved, oldValue: future });
66
+ }).catch((thrown) => {
67
+ if (thrown !== `canceled`) {
68
+ store.logger.error(`\u{1F4A5}`, `state`, key, `rejected:`, thrown);
69
+ }
70
+ });
71
+ return future;
72
+ }
73
+ target.valueMap.set(key, value);
74
+ return value;
75
+ }
76
+ var readCachedValue = (key, store) => {
77
+ return newest(store).valueMap.get(key);
78
+ };
79
+ var isValueCached = (key, store) => {
80
+ return newest(store).valueMap.has(key);
81
+ };
82
+ var evictCachedValue = (key, store) => {
83
+ const core = newest(store);
84
+ const currentValue = core.valueMap.get(key);
85
+ if (currentValue instanceof Future) {
86
+ currentValue.cancel();
87
+ }
88
+ if (core.operation.open) {
89
+ core.operation.prev.set(key, currentValue);
90
+ }
91
+ core.valueMap.delete(key);
92
+ store.logger.info(`\u{1F5D1}`, `state`, key, `evicted`);
93
+ };
94
+
95
+ // ../anvl/src/json/index.ts
96
+ var parseJson = (str) => JSON.parse(str);
97
+
98
+ // json/src/select-json.ts
99
+ var selectJson = (atom, transform, store = IMPLICIT.STORE) => {
100
+ return createSelector(
101
+ {
102
+ key: `${atom.key}:JSON`,
103
+ get: ({ get }) => transform.toJson(get(atom)),
104
+ set: ({ set }, newValue) => set(atom, transform.fromJson(newValue))
105
+ },
106
+ void 0,
107
+ store
108
+ );
109
+ };
110
+
111
+ // internal/src/read-or-compute-value.ts
112
+ var readOrComputeValue = (state, store) => {
113
+ if (isValueCached(state.key, store)) {
114
+ store.logger.info(`\u{1F4D6}`, state.type, state.key, `reading cached value`);
115
+ return readCachedValue(state.key, store);
116
+ }
117
+ if (state.type !== `atom`) {
118
+ store.logger.info(`\u{1F9EE}`, state.type, state.key, `computing value`);
119
+ return state.get();
120
+ }
121
+ const fallback = state.default instanceof Function ? state.default() : state.default;
122
+ store.logger.info(
123
+ `\u{1F481}`,
124
+ `atom`,
125
+ state.key,
126
+ `could not find cached value; using default`,
127
+ fallback
128
+ );
129
+ return state.default instanceof Function ? state.default() : state.default;
130
+ };
131
+
132
+ // internal/src/operation.ts
133
+ var openOperation = (token, store) => {
134
+ const target = newest(store);
135
+ if (target.operation.open) {
136
+ store.logger.error(
137
+ `\u274C`,
138
+ token.type,
139
+ token.key,
140
+ `failed to setState during a setState for "${target.operation.token.key}"`
141
+ );
142
+ return `rejection`;
143
+ }
144
+ target.operation = {
145
+ open: true,
146
+ done: /* @__PURE__ */ new Set(),
147
+ prev: /* @__PURE__ */ new Map(),
148
+ time: Date.now(),
149
+ token
150
+ };
151
+ store.logger.info(
152
+ `\u2B55`,
153
+ token.type,
154
+ token.key,
155
+ `operation start in store "${store.config.name}"${target.transactionMeta === null ? `` : ` ${target.transactionMeta.phase} "${target.transactionMeta.update.key}"`}`
156
+ );
157
+ };
158
+ var closeOperation = (store) => {
159
+ const target = newest(store);
160
+ if (target.operation.open) {
161
+ store.logger.info(
162
+ `\u{1F534}`,
163
+ target.operation.token.type,
164
+ target.operation.token.key,
165
+ `operation done in store "${store.config.name}"`
166
+ );
167
+ }
168
+ target.operation = { open: false };
169
+ store.subject.operationStatus.next(target.operation);
170
+ };
171
+ var isDone = (key, store) => {
172
+ const target = newest(store);
173
+ if (!target.operation.open) {
174
+ store.logger.warn(
175
+ `\u{1F41E}`,
176
+ `unknown`,
177
+ key,
178
+ `isDone called outside of an operation. This is probably a bug.`
179
+ );
180
+ return true;
181
+ }
182
+ return target.operation.done.has(key);
183
+ };
184
+ var markDone = (key, store) => {
185
+ const target = newest(store);
186
+ if (!target.operation.open) {
187
+ store.logger.warn(
188
+ `\u{1F41E}`,
189
+ `unknown`,
190
+ key,
191
+ `markDone called outside of an operation. This is probably a bug.`
192
+ );
193
+ return;
194
+ }
195
+ target.operation.done.add(key);
196
+ };
197
+
198
+ // internal/src/set-state/become.ts
199
+ var become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing instanceof Function ? nextVersionOfThing(
200
+ originalThing instanceof Function ? originalThing() : originalThing
201
+ ) : nextVersionOfThing;
202
+
203
+ // internal/src/subject.ts
204
+ var Subject = class {
205
+ constructor() {
206
+ this.subscribers = /* @__PURE__ */ new Map();
207
+ }
208
+ subscribe(key, subscriber) {
209
+ this.subscribers.set(key, subscriber);
210
+ const unsubscribe = () => this.unsubscribe(key);
211
+ return unsubscribe;
212
+ }
213
+ unsubscribe(key) {
214
+ this.subscribers.delete(key);
215
+ }
216
+ next(value) {
217
+ const subscribers = this.subscribers.values();
218
+ for (const subscriber of subscribers) {
219
+ subscriber(value);
220
+ }
221
+ }
222
+ };
223
+ var StatefulSubject = class extends Subject {
224
+ constructor(initialState) {
225
+ super();
226
+ this.state = initialState;
227
+ }
228
+ next(value) {
229
+ this.state = value;
230
+ super.next(value);
231
+ }
232
+ };
233
+
234
+ // internal/src/set-state/copy-mutable-if-needed.ts
235
+ function copyMutableIfNeeded(atom, transform, origin, target) {
236
+ const originValue = origin.valueMap.get(atom.key);
237
+ const targetValue = target.valueMap.get(atom.key);
238
+ if (originValue === targetValue) {
239
+ origin.logger.info(`\u{1F4C3}`, `atom`, `${atom.key}`, `copying`);
240
+ const jsonValue = transform.toJson(originValue);
241
+ const copiedValue = transform.fromJson(jsonValue);
242
+ target.valueMap.set(atom.key, copiedValue);
243
+ new Tracker(atom, origin);
244
+ return copiedValue;
245
+ }
246
+ return targetValue;
247
+ }
248
+
249
+ // internal/src/set-state/copy-mutable-in-transaction.ts
250
+ function copyMutableIfWithinTransaction(oldValue, atom, store) {
251
+ const target = newest(store);
252
+ const parent = target.parent;
253
+ if (parent !== null) {
254
+ if (`toJson` in atom && `fromJson` in atom) {
255
+ const copiedValue = copyMutableIfNeeded(atom, atom, parent, target);
256
+ return copiedValue;
257
+ }
258
+ if (`family` in atom) {
259
+ const family = parent.families.get(atom.family.key);
260
+ if (family && family.type === `atom_family`) {
261
+ const result = copyMutableFamilyMemberWithinTransaction(
262
+ atom,
263
+ family,
264
+ parent,
265
+ target
266
+ );
267
+ if (result) {
268
+ return result;
269
+ }
270
+ }
271
+ }
272
+ }
273
+ return oldValue;
274
+ }
275
+ function copyMutableFamilyMemberWithinTransaction(atom, family, origin, target) {
276
+ if (`toJson` in family && `fromJson` in family) {
277
+ const copyCreated = copyMutableIfNeeded(atom, family, origin, target);
278
+ return copyCreated;
279
+ }
280
+ return null;
281
+ }
282
+
283
+ // internal/src/set-state/emit-update.ts
284
+ var emitUpdate = (state, update, store) => {
285
+ store.logger.info(
286
+ `\u{1F4E2}`,
287
+ state.type,
288
+ state.key,
289
+ `went (`,
290
+ update.oldValue,
291
+ `->`,
292
+ update.newValue,
293
+ `) subscribers:`,
294
+ state.subject.subscribers
295
+ );
296
+ state.subject.next(update);
297
+ };
298
+
299
+ // internal/src/set-state/evict-downstream.ts
300
+ var evictDownStream = (atom, store) => {
301
+ const target = newest(store);
302
+ const downstreamKeys = target.selectorAtoms.getRelatedKeys(atom.key);
303
+ store.logger.info(
304
+ `\u{1F9F9}`,
305
+ atom.type,
306
+ atom.key,
307
+ downstreamKeys ? `evicting ${downstreamKeys.size} states downstream:` : `no downstream states`,
308
+ downstreamKeys != null ? downstreamKeys : `to evict`
309
+ );
310
+ if (downstreamKeys) {
311
+ if (target.operation.open) {
312
+ store.logger.info(
313
+ `\u{1F9F9}`,
314
+ atom.type,
315
+ atom.key,
316
+ `[ ${[...target.operation.done].join(`, `)} ] already done`
317
+ );
318
+ }
319
+ for (const key of downstreamKeys) {
320
+ if (isDone(key, store)) {
321
+ continue;
322
+ }
323
+ evictCachedValue(key, store);
324
+ markDone(key, store);
325
+ }
326
+ }
327
+ };
328
+
329
+ // internal/src/set-state/stow-update.ts
330
+ function shouldUpdateBeStowed(key, update) {
331
+ if (isTransceiver(update.newValue)) {
332
+ return false;
333
+ }
334
+ if (key.includes(`\u{1F441}\u200D\u{1F5E8}`)) {
335
+ return false;
336
+ }
337
+ return true;
338
+ }
339
+ var stowUpdate = (state, update, store) => {
340
+ const { key } = state;
341
+ const target = newest(store);
342
+ if (target.transactionMeta === null || target.transactionMeta.phase !== `building`) {
343
+ store.logger.error(
344
+ `\u{1F41E}`,
345
+ `atom`,
346
+ key,
347
+ `stowUpdate called outside of a transaction. This is probably a bug.`
348
+ );
349
+ return;
350
+ }
351
+ const shouldStow = shouldUpdateBeStowed(key, update);
352
+ if (!shouldStow) {
353
+ return;
354
+ }
355
+ const atomUpdate = __spreadValues({ key }, update);
356
+ if (state.family) {
357
+ atomUpdate.family = state.family;
358
+ }
359
+ target.transactionMeta.update.updates.push(atomUpdate);
360
+ store.logger.info(
361
+ `\u{1F4C1}`,
362
+ `atom`,
363
+ key,
364
+ `stowed (`,
365
+ update.oldValue,
366
+ `->`,
367
+ update.newValue,
368
+ `)`
369
+ );
370
+ };
371
+
372
+ // internal/src/set-state/set-atom.ts
373
+ var setAtom = (atom, next, store) => {
374
+ const target = newest(store);
375
+ const oldValue = readOrComputeValue(atom, store);
376
+ let newValue = copyMutableIfWithinTransaction(oldValue, atom, store);
377
+ newValue = become(next)(newValue);
378
+ store.logger.info(`\u{1F4DD}`, `atom`, atom.key, `set to`, newValue);
379
+ newValue = cacheValue(atom.key, newValue, atom.subject, store);
380
+ if (isAtomDefault(atom.key, store)) {
381
+ markAtomAsNotDefault(atom.key, store);
382
+ }
383
+ markDone(atom.key, store);
384
+ evictDownStream(atom, store);
385
+ const update = { oldValue, newValue };
386
+ if (target.transactionMeta === null || target.transactionMeta.phase === `applying`) {
387
+ emitUpdate(atom, update, store);
388
+ } else {
389
+ stowUpdate(atom, update, store);
390
+ }
391
+ };
392
+
393
+ // internal/src/set-state/set-atom-or-selector.ts
394
+ var setAtomOrSelector = (state, value, store) => {
395
+ if (state.type === `selector`) {
396
+ state.set(value);
397
+ } else {
398
+ setAtom(state, value, store);
399
+ }
400
+ };
401
+
402
+ // internal/src/store/deposit.ts
403
+ function deposit(state) {
404
+ const token = {
405
+ key: state.key,
406
+ type: state.type
407
+ };
408
+ if (`family` in state) {
409
+ token.family = state.family;
410
+ }
411
+ return token;
412
+ }
413
+
414
+ // ../rel8/junction/src/junction.ts
415
+ var Junction = class {
416
+ constructor(data, config) {
417
+ this.relations = /* @__PURE__ */ new Map();
418
+ this.contents = /* @__PURE__ */ new Map();
419
+ this.makeContentKey = (a, b) => `${a}:${b}`;
420
+ var _a, _b, _c, _d;
421
+ this.a = data.between[0];
422
+ this.b = data.between[1];
423
+ this.cardinality = data.cardinality;
424
+ if (!(config == null ? void 0 : config.externalStore)) {
425
+ this.relations = new Map((_a = data.relations) == null ? void 0 : _a.map(([a, b]) => [a, new Set(b)]));
426
+ this.contents = new Map(data.contents);
427
+ }
428
+ this.isContent = (_b = config == null ? void 0 : config.isContent) != null ? _b : null;
429
+ if (config == null ? void 0 : config.makeContentKey) {
430
+ this.makeContentKey = config.makeContentKey;
431
+ }
432
+ if (config == null ? void 0 : config.externalStore) {
433
+ const externalStore = config.externalStore;
434
+ this.has = (a, b) => externalStore.has(a, b);
435
+ this.addRelation = (a, b) => {
436
+ externalStore.addRelation(a, b);
437
+ };
438
+ this.deleteRelation = (a, b) => {
439
+ externalStore.deleteRelation(a, b);
440
+ };
441
+ this.replaceRelationsSafely = (a, bs) => {
442
+ externalStore.replaceRelationsSafely(a, bs);
443
+ };
444
+ this.replaceRelationsUnsafely = (a, bs) => {
445
+ externalStore.replaceRelationsUnsafely(a, bs);
446
+ };
447
+ this.getRelatedKeys = (key) => externalStore.getRelatedKeys(key);
448
+ if (externalStore.getContent) {
449
+ this.getContentInternal = (contentKey) => {
450
+ return externalStore.getContent(contentKey);
451
+ };
452
+ this.setContent = (contentKey, content) => {
453
+ externalStore.setContent(contentKey, content);
454
+ };
455
+ this.deleteContent = (contentKey) => {
456
+ externalStore.deleteContent(contentKey);
457
+ };
458
+ }
459
+ for (const [x, ys] of (_c = data.relations) != null ? _c : []) {
460
+ for (const y of ys)
461
+ this.addRelation(x, y);
462
+ }
463
+ for (const [contentKey, content] of (_d = data.contents) != null ? _d : []) {
464
+ this.setContent(contentKey, content);
465
+ }
466
+ }
467
+ }
468
+ getRelatedKeys(key) {
469
+ return this.relations.get(key);
470
+ }
471
+ addRelation(a, b) {
472
+ let aRelations = this.relations.get(a);
473
+ let bRelations = this.relations.get(b);
474
+ if (aRelations) {
475
+ aRelations.add(b);
476
+ } else {
477
+ aRelations = /* @__PURE__ */ new Set([b]);
478
+ this.relations.set(a, aRelations);
479
+ }
480
+ if (bRelations) {
481
+ bRelations.add(a);
482
+ } else {
483
+ bRelations = /* @__PURE__ */ new Set([a]);
484
+ this.relations.set(b, bRelations);
485
+ }
486
+ }
487
+ deleteRelation(a, b) {
488
+ const aRelations = this.relations.get(a);
489
+ if (aRelations) {
490
+ aRelations.delete(b);
491
+ if (aRelations.size === 0) {
492
+ this.relations.delete(a);
493
+ }
494
+ const bRelations = this.relations.get(b);
495
+ if (bRelations) {
496
+ bRelations.delete(a);
497
+ if (bRelations.size === 0) {
498
+ this.relations.delete(b);
499
+ }
500
+ }
501
+ }
502
+ }
503
+ replaceRelationsUnsafely(a, bs) {
504
+ this.relations.set(a, new Set(bs));
505
+ for (const b of bs) {
506
+ const bRelations = /* @__PURE__ */ new Set([a]);
507
+ this.relations.set(b, bRelations);
508
+ }
509
+ }
510
+ replaceRelationsSafely(a, bs) {
511
+ const aRelationsPrev = this.relations.get(a);
512
+ if (aRelationsPrev) {
513
+ for (const b of aRelationsPrev) {
514
+ const bRelations = this.relations.get(b);
515
+ if (bRelations) {
516
+ if (bRelations.size === 1) {
517
+ this.relations.delete(b);
518
+ } else {
519
+ bRelations.delete(a);
520
+ }
521
+ this.contents.delete(this.makeContentKey(a, b));
522
+ }
523
+ }
524
+ }
525
+ this.relations.set(a, new Set(bs));
526
+ for (const b of bs) {
527
+ let bRelations = this.relations.get(b);
528
+ if (bRelations) {
529
+ bRelations.add(a);
530
+ } else {
531
+ bRelations = /* @__PURE__ */ new Set([a]);
532
+ this.relations.set(b, bRelations);
533
+ }
534
+ }
535
+ }
536
+ getContentInternal(contentKey) {
537
+ return this.contents.get(contentKey);
538
+ }
539
+ setContent(contentKey, content) {
540
+ this.contents.set(contentKey, content);
541
+ }
542
+ deleteContent(contentKey) {
543
+ this.contents.delete(contentKey);
544
+ }
545
+ toJSON() {
546
+ return {
547
+ between: [this.a, this.b],
548
+ cardinality: this.cardinality,
549
+ relations: [...this.relations.entries()].map(([a, b]) => [a, [...b]]),
550
+ contents: [...this.contents.entries()]
551
+ };
552
+ }
553
+ set(a, ...rest) {
554
+ var _a;
555
+ const b = typeof rest[0] === `string` ? rest[0] : a[this.b];
556
+ const content = ((_a = rest[1]) != null ? _a : typeof rest[0] === `string`) ? void 0 : rest[0];
557
+ a = typeof a === `string` ? a : a[this.a];
558
+ switch (this.cardinality) {
559
+ case `1:1`: {
560
+ const bPrev = this.getRelatedKey(a);
561
+ if (bPrev && bPrev !== b)
562
+ this.delete(bPrev, a);
563
+ }
564
+ case `1:n`: {
565
+ const aPrev = this.getRelatedKey(b);
566
+ if (aPrev && aPrev !== a)
567
+ this.delete(aPrev, b);
568
+ }
569
+ }
570
+ if (content) {
571
+ const contentKey = this.makeContentKey(a, b);
572
+ this.setContent(contentKey, content);
573
+ }
574
+ this.addRelation(a, b);
575
+ return this;
576
+ }
577
+ delete(x, b) {
578
+ b = typeof b === `string` ? b : x[this.b];
579
+ const a = typeof x === `string` ? x : x[this.a];
580
+ if (a === void 0 && typeof b === `string`) {
581
+ const bRelations = this.getRelatedKeys(b);
582
+ if (bRelations) {
583
+ for (const a2 of bRelations) {
584
+ this.delete(a2, b);
585
+ }
586
+ }
587
+ }
588
+ if (typeof a === `string` && b === void 0) {
589
+ const aRelations = this.getRelatedKeys(a);
590
+ if (aRelations) {
591
+ for (const b2 of aRelations) {
592
+ this.delete(a, b2);
593
+ }
594
+ }
595
+ }
596
+ if (typeof a === `string` && typeof b === `string`) {
597
+ this.deleteRelation(a, b);
598
+ const contentKey = this.makeContentKey(a, b);
599
+ this.deleteContent(contentKey);
600
+ }
601
+ return this;
602
+ }
603
+ getRelatedKey(key) {
604
+ const relations = this.getRelatedKeys(key);
605
+ if (relations) {
606
+ if (relations.size > 1) {
607
+ console.warn(
608
+ `${relations.size} related keys were found for key "${key}": (${[
609
+ ...relations
610
+ ].map((k) => `"${k}"`).join(`, `)}). Only one related key was expected.`
611
+ );
612
+ }
613
+ for (const relation of relations) {
614
+ return relation;
615
+ }
616
+ }
617
+ }
618
+ replaceRelations(a, relations, config) {
619
+ const hasContent = !Array.isArray(relations);
620
+ const bs = hasContent ? Object.keys(relations) : relations;
621
+ if (config == null ? void 0 : config.reckless) {
622
+ this.replaceRelationsUnsafely(a, bs);
623
+ } else {
624
+ this.replaceRelationsSafely(a, bs);
625
+ }
626
+ if (hasContent) {
627
+ for (const b of bs) {
628
+ const contentKey = this.makeContentKey(a, b);
629
+ const content = relations[b];
630
+ this.setContent(contentKey, content);
631
+ }
632
+ }
633
+ return this;
634
+ }
635
+ getContent(a, b) {
636
+ const contentKey = this.makeContentKey(a, b);
637
+ return this.getContentInternal(contentKey);
638
+ }
639
+ getRelationEntries(input) {
640
+ const a = input[this.a];
641
+ const b = input[this.b];
642
+ if (a !== void 0 && b === void 0) {
643
+ const aRelations = this.getRelatedKeys(a);
644
+ if (aRelations) {
645
+ return [...aRelations].map((b2) => {
646
+ var _a;
647
+ return [b2, (_a = this.getContent(a, b2)) != null ? _a : null];
17
648
  });
18
649
  }
650
+ }
651
+ if (a === void 0 && b !== void 0) {
652
+ const bRelations = this.getRelatedKeys(b);
653
+ if (bRelations) {
654
+ return [...bRelations].map((a2) => {
655
+ var _a;
656
+ return [a2, (_a = this.getContent(a2, b)) != null ? _a : null];
657
+ });
658
+ }
659
+ }
660
+ return [];
661
+ }
662
+ has(a, b) {
663
+ var _a;
664
+ if (b) {
665
+ const setA = this.getRelatedKeys(a);
666
+ return (_a = setA == null ? void 0 : setA.has(b)) != null ? _a : false;
667
+ }
668
+ return this.relations.has(a);
669
+ }
670
+ };
671
+
672
+ // internal/src/store/store.ts
673
+ var Store = class {
674
+ constructor(name, store = null) {
675
+ this.parent = null;
676
+ this.child = null;
677
+ this.valueMap = /* @__PURE__ */ new Map();
678
+ this.atoms = /* @__PURE__ */ new Map();
679
+ this.selectors = /* @__PURE__ */ new Map();
680
+ this.readonlySelectors = /* @__PURE__ */ new Map();
681
+ this.trackers = /* @__PURE__ */ new Map();
682
+ this.families = /* @__PURE__ */ new Map();
683
+ this.timelines = /* @__PURE__ */ new Map();
684
+ this.transactions = /* @__PURE__ */ new Map();
685
+ this.atomsThatAreDefault = /* @__PURE__ */ new Set();
686
+ this.timelineAtoms = new Junction({
687
+ between: [`timelineKey`, `atomKey`],
688
+ cardinality: `1:n`
689
+ });
690
+ this.selectorAtoms = new Junction({
691
+ between: [`selectorKey`, `atomKey`],
692
+ cardinality: `n:n`
693
+ });
694
+ this.selectorGraph = new Junction(
695
+ {
696
+ between: [`upstreamSelectorKey`, `downstreamSelectorKey`],
697
+ cardinality: `n:n`
698
+ },
699
+ {
700
+ makeContentKey: (...keys) => keys.sort().join(`:`)
701
+ }
702
+ );
703
+ this.subject = {
704
+ atomCreation: new Subject(),
705
+ selectorCreation: new Subject(),
706
+ transactionCreation: new Subject(),
707
+ timelineCreation: new Subject(),
708
+ transactionApplying: new StatefulSubject(null),
709
+ operationStatus: new Subject()
710
+ };
711
+ this.operation = { open: false };
712
+ this.transactionMeta = null;
713
+ this.config = {
714
+ name: `IMPLICIT_STORE`
715
+ };
716
+ this.loggers = [
717
+ new AtomIOLogger(`warn`, (_, __, key) => !key.includes(`\u{1F441}\u200D\u{1F5E8}`))
718
+ ];
719
+ this.logger = {
720
+ error: (...messages) => {
721
+ for (const logger of this.loggers)
722
+ logger.error(...messages);
723
+ },
724
+ info: (...messages) => {
725
+ for (const logger of this.loggers)
726
+ logger.info(...messages);
727
+ },
728
+ warn: (...messages) => {
729
+ for (const logger of this.loggers)
730
+ logger.warn(...messages);
731
+ }
732
+ };
733
+ if (store !== null) {
734
+ this.valueMap = new Map(store == null ? void 0 : store.valueMap);
735
+ this.operation = __spreadValues({}, store == null ? void 0 : store.operation);
736
+ this.transactionMeta = (store == null ? void 0 : store.transactionMeta) ? __spreadValues({}, store == null ? void 0 : store.transactionMeta) : null;
737
+ this.config = __spreadProps(__spreadValues({}, store == null ? void 0 : store.config), {
738
+ name
739
+ });
740
+ for (const [, atom] of store.atoms) {
741
+ atom.install(this);
742
+ }
743
+ for (const [, selector] of store.readonlySelectors) {
744
+ selector.install(this);
745
+ }
746
+ for (const [, selector] of store.selectors) {
747
+ selector.install(this);
748
+ }
749
+ for (const [, tx] of store.transactions) {
750
+ tx.install(this);
751
+ }
752
+ for (const [, timeline] of store.timelines) {
753
+ timeline.install(this);
754
+ }
755
+ }
756
+ }
757
+ };
758
+ var IMPLICIT = {
759
+ STORE_INTERNAL: void 0,
760
+ get STORE() {
761
+ var _a;
762
+ return (_a = this.STORE_INTERNAL) != null ? _a : this.STORE_INTERNAL = new Store(`IMPLICIT_STORE`);
763
+ }
764
+ };
765
+
766
+ // internal/src/store/withdraw.ts
767
+ function withdraw(token, store) {
768
+ var _a, _b, _c, _d;
769
+ const target = newest(store);
770
+ const state = (_d = (_c = (_b = (_a = target.atoms.get(token.key)) != null ? _a : target.selectors.get(token.key)) != null ? _b : target.readonlySelectors.get(token.key)) != null ? _c : target.transactions.get(token.key)) != null ? _d : target.timelines.get(token.key);
771
+ if (state) {
772
+ return state;
773
+ }
774
+ return void 0;
775
+ }
776
+
777
+ // internal/src/store/withdraw-new-family-member.ts
778
+ function withdrawNewFamilyMember(token, store) {
779
+ if (token.family) {
780
+ store.logger.info(
781
+ `\u{1F46A}`,
782
+ token.type,
783
+ token.key,
784
+ `creating new family member in store "${store.config.name}"`
785
+ );
786
+ const target = newest(store);
787
+ const family = target.families.get(token.family.key);
788
+ if (family) {
789
+ const jsonSubKey = JSON.parse(token.family.subKey);
790
+ family(jsonSubKey);
791
+ const state = withdraw(token, store);
792
+ return state;
793
+ }
794
+ }
795
+ return void 0;
796
+ }
797
+
798
+ // internal/src/keys.ts
799
+ var isAtomKey = (key, store) => newest(store).atoms.has(key);
800
+ var isSelectorKey = (key, store) => newest(store).selectors.has(key);
801
+ var isReadonlySelectorKey = (key, store) => newest(store).readonlySelectors.has(key);
802
+ var isStateKey = (key, store) => isAtomKey(key, store) || isSelectorKey(key, store) || isReadonlySelectorKey(key, store);
803
+
804
+ // internal/src/selector/get-selector-dependency-keys.ts
805
+ var getSelectorDependencyKeys = (key, store) => {
806
+ const sources = newest(store).selectorGraph.getRelationEntries({ downstreamSelectorKey: key }).filter(([_, { source }]) => source !== key).map(([_, { source }]) => source).filter((source) => isStateKey(source, store));
807
+ return sources;
808
+ };
809
+
810
+ // internal/src/selector/trace-selector-atoms.ts
811
+ var traceSelectorAtoms = (selectorKey, directDependencyKey, store) => {
812
+ const rootKeys = [];
813
+ const indirectDependencyKeys = getSelectorDependencyKeys(
814
+ directDependencyKey,
815
+ store
816
+ );
817
+ let depth = 0;
818
+ while (indirectDependencyKeys.length > 0) {
819
+ const indirectDependencyKey = indirectDependencyKeys.shift();
820
+ ++depth;
821
+ if (depth > 99999) {
822
+ throw new Error(
823
+ `Maximum selector dependency depth exceeded (> 99999) in selector "${selectorKey}". This is likely due to a circular dependency.`
824
+ );
825
+ }
826
+ if (!isAtomKey(indirectDependencyKey, store)) {
827
+ indirectDependencyKeys.push(
828
+ ...getSelectorDependencyKeys(indirectDependencyKey, store)
829
+ );
830
+ } else if (!rootKeys.includes(indirectDependencyKey)) {
831
+ rootKeys.push(indirectDependencyKey);
832
+ }
833
+ }
834
+ return rootKeys;
835
+ };
836
+ var traceAllSelectorAtoms = (selectorKey, store) => {
837
+ const directDependencyKeys = getSelectorDependencyKeys(selectorKey, store);
838
+ return directDependencyKeys.flatMap(
839
+ (depKey) => isAtomKey(depKey, store) ? depKey : traceSelectorAtoms(selectorKey, depKey, store)
840
+ );
841
+ };
842
+
843
+ // internal/src/selector/update-selector-atoms.ts
844
+ var updateSelectorAtoms = (selectorKey, dependency, store) => {
845
+ const target = newest(store);
846
+ if (dependency.type === `atom`) {
847
+ target.selectorAtoms.set({
848
+ selectorKey,
849
+ atomKey: dependency.key
19
850
  });
851
+ store.logger.info(
852
+ `\u{1F50D}`,
853
+ `selector`,
854
+ selectorKey,
855
+ `discovers root atom "${dependency.key}"`
856
+ );
857
+ } else {
858
+ const rootKeys = traceSelectorAtoms(selectorKey, dependency.key, store);
859
+ store.logger.info(
860
+ `\u{1F50D}`,
861
+ `selector`,
862
+ selectorKey,
863
+ `discovers root atoms: [ ${rootKeys.map((key) => `"${key}"`).join(`, `)} ]`
864
+ );
865
+ for (const atomKey of rootKeys) {
866
+ target.selectorAtoms = target.selectorAtoms.set({
867
+ selectorKey,
868
+ atomKey
869
+ });
870
+ }
871
+ }
872
+ };
873
+
874
+ // internal/src/selector/register-selector.ts
875
+ var registerSelector = (selectorKey, store) => ({
876
+ get: (dependency) => {
877
+ const target = newest(store);
878
+ const alreadyRegistered = target.selectorGraph.getRelationEntries({ downstreamSelectorKey: selectorKey }).some(([_, { source }]) => source === dependency.key);
879
+ const dependencyState = withdraw(dependency, store);
880
+ if (dependencyState === void 0) {
881
+ throw new Error(
882
+ `State "${dependency.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
883
+ );
884
+ }
885
+ const dependencyValue = readOrComputeValue(dependencyState, store);
886
+ store.logger.info(
887
+ `\u{1F50C}`,
888
+ `selector`,
889
+ selectorKey,
890
+ `registers dependency ( "${dependency.key}" =`,
891
+ dependencyValue,
892
+ `)`
893
+ );
894
+ if (!alreadyRegistered) {
895
+ target.selectorGraph.set(
896
+ {
897
+ upstreamSelectorKey: dependency.key,
898
+ downstreamSelectorKey: selectorKey
899
+ },
900
+ {
901
+ source: dependency.key
902
+ }
903
+ );
904
+ }
905
+ updateSelectorAtoms(selectorKey, dependency, store);
906
+ return dependencyValue;
907
+ },
908
+ set: (stateToken, newValue) => {
909
+ const state = withdraw(stateToken, store);
910
+ if (state === void 0) {
911
+ throw new Error(
912
+ `State "${stateToken.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
913
+ );
914
+ }
915
+ setAtomOrSelector(state, newValue, store);
916
+ }
917
+ });
918
+
919
+ // internal/src/selector/create-read-write-selector.ts
920
+ var createReadWriteSelector = (options, family, store) => {
921
+ const target = newest(store);
922
+ const subject = new Subject();
923
+ const { get, set } = registerSelector(options.key, store);
924
+ const getSelf = () => {
925
+ const value = options.get({ get });
926
+ cacheValue(options.key, value, subject, store);
927
+ return value;
928
+ };
929
+ const setSelf = (next) => {
930
+ const oldValue = getSelf();
931
+ const newValue = become(next)(oldValue);
932
+ store.logger.info(
933
+ `\u{1F4DD}`,
934
+ `selector`,
935
+ options.key,
936
+ `set (`,
937
+ oldValue,
938
+ `->`,
939
+ newValue,
940
+ `)`
941
+ );
942
+ cacheValue(options.key, newValue, subject, store);
943
+ markDone(options.key, store);
944
+ if (target.transactionMeta === null) {
945
+ subject.next({ newValue, oldValue });
946
+ }
947
+ options.set({ get, set }, newValue);
948
+ };
949
+ const mySelector = __spreadValues(__spreadProps(__spreadValues({}, options), {
950
+ subject,
951
+ install: (s) => createSelector(options, family, s),
952
+ get: getSelf,
953
+ set: setSelf,
954
+ type: `selector`
955
+ }), family && { family });
956
+ target.selectors.set(options.key, mySelector);
957
+ const initialValue = getSelf();
958
+ store.logger.info(`\u2728`, mySelector.type, mySelector.key, `=`, initialValue);
959
+ const token = {
960
+ key: options.key,
961
+ type: `selector`
962
+ };
963
+ if (family) {
964
+ token.family = family;
965
+ }
966
+ store.subject.selectorCreation.next(token);
967
+ return token;
968
+ };
969
+
970
+ // internal/src/selector/create-readonly-selector.ts
971
+ var createReadonlySelector = (options, family, store) => {
972
+ const target = newest(store);
973
+ const subject = new Subject();
974
+ const { get } = registerSelector(options.key, store);
975
+ const getSelf = () => {
976
+ const value = options.get({ get });
977
+ cacheValue(options.key, value, subject, store);
978
+ return value;
979
+ };
980
+ const readonlySelector = __spreadValues(__spreadProps(__spreadValues({}, options), {
981
+ subject,
982
+ install: (s) => createSelector(options, family, s),
983
+ get: getSelf,
984
+ type: `readonly_selector`
985
+ }), family && { family });
986
+ target.readonlySelectors.set(options.key, readonlySelector);
987
+ const initialValue = getSelf();
988
+ store.logger.info(
989
+ `\u2728`,
990
+ readonlySelector.type,
991
+ readonlySelector.key,
992
+ `=`,
993
+ initialValue
994
+ );
995
+ const token = {
996
+ key: options.key,
997
+ type: `readonly_selector`
998
+ };
999
+ if (family) {
1000
+ token.family = family;
1001
+ }
1002
+ store.subject.selectorCreation.next(token);
1003
+ return token;
1004
+ };
1005
+
1006
+ // internal/src/selector/create-selector.ts
1007
+ function createSelector(options, family, store) {
1008
+ const target = newest(store);
1009
+ const existingWritable = target.selectors.get(options.key);
1010
+ const existingReadonly = target.readonlySelectors.get(options.key);
1011
+ if (existingWritable || existingReadonly) {
1012
+ store.logger.error(
1013
+ `\u274C`,
1014
+ existingReadonly ? `readonly_selector` : `selector`,
1015
+ options.key,
1016
+ `Tried to create selector, but it already exists in the store. (Ignore if you are in development using hot module replacement.)`
1017
+ );
1018
+ }
1019
+ if (`set` in options) {
1020
+ return createReadWriteSelector(options, family, store);
1021
+ }
1022
+ return createReadonlySelector(options, family, store);
1023
+ }
1024
+
1025
+ // internal/src/subscribe/recall-state.ts
1026
+ var recallState = (state, store) => {
1027
+ const target = newest(store);
1028
+ if (!target.operation.open) {
1029
+ return target.valueMap.get(state.key);
1030
+ }
1031
+ return target.operation.prev.get(state.key);
1032
+ };
1033
+
1034
+ // internal/src/subscribe/subscribe-to-root-atoms.ts
1035
+ var subscribeToRootAtoms = (state, store) => {
1036
+ const dependencySubscriptions = `default` in state ? null : traceAllSelectorAtoms(state.key, store).map((atomKey) => {
1037
+ const atom = store.atoms.get(atomKey);
1038
+ if (atom === void 0) {
1039
+ throw new Error(
1040
+ `Atom "${atomKey}", a dependency of selector "${state.key}", not found in store "${store.config.name}".`
1041
+ );
1042
+ }
1043
+ return atom.subject.subscribe(
1044
+ `${state.type}:${state.key}`,
1045
+ (atomChange) => {
1046
+ store.logger.info(
1047
+ `\u{1F4E2}`,
1048
+ state.type,
1049
+ state.key,
1050
+ `root`,
1051
+ atomKey,
1052
+ `went`,
1053
+ atomChange.oldValue,
1054
+ `->`,
1055
+ atomChange.newValue
1056
+ );
1057
+ const oldValue = recallState(state, store);
1058
+ const newValue = readOrComputeValue(state, store);
1059
+ store.logger.info(
1060
+ `\u2728`,
1061
+ state.type,
1062
+ state.key,
1063
+ `went`,
1064
+ oldValue,
1065
+ `->`,
1066
+ newValue
1067
+ );
1068
+ state.subject.next({ newValue, oldValue });
1069
+ }
1070
+ );
1071
+ });
1072
+ return dependencySubscriptions;
1073
+ };
1074
+
1075
+ // internal/src/subscribe/subscribe-to-state.ts
1076
+ function subscribeToState(token, handleUpdate, key, store) {
1077
+ const state = withdraw(token, store);
1078
+ if (state === void 0) {
1079
+ throw new Error(
1080
+ `State "${token.key}" not found in this store. Did you forget to initialize with the "atom" or "selector" function?`
1081
+ );
20
1082
  }
21
- n.default = e;
22
- return Object.freeze(n);
1083
+ const unsubFunction = state.subject.subscribe(key, handleUpdate);
1084
+ store.logger.info(`\u{1F440}`, state.type, state.key, `Adding subscription "${key}"`);
1085
+ const dependencyUnsubFunctions = state.type !== `atom` ? subscribeToRootAtoms(state, store) : null;
1086
+ const unsubscribe = dependencyUnsubFunctions === null ? () => {
1087
+ store.logger.info(
1088
+ `\u{1F648}`,
1089
+ state.type,
1090
+ state.key,
1091
+ `Removing subscription "${key}"`
1092
+ );
1093
+ unsubFunction();
1094
+ } : () => {
1095
+ store.logger.info(
1096
+ `\u{1F648}`,
1097
+ state.type,
1098
+ state.key,
1099
+ `Removing subscription "${key}"`
1100
+ );
1101
+ unsubFunction();
1102
+ for (const unsubFromDependency of dependencyUnsubFunctions) {
1103
+ unsubFromDependency();
1104
+ }
1105
+ };
1106
+ return unsubscribe;
23
1107
  }
24
1108
 
25
- var AtomIO4__namespace = /*#__PURE__*/_interopNamespace(AtomIO4);
26
- var Internal__namespace = /*#__PURE__*/_interopNamespace(Internal);
1109
+ // internal/src/subscribe/subscribe-to-timeline.ts
1110
+ var subscribeToTimeline = (token, handleUpdate, key, store) => {
1111
+ const tl = withdraw(token, store);
1112
+ if (tl === void 0) {
1113
+ throw new Error(
1114
+ `Cannot subscribe to timeline "${token.key}": timeline not found in store "${store.config.name}".`
1115
+ );
1116
+ }
1117
+ store.logger.info(`\u{1F440}`, `timeline`, token.key, `Adding subscription "${key}"`);
1118
+ const unsubscribe = tl.subject.subscribe(key, handleUpdate);
1119
+ return () => {
1120
+ store.logger.info(
1121
+ `\u{1F648}`,
1122
+ `timeline`,
1123
+ token.key,
1124
+ `Removing subscription "${key}" from timeline`
1125
+ );
1126
+ unsubscribe();
1127
+ };
1128
+ };
1129
+
1130
+ // internal/src/subscribe/subscribe-to-transaction.ts
1131
+ var subscribeToTransaction = (token, handleUpdate, key, store) => {
1132
+ const tx = withdraw(token, store);
1133
+ if (tx === void 0) {
1134
+ throw new Error(
1135
+ `Cannot subscribe to transaction "${token.key}": transaction not found in store "${store.config.name}".`
1136
+ );
1137
+ }
1138
+ store.logger.info(
1139
+ `\u{1F440}`,
1140
+ `transaction`,
1141
+ token.key,
1142
+ `Adding subscription "${key}"`
1143
+ );
1144
+ const unsubscribe = tx.subject.subscribe(key, handleUpdate);
1145
+ return () => {
1146
+ store.logger.info(
1147
+ `\u{1F648}`,
1148
+ `transaction`,
1149
+ token.key,
1150
+ `Removing subscription "${key}"`
1151
+ );
1152
+ unsubscribe();
1153
+ };
1154
+ };
27
1155
 
28
- // src/hook-composition/expose-single.ts
1156
+ // internal/src/mutable/tracker.ts
1157
+ var Tracker = class {
1158
+ constructor(mutableState, store) {
1159
+ this.unsubscribeFromInnerValue = null;
1160
+ this.mutableState = mutableState;
1161
+ const target = newest(store);
1162
+ this.latestUpdateState = this.initializeState(mutableState, target);
1163
+ this.observeCore(mutableState, this.latestUpdateState, target);
1164
+ this.updateCore(mutableState, this.latestUpdateState, target);
1165
+ target.trackers.set(mutableState.key, this);
1166
+ }
1167
+ initializeState(mutableState, store) {
1168
+ const latestUpdateStateKey = `*${mutableState.key}`;
1169
+ store.atoms.delete(latestUpdateStateKey);
1170
+ store.valueMap.delete(latestUpdateStateKey);
1171
+ const familyMetaData = mutableState.family ? {
1172
+ key: `*${mutableState.family.key}`,
1173
+ subKey: mutableState.family.subKey
1174
+ } : void 0;
1175
+ const latestUpdateState = createAtom(
1176
+ {
1177
+ key: latestUpdateStateKey,
1178
+ default: null
1179
+ },
1180
+ familyMetaData,
1181
+ store
1182
+ );
1183
+ if (store.parent) {
1184
+ const parentValue = store.parent.valueMap.get(latestUpdateStateKey);
1185
+ store.valueMap.set(latestUpdateStateKey, parentValue);
1186
+ }
1187
+ return latestUpdateState;
1188
+ }
1189
+ observeCore(mutableState, latestUpdateState, store) {
1190
+ const originalInnerValue = getState(mutableState, store);
1191
+ const target = newest(store);
1192
+ this.unsubscribeFromInnerValue = originalInnerValue.subscribe(
1193
+ `tracker:${store.config.name}:${target.transactionMeta === null ? `main` : target.transactionMeta.update.key}`,
1194
+ (update) => {
1195
+ const unsubscribe = store.subject.operationStatus.subscribe(
1196
+ mutableState.key,
1197
+ () => {
1198
+ unsubscribe();
1199
+ setState(latestUpdateState, update, store);
1200
+ }
1201
+ );
1202
+ }
1203
+ );
1204
+ subscribeToState(
1205
+ mutableState,
1206
+ (update) => {
1207
+ var _a;
1208
+ if (update.newValue !== update.oldValue) {
1209
+ (_a = this.unsubscribeFromInnerValue) == null ? void 0 : _a.call(this);
1210
+ const target2 = newest(store);
1211
+ this.unsubscribeFromInnerValue = update.newValue.subscribe(
1212
+ `tracker:${store.config.name}:${target2.transactionMeta === null ? `main` : target2.transactionMeta.update.key}`,
1213
+ (update2) => {
1214
+ const unsubscribe = store.subject.operationStatus.subscribe(
1215
+ mutableState.key,
1216
+ () => {
1217
+ unsubscribe();
1218
+ setState(latestUpdateState, update2, store);
1219
+ }
1220
+ );
1221
+ }
1222
+ );
1223
+ }
1224
+ },
1225
+ `${store.config.name}: tracker observing inner value`,
1226
+ store
1227
+ );
1228
+ }
1229
+ updateCore(mutableState, latestUpdateState, store) {
1230
+ subscribeToState(
1231
+ latestUpdateState,
1232
+ ({ newValue, oldValue }) => {
1233
+ const timelineId = store.timelineAtoms.getRelatedKey(
1234
+ latestUpdateState.key
1235
+ );
1236
+ if (timelineId) {
1237
+ const timelineData = store.timelines.get(timelineId);
1238
+ if (timelineData == null ? void 0 : timelineData.timeTraveling) {
1239
+ const unsubscribe2 = subscribeToTimeline(
1240
+ { key: timelineId, type: `timeline` },
1241
+ (update) => {
1242
+ unsubscribe2();
1243
+ setState(
1244
+ mutableState,
1245
+ (transceiver) => {
1246
+ if (update === `redo` && newValue) {
1247
+ transceiver.do(newValue);
1248
+ } else if (update === `undo` && oldValue) {
1249
+ transceiver.undo(oldValue);
1250
+ }
1251
+ return transceiver;
1252
+ },
1253
+ store
1254
+ );
1255
+ },
1256
+ `${mutableState.key}: tracker observing timeline`,
1257
+ store
1258
+ );
1259
+ return;
1260
+ }
1261
+ }
1262
+ const unsubscribe = store.subject.operationStatus.subscribe(
1263
+ latestUpdateState.key,
1264
+ () => {
1265
+ unsubscribe();
1266
+ const mutable = getState(mutableState, store);
1267
+ const updateNumber = newValue === null ? -1 : mutable.getUpdateNumber(newValue);
1268
+ const eventOffset = updateNumber - mutable.cacheUpdateNumber;
1269
+ if (newValue && eventOffset === 1) {
1270
+ setState(
1271
+ mutableState,
1272
+ (transceiver) => (transceiver.do(newValue), transceiver),
1273
+ store
1274
+ );
1275
+ }
1276
+ }
1277
+ );
1278
+ },
1279
+ `${store.config.name}: tracker observing latest update`,
1280
+ store
1281
+ );
1282
+ }
1283
+ };
1284
+
1285
+ // internal/src/mutable/create-mutable-atom.ts
1286
+ function createMutableAtom(options, store) {
1287
+ store.logger.info(
1288
+ `\u{1F527}`,
1289
+ `atom`,
1290
+ options.key,
1291
+ `creating in store "${store.config.name}"`
1292
+ );
1293
+ const coreState = createAtom(options, void 0, store);
1294
+ new Tracker(coreState, store);
1295
+ const jsonState = selectJson(coreState, options, store);
1296
+ const target = newest(store);
1297
+ subscribeToState(
1298
+ jsonState,
1299
+ () => {
1300
+ const trackerHasBeenInitialized = newest(store).trackers.has(coreState.key);
1301
+ if (!trackerHasBeenInitialized) {
1302
+ new Tracker(coreState, store);
1303
+ }
1304
+ },
1305
+ `tracker-initializer:${store == null ? void 0 : store.config.name}:${target.transactionMeta === null ? `main` : `${target.transactionMeta.update.key}`}`,
1306
+ store
1307
+ );
1308
+ return coreState;
1309
+ }
1310
+
1311
+ // internal/src/mutable/get-json-token.ts
1312
+ var getJsonToken = (mutableAtomToken) => {
1313
+ const key = mutableAtomToken.family ? `${mutableAtomToken.family.key}:JSON(${mutableAtomToken.family.subKey})` : `${mutableAtomToken.key}:JSON`;
1314
+ const jsonToken = { type: `selector`, key };
1315
+ if (mutableAtomToken.family) {
1316
+ jsonToken.family = {
1317
+ key: `${mutableAtomToken.family.key}:JSON`,
1318
+ subKey: mutableAtomToken.family.subKey
1319
+ };
1320
+ }
1321
+ return jsonToken;
1322
+ };
1323
+
1324
+ // internal/src/mutable/get-update-token.ts
1325
+ var getUpdateToken = (mutableAtomToken) => {
1326
+ const key = `*${mutableAtomToken.key}`;
1327
+ const updateToken = { type: `atom`, key };
1328
+ if (mutableAtomToken.family) {
1329
+ updateToken.family = {
1330
+ key: `*${mutableAtomToken.family.key}`,
1331
+ subKey: mutableAtomToken.family.subKey
1332
+ };
1333
+ }
1334
+ return updateToken;
1335
+ };
1336
+
1337
+ // internal/src/mutable/transceiver.ts
1338
+ function isTransceiver(value) {
1339
+ return typeof value === `object` && value !== null && `do` in value && `undo` in value && `subscribe` in value;
1340
+ }
1341
+
1342
+ // internal/src/atom/is-default.ts
1343
+ var isAtomDefault = (key, store) => {
1344
+ const core = newest(store);
1345
+ return core.atomsThatAreDefault.has(key);
1346
+ };
1347
+ var markAtomAsDefault = (key, store) => {
1348
+ const core = newest(store);
1349
+ core.atomsThatAreDefault = new Set(core.atomsThatAreDefault).add(key);
1350
+ };
1351
+ var markAtomAsNotDefault = (key, store) => {
1352
+ const core = newest(store);
1353
+ core.atomsThatAreDefault = new Set(newest(store).atomsThatAreDefault);
1354
+ core.atomsThatAreDefault.delete(key);
1355
+ };
1356
+
1357
+ // internal/src/atom/create-atom.ts
1358
+ function createAtom(options, family, store) {
1359
+ store.logger.info(
1360
+ `\u{1F528}`,
1361
+ `atom`,
1362
+ options.key,
1363
+ `creating in store "${store.config.name}"`
1364
+ );
1365
+ const target = newest(store);
1366
+ const existing = target.atoms.get(options.key);
1367
+ if (existing) {
1368
+ store.logger.error(
1369
+ `\u274C`,
1370
+ `atom`,
1371
+ options.key,
1372
+ `Tried to create atom, but it already exists in the store.`,
1373
+ `(Ignore if you are in development using hot module replacement.)`
1374
+ );
1375
+ return deposit(existing);
1376
+ }
1377
+ const subject = new Subject();
1378
+ const newAtom = __spreadValues(__spreadProps(__spreadValues({}, options), {
1379
+ type: `atom`,
1380
+ install: (store2) => {
1381
+ store2.logger.info(
1382
+ `\u{1F6E0}\uFE0F`,
1383
+ `atom`,
1384
+ options.key,
1385
+ `installing in store "${store2.config.name}"`
1386
+ );
1387
+ return `mutable` in options ? createMutableAtom(options, store2) : createAtom(options, void 0, store2);
1388
+ },
1389
+ subject
1390
+ }), family && { family });
1391
+ let initialValue = options.default;
1392
+ if (options.default instanceof Function) {
1393
+ initialValue = options.default();
1394
+ }
1395
+ target.atoms.set(newAtom.key, newAtom);
1396
+ markAtomAsDefault(options.key, store);
1397
+ cacheValue(options.key, initialValue, subject, store);
1398
+ const token = deposit(newAtom);
1399
+ if (options.effects) {
1400
+ let effectIndex = 0;
1401
+ const cleanupFunctions = [];
1402
+ for (const effect of options.effects) {
1403
+ const cleanup = effect({
1404
+ setSelf: (next) => setState(token, next, store),
1405
+ onSet: (handle) => subscribeToState(token, handle, `effect[${effectIndex}]`, store)
1406
+ });
1407
+ if (cleanup) {
1408
+ cleanupFunctions.push(cleanup);
1409
+ }
1410
+ ++effectIndex;
1411
+ }
1412
+ newAtom.cleanup = () => {
1413
+ for (const cleanup of cleanupFunctions) {
1414
+ cleanup();
1415
+ }
1416
+ };
1417
+ }
1418
+ store.subject.atomCreation.next(token);
1419
+ return token;
1420
+ }
1421
+
1422
+ // internal/src/not-found-error.ts
1423
+ var capitalize = (str) => str[0].toUpperCase() + str.slice(1);
1424
+ function prettyPrintTokenType(token) {
1425
+ if (token.type === `readonly_selector`) {
1426
+ return `Readonly Selector`;
1427
+ }
1428
+ return capitalize(token.type);
1429
+ }
1430
+ var NotFoundError = class extends Error {
1431
+ constructor(token, store) {
1432
+ super(
1433
+ `${prettyPrintTokenType(token)} "${token.key}" not found in store "${store.config.name}".`
1434
+ );
1435
+ }
1436
+ };
1437
+
1438
+ // src/get-state.ts
1439
+ function getState(token, store = IMPLICIT.STORE) {
1440
+ var _a;
1441
+ const state = (_a = withdraw(token, store)) != null ? _a : withdrawNewFamilyMember(token, store);
1442
+ if (state === void 0) {
1443
+ throw new NotFoundError(token, store);
1444
+ }
1445
+ return readOrComputeValue(state, store);
1446
+ }
1447
+
1448
+ // src/logger.ts
1449
+ var simpleLog = (logLevel) => (icon, tokenType, tokenKey, message, ...rest) => {
1450
+ console[logLevel](`${icon} ${tokenType} "${tokenKey}" ${message}`, ...rest);
1451
+ };
1452
+ var simpleLogger = {
1453
+ error: simpleLog(`error`),
1454
+ info: simpleLog(`info`),
1455
+ warn: simpleLog(`warn`)
1456
+ };
1457
+ var AtomIOLogger = class {
1458
+ constructor(logLevel, filter, logger = simpleLogger) {
1459
+ this.logLevel = logLevel;
1460
+ this.filter = filter;
1461
+ this.logger = logger;
1462
+ this.error = (...args) => {
1463
+ var _a, _b;
1464
+ if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel !== null) {
1465
+ this.logger.error(...args);
1466
+ }
1467
+ };
1468
+ this.info = (...args) => {
1469
+ var _a, _b;
1470
+ if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel === `info`) {
1471
+ this.logger.info(...args);
1472
+ }
1473
+ };
1474
+ this.warn = (...args) => {
1475
+ var _a, _b;
1476
+ if (((_b = (_a = this.filter) == null ? void 0 : _a.call(this, ...args)) != null ? _b : true) && this.logLevel !== `error` && this.logLevel !== null) {
1477
+ this.logger.warn(...args);
1478
+ }
1479
+ };
1480
+ }
1481
+ };
1482
+
1483
+ // src/set-state.ts
1484
+ function setState(token, value, store = IMPLICIT.STORE) {
1485
+ var _a;
1486
+ const rejection = openOperation(token, store);
1487
+ if (rejection) {
1488
+ return;
1489
+ }
1490
+ const state = (_a = withdraw(token, store)) != null ? _a : withdrawNewFamilyMember(token, store);
1491
+ if (state === void 0) {
1492
+ throw new NotFoundError(token, store);
1493
+ }
1494
+ setAtomOrSelector(state, value, store);
1495
+ closeOperation(store);
1496
+ }
1497
+
1498
+ // src/transaction.ts
1499
+ var runTransaction = (token, store = IMPLICIT.STORE) => (...parameters) => {
1500
+ const tx = withdraw(token, store);
1501
+ if (tx) {
1502
+ return tx.run(...parameters);
1503
+ }
1504
+ throw new Error(
1505
+ `Cannot run transaction "${token.key}": transaction not found in store "${store.config.name}".`
1506
+ );
1507
+ };
1508
+
1509
+ // realtime-server/src/hook-composition/expose-single.ts
29
1510
  var useExposeSingle = ({
30
1511
  socket,
31
- store = Internal__namespace.IMPLICIT.STORE
1512
+ store = IMPLICIT.STORE
32
1513
  }) => {
33
1514
  return function exposeSingle(token) {
34
1515
  let unsubscribeFromStateUpdates = null;
@@ -38,8 +1519,8 @@ var useExposeSingle = ({
38
1519
  unsubscribeFromStateUpdates = null;
39
1520
  };
40
1521
  const fillSubRequest = () => {
41
- socket.emit(`serve:${token.key}`, AtomIO4__namespace.getState(token, store));
42
- unsubscribeFromStateUpdates = Internal__namespace.subscribeToState(
1522
+ socket.emit(`serve:${token.key}`, getState(token, store));
1523
+ unsubscribeFromStateUpdates = subscribeToState(
43
1524
  token,
44
1525
  ({ newValue }) => {
45
1526
  socket.emit(`serve:${token.key}`, newValue);
@@ -56,13 +1537,15 @@ var useExposeSingle = ({
56
1537
  };
57
1538
  };
58
1539
  };
1540
+
1541
+ // realtime-server/src/hook-composition/expose-family.ts
59
1542
  var subscribeToTokenCreation = (family, key, handleTokenCreation) => {
60
1543
  const unsubscribe = family.type === `atom_family` ? family.subject.subscribe(key, handleTokenCreation) : family.subject.subscribe(key, handleTokenCreation);
61
1544
  return unsubscribe;
62
1545
  };
63
1546
  var useExposeFamily = ({
64
1547
  socket,
65
- store = Internal.IMPLICIT.STORE
1548
+ store = IMPLICIT.STORE
66
1549
  }) => {
67
1550
  return function exposeFamily(family, index) {
68
1551
  const unsubSingleCallbacksByKey = /* @__PURE__ */ new Map();
@@ -85,26 +1568,26 @@ var useExposeFamily = ({
85
1568
  const fillSubRequest = (subKey) => {
86
1569
  var _a;
87
1570
  if (subKey === void 0) {
88
- const keys = AtomIO4__namespace.getState(index, store);
1571
+ const keys = getState(index, store);
89
1572
  for (const key of keys) {
90
1573
  const token = family(key);
91
1574
  socket.emit(
92
1575
  `serve:${family.key}`,
93
- json.parseJson(((_a = token.family) == null ? void 0 : _a.subKey) || `null`),
94
- AtomIO4__namespace.getState(token, store)
1576
+ parseJson(((_a = token.family) == null ? void 0 : _a.subKey) || `null`),
1577
+ getState(token, store)
95
1578
  );
96
1579
  }
97
1580
  const unsubscribeFromTokenCreation = subscribeToTokenCreation(
98
1581
  family,
99
1582
  `expose-family:${socket.id}`,
100
1583
  (token) => {
101
- const unsub = Internal.subscribeToState(
1584
+ const unsub = subscribeToState(
102
1585
  token,
103
1586
  ({ newValue }) => {
104
1587
  var _a2;
105
1588
  socket.emit(
106
1589
  `serve:${family.key}`,
107
- json.parseJson(((_a2 = token.family) == null ? void 0 : _a2.subKey) || `null`),
1590
+ parseJson(((_a2 = token.family) == null ? void 0 : _a2.subKey) || `null`),
108
1591
  newValue
109
1592
  );
110
1593
  },
@@ -118,8 +1601,8 @@ var useExposeFamily = ({
118
1601
  socket.on(`unsub:${family.key}`, fillFamilyUnsubRequest);
119
1602
  } else {
120
1603
  const token = family(subKey);
121
- socket.emit(`serve:${token.key}`, AtomIO4__namespace.getState(token, store));
122
- const unsubscribe = Internal.subscribeToState(
1604
+ socket.emit(`serve:${token.key}`, getState(token, store));
1605
+ const unsubscribe = subscribeToState(
123
1606
  token,
124
1607
  ({ newValue }) => {
125
1608
  socket.emit(`serve:${token.key}`, newValue);
@@ -147,22 +1630,24 @@ var useExposeFamily = ({
147
1630
  };
148
1631
  };
149
1632
  };
1633
+
1634
+ // realtime-server/src/hook-composition/expose-mutable.ts
150
1635
  var useExposeMutable = ({
151
1636
  socket,
152
- store = Internal.IMPLICIT.STORE
1637
+ store = IMPLICIT.STORE
153
1638
  }) => {
154
1639
  return function exposeMutable(token) {
155
1640
  let unsubscribeFromStateUpdates = null;
156
- const jsonToken = Internal.getJsonToken(token);
157
- const trackerToken = Internal.getUpdateToken(token);
1641
+ const jsonToken = getJsonToken(token);
1642
+ const trackerToken = getUpdateToken(token);
158
1643
  const fillUnsubRequest = () => {
159
1644
  socket.off(`unsub:${token.key}`, fillUnsubRequest);
160
1645
  unsubscribeFromStateUpdates == null ? void 0 : unsubscribeFromStateUpdates();
161
1646
  unsubscribeFromStateUpdates = null;
162
1647
  };
163
1648
  const fillSubRequest = () => {
164
- socket.emit(`init:${token.key}`, AtomIO4__namespace.getState(jsonToken, store));
165
- unsubscribeFromStateUpdates = Internal.subscribeToState(
1649
+ socket.emit(`init:${token.key}`, getState(jsonToken, store));
1650
+ unsubscribeFromStateUpdates = subscribeToState(
166
1651
  trackerToken,
167
1652
  ({ newValue }) => {
168
1653
  socket.emit(`next:${token.key}`, newValue);
@@ -179,9 +1664,11 @@ var useExposeMutable = ({
179
1664
  };
180
1665
  };
181
1666
  };
1667
+
1668
+ // realtime-server/src/hook-composition/expose-mutable-family.ts
182
1669
  var useExposeMutableFamily = ({
183
1670
  socket,
184
- store = Internal.IMPLICIT.STORE
1671
+ store = IMPLICIT.STORE
185
1672
  }) => {
186
1673
  return function exposeMutableFamily(family, index) {
187
1674
  const unsubSingleCallbacksByKey = /* @__PURE__ */ new Map();
@@ -204,23 +1691,23 @@ var useExposeMutableFamily = ({
204
1691
  const fillSubRequest = (subKey) => {
205
1692
  var _a;
206
1693
  if (subKey === void 0) {
207
- const keys = AtomIO4__namespace.getState(index, store);
1694
+ const keys = getState(index, store);
208
1695
  for (const key of keys) {
209
1696
  const token = family(key);
210
- const jsonToken = Internal.getJsonToken(token);
211
- const trackerToken = Internal.getUpdateToken(token);
1697
+ const jsonToken = getJsonToken(token);
1698
+ const trackerToken = getUpdateToken(token);
212
1699
  socket.emit(
213
1700
  `init:${family.key}`,
214
- json.parseJson(((_a = jsonToken.family) == null ? void 0 : _a.subKey) || `null`),
215
- AtomIO4__namespace.getState(jsonToken, store)
1701
+ parseJson(((_a = jsonToken.family) == null ? void 0 : _a.subKey) || `null`),
1702
+ getState(jsonToken, store)
216
1703
  );
217
- const unsubFromUpdates = Internal.subscribeToState(
1704
+ const unsubFromUpdates = subscribeToState(
218
1705
  trackerToken,
219
1706
  ({ newValue }) => {
220
1707
  var _a2;
221
1708
  socket.emit(
222
1709
  `next:${token.key}`,
223
- json.parseJson(((_a2 = jsonToken.family) == null ? void 0 : _a2.subKey) || `null`),
1710
+ parseJson(((_a2 = jsonToken.family) == null ? void 0 : _a2.subKey) || `null`),
224
1711
  newValue
225
1712
  );
226
1713
  },
@@ -233,20 +1720,20 @@ var useExposeMutableFamily = ({
233
1720
  `expose-family:${socket.id}`,
234
1721
  (token) => {
235
1722
  var _a2;
236
- const jsonToken = Internal.getJsonToken(token);
237
- const trackerToken = Internal.getUpdateToken(token);
1723
+ const jsonToken = getJsonToken(token);
1724
+ const trackerToken = getUpdateToken(token);
238
1725
  socket.emit(
239
1726
  `init:${family.key}`,
240
- json.parseJson(((_a2 = jsonToken.family) == null ? void 0 : _a2.subKey) || `null`),
241
- AtomIO4__namespace.getState(jsonToken, store)
1727
+ parseJson(((_a2 = jsonToken.family) == null ? void 0 : _a2.subKey) || `null`),
1728
+ getState(jsonToken, store)
242
1729
  );
243
- const unsubFromUpdates = Internal.subscribeToState(
1730
+ const unsubFromUpdates = subscribeToState(
244
1731
  trackerToken,
245
1732
  ({ newValue }) => {
246
1733
  var _a3;
247
1734
  socket.emit(
248
1735
  `next:${token.key}`,
249
- json.parseJson(((_a3 = jsonToken.family) == null ? void 0 : _a3.subKey) || `null`),
1736
+ parseJson(((_a3 = jsonToken.family) == null ? void 0 : _a3.subKey) || `null`),
250
1737
  newValue
251
1738
  );
252
1739
  },
@@ -260,10 +1747,10 @@ var useExposeMutableFamily = ({
260
1747
  socket.on(`unsub:${family.key}`, fillFamilyUnsubRequest);
261
1748
  } else {
262
1749
  const token = family(subKey);
263
- const jsonToken = Internal.getJsonToken(token);
264
- const updateToken = Internal.getUpdateToken(token);
265
- socket.emit(`init:${token.key}`, AtomIO4__namespace.getState(jsonToken, store));
266
- const unsubscribe = Internal.subscribeToState(
1750
+ const jsonToken = getJsonToken(token);
1751
+ const updateToken = getUpdateToken(token);
1752
+ socket.emit(`init:${token.key}`, getState(jsonToken, store));
1753
+ const unsubscribe = subscribeToState(
267
1754
  updateToken,
268
1755
  ({ newValue }) => {
269
1756
  socket.emit(`next:${token.key}`, newValue);
@@ -291,20 +1778,22 @@ var useExposeMutableFamily = ({
291
1778
  };
292
1779
  };
293
1780
  };
1781
+
1782
+ // realtime-server/src/hook-composition/receive-transaction.ts
294
1783
  var useReceiveTransaction = ({ socket, store }) => {
295
1784
  return function receiveTransaction(tx) {
296
- const fillTransactionRequest = (update) => AtomIO4__namespace.runTransaction(tx, store)(...update.params);
1785
+ const fillTransactionRequest = (update) => runTransaction(tx, store)(...update.params);
297
1786
  socket.on(`tx:${tx.key}`, fillTransactionRequest);
298
1787
  return () => socket.off(`tx:${tx.key}`, fillTransactionRequest);
299
1788
  };
300
1789
  };
301
1790
  function useSyncTransaction({
302
1791
  socket,
303
- store = Internal__namespace.IMPLICIT.STORE
1792
+ store = IMPLICIT.STORE
304
1793
  }) {
305
1794
  return function receiveTransaction(tx) {
306
1795
  const fillTransactionRequest = (update, transactionId) => {
307
- const unsubscribe = Internal__namespace.subscribeToTransaction(
1796
+ const unsubscribe = subscribeToTransaction(
308
1797
  tx,
309
1798
  (update2) => {
310
1799
  unsubscribe();
@@ -313,15 +1802,17 @@ function useSyncTransaction({
313
1802
  `sync:${transactionId}`,
314
1803
  store
315
1804
  );
316
- AtomIO4__namespace.runTransaction(tx, store)(...update.params);
1805
+ runTransaction(tx, store)(...update.params);
317
1806
  };
318
1807
  socket.on(`tx:${tx.key}`, fillTransactionRequest);
319
1808
  return () => socket.off(`tx:${tx.key}`, fillTransactionRequest);
320
1809
  };
321
1810
  }
1811
+
1812
+ // realtime-server/src/hook-composition/receive-state.ts
322
1813
  var useReceiveState = ({ socket, store }) => {
323
1814
  return function receiveState(token) {
324
- const publish = (newValue) => AtomIO4.setState(token, newValue, store);
1815
+ const publish = (newValue) => setState(token, newValue, store);
325
1816
  const fillPubUnclaim = () => {
326
1817
  socket.off(`pub:${token.key}`, publish);
327
1818
  socket.off(`unclaim:${token.key}`, fillPubUnclaim);