atom.io 0.6.7 → 0.6.9

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 (129) hide show
  1. package/dist/index.d.mts +241 -263
  2. package/dist/index.d.ts +241 -263
  3. package/dist/index.js +28 -1911
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +5 -1871
  6. package/dist/index.mjs.map +1 -1
  7. package/introspection/dist/index.d.mts +121 -176
  8. package/introspection/dist/index.d.ts +121 -176
  9. package/introspection/dist/index.js +6 -346
  10. package/introspection/dist/index.js.map +1 -1
  11. package/introspection/dist/index.mjs +5 -324
  12. package/introspection/dist/index.mjs.map +1 -1
  13. package/json/dist/index.d.mts +37 -8
  14. package/json/dist/index.d.ts +37 -8
  15. package/json/dist/index.js +31 -48
  16. package/json/dist/index.js.map +1 -1
  17. package/json/dist/index.mjs +6 -14
  18. package/json/dist/index.mjs.map +1 -1
  19. package/package.json +30 -14
  20. package/react/dist/index.js +34 -83
  21. package/react/dist/index.js.map +1 -1
  22. package/react/dist/index.mjs +7 -43
  23. package/react/dist/index.mjs.map +1 -1
  24. package/react-devtools/dist/index.css +1 -42
  25. package/react-devtools/dist/index.css.map +1 -1
  26. package/react-devtools/dist/index.d.mts +128 -193
  27. package/react-devtools/dist/index.d.ts +128 -193
  28. package/react-devtools/dist/index.js +56 -4154
  29. package/react-devtools/dist/index.js.map +1 -1
  30. package/react-devtools/dist/index.mjs +19 -4117
  31. package/react-devtools/dist/index.mjs.map +1 -1
  32. package/realtime/dist/index.d.mts +7 -11
  33. package/realtime/dist/index.d.ts +7 -11
  34. package/realtime/dist/index.js +26 -185
  35. package/realtime/dist/index.js.map +1 -1
  36. package/realtime/dist/index.mjs +4 -149
  37. package/realtime/dist/index.mjs.map +1 -1
  38. package/realtime-react/dist/index.d.mts +12 -16
  39. package/realtime-react/dist/index.d.ts +12 -16
  40. package/realtime-react/dist/index.js +41 -214
  41. package/realtime-react/dist/index.js.map +1 -1
  42. package/realtime-react/dist/index.mjs +9 -169
  43. package/realtime-react/dist/index.mjs.map +1 -1
  44. package/src/atom.ts +7 -6
  45. package/src/index.ts +12 -9
  46. package/src/logger.ts +5 -5
  47. package/src/selector.ts +16 -14
  48. package/src/silo.ts +36 -39
  49. package/src/subscribe.ts +25 -20
  50. package/src/timeline.ts +9 -4
  51. package/src/transaction.ts +3 -4
  52. package/src/internal/atom-internal.ts +0 -54
  53. package/src/internal/families-internal.ts +0 -141
  54. package/src/internal/get.ts +0 -129
  55. package/src/internal/index.ts +0 -15
  56. package/src/internal/is-default.ts +0 -35
  57. package/src/internal/operation.ts +0 -139
  58. package/src/internal/selector/create-read-write-selector.ts +0 -66
  59. package/src/internal/selector/create-readonly-selector.ts +0 -46
  60. package/src/internal/selector/index.ts +0 -4
  61. package/src/internal/selector/lookup-selector-sources.ts +0 -16
  62. package/src/internal/selector/register-selector.ts +0 -57
  63. package/src/internal/selector/trace-selector-atoms.ts +0 -43
  64. package/src/internal/selector/update-selector-atoms.ts +0 -33
  65. package/src/internal/selector-internal.ts +0 -58
  66. package/src/internal/set.ts +0 -99
  67. package/src/internal/store.ts +0 -151
  68. package/src/internal/subject.ts +0 -24
  69. package/src/internal/subscribe-internal.ts +0 -88
  70. package/src/internal/time-travel-internal.ts +0 -91
  71. package/src/internal/timeline/add-atom-to-timeline.ts +0 -168
  72. package/src/internal/timeline/index.ts +0 -1
  73. package/src/internal/timeline-internal.ts +0 -107
  74. package/src/internal/transaction/abort-transaction.ts +0 -12
  75. package/src/internal/transaction/apply-transaction.ts +0 -57
  76. package/src/internal/transaction/build-transaction.ts +0 -33
  77. package/src/internal/transaction/index.ts +0 -25
  78. package/src/internal/transaction/redo-transaction.ts +0 -23
  79. package/src/internal/transaction/undo-transaction.ts +0 -23
  80. package/src/internal/transaction-internal.ts +0 -61
  81. package/src/introspection/attach-atom-index.ts +0 -73
  82. package/src/introspection/attach-introspection-states.ts +0 -42
  83. package/src/introspection/attach-selector-index.ts +0 -77
  84. package/src/introspection/attach-timeline-family.ts +0 -59
  85. package/src/introspection/attach-timeline-index.ts +0 -36
  86. package/src/introspection/attach-transaction-index.ts +0 -38
  87. package/src/introspection/attach-transaction-logs.ts +0 -40
  88. package/src/introspection/index.ts +0 -20
  89. package/src/json/index.ts +0 -1
  90. package/src/json/select-json.ts +0 -18
  91. package/src/react/index.ts +0 -2
  92. package/src/react/store-context.tsx +0 -13
  93. package/src/react/store-hooks.ts +0 -47
  94. package/src/react-devtools/AtomIODevtools.tsx +0 -107
  95. package/src/react-devtools/Button.tsx +0 -24
  96. package/src/react-devtools/StateEditor.tsx +0 -70
  97. package/src/react-devtools/StateIndex.tsx +0 -153
  98. package/src/react-devtools/TimelineIndex.tsx +0 -92
  99. package/src/react-devtools/TransactionIndex.tsx +0 -70
  100. package/src/react-devtools/Updates.tsx +0 -145
  101. package/src/react-devtools/devtools.scss +0 -311
  102. package/src/react-devtools/index.ts +0 -72
  103. package/src/react-explorer/AtomIOExplorer.tsx +0 -218
  104. package/src/react-explorer/explorer-effects.ts +0 -20
  105. package/src/react-explorer/explorer-states.ts +0 -217
  106. package/src/react-explorer/index.ts +0 -23
  107. package/src/react-explorer/space-states.ts +0 -72
  108. package/src/react-explorer/view-states.ts +0 -41
  109. package/src/realtime/README.md +0 -33
  110. package/src/realtime/hook-composition/expose-family.ts +0 -101
  111. package/src/realtime/hook-composition/expose-single.ts +0 -38
  112. package/src/realtime/hook-composition/expose-timeline.ts +0 -60
  113. package/src/realtime/hook-composition/index.ts +0 -12
  114. package/src/realtime/hook-composition/receive-state.ts +0 -29
  115. package/src/realtime/hook-composition/receive-transaction.ts +0 -18
  116. package/src/realtime/index.ts +0 -1
  117. package/src/realtime-react/index.ts +0 -3
  118. package/src/realtime-react/realtime-context.tsx +0 -30
  119. package/src/realtime-react/realtime-hooks.ts +0 -39
  120. package/src/realtime-react/realtime-state.ts +0 -10
  121. package/src/realtime-react/use-pull-family-member.ts +0 -26
  122. package/src/realtime-react/use-pull-family.ts +0 -24
  123. package/src/realtime-react/use-pull.ts +0 -22
  124. package/src/realtime-react/use-push.ts +0 -25
  125. package/src/realtime-react/use-server-action.ts +0 -33
  126. package/src/realtime-testing/index.ts +0 -1
  127. package/src/realtime-testing/setup-realtime-test.tsx +0 -159
  128. package/src/web-effects/index.ts +0 -1
  129. package/src/web-effects/storage.ts +0 -30
@@ -1,23 +1,19 @@
1
1
  import * as AtomIO from 'atom.io';
2
2
  import * as SocketIO from 'socket.io';
3
3
 
4
- type Primitive = boolean | number | string | null;
5
- type Serializable = Primitive | Readonly<{
4
+ type primitive = boolean | number | string | null;
5
+
6
+ type Serializable = primitive | Readonly<{
6
7
  [key: string]: Serializable;
7
8
  }> | ReadonlyArray<Serializable>;
8
- type JsonObj<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
9
- type JsonArr<Element extends Serializable = Serializable> = ReadonlyArray<Element>;
10
- type Json = JsonArr | JsonObj | Primitive;
11
-
12
- declare const useExposeSingle: ({ socket, store }: ServerConfig) => <J extends Json>(token: AtomIO.StateToken<J>) => () => void;
13
9
 
14
- declare const useExposeFamily: ({ socket, store }: ServerConfig) => <J extends Json>(family: AtomIO.AtomFamily<J, AtomIO.Serializable> | AtomIO.SelectorFamily<J, AtomIO.Serializable>, index: AtomIO.StateToken<Set<string>>) => () => void;
10
+ declare const useExposeSingle: ({ socket, store }: ServerConfig) => <J extends Serializable>(token: AtomIO.StateToken<J>) => () => void;
15
11
 
16
- type ƒn = (...parameters: any[]) => any;
12
+ declare const useExposeFamily: ({ socket, store }: ServerConfig) => <J extends Serializable>(family: AtomIO.AtomFamily<J, Serializable> | AtomIO.SelectorFamily<J, Serializable>, index: AtomIO.StateToken<Set<string>>) => () => void;
17
13
 
18
- declare const useReceiveTransaction: ({ socket, store }: ServerConfig) => <ƒ extends ƒn>(tx: AtomIO.TransactionToken<ƒ>) => () => void;
14
+ declare const useReceiveTransaction: ({ socket, store }: ServerConfig) => <ƒ extends AtomIO.ƒn>(tx: AtomIO.TransactionToken<ƒ>) => () => void;
19
15
 
20
- declare const useReceiveState: ({ socket, store }: ServerConfig) => <J extends Json>(token: AtomIO.StateToken<J>) => () => void;
16
+ declare const useReceiveState: ({ socket, store }: ServerConfig) => <J extends Serializable>(token: AtomIO.StateToken<J>) => () => void;
21
17
 
22
18
  type ServerConfig = {
23
19
  socket: SocketIO.Socket;
@@ -1,23 +1,19 @@
1
1
  import * as AtomIO from 'atom.io';
2
2
  import * as SocketIO from 'socket.io';
3
3
 
4
- type Primitive = boolean | number | string | null;
5
- type Serializable = Primitive | Readonly<{
4
+ type primitive = boolean | number | string | null;
5
+
6
+ type Serializable = primitive | Readonly<{
6
7
  [key: string]: Serializable;
7
8
  }> | ReadonlyArray<Serializable>;
8
- type JsonObj<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
9
- type JsonArr<Element extends Serializable = Serializable> = ReadonlyArray<Element>;
10
- type Json = JsonArr | JsonObj | Primitive;
11
-
12
- declare const useExposeSingle: ({ socket, store }: ServerConfig) => <J extends Json>(token: AtomIO.StateToken<J>) => () => void;
13
9
 
14
- declare const useExposeFamily: ({ socket, store }: ServerConfig) => <J extends Json>(family: AtomIO.AtomFamily<J, AtomIO.Serializable> | AtomIO.SelectorFamily<J, AtomIO.Serializable>, index: AtomIO.StateToken<Set<string>>) => () => void;
10
+ declare const useExposeSingle: ({ socket, store }: ServerConfig) => <J extends Serializable>(token: AtomIO.StateToken<J>) => () => void;
15
11
 
16
- type ƒn = (...parameters: any[]) => any;
12
+ declare const useExposeFamily: ({ socket, store }: ServerConfig) => <J extends Serializable>(family: AtomIO.AtomFamily<J, Serializable> | AtomIO.SelectorFamily<J, Serializable>, index: AtomIO.StateToken<Set<string>>) => () => void;
17
13
 
18
- declare const useReceiveTransaction: ({ socket, store }: ServerConfig) => <ƒ extends ƒn>(tx: AtomIO.TransactionToken<ƒ>) => () => void;
14
+ declare const useReceiveTransaction: ({ socket, store }: ServerConfig) => <ƒ extends AtomIO.ƒn>(tx: AtomIO.TransactionToken<ƒ>) => () => void;
19
15
 
20
- declare const useReceiveState: ({ socket, store }: ServerConfig) => <J extends Json>(token: AtomIO.StateToken<J>) => () => void;
16
+ declare const useReceiveState: ({ socket, store }: ServerConfig) => <J extends Serializable>(token: AtomIO.StateToken<J>) => () => void;
21
17
 
22
18
  type ServerConfig = {
23
19
  socket: SocketIO.Socket;
@@ -1,191 +1,32 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
28
2
 
29
- // ../src/realtime/index.ts
30
- var realtime_exports = {};
31
- __export(realtime_exports, {
32
- useExposeFamily: () => useExposeFamily,
33
- useExposeSingle: () => useExposeSingle,
34
- useReceiveState: () => useReceiveState,
35
- useReceiveTransaction: () => useReceiveTransaction
36
- });
37
- module.exports = __toCommonJS(realtime_exports);
3
+ var m = require('atom.io');
38
4
 
39
- // ../src/realtime/hook-composition/expose-single.ts
40
- var AtomIO = __toESM(require("atom.io"));
41
- var useExposeSingle = ({ socket, store }) => {
42
- return function exposeSingle(token) {
43
- let unsubscribeFromStateUpdates = null;
44
- const fillUnsubRequest = () => {
45
- socket.off(`unsub:${token.key}`, fillUnsubRequest);
46
- unsubscribeFromStateUpdates == null ? void 0 : unsubscribeFromStateUpdates();
47
- unsubscribeFromStateUpdates = null;
48
- };
49
- const fillSubRequest = () => {
50
- socket.emit(`serve:${token.key}`, AtomIO.getState(token, store));
51
- unsubscribeFromStateUpdates = AtomIO.subscribe(
52
- token,
53
- ({ newValue }) => {
54
- socket.emit(`serve:${token.key}`, newValue);
55
- },
56
- store
57
- );
58
- socket.on(`unsub:${token.key}`, fillUnsubRequest);
59
- };
60
- socket.on(`sub:${token.key}`, fillSubRequest);
61
- return () => {
62
- socket.off(`sub:${token.key}`, fillSubRequest);
63
- unsubscribeFromStateUpdates == null ? void 0 : unsubscribeFromStateUpdates();
64
- };
65
- };
66
- };
5
+ function _interopNamespace(e) {
6
+ if (e && e.__esModule) return e;
7
+ var n = Object.create(null);
8
+ if (e) {
9
+ Object.keys(e).forEach(function (k) {
10
+ if (k !== 'default') {
11
+ var d = Object.getOwnPropertyDescriptor(e, k);
12
+ Object.defineProperty(n, k, d.get ? d : {
13
+ enumerable: true,
14
+ get: function () { return e[k]; }
15
+ });
16
+ }
17
+ });
18
+ }
19
+ n.default = e;
20
+ return Object.freeze(n);
21
+ }
67
22
 
68
- // ../../anvl/src/json/index.ts
69
- var import_function = require("fp-ts/function");
70
- var parseJson = (str) => JSON.parse(str);
23
+ var m__namespace = /*#__PURE__*/_interopNamespace(m);
71
24
 
72
- // ../src/realtime/hook-composition/expose-family.ts
73
- var AtomIO2 = __toESM(require("atom.io"));
74
- var subscribeToTokenCreation = (family, handleTokenCreation) => {
75
- const subscription = family.type === `atom_family` ? family.subject.subscribe(handleTokenCreation) : family.subject.subscribe(handleTokenCreation);
76
- return () => subscription.unsubscribe();
77
- };
78
- var useExposeFamily = ({ socket, store }) => {
79
- return function exposeFamily(family, index) {
80
- const unsubSingleCallbacksByKey = /* @__PURE__ */ new Map();
81
- const unsubFamilyCallbacksByKey = /* @__PURE__ */ new Map();
82
- const fillFamilyUnsubRequest = () => {
83
- unsubFamilyCallbacksByKey.forEach((unsub) => unsub());
84
- unsubFamilyCallbacksByKey.clear();
85
- socket.off(`unsub:${family.key}`, fillFamilyUnsubRequest);
86
- };
87
- const fillSingleUnsubRequest = (key) => {
88
- socket.off(`unsub:${key}`, fillSingleUnsubRequest);
89
- const unsub = unsubSingleCallbacksByKey.get(key);
90
- if (unsub) {
91
- unsub();
92
- unsubSingleCallbacksByKey.delete(key);
93
- }
94
- };
95
- const fillSubRequest = (subKey) => {
96
- if (subKey === void 0) {
97
- const keys = AtomIO2.getState(index, store);
98
- keys.forEach((key) => {
99
- var _a;
100
- const token = family(key);
101
- socket.emit(
102
- `serve:${family.key}`,
103
- parseJson(((_a = token.family) == null ? void 0 : _a.subKey) || `null`),
104
- AtomIO2.getState(token, store)
105
- );
106
- });
107
- const unsubscribeFromTokenCreation = subscribeToTokenCreation(
108
- family,
109
- (token) => {
110
- const unsub = AtomIO2.subscribe(
111
- token,
112
- ({ newValue }) => {
113
- var _a;
114
- socket.emit(
115
- `serve:${family.key}`,
116
- parseJson(((_a = token.family) == null ? void 0 : _a.subKey) || `null`),
117
- newValue
118
- );
119
- },
120
- store
121
- );
122
- unsubFamilyCallbacksByKey.set(token.key, unsub);
123
- }
124
- );
125
- unsubFamilyCallbacksByKey.set(family.key, unsubscribeFromTokenCreation);
126
- socket.on(`unsub:${family.key}`, fillFamilyUnsubRequest);
127
- } else {
128
- const token = family(subKey);
129
- socket.emit(`serve:${token.key}`, AtomIO2.getState(token, store));
130
- const unsubscribe = AtomIO2.subscribe(
131
- token,
132
- ({ newValue }) => {
133
- socket.emit(`serve:${token.key}`, newValue);
134
- },
135
- store
136
- );
137
- unsubSingleCallbacksByKey.set(token.key, unsubscribe);
138
- socket.on(`unsub:${token.key}`, () => {
139
- fillSingleUnsubRequest(token.key);
140
- });
141
- }
142
- };
143
- socket.on(`sub:${family.key}`, fillSubRequest);
144
- return () => {
145
- socket.off(`sub:${family.key}`, fillSubRequest);
146
- unsubFamilyCallbacksByKey.forEach((unsub) => unsub());
147
- unsubSingleCallbacksByKey.forEach((unsub) => unsub());
148
- unsubFamilyCallbacksByKey.clear();
149
- unsubSingleCallbacksByKey.clear();
150
- };
151
- };
152
- };
25
+ var $=({socket:e,store:t})=>function(o){let n=null,r=()=>{e.off(`unsub:${o.key}`,r),n==null||n(),n=null;},i=()=>{e.emit(`serve:${o.key}`,m__namespace.getState(o,t)),n=m__namespace.subscribe(o,({newValue:f})=>{e.emit(`serve:${o.key}`,f);},`expose-single:${e.id}`,t),e.on(`unsub:${o.key}`,r);};return e.on(`sub:${o.key}`,i),()=>{e.off(`sub:${o.key}`,i),n==null||n();}};var S=e=>JSON.parse(e);var v=(e,t,l)=>(e.type==="atom_family",e.subject.subscribe(t,l)),E=({socket:e,store:t})=>function(o,n){let r=new Map,i=new Map,f=()=>{i.forEach(s=>s()),i.clear(),e.off(`unsub:${o.key}`,f);},J=s=>{e.off(`unsub:${s}`,J);let a=r.get(s);a&&(a(),r.delete(s));},g=s=>{if(s===void 0){m__namespace.getState(n,t).forEach(u=>{var b;let p=o(u);e.emit(`serve:${o.key}`,S(((b=p.family)==null?void 0:b.subKey)||"null"),m__namespace.getState(p,t));});let c=v(o,`expose-family:${e.id}`,u=>{let p=m__namespace.subscribe(u,({newValue:b})=>{var x;e.emit(`serve:${o.key}`,S(((x=u.family)==null?void 0:x.subKey)||"null"),b);},`expose-family:${o.key}:${e.id}`,t);i.set(u.key,p);});i.set(o.key,c),e.on(`unsub:${o.key}`,f);}else {let a=o(s);e.emit(`serve:${a.key}`,m__namespace.getState(a,t));let c=m__namespace.subscribe(a,({newValue:u})=>{e.emit(`serve:${a.key}`,u);},`expose-family:${o.key}:${e.id}`,t);r.set(a.key,c),e.on(`unsub:${a.key}`,()=>{J(a.key);});}};return e.on(`sub:${o.key}`,g),()=>{e.off(`sub:${o.key}`,g),i.forEach(s=>s()),r.forEach(s=>s()),i.clear(),r.clear();}};var j=({socket:e,store:t})=>function(o){let n=r=>m__namespace.runTransaction(o,t)(...r.params);return e.on(`tx:${o.key}`,n),()=>e.off(`tx:${o.key}`,n)};var R=({socket:e,store:t})=>function(o){let n=f=>m__namespace.setState(o,f,t),r=()=>{e.off(`pub:${o.key}`,n),e.off(`unclaim:${o.key}`,r);},i=()=>{e.on(`pub:${o.key}`,n),e.on(`unclaim:${o.key}`,r);};return e.on(`claim:${o.key}`,i),()=>{e.off(`claim:${o.key}`,i),e.off(`pub:${o.key}`,n);}};
153
26
 
154
- // ../src/realtime/hook-composition/receive-transaction.ts
155
- var AtomIO3 = __toESM(require("atom.io"));
156
- var useReceiveTransaction = ({ socket, store }) => {
157
- return function receiveTransaction(tx) {
158
- const fillTransactionRequest = (update) => AtomIO3.runTransaction(tx, store)(...update.params);
159
- socket.on(`tx:${tx.key}`, fillTransactionRequest);
160
- return () => socket.off(`tx:${tx.key}`, fillTransactionRequest);
161
- };
162
- };
163
-
164
- // ../src/realtime/hook-composition/receive-state.ts
165
- var AtomIO4 = __toESM(require("atom.io"));
166
- var useReceiveState = ({ socket, store }) => {
167
- return function receiveState(token) {
168
- const publish = (newValue) => AtomIO4.setState(token, newValue, store);
169
- const fillPubUnclaim = () => {
170
- socket.off(`pub:${token.key}`, publish);
171
- socket.off(`unclaim:${token.key}`, fillPubUnclaim);
172
- };
173
- const fillPubClaim = () => {
174
- socket.on(`pub:${token.key}`, publish);
175
- socket.on(`unclaim:${token.key}`, fillPubUnclaim);
176
- };
177
- socket.on(`claim:${token.key}`, fillPubClaim);
178
- return () => {
179
- socket.off(`claim:${token.key}`, fillPubClaim);
180
- socket.off(`pub:${token.key}`, publish);
181
- };
182
- };
183
- };
184
- // Annotate the CommonJS export names for ESM import in node:
185
- 0 && (module.exports = {
186
- useExposeFamily,
187
- useExposeSingle,
188
- useReceiveState,
189
- useReceiveTransaction
190
- });
27
+ exports.useExposeFamily = E;
28
+ exports.useExposeSingle = $;
29
+ exports.useReceiveState = R;
30
+ exports.useReceiveTransaction = j;
31
+ //# sourceMappingURL=out.js.map
191
32
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/realtime/index.ts","../../src/realtime/hook-composition/expose-single.ts","../../../anvl/src/json/index.ts","../../src/realtime/hook-composition/expose-family.ts","../../src/realtime/hook-composition/receive-transaction.ts","../../src/realtime/hook-composition/receive-state.ts"],"sourcesContent":["export * from \"./hook-composition\"\n","import type { Json } from \"anvl/json\"\nimport * as AtomIO from \"atom.io\"\n\nimport type { ServerConfig } from \"..\"\n\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nexport const useExposeSingle = ({ socket, store }: ServerConfig) => {\n\treturn function exposeSingle<J extends Json>(\n\t\ttoken: AtomIO.StateToken<J>,\n\t): () => void {\n\t\tlet unsubscribeFromStateUpdates: (() => void) | null = null\n\n\t\tconst fillUnsubRequest = () => {\n\t\t\tsocket.off(`unsub:${token.key}`, fillUnsubRequest)\n\t\t\tunsubscribeFromStateUpdates?.()\n\t\t\tunsubscribeFromStateUpdates = null\n\t\t}\n\n\t\tconst fillSubRequest = () => {\n\t\t\tsocket.emit(`serve:${token.key}`, AtomIO.getState(token, store))\n\t\t\tunsubscribeFromStateUpdates = AtomIO.subscribe(\n\t\t\t\ttoken,\n\t\t\t\t({ newValue }) => {\n\t\t\t\t\tsocket.emit(`serve:${token.key}`, newValue)\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\t\t\tsocket.on(`unsub:${token.key}`, fillUnsubRequest)\n\t\t}\n\n\t\tsocket.on(`sub:${token.key}`, fillSubRequest)\n\n\t\treturn () => {\n\t\t\tsocket.off(`sub:${token.key}`, fillSubRequest)\n\t\t\tunsubscribeFromStateUpdates?.()\n\t\t}\n\t}\n}\n","import { pipe } from \"fp-ts/function\"\n\nexport * from \"./refine\"\nexport * from \"./json-interface\"\n\nexport const serializeSet = <T>(set: Set<T>): string =>\n\tpipe(set, Array.from, JSON.stringify)\n\nexport const deserializeSet = <T>(str: string): Set<T> =>\n\tpipe(str, JSON.parse, Array.from, (a) => new Set(a as T[]))\n\nexport type Primitive = boolean | number | string | null\n\nexport type Serializable =\n\t| Primitive\n\t| Readonly<{ [key: string]: Serializable }>\n\t| ReadonlyArray<Serializable>\n\nexport type JsonObj<\n\tKey extends string = string,\n\tValue extends Serializable = Serializable,\n> = Record<Key, Value>\n\nexport type JsonArr<Element extends Serializable = Serializable> =\n\tReadonlyArray<Element>\n\nexport type Json = JsonArr | JsonObj | Primitive\n\nexport const parseJson = <S extends Stringified<Json>>(\n\tstr: S | string,\n): S extends Stringified<infer J> ? J : Json => JSON.parse(str)\n\nexport type Stringified<J extends Json> = string & { __json: J }\n\nexport const stringifyJson = <J extends Json>(json: J): Stringified<J> =>\n\tJSON.stringify(json) as Stringified<J>\n\nexport type Empty = Record<string, never>\n\nexport const JSON_TYPE_NAMES = [\n\t`array`,\n\t`boolean`,\n\t`null`,\n\t`number`,\n\t`object`,\n\t`string`,\n] as const\n\nexport type JsonTypeName = typeof JSON_TYPE_NAMES[number]\n\nexport interface JsonTypes extends Record<JsonTypeName, Json> {\n\tarray: JsonArr\n\tboolean: boolean\n\tnull: null\n\tnumber: number\n\tobject: JsonObj\n\tstring: string\n}\n\nexport const JSON_DEFAULTS: JsonTypes = {\n\tarray: [],\n\tboolean: false,\n\tnull: null,\n\tnumber: 0,\n\tobject: {},\n\tstring: ``,\n}\n","import type { Json } from \"anvl/json\"\nimport { parseJson } from \"anvl/json\"\nimport * as AtomIO from \"atom.io\"\n\nimport type { ServerConfig } from \"..\"\n\nconst subscribeToTokenCreation = <T>(\n\tfamily: AtomIO.AtomFamily<T> | AtomIO.SelectorFamily<T>,\n\thandleTokenCreation: (token: AtomIO.StateToken<T>) => void,\n): (() => void) => {\n\tconst subscription =\n\t\tfamily.type === `atom_family`\n\t\t\t? family.subject.subscribe(handleTokenCreation)\n\t\t\t: family.subject.subscribe(handleTokenCreation)\n\treturn () => subscription.unsubscribe()\n}\n\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nexport const useExposeFamily = ({ socket, store }: ServerConfig) => {\n\treturn function exposeFamily<J extends Json>(\n\t\tfamily: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,\n\t\tindex: AtomIO.StateToken<Set<string>>,\n\t): () => void {\n\t\tconst unsubSingleCallbacksByKey = new Map<string, () => void>()\n\t\tconst unsubFamilyCallbacksByKey = new Map<string, () => void>()\n\n\t\tconst fillFamilyUnsubRequest = () => {\n\t\t\tunsubFamilyCallbacksByKey.forEach((unsub) => unsub())\n\t\t\tunsubFamilyCallbacksByKey.clear()\n\t\t\tsocket.off(`unsub:${family.key}`, fillFamilyUnsubRequest)\n\t\t}\n\n\t\tconst fillSingleUnsubRequest = (key: string) => {\n\t\t\tsocket.off(`unsub:${key}`, fillSingleUnsubRequest)\n\t\t\tconst unsub = unsubSingleCallbacksByKey.get(key)\n\t\t\tif (unsub) {\n\t\t\t\tunsub()\n\t\t\t\tunsubSingleCallbacksByKey.delete(key)\n\t\t\t}\n\t\t}\n\n\t\tconst fillSubRequest = (subKey?: AtomIO.Serializable) => {\n\t\t\tif (subKey === undefined) {\n\t\t\t\tconst keys = AtomIO.getState(index, store)\n\t\t\t\tkeys.forEach((key) => {\n\t\t\t\t\tconst token = family(key)\n\t\t\t\t\tsocket.emit(\n\t\t\t\t\t\t`serve:${family.key}`,\n\t\t\t\t\t\tparseJson(token.family?.subKey || `null`),\n\t\t\t\t\t\tAtomIO.getState(token, store),\n\t\t\t\t\t)\n\t\t\t\t})\n\n\t\t\t\tconst unsubscribeFromTokenCreation = subscribeToTokenCreation(\n\t\t\t\t\tfamily,\n\t\t\t\t\t(token) => {\n\t\t\t\t\t\tconst unsub = AtomIO.subscribe(\n\t\t\t\t\t\t\ttoken,\n\t\t\t\t\t\t\t({ newValue }) => {\n\t\t\t\t\t\t\t\tsocket.emit(\n\t\t\t\t\t\t\t\t\t`serve:${family.key}`,\n\t\t\t\t\t\t\t\t\tparseJson(token.family?.subKey || `null`),\n\t\t\t\t\t\t\t\t\tnewValue,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tunsubFamilyCallbacksByKey.set(token.key, unsub)\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\t\tunsubFamilyCallbacksByKey.set(family.key, unsubscribeFromTokenCreation)\n\n\t\t\t\tsocket.on(`unsub:${family.key}`, fillFamilyUnsubRequest)\n\t\t\t} else {\n\t\t\t\tconst token = family(subKey)\n\t\t\t\tsocket.emit(`serve:${token.key}`, AtomIO.getState(token, store))\n\t\t\t\tconst unsubscribe = AtomIO.subscribe(\n\t\t\t\t\ttoken,\n\t\t\t\t\t({ newValue }) => {\n\t\t\t\t\t\tsocket.emit(`serve:${token.key}`, newValue)\n\t\t\t\t\t},\n\t\t\t\t\tstore,\n\t\t\t\t)\n\t\t\t\tunsubSingleCallbacksByKey.set(token.key, unsubscribe)\n\t\t\t\tsocket.on(`unsub:${token.key}`, () => {\n\t\t\t\t\tfillSingleUnsubRequest(token.key)\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\tsocket.on(`sub:${family.key}`, fillSubRequest)\n\n\t\treturn () => {\n\t\t\tsocket.off(`sub:${family.key}`, fillSubRequest)\n\t\t\tunsubFamilyCallbacksByKey.forEach((unsub) => unsub())\n\t\t\tunsubSingleCallbacksByKey.forEach((unsub) => unsub())\n\t\t\tunsubFamilyCallbacksByKey.clear()\n\t\t\tunsubSingleCallbacksByKey.clear()\n\t\t}\n\t}\n}\n","import * as AtomIO from \"atom.io\"\n\nimport type { ƒn } from \"~/packages/anvl/src/function\"\n\nimport type { ServerConfig } from \".\"\n\nexport const useReceiveTransaction = ({ socket, store }: ServerConfig) => {\n\treturn function receiveTransaction<ƒ extends ƒn>(\n\t\ttx: AtomIO.TransactionToken<ƒ>,\n\t): () => void {\n\t\tconst fillTransactionRequest = (update: AtomIO.TransactionUpdate<ƒ>) =>\n\t\t\tAtomIO.runTransaction<ƒ>(tx, store)(...update.params)\n\n\t\tsocket.on(`tx:${tx.key}`, fillTransactionRequest)\n\n\t\treturn () => socket.off(`tx:${tx.key}`, fillTransactionRequest)\n\t}\n}\n","import type { Json } from \"anvl/json\"\nimport * as AtomIO from \"atom.io\"\n\nimport type { ServerConfig } from \"..\"\n\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nexport const useReceiveState = ({ socket, store }: ServerConfig) => {\n\treturn function receiveState<J extends Json>(\n\t\ttoken: AtomIO.StateToken<J>,\n\t): () => void {\n\t\tconst publish = (newValue: J) => AtomIO.setState(token, newValue, store)\n\n\t\tconst fillPubUnclaim = () => {\n\t\t\tsocket.off(`pub:${token.key}`, publish)\n\t\t\tsocket.off(`unclaim:${token.key}`, fillPubUnclaim)\n\t\t}\n\t\tconst fillPubClaim = () => {\n\t\t\tsocket.on(`pub:${token.key}`, publish)\n\t\t\tsocket.on(`unclaim:${token.key}`, fillPubUnclaim)\n\t\t}\n\n\t\tsocket.on(`claim:${token.key}`, fillPubClaim)\n\n\t\treturn () => {\n\t\t\tsocket.off(`claim:${token.key}`, fillPubClaim)\n\t\t\tsocket.off(`pub:${token.key}`, publish)\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,aAAwB;AAKjB,IAAM,kBAAkB,CAAC,EAAE,QAAQ,MAAM,MAAoB;AACnE,SAAO,SAAS,aACf,OACa;AACb,QAAI,8BAAmD;AAEvD,UAAM,mBAAmB,MAAM;AAC9B,aAAO,IAAI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tomIO","AtomIO","AtomIO"]}
1
+ {"version":3,"sources":["../src/hook-composition/expose-single.ts","../../../anvl/src/json/index.ts","../src/hook-composition/expose-family.ts","../src/hook-composition/receive-transaction.ts","../src/hook-composition/receive-state.ts"],"names":["AtomIO","useExposeSingle","socket","store","token","unsubscribeFromStateUpdates","fillUnsubRequest","fillSubRequest","newValue","parseJson","str","subscribeToTokenCreation","family","key","handleTokenCreation","useExposeFamily","index","unsubSingleCallbacksByKey","unsubFamilyCallbacksByKey","fillFamilyUnsubRequest","unsub","fillSingleUnsubRequest","subKey","_a","unsubscribeFromTokenCreation","unsubscribe","useReceiveTransaction","tx","fillTransactionRequest","update","useReceiveState","publish","fillPubUnclaim","fillPubClaim"],"mappings":"AACA,UAAYA,MAAY,UAKjB,IAAMC,EAAkB,CAAC,CAAE,OAAAC,EAAQ,MAAAC,CAAM,IACxC,SACNC,EACa,CACb,IAAIC,EAAmD,KAEjDC,EAAmB,IAAM,CAC9BJ,EAAO,IAAI,SAASE,EAAM,GAAG,GAAIE,CAAgB,EACjDD,GAAA,MAAAA,IACAA,EAA8B,IAC/B,EAEME,EAAiB,IAAM,CAC5BL,EAAO,KAAK,SAASE,EAAM,GAAG,GAAW,WAASA,EAAOD,CAAK,CAAC,EAC/DE,EAAqC,YACpCD,EACA,CAAC,CAAE,SAAAI,CAAS,IAAM,CACjBN,EAAO,KAAK,SAASE,EAAM,GAAG,GAAII,CAAQ,CAC3C,EACA,iBAAiBN,EAAO,EAAE,GAC1BC,CACD,EACAD,EAAO,GAAG,SAASE,EAAM,GAAG,GAAIE,CAAgB,CACjD,EAEA,OAAAJ,EAAO,GAAG,OAAOE,EAAM,GAAG,GAAIG,CAAc,EAErC,IAAM,CACZL,EAAO,IAAI,OAAOE,EAAM,GAAG,GAAIG,CAAc,EAC7CF,GAAA,MAAAA,GACD,CACD,ECjCM,IAAMI,EACZC,GAC4D,KAAK,MAAMA,CAAG,ECJ3E,UAAYV,MAAY,UAIxB,IAAMW,EAA2B,C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9B,EAAO,IAAI,OAAOE,EAAM,GAAG,GAAI2B,CAAO,EACtC7B,EAAO,IAAI,WAAWE,EAAM,GAAG,GAAI4B,CAAc,CAClD,EACMC,EAAe,IAAM,CAC1B/B,EAAO,GAAG,OAAOE,EAAM,GAAG,GAAI2B,CAAO,EACrC7B,EAAO,GAAG,WAAWE,EAAM,GAAG,GAAI4B,CAAc,CACjD,EAEA,OAAA9B,EAAO,GAAG,SAASE,EAAM,GAAG,GAAI6B,CAAY,EAErC,IAAM,CACZ/B,EAAO,IAAI,SAASE,EAAM,GAAG,GAAI6B,CAAY,EAC7C/B,EAAO,IAAI,OAAOE,EAAM,GAAG,GAAI2B,CAAO,CACvC,CACD","sourcesContent":["import type { Json } from \"anvl/json\"\nimport * as AtomIO from \"atom.io\"\n\nimport type { ServerConfig } from \"..\"\n\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nexport const useExposeSingle = ({ socket, store }: ServerConfig) => {\n\treturn function exposeSingle<J extends Json.Serializable>(\n\t\ttoken: AtomIO.StateToken<J>,\n\t): () => void {\n\t\tlet unsubscribeFromStateUpdates: (() => void) | null = null\n\n\t\tconst fillUnsubRequest = () => {\n\t\t\tsocket.off(`unsub:${token.key}`, fillUnsubRequest)\n\t\t\tunsubscribeFromStateUpdates?.()\n\t\t\tunsubscribeFromStateUpdates = null\n\t\t}\n\n\t\tconst fillSubRequest = () => {\n\t\t\tsocket.emit(`serve:${token.key}`, AtomIO.getState(token, store))\n\t\t\tunsubscribeFromStateUpdates = AtomIO.subscribe(\n\t\t\t\ttoken,\n\t\t\t\t({ newValue }) => {\n\t\t\t\t\tsocket.emit(`serve:${token.key}`, newValue)\n\t\t\t\t},\n\t\t\t\t`expose-single:${socket.id}`,\n\t\t\t\tstore,\n\t\t\t)\n\t\t\tsocket.on(`unsub:${token.key}`, fillUnsubRequest)\n\t\t}\n\n\t\tsocket.on(`sub:${token.key}`, fillSubRequest)\n\n\t\treturn () => {\n\t\t\tsocket.off(`sub:${token.key}`, fillSubRequest)\n\t\t\tunsubscribeFromStateUpdates?.()\n\t\t}\n\t}\n}\n","export * from \"./json-interface\"\nimport type * as Json from \"./json\"\nexport { Json }\n\nexport const parseJson = <S extends Stringified<Json.Serializable>>(\n\tstr: S | string,\n): S extends Stringified<infer J> ? J : Json.Serializable => JSON.parse(str)\n\nexport type Stringified<J extends Json.Serializable> = string & { __json: J }\n\nexport const stringifyJson = <J extends Json.Serializable>(\n\tjson: J,\n): Stringified<J> => JSON.stringify(json) as Stringified<J>\n\nexport type Empty = Record<string, never>\n\nexport const JSON_TYPE_NAMES = [\n\t`array`,\n\t`boolean`,\n\t`null`,\n\t`number`,\n\t`object`,\n\t`string`,\n] as const\n\nexport type JsonTypeName = typeof JSON_TYPE_NAMES[number]\n\nexport interface JsonTypes extends Record<JsonTypeName, Json.Serializable> {\n\tarray: Json.Array\n\tboolean: boolean\n\tnull: null\n\tnumber: number\n\tobject: Json.Object\n\tstring: string\n}\n\nexport const JSON_DEFAULTS: JsonTypes = {\n\tarray: [],\n\tboolean: false,\n\tnull: null,\n\tnumber: 0,\n\tobject: {},\n\tstring: ``,\n}\n","import type { Json } from \"anvl/json\"\nimport { parseJson } from \"anvl/json\"\nimport * as AtomIO from \"atom.io\"\n\nimport type { ServerConfig } from \"..\"\n\nconst subscribeToTokenCreation = <T>(\n\tfamily: AtomIO.AtomFamily<T> | AtomIO.SelectorFamily<T>,\n\tkey: string,\n\thandleTokenCreation: (token: AtomIO.StateToken<T>) => void,\n): (() => void) => {\n\tconst unsubscribe =\n\t\tfamily.type === `atom_family`\n\t\t\t? family.subject.subscribe(key, handleTokenCreation)\n\t\t\t: family.subject.subscribe(key, handleTokenCreation)\n\treturn unsubscribe\n}\n\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nexport const useExposeFamily = ({ socket, store }: ServerConfig) => {\n\treturn function exposeFamily<J extends Json.Serializable>(\n\t\tfamily: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,\n\t\tindex: AtomIO.StateToken<Set<string>>,\n\t): () => void {\n\t\tconst unsubSingleCallbacksByKey = new Map<string, () => void>()\n\t\tconst unsubFamilyCallbacksByKey = new Map<string, () => void>()\n\n\t\tconst fillFamilyUnsubRequest = () => {\n\t\t\tunsubFamilyCallbacksByKey.forEach((unsub) => unsub())\n\t\t\tunsubFamilyCallbacksByKey.clear()\n\t\t\tsocket.off(`unsub:${family.key}`, fillFamilyUnsubRequest)\n\t\t}\n\n\t\tconst fillSingleUnsubRequest = (key: string) => {\n\t\t\tsocket.off(`unsub:${key}`, fillSingleUnsubRequest)\n\t\t\tconst unsub = unsubSingleCallbacksByKey.get(key)\n\t\t\tif (unsub) {\n\t\t\t\tunsub()\n\t\t\t\tunsubSingleCallbacksByKey.delete(key)\n\t\t\t}\n\t\t}\n\n\t\tconst fillSubRequest = (subKey?: AtomIO.Json.Serializable) => {\n\t\t\tif (subKey === undefined) {\n\t\t\t\tconst keys = AtomIO.getState(index, store)\n\t\t\t\tkeys.forEach((key) => {\n\t\t\t\t\tconst token = family(key)\n\t\t\t\t\tsocket.emit(\n\t\t\t\t\t\t`serve:${family.key}`,\n\t\t\t\t\t\tparseJson(token.family?.subKey || `null`),\n\t\t\t\t\t\tAtomIO.getState(token, store),\n\t\t\t\t\t)\n\t\t\t\t})\n\n\t\t\t\tconst unsubscribeFromTokenCreation = subscribeToTokenCreation(\n\t\t\t\t\tfamily,\n\t\t\t\t\t`expose-family:${socket.id}`,\n\t\t\t\t\t(token) => {\n\t\t\t\t\t\tconst unsub = AtomIO.subscribe(\n\t\t\t\t\t\t\ttoken,\n\t\t\t\t\t\t\t({ newValue }) => {\n\t\t\t\t\t\t\t\tsocket.emit(\n\t\t\t\t\t\t\t\t\t`serve:${family.key}`,\n\t\t\t\t\t\t\t\t\tparseJson(token.family?.subKey || `null`),\n\t\t\t\t\t\t\t\t\tnewValue,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t`expose-family:${family.key}:${socket.id}`,\n\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tunsubFamilyCallbacksByKey.set(token.key, unsub)\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\t\tunsubFamilyCallbacksByKey.set(family.key, unsubscribeFromTokenCreation)\n\n\t\t\t\tsocket.on(`unsub:${family.key}`, fillFamilyUnsubRequest)\n\t\t\t} else {\n\t\t\t\tconst token = family(subKey)\n\t\t\t\tsocket.emit(`serve:${token.key}`, AtomIO.getState(token, store))\n\t\t\t\tconst unsubscribe = AtomIO.subscribe(\n\t\t\t\t\ttoken,\n\t\t\t\t\t({ newValue }) => {\n\t\t\t\t\t\tsocket.emit(`serve:${token.key}`, newValue)\n\t\t\t\t\t},\n\t\t\t\t\t`expose-family:${family.key}:${socket.id}`,\n\t\t\t\t\tstore,\n\t\t\t\t)\n\t\t\t\tunsubSingleCallbacksByKey.set(token.key, unsubscribe)\n\t\t\t\tsocket.on(`unsub:${token.key}`, () => {\n\t\t\t\t\tfillSingleUnsubRequest(token.key)\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\tsocket.on(`sub:${family.key}`, fillSubRequest)\n\n\t\treturn () => {\n\t\t\tsocket.off(`sub:${family.key}`, fillSubRequest)\n\t\t\tunsubFamilyCallbacksByKey.forEach((unsub) => unsub())\n\t\t\tunsubSingleCallbacksByKey.forEach((unsub) => unsub())\n\t\t\tunsubFamilyCallbacksByKey.clear()\n\t\t\tunsubSingleCallbacksByKey.clear()\n\t\t}\n\t}\n}\n","import * as AtomIO from \"atom.io\"\n\nimport type { ServerConfig } from \".\"\n\nexport const useReceiveTransaction = ({ socket, store }: ServerConfig) => {\n\treturn function receiveTransaction<ƒ extends AtomIO.ƒn>(\n\t\ttx: AtomIO.TransactionToken<ƒ>,\n\t): () => void {\n\t\tconst fillTransactionRequest = (update: AtomIO.TransactionUpdate<ƒ>) =>\n\t\t\tAtomIO.runTransaction<ƒ>(tx, store)(...update.params)\n\n\t\tsocket.on(`tx:${tx.key}`, fillTransactionRequest)\n\n\t\treturn () => socket.off(`tx:${tx.key}`, fillTransactionRequest)\n\t}\n}\n","import type { Json } from \"anvl/json\"\nimport * as AtomIO from \"atom.io\"\n\nimport type { ServerConfig } from \"..\"\n\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nexport const useReceiveState = ({ socket, store }: ServerConfig) => {\n\treturn function receiveState<J extends Json.Serializable>(\n\t\ttoken: AtomIO.StateToken<J>,\n\t): () => void {\n\t\tconst publish = (newValue: J) => AtomIO.setState(token, newValue, store)\n\n\t\tconst fillPubUnclaim = () => {\n\t\t\tsocket.off(`pub:${token.key}`, publish)\n\t\t\tsocket.off(`unclaim:${token.key}`, fillPubUnclaim)\n\t\t}\n\t\tconst fillPubClaim = () => {\n\t\t\tsocket.on(`pub:${token.key}`, publish)\n\t\t\tsocket.on(`unclaim:${token.key}`, fillPubUnclaim)\n\t\t}\n\n\t\tsocket.on(`claim:${token.key}`, fillPubClaim)\n\n\t\treturn () => {\n\t\t\tsocket.off(`claim:${token.key}`, fillPubClaim)\n\t\t\tsocket.off(`pub:${token.key}`, publish)\n\t\t}\n\t}\n}\n"]}
@@ -1,152 +1,7 @@
1
- // ../src/realtime/hook-composition/expose-single.ts
2
- import * as AtomIO from "atom.io";
3
- var useExposeSingle = ({ socket, store }) => {
4
- return function exposeSingle(token) {
5
- let unsubscribeFromStateUpdates = null;
6
- const fillUnsubRequest = () => {
7
- socket.off(`unsub:${token.key}`, fillUnsubRequest);
8
- unsubscribeFromStateUpdates == null ? void 0 : unsubscribeFromStateUpdates();
9
- unsubscribeFromStateUpdates = null;
10
- };
11
- const fillSubRequest = () => {
12
- socket.emit(`serve:${token.key}`, AtomIO.getState(token, store));
13
- unsubscribeFromStateUpdates = AtomIO.subscribe(
14
- token,
15
- ({ newValue }) => {
16
- socket.emit(`serve:${token.key}`, newValue);
17
- },
18
- store
19
- );
20
- socket.on(`unsub:${token.key}`, fillUnsubRequest);
21
- };
22
- socket.on(`sub:${token.key}`, fillSubRequest);
23
- return () => {
24
- socket.off(`sub:${token.key}`, fillSubRequest);
25
- unsubscribeFromStateUpdates == null ? void 0 : unsubscribeFromStateUpdates();
26
- };
27
- };
28
- };
1
+ import * as m from 'atom.io';
29
2
 
30
- // ../../anvl/src/json/index.ts
31
- import { pipe } from "fp-ts/function";
32
- var parseJson = (str) => JSON.parse(str);
3
+ var $=({socket:e,store:t})=>function(o){let n=null,r=()=>{e.off(`unsub:${o.key}`,r),n==null||n(),n=null;},i=()=>{e.emit(`serve:${o.key}`,m.getState(o,t)),n=m.subscribe(o,({newValue:f})=>{e.emit(`serve:${o.key}`,f);},`expose-single:${e.id}`,t),e.on(`unsub:${o.key}`,r);};return e.on(`sub:${o.key}`,i),()=>{e.off(`sub:${o.key}`,i),n==null||n();}};var S=e=>JSON.parse(e);var v=(e,t,l)=>(e.type==="atom_family",e.subject.subscribe(t,l)),E=({socket:e,store:t})=>function(o,n){let r=new Map,i=new Map,f=()=>{i.forEach(s=>s()),i.clear(),e.off(`unsub:${o.key}`,f);},J=s=>{e.off(`unsub:${s}`,J);let a=r.get(s);a&&(a(),r.delete(s));},g=s=>{if(s===void 0){m.getState(n,t).forEach(u=>{var b;let p=o(u);e.emit(`serve:${o.key}`,S(((b=p.family)==null?void 0:b.subKey)||"null"),m.getState(p,t));});let c=v(o,`expose-family:${e.id}`,u=>{let p=m.subscribe(u,({newValue:b})=>{var x;e.emit(`serve:${o.key}`,S(((x=u.family)==null?void 0:x.subKey)||"null"),b);},`expose-family:${o.key}:${e.id}`,t);i.set(u.key,p);});i.set(o.key,c),e.on(`unsub:${o.key}`,f);}else {let a=o(s);e.emit(`serve:${a.key}`,m.getState(a,t));let c=m.subscribe(a,({newValue:u})=>{e.emit(`serve:${a.key}`,u);},`expose-family:${o.key}:${e.id}`,t);r.set(a.key,c),e.on(`unsub:${a.key}`,()=>{J(a.key);});}};return e.on(`sub:${o.key}`,g),()=>{e.off(`sub:${o.key}`,g),i.forEach(s=>s()),r.forEach(s=>s()),i.clear(),r.clear();}};var j=({socket:e,store:t})=>function(o){let n=r=>m.runTransaction(o,t)(...r.params);return e.on(`tx:${o.key}`,n),()=>e.off(`tx:${o.key}`,n)};var R=({socket:e,store:t})=>function(o){let n=f=>m.setState(o,f,t),r=()=>{e.off(`pub:${o.key}`,n),e.off(`unclaim:${o.key}`,r);},i=()=>{e.on(`pub:${o.key}`,n),e.on(`unclaim:${o.key}`,r);};return e.on(`claim:${o.key}`,i),()=>{e.off(`claim:${o.key}`,i),e.off(`pub:${o.key}`,n);}};
33
4
 
34
- // ../src/realtime/hook-composition/expose-family.ts
35
- import * as AtomIO2 from "atom.io";
36
- var subscribeToTokenCreation = (family, handleTokenCreation) => {
37
- const subscription = family.type === `atom_family` ? family.subject.subscribe(handleTokenCreation) : family.subject.subscribe(handleTokenCreation);
38
- return () => subscription.unsubscribe();
39
- };
40
- var useExposeFamily = ({ socket, store }) => {
41
- return function exposeFamily(family, index) {
42
- const unsubSingleCallbacksByKey = /* @__PURE__ */ new Map();
43
- const unsubFamilyCallbacksByKey = /* @__PURE__ */ new Map();
44
- const fillFamilyUnsubRequest = () => {
45
- unsubFamilyCallbacksByKey.forEach((unsub) => unsub());
46
- unsubFamilyCallbacksByKey.clear();
47
- socket.off(`unsub:${family.key}`, fillFamilyUnsubRequest);
48
- };
49
- const fillSingleUnsubRequest = (key) => {
50
- socket.off(`unsub:${key}`, fillSingleUnsubRequest);
51
- const unsub = unsubSingleCallbacksByKey.get(key);
52
- if (unsub) {
53
- unsub();
54
- unsubSingleCallbacksByKey.delete(key);
55
- }
56
- };
57
- const fillSubRequest = (subKey) => {
58
- if (subKey === void 0) {
59
- const keys = AtomIO2.getState(index, store);
60
- keys.forEach((key) => {
61
- var _a;
62
- const token = family(key);
63
- socket.emit(
64
- `serve:${family.key}`,
65
- parseJson(((_a = token.family) == null ? void 0 : _a.subKey) || `null`),
66
- AtomIO2.getState(token, store)
67
- );
68
- });
69
- const unsubscribeFromTokenCreation = subscribeToTokenCreation(
70
- family,
71
- (token) => {
72
- const unsub = AtomIO2.subscribe(
73
- token,
74
- ({ newValue }) => {
75
- var _a;
76
- socket.emit(
77
- `serve:${family.key}`,
78
- parseJson(((_a = token.family) == null ? void 0 : _a.subKey) || `null`),
79
- newValue
80
- );
81
- },
82
- store
83
- );
84
- unsubFamilyCallbacksByKey.set(token.key, unsub);
85
- }
86
- );
87
- unsubFamilyCallbacksByKey.set(family.key, unsubscribeFromTokenCreation);
88
- socket.on(`unsub:${family.key}`, fillFamilyUnsubRequest);
89
- } else {
90
- const token = family(subKey);
91
- socket.emit(`serve:${token.key}`, AtomIO2.getState(token, store));
92
- const unsubscribe = AtomIO2.subscribe(
93
- token,
94
- ({ newValue }) => {
95
- socket.emit(`serve:${token.key}`, newValue);
96
- },
97
- store
98
- );
99
- unsubSingleCallbacksByKey.set(token.key, unsubscribe);
100
- socket.on(`unsub:${token.key}`, () => {
101
- fillSingleUnsubRequest(token.key);
102
- });
103
- }
104
- };
105
- socket.on(`sub:${family.key}`, fillSubRequest);
106
- return () => {
107
- socket.off(`sub:${family.key}`, fillSubRequest);
108
- unsubFamilyCallbacksByKey.forEach((unsub) => unsub());
109
- unsubSingleCallbacksByKey.forEach((unsub) => unsub());
110
- unsubFamilyCallbacksByKey.clear();
111
- unsubSingleCallbacksByKey.clear();
112
- };
113
- };
114
- };
115
-
116
- // ../src/realtime/hook-composition/receive-transaction.ts
117
- import * as AtomIO3 from "atom.io";
118
- var useReceiveTransaction = ({ socket, store }) => {
119
- return function receiveTransaction(tx) {
120
- const fillTransactionRequest = (update) => AtomIO3.runTransaction(tx, store)(...update.params);
121
- socket.on(`tx:${tx.key}`, fillTransactionRequest);
122
- return () => socket.off(`tx:${tx.key}`, fillTransactionRequest);
123
- };
124
- };
125
-
126
- // ../src/realtime/hook-composition/receive-state.ts
127
- import * as AtomIO4 from "atom.io";
128
- var useReceiveState = ({ socket, store }) => {
129
- return function receiveState(token) {
130
- const publish = (newValue) => AtomIO4.setState(token, newValue, store);
131
- const fillPubUnclaim = () => {
132
- socket.off(`pub:${token.key}`, publish);
133
- socket.off(`unclaim:${token.key}`, fillPubUnclaim);
134
- };
135
- const fillPubClaim = () => {
136
- socket.on(`pub:${token.key}`, publish);
137
- socket.on(`unclaim:${token.key}`, fillPubUnclaim);
138
- };
139
- socket.on(`claim:${token.key}`, fillPubClaim);
140
- return () => {
141
- socket.off(`claim:${token.key}`, fillPubClaim);
142
- socket.off(`pub:${token.key}`, publish);
143
- };
144
- };
145
- };
146
- export {
147
- useExposeFamily,
148
- useExposeSingle,
149
- useReceiveState,
150
- useReceiveTransaction
151
- };
5
+ export { E as useExposeFamily, $ as useExposeSingle, R as useReceiveState, j as useReceiveTransaction };
6
+ //# sourceMappingURL=out.js.map
152
7
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/realtime/hook-composition/expose-single.ts","../../../anvl/src/json/index.ts","../../src/realtime/hook-composition/expose-family.ts","../../src/realtime/hook-composition/receive-transaction.ts","../../src/realtime/hook-composition/receive-state.ts"],"sourcesContent":["import type { Json } from \"anvl/json\"\nimport * as AtomIO from \"atom.io\"\n\nimport type { ServerConfig } from \"..\"\n\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nexport const useExposeSingle = ({ socket, store }: ServerConfig) => {\n\treturn function exposeSingle<J extends Json>(\n\t\ttoken: AtomIO.StateToken<J>,\n\t): () => void {\n\t\tlet unsubscribeFromStateUpdates: (() => void) | null = null\n\n\t\tconst fillUnsubRequest = () => {\n\t\t\tsocket.off(`unsub:${token.key}`, fillUnsubRequest)\n\t\t\tunsubscribeFromStateUpdates?.()\n\t\t\tunsubscribeFromStateUpdates = null\n\t\t}\n\n\t\tconst fillSubRequest = () => {\n\t\t\tsocket.emit(`serve:${token.key}`, AtomIO.getState(token, store))\n\t\t\tunsubscribeFromStateUpdates = AtomIO.subscribe(\n\t\t\t\ttoken,\n\t\t\t\t({ newValue }) => {\n\t\t\t\t\tsocket.emit(`serve:${token.key}`, newValue)\n\t\t\t\t},\n\t\t\t\tstore,\n\t\t\t)\n\t\t\tsocket.on(`unsub:${token.key}`, fillUnsubRequest)\n\t\t}\n\n\t\tsocket.on(`sub:${token.key}`, fillSubRequest)\n\n\t\treturn () => {\n\t\t\tsocket.off(`sub:${token.key}`, fillSubRequest)\n\t\t\tunsubscribeFromStateUpdates?.()\n\t\t}\n\t}\n}\n","import { pipe } from \"fp-ts/function\"\n\nexport * from \"./refine\"\nexport * from \"./json-interface\"\n\nexport const serializeSet = <T>(set: Set<T>): string =>\n\tpipe(set, Array.from, JSON.stringify)\n\nexport const deserializeSet = <T>(str: string): Set<T> =>\n\tpipe(str, JSON.parse, Array.from, (a) => new Set(a as T[]))\n\nexport type Primitive = boolean | number | string | null\n\nexport type Serializable =\n\t| Primitive\n\t| Readonly<{ [key: string]: Serializable }>\n\t| ReadonlyArray<Serializable>\n\nexport type JsonObj<\n\tKey extends string = string,\n\tValue extends Serializable = Serializable,\n> = Record<Key, Value>\n\nexport type JsonArr<Element extends Serializable = Serializable> =\n\tReadonlyArray<Element>\n\nexport type Json = JsonArr | JsonObj | Primitive\n\nexport const parseJson = <S extends Stringified<Json>>(\n\tstr: S | string,\n): S extends Stringified<infer J> ? J : Json => JSON.parse(str)\n\nexport type Stringified<J extends Json> = string & { __json: J }\n\nexport const stringifyJson = <J extends Json>(json: J): Stringified<J> =>\n\tJSON.stringify(json) as Stringified<J>\n\nexport type Empty = Record<string, never>\n\nexport const JSON_TYPE_NAMES = [\n\t`array`,\n\t`boolean`,\n\t`null`,\n\t`number`,\n\t`object`,\n\t`string`,\n] as const\n\nexport type JsonTypeName = typeof JSON_TYPE_NAMES[number]\n\nexport interface JsonTypes extends Record<JsonTypeName, Json> {\n\tarray: JsonArr\n\tboolean: boolean\n\tnull: null\n\tnumber: number\n\tobject: JsonObj\n\tstring: string\n}\n\nexport const JSON_DEFAULTS: JsonTypes = {\n\tarray: [],\n\tboolean: false,\n\tnull: null,\n\tnumber: 0,\n\tobject: {},\n\tstring: ``,\n}\n","import type { Json } from \"anvl/json\"\nimport { parseJson } from \"anvl/json\"\nimport * as AtomIO from \"atom.io\"\n\nimport type { ServerConfig } from \"..\"\n\nconst subscribeToTokenCreation = <T>(\n\tfamily: AtomIO.AtomFamily<T> | AtomIO.SelectorFamily<T>,\n\thandleTokenCreation: (token: AtomIO.StateToken<T>) => void,\n): (() => void) => {\n\tconst subscription =\n\t\tfamily.type === `atom_family`\n\t\t\t? family.subject.subscribe(handleTokenCreation)\n\t\t\t: family.subject.subscribe(handleTokenCreation)\n\treturn () => subscription.unsubscribe()\n}\n\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nexport const useExposeFamily = ({ socket, store }: ServerConfig) => {\n\treturn function exposeFamily<J extends Json>(\n\t\tfamily: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,\n\t\tindex: AtomIO.StateToken<Set<string>>,\n\t): () => void {\n\t\tconst unsubSingleCallbacksByKey = new Map<string, () => void>()\n\t\tconst unsubFamilyCallbacksByKey = new Map<string, () => void>()\n\n\t\tconst fillFamilyUnsubRequest = () => {\n\t\t\tunsubFamilyCallbacksByKey.forEach((unsub) => unsub())\n\t\t\tunsubFamilyCallbacksByKey.clear()\n\t\t\tsocket.off(`unsub:${family.key}`, fillFamilyUnsubRequest)\n\t\t}\n\n\t\tconst fillSingleUnsubRequest = (key: string) => {\n\t\t\tsocket.off(`unsub:${key}`, fillSingleUnsubRequest)\n\t\t\tconst unsub = unsubSingleCallbacksByKey.get(key)\n\t\t\tif (unsub) {\n\t\t\t\tunsub()\n\t\t\t\tunsubSingleCallbacksByKey.delete(key)\n\t\t\t}\n\t\t}\n\n\t\tconst fillSubRequest = (subKey?: AtomIO.Serializable) => {\n\t\t\tif (subKey === undefined) {\n\t\t\t\tconst keys = AtomIO.getState(index, store)\n\t\t\t\tkeys.forEach((key) => {\n\t\t\t\t\tconst token = family(key)\n\t\t\t\t\tsocket.emit(\n\t\t\t\t\t\t`serve:${family.key}`,\n\t\t\t\t\t\tparseJson(token.family?.subKey || `null`),\n\t\t\t\t\t\tAtomIO.getState(token, store),\n\t\t\t\t\t)\n\t\t\t\t})\n\n\t\t\t\tconst unsubscribeFromTokenCreation = subscribeToTokenCreation(\n\t\t\t\t\tfamily,\n\t\t\t\t\t(token) => {\n\t\t\t\t\t\tconst unsub = AtomIO.subscribe(\n\t\t\t\t\t\t\ttoken,\n\t\t\t\t\t\t\t({ newValue }) => {\n\t\t\t\t\t\t\t\tsocket.emit(\n\t\t\t\t\t\t\t\t\t`serve:${family.key}`,\n\t\t\t\t\t\t\t\t\tparseJson(token.family?.subKey || `null`),\n\t\t\t\t\t\t\t\t\tnewValue,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tunsubFamilyCallbacksByKey.set(token.key, unsub)\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\t\tunsubFamilyCallbacksByKey.set(family.key, unsubscribeFromTokenCreation)\n\n\t\t\t\tsocket.on(`unsub:${family.key}`, fillFamilyUnsubRequest)\n\t\t\t} else {\n\t\t\t\tconst token = family(subKey)\n\t\t\t\tsocket.emit(`serve:${token.key}`, AtomIO.getState(token, store))\n\t\t\t\tconst unsubscribe = AtomIO.subscribe(\n\t\t\t\t\ttoken,\n\t\t\t\t\t({ newValue }) => {\n\t\t\t\t\t\tsocket.emit(`serve:${token.key}`, newValue)\n\t\t\t\t\t},\n\t\t\t\t\tstore,\n\t\t\t\t)\n\t\t\t\tunsubSingleCallbacksByKey.set(token.key, unsubscribe)\n\t\t\t\tsocket.on(`unsub:${token.key}`, () => {\n\t\t\t\t\tfillSingleUnsubRequest(token.key)\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\tsocket.on(`sub:${family.key}`, fillSubRequest)\n\n\t\treturn () => {\n\t\t\tsocket.off(`sub:${family.key}`, fillSubRequest)\n\t\t\tunsubFamilyCallbacksByKey.forEach((unsub) => unsub())\n\t\t\tunsubSingleCallbacksByKey.forEach((unsub) => unsub())\n\t\t\tunsubFamilyCallbacksByKey.clear()\n\t\t\tunsubSingleCallbacksByKey.clear()\n\t\t}\n\t}\n}\n","import * as AtomIO from \"atom.io\"\n\nimport type { ƒn } from \"~/packages/anvl/src/function\"\n\nimport type { ServerConfig } from \".\"\n\nexport const useReceiveTransaction = ({ socket, store }: ServerConfig) => {\n\treturn function receiveTransaction<ƒ extends ƒn>(\n\t\ttx: AtomIO.TransactionToken<ƒ>,\n\t): () => void {\n\t\tconst fillTransactionRequest = (update: AtomIO.TransactionUpdate<ƒ>) =>\n\t\t\tAtomIO.runTransaction<ƒ>(tx, store)(...update.params)\n\n\t\tsocket.on(`tx:${tx.key}`, fillTransactionRequest)\n\n\t\treturn () => socket.off(`tx:${tx.key}`, fillTransactionRequest)\n\t}\n}\n","import type { Json } from \"anvl/json\"\nimport * as AtomIO from \"atom.io\"\n\nimport type { ServerConfig } from \"..\"\n\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nexport const useReceiveState = ({ socket, store }: ServerConfig) => {\n\treturn function receiveState<J extends Json>(\n\t\ttoken: AtomIO.StateToken<J>,\n\t): () => void {\n\t\tconst publish = (newValue: J) => AtomIO.setState(token, newValue, store)\n\n\t\tconst fillPubUnclaim = () => {\n\t\t\tsocket.off(`pub:${token.key}`, publish)\n\t\t\tsocket.off(`unclaim:${token.key}`, fillPubUnclaim)\n\t\t}\n\t\tconst fillPubClaim = () => {\n\t\t\tsocket.on(`pub:${token.key}`, publish)\n\t\t\tsocket.on(`unclaim:${token.key}`, fillPubUnclaim)\n\t\t}\n\n\t\tsocket.on(`claim:${token.key}`, fillPubClaim)\n\n\t\treturn () => {\n\t\t\tsocket.off(`claim:${token.key}`, fillPubClaim)\n\t\t\tsocket.off(`pub:${token.key}`, publish)\n\t\t}\n\t}\n}\n"],"mappings":";AACA,YAAY,YAAY;AAKjB,IAAM,k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;AACZ,aAAO,IAAI,SAAS,MAAM,GAAG,IAAI,YAAY;AAC7C,aAAO,IAAI,OAAO,MAAM,GAAG,IAAI,OAAO;AAAA,IACvC;AAAA,EACD;AACD;","names":["AtomIO","AtomIO","AtomIO"]}
1
+ {"version":3,"sources":["../src/hook-composition/expose-single.ts","../../../anvl/src/json/index.ts","../src/hook-composition/expose-family.ts","../src/hook-composition/receive-transaction.ts","../src/hook-composition/receive-state.ts"],"names":["AtomIO","useExposeSingle","socket","store","token","unsubscribeFromStateUpdates","fillUnsubRequest","fillSubRequest","newValue","parseJson","str","subscribeToTokenCreation","family","key","handleTokenCreation","useExposeFamily","index","unsubSingleCallbacksByKey","unsubFamilyCallbacksByKey","fillFamilyUnsubRequest","unsub","fillSingleUnsubRequest","subKey","_a","unsubscribeFromTokenCreation","unsubscribe","useReceiveTransaction","tx","fillTransactionRequest","update","useReceiveState","publish","fillPubUnclaim","fillPubClaim"],"mappings":"AACA,UAAYA,MAAY,UAKjB,IAAMC,EAAkB,CAAC,CAAE,OAAAC,EAAQ,MAAAC,CAAM,IACxC,SACNC,EACa,CACb,IAAIC,EAAmD,KAEjDC,EAAmB,IAAM,CAC9BJ,EAAO,IAAI,SAASE,EAAM,GAAG,GAAIE,CAAgB,EACjDD,GAAA,MAAAA,IACAA,EAA8B,IAC/B,EAEME,EAAiB,IAAM,CAC5BL,EAAO,KAAK,SAASE,EAAM,GAAG,GAAW,WAASA,EAAOD,CAAK,CAAC,EAC/DE,EAAqC,YACpCD,EACA,CAAC,CAAE,SAAAI,CAAS,IAAM,CACjBN,EAAO,KAAK,SAASE,EAAM,GAAG,GAAII,CAAQ,CAC3C,EACA,iBAAiBN,EAAO,EAAE,GAC1BC,CACD,EACAD,EAAO,GAAG,SAASE,EAAM,GAAG,GAAIE,CAAgB,CACjD,EAEA,OAAAJ,EAAO,GAAG,OAAOE,EAAM,GAAG,GAAIG,CAAc,EAErC,IAAM,CACZL,EAAO,IAAI,OAAOE,EAAM,GAAG,GAA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,OAAA5B,EAAQ,MAAAC,CAAM,IACxC,SACNC,EACa,CACb,IAAM2B,EAAWvB,GAAuB,WAASJ,EAAOI,EAAUL,CAAK,EAEjE6B,EAAiB,IAAM,CAC5B9B,EAAO,IAAI,OAAOE,EAAM,GAAG,GAAI2B,CAAO,EACtC7B,EAAO,IAAI,WAAWE,EAAM,GAAG,GAAI4B,CAAc,CAClD,EACMC,EAAe,IAAM,CAC1B/B,EAAO,GAAG,OAAOE,EAAM,GAAG,GAAI2B,CAAO,EACrC7B,EAAO,GAAG,WAAWE,EAAM,GAAG,GAAI4B,CAAc,CACjD,EAEA,OAAA9B,EAAO,GAAG,SAASE,EAAM,GAAG,GAAI6B,CAAY,EAErC,IAAM,CACZ/B,EAAO,IAAI,SAASE,EAAM,GAAG,GAAI6B,CAAY,EAC7C/B,EAAO,IAAI,OAAOE,EAAM,GAAG,GAAI2B,CAAO,CACvC,CACD","sourcesContent":["import type { Json } from \"anvl/json\"\nimport * as AtomIO from \"atom.io\"\n\nimport type { ServerConfig } from \"..\"\n\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nexport const useExposeSingle = ({ socket, store }: ServerConfig) => {\n\treturn function exposeSingle<J extends Json.Serializable>(\n\t\ttoken: AtomIO.StateToken<J>,\n\t): () => void {\n\t\tlet unsubscribeFromStateUpdates: (() => void) | null = null\n\n\t\tconst fillUnsubRequest = () => {\n\t\t\tsocket.off(`unsub:${token.key}`, fillUnsubRequest)\n\t\t\tunsubscribeFromStateUpdates?.()\n\t\t\tunsubscribeFromStateUpdates = null\n\t\t}\n\n\t\tconst fillSubRequest = () => {\n\t\t\tsocket.emit(`serve:${token.key}`, AtomIO.getState(token, store))\n\t\t\tunsubscribeFromStateUpdates = AtomIO.subscribe(\n\t\t\t\ttoken,\n\t\t\t\t({ newValue }) => {\n\t\t\t\t\tsocket.emit(`serve:${token.key}`, newValue)\n\t\t\t\t},\n\t\t\t\t`expose-single:${socket.id}`,\n\t\t\t\tstore,\n\t\t\t)\n\t\t\tsocket.on(`unsub:${token.key}`, fillUnsubRequest)\n\t\t}\n\n\t\tsocket.on(`sub:${token.key}`, fillSubRequest)\n\n\t\treturn () => {\n\t\t\tsocket.off(`sub:${token.key}`, fillSubRequest)\n\t\t\tunsubscribeFromStateUpdates?.()\n\t\t}\n\t}\n}\n","export * from \"./json-interface\"\nimport type * as Json from \"./json\"\nexport { Json }\n\nexport const parseJson = <S extends Stringified<Json.Serializable>>(\n\tstr: S | string,\n): S extends Stringified<infer J> ? J : Json.Serializable => JSON.parse(str)\n\nexport type Stringified<J extends Json.Serializable> = string & { __json: J }\n\nexport const stringifyJson = <J extends Json.Serializable>(\n\tjson: J,\n): Stringified<J> => JSON.stringify(json) as Stringified<J>\n\nexport type Empty = Record<string, never>\n\nexport const JSON_TYPE_NAMES = [\n\t`array`,\n\t`boolean`,\n\t`null`,\n\t`number`,\n\t`object`,\n\t`string`,\n] as const\n\nexport type JsonTypeName = typeof JSON_TYPE_NAMES[number]\n\nexport interface JsonTypes extends Record<JsonTypeName, Json.Serializable> {\n\tarray: Json.Array\n\tboolean: boolean\n\tnull: null\n\tnumber: number\n\tobject: Json.Object\n\tstring: string\n}\n\nexport const JSON_DEFAULTS: JsonTypes = {\n\tarray: [],\n\tboolean: false,\n\tnull: null,\n\tnumber: 0,\n\tobject: {},\n\tstring: ``,\n}\n","import type { Json } from \"anvl/json\"\nimport { parseJson } from \"anvl/json\"\nimport * as AtomIO from \"atom.io\"\n\nimport type { ServerConfig } from \"..\"\n\nconst subscribeToTokenCreation = <T>(\n\tfamily: AtomIO.AtomFamily<T> | AtomIO.SelectorFamily<T>,\n\tkey: string,\n\thandleTokenCreation: (token: AtomIO.StateToken<T>) => void,\n): (() => void) => {\n\tconst unsubscribe =\n\t\tfamily.type === `atom_family`\n\t\t\t? family.subject.subscribe(key, handleTokenCreation)\n\t\t\t: family.subject.subscribe(key, handleTokenCreation)\n\treturn unsubscribe\n}\n\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nexport const useExposeFamily = ({ socket, store }: ServerConfig) => {\n\treturn function exposeFamily<J extends Json.Serializable>(\n\t\tfamily: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,\n\t\tindex: AtomIO.StateToken<Set<string>>,\n\t): () => void {\n\t\tconst unsubSingleCallbacksByKey = new Map<string, () => void>()\n\t\tconst unsubFamilyCallbacksByKey = new Map<string, () => void>()\n\n\t\tconst fillFamilyUnsubRequest = () => {\n\t\t\tunsubFamilyCallbacksByKey.forEach((unsub) => unsub())\n\t\t\tunsubFamilyCallbacksByKey.clear()\n\t\t\tsocket.off(`unsub:${family.key}`, fillFamilyUnsubRequest)\n\t\t}\n\n\t\tconst fillSingleUnsubRequest = (key: string) => {\n\t\t\tsocket.off(`unsub:${key}`, fillSingleUnsubRequest)\n\t\t\tconst unsub = unsubSingleCallbacksByKey.get(key)\n\t\t\tif (unsub) {\n\t\t\t\tunsub()\n\t\t\t\tunsubSingleCallbacksByKey.delete(key)\n\t\t\t}\n\t\t}\n\n\t\tconst fillSubRequest = (subKey?: AtomIO.Json.Serializable) => {\n\t\t\tif (subKey === undefined) {\n\t\t\t\tconst keys = AtomIO.getState(index, store)\n\t\t\t\tkeys.forEach((key) => {\n\t\t\t\t\tconst token = family(key)\n\t\t\t\t\tsocket.emit(\n\t\t\t\t\t\t`serve:${family.key}`,\n\t\t\t\t\t\tparseJson(token.family?.subKey || `null`),\n\t\t\t\t\t\tAtomIO.getState(token, store),\n\t\t\t\t\t)\n\t\t\t\t})\n\n\t\t\t\tconst unsubscribeFromTokenCreation = subscribeToTokenCreation(\n\t\t\t\t\tfamily,\n\t\t\t\t\t`expose-family:${socket.id}`,\n\t\t\t\t\t(token) => {\n\t\t\t\t\t\tconst unsub = AtomIO.subscribe(\n\t\t\t\t\t\t\ttoken,\n\t\t\t\t\t\t\t({ newValue }) => {\n\t\t\t\t\t\t\t\tsocket.emit(\n\t\t\t\t\t\t\t\t\t`serve:${family.key}`,\n\t\t\t\t\t\t\t\t\tparseJson(token.family?.subKey || `null`),\n\t\t\t\t\t\t\t\t\tnewValue,\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t`expose-family:${family.key}:${socket.id}`,\n\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t)\n\t\t\t\t\t\tunsubFamilyCallbacksByKey.set(token.key, unsub)\n\t\t\t\t\t},\n\t\t\t\t)\n\t\t\t\tunsubFamilyCallbacksByKey.set(family.key, unsubscribeFromTokenCreation)\n\n\t\t\t\tsocket.on(`unsub:${family.key}`, fillFamilyUnsubRequest)\n\t\t\t} else {\n\t\t\t\tconst token = family(subKey)\n\t\t\t\tsocket.emit(`serve:${token.key}`, AtomIO.getState(token, store))\n\t\t\t\tconst unsubscribe = AtomIO.subscribe(\n\t\t\t\t\ttoken,\n\t\t\t\t\t({ newValue }) => {\n\t\t\t\t\t\tsocket.emit(`serve:${token.key}`, newValue)\n\t\t\t\t\t},\n\t\t\t\t\t`expose-family:${family.key}:${socket.id}`,\n\t\t\t\t\tstore,\n\t\t\t\t)\n\t\t\t\tunsubSingleCallbacksByKey.set(token.key, unsubscribe)\n\t\t\t\tsocket.on(`unsub:${token.key}`, () => {\n\t\t\t\t\tfillSingleUnsubRequest(token.key)\n\t\t\t\t})\n\t\t\t}\n\t\t}\n\n\t\tsocket.on(`sub:${family.key}`, fillSubRequest)\n\n\t\treturn () => {\n\t\t\tsocket.off(`sub:${family.key}`, fillSubRequest)\n\t\t\tunsubFamilyCallbacksByKey.forEach((unsub) => unsub())\n\t\t\tunsubSingleCallbacksByKey.forEach((unsub) => unsub())\n\t\t\tunsubFamilyCallbacksByKey.clear()\n\t\t\tunsubSingleCallbacksByKey.clear()\n\t\t}\n\t}\n}\n","import * as AtomIO from \"atom.io\"\n\nimport type { ServerConfig } from \".\"\n\nexport const useReceiveTransaction = ({ socket, store }: ServerConfig) => {\n\treturn function receiveTransaction<ƒ extends AtomIO.ƒn>(\n\t\ttx: AtomIO.TransactionToken<ƒ>,\n\t): () => void {\n\t\tconst fillTransactionRequest = (update: AtomIO.TransactionUpdate<ƒ>) =>\n\t\t\tAtomIO.runTransaction<ƒ>(tx, store)(...update.params)\n\n\t\tsocket.on(`tx:${tx.key}`, fillTransactionRequest)\n\n\t\treturn () => socket.off(`tx:${tx.key}`, fillTransactionRequest)\n\t}\n}\n","import type { Json } from \"anvl/json\"\nimport * as AtomIO from \"atom.io\"\n\nimport type { ServerConfig } from \"..\"\n\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nexport const useReceiveState = ({ socket, store }: ServerConfig) => {\n\treturn function receiveState<J extends Json.Serializable>(\n\t\ttoken: AtomIO.StateToken<J>,\n\t): () => void {\n\t\tconst publish = (newValue: J) => AtomIO.setState(token, newValue, store)\n\n\t\tconst fillPubUnclaim = () => {\n\t\t\tsocket.off(`pub:${token.key}`, publish)\n\t\t\tsocket.off(`unclaim:${token.key}`, fillPubUnclaim)\n\t\t}\n\t\tconst fillPubClaim = () => {\n\t\t\tsocket.on(`pub:${token.key}`, publish)\n\t\t\tsocket.on(`unclaim:${token.key}`, fillPubUnclaim)\n\t\t}\n\n\t\tsocket.on(`claim:${token.key}`, fillPubClaim)\n\n\t\treturn () => {\n\t\t\tsocket.off(`claim:${token.key}`, fillPubClaim)\n\t\t\tsocket.off(`pub:${token.key}`, publish)\n\t\t}\n\t}\n}\n"]}
@@ -10,32 +10,28 @@ declare const RealtimeProvider: React.FC<{
10
10
  socket: Socket;
11
11
  }>;
12
12
 
13
- type ƒn = (...parameters: any[]) => any;
13
+ type primitive = boolean | number | string | null;
14
14
 
15
- type Primitive = boolean | number | string | null;
16
- type Serializable = Primitive | Readonly<{
15
+ type Serializable = primitive | Readonly<{
17
16
  [key: string]: Serializable;
18
17
  }> | ReadonlyArray<Serializable>;
19
- type JsonObj<Key extends string = string, Value extends Serializable = Serializable> = Record<Key, Value>;
20
- type JsonArr<Element extends Serializable = Serializable> = ReadonlyArray<Element>;
21
- type Json = JsonArr | JsonObj | Primitive;
22
18
 
23
- declare function usePull<J extends Json>(token: AtomIO.StateToken<J>): void;
19
+ declare function usePull<J extends Serializable>(token: AtomIO.StateToken<J>): void;
24
20
 
25
- declare function usePullFamily<J extends Json>(family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>): void;
21
+ declare function usePullFamily<J extends Serializable>(family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>): void;
26
22
 
27
- declare function usePullFamilyMember<J extends Json>(family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>, subKey: AtomIO.Serializable): void;
23
+ declare function usePullFamilyMember<J extends Serializable>(family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>, subKey: AtomIO.Json.Serializable): void;
28
24
 
29
- declare function usePush<J extends Json>(token: AtomIO.StateToken<J>): void;
25
+ declare function usePush<J extends Serializable>(token: AtomIO.StateToken<J>): void;
30
26
 
31
- declare function useServerAction<ƒ extends ƒn>(token: AtomIO.TransactionToken<ƒ>): (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
27
+ declare function useServerAction<ƒ extends AtomIO.ƒn>(token: AtomIO.TransactionToken<ƒ>): (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
32
28
 
33
29
  type RealtimeHooks = {
34
- usePull: <J extends Json>(token: AtomIO.StateToken<J>) => void;
35
- usePullFamily: <J extends Json>(family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>) => void;
36
- usePullFamilyMember: <J extends Json>(family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>, subKey: string) => void;
37
- usePush: <J extends Json>(token: AtomIO.StateToken<J>) => void;
38
- useServerAction: <ƒ extends ƒn>(token: AtomIO.TransactionToken<ƒ>) => (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
30
+ usePull: <J extends Serializable>(token: AtomIO.StateToken<J>) => void;
31
+ usePullFamily: <J extends Serializable>(family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>) => void;
32
+ usePullFamilyMember: <J extends Serializable>(family: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>, subKey: string) => void;
33
+ usePush: <J extends Serializable>(token: AtomIO.StateToken<J>) => void;
34
+ useServerAction: <ƒ extends AtomIO.ƒn>(token: AtomIO.TransactionToken<ƒ>) => (...parameters: Parameters<ƒ>) => ReturnType<ƒ>;
39
35
  };
40
36
  declare const realtimeHooks: RealtimeHooks;
41
37