atom.io 0.6.2 → 0.6.3
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.
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -2
- package/dist/index.mjs.map +1 -1
- package/json/dist/index.d.mts +18 -0
- package/json/dist/index.d.ts +18 -0
- package/json/dist/index.js +51 -0
- package/json/dist/index.js.map +1 -0
- package/json/dist/index.mjs +15 -0
- package/json/dist/index.mjs.map +1 -0
- package/package.json +13 -3
- package/react/dist/index.d.mts +24 -0
- package/react/dist/index.d.ts +24 -0
- package/react/dist/index.js +83 -0
- package/react/dist/index.js.map +1 -0
- package/react/dist/index.mjs +41 -0
- package/react/dist/index.mjs.map +1 -0
- package/react-devtools/dist/index.css +26 -0
- package/react-devtools/dist/index.css.map +1 -0
- package/react-devtools/dist/index.d.mts +15 -0
- package/react-devtools/dist/index.d.ts +15 -0
- package/react-devtools/dist/index.js +1596 -0
- package/react-devtools/dist/index.js.map +1 -0
- package/react-devtools/dist/index.mjs +1568 -0
- package/react-devtools/dist/index.mjs.map +1 -0
- package/realtime/dist/index.d.mts +27 -0
- package/realtime/dist/index.d.ts +27 -0
- package/realtime/dist/index.js +191 -0
- package/realtime/dist/index.js.map +1 -0
- package/realtime/dist/index.mjs +152 -0
- package/realtime/dist/index.mjs.map +1 -0
- package/realtime-react/dist/index.d.mts +45 -0
- package/realtime-react/dist/index.d.ts +45 -0
- package/realtime-react/dist/index.js +213 -0
- package/realtime-react/dist/index.js.map +1 -0
- package/realtime-react/dist/index.mjs +168 -0
- package/realtime-react/dist/index.mjs.map +1 -0
- package/realtime-testing/dist/index.d.mts +49 -0
- package/realtime-testing/dist/index.d.ts +49 -0
- package/realtime-testing/dist/index.js +153 -0
- package/realtime-testing/dist/index.js.map +1 -0
- package/realtime-testing/dist/index.mjs +117 -0
- package/realtime-testing/dist/index.mjs.map +1 -0
- package/realtime-testing/package.json +15 -0
- package/src/atom.ts +15 -15
- package/src/index.ts +59 -59
- package/src/internal/atom-internal.ts +36 -36
- package/src/internal/families-internal.ts +114 -114
- package/src/internal/get.ts +83 -83
- package/src/internal/is-default.ts +17 -17
- package/src/internal/meta/attach-meta.ts +7 -7
- package/src/internal/meta/meta-state.ts +115 -115
- package/src/internal/operation.ts +93 -93
- package/src/internal/selector/create-read-write-selector.ts +46 -46
- package/src/internal/selector/create-readonly-selector.ts +37 -37
- package/src/internal/selector/lookup-selector-sources.ts +9 -9
- package/src/internal/selector/register-selector.ts +44 -44
- package/src/internal/selector/trace-selector-atoms.ts +30 -30
- package/src/internal/selector/update-selector-atoms.ts +25 -25
- package/src/internal/selector-internal.ts +37 -37
- package/src/internal/set.ts +78 -78
- package/src/internal/store.ts +118 -118
- package/src/internal/subscribe-internal.ts +62 -62
- package/src/internal/time-travel-internal.ts +76 -76
- package/src/internal/timeline/add-atom-to-timeline.ts +158 -153
- package/src/internal/timeline-internal.ts +80 -80
- package/src/internal/transaction/abort-transaction.ts +8 -8
- package/src/internal/transaction/apply-transaction.ts +41 -41
- package/src/internal/transaction/build-transaction.ts +28 -28
- package/src/internal/transaction/index.ts +7 -7
- package/src/internal/transaction/redo-transaction.ts +13 -13
- package/src/internal/transaction/undo-transaction.ts +13 -13
- package/src/internal/transaction-internal.ts +48 -48
- package/src/json/select-json.ts +12 -12
- package/src/logger.ts +30 -30
- package/src/react/store-context.tsx +4 -4
- package/src/react/store-hooks.ts +18 -18
- package/src/react-devtools/AtomIODevtools.tsx +83 -82
- package/src/react-devtools/StateEditor.tsx +53 -53
- package/src/react-devtools/TokenList.tsx +47 -42
- package/src/react-explorer/AtomIOExplorer.tsx +197 -185
- package/src/react-explorer/explorer-effects.ts +11 -11
- package/src/react-explorer/explorer-states.ts +186 -193
- package/src/react-explorer/index.ts +11 -11
- package/src/react-explorer/space-states.ts +48 -50
- package/src/react-explorer/view-states.ts +25 -25
- package/src/realtime/hook-composition/expose-family.ts +81 -81
- package/src/realtime/hook-composition/expose-single.ts +26 -26
- package/src/realtime/hook-composition/expose-timeline.ts +60 -0
- package/src/realtime/hook-composition/index.ts +2 -2
- package/src/realtime/hook-composition/receive-state.ts +18 -18
- package/src/realtime/hook-composition/receive-transaction.ts +8 -8
- package/src/realtime-react/realtime-context.tsx +17 -17
- package/src/realtime-react/realtime-hooks.ts +17 -17
- package/src/realtime-react/realtime-state.ts +4 -4
- package/src/realtime-react/use-pull-family-member.ts +15 -15
- package/src/realtime-react/use-pull-family.ts +13 -13
- package/src/realtime-react/use-pull.ts +12 -12
- package/src/realtime-react/use-push.ts +15 -15
- package/src/realtime-react/use-server-action.ts +21 -21
- package/src/realtime-testing/index.ts +1 -0
- package/src/realtime-testing/setup-realtime-test.tsx +160 -0
- package/src/selector.ts +25 -25
- package/src/silo.ts +38 -38
- package/src/subscribe.ts +68 -68
- package/src/timeline.ts +13 -13
- package/src/transaction.ts +28 -28
- package/src/web-effects/storage.ts +17 -17
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/realtime-react/realtime-context.tsx","../../src/realtime-react/realtime-state.ts","../../src/realtime-react/use-pull.ts","../../src/react/store-context.tsx","../../src/realtime-react/use-pull-family.ts","../../src/realtime-react/use-pull-family-member.ts","../../src/realtime-react/use-push.ts","../../src/realtime-react/use-server-action.ts","../../src/realtime-react/realtime-hooks.ts"],"sourcesContent":["import * as React from \"react\"\n\nimport * as AR from \"atom.io/react\"\nimport type { Socket } from \"socket.io-client\"\nimport { io } from \"socket.io-client\"\n\nimport { myIdState__INTERNAL } from \"./realtime-state\"\n\nexport const RealtimeContext = React.createContext<{ socket: Socket }>({\n\tsocket: io(),\n})\n\nexport const RealtimeProvider: React.FC<{\n\tchildren: React.ReactNode\n\tsocket: Socket\n}> = ({ children, socket }) => {\n\tconst setMyId = AR.useI(myIdState__INTERNAL)\n\tReact.useEffect(() => {\n\t\tsocket.on(`connect`, () => {\n\t\t\tsetMyId(socket.id)\n\t\t})\n\t\tsocket.on(`disconnect`, () => {\n\t\t\tsetMyId(null)\n\t\t})\n\t}, [socket, setMyId])\n\treturn (\n\t\t<RealtimeContext.Provider value={{ socket }}>\n\t\t\t{children}\n\t\t</RealtimeContext.Provider>\n\t)\n}\n","import * as AtomIO from \"atom.io\"\n\nexport const myIdState__INTERNAL = AtomIO.atom<string | null>({\n\tkey: `myId__INTERNAL`,\n\tdefault: null,\n})\nexport const myIdState = AtomIO.selector<string | null>({\n\tkey: `myId`,\n\tget: ({ get }) => get(myIdState__INTERNAL),\n})\n","import * as React from \"react\"\n\nimport * as AtomIO from \"atom.io\"\n\nimport type { Json } from \"~/packages/anvl/src/json\"\n\nimport { RealtimeContext } from \"./realtime-context\"\nimport { StoreContext } from \"../react\"\n\nexport function usePull<J extends Json>(token: AtomIO.StateToken<J>): void {\n\tconst { socket } = React.useContext(RealtimeContext)\n\tconst store = React.useContext(StoreContext)\n\tReact.useEffect(() => {\n\t\tsocket.on(`serve:${token.key}`, (data: J) => {\n\t\t\tAtomIO.setState(token, data, store)\n\t\t})\n\t\tsocket.emit(`sub:${token.key}`)\n\t\treturn () => {\n\t\t\tsocket.off(`serve:${token.key}`)\n\t\t\tsocket.emit(`unsub:${token.key}`)\n\t\t}\n\t}, [token.key])\n}\n","import * as React from \"react\"\n\nimport * as AtomIO from \"atom.io\"\n\nexport const StoreContext = React.createContext<AtomIO.Store>(\n\tAtomIO.__INTERNAL__.IMPLICIT.STORE,\n)\n\nexport const StoreProvider: React.FC<{\n\tchildren: React.ReactNode\n\tstore?: AtomIO.Store\n}> = ({ children, store = AtomIO.__INTERNAL__.IMPLICIT.STORE }) => (\n\t<StoreContext.Provider value={store}>{children}</StoreContext.Provider>\n)\n","import * as React from \"react\"\n\nimport * as AtomIO from \"atom.io\"\n\nimport type { Json } from \"~/packages/anvl/src/json\"\n\nimport { RealtimeContext } from \"./realtime-context\"\nimport { StoreContext } from \"../react\"\n\nexport function usePullFamily<J extends Json>(\n\tfamily: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,\n): void {\n\tconst { socket } = React.useContext(RealtimeContext)\n\tconst store = React.useContext(StoreContext)\n\tReact.useEffect(() => {\n\t\tsocket.on(`serve:${family.key}`, (key: Json, data: J) => {\n\t\t\tAtomIO.setState(family(key), data, store)\n\t\t})\n\t\tsocket?.emit(`sub:${family.key}`)\n\t\treturn () => {\n\t\t\tsocket?.off(`serve:${family.key}`)\n\t\t\tsocket?.emit(`unsub:${family.key}`)\n\t\t}\n\t}, [family.key])\n}\n","import * as React from \"react\"\n\nimport * as AtomIO from \"atom.io\"\n\nimport type { Json } from \"~/packages/anvl/src/json\"\n\nimport { RealtimeContext } from \"./realtime-context\"\nimport { StoreContext } from \"../react\"\n\nexport function usePullFamilyMember<J extends Json>(\n\tfamily: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,\n\tsubKey: AtomIO.Serializable,\n): void {\n\tconst token = family(subKey)\n\tconst { socket } = React.useContext(RealtimeContext)\n\tconst store = React.useContext(StoreContext)\n\tReact.useEffect(() => {\n\t\tsocket?.on(`serve:${token.key}`, (data: J) => {\n\t\t\tAtomIO.setState(family(subKey), data, store)\n\t\t})\n\t\tsocket?.emit(`sub:${family.key}`, subKey)\n\t\treturn () => {\n\t\t\tsocket?.off(`serve:${token.key}`)\n\t\t\tsocket?.emit(`unsub:${token.key}`)\n\t\t}\n\t}, [family.key])\n}\n","import * as React from \"react\"\n\nimport * as AtomIO from \"atom.io\"\n\nimport type { Json } from \"~/packages/anvl/src/json\"\n\nimport { RealtimeContext } from \"./realtime-context\"\nimport { StoreContext } from \"../react\"\n\nexport function usePush<J extends Json>(token: AtomIO.StateToken<J>): void {\n\tconst { socket } = React.useContext(RealtimeContext)\n\tconst store = React.useContext(StoreContext)\n\tReact.useEffect(() => {\n\t\tsocket.emit(`claim:${token.key}`)\n\t\tAtomIO.subscribe(\n\t\t\ttoken,\n\t\t\t({ newValue }) => {\n\t\t\t\tsocket.emit(`pub:${token.key}`, newValue)\n\t\t\t},\n\t\t\tstore,\n\t\t)\n\t\treturn () => {\n\t\t\tsocket.emit(`unclaim:${token.key}`)\n\t\t}\n\t}, [token.key])\n}\n","import * as React from \"react\"\n\nimport * as AtomIO from \"atom.io\"\nimport { StoreContext } from \"atom.io/react\"\n\nimport type { ƒn } from \"~/packages/anvl/src/function\"\n\nimport { RealtimeContext } from \"./realtime-context\"\n\nconst TX_SUBS = new Map<string, number>()\nexport function useServerAction<ƒ extends ƒn>(\n\ttoken: AtomIO.TransactionToken<ƒ>,\n): (...parameters: Parameters<ƒ>) => ReturnType<ƒ> {\n\tconst store = React.useContext(StoreContext)\n\tconst { socket } = React.useContext(RealtimeContext)\n\tReact.useEffect(() => {\n\t\tconst count = TX_SUBS.get(token.key) ?? 0\n\t\tTX_SUBS.set(token.key, count + 1)\n\t\tconst unsubscribe =\n\t\t\tcount === 0\n\t\t\t\t? AtomIO.subscribeToTransaction(\n\t\t\t\t\t\ttoken,\n\t\t\t\t\t\t(update) => socket.emit(`tx:${token.key}`, update),\n\t\t\t\t\t\tstore,\n\t\t\t\t )\n\t\t\t\t: () => null\n\t\treturn () => {\n\t\t\tconst newCount = TX_SUBS.get(token.key) ?? 0\n\t\t\tTX_SUBS.set(token.key, newCount - 1)\n\t\t\tunsubscribe()\n\t\t}\n\t}, [token.key])\n\treturn AtomIO.runTransaction(token, store)\n}\n","import type * as AtomIO from \"atom.io\"\n\nimport type { ƒn } from \"~/packages/anvl/src/function\"\nimport type { Json } from \"~/packages/anvl/src/json\"\n\nimport { usePull } from \"./use-pull\"\nimport { usePullFamily } from \"./use-pull-family\"\nimport { usePullFamilyMember } from \"./use-pull-family-member\"\nimport { usePush } from \"./use-push\"\nimport { useServerAction } from \"./use-server-action\"\n\nexport type RealtimeHooks = {\n\tusePull: <J extends Json>(token: AtomIO.StateToken<J>) => void\n\tusePullFamily: <J extends Json>(\n\t\tfamily: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,\n\t) => void\n\tusePullFamilyMember: <J extends Json>(\n\t\tfamily: AtomIO.AtomFamily<J> | AtomIO.SelectorFamily<J>,\n\t\tsubKey: string,\n\t) => void\n\tusePush: <J extends Json>(token: AtomIO.StateToken<J>) => void\n\tuseServerAction: <ƒ extends ƒn>(\n\t\ttoken: AtomIO.TransactionToken<ƒ>,\n\t) => (...parameters: Parameters<ƒ>) => ReturnType<ƒ>\n}\n\nexport const realtimeHooks: RealtimeHooks = {\n\tusePull,\n\tusePullFamily,\n\tusePullFamilyMember,\n\tusePush,\n\tuseServerAction,\n}\n\nexport * from \"./use-pull\"\nexport * from \"./use-pull-family\"\nexport * from \"./use-pull-family-member\"\nexport * from \"./use-push\"\nexport * from \"./use-server-action\"\n"],"mappings":";AAAA,YAAY,WAAW;AAEvB,YAAY,QAAQ;AAEpB,SAAS,UAAU;;;ACJnB,YAAY,YAAY;AAEjB,IAAM,sBAA6B,YAAoB;AAAA,EAC7D,KAAK;AAAA,EACL,SAAS;AACV,CAAC;AACM,IAAM,YAAmB,gBAAwB;AAAA,EACvD,KAAK;AAAA,EACL,KAAK,CAAC,EAAE,IAAI,MAAM,IAAI,mBAAmB;AAC1C,CAAC;;;ADiBC;AAlBK,IAAM,kBAAwB,oBAAkC;AAAA,EACtE,QAAQ,GAAG;AACZ,CAAC;AAEM,IAAM,mBAGR,CAAC,EAAE,UAAU,OAAO,MAAM;AAC9B,QAAM,UAAa,QAAK,mBAAmB;AAC3C,EAAM,gBAAU,MAAM;AACrB,WAAO,GAAG,WAAW,MAAM;AAC1B,cAAQ,OAAO,EAAE;AAAA,IAClB,CAAC;AACD,WAAO,GAAG,cAAc,MAAM;AAC7B,cAAQ,IAAI;AAAA,IACb,CAAC;AAAA,EACF,GAAG,CAAC,QAAQ,OAAO,CAAC;AACpB,SACC,oBAAC,gBAAgB,UAAhB,EAAyB,OAAO,EAAE,OAAO,GACxC,UACF;AAEF;;;AE9BA,YAAYA,YAAW;AAEvB,YAAYC,aAAY;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AM,MAAM,GAAG,IAAI,MAAM;AAAA,MACjD;AAAA,IACA,IACA,MAAM;AACV,WAAO,MAAM;AA1Bf,UAAAC;AA2BG,YAAM,YAAWA,MAAA,QAAQ,IAAI,MAAM,GAAG,MAArB,OAAAA,MAA0B;AAC3C,cAAQ,IAAI,MAAM,KAAK,WAAW,CAAC;AACnC,kBAAY;AAAA,IACb;AAAA,EACD,GAAG,CAAC,MAAM,GAAG,CAAC;AACd,SAAc,uBAAe,OAAO,KAAK;AAC1C;;;ACPO,IAAM,gBAA+B;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;","names":["React","AtomIO","React","AtomIO","jsx","React","AtomIO","React","AtomIO","React","AtomIO","React","AtomIO","StoreContext","StoreContext","_a"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { RenderResult } from '@testing-library/react';
|
|
3
|
+
import * as AtomIO from 'atom.io';
|
|
4
|
+
import * as SocketIO from 'socket.io';
|
|
5
|
+
|
|
6
|
+
type TestSetupOptions = {
|
|
7
|
+
server: (tools: {
|
|
8
|
+
socket: SocketIO.Socket;
|
|
9
|
+
silo: AtomIO.Silo;
|
|
10
|
+
}) => void;
|
|
11
|
+
};
|
|
12
|
+
type TestSetupOptions__SingleClient = TestSetupOptions & {
|
|
13
|
+
client: React.FC;
|
|
14
|
+
};
|
|
15
|
+
type TestSetupOptions__MultiClient<ClientNames extends string> = TestSetupOptions & {
|
|
16
|
+
clients: {
|
|
17
|
+
[K in ClientNames]: React.FC;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
type RealtimeTestTools = {
|
|
21
|
+
name: string;
|
|
22
|
+
silo: AtomIO.Silo;
|
|
23
|
+
dispose: () => void;
|
|
24
|
+
};
|
|
25
|
+
type RealtimeTestClient = RealtimeTestTools & {
|
|
26
|
+
renderResult: RenderResult;
|
|
27
|
+
prettyPrint: () => void;
|
|
28
|
+
reconnect: () => void;
|
|
29
|
+
disconnect: () => void;
|
|
30
|
+
};
|
|
31
|
+
type RealtimeTestServer = RealtimeTestTools & {
|
|
32
|
+
port: number;
|
|
33
|
+
};
|
|
34
|
+
type RealtimeTestAPI = {
|
|
35
|
+
server: RealtimeTestServer;
|
|
36
|
+
teardown: () => void;
|
|
37
|
+
};
|
|
38
|
+
type RealtimeTestAPI__SingleClient = RealtimeTestAPI & {
|
|
39
|
+
client: RealtimeTestClient;
|
|
40
|
+
};
|
|
41
|
+
type RealtimeTestAPI__MultiClient<ClientNames extends string> = RealtimeTestAPI & {
|
|
42
|
+
clients: Record<ClientNames, RealtimeTestClient>;
|
|
43
|
+
};
|
|
44
|
+
declare const setupRealtimeTestServer: (options: TestSetupOptions) => RealtimeTestServer;
|
|
45
|
+
declare const setupRealtimeTestClient: (options: TestSetupOptions__SingleClient, name: string, port: number) => RealtimeTestClient;
|
|
46
|
+
declare const singleClient: (options: TestSetupOptions__SingleClient) => RealtimeTestAPI__SingleClient;
|
|
47
|
+
declare const multiClient: <ClientNames extends string>(options: TestSetupOptions__MultiClient<ClientNames>) => RealtimeTestAPI__MultiClient<ClientNames>;
|
|
48
|
+
|
|
49
|
+
export { RealtimeTestAPI, RealtimeTestAPI__MultiClient, RealtimeTestAPI__SingleClient, RealtimeTestClient, RealtimeTestServer, RealtimeTestTools, TestSetupOptions, TestSetupOptions__MultiClient, TestSetupOptions__SingleClient, multiClient, setupRealtimeTestClient, setupRealtimeTestServer, singleClient };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { RenderResult } from '@testing-library/react';
|
|
3
|
+
import * as AtomIO from 'atom.io';
|
|
4
|
+
import * as SocketIO from 'socket.io';
|
|
5
|
+
|
|
6
|
+
type TestSetupOptions = {
|
|
7
|
+
server: (tools: {
|
|
8
|
+
socket: SocketIO.Socket;
|
|
9
|
+
silo: AtomIO.Silo;
|
|
10
|
+
}) => void;
|
|
11
|
+
};
|
|
12
|
+
type TestSetupOptions__SingleClient = TestSetupOptions & {
|
|
13
|
+
client: React.FC;
|
|
14
|
+
};
|
|
15
|
+
type TestSetupOptions__MultiClient<ClientNames extends string> = TestSetupOptions & {
|
|
16
|
+
clients: {
|
|
17
|
+
[K in ClientNames]: React.FC;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
type RealtimeTestTools = {
|
|
21
|
+
name: string;
|
|
22
|
+
silo: AtomIO.Silo;
|
|
23
|
+
dispose: () => void;
|
|
24
|
+
};
|
|
25
|
+
type RealtimeTestClient = RealtimeTestTools & {
|
|
26
|
+
renderResult: RenderResult;
|
|
27
|
+
prettyPrint: () => void;
|
|
28
|
+
reconnect: () => void;
|
|
29
|
+
disconnect: () => void;
|
|
30
|
+
};
|
|
31
|
+
type RealtimeTestServer = RealtimeTestTools & {
|
|
32
|
+
port: number;
|
|
33
|
+
};
|
|
34
|
+
type RealtimeTestAPI = {
|
|
35
|
+
server: RealtimeTestServer;
|
|
36
|
+
teardown: () => void;
|
|
37
|
+
};
|
|
38
|
+
type RealtimeTestAPI__SingleClient = RealtimeTestAPI & {
|
|
39
|
+
client: RealtimeTestClient;
|
|
40
|
+
};
|
|
41
|
+
type RealtimeTestAPI__MultiClient<ClientNames extends string> = RealtimeTestAPI & {
|
|
42
|
+
clients: Record<ClientNames, RealtimeTestClient>;
|
|
43
|
+
};
|
|
44
|
+
declare const setupRealtimeTestServer: (options: TestSetupOptions) => RealtimeTestServer;
|
|
45
|
+
declare const setupRealtimeTestClient: (options: TestSetupOptions__SingleClient, name: string, port: number) => RealtimeTestClient;
|
|
46
|
+
declare const singleClient: (options: TestSetupOptions__SingleClient) => RealtimeTestAPI__SingleClient;
|
|
47
|
+
declare const multiClient: <ClientNames extends string>(options: TestSetupOptions__MultiClient<ClientNames>) => RealtimeTestAPI__MultiClient<ClientNames>;
|
|
48
|
+
|
|
49
|
+
export { RealtimeTestAPI, RealtimeTestAPI__MultiClient, RealtimeTestAPI__SingleClient, RealtimeTestClient, RealtimeTestServer, RealtimeTestTools, TestSetupOptions, TestSetupOptions__MultiClient, TestSetupOptions__SingleClient, multiClient, setupRealtimeTestClient, setupRealtimeTestServer, singleClient };
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
|
+
};
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
37
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
38
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
39
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
40
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
41
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
42
|
+
mod
|
|
43
|
+
));
|
|
44
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
45
|
+
|
|
46
|
+
// ../src/realtime-testing/index.ts
|
|
47
|
+
var realtime_testing_exports = {};
|
|
48
|
+
__export(realtime_testing_exports, {
|
|
49
|
+
multiClient: () => multiClient,
|
|
50
|
+
setupRealtimeTestClient: () => setupRealtimeTestClient,
|
|
51
|
+
setupRealtimeTestServer: () => setupRealtimeTestServer,
|
|
52
|
+
singleClient: () => singleClient
|
|
53
|
+
});
|
|
54
|
+
module.exports = __toCommonJS(realtime_testing_exports);
|
|
55
|
+
|
|
56
|
+
// ../src/realtime-testing/setup-realtime-test.tsx
|
|
57
|
+
var http = __toESM(require("http"));
|
|
58
|
+
var import_react = require("@testing-library/react");
|
|
59
|
+
var AtomIO = __toESM(require("atom.io"));
|
|
60
|
+
var AR = __toESM(require("atom.io/react"));
|
|
61
|
+
var RTC = __toESM(require("atom.io/realtime-react"));
|
|
62
|
+
var RR = __toESM(require("fp-ts/ReadonlyRecord"));
|
|
63
|
+
var Happy = __toESM(require("happy-dom"));
|
|
64
|
+
var SocketIO = __toESM(require("socket.io"));
|
|
65
|
+
var import_socket = require("socket.io-client");
|
|
66
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
67
|
+
var setupRealtimeTestServer = (options) => {
|
|
68
|
+
const httpServer = http.createServer((_, res) => res.end(`Hello World!`));
|
|
69
|
+
const address = httpServer.listen().address();
|
|
70
|
+
const port = typeof address === `string` ? 80 : address === null ? null : address.port;
|
|
71
|
+
if (port === null)
|
|
72
|
+
throw new Error(`Could not determine port for test server`);
|
|
73
|
+
const server = new SocketIO.Server(httpServer);
|
|
74
|
+
const silo2 = AtomIO.silo(`SERVER`, AtomIO.__INTERNAL__.IMPLICIT.STORE);
|
|
75
|
+
server.on(`connection`, (socket) => {
|
|
76
|
+
options.server({ socket, silo: silo2 });
|
|
77
|
+
});
|
|
78
|
+
const dispose = () => {
|
|
79
|
+
server.close();
|
|
80
|
+
AtomIO.__INTERNAL__.clearStore(silo2.store);
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
name: `SERVER`,
|
|
84
|
+
silo: silo2,
|
|
85
|
+
dispose,
|
|
86
|
+
port
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
var setupRealtimeTestClient = (options, name, port) => {
|
|
90
|
+
const socket = (0, import_socket.io)(`http://localhost:${port}/`);
|
|
91
|
+
const silo2 = AtomIO.silo(name, AtomIO.__INTERNAL__.IMPLICIT.STORE);
|
|
92
|
+
const { document } = new Happy.Window();
|
|
93
|
+
document.body.innerHTML = `<div id="app"></div>`;
|
|
94
|
+
const renderResult = (0, import_react.render)(
|
|
95
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(AR.StoreProvider, { store: silo2.store, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RTC.RealtimeProvider, { socket, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(options.client, {}) }) }),
|
|
96
|
+
{
|
|
97
|
+
container: document.querySelector(`#app`)
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
const prettyPrint = () => console.log((0, import_react.prettyDOM)(renderResult.container));
|
|
101
|
+
const disconnect = () => socket.disconnect();
|
|
102
|
+
const reconnect = () => socket.connect();
|
|
103
|
+
const dispose = () => {
|
|
104
|
+
socket.disconnect();
|
|
105
|
+
AtomIO.__INTERNAL__.clearStore(silo2.store);
|
|
106
|
+
};
|
|
107
|
+
return {
|
|
108
|
+
name,
|
|
109
|
+
silo: silo2,
|
|
110
|
+
renderResult,
|
|
111
|
+
prettyPrint,
|
|
112
|
+
disconnect,
|
|
113
|
+
reconnect,
|
|
114
|
+
dispose
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
var singleClient = (options) => {
|
|
118
|
+
const server = setupRealtimeTestServer(options);
|
|
119
|
+
const client = setupRealtimeTestClient(options, `CLIENT`, server.port);
|
|
120
|
+
return {
|
|
121
|
+
client,
|
|
122
|
+
server,
|
|
123
|
+
teardown: () => {
|
|
124
|
+
client.dispose();
|
|
125
|
+
server.dispose();
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
var multiClient = (options) => {
|
|
130
|
+
const server = setupRealtimeTestServer(options);
|
|
131
|
+
const clients = RR.toEntries(options.clients).reduce(
|
|
132
|
+
(clients2, [name, client]) => __spreadProps(__spreadValues({}, clients2), {
|
|
133
|
+
[name]: setupRealtimeTestClient(__spreadProps(__spreadValues({}, options), { client }), name, server.port)
|
|
134
|
+
}),
|
|
135
|
+
{}
|
|
136
|
+
);
|
|
137
|
+
return {
|
|
138
|
+
clients,
|
|
139
|
+
server,
|
|
140
|
+
teardown: () => {
|
|
141
|
+
RR.toEntries(clients).forEach(([, client]) => client.dispose());
|
|
142
|
+
server.dispose();
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
147
|
+
0 && (module.exports = {
|
|
148
|
+
multiClient,
|
|
149
|
+
setupRealtimeTestClient,
|
|
150
|
+
setupRealtimeTestServer,
|
|
151
|
+
singleClient
|
|
152
|
+
});
|
|
153
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/realtime-testing/index.ts","../../src/realtime-testing/setup-realtime-test.tsx"],"sourcesContent":["export * from \"./setup-realtime-test\"\n","import * as http from \"http\"\n\nimport * as React from \"react\"\n\nimport { prettyDOM, render, type RenderResult } from \"@testing-library/react\"\nimport * as AtomIO from \"atom.io\"\nimport * as AR from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-react\"\nimport * as RR from \"fp-ts/ReadonlyRecord\"\nimport * as Happy from \"happy-dom\"\nimport * as SocketIO from \"socket.io\"\nimport type { Socket as ClientSocket } from \"socket.io-client\"\nimport { io } from \"socket.io-client\"\n\nexport type TestSetupOptions = {\n\tserver: (tools: { socket: SocketIO.Socket; silo: AtomIO.Silo }) => void\n}\nexport type TestSetupOptions__SingleClient = TestSetupOptions & {\n\tclient: React.FC\n}\nexport type TestSetupOptions__MultiClient<ClientNames extends string> =\n\tTestSetupOptions & {\n\t\tclients: {\n\t\t\t[K in ClientNames]: React.FC\n\t\t}\n\t}\n\nexport type RealtimeTestTools = {\n\tname: string\n\tsilo: AtomIO.Silo\n\tdispose: () => void\n}\nexport type RealtimeTestClient = RealtimeTestTools & {\n\trenderResult: RenderResult\n\tprettyPrint: () => void\n\treconnect: () => void\n\tdisconnect: () => void\n}\nexport type RealtimeTestServer = RealtimeTestTools & {\n\tport: number\n}\n\nexport type RealtimeTestAPI = {\n\tserver: RealtimeTestServer\n\tteardown: () => void\n}\nexport type RealtimeTestAPI__SingleClient = RealtimeTestAPI & {\n\tclient: RealtimeTestClient\n}\nexport type RealtimeTestAPI__MultiClient<ClientNames extends string> =\n\tRealtimeTestAPI & {\n\t\tclients: Record<ClientNames, RealtimeTestClient>\n\t}\n\nexport const setupRealtimeTestServer = (\n\toptions: TestSetupOptions,\n): RealtimeTestServer => {\n\tconst httpServer = http.createServer((_, res) => res.end(`Hello World!`))\n\tconst address = httpServer.listen().address()\n\tconst port =\n\t\ttypeof address === `string` ? 80 : address === null ? null : address.port\n\tif (port === null) throw new Error(`Could not determine port for test server`)\n\tconst server = new SocketIO.Server(httpServer)\n\tconst silo = AtomIO.silo(`SERVER`, AtomIO.__INTERNAL__.IMPLICIT.STORE)\n\n\tserver.on(`connection`, (socket: SocketIO.Socket) => {\n\t\toptions.server({ socket, silo })\n\t})\n\n\tconst dispose = () => {\n\t\tserver.close()\n\t\tAtomIO.__INTERNAL__.clearStore(silo.store)\n\t}\n\n\treturn {\n\t\tname: `SERVER`,\n\t\tsilo,\n\t\tdispose,\n\t\tport,\n\t}\n}\nexport const setupRealtimeTestClient = (\n\toptions: TestSetupOptions__SingleClient,\n\tname: string,\n\tport: number,\n): RealtimeTestClient => {\n\tconst socket: ClientSocket = io(`http://localhost:${port}/`)\n\tconst silo = AtomIO.silo(name, AtomIO.__INTERNAL__.IMPLICIT.STORE)\n\n\tconst { document } = new Happy.Window()\n\tdocument.body.innerHTML = `<div id=\"app\"></div>`\n\tconst renderResult = render(\n\t\t<AR.StoreProvider store={silo.store}>\n\t\t\t<RTC.RealtimeProvider socket={socket}>\n\t\t\t\t<options.client />\n\t\t\t</RTC.RealtimeProvider>\n\t\t</AR.StoreProvider>,\n\t\t{\n\t\t\tcontainer: document.querySelector(`#app`) as unknown as HTMLElement,\n\t\t},\n\t)\n\n\tconst prettyPrint = () => console.log(prettyDOM(renderResult.container))\n\n\tconst disconnect = () => socket.disconnect()\n\tconst reconnect = () => socket.connect()\n\n\tconst dispose = () => {\n\t\tsocket.disconnect()\n\t\tAtomIO.__INTERNAL__.clearStore(silo.store)\n\t}\n\n\treturn {\n\t\tname,\n\t\tsilo,\n\t\trenderResult,\n\t\tprettyPrint,\n\t\tdisconnect,\n\t\treconnect,\n\t\tdispose,\n\t}\n}\n\nexport const singleClient = (\n\toptions: TestSetupOptions__SingleClient,\n): RealtimeTestAPI__SingleClient => {\n\tconst server = setupRealtimeTestServer(options)\n\tconst client = setupRealtimeTestClient(options, `CLIENT`, server.port)\n\n\treturn {\n\t\tclient,\n\t\tserver,\n\t\tteardown: () => {\n\t\t\tclient.dispose()\n\t\t\tserver.dispose()\n\t\t},\n\t}\n}\n\nexport const multiClient = <ClientNames extends string>(\n\toptions: TestSetupOptions__MultiClient<ClientNames>,\n): RealtimeTestAPI__MultiClient<ClientNames> => {\n\tconst server = setupRealtimeTestServer(options)\n\tconst clients = RR.toEntries(options.clients).reduce(\n\t\t(clients, [name, client]) => ({\n\t\t\t...clients,\n\t\t\t[name]: setupRealtimeTestClient({ ...options, client }, name, server.port),\n\t\t}),\n\t\t{} as Record<ClientNames, RealtimeTestClient>,\n\t)\n\n\treturn {\n\t\tclients,\n\t\tserver,\n\t\tteardown: () => {\n\t\t\tRR.toEntries(clients).forEach(([, client]) => client.dispose())\n\t\t\tserver.dispose()\n\t\t},\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,WAAsB;AAItB,mBAAqD;AACrD,aAAwB;AACxB,SAAoB;AACpB,UAAqB;AACrB,SAAoB;AACpB,YAAuB;AACvB,eAA0B;AAE1B,oBAAmB;AAkFf;AAxCG,IAAM,0BAA0B,CACtC,YACwB;AACxB,QAAM,aAAkB,kBAAa,CAAC,GAAG,QAAQ,IAAI,IAAI,cAAc,CAAC;AACxE,QAAM,UAAU,WAAW,OAAO,EAAE,QAAQ;AAC5C,QAAM,OACL,OAAO,YAAY,WAAW,KAAK,YAAY,OAAO,OAAO,QAAQ;AACtE,MAAI,SAAS;AAAM,UAAM,IAAI,MAAM,0CAA0C;AAC7E,QAAM,SAAS,IAAa,gBAAO,UAAU;AAC7C,QAAMA,QAAc,YAAK,UAAiB,oBAAa,SAAS,KAAK;AAErE,SAAO,GAAG,cAAc,CAAC,WAA4B;AACpD,YAAQ,OAAO,EAAE,QAAQ,MAAAA,MAAK,CAAC;AAAA,EAChC,CAAC;AA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AO;AAC9C,QAAM,UAAa,aAAU,QAAQ,OAAO,EAAE;AAAA,IAC7C,CAACC,UAAS,CAAC,MAAM,MAAM,MAAO,iCAC1BA,WAD0B;AAAA,MAE7B,CAAC,IAAI,GAAG,wBAAwB,iCAAK,UAAL,EAAc,OAAO,IAAG,MAAM,OAAO,IAAI;AAAA,IAC1E;AAAA,IACA,CAAC;AAAA,EACF;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA,UAAU,MAAM;AACf,MAAG,aAAU,OAAO,EAAE,QAAQ,CAAC,CAAC,EAAE,MAAM,MAAM,OAAO,QAAQ,CAAC;AAC9D,aAAO,QAAQ;AAAA,IAChB;AAAA,EACD;AACD;","names":["silo","clients"]}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
|
|
21
|
+
// ../src/realtime-testing/setup-realtime-test.tsx
|
|
22
|
+
import * as http from "http";
|
|
23
|
+
import { prettyDOM, render } from "@testing-library/react";
|
|
24
|
+
import * as AtomIO from "atom.io";
|
|
25
|
+
import * as AR from "atom.io/react";
|
|
26
|
+
import * as RTC from "atom.io/realtime-react";
|
|
27
|
+
import * as RR from "fp-ts/ReadonlyRecord";
|
|
28
|
+
import * as Happy from "happy-dom";
|
|
29
|
+
import * as SocketIO from "socket.io";
|
|
30
|
+
import { io } from "socket.io-client";
|
|
31
|
+
import { jsx } from "react/jsx-runtime";
|
|
32
|
+
var setupRealtimeTestServer = (options) => {
|
|
33
|
+
const httpServer = http.createServer((_, res) => res.end(`Hello World!`));
|
|
34
|
+
const address = httpServer.listen().address();
|
|
35
|
+
const port = typeof address === `string` ? 80 : address === null ? null : address.port;
|
|
36
|
+
if (port === null)
|
|
37
|
+
throw new Error(`Could not determine port for test server`);
|
|
38
|
+
const server = new SocketIO.Server(httpServer);
|
|
39
|
+
const silo2 = AtomIO.silo(`SERVER`, AtomIO.__INTERNAL__.IMPLICIT.STORE);
|
|
40
|
+
server.on(`connection`, (socket) => {
|
|
41
|
+
options.server({ socket, silo: silo2 });
|
|
42
|
+
});
|
|
43
|
+
const dispose = () => {
|
|
44
|
+
server.close();
|
|
45
|
+
AtomIO.__INTERNAL__.clearStore(silo2.store);
|
|
46
|
+
};
|
|
47
|
+
return {
|
|
48
|
+
name: `SERVER`,
|
|
49
|
+
silo: silo2,
|
|
50
|
+
dispose,
|
|
51
|
+
port
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
var setupRealtimeTestClient = (options, name, port) => {
|
|
55
|
+
const socket = io(`http://localhost:${port}/`);
|
|
56
|
+
const silo2 = AtomIO.silo(name, AtomIO.__INTERNAL__.IMPLICIT.STORE);
|
|
57
|
+
const { document } = new Happy.Window();
|
|
58
|
+
document.body.innerHTML = `<div id="app"></div>`;
|
|
59
|
+
const renderResult = render(
|
|
60
|
+
/* @__PURE__ */ jsx(AR.StoreProvider, { store: silo2.store, children: /* @__PURE__ */ jsx(RTC.RealtimeProvider, { socket, children: /* @__PURE__ */ jsx(options.client, {}) }) }),
|
|
61
|
+
{
|
|
62
|
+
container: document.querySelector(`#app`)
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
const prettyPrint = () => console.log(prettyDOM(renderResult.container));
|
|
66
|
+
const disconnect = () => socket.disconnect();
|
|
67
|
+
const reconnect = () => socket.connect();
|
|
68
|
+
const dispose = () => {
|
|
69
|
+
socket.disconnect();
|
|
70
|
+
AtomIO.__INTERNAL__.clearStore(silo2.store);
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
name,
|
|
74
|
+
silo: silo2,
|
|
75
|
+
renderResult,
|
|
76
|
+
prettyPrint,
|
|
77
|
+
disconnect,
|
|
78
|
+
reconnect,
|
|
79
|
+
dispose
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
var singleClient = (options) => {
|
|
83
|
+
const server = setupRealtimeTestServer(options);
|
|
84
|
+
const client = setupRealtimeTestClient(options, `CLIENT`, server.port);
|
|
85
|
+
return {
|
|
86
|
+
client,
|
|
87
|
+
server,
|
|
88
|
+
teardown: () => {
|
|
89
|
+
client.dispose();
|
|
90
|
+
server.dispose();
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
var multiClient = (options) => {
|
|
95
|
+
const server = setupRealtimeTestServer(options);
|
|
96
|
+
const clients = RR.toEntries(options.clients).reduce(
|
|
97
|
+
(clients2, [name, client]) => __spreadProps(__spreadValues({}, clients2), {
|
|
98
|
+
[name]: setupRealtimeTestClient(__spreadProps(__spreadValues({}, options), { client }), name, server.port)
|
|
99
|
+
}),
|
|
100
|
+
{}
|
|
101
|
+
);
|
|
102
|
+
return {
|
|
103
|
+
clients,
|
|
104
|
+
server,
|
|
105
|
+
teardown: () => {
|
|
106
|
+
RR.toEntries(clients).forEach(([, client]) => client.dispose());
|
|
107
|
+
server.dispose();
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
export {
|
|
112
|
+
multiClient,
|
|
113
|
+
setupRealtimeTestClient,
|
|
114
|
+
setupRealtimeTestServer,
|
|
115
|
+
singleClient
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/realtime-testing/setup-realtime-test.tsx"],"sourcesContent":["import * as http from \"http\"\n\nimport * as React from \"react\"\n\nimport { prettyDOM, render, type RenderResult } from \"@testing-library/react\"\nimport * as AtomIO from \"atom.io\"\nimport * as AR from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-react\"\nimport * as RR from \"fp-ts/ReadonlyRecord\"\nimport * as Happy from \"happy-dom\"\nimport * as SocketIO from \"socket.io\"\nimport type { Socket as ClientSocket } from \"socket.io-client\"\nimport { io } from \"socket.io-client\"\n\nexport type TestSetupOptions = {\n\tserver: (tools: { socket: SocketIO.Socket; silo: AtomIO.Silo }) => void\n}\nexport type TestSetupOptions__SingleClient = TestSetupOptions & {\n\tclient: React.FC\n}\nexport type TestSetupOptions__MultiClient<ClientNames extends string> =\n\tTestSetupOptions & {\n\t\tclients: {\n\t\t\t[K in ClientNames]: React.FC\n\t\t}\n\t}\n\nexport type RealtimeTestTools = {\n\tname: string\n\tsilo: AtomIO.Silo\n\tdispose: () => void\n}\nexport type RealtimeTestClient = RealtimeTestTools & {\n\trenderResult: RenderResult\n\tprettyPrint: () => void\n\treconnect: () => void\n\tdisconnect: () => void\n}\nexport type RealtimeTestServer = RealtimeTestTools & {\n\tport: number\n}\n\nexport type RealtimeTestAPI = {\n\tserver: RealtimeTestServer\n\tteardown: () => void\n}\nexport type RealtimeTestAPI__SingleClient = RealtimeTestAPI & {\n\tclient: RealtimeTestClient\n}\nexport type RealtimeTestAPI__MultiClient<ClientNames extends string> =\n\tRealtimeTestAPI & {\n\t\tclients: Record<ClientNames, RealtimeTestClient>\n\t}\n\nexport const setupRealtimeTestServer = (\n\toptions: TestSetupOptions,\n): RealtimeTestServer => {\n\tconst httpServer = http.createServer((_, res) => res.end(`Hello World!`))\n\tconst address = httpServer.listen().address()\n\tconst port =\n\t\ttypeof address === `string` ? 80 : address === null ? null : address.port\n\tif (port === null) throw new Error(`Could not determine port for test server`)\n\tconst server = new SocketIO.Server(httpServer)\n\tconst silo = AtomIO.silo(`SERVER`, AtomIO.__INTERNAL__.IMPLICIT.STORE)\n\n\tserver.on(`connection`, (socket: SocketIO.Socket) => {\n\t\toptions.server({ socket, silo })\n\t})\n\n\tconst dispose = () => {\n\t\tserver.close()\n\t\tAtomIO.__INTERNAL__.clearStore(silo.store)\n\t}\n\n\treturn {\n\t\tname: `SERVER`,\n\t\tsilo,\n\t\tdispose,\n\t\tport,\n\t}\n}\nexport const setupRealtimeTestClient = (\n\toptions: TestSetupOptions__SingleClient,\n\tname: string,\n\tport: number,\n): RealtimeTestClient => {\n\tconst socket: ClientSocket = io(`http://localhost:${port}/`)\n\tconst silo = AtomIO.silo(name, AtomIO.__INTERNAL__.IMPLICIT.STORE)\n\n\tconst { document } = new Happy.Window()\n\tdocument.body.innerHTML = `<div id=\"app\"></div>`\n\tconst renderResult = render(\n\t\t<AR.StoreProvider store={silo.store}>\n\t\t\t<RTC.RealtimeProvider socket={socket}>\n\t\t\t\t<options.client />\n\t\t\t</RTC.RealtimeProvider>\n\t\t</AR.StoreProvider>,\n\t\t{\n\t\t\tcontainer: document.querySelector(`#app`) as unknown as HTMLElement,\n\t\t},\n\t)\n\n\tconst prettyPrint = () => console.log(prettyDOM(renderResult.container))\n\n\tconst disconnect = () => socket.disconnect()\n\tconst reconnect = () => socket.connect()\n\n\tconst dispose = () => {\n\t\tsocket.disconnect()\n\t\tAtomIO.__INTERNAL__.clearStore(silo.store)\n\t}\n\n\treturn {\n\t\tname,\n\t\tsilo,\n\t\trenderResult,\n\t\tprettyPrint,\n\t\tdisconnect,\n\t\treconnect,\n\t\tdispose,\n\t}\n}\n\nexport const singleClient = (\n\toptions: TestSetupOptions__SingleClient,\n): RealtimeTestAPI__SingleClient => {\n\tconst server = setupRealtimeTestServer(options)\n\tconst client = setupRealtimeTestClient(options, `CLIENT`, server.port)\n\n\treturn {\n\t\tclient,\n\t\tserver,\n\t\tteardown: () => {\n\t\t\tclient.dispose()\n\t\t\tserver.dispose()\n\t\t},\n\t}\n}\n\nexport const multiClient = <ClientNames extends string>(\n\toptions: TestSetupOptions__MultiClient<ClientNames>,\n): RealtimeTestAPI__MultiClient<ClientNames> => {\n\tconst server = setupRealtimeTestServer(options)\n\tconst clients = RR.toEntries(options.clients).reduce(\n\t\t(clients, [name, client]) => ({\n\t\t\t...clients,\n\t\t\t[name]: setupRealtimeTestClient({ ...options, client }, name, server.port),\n\t\t}),\n\t\t{} as Record<ClientNames, RealtimeTestClient>,\n\t)\n\n\treturn {\n\t\tclients,\n\t\tserver,\n\t\tteardown: () => {\n\t\t\tRR.toEntries(clients).forEach(([, client]) => client.dispose())\n\t\t\tserver.dispose()\n\t\t},\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,YAAY,UAAU;AAItB,SAAS,WAAW,cAAiC;AACrD,YAAY,YAAY;AACxB,YAAY,QAAQ;AACpB,YAAY,SAAS;AACrB,YAAY,QAAQ;AACpB,YAAY,WAAW;AACvB,YAAY,cAAc;AAE1B,SAAS,UAAU;AAkFf;AAxCG,IAAM,0BAA0B,CACtC,YACwB;AACxB,QAAM,aAAkB,kBAAa,CAAC,GAAG,QAAQ,IAAI,IAAI,cAAc,CAAC;AACxE,QAAM,UAAU,WAAW,OAAO,EAAE,QAAQ;AAC5C,QAAM,OACL,OAAO,YAAY,WAAW,KAAK,YAAY,OAAO,OAAO,QAAQ;AACtE,MAAI,SAAS;AAAM,UAAM,IAAI,MAAM,0CAA0C;AAC7E,QAAM,SAAS,IAAa,gBAAO,UAAU;AAC7C,QAAMA,QAAc,YAAK,UAAiB,oBAAa,SAAS,KAAK;AAErE,SAAO,GAAG,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AA,IAChB;AAAA,EACD;AACD;AAEO,IAAM,cAAc,CAC1B,YAC+C;AAC/C,QAAM,SAAS,wBAAwB,OAAO;AAC9C,QAAM,UAAa,aAAU,QAAQ,OAAO,EAAE;AAAA,IAC7C,CAACC,UAAS,CAAC,MAAM,MAAM,MAAO,iCAC1BA,WAD0B;AAAA,MAE7B,CAAC,IAAI,GAAG,wBAAwB,iCAAK,UAAL,EAAc,OAAO,IAAG,MAAM,OAAO,IAAI;AAAA,IAC1E;AAAA,IACA,CAAC;AAAA,EACF;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA,UAAU,MAAM;AACf,MAAG,aAAU,OAAO,EAAE,QAAQ,CAAC,CAAC,EAAE,MAAM,MAAM,OAAO,QAAQ,CAAC;AAC9D,aAAO,QAAQ;AAAA,IAChB;AAAA,EACD;AACD;","names":["silo","clients"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "atom.io-realtime-testing",
|
|
3
|
+
"private": true,
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"browser": "./dist/index.mjs",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/atom.ts
CHANGED
|
@@ -6,38 +6,38 @@ import type { AtomToken } from "."
|
|
|
6
6
|
import { atomFamily__INTERNAL, atom__INTERNAL } from "./internal"
|
|
7
7
|
|
|
8
8
|
export type Effectors<T> = {
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
setSelf: <V extends T>(next: V | ((oldValue: T) => V)) => void
|
|
10
|
+
onSet: (callback: (options: { newValue: T; oldValue: T }) => void) => void
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export type AtomEffect<T> = (tools: Effectors<T>) => void
|
|
14
14
|
|
|
15
15
|
export type AtomOptions<T> = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
key: string
|
|
17
|
+
default: T | (() => T)
|
|
18
|
+
effects?: AtomEffect<T>[]
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export function atom<T>(options: AtomOptions<T>): AtomToken<T> {
|
|
22
|
-
|
|
22
|
+
return atom__INTERNAL<T>(options)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export type AtomFamilyOptions<T, K extends Serializable> = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
key: string
|
|
27
|
+
default: T | ((key: K) => T)
|
|
28
|
+
effects?: (key: K) => AtomEffect<T>[]
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
export type AtomFamily<T, K extends Serializable = Serializable> = ((
|
|
32
|
-
|
|
32
|
+
key: K,
|
|
33
33
|
) => AtomToken<T>) & {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
key: string
|
|
35
|
+
type: `atom_family`
|
|
36
|
+
subject: Rx.Subject<AtomToken<T>>
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export function atomFamily<T, K extends Serializable>(
|
|
40
|
-
|
|
40
|
+
options: AtomFamilyOptions<T, K>,
|
|
41
41
|
): AtomFamily<T, K> {
|
|
42
|
-
|
|
42
|
+
return atomFamily__INTERNAL<T, K>(options)
|
|
43
43
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { capitalize } from "~/packages/anvl/src/string/capitalize"
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
IMPLICIT,
|
|
5
|
+
closeOperation,
|
|
6
|
+
openOperation,
|
|
7
|
+
getState__INTERNAL,
|
|
8
|
+
setState__INTERNAL,
|
|
9
|
+
isAtomDefault,
|
|
10
|
+
isSelectorDefault,
|
|
11
|
+
withdraw,
|
|
12
12
|
} from "./internal"
|
|
13
13
|
import * as __INTERNAL__ from "./internal"
|
|
14
14
|
import type { Store } from "./internal/store"
|
|
@@ -25,75 +25,75 @@ export type { Store } from "./internal/store"
|
|
|
25
25
|
export type { Serializable } from "~/packages/anvl/src/json"
|
|
26
26
|
|
|
27
27
|
export type AtomToken<_> = {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
key: string
|
|
29
|
+
type: `atom`
|
|
30
|
+
family?: FamilyMetadata
|
|
31
|
+
__brand?: _
|
|
32
32
|
}
|
|
33
33
|
export type SelectorToken<_> = {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
key: string
|
|
35
|
+
type: `selector`
|
|
36
|
+
family?: FamilyMetadata
|
|
37
|
+
__brand?: _
|
|
38
38
|
}
|
|
39
39
|
export type StateToken<T> = AtomToken<T> | SelectorToken<T>
|
|
40
40
|
|
|
41
41
|
export type ReadonlySelectorToken<_> = {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
key: string
|
|
43
|
+
type: `readonly_selector`
|
|
44
|
+
family?: FamilyMetadata
|
|
45
|
+
__brand?: _
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export type FamilyMetadata = {
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
key: string
|
|
50
|
+
subKey: string
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
export const getState = <T>(
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
token: ReadonlySelectorToken<T> | StateToken<T>,
|
|
55
|
+
store: Store = IMPLICIT.STORE,
|
|
56
56
|
): T => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
57
|
+
const state = withdraw<T>(token, store)
|
|
58
|
+
if (state === null) {
|
|
59
|
+
throw new Error(
|
|
60
|
+
`${capitalize(token.type)} "${token.key}" not found in store "${
|
|
61
|
+
store.config.name
|
|
62
|
+
}".`,
|
|
63
|
+
)
|
|
64
|
+
}
|
|
65
|
+
return getState__INTERNAL(state, store)
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
export const setState = <T, New extends T>(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
token: StateToken<T>,
|
|
70
|
+
value: New | ((oldValue: T) => New),
|
|
71
|
+
store: Store = IMPLICIT.STORE,
|
|
72
72
|
): void => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
73
|
+
try {
|
|
74
|
+
openOperation(token, store)
|
|
75
|
+
} catch (thrown) {
|
|
76
|
+
if (!(typeof thrown === `symbol`)) {
|
|
77
|
+
throw thrown
|
|
78
|
+
}
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
const state = withdraw(token, store)
|
|
82
|
+
if (state === null) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`${capitalize(token.type)} "${token.key}" not found in store "${
|
|
85
|
+
store.config.name
|
|
86
|
+
}".`,
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
setState__INTERNAL(state, value, store)
|
|
90
|
+
closeOperation(store)
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
export const isDefault = (
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
token: ReadonlySelectorToken<unknown> | StateToken<unknown>,
|
|
95
|
+
store: Store = IMPLICIT.STORE,
|
|
96
96
|
): boolean =>
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
token.type === `atom`
|
|
98
|
+
? isAtomDefault(token.key, store)
|
|
99
|
+
: isSelectorDefault(token.key, store)
|